I am working on a pilot for a system that will eventually loop over a number of raster files to produce a single output one. If I have two input rasters, the routine works reliably. If I have more than three, it always fails. If I try three after a failure, it fails, but it can be made to work by first resorting to just two inputs and then adding the third. This is my (anonymised) code:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">from</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sa <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CheckOutExtension<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Spatial"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>extent <SPAN class="operator token">=</SPAN> <SPAN class="string token">"MAXOF"</SPAN>
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>env<SPAN class="punctuation token">.</SPAN>qualifiedFieldNames <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> <SPAN class="string token">"C:\aaaa"</SPAN>
inRasDir <SPAN class="operator token">=</SPAN> bbb\\"
outRasDir <SPAN class="operator token">=</SPAN> ccc\\"
terms <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN>
terms <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">'first'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'0.025'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'*'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'+'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'second'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'0.025'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'*'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'+'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'third'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'0.025'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'*'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'+'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'fourth'</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">'0.15'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'*'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'-'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">coeff</SPAN><SPAN class="punctuation token">(</SPAN>lyr<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">if</SPAN> terms<SPAN class="punctuation token">[</SPAN>lyr<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">==</SPAN> <SPAN class="string token">'+'</SPAN><SPAN class="punctuation token">:</SPAN>
c <SPAN class="operator token">=</SPAN> float<SPAN class="punctuation token">(</SPAN>terms<SPAN class="punctuation token">[</SPAN>lyr<SPAN class="punctuation token">]</SPAN><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">else</SPAN><SPAN class="punctuation token">:</SPAN>
c <SPAN class="operator token">=</SPAN> <SPAN class="operator token">-</SPAN>float<SPAN class="punctuation token">(</SPAN>terms<SPAN class="punctuation token">[</SPAN>lyr<SPAN class="punctuation token">]</SPAN><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">return</SPAN> c<SPAN class="punctuation token">;</SPAN>
outRas <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>
<SPAN class="punctuation token">(</SPAN>coeff<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'first'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> Raster<SPAN class="punctuation token">(</SPAN>inRasDir <SPAN class="operator token">+</SPAN> <SPAN class="string token">"first"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>coeff<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'second'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> Raster<SPAN class="punctuation token">(</SPAN>inRasDir <SPAN class="operator token">+</SPAN> <SPAN class="string token">"second"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>coeff<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'third'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> Raster<SPAN class="punctuation token">(</SPAN>inRasDir <SPAN class="operator token">+</SPAN> <SPAN class="string token">"third"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># + (coeff('fourth') * Raster(inRasDir + "fourth"))</SPAN>
<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># * 'fifth'</SPAN>
<SPAN class="punctuation token">)</SPAN>
outRas<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>outRasDir <SPAN class="operator token">+</SPAN> <SPAN class="string token">"finalRas"</SPAN><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>The error on the last line is:
outRas<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>outRasDir <SPAN class="operator token">+</SPAN> <SPAN class="string token">"finalRas"</SPAN><SPAN class="punctuation token">)</SPAN>
RuntimeError<SPAN class="punctuation token">:</SPAN> ERROR <SPAN class="number token">999998</SPAN><SPAN class="punctuation token">:</SPAN> Unexpected Error<SPAN class="punctuation token">.</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
I also tried using CellStatistics but that also failed on the save statement.
Any comments would be gratefully received.
Regards,
Ian