calamari.sweeps.segment_by_constant#
- calamari.sweeps.segment_by_constant(x, *, tol, min_points=1)#
Segment a 1-D signal into contiguous runs (plateaus) of ~constant value.
Generic primitive for a signal that steps between plateaus: a stacked multi-setpoint measurement (temperature held at 2 K for a whole field sweep, stepped to 3 K for the next, …), a staircase drive, or any trace that dwells at a level then jumps to the next. A new segment begins wherever the point-to-point change
|x[i] - x[i-1]|exceedstol, sotolmust be chosen between the within-plateau jitter (kept together) and the inter-plateau step size (which splits). Because the test is on the consecutive difference, slow drift within one plateau – where each step stays undertoleven though the plateau’s total span does not – is tolerated and stays one segment, which is the desired behaviour for real setpoint data that settles gradually.- Parameters:
x (
ArrayLike) – The stepped signal (e.g. a temperature column in Kelvin). Converted tofloat. NaNs are kept in place and counted as ordinary points: a NaN neighbour makes|diff|NaN, which does not exceedtol, so a NaN never forces a split (callers who want NaN-free segments should mask first).tol (
float) – Maximum consecutive change tolerated within a plateau. Must be non-negative. Atolof exactly 0 splits on any change at all, which is the natural choice whenxhas already been quantised onto a grid (seesplit_isotherms()).min_points (
int) – Segments shorter than this many points are dropped from the result. Default 1 (keep every run, including singletons).
- Return type:
- Returns:
listofnumpy.ndarray– One integer index array per kept segment, in order, each holding the positions intoxbelonging to that plateau (contiguous and ascending). Index arrays – rather than slices – are returned so a caller can build a boolean row-mask directly (mask[seg] = True) forrestrict().- Raises:
SweepInputError – If
tolis negative ormin_pointsis less than 1.