tos_min#

# Parameters
variable = "tos_min"
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 tos_min 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/ea089a1bfb69e3f00f6995f513db4b35750842ad29079c3f2ef2f591385e1837.png

PersianGulf#

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

RedSea#

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

BlackSea#

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

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/7061cc52a7474e48a74bca7bf0ef33a96ba4898341c475f413eb7c479d28a7be.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/00fdfa922c7c4441ba337a2718d7e3df0dab9c0afcb45632e493efb5b2ff16b6.png

Arctic#

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

PacificOcean#

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

AtlanticOcean#

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

IndianOcean#

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

SouthernOcean#

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

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/8880795b8760b560f8a5ca6c0b3f4f45b04f6977eec38abe362a8688acb21a52.png

Maritime#

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

SouthernOcean60S#

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

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/8579b201810d0b56162804eff125e9f92d356feef27c4886b523732fd7e7b08a.png

GulfOfMexico#

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