I am trying to normalize the raster in arcpy
by unchanged location over time. As such, I
- read the raster ('inRaster')
- read unchanged locations as polygon ('inPoly')
- Extract by mask unchanged location
- calculate MEAN and SD of unchanged extracted land
- normalize original raster by values of unchanged land
Everything works great until step 5, where I got an error:
RuntimeError: ERROR 000732: Input Raster: Dataset 0.152711537046664 does not exist or is not supported
Well, my Input Raster
had somehow to changed, as the Dataset 0.152711537046664 represents exactly my mean value... When I let to print all values (mean, SD, inRaster
andoutRaster
), my input variables seem correct:
inRaster is C:/Users/ndvi_0419
Mean is 0.152711537046664
SD is 2.85148713249969E-02
outRaster is C:/Users/norm_ndvi_0419
For normalization formula, I am using arcpy.sa
algebra, suggested here: Using Loop with Raster Calculator in ArcPy?
normRaster = (Raster(inRaster) - rMean)/rSD
Do you know what could be the issue in my code?
My whole code:
# Import modules
import itertools, arcpy, os
# import envronmental settings
from arcpy import env
from arcpy.sa import *
# Define working environment
inWD = "C:/Users/analyzed"
# Set Snap Raster environment
arcpy.env.snapRaster = os.path.join(inWD, "rectif.gdb/r_20160502")
# Define variables
inRaster = os.path.join(inWD, "VI.gdb", "ndvi_0419")
inPoly = os.path.join(inWD, "normBlackSquare.gdb", "n_0419")
# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")
# Execute ExtractByMask
outExtractByMask = arcpy.sa.ExtractByMask(inRaster, inPoly)
#Get raster properties: Mean and STD
rMean = arcpy.GetRasterProperties_management(outExtractByMask, "MEAN")
rSD = arcpy.GetRasterProperties_management(outExtractByMask, "STD")
# Save the output
outName = os.path.basename(inRaster)
outRaster = os.path.join(inWD, "normVI.gdb", outName)
# Print values to check if inputs are correct
print "inRaster is " + inRaster
print "Mean is " + str(rMean)
print "SD is " + str(rSD)
print "outRaster is " + outRaster
# This formula seems not to work right!!!
normRaster = (Raster(inRaster) - rMean)/rSD
#normRaster.save(outRaster)
# print "Normalized raster saved"
#Return (check-in) the spatial extension
arcpy.CheckInExtension("spatial")