# Parameters
variable = "heat_content_evap"
long_name = "Heat content (relative to 0degC) of water evaporating from ocean"

heat_content_evap#

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 heat_content_evap 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/6a0e5416c9f6f3001ff1d74d8c2bb520b3447c0cf221d0b60090dc3c460f3bb9.png ../_images/28bb1babae85484aa5120dada0b4cfa913c6ca6c0b4efda9bbec7ded4b55b118.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b3e4ec79ec3b84e2f54d6d9e0bcb9c80d2ff4907c8b129e226c931b262d5f938.png ../_images/ea269cf244f09eafc2226d7529df9fa178a413e7b8b9a1a83c2cb4c2070f0136.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/84c13d344f26675063e8e593c3f723cf7acdeadfde2b8ca06b4182230baccb81.png ../_images/e1c1289775c859cdb8070e02cb3698415e0ea91509d4f25b61e0e6a9d5ca04ac.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ea99fc661cf54dc1ce549b7c8ac5f7313879a5d9721ffaafb26a4340da6ad74d.png ../_images/84d3987b3018593f2723af8f0fc92e8f52aa6615a10d578c1f8589757e03736b.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3931ee79eb7910989523d63570972da5b9cbd42052100dc47137ac6a2a11e037.png ../_images/55efffb3db4549a643d1fc5c1a8fec2a673c3a98e41177454682c7d2a31d8db8.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/22375b1effad9d5f9b99e1e6570601fdf5415bfd2b2cdfff63a48338dbd5f70a.png ../_images/8c654fee754b6bad96be34fc790f4328c90512e00fee1d1bc26d30446236e570.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/aec5dff801401130d66380a8fb72decea1256976e4849abe77025d0d1ad10c05.png ../_images/d689d9f028c89875fbab9dda5657cfcf350a3aa9c47aa5983539c4db25db10e8.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2c0503c3ae154a4f7f9e2f316c4ea5a21b344053e7b9799d555e8fca59ddb7ee.png ../_images/33148eead2b16b3808e6829c54aee978d715c7eccd71cf71fcf9c4212624adb5.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/958ca0d353d455fea5737ee687e8a086a23ff885c2f75fc8ea8cdb08271b294c.png ../_images/c0a4e1b4ee0a8537a533844a346383334b815aaaba9d73fe64838975db93941d.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1c6d7431e439cc47dc25caf45fdb9a69fde5778a890707f2f5b89659ebda6459.png ../_images/17b948d48c1d921001b788920ae25ef0f694824bffdb3be1e85a6fb959124538.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cfe25d22a1601443887a00b951df397e9b470f81668281b9203bec4a794a3204.png ../_images/98066cb696c522e7c6c2091044553a45ad3378909bd191abe6a0cbe913bd9a42.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c9381413ae5603eded7309ddc48179a9dcb73ebfc4ba5ae261d29fd84de92c49.png ../_images/4cf9d144ea82585fd7b92bd570605abc9013dd6c004b0543ff96b349240e7ace.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/33c3fd8cd1957e54517449a518fb6d1f9cf94965642dfc72be6c3458ca78df92.png ../_images/d41d05361663eca26991463734f99bd1b557eb2ae5e8caf3192a158d729b0d91.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d30478a6fd65f4c7394aa44517b7223bd4202db7293056212cd31af08997f4d5.png ../_images/8eb8564b0ea4d6d72b07b82a1435da4df182962eb3aa22a210b6204eb45bcabb.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d68d8f45d4d633cacae3cda53486295edfda7552ac097a2cb6c66c80f44d1867.png ../_images/49acfcab63edaa2c4faee4a3a93232209a0e490528bfbfcf278c5a7649b86993.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/049da759964d27cf1cf2aa0443d4a8a87d69cee904387b06af94c321dfc66d55.png ../_images/ea392921c9d101545ff4882553b77661e108f5ef97d5bc49507ec757971fd908.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4d25558c3f453d6345cc6f593ff80917a355f27114653622f01a721b7257a85c.png ../_images/b164d1ca297b178fe452c700aa4aeac1acc0cdb34ae47baa1be4b743bb5e9751.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9211fa388bbbd3899c7154bba76f8d72bb573d82a58c06e931e69975d7fe6570.png ../_images/793ddd62474b6a9f3c4400a80d7f09695273e37c53501d353e03867d15e09956.png