-
Notifications
You must be signed in to change notification settings - Fork 85
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
Enable dim_order
kwargs for direct image conversions
#238
Conversation
Codecov ReportBase: 76.05% // Head: 77.40% // Increases project coverage by
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #238 +/- ##
==========================================
+ Coverage 76.05% 77.40% +1.35%
==========================================
Files 16 16
Lines 1829 1868 +39
==========================================
+ Hits 1391 1446 +55
+ Misses 438 422 -16
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
dim_order
kwargs for direct image conversions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't take the time to understand to understand the dimension translations, but this looks like a great step forward @elevans!
Just had a couple minor suggestions, but I don't think anything was major.
Update:I'm working on using xarray's global attribute's to store imagej/pyimagej specific metadata like the scale and |
This commit removes the pytest.fixtures decorator around the image generator methods. Images are created and thrown away during each test, defeating the purpose of pytest.fixtures in this case. Removing the decorators reduces code complexity.
Add direct conversion tests for to_dataset and to_img that test dim_order arguments.
to_xarray was returning the TypeError instead of rasing it.
Refactor the direct to_xarray tests to use pytest's parameterize feature.
RAI's without an axis attribute (e.g. an ImgLib2 Img) raises the TypeError because the RAI's fail an axis attribute check (imagej.convert.supports_java_to_xarray()). This fix converts the Img to a NumPy first and then converts the result to a DataArray.
0479a3c
to
83d4a7e
Compare
This commit add a test to check if the coordinates are the same when converting between Dataset and xarray.
This commit enables users to supply dim_orders that are smaller in length than the number of dimensions the source data has . The remaining unknown dimensions are labeled "dim_n" where "n" increments with the number of unknown dimensions. This follows xarray convention.
This commit adds image content checking (i.e. assert that the data in one image is successfully converted into the other) to the direct image conversion tests.
Convert ImagePlus to ImgPlus before converting to xarray.DataArray.
Add a new section (6.9) to working with images describing how to use and what to expect from the direct image converters and the dim_order argument.
Use op().run() instead of obtaining the CreateNamespace. This is easier ot undrestand.
If the axis array is size 1 or smaller, apply a scale of 1.
83d4a7e
to
dccabff
Compare
Me again! I have reverted the
I have a nice metadata solution and a rework on how we assign axes for xarrays <-> datasets. That work is still in progress (almost done) on this branch/PR: #247 Singleton dimensionsThe reason I originally added the work with axis scales was because I discovered a bug when creating more tests for the Lines 277 to 289 in a5544fa
From what I gather this rather serious bug has been here the entire time. Here is how you can reproduce it on import numpy as np
import imagej
ij = imagej.init()
nparr = np.random.rand(1, 2, 3, 4, 5)
# index error
ds = ij.py.to_dataset(nparr) I think no one has ran into this yet (or very few people have) because when you slice an array to a singleton dimension its usually squashed. But anyone who is making an array with a singleton dimension will hit this bug when converting to a |
There were two blank lines it did not like that my local Black didn't mind seeing. Who knows!
This pull request enables
dim_order
kwargs for the direct image converter methods:to_dataset()
,to_img()
, andto_xarray()
. It also adds tests for this new feature intest_image_conversion.py
and some additional features. There are also a couple of bugs/enhancements I made (e.g. we now calculate the slope for linear axis using all points instead of the first two elements of the scale array).To get a good idea on the
dim_order
kwarg option and how it works with the direct image converters, check out the new section I wrote in the docs (06-Working-with-Images
, section 6.9). There is a nice table that outlines the image conversion behavior with or withoutdim_order
supplied.changes
dim_order
kwarg for direct image converions (to_dataset()
,to_img()
,to_xarray()
).dim_order
kwargsReplaced(see latest comment)imagej.dims._get_scale()
withimagej.dims._compute_slope()
.dim_order
lengths that are shorter than the length of the array. Unknown dims are assigneddim_n
like xarray.dim_order
.