heat_content_lprec#

# Parameters
variable = "heat_content_lprec"
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 heat_content_lprec 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/a81c6fed55ac92fd96f5785c9ff00ea5e15e3af1a9f29338a3969d3aa899c796.png _images/485d09d4b9f09d2fb4f30bf4fa7e671c65dc5e1403312f5ce42c9da8adbd068c.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/912387c8ff4366b54ee826af149708f6b6bf3b4bb5176526fde28508ae6adf2e.png _images/c88362926e1f0306ec7cc7fe790ab0895fcecb15d78bfb39293cb8ac2fe569a9.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/fcef32f79dc6d228cb03aa8ca9db6b132af8c6b8dcfcf8e173ab03d4057dc514.png _images/0285d79c83a0a4cdc80b99fdc936c6f78dc94d4603fc5a303b1f7f4780e77040.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/fcd462d08d7875dcb3a95ab51679fb5a00ffa8e6579a9ca3f8dc54b207b8901e.png _images/808bf7520dc128e9c006a96a445078db8b008b7de2852a8afc7e8d1c92619f50.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/cb778e4a53aaeda3c318b09f58c80373de57ae2d436d59aeb698ddceb4dd1971.png _images/9d83cd1a627100a659bb9af54abfc68514f824940414fb217fa18a55f49303be.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d7e15496cd0477bc19c7b9c02e38520fea0ad86712d96a395433f538fb8d9d8c.png _images/7505d53c44f15ab5a051bc6d22bfcacc96a70b59ccee416234961dbc331b961b.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/2796b10b86d4617c9cba858e3724dcd5747fe5a48cc10a62a1f2c01e8eeaee05.png _images/c5582b16c2efcbd734b08f739fff89f9ae036e54a367712113c07ccce22fb9b1.png

AtlanticOcean#

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

IndianOcean#

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

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
The history saving thread hit an unexpected error (OperationalError('database is locked')).History will not be written to the database.
_images/db7375c3c8901b6166ef167ba9302d087560d0bd0335f65708cf28dfd257c8ab.png _images/061a61f0252432c0169985a54dfa1f59a54c201f386c71df89ee5d3c482280a2.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/96b1bc7f8f1971ea51f5c3cd1de5f487067bda685fd009db3ba6989f28966a46.png _images/0cea3a879a75eb8ca612c2fe50e65e2347240a5aca77c7fb95829297b9bb59cf.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/c4068880d7b9b33ca39236750836b7d779bd9b5c2bd99392465cfcc289177bcf.png _images/1b261db620a69789d0b619e8e09d8e032c76d71e59aebc8accf60220409fc744.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/a95b5f5a815968ba2a3f6c923ce29637113da134e5f82e02fbe398d371c9588a.png _images/50fe8eeabe971e3b4fab56159addccffed15ad036bc1fdf840533d3c73fe0700.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/ff5cbade2d94778f55857ea03f1b30b2179631fa1dc49c9174a38c1897e9b4a0.png _images/01b35269408b2f7e2573060f94d32ab9428a4bcc072d9107ed3fd13ce67c7bea.png

GulfOfMexico#

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