From c7ae0e913ae4ab99364189980a4bb39a5c08acff Mon Sep 17 00:00:00 2001 From: Jemma Stachelek Date: Tue, 16 Apr 2024 09:13:35 -0600 Subject: [PATCH] formatting with black --- hydropop/streamflow/selecting_gages.py | 70 ++++++++++++++------------ 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/hydropop/streamflow/selecting_gages.py b/hydropop/streamflow/selecting_gages.py index de5d4a2..a7af1ae 100644 --- a/hydropop/streamflow/selecting_gages.py +++ b/hydropop/streamflow/selecting_gages.py @@ -1,39 +1,39 @@ -# -*- coding: utf-8 -*- -""" -Created on Mon Sep 12 14:45:03 2022 - -@author: 318596 -""" import geopandas as gpd from VotE 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"X:\Research\CIMMID\Data\Hydropop Layers\Finals\toronto_coarse\roi.gpkg" # shapefile of ROI bb = gpd.read_file(path_bounding_box) -gage_params = {'within' : bb.geometry.values[0], - 'max_drainarea_km2' : 10000, - 'fraction_valid' : .9, - 'vote_snapped' : True, - 'end_date': '2000-01-01', - 'min_span_years' : 10 - } +gage_params = { + "within": bb.geometry.values[0], + "max_drainarea_km2": 10000, + "fraction_valid": 0.9, + "vote_snapped": True, + "end_date": "2000-01-01", + "min_span_years": 10, +} gage_ids = es.gage_selector(gage_params) gages = es.get_gages(gage_ids) # Export the gages and their watersheds (two files) -keepkeys = [k for k in gages.keys() if 'geom' not in k] -keepkeys = [k for k in keepkeys if 'chunk' not in k] -keepkeys.remove('id_duplicates') -gage_locs = gpd.GeoDataFrame(data=gages[keepkeys], geometry=gages['mapped_geom'], crs=gages.crs) -basins = gpd.GeoDataFrame(data=gages[keepkeys], geometry=gages['basin_geom_vote'], crs=gages.crs) +keepkeys = [k for k in gages.keys() if "geom" not in k] +keepkeys = [k for k in keepkeys if "chunk" not in k] +keepkeys.remove("id_duplicates") +gage_locs = gpd.GeoDataFrame( + data=gages[keepkeys], geometry=gages["mapped_geom"], crs=gages.crs +) +basins = gpd.GeoDataFrame( + data=gages[keepkeys], geometry=gages["basin_geom_vote"], crs=gages.crs +) -gage_locs['start_date'] = gage_locs['start_date'].astype(str) -gage_locs['end_date'] = gage_locs['end_date'].astype(str) -basins['start_date'] = basins['start_date'].astype(str) -basins['end_date'] = basins['end_date'].astype(str) +gage_locs["start_date"] = gage_locs["start_date"].astype(str) +gage_locs["end_date"] = gage_locs["end_date"].astype(str) +basins["start_date"] = basins["start_date"].astype(str) +basins["end_date"] = basins["end_date"].astype(str) # gage_locs.to_file(r'X:\Research\CIMMID\Data\Hydropop Layers\Finals\na_10k\gage_selection\na_10k_gages.gpkg', driver='GPKG') # basins.to_file(r'X:\Research\CIMMID\Data\Hydropop Layers\Finals\na_10k\gage_selection\na_10k_basins.gpkg', driver='GPKG') @@ -43,15 +43,23 @@ # current_gages = gpd.read_file(current_gages) # 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') -basins.to_file(r'X:\Research\CIMMID\Data\Watersheds\Toronto\initial_basins.gpkg', driver='GPKG') +gage_locs.to_file( + r"X:\Research\CIMMID\Data\Watersheds\Toronto\initial_gages.gpkg", driver="GPKG" +) +basins.to_file( + r"X:\Research\CIMMID\Data\Watersheds\Toronto\initial_basins.gpkg", driver="GPKG" +) """ Download streamflow data """ -for id_gage in basins['id_gage'].values: +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 = 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.to_csv(path_out, index=False) -