<?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: loop for value and counts in raster attribute in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611822#M47769</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for your help! I really appreciate it. Have a good weekend!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Subhasis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 25 Jul 2014 12:36:15 GMT</pubDate>
    <dc:creator>InceptionWoznicki</dc:creator>
    <dc:date>2014-07-25T12:36:15Z</dc:date>
    <item>
      <title>loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611812#M47759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a beginner to python scripting in GIS. &lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif';"&gt;I ‘m trying to make a loop for field “value” and “count” of a raster data.&amp;nbsp; The logic behind the code is:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif';"&gt;-&lt;SPAN style="font-size: 11.0pt; font-family: 'Calibri','sans-serif';"&gt;1&lt;SUP&gt;st&lt;/SUP&gt; calculate the total number of counts in the original raster &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;- use the " 1st value" from value field of the raster attribute of original raster to extract a new raster using raster calculator&lt;/P&gt;&lt;P&gt;-calculate the total number of counts in the new raster&lt;/P&gt;&lt;P&gt;-If the total counts of new raster &amp;lt; 0.25*(total counts of original raster)&lt;/P&gt;&lt;P&gt;-Then got the threshold value(which was used to calculate new raster from the original raster)&lt;/P&gt;&lt;P&gt;-Else, use the next value from the old raster attribute to calculate new raster and the total “count” of new raster until the total counts of new raster is &amp;lt;&amp;nbsp; 0.25* (total counts of original raster).&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am providing the code below.However, I am getting "invalid syntax error" at the end of the for loop in the code below where it says "next row". I would appreciate any comment/suggestion.&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;from arcpy.sa import *&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#To overwrite output&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#Set environment settings&lt;/P&gt;&lt;P&gt;env.workspace = "C:/Subhasis/Test/Neshanic_Python"&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# set local variable&lt;/P&gt;&lt;P&gt;inraster ="01367620-r-r"&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# read attribute table of raster&lt;/P&gt;&lt;P&gt;rows = arcpy.SearchCursor(inraster,"","","Count","")&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# sum of counts in raster&lt;/P&gt;&lt;P&gt;s1=[]&lt;/P&gt;&lt;P&gt;for row in rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s1.append(row.getValue("Count"))&lt;/P&gt;&lt;P&gt;A= sum(s1)&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#checkout ArcGIS spatial analyst extension license&lt;/P&gt;&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# read attribute table of raster&lt;/P&gt;&lt;P&gt;rows = arcpy.SearchCursor(inraster,"","","value","")&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for row in rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inSQLClause = "VALUE = row&lt;I&gt;"&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; attExtract = ExtractByAttributes(inraster, inSQLClause)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; attExtract.save("C:/Subhasis/Test/Neshanic_Python/STI-TH")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; inraster="STI-TH"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; rows = arcpy.SearchCursor(inraster,"","","Count","")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s2=[]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; s2.append(row.getValue("Count"))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; B=sum(s2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if B&amp;lt;=.25*A:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'got the Threshold point for STI row&lt;I&gt;'&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print'need to use different STI'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; next row&lt;/P&gt;&lt;P style="min-height: 8pt; padding: 0px;"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;..........................................................................................................................&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 13:37:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611812#M47759</guid>
      <dc:creator>InceptionWoznicki</dc:creator>
      <dc:date>2014-07-18T13:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611813#M47760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;you shouldn't need the "next row" at all, you are in a for loop, so it will loop through all the rows regardless.&amp;nbsp; Also, if you are on ArcGIS 10.1 or higher, I would use the data access cursor(arcpy.da.SearchCursor), it works significantly faster the old arcpy.SearchCursor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 13:43:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611813#M47760</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-18T13:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611814#M47761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 13:51:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611814#M47761</guid>
      <dc:creator>InceptionWoznicki</dc:creator>
      <dc:date>2014-07-18T13:51:55Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611815#M47762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, there is a lot more going on in the script that wont work:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;the nested loop and reusing the same variable names (row, rows, inraster)&lt;/LI&gt;&lt;LI&gt;the where clause will not be filled with the value you're reading&lt;/LI&gt;&lt;LI&gt;the print statement at the end will never show a result since the "row&lt;I&gt;" is printed as text&lt;/I&gt;&lt;/LI&gt;&lt;LI&gt;you're mixing the "normal" SearchCursor and da.SearchCursor syntax&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Furthermore, there is actually no need to create rasters, and therefore you don't need a SA license.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at the code below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14057495445306471 jive_text_macro" jivemacro_uid="_14057495445306471"&gt;
