|
44 | 44 | # NRCS AWDB network codes to download
|
45 | 45 | NETWORKS = ["SNTL", "SNOW", "USGS", "COOP", "SCAN", "SNTLT", "OTHER", "BOR",
|
46 | 46 | "MPRC", "MSNT"]
|
| 47 | +#NETWORKS = ["USGS"] |
47 | 48 |
|
48 | 49 |
|
49 | 50 | ## Dictionaries of the station fields
|
@@ -717,6 +718,77 @@ def get_USGS_metadata(usgs_fc):
|
717 | 718 | # no exception so data valid, update row
|
718 | 719 | cursor.updateRow(row)
|
719 | 720 |
|
| 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)) |
720 | 792 |
|
721 | 793 | def write_to_summary_log(message):
|
722 | 794 | """
|
@@ -802,16 +874,16 @@ def main():
|
802 | 874 | write_to_summary_log("{}: stations_{} processing FAILED".format(datetime.now(), network))
|
803 | 875 | continue
|
804 | 876 |
|
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 |
815 | 887 |
|
816 | 888 | try:
|
817 | 889 | projectedfc = arcpy.Project_management(fc, os.path.join(templocation, fc_name), prjSR) # from unprjSR to prjSR
|
@@ -858,6 +930,10 @@ def main():
|
858 | 930 |
|
859 | 931 | # end processing of network
|
860 | 932 |
|
| 933 | + # create forecast webservice |
| 934 | + # Commenting out. Not ready to use yet |
| 935 | + # create_forecast_point_ws() |
| 936 | + |
861 | 937 | if wfsupdatelist:
|
862 | 938 | LOGGER.info("\nUpdating AGOL feature services in update list...")
|
863 | 939 | for wfspath in wfsupdatelist:
|
|
0 commit comments