-
Notifications
You must be signed in to change notification settings - Fork 2
/
pppr_functions.py
104 lines (90 loc) · 3.35 KB
/
pppr_functions.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
"""
Functions used in pppr-gui
Authors/modifications:
----------------------
Frank Heberling ([email protected])
"""
####################################################
import numpy as Num
import random
############################## extract datasets and read parameters ############################
class DataSet:
def __init__(self):
self.x_label = ''
self.y_label = ''
self.n = 0
self.weight = 1.0
self.plot = 0
self.lower = 0
self.upper = 0
def eval_datastring(datastring):
data = Num.ndarray((0,7),float)
datasets = []
datastring = str(datastring)
tmp = datastring.split("\n")
counter = 0
for i in range(len(tmp)):
if tmp[i] =='':
pass
else:
tmp2 = str.rsplit(tmp[i])
try:
tmp3 = []
for a in tmp2:
tmp3.append(float(a))
for a in range(4):
tmp3.append(0.)
data = Num.append(data, [tmp3], axis = 0)
counter += 1
except ValueError:
if counter == 0:
a = DataSet()
a.x_label = tmp2[0]
a.y_label = tmp2[1]
a.lower = counter
datasets.append(a)
else:
a = DataSet()
a.x_label = tmp2[0]
a.y_label = tmp2[1]
a.lower = counter
datasets[-1].upper = counter
datasets[-1].n = datasets[-1].upper - datasets[-1].lower
datasets.append(a)
datasets[-1].upper = counter
datasets[-1].n = datasets[-1].upper - datasets[-1].lower
data = Num.transpose(data)
return data, datasets
def read_parameters(parameterfile):
parameter={}
param_labels = []
f = open(parameterfile, 'r')
data = f.readlines()
f.close()
for i in data:
tmp = str.rsplit(i)
if tmp[0] != '%':
if len(tmp) == 5:
parameter[tmp[0]]= [float(tmp[1]),float(tmp[2]),float(tmp[3]),False, 0., '']
if tmp[4] == 'True':
parameter[tmp[0]][3] = True
elif len(tmp) == 6:
parameter[tmp[0]]= [float(tmp[1]),float(tmp[3]),float(tmp[4]),False, float(tmp[2]), '']
if tmp[5] == 'True':
parameter[tmp[0]][3] = True
param_labels.append(tmp[0])
return parameter, param_labels
######################## writing parameter file #######################################
def write_par(parameter, param_labels, filename = 'parameters.new'):
f = file(filename, 'w')
f.write('% param_label value std-dev min max '+\
'refine_flag\n')
for i in param_labels:
line = "%13s %18.12e %12.8e %12.4e %12.4e %10s\n" % (i,parameter[i][0],
parameter[i][4],
parameter[i][1],
parameter[i][2],
parameter[i][3])
f.write(line)
f.close()
#