add calibration file
This commit is contained in:
@ -12,7 +12,7 @@ from rfg_adc_plotter.constants import FFT_LEN, FREQ_SPAN_GHZ, IFFT_LEN
|
||||
_IFFT_T_MAX_NS = float((IFFT_LEN - 1) / (FREQ_SPAN_GHZ * 1e9) * 1e9)
|
||||
from rfg_adc_plotter.io.sweep_reader import SweepReader
|
||||
from rfg_adc_plotter.processing.normalizer import build_calib_envelopes
|
||||
from rfg_adc_plotter.state.app_state import AppState, format_status
|
||||
from rfg_adc_plotter.state.app_state import CALIB_ENVELOPE_PATH, AppState, format_status
|
||||
from rfg_adc_plotter.state.ring_buffer import RingBuffer
|
||||
from rfg_adc_plotter.types import SweepPacket
|
||||
|
||||
@ -165,10 +165,16 @@ def run_matplotlib(args):
|
||||
ax_smax = fig.add_axes([0.95, 0.55, 0.02, 0.35])
|
||||
ax_sctr = fig.add_axes([0.98, 0.55, 0.02, 0.35])
|
||||
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])
|
||||
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])
|
||||
|
||||
import os as _os
|
||||
if not _os.path.isfile(CALIB_ENVELOPE_PATH):
|
||||
ax_cb_file.set_visible(False)
|
||||
|
||||
def _on_ylim_change(_val):
|
||||
try:
|
||||
@ -179,12 +185,30 @@ def run_matplotlib(args):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _on_calib_file_clicked(_v):
|
||||
use_file = bool(calib_file_cb.get_status()[0])
|
||||
if use_file:
|
||||
ok = state.load_calib_envelope(CALIB_ENVELOPE_PATH)
|
||||
if ok:
|
||||
state.set_calib_mode("file")
|
||||
else:
|
||||
calib_file_cb.set_active(0) # снять галочку
|
||||
else:
|
||||
state.set_calib_mode("live")
|
||||
state.set_calib_enabled(bool(calib_cb.get_status()[0]))
|
||||
|
||||
def _on_calib_clicked(_v):
|
||||
import os as _os2
|
||||
if _os2.path.isfile(CALIB_ENVELOPE_PATH):
|
||||
ax_cb_file.set_visible(True)
|
||||
state.set_calib_enabled(bool(calib_cb.get_status()[0]))
|
||||
fig.canvas.draw_idle()
|
||||
|
||||
ymin_slider.on_changed(_on_ylim_change)
|
||||
ymax_slider.on_changed(_on_ylim_change)
|
||||
contrast_slider.on_changed(lambda _v: fig.canvas.draw_idle())
|
||||
calib_cb.on_clicked(lambda _v: state.set_calib_enabled(
|
||||
bool(calib_cb.get_status()[0])
|
||||
))
|
||||
calib_cb.on_clicked(_on_calib_clicked)
|
||||
calib_file_cb.on_clicked(_on_calib_file_clicked)
|
||||
except Exception:
|
||||
calib_cb = None
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@ import numpy as np
|
||||
from rfg_adc_plotter.constants import FREQ_SPAN_GHZ, IFFT_LEN
|
||||
from rfg_adc_plotter.io.sweep_reader import SweepReader
|
||||
from rfg_adc_plotter.processing.normalizer import build_calib_envelopes
|
||||
from rfg_adc_plotter.state.app_state import AppState, format_status
|
||||
from rfg_adc_plotter.state.app_state import CALIB_ENVELOPE_PATH, AppState, format_status
|
||||
from rfg_adc_plotter.state.ring_buffer import RingBuffer
|
||||
from rfg_adc_plotter.types import SweepPacket
|
||||
|
||||
@ -184,12 +184,46 @@ def run_pyqtgraph(args):
|
||||
img_fft = pg.ImageItem()
|
||||
p_spec.addItem(img_fft)
|
||||
|
||||
# Чекбокс калибровки
|
||||
# Чекбоксы калибровки — в одном контейнере
|
||||
calib_widget = QtWidgets.QWidget()
|
||||
calib_layout = QtWidgets.QHBoxLayout(calib_widget)
|
||||
calib_layout.setContentsMargins(2, 2, 2, 2)
|
||||
calib_layout.setSpacing(8)
|
||||
|
||||
calib_cb = QtWidgets.QCheckBox("калибровка")
|
||||
cb_proxy = QtWidgets.QGraphicsProxyWidget()
|
||||
cb_proxy.setWidget(calib_cb)
|
||||
win.addItem(cb_proxy, row=2, col=1)
|
||||
calib_cb.stateChanged.connect(lambda _v: state.set_calib_enabled(calib_cb.isChecked()))
|
||||
calib_file_cb = QtWidgets.QCheckBox("из файла")
|
||||
calib_file_cb.setEnabled(False) # активируется только если файл существует
|
||||
|
||||
calib_layout.addWidget(calib_cb)
|
||||
calib_layout.addWidget(calib_file_cb)
|
||||
|
||||
cb_container_proxy = QtWidgets.QGraphicsProxyWidget()
|
||||
cb_container_proxy.setWidget(calib_widget)
|
||||
win.addItem(cb_container_proxy, row=2, col=1)
|
||||
|
||||
def _check_file_cb_available():
|
||||
import os
|
||||
calib_file_cb.setEnabled(os.path.isfile(CALIB_ENVELOPE_PATH))
|
||||
|
||||
_check_file_cb_available()
|
||||
|
||||
def _on_calib_file_toggled(checked):
|
||||
if checked:
|
||||
ok = state.load_calib_envelope(CALIB_ENVELOPE_PATH)
|
||||
if ok:
|
||||
state.set_calib_mode("file")
|
||||
else:
|
||||
calib_file_cb.setChecked(False)
|
||||
else:
|
||||
state.set_calib_mode("live")
|
||||
state.set_calib_enabled(calib_cb.isChecked())
|
||||
|
||||
def _on_calib_toggled(_v):
|
||||
_check_file_cb_available()
|
||||
state.set_calib_enabled(calib_cb.isChecked())
|
||||
|
||||
calib_cb.stateChanged.connect(_on_calib_toggled)
|
||||
calib_file_cb.stateChanged.connect(lambda _v: _on_calib_file_toggled(calib_file_cb.isChecked()))
|
||||
|
||||
# Статусная строка
|
||||
status = pg.LabelItem(justify="left")
|
||||
|
||||
Reference in New Issue
Block a user