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

heat_content_lprec#

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_lprec 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/e28943046fbe021d61ce957192d3a7ebc931364203c0151fd98ce00f25066e24.png ../_images/41068a4cc837e1d014acef204e310e8f04142b7014931c004c55106d51782c45.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bb0a688bf4b0fe2234fafba46be7f0139d577afca9f4e163f1523528408b6890.png ../_images/8a931871dbb438c0a6d418939fe2a88e22ae4ded749697c7d62ae1fcf1c29fe7.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/64b875ab85cc8dfd7adc2f375db93f595d61ac9e5d9186916fb5b334676e8253.png ../_images/d61a42c11870ea63b0167528cdf46d4bb98a45f60b45f244b16d24041e05d7bd.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8bb0cb651917b3d7a391376d76b17e8dd470ebd0eef26d3ff0203a9f9b8d11d4.png ../_images/4de1b8bde26088d915f973002065cf74709688a983be9644be2baa919058bf7d.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/622b16f9d0e040825b388a09e0f5e1e266e788c8143daacc840e5e20a7deb15a.png ../_images/65278d6393151562cbdc0496c91c33116579a98bbef86c40ea5587286fa84a5c.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/31b5a0775b732956563f277951c98df16be4bd53bc4b38996508e8f97e699dd8.png ../_images/7c4fdc7ba5b5766c5589ac8ffc1d81b257cb422e9216a6088676f2ade834f2a2.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/07368443c4073174c1f074cd53b701a322ce2106cb972dd68a63f2a06212da1e.png ../_images/7a4370e7b51fcacfb14dfcd9bd49d168a9ad30e5877a2ac6e23109309bab54bb.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/80fcc4f6bbc7ef6b0a5d07d0793562c881c8a5f4afab9f84516f3d56c4529a75.png ../_images/5b88d33bb17d426b1eb03d3df477a7c7d8202d53cdd82a5d45112252687ba638.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/debbc20207632545e284fcbd9e7d01ef2ed9161af65cf80df5446c9d54736389.png ../_images/8630737c6c6f3a749939712885a39304fb5aaf3c5b3ac8fd85962d19160d904e.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6ccf6d3f259b80f5be667d744d80bbf225f076e49b688f78c696958be261de68.png ../_images/baf9e412091f78f7cc3ffbcff18db201b89e2fb9fd58cbbc6a49ea7d24b64406.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/70ef9e386b17b84247889fc589129d867ef49e4d624796d349827a565b46ce93.png ../_images/2f954b0effe61894bfb504e35980ac593f8c827ec1605e0be7359b8836cd5efa.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/46d1d13f65699ae5714fff25c7e956a4ad13d926cd79f48bbe48b1eca489341f.png ../_images/25a5776dd2daa042ec1989fbb8a13d1072731928442676a2f658739a036c2e66.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/40a4da1a2c5eca5419a09be3c42cf9715326addee1948bea258c839a0f855f9b.png ../_images/7390b1ba7751be7347c4059b4387a303d28b49b2b13d61a9316424b2e6fd29ab.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b96b95513eca6d9e093facf0980b90b8ac31f305233aea2433666b353321ee26.png ../_images/62d831e53ad30e267712c111514bdf98273ff28ab8380216f933fdf033156395.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b4e0c3ec2f203b44a5a973ea68e7abf6afa414b50a9a75d1e83d1dcbf4559088.png ../_images/1b57625ceb104ee07c9e89a99175bb2c2e5fd16df97ddbd9eff765c05dd4ce89.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/70f4053a3bc332db1b6bf4652abdcee85ad932ee788b9a56c9df9fd7345a32ee.png ../_images/c98beeb7bee00833864a9de491f6439d4ae9ac2d4cf4090f60bbcd316131b19a.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4848a7097d741e5ba4af321dc855b3e0e8e03d7ac7fbb373c73cda14efb60f4d.png ../_images/3366b3a9df43d07ca65c22d3cbae71e6c937df5532bdf65b39410c32469013d4.png