calamari.repeats.combine#

calamari.repeats.combine(values, errors=None, *, error='birge')#

Combine repeat measurements of one quantity into a single point.

Array-first and unit-agnostic: values and errors are whatever unit you supplied, and the result is in that same unit, so this is usable well outside magnetometry. The parameters therefore carry no unit suffix, which would be an active lie for every other caller.

Parameters:
  • values (ArrayLike) – The repeated measurements. Non-finite entries are dropped, and the count that survives is reported as CombinedPoint.n – a blank row is not a measurement, and in an interleaved AC/DC file most quantities are blank on most rows.

  • errors (ArrayLike | None) – Per-point standard errors aligned to values. When omitted, or when every error in the group is zero or missing, the mean is unweighted and the uncertainty comes from the observed scatter.

  • error (str) –

    Which uncertainty to report on CombinedPoint.error:

    'birge' (default)

    sigma_int * max(1, S), the Particle Data Group convention. When the repeats agree no better than chance you get the propagated error; when they disagree by more than their error bars allow, the error is inflated to match the disagreement rather than reporting a precision the data does not support.

    'internal'

    The propagated error alone, sigma_int. This is the choice that leaves a downstream weighted fit numerically identical to fitting the unaggregated rows.

    'external'

    The observed scatter alone. Honest about disagreement but noisy, and exactly 0 when two repeats happen to land on the same value. This is also the escape hatch for a group whose errors cannot be turned into weights: asking for the scatter is asking for no weighting, so it combines such a group unweighted instead of raising RepeatWeightError.

    An unweighted group reports the external error whatever is asked, since there is no propagated error to report.

Return type:

CombinedPoint

Returns:

CombinedPoint

Raises:
  • RepeatWeightError – If the group mixes zero (or missing) errors with real ones, and error is not 'external'. These instruments write a zero error to mean “only one scan was averaged”, so the two are different conventions rather than different numbers, and weighting cannot span them – see the exception. error='external' does not need weights and so is answerable rather than refused.

  • ValueError – If errors has a different shape from values, or error is not one of the three names above.

Notes

The n = 2 caveat. Two repeats give nu = 1, so S = |z| and the scale factor is itself as uncertain as the measurement. Because max(1, S) is one-sided it inflates on average even when nothing is wrong: E[max(1, |z|)] = 1.167 for independent Gaussian errors with correctly specified standard deviations and a common underlying value. This is a deliberate upward scaling bias; error='internal' omits it under those assumptions. Two observations alone cannot identify a bad member or distinguish drift from random scatter.

Examples

>>> from calamari.repeats import combine
>>> point = combine([1.00, 1.02], [0.01, 0.01])
>>> round(point.value, 4)
1.01
>>> round(point.birge, 4)   # 2 sigma apart, so the error is inflated
1.4142
>>> round(point.internal, 6), round(point.error, 6)
(0.007071, 0.01)