# Parameters
variable = "heat_content_fprec"
long_name = "Heat content (relative to 0degC) of frozen prec entering ocean"

heat_content_fprec#

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_fprec 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/c83c24a289fd20c59b3a9b07e1528673935963720844fcbcac47dbca8fec93d5.png ../_images/2862d63a24a50fb7c7f95a924eab70ff3896c9646c2459ce78e4b06dbe814121.png

PersianGulf#

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

RedSea#

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

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3b35ce972c4ea95ee4e6dbd6d09a96e3c8825a6c4db933e429528b7096dc49c8.png ../_images/5b10b9ceab0311cd8ab8b8c8adbdb58c752da511cb336a3d9b38e26c5532be7a.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/86442af63274d43ac2c8a4d2769a46da1b52c0680ec5050139f6ed3df67599e7.png ../_images/060c7ab2af3f7f729f9e2f98a0cf9826c0c8a169742657a95fc6515b9f916eeb.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eeb7c115e04a38c13a331dd358ca35a13e27b45cd9542bc516d778a3634ba628.png ../_images/62a9777a642b606e77c22b70f63a0503351d83f2679dcdcaacabafe99dbf917c.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7b7d80f259fbf86002f271671393122de9bb6be659121a4ea9d394b227fc2463.png ../_images/1b1a8d5790524eb89d29c1a2a1ed8f2c5160202585a8491a088fb649842f23d0.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7550ee64a34898e93234d1aadb8e63d971476c7d5d55bddddc4cf23d4836acd7.png ../_images/06bd99f971176c857cd0e87651c0d30aec6f000e796b84dd00befb16f6e08d4d.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e5fab8d0d917e8bb5ffeac58548220d60dceac2dfafda1e142cd6aa3c566afae.png ../_images/8e01d0f19dbbf64f371f446d28dd36e240b8fe7d587ac74572d77dec6d707b93.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dd794690930f1d64eed86a5e2460543839c9a261870ac43ca505e17e1abf9484.png ../_images/181edf26863549739767dd97438a1fa16afa10cd0fa2cab8e530394d788d79f9.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/042d04ebd29aed9ec5d920d6f92240fe3e4c4ab0ee75628fd807bd32e09aae52.png ../_images/50f6dcadba45c419fc10dc85b07ee10109d096a8c4d15190ed3988015318bc14.png

BaffinBay#

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

Maritime#

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

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/40bf28a17304acb4e09466d63dee73f700fc32c73e82671ad9915a000d56b451.png ../_images/8a58ea60897c06f3e0f4b7718cb53d70c1e5c23e5a6a5c42a9bda9907bd8b9ba.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e4a4bce04099ff080c9ba2e17b77a2bbc62584645b8e2752167ee2c6a53b08f6.png ../_images/1043fb2d8338e927d8e1eda13878faa5d1d33978944c71c0796a471d7d89d728.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/88c9f6a24e400ca672390eecc853c2f608c2f79b883652f9b961e44cee15356e.png ../_images/97ab9412a6c3d2f0da02e7a193d0a91f04b3180a9744fd7937aea31ca8fcb9b5.png