MCPcopy Index your code
hub / github.com/pydata/xarray / integrate

Method integrate

xarray/core/dataset.py:8492–8553  ·  view source on GitHub ↗

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 C

(
        self,
        coord: Hashable | Sequence[Hashable],
        datetime_unit: DatetimeUnitOptions = None,
    )

Source from the content-addressed store, hash-verified

8490 return self._replace(variables)
8491
8492 def integrate(
8493 self,
8494 coord: Hashable | Sequence[Hashable],
8495 datetime_unit: DatetimeUnitOptions = None,
8496 ) -> Self:
8497 """Integrate along the given coordinate using the trapezoidal rule.
8498
8499 .. note::
8500 This feature is limited to simple cartesian geometry, i.e. coord
8501 must be one dimensional.
8502
8503 Parameters
8504 ----------
8505 coord : hashable, or sequence of hashable
8506 Coordinate(s) used for the integration.
8507 datetime_unit : {'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \
8508 'ps', 'fs', 'as', None}, optional
8509 Specify the unit if datetime coordinate is used.
8510
8511 Returns
8512 -------
8513 integrated : Dataset
8514
8515 See Also
8516 --------
8517 DataArray.integrate
8518 numpy.trapz : corresponding numpy function
8519
8520 Examples
8521 --------
8522 >>> ds = xr.Dataset(
8523 ... data_vars={"a": ("x", [5, 5, 6, 6]), "b": ("x", [1, 2, 1, 0])},
8524 ... coords={"x": [0, 1, 2, 3], "y": ("x", [1, 7, 3, 5])},
8525 ... )
8526 >>> ds
8527 <xarray.Dataset> Size: 128B
8528 Dimensions: (x: 4)
8529 Coordinates:
8530 * x (x) int64 32B 0 1 2 3
8531 y (x) int64 32B 1 7 3 5
8532 Data variables:
8533 a (x) int64 32B 5 5 6 6
8534 b (x) int64 32B 1 2 1 0
8535 >>> ds.integrate("x")
8536 <xarray.Dataset> Size: 16B
8537 Dimensions: ()
8538 Data variables:
8539 a float64 8B 16.5
8540 b float64 8B 3.5
8541 >>> ds.integrate("y")
8542 <xarray.Dataset> Size: 16B
8543 Dimensions: ()
8544 Data variables:
8545 a float64 8B 20.0
8546 b float64 8B 4.0
8547 """
8548 if not isinstance(coord, list | tuple):
8549 coord = (coord,)

Callers 2

test_integrateFunction · 0.95
test_integrateMethod · 0.45

Calls 1

_integrate_oneMethod · 0.80

Tested by 2

test_integrateFunction · 0.76
test_integrateMethod · 0.36