Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: working numpy arrays for methods that return arrays #14

Merged
merged 13 commits into from
Dec 2, 2024

Conversation

tlambert03
Copy link
Member

@tlambert03 tlambert03 commented Dec 1, 2024

this closes #1, adding proper numpy bindings for things that need to return arrays, like getImage(). All arrays are read-only views of the C++ memory buffer owned by the core object

Refactoring and Enhancements:

  • meson.build: Updated the script run command to use patch_sources.py instead of patch_c14_c17.py to apply necessary patches and bring code up to C++17.
  • scripts/patch_sources.py: Introduced a new script that consolidates and extends the functionality of patch_c14_c17.py, including additional patching for image metadata error handling.

Image Handling Improvements:

  • src/_pymmcore_nano.cc: Added helper functions to create NumPy arrays from image data and metadata, and extended the CMMCore methods to return these arrays. This includes new overloads for methods like getLastImageMD and popNextImageMD to return both image and metadata. [1] [2] [3] [4] [5]

Type Annotations:

  • src/_pymmcore_nano.pyi: Updated type annotations to use Annotated[ArrayLike, dict(writable=False)] for image-related methods in the CMMCore class, ensuring that returned NumPy arrays are read-only. Added new exception classes MetadataIndexError and MetadataKeyError. [1] [2] [3] [4]

Testing:

  • tests/test_core.py: Added numpy import and updated the demo_core function to include a system wait to ensure the demo configuration is fully loaded before proceeding with tests. [1] [2]

Copy link

codecov bot commented Dec 1, 2024

Codecov Report

Attention: Patch coverage is 44.15584% with 43 lines in your changes missing coverage. Please review.

Project coverage is 24.90%. Comparing base (6245883) to head (8015dc4).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/_pymmcore_nano.cc 44.15% 18 Missing and 25 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #14      +/-   ##
==========================================
+ Coverage   15.00%   24.90%   +9.90%     
==========================================
  Files           2        2              
  Lines         180      257      +77     
  Branches      141      183      +42     
==========================================
+ Hits           27       64      +37     
- Misses         18       33      +15     
- Partials      135      160      +25     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tlambert03 tlambert03 changed the title feat: working numpy arrays for getImage feat: working numpy arrays for methods that return arrays Dec 2, 2024
@tlambert03 tlambert03 merged commit 4835ee0 into pymmcore-plus:main Dec 2, 2024
7 checks passed
@tlambert03 tlambert03 deleted the numpy branch December 2, 2024 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TODO: add numpy buffers
1 participant