Differentiate the array with the second order accurate central differences. .. note:: This feature is limited to simple cartesian geometry, i.e. coord must be one dimensional. Parameters ---------- coord : Hashable The coo
(
self,
coord: Hashable,
edge_order: Literal[1, 2] = 1,
datetime_unit: DatetimeUnitOptions = None,
)
| 5473 | return self._from_temp_dataset(ds) |
| 5474 | |
| 5475 | def differentiate( |
| 5476 | self, |
| 5477 | coord: Hashable, |
| 5478 | edge_order: Literal[1, 2] = 1, |
| 5479 | datetime_unit: DatetimeUnitOptions = None, |
| 5480 | ) -> Self: |
| 5481 | """Differentiate the array with the second order accurate central |
| 5482 | differences. |
| 5483 | |
| 5484 | .. note:: |
| 5485 | This feature is limited to simple cartesian geometry, i.e. coord |
| 5486 | must be one dimensional. |
| 5487 | |
| 5488 | Parameters |
| 5489 | ---------- |
| 5490 | coord : Hashable |
| 5491 | The coordinate to be used to compute the gradient. |
| 5492 | edge_order : {1, 2}, default: 1 |
| 5493 | N-th order accurate differences at the boundaries. |
| 5494 | datetime_unit : {"W", "D", "h", "m", "s", "ms", \ |
| 5495 | "us", "ns", "ps", "fs", "as", None}, optional |
| 5496 | Unit to compute gradient. Only valid for datetime coordinate. "Y" and "M" are not available as |
| 5497 | datetime_unit. |
| 5498 | |
| 5499 | Returns |
| 5500 | ------- |
| 5501 | differentiated: DataArray |
| 5502 | |
| 5503 | See Also |
| 5504 | -------- |
| 5505 | numpy.gradient: corresponding numpy function |
| 5506 | |
| 5507 | Examples |
| 5508 | -------- |
| 5509 | |
| 5510 | >>> da = xr.DataArray( |
| 5511 | ... np.arange(12).reshape(4, 3), |
| 5512 | ... dims=["x", "y"], |
| 5513 | ... coords={"x": [0, 0.1, 1.1, 1.2]}, |
| 5514 | ... ) |
| 5515 | >>> da |
| 5516 | <xarray.DataArray (x: 4, y: 3)> Size: 96B |
| 5517 | array([[ 0, 1, 2], |
| 5518 | [ 3, 4, 5], |
| 5519 | [ 6, 7, 8], |
| 5520 | [ 9, 10, 11]]) |
| 5521 | Coordinates: |
| 5522 | * x (x) float64 32B 0.0 0.1 1.1 1.2 |
| 5523 | Dimensions without coordinates: y |
| 5524 | >>> |
| 5525 | >>> da.differentiate("x") |
| 5526 | <xarray.DataArray (x: 4, y: 3)> Size: 96B |
| 5527 | array([[30. , 30. , 30. ], |
| 5528 | [27.54545455, 27.54545455, 27.54545455], |
| 5529 | [27.54545455, 27.54545455, 27.54545455], |
| 5530 | [30. , 30. , 30. ]]) |
| 5531 | Coordinates: |
| 5532 | * x (x) float64 32B 0.0 0.1 1.1 1.2 |