prsn#

# Parameters
variable = "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
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/bf447b11348b888c556e4a7b5093e5ff584add230a5ef014add5c179a35e1c0d.png _images/e68886b08bb4bd8240bf3a737af9b4e17905109796cb244c4e3fe116ba2caedf.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
_images/173563a4382ed625d2ec10f494f9bc3ec936ee595bcec91416b591f0ae594efd.png _images/79142de7e93f47ec259bbad56d8c249521f7848cf59147c93018763c01493a05.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/02ee4392f36dcec69c547d72ecdeeec763279220890c7d7152153a5d89c8e0dc.png _images/9ba860675b6f2dd08efc3b038d14345d65cb8327c2afeee6778de1ee407e1300.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/a8aee3f980ae3621254988b64e48cadbc3544ad5efbe0075d5b26360c0defb8d.png _images/3ae4e37c840b36ae104bb6d1d2e2c0c86c4e856c5961d6ffd771d58627ebad1c.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/5389a11847a875c9153844824209f7d9b20befe5a589997c33c7fe91eddbf92f.png _images/7d07f92033e79b05224340c92861b6757e7684d29b06aff69c8f5e62b487bb52.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/324829176f2c29ddca75e08738a518476a7f1bdee27d4e015cfffbc7fae54f91.png _images/0878431aa8b3919290f8d3874154320a22211677dd71a61a094b63cbf1b6e10c.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/ad6bd74694d07f328f5dd2f20f87ff3a090a03eb085402adb43c998510968e28.png _images/3c256d08a46e0af92ccd2df802c9f199638554a86f61411687138a55c9bcfa56.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
_images/183566e7d5dc3ad30d37f820d54c6069113099187fc50fa51200958a9383cd88.png _images/a5c94a25e4ab1b893568d6cbd106e4b76f785931f4d00e24a47891e1660d98d8.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/c527418cf68d00ccc027059bb52cae97163175ca4d68787c7115ac5c9132a1ec.png _images/37f636c3e075c49dfa44a597eb4d8dbffe2c4956c1989d074abbe46cfdecc76a.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/4cd02617838f32fab6a91b9acef71b8707c1f16dc323910f2f346772b12b195d.png _images/8e66bc50e01f83a9f97fe46cf56fc59442c97ebe6a8021cbc4a0c520ecb40845.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/37683e0535de33b937e1b2694b6bd546e707cddedfd39a0d1e57f21e7360ff55.png _images/0c82d82df91ade52ea25ee7a8b73a2e42f11b31de6d36bb5f72c67ce0e0c397d.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
_images/331a9ffbc5592992dc49ea418df566514c4cc3a6ef4788acba059e277086608e.png _images/0da9bae387ba4d96a4d0f0572ae0db98cc3c886de6593aa1e37d2ba46f3a7f2a.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
_images/f24f58b7ccd9f29fa0b2d9ac21c5933063757c0646a6f8a61909fd04676a4161.png _images/9627d343239dfe010870dc46427e923088ad8c011035e679daab2ae4eb2dbac6.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
_images/9a46111ea0e0fc71c8c7224fd005b1425bc24b79ef53bee1e49b441685df0cfc.png _images/3e30e9244b9befe9ef2a08c5ce7a80d3902e8b5d222f37c57861f9e691694985.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
_images/018510e1802244c4bbbf27b1a382cf3a0c4707742452a2520baf5b435f014800.png _images/49d53995044b3405ad67cc00913e76861b798181bdd7271bf8c270ada81f4092.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
_images/19526bf71ec282e2da81c73379f8b75cade1793641bd272ce5d35fe63a819c73.png _images/e0f7ab5acc32396535bb251319753734977927d8b0e8215331cc354781db74a5.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
_images/15e324fd871efab7fffb3a91b60bba2529211d515f63cc1762df3d1e952e6250.png _images/f0204505e8c1a6d5fe587ef6892b03d13ce7b4b70aa5608af62f75367c1c3a40.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
_images/849c0c599293ae0562331d724e52f3c87a958fd9084195bb63c040758aec6065.png _images/18f06b5895258e9a9697f9099b0b2166802175b374951b782abdbf9cda3dcb71.png