An Exception was encountered at ‘In [8]’.
from IPython.display import display, Markdown
# Parameters injected by Papermill
variable = 'tos'
# Parameters
variable = "fsitherm"
# Dynamically generate markdown content
markdown_text = f"# {variable} \n This notebook compares area-weighted mean time series for {variable} in different basins."
# Display the updated markdown content
display(Markdown(markdown_text))
fsitherm
This notebook compares area-weighted mean time series for fsitherm in different basins.
%load_ext autoreload
%autoreload 2
%%capture
# comment above line to see details about the run(s) displayed
from misc import *
import glob
from mom6_tools.m6toolbox import weighted_temporal_mean
print("Last update:", date.today())
%matplotlib inline
# figure size
fs = (10,4)
# load data
ds = []
#variable = 'tos'
for c, p in zip(casename, ocn_path):
file = glob.glob(p+'{}.native.{}.??????-??????.nc'.format(c, variable))[0]
ds.append(xr.open_dataset(file))
Global#
Execution using papermill encountered an exception here and stopped:
reg = 'Global'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/glade/work/gmarques/conda-envs/mom6-tools/lib/python3.11/site-packages/xarray/core/dataset.py in ?(self, name)
1475 variable = self._variables[name]
1476 except KeyError:
-> 1477 _, name, variable = _get_virtual_variable(self._variables, name, self.sizes)
1478
KeyError: 'fsitherm'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
/glade/work/gmarques/conda-envs/mom6-tools/lib/python3.11/site-packages/xarray/core/dataset.py in ?(self, key)
1574 return self._construct_dataarray(key)
1575 except KeyError as e:
-> 1576 raise KeyError(
1577 f"No variable named {key!r}. Variables on the dataset include {shorten_list_repr(list(self.variables.keys()), max_items=10)}"
/glade/work/gmarques/conda-envs/mom6-tools/lib/python3.11/site-packages/xarray/core/dataset.py in ?(self, name)
1475 variable = self._variables[name]
1476 except KeyError:
-> 1477 _, name, variable = _get_virtual_variable(self._variables, name, self.sizes)
1478
/glade/work/gmarques/conda-envs/mom6-tools/lib/python3.11/site-packages/xarray/core/dataset.py in ?(variables, key, dim_sizes)
208 split_key = key.split(".", 1)
209 if len(split_key) != 2:
--> 210 raise KeyError(key)
211
KeyError: 'fsitherm'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
/glade/derecho/scratch/gmarques/tmp/ipykernel_26844/847476785.py in ?()
1 reg = 'Global'
2 fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
3 for l, i in zip(label, range(len(label))):
----> 4 ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
5
6 #ax.set_ylabel(ds[variable].attrs['units'])
7 ax.set_xlabel('Year')
/glade/work/gmarques/conda-envs/mom6-tools/lib/python3.11/site-packages/xarray/core/dataset.py in ?(self, key)
1572 if utils.hashable(key):
1573 try:
1574 return self._construct_dataarray(key)
1575 except KeyError as e:
-> 1576 raise KeyError(
1577 f"No variable named {key!r}. Variables on the dataset include {shorten_list_repr(list(self.variables.keys()), max_items=10)}"
1578 ) from e
1579
KeyError: "No variable named 'fsitherm'. Variables on the dataset include ['time', 'region', 'fsitherm_mean', 'fsitherm_int']"
PersianGulf#
reg = 'PersianGulf'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
RedSea#
reg = 'RedSea'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
BlackSea#
reg = 'BlackSea'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
MedSea#
reg = 'MedSea'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
BalticSea#
reg = 'BalticSea'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
HudsonBay#
reg = 'HudsonBay'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
Arctic#
reg = 'Arctic'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
PacificOcean#
reg = 'PacificOcean'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
AtlanticOcean#
reg = 'AtlanticOcean'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
IndianOcean#
reg = 'IndianOcean'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
SouthernOcean#
reg = 'SouthernOcean'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
LabSea#
reg = 'LabSea'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
BaffinBay#
reg = 'BaffinBay'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
Maritime#
reg = 'Maritime'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);
SouthernOcean60S#
reg = 'SouthernOcean60S'
fig, ax = plt.subplots(nrows=1,ncols=1,figsize=fs)
for l, i in zip(label, range(len(label))):
ds[i][variable].sel(region=reg).plot(ax=ax, label=l, lw=3)
#ax.set_ylabel(ds[variable].attrs['units'])
ax.set_xlabel('Year')
ax.grid()
ax.legend(ncol=3,loc=1);