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
(
self,
coord: Hashable | Sequence[Hashable] = None,
datetime_unit: DatetimeUnitOptions = None,
)
| 5590 | return self._from_temp_dataset(ds) |
| 5591 | |
| 5592 | def cumulative_integrate( |
| 5593 | self, |
| 5594 | coord: Hashable | Sequence[Hashable] = None, |
| 5595 | datetime_unit: DatetimeUnitOptions = None, |
| 5596 | ) -> Self: |
| 5597 | """Integrate cumulatively along the given coordinate using the trapezoidal rule. |
| 5598 | |
| 5599 | .. note:: |
| 5600 | This feature is limited to simple cartesian geometry, i.e. coord |
| 5601 | must be one dimensional. |
| 5602 | |
| 5603 | The first entry of the cumulative integral is always 0, in order to keep the |
| 5604 | length of the dimension unchanged between input and output. |
| 5605 | |
| 5606 | Parameters |
| 5607 | ---------- |
| 5608 | coord : Hashable, or sequence of Hashable |
| 5609 | Coordinate(s) used for the integration. |
| 5610 | datetime_unit : {'W', 'D', 'h', 'm', 's', 'ms', 'us', 'ns', \ |
| 5611 | 'ps', 'fs', 'as', None}, optional |
| 5612 | Specify the unit if a datetime coordinate is used. |
| 5613 | |
| 5614 | Returns |
| 5615 | ------- |
| 5616 | integrated : DataArray |
| 5617 | |
| 5618 | See Also |
| 5619 | -------- |
| 5620 | Dataset.cumulative_integrate |
| 5621 | scipy.integrate.cumulative_trapezoid : corresponding scipy function |
| 5622 | |
| 5623 | Examples |
| 5624 | -------- |
| 5625 | |
| 5626 | >>> da = xr.DataArray( |
| 5627 | ... np.arange(12).reshape(4, 3), |
| 5628 | ... dims=["x", "y"], |
| 5629 | ... coords={"x": [0, 0.1, 1.1, 1.2]}, |
| 5630 | ... ) |
| 5631 | >>> da |
| 5632 | <xarray.DataArray (x: 4, y: 3)> Size: 96B |
| 5633 | array([[ 0, 1, 2], |
| 5634 | [ 3, 4, 5], |
| 5635 | [ 6, 7, 8], |
| 5636 | [ 9, 10, 11]]) |
| 5637 | Coordinates: |
| 5638 | * x (x) float64 32B 0.0 0.1 1.1 1.2 |
| 5639 | Dimensions without coordinates: y |
| 5640 | >>> |
| 5641 | >>> da.cumulative_integrate("x") |
| 5642 | <xarray.DataArray (x: 4, y: 3)> Size: 96B |
| 5643 | array([[0. , 0. , 0. ], |
| 5644 | [0.15, 0.25, 0.35], |
| 5645 | [4.65, 5.75, 6.85], |
| 5646 | [5.4 , 6.6 , 7.8 ]]) |
| 5647 | Coordinates: |
| 5648 | * x (x) float64 32B 0.0 0.1 1.1 1.2 |
| 5649 | Dimensions without coordinates: y |