somint#

# Parameters
variable = "somint"
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 somint 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/f8f911d76391b7e149c18ee904f25262a8bd8d00033b10aa4a9f3f105dfe0b47.png _images/5920e5bf0b32203e3b9168bb22497953d0fb0bbd7da5c41df3a83de4a9c74083.png

PersianGulf#

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

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/86732c882f10fe1ac458ca677347317b428b424b33c10f73974475bc1fe63144.png _images/344ac321f22c3f6831151d6587b9b279921ee3f1831e2626d20b6785815f7f66.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/4e07e206770a68ea43525eba564d4cbc9e956d2b14067ad8cdb5aac716b3e62f.png _images/7fc4bb719bc1fb5c5b5a7a0aed1afdd6e12f2cca2918be6ba9668c67f04cdcec.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d291a566bb34167bdf7abfafdca73c2c17fbd9de6685b39cbba1da6a208c67c0.png _images/61de658e999ca0204c08036fefc10f610605bf49dee050d2cb5b91ac5121d1c4.png

BalticSea#

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

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/3f8cb5b823b16f3f53160ef6f179844dde4dd96802fb4a37f213f6ba62728575.png _images/669b1a6378690fbced9b5b954494a7b24fc9af53d2130ee291509e545004f0ad.png

Arctic#

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

PacificOcean#

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

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/bc9e3a70f95a8aa867b8f12c31314eb1d1b553fb717611e32a2dab513c43f2bb.png _images/86ab0bb248e1f99a17e6018580d1a3f61b98b6badb351ca501fc15f6dd662fb0.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/1ac894e7d015188e96df3bc0c13945c9179406108360210c5cdd3547a39fe8dc.png _images/e6d8b5122c343581c827e26da577d7b03e469f7ec29f30f841b244ad533f3b5b.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/72b7f7b18efe82b98d74a9308a5b99e2d128744116c07e44ef9b2f3101b71445.png _images/4dfff7fa31849de93c5e842b2b272ec7ead5ed58e2c3137ff2a337666ad126ab.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/b7d834fdc33bda74f1cbfd288b2ae2c931f43b51a66bde0a467d3989288929aa.png _images/7c2b0d9d6f1b286838e5217b00103c63da61ae3552df4f93a655b8cf20d71d62.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/970dc651d8aaf5ef6454d3ff943e8f2aad10be100f08d05b096ec9a380e04937.png _images/5ef3b9ab77d0b84c627b6a90490664a657bbfeb3eb9b4e717adb8d9c80989dd1.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/60dbced8049796a3b7a110839d109294a8331cdaad907eb81f77d7cd28806b98.png _images/9737ea90ccc4c97daf5fd0126f49082462c0950fa55dbefb02436bc39fc83597.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/8e6971d517f4306f3aa99141d5984d6ed6d35b603dd31b3558a4dd240b4e87db.png _images/953c8a337283fc655ceeece5bc001d1812a67b51a294e95eb0e652e91e7f6dc9.png