hfsso#

# Parameters
variable = "hfsso"
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 hfsso 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/f7c9fb7cec2c3badc9b14f4f5d52a6c487cf15fc934116c1f12a70d233c36d1e.png _images/ba35b39d7115a5be863303430956ddbdd707d250fbc0589ddd2b5bb56723bc10.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/65b4d91209f69ee130573830f28a3b854d8978056e12f892db19c643e0c2c262.png _images/11fcf9da2fef25e071ffceb6b4c1a865a21191d00fa7d4caf9a8b640346a4793.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/c67f9904a21495240469ad10612ee6962803cf576bc6f45b54bc8c6cd046d59d.png _images/9b076877e8e50b1c8e2402fe0fd52b526656e6a3f6c36768cd234dfd3c290e18.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/993b7dd3f8a4c63edb557930eff153908c3cb69c9be22d1f02cfa936542bae72.png _images/0c08c893527fb8295e61a1356cbe66a025ab765f7955fde4848d8d1ff589b58d.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/fcf263a76888cebec57ad96cf78730d7aa4f9a13004ab9c3cedfb454571fd1cf.png _images/33fcd5e1066f8b4df32d5c2499f26b2fef0c94ffb8bb88773214847ec95863d0.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/581489cd5fd7bf2a1243e359dab03ff360fbfc2be165eb034676691b8fdbd8d2.png _images/3115c24908d184922ec043cbad7b9fa93179df9cbf1ca4d543a2d01313c6da40.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/325d293083ba2ad0d7b757a9be1068c5b0568a36af20e3f84e6c9c6c4e461ef0.png _images/f453c0aba789688fa1ef3b409e8a878aaaffc399fbda76aadd2d57c915390802.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/98e453278c7ff7e915d274d3e62cf4e933a0cb055dfaaba06a0dcdbd0f0a73d7.png _images/5649896f4ac1a3ea168514b5b333b49d4db07a20e6c7230c5f570870ac9303f5.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/8b1396cce5a1a625de15951790d02e4c3f1b99a5db041104d2f054f49da24fa1.png _images/840af28558145e1967f1e361f277a311f6d492cc85ff042dbba9afcbe1f94728.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/56118f084b35fe92412fb408fdfeaa2259ab8213a33414acb7bea5f3a854bc57.png _images/4a643a8ea36e7dd1b705a29ea021b4fb5fef3fc733182bf3faaee971f3733c0d.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/5a294d5b62b141e8c465c18cc6618c18da09c1fd3395cb6d3218ce75a67fad1e.png _images/3cb25512e7a1a4830cfde0b196040fd76c48674dd865e1da3f60365043266428.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/759714778e7a765aec029ae4cbc21189c4e66ac4ebf79f14816b1dd804ccb29b.png _images/f5949bcbe724198c325d8c2dd5f093f6d43ef92f712661330770fb93cfc7ca24.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/569f6dd407d59f7b562833a81cde7e9452373f043973dfa087304c152c1e8b07.png _images/06b90c886ff768d418beb641973bb888803fa8586508f20e40d4e184bcc251cf.png

Maritime#

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

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/137c7282dd0463345128e4bd485d14c18900ec98a1fa4088504296f826e66bd4.png _images/6915e3b4019529050895444f7c06b3fb37ca6537fdcb0348d487fe9f44d02d25.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/9dcde08ad908761249a7fe9ffede8e95d35fdbefbbbd4514eb0b006ac2478324.png _images/b98991bcba1b21179ae8af63043045ed088be7f6e5490ba2df2a35ab8e7a46fd.png