# 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/4367b2f54f47f07a4c6e380d11853b72e007797c2012e074639270afd2a96f1c.png ../_images/4d0d15cea246ed5c3a6f13214aa66b2d031ad94ae2b8ce9832cb652ada071886.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/909bc527dec86361d4942cf71ddfa2784a3c7cb7ae869820295b66b5c260f7a0.png ../_images/9c01ddf8402b31ee4bac233afb35acf1507278b221e21a51e719c6be11a7f0cd.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6b646bf25dd54b69d7330c3bc21a3aedc92d2ebe704eca4b884d9d2826c118a0.png ../_images/5c1ba695f0d6269cf8375de0c6202f14a3d2b616683abf330c951d48dc56eed2.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/172d59bc09699386857850592bd2d91c6becdf785c4d3109ca561998f279718a.png ../_images/7b766978eed09f646a1eed126200404bfad4f215604485c3b32691c8421e9561.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f0710edeffa5971e253647541f405948c28e68af006c735ac3f623583d201127.png ../_images/4693e01b4cf75382cdd7fd037cea347074577d89a44de1b90b5aef06c5b6f214.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9e3d3aaec6822a8942c630970d55996bea2d1bc320f44f7cfb9e95375d2a55f8.png ../_images/30b54d167dd99b33c5431d741f2507cafc1a95512418c57ff4736d8b76d25de4.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7e84a82e05451e5119ac43096caa53dec79470cb1277c61959e891adb6a49025.png ../_images/aa5a580fb9950cf3e88e3c67a4c0955ea9d7b76cf9cfab075f5ac9693affc8c5.png

PacificOcean#

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

AtlanticOcean#

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

IndianOcean#

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

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f5100320b6fe5b61eab41a0d627bb88721313ea5b46510bc1c77846a5542ce4a.png ../_images/34e5b4231392b012d1d1788e56f65d89b47c04210f98811dbeaaae4ccd2d920a.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/816554e8affa342d2f9aaa9ec5f23329a28836236a73f1b363ab9f0b9bd3902f.png ../_images/5dca53f81419bdd22754c5949cfaef52c1d759311c6efa4eed567a659d7b18d9.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/14a24f0f78214a3a6d72587145b5ed514eca3e7d59fe5443d20c692cb95c97df.png ../_images/1289b3c91ed11cdcb6b7fd086d0062d45993812fa5c2cbe987e10fcdd82622a4.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/032964dc2a115446cc247a147c578bfe76fbde5387cb505bfd53a9f5ffb2cfaf.png ../_images/6fde698e60c566ec6c61de94e771f31e3e0f93c5cd211c58d42cc142e2b90dda.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/77e6a4b7d70d29149e6eccc5da59d776e69916a8bdd72b01b61fe5a7dd2b67cc.png ../_images/781bb4b6d78699873a4456ee78821f76af24822c819a6712586273f16cd2574c.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/62a7884bae13aa513104305467c980cf00d2d931254d9dd697bc26438a208d82.png ../_images/e4dced85cfc17bc0921d3a9e11a5bf24d0935269d72547a3882a5ecae3147ea7.png