added s11!

This commit is contained in:
Ayzen
2026-03-26 18:29:42 +03:00
parent 9ddbde22bd
commit 077542cbd0
43 changed files with 713 additions and 347 deletions
+11 -11
View File
@@ -6,6 +6,7 @@ import json
from pathlib import Path
from python_app.models.run_config_model import RunConfigModel, parse_combos_from_text
from python_app.orchestration.preprocess_assets import PREPROCESS_ASSET_KEYS, PREPROCESS_ASSET_SPECS, preprocess_asset_model
from python_app.storage.npz_store import NpzStore
@@ -17,20 +18,19 @@ class ConfigWriter:
self._runtime_dir = runtime_dir
self._runtime_dir.mkdir(parents=True, exist_ok=True)
def prepare_s21_bundles(
def prepare_preprocess_bundles(
self,
store: NpzStore,
radar_key: str,
s21_calibration_set: str,
s21_reference_set: str,
) -> tuple[Path, Path]:
"""Export calibration/reference sets into binary bundles for preprocessor."""
calibration_bundle = self._runtime_dir / "s21_calibration_bundle.bin"
reference_bundle = self._runtime_dir / "s21_reference_bundle.bin"
store.export_set_bundle("calibration", radar_key, s21_calibration_set, calibration_bundle)
store.export_set_bundle("reference", radar_key, s21_reference_set, reference_bundle)
return calibration_bundle, reference_bundle
config: RunConfigModel,
) -> None:
"""Export selected preprocess sets into runtime bundles and update config paths."""
for key in PREPROCESS_ASSET_KEYS:
spec = PREPROCESS_ASSET_SPECS[key]
asset = preprocess_asset_model(config, key)
bundle_path = self._runtime_dir / spec.runtime_filename
store.export_set_bundle(spec.set_kind, radar_key, asset.set_name, bundle_path)
asset.bundle_path = str(bundle_path)
def write(self, config: RunConfigModel, output_path: Path) -> Path:
"""Write run configuration JSON file."""
@@ -19,6 +19,7 @@ class ProcessingLiveConfig:
pass_through_y_min_db: float = -100.0
pass_through_y_max_db: float = 0.0
bscan_axis: str = "abs"
bscan_channel: str = "s21"
bscan_cut_m: float = 0.824
bscan_max_depth_m: float = 1.0
bscan_gain: float = 1.0
@@ -58,6 +59,7 @@ class ProcessingLiveConfig:
"pass_through_y_min_db": float(self.pass_through_y_min_db),
"pass_through_y_max_db": float(self.pass_through_y_max_db),
"bscan_axis": str(self.bscan_axis),
"bscan_channel": str(self.bscan_channel),
"bscan_cut_m": float(self.bscan_cut_m),
"bscan_max_depth_m": float(self.bscan_max_depth_m),
"bscan_gain": float(self.bscan_gain),
@@ -0,0 +1,95 @@
"""Canonical preprocess asset definitions shared by GUI and runtime orchestration."""
from __future__ import annotations
from dataclasses import dataclass
from python_app.models.run_config_model import PreprocessAssetModel, RunConfigModel
@dataclass(frozen=True, slots=True)
class PreprocessAssetSpec:
"""Stable description of one preprocess asset."""
key: str
display_name: str
set_kind: str
runtime_filename: str
channel: str
PREPROCESS_ASSET_SPECS = {
"s21_calibration": PreprocessAssetSpec(
key="s21_calibration",
display_name="S21 Calibration",
set_kind="s21_calibration",
runtime_filename="s21_calibration_bundle.bin",
channel="s21",
),
"s21_reference": PreprocessAssetSpec(
key="s21_reference",
display_name="S21 Reference",
set_kind="s21_reference",
runtime_filename="s21_reference_bundle.bin",
channel="s21",
),
"s11_open": PreprocessAssetSpec(
key="s11_open",
display_name="S11 Open",
set_kind="s11_open",
runtime_filename="s11_open_calibration_bundle.bin",
channel="s11",
),
"s11_short": PreprocessAssetSpec(
key="s11_short",
display_name="S11 Short",
set_kind="s11_short",
runtime_filename="s11_short_calibration_bundle.bin",
channel="s11",
),
"s11_load": PreprocessAssetSpec(
key="s11_load",
display_name="S11 Load",
set_kind="s11_load",
runtime_filename="s11_load_calibration_bundle.bin",
channel="s11",
),
"s11_reference": PreprocessAssetSpec(
key="s11_reference",
display_name="S11 Reference",
set_kind="s11_reference",
runtime_filename="s11_reference_bundle.bin",
channel="s11",
),
}
PREPROCESS_ASSET_KEYS = tuple(PREPROCESS_ASSET_SPECS.keys())
S21_PREPROCESS_ASSET_KEYS = ("s21_calibration", "s21_reference")
S11_PREPROCESS_ASSET_KEYS = ("s11_open", "s11_short", "s11_load", "s11_reference")
def preprocess_asset_model(config: RunConfigModel, key: str) -> PreprocessAssetModel:
"""Return nested preprocess asset model by canonical asset key."""
if key == "s21_calibration":
return config.preprocess.s21.calibration
if key == "s21_reference":
return config.preprocess.s21.reference
if key == "s11_open":
return config.preprocess.s11.calibration.open
if key == "s11_short":
return config.preprocess.s11.calibration.short
if key == "s11_load":
return config.preprocess.s11.calibration.load
if key == "s11_reference":
return config.preprocess.s11.reference
raise KeyError(f"Unknown preprocess asset key: {key}")
def preprocess_asset_display_name(key: str) -> str:
"""Return human-readable label for preprocess asset."""
return PREPROCESS_ASSET_SPECS[key].display_name
def preprocess_asset_channel(key: str) -> str:
"""Return associated trace channel for preprocess asset."""
return PREPROCESS_ASSET_SPECS[key].channel
+5 -5
View File
@@ -40,16 +40,16 @@ def decode_trace_collection(payload: bytes, expected_magic: int) -> SweepCollect
freq = np.frombuffer(cursor.read_bytes(freq_bytes), dtype="<f4").astype(np.float32, copy=False)
interleaved_bytes = point_count * 8
# Runtime trace payloads now carry S11 before S21. The Python layer
# still works with S21 only for now, so consume and discard S11 here.
cursor.read_bytes(interleaved_bytes)
interleaved = np.frombuffer(cursor.read_bytes(interleaved_bytes), dtype="<f4")
s21 = (interleaved[0::2] + 1j * interleaved[1::2]).astype(np.complex64, copy=False)
s11_interleaved = np.frombuffer(cursor.read_bytes(interleaved_bytes), dtype="<f4")
s21_interleaved = np.frombuffer(cursor.read_bytes(interleaved_bytes), dtype="<f4")
s11 = (s11_interleaved[0::2] + 1j * s11_interleaved[1::2]).astype(np.complex64, copy=False)
s21 = (s21_interleaved[0::2] + 1j * s21_interleaved[1::2]).astype(np.complex64, copy=False)
traces.append(
TraceData(
combo=ComboKey(input_pos=input_pos, output_pos=output_pos),
frequency_hz=freq,
s11=s11,
s21=s21,
)
)