ERROR 999998: Unexpected Error raster algebra

7635
42
02-08-2018 11:30 AM
PauloFlores
New Contributor II

Hi there,

 I am new at Pythin and during the last couple months I have working on writing some Python scripts to automatize some of my drone imagery analysis, such as the code bellow. I have written few scripts and used them on different datasets and they were working just fine. A couple days ago I realize that would be better to save my final raster (yellow) on the same folder that my original RGB raster (blue), so I can use that same path in other scripts for further analysis without having to copy rasters around. Then, I started to get a message ERROR 999998: Unexpected Error, and now does not matter which code I try to run, I get the same message. 

I have been looking around for a solution for my issue but I have been unsuccessful on that regard. By reading some material online, it seems that problem is related to memory issues, but I am not quite sure about that. Here are some details about my machine and software.

- desktop computer (Windows 10, version 1511, OS Build 10586.663, Processor Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz 3.41 GHz, RAM 32GB, System type 64-bit operating system, x64-based processor) . I have ArcGis 10.5  and I am using PythonWin (PythonWin 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32.) to write my scripts.

- I ran the code bellow on my Surface 3 laptop (Windows 10 Pro, version 10.0.16299 build 16299, system type x64-based PC, processor Intel Core i5-4300 CPU @ 1.90GHz, 2501 Mhz, 2 cores, 4 logical processors; RAM 8GB) this morning and it worked just fine.

-Last night I ran the same code from within ArcGIS and it worked just fine.

-I can not understand how everything was working just fine until a couple days ago, and suddenly the computer does not have enough memory to handle the same task. My RGB file is (around 1.8 GB in size, but I used files larger than that in the past with no problems.

 

Any help to fix this issue would be greatly appreciated.

Code:

import arcpy, string, os, errno

from arcpy import env

from arcpy.sa import*

from datetime import datetime

arcpy.CheckOutExtension("spatial")

arcpy.env.overwriteOutput = True

 

start_time = datetime.now()

 

imagery = r'E:\UAV2017\PythonField8ExGr\Field8_90ft_08012017.tif'

 

path = os.path.dirname(imagery)

base1 = os.path.basename(imagery)

base = os.path.splitext(base1)[0]

folder = "Results"

Results = os.path.join(path,folder)

if not os.path.exists(Results):

    os.makedirs(Results)

print "Results folder successfully created"

 

exgr_filename = base + "_ExGr.tif"

arcpy.env.workspace = imagery

bands = [Raster(os.path.join(imagery, b)) for b in arcpy.ListRasters()]

print bands

 

arcpy.env.workspace = Results

Ngreen = (Float(bands[1])) / (Float(bands[0]) + bands[1] + bands[2])

Nred = (Float(bands[0])) / (Float(bands[0]) + bands[1] + bands[2])

Nblue = (Float(bands[2])) / (Float(bands[0]) + bands[1] + bands[2])

exgr = (2 * Ngreen) - Nred - Nblue

exgr.save(exgr_filename)

print "Excess Green successfully calculated"

 

#Build pyramids and calculate statistics

arcpy.BuildPyramids_management(exgr_filename)

arcpy.BuildPyramids_management(exgr_filename)

print "Pyramids and Statistics successful"

 

end_time = datetime.now()

print('Duration: {}'.format(end_time - start_time))

 

Interactive Window messages:

E:\UAV2017\PythonField8ExGr

Field8_90ft_08012017

Results folder successfully created

Traceback (most recent call last):

  File "C:\Python27\ArcGIS10.5\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript

    exec codeObject in __main__.__dict__

  File "C:\Users\Paulo.Flores\Desktop\Python Codes\New versions\ExGr_calc_02072018.py", line 45, in <module>

    exgr.save(exgr_filename)

RuntimeError: ERROR 999998: Unexpected Error.

0 Kudos
42 Replies
PauloFlores
New Contributor II

Charlie,

I think that the issue that I am still experiencing is due some hardware problem on my desktop. Until this day I get the same error when trying to save a raster after algebra calculation. I use the same code on different laptops and it has worked just fine.

Best,

Paulo

0 Kudos
CharlesFried
New Contributor III

Well, I guess that I have the same problem because saving rasters after raster algebra often (although not always, curiously) fails with ERROR 999998.  This leaves me extremely frustrated with ESRI raster algebra functions which seem to be unreliable.

0 Kudos
ANILBaral
New Contributor

I have a problem saving the raster file working with Arcpy.  Sometimes the code runs and sometimes I get this error message displayed.

File "C:/Users/Anil/Desktop/python GIS/Script/analysis file for asking.py", line 27, in <module>
globals()['Bulk_saturated_desnity%s'%i].save("C:/Users/Anil/Desktop/checkfor code/out/bulkdesnity1%d.tif" %i)
RuntimeError: ERROR 999998: Unexpected Error.

My codes are below: I don't know why is it sometimes I get the output and sometimes the error message is displayed? When I save my file outside of geodatabase the file size is like 15 GB? can it be the reason for this error?

Traceback (most recent call last):

import arcpy
from arcpy import env
from arcpy.sa import *

arcpy.env.overwriteOutput= True

# Set environment settings:
env.workspace = r"E:\Geodatabaseforanalysis\TxDOT.gdb"

slope1 = Raster("Slope_corridor_masked.tif")


# Defining angle in Radian:
def angle(x):
 return x * 0.017453

for i in range(1,2):
    globals()['bulkspecificdensity%s' % i] =Raster('bd0%d.tif' % i)       # bulk specific gravity from geodatabase
    globals()['claypercentage%s' % i] = Raster('pc0%d.tif' % i)           #percentage clay from geodatabase
    globals()['liquidlimit%s' % i] = Raster('ll0%d.tif' % i)              #liquid limit from geodatabase
    globals()['watercontent%s' % i] = Raster('wc0%d.tif' % i)             #watercontent from geodatabase
    globals()['Ksat%s' % i] = Raster('hc0%d.tif' % i)                     #hydraulic conductivity from geodatabase
    sp_water = 10

    # Calculation of Raster file for Bulk saturated Density:
    globals()['Bulk_saturated_desnity%s'%i] = sp_water * (1 - globals()['watercontent%s' % i] / 100) + globals()['bulkspecificdensity%s' % i] * sp_water * (1 - 1 / 2.65)
    globals()['Bulk_saturated_desnity%s'%i].save("C:/Users/Anil/Desktop/checkfor code/out/bulkdesnity1%d.tif" %i)

    # # # Calculating FOS for each depth
    globals()['phi%s' % i]= Con((globals()['claypercentage%s' % i] < 20), (34.85 - 0.0709 * globals()['liquidlimit%s' % i] + 2.35 * (10 ** (-4)) * (globals()['liquidlimit%s' % i]** 2)),
              Con((globals()['claypercentage%s' % i]), (36.18 - 0.1143 * globals()['liquidlimit%s' % i]+ 2.354 * (10 ** (-4)) * (globals()['liquidlimit%s' % i] ** 2)),
                  Con((globals()['claypercentage%s' % i]), (34.85 - 0.0709 * globals()['liquidlimit%s' % i]+ 2.35 * (10 ** (-4)) * globals()['liquidlimit%s' % i] ** 2))))

    globals()['phi%s' % i].save("C:/Users/Anil/Desktop/checkfor code/out/phi%d.tif" % i)
0 Kudos