pyrolite.comp.pyrocomp (Pandas Interface)

class pyrolite.comp.pyrocomp(obj)[source]
renormalise(components: list = [], scale=100.0)[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, 100.) – Closure parameter. Typically either 100 or 1.

Returns

Renormalized dataframe.

Return type

pandas.DataFrame

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=[], ind=-1, null_col=False, label_mode='simple')[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

pandas.DataFrame

inverse_ALR(ind=None, null_col=False)[source]

Inverse Additive Log Ratio transformation.

Parameters
  • ind (int, str) – Index or name of column used as denominator.

  • null_col (bool, False) – 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

pandas.DataFrame

CLR(label_mode='simple')[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

pandas.DataFrame

inverse_CLR()[source]

Inverse Centred Log Ratio transformation.

Returns

Inverse-CLR transformed array, of shape (N, D).

Return type

pandas.DataFrame

ILR(label_mode='simple')[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

pandas.DataFrame

inverse_ILR(X=None)[source]

Inverse Isometric Log Ratio transformation.

Parameters

X (numpy.ndarray, None) – 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

pandas.DataFrame

boxcox(lmbda=None, lmbda_search_space=(-1, 5), search_steps=100, return_lmbda=False)[source]

Box-Cox transformation.

Parameters
  • lmbda (numpy.number, None) – 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

pandas.DataFrame

inverse_boxcox(lmbda=None)[source]

Inverse Box-Cox transformation.

Parameters

lmbda (float) – Lambda value used to forward-transform values.

Returns

Inverse Box-Cox transformed array.

Return type

pandas.DataFrame

sphere()[source]

Spherical coordinate transformation for compositional data.

Returns

θ – Array of angles in radians (\((0, \pi / 2]\))

Return type

pandas.DataFrame

inverse_sphere(variables=None)[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

pandas.DataFrame

logratiomean(transform=<function CLR>, inverse_transform=<function inverse_CLR>)[source]

Take a mean of log-ratios along the index of a dataframe.

Parameters

transform (callable : str) – Log transform to use.

Returns

Mean values as a pandas series.

Return type

pandas.Series

invert_transform(**kwargs)[source]

Try to inverse-transform a transformed dataframe.