I wrote a little script that gets the mean value of a raster, does some map algebra and should save the new raster. The raster I am using is a 32 bit floating point, geotiff, 200 MB.
Here is an example of the code:
import arcpy, os, shutil, time
from arcpy import env
from arcpy.sa import *
raster_folder = r"C:\folder\with\rasters"
result_folder = r"C:\folder\for\results"
env.workspace = result_folder
for raster in arcpy.ListRasters("*", "TIF"):
ras_mean = arcpy.GetRasterProperties_management(raster, "MEAN")
r_m = float(ras_mean.getOutput(0))
ras_norm = (Raster(raster) - r_m) / r_m
Every time I want to save the raster, I get the error message.
RuntimeError: ERROR 999998: Unexpected Error.
Both, clip_raster and result folder exist. I tried to shorten the path of the result folder, the size of the raster name has no symbols in it that are not allowed and is short enough. I tried to use a direct path and name to save the raster, I tried to just save it with "ras_norm.save()" - no change.
I tried it with only one raster and giving it the exact path to it, no change. I also set the scratchWorkspace but that made no difference.
I realized when I replaced "r_m" with a fixed number, float or integer, it worked - but I will not work with a fixed number, I need to get the mean from the "clip_raster". When I rounded the mean to 2 or 3 digits, the process was working most of the time but I would like to work with as many digits as possible.
I am suspect that the map algebra is creating a larger raster than the program can handle? I have enough RAM (16GB) and also space on the hard drive (100 GB).
When I load the script into ArcMap's python, it is running just fine (without rounding the mean value) which shows me that it should work. I checked that both are using the same python version (no other python version is installed) and python exe. Background processing is disabled. I have a license for the Spatial Analyst extension. I have writing permission to the result_folder. I tried repairing ArcGIS and reinstalling - no change.
I am not sure what else I could do - yes it is running in ArcMap but I would like to run it directly in a python IDLE and not in the ArcMap interface. And, I know it should work because on a similar machine I had no problem with the same script, same data.
Any help or advice is appreciated.