Skip to content

Commit a23d1d8

Browse files
committed
add agency to nwis site numbers
1 parent a5d0b59 commit a23d1d8

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

backend/connectors/usgs/source.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,12 @@ def parse_json(data):
7676

7777
for location in data["timeSeries"]:
7878
site_code = location["sourceInfo"]["siteCode"][0]["value"]
79+
agency = location["sourceInfo"]["siteCode"][0]["agencyCode"]
7980
source_parameter_name = location["variable"]["variableName"]
8081
source_parameter_units = location["variable"]["unit"]["unitCode"]
8182
for value in location["values"][0]["value"]:
8283
record = {
83-
"site_code": site_code,
84+
"site_id": f"{agency}-{site_code}",
8485
"source_parameter_name": source_parameter_name,
8586
"value": value["value"],
8687
"datetime_measured": value["dateTime"],
@@ -150,12 +151,16 @@ def __repr__(self):
150151
return "NWISWaterLevelSource"
151152

152153
def get_records(self, site_record):
154+
# query sites with the agency, which need to be in the form of "{agency}:{site number}"
155+
sites = make_site_list(site_record)
156+
sites_with_colons = [s.replace("-", ":") for s in sites]
157+
153158
params = {
154159
"format": "json",
155160
"siteType": "GW",
156161
"siteStatus": "all",
157162
"parameterCd": "72019",
158-
"sites": ",".join(make_site_list(site_record)),
163+
"sites": ",".join(sites_with_colons),
159164
}
160165

161166
config = self.config
@@ -178,7 +183,7 @@ def get_records(self, site_record):
178183
return records
179184

180185
def _extract_site_records(self, records, site_record):
181-
return [ri for ri in records if ri["site_code"] == site_record.id]
186+
return [ri for ri in records if ri["site_id"] == site_record.id]
182187

183188
def _clean_records(self, records):
184189
return [

backend/connectors/usgs/transformer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ def _transform(self, record):
3232
# if not self.contained(lng, lat):
3333
# return
3434

35+
agency = record["agency_cd"]
36+
site_no = record["site_no"]
37+
site_id = f"{agency}-{site_no}"
38+
3539
rec = {
3640
"source": "USGS-NWIS",
37-
"id": record["site_no"],
41+
"id": site_id,
3842
"name": record["station_nm"],
3943
"latitude": lat,
4044
"longitude": lng,

0 commit comments

Comments
 (0)