# 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))
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/77d9575ab15213d008dcd0fcb2b0680df5f46e48ac264f50f26b02f365e7761b.png ../_images/40cb723dfb3f5a18c15c360216a8e32fba7eb116a6eac41a8215cd18f94ba0bc.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1a5c48fa60115f93b3cdb8e82f0cede5a9185fd31b2b189f0afad95ef381111f.png ../_images/22804d473944dadef99002dad2093751f2e8222dcc59f010541b585ba57f7a11.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5ebfad1a112a6721eb5afae21eec78478c69610bdf8cc1f04e2852e80eaea74f.png ../_images/8da8d034e75328d389cb0dc84177e064c866c141a3f115bf41186fb9e012852c.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/18f4af9a88ace5c6769b453280f09e79c6fa4cdf43c141c0b2842ce0422c715e.png ../_images/dc320413ee4a35a74b045e771f0316f7faf5b8fce053e01966418cac5d34d2bd.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2ad875cbd9d77baddda5120041c158a7e9c65927ee56d1ab3d48344346a73d24.png ../_images/554cbe55f3dc0e0a0cc459c886f6e777df994242489974d241665e6566d1b434.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/89924e200a5b2eee8443536edb11a8eb175db0f38a30150749a07c4f27d119ae.png ../_images/91c0adc4435bc2ad11021f25546929bdac84abfe782526ddafcc00ed087463fb.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2363c60173e52c6910f477d92590cb3e8849201ddac14a9c6b6f28e733be96fe.png ../_images/767581851bfd61e9814e4056d3a4aa9477fe3155aa47510f9d4d34cc3f56e179.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9340f8cf987ac8abc367796d90b474a6af85f6a1593553bddce35dfdc995e6b8.png ../_images/7c06cc42d1b3857eef54618fcc578d8ae548982f2af07697c7afcb835252acc2.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9e07d83e49c259aa3186a9ad065dff5d0d202d92b5b15004cc74ee521113b202.png ../_images/5a442bdf113d9bfa4f43fa82875cacb8e51fd86e1a1febdea20bef4e44b3b0f3.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d66ba724ab171a8d8faf00b4ee80fe58abbeb37d33ada517f316493e615ea685.png ../_images/9d58b4bf1de9e4b0cee81ca0fd50bdd34db0ae8ecf21b5181d0b82abdc7cfeb4.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0306743bf78e455b9181e163ade5fb118c745be54cd6a4d3deef58e28aa8d504.png ../_images/4f40fdf929566a278d3b411d694e7ac5954c5e6077fdd5516fb09b12ce77a35c.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/82a7f408a5613c23ecf8926e680404b302c9743023c575974dbddde6b119c553.png ../_images/b26ac62976f1ce6ef2f802a556551428d7508583669ef3855becb8aa111945a3.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a33b90b104ab603c853d5ba60eed2a15f414bf6bffb585beec29862caa82171f.png ../_images/3e0a4802dfb6c5579548559dfae5c0a93a1b66372fc8dd0982169fae24477e29.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ca28de21b5177d8880606c97be72f30bc10d91542bb46933b5112d9bc242711c.png ../_images/63dd6c03b977bba16f5fdc4d07aef19ef1ddf9ee300eacbbcd1fb0d2c7bf2fad.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/758f9d36543d049ea9dfb63a6c3bf864bd180a4451d8093f1ebdd6da8340b111.png ../_images/5fa6ef3723ea07d6015ff06f023606445f5f80ec90a632548069b3dbc97a409e.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/628e689590565f14fc506cd9fd66d6c2b79ab1b8435ea121aecb127a21f547c8.png ../_images/48a467cf8f4b10bb45a3e5730d97cfa8280b8a03d577ca759523b31b6106de04.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c6b205eb60fc5a4dd97b875e9b0a40b823419d3e99d9169776391924a13555ef.png ../_images/9cfd5f0895fcf96501adb9b0fa6d4844aeec6cb8f976765fa78e7acbb3fbc5e2.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f6e4e7558b1a5fddfe7612d81fb228adb31a8640d0c9d922a2c88f2dab401576.png ../_images/4911fbe113e7ce1f3b109584860d356b11914edb23a9a22b4fda9d4ffae6d068.png