<?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 How to determine whether Raster statistics have been calculated in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75547#M6144</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a script which fails when I use the GetRasterProperties_management function on a dataset where statistics have not yet been calculated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I in a simple way check whether the statistics have been calculated ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is strangely enough not a Raster set attribute named "hasStatistics" or similar to get from Describe fuunction &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;neither does the GetRasterProperties simply rerturn a Null object &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;so I could use something like :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; if arcpy.GetRasterProperties_management (outRaster, "MINIMUM") == None:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CalculateStatistics_management (outRaster) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All help is most welcome&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Apr 2011 09:03:51 GMT</pubDate>
    <dc:creator>MichaelStjernholm</dc:creator>
    <dc:date>2011-04-15T09:03:51Z</dc:date>
    <item>
      <title>How to determine whether Raster statistics have been calculated</title>
      <link>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75547#M6144</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a script which fails when I use the GetRasterProperties_management function on a dataset where statistics have not yet been calculated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;How can I in a simple way check whether the statistics have been calculated ?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There is strangely enough not a Raster set attribute named "hasStatistics" or similar to get from Describe fuunction &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;neither does the GetRasterProperties simply rerturn a Null object &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;so I could use something like :&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; if arcpy.GetRasterProperties_management (outRaster, "MINIMUM") == None:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; CalculateStatistics_management (outRaster) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All help is most welcome&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Apr 2011 09:03:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75547#M6144</guid>
      <dc:creator>MichaelStjernholm</dc:creator>
      <dc:date>2011-04-15T09:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether Raster statistics have been calculated</title>
      <link>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75548#M6145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;After raster statistics are calculated, a file with aux.xml extension is created in the same directory as the raster resides. The auxiliary file saves information of statistics for future use. Therefore, if you can see an aux.xml file in the same location, that indicates Raster statistics have been calculated. Or you can simplly put a line after CalculateStatistics_management( ) to inform the calculation has been done successfully.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Print "Done successfully!"&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Apr 2011 14:44:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75548#M6145</guid>
      <dc:creator>HongmeiZhu</dc:creator>
      <dc:date>2011-04-15T14:44:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether Raster statistics have been calculated</title>
      <link>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75549#M6146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Hongmei for reminding me of using the test of whether the aux.xml file exists - I use similar approach in other calculations.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;regards michael&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Apr 2011 06:42:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75549#M6146</guid>
      <dc:creator>MichaelStjernholm</dc:creator>
      <dc:date>2011-04-18T06:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether Raster statistics have been calculated</title>
      <link>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75550#M6147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Another way to solve the problem is to just assume that statistics is there and deal with the problem when it isn't.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
# Pseudocode:
while True:
&amp;nbsp;&amp;nbsp;&amp;nbsp; try: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FunctionThatNeedsRasterStatistics(raster)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
&amp;nbsp;&amp;nbsp;&amp;nbsp; except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateStatistics(raster)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This pattern also has the advantage that it isn't subject to race conditions (not that those are likely for raster statistics, but in other contexts that can be a real issue.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:55:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75550#M6147</guid>
      <dc:creator>NiklasNorrthon</dc:creator>
      <dc:date>2021-12-10T22:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine whether Raster statistics have been calculated</title>
      <link>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75551#M6148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I just wanted to note that an aux.xml can exist when statistics do not.&amp;nbsp; For example, the aux.xml will also be used as a pointer to the pyramid file.&amp;nbsp; This is explained here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009t00000027000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009t00000027000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You may want to go along the lines Niklas mentioned.&amp;nbsp; Ex:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;try:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.GetRasterProperties_management(input, "STD")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Statistics exist"
except arcpy.ExecuteError:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateStatistics_management(input)
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Statistics were calculated"&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:55:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-determine-whether-raster-statistics-have/m-p/75551#M6148</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T22:55:38Z</dc:date>
    </item>
  </channel>
</rss>

