ehrapy.preprocessing.log_norm

ehrapy.preprocessing.log_norm(adata, vars=None, base=None, offset=1, copy=False)[source]

Apply log normalization.

Computes \(x = \log(x + offset)\), where \(log\) denotes the natural logarithm unless a different base is given and the default \(offset\) is \(1\).

Parameters:
  • adata (AnnData) – AnnData object containing X to normalize values in. Must already be encoded using encode().

  • vars (str | Sequence[str] | None, default: None) – List of the names of the numeric variables to normalize. If None all numeric variables will be normalized.

  • base (int | float | None, default: None) – Numeric base for logarithm. If None the natural logarithm is used.

  • offset (int | float, default: 1) – Offset added to values before computing the logarithm.

  • copy (bool, default: False) – Whether to return a copy or act in place.

Return type:

AnnData | None

Returns:

None if copy=False and modifies the passed adata, else returns an updated AnnData object. Also stores a record of applied normalizations as a dictionary in adata.uns[“normalization”].

Examples

>>> import ehrapy as ep
>>> adata = ep.dt.mimic_2(encoded=True)
>>> adata_norm = ep.pp.log_norm(adata, copy=True)