xarray.Dataset.integrate

Dataset.integrate(coord, datetime_unit=None)

integrate the array with the trapezoidal rule.

Note

This feature is limited to simple cartesian geometry, i.e. coord must be one dimensional.

Parameters
  • coord (str, or sequence of str) – Coordinate(s) used for the integration.

  • datetime_unit ({"Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns", "ps", "fs", "as"}, optional) – Can be specify the unit if datetime coordinate is used.

Returns

integrated

Return type

Dataset

See also

DataArray.integrate

numpy.trapz

corresponding numpy function

Examples

>>> ds = xr.Dataset(
...     data_vars={"a": ("x", [5, 5, 6, 6]), "b": ("x", [1, 2, 1, 0])},
...     coords={"x": [0, 1, 2, 3], "y": ("x", [1, 7, 3, 5])},
... )
>>> ds
<xarray.Dataset>
Dimensions:  (x: 4)
Coordinates:
  * x        (x) int64 0 1 2 3
    y        (x) int64 1 7 3 5
Data variables:
    a        (x) int64 5 5 6 6
    b        (x) int64 1 2 1 0
>>> ds.integrate("x")
<xarray.Dataset>
Dimensions:  ()
Data variables:
    a        float64 16.5
    b        float64 3.5
>>> ds.integrate("y")
<xarray.Dataset>
Dimensions:  ()
Data variables:
    a        float64 20.0
    b        float64 4.0