5

I have 15 annual MOD44B (vegetation continuous field) HDFs for 2000-2014, working in Arcmap 10.2. Each contains several bands. The two I'm concerned with are "percent tree cover" and "quality." The quality layer is an 8-bit integer product, where each bit in a pixel represents one of 8 inputs to the corresponding tree cover pixel. Each bit is '0' is good data and '1' if bad data. How can I determine whether the digital numbers are due to a single 2^x from one 'bad' bit or from multiple ones? For example, a pixel with value 32 could be a single bad data input from the 5th input (2^5 = 32) or could be 4 bad inputs (2^1 + 2^2 + 2^3 + 2^4 = 32).

5

I think you're misunderstanding the bit packing in the QA flags as your example with 32 is incorrect. 32 is 00100000 in binary so can only mean bad data in the 6th input (bits are numbered from right to left). As another example, 11 is 0001011 in binary, so means there was bad data in the 1st, 2nd and 4th inputs.

The quality flags for MOD44B are:

Bit Input Layers    State
0   DOY 065 – 097   0 Clear; 1 Cloudy
1   DOY 113 – 145   0 Clear; 1 Cloudy
2   DOY 161 – 193   0 Clear; 1 Cloudy
3   DOY 209 – 241   0 Clear; 1 Cloudy
4   DOY 257 – 289   0 Clear; 1 Cloudy
5   DOY 305 – 337   0 Clear; 1 Cloudy
6   DOY 353 – 017   0 Clear; 1 Cloudy
7   DOY 033 – 045   0 Clear; 1 Cloudy

To unpack the bits, shift values right by the number of the bit you want to extract then extract it with the & operator, ie (quality >> bitN) & 1 (bits numbered 0-7)

To do this, you can use the Bitwise Right Shift and And tools or the arcpy.sa >> and & operators.

Here is an example using arcpy:

from arcpy.sa import *

qa = Raster('/path/to/file')

doy065097 = qa & 1 # bit 0, same as (qa >> 0) & 1
doy113145 = (qa >> 1) & 1
doy161193 = (qa >> 2) & 1
doy209241 = (qa >> 3) & 1
etc...
doy033045 = (qa >> 7) & 1

To calculate the number of bad inputs, just sum the outputs of the bitwise operations:

inputs=[qa & 1]
for i in range(1,8):
    inputs.append((qa>>i)&1)
nbadinputs = CellStatistics(inputs, "SUM")
  • Thanks. I did not know about the bitwise math tools. I'll have a read, and see if it get me where I need to be. – ecologist1234 Sep 15 '15 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.