# Parameters
variable = "heat_content_fprec"
long_name = "Heat content (relative to 0degC) of frozen prec entering ocean"

heat_content_fprec#

from IPython.display import display, Markdown
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.

# 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_fprec 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/94248ef598b4921974bec7777360ee4e4bc96667cad52d684c95465b6578ab0a.png ../_images/2ba6ac2cb76b82bc83b584d2be4f98f05ea1757fef6151adee29eea4eab9cf34.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/aa5a083f2fdaf465a8d8adb11d0fa891761092225f0de48f89e9deb45bb15539.png ../_images/8130ca248f2ca328d988012a0977130264fe384bcec9c48cb0406db228bd1047.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/46bdaa10f248179311eb6d247928db4e9b216b8aeedc1dde0fc07a5b8ee3fae9.png ../_images/99049351000b0957e3ef377711f85b5cc5ac43383a33cf66fa84584c23ce305f.png

BlackSea#

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

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b49999207ea92ca263afb8ad1b1ed1e476f9b03fc5951e1c53f9492782e253a8.png ../_images/136eacdc374dcc66c4debb4135bc3e8ea90def435657f838b8f96a00ff7bd308.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f7bdbed61ab6af0398393c5bce7c092d2456afbcd4fb8a6df6868e66e3d42b53.png ../_images/b08e2da1e31476f29f54f37cdefb903aebb64b39b74245412ab88158c9c63e99.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3d00848fb8d717683ba986f055448f8e8d39dbb07648d319a5d9758f02a48adb.png ../_images/8c820b92db79b6e95f39966ca6715a3cf408ea1a2d35507433a66b782c33ff8d.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8a08d70c46a85d955a33c886bd333919f57a314a29e56fa3a23000f374f6db0f.png ../_images/e5c9430365ac4affcc7911a9c248d93b55dbf1c2eea82076c29c0b09657c8572.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a8faffea156918dda67e43885904e605f08a327ebfd05ad779d55540c04af1a9.png ../_images/55d3d86e912aea8fb16704ec48e1b68e4c04fd2f2fdd959ab9a97290c694203a.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/acdd69acac1c7f70413f588444142ed791e69ad7872cd4d35bdd70575a9133bc.png ../_images/9c4ca3be82f3d5612e4159cc1bff7ad823e05b379a9eba67e0eb99b79661cf7d.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5b14aaa204ce02255b2b2646fd00af27351464110e9c981d183b4ed727974a8b.png ../_images/d5929c9525be2849aa2e73da5989e116e9a56b0328d4e7352912cc75a026b2f8.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fc9340bc92ccc9dc68309ead9ef251424d95618777ec7d98076f82d5f24b0381.png ../_images/8a4685352a3ecbc5256e96e2e05d569eaf6ab47ea2e81541247ec36414494a21.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2d486dc9461b7e0f4cbf11e72f39b445a201614385d138c9afb63ac3ffc487c2.png ../_images/ccf55f12c47176caf34e4de444c0b0369ac3ca378f4637a6e6b78a1b8634e93d.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fe0f658434a0afed7355e2c4507087a41771e054de18493ee630fc45df9d6a14.png ../_images/df83c0c6d649ae7d23afb3a3331326cb47d469f80e1634fd8f35d8705310372f.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bdf072899204f81d686626d9a1edff62e9f8cb92e4fe74f6d418fcdcaf396ed2.png ../_images/d0627723e0d680c5bb79c239e1f8d44c048fd45cfb64772d89b5cd4123ea0eca.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dbb1d9eac382ddf689c6a0d509e1f4e97d5eb56c807e65db1eb1e6d1799b1ff6.png ../_images/c471ed1a43d11fb816ad8c6a5f933af005337ec1877f67d2a4e7bdd2efe5cdb5.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/471e8aef34d33b1d3f5290fd5362a121f3ea561c47825860838b0abf0e72c225.png ../_images/99657a35c5694b49d04afa6bf6abf6b4b6d549ceff35386f30a213f8316a1aa6.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9531b3566a74a85f115509a70d66176d261033d549c5c4131c692397f09ebcdb.png ../_images/ef6f7847c0e25d3008de009949844596198d0a5831cc17eb8b78cb3ca68f8283.png