# 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/86b9bf6530485ca79b94c596e4b08efa0cc1811a681057b82fe5cec1fafee3b9.png ../_images/f83a2bad6def4b7af41e6c3015503766a9b9acf4c423022027a3c23e7b3ad2d5.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/495aa0b3d700f7eba7a81d82b66f2f56d6f51e184b886be9de300839cac7c4d8.png ../_images/6485a884053e31c0310c7ef587b20e51cece242835de1c15bdc71cf3241bd8cc.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3c6913986568aa9818bad0618a76d5d6532141659c4b3869c19bb9ef0f2420a4.png ../_images/203141b8d410b7d974929497115bb8b11968ec026d2e283c8857d90afa9b9ef6.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ee1ca661f24566e75a013d5e33c873ee715dbfe58564049281686e9153252e6e.png ../_images/0b33c3be7bbd6fb6977c8728a09f0831f19eb0a7f6fe718b6c0226fef27def2c.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/32d11672809e0eca12e9d289296c76497c01d77f1b880af5234ce5690096550a.png ../_images/13e1ed38366b006ffbb2f46a27733fbebeb7a4ad830936fdfde376f7959e0104.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6409bab6837221332e9e8c9a3d9d2538b7d85ef3d3f35621c9cd995b6eaa56f0.png ../_images/0902d0c8757bd2ad07f36c3e25fa5f2e19b40cfb03478ee7e3d66c8f7114491e.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2deaf22edab73b9721002af47a9b34c9f5634b61d91b89449677a663cb5eb1ad.png ../_images/4b1130e73d9d626543f67d1de482b72249ef00bd4e6d3b6a7857fdcc9cfc7970.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/013affd19ba8d908a33d4f359c71513dca5b26a88d1cc712fd4b7938c912b894.png ../_images/90092c155edc89e866b104792165d0f62b12f194f29755db04ab2ce09ba8e6b2.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e47fc80024ff66f458292f37ad31a2cd56baf1be690cc79fa2cb32da4e64ee0c.png ../_images/32db81ff7d094e125d13d49520dfafa92c3463f00de2cd5ae5df69f7382c72aa.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/595707d150b48f66c22108e50146e1692e3bdccbd5ede0901692793f61a4d7c5.png ../_images/f4f483aa7c0a913ff0791876e59a6d268c061ca09b674a5ad97f94ea3815bfbe.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3a54d5c3255becbdba118bc228d98c28b3e9beafc2aca3cb722e943fc61edb1b.png ../_images/1a90d7e1edb26e5a6eccfc9fce9dc46bfa929292e0b9da5da3cf4b0d26385720.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/20958123bff99b891d1b98fbe0e557796a3ec5547eb55da449967bd72226d77a.png ../_images/f9b2cb9bde71d512ef7813f2ee1735775fd54479dfc2ec8283d24dd709bb49e4.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/934a72802cd1b3da6b2ce45ecaf531e4c985b8a02c1229f8e97e1eae10aaca88.png ../_images/e0deb9d7b1d44995cb5824ad2a147cef0a6d9488f8047c934b41e42e3787d750.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8238311b7b07c8fea4ad566e6c0c05e3219781038202ecb7744326f196b054a0.png ../_images/ad768990c746c7755fe3f120a26a21b4672decce7d0d579bd0234a1f9ab960ec.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ef5e46b3bacda92b5f8fc7bfaf18d5b5f288c02d252e1d95f804b8716cd4659b.png ../_images/7a7b62d7909371822b5fc5e70cbd694bcb8652c0ea473a41af5b7e14c20d4e6a.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/87ee0201f32fff9b950870852c40619f902b3b6cf4e070180966d4e869214a56.png ../_images/6517526f1b39bfb962e5dbcde29e8737f748ab9c5d405b48f2500914599dcea1.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c0f8427e8d79900084ae1d8a7a3078e364741118b59761c1cd046fbe9459aadf.png ../_images/9a47049c8a71cc3fd885e5063dcc28cc3ac2e68b9adae2dedced0ea064dda753.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/438a6750029ef8a2969e705726ab479a7777bf10ece95e05ae766bbad2dbd983.png ../_images/96556937aa40a2ba5c0b8d987069627336effbcaa78903bbdf33d6e6b7657160.png