<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Model Builder/Python: batch raster calculation in ArcGIS Spatial Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441541#M6234</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wish to carry out a raster calculation on a batch of rasters. &lt;BR /&gt;I want to add rasters by month, as identified by their file name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I.e. all rasters within the month of January should add together and output a single jan.png/raster file. Then all the rasters within Feb should add together and produce a single FEB.png.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rather than manually write a new rast calc expression for each month, I would prefer to automate it via either python or modelbuilder.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My plan outline is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;Input Files. 36 Weekly raster files&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;5jan15-11jan15.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;12jan15-18jan15.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;19jan15-25jan15.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;26jan15-31jan15.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;01feb15-07feb15.png....&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;Raster operation.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;(raster1+raster2+raster3+raster4)/(raster1+raster2+raster3+raster4) = month.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;output. 12 rasters for each month.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;jan.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;feb.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;march.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;is it possible to write a python expression or create a modelbuilder which will add rasters by month using their filename?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;Current Attempts&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I have built a model, however this only runs on the rasters I provide it, requiring me to write a new expression each time. In other words it's the same as manually running raster calculator and writing a new expression for each month, I wish to automate this via modelbuilder. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="193162" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/193162_pastedImage_5.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Mar 2016 08:38:43 GMT</pubDate>
    <dc:creator>TomHawkins</dc:creator>
    <dc:date>2016-03-28T08:38:43Z</dc:date>
    <item>
      <title>Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441541#M6234</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wish to carry out a raster calculation on a batch of rasters. &lt;BR /&gt;I want to add rasters by month, as identified by their file name.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I.e. all rasters within the month of January should add together and output a single jan.png/raster file. Then all the rasters within Feb should add together and produce a single FEB.png.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rather than manually write a new rast calc expression for each month, I would prefer to automate it via either python or modelbuilder.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My plan outline is as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;Input Files. 36 Weekly raster files&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;5jan15-11jan15.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;12jan15-18jan15.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;19jan15-25jan15.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;26jan15-31jan15.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;01feb15-07feb15.png....&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;Raster operation.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;(raster1+raster2+raster3+raster4)/(raster1+raster2+raster3+raster4) = month.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;output. 12 rasters for each month.&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;jan.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;feb.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;march.png&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;/P&gt;&lt;P&gt;is it possible to write a python expression or create a modelbuilder which will add rasters by month using their filename?&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;Current Attempts&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I have built a model, however this only runs on the rasters I provide it, requiring me to write a new expression each time. In other words it's the same as manually running raster calculator and writing a new expression for each month, I wish to automate this via modelbuilder. &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="193162" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/193162_pastedImage_5.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 08:38:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441541#M6234</guid>
      <dc:creator>TomHawkins</dc:creator>
      <dc:date>2016-03-28T08:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441542#M6235</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you will have to read up on iterators&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/modelbuilder/a-quick-tour-of-using-iterators-for-iteration-looping-.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/modelbuilder/a-quick-tour-of-using-iterators-for-iteration-looping-.htm"&gt;A quick tour of using iterators—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/modelbuilder-toolbox/examples-of-using-iterators-in-modelbuilder.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/modelbuilder-toolbox/examples-of-using-iterators-in-modelbuilder.htm"&gt;Examples of using iterators in ModelBuilder—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 10:36:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441542#M6235</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-28T10:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441543#M6236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan, I've been reading up on iterators and trying to wrap my head around them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the examples I have seen it seems it will cause the raster Calc to run on EACH of the rasters. Whereas I only want it to run on GROUPS of the raster, which are grouped by month.&lt;/P&gt;&lt;P&gt;i.e. I want the following...&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;(janweek1+janweek2+janweek3+janweek4) /(&lt;SPAN style="background-color: #f6f6f6;"&gt;(janweek1+janweek2+janweek3+janweek4))&lt;/SPAN&gt;= jan.png&lt;/P&gt;&lt;P&gt;(febweek1+febweek2+febweek3+febweek4)/&lt;SPAN style="background-color: #f6f6f6;"&gt;(janweek1+janweek2+janweek3+janweek4)&lt;/SPAN&gt; = feb.png&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;yet from my understanding the iterator will produce something akin to&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;janweek1+janweek2+janweek3+janweek4 + febweek1+febweek2+febweek3+febweek4....=month.png&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 16:05:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441543#M6236</guid>
      <dc:creator>TomHawkins</dc:creator>
      <dc:date>2016-03-28T16:05:53Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441544#M6237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can make a new table to hold the month names (row values = jan, feb, etc.). Then Iterate through those with &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/modelbuilder-toolbox/examples-of-using-iterators-in-modelbuilder.htm#ESRI_SECTION1_33EDB1C8829F4CF4BBD5DABAA3ED34DD" rel="nofollow noopener noreferrer" target="_blank"&gt;Iterate Field Values&lt;/A&gt;. Finally, use the outputs of that simple &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/analyze/modelbuilder/integrating-model-within-a-model.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;submodel &lt;/A&gt;to feed into the wildcard parameter of &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/modelbuilder-toolbox/examples-of-using-iterators-in-modelbuilder.htm#ESRI_SECTION1_2972801CD03B4BD49859ABB24FE01DB4" rel="nofollow noopener noreferrer" target="_blank"&gt;Iterate Rasters&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately, using multiple iterators is a relatively complex way to do something very straight forward in Python. Something like:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;This is a list of month names.
