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

heat_content_vprec#

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_vprec 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/9e0a9386e4f7c61d84b1e43413a277016a0b579ef89c492801166726b5343f7f.png ../_images/fac13928426aa1e16cecc630fae145afec92fb1c7d89f9f298988b7d788c398f.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1d20058a6d6581eae9abe168a9ae5a2888c7c65cc1b1d2df29e37964b50cd9e3.png ../_images/42c9fde60235f206fcae7414eb884d0e8faffdb5b79bf66069321b685c9ac4da.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/063de8bf9d4470592edff6e5d276c510104fc797cc6fd7ab7e0b962d0a69f6b7.png ../_images/f2ef09c5e37a72ab9f6775755f0469e149b74c02f3be1222d7f28b8c76272c47.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c609fc09d34c193c1c50e11842909a02540ac652c828a87f7ffb6dcb4aba80a0.png ../_images/814375f01cdb5b85395f98759d12d37def027fe766ca7ac26b5c7707cc789879.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0f3c6e5714075363ccd3dad5a7943089d13bed73c95c663021c530b298580beb.png ../_images/e8012546f427aaf26c5886aa815324c5352391bc45b22b4322593a5af800c7bb.png

BalticSea#

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

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/55472cc22b3246310304dcdc210dfcc0ac75c7d89b3719cc077d086267c5b21f.png ../_images/dc9a5c1d500c3e590826d5c7d9571819a6f62b5b582cd8b40cf4f7d30172badd.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/054c6d948afc75060097e11dbad68f8d75fa51b6f2484c0522fb09d74f0f63c8.png ../_images/c6a2f3038fbfc8aab0722d628be1621a2150a8f09bba26aca8da19797148e47d.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dab10ae87dd22d92fd05db8fe412f8ae727076c4b23bfe57f725f0116ca012cf.png ../_images/3e755cc826253b7c8be5854270f6b4a5942b9fbc9a3dc903fb43cfc415f898d7.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6961700e86bdbdcd7aeabc04e9fd3dc1ba1666b958ca4ad675ece94aeba689d0.png ../_images/e9260c70b5f2da282a1fe0db8a5a0d870c21242840bd4ba5da2fe680c7ffabaa.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/666d2c63637d67659d776f6b5d7bce4cd1774a6fd3fbefb52f78aafe5f901ee6.png ../_images/7557cc77149b1bebfbf303a4fb718b944c5ce7abd8f484b8ded24fbace80f123.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2522c0d305a9f87322432c7a281be23f745c8b8b1bf7e0108854935d96c5f388.png ../_images/87006a42b7876682dce02cf1936df1b74c4f14e122d4fc7de2fadbff352c7c2f.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/823956d8778abc699242a6ad095e972f1087de2d4fe1fc4564fa9f243be49a5f.png ../_images/9e2c2556863e8e546f22cf4b84ff1778d8fe78bcc5adf689690ba42f911dedab.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d2a205f4a2c636c2f0bbde3eb06f2cd0ca4ed930794d073d13b3e4254544ca63.png ../_images/58799b0e95a0d4fa196ef84ab892997ef98441955fd3896b71f7dee1abce82a9.png

Maritime#

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

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/055c1d23b98e1512db08795efabbacf13b59c6d6fe7c02e2247284a0a0d4e713.png ../_images/5d5b1ad119f4fab61b3bd75a9a40eaef7ffb6e9c7f0fcda3a96685af48228b02.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d6450b5939d723000fb82dae553c9e6fb85483df6892404334b42a54e052b7f2.png ../_images/fa6008b0470fc2a87cc2683292de846e780889746f41cebbb2b7055d59c60efc.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7e50a361e49cbed43a46d03fdfca5986d5f69d1e627f41ead548ee6a92e97ec8.png ../_images/2f0bff4e37e7422f90497f6f18f06b8d3496a88cb7944f1316e38daf56960903.png