Skip to content

Commit 9db456f

Browse files
timtreisclaude
andcommitted
feat(centroids): add return_area + SpatialData persist to get_centroids
Surface the per-instance area that the labels bincount already computes (and geometric area for shapes), and add a SpatialData dispatch that writes centroids/area into the element's annotating table, squidpy-style. - `return_area` on all element overloads: labels return the pixel/voxel count (free, already computed); shapes return `pi*r**2` for circles and `geometry.area` for polygons; points raise. Carried as a feature column on the returned Points element. - Harmonise the three element overload signatures (they previously disagreed on `return_background`). - New `get_centroids(sdata, element_name, ..., persist_as="adata")` dispatch: resolves the element's annotating table and writes `obsm["spatial"]` (x, y[, z]) and `obs["area"]` at the element's rows, in place. Raises (pointing to `persist_as="Points"`) when no table annotates the element. No standalone AnnData is ever created. - Element-level `persist_as="adata"` raises, directing to the SpatialData form (which can resolve the table). - Fast path: the table-writing path applies the coordinate transform to the tiny per-instance centroid array in-memory and short-circuits when it is an identity, avoiding the dask `transform()` round-trip. `coordinate_system=None` returns intrinsic coordinates. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent af51100 commit 9db456f

2 files changed

Lines changed: 372 additions & 47 deletions

File tree

0 commit comments

Comments
 (0)