AnsweredAssumed Answered

Workspace and scratchWorkspace doing strange things when using arcpy.sa?

Question asked by xander_bakker on Oct 26, 2011
Latest reply on Nov 4, 2011 by rdebruyn-esristaff
Workspace and scratchWorkspace doing strange things when using arcpy.sa?

An odd thing just happened. I was working on some analysis using arcpy.sa when a simple Focal Statistics:

>>> AHN2CFILL2FM2 = FocalStatistics("AHN2CFILL2",NbrRectangle(3,3,"CELL"),"MEAN","DATA")

â?¦ resulted in the following error:

Runtime error File <string>, line 1, in <module> File c:\program files\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py, line 4788, in FocalStatistics File c:\program files\arcgis\desktop10.1\arcpy\arcpy\sa\Utils.py, line 47, in swapper File c:\program files\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py, line 4782, in wrapper File c:\program files\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py, line 490, in <lambda> <class 'arcgisscripting.ExecuteError'>: ERROR 000875: Output raster: C:\Project\_Wetterskip\data\Wetterskip.gdb\C:\Project\_Wetterskip\data\py\py\Wetterskip.gdb\FocalSt_AHN21's workspace is an invalid output workspace. ERROR 000581: Invalid parameters. Failed to execute (FocalStatistics).

Apparently, for some reason my workspace was set to a non valid location. When I listed the workspace and scratchworkspace I noticed this:

>>> print env.workspace
C:\Project\_Wetterskip\data\Wetterskip.gdb

>>> print env.scratchWorkspace
C:\Project\_Wetterskip\data\py\py\Wetterskip.gdb

My workspace was still defined correctly, but for some strange reason my scratch workspace (normally the same location as my workspace) had been set to a non existing subfolder \py\py, where obviously it wasnâ??t going to find any geodatabaseâ?¦ But why would my output workspace been set to a combination of my workspace and my scratchWorkspace?

The only thing that I can imagine being the reason for this, is that shortly before executing the Focal Statistics command I had used the option "Save Asâ?¦" from the context sensitive menu, shown when clicking the right mouse button in the python window. On saving I had created a new folder "py" (but only 1 "\py" subfolder and not "\py\py").

Also, when opening the Focal Statistics tool in the toolbox, the default output location was pointing to the non existing location (see Screenshot_FocalStatisticsTool). Investigation the Environment setting (through Geoprocessing menu, option Environmentsâ?¦) also showed the wrong location for scratch workspace.

I closed the tool and the environment setting, went back to my python window and set my scratchWorkspace to my current workspace:

>>> env.scratchWorkspace = env.workspace
>>> print env.scratchWorkspace
C:\Project\_Wetterskip\data\Wetterskip.gdb

Next step was to perform the Focal Statistics again (through Python), which this time resulted in:

Runtime error File <string>, line 1, in <module> File c:\program files\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py, line 4788, in FocalStatistics File c:\program files\arcgis\desktop10.1\arcpy\arcpy\sa\Utils.py, line 47, in swapper File c:\program files\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py, line 4782, in wrapper File c:\program files\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py, line 490, in <lambda> <class 'arcgisscripting.ExecuteError'>: ERROR 000622: Failed to execute (Focal Statistics). Parameters are not valid. ERROR 000628: Cannot set input into parameter in_raster.

What in the worlds name was happening with my "in_raster"â?¦ :confused:
I took a closer look at my TOC and noticed that for a really strange reason all the datasources had become invalidâ?¦ (see Screenshot_TOC).

Fortunately, using the Repair Datasource option fixed all the datasource errors. :)
I Think Iâ??m going to restart my system, and see if it happens againâ?¦

Anyone with similar experiences?

Outcomes