Skip to content

Commit 8815e72

Browse files
committed
generate dict to look up which spatialdata element is attributed to which element type
1 parent 6adbdab commit 8815e72

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/scportrait/spdata/write/_helper.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@
66
ObjectType: TypeAlias = Literal["images", "labels", "points", "tables", "shapes"]
77

88

9+
def _make_key_lookup(sdata: SpatialData) -> dict:
10+
"""Make a lookup dictionary for the keys in the SpatialData object.
11+
12+
Args:
13+
sdata: SpatialData object
14+
15+
Returns:
16+
Dictionary of the keys in the SpatialData object
17+
"""
18+
dict_lookup: dict[str, list[str]] = {}
19+
for elem in sdata.elements_paths_in_memory():
20+
key, name = elem.split("/")
21+
if key not in dict_lookup:
22+
dict_lookup[key] = []
23+
dict_lookup[key].append(name)
24+
return dict_lookup
25+
26+
927
def _force_delete_object(sdata: SpatialData, name: str) -> None:
1028
"""Force delete an object from the SpatialData object and directory.
1129

0 commit comments

Comments
 (0)