"Wrapped for dask" TEOS-10 / Gibbs SeaWater (GSW) Oceanographic Toolbox?

Hello PANGEO ocean folks,

I anyone aware of an effort or a repo of the GSW toolbox (already wrapped from C) that has been wrapped for “lazy” use with Dask and is “xarray ready”?

I believe Eric Firing et al wrapped the C code of the TEOS-10 GSW toolbox (?) by McDougall, T.J. and P.M. Barker, 2011? http://www.teos-10.org/software.htm

@rabernat & @ocefpaf appear to have some association with the GSW repos?

To date my approach has been very limited - individual plots of things like PV sections where the huge model output is subsetted plot-by-plot using xarray/dask and then handing off single numpy, in-memory calculations to stock GSW-python. “xarray ready” GSW would be useful? :thinking:

1 Like

It is pretty simply to do with xarray.apply_ufunc.

import gsw
import xarray as xr
import numpy as np
import dask.array as dsa

# define some input data
shape = (100, 1000)
chunks = (100, 200)
sp = xr.DataArray(dsa.full(shape, 35., chunks=chunks), dims=['time', 'depth'])
p = xr.DataArray(np.arange(shape[1]), dims=['depth'])
lon = 0
lat = 45

# lazily apply gsw function
sa = xr.apply_ufunc(gsw.SA_from_SP, sp, p, lon, lat,
                    dask='parallelized', output_dtypes=[sp.dtype])

# compute in parallel with dask
sa.compute()

A further step to make this even easier would be to have gsw implement NEP 18 and accept dask or xarray arrays as inputs. This would require some changes to gsw itself.

1 Like

Thanks Ryan, very helpful.

I was looking at wrapping with “.apply_ufunc” yesterday after some advice from @dougiesquire.