# 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))
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/0c79555ab93fc3920f038d4f1e62f304c308e682b129608b04d383d2771dd436.png ../_images/d6e5a748ffdfa3e0261c0b76a5922646ff98771c4039c5615999bb405b5627ef.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a573c2ee217eb9c427985b6a41553eab8e9b11beb1663233b7162f7438e505e2.png ../_images/0cf316883ada878f908f5951b7bfb01c98945df57dc2a3947a5a9ce4bfe9a2e6.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/57951517796547cfac2f781b14f58e92b0bff10139a4b716885011afee0ee5e0.png ../_images/58492f6a25366ada739596d69313863f56d3236e11a3a907be181c59f74c230e.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fb37ffdcaa45f4c78c2512b69f1a9d3b01eaeec51eede480befb8c8be098d891.png ../_images/775b2bf6592a8970ca1cbc01de0c4848eac339dd471d4645cd4f9dffe5d77829.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4f9fe73adde5f40c5387f6c1f3949bbd84f3b26eed496c5f475007f2482db379.png ../_images/8f5c8d39591e1a14369dece3f851c1b5835f537bf3084bfae8f8c34569f38985.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/380e58c3deb9d514c3698434711a1a2edf69b1bb610e65164ee89e183079909e.png ../_images/fd0ee79ce6d1f303d49f542a8d66d0676ac42fca3cdb1c580f9f2b09f78ca323.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/89ed0663d707866528d17018c8a4e2a0d4774910f91b6ab7059d18240b7b62f5.png ../_images/f05f550608a1205f117257add2958eea09f7677bc87887e13fab681e9067c128.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5fec0b5f8900b5a685cba5e345eb652ed7d2c1ba205f60d77e43763030cb17f7.png ../_images/6bf52b9452ea0c11148f447afe016a3c6f10da173790e5272d453e5d1bca71d6.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/12555d5be945a1dbf43dea4dffde6bd37a0597ec7156c62f62d384016c484a60.png ../_images/c65172c8d2966ceb7d5dd9d7a5a25a0b16c18ec47d2125c4148f0f3f0c1bf485.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/47ea75a4a02352c9c43760b68455a45dea9787c757dfb70f8570cd345dfc7fb2.png ../_images/fa6dfb9a5440b674d7859b3698a087bc19f20c50b7a45613200b0f2dc2295aa6.png

SouthernOcean#

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

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0afd0f039fc17c99818ce54ca42b959ac9149da0fe08b130da99a0c633eaf416.png ../_images/f0845d8f5f585240f9a521408468b88e575685002f0aef801319684853acefb8.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/25ce1510b10af61d05a221a44716609c945c68d2a9d297846d5edcd94fa9e69b.png ../_images/30623d6109792042de203176f246271dd5e1130f701badd2eb6f7afc7238ea49.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/150a7bd05265162aebfcd1329be3b9be9c41de7b4b4a957e2d1581c8642f7dfd.png ../_images/de40cb2a554e719546deb9313d8128aff538c786bec60f00adce78f822f2a1bd.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/bba4c20919805b72f1dcc68083d749015d52f5cc86e424a774af8390bde41764.png ../_images/0c1324960b2f38e2e2fb31a70ee32d81bf0356748a6aa8ae539b03059da28700.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c42954c9b7bef935e7e71accf86bc447e127d2b894ac3ac4d21cacf6e29e9786.png ../_images/16ff0b56dd559de7c89a3b97ead7c35d54805d4f5429eea20f99915fb6c1aae9.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/901ac92de64bb62b00f1933a4a5517a0610d059358119794f9e9082c7a2c9699.png ../_images/a887b04feefe92061d8c829cf060ef1eb2110e7afe547134223fa8c78e4400a0.png