Skip to content

Fix validate image parameters method for multiscale images #369

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

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning][].

### Fixed

-
- Giving a custom colormap when rendering a multiscale image now works (#586)

## [0.2.6] - 2024-09-04

Expand Down
8 changes: 4 additions & 4 deletions src/spatialdata_plot/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,18 +1897,18 @@ def _validate_image_render_params(

if isinstance(palette := param_dict["palette"], list):
if len(palette) == 1:
palette_length = len(channel) if channel is not None else len(spatial_element.c)
palette_length = len(channel) if channel is not None else len(spatial_element_ch)
palette = palette * palette_length
if (channel is not None and len(palette) != len(channel)) and len(palette) != len(spatial_element.c):
if (channel is not None and len(palette) != len(channel)) and len(palette) != len(spatial_element_ch):
palette = None
element_params[el]["palette"] = palette
element_params[el]["na_color"] = param_dict["na_color"]

if (cmap := param_dict["cmap"]) is not None:
if len(cmap) == 1:
cmap_length = len(channel) if channel is not None else len(spatial_element.c)
cmap_length = len(channel) if channel is not None else len(spatial_element_ch)
cmap = cmap * cmap_length
if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element.c):
if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element_ch):
cmap = None
element_params[el]["cmap"] = cmap
element_params[el]["norm"] = param_dict["norm"]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions tests/pl/test_render_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ def test_plot_can_stack_render_images(self, sdata_blobs: SpatialData):

def test_plot_can_stick_to_zorder(self, sdata_blobs: SpatialData):
sdata_blobs.pl.render_shapes().pl.render_images().pl.show()

def test_plot_can_render_multiscale_image_with_custom_cmap(self, sdata_blobs: SpatialData):
sdata_blobs.pl.render_images("blobs_multiscale_image", channel=0, scale="scale2", cmap="Greys").pl.show()
Loading