Script works in 10.2 with python 2.7.3 but not 10.3 with 2.7.8

1843
2
Jump to solution
04-29-2016 12:23 PM
AmelieDavis
New Contributor II

I have a script that looks in a folder for all the rasters it contains, performs simple operations on those rasters, and saves them as new rasters in a new folder. The script works fine in ArcGIS 10.2 with python version 2.7.3, but gives the following error in ArcGIS 10.3 with python 2.7.8.  The script is embedded in a tool, i.e. not standalone in python.

Python_Error.JPG

I've attached example input files, the script (entitled .NDVI_Calc3_Parameters_W.py), and its associated toolbox.

The script fails at:

    arcpy.CalculateStatistics_management(inputRaster)

Troubleshooting has lead me to believe that someone it no longer recognizes the input as a raster.  I've tried various workarounds (including removing the build attribute table line before that one, creating a raster object, etc.) but I still can't get it to work. 

Any ideas?

Thank you in advance for any help you provide.

Sincerely,

Amelie

0 Kudos
1 Solution

Accepted Solutions
AndrewKeith3
Occasional Contributor

Try using:

arcpy.MakeRasterLayer_management(inputRaster, "name")
arcpy.CalculateStatistics_management("name")

View solution in original post

2 Replies
AndrewKeith3
Occasional Contributor

Try using:

arcpy.MakeRasterLayer_management(inputRaster, "name")
arcpy.CalculateStatistics_management("name")
curtvprice
MVP Esteemed Contributor

I agree with Andrew's suggestion. These file names are really long and you can run into issues when the entire pathname gets beyond a certain number of characters. When a raster object is passed to a tool, its full path gets expanded (because its str() method returns the full path). Layers are safer because they are nice and short and can be passed directly to the tool without having to handle the path.

In 9x we had a similar deal with Single Output Map Algebra, if you passed the tool raster layers instead of paths, you avoided all kinds of path issues as the the layer object hid the path until the map algebra was passed into ArcObjects, is much friendlier with unusual pathnames than the map algebra parser. 

If I have to access an object more than once in a script, I usually make a layer or table view. This is because layers and table views (rather than paths) have the additional benefit of pre-validating datasets (and attribute tables) so paths and field names don't have to be re-read and validated by a tool before it launches -- saving disk I/O and CPU ticks -- the tool can get right to it!

Are you certain this worked in 10.2 with the ​exact​ same data in the ​exact ​same path?