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
kor radius, anddststores Euclidean edge lengths.- Parameters:
- adata
Annotated data object.
- spatial_key
str(default:'spatial') Key in
anndata.AnnData.obsmwhere spatial coordinates are stored.- elements_to_coordinate_systems
dict[str,str] |None(default: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
Noneifadatais aspatialdata.SpatialData.- table_key
str|None(default:None) Key in
spatialdata.SpatialData.tableswhere the spatialdata table is stored. Must not beNoneifadatais aspatialdata.SpatialData.- library_key
str|None(default:None) If multiple
library_id, column inanndata.AnnData.obswhich stores mapping betweenlibrary_idand obs.- radius
float|tuple[float,float] |None(default:None) Post-construction edge pruning of the Delaunay graph. The triangulation itself is never changed; only the resulting edges are filtered.
- percentile
float|None(default:None) Percentile of the distances to use as threshold.
- transform
Literal['spectral','cosine'] |None(default:None) Adjacency matrix transform (
'spectral','cosine', orNone).- set_diag
bool(default:False) Whether to set the diagonal of the connectivities to
1.0.- key_added
str(default:'spatial') Key which controls where the results are saved if
copy = False.- copy
bool(default:False) If
True, return the result, otherwise save it to theadataobject.- n_jobs
int(default:1) Number of parallel jobs used to build the per-library graphs when
library_keyis set. Each library’s graph is computed independently, so this only has an effect for multi-library data.1builds the graphs sequentially and does not change behavior, and it has no effect whenlibrary_keyisNone.Noneand-1use numba’s default thread count (NUMBA_NUM_THREADS); asking for more threads than that warns and falls back to it, while0and values below-1raise, since scanpy only supportsn_jobs >= -1. Speedup is sub-linear (memory-bandwidth bound), so parallelism mainly pays off for many large libraries.
- Returns:
SpatialNeighborsResult|None– Ifcopy = True, returns aSpatialNeighborsResultwith thespatial connectivities and distances matrices.
Otherwise, modifies the
adatawith the following keys:anndata.AnnData.obsp['{key_added}_connectivities']- the spatial connectivities.anndata.AnnData.obsp['{key_added}_distances']- the spatial distances.anndata.AnnData.uns['{key_added}']-dictcontaining parameters.
See also
spatial_neighbors_from_builderUse
DelaunayBuilderdirectly for advanced customization.squidpy.gr.neighbors.DelaunayBuilderDelaunay triangulation builder class.