# Parameters
variable = "sos_min"
long_name = "Sea Surface Salinity"

sos_min#

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 sos_min 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)
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.
../_images/00f5d48dd226bbb5090599b7feb640bea3177465fb5ce70cd217c03747523a57.png

PersianGulf#

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

RedSea#

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

BlackSea#

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

MedSea#

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

BalticSea#

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

HudsonBay#

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

Arctic#

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

PacificOcean#

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

AtlanticOcean#

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

IndianOcean#

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

SouthernOcean#

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

LabSea#

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

BaffinBay#

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

Maritime#

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

SouthernOcean60S#

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

EGreenlandIceland#

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

GulfOfMexico#

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