divergence#
- metpy.calc.divergence(u, v, *, dx=None, dy=None, x_dim=- 1, y_dim=- 2)#
Calculate the horizontal divergence of a vector.
- Parameters
u ((…, M, N)
xarray.DataArray
orpint.Quantity
) – x component of the vectorv ((…, M, N)
xarray.DataArray
orpint.Quantity
) – y component of the vectordx (
pint.Quantity
, optional) – The grid spacing(s) in the x-direction. If an array, there should be one item less than the size of u along the applicable axis. Optional ifxarray.DataArray
with latitude/longitude coordinates used as input. Keyword-only argument.dy (
pint.Quantity
, optional) – The grid spacing(s) in the y-direction. If an array, there should be one item less than the size of u along the applicable axis. Optional ifxarray.DataArray
with latitude/longitude coordinates used as input. Keyword-only argument.x_dim (int, optional) – Axis number of x dimension. Defaults to -1 (implying […, Y, X] order). Automatically parsed from input if using
xarray.DataArray
. Keyword-only argument.y_dim (int, optional) – Axis number of y dimension. Defaults to -2 (implying […, Y, X] order). Automatically parsed from input if using
xarray.DataArray
. Keyword-only argument.
- Returns
(…, M, N)
xarray.DataArray
orpint.Quantity
– The horizontal divergence
See also
Notes
This implements a numerical version of the typical equation of 2D divergence of a vector in Cartesian coordinates:
\[\nabla \cdot \vec{U} = \frac{\partial u}{\partial x} + \frac{\partial v}{\partial y}\]Changed in version 1.0: Changed signature from
(u, v, dx, dy)