<?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: Looping over the list of rasters in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659966#M51280</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan thanks for your reply. Sorry the line lastdek, it should be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lastdek = (last3, first3).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the script that I am trying but with no success. I think the range that I specified below (line 14) still refers to my list of rasters data in my rasters variable (line 7).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;gt;&amp;gt;&amp;gt; import arcpy


&amp;gt;&amp;gt;&amp;gt; from arcpy import env


&amp;gt;&amp;gt;&amp;gt; from arcpy.sa import *


&amp;gt;&amp;gt;&amp;gt; arcpy.CheckOutExtension("Spatial")


u'CheckedOut'


&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace = 'raster/path'


&amp;gt;&amp;gt;&amp;gt; rasters = arcpy.ListRasters("*", "tif")


&amp;gt;&amp;gt;&amp;gt; last4 = range(362,366)


&amp;gt;&amp;gt;&amp;gt; first3 = range(0,3)


&amp;gt;&amp;gt;&amp;gt; lastdek = (last4,first3)


&amp;gt;&amp;gt;&amp;gt; lastdek


([362, 363, 364, 365], [0, 1, 2])


&amp;gt;&amp;gt;&amp;gt; dek = []


&amp;gt;&amp;gt;&amp;gt; for l in range(0,7):


...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print l


...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dek.append(rasters&lt;L&gt;)&lt;/L&gt;


... 


0


1


2


3


4


5


6


&amp;gt;&amp;gt;&amp;gt; outCellStatistics = CellStatistics(dek, "MEAN", "NODATA")


&amp;gt;&amp;gt;&amp;gt; output = 'folder/path/dek_037.tif'


&amp;gt;&amp;gt;&amp;gt; outCellStatistics.save(output)

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a workaround to set the range starting from the last four rasters to the first three rasters in my list?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&lt;SPAN class="keyword"&gt;for l &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; range(&lt;SPAN class="number"&gt;363&lt;/SPAN&gt;,&lt;SPAN class="number"&gt;3&lt;/SPAN&gt;):&amp;nbsp; &lt;/SPAN&gt;


&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print l
&lt;/SPAN&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Leo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 03:55:18 GMT</pubDate>
    <dc:creator>Leo_KrisPalao</dc:creator>
    <dc:date>2021-12-12T03:55:18Z</dc:date>
    <item>
      <title>Looping over the list of rasters</title>
      <link>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659964#M51278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi GeoNet community,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a little bit of problem in my code. I have a raster list from 0-365 representing day of year (doy1-doy366). I would like to calculate the mean of my rasters using the last three rasters (these are raster364, raster365, raster366, which are indexed as 363,364,365) and the first three rasters of my list (raster1, raster2, and raster3, which are indexed as 0, 1, 2).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this is my initial code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14107586718357350 jive_text_macro" jivemacro_uid="_14107586718357350" modifiedtitle="true"&gt;
&lt;P&gt;rasters = arcpy.ListRasters("*", "tif")&lt;/P&gt;
&lt;P&gt;last3 = range(363,366)&lt;/P&gt;
&lt;P&gt;first3 = range(0,3)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;lastdek = (last5, first1)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;lastDekad = []&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# process only the 6 rasters - last and first three rasters&lt;/P&gt;
&lt;P&gt;for l in range(0,7):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print l&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lastDekad.append(rasters&lt;L&gt;)&lt;/L&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dek37 = CellStatistics(lastDekad, "MEAN", "NODATA")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output = 'E:/Test/Temp/tmax_dek_037.tif'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dek37.save(output)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope my query is clear.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-Leo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Sep 2014 05:36:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659964#M51278</guid>
      <dc:creator>Leo_KrisPalao</dc:creator>
      <dc:date>2014-09-15T05:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looping over the list of rasters</title>
      <link>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659965#M51279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;sorry...it is not clear.&amp;nbsp; This line lastdek = (last5, first1) should have started throwing error messages since last5 and first1 aren't defined.&amp;nbsp; Can your provide the full code or list the error messages&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Sep 2014 07:21:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659965#M51279</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-09-15T07:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Looping over the list of rasters</title>
      <link>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659966#M51280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan thanks for your reply. Sorry the line lastdek, it should be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;lastdek = (last3, first3).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the script that I am trying but with no success. I think the range that I specified below (line 14) still refers to my list of rasters data in my rasters variable (line 7).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&amp;gt;&amp;gt;&amp;gt; import arcpy


&amp;gt;&amp;gt;&amp;gt; from arcpy import env


&amp;gt;&amp;gt;&amp;gt; from arcpy.sa import *


&amp;gt;&amp;gt;&amp;gt; arcpy.CheckOutExtension("Spatial")


u'CheckedOut'


&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace = 'raster/path'


&amp;gt;&amp;gt;&amp;gt; rasters = arcpy.ListRasters("*", "tif")


&amp;gt;&amp;gt;&amp;gt; last4 = range(362,366)


&amp;gt;&amp;gt;&amp;gt; first3 = range(0,3)


&amp;gt;&amp;gt;&amp;gt; lastdek = (last4,first3)


&amp;gt;&amp;gt;&amp;gt; lastdek


([362, 363, 364, 365], [0, 1, 2])


&amp;gt;&amp;gt;&amp;gt; dek = []


&amp;gt;&amp;gt;&amp;gt; for l in range(0,7):


...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print l


...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dek.append(rasters&lt;L&gt;)&lt;/L&gt;


... 


0


1


2


3


4


5


6


&amp;gt;&amp;gt;&amp;gt; outCellStatistics = CellStatistics(dek, "MEAN", "NODATA")


&amp;gt;&amp;gt;&amp;gt; output = 'folder/path/dek_037.tif'


&amp;gt;&amp;gt;&amp;gt; outCellStatistics.save(output)

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a workaround to set the range starting from the last four rasters to the first three rasters in my list?&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

&lt;SPAN class="keyword"&gt;for l &lt;SPAN class="keyword"&gt;in&lt;/SPAN&gt; range(&lt;SPAN class="number"&gt;363&lt;/SPAN&gt;,&lt;SPAN class="number"&gt;3&lt;/SPAN&gt;):&amp;nbsp; &lt;/SPAN&gt;


&lt;SPAN class="keyword"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print l
&lt;/SPAN&gt;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Leo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:55:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659966#M51280</guid>
      <dc:creator>Leo_KrisPalao</dc:creator>
      <dc:date>2021-12-12T03:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Looping over the list of rasters</title>
      <link>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659967#M51281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;as a possible demo, examine this idea...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; aList = [i for i in range(366)]&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; aList&lt;/P&gt;&lt;P&gt;[0, 1, 2, 3,&amp;nbsp; .... 360, 361, 362, 363, 364, 365]&amp;nbsp;&amp;nbsp; #a big snip here&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; bList = [aList&lt;I&gt; for i in range(-3,3)]&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt; bList&lt;/P&gt;&lt;P&gt;[363, 364, 365, 0, 1, 2]&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;will at least give you some ideas on accessing the head and tail of a list&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 02:36:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659967#M51281</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-09-16T02:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Looping over the list of rasters</title>
      <link>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659968#M51282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan, thanks. It worked okay.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Leo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Sep 2014 07:49:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/looping-over-the-list-of-rasters/m-p/659968#M51282</guid>
      <dc:creator>Leo_KrisPalao</dc:creator>
      <dc:date>2014-09-16T07:49:15Z</dc:date>
    </item>
  </channel>
</rss>

