Skip to content

The bounding_box() doesn't apply the order of the axes from the function call to the transcripts #1175

Description

@dariarom94

Issue occurs in certain case

  • points elements contain 3D coordinates {x, y, z}
  • query a 2D-cut with {y, x}
  • element is transformed

Toy example

importspatialdataassdimportspatialdata_plotimportnumpyasnpfromspatialdata.modelsimportPointsModelfromspatialdata.transformationsimportset_transformation, Scalefromspatialdata.datasetsimportblobsdf=blobs()["blobs_points"].compute()[["x", "y", "genes"]].copy()
df["z"] =np.random.default_rng(0).uniform(
0, 10, len(df)
) # add 3D, as real readers emitpts3d=PointsModel.parse(df, feature_key="genes") # createset_transformation(pts3d, Scale([0.5, 2.0], axes=("x", "y")), "global") # non-Identitysdata_3d=sd.SpatialData(points={"transcripts": pts3d})
X0, X1, Y0, Y1=60, 240, 20, 160forqaxes, mn, mxin [
(["x", "y"], [X0, Y0], [X1, Y1]),
(["y", "x"], [Y0, X0], [Y1, X1]),
]:
r=sdata_3d.query.bounding_box(
axes=qaxes,
min_coordinate=mn,
max_coordinate=mx,
target_coordinate_system="global",
)
n=len(r["transcripts"]) if"transcripts"inr.pointselse"element dropped"print(f"axes={str(qaxes):14s} -> {n}")
r.pl.render_points("transcripts", color="genes", size=3).pl.show(
colorbar=False, legend_loc=None, title="All transcripts"
)

Output:
axes=['x', 'y'] -> 25
axes=['y', 'x'] -> 16

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions