scverse / spatialdata-plot

Static plotting for spatialdata
BSD 3-Clause "New" or "Revised" License
27 stars 13 forks source link

Error in Squidpy notebook due to rasterization #291

Open LucaMarconato opened 1 month ago

LucaMarconato commented 1 month ago

The Squidpy notebook shows an error liked to rasterizatation. @Sonja-Stockhaus could you please have a look at it? Thanks 😊

This is part of the log:

    300 else:
    301     array_module = np
--> 302 return lambda shape: tuple(c(shape, array_module) for c in creators)
File /mnt/miniconda3/envs/ome/lib/python3.10/site-packages/datashader/compiler.py:302, in <genexpr>(.0)
    300 else:
    301     array_module = np
--> 302 return lambda shape: tuple(c(shape, array_module) for c in creators)
File /mnt/miniconda3/envs/ome/lib/python3.10/site-packages/datashader/reductions.py:785, in by._build_create.<locals>.<lambda>(shape, array_module)
    783 def _build_create(self, required_dshape):
    784     n_cats = len(required_dshape.measure.fields)
--> 785     return lambda shape, array_module: self.reduction._build_create(
    786         required_dshape)(shape + (n_cats,), array_module)
File /mnt/miniconda3/envs/ome/lib/python3.10/site-packages/datashader/reductions.py:472, in Reduction._create_uint32(shape, array_module)
    470 @staticmethod
    471 def _create_uint32(shape, array_module):
--> 472     return array_module.zeros(shape, dtype='u4')
MemoryError: Unable to allocate 74.8 GiB for an array with shape (25783, 35416, 22) and data type uint32
Sonja-Stockhaus commented 1 month ago

@LucaMarconato I feel like this also has to do with https://github.com/scverse/spatialdata-plot/issues/296 and might be solved with https://github.com/scverse/spatialdata-plot/pull/309 since with that version of the code everything runs for me.

LucaMarconato commented 1 month ago

I just tried: the error disappeared and the plot is fast! There is still a problem with the lims as I get this plot

image

Can you have a look at it as part of the PR please?

LucaMarconato commented 4 weeks ago

I checked, the extent of the plot is correct. I think that the datashader plot has been made against the original non-transformed coordinates.

LucaMarconato commented 4 weeks ago

I confirm that my claim seems to be indeed the source of the issue, in fact a workaround that fixes the plot is to call

sdata['cell_circles'] = sd.transform(sdata['cell_circles'], to_coordinate_system='global')

before making the plot.

I think that a solution is to: