<?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 Re: Sum 6,000+ rasters - Python script in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556473#M43490</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To give you a start (code below is not tested!):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy

&amp;nbsp;&amp;nbsp;&amp;nbsp; data_path = r'E:\BOM\daily-temperature\daily-maximum-temperature\max_temp_1971_2000_grids'
&amp;nbsp;&amp;nbsp;&amp;nbsp; # out_path = r'E:\BOM\daily-temperature\daily-maximum-temperature'
&amp;nbsp;&amp;nbsp;&amp;nbsp; res_ws = r'E:\BOM\daily-temperature\daily-maximum-temperature\yourGDB.gdb' # I prefer gdb over folder

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.overwriteOutput = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CheckOutExtension('Spatial')
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = data_path

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create fgdb res_ws
&amp;nbsp;&amp;nbsp;&amp;nbsp; path, name = os.path.split(res_ws)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFileGDB_management(path, name)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #create a list of rasters in the workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters()

&amp;nbsp;&amp;nbsp;&amp;nbsp; i = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_cellstat = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for rasters_chunk in chunks(rasters, 500):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat = arcpy.sa.CellStatistics(rasters_chunk, "SUM", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = os.path.join(res_ws, "cellstat{0}".format(i))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat.save(outname)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_cellstat.append(outname)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create the final raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat = arcpy.sa.CellStatistics(lst_cellstat, "SUM", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = os.path.join(res_ws, "total_sum")
&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat.save(outname)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # eliminate intermediate results
&amp;nbsp;&amp;nbsp;&amp;nbsp; for ras in lst_cellstat:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(ras)

def chunks(l, n):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """ Yield successive n-sized chunks from l."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in xrange(0, len(l), n):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield l&lt;I&gt;&lt;/I&gt;

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 00:02:17 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2021-12-12T00:02:17Z</dc:date>
    <item>
      <title>Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556465#M43482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to sum close to 6,000 ESRI grids and found a piece of script on this forum that I have tried to adapt (attached). The script runs fine and prompts every grid but eventually crashes when it reaches the last raster. No output is created.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would you have any idea as to why it crashes? The script seems to work fine when I test it on 5-10 grids. Could the reason be the 5,000 ESRI grid limit&amp;nbsp; that can be stored in a single workspace directory (&lt;A href="http://desktop.arcgis.com/en/desktop/latest/manage-data/raster-and-images/esri-grid-format.htm" title="http://desktop.arcgis.com/en/desktop/latest/manage-data/raster-and-images/esri-grid-format.htm"&gt;Esri Grid format—Help | ArcGIS for Desktop&lt;/A&gt;) ? I did try on less than 5,000 grids but had the same outcome.&lt;/P&gt;&lt;P&gt;I am using ArcGIS 10.2.2 and Python 2.7.5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mathieu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 10:05:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556465#M43482</guid>
      <dc:creator>MathieuLacorde1</dc:creator>
      <dc:date>2016-02-02T10:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556466#M43483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;the download has a ...py.zip filename, but the zip file contains an addin. do you have the script?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 11:10:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556466#M43483</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-02-02T11:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556467#M43484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The zip file contains the *.py that I edited and ran within IDLE. Here is the script:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import os,sys&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sPath = sys.path[0]&lt;/P&gt;&lt;P&gt;dataPath = 'E:\BOM\daily-temperature\daily-maximum-temperature\max_temp_1971_2000_grids' # ADD your workspace path here&lt;/P&gt;&lt;P&gt;outPath = 'E:\BOM\daily-temperature\daily-maximum-temperature'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = 1&lt;/P&gt;&lt;P&gt;arcpy.CheckOutExtension('Spatial')&lt;/P&gt;&lt;P&gt;arcpy.env.scratchWorkspace = outPath&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = dataPath&lt;/P&gt;&lt;P&gt;#create a list of rasters in the workspace&lt;/P&gt;&lt;P&gt;rasters = arcpy.ListRasters('','')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i = 0&lt;/P&gt;&lt;P&gt;#loop through rasters in list&lt;/P&gt;&lt;P&gt;for raster in rasters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "processing raster: %s" %os.path.join(dataPath,raster)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #convert nodata to zero&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out1 = Con(IsNull(raster), 0, raster)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; #sum rasters together&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == 0:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out2 = out1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out2 = out2 + out1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1&lt;/P&gt;&lt;P&gt;#save final output&lt;/P&gt;&lt;P&gt;out2.save(os.path.join(outPath,'sumRas2'))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mathieu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 11:28:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556467#M43484</guid>
      <dc:creator>MathieuLacorde1</dc:creator>
      <dc:date>2016-02-02T11:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556468#M43485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to make the thread more readable I have included the script you attached:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import os,sys
import arcpy
from arcpy.sa import *

sPath = sys.path[0]
dataPath = 'E:\BOM\daily-temperature\daily-maximum-temperature\max_temp_1971_2000_grids' # ADD your workspace path here
outPath = 'E:\BOM\daily-temperature\daily-maximum-temperature'

arcpy.env.overwriteOutput = 1
arcpy.CheckOutExtension('Spatial')
arcpy.env.scratchWorkspace = outPath
arcpy.env.workspace = dataPath
#create a list of rasters in the workspace
rasters = arcpy.ListRasters('','')

i = 0
#loop through rasters in list
for raster in rasters:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "processing raster: %s" %os.path.join(dataPath,raster)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #convert nodata to zero
&amp;nbsp;&amp;nbsp;&amp;nbsp; out1 = Con(IsNull(raster), 0, raster)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #sum rasters together
&amp;nbsp;&amp;nbsp;&amp;nbsp; if i == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out2 = out1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; out2 = out2 + out1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1

#save final output
out2.save(os.path.join(outPath,'sumRas2'))&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The first thing I notice is the long path with multiple minus signs. This can cause problems when working with grid files. The number of files in a single folder can be the cause of problems too. I also notice that for each raster you first set the NoData cells to 0 and then add it to the sum. Have you considered using &lt;A href="http://desktop.arcgis.com/en/desktop/latest/tools/spatial-analyst-toolbox/cell-statistics.htm" title="http://desktop.arcgis.com/en/desktop/latest/tools/spatial-analyst-toolbox/cell-statistics.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Cell Statistics—Help | ArcGIS for Desktop&lt;/A&gt;​ with the SUM statistics type and the DATA option. This allows you to sum multiple rasters and ignore the NoData cells (they will be considered 0 in the SUM operation). I don't think you will be able to use 6000 rasters as inputs but you can chunk the list and perform it on smaller batches and afterwards on the intermediate results.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:02:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556468#M43485</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T00:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556469#M43486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Xander,&lt;/P&gt;&lt;P&gt;I did try without setting the NoData cells to Zero and it didn't change the result. The Cell Statistics tool only allows 1,000 rasters if I am not mistaken so I could give it a go in several batches. The thing is I have to run this script on another 10,000 files and I was hoping to get it to work on the whole workspace.&lt;/P&gt;&lt;P&gt;It looks like I will have to subdivide my data though. I'll try to shorten the path too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 11:49:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556469#M43486</guid>
      <dc:creator>MathieuLacorde1</dc:creator>
      <dc:date>2016-02-02T11:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556470#M43487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When I mentioned using chunk, I was referring to let Python divide the list of rasters into chunks of less than 1000 rasters, perform the sum and store the result temporarily and at the end of the chunks, combine the temporal results into one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An example of how to "chunk":&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; my_list = ["Raster{0}".format(i) for i in range(100)]

&amp;nbsp;&amp;nbsp;&amp;nbsp; for my_list_chunk in chunks(my_list, 10):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print my_list_chunk

def chunks(l, n):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """ Yield successive n-sized chunks from l."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in xrange(0, len(l), n):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield l&lt;I&gt;&lt;/I&gt;

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will yield 10 lists with 10 elements each:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;['Raster0', 'Raster1', 'Raster2', 'Raster3', 'Raster4', 'Raster5', 'Raster6', 'Raster7', 'Raster8', 'Raster9']
['Raster10', 'Raster11', 'Raster12', 'Raster13', 'Raster14', 'Raster15', 'Raster16', 'Raster17', 'Raster18', 'Raster19']
['Raster20', 'Raster21', 'Raster22', 'Raster23', 'Raster24', 'Raster25', 'Raster26', 'Raster27', 'Raster28', 'Raster29']
['Raster30', 'Raster31', 'Raster32', 'Raster33', 'Raster34', 'Raster35', 'Raster36', 'Raster37', 'Raster38', 'Raster39']
['Raster40', 'Raster41', 'Raster42', 'Raster43', 'Raster44', 'Raster45', 'Raster46', 'Raster47', 'Raster48', 'Raster49']
['Raster50', 'Raster51', 'Raster52', 'Raster53', 'Raster54', 'Raster55', 'Raster56', 'Raster57', 'Raster58', 'Raster59']
['Raster60', 'Raster61', 'Raster62', 'Raster63', 'Raster64', 'Raster65', 'Raster66', 'Raster67', 'Raster68', 'Raster69']
['Raster70', 'Raster71', 'Raster72', 'Raster73', 'Raster74', 'Raster75', 'Raster76', 'Raster77', 'Raster78', 'Raster79']
['Raster80', 'Raster81', 'Raster82', 'Raster83', 'Raster84', 'Raster85', 'Raster86', 'Raster87', 'Raster88', 'Raster89']
['Raster90', 'Raster91', 'Raster92', 'Raster93', 'Raster94', 'Raster95', 'Raster96', 'Raster97', 'Raster98', 'Raster99']&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One question, I don't think your goal is to get the total sum of maximum temperatures, right? You are probably looking for an average (dividing the sum by the number of rasters)? The Cell Statistics also comes with the MEAN statistics type and other perhaps interesting statistics types.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:02:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556470#M43487</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T00:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556471#M43488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for that, I wouldn't have thought about it!&lt;/P&gt;&lt;P&gt;You're right, my goal is not to get the total sum but it is a first step into a more complex calculation. Once I get this script running smoothly, I will fine tune the calculation. &lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 12:09:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556471#M43488</guid>
      <dc:creator>MathieuLacorde1</dc:creator>
      <dc:date>2016-02-02T12:09:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556472#M43489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I noticed another thing... the way you specify your paths. This will probably yield problems. There is a nice post by &lt;A href="https://community.esri.com/migrated-users/3116"&gt;Dan Patterson&lt;/A&gt;​ that explains in more detail about paths in Python: &lt;A href="https://community.esri.com/migration-blogpost/55463"&gt;Filenames and file paths in Python&lt;/A&gt; .&lt;/P&gt;&lt;P&gt;I usually prefer the raw notation (put an r in front of the path, outside the quotes).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 12:18:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556472#M43489</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2016-02-02T12:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556473#M43490</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To give you a start (code below is not tested!):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;def main():
&amp;nbsp;&amp;nbsp;&amp;nbsp; import os
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcpy

&amp;nbsp;&amp;nbsp;&amp;nbsp; data_path = r'E:\BOM\daily-temperature\daily-maximum-temperature\max_temp_1971_2000_grids'
&amp;nbsp;&amp;nbsp;&amp;nbsp; # out_path = r'E:\BOM\daily-temperature\daily-maximum-temperature'
&amp;nbsp;&amp;nbsp;&amp;nbsp; res_ws = r'E:\BOM\daily-temperature\daily-maximum-temperature\yourGDB.gdb' # I prefer gdb over folder

&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.overwriteOutput = True
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CheckOutExtension('Spatial')
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.env.workspace = data_path

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create fgdb res_ws
&amp;nbsp;&amp;nbsp;&amp;nbsp; path, name = os.path.split(res_ws)
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CreateFileGDB_management(path, name)

&amp;nbsp;&amp;nbsp;&amp;nbsp; #create a list of rasters in the workspace
&amp;nbsp;&amp;nbsp;&amp;nbsp; rasters = arcpy.ListRasters()

&amp;nbsp;&amp;nbsp;&amp;nbsp; i = 0
&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_cellstat = []
&amp;nbsp;&amp;nbsp;&amp;nbsp; for rasters_chunk in chunks(rasters, 500):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat = arcpy.sa.CellStatistics(rasters_chunk, "SUM", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = os.path.join(res_ws, "cellstat{0}".format(i))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat.save(outname)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_cellstat.append(outname)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # create the final raster
&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat = arcpy.sa.CellStatistics(lst_cellstat, "SUM", "DATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = os.path.join(res_ws, "total_sum")
&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat.save(outname)

&amp;nbsp;&amp;nbsp;&amp;nbsp; # eliminate intermediate results
&amp;nbsp;&amp;nbsp;&amp;nbsp; for ras in lst_cellstat:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Delete_management(ras)

def chunks(l, n):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """ Yield successive n-sized chunks from l."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; for i in xrange(0, len(l), n):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield l&lt;I&gt;&lt;/I&gt;

if __name__ == '__main__':
&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:02:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556473#M43490</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-12T00:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556474#M43491</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'll try it as soon as I can!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 13:53:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556474#M43491</guid>
      <dc:creator>MathieuLacorde1</dc:creator>
      <dc:date>2016-02-02T13:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556475#M43492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;res_ws = r&lt;SPAN class="string"&gt;'E:\BOM\daily-temperature\daily-maximum-temperature\yourGDB.gdb' &lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN class="comment"&gt;# I prefer gdb over folder&lt;/SPAN&gt;&lt;/STRONG&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 agree.&amp;nbsp; Not sure how many times it has occurred but simply moving things into a FGDB resolves various issues I've run into.&amp;nbsp; Pretty much I've just accepted the fact that there's probably a darn good reason why ESRI engineers have fully integrated the fgdb (Default.gdb) into the ArcGIS product, so why not follow?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 13:58:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556475#M43492</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2016-02-02T13:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556476#M43493</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with &lt;A href="https://community.esri.com/migrated-users/3100"&gt;Xander Bakker&lt;/A&gt;&amp;nbsp; that the dashes in the file path may be an issue.&amp;nbsp; Maybe try using a different folder structure that does not have dashes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A general suggestion.&amp;nbsp; With Grid files, shorter is usually better in terms of paths and filenames.&amp;nbsp; Oftentimes if the combined length of filename &lt;SPAN style="text-decoration: underline;"&gt;and&lt;/SPAN&gt; path is long, there can be issues.&amp;nbsp; Yet the same process will often work fine if the path is simplified to be very short.&amp;nbsp; In theory it shouldn't matter, but there can be a difference.&amp;nbsp; So try a shorter path, that may resolve it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#/Esri_Grid_format/009t0000000w000000/" title="http://resources.arcgis.com/en/help/main/10.2/index.html#/Esri_Grid_format/009t0000000w000000/"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt; - ESRI Grid format&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Chris Donohue, GISP&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Feb 2016 16:05:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556476#M43493</guid>
      <dc:creator>ChrisDonohue__GISP</dc:creator>
      <dc:date>2016-02-02T16:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556477#M43494</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your computer might not have enough memory.&amp;nbsp; As &lt;A href="https://community.esri.com/migrated-users/3100"&gt;Xander Bakker&lt;/A&gt;​ states, try smaller chunks of rasters.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 04 Feb 2016 18:56:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556477#M43494</guid>
      <dc:creator>TonySoeller</dc:creator>
      <dc:date>2016-02-04T18:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556478#M43495</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mathieu&lt;/P&gt;&lt;P&gt;I would also recommend trying the FGDB ideas given above. And if &lt;A href="https://community.esri.com/migrated-users/3100"&gt;Xander Bakker&lt;/A&gt;'s good looking code doesn't do the trick, I have some further options that might be worthy to check out. We ran into similar problems at work while processing a large number of (raster)data in Python scripts. The following helped us solving similar issues as you are currently experiencing:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Monitor your computers memory while the tool runs using Task Manager. Should there be a memory issue, or if the above ideas using the FGDB does not work try the following:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Write a .BAT file that accesses the Python.exe and then opens your script. Insert all the necessary arguments in the command line script. You can prepare the batches using an Editor or Excel.&lt;/LI&gt;&lt;LI&gt;This way you'll be able to process a large number of iterations of your script outside the ArcCatalog environment, which (in case there are any in the first place) would solve the memory issues, because running a BAT-script means that the Python environment is closed after each iteration and loaded again for the next.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Feb 2016 07:07:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556478#M43495</guid>
      <dc:creator>AndreasSutter2</dc:creator>
      <dc:date>2016-02-05T07:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556479#M43496</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Sorry to only get back to you now,&amp;nbsp; I just had a chance to look at the script today... I removed the dashes and tried to use shorter pathnames. I ran the script and got an error message:&lt;/P&gt;&lt;P&gt;File "E:/Software/new_script_geonet.py", line 44, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "E:/Software/new_script_geonet.py", line 26, in main&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cellstat.save(outname)&lt;/P&gt;&lt;P&gt;RuntimeError: ERROR 010240: Could not save raster dataset to E:\BOM\daily_temp\daily_max_temp\MaxTemp.gdb\cellstat1 with output format FGDBR.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas on what I could modify in the script to get it right?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mathieu&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Mar 2016 09:09:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556479#M43496</guid>
      <dc:creator>MathieuLacorde1</dc:creator>
      <dc:date>2016-03-06T09:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556480#M43497</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;try a different format... just add .tif to the output name&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Mar 2016 11:54:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556480#M43497</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-06T11:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556481#M43498</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;Struggling a bit as to where I should add the extension ".tif". I would say:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = os.path.join(res_ws, "cellstat{0}".format(i).tif)&lt;/P&gt;&lt;P&gt;However, I still get an error message, different one though:&lt;/P&gt;&lt;P&gt;File "E:\Software\new_script_geonet_revB.py", line 45, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; main()&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "E:\Software\new_script_geonet_revB.py", line 26, in main&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = os.path.join(res_ws, "cellstat{0}".format(i).tif)&lt;/P&gt;&lt;P&gt;AttributeError: 'str' object has no attribute 'tif'&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Mar 2016 12:55:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556481#M43498</guid>
      <dc:creator>MathieuLacorde1</dc:creator>
      <dc:date>2016-03-06T12:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556482#M43499</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well according to this &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/cell-statistics.htm" title="http://desktop.arcgis.com/en/arcmap/latest/tools/spatial-analyst-toolbox/cell-statistics.htm"&gt;Cell Statistics—Help | ArcGIS for Desktop&lt;/A&gt; &lt;/P&gt;&lt;P&gt;you should be able to save to an Esri grid format (with no file extension given)&lt;/P&gt;&lt;P&gt;But the only example that they give there is one with an img or grid format, but saved to a folder rather than a geodatabase.&amp;nbsp; So, I don't know why it won't save to the geodatabase but I do know that esri grids don't like anything in their paths other than letters, the underscore and maybe the odd number (not beginning any folder segment), although Xander's example suggests otherwise.&amp;nbsp; So you can try saving to a folder until &lt;A href="https://community.esri.com/migrated-users/3100"&gt;Xander Bakker&lt;/A&gt;​ can comment&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Mar 2016 14:11:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556482#M43499</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-03-06T14:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556483#M43500</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The error refers to not being able to write to the output File Geodatabase. The Help states: &lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;SPAN style="color: #000000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12.8px;"&gt;Check that a raster with the same name and format does not already exist in the output location. Also, check the Help for the technical specifications of raster dataset formats to make sure that the expected range of values in the output is compatible with the specified format&lt;/SPAN&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;Just to be sure "&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; font-size: 14px;"&gt;MaxTemp.gdb" is a file geodatabase and you have privileges to write to that location? &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #3d3d3d; font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif; font-size: 14px;"&gt;And at what moment does the error occur,when writing the first raster to that location or when part of the data has been processed?&lt;/SPAN&gt;&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; font-size: 14px;"&gt;You could include "arcpy.env.overwriteOutput = True" at the beging of the scipt (after "import arcpy")&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Mar 2016 19:11:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556483#M43500</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2016-03-06T19:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sum 6,000+ rasters - Python script</title>
      <link>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556484#M43501</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The line you included doesn't add the ".tif" correctly. Change:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14572915775791177" data-renderedposition="60_8_1332_16" jivemacro_uid="_14572915775791177"&gt;&lt;P&gt;outname = os.path.join(res_ws, "cellstat{0}".format(i).tif)&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;into&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14572915832097590" data-renderedposition="102_8_1332_16" jivemacro_uid="_14572915832097590"&gt;&lt;P&gt;outname = os.path.join(res_ws, "cellstat{0}.tif".format(i))&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and be sure that the res_ws points to a folder and not a File Geodatabase.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 06 Mar 2016 19:13:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/sum-6-000-rasters-python-script/m-p/556484#M43501</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2016-03-06T19:13:28Z</dc:date>
    </item>
  </channel>
</rss>

