mobie / mobie-viewer-fiji

BSD 2-Clause "Simplified" License
33 stars 13 forks source link

Only first two channels are displayed when channel-chunksize is > 1 #945

Open tibuch opened 1 year ago

tibuch commented 1 year ago

Hi,

I have built a MoBIE project which uses an underlying ome-zarr file with 4 channels. I have the single channel views and then used these to assemble a grid-view. Then I set the grid-view to be the default view.

~Now, when I load the MoBIE project I only get displayed the grid-view but only the first two channels show up. However, I can select the individual views for all four channels and add them to the view. Then they all show up as they should.~ The issue is the same for grid-view and single views.

I have uploaded the MoBIE project and the zarr-file here.

This is the dataset.json:

{
  "is2D": true,
  "sources": {
    "C05_Cy5": {
      "image": {
        "imageData": {
          "ome.zarr": {
            "channel": 3,
            "relativePath": "../../../zarr-files/MIP-4P-4sub.zarr/C/5/0"
          }
        }
      }
    },
    "C05_DAPI": {
      "image": {
        "imageData": {
          "ome.zarr": {
            "channel": 0,
            "relativePath": "../../../zarr-files/MIP-4P-4sub.zarr/C/5/0"
          }
        }
      }
    },
    "C05_FITC": {
      "image": {
        "imageData": {
          "ome.zarr": {
            "channel": 1,
            "relativePath": "../../../zarr-files/MIP-4P-4sub.zarr/C/5/0"
          }
        }
      }
    },
    "C05_Texas_Red": {
      "image": {
        "imageData": {
          "ome.zarr": {
            "channel": 2,
            "relativePath": "../../../zarr-files/MIP-4P-4sub.zarr/C/5/0"
          }
        }
      }
    }
  },
  "views": {
    "C05_Cy5": {
      "isExclusive": false,
      "sourceDisplays": [
        {
          "imageDisplay": {
            "color": "r=188,g=0,b=0,a=255",
            "contrastLimits": [
              0.0,
              1000.0
            ],
            "name": "C05_Cy5",
            "opacity": 1.0,
            "sources": [
              "C05_Cy5"
            ]
          }
        }
      ],
      "uiSelectionGroup": "wells"
    },
    "C05_DAPI": {
      "isExclusive": false,
      "sourceDisplays": [
        {
          "imageDisplay": {
            "color": "r=0,g=52,b=255,a=255",
            "contrastLimits": [
              0.0,
              1000.0
            ],
            "name": "C05_DAPI",
            "opacity": 1.0,
            "sources": [
              "C05_DAPI"
            ]
          }
        }
      ],
      "uiSelectionGroup": "wells"
    },
    "C05_FITC": {
      "isExclusive": false,
      "sourceDisplays": [
        {
          "imageDisplay": {
            "color": "r=115,g=255,b=0,a=255",
            "contrastLimits": [
              0.0,
              1000.0
            ],
            "name": "C05_FITC",
            "opacity": 1.0,
            "sources": [
              "C05_FITC"
            ]
          }
        }
      ],
      "uiSelectionGroup": "wells"
    },
    "C05_Texas_Red": {
      "isExclusive": false,
      "sourceDisplays": [
        {
          "imageDisplay": {
            "color": "r=255,g=103,b=0,a=255",
            "contrastLimits": [
              0.0,
              1000.0
            ],
            "name": "C05_Texas_Red",
            "opacity": 1.0,
            "sources": [
              "C05_Texas_Red"
            ]
          }
        }
      ],
      "uiSelectionGroup": "wells"
    },
    "default": {
      "isExclusive": true,
      "sourceDisplays": [
        {
          "imageDisplay": {
            "color": "r=0,g=52,b=255,a=255",
            "contrastLimits": [
              0.0,
              1000.0
            ],
            "name": "DAPI",
            "opacity": 1.0,
            "sources": [
              "DAPI_grid"
            ],
            "visible": true
          }
        },
        {
          "imageDisplay": {
            "color": "r=115,g=255,b=0,a=255",
            "contrastLimits": [
              0.0,
              1000.0
            ],
            "name": "FITC",
            "opacity": 1.0,
            "sources": [
              "FITC_grid"
            ],
            "visible": true
          }
        },
        {
          "imageDisplay": {
            "color": "r=255,g=103,b=0,a=255",
            "contrastLimits": [
              0.0,
              1000.0
            ],
            "name": "Texas_Red",
            "opacity": 1.0,
            "sources": [
              "Texas_Red_grid"
            ],
            "visible": true
          }
        },
        {
          "imageDisplay": {
            "color": "r=188,g=0,b=0,a=255",
            "contrastLimits": [
              0.0,
              1000.0
            ],
            "name": "Cy5",
            "opacity": 1.0,
            "sources": [
              "Cy5_grid"
            ],
            "visible": true
          }
        }
      ],
      "sourceTransforms": [
        {
          "mergedGrid": {
            "mergedGridSourceName": "DAPI_grid",
            "metadataSource": "C05_DAPI",
            "positions": [
              [
                4,
                2
              ]
            ],
            "sources": [
              "C05_DAPI"
            ]
          }
        },
        {
          "mergedGrid": {
            "mergedGridSourceName": "FITC_grid",
            "metadataSource": "C05_FITC",
            "positions": [
              [
                4,
                2
              ]
            ],
            "sources": [
              "C05_FITC"
            ]
          }
        },
        {
          "mergedGrid": {
            "mergedGridSourceName": "Texas_Red_grid",
            "metadataSource": "C05_Texas_Red",
            "positions": [
              [
                4,
                2
              ]
            ],
            "sources": [
              "C05_Texas_Red"
            ]
          }
        },
        {
          "mergedGrid": {
            "mergedGridSourceName": "Cy5_grid",
            "metadataSource": "C05_Cy5",
            "positions": [
              [
                4,
                2
              ]
            ],
            "sources": [
              "C05_Cy5"
            ]
          }
        }
      ],
      "uiSelectionGroup": "bookmark"
    }
  }
}
constantinpape commented 1 year ago

