# 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/f504cc72a388d8639da66da97bb490e2ee4c87e0837c432cf965aa8ce2b3b9f8.png ../_images/09acb1bec33e47e902b8e8ca7fe1b5038b6bfe63b45b055e8b04049f07239eab.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/cc938c315b7d32e472197020f61a7f3bbcf2d85d8471a33e7894f3fa11a06c46.png ../_images/7a8dc43738837713bf063e028c0151433b926468f2adc313ba56193ef56aedba.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1704a1630edb549bf13cb3d6e9ee55fd928f636e4f29d763e6922dc369b3f20b.png ../_images/872e774fda6173557b4bdae190653294f537c54d460f4663cc8c8211c78ccbb4.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5a97e14650504e205b8c838772fca395bb1eef2f0f39f9944154b10bdcc7e160.png ../_images/c17c7d4749a7b651922616fdbbf47001e054b37ec9d62b695df2bf6b08f73855.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/f714c91643de95385d056c080e2d2b78190b7488bcca2730ed4407f5fb8df48e.png ../_images/98c3030448fe937fc536bd2bf33e6d2144763dabba799b0b8cb6941c3e4d14f8.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a398f81ddcb75c5e30d047a20faa32251048555055691bed69d15a882579cf40.png ../_images/b261ce247f6e0bad4329a45b85676abd92f19ceec0e34a9f639d9938b40a11b5.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/870266152dd7dc19b57efc650dee8f6f2fd59d91fdfc9be293b5fed6dbeac7be.png ../_images/bed8f35e9e779d038f0254134c85b8eda13e42ed01963c60fbd94906cc35fdfc.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/49d5ad3ed8e140dc1ec431798781dfc0f8407f234273937747fd79fddb5506a8.png ../_images/3ef7bf7b72d63c454e5980dba61eba501a1cce22420a72d59cafcca661e7ac0f.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ede2ca737a7f4793a9455262ccdaea071504cd651aab70c899790cc83d3a007f.png ../_images/31787dbf5889d7d3e0878e3b50d822c1beda9dec4f965f61105eb537132ea176.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/32ffb68de091977c59d5ae7ac76d1e7d5dc6243f1eb086417b6a91fa9eb27c4c.png ../_images/02c7d55cd5432ccd0eba004e11a7ba86558d19ee43e0bb6dc7eefd0d049b449e.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/82088201ebcc4da39cc676e8bd005942c787ddc89ab2fc6860803bf2b2fec66e.png ../_images/89d1aa6dc3daae1a688333922469670dcdfccae52d679e9e3c799fc9c077129c.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d541c0a41ecddee789d22f053edd96122975aa5d7a2fbdf9989ea3b7c4174c11.png ../_images/24d84ea08f4fa347955744615d62641ce3e6d5caaafe3e1a4f112f72ab82950d.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/20d7a858061c0389af58caff8f681bca0925715fb593be86fd838e2f5c9d9c20.png ../_images/3c1d3b710c5a91cd2013757a4d5b2e5f36ffff273f27640fdacba93150cefb43.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/79843bfd16226fec0828de7bbc4f82bf9e69d50d9925fe99409f705cdf1baa1c.png ../_images/e4dde4b0796de9331cc9684384ff92dc4a49730f5781d38cf18ed02f5cd6cade.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b5a75b1fd8edaa799cf6a81e521812b812adc3f2e03583bc6c6204b22d244a0a.png ../_images/5eda50692ebc48ecd2590893dafc51a71b76b623415d47cc1a0e2f4962461514.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fc86ad7a741ec149e4009ed47418d733b1b3e05e5b924c7bdbec90a9d26f84c7.png ../_images/65f6a027b8b8e004ca104c63b64ce63c99004685758da866d036d304edb57cd8.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/015ab9fb33b4f79358816cadf3cf0a0d50cb068ad9b7baa03f29dcc72a0d8b43.png ../_images/586aa94e829e73394ea26afca776410bd947d959544a0c5ff83980cabca87aaf.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/13b33f6b2daedb30b8a12bf8839154b085907011daac9fc16086f4b4f25cf83d.png ../_images/6d9a41694c80d9aed9ecb624ffbf75d8b4d2e8f0e7a264ebf0cd8e62924d7e05.png