Per-angle background capture: v7/v11 .sras layout

A multi-angle scan runs for hours, but every angle was referenced against
one background captured before the first row of the first angle. That
reference has drifted by the last angle, and comparing angles — the whole
point of a multi-angle scan — was comparing each one against a noise floor
measured at whichever angle came first.

Every angle now captures its own. Before each angle's rows, the operator is
prompted to switch the Genesis laser off, the engine averages a fresh CH1
record, and the operator switches it back on. The data block therefore reads
[background][scan][background][scan] …, one pair per angle.

Format v7 (scan) and v11 (SAW check) carry the background inside the data
block, one length-prefixed block ahead of each angle's rows; the single
block that sat between the preambles and the data is gone. Per-angle offsets
now come from a walk of the data block at parse time rather than arithmetic
over the geometry table, and an angle whose background is not fully on disk
is the frontier — nothing of it was written yet.

v6/v10 files still read: SrasFile hands their one background to every angle,
so readers never branch on the version. Nothing writes them, and a resume
refuses them, since a re-acquired angle writes a block the old layout has no
room for. A resumed v7 angle rewrites its background in place, and the
engine checks the new block fits the room the file has before writing it —
anything else would shift every row behind it.

Two fixes made along the way:

  * QtScanController never accepted file_version, so every scan launched
    from the app raised TypeError at construction.
  * angle_status() left its cursor parked at the frontier, so every angle
    past it reported the frontier's own data_offset — which handed a resumed
    scan the same write position for several angles. Two recorded offsets in
    tests/golden/sras_expected.json are corrected accordingly.

The v6 goldens stay as parser fixtures; the writer is now locked against
bytes the test lays out from scan_format.md itself.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Thomas Ales
2026-09-04 12:44:25 -05:00
parent 83744c3337
commit aa06fa1460
21 changed files with 823 additions and 241 deletions
+20 -3
View File
@@ -3,6 +3,7 @@ from pathlib import Path
from core.scan_resume import is_compatible, plan_resume
from core.sras_format import SrasFile
from golden_util import write_v7
GOLDEN = Path(__file__).parent / "golden"
@@ -47,11 +48,17 @@ def test_selecting_only_a_later_angle_pulls_in_the_frontier():
assert plan.auto_added == [0]
def test_targets_carry_offsets_and_rows():
st = _statuses("complete.sras")
def test_targets_carry_offsets_and_rows(tmp_path):
out = tmp_path / "v7.sras"
write_v7(out)
st = SrasFile(out).angle_status()
plan = plan_resume(st, selected={0, 1})
for target, status in zip(plan.targets, st, strict=True):
# A re-acquired angle rewrites its background too, so a target has to
# know where the block starts as well as where the rows do.
assert target.bg_offset == status.bg_offset
assert target.data_offset == status.data_offset
assert target.bg_offset < target.data_offset
assert target.n_rows == status.n_rows
assert target.angle_deg == status.angle_deg
assert plan.total_rows == sum(s.n_rows for s in st)
@@ -65,9 +72,19 @@ def test_to_state_carries_samples_per_frame():
assert state.target_indices == {0}
def test_is_compatible_checks_acquisition_settings():
def test_is_compatible_rejects_a_legacy_file():
"""A v6 file has no room for the background block each angle now writes."""
sras = SrasFile(GOLDEN / "complete.sras")
h = sras.header
assert not is_compatible(sras, velocity=h.velocity, laser_freq=h.laser_freq,
sample_rate=h.sample_rate, n_channels=h.n_channels)
def test_is_compatible_checks_acquisition_settings(tmp_path):
out = tmp_path / "v7.sras"
write_v7(out)
sras = SrasFile(out)
h = sras.header
ok = dict(velocity=h.velocity, laser_freq=h.laser_freq,
sample_rate=h.sample_rate, n_channels=h.n_channels)
assert is_compatible(sras, **ok)