This page was generated from things.ipynb. Interactive online version:
SensorThings#
[1]:
from pygeohydro import SensorThings
SensorThings is a recently released USGS web service that provides access to real-time USGS sensors. For more information about the service you can check out this to the service and also this which is overview or different USGS APIs. PyGeoHydro provides access to the Things
endpoint which is “one of the most important components, and can be mapped to USGS
Monitoring locations”.
[2]:
sensor = SensorThings()
We can query information about stations using sensor_info
. We can pass a single ID or list of them.
[3]:
resp = sensor.sensor_info(["USGS-09380000", "USGS-09472050"])
resp
[3]:
description | @iot.id | name | properties.state | properties.active | properties.agency | properties.county | properties.country | properties.district | properties.stateFIPS | ... | properties.districtCode | properties.altitudeDatum | properties.altitudeMethod | properties.hydrologicUnit | properties.altitudeAccuracy | properties.monitoringLocationUrl | properties.monitoringLocationName | properties.monitoringLocationType | properties.monitoringLocationNumber | properties.monitoringLocationAltitudeLandSurface | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Stream | USGS-09380000 | USGS-09380000 | Arizona | True | U.S. Geological Survey | Coconino County | US | Arizona | US:04 | ... | 04 | North American Vertical Datum of 1988 | Interpolated from Digital Elevation Model | 140700061105 | 4.3 | https://waterdata.usgs.gov/monitoring-location... | COLORADO RIVER AT LEES FERRY, AZ | Stream | 09380000 | 3083 |
1 | Stream | USGS-09472050 | USGS-09472050 | Arizona | True | U.S. Geological Survey | Pima County | US | Arizona | US:04 | ... | 04 | National Geodetic Vertical Datum of 1929 | Interpolated from topographic map. | 150502030503 | 10 | https://waterdata.usgs.gov/monitoring-location... | SAN PEDRO R AT REDINGTON BRIDGE NR REDINGTON, AZ | Stream | 09472050 | 2820. |
2 rows × 23 columns
Additionally, we can get a sensor property using sensor_property
.
[4]:
resp = sensor.sensor_property("Datastreams", ["USGS-09380000", "USGS-09472050"])
resp
[4]:
description | @iot.id | name | observationType | phenomenonTime | resultTime | @iot.selfLink | ObservedProperty@iot.navigationLink | Sensor@iot.navigationLink | Thing@iot.navigationLink | Observations@iot.navigationLink | observedArea.type | observedArea.coordinates | properties.Thresholds | properties.ParameterCode | properties.StatisticCode | unitOfMeasurement.name | unitOfMeasurement.symbol | unitOfMeasurement.definition | properties.WebDescription | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Specific cond at 25C / USGS-09380000-9d24cf502... | 9d24cf50257a4f60b76b92e38f286cde | 9d24cf50257a4f60b76b92e38f286cde | Instantaneous | 2021-07-12T18:45:00.000Z/2023-02-05T03:00:00.000Z | None | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | Point | [-111.5878722, 36.8643333] | [{'Name': 'HIGH SC THRESHOLD', 'Type': 'Thresh... | 00095 | 00011 | uS/cm | uS/cm | NaN | |
1 | None / USGS-09380000-0a10dcb7436f4af8a679a783a... | 0a10dcb7436f4af8a679a783ae3d8d58 | 0a10dcb7436f4af8a679a783ae3d8d58 | Instantaneous | 2022-07-08T20:30:00.000Z/2022-07-20T19:00:00.000Z | None | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | Point | [-111.5878722, 36.8643333] | NaN | 00095 | 00011 | uS/cm | uS/cm | Starts 7/8/22 | |
2 | Discharge / USGS-09380000-a62122d8ff094125b63b... | a62122d8ff094125b63bb2f73410b2b4 | a62122d8ff094125b63bb2f73410b2b4 | Instantaneous | 2021-09-16T11:00:00.000Z/2023-02-05T03:00:00.000Z | None | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | Point | [-111.5878722, 36.8643333] | NaN | 00060 | 00011 | Cubic Feet per Second | ft^3/s | NaN | |
3 | Temperature, water / USGS-09380000-b3c374548a8... | b3c374548a8d4553868046dd9fda2582 | b3c374548a8d4553868046dd9fda2582 | Instantaneous | 2021-07-12T20:30:00.000Z/2023-02-05T03:00:00.000Z | None | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | Point | [-111.5878722, 36.8643333] | NaN | 00010 | 00011 | Degrees Centigrade | degC | NaN | |
4 | None / USGS-09380000-e1c4b44914ed43819cf8e2e21... | e1c4b44914ed43819cf8e2e2138e9064 | e1c4b44914ed43819cf8e2e2138e9064 | Instantaneous | 2022-01-10T01:30:00.000Z/2023-02-05T03:00:00.000Z | None | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | Point | [-111.5878722, 36.8643333] | NaN | 00045 | NaN | in | in | NaN | |
5 | None / USGS-09380000-c1d72c8390d144f78b51568a3... | c1d72c8390d144f78b51568a3755a5ad | c1d72c8390d144f78b51568a3755a5ad | Instantaneous | 2022-07-08T18:30:00.000Z/2023-02-05T03:00:00.000Z | None | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | Point | [-111.5878722, 36.8643333] | NaN | 00065 | 00011 | Feet | ft | PRIMARY STAGE | |
6 | Gage height / USGS-09472050-3c47927571274e388e... | 3c47927571274e388e7f4a8fbf1049e9 | 3c47927571274e388e7f4a8fbf1049e9 | Instantaneous | 2021-07-16T22:45:00.000Z/2023-02-05T04:15:00.000Z | None | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | Point | [-110.4884183, 32.4461827] | [{'Name': 'Operational limit (maximum) Upper l... | 00065 | 00011 | Feet | ft | NaN | |
7 | Discharge / USGS-09472050-9e9527c7d6c542cd92a5... | 9e9527c7d6c542cd92a5178922712ed8 | 9e9527c7d6c542cd92a5178922712ed8 | Instantaneous | 2021-08-12T06:00:00.000Z/2023-02-05T04:15:00.000Z | None | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | https://labs.waterdata.usgs.gov/sta/v1.1/Datas... | Point | [-110.4884183, 32.4461827] | NaN | 00060 | 00011 | Cubic Feet per Second | ft^3/s | NaN |
For more complex queries, we need to construct an Odata query.
[5]:
odata = {
"filter": "properties/monitoringLocationType eq 'Stream' and properties/stateFIPS eq 'US:04'",
}
df = sensor.query_byodata(odata)
df
[5]:
description | @iot.id | name | @iot.selfLink | Datastreams@iot.navigationLink | TaskingCapabilities@iot.navigationLink | HistoricalLocations@iot.navigationLink | Locations@iot.navigationLink | MultiDatastreams@iot.navigationLink | properties.state | ... | properties.districtCode | properties.altitudeDatum | properties.altitudeMethod | properties.hydrologicUnit | properties.altitudeAccuracy | properties.monitoringLocationUrl | properties.monitoringLocationName | properties.monitoringLocationType | properties.monitoringLocationNumber | properties.monitoringLocationAltitudeLandSurface | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | Stream | USGS-09497700 | USGS-09497700 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | North American Vertical Datum of 1988 | Interpolated from topographic map. | 150601030102 | 20 | https://waterdata.usgs.gov/monitoring-location... | CIBECUE CREEK NEAR OVERGAARD, AZ | Stream | 09497700 | 7200 |
1 | Stream | USGS-09472050 | USGS-09472050 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | National Geodetic Vertical Datum of 1929 | Interpolated from topographic map. | 150502030503 | 10 | https://waterdata.usgs.gov/monitoring-location... | SAN PEDRO R AT REDINGTON BRIDGE NR REDINGTON, AZ | Stream | 09472050 | 2820. |
2 | Stream | USGS-09424900 | USGS-09424900 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | National Geodetic Vertical Datum of 1929 | Interpolated from topographic map. | 150302030506 | 20 | https://waterdata.usgs.gov/monitoring-location... | SANTA MARIA RIVER NEAR BAGDAD, AZ | Stream | 09424900 | 1360 |
3 | Stream | USGS-09491980 | USGS-09491980 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | North American Vertical Datum of 1988 | Interpolated from Digital Elevation Model | 150601020207 | 1.6 | https://waterdata.usgs.gov/monitoring-location... | N-FORK WHITE RIVER BLW GOLD GULCH AT WHITERIVE... | Stream | 09491980 | 5270 |
4 | Stream | USGS-09537200 | USGS-09537200 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | National Geodetic Vertical Datum of 1929 | Interpolated from topographic map. | 150803010307 | 20 | https://waterdata.usgs.gov/monitoring-location... | LESLIE CREEK NEAR MCNEAL, AZ. | Stream | 09537200 | 4620. |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
187 | Stream | USGS-09403850 | USGS-09403850 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | National Geodetic Vertical Datum of 1929 | Interpolated from topographic map. | 150100031004 | 20 | https://waterdata.usgs.gov/monitoring-location... | KANAB CREEK ABOVE THE MOUTH NEAR SUPAI, AZ | Stream | 09403850 | 1920. |
188 | Stream | USGS-09429070 | USGS-09429070 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | North American Vertical Datum of 1988 | Interpolated from topographic map. | 150301040405 | 20 | https://waterdata.usgs.gov/monitoring-location... | CRIR LWR MAIN DRAIN BLW TYSON WW, NR EHRENBERG... | Stream | 09429070 | 272 |
189 | Stream | USGS-09402000 | USGS-09402000 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | National Geodetic Vertical Datum of 1929 | Unknown. | 150200160906 | 20 | https://waterdata.usgs.gov/monitoring-location... | LITTLE COLORADO RIVER NEAR CAMERON, AZ | Stream | 09402000 | 3979.20 |
190 | Stream | USGS-09535300 | USGS-09535300 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 04 | National Geodetic Vertical Datum of 1929 | Interpolated from topographic map. | 150801010512 | 20 | https://waterdata.usgs.gov/monitoring-location... | VAMORI WASH AT KOM VO, AZ | Stream | 09535300 | 1770. |
191 | Stream | USGS-09415000 | USGS-09415000 | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | https://labs.waterdata.usgs.gov/sta/v1.1/Thing... | Arizona | ... | 32 | National Geodetic Vertical Datum of 1929 | Level or other surveyed method. | 150100100602 | 1.0 | https://waterdata.usgs.gov/monitoring-location... | VIRGIN RV AT LITTLEFIELD, AZ | Stream | 09415000 | 1763.68 |
192 rows × 29 columns
We can get geospatial data by setting the format to geojson
.
[6]:
expand = {"Locations": {"select": "location"}}
max_count = 1000
conditionals = "properties/monitoringLocationType eq 'Stream' and properties/stateFIPS eq 'US:04'"
odata = sensor.odata_helper(expand=expand, max_count=max_count, conditionals=conditionals)
df = sensor.query_byodata(odata, outformat="geojson")
df.explore()
[6]:
We can even make more complex queries. For such cases we can use the odata_helper
function to contruct complex Odata filters.
[7]:
expand = {
"ObservedProperty": {"select": "name,description,@iot.id"},
"Observations": {
"select": "result,phenomenonTime,@iot.id",
"orderby": "phenomenonTime desc",
"top": 1,
},
}
odata_inner = sensor.odata_helper(expand=expand)
columns = ["properties", "@iot.id"]
conditionals = " and ".join(
[
"Datastreams/ObservedProperty/@iot.id eq '00060' ",
"properties/monitoringLocationType eq 'Stream' ",
"startswith(properties/hydrologicUnit,'15')",
]
)
expand = {
"Locations": {"select": "name,description,location,@iot.id"},
"Datastreams": {
"select": "name,unitOfMeasurement,@iot.id",
"filter": "ObservedProperty/@iot.id eq '00060'",
"expand": odata_inner["expand"],
},
}
max_count = 1000
odata = sensor.odata_helper(
columns=columns,
conditionals=conditionals,
expand=expand,
max_count=max_count,
)
df = sensor.query_byodata(odata, outformat="geojson")
df.explore()
[7]: