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

Extract S dim from OME data #483

Merged
merged 4 commits into from
Apr 11, 2023

Conversation

SeanLeRoy
Copy link
Collaborator

@SeanLeRoy SeanLeRoy commented Apr 7, 2023

Description

#457 describes an error where a RGB OME TIFF fails to open. This error occurs because the dimensions of the file are SYX and currently the OmeTiffReader only supports the Samples dimension being at the end of the dimension order via this line.

How does this PR address the issue?

The OmeTiffReader was already aware of the SizeC occasionally being representative of RGB data when SamplesPerPixel was present elsewhere in the code. However, it just incorrectly assumed the Samples dimension is the last dimension of the image data.

Testing

Tested locally with file from issue as well as some random OME TIFFs from AICS

@@ -189,14 +189,19 @@ def _expand_dims_to_match_ome(
# need to correct channel count if this is a RGB image
n_samples = ome.images[scene_index].pixels.channels[0].samples_per_pixel
for d in dims:
# SizeC can represent RGB (Samples) data rather
# than channel data, whether or not this is the case depends
# on what the SamplesPerPixel are for the channel
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a scenario where you can have N channels and M samples and SizeC is set to N*M? Do you have to do a bit of math to find the true N value? Or is that automatically handled here. I remember that coming up a long time ago as a possibility.

Copy link
Collaborator Author

@SeanLeRoy SeanLeRoy Apr 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The channel dimension shape is determined by line 196 rather than line 200 so instead of using SizeC it uses the length of the channels list to assign the size of the channel dimension, likely already for this reason so I think we are covered there

@SeanLeRoy SeanLeRoy self-assigned this Apr 7, 2023
@SeanLeRoy SeanLeRoy closed this Apr 7, 2023
@SeanLeRoy SeanLeRoy reopened this Apr 7, 2023
@codecov-commenter
Copy link

codecov-commenter commented Apr 7, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 🎉

Comparison is base (e2dd9c7) 94.18% compared to head (6933f2a) 94.20%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #483      +/-   ##
==========================================
+ Coverage   94.18%   94.20%   +0.01%     
==========================================
  Files          48       48              
  Lines        4265     4279      +14     
==========================================
+ Hits         4017     4031      +14     
  Misses        248      248              
Impacted Files Coverage Δ
aicsimageio/metadata/utils.py 90.52% <100.00%> (+0.27%) ⬆️
aicsimageio/readers/bfio_reader.py 88.29% <100.00%> (ø)
aicsimageio/readers/bioformats_reader.py 84.08% <100.00%> (ø)
aicsimageio/readers/ome_tiff_reader.py 93.44% <100.00%> (+0.46%) ⬆️

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 in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@SeanLeRoy SeanLeRoy marked this pull request as ready for review April 7, 2023 18:56
"""
dims_from_ome = metadata_utils.get_dims_from_ome(ome, scene_index)

dims_from_tiff_axes = list(tiff.series[scene_index].axes)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implicit assumption that the dim names coming from tiffffile are compatible with our TCZYXS?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I'll comment on this. I'd assumed we were already dependent on that assumption based on these lines, but perhaps this comment is just refering to non-TCZYXS dimensions.

Copy link
Collaborator

@toloudis toloudis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, maybe need a comment about the dimension strings I mentioned above.

Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I might be missing something, do our tests already cover the new case? Would it make sense to add any new tests for this?

@@ -65,7 +65,7 @@ def _general_data_array_constructor(
) -> xr.DataArray:

# Unpack dims and coords from OME
_, coords = metadata_utils.get_dims_and_coords_from_ome(
coords = metadata_utils.get_coords_from_ome(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Good call separating these out 🙂

aicsimageio/readers/ome_tiff_reader.py Outdated Show resolved Hide resolved
Co-authored-by: Madison Swain-Bowden <bowdenm@spu.edu>
@SeanLeRoy
Copy link
Collaborator Author

SeanLeRoy commented Apr 11, 2023

Looks good! I might be missing something, do our tests already cover the new case? Would it make sense to add any new tests for this?

@AetherUnbound There are tests that cover this in terms of testing the code path and logic, however this issue does refer specifically to an OME TIFF where the dimensions were ordered SYX which is different than the test files the package currently has. I wasn't sure if this was enough of a case to add a new test file or what the criterion were for adding new test files. If it seems like it would be worth it lmk & I'll happily add it!

@AetherUnbound
Copy link
Collaborator

Ah okay, no worries! I figured since we were adding a new condition that perhaps some test might need to be changed, but if that's dependent on a new file being added then I'm of less help there 😅

@SeanLeRoy SeanLeRoy linked an issue Apr 11, 2023 that may be closed by this pull request
@SeanLeRoy SeanLeRoy merged commit 45dd26f into main Apr 11, 2023
@SeanLeRoy SeanLeRoy deleted the bugfix/fail-to-open-ome-tiff-rgb-from-imagej branch April 11, 2023 22:47
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.

AICSImageIO fails to open OME-TIFF from Fiji which has type RGB
4 participants