-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot_output.py
executable file
·214 lines (145 loc) · 5.04 KB
/
plot_output.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env python
#import read_sub as sub
import py_read_output as rd
import py_plot_util as util
import plot_sub as p
from pylab import *
import numpy as np
import sys
import os
from astropy.io import ascii
import time
'''
usage
e.g. python plot_output.py
'''
BENCH_FOLDER = "outputs_release/"
def which(program):
'''
routine which checks if a program exists in the PATH.
just like the shell command which.
Parameters:
program string
name of binary e.g. py_wind80
Returns:
None not found
String location of binary
'''
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)
def ext_candidates(fpath):
yield fpath
for ext in os.environ.get("PATHEXT", "").split(os.pathsep):
yield fpath + ext
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
for candidate in ext_candidates(exe_file):
if is_exe(candidate):
return candidate
return None
def run_py_wind (fname, FOLDER, vers="", cmds=None, ilv=None):
'''
run version vers of py_wind on file fname.wind_save, removes
all traces and moves the .complete file to FOLDER/
'''
py_wind_cmd = 'py_wind'+vers
if which(py_wind_cmd) == None:
raise RuntimeError("Could not find executable %s. Compile it!" % py_wind_cmd)
if cmds == None:
cmds = np.array(["1","1","1","q"]) # cms to make the onefile summaries
x = cmds
np.savetxt("_tempcmd.txt", x, fmt = "%s")
cmd = py_wind_cmd+" "+FOLDER+fname+' < _tempcmd.txt > tempfile'
print "about to run py_wind with command: ",cmd
isys = os.system(cmd)
time.sleep(3)
#os.system("mv %s.complete %s" % (fname, FOLDER))
# remove temporary file
os.system("rm -f _tempcmd.txt py_wind.pf logfile tempfile tmp.rdpar")
return isys
def make_plots(names, FOLDER):
try:
VERSION=""
f = open("%s%s.out" % (FOLDER,names[0]), "r")
for line in f:
data = line.split()
if len(data) > 2:
if data[0] == "!!Python" and data[1]=="Version":
VERSION = data[2]
#if data[0] == "!!Python" and data[1]=="Version":
except IOError:
print "Couldn't read version"
VERSION=""
print "VERSION %s" % VERSION
for i in range(len(names)):
# this is just the name of the parameter file
shortname = names[i]
# the file will be in subfolders for comparison
name = FOLDER + shortname
benchname = BENCH_FOLDER + shortname
PLOT_FOLDER = "plot%s" % FOLDER[4:]
os.system("mkdir %s" % PLOT_FOLDER)
# read in the parameter file
pf_dict = rd.read_pf(name)
# try and read the output. if you get an index error it may have failed
try:
convergence = rd.read_convergence (name + ".out") # get convergence of model
bench_convergence = rd.read_convergence (benchname + ".out")
except IndexError:
print "Couldn't read convergence info for root %s, possible failure" % name
# print out the convergence compared to the benchmark model
print "Model %s" % name
print "%.2fpc Converged. Release: %.2f" % (100.0*convergence, 100.0*bench_convergence)
# run py_wind- only need to run this to create the onefile summary
run_py_wind(shortname, FOLDER, vers=VERSION)
p.make_geometry_plot(shortname, FOLDER, PLOT_FOLDER) # make plots of pywind quantities
p.make_geometry_ratios(shortname, FOLDER, PLOT_FOLDER)
# try and read in the spectrum
make_plots=True
try:
s = rd.read_spectrum(name)
except IOError:
print "Couldn't read spectrum for root %s, possible failure" % name
make_plots = False
# make plots against the benchmark spectrum
if make_plots:
s_bench = rd.read_spectrum(benchname)
#get_standard_dev(shortname, s, s_bench)
p.make_residual_plot(s, s_bench, shortname, PLOT_FOLDER) # make residual plots
p.make_comp_plot(s, s_bench, shortname, PLOT_FOLDER) # make comparison plots
p.make_components_comp_plot(s, s_bench, shortname, PLOT_FOLDER) # make components comparison plots
# this is the test spectot file
s = rd.read_spectrum (name+".log_spec_tot")
# this is the benchmark spectot file to test against
s_bench = rd.read_spectrum (benchname+".log_spec_tot")
# make a comparison plot of the log_spec_tot file
p.make_log_spec_tot_comp_plot(s, s_bench, shortname, PLOT_FOLDER)
#p.make_hc_plots_from_loop (shortname)
#p.make_ion_plots_from_loop (shortname)
# move all the wind data somewhere out the way
#os.system("mkdir wind_data")
#os.system("mv *.dat wind_data/")
#os.system("open -a preview *.png")
print "all done"
return 0
if __name__ == "__main__":
os.system("mkdir plots")
mode = int(sys.argv[1])
# this is where the outputs and plots are stored
FOLDER = sys.argv[2] +"/"
if mode == 1:
names = ["1d_sn", "star", "cv_standard"]
elif mode == 2:
names = ["1d_sn", "star", "fiducial_agn", "cv_standard"]
elif mode == 3:
names = ["1d_sn", "star", "m16_agn", "cv_macro_benchmark", "fiducial_agn", "cv_standard"]
make_plots(names, FOLDER)
# import Nick's script to make the ion plots
if mode > 1:
from ion_plots import make_ion_plots
make_ion_plots(FOLDER)