/
g.gui.tplot.py
executable file
·175 lines (155 loc) · 4.66 KB
/
g.gui.tplot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/usr/bin/env python3
############################################################################
#
# MODULE: g.gui.tplot.py
# AUTHOR(S): Luca Delucchi
# PURPOSE: Temporal Plot Tool is a wxGUI component (based on matplotlib)
# the user to see in a plot the values of one or more temporal
# datasets for a queried point defined by a coordinate pair.
# COPYRIGHT: (C) 2014-2015 by Luca Delucchi, and the GRASS Development Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
############################################################################
#%module
#% description: Plots the values of temporal datasets.
#% keywords: general
#% keywords: GUI
#% keywords: temporal
#% keywords: plot
#%end
#%flag
#% key: h
#% description: Set the header of CSV file, to be used with csv option
#%end
#%option G_OPT_STVDS_INPUTS
#% key: stvds
#% required: no
#%end
#%option G_OPT_STRDS_INPUTS
#% key: strds
#% required: no
#%end
#%option G_OPT_M_COORDS
#% required: no
#%end
# TODO use option G_OPT_V_CATS
#%option
#% key: cats
#% label: Categories of vectores features
#% description: To use only with stvds
#% required: no
#%end
#%option
#% key: attr
#% label: Name of attribute
#% description: Name of attribute which represent data for plotting
#% required: no
#%end
#%option G_OPT_F_OUTPUT
#% required: no
#% label: Name for output graphical file
#% description: Full path for output file containing the plot, ddd extension to specify format (.png, .pdf, .svg)
#%end
#%option G_OPT_F_OUTPUT
#% key: csv
#% required: no
#% label: Name for output CSV file
#% description: Full path for the CSV file containing the plotted data
#%end
#%option
#% key: title
#% label: Title for plot
#% description: The title for the output plot
#% required: no
#%end
#%option
#% key: xlabel
#% label: Label for x axis
#% description: The x axis label for the output plot
#% required: no
#%end
#%option
#% key: ylabel
#% label: Label for y axis
#% description: The y axis label for the output plot
#% required: no
#%end
#%option
#% key: size
#% type: string
#% label: The size for output image
#% description: It works only with output parameter
#% required: no
#%end
import grass.script as gscript
def main():
options, flags = gscript.parser()
import wx
from grass.script.setup import set_gui_path
set_gui_path()
from core.giface import StandaloneGrassInterface
try:
from tplot.frame import TplotFrame
except ImportError as e:
gscript.fatal(e.message)
rasters = None
if options['strds']:
rasters = options['strds'].strip().split(',')
coords = None
if options['coordinates']:
coords = options['coordinates'].strip().split(',')
cats = None
if options['cats']:
cats = options['cats']
output = options['output']
vectors = None
attr = None
if options['stvds']:
vectors = options['stvds'].strip().split(',')
if not options['attr']:
gscript.fatal(_("With stvds you have to set 'attr' option"))
else:
attr = options['attr']
if coords and cats:
gscript.fatal(_("With stvds it is not possible to use 'coordinates' "
"and 'cats' options together"))
elif not coords and not cats:
gscript.warning(_("With stvds you have to use 'coordinates' or "
"'cats' option"))
title = None
if options['title']:
title = options['title']
xlabel = None
if options['xlabel']:
xlabel = options['xlabel']
ylabel = None
if options['ylabel']:
ylabel = options['ylabel']
csvfile = None
if options['csv']:
csvfile = options['csv']
app = wx.App()
frame = TplotFrame(parent=None, giface=StandaloneGrassInterface())
frame.SetDatasets(rasters, vectors, coords, cats, attr, title, xlabel,
ylabel, csvfile, flags['h'], gscript .overwrite)
if output:
frame.OnRedraw()
if options['size']:
sizes = options['size'].strip().split(',')
sizes = [int(s) for s in sizes]
frame.canvas.SetSize(sizes)
frame.canvas.figure.savefig(output)
else:
frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()