59 lines
2.3 KiB
Python
Executable File
59 lines
2.3 KiB
Python
Executable File
"""Shared constants and writers for the .sras test fixtures.
|
||
|
||
The constants mirror the values tests/gen_goldens.py used when the committed
|
||
golden files were generated against the pre-refactor code (commit d185676);
|
||
they must never change, or the comparisons against those files stop meaning
|
||
anything. Those goldens are legacy v6 files — the one background per file
|
||
layout — and are now read-only fixtures for the parser.
|
||
|
||
``write_v7`` builds the current layout (one background per angle, inside the
|
||
data block) over the same geometry, for the tests that need a file this
|
||
version of the app could actually have written.
|
||
"""
|
||
from core.scan_geometry import build_plan
|
||
from core.sras_format import VERSION, create_scan_file, write_background_block
|
||
|
||
SPF = 8
|
||
SAMPLE_RATE = 6.25e9
|
||
CHANNELS = [1, 3, 4]
|
||
PREAMBLES = [f"WFMOUTPRE:CH{ch};SYNTHETIC;PT_FMT Y;XINCR 1.6E-10" for ch in CHANNELS]
|
||
BACKGROUND = bytes(range(SPF))
|
||
|
||
# build_plan inputs for the fixture geometry: 2 angles × 3 rows × 4 frames
|
||
TINY_PLAN_ARGS = dict(x_start=1.0, y_start=1.0, x_delta=0.02, y_delta=0.02,
|
||
num_angles=2, row_spacing=0.01)
|
||
LASER_FREQ_HZ = 20000.0
|
||
VELOCITY_MM_S = 100.0
|
||
|
||
|
||
def synthetic_frame(ai, ri, ci, fi):
|
||
return bytes((ai * 7 + ri * 5 + ci * 3 + fi + s) % 256 for s in range(SPF))
|
||
|
||
|
||
def tiny_plan():
|
||
"""The fixture geometry: 2 angles × 3 rows × 4 frames."""
|
||
return build_plan(**TINY_PLAN_ARGS, laser_freq_hz=LASER_FREQ_HZ,
|
||
velocity_mm_s=VELOCITY_MM_S)
|
||
|
||
|
||
def angle_background(ai):
|
||
"""A background that differs per angle, so tests can tell them apart."""
|
||
return bytes((ai * 11 + s) % 256 for s in range(SPF))
|
||
|
||
|
||
def write_v7(path, plan=None, version=None):
|
||
"""Write a complete current-format file: [background][rows] per angle."""
|
||
plan = plan if plan is not None else tiny_plan()
|
||
f = create_scan_file(path, plan, SPF, SAMPLE_RATE, PREAMBLES,
|
||
version=VERSION if version is None else version)
|
||
try:
|
||
for ai, pa in enumerate(plan.per_angle):
|
||
write_background_block(f, angle_background(ai))
|
||
for ri in range(pa.n_rows):
|
||
for ci in range(len(CHANNELS)):
|
||
for fi in range(pa.n_frames):
|
||
f.write(synthetic_frame(ai, ri, ci, fi))
|
||
finally:
|
||
f.close()
|
||
return plan
|