Hello all,
I have written a script to partially automate a supervised classification of a raster (my only interest is to differentiate water features from non-water features) and it worked seamlessly on several tests, but I am now encountering error(s) when I attempt to create signature file(s). I am running ArcGIS 10.2.1 (Advanced)
# Import python modules import arcpy, os, ntpath # Input Parameters classRast = arcpy.GetParameterAsText(0) trainSamp = arcpy.GetParameterAsText(1) aPriori = arcpy.GetParameterAsText(2) outDir = arcpy.GetParameterAsText(3) #Environments arcpy.env.workspace = outDir ws = arcpy.env.workspace arcpy.env.overwriteOutput = True def stripped(path): head, tail = ntpath.split(path) return tail or ntpath.basename(head) # Create Signatures from Shoreline Training Samples arcpy.AddMessage("Generating Signature File from Training Samples...") sigFile = outDir + "/TrainSignats.GSG" arcpy.gp.CreateSignatures_sa(classRast,trainSamp,sigFile,"COVARIANCE","Classvalue")
On one failed example, the inputs are:
classRast = m_3307811_ne_17_1_20130929.tif
trainSamp = S:/Software/Scripts and Tools/ShorelineTools/ExtractShorelines.gdb/ShorelineTrainingSamples
aPriori = S:/Software/Scripts and Tools/ShorelineTools/apriori.txt
outDir = T:/PERSONAL/Jimmy/SE USA/test5
I hit an error on line 22 stating:
Traceback (most recent call last):
File "T:\PERSONAL\Jimmy\Tools and References\python scripts\ExtractShorelines.py", line 29, in <module>
arcpy.gp.CreateSignatures_sa(classRast,trainSamp,sigFile,"COVARIANCE","Classvalue")
File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 010423: T:\PERSONAL\Jimmy\SE USA\test5\t_t285 does not have valid statistics as required by the operation.
ERROR 010159: Unable to open VAT file of t:\personal\jimmy\se~d1mse\test5\t_t285. ClassSig failed!
ERROR 010067: Error in executing grid expression.
Failed to execute (CreateSignatures).
I have tried building pyramids and statistics for the problem raster(s) prior to executing the script. I have also tried the raster(s) into GRID format, but neither of these approaches has changed the result. I have had some tiff rasters succeed but other tiffs fail and so far all jp2 files have failed. The location of the VAT file looks suspect as I'm not sure where the '\se~d1mse' portion of the filepath comes from or what it refers to. Any ideas why the CreateSignatures fails?
Solved! Go to Solution.
I found that in my case, the issue was with one of my input files and not with the code itself. Thank you to all who chimed in.
See if you get better results using forward slashes in your paths. '\t' means tab in Python.
thank you, I wrote these in incorrectly in the original post...in the actual script theses are user-defined parameters where the user can navigate to / select the folder or file...so the slash shouldn't be the issue
check and print it out... since it is just returning a string, there is no guarantee that it is properly interpreted... check the examples in my blog post... those are all examples that can be returned from tools. The fixes/checks are easy to fix in a script or tool.
to build on what everyone else is saying, here is an entire thread where file paths are discussed:
I found that in my case, the issue was with one of my input files and not with the code itself. Thank you to all who chimed in.