vprec#

# Parameters
variable = "vprec"
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 vprec 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/0c739c48fee1186d7744af17bd4167ddea79bcb0ae4bcf64c3eea47b0004de42.png _images/b78315d004565956ed0fc73133d53e5441175eac56fa057d74235d7855021088.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/9093d890f24e952715ba76cbad46eacff07325e2c424178392f31a344d4d1175.png _images/6bb47bf60573d38430c1e9242ee108c0820d76fe47ed5ed74bcd18a1b9df8c6c.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/1d86bf18ac9f2ab1b9a9f6e61e12337427dd43d63f2f8d9dd9f01cc9dee17f1b.png _images/c5b39429dfce64a37c1fc6dcc7bb4304905213cdcf86106c893fa7c1ad659051.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/526b82fb6b0de854fdee75af910318bd401644ebd524b020636966d5e572a1d5.png _images/b5fb34740299a1fa4818989f502b662ae2ecc8370677b3cc8937117ee19b71b7.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/93aa28c26667ee6f11a55e60c3192e2fcbc03143997229276fb2835a750e4d8c.png _images/ca4570ab5eca6ed87e76de5644216f9ae2d9ccb4f2c143a17fe98a46aea5339d.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/11a3502bd45a3de26541474729c832a373cee57343dd6d8fd6a7ef9a316baf44.png _images/349f68bedf4464a1c989bbded970c956bf710bbe542e231f3e1a25ed82b6abac.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/fc12f055e5388dbcb62e38abc087fcd5d09711061c7ce243fe41e213379888ed.png _images/9588cf06972794e860bb6f18aa51caf4b398cd444d32323a0b6b15d1225a360b.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/00ca607db2bd35ee3cc2ca5cff1ab1ca21ad2d5a50964205893bd547f153c95e.png _images/bbd2991f47fb71a54f2979d3417774a04aab463b632eb37d2a56640f8fe57fa2.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/04f52f6957aca5ec00e64f81603e27690ddf0a46f241edf41382a920cf91b273.png _images/2d253a4a6c8b01ccbd48b9f1fb62f6e0fb9e2a79f22b55cd70c37228437291d0.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/cde204e0fc98bc6fb3824c39cc72a437ca28eec6e15060c4a49eed6e9bc02d5b.png _images/5dfeaf2906ca8baf4b134bff473af4b89a2cfef271fa0ee611fd284f3a7ed6a6.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/3db2a58e7d5f47a25824fa981333122289704f3397d374997cbc171512a4f51b.png _images/71576827fd69a2d65732cbcd3459fa8f992aa3d2147dc075e734b67aa6185248.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/263bec761bd6ed6147ae68b676977212881f2f2163e7b943d9ba15b4ae0415a5.png _images/f80f1c9ce06975d8b54d4cf5e3db2d1371ab1a2f4005f585c12b96c413c3e878.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/faaac092fe86ec44ae2995fde64a0c9002ffa39d71903828ee5fac7a75780005.png _images/97b0edda36edcec494875b442d7a98ff0bd08cd62b2b654f38a6a90eafe238bb.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/9e40a4688bac7f65d562170c45e1ddb8a8106a6edecb5a24de0163fa365d202e.png _images/71b45741095a0629625ae84677fbeb3eb4b0fae260ea357fc1a4567af47b5d8c.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/963d3a7e19875ab1e6d9cea962b2a25958d0a376b163e62c43e3fa1dd6f280f5.png _images/285d8ef5070ea013cea3b7fccd83f0e58260705fe91a25f7da12d6a5d54bb8c2.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/0d94b07d83bed7473e50867dcd9ea5e29d2d6343327f0ffc1c77f5d51afdc4ea.png _images/8a2e0f17792cbf9c6a9d258a97ee9c143cc2017d7a4187e722820dc4bedcc218.png