# 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/9c66db98adbdfd917480591fa3324b993156921b7e20591956c8824a479b8e64.png ../_images/07e9509ccb189ba5c8347ff87dcad02499c8ea9f012b7bdfdc4b8d465a9624a8.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/96ea2a672c08ba216685af9c6d4bb3bdbd140371a3f550dd4efd039f7f27f4b8.png ../_images/bc0be0f8410cbefdc579d69f85e38dafdfda8aa2278c615dc7b0ae93c96974a8.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cc6692acf1cc1162d25d5b9b34924d890bd1c98b14ee15ca4340e272ccd09872.png ../_images/7f82e528b55fcb75d15951217a271eb63a27d83272c5b049adf533dc50e8af95.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c66ff00c2a5fcedca4d05a517db04af6557d107e271fd0a888651cf5fc6a1d01.png ../_images/115f160181abbd96e9905ec346ff7a24bca1a4702343975636b2f12af1d000c6.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/86a934ab280d970bab446b291158d5607d32c17494a70189649f08b534fc5d88.png ../_images/93f7fd6d380fa397663791f0c4ec64225c7a2edc9fa8db3fe73869d3b37d3117.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2592df8274ef26ce693caa58005db6d3daf93969ecbd86d2997090348b2c1c69.png ../_images/b46037366eafc2938cbc780f3b6d8aa909c63233899428d416a4b87c56e1b8a1.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/62498d7db29ffa6b5dc2c4e22de840bc4a6f3202d2b9354b2186b9cbf63b2f29.png ../_images/01a7a4dcff434cd96011a70352a55c424ce7c4442479803fe7424b513c5d9b3f.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/099c36210acd134c5f4d3bda68f544ad926d66e56261f082110dca52b0966cbe.png ../_images/b02faf3dd4ab92d17f5aa173198c4c27e1e1d175febcb9eabd5a7d5531e6f848.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cdfb251da297ea45760a113c7e8628a509f9827f62d81b023394842da3f5653b.png ../_images/5d06fae554645e63f98cee67ef012931be3ed792b786e564fe0f09245628c8da.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/abd6705a6f93e6f8f505ca9314f324d054ed6dfc14541d4f348758bfa2188aca.png ../_images/6b50d360dca2aa20bc6dd9019a0c3691df7623a45c5bd7d7b8016da1f89bff53.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8acfd9c17c9178e4bfa88134152b591eb7ff556118ac8d438771de50aef53faf.png ../_images/501979fe91637f21fd658a841f22f8bb11edc14d6d353799807ae8ac9cb0dc63.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7c2fe81f96a09bdc271f0be11afcc0b52319ea10ae9c9700d6a634f590487a51.png ../_images/0aea2fddadc8510dda26f6db4ab697a2bf0f1444e916a95c1f2a081053f21f0b.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1631bc515bb7ec3267ab6de059a5e761ce351e4664e856eaf7b4f06ba318cc06.png ../_images/aa60e93595fa740905a8888be3f963cc27d3d64528f6ab0428f608ae437ac736.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4689c5821e90f1eefc02ec42d165f31ec7e57dffbac2a318d3d568987fc87d9b.png ../_images/2e328a2c6d54036dd256150959bc62227fd0ac4b3d47d7f5b4cf226d5f89a683.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e7e17a827b04f4399c7be66447364f899ec049e72702b47e920b4b067bc2e8d0.png ../_images/8051a0e3827f7a24112776f6b09a6bff3a671bc9fed6540aad6ee1c6638ea66f.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4d2cc39e91bba3105a405daf7c5fc91d4e17ad5512d39016c492b9188f9ee742.png ../_images/403b215d0a3a0cf4e0f9d397109cf35b2a131055f68ecb3b25a1c6fcfd304616.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/199edff427a2bd0e58a9ac414afbb04acf91bf2f039093cdace97419d567e028.png ../_images/55df3412bfc4eed797bc3a7f0b7bed13f859e004eb5f110dbaba170d1da3fc57.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ff7f869cd9dedaea2159f4107a8ef158dbe9e17ac09d81d70152ade3ca85b987.png ../_images/47d4dd03e1b3592bf6f6df4f36d95c90750a8adae38adc304668fe9b96e0f7db.png