salt_flux_added#

# Parameters
variable = "salt_flux_added"
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 salt_flux_added 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/98a4d5e54db0fbf118768f4b41d715deeaac9a526115fec8f4f5abf89bbfe74e.png _images/10976797c9fd03bf57129eec59ec946e2487f044e34884d75cd3e95f33083437.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/75dce9d17ccc008e95f6adb697151ad9c8e1a8308e71fe398ccef6535a1feb3a.png _images/8106969387d237b1e090102692e9cd50fdda3a7529fa4e8c0c21e8f82de541d0.png

RedSea#

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

BlackSea#

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

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/442e8bf4f15000584fc46d13041bebdbfe1e648f07b9505449d9d57ffd0a428b.png _images/d960308bc3c50b70eb41ce366e0c8e64cb5399350ee1d1c52ac3a9ee25bfa797.png

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/9efdd8bf8d54efce21b0a57fc288f698546bc682f23c8475ef8c78f696ab662f.png _images/be139baba1dfb2313a77893a8bbc992045fa64918b6e8667006886fd4fdbbe7c.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/4c6826204ce69011e690073b3172210277e2d7de64d6b3d31eb2e7462c9e36d5.png _images/87d99589ff0b0942ee990e53900d67d4fd20e435d86f71bb351e9fc3833f618e.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/626d5f2bf08cb5d476152fef1a3a93572f2ddfc18138fe4eba64cd9bb7bb52ef.png _images/4b51758d091ec2400339d73073fba00ea28e13972948ed90b8f08c6940f3db14.png

IndianOcean#

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

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/b19f53688348e1064d177f902b3958ee1fd05d81366a18a82c9a29af940ac354.png _images/32b8da29328bcc04d76c7186396d9532c09b2cc20f2482a4a64f6d284117c188.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/33e88de1ab8b6b45b410c512f84eadf718e241fd044838a4b508735d6d9af132.png _images/0a6b4d16a1cfe5c84c4d61d77b33bf46faa1e6410602e2408a332d4c9c6ab032.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/777575b681e18113a2b370bdec45acaf56c1a81a4d0c5c3aee97e61334acf630.png _images/294177c249079db2a3a561c00a0018738ba82b5998a471522e6fd9e464c8faac.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/7c394bad2ba429e394564c4b05954dab8a2d987874c18eb55c9fc7cbd01b0fbf.png _images/22d33168ae392c3260132ecf9540232ae76e80948a4f47cf0e276a154b170f03.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/3bfcf9f90ec0d4349e67870cabfc0c64ad3611496477902acd73e3534fc4d240.png _images/6ef96e57d2fb72c7888fad5854189a5aae9d62c6a62ced7ff498ef1daa4cbcb0.png

GulfOfMexico#

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