23
23
from spatialdata ._core .data_extent import get_extent
24
24
25
25
from spatialdata_plot ._accessor import register_spatial_data_accessor
26
+ from spatialdata_plot ._utils import deprecation_alias
26
27
from spatialdata_plot .pl .render import (
27
28
_render_images ,
28
29
_render_labels ,
50
51
_prepare_params_plot ,
51
52
_set_outline ,
52
53
_update_params ,
54
+ _validate_image_render_params ,
53
55
_validate_render_params ,
54
56
_validate_show_parameters ,
55
57
save_fig ,
@@ -390,59 +392,63 @@ def render_points(
390
392
391
393
return sdata
392
394
395
+ @deprecation_alias (elements = "element" , quantiles_for_norm = "percentiles_for_norm" , version = "version 0.3.0" )
393
396
def render_images (
394
397
self ,
395
- elements : list [ str ] | str | None = None ,
398
+ element : str | None = None ,
396
399
channel : list [str ] | list [int ] | str | int | None = None ,
397
- cmap : list [Colormap ] | Colormap | str | None = None ,
400
+ cmap : list [Colormap | str ] | Colormap | str | None = None ,
398
401
norm : Normalize | None = None ,
399
402
na_color : ColorLike | None = (0.0 , 0.0 , 0.0 , 0.0 ),
400
- palette : list [list [ str | None ]] | list [ str | None ] | str | None = None ,
403
+ palette : list [str ] | str | None = None ,
401
404
alpha : float | int = 1.0 ,
402
- quantiles_for_norm : tuple [float | None , float | None ] | None = None ,
403
- scale : list [ str ] | str | None = None ,
405
+ percentiles_for_norm : tuple [float , float ] | None = None ,
406
+ scale : str | None = None ,
404
407
** kwargs : Any ,
405
408
) -> sd .SpatialData :
406
409
"""
407
410
Render image elements in SpatialData.
408
411
412
+ In case of no elements specified, "broadcasting" of parameters is applied. This means that for any particular
413
+ SpatialElement, we validate whether a given parameter is valid. If not valid for a particular SpatialElement the
414
+ specific parameter for that particular SpatialElement will be ignored. If you want to set specific parameters
415
+ for specific elements please chain the render functions: `pl.render_images(...).pl.render_images(...).pl.show()`
416
+ .
417
+
409
418
Parameters
410
419
----------
411
- elements : list[str] | str | None, optional
412
- The name(s) of the image element(s) to render. If `None`, all image
413
- elements in the `SpatialData` object will be used. If a string is provided,
414
- it is converted into a single-element list.
415
- channel : list[str] | list[int] | str | int | None, optional
420
+ element : str | None
421
+ The name of the image element to render. If `None`, all image
422
+ elements in the `SpatialData` object will be used.
423
+ channels : list[str] | list[int] | str | int | None, optional
416
424
To select specific channels to plot. Can be a single channel name/int or a
417
425
list of channel names/ints. If `None`, all channels will be used.
418
- cmap : list[Colormap] | Colormap | str | None, optional
426
+ cmap : list[Colormap | str ] | Colormap | str | None, optional
419
427
Colormap or list of colormaps for continuous annotations, see :class:`matplotlib.colors.Colormap`.
420
428
Each colormap applies to a corresponding channel.
421
429
norm : Normalize | None, optional
422
430
Colormap normalization for continuous annotations, see :class:`matplotlib.colors.Normalize`.
423
431
Applies to all channels if set.
424
432
na_color : ColorLike | None, default (0.0, 0.0, 0.0, 0.0)
425
433
Color to be used for NA values. Accepts color-like values (string, hex, RGB(A)).
426
- palette : list[list[ str | None]] | list[str | None] | str | None
434
+ palette : list[str] | None
427
435
Palette to color images. In the case of a list of
428
436
lists means that there is one list per element to be plotted in the list and this list contains the string
429
437
indicating the palette to be used. If not provided as list of lists, broadcasting behaviour is
430
438
attempted (use the same values for all elements).
431
439
alpha : float | int, default 1.0
432
440
Alpha value for the images. Must be a numeric between 0 and 1.
433
- quantiles_for_norm : tuple[float | None , float | None ] | None, optional
441
+ percentiles_for_norm : tuple[float, float] | None
434
442
Optional pair of floats (pmin < pmax, 0-100) which will be used for quantile normalization.
435
- scale : list[ str] | str | None, optional
443
+ scale : str | None
436
444
Influences the resolution of the rendering. Possibilities include:
437
445
1) `None` (default): The image is rasterized to fit the canvas size. For
438
446
multiscale images, the best scale is selected before rasterization.
439
- 2) A scale name: Renders the specified scale as-is (with adjustments for dpi
440
- in `show()`).
447
+ 2) A scale name: Renders the specified scale ( of a multiscale image) as-is
448
+ (with adjustments for dpi in `show()`).
441
449
3) "full": Renders the full image without rasterization. In the case of
442
450
multiscale images, the highest resolution scale is selected. Note that
443
451
this may result in long computing times for large images.
444
- 4) A list matching the list of elements. Can contain `None`, scale names, or
445
- "full". Each scale applies to the corresponding element.
446
452
kwargs
447
453
Additional arguments to be passed to cmap, norm, and other rendering functions.
448
454
@@ -451,19 +457,19 @@ def render_images(
451
457
sd.SpatialData
452
458
The SpatialData object with the rendered images.
453
459
"""
454
- params_dict = _validate_render_params (
455
- "images" ,
460
+ params_dict = _validate_image_render_params (
456
461
self ._sdata ,
457
- elements = elements ,
462
+ element = element ,
458
463
channel = channel ,
459
464
alpha = alpha ,
460
465
palette = palette ,
461
466
na_color = na_color ,
462
467
cmap = cmap ,
463
468
norm = norm ,
464
469
scale = scale ,
465
- quantiles_for_norm = quantiles_for_norm ,
470
+ percentiles_for_norm = percentiles_for_norm ,
466
471
)
472
+
467
473
sdata = self ._copy ()
468
474
sdata = _verify_plotting_tree (sdata )
469
475
n_steps = len (sdata .plotting_tree .keys ())
@@ -488,15 +494,17 @@ def render_images(
488
494
** kwargs ,
489
495
)
490
496
491
- sdata .plotting_tree [f"{ n_steps + 1 } _render_images" ] = ImageRenderParams (
492
- elements = params_dict ["elements" ],
493
- channel = channel ,
494
- cmap_params = cmap_params ,
495
- palette = params_dict ["palette" ],
496
- alpha = alpha ,
497
- quantiles_for_norm = params_dict ["quantiles_for_norm" ],
498
- scale = params_dict ["scale" ],
499
- )
497
+ for element , param_values in params_dict .items ():
498
+ sdata .plotting_tree [f"{ n_steps + 1 } _render_images" ] = ImageRenderParams (
499
+ element = element ,
500
+ channel = param_values ["channel" ],
501
+ cmap_params = cmap_params ,
502
+ palette = param_values ["palette" ],
503
+ alpha = param_values ["alpha" ],
504
+ percentiles_for_norm = param_values ["percentiles_for_norm" ],
505
+ scale = param_values ["scale" ],
506
+ )
507
+ n_steps += 1
500
508
501
509
return sdata
502
510
0 commit comments