# Parameters
variable = "heat_content_vprec"
long_name = "Heat content (relative to 0degC) of virtual precip entering ocean"

heat_content_vprec#

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_vprec 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/c0bce7986831fa96c3772d994570d5733909bc0e66a053f1781ac9abf7486146.png ../_images/0d99753146cdb38ed75621f6ecaf758e0c44b620db2a05d948512bca47fe18a5.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/31bcf415065620b2d84972b3dddc49e589f99716a13df66f90b01e207d8bb8f3.png ../_images/c05db5669a5699740752068255cb413f6cd02239924461274f86ad67cdf8c7ff.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/97bf2e9a0e8b1d6532769aeeb7933cd370d14ad0429592ef01b54579ae98b2b4.png ../_images/9a359f1b586541efbdab9f8d4605c6543ad22798a38eaaa98b275a72bd5a34f0.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5e1655909851d1f96a82b06d7dd95d597ba4ca89cf9f615f45e3b34f9bcf8f67.png ../_images/5d6c3d6e013bef814189f9a0e0ecfe8e6ccde07a98c8d3da105227ee3f15f68a.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7d9a3704ffa0a6b1e2f3fa414f0b7df281add4682f8aca97923d1fef6487b556.png ../_images/f74c65bdaade7132944cc580ad7fe303419911264e7f8122b64fcd2b75797096.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/67a115574d2382395d203903cb0f66e7a874904830e478580f9f0fd8c65e4025.png ../_images/ec716e9843f7300b2186a25617b81f847bea20d7a54a6245eb7b69a2ad8be0a7.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d9a228ca8d1e797b6fdbe6a09eab8b9cca6140b8184e83c99273ec5c0ceee93a.png ../_images/586213379e5d407c671319386eda3f6d3d377167485ba00eb05d10fbb1b0564b.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4e05b5dafe939e0eb99e883eb7cf99244118ba907fa7dd53023595742fbb22a5.png ../_images/d10c4e5cefc647c88d2fc4e2e451102f7cad5edf1b8ea63d38bbbf4042635e05.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/001adb2c0c474aa02f92a860e675d303d0940e4da646083efa454167416ff3b7.png ../_images/f6a30a1d9bf919f157294ae293c5d00d34b992c8e677527871d82c11275997cc.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2666fabaa12f7c5de8ecb57a52fb9bf8d7b69b7af7df3f08e2a22e6647ef9706.png ../_images/ab51dac3a8ede9d5140bbab057a012004ad8092860c5c97dc53ad0dbdd5a4d00.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ca0bfbfb3dc14195fe295f490e57939804392ced7905af2e60db345e857ba95b.png ../_images/02fe11ceb15ad714f755a3161fed7785883c2f262385b184e79268c51ad4b748.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/45213977a31a672d3fe2efd5ce16a76af77b069ae818048ebe60a22b40d25cb5.png ../_images/4da9ac5f9b1061ca04aaba26f43a9b7b63713dfdfa8acc2a2c9e566a5943dff2.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a4c8bc172273b2d4ab203ce18aea2a62b9e2e2340fb9a0235f20e14d992e74bb.png ../_images/979de45ed1bd756169a9a37c2a555c7bc1150f015c0be89ea98c001de18bfbb6.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/69590e724b6a88789b5daabb918a044e7e7bd5221bdbf24e98c3c98b493c5b3e.png ../_images/d3a150e008b0b14d7ef39df9ebd116f3f587551f94f550d39deaa51d3cd870b0.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ea7a45088d08aebfa364723344e9badcd41482cc107c9001eb2d8a8a14effee8.png ../_images/0e1c36f2c8bacf63262d0d834a743abfc026675c76e99193fc1cbd54d3a897c2.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/22515316d09cf8350a0a76434e5c85021b7f8df9a1aa9ce900c679f9f0f6d3e0.png ../_images/5e618fb4723f89b18bde68b3a2ebd7a7733e14aa339b6a72523b4c6e532c5b88.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/317f228ac7214cd9c006fd230d34196033a470d1606f9f1f4438a587902623d2.png ../_images/2ae23f5da7d5b7afd2a0579aeb7be1f26d7b0e09144558eafb1ce99a54ef0e72.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/98678334d390bfa7294646fa0182ed7a81e1aa9d86b1531ccfa7bf6ef23217de.png ../_images/72a1c7a23d6238ca46163f724e3dc019243319ac89fee1306012077cb5304097.png