# 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))
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/24c45ed1c1d70f2b414cc951840c66a78f1ba9b487eaede8ece4d80e5c9e8a03.png ../_images/8a99ed9a394b247b203ea4b0a22f0392c4e8177c2fb46f90d08b63f8af7b5147.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/25091542003633a1bfecf4f7a1c3fc16a43d6e166a0384aa52ba989cfc369ca2.png ../_images/efc7830b2c8544afd187db688a77079bba909bb31a308b4e05c0976aee5e6759.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/124a5dc043c2ea395b8a49fcae405d154830c23ca4d7b27c3741e17d0add2deb.png ../_images/2c079714fa094f73dd83486082ecd93d2b84655e06b2284940540af8848f7c04.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/be8711635db8a718853f9529a5ca4b1b79355f17654cf190d9c05e38067ca88e.png ../_images/b2f0408e7b3605cea078820216ffc65ba3f3369df99b2438098c18cd5062a370.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5b7c708874e12a08e539f2313cc9749ee59457c3708508c4d313279d69a138d5.png ../_images/c77d73fa69a36421d4234411cdefe4e7866c291fe445791e88e265637b2ad62a.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1fc8eaab239111364c114988a0804f4c273a96a0caffec273abff3d420ee7f2e.png ../_images/1292997b5e0cce7251334f7e4746d2e6f817c0282573644e1785facc54fa0ff9.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e6f3dc80de5903bbcf6a7edf3042f9104b846947922118b0d61b4b3597054381.png ../_images/5a842da8002eaf3fe6ac5fc7efa0fff446ba948177108c95fd95fb2baebc37b2.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ab24812dfaf94be5024021928408427ff4eee00e0e6dcd298e819abd31431871.png ../_images/8a9ed89b6280aef8b7e6b1f7000fcb291d8b259057fb5223fa607b644e1644b6.png

PacificOcean#

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

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c6dc53c2717abbc5f049cca9f0b6f11f8831a9912fda9cf28d0d7ee74c0a2419.png ../_images/1a6dac4effd0fa8139bd80395c44d0d3b22eff0e1c3766b3980c4c19a32ad40d.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8203a2f754423a0f933a4ba21b427bff8088d500d32f3146d60303545a76148a.png ../_images/ac2ac1be1755d5540fc7e009e53216dd61eddd89a0c5d3231757b98d09bd7dda.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/59dbc161945a9a73a681601603a55337e0b8e3bf578e20f9762fbf82d5b89980.png ../_images/9aaa6cd70a27700e3fc1747978835cb0cbeb7a6da5e0acd0f3cd83cb5daf3f42.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/db228f354d609cfa9e3ca1af2ab8caaa9c2749c3ae5e2f40bb7048ad323a5529.png ../_images/4cb09a94dcf52a8fed3a9248ea77e93e5ca5ac3a281023f6fc52009e1462890f.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/181508103e9d80d3f5a4ebad3e93bfd9d8a4fb0df39e1670dd2cfcfebec0d50e.png ../_images/f55bb4ab004fa3e89e358563a5032cc1bb9440aa4142bfd1471db4784d4a6a50.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c7d9f94f90b7628598dc6487b7dcc32cb187c70e84e69cc43f7719e8e04c829a.png ../_images/40f8bcb1e2ec5a099762de8ef9361e30ea8e8f13433c7da70ae21c85698cec9d.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b71e240a59a0b64c6644e1e54408198eb25663551649c386919de86c2786efa4.png ../_images/925b02cb55c7cf09dc2e08ee0a8f0ab21bc2816de0b2c6b1927584758fe0f557.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/530ecd5004fc2e2ca09af944dfaac18210b413124b6f531359e7451de44f266a.png ../_images/61064d20a3a8470080d2505263e26b6074f700d8922f6a80a588fdce9d37fbdd.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/89b29b02c655e414d5d083db87c17cc803e3454899b9c8d6bdd55c83db700e64.png ../_images/d9f5198e25ba491b800ec5cff886a9bf5807f4738a6e8ee0b576532a140b107f.png