Skip to content

Commit 570e850

Browse files
committed
add function to get shape of image like element irrespective of number of scales
1 parent 8815e72 commit 570e850

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
@@ -2,10 +2,28 @@
22

33
from spatialdata import SpatialData
44
from spatialdata.models import get_model
5+
from xarray import DataArray, DataTree
56

67
ObjectType: TypeAlias = Literal["images", "labels", "points", "tables", "shapes"]
78

89

10+
def _get_shape(elem: DataArray | DataTree) -> tuple[int, int] | tuple[int, int, int]:
11+
"""Get the shape of the element.
12+
13+
Args:
14+
elem: Element to get the shape of
15+
16+
Returns:
17+
Tuple of the shape of the element
18+
"""
19+
if isinstance(elem, DataArray):
20+
return elem.shape
21+
elif isinstance(elem, DataTree):
22+
return elem.scale0.image.shape
23+
else:
24+
raise ValueError(f"Element type {type(elem)} not supported.")
25+
26+
927
def _make_key_lookup(sdata: SpatialData) -> dict:
1028
"""Make a lookup dictionary for the keys in the SpatialData object.
1129

0 commit comments

Comments
 (0)