<?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: Excluding &amp;quot;NoData&amp;quot; in raster percentile calculation in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521941#M40912</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check your duplicate thread&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 16 Jul 2015 15:07:17 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2015-07-16T15:07:17Z</dc:date>
    <item>
      <title>Excluding "NoData" in raster percentile calculation</title>
      <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521938#M40909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to calculate percentiles out of a floating point raster.&lt;/P&gt;&lt;P&gt;It works BUT it includes the NoData in the calculation so I don't get what I need.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to exclude the NoData from this calculation?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;env.workspace = r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL\00_UPWELLING\OUTPUT_Test.gdb"
raster = env.workspace + "\\" + "percentile"
array = arcpy.RasterToNumPyArray(raster)
array = scipy.sort(array)
per = 10
a = scipy.percentile(array,per)
print a&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:45:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521938#M40909</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2021-12-11T22:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding "NoData" in raster percentile calculation</title>
      <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521939#M40910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Toni,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The arcpy.RasterToNumPyArray tool has a parameter called 'nodata_to_value'.&amp;nbsp; This parameter allows you to set a value to assign to your input raster's nodata.&amp;nbsp; The default value is "None," which is probably what's messing up your calculations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tool help - &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//03q300000029000000" title="http://resources.arcgis.com/en/help/main/10.2/index.html#//03q300000029000000"&gt;ArcGIS Help (10.2, 10.2.1, and 10.2.2)&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Todd&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 14:41:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521939#M40910</guid>
      <dc:creator>ToddBlanchette</dc:creator>
      <dc:date>2015-07-16T14:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding "NoData" in raster percentile calculation</title>
      <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521940#M40911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Todd,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for your reply.&lt;/P&gt;&lt;P&gt;I'm aware NoData can be assigned to a particular value. But, wouldn't that then "corrupt" the percentile calculation? as in this case there would be a lot of say value 1 (if for example I assign NoData to 1).&lt;/P&gt;&lt;P&gt;I'm working with global rasters with values present only 250km from the coast.&lt;/P&gt;&lt;P&gt;I think for the percentile calculation to be correct only the real list of values should be taken into account excluding the NoData values.&lt;/P&gt;&lt;P&gt;Or maybe I'm not quite right...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 14:52:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521940#M40911</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2015-07-16T14:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding "NoData" in raster percentile calculation</title>
      <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521941#M40912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check your duplicate thread&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 15:07:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521941#M40912</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2015-07-16T15:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding "NoData" in raster percentile calculation</title>
      <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521942#M40913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry Toni, you are correct in that you still have to deal with the noData in some way as to not taint your calculations - I thought you were just wondering if you could modify the noData.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could probably use an array mask on your numpy array to exclude the values you don't want to include.&lt;/P&gt;&lt;P&gt;More info on how to do this here &lt;A href="http://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html#what-is-a-masked-array" title="http://docs.scipy.org/doc/numpy/reference/maskedarray.generic.html#what-is-a-masked-array"&gt;The numpy.ma module — NumPy v1.9 Manual&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Todd &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 16 Jul 2015 15:15:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521942#M40913</guid>
      <dc:creator>ToddBlanchette</dc:creator>
      <dc:date>2015-07-16T15:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding "NoData" in raster percentile calculation</title>
      <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521943#M40914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Todd/Dan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm trying to use numpy mask module. Not sure I'm getting the right syntax when calling the "NoData" (Null, NoData...) values.&lt;/P&gt;&lt;P&gt;I don't quite see how to do so in the documentation. This is how my code looks at the moment.&lt;/P&gt;&lt;P&gt;Any further help would be greatly appreciate it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;env.workspace = r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL\00_UPWELLING\OUTPUT_Test.gdb"

raster = env.workspace + "\\" + "percentile"
array = arcpy.RasterToNumPyArray(raster)
marray = numpy.ma.masked_values(array,NULL)
sarray = scipy.sort(marray)
per = 20
a = scipy.percentile(sarray,per)
print a
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:46:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521943#M40914</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2021-12-11T22:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding "NoData" in raster percentile calculation</title>
      <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521944#M40915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi again,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've been trying also to set NoData to a value and then use "ma.masked_values" to exclude that value from the percentile calculation but it looks as if the value is not excluded.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Capture.JPG" class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/117788_Capture.JPG" style="width: 620px; height: 343px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Jul 2015 10:53:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521944#M40915</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2015-07-17T10:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: Excluding "NoData" in raster percentile calculation</title>
      <link>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521945#M40916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks as if I finally managed to get it running. Code looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;env.workspace = r"D:\PROGRAMMES\LFP_Source_Rocks\ArcGIS\00_LFP_GLOBAL\00_UPWELLING\OUTPUT_Test.gdb"
raster = env.workspace + "\\" + "percentile"
array = arcpy.RasterToNumPyArray(raster,nodata_to_value=10000000)
marray = numpy.ma.masked_values(array,10000000)
sarray = scipy.sort(marray)
per = 40
percen = numpy.percentile(sarray.compressed(),(per))
print percen&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your comments/help&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:46:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/excluding-quot-nodata-quot-in-raster-percentile/m-p/521945#M40916</guid>
      <dc:creator>anTonialcaraz</dc:creator>
      <dc:date>2021-12-11T22:46:04Z</dc:date>
    </item>
  </channel>
</rss>

