# Parameters
variable = "heat_content_lrunoff"
long_name = "Heat content (relative to 0C) of liquid runoff into ocean"

heat_content_lrunoff#

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_lrunoff 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/8c57f0c927621af108316245fe9594d50d3374a5d4cfc6b85958c5e60f7cb4e7.png ../_images/7fb3f3f4243f9fb02fddd8c696c326afc4ad0abf77a884ead5cca538556d615f.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e0be7951a597c75d56aca4132d88f5a999b6a0a37f1bf5fb777bab2aa3894472.png ../_images/7d7a43e4b70446b64589e202cdd14bbfd4aaf38e8c315651f1f4e293fc3c4c33.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c988cad2558af63d5fb168ee6d72b63247c7b86e6970a14aeda660334746b010.png ../_images/2949c9631384246f900951f03317825ac03cbf885b78b9d927c3bc2bdd5af3f6.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a3d8d8b9d43577c1fdb7d3c445f9d0e08f825a1456f96755c05731160e6ff2d6.png ../_images/8621a7e504122cd71a3d3c9c63a92cb5e076d58d11ec7f1ec18701ef279e0daa.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e04748dd5972680c81aeaa9d17f89e5f6fe2dd242e525ffad41ae671041b95f8.png ../_images/82c06b8de7c4df547b993ded6c634c092e4e92ee79a38a13281058405a8c17b2.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f160cafbab4738171aa77d70c7be4c2607287823700b48277bff2a615282c9ab.png ../_images/7d2953f80367e5e310f8c5cbc126367045cd040fe21717968d528da018e42e14.png

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8200799f57898c5df35d628ec134115ceebbfaa8dde69327abc497b34ee5f42f.png ../_images/efbe403f14f3f2710030f604e0003ade91b61ba578adabb7033c81ac38b13f0b.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/912d0a1437c0dc2cb28a29e161d50dcc8898c982392f7f17aa6547ca7ef80329.png ../_images/3a6536eddf6ef1715b94b8f2932b7ef3c2fda31ef3545ba1815893ab1fb37695.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7468af0397c60782bc7b2f2b5e10e469156f5857fe93c4a093067f739dc34cbe.png ../_images/57ebee01def7d72f9963ae9360438582c2b34b5f7f42543727d1ddf475368b87.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c9c2516e7f60fe07fe65588f37423e522c8c83b5df58c1b79e7ffc1cd9fd5d07.png ../_images/b25b027f265fa1455cbcd9127adc7b371c5e2dced960d0c7070baea8cd7ef26b.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5c954752e047ea1f3f986789ae0ffc603eb8078ef9c69f08b966c0037f826e14.png ../_images/6ec0da5706915fb7f74080fcd903f07d32be87fc983517b362f2fa8abdd40e87.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c6243cf15a885bcf49ea4ee71b0ff94b83b7ec3fcfab15a5085dab02961b9f0a.png ../_images/87ef868c1db904eead008d2da917c8fb384955fa925db8093bb989db0756a4ed.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/addb8fd332a882eda48425c5219297a70cb2a619498bb13074ccb007eb6d29dd.png ../_images/9729d7e2627e16a7229fc0d3fc7e00ea8acbe02ba436568c252ce03cbc469a55.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f85f0e4b63f96e2ce3a9fc5eeb9bf00cd4fa3bc824c8638f50b42a219924a1db.png ../_images/9717cafee325b70c74d01da65f6832cc2a66967568a55774481f86f8154750fa.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6735ab22ba02cc0447378b4cc61bf8e5101b194562af8ae92ef9a94bd2127fa6.png ../_images/c32503121934709253a27d2183110097a29feb38efdbe71f66b2c061eb81de7d.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ec77ae7f21f803792c526946d147cb308977bc584bee04f538a91de732387d53.png ../_images/47aaf6d7ac608ff45bc107f6ddaad1728c3c58f88bf3cafbc9b2bd769fe0192e.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f533ee3db366999f9c9b3e1390ecf3687f67c8efc7dd954fc198bef617c83b50.png ../_images/c0d3b4877d775c428ac87fb1db3779ca53f802d7f7d2aba32732739bb63e8257.png