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

Erddap update #344

Merged
merged 18 commits into from
Aug 21, 2024
Merged
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
32 changes: 14 additions & 18 deletions argopy/data_fetchers/erddap_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import numpy as np
import copy
import time

from abc import abstractmethod
import getpass
from typing import Union
import fnmatch
from aiohttp import ClientResponseError
import logging
from erddapy.erddapy import ERDDAP, parse_dates
from erddapy.erddapy import _quote_string_constraints as quote_string_constraints

from ..options import OPTIONS
from ..utils.format import format_oneline
Expand All @@ -32,19 +32,6 @@
from .proto import ArgoDataFetcherProto


# 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: # noqa: E722
# >= 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

# Soon ! https://github.com/ioos/erddapy


log = logging.getLogger("argopy.erddap.data")

access_points = ["wmo", "box"]
Expand Down Expand Up @@ -401,10 +388,12 @@ def _init_erddapy(self):

if self.dataset_id == "phy":
self.erddap.dataset_id = "ArgoFloats"
elif self.dataset_id == "ref":
self.erddap.dataset_id = "ArgoFloats-ref"
elif self.dataset_id == "bgc":
self.erddap.dataset_id = "ArgoFloats-synthetic-BGC"
elif self.dataset_id == "ref":
self.erddap.dataset_id = "ArgoFloats-reference"
elif self.dataset_id == "ref-ctd":
self.erddap.dataset_id = "ArgoFloats-reference-CTD"
elif self.dataset_id == "fail":
self.erddap.dataset_id = "invalid_db"
else:
Expand Down Expand Up @@ -672,16 +661,23 @@ def post_process(self, this_ds, add_dm: bool = True, URI: list = None): # noqa:
Fetched_constraints = this_ds.attrs.get('Fetched_constraints', False)

# Finally overwrite erddap attributes with those from argopy:
raw_attrs = this_ds.attrs.copy()
this_ds.attrs = {}
if self.dataset_id == "phy":
this_ds.attrs["DATA_ID"] = "ARGO"
this_ds.attrs["DOI"] = "http://doi.org/10.17882/42182"
elif self.dataset_id == "ref":
this_ds.attrs["DATA_ID"] = "ARGO_Reference"
this_ds.attrs["DOI"] = "-"
this_ds.attrs["Fetched_version"] = raw_attrs.get('version', '?')
elif self.dataset_id == "ref-ctd":
this_ds.attrs["DATA_ID"] = "ARGO_Reference_CTD"
this_ds.attrs["DOI"] = "-"
this_ds.attrs["Fetched_version"] = raw_attrs.get('version', '?')
elif self.dataset_id == "bgc":
this_ds.attrs["DATA_ID"] = "ARGO-BGC"
this_ds.attrs["DOI"] = "http://doi.org/10.17882/42182"

this_ds.attrs["Fetched_from"] = self.erddap.server
try:
this_ds.attrs["Fetched_by"] = getpass.getuser()
Expand All @@ -690,7 +686,7 @@ def post_process(self, this_ds, add_dm: bool = True, URI: list = None): # noqa:
this_ds.attrs["Fetched_date"] = pd.to_datetime("now", utc=True).strftime(
"%Y/%m/%d"
)
this_ds.attrs["Fetched_constraints"] = self.cname() if not Fetched_constraints else Fetched_constraints
this_ds.attrs["Fetched_constraints"] = self.cname() if not Fetched_constraints else Fetched_constraints
this_ds.attrs["Fetched_uri"] = URI if not Fetched_url else Fetched_url
this_ds = this_ds[np.sort(this_ds.data_vars)]

Expand Down
14 changes: 2 additions & 12 deletions argopy/data_fetchers/erddap_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
import numpy as np
import copy
import logging

from abc import ABC, abstractmethod
from erddapy.erddapy import ERDDAP, parse_dates
from erddapy.erddapy import _quote_string_constraints as quote_string_constraints

from ..utils.format import format_oneline
from ..related import load_dict, mapp_dict
Expand All @@ -25,17 +26,6 @@
log = logging.getLogger("argopy.fetchers.erddap_index")


