-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_data.py
More file actions
52 lines (49 loc) · 1.87 KB
/
Copy pathsave_data.py
File metadata and controls
52 lines (49 loc) · 1.87 KB
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
#import gvar as gv
import datetime
import meta_data
def save_data(out_fname,fit,data):
## -- save the fit parameters found after fitting
try:
fit_file = open(out_fname,'w')
write_header(fit_file)
fit_file.write('chi2/dof ' + str(round(fit.chi2/fit.dof,2)) + '\n')
fit_file.write('dof ' + str(fit.dof) + '\n')
fit_file.write('Q ' + str(round(fit.Q,2)) + '\n')
for ptag in fit.transformed_p:
if ptag == 'dE':
E = [sum(fit.p['dE'][:i+1]) for i in range(len(fit.p['dE']))]
fit_file.write( "fit_mean E " +\
" ".join(str('{:1.4e}'.format(E[i].mean))\
for i in range(len(fit.transformed_p[ptag]))) + '\n')
fit_file.write( "fit_sdev E " +\
" ".join(str('{:1.4e}'.format(fit.transformed_p['dE'][i].sdev))\
for i in range(len(fit.transformed_p[ptag]))) + '\n')
else:
fit_file.write( "fit_mean " + ptag + " " +\
" ".join(str('{:1.4e}'.format(fit.transformed_p[ptag][i].mean))\
for i in range(len(fit.transformed_p[ptag]))) + '\n')
fit_file.write( "fit_sdev " + ptag + " " +\
" ".join(str('{:1.4e}'.format(fit.transformed_p[ptag][i].sdev))\
for i in range(len(fit.transformed_p[ptag]))) + '\n')
#for ctag in data:
# fit_file.write( ctag + " dat_mean " +\
# " ".join(str('{:e}'.format(data[ctag][i].mean))\
# for i in range(len(data[ctag]))) + '\n')
# fit_file.write( ctag + " dat_sdev " +\
# " ".join(str('{:e}'.format(data[ctag][i].sdev))\
# for i in range(len(data[ctag]))) + '\n')
print "Wrote fit information to file: "
print " " + out_fname
fit_file.close()
except IOError:
print "Could not save data"
pass
def write_header(outfile):
## -- write a header to the output file
outfile.seek(0,2)
dtime = datetime.datetime.now()
try:
outfile.write("# opened : %s/%s/%s - %s:%s:%s \n" %\
(dtime.year,dtime.month,dtime.day,dtime.hour,dtime.minute,dtime.second) )
except AttributeError:
pass