# Parameters
variable = "heat_content_evap"
long_name = "Heat content (relative to 0degC) of water evaporating from ocean"

heat_content_evap#

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_evap 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/cf88cd7c9f8b70972296c0e149be400879975126f4639e2f92ce972ce7317378.png ../_images/8e163da61851448ff369b2b79baac8fcc5e8db51880f287e2b83a5a75b24f9ef.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/72840bc830971f7ba89a6ff9f416e572b671a2ac164f5eea748fe735c71d1b60.png ../_images/4e636608fd586ac508914e7f1dc082a3aeae06dec6e3b91e696dbf738dc4d1c8.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/242630073e5f0b78e70116c5f4ab51f52d5be861d06031d81894758db63a385e.png ../_images/684cfae7cfae8f58cb76e2ab1a5a47160a18daac26148f44d62aeabb6749297b.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c18163d51e8c7b1000e2cd87a795eed23e03171387de8d99c1f53a8f66ae706a.png ../_images/e7b817c529135f543c19e203ea87ab01e0f1bd7b579d83b9855d31b741222b92.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/358895fd60391830c4d0829f6390a1dc220569f9269269dd287117f2e3025187.png ../_images/131017665e2e4245615475697442cdf6b7b9c199f6db1b0fbdb725117e54f875.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4bbda4318f1b83c380af9fd34414ea3c89b102320764a4d4f3c16756d0ca4c39.png ../_images/dd2f685a848e2f341515d198429ed42edf3675fda0c86767225c322510134a63.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7dc0e0018db2320b957b9900bae7d4f811334a10917e022613fd8bf7d226257e.png ../_images/badc256b61f9ac7cdac110631767899b4e3ec024b9c5f0170af7734805cd34cd.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c104af4fc68733c094f11fbc71b1b6146ccc4f2af16e3725fbf9af5b62901392.png ../_images/51dbc0c726005344893cabb66383108b1a0e1f47c70cdfe45969a2969a757639.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cb135f027769c2570815745627af34491c5b0e53261e72d31f9285cb49da5f38.png ../_images/a3db512b02811c647a107ed4748ed2eea17638afa41e573c1b35264f960e9f60.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/46a3573cdcdded003d694d8e12ab40301c6a82176c61df2e3ed3dfcce499bda6.png ../_images/f67be3cdf31253e3ffc07b940d38c1496b6e483c3e00b97287081a85b1a6aa8b.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1510b2c6b8d55edb564b35dd7ecba8d7bafb148c24d9caa8f6bf2f7190ff1eb1.png ../_images/3d0b6ee693887006f652baa9c1812887abdae31cfefb6af39a8390a8e6e47be5.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/01e1992e0ab8d97efe3e0e3ddf22e081ef1d02fc40d670dc91678d6647af7325.png ../_images/409d9e630a3a8f3933b832c4f0ce58582397a1b0f5bf0a0aa2f224af055dea27.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/16e11a5a0f417a2a1d57e96fe36f70698e4d29b8b450f0d6dda152af2cd69bec.png ../_images/194b89c1ed6206eb9f42ffec7b0721ef1ed5bbcb75720df7b6eabd35ab2d246a.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9350c9e5898707464c8203203558234f402f0e306385f9a3a1f86514a777843e.png ../_images/5d99f169835ee33f3712b49ddf0dc94a8eb74ef5f15ff43267a8f01edc12b146.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b26e9c82dec0436db430b4c76c14f2ef71daf93602e3cd65d835cf8f3548b59e.png ../_images/663d7cf039c740aaa21db62effd56a6bb4ccb0bf154cef4e5f800ecec883a45b.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c4442ffa2ec8dd38cc865f6c75f534fc6c1ae1e3b616f8c8d097fa23b8ba57b9.png ../_images/cf2cfaedf968e7bcf2484436c983e75ba9e422120ee6f067bb42afc74e72e028.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/845dfe1a4635bc8a05aa4ad5fd9d86344cb152f8b07fd66534a7895f1b32316d.png ../_images/3c1bdc1e856be70dc414e208cf1d31f5b06e673f85013b03f66fadcd8d3187e6.png