desc0107

model builder raster calculator converted to python script

Discussion created by desc0107 on Jun 26, 2011
Latest reply on Jun 28, 2011 by desc0107
I exported this from a working model builder tool and working on modifying to make it work in python.  In the end I would like to be able the automatically rename the output => input + ST_DEV + enh.tif .  

I am fairly new to Python so I am not there yet!  Python does not seam to recognize the map algebra from arcpy.gp.RasterCalculator_sa that was exported from Model Builder.   Therefore I decided to convert this part to straight python map algebra but I keep on getting errors for the code under # Process: Raster Calculator (1)

"RuntimeError: ERROR 000732: Input Raster: Dataset inRaster does not exist or is not supported."   This does not make sense to me since the inRaster is recognised in the previous 3 GetRasterProperties statements since the print statements are ouputting the right values?


Any suggestions on how to make this work??

# ---------------------------------------------------------------------------
# copy and past this at promt: 15May2011_HH_set_zero_8bit.tif 3 test.tif
# Import arcpy module
import arcpy
from arcpy import env
from arcpy.sa import *
import sys, string, os
arcpy.env.overwriteOutput = True

# Set Geoprocessing environments
arcpy.env.workspace = "C:/Alice"

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Script arguments
inRaster = arcpy.GetParameterAsText(0)
No_STDEV = arcpy.GetParameterAsText(1)
Output_Enhanced_8bit_SAR_Image = arcpy.GetParameterAsText(2)

# Process: Get Raster Properties (2)
imageMin=arcpy.GetRasterProperties_management(inRaster, "MINIMUM")
print "Image MIN value=", imageMin

# Process: Get Raster Properties (3)
imageMean=arcpy.GetRasterProperties_management(inRaster, "MEAN")
print "Image MEAN value=", imageMean

# Process: Get Raster Properties
imageSTDEV=arcpy.GetRasterProperties_management(inRaster, "STD")
print "Image STDEV value=", imageSTDEV

# Process: Raster Calculator (1)
enhImage=((Raster("inRaster") - imageMin) / ((imageMean + No_STDEV * imageSTDEV) - imageMin)) * 255

# Process: Raster Calculator (2)
outCon= Con(enhImage, enhImage, 255, "VALUE < 255")

# Process: Copy Raster
arcpy.CopyRaster_management(outCon, Output_Enhanced_8bit_SAR_Image, "", "", "", "NONE", "NONE", "8_BIT_UNSIGNED")

Outcomes