From 26a2a85828884e88e3842981a81908191a8b881b Mon Sep 17 00:00:00 2001 From: jupfi Date: Sun, 23 Jul 2023 15:27:23 +0200 Subject: [PATCH] Pulseshape paramter update. --- src/nqrduck_spectrometer/pulseparameters.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/nqrduck_spectrometer/pulseparameters.py b/src/nqrduck_spectrometer/pulseparameters.py index e081848..e4dcdf0 100644 --- a/src/nqrduck_spectrometer/pulseparameters.py +++ b/src/nqrduck_spectrometer/pulseparameters.py @@ -1,3 +1,4 @@ +import logging import numpy as np import sympy from pathlib import Path @@ -6,6 +7,8 @@ from nqrduck.contrib.mplwidget import MplWidget from nqrduck.helpers.signalprocessing import SignalProcessing as sp from .base_spectrometer_model import BaseSpectrometerModel +logger = logging.getLogger(__name__) + class Function(): name: str parameters : list @@ -31,9 +34,13 @@ class Function(): def evaluate(self, pulse_length: float) -> np.ndarray: """Evaluates the function for the given pulse length.""" n = int(pulse_length / self.resolution) - t = np.linspace(-np.pi, np.pi, n) + t = np.linspace(self.start_x, self.end_x, n) x = sympy.symbols("x") + # If the expression is a string, convert it to a sympy expression + if isinstance(self.expr, str): + self.expr = sympy.sympify(self.expr) + found_variables = dict() # Create a dictionary of the parameters and their values for parameter in self.parameters: @@ -69,6 +76,7 @@ class Function(): def add_parameter(self, parameter : "Function.Parameter"): self.parameters.append(parameter) + class Parameter: def __init__(self, name : str, symbol : str, value : float) -> None: self.name = name @@ -76,6 +84,10 @@ class Function(): self.value = value self.default = value + def set_value(self, value : float): + self.value = value + logger.debug("Parameter %s set to %s", self.name, self.value) + class RectFunction(Function): name = "Rectangular" def __init__(self) -> None: @@ -88,6 +100,8 @@ class SincFunction(Function): expr = sympy.sympify("sin(x * l)/ (x * l)") super().__init__(expr) self.add_parameter(Function.Parameter("Scale Factor", "l", 2)) + self.start_x = -np.pi + self.end_x = np.pi class GaussianFunction(Function): name = "Gaussian"