# 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))
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/5fd224dafd66fa2112bba7ed41b229289a4e142b7614d2de9cbfd4c88d1862f1.png ../_images/e2a957ba22459e4e76c556cfc43f80b74e6183e0ef7480e5101a21301d26f93b.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9b624706436ad80161b8be540f8191585e11f029ac557dfc4e7a71ff0f526fcd.png ../_images/6528bda8643dd9b53f7397c27a333b3be0257f7cf439ecaba363f3bffeabc2b5.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0016b78433264fe3e17b7f0591a83e8784fe06d6eb057a950957171715321cb1.png ../_images/63ce27bc47a2da4fa9f3c42672b4e72da3d6983290781c0c2d1c9cd70d40d1a3.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3fb0f9e47d6b1222ca30e3666c21b685decb5063807c88eee837e66888c1f903.png ../_images/8586857356b2af4edd3fd1542f9f82e50f33c6e7601ebe098672cc4779080757.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8196dac4b8ccd3cde42d4fb016494fadfda9da0f481148700aa39fe1faa17e87.png ../_images/3232aa2b6f1eeb58bc228857c472b00cd5bd0e00c41b1ec121d056b942bf92bb.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bfd45670eb8e799f05e124be1486c5cc0ddd11f1c7993158e83dba558c4d679a.png ../_images/85240da75f0e2f338686cbb6c8dc566bb28779a578c838bbbac122fb1f8b7f39.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0620a92035fb9f71b0fa3ffcba435628021b0c878e807d1464fd60be37a5c64e.png ../_images/988777d2d2487ed1bc61a79a2bcec32dd390bae2dd92283f4e53330ad57b333d.png

PacificOcean#

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

AtlanticOcean#

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

IndianOcean#

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

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/984fc903bfd3f915c56c34f36bf65437312896fbead8c2994f5a2cc0b05fb94f.png ../_images/03c2146bb962fdc9ab5901abb29943ca762355b330ab00cc754e29181c8f2856.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7bdbcdd41cfa8f602000983927c561300962989548d1d3d3fc8acb1ebbf008be.png ../_images/1673f46e57a3793dcd20bf58b497b07138c1fff7898ed2dcff0dadb86166578b.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4bd595de559d728185c3260b22ff9d78337f3bdddba08ea5bc9027dbc2d8dd59.png ../_images/c8eb5ced09f7df496dea972ba68c02d60d075c3bdb7e6d8c9300412a30bdc397.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/77899d8cbc2366c93aadecdd80e956c0e70b95b48427ff4de459bf0c0ed5acd2.png ../_images/61474178e84a17daabcb62cdf1ad79c5790c8d2fd14f7de0d3f66d09e5f8f97d.png

EGreenlandIceland#

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

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/52c3c82b2cb6392306f23bcd1ac4824b86ffccf18330f800e0d147b998c73cba.png ../_images/902c34143d91daf616ae8c1202a913b9807ecfbb3f177e10510017ab0ee5191d.png