Thanks for reporting this @tibuch. You're running into the same issue that we are seeing here as well: https://github.com/mobie/spatial-transcriptomics-example-project/issues/21 (I checked this in your example project, and you can see all channels in the default view if you zoom in enough that the highest resolution is loaded). -> so there seems to be an issue with loading higher scale levels (potentially in MoBIE-io). I will follow up on this here later.

constantinpape commented 1 year ago

Ok, briefly: the issue seems to be that ome.zarr values are not loaded correctly for channels > 1 for a MIP Level > 0. I am not sure if this already happens in mobie-io or in the actual mobie code.

The easiest way to check this in mobie-io would be to extend the tests here to also load values from higher MIP levels. I am pretty busy this week, but if one of yu @tibuch or @tischi would have time to look into it I can generate the expected values for this test.

(Otherwise I should have time to at least do the mobie-io tests next week; but I would need a ping again here...)

tischi commented 1 year ago

I may have some time on Friday to look into extending the tests.

If @tibuch would like to contribute a little bit of Java code here that'd be of course highly welcome :heart:

Should we for now just check whether it returns values > 0 at some of the downsampled resolutions, until @constantinpape gives us some real values?

tibuch commented 1 year ago

Happy to contribute, but a bit rusty in terms of what is what. Maybe @tischi and I can carve out an hour or two on Friday and do a pair-zoom-programming?

Currently clean & install-ing the project :wink:

constantinpape commented 1 year ago

Should we for now just check whether it returns values > 0 at some of the downsampled resolutions, until @constantinpape gives us some real values?

That's a good point. Once you have the structure for this test I can also easily put in the actual values myself.

tibuch commented 1 year ago

@constantinpape and @tischi just figured out that everything works fine iff the chunk-size is 1 for the channel dimension.

tischi commented 1 year ago

which makes a lot of sense :-)

@constantinpape

tibuch commented 1 year ago

Just an FYI. I wrote the ome-zarr beforehand and did not use mobie-python for it.

Depending on what you decide, we might want to add a warning/assertion somewhere.

tischi commented 1 year ago

what did you use to create the OME-Zarr?

ok, let's try to fix it then in our reader...

tibuch commented 1 year ago

from ome_zarr.writer import write_image with defaults can result in chunks > 1 for the channel dimension.

constantinpape commented 1 year ago
  • what is your mobie-python doing there when writing the data?

I am also not quite sure there; I should def. make sure that it writes with a chunk size of 1, which will be more efficient regardless.

what did you use to create the OME-Zarr? ok, let's try to fix it then in our reader...

Yeah, if possible it would still be good to fix this.

tischi commented 1 year ago

@tibuch

in the current implementation it would read the data N times if there are N channels => definitely go for chunk size 1 for the channel dimension.

to avoid this we would have to cache/reuse the SpimData object, which is doable.