Skip to content

Commit

Permalink
Fix validate image parameters method for multiscale images (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaMarconato authored Oct 11, 2024
2 parents 6cce44e + 79e3105 commit 80c6f77
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
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 @@ -1887,18 +1887,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.
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()

0 comments on commit 80c6f77

Please sign in to comment.