# 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))
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/e069b30a7e6a2278fc6dedddb4ad548c9038bd17944d28916bf15c29e36365c6.png ../_images/27a03f84e3bb93eeedc3c4d5e6c65c6efdd8140e98d060ca109eb44874a7c857.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6f0383ba646463a0a6a0e4327b0cff3d8156797a52d83b4eb0273fc000c48ae4.png ../_images/6f7736d27f2afdf2933b27cc4713c799c1068ac02c6836c965807d936b7d9d23.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/dca4041f9ce2e89264470fd1476f91246b0fbe76978ae7aabc4a7bb094d2a4c6.png ../_images/2be4594cfcfe7313aba7f2c6fd9a0fa6285b52d39b708df02f5a952f0a05a12c.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/da55f3baf036b132f5067865d998c5da3fab9c64567b1f94271cbdfa34884ee6.png ../_images/beb570cb32cbb9834477b8b49d2e6e25a08ccc4e4ee96a79ded746548f33d156.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0729a88bac9b7a62d454c0eb4e0215a77700a1db6b25e5544c54e2714a7c24b2.png ../_images/1ba7ad6a3f5ad86369c9faeff079251df2eae73bdf5e80408129bd16afb432f5.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ad5b3f00da7a08619ba81955f9a90c69b98a1724bc1cd5bf386c9063ab16b064.png ../_images/6b69fd799193541320140148ce474fc6de4f0898bbd17f2250ac88a658470a07.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0cf6ee43360f80a89cfd7ff021f1a891bf3d64dbcb92cc01baf932690a00a9f8.png ../_images/56e61311e3b70b103b757624ccfe473e57d70dec093fb53c0aa96366664465ca.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/25a9b8f1a5f76efd016a4dafe2443a8d97844415f1a22946f6991786905205e9.png ../_images/54c00c57e4950f7c31875bc7992f5ae51ba8baf5da7ee906fbddb1ebf190d10e.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/48fcc7b384a50ea11db7b85816adedb105f8a56d4916cb23064d9369f160613c.png ../_images/f9c3737f68c11605b619d2dc9c179fe6bd57577353fce9913b1f8a060ad1da75.png

AtlanticOcean#

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

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ab802311531b943fd5e15f6ac924fff86a19c49486fc0bf22543722c74020912.png ../_images/e0430659a6b71cb731203c5c383d973de5a8fbb74194170310493cd37e690058.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5c5c55926fa39f006772944f2db618f826509161c732a8be8e76fac2fbffd5e4.png ../_images/9ae90443294d1add93b297c17b58d63885b9192efc404eaa622758c9dd801bc7.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/be3d4fcec21e363d3fa3df736106335b82f533df5a26b0a7f893a4b5456e3b37.png ../_images/c278047f77bcf26eec88ac455b84593e284739ecbdb000d97d90f6ed73544176.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1a45d2f6b902c43848648ef568310203bc4b51c0fe05f01039b3057582da5e27.png ../_images/8454f2113114b2f9ecce7d880b446beaf3a50bf1d19bd78e337d4e905b0f964c.png

Maritime#

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

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/27f49aecebe79b3960c7ecf033ced06de14fa8d241f17d7cb202adf63b477305.png ../_images/d2d19b270380c287f75126ac62d9e4533894a69624817dc48fd1dd185b65ebbd.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/14b8c356ac648fa4ead5390875fbe4fd3c26ac49f115ff8404548c9378767200.png ../_images/18497b467b80c5558feee0723887ae3536f839b8f8ff11b2ade78a709f745e23.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a635b5c66654f1ce6d72eac8e310e191a01f605d6aca1f4d7d0358a34b8bb6c7.png ../_images/921215976d48df8a967ba72f67ebb415dd1de98272ff8bd33b753c33e1b231f8.png