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_radiusso the result carries physical, per-meter units ([data units]/m). WhenFalsethe result is left on the unit sphere with per-radian units ([data units]/rad). IfTruebut the grid has nosphere_radiusattribute, the result falls back to unit-sphere output and aUserWarningis emitted.- Returns:
gradient – Dataset containing the zonal and meridional components of the gradient. With the default
scale_by_radius=Truethe components are in[data units]/m; withscale_by_radius=Falsethey are in[data units]/rad.- Return type:
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_radiusto 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()