calamari.sweeps#
Sweep segmentation and branch-folding primitives.
This module is deliberately array-first and backend-free: its two lower
helpers (segment_by_constant(), increasing_field_branch()) operate
on plain NumPy arrays and know nothing about Measurement,
so they are reusable well beyond magnetometry; the one higher helper
(split_isotherms()) is a thin Measurement-aware
wrapper that uses
Measurement.restrict
to carve a stacked multi-isotherm file back into
real sub-measurements.
Why these three#
They exist to prepare raw DC sweep data for the transition detectors in
calamari.transitions (detect_transitions()
and detect_transitions_all(), which accepts the
(T_K, Measurement) pairs split_isotherms() returns):
A single physical data file is not always a single sweep. A “phase-diagram” DC run is often a stack of isothermal M(H) sweeps (e.g. 2 K, 3 K, … each ramping 0 -> H_max) laid end to end in one file, which a naive scan-kind classifier tags as “mixed” because both T and H vary across the file as a whole.
split_isotherms()splits it back into one sub-measurement per temperature plateau so each isotherm is searched independently;segment_by_constant()is the generic plateau-finding primitive underneath it.An M(H) file frequently ramps up and back down in field (a hysteresis loop, or a bidirectional sweep). Detecting a metamagnetic step on the full loop would double-count it (once per leg) and let the return leg add spurious high-field candidates.
increasing_field_branch()folds the sweep to its initial increasing-|field| branch so a feature is counted once.
Determinism#
Nothing here is random: given the same input arrays and parameters every call returns the same segmentation/branch, so downstream boundary tables are reproducible.
Functions
Fold an M(H) sweep to its initial increasing-|field| branch. |
|
Segment a 1-D signal into contiguous runs (plateaus) of ~constant value. |
|
Split a stacked multi-isotherm M(H) file into per-temperature sweeps. |