# Parameters
variable = "fsitherm"
long_name = "water flux to ocean from sea ice melt(> 0) or form(< 0)"

fsitherm#

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 fsitherm 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/2bdcdbcab12132371f03023b138cc4e4446ce8d03a882ad1e1fdd1bab9e403a9.png ../_images/39aa57183dedd56358514ca50935dff0b44638a4b2ebadb931877c7dc4452f22.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/07000ab3032c699ebecd03894eabb19d53964a1c72641b0aad3465bf626ffe8d.png ../_images/59c1ca752ea29af7c026bca28cdf7d78f6267c43615bbd9fd30087b1a1eaa43f.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a5e3c10ab89fbe134d2ab7a55f599e14aa2c46213a6904d09b3573c9ff7c8f3b.png ../_images/1be5c506c5ad8f73547525f9276d97968d60e25a8c6290bea4c1dd91bf59ca78.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2fa68d08345d1bd576942042d715f63e861caef6153e13f9ef80aa3af32b71d9.png ../_images/8e63702afc78b7e9faeafaa3d4d38670a3fd7666bdbc493a7e9d41a5fc4eb2f2.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2cfa3f398c19e928b6289502b46522302388ecc993c753174fcc6e1d0221b1fd.png ../_images/92e4c75e7e4c77d952e48611cf75d1263da82f8e3d79959c06befb3c014bb5e7.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/727f68760a9afdce0e328665611a6bea0fb92818a05c231d8c57c0de32abfb38.png ../_images/0b0918c81442cd38f3d6674dadc4b947ce7e0608700836747b59e49fa2729c52.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4f27e59c7235d6693edb0ca47e622b0e7ec0a2c6a72e66142b8b43ee48c2dddd.png ../_images/fa1322e78896b6b8873957a738437ddf1390174ffdba8340d77b819683732fa9.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4d556b035978edfa30f67e4bf10f98cf657a805a170f30385c3e3699f4c2c537.png ../_images/05b54696731e102387f7f1d6edcda91da84e0840c2b5e669f2157d9af097a6dd.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3bbf628d06fa27b82ddd915d1eae61d29e49cdd5060dc185e82abcb5edab8098.png ../_images/6b3acaa34c51eb5550b608ece86b2bdd56233a3db719d5bcaa2ffb53da541420.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e0fc13dabfc591d2303f2777b5519e582bfcbaa4834cc92c79a9785036faec4d.png ../_images/8905bc423022867b1b12a538b38cad0de2da9c3d4c6d9544d47de2afcc4521db.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/aeb568cab4220091f7e8fd2f497c8c1cc26982ec237b1c70a9e3eb30662e3082.png ../_images/5dffbcf528ca8ab50c5c3daf7a39091914c52f33ee08be9fe661a19dbafb0f9a.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/427a38f7f5c21b99648b17fac730c9e5cbe678ed3824b098a114ba3e242288a2.png ../_images/2d94d6d2e10daf35405e692a2caab87f28166fa01afda92f2ebe90e247aedda1.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5fbe326ba5cf63924cda85421201eb7c513adbdcd3794f574391e71afac71935.png ../_images/50d7db3c0f58561c67ee63b1f7e4eb4b1a6cdb30d283c2797153b3f2c193fd5b.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/094371373cc81f0c9bec83cb5e32050bc7e2a7b4c8f92f2ea81145c96749ac0b.png ../_images/2c8553c5adaf43a08405642ea63bddd98c9f783b8aae3711f0e341221ab7bbb6.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/de51dd9faa0a9d1746b63e50a62c37dc0bbaa985956b8ee252a2f38c33e53e8e.png ../_images/c94c35c6118f4fe94a9ae745eda994e17180a626229f08a9b5b1c91172c28f06.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e8726c7198efb62adf978d0135f8e30a327330bd419a3c6e8c05b12e3f484fbc.png ../_images/75ba1912dd7f27405f40744b82ebc2356edc1576e1c82862ae99e15c8750f919.png

GulfOfMexico#

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