Skip to content

Commit

Permalink
force 3D points to 2D xy. fixes #161
Browse files Browse the repository at this point in the history
  • Loading branch information
ckmah committed Oct 15, 2024
1 parent d4d4071 commit ef986c2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions bento/io/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List, Union

import emoji
import spatialdata as sd
from anndata.utils import make_index_unique
from spatialdata import SpatialData
from spatialdata.models import TableModel
Expand Down Expand Up @@ -57,6 +58,21 @@ def prep(
shape_gdf[shape_key] = shape_gdf["geometry"]
shape_gdf.index = make_index_unique(shape_gdf.index.astype(str))

if "global" in sdata.points[points_key].attrs["transform"]:
# Force points to 2D for Xenium data
xyz_scale = sd.transformations.get_transformation(sdata.points[points_key])
if isinstance(xyz_scale, sd.transformations.Scale):
xy_scale = sd.transformations.Scale(
scale=xyz_scale.to_scale_vector(["x", "y"]), axes=["x", "y"]
)
sdata.points[points_key] = sd.models.PointsModel.parse(
sdata.points[points_key].compute().reset_index(drop=True),
coordinates={"x": "x", "y": "y"},
feature_key=feature_key,
instance_key=instance_key,
transform=xy_scale,
)

# sindex points and sjoin shapes if they have not been indexed or joined
point_sjoin = []
shape_sjoin = []
Expand Down

0 comments on commit ef986c2

Please sign in to comment.