transforms – Function Transforms
Transform module: function parsing and mathematical transforms (Fourier, Laplace, Taylor).
- transforms.parse_scalar_function(expression, parameters=None)[source]
Parse a scalar function expression f(x) into a vectorized callable.
The expression should use
xas the independent variable. Supports the same math functions as the ODE parser.- Parameters:
- Return type:
- Returns:
A vectorized callable
f(x)that accepts a numpy array and returns the evaluated values.- Raises:
EquationParseError – If the expression is invalid.
- class transforms.DisplayMode(*values)[source]
-
How to display the transform result.
- CURVE = 'Curve (f vs x)'
- COEFFICIENTS = 'Coefficients (aᵢ vs i)'
- class transforms.TransformKind(*values)[source]
-
Available transformation types.
- ORIGINAL = 'Original (f(x))'
- FOURIER = 'Fourier (FFT)'
- LAPLACE = 'Laplace (real axis)'
- TAYLOR = 'Taylor series'
- HILBERT = 'Hilbert (discrete)'
- Z_TRANSFORM = 'Z-transform (discrete)'
- transforms.apply_transform(func, kind, x_min, x_max, n_points=1024, *, taylor_order=5, taylor_center=None, laplace_s_min=0.1, laplace_s_max=10.0, laplace_n_points=200, fourier_amp_threshold=0.01, z_transform_amp_threshold=0.01, laplace_amp_threshold=0.01)[source]
Apply a transformation to a function and return (x, y) for plotting.
- Parameters:
func (
Callable[[ndarray],ndarray]) – Vectorized callable f(x) -> y.kind (
TransformKind) – Type of transformation.x_min (
float) – Lower bound of the original domain.x_max (
float) – Upper bound of the original domain.n_points (
int) – Number of sample points for Original/Fourier/Taylor.taylor_order (
int) – Order of Taylor expansion (for Taylor kind).taylor_center (
float|None) – Center point for Taylor (default: midpoint).laplace_s_min (
float) – Minimum s for Laplace (real axis).laplace_s_max (
float) – Maximum s for Laplace.laplace_n_points (
int) – Number of s values for Laplace.fourier_amp_threshold (
float) – Relative amplitude threshold (fraction of max) to trim Fourier spectrum at low and high frequencies. Frequencies with|F(ω)|below this fraction of the maximum are excluded from the displayed range. Default 0.01.z_transform_amp_threshold (
float) – Same as fourier_amp_threshold but for Z-transform magnitude spectrum. Default 0.01.laplace_amp_threshold (
float) – Same for Laplace: trim s range where|L(s)|is below this fraction of max. Default 0.01.
- Return type:
- Returns:
Tuple of (x_axis, y_values, x_label, y_label).
- Raises:
ValueError – If kind is not a known transform type.
- transforms.compute_function_samples(func, x_min, x_max, n_points=1024)[source]
Sample a function over a range.
- transforms.get_transform_coefficients(func, kind, x_min, x_max, n_points=512, *, taylor_order=5, taylor_center=None, laplace_s_min=0.1, laplace_s_max=10.0, laplace_n_points=50, fourier_amp_threshold=0.01, z_transform_amp_threshold=0.01, laplace_amp_threshold=0.01, hilbert_amp_threshold=0.01)[source]
Return coefficient representation with physical axis and metadata.
Uses frequency ω (or s for Laplace) as x-axis when meaningful for interpretation.
- Parameters:
func (
Callable[[ndarray],ndarray]) – Vectorized callable f(x) -> y.kind (
TransformKind) – Transform kind.x_min (
float) – Lower bound.x_max (
float) – Upper bound.n_points (
int) – Sample count.taylor_order (
int) – Taylor order.laplace_n_points (
int) – Number of s values for Laplace.fourier_amp_threshold (
float) – Amplitude threshold for Fourier coefficient trimming.z_transform_amp_threshold (
float) – Amplitude threshold for Z-transform coefficient trimming.laplace_amp_threshold (
float) – Amplitude threshold for Laplace coefficient trimming.hilbert_amp_threshold (
float) – Amplitude threshold for Hilbert coefficient trimming.laplace_s_min (float)
laplace_s_max (float)
- Return type:
- Returns:
Tuple of (x_axis, coefficients, x_label, y_label, metadata). metadata: dict with domain, n_points, and transform-specific params.
- Raises:
ValueError – If kind is not a known transform type.
transforms.function_parser
Safe parsing and evaluation of user-written scalar functions f(x).
- transforms.function_parser.parse_scalar_function(expression, parameters=None)[source]
Parse a scalar function expression f(x) into a vectorized callable.
The expression should use
xas the independent variable. Supports the same math functions as the ODE parser.- Parameters:
- Return type:
- Returns:
A vectorized callable
f(x)that accepts a numpy array and returns the evaluated values.- Raises:
EquationParseError – If the expression is invalid.
transforms.transform_engine
Mathematical transforms: Fourier, Laplace, Taylor series.
- class transforms.transform_engine.TransformKind(*values)[source]
-
Available transformation types.
- ORIGINAL = 'Original (f(x))'
- FOURIER = 'Fourier (FFT)'
- LAPLACE = 'Laplace (real axis)'
- TAYLOR = 'Taylor series'
- HILBERT = 'Hilbert (discrete)'
- Z_TRANSFORM = 'Z-transform (discrete)'
- class transforms.transform_engine.DisplayMode(*values)[source]
-
How to display the transform result.
- CURVE = 'Curve (f vs x)'
- COEFFICIENTS = 'Coefficients (aᵢ vs i)'
- transforms.transform_engine.compute_function_samples(func, x_min, x_max, n_points=1024)[source]
Sample a function over a range.
- transforms.transform_engine.apply_transform(func, kind, x_min, x_max, n_points=1024, *, taylor_order=5, taylor_center=None, laplace_s_min=0.1, laplace_s_max=10.0, laplace_n_points=200, fourier_amp_threshold=0.01, z_transform_amp_threshold=0.01, laplace_amp_threshold=0.01)[source]
Apply a transformation to a function and return (x, y) for plotting.
- Parameters:
func (
Callable[[ndarray],ndarray]) – Vectorized callable f(x) -> y.kind (
TransformKind) – Type of transformation.x_min (
float) – Lower bound of the original domain.x_max (
float) – Upper bound of the original domain.n_points (
int) – Number of sample points for Original/Fourier/Taylor.taylor_order (
int) – Order of Taylor expansion (for Taylor kind).taylor_center (
float|None) – Center point for Taylor (default: midpoint).laplace_s_min (
float) – Minimum s for Laplace (real axis).laplace_s_max (
float) – Maximum s for Laplace.laplace_n_points (
int) – Number of s values for Laplace.fourier_amp_threshold (
float) – Relative amplitude threshold (fraction of max) to trim Fourier spectrum at low and high frequencies. Frequencies with|F(ω)|below this fraction of the maximum are excluded from the displayed range. Default 0.01.z_transform_amp_threshold (
float) – Same as fourier_amp_threshold but for Z-transform magnitude spectrum. Default 0.01.laplace_amp_threshold (
float) – Same for Laplace: trim s range where|L(s)|is below this fraction of max. Default 0.01.
- Return type:
- Returns:
Tuple of (x_axis, y_values, x_label, y_label).
- Raises:
ValueError – If kind is not a known transform type.
- transforms.transform_engine.get_transform_coefficients(func, kind, x_min, x_max, n_points=512, *, taylor_order=5, taylor_center=None, laplace_s_min=0.1, laplace_s_max=10.0, laplace_n_points=50, fourier_amp_threshold=0.01, z_transform_amp_threshold=0.01, laplace_amp_threshold=0.01, hilbert_amp_threshold=0.01)[source]
Return coefficient representation with physical axis and metadata.
Uses frequency ω (or s for Laplace) as x-axis when meaningful for interpretation.
- Parameters:
func (
Callable[[ndarray],ndarray]) – Vectorized callable f(x) -> y.kind (
TransformKind) – Transform kind.x_min (
float) – Lower bound.x_max (
float) – Upper bound.n_points (
int) – Sample count.taylor_order (
int) – Taylor order.laplace_n_points (
int) – Number of s values for Laplace.fourier_amp_threshold (
float) – Amplitude threshold for Fourier coefficient trimming.z_transform_amp_threshold (
float) – Amplitude threshold for Z-transform coefficient trimming.laplace_amp_threshold (
float) – Amplitude threshold for Laplace coefficient trimming.hilbert_amp_threshold (
float) – Amplitude threshold for Hilbert coefficient trimming.laplace_s_min (float)
laplace_s_max (float)
- Return type:
- Returns:
Tuple of (x_axis, coefficients, x_label, y_label, metadata). metadata: dict with domain, n_points, and transform-specific params.
- Raises:
ValueError – If kind is not a known transform type.