mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-11-09 12:30:01 +00:00
Pulseshape paramter update.
This commit is contained in:
parent
d868c60f4e
commit
26a2a85828
1 changed files with 15 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import sympy
|
import sympy
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
@ -6,6 +7,8 @@ from nqrduck.contrib.mplwidget import MplWidget
|
||||||
from nqrduck.helpers.signalprocessing import SignalProcessing as sp
|
from nqrduck.helpers.signalprocessing import SignalProcessing as sp
|
||||||
from .base_spectrometer_model import BaseSpectrometerModel
|
from .base_spectrometer_model import BaseSpectrometerModel
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Function():
|
class Function():
|
||||||
name: str
|
name: str
|
||||||
parameters : list
|
parameters : list
|
||||||
|
@ -31,9 +34,13 @@ class Function():
|
||||||
def evaluate(self, pulse_length: float) -> np.ndarray:
|
def evaluate(self, pulse_length: float) -> np.ndarray:
|
||||||
"""Evaluates the function for the given pulse length."""
|
"""Evaluates the function for the given pulse length."""
|
||||||
n = int(pulse_length / self.resolution)
|
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")
|
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()
|
found_variables = dict()
|
||||||
# Create a dictionary of the parameters and their values
|
# Create a dictionary of the parameters and their values
|
||||||
for parameter in self.parameters:
|
for parameter in self.parameters:
|
||||||
|
@ -69,6 +76,7 @@ class Function():
|
||||||
def add_parameter(self, parameter : "Function.Parameter"):
|
def add_parameter(self, parameter : "Function.Parameter"):
|
||||||
self.parameters.append(parameter)
|
self.parameters.append(parameter)
|
||||||
|
|
||||||
|
|
||||||
class Parameter:
|
class Parameter:
|
||||||
def __init__(self, name : str, symbol : str, value : float) -> None:
|
def __init__(self, name : str, symbol : str, value : float) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -76,6 +84,10 @@ class Function():
|
||||||
self.value = value
|
self.value = value
|
||||||
self.default = 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):
|
class RectFunction(Function):
|
||||||
name = "Rectangular"
|
name = "Rectangular"
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
|
@ -88,6 +100,8 @@ class SincFunction(Function):
|
||||||
expr = sympy.sympify("sin(x * l)/ (x * l)")
|
expr = sympy.sympify("sin(x * l)/ (x * l)")
|
||||||
super().__init__(expr)
|
super().__init__(expr)
|
||||||
self.add_parameter(Function.Parameter("Scale Factor", "l", 2))
|
self.add_parameter(Function.Parameter("Scale Factor", "l", 2))
|
||||||
|
self.start_x = -np.pi
|
||||||
|
self.end_x = np.pi
|
||||||
|
|
||||||
class GaussianFunction(Function):
|
class GaussianFunction(Function):
|
||||||
name = "Gaussian"
|
name = "Gaussian"
|
||||||
|
|
Loading…
Reference in a new issue