0

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)

1

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)
}

For more information you can refer to this link. https://github.com/jianzhaobi/bjzresc/tree/master/R

1
  • You can use the readMCD19A2 function in that link (after loading the QA2Char function). In the end, you will have a .csv file with all the QA information you need.
    – ay__ya
    Nov 12 '21 at 20:28

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.