I have a series of .asc files that are output from a modeling exercise (see image below). I need to scroll through each .asc raster, and calculate the mean pixel value within a certain outline. I can do this manually by using the "Calculate Statistics" tool in the Data Management toolbox and then clicking through to the Layer Properties of each .asc file. I have been successful at doing this but it is time consuming (see second image below).

I would prefer to create a script in Python to automate this process. However, when I try to run Calculate Statistics on these same files through Python, I get the following error:

CalculateStatistics_management(r"colby_cbp_run1\control_BP.asc", "1", "1", "", "OVERWRITE", path_to_area_of_interest)

Runtime error Traceback (most recent call last): File "", line 1, in File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\management.py", line 14811, in CalculateStatistics raise e ExecuteError: ERROR 000840: The value is not a Mosaic Dataset. ERROR 000840: The value is not a Mosaic Layer. ERROR 000840: The value is not a Raster Dataset.

What is happening here? Is there an error in the syntax of the above command, or do I need to convert the .asc files to another format to perform this calculation using Python? Why is the tool working one way and not the other?

Screenshot of TOC

Success using Tool

  • Have you reviewed these Q&As? gis.stackexchange.com/questions/tagged/error-000840
    – PolyGeo
    Commented Feb 21, 2017 at 21:22
  • The short answer is, "yes, you can run Calculate Statistics on an ASCII file via Python." I just did it. There is something else going on in your script.
    – phloem
    Commented Feb 21, 2017 at 21:25

1 Answer 1


It appears that CalculateStatistics_management needs to be passed the path to the data source rather than the path to the layer.

So while this did not work:

CalculateStatistics_management(r"group_layer\my_raster.asc", "1", "1", "", "OVERWRITE", "") 

This does:

CalculateStatistics_management("C:\\my_directory\\subdirectory\\my_raster.asc", "1", "1", "", "OVERWRITE", "")

See @Donna 's question Calculating raster layer statistics using ArcPy gives ERROR 000840? for another version of the same question. Searching for questions tagged with the same error message is very useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.