For each month name, loop through rasters.
If the raster name contains the month name, add it and save it.&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:45:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441544#M6237</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T19:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441545#M6238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've read that this is something that would be easier in Python. If you could provide some advice as to a python-like solution that would be brilliant and perhaps less mind boggling. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like Python to run the calculator expression by months.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 16:22:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441545#M6238</guid>
      <dc:creator>TomHawkins</dc:creator>
      <dc:date>2016-03-28T16:22:37Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441546#M6239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Adding to your notes, what I would try to achieve is this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;This is a list of month names.&amp;nbsp; &lt;/LI&gt;&lt;LI&gt;For each month name, loop through rasters.&amp;nbsp; &lt;/LI&gt;&lt;LI&gt;If the raster name contains the month name, add it and save it. &lt;/LI&gt;&lt;/OL&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI&gt;output: JAN = (janweek1, janweek2, janweek3, janweek4), FEB = (febweek1,febweek2,febweek3,febweek4)...&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp; 4. For each month, run the set of rasters through the following expression&lt;/P&gt;&lt;UL&gt;&lt;UL&gt;&lt;LI&gt;(week1+week2+week3+week4)/(week1+week2+week3+week4) = month.png&lt;/LI&gt;&lt;LI&gt;result: jan.png, feb.png, march.png...&lt;/LI&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 16:33:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441546#M6239</guid>
      <dc:creator>TomHawkins</dc:creator>
      <dc:date>2016-03-28T16:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441547#M6240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Untested - there may be errors:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import calendar, os # import libraries
