You are on page 1of 2

import sys, os, arcpy, time importPath = os.path.dirname(sys.argv[0]) sys.path.append(importPath) arcpy.

AddMessage("Starting FAWN interpolation tool") #import procedures and classes, set to reload import CSV_cleanup, dataSort, classSort, DataFetcher debug = True if debug == True: reload(CSV_cleanup) reload(dataSort) reload(classSort) reload(DataFetcher) arcpy.CheckOutExtension("Spatial")# Check out the ArcGIS Spatial Analyst extensi on license FAWNdataPath = sys.argv[1] TempPath = sys.argv[2] startDate = sys.argv[3] endDate = sys.argv[4] attCall = sys.argv[5] readTime = 2 arcpy.env.overwriteOutput = True #set overwrite options arcpy.env.workspace = TempPath #set workspace arcpy.SetProgressor("Default", "FAWN Interpolation Tool") time.sleep(readTime) fawnData = os.listdir(FAWNdataPath) #downloads and unzips current 2012 data file DataFetcher.getcurrentdata(FAWNdataPath) #Collects the date range that the users wants Start = dataSort.dateConverter(startDate) End = dataSort.dateConverter(endDate) #Collects the attribute that the user wants attributes = {"AvgSoilTemp":2,"AvgAirTemp":3,"Rain":4,"ET":5} TempFile = "/temp_data_" #prepare the files for analysis in ArcMap arcpy.AddMessage("Processing Data Files") time.sleep(readTime) for file in fawnData: InDataFile = os.path.join(FAWNdataPath, file) OutDataFile = TempPath + TempFile + file #define output data file names dscObject = arcpy.Describe(InDataFile) if dscObject.dataType == "TextFile": if not "temp_data_" in file: if not "notNeeded" in file: CSV_cleanup.removeExLines(InDataFile, OutDataFile) #clean up the csv data CSV_cleanup.removeColumns(OutDataFile, OutDataFile) CSV_cleanup.removeNullValues(OutDataFile, OutDataFile) dataSort.sortByDate(OutDataFile, OutDataFile, Start[0], Start[1] , Start[2], End[0], End[1], End[2]) #sort data by date stationAvg = classSort.sort(OutDataFile, OutDataFile, attributes [attCall]) #sort data by attribute stationAvg.attributeAverage() #average data value to be used in interpolation model arcpy.AddMessage("Calculating " + attCall) time.sleep(readTime) fileList = [] #create a list of files TempData = os.listdir(TempPath) for file in TempData: if "temp_data_" in file: if not "notNeeded" in file:

fileList.append(file) #merge the to csv datafiles together outputMerge = os.path.join(TempPath, "FawnDataMerged.dbf") arcpy.Merge_management (fileList, outputMerge) StationLoc = os.path.join(FAWNdataPath, "Stations.shp") arcpy.DeleteField_management (StationLoc, "Field2") #Next 2 lines manage table f or repeated use arcpy.DeleteField_management (StationLoc, "Value") arcpy.AddField_management (StationLoc, "Value", "DOUBLE", 6, 2) #Creates new col umn #Add the attribute data to the x/y station locations data arcpy.JoinField_management (StationLoc, "Station_Nu", outputMerge, "Field1", ["F ield2"]) barrier = os.path.join(FAWNdataPath, "FLORIDA_Project.shp") #restricts the inter polation to within the state boundary # Execute Spline with Barriers arcpy.AddMessage("Performing Spline Interpolation") time.sleep(readTime) if attCall == "AvgSoilTemp" or attCall == "AvgAirTemp": #Converts from C to F arcpy.CalculateField_management (StationLoc, "Value", "(1.8 * float(!Field2! )) + 32", "PYTHON") elif attCall == "ET": # Converts from mm to inches arcpy.CalculateField_management (StationLoc, "Value", "(float(!Field2!) * 0. 0394)", "PYTHON") else: arcpy.CalculateField_management (StationLoc, "Value", "float(!Field2!)", "PY THON") splineResults = arcpy.sa.SplineWithBarriers(StationLoc, "Value", barrier) # Save the output Spline_raster = os.path.join(TempPath, "SplineResults") splineResults.save(Spline_raster) maskResults = arcpy.sa.ExtractByMask (Spline_raster, barrier) Mask_raster = os.path.join(TempPath, "FAWNresults") maskResults.save(Mask_raster) arcpy.SetParameterAsText(5, Mask_raster) # Sets the symbology of the output based on the attribute calculating(next 13 li nes) # also makes the symbology transportable RainLyr = os.path.join(FAWNdataPath, "FAWNresultsRain.lyr") ETLyr = os.path.join(FAWNdataPath, "FAWNresultsET.lyr") TempLyr = os.path.join(FAWNdataPath, "FAWNresultsTemp.lyr") Stationlyr = os.path.join(FAWNdataPath, "Stations.lyr") params = arcpy.GetParameterInfo() if attCall == "ET": params[5].symbology = ETLyr elif attCall == "Rain": params[5].symbology = RainLyr else: params[5].symbology = TempLyr arcpy.SetParameterAsText(6, StationLoc) params[6].symbology = Stationlyr arcpy.AddMessage("Finishing Calculation")

You might also like