Skip to content

Commit

Permalink
fix delineation by gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshCu committed Aug 9, 2024
1 parent b000a10 commit 2d7c67f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions modules/data_processing/gpkg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ def get_wb_from_gage_id(gage_id: str, gpkg: Path = file_paths.conus_hydrofabric(
sql_query = f"SELECT id FROM hydrolocations WHERE hl_uri = 'Gages-{gage_id}'"
nex_id = con.execute(sql_query).fetchone()[0]
sql_query = f"SELECT id FROM network WHERE toid = '{nex_id}'"
wb_id = con.execute(sql_query).fetchone()[0]
wb_id = con.execute(sql_query).fetchall()
wb_ids = [str(x[0]) for x in wb_id]
if nex_id is None:
raise IndexError(f"No nexus found for gage ID {gage_id}")
return wb_id
return wb_ids
10 changes: 6 additions & 4 deletions modules/map_app/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ function get_wbid_from_gage_id(gage_id) {
})
.then(response => response.json())
.then(data => {
return data['wb_id'];
return data['wb_ids'];
})
.catch(error => {
console.error('Error:', error);
Expand All @@ -304,9 +304,11 @@ function select_by_gage_id() {
gage_ids = $('#gage_id_input').val();
gage_ids = gage_ids.split(',');
for (gage_id of gage_ids) {
wb_id = get_wbid_from_gage_id(gage_id);
wb_id.then(function (result) {
wb_id_dict[result] = [0, 0];
wb_ids = get_wbid_from_gage_id(gage_id);
wb_ids.then(function (result) {
for (result of result) {
wb_id_dict[result] = [0, 0];
}
$('#selected-basins').text(Object.keys(wb_id_dict));
});
}
Expand Down
2 changes: 1 addition & 1 deletion modules/map_app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,5 +354,5 @@ def get_wbid_from_gage_id():
gage_id = json.loads(request.data.decode("utf-8"))["gage_id"]
result = get_wb_from_gage_id(gage_id)
if result is not None:
return jsonify({"wb_id": result}), 200
return jsonify({"wb_ids": result}), 200
return jsonify({"error": "No wbid found for gage id"}), 404
3 changes: 2 additions & 1 deletion modules/ngiab_data_cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ def get_wb_ids_from_gage_ids(input_file: Path) -> List[str]:
wb_ids = []
for gage_id in gage_ids:
wb_id = get_wb_from_gage_id(gage_id)
wb_ids.append(wb_id)
wb_ids.extend(wb_id)
logging.info(f"Converted {len(gage_ids)} gage IDs to {len(wb_ids)} waterbody IDs")
return wb_ids


Expand Down

0 comments on commit 2d7c67f

Please sign in to comment.