OK. So this mostly works. One problem that I am having is getting M for missing to be ignored rather that treated as a 0 but I will get that resolved eventually. #! /usr/bin/python # # Format a csv for further processing # #import time import csv import array import decimal decimal.getcontext().prec = 4 from time import gmtime, strftime print strftime("%Y-%m-%d %H:%M:%S", gmtime()) # Create an unordered MON to column number dictionary and get user data mdict = {'MAR': 11, 'FEB': 10, 'AUG': 16, 'SEP': 17, 'APR': 12, 'JUN': 14, 'JUL': 15, 'JAN': 9, 'MAY': 13, 'NOV': 19, 'DEC': 20, 'OCT': 18} month_start = raw_input('Input the 3 letter ID of beginning month: ') month_end = raw_input('Input the 3 letter ID of ending month: ') month_start = month_start.upper() month_end = month_end.upper() mon_layer_name = month_start + ' through ' +month_end user_month = '[' + mon_layer_name + ']' start_num = mdict[month_start] end_num = mdict[month_end]+1 new_list = [['Station', 'Lat', 'Long', 'mysum']] with open('R:\\COOP\\temp\\COOP_rainfall2.csv', 'rb') as csvfile: #with open('Z:\\Desktop\\COOP_rainfall2.csv', 'rb') as csvfile: filereader = csv.reader(csvfile) filereader.next() #skip header line for row in filereader: sta = row[0] lat = row[2] lon = row[3] tot = decimal.Decimal(0) for x in row[start_num:end_num]: if x == '' : x = 0 elif x == 'M': x = 0 tot = tot + decimal.Decimal(x) if tot == 0: continue # No zeros allowed so don't append line else: new_list.append([sta, lat, lon, str(tot)]) with open('R:\\COOP\\temp\\output.csv', 'wb') as csvout: #with open('Z:\\Desktop\\output.csv', 'wb') as csvout: filewriter = csv.writer(csvout) for line in new_list: filewriter.writerow(line) Rex = 'R:\\COOP\\temp\\output.csv' Precip=[] #creating an array named Precip inp = open (Rex,"r") for line in inp.readlines(): line.split(',') Precip.append(line) file.close(inp) COOP = 'R:\\COOP\\temp\\output.csv' # # ARCGIS Processing begins here # # # Determine Max, Min, and Diff Values templist = [] data = open (COOP, 'r') lines = str(data.read()).splitlines() for line in lines: if 'Lat,Long' not in line: line = line.split(',') value = line[int(3)] templist.append(float(value)) maxV = max(templist) minV = min(templist) diff = float(maxV) - float(minV) #print 'MAX ' + str(maxV) #print 'MIN ' + str(minV) #print 'DIFF ' + str(diff) month = month_start + ' through ' + month_end months = month usermonth = "[" + months + "]" # Import arcpy module import arcpy import arcpy.mapping # Check out any necessary licenses arcpy.CheckOutExtension("spatial") import sys, string, os # Directories ClipShape = "R:/fxc/Western Region FXC Packet/GGW.shp" webdir = 'R:/COOPImages/' tempdir = 'CSV\\' directory = 'N:\\climate\\ClimateSheets\\' + str(tempdir) # Local variables: GGW_Counties = "R:\\fxc\\Western Region FXC Packet\\GGW.shp" Var_layer = 'mysum' Var_shp = str(directory) + 'Var.shp' spRef = r"Coordinate Systems\Geographic Coordinate Systems\World\WGS 1984.prj" print 'Made it through Local variables' # Import Arcview import arcview import sys, string, os, arcgisscripting gp = arcgisscripting.create(10.1) gp.SetProduct("ArcView") # or ArcEditor or ArcInfo gp.overwriteoutput = 1 arcpy.overwriteOutput = True print 'Made it through import arcview' # Process: Make XY Event Layer long = 'Long' lat = 'Lat' arcpy.MakeXYEventLayer_management(COOP, long, lat, Var_layer, spRef, "") #COOP is defined in line 103 of code as Z:\\Desktop\\test3.csv #edited 3-15-2013 print 'Make XY Event Layer Done' # Process: Copy Features arcpy.CopyFeatures_management(Var_layer, Var_shp, "", "0", "0", "0") print 'Copy Features Done' # created the COOP folder on the R drive COOPdir = 'R:/COOP/' COOPtempdir = COOPdir + 'temp/' contour = 'Y' # Conduct remaining code if grid contains values greater than zero if float(maxV) > 0.00: # Execute Interpolation outRaster = COOPtempdir + 'Pre' outContourRaster = COOPtempdir + 'Pre' + 'CRas' from arcpy import env env.extent = "-108.891024 46.540403 -104.041596 49.000024" from arcpy.sa import * #make sure 'mysum' is named correctly when copying over outTTR = TopoToRaster([TopoPointElevation([[Var_shp, 'mysum']])], "0.01", "", "20", "", "", "NO_ENFORCE", "SPOT", "", "", "", "", "", "") #make sure 'mysum' is named correctly outTTR.save(outRaster) outTTR = TopoToRaster([TopoPointElevation([[Var_shp, 'mysum']])], "0.1", "", "20", "", "", "NO_ENFORCE", "SPOT", "", "", "", "", "", "") outTTR.save(outContourRaster) print 'Interpolation Done' #Execute Clip of Raster FinalGridImage = COOPtempdir + 'PrecipTotal.img' arcpy.Clip_management(outRaster, "", FinalGridImage, ClipShape, "", "ClippingGeometry") print 'Raster Clip Done' #Calculate Contour Interval and Layer Value # Contour Interval if contour == 'Y': if float(diff) < 0.25: interval = '0.01' if float(diff) >= 0.25 and float(diff) <= 0.50: interval = '0.05' if float(diff) >= 0.50 and float(diff) <= 1.00: interval = '0.10' if float(diff) >= 1.01 and float(diff) <= 3.00: interval = '0.25' if float(diff) >= 3.01 and float(diff) <= 5.00: interval = '0.50' if float(diff) >= 5.01: interval = '1.00' # Layer Value if float(maxV) < 0.25: imagelayer = 'Precip_0.25' if float(maxV) > 0.25 and float(maxV) <= 0.50: imagelayer = 'Precip_0.50' if float(maxV) > 0.50 and float(maxV) <= 1.00: imagelayer = 'Precip_1' if float(maxV) > 1.00 and float(maxV) <= 2.00: imagelayer = 'Precip_2' if float(maxV) > 2.00 and float(maxV) <= 3.00: imagelayer = 'Precip_3' if float(maxV) > 3.00 and float(maxV) <= 4.00: imagelayer = 'Precip_4' if float(maxV) > 4.00 and float(maxV) <= 6.00: imagelayer = 'Precip_6' if float(maxV) > 6.00 and float(maxV) <= 8.00: imagelayer = 'Precip_8' if float(maxV) > 8.00 and float(maxV) <= 10.00: imagelayer = 'Precip_10' if float(maxV) > 10.00: imagelayer = 'Precip_12' if contour == 'Y': # Execute Contours print 'Contouring Using Interval: ' + str(interval) outContours = COOPtempdir + 'PrecipContours.shp' # still need to create the PrecipContours.shp file Contour(outContourRaster, outContours, interval, '0') # Assign mxd variable # Created the PrecipTotal.mxd file mxd1 = arcpy.mapping.MapDocument(COOPdir + 'PrecipTotal.mxd') # Activate Correct Layer print 'Image Layer: ' + imagelayer for lyr in arcpy.mapping.ListLayers(mxd1): layername = str(lyr) if str(imagelayer) in layername: print 'Using Scale: ' + str(layername) lyr.visible = True break print '-Exporting Precip Graphic-' outputpathfull = webdir + months + ".png" arcpy.mapping.ExportToPNG(mxd1, outputpathfull, resolution=100) # Process: Define Projection for Shapefile in order to plot record values correctly ggw_shp = 'R:\\fxc\\Western Region FXC Packet\\GGW.shp' dsc = arcpy.Describe(ggw_shp) coord_sys = dsc.SpatialReference arcpy.DefineProjection_management(Var_shp, coord_sys) print 'Define Projection Done' print 'Exporting Map' from datetime import date now = date.today().isoformat() mxd1 = arcpy.mapping.MapDocument(COOPtempdir + 'PrecipTotal.mxd') #newtitle = arcpy.mapping.ListLayoutElements(mxd3, "TEXT_ELEMENT", "title")[0] print 'Map is complete and located at ' + outputpathfull
I hope that this helps someone or inspires someone to so something similar. I could not have made it this far without the help of Josh Barnwell and Rob Oslund, Thanks guys. I have added an image created. I am still battling small things that would make this a little nicer but it does work somewhat.;)