arcpy.env.workspace = r'C:\myfolder\anotherfolder' # your workspace
for month in calendar.month_abbr: # loop through 3-letter month abbreviations
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters('*' + month.lower() + '*') # make list of matching rasters in workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; monthsum = sum(rasters) # add matching rasters together
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; monthsum.save(os.path.join(r'C:\myfolder\anotherfolder',month.lower()+'sum.png' ) # save to new raster&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:45:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441547#M6240</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T19:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441548#M6241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Darren. &lt;BR /&gt;Does line 5 represent the raster calculator expression?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately my actual expression is a little more complicated than provided...&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Float(Con(IsNull("w1") ,0,"w1") + Con(IsNull("w2"), 0,"w2")+Con(IsNull("w3"), 0,"w3")+Con(IsNull("w4"), 0,"w4") )/(Con(IsNull("w1"), 0,1) + Con(IsNull("w2"), 0,1)+Con(IsNull("w3"), 0,1)+Con(IsNull("w4"), 0,1))&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That expression is only valid if there is 4 rasters for that month of course, there could only be three etc. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A crux of problem is trying to tell Arcmap that the variables 'week1, week2, week3, week4` are dynamic, meaning that the input rasters change for each month. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In other words I'm trying to create a "dynamic expression"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The basic expression is &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;Float(Con(IsNull("w1") ,0,"w1") + &lt;SPAN style="background-color: #f6f6f6;"&gt;Con(IsNull("w2"), 0,"w2") &lt;/SPAN&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;/(Con(IsNull("w1"), 0,1) + Con(IsNull("w2"), 0,1)&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I would like this expression to adapt to each month, automatically inputting the rasters of that group and returning a `month.png/raster`&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 16:51:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441548#M6241</guid>
      <dc:creator>TomHawkins</dc:creator>
      <dc:date>2016-03-28T16:51:57Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441549#M6242</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;Here's what I would try. Again, untested (sorry, I'm too lazy to duplicate your raster folder setup). I'm not 100% sure that you can sum rasters using sum(), but it's worth a shot.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;import&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; calendar, os &lt;/SPAN&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;# import libraries&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;arcpy.env.workspace = r&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;'C:\myfolder\anotherfolder'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; &lt;/SPAN&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;# your workspace&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; month &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; calendar.month_abbr: &lt;/SPAN&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;# loop through 3-letter month abbreviations&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters(&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;'*' + month.lower() + '*'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;) &lt;/SPAN&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;# make list of matching rasters in workspace&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; con_rasters = [] # empty list&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for raster in rasters: # loop through matching rasters&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; con_rasters.append(Con(IsNull(raster),0,raster)) # run Con expression and add to list
&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; monthsum = sum(con_rasters) # add Con rasters&lt;/SPAN&gt;
&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; monthsum.save(os.path.join(r&lt;SPAN class="string" style="font-weight: inherit; font-style: inherit; color: blue; font-size: 9pt !important; background-color: inherit;"&gt;'C:\myfolder\anotherfolder',month.lower()+'sum.png'&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; ) &lt;/SPAN&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;# save to new raster&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN style="background-color: inherit; color: black; font-weight: inherit; font-size: 9pt !important; font-style: inherit;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:45:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441549#M6242</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T19:45:35Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441550#M6243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, but I'm a little bit confused, this is most likely due to my naivety in reading Python syntax.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;When looking at lines 05-07. of code, I see&lt;/P&gt;&lt;OL class="dp-py" start="1" style="font-size: 12px; font-family: Consolas, 'Courier New', Courier, mono, serif; color: #5c5c5c; margin-bottom: 1px !important; margin-left: 45px !important;"&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;con_rasters = [] &lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;# empty list&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;for&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; raster &lt;/SPAN&gt;&lt;SPAN class="keyword" style="font-weight: inherit; font-style: inherit; color: #006699; font-size: 9pt !important; background-color: inherit;"&gt;in&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt; rasters: &lt;/SPAN&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;# loop through matching rasters&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; color: black; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; con_rasters.append(Con(IsNull(raster),&lt;SPAN class="number" style="font-weight: inherit; font-style: inherit; color: green; font-size: 9pt !important; background-color: inherit;"&gt;0&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;,raster)) &lt;/SPAN&gt;&lt;SPAN class="comment" style="font-weight: inherit; font-style: inherit; color: #008200; font-size: 9pt !important; background-color: inherit;"&gt;# run Con expression and add to list&lt;/SPAN&gt;&lt;SPAN style="font-weight: inherit; font-style: inherit; font-size: 9pt !important; background-color: inherit;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I feel that it is only running the first half of the expression, which is...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background-color: #f6f6f6; color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;Float(Con(IsNull("w1") ,0,"w1") + Con(IsNull("w2"), 0,"w2")+Con(IsNull("w3"), 0,"w3")+Con(IsNull("w4"), 0,"w4") &lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;and leaving out the second half of the expression which is....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; background-color: #f6f6f6;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; / (Con(IsNull("w1"), 0,1) + Con(IsNull("w2"), 0,1)+Con(IsNull("w3"), 0,1)+Con(IsNull("w4"), 0,1))&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The expression is essentially the number of times a cell had a value and divide by the number of times it was possible for a value to be detected. The numerator in this case is how many times the pixel had the value 1. The denominator is now many times the pixel did not have No Data (i.e. it had the value 1 or 0).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Expression:&lt;/P&gt;&lt;P&gt;number of times a cell had a value / number of times the cell could have had a value&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Float(Con(IsNull(A),0,A) + Con(IsNull(B),0,B) + Con(IsNull(C),0,C)) / (~IsNull(A) + ~IsNull(B) + ~IsNull(C))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope that clarifies what I'm trying to achieve and apologies if I've misunderstood your code!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 17:19:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441550#M6243</guid>
      <dc:creator>TomHawkins</dc:creator>
      <dc:date>2016-03-28T17:19:57Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441551#M6244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I need to hop off here for a while - just wanted you to know that yes, I completely missed the division part.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Mar 2016 17:41:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441551#M6244</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2016-03-28T17:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Model Builder/Python: batch raster calculation</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441552#M6245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Darren, the Cell Statistics tool would be a lot easier - it has an option to ignore NoData in the calculation, saving you all that work with Con!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14592259868123639 jive_text_macro" data-renderedposition="60_8_1168_16" jivemacro_uid="_14592259868123639"&gt;&lt;P&gt;CellStatistics(rasters, "SUM", "DATA")&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Mar 2016 04:34:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/model-builder-python-batch-raster-calculation/m-p/441552#M6245</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2016-03-29T04:34:07Z</dc:date>
    </item>
  </channel>
</rss>

