friver#

# Parameters
variable = "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
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/285fa7623388261d4cd6e5f98f3f27728fe72977ea4554c58dc752dc1444eed4.png _images/93ff0a660b4e8308cbd7b7c4921c67cf1103dc47d291b2e57e19d69883542bd5.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/1a398f8f307789e686b932cbc3b59e6fdbef56601749d27224d4bf729740bc9f.png _images/3b32899315affd4869b8d467942327b0e54a50528260a357d24cdb9afae4ce63.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/96c062c60b2221d0099fee06161f55852c6073fbb9101cc472f6795aa66882b3.png _images/3cd9598a26b9a4ec173779508d6088c2a42e954ed1ab76cfa9634ed6a46c77a9.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/25600e7ff34a011198614e7898724fde0fd76e062232bc1fecc9e72d7324e5fd.png _images/f51201ce17a6d8dbd1b52cd60dc4e2dc33f4b650ce762fb7464e66867dad67f8.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/7c72592e5750bf0e8e6fddc57f2ed7c0d2cc49f0c64a4c3b7d4d64b03d2e9224.png _images/7f585330c99957e94c1805e5bdab780f22e2b81f27249d7ad0b3dc56a527e71e.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/8af9120f04d8f6102738511f9e0fbcfd8b3c42b776b2b8df029f22d75c6cee90.png _images/451c8671e4c649e37f8888858e04d41918e3089b7a21c8f091611f08f995436e.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/18aba7e63f14b869a6a2f44a70fb354f6cf8e8afcaac1b1dbf7a0ffc333cc136.png _images/3d74189cf63a0be2e3c8403816363fb7b4befec9cc9018a5a1558f612d46d9d5.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/bf6a82659fce917a474fed44488c505ef75298eb90729664b528431a929d0365.png _images/a02ae7f36d97990e333cd9590bdfdfd589c67a369c8d57eaf32024dbd6f54aaf.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/bad1567997d10f266d026ef51e834819c66360964936f04d765dfe5bdcfe686b.png _images/63766daca978c7745adb42e776a3d162d5bc525625f01d7f0eb4eb8f1b522a8f.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/5f65a412a6d87eed53b36033960e4c2df0be905a36f1df50587a4ba46f6cb7a1.png _images/9f56aeb9ccd2f002d7c604dbc5669043f46abafcc76918c9e761e8ce08bd6228.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/442b79fe9ec0f46b2e7280d3b573b59e7f206e59457153166a0607dba87d2622.png _images/076e7be11bae99b3f93dcbcb64e1ff822c6fa738d153db4527bac0f9300dfa1a.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/87c4329668160f2ffd0f4458a6081bc7ea775c016a3e02daff1f2eeed77eeb8f.png _images/582fa350f06f22bb1845aa843803724205a12b5d79223a9577d4ca6193c2e87d.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/62b2c60bfe950873d498b8561ebbb9d5ec1c04ca2eeae2a65ecec2e42fdbe040.png _images/faba1109b2db4506ae899720b0a022d473af871147a61ff846613973ffaa0e3d.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/736a0662ff7d2775bdede77cb22a4fce4ef6d5f3a6e885209aad73844384008f.png _images/8f8c0a8756ddcc4333746292cb009a1d621a370db75d30124998a15456ec04f3.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d69195b05a192bbc69891b8eea2fdbf64e9f5661748a8f24a49ba6a9c7f50796.png _images/b86bd9abea3a2d128ed14d25588d4f61573f43f68dd7b4dd411e85ad80ac5168.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/67dd7630323fc7825563e0a6664c430dbca84de13dcbf7bd965faac4f32e60a7.png _images/64d7b5129a341f6e2ee05e4c82c7f9ea8ccde46e19520c5a7a06873a9538ecf4.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/dacf4ad88eaa14030c932151f17d4adf66d58b2fd3d4dd024bbc0c73ea289a5b.png _images/3c4dfad45840bbf243729b6b76d05a12c5f2e57267adfe2785a7910a44fe56fc.png