Skip to content

Commit d5d5788

Browse files
committed
add continuous endpoint, take 2
1 parent 4e23554 commit d5d5788

2 files changed

Lines changed: 165 additions & 20 deletions

File tree

dataretrieval/waterdata/api.py

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,171 @@ def get_daily(
205205

206206
return get_ogc_data(args, output_id, service)
207207

208+
def get_continuous(
209+
monitoring_location_id: Optional[Union[str, List[str]]] = None,
210+
parameter_code: Optional[Union[str, List[str]]] = None,
211+
statistic_id: Optional[Union[str, List[str]]] = None,
212+
properties: Optional[List[str]] = None,
213+
time_series_id: Optional[Union[str, List[str]]] = None,
214+
continuous_id: Optional[Union[str, List[str]]] = None,
215+
approval_status: Optional[Union[str, List[str]]] = None,
216+
unit_of_measure: Optional[Union[str, List[str]]] = None,
217+
qualifier: Optional[Union[str, List[str]]] = None,
218+
value: Optional[Union[str, List[str]]] = None,
219+
last_modified: Optional[str] = None,
220+
skip_geometry: Optional[bool] = None,
221+
time: Optional[Union[str, List[str]]] = None,
222+
limit: Optional[int] = None,
223+
convert_type: bool = True,
224+
) -> Tuple[pd.DataFrame, BaseMetadata]:
225+
"""This is an early version of the continuous endpoint. It is
226+
feature-complete and provides access to the full continuous data record,
227+
and is being made available as we continue to work on performance
228+
improvements. Continuous data are collected via automated sensors
229+
installed at a monitoring location. They are collected at a high
230+
frequency and often at a fixed 15-minute interval. Depending on the
231+
specific monitoring location, the data may be transmitted automatically
232+
via telemetry and be available on WDFN within minutes of collection,
233+
while other times the delivery of data may be delayed if the monitoring
234+
location does not have the capacity to automatically transmit data.
235+
Continuous data are described by parameter name and parameter code
236+
(pcode). These data might also be referred to as "instantaneous values"
237+
or "IV".
238+
239+
Parameters
240+
----------
241+
monitoring_location_id : string or list of strings, optional
242+
A unique identifier representing a single monitoring location. This
243+
corresponds to the id field in the monitoring-locations endpoint.
244+
Monitoring location IDs are created by combining the agency code of
245+
the agency responsible for the monitoring location (e.g. USGS) with
246+
the ID number of the monitoring location (e.g. 02238500), separated
247+
by a hyphen (e.g. USGS-02238500).
248+
parameter_code : string or list of strings, optional
249+
Parameter codes are 5-digit codes used to identify the constituent
250+
measured and the units of measure. A complete list of parameter
251+
codes and associated groupings can be found at
252+
https://help.waterdata.usgs.gov/codes-and-parameters/parameters.
253+
statistic_id : string or list of strings, optional
254+
A code corresponding to the statistic an observation represents.
255+
Example codes include 00001 (max), 00002 (min), and 00003 (mean).
256+
A complete list of codes and their descriptions can be found at
257+
https://help.waterdata.usgs.gov/code/stat_cd_nm_query?stat_nm_cd=%25&fmt=html.
258+
properties : string or list of strings, optional
259+
A vector of requested columns to be returned from the query.
260+
Available options are: geometry, id, time_series_id,
261+
monitoring_location_id, parameter_code, statistic_id, time, value,
262+
unit_of_measure, approval_status, qualifier, last_modified
263+
time_series_id : string or list of strings, optional
264+
A unique identifier representing a single time series. This
265+
corresponds to the id field in the time-series-metadata endpoint.
266+
daily_id : string or list of strings, optional
267+
A universally unique identifier (UUID) representing a single version of
268+
a record. It is not stable over time. Every time the record is refreshed
269+
in our database (which may happen as part of normal operations and does
270+
not imply any change to the data itself) a new ID will be generated. To
271+
uniquely identify a single observation over time, compare the time and
272+
time_series_id fields; each time series will only have a single
273+
observation at a given time.
274+
approval_status : string or list of strings, optional
275+
Some of the data that you have obtained from this U.S. Geological Survey
276+
database may not have received Director's approval. Any such data values
277+
are qualified as provisional and are subject to revision. Provisional
278+
data are released on the condition that neither the USGS nor the United
279+
States Government may be held liable for any damages resulting from its
280+
use. This field reflects the approval status of each record, and is either
281+
"Approved", meaining processing review has been completed and the data is
282+
approved for publication, or "Provisional" and subject to revision. For
283+
more information about provisional data, go to:
284+
https://waterdata.usgs.gov/provisional-data-statement/.
285+
unit_of_measure : string or list of strings, optional
286+
A human-readable description of the units of measurement associated
287+
with an observation.
288+
qualifier : string or list of strings, optional
289+
This field indicates any qualifiers associated with an observation, for
290+
instance if a sensor may have been impacted by ice or if values were
291+
estimated.
292+
value : string or list of strings, optional
293+
The value of the observation. Values are transmitted as strings in
294+
the JSON response format in order to preserve precision.
295+
last_modified : string, optional
296+
The last time a record was refreshed in our database. This may happen
297+
due to regular operational processes and does not necessarily indicate
298+
anything about the measurement has changed. You can query this field
299+
using date-times or intervals, adhering to RFC 3339, or using ISO 8601
300+
duration objects. Intervals may be bounded or half-bounded (double-dots
301+
at start or end).
302+
Examples:
303+
304+
* A date-time: "2018-02-12T23:20:50Z"
305+
* A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"
306+
* Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z"
307+
* Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours
308+
309+
Only features that have a last_modified that intersects the value of
310+
datetime are selected.
311+
skip_geometry : boolean, optional
312+
This option can be used to skip response geometries for each feature.
313+
The returning object will be a data frame with no spatial information.
314+
Note that the USGS Water Data APIs use camelCase "skipGeometry" in
315+
CQL2 queries.
316+
time : string, optional
317+
The date an observation represents. You can query this field using
318+
date-times or intervals, adhering to RFC 3339, or using ISO 8601
319+
duration objects. Intervals may be bounded or half-bounded (double-dots
320+
at start or end). Only features that have a time that intersects the
321+
value of datetime are selected. If a feature has multiple temporal
322+
properties, it is the decision of the server whether only a single
323+
temporal property is used to determine the extent or all relevant
324+
temporal properties.
325+
Examples:
326+
327+
* A date-time: "2018-02-12T23:20:50Z"
328+
* A bounded interval: "2018-02-12T00:00:00Z/2018-03-18T12:31:12Z"
329+
* Half-bounded intervals: "2018-02-12T00:00:00Z/.." or "../2018-03-18T12:31:12Z"
330+
* Duration objects: "P1M" for data from the past month or "PT36H" for the last 36 hours
331+
332+
limit : numeric, optional
333+
The optional limit parameter is used to control the subset of the
334+
selected features that should be returned in each page. The maximum
335+
allowable limit is 10000. It may be beneficial to set this number lower
336+
if your internet connection is spotty. The default (NA) will set the
337+
limit to the maximum allowable limit for the service.
338+
convert_type : boolean, optional
339+
If True, the function will convert the data to dates and qualifier to
340+
string vector
341+
342+
Returns
343+
-------
344+
df : ``pandas.DataFrame`` or ``geopandas.GeoDataFrame``
345+
Formatted data returned from the API query.
346+
md: :obj:`dataretrieval.utils.Metadata`
347+
A custom metadata object
348+
349+
Examples
350+
--------
351+
.. code::
352+
353+
>>> # Get instantaneous gage height data from a
354+
>>> # single site from a single year
355+
>>> df, md = dataretrieval.waterdata.get_continuous(
356+
... monitoring_location_id="USGS-02238500",
357+
... parameter_code="00060",
358+
... time="2021-01-01T00:00:00Z/2022-01-01T00:00:00Z",
359+
... )
360+
"""
361+
service = "continuous"
362+
output_id = "continuous_id"
363+
364+
# Build argument dictionary, omitting None values
365+
args = {
366+
k: v
367+
for k, v in locals().items()
368+
if k not in {"service", "output_id"} and v is not None
369+
}
370+
371+
return get_ogc_data(args, output_id, service)
372+
208373

209374
def get_monitoring_locations(
210375
monitoring_location_id: Optional[List[str]] = None,

dataretrieval/waterdata/utils.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -755,23 +755,3 @@ def get_ogc_data(
755755
metadata = BaseMetadata(response)
756756
return return_list, metadata
757757

758-
759-
# def _get_description(service: str):
760-
# tags = _get_collection().get("tags", [])
761-
# for tag in tags:
762-
# if tag.get("name") == service:
763-
# return tag.get("description")
764-
# return None
765-
766-
# def _get_params(service: str):
767-
# url = f"{_base_url()}collections/{service}/schema"
768-
# resp = requests.get(url, headers=_default_headers())
769-
# resp.raise_for_status()
770-
# properties = resp.json().get("properties", {})
771-
# return {k: v.get("description") for k, v in properties.items()}
772-
773-
# def _get_collection():
774-
# url = f"{_base_url()}openapi?f=json"
775-
# resp = requests.get(url, headers=_default_headers())
776-
# resp.raise_for_status()
777-
# return resp.json()

0 commit comments

Comments
 (0)