# 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))
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/694f7ac8fc3d8d825670bb945c462e8559f22b97059d84debdc5fc9831e6fc12.png ../_images/cedd01bb0e1651138599d82aff0f8ac77df63f078fb1ca7e00afb3817a6da23a.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7c004ab52873a7cee130c6d3a6978cd626e974be13dae6f8ee77084c27defc71.png ../_images/fac76043c8bba0430526a2d47e5b5931d3c5d52a374caffc98afe57f77603b60.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/379c556f2e9e104da5daccc49c223ae94f521011e6ce999da866e166ee55200f.png ../_images/85da3766960688117d3e82d15a184893e90e0c57589102bcb0069051518400f2.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/feeb7d602f1c65ee7a33d7f62c72cd6f5b2240a59faf396ff74bde8894cee0d8.png ../_images/9dac5ba0777422aa3cbf612b51109828098fb240aad04caba2f80c1ac896cddf.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a75f50960107b5cc3cb268fe94eabbddea6307f3953ff82b2b1e8ac7ab3894e5.png ../_images/793b127066dc20cd3e8ad63f22294802841bc264a2c1b393b4ac01a7ad97a920.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/55e5c0cceb495c87c22cebbcb54896d1cb35dc619030fe68ca5f8d051f7685c8.png ../_images/8a4cf0bac8a702a1164f1fc97df058ce4d0460ae1c6f7581daf23c8bd5bb930a.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a8500412a0eb4978e2aef9f2246baf3976c39f21ba6f283bba56305b9cdf8989.png ../_images/4969e305f4b607a09e968fe5fc4833aff0531ba96026508fbcb176c3f6f2c652.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/06a1a33da54337c4b27f3a4a6bbfd66fb84a990633e85f3b07cf84740da99cc0.png ../_images/ff8fb7c02f8f1a5f12a4569690b28c9ecb0ad4ccb7d25d8447f9b7e8841077f7.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/da4acd630b5bdc29df36d0650ac7138b52706beb1e1fdea858259d2fc9c353b4.png ../_images/06029dfac853569216a06e344d3c2f42a1066a57e0ac41f74da09120fe337b6e.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/84690bd9a08e66059c73566986c51d4173f9679ae6dac05613b3c488d7359a1d.png ../_images/6b9b46a1159d50b3f288c1b5bd764a0f4986086b2edbaa7c93dbbfde2dca37ff.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f86b5e0ec2133aacea18815139f16377d665d46588bb43ae01e23e0fb65b7620.png ../_images/80f569b89c4a4aa65afe92c825b8693b0eea1e3f9f92265ce9c10ea18a8d85fc.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e265116d73586420b3e2bc58887bdd633308387213e4b45b6598e9a5a3179ea6.png ../_images/6a5c3b955357b27249853950ba7ab3843f9d511a0d4099377ba6706414775c2d.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/559246fd133448a96436a236d07dca2a3a61eb3939012cb42800c0ac2dc18e6c.png ../_images/c6eb962dfc14b6181c04f8f551ea50de1d2fe523c7c6fbc3178c5e638926dd21.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3cf90a901d4ea5e5d48592bce604630fc1d7f91b9fb9f645173ebf1f5aa5385e.png ../_images/41155e2ef85fd510d57267210f2ebdede83add3f064a68015b2ef2a6ed4d4d37.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2d401fb87d8142105b4fcc3bf4d9386f99abc0c8ceab63d8f4af213b0028d398.png ../_images/492713b6255dcea538e271aa583958748509e9501e872dfeb8ea9c1321f7883f.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5c044ef4ed52458e2d4c37f8fd46dea406d52bfe66f1a884ff506e3b9074bb12.png ../_images/7658a22107fa82b47b718f235bd84169bdc7510c4d093542a64d73fe216b59b7.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a0ac5da3122980ba2f6cc9e263fa7f864223b9929f259b78385090f14ec08988.png ../_images/baa8b1f8679f48442e387b65ba0c1c3ce29d419666298f649ee32b7b52f01a0a.png