# 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/7c67b6cba49c0754192afb49c1e259f19dc326994623241404b57f3d70c15f53.png ../_images/934234e97c26bb2e6dbe23237c2798c0be847d9e9dc53a0d9c6cabc9a3b03ec6.png

PersianGulf#

reg = 'PersianGulf'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e28a3838d085ad8c4699bcf6f78fb541a0b7da780402d13746d46663f9286b6d.png ../_images/c25a3d62e1255225ff9ff17c54d2014a3b768b1896facbe49dd93f8873131914.png

RedSea#

reg = 'RedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/a3f28507da34f342289c4a3310e4a07e99305cb57da6d6e2ad556fe1beb7a594.png ../_images/2140d89f7734320b7719c850520ab93976f05d4b479380487d55d5d7f654665a.png

BlackSea#

reg = 'BlackSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/e4be0062b33e72d4f1db12b730da8bb6ea0f7f6d05a8a3afe8727baa506e5ea0.png ../_images/12fc3db885cbf0286d76a35a6c0365f5f6075214edf40f8e7c9d691faa7a1a85.png

MedSea#

reg = 'MedSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3bec5f3bc355b24395552daa92412a9f56cc97a9dfb9288de637eea55c9e2b30.png ../_images/1b082126b7ded3af857be4780c31ef86dc941f9e155bae92c7a34c43e47ac392.png

BalticSea#

reg = 'BalticSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b414b4340152f7daa17ecf0631aa2d7068dca340e9b451738619e80a2d849abb.png ../_images/7cfc3525901f0b730a7bf98966c743aefa1f0504b98bb43f01a632d8d83b6cbb.png

HudsonBay#

reg = 'HudsonBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/93613ed9d5029e952edbfe3c1f63f6019f8050e1a36b7863e42e21b78ffcb46b.png ../_images/6ad260ed5450a77df252a7df0f2f1858ec57e4916f77d35c19e14e90f2e30f51.png

Arctic#

reg = 'Arctic'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/548851598c0eec1eea01210fc517dd1a4cc2db15a11690481768aeea4164a1d2.png ../_images/f645710d7bc2a8f1a0e29fef31f2d786afae5d4eb037c7fa427b649b213ace12.png

PacificOcean#

reg = 'PacificOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/86c492d69143d4a40cb85408dd91feab2527c7000e7bca40291eda1b4422496d.png ../_images/66b07a146752bb28f75ed29689de5a26729824e7e8e50445c08d1bbc4350c208.png

AtlanticOcean#

reg = 'AtlanticOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/1dcc88aa0d3acc23343e0a789494205674c9c368c7f572fa389a55f83b8e2a0f.png ../_images/c490eb00785b2930982064d2f90e69fb2c90cc634f5609abdb6812f670ca43dc.png

IndianOcean#

reg = 'IndianOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/eca278dec684b145846f3fb08070d00b803be1ed5ecfce725663d1b130d5a715.png ../_images/5c158013416777239cc1da2f57dc32aac47e9fb3ffe9c5bc854dc45f69f6b963.png

SouthernOcean#

reg = 'SouthernOcean'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4745f2fb3edcfaf30ecbd491ae1fe3750ceb0ce951773b8c501ed6879996e1f1.png ../_images/da950ec1d51d4b63c76ac1e2c09ad98cf326978335815716456b1a734b9bf22d.png

LabSea#

reg = 'LabSea'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/fe4b3db05de41fea975fe2d8abd115342de469d86db9360c2cd92a25687b1598.png ../_images/30f06d5777467a339ec88e6cc7cf877aae3c14bd089636fd80b13abde88f6798.png

BaffinBay#

reg = 'BaffinBay'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/3b6aa6c06e88066e599528f71e75aaddebd4416825342dcade0c8b20af56d28c.png ../_images/667c51eb6b16a25876a7874ba34e817b4734406d82b482a8923f974784595d9a.png

Maritime#

reg = 'Maritime'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b609808d2d5936b2ff47d5c69a75a5da7f4db0fa01e2f072b6b67b4ced4bef3b.png ../_images/0e4f1d85dcbf783552792737793a25e0dc6ab7c0804677d251e3f8568113690c.png

SouthernOcean60S#

reg = 'SouthernOcean60S'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/150f751bffd3a5470fa346c2d7667b3e3b46513755ebc5e9b965a082ec59ae5a.png ../_images/8b686fcc10a35ede209fa7bdcac71d88b45b113a5bb8f75ec59b0b2e483e0d98.png

EGreenlandIceland#

reg = 'EGreenlandIceland'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/b309b8e5b050612f38426f3317e9acea9815878a537f72cd5c86c27ec88b37f1.png ../_images/0b61ba7ce64f066fbfa37fb3270cee18471c67f0b00da55f31eb8e994ea40c18.png

GulfOfMexico#

reg = 'GulfOfMexico'
ts_plot(variable, ds, fs, label, reg = reg)
../_images/4973148e636007c512fd833665d55d7be3dca084ff29f1635e4b2bc0fdc81a49.png ../_images/c7c7084fa37f38f2d3f7fc06405e7f834cb4ebc5780965e2d1904cfa8656f542.png