Skip to content

Commit 5389ae1

Browse files
authored
simple multiscale support (#56)
1 parent 9c7a888 commit 5389ae1

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/spatialdata_plot/pl/basic.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
_get_cs_contents,
4242
_get_extent,
4343
_maybe_set_colors,
44+
_multiscale_to_image,
4445
_prepare_cmap_norm,
4546
_prepare_params_plot,
4647
_set_outline,
@@ -504,6 +505,9 @@ def show(
504505
if len(render_cmds.keys()) == 0:
505506
raise TypeError("Please specify what to plot using the 'render_*' functions before calling 'imshow().")
506507

508+
# Simplicstic solution: If the images are multiscale, just use the first
509+
sdata = _multiscale_to_image(sdata)
510+
507511
# transform all elements
508512
for cmd, _ in render_cmds.items():
509513
if cmd == "render_images" or cmd == "render_channels":

src/spatialdata_plot/pl/render.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ class LabelsRenderParams:
347347
layer: str | None = None
348348
palette: Palette_t = None
349349
outline_alpha: float = 1.0
350-
fill_alpha: float = 0.3
350+
fill_alpha: float = 0.4
351351

352352

353353
def _render_labels(

src/spatialdata_plot/pl/utils.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import Any, Literal, Optional, Union
1111

1212
import matplotlib.pyplot as plt
13+
import multiscale_spatial_image as msi
1314
import numpy as np
1415
import pandas as pd
1516
import spatialdata as sd
@@ -36,6 +37,9 @@
3637
from skimage.util import map_array
3738
from spatialdata._logging import logger as logging
3839
from spatialdata._types import ArrayLike
40+
from spatialdata.models import (
41+
Image2DModel,
42+
)
3943

4044
from spatialdata_plot.pp.utils import _get_coordinate_system_mapping
4145

@@ -903,3 +907,14 @@ def _get_cs_element_map(
903907
# model = get_model(element_map["blobs_labels"])
904908
# if model in [Image2DModel, Image3DModel, Labels2DModel, Labels3DModel]
905909
return d
910+
911+
912+
def _multiscale_to_image(sdata: sd.SpatialData) -> sd.SpatialData:
913+
if sdata.images is None:
914+
raise ValueError("No images found in the SpatialData object.")
915+
916+
for k, v in sdata.images.items():
917+
if isinstance(v, msi.multiscale_spatial_image.MultiscaleSpatialImage):
918+
sdata.images[k] = Image2DModel.parse(v["scale0"].ds.to_array().squeeze(axis=0))
919+
920+
return sdata

0 commit comments

Comments
 (0)