# Parameters
variable = "sfdsi"
long_name = "Downward Sea Ice Basal Salt Flux"

sfdsi#

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

PersianGulf#

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

RedSea#

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

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/49388127fda190db615c6098a7cb6e784eeb6e86657e15381205031516410e31.png ../_images/52ae58f064d89045b3e23b4a5a69579c4972092fb7d89c7e1e934ed6514a6740.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0475766dfb95c90e85c289893894cbc4b507bd91761b1199bbf7a65190b6f649.png ../_images/cad677680cac7075d6795a7dc2f0ab45fcacd238a1963c33e47ea151392e79f9.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/95b29d456d49d4e0b020a5ea03e8b311e5c13d864e76fdbb6736558c72959f2c.png ../_images/b5d33dc17865bf4b28692eb645eb5b5456144ec069838377646d0a11839d7b66.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7097c8e35bcdbb8d554db4df1fe2f2651f171ca816b68193e1de3426f2cd6063.png ../_images/329dc6a4d3d0b6b809fe245f526d937b226da698868dee4dfdef482e9900fb0b.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8f5dcfec8bd11fd411ad79fc6bcb329cabb4d4eb19bfb6e8a36011bb6090d575.png ../_images/98fca1efcd7ab6f7e4982cf41a23d69378b8c9451a43030169c5de53e793057e.png

AtlanticOcean#

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

IndianOcean#

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

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2288b7b3d891bb1cf8bd68ed4915d613dcbad8753f708b5cad3ea5730be2e23f.png ../_images/576441f217973c4c252d6dd2446f2ea974c8aa4cf596009f79ac22abad466091.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8c2b6bd07ff3498160e9b4971f890da42880ed9debb5f9a3bf78e1e9fc1be49d.png ../_images/19f562d4074ae24968664cbbc11d20ddbdbce85ada63b10a7bb94fb999056d4c.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/63ff1653f65066c286b69f498d37a4b15800cc4e797b513be61e851eae91d6dd.png ../_images/c636e955291dfc4840eed6e8d8011049bb0a93ca413e50a07366aca8900ce771.png

EGreenlandIceland#

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

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dd8bc0f488994eccee9aa000b5986e1e277237868c4238edf471d226c717802d.png ../_images/8e384da5d1182fe29262cbf78c406de6bc69d365420bd6293cd692d874e5d800.png