Code documentation

Configuration

class MagmaPEC.PEC_configuration.PEC_configuration[source]

Class for configuring the post-entrapment crystallisation (PEC) correction model

Fe2_behaviour

behaviour of Fe2+. Available options: ‘buffered’ and ‘closed system’. Default value: ‘buffered’

Type:

str

stepsize_equilibration

stepsize in Fe-Mg cation exchange during the equilibration stage. Default value: 0.002 moles

Type:

float

stepsize_crystallisation

stepsize of olivine crystallisation/melting during the crystallisation stage. Default value: 0.05 moles

Type:

float

decrease_factor

decrease factor for Fe-Mg exchange and olivine crystallisation/melting stepsizes after overstepping convergence values. Default value: 5.

Type:

float, int

FeO_converge

value in wt.% within which melt FeO and target FeO are considered the same. Default value: 0.05 wt.%

Type:

float

Kd_converge

value within which modelled and observed olivine-melt Fe-Mg Kd are considered the same. Default value: 0.001

Type:

float

classmethod reset()[source]

Reset to default values

PEC correction

class MagmaPEC.PEC_model.PEC(inclusions: Melt, olivines: Olivine | Series | float, P_bar: float | int | Series, FeO_target: float | Series | callable, Fe3Fe2_offset_parameters: float = 0.0, Kd_offset_parameters: float = 0.0, temperature_offset_parameters: float = 0.0, **kwargs)[source]

Class for post-entrapment crystallisation (PEC) correction of olivine-hosted melt inclusions. The algorithm is modified after Petrolog3:

    1. Danyushesky and P. Plechov (2011) Petrolog3: Integrated software for modeling crystallization processes Geochemistry, Geophysics, Geosystems, vol 12

Model specific settings like calculation stepsizes and convergence values are controlled by PEC_configuration.

More general settings like fO2 buffer (offsets) and model selection for Kd, Fe3+/Fe2+ and liquidus temperature are set in the configuration of MagmaPandas

Parameters:
  • inclusions (Melt) – melt inclusion compositions in oxide wt. %

  • olivines (Olivine, Pandas Series, float) – Olivine compositions in oxide wt. % as Olivine MagmaFrame, or olivine forsterite contents as pandas Series or float.

  • P_bar (float, Pandas Series) – Pressures in bar

  • FeO_target (float, Pandas Series, Callable) – Melt inclusion initial FeO content as a fixed value for all inclusions, inclusion specific values, or a predictive equation based on melt composition. The callable needs to accept a Pandas DataFrame with melt compositions in oxide wt. % as input and return an array-like object with initial FeO contents per inclusion.

  • Fe3Fe2_offset_parameters (float, array-like) – offsets of calculated melt Fe3+/Fe2+ ratios in standard deviations.

  • Kd_offset_parameters (float, array-like) – offsets of calculated olivine-melt Fe-Mg Kd’s in standard deviations.

  • temperature_offset_parameters (float, array-like) – offsets of calculated temperatures in standard deviations.

inclusions

Melt inclusion compositions in oxide wt. %. Compositions are updated during the PEC correction procedure

Type:

Melt

P_bar

Pressures in bar

Type:

Pandas Series

FeO_target

Melt inclusion initial FeO contents.

Type:

float, Pandas Series, Callable

olivine_corrected

Dataframe with columns equilibration_crystallisation, PE_crystallisation and total_crystallisation, storing total PEC and crystallisation amounts during the equilibration and crystallisation stages.

Type:

Pandas DataFrame

correct(progressbar=True, **kwargs) Tuple[Melt, DataFrame, DataFrame][source]

Correct inclusions for PEC.

Runs Stage 1, equilibrate_inclusions(), and 2, correct_olivine_crystallisation(), to fully correct melt inclusion for post-entrapment modification processes.

progressbarboolean

show progress bar.

correct_inclusion(index, plot=True, intermediate_steps=False, **kwargs) DataFrame[source]

Correct a single inclusion for PEC

