# Parameters
variable = "rlntds"
long_name = "Surface Net Downward Longwave Radiation"

rlntds#

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 rlntds 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))
The history saving thread hit an unexpected error (OperationalError('attempt to write a readonly database')).History will not be written to the database.
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/811b96969931f4f95b25217ede5dda7e6ec46c5e1713cedd7c981e46dab0f6c5.png ../_images/3ec3d620a064a5d394e6f1c14731415d89361e98c86e8b9e69130c7e09f55181.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/137d750689105df0880c6d2305be773e0da3393e18f0d3a1f16647f55cc5b4b2.png ../_images/9ddcf6bdf1ac406506770c3e2cd8d8d4f735743f9fb01f6ded76dcdd2007ffb8.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ad2aceda2de14fd8b35c046c09998f4d9365e10bcd35ff529b85e6040ef4beb2.png ../_images/56cbceaf3a19243f12c5fb432aa86aefaed7c32b4e91a89285c14755d31ad4b9.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ded769e5f248ab2df835db1d8b2a1120136774bd9b5d56ecef65604cffd7a1b8.png ../_images/d8086ab90b2c340320de702457fca25924eda4d24941edd096fe7c9d8f7acfcb.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fa46722bd7eaee9ea6347c01fd224dab97c79f62f357594a0b47d34bfb4714c8.png ../_images/9893c5fc83153bee4f20ff24ea1710acdeab0e74c3fb0074c3c8e0b1619753fb.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/47f2344985d513067076b54d3cbc6bf571cfc5ded04218c46f5984e18e600ec3.png ../_images/1abb13dd350be68d7bc419257309f7bcccc15de1a18abf049f9892e220475609.png

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c5bed034699634d1b18d5465f82e7b65c74af747b57e2e4de5d8afa613ebf30a.png ../_images/1b54ecd229fe3626fbe7c88c5c32078a98dbd2e65fe878027bcc92f392ab0316.png

PacificOcean#

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

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2888d59a29619dc4822e76ddaba08d5d938849d4d972314295b2a371111732dc.png ../_images/dc89127223bb04928916636157f74c3f923f8ef3375560afea43f5bff4b969ad.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5accd4deb4b5eba75f38a6edf17f9b6734865e2e9d82e4196fc763037da9234e.png ../_images/737527c905670adacc68722f72bac12737c6efd390fb050c9af91bdc9ca71a40.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/606d40c4926a6eba657c8e74fbeef701c725b7b5473cd32ca1de7a920d050138.png ../_images/fbf10d91222e3808f1de722091f7eb0627ba4f298c0bbf73e719e812fb741b7f.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e07a2b5488ed33316fdcc11b0dc54d8231226f255399449add688f41633e3ea1.png ../_images/c42784d484d433c6dca6dc49227f78ee500017e880c748ce3291e84a6eec7eaa.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cb7f350f77df247874d898a5a2a6ec2802386db735ec45bffd85c01b81791e08.png ../_images/6a5885aa1d7f24417044f3fcde5c26c885a2cbcca9203f446ccc3d947536b138.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/95b658ad003adda0ab86a39d9bd032cab10666f31326cea088f7b781db9f9c4a.png ../_images/1441da293fbd28b8adebd249bd09cbd0bdd4a468411103fca19c56c3f19e55db.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9ff69fc3256d64dd84027b75e7c452ed8d18a109b831d9cc762aaa7328ed5d4a.png ../_images/ac81a019738b43dad22cd5d42b62902f46345982aff07eeabb28d0490127147a.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a9cacb71ca82d94bf22ff185c222486ae74fd9537c9277bce76de31f59fb825.png ../_images/b1136560e7a673b2e93c8cb00b6acd107434fc1370e4c47f15dd5976b272dbc7.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7e98d4a62fee561939278c06086e592e8b003430f9723eb3717ec60d6a5f5421.png ../_images/ff71abc0bd29ba33cc855544ce6d0b72767f6850766460d9cc7e03a1650b3bf2.png