spatialdata-plot icon indicating copy to clipboard operation
spatialdata-plot copied to clipboard

channel selection in `render_images()` depends on `rasterize`

Open clwgg opened this issue 1 year ago • 0 comments

I'm running into the following issue: I have a multichannel image saved in a SpatialData object, and I've annotated the color coordinate according to the channels they correspond to, like so: image

When I try to plot a specific channel:

sdata.pl.render_images(channel="DAPI").pl.show()

I get the following error (just showing the last line for brevity):

KeyError: "not all values found in index 'c'"

I tracked this error a bit, and it appears to depend on whether the image is getting rasterized or not here: https://github.com/scverse/spatialdata-plot/blob/49f0efb4fca568ae1c078a0d87c37a0991c26956/src/spatialdata_plot/pl/render.py#L403

I tested this by setting scale="full":

sdata.pl.render_images(channel="DAPI", scale="full").pl.show()

which works fine.

Tracking the issue further, this actually appears to be a problem in the core spatialdata library, where the channel information gets lost during rasterization here: spatialdata/_core/operations/rasterize.py#L463

I'll open a draft PR over on the spatialdata repo to address this, but thought I'd put the issue here since it manifests as an issue in render_images().

clwgg avatar Apr 11 '24 19:04 clwgg