&lt;P&gt;import arcpy&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;inraster ="C:/Subhasis/Test/Neshanic_Python/01367620-r-r"&lt;/P&gt;
&lt;P&gt;threshold = 0.25&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;flds = ("VALUE", "COUNT")&lt;/P&gt;
&lt;P&gt;dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(inraster, flds)}&lt;/P&gt;
&lt;P&gt;sumcnt = sum(dct.values())&lt;/P&gt;
&lt;P&gt;threscnt = sumcnt * threshold&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Number of pixels with a value = {0}".format(sumcnt)&lt;/P&gt;
&lt;P&gt;print "Maximum number of pixels within threshold = {0}".format(threscnt)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;cnt, result = 0, 0&lt;/P&gt;
&lt;P&gt;for k in sorted(dct):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt += dct&lt;K&gt;&lt;/K&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print " - Value = {0}, Sum = {1}".format(k, cnt)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cnt &amp;lt; threscnt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(k)&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; break&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;print "Threshold = {0}".format(result)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On line 7 a dictionary is created using the da.SeachCursor. A dictionary is an object that hold key (=VALUE), value (=COUNT) pairs. Insert a print statement in the code to print the "dct" object to see how it is filled.&lt;/P&gt;&lt;P&gt;The sum of all the counts is calculated on line 8&lt;/P&gt;&lt;P&gt;On line 9 a variable is introduced that holds the maximum number of pixels based on the specified threshold.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Line 14 till 21 loop through the sorted dictionary (it is sorted on the pixel values) and calculates the sum of the COUNT of all the pixel values less than or equal to the current pixel value. In case this count is less than the maximum number of pixels calculated on line 9, the result is overwritten with the new best result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have a look at the output generated with a test raster:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Number of pixels with a value = 219996&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Maximum number of pixels within threshold = 54999.0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; - Value = 0, Sum = 10649&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; - Value = 1, Sum = 10721&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; - Value = 2, Sum = 10807&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; - Value = 3, Sum = 10896&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier; color: #909090;"&gt;&amp;lt;&amp;lt; other values omitted&amp;gt;&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; - Value = 38, Sum = 53141&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; - Value = 39, Sum = 54281&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt; - Value = 40, Sum = 55675&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Threshold = &lt;STRONG&gt;39&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 19 Jul 2014 06:15:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611815#M47762</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-07-19T06:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611816#M47763</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;&lt;/P&gt;&lt;P&gt;Sorry for my late response. Thank you very much for your quick response and walk through the code step by step. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you have a chance could you please tell me the following:&lt;/P&gt;&lt;P&gt;-I want to automate this process for 70 rasters (finding the threshold value first for each raster)&lt;/P&gt;&lt;P&gt;-make a new raster using the individual threshold value&amp;nbsp; and store the new raster in individual raster&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Logic:-Assign a list and keep all the raster name inside the list&lt;/P&gt;&lt;P&gt;-Use a for loop to iterate the rasters in "inraster position in the code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Problem: each raster files have two folders: 1) raster name, 2)info. The second folder "info" is common for all raster. Therefore, I am not able to put all rasters directly in the working folder. Is there way I can solve this problem?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;import arcpy,os&lt;/P&gt;&lt;P&gt;from arcpy import env&lt;/P&gt;&lt;P&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#To overwrite output&lt;/P&gt;&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#Set environment settings&lt;/P&gt;&lt;P&gt;env.workspace = "C:/Subhasis/Test/Neshanic_Python"&lt;/P&gt;&lt;P&gt;outws="C:/Subhasis/Test/Neshanic_Python/extract"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;#checkout ArcGIS spatial analyst extension license&lt;/P&gt;&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# set local variable (only presented 3 out of 70 for testing)&lt;/P&gt;&lt;P&gt;inraster = ["01367620-r-r,01367700-r-r,01367770-r-r"]&lt;/P&gt;&lt;P&gt;threshold = 0.75&lt;/P&gt;&lt;P&gt;for i in inraster:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flds = ("VALUE", "COUNT")&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)}&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumcnt = sum(dct.values())&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; threscnt = sumcnt * threshold&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Total number of pixels with a value = {0}".format(sumcnt)&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Total number of pixels within threshold = {0}".format(threscnt)&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt, result = 0, 0&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for k in sorted(dct):&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt += dct&lt;K&gt;&amp;nbsp; &lt;/K&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print " - Value = {0}, Sum = {1}".format(k, cnt)&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cnt &amp;lt; threscnt:&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(k)&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Threshold = {0}".format(result)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; attExtract = ExtractByAttributes(str(i), "VALUE&amp;gt;=" + str("{0}".format(result)))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname=os.path.join(outws,str(i), str("{0}".format(result)))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; attExtract.save(outname&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot for your time and help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Subhasis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Jul 2014 17:13:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611816#M47763</guid>
      <dc:creator>InceptionWoznicki</dc:creator>
      <dc:date>2014-07-21T17:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611817#M47764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Subhasis,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suppose the code you posted did not work, right?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The list you created to test the code is actually a list with only one element. The list should have been created as (notice the missing quotes):&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;inraster = ["01367620-r-r&lt;STRONG&gt;","&lt;/STRONG&gt;01367700-r-r&lt;STRONG&gt;","&lt;/STRONG&gt;01367770-r-r"]&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Don't worry about the folders, each folder contains an Esri grid and the info folder is a common storage for those grids.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The other part that wasn’t optimal was this block:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_14061382764194232 jive_text_macro" jivemacro_uid="_14061382764194232"&gt;
