# 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/f1bf704e3c5593f1699721e424a3db17b4821eec1665192e93b1bf3f312c896c.png ../_images/b3169531ee98155ec46602cc68ba6ac3fceffeb7de402322514575bfe187b45f.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d0a3d8b4e32bcb69c539644c47ab67db3ac93e0d2cb3973e021a94b4a5584d08.png ../_images/139fb258614b48b4141657ef474e877e101c0e44bdbf41a520d14b2c9075a975.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/65e977a3c7e7d3ded304dded2e451289416c880637cf78184ffbb991c5e49445.png ../_images/a9ef4c1f826481be570f2e310497344a8884455d464ada9cad7c1e6fdfbe1202.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1ba82ab0d8d38d1164ccd03ff5c15ad3d2347ea2b41458e2d378ab1c90649121.png ../_images/c269d58b61f6dfd5f8816798f09fae381b012a8aef1363b4abd54b1c856bf76b.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b41ba68450353bb8c7a0209895458ddb575afc331836bfef87cd07983aad0f2f.png ../_images/93d718bb2cac76367d5c130bc294df0d469164fd2c768809fb4bc808c4688cee.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/20918b29e0ce6ee68bfc83f32294b225b1ecf6ad17fa9bb8b15ca957f75355cb.png ../_images/bbb1cfcd3a9496c29bcbac63d4d3ebe50a4ee9bae6a92f14476a1e1009ce12bd.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2b923d55cb15a5dcd402574622fb64c886cfb0c41e667691d711894a27e29946.png ../_images/42b188ea5c82909ef346bd5c07275d74d9d8ba075b856a04549cf4c4d80deb25.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/252b46cd330f6a5a468c7ae16a360dd13503f0a43f90a3ecd23962e54550cb51.png ../_images/5b15e98a3acf777ab9322f45b0b6812ac06dd5975f60cb75dd10ace5fbeec694.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/21f00043a80329d20fb5aaad079997131744aba918dd4c99ea90cf0519bca2d2.png ../_images/823219836ecdbfe6ddf7ecdcb6132a2c9bc79b80dfcd42eef4e6aef06b72f0f2.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1c5f2943929ce8dc60736f4bf3421d3c5ae95a1c75f6ddc0d18155d709b29713.png ../_images/27ddb1c8f0148acdd5ca2b3cb99b813bd18db67be678fdf620c57fa7a7986f05.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6d1b7909348784e235632b36d4f98c351ad32c93aec22b4f43e4039e025a8c2f.png ../_images/fe61d92245b01e6d7601a45d483d712a31718d1d74e357a9e9c514241fcdf2da.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9fb6b5a637b26edef4495d00bb3e54dc253a7067e1d72226454d5e38b2ab1e64.png ../_images/2bb9de099e832ca9a8925ad53907c39c1dbb4a33a539582720b71f015bebb4c8.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bd3cfededa991a1c7eb01dd7f2f7efb4dbd8c0e47d47836d465f918eee2f115c.png ../_images/40906bae7abf686b17e45babc6b568b7e2d664b3b575cda07db4023e270f67f9.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/91f6ae56e35df7a433707dc2f56800da82ef30e221e9b30d77d0c86e843c40a1.png ../_images/0ac434340124172e79415373a2190b49b05aa25b22e9aa2e1fa3f7ac6d71528a.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2ef81f02631e873fce433e7c134c9870b54f457db8b932b010968122c33a1b3a.png ../_images/902a86df448e3fb17a6d31ae2eecc5653783a5982f7fd064fb0652c59d13f905.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3a146867252b8338ed0d5fee17cf7f020613d8352da8efa0dd5c04a5bc38b2b6.png ../_images/097846fd5cdc486eae6fb1281701fb64fbadc57b399f04fdebdd3dd0abf00ca3.png

GulfOfMexico#

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