# 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/111e10450d97024e1ff2a064c58ddb261af7f23bfa16209dd55f261f1bf38b19.png ../_images/1773f5713d5a63186ef4263c617ea75aed8641fb71fd25fc4cdc5a4d2c453896.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/48df20ffefb265b1dbc96624fbb3e2f27cfc1836a608783efaf09575c7ab6d00.png ../_images/7eb69bdc53b530261b69352c4d0b9db88c10d4cea0b03303c5611de02714a9c3.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/833293a62996e75948ac5337439a910b33c75896b65b927fced889a60ccf4f9d.png ../_images/e0b359287d8069f0ea2d4032f973011457f9842ad1e565c674ceacc384b26285.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/10385c4d11eff4e1f6be30b0c005357b33faacdcb3e79d1ef7cfce2283505c37.png ../_images/15830c1fb78c9c3c8f3e36c16b3c6762b7c640b06acdfa8f6dc6a315ca9ee7fd.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6bd8f2f477d67ef56cb888df655e759d0de7f936955b122705f44059b1d96459.png ../_images/bc295e7998a2af7dc7cf434ed598a6529922924b5e4574379be13ed3d22ca3f1.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e2f807a94e6b245491ae941296565a5a8c9c3263dfdd04f3ecf07aa69a1b3b43.png ../_images/24e99b5f3c0a6c4cc8cafe0d917c040f4cc007428626828e303dbccba6eda442.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/474d1f51ef309d286ea727680799ddf39571f2d130a99896af440f82de55aec0.png ../_images/6683a74c01f40366dbe4f864406741f12eb2df5df85c696b24f1e570ee643c32.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a37080022e26439262b53eb44c4cf95be934b8c0f3862779b13702efd5cb5561.png ../_images/25a472ab03a50576151fe1aaffa19804ac1aabf6066b68f57e584b8ca5f1d7b9.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/09be969f9d45800b7eacf7d18868802bbb2ad10ed32787b9e9ae5052b0729867.png ../_images/b06973f5c157521e8200d404cbad9922a50ff103721bac655c89824b22b31e6d.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/067b4846acb5c01600a09d84e52fa09c0dc03b31a2c6eb0e3e655b40fca7c648.png ../_images/f259d9cecfa33c5147687427076309b10b7f56197a27d563bd7ef6da9280883a.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8c68f910f30350168e4969c257f5a587ce1826ce6e285f1bc9d3f2422efcf093.png ../_images/5d08a75cc84ec083849b2c571c7c72cfe8f772f14001723c53cfd9501a21fa33.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/38baaf7e52a9f5a96f5ca07559093498b75cdc4d4051f2e88d7ee6b1f82d9ec4.png ../_images/1f61284290331e822ae45ba7e14273a422c881f6e20768f3fd84e1e51e67e64d.png

BaffinBay#

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

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f2e2effdcc6e9ec000e0a6fda3e5ca5ea1e3198fcf3a0ae25e69eb6ec9c96b55.png ../_images/8b94fc11b28a8dcf560913c9b7b712fbc28d767e361679a7640aacaff4fe5ef1.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/def8abb4d1f4354a583ac4d889da1763ce6b88bbaa50d5e5e6902046fe024b34.png ../_images/3ab609ee9ad1db0c071b9e82e2be23914e77ed8c68340e3533a19b820c2ea819.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ec6c52da9d1986cc1fa1ebba15fdfab69c8d4b0b0c7c663938ac42b6418a1a09.png ../_images/d623833f7a352f0e4c92deca0053f6393dd5a0a96e0f9f6006e18bc9df0c04f9.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/554f78f1f26274b9f83860d42e7b36d714200730514452f28c1d179e6615c02a.png ../_images/da3b8ed3e47806adeb82d79cd6851c6edc6c9f8378507fd1a8c1bb16f44ea5fc.png