# 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/2a41bf81d1089222909bc0fc4e10151ae1ecd5a63ea9e2dc479b460a1404c932.png ../_images/b559b43a4c2748ea57aa0a531682a6e8f71c0830af56ffbee905645d38fd6781.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4c0beb195d263bb632a7a33ae263f7ba43b13f959c006e605803fce62173fd93.png ../_images/023811f19c4c5ab17435d1b2b529f6636e11fbb936661000445e4e40de0fd28e.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/35ceeb241f07cd90a5f12e0ce416ec283645cfcab57053eb8a3b14a0375c7679.png ../_images/e25af25f34dbe75c95c9e5be2ec3d72acd832bf19de718b0afd32edaf4c2b104.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6756b8d1103a1a02999b299e68eada83307abaf238c2b1cc6cc384e674ab706d.png ../_images/012a922f0f7c557c8091768b4e9bd99687e1934030fae2bc58b9270bd4d63418.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b73ae72efc8e3fb409164785f8632937e4cbdb0208d59f97302a4fbb72ff87fb.png ../_images/57e26d1e5221dd7ecfb0dc4b6aef5891bb9218071cf98b6ed514779e6b0390ce.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/054b4e622d354a29597fe0c1679cb1bdd10cfa6462eb64742b24c4075d3f3012.png ../_images/a11a4b31f8c705801902db8e81b87e84c592b40819eaadebd1433b65f3ebeaeb.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/77192d2120708a41df3280ad1011e91747dcc2f35819d39c0dbb3c25d5a164f3.png ../_images/486670d93fab5c3e5de21b6794e5fe4d2422a44fd821a46d3c33783176556ebb.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/11d76159f18e5525907ed638c45c2589d70fe83cbd9c5bb52c33ce3ec956052a.png ../_images/9e56c6f900f07a7b274ea9b6446f4ccbdc5c053006dc00a982a70fd8b8158952.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e88daf0e2d760c66c4b9a6a6ac05880d817403f0d3df2f7b2783f1d91b7c0079.png ../_images/c37308a3383ce904bb5c149b1beab0375bd090865b1b6398bc724f765fc0da1d.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c086ce55027e749bf6922fe8d96daf4a008f4ca5d9b76824275af91362363afe.png ../_images/bd0e5bc7c2db30c6d829170ece1af29dcc04c8f295b830aceec973cab3622d05.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/da7e0b09f3d716becd717d9f68bf527dad274eda4ec2a950dce2b8dd0e6a3afa.png ../_images/05c17adec1e6cf79be64e1a11e174cfbd5441cc7cf05f5a7a6fd2b6aa7beb799.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/335d6e83501c41f328e9abf3c7f02ee5f08d5017136e0f19b5899493920dc16b.png ../_images/cf4b4614342f5bae1e8bc28e254e8d4cac267b6b86800c0dfcf474cb1463838c.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6858160ebfcd6ef4968fc87c70bb59c0b8577e17e3ed476663325f5a93ee9938.png ../_images/ee4a33adf6d680e8f7dbe32681d00f2fcd517e99063a5bee93114415c2c96ff9.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/094209fc6c9595a88cc12cd19aa7008c92a9bcd2304b23dcad5fbc1960bae113.png ../_images/d82e91b66b53c3e668787249d7dffa9a12a0abaa8f6b133f5e0c85f2ab26ec72.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ec214258a3c1d756391a38802bc34f17cfd3b46119642b2106599f6d40eb8c80.png ../_images/903fc4be1a3f0f1500e761ae001aeafe7c95ea19b909d8033483089a8997f3c7.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b1089429c975d5e4871c076130f774465b1cd91631191c38fc2bae600d8527ef.png ../_images/c7d497580424e8010c12b0956b29499f6282aaa6511d07b2d0ef3836616b55bd.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a13d3edf6b5e9ff94a50382de61369ab9af1dfe18e5ce3206e57b6e954856760.png ../_images/cc449c24089b2312479d66ff77ba65533f4024b0ee8160fb5c50b78bae8d68b2.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9e61b6b88a85305f55768e5d4db6100c9bee7270b99360e5b3f617ea115c9074.png ../_images/8408123616b524ea12c008afe633a90ccfa892c2ed0583d9cd9d10c8adb90e44.png