# Parameters
variable = "opottempmint"
long_name = "integral_wrt_depth_of_product_of_sea_water_density_and_potential_temperature"

opottempmint#

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 opottempmint 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/fefe9599b12900157bc707a5ae651051297b8a347b2bd06961956b54e2aaf771.png ../_images/8d65462e6e80b024de19004105691a7402740350e1c2364a55c90a8f62a95257.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5f7c4d22e7058298f0003dd05bc6eb4a3493361c304726226c682f5f187f41af.png ../_images/f0d80fcf20ff93facd6e237a7a164c4da73fe5fb4cb3e5fcd96170c39735dc17.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c84e41431ecab3f0480943471efaf950bcac9830522ba2ae42e4b3bef623b50c.png ../_images/b27aa11a7e63edd8e35ad106d1fae7d0fc3a5c0d718c709fb49d8f58b5f7d33a.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dc66bde0765d7601148b341b395373019b5d3b6a0e8f046db2680377cebfe50b.png ../_images/171c7f051700dd88de1efe9819e33240406d0fb364f0a527c765122e8f16a927.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2e2efda349007548df3403be63cf923b306a986d39bdc7e753ac1f965870346b.png ../_images/da655d69c3085a7377fa74ab683d404fe49305973889646b24a3a07cf5d9b431.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/882d3923f5e593a467bf1d54a11db790e6ff7d9c494c551f81ca0a6bcc790b65.png ../_images/57feb8bfd3b408c62eb486d457fc935d3a9944b3d6bf0e07624f8acd52502cfc.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0e37f270b00e3f16130e08733f0ad2ebe13a4e2b688f87fd1f6ba321fce90788.png ../_images/1eb1ee1004ff06ebebd1085bc8c5528e35c84d29fa562d33d8e67f93de00128f.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6a9122505d5bba8dade56f5401900f50a77c59f7669a9e77bc3849803eefaa4a.png ../_images/cbb0a6d4ed3d781883324c24d50b032870492d5e5b9b8ed42cdf8cfeb5a64930.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/539e220ef917c210f5a15166bb525afa1b089eaf7d630674bbf7fa489237dc11.png ../_images/3532ef50336e07feda1e13a29fff015727ea1662374fab52d08b494876b034ab.png

IndianOcean#

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

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1a425cd924c4596782357ba4f8bccf09b4a41c3bc1db903ae9a60ecc080bf5ed.png ../_images/1ad7eb5d21886ba2fba01286038045a3f36463eb08eb90f7bd1ef99a34ca8b92.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8b7b3844d94c7e3c8f4e0a13e03e9dadbe97c0c668643b703759edd9bfacf658.png ../_images/8423f2b1713ed418ca1977bf1b0f427f5ec09daf09ce70df3acfef794e7170db.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a1f85a6c0d0c62a8a49824f56daf4bb1b488e8bdadbc5b1b70d6d87d43cae6ec.png ../_images/5d7566d74d697eb9aacb2b685c7c04d083137cdb9a89e68570ae74630d26f4d9.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b3ea2502c74ffa3304722abccf3fdbc2af425d1d36b3e66551f0b90589a8c718.png ../_images/3d0dd477598ab27891c52057c93425a7e6105c7f312c45cf2dbee27c7a7b913c.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/923ffff8a6915dae96b92eaffdd0c262d0052ef906c0bd1d1c2a732f3e4c83e7.png ../_images/8f28c2c1bd710037dd15a3976758d41cd95fe3cf06a02581ceeaa90b3ac1bbf5.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/500040e532e76a138f3b0f4df1baa90a9736847b70009e97a032e22ae06a9156.png ../_images/49ce623ac2205b476196e3eb4da4df14601e9d54bfb610130bd79c53e5002ed2.png

GulfOfMexico#

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