Closed gmaze closed 3 years ago
the error above, that we have with xarray 0.16.1 and not previous versions is in the line:
argo_r = ds.where(ds['DATA_MODE'] == 'R', drop=True)
which triggers an enigmatic:
ValueError: zero-size array to reduction operation minimum which has no identity
I have to notice than the mask here is full of False, so that the argo_r
output will be empty.
This is what is returned with an xarray version older than 0.16.1:
<xarray.Dataset>
Dimensions: (N_POINTS: 0)
Coordinates:
TIME (N_POINTS) datetime64[ns]
LATITUDE (N_POINTS) float64
LONGITUDE (N_POINTS) float64
* N_POINTS (N_POINTS) int64
Data variables:
CONFIG_MISSION_NUMBER (N_POINTS) float64
[...]
This resembles this old issue: https://github.com/pydata/xarray/issues/1329
So it's the time decoding of an empty array that fails here,
If we remove the TIME
variable before the where
statement, it works and return an empty array:
ds2 = ds.copy(deep=True)
ds2 = ds2.drop_vars('TIME')
ds2.where(ds2['DATA_MODE'] == 'R', drop=True)
returns:
<xarray.Dataset>
Dimensions: (N_POINTS: 0)
Coordinates:
LATITUDE (N_POINTS) float64
LONGITUDE (N_POINTS) float64
* N_POINTS (N_POINTS) int64
Data variables:
CONFIG_MISSION_NUMBER (N_POINTS) float64
[...]
and no error is raised anymore
To fix this, we should then monitor for the possible xarray error and turn around it like in https://github.com/atmtools/typhon/pull/37
I implemented a fix in #65 But I still don't understand why this popped up in 0.16.1 and not before ...
It seems that since xarray moved to 0.16.1, argopy is broken !
MCVE Code Sample
the same code with an xarray version strictly lower than 0.16.1 will work (eg. 0.15.1, 0.16.0)
This will throw an error like those found in unit testing here before we locked xarray version to 0.15.1. This is the reason we currently have an "outdated" message for argopy requirements.
Full error stack
--------------------------------------------------------------------------- ValueError Traceback (most recent call last)Problem Description
Obviously, argopy must work with the last versions of xarray.
I noticed that in the breaking changes of the 0.16.1 version that:
DataArray.astype() and Dataset.astype() now preserve attributes. Keep the old behavior by passing keep_attrs=False
This may be the origin of the issue here.
Versions
Output of `argopy.show_versions()`
INSTALLED VERSIONS ------------------ commit: None python: 3.8.6 | packaged by conda-forge | (default, Oct 7 2020, 18:42:56) [Clang 10.0.1 ] python-bits: 64 OS: Darwin OS-release: 18.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.6 libnetcdf: 4.7.4 argopy: 999 xarray: 0.16.1 pandas: 1.1.3 numpy: 1.19.2 scipy: 1.5.2 fsspec: 0.8.4 erddapy: 0.7.2 netCDF4: 1.5.4 pydap: installed h5netcdf: 0.8.1 h5py: 2.10.0 Nio: None zarr: 2.4.0 cftime: 1.2.1 nc_time_axis: 1.2.0 PseudoNetCDF: installed rasterio: 1.1.7 cfgrib: 0.9.8.4 iris: 2.4.0 bottleneck: 1.3.2 dask: 2.30.0 distributed: 2.30.0 matplotlib: 3.3.2 cartopy: 0.18.0 seaborn: 0.11.0 numbagg: installed gsw: 3.4.0 setuptools: 49.6.0.post20201009 pip: 20.2.3 conda: None pytest: 6.1.1 IPython: 7.18.1 sphinx: None