# 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/8ec195cbca3bb9f5f34e401e641638a4f4ef864defa20483c65769b89d4242b6.png ../_images/53cd12cdf0f19a0b1136f94f263a8aaf5b9a47a44047f5b9340a3c0531daa6e2.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e0fe994453a48a24ca567a541337f5ddd4d516088ae0d1235500bc869580ab5e.png ../_images/93e3deb8bae4333bb0d3ee5f54888e394d0ecbe3f51db07e565ab5ff4c8c8041.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/ff418e81e83b55d5ef5a04b0d85d8330110a6208fdec3ed4677c55ffdbd569da.png ../_images/6219c31a05d23928f6717deb1dc1a284e49dd9ccfa0f34bc824162c374b9ae01.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/14882f3778d2e82c0139d0689528574ee26a888ec2ffbfde078a530323d8c03c.png ../_images/c474faaa0ac73561b8ba04eb10b4781222f90f476e59b1126e2b6ce59ce07667.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/5a5af12df43ee2b70475e45f22f6da1f451bcb9399cb5a4b47dcb0648f2a619b.png ../_images/1d7d6a9dc84bad62cab295e4ae290ae5796934c0610a7a78b6ff792ca62729c3.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7c03f7af47ebe3a9a63027f4cdef03fdd71c0c36e187510f559491d20548c04f.png ../_images/6a2532b2e4ee2962924ff31a8103ea4c59b5edb30c18d2e90b153605d4663bd3.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/d3c0be38433f9633b18f3f0d128b4814e2ce475855d761930215f35f1e4b50cb.png ../_images/92a497be6aa1c117dbd177c19661fe1287d8fe933f3f78261703b4474902f99e.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/67dcd84e83bad7b9f1d8b1fbea9377393466724ef5c4453cd40f9dfddea5f6ca.png ../_images/c173d436aedc4d27738f2f3f17d2f82304b262c4bb4a2e29ba2275e13ea0088a.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/710c8f2ad582465f70436172e27b999707eca99c1cc4551ad40905e1373683ee.png ../_images/60cfa09d6c4267346729eda821a1a331c3cf967689a73eb8885851d8c77e3d05.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/74feff049f6a5de77e6ca43405cce30b8d2e06b948395f343b0526061daa15b3.png ../_images/ce81b740d2c7b1bb6ba42ad9cf823dde307f3587b45f2de3228be90a3f697abc.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/8c721fe885a3637a60cba6656351e43dfebc903aa4d17f313d231b7ff5304722.png ../_images/56e79015a8a92373f99f72399be79d6164ad44c5b2a6e544327dd94cd3d1003a.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/886a042adb1f3b923c0d490abdf4490308109f05a4de092c7fecab87c1cf9e1f.png ../_images/0bb9e0acaa661cafa9dcbe98f3f120007ce5d3a1c8e01fc8636c443ccc74b6a4.png

LabSea#

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

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/18411a9490d191a272ce0cd630181b4ec24a845ad6662190fc9d347b2bc19ee1.png ../_images/3a968dcd56ed15e34ffdf0d57ed5e9b66ec7b7a565ce810db13d3e8a585421db.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7bf7cb790a1cc1315d112c7ef29f9f017412a589c6af832c88abb5828e999d35.png ../_images/bb501eecaf18c76ee492d4e7c9cfecf15bc14d0849a51f8e5a5ddce2bd76e59d.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/27ee61133fd10ed9a00f7d9028846f56e715ed6271dc9b91aaf597ebd7be132c.png ../_images/0ae1acb0ca25ffa9a98b9d53ee823f9fe743263c94ff1ec1d24d69f877d29a3e.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/70ab351f20f5703a946782e4bba516b6c922be68dff895dbf7a982a15c92046f.png ../_images/37fd9cac31cac88067213a20b6e89cb79e7221a79204c11ec4b5ea2a291353d2.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/7723ddbd23daa2e660a60c60ac6cc8b93086e33cfa44eb5e949df00bf718af55.png ../_images/05aaddfdc6e1f226eb054898c1f0c7a3f5bf660644c11a16b0560b3c3c6b6815.png