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

Plotting cluster sometimes results in coordinate system not being found, even if set correctly #420

Open
marcouderzo opened this issue Feb 7, 2025 · 1 comment

Comments

@marcouderzo
Copy link

Hi,
reporting an issue with plotting.

SpatialData object, with associated Zarr store: ...
├── Images
│ ├── 'wt1_cytassist_image': DataArray[cyx] (3, 3000, 3200)
│ ├── 'wt1_hires_image': DataArray[cyx] (3, 4818, 6000)
│ ├── 'wt1_lowres_image': DataArray[cyx] (3, 482, 600)
│ ├── 'wt5_cytassist_image': DataArray[cyx] (3, 3000, 3200)
│ ├── 'wt5_hires_image': DataArray[cyx] (3, 5013, 6000)
│ ├── 'wt5_lowres_image': DataArray[cyx] (3, 501, 600)
│ ├── 'wt8_cytassist_image': DataArray[cyx] (3, 3000, 3200)
│ ├── 'wt8_hires_image': DataArray[cyx] (3, 6000, 5907)
│ └── 'wt8_lowres_image': DataArray[cyx] (3, 600, 591)
├── Shapes
│ ├── 'wt1_square_002um': GeoDataFrame shape: (2919200, 1) (2D shapes)
│ ├── 'wt1_square_008um': GeoDataFrame shape: (182450, 1) (2D shapes)
│ ├── 'wt1_square_016um': GeoDataFrame shape: (46427, 1) (2D shapes)
│ ├── 'wt5_square_002um': GeoDataFrame shape: (1779504, 1) (2D shapes)
│ ├── 'wt5_square_008um': GeoDataFrame shape: (111219, 1) (2D shapes)
│ ├── 'wt5_square_016um': GeoDataFrame shape: (28148, 1) (2D shapes)
│ ├── 'wt8_square_002um': GeoDataFrame shape: (1498336, 1) (2D shapes)
│ ├── 'wt8_square_008um': GeoDataFrame shape: (93646, 1) (2D shapes)
│ └── 'wt8_square_016um': GeoDataFrame shape: (23643, 1) (2D shapes)
└── Tables
├── 'square_002um': AnnData (6197040, 19059)
├── 'square_008um': AnnData (381575, 19059)
└── 'square_016um': AnnData (98218, 19059)
with coordinate systems:
▸ 'downscaled_hires', with elements:
wt1_hires_image (Images), wt5_hires_image (Images), wt8_hires_image (Images), wt1_square_002um (Shapes), wt1_square_008um (Shapes), wt1_square_016um (Shapes), wt5_square_002um (Shapes), wt5_square_008um (Shapes), wt5_square_016um (Shapes), wt8_square_002um (Shapes), wt8_square_008um (Shapes), wt8_square_016um (Shapes)
▸ 'downscaled_lowres', with elements:
wt1_lowres_image (Images), wt5_lowres_image (Images), wt8_lowres_image (Images), wt1_square_002um (Shapes), wt1_square_008um (Shapes), wt1_square_016um (Shapes), wt5_square_002um (Shapes), wt5_square_008um (Shapes), wt5_square_016um (Shapes), wt8_square_002um (Shapes), wt8_square_008um (Shapes), wt8_square_016um (Shapes)
▸ 'global', with elements:
wt1_cytassist_image (Images), wt5_cytassist_image (Images), wt8_cytassist_image (Images), wt1_square_002um (Shapes), wt1_square_008um (Shapes), wt1_square_016um (Shapes), wt5_square_002um (Shapes), wt5_square_008um (Shapes), wt5_square_016um (Shapes), wt8_square_002um (Shapes), wt8_square_008um (Shapes), wt8_square_016um (Shapes)

and

sdata['wt1_hires_image'].transform
{'downscaled_hires': Identity }

When I try to plot some clusters with "group=", some of them are indeed plotted and others, without any apparent reason, yield this error:

clusters_list = sdata['square_008um'].obs['clusters'].unique()
for cluster in clusters_list:
try:
sdata.pl.render_images('wt1_hires_image').pl.render_shapes(
'wt1_square_008um',
color="clusters", # Color by the 'clusters' column
groups=[cluster],
size=0.3,
).pl.show(
coordinate_systems="downscaled_hires",
figsize=(10, 10)
)

except Exception as e:
    print(f"Error while plotting cluster {cluster}: {e}")
INFO Rasterizing image for faster rendering.

[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py:105](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py#line=104): UserWarning: Key wt1_square_008um already exists. Overwriting it in-memory.
self._check_key(key, self.keys(), self._shared_keys)
[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py:125](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py#line=124): UserWarning: Key square_008um already exists. Overwriting it in-memory.
self._check_key(key, self.keys(), self._shared_keys)

INFO Using 'datashader' backend with 'None' as reduction method to speed up plotting. Depending on the
reduction method, the value range of the plot might change. Set method to 'matplotlib' do disable this
behaviour.

[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata_plot/pl/utils.py:771](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata_plot/pl/utils.py#line=770): FutureWarning: The default value of 'ignore' for the na_action parameter in [pandas.Categorical.map](http://pandas.categorical.map/) is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning
color_vector = color_source_vector.map(color_mapping)

Error while plotting cluster 0: The element does not contain any coordinate system named 'downscaled_hires', please pass a different coordinate system with the argument 'coordinate_system'.
INFO Rasterizing image for faster rendering.

[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py:105](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py#line=104): UserWarning: Key wt1_square_008um already exists. Overwriting it in-memory.
self._check_key(key, self.keys(), self._shared_keys)
[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py:125](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py#line=124): UserWarning: Key square_008um already exists. Overwriting it in-memory.
self._check_key(key, self.keys(), self._shared_keys)
[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata_plot/pl/utils.py:771](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata_plot/pl/utils.py#line=770): FutureWarning: The default value of 'ignore' for the na_action parameter in [pandas.Categorical.map](http://pandas.categorical.map/) is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning
color_vector = color_source_vector.map(color_mapping)

INFO Rasterizing image for faster rendering.

[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py:105](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py#line=104): UserWarning: Key wt1_square_008um already exists. Overwriting it in-memory.
self._check_key(key, self.keys(), self._shared_keys)
[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py:125](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata/_core/_elements.py#line=124): UserWarning: Key square_008um already exists. Overwriting it in-memory.
self._check_key(key, self.keys(), self._shared_keys)

INFO Using 'datashader' backend with 'None' as reduction method to speed up plotting. Depending on the
reduction method, the value range of the plot might change. Set method to 'matplotlib' do disable this
behaviour.

[/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata_plot/pl/utils.py:771](https://192.33.153.24/opt/conda/envs/spatialdatahd/lib/python3.10/site-packages/spatialdata_plot/pl/utils.py#line=770): FutureWarning: The default value of 'ignore' for the na_action parameter in [pandas.Categorical.map](http://pandas.categorical.map/) is deprecated and will be changed to 'None' in a future version. Please set na_action to the desired value to avoid seeing this warning
color_vector = color_source_vector.map(color_mapping)

Error while plotting cluster 15: The element does not contain any coordinate system named 'downscaled_hires', please pass a different coordinate system with the argument 'coordinate_system'.

Though it seems that coordinate systems are set, as shown above.

Any ideas why?

Thanks!

@LucaMarconato
Copy link
Member

Thanks for reporting 😊 I add also that the problem occurs only with the datashader backend.

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

No branches or pull requests

2 participants