# Parameters
variable = "hfsifrazil"
long_name = "Heat Flux into Sea Water due to Frazil Ice Formation"

hfsifrazil#

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 hfsifrazil 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/7e88a26439e540714344f293452903d602afcdd20717270787579c16b3f46880.png ../_images/dd26a4874a71b280ee1fec50b47740c55ef19338839075b620f16d7ab0010614.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1ad72ecc3be45170b00dce40240d4d2194e39be3fec0e792c5af74ae482f0ba4.png ../_images/fa9548960f9141d1aa26a5aed928cc89c412c452b7fcc81d3758de00c0e0d698.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dc6ac6fb3102ab0e54138d12ee7091e107001059a233dae9492c5dd49c87090e.png ../_images/8ad5ec5f63e5e2ef8e649094c50c03a621e1e4fa53e6e3d3888984502569a85e.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/98325988d574bdce1a2dd0aac23d96fc26e09d5df9962c8ccd93678e464f3a76.png ../_images/06a978dd09d161c25c2fcd52bd0d21494b602a14950dd358d3ff96e6cee0e91f.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0219dc887d103cead1888d1af5819a48a984a29baa64e77123a94f3453d7c028.png ../_images/0c18e0937621b5069053c11ec9ec68532e2e413221f03dfae3ea7f30ee5325df.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cf439badbb6c298d1debc5181b71a3a9eaf6f5aeef0d375ed43bb09e3a1e2692.png ../_images/7d3ca4821bb545d67a0ed065c053b9441e5e59b27eb57a13435dd46c30b67d62.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/456b4241ba4321b82138e8fe5f425b7725f59be8326d5ab034b85f2fa3c5cc25.png ../_images/5915b267e6c1614d8b21856522e66bb5ad2f0c74a27c8c58dd8b5c958708db70.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a13f45e869aa92b7976df2a284a27ded3fed3a7c9afb4914a6379a0913fe494b.png ../_images/a93ab6dc1db30cc8d7976da4c8215b40bb51ee183597bef2271e36715446a2ea.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/90ccf3f392364405010d3ab921dc8df90dc939c784ef821db87a2da4d88047c2.png ../_images/5a0f579a8c140c4d63266c84ad7790a1df2f50e37200c823304d04ace0805578.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d39ed00e5caa11b579e578fcbb5f17ba72418b9ba136d0ce224e98f688f39cec.png ../_images/db553d33741812cacb05ee10734b180fd44a7e7f5af7fc3ae76cea107fa8ca36.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ae43b98348282f79c4fbf0526808425c3bcb7a00b874e277c76570d9edfef8e3.png ../_images/13acc0f4d436721be15a011a6a423fcd742add3443b93f67c74d70af6b7e19af.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2fa6796d719568d4488e273075ed81adde040a2a38ffca9bd704a3dd004f394f.png ../_images/b889bd3cb2d42075f97647db5e996dc5489a30974c2011125159a73cf04fe39a.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8136383573e33e13214014a7c60af7b9db2e86c29d881778fd635a7dcb2c35e7.png ../_images/ca77ed8b3e05e24fc87923719dd1c2be31bc098fb1ef6ba36a756a9dcd737bf5.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ac6033f1304d1a06d084608cee26d9b2e2ad1e9b730c5c3c17ac18f25d047ec6.png ../_images/fe48685ded6b5daefa3a7e389842ce715d97dd0e00996ce0613d74c87e238cac.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0f53efebb970c1d15feecd263ded6ac4876b3cc391b6cb0305aef2fd06a15609.png ../_images/44df2be28c9f18c637ba62f9a3a0f6e6b4e8895f22d6a6f62ca4d2717146d552.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/49dab1dbf7cfa796b41ffcd5483ef8ee66a6971b2a12e46635b99d5389f8e462.png ../_images/ffb5a109e996a956069b0bd324302b157f405bf1ae9c9ca1fb1b244ea6940ec0.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5e53d551b5858292138ba67760500a5d00709af710ef6a05e8a624c7a03f1162.png ../_images/9bacd8690dcb81181d884e51d288bb93d5885f982d26704eac348c2ece3690d3.png

GulfOfMexico#

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