# 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 Exception:
# >= 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"]
exit_formats = ["xarray", "dataframe"]
dataset_ids = ["phy"] # First is default
Expand Down
17 changes: 4 additions & 13 deletions argopy/data_fetchers/erddap_refdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ErddapREFDataFetcher(ErddapArgoDataFetcher):
"""Manage access to Argo CTD-reference data through Ifremer ERDDAP"""

# @doc_inherit
def __init__(self, **kwargs):
def __init__(self, *args, **kwargs):
"""Instantiate an authenticated ERDDAP Argo data fetcher

Parameters
Expand All @@ -50,7 +50,7 @@ def __init__(self, **kwargs):
Erddap request time out in seconds. Set to OPTIONS['api_timeout'] by default.
"""
kwargs["ds"] = "ref-ctd"
super().__init__(**kwargs)
super().__init__(*args, **kwargs)
kw = kwargs
[
kw.pop(p)
Expand Down Expand Up @@ -110,12 +110,6 @@ def _add_attributes(self, this): # noqa: C901

return this

def _init_erddapy(self):
# Init erddapy
self.erddap = ERDDAP(server=str(self.server), protocol="tabledap")
self.erddap.response = "nc"
self.erddap.dataset_id = "Argo-ref-ctd"
return self

@property
def _minimal_vlist(self):
Expand Down Expand Up @@ -152,9 +146,6 @@ def to_xarray(self, errors: str = "ignore"): # noqa: C901
g, dim="N_POINTS", data_vars="minimal", coords="minimal", compat="override"
)

ds.attrs["DATA_ID"] = "ARGO_Reference_CTD"
ds.attrs["DOI"] = "-"

# Cast data types and add variable attributes (not available in the csv download):
ds = self._add_attributes(ds)
ds = ds.argo.cast_types()
Expand Down Expand Up @@ -185,8 +176,8 @@ def init(self, box: list, **kw):
def define_constraints(self):
"""Define request constraints"""

self.erddap.constraints = {"longitude>=": conv_lon(self.BOX[0], conv='360')}
self.erddap.constraints.update({"longitude<=": conv_lon(self.BOX[1], conv='360')})
self.erddap.constraints = {"longitude>=": conv_lon(self.BOX[0], conv='180')}
self.erddap.constraints.update({"longitude<=": conv_lon(self.BOX[1], conv='180')})
self.erddap.constraints.update({"latitude>=": self.BOX[2]})
self.erddap.constraints.update({"latitude<=": self.BOX[3]})
self.erddap.constraints.update({"pres>=": self.BOX[4]})
Expand Down
2 changes: 1 addition & 1 deletion argopy/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def reset_options():

def check_erddap_path(path, errors='ignore'):
"""Check if an url points to an ERDDAP server"""
fs = fsspec.filesystem('http')
fs = fsspec.filesystem('http', ssl=False)
check1 = fs.exists(path + "/info/index.json")
if check1:
return True
Expand Down
13 changes: 9 additions & 4 deletions argopy/stores/filesystems.py
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,9 @@ def _repr_html_(self):
html.append("</thead>")
html.append("<tbody>")
html.append(tr_ticklink("login page", self._login_page, self._login_page))
html.append(tr_tick("login data", self._login_payload))
payload = self._login_payload.copy()
payload['password'] = "*" * len(payload['password'])
html.append(tr_tick("login data", payload))
if hasattr(self, "_connected"):
html.append(tr_tick("connected", "✅" if self._connected else "⛔"))
else:
Expand All @@ -1788,9 +1790,11 @@ def _repr_html_(self):

def connect(self):
try:
payload = self._login_payload.copy()
payload['password'] = "*" * len(payload['password'])
log.info(
"Try to log-in to '%s' page with %s data ..."
% (self._login_page, self._login_payload)
"Try to log-in to '%s' page with %s"
% (self._login_page, payload)
)
self.fs.info(self._login_page)
self._connected = True
Expand All @@ -1808,7 +1812,8 @@ def connected(self):


def httpstore_erddap(url: str = "", cache: bool = False, cachedir: str = "", **kwargs):
login_page = "%s/login.html" % url.rstrip("/")
erddap = OPTIONS['erddap'] if url == "" else url
login_page = "%s/login.html" % erddap.rstrip("/")
login_store = httpstore_erddap_auth(
cache=cache, cachedir=cachedir, login=login_page, auto=False, **kwargs
)
Expand Down
Loading
Loading