last implement diff

This commit is contained in:
awe
2026-02-27 17:43:32 +03:00
parent 33e1976233
commit c199ab7f28
8 changed files with 265 additions and 34 deletions

View File

@ -112,6 +112,10 @@ def run_matplotlib(args):
state = AppState(norm_type=norm_type)
state.configure_capture_import(fancy=bool(args.fancy), logscale=bool(getattr(args, "logscale", False)))
ring = RingBuffer(max_sweeps)
try:
ring.set_fft_complex_mode(str(getattr(args, "ifft_complex_mode", "arccos")))
except Exception:
pass
# --- Создание фигуры ---
fig, axs = plt.subplots(2, 2, figsize=(12, 8))
@ -181,17 +185,28 @@ def run_matplotlib(args):
ax_cb = fig.add_axes([0.92, 0.45, 0.08, 0.08])
ax_cb_file = fig.add_axes([0.92, 0.36, 0.08, 0.08])
ax_line_mode = fig.add_axes([0.92, 0.10, 0.08, 0.08])
ax_ifft_mode = fig.add_axes([0.92, 0.01, 0.08, 0.08])
ymin_slider = Slider(ax_smin, "Y min", 0, max(1, fft_bins - 1), valinit=0, valstep=1, orientation="vertical")
ymax_slider = Slider(ax_smax, "Y max", 0, max(1, fft_bins - 1), valinit=max(1, fft_bins - 1), valstep=1, orientation="vertical")
contrast_slider = Slider(ax_sctr, "Int max", 0, 100, valinit=100, valstep=1, orientation="vertical")
calib_cb = CheckButtons(ax_cb, ["калибровка"], [False])
calib_file_cb = CheckButtons(ax_cb_file, ["из файла"], [False])
line_mode_rb = RadioButtons(ax_line_mode, ("raw", "processed"), active=0)
ifft_mode_rb = RadioButtons(
ax_ifft_mode,
("arccos", "diff"),
active=(1 if ring.fft_complex_mode == "diff" else 0),
)
try:
ax_line_mode.set_title("Линия", fontsize=8, pad=2)
except Exception:
pass
try:
ax_ifft_mode.set_title("IFFT", fontsize=8, pad=2)
except Exception:
pass
line_mode_state = {"value": "raw"}
ifft_mode_state = {"value": str(ring.fft_complex_mode)}
import os as _os
try:
@ -280,7 +295,7 @@ def run_matplotlib(args):
pass
def _refresh_status_texts():
pipeline_text.set_text(state.format_pipeline_status())
pipeline_text.set_text(f"{state.format_pipeline_status()} | cplx:{ring.fft_complex_mode}")
ref_text.set_text(state.format_reference_status())
try:
fig.canvas.draw_idle()
@ -414,6 +429,18 @@ def run_matplotlib(args):
except Exception:
pass
def _on_ifft_mode_clicked(label):
ifft_mode_state["value"] = str(label)
try:
ring.set_fft_complex_mode(str(label))
except Exception:
pass
_refresh_status_texts()
try:
fig.canvas.draw_idle()
except Exception:
pass
save_bg_btn.on_clicked(_on_save_bg)
bg_cb.on_clicked(_on_bg_clicked)
calib_load_btn2.on_clicked(_on_calib_load_btn)
@ -425,6 +452,7 @@ def run_matplotlib(args):
bg_sample_btn2.on_clicked(_on_bg_sample_btn)
bg_save_btn2.on_clicked(_on_bg_save_btn2)
line_mode_rb.on_clicked(_on_line_mode_clicked)
ifft_mode_rb.on_clicked(_on_ifft_mode_clicked)
ymin_slider.on_changed(_on_ylim_change)
ymax_slider.on_changed(_on_ylim_change)
@ -437,6 +465,7 @@ def run_matplotlib(args):
except Exception:
calib_cb = None
line_mode_state = {"value": "raw"}
ifft_mode_state = {"value": str(getattr(ring, "fft_complex_mode", "arccos"))}
FREQ_MIN = float(FREQ_MIN_GHZ)
FREQ_MAX = float(FREQ_MAX_GHZ)
@ -602,10 +631,10 @@ def run_matplotlib(args):
if changed and state.current_info:
status_text.set_text(format_status(state.current_info))
channel_text.set_text(state.format_channel_label())
pipeline_text.set_text(state.format_pipeline_status())
pipeline_text.set_text(f"{state.format_pipeline_status()} | cplx:{ring.fft_complex_mode}")
ref_text.set_text(state.format_reference_status())
elif changed:
pipeline_text.set_text(state.format_pipeline_status())
pipeline_text.set_text(f"{state.format_pipeline_status()} | cplx:{ring.fft_complex_mode}")
ref_text.set_text(state.format_reference_status())
return (

View File

@ -140,6 +140,10 @@ def run_pyqtgraph(args):
state = AppState(norm_type=norm_type)
state.configure_capture_import(fancy=bool(args.fancy), logscale=bool(getattr(args, "logscale", False)))
ring = RingBuffer(max_sweeps)
try:
ring.set_fft_complex_mode(str(getattr(args, "ifft_complex_mode", "arccos")))
except Exception:
pass
try:
_qt_text_selectable = QtCore.Qt.TextSelectableByMouse
@ -445,6 +449,25 @@ def run_pyqtgraph(args):
def _line_mode() -> str:
return "processed" if line_mode_proc_rb.isChecked() else "raw"
# Переключатель режима реконструкции комплексного спектра перед IFFT
ifft_mode_widget = QtWidgets.QWidget()
ifft_mode_layout = QtWidgets.QHBoxLayout(ifft_mode_widget)
ifft_mode_layout.setContentsMargins(2, 2, 2, 2)
ifft_mode_layout.setSpacing(8)
ifft_mode_layout.addWidget(QtWidgets.QLabel("IFFT mode:"))
ifft_mode_arccos_rb = QtWidgets.QRadioButton("arccos")
ifft_mode_diff_rb = QtWidgets.QRadioButton("diff")
if ring.fft_complex_mode == "diff":
ifft_mode_diff_rb.setChecked(True)
else:
ifft_mode_arccos_rb.setChecked(True)
ifft_mode_layout.addWidget(ifft_mode_arccos_rb)
ifft_mode_layout.addWidget(ifft_mode_diff_rb)
ifft_mode_layout.addStretch(1)
ifft_mode_proxy = QtWidgets.QGraphicsProxyWidget()
ifft_mode_proxy.setWidget(ifft_mode_widget)
win.addItem(ifft_mode_proxy, row=7, col=0, colspan=2)
# Статусная строка
status = pg.LabelItem(justify="left")
win.addItem(status, row=3, col=0, colspan=2)
@ -455,12 +478,32 @@ def run_pyqtgraph(args):
def _refresh_pipeline_label():
txt = state.format_pipeline_status()
txt = f"{txt} | cplx:{ring.fft_complex_mode}"
trace = state.format_stage_trace()
if trace:
txt = f"{txt} | trace: {trace}"
pipeline_status.setText(txt)
ref_status.setText(state.format_reference_status())
def _apply_ifft_complex_mode(mode: str):
try:
changed = ring.set_fft_complex_mode(mode)
except Exception:
changed = False
if changed:
try:
curve_fft.setData([], [])
except Exception:
pass
_refresh_pipeline_label()
ifft_mode_arccos_rb.toggled.connect(
lambda checked: _apply_ifft_complex_mode("arccos") if checked else None
)
ifft_mode_diff_rb.toggled.connect(
lambda checked: _apply_ifft_complex_mode("diff") if checked else None
)
_refresh_calib_controls()
_refresh_bg_controls()
_refresh_pipeline_label()