-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_stat.py
executable file
·191 lines (175 loc) · 5.15 KB
/
plot_stat.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/usr/bin/env python
###################################################################
# Plot stuff from multiple stat files on a single plot
#
#Copyright (C) 2013 Jon Hill, [email protected]
#
# 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 3 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import sys
import math
import string
import biology_util
from mld_util import *
import argparse
from fluidity_tools import stat_parser
from pylab import *
def main():
parser = argparse.ArgumentParser(
prog="plot stat",
description="""Plot a variable from the stat file for several runs."""
)
parser.add_argument(
'-v',
'--verbose',
action='store_true',
help="Verbose output: mainly progress reports.",
default=False
)
parser.add_argument(
'-o',
'--output',
nargs='+',
help="Fluidity stat files",
required=True
)
parser.add_argument(
'-l',
'--labels',
help="What to call the Fluidity data",
required=True,
nargs='+'
)
parser.add_argument(
'-n',
'--nyears',
type=int,
help="Number of years to plot. Default is longest time from Fluidity data",
required=False,
)
parser.add_argument(
'-s',
'--smooth',
type=int,
help="Take every n data points from the statplot. Use a large number if your stat file is large.",
required=False,
default = 1
)
parser.add_argument(
'-y',
'--ylabel',
help="Supply a different label for the y-axis",
required=False,
default = 1
)
parser.add_argument(
'-m',
'--material',
help="Material name. Default is Fluid",
required=False,
default = "Fluid"
)
parser.add_argument(
'variable',
metavar='variable',
nargs=1,
help="The variable to pull",
)
parser.add_argument(
'statistic',
metavar='statistic',
nargs=1,
help="The statistic to pull",
)
parser.add_argument(
'output_file',
metavar='output_file',
nargs=1,
help='The output filename'
)
args = parser.parse_args()
verbose = args.verbose
labels = args.labels
output_file = args.output_file[0]
variable = args.variable[0]
statistic = args.statistic[0]
smooth = args.smooth
ylabel_string = args.ylabel
material = args.material
if (args.nyears == None):
nDays = None
else:
nDays = args.nyears*365
if (ylabel_string == None):
ylabel_string = statistic + " " + variable
if (verbose):
print "Plot Summary: "
data_array = []
time_array = []
files = []
longest_day = 0
for s in args.output:
if (verbose):
print " Scanning "+d
# grab data from stat file
stat=stat_parser( s, smooth )
time = stat["ElapsedTime"]["value"]
days = []
for t in time:
days.append(t/(24*60*60))
time_array.append(days)
if (days[-1] > longest_day):
longest_day = days[-1]
time = []
days = []
data = stat[material][variable][statistic]
data_array.append(data)
if (not nDays):
nDays = longest_day
colours = [
'r',
'b',
'g',
'k',
'DarkBlue',
'Olive',
'DarkGoldenRod',
]
params = {
'legend.fontsize': 30,
'xtick.labelsize': 26,
'ytick.labelsize': 26,
'font.size' : 26,
'axes.labelsize' : 30,
'text.fontsize' : 30,
'figure.subplot.hspace' : 0.5,
'text.usetex' : True
}
rcParams.update(params)
i = 0
fig = figure(figsize=(25,10),dpi=90)
ax = fig.add_subplot(111)
for data in data_array:
ax.plot(time_array[i][:],data[:],colours[i],label=labels[i],lw=3)
i = i+1
ax.yaxis.grid(True)
xlabel('Time (days)')
ylabel(ylabel_string)
ax.set_xlim(0,nDays)
#ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.1),
# ncol=2, fancybox=True, shadow=True)
ax.legend(loc=0,ncol=2,fancybox=True,shadow=True)
savefig(output_file, dpi=90,format='png')
if __name__ == "__main__":
main()