# 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/4cfe7902caac6138fafc2eecf3ee11e1bb8a3cf3b016e903e44d69dec9ad1fd7.png ../_images/9451a4423b0579353b5fd15ade4000c0437145913fe8909a84c8454cbd35675d.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e1cce1ee8784903964a5c89d9279ce63e2f01deda1d628582ecad17ac7c0d053.png ../_images/a71610adea6024ea6b3a81a7bcc5231fc824c18439962dbaa487136a0b166acd.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5427cf03f054e24cb4b2004e8205ebb62fa599e9d8d63989df2378faef5f1129.png ../_images/d07541fab54ae1bbbb7bc12d0f56f779747f928f7aad748240adb524343b94ff.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7c4a94c5f364fb1903a9bed57dd78be705e0eb5e319c2750545f25aad4534ce6.png ../_images/dd0e64b605d06c0ae00f1e150f0cc06c52f50e2918709249c857b4c3c4143af6.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/703d6526f2dd8a725eaa13885e6a7dcc180b2f2de7e74527e36f3caa1e7350b2.png ../_images/06480430199b16f2cf8e0ce09a772d9aac46d0d302f1aad7389df2a646d84eda.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f1289ba814f70ffe7ed20f7cea77c2e060f4ba53c1a21c40dd21b7973a7ed465.png ../_images/189dba7b024d33b10a1eeaff91e5e113045f693b9fe56d3953a2c293443a2e6b.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/aaf5d7ecd7dbe0735429760a8cc9afc7cc5462378fa2ca6254033002de3498cd.png ../_images/7233e2b028e2dacb694a8d335c8a9427c99b471faf02f425b0fc7507fa63b43e.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f904f654dd33097c4614c7e7f2b1759bce057bf03a359940c49e57ac869140dd.png ../_images/9d2c1e7a7f2fe6fc205d66afb84bb56ba87d2b127edb12ab1e4afdb7d6fee83e.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eef9868b639aa2a75f6e0deabaa99af8f100f8960551f79018b2efc41150770c.png ../_images/d46cae07ea9142b46a4edc9a78dade3306647e933ad7d6bcf3a3d8fa12982863.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5adcdcc9316d1a65afdea5072fb9a9d0c3687c55a7083786b2ac0b69bd13db6f.png ../_images/d04795e39ad101fdbc97fd7890ecafd6a2e3bd282a3a6925acfd7d33b3a22e71.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9435a151368f70d9ccae9529bd8428ff5ad1e4f9a3c3787b253722b94a648745.png ../_images/3d6a1762353f4eb624b6ece8d2827e886afbaeaba0fa4d43744956bd588172f6.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/28c0bc6d5ae782de2912e8fff31f5c5347ed23bff4c1707f886e192daaf8d3c5.png ../_images/432700f9418cddeb2e97fa9f2caeb67a38cdb6f8aa188f5fae811de4cc6a8267.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fbdc929c0edea15907e887e626316547ac5b3f291a130deea2ba8c4adaa9ba94.png ../_images/74fe712c3acd803a2465073e6ee6b83915d2c4ccc75151b794a5bfd1abdf373c.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/23c2df4083f7e851ecb4a52e09c7cfae4b49665288056eac7f47fcc63770a1e0.png ../_images/1b9176c716452b7bc02878f97b699d4b73d64540bdbcfe40d62e431cc9277c26.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c3fe6dcf3e700414cf88d3be713b1eca33d7e0cb37bb3724cf545a10f830214c.png ../_images/4bbe309e9e0e2c9a9107c1754270c2fc8d1a2c17f002c907eb6a9ba562fb88d9.png

EGreenlandIceland#

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

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3e9970f5430923a365ceee2376f66d8f479161382b6fe96f367b533cf5884c85.png ../_images/1956bfd29038f69dec71ef6f7a3bc4abd7f19b4adfc3ce48f78ddbdd9756256b.png