Added saving and loading of S11 measurements.

This commit is contained in:
jupfi 2023-12-16 13:20:33 +01:00
parent bbe1798f06
commit 2d7fbf3479
5 changed files with 110 additions and 0 deletions

View file

@ -512,6 +512,35 @@ class AutoTMController(ModuleController):
self.module.model.open_calibration = S11Data.from_json(data["open"])
self.module.model.load_calibration = S11Data.from_json(data["load"])
def save_measurement(self, filename: str) -> None:
"""Save measurement to file.
Args:
filename (str): Path to file.
"""
logger.debug("Saving measurement.")
if not self.module.model.measurement:
logger.debug("No measurement to save.")
return
measurement = self.module.model.measurement.to_json()
with open(filename, "w") as f:
json.dump(measurement, f)
def load_measurement(self, filename: str) -> None:
"""Load measurement from file.
Args:
filename (str): Path to file.
"""
logger.debug("Loading measurement.")
with open(filename, "r") as f:
measurement = json.load(f)
self.module.model.measurement = S11Data.from_json(measurement)
### Voltage Control ###
def set_voltages(self, tuning_voltage: str, matching_voltage: str) -> None:

View file

@ -10,6 +10,7 @@ logger = logging.getLogger(__name__)
class S11Data:
FILE_EXTENSION = "s11"
# Conversion factors - the data is generally sent and received in mV
# These values are used to convert the data to dB and degrees
CENTER_POINT_MAGNITUDE = 900 # mV

View file

@ -547,6 +547,41 @@
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="importButton">
<property name="text">
<string>Import Measurement</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="exportButton">
<property name="text">
<string>Export Measurement</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>

View file

@ -21,6 +21,7 @@ from nqrduck.contrib.mplwidget import MplWidget
from nqrduck.assets.icons import Logos
from nqrduck.assets.animations import DuckAnimations
from .widget import Ui_Form
from .model import S11Data
logger = logging.getLogger(__name__)
@ -138,6 +139,16 @@ class AutoTMView(ModuleView):
# Position Button
self._ui_form.positionButton.clicked.connect(self.on_position_button_clicked)
# Import and export buttons
self._ui_form.exportButton.setIcon(Logos.Save16x16())
self._ui_form.exportButton.setIconSize(self._ui_form.exportButton.size())
self._ui_form.exportButton.clicked.connect(self.on_export_button_clicked)
self._ui_form.importButton.setIcon(Logos.Load16x16())
self._ui_form.importButton.setIconSize(self._ui_form.importButton.size())
self._ui_form.importButton.clicked.connect(self.on_import_button_clicked)
self.init_plot()
self.init_labels()
@ -384,6 +395,24 @@ class AutoTMView(ModuleView):
self.lut_window = self.LutWindow(self.module)
self.lut_window.show()
@pyqtSlot()
def on_export_button_clicked(self) -> None:
"""Slot for when the export button is clicked."""
logger.debug("Export button clicked")
file_manager = self.QFileManager(S11Data.FILE_EXTENSION, parent=self.widget)
file_name = file_manager.saveFileDialog()
if file_name:
self.module.controller.save_measurement(file_name)
@pyqtSlot()
def on_import_button_clicked(self) -> None:
"""Slot for when the import button is clicked."""
logger.debug("Import button clicked")
file_manager = self.QFileManager(S11Data.FILE_EXTENSION, parent=self.widget)
file_name = file_manager.loadFileDialog()
if file_name:
self.module.controller.load_measurement(file_name)
class StepperSavedPositionsWindow(QDialog):
def __init__(self, module, parent=None):
super().__init__(parent)

View file

@ -283,6 +283,20 @@ class Ui_Form(object):
self.S11Plot.setSizePolicy(sizePolicy)
self.S11Plot.setObjectName("S11Plot")
self.verticalLayout_5.addWidget(self.S11Plot)
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
self.verticalLayout_4 = QtWidgets.QVBoxLayout()
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.importButton = QtWidgets.QPushButton(parent=Form)
self.importButton.setObjectName("importButton")
self.verticalLayout_4.addWidget(self.importButton)
self.exportButton = QtWidgets.QPushButton(parent=Form)
self.exportButton.setObjectName("exportButton")
self.verticalLayout_4.addWidget(self.exportButton)
self.horizontalLayout.addLayout(self.verticalLayout_4)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Policy.Expanding, QtWidgets.QSizePolicy.Policy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.verticalLayout_5.addLayout(self.horizontalLayout)
self.horizontalLayout_2.addLayout(self.verticalLayout_5)
self.horizontalLayout_2.setStretch(1, 1)
@ -342,4 +356,6 @@ class Ui_Form(object):
self.calibrationButton.setText(_translate("Form", "Calibrate"))
self.pushButton_3.setText(_translate("Form", "T&M Settings"))
self.titleinfoLabel.setText(_translate("Form", "Info Box:"))
self.importButton.setText(_translate("Form", "Import Measurement"))
self.exportButton.setText(_translate("Form", "Export Measurement"))
from nqrduck.contrib.mplwidget import MplWidget