Added fitting of frequency domain data.

This commit is contained in:
jupfi 2024-05-23 17:04:58 +02:00
parent df9461019c
commit dca1c6816f
3 changed files with 10 additions and 19 deletions

View file

@ -45,7 +45,7 @@ class MeasurementModel(ModuleModel):
FILE_EXTENSION = "meas"
# This constants are used to determine which view is currently displayed.
FFT_VIEW = "fft"
FFT_VIEW = "frequency"
TIME_VIEW = "time"
displayed_measurement_changed = pyqtSignal(Measurement)

View file

@ -2,7 +2,7 @@
import logging
import sympy
from nqrduck_spectrometer.measurement import Measurement, Fit, T2StarFit
from nqrduck_spectrometer.measurement import Measurement, Fit, T2StarFit, LorentzianFit
from nqrduck.helpers.functions import Function, GaussianFunction, CustomFunction
from nqrduck.helpers.formbuilder import (
DuckFormBuilder,
@ -27,22 +27,6 @@ class FIDFunction(Function):
self.add_parameter(Function.Parameter("T2star (microseconds)", "T2star", 10))
class LorentzianFunction(Function):
"""The Lorentzian function."""
name = "Lorentzian"
def __init__(self) -> None:
"""Lorentzian function."""
expr = sympy.sympify("1 / (1 + (x / T2star)^2)")
super().__init__(expr)
self.start_x = 0
self.end_x = 30
self.add_parameter(Function.Parameter("T2star (microseconds)", "T2star", 10))
class Apodization(DuckFormBuilder):
"""Apodization parameter.
@ -100,6 +84,7 @@ class Fitting(DuckFormBuilder):
fits = {}
fits["T2*"] = T2StarFit(self.measurement)
fits["Lorentzian"] = LorentzianFit(self.measurement)
selection_field = DuckFormDropdownField(
text=None,

View file

@ -251,10 +251,16 @@ class MeasurementView(ModuleView):
return
for fit in measurement.fits:
logger.debug(f"Plotting fit {fit.name}.")
if fit.domain == self.module.model.view_mode:
logger.debug(f"Plotting {fit.name} fit in domain {fit.domain}.")
x = fit.x
y = fit.y
# Shift the x values if the view mode is FFT
if fit.domain == self.module.model.FFT_VIEW:
x = x + float(
measurement.target_frequency - measurement.IF_frequency
) * 1e-6
self._ui_form.plotter.canvas.ax.plot(
x, y, label=f"{fit.name} Fit", linestyle="--"
)