Parameters:
  • index (int, str) – row index of the inclusion in the DataFrame as integer, or name of the inclusion as string

  • plot (boolean) – print MgO vs FeO plot of the PEC results if True

  • intermediate_steps (boolean) – keep intermediate steps C1A and C2A if True

correct_olivine_crystallisation(inplace=False, progressbar=True, **kwargs)[source]

Run correction stage 2.

Correct melt inclusions for post entrapment modification by melting or crystallising host olivine. Expects complete Fe-Mg equilibration between inclusions and host crystals (i.e. the output from stage 1: equilibrate_inclusions()). The models exits when inclusion initial FeO contents are restored.

progressbarboolean

show progress bar.

equilibrate_inclusions(progressbar=True, **kwargs)[source]

Run correction stage 1.

Fe-Mg equilibrium between inclusions and olivine hosts is restored via isothermal Fe-Mg cation exchange. Equilibrium is checked with modelled partitioning coefficients (Kd).

progressbarboolean

show progress bar.

get_PTX(P_bar=None)[source]
P_bararray-like

pressures in bar for each inclusion.

Return type:

pandas dataframe with pressures, temperatures, Kd (current inclusion value, not modelled), melt Fe3Fe2, and fO2 for uncorrected and corrected inclusions.

reset()[source]

Reset all data to their initial, uncorrected states.

property Fe_loss: Series

Booleans set to True for inclusions that have experienced Fe-loss

PEC Monte Carlo simulation

Module for PEC correction of olivine-hosted melt inclusions, with errors on models and input parameters propagated in a Monte Carlo simulation. Includes error propagation for:

  • melt composition,

  • olivine composition,

  • initial MI FeO content,

  • melt Fe3+/Fe2+ ratios and

  • olivine-melt Fe-Mg partition coefficients.

class MagmaPEC.error_propagation.FeOi_prediction(x: DataFrame, FeO: Series)[source]

Class for predicting melt FeO from differentiation trends.

Calculate multiple linear regressions by ordinary least-squares (OLS) of FeO against melt major element compositions.

Parameters:
  • x (pandas DataFrame) – melt compositions (excluding FeO) in oxide wt. %. Columns are used as predictors.

  • FeO (pandas Series) – melt FeO contents in wt. %

predictors

names of elements used as predictors. Defaults to all columns in x

Type:

List[str]

coefficients

fitted regression coefficients

Type:

pandas Series

errors

one standard deviation errors on coefficients

Type:

pandas Series

model

FeOi prediction model

Type:

Callable

calculate_model_fits(exclude: List[str] | None = None, crossvalidation_split: float = 0.15) DataFrame[source]

Calculate cross-validated misfits of linear regressions.

n - 1 regressions are calculated for n columns in x. For each new regression, the element whose removal results in the lowest regression F-test p-value is removed from the dataset. Goodness of fit for each regression is measured by R2, root-mean squared error (RMSE) and cross-validated RMSE (CV-RMSE), where large differences between RMSE and CV-RMSE (\({\Delta}\)RMSE) indicate overfitting. As long as RMSE and R2 values are acceptable, the model with the smallest \({\Delta}\)RMSE should be selected.

Parameters:
  • exclude (List[str]) – list of column names in x to exclude from the regression

  • crossvalidation_split (float) – split for cross validation. Data fraction (1 - crossvalidation_split) will be used for the regression, the rest for calculating misfits by RMSE.

Returns:

regressions – regression results with columns for fitted coefficients (intercept and element-wise slopes), calibration RMSE, cross-validated RMSE, \({\Delta}\)RMSE and R2.

Return type:

pandas DataFrame

get_OLS_coefficients() None[source]

Get linear regression coefficients by ordinary least squares.

Uses elements in predictors to predict FeO. Results are stored in coefficients and errors.

predict(melt: DataFrame) Series[source]

Predict melt FeO contents with the current model

random_sample_coefficients(n: int) DataFrame[source]

Randomly sample fitted slopes within their errors. Intercepts, \(\hat{\beta}_{0}\), are calculated as:

\[\hat{\beta}_{0} = \overline{y} - \sum \hat{\beta}_{1}^{e} \cdot \overline{e}\]

