sar3d: GPU port of the notebook with four views
The sar3d processor is rewritten as a checked port of Multi_antenna_3D_clean_v1.ipynb: NVRTC kernels, timing from the trace stamps, notebook parameter names and one cubic SAR_VOXEL_M. It adds front, side, top and 3D views, drops gpr_cpp and the parity tools, and the GUI speed now applies only while the socket speed is ignored.
This commit is contained in:
@@ -371,9 +371,6 @@ class AppWindow(
|
||||
self._gpr_region_contours = []
|
||||
self._gpr_geometry_signature = None
|
||||
self._gpr_selected_geometry = None
|
||||
self._sar3d_lookup_table = None
|
||||
self._sar3d_xz_image_item = None
|
||||
self._sar3d_xy_image_item = None
|
||||
self._phase_viewbox = None
|
||||
self._history_run_signature = None
|
||||
self._processor_run_signature = None
|
||||
|
||||
@@ -13,7 +13,6 @@ from PyQt6.QtWidgets import (
|
||||
)
|
||||
|
||||
from python_app.gui.runtime.constraints import validate_processing_mode_constraints
|
||||
from python_app.gui.runtime.sar3d_views import sar3d_bottom_view_deg_from_label
|
||||
from python_app.orchestration.live_processing_config import ProcessingLiveConfig
|
||||
|
||||
_GPR_MODES = ("gpr", "legacy_gpr")
|
||||
@@ -83,32 +82,17 @@ _WEB_LIVE_SCHEMA = [
|
||||
("gpr_visible_z_max_m", "Visible window", _GPR_MODES, _dual("_gpr_visible_z_max_m", {"legacy_gpr": "_legacy_gpr_visible_z_max_m"})),
|
||||
("gpr_motion_mode", "Motion", ("gpr",), _attr("_gpr_motion_mode")),
|
||||
("gpr_look_angle_deg", "Motion", _GPR_LIKE_MODES, _dual("_gpr_look_angle_deg", {"legacy_gpr": "_legacy_gpr_look_angle_deg", "sar3d": "_sar3d_look_angle_deg"})),
|
||||
("gpr_direction_sign", "Motion", ("gpr", "sar3d"), _dual("_gpr_direction_sign", {"sar3d": "_sar3d_direction_sign"})),
|
||||
("gpr_apply_freq_phase_correction", "Motion", ("legacy_gpr", "sar3d"), _dual("_legacy_gpr_apply_freq_phase_correction", {"sar3d": "_sar3d_apply_freq_phase_correction"})),
|
||||
("gpr_direction_sign", "Motion", ("gpr",), _attr("_gpr_direction_sign")),
|
||||
("gpr_apply_freq_phase_correction", "Motion", ("legacy_gpr",), _attr("_legacy_gpr_apply_freq_phase_correction")),
|
||||
("gpr_reference_mode", "Motion", ("legacy_gpr",), _attr("_legacy_gpr_reference_mode")),
|
||||
("ignore_socket_speed", "Motion", _GPR_LIKE_MODES, _dual("_gpr_ignore_socket_speed_enabled", {"legacy_gpr": "_legacy_gpr_ignore_socket_speed_enabled", "sar3d": "_sar3d_ignore_socket_speed_enabled"})),
|
||||
("gpr_speed_m_s", "Motion", _GPR_LIKE_MODES, _dual("_gpr_speed_m_s", {"legacy_gpr": "_legacy_gpr_speed_m_s", "sar3d": "_sar3d_speed_m_s"})),
|
||||
("sar3d_frame_radius", "3D SAR", ("sar3d",), _attr("_sar3d_frame_radius")),
|
||||
("sar3d_edge_frame_weight", "3D SAR", ("sar3d",), _attr("_sar3d_edge_frame_weight")),
|
||||
("sar3d_pitch_override_enabled", "3D SAR", ("sar3d",), _attr("_sar3d_pitch_override_enabled")),
|
||||
("sar3d_pitch_deg", "3D SAR", ("sar3d",), _attr("_sar3d_pitch_deg")),
|
||||
("sar3d_ground_depth_m", "3D SAR", ("sar3d",), _attr("_sar3d_ground_depth_m")),
|
||||
("sar3d_x_min_m", "3D SAR", ("sar3d",), _attr("_sar3d_x_min_m")),
|
||||
("sar3d_x_max_m", "3D SAR", ("sar3d",), _attr("_sar3d_x_max_m")),
|
||||
("sar3d_y_min_m", "3D SAR", ("sar3d",), _attr("_sar3d_y_min_m")),
|
||||
("sar3d_y_max_m", "3D SAR", ("sar3d",), _attr("_sar3d_y_max_m")),
|
||||
("sar3d_z_min_m", "3D SAR", ("sar3d",), _attr("_sar3d_z_min_m")),
|
||||
("sar3d_z_max_m", "3D SAR", ("sar3d",), _attr("_sar3d_z_max_m")),
|
||||
("sar3d_voxel_x_m", "3D SAR", ("sar3d",), _attr("_sar3d_voxel_x_m")),
|
||||
("sar3d_voxel_y_m", "3D SAR", ("sar3d",), _attr("_sar3d_voxel_y_m")),
|
||||
("sar3d_voxel_z_m", "3D SAR", ("sar3d",), _attr("_sar3d_voxel_z_m")),
|
||||
("sar3d_norm_edge_margin_m", "3D SAR", ("sar3d",), _attr("_sar3d_norm_edge_margin_m")),
|
||||
("sar3d_smooth_sigma", "3D SAR", ("sar3d",), _attr("_sar3d_smooth_sigma")),
|
||||
("sar3d_voxel_m", "3D SAR", ("sar3d",), _attr("_sar3d_voxel_m")),
|
||||
("sar3d_bp_ground_depth_m", "3D SAR", ("sar3d",), _attr("_sar3d_bp_ground_depth_m")),
|
||||
("sar3d_comp_range_power", "3D SAR", ("sar3d",), _attr("_sar3d_comp_range_power")),
|
||||
("sar3d_tx_per_segment", "3D SAR", ("sar3d",), _attr("_sar3d_tx_per_segment")),
|
||||
("sar3d_use_compensation", "3D SAR", ("sar3d",), _attr("_sar3d_use_compensation")),
|
||||
("sar3d_normalize_pairs", "3D SAR", ("sar3d",), _attr("_sar3d_normalize_pairs")),
|
||||
("sar3d_bottom_view_deg", "3D SAR", ("sar3d",), _attr("_sar3d_bottom_view")),
|
||||
("sar3d_normalize_each_frame", "3D SAR", ("sar3d",), _attr("_sar3d_normalize_each_frame")),
|
||||
]
|
||||
_WEB_LIVE_GETTERS = {field: getter for field, _group, _modes, getter in _WEB_LIVE_SCHEMA}
|
||||
|
||||
@@ -259,7 +243,7 @@ class AppWindowLiveProcessingMixin:
|
||||
:meth:`_is_gpr_processing_mode`; this predicate gates only the shared
|
||||
behaviors (result drain on settings changes, geometry page visibility).
|
||||
"""
|
||||
return mode in set(_GPR_LIKE_MODES)
|
||||
return mode in _GPR_LIKE_MODES
|
||||
|
||||
def _validate_processing_mode_selection(self, mode: str) -> None:
|
||||
"""Validate requested processing mode against current stable/live GUI state."""
|
||||
@@ -295,10 +279,6 @@ class AppWindowLiveProcessingMixin:
|
||||
# Switch-position CSV text -> integer lists.
|
||||
values["gpr_input_positions"] = self._parse_csv_int_list(values["gpr_input_positions"])
|
||||
values["gpr_output_positions"] = self._parse_csv_int_list(values["gpr_output_positions"])
|
||||
# Bottom-view combo label -> projection angle in degrees.
|
||||
values["sar3d_bottom_view_deg"] = sar3d_bottom_view_deg_from_label(
|
||||
str(values["sar3d_bottom_view_deg"])
|
||||
)
|
||||
# Order-normalize the pass-through Y range so a reversed entry still works.
|
||||
y_min_db, y_max_db = values["pass_through_y_min_db"], values["pass_through_y_max_db"]
|
||||
values["pass_through_y_min_db"] = min(y_min_db, y_max_db)
|
||||
@@ -424,13 +404,23 @@ class AppWindowLiveProcessingMixin:
|
||||
except Exception as exc: # noqa: BLE001
|
||||
self._show_exception("Failed to update live processing settings", exc)
|
||||
|
||||
def _on_legacy_gpr_ignore_socket_speed_toggled(self, ignore_socket_speed: bool) -> None:
|
||||
"""Reflect socket/manual speed authority in the GUI and live config."""
|
||||
try:
|
||||
self._legacy_gpr_speed_m_s.setEnabled(bool(ignore_socket_speed))
|
||||
self._write_live_processing_config()
|
||||
except Exception as exc: # noqa: BLE001
|
||||
self._show_exception("Failed to update socket-speed mode", exc)
|
||||
def _sync_socket_speed_controls(self) -> None:
|
||||
"""Enable each GPR-like speed field only while its page ignores the socket speed.
|
||||
|
||||
Unchecked, the speed a locator client streams drives the processing and the
|
||||
field only stands in while no client sends one, so it must not look editable.
|
||||
"""
|
||||
for checkbox, speed in (
|
||||
(self._gpr_ignore_socket_speed_enabled, self._gpr_speed_m_s),
|
||||
(self._legacy_gpr_ignore_socket_speed_enabled, self._legacy_gpr_speed_m_s),
|
||||
(self._sar3d_ignore_socket_speed_enabled, self._sar3d_speed_m_s),
|
||||
):
|
||||
speed.setEnabled(checkbox.isChecked())
|
||||
|
||||
def _on_ignore_socket_speed_toggled(self, *_args) -> None:
|
||||
"""Switch the speed authority between the socket client and the GUI field."""
|
||||
self._sync_socket_speed_controls()
|
||||
self._on_processing_live_settings_changed()
|
||||
|
||||
def _on_gpr_visual_settings_changed(self, *_args) -> None:
|
||||
"""Redraw current GPR result using updated GUI-only render settings."""
|
||||
@@ -556,13 +546,13 @@ class AppWindowLiveProcessingMixin:
|
||||
elif mode == "sar3d":
|
||||
self._log(
|
||||
"Processing mode selected: sar3d "
|
||||
f"(inputs={self._sar3d_input_positions_input.text().strip() or '<all>'}, "
|
||||
f"outputs={self._sar3d_output_positions_input.text().strip() or '<all>'}, "
|
||||
f"depth={self._sar3d_min_depth_m.value():g}..{self._sar3d_max_depth_m.value():g} m, "
|
||||
f"freq={self._sar3d_start_freq_mhz.value():g}..{self._sar3d_stop_freq_mhz.value():g} MHz, "
|
||||
f"frame_radius={self._sar3d_frame_radius.value()}, "
|
||||
f"voxel={self._sar3d_voxel_x_m.value():g}x{self._sar3d_voxel_y_m.value():g}x{self._sar3d_voxel_z_m.value():g} m, "
|
||||
f"ground_depth={self._sar3d_ground_depth_m.value():g} m)"
|
||||
f"(INPUT_IDX={self._sar3d_input_positions_input.text().strip() or '<all>'}, "
|
||||
f"OUTPUT_IDX={self._sar3d_output_positions_input.text().strip() or '<all>'}, "
|
||||
f"F={self._sar3d_start_freq_mhz.value():g}..{self._sar3d_stop_freq_mhz.value():g} MHz, "
|
||||
f"DEPTH={self._sar3d_min_depth_m.value():g}..{self._sar3d_max_depth_m.value():g} m, "
|
||||
f"SAR_VOXEL_M={self._sar3d_voxel_m.value():g}, "
|
||||
f"LOOK_ANGLE_DEG={self._sar3d_look_angle_deg.value():g}, "
|
||||
f"SAR_FRAME_RADIUS={self._sar3d_frame_radius.value()})"
|
||||
)
|
||||
|
||||
def _clear_history_mode_caches(self) -> None:
|
||||
@@ -574,7 +564,7 @@ class AppWindowLiveProcessingMixin:
|
||||
self._clear_trace_plots()
|
||||
if hasattr(self, "_gpr_plot"):
|
||||
self._clear_gpr_plot()
|
||||
if hasattr(self, "_sar3d_xz_plot"):
|
||||
if hasattr(self, "_sar3d_plots"):
|
||||
self._clear_sar3d_plot()
|
||||
|
||||
def _redraw_after_history_deletion(self) -> None:
|
||||
|
||||
@@ -10,7 +10,6 @@ from pathlib import Path
|
||||
from PyQt6.QtCore import QSignalBlocker
|
||||
from PyQt6.QtWidgets import QFileDialog
|
||||
|
||||
from python_app.gui.runtime.sar3d_views import sar3d_bottom_view_label_from_deg
|
||||
from python_app.models.gui_profile_model import GuiProfileModel
|
||||
from python_app.models.run_config_model import RunConfigModel
|
||||
from python_app.orchestration.preprocess_assets import (
|
||||
@@ -346,28 +345,12 @@ class AppWindowConfigProfileIOMixin:
|
||||
self._sar3d_speed_m_s,
|
||||
self._sar3d_ignore_socket_speed_enabled,
|
||||
self._sar3d_look_angle_deg,
|
||||
self._sar3d_direction_sign,
|
||||
self._sar3d_apply_freq_phase_correction,
|
||||
self._sar3d_frame_radius,
|
||||
self._sar3d_edge_frame_weight,
|
||||
self._sar3d_pitch_override_enabled,
|
||||
self._sar3d_pitch_deg,
|
||||
self._sar3d_ground_depth_m,
|
||||
self._sar3d_x_min_m,
|
||||
self._sar3d_x_max_m,
|
||||
self._sar3d_y_min_m,
|
||||
self._sar3d_y_max_m,
|
||||
self._sar3d_z_min_m,
|
||||
self._sar3d_z_max_m,
|
||||
self._sar3d_voxel_x_m,
|
||||
self._sar3d_voxel_y_m,
|
||||
self._sar3d_voxel_z_m,
|
||||
self._sar3d_norm_edge_margin_m,
|
||||
self._sar3d_smooth_sigma,
|
||||
self._sar3d_voxel_m,
|
||||
self._sar3d_bp_ground_depth_m,
|
||||
self._sar3d_comp_range_power,
|
||||
self._sar3d_tx_per_segment,
|
||||
self._sar3d_use_compensation,
|
||||
self._sar3d_normalize_pairs,
|
||||
self._sar3d_normalize_each_frame,
|
||||
self._save_count,
|
||||
self._record_count,
|
||||
self._save_path_input,
|
||||
@@ -532,11 +515,9 @@ class AppWindowConfigProfileIOMixin:
|
||||
self._legacy_gpr_start_freq_mhz.setValue(float(gui_state.processing.legacy_gpr.start_freq_mhz))
|
||||
self._legacy_gpr_stop_freq_mhz.setValue(float(gui_state.processing.legacy_gpr.stop_freq_mhz))
|
||||
self._legacy_gpr_speed_m_s.setValue(float(gui_state.processing.legacy_gpr.speed_m_s))
|
||||
ignore_socket_speed_enabled = bool(
|
||||
gui_state.processing.legacy_gpr.ignore_socket_speed_enabled
|
||||
self._legacy_gpr_ignore_socket_speed_enabled.setChecked(
|
||||
bool(gui_state.processing.legacy_gpr.ignore_socket_speed_enabled)
|
||||
)
|
||||
self._legacy_gpr_ignore_socket_speed_enabled.setChecked(ignore_socket_speed_enabled)
|
||||
self._legacy_gpr_speed_m_s.setEnabled(ignore_socket_speed_enabled)
|
||||
self._legacy_gpr_look_angle_deg.setValue(float(gui_state.processing.legacy_gpr.look_angle_deg))
|
||||
self._legacy_gpr_apply_freq_phase_correction.setChecked(
|
||||
bool(gui_state.processing.legacy_gpr.apply_freq_phase_correction)
|
||||
@@ -566,32 +547,13 @@ class AppWindowConfigProfileIOMixin:
|
||||
self._sar3d_speed_m_s.setValue(float(sar3d_state.speed_m_s))
|
||||
self._sar3d_ignore_socket_speed_enabled.setChecked(bool(sar3d_state.ignore_socket_speed_enabled))
|
||||
self._sar3d_look_angle_deg.setValue(float(sar3d_state.look_angle_deg))
|
||||
self._sar3d_direction_sign.setValue(float(sar3d_state.direction_sign))
|
||||
self._sar3d_apply_freq_phase_correction.setChecked(bool(sar3d_state.apply_freq_phase_correction))
|
||||
self._sar3d_frame_radius.setValue(int(sar3d_state.frame_radius))
|
||||
self._sar3d_edge_frame_weight.setValue(float(sar3d_state.edge_frame_weight))
|
||||
self._sar3d_pitch_override_enabled.setChecked(bool(sar3d_state.pitch_override_enabled))
|
||||
self._sar3d_pitch_deg.setValue(float(sar3d_state.pitch_deg))
|
||||
self._sar3d_ground_depth_m.setValue(float(sar3d_state.ground_depth_m))
|
||||
self._sar3d_x_min_m.setValue(float(sar3d_state.x_min_m))
|
||||
self._sar3d_x_max_m.setValue(float(sar3d_state.x_max_m))
|
||||
self._sar3d_y_min_m.setValue(float(sar3d_state.y_min_m))
|
||||
self._sar3d_y_max_m.setValue(float(sar3d_state.y_max_m))
|
||||
self._sar3d_z_min_m.setValue(float(sar3d_state.z_min_m))
|
||||
self._sar3d_z_max_m.setValue(float(sar3d_state.z_max_m))
|
||||
self._sar3d_voxel_x_m.setValue(float(sar3d_state.voxel_x_m))
|
||||
self._sar3d_voxel_y_m.setValue(float(sar3d_state.voxel_y_m))
|
||||
self._sar3d_voxel_z_m.setValue(float(sar3d_state.voxel_z_m))
|
||||
self._sar3d_norm_edge_margin_m.setValue(float(sar3d_state.norm_edge_margin_m))
|
||||
self._sar3d_smooth_sigma.setValue(float(sar3d_state.smooth_sigma))
|
||||
self._sar3d_voxel_m.setValue(float(sar3d_state.voxel_m))
|
||||
self._sar3d_bp_ground_depth_m.setValue(float(sar3d_state.bp_ground_depth_m))
|
||||
self._sar3d_comp_range_power.setValue(float(sar3d_state.comp_range_power))
|
||||
self._sar3d_tx_per_segment.setValue(int(sar3d_state.tx_per_segment))
|
||||
self._sar3d_use_compensation.setChecked(bool(sar3d_state.use_compensation))
|
||||
self._sar3d_normalize_pairs.setChecked(bool(sar3d_state.normalize_pairs))
|
||||
self._set_combo_current_text(
|
||||
self._sar3d_bottom_view,
|
||||
sar3d_bottom_view_label_from_deg(float(sar3d_state.bottom_view_deg)),
|
||||
)
|
||||
self._sar3d_normalize_each_frame.setChecked(bool(sar3d_state.normalize_each_frame))
|
||||
self._sync_socket_speed_controls()
|
||||
|
||||
self._save_count.setValue(int(gui_state.data_actions.save_count))
|
||||
self._record_count.setValue(int(gui_state.data_actions.record_count))
|
||||
|
||||
@@ -25,7 +25,6 @@ from python_app.orchestration.preprocess_assets import (
|
||||
VISIBLE_PREPROCESS_ASSET_KEYS,
|
||||
preprocess_asset_model,
|
||||
)
|
||||
from python_app.gui.runtime.sar3d_views import sar3d_bottom_view_deg_from_label
|
||||
from python_app.storage.npz_store import radar_key_from_config
|
||||
|
||||
|
||||
@@ -434,31 +433,12 @@ class AppWindowConfigStateBuildersMixin:
|
||||
speed_m_s=float(self._sar3d_speed_m_s.value()),
|
||||
ignore_socket_speed_enabled=bool(self._sar3d_ignore_socket_speed_enabled.isChecked()),
|
||||
look_angle_deg=float(self._sar3d_look_angle_deg.value()),
|
||||
direction_sign=float(self._sar3d_direction_sign.value()),
|
||||
apply_freq_phase_correction=bool(self._sar3d_apply_freq_phase_correction.isChecked()),
|
||||
frame_radius=int(self._sar3d_frame_radius.value()),
|
||||
edge_frame_weight=float(self._sar3d_edge_frame_weight.value()),
|
||||
pitch_override_enabled=bool(self._sar3d_pitch_override_enabled.isChecked()),
|
||||
pitch_deg=float(self._sar3d_pitch_deg.value()),
|
||||
ground_depth_m=float(self._sar3d_ground_depth_m.value()),
|
||||
x_min_m=float(self._sar3d_x_min_m.value()),
|
||||
x_max_m=float(self._sar3d_x_max_m.value()),
|
||||
y_min_m=float(self._sar3d_y_min_m.value()),
|
||||
y_max_m=float(self._sar3d_y_max_m.value()),
|
||||
z_min_m=float(self._sar3d_z_min_m.value()),
|
||||
z_max_m=float(self._sar3d_z_max_m.value()),
|
||||
voxel_x_m=float(self._sar3d_voxel_x_m.value()),
|
||||
voxel_y_m=float(self._sar3d_voxel_y_m.value()),
|
||||
voxel_z_m=float(self._sar3d_voxel_z_m.value()),
|
||||
norm_edge_margin_m=float(self._sar3d_norm_edge_margin_m.value()),
|
||||
smooth_sigma=float(self._sar3d_smooth_sigma.value()),
|
||||
voxel_m=float(self._sar3d_voxel_m.value()),
|
||||
bp_ground_depth_m=float(self._sar3d_bp_ground_depth_m.value()),
|
||||
comp_range_power=float(self._sar3d_comp_range_power.value()),
|
||||
tx_per_segment=int(self._sar3d_tx_per_segment.value()),
|
||||
use_compensation=bool(self._sar3d_use_compensation.isChecked()),
|
||||
normalize_pairs=bool(self._sar3d_normalize_pairs.isChecked()),
|
||||
bottom_view_deg=sar3d_bottom_view_deg_from_label(
|
||||
self._sar3d_bottom_view.currentText()
|
||||
),
|
||||
normalize_each_frame=bool(self._sar3d_normalize_each_frame.isChecked()),
|
||||
),
|
||||
),
|
||||
data_actions=GuiDataActionsStateModel(
|
||||
|
||||
@@ -1,162 +1,158 @@
|
||||
"""3D SAR projection rendering helpers.
|
||||
"""3D SAR views of the volume published by the sar3d processor.
|
||||
|
||||
The sar3d processor publishes two normalized max-projections of the imaged
|
||||
volume as collection-level ImageF32 payloads, matching the legacy render
|
||||
conventions (X across, Z range/"вдаль", Y up):
|
||||
Scene axes: X across, Y height above the ground (Y = 0 is the ground), Z along
|
||||
the ground away from the radar. Payloads, the volume normalized to a peak of 1:
|
||||
|
||||
- ``sar3d_proj_xz`` — top view: X (m) horizontal, Z/range (m) vertical
|
||||
(max over the height Y), like the classic GPR heatmap;
|
||||
- ``sar3d_proj_bottom`` — switchable bottom view: height Y (m) vertical, the
|
||||
horizontal axis is the ground direction rotated by ``sar3d_bottom_view_deg``
|
||||
around Y (0° = front view X, 90° = side view Z, 30°/60° in between);
|
||||
|
||||
plus ``sar3d_peak`` (ScalarF32), the volume peak before normalization. Both
|
||||
projections are drawn on their own PlotWidgets stacked in one plot-stack page
|
||||
(top view on top), mirroring how the pass-through page stacks its two plots.
|
||||
- ``sar3d_front``, ``sar3d_side``, ``sar3d_top``: maximum projections onto X-Y
|
||||
(looking ahead from the radar), Z-Y (from the side) and X-Z (from above);
|
||||
- ``sar3d_oblique``: orthographic projection along the camera of the notebook's
|
||||
3D scene; ``sar3d_oblique_basis`` (2x3) gives its image axes u and v as scene
|
||||
directions, which places the scene box, the ground and the maximum on it;
|
||||
- ``sar3d_peak``: [level, X, Y, Z] of the volume maximum before normalization.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PyQt6.QtCore import QRectF
|
||||
import itertools
|
||||
|
||||
import numpy as np
|
||||
import pyqtgraph as pg
|
||||
from PyQt6.QtCore import QRectF, Qt
|
||||
|
||||
from python_app.gui.runtime.sar3d_views import sar3d_bottom_view_deg_from_label
|
||||
from python_app.gui.controllers.app_window_plot.bscan_plot_mixin import build_lut
|
||||
from python_app.models.dataset_model import ResultCollection
|
||||
|
||||
# Fraction of the projection maximum below which the heatmap is not highlighted
|
||||
# (same as cloud-threshold=0.75 in the VNA_AlGo 3D SAR animation): the color
|
||||
# scale is stretched over [frac, 1], everything below falls into the darkest
|
||||
# LUT color.
|
||||
HEATMAP_DISPLAY_THRESHOLD_FRAC = 0.75
|
||||
# Colours start at this fraction of the maximum; weaker voxels stay transparent,
|
||||
# like those under the threshold of the notebook's point cloud.
|
||||
DISPLAY_THRESHOLD = 0.75
|
||||
|
||||
# payload -> (title, x label, y label, scene axes (0 = X, 1 = Y, 2 = Z) along the plot axes)
|
||||
SAR3D_VIEWS: dict[str, tuple[str, str, str, tuple[int, int] | None]] = {
|
||||
"sar3d_front": ("Front (X-Y)", "X", "Y", (0, 1)),
|
||||
"sar3d_side": ("Side (Z-Y)", "Z", "Y", (2, 1)),
|
||||
"sar3d_top": ("Top (X-Z)", "X", "Z", (0, 2)),
|
||||
"sar3d_oblique": ("3D", "", "", None),
|
||||
}
|
||||
|
||||
# Corners of the scene box indexed by bits (x, y, z); an edge joins corners one bit apart.
|
||||
_BOX_EDGES = [(a, b) for a, b in itertools.combinations(range(8), 2) if bin(a ^ b).count("1") == 1]
|
||||
# Axis names go on the edges meeting at the bottom corner nearest the camera (X max, Y min, Z min).
|
||||
_AXIS_EDGES = {"X": (0, 1), "Y": (1, 3), "Z": (1, 5)}
|
||||
|
||||
|
||||
def _image_rect(x_axis: np.ndarray, y_axis: np.ndarray) -> QRectF:
|
||||
"""Rectangle covering the pixels centred on the axis samples."""
|
||||
dx = (x_axis[-1] - x_axis[0]) / max(len(x_axis) - 1, 1)
|
||||
dy = (y_axis[-1] - y_axis[0]) / max(len(y_axis) - 1, 1)
|
||||
return QRectF(x_axis[0] - dx / 2, y_axis[0] - dy / 2, x_axis[-1] - x_axis[0] + dx, y_axis[-1] - y_axis[0] + dy)
|
||||
|
||||
|
||||
class AppWindowSar3dPlotMixin:
|
||||
"""Renders 3D SAR volume projections published by the sar3d processor."""
|
||||
"""Draws the 3D SAR views."""
|
||||
|
||||
def _sar3d_bottom_view_labels(self) -> tuple[str, str]:
|
||||
"""Return (plot title, horizontal axis label) for the active bottom view.
|
||||
def _init_sar3d_views(self) -> None:
|
||||
"""Create the persistent items of the four 3D SAR plots."""
|
||||
lut = build_lut(["#081c15", "#1b4332", "#ffd166", "#f94144"]) # the GPR palette
|
||||
lut = np.column_stack([lut, np.full(len(lut), 255, dtype=np.uint8)])
|
||||
lut[0, 3] = 0 # below DISPLAY_THRESHOLD
|
||||
self._sar3d_images = {}
|
||||
self._sar3d_peaks = {}
|
||||
for name, (_title, x_label, y_label, _axes) in SAR3D_VIEWS.items():
|
||||
plot = self._sar3d_plots[name]
|
||||
self._disable_gpr_plot_interaction(plot, plot.getViewBox())
|
||||
plot.getViewBox().enableAutoRange(x=False, y=False)
|
||||
image = pg.ImageItem(axisOrder="row-major", lut=lut)
|
||||
plot.addItem(image)
|
||||
# Hollow, so the response at the maximum stays visible.
|
||||
peak = pg.ScatterPlotItem(symbol="star", size=18, pen=pg.mkPen("w", width=1.5), brush=None)
|
||||
peak.setZValue(3)
|
||||
plot.addItem(peak)
|
||||
self._sar3d_images[name] = image
|
||||
self._sar3d_peaks[name] = peak
|
||||
if x_label:
|
||||
plot.showGrid(x=True, y=True, alpha=0.2)
|
||||
plot.setLabel("bottom", x_label, units="m")
|
||||
plot.setLabel("left", y_label, units="m")
|
||||
if y_label == "Y":
|
||||
ground = pg.InfiniteLine(pos=0.0, angle=0, pen=pg.mkPen("w", width=1, style=Qt.PenStyle.DashLine))
|
||||
ground.setZValue(2)
|
||||
plot.addItem(ground)
|
||||
|
||||
The plot surfaces are created before the processing section builds the
|
||||
bottom-view combo, so fall back to the front view until it exists.
|
||||
"""
|
||||
combo = getattr(self, "_sar3d_bottom_view", None)
|
||||
degrees = sar3d_bottom_view_deg_from_label(combo.currentText()) if combo is not None else 0.0
|
||||
if degrees <= 1e-9:
|
||||
return "3D SAR front view (X-Y)", "X"
|
||||
if degrees >= 90.0 - 1e-9:
|
||||
return "3D SAR side view (Z-Y)", "Range Z"
|
||||
return f"3D SAR view @ {degrees:g}\N{DEGREE SIGN}", f"u({degrees:g}\N{DEGREE SIGN})"
|
||||
|
||||
def _configure_sar3d_plot_axes(self) -> None:
|
||||
"""Apply persistent axis labels and view settings to both projection plots."""
|
||||
_bottom_title, bottom_x_label = self._sar3d_bottom_view_labels()
|
||||
for plot, x_label, y_label in (
|
||||
(self._sar3d_xz_plot, "X", "Range Z"),
|
||||
(self._sar3d_xy_plot, bottom_x_label, "Height Y"),
|
||||
):
|
||||
plot_item = plot.getPlotItem()
|
||||
plot_item.showAxis("left", show=True)
|
||||
plot_item.showAxis("bottom", show=True)
|
||||
plot_item.setClipToView(True)
|
||||
plot.setLabel("bottom", x_label, units="m")
|
||||
plot.setLabel("left", y_label, units="m")
|
||||
view_box = plot.getViewBox()
|
||||
view_box.invertY(False)
|
||||
view_box.enableAutoRange(x=False, y=False)
|
||||
self._disable_gpr_plot_interaction(plot, view_box)
|
||||
|
||||
def _ensure_sar3d_plot_items(self) -> None:
|
||||
"""Create persistent projection image items once and reuse them on redraw."""
|
||||
if self._sar3d_xz_image_item is not None:
|
||||
return
|
||||
|
||||
self._configure_sar3d_plot_axes()
|
||||
if self._sar3d_lookup_table is None:
|
||||
# Same palette as the GPR accumulator so both imagers read alike.
|
||||
self._sar3d_lookup_table = self._build_lut(["#081c15", "#1b4332", "#ffd166", "#f94144"])
|
||||
|
||||
self._sar3d_xz_image_item = pg.ImageItem(axisOrder="row-major")
|
||||
self._sar3d_xz_image_item.setZValue(0)
|
||||
self._sar3d_xz_image_item.hide()
|
||||
self._sar3d_xz_plot.addItem(self._sar3d_xz_image_item)
|
||||
|
||||
self._sar3d_xy_image_item = pg.ImageItem(axisOrder="row-major")
|
||||
self._sar3d_xy_image_item.setZValue(0)
|
||||
self._sar3d_xy_image_item.hide()
|
||||
self._sar3d_xy_plot.addItem(self._sar3d_xy_image_item)
|
||||
oblique = self._sar3d_plots["sar3d_oblique"]
|
||||
oblique.hideAxis("bottom")
|
||||
oblique.hideAxis("left")
|
||||
oblique.setAspectLocked(True)
|
||||
# The notebook scene's ground, under the image so it shows through weak voxels.
|
||||
self._sar3d_ground = pg.PlotCurveItem(
|
||||
pen=pg.mkPen(115, 105, 88), brush=pg.mkBrush(115, 105, 88, 110), fillLevel="enclosed"
|
||||
)
|
||||
self._sar3d_ground.setZValue(-1)
|
||||
oblique.addItem(self._sar3d_ground)
|
||||
self._sar3d_box = pg.PlotCurveItem(pen=pg.mkPen(190, 190, 190, 170), connect="pairs")
|
||||
self._sar3d_box.setZValue(2)
|
||||
oblique.addItem(self._sar3d_box)
|
||||
self._sar3d_axis_labels = {}
|
||||
for axis_name in _AXIS_EDGES:
|
||||
label = pg.TextItem(axis_name, color=(190, 190, 190), anchor=(0.5, 0.5))
|
||||
oblique.addItem(label)
|
||||
self._sar3d_axis_labels[axis_name] = label
|
||||
|
||||
def _clear_sar3d_plot(self) -> None:
|
||||
"""Clear both 3D SAR projection surfaces."""
|
||||
if not hasattr(self, "_sar3d_xz_plot"):
|
||||
return
|
||||
self._configure_sar3d_plot_axes()
|
||||
if self._sar3d_xz_image_item is not None:
|
||||
self._sar3d_xz_image_item.hide()
|
||||
if self._sar3d_xy_image_item is not None:
|
||||
self._sar3d_xy_image_item.hide()
|
||||
bottom_title, _bottom_x_label = self._sar3d_bottom_view_labels()
|
||||
self._sar3d_xz_plot.setTitle("3D SAR top view (X-Z)")
|
||||
self._sar3d_xy_plot.setTitle(bottom_title)
|
||||
|
||||
def _draw_sar3d_projection(self, plot: pg.PlotWidget, image_item: pg.ImageItem, payload) -> bool:
|
||||
"""Draw one normalized projection payload onto its plot; return success."""
|
||||
image = np.asarray(payload.image, dtype=np.float32)
|
||||
x_axis = np.asarray(payload.image_x_axis, dtype=np.float32)
|
||||
y_axis = np.asarray(payload.image_y_axis, dtype=np.float32)
|
||||
if image.ndim != 2 or image.size == 0 or x_axis.size == 0 or y_axis.size == 0:
|
||||
image_item.hide()
|
||||
return False
|
||||
|
||||
x_min = float(x_axis[0])
|
||||
x_max = float(x_axis[-1])
|
||||
y_min = float(y_axis[0])
|
||||
y_max = float(y_axis[-1])
|
||||
rect = QRectF(x_min, y_min, max(x_max - x_min, 1e-6), max(y_max - y_min, 1e-6))
|
||||
|
||||
image_item.setImage(image, autoLevels=False)
|
||||
image_item.setRect(rect)
|
||||
image_item.setLookupTable(self._sar3d_lookup_table)
|
||||
# Projections are normalized to [0, 1] by the processor; stretch the
|
||||
# colors over [threshold, 1] like the 3D animation cloud cutoff.
|
||||
image_item.setLevels((HEATMAP_DISPLAY_THRESHOLD_FRAC, 1.0))
|
||||
image_item.show()
|
||||
plot.setXRange(x_min, x_max, padding=0.0)
|
||||
plot.setYRange(y_min, y_max, padding=0.0)
|
||||
return True
|
||||
"""Clear all four 3D SAR views."""
|
||||
for name, (title, *_rest) in SAR3D_VIEWS.items():
|
||||
self._sar3d_images[name].hide()
|
||||
self._sar3d_peaks[name].setData([], [])
|
||||
self._sar3d_plots[name].setTitle(title)
|
||||
self._sar3d_box.setData([], [])
|
||||
self._sar3d_ground.setData([], [])
|
||||
|
||||
def _draw_sar3d_projections(self, collection: ResultCollection) -> bool:
|
||||
"""Draw the latest collection-level 3D SAR top and bottom projections."""
|
||||
xz_payload = self._collection_payload_by_name(collection, "sar3d_proj_xz", kind=3)
|
||||
bottom_payload = self._collection_payload_by_name(collection, "sar3d_proj_bottom", kind=3)
|
||||
if xz_payload is None and bottom_payload is None:
|
||||
"""Draw the 3D SAR views of a result collection; return success."""
|
||||
payloads = {name: self._collection_payload_by_name(collection, name, kind=3) for name in SAR3D_VIEWS}
|
||||
basis = self._collection_payload_by_name(collection, "sar3d_oblique_basis", kind=4)
|
||||
if basis is None or any(payload is None or payload.image.size == 0 for payload in payloads.values()):
|
||||
self._clear_sar3d_plot()
|
||||
return False
|
||||
peak = self._collection_payload_by_name(collection, "sar3d_peak", kind=4)
|
||||
level, *peak_xyz = peak.table[0] if peak is not None else (None,)
|
||||
|
||||
for plot in (self._sar3d_xz_plot, self._sar3d_xy_plot):
|
||||
plot.setUpdatesEnabled(False)
|
||||
try:
|
||||
self._ensure_sar3d_plot_items()
|
||||
# Axis labels track the bottom-view selector (payload axes change with it).
|
||||
self._configure_sar3d_plot_axes()
|
||||
xz_drawn = xz_payload is not None and self._draw_sar3d_projection(
|
||||
self._sar3d_xz_plot, self._sar3d_xz_image_item, xz_payload
|
||||
)
|
||||
bottom_drawn = bottom_payload is not None and self._draw_sar3d_projection(
|
||||
self._sar3d_xy_plot, self._sar3d_xy_image_item, bottom_payload
|
||||
)
|
||||
if not xz_drawn and not bottom_drawn:
|
||||
self._clear_sar3d_plot()
|
||||
return False
|
||||
for name, payload in payloads.items():
|
||||
title, _x_label, _y_label, axes = SAR3D_VIEWS[name]
|
||||
rect = _image_rect(payload.image_x_axis, payload.image_y_axis)
|
||||
image = self._sar3d_images[name]
|
||||
image.setImage(payload.image, autoLevels=False, levels=(DISPLAY_THRESHOLD, 1.0))
|
||||
image.setRect(rect)
|
||||
image.show()
|
||||
plot = self._sar3d_plots[name]
|
||||
plot.setRange(rect, padding=0.0)
|
||||
if peak_xyz:
|
||||
position = basis.table @ np.asarray(peak_xyz) if axes is None else [peak_xyz[axis] for axis in axes]
|
||||
self._sar3d_peaks[name].setData([position[0]], [position[1]])
|
||||
else:
|
||||
self._sar3d_peaks[name].setData([], [])
|
||||
plot.setTitle(title)
|
||||
|
||||
peak_payload = self._collection_payload_by_name(collection, "sar3d_peak", kind=2)
|
||||
peak_suffix = ""
|
||||
if peak_payload is not None:
|
||||
peak_suffix = f" | peak={float(peak_payload.scalar_value):.3g}"
|
||||
bottom_title, _bottom_x_label = self._sar3d_bottom_view_labels()
|
||||
self._sar3d_xz_plot.setTitle(f"3D SAR top view (X-Z){peak_suffix}")
|
||||
self._sar3d_xy_plot.setTitle(bottom_title)
|
||||
finally:
|
||||
for plot in (self._sar3d_xz_plot, self._sar3d_xy_plot):
|
||||
plot.setUpdatesEnabled(True)
|
||||
# Scene box and ground on the oblique view, from the extents of the other views.
|
||||
front, top = payloads["sar3d_front"], payloads["sar3d_top"]
|
||||
bounds = [
|
||||
(front.image_x_axis[0], front.image_x_axis[-1]),
|
||||
(front.image_y_axis[0], front.image_y_axis[-1]),
|
||||
(top.image_y_axis[0], top.image_y_axis[-1]),
|
||||
]
|
||||
corners = np.array([[bounds[axis][(index >> axis) & 1] for axis in range(3)] for index in range(8)])
|
||||
projected = corners @ basis.table.T
|
||||
box = projected[np.ravel(_BOX_EDGES)]
|
||||
self._sar3d_box.setData(box[:, 0], box[:, 1])
|
||||
centre = projected.mean(axis=0)
|
||||
for axis_name, (start, end) in _AXIS_EDGES.items():
|
||||
middle = (projected[start] + projected[end]) / 2
|
||||
self._sar3d_axis_labels[axis_name].setPos(*(middle + 0.08 * (middle - centre))) # just outside
|
||||
(x0, x1), _, (z0, z1) = bounds
|
||||
ground = (np.array([[x0, 0.0, z0], [x1, 0.0, z0], [x1, 0.0, z1], [x0, 0.0, z1], [x0, 0.0, z0]]) @ basis.table.T).T
|
||||
self._sar3d_ground.setData(ground[0], ground[1])
|
||||
if level is not None:
|
||||
x, y, z = peak_xyz
|
||||
self._sar3d_plots["sar3d_oblique"].setTitle(
|
||||
f"3D | max X {x:+.2f}, Y {y:+.2f}, Z {z:.2f} m | level {level:.3g}"
|
||||
)
|
||||
return True
|
||||
|
||||
@@ -13,6 +13,7 @@ from __future__ import annotations
|
||||
from PyQt6.QtWidgets import (
|
||||
QComboBox,
|
||||
QFrame,
|
||||
QGridLayout,
|
||||
QGroupBox,
|
||||
QHBoxLayout,
|
||||
QLabel,
|
||||
@@ -25,6 +26,7 @@ from PyQt6.QtWidgets import (
|
||||
)
|
||||
import pyqtgraph as pg
|
||||
|
||||
from python_app.gui.controllers.app_window_plot.sar3d_plot_mixin import SAR3D_VIEWS
|
||||
from python_app.gui.controllers.sections import (
|
||||
build_data_actions_group,
|
||||
build_primary_actions_group,
|
||||
@@ -141,23 +143,16 @@ class AppWindowUiMixin:
|
||||
self._plot_stack.addWidget(self._gpr_plot)
|
||||
|
||||
def _build_sar3d_plot_page(self) -> None:
|
||||
"""Create 3D SAR page with stacked side (X-Z) and top (X-Y) projection plots."""
|
||||
# 3D SAR surface: container with two projection heatmaps, mirroring the
|
||||
# pass-through page layout (two stacked PlotWidgets on one stack page).
|
||||
"""Create the 3D SAR page: front, side, top and 3D views in a 2x2 grid."""
|
||||
self._sar3d_plots_container = QWidget()
|
||||
sar3d_layout = QVBoxLayout(self._sar3d_plots_container)
|
||||
sar3d_layout.setContentsMargins(0, 0, 0, 0)
|
||||
sar3d_layout.setSpacing(6)
|
||||
|
||||
self._sar3d_xz_plot = self._create_plot_widget(background="#0f141c")
|
||||
self._sar3d_xz_plot.showGrid(x=True, y=True, alpha=0.2)
|
||||
sar3d_layout.addWidget(self._sar3d_xz_plot, stretch=1)
|
||||
|
||||
self._sar3d_xy_plot = self._create_plot_widget(background="#0f141c")
|
||||
self._sar3d_xy_plot.showGrid(x=True, y=True, alpha=0.2)
|
||||
sar3d_layout.addWidget(self._sar3d_xy_plot, stretch=1)
|
||||
|
||||
self._configure_sar3d_plot_axes()
|
||||
layout = QGridLayout(self._sar3d_plots_container)
|
||||
layout.setContentsMargins(0, 0, 0, 0)
|
||||
layout.setSpacing(6)
|
||||
self._sar3d_plots = {}
|
||||
for index, name in enumerate(SAR3D_VIEWS):
|
||||
self._sar3d_plots[name] = self._create_plot_widget(background="#0f141c")
|
||||
layout.addWidget(self._sar3d_plots[name], index // 2, index % 2)
|
||||
self._init_sar3d_views()
|
||||
self._clear_sar3d_plot()
|
||||
self._plot_stack.addWidget(self._sar3d_plots_container)
|
||||
|
||||
|
||||
@@ -20,9 +20,13 @@ from PyQt6.QtWidgets import (
|
||||
|
||||
from python_app.gui.controllers.app_window_config.state_builders import GUI_SAVE_HISTORY_LIMIT
|
||||
from python_app.gui.controllers.sections.layout_helpers import FormRow, build_two_column_form_widget
|
||||
from python_app.gui.runtime.sar3d_views import (
|
||||
SAR3D_BOTTOM_VIEW_CHOICES,
|
||||
sar3d_bottom_view_label_from_deg,
|
||||
|
||||
|
||||
# Same semantics on every GPR-like page; the data_processor applies them.
|
||||
_IGNORE_SOCKET_SPEED_TOOLTIP = (
|
||||
"Checked: the speed below drives the motion correction. Unchecked: the speed a locator "
|
||||
"socket client streams ('vlc') does, and the field below only stands in while no client "
|
||||
"has sent one in the last 5 s."
|
||||
)
|
||||
|
||||
|
||||
@@ -290,10 +294,7 @@ def build_processing_group(owner) -> QGroupBox:
|
||||
|
||||
owner._gpr_ignore_socket_speed_enabled = QCheckBox("Ignore socket speed")
|
||||
owner._gpr_ignore_socket_speed_enabled.setChecked(bool(gpr_live_defaults.ignore_socket_speed_enabled))
|
||||
owner._gpr_ignore_socket_speed_enabled.setToolTip(
|
||||
"When checked, use the speed below for motion correction instead of the "
|
||||
"value streamed over the locator socket."
|
||||
)
|
||||
owner._gpr_ignore_socket_speed_enabled.setToolTip(_IGNORE_SOCKET_SPEED_TOOLTIP)
|
||||
|
||||
owner._gpr_speed_m_s = QDoubleSpinBox()
|
||||
owner._gpr_speed_m_s.setDecimals(3)
|
||||
@@ -475,12 +476,7 @@ def build_processing_group(owner) -> QGroupBox:
|
||||
owner._legacy_gpr_ignore_socket_speed_enabled.setChecked(
|
||||
bool(legacy_gpr_defaults.ignore_socket_speed_enabled)
|
||||
)
|
||||
# When the box is unchecked, an external TCP client controls the speed
|
||||
# through the C++ locator server; disable the spinner so the GUI value
|
||||
# cannot silently win against the live socket value.
|
||||
owner._legacy_gpr_speed_m_s.setEnabled(
|
||||
bool(legacy_gpr_defaults.ignore_socket_speed_enabled)
|
||||
)
|
||||
owner._legacy_gpr_ignore_socket_speed_enabled.setToolTip(_IGNORE_SOCKET_SPEED_TOOLTIP)
|
||||
|
||||
owner._legacy_gpr_look_angle_deg = QDoubleSpinBox()
|
||||
owner._legacy_gpr_look_angle_deg.setDecimals(2)
|
||||
@@ -575,26 +571,15 @@ def build_processing_group(owner) -> QGroupBox:
|
||||
)
|
||||
owner._processing_mode_pages.addWidget(legacy_gpr_page)
|
||||
|
||||
# 3D SAR page: shared gpr_* knobs get their own widget set (like legacy_gpr)
|
||||
# plus the sar3d-specific aperture/volume knobs consumed by the C++ processor.
|
||||
# 3D SAR page. The labels are the names of the reference notebook
|
||||
# Multi_antenna_3D_clean_v1.ipynb; the shared gpr_* fields get their own
|
||||
# widgets here, like on the legacy page.
|
||||
owner._sar3d_input_positions_input = QLineEdit(str(sar3d_defaults.input_positions))
|
||||
owner._sar3d_input_positions_input.setPlaceholderText("0,1,2")
|
||||
|
||||
owner._sar3d_output_positions_input = QLineEdit(str(sar3d_defaults.output_positions))
|
||||
owner._sar3d_output_positions_input.setPlaceholderText("0,1")
|
||||
|
||||
owner._sar3d_min_depth_m = QDoubleSpinBox()
|
||||
owner._sar3d_min_depth_m.setDecimals(2)
|
||||
owner._sar3d_min_depth_m.setRange(0.0, 50.0)
|
||||
owner._sar3d_min_depth_m.setSingleStep(0.1)
|
||||
owner._sar3d_min_depth_m.setValue(float(sar3d_defaults.min_depth_m))
|
||||
|
||||
owner._sar3d_max_depth_m = QDoubleSpinBox()
|
||||
owner._sar3d_max_depth_m.setDecimals(2)
|
||||
owner._sar3d_max_depth_m.setRange(0.1, 50.0)
|
||||
owner._sar3d_max_depth_m.setSingleStep(0.1)
|
||||
owner._sar3d_max_depth_m.setValue(float(sar3d_defaults.max_depth_m))
|
||||
|
||||
owner._sar3d_start_freq_mhz = QDoubleSpinBox()
|
||||
owner._sar3d_start_freq_mhz.setDecimals(1)
|
||||
owner._sar3d_start_freq_mhz.setRange(100.0, 8800.0)
|
||||
@@ -607,223 +592,98 @@ def build_processing_group(owner) -> QGroupBox:
|
||||
owner._sar3d_stop_freq_mhz.setSingleStep(10.0)
|
||||
owner._sar3d_stop_freq_mhz.setValue(float(sar3d_defaults.stop_freq_mhz))
|
||||
|
||||
owner._sar3d_min_depth_m = QDoubleSpinBox()
|
||||
owner._sar3d_min_depth_m.setDecimals(2)
|
||||
owner._sar3d_min_depth_m.setRange(0.0, 50.0)
|
||||
owner._sar3d_min_depth_m.setSingleStep(0.1)
|
||||
owner._sar3d_min_depth_m.setValue(float(sar3d_defaults.min_depth_m))
|
||||
owner._sar3d_min_depth_m.setToolTip("Radar depth gate start (m); the scene grid along Z follows the gate.")
|
||||
|
||||
owner._sar3d_max_depth_m = QDoubleSpinBox()
|
||||
owner._sar3d_max_depth_m.setDecimals(2)
|
||||
owner._sar3d_max_depth_m.setRange(0.1, 50.0)
|
||||
owner._sar3d_max_depth_m.setSingleStep(0.1)
|
||||
owner._sar3d_max_depth_m.setValue(float(sar3d_defaults.max_depth_m))
|
||||
owner._sar3d_max_depth_m.setToolTip("Radar depth gate end (m); the scene grid along Z follows the gate.")
|
||||
|
||||
owner._sar3d_voxel_m = QDoubleSpinBox()
|
||||
owner._sar3d_voxel_m.setDecimals(3)
|
||||
owner._sar3d_voxel_m.setRange(0.01, 0.1)
|
||||
owner._sar3d_voxel_m.setSingleStep(0.005)
|
||||
owner._sar3d_voxel_m.setValue(float(sar3d_defaults.voxel_m))
|
||||
owner._sar3d_voxel_m.setToolTip(
|
||||
"Edge of the cubic voxel (m), the same along X, Y and Z. Smaller is finer and slower: "
|
||||
"halving it makes 8 times more voxels."
|
||||
)
|
||||
|
||||
owner._sar3d_look_angle_deg = QDoubleSpinBox()
|
||||
owner._sar3d_look_angle_deg.setDecimals(2)
|
||||
owner._sar3d_look_angle_deg.setRange(-90.0, 90.0)
|
||||
owner._sar3d_look_angle_deg.setSingleStep(0.5)
|
||||
owner._sar3d_look_angle_deg.setValue(float(sar3d_defaults.look_angle_deg))
|
||||
owner._sar3d_look_angle_deg.setToolTip(
|
||||
"Radar look angle vs the range axis (deg). Used by intra-sweep motion correction."
|
||||
)
|
||||
|
||||
owner._sar3d_direction_sign = QDoubleSpinBox()
|
||||
owner._sar3d_direction_sign.setDecimals(0)
|
||||
owner._sar3d_direction_sign.setRange(-1.0, 1.0)
|
||||
owner._sar3d_direction_sign.setSingleStep(2.0)
|
||||
owner._sar3d_direction_sign.setValue(float(sar3d_defaults.direction_sign))
|
||||
owner._sar3d_direction_sign.setToolTip(
|
||||
"Motion direction along range: +1 (later frequencies deeper) or -1 (shallower)."
|
||||
"Downward tilt of the radar (deg): motion correction along range and the ground scene axes."
|
||||
)
|
||||
|
||||
owner._sar3d_ignore_socket_speed_enabled = QCheckBox("Ignore socket speed")
|
||||
owner._sar3d_ignore_socket_speed_enabled.setChecked(bool(sar3d_defaults.ignore_socket_speed_enabled))
|
||||
owner._sar3d_ignore_socket_speed_enabled.setToolTip(
|
||||
"When checked, use the speed below for motion correction instead of the "
|
||||
"value streamed over the locator socket."
|
||||
)
|
||||
owner._sar3d_ignore_socket_speed_enabled.setToolTip(_IGNORE_SOCKET_SPEED_TOOLTIP)
|
||||
|
||||
owner._sar3d_speed_m_s = QDoubleSpinBox()
|
||||
owner._sar3d_speed_m_s.setDecimals(3)
|
||||
owner._sar3d_speed_m_s.setRange(-100.0, 100.0)
|
||||
owner._sar3d_speed_m_s.setSingleStep(0.05)
|
||||
owner._sar3d_speed_m_s.setValue(float(sar3d_defaults.speed_m_s))
|
||||
owner._sar3d_speed_m_s.setToolTip(
|
||||
"Radar speed (m/s) used by intra-sweep motion correction when 'Ignore socket speed' is on."
|
||||
)
|
||||
|
||||
owner._sar3d_apply_freq_phase_correction = QCheckBox("Apply intra-sweep phase correction")
|
||||
owner._sar3d_apply_freq_phase_correction.setChecked(bool(sar3d_defaults.apply_freq_phase_correction))
|
||||
|
||||
owner._sar3d_frame_radius = QSpinBox()
|
||||
owner._sar3d_frame_radius.setRange(0, 25)
|
||||
owner._sar3d_frame_radius.setRange(0, 24)
|
||||
owner._sar3d_frame_radius.setValue(int(sar3d_defaults.frame_radius))
|
||||
owner._sar3d_frame_radius.setToolTip(
|
||||
"Synthetic-aperture half width in frames: 2*radius+1 consecutive frames form one aperture."
|
||||
"Aperture of 2*r+1 consecutive frames. 0: the current frame only (needs a vertical antenna "
|
||||
"baseline); >0 adds aperture from motion and needs an accurate speed. The image lags by r frames."
|
||||
)
|
||||
|
||||
owner._sar3d_edge_frame_weight = QDoubleSpinBox()
|
||||
owner._sar3d_edge_frame_weight.setDecimals(2)
|
||||
owner._sar3d_edge_frame_weight.setRange(0.0, 1.0)
|
||||
owner._sar3d_edge_frame_weight.setSingleStep(0.05)
|
||||
owner._sar3d_edge_frame_weight.setValue(float(sar3d_defaults.edge_frame_weight))
|
||||
owner._sar3d_edge_frame_weight.setToolTip(
|
||||
"Weight of the outermost aperture frames (1 = flat window, 0 = strong taper)."
|
||||
)
|
||||
|
||||
owner._sar3d_pitch_override_enabled = QCheckBox("Override pitch")
|
||||
owner._sar3d_pitch_override_enabled.setChecked(bool(sar3d_defaults.pitch_override_enabled))
|
||||
owner._sar3d_pitch_override_enabled.setToolTip(
|
||||
"When unchecked, the frame pitch follows the look angle (notebook "
|
||||
"BP_GROUND_PITCH_DEG = None); check to set it separately below."
|
||||
)
|
||||
|
||||
owner._sar3d_pitch_deg = QDoubleSpinBox()
|
||||
owner._sar3d_pitch_deg.setDecimals(2)
|
||||
owner._sar3d_pitch_deg.setRange(-90.0, 90.0)
|
||||
owner._sar3d_pitch_deg.setSingleStep(0.5)
|
||||
owner._sar3d_pitch_deg.setValue(float(sar3d_defaults.pitch_deg))
|
||||
owner._sar3d_pitch_deg.setToolTip(
|
||||
"Frame pitch (deg) used for ground coordinates and aperture offsets when the override is on."
|
||||
)
|
||||
|
||||
owner._sar3d_ground_depth_m = QDoubleSpinBox()
|
||||
owner._sar3d_ground_depth_m.setDecimals(2)
|
||||
owner._sar3d_ground_depth_m.setRange(0.0, 10.0)
|
||||
owner._sar3d_ground_depth_m.setSingleStep(0.05)
|
||||
owner._sar3d_ground_depth_m.setValue(float(sar3d_defaults.ground_depth_m))
|
||||
owner._sar3d_ground_depth_m.setToolTip(
|
||||
"Height of the lower antenna row above the ground (m); scene Y=0 is the ground."
|
||||
)
|
||||
|
||||
owner._sar3d_x_min_m = QDoubleSpinBox()
|
||||
owner._sar3d_x_min_m.setDecimals(2)
|
||||
owner._sar3d_x_min_m.setRange(-50.0, 50.0)
|
||||
owner._sar3d_x_min_m.setSingleStep(0.1)
|
||||
owner._sar3d_x_min_m.setValue(float(sar3d_defaults.x_min_m))
|
||||
|
||||
owner._sar3d_x_max_m = QDoubleSpinBox()
|
||||
owner._sar3d_x_max_m.setDecimals(2)
|
||||
owner._sar3d_x_max_m.setRange(-50.0, 50.0)
|
||||
owner._sar3d_x_max_m.setSingleStep(0.1)
|
||||
owner._sar3d_x_max_m.setValue(float(sar3d_defaults.x_max_m))
|
||||
|
||||
owner._sar3d_z_min_m = QDoubleSpinBox()
|
||||
owner._sar3d_z_min_m.setDecimals(2)
|
||||
owner._sar3d_z_min_m.setRange(-50.0, 50.0)
|
||||
owner._sar3d_z_min_m.setSingleStep(0.1)
|
||||
owner._sar3d_z_min_m.setValue(float(sar3d_defaults.z_min_m))
|
||||
|
||||
owner._sar3d_z_max_m = QDoubleSpinBox()
|
||||
owner._sar3d_z_max_m.setDecimals(2)
|
||||
owner._sar3d_z_max_m.setRange(-50.0, 50.0)
|
||||
owner._sar3d_z_max_m.setSingleStep(0.1)
|
||||
owner._sar3d_z_max_m.setValue(float(sar3d_defaults.z_max_m))
|
||||
|
||||
owner._sar3d_y_min_m = QDoubleSpinBox()
|
||||
owner._sar3d_y_min_m.setDecimals(2)
|
||||
owner._sar3d_y_min_m.setRange(-10.0, 10.0)
|
||||
owner._sar3d_y_min_m.setSingleStep(0.1)
|
||||
owner._sar3d_y_min_m.setValue(float(sar3d_defaults.y_min_m))
|
||||
|
||||
owner._sar3d_y_max_m = QDoubleSpinBox()
|
||||
owner._sar3d_y_max_m.setDecimals(2)
|
||||
owner._sar3d_y_max_m.setRange(-10.0, 10.0)
|
||||
owner._sar3d_y_max_m.setSingleStep(0.1)
|
||||
owner._sar3d_y_max_m.setValue(float(sar3d_defaults.y_max_m))
|
||||
|
||||
owner._sar3d_voxel_x_m = QDoubleSpinBox()
|
||||
owner._sar3d_voxel_x_m.setDecimals(3)
|
||||
owner._sar3d_voxel_x_m.setRange(0.005, 1.0)
|
||||
owner._sar3d_voxel_x_m.setSingleStep(0.005)
|
||||
owner._sar3d_voxel_x_m.setValue(float(sar3d_defaults.voxel_x_m))
|
||||
|
||||
owner._sar3d_voxel_y_m = QDoubleSpinBox()
|
||||
owner._sar3d_voxel_y_m.setDecimals(3)
|
||||
owner._sar3d_voxel_y_m.setRange(0.005, 1.0)
|
||||
owner._sar3d_voxel_y_m.setSingleStep(0.005)
|
||||
owner._sar3d_voxel_y_m.setValue(float(sar3d_defaults.voxel_y_m))
|
||||
|
||||
owner._sar3d_voxel_z_m = QDoubleSpinBox()
|
||||
owner._sar3d_voxel_z_m.setDecimals(3)
|
||||
owner._sar3d_voxel_z_m.setRange(0.005, 1.0)
|
||||
owner._sar3d_voxel_z_m.setSingleStep(0.005)
|
||||
owner._sar3d_voxel_z_m.setValue(float(sar3d_defaults.voxel_z_m))
|
||||
|
||||
owner._sar3d_norm_edge_margin_m = QDoubleSpinBox()
|
||||
owner._sar3d_norm_edge_margin_m.setDecimals(2)
|
||||
owner._sar3d_norm_edge_margin_m.setRange(0.0, 5.0)
|
||||
owner._sar3d_norm_edge_margin_m.setSingleStep(0.05)
|
||||
owner._sar3d_norm_edge_margin_m.setValue(float(sar3d_defaults.norm_edge_margin_m))
|
||||
owner._sar3d_norm_edge_margin_m.setToolTip(
|
||||
"Grid Y edges excluded from volume normalization (constant-range ridge)."
|
||||
)
|
||||
|
||||
owner._sar3d_smooth_sigma = QDoubleSpinBox()
|
||||
owner._sar3d_smooth_sigma.setDecimals(2)
|
||||
owner._sar3d_smooth_sigma.setRange(0.0, 10.0)
|
||||
owner._sar3d_smooth_sigma.setSingleStep(0.25)
|
||||
owner._sar3d_smooth_sigma.setValue(float(sar3d_defaults.smooth_sigma))
|
||||
owner._sar3d_smooth_sigma.setToolTip("Gaussian smoothing sigma over (Z, X) planes, voxels.")
|
||||
owner._sar3d_bp_ground_depth_m = QDoubleSpinBox()
|
||||
owner._sar3d_bp_ground_depth_m.setDecimals(2)
|
||||
owner._sar3d_bp_ground_depth_m.setRange(0.0, 10.0)
|
||||
owner._sar3d_bp_ground_depth_m.setSingleStep(0.05)
|
||||
owner._sar3d_bp_ground_depth_m.setValue(float(sar3d_defaults.bp_ground_depth_m))
|
||||
owner._sar3d_bp_ground_depth_m.setToolTip("Height of the lower antenna row above the ground (m); scene Y = 0 is the ground.")
|
||||
|
||||
owner._sar3d_comp_range_power = QDoubleSpinBox()
|
||||
owner._sar3d_comp_range_power.setDecimals(2)
|
||||
owner._sar3d_comp_range_power.setRange(0.0, 2.0)
|
||||
owner._sar3d_comp_range_power.setSingleStep(0.05)
|
||||
owner._sar3d_comp_range_power.setValue(float(sar3d_defaults.comp_range_power))
|
||||
owner._sar3d_comp_range_power.setToolTip("Geometric spreading compensation power.")
|
||||
owner._sar3d_comp_range_power.setToolTip("Geometric spreading compensation (Rtx*Rrx)^power, capped at 5.")
|
||||
|
||||
owner._sar3d_tx_per_segment = QSpinBox()
|
||||
owner._sar3d_tx_per_segment.setRange(1, 64)
|
||||
owner._sar3d_tx_per_segment.setValue(int(sar3d_defaults.tx_per_segment))
|
||||
owner._sar3d_tx_per_segment.setToolTip(
|
||||
"Fallback Tx-per-segment split of a frame when per-trace capture stamps are absent."
|
||||
)
|
||||
|
||||
owner._sar3d_use_compensation = QCheckBox("Use per-voxel compensation")
|
||||
owner._sar3d_use_compensation = QCheckBox("SAR_USE_COMPENSATION")
|
||||
owner._sar3d_use_compensation.setChecked(bool(sar3d_defaults.use_compensation))
|
||||
|
||||
owner._sar3d_normalize_pairs = QCheckBox("Normalize Tx/Rx pairs")
|
||||
owner._sar3d_normalize_pairs.setChecked(bool(sar3d_defaults.normalize_pairs))
|
||||
|
||||
owner._sar3d_bottom_view = QComboBox()
|
||||
owner._sar3d_bottom_view.addItems([label for label, _deg in SAR3D_BOTTOM_VIEW_CHOICES])
|
||||
owner._set_combo_current_text(
|
||||
owner._sar3d_bottom_view,
|
||||
sar3d_bottom_view_label_from_deg(float(sar3d_defaults.bottom_view_deg)),
|
||||
)
|
||||
owner._sar3d_bottom_view.setToolTip(
|
||||
"Bottom plot projection: front view (X-Y), side view (Z-Y) or an "
|
||||
"intermediate rotation around the vertical axis. The top plot always "
|
||||
"shows the X-Z top view."
|
||||
)
|
||||
owner._sar3d_normalize_each_frame = QCheckBox("SAR_NORMALIZE_EACH_FRAME")
|
||||
owner._sar3d_normalize_each_frame.setChecked(bool(sar3d_defaults.normalize_each_frame))
|
||||
owner._sar3d_normalize_each_frame.setToolTip("Scale every Tx/Rx A-scan by its median inside the depth gate.")
|
||||
|
||||
sar3d_page = _build_processing_mode_page(
|
||||
owner._processing_mode_pages,
|
||||
[
|
||||
("Input positions", owner._sar3d_input_positions_input),
|
||||
("Output positions", owner._sar3d_output_positions_input),
|
||||
("Min depth m", owner._sar3d_min_depth_m),
|
||||
("Max depth m", owner._sar3d_max_depth_m),
|
||||
("Start MHz", owner._sar3d_start_freq_mhz),
|
||||
("Stop MHz", owner._sar3d_stop_freq_mhz),
|
||||
("Look angle deg", owner._sar3d_look_angle_deg),
|
||||
("Direction sign", owner._sar3d_direction_sign),
|
||||
("INPUT_IDX", owner._sar3d_input_positions_input),
|
||||
("OUTPUT_IDX", owner._sar3d_output_positions_input),
|
||||
("F_START MHz", owner._sar3d_start_freq_mhz),
|
||||
("F_STOP MHz", owner._sar3d_stop_freq_mhz),
|
||||
("MIN_DEPTH", owner._sar3d_min_depth_m),
|
||||
("MAX_DEPTH", owner._sar3d_max_depth_m),
|
||||
("SAR_VOXEL_M", owner._sar3d_voxel_m),
|
||||
("LOOK_ANGLE_DEG", owner._sar3d_look_angle_deg),
|
||||
owner._sar3d_ignore_socket_speed_enabled,
|
||||
("Speed m/s", owner._sar3d_speed_m_s),
|
||||
owner._sar3d_apply_freq_phase_correction,
|
||||
("Frame radius", owner._sar3d_frame_radius),
|
||||
("Edge frame weight", owner._sar3d_edge_frame_weight),
|
||||
owner._sar3d_pitch_override_enabled,
|
||||
("Pitch deg", owner._sar3d_pitch_deg),
|
||||
("Ground depth m", owner._sar3d_ground_depth_m),
|
||||
("X min m", owner._sar3d_x_min_m),
|
||||
("X max m", owner._sar3d_x_max_m),
|
||||
("Y min m", owner._sar3d_y_min_m),
|
||||
("Y max m", owner._sar3d_y_max_m),
|
||||
("Z min m", owner._sar3d_z_min_m),
|
||||
("Z max m", owner._sar3d_z_max_m),
|
||||
("Voxel X m", owner._sar3d_voxel_x_m),
|
||||
("Voxel Y m", owner._sar3d_voxel_y_m),
|
||||
("Voxel Z m", owner._sar3d_voxel_z_m),
|
||||
("Norm edge margin m", owner._sar3d_norm_edge_margin_m),
|
||||
("Smooth sigma", owner._sar3d_smooth_sigma),
|
||||
("Comp range power", owner._sar3d_comp_range_power),
|
||||
("Tx per segment", owner._sar3d_tx_per_segment),
|
||||
("Bottom view", owner._sar3d_bottom_view),
|
||||
("SPEED_M_S", owner._sar3d_speed_m_s),
|
||||
("SAR_FRAME_RADIUS", owner._sar3d_frame_radius),
|
||||
("BP_GROUND_DEPTH_M", owner._sar3d_bp_ground_depth_m),
|
||||
("COMP_RANGE_POWER", owner._sar3d_comp_range_power),
|
||||
owner._sar3d_use_compensation,
|
||||
owner._sar3d_normalize_pairs,
|
||||
owner._sar3d_normalize_each_frame,
|
||||
],
|
||||
split_index=13,
|
||||
split_index=8,
|
||||
)
|
||||
owner._processing_mode_pages.addWidget(sar3d_page)
|
||||
|
||||
@@ -858,7 +718,7 @@ def build_processing_group(owner) -> QGroupBox:
|
||||
owner._gpr_motion_mode.currentTextChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._gpr_look_angle_deg.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._gpr_direction_sign.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._gpr_ignore_socket_speed_enabled.toggled.connect(owner._on_processing_live_settings_changed)
|
||||
owner._gpr_ignore_socket_speed_enabled.toggled.connect(owner._on_ignore_socket_speed_toggled)
|
||||
owner._gpr_speed_m_s.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._gpr_start_freq_mhz.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._gpr_stop_freq_mhz.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
@@ -885,9 +745,7 @@ def build_processing_group(owner) -> QGroupBox:
|
||||
owner._legacy_gpr_start_freq_mhz.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._legacy_gpr_stop_freq_mhz.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._legacy_gpr_speed_m_s.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._legacy_gpr_ignore_socket_speed_enabled.toggled.connect(
|
||||
owner._on_legacy_gpr_ignore_socket_speed_toggled
|
||||
)
|
||||
owner._legacy_gpr_ignore_socket_speed_enabled.toggled.connect(owner._on_ignore_socket_speed_toggled)
|
||||
owner._legacy_gpr_look_angle_deg.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._legacy_gpr_apply_freq_phase_correction.toggled.connect(owner._on_processing_live_settings_changed)
|
||||
owner._legacy_gpr_reference_mode.currentTextChanged.connect(owner._on_processing_live_settings_changed)
|
||||
@@ -901,36 +759,23 @@ def build_processing_group(owner) -> QGroupBox:
|
||||
owner._legacy_gpr_visible_z_max_m.valueChanged.connect(owner._on_gpr_locator_window_changed)
|
||||
owner._sar3d_input_positions_input.editingFinished.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_output_positions_input.editingFinished.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_min_depth_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_max_depth_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_start_freq_mhz.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_stop_freq_mhz.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_look_angle_deg.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_direction_sign.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_ignore_socket_speed_enabled.toggled.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_speed_m_s.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_apply_freq_phase_correction.toggled.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_frame_radius.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_edge_frame_weight.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_pitch_override_enabled.toggled.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_pitch_deg.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_ground_depth_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_x_min_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_x_max_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_z_min_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_z_max_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_y_min_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_y_max_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_voxel_x_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_voxel_y_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_voxel_z_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_norm_edge_margin_m.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_smooth_sigma.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_comp_range_power.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_tx_per_segment.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
for widget in (
|
||||
owner._sar3d_start_freq_mhz,
|
||||
owner._sar3d_stop_freq_mhz,
|
||||
owner._sar3d_min_depth_m,
|
||||
owner._sar3d_max_depth_m,
|
||||
owner._sar3d_voxel_m,
|
||||
owner._sar3d_look_angle_deg,
|
||||
owner._sar3d_speed_m_s,
|
||||
owner._sar3d_frame_radius,
|
||||
owner._sar3d_bp_ground_depth_m,
|
||||
owner._sar3d_comp_range_power,
|
||||
):
|
||||
widget.valueChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_ignore_socket_speed_enabled.toggled.connect(owner._on_ignore_socket_speed_toggled)
|
||||
owner._sar3d_use_compensation.toggled.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_normalize_pairs.toggled.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_bottom_view.currentTextChanged.connect(owner._on_processing_live_settings_changed)
|
||||
owner._sar3d_normalize_each_frame.toggled.connect(owner._on_processing_live_settings_changed)
|
||||
|
||||
owner._sync_socket_speed_controls()
|
||||
owner._set_processing_mode_page(owner._processing_mode.currentText())
|
||||
return group
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
"""Shared mapping for the sar3d bottom-view projection choices.
|
||||
|
||||
The bottom plot of the sar3d mode projects the imaged volume along a
|
||||
horizontal direction rotated around the vertical Y axis: 0° = front view
|
||||
(X horizontal), 90° = side view (Z horizontal). One shared mapping keeps the
|
||||
combo box, the live-config build, the profile persistence and the plot labels
|
||||
consistent.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
SAR3D_BOTTOM_VIEW_CHOICES: tuple[tuple[str, float], ...] = (
|
||||
("front (0°)", 0.0),
|
||||
("30°", 30.0),
|
||||
("60°", 60.0),
|
||||
("side (90°)", 90.0),
|
||||
)
|
||||
|
||||
|
||||
def sar3d_bottom_view_deg_from_label(label: str) -> float:
|
||||
"""Map a bottom-view combo label to its projection angle in degrees."""
|
||||
for choice_label, degrees in SAR3D_BOTTOM_VIEW_CHOICES:
|
||||
if choice_label == label:
|
||||
return degrees
|
||||
return 0.0
|
||||
|
||||
|
||||
def sar3d_bottom_view_label_from_deg(degrees: float) -> str:
|
||||
"""Map a projection angle to the nearest bottom-view combo label."""
|
||||
return min(SAR3D_BOTTOM_VIEW_CHOICES, key=lambda choice: abs(choice[1] - float(degrees)))[0]
|
||||
@@ -4,6 +4,7 @@ Encodes commands to wire bytes, decodes device responses, and manages the
|
||||
serial port connection to the laser control board.
|
||||
"""
|
||||
|
||||
import errno
|
||||
import logging
|
||||
import struct
|
||||
from typing import Optional
|
||||
@@ -204,9 +205,9 @@ class Protocol:
|
||||
exclusive=True,
|
||||
)
|
||||
except serial.SerialException as exc:
|
||||
# pyserial raises SerialException with errno EAGAIN/EWOULDBLOCK (11)
|
||||
# when another process already holds the exclusive flock.
|
||||
if getattr(exc, "errno", None) in (11,) or "exclusively lock" in str(exc).lower():
|
||||
# pyserial raises SerialException with errno EWOULDBLOCK when another
|
||||
# process already holds the exclusive flock.
|
||||
if getattr(exc, "errno", None) == errno.EWOULDBLOCK or "exclusively lock" in str(exc).lower():
|
||||
logger.error("Laser serial port '%s' is busy (held by another program)", port)
|
||||
raise PortBusyError(port) from exc
|
||||
logger.error("Cannot open laser serial port '%s': %s", port, exc)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import dataclasses
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
@@ -172,6 +173,21 @@ def gui_profile_from_dict(payload: dict[str, Any]) -> GuiProfileModel:
|
||||
legacy_gpr_context,
|
||||
)
|
||||
|
||||
sar3d_context = "gui.processing.sar3d"
|
||||
sar3d_defaults = GuiSar3dStateModel()
|
||||
|
||||
def sar3d_string(key: str) -> str:
|
||||
return _optional_string(sar3d_object, key, getattr(sar3d_defaults, key), sar3d_context)
|
||||
|
||||
def sar3d_bool(key: str) -> bool:
|
||||
return _optional_bool(sar3d_object, key, getattr(sar3d_defaults, key), sar3d_context)
|
||||
|
||||
def sar3d_int(key: str) -> int:
|
||||
return _optional_int(sar3d_object, key, getattr(sar3d_defaults, key), sar3d_context)
|
||||
|
||||
def sar3d_float(key: str) -> float:
|
||||
return _optional_float(sar3d_object, key, getattr(sar3d_defaults, key), sar3d_context)
|
||||
|
||||
gui.processing = GuiProcessingStateModel(
|
||||
selected_mode=selected_mode,
|
||||
pass_through=GuiPassThroughStateModel(
|
||||
@@ -455,198 +471,21 @@ def gui_profile_from_dict(payload: dict[str, Any]) -> GuiProfileModel:
|
||||
visible_z_max_m=legacy_float("visible_z_max_m", gui.processing.legacy_gpr.visible_z_max_m),
|
||||
),
|
||||
sar3d=GuiSar3dStateModel(
|
||||
input_positions=_optional_string(
|
||||
sar3d_object,
|
||||
"input_positions",
|
||||
gui.processing.sar3d.input_positions,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
output_positions=_optional_string(
|
||||
sar3d_object,
|
||||
"output_positions",
|
||||
gui.processing.sar3d.output_positions,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
min_depth_m=_optional_float(
|
||||
sar3d_object,
|
||||
"min_depth_m",
|
||||
gui.processing.sar3d.min_depth_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
max_depth_m=_optional_float(
|
||||
sar3d_object,
|
||||
"max_depth_m",
|
||||
gui.processing.sar3d.max_depth_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
start_freq_mhz=_optional_float(
|
||||
sar3d_object,
|
||||
"start_freq_mhz",
|
||||
gui.processing.sar3d.start_freq_mhz,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
stop_freq_mhz=_optional_float(
|
||||
sar3d_object,
|
||||
"stop_freq_mhz",
|
||||
gui.processing.sar3d.stop_freq_mhz,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
speed_m_s=_optional_float(
|
||||
sar3d_object,
|
||||
"speed_m_s",
|
||||
gui.processing.sar3d.speed_m_s,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
ignore_socket_speed_enabled=_optional_bool(
|
||||
sar3d_object,
|
||||
"ignore_socket_speed_enabled",
|
||||
gui.processing.sar3d.ignore_socket_speed_enabled,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
look_angle_deg=_optional_float(
|
||||
sar3d_object,
|
||||
"look_angle_deg",
|
||||
gui.processing.sar3d.look_angle_deg,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
direction_sign=_optional_float(
|
||||
sar3d_object,
|
||||
"direction_sign",
|
||||
gui.processing.sar3d.direction_sign,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
apply_freq_phase_correction=_optional_bool(
|
||||
sar3d_object,
|
||||
"apply_freq_phase_correction",
|
||||
gui.processing.sar3d.apply_freq_phase_correction,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
frame_radius=_optional_int(
|
||||
sar3d_object,
|
||||
"frame_radius",
|
||||
gui.processing.sar3d.frame_radius,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
edge_frame_weight=_optional_float(
|
||||
sar3d_object,
|
||||
"edge_frame_weight",
|
||||
gui.processing.sar3d.edge_frame_weight,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
pitch_override_enabled=_optional_bool(
|
||||
sar3d_object,
|
||||
"pitch_override_enabled",
|
||||
gui.processing.sar3d.pitch_override_enabled,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
pitch_deg=_optional_float(
|
||||
sar3d_object,
|
||||
"pitch_deg",
|
||||
gui.processing.sar3d.pitch_deg,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
ground_depth_m=_optional_float(
|
||||
sar3d_object,
|
||||
"ground_depth_m",
|
||||
gui.processing.sar3d.ground_depth_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
x_min_m=_optional_float(
|
||||
sar3d_object,
|
||||
"x_min_m",
|
||||
gui.processing.sar3d.x_min_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
x_max_m=_optional_float(
|
||||
sar3d_object,
|
||||
"x_max_m",
|
||||
gui.processing.sar3d.x_max_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
y_min_m=_optional_float(
|
||||
sar3d_object,
|
||||
"y_min_m",
|
||||
gui.processing.sar3d.y_min_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
y_max_m=_optional_float(
|
||||
sar3d_object,
|
||||
"y_max_m",
|
||||
gui.processing.sar3d.y_max_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
z_min_m=_optional_float(
|
||||
sar3d_object,
|
||||
"z_min_m",
|
||||
gui.processing.sar3d.z_min_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
z_max_m=_optional_float(
|
||||
sar3d_object,
|
||||
"z_max_m",
|
||||
gui.processing.sar3d.z_max_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
voxel_x_m=_optional_float(
|
||||
sar3d_object,
|
||||
"voxel_x_m",
|
||||
gui.processing.sar3d.voxel_x_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
voxel_y_m=_optional_float(
|
||||
sar3d_object,
|
||||
"voxel_y_m",
|
||||
gui.processing.sar3d.voxel_y_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
voxel_z_m=_optional_float(
|
||||
sar3d_object,
|
||||
"voxel_z_m",
|
||||
gui.processing.sar3d.voxel_z_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
norm_edge_margin_m=_optional_float(
|
||||
sar3d_object,
|
||||
"norm_edge_margin_m",
|
||||
gui.processing.sar3d.norm_edge_margin_m,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
smooth_sigma=_optional_float(
|
||||
sar3d_object,
|
||||
"smooth_sigma",
|
||||
gui.processing.sar3d.smooth_sigma,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
comp_range_power=_optional_float(
|
||||
sar3d_object,
|
||||
"comp_range_power",
|
||||
gui.processing.sar3d.comp_range_power,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
tx_per_segment=_optional_int(
|
||||
sar3d_object,
|
||||
"tx_per_segment",
|
||||
gui.processing.sar3d.tx_per_segment,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
use_compensation=_optional_bool(
|
||||
sar3d_object,
|
||||
"use_compensation",
|
||||
gui.processing.sar3d.use_compensation,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
normalize_pairs=_optional_bool(
|
||||
sar3d_object,
|
||||
"normalize_pairs",
|
||||
gui.processing.sar3d.normalize_pairs,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
bottom_view_deg=_optional_float(
|
||||
sar3d_object,
|
||||
"bottom_view_deg",
|
||||
gui.processing.sar3d.bottom_view_deg,
|
||||
"gui.processing.sar3d",
|
||||
),
|
||||
input_positions=sar3d_string("input_positions"),
|
||||
output_positions=sar3d_string("output_positions"),
|
||||
min_depth_m=sar3d_float("min_depth_m"),
|
||||
max_depth_m=sar3d_float("max_depth_m"),
|
||||
start_freq_mhz=sar3d_float("start_freq_mhz"),
|
||||
stop_freq_mhz=sar3d_float("stop_freq_mhz"),
|
||||
speed_m_s=sar3d_float("speed_m_s"),
|
||||
ignore_socket_speed_enabled=sar3d_bool("ignore_socket_speed_enabled"),
|
||||
look_angle_deg=sar3d_float("look_angle_deg"),
|
||||
frame_radius=sar3d_int("frame_radius"),
|
||||
voxel_m=sar3d_float("voxel_m"),
|
||||
bp_ground_depth_m=sar3d_float("bp_ground_depth_m"),
|
||||
comp_range_power=sar3d_float("comp_range_power"),
|
||||
use_compensation=sar3d_bool("use_compensation"),
|
||||
normalize_each_frame=sar3d_bool("normalize_each_frame"),
|
||||
),
|
||||
)
|
||||
if gui.processing.selected_mode not in {"pass_through", "bscan", "gpr", "legacy_gpr", "sar3d"}:
|
||||
@@ -689,20 +528,8 @@ def gui_profile_from_dict(payload: dict[str, Any]) -> GuiProfileModel:
|
||||
raise ValueError("gui.processing.legacy_gpr.min_visible_pair_count must be >= 1")
|
||||
if gui.processing.sar3d.frame_radius < 0:
|
||||
raise ValueError("gui.processing.sar3d.frame_radius must be >= 0")
|
||||
if not 0.0 <= gui.processing.sar3d.edge_frame_weight <= 1.0:
|
||||
raise ValueError("gui.processing.sar3d.edge_frame_weight must be within [0, 1]")
|
||||
if min(gui.processing.sar3d.voxel_x_m, gui.processing.sar3d.voxel_y_m, gui.processing.sar3d.voxel_z_m) <= 0.0:
|
||||
raise ValueError("gui.processing.sar3d.voxel_x/y/z_m must each be > 0")
|
||||
if gui.processing.sar3d.x_max_m <= gui.processing.sar3d.x_min_m:
|
||||
raise ValueError("gui.processing.sar3d.x_max_m must be > x_min_m")
|
||||
if gui.processing.sar3d.y_max_m <= gui.processing.sar3d.y_min_m:
|
||||
raise ValueError("gui.processing.sar3d.y_max_m must be > y_min_m")
|
||||
if gui.processing.sar3d.z_max_m <= gui.processing.sar3d.z_min_m:
|
||||
raise ValueError("gui.processing.sar3d.z_max_m must be > z_min_m")
|
||||
if gui.processing.sar3d.ground_depth_m < 0.0:
|
||||
raise ValueError("gui.processing.sar3d.ground_depth_m must be >= 0")
|
||||
if gui.processing.sar3d.tx_per_segment < 1:
|
||||
raise ValueError("gui.processing.sar3d.tx_per_segment must be >= 1")
|
||||
if not gui.processing.sar3d.voxel_m > 0.0:
|
||||
raise ValueError("gui.processing.sar3d.voxel_m must be > 0")
|
||||
|
||||
data_actions_object = _as_dict(gui_object.get("data_actions"), "gui.data_actions")
|
||||
gui.data_actions = GuiDataActionsStateModel(
|
||||
@@ -854,40 +681,7 @@ def gui_profile_to_dict(model: GuiProfileModel) -> dict[str, Any]:
|
||||
"visible_z_min_m": gui.processing.legacy_gpr.visible_z_min_m,
|
||||
"visible_z_max_m": gui.processing.legacy_gpr.visible_z_max_m,
|
||||
},
|
||||
"sar3d": {
|
||||
"input_positions": gui.processing.sar3d.input_positions,
|
||||
"output_positions": gui.processing.sar3d.output_positions,
|
||||
"min_depth_m": gui.processing.sar3d.min_depth_m,
|
||||
"max_depth_m": gui.processing.sar3d.max_depth_m,
|
||||
"start_freq_mhz": gui.processing.sar3d.start_freq_mhz,
|
||||
"stop_freq_mhz": gui.processing.sar3d.stop_freq_mhz,
|
||||
"speed_m_s": gui.processing.sar3d.speed_m_s,
|
||||
"ignore_socket_speed_enabled": gui.processing.sar3d.ignore_socket_speed_enabled,
|
||||
"look_angle_deg": gui.processing.sar3d.look_angle_deg,
|
||||
"direction_sign": gui.processing.sar3d.direction_sign,
|
||||
"apply_freq_phase_correction": gui.processing.sar3d.apply_freq_phase_correction,
|
||||
"frame_radius": gui.processing.sar3d.frame_radius,
|
||||
"edge_frame_weight": gui.processing.sar3d.edge_frame_weight,
|
||||
"pitch_override_enabled": gui.processing.sar3d.pitch_override_enabled,
|
||||
"pitch_deg": gui.processing.sar3d.pitch_deg,
|
||||
"ground_depth_m": gui.processing.sar3d.ground_depth_m,
|
||||
"x_min_m": gui.processing.sar3d.x_min_m,
|
||||
"x_max_m": gui.processing.sar3d.x_max_m,
|
||||
"y_min_m": gui.processing.sar3d.y_min_m,
|
||||
"y_max_m": gui.processing.sar3d.y_max_m,
|
||||
"z_min_m": gui.processing.sar3d.z_min_m,
|
||||
"z_max_m": gui.processing.sar3d.z_max_m,
|
||||
"voxel_x_m": gui.processing.sar3d.voxel_x_m,
|
||||
"voxel_y_m": gui.processing.sar3d.voxel_y_m,
|
||||
"voxel_z_m": gui.processing.sar3d.voxel_z_m,
|
||||
"norm_edge_margin_m": gui.processing.sar3d.norm_edge_margin_m,
|
||||
"smooth_sigma": gui.processing.sar3d.smooth_sigma,
|
||||
"comp_range_power": gui.processing.sar3d.comp_range_power,
|
||||
"tx_per_segment": gui.processing.sar3d.tx_per_segment,
|
||||
"use_compensation": gui.processing.sar3d.use_compensation,
|
||||
"normalize_pairs": gui.processing.sar3d.normalize_pairs,
|
||||
"bottom_view_deg": gui.processing.sar3d.bottom_view_deg,
|
||||
},
|
||||
"sar3d": dataclasses.asdict(gui.processing.sar3d),
|
||||
},
|
||||
"data_actions": {
|
||||
"save_count": gui.data_actions.save_count,
|
||||
|
||||
@@ -127,45 +127,25 @@ class GuiLegacyGprStateModel:
|
||||
class GuiSar3dStateModel:
|
||||
"""UI-only defaults for the 3D SAR (sar3d) live settings.
|
||||
|
||||
The band, depth gate, antenna selection and motion knobs mirror the shared
|
||||
gpr_* live-config fields; the sar3d_* knobs mirror the reference notebook
|
||||
(Multi_antenna_3D_clean_v1.ipynb) defaults used by the C++ sar3d processor.
|
||||
Values are the reference notebook's (Multi_antenna_3D_clean_v1.ipynb), whose
|
||||
names the GUI shows: INPUT_IDX, F_START, MIN_DEPTH, LOOK_ANGLE_DEG, ...
|
||||
"""
|
||||
|
||||
input_positions: str = ""
|
||||
output_positions: str = ""
|
||||
min_depth_m: float = 2.5
|
||||
min_depth_m: float = 2.0
|
||||
max_depth_m: float = 8.0
|
||||
start_freq_mhz: float = 2000.0
|
||||
start_freq_mhz: float = 1500.0
|
||||
stop_freq_mhz: float = 6000.0
|
||||
speed_m_s: float = 0.0
|
||||
ignore_socket_speed_enabled: bool = False
|
||||
look_angle_deg: float = 17.5
|
||||
direction_sign: float = 1.0
|
||||
apply_freq_phase_correction: bool = True
|
||||
look_angle_deg: float = 19.5
|
||||
frame_radius: int = 0
|
||||
edge_frame_weight: float = 0.8
|
||||
pitch_override_enabled: bool = False
|
||||
pitch_deg: float = 17.5
|
||||
ground_depth_m: float = 1.25
|
||||
x_min_m: float = -2.0
|
||||
x_max_m: float = 2.0
|
||||
y_min_m: float = -0.5
|
||||
y_max_m: float = 2.0
|
||||
z_min_m: float = 0.0
|
||||
z_max_m: float = 8.0
|
||||
voxel_x_m: float = 0.025
|
||||
voxel_y_m: float = 0.02
|
||||
voxel_z_m: float = 0.02
|
||||
norm_edge_margin_m: float = 0.3
|
||||
smooth_sigma: float = 1.5
|
||||
voxel_m: float = 0.02
|
||||
bp_ground_depth_m: float = 1.25
|
||||
comp_range_power: float = 0.3
|
||||
tx_per_segment: int = 2
|
||||
use_compensation: bool = True
|
||||
normalize_pairs: bool = True
|
||||
# Bottom-view projection angle around the vertical Y axis, degrees:
|
||||
# 0 = front view (X-Y), 90 = side view (Z-Y).
|
||||
bottom_view_deg: float = 0.0
|
||||
normalize_each_frame: bool = True
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
|
||||
@@ -72,40 +72,16 @@ class ProcessingLiveConfig:
|
||||
gpr_visible_x_max_m: float = 2.0
|
||||
gpr_visible_z_min_m: float = 0.0
|
||||
gpr_visible_z_max_m: float = 14.0
|
||||
# 3D SAR (sar3d processor) parameters; defaults mirror the reference
|
||||
# notebook Multi_antenna_3D_clean_v1.ipynb. The frequency band, depth gate,
|
||||
# antenna selection and motion parameters are shared with the gpr_* fields.
|
||||
# 3D SAR (sar3d processor) parameters, named after the reference notebook
|
||||
# Multi_antenna_3D_clean_v1.ipynb (SAR_FRAME_RADIUS, BP_GROUND_DEPTH_M, ...).
|
||||
# The band, depth gate, antenna selection, speed and look angle are the
|
||||
# shared gpr_* fields.
|
||||
sar3d_frame_radius: int = 0
|
||||
sar3d_edge_frame_weight: float = 0.8
|
||||
# Frame pitch override; disabled -> the pitch follows gpr_look_angle_deg.
|
||||
sar3d_pitch_override_enabled: bool = False
|
||||
sar3d_pitch_deg: float = 17.5
|
||||
# Height of the lower antenna row above the ground (scene Y=0 = ground).
|
||||
sar3d_ground_depth_m: float = 1.25
|
||||
# Scene grid bounds (metres): X across, Y height above the ground, Z along
|
||||
# the ground away from the radar. Voxels outside the radar depth gate are
|
||||
# zeroed by the mask regardless of the Z window.
|
||||
sar3d_x_min_m: float = -2.0
|
||||
sar3d_x_max_m: float = 2.0
|
||||
sar3d_y_min_m: float = -0.5
|
||||
sar3d_y_max_m: float = 2.0
|
||||
sar3d_z_min_m: float = 0.0
|
||||
sar3d_z_max_m: float = 8.0
|
||||
sar3d_voxel_x_m: float = 0.025
|
||||
sar3d_voxel_y_m: float = 0.02
|
||||
sar3d_voxel_z_m: float = 0.02
|
||||
# Volume finalization: Y-edge margin excluded from normalization, Gaussian
|
||||
# smoothing sigma over (Z, X) planes.
|
||||
sar3d_norm_edge_margin_m: float = 0.3
|
||||
sar3d_smooth_sigma: float = 1.5
|
||||
sar3d_voxel_m: float = 0.02 # SAR_VOXEL_M, one edge for X, Y and Z
|
||||
sar3d_bp_ground_depth_m: float = 1.25
|
||||
sar3d_comp_range_power: float = 0.3
|
||||
# Fallback frame segmentation when per-trace capture stamps are absent.
|
||||
sar3d_tx_per_segment: int = 2
|
||||
sar3d_use_compensation: bool = True
|
||||
sar3d_normalize_pairs: bool = True
|
||||
# Bottom-view projection angle around the vertical Y axis, degrees:
|
||||
# 0 = front view (X horizontal), 90 = side view (Z horizontal).
|
||||
sar3d_bottom_view_deg: float = 0.0
|
||||
sar3d_normalize_each_frame: bool = True
|
||||
# When true, the C++ data_processor ignores socket-supplied vlc updates
|
||||
# and keeps using `gpr_speed_m_s` from this file.
|
||||
ignore_socket_speed: bool = False
|
||||
@@ -171,26 +147,11 @@ class ProcessingLiveConfig:
|
||||
"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_edge_frame_weight": float(self.sar3d_edge_frame_weight),
|
||||
"sar3d_pitch_override_enabled": bool(self.sar3d_pitch_override_enabled),
|
||||
"sar3d_pitch_deg": float(self.sar3d_pitch_deg),
|
||||
"sar3d_ground_depth_m": float(self.sar3d_ground_depth_m),
|
||||
"sar3d_x_min_m": float(self.sar3d_x_min_m),
|
||||
"sar3d_x_max_m": float(self.sar3d_x_max_m),
|
||||
"sar3d_y_min_m": float(self.sar3d_y_min_m),
|
||||
"sar3d_y_max_m": float(self.sar3d_y_max_m),
|
||||
"sar3d_z_min_m": float(self.sar3d_z_min_m),
|
||||
"sar3d_z_max_m": float(self.sar3d_z_max_m),
|
||||
"sar3d_voxel_x_m": float(self.sar3d_voxel_x_m),
|
||||
"sar3d_voxel_y_m": float(self.sar3d_voxel_y_m),
|
||||
"sar3d_voxel_z_m": float(self.sar3d_voxel_z_m),
|
||||
"sar3d_norm_edge_margin_m": float(self.sar3d_norm_edge_margin_m),
|
||||
"sar3d_smooth_sigma": float(self.sar3d_smooth_sigma),
|
||||
"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_tx_per_segment": int(self.sar3d_tx_per_segment),
|
||||
"sar3d_use_compensation": bool(self.sar3d_use_compensation),
|
||||
"sar3d_normalize_pairs": bool(self.sar3d_normalize_pairs),
|
||||
"sar3d_bottom_view_deg": float(self.sar3d_bottom_view_deg),
|
||||
"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),
|
||||
|
||||
@@ -1,262 +0,0 @@
|
||||
"""Headless smoke: replay the recorded VNA_AlGo dataset through the full pipeline.
|
||||
|
||||
Loads the replay profile, creates neutral preprocess sets, launches the whole
|
||||
pipeline (replay_raw_producer -> data_preprocessor -> data_processor) via the
|
||||
ProcessSupervisor with unique ring names, forces the sar3d processor through
|
||||
processing_live.json, and asserts that:
|
||||
|
||||
- sar3d projection payloads arrive with a positive peak;
|
||||
- collection ids increase monotonically (including across a dataset loop);
|
||||
- the preprocessor is transparent: a preprocessed_tap trace equals the
|
||||
recorded snapshot's s21 within float32 rounding.
|
||||
|
||||
Usage:
|
||||
python -m python_app.scripts.replay_smoke_run \
|
||||
[--config run_config_examples/run_config_replay_vna.example.json] \
|
||||
[--duration 20.0]
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
import time
|
||||
|
||||
import numpy as np
|
||||
|
||||
from python_app.models.run_config_model import RunConfigModel
|
||||
from python_app.orchestration.config_writer import ConfigWriter
|
||||
from python_app.orchestration.live_processing_config import (
|
||||
ProcessingLiveConfig,
|
||||
ProcessingLiveConfigWriter,
|
||||
)
|
||||
from python_app.orchestration.process_supervisor import ProcessSupervisor
|
||||
from python_app.orchestration.shm import ShmRingReader
|
||||
from python_app.orchestration.shm.decoder import PREPROC_MAGIC, decode_trace_collection
|
||||
from python_app.storage.npz_store import NpzStore, radar_key_from_config
|
||||
from python_app.workflows.kamil_adc_neutral_preprocess import build_neutral_s21_sets
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
def _make_unique_ring_name(prefix: str) -> str:
|
||||
"""Build unique POSIX SHM ring name."""
|
||||
return f"/{prefix}_{os.getpid()}_{time.monotonic_ns()}"
|
||||
|
||||
|
||||
def _sar3d_live_config(profile_path: Path) -> ProcessingLiveConfig:
|
||||
"""Build a sar3d live config from the profile's gui.processing.sar3d section.
|
||||
|
||||
RunConfigModel does not carry the GUI section (it belongs to the GUI profile
|
||||
layer), so the sar3d defaults are read straight from the profile JSON.
|
||||
"""
|
||||
payload = json.loads(profile_path.read_text(encoding="utf-8"))
|
||||
sar3d = (
|
||||
payload.get("gui", {}).get("processing", {}).get("sar3d", {})
|
||||
if isinstance(payload, dict)
|
||||
else {}
|
||||
)
|
||||
|
||||
def _positions(text: str) -> list[int]:
|
||||
return [int(value) for value in str(text).split(",") if value.strip()]
|
||||
|
||||
live = ProcessingLiveConfig(processor_mode="sar3d", ignore_socket_speed=True)
|
||||
if not isinstance(sar3d, dict) or not sar3d:
|
||||
return live
|
||||
live.gpr_input_positions = _positions(sar3d.get("input_positions", ""))
|
||||
live.gpr_output_positions = _positions(sar3d.get("output_positions", ""))
|
||||
live.gpr_min_depth_m = float(sar3d.get("min_depth_m", live.gpr_min_depth_m))
|
||||
live.gpr_max_depth_m = float(sar3d.get("max_depth_m", live.gpr_max_depth_m))
|
||||
live.gpr_start_freq_mhz = float(sar3d.get("start_freq_mhz", live.gpr_start_freq_mhz))
|
||||
live.gpr_stop_freq_mhz = float(sar3d.get("stop_freq_mhz", live.gpr_stop_freq_mhz))
|
||||
live.gpr_speed_m_s = float(sar3d.get("speed_m_s", live.gpr_speed_m_s))
|
||||
live.gpr_look_angle_deg = float(sar3d.get("look_angle_deg", live.gpr_look_angle_deg))
|
||||
live.gpr_direction_sign = float(sar3d.get("direction_sign", live.gpr_direction_sign))
|
||||
live.gpr_apply_freq_phase_correction = bool(
|
||||
sar3d.get("apply_freq_phase_correction", live.gpr_apply_freq_phase_correction)
|
||||
)
|
||||
live.sar3d_frame_radius = int(sar3d.get("frame_radius", live.sar3d_frame_radius))
|
||||
live.sar3d_edge_frame_weight = float(
|
||||
sar3d.get("edge_frame_weight", live.sar3d_edge_frame_weight)
|
||||
)
|
||||
live.sar3d_pitch_override_enabled = bool(
|
||||
sar3d.get("pitch_override_enabled", live.sar3d_pitch_override_enabled)
|
||||
)
|
||||
live.sar3d_pitch_deg = float(sar3d.get("pitch_deg", live.sar3d_pitch_deg))
|
||||
live.sar3d_ground_depth_m = float(sar3d.get("ground_depth_m", live.sar3d_ground_depth_m))
|
||||
live.sar3d_x_min_m = float(sar3d.get("x_min_m", live.sar3d_x_min_m))
|
||||
live.sar3d_x_max_m = float(sar3d.get("x_max_m", live.sar3d_x_max_m))
|
||||
live.sar3d_y_min_m = float(sar3d.get("y_min_m", live.sar3d_y_min_m))
|
||||
live.sar3d_y_max_m = float(sar3d.get("y_max_m", live.sar3d_y_max_m))
|
||||
live.sar3d_z_min_m = float(sar3d.get("z_min_m", live.sar3d_z_min_m))
|
||||
live.sar3d_z_max_m = float(sar3d.get("z_max_m", live.sar3d_z_max_m))
|
||||
live.sar3d_voxel_x_m = float(sar3d.get("voxel_x_m", live.sar3d_voxel_x_m))
|
||||
live.sar3d_voxel_y_m = float(sar3d.get("voxel_y_m", live.sar3d_voxel_y_m))
|
||||
live.sar3d_voxel_z_m = float(sar3d.get("voxel_z_m", live.sar3d_voxel_z_m))
|
||||
live.sar3d_norm_edge_margin_m = float(
|
||||
sar3d.get("norm_edge_margin_m", live.sar3d_norm_edge_margin_m)
|
||||
)
|
||||
live.sar3d_smooth_sigma = float(sar3d.get("smooth_sigma", live.sar3d_smooth_sigma))
|
||||
live.sar3d_comp_range_power = float(
|
||||
sar3d.get("comp_range_power", live.sar3d_comp_range_power)
|
||||
)
|
||||
live.sar3d_tx_per_segment = int(sar3d.get("tx_per_segment", live.sar3d_tx_per_segment))
|
||||
live.sar3d_use_compensation = bool(sar3d.get("use_compensation", live.sar3d_use_compensation))
|
||||
live.sar3d_normalize_pairs = bool(sar3d.get("normalize_pairs", live.sar3d_normalize_pairs))
|
||||
live.sar3d_bottom_view_deg = float(sar3d.get("bottom_view_deg", live.sar3d_bottom_view_deg))
|
||||
return live
|
||||
|
||||
|
||||
def _check_preprocessor_transparency(
|
||||
tap_reader: ShmRingReader, dataset_dir: Path
|
||||
) -> bool:
|
||||
"""Compare one preprocessed trace against the recorded snapshot's s21."""
|
||||
payload = tap_reader.peek_latest_payload()
|
||||
if payload is None:
|
||||
logger.warning("No preprocessed_tap payload available for transparency check")
|
||||
return False
|
||||
preprocessed = decode_trace_collection(payload, PREPROC_MAGIC)
|
||||
|
||||
# Any snapshot works: neutral preprocessing is time-invariant, so match the
|
||||
# trace against every recorded snapshot and accept the best one.
|
||||
trace = preprocessed.traces[0]
|
||||
combo_file = f"i{trace.combo.input}_o{trace.combo.output}_s21.npy"
|
||||
best_delta = np.inf
|
||||
for folder in sorted(p for p in dataset_dir.iterdir() if p.name[:1].isdigit()):
|
||||
recorded = np.load(folder / combo_file).astype(np.complex64)
|
||||
if recorded.size != np.asarray(trace.s21).size:
|
||||
continue
|
||||
delta = float(np.max(np.abs(np.asarray(trace.s21) - recorded)))
|
||||
best_delta = min(best_delta, delta)
|
||||
if best_delta == 0.0:
|
||||
break
|
||||
logger.info("Preprocessor transparency: max|delta| vs best snapshot = %.3e", best_delta)
|
||||
return best_delta < 1e-6
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""Run the replay pipeline smoke and report pass/fail."""
|
||||
parser = argparse.ArgumentParser(description="Headless replay pipeline smoke")
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
type=Path,
|
||||
default=PROJECT_ROOT / "run_config_examples/run_config_replay_vna.example.json",
|
||||
)
|
||||
parser.add_argument("--duration", type=float, default=20.0)
|
||||
args = parser.parse_args()
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="%(levelname)s %(name)s: %(message)s")
|
||||
|
||||
config = RunConfigModel.load_from_path(args.config)
|
||||
config.ensure_combos()
|
||||
# expanduser: "~/..." dataset paths from machine-portable profiles.
|
||||
dataset_dir = Path(config.radar.replay.dataset_dir).expanduser()
|
||||
if not dataset_dir.is_dir():
|
||||
raise RuntimeError(f"Replay dataset not found: {dataset_dir}")
|
||||
|
||||
config.rings.raw.name = _make_unique_ring_name("radar_raw_replay_smoke")
|
||||
config.rings.raw_tap.name = _make_unique_ring_name("radar_raw_tap_replay_smoke")
|
||||
config.rings.preprocessed.name = _make_unique_ring_name("radar_preprocessed_replay_smoke")
|
||||
config.rings.preprocessed_tap.name = _make_unique_ring_name("radar_preprocessed_tap_replay_smoke")
|
||||
config.rings.results.name = _make_unique_ring_name("radar_results_replay_smoke")
|
||||
# Private live-config path so the smoke never clobbers the GUI's file.
|
||||
live_path = PROJECT_ROOT / "python_app/runtime/processing_live_replay_smoke.json"
|
||||
config.runtime.processing_live_config_path = str(
|
||||
live_path.relative_to(PROJECT_ROOT)
|
||||
)
|
||||
|
||||
radar_key = radar_key_from_config(
|
||||
model_name=config.radar.model,
|
||||
serial=config.radar.serial,
|
||||
sweep_start_hz=config.radar.sweep.start_hz,
|
||||
sweep_stop_hz=config.radar.sweep.stop_hz,
|
||||
sweep_points=config.radar.sweep.points,
|
||||
ifbw_hz=config.radar.sweep.if_bandwidth_hz,
|
||||
power_dbm=config.radar.sweep.power_dbm,
|
||||
extra_serials=config.radar_key_extra_parts() or None,
|
||||
)
|
||||
store = NpzStore(PROJECT_ROOT / "python_app/data")
|
||||
set_name = config.preprocess.s21.calibration.set_name or "neutral_replay"
|
||||
if set_name not in store.list_sets("s21_calibration", radar_key):
|
||||
calibration, reference = build_neutral_s21_sets(config)
|
||||
store.save_set("s21_calibration", radar_key, set_name, calibration)
|
||||
store.save_set("s21_reference", radar_key, set_name, reference)
|
||||
logger.info("Created neutral sets '%s' (radar_key=%s)", set_name, radar_key)
|
||||
config.preprocess.s21.calibration.set_name = set_name
|
||||
config.preprocess.s21.reference.set_name = set_name
|
||||
|
||||
ProcessingLiveConfigWriter(live_path).write(_sar3d_live_config(args.config))
|
||||
|
||||
config_writer = ConfigWriter(PROJECT_ROOT / "python_app/runtime")
|
||||
config_writer.prepare_preprocess_bundles(store, radar_key, config)
|
||||
config_path = config_writer.write(
|
||||
config, PROJECT_ROOT / "python_app/runtime/run_config_replay_smoke.json"
|
||||
)
|
||||
|
||||
supervisor = ProcessSupervisor(PROJECT_ROOT)
|
||||
result_reader: ShmRingReader | None = None
|
||||
tap_reader: ShmRingReader | None = None
|
||||
failures: list[str] = []
|
||||
try:
|
||||
supervisor.start(config_path)
|
||||
result_reader = ShmRingReader(config.rings.results.name, open_timeout_s=15.0)
|
||||
tap_reader = ShmRingReader(config.rings.preprocessed_tap.name, open_timeout_s=15.0)
|
||||
|
||||
deadline = time.monotonic() + args.duration
|
||||
received = 0
|
||||
sar3d_results = 0
|
||||
last_peak = 0.0
|
||||
last_id = 0
|
||||
ids_monotonic = True
|
||||
while time.monotonic() < deadline:
|
||||
result = result_reader.pop_result_collection()
|
||||
if result is None:
|
||||
time.sleep(0.02)
|
||||
continue
|
||||
received += 1
|
||||
if last_id and result.collection_id <= last_id:
|
||||
ids_monotonic = False
|
||||
last_id = result.collection_id
|
||||
names = {p.processing_name: p for p in result.collection_payloads}
|
||||
if "sar3d_proj_xz" in names and "sar3d_proj_bottom" in names:
|
||||
sar3d_results += 1
|
||||
peak_payload = names.get("sar3d_peak")
|
||||
if peak_payload is not None:
|
||||
last_peak = float(peak_payload.scalar_value)
|
||||
|
||||
logger.info(
|
||||
"Results: total=%d, with sar3d projections=%d, last collection_id=%d, last peak=%.4e",
|
||||
received, sar3d_results, last_id, last_peak,
|
||||
)
|
||||
if received == 0:
|
||||
failures.append("no result collections received")
|
||||
if sar3d_results == 0:
|
||||
failures.append("no sar3d projection payloads received")
|
||||
if not (last_peak > 0.0):
|
||||
failures.append(f"sar3d peak is not positive: {last_peak}")
|
||||
if not ids_monotonic:
|
||||
failures.append("collection ids were not monotonically increasing")
|
||||
if not _check_preprocessor_transparency(tap_reader, dataset_dir):
|
||||
failures.append("preprocessor is not transparent vs recorded snapshots")
|
||||
finally:
|
||||
supervisor.stop_all()
|
||||
if result_reader is not None:
|
||||
result_reader.close()
|
||||
if tap_reader is not None:
|
||||
tap_reader.close()
|
||||
|
||||
if failures:
|
||||
for failure in failures:
|
||||
logger.error("FAIL: %s", failure)
|
||||
return 1
|
||||
logger.info("REPLAY SMOKE OK")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
@@ -1,389 +0,0 @@
|
||||
"""Reference implementation of the sar3d volume from Multi_antenna_3D_clean_v1.ipynb.
|
||||
|
||||
Executable specification for the C++ port: recomputes a single-frame
|
||||
(aperture radius 0) 3D SAR volume from a preprocessed snapshot exactly the
|
||||
way the notebook does, then compares it against a reference *_volume.npz
|
||||
exported by the notebook.
|
||||
|
||||
Usage:
|
||||
python sar3d_reference_check.py <dataset_root> <reference_volume.npz>
|
||||
|
||||
<dataset_root> is an extracted replay dataset (contains config_profile.json
|
||||
and preprocessed/<snapshot>/i*_o*_{s21,freq}.npy + meta.json). The snapshot
|
||||
name and all physics parameters are taken from the npz meta.
|
||||
|
||||
Exits non-zero when the recomputed volume differs from the reference by more
|
||||
than the tolerance. The only expected difference is the Gaussian smoothing
|
||||
(manual separable filter vs scipy) at the 1e-6 level.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
TOLERANCE = 2e-6
|
||||
|
||||
C_LIGHT = 3e8
|
||||
|
||||
# Notebook constants not recorded in the npz meta (cell 0 / cell 4).
|
||||
BP_OVERSAMPLE = 8
|
||||
BP_WINDOW = True
|
||||
PAIR_NORM_PERCENTILE = 50.0
|
||||
PAIR_NORM_EPS = 1e-15
|
||||
COMP_RANGE_POWER = 0.3
|
||||
COMP_RANGE_WEIGHT_MAX = 5.0
|
||||
COMP_REF_DEPTH = 5.0
|
||||
BP_SMOOTH_SIGMA = 1.5
|
||||
SAR_Y_RANGE_M = (-0.5, 2.0)
|
||||
SAR_NORM_EDGE_MARGIN_M = 0.3
|
||||
X_MARGIN_M = 2.0
|
||||
MOTION_PHASE_SIGN = -1.0
|
||||
DIRECTION_SIGN = +1.0
|
||||
|
||||
|
||||
def gaussian_kernel1d(sigma: float, radius: int) -> np.ndarray:
|
||||
x = np.arange(-radius, radius + 1, dtype=float)
|
||||
phi = np.exp(-0.5 / (sigma * sigma) * x * x)
|
||||
return phi / phi.sum()
|
||||
|
||||
|
||||
def correlate1d_reflect(arr: np.ndarray, weights: np.ndarray, axis: int) -> np.ndarray:
|
||||
r = (len(weights) - 1) // 2
|
||||
a = np.moveaxis(arr, axis, -1)
|
||||
pad = np.concatenate([a[..., r - 1::-1], a, a[..., :-r - 1:-1]], axis=-1)
|
||||
out = np.zeros_like(a)
|
||||
for k, w in enumerate(weights):
|
||||
out += w * pad[..., k:k + a.shape[-1]]
|
||||
return np.moveaxis(out, -1, axis)
|
||||
|
||||
|
||||
def gaussian_filter(arr: np.ndarray, sigma: tuple[float, ...], truncate: float = 4.0) -> np.ndarray:
|
||||
"""scipy.ndimage.gaussian_filter equivalent (mode='reflect')."""
|
||||
out = np.asarray(arr, dtype=float).copy()
|
||||
for axis, s in enumerate(sigma):
|
||||
if s <= 0:
|
||||
continue
|
||||
radius = int(truncate * float(s) + 0.5)
|
||||
out = correlate1d_reflect(out, gaussian_kernel1d(float(s), radius), axis)
|
||||
return out
|
||||
|
||||
|
||||
def load_geometry(profile_path: Path) -> dict:
|
||||
profile = json.loads(profile_path.read_text())
|
||||
gpr = profile["gpr"]
|
||||
tx_geom = {int(e["output_pos"]): (e["x_m"], e.get("y_m", 0.0), e.get("z_m", 0.0))
|
||||
for e in gpr["tx_geometry"]}
|
||||
rx_geom = {int(e["input_pos"]): (e["x_m"], e.get("y_m", 0.0), e.get("z_m", 0.0))
|
||||
for e in gpr["rx_geometry"]}
|
||||
combos = profile["run"]["combos"]
|
||||
pair_order = [(int(c["output"]), int(c["input"])) for c in combos]
|
||||
tx_order_full: list[int] = []
|
||||
for tx, _ in pair_order:
|
||||
if tx not in tx_order_full:
|
||||
tx_order_full.append(tx)
|
||||
output_idx = sorted(tx_geom)
|
||||
input_idx = sorted(rx_geom)
|
||||
tx_xyz = np.array([tx_geom[i] for i in output_idx], dtype=float)
|
||||
rx_xyz = np.array([rx_geom[i] for i in input_idx], dtype=float)
|
||||
return {
|
||||
"output_idx": output_idx, "input_idx": input_idx,
|
||||
"tx_xyz": tx_xyz, "rx_xyz": rx_xyz,
|
||||
"pair_order": pair_order, "tx_order_full": tx_order_full,
|
||||
}
|
||||
|
||||
|
||||
def snapshot_timing(snapshot_dir: Path) -> dict | None:
|
||||
"""Per-Tx capture windows from the snapshot's meta.json trace labels."""
|
||||
try:
|
||||
meta = json.loads((snapshot_dir / "meta.json").read_text())
|
||||
except OSError:
|
||||
return None
|
||||
traces = [t for t in meta.get("traces", [])
|
||||
if "capture_start_ns" in t and "capture_end_ns" in t and "output" in t]
|
||||
if not traces:
|
||||
return None
|
||||
first = min(int(t["capture_start_ns"]) for t in traces)
|
||||
last = max(int(t["capture_end_ns"]) for t in traces)
|
||||
by_tx: dict[int, tuple[int, int]] = {}
|
||||
for t in traces:
|
||||
by_tx.setdefault(int(t["output"]), (int(t["capture_start_ns"]), int(t["capture_end_ns"])))
|
||||
return {
|
||||
"acq_s": (last - first) * 1e-9,
|
||||
"center_abs_s": 0.5 * (first + last) * 1e-9,
|
||||
"tx_window_s": {tx: ((a - first) * 1e-9, (b - first) * 1e-9) for tx, (a, b) in by_tx.items()},
|
||||
}
|
||||
|
||||
|
||||
def pair_timestamps(geometry: dict, timing: dict, speed_m_s: float, look_angle_deg: float,
|
||||
wave_speed: float) -> dict:
|
||||
"""Segment/slot assignment and coarse pair dtau (notebook compute_pair_timestamps_for_snapshot)."""
|
||||
windows = timing["tx_window_s"]
|
||||
hw_order = [tx for tx in geometry["tx_order_full"] if tx in windows]
|
||||
hw_order += [tx for tx in sorted(windows) if tx not in hw_order]
|
||||
groups: dict[tuple[float, float], list[int]] = {}
|
||||
for tx in hw_order:
|
||||
groups.setdefault(windows[tx], []).append(tx)
|
||||
seg_of = {}
|
||||
for seg_idx, win in enumerate(sorted(groups)):
|
||||
for slot, tx in enumerate(groups[win]):
|
||||
seg_of[tx] = (seg_idx, slot, len(groups[win]))
|
||||
cos_theta = np.cos(np.radians(look_angle_deg))
|
||||
t_ref = 0.5 * timing["acq_s"]
|
||||
tx_map = {p: k for k, p in enumerate(geometry["output_idx"])}
|
||||
rx_map = {p: k for k, p in enumerate(geometry["input_idx"])}
|
||||
ts = {}
|
||||
for tx_phys, rx_phys in geometry["pair_order"]:
|
||||
_, slot, n_slots = seg_of[tx_phys]
|
||||
t0, t1 = windows[tx_phys]
|
||||
t_center = 0.5 * (t0 + t1)
|
||||
dz_motion = DIRECTION_SIGN * speed_m_s * (t_center - t_ref) * cos_theta
|
||||
ts[(tx_map[tx_phys], rx_map[rx_phys])] = {
|
||||
"slot": slot, "n_slots": n_slots,
|
||||
"segment_start_s": t0, "segment_time_s": t1 - t0,
|
||||
"t_center_s": t_center,
|
||||
"dtau_motion_s": 2.0 * dz_motion / wave_speed,
|
||||
}
|
||||
return ts
|
||||
|
||||
|
||||
def timing_abs_center(snapshot_dir: Path) -> float:
|
||||
timing = snapshot_timing(snapshot_dir)
|
||||
if timing is None:
|
||||
raise RuntimeError(f"meta.json trace labels required in {snapshot_dir}")
|
||||
return timing["center_abs_s"]
|
||||
|
||||
|
||||
def load_mimo(snapshot_dir: Path, geometry: dict) -> tuple[dict, dict]:
|
||||
s21_data, freq_data = {}, {}
|
||||
for f in snapshot_dir.glob("i*_o*_s21.npy"):
|
||||
parts = f.stem.split("_")
|
||||
rx_phys = int(parts[0][1:])
|
||||
tx_phys = int(parts[1][1:])
|
||||
if tx_phys not in geometry["output_idx"] or rx_phys not in geometry["input_idx"]:
|
||||
continue
|
||||
key = (geometry["output_idx"].index(tx_phys), geometry["input_idx"].index(rx_phys))
|
||||
s21_data[key] = np.load(f)
|
||||
freq_data[key] = np.asarray(np.load(f.parent / f"i{rx_phys}_o{tx_phys}_freq.npy"), dtype=float)
|
||||
return s21_data, freq_data
|
||||
|
||||
|
||||
def apply_phase_correction(s21: np.ndarray, freq_full: np.ndarray, info: dict,
|
||||
f_start: float, f_stop: float, speed_m_s: float,
|
||||
look_angle_deg: float, wave_speed: float) -> np.ndarray:
|
||||
"""Coarse pair + intra-sweep motion correction as one phase ramp before the IFFT."""
|
||||
idx = np.flatnonzero((freq_full >= f_start) & (freq_full <= f_stop))
|
||||
n_full = len(freq_full)
|
||||
dt_event = info["segment_time_s"] / (info["n_slots"] * n_full)
|
||||
t_abs = info["segment_start_s"] + (info["n_slots"] * idx + info["slot"]) * dt_event
|
||||
dt_intra = t_abs - info["t_center_s"]
|
||||
dtau_intra = 2.0 * DIRECTION_SIGN * speed_m_s * np.cos(np.radians(look_angle_deg)) * dt_intra / wave_speed
|
||||
total_dtau = dtau_intra + info["dtau_motion_s"]
|
||||
phi = 2.0 * np.pi * freq_full[idx] * total_dtau
|
||||
out = np.array(s21, dtype=np.complex128, copy=True)
|
||||
out[idx] *= np.exp(1j * MOTION_PHASE_SIGN * phi)
|
||||
return out
|
||||
|
||||
|
||||
def compute_ascan(s21: np.ndarray, freq: np.ndarray, f_start: float, f_stop: float):
|
||||
"""Oversampled complex A-scan with the notebook's frequency-shifted IFFT."""
|
||||
mask = (freq >= f_start) & (freq <= f_stop)
|
||||
freq_cut = freq[mask]
|
||||
s21_cut = s21[mask]
|
||||
df = float(np.median(np.diff(freq_cut)))
|
||||
n = len(freq_cut)
|
||||
k0 = int(round(freq_cut[0] / df))
|
||||
n_fft = (1 << int(np.ceil(np.log2(2 * (k0 + n - 1))))) * BP_OVERSAMPLE
|
||||
dt = 1.0 / (n_fft * df)
|
||||
s = s21_cut * np.hanning(n) if BP_WINDOW else s21_cut.copy()
|
||||
spectrum = np.zeros(n_fft, dtype=np.complex128)
|
||||
spectrum[k0:k0 + n] = s
|
||||
return np.arange(n_fft, dtype=float) * dt, np.fft.ifft(spectrum)
|
||||
|
||||
|
||||
def interp_complex(tau: np.ndarray, t_axis: np.ndarray, h_axis: np.ndarray) -> np.ndarray:
|
||||
n = t_axis.size
|
||||
dt = (float(t_axis[-1]) - float(t_axis[0])) / (n - 1)
|
||||
pos = (tau - float(t_axis[0])) / dt
|
||||
inside = (pos >= 0.0) & (pos <= n - 1)
|
||||
k = np.clip(np.floor(pos), 0, n - 2).astype(np.intp)
|
||||
frac = pos - k
|
||||
out = h_axis[k] + frac * (h_axis[k + 1] - h_axis[k])
|
||||
return np.where(inside, out, 0.0 + 0.0j)
|
||||
|
||||
|
||||
def axis_linspace(lo: float, hi: float, step: float) -> np.ndarray:
|
||||
return np.linspace(lo, hi, max(int(round((hi - lo) / step)) + 1, 2))
|
||||
|
||||
|
||||
def compute_volume(dataset_root: Path, meta: dict) -> dict:
|
||||
"""Single-frame volume via the notebook's ANIMATION path.
|
||||
|
||||
The reference npz files were exported from animation frames: the base grid
|
||||
is shifted by the radar displacement between the frame and the scene-origin
|
||||
snapshot (meta reference_snapshot), antennas get the same offset, and the
|
||||
depth window follows the radar (depth_shift). Physically it all cancels for
|
||||
an aperture of radius 0, but replicating the exact float arithmetic is what
|
||||
makes the comparison bit-tight at the depth-mask knife edge.
|
||||
"""
|
||||
geometry = load_geometry(dataset_root / "config_profile.json")
|
||||
snapshot_dir = dataset_root / "preprocessed" / meta["snapshot"]
|
||||
|
||||
eps_r = 1.0
|
||||
wave_speed = C_LIGHT / np.sqrt(eps_r)
|
||||
f_start = float(meta["f_start_hz"])
|
||||
f_stop = float(meta["f_stop_hz"])
|
||||
min_depth = float(meta["min_depth_m"])
|
||||
max_depth = float(meta["max_depth_m"])
|
||||
speed = float(meta["speed_m_s"])
|
||||
look_angle = float(meta["look_angle_deg"])
|
||||
ground_depth = float(meta["ground_depth_m"])
|
||||
voxel = [float(a) for a in meta["voxel_m"]]
|
||||
|
||||
x_tx, y_tx, z_tx = geometry["tx_xyz"].T
|
||||
x_rx, y_rx, z_rx = geometry["rx_xyz"].T
|
||||
n_tx, n_rx = len(x_tx), len(x_rx)
|
||||
|
||||
timing = snapshot_timing(snapshot_dir)
|
||||
if timing is None:
|
||||
raise RuntimeError(f"meta.json trace labels required in {snapshot_dir}")
|
||||
ts = pair_timestamps(geometry, timing, speed, look_angle, wave_speed)
|
||||
|
||||
s21_data, freq_data = load_mimo(snapshot_dir, geometry)
|
||||
ascan_h, ascan_t = {}, {}
|
||||
for key, s21 in s21_data.items():
|
||||
corrected = apply_phase_correction(
|
||||
s21, freq_data[key], ts[key], f_start, f_stop, speed, look_angle, wave_speed)
|
||||
t_axis, h = compute_ascan(corrected, freq_data[key], f_start, f_stop)
|
||||
z_axis = t_axis * wave_speed / 2
|
||||
m = (z_axis >= min_depth) & (z_axis <= max_depth)
|
||||
scale = float(np.percentile(np.abs(h)[m], PAIR_NORM_PERCENTILE))
|
||||
if not np.isfinite(scale) or scale <= PAIR_NORM_EPS:
|
||||
scale = 1.0
|
||||
ascan_h[key] = h / (scale + PAIR_NORM_EPS)
|
||||
ascan_t[key] = t_axis
|
||||
|
||||
pitch = np.radians(look_angle)
|
||||
cos_p, sin_p = np.cos(pitch), np.sin(pitch)
|
||||
|
||||
def scene_to_radar_yz(y_scene, z_scene):
|
||||
y0 = y_scene - ground_depth
|
||||
return y0 * cos_p + z_scene * sin_p, -y0 * sin_p + z_scene * cos_p
|
||||
|
||||
x_ant = np.concatenate([x_tx, x_rx])
|
||||
y_lo, y_hi = SAR_Y_RANGE_M
|
||||
z_span = [(d - float(scene_to_radar_yz(y, 0.0)[1])) / cos_p
|
||||
for y in (y_lo, y_hi) for d in (min_depth, max_depth)]
|
||||
gx = axis_linspace(float(x_ant.min() - X_MARGIN_M), float(x_ant.max() + X_MARGIN_M), voxel[0])
|
||||
gy = axis_linspace(y_lo, y_hi, voxel[1])
|
||||
gz = axis_linspace(min(z_span), max(z_span), voxel[2])
|
||||
|
||||
# Displacement of this frame relative to the scene-origin snapshot
|
||||
# (notebook sar_frame_offsets + anim_frame_displacement).
|
||||
off_dy = off_dz = 0.0
|
||||
disp_y = disp_z = 0.0
|
||||
reference_name = meta.get("reference_snapshot", meta["snapshot"])
|
||||
if reference_name != meta["snapshot"]:
|
||||
ref_timing = snapshot_timing(dataset_root / "preprocessed" / reference_name)
|
||||
if ref_timing is None:
|
||||
raise RuntimeError(f"meta.json trace labels required in {reference_name}")
|
||||
dt = timing_abs_center(snapshot_dir) - ref_timing["center_abs_s"]
|
||||
horizontal = DIRECTION_SIGN * speed * dt
|
||||
off_dy = float(horizontal * np.sin(pitch))
|
||||
off_dz = float(horizontal * np.cos(pitch))
|
||||
# Scene displacement = difference of two transformed points; the ground
|
||||
# lift cancels, leaving essentially (0, ~0, horizontal).
|
||||
disp_y = (off_dy * cos_p - off_dz * sin_p + ground_depth) - ground_depth
|
||||
disp_z = off_dy * sin_p + off_dz * cos_p
|
||||
gy_s = gy + disp_y
|
||||
gz_s = gz + disp_z
|
||||
depth_shift = off_dz
|
||||
grid_xx, grid_zz = np.meshgrid(gx, gz_s)
|
||||
|
||||
ground_plane_y = (-ground_depth + COMP_REF_DEPTH * sin_p) / cos_p
|
||||
|
||||
def pair_geo_ref(i, j):
|
||||
xc = (x_tx[i] + x_rx[j]) / 2.0
|
||||
r_tx = np.sqrt((xc - x_tx[i]) ** 2 + (ground_plane_y - y_tx[i]) ** 2 + (COMP_REF_DEPTH - z_tx[i]) ** 2)
|
||||
r_rx = np.sqrt((xc - x_rx[j]) ** 2 + (ground_plane_y - y_rx[j]) ** 2 + (COMP_REF_DEPTH - z_rx[j]) ** 2)
|
||||
return 1.0 / (r_tx * r_rx + 1e-12) + 1e-30
|
||||
|
||||
geo_ref = {(i, j): pair_geo_ref(i, j) for i in range(n_tx) for j in range(n_rx)}
|
||||
dx2_tx = [(grid_xx - x_tx[i]) ** 2 for i in range(n_tx)]
|
||||
dx2_rx = [(grid_xx - x_rx[j]) ** 2 for j in range(n_rx)]
|
||||
|
||||
acc_vol = np.zeros((gy.size, gz.size, gx.size), dtype=np.complex128)
|
||||
cnt_vol = np.zeros(acc_vol.shape, dtype=float)
|
||||
for iy, y_plane in enumerate(gy_s):
|
||||
y_rad, z_rad = scene_to_radar_yz(y_plane, grid_zz)
|
||||
depth_ok = (z_rad - depth_shift >= min_depth) & (z_rad - depth_shift <= max_depth)
|
||||
r_tx_all = [np.sqrt(dx2_tx[i] + (y_rad - (y_tx[i] + off_dy)) ** 2 + (z_rad - (z_tx[i] + off_dz)) ** 2)
|
||||
for i in range(n_tx)]
|
||||
r_rx_all = [np.sqrt(dx2_rx[j] + (y_rad - (y_rx[j] + off_dy)) ** 2 + (z_rad - (z_rx[j] + off_dz)) ** 2)
|
||||
for j in range(n_rx)]
|
||||
acc = np.zeros_like(grid_xx, dtype=np.complex128)
|
||||
cnt = np.zeros_like(grid_xx, dtype=float)
|
||||
for i in range(n_tx):
|
||||
for j in range(n_rx):
|
||||
key = (i, j)
|
||||
if key not in ascan_h:
|
||||
continue
|
||||
r_tx, r_rx = r_tx_all[i], r_rx_all[j]
|
||||
tau = (r_tx + r_rx) / wave_speed
|
||||
t_axis = ascan_t[key]
|
||||
valid = depth_ok & (tau >= t_axis[0]) & (tau <= t_axis[-1])
|
||||
h = interp_complex(tau, t_axis, ascan_h[key])
|
||||
ratio = (1.0 / (r_tx * r_rx + 1e-12) + 1e-30) / geo_ref[key]
|
||||
weight = np.clip(1.0 / (ratio ** COMP_RANGE_POWER + 1e-12), 0.0, COMP_RANGE_WEIGHT_MAX)
|
||||
acc += np.where(valid, h * weight, 0.0 + 0.0j)
|
||||
cnt += valid
|
||||
acc_vol[iy] = acc
|
||||
cnt_vol[iy] = cnt
|
||||
|
||||
volume = np.abs(acc_vol / (cnt_vol + 1e-12))
|
||||
z_rad_planes = np.asarray([scene_to_radar_yz(yp, grid_zz)[1] - depth_shift for yp in gy_s])
|
||||
volume = np.where((z_rad_planes >= min_depth) & (z_rad_planes <= max_depth), volume, 0.0)
|
||||
ref_planes = (gy_s >= gy_s[0] + SAR_NORM_EDGE_MARGIN_M) & (gy_s <= gy_s[-1] - SAR_NORM_EDGE_MARGIN_M)
|
||||
level_raw = volume[ref_planes].max() + 1e-12
|
||||
volume = gaussian_filter(volume / level_raw, sigma=(0.0, BP_SMOOTH_SIGMA, BP_SMOOTH_SIGMA))
|
||||
level_smooth = volume[ref_planes].max() + 1e-12
|
||||
volume = np.clip(volume / level_smooth, 0.0, None).astype(np.float32)
|
||||
return {"volume": volume, "level": float(level_raw * level_smooth), "x": gx, "y": gy, "z": gz}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("dataset_root", type=Path,
|
||||
help="extracted dataset dir (config_profile.json + preprocessed/)")
|
||||
parser.add_argument("reference_npz", type=Path, help="reference *_volume.npz from the notebook")
|
||||
args = parser.parse_args()
|
||||
|
||||
ref = np.load(args.reference_npz)
|
||||
meta = json.loads(str(ref["meta"]))
|
||||
print(f"snapshot: {meta['snapshot']}")
|
||||
result = compute_volume(args.dataset_root, meta)
|
||||
|
||||
volume, ref_volume = result["volume"], ref["volume"]
|
||||
axes_ok = all(np.allclose(result[k], ref[f"{k}_m"]) for k in ("x", "y", "z"))
|
||||
level_rel = abs(result["level"] - meta["level"]) / abs(meta["level"])
|
||||
print(f"axes match: {axes_ok}; level rel diff: {level_rel:.3e} "
|
||||
f"(mine {result['level']:.9f}, ref {meta['level']:.9f})")
|
||||
if volume.shape != ref_volume.shape:
|
||||
print(f"FAIL: shape mismatch {volume.shape} vs {ref_volume.shape}")
|
||||
return 1
|
||||
diff = np.abs(volume.astype(np.float64) - ref_volume.astype(np.float64))
|
||||
argmax = np.unravel_index(int(np.argmax(volume)), volume.shape)
|
||||
ref_argmax = np.unravel_index(int(np.argmax(ref_volume)), ref_volume.shape)
|
||||
print(f"max |diff| = {diff.max():.3e}, mean = {diff.mean():.3e}")
|
||||
print(f"argmax: mine {argmax}, ref {ref_argmax}")
|
||||
ok = axes_ok and diff.max() <= TOLERANCE and argmax == ref_argmax and level_rel <= TOLERANCE
|
||||
print("OK" if ok else "FAIL")
|
||||
return 0 if ok else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1,89 +0,0 @@
|
||||
"""Compare a sar3d volume dumped by the C++ processor with a notebook npz export.
|
||||
|
||||
Usage:
|
||||
python sar3d_volume_compare.py <dump_base> <reference_volume.npz>
|
||||
|
||||
<dump_base> is the path prefix written by `sar3d_parity --dump-dir` (or by the
|
||||
processor with `sar3d_volume_dump_dir` set): <dump_base>.f32 holds the raw
|
||||
float32 volume [iy][iz][ix], <dump_base>.json its axes and level.
|
||||
|
||||
The C++ path accumulates the backprojection in float32 (CUDA kernel), so the
|
||||
comparison is tolerance-based rather than bitwise; geometry is computed in
|
||||
double, keeping the expected difference at the 1e-5 level. Voxels within the
|
||||
smoothing radius of the depth-mask boundary are reported separately: there the
|
||||
float32 knife-edge can flip whole boundary voxels (the same effect exists
|
||||
between two float64 runs with shifted grids).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
|
||||
MAX_DIFF_TOLERANCE = 1e-4
|
||||
LEVEL_REL_TOLERANCE = 1e-4
|
||||
# Gaussian smoothing radius (sigma 1.5 -> radius 6) around the depth-mask edge.
|
||||
EDGE_EXCLUSION_VOXELS = 7
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("dump_base", type=Path, help="path prefix of the .f32/.json dump")
|
||||
parser.add_argument("reference_npz", type=Path, help="reference *_volume.npz from the notebook")
|
||||
args = parser.parse_args()
|
||||
|
||||
header = json.loads(Path(str(args.dump_base) + ".json").read_text())
|
||||
shape = (header["ny"], header["nz"], header["nx"])
|
||||
volume = np.fromfile(str(args.dump_base) + ".f32", dtype=np.float32).reshape(shape)
|
||||
|
||||
ref = np.load(args.reference_npz)
|
||||
ref_volume = ref["volume"]
|
||||
meta = json.loads(str(ref["meta"]))
|
||||
print(f"snapshot: {meta['snapshot']}")
|
||||
if volume.shape != ref_volume.shape:
|
||||
print(f"FAIL: shape mismatch {volume.shape} vs {ref_volume.shape}")
|
||||
return 1
|
||||
|
||||
axes_ok = all(
|
||||
np.allclose(np.asarray(header[key]), ref[key])
|
||||
for key in ("x_m", "y_m", "z_m")
|
||||
)
|
||||
level_rel = abs(header["level"] - meta["level"]) / abs(meta["level"])
|
||||
print(f"axes match: {axes_ok}; level rel diff: {level_rel:.3e} "
|
||||
f"(dump {header['level']:.9f}, ref {meta['level']:.9f})")
|
||||
|
||||
diff = np.abs(volume.astype(np.float64) - ref_volume.astype(np.float64))
|
||||
|
||||
# Depth-mask boundary band: voxels whose (iy, iz) sit within the smoothing
|
||||
# radius of a masked/unmasked transition. Reconstructed from the reference
|
||||
# parameters exactly like the processor computes the mask.
|
||||
pitch = np.radians(float(meta.get("ground_pitch_deg") or meta["look_angle_deg"]))
|
||||
y0 = np.asarray(ref["y_m"]) - float(meta["ground_depth_m"])
|
||||
z_rad = -y0[:, None] * np.sin(pitch) + np.asarray(ref["z_m"])[None, :] * np.cos(pitch)
|
||||
mask = (z_rad >= float(meta["min_depth_m"])) & (z_rad <= float(meta["max_depth_m"]))
|
||||
edge = np.zeros_like(mask)
|
||||
r = EDGE_EXCLUSION_VOXELS
|
||||
for shift in range(-r, r + 1):
|
||||
edge |= np.roll(mask, shift, axis=1) != mask
|
||||
interior = ~edge
|
||||
|
||||
argmax = np.unravel_index(int(np.argmax(volume)), volume.shape)
|
||||
ref_argmax = np.unravel_index(int(np.argmax(ref_volume)), ref_volume.shape)
|
||||
interior_diff = diff[interior[:, :, None] & np.ones(volume.shape, dtype=bool)]
|
||||
print(f"max |diff| (all voxels) = {diff.max():.3e}")
|
||||
print(f"max |diff| (off depth-mask edge) = {interior_diff.max():.3e}, "
|
||||
f"mean = {interior_diff.mean():.3e}")
|
||||
print(f"argmax: dump {argmax}, ref {ref_argmax}")
|
||||
|
||||
ok = (axes_ok and level_rel <= LEVEL_REL_TOLERANCE and argmax == ref_argmax
|
||||
and interior_diff.max() <= MAX_DIFF_TOLERANCE)
|
||||
print("OK" if ok else "FAIL")
|
||||
return 0 if ok else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -8,6 +8,7 @@ from python_app.models.gui_profile_model import (
|
||||
GuiPassThroughStateModel,
|
||||
GuiProcessingStateModel,
|
||||
GuiProfileModel,
|
||||
GuiSar3dStateModel,
|
||||
GuiStateModel,
|
||||
)
|
||||
|
||||
@@ -53,6 +54,31 @@ class GuiProfileCodecTest(unittest.TestCase):
|
||||
twice = GuiProfileModel.from_dict(once).to_dict()
|
||||
self.assertEqual(once["gui"], twice["gui"])
|
||||
|
||||
def test_sar3d_section_round_trips(self) -> None:
|
||||
sar3d = GuiSar3dStateModel(
|
||||
input_positions="0,2",
|
||||
output_positions="1,3",
|
||||
min_depth_m=2.5,
|
||||
max_depth_m=9.0,
|
||||
start_freq_mhz=2000.0,
|
||||
stop_freq_mhz=5500.0,
|
||||
speed_m_s=1.42,
|
||||
ignore_socket_speed_enabled=True,
|
||||
look_angle_deg=6.5,
|
||||
frame_radius=3,
|
||||
voxel_m=0.035,
|
||||
bp_ground_depth_m=1.1,
|
||||
comp_range_power=0.5,
|
||||
use_compensation=False,
|
||||
normalize_each_frame=False,
|
||||
)
|
||||
profile = GuiProfileModel(gui=GuiStateModel(processing=GuiProcessingStateModel(sar3d=sar3d)))
|
||||
|
||||
decoded = GuiProfileModel.from_dict(profile.to_dict())
|
||||
|
||||
assert decoded.gui is not None
|
||||
self.assertEqual(decoded.gui.processing.sar3d, sar3d)
|
||||
|
||||
def test_missing_gui_section_yields_none(self) -> None:
|
||||
self.assertIsNone(GuiProfileModel.from_dict({}).gui)
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
"""Speed authority between a locator socket client and the GUI field.
|
||||
|
||||
The data_processor uses the speed a socket client streams unless the live config
|
||||
sets `ignore_socket_speed`; then `gpr_speed_m_s` from the GUI field applies. Each
|
||||
GPR-like page (gpr, legacy_gpr, sar3d) has its own checkbox and field, and the
|
||||
field is editable only while it is the one in force.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
from PyQt6.QtWidgets import QApplication # noqa: E402
|
||||
|
||||
from python_app.gui.app_window import AppWindow # noqa: E402
|
||||
|
||||
_app: QApplication | None = None
|
||||
_window: AppWindow | None = None
|
||||
|
||||
# mode -> (checkbox, speed field) attributes of its page
|
||||
_PAGES = {
|
||||
"gpr": ("_gpr_ignore_socket_speed_enabled", "_gpr_speed_m_s"),
|
||||
"legacy_gpr": ("_legacy_gpr_ignore_socket_speed_enabled", "_legacy_gpr_speed_m_s"),
|
||||
"sar3d": ("_sar3d_ignore_socket_speed_enabled", "_sar3d_speed_m_s"),
|
||||
}
|
||||
|
||||
|
||||
def setUpModule() -> None:
|
||||
global _app, _window
|
||||
_app = QApplication.instance() or QApplication([])
|
||||
_window = AppWindow(Path("."))
|
||||
|
||||
|
||||
def tearDownModule() -> None:
|
||||
if _window is not None:
|
||||
_window.close()
|
||||
|
||||
|
||||
class SocketSpeedControlsTest(unittest.TestCase):
|
||||
def test_speed_field_is_editable_only_while_the_socket_is_ignored(self) -> None:
|
||||
assert _window is not None
|
||||
for mode, (checkbox_name, speed_name) in _PAGES.items():
|
||||
checkbox, speed = getattr(_window, checkbox_name), getattr(_window, speed_name)
|
||||
for ignore in (True, False):
|
||||
checkbox.setChecked(ignore)
|
||||
self.assertEqual(speed.isEnabled(), ignore, msg=f"{mode}, ignore={ignore}")
|
||||
|
||||
def test_live_config_takes_the_active_page(self) -> None:
|
||||
assert _window is not None
|
||||
for mode, (checkbox_name, speed_name) in _PAGES.items():
|
||||
_window._set_combo_current_text(_window._processing_mode, mode)
|
||||
getattr(_window, checkbox_name).setChecked(True)
|
||||
getattr(_window, speed_name).setValue(1.25)
|
||||
config = _window._live_processing_config()
|
||||
self.assertTrue(config.ignore_socket_speed, msg=mode)
|
||||
self.assertAlmostEqual(config.gpr_speed_m_s, 1.25, msg=mode)
|
||||
getattr(_window, checkbox_name).setChecked(False)
|
||||
self.assertFalse(_window._live_processing_config().ignore_socket_speed, msg=mode)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user