calamari.sweeps.increasing_field_branch#

calamari.sweeps.increasing_field_branch(field, moment)#

Fold an M(H) sweep to its initial increasing-|field| branch.

Many M(H) files ramp 0 -> +H_max -> 0 (and sometimes on into negative field): a hysteresis loop or a bidirectional sweep. Running a step/kink detector on the whole trace would (a) report a metamagnetic feature twice, once from the up-leg and once from the down-leg, and (b) let the return leg contribute spurious high-field candidates. This helper returns the leading monotonically-increasing run of |field| from the start of the sweep, paired with the corresponding moment values, so a feature is counted once on a clean monotone field axis.

The function is unit-agnostic: it operates purely on |field| and monotonicity, so the returned field array is in whatever unit field was supplied in (Oe or Tesla). The parameter is therefore named plainly field rather than carrying a unit suffix – attaching one would be an active lie whenever the other unit is passed. Callers that need a specific output unit should pass that unit in.

Parameters:
  • field (ArrayLike) – Applied-field column, in any single consistent unit. May be signed; only its magnitude is used.

  • moment (ArrayLike) – Moment column aligned to field (same length).

Return type:

tuple[ndarray, ndarray]

Returns:

(numpy.ndarray, numpy.ndarray) – (field_increasing, moment) – |field| over the leading increasing run and the matching moments. If the sweep starts on a decreasing leg (leading run shorter than three points, e.g. a +H_max -> 0 -> -H_max sweep), falls back to the whole sweep sorted by |field| so a usable monotone axis is still returned rather than nothing.

Raises:

SweepInputError – If field and moment have different lengths.