diff --git a/pyproject.toml b/pyproject.toml index 5917a3d..c026343 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,8 +25,40 @@ dependencies = [ "pyqt6", "nqrduck", "pyserial", + "scipy", ] [project.entry-points."nqrduck"] "nqrduck-autotm" = "nqrduck_autotm.autotm:AutoTM" +dev = [ + "black", + "pydocstyle", + "pyupgrade", + "ruff", +] + +[tool.ruff] +exclude = [ + "widget.py", +] + +[tool.ruff.lint] +extend-select = [ + "UP", # pyupgrade + "D", # pydocstyle +] + +[tool.ruff.lint.per-file-ignores] +"__init__.py" = ["F401"] + +[tool.ruff.lint.pydocstyle] +convention = "google" + +[project.urls] +"Homepage" = "https://nqrduck.cool" +"Bug Tracker" = "https://github.com/nqrduck/nqrduck-autotm/issues" +"Source Code" = "https://github.com/nqrduck/nqrduck-autotm" + +[tool.hatch.build.targets.wheel] +packages = ["src/nqrduck"] \ No newline at end of file diff --git a/src/nqrduck_autotm/controller.py b/src/nqrduck_autotm/controller.py index e21525d..7d80d23 100644 --- a/src/nqrduck_autotm/controller.py +++ b/src/nqrduck_autotm/controller.py @@ -2,11 +2,9 @@ import logging import time import numpy as np import json -import time from serial.tools.list_ports import comports -from PyQt6.QtTest import QTest from PyQt6 import QtSerialPort -from PyQt6.QtCore import QThread, pyqtSignal, pyqtSlot, Qt +from PyQt6.QtCore import pyqtSlot from PyQt6.QtCore import QTimer from PyQt6.QtWidgets import QApplication from nqrduck.module.module_controller import ModuleController @@ -43,7 +41,7 @@ class AutoTMController(ModuleController): self.tune_and_match(value) def tune_and_match(self, frequency: float) -> None: - """ This method is called when this module already has a LUT table. It should then tune and match the probe coil to the specified frequency. + """This method is called when this module already has a LUT table. It should then tune and match the probe coil to the specified frequency. """ if self.module.model.LUT is None: logger.error("Could not tune and match. No LUT available.") @@ -301,7 +299,8 @@ class AutoTMController(ModuleController): It hides the voltage sweep spinner dialog and adds the data to the model. Args: - LUT (LookupTable): The lookup table that is being generated.""" + LUT (LookupTable): The lookup table that is being generated. + """ logger.debug("Voltage sweep finished") self.module.view.el_LUT_spinner.hide() self.module.model.LUT = LUT @@ -505,7 +504,7 @@ class AutoTMController(ModuleController): logger.debug("Importing calibration") # We import the different calibrations from a json file - with open(filename, "r") as f: + with open(filename) as f: data = json.load(f) self.module.model.short_calibration = S11Data.from_json(data["short"]) self.module.model.open_calibration = S11Data.from_json(data["open"]) @@ -533,10 +532,9 @@ class AutoTMController(ModuleController): Args: filename (str): Path to file. """ - logger.debug("Loading measurement.") - with open(filename, "r") as f: + with open(filename) as f: measurement = json.load(f) self.module.model.measurement = S11Data.from_json(measurement) @@ -928,7 +926,7 @@ class AutoTMController(ModuleController): # First clear the old positions self.module.model.saved_positions = [] - with open(path, "r") as f: + with open(path) as f: positions = json.load(f) for position in positions: logger.debug("Loading position: %s", position) @@ -1048,7 +1046,6 @@ class AutoTMController(ModuleController): def start_next_mechTM(self, LUT): """Start the next mechanical tuning and matching sweep.""" - next_frequency = LUT.get_next_frequency() LUT.started_frequency = next_frequency logger.debug("Starting next mechanical tuning and matching:") diff --git a/src/nqrduck_autotm/model.py b/src/nqrduck_autotm/model.py index 26fd7c3..bb69231 100644 --- a/src/nqrduck_autotm/model.py +++ b/src/nqrduck_autotm/model.py @@ -40,7 +40,6 @@ class S11Data: Keyword Arguments: phase_correction {bool} -- If True, the phase correction is applied. (default: {False}) """ - phase_deg = (self.phase_mv - self.CENTER_POINT_PHASE) / self.PHASE_SLOPE if phase_correction: phase_deg = self.phase_correction(self.frequency, phase_deg) @@ -197,7 +196,7 @@ class Stepper: self.homed = False self.position = 0 -class SavedPosition(): +class SavedPosition: """This class is used to store a saved position for tuning and matching of electrical probeheads.""" def __init__(self, frequency: float, tuning_position : int, matching_position : int) -> None: self.frequency = frequency @@ -251,7 +250,8 @@ class ElectricalLookupTable(LookupTable): Args: tuning_voltage (float): The tuning voltage for the given frequency. - matching_voltage (float): The matching voltage for the given frequency.""" + matching_voltage (float): The matching voltage for the given frequency. + """ self.data[self.started_frequency] = (tuning_voltage, matching_voltage) def get_voltages(self, frequency: float) -> tuple: @@ -287,7 +287,6 @@ class ElectricalLookupTable(LookupTable): Returns: float: The next frequency for which the tuning and matching voltage is not yet set. """ - for frequency, (tuning_voltage, matching_voltage) in self.data.items(): if tuning_voltage is None or matching_voltage is None: return frequency @@ -316,7 +315,8 @@ class MechanicalLookupTable(LookupTable): Args: tuning_position (int): The tuning position for the given frequency. - matching_position (int): The matching position for the given frequency.""" + matching_position (int): The matching position for the given frequency. + """ self.data[self.started_frequency] = (tuning_position, matching_position) def get_positions(self, frequency: float) -> tuple: @@ -352,7 +352,6 @@ class MechanicalLookupTable(LookupTable): Returns: float: The next frequency for which the tuning and matching position is not yet set. """ - for frequency, (tuning_position, matching_position) in self.data.items(): if tuning_position is None or matching_position is None: return frequency @@ -452,7 +451,8 @@ class AutoTMModel(ModuleModel): @property def measurement(self): """The measurement property is used to store the current measurement. - This is the measurement that is shown in the main S11 plot""" + This is the measurement that is shown in the main S11 plot + """ return self._measurement @measurement.setter diff --git a/src/nqrduck_autotm/view.py b/src/nqrduck_autotm/view.py index 89bd753..336d5c7 100644 --- a/src/nqrduck_autotm/view.py +++ b/src/nqrduck_autotm/view.py @@ -212,7 +212,8 @@ class AutoTMView(ModuleView): """Update the serial 'connectionLabel' according to the current serial connection. Args: - serial (serial.Serial): The current serial connection.""" + serial (serial.Serial): The current serial connection. + """ logger.debug("Updating serial connection label") if serial.isOpen(): self._ui_form.connectionLabel.setText(serial.portName())