cumulative_integrate
- UnitsAwareDataArray.cumulative_integrate(coord: Optional[Union[Hashable, Sequence[Hashable]]] = None, datetime_unit: Optional[str] = None) xarray.core.dataarray.DataArray
Integrate cumulatively along the given coordinate using the trapezoidal rule.
Note
This feature is limited to simple cartesian geometry, i.e. coord must be one dimensional.
The first entry of the cumulative integral is always 0, in order to keep the length of the dimension unchanged between input and output.
- Parameters
coord (hashable, or sequence of hashable) – Coordinate(s) used for the integration.
datetime_unit ({'Y', 'M', 'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', 'ps', 'fs', 'as'}, optional) – Specify the unit if a datetime coordinate is used.
- Returns
integrated
- Return type
DataArray
See also
Dataset.cumulative_integrate
scipy.integrate.cumulative_trapezoid
corresponding scipy function
Examples
>>> da = xr.DataArray( ... np.arange(12).reshape(4, 3), ... dims=["x", "y"], ... coords={"x": [0, 0.1, 1.1, 1.2]}, ... ) >>> da <xarray.DataArray (x: 4, y: 3)> array([[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8], [ 9, 10, 11]]) Coordinates: * x (x) float64 0.0 0.1 1.1 1.2 Dimensions without coordinates: y >>> >>> da.cumulative_integrate("x") <xarray.DataArray (x: 4, y: 3)> array([[0. , 0. , 0. ], [0.15, 0.25, 0.35], [4.65, 5.75, 6.85], [5.4 , 6.6 , 7.8 ]]) Coordinates: * x (x) float64 0.0 0.1 1.1 1.2 Dimensions without coordinates: y