MAYBE: Can we select channels for multi-scale images?
I think I can follow up on this issue, since I am encountering the same problem.
Context: Working with MERSCOPE spatial data.
Once loaded my spatial data (assigned to spdata variable) looks like this:
├── Images │ └── 'E9_5_region_1_z3': DataTree[cyx] (5, 17013, 17062), (5, 8506, 8531), (5, 4253, 4265), (5, 2126, 2132), (5, 1063, 1066) ├── Points │ └── 'E9_5_region_1_transcripts': DataFrame with shape: (<Delayed>, 9) (2D points) ├── Shapes │ └── 'E9_5_region_1_polygons': GeoDataFrame shape: (6835, 9) (2D shapes) └── Tables └── 'table': AnnData (6835, 296) with coordinate systems: ▸ 'global', with elements: E9_5_region_1_z3 (Images), E9_5_region_1_transcripts (Points), E9_5_region_1_polygons (Shapes)
The Image DataTree looks like this:
DataTree('None', parent=None) ├── DataTree('scale0') │ Dimensions: (c: 5, y: 17013, x: 17062) │ Coordinates: │ * c (c) <U10 'PolyT' 'Cellbound2' 'DAPI' 'Cellbound3' 'Cellbound1' │ * y (y) float64 0.5 1.5 2.5 3.5 ... 1.701e+04 1.701e+04 1.701e+04 │ * x (x) float64 0.5 1.5 2.5 3.5 ... 1.706e+04 1.706e+04 1.706e+04 │ Data variables: │ image (c, y, x) uint16 dask.array<chunksize=(1, 4096, 4096), meta=np.ndarray> ├── DataTree('scale1') │ Dimensions: (c: 5, y: 8506, x: 8531) │ Coordinates: │ * c (c) <U10 'PolyT' 'Cellbound2' 'DAPI' 'Cellbound3' 'Cellbound1' │ * y (y) float64 1.0 3.0 5.0 7.0 ... 1.701e+04 1.701e+04 1.701e+04 │ * x (x) float64 1.0 3.0 5.0 7.0 ... 1.706e+04 1.706e+04 1.706e+04 │ Data variables: │ image (c, y, x) uint16 dask.array<chunksize=(1, 4096, 4096), meta=np.ndarray> ├── DataTree('scale2') │ Dimensions: (c: 5, y: 4253, x: 4265) │ Coordinates: │ * c (c) <U10 'PolyT' 'Cellbound2' 'DAPI' 'Cellbound3' 'Cellbound1' │ * y (y) float64 2.0 6.0 10.0 14.0 ... 1.7e+04 1.701e+04 1.701e+04 │ * x (x) float64 2.0 6.001 10.0 14.0 ... 1.705e+04 1.706e+04 1.706e+04 │ Data variables: │ image (c, y, x) uint16 dask.array<chunksize=(1, 4096, 4096), meta=np.ndarray> ├── DataTree('scale3') │ Dimensions: (c: 5, y: 2126, x: 2132) │ Coordinates: │ * c (c) <U10 'PolyT' 'Cellbound2' 'DAPI' 'Cellbound3' 'Cellbound1' │ * y (y) float64 4.001 12.0 20.01 28.01 ... 1.699e+04 1.7e+04 1.701e+04 │ * x (x) float64 4.001 12.0 20.01 ... 1.704e+04 1.705e+04 1.706e+04 │ Data variables: │ image (c, y, x) uint16 dask.array<chunksize=(1, 2126, 2132), meta=np.ndarray> └── DataTree('scale4') Dimensions: (c: 5, y: 1063, x: 1066) Coordinates: * c (c) <U10 'PolyT' 'Cellbound2' 'DAPI' 'Cellbound3' 'Cellbound1' * y (y) float64 8.002 24.01 40.01 56.02 ... 1.697e+04 1.699e+04 1.7e+04 * x (x) float64 8.003 24.01 40.01 ... 1.702e+04 1.704e+04 1.705e+04 Data variables: image (c, y, x) uint16 dask.array<chunksize=(1, 1063, 1066), meta=np.ndarray>
If i try to: spdata.pl.render_images(element="E9_5_region_1_z3", channel=["DAPI", "PolyT"], cmap=["Reds", "Blues"]).pl.show()
It raises an error on the DataTree not having the "c" attribute, which clearly has.
This is the traceback: File "/home/matteo/miniforge3/envs/stIntegrationENV/lib/python3.12/site-packages/spatialdata/_utils.py", line 261, in wrapper return f(*args, **kwargs) ^^^^^^^^^^^^^^^^^^ File "/home/matteo/miniforge3/envs/stIntegrationENV/lib/python3.12/site-packages/spatialdata_plot/pl/basic.py", line 476, in render_images params_dict = _validate_image_render_params( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/matteo/miniforge3/envs/stIntegrationENV/lib/python3.12/site-packages/spatialdata_plot/pl/utils.py", line 1911, in _validate_image_render_params if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element.c): ^^^^^^^^^^^^^^^^^ File "/home/matteo/miniforge3/envs/stIntegrationENV/lib/python3.12/site-packages/datatree/common.py", line 54, in getattr raise AttributeError( AttributeError: 'DataTree' object has no attribute 'c'
While... If do not choose the channel, I do not get this error and it plots everyone of the 5 present together, which is confusing to look at.
Hey @BaldanMatt, thanks for confirming the suspicion! It's in our current sprint, so it should be fixed with the next release :) cc @Sonja-Stockhaus
Dear @timtreis, I was trying right now to add some details, like reproducing the expected behavior by hard-coding the selection of the scale and recreating a single scale spatial image.
If i manage to provide a clear traceback of the stdout and stder, then I'll follow up this thread.
Happy to help. Will use this tool a lot in the future.
I was testing with 0.2.7 and it seems that the issue was solved. I did not see it in the changelog, therefore I was not sure. I will continue testing, but it seems good.
It could be that with datatree now included directly in xarray and using a new datamodel that some of the methods previously used directly on the datatree are not available anymore. There are some PRs now to update all the repos to account for this. I will double check the test for this.