# Parameters
variable = "opottempmint"
long_name = "integral_wrt_depth_of_product_of_sea_water_density_and_potential_temperature"

opottempmint#

from IPython.display import display, Markdown
# Dynamically generate markdown content
markdown_text = f" This notebook compares area-weighted mean and, in some cases, integral time series for {variable} in different basins."

# Display the updated markdown content
display(Markdown(markdown_text))

This notebook compares area-weighted mean and, in some cases, integral time series for opottempmint in different basins.

%load_ext autoreload
%autoreload 2
%%capture 
# comment above line to see details about the run(s) displayed
import sys, os
sys.path.append(os.path.abspath(".."))
from misc import *
import glob
print("Last update:", date.today())
%matplotlib inline
# figure size
fs = (10,4)
# load data
ds = []
for c, p in zip(casename, ocn_path):
  file = glob.glob(p+'{}.native.{}.??????-??????.nc'.format(c, variable))[0]
  ds.append(xr.open_dataset(file))
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.
def ts_plot(variable, ds, fs, label, reg='Global'):
    """
    Plot time series of regional means and integrals for a given variable from a list of datasets.

    Parameters
    ----------
    variable : str
        Name of the variable to plot (prefix for "_mean" and "_int" variables in dataset).
    ds : list of xarray.Dataset
        List of datasets, each containing time series data for the specified variable with
        variables named as `<variable>_mean` and optionally `<variable>_int`, and with
        attributes 'long_name', 'units_mean', and optionally 'units_int'.
    fs : tuple
        Figure size (width, height) in inches for the plots.
    label : list of str
        List of labels corresponding to each dataset, used for the legend.
    reg : str, optional
        Name of the region to select for plotting (default is 'Global').

    Returns
    -------
    None
        Displays the plots but does not return any value.

    Notes
    -----
    - This function creates one or two plots:
        1. A time series of the variable's regional mean (`<variable>_mean`).
        2. If available, a time series of the variable's regional integral (`<variable>_int`).
    - The function expects each dataset to have attributes 'long_name', 'units_mean', and optionally 'units_int'.
    - The same region name is applied across all datasets.
    """
    
    fig, ax = plt.subplots(nrows=1, ncols=1, figsize=fs)
    for l, i in zip(label, range(len(label))):
        ds[i][variable+"_mean"].sel(region=reg).plot(ax=ax, label=l, lw=3, linestyle=linestyle[i], color=color[i])
    
    long_name = ds[0].attrs['long_name']
    ax.set_title("{}, {}".format(reg, long_name))
    ax.set_ylabel(variable+"_mean, " + ds[i].attrs['units_mean'])
    ax.set_xlabel('Year')
    ax.grid()
    ax.legend(ncol=3, loc=1)
    
    if variable+"_int" in ds[0]:
        fig, ax = plt.subplots(nrows=1, ncols=1, figsize=fs)
        for l, i in zip(label, range(len(label))):
            ds[i][variable+"_int"].sel(region=reg).plot(ax=ax, label=l, lw=3, linestyle=linestyle[i], color=color[i])

        ax.set_title("{}, {}".format(reg, long_name))
        ax.set_ylabel(variable+"_int, " + ds[i].attrs['units_int'])
        ax.set_xlabel('Year')
        ax.grid()
        ax.legend(ncol=3, loc=1)

    return

Global#

reg = 'Global'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7db687a793416e5586597d8c3ce4be811ab97e1e19bcc12d76a69d62c758bb04.png ../_images/d8563708a290113cf38d783c3ed1700d61a60043d86e273d8df9ccbc8ce501e8.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f21cbb87455d55d4959ff701ed2936125f3aa136ea91567c4db6757ced7cc672.png ../_images/9b400dc3dd9d00abdb3da5d5336e3e7acc16a383683db5421ad9a6fe7661dafe.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/86f4a8e4052781e4ce6b1d22956b9e5fe5706d182d4b46226614f96d19d7c91e.png ../_images/d27bb42e5296c17f33b2c579bf4c101975485201d66b37f42068464b41cec193.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ecbffc8a4e233c4615598b6177366121ffaf3f9d6322a37bf407151aa8277399.png ../_images/12da197505eba64fbbafabe71cf15f70547f19593bdd92807cddee7ae9d38ffc.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5fed0511f44b7c48a13ff3770eb9e5565c588594d411ee784baf101dd83a9124.png ../_images/b385d659c6151b09e4249bf62899579921c9d8218a39f5fa92c32bc37c3e4565.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/33337fdc779a3b42058bfe82dc50d75bcb4d78b339ca0fc99671a100bbc1b3da.png ../_images/f0ce5697b70ee2520c6ea14d7c8edbbd04132b434eff80c181681a6d1e82fc3a.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d653a995f3bea20e8bd944b8b1180bf8642b181ec5ee9483334ff3f6ea4e0732.png ../_images/d4e0db70a8810f146e20c52dbfa377afb3e742d4fd50073c122b2ff4ed59f42c.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8e274299c5f2d4e52f06aeafcea4edb2303c9dda18b1b76551049276fac9188b.png ../_images/abaca6d4efac4cdc0b172ab85ef6dfb4ff5b16d652ac1417d25230d6812c073b.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a60bf45849752f8ae5116f786e70ece6560934ff98e19f53f3ec2f045e7984c5.png ../_images/033fc00e2c12e859757f9d4ac1bbb8cdbfa65b6dba52ab2c185f90c30fcd619d.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/93d817565564c1125ceeffde191763c615cbcdca8acc54eb8fb79dd9c5eaf56b.png ../_images/0c05f874439dd5e05dd15a6c8ad424d342e0c40133cdf236530553fffbfc7b94.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/db09d197e6d246d93473a754fcbb53dd253d0aa2ea5356be2c6d6e55b8268fa3.png ../_images/9ee30b74f01b4060eeff108a5029997e8be46892979756de65d24a1a537c3e98.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b023ff1d98806b1f57e39afcb9c9351a70c83b954dc2637cfb747bd20f3848c6.png ../_images/01c97c4963d57e07a4fced235dccd96b31d6fe3fe92737ffe02e8bb324a39463.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/937aea894d5f3eb618fecdeb192a68f015567e41d4c038c31b6cd9b877c25681.png ../_images/c36ed332a48169b363069a7438c81fb27b19e1d0e8a3be042f3bc5f8c66c6f63.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3392bbd3cfa2e65a439275220d60006f1a85d9c197617b3fa3440f09f40ef1ec.png ../_images/4bd77c949922fa078f7133904d297dbabb36533ca4b03d281d701b923ae61568.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dad57b3aef54c6b8d5a93f4f766f8166c148283996576855241ab6de9058359a.png ../_images/9fb7fd031db33e802523136f7863f9f1c0445752b3edfd9e6716cc2032213566.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3cf4c03368a575c230079d18dda5636cbd4e4c4f440b1270c75a43d057f88444.png ../_images/c010519ddac613a6818d33c1242187a89a8f35bfb98c829ce26d69f4fdef9e09.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/946a2d52f97761d163d447052c6170905357fc1010bbd70120be2fb072c17b7d.png ../_images/97bb7cc6378195712362a13ca03210f21a50ab35f4f79b0db2f62862f7f1461b.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/df796344aaacee22ded4d785bdb0b9c275ea38120c1ed73350238c8f242cac91.png ../_images/0ec51ad731066616a82cdfb89681d3ab653e1e764b9dcc21bad397d8fdaea704.png