hfsnthermds#

# Parameters
variable = "hfsnthermds"
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 hfsnthermds 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/53d5c20761b9199af3db71458fbed7964dfd31fb8c7cc5f0cc20555f7b88195d.png _images/ac6d3a9de744840e4e2b6937ff789d38ecf04dd81ab5a8d3a567901ecc5628fd.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/e4f4149bbbdecfb3accd621cb704bb25dea8fb87673aad4e4f2e511f6dbcec12.png _images/54ee2a4be6cdddeae9daba4dc1e1ac6aa0f3d353e9544d76ca10022e575787cc.png

RedSea#

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

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d6b21058e03d8c8070a8f146899a1d12399fc43417706b448874ae5ed597abe7.png _images/635f27b7dd004033c05289fe96b0bae2fa14b51e7898b4ba1e6f218cf875ba8a.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/dba2e0381a6b280a16407f1b3484679955856b7ebce670f4b8111ebb3889541e.png _images/f59241e5164c1ee6a13e757d456584edcb567489d6d7f10f6699b225997bc443.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/606e808d71180711c28aea63e0a11087b04a249ffc39b6e0c1495b0b16edb7d2.png _images/819df8393c76e1c266894367f0f8a01e8c6a6d9acc2e67f2bdf52cde047cd02c.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/cf6cb3dabddd5ac2e4563dffa56927736cfaa49e67fdbe58c25b1bbb2c39033a.png _images/abf0d3bfcf79ae2ff3d9189341c020b368fe989c553ca512864bb6ae700c24be.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/5ee6dcd1ca300e00d6b11fa5616cb13682772d933ff592e65ffa3a11703c461d.png _images/9fd46c8386912d2761cfc93a2119db5ecc1a794b2f4819498f08702c3274d8ad.png

PacificOcean#

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

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/91e12210db8a2b7d83841f26fc089fe445f43f39ea2d7b86ed173577747778bb.png _images/be90af4e51f807422a530ca6c73472c3fba2b93cedc535281e89568afa32aaef.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d3583d9a7581f6e1d1d8408cf753903ce5c647ad16c8b722d32db1e013c15ef4.png _images/bf39727ea591526ffc9c71d2529b39ffbfa87395be481fdf65eda7221627e82f.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/bab8a579972fb66144b1250a21a224b5eb3b1b9e97c87cccbcb8771237bc1a1f.png _images/48bdf67dfe1bdeab90e6c6f7036018ccc7307d71c911b74a42a8a8015cedf0fb.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/3a92f7d5958d8531ab0434523c973b89acd61393c3cc20ba275483b0b6c74f29.png _images/7184c0b97326a4f86eb986150bb9b69b0d5d233fab4ed4090072064f7eef68c9.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/a21a03ffd205f85eaa14905bfc76d5b1b51a6e6b955cf62cc3f3176767e4a86c.png _images/8d2abfe259f0599cae075f839c244e883c0ec26ede01f0cc6dc6952da6bf90f1.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d4649d512e3203409b861af228aa20e6cade42872351d79248ab94a9e7d891fd.png _images/623052ea48af72334c38c79b72420c77367658e73101da45a160b36f27b58716.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/fd590b31dc57b5884b809bc6b1e3bf8516ffe7e5e995bab304c932c16253fe9f.png _images/5b6dbe02b3180a048b617555a845f7b5ddc31e1e840497611f1097c7473231bd.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/9953da733f3dcb8a753cc354b5122b5da8f45bf7c9c8072e43f2e19cbf161878.png _images/17da838e718f4cbe58ea9208aef58b547d5fda3eabd8f42e4ab9c43e164d0da4.png