# 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/e0159806f36e63f8907ad580707dab2339464ef5e70203babe06fc207c76fd26.png ../_images/6f49b324ae0d29b3ef6685768895bbfd1965b71bd3b41fc86fea45bb0373067a.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/341409c2ff24873ef42ec13c310bdf5293f4840b6166315d821c299995f7d944.png ../_images/35f106794ad1962d46e6da5bc87b7523418c8d50f4dff1e9250ccb6069e236c2.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a723ed5c6ebe1976bfe55a73389e5f9585daff360b7406c2efd3df55709fe777.png ../_images/8d417a3861eaf4bbe11028289e4f973a77af9eb238a50db35f1d7e5a8bad7075.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b9f1b4d9c924fd99a73f0959ce8194d3e618cc628945fe8f2bc50616d7c5fd7d.png ../_images/cf5546d1970e1bbdf814ae0d0a80136bcee44b2d2d2cb9a63c1db8900175b998.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9fa2411dbf182b10556b1e7f4a3d51b9f6123beddbb3aa53f563b0ed0dc9f626.png ../_images/8443a7b6fb35fbb418b46bfbfbbec24a05df3d837f944e15754209f1f2dea7f8.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2527b461c6aaf6edfa7027b7826a324f185e60207f09564ed7be1050c1cfa096.png ../_images/7bc87f189c305f746d34774ec2f0cebe72d8d185842a3428eb4fdda3451a900f.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5f1f09c7ca5ce250b2038c1b55a85f8eb489725efba39a2e4e2221c11eaac2c1.png ../_images/9c050a0cb1e13e46b1155263fe13f8d55e4b5a294a43092d34376fbadcb9036d.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5840e0d7531804703b2ffabdc19b10d45f918dd73b3287b83f955717bcd040b0.png ../_images/253eb33f5e5e6a096837fa168264bcb675bcbb24c5ad0efcfb15cd19d250c5a0.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/79a0536aad81df996a54067459c97d3cb836299caa002e97398d4379c61b1729.png ../_images/6a3b7a17cee2754a0c26f7708178d1b1178c7dac087c18621c49946aa84e8cfe.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bc0d17b579ddf73f1675a65ac01927a45683b1420f9131524bfb8deb5caf68a7.png ../_images/14022031aa80c99a5c500ff43ded30ca3d66bb01ac118c7686ffc3e56301be3f.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4a7658ef944a0db1072eee482e079edb4c22af140fed06e2581fe08b00af6f7a.png ../_images/567f85ff8a3bab68c801e75272698666b1da1185119f592be059280b6da0dbef.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d7f2b8cf7aee32f6953afc72562079606bd3e7b088f9f635f67f5ff6b6a24cee.png ../_images/81e8b0fea8269c5a3a1693732f3a1a1f508fb5af49e18d03f8e94c61243af429.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/94a89372d9f33225dbefad58f3927b446b7083ab7856c3f620b181c49b6da9e8.png ../_images/ce45ff4ee121fc49d8de7c7c02b78f77628f9b6cb86a3d011378e7778e4f104b.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e7fbabe8b3fee75db4057d77719319c017cd1f6369ab4b19eaaa2cecf5c712e4.png ../_images/8e1b711da71670eb77e34eddc5f0be8e8d728f82e3144a710856e8a38803b98a.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b643adf081b87825e83837288c1574a51f01faaf4e1aa249d4a67e27e0a66ba5.png ../_images/5260a38d8520092a37d2623db484bea0df79f7378deee3de0b247d3bc0ff0589.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5842b90234847fad48f7dfbee03824eb22724d2c63970e5bcf60e5e63f9327be.png ../_images/97057ee905ec665f5bf61b18a694973dfb5abd43fdf7121ccad3df16010575fb.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/df837dca00cb4c577989adef412c3e6877d44a13f0e9dd4568dd8be7b835b606.png ../_images/303dd91cf8de49ce67d41c767b26b8d6b3b9e06ab9328b3f6024176b2e0e3404.png