GeneralBrokenLines V03-01-02
gblpy
mille.py
Go to the documentation of this file.
1'''
2Input/output of MP-II binary records.
3
4Created on Aug 1, 2011
5
6@author: kleinwrt
7'''
8
9
29
30import array, math
31
32
33
76class MilleRecord(object):
77
78
80 def __init__(self, doublePrec=False):
81
82 self.__doublePrecision = doublePrec
83
84 self.__position = 1
85
86 self.__numData = 0
87
88 self.__recLen = 0
89
90 self.__iMeas = 0
91
92 self.__iErr = 0
93
94 self.__inder = array.array('i')
95
96 self.__glder = array.array('d' if doublePrec else 'f')
97
98
102 def addData(self, dataList):
103 if (self.__numData == 0): # first word is error counter
104 self.__inder.append(0)
105 self.__glder.append(0.)
106 self.__numData += 1
107
108 aMeas, aPrec, indLocal, derLocal, labGlobal, derGlobal = dataList
109 self.__inder.append(0)
110 self.__glder.append(aMeas)
111 self.__inder.fromlist(indLocal)
112 self.__glder.fromlist(derLocal)
113 self.__inder.append(0)
114 self.__glder.append(1.0 / math.sqrt(aPrec)) # convert to error
115 self.__inder.fromlist(labGlobal)
116 self.__glder.fromlist(derGlobal)
117
118
122 def getData(self):
123 aMeas = self.__glder[self.__iMeas]
124 indLocal = []
125 derLocal = []
126 for i in range(self.__iMeas + 1, self.__iErr):
127 indLocal.append(self.__inder[i])
128 derLocal.append(self.__glder[i])
129 aPrec = 1.0 / self.__glder[self.__iErr] ** 2 # convert to precision
130 indGlobal = []
131 derGlobal = []
132 for i in range(self.__iErr + 1, self.__position):
133 indGlobal.append(self.__inder[i])
134 derGlobal.append(self.__glder[i])
135 return aMeas, aPrec, indLocal, derLocal, indGlobal, derGlobal
136
137
138 def printRecord(self):
139 print " MilleRecord, len: ", len(self.__inder)
140 print self.__inder
141 print self.__glder
142
143
147 def writeRecord(self, aFile):
148 header = array.array('i') # header with number of words
149 header.append(-len(self.__inder) * 2 if self.__doublePrecision else len(self.__inder) * 2)
150 header.tofile(aFile)
151 self.__glder.tofile(aFile)
152 self.__inder.tofile(aFile)
153
154
158 def readRecord(self, aFile):
159 header = array.array('i') # header with number of words
160 header.fromfile(aFile, 1)
161 self.__recLen = abs(header[0] / 2)
162 if header[0] < 0:
163 self.__glder = array.array('d')
164 self.__glder.fromfile(aFile, self.__recLen)
165 self.__inder.fromfile(aFile, self.__recLen)
166
167
171 def moreData(self):
172 if (self.__position < self.__recLen):
173 while (self.__position < self.__recLen and self.__inder[self.__position] != 0):
174 self.__position += 1
175 self.__iMeas = self.__position
176 self.__position += 1
177 while (self.__position < self.__recLen and self.__inder[self.__position] != 0):
178 self.__position += 1
179 self.__iErr = self.__position
180 self.__position += 1
181 # special data?
182 if (self.__iMeas + 1 == self.__iErr and self.__glder[self.__iErr] < 0):
183 self.__position += int(-self.__glder[self.__iErr])
184 else:
185 while (self.__position < self.__recLen and self.__inder[self.__position] != 0):
186 self.__position += 1
187 self.__numData += 1
188 return True
189 else:
190 return False
191
192
196 def specialDataTag(self):
197 aTag = -1
198 if (self.__iMeas + 1 == self.__iErr and self.__glder[self.__iErr] < 0):
199 aTag = int(-self.__glder[self.__iErr] * 10. + 0.5) % 10
200 return aTag
Millepede-II (binary) record.
Definition: mille.py:76
def readRecord(self, aFile)
Read record from file.
Definition: mille.py:158
__iMeas
position of value in current data block; int
Definition: mille.py:90
def addData(self, dataList)
Add data block to (end of) record.
Definition: mille.py:102
def moreData(self)
Locate next data block.
Definition: mille.py:171
__iErr
position of error in current data block; int
Definition: mille.py:92
__numData
number of data blocks in record; int
Definition: mille.py:86
__doublePrecision
flag for storage in as double values
Definition: mille.py:82
__recLen
record length; int
Definition: mille.py:88
def __init__(self, doublePrec=False)
Create MP-II binary record.
Definition: mille.py:80
__glder
array with values, errors and derivatives; (float32 or float64)
Definition: mille.py:96
__inder
array with markers (0) and labels; array(int32)
Definition: mille.py:94
__position
position in record, usually start of next data block; int
Definition: mille.py:84
def getData(self)
Get data block from current position in record.
Definition: mille.py:122
def specialDataTag(self)
Get special data tag from block.
Definition: mille.py:196
def writeRecord(self, aFile)
Write record to file.
Definition: mille.py:147
def printRecord(self)
Print record.
Definition: mille.py:138