uxarray.UxDataArray.gradient

uxarray.UxDataArray.gradient#

UxDataArray.gradient(scale_by_radius=True, **kwargs)#

Computes the gradient of a data variable.

Parameters:

scale_by_radius (bool, default=True) – Divide unit-sphere derivatives by uxgrid.sphere_radius so the result carries physical, per-meter units ([data units]/m). When False the result is left on the unit sphere with per-radian units ([data units]/rad). If True but the grid has no sphere_radius attribute, the result falls back to unit-sphere output and a UserWarning is emitted.

Returns:

gradient – Dataset containing the zonal and meridional components of the gradient. With the default scale_by_radius=True the components are in [data units]/m; with scale_by_radius=False they are in [data units]/rad.

Return type:

UxDataset

Notes

The Green-Gauss theorem is utilized, where a closed control volume around each cell is formed connecting centroids of the neighboring cells. The surface integral is approximated using the trapezoidal rule. The sum of the contributions is then normalized by the cell volume.

By default the raw unit-sphere (per-radian) gradient is divided by uxgrid.sphere_radius to yield physical per-meter values. For Earth (radius ~6.37e6 m) this scales magnitudes down by ~1/6.37e6 relative to the unit-sphere result.

Example

>>> uxds["var"].gradient()