Equatorial Upperocean model vs. obs comparison
The goal of this notebook is the following:
serve as an example of how to post-process CESM/MOM6 output;
create time averages of T, S and VEL fields and compared agains observations (PHC2 and Johnson et al, 2002);
[1]:
%matplotlib inline
import warnings
warnings.filterwarnings("ignore")
from mom6_tools.MOM6grid import MOM6grid
from mom6_tools.m6toolbox import shiftgrid
from mom6_tools.m6plot import yzcompare, yzplot
from mom6_tools.m6toolbox import cime_xmlquery
from mom6_tools import m6toolbox
from mom6_tools.jobqueue import get_cluster
import yaml, intake, os
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
from IPython.display import display, Markdown, Latex
Basemap module not found. Some regional plots may not function properly
[2]:
# Read in the yaml file
diag_config_yml_path = "diag_config.yml"
diag_config_yml = yaml.load(open(diag_config_yml_path,'r'), Loader=yaml.Loader)
[3]:
caseroot = diag_config_yml['Case']['CASEROOT']
casename = cime_xmlquery(caseroot, 'CASE')
DOUT_S = cime_xmlquery(caseroot, 'DOUT_S')
if DOUT_S:
OUTDIR = cime_xmlquery(caseroot, 'DOUT_S_ROOT')+'/ocn/hist/'
else:
OUTDIR = cime_xmlquery(caseroot, 'RUNDIR')
print('Output directory is:', OUTDIR)
print('Casename is:', casename)
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
Cell In[3], line 2
1 caseroot = diag_config_yml['Case']['CASEROOT']
----> 2 casename = cime_xmlquery(caseroot, 'CASE')
3 DOUT_S = cime_xmlquery(caseroot, 'DOUT_S')
4 if DOUT_S:
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/mom6_tools/m6toolbox.py:47, in cime_xmlquery(caseroot, varname)
45 """run CIME's xmlquery for varname in the directory caseroot, return the value"""
46 try:
---> 47 value = subprocess.check_output(
48 ["./xmlquery", "-N", "--value", varname],
49 stderr=subprocess.STDOUT,
50 cwd=caseroot,
51 )
52 except subprocess.CalledProcessError:
53 value = subprocess.check_output(
54 ["./xmlquery", "--value", varname], stderr=subprocess.STDOUT, cwd=caseroot
55 )
File ~/.asdf/installs/python/3.10.20/lib/python3.10/subprocess.py:421, in check_output(timeout, *popenargs, **kwargs)
418 empty = b''
419 kwargs['input'] = empty
--> 421 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
422 **kwargs).stdout
File ~/.asdf/installs/python/3.10.20/lib/python3.10/subprocess.py:503, in run(input, capture_output, timeout, check, *popenargs, **kwargs)
500 kwargs['stdout'] = PIPE
501 kwargs['stderr'] = PIPE
--> 503 with Popen(*popenargs, **kwargs) as process:
504 try:
505 stdout, stderr = process.communicate(input, timeout=timeout)
File ~/.asdf/installs/python/3.10.20/lib/python3.10/subprocess.py:971, in Popen.__init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, user, group, extra_groups, encoding, errors, text, umask, pipesize)
967 if self.text_mode:
968 self.stderr = io.TextIOWrapper(self.stderr,
969 encoding=encoding, errors=errors)
--> 971 self._execute_child(args, executable, preexec_fn, close_fds,
972 pass_fds, cwd, env,
973 startupinfo, creationflags, shell,
974 p2cread, p2cwrite,
975 c2pread, c2pwrite,
976 errread, errwrite,
977 restore_signals,
978 gid, gids, uid, umask,
979 start_new_session)
980 except:
981 # Cleanup if the child failed starting.
982 for f in filter(None, (self.stdin, self.stdout, self.stderr)):
File ~/.asdf/installs/python/3.10.20/lib/python3.10/subprocess.py:1863, in Popen._execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, gid, gids, uid, umask, start_new_session)
1861 if errno_num != 0:
1862 err_msg = os.strerror(errno_num)
-> 1863 raise child_exception_type(errno_num, err_msg, err_filename)
1864 raise child_exception_type(err_msg)
FileNotFoundError: [Errno 2] No such file or directory: '/glade/work/gmarques/cesm.cases/G/g.e30_a07c_cesm.GJRAv4.TL319_t232_wgx3_hycom1_N75.2025.130/'
[4]:
# The following parameters must be set accordingly
######################################################
# create an empty class object
class args:
pass
# load avg dates
avg = diag_config_yml['Avg']
args.start_date = avg['start_date']
args.end_date = avg['end_date']
args.casename = casename
args.obs = "woa-2018-tx2_3v2-annual-all"
args.monthly = casename+diag_config_yml['Fnames']['z']
args.static = casename+diag_config_yml['Fnames']['static']
args.geom = casename+diag_config_yml['Fnames']['geom']
args.savefigs = False
args.nw = 6 # requesting 6 workers
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[4], line 13
11 args.start_date = avg['start_date']
12 args.end_date = avg['end_date']
---> 13 args.casename = casename
14 args.obs = "woa-2018-tx2_3v2-annual-all"
15 args.monthly = casename+diag_config_yml['Fnames']['z']
NameError: name 'casename' is not defined
[5]:
# read grid info
geom_file = OUTDIR+'/'+args.geom
if os.path.exists(geom_file):
grd = MOM6grid(OUTDIR+'/'+args.static, geom_file, xrformat=True)
else:
grd = MOM6grid(OUTDIR+'/'+args.static, xrformat=True)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[5], line 2
1 # read grid info
----> 2 geom_file = OUTDIR+'/'+args.geom
3 if os.path.exists(geom_file):
4 grd = MOM6grid(OUTDIR+'/'+args.static, geom_file, xrformat=True)
NameError: name 'OUTDIR' is not defined
[6]:
# optional Jobqueue: block in diag_config.yml. It must set
# cluster_class: PBSCluster to get batch workers -- resource settings
# alone are ignored (with a warning) and you get a LocalCluster.
parallel, cluster, client = get_cluster(args.nw, config=diag_config_yml.get('Jobqueue'))
client
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[6], line 4
1 # optional Jobqueue: block in diag_config.yml. It must set
2 # cluster_class: PBSCluster to get batch workers -- resource settings
3 # alone are ignored (with a warning) and you get a LocalCluster.
----> 4 parallel, cluster, client = get_cluster(args.nw, config=diag_config_yml.get('Jobqueue'))
5 client
AttributeError: type object 'args' has no attribute 'nw'
[7]:
# Alternative to reading Jobqueue: from diag_config.yml above: set kwargs manually here instead.
# (Only run one of these two cluster-launch cells, not both.)
# jobqueue_kwargs = dict(
# cores=1, memory='4GB', processes=1, interface='ib0', queue='casper',
# walltime='02:00:00', resource_spec='select=1:ncpus=1:mem=4GB',
# log_directory='/glade/derecho/scratch/{}/dask/logs'.format(os.environ['USER']),
# local_directory='/glade/derecho/scratch/{}/dask/local-dir'.format(os.environ['USER']),
# )
# parallel, cluster, client = get_cluster(args.nw, cluster_class='PBSCluster', **jobqueue_kwargs)
# client
[8]:
client
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[8], line 1
----> 1 client
NameError: name 'client' is not defined
[9]:
# Compute the climatology dataset
#dset_climo = climo.stage()
variables = ['thetao', 'so', 'uo', 'h', 'z_i']
def preprocess(ds):
''' Compute yearly averages and return the dataset with variables'''
return ds[variables]
ds = xr.open_mfdataset(OUTDIR+'/'+args.monthly, \
parallel=True, data_vars='minimal', \
coords='minimal', compat='override', preprocess=preprocess)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[9], line 8
5 ''' Compute yearly averages and return the dataset with variables'''
6 return ds[variables]
----> 8 ds = xr.open_mfdataset(OUTDIR+'/'+args.monthly, \
9 parallel=True, data_vars='minimal', \
10 coords='minimal', compat='override', preprocess=preprocess)
NameError: name 'OUTDIR' is not defined
[10]:
ds
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[10], line 1
----> 1 ds
NameError: name 'ds' is not defined
[11]:
%time ds_sel = ds.sel(time=slice(args.start_date, args.end_date)).sel(yh=slice(-10,10)).isel(z_l=slice(0,14))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
File <timed exec>:1
NameError: name 'ds' is not defined
[12]:
# load WOA18 data
catalog = intake.open_catalog(diag_config_yml['oce_cat'])
woa18 = catalog[args.obs].to_dask()
woa18['xh'] = grd['xh']
woa18['yh'] = grd['yh']
obs_label = catalog[args.obs].metadata['prefix']+' '+str(catalog[args.obs].metadata['version'])
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In[12], line 2
1 # load WOA18 data
----> 2 catalog = intake.open_catalog(diag_config_yml['oce_cat'])
3 woa18 = catalog[args.obs].to_dask()
4 woa18['xh'] = grd['xh']
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/__init__.py:186, in open_catalog(uri, **kwargs)
179 raise ValueError(
180 f"Unknown catalog driver '{driver}'. "
181 "Do you need to install a new driver from the plugin directory? "
182 "https://intake.readthedocs.io/en/latest/plugin-directory.html\n"
183 f"Current registry: {list(sorted(registry))}"
184 )
185 try:
--> 186 return registry[driver](uri, **kwargs)
187 except VersionError:
188 # warn that we are switching to V2? The file will be read twice
189 return from_yaml_file(uri, **kwargs)
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/catalog/local.py:617, in YAMLFileCatalog.__init__(self, path, text, autoreload, **kwargs)
615 self.filesystem = kwargs.pop("fs", None)
616 self.access = "name" not in kwargs
--> 617 super(YAMLFileCatalog, self).__init__(**kwargs)
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/catalog/base.py:128, in Catalog.__init__(self, entries, name, description, metadata, ttl, getenv, getshell, persist_mode, storage_options, user_parameters)
126 self.updated = time.time()
127 self._entries = entries if entries is not None else self._make_entries_container()
--> 128 self.force_reload()
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/catalog/base.py:186, in Catalog.force_reload(self)
184 """Imperative reload data now"""
185 self.updated = time.time()
--> 186 self._load()
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/catalog/local.py:652, in YAMLFileCatalog._load(self, reload)
650 logger.warning("Use of '!template' deprecated - fixing")
651 text = text.replace("!template ", "")
--> 652 self.parse(text)
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/catalog/local.py:730, in YAMLFileCatalog.parse(self, text)
728 # Second, we validate the schema and semantics
729 context = dict(root=self._dir)
--> 730 result = CatalogParser(data, context=context, getenv=self.getenv, getshell=self.getshell)
731 if result.errors:
732 raise exceptions.ValidationError(
733 "Catalog '{}' has validation errors:\n\n{}"
734 "".format(self.path, "\n".join(result.errors)),
735 result.errors,
736 )
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/catalog/local.py:342, in CatalogParser.__init__(self, data, getenv, getshell, context)
340 self.getenv = getenv
341 self.getshell = getshell
--> 342 self._data = self._parse(data)
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/catalog/local.py:565, in CatalogParser._parse(self, data)
561 if (data.get("version", None) or data.get("metadata", {}).get("version", None) or 1) > 1:
562 raise VersionError("Not a V1 Catalog; perhaps use intake.open_catalog")
564 return dict(
--> 565 plugin_sources=self._parse_plugins(data),
566 data_sources=self._parse_data_sources(data),
567 metadata=data.get("metadata", {}),
568 name=data.get("name"),
569 description=data.get("description"),
570 )
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/catalog/local.py:400, in CatalogParser._parse_plugins(self, data)
397 elif "module" in plugin_source:
398 import intake
--> 400 intake.import_name(plugin_source["module"])
401 elif "dir" in plugin_source:
402 self.error(
403 "The key 'dir', and in general the feature of registering "
404 "plugins from a directory of Python scripts outside of "
405 "sys.path, is no longer supported. Use 'module'.",
406 plugin_source,
407 )
File ~/checkouts/readthedocs.org/user_builds/mom6-tools/envs/latest/lib/python3.10/site-packages/intake/utils.py:27, in import_name(name)
25 modname = name.split(":", 1)[0]
26 logger.debug("Importing: '%s'" % modname)
---> 27 mod = importlib.import_module(modname)
28 if ":" in name:
29 end = name.split(":")[1]
File ~/.asdf/installs/python/3.10.20/lib/python3.10/importlib/__init__.py:126, in import_module(name, package)
124 break
125 level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)
File <frozen importlib._bootstrap>:1050, in _gcd_import(name, package, level)
File <frozen importlib._bootstrap>:1027, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:1004, in _find_and_load_unlocked(name, import_)
ModuleNotFoundError: No module named 'intake_xarray'
[13]:
# load johnson_pmel
johnson =catalog['eq-uvts-johnson'].to_dask()
johnson
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[13], line 2
1 # load johnson_pmel
----> 2 johnson =catalog['eq-uvts-johnson'].to_dask()
3 johnson
NameError: name 'catalog' is not defined
[14]:
print('Time averaging...')
# compute annual mean and then average in time
ds_ann = m6toolbox.weighted_temporal_mean_vars(ds_sel)
thetao = ds_ann.thetao.mean('time')
so = ds_ann.so.mean('time')
uo = ds_ann.uo.mean('time')
Time averaging...
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[14], line 3
1 print('Time averaging...')
2 # compute annual mean and then average in time
----> 3 ds_ann = m6toolbox.weighted_temporal_mean_vars(ds_sel)
4 thetao = ds_ann.thetao.mean('time')
5 so = ds_ann.so.mean('time')
NameError: name 'ds_sel' is not defined
[15]:
print('Selecting equatorial data...')
# select Equatorial region
grd_eq = grd.sel(yh=slice(-10,10))
# find point closest to eq. and select data
j = np.abs( grd_eq.geolat[:,0].values - 0. ).argmin()
temp_eq = np.ma.masked_invalid(thetao.isel(yh=j).values)
salt_eq = np.ma.masked_invalid(so.isel(yh=j).values)
u_eq = np.ma.masked_invalid(uo.isel(yh=j).values)
#e_eq = np.ma.masked_invalid(eta.isel(yh=j).values)
thetao_obs_eq = np.ma.masked_invalid(woa18.thetao.sel(yh=slice(-10,10)).isel(yh=j).isel(z_l=slice(0,14)).values)
salt_obs_eq = np.ma.masked_invalid(woa18.so.sel(yh=slice(-10,10)).isel(yh=j).isel(z_l=slice(0,14)).values)
Selecting equatorial data...
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[15], line 3
1 print('Selecting equatorial data...')
2 # select Equatorial region
----> 3 grd_eq = grd.sel(yh=slice(-10,10))
4 # find point closest to eq. and select data
5 j = np.abs( grd_eq.geolat[:,0].values - 0. ).argmin()
NameError: name 'grd' is not defined
[16]:
y = ds.yh.values
zz = ds.z_i[0:15].values
x = ds.xh.values
[X, Z] = np.meshgrid(x, zz)
z = 0.5 * ( Z[:-1] + Z[1:])
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[16], line 1
----> 1 y = ds.yh.values
2 zz = ds.z_i[0:15].values
3 x = ds.xh.values
NameError: name 'ds' is not defined
[17]:
print('Saving netCDF files...')
os.makedirs('ncfiles', exist_ok=True)
Saving netCDF files...
[18]:
# create dataarays and saving data
temp_eq_da = xr.DataArray(temp_eq, dims=['zl','xh'],
coords={'zl' : z[:,0], 'xh' : x[:]}).rename('temp_eq')
attrs = {'casename': args.casename}
m6toolbox.add_global_attrs(temp_eq_da,attrs)
temp_eq_da.to_netcdf('ncfiles/'+str(args.casename)+'_temp_eq.nc')
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[18], line 2
1 # create dataarays and saving data
----> 2 temp_eq_da = xr.DataArray(temp_eq, dims=['zl','xh'],
3 coords={'zl' : z[:,0], 'xh' : x[:]}).rename('temp_eq')
5 attrs = {'casename': args.casename}
6 m6toolbox.add_global_attrs(temp_eq_da,attrs)
NameError: name 'temp_eq' is not defined
[19]:
salt_eq_da = xr.DataArray(salt_eq, dims=['zl','xh'],
coords={'zl' : z[:,0], 'xh' : x[:]}).rename('salt_eq')
m6toolbox.add_global_attrs(salt_eq_da,attrs)
salt_eq_da.to_netcdf('ncfiles/'+str(args.casename)+'_salt_eq.nc')
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[19], line 1
----> 1 salt_eq_da = xr.DataArray(salt_eq, dims=['zl','xh'],
2 coords={'zl' : z[:,0], 'xh' : x[:]}).rename('salt_eq')
3 m6toolbox.add_global_attrs(salt_eq_da,attrs)
4 salt_eq_da.to_netcdf('ncfiles/'+str(args.casename)+'_salt_eq.nc')
NameError: name 'salt_eq' is not defined
[20]:
client.close(); cluster.close()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[20], line 1
----> 1 client.close(); cluster.close()
NameError: name 'client' is not defined
[21]:
%matplotlib inline
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(14,16))
yzcompare(temp_eq , thetao_obs_eq, x, -Z,
title1 = 'model temperature',
title2 = 'observed temperature ({})'.format(obs_label), axis=ax,
suptitle=casename + ', averaged '+str(args.start_date)+ ' to ' +str(args.end_date),
extend='neither', dextend='neither', clim=(6,31.), dlim=(-5,5), dcolormap=plt.cm.bwr)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[21], line 3
1 get_ipython().run_line_magic('matplotlib', 'inline')
2 fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(14,16))
----> 3 yzcompare(temp_eq , thetao_obs_eq, x, -Z,
4 title1 = 'model temperature',
5 title2 = 'observed temperature ({})'.format(obs_label), axis=ax,
6 suptitle=casename + ', averaged '+str(args.start_date)+ ' to ' +str(args.end_date),
7 extend='neither', dextend='neither', clim=(6,31.), dlim=(-5,5), dcolormap=plt.cm.bwr)
NameError: name 'temp_eq' is not defined
[22]:
%matplotlib inline
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,16))
yzcompare(salt_eq , salt_obs_eq, x, -Z,
title1 = 'model salinity',
title2 = 'observed salinity ({})'.format(obs_label), axis=ax,
suptitle=casename + ', averaged '+str(args.start_date)+ ' to ' +str(args.end_date),
extend='neither', dextend='neither', clim=(33.5,37.), dlim=(-1,1), dcolormap=plt.cm.bwr)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[22], line 3
1 get_ipython().run_line_magic('matplotlib', 'inline')
2 fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,16))
----> 3 yzcompare(salt_eq , salt_obs_eq, x, -Z,
4 title1 = 'model salinity',
5 title2 = 'observed salinity ({})'.format(obs_label), axis=ax,
6 suptitle=casename + ', averaged '+str(args.start_date)+ ' to ' +str(args.end_date),
7 extend='neither', dextend='neither', clim=(33.5,37.), dlim=(-1,1), dcolormap=plt.cm.bwr)
NameError: name 'salt_eq' is not defined
[23]:
%matplotlib inline
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,8))
yzplot(temp_eq, x, -Z, axis=ax, clim=(5,31), landcolor=[0., 0., 0.], ignore=np.nan)
cs1 = ax.contour( x + 0*z, -z, temp_eq, colors='k',); plt.clabel(cs1,fmt='%2.1f', fontsize=14)
plt.ylim(-400,0);
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[23], line 3
1 get_ipython().run_line_magic('matplotlib', 'inline')
2 fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,8))
----> 3 yzplot(temp_eq, x, -Z, axis=ax, clim=(5,31), landcolor=[0., 0., 0.], ignore=np.nan)
4 cs1 = ax.contour( x + 0*z, -z, temp_eq, colors='k',); plt.clabel(cs1,fmt='%2.1f', fontsize=14)
5 plt.ylim(-400,0);
NameError: name 'temp_eq' is not defined
[24]:
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,8))
yzplot(thetao_obs_eq, x, -Z, axis=ax, clim=(5,31))
cs1 = ax.contour( x + 0*z, -z, thetao_obs_eq, colors='k',); plt.clabel(cs1,fmt='%2.1f', fontsize=14)
ax.set_ylim(-400,0);
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[24], line 2
1 fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(12,8))
----> 2 yzplot(thetao_obs_eq, x, -Z, axis=ax, clim=(5,31))
3 cs1 = ax.contour( x + 0*z, -z, thetao_obs_eq, colors='k',); plt.clabel(cs1,fmt='%2.1f', fontsize=14)
4 ax.set_ylim(-400,0);
NameError: name 'thetao_obs_eq' is not defined
[25]:
# Shift model data to compare against obs
tmp, lonh = shiftgrid(thetao.xh[-1].values, thetao[0,0,:].values, ds.thetao.xh.values)
tmp, lonq = shiftgrid(uo.xq[-1].values, uo[0,0,:].values, uo.xq.values)
thetao['xh'].values[:] = lonh
so['xh'].values[:] = lonh
uo['xq'].values[:] = lonq
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[25], line 2
1 # Shift model data to compare against obs
----> 2 tmp, lonh = shiftgrid(thetao.xh[-1].values, thetao[0,0,:].values, ds.thetao.xh.values)
3 tmp, lonq = shiftgrid(uo.xq[-1].values, uo[0,0,:].values, uo.xq.values)
5 thetao['xh'].values[:] = lonh
NameError: name 'thetao' is not defined
[26]:
# y and z from obs
y_obs = johnson.YLAT11_101.values
zz = np.arange(0,510,10)
[Y, Z_obs] = np.meshgrid(y_obs, zz)
z_obs = 0.5 * ( Z_obs[0:-1,:] + Z_obs[1:,] )
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[26], line 2
1 # y and z from obs
----> 2 y_obs = johnson.YLAT11_101.values
3 zz = np.arange(0,510,10)
4 [Y, Z_obs] = np.meshgrid(y_obs, zz)
NameError: name 'johnson' is not defined
[27]:
# y and z from model
y_model = thetao.yh.values
z = ds.z_i[0:15].values
[Y, Z_model] = np.meshgrid(y_model, z)
z_model = 0.5 * ( Z_model[0:-1,:] + Z_model[1:,:] )
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[27], line 2
1 # y and z from model
----> 2 y_model = thetao.yh.values
3 z = ds.z_i[0:15].values
4 [Y, Z_model] = np.meshgrid(y_model, z)
NameError: name 'thetao' is not defined
[28]:
longitudes = [143., 156., 165., 180., 190., 205., 220., 235., 250., 265.]
[29]:
# Temperature
for l in longitudes:
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8))
dummy_model = np.ma.masked_invalid(thetao.sel(xh=l, method='nearest').values)
dummy_obs = np.ma.masked_invalid(johnson.POTEMPM.sel(XLON=l, method='nearest').values)
yzplot(dummy_model, y_model, -Z_model, clim=(9,29), axis=ax1, zlabel='Depth', ylabel='Latitude', title=str(dcase.casename))
cs1 = ax1.contour( y_model + 0*z_model, -z_model, dummy_model, levels=np.arange(0,30,2), colors='k',); plt.clabel(cs1,fmt='%3.1f', fontsize=14)
ax1.set_ylim(-400,0)
yzplot(dummy_obs, y_obs, -Z_obs, clim=(9,29), axis=ax2, zlabel='Depth', ylabel='Latitude', title='Johnson et al (2002)')
cs2 = ax2.contour( y_obs + 0*z_obs, -z_obs, dummy_obs, levels=np.arange(0,30,2), colors='k',); plt.clabel(cs2,fmt='%3.1f', fontsize=14)
ax2.set_ylim(-400,0)
plt.suptitle('Temperature [C] @ '+str(l)+ ', averaged between '+str(args.start_date)+' and '+str(args.end_date))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[29], line 4
2 for l in longitudes:
3 fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8))
----> 4 dummy_model = np.ma.masked_invalid(thetao.sel(xh=l, method='nearest').values)
5 dummy_obs = np.ma.masked_invalid(johnson.POTEMPM.sel(XLON=l, method='nearest').values)
6 yzplot(dummy_model, y_model, -Z_model, clim=(9,29), axis=ax1, zlabel='Depth', ylabel='Latitude', title=str(dcase.casename))
NameError: name 'thetao' is not defined
[30]:
for l in longitudes:
# Salt
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8))
dummy_model = np.ma.masked_invalid(so.sel(xh=l, method='nearest').values)
dummy_obs = np.ma.masked_invalid(johnson.SALINITYM.sel(XLON=l, method='nearest').values)
yzplot(dummy_model, y_model, -Z_model, clim=(32,36), axis=ax1, zlabel='Depth', ylabel='Latitude', title=str(dcase.casename))
cs1 = ax1.contour( y_model + 0*z_model, -z_model, dummy_model, levels=np.arange(32,36,0.5), colors='k',); plt.clabel(cs1,fmt='%3.1f', fontsize=14)
ax1.set_ylim(-400,0)
yzplot(dummy_obs, y_obs, -Z_obs, clim=(32,36), axis=ax2, zlabel='Depth', ylabel='Latitude', title='Johnson et al (2002)')
cs2 = ax2.contour( y_obs + 0*z_obs, -z_obs, dummy_obs, levels=np.arange(32,36,0.5), colors='k',); plt.clabel(cs2,fmt='%3.1f', fontsize=14)
ax2.set_ylim(-400,0)
plt.suptitle('Salinity [psu] @ '+str(l)+ ', averaged between '+str(args.start_date)+' and '+str(args.end_date))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[30], line 4
1 for l in longitudes:
2 # Salt
3 fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8))
----> 4 dummy_model = np.ma.masked_invalid(so.sel(xh=l, method='nearest').values)
5 dummy_obs = np.ma.masked_invalid(johnson.SALINITYM.sel(XLON=l, method='nearest').values)
6 yzplot(dummy_model, y_model, -Z_model, clim=(32,36), axis=ax1, zlabel='Depth', ylabel='Latitude', title=str(dcase.casename))
NameError: name 'so' is not defined
[31]:
for l in longitudes:
# uo
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8))
dummy_model = np.ma.masked_invalid(uo.sel(xq=l, method='nearest').values)
dummy_obs = np.ma.masked_invalid(johnson.UM.sel(XLON=l, method='nearest').values)
yzplot(dummy_model, y_model, -Z_model, clim=(-1,1), axis=ax1, zlabel='Depth', ylabel='Latitude', title=str(dcase.casename))
cs1 = ax1.contour( y_model + 0*z_model, -z_model, dummy_model, levels=np.arange(-1,1,0.1), colors='k',); plt.clabel(cs1,fmt='%3.1f', fontsize=14)
ax1.set_ylim(-400,0)
yzplot(dummy_obs, y_obs, -Z_obs, clim=(-1,1), axis=ax2, zlabel='Depth', ylabel='Latitude', title='Johnson et al (2002)')
cs2 = ax2.contour( y_obs + 0*z_obs, -z_obs, dummy_obs, levels=np.arange(-1,1,0.1), colors='k',); plt.clabel(cs2,fmt='%3.1f', fontsize=14)
ax2.set_ylim(-400,0)
plt.suptitle('Eastward velocity [m/s] @ '+str(l)+ ', averaged between '+str(args.start_date)+' and '+str(args.end_date))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[31], line 4
1 for l in longitudes:
2 # uo
3 fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8))
----> 4 dummy_model = np.ma.masked_invalid(uo.sel(xq=l, method='nearest').values)
5 dummy_obs = np.ma.masked_invalid(johnson.UM.sel(XLON=l, method='nearest').values)
6 yzplot(dummy_model, y_model, -Z_model, clim=(-1,1), axis=ax1, zlabel='Depth', ylabel='Latitude', title=str(dcase.casename))
NameError: name 'uo' is not defined
[32]:
x_obs = johnson.XLON.values
[X_obs, Z_obs] = np.meshgrid(x_obs, zz)
z_obs = 0.5 * ( Z_obs[:-1,:] + Z_obs[1:,:] )
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[32], line 1
----> 1 x_obs = johnson.XLON.values
2 [X_obs, Z_obs] = np.meshgrid(x_obs, zz)
3 z_obs = 0.5 * ( Z_obs[:-1,:] + Z_obs[1:,:] )
NameError: name 'johnson' is not defined
[33]:
x_model = so.xh.values
z = ds.z_i[0:15].values
[X, Z_model] = np.meshgrid(x_model, z)
z_model = 0.5 * ( Z_model[:-1,:] + Z_model[1:,:] )
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[33], line 1
----> 1 x_model = so.xh.values
2 z = ds.z_i[0:15].values
3 [X, Z_model] = np.meshgrid(x_model, z)
NameError: name 'so' is not defined
[34]:
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8))
dummy_obs = np.ma.masked_invalid(johnson.UM.sel(YLAT11_101=0).values)
dummy_model = np.ma.masked_invalid(uo.sel(yh=0, method='nearest').values)
yzplot(dummy_model, x_model, -Z_model, clim=(-0.4,1.2), axis=ax1, landcolor=[0., 0., 0.], title=str(dcase.casename), ylabel='Longitude', yunits=r'$^o$E' )
cs1 = ax1.contour( x_model + 0*z_model, -z_model, dummy_model, levels=np.arange(-1.2,1.2,0.1), colors='k',); plt.clabel(cs1,fmt='%2.1f', fontsize=14)
ax1.set_xlim(143,265); ax1.set_ylim(-400,0)
yzplot(dummy_obs, x_obs, -Z_obs, clim=(-0.4,1.2), axis=ax2, title='Johnson et al (2002)', ylabel='Longitude', yunits=r'$^o$E' )
cs1 = ax2.contour( x_obs + 0*z_obs, -z_obs, dummy_obs, levels=np.arange(-1.2,1.2,0.1), colors='k',); plt.clabel(cs1,fmt='%2.1f', fontsize=14)
ax2.set_xlim(143,265); ax2.set_ylim(-400,0)
plt.suptitle('Eastward velocity [m/s] along the Equatorial Pacific, averaged between '+str(args.start_date)+' and '+str(args.end_date))
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[34], line 2
1 fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8))
----> 2 dummy_obs = np.ma.masked_invalid(johnson.UM.sel(YLAT11_101=0).values)
3 dummy_model = np.ma.masked_invalid(uo.sel(yh=0, method='nearest').values)
5 yzplot(dummy_model, x_model, -Z_model, clim=(-0.4,1.2), axis=ax1, landcolor=[0., 0., 0.], title=str(dcase.casename), ylabel='Longitude', yunits=r'$^o$E' )
NameError: name 'johnson' is not defined