Skip to content

Commit 31dd547

Browse files
authored
Merge pull request #11 from lbross/master
Removes call to USGS REST service
2 parents 6d72390 + 15f17a8 commit 31dd547

File tree

2 files changed

+86
-10
lines changed

2 files changed

+86
-10
lines changed

get_AWDB_stations_3.py

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
# NRCS AWDB network codes to download
4545
NETWORKS = ["SNTL", "SNOW", "USGS", "COOP", "SCAN", "SNTLT", "OTHER", "BOR",
4646
"MPRC", "MSNT"]
47+
#NETWORKS = ["USGS"]
4748

4849

4950
## Dictionaries of the station fields
@@ -717,6 +718,77 @@ def get_USGS_metadata(usgs_fc):
717718
# no exception so data valid, update row
718719
cursor.updateRow(row)
719720

721+
def create_forecast_point_ws():
722+
from arcpy import CopyFeatures_management
723+
import arcpy
724+
725+
bUSGSExists = False
726+
bBORExists = False
727+
LOGGER.info("create_forecast_point_ws...")
728+
729+
USGS_Active = "active_stations_USGS"
730+
if arcpy.Exists(os.path.join(settings.AWDB_FGDB_PATH, USGS_Active)):
731+
bUSGSExists = True
732+
BOR_Active = "active_stations_BOR"
733+
if arcpy.Exists(os.path.join(settings.AWDB_FGDB_PATH, BOR_Active)):
734+
bBORExists = True
735+
FCST_Active = "active_stations_FCST"
736+
737+
if (bUSGSExists and bBORExists):
738+
client = Client(settings.WDSL_URL)
739+
# get list of station IDs in network
740+
data = None
741+
forecastIDs = []
742+
data = client.service.getForecastPoints(networkCds="USGS",logicalAnd="true")
743+
if data:
744+
for station in data:
745+
try:
746+
forecastIDs.append(station["stationTriplet"])
747+
except:
748+
pass
749+
numberofstations = len(data)
750+
LOGGER.info('We processed %d records', numberofstations)
751+
LOGGER.info('%d records in array', len(forecastIDs))
752+
BOR_Temp_Active = "temp_" + BOR_Active
753+
sourceFc = os.path.join(settings.AWDB_FGDB_PATH, USGS_Active)
754+
targetFc = os.path.join(settings.AWDB_FGDB_PATH, FCST_Active)
755+
CopyFeatures_management(sourceFc, targetFc)
756+
LOGGER.info("Before %d records", getCount(targetFc))
757+
with arcpy.da.UpdateCursor(targetFc, ('stationTriplet')) as curs:
758+
for row in curs:
759+
test_triplet = row[0]
760+
if (test_triplet not in forecastIDs):
761+
curs.deleteRow()
762+
LOGGER.info("After %d records", getCount(targetFc))
763+
sourceFc = os.path.join(settings.AWDB_FGDB_PATH, BOR_Active)
764+
targetFc = os.path.join(settings.AWDB_FGDB_PATH, BOR_Temp_Active)
765+
CopyFeatures_management(sourceFc, targetFc)
766+
forecastIDs.clear()
767+
data = client.service.getForecastPoints(networkCds="BOR",logicalAnd="true")
768+
if data:
769+
for station in data:
770+
try:
771+
forecastIDs.append(station["stationTriplet"])
772+
except:
773+
pass
774+
numberofstations = len(data)
775+
LOGGER.info('%d records in array', len(forecastIDs))
776+
with arcpy.da.UpdateCursor(targetFc, ('stationTriplet')) as curs:
777+
for row in curs:
778+
test_triplet = row[0]
779+
if (test_triplet not in forecastIDs):
780+
curs.deleteRow()
781+
LOGGER.info("After %d records", getCount(targetFc))
782+
783+
784+
785+
786+
else:
787+
LOGGER.error("unable to locate {0} and or {1}. Forecast service will not be updated".format(USGS_Active, BOM_Active))
788+
789+
def getCount(fc):
790+
import arcpy
791+
return int(arcpy.GetCount_management(fc).getOutput(0))
720792

721793
def write_to_summary_log(message):
722794
"""
@@ -802,16 +874,16 @@ def main():
802874
write_to_summary_log("{}: stations_{} processing FAILED".format(datetime.now(), network))
803875
continue
804876

805-
if network == "USGS":
806-
LOGGER.info("USGS data requires area from USGS web service. Retreiving...")
807-
try:
808-
get_USGS_metadata(fc)
809-
except Exception as e:
810-
LOGGER.log(15, e)
811-
LOGGER.log(15, traceback.format_exc())
812-
LOGGER.error("Failed to retrieve the USGS area data. Could not continue.")
813-
write_to_summary_log("{}: stations_{} processing FAILED".format(datetime.now(), network))
814-
continue
877+
#if network == "USGS":
878+
# LOGGER.info("USGS data requires area from USGS web service. Retreiving...")
879+
# try:
880+
# get_USGS_metadata(fc)
881+
# except Exception as e:
882+
# LOGGER.log(15, e)
883+
# LOGGER.log(15, traceback.format_exc())
884+
# LOGGER.error("Failed to retrieve the USGS area data. Could not continue.")
885+
# write_to_summary_log("{}: stations_{} processing FAILED".format(datetime.now(), network))
886+
# continue
815887

816888
try:
817889
projectedfc = arcpy.Project_management(fc, os.path.join(templocation, fc_name), prjSR) # from unprjSR to prjSR
@@ -858,6 +930,10 @@ def main():
858930

859931
# end processing of network
860932

933+
# create forecast webservice
934+
# Commenting out. Not ready to use yet
935+
# create_forecast_point_ws()
936+
861937
if wfsupdatelist:
862938
LOGGER.info("\nUpdating AGOL feature services in update list...")
863939
for wfspath in wfsupdatelist:

lib/suds_jurko.zip

300 KB
Binary file not shown.

0 commit comments

Comments
 (0)