# 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))
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/7a92b6fa3ebbc17e18ce3e549d86f798f6d29c21c56435f022108a1c638dd145.png ../_images/0c33162e1fa9c29aad5fbe087b093a30c549247079b2561a858f0caa68a8623e.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/53b8a124b992daad4b9f44fd4eac8fc387c3c9624d2ef8a7a82e3dd215e1085d.png ../_images/2355c80aaf4c1cffa9fa61184b2ab356a9a3235e627629c4b6884ff1f85f4150.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c1f54dfa7d9ef64057ef396efef375350a9b5925fd5910c22b2aff47f662045c.png ../_images/1518603b4af7c5a0ded14d821a7c791387b478f6df67eb3aa64d80afe535e55b.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4b18e6015abe3f510448885b88975a1caf6aef96bb301a6fefbfb2be8f23a3e5.png ../_images/f07ec2e2e35a0f36399cd1864e1ddb6d0693b1d7cc44329efbd33d7a6af4b1eb.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9689365d34c0a802e368177b6e22d1d2b4ca84222e4ed728d2852407bd54c3cb.png ../_images/df857d5594724f0a689a02ff7d3a8eab9c7623fdaa76c7c07791517edd456958.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5b802411b5151f289042fd4a216e45b784e0c8110de6cb021681d604ccf08690.png ../_images/04da6258acad001c0ad04b7c2136e61b2376f5787be0ae01f1583a955aa508fe.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c4e3192bdd4bbb411b157994c7211859da91d3bd67aa1a73d1a655e317daf007.png ../_images/7a70c915e82a61bdef1ac5a664ee82ae5f3d89ca0054fe7c389eb5989a2d0604.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8eee920d5ecce390f2202b1bc4d7b40ede88081c5db6303bf7a9d4335f579700.png ../_images/e8e129f5eafa3a1e9d717d51c34c65b5203fe6d0704f9e9181e0459272be8919.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3d4c54db15c6a49ef82fe0a6b23fd998c74f046cafb3575511e19e16287ad223.png ../_images/3570522541094f82ad42fc400a32b81ae2f07b3361abdf2edb33acf1c990b672.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2b1c3367f966e6fd593483e46f16b8b99c5a655ab2b2343ab36c7880b6b68ae2.png ../_images/4e835ca9443f75db661a6570307692bb9b995dc127f71a30ae56eda4319d15c4.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a7d2b31c3d07768b1148f341bd3b6ce5b1212865be19600a16a14ceb35894a2b.png ../_images/07c1cc352027a573309d3e2238f3730549fda1de7b823b14647e4332842499fc.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9e32c3f3daaedaeed75b215b527413b6233e2a948c3c6d0390688a5d44c01a2f.png ../_images/9b9aaedb37fcb0a94aa2006732ed71aa434ce3b34a88bf0954e52710f7a01e3b.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/460c9130d1caec65b10b68dea6d526d921be3833c3cf8b6c857d943b04790094.png ../_images/693f0dad335a4bf6bbeebbf34ce70bb62a1f526aa10c0e9d0ac26a13da618cb2.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/259faf369456388dccc8c6ed583501c0b6ee4487c181c13df63556c7d5f61c9b.png ../_images/8ed448a9c7075c29087ea5b31c710d600d1be4447dad36faa4cb9e7cc99e7350.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/37ae0d61c4625f9444024bc5b8d2b97e6493263412aa2aa35fdc5e8e14f71d9a.png ../_images/c4d0e5a94fe38cb5877ad9ffb5dea409b1e4bc38ee080a87cace255abb4839aa.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/06b23f851b674e96d97a32b4cf1b0a2e0c81b2f97aa58abe60083febac62d13f.png ../_images/6391972ed4474327c5f0807a06612c3c73cd43cbeb978c516d428104d01f58d5.png