# Parameters
variable = "hflso"
long_name = "Surface Downward Latent Heat Flux due to Evap + Melt Snow/Ice"

hflso#

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 hflso 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/a491324c34c03e97b68d5b397214fa8349631b4ff25d7e98e02b3c4d7ad1348f.png ../_images/4dcb7e086a457d0f5be7a7bac200b08d49cb68f9edfd98c1718ee89e3d97890a.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5dd5355de22a9eba85f7b5c1f676b8aed7e23579d4fcc52295e615095d37245a.png ../_images/3a36c7318c36f42b4f141c05bb9a1b5ad7a12c5ebf678fb060c53b65c1f75842.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/44e890367e1a946dcb9365549cc3ccb8704074daa07c4ce475cd10e817ce2a53.png ../_images/5da42561c3a253432bd91489f6704547d21c36751116c7d8aea41f69916bcd79.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/46cf0f8879d37e7e8889ff74dbf3f05ec21977dbbf63908b5d63d4dffa3111dc.png ../_images/b7dce9300b90160be03e391a598e6413b6f17fc48d5c05fd9abe9042f8014c69.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/61b339f6977d24ee67f6b14b5cdd801d55e4ae427a0213f830dafe6a855f636b.png ../_images/7edec152b99165caeeb1a2ca3fe7828a223304c7643d5f18074cc4f0b8a85b53.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/62a9bb648b3612a3daec54864451650ca16cdc729413d507d4c2ec0425e6cd49.png ../_images/1a7921c78fb08e499050bc951d0e4d2ac671621636dfb29ba570205bd0052518.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7ab52b44535bbbb7531e1c6343d7c0d4e3739c5f85f0f44b80e7f2f7d30f064e.png ../_images/c0931596471cb823b9c6483ef7ca5829118bf334d58115384d6855a05158e669.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d63b7e86bf20f95d20bb05d459024178f78a99e1e30dbb059bca02a84f0a0038.png ../_images/16c756ba32401476c194d348389bfeec55806cba130c7e55d04fdb98f0178b76.png

PacificOcean#

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

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e89e4b8b9acd62d2bfbc78ebaa673aca682041a7e390a10779992b327759b881.png ../_images/de32872d13e20249461d6143a94128bd9aa264327f1fb63d18ee11252d000111.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8b8ae43578fcd8c16962c004775c6343b81578ca1903527f49e3e86b6423b719.png ../_images/46e89438994c61cbc4f74819f19847b13f02504ac3435ae32bbd27f65304219a.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e138817e2317934ed314bc519aad117c8931c8c3c52e04503c5950b879aac352.png ../_images/d3d0b444f792f81a0fb2c76cc5f278e2cca7d8d8b39608619240cd817afb1b67.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5e16a2d093acbd3c50424502cecc5565b866ec6a4505b6eaf8750f3ea78a8924.png ../_images/f666d146a43307e164f41ee406476a729b32e1b19ead1f6a0211c8e2550cfa45.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fe1d9cc1ed07cb7d3aab646ae423b2e8e09c1a99791550ee67a748912dc2468d.png ../_images/368a119fc3566369f6c65309a43d0a9afbc7596aa892e663253cd7b432208c33.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1a522253e32b8961d7f5d645dc5fbfb1b8973c516e5417bd3ac78f9d89c254bb.png ../_images/25fe7fa863712a0d05fe5d9ff1d7e6f596bef3cf9415c5f8d9e7575e0ea4f765.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1c51aaca9cd799546c641b43da89bb269e04cd4c9887db526760dc632bec6b62.png ../_images/0ed41ed11b7c957c1bbc6356c7fde9db11a922c6bfbf43f2d20ad7caa22fddca.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a7991b807152fe52eaa756b990f831a977df82fc00cf261b20e3b7ffa338fb5c.png ../_images/604d46c5c38ae60154f238b0e0fd0c4e708c7bc9d50df248fc0983dd262abe46.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/311a6c7acc133d7080274f1a2b67bb1fa6331177d7fee29746c613bd7860b14f.png ../_images/ce833bc0ea51285d4aa39da1faa5dd8f3d22cd300f17395f3e735f2c83e3d556.png