# 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))
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/fbb2cd9773818d1416db6da2ffd34c400f5bcf283d270eef7b49ba581c2c23ba.png ../_images/f4bca9a176febae123f0d48d105c346504922b3ee0b380bc62143fe33305e40f.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/116c08e50dfe1d1ed3034ed5461e844e784980bd2d1a79cc60142d416c86c4c2.png ../_images/58a82e458f4b4396f96f1b3d73eab9baf738aec3d7ce8cc1f501f3988995e014.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/32eb3c3e941ede3b1ef8bffb684dbe9122bea0003c3a011c08b8b626a2224fc4.png ../_images/8e02ddda520e8e8bfa1a72f173878c09e212a135568e706fdad5877a66984757.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a10ae6ef102475f693017f2b3a93b35af947558c1e4773e3f31cd274e1615bb7.png ../_images/598e16c4cb9c5a28ce5a75dbf57e450ad62e899b4d2408f4b11bcd0e94dc4607.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/de61448fc366e1de3f05f4abe2b06cb1d543e47e97aa239b1f4f747bef6d7274.png ../_images/bb40fd780f9889b04526deb9ab74ccf2de3c268fe30527d9b1774da97b1d6f74.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1158eedbededf2c5088cc362585df8df1f12d6449b88b41d40d19a13efe6e592.png ../_images/04e82711a0a0faa03803f4909fbec8eb19e6d0a9795e1ddffe3ce6f91ce84eee.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cc992a9232992004b13a5b75c3a192b234e1936f915f4e39af2ab340a1857686.png ../_images/fce6add79117788fcc3b9b3dd7bf643cf4e4193191c8437c0d868988522c2ba4.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/905740fb47d79d12e0885f83da36a920edd0c1341bc5cee8229750108c84b9b0.png ../_images/791d3a87d63ac9e59218534b3db134724fa631efa485c8227b26755445e8d92b.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1a75718963248332bf4f009d68bc0ec07afa6f3d5357e5982d9dc2e6e9e4068d.png ../_images/c4c06cc01a85e834f0ba2b9fe40f18bd10b3cdcf4168d10cd0b6245e69248d0a.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/81db18a38abb90566e242fe1acfd7fb413cc63f14f3d0b31d5d5598844ee1b59.png ../_images/2b6e2c80b451379f19533af797e184228db4b27f0f0afd0d8ad0d89a456bc112.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0549db2098ef76457328b78f8226cf6ea90179dac436f840258dd5d32bace4cc.png ../_images/d4d2b5d7f6d7b660eb3d2e7d87e53afa245e922c543f082b523ea4fbff345628.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/739807ba5ea6d60867725f49eecd524e25561a8c720e1f11d23998d211aa0f38.png ../_images/51e12e49786ade01e09d8fc3209317ffd975f89d53e72c36b31f2f93b941d537.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3c2a9e93f960525dbc452a9ac48989f3048f9c9dbdfdd76f56e448feb4049528.png ../_images/164f11defe2447c3ff5afe902460b8963f335e450493c6485a68155d31dd5c3f.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/384d45e1d414d350f2f5ea487b28f7a0e9c87a3d7ef29d18476d28f15ccef232.png ../_images/cba845ab01443cedddc149d93227730da48f7fb48f53d7361e6040036cc6c752.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/03b12ef10a5ace0aace57585f4832d54038afa9680b27f9aacb3492f63638537.png ../_images/d85b7bb41b19ca63e0288992892b40438c0aeed02644c30f70d93b40a4e01d81.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b12332ace272b7b8612abb7d5bed6bc7e6396944e59289b0b2c014d8fbc1298f.png ../_images/ac0b0c90065188a78a08f5c3922743ec36ea6bfea1473100455d8c62642056c6.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a04e81c413820befe4210500ad2b2e34f290155871845ce293f6988b57f62ef6.png ../_images/3ca26e8e65fb17051e06122fcea6d99516059033dc987f298070c279a6ca5540.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/618bd0154b27f33d83138d8f76365f93b030dc498cc50cce382e58c25640f8d3.png ../_images/ecf04fdd87b47bd84f5c1738805d47e18191c64af8e5336d7fbbace7392f72ed.png