modis_quality.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/usr/bin/env python
  2. # script to extract specific information from MODIS Quality Masks
  3. #
  4. # (c) Copyright Ingmar Nitze 2013
  5. # Authors: Ingmar Nitze, Luca Delucchi
  6. # Email: initze at ucc dot ie
  7. # Email: luca dot delucchi at iasma dot it
  8. #
  9. ##################################################################
  10. #
  11. # This MODIS Python script is licensed under the terms of GNU GPL 2.
  12. # This program is free software; you can redistribute it and/or
  13. # modify it under the terms of the GNU General Public License as
  14. # published by the Free Software Foundation; either version 2 of
  15. # the License, or (at your option) any later version.
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. # See the GNU General Public License for more details.
  20. #
  21. ##################################################################
  22. import sys
  23. import os
  24. try:
  25. from pymodis import optparse_gui
  26. WXPYTHON = True
  27. except:
  28. WXPYTHON = False
  29. from pymodis import optparse_required
  30. from pymodis import qualitymodis
  31. def main():
  32. """Main function"""
  33. # usage
  34. usage = "usage: %prog [options] input_file"
  35. if 1 == len(sys.argv) and WXPYTHON:
  36. option_parser_class = optparse_gui.OptionParser
  37. else:
  38. option_parser_class = optparse_required.OptionParser
  39. parser = option_parser_class(usage=usage, description='modis_quality')
  40. parser.add_option("-o", "--output", dest="output", required=True,
  41. help="the prefix of output file", metavar="OUTPUT_FILE")
  42. # type
  43. parser.add_option("-t", "--type", dest="type", default="1",
  44. help="quality type either as number or name (e.g. 1 or "
  45. "VIQuality for MOD13 products) [default=%default]")
  46. # quality layer
  47. parser.add_option("-l", "--qualitylayer", dest="layer", default="1",
  48. help="quality layer of the dataset, dependent on the "
  49. "used MODIS product. (e.g. 1 or QC_Day for the "
  50. "Daytime QC Layer of MOD11) [default=%default]")
  51. # quality layer
  52. parser.add_option("-p", "--producttype", dest="product", default="MOD13Q1",
  53. help="quality layer of the dataset, dependent on the "
  54. "used MODIS product. (e.g. 1 or QC_Day for the "
  55. "Daytime QC Layer of MOD11) [default=%default]")
  56. # return options and argument
  57. (options, args) = parser.parse_args()
  58. if len(args) == 0 and not WXPYTHON:
  59. parser.print_help()
  60. sys.exit(1)
  61. if len(args) > 1:
  62. parser.error("You have to define the name of HDF file.")
  63. if not os.path.isfile(args[0]):
  64. parser.error("You have to define the name of HDF file.")
  65. # set modis object
  66. modisQuality = qualitymodis.QualityModis(args[0], options.output,
  67. qType=options.type,
  68. qLayer=options.layer,
  69. pType=options.product)
  70. # run
  71. modisQuality.run()
  72. if __name__ == "__main__":
  73. main()