Skip to content

Commit 80c6f77

Browse files
Fix validate image parameters method for multiscale images (#369)
2 parents 6cce44e + 79e3105 commit 80c6f77

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ and this project adheres to [Semantic Versioning][].
2020

2121
### Fixed
2222

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

2525
## [0.2.6] - 2024-09-04
2626

src/spatialdata_plot/pl/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,18 +1887,18 @@ def _validate_image_render_params(
18871887

18881888
if isinstance(palette := param_dict["palette"], list):
18891889
if len(palette) == 1:
1890-
palette_length = len(channel) if channel is not None else len(spatial_element.c)
1890+
palette_length = len(channel) if channel is not None else len(spatial_element_ch)
18911891
palette = palette * palette_length
1892-
if (channel is not None and len(palette) != len(channel)) and len(palette) != len(spatial_element.c):
1892+
if (channel is not None and len(palette) != len(channel)) and len(palette) != len(spatial_element_ch):
18931893
palette = None
18941894
element_params[el]["palette"] = palette
18951895
element_params[el]["na_color"] = param_dict["na_color"]
18961896

18971897
if (cmap := param_dict["cmap"]) is not None:
18981898
if len(cmap) == 1:
1899-
cmap_length = len(channel) if channel is not None else len(spatial_element.c)
1899+
cmap_length = len(channel) if channel is not None else len(spatial_element_ch)
19001900
cmap = cmap * cmap_length
1901-
if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element.c):
1901+
if (channel is not None and len(cmap) != len(channel)) or len(cmap) != len(spatial_element_ch):
19021902
cmap = None
19031903
element_params[el]["cmap"] = cmap
19041904
element_params[el]["norm"] = param_dict["norm"]
Loading

tests/pl/test_render_images.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,6 @@ def test_plot_can_stack_render_images(self, sdata_blobs: SpatialData):
125125

126126
def test_plot_can_stick_to_zorder(self, sdata_blobs: SpatialData):
127127
sdata_blobs.pl.render_shapes().pl.render_images().pl.show()
128+
129+
def test_plot_can_render_multiscale_image_with_custom_cmap(self, sdata_blobs: SpatialData):
130+
sdata_blobs.pl.render_images("blobs_multiscale_image", channel=0, scale="scale2", cmap="Greys").pl.show()

0 commit comments

Comments
 (0)