# 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))
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/cb9c8f8e04776ef4354a80fed32158fd6f2c665752f0086fe3345cdba1b85c74.png ../_images/b0daa7ab1a083a4fd95a55094a3f9c100e04b1578e40363d9cd8e363f4d3a82f.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a84b5a36c9c66129bd1e33bb1c70266df0a8a7701a735393eab60d5d7cc0896c.png ../_images/6b518ec64f4568b586a47dbde01549e282467e4987e5670b61e95f46c3e8580d.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c78af274979658d49231e732e7093b23801aa8340c39344ac31264301380f5f3.png ../_images/5960b991a53ffbc21d301fd3746282c27945831e5f67c156d140f8a110bde663.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/da37da87a06606a3ea6b3d6773144be99ba36f8417d62ea8613686524fb6040a.png ../_images/6d9a87d3ee996c6280b8ffea28d95e63928b7dfa33f5061713de8869063c0c13.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4d7edaa41de2b319e52ccdacdc3584f5e1de9190acf1ee32a66f6720c9350eae.png ../_images/11dab672cc5f6be138708b486ed09dd4018687f63cb32b989ce7c87ea98fafbc.png

BalticSea#

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

HudsonBay#

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

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fc554766ff4114e059e2e636e18631f9b9804225704219178836bd692a78f3ce.png ../_images/5dc84b5e1cea127a13c23066720e67296f86d2c766293d0975d891631fe91796.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/16d6d8b5836315ff3418e56b16cb699d05b71af56983e31ee978765930a9b4cf.png ../_images/9d86531a30fd8d9dd826a0e373f682cc97ab0d9270193c6fdb2bbb34aa4fa0cd.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f0db9cbee226c93120b79114d08bb179d395678ec7ba2ce3ebd6bbbde2e281a1.png ../_images/30e2e418f528daa7fa95c34b40d0a9a03393a82d9225033934e328846d772b5f.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/671094b377fe5cba022b9100d6681459c491d9ddc7769387b4677d8f41a38bdf.png ../_images/18e8d1dc2284db039424a9cd38618ce026403b165a74a33a81de762ab2848448.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0eb35eb14babe048545f7dd990b3d44d40eaf5c7a725716dce3922bf47369ea5.png ../_images/32ac3f529304a827ba073a244efc2458fd816eacc1aa6803227546c7077a1f06.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7184bac86a20c36d521a025c5190fb76151d4972bb63d703a2c3135ad873bdaa.png ../_images/e3d8914ce78635ee2c10a9086165506db951e4d0d1bb49093c044f9f9ff0c240.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/967898286c51a60d9a86845a86c754d6fc6ba3502dfa8ff35c50cd04fa2ecae2.png ../_images/f41f4330524eeab4d2af9a0dd010aa26c94f63ab2704bcb941420c3823be4447.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7994bebaee1ea6a5145a748a1fe371b7f661a8e01cd889270dd693c6d0aa6152.png ../_images/05788dd9a8259a548bbe9f93e6811c598f1cdad44c8dfbd2756245946589dfe4.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/76e9927c307f219ce41f1df2a42fe832bb109ead56ced35a947949d119688f83.png ../_images/f0cf6f51a5db2449d367cf75f171ca8c5d0507de56fa43506a557d70c84a287f.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4eee4a35493cb21383ea2baf35c278614c83f5f12c89cb10732118887f83de44.png ../_images/ed3007e0b76618fd3769aabe6dfa5edd132f4e6e1f0ba5159205b3318f0d4838.png

GulfOfMexico#

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