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

v0.4 axes transforms #31

Merged
merged 6 commits into from
Jan 26, 2022
Merged

v0.4 axes transforms #31

merged 6 commits into from
Jan 26, 2022

Conversation

will-moore
Copy link
Member

@will-moore will-moore commented Jan 18, 2022

WIP:

Test napari https://minio-dev.openmicroscopy.org/idr/v0.4/2022-01-05/idr0062/6001240.zarr.
To show scale-bar, open the napari terminal and (on latest napari):

viewer.scale_bar.visible = True

(This was previously viewer.scale_bar_visible napari/napari#1720)

This PR requires https://pypi.org/project/ome-zarr/0.3a1/

To do:

  • handle axes in v0.4 format
  • handle transform scale to set pixel sizes
  • affine transform ?!?

Not sure yet how to convert affine transform in the spec into what napari is expecting? https://napari.org/api/stable/napari.Viewer.html#napari.Viewer.add_image

- scale (tuple of float or list) – Scale factors for the layer. If a list then must be a list of tuples of float with the same length as the axis that is being expanded as channels.

- affine (n-D array or napari.utils.transforms.Affine) – (N+1, N+1) affine transformation matrix in homogeneous coordinates. The first (N, N) entries correspond to a linear transform and the final column is a length N translation vector and a 1 or a napari Affine transform object. Applied as an extra transform on top of the provided scale, rotate, and shear values.

@will-moore
Copy link
Member Author

Without scale metadata, scale-bar shows pixels.
NB: size Z is 235.

Screenshot 2022-01-18 at 12 38 52

Using pixel sizes in microns to add:
"scale": (0.5002025531914894, 0.3603981534640209, 0.3603981534640209)
to the metadata fixes the scale-bar to show correct size (compare with IDR image below), but now there are 470 Z-sections and if you go above 235 on the Z-slider you just get black.

Screenshot 2022-01-18 at 12 40 34

See IDR https://idr.openmicroscopy.org/webclient/img_detail/6001240/

Screenshot 2022-01-18 at 12 42 31

@will-moore
Copy link
Member Author

You can also set units with viewer.scale_bar.unit='um' for microns.

@will-moore
Copy link
Member Author

If I set the scale for only the X and Y axes, then I get a correct scale-bar without breaking the Z-slider:

"scale": (1, 0.36, 0.36),

but this distorts the 3D view:

Screenshot 2022-01-18 at 13 06 50

@imagesc-bot
Copy link

This pull request has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/napari-non-integer-step-size/31847/8

@will-moore
Copy link
Member Author

@jni
Copy link
Contributor

jni commented Jan 19, 2022

@will-moore what version of napari are you on? Do you think you would be able to make a reproducible example with just NumPy arrays? This works fine on main:

import napari
import numpy as np

_ = napari.view_image(
    np.random.random((10, 256, 256)),
    scale=(0.5, 0.3, 0.3),
)
napari.run()

I get a slider with 10 positions from 0 to 9 inclusive. The broadcasting of the scale doesn't seem to be the issue either, as the sliders also seem fine with this:

import napari
import numpy as np

_ = napari.view_image(
    np.random.random((3, 10, 256, 256)),
    scale=(0.5, 0.3, 0.3),
)
napari.run()

@will-moore will-moore changed the title Always read channel_axis, even when sizeC==1 v0.4 axes transforms Jan 19, 2022
@will-moore
Copy link
Member Author

@jni Thanks for that. I'm using napari 0.4.12 and your sample helped me to track down the issue. I was only applying the scaling to the image layers and not the labels layer so the sizeZ of the scaled image in real world coordinates is only a portion of the sizeZ of the labels layer.

@will-moore
Copy link
Member Author

Looks like it's not possible to handle units yet - see napari/napari#1701

@will-moore
Copy link
Member Author

Currently the tests are failing because the code now depends on ome/ome-zarr-py#124
cc @sbesson Do we need to do a pre-release of ome-zarr-py first and then update to that in the requirements here?

@sbesson
Copy link
Member

sbesson commented Jan 19, 2022

cc @sbesson Do we need to do a pre-release of ome-zarr-py first and then update to that in the requirements here?

Yes that's one of the driver for the pre-release. The other one being ome/omero-cli-zarr#93 which is only passing because there are no tests.

I propose we review how close we are later today on signing off on the two open HCS ome-zarr-py and then decide on a 0.3.0 pre-release?

@jburel
Copy link
Member

jburel commented Jan 20, 2022

tested using ome-zarr==0.3a1.
Scalebar is at 25microns as expected.

Copy link
Member

@joshmoore joshmoore left a comment

Choose a reason for hiding this comment

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

Few minor points but happy to get this in for the meeting. I assume we keep it at a pre-release version until ome-zarr-py is ready.

napari_ome_zarr/_reader.py Outdated Show resolved Hide resolved
napari_ome_zarr/_reader.py Show resolved Hide resolved
Get a list of these for each level in data. Just use first?
"""
if "transformations" in node_metadata:
level_0_transforms = node_metadata["transformations"][0]
Copy link
Member

Choose a reason for hiding this comment

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

Just a reminder that here we should probably think of a proper model (even if just using @propertys) as the mode

@sbesson
Copy link
Member

sbesson commented Jan 25, 2022

@will-moore can any of the three points raised in #31 (review) be addressed/resolved quickly? Otherwise, I agree to get this merged and tagged as a pre-release in preparation of the community call.

@codecov-commenter
Copy link

codecov-commenter commented Jan 25, 2022

Codecov Report

Merging #31 (b3abf92) into main (fcff2c8) will decrease coverage by 6.84%.
The diff coverage is 36.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #31      +/-   ##
==========================================
- Coverage   92.77%   85.92%   -6.85%     
==========================================
  Files           3        3              
  Lines         180      199      +19     
==========================================
+ Hits          167      171       +4     
- Misses         13       28      +15     
Impacted Files Coverage Δ
napari_ome_zarr/_reader.py 76.85% <36.66%> (-11.92%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fcff2c8...b3abf92. Read the comment docs.

@sbesson
Copy link
Member

sbesson commented Jan 26, 2022

Thanks @will-moore. Merging and creating a pre-release

@sbesson sbesson merged commit 08c3fa4 into ome:main Jan 26, 2022
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.

7 participants