# How to interpret "AOD_QA" layer of MCD19A2?

I read hdf data using MATLAB, `qa = hdfread("MCD19A2.A2003060.h28v04.006.2018018233855.hdf","AOD_QA");`

According to page 13 of the user guide (MODIS Multi-Angle Implementation of Atmospheric Correction (MAIAC) Data User’s Guide https://modis-land.gsfc.nasa.gov/pdf/MCD19_UserGuide_final_Feb-6-2018.pdf), I was expecting 16 bit unsigned integer data.

My confusion is, when I convert the unsigned integers to binary (using `dec2bin`), I get a maximum of 12 bits, instead of 16 (all the decimals are small enough to fit into 12 bits). But according to documentation, I believe most of them would need more.

In summary, how do I extract AOD_QA (AOD quality assurance) data from a hdf file in Matlab?

Edit: I shifted those 12 bits in both directions, but in any case they do not fit into the documentation. (Not all bit combinations are used in the documentation. For instance bits from 5 to 7 cannot be 111)

• Were you able to find a way to translate the QA layer?
– M.O.
Commented Jun 22, 2022 at 19:10
• @M.O. hi, sorry for the late reply, yes. Do you still need it? I should write it as an answer here, I'll be able to do it in a week. Commented Sep 28, 2022 at 22:39

There is an R function available specifically for the MCD19A2 product.

``````QA2Char <- function(num) {

if (!is.na(num)) {
# Decimal to binary
char <- paste(sapply(strsplit(paste(rev(intToBits(num))),""),`[[`,2),collapse="")
# Extract the last 16 digits
char <- substr(char, 17, 32)

# QA array
qa.arr <- c(substr(char, 1, 1), # 15 Reserved
substr(char, 2, 3), # 13-14 Aerosol Model
substr(char, 4, 4), # 12 Glint Mask
substr(char, 5, 8), # 8-11 QA AOD
substr(char, 9, 11), # 5-7 Ajacency Mask
substr(char, 12, 13), # 3-4 Land Water Snow/Ice Mask
substr(char, 14, 16)) # 0-2 Cloud Mask
} else {
qa.arr <- rep(NA, 7)
}

return(qa.arr)
}
``````