hfds#

# Parameters
variable = "hfds"
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 hfds in different basins.

%load_ext autoreload
%autoreload 2
%%capture 
# comment above line to see details about the run(s) displayed
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)
    
    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)

        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/138676f387f1289641a5a59b49cae9443ac441da7907a44f5523e8a588d84398.png _images/a1f2e1846e064017d04a332de0219136e396151079822461f6c417354a9fe50d.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/36f7285814b560764ca19fd208dd079992eb22eb9f2f635ff6492b2b24089e3d.png _images/4c1bf713f391d6aa7e7298afd8f7aa8848bfd37334c02f4fbe0c77115910b01c.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/fe8763ce793d7b0d914039587ea2cec1a313a62d42fef5e6d6cdeecfa91b6eae.png _images/fb05e26bfd5548b83dfacb8ba1563a0d42ffe5fbd8866c812a2fa5a0cc0843b2.png

BlackSea#

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

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/0bcc657cf617a381ab8f1ed75e3c876a241544959edecafa955a3abc21698539.png _images/900a81cc370e4f5c423b854d639cfaf54de21984edf86a28d5287359e957fcae.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/20fc0157692193c1df2bf8f20f428088a7278e0cdce3f02a5f55b5757fca51bf.png _images/a9a46e7db969c5bf45522571f00212185a243000b37e1978a438564862cc7bfe.png

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/784ac2899dca27aa3caba13553ce095f18ad43db4950c05fe0a21380e6654f7c.png _images/f74d751ec96ed1f3c8ca0579ffd9db401dc7a1c1077b56d50157a77083da0be9.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/2da3b7e2ed57403f452cf7c7c361720c0acbe3a026e170afe6d0c7e623e4c21d.png _images/9dd83e64e86b750e9da7410072e4399effa050911d32b2ddd8b25a25f77aa749.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/4a61ff1c43b17e5368f0e27a52a076ea52bb7e2e8f8f44e5befb6e5587398966.png _images/1d481be43c937e859fa1854bad5f0622b4144ab830e2066d79fec206e9ebd340.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/9841428ee47d9b69d3466fbd7e6b0aab7dd5fc6729406d47c180f619a56dfe4a.png _images/c57156891344e1a9d7a4d1b4b404c4bc5dd40a12d66d7ea65e0613f834bcbf14.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/ae6e630ff5ade7c6d3bd85a0b5949b84ae1309223ef3f9c02ce5fb1098d8e34a.png _images/46ca85eeecb2e6b4a378055f55f0611a15d00a7068e7973c9c77f9bc4e58e9c8.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/ed53412772d72efce9ed4a90ed13869a55703f52869d2d069a4d3ca3d4fa8af7.png _images/0cfa2756b60a8a50597cb66bc86296d1bba253c0890261bc0e262a613a056b15.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/7f3c30e048d04ddc62dc548dfe637ab8a970f7a9e22c0c1832440cca1e2dd03f.png _images/aa8a08e03c41b686eb186e196e337035515f3c9557c86214a6c8aa47db343d3f.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/22783254916c73bae757365a7095e48b03e3cb110bc376f3da0a9fb319166a2e.png _images/32fa82722b3e0b13c553c97e30793cafb5ee089cef9833f7340c229f17ee55f9.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/93bc5d45f88cab389c2376b80c6061244b70e6e9d099d7b9440270698f16f27d.png _images/8957bd78dd4a333e97c5aa236b9a743fa71fccc1d5196ae870cdbab32783469b.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/4af72e496d88c301cf937a4b35a8ece336dd94ea9b3dd87046c613d76bd1afa3.png _images/df89041ffaec8f5d27c2614634bc01ccb6c03b2c20ea05682ec9030c51392c61.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/c85c65a6b06abeb9f37088c19facd6c3917445f2d2b881530a4c9bd58984f14e.png _images/1f9efce292097dcdbff709fe5b465c09661c25ab2d7a9f1b253502d26c22008b.png