scverse / napari-spatialdata

Interactive visualization of spatial omics data
https://spatialdata.scverse.org/projects/napari/en/latest/
BSD 3-Clause "New" or "Revised" License
41 stars 17 forks source link

Split Stack resets coordinates? #143

Open harrig12 opened 1 year ago

harrig12 commented 1 year ago

I have a SpatialData with two images, a and b. Each image is mapped to two coordinate system: global and aligned, with the following mapping:

a -> global: identity b -> global: identity a -> aligned: identity b -> aligned: affine

in the viewer, when I open the aligned images, things look good, but if I rightclick image b and use Split Stack to separate out the channels, then my aligned coordinated system seems to be ignored, and the channels all get reset to global. Mean (or other) projections don't seem to have this issue.

LucaMarconato commented 1 year ago

Hi, thanks for reporting.

@melonora do you know if there is a hook for Split Stack? I think that calling the function you wrote to transfer the metadata would fix this issue.

melonora commented 1 year ago

@harrig12 @LucaMarconato there is no callback other than a new layer being added as far as I know. However, we can potentially overload the call with the SpatialDataViewer class. I will look into it and report back / implement changes later this week. @harrig12 would you be able to share a small test example? No worries if you can't. One question what number of channels does B have?

LucaMarconato commented 1 year ago

Thanks a lot @melonora!

harrig12 commented 1 year ago

Sure, here's an example zarr

splitstack_mwe.zarr.zip

The affine transformation on B is:

Affine (x, y -> x, y)
    [2.90898430e-01 6.02962457e-03 1.48529400e+02]
    [-2.58579771e-03  2.91931444e-01  2.53555781e+02]
    [0. 0. 1.]

In this example, I have 4 channels in B, but there may be anywhere from 1-40

Thanks! 💃

melonora commented 1 year ago

Thanks for providing the sample data! I will get on it

melonora commented 1 year ago

Hi @harrig12,

Just to give an update. I opened #136 to support multiple spatialdata objects. As a follow up PR I can fix the issue that you have as I have added a callback function when a layer gets inserted. Could you tell me whether you are using split rgb or split stack? Based on napari documentation these should behave differently.

Based on napari documentation:

Split RGB - if the image layer is an RGB image, it will be split into 3 new layers with red, green, and blue values in separate layers.

Split Stack - if an image layer is a stack (has 3 or more dimensions), it is split into a list of layers along the axis. This option takes a little time to execute. Properties will be changed as follows:

    - Colormap: (magenta, green) for a stack with 2 channels, (CYMRGB) for stacks with more than 2 channels

    - Blending: additive

    - Contrast_limits: min and max values of the layer

    - All other properties, such as Scale and Translate will be propagated from the original stack.
harrig12 commented 1 year ago

I'm using split stack