Skip to content

Commit

Permalink
formatting with black
Browse files Browse the repository at this point in the history
  • Loading branch information
jsta committed Apr 16, 2024
1 parent 79743de commit c7ae0e9
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions hydropop/streamflow/selecting_gages.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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)

0 comments on commit c7ae0e9

Please sign in to comment.