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

heat_content_lrunoff#

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_lrunoff 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/b7eab0118ba6f33455aee534df36d1f959eada2100b9d6db7d7412353a3c77e2.png ../_images/2918f5e89053dc074473699540eab47734dd7c24fb8c1368853c3ef86c6406f5.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/266d7de2a2aae4fa682cc4a4a3c05354b1377976427fc77a8b025782a1ce474f.png ../_images/b3dc1609278d9dbaec04a34fb253c7c08711b48b2486a43fd905a2930fe304af.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bdaa1ac6589dc73e09d16f4831719465d3f93f986bd85513c84f4c5a3f287118.png ../_images/ed2d6453e397a7cdf1dd06ae7db50b656b7e4b25c49d195559f44849cd3902f7.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/491818e6a10771c0e8579108db620d3f80c0bd6198d9e57932df3eda8444796e.png ../_images/5ea6a24360904c4548d6755e08ddf8d94cde56f048ed31de61f2c2254c7fe997.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a27eb750db738378374d9c1f3b1ff5daaf9048958245a6c424ee011f53f2319.png ../_images/7839849b5e73de009596d334ff1a613c295b5bfd2c4ccc7a095bcaaae21496e2.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/32a17dc1dac9cf2cf396f9827f94bfbed461ffe792d3db73e7b779180771194e.png ../_images/023b5c39a5ebc9244bd2bf8de72439b36c02b6693d86cf579e51bc98281bf090.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a3383c4d9202d80044e13c106b85b2b66ef434308c220a15529e1d88ccc6e0a7.png ../_images/67446ec12d2a0cd1f5e16da082a804d368ee55de5653066962da44ec5c4b51cb.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3dee739daca2aef5a1dcd7febdeda888829047872cb6ee3f8ca08d05c2181206.png ../_images/d39f99e39ac3300cf751a9487b3ecaeba718c78b297d10b2dea33076e0084e0f.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/caa7605e21273b2f72ca4ceab0f14c4cd3877b8b13b171f9e36169942414e9cf.png ../_images/85f884e058202eab428500d80908425e3beebe5dbba707e6c56e5bdc107d2d9c.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/50809782725fe2a9fe8fd9f5c623b6aa6c9f77c8ea74f12ec545aaa3fd9678db.png ../_images/ba5e11ae7e385397df2da5876897459d127013a1ddea1d0216dc372d2e78b19c.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0f61d69afce0b6949edbffffd30c589757a1702d00442021d5d5a5e1b8d9c686.png ../_images/7a78f129975e5e26e065515201dbc6b8b6b5a8a3328f036de42a45fd773b9fc6.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0fc63a06d10413fa5a9b37f48efcf9b4f57b995de605f77c454218117e1ddd79.png ../_images/502fd4ace2b124ebc1f34d11a643c7218d1eafc0fb8834d49b8802189bc5654d.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/57339494c12e667e8be083a65d99ca88d0842f68792f93264e25a961d50f1793.png ../_images/8a3bd356592a40e5a5c4426d86c830f2eae323d5451d599d8edb4b7b87de798a.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a72b93f770a11180ed980518514ceecc6a15aecba52a4a227f7c01d2a6d4227.png ../_images/1a5fc36063c5465104845f3ed85669e4d39dfda0e35d8fd16bd83b5829c9a6a6.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/12f2b6a7f1950020bd483eba4638cf4648ba8dca2ac2667f84fac8b5fd8187dc.png ../_images/5c21db02de2b43728f20b639721c817a92c9299bf67edad03b62c84e4253a8f2.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/142dd693ac9b68e428b2f028d2e3c1c276a3d426796a27096d169748b6281d9e.png ../_images/a141967541b364d4e3c4c1d5e9ba64bfe306255c918f02d0d5e46f18b7fdf07d.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/82a559e4df735040574aefac003baba659f790c76c56f064949bc5ed403126da.png ../_images/33cd5de50762fc61c7d3fc627779b156b076934e778b229f25c028d3b8075772.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/aa105860cef5603e6144e940172803b3b1a3ba7358b677ac493d2deb2fe84857.png ../_images/8d25bfe655df8b0918e7f5fb8a1c0f572ca50a14a4d8845a154c4a958d977cfb.png