# Parameters
variable = "hfsnthermds"
long_name = "Latent Heat to Melt Frozen Precipitation"

hfsnthermds#

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 hfsnthermds 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/9f77ec93f991b46d9fcb2c03e40cdbb7ec14be3b3b7043066534e0bbaf3c3ba7.png ../_images/deafc02a9fa89c7e63eed9d68811e1fe05a0a6b7d5c9389718ac7aef1c87d064.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/32a19615ad43bd521aa0c1ff1d03e7dc0b6ae58ac38343631d8e89ebe28682f2.png ../_images/beae68621ecbf36ee1da2fa17c280769f50ee52e4b6ea88c76d1ad0e8d0c2802.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d6931654354913002ab7cce684f9eb64d7f3dc7128944a3078e7c47350d1e39d.png ../_images/c15485c50c7b152e1e621c8dd43a7544446d6c4cce68d5f36c315e2c7bc2afa1.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7cf2959feb8b9f099c8822f48473ef2b6a8f007b62eba9342315d1f95f4c9ed3.png ../_images/167c1199eb0449799a64d302a5277087cc010a0f2b9febb8150de6dd7b059f20.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4930125fc4ca82b8d39328040578bfbfb43c8a6f9df4b909c453b1c8e15c12da.png ../_images/405ea0aea9f72ccc4e401c13085599723dc79fa36b99b50f846882c85a9ce012.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/631c1878d3d70c433eb84641229471fa9b699e534f13ed6b3dea81f7d9730a0f.png ../_images/c75d5c66e45886dd32d71262647994a8f1870cfebc74de1b761e048bec7ffd42.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3a25d73c9165d8714fe625e8977c21865c698ddb5361307fd0dbca3bac1c0188.png ../_images/b68dc8742c374af9cf16fbb6cf676193cfbd3d88716e309b3d9baf0d8ded0c60.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5cf3b599958e2d43eff549e84f2d933e4460b023de5eb078a8909b89a3f80e2c.png ../_images/0d1a8da4be1b20d2189a613aa594126f5ea4789e11c15152040dfdf91bba1d88.png

PacificOcean#

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

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e9afab99faaf02de89c3616166fdfbb0b97756de9b48f57ee9b89ec00f73ffe9.png ../_images/6c7f7d46c189c1237ece6932971beea8e5d0e95411c7f10af1b7f311edfc4d3c.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7477e1ab4a353f1e964f7a098756f0e0d68b0e0ef5b81a0cc18e24a2df4eaa61.png ../_images/4b592db4d25db7e0ec57ffcc062e94471ad1911d0ae57f04f99393a23dc9c3ca.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2828d41a1cae49f0e2f1262f9b9e5edbd34946530c77935e851081b1d641582e.png ../_images/7876701e9f4c9c29d1a6177d8f4cc7847e9655fe7f874ceab5aeac4c0d07173e.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6bdd0e877f02e2bf13e942e4bc6473e6cd4ba1d3c9359ca4678e18d680500d5f.png ../_images/ce096600519985bbfb3aa3881ccde7e2bf4225f7783347f3513ccebd972e2c3a.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9e54d7f1a47a151e7eb323838def4ccd320b7ffe31207573d2460ef6bdaea901.png ../_images/a72cc2b07f872d624d6c582f37f1a98ab55f795c9bff1f2ef45053cd24904c40.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dcd9f7efeeba9ce8d4597df4c0c75edd4dda7e7559f6c228b3c041e8708340bc.png ../_images/170a24257d4281e78d4df80338bd870ea84421ab6e7034e8dc1d10f3de8b7230.png

EGreenlandIceland#

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

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cf1241a18d250fbe019c8b490257f56e7466afecab94aa6ae151bc2bb96fa2e9.png ../_images/6adaf621f3464a5a63e205dd4559e4709216c545898bdcdd4499d497cf794819.png