t.rast3d.mapcalc.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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-2017 by the GRASS Development Team
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. #############################################################################
  22. #%module
  23. #% description: Performs r3.mapcalc expressions on maps of sampled space time 3D raster datasets.
  24. #% keyword: temporal
  25. #% keyword: algebra
  26. #% keyword: raster3d
  27. #% keyword: voxel
  28. #% keyword: time
  29. #%end
  30. #%option G_OPT_STR3DS_INPUTS
  31. #%end
  32. #%option
  33. #% key: expression
  34. #% type: string
  35. #% description: r3.mapcalc expression applied to each time step of the sampled data
  36. #% required: yes
  37. #% multiple: no
  38. #%end
  39. #%option G_OPT_T_SAMPLE
  40. #% key: method
  41. #% answer: during,overlap,contain,equal
  42. #%end
  43. #%option G_OPT_STR3DS_OUTPUT
  44. #%end
  45. #%option
  46. #% key: basename
  47. #% type: string
  48. #% label: Basename of the new generated output maps
  49. #% description: A numerical suffix separated by an underscore will be attached to create a unique identifier
  50. #% required: yes
  51. #% multiple: no
  52. #% gisprompt:
  53. #%end
  54. #%option
  55. #% key: nprocs
  56. #% type: integer
  57. #% description: Number of r3.mapcalc processes to run in parallel
  58. #% required: no
  59. #% multiple: no
  60. #% answer: 1
  61. #%end
  62. #%flag
  63. #% key: n
  64. #% description: Register Null maps
  65. #%end
  66. #%flag
  67. #% key: s
  68. #% description: Check the spatial topology of temporally related maps and process only spatially related maps
  69. #%end
  70. from multiprocessing import Process
  71. import copy
  72. import grass.script as grass
  73. ############################################################################
  74. def main():
  75. # lazy imports
  76. import grass.temporal as tgis
  77. # Get the options
  78. inputs = options["inputs"]
  79. output = options["output"]
  80. expression = options["expression"]
  81. base = options["basename"]
  82. method = options["method"]
  83. nprocs = int(options["nprocs"])
  84. register_null = flags["n"]
  85. spatial = flags["s"]
  86. # Create the method list
  87. method = method.split(",")
  88. # Make sure the temporal database exists
  89. tgis.init()
  90. tgis.dataset_mapcalculator(inputs, output, "raster3d", expression,
  91. base, method, nprocs, register_null, spatial)
  92. ###############################################################################
  93. if __name__ == "__main__":
  94. options, flags = grass.parser()
  95. main()