From 2a016f1ffd1af381ad340b9f98e967a7c66438e4 Mon Sep 17 00:00:00 2001 From: Jemma Stachelek Date: Tue, 16 Apr 2024 10:21:50 -0600 Subject: [PATCH] pull initial vote data --- .gitignore | 3 ++- Makefile | 5 +++++ hydropop/streamflow/selecting_gages.py | 23 ++++++++++++----------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index ca374a7..b2876db 100644 --- a/.gitignore +++ b/.gitignore @@ -154,4 +154,5 @@ results/*.shp results/*.tif results/*.csv results/*.shx -data \ No newline at end of file +data +hydropop/config.py \ No newline at end of file diff --git a/Makefile b/Makefile index f79e3cf..91394df 100644 --- a/Makefile +++ b/Makefile @@ -10,3 +10,8 @@ clean: rabpro: pip install --upgrade -e ../rabpro + +initial_data: data/initial_basins.gpkg data/initial_gages.gpkg + +data/initial_basins.gpkg data/initial_gages.gpkg: hydropop/streamflow/selecting_gages.py + python $< diff --git a/hydropop/streamflow/selecting_gages.py b/hydropop/streamflow/selecting_gages.py index a7af1ae..e30cc38 100644 --- a/hydropop/streamflow/selecting_gages.py +++ b/hydropop/streamflow/selecting_gages.py @@ -1,12 +1,13 @@ +import os +import sys import geopandas as gpd -from VotE import config +sys.path.append(".") +from hydropop import config config.vote_db() from VotE.streamflow import export_streamflow as es -import os - -path_bounding_box = r"X:\Research\CIMMID\Data\Hydropop Layers\Finals\toronto_coarse\roi.gpkg" # shapefile of ROI +path_bounding_box = r"data/roi_small.gpkg" bb = gpd.read_file(path_bounding_box) gage_params = { "within": bb.geometry.values[0], @@ -44,22 +45,22 @@ # gages = es.get_gages(current_gages['id_gage'].values.tolist()) gage_locs.to_file( - r"X:\Research\CIMMID\Data\Watersheds\Toronto\initial_gages.gpkg", driver="GPKG" + r"data/initial_gages.gpkg", driver="GPKG" ) basins.to_file( - r"X:\Research\CIMMID\Data\Watersheds\Toronto\initial_basins.gpkg", driver="GPKG" + r"data/initial_basins.gpkg", driver="GPKG" ) """ Download streamflow data """ +path_dir = "data/na_10k/streamflow/" +os.makedirs(path_dir, exist_ok=True) + for id_gage in basins["id_gage"].values: print(id_gage) df = es.get_streamflow_timeseries( [int(id_gage)], start_date="1981-01-01", expand=True, trim=True ) df.drop("id_gage", inplace=True, axis=1) - df.sort_values(by="date", inplace=True) - path_out = os.path.join( - r"X:\Research\CIMMID\Data\Hydropop Layers\Finals\na_10k\streamflow", - str(id_gage) + ".csv", - ) + df.sort_values(by="date", inplace=True) + path_out = path_dir + str(id_gage) + ".csv" df.to_csv(path_out, index=False)