1010import numpy as np
1111import pandas as pd
1212import scanpy as sc
13+ import spatial_image
1314import spatialdata as sd
1415from anndata import AnnData
1516from geopandas import GeoDataFrame
1920from matplotlib .patches import Circle , Polygon
2021from pandas .api .types import is_categorical_dtype
2122from scanpy ._settings import settings as sc_settings
23+ from spatialdata .models import (
24+ Image2DModel ,
25+ Labels2DModel ,
26+ )
2227
2328from spatialdata_plot ._logging import logger
2429from spatialdata_plot .pl .utils import (
@@ -342,8 +347,11 @@ def _render_images(
342347 elements = list (sdata_filt .images .keys ())
343348
344349 images = [sdata .images [e ] for e in elements ]
350+ for img , img_key in zip (images , elements ):
351+ if not isinstance (img , spatial_image .SpatialImage ):
352+ img = Image2DModel .parse (img ["scale0" ].ds .to_array ().squeeze (axis = 0 ))
353+ logger .warning (f"Multi-scale images not yet supported, using scale0 of multi-scale image '{ img_key } '." )
345354
346- for img in images :
347355 if render_params .channel is None :
348356 channels = img .coords ["c" ].values
349357 else :
@@ -512,17 +520,21 @@ def _render_labels(
512520 if elements is None :
513521 elements = list (sdata_filt .labels .keys ())
514522
515- labels = [sdata .labels [e ].values for e in elements ]
523+ labels = [sdata .labels [e ] for e in elements ]
524+
525+ for label , label_key in zip (labels , elements ):
526+ if not isinstance (label , spatial_image .SpatialImage ):
527+ label = Labels2DModel .parse (label ["scale0" ].ds .to_array ().squeeze (axis = 0 ))
528+ logger .warning (f"Multi-scale labels not yet supported, using scale0 of multi-scale label '{ label_key } '." )
516529
517- for label , labels_key in zip (labels , elements ):
518530 if sdata .table is None :
519531 instance_id = np .unique (label )
520532 table = AnnData (None , obs = pd .DataFrame (index = np .arange (len (instance_id ))))
521533 else :
522534 instance_key = _get_instance_key (sdata )
523535 region_key = _get_region_key (sdata )
524536
525- table = sdata .table [sdata .table .obs [region_key ].isin ([labels_key ])]
537+ table = sdata .table [sdata .table .obs [region_key ].isin ([label_key ])]
526538
527539 # get isntance id based on subsetted table
528540 instance_id = table .obs [instance_key ].values
@@ -542,7 +554,7 @@ def _render_labels(
542554 if (render_params .fill_alpha != render_params .outline_alpha ) and render_params .contour_px is not None :
543555 # First get the labels infill and plot them
544556 labels_infill = _map_color_seg (
545- seg = label ,
557+ seg = label . values ,
546558 cell_id = instance_id ,
547559 color_vector = color_vector ,
548560 color_source_vector = color_source_vector ,
@@ -565,7 +577,7 @@ def _render_labels(
565577
566578 # Then overlay the contour
567579 labels_contour = _map_color_seg (
568- seg = label ,
580+ seg = label . values ,
569581 cell_id = instance_id ,
570582 color_vector = color_vector ,
571583 color_source_vector = color_source_vector ,
0 commit comments