AnsweredAssumed Answered

Error with focal statistics in a custom script - says kernel file is not provided even though it is

Question asked by claireea@byu.edu_byu on Jul 11, 2020
Latest reply on Jul 13, 2020 by claireea@byu.edu_byu

I'm trying to code my own script (well, modify an old ArcInfo Workstation program to work in ArcGIS pro) and am running into problems. Part of the script involves doing focal statistics where I calculate the mean based on a basic 3x3 laplacian kernel (a .txt file I provide). However, this part of the script fails to run and I get error 010391 as described below. The issue is that I can't find any explanation for this. I double-checked the path to the kernel file and it's correct. The text file itself is CRLF. I can't find any online documentation on how the kernel should be formatted for ArcGIS, but I have it formatted the standard way. I have some experience with MatLab and C++ but no Python experience, so there might be an obvious answer I'm missing. What am I doing wrong?


Here's the section of code (this is my first post; if there's a code formatting button for GeoNet I can't find it, sorry):


# Import system modules
import arcpy
from arcpy import env
from import *


#bring the parameters into the program
classnumber = arcpy.GetParameter(0) #Used later in the program
demoriginal = arcpy.GetParameter(1) #DEM raster
laplacian = arcpy.GetParameter(2) #Laplacian filter text file


#turn the raster into a GRID format composite geodataset called "dem" so that focal statistics can be done on it
dem = arcpy.CompositeBands_management(demoriginal, "dem")


#making slope image
simg = Slope(dem,"DEGREE")


# making convex area image
img1 = Con(FocalStatistics(dem,NbrWeight(laplacian),"MEAN") > 0, 1, 0)  #This is the line that fails
convex = focalmean (img1,circle,10)


(and so on)



The error:


Traceback (most recent call last):  File "C:\Users\User\Desktop\ArcGIS Files\GeographicClassification3\ProgramFiles\", line 35, in <module>    img1 = Con(FocalStatistics(dem,NbrWeight(laplacian),"MEAN") > 0, 1, 0)

File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\", line 5486, in FocalStatistics    percentile_value)

File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\", line 53, in swapper    result = wrapper(*args, **kwargs)

File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\sa\", line 5479, in Wrapper    percentile_value) 

File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing\", line 511, in <lambda>    return lambda *args: val(*gp_fixargs(args, True))arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.


ERROR 010391: Kernel file is not provided or does not exist.Failed to execute (FocalStatistics).

Failed to execute (Classification).



I attached the kernel file but this is what it contains:

3 3
0 -1 0
-1 4 -1
0 -1 0