# 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))
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/be4f0366c7cf909036ab510abc87037f62ffaac8c3949cf5cdd84c9b9fad4290.png ../_images/8a1533ac97139a5f99366f243274a191a6057dd29e6992aa8d405063cbf0c2c7.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ac2480b7a4432994adf88a198a1abbe955c68edc4b5983b18221335219f4f1bd.png ../_images/345f295bb1cc6d10573f0433b44562a564f84c36ef50405a0ffd6069954d0274.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c985bfb2af7cc5d0a9608429efc0bea664999051981682ec2f02f2dec2bc4a89.png ../_images/5eceb75f6ed89ad042f55d8eb8afe53e84dd4625ae5747ab4b7732a985ef1b1b.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bec3caf10af3e9a4efc5229a3f7f117bebf04eba6e1d03accb6f2fdf0112020c.png ../_images/24cb209b75e54b4a94237a1f718b76166a7f889d7755f5c286356156362c0ae6.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1b8b319c0924f2daf2e56975a50e40e99bb379c5baf14d083322b3c89f0111e4.png ../_images/c05ea0c1fd7c7bd06e242e4da69e1d369ef5a093c151a70da750e26355e2d452.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/72a400a5410c3498a96b79f51612104056aba2303757b92dc4144fcd8f96faa3.png ../_images/5526b25feb994984a50ff729d9fce111c204b7c95e6352e7464f045b3d830636.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6522b02197aff5d8b2cd68b6d4a85f13151fe9c730181588bcbe4fba006f8e43.png ../_images/25f2e3ab57ada276f1c8d2d7bf5623ffccf904462aa78078528932a7d5b4f37f.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6f10bf9232512f04ce496c1e6ce114b4e201be41b0121fec6ad067936b423562.png ../_images/f48723c79bb6b1979266aa01fcce09093611b3b267931033d15cc52910dde3a8.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e5a5d878c71a26871ff0168012b1a41c18fb91fb9f34f1d196aecc8c10b11c1c.png ../_images/b3e7d86d259bbbf6333be41d374b9430750e124d5cfdee5ff5ae654e7e972f96.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/42dfd2fa5e539ade595cd29c5ad5d1765068ae9a43ccd231d29ecb51a0733fba.png ../_images/58ab24b77bcdb897335aef617cbcffca1ac71a350895948bd63d40915cb83990.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e84b45092709e0503935af4628f1a82306a599969ec867656d763fb9b14d9513.png ../_images/7961ea2cb9bdcf46f874469343a1ae3aedaf0bb03515f39aed4c5f6302139508.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2032d4414dcfe2b0e4f80ba930d788ba157014e16dca6a62ce5fce923e1388e1.png ../_images/341c57249ff94f57e38bb577d1ef51123d90e5395056aa18cabc012784d1b8e2.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c749985cc04323d700d665f84e0b0ea1da19312cd6f17873c42509e1ab5faf68.png ../_images/3eb3836f1c9112b422d031a9029e22f5ef14a61a9675022cfb77fd49dbd6e0e2.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/35f60586a441762073fe0982ebb96c0021f672e644f389bcaf92b13d15194184.png ../_images/43e9b1840438c26f11c382c90adc3f00af08d7cbb9b4454bf070041286a5f850.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b6408831d0780f5ee976ade310750fa1f3b3fe8b8886eb4292cf72aa25d6f09d.png ../_images/63746f7420d467cca4d800583a64b1cf414617af72b0b462f57c123443ddd39b.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1210a38fdad401880f68832a22e9328bc1ad71e82be83c2bc08692d6a369bc42.png ../_images/38a2405afe5c163de8363375a467c0c44e3a5e6b43ed2cba4121c597223f4f57.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/86a85eacde21e9ffe014e162e935d5b73d17b3494a2f7ca9cd58f4f1fd2ea8f4.png ../_images/35be9e5241a286554bd3f94aaace2a98878a929b63d691aa78bd5c920bc7be8e.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d7571a9ec1e2f4019f91f0443fdedb998b6cc96c09f95143712968d8bf10d486.png ../_images/e096e3131e15b82b15de851e9a4678d359e7bc57e34b3255385aa1a2fae54116.png