~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to temporal/t.topology/t.topology.py

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

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