mirror of
https://github.com/nqrduck/nqrduck-measurement.git
synced 2024-11-09 20:00:02 +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
|
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:
|
if result:
|
||||||
for option, function in dialog.return_functions.items():
|
function = dialog.get_function()
|
||||||
logger.debug(
|
|
||||||
"Setting option %s of parameter %s in event %s to %s",
|
|
||||||
option,
|
|
||||||
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 = dialog.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 = None
|
||||||
|
|
||||||
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,11 +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.helpers.functions import Function, GaussianFunction, CustomFunctiony
|
from nqrduck.helpers.functions import Function, GaussianFunction, CustomFunction
|
||||||
|
from nqrduck.helpers.formbuilder import DuckFormBuilder, DuckFormFunctionSelectionField
|
||||||
# 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."""
|
||||||
|
@ -22,7 +24,7 @@ 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.
|
||||||
|
@ -32,15 +34,64 @@ class Apodization(BaseSpectrometerModel.PulseParameter):
|
||||||
APODIZATION_FUNCTIONS (str): The name of the apodization functions option.
|
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 = 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