g.bands.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env python3
  2. ############################################################################
  3. #
  4. # MODULE: g.bands
  5. # AUTHOR(S): Martin Landa <landa.martin gmail com>
  6. #
  7. # PURPOSE: Prints available band reference information used for multispectral data.
  8. #
  9. # COPYRIGHT: (C) 2019 by mundialis GmbH & Co.KG, and the GRASS Development Team
  10. #
  11. # This program is free software under the GNU General
  12. # Public License (>=v2). Read the file COPYING that
  13. # comes with GRASS for details.
  14. #
  15. #############################################################################
  16. # %module
  17. # % description: Prints available band reference information used for multispectral data.
  18. # % keyword: general
  19. # % keyword: imagery
  20. # % keyword: band reference
  21. # % keyword: image collections
  22. # %end
  23. # %option
  24. # % key: pattern
  25. # % type: string
  26. # % description: Band reference search pattern (examples: L, S2, .*_2, S2_1)
  27. # % required: no
  28. # % multiple: no
  29. # %end
  30. # %option
  31. # % key: operation
  32. # % type: string
  33. # % required: no
  34. # % multiple: no
  35. # % options: print
  36. # % description: Operation to be performed
  37. # % answer: print
  38. # %end
  39. # %flag
  40. # % key: e
  41. # % description: Print extended metadata information
  42. # %end
  43. import sys
  44. import grass.script as gs
  45. def main():
  46. from grass.bandref import BandReferenceReader, BandReferenceReaderError
  47. kwargs = {}
  48. if "," in options["pattern"]:
  49. gs.fatal("Multiple values not supported")
  50. if "_" in options["pattern"]:
  51. # full band identifier specified
  52. kwargs["shortcut"], kwargs["band"] = options["pattern"].split("_")
  53. else:
  54. # pattern
  55. kwargs["shortcut"] = options["pattern"]
  56. kwargs["extended"] = flags["e"]
  57. if options["operation"] == "print":
  58. try:
  59. reader = BandReferenceReader()
  60. reader.print_info(**kwargs)
  61. except BandReferenceReaderError as e:
  62. gs.fatal(e)
  63. return 0
  64. if __name__ == "__main__":
  65. options, flags = gs.parser()
  66. sys.exit(main())