# 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/6d7d8fc0d8379dc9329256f5aa1e8b6ac3538a262d6df31f7e7b210b75ebae56.png ../_images/5ec9ae5a78d0bfbbf5b228e86cf870fbe84234eab11bbc8dbf2cacac25f641b2.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/96391951d8fc101d1c3c28d1bff41dd3f357493d7e3c36319fd332ddcf0605f2.png ../_images/84495c3b518a92c729478b4b2ba0ba98bbbaddfc022daf0fa82e4253a71fbfd3.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0a8d42405d660f408178d8ad021cad2eddeca7bca2b18595b96e4b72e2b95a47.png ../_images/c4c4f807b6ca4f3fd14595d4eb053b903f9afd46aaff85e1401e39a1008e1b43.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/13a1d513f18a46bc9fc6ef8097c7c8cea9a759814e477f76f888fe960dc7ec8d.png ../_images/da81a0b3d4a28a6a9fe32c94481d3b7661feda53820d1c3f3b23adb4915a867c.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/885db833a35d19bd289d1f76261adc619ca8f9db0aad4ef0a2c46a9f2181cfd4.png ../_images/06e65795d81873c12ed3572cd743d61434b4a2183ab18c97dddfef6b910f208c.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7ddd970f25981ea8063b33f5e8249d2b8207e676e9499c673e709214d725bca6.png ../_images/2888b03b292db6328204cef7a9d6bc5a16f8bf0293dd8633a5635b09be80bbda.png

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c284ca108464b1e5011d485cd790ef7f5d58258977b3f89544b4608e3635aabe.png ../_images/7cced87ceab429f68fc3feace5761bc89eb1774143190df2eb0eb55b814fa47d.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/871299269e2efc37faada4e2df0cbe7e435a9d0b4df957fc93597ea83f3c50b7.png ../_images/8effd81ab252496e5f493960fe2793d272eca54b3fb4770bea1ec23e0ab7fe70.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ca28cb8eb7499be4deb572a437aa2cec6b48382574d3e5c63874e988bffe074b.png ../_images/dfc28a67a86410a9fa5969398e4f77b76c03107e38230176faf98dc37a668a79.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5c91ca2045eb33a9b20e4dca2273250f87aaef0bbf9ad83555fd5f54bc90d4f2.png ../_images/67e417d652e95e9d08665fc2fd9144db344b351bbca0b4bae274fff353a284bb.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/323a4aa12be92c0435f3996fb2253d4ffab6b26296dbf3090fd8b5c80b5a965b.png ../_images/07399b1949921fc80d684bdad26d168978e8bb45c8f0fa63e6276751c0fb9538.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a3f4dc2606781eef549ecbcd564785ed6f4c111218fa82b09f99c4f1504aaef9.png ../_images/3155282af2ebf9fa83aee7b216b3faf33094b03eba9761f4ec3c060766c21981.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/75faae75b708ffb9d992a858de49b4f7c62f9cdb84d5c130fef62bd280c38eb9.png ../_images/a1ef8ba9ba762a21acc5e22a4ed24cb8f60f7455fc4d84f6f46e7fab7d7a670c.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/35024e415b7205c387c5ce139e8c63c5c5edda29eef07ff86c8d803d61b13e4d.png ../_images/f81d3375ed9778b83dcd838602f6b5123f3936432d31275af1145ab5f6a51ff1.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/16769e1926ea385b7623318ece01dc49370606440cfcc036e74a82b7920ef769.png ../_images/b4d66706998a026fa26ed2e24ab94bb216f8a21f809e8c9851b2455bd7f56fd5.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bfac012a46771bb5d8534d43f2f7a80e7cdcc1b51879c9eb8c9264aa4a2669ff.png ../_images/088d057ec2581f1a2eb5d12ee709d1fe320832c874172f22721476ba493cfc71.png