rapids_singlecell.tl.embedding_density#

rapids_singlecell.tl.embedding_density(adata, use='umap', *, groupby=None, components=None, out=False, basis=None, key_added=None)[source]#

Calculate the density of cells in an embedding (per condition).

Gaussian kernel density estimation is used to calculate the density of cells in an embedded space. This can be performed per category over a categorical cell annotation. The cell density can be plotted using the pl.embedding_density function. Note that density values are scaled to be between 0 and 1. Thus, the density value at each cell is only comparable to densities in the same category. This function was written by Sophie Tritschler and implemented into Scanpy by Malte Luecken.

Parameters:
adata AnnData

The annotated data matrix.

use MultiAcc | str | Default (default: 'umap')

The embedding over which the density will be calculated, e.g. A.obsm['X_umap'], or the name of a basis found in adata.obsm[basis] or adata.obsm[f"X_{basis}"]. Strings are basis names, unless the scanpy v2 preset is active, where they are resolved by anndata.acc.AdAcc.resolve(), e.g. 'obsm.X_umap'.

groupby AdRef | str | None (default: None)

Categorical .obs column for which densities are calculated per category, e.g. A.obs['batch'] or its name.

components str | Sequence[str] (default: None)

The embedding dimensions over which the density should be calculated. This is limited to two components.

out AdRef | str | bool (default: False)

Where to write the densities, e.g. A.obs['k'] (or 'obs.k'); the parameters then go to .uns['k_params']. If True, the densities are returned instead of written. If False, they are written to .obs['[basis]_density_[groupby]'].

Return type:

ndarray | None

Returns:

The densities if out=True, else None. Sets adata.obs[key] and adata.uns[f'{key}_params'], where key defaults to [basis]_density_[groupby], [basis] being one of umap, diffmap, pca, tsne, or draw_graph_fa.