synthesizer.utils.integrate¶
A module containing integration helper functions.
This module contains functions that help with numerical integration. These functions wrap C extensions and abstract away boilerplate code (i.e. deciding which integration method to use, etc.).
Example
integrate_last_axis(xs, ys, nthreads=1, method=”trapz”)
Functions
- synthesizer.utils.integrate.integrate_last_axis(xs, ys, nthreads=1, method='trapz')[source]¶
Integrate the last axis of an N-dimensional array.
- Parameters:
xs (array-like) – The x-values to integrate over.
ys (array-like) – The y-values to integrate.
nthreads (int) – The number of threads to use for the integration. If -1, all available threads will be used.
method (str) – The integration method to use. Options are ‘trapz’ or ‘simps’.
- Returns:
The result of the integration.
- Return type:
array-like
- Raises:
InconsistentArguments – If an invalid method is passed.
- synthesizer.utils.integrate.integrate_weighted_last_axis(xs, ys, weights, nthreads=1, method='trapz')[source]¶
Compute a weighted average over the final axis of an ND array.
- This computes:
integral(ys * weights, xs) / integral(weights, xs)
in a single C-extension pass over ys.
- Parameters:
xs (array-like) – The x-values to integrate over.
ys (array-like) – The y-values to integrate over the final axis.
weights (array-like) – 1D weights defined over xs.
nthreads (int) – Number of threads to use. If -1, all available threads are used.
method (str) – Integration method: ‘trapz’ or ‘simps’.
- Returns:
Weighted average over the final axis.
- Return type:
array-like
- Raises:
InconsistentArguments – If an invalid method is passed.