Arcpy script results in RuntimeError: ERROR 999998: Unexpected Error

976
5
04-14-2020 04:42 AM
KonanPruiksma
New Contributor

I made this pretty simple tool with the code below and all through last night it ran error free on every run. Now since this morning I am getting a RuntimeError: 999998: Unexpected Error. The error occurs on line 15:

outMinus.save(r'D:\Documents\LocalReliefModel\TestRaster\difmodel.tif')

I have no idea why it isn't working all of the sudden. I can see it writing the raster file in the given location, but it gets deleted immediately and than the RuntimeError happens. I can't really find any solution and have tried different paths, names, setting it as a variable, etc.

Does anyone know what to do?

import arcpy
from arcpy.sa import *

arcpy.env.overwriteOutput = True
arcpy.env.workspace = r'D:\Documents\LocalReliefModel'

DEM_org = r'D:\Documents\LocalReliefModel\TestRaster\GH_Toterfout.tif'

# Low pass filter -> Smoothed DEM (focal statistics)
outFocalStat = arcpy.sa.FocalStatistics(DEM_org, NbrRectangle(50, 50, "CELL"), 'MEAN')
outFocalStat.save(r'D:\Documents\LocalReliefModel\TestRaster\LPF.tif')

# Subtract smoothed DEM from the original DEM -> Difference model (Minus function)
outMinus = arcpy.sa.Minus(outFocalStat, DEM_org)
outMinus.save(r'D:\Documents\LocalReliefModel\TestRaster\difmodel.tif')

# Calculate the zero meters contours for the Difference model ->
# set of the break lines between the positive and negative features (convex and concave features; Contour function)
outCont_save = r'D:\Documents\LocalReliefModel\TestRaster\ZeroCont.tif'
outCont = arcpy.sa.Contour(outMinus, outCont_save, 100)

# Extract the real elevation of the cells from the original DEM, which intersects with the break lines ->
# simplified elevation raster (Extract by Mask function)
outMask = arcpy.sa.ExtractByMask(DEM_org, outCont)
outMask.save(r'D:\Documents\LocalReliefModel\TestRaster\ElExtract.tif')

# Convert the simplified elevation raster to the point features (only nonzero cells) ->
# elevation points (Raster to Point function)
outRastToPoint_save = r'D:\Documents\LocalReliefModel\TestRaster\RastToPoint'
outRastToPoint = arcpy.RasterToPoint_conversion(outMask, outRastToPoint_save)‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
Tags (2)
0 Kudos
5 Replies
DanPatterson_Retired
MVP Emeritus

you said you tried different paths, but did you attempt changing the names?

KonanPruiksma
New Contributor

The issue is resolved now. The problem was with writing in-memory and not on drive. Thanks!

0 Kudos
DavidPike
MVP Frequent Contributor

Maybe because your outFocalStat is a raster object rather than a path.

also you a using arcpy.sa explicitly so theres no need for from arcpy.sa import *

one last guess might be not having

arcpy.CheckOutExtension("Spatial")

KonanPruiksma
New Contributor

Thanks for your reply! The problem has been solved by moving all the .save functions to the end of the script. 

I still need arcpy.sa import * for NbrRectangle for some reason. 

0 Kudos
SteveLynch
Esri Regular Contributor

because it is in the Spatial Analyst module