<?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: Tool for a moving average over a time series in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198763#M6809</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;I am not sure if what you edited meets what I thought as I am really not familiar with Python programming and can't read the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Concerning the other two options - I am not looking for the averages over all time steps, nor for a moving window filter for one. What I am seeking is something that can easily calculate the mean for each cell for layer 1, 2 and 3, then one for 2, 3 and 4, the next one for 3, 4, and 5 etc. I know I could simply do it with the raster calculator, but since I have a large number of rasters, this will take ages to do manually.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 07 Sep 2015 17:26:01 GMT</pubDate>
    <dc:creator>StefanieSteinbach</dc:creator>
    <dc:date>2015-09-07T17:26:01Z</dc:date>
    <item>
      <title>Tool for a moving average over a time series</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198761#M6807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am looking for a tool to create a &lt;STRONG&gt;pixel-based moving average&lt;/STRONG&gt; from a range of MODIS EVI tiles (from 2001 to 2013).&lt;/P&gt;&lt;P&gt;Is there a tool in ArcGIS to create the respective raster data sets by aggregating for example 3 time steps?&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;Stefanie&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Sep 2015 12:50:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198761#M6807</guid>
      <dc:creator>StefanieSteinbach</dc:creator>
      <dc:date>2015-09-07T12:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: Tool for a moving average over a time series</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198762#M6808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you are talking moving average as being the time step for each spatial location, then have you seen&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fdesktop.arcgis.com%2Fen%2Fdesktop%2Flatest%2Ftools%2Fspatial-analyst-toolbox%2Fhow-cell-statistics-works.htm" target="_blank"&gt;http://desktop.arcgis.com/en/desktop/latest/tools/spatial-analyst-toolbox/how-cell-statistics-works.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and the mean example.&amp;nbsp; It will give you the average at each location given rasters of the same extent, cell size just representing different times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want a 'moving' average at one time step, then you want to look at&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fdesktop.arcgis.com%2Fen%2Fdesktop%2Flatest%2Ftools%2Fspatial-analyst-toolbox%2Ffocal-statistics.htm" target="_blank"&gt;http://desktop.arcgis.com/en/desktop/latest/tools/spatial-analyst-toolbox/focal-statistics.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;you could use a 3x3 window and calculate the average within the 9 cells.&amp;nbsp; Depending how the average is calculated for a window, this may yield the same results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;An example using simple mean calculations (and I had Python open...sorry)&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 numpy as np
&amp;gt;&amp;gt;&amp;gt; a = np.arange(9.).reshape((3,3))
&amp;gt;&amp;gt;&amp;gt; b = np.arange(5.,14.).reshape((3,3))
&amp;gt;&amp;gt;&amp;gt; c = np.arange(10.,19.).reshape((3,3))
&amp;gt;&amp;gt;&amp;gt; a_m = np.mean(a)
&amp;gt;&amp;gt;&amp;gt; b_m = np.mean(b)
&amp;gt;&amp;gt;&amp;gt; c_m = np.mean(c)
&amp;gt;&amp;gt;&amp;gt; cent_m = np.mean([a_m,b_m,c_m])
&amp;gt;&amp;gt;&amp;gt; cent_m
9.0
&amp;gt;&amp;gt;&amp;gt; all_data = np.array([a,b,c])
&amp;gt;&amp;gt;&amp;gt; all_data = all_data.flatten()
&amp;gt;&amp;gt;&amp;gt; all_data_mean = np.mean(all_data)
&amp;gt;&amp;gt;&amp;gt; all_data_mean
9.0
&amp;gt;&amp;gt;&amp;gt; a&amp;nbsp; # time step 1
array([[ 0.,&amp;nbsp; 1.,&amp;nbsp; 2.],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 3.,&amp;nbsp; 4.,&amp;nbsp; 5.],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 6.,&amp;nbsp; 7.,&amp;nbsp; 8.]])
&amp;gt;&amp;gt;&amp;gt; b&amp;nbsp; # time step 2
array([[&amp;nbsp; 5.,&amp;nbsp; 6.,&amp;nbsp; 7.],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [&amp;nbsp; 8.,&amp;nbsp; 9.,&amp;nbsp; 10.],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 11.,&amp;nbsp; 12.,&amp;nbsp; 13.]])
&amp;gt;&amp;gt;&amp;gt; c&amp;nbsp; # time step 3
array([[ 10.,&amp;nbsp; 11.,&amp;nbsp; 12.],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 13.,&amp;nbsp; 14.,&amp;nbsp; 15.],
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; [ 16.,&amp;nbsp; 17.,&amp;nbsp; 18.]])
&amp;gt;&amp;gt;&amp;gt; a_m, b_m, c_m&amp;nbsp; # means for arrays a, b, c
(4.0, 9.0, 14.0)
&amp;gt;&amp;gt;&amp;gt; all_data_mean&amp;nbsp; # mean of flattened array of all data,
9.0
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just some food for thought&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;EDIT&lt;/P&gt;&lt;P&gt;Oh yeah... of course you can do this within python.&amp;nbsp; You can get your ArcMap data layers into numpy array format using&lt;/P&gt;&lt;P&gt;&lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fdesktop.arcgis.com%2Fen%2Fdesktop%2Flatest%2Fanalyze%2Farcpy-functions%2Frastertonumpyarray-function.htm" target="_blank"&gt;http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-functions/rastertonumpyarray-function.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;and you could simply create a multi-dimensional array from the inputs, or work with each layer one at a time.&amp;nbsp; It is trivial to setup and there are workarounds for humungous data files etc (ie netCDF support)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:54:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198762#M6808</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T09:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Tool for a moving average over a time series</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198763#M6809</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;I am not sure if what you edited meets what I thought as I am really not familiar with Python programming and can't read the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Concerning the other two options - I am not looking for the averages over all time steps, nor for a moving window filter for one. What I am seeking is something that can easily calculate the mean for each cell for layer 1, 2 and 3, then one for 2, 3 and 4, the next one for 3, 4, and 5 etc. I know I could simply do it with the raster calculator, but since I have a large number of rasters, this will take ages to do manually.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Sep 2015 17:26:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198763#M6809</guid>
      <dc:creator>StefanieSteinbach</dc:creator>
      <dc:date>2015-09-07T17:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Tool for a moving average over a time series</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198764#M6810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What you want is to do is code the local statistics in a moving loop... sorry to stick to code but ultimately you want something like this&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 numpy as np
