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

hfsifrazil#

from IPython.display import display, Markdown
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.

# 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/471f1eba69c90707abe6e9d1800ee8d1e07a874b2eb44865e1dcca4d5fd8bd13.png ../_images/bde2afdb7394d3595941f5262cfd9611655bb97821eeec5c3307571c3d375460.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/29956ab4e1df00fa6baca5198f9f9071eace3111ba147f200a91aba963f16a41.png ../_images/2dc41cd7a81fedd57a0d97f1a00bebe41086ab3ef952dc7c494802ff8fd2705b.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/81de25b8269a4fa728e4ee3a95729c12601b6cd488300f05ca3a7211415dd8bd.png ../_images/830581c0d6e8cd869ef6489f269a0597e9736fa51de3f0c1975ce32711f0b561.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ae38b3dae85425b2331740b0f69512410b86763e2769f666445c6b2ff95cbf67.png ../_images/2bd9f526c231310d0816024f738f252f4e800fe79e4e9b0b26e32ca1b4f2d209.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9b3506a55b587e207d3e3657d43986eb2bae2fcf7d0d59fd1bcc83f6194e4304.png ../_images/4438eef5393eb00aa9a6c263cf8e8fc595e9112f18c17bdf435c960e3de85a35.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/496c6cbf68f00f4aede6413d925b4f8585245ba9581a3c6762240c4835227f68.png ../_images/bc8fc45258c909d3ff39de4839e1ea5af207abb274cb99bb02a37fb1957069e1.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3551cc7e397ff4f14a5700ba841f92e879e6322dd82d6f035a3111425be50188.png ../_images/7d13c1331da616425a1002b42ec83dd74680bbd50ebb79db4df1007c2f5a3a1a.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8019d8fbba260d56960bf6ad835c6dbc52897e39acad665f0284787203de55e4.png ../_images/070ea187082dd6a71e1d450e76a8f2d8f58d313bce01bbf690bcc77e4797acc6.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4feb5c3dc05b2589efb9006caa66cba308f5939efd371b50eb6a178b8fefdd98.png ../_images/8b2b4535f8265691f2399a58d0e6ff5597a9a694c8bef52492281c069208db43.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/61db7860870310882b9bcee3246072ce6ba3b61cd18a33019a675e7bdc04b15f.png ../_images/a65557a340a0f1878120806cea0ec4dbd0cfaa4198ca5ea18f9f4abcb6947258.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dc3d2f5f4cb3e142286784da2422afc1197f2e7e0f3cbe35a4d43b0996eb05aa.png ../_images/fe1e466800d5071766dee3a0eb70f044235b4b0d9bfd8e0ae121760f18c44133.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fd0ddb1357775c9b3414044af2af087c46a6d37a50e731cd01382adf430e016a.png ../_images/0324b93cbe2625c3fafb44f035b73a2a3861172677f04b495cc2f7c38815755c.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5823fa09371dbe18a7be124d9d25f325e7a7fb3c4e777a843899d7f0e196a3f2.png ../_images/0320c8aa1c347bbae27ada4077ceb41d6cfc55d74218103ad425372259a8f7d7.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/58ad8b7171f72151b7433ddac39c5963b322b29f7b79b3ac4449df8dad1ad3b6.png ../_images/36b9f7e47c466c9abf524652d9f81b00cdfb6a1753f4e9f80af33a3c9b217b99.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/46e139aa08d4b4023b2c2bf4338d5eed94bb99ec0fdf39fe692fcb6e1d3b4b0e.png ../_images/05612f84748d44d480502652c29550ff76d47dd1cd1fa24b1275824d2198c5a5.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/54210ac2c9f965a35dd90ad93023c78a900ac7415145f6a3a176a011a170d6c0.png ../_images/57056cb8c88b3a4f09f796264ae96e2a5a697c28fbcef66f1d8e851da426c7e8.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e2301f47653a2f6c8df51b2af149139a4245f5fc3f3fc931ea39555d455c1b2f.png ../_images/6e74d8b65d2f11fa2a84ecb41002d9324d1c8cbbb5d74b3f5b1738dfc4c11555.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e06266df038bed266e0a89ff51b0c462dbd02750b55d172377fd733ab2c3b3e4.png ../_images/3fd26fad4659d0918bcb391b55fd409680cc07122cd01c858f0f3f4e5fa5c325.png