# 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))
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/71064d348f719ec2ce84879e4a8754aac0e8ff22d20b4705c351e8571a3e28eb.png ../_images/6f3dc4e2a8a18157a224820d4c08a384c1b216813b1a047833161cfbd7d1e7f1.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ebd835d1276dbbf72995dc5f5e7a9db31d9e29eea1fd079da27b3e3f67921f64.png ../_images/d78456081b2f7a0b1d4dec89020b3f7901b4edbf93dbdc5f0cedfb1089ded043.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9505e01a43ebb760949a64350a19fb687618bcde7b22da6ea207ec3afff75c88.png ../_images/005d1e89b73b43c74048a21f6dfa64898fca7dd292c283427f3169bfef6320a9.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a32e7728d2db636a5db866e5420c4b95eed31f34ae5afbcf21dde61bae6bce1e.png ../_images/1cfae5bc6c0b36b50e48afadfba384a5d7a8e9db7b1c177bae5547c299102bbc.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/08a6123e8299095bb7879546371765aa0054d361fcd3ad87b7b79af7acccb991.png ../_images/28499da2f95bbd0cbfe1c85e9c8cdbf8ea626334905f213182238bbd55fd9e8d.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/168f19f079bf11bdb79947a93446bc72eb733ffc884ec441604a2c8fcffa2d26.png ../_images/950da9f7b148afae5eec09e701694ce3e20e75f92f76de2d9629d51ab985ba96.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b904ef5f588fd91c2d3135fbb66f59eba78571def599af88abdeb6098f4e54d2.png ../_images/700becb972a89f9b1533ba68f79e38318ea579dd375faf1a4ffc564a34faae23.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0c54c57db7dac939b7dfad0736258119b50ca7e26b1a92fef354d691c18d4b84.png ../_images/715cb155b58ce80a6bbfa0d205959a73c5d61a3fbd159c7367debb2ecaa0b60e.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/134dbef4f37fc59b40c5fabe741ee4d9da925a3dd057f51249e3bb6074a16fdf.png ../_images/15652c6841f5c21b630a9d7a7fb079e89a9afaec4d19bdc916b2df0c2f36fb04.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fff67c3adf7a97b4975522b675c4f4294a75767be91f67c8e4041f645ccebe20.png ../_images/2f891c4f40929dd428a2700e94731e36124bdb7fef261f3af3ee95765fc3db30.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0c90bfd0547bc23187216e7eab2b5c614dfde37e84866c0b589e0de537ce19b8.png ../_images/b6786c6caf0558bbdebc01ca26385b1ff0b7a9b76bf22264f58edca6262234c5.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/55f6296c542e3ee55eeebf93cf5a23af1fdf1a770c13d0d404a9b46e6278c78f.png ../_images/b288356380fb2623e0cbbf5e219c45fd3bc03a2451a4ad61b78b8a5fcbef6feb.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/612d36b2b8b18076c648fe425c263143e7f5b130048462e0b92dfc1c77de2eeb.png ../_images/727426bdbca563f6ea4b69558e975cf54f8cc46c1d700961ec39c7a98d501774.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3dbe99800c354046c715c3718f7dd7ad301756ddbd499a234cf3b6cdd4b92276.png ../_images/beea89589a77aef1328096a6e77b3bd7b5baf25e9828c0868cac51d74e234891.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5ca6ded76956103763c060416e02188d830904ef6803bd034ba977883fc0991f.png ../_images/2c26f4325c92b43c6bcc99504634a0a92e6fec7210b1382bb42c1fc2c72b97be.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/678df2c83712dcd17778afa7a27a118a67888c4cc247090a530dffa1974e3055.png ../_images/733ad0e3e876caca5d418652577d451fe0d701ba5bfd5b4af75074390eea49d0.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/89086342e140e6c146fa2688f9080dbbbef53dad34d0c85fa9a8f54fc9ed52a5.png ../_images/ff7d72cc67023ee3fe0171266ed25ee02fc5c27297c6856873fb4448a4ce2468.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d3a754e5b2b82291a8dbcb460e57bd9aea1b574ff22bdd56199e09f645d5ae2a.png ../_images/4abc272e1b3b884a12e1d4491d884d28d4e18e7fb1de2596b520469f63992e9f.png