mirror of
https://github.com/nqrduck/nqrduck-measurement.git
synced 2024-11-09 20:00:02 +00:00
Merge pull request #15 from nqrduck/formbuilder-and-function-optimization
Formbuilder and function optimization
This commit is contained in:
commit
822264bc79
4 changed files with 47 additions and 62 deletions
|
@ -1,5 +1,8 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
### Version 0.0.3 (26-04-2024)
|
||||||
|
- Switched to new formbuilder. This should make implementation of signal processing methods more robust and easier.
|
||||||
|
|
||||||
### Version 0.0.2 (17-04-2024)
|
### Version 0.0.2 (17-04-2024)
|
||||||
- Deployment to PyPi via github actions
|
- Deployment to PyPi via github actions
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ allow-direct-references = true
|
||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "nqrduck-measurement"
|
name = "nqrduck-measurement"
|
||||||
version = "0.0.2"
|
version = "0.0.3"
|
||||||
authors = [
|
authors = [
|
||||||
{ name="jupfi", email="support@nqrduck.cool" },
|
{ name="jupfi", email="support@nqrduck.cool" },
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,7 +6,6 @@ import numpy as np
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from PyQt6.QtCore import pyqtSlot, pyqtSignal
|
from PyQt6.QtCore import pyqtSlot, pyqtSignal
|
||||||
from PyQt6.QtWidgets import QApplication
|
from PyQt6.QtWidgets import QApplication
|
||||||
from nqrduck_pulseprogrammer.view import OptionsDialog
|
|
||||||
from nqrduck_spectrometer.pulsesequence import PulseSequence
|
from nqrduck_spectrometer.pulsesequence import PulseSequence
|
||||||
from .signalprocessing_options import Apodization
|
from .signalprocessing_options import Apodization
|
||||||
from nqrduck.module.module_controller import ModuleController
|
from nqrduck.module.module_controller import ModuleController
|
||||||
|
@ -211,48 +210,22 @@ class MeasurementController(ModuleController):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
# We need to create a event which corresponds to the measurement.
|
measurement = self.module.model.displayed_measurement
|
||||||
event_duration = self.module.model.displayed_measurement.tdx[-1] * 1e-6
|
|
||||||
|
|
||||||
event = PulseSequence.Event(name="Apodization", duration=str(event_duration))
|
dialog = Apodization(measurement, parent=self.module.view)
|
||||||
parameter = Apodization()
|
|
||||||
parameter.start_x = 0
|
|
||||||
parameter.end_x = event_duration
|
|
||||||
dialog = OptionsDialog(event, parameter, self.module.view)
|
|
||||||
result = dialog.exec()
|
result = dialog.exec()
|
||||||
|
|
||||||
if result:
|
logger.debug("Dialog result: %s", result)
|
||||||
for option, function in dialog.return_functions.items():
|
if not result:
|
||||||
logger.debug(
|
return
|
||||||
"Setting option %s of parameter %s in event %s to %s",
|
|
||||||
option,
|
function = dialog.get_function()
|
||||||
parameter,
|
|
||||||
event,
|
|
||||||
function(),
|
|
||||||
)
|
|
||||||
option.set_value(function())
|
|
||||||
|
|
||||||
# Get the function from the Apodization function
|
|
||||||
function = parameter.get_option_by_name(Apodization.APODIZATION_FUNCTIONS).value
|
|
||||||
logger.debug("Apodization function: %s", function)
|
logger.debug("Apodization function: %s", function)
|
||||||
|
|
||||||
# Get the y data weights from the function
|
apodized_measurement = measurement.apodization(function)
|
||||||
resolution = (
|
|
||||||
self.module.model.displayed_measurement.tdx[1]
|
|
||||||
- self.module.model.displayed_measurement.tdx[0]
|
|
||||||
) * 1e-6
|
|
||||||
y_weight = function.get_pulse_amplitude(event.duration, Decimal(resolution))
|
|
||||||
# Append the last point to the end of the array
|
|
||||||
y_weight = np.append(y_weight, y_weight[-1])
|
|
||||||
|
|
||||||
tdy_measurement = self.module.model.displayed_measurement.tdy * y_weight
|
dialog.deleteLater()
|
||||||
|
|
||||||
measurement = Measurement(
|
self.module.model.displayed_measurement = apodized_measurement
|
||||||
self.module.model.displayed_measurement.tdx,
|
self.module.model.add_measurement(apodized_measurement)
|
||||||
tdy_measurement,
|
|
||||||
target_frequency=self.module.model.displayed_measurement.target_frequency,
|
|
||||||
IF_frequency=self.module.model.displayed_measurement.IF_frequency,
|
|
||||||
)
|
|
||||||
|
|
||||||
self.module.model.displayed_measurement = measurement
|
|
||||||
self.module.model.add_measurement(measurement)
|
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
"""Signal processing options."""
|
"""Signal processing options."""
|
||||||
|
import logging
|
||||||
|
from decimal import Decimal
|
||||||
|
import numpy as np
|
||||||
import sympy
|
import sympy
|
||||||
from nqrduck_spectrometer.base_spectrometer_model import BaseSpectrometerModel
|
from nqrduck_spectrometer.measurement import Measurement
|
||||||
from nqrduck_spectrometer.pulseparameters import (
|
from nqrduck.helpers.functions import Function, GaussianFunction, CustomFunction
|
||||||
FunctionOption,
|
from nqrduck.helpers.formbuilder import DuckFormBuilder, DuckFormFunctionSelectionField
|
||||||
GaussianFunction,
|
|
||||||
CustomFunction,
|
|
||||||
Function,
|
|
||||||
)
|
|
||||||
|
|
||||||
# We implement the signal processing options as PulseParamterOptions because we can then easily use the automatic UI generation
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class FIDFunction(Function):
|
class FIDFunction(Function):
|
||||||
"""The exponetial FID function."""
|
"""The exponetial FID function."""
|
||||||
|
@ -27,25 +24,37 @@ class FIDFunction(Function):
|
||||||
self.add_parameter(Function.Parameter("T2star (microseconds)", "T2star", 10))
|
self.add_parameter(Function.Parameter("T2star (microseconds)", "T2star", 10))
|
||||||
|
|
||||||
|
|
||||||
class Apodization(BaseSpectrometerModel.PulseParameter):
|
class Apodization(DuckFormBuilder):
|
||||||
"""Apodization parameter.
|
"""Apodization parameter.
|
||||||
|
|
||||||
This parameter is used to apply apodization functions to the signal.
|
This parameter is used to apply apodization functions to the signal.
|
||||||
The apodization functions are used to reduce the noise in the signal.
|
The apodization functions are used to reduce the noise in the signal.
|
||||||
|
|
||||||
Attributes:
|
|
||||||
APODIZATION_FUNCTIONS (str): The name of the apodization functions option.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
APODIZATION_FUNCTIONS = "Apodization functions"
|
def __init__(self, measurement: Measurement, parent=None) -> None:
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Apodization parameter."""
|
"""Apodization parameter."""
|
||||||
super().__init__("Apodization")
|
super().__init__("Apodization", parent=parent)
|
||||||
|
|
||||||
self.add_option(
|
self.measurement = measurement
|
||||||
FunctionOption(
|
functions = [
|
||||||
self.APODIZATION_FUNCTIONS,
|
FIDFunction(),
|
||||||
[FIDFunction(), GaussianFunction(), CustomFunction()],
|
GaussianFunction(),
|
||||||
),
|
CustomFunction(),
|
||||||
|
]
|
||||||
|
|
||||||
|
self.duration = (self.measurement.tdx[-1] - self.measurement.tdx[0]) * 1e-6
|
||||||
|
|
||||||
|
function_selection_field = DuckFormFunctionSelectionField(
|
||||||
|
text=None, tooltip=None, functions=functions, duration=self.duration, parent=parent, default_function=0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.add_field(function_selection_field)
|
||||||
|
|
||||||
|
def get_function(self) -> Function:
|
||||||
|
"""Get the selected function.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Function: The selected function.
|
||||||
|
"""
|
||||||
|
return self.get_values()[0]
|
||||||
|
|
Loading…
Reference in a new issue