# Parameters
variable = "vprec"
long_name = "Virtual liquid precip into ocean due to SSS restoring"

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
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/3e3583ed09f3af1b2bbee337542a22b06d432bc8e1aa8d1c7862bf19bba2e785.png ../_images/63acaa30dc34093b28148951bbdca428efa5af07dc9a774179f5138a2356c2a8.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a67057f651ac51a969156a2abbfabdc922095d96f6549101ea001c2a89ceef00.png ../_images/85133999fe1673a218cfcc2dd11a2af915657128c04b4019ac4eb0baa3dbb92a.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/96b7c36bd78aa282e190502e002287d64838ca2a1ee919bed23de7cb5178283b.png ../_images/b642717f4f69eddd75596f040bd9d0b49818a6263a740620927c83dfa0a13ab7.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e38b29ca10464b8897b6d613e897a3d390af004a30bb2a93f54c3df4439202bb.png ../_images/17d1bbe050b36fe3653f1cc49c45753bdaf12f16dbc44cedafe6623972000028.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/943b4c5cb52e49aed357c35f433d136f26d5cd5195b56a82ad098c66c383745c.png ../_images/3b6f449461b7793c3f29647c60ff6ffc39e9878a1413b0a38d8df49489214439.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3bd705a170ac53e84f8f26dbe064164ed6b56671e9c25458e40cc6482ee31d05.png ../_images/f7faea88e245b2d5b5d508473bdf713f0df91bfc141bee9e47015822aa570827.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/21de9edf473d2c7cc8990221c64368942fc79ab2592c749a0ac2f8a89f28e808.png ../_images/34e410799b9ebacc21095b893b39cb44e175c32b3954a82bda6e4bf65318e789.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/887874d36578081ddee812ef881daff6cc639b4ece9666ed8538ace037589e91.png ../_images/aed3bf40bd45d5247292cd3ad13359525543f02b49f28b9b2fba2fce8012675d.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8758b683fef4392808d160ba17b040d15c60a5609ea20a58db8299487d0c221f.png ../_images/d3adfe68145babc961e2c39242c66f09c9a361b201262a8879fc40f4fcb3559d.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7688ea8cedd838bb52a31827fa7e54995d1fadbb27b4954074decee58699f43e.png ../_images/b00ac8e261686053e1a0ca35c9933b1a042d1bf0564faa97ee0d9023ca7440f9.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/308f896105c4d0397fd2db31d7251e87452579be392dbf8f975de259c3c287d7.png ../_images/1acd3d1a01adb91e9fb74da26f30826e4327e98cff2688c3e3760e91b84210fb.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/650b8c29b41ddbc8ecd3835f3875d6076f0cce175d249874647bde14765f1eeb.png ../_images/fae33949bd7a18b7144016bb7747464ae091062c61d7955aa6e0024faf541458.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0e677ba1454749390b53c69a903c4983f54de7aa73aadd320ad16a66b082c5dd.png ../_images/cd983d1a4c08b46ad714f4a9e5b9638b599205b0c20679277547695c4059accc.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3484892683ea02f1427d2657207d9a5596fb4dc9941bfa48225053c49eeefa7b.png ../_images/d572ba545423ebea435eedc8833ff4b2d0834680e5743a0011be7acac754be98.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2edb647e5a288ddaebe631b4e63ad77358f44e63288a053671be42a1ce8e1f2e.png ../_images/9d55bb3e53853603a2def90fd103ad0bd58bd2a97ce778a29a49acc614794450.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b775620571d99a70cc9d505d3a9ac84aeeb10e20b69d7e8c90b65c4cba0f6d3c.png ../_images/1de5e7b8dec4e94179afbc7e623cab08b686ef44f4457a8cbe95e05e3b25eb02.png