prlq#

# Parameters
variable = "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
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/22473c686b653dee1f89fc08796ef10aad9a1d0c34a4ff73f3bf990d8682752b.png _images/c5ef840c41de4139aa6f4a1bb72b2b427f69372fa0fee3b7c4992c826f040038.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/4ee0eff599d48de96a4d0a410e73f7f84f9c264f3269bb88a012a47a4879fef8.png _images/2696c98b129ee6c04687b00be4af42121f0ebeecc6ac77a02c572649c250f0f3.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/6dbc7ed2b129c1cbb28cad8a05116e0abd9b4e03988fdf68016832dd2adfac9a.png _images/7238da5b32667718fe3865ba9b107fb2a87e9bf66918fbaf9e7bd1cb485950d4.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/b29d6126b5b8664d26e4dae9f83e94c41c5276c1c0f3ea0abbf7a98cdf36bcb5.png _images/58d571cb1fa26f779af03e4415d3ec12bdd7a950afe474866509d3cf2494fba0.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/2470f48bc9a2da765b68232e35c018f31e70a78c3662b6a66ebef7676b040848.png _images/42e034682a28f5c111ebb58acd2efd10af420d88a30fbeae1a0993957fc02f31.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/8f2a1629033a3c9376b8d1a2221b73c079cb1f8a9d86a44dbf911df84cbc5dc7.png _images/da597eda891ac29ab992b89372e512a5e6f2b12f87c0817f9cccb2d48e5a4bfe.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/5897bdf211170af2da3b94be99c07f6be73e1e7551810725898b1a33d7b6887d.png _images/7c5c321d57829438333a4ad747a86b2ce059e01b626ce2c1676ad218e61c08b8.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/7e14b4dad9dda49786146f991ffdd88f6bb46fa4648bb5bff15e5e4367a3c3ec.png _images/6993b91444a3dfa2462f436c8a4fa149f9af5452200db6035a096560cd2ee131.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/187849cf7d9d38f1ab1e4c9268676f9709ab7c0e75696ea91b5f6f97f0ac8637.png _images/33f24e762679aedf531f8c2e53522066af411adc53014cb72be619643773275c.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/d6048c315c8a83ded62b8f5aac1d86cafdc91c6bdaaab55069024c6401d4b450.png _images/79ddd38bf7bf51b8f57ace778e16d6e1c29d0b736451987e5c5dcf8e04b0b3db.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/8cb0ca348c71762c61c71f6c31cbea9dbccf35d8eb3296f7a5f8e09d394cc112.png _images/a52612d5aca7cc8e41b0f59c477904835fc72c58434c6a97083a5cd87758d547.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/59189fa9d27f13a8ecadb931651242c79741c93538e13d68fef8dea33bdf5e1a.png _images/20342a1d1017ba8a4009f9b2dee3400353531967a31f4a263964b1dfbb03cab0.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/684a1bf33f2020b2cc34ed0c41405656e703188709733658815ec41b4595094e.png _images/ede22946b3a44ed644cde5c7be5151adc0a19c7a7afb85b6a7c7bc11b03f5f6d.png

Maritime#

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

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/79271cf1a54d9ab07866118f1ccc0b6c572a0898b74e86c2e97cd53b848ca262.png _images/aa0836cf75cec85a7cb7dbd168200be08511f66f11dc31f0838a0cbcdd89fb10.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/c2598c613d0b0f742282d7037a966f3a91165314374e110e90dca59128f1757c.png _images/4024ca779d0089e912364e256b4fc42a7ecef8327901ec53dabea0f5d5d76dc8.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/3e6be7c1b73272f0c456dfd2cc4581070ee3cb479a15d6105c9f33200c5f56e9.png _images/499ebc8c395eb004579458b91482f2e78ce245b68575447e621dc3def37029be.png