for elements e in predictors with slopes \(\hat{\beta}_{1}^{e}\) and where y = FeO.

Parameters:

n (int) – amount of samples

Returns:

coefficients – DataFrame with resampled coefficients.

Return type:

pandas DataFrame

select_predictors(idx: int, plot=True)[source]

Set predictors according to the results from calculate_model_fits().

idxint

model index in the results from calculate_model_fits()

class MagmaPEC.error_propagation.PEC_MC(inclusions: Melt, olivines: Olivine, P_bar: float | Series, FeO_target: float | FeOi_prediction, MC_parameters: PEC_MC_parameters)[source]

Class for post-entrapment crystallisation (PEC) correction of olivine-hosted melt inclusions, with model and input parameter errors propagated in a Monte Carlo (MC) simulation.

Parameters:
  • inclusions (Melt) – melt inclusion compositions in oxide wt. %.

  • olivines (Olivine) – olivine compositions in oxide wt. %.

  • P_bar (float, pandas Series) – pressures in bar

  • FeO_target (float, pandas Series, FeOi_prediction) – melt inclusion initial FeO content, as fixed value (float, Series) or predictive equation based on melt composition (FeOi_prediction)

  • MC_parameters (PEC_MC_parameters) – model and input parameter errors.

pec

average PEC extents (%) of the MC model, with errors as one standard deviation.

Type:

pandas DataFrame

inclusions_corr

averages of corrected melt inclusion compositions of the MC model.

Type:

pandas DataFrame

inclusions_stddev

errors on inclusions_corr as one standard deviation.

Type:

pandas DataFrame

inclusions_MC

corrected melt compositions per inclusion for all MC iterations.

Type:

Dict[str, pd.DataFrame]

pec_MC

modelled PEC extents for all MC interations.

Type:

pandas DataFrame

run(n: int, multicore=True)[source]

Run the PEC correction Monte Carlo loop.

Parameters:
  • n (int) – number of iterations in the Monte Carlo loop

  • multicore (boolean) – run calculations in parallel across multiple cpu cores

class MagmaPEC.error_propagation.PEC_MC_parameters(melt_errors: None | Series | DataFrame | ndarray = None, olivine_errors: None | Series | DataFrame | ndarray = None, pressure_errors: Series | ndarray | int | float = 0.0, FeOi_errors: float | int | FeOi_prediction = 0.0, Fe3Fe2: bool = False, Kd: bool = False, temperature: bool = False)[source]

Class for fetching parameters for PEC Monte Carlo simulations. Includes error propagation for:

  • melt composition

  • olivine composition

  • initial MI FeO content

  • melt Fe3+/Fe2+ ratios

  • olivine-melt Fe-Mg partition coefficients.

Parameters:
  • melt_errors (pandas Series, None) – one standard deviation errors on melt compositions in oxide wt. %. Errors are 0 when set to None. Default value: None

  • olivine_errors (pandas Series, None) – one standard deviation errors on olivine compositions in oxide wt. %. Errors are 0 when set to None. Default value: None

  • FeOi_errors (float, pandas Series, FeOi_prediction) – errors on melt initial FeO content. float or Series for errors on FeO, FeOi_prediction for errors on coefficients of linear regressions of FeO against melt major element compositions. Default value: 0.0

  • Fe3Fe2 (bool) – propagate melt Fe3+/Fe2+ errors. Errors are calculated from regressions on a validation dataset. Default value: False

  • Kd (bool) – propagate olivine-melt Fe-Mg partition coefficient errors. Errors are calibration errors as reported in their respective publications. Default value: False

parameters

dictionary with errors ordered as ‘melt’, ‘olivine’, ‘pressure’, ‘FeOi’, ‘Fe3Fe2’, ‘Kd’, ‘temperature’

Type:

OrderedDict

get_parameters(n: int)[source]

Randomly sample parameter errors. Results are stored in parameters.

melt, olivine and FeOi errors are calculated based on user input values. Fe3+/Fe2+ and Kd errors are in standard deviations and calculated based on model calibration errors.

Parameters:

n (int) – amount of random samples.