# 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/57899073e92b766c6a3a1cb7074d34eeb79fc3e8f5e4d6d5c2d7385ff34f2094.png ../_images/8640813c6012dc79d8e07555f7130623d701bead007a207724d963c59e369642.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7fa4cec31bc11268363583440d7eb5256e9e926b3462d0c0e378dc5b53093012.png ../_images/4647f8cf7b3c56b523df2eeaef789a2db2d6e59dd71aecf6c00adba3c9b2a257.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9d820aa229d6cf7051c1dfe9a0a3b2fbf7c8c0780aecc9f94de25e3a05137631.png ../_images/fd428076054652b68f5074983856555d986b9c077ea5a6e02ca2259d49805f69.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7fe0ec77dc908826acc56d891d4509b92abbee3938e4f72f49de45f701108f3f.png ../_images/f71c49562016137732fa5cbeaf3fad6d38509d4caafb150add0dfe35c35676cf.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a1653190a2139fd96b137b8161b66d4820d4a091eb2370d79314f29138c9c72c.png ../_images/275fa72040e0c060709939fcea909b36ba42b972dcf03e711d4dfb9df23bb6d0.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eda2cbb6830c2382969a98c0b1b91abba82b3c8d56021e70bbaa3cf590fe9676.png ../_images/1ec94e9896daed7b6070bc29f453da998ac82f3f734dd54480ddf2f59cd9efbc.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/11b95239e2db8558fa336c02bb270bb2dbbde3bef578f484a3e695204ff76b4b.png ../_images/3f3f1ed692566e094e6774d69d38548b8041d1b33d98e703cfad5310c97c6b72.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/64f995f0173b3b18cf8de21375bb61f76eeb62a223f5f35a27a4b204767607bc.png ../_images/25f53ccf1736267a41a2a43696bdce0ad0fce5df2e1e1983c00616078b6c43fc.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/18b6abfdf99fd36a1cb1228fe5adc71e54e8a62a03d7f51d6802712aa94a21f6.png ../_images/ec46f6d14ac786fa97d147486fc16f444997e8fb63988e9e20517d841320bb6e.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/253fa726328bd6cff0962dcdcb04514205a3e1330760600830216e59c36dcc7d.png ../_images/0ae9df33c79f7b80fb883e4fa6d847fa8b33a4d54b9fd195085e6a54bf6c231e.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2ddb819e6636086ae6f012319a0a03be1402f0ffebac10cacac52462b776517f.png ../_images/ca34ceb5e957350b5f2adf5cbc55aba8a7e2886553731955352eacce4ce16b3d.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0fa0434850c4ef9c04ab15cf7d717684d36fcc170af636b1ceac826684f1f946.png ../_images/3e9abd298d870b93759a34e8ebfcbdc8387ff46a165fbc58da9ff7e8662303ad.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d7a45ca3e695665434d7d64372a05b7aec1a960923c68f1d3ec4959507d8aa12.png ../_images/197ab9ec84360bf003476af9c59ce18b69ad0dcff64aa3e326875443ae9f1720.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9d19264939db81a943e21c44fa9544e1bb0176863d2b4b748cd9faecbb062353.png ../_images/90c18b6512b51336872dca9d18cefd7737853d157e8ea5b4d81045cb09c4b403.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2708bc18e370e6d3c4a1f82d550acec7f7d1850080bf4e48373a61f707201dff.png ../_images/ba047f5bfe2e7fb4adbf87af8e82c455efce3927a838c806404edeeba4041e1c.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dd6736399ded8764b0e16ffe43a76f0adef14c78fafa206187402dce8bf9a87c.png ../_images/47cd04ac8e45bf00d8ae5f43b270bc26e57ebfd3098cebbc9932f1621f5a2770.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/55be289874846a6ec5b4ed1196ea6b3ae9e22e9b902ad04724182a085e7860c1.png ../_images/95ad404b159e6e26c64bbc492e09c6206e335725234d3355c4cb2e218196e1c5.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/904e3dfe229a530e43b3fb45925c61abc831eb612d809379c23408faaf8bcaf1.png ../_images/9e69a9f05e8eab02b937ccb63b4d2863029f1a53218f9b158edd7c3b3a13d7b9.png