dynamo.vf.divergence(adata, cell_idx=None, sampling=None, sample_ncells=1000, basis='pca', vector_field_class=None, method='analytical', store_in_adata=True, **kwargs)[source]

Calculate divergence for each cell with the reconstructed vector field function. Either AnnData object is updated with the ‘divergence’ key in the .obs or the divergence is returned as a numpy array.

  • adata (AnnData) – AnnData object that contains the reconstructed vector field function in the uns attribute.

  • cell_idx (Optional[List]) – A list of cell index (or boolean flags) for which the jacobian is calculated.

  • sampling (Optional[Literal['random', 'velocity', 'trn']]) – {None, ‘random’, ‘velocity’, ‘trn’}, (default: None) See specific information on these methods in .tl.sample. If None, all cells are used.

  • sample_ncells (int) – The number of cells to be sampled. If sampling is None, this parameter is ignored.

  • basis (str) – The embedding data in which the vector field was reconstructed.

  • vector_field_class – If not None, the divergene will be computed using this class instead of the vector field stored in adata.

  • method (str) – The method that will be used for calculating divergence, either analytical or numeric. analytical method will use the analytical form of the reconstructed vector field for calculating divergence while numeric method will use numdifftools for calculation. analytical method is much more efficient.

  • store_in_adata (bool) – Whether to store the divergence result in adata.

  • kwargs – Any additional keys that will be passed to vector_field_class.compute_divergence function.

Return type:



the divergence is returned as an np.ndarray if store_in_adata is False.