# 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/b73bdf7f374947ea6b299054f3710e65b8bdcd7c574023ddff7f13768d4656f5.png ../_images/7d63d900d6c1b198095ba43e9567c4187521699c6dee263510e7d154320439bc.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/67093b0662b10a04a3debc11e53f190a47f76b21d5aec47db9ef3a368af9375a.png ../_images/8943ad3afdadfe298cee8d7857707418380238bdff24de32ae9cca050a23802b.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eb88fac64f327e3ee4a6dfd6e8d9d691491fa6f37ea52a31c2d9e115777dad72.png ../_images/6f4b1dceee2d81741b4b43965fd9ec4de155384c5c1f946b948ef6fd57e3ee67.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b38a581a5befdb70ae196f7a300241d3ccbc30e72c296a33d1746ec9acc08d17.png ../_images/6839b63c537ae2de864044dfa15fb8c94612944ded6d9522399e59dae70273f3.png

MedSea#

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

BalticSea#

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

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f6f7cc4c460ddf9b8c8bb1352d560d3397659df44365496ec5ecd00e17bc3832.png ../_images/f08ac8c01fbaa89ed20f03ba73d140b826064bc210f85b51c471e87c72468e09.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/956ba1ddf2bcab211e8bffcb1fc89d4e20eb09640e8fb2e08a3d374b103c095b.png ../_images/01d04a05988e4564cedbc10d41ff4e4551b2300cf4e5c12844f1622365b811eb.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fe0a9e8b62a24f75d64eadd255c7fcd1494f372d41cabf56c5a512ddd6ad68de.png ../_images/03ea47a32c4d999d49e04550dbfe7b91beb216642322d6cd0999aa1f8e1fc8ad.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fdb2ac77813d09c7e1210cfd098b9486b8e4abc54884247c0e369162cbf91b18.png ../_images/49526054568b2cf1436f5981a443063e642928aeef546605c4834e768ed5ca57.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3e45b1d9dbc51509a35f3437f981e5cea7e152a5c70eba02c4dfd2c1da97f28f.png ../_images/6798ce6d548a47ae4eab82493f550925e9b9295a900948c079a37f5ae899011e.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d6c941111d0ca7f0c496721b4f358eaeefcbaa65555c19f8c598354020b2a08c.png ../_images/e7b7afbc0975b66eeff9a8a2885fcb51dd46626d601e102338eb4d4c928d049d.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/643a048323dd260dcc2739eabf93b99003e2555047a6c2aec278e60472df50d6.png ../_images/ac4ebbd43a6784eaece4f682d16bb1b22cace3cad7ef6dba688332517f2ff8fa.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ef1664aecef334d659965efbc49adec45e460e9975f6e55e7f61f1e4448511ee.png ../_images/561fa6055f69eea0d15d3229bfc9b122db93e4a94f898c3fdf48a1ad799f3a3e.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4e590de783c4233b7013b09cdd844328170a8dd9feaaf35f28c96b0dcd19b656.png ../_images/68851d9a31d712d094aa4217a820b881ba74d7af721007719cbd51e928c21a75.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/abcf57dce3932b9973b782e86de9578d7d7ac278648b4c1f055e5c13afe5154c.png ../_images/8bae56278e45eccdd30ec844beca3fce3a010405d0c663f4a6d7ee3cabe84bdf.png

GulfOfMexico#

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