squidpy.gr.spatial_neighbors

squidpy.gr.spatial_neighbors(adata, spatial_key='spatial', coord_type=None, n_rings=1, neigh_grid=6, n_neigh=6, delaunay=False, radius=None, transform=None, set_diag=False, key_added=None)[source]

Create a graph from spatial coordinates.

Parameters
  • adata (AnnData) – Annotated data object.

  • spatial_key (str) – Key in anndata.AnnData.obsm where spatial coordinates are stored.

  • coord_type (Union[str, CoordType, None]) –

    Type of coordinate system. Valid options are:

    • grid - grid coordinates.

    • generic - generic coordinates.

    If None, use grid if spatial_key is present in anndata.AnnData.uns, with neigh_grid=6 (Visium), otherwise use generic.

  • n_rings (int) – Number of rings of neighbors for grid data. The argument is used if coord_type=grid.

  • neigh_grid (int) – Number of neighboring tiles in a grid. The argument is used if coord_type=grid.

  • n_neigh (int) – Number of neighborhoods to consider for non-grid data. The argument is used if coord_type=generic.

  • delaunay (bool) – Whether to compute the graph from Delaunay triangulation. The argument is used if coord_type=generic.

  • radius (Optional[float]) – Radius of neighbors for non-grid data. The argument is used if coord_type=generic.

  • transform (Union[str, Transform, None]) –

    Type of adjacency matrix transform. Valid options are:

    • ’spectral’ - spectral transformation of the adjacency matrix.

    • ’cosine’ - cosine transformation of the adjacency matrix.

    • None - no transformation of the adjacency matrix.

  • set_diag (bool) – Whether to set the diagonal to 1.0.

  • key_added (Optional[str]) – Key which controls where the results are saved.

Return type

None

Returns

Modifies the adata with the following keys: