# Parameters
variable = "salt_flux_added"
long_name = "Salt flux into ocean at surface due to restoring or flux adjustment"

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
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/2e9c57f612770c145ec2e0184e4cf21a1df439e2f5bc39d053aeca50bf6c8513.png ../_images/f5264bb7e629688d9e480818adb45f8f2aeb140084731a7721eadbc8c5f7f953.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a6d85425ed438c398a9f4f2688f3a9a31b9156d7f1c6f95f69102d63767a12ad.png ../_images/1127b263438438746374f0e044f4046f51e866711f3d2efeb2a3cc21a6a0e48b.png

RedSea#

reg = 'RedSea'
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/9a7a48e44706d3733499729b165c676e36f5504e3356f950ef4b1fee2db5eb75.png ../_images/b183debded96238e8e7255c92d57de6db389adaa107a82e84c0b050225451998.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c7b12201a04714f96aa55a62539ddc48d1d92d8373ff389dce67befe89e67f4d.png ../_images/7453d52292303b9e39cfc1c1a397bf513e8475e69a02acfd5297c9b8a0931fa0.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2fe7abf32b9ef0f32dd148df74f209836a71a3f84353cc651e9d467d87171e3b.png ../_images/7e699ba1470b9dd395ecccb413feb699b730701450eb2465d592a18b432713e0.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/54a67cd8e8ff58b9d8627aca25ca0f3ad0f7b08dc2a82153a539c565eb3d9d46.png ../_images/542b4a70d6449c161bd92e6ef8a916e416e4389a1eee15dfe75fe6300979c3d6.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/11e6c7649a83c95e2db6bd71e3833d7598a0493a5ef7803328915ac29ea6c80c.png ../_images/a60619ac976686c507e913a78b80a7156e020f8652b9fd0e0797193a4cab0103.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bf64188efcf4b67a59f0eb0ae1459c1784bf21727e6889c55368fdff84bd524a.png ../_images/0f66ed489d6e378f9f71699a2abd75df89848faf59f1f1384991834cf05edc85.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/12f02f49898feeea7f55232635ec776ed94371e2b40b1b52b1e30af19c31c4a3.png ../_images/c73cf9a9d625f0d41e8d679638c6fa30392251e2cf83e410cc9ae9748833d54d.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/07dde6a805558fe155949e3db7b29a5a5047fe95068202d72839ed070493c809.png ../_images/82eab10af1a81d48162e9058eb3867532627e653650da1163e43a8ff6c8ded2e.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/27e0d139e09c69c5a69905666048e2bbb35785c386df3089c76b3387de96c56c.png ../_images/f70c40d745e9bae86ce68f6416b613564627a702dc719a4255ade87ef9f95e44.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6144148480f98225c283124353488ff41ade833517763bdc466611e65fec78f8.png ../_images/bf942d57537c7e3fa92fbc02cdefff5a8902d346121f49dac6321c64b050fa16.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ca427075a964d1aa26161617cce59e022a68bd6189e9381b4804bb1903c7e3b3.png ../_images/a7610d3fa27deee7405666373d16b1c89a6c6303679b97e55199cd4bce623fd2.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4c9a6d77a5b14578c28dc1b1cb891457287a12315a4f1a305069d2d3dc31b859.png ../_images/80f7832db37cb9396691eb950dad29c870f9a06846b2e4f4c889dbb254021f5c.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e9ab36a3933ddeaff69af9af461123310839b88b91de90f1720d1a2436700cb9.png ../_images/9cb38b91c8bdda600c2d482166dadac9cd4895e0cb7e998d39f7d0483fb0e0d9.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7050ca1a86faf4ca9210d4d6ca47051693065aeb1b82dc8ea06e2fc155c1b2ac.png ../_images/e5031e2b446154223004c329587462a2a3b7fd130b01cdd1fb55838aa6dc8aa8.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5aecafe36edfc98791452006de8c80612c724e8963c4cc5e43d080a49c2a8e0f.png ../_images/084df79316ced3bc05a5f50d7823044263275975a33b21874468f5257ae19888.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c3206b23530397bc3caf1e501671a90c1755f703f9a70bc7e87d96659225fe5a.png ../_images/1dfa3e30576bce5fa234e4503d3942c0733b44a401486b4349db268c6fe0908b.png