# 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/5e84a66ca79ed4a3cd6f2e2d9d432b2733aa36f93e024864295f6d776395f096.png ../_images/8db1e0fefb3050c9750f41187172bf3cfb9c559d2a5b4f6019c52ec4869162b4.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/369476eb1c980243d054942d5354cb6f80d1f8fef73d83d68914470e0b6260eb.png ../_images/50921fd2ed59c6777d6e6ad98db575e72afccbb50f4f19bf3f0606950d631fcf.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/19bedd03082cedc9eafb57a471475cb1aa4a605109ea70bf2a81beb7cbfadd57.png ../_images/72e02f7fd0103ced073084852a3c6e8dfd33c1ea92e4107d31721690db54de09.png

BlackSea#

reg = 'BlackSea'
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/acb4b29e8c16a9529369d6c17b2c914e93dcbf42b3bf511fc06648f8e9d32788.png ../_images/b68d59b7459a21d78982b57a361d01cc7a490bf8eefb30bc4a3eb5794db1ab62.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7f760733844130ca8db3994cbba31c15a37f904e7332faec33210cee1cc53b9b.png ../_images/9ba70c7397239c6a7905e80ab1fb3fdf46c0e495444ff5e8dff3c08d6bf4a727.png

BalticSea#

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

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/967f025ebabb9c3141a0e2fb1860443279069a3d4ec51a9176671a77fb701e76.png ../_images/6e005d29b8487fb031d2f191ad48d92a24eb1a968314d8527a78e09f954af612.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3f8c2d248100c53e1bfcc679145ced9ff0acb01137fc00cf20ab12466c10fa11.png ../_images/e5de43e72c2090f98a9f5c122351b04511a889555e561d8472a971565b9c76ca.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2f2d9987c772641dfbf08c480e23aac1099e29dc3f61725aeab3eea2d2cc999c.png ../_images/320c4452d1ec8537ac886b41b57ff09df75c865e4eb140d03dc55ae5e7ca1f5c.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/928677407126524e9355b7e44994f5f01f81a2e9183ff489dbcc6dab39ddbbc2.png ../_images/897fc4b24610fedf0376cd0df42a49292efd555f16b4e9587f4ec2361f5a34a7.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b67c5353ff3d0a01d8bdadb41e880f84471013eb9ce74cc4762cf08d61427ad5.png ../_images/18da069ca19fbb14672fbaf1a334192d0a11103dd4a4109432c72211b4e6be22.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/773375e849e86fa64767f173763b2106de027bcc71f73a287d91d14bcaf7f9b7.png ../_images/3baabc7f4d944c92623bfe32a322a2accf4fe6d4db7cb9dccd8aad98d8b6811b.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/364a20b74617d265f44ed7c8861c239601626132bea0053d54cb837470e9c0be.png ../_images/868bfa3ccfc73ba8a846fb714a0a158209e74d534d4ed0e028d3bc9bb02146b9.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c3e495a6e258e83abebacf3149dccaaa1a212e367630e1fe51bbe541a3c37817.png ../_images/90b08953f9b15209fbeb043b8c30de16ded27065b17338c16d74d1ee240d2eea.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/587e887d7690777464ebd091fc2f02956dcd6034a7acf5bb1eab04db0218ac9c.png ../_images/ee3a7cb22145d72442570f3a8f63fe3cd07e3427e76eff6f7fa31860af436e27.png

EGreenlandIceland#

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

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/76b83f88eb06e38b44b1080dd722d18f9ae8ba5c81190907f94532a25b8d6b05.png ../_images/2e95b2fa8c9bd91b9e777bbb4e0e4e63be7baad862fed5edb6cd1d1fee3738d9.png