qiu_signals.algebraic_signal
¶
Signals given by an algebraic expression evaluated on a physical axis.
Classes:
-
AlgebraicSignal–A signal given by an algebraic expression of the axis values.
-
PolynomialSignal–A monomial signal of the form f(x) = alpha * x^power.
-
QuadraticSignal–A quadratic signal of the form f(x) = alpha * x^2. Also called an intensity signal.
Attributes:
-
SignalFunctionType–A vectorized function, mapping an array of axis values to the signal values.
-
SampledSignal–A signal with sampled values on its axis, given directly or by an expression.
SignalFunctionType
module-attribute
¶
A vectorized function, mapping an array of axis values to the signal values.
It is called once with all values as an array, e.g. axis.values, so it must act
elementwise on arrays, e.g. with NumPy functions. The dtype of the array is not fixed,
so that functions annotated for a specific dtype are accepted. It may return a scalar
for constant signals, which is broadcast to the axis values.
SampledSignal
module-attribute
¶
SampledSignal = Signal | AlgebraicSignal
A signal with sampled values on its axis, given directly or by an expression.
Both kinds provide the axis and the sampled values data.
AlgebraicSignal
¶
AlgebraicSignal(axis: PhysicalAxis, function: SignalFunctionType)
Bases: ArithmeticOperators
A signal given by an algebraic expression of the axis values.
The expression is held as a vectorized function, mapping an array of axis values
to the array of signal values. It is either given directly, e.g. as a lambda or
a NumPy function, or compiled from a SymPy expression with from_sympy, which
also keeps the symbolic expression.
Algebraic signals support the arithmetic operators +, -, *, / and **
with scalars and with algebraic signals on an equal axis, composing their
functions, and their SymPy expressions if both operands have one. Combined with a
sampled Signal, they are sampled first, and the result is a sampled Signal.
Parameters:
-
axis(PhysicalAxis) –The axis the signal is evaluated on.
-
function(SignalFunctionType) –A function mapping an array of axis values to the array of signal values, e.g.
lambda x: np.exp(-(x**2)).
Methods:
-
from_sympy–Create a signal from a SymPy expression in one symbol.
-
to_signal–Return the signal sampled on its axis.
Attributes:
-
axis(PhysicalAxis) –The axis the signal is evaluated on.
-
function(SignalFunctionType) –The vectorized function mapping axis values to signal values.
-
expression(Expr | None) –The SymPy expression of the signal, if it was created from one.
-
symbol(Symbol | None) –The SymPy symbol standing for the axis values, if created from an expression.
-
data(NDArray[number]) –Return the signal evaluated on the axis values.
-
size(int) –Return the number of samples of the signal on its axis.
Source code in packages/qiu-signals/src/qiu_signals/algebraic_signal.py
59 60 61 62 63 64 65 66 67 68 69 70 | |
function
instance-attribute
¶
function: SignalFunctionType = function
The vectorized function mapping axis values to signal values.
expression
instance-attribute
¶
expression: Expr | None = None
The SymPy expression of the signal, if it was created from one.
symbol
instance-attribute
¶
symbol: Symbol | None = None
The SymPy symbol standing for the axis values, if created from an expression.
from_sympy
classmethod
¶
from_sympy(axis: PhysicalAxis, expression: Expr | str, symbol: Symbol | None = None) -> AlgebraicSignal
Create a signal from a SymPy expression in one symbol.
Requires SymPy, e.g. via the sympy extra of this package.
Parameters:
-
axis(PhysicalAxis) –The axis the signal is evaluated on.
-
expression(Expr | str) –The expression of the signal, or a string SymPy can parse.
-
symbol(Symbol | None, default:None) –The symbol standing for the axis values. Can be omitted if the expression has at most one free symbol.
Returns:
-
AlgebraicSignal–The signal, evaluating the expression with NumPy.
Raises:
-
ImportError–If SymPy is not installed.
-
TypeError–If the expression is not an algebraic SymPy expression.
-
ValueError–If the expression has free symbols other than
symbol, or, withsymbolomitted, more than one free symbol or a free symbol that is not a plain SymPy symbol.
Source code in packages/qiu-signals/src/qiu_signals/algebraic_signal.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
PolynomialSignal
¶
PolynomialSignal(axis: PhysicalAxis, alpha: float, power: int)
Bases: AlgebraicSignal
A monomial signal of the form f(x) = alpha * x^power.
Attributes:
-
alpha(float) –The coefficient of the monomial.
-
power(int) –The power of the monomial.
-
effective_alpha(float) –Return the coefficient of the monomial in terms of the integer indices.
Source code in packages/qiu-signals/src/qiu_signals/algebraic_signal.py
237 238 239 240 241 | |
QuadraticSignal
¶
QuadraticSignal(axis: PhysicalAxis, alpha: float)
Bases: PolynomialSignal
A quadratic signal of the form f(x) = alpha * x^2. Also called an intensity signal.
Source code in packages/qiu-signals/src/qiu_signals/algebraic_signal.py
268 269 270 | |