# Parameters
variable = "heat_content_cond"
long_name = "Heat content (relative to 0degC) of water condensing into ocean"

heat_content_cond#

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_cond 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/f803ce8b2807820abb44c0e66e516d52c695efcba54054101eee470a27ccd36d.png ../_images/0927e9a7af87b8f2f7600e292deb3563bff827b89a5dc1f73175fbfd86021e62.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1bc3f7b59c8efe37fe97f9acb691f77d36cfab15ff49bccf9e0ebc4353d1af65.png ../_images/e5071da5764c34a279aeb602f1ee331c8e423f45770ec6a90394d00ec30a5d94.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/73858b10d49974dcd3750864d2759909dc1f8e059230bb3b6515563217e4d05b.png ../_images/ba55f31904bfdff37f3b111c2eadbb56862f0e6eb335691c34e1ba0311e38dbe.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/841e236a109df7f580c23cfdbbba94af6882d0928aa9a153fa7a3bc3c4a6db57.png ../_images/64e2a7890b051fb5c02eb522228c401dc2bb183537055415dc3559f8d04c6831.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e475e2d637e9514ffc45cf42a48732160d5ddf84c2e8c5b6103e902b527ff920.png ../_images/3f026cf7efa513af22e1cc73800dfb88de68a543ef662d9c7ac54d764ac386d4.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/560b86c09e0e769955257e3dd8662580b10fa6be2eefece0801c465abdb52edb.png ../_images/4ce99a2f1c2cb850ef4727c68a63ec67e55ae5d233fda0f92ab51642e6f56f5c.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/996077674614af1ed5b9aecef41035d81be4f2d6780016185d7ab1e5fad4c686.png ../_images/28171b24dbb3332c66f3485f05c3c03fa00676ba5863ae9941477f43e4b3ac25.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f57ddbfdfce37a0deda46021538c44b3bb9f75491b70dce126ec149d29672f34.png ../_images/392c6e0aaf5a720bbfa02280491a526263dcc0c9e965bfb694efb52a7f67fd45.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e71f1ea71c8b7ec79ab0ac2801c8d372a785c75637814d8b35b75f183e0e5618.png ../_images/cf55c8cf78b215a92fabede2639d836d94f3da154f86f0a96d684a75e66ac1f2.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7723a2b8dfa39f3cd4515b942f6e27c903e3b45f931045f006ae6e16059654e2.png ../_images/4d2653af82ac27f5d18c7ea15eebdb128921fc880242343439c8b19a36ce4141.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d93cdfedd927c82e8bd4d61c45e63ecd8c1add487c3f4af7203d494b48fc318d.png ../_images/0875176bdc67d84366636313343419805d65400290f76462df20a48450b70a84.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bbd67df850328ba4a862e750af3ac376c3c44bf4a1880b4ea685bf8e799261b8.png ../_images/4862e6f03de17d497326843ab7e342d301db471d9800898205ce52e2720fe846.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/47203c007a7417a34fe8bc0bb16b09e8c6f8d79444f08e46be43d2f9f1dfecca.png ../_images/cfe3738b5bedb457dfafade5a0ae1e9d5dd82776edc8c106350779a330c23f9b.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/91f3b864f7a7480fc51ddbcaf5fd1e2651cfeb396c9fc4a7e26cd5c779624303.png ../_images/381c5e1b5d650a0391a85851956908ef1133269a5f2ba9f3405d2a60c6704f16.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ed4016bae49dba49d9f2f232854aacb131297b96b79e559c877eb05d65f6b3ed.png ../_images/bddfd0e12d7a1b482baf262ae43782347a952bb7c9b564f29d0d5906e7225ed2.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1fad0671a36a2bb964649b0ea990f528685b17dc55fc9164095d9a1d01e48f75.png ../_images/4b98d5bd3d7208d6c54dd9c619b744f9a378bc286d062b4cbfccf5df62b858dc.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e0783a3bda168bcdd9d30c09e855e79dc671ea99150d02c9de6eb3ff1e63e33f.png ../_images/92d96ecd35069f2ab047b754e256ca089aea441b2b8962859245ab3079a9a3c7.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8f11f34ad405719f59288398ab63f8b2c79e060f6a47e572a0c36a6aa7f882e2.png ../_images/93dc31425082bf2153344b1a24ba416805913e4dfcc7100ecc14d3aaa2f459b7.png