# Parameters
variable = "prsn"
long_name = "Snowfall Flux where Ice Free Ocean over Sea"

prsn#

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 prsn 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/ca991314114aeda99842ee986da863f8a34a90b6aeac40543bf432a3ab4cf04c.png ../_images/4ae9dc0621e358b20da71be38fbe8ed050124574dcb5c3348735e309a5fe394f.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/16fa86b223b833e04d54f83ad27542cd1c9717f57e1d769bb558f62f6e8176bb.png ../_images/5f94947a5529f365a0d154234963de638873dc0504188aaddd17784fbf7e343a.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/2426707d357fd6aab6dd702990bb490e634a2cdf90cab42b78ae4770c308c2c2.png ../_images/3b2f27918ae23f7d9c7cf0f98ec6572280efbca9627b581ccfa42df62c891b6a.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/876657e73a8837e65a70f538e37a2550adf00a04d9eeb82822dfe00c48834fd4.png ../_images/aff4eedb47bd52db27010b944df00384698ca23b7b0092a4e28e2ec9c54f6d6c.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f889c600d73a54792346516ab7052b8cdc9cdd14528fa0407c024630faaddc05.png ../_images/6774939d5ef56f0801b62899f8d96dac0277f4062475370ed6844ededccbfa2a.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a4bb334efb43338af408b60ab84b2d5fd4e984786e272634c760d67db9961b4d.png ../_images/3cea9da933730f17d18c144f6abfd17e9bf0a0be51b92cd5daedb1059284d649.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/198d47199a8e0d4e3ba1907b3e386d8bfe5917de2a2463d9a38b215bbb3c60ef.png ../_images/a32f7c9951fe9b8e9a30bff3763dd3c6de2423fef336f508070929f2d5359059.png

Arctic#

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

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6caa871f3438e138d31d3dc0e46abfe7237f7da2cd3a3c57550c6368b984728c.png ../_images/173dc8f903b06dd49f77e372c0ad6e41b8157dfb2c072a0e5699489a52485828.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0a41b32461c4555ca390309f9b602c38c4416840bc3e9efb7a1717884ca5712f.png ../_images/346a21c50828c2300075f6507a0136eb9444ee31abc3c26f431ecebd0f642934.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3774b4fcc8f14304afaa6986a883933b6f3a9f2df194876b4cddb48364f469f4.png ../_images/5e43acbcbd67bff91cf8d2b50ba9652d13d850fa89ebbf5869f9634f9837d166.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/250c1ac1a0d84df3edf2167b5a260e3c85c0d67380ce0a7897085d67833edb88.png ../_images/077da1915f8f2d4e36214db87de4b9ca46854ba4f58cdb6c326dc264210e918c.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ee7ec0d144c13b8cdf86a48a49046e2c7dea4e8aa59c62e3f0205b5f2ceb5714.png ../_images/6b24f12cef73e3170356c9d09629f3cd5c4908c2487d633d0b5488d2a4246481.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/96c359f1a96988a11f19dd687180d6a552742f5407db793ce865965811b7bdd5.png ../_images/9150a07f58871547e7da5b97320971bb8051fb844047ae9fb8c9dbe3da297e22.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/c00f0c9292a8fd370b58dae5a171a1094c1d55e4b29a04c6a3bffee2c882ebc8.png ../_images/31e17afd8ffd44f8917f86ccfe5f5be13b21873f9f804f4bec0171738061c8ba.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/031277b29deead45a76430221da2a804904ea1af1acf1ca5b0d907d0fb7ad1ed.png ../_images/ebe25f01a8996fc044eef9c0c4ca3bc2de422c74c7fd23f8a55e95580f382191.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/882dd47587d924f393537ac1f3be4e85436c881df63de302310d9b163b5d5f2f.png ../_images/b4cabbf525c4b543f02eaf3e7d6c63aee0170bad338ec2651d191f88315b238e.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a034058a5fbc875d40ebc274955d3887250e5f29deb39561f882a2c8d3338c5d.png ../_images/4f1907c0dad7990998b77cbfb2eef4a1215504f17aafb06e7bd02229e5a57bfb.png