I am dabbling with the resolution of the error says RuntimeError: ERROR 010240: Could not save raster dataset to as attached as a screen shot. I am working with a DEM file and trying to generate raster based on the conditional values from an excel file. As the excel file has about 15000 row, I need to generate about 15000 raster. I am very much disappointed when the script takes long time and at last it fails every time at different point and this has been happening from the yesterday.
I am just reading date and associated 3 temperature values from the excel file and applying con operation on DEM arcgis grid raster to generate another raster. This process is repeated for all the dates i.e. rows in the excel file as attached.
My script is a below
<SPAN class="comment token">#!/usr/bin/python</SPAN>
<SPAN class="comment token"># -*- coding: utf-8 -*-</SPAN>
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> sys
<SPAN class="keyword token">import</SPAN> shutil
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> Con
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> Raster
<SPAN class="keyword token">from</SPAN> openpyxl <SPAN class="keyword token">import</SPAN> load_workbook
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CheckOutExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'spatial'</SPAN><SPAN class="punctuation token">)</SPAN>
INPUT_TEMP_EXCEL_PATH <SPAN class="operator token">=</SPAN> \
r<SPAN class="string token">"C:\Users\Winrock\Desktop\Ryan\Sept02ModularApproach\Temperature Model Data.xlsx"</SPAN> <SPAN class="comment token"># arcpy.GetParameterAsText(0)</SPAN>
INPUT_DEM_RASTER_PATH <SPAN class="operator token">=</SPAN> \
r<SPAN class="string token">"C:\Users\Winrock\Desktop\Ryan\Sept02ModularApproach\DEM\dem_clip_11"</SPAN> <SPAN class="comment token"># arcpy.GetParameterAsText(1)</SPAN>
Second_Discrete_variable <SPAN class="operator token">=</SPAN> <SPAN class="number token">10</SPAN> <SPAN class="comment token"># arcpy.GetParameterAsText(2)</SPAN>
OUTPUT_TEMP_RASTER_FOLDER <SPAN class="operator token">=</SPAN> \
r<SPAN class="string token">"C:\Users\Winrock\Desktop\Ryan\Sept02ModularApproach\OutputRaster"</SPAN> <SPAN class="comment token"># arcpy.GetParameterAsText(3)</SPAN>
TEMP_FOLDER_PATH <SPAN class="operator token">=</SPAN> \
r<SPAN class="string token">"C:\Users\Winrock\Desktop\Ryan\Sept02ModularApproach\Temp"</SPAN> <SPAN class="comment token"># arcpy.GetParameterAsText(4)</SPAN>
Second_Discrete_variable <SPAN class="operator token">=</SPAN> float<SPAN class="punctuation token">(</SPAN>Second_Discrete_variable<SPAN class="punctuation token">)</SPAN>
Temp_Data <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Loading temperature data</SPAN>
temp_wb <SPAN class="operator token">=</SPAN> load_workbook<SPAN class="punctuation token">(</SPAN>filename<SPAN class="operator token">=</SPAN>INPUT_TEMP_EXCEL_PATH<SPAN class="punctuation token">,</SPAN> read_only<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">)</SPAN>
temp_ws <SPAN class="operator token">=</SPAN> temp_wb<SPAN class="punctuation token">[</SPAN>temp_wb<SPAN class="punctuation token">.</SPAN>sheetnames<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> temp_ws<SPAN class="punctuation token">.</SPAN>rows<SPAN class="punctuation token">:</SPAN>
rw <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>cell<SPAN class="punctuation token">.</SPAN>value <SPAN class="keyword token">for</SPAN> cell <SPAN class="keyword token">in</SPAN> row<SPAN class="punctuation token">]</SPAN>
Temp_Data<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>rw<SPAN class="punctuation token">)</SPAN>
Temp_Data <SPAN class="operator token">=</SPAN> Temp_Data<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Folder content deleter</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">folder_content_deleter</SPAN><SPAN class="punctuation token">(</SPAN>folder_path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> the_file <SPAN class="keyword token">in</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>folder_path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
file_path <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>folder_path<SPAN class="punctuation token">,</SPAN> the_file<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>isfile<SPAN class="punctuation token">(</SPAN>file_path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
os<SPAN class="punctuation token">.</SPAN>unlink<SPAN class="punctuation token">(</SPAN>file_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">elif</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>isdir<SPAN class="punctuation token">(</SPAN>file_path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
shutil<SPAN class="punctuation token">.</SPAN>rmtree<SPAN class="punctuation token">(</SPAN>file_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> Exception<SPAN class="punctuation token">,</SPAN> e<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">pass</SPAN>
<SPAN class="comment token"># set temporary places, grid format needs a gdb for placing intermediate data</SPAN>
folder_content_deleter<SPAN class="punctuation token">(</SPAN>TEMP_FOLDER_PATH<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CreateFileGDB_management<SPAN class="punctuation token">(</SPAN>out_folder_path<SPAN class="operator token">=</SPAN>TEMP_FOLDER_PATH<SPAN class="punctuation token">,</SPAN>
out_name<SPAN class="operator token">=</SPAN><SPAN class="string token">'ScratchData_solRaster'</SPAN><SPAN class="punctuation token">,</SPAN>
out_version<SPAN class="operator token">=</SPAN><SPAN class="string token">'CURRENT'</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchWorkspace <SPAN class="operator token">=</SPAN> \
os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>TEMP_FOLDER_PATH<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'ScratchData_solRaster.gdb'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># processing Second part</SPAN>
<SPAN class="keyword token">for</SPAN> tdata <SPAN class="keyword token">in</SPAN> Temp_Data<SPAN class="punctuation token">:</SPAN>
T1 <SPAN class="operator token">=</SPAN> tdata<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
T2 <SPAN class="operator token">=</SPAN> tdata<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN>
T3 <SPAN class="operator token">=</SPAN> tdata<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN>
output_second <SPAN class="operator token">=</SPAN> Con<SPAN class="punctuation token">(</SPAN>Raster<SPAN class="punctuation token">(</SPAN>INPUT_DEM_RASTER_PATH<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token"><</SPAN> <SPAN class="number token">2573</SPAN><SPAN class="punctuation token">,</SPAN> T1<SPAN class="punctuation token">,</SPAN>
Con<SPAN class="punctuation token">(</SPAN>Raster<SPAN class="punctuation token">(</SPAN>INPUT_DEM_RASTER_PATH<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token"><=</SPAN> <SPAN class="number token">2754</SPAN><SPAN class="punctuation token">,</SPAN> T2<SPAN class="punctuation token">,</SPAN>
T3<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
final_temp_raster <SPAN class="operator token">=</SPAN> output_second <SPAN class="operator token">+</SPAN> Second_Discrete_variable
<SPAN class="comment token"># save</SPAN>
out_path <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>OUTPUT_TEMP_RASTER_FOLDER<SPAN class="punctuation token">,</SPAN> str<SPAN class="punctuation token">(</SPAN>tdata<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
final_temp_raster<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>out_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Cleaning</SPAN>
<SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'in_memory'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'in_memory'</SPAN><SPAN class="punctuation token">)</SPAN>
folder_content_deleter<SPAN class="punctuation token">(</SPAN>TEMP_FOLDER_PATH<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
My error in gist is-
RuntimeError: ERROR 010240: Could not save raster dataset to C:\Users\Winrock\Desktop\Ryan\Sept02ModularApproach\Temp\ScratchData_solRaster.gdb\ifthe_ras with output format FGDBR
The excel file I am using is https://www.dropbox.com/s/qacfhipo4ry7o2b/Temperature%20Model%20Data.xlsx?dl=0
My error-

N.B. I tried several thread some of them are-
- What causes RuntimeError: ERROR 010240 saving after CellStatistics?
- Why does CON statement give ERROR 010240: Could not save raster dataset to (value) with output format GRID?
- error 010240 with output format grid
- arcgis 10.0 - python.multiprocessing and "FATAL ERROR (INFADI) MISSING DIRECTORY" - Geographic Information Systems Stack…
System specification:

---------------------------------------------------------------------------------------------------------------------------------------------------------------
Update:
*I tried with different scratch and current workspace
*I tried with arcpy.gp.Times_sa(it stops after processing almost 3000 rasters) and arcpy.sa.Times(it stops after processing almost 1070 rasters)
*I tried with arcpy.TestSchemaLock
*I tried with setting output to tif format too.
I see that it stops and raises error when it processed and output exact number of 1070 grid files.
It is giving me pain for several days- please help!