make_stitched_labels#
- squidpy.experimental.tl.make_stitched_labels(sdata, *, labels_key, qc_table_key=None, labels_key_added=None, table_key_added=None, write_table=True, merge_strategy='sum', join_labels=False, join_close_radius=3, inplace=True)[source]#
Materialise a stitched labels element from an assign_stitch_groups result.
Registers a new labels element where each stitched group shares one ID; the original is left unmodified. With
write_table=Truea companion table is written too, one row perstitch_group_id, groups collapsed bymerge_strategy.- Parameters:
- sdata
SpatialData SpatialDatawith a labels element and a QC table that has been processed bysquidpy.experimental.tl.assign_stitch_groups().- labels_key
str Key in
sdata.labelsof the original labels element.- qc_table_key
str|None(default:None) Key of the QC table. Defaults to
"{labels_key}_qc".- labels_key_added
str|None(default:None) Key for the new labels element. Defaults to
"{labels_key}_stitched". Existing element at this key is overwritten with a warning.- table_key_added
str|None(default:None) Key for the optional collapsed AnnData (one row per unique
stitch_group_id). Defaults to"{labels_key_added}_table"(must differ from the labels element key – SpatialData requires unique names across element types).- write_table
bool(default:True) If
True, also write the collapsed AnnData tosdata.tables[table_key_added].- merge_strategy
str|Callable[[Series],object] (default:'sum') How to aggregate genuine numeric user feature columns in
.obsand all of.Xacross the 2-4 pieces of each stitched cell. String options:"sum"(default, for additive features like area / intensity),"min","max","mean","median","first". Callable: receives apandas.Series(one column of one group’s members) and returns a scalar; applied column-wise to.obsand.X.merge_strategydoes not apply to the columns below, which are handled automatically (so a stray"sum"can’t corrupt them):Group-invariant columns (
stitch_group_id,is_stitched,n_pieces,stitch_confidence,region) and any non-numeric column -> first member’s value.centroid_y/centroid_x-> mean of the pieces’ centroids.QC cut-artifact scores (
cut_score,smoothed_cut_score,max_straight_edge_ratio,cardinal_alignment_score,nhood_outlier_fraction,is_outlier) -> max (worst piece).
- join_labels
bool(default:False) If
True, morphologically close the gap between pieces of each stitched group, so a group that the basic remap leaves as several components sharing an ID becomes a single connected component. Only background pixels inside each group’s closed hull are filled; other cells are never overwritten. This stays lazy on dask input (a per-blockdask.array.map_overlap()pass, never materialising the whole image). Closing bridges seams up to2 * join_close_radiuspx wide; pieces separated by a wider gap stay disconnected – raisejoin_close_radiusfor those. DefaultFalsepreserves the original gap pixels.- join_close_radius
int(default:3) Radius (px) of the disk structuring element used when
join_labels=True. Default3matches the closing radius used during scoring; raise it if pieces remain disconnected after joining.- inplace
bool(default:True) If
True, write the new labels element (and table whenwrite_table=True) intosdata. IfFalse, return the materialised objects in a dict{"labels": ..., "table": ...}without mutatingsdata;"table"isNonewhenwrite_table=False.
- sdata
- Returns:
dict[str,object] |None– Ifinplace = False, the materialised{"labels": ..., "table": ...}. Otherwise None, and the elements are written tosdata.