Skip to content

Commit 422328f

Browse files
authored
Closes issue 69 (#98)
1 parent 1ba0d66 commit 422328f

File tree

2 files changed

+236
-207
lines changed

2 files changed

+236
-207
lines changed

src/spatialdata_plot/pl/basic.py

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def _copy(
139139

140140
def render_shapes(
141141
self,
142-
element: str | None = None,
142+
elements: str | list[str] | None = None,
143143
color: str | None = None,
144144
groups: str | Sequence[str] | None = None,
145145
size: float = 1.0,
@@ -161,8 +161,8 @@ def render_shapes(
161161
162162
Parameters
163163
----------
164-
element
165-
The name of the shapes element to render. If `None`, the first
164+
elements
165+
The name of the shapes element(s) to render. If `None`, all
166166
shapes element in the `SpatialData` object will be used.
167167
color
168168
Key for annotations in :attr:`anndata.AnnData.obs` or variables/genes.
@@ -209,7 +209,7 @@ def render_shapes(
209209
)
210210
outline_params = _set_outline(size, outline, outline_width, outline_color)
211211
sdata.plotting_tree[f"{n_steps+1}_render_shapes"] = ShapesRenderParams(
212-
element=element,
212+
elements=elements,
213213
color=color,
214214
groups=groups,
215215
outline_params=outline_params,
@@ -226,7 +226,7 @@ def render_shapes(
226226

227227
def render_points(
228228
self,
229-
element: str | None = None,
229+
elements: str | list[str] | None = None,
230230
color: str | None = None,
231231
groups: str | Sequence[str] | None = None,
232232
size: float = 1.0,
@@ -242,8 +242,8 @@ def render_points(
242242
243243
Parameters
244244
----------
245-
element
246-
The name of the points element to render. If `None`, the first
245+
elements
246+
The name of the points element(s) to render. If `None`, all
247247
shapes element in the `SpatialData` object will be used.
248248
color
249249
Key for annotations in :attr:`anndata.AnnData.obs` or variables/genes.
@@ -279,7 +279,7 @@ def render_points(
279279
**kwargs,
280280
)
281281
sdata.plotting_tree[f"{n_steps+1}_render_points"] = PointsRenderParams(
282-
element=element,
282+
elements=elements,
283283
color=color,
284284
groups=groups,
285285
cmap_params=cmap_params,
@@ -293,7 +293,7 @@ def render_points(
293293

294294
def render_images(
295295
self,
296-
element: str | None = None,
296+
elements: str | list[str] | None = None,
297297
channel: list[str] | list[int] | int | str | None = None,
298298
cmap: Colormap | str | None = None,
299299
norm: Optional[Normalize] = None,
@@ -307,9 +307,9 @@ def render_images(
307307
308308
Parameters
309309
----------
310-
element
311-
The name of the image element to render. If `None`, the first
312-
shapes element in the `SpatialData` object will be used.
310+
elements
311+
The name of the image element(s) to render. If `None`, all
312+
shapes elements in the `SpatialData` object will be used.
313313
channel
314314
To select which channel to plot (all by default).
315315
cmap
@@ -338,7 +338,7 @@ def render_images(
338338
**kwargs,
339339
)
340340
sdata.plotting_tree[f"{n_steps+1}_render_images"] = ImageRenderParams(
341-
element=element,
341+
elements=elements,
342342
channel=channel,
343343
cmap_params=cmap_params,
344344
palette=palette,
@@ -349,7 +349,7 @@ def render_images(
349349

350350
def render_labels(
351351
self,
352-
element: str | None = None,
352+
elements: str | list[str] | None = None,
353353
color: str | None = None,
354354
groups: str | Sequence[str] | None = None,
355355
contour_px: int = 3,
@@ -369,9 +369,9 @@ def render_labels(
369369
370370
Parameters
371371
----------
372-
element
373-
The name of the labels element to render. If `None`, the first
374-
labels element in the `SpatialData` object will be used.
372+
elements
373+
The name of the labels element(s) to render. If `None`, all
374+
labels elements in the `SpatialData` object will be used.
375375
color
376376
Key for annotations in :attr:`anndata.AnnData.obs` or variables/genes.
377377
groups
@@ -420,7 +420,7 @@ def render_labels(
420420
**kwargs,
421421
)
422422
sdata.plotting_tree[f"{n_steps+1}_render_labels"] = LabelsRenderParams(
423-
element=element,
423+
elements=elements,
424424
color=color,
425425
groups=groups,
426426
contour_px=contour_px,
@@ -523,6 +523,15 @@ def show(
523523
# Simplicstic solution: If the images are multiscale, just use the first
524524
sdata = _multiscale_to_image(sdata)
525525

526+
# handle coordinate system
527+
coordinate_systems = sdata.coordinate_systems if coordinate_systems is None else coordinate_systems
528+
if isinstance(coordinate_systems, str):
529+
coordinate_systems = [coordinate_systems]
530+
531+
for cs in coordinate_systems:
532+
if cs not in sdata.coordinate_systems:
533+
raise ValueError(f"Unknown coordinate system '{cs}', valid choices are: {sdata.coordinate_systems}")
534+
526535
extent = _get_extent(
527536
sdata=sdata,
528537
has_images="render_images" in render_cmds,
@@ -532,11 +541,6 @@ def show(
532541
coordinate_systems=coordinate_systems,
533542
)
534543

535-
# handle coordinate system
536-
coordinate_systems = sdata.coordinate_systems if coordinate_systems is None else coordinate_systems
537-
if isinstance(coordinate_systems, str):
538-
coordinate_systems = [coordinate_systems]
539-
540544
# Use extent to filter out coordinate system without the relevant elements
541545
valid_cs = []
542546
for cs in coordinate_systems:
@@ -546,13 +550,18 @@ def show(
546550
logg.info(f"Dropping coordinate system '{cs}' since it doesn't have relevant elements.")
547551
coordinate_systems = valid_cs
548552

553+
# print(coordinate_systems)
554+
# cs_mapping = _get_coordinate_system_mapping(sdata)
555+
# print(cs_mapping)
556+
549557
# check that coordinate system and elements to be rendered match
550-
for cmd, params in render_cmds.items():
551-
if params.element is not None and len([params.element]) != len(coordinate_systems):
552-
raise ValueError(
553-
f"Number of coordinate systems ({len(coordinate_systems)}) does not match number of elements "
554-
f"({len(params.element)}) in command {cmd}."
555-
)
558+
# for cmd, params in render_cmds.items():
559+
# if params.elements is not None and len([params.elements]) != len(coordinate_systems):
560+
# print(params.elements)
561+
# raise ValueError(
562+
# f"Number of coordinate systems ({len(coordinate_systems)}) does not match number of elements "
563+
# f"({len(params.elements)}) in command {cmd}."
564+
# )
556565

557566
# set up canvas
558567
fig_params, scalebar_params = _prepare_params_plot(

0 commit comments

Comments
 (0)