# Parameters
variable = "wfo"
long_name = "Water Flux Into Sea Water"

wfo#

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 wfo 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/7dd5a7c04ac591221ad343e50b3eddbf21e61f8de2a0da76fb3655e459df05a5.png ../_images/61fa80ecdbacde36c0f7ab644a01a212297bd1723ed2d17fd638b7f0b6b19629.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4bcd3fb5760530042912d97c66df1c43b4ad35339a513baead2c8f8406560c0e.png ../_images/8a354c116bbfe8b68a290b47e191ec4d47661be9418f914bf9bd11787c0553ea.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9f8b0e54823aadda92f354805ac6e4fd0c79e29edb472c76460ba431da23447e.png ../_images/5b698fc769950b974779c9230eb38e3814c2902597c50c79c9de29dbc2d5a80f.png

BlackSea#

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

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/0a9fcd0a8ef144f5e09b5094222134a0862850b3715fe6c1c4161ef96cb992ae.png ../_images/5dcf7f94a3ec40b647800d2d40a357c921acffb885577d1f93815e60fcb320d6.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3c5ed53aeb97be1ad73cd71e38fcd3e1b9316fb928557b752089770c0651d750.png ../_images/554f7813afc2cb6449f0ae59769ac030bb3da41833f8a52ad6fba28e562f0e9c.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/72ee8ab09ed881cc3dc827be62aa2f9c36a4f6829a02d55d2ef63c40fcccc91d.png ../_images/812567caa00ab3856876e748be4be4493dbc2c29d6c227fe24f68072a9b1be35.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8107d65b4e83e0fcc838242b8ee29fcf87f1a3ff85e54cedb7b5c9b59a2d7cac.png ../_images/2c045ec2c60025bd4648a36d6a83df7f6a9fd040c33faac3d7d434521d5825c9.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a71666f2f0a188d64fb957a4d815755208c06b7029f7667449ee55d7e1c0e496.png ../_images/d0d20a8b5dbc68e0f35eab4072435aa070feb6b009af0eaeb8d4aa1f6db41978.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b98f806e1c5d6622c6cd65d0750c763d2b148becbeb8f6f70a3d6d314f23c1ec.png ../_images/8ea35eb44dd54409d45e7f4c8d0fbf7c99b0becaf486b5bca3d90d025ac6b4dc.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d9029a28b48d337bf13f5b01d72360aec5bab49c40d9c062c6a7cab8a6175df6.png ../_images/405ba984195260b41e137fd9594bc279f4801b3819648aae396090dfbe986104.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/373822dba0edbdef7a08eb1a689fb829c4443c2754b8cff6743c901e4a21b36f.png ../_images/1133df1aed4a79538627a57ccb2fc6ac1bcadc68de4f4725e1f4a6b6718341f6.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a35ebb1c946e01933a280e0f38d3c7ae876061a287149dc36841a7fbd0723473.png ../_images/18d97731766ffaa961534ac5d1a36ba97c36168d85e427ddbeba0d8b828aa3cc.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6e1781ce4d54e64926e19e206ffc2bd8d1bf9f2be461aa70dbd3dde9eb23f53e.png ../_images/b4c29fd548071a8590beecc548a794ffb9e4d20008ad475f7c8147927b9c50a1.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6407053b3e3c0b48a2ead1e0c70b29bce010cf9887cf6a98993f69b2f3d23ba1.png ../_images/0a6995ebd9a43a561a1dd75fbfd269c572852305f75ee718da96db171748a57b.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/6f7757dd4645d84fd38394417ad18d0196315f4f367d756814d7d389af2009ee.png ../_images/f62d208146fe74334be045e2b9e62e9c2a4c37d638356e20aad4bed08abc79dc.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e402bcbf7d2af1e2b3c95ac7126fa6c0ef5584ca23f7497b5ff72540c6a16638.png ../_images/d03c2c8d1585a75862d4ae082bafcf03edba13d0edb69b929c31b13f6b10488c.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/9edd8b98c9fe553b15b80340ee79f9dadeecb7e43694bf8ab278b512d001ca1d.png ../_images/ef4e0be1825ea769909a50d1686cfce486e122632faf6431e9a1ce134db025ee.png