Skip to content

Commit 9d2343c

Browse files
authored
Merge pull request #65 from kthyng/fix_geostrophic
Fixed uv_geostrophic
2 parents d4611a4 + 0a461c2 commit 9d2343c

File tree

11 files changed

+168
-31
lines changed

11 files changed

+168
-31
lines changed

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ API
88
:toctree: generated/
99
:recursive:
1010

11-
xroms.roms_dataset
11+
xroms
1212
derived
1313
interp
1414
roms_seawater

docs/calc.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,26 +394,26 @@ ds.xroms.vertical_shear
394394
ds.xroms.vort
395395
```
396396

397-
### Horizontal divergence
397+
### Horizontal convergence
398398

399-
Horizontal component of the currents divergence.
399+
Horizontal component of the currents convergence.
400400

401-
ds.xroms.div
401+
ds.xroms.convergence
402402

403-
xroms.divergence(ds.u, ds.v, xgrid)
403+
xroms.convergence(ds.u, ds.v, xgrid)
404404

405405
```{code-cell} ipython3
406-
ds.xroms.div
406+
ds.xroms.convergence
407407
```
408408

409-
### Normalized surface divergence
409+
### Normalized surface convergence
410410

411-
Horizontal component of the currents divergence at the surface, normalized by $f$. This is only available through the accessor.
411+
Horizontal component of the currents convergence at the surface, normalized by $f$. This is only available through the accessor.
412412

413-
ds.xroms.div_norm
413+
ds.xroms.convergence_norm
414414

415415
```{code-cell} ipython3
416-
ds.xroms.div_norm
416+
ds.xroms.convergence_norm
417417
```
418418

419419
### Ertel potential vorticity

docs/conf.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121
from importlib.metadata import version as imversion
2222

2323

24+
# to fix issue with xESMF
25+
# https://github.com/conda-forge/esmf-feedstock/issues/91#issuecomment-1387279692
26+
if "ESMFMKFILE" not in os.environ:
27+
# RTD doesn't activate the env, and esmpy depends on a env var set there
28+
# We assume the `os` package is in {ENV}/lib/pythonX.X/os.py
29+
# See conda-forge/esmf-feedstock#91 and readthedocs/readthedocs.org#4067
30+
os.environ["ESMFMKFILE"] = str(pathlib.Path(os.__file__).parent.parent / "esmf.mk")
31+
32+
2433
print("python exec:", sys.executable)
2534
print("sys.path:", sys.path)
2635
root = pathlib.Path(__file__).parent.parent.absolute()
@@ -32,7 +41,7 @@
3241
# -- Project information -----------------------------------------------------
3342

3443
project = "xroms"
35-
copyright = "2020-2023"
44+
copyright = "2020-2024"
3645
author = "Rob Hetland, Kristen Thyng, Veronica Ruiz Xomchuk"
3746

3847
release = imversion("xroms")

docs/whats_new.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# What's New
22

3+
## v0.6.0 (February 9, 2023)
4+
* fixed error in `derived.py`'s `uv_geostrophic` function after being pointed out by @ak11283
5+
* updated docs so mostly well-formatted and working
6+
37
## v0.5.3 (October 11, 2023)
48
* change to `roms_dataset()` so that input flag `include_3D_metrics` also controls if `ds["3d"] = True`.
59

xroms/accessor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def set_grid(self, xgrid):
7575
7676
Examples
7777
--------
78+
7879
>>> ds.xroms.set_grid(xgrid)
7980
"""
8081
self._xgrid = xgrid
@@ -100,6 +101,7 @@ def speed(self):
100101
101102
Examples
102103
--------
104+
103105
>>> ds.xroms.speed
104106
"""
105107

@@ -120,6 +122,7 @@ def KE(self):
120122
121123
Examples
122124
--------
125+
123126
>>> ds.xroms.KE
124127
"""
125128

@@ -140,6 +143,7 @@ def ug(self):
140143
141144
Examples
142145
--------
146+
143147
>>> ds.xroms.ug
144148
"""
145149

xroms/derived.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ def speed(u, v, xgrid, hboundary="extend", hfill_value=None):
2828
for moving to rho grid.
2929
From xgcm documentation:
3030
A flag indicating how to handle boundaries:
31+
3132
* None: Do not apply any boundary conditions. Raise an error if
3233
boundary conditions are required for the operation.
3334
* 'fill': Set values outside the array boundary to fill_value
3435
(i.e. a Neumann boundary condition.)
3536
* 'extend': Set values outside the array to the nearest array
3637
value. (i.e. a limited form of Dirichlet boundary condition.
38+
3739
hfill_value: float, optional
3840
Passed to `grid` method calls; horizontal boundary fill value
3941
selection for moving to rho grid.
@@ -122,19 +124,22 @@ def uv_geostrophic(zeta, f, xgrid, hboundary="extend", hfill_value=None, which="
122124
for moving f to rho grid.
123125
From xgcm documentation:
124126
A flag indicating how to handle boundaries:
127+
125128
* None: Do not apply any boundary conditions. Raise an error if
126129
boundary conditions are required for the operation.
127130
* 'fill': Set values outside the array boundary to fill_value
128131
(i.e. a Neumann boundary condition.)
129132
* 'extend': Set values outside the array to the nearest array
130133
value. (i.e. a limited form of Dirichlet boundary condition.
134+
131135
hfill_value: float, optional
132136
Passed to `grid` method calls; horizontal boundary selection
133137
for moving f to rho grid.
134138
From xgcm documentation:
135139
The value to use in the boundary condition with `boundary='fill'`.
136140
which: string, optional
137141
Which components of geostrophic velocity to return.
142+
138143
* 'both': return both components of hgrad
139144
* 'xi': return only xi-direction.
140145
* 'eta': return only eta-direction.
@@ -147,10 +152,16 @@ def uv_geostrophic(zeta, f, xgrid, hboundary="extend", hfill_value=None, which="
147152
148153
Notes
149154
-----
150-
vg = g * zeta_eta / (d eta * f) # on v grid
151-
ug = -g * zeta_xi / (d xi * f) # on u grid
155+
156+
ug = -g * zeta_eta / (d eta * f) # on u grid
157+
158+
vg = g * zeta_xi / (d xi * f) # on v grid
159+
152160
Translation to Python of Matlab copy of surf_geostr_vel of IRD Roms_Tools.
153161
162+
Good resourcefor more information:
163+
https://uw.pressbooks.pub/ocean285/chapter/geostrophic-balance/
164+
154165
Examples
155166
--------
156167
>>> xroms.uv_geostrophic(ds.zeta, ds.f, xgrid)
@@ -162,11 +173,13 @@ def uv_geostrophic(zeta, f, xgrid, hboundary="extend", hfill_value=None, which="
162173
if which in ["both", "xi"]:
163174

164175
# calculate derivatives of zeta
165-
dzetadxi = hgrad(zeta, xgrid, which="xi")
176+
dzetadeta = hgrad(zeta, xgrid, which="eta", hcoord="u")
166177

167178
# calculate geostrophic velocities
168179
ug = (
169-
-g * dzetadxi / to_u(f, xgrid, hboundary=hboundary, hfill_value=hfill_value)
180+
-g
181+
* dzetadeta
182+
/ to_u(f, xgrid, hboundary=hboundary, hfill_value=hfill_value)
170183
)
171184

172185
ug.attrs["name"] = "ug"
@@ -175,13 +188,12 @@ def uv_geostrophic(zeta, f, xgrid, hboundary="extend", hfill_value=None, which="
175188
ug.name = ug.attrs["name"]
176189

177190
if which in ["both", "eta"]:
191+
178192
# calculate derivatives of zeta
179-
dzetadeta = hgrad(zeta, xgrid, which="eta")
193+
dzetadxi = hgrad(zeta, xgrid, which="xi", hcoord="v")
180194

181195
# calculate geostrophic velocities
182-
vg = (
183-
g * dzetadeta / to_v(f, xgrid, hboundary=hboundary, hfill_value=hfill_value)
184-
)
196+
vg = g * dzetadxi / to_v(f, xgrid, hboundary=hboundary, hfill_value=hfill_value)
185197

186198
vg.attrs["name"] = "vg"
187199
vg.attrs["long_name"] = "geostrophic v velocity"
@@ -214,12 +226,14 @@ def EKE(ug, vg, xgrid, hboundary="extend", hfill_value=None):
214226
for moving to rho grid.
215227
From xgcm documentation:
216228
A flag indicating how to handle boundaries:
229+
217230
* None: Do not apply any boundary conditions. Raise an error if
218231
boundary conditions are required for the operation.
219232
* 'fill': Set values outside the array boundary to fill_value
220233
(i.e. a Neumann boundary condition.)
221234
* 'extend': Set values outside the array to the nearest array
222235
value. (i.e. a limited form of Dirichlet boundary condition.
236+
223237
hfill_value: float, optional
224238
Passed to `grid` method calls; horizontal boundary selection
225239
for moving to rho grid.
@@ -272,12 +286,14 @@ def dudz(u, xgrid, sboundary="extend", sfill_value=None):
272286
calculating z derivative.
273287
From xgcm documentation:
274288
A flag indicating how to handle boundaries:
289+
275290
* None: Do not apply any boundary conditions. Raise an error if
276291
boundary conditions are required for the operation.
277292
* 'fill': Set values outside the array boundary to fill_value
278293
(i.e. a Neumann boundary condition.)
279294
* 'extend': Set values outside the array to the nearest array
280295
value. (i.e. a limited form of Dirichlet boundary condition.
296+
281297
sfill_value: float, optional
282298
Passed to `grid` method calls; vertical boundary fill value
283299
associated with sboundary input.
@@ -321,12 +337,14 @@ def dvdz(v, xgrid, sboundary="extend", sfill_value=None):
321337
calculating z derivative.
322338
From xgcm documentation:
323339
A flag indicating how to handle boundaries:
340+
324341
* None: Do not apply any boundary conditions. Raise an error if
325342
boundary conditions are required for the operation.
326343
* 'fill': Set values outside the array boundary to fill_value
327344
(i.e. a Neumann boundary condition.)
328345
* 'extend': Set values outside the array to the nearest array
329346
value. (i.e. a limited form of Dirichlet boundary condition.
347+
330348
sfill_value: float, optional
331349
Passed to `grid` method calls; vertical boundary fill value
332350
associated with sboundary input.
@@ -372,12 +390,14 @@ def vertical_shear(dudz, dvdz, xgrid, hboundary="extend", hfill_value=None):
372390
for moving dudz and dvdz to rho grid.
373391
From xgcm documentation:
374392
A flag indicating how to handle boundaries:
393+
375394
* None: Do not apply any boundary conditions. Raise an error if
376395
boundary conditions are required for the operation.
377396
* 'fill': Set values outside the array boundary to fill_value
378397
(i.e. a Neumann boundary condition.)
379398
* 'extend': Set values outside the array to the nearest array
380399
value. (i.e. a limited form of Dirichlet boundary condition.
400+
381401
hfill_value: float, optional
382402
Passed to `grid` method calls; horizontal boundary selection
383403
for moving to rho grid.
@@ -439,12 +459,14 @@ def relative_vorticity(
439459
for calculating horizontal derivatives of u and v.
440460
From xgcm documentation:
441461
A flag indicating how to handle boundaries:
462+
442463
* None: Do not apply any boundary conditions. Raise an error if
443464
boundary conditions are required for the operation.
444465
* 'fill': Set values outside the array boundary to fill_value
445466
(i.e. a Neumann boundary condition.)
446467
* 'extend': Set values outside the array to the nearest array
447468
value. (i.e. a limited form of Dirichlet boundary condition.
469+
448470
hfill_value: float, optional
449471
Passed to `grid` method calls; horizontal boundary selection
450472
fill value.
@@ -455,12 +477,14 @@ def relative_vorticity(
455477
for calculating horizontal derivatives of u and v.
456478
From xgcm documentation:
457479
A flag indicating how to handle boundaries:
480+
458481
* None: Do not apply any boundary conditions. Raise an error if
459482
boundary conditions are required for the operation.
460483
* 'fill': Set values outside the array boundary to fill_value
461484
(i.e. a Neumann boundary condition.)
462485
* 'extend': Set values outside the array to the nearest array
463486
value. (i.e. a limited form of Dirichlet boundary condition.
487+
464488
sfill_value: float, optional
465489
Passed to `grid` method calls; vertical boundary selection
466490
fill value.
@@ -537,12 +561,14 @@ def convergence(
537561
for calculating horizontal derivatives of u and v.
538562
From xgcm documentation:
539563
A flag indicating how to handle boundaries:
564+
540565
* None: Do not apply any boundary conditions. Raise an error if
541566
boundary conditions are required for the operation.
542567
* 'fill': Set values outside the array boundary to fill_value
543568
(i.e. a Neumann boundary condition.)
544569
* 'extend': Set values outside the array to the nearest array
545570
value. (i.e. a limited form of Dirichlet boundary condition.
571+
546572
hfill_value: float, optional
547573
Passed to `grid` method calls; horizontal boundary selection
548574
fill value.
@@ -553,12 +579,14 @@ def convergence(
553579
for calculating horizontal derivatives of u and v.
554580
From xgcm documentation:
555581
A flag indicating how to handle boundaries:
582+
556583
* None: Do not apply any boundary conditions. Raise an error if
557584
boundary conditions are required for the operation.
558585
* 'fill': Set values outside the array boundary to fill_value
559586
(i.e. a Neumann boundary condition.)
560587
* 'extend': Set values outside the array to the nearest array
561588
value. (i.e. a limited form of Dirichlet boundary condition.
589+
562590
sfill_value: float, optional
563591
Passed to `grid` method calls; vertical boundary selection
564592
fill value.
@@ -660,12 +688,14 @@ def ertel(
660688
horizontal grid changes too.
661689
From xgcm documentation:
662690
A flag indicating how to handle boundaries:
691+
663692
* None: Do not apply any boundary conditions. Raise an error if
664693
boundary conditions are required for the operation.
665694
* 'fill': Set values outside the array boundary to fill_value
666695
(i.e. a Neumann boundary condition.)
667696
* 'extend': Set values outside the array to the nearest array
668697
value. (i.e. a limited form of Dirichlet boundary condition.
698+
669699
hfill_value: float, optional
670700
Passed to `grid` method calls; horizontal boundary selection
671701
fill value.
@@ -678,12 +708,14 @@ def ertel(
678708
all vertical grid changes too.
679709
From xgcm documentation:
680710
A flag indicating how to handle boundaries:
711+
681712
* None: Do not apply any boundary conditions. Raise an error if
682713
boundary conditions are required for the operation.
683714
* 'fill': Set values outside the array boundary to fill_value
684715
(i.e. a Neumann boundary condition.)
685716
* 'extend': Set values outside the array to the nearest array
686717
value. (i.e. a limited form of Dirichlet boundary condition.
718+
687719
sfill_value: float, optional
688720
Passed to `grid` method calls; vertical boundary selection
689721
fill value.

0 commit comments

Comments
 (0)