detectBitInfo.R 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #' List MODIS Quality Information
  2. #'
  3. #' @description
  4. #' This function returns MODIS QA information for a specific product. It gets
  5. #' the information from an internal database and not all products are available.
  6. #'
  7. #' @param product \code{character}, see \code{\link{getProduct}}.
  8. #' @param what \code{character}. Parameter name, i.e.
  9. #' \url{https://lpdaac.usgs.gov/dataset_discovery/modis/modis_products_table/mod13q1},
  10. #' (TABLE 2: MOD13Q1 VI Quality; Long Name).
  11. #' @param warn \code{logical}, whether or not to throw warning messages.
  12. #'
  13. #' @return
  14. #' If \code{what = "all"} a \code{data.frame}, else a \code{list}.
  15. #'
  16. #' @author
  17. #' Matteo Mattiuzzi
  18. #'
  19. #' @examples
  20. #' detectBitInfo("MOD13Q1")
  21. #' detectBitInfo("MOD13Q1", "VI usefulness")
  22. #'
  23. #' detectBitInfo("MYD17A2")
  24. #'
  25. #' @export detectBitInfo
  26. #' @name detectBitInfo
  27. detectBitInfo <- function(product, what='all',warn=TRUE)
  28. {
  29. if(inherits(product,"Raster"))
  30. {
  31. product <- basename(names(product)[1])
  32. } else if(inherits(product,"character"))
  33. {
  34. product <- basename(product)
  35. } else
  36. {
  37. stop("Unknown input in detectBitInfo!")
  38. }
  39. product <- strsplit(product,"\\.")[[1]][1]
  40. prodinfo <- getProduct(product,quiet=TRUE)$PRODUCT[1]
  41. if(is.null(prodinfo))
  42. {
  43. stop()
  44. }
  45. try(info <- eval(parse(text=paste("",prodinfo,"_QC",sep=""))),silent=TRUE)
  46. if(exists("info"))
  47. {
  48. if(what!='all')
  49. {
  50. index <- grep(info$LongName,pattern=what, ignore.case = TRUE)
  51. res <- list(bitShift=info[index,"bitShift"],bitMask=info[index,"bitMask"])
  52. } else
  53. {
  54. res <- info
  55. }
  56. } else
  57. {
  58. if(warn)
  59. {
  60. warning("Could not detect 'bit' information, please provide me ([email protected]) the product name you have used so I can enable it, or add it manually see '?extractBits'!")
  61. }
  62. res <- NULL
  63. }
  64. return(res)
  65. }