# 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/89aa9b9aa0b925ccbcf371f3f087d36ebee3a117fb16dc1734cc703e90f55bef.png ../_images/0d9e49d2e2dd0185b6788173832c8149aeb246d14764aee6505c2638c0145538.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/432c8fce341e5d75486876e96f62fd889ff97984ad5d9fd32405761c04e7836c.png ../_images/b01d1be5aeec30aed07d8d0d1e9136663215e30bf09af4803539f8c3f19beab4.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c0194015c7dfbbb74acfb944058b96a2066d129511221fa56816c292633f6964.png ../_images/0df40d81af3afefac94c29a52a00addf67333fba01f9cd01b678a8b96c92ac1f.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1edafa9e0b26cc1521bca36c87f7df85ca4894152b40f3bd05cb3002d5b3206d.png ../_images/fb49607fbd9beb64367f72491fd8e11356d9baa9e39865680bc4d2cc146add54.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/90325ce047e818dd40cdae68a52ce0e7202172f3939a489cf44b91d375043761.png ../_images/c66c2d8f94ced5ddb313756284ac51bf88f1a2982a7bb86c4720a97b7bd0fd67.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bf61b9a30935f570fc41eb72e69dd10310187bef11c4ae5ba2822ed962853176.png ../_images/dd73d91e0cdb967d42a85aac4031ebaf91cb146414966bd5a870a150e8b6c8ba.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/26c9aa8a02adb4dd40978a5b398aa991c2561dc7549220cba69c672aaa863766.png ../_images/43094a7a2eafc88875b1012d384a9e3c025094efbc665f00e94c20546ee97128.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2b315aa0e8c4472d62ca8f11529e18f879d2afc195291086dd4301063726f4ca.png ../_images/2aadde4ef5f8ec0b19b58dee8736ade9a2e0ad097632256f04122ddc63795093.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4a62fd8935b0e79dbd031f1ef2e53d01acbe6c78d9ecb69a29be884df07173a3.png ../_images/cf30a1543c9ff6f03d811e5c520d0c288f5276c37dca204d413ff2889027e95b.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3c0364c77563e12955959520f69e840747458c18d9a74fa0aebcb28f83c35812.png ../_images/27a543820b6d6dfcdfcb9885539f96d5237f81fd462df417b4104838ed617b9d.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/841ddbce3b76f33f80e05d7a8970437aeb40e42ece39bae2cb0a5b6be645d037.png ../_images/6adfcc9e340e29bbba0c19a705e51269418350633f269a48369fbf65a6baa3fd.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5544a4e0d168a439f0a04901ac3d5f38c4afacd75b684a3adeb8b091150c5687.png ../_images/b0059a41abfdf4721eaddf8f36d9945e01cde51b50c901df7f6c2206931401e9.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3e119c073bf9d80fb9e563ba5260a7529f105b649ce57f7382a2d879e64c4f4c.png ../_images/aee5c20a7273e7f6dac0192d6a86bd67ac9aeab452bab521a401502b8d5ef621.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a96e491d10b470f9ca877158adb56ba9fe255c0215c62628a67aeb448f5b4c49.png ../_images/267fe5149cf4a3bd914d4da8af0467fae50ca0b7934ae321f2c4b181c050510c.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a154dfdbb87edb06e96a9f406f298e6f434223d3aef7fb36f0cd83656e27c6e6.png ../_images/79b43fbd9c5cd75be3d945a1b37c6c4160ed5b7a9aa451457a6ff7d9ebca45b1.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a41796166b0ffd2930a19f8323d67756869f249589668afae98cb3a4ee9d951a.png ../_images/3d83970430fb31d9fc3e76ab0ea9129929f24c1c57da32d4688c5084aa9d786c.png