Skip to content

simple multiscale support #56

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 1 commit into from
Apr 18, 2023
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
4 changes: 4 additions & 0 deletions src/spatialdata_plot/pl/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
_get_cs_contents,
_get_extent,
_maybe_set_colors,
_multiscale_to_image,
_prepare_cmap_norm,
_prepare_params_plot,
_set_outline,
Expand Down Expand Up @@ -504,6 +505,9 @@ def show(
if len(render_cmds.keys()) == 0:
raise TypeError("Please specify what to plot using the 'render_*' functions before calling 'imshow().")

# Simplicstic solution: If the images are multiscale, just use the first
sdata = _multiscale_to_image(sdata)

# transform all elements
for cmd, _ in render_cmds.items():
if cmd == "render_images" or cmd == "render_channels":
Expand Down
2 changes: 1 addition & 1 deletion src/spatialdata_plot/pl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class LabelsRenderParams:
layer: str | None = None
palette: Palette_t = None
outline_alpha: float = 1.0
fill_alpha: float = 0.3
fill_alpha: float = 0.4


def _render_labels(
Expand Down
15 changes: 15 additions & 0 deletions src/spatialdata_plot/pl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing import Any, Literal, Optional, Union

import matplotlib.pyplot as plt
import multiscale_spatial_image as msi
import numpy as np
import pandas as pd
import spatialdata as sd
Expand All @@ -36,6 +37,9 @@
from skimage.util import map_array
from spatialdata._logging import logger as logging
from spatialdata._types import ArrayLike
from spatialdata.models import (
Image2DModel,
)

from spatialdata_plot.pp.utils import _get_coordinate_system_mapping

Expand Down Expand Up @@ -903,3 +907,14 @@ def _get_cs_element_map(
# model = get_model(element_map["blobs_labels"])
# if model in [Image2DModel, Image3DModel, Labels2DModel, Labels3DModel]
return d


def _multiscale_to_image(sdata: sd.SpatialData) -> sd.SpatialData:
if sdata.images is None:
raise ValueError("No images found in the SpatialData object.")

for k, v in sdata.images.items():
if isinstance(v, msi.multiscale_spatial_image.MultiscaleSpatialImage):
sdata.images[k] = Image2DModel.parse(v["scale0"].ds.to_array().squeeze(axis=0))

return sdata