# Parameters
variable = "hfds"
long_name = "Surface ocean heat flux from SW+LW+latent+sensible+masstransfer+frazil+seaice_melt_heat"

hfds#

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 hfds 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/5bbe51a0dfbac3f20fce9abe245c22ad7f4945f7c0cc5be04bce38146976c65c.png ../_images/ce6cf36876f1e96ccbd0bc4e81658109d32f1c408ef7081d0f4b17c4ff9e1284.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0119d60021693e492a8bfd02bf410c3fceee163ff778ac58ae85a60d58cc83f7.png ../_images/a0835e79127f13bd830b9ec88cab6f67fd11ac5ae780e2b46645a7cc7a6c5148.png

RedSea#

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

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/06d1bed8da938938043648e8299e237020b2fa28258eaa11b0771056e88cc896.png ../_images/40753e61d3c0962fd4382c294158eccf99fb5ce0e0ed768aa7704362bb3986f5.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5dee709ff300add72772f095fdd819ff6297e96c95117ab1783cd27af9c4af3f.png ../_images/d01b9b1e7d90ce48077a20c0fd5111d8ed6345bf05296833d5b48cc7c27ef48d.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c003fe759c44fb7e098ce25a27a5e008faf5135f8874b02e61660a38950636bc.png ../_images/98580d5204a8e8aab049369f47f70fc869ef2c3dde9b48dd63b73528f4a6eb3b.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/611025c44d63088ba03caebb228caeec004433f0f7d281d69a37dabbe6a37ecf.png ../_images/41f47633f7ebdea80b357ad2129d6bde03c647281dc48f21184545201643eedb.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/357c7a3070533900d49030c63b27849a1950f09ad594e8ab51b3fbf4569374b3.png ../_images/b55f083bb1d390620cf5a7aaffaff857f535206ef812e72f990da0cc4b55258c.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0f64680e317bfce7af315ec9689f76728823b6becfda2bd418ce26272460dc54.png ../_images/0d0dc3d06bb2f196f91c57a7e6395f5568e4b717ab3c391d69bf77b2302e30fe.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/887e632f8c80544c7b453b9faa707cadfec04fb43dfc21167b24da02ba2c25ba.png ../_images/b969911164751d3d3d155ee78ad72607b00cde8944afb044b084e66b87de0d90.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/090598c7297d77d731c38bab2a24bdf6bb4b9162e4a3832c2cee296bb6d2f4ea.png ../_images/cee37f18595ae85ea60a8d8c902d59a8cc2d0eb495b1c5d1cd00e9dd69b95f7d.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/75c60c2f8a2328fbd2ac1ffccc626af8a0744aaf92340f639d37ba29823e5186.png ../_images/d814715f30ca521621fa176f1624793efb323e4ce36cb78a1d6ce6cf61a281f3.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6dcb4ee6cef00a057243005a1dd801559458d6c076547c94f17b69d0047ce7f7.png ../_images/0917ae658c9d58d88d482a6761d4be03087e6392df129c9d681d54051e0ae33e.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/41ddae70920db0dc27c3554fd45f149f2dc3a9dcf1cd08392a84dca8a4aebdb4.png ../_images/d844303aa2b720097fce667d614e2fb93d6de7c97410d5c721a0d04cf12ce9ad.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/544649d1fe5f0eacabb2fa4accec3a4dbeab0b15a7c135aea08d8c771aa5fa0d.png ../_images/95bf7a7a7fd8b91488184f2d46ceafdb357f1a9290e48b158151affc9efec449.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2e9e01a5f204b1b079ef1dd1f71d65e02954b3b7cd4e80670693f2824bf35337.png ../_images/e86d8a62994cf13e0b3456a9b6681c26dc83788e1f571322ef0011e4e94ab775.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/734686d4f25b11f676089cb74f78fb8c1588ee77f161e99b4be021f4b10531db.png ../_images/85f0a7854bb87c654407b9108617f857acb6348fd0f4877b513b09e07fe1d191.png