Running Cell Stat from copied Python command produces error

1434
12
Jump to solution
01-07-2019 11:59 AM
GabrielMarcus1
Occasional Contributor II

When I run Cell Statistics from the UI, then copy the python command from History and paste it into the Python window, it produces an error: 

TypeError: CellStatistics() takes from 1 to 3 positional arguments but 4 were given. 

The only modification I made to the script was changing the name of the output. 

Here's the code:

arcpy.ia.CellStatistics(r"'WindSpeed\WindSpd_10_HTGL1/9/2019 6:00:00 PM';'WindSpeed\WindSpd_10_HTGL1/9/2019 12:00:00 PM';'WindSpeed\WindSpd_10_HTGL1/9/2019 6:00:00 AM';WindSpeed\WindSpd_10_HTGL1/9/2019;'WindSpeed\WindSpd_10_HTGL1/8/2019 6:00:00 PM';'WindSpeed\WindSpd_10_HTGL1/8/2019 12:00:00 PM';'WindSpeed\WindSpd_10_HTGL1/8/2019 6:00:00 AM';WindSpeed\WindSpd_10_HTGL1/8/2019;'WindSpeed\WindSpd_10_HTGL1/7/2019 6:00:00 PM';'WindSpeed\WindSpd_10_HTGL1/7/2019 12:00:00 PM';'WindSpeed\WindSpd_10_HTGL1/7/2019 6:00:00 AM';WindSpeed\WindSpd_10_HTGL1/7/2019;'WindSpeed\WindSpd_10_HTGL1/6/2019 6:00:00 PM';'WindSpeed\WindSpd_10_HTGL1/6/2019 12:00:00 PM';'WindSpeed\WindSpd_10_HTGL1/6/2019 6:00:00 AM';WindSpeed\WindSpd_10_HTGL1/10/2019", r"C:\Users\gmarcus\Documents\ArcGIS\Projects\MyProject4\MyProject4.gdb\WindSpdMaxde", "MAXIMUM", "DATA")

Why would the python that ArcGIS Pro produces cause an error? Is this yet another example of a line of python produced by ArcGIS Pro that is known to not work? 

I'm aware that when copying the Python from Raster Calculator also doesn't work. It seems lame to allow a user to copy a Python snippet when it won't work. Looking at the example of Cell Statistics in the documentation, it seems like this is another example of this approach. WHY ARE YOU DOING THIS ESRI?!

Thanks,

Gabe

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Emeritus

Gabriel,

It is a bug, and I will report it to the ArcGIS Pro 2.3 beta 2 forum

Worked in the interface as designed and described.

Copied the path into the CellStatistics line which it shouldn't

arcpy.ia.CellStatistics("r012;2", r"C:\Git_Dan\arraytools\array_tools_testing\array_tools.gdb\CellSta_r0121", "MAXIMUM", "DATA")

DONE... I will report here any information, but the help is misleading and/or it should include an optional path parameter should the user wish to save the results.

View solution in original post

12 Replies
DanPatterson_Retired
MVP Emeritus

you will have to parse the output string since you have noted, up to 3 are required, but it appears that they have whipped in the save portion into the output string

outCellStats = CellStatistics(["degs", "negs", "cost"], "STD", "DATA")

outCellStats.save("C:/sapyexamples/output/outcellstats.img")

you stuff

result = arcpy.ia.CellStatistics(r'..snip...', "MAXIMUM", "DATA")  # your input list

result.save( r"C:\… snip... \MyProject4.gdb\WindSpdMaxde")  # your output folder

GabrielMarcus1
Occasional Contributor II

I have it working now. I'm annoyed that copying the python command won't work though. 

0 Kudos
DanPatterson_Retired
MVP Emeritus

Gabriel,

It is a bug, and I will report it to the ArcGIS Pro 2.3 beta 2 forum

Worked in the interface as designed and described.

Copied the path into the CellStatistics line which it shouldn't

arcpy.ia.CellStatistics("r012;2", r"C:\Git_Dan\arraytools\array_tools_testing\array_tools.gdb\CellSta_r0121", "MAXIMUM", "DATA")

DONE... I will report here any information, but the help is misleading and/or it should include an optional path parameter should the user wish to save the results.

GabrielMarcus1
Occasional Contributor II

2.3 beta 2? Does it matter that I'm running 2.2.4?

0 Kudos
DanPatterson_Retired
MVP Emeritus

Gabriel... I am running 2.3 beta 2 and it failed… if it failed in 2.2.4, then it just hasn't been detected as an error, or no one reported it before.

Your workaround is to remember that the 'save' portion of the process has somehow been included in the one-line but needs to be separated out as I showed.

0 Kudos
GabrielMarcus1
Occasional Contributor II

Dan, 

Is your raster.save working appropriately?

I've annotated my script with status messages using print() statements. 

I have a loop that saves 3 files to a GDB. The first one executes, then stops. 

There's no error. It just stops executing. The raster file is named the variable name, but the name I chose for the raster is stored in the GDB. 

There are no conditional statements to branch off or evaluate a condition.

0 Kudos
DanPatterson_Retired
MVP Emeritus

I save my rasters to *.tif files for a variety of reason, so not in a gdb.

I would therefore, specify a complete path to a folder.

I don't know what happens when things go wrong and rasters are directed to a gdb.

On the upside, I can use my tif files in other applications... if I need a raster equivalent in a gdb, I can 'copy raster' it in without the file extension.

Just make sure you don't send rasters to a folder without a file extension, unless you want esri grids (which aren't the same as rasters in a gdb if memory serves)

ElizabethGraham
Esri Contributor

Thank you for bringing this issue to our attention.  I have submitted this issue to our development team and will work towards a fix for next release.

GabrielMarcus1
Occasional Contributor II

Thanks for your help everyone!

One other thing: why are some commands such as "merge" and "project" output from the "Copy as python command" as arcpy.management.name  versus "name_management" the way that they appear in the docs?

0 Kudos