pyrolite.geochem.transform

Functions for converting, transforming and parameterizing geochemical data.

pyrolite.geochem.transform.to_molecular(df: DataFrame, renorm=True)[source]

Converts mass quantities to molar quantities of the same order.

Parameters:
  • df (pandas.DataFrame) – Dataframe to transform.

  • renorm (bool, True) – Whether to renormalise the dataframe after converting to relative moles.

Returns:

Transformed dataframe.

Return type:

pandas.DataFrame

Notes

Does not convert units (i.e. mass% –> mol%; mass-ppm –> mol-ppm).

pyrolite.geochem.transform.to_weight(df: DataFrame, renorm=True)[source]

Converts molar quantities to mass quantities of the same order.

Parameters:
  • df (pandas.DataFrame) – Dataframe to transform.

  • renorm (bool, True) – Whether to renormalise the dataframe after converting to relative moles.

Returns:

Transformed dataframe.

Return type:

pandas.DataFrame

Notes

Does not convert units (i.e. mol% –> mass%; mol-ppm –> mass-ppm).

pyrolite.geochem.transform.devolatilise(df: DataFrame, exclude=['H2O', 'H2O_PLUS', 'H2O_MINUS', 'CO2', 'LOI'], renorm=True)[source]

Recalculates components after exclusion of volatile phases (e.g. H2O, CO2).

Parameters:
  • df (pandas.DataFrame) – Dataframe to devolatilise.

  • exclude (list) – Components to exclude from the dataset.

  • renorm (bool, True) – Whether to renormalise the dataframe after devolatilisation.

Returns:

Transformed dataframe.

Return type:

pandas.DataFrame

pyrolite.geochem.transform.oxide_conversion(oxin, oxout, molecular=False)[source]

Factory function to generate a function to convert oxide components between two elemental oxides, for use in redox recalculations.

Parameters:
  • oxin (str | Formula) – Input component.

  • oxout (str | Formula) – Output component.

  • molecular (bool, False) – Whether to apply the conversion for molecular data.

Returns:

  • Function to convert a pandas.Series from one elment-oxide

  • component to another.

pyrolite.geochem.transform.elemental_sum(df: DataFrame, component=None, to=None, total_suffix='T', logdata=False, molecular=False)[source]

Sums abundance for a cation to a single series, starting from a dataframe containing multiple componnents with a single set of units.

Parameters:
  • df (pandas.DataFrame) – DataFrame for which to aggregate cation data.

  • component (str) – Component indicating which element to aggregate.

  • to (str) – Component to cast the output as.

  • logdata (bool, False) – Whether data has been log transformed.

  • molecular (bool, False) – Whether to perform a sum of molecular data.

Returns:

Series with cation aggregated.

Return type:

pandas.Series

pyrolite.geochem.transform.aggregate_element(df: DataFrame, to, total_suffix='T', logdata=False, renorm=False, molecular=False)[source]

Aggregates cation information from oxide and elemental components to either a single species or a designated mixture of species.

Parameters:
  • df (pandas.DataFrame) – DataFrame for which to aggregate cation data.

  • to (str | Element | Formula | dict) – Component(s) to convert to. If one component is specified, the element will be converted to the target species.

    If more than one component is specified with proportions in a dictionary (e.g. {'FeO': 0.9, 'Fe2O3': 0.1}), the components will be split as a fraction of the elemental sum.

  • renorm (bool, True) – Whether to renormalise the dataframe after recalculation.

  • total_suffix (str, ‘T’) – Suffix of ‘total’ variables. E.g. ‘T’ for FeOT, Fe2O3T.

  • logdata (bool, False) – Whether the data has been log transformed.

  • molecular (bool, False) – Whether to perform a sum of molecular data.

Notes

This won’t convert units, so need to start from single set of units.

Returns:

Dataframe with cation aggregated to the desired species.

Return type:

pandas.DataFrame

pyrolite.geochem.transform.get_ratio(df: DataFrame, ratio: str, alias: str = None, norm_to=None, molecular=False)[source]

Get a ratio of components A and B, given in the form of string ‘A/B’. Returned series be assigned an alias name.

