sddb.loader.Centroids#
- class sddb.loader.Centroids#
Each cell's centre of mass in
labels["cells"]asobsm["spatial"](x, y), in table row order.The pixel sums per label run block by block and are reduced over the blocks. No row is dropped. A row whose label has no pixel (a cell smaller than a pixel of the written grid) takes:
labels cells: its centre of mass in the source labels at native resolution (
item.native_cells), mapped to the written grid by that element's own transformation. This costs one more block pass over the source labels, only when a cell has no pixel. The table's centroid is not used, since its frame is the reader's (microns for Xenium and Atera in spatialdata-io, against labels in pixels).shape cells, in this order: the centroid of its polygon (
item.shape_centroids, set byRasterize); then the source table's centroid (obsm["spatial"],item.table_centroids). Readers put it in different frames (microns for Atera, pixels for CODEX, DNB units for Stereo-seq in spatialdata-io), and spatialdata gives a table no transformation, soRasterizemaps it as intrinsic coordinates of the element the table annotates (that element's transformation), and this step checks the mapping on up to_TABLE_CHECK_ROWScells that have pixels: the median distance to their pixel centroid must be at most_TABLE_CENTROID_PX, else it raises, asobsm["spatial"]is then not in that element's frame.
The count goes to
item.n_centroid_fallbackand into the contract asn_centroid_fallback, and is logged.A fallback centroid keeps its true position, also outside the written grid (a cell of the labels that lies beyond the H&E).
obs["outside_image"]is True for every row whose centroid is not on the image's footprint: the quadrilateral of the source image's scale-0 extent mapped onto the grid (item.image_footprint, set byRasterizewith the affine it resamples the image with), points on its edge counting as on it, or whose centroid lies outside[0, w) x [0, h). With a rotated image the grid's corners are fill, so a cell there is flagged too. The count goes toitem.n_outside_imageand into the contract asn_outside_image.- Raises:
ValueError -- If a row has no pixel and no fallback (labels cells: no pixel in the native labels either; shape cells: no polygon centroid and no usable table centroid), or if the table centroids are not in the frame of the element the table annotates (the check above).
Attributes table#
Methods table#
build(sdata)Return the item with
obsm["spatial"]andobs["label_id"], one centroid per row.from_record(rec)Rebuild the step from
to_record()'s output.labels["cells"].The step as an
AdapterRecordthatfrom_record()rebuilds.validate(sdata)Require
labels["cells"].validate_meta(meta)No catalog metadata decides these steps; the checks run on the item in
validate().Attributes#
Methods#
- build(sdata: LoaderItem) LoaderItem#
Return the item with
obsm["spatial"]andobs["label_id"], one centroid per row.
- classmethod from_record(rec: AdapterRecord) Self#
Rebuild the step from
to_record()'s output.- Raises:
ValueError -- If the record is of another adapter or another version.
- to_record() AdapterRecord#
The step as an
AdapterRecordthatfrom_record()rebuilds.
- validate(sdata: LoaderItem) list[str]#
Require
labels["cells"].
- validate_meta(meta: ObjectMeta) list[str]#
No catalog metadata decides these steps; the checks run on the item in
validate().