# Parameters
variable = "heat_content_frunoff"
long_name = "Heat content (relative to 0C) of solid runoff into ocean"

heat_content_frunoff#

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_frunoff 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/a28997660f0e7cdf4732dcca6573754f64b7985a5fa12aa779de4e1655c6e927.png ../_images/f8a38639c53669b55e25debbb107cd5cd9e71d594829faf5d50e113f13af91df.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2e343830dd050a0b7ae31830be044289f3a6d32b8cf210b336f032397cc1ea0e.png ../_images/f64e39703e9f564fa8f2eaf5a51cd2f0eee8af6c46e95ede2659b4572dd5e08a.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/effc428f4af179e9adf7e8269f23b7b8328811261468dd50134c8f9818645c8a.png ../_images/4d8f184a232d2fd2aa363733ad10ba22f7b90b642a9c88625f3ebc37e1d619ad.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4e30b7cca3a4c3167b98c1f8a57776aa946c5b81d50aa306cdeb770aac206dcf.png ../_images/93cd89ee9ca1604660c280eb415a6c9fdb9806433000f7265245b344d18e7248.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ec32bca832c52d35397ef1cb8fec589f792868b6b33987d5f26e1780d2ab1d89.png ../_images/691e0ef643f6f68a4f5d65f58044fd98b54bf5910aa52705ec84fad1c80ac5d4.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7326e4fb5aeb5ddceadbcc0a84dedf4f894e5191acd6058a5a9c875eed9274c1.png ../_images/95733902902cab87b8567b1397ba11a9189a32d517cbf830eddd0d9679200bb1.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ddbfd1b4bef7b215d3234bfaecef298e8595d5dd9e2678dbc64eec72bfcd5f92.png ../_images/db3029cacccc92eb80a351db83eafd972a43f71e7f4a48d3f7c15640ae3803d7.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bdf1d064b774cd1c750ee7770c7711c5be9f6d5fd9c0b41381311d6014e93e3f.png ../_images/c9db378d4895762f952c862d3ab1a68a9a301d6b638bbb681128e5312a371feb.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0ee704bf43524a3863b630d1fa717784ba074e09463e80700c62e2236923d99a.png ../_images/007a0f8f33ee536c97d3bcbfca6afe1b20a8f8c7a9eded4f8b42b53a04047e45.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ff90490dfc1588f79d26c91577e0e203a8b81db902dafae4e7e811873af7526f.png ../_images/c9f30044b6d24289bc871cad45179b24b01e46800406e11db9f0c61df6184dbc.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c65fac17faf766e22fece2f2aff4c1394f1956ce1f000d08e4ead3d697f45c30.png ../_images/b83f24aa67c7460f91474005d4d3800920de314f1b09d42b3ee4bbd40045e848.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/166e703c3f9e53e4c2f93f01f03710cc993bda9a4ee360d05800af621e2d956f.png ../_images/22ca86e0d6c4bd30c2abf09261182582a43da3e29add43f46871fa7b952748e7.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fcb8908823fc61e5e98125e949f8df703bdc6455db771a7c1e2a6e70ce41e7ec.png ../_images/f3f2314a9f584f4d02306e7072f434849c2e5fb5bf8bffe37ba8fe733967a577.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2c6b3c70da7a0d0591a2b22f10e738ddc10ef787b0d42b0355345cb7f5febf2e.png ../_images/48459e57cb721085d93f25c2c23ac0be743c636fb1b33537fd242d91da7fc654.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8cd6ee516afc74078835faecfdaba85dedf9cc2c4db57a8ebde18d95eec09a33.png ../_images/913079f4f99b8987ce6fc6e1d3cfdb7272f41329c07d09268d956ec984583736.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1fcd0ba3b4edb9923b5149d01a187b75dc60fc0e623dfb60778c5875f2eee051.png ../_images/4fefd150298de4c86153603ecfd3a3fc7c0d0deb955f22e6d5e4c725e953875d.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7212d028216692811064b4ef07535be56f1c25a027e8d6b1db5620042cfee4f4.png ../_images/093cb3c107f4e26ee842ac11c35f7cfa79dcc77dab156f207895afdd8055ab35.png