# Parameters
variable = "prlq"
long_name = "Rainfall Flux where Ice Free Ocean over Sea"

prlq#

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 prlq 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/f9cc4fa5c0e64a931435d50a50676fa11ee0b69c7e6578be78820e11bd852bf2.png ../_images/1e65933db29b25136838d47945fa6700b4f95556178540b975cbdf01afc2b1f1.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/14f0cdf585d9585ad3cc482ac206f885d62c04c9502dbfa0f6849cfb01189cf8.png ../_images/32bc57009e8d93ea74c53ebc671b18363c0cab5ae2c1844d7759aa7e22dd1688.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b1160173a11459906453e7d3948640e9bdfdb4358bd2593b21fb0fb458b82e16.png ../_images/cb12a59da25d607791356baf65ebbccdcc7da515a3c8a9c6adfd153eeea8c9d1.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/847ab99e87808abf54f9707361b253ce45127311f826c4e2e6117685042643da.png ../_images/842735e9f6b9a74058ce4a5980311d43babd2ffe61459b1376bc4174ee49b42e.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2c168818ce1e632c9eaaa9746431b33ea695a69590e7204d6a2a1dba9f9e4085.png ../_images/3c3d536b66ce655e94c0059675e63fc59e86198241e58a55d1912c5d9b7fa459.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/51c29ac8667b13c35bf22769c2ea31ddbd08c0cbaeb3a91e8ce214294c8c74df.png ../_images/fa3c17656fd8cc847eef22e3db1b7d27796c9cb093e492d6077d84be4565ee00.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5452eb4f73d77ae61f6c42eb07f0962aebc2c0ff4f0e283cbd89544d4d6f6a68.png ../_images/484d1efac71db01823bad4172b256130919d6e83db32a1290c103a3bf2c9e094.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/77a8bdf5a743f568ac1f6c8bb27aca4cc45a3de9b5a19a9d538f246af5641ba5.png ../_images/bb8416dc84d344259b2332f96c676723415dbc2b9b2860a43247d9b487d945d7.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3368153b1501cd8fb06506c4ff522303543c4ee11ec844d4e836bff3856bd6fb.png ../_images/2b7ece8e0c1c68b97a2dcc7ea2e87a1e32bb8dd920601729a798038cb9b11fd7.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/77430eac7cd33507388a9865bec031b9eee7f1251704a5e8506c3c273a3d84a2.png ../_images/70db2f2cb4d5ec6a99efcd034918320eba7612c9b0c3b0e0e7c7f9d746a1efdd.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/867c1bc93ba7df8ba001e90e361a9676630583ebc6b3c69e9e19266fe9dabb99.png ../_images/dea07c0c079af46f44dffbd8b63894093fb836e94092c67ad6780fbc6e0cc37d.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2c1cbeaf9b809b19ac427c4d9c44bfcbf8717ce1dcd16684ac0293515dd76700.png ../_images/4e6a2b55828f2d8d97350c01f19aeb32305085f6f20c6ff9be7a818d7a91e219.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/815bfd3cb487502771cd41c1b624371ae10459edfd80f6b7f64b4ff39016f85f.png ../_images/8b8750c0601a3575b89c17b1c17c737cd6babc2c7b5154ce6392f96cf82520b1.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a5c7bb1d7ddb92d39ed113f14036f5dd3c35c13eb9c88fa5e6896672d10535a3.png ../_images/5c03ff8cfb3a279be990b50bc539be5b18ddcc5490b8f3cb2829bc8885e87565.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/899624254c8c27fd7df5dde84c86782c9681dd525400bf8a0d4c9b014129f901.png ../_images/b43a7ec4c8c81bcf98ea1b6bbcf06c9ce2078521959a2ea68e259f5c2ce8c9bc.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f02ee7458d04624f1de4d14d438ec1a1764814d19d8a73ed4dc776be4a1b91fc.png ../_images/845077d0a6b8d72a224f8e9550c6b3cb431ef1761e9603eea0de1e5c68c40c3d.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/00103595e5af4f1db925f33508496badaecc10d040cbabc3c0a4ae56cf25ea52.png ../_images/a2cc1489c47abcd8ce8e6557855ce2f3a335b1efffe610647abda92004a23f89.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/30ee64282519a3b5895fdd357a31ab4b71c9bcb22dae5f9796b7adb6ea0bb673.png ../_images/173463f4a0ad7c82b74fe8503ab4b47b40a201a1ba846d746ff15324b78d60f6.png