##// END OF EJS Templates
Problems setting and reading Header size
Miguel Valdez -
r728:e878c6835775
parent child
Show More
@@ -1,735 +1,757
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
4 $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $
5 '''
5 '''
6 import numpy
6 import numpy
7 import copy
7 import copy
8 import datetime
8 import datetime
9
9
10 SPEED_OF_LIGHT = 299792458
10 SPEED_OF_LIGHT = 299792458
11 SPEED_OF_LIGHT = 3e8
11 SPEED_OF_LIGHT = 3e8
12
12
13 BASIC_STRUCTURE = numpy.dtype([
13 BASIC_STRUCTURE = numpy.dtype([
14 ('nSize','<u4'),
14 ('nSize','<u4'),
15 ('nVersion','<u2'),
15 ('nVersion','<u2'),
16 ('nDataBlockId','<u4'),
16 ('nDataBlockId','<u4'),
17 ('nUtime','<u4'),
17 ('nUtime','<u4'),
18 ('nMilsec','<u2'),
18 ('nMilsec','<u2'),
19 ('nTimezone','<i2'),
19 ('nTimezone','<i2'),
20 ('nDstflag','<i2'),
20 ('nDstflag','<i2'),
21 ('nErrorCount','<u4')
21 ('nErrorCount','<u4')
22 ])
22 ])
23
23
24 SYSTEM_STRUCTURE = numpy.dtype([
24 SYSTEM_STRUCTURE = numpy.dtype([
25 ('nSize','<u4'),
25 ('nSize','<u4'),
26 ('nNumSamples','<u4'),
26 ('nNumSamples','<u4'),
27 ('nNumProfiles','<u4'),
27 ('nNumProfiles','<u4'),
28 ('nNumChannels','<u4'),
28 ('nNumChannels','<u4'),
29 ('nADCResolution','<u4'),
29 ('nADCResolution','<u4'),
30 ('nPCDIOBusWidth','<u4'),
30 ('nPCDIOBusWidth','<u4'),
31 ])
31 ])
32
32
33 RADAR_STRUCTURE = numpy.dtype([
33 RADAR_STRUCTURE = numpy.dtype([
34 ('nSize','<u4'),
34 ('nSize','<u4'),
35 ('nExpType','<u4'),
35 ('nExpType','<u4'),
36 ('nNTx','<u4'),
36 ('nNTx','<u4'),
37 ('fIpp','<f4'),
37 ('fIpp','<f4'),
38 ('fTxA','<f4'),
38 ('fTxA','<f4'),
39 ('fTxB','<f4'),
39 ('fTxB','<f4'),
40 ('nNumWindows','<u4'),
40 ('nNumWindows','<u4'),
41 ('nNumTaus','<u4'),
41 ('nNumTaus','<u4'),
42 ('nCodeType','<u4'),
42 ('nCodeType','<u4'),
43 ('nLine6Function','<u4'),
43 ('nLine6Function','<u4'),
44 ('nLine5Function','<u4'),
44 ('nLine5Function','<u4'),
45 ('fClock','<f4'),
45 ('fClock','<f4'),
46 ('nPrePulseBefore','<u4'),
46 ('nPrePulseBefore','<u4'),
47 ('nPrePulseAfter','<u4'),
47 ('nPrePulseAfter','<u4'),
48 ('sRangeIPP','<a20'),
48 ('sRangeIPP','<a20'),
49 ('sRangeTxA','<a20'),
49 ('sRangeTxA','<a20'),
50 ('sRangeTxB','<a20'),
50 ('sRangeTxB','<a20'),
51 ])
51 ])
52
52
53 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
53 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
54
54
55
55
56 PROCESSING_STRUCTURE = numpy.dtype([
56 PROCESSING_STRUCTURE = numpy.dtype([
57 ('nSize','<u4'),
57 ('nSize','<u4'),
58 ('nDataType','<u4'),
58 ('nDataType','<u4'),
59 ('nSizeOfDataBlock','<u4'),
59 ('nSizeOfDataBlock','<u4'),
60 ('nProfilesperBlock','<u4'),
60 ('nProfilesperBlock','<u4'),
61 ('nDataBlocksperFile','<u4'),
61 ('nDataBlocksperFile','<u4'),
62 ('nNumWindows','<u4'),
62 ('nNumWindows','<u4'),
63 ('nProcessFlags','<u4'),
63 ('nProcessFlags','<u4'),
64 ('nCoherentIntegrations','<u4'),
64 ('nCoherentIntegrations','<u4'),
65 ('nIncoherentIntegrations','<u4'),
65 ('nIncoherentIntegrations','<u4'),
66 ('nTotalSpectra','<u4')
66 ('nTotalSpectra','<u4')
67 ])
67 ])
68
68
69 class Header(object):
69 class Header(object):
70
70
71 def __init__(self):
71 def __init__(self):
72 raise NotImplementedError
72 raise NotImplementedError
73
73
74 def copy(self):
74 def copy(self):
75 return copy.deepcopy(self)
75 return copy.deepcopy(self)
76
76
77 def read(self):
77 def read(self):
78
78
79 raise NotImplementedError
79 raise NotImplementedError
80
80
81 def write(self):
81 def write(self):
82
82
83 raise NotImplementedError
83 raise NotImplementedError
84
84
85 def printInfo(self):
85 def printInfo(self):
86
86
87 message = "#"*50 + "\n"
87 message = "#"*50 + "\n"
88 message += self.__class__.__name__.upper() + "\n"
88 message += self.__class__.__name__.upper() + "\n"
89 message += "#"*50 + "\n"
89 message += "#"*50 + "\n"
90
90
91 for key in self.__dict__.keys():
91 keyList = self.__dict__.keys()
92 keyList.sort()
93
94 for key in keyList:
92 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
95 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
96
97 if "size" not in keyList:
98 attr = getattr(self, "size")
93
99
100 if attr:
101 message += "%s = %s" %("size", attr) + "\n"
102
94 print message
103 print message
95
104
96 class BasicHeader(Header):
105 class BasicHeader(Header):
97
106
98 size = None
107 size = None
99 version = None
108 version = None
100 dataBlock = None
109 dataBlock = None
101 utc = None
110 utc = None
102 ltc = None
111 ltc = None
103 miliSecond = None
112 miliSecond = None
104 timeZone = None
113 timeZone = None
105 dstFlag = None
114 dstFlag = None
106 errorCount = None
115 errorCount = None
107 datatime = None
116 datatime = None
108
117
109 __LOCALTIME = None
118 __LOCALTIME = None
110
119
111 def __init__(self, useLocalTime=True):
120 def __init__(self, useLocalTime=True):
112
121
113 self.size = 24
122 self.size = 24
114 self.version = 0
123 self.version = 0
115 self.dataBlock = 0
124 self.dataBlock = 0
116 self.utc = 0
125 self.utc = 0
117 self.miliSecond = 0
126 self.miliSecond = 0
118 self.timeZone = 0
127 self.timeZone = 0
119 self.dstFlag = 0
128 self.dstFlag = 0
120 self.errorCount = 0
129 self.errorCount = 0
121
130
122 self.useLocalTime = useLocalTime
131 self.useLocalTime = useLocalTime
123
132
124 def read(self, fp):
133 def read(self, fp):
125
134
126 try:
135 try:
127 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
136 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
128
137
129 except Exception, e:
138 except Exception, e:
130 print "BasicHeader: "
139 print "BasicHeader: "
131 print e
140 print e
132 return 0
141 return 0
133
142
134 self.size = int(header['nSize'][0])
143 self.size = int(header['nSize'][0])
135 self.version = int(header['nVersion'][0])
144 self.version = int(header['nVersion'][0])
136 self.dataBlock = int(header['nDataBlockId'][0])
145 self.dataBlock = int(header['nDataBlockId'][0])
137 self.utc = int(header['nUtime'][0])
146 self.utc = int(header['nUtime'][0])
138 self.miliSecond = int(header['nMilsec'][0])
147 self.miliSecond = int(header['nMilsec'][0])
139 self.timeZone = int(header['nTimezone'][0])
148 self.timeZone = int(header['nTimezone'][0])
140 self.dstFlag = int(header['nDstflag'][0])
149 self.dstFlag = int(header['nDstflag'][0])
141 self.errorCount = int(header['nErrorCount'][0])
150 self.errorCount = int(header['nErrorCount'][0])
142
151
143 return 1
152 return 1
144
153
145 def write(self, fp):
154 def write(self, fp):
146
155
147 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
156 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
148 header = numpy.array(headerTuple, BASIC_STRUCTURE)
157 header = numpy.array(headerTuple, BASIC_STRUCTURE)
149 header.tofile(fp)
158 header.tofile(fp)
150
159
151 return 1
160 return 1
152
161
153 def get_ltc(self):
162 def get_ltc(self):
154
163
155 return self.utc - self.timeZone*60
164 return self.utc - self.timeZone*60
156
165
157 def set_ltc(self, value):
166 def set_ltc(self, value):
158
167
159 self.utc = value + self.timeZone*60
168 self.utc = value + self.timeZone*60
160
169
161 def get_datatime(self):
170 def get_datatime(self):
162
171
163 return datetime.datetime.utcfromtimestamp(self.ltc)
172 return datetime.datetime.utcfromtimestamp(self.ltc)
164
173
165 ltc = property(get_ltc, set_ltc)
174 ltc = property(get_ltc, set_ltc)
166 datatime = property(get_datatime)
175 datatime = property(get_datatime)
167
176
168 class SystemHeader(Header):
177 class SystemHeader(Header):
169
178
170 size = None
179 size = None
171 nSamples = None
180 nSamples = None
172 nProfiles = None
181 nProfiles = None
173 nChannels = None
182 nChannels = None
174 adcResolution = None
183 adcResolution = None
175 pciDioBusWidth = None
184 pciDioBusWidth = None
176
185
177 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
186 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
178
187
179 self.size = 24
188 self.size = 24
180 self.nSamples = nSamples
189 self.nSamples = nSamples
181 self.nProfiles = nProfiles
190 self.nProfiles = nProfiles
182 self.nChannels = nChannels
191 self.nChannels = nChannels
183 self.adcResolution = adcResolution
192 self.adcResolution = adcResolution
184 self.pciDioBusWidth = pciDioBusWith
193 self.pciDioBusWidth = pciDioBusWith
185
194
186 def read(self, fp):
195 def read(self, fp):
187
196
188 startFp = fp.tell()
197 startFp = fp.tell()
189
198
190 try:
199 try:
191 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
200 header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1)
192 except Exception, e:
201 except Exception, e:
193 print "SystemHeader: " + e
202 print "System Header: " + e
194 return 0
203 return 0
195
204
196 self.size = header['nSize'][0]
205 self.size = header['nSize'][0]
197 self.nSamples = header['nNumSamples'][0]
206 self.nSamples = header['nNumSamples'][0]
198 self.nProfiles = header['nNumProfiles'][0]
207 self.nProfiles = header['nNumProfiles'][0]
199 self.nChannels = header['nNumChannels'][0]
208 self.nChannels = header['nNumChannels'][0]
200 self.adcResolution = header['nADCResolution'][0]
209 self.adcResolution = header['nADCResolution'][0]
201 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
210 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
202
211
203 endFp = self.size + startFp
212 endFp = self.size + startFp
204
213
205 if fp.tell() != endFp:
214 if fp.tell() > endFp:
206 print "System Header is not consistent"
215 sys.stderr.write("Warning: System header size is lower than it has to be")
207 return 0
216 return 0
208
217
218 if fp.tell() < endFp:
219 sys.stderr.write("Warning: System header size is greater than it is considered")
220
209 return 1
221 return 1
210
222
211 def write(self, fp):
223 def write(self, fp):
212
224
213 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
225 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
214 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
226 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
215 header.tofile(fp)
227 header.tofile(fp)
216
228
217 return 1
229 return 1
218
230
219 class RadarControllerHeader(Header):
231 class RadarControllerHeader(Header):
220
232
221 size = None
222 expType = None
233 expType = None
223 nTx = None
234 nTx = None
224 ipp = None
235 ipp = None
225 txA = None
236 txA = None
226 txB = None
237 txB = None
227 nWindows = None
238 nWindows = None
228 numTaus = None
239 numTaus = None
229 codeType = None
240 codeType = None
230 line6Function = None
241 line6Function = None
231 line5Function = None
242 line5Function = None
232 fClock = None
243 fClock = None
233 prePulseBefore = None
244 prePulseBefore = None
234 prePulserAfter = None
245 prePulserAfter = None
235 rangeIpp = None
246 rangeIpp = None
236 rangeTxA = None
247 rangeTxA = None
237 rangeTxB = None
248 rangeTxB = None
238
249
239 __size = None
250 __size = None
240
251
241 def __init__(self, expType=2, nTx=1,
252 def __init__(self, expType=2, nTx=1,
242 ippKm=None, txA=0, txB=0,
253 ippKm=None, txA=0, txB=0,
243 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
254 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
244 numTaus=0, line6Function=0, line5Function=0, fClock=None,
255 numTaus=0, line6Function=0, line5Function=0, fClock=None,
245 prePulseBefore=0, prePulseAfter=0,
256 prePulseBefore=0, prePulseAfter=0,
246 codeType=0, nCode=0, nBaud=0, code=None,
257 codeType=0, nCode=0, nBaud=0, code=None,
247 flip1=0, flip2=0):
258 flip1=0, flip2=0):
248
259
249 self.size = 116
260 # self.size = 116
250 self.expType = expType
261 self.expType = expType
251 self.nTx = nTx
262 self.nTx = nTx
252 self.ipp = ippKm
263 self.ipp = ippKm
253 self.txA = txA
264 self.txA = txA
254 self.txB = txB
265 self.txB = txB
255 self.rangeIpp = ippKm
266 self.rangeIpp = ippKm
256 self.rangeTxA = txA
267 self.rangeTxA = txA
257 self.rangeTxB = txB
268 self.rangeTxB = txB
258
269
259 self.nWindows = nWindows
270 self.nWindows = nWindows
260 self.numTaus = numTaus
271 self.numTaus = numTaus
261 self.codeType = codeType
272 self.codeType = codeType
262 self.line6Function = line6Function
273 self.line6Function = line6Function
263 self.line5Function = line5Function
274 self.line5Function = line5Function
264 self.fClock = fClock
275 self.fClock = fClock
265 self.prePulseBefore = prePulseBefore
276 self.prePulseBefore = prePulseBefore
266 self.prePulserAfter = prePulseAfter
277 self.prePulserAfter = prePulseAfter
267
278
268 self.nHeights = nHeights
279 self.nHeights = nHeights
269 self.firstHeight = firstHeight
280 self.firstHeight = firstHeight
270 self.deltaHeight = deltaHeight
281 self.deltaHeight = deltaHeight
271 self.samplesWin = nHeights
282 self.samplesWin = nHeights
272
283
273 self.nCode = nCode
284 self.nCode = nCode
274 self.nBaud = nBaud
285 self.nBaud = nBaud
275 self.code = code
286 self.code = code
276 self.flip1 = flip1
287 self.flip1 = flip1
277 self.flip2 = flip2
288 self.flip2 = flip2
278
289
279 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
290 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
280 # self.dynamic = numpy.array([],numpy.dtype('byte'))
291 # self.dynamic = numpy.array([],numpy.dtype('byte'))
281
292
282 if self.fClock is None and self.deltaHeight is not None:
293 if self.fClock is None and self.deltaHeight is not None:
283 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
294 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
284
295
285 def read(self, fp):
296 def read(self, fp):
286
297
287
298
288 startFp = fp.tell()
299 startFp = fp.tell()
289 try:
300 try:
290 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
301 header = numpy.fromfile(fp,RADAR_STRUCTURE,1)
291 except Exception, e:
302 except Exception, e:
292 print "RadarControllerHeader: " + e
303 print "RadarControllerHeader: " + e
293 return 0
304 return 0
294
305
295 size = int(header['nSize'][0])
306 size = int(header['nSize'][0])
296 self.expType = int(header['nExpType'][0])
307 self.expType = int(header['nExpType'][0])
297 self.nTx = int(header['nNTx'][0])
308 self.nTx = int(header['nNTx'][0])
298 self.ipp = float(header['fIpp'][0])
309 self.ipp = float(header['fIpp'][0])
299 self.txA = float(header['fTxA'][0])
310 self.txA = float(header['fTxA'][0])
300 self.txB = float(header['fTxB'][0])
311 self.txB = float(header['fTxB'][0])
301 self.nWindows = int(header['nNumWindows'][0])
312 self.nWindows = int(header['nNumWindows'][0])
302 self.numTaus = int(header['nNumTaus'][0])
313 self.numTaus = int(header['nNumTaus'][0])
303 self.codeType = int(header['nCodeType'][0])
314 self.codeType = int(header['nCodeType'][0])
304 self.line6Function = int(header['nLine6Function'][0])
315 self.line6Function = int(header['nLine6Function'][0])
305 self.line5Function = int(header['nLine5Function'][0])
316 self.line5Function = int(header['nLine5Function'][0])
306 self.fClock = float(header['fClock'][0])
317 self.fClock = float(header['fClock'][0])
307 self.prePulseBefore = int(header['nPrePulseBefore'][0])
318 self.prePulseBefore = int(header['nPrePulseBefore'][0])
308 self.prePulserAfter = int(header['nPrePulseAfter'][0])
319 self.prePulserAfter = int(header['nPrePulseAfter'][0])
309 self.rangeIpp = header['sRangeIPP'][0]
320 self.rangeIpp = header['sRangeIPP'][0]
310 self.rangeTxA = header['sRangeTxA'][0]
321 self.rangeTxA = header['sRangeTxA'][0]
311 self.rangeTxB = header['sRangeTxB'][0]
322 self.rangeTxB = header['sRangeTxB'][0]
312
323
313 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
324 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
314
325
315 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
326 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
316 self.firstHeight = samplingWindow['h0']
327 self.firstHeight = samplingWindow['h0']
317 self.deltaHeight = samplingWindow['dh']
328 self.deltaHeight = samplingWindow['dh']
318 self.samplesWin = samplingWindow['nsa']
329 self.samplesWin = samplingWindow['nsa']
319
330
320 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
331 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
321
332
322 self.code_size = 0
333 self.code_size = 0
323 if self.codeType != 0:
334 if self.codeType != 0:
324 self.nCode = int(numpy.fromfile(fp,'<u4',1))
335 self.nCode = int(numpy.fromfile(fp,'<u4',1))
325 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
336 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
326
337
327 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
338 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
328 for ic in range(self.nCode):
339 for ic in range(self.nCode):
329 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
340 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
330 for ib in range(self.nBaud-1,-1,-1):
341 for ib in range(self.nBaud-1,-1,-1):
331 code[ic,ib] = temp[ib/32]%2
342 code[ic,ib] = temp[ib/32]%2
332 temp[ib/32] = temp[ib/32]/2
343 temp[ib/32] = temp[ib/32]/2
333
344
334 self.code = 2.0*code - 1.0
345 self.code = 2.0*code - 1.0
335 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
346 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
336
347
337 # if self.line5Function == RCfunction.FLIP:
348 # if self.line5Function == RCfunction.FLIP:
338 # self.flip1 = numpy.fromfile(fp,'<u4',1)
349 # self.flip1 = numpy.fromfile(fp,'<u4',1)
339 #
350 #
340 # if self.line6Function == RCfunction.FLIP:
351 # if self.line6Function == RCfunction.FLIP:
341 # self.flip2 = numpy.fromfile(fp,'<u4',1)
352 # self.flip2 = numpy.fromfile(fp,'<u4',1)
342
353
343 endFp = size + startFp
354 endFp = size + startFp
344
355
345 if fp.tell() != endFp:
356 if fp.tell() != endFp:
346 # fp.seek(endFp)
357 # fp.seek(endFp)
347 print "Radar Controller Header is not consistent read[%d] != header[%d]" %(fp.tell()-startFp,endFp)
358 print "Radar Controller Header is not consistent read[%d] != header[%d]" %(fp.tell()-startFp,endFp)
348 # return 0
359 # return 0
349
360
361 if fp.tell() > endFp:
362 sys.stderr.write("Warning: Radar Controller header size is lower than it has to be")
363 # return 0
364
365 if fp.tell() < endFp:
366 sys.stderr.write("Warning: Radar Controller header size is greater than it is considered")
367
368
350 return 1
369 return 1
351
370
352 def write(self, fp):
371 def write(self, fp):
353
372
354 headerTuple = (self.size,
373 headerTuple = (self.size,
355 self.expType,
374 self.expType,
356 self.nTx,
375 self.nTx,
357 self.ipp,
376 self.ipp,
358 self.txA,
377 self.txA,
359 self.txB,
378 self.txB,
360 self.nWindows,
379 self.nWindows,
361 self.numTaus,
380 self.numTaus,
362 self.codeType,
381 self.codeType,
363 self.line6Function,
382 self.line6Function,
364 self.line5Function,
383 self.line5Function,
365 self.fClock,
384 self.fClock,
366 self.prePulseBefore,
385 self.prePulseBefore,
367 self.prePulserAfter,
386 self.prePulserAfter,
368 self.rangeIpp,
387 self.rangeIpp,
369 self.rangeTxA,
388 self.rangeTxA,
370 self.rangeTxB)
389 self.rangeTxB)
371
390
372 header = numpy.array(headerTuple,RADAR_STRUCTURE)
391 header = numpy.array(headerTuple,RADAR_STRUCTURE)
373 header.tofile(fp)
392 header.tofile(fp)
374
393
375 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
394 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
376 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
395 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
377 samplingWindow.tofile(fp)
396 samplingWindow.tofile(fp)
378
397
379 if self.numTaus > 0:
398 if self.numTaus > 0:
380 self.Taus.tofile(fp)
399 self.Taus.tofile(fp)
381
400
382 if self.codeType !=0:
401 if self.codeType !=0:
383 nCode = numpy.array(self.nCode, '<u4')
402 nCode = numpy.array(self.nCode, '<u4')
384 nCode.tofile(fp)
403 nCode.tofile(fp)
385 nBaud = numpy.array(self.nBaud, '<u4')
404 nBaud = numpy.array(self.nBaud, '<u4')
386 nBaud.tofile(fp)
405 nBaud.tofile(fp)
387 code1 = (self.code + 1.0)/2.
406 code1 = (self.code + 1.0)/2.
388
407
389 for ic in range(self.nCode):
408 for ic in range(self.nCode):
390 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
409 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
391 start = 0
410 start = 0
392 end = 32
411 end = 32
393 for i in range(len(tempx)):
412 for i in range(len(tempx)):
394 code_selected = code1[ic,start:end]
413 code_selected = code1[ic,start:end]
395 for j in range(len(code_selected)-1,-1,-1):
414 for j in range(len(code_selected)-1,-1,-1):
396 if code_selected[j] == 1:
415 if code_selected[j] == 1:
397 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
416 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
398 start = start + 32
417 start = start + 32
399 end = end + 32
418 end = end + 32
400
419
401 tempx = tempx.astype('u4')
420 tempx = tempx.astype('u4')
402 tempx.tofile(fp)
421 tempx.tofile(fp)
403
422
404 # if self.line5Function == RCfunction.FLIP:
423 # if self.line5Function == RCfunction.FLIP:
405 # self.flip1.tofile(fp)
424 # self.flip1.tofile(fp)
406 #
425 #
407 # if self.line6Function == RCfunction.FLIP:
426 # if self.line6Function == RCfunction.FLIP:
408 # self.flip2.tofile(fp)
427 # self.flip2.tofile(fp)
409
428
410 return 1
429 return 1
411
430
412 def get_ippSeconds(self):
431 def get_ippSeconds(self):
413 '''
432 '''
414 '''
433 '''
415 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
434 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
416
435
417 return ippSeconds
436 return ippSeconds
418
437
419 def set_ippSeconds(self, ippSeconds):
438 def set_ippSeconds(self, ippSeconds):
420 '''
439 '''
421 '''
440 '''
422
441
423 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
442 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
424
443
425 return
444 return
426
445
427 def get_size(self):
446 def get_size(self):
428
447
429 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
448 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
430
449
431 if self.codeType != 0:
450 if self.codeType != 0:
432 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
451 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
433
452
434 return self.__size
453 return self.__size
435
454
436 def set_size(self, value):
455 def set_size(self, value):
437
456
438 self.__size = value
457 raise IOError, "size is a property and it cannot be set, just read"
439
458
440 return
459 return
441
460
442 ippSeconds = property(get_ippSeconds, set_ippSeconds)
461 ippSeconds = property(get_ippSeconds, set_ippSeconds)
443 size = property(get_size, set_size)
462 size = property(get_size, set_size)
444
463
445 class ProcessingHeader(Header):
464 class ProcessingHeader(Header):
446
465
447 # size = None
466 # size = None
448 dtype = None
467 dtype = None
449 blockSize = None
468 blockSize = None
450 profilesPerBlock = None
469 profilesPerBlock = None
451 dataBlocksPerFile = None
470 dataBlocksPerFile = None
452 nWindows = None
471 nWindows = None
453 processFlags = None
472 processFlags = None
454 nCohInt = None
473 nCohInt = None
455 nIncohInt = None
474 nIncohInt = None
456 totalSpectra = None
475 totalSpectra = None
457
476
458 flag_dc = None
477 flag_dc = None
459 flag_cspc = None
478 flag_cspc = None
460
479
461 def __init__(self):
480 def __init__(self):
462
481
463 # self.size = 0
482 # self.size = 0
464 self.dtype = 0
483 self.dtype = 0
465 self.blockSize = 0
484 self.blockSize = 0
466 self.profilesPerBlock = 0
485 self.profilesPerBlock = 0
467 self.dataBlocksPerFile = 0
486 self.dataBlocksPerFile = 0
468 self.nWindows = 0
487 self.nWindows = 0
469 self.processFlags = 0
488 self.processFlags = 0
470 self.nCohInt = 0
489 self.nCohInt = 0
471 self.nIncohInt = 0
490 self.nIncohInt = 0
472 self.totalSpectra = 0
491 self.totalSpectra = 0
473
492
474 self.nHeights = 0
493 self.nHeights = 0
475 self.firstHeight = 0
494 self.firstHeight = 0
476 self.deltaHeight = 0
495 self.deltaHeight = 0
477 self.samplesWin = 0
496 self.samplesWin = 0
478 self.spectraComb = 0
497 self.spectraComb = 0
479 self.nCode = None
498 self.nCode = None
480 self.code = None
499 self.code = None
481 self.nBaud = None
500 self.nBaud = None
482
501
483 self.shif_fft = False
502 self.shif_fft = False
484 self.flag_dc = False
503 self.flag_dc = False
485 self.flag_cspc = False
504 self.flag_cspc = False
486 self.flag_decode = False
505 self.flag_decode = False
487 self.flag_deflip = False
506 self.flag_deflip = False
488
507
489 def read(self, fp):
508 def read(self, fp):
490
509
491 startFp = fp.tell()
510 startFp = fp.tell()
492
511
493 try:
512 try:
494 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
513 header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1)
495 except Exception, e:
514 except Exception, e:
496 print "ProcessingHeader: " + e
515 print "ProcessingHeader: " + e
497 return 0
516 return 0
498
517
499 size = int(header['nSize'][0])
518 size = int(header['nSize'][0])
500 self.dtype = int(header['nDataType'][0])
519 self.dtype = int(header['nDataType'][0])
501 self.blockSize = int(header['nSizeOfDataBlock'][0])
520 self.blockSize = int(header['nSizeOfDataBlock'][0])
502 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
521 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
503 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
522 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
504 self.nWindows = int(header['nNumWindows'][0])
523 self.nWindows = int(header['nNumWindows'][0])
505 self.processFlags = header['nProcessFlags']
524 self.processFlags = header['nProcessFlags']
506 self.nCohInt = int(header['nCoherentIntegrations'][0])
525 self.nCohInt = int(header['nCoherentIntegrations'][0])
507 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
526 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
508 self.totalSpectra = int(header['nTotalSpectra'][0])
527 self.totalSpectra = int(header['nTotalSpectra'][0])
509
528
510 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
529 samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows)
511
530
512 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
531 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
513 self.firstHeight = float(samplingWindow['h0'][0])
532 self.firstHeight = float(samplingWindow['h0'][0])
514 self.deltaHeight = float(samplingWindow['dh'][0])
533 self.deltaHeight = float(samplingWindow['dh'][0])
515 self.samplesWin = samplingWindow['nsa'][0]
534 self.samplesWin = samplingWindow['nsa'][0]
516
535
517 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
536 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
518
537
519 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
538 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
520 self.nCode = int(numpy.fromfile(fp,'<u4',1))
539 self.nCode = int(numpy.fromfile(fp,'<u4',1))
521 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
540 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
522 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
541 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
523
542
524 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
543 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
525 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
544 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
526 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
545 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
527
546
528 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
547 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
529 self.shif_fft = True
548 self.shif_fft = True
530 else:
549 else:
531 self.shif_fft = False
550 self.shif_fft = False
532
551
533 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
552 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
534 self.flag_dc = True
553 self.flag_dc = True
535 else:
554 else:
536 self.flag_dc = False
555 self.flag_dc = False
537
556
538 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
557 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
539 self.flag_decode = True
558 self.flag_decode = True
540 else:
559 else:
541 self.flag_decode = False
560 self.flag_decode = False
542
561
543 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
562 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
544 self.flag_deflip = True
563 self.flag_deflip = True
545 else:
564 else:
546 self.flag_deflip = False
565 self.flag_deflip = False
547
566
548 nChannels = 0
567 nChannels = 0
549 nPairs = 0
568 nPairs = 0
550 pairList = []
569 pairList = []
551
570
552 for i in range( 0, self.totalSpectra*2, 2 ):
571 for i in range( 0, self.totalSpectra*2, 2 ):
553 if self.spectraComb[i] == self.spectraComb[i+1]:
572 if self.spectraComb[i] == self.spectraComb[i+1]:
554 nChannels = nChannels + 1 #par de canales iguales
573 nChannels = nChannels + 1 #par de canales iguales
555 else:
574 else:
556 nPairs = nPairs + 1 #par de canales diferentes
575 nPairs = nPairs + 1 #par de canales diferentes
557 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
576 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
558
577
559 self.flag_cspc = False
578 self.flag_cspc = False
560 if nPairs > 0:
579 if nPairs > 0:
561 self.flag_cspc = True
580 self.flag_cspc = True
562
581
563 endFp = size + startFp
582 endFp = size + startFp
564
583
565 if fp.tell() != endFp:
584 if fp.tell() > endFp:
566 print "Processing Header is not consistent"
585 sys.stderr.write("Warning: Processing header size is lower than it has to be")
567 return 0
586 return 0
587
588 if fp.tell() < endFp:
589 sys.stderr.write("Warning: Processing header size is greater than it is considered")
568
590
569 return 1
591 return 1
570
592
571 def write(self, fp):
593 def write(self, fp):
572 #Clear DEFINE_PROCESS_CODE
594 #Clear DEFINE_PROCESS_CODE
573 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
595 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
574
596
575 headerTuple = (self.size,
597 headerTuple = (self.size,
576 self.dtype,
598 self.dtype,
577 self.blockSize,
599 self.blockSize,
578 self.profilesPerBlock,
600 self.profilesPerBlock,
579 self.dataBlocksPerFile,
601 self.dataBlocksPerFile,
580 self.nWindows,
602 self.nWindows,
581 self.processFlags,
603 self.processFlags,
582 self.nCohInt,
604 self.nCohInt,
583 self.nIncohInt,
605 self.nIncohInt,
584 self.totalSpectra)
606 self.totalSpectra)
585
607
586 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
608 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
587 header.tofile(fp)
609 header.tofile(fp)
588
610
589 if self.nWindows != 0:
611 if self.nWindows != 0:
590 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
612 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
591 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
613 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
592 samplingWindow.tofile(fp)
614 samplingWindow.tofile(fp)
593
615
594 if self.totalSpectra != 0:
616 if self.totalSpectra != 0:
595 # spectraComb = numpy.array([],numpy.dtype('u1'))
617 # spectraComb = numpy.array([],numpy.dtype('u1'))
596 spectraComb = self.spectraComb
618 spectraComb = self.spectraComb
597 spectraComb.tofile(fp)
619 spectraComb.tofile(fp)
598
620
599 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
621 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
600 nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
622 nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
601 nCode.tofile(fp)
623 nCode.tofile(fp)
602
624
603 nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
625 nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
604 nBaud.tofile(fp)
626 nBaud.tofile(fp)
605
627
606 code = self.code.reshape(self.nCode*self.nBaud)
628 code = self.code.reshape(self.nCode*self.nBaud)
607 code = code.astype(numpy.dtype('<f4'))
629 code = code.astype(numpy.dtype('<f4'))
608 code.tofile(fp)
630 code.tofile(fp)
609
631
610 return 1
632 return 1
611
633
612 def get_size(self):
634 def get_size(self):
613
635
614 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
636 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
615
637
616 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
638 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
617 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
639 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
618 self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
640 self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
619
641
620 return self.__size
642 return self.__size
621
643
622 def set_size(self, value):
644 def set_size(self, value):
623
645
624 self.__size = value
646 raise IOError, "size is a property and it cannot be set, just read"
625
647
626 return
648 return
627
649
628 size = property(get_size, set_size)
650 size = property(get_size, set_size)
629
651
630 class RCfunction:
652 class RCfunction:
631 NONE=0
653 NONE=0
632 FLIP=1
654 FLIP=1
633 CODE=2
655 CODE=2
634 SAMPLING=3
656 SAMPLING=3
635 LIN6DIV256=4
657 LIN6DIV256=4
636 SYNCHRO=5
658 SYNCHRO=5
637
659
638 class nCodeType:
660 class nCodeType:
639 NONE=0
661 NONE=0
640 USERDEFINE=1
662 USERDEFINE=1
641 BARKER2=2
663 BARKER2=2
642 BARKER3=3
664 BARKER3=3
643 BARKER4=4
665 BARKER4=4
644 BARKER5=5
666 BARKER5=5
645 BARKER7=6
667 BARKER7=6
646 BARKER11=7
668 BARKER11=7
647 BARKER13=8
669 BARKER13=8
648 AC128=9
670 AC128=9
649 COMPLEMENTARYCODE2=10
671 COMPLEMENTARYCODE2=10
650 COMPLEMENTARYCODE4=11
672 COMPLEMENTARYCODE4=11
651 COMPLEMENTARYCODE8=12
673 COMPLEMENTARYCODE8=12
652 COMPLEMENTARYCODE16=13
674 COMPLEMENTARYCODE16=13
653 COMPLEMENTARYCODE32=14
675 COMPLEMENTARYCODE32=14
654 COMPLEMENTARYCODE64=15
676 COMPLEMENTARYCODE64=15
655 COMPLEMENTARYCODE128=16
677 COMPLEMENTARYCODE128=16
656 CODE_BINARY28=17
678 CODE_BINARY28=17
657
679
658 class PROCFLAG:
680 class PROCFLAG:
659
681
660 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
682 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
661 DECODE_DATA = numpy.uint32(0x00000002)
683 DECODE_DATA = numpy.uint32(0x00000002)
662 SPECTRA_CALC = numpy.uint32(0x00000004)
684 SPECTRA_CALC = numpy.uint32(0x00000004)
663 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
685 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
664 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
686 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
665 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
687 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
666
688
667 DATATYPE_CHAR = numpy.uint32(0x00000040)
689 DATATYPE_CHAR = numpy.uint32(0x00000040)
668 DATATYPE_SHORT = numpy.uint32(0x00000080)
690 DATATYPE_SHORT = numpy.uint32(0x00000080)
669 DATATYPE_LONG = numpy.uint32(0x00000100)
691 DATATYPE_LONG = numpy.uint32(0x00000100)
670 DATATYPE_INT64 = numpy.uint32(0x00000200)
692 DATATYPE_INT64 = numpy.uint32(0x00000200)
671 DATATYPE_FLOAT = numpy.uint32(0x00000400)
693 DATATYPE_FLOAT = numpy.uint32(0x00000400)
672 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
694 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
673
695
674 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
696 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
675 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
697 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
676 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
698 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
677
699
678 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
700 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
679 DEFLIP_DATA = numpy.uint32(0x00010000)
701 DEFLIP_DATA = numpy.uint32(0x00010000)
680 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
702 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
681
703
682 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
704 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
683 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
705 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
684 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
706 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
685 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
707 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
686 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
708 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
687
709
688 EXP_NAME_ESP = numpy.uint32(0x00200000)
710 EXP_NAME_ESP = numpy.uint32(0x00200000)
689 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
711 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
690
712
691 OPERATION_MASK = numpy.uint32(0x0000003F)
713 OPERATION_MASK = numpy.uint32(0x0000003F)
692 DATATYPE_MASK = numpy.uint32(0x00000FC0)
714 DATATYPE_MASK = numpy.uint32(0x00000FC0)
693 DATAARRANGE_MASK = numpy.uint32(0x00007000)
715 DATAARRANGE_MASK = numpy.uint32(0x00007000)
694 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
716 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
695
717
696 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
718 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
697 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
719 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
698 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
720 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
699 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
721 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
700 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
722 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
701 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
723 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
702
724
703 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
725 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
704
726
705 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
727 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
706 PROCFLAG.DATATYPE_SHORT,
728 PROCFLAG.DATATYPE_SHORT,
707 PROCFLAG.DATATYPE_LONG,
729 PROCFLAG.DATATYPE_LONG,
708 PROCFLAG.DATATYPE_INT64,
730 PROCFLAG.DATATYPE_INT64,
709 PROCFLAG.DATATYPE_FLOAT,
731 PROCFLAG.DATATYPE_FLOAT,
710 PROCFLAG.DATATYPE_DOUBLE]
732 PROCFLAG.DATATYPE_DOUBLE]
711
733
712 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
734 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
713
735
714 def get_dtype_index(numpy_dtype):
736 def get_dtype_index(numpy_dtype):
715
737
716 index = None
738 index = None
717
739
718 for i in range(len(NUMPY_DTYPE_LIST)):
740 for i in range(len(NUMPY_DTYPE_LIST)):
719 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
741 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
720 index = i
742 index = i
721 break
743 break
722
744
723 return index
745 return index
724
746
725 def get_numpy_dtype(index):
747 def get_numpy_dtype(index):
726
748
727 return NUMPY_DTYPE_LIST[index]
749 return NUMPY_DTYPE_LIST[index]
728
750
729 def get_procflag_dtype(index):
751 def get_procflag_dtype(index):
730
752
731 return PROCFLAG_DTYPE_LIST[index]
753 return PROCFLAG_DTYPE_LIST[index]
732
754
733 def get_dtype_width(index):
755 def get_dtype_width(index):
734
756
735 return DTYPE_WIDTH[index] No newline at end of file
757 return DTYPE_WIDTH[index]
General Comments 0
You need to be logged in to leave comments. Login now