# 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))
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/a6e82c540fb269b5a4c06636aeb4dcc56736354e33e5139619c36fc1699f69de.png ../_images/ef16e1edcd3f27e923cd8b1b6b3193ffa6dc608e08b54ce07e6ff77116b44f21.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3df3a8540986bd484aa31a1d897cc2f9ba343895988ec083de3a2e3e7d3e1d94.png ../_images/da9d0fe63c7921eed0dbe8f20527acb3fcd61a67631fd770c736f34d608d746e.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5d85058dcf1f4ac6340a7e87af349b6dfd1a4696b7f39cbed58669e1e166dc9e.png ../_images/3b764786f6c6bbc1798f83cba4d5ba95ac2a276560081fdc702fc0e2718687c1.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5a35db642716fbe4d83e1a6a30a06b0151d6bf4e301ee6cb950c424906305e4d.png ../_images/72a49d4fb79ddd87926b2a4d6b8cbee2dadd6269fb92a13d3a251aeef08fd995.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b5fc772a977e878504e09b44be15106e3acf5472398076ccbe6201e84fd767c6.png ../_images/e64bbbd56f0326a5ccdf56cd9df01b80b86b2af0a38df78e31f99cdf16e6a795.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/93cdedcb48a7c68a37258972a42d9894f0c55ec092f2470d9042e911726d6ecf.png ../_images/67ae680abdb328e8ed22275ecfb7ea7e67fc5c9d1a9cc890923c096ee1d8c938.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/61619b6bca3350d232a9ea24ff89e4342282095efc2f6bc909822cfbc8a57b3e.png ../_images/bbce2a902e012ba98da8d309027daab280568cb1d730e1816e3e62cd9696fab9.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8af43b5f16fc95baf628c7830071fbf30c618734cafaa91dbb502b9b7819dfad.png ../_images/02e3a22aeeb23e6e6e05060daf83c77b3e2828682cb3f61d642422887dbb3b29.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/950727a1cb71389de7af0038974f8411d60f9039aa107886b4613b1978e943fe.png ../_images/7be11f5ab0e005bf1ec8e883451ba49955ec9d02e80422b4a540e04b8f846774.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9deebd519b59ef67dc6185bed76c346625147cecfada002fe5b10eac93044d4a.png ../_images/916df3dc843c2a1e0ac9133bef4b6e814d28ceff86153382da8c2814a8f82844.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/94a16d1d1d2e5bdd47bc80ca2aef8f7faa79d9ff9ca5f04cc7d4a35fe35c447f.png ../_images/a0e1c54bd3feb51ca1d86561b6218f7ab1db8bdfe16d3a1e6d5b45bec99083f6.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/35541f81d0de9df307da329e11c4b827badf1d30fdc7033281a39ec94a64650c.png ../_images/91f4c08201a040de9be3630a37c30a6187a26e72266bb1ee7aa4e55b7ee8af83.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6bd68fdcd0fe912068de9c929916c6588b1ded3e6824c2839ddb7016b14b9c00.png ../_images/843ad344fd8f6f09e6663130e56327d48ea3b681d24015ab24e531eac9389828.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/871174fde6a8d832164ccf31474cd909646aa8dcac3557447cea92855a087a53.png ../_images/29219c2c56854c9dc32f0847bdc6c1c68e76ab1244ba057a03e5fc9593df2ac9.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4ec100e5e8be6bea32c0a49ac41238a5f584522056d0abe965f68c4571810f92.png ../_images/a3679db555801dd7495efbdcb18afb94a9b2db27f8f0eadc686411861f04059b.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e671992db12962383626d40cb468b8d93dbe35dc777c1db92cfbac1136f3408a.png ../_images/9e70092c49c8cf3fe8f930457d395951ba3d4deb9d3abdf7908c9aeae5771cfd.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9cfea351042e92c604cdff5f56e6bfcd01088d241a7bd3de4e333a8ee26e83db.png ../_images/b69181a513644606fb20fa040b5c676a65cd43ec20d1d6f069ba7e1ae44ad979.png