# 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/982fe8feaae024f926e05349c57e338f8456a42cc4d4dad4e509ca0fe650289f.png ../_images/b1cb960210f789391b35dba544c8efe6ca3e440f4d5476a57929279b190700f7.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/519a566462ae2135b64738f75b50781e42b72ba78f0c7b758b76447e11844efe.png ../_images/f078581e359c0610be1cbf6d0d1088bc9f68f412cdd85a2d92c1bba0d11a32f1.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4b825669fdbaf331e8b90299bc45823c06fd035906660d40806e5952fe2cd357.png ../_images/7cf354fa5dd33b37166d0cc496b898f8487de21e8c3a8523be4d35cdbd1a6130.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1ce3e377bb247d56b7c5178d461880f784ac3d4d725034797b2441401d176552.png ../_images/0995e7e138ff099237c894c4796e380e944608c3a888afae49e7917f880b5c8e.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/53ee2f7c7a9af21a34f35240409a8b6903460b7987857e428a7871d040274ce8.png ../_images/b91bbcb5893e159c9f0a7f0e5000528dfed8b9dd43efb24f3faeb6dc517e9921.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e19976ad02ed114362e027821cfd169984b5c58793026b6dff40259ad27bd040.png ../_images/59066ea75e9ac9fb4d4b1509e1ea6c43f95274bd6e99163bb0a0c4ee6ad0aeea.png

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/20fec4cae79bc2240eeb5dea6c58b61e6a1fe9a89edfb0351420daf70f532192.png ../_images/33e4e54cab3a3b876ddeca445027a45c992d6cd00e1e6bbf94fafcdb870d797c.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/62b9c0526c4a393e76d9344bd76ddaf7f73d386ac6f97c69e9aea93d9ed6223e.png ../_images/c12c4af956174301da3b2bef2259677199d640e35ee99c09394e6dc20d8da766.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c42a79a79d1bd2afa4b12d8b4236c2cb496a5e7d635a3dd0b4a876496e4da827.png ../_images/a3fcf2c055901acd654564aadc44aa61549c0d866760ac2358aa29c67cae783a.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9fb6f57d0397587e1f2732c74dca188bc18b89fca0cbc8cd00e1f295cd947546.png ../_images/b73d791c985d75f47160a19a5fa866d4adc4d015281d68bcf3e9352792675739.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ee31a5ed9f086b73c8a117354219479cd4a23bb736b2943615351d4e83013082.png ../_images/ee22c217d5acd5898586d05eeebc9b027954e1902133ce32096b3e1999fe4a3a.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/019e128809b722a4d92ba2848f2e090cb2ac9a03e5977a310d654279b693477e.png ../_images/bd85b3e39a5741c2fabe8cdc17dff8960ccac31658c0778caf583ad786ff19a5.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fa82be6821c42e57514046f8723c85cfd2287f3accc198634a571b2ce5a19cfc.png ../_images/3cc096b550fcdae8a1ea192d23e8548df82b956ee1d7a57a3c185ec398eeb5d9.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5f0f58d89d9941f8e45d1718892598826b94235364b010dbcb7103dcd5be1e30.png ../_images/1ddec534391bbba0276ef49f34fc64830574df3c050dafefd7442a93d7c45e91.png

EGreenlandIceland#

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

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/df8c13621a0295f54346f963f14e19757af41e84035ca4a5d0c3283bf1bda1c4.png ../_images/3449189a273469bfa885ed9deb1126210681de7433c09c880bf463b460163c35.png