mirror of
https://github.com/nqrduck/nqrduck-measurement.git
synced 2024-12-22 15:47:51 +00:00
Switched to new formbuilder for singal processing.
This commit is contained in:
parent
ca74b16b5f
commit
0cd27cde86
2 changed files with 73 additions and 51 deletions
|
@ -211,48 +211,19 @@ class MeasurementController(ModuleController):
|
|||
)
|
||||
return
|
||||
|
||||
# We need to create a event which corresponds to the measurement.
|
||||
event_duration = self.module.model.displayed_measurement.tdx[-1] * 1e-6
|
||||
measurement = self.module.model.displayed_measurement
|
||||
|
||||
event = PulseSequence.Event(name="Apodization", duration=str(event_duration))
|
||||
parameter = Apodization()
|
||||
parameter.start_x = 0
|
||||
parameter.end_x = event_duration
|
||||
dialog = OptionsDialog(event, parameter, self.module.view)
|
||||
dialog = Apodization(measurement, parent=self.module.view)
|
||||
result = dialog.exec()
|
||||
|
||||
if result:
|
||||
for option, function in dialog.return_functions.items():
|
||||
logger.debug(
|
||||
"Setting option %s of parameter %s in event %s to %s",
|
||||
option,
|
||||
parameter,
|
||||
event,
|
||||
function(),
|
||||
)
|
||||
option.set_value(function())
|
||||
function = dialog.get_function()
|
||||
|
||||
# Get the function from the Apodization function
|
||||
function = parameter.get_option_by_name(Apodization.APODIZATION_FUNCTIONS).value
|
||||
logger.debug("Apodization function: %s", function)
|
||||
|
||||
# Get the y data weights from the 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])
|
||||
apodized_measurement = dialog.apodization(function)
|
||||
|
||||
tdy_measurement = self.module.model.displayed_measurement.tdy * y_weight
|
||||
dialog = None
|
||||
|
||||
measurement = Measurement(
|
||||
self.module.model.displayed_measurement.tdx,
|
||||
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)
|
||||
self.module.model.displayed_measurement = apodized_measurement
|
||||
self.module.model.add_measurement(apodized_measurement)
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
"""Signal processing options."""
|
||||
|
||||
import logging
|
||||
from decimal import Decimal
|
||||
import numpy as np
|
||||
import sympy
|
||||
from nqrduck_spectrometer.base_spectrometer_model import BaseSpectrometerModel
|
||||
from nqrduck.helpers.functions import Function, GaussianFunction, CustomFunctiony
|
||||
|
||||
# We implement the signal processing options as PulseParamterOptions because we can then easily use the automatic UI generation
|
||||
from nqrduck_spectrometer.measurement import Measurement
|
||||
from nqrduck.helpers.functions import Function, GaussianFunction, CustomFunction
|
||||
from nqrduck.helpers.formbuilder import DuckFormBuilder, DuckFormFunctionSelectionField
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class FIDFunction(Function):
|
||||
"""The exponetial FID function."""
|
||||
|
@ -22,7 +24,7 @@ class FIDFunction(Function):
|
|||
self.add_parameter(Function.Parameter("T2star (microseconds)", "T2star", 10))
|
||||
|
||||
|
||||
class Apodization(BaseSpectrometerModel.PulseParameter):
|
||||
class Apodization(DuckFormBuilder):
|
||||
"""Apodization parameter.
|
||||
|
||||
This parameter is used to apply apodization functions to the signal.
|
||||
|
@ -32,15 +34,64 @@ class Apodization(BaseSpectrometerModel.PulseParameter):
|
|||
APODIZATION_FUNCTIONS (str): The name of the apodization functions option.
|
||||
"""
|
||||
|
||||
APODIZATION_FUNCTIONS = "Apodization functions"
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, measurement: Measurement, parent=None) -> None:
|
||||
"""Apodization parameter."""
|
||||
super().__init__("Apodization")
|
||||
super().__init__("Apodization", parent=parent)
|
||||
|
||||
self.add_option(
|
||||
FunctionOption(
|
||||
self.APODIZATION_FUNCTIONS,
|
||||
[FIDFunction(), GaussianFunction(), CustomFunction()],
|
||||
),
|
||||
self.measurement = measurement
|
||||
functions = [
|
||||
FIDFunction(),
|
||||
GaussianFunction(),
|
||||
CustomFunction(),
|
||||
]
|
||||
|
||||
self.duration = Decimal((measurement.tdx[-1] - measurement.tdx[0]) * 1e-6)
|
||||
|
||||
function_selection_field = DuckFormFunctionSelectionField(
|
||||
False, False, functions, 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]
|
||||
|
||||
def apodization(self, function : Function) -> None:
|
||||
"""Apply the apodization function to the measurement the object has been created to.
|
||||
|
||||
Args:
|
||||
function (Function): The apodization function.
|
||||
|
||||
Returns:
|
||||
Measurement: The apodized measurement.
|
||||
"""
|
||||
|
||||
# Get the y data weights from the function
|
||||
resolution = (
|
||||
self.measurement.tdx[1]
|
||||
- self.measurement.tdx[0]
|
||||
) * 1e-6
|
||||
|
||||
logger.debug("Resolution: %s", resolution)
|
||||
logger.debug("Resolution (Dec): %s", Decimal(resolution))
|
||||
|
||||
y_weight = function.get_pulse_amplitude(self.duration, Decimal(resolution))
|
||||
# Append the last value to the end of the array
|
||||
y_weight = np.append(y_weight, y_weight[-1])
|
||||
|
||||
tdy_measurement = self.measurement.tdy * y_weight
|
||||
|
||||
apodized_measurement = Measurement(
|
||||
self.measurement.tdx,
|
||||
tdy_measurement,
|
||||
target_frequency=self.measurement.target_frequency,
|
||||
IF_frequency=self.measurement.IF_frequency,
|
||||
)
|
||||
|
||||
return apodized_measurement
|
||||
|
||||
|
|
Loading…
Reference in a new issue