mirror of
https://github.com/nqrduck/nqrduck-spectrometer.git
synced 2024-12-22 16:27:48 +00:00
Added check for valid function expression.
This commit is contained in:
parent
18e25155a3
commit
a1bf3df72c
2 changed files with 30 additions and 5 deletions
|
@ -21,7 +21,7 @@ class Function:
|
||||||
def __init__(self, expr) -> None:
|
def __init__(self, expr) -> None:
|
||||||
self.parameters = []
|
self.parameters = []
|
||||||
self.expr = expr
|
self.expr = expr
|
||||||
self.resolution = 16/30.72e6
|
self.resolution = 1/30.72e6
|
||||||
self.start_x = -1
|
self.start_x = -1
|
||||||
self.end_x = 1
|
self.end_x = 1
|
||||||
|
|
||||||
|
@ -38,10 +38,6 @@ class Function:
|
||||||
t = np.linspace(self.start_x, self.end_x, 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:
|
||||||
|
@ -111,6 +107,22 @@ class Function:
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@property
|
||||||
|
def expr(self):
|
||||||
|
return self._expr
|
||||||
|
|
||||||
|
@expr.setter
|
||||||
|
def expr(self, expr):
|
||||||
|
if isinstance(expr, str):
|
||||||
|
try:
|
||||||
|
self._expr = sympy.sympify(expr)
|
||||||
|
except:
|
||||||
|
logger.error("Could not convert %s to a sympy expression", expr)
|
||||||
|
raise SyntaxError("Could not convert %s to a sympy expression" % expr)
|
||||||
|
elif isinstance(expr, sympy.Expr):
|
||||||
|
self._expr = expr
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -102,3 +102,16 @@ class PulseSequence:
|
||||||
obj.events.append(cls.Event.load_event(event_data, pulse_parameter_options))
|
obj.events.append(cls.Event.load_event(event_data, pulse_parameter_options))
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
class Variable:
|
||||||
|
""" A variable is a parameter that can be used within a pulsesequence as a placeholder.
|
||||||
|
For example the event duration a Variable with name a can be set. This variable can then be set to a list of different values.
|
||||||
|
On execution of the pulse sequence the event duration will be set to the first value in the list.
|
||||||
|
Then the pulse sequence will be executed with the second value of the list. This is repeated until the pulse sequence has
|
||||||
|
been executed with all values in the list."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
class VariableGroup:
|
||||||
|
""" Variables can be grouped together.
|
||||||
|
If we have groups a and b the pulse sequence will be executed for all combinations of variables in a and b."""
|
||||||
|
pass
|
Loading…
Reference in a new issue