API¶
jaxparrow.cyclogeostrophy
¶
CyclogeostrophyResult
¶
Bases: NamedTuple
Result of cyclogeostrophic velocity computation.
This NamedTuple provides named access to results, avoiding positional unpacking errors.
All fields except ucg and vcg are optional and depend on the
return_* flags passed to the computation function.
Attributes:
| Name | Type | Description |
|---|---|---|
ucg |
Float[Array, 'y x']
|
\(u\) component of cyclogeostrophic velocity, on the T grid |
vcg |
Float[Array, 'y x']
|
\(v\) component of cyclogeostrophic velocity, on the T grid |
ug |
Float[Array, 'y x'] | None
|
\(u\) component of geostrophic velocity, on the T grid (if |
vg |
Float[Array, 'y x'] | None
|
\(v\) component of geostrophic velocity, on the T grid (if |
losses |
Float[Array, n_it] | None
|
Cyclogeostrophic imbalance over iterations (if |
Source code in jaxparrow/cyclogeostrophy/_core.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
cyclogeostrophic_loss(ug, vg, ucg, vcg, lat_t=None, lon_t=None, lat_u=None, lon_u=None, lat_v=None, lon_v=None, land_mask=None, uv_on_t=True, is_grid_rectilinear=None)
¶
Computes the cyclogeostrophic imbalance loss (a scalar) from a geostrophic and a cyclogeostrophic velocity field.
The velocity fields can be provided either on the T grid (uv_on_t=True) or on the U/V grids (uv_on_t=False).
If provided, the lat_u, lon_u, lat_v, and lon_v are expected to follow the NEMO convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ug
|
Float[Array, 'y x']
|
\(u\) component of the geostrophic velocity field |
required |
vg
|
Float[Array, 'y x']
|
\(v\) component of the geostrophic velocity field |
required |
ucg
|
Float[Array, 'y x']
|
\(u\) component of the cyclogeostrophic velocity field |
required |
vcg
|
Float[Array, 'y x']
|
\(v\) component of the cyclogeostrophic velocity field |
required |
lat_t
|
Float[Array, 'y x']
|
Latitudes of the T grid. If Defaults to |
None
|
lon_t
|
Float[Array, 'y x']
|
Longitudes of the T grid. If Defaults to |
None
|
lat_u
|
Float[Array, 'y x']
|
Latitudes of the U grid. Defaults to |
None
|
lon_u
|
Float[Array, 'y x']
|
Longitudes of the U grid. Defaults to |
None
|
lat_v
|
Float[Array, 'y x']
|
Latitudes of the V grid. Defaults to |
None
|
lon_v
|
Float[Array, 'y x']
|
Longitudes of the V grid. Defaults to |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; |
None
|
uv_on_t
|
bool
|
If Defaults to |
True
|
is_grid_rectilinear
|
bool | None
|
If Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Float[Array, '']
|
Cyclogeostrophic imbalance loss |
Source code in jaxparrow/cyclogeostrophy/_core.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
cyclogeostrophic_imbalance(ug, vg, ucg, vcg, lat_t=None, lon_t=None, lat_u=None, lon_u=None, lat_v=None, lon_v=None, land_mask=None, uv_on_t=True, is_grid_rectilinear=None)
¶
Computes the cyclogeostrophic imbalance field from a geostrophic and a cyclogeostrophic velocity field.
The velocity fields can be provided either on the T grid (uv_on_t=True) or on the U/V grids (uv_on_t=False).
If provided, the lat_u, lon_u, lat_v, and lon_v are expected to follow the NEMO convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ug
|
Float[Array, 'y x']
|
\(u\) component of the geostrophic velocity field |
required |
vg
|
Float[Array, 'y x']
|
\(v\) component of the geostrophic velocity field |
required |
ucg
|
Float[Array, 'y x']
|
\(u\) component of the cyclogeostrophic velocity field |
required |
vcg
|
Float[Array, 'y x']
|
\(v\) component of the cyclogeostrophic velocity field |
required |
lat_t
|
Float[Array, 'y x']
|
Latitudes of the T grid. If Defaults to |
None
|
lon_t
|
Float[Array, 'y x']
|
Longitudes of the T grid. If Defaults to |
None
|
lat_u
|
Float[Array, 'y x']
|
Latitudes of the U grid. Defaults to |
None
|
lon_u
|
Float[Array, 'y x']
|
Longitudes of the U grid. Defaults to |
None
|
lat_v
|
Float[Array, 'y x']
|
Latitudes of the V grid. Defaults to |
None
|
lon_v
|
Float[Array, 'y x']
|
Longitudes of the V grid. Defaults to |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; |
None
|
uv_on_t
|
bool
|
If Defaults to |
True
|
is_grid_rectilinear
|
bool | None
|
If Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
u_imbalance |
Float[Array, 'y x']
|
\(u\) component of the cyclogeostrophic imbalance, on the T grid |
v_imbalance |
Float[Array, 'y x']
|
\(v\) component of the cyclogeostrophic imbalance, on the T grid |
Source code in jaxparrow/cyclogeostrophy/_core.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
fixed_point(lat_t, lon_t, ssh_t=None, ug_t=None, vg_t=None, land_mask=None, is_grid_rectilinear=None, rotate_to_geographic=True, return_geos=False, return_losses=False, n_it=20, res_eps=0.01)
¶
Computes the cyclogeostrophic Sea Surface Current (SSC) velocity field using the fixed-point method Penven et al. (2014).
There are two modes of operation:
-
SSH mode: Provide
lat_t,lon_t,ssh_t(and optionallyland_mask). Geostrophic velocities will be computed from SSH. -
Geostrophic mode: Provide
lat_t,lon_t,ug_t,vg_t(and optionallyland_mask). Geostrophic velocities are provided on the T grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_t
|
Float[Array, 'y x']
|
Latitude of the T grid |
required |
lon_t
|
Float[Array, 'y x']
|
Longitude of the T grid |
required |
ssh_t
|
Float[Array, 'y x']
|
SSH field (on the T grid) Defaults to |
None
|
ug_t
|
Float[Array, 'y x']
|
U component of geostrophic velocity on T grid Defaults to |
None
|
vg_t
|
Float[Array, 'y x']
|
V component of geostrophic velocity on T grid Defaults to |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; If not provided, inferred from Defaults to |
None
|
is_grid_rectilinear
|
bool
|
If Defaults to |
None
|
rotate_to_geographic
|
bool
|
If If using a rectilinear grid in geographic coordinates, set to Defaults to |
True
|
return_geos
|
bool
|
If Defaults to |
False
|
return_losses
|
bool
|
If Defaults to |
False
|
n_it
|
int
|
Maximum number of iterations. Defaults to |
20
|
res_eps
|
float
|
Residual tolerance of the iterative approach. When residuals are smaller, the iterative approach considers local convergence to cyclogeostrophy. Defaults to |
0.01
|
Returns:
| Type | Description |
|---|---|
CyclogeostrophyResult
|
Named tuple containing:
- |
Source code in jaxparrow/cyclogeostrophy/_fixed_point.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
gradient_wind(lat_t, lon_t, ssh_t=None, ug_t=None, vg_t=None, land_mask=None, is_grid_rectilinear=None, rotate_to_geographic=True, return_geos=False)
¶
Computes the cyclogeostrophic Sea Surface Current (SSC) velocity field using the gradient wind approximation.
There are two modes of operation:
-
SSH mode: Provide
lat_t,lon_t,ssh_t(and optionallyland_mask). Geostrophic velocities will be computed from SSH. -
Geostrophic mode: Provide
lat_t,lon_t,ug_t,vg_t(and optionallyland_mask). Geostrophic velocities are provided on the T grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_t
|
Float[Array, 'y x']
|
Latitude of the T grid |
required |
lon_t
|
Float[Array, 'y x']
|
Longitude of the T grid |
required |
ssh_t
|
Float[Array, 'y x']
|
SSH field (on the T grid) Defaults to |
None
|
ug_t
|
Float[Array, 'y x']
|
U component of geostrophic velocity on T grid Defaults to |
None
|
vg_t
|
Float[Array, 'y x']
|
V component of geostrophic velocity on T grid Defaults to |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; If not provided, inferred from Defaults to |
None
|
is_grid_rectilinear
|
bool
|
If Defaults to |
None
|
rotate_to_geographic
|
bool
|
If If using a rectilinear grid in geographic coordinates, set to Defaults to |
True
|
return_geos
|
bool
|
If Defaults to |
False
|
Returns:
| Type | Description |
|---|---|
CyclogeostrophyResult
|
Named tuple containing:
- |
Source code in jaxparrow/cyclogeostrophy/_gradient_wind.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
minimization_based(lat_t, lon_t, ssh_t=None, ug_t=None, vg_t=None, land_mask=None, is_grid_rectilinear=None, rotate_to_geographic=True, return_geos=False, return_losses=False, n_it=2000, optim='sgd', optim_kwargs=None, regularization=None, reg_kwargs=None)
¶
Computes the cyclogeostrophic Sea Surface Current (SSC) velocity field using our minimization-based method.
There are two modes of operation:
-
SSH mode: Provide
lat_t,lon_t,ssh_t(and optionallyland_mask). Geostrophic velocities will be computed from SSH. -
Geostrophic mode: Provide
lat_t,lon_t,ug_t,vg_t(and optionallyland_mask). Geostrophic velocities are provided on the T grid and will be interpolated to U/V grids internally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_t
|
Float[Array, 'y x']
|
Latitude of the T grid. |
required |
lon_t
|
Float[Array, 'y x']
|
Longitude of the T grid. |
required |
ssh_t
|
Float[Array, 'y x']
|
SSH field (on the T grid). Required if geostrophic velocities are not provided. |
None
|
ug_t
|
Float[Array, 'y x']
|
U component of geostrophic velocity on T grid. If provided with |
None
|
vg_t
|
Float[Array, 'y x']
|
V component of geostrophic velocity on T grid. If provided with |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; If not provided, inferred from Defaults to |
None
|
is_grid_rectilinear
|
bool
|
If Defaults to |
None
|
rotate_to_geographic
|
bool
|
If If using a rectilinear grid in geographic coordinates, set to Defaults to |
True
|
return_geos
|
bool
|
If Defaults to |
False
|
return_grids
|
bool
|
If Defaults to |
required |
return_losses
|
bool
|
If Defaults to |
False
|
n_it
|
int
|
Maximum number of iterations. Defaults to |
2000
|
optim
|
GradientTransformation | str
|
Optimizer to use.
Can be an Defaults to |
'sgd'
|
optim_kwargs
|
dict
|
Optimizer arguments (such as learning rate, etc...). If Defaults to |
None
|
regularization
|
Callable
|
A regularization function added to the cyclogeostrophic loss at every iteration. Its signature is defined as follows:
Must return a scalar. Defaults to |
None
|
reg_kwargs
|
dict
|
Additional keyword arguments passed to the Defaults to |
None
|
Returns:
| Type | Description |
|---|---|
CyclogeostrophyResult
|
Named tuple containing:
- |
Source code in jaxparrow/cyclogeostrophy/_minimization_based.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
jaxparrow.geostrophy
¶
geostrophy(ssh_t, lat_t, lon_t, land_mask=None, is_grid_rectilinear=None, rotate_to_geographic=True)
¶
Computes the geostrophic velocity field from a Sea Surface Height (SSH) field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ssh_t
|
Float[Array, 'y x']
|
SSH field (on the T grid) |
required |
lat_t
|
Float[Array, 'y x']
|
Latitudes of the T grid |
required |
lon_t
|
Float[Array, 'y x']
|
Longitudes of the T grid |
required |
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; Defaults to |
None
|
is_grid_rectilinear
|
bool
|
If Defaults to |
None
|
rotate_to_geographic
|
bool
|
If Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
ug_t |
Float[Array, 'y x']
|
\(u\) component of the geostrophic velocity field, on the T grid |
vg_t |
Float[Array, 'y x']
|
\(v\) component of the geostrophic velocity field, on the T grid |
Source code in jaxparrow/geostrophy.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
jaxparrow.utils
¶
Utility modules for jaxparrow computations.
geometry
¶
grid_spacing(lat, lon)
¶
Computes the physical spacing associated with one grid-index step, used to transform derivatives to physical coordinates.
It makes use of the distance-on-a-sphere formula with Taylor expansion approximations of cos and arccos
functions to avoid truncation issues.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
Float[Array, 'y x']
|
Latitude grid |
required |
lon
|
Float[Array, 'y x']
|
Longitude grid |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dx |
Float[Array, 'y x']
|
Spacing associated with one step in the x-index direction |
dy |
Float[Array, 'y x']
|
Spacing associated with one step in the y-index direction |
Source code in jaxparrow/utils/geometry.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
compute_grid_angle(lat, lon)
¶
Computes the local angles of both grid axes relative to geographic east.
For curvilinear grids (e.g., SWOT swaths, tripolar grids), the grid axes are not aligned with geographic east-west/north-south directions. This function computes the rotation angles needed to transform velocity components between grid coordinates and geographic coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
Float[Array, 'lat lon']
|
Latitude grid |
required |
lon
|
Float[Array, 'lat lon']
|
Longitude grid |
required |
Returns:
| Name | Type | Description |
|---|---|---|
angle_i |
Float[Array, 'lat lon']
|
Angle of the grid i-axis (axis=1) relative to geographic east, in radians, measured counterclockwise. Range is [-pi, pi]. |
angle_j |
Float[Array, 'lat lon']
|
Angle of the grid j-axis (axis=0) relative to geographic east, in radians, measured counterclockwise. Range is [-pi, pi]. |
Notes
Both angles are computed using the initial bearing formula between adjacent grid points.
For a standard rectilinear lat/lon grid: angle_i ≈ 0 (i-axis ≈ east) and
angle_j ≈ π/2 (j-axis ≈ north).
For grids where the axes are not orthogonal in the geographic sense, or where
angle_j - angle_i ≠ π/2 (e.g. non-orthogonal or left-handed grids), the rotation
functions jaxparrow.utils.geometry.rotate_to_geographic and jaxparrow.utils.geometry.rotate_to_grid
handle these cases correctly via the determinant det = sin(angle_j - angle_i).
Source code in jaxparrow/utils/geometry.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
rotate_to_geographic(u, v, angle_i, angle_j)
¶
Rotates velocity components from grid coordinates to geographic coordinates (eastward and northward components).
Uses the full 2-column rotation matrix defined by the actual directions of both grid axes, correctly handling any grid orientation including non-orthogonal or left-handed grids.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[Array, 'y x']
|
Velocity component along the grid i-axis (axis=1) |
required |
v
|
Float[Array, 'y x']
|
Velocity component along the grid j-axis (axis=0) |
required |
angle_i
|
Float[Array, 'y x']
|
Angle of the grid i-axis (axis=1) relative to geographic east, in radians
(counterclockwise positive). Typically obtained from |
required |
angle_j
|
Float[Array, 'y x']
|
Angle of the grid j-axis (axis=0) relative to geographic east, in radians
(counterclockwise positive). Typically obtained from |
required |
Returns:
| Name | Type | Description |
|---|---|---|
u_east |
Float[Array, 'y x']
|
Eastward velocity component |
v_north |
Float[Array, 'y x']
|
Northward velocity component |
Source code in jaxparrow/utils/geometry.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | |
rotate_to_grid(u, v, angle_i, angle_j)
¶
Rotates velocity components from geographic coordinates (eastward and northward) to grid coordinates.
This is the inverse of jaxparrow.utils.geometry.rotate_to_geographic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[Array, 'y x']
|
Eastward velocity component |
required |
v
|
Float[Array, 'y x']
|
Northward velocity component |
required |
angle_i
|
Float[Array, 'y x']
|
Angle of the grid i-axis (axis=1) relative to geographic east, in radians
(counterclockwise positive). Typically obtained from |
required |
angle_j
|
Float[Array, 'y x']
|
Angle of the grid j-axis (axis=0) relative to geographic east, in radians
(counterclockwise positive). Typically obtained from |
required |
Returns:
| Name | Type | Description |
|---|---|---|
u_grid |
Float[Array, 'y x']
|
Velocity component along the grid i-axis (axis=1) |
v_grid |
Float[Array, 'y x']
|
Velocity component along the grid j-axis (axis=0) |
Source code in jaxparrow/utils/geometry.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | |
coriolis_factor(lat)
¶
Computes the Coriolis factor from a latitude grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
Float[Array, 'y x']
|
Latitudes grid |
required |
Returns:
| Name | Type | Description |
|---|---|---|
cf |
Float[Array, 'y x']
|
Coriolis factor grid |
Source code in jaxparrow/utils/geometry.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
compute_uv_grids(lat_t, lon_t)
¶
Computes the U and V grids associated to a T grid following NEMO convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat_t
|
Float[Array, 'lat lon']
|
Latitudes of the T grid |
required |
lon_t
|
Float[Array, 'lat lon']
|
Longitudes of the T grid |
required |
Returns:
| Name | Type | Description |
|---|---|---|
lat_u |
Float[Array, 'lat lon']
|
Latitudes of the U grid |
lon_u |
Float[Array, 'lat lon']
|
Longitudes of the U grid |
lat_v |
Float[Array, 'lat lon']
|
Latitudes of the V grid |
lon_v |
Float[Array, 'lat lon']
|
Longitudes of the V grid |
Source code in jaxparrow/utils/geometry.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 | |
kinematics
¶
magnitude(u, v, land_mask=None, uv_on_t=True)
¶
Computes the magnitude (azimuthal velocity) of a 2d velocity field.
The velocity field can be provided either on the T grid (uv_on_t=True) or on the U/V grids (uv_on_t=False).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[Array, 'y x']
|
\(u\) component of the velocity field (on the U or T grid) |
required |
v
|
Float[Array, 'y x']
|
\(v\) component of the velocity field (on the V or T grid) |
required |
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; Defaults to |
None
|
uv_on_t
|
bool
|
If Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
magnitude |
Float[Array, 'y x']
|
Magnitude of the velocity field, on the T grid |
Source code in jaxparrow/utils/kinematics.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
kinetic_energy(u, v, land_mask=None, uv_on_t=True)
¶
Computes the Kinetic Energy (KE) of a velocity field.
The velocity field can be provided either on the T grid (uv_on_t=True) or on the U/V grids (uv_on_t=False).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[Array, 'y x']
|
\(u\) component of the velocity field (on the U grid) |
required |
v
|
Float[Array, 'y x']
|
\(v\) component of the velocity field (on the V grid) |
required |
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; Defaults to |
None
|
uv_on_t
|
bool
|
If Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
kinetic_energy |
Float[Array, 'y x']
|
The Kinetic Energy on the T grid |
Source code in jaxparrow/utils/kinematics.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
vorticity(u, v, lat_t=None, lon_t=None, lat_u=None, lon_u=None, lat_v=None, lon_v=None, land_mask=None, uv_on_t=True, normalize_by_coriolis=True)
¶
Computes the relative vorticity of a velocity field.
The velocity field can be provided either on the T grid (uv_on_t=True) or on the U/V grids (uv_on_t=False).
If provided, the lat_u, lon_u, lat_v, and lon_v are expected to follow the NEMO convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[Array, 'y x']
|
\(u\) component of the velocity field |
required |
v
|
Float[Array, 'y x']
|
\(v\) component of the velocity field |
required |
lat_t
|
Float[Array, 'y x']
|
Latitudes of the T grid. If Defaults to |
None
|
lon_t
|
Float[Array, 'y x']
|
Longitudes of the T grid. If Defaults to |
None
|
lat_u
|
Float[Array, 'y x']
|
Latitudes of the U grid. Defaults to |
None
|
lon_u
|
Float[Array, 'y x']
|
Longitudes of the U grid. Defaults to |
None
|
lat_v
|
Float[Array, 'y x']
|
Latitudes of the V grid. Defaults to |
None
|
lon_v
|
Float[Array, 'y x']
|
Longitudes of the V grid. Defaults to |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; |
None
|
uv_on_t
|
bool
|
If Defaults to |
True
|
normalize_by_coriolis
|
bool
|
If Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
vorticity |
Float[Array, 'y x']
|
The vorticity on the T grid, normalized by the Coriolis factor if |
Source code in jaxparrow/utils/kinematics.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 | |
strain_rate(u, v, lat_t=None, lon_t=None, lat_u=None, lon_u=None, lat_v=None, lon_v=None, land_mask=None, uv_on_t=True, normalize_by_coriolis=True)
¶
Computes the strain rate magnitude of a velocity field.
The velocity field can be provided either on the T grid (uv_on_t=True) or on the U/V grids (uv_on_t=False).
If provided, the lat_u, lon_u, lat_v, and lon_v are expected to follow the NEMO convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[Array, 'y x']
|
\(u\) component of the velocity field |
required |
v
|
Float[Array, 'y x']
|
\(v\) component of the velocity field |
required |
lat_t
|
Float[Array, 'y x']
|
Latitudes of the T grid.
Defaults to |
None
|
lon_t
|
Float[Array, 'y x']
|
Longitudes of the T grid.
Defaults to |
None
|
lat_u
|
Float[Array, 'y x']
|
Latitudes of the U grid.
Defaults to |
None
|
lon_u
|
Float[Array, 'y x']
|
Longitudes of the U grid.
Defaults to |
None
|
lat_v
|
Float[Array, 'y x']
|
Latitudes of the V grid.
Defaults to |
None
|
lon_v
|
Float[Array, 'y x']
|
Longitudes of the V grid.
Defaults to |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; |
None
|
uv_on_t
|
bool
|
If Defaults to |
True
|
normalize_by_coriolis
|
bool
|
If Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
strain_rate |
Float[Array, 'y x']
|
The strain rate magnitude on the T grid, normalized by the Coriolis factor if |
Source code in jaxparrow/utils/kinematics.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
radius_of_curvature(u, v, lat_t=None, lon_t=None, lat_u=None, lon_u=None, lat_v=None, lon_v=None, land_mask=None, uv_on_t=True)
¶
Computes the radius of curvature of a 2d velocity field.
The velocity field can be provided either on the T grid (uv_on_t=True) or on the U/V grids (uv_on_t=False).
If provided, the lat_u, lon_u, lat_v, and lon_v are expected to follow the NEMO convention.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Float[Array, 'y x']
|
\(u\) component of the velocity field |
required |
v
|
Float[Array, 'y x']
|
\(v\) component of the velocity field |
required |
lat_t
|
Float[Array, 'y x']
|
Latitudes of the T grid. If Defaults to |
None
|
lon_t
|
Float[Array, 'y x']
|
Longitudes of the T grid. If Defaults to |
None
|
lat_u
|
Float[Array, 'y x']
|
Latitudes of the U grid. Defaults to |
None
|
lon_u
|
Float[Array, 'y x']
|
Longitudes of the U grid. Defaults to |
None
|
lat_v
|
Float[Array, 'y x']
|
Latitudes of the V grid. Defaults to |
None
|
lon_v
|
Float[Array, 'y x']
|
Longitudes of the V grid. Defaults to |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask defining the marine area of the spatial domain; |
None
|
uv_on_t
|
bool
|
If Defaults to |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
rc |
Float[Array, 'y x']
|
The radius of curvature of the velocity field in meters, on the T grid |
Source code in jaxparrow/utils/kinematics.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
operators
¶
interpolation(field, axis, padding, land_mask=None)
¶
Interpolates the values of a field along a given axis (0 for lat/y, 1 for lon/x),
applying padding to the left (i.e. West if axis=1, South if axis=0) or
to the right (i.e. East if axis=1, North if axis=0) of the domain.
An open boundary condition is applied:
- At domain edges: the interpolated value equals the nearest interior value
- At land/NaN boundaries: if one of the two values is NaN, the valid value is used; if both are NaN, the result is NaN
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Float[Array, 'y x']
|
Field to interpolate |
required |
axis
|
Literal[0, 1]
|
Axis along which interpolation is performed |
required |
padding
|
Literal['left', 'right']
|
Padding direction.
For example, following NEMO convention,
interpolating from U to T points requires a |
required |
land_mask
|
Float[Array, 'y x']
|
Mask indicating the land domain where extrapolation should be applied.
Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
field |
Float[Array, 'y x']
|
Interpolated field |
Source code in jaxparrow/utils/operators.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
derivative(field, axis, land_mask=None)
¶
Differentiates a field, using finite differences, along a given axis (0 for lat/y, 1 for lon/'x'),
applying padding to the left (i.e. West if axis=1, South if axis=0) or
to the right (i.e. East if axis=1, North if axis=0) of the domain.
An open boundary condition is applied (zero second derivative):
- At domain edges: the boundary derivative equals the nearest interior derivative
- At land/NaN boundaries: if one of the two values is NaN, the derivative is filled with the immediate neighbor derivative; if both neighbors are NaN, the result is NaN
This is appropriate for domains with sharp physical boundaries (e.g., SWOT swaths) where the signal continues smoothly beyond the observation edge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Float[Array, 'y x']
|
Field to differentiate |
required |
axis
|
Literal[0, 1]
|
Axis along which interpolation is performed |
required |
land_mask
|
Float[Array, 'y x']
|
Mask indicating the land domain where extrapolation should be applied.
Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
df |
Float[Array, 'y x']
|
Differentiated field |
Source code in jaxparrow/utils/operators.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
horizontal_derivatives(field, lat=None, lon=None, dx=None, dy=None, land_mask=None)
¶
Computes the horizontal derivatives of a field defined on an orthogonal grid,
using finite differences and applying an open boundary condition at domain edges and land/NaN boundaries.
Horizontal derivatives are returned on the same grid as the input field, and in the grid coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Float[Array, 'y x']
|
Field for which to compute gradients |
required |
lat
|
Float[Array, 'y x']
|
Latitude grid corresponding to the field Defaults to |
None
|
lon
|
Float[Array, 'y x']
|
Longitude grid corresponding to the field Defaults to |
None
|
dx
|
Float[Array, 'y x']
|
Grid spacing in the eastward direction (i.e. along axis=1) Defaults to |
None
|
dy
|
Float[Array, 'y x']
|
Grid spacing in the northward direction (i.e. along axis=1) Defaults to |
None
|
land_mask
|
Float[Array, 'y x']
|
Mask indicating the land domain where extrapolation should be applied.
Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
df_e |
Float[Array, 'y x']
|
Eastward derivative of the field, on the same grid as the input field |
df_n |
Float[Array, 'y x']
|
Northward derivative of the field, on the same grid as the input field |
Source code in jaxparrow/utils/operators.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
sanitize
¶
sanitize_data(arr, fill_value, land_mask)
¶
Sanitizes data by replacing nan with fill_value and applying fill_value to the masked area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr
|
Float[Array, 'y x']
|
Array to sanitize |
required |
fill_value
|
float
|
Value to replace |
required |
land_mask
|
Float[jax.Array, "y x"]
|
Mask to apply, |
required |
Returns:
| Name | Type | Description |
|---|---|---|
arr |
Float[Array, 'y x']
|
Sanitized array |
Source code in jaxparrow/utils/sanitize.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
init_land_mask(field, land_mask=None)
¶
If land_mask is None, initializes it from the nan values of field.
If land_mask is not None, simply returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field
|
Float[Array, 'y x']
|
Field used to initialize the mask (if needed) |
required |
land_mask
|
Float[jax.Array, "y x"]
|
Mask to initialized (if Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
land_mask |
Float[Array, 'y x']
|
Initialized (if needed) land mask |
Source code in jaxparrow/utils/sanitize.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |