# 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
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.

# 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/b457cdf42d7c8a4ef2510b1948e334fd8d79426e4599eecc85c761ebcec63537.png ../_images/034db8144152b22e3c0f5b69f725d374d62f95854f40b209c82ef9d10ad4edf6.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/52e485b6f187921cdb907e98befed4dee4ac0d658bb79c2cc56317af1a9578d1.png ../_images/929f72fe01c5ef7b93c1368d4fb7c65a04835ff02f3440cdf57e507bc84829f3.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2817ba8b5f40117aa720ba9a6ddaba11fde344c744af17b2cdcbae44c8da8124.png ../_images/f1ab5597cbac728f5eacd78ca19f49aa6b2c683ef81d3ecf42ae85fdff865f18.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f007db4f65c2c4aad3bd8e5a6d62745d3a1234a868c97c3f2f9c5614b4507d07.png ../_images/9f19ae045a258a470b78a15a49e7696ccec914814d0e058b09f829dbddfe5a32.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4ac3862e221c65cafd0b098113140d4bec20b1b2860f033a7c8950cb891b0bb4.png ../_images/a2a10561adb8eb3e764b9e863f43c0e7a0d62170f8fbcc1cf7221a00abbcd483.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/225196e9b7a4d79d193496c6e6f941dfe3f349f8cef3b6ba0c7927db21a5fe59.png ../_images/1f17e385d5ea952d48700e351f4b92efcdadac3f516e377f09f2c2ebf8d01ddc.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5f8e9c4e2cab25b91cfc94ebd83d4ae1b20f22fee2267defe47002ad9872f560.png ../_images/1e3e0a85dc8e4d239d21e0c0890b1e4f7f5d9b9fe4e657bc29eb75f09b741e6b.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8a98112872b89506b16dd8c96578e0cfce1037c1c6b4631142d72d38c889f8d0.png ../_images/14387216c18929f2e7abb706af7c47d657641627a2f04b5e9b228d233376abe0.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0e184dadcabc9ab1560fe9b370f042796d0f30875f5c94604e2930466fdeabb3.png ../_images/b8f95882d37199bd5c3e357800ce7bbc2814ffaa89edc68f030a4efcac562864.png

IndianOcean#

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

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/73b8278d0479329d42acd4151e4af6dc9457c252747af27d7dd367898f165660.png ../_images/af0f6c38f035855b07c9efbfef5ed2f2670584a0c37540ce5c9e6e082a06fec4.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bd883bd629b942a7ea67f422e98d4d3760eb58fb77e173ec92c4db9e7e0c5a7a.png ../_images/cb67aeb8937d7bf62f4d23c41cd4456d01dc92d4cd4efe9c39208c0c23c30bea.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eadd6c9746b1f451d387618e52112f9e29b6b9daaabdd3e2e113503cab24e71e.png ../_images/351a84b5ea8a29ba2777e00c120653bfe3afcdd277f3a753d62720ecf7a52750.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c448a5ac2c5773ee56a5bd38af32bb6e9426f0031dc08d7355b657b44ad51626.png ../_images/bcce24f94d15b3dd9629924420aaac9da326538b57861a84b1cf5dfbbe1528d9.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7d7d938d1dc7204b7600eed4570164d4f55e9313be5f14a2d2f348bd1461f495.png ../_images/0165b95d42f06ac8dd65817267f8158139b3723de317bdb2e2bc95dba53a0ae6.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/190280ec6ceb8133af5c9474267ed1f7e81368c3ec35721b35eafc5fc763faf3.png ../_images/d66933fec80a0535fc7ff63bdf164debcee294e615bc1d91664e4a88a0402114.png