# Parameters
variable = "rsntds"
long_name = "Net Downward Shortwave Radiation at Sea Water Surface"

rsntds#

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 rsntds 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/0157ff6735cc297137a996a3713d9e6af197391bd5e12d35ca5675a911eef4e0.png ../_images/45019d94c44e080e77e6c27fe9f6e9f16c873d61a4979e3ec538a57e968f3bd2.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1a093cb094cf356a164d703e3892b93277f95f9272254dd2c5a5dcce1cabdb54.png ../_images/20312d95da58c9886bfbeeb718f341c6cb2960e3a1a74e46045d9fb5912128a0.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/43e0a7296bbf9e6adff4cc6636caf63b10176f70df827c8568692fbed0ebcca7.png ../_images/04dd39b681ae495f49204c2600e23f051def07b310fe73abe5efd43ef37acf71.png

BlackSea#

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

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d601358739205efcfda41a7e5be44b8db87e2d37db5b75c6f5c7d1b4a9352068.png ../_images/de16b36ed500252202f95cd327479d9f03c70648100077e063bd8ea28e75c419.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0dcf5d8ad80a392a6feb4293219403706c4ee345d24ba1f4914533bba3114461.png ../_images/c884486b16033f7209c3b72bc74a733ddbb1e3d5fcc73900855ef8658a43a07f.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eab49ea6a029d358e463b22f9ef40ed6a8a5d315d0256f0729bfc13c1031e584.png ../_images/8aeedd865bbbedd5a92a5a2577e9ef4dcf2a8e454538b6e069af4d8184f8e1dc.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/85788b3615b2f7cb99c14f0764ea6a47c5590c2ca3b673a1a9ba66ca346c0b25.png ../_images/8e89ae6425768ad7445f4671337a30ecb8d324ebb146c83b6bbbaeadb90545ec.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/32bf0f3716ec1400ec4ffb2c1eb4b83709313af4815962907a2316ce21767ce6.png ../_images/06414983745481ac8d3852095fc721839074306ec1665c0cef09e10d8f08f87e.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/727544105d594b251454357230da3b89b708fce5d79d6527b511d6b708070784.png ../_images/87caa0f02cc460fc8700fbe00a0e0bf86009cb69db395d5b4663fb9343a0b851.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e8ab39217b6fbc936eb5ccf8ce4c3582d91b2e0bc5bd153b8c98ca6e5dba8166.png ../_images/1935c25fbde6cb5aa448aab40efd9b8d1b8144d74a27334e94d34b856c8efdb0.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1ab1c561cbd67ab8f24e07ac71c2f8cac69eb927e7460ce3e21a1870e26fe75c.png ../_images/83bc494942d92a5b94a5706da2a462662d4d2bfb39bf43326aff8d09fe5bfb8d.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/161c24d9a8342ad6c43d12a54e227c1854633b7d336dca3ca0b775897bc9f5d5.png ../_images/08ce7d5c6c3dbfb7b65fd43f4a3a6ae9518a009e2de7723abe220c2cff955685.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/52098e818db0ebd428d2fd9bc4c0f0d920f4470e861bdd31efd09234c6cfcddf.png ../_images/accc845b845f5a507f50a628b1be3db6b737e047d9a45e2e66f6f3de37d0fefb.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9504472ae62010340bd7513c62742855c976df28b08af6be28d2d4593f852d2c.png ../_images/6e84f12666b7447038e10b40573e985075bff4bd088276791076915f59b4fb25.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9fdc4c057a4b1abc8cd21b5cbd65a669ac22621199b71626bd40d3afae3c75b9.png ../_images/68a1f96167e3e5687b87b0ae619fb4d2ff0f8991af2974d373a21f4ca924fa25.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3ce4c50e78651636d47d16dfeb294cc122d9ac8116d193a00c98ea88433160c5.png ../_images/0450a932875f49c6aab3c2c4e678baef60e1913ff6dafa9a6adeab6ef8ccacdc.png