t.rast.mapcalc.py 2.2 KB

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