# Parameters
variable = "hfsso"
long_name = "Surface Downward Sensible Heat Flux"

hfsso#

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 hfsso 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/d22e4c06eda9e93b6825e1fa9cbc7b1466fb2462aab7fc059073bf5d457f8c36.png ../_images/b7c0b014cea9edac7b273d71e92f323a352b594870468b96180321db55a797c1.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/406330e9f29cb653c748d0c3b00c394b6117be226f3dac4e93abe59a3e3a34f8.png ../_images/88082ae0e219c3a82558fb81bc23434c8da5302f9e929e0bf4865ca06ab71c09.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/78891815947fa08810d56a10e3e6eff59db117a89e6d7269cd676e95063f6b02.png ../_images/81456e64db222b20a2c1ca3603b77230183e514689cd2bf79c2d6469365c8efa.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/84ba8d76e633b6042c454f336721f9ca4a942450af4cf464a755113b247b38cd.png ../_images/233c9107f6bd8988a3cf49cc6dc16e7ea94339f0e27de6d46eecba345185a09d.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/511e2a4c074d86ab541c1f8377eeb7b1b9082113c677cde547be7aa4541840b8.png ../_images/533bccc63363eba6fbfd5315d6a0e7b480f3c5b596b91ddd773f100f0479d783.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/408d4faa96a3f5ebc03b5c2d16690576888bf03de0ea2bdffd385e409555a605.png ../_images/62d643a34ba1cd95bcf065d116c59bc2e816b3ece51f653bfb4fa4a0e62b414d.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/35a1ce3997c652106279d0368999e54e112667b4c04e13229cc0fa2924905ab4.png ../_images/670aacfd91a606b27180340eead72b4ebc58c6e95016fbb24e590eede66f1e89.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/15eb0c5f69cdaacf9b0066b3364273fb2dc1c9e3637cc34b8c62fe6295905a89.png ../_images/8cd8d48ce68c5e8c6298086074d1b3c1fb0f9f266e050c2a176959167f43d945.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5ee72b1cd8a8856fa92aa8a14f06d138b3f9ee6ce5840f9c58608c806b248cc5.png ../_images/9618480c98d11361f2f34e47305d18fad14ed1b3e00e5ba95fc998c513a141d0.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0b47e37e56c8a494239ad9a64551cdd4f72d81e1323c2a569e7d812ce42d0dfc.png ../_images/7965bd578430cd4e2d68062aaae6f6a1f3e36d31b193cd30bd534d5aca22400d.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/236cffe598429dc9a63aceea768aae6046999890ba1a1d5d7cbfebc3ec39260f.png ../_images/d7f7cdf5552c3f52072fffe4d0d552f11a4f89d8c151ce148c1f963d5d4f8313.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/de0dad59ff43648eeea5072e86701910dd6041a09c518cd21a9543f922e9677b.png ../_images/b4595c0c562c6dd2ca0574293cb27b626a6299cfcf41a576a412a50181bd9291.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/52e78fde88c2b724fb2c57f5dd08feb9a8b7e9a9ffdd587fda1a61d2c35dd46b.png ../_images/b70ad23507eef8a5142d8381d485b25ae8494dddb1789ac5f370d4b24cc48fbf.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/869e9119f914e64aea2b29a6ec6b0509bb41fb30ec946edf170c5f459aac7af4.png ../_images/f8513f81f60ec921c0acfc5251e44e7fa3e495adf04f6ecaa23be547e3197eb5.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/44803d6cfb39953b573a799625f5df9db614fee29ddbf91cdb2003cb0b135845.png ../_images/7e32aaaeb14639dbc6d09231560c617bd4f69c0089dab1f558e297dc91daa540.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/36ee5f216b5421a9cc2bbbd0907f12b85af03f6db52ceac016549a830831471a.png ../_images/35a1a57d4b5fe662e818b284f7dace21e90a1ba144d80934633754fb880e5f87.png

GulfOfMexico#

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