This is development documentation. Some features are not available in the stable release. View stable documentation.

spectrochempy.simpson

simpson(dataset, *args, **kwargs)[source]

Integrate using the composite Simpson’s rule.

Wrapper of scipy.integrate.simpson.

Performs the integration along the last or given dimension.

If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson’s rule requires an even number of intervals. The former even keyword that selected how this was handled was deprecated in SciPy 1.11.0 and removed in SciPy 1.14.0, and is rejected here. Omitting it selects the current SciPy strategy, which for an even number of samples follows the former even='simpson' behaviour, so the result may differ from the former even='avg', even='first' and even='last' strategies.

Parameters:
  • dataset (NDDataset) – Dataset to be integrated.

  • **kwargs – Additional keywords parameters. See Other Parameters.

Returns:

NDDataset – Definite integral as approximated using the composite Simpson’s rule.

Notes

SpectroChemPy does not publish an integral for a slice whose contribution is incomplete. A masked point is a scientific exclusion: an output slice is integrated normally, and is not masked, when it was built without any masked point. A slice that used at least one masked point, including a fully masked slice, is instead published as a masked value with a raw numpy.nan.

No estimate of the missing area is made, so masked points are not replaced, removed or interpolated. The values hidden under the mask never reach the quadrature, so they cannot influence a result nor overflow it.

The result mask is always compatible with the result shape: a 1D input yields a zero-dimensional result with a scalar mask, and an unmasked input yields the canonical unmasked numpy.False_ mask.

Other Parameters:

dim (int or str, optional, default: "x") – Dimension along which to integrate. If an integer is provided, it is equivalent to the numpy.axis parameter for numpy.ndarray. The dims and axis keywords are accepted as equivalent synonyms of dim.

See also

trapezoid

Integrate using the composite simpson rule.

Example

>>> dataset = scp.read('irdata/nh4y-activation.spg')
>>> dataset[:,1250.:1800.].simpson()
NDDataset: [float64] a.u..cm^-1 (size: 55)