# 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
# 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/387384b9b413cc3e2fb1a1dbe3f44972940d60433204a5feb790586e38da52ce.png ../_images/3b874d3d6d9f8a72e8a1d2c42f2d7f97b6136af4e05c3618a901a592f206cc8c.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c5a74dd946715999edc72463a5d9d3bac78f24c1618b22ae7baf6a6eb6c58b83.png ../_images/afb4964a0b67317db3344f38d385ffd35359938a711998f3aebab287ee958da3.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.
../_images/544faf08cab6f7804e82487b628ebe539656d903dd4b784517e6d6532b08eddc.png ../_images/c1f57d6c36f75587842b4625ebf49632470afbb9484ff4616bb576c90533f94a.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/814941357bdab4456a10c00041007b803e2f970aec9c3f850758b59479e62468.png ../_images/dbb80655d3ffec8a259b57873d089dfaad44cd496dfa382688e47f892bece547.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/63e61b77ae93793feae23a46ddf3cd685f1fee078328a645aa9261cbcf8e6180.png ../_images/c4fa7775d28c53f88c68a38fcb0cacd253deba388b7af24f7d65d3cf5549f6cf.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2d5b4b22a49d41b51884852569f63fc5562b64bd00adc791159c327b220600a8.png ../_images/252cdec54a0eb38c2bd6cf80a2825d574bb2e744b956524e2182c860c967e882.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b24636b492810601c679a1e30bb7b280dcc8c943316b193efef7e763c24ebb94.png ../_images/0fe32ddbbe79ae091f8dea05467fdc368c5826b55e1561a8c75b508700b57fa4.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/17c1c55c27b0d73a3e233772dbd23d5c41acf29c7130182517d3b02d5096825e.png ../_images/1177de15a390e257ef6f134b9e74e7446d846cafeecd9c7b87a2a498f34eab8c.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/09ed10afa2f055aeec92a1413dab518b7600b96aff0a33d5583b8f30da6c93bb.png ../_images/4b100ef6840dc4b084ec3e86109c6ea92dcb071cd558370828c0d3cdedaabac7.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9fb346954b00344186aaafb2091604439b2a1b084de71ab05fafb9c8574282cc.png ../_images/8d8cf53a621d70aa0de33de266eb01e091d85940fdf176dc85e215ecf25f7923.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3f2cf3c1c771958429ecc118a9b470968b336ff7388a51ff908837fd04c5bb3f.png ../_images/887065a4d08526d118b79a0894b0949d4b26eaacc0bcb5e5ad3e6bedbe2bebab.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6560a2ccc0b7774b8a764c4bc11cbe4eb49005d4cb58afea707d2dcf08bb7d1e.png ../_images/4b43ed20d0c882abb579c774544eccda2ceef17161822229924768ad1fdc17a2.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8cfa29bb56daeda5ffa364865dd19730ee32993397650a690c40a0382eaba7d0.png ../_images/4b4486d3e68c8ea62b4861b499fbf2c56d791d77473706881a4f1181a87bd9ee.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/36d78af5a0b1aae4083b07a159d0a26a107aa70cb12f161f5f1dad023a6daf45.png ../_images/2c707b833d51a082f4e96d14ec932823015b682a89d2008f254110e0416e8b7a.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4ec8db0091145688b0308f9e4cdd4a2207afd8a1aaaced15de5946abe19d9dae.png ../_images/e1e1dfc047c6674333f7462fedb26262a65507b16b7c48e373ade1ea2c4503d4.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/62715775b116cced58b8ea88aa9e83b3372f70dcd50b709ae449438fab06454d.png ../_images/b018752a186a4a0eb69ad828456a1f3d55c7eb572b8090e429ad055207656e36.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/515615b9cbebd73b45423200497c76e2615deb46c30fc75872ab2c10be2ce0d0.png ../_images/3d894d33ec4d06743473e797692bf7e93b8edbf793d9be0065e0cf002d58a40a.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/76875f04b68c1a8bc6e930ce37f757e5adeaf0c1c68f5a33bc67cfe7206497a9.png ../_images/fabacf3073cac32dc117aa6387cb05badb2dbd0557f8c478fc47db012ef1e54d.png