forked from scverse/spatialdata-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
54 lines (36 loc) · 1.89 KB
/
utils.py
File metadata and controls
54 lines (36 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from collections import OrderedDict
import spatialdata as sd
from spatialdata.transformations import get_transformation
def _verify_plotting_tree(sdata: sd.SpatialData) -> sd.SpatialData:
"""Verify that the plotting tree exists, and if not, create it."""
if not hasattr(sdata, "plotting_tree"):
sdata.plotting_tree = OrderedDict()
return sdata
def _get_coordinate_system_mapping(sdata: sd.SpatialData) -> dict[str, list[str]]:
coordsys_keys = sdata.coordinate_systems
image_keys = [] if sdata.images is None else sdata.images.keys()
label_keys = [] if sdata.labels is None else sdata.labels.keys()
shape_keys = [] if sdata.shapes is None else sdata.shapes.keys()
point_keys = [] if sdata.points is None else sdata.points.keys()
mapping: dict[str, list[str]] = {}
if len(coordsys_keys) < 1:
raise ValueError("SpatialData object must have at least one coordinate system to generate a mapping.")
for key in coordsys_keys:
mapping[key] = []
for image_key in image_keys:
transformations = get_transformation(sdata.images[image_key], get_all=True)
if key in list(transformations.keys()):
mapping[key].append(image_key)
for label_key in label_keys:
transformations = get_transformation(sdata.labels[label_key], get_all=True)
if key in list(transformations.keys()):
mapping[key].append(label_key)
for shape_key in shape_keys:
transformations = get_transformation(sdata.shapes[shape_key], get_all=True)
if key in list(transformations.keys()):
mapping[key].append(shape_key)
for point_key in point_keys:
transformations = get_transformation(sdata.points[point_key], get_all=True)
if key in list(transformations.keys()):
mapping[key].append(point_key)
return mapping