&amp;gt;&amp;gt;&amp;gt;
&amp;gt;&amp;gt;&amp;gt; rasters = np.array([1,2,3,4,5,6,7,8,9])
&amp;gt;&amp;gt;&amp;gt; moving_mean = [np.mean(rasters[i-3:i]) for i in range(3,len(rasters)+1)]
&amp;gt;&amp;gt;&amp;gt; moving_mean
[2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
&amp;gt;&amp;gt;&amp;gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but using something like this &lt;STRONG&gt;totally unchecked code &lt;/STRONG&gt;(money refunded if it doesn't work)&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;CheckOutExtension&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"Spatial"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="p"&gt;&lt;SPAN class="n"&gt;env&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;workspace&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"C:/somepath/to_your/data"&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN class="p"&gt;&lt;SPAN class="s"&gt;&lt;SPAN class="n"&gt;rasters&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;ListRasters&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"*"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"GRID"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;SPAN class="p"&gt;&lt;/SPAN&gt;&lt;SPAN class="p"&gt;ras_name = "amazing"&lt;/SPAN&gt;
for i in range(3,len(rasters)+1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; outras = CellStatistics([rasters[i-3],rasters[i-2],rasters[i-1]], "Mean", "NODATA")
&amp;nbsp;&amp;nbsp;&amp;nbsp; ras_name = env.workspace + "/" +ras_name + str(I)
&amp;nbsp;&amp;nbsp;&amp;nbsp; ras_name.save(ras_name)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now maybe someone with some data, or is so inclined could check this out.&lt;/P&gt;&lt;P&gt;Other info &lt;A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fdesktop.arcgis.com%2Fen%2Fdesktop%2Flatest%2Fanalyze%2Farcpy-functions%2Flistrasters.htm" target="_blank"&gt;http://desktop.arcgis.com/en/desktop/latest/analyze/arcpy-functions/listrasters.htm&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 09:54:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198764#M6810</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T09:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Tool for a moving average over a time series</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198765#M6811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the code, I'll try it on my data and will give you feedback!&lt;/P&gt;&lt;P&gt;I guess there's no way around Python when seriously working with ArcGIS..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Sep 2015 18:51:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198765#M6811</guid>
      <dc:creator>StefanieSteinbach</dc:creator>
      <dc:date>2015-09-07T18:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: Tool for a moving average over a time series</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198766#M6812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No...It is important to learn as many languages as possible...there isn't a code Bablefish however.&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="125861" alt="LanguagesBablefish.jpg" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/125861_LanguagesBablefish.jpg" style="height: auto;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 07 Sep 2015 19:00:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/tool-for-a-moving-average-over-a-time-series/m-p/198766#M6812</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-09-07T19:00:36Z</dc:date>
    </item>
  </channel>
</rss>

