t.rast.mapcalc.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.rast.mapcalc
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: Perform spatio-temporal mapcalc expressions on temporal sampled maps of space time raster datasets
  9. # COPYRIGHT: (C) 2012 by the GRASS Development Team
  10. #
  11. # This program is free software under the GNU General Public
  12. # License (version 2). Read the file COPYING that comes with GRASS
  13. # for details.
  14. #
  15. #############################################################################
  16. #%module
  17. #% description: Perform spatio-temporal mapcalc expressions on temporal sampled maps of space time raster datasets.
  18. #% keywords: temporal
  19. #% keywords: algebra
  20. #%end
  21. #%option G_OPT_STRDS_INPUTS
  22. #%end
  23. #%option
  24. #% key: expression
  25. #% type: string
  26. #% description: Spatio-temporal mapcalc expression
  27. #% required: yes
  28. #% multiple: no
  29. #%end
  30. #%option G_OPT_T_SAMPLE
  31. #% key: method
  32. #% answer: equal
  33. #%end
  34. #%option G_OPT_STRDS_OUTPUT
  35. #%end
  36. #%option
  37. #% key: base
  38. #% type: string
  39. #% description: Base name of the new created raster maps. This name will be extended with a numerical prefix
  40. #% gisprompt: NULL
  41. #% required: yes
  42. #% multiple: no
  43. #%end
  44. #%option
  45. #% key: nprocs
  46. #% type: integer
  47. #% description: Number of r.mapcalc processes to run in parallel
  48. #% required: no
  49. #% multiple: no
  50. #% answer: 1
  51. #%end
  52. #%flag
  53. #% key: n
  54. #% description: Register Null maps
  55. #%end
  56. #%flag
  57. #% key: s
  58. #% description: Check spatial overlap
  59. #%end
  60. from multiprocessing import Process
  61. import copy
  62. import grass.script as grass
  63. import grass.temporal as tgis
  64. ############################################################################
  65. def main():
  66. # Get the options
  67. inputs = options["inputs"]
  68. output = options["output"]
  69. expression = options["expression"]
  70. base = options["base"]
  71. method = options["method"]
  72. nprocs = int(options["nprocs"])
  73. register_null = flags["n"]
  74. spatial = flags["s"]
  75. # Create the method list
  76. method = method.split(",")
  77. # Make sure the temporal database exists
  78. tgis.init()
  79. tgis.dataset_mapcalculator(inputs, output, "raster", expression,
  80. base, method, nprocs, register_null, spatial)
  81. ###############################################################################
  82. if __name__ == "__main__":
  83. options, flags = grass.parser()
  84. main()