Skip to content

Commit f88d7ad

Browse files
committed
WIP
1 parent 56fff15 commit f88d7ad

File tree

2 files changed

+194
-29
lines changed

2 files changed

+194
-29
lines changed

docs/notebooks/spatial_data_kpmp.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
import spatialdata
21-
from spatialdata import SpatialData
21+
from spatialdata import SpatialData, to_polygons
2222
from spatialdata.models import Image2DModel, Labels2DModel, TableModel
2323
from spatialdata.transformations import (
2424
Affine,
@@ -91,6 +91,10 @@
9191
def clean_adata(adata):
9292
colnames = adata.obs.columns.tolist()
9393
adata.obs = adata.obs.rename(columns=dict([ (c, c.replace(" ", "_")) for c in colnames ]))
94+
# Many of the anndata objects contain un-helpful obs indices with entirely zero values like [0, 0, 0, 0]
95+
# TODO: determine whether using 1...N+1 in these cases is correct.
96+
if adata.obs.index.unique().shape[0] == 1:
97+
adata.obs.index = range(1, adata.obs.shape[0]+1)
9498
return adata
9599

96100

@@ -117,6 +121,10 @@ def clean_adata(adata):
117121

118122
# In[ ]:
119123

124+
for labels_key in sdata.labels.keys():
125+
shapes_key = "shapes" + labels_key[labels_key.index("_"):]
126+
sdata.shapes[shapes_key] = to_polygons(sdata.labels[labels_key])
127+
120128

121129
sdata.write(join(base_dir, "sdata.zarr"), overwrite=True)
122130
print(join(base_dir, "sdata.zarr"))

0 commit comments

Comments
 (0)