oml#

# Parameters
variable = "oml"
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 oml 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/518354bc825fd3398224d357256b8551afbd5d08ea59a3759d8ccde452de348e.png

PersianGulf#

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

RedSea#

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

BlackSea#

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

MedSea#

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

BalticSea#

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

HudsonBay#

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

Arctic#

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

PacificOcean#

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

AtlanticOcean#

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

IndianOcean#

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

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/2b1230ffc9056cc73d3b2b98b9dca62d13e63931038ab03617c2fcdb4c5eab26.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/273afd07c040f6763a412d27431ae7274589ae8f3752f682616df27125a95d8a.png

BaffinBay#

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

Maritime#

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

SouthernOcean60S#

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

EGreenlandIceland#

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

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/11f1f99ee93bb2a9f8f8a0fbd16f5172a524809bed09138eff03b87309cdbb77.png