# 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/72721f02398847664ae618603fe0e0816d46c25e146f0668062f5eff5503590c.png ../_images/e06c2cd3db86292c2aab625f045e22928e85bf70d5ea3005bf47d7f148131e49.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/403d9d71a82160560ff1ffd79ee271401f93c601796643fb49e9d7fd3a5304ab.png ../_images/479033828723854ed18b7ebdcdac979e947b504cae44e542af62d84cb4d560ea.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2abd98a4a11814a1063e4691a61f8ff994182617fc0d725219d4e046ae8937d7.png ../_images/070416588dc6773acf0994fad9ebf525818527e5ad8d8ea0f9d25beabf1102a2.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e257389109ad323f85d75e6969c64384d5ff87ab25f96cad310471ff3e69d9a3.png ../_images/166c0d6fd7002da9c0aeef4379e422871e90dbf56b0aebf9524d70287fc1558c.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/37922328e5f37b9ba131942331802153232aec1b21fe1725efeec9fae8c6f1f9.png ../_images/6c14d5b4a435bd606138d5008faa147c6b0c2e632673475b118730786e495031.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/533c262fea984ab83bd92b07861ecb163b9727ba333166be9ce02dec849c3de2.png ../_images/7be2585db561fcc6d3e31c2e7640f36a195740e284586aa292ede9b9a3aac684.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/db32300c95ea367d16c82e199bf803aacb84d94c9ebf316868a3cc3467546929.png ../_images/f3b4ed4996959a194dc2637e57de129c7a406904e4f3d58b381395f9fe4ad70a.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c21225595dc73f891a97039b9612c71ba9ffee27b6704bc8ab94461af0b45d58.png ../_images/3439e989dde469cdc7091b87199b5eb01333119f0bcf2eb11f02639e793964a1.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6130192b51df7188cdc4ffcc880deaa66f2c18a8f074afad2fa7b8898d594895.png ../_images/6f6f685e71689606df4670f34d6bfa37661afc40eeaafbc1a95ede8b26277aa9.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e74451c97c9e7a33572e22607399a44c42c8a0ad173a4124ea95102111872f90.png ../_images/8b0e4e925f023a23b59456a1dbd0d93a1d1ea6d27d49b1d0b8a481b8209fe55e.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8dd7c551dc87b0397056672cdcc8fba783ffef66117ccee58632c7b9b919bd0e.png ../_images/dcdda570ec1a72bcaf1f6e94e45eea5a84a94f7703fcccd1289d65a74e7b08b4.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a64435acabc4616882c0d07a761ee23da2b106d4fd05368453fd26ebb0960b1.png ../_images/d4bf38d7fc699513a4155bee8c76d5c3d358c95167e03fe18205be88d096ca88.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3c9eb2d830c7feb36ae78d372ce8b9addc3d683726f1d3492b94a88fcf86e4c3.png ../_images/159fcc367d2edec178dd5900dc8f1d189c6d3648dfb7d9ebb20714d91b4991af.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e126453e7ec705a843f8bb35936cc72fe376e4cb0d207461479030ddf146eb71.png ../_images/7c338caf25d4c33ff6cdddbc035c6ae4886ac001a162686df6a14895e20b0340.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4e37bbc44547d6b7f47ca7db3c134aa9afe5315a462c5013121834b1c435b21f.png ../_images/e14454272f1b530cd1b2440b2f94959c2f1003dadd13c7fad3858bac634dc800.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bfeb0bab312088caa9758890afbdb0ec458ee9ac730d47fef0a6f22384270de2.png ../_images/588a8ce3bf71149d8438e44b982140482c501b0c65fb3d1aa217a45c4963ad02.png