heat_content_vprec#

# Parameters
variable = "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
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)
    
    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)

        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/6ab987dba6ffcd9f1c7cb08f0a393f3c89b8244a63deec961747d95dafd5fdf9.png _images/6fa85c36d36cf76b763be63c1413a8665d3d8c3c67e6967fc1a9462f338cdfe0.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/a2313aac8700fca5ad848cb9795b53ef49fe38c6909b9ba79e0d112147ea0b14.png _images/6f1a05665064066b8efdc3e56ce1998d308cabce286c6eed12b3be3b4a963095.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/34e7b75c950bffe4d28f280a7bc13b5f6cb1c0399ad49bddf5f1796cfecaa82d.png _images/92f3617440bbf0be67b19ecb3b4fdfdcc2e03784cffa9967aa2aeedb36cecc1e.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/5a42571017386bdf9b209ca9ee39f9a033dfa04571bda49aa5e2fe9f98886eca.png _images/7fe4288fdb8b5f6bf702f5367d39e6d1441bda8fe9d88bd0b76d79183f80ea42.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/2534f6c73a8eb47458633885718d64c72dd684581c6a803c289811ef4efa5833.png _images/ec96220798c8ca06a2312e95817aefaf34d17f0d351c2104056246d782a46339.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/1ed01c23c77ea0486364497a9fbad68a2d5738698eea31beefc87fd501205da2.png _images/8b8bfee3c8eeab20d5184f91b671884cbb357bcfd1da6a2b34ed1902e9c0aeee.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/1cff63ee3614e3cff6295dabd3662d9173ec3aa4d21698033efe3c0803dcc804.png _images/3af7103e7b3f4f1a65454d9b5e2f51a3aaf1da641487fe1f4fa07d2e58e9bdb1.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/ff071910ef57369a7d24ddd591bca801a1a721dadd6d7862144df5876c01ce4b.png _images/2d23085cb89b459ba8d2d41d839b953b47ca6272bb2a75c1019b3e8e7e12983a.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/16453d09d8a2c5380a0feed359f0d20ff4348761b4219aa87b61d47491e7b936.png _images/da88e5a33ec276bd3853dd87d5e58ce75e8e8957c00ed5e8704f916be05c7c90.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/3372d2e1b6f5cc147f6283fdcd6e69f6ffaaedd886a0d5451742c1ea09b4498a.png _images/4139a8317eaff6d3670f8d4598dbfc5dce7d6b9dc45a462d38dbead8d1f81877.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/9e00a0f30399cf67725e0b50a25efe958575435b654c64c5649e40e2a6a0d602.png _images/b1222b0d54a97f79c817a7d6a4c929481dee4ae22c83cd093c4728d10865e6ee.png

SouthernOcean#

reg = 'SouthernOcean'
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/36e96da30553743d78e24cd445be618b59a0fb2f562b54d664e13a8c8c1b1b66.png _images/73c6b5cedf369d30aa5c910dc10ba15e39cbfe15d52a43cf0646a0c4c7bef930.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/6e34ca5671832f6e3c1c7dc2416c0fb50eb781a2c9d26072af84d6269b52254a.png _images/3f592c4d296b85fb27e291cf0087b5e4347e9ba9a44e4dfa281a2807175882cc.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d715c7e7baa1b004ab2cdfc30e4065a5274bc1de800eada8f1585f69eb0c748b.png _images/2aba58dd62e07f714e2643dd864687b12a08199f0fa87a62de8e060d8cfdd7de.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/6661b9acb9923d3895c4a5bcf6eb79200eff5d04104a1fa8d4ed063cba56a699.png _images/623f043ab3ca84b1da679fb24cabaf56d5af0d258f6b246e53f87eeaa9ef4c95.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/85c5a3f8e05d145fd8f7a80fff45bedd906815d79a91d7484508fff7f3b075a0.png _images/1606f3fbe730ab61e99afb216492a3d1607eedfe41c528e1ec15982903b600ec.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/90fefcc876627e1615b926e10466ec9de4615afedd6ffd193f5f21972ef62b49.png _images/a10806fcbc4262a415c2a19b13087fb6953da0e80c5e4b64d23e185470da5e0a.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/c361adde8edec3a56ee39e950d87cc7108eeb06d406837468aa93da5c7cff2e2.png _images/a128f378f94f1d3d77f22c3a0f3c965231ee2ebb782188f2eb153a85c2b765be.png