ocelli.tl.projection#

ocelli.tl.projection(adata: AnnData, x: str, phi: int = 20, theta: int = 20, out: str = 'X_proj', random_state=None, copy: bool = False)#

Graphical projection of 3D data to 2D

Projects 3D data onto a 2D plane defined by a normal vector. This method enables better visualization of 3D embeddings by projecting the data while preserving its structure.

The 2D projection is determined by the orientation of the projection plane, which is defined using spherical coordinates (phi and theta). The normal vector of the plane is calculated based on these angles. Data is then projected onto the 2D plane using orthogonal base vectors.

Parameters:
  • adata (anndata.AnnData) – The annotated data matrix.

  • x (str) – Key in adata.obsm storing the 3D data to be projected.

  • phi (int) – First spherical angle in degrees, ranging from 0 to 360. (default: 20)

  • theta (int) – Second spherical angle in degrees, ranging from 0 to 180. (default: 20)

  • out (str) – Key in adata.obsm where the resulting 2D projection will be stored. (default: ‘X_proj’)

  • random_state (int or None) – Seed for reproducibility. If None, no seed is set. (default: None)

  • copy (bool) – Whether to return a copy of adata. If False, updates are made in-place. (default: False)

Returns:

  • If copy=False: Updates adata with the 2D projection stored in adata.obsm[out].

  • If copy=True: Returns a modified copy of adata with the 2D projection.

Return type:

anndata.AnnData or None

Example:
import ocelli as oci
from anndata import AnnData
import numpy as np

# Example data
adata = AnnData(X=np.random.rand(100, 50))
adata.obsm['embedding_3d'] = np.random.rand(100, 3)

# Project 3D data to 2D
oci.tl.projection(adata, x='embedding_3d', phi=45, theta=60, out='X_projected')