t.rast3d.mapcalc.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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: mapcalc
  20. #%end
  21. #%option G_OPT_STR3DS_INPUTS
  22. #%end
  23. #%option
  24. #% key: expression
  25. #% type: string
  26. #% description: The 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 G_OPT_R_BASE
  37. #% required: yes
  38. #% description: Name of the base raster3d map
  39. #% gisprompt: old,grid3,3d-raster
  40. #%end
  41. #%option
  42. #% key: nprocs
  43. #% type: integer
  44. #% description: The number of r3.mapcalc processes to run in parallel
  45. #% required: no
  46. #% multiple: no
  47. #% answer: 1
  48. #%end
  49. #%flag
  50. #% key: n
  51. #% description: Register Null maps
  52. #%end
  53. #%flag
  54. #% key: s
  55. #% description: Check spatial overlap
  56. #%end
  57. from multiprocessing import Process
  58. import copy
  59. import grass.script as grass
  60. import grass.temporal as tgis
  61. ############################################################################
  62. def main():
  63. # Get the options
  64. inputs = options["inputs"]
  65. output = options["output"]
  66. expression = options["expression"]
  67. base = options["base"]
  68. method = options["method"]
  69. nprocs = int(options["nprocs"])
  70. register_null = flags["n"]
  71. spatial = flags["s"]
  72. # Create the method list
  73. method = method.split(",")
  74. # Make sure the temporal database exists
  75. tgis.create_temporal_database()
  76. tgis.dataset_mapcalculator(inputs, output, "raster3d", expression, base, method, nprocs, register_null, spatial)
  77. ###############################################################################
  78. if __name__ == "__main__":
  79. options, flags = grass.parser()
  80. main()