In order to cope with lack of NumPy on Jython, PShell includes Apache's Commons Math library (http://commons.apache.org/proper/commons-math/).
All functionality available in org.apache.commons.math3 can be accessed from the scripts. The direct access to this library is not straightforward in Python though. The module mathutils.py implements a facade to this library, in order to facilitate the use of its most common features.
The functions in mathutils.py are not built-in functions: the module must be imported such as:
from mathutils import *
The tutorial provides examples on the use of mathutils.
The main functions available are:
-
Derivative and interpolation:
- deriv: Calculate derivative of UnivariateFunction, array or list.
- integrate: Integrate UnivariateFunction, array or list.
- trapz: Integrate an array or list using the composite trapezoidal rule.
- interpolate: Interpolate data array or list to a UnivariateFunction.
-
Fitting and peak search:
- fit_polynomial: Fits data vector as a polynomial.
- fit_gaussian: Fits data vector as a gaussian.
- fit_gaussian_offset:Fits data vector as a gaussian with constant background.
- fit_gaussian_linear:Fits data vector as a gaussian with linear background.
- fit_harmonic: Fits data vector as an harmonic.
- estimate_peak_indexes: Estimation of peaks in an array by ordering local maxima according to given criteria.
- fit_gaussians: Fits data on multiple gaussians on the given peak indexes.
- calculate_peaks: Calculate peaks of a DifferentiableUnivariateFunction in a given range by finding the roots of the derivative.
-
Least squares problem:
- optimize_least_squares: Fits a parametric model to a set of observed values by minimizing a cost function.
-
Transforms:
- fft: Calculate the FFT of a vector, padding to the next power of 2 elements.
- ffti: Calculates the Inverse FFT of a vector, padding to the next power of 2 elements.
- get_real: Calculate real part of a complex vector.
- get_imag: Calculate imaginary part of a complex vector.
- get_modulus: Calculate modulus of a complex vector.
- get_phase: Calculate phase of a complex vector.
-
Tools:
- get_values: Computes list of values of a UnivariateFunction
Note: Check the PyDocs of the methods for parameters and return types:
help(function_name)