# Parameters
variable = "Heat_PmE"
long_name = "Heat flux into ocean from mass flux into ocean"

Heat_PmE#

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_PmE 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))
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.
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/8d117042077d2690759d7b58e1176795c6f8bad921b0ad1896f13b23d76c48b6.png ../_images/c83dc00802a29c74df0b16db077c10393e0b6e7b1ea3cc6085c409f13cfab33e.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/12c10f8f69850925f42c8db568478232afde7d7dcb45bb5b406866765f7c04d4.png ../_images/b940a039786f3ccf5fe65490c5c0c3837c9a5595ba0619d898ab55eabcab9a4f.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/197d412b65cfab498bfb5b3842eab725a7495d0213f79558f90677769974af66.png ../_images/a0d5f041d7c8a774d66c2a4765aa41e6e3ce231fddfe17c094dac8a448847538.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2eca1d0bdb0c93121d9aa940bb88452aef1f689d9882776f00a00e7988baf275.png ../_images/3fa5730733b021ca9301479a6bd9d3d2331d974fd02d0dda56b60f7bed77b9ab.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1757f0064ef0f38d855e7a9a17d4f7d62d50ec448cbb9673486dde7cae435132.png ../_images/83a1d1285f4e38944c3323ee8f87c8fbb2a928694f98097db3bac640d176e952.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5e5c1371b62eb65923dd146b0337a2baafe69195216690b9a3e90173bc5b48cb.png ../_images/6d87ad51a95c898d1e5d1c5e71c746b6c15a7b08ae2a92459ab3f524c37fb632.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8d15cfa9c09705ca4044b32e8d93f4b110b975ea9b474faa815916cce64b58e1.png ../_images/4c99a4a971b2c6e904c6d248ff24ac85e7c87f48d0d1bdfcf9cec29f06644186.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/956d2596bd93c283b8c7216b91a3ff3b8eb226c043b84a379a71fe2d1440bd96.png ../_images/675d27c11569e7aecd3f7160e51b06e9498d646b04796eec2deffc732c71c0db.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/85125bba223c67479406a3efa07c0f0755b517f622a8c0024d0113d69ef0f0e0.png ../_images/8953483fef875034acc79a062279c2127acf4ab420ee7b7607992ac83f706ae4.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4270d29661709a90b4c1e02f646549bf18bb4cf89b6f0c566e94ab32db8588c9.png ../_images/ec1178fa5a4d39a1d0106167daf671c3d85fd3c71ab39c5f3d4c278b8e6cb5b9.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7182c0dc3bab9ea250599288730430bcfd0ce09356eca11a4f16ff1ca225ef82.png ../_images/044fdfefaf233ef91f7f1aa5b0cefe86a42a30b2dbcdac64872dafe679a11c26.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/57db7564e00b88123b533b6aa3bc9a9276fc20835e011ad916b95e3a4cc490f7.png ../_images/2c93b08a44fcac257b7411140bf4da49afc759c7b0e3e292bff89f0a0f9908a7.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/784867c05d2233868c4b41a5bd1e357bccd98a67c50ed83fd9b2473fcfe493c5.png ../_images/f3c17d5ad8feec843052a0dc2a369785e8b53af6f07412fc67dfef9aef869d23.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f9d519534d3cf2334953579e0272b80695a439fc1e4cb9c3f858cf3a97ab5d28.png ../_images/a02fa983adc94499db8a513f9ba2415f3d2520e9d0bb1d0556962b57f5aed446.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3de45bae5846c023bc446966dcb58698855d017c5f08356a25bb0c6ad08fc614.png ../_images/69045a9b36845a6bb456866ba51f13ad80c4254a797d391e8af025e3742bfa25.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/543d8f11417871dd81f97ee0538275e4bf25f1bd52544dcdff02f7e8dc31b67c.png ../_images/82bc7b40afdaa22df59ac0024d0df67765bcb3921f52fb86867f8615471f8770.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/43c833a1ec69d354e164efbd2871ba6749edc555853d76647c6ca9e98db91423.png ../_images/de529d3a93b9d678c956db1ec76b9dbab3439f59de8ffe06910a6507c301b5b1.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/886a1963a530ebc07c638ea23d65642015145b702ea9211789cbc44ec2d07335.png ../_images/4a3832fe9c9298b31bc57a27b6873a4009c935320551bc561ee840983505c158.png