rapids_singlecell.gr.spatial_neighbors_radius#

rapids_singlecell.gr.spatial_neighbors_radius(adata, *, radius, spatial_key='spatial', table_key=None, elements_to_coordinate_systems=None, library_key=None, percentile=None, transform=None, set_diag=False, key_added='spatial', copy=False)[source]#

Connect observations within an inclusive radius.

A pair radius is an interval: neighbors up to its maximum are found, then shorter edges are pruned before percentile. Zero connects coincident points.

Parameters:
adata AnnData | SpatialData

Annotated data matrix, or a SpatialData object containing the selected table. SpatialData is optional and imported only for SpatialData input.

radius float | tuple[float, float]

Maximum inclusive Euclidean distance, or an inclusive (min, max) interval. Zero connects coincident observations.

spatial_key str (default: 'spatial')

Key in adata.obsm containing 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.obs defining independent libraries. For SpatialData, the table region key is used instead.

percentile float | None (default: None)

Prune edges above this distance percentile (0 to 100) independently per library, after radius pruning. Stored zeros, including the diagonal, contribute to the percentile. None disables percentile pruning.

transform Literal['spectral', 'cosine'] | None (default: None)

Connectivity transform: None, "spectral" (normalization by column degrees), or "cosine" (similarity between connectivity rows). Applied after pruning and adding the requested diagonal; distances are unchanged.

set_diag bool (default: False)

Whether to set connectivity self-loops before transforming the graph. Distance diagonals are zero; cosine can create connectivity self-loops even when this is False.

key_added str (default: 'spatial')

Prefix for graph keys in adata.obsp and neighbor metadata in adata.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.

Return type:

SpatialNeighborsResult | None

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, return None and store '{key_added}_connectivities' and '{key_added}_distances' in adata.obsp, and graph parameters in adata.uns['{key_added}_neighbors']. For SpatialData, adata here denotes the selected table.