t.rast3d.mapcalc.py 2.9 KB

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