Skip to content

Commit e9e7e80

Browse files
Testing code`
1 parent 9fba7a9 commit e9e7e80

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tools/rating_curve_get_usgs_curves.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,27 @@ def get_all_active_usgs_sites():
7474

7575
#Cycle through each site and filter out if site doesn't meet criteria.
7676
acceptable_sites_metadata = []
77+
code_list_to_write = [['usgs_site_code', 'nws_lid', 'coord_acc', 'coord_meth', 'alt_acc', 'alt_meth', 'site_type']]
7778
for metadata in metadata_list:
7879
#Get the usgs info from each site
7980
usgs_data = metadata['usgs_data']
8081

82+
usgs_site_code = metadata['identifiers']['usgs_site_code']
83+
84+
try:
85+
nws_lid = metadata['identifiers']['nws_lid']
86+
except:
87+
nws_lid = None
88+
8189
#Get site quality attributes
8290
coord_accuracy_code = usgs_data.get('coord_accuracy_code')
8391
coord_method_code = usgs_data.get('coord_method_code')
8492
alt_accuracy_code = usgs_data.get('alt_accuracy_code')
8593
alt_method_code = usgs_data.get('alt_method_code')
8694
site_type = usgs_data.get('site_type')
8795

96+
code_list_to_write.append([usgs_site_code, nws_lid, coord_accuracy_code, coord_method_code, alt_accuracy_code, alt_method_code, site_type])
97+
8898
#Check to make sure that none of the codes were null, if null values are found, skip to next.
8999
if not all([coord_accuracy_code, coord_method_code, alt_accuracy_code, alt_method_code, site_type]):
90100
continue
@@ -102,15 +112,15 @@ def get_all_active_usgs_sites():
102112

103113
#Append metadata of acceptable site to acceptable_sites list.
104114
acceptable_sites_metadata.append(metadata)
105-
115+
106116
#Get a geospatial layer (gdf) for all acceptable sites
107117
dictionary, gdf = aggregate_wbd_hucs(acceptable_sites_metadata, Path(WBD_LAYER), retain_attributes = False)
108118
#Get a list of all sites in gdf
109119
list_of_sites = gdf['identifiers_usgs_site_code'].to_list()
110120
#Rename gdf fields
111121
gdf.columns = gdf.columns.str.replace('identifiers_','')
112122

113-
return gdf, list_of_sites, acceptable_sites_metadata
123+
return gdf, list_of_sites, acceptable_sites_metadata, code_list_to_write
114124

115125
##############################################################################
116126
#Generate categorical flows for each category across all sites.
@@ -240,7 +250,13 @@ def usgs_rating_to_elev(list_of_gage_sites, workspace=False, sleep_time = 1.0):
240250
#If 'all' option passed to list of gages sites, it retrieves all acceptable sites within CONUS.
241251
print('getting metadata for all sites')
242252
if list_of_gage_sites == ['all']:
243-
acceptable_sites_gdf, acceptable_sites_list, metadata_list = get_all_active_usgs_sites()
253+
acceptable_sites_gdf, acceptable_sites_list, metadata_list, code_list_to_write = get_all_active_usgs_sites()
254+
255+
import csv
256+
with open(os.path.join(workspace, 'all_codes.csv'), 'w+', newline ='') as f:
257+
write = csv.writer(f)
258+
write.writerows(code_list_to_write)
259+
244260
#Otherwise, if a list of sites is passed, retrieve sites from WRDS.
245261
else:
246262
#Define arguments to retrieve metadata and then get metadata from WRDS

0 commit comments

Comments
 (0)