spatialvi.data.compute_spatial_neighbors

spatialvi.data.compute_spatial_neighbors#

spatialvi.data.compute_spatial_neighbors(adata, spatial_key='spatial', n_neighbors=20, index_key='nn_index', dist_key='nn_dist', metric='euclidean', copy=False)[source]#

Compute spatial nearest neighbors.

Parameters:
  • adata (AnnData) – AnnData object with spatial coordinates.

  • spatial_key (str) – Key in obsm for spatial coordinates.

  • n_neighbors (int) – Number of neighbors to compute.

  • index_key (str) – Key to store neighbor indices in obsm.

  • dist_key (str) – Key to store neighbor distances in obsm.

  • metric (Literal['euclidean', 'manhattan', 'cosine']) – Distance metric to use.

  • copy (bool) – Whether to return a copy of the AnnData.

  • adata (AnnData)

  • spatial_key (str)

  • n_neighbors (int)

  • index_key (str)

  • dist_key (str)

  • metric (Literal['euclidean', 'manhattan', 'cosine'])

  • copy (bool)

Return type:

AnnData | None

Returns:

AnnData with neighbor information if copy=True, else None.