Skip to content

Commit 5943840

Browse files
authored
Merge pull request #38 from andrewdelman/geos_bal_tutorial
Geostrophic balance tutorial
2 parents 67f1a8a + c5896c0 commit 5943840

7 files changed

Lines changed: 6668 additions & 221 deletions

File tree

ECCO-ACCESS/Downloading_ECCO_datasets_from_PODAAC/Tutorial_Python3_Jupyter_Notebook_Downloading_ECCO_Datasets_from_PODAAC.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@
925925
"\n",
926926
"[**ecco_download** module](../../ECCO-ACCESS/Downloading_ECCO_datasets_from_PODAAC/ecco_download.py)\n",
927927
"\n",
928-
"You can save this file either in the same directory where you store the tutorial notebooks, or a different directory that you then add to your path using sys.path.append. The syntax for using this module will be discussed in the next tutorial (Geostrophic Balance)."
928+
"You can save this file either in the same directory where you store the tutorial notebooks, or a different directory that you then add to your path using sys.path.append. You can see the syntax of how the module is used in upcoming tutorials."
929929
]
930930
}
931931
],

Intro_to_PO_Tutorials/Geostrophic_balance.ipynb

Lines changed: 6580 additions & 0 deletions
Large diffs are not rendered by default.

Intro_to_PO_Tutorials/ecco_download.py

Lines changed: 0 additions & 220 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../ECCO-ACCESS/Downloading_ECCO_datasets_from_PODAAC/ecco_download.py

Intro_to_PO_Tutorials/geos_vel.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
def geos_vel_compute(dens_press_filename,grid_filename="~/Downloads/ECCO_V4r4_PODAAC/ECCO_L4_GEOMETRY_LLC0090GRID_V4R4/GRID_GEOMETRY_ECCO_V4r4_native_llc0090.nc",fc_filename="llc_13tile_fc.txt"):
2+
"""
3+
This routine computes geostrophic velocities from an input netCDF file containing ECCO v4r4 density and pressure anomalies on the native llc90 grid.
4+
5+
Parameters
6+
----------
7+
dens_press_filename: the name (including path if not in current directory) of the netCDF file containing the density and pressure anomalies
8+
9+
grid_filename: the name (including path if not in current directory) of the netCDF file containing the latitudes ('YC') and grid parameters ('dxC','dyC') needed to compute horizontal derivatives
10+
11+
fc_filename: text file containing a Python dictionary specifying the tile/face connections in the ECCO llc90 grid
12+
"""
13+
14+
import numpy as np
15+
import xarray as xr
16+
import json
17+
import xgcm
18+
19+
# load file into workspace
20+
ds_denspress = xr.open_dataset(dens_press_filename, data_vars='minimal',\
21+
coords='minimal', compat='override')
22+
23+
densanom = ds_denspress.RHOAnoma
24+
25+
rhoConst = 1029.
26+
dens = rhoConst + densanom
27+
28+
pressanom = ds_denspress.PHIHYDcR
29+
30+
31+
# load grid parameters file
32+
ds_grid = xr.open_dataset(grid_filename)
33+
34+
35+
# load face_connections dictionary
36+
37+
# read in as string
38+
with open(fc_filename) as fc:
39+
data = fc.read()
40+
# convert string to dictionary
41+
face_connections = json.loads(data)
42+
43+
44+
# create xgcm Grid object
45+
grid = xgcm.Grid(ds_grid,periodic=False,face_connections=face_connections)
46+
47+
# compute derivatives of pressure in x and y
48+
d_press_dx = (grid.diff(rhoConst*pressanom,axis="X",boundary='extend'))/ds_grid.dxC
49+
d_press_dy = (grid.diff(rhoConst*pressanom,axis="Y",boundary='extend'))/ds_grid.dyC
50+
51+
# interpolate (vector) gradient values to center of grid cells
52+
press_grads_interp = grid.interp_2d_vector({'X':d_press_dx,'Y':d_press_dy},boundary='extend')
53+
dp_dx = press_grads_interp['X']
54+
dp_dy = press_grads_interp['Y']
55+
56+
# compute f from latitude of grid cell centers
57+
lat = ds_grid.YC
58+
Omega = (2*np.pi)/86164
59+
lat_rad = (np.pi/180)*lat # convert latitude from degrees to radians
60+
f = 2*Omega*np.sin(lat_rad)
61+
62+
# compute geostrophic velocities
63+
v_g = dp_dx/(f*dens)
64+
u_g = -dp_dy/(f*dens)
65+
66+
# assign attributes to DataArrays (names) and units
67+
u_g.name = 'u_g'
68+
u_g.attrs.update({'long_name': 'Geostrophic velocity in model-x direction',\
69+
'units': 'm s-1'})
70+
v_g.name = 'v_g'
71+
v_g.attrs.update({'long_name': 'Geostrophic velocity in model-y direction',\
72+
'units': 'm s-1'})
73+
74+
# create xarray Dataset containing geostrophic velocities
75+
ds_geos_vel = u_g.to_dataset(name='u_g',promote_attrs=True)
76+
ds_geos_vel['v_g'] = v_g
77+
78+
return ds_geos_vel
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{'tile': {0: {'X': ((12, 'Y', False), (3, 'X', False)), 'Y': (None, (1, 'Y', False))}, 1: {'X': ((11, 'Y', False), (4, 'X', False)), 'Y': ((0, 'Y', False), (2, 'Y', False))}, 2: {'X': ((10, 'Y', False), (5, 'X', False)), 'Y': ((1, 'Y', False), (6, 'X', False))}, 3: {'X': ((0, 'X', False), (9, 'Y', False)), 'Y': (None, (4, 'Y', False))}, 4: {'X': ((1, 'X', False), (8, 'Y', False)), 'Y': ((3, 'Y', False), (5, 'Y', False))}, 5: {'X': ((2, 'X', False), (7, 'Y', False)), 'Y': ((4, 'Y', False), (6, 'Y', False))}, 6: {'X': ((2, 'Y', False), (7, 'X', False)), 'Y': ((5, 'Y', False), (10, 'X', False))}, 7: {'X': ((6, 'X', False), (8, 'X', False)), 'Y': ((5, 'X', False), (10, 'Y', False))}, 8: {'X': ((7, 'X', False), (9, 'X', False)), 'Y': ((4, 'X', False), (11, 'Y', False))}, 9: {'X': ((8, 'X', False), None), 'Y': ((3, 'X', False), (12, 'Y', False))}, 10: {'X': ((6, 'Y', False), (11, 'X', False)), 'Y': ((7, 'Y', False), (2, 'X', False))}, 11: {'X': ((10, 'X', False), (12, 'X', False)), 'Y': ((8, 'Y', False), (1, 'X', False))}, 12: {'X': ((11, 'X', False), None), 'Y': ((9, 'Y', False), (0, 'X', False))}}}

doc/Geostrophic_balance.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../Intro_to_PO_Tutorials/Geostrophic_balance.ipynb

doc/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ The `ecco_v4_py`_ package used in this tutorial was inspired by the `xmitgcm`_ p
7070

7171
ECCO_v4_Example_calculations_with_scalar_quantities.ipynb
7272

73+
.. toctree::
74+
:maxdepth: 2
75+
:caption: Intro to PO Tutorials
76+
77+
Geostrophic_balance.ipynb
78+
7379
.. toctree::
7480
:maxdepth: 2
7581
:caption: More Advanced Calculations

0 commit comments

Comments
 (0)