# Parameters
variable = "somint"
long_name = "integral_wrt_depth_of_product_of_sea_water_density_and_salinity"

somint#

from IPython.display import display, Markdown
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.

# 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
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/bc5a93b5d65dc636579691b5b1b585c5f760e6659ea3d921b393113b406ecd83.png ../_images/12bb1c2b6f7e0c69982e31861b873e61748087d32840bcb359052e0375b9059f.png

PersianGulf#

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

RedSea#

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

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/65e0d1c48089aafee23320b6ec4fed81246fab7364d6337b80328adfb0f2862b.png ../_images/a22ffcdf8dfaa379d2c22a21643ace627b726614c9d59020a53874dfd7cf8a63.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3e2ba89e8f7e423301656ce479def18154c3d31fbb55fcad314610b3468317b9.png ../_images/44ca915ce3006a0a0c12a2034bbfc146709f58217508d60dd0926003363d3b6b.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a776105b20af54dce799a527e772b1069dae3e7754523d13e1fcae22bf55624d.png ../_images/3a38ee66bd2b5f30e669939bad3f54d0e50ed69ffaab0d680d8e82a6e74110c4.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/57b90e2f9ce32df365a5bf9bce35d9bae780d7f23e58e7b68c6289ab38394dcb.png ../_images/67c1a4dfcf54b245c1c96b3c2f19f2ebd37cef9d7eb7f062dd6ed5f1ac61ec83.png

Arctic#

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

PacificOcean#

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

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3f16888d976348fec468dceb2b865803ac571a99f0dcd8b687b88c11084167b6.png ../_images/bd542c9a50e0f42ae1acb568e544d58948ea064409e78bb34d7ab0b0db8b7b20.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/62fecb525a2fb0ed0fda66ca2bcff705cf96e30705d9b5f02ac670fbd5d4800c.png ../_images/15bd2d88cfa9c04c2ac07a22ef173574807167b8f34b6b9b7d87d4d33e97e6b0.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2d85958006c61076e36951e73f8027d719906aa15087311d95d613eb12080bce.png ../_images/a32d23e5f1c0c32e9a96e4338cb719a960417677f6b231cc6f41c60ea6518ddb.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1ff3f69eab5abb8f64dea6847932ab3bdf59dc8ebb66929508589c99e824fc55.png ../_images/ec3c742fed9d33cc1fa9ac89950f71eab0bf3c1c1dcac171c08ab3ffad7c6b6b.png

Maritime#

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

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6bc8d90af2a18307cbb16531c793569c359aa960627dc545c3ee45ec5e549159.png ../_images/b2cb4505f3b1e963d2a634bae957e40e24f8050e53713b1b765ce7e08405b95c.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8cb473a611facbf006e86debcd1f52b4203ef0c07364be080da86ea411e8b7d2.png ../_images/dac86f039ad178f6d4b5260923675caa6595b7bcfd236b93a81a6be88624c794.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c256f8a06362a0beff2920e78badb55fd0bad7236cd122d31cc74ad32a3d0cb2.png ../_images/187519b62106467d6bd162e9ae1003d483a6f7f72038ec207079a4c786a8f070.png