TEOS-10 / GSW-Python

Python implementation of TEOS-10 GSW based on ufunc wrappers of GSW-C
https://teos-10.github.io/GSW-Python
Other
147 stars 31 forks source link

Error when using xarray.DataArray and gsw.geo_strf_dyn_height with numpy < 1.23 #95

Closed rcaneill closed 2 years ago

rcaneill commented 2 years ago

When using xarray.DataArray as inputs for gsw.geo_strf_dyn_height, the result is only NaNs. Do you have any idea why this is so?

Example

import gsw
a = [0,1,2]
print(gsw.geo_strf_dyn_height(a, a, a))

Outputs

array([ 0.        , -0.27061522, -0.53269375])

Using xarray

import gsw
import xarray as xr
da = xr.DataArray([0,1,2])
print(gsw.geo_strf_dyn_height(da, da, da))

Outputs

array([nan, nan, nan])

With numpy 1.22.2 I also get a FutureWarning:

/home/romain/.cache/pypoetry/virtualenvs/gsw-xarray-NsrEXKiZ-py3.8/lib/python3.8/site-packages/gsw/geostrophy.py:83: FutureWarning: Using a non-tuple sequence for multidimensional indexing is deprecated; use `arr[tuple(seq)]` instead of `arr[seq]`. In the future this will be interpreted as an array index, `arr[np.array(seq)]`, which will result either in an error or a different result.
  pgood = p[ind][igood]
rcaneill commented 2 years ago

With numpy 1.23.0 the functions works well with xarray