calamari.repeats.repeat_groups#

calamari.repeats.repeat_groups(measurement, *, t_tol_K=0.025, h_tol_Oe=1.0, drive_rtol=0.001, frequency_rtol=0.001, max_repeats=32, use_counter=True)#

Find the repeat groups in a measurement, without combining anything.

The “look before you leap” entry point, and the way to recover an AggregatedMeasurement’s constituent rows: grouping is deterministic, so re-running this on .source with .params reproduces exactly the groups that were combined.

Parameters:
  • measurement (Measurement) – The file to inspect.

  • t_tol_K (float) – Absolute setpoint tolerances, defaulting to REPEAT_T_TOL_K and REPEAT_H_TOL_OE. Deliberately much tighter than SCAN_T_TOL_K / SCAN_H_TOL_OE, which answer a different question – see this module’s constants.

  • h_tol_Oe (float) – Absolute setpoint tolerances, defaulting to REPEAT_T_TOL_K and REPEAT_H_TOL_OE. Deliberately much tighter than SCAN_T_TOL_K / SCAN_H_TOL_OE, which answer a different question – see this module’s constants.

  • drive_rtol (float) – Relative tolerances for the AC drive amplitude and frequency, which are magnitudes rather than offsets. The drive one is load-bearing for response consistency – see REPEAT_DRIVE_RTOL.

  • frequency_rtol (float) – Relative tolerances for the AC drive amplitude and frequency, which are magnitudes rather than offsets. The drive one is load-bearing for response consistency – see REPEAT_DRIVE_RTOL.

  • max_repeats (int) – Sanity bound on group size; see MAX_REPEATS.

  • use_counter (bool) – Whether to let the instrument’s Measurement Number column propose the groups (default True). Set False to group purely on setpoints – the escape hatch when a file’s counter turns out to mean something else.

Return type:

list[ndarray]

Returns:

list of numpy.ndarray – One integer index array per group, in file order, covering every row exactly once. A file with no repeats returns one singleton group per row, which is the honest answer rather than an empty list.

Raises:

RepeatGroupError – If a proposed group is not one setpoint, if a group exceeds max_repeats, or if the file has no setpoint column at all.

Examples

>>> import numpy as np
>>> from calamari import load, simulate
>>> from calamari.repeats import repeat_groups
>>> path = simulate.write_mpms3_file(
...     "repeats.dat", app="SQUID AC",
...     temperature_K=np.repeat([2.0, 3.0], 2),
...     field_oe=np.zeros(4), chi_real=[1.0, 1.1, 2.0, 2.2],
...     extra_columns={"Measurement Number": [1, 2, 1, 2]},
... )
>>> [g.tolist() for g in repeat_groups(load(path))]
[[0, 1], [2, 3]]