# 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/ad0f6010af9d334730a9f2fbb6d662af66716249b4b9268fafd2c3f8d43305a1.png ../_images/3bf9a51f45702f6baeaeee9ca2c675706703715183d03df45e3e7fedf58fd129.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8a2d3c76ff9a8451693df0a33c598802df86d685589f1dc25391198942c78506.png ../_images/c92ab604b259741fbb276e0cb99beb1fa2fc7ac5d19c028d27deb7c16b4f0bcd.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f1ebccba7efa0046ab6f03de474eca2718d3612f91303b0ab9b255585a149361.png ../_images/2bad54c5c7bafd402d361854855cacc3d07a93b7773618c5133b14199fc8b6e9.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b482f320011b20ee20fd0b4e7d07bb922f5273a9237059ea42b0e637d7b3088b.png ../_images/469f2641be9660bc6fe335752c2ba134700c5a2225b73f01adf7551bca1e0a9a.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/889b16991fcd7b07f9cd9284cb08b6d47d64712f0fb4b64bd344bb8e5c9e4d2c.png ../_images/7e21a2f6dc0cea644a6244ba6f0cc8ffe255414fdf75c7a25669a436416765bd.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c9ecbe36909b4b09a2880a5e50487d3e19f9fe2393b4a5e75edaf871201b0896.png ../_images/989e68b97644c9e86408b1bfeab0cd1542ce176e3a10bae74cf12c611ac50842.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/64fe91043a20eb8661aec804523ea55b670d5aeed39c1c1cbe4dc03acaf910a1.png ../_images/4ddec3dc26ee462e2a6d3c37569401fa5d5499886e9c27877ba8305e48f5102c.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e7f5130f5a2239745ed270e4aaa928b450852986e81e1accc2592fdaaa783300.png ../_images/0825cf1ab0ae16470e9b8b2b86f30e9abe69cc52b59415d138b7cd430c1e1950.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/386de6ce6ece90d34bd15ea6ef5c8f28fa7949f20a033f664cf774b382c73a8c.png ../_images/f45108c40145860690c46af4831b97403365d0f6f5c6a17d3cfdc7dc3bfc3d73.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/75cf9822e69d8bd05b35a6d777a7dc97746ca87af43d7a4a365434bf293cd681.png ../_images/54e8a4f2e80af936ca21775dd0e472c986f257ac9380ea06b300535921749489.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7cdd57a8879e3fc7a216cbd806e1472f9845d414b010ea90f54551fc23e317fd.png ../_images/ae9fb59f044d7d6ec50e8f8578dba5f41c3abbf04ec0d2a3a2e1641272ae6add.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0178814588e789f40671ebde98bd6abb2785c8a1c5f5e0c6659462908ed724bf.png ../_images/7e291471cc77ca5d869a23ae0c2fa2afc33173e2a62711fca80a3364f89f6791.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d8037f008354a0cc8df6cb604f68e9dfd3baf440e0aa322be100d5fff9118383.png ../_images/8c630059e5535cd86697a56045996843d0f5a5e4058e370c18843ad911e90d0e.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e9e0631721e52c1430b72c2646166a1b892e274e81081a020e8cf8f34c9fe5fe.png ../_images/f983d6e733d170639fad1774b36bbe9d3945a44ffebf763942813cbcc5830591.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/81f850f176e9a12998c3298f7feacf3386edbdd95cc0b57167fcb72799f1033c.png ../_images/3731be15cf5912c5cb42ba70ea600d386c681f456a04aee1ff7f2959504f45a3.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/14f21aa466f5fbc5a46f700bf9074e0ae552da9952e9129a9476238de93cbe54.png ../_images/9303439e861d02fc0a8cbb97e6e22d546eccc040095d3002445d37eaa8c9ca92.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a23e1fa81c5a8009a8abae129c525081fcdc90e944b340125b749cc5d9255638.png ../_images/07cc0c708fe1676be3b05e8abe41e69643b3162fe64f3b6742c2c1f700988257.png