# 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))
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.
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/99a7e3d07653edf9a7a71b405e5e8b1dff39b27700795f2b99624efdef65e62e.png ../_images/9a15e3bd25e4a4532bcaa365ba132161bd20ca7230b9aa8d9bd09434ac650461.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f92c62a39c3521a692a61ffa46116c04399f8ca66d83781fff7d11e6fe21ab72.png ../_images/4b062a2d161785e726eef7f74ad97db6c32e448fe1c6dbc72ae112fafd6c3c8b.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8947317ef42f4a52d88fc071e736e40260902db2a81a77c013c9d42dfb9483d2.png ../_images/05ee2e3bbfe854a5bc160991a737698423fe2949ea1231b55f4f53044195be8a.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/801b57b5575863ca8b3187685cb5df389d956e31fee8a4510655cdbebe0ca8b3.png ../_images/fa1e2057edc14877433d86bef6d84082801d62eee1e9e89f18a342a832a89e64.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ca4a0f8aa6cd7011bb6207184c5cbba389e0b0554b2e047ec2c5a17e0108b45d.png ../_images/76d0a1cd1a9972e7a042c06d08d9bcb26d3032a7b38dddccedee368e245c3ad5.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4a1c9abdc3bd6a3a038a48fd9e446f14cbe9258a6e04320ead8f6c9f172b3321.png ../_images/39ed2e8fc7102e3c0c839985183afcf518b326ce0fce9d6b89d95ad652780115.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2583a052622be6274b8b690678cf4fd93cf7e5fa1e4d9ea170590fb92c769bb1.png ../_images/f2a355e17277a7e01e8e8374d5f94343056ed94bc2475c2b6125634ba5e226e7.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/65e270fbe51db77b610d0823cc2e618fc1e179bc29e55b63f2544b35a2ccb607.png ../_images/0855639be0f34e9c27b160fded363856307f02a0243ffeaa9f98090c3b432710.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/989d3d4fbd2b948348c65cba85c4189dcfb450a52f8573653c113fcec4e16dbd.png ../_images/c124c45ae438d5af8e50f149c3360c2ea0681073214a366ef8ba23eca625d057.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/834e4baa826739d7dcf38db526b6eb334377d5ed77f00ff2d7c4057411a8fb65.png ../_images/0731aefc027326d15327b478878b528cc99a6b34a8abcc7d18bacf4b9f80a409.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/95fce21ec7da8f0e75b08c8938854a52414db2dde8996548d4656529c2a3e7bb.png ../_images/5851c02f8b7513a029767805b9044154ad3db66143ecd0b370661accfaa4f32f.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/19825c0da3d30abe512c7a72a8cc6cc19a9d98daea558f0bb4059c9c9af2799d.png ../_images/4f1ad6716ab4f44aa434409e0123890a2b86038067e807b1c0e1741e39300d2c.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d5588df72ee0d152dcb4a8e6ce632e8ef7d9f814f6d6f0b6476fbce84dbbdfd0.png ../_images/f9c99bfdc83710614e5dc38281a304712921c7355b2595a9c92637671de50534.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6465e7bbe20996501acb6abcc4d068825890e21bdb6787286dd5ee5fcbb39e45.png ../_images/d91b4fc914b1421a4bd6b8520d6654e094f66b3e454be1cc6ba9720680dfce11.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/15cd4472067a0b869c3b87f6e8ad191872ab3ff29635b5eb20ee988d31f9c7dc.png ../_images/79e0a6f457acff14047a94b14607e655794de1d2437fbdd7b57b9ed2ec704e62.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/022fa1b736de5a708387a4fdf497549ab34728f4114b6be83245bb3ba01d0241.png ../_images/f1ef2d205c789175ded7363d8f5f8e3e915394d0523b183f56ce65266252978a.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6b135596d524f60179cdb515dec6f2c4f0b8ad02016f70d4eb474b5d02ab5661.png ../_images/215f5b9391a17293b7ded89581028b66f5d38785b9aae3e2258d4528e50ac7df.png