FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Aether/srcPython/plot_logfiles.py at refs/heads/develop · AetherModel/Aether · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
AetherModel
/
Aether
Public
Notifications
You must be signed in to change notification settings
Fork
31
Star
25
Code
Issues
21
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Aether
/
srcPython
/
plot_logfiles.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
345 lines (270 loc) · 8.49 KB
Breadcrumbs
Aether
/
srcPython
/
plot_logfiles.py
Copy path
File metadata and controls
executable file
·
345 lines (270 loc) · 8.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/usr/bin/env python3
import
matplotlib
as
mpl
mpl
.
use
(
'Agg'
)
import
matplotlib
.
pyplot
as
plt
import
numpy
as
np
import
re
import
argparse
import
datetime
as
dt
# ----------------------------------------------------------------------
# Function to parse input arguments
# ----------------------------------------------------------------------
def
get_args_timeline
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Post process and move model results'
)
parser
.
add_argument
(
'-plotfile'
,
help
=
'output file for plot'
,
default
=
'timeline.png'
)
parser
.
add_argument
(
'-vars'
,
help
=
'var(s) to plot (e.g. -vars 0 or -vars 0 1 2'
,
default
=
[
0
],
nargs
=
'+'
,
type
=
int
)
parser
.
add_argument
(
'filelist'
,
nargs
=
'+'
, \
help
=
'list files to use for generating plots'
)
args
=
parser
.
parse_args
()
return
args
# ----------------------------------------------------------------------
# Read space seperated file with header containing variable names
# ----------------------------------------------------------------------
def
read_ssv_file
(
file
):
data
=
{
"times"
: [],
'vars'
: [],
'alt'
:
0.0
,
"integral"
:
'values'
,
"file"
:
file
}
fpin
=
open
(
file
,
'r'
)
lines
=
fpin
.
readlines
()
fpin
.
close
()
vars
=
lines
[
0
].
split
(
' '
)
if
(
vars
[
6
]
==
'milli'
):
iOff
=
7
else
:
iOff
=
6
data
[
'vars'
]
=
vars
[
iOff
:]
nVars
=
len
(
data
[
'vars'
])
iStart
=
1
iEnd
=
len
(
lines
)
iLine
=
iStart
allValues
=
np
.
zeros
((
nVars
,
iEnd
-
iStart
))
while
(
iLine
<
iEnd
):
aline
=
lines
[
iLine
].
split
(
' '
)
if
((
len
(
aline
)
-
iOff
)
==
nVars
):
year
=
int
(
aline
[
0
])
month
=
int
(
aline
[
1
])
day
=
int
(
aline
[
2
])
hour
=
int
(
aline
[
3
])
minute
=
int
(
aline
[
4
])
second
=
int
(
aline
[
5
])
if
(
iOff
==
6
):
milli
=
0
else
:
milli
=
int
(
aline
[
6
])
t
=
dt
.
datetime
(
year
,
month
,
day
,
hour
,
minute
,
second
,
milli
)
data
[
"times"
].
append
(
t
)
for
iVar
in
range
(
nVars
):
allValues
[
iVar
,
iLine
-
iStart
]
=
float
(
aline
[
iOff
+
iVar
])
iLine
+=
1
data
[
'values'
]
=
allValues
return
data
# ----------------------------------------------------------------------
# Read file
# ----------------------------------------------------------------------
def
read_timeline_file
(
file
):
data
=
{
"times"
: [],
'vars'
: [],
'alt'
:
0.0
,
"integral"
:
'values'
,
"file"
:
file
}
fpin
=
open
(
file
,
'r'
)
lines
=
fpin
.
readlines
()
iStart
=
0
iEnd
=
len
(
lines
)
iLine
=
iStart
while
(
iLine
<
iEnd
):
line
=
lines
[
iLine
]
m
=
re
.
match
(
r'#VAR'
,
line
)
if
m
:
# skip year, month, day, hour, minute, second:
if
(
lines
[
iLine
+
1
].
strip
().
lower
()
==
'year'
):
iLine
+=
7
else
:
iLine
+=
1
while
(
len
(
lines
[
iLine
].
strip
())
>
1
):
data
[
"vars"
].
append
(
lines
[
iLine
].
strip
())
iLine
+=
1
data
[
'var'
]
=
data
[
"vars"
][
0
]
m
=
re
.
match
(
r'#INTEGRAL'
,
line
)
if
m
:
iLine
+=
1
data
[
"integral"
]
=
lines
[
iLine
].
strip
()
m
=
re
.
match
(
r'#ALTITUDE'
,
line
)
if
m
:
iLine
+=
1
data
[
"alt"
]
=
float
(
lines
[
iLine
].
strip
())
m
=
re
.
match
(
r'#DIRECTORY'
,
line
)
if
m
:
iLine
+=
1
data
[
"dir"
]
=
lines
[
iLine
].
strip
()
m
=
re
.
match
(
r'#START'
,
line
)
if
m
:
iStart
=
iLine
+
1
break
iLine
+=
1
nVars
=
len
(
data
[
'vars'
])
nTimes
=
iEnd
-
iStart
allValues
=
np
.
zeros
([
nVars
,
nTimes
])
for
i
in
range
(
iStart
,
iEnd
):
aline
=
lines
[
i
].
split
()
year
=
int
(
aline
[
0
])
month
=
int
(
aline
[
1
])
day
=
int
(
aline
[
2
])
hour
=
int
(
aline
[
3
])
minute
=
int
(
aline
[
4
])
second
=
int
(
aline
[
5
])
t
=
dt
.
datetime
(
year
,
month
,
day
,
hour
,
minute
,
second
)
data
[
"times"
].
append
(
t
)
for
iVar
in
range
(
nVars
):
allValues
[
iVar
,
i
-
iStart
]
=
float
(
aline
[
6
+
iVar
])
data
[
'values'
]
=
allValues
return
data
# ----------------------------------------------------------------------
# match filename with colors and linestyles
# ----------------------------------------------------------------------
def
assign_var_to_color
(
var
):
color
=
'black'
line
=
'solid'
label
=
file
m
=
re
.
match
(
'.*GOCE.*'
,
var
)
if
m
:
color
=
'black'
line
=
'solid'
label
=
'GOCE'
m
=
re
.
match
(
'.*GITM.*'
,
var
)
if
m
:
color
=
'blue'
line
=
'solid'
label
=
'GITM'
m
=
re
.
match
(
'.*Smooth.*'
,
var
)
if
m
:
line
=
'dashed'
label
=
label
+
' (smoothed)'
return
color
,
line
,
label
# ----------------------------------------------------------------------
# match filename with colors and linestyles
# ----------------------------------------------------------------------
def
assign_file_to_color
(
file
):
color
=
'black'
line
=
'solid'
label
=
file
m
=
re
.
match
(
'gdcA.*'
,
file
)
if
m
:
color
=
'black'
m
=
re
.
match
(
'gdcB.*'
,
file
)
if
m
:
color
=
'blue'
m
=
re
.
match
(
'gdcC.*'
,
file
)
if
m
:
color
=
'cyan'
m
=
re
.
match
(
'gdcD.*'
,
file
)
if
m
:
color
=
'purple'
m
=
re
.
match
(
'gdcE.*'
,
file
)
if
m
:
color
=
'orange'
m
=
re
.
match
(
'gdcF.*'
,
file
)
if
m
:
color
=
'red'
m
=
re
.
match
(
r'base'
,
file
)
if
m
:
color
=
'black'
line
=
'solid'
label
=
'Idealized Model'
m
=
re
.
match
(
r'fre'
,
file
)
if
m
:
color
=
'grey'
line
=
'solid'
label
=
'FRE Model'
m
=
re
.
match
(
r'ovation'
,
file
)
if
m
:
color
=
'blue'
line
=
'dashed'
label
=
'Ovation'
m
=
re
.
match
(
r'avee_050'
,
file
)
if
m
:
color
=
'darkblue'
line
=
'dashed'
m
=
re
.
match
(
r'avee_075'
,
file
)
if
m
:
color
=
'blue'
line
=
'dashed'
m
=
re
.
match
(
r'avee_150'
,
file
)
if
m
:
color
=
'firebrick'
line
=
'dashdot'
m
=
re
.
match
(
r'avee_200'
,
file
)
if
m
:
color
=
'red'
line
=
'dashdot'
m
=
re
.
match
(
r'fta'
,
file
)
if
m
:
color
=
'forestgreen'
line
=
'dashed'
label
=
'FTA Model'
m
=
re
.
match
(
r'ae'
,
file
)
if
m
:
color
=
'plum'
line
=
'dashed'
label
=
'FRE, AE Power'
m
=
re
.
match
(
r'ions'
,
file
)
if
m
:
color
=
'plum'
line
=
'dashdot'
label
=
'Ions'
m
=
re
.
match
(
r'.*no'
,
file
)
if
m
:
color
=
'cyan'
label
=
'NO Cooling'
m
=
re
.
match
(
r'.*ch'
,
file
)
if
m
:
color
=
'red'
label
=
'Chemical Heating'
m
=
re
.
match
(
r'.*ht'
,
file
)
if
m
:
color
=
'blue'
label
=
'Heat Transfer'
m
=
re
.
match
(
r'.*jh'
,
file
)
if
m
:
label
=
'Joule Heating'
return
color
,
line
,
label
# Needed to run main script as the default executable from the command line
if
__name__
==
'__main__'
:
args
=
get_args_timeline
()
iVar
=
args
.
vars
[
0
]
nFiles
=
len
(
args
.
filelist
)
nVars
=
len
(
args
.
vars
)
fig
=
plt
.
figure
(
figsize
=
(
10
,
10
))
ax
=
fig
.
add_subplot
(
111
)
for
file
in
args
.
filelist
:
print
(
"Reading file : "
,
file
)
#data = read_timeline_file(file)
data
=
read_ssv_file
(
file
)
nT
=
len
(
data
[
"times"
])
-
1
for
iVar
in
args
.
vars
:
label
=
data
[
"vars"
][
iVar
]
color
=
'black'
line
=
'--'
if
(
nFiles
>
1
):
color
,
line
,
label
=
assign_file_to_color
(
file
)
if
(
nVars
>
1
):
color
,
line
,
label
=
assign_var_to_color
(
data
[
'vars'
][
iVar
])
ax
.
plot
(
data
[
"times"
][:
nT
],
data
[
"values"
][
iVar
,:
nT
],
label
=
label
,
color
=
color
,
linestyle
=
line
,
linewidth
=
2.0
)
iVar
=
args
.
vars
[
0
]
ytitle
=
data
[
"integral"
]
+
" of "
+
data
[
"vars"
][
iVar
]
if
(
data
[
"alt"
]
>
0
):
ytitle
+=
" at %5.1f"
%
data
[
"alt"
]
+
" km Alt"
ax
.
set_ylabel
(
ytitle
)
ax
.
legend
()
plotfile
=
args
.
plotfile
print
(
'writing : '
,
plotfile
)
fig
.
savefig
(
plotfile
)
plt
.
close
()
Back
|
FazBrowse Home
|
New Git URL