# Parameters
variable = "heat_content_cond"
long_name = "Heat content (relative to 0degC) of water condensing into ocean"

heat_content_cond#

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 heat_content_cond 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))
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/e95011684f9c35236338137f76b36271b16c00cef3acb7fee65df52703461464.png ../_images/a580b80d308dfd6fa93aa76dfde2da366ddf3cba89d72b76cb7ad2ead9afaa8d.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2618ec158860f1c715f412e1adec37f88feaea72f0e31a09b469e66c2245e68c.png ../_images/2e1f3dee49a53f00f099d04b18e69a4fd10dc75fd69b27c8c21f61e1b511a31d.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7bd3d40329762ebd58411ed1b981a24c438823cf0eed4796c1b95f764dceced7.png ../_images/f460816224483045197c258a93d8f08ba8934db78c9f97505b1fd73e67a6fe83.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4fce1f986074354721b3e24f755e39f7f361de6cba65a4900740e03a3bbb38ab.png ../_images/eaef3fbc8e46f6194b0d4ddb8698e25a7a726025610deb3e85ea43ef5d84481d.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4680664b8cdc86e7cf68b3e855c4840be23471a7d15ba1de75f29c5b3541e75a.png ../_images/e7c5a01ff82a607662c0018078c670dd1f3f41bc6a6aac0a9a5ab0735ffa1646.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3a7de5f19e94c59b3e09562b81efc15ba19c32a13ded17e677f4f7c052f2cbc6.png ../_images/b3120d0c20af080f79bde154d64ec8ca6d620e777675caf2030d020a7df92095.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a31b70debbe834117363e9838e7576e6b1ca1e7d3f1d4b3d640b1408abca8c1a.png ../_images/31b21f116172d642e2733c58115a3a90d2677dc69d1998fd3f36c4ea2a196b9f.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4b5e277e070b8b4a0a07659134a8f4a46285d9f268bc374656b08485de400ea6.png ../_images/08f7c32c857acc0fe63704525abd2b8fbdb7965d4072037543faddf0f84512f7.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bf33c5f55eee90ddba368ab8acce27364e48a3f1f23ef847674aa2f676ead6b0.png ../_images/5c6234ca14c4f717ccec29d01dc7514bbe7ea00f567fffdc0876be77fa310f46.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/549bbd0ef650c7a9fa5b0d7791045ba7aaf9c1b16668d7a3475c434c1de630af.png ../_images/56331d6bd9d23e5bdfd73d642f51d667d6b720181786a3f167adbc965eaea6d5.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2736d7dcb169848eae693cfb062c998f9c3e51a1961ecc1a7f5e02de1ee3c695.png ../_images/0e1269f7c1a89976b854c5d929162bfe0fbd7cf1de255d5b51eef31b2a425a12.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e81f9a516bb7ffc5d0af91fe730b37a3599cedc9469afca0cb2207e71a1bc6b1.png ../_images/32198002c084e7b141944bfc5eb00eb51caaf97cadb03e7de284591ac9feea80.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cca42cf0f8b50485dd4333f07d76ddeb431d8181fcbc54238896c1b65609c7ff.png ../_images/5839d22d6e00ca6309d5d3106c34d447054577cb7607048f3d942c06074d078f.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b4a63354201a43d68c1e6cb043b15c228864bccd3a6bf018afa7d59dd06c7c60.png ../_images/23b9391cae45305dff0fbde8140cb3a98f8fca32759c42b40d544006461aeaa9.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dc8b131824fcace5b825cec9e0626052c84ab5b4f837d684b6d4d8f4cc002b57.png ../_images/ca3a2fae621a4aa6ef32f59270a3b62acf96dc556d8d15895d19ad7ef09bd0e5.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a7853e7eb91f178cae50d1e34808617fb3654138424db13d0f530890562b47e.png ../_images/5d63f7e0be3e29a716abfc9e3a9d3f097568d6698521802a30e66db99f767e80.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1cbd7e86304dad80e53e14d551bb6aab904a9fa2f6689ce3984da9b352fee0a1.png ../_images/5f94a51eeb7055d8b060fe2e5906612cf00bfce7b8c937672445fcc47ef535cb.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/52509c9fd6c4f7a7e754a6670cf374a1040a2070ab1e662d9419fa11dce83bf1.png ../_images/5ecc52b804c7884c82423f3a8d6369993a97147a7280b01a5cf143860360539a.png