rapids_singlecell.gr.ripley#

rapids_singlecell.gr.ripley(adata, cluster_key, *, mode='F', spatial_key='spatial', metric='euclidean', n_neigh=2, n_simulations=100, n_observations=1000, max_dist=None, n_steps=50, rng=None, copy=False, table_key=None)[source]#

Calculate Ripley’s statistics for point processes.

GPU port of squidpy.gr.ripley(). Depending on mode, it computes Ripley’s 'F', 'G' or 'L' statistic per cluster and compares it to simulated Spatial Poisson Point Processes on the convex hull of all observations.

'F' and 'G' are defined as

F(t),G(t)=P(di,j≤t)

where di,j are the distances from random points of a Spatial Poisson Point Process ('F') or from points of other clusters ('G') to their n_neigh nearest points of the cluster. 'L' stabilizes the variance of

K(t)=1λ∑i≠jI(di,j≤t)n

as L(t)=(K(t)/π)1/2.

Parameters:
adata AnnData | SpatialData

Annotated data matrix or a SpatialData object containing the selected table.

cluster_key str

Key in anndata.AnnData.obs with the cluster labels.

mode Literal['F', 'G', 'L'] (default: 'F')

Which Ripley’s statistic to compute.

spatial_key str (default: 'spatial')

Key in anndata.AnnData.obsm with the 2D spatial coordinates.

metric str (default: 'euclidean')

Distance metric. Only 'euclidean' is supported.

n_neigh int (default: 2)

Number of nearest neighbors whose distances enter 'F' and 'G'.

n_simulations int (default: 100)

How many simulations to run for computing p-values.

n_observations int (default: 1000)

How many observations to generate for each Spatial Poisson Point Process.

max_dist float | None (default: None)

Maximum distance of the support. If None, max_dist is area/2 of the convex hull.

n_steps int (default: 50)

Number of steps of the support.

rng int | Generator | None (default: None)

Seed or numpy.random.Generator that seeds the GPU random number generator for the simulated point processes.

copy bool (default: False)

If True, return the result, otherwise save it to adata.

table_key str | None (default: None)

Key in SpatialData.tables; required for SpatialData input. All reads and writes use this table; ignored for AnnData input.

Return type:

dict[str, DataFrame | ndarray] | None

Returns:

If copy = True, returns a dict with the following keys:

  • '{mode}_stat' - pandas.DataFrame with the statistic per cluster and bin.

  • 'sims_stat' - pandas.DataFrame with the statistic per simulation and bin.

  • 'bins' - the support of the statistic.

  • 'pvalues' - p-values of shape (n_clusters, n_steps).

Otherwise, modifies the adata with the following key:

Notes

Distances for 'F' and 'G' are exact in double precision. 'L' counts pairs in single precision around the centroid of the coordinates, so pairs within rounding error of a support value may land in the neighboring bin. Random points are drawn on the GPU, so simulations do not reproduce squidpy.gr.ripley() for the same rng.