pyrolite.comp.aggregate

pyrolite.comp.aggregate.get_full_column(X: ndarray)[source]

Returns the index of the first array column which contains only finite numbers (i.e. no missing data, nan, inf).

Parameters

X (numpy.ndarray) – Array for which to find the first full column within.

Returns

Index of the first full column.

Return type

int

pyrolite.comp.aggregate.weights_from_array(X: ndarray)[source]

Returns a set of equal weights with size equal to that of the first axis of an array.

Parameters

X (numpy.ndarray) – Array of compositions to produce weights for.

Returns

Array of weights.

Return type

numpy.ndarray

pyrolite.comp.aggregate.nan_weighted_mean(X: ndarray, weights=None)[source]

Returns a weighted mean of compositions, where weights are renormalised to account for missing data.

Parameters
Returns

Array mean.

Return type

numpy.ndarray

pyrolite.comp.aggregate.compositional_mean(df, weights=[], **kwargs)[source]

Implements an aggregation using a compositional weighted mean.

Parameters
Returns

Mean values along index of dataframe.

Return type

pandas.Series

pyrolite.comp.aggregate.nan_weighted_compositional_mean(X: ndarray, weights=None, ind=None, renorm=True, **kwargs)[source]

Implements an aggregation using a weighted mean, but accounts for nans. Requires at least one non-nan column for ALR mean.

When used for internal standardisation, there should be only a single common element - this would be used by default as the divisor here. When used for multiple-standardisation, the [specified] or first common element will be used.

Parameters
  • X (numpy.ndarray) – Array of compositions to aggregate.

  • weights (numpy.ndarray) – Array of weights.

  • ind (int) – Index of the column to use as the ALR divisor.

  • renorm (bool, True) – Whether to renormalise the output compositional mean to unity.

Returns

An array with the mean composition.

Return type

numpy.ndarray

pyrolite.comp.aggregate.cross_ratios(df: DataFrame)[source]

Takes ratios of values across a dataframe, such that columns are denominators and the row indexes the numerators, to create a square array. Returns one array per record.

Parameters

df (pandas.DataFrame) – Dataframe of compositions to create ratios of.

Returns

A 3D array of ratios.

Return type

numpy.ndarray

pyrolite.comp.aggregate.np_cross_ratios(X: ndarray, debug=False)[source]

Takes ratios of values across an array, such that columns are denominators and the row indexes the numerators, to create a square array. Returns one array per record.

Parameters

X (numpy.ndarray) – Array of compositions to create ratios of.

Returns

A 3D array of ratios.

Return type

numpy.ndarray

pyrolite.comp.aggregate.standardise_aggregate(df: DataFrame, int_std=None, fixed_record_idx=0, renorm=True, **kwargs)[source]

Performs internal standardisation and aggregates dissimilar geochemical records. Note: this changes the closure parameter, and is generally intended to integrate major and trace element records.

Parameters
  • df (pandas.DataFrame) – Dataframe of compositions to aggregate of.

  • int_std (str) – Name of the internal standard column.

  • fixed_record_idx (int) – Numeric index of a specific record’s for which to retain the internal standard value (e.g for standardising trace element data).

  • renorm (bool, True) – Whether to renormalise to unity.

Returns

A series representing the internally standardised record.

Return type

pandas.Series