troutpy.tl.calculate_heuristic_radius_by_cells#
- troutpy.tl.calculate_heuristic_radius_by_cells(sdata, k=10, n_cells=500, segmentation_key='overlaps_cell')#
Estimate a neighbor-distance radius from the local geometry of a sample of cells.
Randomly selects
n_cellscells and computes the mean distance to each transcript’sk-th nearest neighbor among the transcripts of those cells.- Parameters:
sdata (spatialdata.SpatialData) – SpatialData object with a
"transcripts"points layer containingx,y,cell_id, andsegmentation_keycolumns.k (int, optional) – Neighbor rank used for the distance heuristic. Defaults to
10.n_cells (int, optional) – Number of cells to randomly sample. Defaults to
500.segmentation_key (str, optional) – Boolean column used to restrict the sampled transcripts to those that overlap a cell. Defaults to
"overlaps_cell".
- Returns:
float Mean distance to the
k-th nearest neighbor across the sampled transcripts.- Raises:
ValueError – If no valid (non-
UNASSIGNED) cells are found, or if fewer thank + 1transcripts remain after filtering bysegmentation_key.