mescla.mixing.lsq.mixing_ratios

mescla.mixing.lsq.mixing_ratios(endmembers, samples, sigma=None, non_negative=True)[source]

Mixing ratios for every sample, by weighted constrained least squares.

Use this when the end-members are well characterised. When they are uncertain and you have many mixed samples, mescla.mixing.ml.mix_ml() will do better – least squares treats each sample independently, so it cannot improve as samples accumulate.

Parameters:
  • endmembers (EndMembers, DataFrame or array, shape (ne, ns))

  • samples (WaterChemistry, DataFrame or array, shape (np, ns)) – Ragged input is fine: nan marks a species not analysed in that sample and simply does not constrain it. Each sample is solved independently, so different samples may rest on different species – but a sample still needs at least ne - 1 usable analyses. Non-detects carried on the container as censored are treated as upper bounds, not as measurements.

  • sigma (array_like, optional) – Standard deviations of the sample analyses. Falls back to the sigma carried by samples, then to uniform weighting. Species measured precisely, or known to be conservative, should get the smallest values – this is how you tell the estimator which tracers to trust.

  • non_negative (bool, default True)

Returns:

MixingResult

Return type:

MixingResult

Examples

>>> result = mixing_ratios(endmembers, samples)
>>> result.ratios_frame().head()