pyrolite.comp.pyrocomp (Pandas Interface)#
- class pyrolite.comp.pyrocomp(obj: DataFrame | Series)[source]#
- renormalise(components: list[str] | None = None, scale: float = 100.0) DataFrame | Series[source]#
Renormalises compositional data to ensure closure.
- Parameters:
components (list) – Option subcompositon to renormalise to 100. Useful for the use case where compostional data and non-compositional data are stored in the same dataframe.
scale (float) – Closure parameter. Typically either 100 or 1.
- Returns:
Renormalized dataframe.
- Return type:
Notes
This won’t modify the dataframe in place, you’ll need to assign it to something. If you specify components, those components will be summed to 100%, and others remain unchanged.
- ALR(components: list[str] | None = None, ind: int | str = -1, null_col: bool = False, label_mode: str = 'simple') DataFrame | Series[source]#
Additive Log Ratio transformation.
- Parameters:
ind (int | str) – Index or name of column used as denominator.
null_col (bool) – Whether to keep the redundant column.
- Returns:
ALR-transformed array, of shape (N, D-1).
- Return type:
- inverse_ALR(ind: int | str | None = None, null_col: bool = False) DataFrame | Series[source]#
Inverse Additive Log Ratio transformation.
- Parameters:
ind (int | str) – Index or name of column used as denominator.
null_col (bool) – Whether the array contains an extra redundant column (i.e. shape is (N, D)).
- Returns:
Inverse-ALR transformed array, of shape (N, D).
- Return type:
- CLR(label_mode: str = 'simple') DataFrame | Series[source]#
Centred Log Ratio transformation.
- Parameters:
label_mode (str) – Labelling mode for the output dataframe (numeric, simple, LaTeX). If you plan to use the outputs for automated visualisation and want to know which components contribute, use simple or LaTeX.
- Returns:
CLR-transformed array, of shape (N, D).
- Return type:
- inverse_CLR() DataFrame | Series[source]#
Inverse Centred Log Ratio transformation.
- Returns:
Inverse-CLR transformed array, of shape (N, D).
- Return type:
- ILR(label_mode: str = 'simple') DataFrame | Series[source]#
Isometric Log Ratio transformation.
- Parameters:
label_mode (str) – Labelling mode for the output dataframe (numeric, simple, LaTeX). If you plan to use the outputs for automated visualisation and want to know which components contribute, use simple or LaTeX.
- Returns:
ILR-transformed array, of shape (N, D-1)
- Return type:
- inverse_ILR(X: ndarray | None = None) DataFrame | Series[source]#
Inverse Isometric Log Ratio transformation.
- Parameters:
X (numpy.ndarray) – Optional specification for an array from which to derive the orthonormal basis, with shape (N, D).
- Returns:
Inverse-ILR transformed array, of shape (N, D).
- Return type:
- boxcox(lmbda: number | None = None, lmbda_search_space: tuple[float, float] = (-1, 5), search_steps: int = 100, return_lmbda: bool = False) DataFrame | Series[source]#
Box-Cox transformation.
- Parameters:
lmbda (numpy.number) – Lambda value used to forward-transform values. If none, it will be calculated using the mean
lmbda_search_space (tuple) – Range tuple (min, max).
search_steps (int) – Steps for lambda search range.
- Returns:
Box-Cox transformed array.
- Return type:
- inverse_boxcox(lmbda: float | None = None) DataFrame | Series[source]#
Inverse Box-Cox transformation.
- Parameters:
lmbda (float) – Lambda value used to forward-transform values.
- Returns:
Inverse Box-Cox transformed array.
- Return type:
- sphere() DataFrame | Series[source]#
Spherical coordinate transformation for compositional data.
- Returns:
θ – Array of angles in radians (\((0, \pi / 2]\))
- Return type:
- inverse_sphere(variables=None) DataFrame | Series[source]#
Inverse spherical coordinate transformation to revert back to compositional data in the simplex.
- Parameters:
variables (list) – List of names for the compositional data variables, optionally specified (for when they may not be stored in the dataframe attributes through the
pyrocomp()functions).- Returns:
df – Dataframe of original compositional (simplex) coordinates, normalised to 1.
- Return type:
- logratiomean(transform: Callable = <function CLR>, inverse_transform: Callable = <function inverse_CLR>) Series[source]#
Take a mean of log-ratios along the index of a dataframe.
- Parameters:
transform (Callable) – Log transform to use.
inverse_transform (Callable) – Inverse transform to use.
- Returns:
Mean values as a pandas series.
- Return type:
Notes
Only makes sense for a dataframe.