Refactor radar system
This commit is contained in:
@@ -2,11 +2,11 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
import json
|
||||
from dataclasses import asdict, dataclass
|
||||
import logging
|
||||
from pathlib import Path
|
||||
|
||||
from python_app.file_io import atomic_write_json
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -21,12 +21,15 @@ class ProcessingLiveConfig:
|
||||
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_cut_m: float = 0.0
|
||||
bscan_max_depth_m: float = 8.0
|
||||
bscan_gain: float = 1.0
|
||||
bscan_start_freq_mhz: float = 100.0
|
||||
bscan_stop_freq_mhz: float = 8800.0
|
||||
legacy_gpr_mode: str = "point"
|
||||
relative_permittivity: float | None = None
|
||||
tx_geometry: list[dict] | None = None
|
||||
rx_geometry: list[dict] | None = None
|
||||
gpr_input_positions: list[int] | None = None
|
||||
gpr_output_positions: list[int] | None = None
|
||||
gpr_min_depth_m: float = 2.0
|
||||
@@ -88,6 +91,7 @@ class ProcessingLiveConfig:
|
||||
reprocess_current_result: bool = True
|
||||
history_command_seq: int = 0
|
||||
history_command: str = "none"
|
||||
settings_revision: int = 0
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
"""Normalize optional list fields to concrete integer lists."""
|
||||
@@ -102,60 +106,10 @@ class ProcessingLiveConfig:
|
||||
|
||||
def to_dict(self) -> dict[str, object]:
|
||||
"""Convert live config to JSON-serializable dictionary."""
|
||||
optional_geometry = {"relative_permittivity", "tx_geometry", "rx_geometry"}
|
||||
return {
|
||||
"processor_mode": str(self.processor_mode),
|
||||
"pass_through_channel": str(self.pass_through_channel),
|
||||
"pass_through_fixed_y_enabled": bool(self.pass_through_fixed_y_enabled),
|
||||
"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),
|
||||
"bscan_start_freq_mhz": float(self.bscan_start_freq_mhz),
|
||||
"bscan_stop_freq_mhz": float(self.bscan_stop_freq_mhz),
|
||||
"legacy_gpr_mode": str(self.legacy_gpr_mode),
|
||||
"gpr_input_positions": [int(value) for value in self.gpr_input_positions],
|
||||
"gpr_output_positions": [int(value) for value in self.gpr_output_positions],
|
||||
"gpr_min_depth_m": float(self.gpr_min_depth_m),
|
||||
"gpr_max_depth_m": float(self.gpr_max_depth_m),
|
||||
"gpr_range_comp_power": float(self.gpr_range_comp_power),
|
||||
"gpr_comp_power": float(self.gpr_comp_power),
|
||||
"gpr_object_min_frac": float(self.gpr_object_min_frac),
|
||||
"gpr_score_mode": str(self.gpr_score_mode),
|
||||
"gpr_motion_mode": str(self.gpr_motion_mode),
|
||||
"gpr_max_detected_objects_to_draw": int(self.gpr_max_detected_objects_to_draw),
|
||||
"gpr_draw_top_m_objects": int(self.gpr_draw_top_m_objects),
|
||||
"gpr_object_approach_min_frames": int(self.gpr_object_approach_min_frames),
|
||||
"gpr_speed_m_s": float(self.gpr_speed_m_s),
|
||||
"gpr_look_angle_deg": float(self.gpr_look_angle_deg),
|
||||
"gpr_direction_sign": float(self.gpr_direction_sign),
|
||||
"gpr_apply_freq_phase_correction": bool(self.gpr_apply_freq_phase_correction),
|
||||
"gpr_reference_mode": str(self.gpr_reference_mode),
|
||||
"gpr_snr_thresh": float(self.gpr_snr_thresh),
|
||||
"gpr_snr_comp_max": float(self.gpr_snr_comp_max),
|
||||
"gpr_start_freq_mhz": float(self.gpr_start_freq_mhz),
|
||||
"gpr_stop_freq_mhz": float(self.gpr_stop_freq_mhz),
|
||||
"gpr_background_subtract_enabled": bool(self.gpr_background_subtract_enabled),
|
||||
"gpr_background_mean_count": int(self.gpr_background_mean_count),
|
||||
"gpr_remove_sidelobe_objects_enabled": bool(self.gpr_remove_sidelobe_objects_enabled),
|
||||
"gpr_imaging_plane_y_m": float(self.gpr_imaging_plane_y_m),
|
||||
"legacy_gpr_min_visible_pair_count": float(self.legacy_gpr_min_visible_pair_count),
|
||||
"gpr_visible_x_min_m": float(self.gpr_visible_x_min_m),
|
||||
"gpr_visible_x_max_m": float(self.gpr_visible_x_max_m),
|
||||
"gpr_visible_z_min_m": float(self.gpr_visible_z_min_m),
|
||||
"gpr_visible_z_max_m": float(self.gpr_visible_z_max_m),
|
||||
"sar3d_frame_radius": int(self.sar3d_frame_radius),
|
||||
"sar3d_voxel_m": float(self.sar3d_voxel_m),
|
||||
"sar3d_bp_ground_depth_m": float(self.sar3d_bp_ground_depth_m),
|
||||
"sar3d_comp_range_power": float(self.sar3d_comp_range_power),
|
||||
"sar3d_use_compensation": bool(self.sar3d_use_compensation),
|
||||
"sar3d_normalize_each_frame": bool(self.sar3d_normalize_each_frame),
|
||||
"ignore_socket_speed": bool(self.ignore_socket_speed),
|
||||
"reprocess_current_result": bool(self.reprocess_current_result),
|
||||
"history_command_seq": int(self.history_command_seq),
|
||||
"history_command": str(self.history_command),
|
||||
name: value for name, value in asdict(self).items()
|
||||
if name not in optional_geometry or value is not None
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +134,4 @@ class ProcessingLiveConfigWriter:
|
||||
config.processor_mode,
|
||||
self._config_path,
|
||||
)
|
||||
temp_path = self._config_path.with_suffix(self._config_path.suffix + ".tmp")
|
||||
temp_path.write_text(json.dumps(config.to_dict(), indent=2), encoding="utf-8")
|
||||
temp_path.replace(self._config_path)
|
||||
return self._config_path
|
||||
return atomic_write_json(self._config_path, config.to_dict())
|
||||
|
||||
Reference in New Issue
Block a user