"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.

2 Likes

Thanks Ryan, very helpful.

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

I’m interested in how nep 18 would be done. I think it would be cool do you propose a wrapper around gsw? I guess once you’ve done it for one function its a step and repeat?

Hey @NickMortimer I have some examples where I’ve followed @rabernat 's advice above if you’re interested. In terms of changes to GSW itself are you looking at pursuing this? My possibly ignorant understanding was the core GSW developer was completely uninterested in Python.

@Thomas_Moore yep I used this to solve a number calls, when I read @rabernat comment I read NEP 18 but was struggling to workout how it would be done I think the idea would be to wrap GSW with function calls that made use of NEP 18?