# Parameters
variable = "heat_content_lprec"
long_name = "Heat content (relative to 0degC) of liquid precip entering ocean"

heat_content_lprec#

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_lprec 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/8808251ea2fa122da7885dd63801aa1d9b9659bd341e01e7d71839919e6a8a8e.png ../_images/db1238c09f2b264ba31208afb1c5dc278c11a92c847b6b48f941090a1c783530.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/83c7ba16e7c2c1a1be43fdda7d306606c0dd479baea0883b4b8cd1d03897baab.png ../_images/6245ddbfab5380657062bb6498246b3222bd9bacd2d5c195cdcaddee450b84ad.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f5ab24cf2bc2e23bfe21cd4fce5dabfe7fab795cf41d59d07bd7c0109eaf7d74.png ../_images/c0751f148885c01a7f45b8287eb8b4121c6eec63c8c76a25ae51ac5aeb5d15ee.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fc740727ec045830af5e92d3e4fcd0d329b696477f162c491b56c5f33010ffa6.png ../_images/623d95cbefd78df089277fbdfebfbea3f2805f5bb33babe39514cce8bcdc9de5.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5e7da7f8f5206e14896852b42693ec26ddd5e16ee7a142f569e9aa8b41fc7e3a.png ../_images/3d5dd8e78214cbbfbd2890d3fd1762d663090d93a125216daa8db76b65c928d4.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/659e3591356211f07afbfef9cffb7c171f73962373bfbae7205b664a63019ddc.png ../_images/86c1bcd24a39d2552161582e10f4603c9d016282f576820160f222f581d91af2.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/78b1923a285e9efac31bfd363c2eb4c5fa63b381c3df016089eb62c398eec3c1.png ../_images/cddf0c8035741d65bafcc30362a8f0349b4e85d2bda9de1a1d919462f4c1f97d.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a475d7f41a7078a4c2edd1ec700d8d9a97521ab97e4e50c00255cea99af695c8.png ../_images/af4eefb77812414c37f4cea87163031286f67437e613c161877ee5cf0b796266.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c59f43b6bb02151ec0764ab3039fd1582eb8417eacf558e6b8fded1b35673cc0.png ../_images/503d5732f59c532b3c9f11f380a7c4d0c95b96582e8bdbc24b4164852a085db1.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2c6cc183f42164f454356c79caf7504c6e6d6bb663b1b7a344f93ec4fd9668bf.png ../_images/8697df0653e58068979caf9546811336801a0b0dc8cf493e374a88b06bdfb309.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/688d8ca416dcf7b1663768cc9aa272b0c38a7527d3ba75167cf410f953119e00.png ../_images/b9c715d045937390775081b1b11b9642584c10f6e3c6c86bb4f3afa6081b7ce4.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9f82c96fdd1ef61a4c0f3d7d64117605dfd563097f9199180dba145dfa2caab4.png ../_images/451ba4094071e39538922f0475f1e9cc796a63969b43be9da0e9e392dde4d91b.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0e4a0d31b8ba9d6ef06b9f7561df0a91bbc7b107aa8f58d5397413ddebe7ff35.png ../_images/0252a65068d611ef3a897b43f4d9d7706ef5f748c142d2d528e608df562f47fe.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d0a880ec08810382f15fa4d27f632d17d75993cba87c8accf9b64d1d525dc051.png ../_images/8671c7785113af7de1ffbd643e0c2d9f8aa834408b4d70e3a4cb2d6b8e1a31a2.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e97d6c4bf84cec56dd1f3c0a300705ba8392b45847eaa7948760fd37ad8a0de1.png ../_images/44c3039617308ac477bee4c66a36367db1ebd9a4d7c3034e5b4daa58870e5ee1.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ea8b8ce171f8841e2fe397e4566ae811f41ec9e5aeccbd42c3d8026fe37c98d3.png ../_images/9f15e0d87094467be874fb6fb1993b62cd7a1dfa426fefb10cb567bce844e338.png