hflso#

# Parameters
variable = "hflso"
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 hflso in different basins.

%load_ext autoreload
%autoreload 2
%%capture 
# comment above line to see details about the run(s) displayed
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)
    
    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)

        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/8fe2d6f5b808c0a72a3081356df9796fc7057e6544d0171397c432f19d05d496.png _images/1b4827d2928aa087e96f28e426e5c5476ed333d06b09d7c6944605c6166d0731.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/b45980996646d38ff9664e83cb7e45f0bbf9695f346c09865848b8b00f0141e0.png _images/baa85b841392e54ab65786ddc8e8d8fa34b2f461a28e437e6aacb8f295776e37.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/93492648ba661a5c61ebc19094ad5210a98d8e24caf8502155c7dc8d65f20248.png _images/e8fd9197b44e7a9031af875da2b5c28b9c3c5a1cddddf10f1e32fe78fe38c744.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/8e839b591ff348a3c57bf2a97f7b36d17c2b34ae921a59a8b0bf230f2edcf5e7.png _images/5446925eef5f26ccaa3fe5696a059c90b51f6c50f85b5f1057fa3b36c9971590.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/009ff07b782187ec7431579582266040c684eaee9c30a85692229e72640bc101.png _images/0c467a8e82a8789599aab059968d0b88fc5bdff6f030ff80190cc70ab1b4d8c9.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/50b5d7404274454acd01b0989e2c559f124927fe86fbca28f9b28d40aca2276c.png _images/36a40ecc8ae1d33107a3afb9b022c4eec06a749d7aa284aa80eaae55e09c12a3.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/6a39e64bd81d4b8e7aeba8101c13af81a063761445e479c3f610005d5b635ded.png _images/dcc4e884e98059f1d80b2db8bbb00408a47f65220f44906af9664945987659dd.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/7f86eeff275268b8fe7a5c84a5948834f3553af958903ec6830c521877615d6a.png _images/d3f97009aa2894b01cfdd983525e3525ca9d9881089947befe78462a7bea2e40.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/1696ac83c366075bdd4f907b3c3ccb9c53fb79c310562ef17f1eda3703856f98.png _images/f5da9337f8755bf7fbe8de8eaa8ae0618dbe9e2c62f53cb9ac9e2e8cf79476f1.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/7339a9534ead4148b5b04a61b0a4c26a0b0ecfea781c833fe5401091d930a505.png _images/3c300e230b164477cee19891b489e5026ada3356f06fde4e1c6b8862f6816a43.png

IndianOcean#

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

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d066398bfe79de60030e1bdc2ef19eda055ba949fd9a16dc73d9d8123fcac04e.png _images/b704ff3bdd1eae8844b4f352c7ff0ba6a2b12ccb984983b6ade88c7adfc531f0.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/df2be7fb1fda46087a29590329fc6a1a02e0b952a7764a6bfccbe2255e96aba2.png _images/076a2f4bae3848ede752cb45eb766afedfbdf3e527ddd7452f7ffb948adf9c2e.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/b852d6b37b6a3d6393c5434e404f1a37fc57caa50cb41b30b52b4de7105166fd.png _images/f22f3c540e6afff5721d754a55a6b00662977024a6fe8806ca38e2afd34993a4.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/76d46400b01138a47f3c5fe4bf0a7ec6b4e49cc387db60467ad66d4cf6a6dc3c.png _images/e77d520388e67c9ea0c085e1794e6b86f4e2746f7a2e3f67c30f7c1c6a71d92d.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/778f6510537afbb06d735d4273390aba08e4e0d925a8c198520544261fa51330.png _images/bed0822def394f4ca25d487fecd5f280d259e81855dfa173c7fa950047d55b36.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/1c7aafc7c49d1b79ac55586aa775660e85a294e3138363b99575533bacbc0c72.png _images/adf3da24f47c6ab3fc7cad5a8d3a590beeee0098b69e24ca32fa294b890f5909.png