#!/usr/bin/env python3 # SPDX-License-Identifier: Apache-2.0 """Settle time of the run/halt switch, from `wai-quantum-landscape-fpga meter 1 0 300` (no settle, 300 samples). LAST deviation, not first touch, and of the level, not of one sample: the sensor throws single-sample spikes all through a segment, so each 15-sample median is held to a band around the segment's final level, the band being 2 sensor quanta (20 mW). The settle used by the campaign must exceed the last window outside it, or every point reads the previous state. The last single sample outside max(20 mW, 3 x the tail's SD) is printed beside it, for the spikes. python3 -I step_settle.py step.dat """ import statistics, sys WINDOW = 15 seg = {} for line in open(sys.argv[1]): if line.startswith('#') or not line.strip(): continue f = line.split() if len(f) < 4: continue seg.setdefault((int(f[0]), f[1]), []).append(int(f[3]) / 1000.0) for (p, state), xs in sorted(seg.items()): tail = xs[-60:] final = statistics.median(tail) band = max(20.0, 3 * statistics.pstdev(tail)) last = max((i for i, x in enumerate(xs) if abs(x - final) > band), default=-1) medians = [statistics.median(xs[i:i + WINDOW]) for i in range(0, len(xs) - WINDOW + 1, WINDOW)] off = max((k for k, m in enumerate(medians) if abs(m - final) > 20.0), default=-1) print(f"pass {p} {state:4s}: final {final:.1f} mW; level settled by {(off + 1) * WINDOW} s of {len(xs)} " f"({WINDOW}-sample medians within 20 mW after that); last single sample outside +-{band:.1f} " f"at {last + 1} s; first 10 s mean {statistics.mean(xs[:10]):.1f} mW")