# 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))
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/9aa8ff9e3b5f153a2ceafe2370d63b373da37bd8874eb976e45e0dc40b6d774c.png ../_images/c3eb5d5cbcc4b795cfcaaba6b85b961244c25a926a3502b56a462b1a2e8c2726.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/64590713dd2a473bd391cb583489989bb49ee973d659e32040f19306938d6a64.png ../_images/72f664cb3503959c9d1efcb251c4423fc6ff4c08dbc8c246413dbd303badd0d6.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ff967c2062fb1e4252ad84f5594694b862825f3befe43dc5c1ed30ad27107022.png ../_images/3f03c0851ebe91b9c77034a7d004f9d1191057910a19bd7991a2f8f021ab7c8c.png

BlackSea#

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

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3c00250ed55931486c05ca7387ffce9204bbfbae55b7fc8adc771cd2d74ed312.png ../_images/0350d09b8d0d3a59bcfeaecf4e098cad64b65c8af8e891a2ed1e85b7a75f48f1.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/571dc96752777cdbc0b952ae07356dd1d903f2c8648f2302ff248c72f7b702cb.png ../_images/aed72f4bd46fc432710776870a7a67b2ab15effc7ae77b5329afbed9e26fc709.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/870e98cdbf10ef43cf1508a9c3c6fe2fe1d42d59c735253b76f221642b147587.png ../_images/39815d56fc8114ded4d7607d12a9143aa7906c17d0e4bddf13624acf0c1e9e3a.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f330e28ef997898c240654f6b493fd51a6ff7d0a49989449270fdb80241c9478.png ../_images/10d4b927ae7d5e3f8d5893b4c8e32d6203b3b5865c1dffeaefa7510327512493.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/53547beb6ce6e39ad5b367b6c0456fb774d92c9a82085eac9abd52b543179a81.png ../_images/53fab70d4f1c9695cc595e569f6b83e56b213850c7bc0234c8f64ef148c9551c.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/54faa869e9a66ec2f5865fb92576150c561acd3b5451cb7617bc16fffcc949fd.png ../_images/761fa7998200bf9567e78094dc7bbb2a52b0fa6f33cebcba505489f4c276f44b.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/75c8fe0474704e1ef3573af44ea6d9a67a62d24014e7cabd2b07e0fcadc51a2f.png ../_images/c7c429e2157d9701df8f4224ac9d6fd265b0f495b5038131ad7efa9b9beebf8d.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/47fafeedd9a949d9f8ec635ab5b2946044d1c1238d8a5f12a962d5abff9329e8.png ../_images/c89ab763922225d8aeb3d0aa4fc9852b82b35b0cb8036ad22ec13c1cea39a27e.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9e6dfc1b9158acb99b187ae9cb53145603e8ee386ca8d66bb5915e576d262de4.png ../_images/f20700478e6b6cda93d3f5393ba0c46aff3f9b899db44bdd56f1087f6280a9d1.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4e8aa678dc96a4f873bc8d5215431d2f70eab08e1614ef01ab3d6700baec54a1.png ../_images/da28b0aa6dd0d3afe08f85670da64596f6b31f3d080a786b793e7a721570c3f5.png

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a6d9569e2190d128211ca577f2cef897597b440bf20715832c891e6e911da2d.png ../_images/1a971b23ce46bcc9b49228f805ed02012e23da5d478b0aeff3d28f431c796dce.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5894c540fa9286c7e2ef1dbacd1a16fd36a54c5c2898a6ab827fe5dbf8a4df55.png ../_images/052dcc26c648166bd50e5fbb96ff94d0688f9d8cfe713acfb5a55691a448f43b.png