# Parameters
variable = "friver"
long_name = "Water Flux into Sea Water From Rivers"

friver#

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 friver 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/75204b8a1c4fa10a139763a5559c54caf3f56462d5a52626ba02d2ebd68ae03a.png ../_images/2cf79ae71eac1a1945c4c5ba41eb546ec08cc12b7fe72ab77c317b846c3c828d.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8cfe3ec295ba1a2341eac2d4552840881e5ad6c1cb7585c6f8dd92967d3afd29.png ../_images/5f4be61740e40a81bf9d57eb1779e86402a9c452d43754b09538dcbaabcd9c73.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3b7820bf56a81e6904d5c42989ef9a45201f43f745890bd7e124f1b34fc4e238.png ../_images/04c4775784354f2c43d87deb37ae7674245a75421b8ceb4bbf346803d0b143fb.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8370ee121b63410c2330bb0abdbc01e0369f372f162f4cbaa5085fe75b859e80.png ../_images/fdd0b22cb12c55d6a8b74ebd67b26a71c54d168d94196f40ee56e0d6caadd391.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eefbc774cee9af752f707b987762d10abee70733ff125366db0c5acfb5de7bc0.png ../_images/32f2fe42e9e4a998d624036150c6b2adfef33efa36809968de949391abe254dc.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e7e0876a8c9d3d102fbb5d4bcd8368d4b54c0f35cff419d8ae69f8d9626d71d2.png ../_images/4af332d8b92192f91a5e39da13535a6d6e5932ce5f87d11b5bb272ba17d488be.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1a767ecf88cd4309488f4e97d730f5b78704abb27f7062b97ef164a2a3f7bc08.png ../_images/0e53f24d74136192521455f19e9a09a0cfde9a7673ffcb46fb36824e02618bde.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3bc924a39eba28db5582ace05f4ab8dc5ca1f239415e7ed3d17d18aebd709c16.png ../_images/29114094f3ac87e251755f0f7b17382dddc39096f95ab088b53777cf56168b11.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eb8fa7ff4eaa0fcf7248a284d3b07ba4e00fd9190baf57fcc5e5216669144a58.png ../_images/15a15bd54da8a6d909d61fce3f4e754a1393dd6e5c911b2a7acb2c58afa24af5.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/13d1011ac769a072b7668dcb9e6e032a2a381b6bbd82e4e6fce77020fa9672fc.png ../_images/01597bdd3cad15df1ecc444a9a3e36b8e505c120ce54ad0f9852c9bc9343b833.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3d8980ec3dc3466d1b3c5ab94710481aa52f5fa09b5b4130b0743a6cf3bd6ee8.png ../_images/2fb4f4f8b68f2816374ed0182c214250203c7a9a1f3dc82f071e4db52876506b.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f332f44ce101eb954a3573d3338108734f324c41fba613825fe5c6440c1bd29f.png ../_images/57b1d7d3ce40560748a178442191c4625f4504ecd8682f176489c78d7edd3059.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4aece00e3fa33fea7e7b3d19ced77ab086f7e99058901260db5b28c9bd67e847.png ../_images/55435238bfb1b9e51bac5e95a11ef8ccb0eb35ca99d018da04fe2d1507261b36.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9849ba39e1296bb11d0b2ccad3101a51642687a6c07e6658e18c77c3e3940f3d.png ../_images/18d722f35f59e93e017a69c52777cf46af1cf76df86cc041a354456996fb91e8.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/71fb0248b8a3dd5e0b9a986fe9a869596eb4b4323962e247bcd0f6a8e56ac17e.png ../_images/e0feabfe493f9448b617674b409ffd3cc77f5f9603bebb255adfc4b9c526f67e.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7f20819c974fec68b6b25afe99cedcc1572a61c714445164aed9bfc4dd90bc4f.png ../_images/8998e446fe923abc0d7eae910523395a8a5c0616e1cf0fb300d245feb37a93f5.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5a6e42d38e98a057d7037e7ec6c0d3eff591f63cdfafc91a62aa1fb4e7435685.png ../_images/27123974ecf2b3a5b0f5356987b5fe49176ed19ccf66bb9db1b021613b5367a7.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/54e5c3db6b477ac285236228c4d7b05605fb788608cdd6668a3f12b7d79141ac.png ../_images/4f5a25c62c73e9ff8339daf0ceb0776f7da0b723eff8b74cfa5b557fe58985a8.png