Calculate percentage of NODATA pixels in a scene

3814
10
Jump to solution
11-27-2013 05:15 AM
ChenaySimms
New Contributor
Hi guys

Does anyone have an idea of how to go about calculating the percentage of NODATA pixels within a image? I need to be able to add the method to a model.

Thanks 🙂
0 Kudos
1 Solution

Accepted Solutions
SteveLynch
Esri Regular Contributor
use the IsNull tool, the output raster is integer with 1=where there are NoData pixels and 0 elsewhere. Open the table and look at the counts

View solution in original post

10 Replies
DuncanHornby
MVP Notable Contributor
If you are going to count the number of pixels in your raster then you need your raster to be an INTEGER grid so you can build its attribute table. Is your raster an INTEGER grid? If so you could do this several ways but probably the conceptually easiest way of doing it is to run your grid through a reclassify tool reclassifying NODATA into some integer value that is not being used by the rest of the pixels, then just look at the resulting attribute table and multiply the count by the cell size.
0 Kudos
SteveLynch
Esri Regular Contributor
use the IsNull tool, the output raster is integer with 1=where there are NoData pixels and 0 elsewhere. Open the table and look at the counts
DuncanHornby
MVP Notable Contributor
Ah yes the IsNull tool, I keep forgetting that exists, that's a much better tool to use!
0 Kudos
ChenaySimms
New Contributor
Hi guys

Thanks, this will do the trick as my raster was not an integer.

However, as I have a few hundred rasters that I need to analyse is there a way to automatically do the % calculations out of the attribute tables?

Thanks again

Chenay
0 Kudos
DuncanHornby
MVP Notable Contributor
To automate the processing of hundreds of rasters you are talking about using python or model builder.

In model builder you would use a raster iterator to step through a folder of rasters feeding them into the IsNull tool that feeds into a summary statistics tool to create a table on count. I would then add a field to indicate which raster it is and append to an existing table. You could probably do it slicker in python.
0 Kudos
NeilAyres
MVP Alum
Chenay,
wanted to reply earlier but the connection went down with the storms.

Try this bit of python :
import sys, os, arcpy
from arcpy import env
from arcpy.sa import *

if arcpy.CheckExtension("Spatial"):
    arcpy.CheckOutExtension("Spatial")
else:
    print "No SA licence"
    exit

HomeDir = "c:/Path to directory here/"
fgdb = "Name of your fgdb.gdb"
InData = os.path.join(HomeDir, fgdb)

env.workspace = InData
env.overwriteOutput = True

ListRast = arcpy.ListRasters()

for r in ListRast:
    print "Processing", r
    Ras = arcpy.Raster(r)
    NullRas = IsNull(Ras)
    NCol = NullRas.width
    NRow = NullRas.height
    NCell = NCol * NRow
    Mean = NullRas.mean
    NNull = Mean * NCell
    print "{} % Null {}".format(r, NNull / NCell * 100)
    


Works for me...
As a matter of interest, I tried to find out how to access a raster attribute table in python, but didn't come up with anything.
Could Steve Lynch or Xander or some other genius enlighten us.

Cheers,
Neil
SteveLynch
Esri Regular Contributor

Neil

To loop through a raster table you can use.

input = "myIntRaster"

cursor = arcpy.da.SearchCursor(input, ['value', 'count'])

for row in cursor:

     print (row)

-Steve

0 Kudos
ChenaySimms
New Contributor
Hi Neil

Thanks, this worked like a charm.

Maybe you can also help me with my next step. I now need to take my clean datasets and find the average pixel value for each pixel across the set of rasters. My final output is a raster that show the average EVI value for each pixel for the year.

I have previously done this as an Excel exersise but I am sure there are better ways of doing this. As far as I can tell there is no tool for such an anlysis and would need to be a python script.....

Any help would be appreciated.

regards

Chenay
0 Kudos
NeilAyres
MVP Alum
Wouldn't SA tools, Local, Cell Statistics do what you want to do.
Cheers,
N