# Parameters
variable = "seaice_melt_heat"
long_name = "Heat flux into ocean due to snow and sea ice melt/freeze"

seaice_melt_heat#

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 seaice_melt_heat 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/a1edbcc28c599fe711b95479c85162a7fb81408583ff7fde3ca2248eb17f5100.png ../_images/638fc7da6836cc5cee11be471318a6748dc95292ee8cb929916132c4077cc115.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/30887fe1432ff334ab592e4257cd117626e49a2508f37f66d648533fa7bc3c49.png ../_images/2317499a9faef44876f26598475a98e8c5c613196ed1be88e53d58b7eab0962f.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a9b0bd966a08a30bff1a5e7092bd0cef9a3a2c544f4bf2f49277cdc4330c31f.png ../_images/0a3ca2f2b3fb015a5ecbd5324585b78761ef05ff97bfb9942fee232de02fc534.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ed23770d6d02206e631f9e91933fb8428fe4b3c2182cfcf9474672ef4466d405.png ../_images/be2ea865401a9a37d361ca5ab8298bdebec9a6423a91beeb239288e4a6a3ca81.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/18ca357248e116d5801aff398f88bfd3c21f5062325fd112da7964d0bb75f0d4.png ../_images/747c8328a6ddd13b3dab8fe452b14bd02b17de7e461f803ceea98021cb84fa61.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8f560be9ea79ba4946348e3cecad0a66c4018d3ee88d5a80265e189b7c85fe77.png ../_images/34a78ee2029047a0f4091ec30a0640adb5f6ec13dc4e25597811e476b3c93dc8.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a211e3dc4dcf44a0718f86d3a4afd1bee420c4c7808735d182e151affb4de5b7.png ../_images/3bce65f8a23654f8d1ec91d2a00f53b989aa86d236719f743f9073198cc90d0a.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/982adca0a38b1c87ecaea71c2df5e84335a212f6a0a9b3cb6b70f0d7302c8d0c.png ../_images/596641244adce0aacfde4f9ec5238c7fcce2d83fc2a0e62803fb9a232e45c332.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/79b77dbbeeed4b8d7fad6b9638984c44c0b4faf24331bc23c302d839289947c4.png ../_images/29381d17ee32255da056acda27411557fdcb2c44cf3f9495b3500ec0984540a0.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/03850e57b112e54877ed24df8b91f6030037f727304cfbcebc36e42629cc3635.png ../_images/09def8ada81003562895e2f79cfd32fcc8d668fff47952ef0f37c986027c579a.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3b551791fc41be24fa81b3d6b10bb18454a0dff6b4c1d79b05ac574924480afb.png ../_images/2a22fa1c5add156eda5f9f8a3d6d132f18a471ce1066c9f5030c985615165605.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/73412174ad458be4712a6f744c5d8ce7487270efdeca337c4e8316160466555a.png ../_images/eced60d186a8ab760adc809d98b2148d70d92495d07bb32bb3ca6ccbb5554ed6.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/35cf36a02b32cd6ff3a4b300560eaa6aa97199c15bec2310357fc11a1b73248c.png ../_images/b83fda66d070697a90270b64650aedf2b591fbf8255703e83cb027a366554a35.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d352d4d30aa34f6378f40fc8201ad6fafbc6f88dccf3d3fc62fe70caf2d9f6e8.png ../_images/7daf6a11634d7c26b579a2afe1cc01aedffe9f29b362bb5f991ab63c02fc69d6.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0357d6fce70e7530e612ea2c11a908b34be15db58f4bb20e95114659f25fd2ab.png ../_images/9d31a9cde32248e4b37858be928ed223b7199ed7a8230eeb43e3de2a0d9f48b3.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2f3a99befd4621f199179dd2c59b7da3262bde0c5b34eee0c14cf6641b6b51dd.png ../_images/e0f711bc6b53607d4ad13451bc765ba9a4f670fa159fb61a4c82d61d4b27cb2d.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0c5d543a0d6169f3b29e3f687e7be0a9ac8caf812195761767120bcd674fb7b2.png ../_images/d56f197bd1ea8e87bafe81341a8fd83691bde473beaac68799d47aa98a5f9c36.png

GulfOfMexico#

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