Oceanography¶
Physical oceanography diagnostics on gridded fields. The Coriolis parameter \(f=2\Omega\sin\phi\) sets the rotation; geostrophic balance gives the surface velocity from sea-surface height \(\eta\):
Vorticity, strain, kinetic energy, the Okubo–Weiss parameter, and stratification (Brunt–Väisälä frequency, mixed-layer depth) follow from the velocity and density fields.
Cartesian / β-plane grids¶
By default every horizontal diagnostic works on a lon/lat grid in degrees
(dims=("lon", "lat"), geometry="spherical") and derives \(f\) from
latitude. Idealised model output on an \(f\)- or β-plane — x/y in metres,
no lon/lat — passes the dims, the geometry and an explicit Coriolis
parameter instead:
from xrops.ocn import GeostrophicVelocities, OkuboWeiss, relative_vorticity
cart = {"dims": ("x", "y"), "geometry": "cartesian"} # or "rectilinear"
zeta = relative_vorticity(ds, "u", "v", **cart)
ug = GeostrophicVelocities("eta", **cart, f=(1e-4, 1.6e-11))(ds)
ow = OkuboWeiss("u", "v", **cart)(ds)
f= accepts a scalar \(f_0\) (f-plane), an (f0, beta) tuple for the
β-plane \(f = f_0 + \beta\,(y - y_0)\) with \(y_0\) the centre of the y
coordinate, (f0, beta, y0) to pin \(y_0\), or a DataArray used as-is. It is
required on non-spherical grids, where there is no latitude to derive it
from. Fields must be collocated on one grid; destagger C-grid output before
calling these diagnostics.
Rotation & geostrophy¶
CoriolisNormalized
¶
Bases: Operator
Normalise a field by the Coriolis parameter f₀.
Divides variable by f (e.g. to form the Rossby number ζ/f).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the variable to normalise. |
required |
f0
|
float | None
|
Reference Coriolis parameter (s⁻¹). |
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Streamfunction
¶
Bases: Operator
Geostrophic stream function ψ = (g / f₀) · η from SSH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the sea-surface-height (η) variable. |
'ssh'
|
g
|
float | None
|
Gravitational acceleration (m s⁻²). |
None
|
f0
|
float | None
|
Reference Coriolis parameter (s⁻¹). |
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
GeostrophicVelocities
¶
GeostrophicVelocities(variable: str = 'ssh', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical', f: Coriolis = None)
Bases: Operator
Geostrophic velocities (u_g, v_g) from a height field.
Computes u_g = −(g/f) ∂η/∂y and v_g = (g/f) ∂η/∂x, on the
lon/lat sphere by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the sea-surface-height (η) variable. |
'ssh'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
f
|
Coriolis
|
Coriolis parameter. |
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with the geostrophic |
|
|
variables (m s⁻¹). |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
AgeostrophicVelocities
¶
AgeostrophicVelocities(variable: str = 'ssh', u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical', f: Coriolis = None)
Bases: Operator
Ageostrophic velocities (u_a, v_a) = (u, v) − u_g(η).
Subtracts the geostrophic velocities derived from variable (SSH)
from the total velocities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the sea-surface-height (η) variable. |
'ssh'
|
u
|
str
|
Name of the total eastward velocity variable. |
'u'
|
v
|
str
|
Name of the total northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
f
|
Coriolis
|
Coriolis parameter. |
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with |
|
|
variables (m s⁻¹). |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Vorticity & strain¶
RelativeVorticity
¶
RelativeVorticity(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: _UVGradOperator
Relative (vertical) vorticity ζ = ∂v/∂x − ∂u/∂y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
AbsoluteVorticity
¶
AbsoluteVorticity(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical', f: Coriolis = None)
Bases: _UVGradOperator
Absolute vorticity ζ_a = ζ + f (relative plus planetary).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
f
|
Coriolis
|
Coriolis parameter. |
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
ShearVorticity
¶
ShearVorticity(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: _UVGradOperator
Along-flow shear component of the relative vorticity.
The part of ζ due to cross-stream changes in flow speed (as opposed
to streamline curvature).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
CurvatureVorticity
¶
CurvatureVorticity(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: _UVGradOperator
Cross-flow curvature component of the relative vorticity.
The part of ζ due to streamline curvature; vort_shear and
vort_curv sum to the relative vorticity vort_r.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Divergence
¶
Divergence(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: _UVGradOperator
Horizontal divergence ∇·u = ∂u/∂x + ∂v/∂y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
ShearStrain
¶
ShearStrain(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: _UVGradOperator
Shear strain rate S_s = ∂v/∂x + ∂u/∂y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
TensorStrain
¶
TensorStrain(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: _UVGradOperator
Normal (tensor) strain rate S_n = ∂u/∂x − ∂v/∂y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
StrainMagnitude
¶
StrainMagnitude(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: _UVGradOperator
Total strain-rate magnitude √(S_n² + S_s²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
OkuboWeiss
¶
OkuboWeiss(u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: _UVGradOperator
Okubo–Weiss parameter W = S_n² + S_s² − ζ².
Negative W marks vorticity-dominated (eddy-core) regions; positive
W marks strain-dominated regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with an |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Enstrophy
¶
Bases: Operator
Enstrophy ½ ζ² from a relative-vorticity field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the (relative) vorticity variable to square. |
'vort_r'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with an |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
PotentialVorticityBarotropic
¶
PotentialVorticityBarotropic(height: str = 'h', u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical', f: Coriolis = None)
Bases: Operator
Single-layer barotropic potential vorticity (ζ + f) / h.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
str
|
Name of the layer-thickness (h) variable. |
'h'
|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
f
|
Coriolis
|
Coriolis parameter. |
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Energy & transport¶
KineticEnergy
¶
Bases: _UVOperator
Kinetic energy KE = ½ (u² + v²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
EddyKineticEnergy
¶
Bases: Operator
Eddy kinetic energy EKE = ½ (u'² + v'²) from velocity anomalies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_anom
|
str
|
Name of the eastward velocity-anomaly variable |
'u_anom'
|
v_anom
|
str
|
Name of the northward velocity-anomaly variable |
'v_anom'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with an |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
VelocityMagnitude
¶
Bases: Operator
Velocity magnitude |U| = √(u² + v² [+ w²]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
w
|
str | None
|
Name of the vertical velocity variable, or |
None
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
HorizontalVelocityMagnitude
¶
Bases: _UVOperator
Horizontal current speed √(u² + v²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Advection
¶
Advection(scalar: str, components: tuple[str, ...] = ('u', 'v'), dim: tuple[str, ...] = ('lon', 'lat'), *, geometry: Geometry = 'spherical')
Bases: Operator
Tracer advection −u·∇c, on the lon/lat sphere by default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalar
|
str
|
Name of the advected tracer variable |
required |
components
|
tuple[str, ...]
|
Names of the velocity components — |
('u', 'v')
|
dim
|
tuple[str, ...]
|
Spatial dimension names the gradient is taken over:
|
('lon', 'lat')
|
geometry
|
Geometry
|
Geometry of the horizontal pair — |
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
|
|
added. |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Frontogenesis
¶
Frontogenesis(scalar: str, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical')
Bases: Operator
Petterssen 2-D kinematic frontogenesis of a scalar.
The rate of change of the horizontal gradient magnitude of scalar
following the flow; positive values indicate front sharpening.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalar
|
str
|
Name of the tracer variable (e.g. temperature). |
required |
u
|
str
|
Name of the eastward velocity variable. |
'u'
|
v
|
str
|
Name of the northward velocity variable. |
'v'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Stratification¶
BruntVaisalaFrequency
¶
BruntVaisalaFrequency(density: str = 'rho', depth: str = 'depth', rho0: float = reference_density, g: float | None = None, positive: str = 'down')
Bases: Operator
Squared Brunt–Väisälä (buoyancy) frequency N² = −(g/ρ₀) ∂ρ/∂z.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
density
|
str
|
Name of the (potential) density variable |
'rho'
|
depth
|
str
|
Name of the vertical coordinate variable. |
'depth'
|
rho0
|
float
|
Reference density |
reference_density
|
g
|
float | None
|
Gravitational acceleration (m s⁻²). |
None
|
positive
|
str
|
Orientation of |
'down'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with an |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
MixedLayerDepth
¶
MixedLayerDepth(density: str = 'rho', depth: str = 'depth', reference_depth: float = 10.0, threshold: float = 0.03)
Bases: Operator
Mixed-layer depth via the de Boyer Montégut density threshold.
Finds the depth at which density first exceeds the reference_depth
value by threshold (kg m⁻³).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
density
|
str
|
Name of the (potential) density variable. |
'rho'
|
depth
|
str
|
Name of the vertical coordinate variable. |
'depth'
|
reference_depth
|
float
|
Near-surface reference depth (m) the threshold is measured from. |
10.0
|
threshold
|
float
|
Density increase defining the mixed-layer base (kg m⁻³). |
0.03
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with an |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
LapseRate
¶
Bases: Operator
Vertical lapse rate Γ = −∂T/∂z (z positive upward).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature
|
str
|
Name of the temperature variable. |
'T'
|
depth
|
str
|
Name of the vertical coordinate variable. |
'depth'
|
positive
|
str
|
Orientation of |
'down'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with a |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Sea-surface height¶
CalculateSSHAlongtrack
¶
CalculateSSHAlongtrack(variable: str = 'ssh', sla: str = 'sla_filtered', mdt: str = 'mdt', lwe: str | None = 'lwe')
Bases: Operator
Compose along-track SSH from its altimetry components.
Reconstructs sea-surface height as ssh = sla + mdt − lwe: filtered
sea-level anomaly plus the mean dynamic topography, minus an optional
long-wavelength-error correction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the output SSH variable to create. |
'ssh'
|
sla
|
str
|
Name of the (filtered) sea-level-anomaly variable. |
'sla_filtered'
|
mdt
|
str
|
Name of the mean-dynamic-topography variable. |
'mdt'
|
lwe
|
str | None
|
Name of the long-wavelength-error variable to subtract, or
|
'lwe'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with the composed |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Validation¶
ValidateSSH
¶
Bases: Operator
Attach canonical CF metadata to a sea-surface-height field.
Assigns the canonical SSH attributes (units, standard_name,
long_name) to variable via assign_attrs. No value checks
(finiteness, range, shape) are performed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
str
|
Name of the sea-surface-height variable to tag. |
'ssh'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
ValidateVelocity
¶
Bases: Operator
Attach canonical CF metadata to a horizontal velocity pair (u, v).
Assigns the canonical zonal / meridional velocity attributes
(units, standard_name, long_name) to both components via
assign_attrs. No value checks (finiteness, shape consistency) are
performed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
str
|
Name of the eastward (zonal) velocity variable. |
'u'
|
v
|
str
|
Name of the northward (meridional) velocity variable. |
'v'
|
Returns:
| Type | Description |
|---|---|
|
The input dataset with |
Source code in packages/xrtoolz-ops/src/xrops/ocn/operators.py
Functional primitives (Layer 0)¶
These pure functions back the operators above; each takes xr.DataArray/xr.Dataset and a dim: argument.
coriolis_parameter
¶
Coriolis parameter f = 2 Ω sin(φ) in s⁻¹.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
DataArray | float | ndarray
|
Latitude(s) in degrees. |
required |
Returns:
| Type | Description |
|---|---|
DataArray | float | ndarray
|
Coriolis parameter with the same shape as |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
coriolis_normalized
¶
Normalize a variable by the Coriolis parameter f₀.
Common for plotting Rossby numbers (ζ / f, σ / f).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset. |
required |
variable
|
str
|
Variable to normalize. |
required |
f0
|
float | None
|
Coriolis parameter. Defaults to the mean over |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
streamfunction
¶
streamfunction(ds: Dataset, variable: str = 'ssh', g: float | None = None, f0: float | None = None) -> Dataset
Stream function from sea-surface height.
Uses the linear geostrophic approximation ψ = (g / f₀) η, i.e.
η = (f₀ / g) ψ.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset containing |
required |
variable
|
str
|
Name of the SSH variable. |
'ssh'
|
g
|
float | None
|
Gravity in m/s². Defaults to :data: |
None
|
f0
|
float | None
|
Coriolis parameter in s⁻¹. Defaults to the mean over the
latitude coordinate of |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
geostrophic_velocities
¶
geostrophic_velocities(ds: Dataset, variable: str = 'ssh', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical', f: Coriolis = None) -> Dataset
Geostrophic u and v from a height field (SSH).
Applies the standard linear geostrophic balance::
u = -(g / f) ∂η/∂y
v = (g / f) ∂η/∂x
with ∂/∂x and ∂/∂y taken by :func:xrops.grad.partial under
geometry (the lon/lat sphere by default).
Do not pass a stream-function field here — applying the same
formula to ψ = (g/f) η would double the scaling and give
unit-inconsistent velocities. :func:streamfunction is provided as
a separate diagnostic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset containing the height |
required |
variable
|
str
|
Name of the SSH (height) variable, in metres. |
'ssh'
|
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
f
|
Coriolis
|
Coriolis parameter. |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with |
Example
A Gaussian SSH bump on a β-plane in metres::
x = y = np.linspace(-5e5, 5e5, 101)
eta = 0.5 * np.exp(-(x[None, :] ** 2 + y[:, None] ** 2) / 1e10)
ds = xr.Dataset({"eta": (("y", "x"), eta)}, coords={"x": x, "y": y})
geostrophic_velocities(
ds, "eta", dims=("x", "y"), geometry="cartesian", f=(1e-4, 1.6e-11)
)
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
ageostrophic_velocities
¶
ageostrophic_velocities(ds: Dataset, variable: str = 'ssh', u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical', f: Coriolis = None) -> Dataset
Ageostrophic velocity (u_a, v_a) = (u, v) − u_g(η).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset containing the SSH |
required |
variable
|
str
|
Name of the SSH (height) variable from which the geostrophic velocities are derived. |
'ssh'
|
u, v
|
Names of the total horizontal velocity components. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
f
|
Coriolis
|
Coriolis parameter. |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
relative_vorticity
¶
relative_vorticity(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Relative vorticity ζ = ∂v/∂x - ∂u/∂y.
On the default spherical geometry this is the flux form,
1/(R cos φ) (∂v/∂λ − ∂(u cos φ)/∂φ) (gridax.curl).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Example
Solid-body rotation u = −y, v = x on a Cartesian grid has
ζ = 2 everywhere::
x = y = np.linspace(0.0, 1e4, 11)
X, Y = np.meshgrid(x, y)
ds = xr.Dataset(
{"u": (("y", "x"), -Y), "v": (("y", "x"), X)},
coords={"x": x, "y": y},
)
relative_vorticity(ds, dims=("x", "y"), geometry="cartesian")
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
absolute_vorticity
¶
absolute_vorticity(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical', f: Coriolis = None) -> Dataset
Absolute vorticity η = ζ + f.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
f
|
Coriolis
|
Coriolis parameter. |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
shear_vorticity
¶
shear_vorticity(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Vertical shear vorticity component (along-flow).
From [Majumdar2024]_::
ζ_s = (v u ∂u/∂x + v² ∂v/∂x − u² ∂u/∂y − u v ∂v/∂y) / (u² + v²)
with the curvature terms of the velocity gradient on a sphere. The
relative vorticity decomposes as
ζ = shear_vorticity + curvature_vorticity, on a sphere to the
truncation of the flux form. The decomposition is undefined where the
wind vanishes — calm points (u = v = 0) are returned as 0
rather than NaN/Inf.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
curvature_vorticity
¶
curvature_vorticity(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Vertical curvature vorticity component (cross-flow).
From [Majumdar2024]_::
ζ_c = (u² ∂v/∂x − v² ∂u/∂y − v u ∂u/∂x + u v ∂v/∂y) / (u² + v²)
Calm points (u = v = 0) are returned as 0, matching the
convention in :func:shear_vorticity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
divergence
¶
divergence(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Horizontal divergence ∂u/∂x + ∂v/∂y.
On the default spherical geometry this is the flux form,
1/(R cos φ) (∂u/∂λ + ∂(v cos φ)/∂φ) (gridax.divergence).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
shear_strain
¶
shear_strain(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Shear strain Sₛ = ∂v/∂x + ∂u/∂y.
On the default spherical geometry, with derivatives along arc length,
u tan φ / R is added: a rotation of the sphere has no strain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
tensor_strain
¶
tensor_strain(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Normal / tensor strain Sₙ = ∂u/∂x - ∂v/∂y.
On the default spherical geometry, with derivatives along arc length,
v tan φ / R is subtracted: a rotation of the sphere has no strain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
strain_magnitude
¶
strain_magnitude(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Total strain magnitude sqrt(Sₙ² + Sₛ²).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
okubo_weiss
¶
okubo_weiss(ds: Dataset, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Okubo–Weiss parameter Sₙ² + Sₛ² − ζ².
Positive in strain-dominated regions, negative in vortical regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity components. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
enstrophy
¶
Enstrophy 0.5 ζ².
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
potential_vorticity_barotropic
¶
potential_vorticity_barotropic(ds: Dataset, height: str = 'h', u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical', f: Coriolis = None) -> Dataset
Single-layer barotropic potential vorticity (ζ + f) / h.
For a shallow-water / single-layer model h is the layer
thickness; for atmospheric height-coordinate use it is the
geopotential height of the layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with |
required |
height
|
str
|
Variable name of the layer thickness / height. |
'h'
|
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
f
|
Coriolis
|
Coriolis parameter. |
None
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
kinetic_energy
¶
Kinetic energy 0.5 (u² + v²).
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
eddy_kinetic_energy
¶
Eddy kinetic energy EKE = ½ (u'² + v'²).
The caller supplies anomaly fields (typically a Reynolds
decomposition: u' = u − ⟨u⟩). Choosing the temporal/spatial mean
is a science decision left to the caller; we just compute the
quadratic combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the velocity anomaly fields. |
required |
u_anom, v_anom
|
Variable names of the anomalies. |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
velocity_magnitude
¶
Velocity magnitude |U|.
2-D sqrt(u² + v²) if w is None; otherwise the full
3-D sqrt(u² + v² + w²).
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
horizontal_velocity_magnitude
¶
Horizontal velocity magnitude sqrt(u² + v²).
Equivalent to :func:velocity_magnitude with w=None; provided
under the oceanspy-style name for callers that prefer the explicit
horizontal-only form.
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
advection
¶
advection(ds: Dataset, scalar: str, components: tuple[str, ...] = ('u', 'v'), dims: tuple[str, ...] = ('lon', 'lat'), *, geometry: Geometry = 'spherical') -> Dataset
Tracer advection −u·∇c, on the lon/lat sphere by default.
Sign convention follows :func:metpy.calc.advection: a positive
value means the tracer is being increased at that point by the flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset containing |
required |
scalar
|
str
|
Name of the advected scalar field (e.g. |
required |
components
|
tuple[str, ...]
|
Wind/current component variable names paired with
|
('u', 'v')
|
dims
|
tuple[str, ...]
|
Two horizontal coordinate names, optionally followed by a
vertical coordinate name. Under the default spherical
geometry the horizontal pair must be |
('lon', 'lat')
|
geometry
|
Geometry
|
Geometry of the horizontal pair — |
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 | |
frontogenesis
¶
frontogenesis(ds: Dataset, scalar: str, u: str = 'u', v: str = 'v', *, dims: tuple[str, str] = ('lon', 'lat'), geometry: Geometry = 'spherical') -> Dataset
Petterssen 2-D kinematic frontogenesis, on the lon/lat sphere by default.
Implements the form from [Bluestein1993]_ pp. 248–253::
F = ½ |∇c| [D cos(2β) − δ]
where c is the scalar (potential temperature in atmospheric use,
or any other density-correlated tracer such as SST in oceanography),
D is the total deformation, β is the angle between the axis
of dilatation and the isentropes, and δ is the divergence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with the scalar and the velocity components. |
required |
scalar
|
str
|
Name of the scalar field (e.g. |
required |
u, v
|
Velocity component names. |
required | |
dims
|
tuple[str, str]
|
|
('lon', 'lat')
|
geometry
|
Geometry
|
|
'spherical'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
brunt_vaisala_frequency
¶
brunt_vaisala_frequency(ds: Dataset, density: str = 'rho', depth: str = 'depth', rho0: float = reference_density, g: float | None = None, positive: str = 'down') -> Dataset
Squared Brunt–Väisälä (buoyancy) frequency.
Defined as N² = −(g/ρ₀) ∂ρ/∂z with z positive upward.
In a stable column N² > 0. We return the same sign convention
independent of how the input vertical coordinate is oriented;
set positive to match the dataset.
The derivative is exact for a quadratic at an inner level, however
uneven the levels, and one-sided at the two ends
(diagnostix.columns.buoyancy_frequency_squared).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with a |
required |
density
|
str
|
In-situ or potential density variable (kg m⁻³). |
'rho'
|
depth
|
str
|
Name of the vertical coordinate (metres). |
'depth'
|
rho0
|
float
|
Reference density (kg m⁻³). Defaults to 1025. |
reference_density
|
g
|
float | None
|
Gravity (m s⁻²). Defaults to :data: |
None
|
positive
|
str
|
Either |
'down'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
mixed_layer_depth
¶
mixed_layer_depth(ds: Dataset, density: str = 'rho', depth: str = 'depth', reference_depth: float = 10.0, threshold: float = 0.03) -> Dataset
Mixed-layer depth via the de Boyer Montégut density threshold.
Implements the criterion of [deBoyerMontegut2004]_::
MLD = first depth z below z_ref where ρ(z) − ρ(z_ref) = Δρ
with z_ref = 10 m and Δρ = 0.03 kg/m³ as the standard
defaults, and ρ linear between the levels, at z_ref too
(diagnostix.columns.mixed_layer_depth).
A column where the criterion is never met (mixed to its bottom) gives the deepest depth with data, and one without data gives NaN. A level without data is left out of its column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with a |
required |
density
|
str
|
Density variable name. |
'rho'
|
depth
|
str
|
Vertical coordinate name. |
'depth'
|
reference_depth
|
float
|
Depth at which |
10.0
|
threshold
|
float
|
Density jump used to mark the base of the mixed layer (kg m⁻³). |
0.03
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Dataset
|
vertical coordinate. |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
lapse_rate
¶
lapse_rate(ds: Dataset, temperature: str = 'T', depth: str = 'depth', positive: str = 'down') -> Dataset
Vertical lapse rate Γ = −∂T/∂z (z positive upward).
The sign convention matches atmospheric usage: a column with
temperature decreasing upward has a positive lapse rate. We flip
the sign automatically when positive="down" (oceanographic
depth convention) so the returned values still follow the
upward-z definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with a temperature (or potential-temperature) variable on a vertical coordinate. |
required |
temperature
|
str
|
Variable name (e.g. |
'T'
|
depth
|
str
|
Vertical coordinate name. |
'depth'
|
positive
|
str
|
|
'down'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
density_from_ts
¶
density_from_ts(ds: Dataset, *, salinity: str = 'so', temperature: str = 'thetao', pressure: str | float | DataArray = 0.0, lon: str = 'lon', lat: str = 'lat', eos: str = 'teos10') -> Dataset
In-situ seawater density via TEOS-10 (lazy gsw import).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset with practical salinity |
required |
salinity, temperature
|
Variable names. |
required | |
pressure
|
str | float | DataArray
|
Sea pressure in dbar — either a variable name in
|
0.0
|
lon, lat
|
Coordinate names used by |
required | |
eos
|
str
|
|
'teos10'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with a single variable |
Raises:
| Type | Description |
|---|---|
ImportError
|
If :mod: |
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/kinematics.py
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 | |
calculate_ssh_alongtrack
¶
calculate_ssh_alongtrack(ds: Dataset, variable: str = 'ssh', sla: str = 'sla_filtered', mdt: str = 'mdt', lwe: str | None = 'lwe') -> Dataset
Compose along-track SSH from SLA + MDT (- LWE, optional).
Equivalent altimetry-convention formula:
ssh = sla + mdt - lwe (when lwe is given)
ssh = sla + mdt (when lwe is None)
Upstream sla_to_ssh convention (no LWE correction) is reproduced by
passing lwe=None::
calculate_ssh_alongtrack(ds, sla="sla", mdt="mdt", lwe=None)
When MDT lives in a separate file it must first be regridded onto the SLA grid before the datasets can be merged. The canonical pattern is::
from xrops.interpolate import regrid_like
from xrops.ocn import calculate_ssh_alongtrack
ds_mdt_on_sla = regrid_like(ds_mdt, ds_sla, dims=("lat", "lon"))
ds = ds_sla.assign(mdt=ds_mdt_on_sla["mdt"])
ds = calculate_ssh_alongtrack(ds, sla="sla", mdt="mdt", lwe=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
Dataset containing the |
required |
variable
|
str
|
Name under which to store the SSH output. |
'ssh'
|
sla
|
str
|
Sea-level anomaly variable name. |
'sla_filtered'
|
mdt
|
str
|
Mean dynamic topography variable name. |
'mdt'
|
lwe
|
str | None
|
Land-water equivalent correction variable name. Pass |
'lwe'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
|
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/ssh.py
calculate_ssh_unfiltered
¶
calculate_ssh_unfiltered(ds: Dataset, variable: str = 'ssh', sla: str = 'sla_unfiltered', mdt: str = 'mdt', lwe: str | None = 'lwe') -> Dataset
Same as :func:calculate_ssh_alongtrack but from the unfiltered SLA.
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/ssh.py
validate_ssh
¶
Attach CF-style attrs to an SSH variable.
Source code in packages/xrtoolz-ops/src/xrops/ocn/_src/validation.py
validate_velocity
¶
Attach CF-style attrs to zonal / meridional velocity variables.