Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breaking changes with Erddapy >= v0.8.0 #69

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pythontests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
os: [ubuntu-latest, macos-latest]
os: [macos-latest]

steps:
- uses: actions/checkout@master
Expand Down
11 changes: 9 additions & 2 deletions argopy/data_fetchers/erddap_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@
from argopy.stores import httpstore
from argopy.plotters import open_dashboard

from erddapy import ERDDAP
from erddapy.utilities import parse_dates, quote_string_constraints
# Load erddapy according to available version (breaking changes in v0.8.0)
try:
from erddapy import ERDDAP
from erddapy.utilities import parse_dates, quote_string_constraints
except:
# >= v0.8.0
from erddapy.erddapy import ERDDAP
from erddapy.erddapy import _quote_string_constraints as quote_string_constraints
from erddapy.erddapy import parse_dates
gmaze marked this conversation as resolved.
Show resolved Hide resolved


access_points = ["wmo", "box"]
Expand Down
13 changes: 11 additions & 2 deletions argopy/data_fetchers/erddap_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@
from argopy.utilities import load_dict, mapp_dict, format_oneline
from argopy.stores import httpstore

from erddapy import ERDDAP
from erddapy.utilities import parse_dates, quote_string_constraints
# from erddapy import ERDDAP
# from erddapy.utilities import parse_dates, quote_string_constraints
# Load erddapy according to available version (breaking changes in v0.8.0)
try:
from erddapy import ERDDAP
from erddapy.utilities import parse_dates, quote_string_constraints
except:
# >= v0.8.0
from erddapy.erddapy import ERDDAP
from erddapy.erddapy import _quote_string_constraints as quote_string_constraints
from erddapy.erddapy import parse_dates


access_points = ['wmo', 'box']
Expand Down
31 changes: 27 additions & 4 deletions argopy/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,34 @@ def filter_data_mode(self, keep_error: bool = True, errors: str = 'raise'):
#########
# Sub-functions
#########
def safe_where_eq(xds, key, value):
# xds.where(xds[key] == value, drop=True) is not safe to empty time variables, cf issue #64
try:
return xds.where(xds[key] == value, drop=True)
except ValueError as v:
if v.args[0] == ("zero-size array to reduction operation "
"minimum which has no identity"):
# A bug in xarray will cause a ValueError if trying to
# decode the times in a NetCDF file with length 0.
# See:
# https://github.com/pydata/xarray/issues/1329
# https://github.com/euroargodev/argopy/issues/64
# Here, we just need to return an empty array
TIME = xds['TIME']
xds = xds.drop_vars('TIME')
xds = xds.where(xds[key] == value, drop=True)
xds['TIME'] = xr.DataArray(np.arange(len(xds['N_POINTS'])), dims='N_POINTS',
attrs=TIME.attrs).astype(np.datetime64)
xds = xds.set_coords('TIME')
return xds

def ds_split_datamode(xds):
""" Create one dataset for each of the data_mode

Split full dataset into 3 datasets
"""
# Real-time:
argo_r = ds.where(ds['DATA_MODE'] == 'R', drop=True)
argo_r = safe_where_eq(xds, 'DATA_MODE', 'R')
for v in plist:
vname = v.upper() + '_ADJUSTED'
if vname in argo_r:
Expand All @@ -232,7 +253,7 @@ def ds_split_datamode(xds):
if vname in argo_r:
argo_r = argo_r.drop_vars(vname)
# Real-time adjusted:
argo_a = ds.where(ds['DATA_MODE'] == 'A', drop=True)
argo_a = safe_where_eq(xds, 'DATA_MODE', 'A')
for v in plist:
vname = v.upper()
if vname in argo_a:
Expand All @@ -241,7 +262,7 @@ def ds_split_datamode(xds):
if vname in argo_a:
argo_a = argo_a.drop_vars(vname)
# Delayed mode:
argo_d = ds.where(ds['DATA_MODE'] == 'D', drop=True)
argo_d = safe_where_eq(xds, 'DATA_MODE', 'D')
return argo_r, argo_a, argo_d

def fill_adjusted_nan(ds, vname):
Expand Down Expand Up @@ -295,7 +316,9 @@ def new_arrays(argo_r, argo_a, argo_d, vname):
return ds

# Define variables to filter:
possible_list = ['PRES', 'TEMP', 'PSAL',
possible_list = ['PRES',
'TEMP',
'PSAL',
'DOXY',
'CHLA',
'BBP532',
Expand Down