Skip to content

Commit

Permalink
Merge pull request #22 from kthyng/more_tests
Browse files Browse the repository at this point in the history
Filled in tests for sensors
  • Loading branch information
kthyng authored Feb 22, 2023
2 parents f9cfa59 + 12502ce commit f03dd8e
Show file tree
Hide file tree
Showing 6 changed files with 685 additions and 72 deletions.
7 changes: 1 addition & 6 deletions intake_axds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
import intake # noqa: F401, need this to eliminate possibility of circular import

# from .axds_cat import AXDSCatalog
from .utils import ( # noqa: F401
_get_version,
available_names,
match_key_to_parameter,
return_parameter_options,
)
from .utils import _get_version, available_names, match_key_to_parameter # noqa: F401


__version__ = _get_version()
15 changes: 11 additions & 4 deletions intake_axds/axds.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,26 @@ def __init__(
"QARTOD is not available for binned output. Set QARTOD to False or use raw data."
)

metadata = metadata or {}

# need dataset_id to get metadata
if self.dataset_id is None:
assert self.internal_id is not None
res = response_from_url(make_metadata_url(make_filter(self.internal_id)))
assert isinstance(res, dict)
self.dataset_id = res["data"]["stations"][0]["uuid"]
metadata["version"] = res["data"]["stations"][0]["version"]

# need internal_id to get data
elif self.internal_id is None:
assert self.dataset_id is not None
self.internal_id = response_from_url(make_search_docs_url(self.dataset_id))[
0
]["id"]
res = response_from_url(make_search_docs_url(self.dataset_id))[0]
assert isinstance(res, dict) # for mypy
self.internal_id = res["id"]
metadata["version"] = res["data"]["version"]

self._dataframe = None

metadata = metadata or {}
metadata["dataset_id"] = self.dataset_id

# this is what shows in the source if you print it
Expand Down Expand Up @@ -156,6 +159,10 @@ def get_filters(self):

filters = []

# if "version" not in self.metadata:
# res = response_from_url(make_search_docs_url(self.dataset_id))[0]
# self.metadata["version"] = res["data"]["version"]

if self.metadata["version"] == 1:

# if we should only return the requested variables, use the pgids input for this.
Expand Down
46 changes: 7 additions & 39 deletions intake_axds/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

search_headers = {"Accept": "application/json"}
baseurl = "https://sensors.axds.co/api"
contexturl = "http://oikos.axds.co/rest/context"


def _get_version() -> str:
Expand All @@ -26,41 +27,6 @@ def _get_version() -> str:
return __version__


def return_parameter_options() -> dict:
"""Find parameters for Axiom assets.
Returns
-------
List
Contains the parameter information for Axiom assets.
Examples
--------
>>> return_parameter_options()
[{'id': 4,
'label': 'Relative Humidity',
'urn': 'http://mmisw.org/ont/cf/parameter/relative_humidity',
'ratio': False,
'sanityMin': 0.0,
'sanityMax': 110.0,
'parameterGroupDefault': True,
'configJson': None,
'stageConfigJson': None,
'idSanityUnit': 1,
'idParameterGroup': 22,
'idParameterType': 101,
'parameterName': 'relative_humidity'},
...
"""

resp = requests.get("http://oikos.axds.co/rest/context")
# resp.raise_for_status()
output = resp.json()
# params = data["parameters"]

return output


def available_names() -> list:
"""Return available parameterNames for variables.
Expand All @@ -70,7 +36,8 @@ def available_names() -> list:
parametersNames, which are a superset of standard_names.
"""

resp = return_parameter_options()
resp = response_from_url(contexturl)
assert isinstance(resp, dict) # for mypy
params = resp["parameters"]

# find parameterName options for AXDS. These are a superset of standard_names
Expand Down Expand Up @@ -100,7 +67,8 @@ def match_key_to_parameter(
Parameter Group values that match key, according to the custom criteria.
"""

resp = return_parameter_options()
resp = response_from_url(contexturl)
assert isinstance(resp, dict) # for mypy
params = resp["parameters"]

# find parameterName options for AXDS. These are a superset of standard_names
Expand Down Expand Up @@ -142,7 +110,8 @@ def match_std_names_to_parameter(standard_names: list) -> list:
Parameter Group values that match standard_names.
"""

resp = return_parameter_options()
resp = response_from_url(contexturl)
assert isinstance(resp, dict) # for mypy
params = resp["parameters"]

names = [i["parameterName"] for i in params]
Expand Down Expand Up @@ -186,7 +155,6 @@ def load_metadata(datatype: str, results: dict) -> dict: #: Dict[str, str]
dict
Metadata to store with catalog entry.
"""

# matching names in intake-erddap
keys = ["datasetID", "title", "summary", "type", "minTime", "maxTime"]
# names of keys in Axiom system.
Expand Down
Loading

0 comments on commit f03dd8e

Please sign in to comment.