cdsspy
The goal of cdsspy
is to provide functions that help Python users to navigate, explore, and make requests to the CDSS REST API web service.
The Colorado’s Decision Support Systems (CDSS) is a water management system created and developed by the Colorado Water Conservation Board (CWCB) and the Colorado Division of Water Resources (DWR).
Thank you to those at CWCB and DWR for providing an accessible and well documented REST API!
See cdssr
, for the R version of this package
Installation
Install the latest version of cdsspy
from PyPI:
pip install cdsspy
Available endpoints
Below is a table of all of the CDSS API endpoints cdsspy
provides functions for.
Identify query inputs using reference tables
The get_reference_tbl()
function will return tables that makes it easier to know what information should be supplied to the data retrieval functions in cdsspy
. For more information on the source reference tables click here.
telemetry_params = cdsspy.get_reference_tbl(
table_name = "telemetryparams"
)
| Parameter |
---|
0 | AIRTEMP |
1 | BAR_P |
2 | BATTERY |
3 | COND |
4 | D1 |
5 | D2 |
6 | DISCHRG |
7 | DISCHRG1 |
8 | DISCHRG2 |
9 | DISCHRG3 |
10 | DISCHRG4 |
11 | ELEV |
Locate structures
cdsspy
provides functions for locating structures/stations/wells/sites by providing a spatial extent, water district, division, county, designated basin, or management district to the functions in the table below. Site data can also be retrieved by providing the site specific abbreviations, GNIS IDs, USGS IDs, WDIDs, or Well IDs.
Example: Locating telemetry stations by county:
stations = cdsspy.get_telemetry_stations(
county = "Boulder"
)
Example: Locating telemetry stations around a point
stations = cdsspy.get_telemetry_stations(
aoi = [-105.358164, 40.092608],
radius = 15
)
Example: Locating telemetry stations within a spatial extent
A masking operation is performed when a location search is done using a polygon. This ensures that the function only returns points that are within the given polygon.
stations = cdsspy.get_telemetry_stations(
aoi = geopandas.read_file("https://cdsspy-images.s3.us-west-1.amazonaws.com/boulder_county.gpkg")
radius = 15
)
This gif highlights the masking process that happens when the aoi
argument is given a polygon
Retrieve time series data
The functions in the table below retrieve time series data from the various time series related CDSS API endpoints.
Example: Daily discharge at a telemetry station
We can then take a station abbreviations from the get_telemetry_stations()
call, a parameter from the get_reference_tbl()
call, and use this information as inputs into the get_telemetry_ts()
function.
The function below returns a dataframe of daily discharge for the "ANDDITCO" site between 2015-2022.
discharge_ts = cdsspy.get_telemetry_ts(
abbrev = "ANDDITCO",
parameter = "DISCHRG",
start_date = "2015-01-01",
end_date = "2022-01-01",
timescale = "day"
)
Example: Retrieve Diversion records for multiple structures
Some of the CDSS API endpoints allow users to request data from multiple structures if you provide a list of IDs. If we want to get diversion data from multiple structure locations, we'll need to get a list of WDIDs. We can get a list WDIDs within a given area by:
- Executing a spatial search using
get_structures()
- Selecting the WDIDs of interest from the search results
- Providing the WDIDs as a vector to
get_structures_divrec_ts()
structures = cdsspy.get_structures(
aoi = [-105.3578, 40.09244],
radius = 5
)
ditch_wdids = structures[(structures["ciuCode"] == "A") & (structures["structureType"] == "DITCH")]
ditch_wdids = list(ditch_wdids['wdid'])
diversion_rec = cdsspy.get_structures_divrec_ts(
wdid = ditch_wdids,
wc_identifier = "diversion",
timescale = "month"
)
Note: Data availability can vary between structures (i.e. Missing data, not all structures have every data type/temporal resolution available, etc.)
Retrieve groundwater data
The get_gw_()
set of functions lets users retrieve data from the various groundwater related API endpoints shown in the table below:
Here we will retrieve groundwater well measurement data for Well ID 1274 between 2021-2022.
well_measure = cdsspy.get_gw_wl_wellmeasures(
wellid = "1274",
start_date = "1990-01-01",
end_date = "2022-01-01"
)