Skip to content

Commit 2ade3cf

Browse files
authored
Merge pull request #41 from andrewdelman/geos_fix
More updates to geos bal; created new ecco_po_tutorials module
2 parents e0bf9f9 + 7d1e827 commit 2ade3cf

8 files changed

Lines changed: 2192 additions & 443 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ _templates
55
/Tutorials_as_Jupyter_Notebooks/.ipynb_checkpoints/*
66
.README.md.swp
77
/ECCO-ACCESS/Downloading_ECCO_Datasets_from_PODAAC/~/
8+
*.pyc

Intro_to_PO_Tutorials/Geostrophic_balance.ipynb

Lines changed: 561 additions & 426 deletions
Large diffs are not rendered by default.

Intro_to_PO_Tutorials/Steric_height.ipynb

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

Intro_to_PO_Tutorials/Thermal_wind.ipynb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -292,22 +292,6 @@
292292
"dens_anom_atdepth = dens.isel(isel_dict) - dens_mean_atdepth\n",
293293
"\n",
294294
"\n",
295-
"# function to scale colormap, coordinating among multiple plots\n",
296-
"def cmap_zerocent_scale_multiplots(plot_objs,scale_factor):\n",
297-
" \"\"\"\n",
298-
" Center colormap at zero and scale relative to existing |maximum| value across multiple plots, \n",
299-
" given plot objects (as list) and scale_factor, a number of type float.\n",
300-
" Returns new colormap limits as new_clim.\n",
301-
" \"\"\"\n",
302-
" clim_plots = np.empty((len(plot_objs),2))\n",
303-
" for count,curr_obj in enumerate(plot_objs):\n",
304-
" clim_plots[count,:] = curr_obj.get_clim()\n",
305-
" new_clim = (scale_factor*np.nanmax(np.abs(clim_plots)))*np.array([-1,1])\n",
306-
" for curr_obj in plot_objs:\n",
307-
" curr_obj.set_clim(new_clim)\n",
308-
" return new_clim\n",
309-
"\n",
310-
"\n",
311295
"# make figure\n",
312296
"curr_mask = land_mask.isel(isel_dict).squeeze()\n",
313297
"fig,axs = depth_two_subplots(ds_grid.XG.isel(isel_dict_ig),-ds_grid.Zl,\\\n",
-6.54 KB
Binary file not shown.

Intro_to_PO_Tutorials/geos_vel.py renamed to Intro_to_PO_Tutorials/ecco_po_tutorials.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,69 @@
1+
def cmap_zerocent_scale(plot,scale_factor):
2+
"""
3+
Center colormap at zero and scale relative to existing |maximum| value,
4+
given plot object and scale_factor, a number of type float.
5+
Returns new colormap limits as new_clim.
6+
"""
7+
curr_clim = plot.get_clim()
8+
new_clim = (scale_factor*np.max(np.abs(curr_clim)))*np.array([-1,1])
9+
plot.set_clim(new_clim)
10+
return new_clim
11+
12+
13+
14+
def plot_mask(*args,ax=None,color):
15+
"""
16+
Plot mask, given input parameters:
17+
- X, Y: (optional) coordinates as 1-D or 2-D NumPy arrays or xarray DataArrays
18+
- mask: 2-D array of boolean values (True/False or 1/0), NumPy or xarray
19+
- axes: axes to plot on, defaults to current axes
20+
- color: a string indicating a color in Matplotlib, or a 3-element tuple or NumPy array indicating RGB color values
21+
22+
Returns plot_obj, the plot object of the mask
23+
"""
24+
if len(args) == 1:
25+
mask = args[0]
26+
else:
27+
X = args[0]
28+
Y = args[1]
29+
mask = args[2]
30+
# set alpha values to 1 where mask is plotted, 0 otherwise
31+
if str(type(mask))[0:5] == 'xarray':
32+
mask = mask.values
33+
# get color for mask
34+
if isinstance(color,str):
35+
import matplotlib.colors as mcolors
36+
color_rgb = mcolors.to_rgb(color)
37+
elif (isinstance(color,tuple)) and (len(color) == 3):
38+
color_rgb = np.asarray(color)
39+
elif (isinstance(color,np.ndarray)) and (len(color) == 3):
40+
color_rgb = color
41+
else:
42+
raise TypeError("input parameter 'color' has incorrect type or number of elements")
43+
# create a colormap using a 2x4 array with two RGBA entries
44+
# the RGB entries are the same in each row
45+
# in the 1st row alpha=0, in the 2nd row alpha=1
46+
cmap_array = np.hstack((np.tile(color_rgb,(2,1)),np.array([[0],[1]])))
47+
from matplotlib.colors import ListedColormap
48+
colormap = ListedColormap(cmap_array)
49+
# get axis limits of existing plot
50+
if ax is None:
51+
ax = plt.gca()
52+
existing_xlim = ax.get_xlim()
53+
existing_ylim = ax.get_ylim()
54+
# plot mask using colormap just created, with alpha=1 where mask=1 or True
55+
if len(args) == 1:
56+
plot_obj = ax.pcolormesh(mask,cmap=colormap,vmin=0.,vmax=1.,zorder=50)
57+
else:
58+
plot_obj = ax.pcolormesh(X,Y,mask,cmap=colormap,vmin=0.,vmax=1.,zorder=50)
59+
# set axis limits of mask to axis limits of existing plot
60+
ax.set_xlim(existing_xlim)
61+
ax.set_ylim(existing_ylim)
62+
63+
return plot_obj
64+
65+
66+
167
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"):
268
"""
369
This routine computes geostrophic velocities from an input netCDF file containing ECCO v4r4 density and pressure anomalies on the native llc90 grid.

doc/Steric_height.ipynb

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

doc/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ The `ecco_v4_py`_ package used in this tutorial was inspired by the `xmitgcm`_ p
2828
intro
2929
fields
3030
Installing_Python_and_Python_Packages
31-
Downloading_the_ECCO_v4_state_estimate
3231
Downloading_ECCO_Datasets_from_PODAAC_Python.ipynb
3332
Downloading_ECCO_Datasets_from_PODAAC_wget.md
3433
Tutorial_Introduction

0 commit comments

Comments
 (0)