# Parameters
variable = "somint"
long_name = "integral_wrt_depth_of_product_of_sea_water_density_and_salinity"

somint#

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 somint 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/8e87754b924614f8918902ece39cfa506e6d1fab931f0cdcc78d6b5558ec4093.png ../_images/12010c8773408fc85467913f774d7ac233c2cd8e462102b2e123be6bc2c0ae3e.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/31636130335a61d5c07546936165314fd2796971642077603ceb8dcbf1136c85.png ../_images/ab882fe43d96c1f0233fe35983b18c88d1a27044cf2fa1ef0797436081fde908.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1b881d974cd4b733b54591c0ef45c3bfce968efc1c1b0bc1a7cae1874ec82bf9.png ../_images/5bf830151ea095f430a8840d95ee1f6c356c18586a7478909f9acb97a7781066.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/993f55664f53112740ed60a3b240205a5d554867cca507f27ddb4467d5b44c4b.png ../_images/fe6ea7f2671234aaefcdbfa444afb389df15dee250d2e4de80c3fbc1c05668f9.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5e7eb3fba4e5f9bd535b5991b43446d72e3ee2c9bf414c5362a2e2d2480a692d.png ../_images/569014b6e4118af7e0bf90de498e42bd6a8996f6289c70b257e3cf2cdaaeba14.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2494af44e7830abfb8429abaa9cd7d623ae8b37a221076b4961e73df65a9938d.png ../_images/630c907da823b8129aa367d09797963e1026be6488590c0a7c93834754ee08dd.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5bad828528ca22ae79fafe7cf120f1b8d57eecaf7a514b126d0e8e04fc637b40.png ../_images/72d618a3476bbe6a61099b6632e544e8fe25917f6dee95d99b2fa55f80c3fc28.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7b899a2d4b89a250fde9a4a1562c412466c80f707dbd55a54d7c2fcac859850c.png ../_images/534e562cc2c23068adc30ac2c82762f673221cdf70cabe70c8dc39709c6f5617.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/be9e9d3363c7184f0619668ea7571303428a85e43f31b2b3d709726ec5580506.png ../_images/207947ae49a281b2cac45c0c4fdb0e0321f3854409fb92e14eaec9d4aa648eba.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dfb4c423919551d3277f275fa512de8679f9e05d34ba9f77c8826e063d3338fa.png ../_images/2ecb22b53dee82e0ab5c648a43196d122e2ff8ede35d6f33c8fa54ef383020c1.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8be322f9ccfd098a965c9f9394e639d6ef980599e7d1fd619b26998e91a91120.png ../_images/285cfd249845bc93a5fe7ab7cfa1d1f4168c64e54cd88278ef4bb73b23e46754.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1b12835dca68fd807b6b28be431694bba77d347a39f4c2c8233e8314e82b6be5.png ../_images/9ee55262e66af53818398f9a12ede9bd1c115567051c483c7be14c7f3387027b.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6b52b0bf4552833e1320ee56004fd6a47a53f5876866f653b9a9e23ec51676c0.png ../_images/aa770899e0b54e1ee5c64dcca369a75c4db9a1b55a7717d7603083684050cb57.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/083c8cea4585a266feb92d1c5fcdea7a79b5419c7793154feba6a3204e69e3c6.png ../_images/4ddbe9439a7969789f9ceb712016030a697c6cb80e7d0ceed6675c1411655224.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9d2adba2af017f85b4f5a113409823baf491a09c58303522a4424024d62c0673.png ../_images/8cdfe83c771e7d88592686be59f3f03d3939ee9539deb52ca39418ee6a11ba6e.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d416062bc7e050d16f4c29a3b551c5bc3b69f274e01159c73bd1b9f605dadcab.png ../_images/3d5c5943e848c94709849d7a1c68746eb0441e26943e9b60441d2d0270c1c00e.png