@@ -74,17 +74,27 @@ def get_all_active_usgs_sites():
74
74
75
75
#Cycle through each site and filter out if site doesn't meet criteria.
76
76
acceptable_sites_metadata = []
77
+ code_list_to_write = [['usgs_site_code' , 'nws_lid' , 'coord_acc' , 'coord_meth' , 'alt_acc' , 'alt_meth' , 'site_type' ]]
77
78
for metadata in metadata_list :
78
79
#Get the usgs info from each site
79
80
usgs_data = metadata ['usgs_data' ]
80
81
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
+
81
89
#Get site quality attributes
82
90
coord_accuracy_code = usgs_data .get ('coord_accuracy_code' )
83
91
coord_method_code = usgs_data .get ('coord_method_code' )
84
92
alt_accuracy_code = usgs_data .get ('alt_accuracy_code' )
85
93
alt_method_code = usgs_data .get ('alt_method_code' )
86
94
site_type = usgs_data .get ('site_type' )
87
95
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
+
88
98
#Check to make sure that none of the codes were null, if null values are found, skip to next.
89
99
if not all ([coord_accuracy_code , coord_method_code , alt_accuracy_code , alt_method_code , site_type ]):
90
100
continue
@@ -102,15 +112,15 @@ def get_all_active_usgs_sites():
102
112
103
113
#Append metadata of acceptable site to acceptable_sites list.
104
114
acceptable_sites_metadata .append (metadata )
105
-
115
+
106
116
#Get a geospatial layer (gdf) for all acceptable sites
107
117
dictionary , gdf = aggregate_wbd_hucs (acceptable_sites_metadata , Path (WBD_LAYER ), retain_attributes = False )
108
118
#Get a list of all sites in gdf
109
119
list_of_sites = gdf ['identifiers_usgs_site_code' ].to_list ()
110
120
#Rename gdf fields
111
121
gdf .columns = gdf .columns .str .replace ('identifiers_' ,'' )
112
122
113
- return gdf , list_of_sites , acceptable_sites_metadata
123
+ return gdf , list_of_sites , acceptable_sites_metadata , code_list_to_write
114
124
115
125
##############################################################################
116
126
#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):
240
250
#If 'all' option passed to list of gages sites, it retrieves all acceptable sites within CONUS.
241
251
print ('getting metadata for all sites' )
242
252
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
+
244
260
#Otherwise, if a list of sites is passed, retrieve sites from WRDS.
245
261
else :
246
262
#Define arguments to retrieve metadata and then get metadata from WRDS
0 commit comments