# 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/ac35c5fe56d570a7a65ac0194737fc1eddcdd27028586f2a97e72235ea6595cb.png ../_images/c5488ee5a973f29d215f01787c3cff8d2702dc9030cde7ea81f1e11ec3e80b26.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/871e718c855a5062e2e16fe83434781b5a43747315dd420273ec3aa19d47d27b.png ../_images/d98214d93264c24dde3cd844c4763507dbe93f31276a0ee232b9db0c066337a9.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3992951ba4d7de97477a406a410e19b2db0645d20d2e99b4ed8272d8145600c4.png ../_images/adfc6c10a8a6304b9cabcc57eb04f55567686119e3e53e7b70cef173f247ddc8.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/03a9ab7e223203f953280c028053a9f8e51605721596f5d54e6ec2792aacb7a3.png ../_images/7b4ba8688311b313904bb8c2ba7801840fe71ab2eb762d14be88c8d3a93d387c.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ddaf3fabcb8bb3c6fbebfa85992828892f4275d766a36f6a11d78aa3c1ebdb94.png ../_images/2e42fa21aed38d73917d94b9eda3bd5f6edc41a82731d37426bddb0f444a6562.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/95eafdf353b0704a3a3d0c0e5d78f3b568ad4a4eb037302a137ebb7308b8c764.png ../_images/a0ec6302fb990d1a360a71b0fccd127cced3a08470bb0a3161471eb6c71987c5.png

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e7afdc80513fa4084503e2d2d702202db3ba4c29aa210f2aabd5a4d56bcb1e48.png ../_images/f646fb51a0c97cc663be83b43ab163c67c21ba3102b247a8568e6e3771562e63.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f1f6a495b4e13681a053230bc07029fa33a8da875179a765045ecf2cf2b00cdc.png ../_images/ba386e7d7408cac9e3ab048a77607fc8773e1a4d055ae69918e049aed2d2544e.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/123e6b4ad6117195ac89186f737b5519f2070392e4af113321147075c930b50a.png ../_images/e9139d4e2b3bc64f5ee793fd4120e6a7b0dbe7c9754759c55c7089421420c541.png

IndianOcean#

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

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/04375bcc697ed21ffb2bf78372c457ac1c52ecba2ef19bde13465b838e294e23.png ../_images/5f3afd0867afae8cc930adfc88ef724e002ca44321548968067c939ad569aadf.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a7cd8c6a93ade52e005bf5dc539dc06bd3e30a41e1acb06b56f7ab5c8e19818b.png ../_images/0b5242ea5ec06c192185c02b24d4c698f2b73b3d607066a59e784b2bed6c074c.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4185782aa097c40e8def0ea12ea1acc691a0dad563c8a65e48e73f25f6c3aeed.png ../_images/85adf521bd90eeada2583767fce44dff9abd8ef7a3ec415fef646edabbcca8ea.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a9ec9cdb057c3c472040f1dcae6758286338c941b5fb76eaddd75d2bb81ee60d.png ../_images/45388bf8e5d66fff8781400a1d551bae8213c224de5b3806b3265a03f7a72c31.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4f8bc9876ecf82d94ee9ef10f28590dcd2f8004059cfe1a5e309c43adb603459.png ../_images/88df6baa4e45abce82f3a0d40bbdef060dd19eb4b11f588e68a04d7ed80c3998.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dbd96d93e802b94222fbd6c6bbbc65c7ca8519085e1e144a7fe0fbb71339c2e4.png ../_images/257e96f1b79b7f3c1120a94b374b0cd817e75fddbda59dd5fabb410570177833.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6d547ed4204959a1f6e2e43d30181b6bf4e5a2acd83eaabbc52024cc2671ad25.png ../_images/ad19307502b39e52f7f084fb66c4318f7afe549b106b7c5b1c450205c97ed295.png