Hi,
I am trying to execute an equation into python program considering monthly folder, but I am getting error, Below i have attached reference of the equation also, Where P and R for rasterlist1 and rasterlist2 respectively,
Error message is.
Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
File <SPAN class="string token">"<module3>"</SPAN><SPAN class="punctuation token">,</SPAN> line <SPAN class="number token">23</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
TypeError<SPAN class="punctuation token">:</SPAN> can<SPAN class="string token">'t multiply sequence by non-int of type '</SPAN>list'<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Script i am working,
<SPAN class="keyword token">import</SPAN> arcpy<SPAN class="punctuation token">,</SPAN> os<SPAN class="punctuation token">,</SPAN> calendar
<SPAN class="keyword token">import</SPAN> numpy
<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>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>
topWorkspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'D:\NPP_GUJARAT_MONSOON'</SPAN>
ws_out <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'D:\NPP_GUJARAT_MONSOON\EVA3'</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> topWorkspace
months <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>calendar<SPAN class="punctuation token">.</SPAN>month_name<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>upper<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> str<SPAN class="punctuation token">(</SPAN>i<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>zfill<SPAN class="punctuation token">(</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">13</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">}</SPAN> <SPAN class="comment token"># Get dict of months and month number (i.e. January = 001, March = 003 etc.)</SPAN>
<SPAN class="comment token"># Step through list of all folders</SPAN>
<SPAN class="keyword token">for</SPAN> folderPath <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListWorkspaces<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
baseName <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>folderPath<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>upper<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> baseName <SPAN class="keyword token">in</SPAN> months<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># Test that subfolder is a month name</SPAN>
monthNumber <SPAN class="operator token">=</SPAN> months<SPAN class="punctuation token">[</SPAN>baseName<SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># Get month-number for use in output filename</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> folderPath
<SPAN class="comment token"># list rasters (Erlier:*Max_Temper.tif, We changed it to below)</SPAN>
rasterList1 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Precipitat*.tif'</SPAN><SPAN class="punctuation token">)</SPAN>
rasterList2 <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListRasters<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Solar*.tif'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> rasterList1<SPAN class="punctuation token">,</SPAN> rasterList2
<SPAN class="keyword token">for</SPAN> ras_name <SPAN class="keyword token">in</SPAN> rasterList1<SPAN class="punctuation token">:</SPAN>
ras_mean <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>folderPath<SPAN class="punctuation token">,</SPAN> ras_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> ras_name <SPAN class="keyword token">in</SPAN> rasterList2<SPAN class="punctuation token">:</SPAN>
ras_mean <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Raster<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>folderPath<SPAN class="punctuation token">,</SPAN> ras_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
outCellStatistics <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>rasterList1 <SPAN class="operator token">*</SPAN> rasterList2<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">*</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>Square<SPAN class="punctuation token">(</SPAN>rasterList1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>Square<SPAN class="punctuation token">(</SPAN>rasterList2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> rasterList1 <SPAN class="operator token">*</SPAN> rasterList2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">/</SPAN>rasterList1 <SPAN class="operator token">+</SPAN> rasterList2 <SPAN class="operator token">*</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>Square<SPAN class="punctuation token">(</SPAN>rasterList1<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="punctuation token">(</SPAN>Square<SPAN class="punctuation token">(</SPAN>rasterList2<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#Save the output</SPAN>
outRasterName <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>ws_out<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"EO_{}.tif"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>monthNumber<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
outCellStatistics<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN>outRasterName<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> outRasterName
<SPAN class="comment token">#print done</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">'done'</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> 