Parameters:
  • df (pandas.DataFrame) – Dataframe to append ratio to.

  • ratio (str) – String decription of ratio in the form A/B[_n].

  • alias (str) – Alternate name for ratio to be used as column name.

  • norm_to (str | pyrolite.geochem.norm.Composition, None) – Reference composition to normalise to.

  • molecular (bool, False) – Flag that data is in molecular units, rather than weight units.

Returns:

Dataframe with ratio appended.

Return type:

pandas.DataFrame

Todo

  • Use elemental sum from reference compositions

  • Use sympy-like functionality to accept arbitrary input for calculation

    e.g. "MgNo = Mg / (Mg + Fe)"

See also

add_MgNo()

pyrolite.geochem.transform.add_MgNo(df: DataFrame, molecular=False, use_total_approx=False, approx_Fe203_frac=0.1, name='Mg#')[source]

Append the magnesium number to a dataframe.

Parameters:
  • df (pandas.DataFrame) – Input dataframe.

  • molecular (bool, False) – Whether the input data is molecular.

  • use_total_approx (bool, False) – Whether to use an approximate calculation using total iron rather than just FeO.

  • approx_Fe203_frac (float) – Fraction of iron which is oxidised, used in approximation mentioned above.

  • name (str) – Name to use for the Mg Number column.

Returns:

Dataframe with ratio appended.

Return type:

pandas.DataFrame

See also

get_ratio()

pyrolite.geochem.transform.lambda_lnREE(df, norm_to='ChondriteREE_ON', exclude=['Pm', 'Eu'], params=None, degree=4, scale='ppm', allow_missing=True, min_elements=7, algorithm='ONeill', sigmas=None, **kwargs)[source]

Calculates orthogonal polynomial coefficients (lambdas) for a given set of REE data, normalised to a specific composition [1]. Lambda coefficeints are given for the polynomial regression of ln(REE/NORM) vs radii.

Parameters:
  • df (pandas.DataFrame) – Dataframe to calculate lambda coefficients for.

  • norm_to (str | Composition | numpy.ndarray) – Which reservoir to normalise REE data to (defaults to "ChondriteREE_ON").

  • exclude (list, ["Pm", "Eu"]) – Which REE elements to exclude from the fit. May wish to include Ce for minerals in which Ce anomalies are common.

  • params (list | str, None) – Pre-computed parameters for the orthogonal polynomials (a list of tuples). Optionally specified, otherwise defaults the parameterisation as in O’Neill (2016). If a string is supplied, "O'Neill (2016)" or similar will give the original defaults, while "full" will use all of the REE (including Eu) as a basis for the orthogonal polynomials.

  • degree (int, 4) – Maximum degree polynomial fit component to include.

  • scale (str) – Current units for the REE data, used to scale the reference dataset.

  • allow_missing (True) – Whether to calculate lambdas for rows which might be missing values.

  • min_elements (int) – Minimum columns present to return lambda values.

  • algorithm (str) – Algorithm to use for fitting the orthogonal polynomials.

  • sigmas (float | numpy.ndarray | pandas.Series) – Value or 1D array of fractional REE uncertaintes (i.e. \(\sigma_{REE}/REE\)).

Todo

  • Operate only on valid rows.

  • Add residuals, Eu, Ce anomalies as options.

References

pyrolite.geochem.transform.convert_chemistry(input_df, to=[], total_suffix='T', renorm=False, molecular=False, logdata=False, **kwargs)[source]

Attempts to convert a dataframe with one set of components to another.

Parameters:
  • input_df (pandas.DataFrame) – Dataframe to convert.

  • to (list) – Set of columns to try to extract from the dataframe.

    Can also include a dictionary for iron speciation. See aggregate_element().

  • total_suffix (str, ‘T’) – Suffix of ‘total’ variables. E.g. ‘T’ for FeOT, Fe2O3T.

  • renorm (bool, False) – Whether to renormalise the data after transformation.

  • molecular (bool, False) – Flag that data is in molecular units, rather than weight units.

  • logdata (bool, False) – Whether chemical data has been log transformed. Necessary for aggregation functions.

Returns:

Dataframe with converted chemistry.

Return type:

pandas.DataFrame

Todo

  • Check for conflicts between oxides and elements

  • Aggregator for ratios

  • Implement generalised redox transformation.

  • Add check for dicitonary components (e.g. Fe) in tests