# 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/e60288b5c3a641e9ac8064aebef862ab2c6c1ebf1be8c3bef653750a80cbe104.png ../_images/8513617a6c070c7152356d94b70e1bc31531390f907db3eeb51e86eb5c6ddaea.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/93a91039a62c4fc9b5483833cde954206cc8bd7c76b13d18e7a8888410ed259d.png ../_images/614adb28c5e0a41593d92465cb95c4ae5f589fb0b2be4d63b597426501fbd1f4.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/511326b9eb54351c34f8672bac1d6f158d0101eaf1631a1767d649f5ec66a5b6.png ../_images/f63e8dfe9e2906c29d75ca71570f2cd4b4ebf878083d90cecc4e0059c643fdb1.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a1b0bc3e9adf2da622bec88da4988a43d59abfa60beb3d582336471cdfaff321.png ../_images/575da59fd3a22db388893a85a05a806d1e5b27a1f52efd7720d9033811b2e49c.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3db35ee1ef50b411853cb9037081693058ba7143f17dded764e26d81e213c29c.png ../_images/83b4d7de8b23013d42223c7652f2defbf6754f59736cc9c8ec18a083757759f5.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3e5d16e23bc391e3cb60791a6e82f1b5e5cbf0b87603654a94580659e5154bde.png ../_images/41b58cd0854dc7642743332be7b7b32bfb5da68f7c598e3286428341a2f32849.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4bbf5910b01d12f226370f0f2a7d6d9ff6c9dcaef56c6f32a050707824d31b88.png ../_images/8d44f3847a7bb60ac29025aa6cbc10dae97d52d5a9d20991678615f500f9b0e9.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/35c4de0dba8d04b14489558263e6873444f60c60cac54f3d930fed02315b47b4.png ../_images/72a3780639d600e3e4d30f980af9292127c35fae30fd18ffff2577f1207c06a5.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/54adb089192ce406b33b79659a9d4c0d12394f0becf7f36e0fc556b07ecfcf6b.png ../_images/944cdd93be2d62b17bd1d3f861076c469d386bf9b3bd583bc55ea7f4b4420d06.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2a7257ce55c6dd2f7e0a8d9d1ad6146fcce11437756f21abd8bfb97f79c27f36.png ../_images/f5453d67c9068d5ef9f05893108e25e166c042429b6684046279c689d4ddf525.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ea65346db5a0ced6c9eed197da14140077083871d516a378ac95f8729ce56650.png ../_images/13d6345e55f7d4df62c1ba95dddbe452cd269938d2b12fa4dc968ce569822a7b.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/213326a359608971574121dae911c0b7a6aaa7b3d635bd53ece9d245d3776c51.png ../_images/aaa19a439cf8f735254e82dddb5d986ecd94c326b113b1426391b11764a543ac.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4968594c704f6ad14cb91f3669778aaa09f315ab2672fca9c0b21979fd3c8602.png ../_images/f963590d786ef1cc3f57880633e734bd94c75f2551ab079339f51841b821e152.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0aedc2840aa092f557efa671e02a221c1cd1ad2d198f98638409bb93782d0558.png ../_images/fb78dcf221cb5e57d4c4a1243eab0003cb200c209d4a3394920c10bd8cda2347.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3768019f962d1f86334597bf7886bbf859cdc4b483c18a34f41d8a0532b71b1c.png ../_images/9bcfcaadfe41978c5f241391ed3a0dc564f5f5b1047bf583fdaf75e8cdfd88aa.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2530a5a7b107b5305312084696cfe0b432ed3328ae29b61dc9fab0799dcd3173.png ../_images/38fc2a12cda2224e0859c8aef4654181f20366f35687bffc74d788a775968e35.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/65c0bb13a7b133dece052268233c44e3cd8d62e5d481dbfeacb7e9fb001d5a91.png ../_images/e4404fe9b718ed0f6452b86ccf60c5ac83391b3389b58d11fe9933d5d6ef2ae4.png