# Parameters
variable = "opottempmint"
long_name = "integral_wrt_depth_of_product_of_sea_water_density_and_potential_temperature"

opottempmint#

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 opottempmint 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/19a0c0aba1d1a73d1a4c9d885e70e944ca7385149c656ed311b023626da79215.png ../_images/035ab5190d478616aea61561733a20780e49c241ccec58c615994d22ad7f4bda.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/481e1f65c61e90b56cf25c2ace5ab1d72bb8b45e195a9bfc66c165f61df5260b.png ../_images/9565289d32cd3c3731831fe10c66d2f0a89b7804b4e2d397c41328c1106b90c2.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/05b326d83e8224887bc7f736b0b920b793d4fb20d14266c946af917c92f4a676.png ../_images/6d6761e3244d20de18dd60ae5b2e44d3768f60332356619cb7594ec1ab65dcbc.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6b1e3ed2cc3a473f6465baf0ee99d3160d7ff3b151b3581685bab90a32e26cbf.png ../_images/168915cead1c0f047f0bac9b8165d09c075f05d4b3269a68cf04ff25cb518e3a.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a87422e05d2f5baa94328f1c430d50d9945771d4bc3c8e4c223aebb9605c137.png ../_images/4b93a8295b1c3b6cc5136df7583746e10423683b9183d4af1d46b0beaf52a9c9.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/21e89b9c505ffdf78b9ea37f49368af431168101b4c877a14fd3a3ad0b51ae66.png ../_images/82a02f0536a221136539fc8eeee969667b05ac989b62876212fe1dba96350276.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/864d27c1fc1cbc6f449baa5a1d334f1319af832c61bcbcd21427581dadbc54f8.png ../_images/901b1d59c0caf1d74e664487aa913df17ff20953ca369a687821493f5ad4ab65.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2998a70bdfb0bc336a719a65c4c12fe2b4f9e7169b3cece07f749bbfb0bf2d8b.png ../_images/3c61990206c54658071e9ec5dde078383ff40f7fb7432ba9ee303615561a4b8c.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/918e8bfc27a77da2282ccf2d390dae786c4a2a5e1b68af08a6de494e9d40d0fa.png ../_images/41ca0f41b717d3efbc96f46121e6ce074a21c443f1fc8d7466f22fff663c975b.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/34c13d68bcfb19aff54b91cb29c2760aeedbbace380a939d27d2ab13c81d23bf.png ../_images/5ca41862e94b447ad27b3ac189cf978f674cb5d1e85919fefa30a40f45f43380.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5e5d861b85d036af2848c05105f8d94d0b0cac1b143d275ce27453d8c101cc19.png ../_images/acbf43bea6b3650d35f663f7127cb832d6bde91f951015fe14c0d71166bc3bd8.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d236125d828685ba4bba4441b7cf240721899cbed051f8aa7375ecf6e0d0889c.png ../_images/39f7f8e7ba3e73949e3a43d2e276b69a23f8e7dc41b94eaaf6e8788f279ae11a.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/99c4f0d7a369dc749ca1238d13c00a375cb931fd8922a13564e81e73011c606d.png ../_images/b76a9fb47398f3bcbe57c78dd96e03f35b55e8341d6dd9e43e43c531f4b56e9c.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/50e8e8e3eec968e0e349b53f58bd8d34e8ec1b01b8c3d25d26255de5c589b49a.png ../_images/b21dad11a8497d69e1cfdbb90856cfb228e09777dfc836d4dd712c9145d70087.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/139d6193168efef00ed0228f854c3d9df6582478ea62b7b89f57895c2c34cbe1.png ../_images/3d0ee05757ffcacbe678b9e7972a38652ded10e4562fa595f07a9568e2cd797e.png