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:
+12
-5
@@ -8,7 +8,7 @@ from __future__ import annotations
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from core.scan_engine import ResumeState, ResumeTarget
|
||||
from core.sras_format import SrasFile
|
||||
from core.sras_format import WRITABLE_VERSIONS, SrasFile
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -44,8 +44,9 @@ def plan_resume(statuses, selected: set[int]) -> ResumePlan:
|
||||
final = set(selected)
|
||||
|
||||
targets = [
|
||||
ResumeTarget(angle_idx=s.index, data_offset=s.data_offset,
|
||||
n_rows=s.n_rows, angle_deg=s.angle_deg)
|
||||
ResumeTarget(angle_idx=s.index, bg_offset=s.bg_offset,
|
||||
data_offset=s.data_offset, n_rows=s.n_rows,
|
||||
angle_deg=s.angle_deg)
|
||||
for s in statuses if s.index in final
|
||||
]
|
||||
return ResumePlan(targets=targets,
|
||||
@@ -55,9 +56,15 @@ def plan_resume(statuses, selected: set[int]) -> ResumePlan:
|
||||
|
||||
def is_compatible(sras: SrasFile, *, velocity: float, laser_freq: float,
|
||||
sample_rate: float, n_channels: int) -> bool:
|
||||
"""Whether appending to this file with the current settings is safe."""
|
||||
"""Whether appending to this file with the current settings is safe.
|
||||
|
||||
A legacy v6/v10 file is not: it has one background for the whole scan,
|
||||
and every angle this engine acquires writes a background block of its
|
||||
own, which the older layout has no room for.
|
||||
"""
|
||||
h = sras.header
|
||||
return (h.bytes_per_sample == 1
|
||||
return (sras.version in WRITABLE_VERSIONS
|
||||
and h.bytes_per_sample == 1
|
||||
and h.n_channels == n_channels
|
||||
and abs(h.velocity - velocity) <= 1e-3
|
||||
and abs(h.laser_freq - laser_freq) <= 1e-3
|
||||
|
||||
Reference in New Issue
Block a user