rapids_singlecell.gr.spatial_neighbors_from_builder#
- rapids_singlecell.gr.spatial_neighbors_from_builder(adata, builder, *, spatial_key='spatial', table_key=None, elements_to_coordinate_systems=None, library_key=None, key_added='spatial', copy=False)[source]#
Build spatial graphs with a built-in or custom builder.
builder.build(coords)receives finite float32 CuPy coordinates and returns connectivity and distance matrices;uns_params()supplies the metadata. Withlibrary_key,combine(graphs, indices)merges the per-library graphs in observation order. Builders fromrapids_singlecell.gr.neighborswith built-in postprocessors build all libraries in one pass.- Parameters:
- adata
AnnData|SpatialData Annotated data matrix, or a SpatialData object containing the selected table. SpatialData is optional and imported only for SpatialData input.
- builder
GraphBuilder Graph construction strategy.
build(coords)receives finite float32 CuPy coordinates and returns connectivity and distance matrices.uns_params()supplies metadata;combine(graphs, indices)must support independent libraries whenlibrary_keyis used.- spatial_key
str(default:'spatial') Key in
adata.obsmcontaining coordinates. For SpatialData, transformed element centroids (x, y) are written here in table observation order.- table_key
str|None(default:None) Key in
SpatialData.tables. Required for SpatialData input; ignored for AnnData input.- elements_to_coordinate_systems
dict[str,str] |None(default:None) Mapping from spatial element names to coordinate system names. Required for SpatialData input and must cover all regions annotated by the table. Graphs are built independently per region; ignored for AnnData input.
- library_key
str|None(default:None) Categorical column in
adata.obsdefining independent libraries. For SpatialData, the table region key is used instead.- key_added
str(default:'spatial') Prefix for graph keys in
adata.obspand neighbor metadata inadata.uns. For SpatialData, results are stored in the selected table.- copy
bool(default:False) Return the graph matrices instead of storing graphs and metadata. For SpatialData, centroid coordinates are still written to the table.
- adata
- Return type:
- Returns:
SpatialNeighborsResult | None With
copy=True, return connectivity and distance matrices as SciPy CSR matrices. Built-in builders store float32 connectivities and distances; Squidpy stores Euclidean distances as float64. Otherwise, returnNoneand store'{key_added}_connectivities'and'{key_added}_distances'inadata.obsp, and graph parameters inadata.uns['{key_added}_neighbors']. For SpatialData,adatahere denotes the selected table.