spatialdata-plot
spatialdata-plot copied to clipboard
Error in Squidpy notebook due to rasterization not handling transformations
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
@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.
I just tried: the error disappeared and the plot is fast! There is still a problem with the lims as I get this plot
Can you have a look at it as part of the PR please?
I checked, the extent of the plot is correct. I think that the datashader plot has been made against the original non-transformed coordinates.
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:
- [ ] assign the correct coordinate transformations to the image element returned by the internal datashader functions
- [ ] ensure that the resolution of the image computed by datashader is computed from the combination of:
- figure DPI
- figure size
- eventually the range given by
get_extent()and not by the min/max computed from the original data. Probably this is already the case in the implementation, but better to double check.
Fixed by https://github.com/scverse/spatialdata-plot/pull/378