squidpy.gr.spatial_neighbors_delaunay

squidpy.gr.spatial_neighbors_delaunay(data, *, spatial_key='spatial', elements_to_coordinate_systems=None, table_key=None, library_key=None, radius=None, percentile=None, transform=None, set_diag=False, key_added='spatial', copy=False, n_jobs=1)[source]

Create a Delaunay triangulation graph from spatial coordinates.

Delaunay triangulation connects observations into triangles such that no other observation lies inside the circumcircle of each triangle. In practice, this yields an adaptive geometry-driven graph rather than one based on a fixed k or radius, and dst stores Euclidean edge lengths.

Parameters:
  • adata – Annotated data object.

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

  • elements_to_coordinate_systems (dict[str, str] | None) – A dictionary mapping element names of the SpatialData object to coordinate systems. The elements can be either Shapes or Labels. For compatibility, the spatialdata table must annotate all regions keys. Must not be None if adata is a spatialdata.SpatialData.

  • table_key (str | None) – Key in spatialdata.SpatialData.tables where the spatialdata table is stored. Must not be None if adata is a spatialdata.SpatialData.

  • library_key (str | None) – If multiple library_id, column in anndata.AnnData.obs which stores mapping between library_id and obs.

  • radius (float | tuple[float, float] | None) –

    Post-construction edge pruning of the Delaunay graph. The triangulation itself is never changed; only the resulting edges are filtered.

    • tuple (min, max): keep edges with Euclidean length in [min(radius), max(radius)].

    • float / int r: shorthand for (0.0, r), i.e. keep edges with length at most r.

    • None: keep every Delaunay edge.

  • percentile (float | None) – Percentile of the distances to use as threshold.

  • transform (str | Transform | None) – Adjacency matrix transform ('spectral', 'cosine', or None).

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

  • key_added (str) – Key which controls where the results are saved if copy = False.

  • copy (bool) – If True, return the result, otherwise save it to the adata object.

  • n_jobs (int) – Number of parallel jobs used to build the per-library graphs when library_key is set. Each library’s graph is computed independently, so this only has an effect for multi-library data. 1 (default) builds the graphs sequentially and does not change behavior; -1 uses all available CPUs. Has no effect when library_key is None. Speedup is sub-linear (memory-bandwidth bound), and process-based backends pay a one-time worker start-up cost, so parallelism mainly pays off for many large libraries.

Return type:

SpatialNeighborsResult | None

Returns:

If copy = True, returns a SpatialNeighborsResult with the spatial connectivities and distances matrices.

Otherwise, modifies the adata with the following keys:

See also

spatial_neighbors_from_builder

Use DelaunayBuilder directly for advanced customization.

squidpy.gr.neighbors.DelaunayBuilder

Delaunay triangulation builder class.