&lt;P&gt;attExtract = ExtractByAttributes(str(i), "VALUE&amp;gt;=" + str("{0}".format(result)))&lt;/P&gt;
&lt;P&gt;outname=os.path.join(outws,str(i), str("{0}".format(result)))&lt;/P&gt;
&lt;P&gt;attExtract.save(outname&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apart from the missing bracket at the end, you don’t need to cast the name of the raster to string (it is already string). The strength of using “format” is that you can combine strings and values together in a much easier way. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I haven't tested the code below:&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_14061383147756737" jivemacro_uid="_14061383147756737"&gt;
&lt;P&gt;import arcpy,os&lt;/P&gt;
&lt;P&gt;from arcpy import env&lt;/P&gt;
&lt;P&gt;from arcpy.sa import *&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#To overwrite output&lt;/P&gt;
&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#Set environment settings&lt;/P&gt;
&lt;P&gt;env.workspace = "C:/Subhasis/Test/Neshanic_Python"&lt;/P&gt;
&lt;P&gt;outws="C:/Subhasis/Test/Neshanic_Python/extract"&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#checkout ArcGIS spatial analyst extension license&lt;/P&gt;
&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create a list of all rasters in current workspace&lt;/P&gt;
&lt;P&gt;lst_ras = arcpy.ListRasters()&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# set local variable (only presented 3 out of 70 for testing)&lt;/P&gt;
&lt;P&gt;# inraster = ["01367620-r-r,01367700-r-r,01367770-r-r"]&lt;/P&gt;
&lt;P&gt;threshold = 0.75&lt;/P&gt;
&lt;P&gt;for ras in lst_ras:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flds = ("VALUE", "COUNT")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumcnt = sum(dct.values())&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; threscnt = sumcnt * threshold&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # print "Total number of pixels with a value = {0}".format(sumcnt)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # print "Total number of pixels within threshold = {0}".format(threscnt)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt, result = 0, 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for k in sorted(dct):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt += dct&lt;K&gt;&lt;/K&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # print " - Value = {0}, Sum = {1}".format(k, cnt)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cnt &amp;lt; threscnt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(k)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # print "Threshold = {0}".format(result)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; attExtract = ExtractByAttributes(ras, "VALUE&amp;gt;={0}".format(result))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = os.path.join(outws,"{0}{1}".format(ras, result))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; attExtract.save(outname)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;arcpy.CheckInExtension("Spatial")&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards, Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Jul 2014 18:00:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611817#M47764</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-07-23T18:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611818#M47765</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;&lt;/P&gt;&lt;P&gt;Thank you very much! This code works only for one raster which has both " ESRI grid" and "info" folder inside the working directory. I was n't able to keep the "info" folder of other two raster inside the working directory as the "info" folder of 1st raster is already in the working directory.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know it is stupid question. But could you please let me know how can i keep the "info" folders of other two rasters inside the working directory?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your time and help!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Subhasis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 14:20:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611818#M47765</guid>
      <dc:creator>InceptionWoznicki</dc:creator>
      <dc:date>2014-07-24T14:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611819#M47766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again Subhasis,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Is there any particular reason why you are using ESRI grids, instead of another raster format, which wouldn't have multiple folders, such as a .tif?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to to iterate over multiple rasters that are in seperate folders than have a common parent folders, you could use arcpy.da.walk, to iterate over them all in seperate folders, that way you wouldn't have to put all your info folders into a single folder.&amp;nbsp; you can make a list of all the filepaths and names, then iterate over that list with your script(see example #2 in the link below)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/018w/018w00000023000000.htm" title="http://resources.arcgis.com/en/help/main/10.1/018w/018w00000023000000.htm"&gt;ArcGIS Help 10.1 - Walk (arcpy.da)&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 14:54:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611819#M47766</guid>
      <dc:creator>IanMurray</dc:creator>
      <dc:date>2014-07-24T14:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611820#M47767</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ian,&lt;/P&gt;&lt;P&gt;Thanks a lot! Yes, the output I have is in ESRI grid format for 70 rasters before. So, I 'm trying to automate this process. I would follow example 2 in the link.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Subhasis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 15:06:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611820#M47767</guid>
      <dc:creator>InceptionWoznicki</dc:creator>
      <dc:date>2014-07-24T15:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611821#M47768</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So, if I understand it correctly your folderstructure does not contain all raster in the same folder (workspace), but in subfolders of the workspace (so the right part if the image below):&lt;/P&gt;&lt;P&gt;&lt;IMG alt="RasterFolderStructure.png" class="jive-image image-1" src="https://community.esri.com/legacyfs/online/2523_RasterFolderStructure.png" style="height: auto;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In that case the &lt;STRONG&gt;arcpy.da.Walk&lt;/STRONG&gt; option (available from 10.1 SP 1) as suggested by &lt;A href="https://community.esri.com/migrated-users/42743"&gt;Ian Murray&lt;/A&gt;‌ is the right way to go. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code would look like this (once again, the code is not tested):&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_14062381946056189" jivemacro_uid="_14062381946056189"&gt;
&lt;P&gt;import arcpy,os&lt;/P&gt;
&lt;P&gt;from arcpy import env&lt;/P&gt;
&lt;P&gt;from arcpy.sa import *&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#To overwrite output&lt;/P&gt;
&lt;P&gt;arcpy.env.overwriteOutput = True&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#Set environment settings&lt;/P&gt;
&lt;P&gt;ws = "C:/Subhasis/Test/Neshanic_Python"&lt;/P&gt;
&lt;P&gt;env.workspace = ws&lt;/P&gt;
&lt;P&gt;outws="C:/Subhasis/Test/Neshanic_Python/extract"&lt;/P&gt;
&lt;P&gt;threshold = 0.75&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;#checkout ArcGIS spatial analyst extension license&lt;/P&gt;
&lt;P&gt;arcpy.CheckOutExtension("Spatial")&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# create a list of all rasters in current workspace&lt;/P&gt;
&lt;P&gt;dct_ras = {}&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# use arcpy.da.Walk (available from 10.1 SP1) to generate dictionary of rasters&lt;/P&gt;
&lt;P&gt;for dirpath, dirnames, filenames in arcpy.da.Walk(ws,&lt;/P&gt;
&lt;P&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; topdown=True,&lt;/P&gt;
&lt;P&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;&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datatype="Raster"):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for filename in filenames:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ras = os.path.join(dirpath, filename)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct_ras[ras] = filename&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# loop through dictionary and extract path to input ras and rasname&lt;/P&gt;
&lt;P&gt;for ras, rasname in dct_ras.items():&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; flds = ("VALUE", "COUNT")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(ras, flds)}&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sumcnt = sum(dct.values())&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; threscnt = sumcnt * threshold&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt, result = 0, 0&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; for k in sorted(dct):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cnt += dct&lt;K&gt;&lt;/K&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # print " - Value = {0}, Sum = {1}".format(k, cnt)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cnt &amp;lt; threscnt:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result = int(k)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; # print "Threshold = {0}".format(result)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; attExtract = ExtractByAttributes(ras, "VALUE&amp;gt;={0}".format(result))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; outname = os.path.join(outws,"{0}{1}".format(rasname, result))&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; attExtract.save(outname)&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;# return SA extension&lt;/P&gt;
&lt;P&gt;arcpy.CheckInExtension("Spatial")&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In this case I do not write the rasters to a list with simply the raster names, since they reside in different workspaces. The rasters path is used as dictionary key and the raster name is used as value. Do notice that in your structure the raster names can repeat and create output rasters with same name (in case the threshold value is equal too). Be ware of that.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xander&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 21:47:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611821#M47768</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2014-07-24T21:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: loop for value and counts in raster attribute</title>
      <link>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611822#M47769</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much for your help! I really appreciate it. Have a good weekend!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;BR /&gt;Subhasis&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jul 2014 12:36:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/loop-for-value-and-counts-in-raster-attribute/m-p/611822#M47769</guid>
      <dc:creator>InceptionWoznicki</dc:creator>
      <dc:date>2014-07-25T12:36:15Z</dc:date>
    </item>
  </channel>
</rss>

