t.rast3d.mapcalc.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.rast3d.mapcalc
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: Perform r3.mapcalc expressions on maps of sampled space time raster3d 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: Performs r3.mapcalc expressions on maps of sampled space time raster3d datasets.
  18. #% keywords: temporal
  19. #% keywords: algebra
  20. #%end
  21. #%option G_OPT_STR3DS_INPUTS
  22. #%end
  23. #%option
  24. #% key: expression
  25. #% type: string
  26. #% description: r3.mapcalc expression applied to each time step of the sampled data
  27. #% required: yes
  28. #% multiple: no
  29. #%end
  30. #%option G_OPT_T_SAMPLE
  31. #% key: method
  32. #% answer: during,overlap,contain,equal
  33. #%end
  34. #%option G_OPT_STR3DS_OUTPUT
  35. #%end
  36. #%option
  37. #% key: base
  38. #% type: string
  39. #% description: Base name of the new created 3d raster maps. This name will be extended with a numerical prefix
  40. #% required: yes
  41. #% multiple: no
  42. #%end
  43. #%option
  44. #% key: nprocs
  45. #% type: integer
  46. #% description: Number of r3.mapcalc processes to run in parallel
  47. #% required: no
  48. #% multiple: no
  49. #% answer: 1
  50. #%end
  51. #%flag
  52. #% key: n
  53. #% description: Register Null maps
  54. #%end
  55. #%flag
  56. #% key: s
  57. #% description: Check spatial overlap
  58. #%end
  59. from multiprocessing import Process
  60. import copy
  61. import grass.script as grass
  62. import grass.temporal as tgis
  63. ############################################################################
  64. def main():
  65. # Get the options
  66. inputs = options["inputs"]
  67. output = options["output"]
  68. expression = options["expression"]
  69. base = options["base"]
  70. method = options["method"]
  71. nprocs = int(options["nprocs"])
  72. register_null = flags["n"]
  73. spatial = flags["s"]
  74. # Create the method list
  75. method = method.split(",")
  76. # Make sure the temporal database exists
  77. tgis.init()
  78. tgis.dataset_mapcalculator(inputs, output, "raster3d", expression,
  79. base, method, nprocs, register_null, spatial)
  80. ###############################################################################
  81. if __name__ == "__main__":
  82. options, flags = grass.parser()
  83. main()