# 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))
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/9cba77b0877997df4ccd46677fe3ac6b66a3a06ee7cb594fd65281ad20b9d36c.png ../_images/145534da6f700ba8109471cf763a1dc08a3a2598764a888856bd3a413bb406f6.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d2fbbe0f9c17fb4f8e233a6301771d11e7bb5de379b5c2a3f1266737449bc61a.png ../_images/c224fb6f2958dfc56a4b7cf878d3481f366c02c1f793dd95052af2845326518a.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ff9830d61a50f3b4849929c765c16aaa912b59f10fb8caf514aa71c8a2cfdf79.png ../_images/1c2c385c4b09b5fd5c2bc8a2836eff757191d394840a9470bde276257dee9b70.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e94bcee1b7dd143a83a6d0c74d627109f23c0856c2e2894ff39cb77c8dfca1bf.png ../_images/388bc19ead39f9195604b8ebf20dfaa74e44864a14d6db0241aa2ac35c316aad.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/80f9583633965309d66d0e6fe2207c6ea34da57ca5c87c2dbff6e8a40d34fc13.png ../_images/7bc98d39dfc2da4f103b76aee0aa080c16a6eaf43a480c357e10fd37ef4b8278.png

BalticSea#

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

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7ef353b8a622786c778e1cc3d3bc53a32bbe7f3a08bbba13a1f7ca01f73ccec6.png ../_images/3a23f8d55c683df4314cc502127a3773d246c58150913c360903317058335557.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4fe256a7120d913a756f22d32c29dc9322c298cdeea4c8c907f8d7812fea551c.png ../_images/26181b2925275e4816715f211a611c028ea884ec75a50f46d42996695d599367.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5f70c8056c2868c7b462d5b110a0d600c867bc1aea3c6a87e58845ad9fd312ba.png ../_images/8979f7f77aa30e3352810c105769f90a31cb24bd7a6b266a08d8a4c8387d0020.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a3fb771217f145f50f91a7da982db28208aab79dadcaec199b7826d544eac699.png ../_images/e5ad1a34dad96fc59c151aab91a1bd5261ae5c700307b954d10909721a6c00f8.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0d12204cdd5bac4f0681ac25d84edd1b077a50679962c8c04f289887d6ece0e3.png ../_images/62fb9420ae6987aeda880c09a796ff09b1dcdb973e2b41e88c63f09b42a99b11.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/95d4388b7c8d815cb4c672b1a97e4231744d3ee521391f8aee6a2088e3256cf4.png ../_images/1a01294a5c3712c7d41679629d4b4cf3c131183d14d65018da44b7b702739e04.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4d1c7c00bbff9b7121ec117dd34034ba1ece3b9a21ecbe0d9f15d9defb1c12bf.png ../_images/238ff198d03a7544bd8579c5aad22a6b9d57ca16f5807ade71a4e32fa3d7fc25.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/60e293e8cc234f9d2ed5dc9e5ec62de1be35c1e42f8d551f6f5cadbdfedf1bdb.png ../_images/aeaaaeece726be7372e9effad3453a2e13006f5d9d14f603dce0fe9404efd6c8.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a590008b5904087c68facac77869cc4d6b98ad2628faf15be8a9e87353b7ce6.png ../_images/2c5b1bdc2c4be223855a8d9f36c4946c4f46637c377de186be3a9fb5a764373a.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1090d1598af6e372dd05f1a2e12dbf448e028afd2ebe2c94601adb7f9511875d.png ../_images/16e25b82ff270619866b488d711be59ef8ab3482caa95bcd38db7f61eb11898c.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e78fa75a65a2d83ba846789a17c9b27db0136c94a7a51e4c4d05ba6d4f07a30a.png ../_images/7ca85ca8a42cee19ec003bf4a40b3b494880dc2c0906384f528dae61c816eddc.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8e55f9d17e920f7983adbfff93a0b25ecb10c3b7e7eaaf55d38861e20aa9cd7f.png ../_images/833eb24dc891613557dc8e0b6dee2ea260ca8a99c33b19015dddecd0fe839a6e.png