uxarray.UxDataArray.gradient#
- UxDataArray.gradient(scale_by_radius=True)#
Computes the gradient of this UxDataArray in the horizontal direction (i.e., along the unstructured grid dimension).
- Parameters:
scale_by_radius (bool, default=True) –
Whether to divide unit-sphere derivatives by
uxgrid.sphere_radius. WhenTrue(and the grid’ssphere_radiusis set correctly), the result carries physical units: [u units]/meter (e.g. result has units of 1/s if u represents velocity). WhenFalse(or if the grid’ssphere_radiusis set to 1.0), the result caries per-radian units: [u units]/radian. (e.g. result has units of (m/s)/rad if u represents velocity).CAUTION: this scaling does not account for any radius increases due to vertical levels; it simply divides by
uxgrid.sphere_radius.- Returns:
gradient – UxDataset with data_vars “zonal_gradient” and “meridional_gradient”. Units determined by
scale_by_radius.- 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()