# 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('database is locked')).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/6faa62597a45becd8a05ba30907d18501b6497894f4a2e3d449dc3338e4e7890.png ../_images/e5a83d2d25d9c9f4d6ccd1dc6753e1d6722d02058c8a12696dc657c8ae05713e.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/193788ac4583a3d40ac3b3836a4375c0b41182a860cfcb2bc3f4d28ea1af994e.png ../_images/a9fe6279b458fbda8cc435f314fb4c8ef462ec3b045b4dac8484932a6c9e61fe.png

RedSea#

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

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7902050ef23447799666371097eac113d3f6ae8a2b8617527f5787d32cd86134.png ../_images/6b72e35c1cc72611a33e20fc0957e146e3f980f6c8d029562a89a85710ed1902.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b1e02f14c375589d3529a5adcb1e3fd1e0f0476f93e7fcecabab9ea95803ae82.png ../_images/6052d199c4b8c44c9562a5bf89232d6a8a6c6ab7bb4e50c2b2ba1f5e745392cb.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f920c65d29bbe11f558cf66bc4605c4d567bed1c6566c48fd6db505be1fee023.png ../_images/ed9b8b4ba198ee3a44237c19a0a4031694572baed65be23a422cefc0f0e656df.png

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2b9d3eb0ca5f1dea8f0ac7a6e76f2b3ba33bd0c159417d43bbc29a2f94524a19.png ../_images/81791e839c6ab1460cc7183e9603f65854f5241314017bf44e9f53260ef11d7c.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/56cdbdd0507089ccc7e6acf648f93dacb699769aea897ddc976b92617a101da6.png ../_images/934956ca88bcfb06a77f4d29cc1b9b9ac7d4f4e4b214bd73559ac64dae42fa8d.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0fbbe8bde702108ac5afb27bf2ded5e2673f78ae433834b8a16d067856e0511d.png ../_images/0188653807d84466331bcdf4e126ce3bd0b3a5876591b69c8fc3f6adb09d9f57.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/583bcc833324fbb48098686287741b13988129d190013ffe8d44f6a0f6f52cf1.png ../_images/72058d05f1380d9d6f9eb02558cddf94cde861cee7d1d7e2d79213e32ec28333.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/16f664e8c03116991196237782f67703787f9990fdc39340b4e4a8d2307bd6b0.png ../_images/4599dfc7b65e39e9ecb4b80e6630a8c7872cc028d2624cad9a6d10bfa5fb3d3d.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/baf2dc63fc9586e7e9009172f24766405fc2b4247711e6ff498f3847d4e6a082.png ../_images/4ba02136029526390be3cfc48cda84da81e584f6643bcf4114c2350b00ad00b4.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1ed61975577b6edda635c62fbdb9b12afd1460618276b3c399aded742b947e06.png ../_images/296eecc4bff1d5938e4ddacabdea0896d4e0d6263a550d5dd0523f025a24ce70.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/30132467af52324a6a17153b9cad27ac65e48e6ce7ebb6820efbddea1449bd5b.png ../_images/a740e0885df05be7cd86431a7d3bf2ba5c620afeae320d806631aaca75b35d5e.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2a8aaf470ca523f56c4115cd2e39bdfc776adfb239290cb134c5870ad3e4e529.png ../_images/d9d85b6ab16c3c054edc26b79007b6a90a173ff85e2f49183b8a013a64515fd8.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0e3254d3d315a91b950b7508230355c2ab16b0144c86cdb72c23089f422db87b.png ../_images/2bc2816ebe7b9ee66e058fabc6f959fb2f9a383162835e3f3155649b7993f4ee.png

GulfOfMexico#

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