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

heat_content_frunoff#

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_frunoff 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/b8f8760897d0bddd3a609d9bfdd245d3fc1a9bc7b873382f75a817de444c543f.png ../_images/8f1c418140b145a171320c18f04e87bc3d5e8386f9a806d0a048821ce4a5e0b2.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a61d709483764ceab6ef032fbe5564d575d7b75f10bf38cda294d3efa02d785e.png ../_images/0ed97b9c4fcb372fb51a0220b0fd32c8bcded978fbc23a6aacc0a0d1fb8d7a8b.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d6adecf894eda11c9c348a4bd1070bcea686cb3f9821a59b64f8fe842fc120ef.png ../_images/4165c5916686be8f7d429fa38f33a56d83437be8dee658cf38b9bee9ef02bf4d.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/338f6fd7a6bf0eaa9066788ba1e73fa827e7f8ca4facaebdf9f65f622eb8838e.png ../_images/762d63bfb1a9cb0841e783dfa4a38d87c081a91275f1cf1d0697fe62e9aa7aa5.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/68051fd76c61dad86f9ceaacedba825590a6157aa0bd1ef26f92ce538f450964.png ../_images/6ee705e793d6a0f879eebead86f82f7a182f86a9171f1f56b550766f8bb5bfc2.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1a585a4623160ff9713e070d7079b65e8ebf6386eb874caac3c049a40b783d26.png ../_images/f34aa48db6baa9ccf60b5bb6635796cfb341f63f78964d6a83d4c31073b830d5.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/04bc9e11b205fb928e0e1e40bccd2162991e62062c9d31547defbe9e18706b1b.png ../_images/395fa434f2fd98432bf076f30c1b727bee3d494b884f4bb3ecb5d01d0a908081.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1bc4b664a0ee5ff7adb35455322cc21514feaa36aa16cae9a7e903841882a498.png ../_images/12786fd72d05b977fec639bbc8cfc2eaf5bc80e5f568c538a9a2769051938a8c.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e664322aae994eb1d1556057305f02d04b2d62182be37017d685e8de7065d8aa.png ../_images/22a2ea7100c1d636181c12f78f058f5cc083558dac7e2db224c93d95bd8df74a.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d1371702ecc2950536aabce6ee60eff5599e2e5f6394ab3622224f3bad6018e5.png ../_images/2d525e7bc024fc9a23d31f15c059b53800c98ec7582a294981ed28d429fa38a9.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/343571a252ca47cd4b726eaf7a121e3288f2a310bedbb6fd441da5cd91df7268.png ../_images/cf8004c44888d334abf69644a6d4e4bc7ad47cf0c3437d94e46ab96708d22e63.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/947751b2ee312a3ff04d0af2a2520e3bba784d3dd5e0648f7099c3bb85dfe413.png ../_images/f934eab5486c8a879c1f22127d8391ae4b66cc854dbe18f988f355a3faa7fe85.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b660b76cd09231143be81c4d78e8c96173d37cc9e84b38f657ab5910d96f806d.png ../_images/e71dce480ca84fa80578236aa6e78a75d53a8ca4a82eda84aff1543a9a3d8109.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/87b4bab1cfe4a6d4615048c8ed74d4ffa51c9220f5c3d03a2952bebda7cde109.png ../_images/247b92b3f69d76ed848b47eb8fb1d17c49ca0893055c2dd19703a20587e43050.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/61a2768635fff2601699d38350bb8f55666381c798bcc977cb7eb926f7edf6e3.png ../_images/1380dc0ffa8ce098579eb05d7caa23c0413dd3992701c61e6a69cb64ceffb2d9.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4f08153d1b7bed1a32e2581bfb6c0f48950e36b38ae5fd5654ed834dcff676ca.png ../_images/97d516c230316841bae3b2d3d36df113c2b6a93850fc8856d5ed43910ec15e7b.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/694e92f2fada5e2cf9158184a213b6eeb9d3580f60a08d47ed3e3fb66805156d.png ../_images/ca3a3b48fcbc14326bc670b6ab5d00fbe6d416bd3f0d53e9a82a68156ff518a4.png

GulfOfMexico#

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