# Parameters
variable = "prlq"
long_name = "Rainfall Flux where Ice Free Ocean over Sea"

prlq#

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 prlq 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/373d404413b62d902fbb24a6f6da17c6dfe2a0feb9832f6b73bdc1345d736326.png ../_images/05fb6010d12670e50f279a3f4ef2aab38547f70fd9cc439155a2b96ae7843b1b.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/103e9ae8bf572d4f35b238e1faac7eabc71e5062d4436104b5e1ab9754927acf.png ../_images/dade951e268b9195c0a772e257d46842ade881d7603c747598ac9624cc23c741.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/93061256841a471f953f7569466f0c5dd8d88c6b5ee0b738bfba234de1271f44.png ../_images/ceef16a833b7bae0c08caaca1d733b47188ce02ed00dfe48d45054da2e45687b.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5b4434cd79e7fbe3b81840aceba90e42d503bff7d666424e8721b5c6719dc248.png ../_images/a58526c85e14902589ccf1cb9c3f8778c7d01f485fcdbee285bdbb4a8284f25a.png

MedSea#

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

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b265fbd2b5f84cdb4c4de21c4d69c1cd4b16fcabe02d8d188ba27ec974bdecd7.png ../_images/91e690c6de552d6dad9cc860a204c0c68fe4c713ee79a57df67e443d052944a2.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/863321bcfa2b74d62d461dc32c4fd26da69296bdc70b66aa623224176a37bdaf.png ../_images/b177ec2dd71e1db8c3917c7985b99e6b449570ec39dff57ed185946918868128.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/79fbf8bf6c30145c8ab1745226c643a86b009bb11ed5c42d7509367a33f13bc8.png ../_images/5faa7101fc047f72652db6c0e1d68cc97aa366d2ca216fc3ac0ec5c3db0a11d6.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5da45a419a005b54886ee91c6ea12a88b51e0b08a7c7428389aeea11809b5116.png ../_images/8de8f342c5c8571cdf53c039b5f9ab7615ecf79a648d4ce8444d1ee380d1b566.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6296113b515e0b163a0f246fe387c48cec765b45cb48d5c43e8a96d66b7d7b2a.png ../_images/71b04ffc841cf261a18cd5389f11e4a349e82ef6071298e50358abed548aba69.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/349b0185f0ae8a893f936a3967c442dc1112645a698b07955d8c07fa938db452.png ../_images/9f84db7594083ec019d8e0245f90ef3d60da12394780ef7266a5aae1777fd61a.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8db10bcfbd42aa040b8f83f7f74732733a0afaa67bbe165e6e839572414d1379.png ../_images/88913089017318ce95a6fa46e6fdfe789c5c727f33eb125448c6e2b9f139c8ce.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/03fde36d510b6b91515f1aceea8d69eaaaa4521eb968a4d953fa2a9ace694578.png ../_images/d0bbb81e2d5c414f495db9cb2e6750c0fcf0d02dccf82ff08fa34ff5cd215c93.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0bdf02be3b41465cddfa03bcf0b9ac1357fd99b97dc768616589e8def3496d83.png ../_images/6e5defb008e278fd637ee1d74261b88a47931dd688b114a01f55a2e171dac893.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/527424b12870054a15fedd82edfb6b66cd5cdf79923690352979ebbb03897850.png ../_images/5ecc4f03fabc18d409f55fa1e6d7d7f30293acd9c1ad8c44ca13fcdaa33b877c.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/709e0db2170467a62e1e05062f70b83ac9200ea8fc55936f949f5105fcbd70eb.png ../_images/f6a03fb0bc92e56ee1e06e93af766864d1e70931c5534873d49db269682aa6db.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/388295bfaa4bd1b21e3e8ee05082a5ae199d68f2c6a60e5bd7e5b6f7785435e6.png ../_images/cbd7ca54c0c6536cdef63ffbbd019a6b271ec828e90d126ad37bd8c301a0ab74.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a009ba148585ad4f191879a9a1326d71623b599ce01895ef796d584b8d35d127.png ../_images/96a31e23f326f17ca0d8790d612f2b4fc4e8138051a141fc2cf3ef270c3a84eb.png