xarray.Dataset.integrate

xarray.Dataset.integrate#

Dataset.integrate(coord, datetime_unit=None)[source]#

Integrate along the given coordinate using the trapezoidal rule.

Note

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

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', None}, optional) – Specify the unit if datetime coordinate is used.

Returns

integrated (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> Size: 128B
Dimensions:  (x: 4)
Coordinates:
  * x        (x) int64 32B 0 1 2 3
    y        (x) int64 32B 1 7 3 5
Data variables:
    a        (x) int64 32B 5 5 6 6
    b        (x) int64 32B 1 2 1 0
>>> ds.integrate("x")
<xarray.Dataset> Size: 16B
Dimensions:  ()
Data variables:
    a        float64 8B 16.5
    b        float64 8B 3.5
>>> ds.integrate("y")
<xarray.Dataset> Size: 16B
Dimensions:  ()
Data variables:
    a        float64 8B 20.0
    b        float64 8B 4.0