sfdsi#

# Parameters
variable = "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
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/aaf41e87dff9ec90fdeb132afa867587548908eee72de2037a4b94d9ea0d5faf.png _images/8506c6ea5fd6a51e2f9ccb22dcf5350934a3ad283d9843d7fa5b8df8cc554ae6.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/775299b1f3e72932e692366141de67769d675087f204099fd698b2e38c492e8e.png _images/17a99265de007c5495862206c6d6133fe5e259f4a7a0aabf3dfb8ba450d63a11.png

RedSea#

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

BlackSea#

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

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/732d317afdc1cf6b0efcc573f149775629835ec8963bb7c5cea56878d49c549a.png _images/3b9c6ccaa3eb1e9c615509144e2d28132488c73a5be8adf485e197d1df4633c0.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/f504fca5a9226c6960b0fbee4e66eab77f16e9ddf228826fc09d33c5dbd71134.png _images/150529ba824ab481b1caa80e119dcd300dc9ee4a80108799d82e22af4a19f7b1.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/2da9b24b2f9fef2417c9d5f7238c63e7950d886e8f62c716cf5b59104a044ae1.png _images/beb1161462662b499b2fdbfa1bb3d401cc1194ade439e4b4cf9e895b3910738c.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/400001ab7b55949c36acff52343397365c1c519f067c126403cee6ee096fd52b.png _images/bec62aa0eaac8cfe03593df69606839807967be4d88be9d3b33d934464bbba10.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/09f22c299c45b7f94a64c069ba52d2ee15d32711237f84277e030125c39f0282.png _images/1c4bdbedab43c27804c046c9c776a2aba27a4a89f617f5527b3668f69fa43c4d.png

SouthernOcean#

reg = 'SouthernOcean'
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/67c93868cdaa648ed7b0634934e23370790008606f775f2963d15349c1d64ab1.png _images/125b1813b50aa0f2db6d127bade0987570eff3d52f22ce599b833c39210f97b5.png

LabSea#

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

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/833d131b2010f24d7c472cab73ee85d3aafa5feeedf53242a635e38e9fb4b83f.png _images/dc4afa75b3c9d83e8bdcb96b6d165dfd4ebf4d00e5859b2f41fb4a85d2347cbd.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/7ddc2aa73890f19eaa48b59a2b69856dce16d0b4b95563743c721ed0befdef93.png _images/acb6aaf9bb380bb72ac51c5fbaf958c95b377168d93348c9f72678ec3bf45f43.png

EGreenlandIceland#

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

GulfOfMexico#

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