# 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/40e40d543fbfa9963cc045fad21ac20a1698c7ce47c220fe04ed140100dd357e.png ../_images/d08f624ab24498c86cc72e82478720f6062dfd643c9ee80ad343ba5fc145be79.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fba0314b22cf91784c3067eedb421e49742752780f1b99f784f921532bdc8191.png ../_images/95c0f56b926c047eed19b81aa306d62d1660930820c0c654ea2f03ad07796abd.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/034aa4ae66b5b45562d6cdbc3d625a499bf77c27a4c05384a4c0b4c6bda5965c.png ../_images/e9c668f7c51eaff176c27a5cbc64d66786b83f08995851528bfd1de8ec31bba6.png

BlackSea#

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

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c9a42639f77ae65fb81180343e33324ecbccdb35e920939141444376d66a826b.png ../_images/2fc9f8c1d3e0e0c60063ea05ad6291b67292c873a91f7cab7df7480ba73bb6c7.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7620f0f8b9a4b30cc4ebb20375452b3283aab49656cbd9b80c045181dadbcc97.png ../_images/85703fa774b3f0a881e511fa05beb05a821a250d05680153bfe312eaf019ae46.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c7716d79b8b8ff706520be5b372ca09a24d3824ab5025f64ed82581724d33776.png ../_images/2b08e9300a656ea699e8a93e39367726189b5b217b6dccbf7d9e978090c3c7e6.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8674d842898a24b63cbe8b7b6018e6e5d26091fc5ccd80fee6b3f09a5b5e50d4.png ../_images/3dbcd2e4da4a9711e8f37c6f36dcc54c33fa1c9bfbb1ca45d8051d886e8ef782.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b0e9fe0f1d6e0fc0856781f9c15481d721aada9b25fa5b668f906d54796f5db1.png ../_images/1a8d7ef7e4f7e6178cfd65e28b0473969bc43c070c816e548c3050e2d8f50c3c.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4948738d56d1ebac2a60c6fbbfd60474950306055c505282b00271ab3fe907c0.png ../_images/36dd6d008d7668648c10dd65137b8030e44c89f3e2d3fa27fc194ca10bddbd4c.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b806229706a69a7c054313042ae5bb9f4b62835903b185832ceb20a880f26a9c.png ../_images/d00d89186f0ac21235f5b6b399c06b5e9eed8b17f3aa8e8b2646032e37d67607.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/565dc1d29b21d29c2153d0bcbd4ea98fd750c530f47b35d5066e4e081128cc5e.png ../_images/d29640c3ca36a285c3b9492d5942dbce489a3c7bc1709675447eb95617558d17.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f055197141b4628152db36bd01511c135d2183c2624060faf63fbce1c6bbfa30.png ../_images/63c577a3e1a13a95bd4859f3b245218252d8d89ccdf0960f4003e9f4632c7ddc.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f554a09751b4ca58aa0115118ef3c991a778c806c089f0d75a3aa4d25748292c.png ../_images/58e690a64add51b74bc6afa4a77b5ff370f459c7b4da390c356986f655b604bd.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bf7e48d2597454b0ec2bac6537bfc1a46ab0b9cd46bbfa3e163134c8eb9002d0.png ../_images/075614543f302dee57092f98038cc85bbc2a87fb6f32140520fcaa1303d85a63.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eb52ca7fac0f7e1d5494915df6d11e44558a51ff6f50fb9837b69ef6cb86520f.png ../_images/08cd20a6d9c5b236fefc4f1c6a0c13bcb86f2c6ed6b6ef825ae9ce7a235b066c.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9f7fbf3eaa6f0e1b635972aac5bf21e4c3cee271ea5d34382c082b3fa7fbe5ca.png ../_images/bec3e34a2d236b6ad6d1ba9de0cffb4f3835db1ac2efe5a085fb2a9fc46d8127.png