-
Notifications
You must be signed in to change notification settings - Fork 41
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
First crack at changing the url for one function #152
Changes from 1 commit
b499253
41b3270
c5839c1
9238e50
7c7ba2d
2603d5d
13bb200
9061f4c
85f2791
9bbae87
83444be
6723b5e
c2b4d12
089354c
3a8c818
91947ad
ec36997
ef09e3d
40a2b46
57f4ab7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
from .utils import BaseMetadata, query | ||
|
||
|
||
def get_results(ssl_check=True, **kwargs): | ||
def get_results(ssl_check=True, legacy=False, **kwargs): | ||
"""Query the WQP for results. | ||
|
||
Any WQP API parameter can be passed as a keyword argument to this function. | ||
|
@@ -30,6 +30,12 @@ def get_results(ssl_check=True, **kwargs): | |
ssl_check: bool | ||
If True, check the SSL certificate. Default is True. If False, SSL | ||
certificate is not checked. | ||
legacy: Boolean | ||
Defaults to False and returns the new WQX3 Result profile. | ||
If set to True, returns data using the legacy WQX version 2 profiles. | ||
dataProfile: string | ||
Describes the type of columns to return with the result dataset. | ||
Includes 'fullPhysChem', 'biological', 'narrow', and 'basicPhysChem'. | ||
siteid: string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could these parameters be added to the documentation of the other WQP functions? Seems like it would be annoying to look at the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good eye. I'm not sure the convention with |
||
Concatenate an agency code, a hyphen ("-"), and a site-identification | ||
number. | ||
|
@@ -63,10 +69,7 @@ def get_results(ssl_check=True, **kwargs): | |
for available characteristic names) | ||
mimeType: string | ||
String specifying the output format which is 'csv' by default but can | ||
be 'geojson' | ||
zip: string | ||
Parameter to stream compressed data, if 'yes', or uncompressed data | ||
if 'no'. Default is 'no'. | ||
be 'geojson' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GeoJSON is not yet supported, so this documentation should reflect that On a related note, is there a reason why the other possible WQP file outputs (tsv, xlsx) aren't supported here? I tested out passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. Legacy supports tsv and xlsx, but it looks like beta does not yet support anything other than csv. I might add this as an issue to follow up on, but leave as-is for this PR. #162 |
||
|
||
Returns | ||
------- | ||
|
@@ -91,7 +94,19 @@ def get_results(ssl_check=True, **kwargs): | |
_warn_v3_profiles_outage() | ||
|
||
kwargs = _alter_kwargs(kwargs) | ||
response = query(wqp_url('Result'), kwargs, delimiter=';', ssl_check=ssl_check) | ||
|
||
if legacy is True: | ||
warnings.warn('Legacy profiles return stale USGS data as of ' | ||
'March 2024. Please set legacy=True to use the WQX3 ' | ||
'data profiles and obtain the latest USGS data.') | ||
url = wqp_url('Result') | ||
|
||
else: | ||
url = wqx3_url('Result') | ||
if 'dataProfile' not in kwargs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should check whether dataProfile is among a list of valid profiles and throw an error if not. Examples in |
||
kwargs['dataProfile'] = 'basicPhysChem' | ||
|
||
response = query(url, kwargs, delimiter=';', ssl_check=ssl_check) | ||
|
||
df = pd.read_csv(StringIO(response.text), delimiter=',') | ||
return df, WQP_Metadata(response) | ||
|
@@ -472,6 +487,11 @@ def wqp_url(service): | |
base_url = 'https://www.waterqualitydata.us/data/' | ||
return f'{base_url}{service}/Search?' | ||
|
||
def wqx3_url(service): | ||
ehinman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Construct the WQP URL for a given WQX 3.0 service.""" | ||
base_url = 'https://www.waterqualitydata.us/wqx3/' | ||
return f'{base_url}{service}/search?' | ||
|
||
|
||
class WQP_Metadata(BaseMetadata): | ||
"""Metadata class for WQP service, derived from BaseMetadata. | ||
|
@@ -531,9 +551,6 @@ def _alter_kwargs(kwargs): | |
user so they are aware of which are being hard-set. | ||
|
||
""" | ||
if kwargs.get('zip', 'no') == 'yes': | ||
warnings.warn('Compressed data not yet supported, zip set to no.') | ||
kwargs['zip'] = 'no' | ||
|
||
if kwargs.get('mimeType', 'csv') == 'geojson': | ||
warnings.warn('GeoJSON not yet supported, mimeType set to csv.') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the documentation here and in the other
what_*
functions could be clearer. For example, what are the "results" that one would expect to obtain? Or what does it mean to search for sites/projects/organizations/activities/etc. "within a region with specific data?" For what purpose would someone use these functions? A simple description of these WQP endpoints would be helpful.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, the definitions of the functions are a bit murky. We can use dataRetrieval as a good example: https://doi-usgs.github.io/dataRetrieval/reference/wqpSpecials.html, though also quite light on specifics.