t.topology.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. ############################################################################
  4. #
  5. # MODULE: t.topology
  6. # AUTHOR(S): Soeren Gebbert
  7. #
  8. # PURPOSE: List temporal topology of a space time dataset
  9. # COPYRIGHT: (C) 2011 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: Lists temporal topology of a space time dataset.
  18. #% keywords: temporal
  19. #% keywords: topology
  20. #%end
  21. #%option G_OPT_STDS_INPUT
  22. #%end
  23. #%option G_OPT_STDS_TYPE
  24. #% guidependency: input
  25. #% guisection: Required
  26. #%end
  27. #%option G_OPT_T_WHERE
  28. #%end
  29. #%flag
  30. #% key: m
  31. #% description: Print temporal relationships and exit
  32. #%end
  33. #%flag
  34. #% key: s
  35. #% description: Print spatio-temporal relationships and exit
  36. #%end
  37. import grass.script as grass
  38. import grass.temporal as tgis
  39. ############################################################################
  40. def main():
  41. # Get the options
  42. name = options["input"]
  43. type = options["type"]
  44. where = options["where"]
  45. temporal_relations = flags['m']
  46. spatio_temporal_relations = flags['s']
  47. # Make sure the temporal database exists
  48. tgis.init()
  49. sp = tgis.open_old_space_time_dataset(name, type)
  50. # Get ordered map list
  51. maps = sp.get_registered_maps_as_objects(
  52. where=where, order="start_time", dbif=None)
  53. spatial = None
  54. if spatio_temporal_relations:
  55. if sp.get_type() == "strds":
  56. spatial = "2D"
  57. else:
  58. spatial = "3D"
  59. if temporal_relations or spatio_temporal_relations:
  60. sp.print_spatio_temporal_relationships(maps=maps, spatial=spatial)
  61. return
  62. sp.base.print_info()
  63. # 0123456789012345678901234567890
  64. print " +-------------------- Temporal topology -------------------------------------+"
  65. if where:
  66. print " | Is subset of dataset: ...... True"
  67. else:
  68. print " | Is subset of dataset: ...... False"
  69. check = sp.check_temporal_topology(maps)
  70. if check:
  71. # 0123456789012345678901234567890
  72. print " | Temporal topology is: ...... valid"
  73. else:
  74. # 0123456789012345678901234567890
  75. print " | Temporal topology is: ...... invalid"
  76. dict_ = sp.count_temporal_types(maps)
  77. for key in dict_.keys():
  78. if key == "interval":
  79. # 0123456789012345678901234567890
  80. print " | Number of intervals: ....... %s" % (dict_[key])
  81. if key == "point":
  82. print " | Number of points: .......... %s" % (dict_[key])
  83. if key == "invalid":
  84. print " | Invalid time stamps: ....... %s" % (dict_[key])
  85. # 0123456789012345678901234567890
  86. print " | Number of gaps: ............ %i" % sp.count_gaps(maps)
  87. if sp.is_time_absolute():
  88. gran = tgis.compute_absolute_time_granularity(maps)
  89. else:
  90. gran = tgis.compute_relative_time_granularity(maps)
  91. print " | Granularity: ............... %s" % str(gran)
  92. print " +-------------------- Topological relations ---------------------------------+"
  93. dict_ = sp.count_temporal_relations(maps)
  94. if dict_:
  95. for key in dict_.keys():
  96. if key == "equal":
  97. # 0123456789012345678901234567890
  98. print " | Equal:...................... %s" % (dict_[key])
  99. if key == "during":
  100. print " | During: .................... %s" % (dict_[key])
  101. if key == "contains":
  102. print " | Contains: .................. %s" % (dict_[key])
  103. if key == "overlaps":
  104. print " | Overlaps: .................. %s" % (dict_[key])
  105. if key == "overlapped":
  106. print " | Overlapped: ................ %s" % (dict_[key])
  107. if key == "after":
  108. print " | After: ..................... %s" % (dict_[key])
  109. if key == "before":
  110. print " | Before: .................... %s" % (dict_[key])
  111. if key == "starts":
  112. print " | Starts: .................... %s" % (dict_[key])
  113. if key == "finishes":
  114. print " | Finishes: .................. %s" % (dict_[key])
  115. if key == "started":
  116. print " | Started: ................... %s" % (dict_[key])
  117. if key == "finished":
  118. print " | Finished: .................. %s" % (dict_[key])
  119. if key == "follows":
  120. print " | Follows: ................... %s" % (dict_[key])
  121. if key == "precedes":
  122. print " | Precedes: .................. %s" % (dict_[key])
  123. print " +----------------------------------------------------------------------------+"
  124. if __name__ == "__main__":
  125. options, flags = grass.parser()
  126. main()