lightcurvelynx.math_nodes.basic_math_node
Nodes that perform basic math operations that can be specified as strings.
The goal of this library is to save users from needing to create a bunch of small FunctionNodes to perform basic math.
Classes
A node that evaluates basic mathematical functions. |
Module Contents
- class BasicMathNode(expression, backend='numpy', node_label=None, **kwargs)[source]
Bases:
lightcurvelynx.base_models.FunctionNodeA node that evaluates basic mathematical functions.
The BasicMathNode wraps Python’s eval() function to sanitize the input string and thus prevent the execution of arbitrary code. It also allows the user to write the expression once and execute using math, numpy, or JAX. The names of the variables in the expression must match the input variables provided by kwargs.
Example:
my_node = BasicMathNode( "redshift + 10.0 * sin(phase)", redshift=host.redshift, phase=source.phase, )
- expression
The expression to evaluate.
- Type:
str
- backend
The math libary to use. This is auto-converted to one of (math, np, or jnp) depending on the input parameter.
- Type:
str
- Parameters:
expression (str) – The expression to evaluate.
backend (str) – The math libary to use. Must be one of: math, numpy, np, jax, or jnp.
node_label (str, optional) – An identifier (or name) for the current node.
**kwargs (dict, optional) – Any additional keyword arguments. Every variable in the expression must be included as a kwarg.
- __getstate__()[source]
We override the default pickling behavior to handle non-pickable attributes such as the backend_lib and to_array function.