6 from oct2py
import octave
9 return math.atan2(math.sin(alpha-beta), math.cos(alpha-beta));
19 (opts, args) = getopt.getopt(argv[1:],
"hr:p:",[
"recordfile=",
"precision="])
20 except getopt.GetoptError:
21 print prog +
' -r <recordfile> -p <precision>' 25 print prog +
' -r <recordfile> -p <precision>' 27 elif opt
in (
"-r",
"--recordfile"):
29 elif opt
in (
"-p",
"--precision"):
30 precision = abs(float(arg))
33 if recordfile ==
'' or precision == -1
or len(args) != 0:
34 print prog +
' -r <recordfile> -p <precision>' 37 pos = recordfile.rfind(
"/")
38 variancefile = recordfile[:pos+1] +
'variance.csv' 39 parameterfile = recordfile[:pos+1] +
'parameter.csv' 44 variance_global = (0, 0, 0, 0)
45 with open(recordfile,
'r') as f: 47 if line ==
'exp_length;exp_angle;exp_orientation;length;angle;orientation\n':
52 raise ValueError(
'Not a valid line: ' + line)
53 count_all = count_all + 1
71 id =
'{}:{}:{}'.format(int(math.floor(abs(el/precision))), int(math.floor(abs(10*ea/precision))), int(math.floor(abs(10*eo/precision))))
74 variance_global = (variance_global[0] + 1, variance_global[1] + dl2, variance_global[2] + da2, variance_global[3] + do2)
75 if id
in boxes.keys():
76 (n, sl2, sa2, so2) = boxes[id]
77 boxes[id] = (n + 1, sl2 + dl2, sa2 + da2, so2 + do2)
79 boxes[id] = (1, dl2, da2, do2)
82 variance_global = (variance_global[1]/variance_global[0], variance_global[2]/variance_global[0], variance_global[3]/variance_global[0])
86 for id
in boxes.keys():
87 (n, sl2, sa2, so2) = boxes[id]
88 variance[id] = (sl2/n, sa2/n, so2/n)
90 if variance[id][0] > 2*variance_global[0]
or variance[id][1] > 2*variance_global[1]
or variance[id][2] > 2*variance_global[2]:
94 if len(suspicious) > 0:
99 count_susp = count_susp + n
100 print id +
" (" + str(n) +
"): " + str(variance[id])
101 if len(suspicious) > 0:
102 print "At all " + str(count_susp) +
" from " + str(count_all) +
" measurements are suspicious" 105 with open(recordfile,
'r') as rf: 106 with open(variancefile, 'w')
as vf:
108 if line ==
'exp_length;exp_angle;exp_orientation;length;angle;orientation\n':
109 vf.write(
'exp_length;exp_angle;exp_orientation;var_length;var_angle;var_orientation;length;angle;orientation\n')
112 tmp = line.split(
';')
114 raise ValueError(
'Not a valid line: ' + line)
122 id =
'{}:{}:{}'.format(int(math.floor(abs(el/precision))), int(math.floor(abs(10*ea/precision))), int(math.floor(abs(10*eo/precision))))
125 (vl, va, vo) = variance[id]
126 assert vl > 0
and va > 0
and vo > 0
129 if id
not in suspicious:
130 vf.write(
'{};{};{};{};{};{};{};{};{}\n'.format(el, ea, eo, vl, va, vo, tmp[3], tmp[4], tmp[5]))
132 print 'Successfully created file \"' + variancefile +
'\"' 135 p = octave.parameter(variancefile)
138 with open(parameterfile,
'w')
as f:
139 f.write(
';par_length_x;par_length_c;par_angle_x;par_angle_c;par_orientation_x;par_orientation_c\n')
140 f.write(
'var_length;{};{};{};{};{};{}\n'.format(p[0][0], p[0][1], p[0][2], p[0][3], p[0][4], p[0][5]))
141 f.write(
'var_angle;{};{};{};{};{};{}\n'.format(p[1][0], p[1][1], p[1][2], p[1][3], p[1][4], p[1][5]))
142 f.write(
'var_orientation;{};{};{};{};{};{}\n'.format(p[2][0], p[2][1], p[2][2], p[2][3], p[2][4], p[2][5]))
144 print 'Successfully created file \"' + parameterfile +
'\"' 146 if __name__ ==
'__main__':
def angle_difference(alpha, beta)