##// END OF EJS Templates
Se corrige arreglo del codigo para la decodificacion, el codigo no era el correcto por uns problema de interpretacion del LSB y MSB. Este error fue evidente en el Experimento MST-ISR-EEJ.
Daniel Valdez -
r432:22d78702ca73
parent child
Show More
@@ -1,534 +1,535
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 sys
6 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10
10
11 class Header:
11 class Header:
12
12
13 def __init__(self):
13 def __init__(self):
14 raise
14 raise
15
15
16 def copy(self):
16 def copy(self):
17 return copy.deepcopy(self)
17 return copy.deepcopy(self)
18
18
19 def read():
19 def read():
20 pass
20 pass
21
21
22 def write():
22 def write():
23 pass
23 pass
24
24
25 def printInfo(self):
25 def printInfo(self):
26
26
27 print "#"*100
27 print "#"*100
28 print self.__class__.__name__.upper()
28 print self.__class__.__name__.upper()
29 print "#"*100
29 print "#"*100
30 for key in self.__dict__.keys():
30 for key in self.__dict__.keys():
31 print "%s = %s" %(key, self.__dict__[key])
31 print "%s = %s" %(key, self.__dict__[key])
32
32
33 class BasicHeader(Header):
33 class BasicHeader(Header):
34
34
35 size = None
35 size = None
36 version = None
36 version = None
37 dataBlock = None
37 dataBlock = None
38 utc = None
38 utc = None
39 ltc = None
39 ltc = None
40 miliSecond = None
40 miliSecond = None
41 timeZone = None
41 timeZone = None
42 dstFlag = None
42 dstFlag = None
43 errorCount = None
43 errorCount = None
44 struct = None
44 struct = None
45 datatime = None
45 datatime = None
46
46
47 __LOCALTIME = None
47 __LOCALTIME = None
48
48
49 def __init__(self, useLocalTime=True):
49 def __init__(self, useLocalTime=True):
50
50
51 self.size = 0
51 self.size = 0
52 self.version = 0
52 self.version = 0
53 self.dataBlock = 0
53 self.dataBlock = 0
54 self.utc = 0
54 self.utc = 0
55 self.miliSecond = 0
55 self.miliSecond = 0
56 self.timeZone = 0
56 self.timeZone = 0
57 self.dstFlag = 0
57 self.dstFlag = 0
58 self.errorCount = 0
58 self.errorCount = 0
59 self.struct = numpy.dtype([
59 self.struct = numpy.dtype([
60 ('nSize','<u4'),
60 ('nSize','<u4'),
61 ('nVersion','<u2'),
61 ('nVersion','<u2'),
62 ('nDataBlockId','<u4'),
62 ('nDataBlockId','<u4'),
63 ('nUtime','<u4'),
63 ('nUtime','<u4'),
64 ('nMilsec','<u2'),
64 ('nMilsec','<u2'),
65 ('nTimezone','<i2'),
65 ('nTimezone','<i2'),
66 ('nDstflag','<i2'),
66 ('nDstflag','<i2'),
67 ('nErrorCount','<u4')
67 ('nErrorCount','<u4')
68 ])
68 ])
69
69
70 self.useLocalTime = useLocalTime
70 self.useLocalTime = useLocalTime
71
71
72 def read(self, fp):
72 def read(self, fp):
73 try:
73 try:
74 header = numpy.fromfile(fp, self.struct,1)
74 header = numpy.fromfile(fp, self.struct,1)
75 self.size = int(header['nSize'][0])
75 self.size = int(header['nSize'][0])
76 self.version = int(header['nVersion'][0])
76 self.version = int(header['nVersion'][0])
77 self.dataBlock = int(header['nDataBlockId'][0])
77 self.dataBlock = int(header['nDataBlockId'][0])
78 self.utc = int(header['nUtime'][0])
78 self.utc = int(header['nUtime'][0])
79 self.miliSecond = int(header['nMilsec'][0])
79 self.miliSecond = int(header['nMilsec'][0])
80 self.timeZone = int(header['nTimezone'][0])
80 self.timeZone = int(header['nTimezone'][0])
81 self.dstFlag = int(header['nDstflag'][0])
81 self.dstFlag = int(header['nDstflag'][0])
82 self.errorCount = int(header['nErrorCount'][0])
82 self.errorCount = int(header['nErrorCount'][0])
83
83
84 self.ltc = self.utc
84 self.ltc = self.utc
85
85
86 if self.useLocalTime:
86 if self.useLocalTime:
87 self.ltc -= self.timeZone*60
87 self.ltc -= self.timeZone*60
88
88
89 self.datatime = datetime.datetime.utcfromtimestamp(self.ltc)
89 self.datatime = datetime.datetime.utcfromtimestamp(self.ltc)
90
90
91 except Exception, e:
91 except Exception, e:
92 print "BasicHeader: "
92 print "BasicHeader: "
93 print e
93 print e
94 return 0
94 return 0
95
95
96 return 1
96 return 1
97
97
98 def write(self, fp):
98 def write(self, fp):
99
99
100 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
100 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
101 header = numpy.array(headerTuple,self.struct)
101 header = numpy.array(headerTuple,self.struct)
102 header.tofile(fp)
102 header.tofile(fp)
103
103
104 return 1
104 return 1
105
105
106 class SystemHeader(Header):
106 class SystemHeader(Header):
107
107
108 size = None
108 size = None
109 nSamples = None
109 nSamples = None
110 nProfiles = None
110 nProfiles = None
111 nChannels = None
111 nChannels = None
112 adcResolution = None
112 adcResolution = None
113 pciDioBusWidth = None
113 pciDioBusWidth = None
114 struct = None
114 struct = None
115
115
116 def __init__(self):
116 def __init__(self):
117 self.size = 0
117 self.size = 0
118 self.nSamples = 0
118 self.nSamples = 0
119 self.nProfiles = 0
119 self.nProfiles = 0
120 self.nChannels = 0
120 self.nChannels = 0
121 self.adcResolution = 0
121 self.adcResolution = 0
122 self.pciDioBusWidth = 0
122 self.pciDioBusWidth = 0
123 self.struct = numpy.dtype([
123 self.struct = numpy.dtype([
124 ('nSize','<u4'),
124 ('nSize','<u4'),
125 ('nNumSamples','<u4'),
125 ('nNumSamples','<u4'),
126 ('nNumProfiles','<u4'),
126 ('nNumProfiles','<u4'),
127 ('nNumChannels','<u4'),
127 ('nNumChannels','<u4'),
128 ('nADCResolution','<u4'),
128 ('nADCResolution','<u4'),
129 ('nPCDIOBusWidth','<u4'),
129 ('nPCDIOBusWidth','<u4'),
130 ])
130 ])
131
131
132
132
133 def read(self, fp):
133 def read(self, fp):
134 try:
134 try:
135 header = numpy.fromfile(fp,self.struct,1)
135 header = numpy.fromfile(fp,self.struct,1)
136 self.size = header['nSize'][0]
136 self.size = header['nSize'][0]
137 self.nSamples = header['nNumSamples'][0]
137 self.nSamples = header['nNumSamples'][0]
138 self.nProfiles = header['nNumProfiles'][0]
138 self.nProfiles = header['nNumProfiles'][0]
139 self.nChannels = header['nNumChannels'][0]
139 self.nChannels = header['nNumChannels'][0]
140 self.adcResolution = header['nADCResolution'][0]
140 self.adcResolution = header['nADCResolution'][0]
141 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
141 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
142
142
143 except Exception, e:
143 except Exception, e:
144 print "SystemHeader: " + e
144 print "SystemHeader: " + e
145 return 0
145 return 0
146
146
147 return 1
147 return 1
148
148
149 def write(self, fp):
149 def write(self, fp):
150 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
150 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
151 header = numpy.array(headerTuple,self.struct)
151 header = numpy.array(headerTuple,self.struct)
152 header.tofile(fp)
152 header.tofile(fp)
153
153
154 return 1
154 return 1
155
155
156 class RadarControllerHeader(Header):
156 class RadarControllerHeader(Header):
157
157
158 size = None
158 size = None
159 expType = None
159 expType = None
160 nTx = None
160 nTx = None
161 ipp = None
161 ipp = None
162 txA = None
162 txA = None
163 txB = None
163 txB = None
164 nWindows = None
164 nWindows = None
165 numTaus = None
165 numTaus = None
166 codeType = None
166 codeType = None
167 line6Function = None
167 line6Function = None
168 line5Function = None
168 line5Function = None
169 fClock = None
169 fClock = None
170 prePulseBefore = None
170 prePulseBefore = None
171 prePulserAfter = None
171 prePulserAfter = None
172 rangeIpp = None
172 rangeIpp = None
173 rangeTxA = None
173 rangeTxA = None
174 rangeTxB = None
174 rangeTxB = None
175 struct = None
175 struct = None
176
176
177 def __init__(self):
177 def __init__(self):
178 self.size = 0
178 self.size = 0
179 self.expType = 0
179 self.expType = 0
180 self.nTx = 0
180 self.nTx = 0
181 self.ipp = 0
181 self.ipp = 0
182 self.txA = 0
182 self.txA = 0
183 self.txB = 0
183 self.txB = 0
184 self.nWindows = 0
184 self.nWindows = 0
185 self.numTaus = 0
185 self.numTaus = 0
186 self.codeType = 0
186 self.codeType = 0
187 self.line6Function = 0
187 self.line6Function = 0
188 self.line5Function = 0
188 self.line5Function = 0
189 self.fClock = 0
189 self.fClock = 0
190 self.prePulseBefore = 0
190 self.prePulseBefore = 0
191 self.prePulserAfter = 0
191 self.prePulserAfter = 0
192 self.rangeIpp = 0
192 self.rangeIpp = 0
193 self.rangeTxA = 0
193 self.rangeTxA = 0
194 self.rangeTxB = 0
194 self.rangeTxB = 0
195 self.struct = numpy.dtype([
195 self.struct = numpy.dtype([
196 ('nSize','<u4'),
196 ('nSize','<u4'),
197 ('nExpType','<u4'),
197 ('nExpType','<u4'),
198 ('nNTx','<u4'),
198 ('nNTx','<u4'),
199 ('fIpp','<f4'),
199 ('fIpp','<f4'),
200 ('fTxA','<f4'),
200 ('fTxA','<f4'),
201 ('fTxB','<f4'),
201 ('fTxB','<f4'),
202 ('nNumWindows','<u4'),
202 ('nNumWindows','<u4'),
203 ('nNumTaus','<u4'),
203 ('nNumTaus','<u4'),
204 ('nCodeType','<u4'),
204 ('nCodeType','<u4'),
205 ('nLine6Function','<u4'),
205 ('nLine6Function','<u4'),
206 ('nLine5Function','<u4'),
206 ('nLine5Function','<u4'),
207 ('fClock','<f4'),
207 ('fClock','<f4'),
208 ('nPrePulseBefore','<u4'),
208 ('nPrePulseBefore','<u4'),
209 ('nPrePulseAfter','<u4'),
209 ('nPrePulseAfter','<u4'),
210 ('sRangeIPP','<a20'),
210 ('sRangeIPP','<a20'),
211 ('sRangeTxA','<a20'),
211 ('sRangeTxA','<a20'),
212 ('sRangeTxB','<a20'),
212 ('sRangeTxB','<a20'),
213 ])
213 ])
214
214
215 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
215 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
216
216
217 self.samplingWindow = None
217 self.samplingWindow = None
218 self.nHeights = None
218 self.nHeights = None
219 self.firstHeight = None
219 self.firstHeight = None
220 self.deltaHeight = None
220 self.deltaHeight = None
221 self.samplesWin = None
221 self.samplesWin = None
222
222
223 self.nCode = None
223 self.nCode = None
224 self.nBaud = None
224 self.nBaud = None
225 self.code = None
225 self.code = None
226 self.flip1 = None
226 self.flip1 = None
227 self.flip2 = None
227 self.flip2 = None
228
228
229 self.dynamic = numpy.array([],numpy.dtype('byte'))
229 self.dynamic = numpy.array([],numpy.dtype('byte'))
230
230
231
231
232 def read(self, fp):
232 def read(self, fp):
233 try:
233 try:
234 startFp = fp.tell()
234 startFp = fp.tell()
235 header = numpy.fromfile(fp,self.struct,1)
235 header = numpy.fromfile(fp,self.struct,1)
236 self.size = int(header['nSize'][0])
236 self.size = int(header['nSize'][0])
237 self.expType = int(header['nExpType'][0])
237 self.expType = int(header['nExpType'][0])
238 self.nTx = int(header['nNTx'][0])
238 self.nTx = int(header['nNTx'][0])
239 self.ipp = float(header['fIpp'][0])
239 self.ipp = float(header['fIpp'][0])
240 self.txA = float(header['fTxA'][0])
240 self.txA = float(header['fTxA'][0])
241 self.txB = float(header['fTxB'][0])
241 self.txB = float(header['fTxB'][0])
242 self.nWindows = int(header['nNumWindows'][0])
242 self.nWindows = int(header['nNumWindows'][0])
243 self.numTaus = int(header['nNumTaus'][0])
243 self.numTaus = int(header['nNumTaus'][0])
244 self.codeType = int(header['nCodeType'][0])
244 self.codeType = int(header['nCodeType'][0])
245 self.line6Function = int(header['nLine6Function'][0])
245 self.line6Function = int(header['nLine6Function'][0])
246 self.line5Function = int(header['nLine5Function'][0])
246 self.line5Function = int(header['nLine5Function'][0])
247 self.fClock = float(header['fClock'][0])
247 self.fClock = float(header['fClock'][0])
248 self.prePulseBefore = int(header['nPrePulseBefore'][0])
248 self.prePulseBefore = int(header['nPrePulseBefore'][0])
249 self.prePulserAfter = int(header['nPrePulseAfter'][0])
249 self.prePulserAfter = int(header['nPrePulseAfter'][0])
250 self.rangeIpp = header['sRangeIPP'][0]
250 self.rangeIpp = header['sRangeIPP'][0]
251 self.rangeTxA = header['sRangeTxA'][0]
251 self.rangeTxA = header['sRangeTxA'][0]
252 self.rangeTxB = header['sRangeTxB'][0]
252 self.rangeTxB = header['sRangeTxB'][0]
253 # jump Dynamic Radar Controller Header
253 # jump Dynamic Radar Controller Header
254 jumpFp = self.size - 116
254 jumpFp = self.size - 116
255 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
255 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
256 #pointer backward to dynamic header and read
256 #pointer backward to dynamic header and read
257 backFp = fp.tell() - jumpFp
257 backFp = fp.tell() - jumpFp
258 fp.seek(backFp)
258 fp.seek(backFp)
259
259
260 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
260 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows)
261 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
261 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
262 self.firstHeight = self.samplingWindow['h0']
262 self.firstHeight = self.samplingWindow['h0']
263 self.deltaHeight = self.samplingWindow['dh']
263 self.deltaHeight = self.samplingWindow['dh']
264 self.samplesWin = self.samplingWindow['nsa']
264 self.samplesWin = self.samplingWindow['nsa']
265
265
266 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
266 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
267
267
268 if self.codeType != 0:
268 if self.codeType != 0:
269 self.nCode = int(numpy.fromfile(fp,'<u4',1))
269 self.nCode = int(numpy.fromfile(fp,'<u4',1))
270 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
270 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
271 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
271 self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1')
272 tempList = []
272
273 for ic in range(self.nCode):
273 for ic in range(self.nCode):
274 temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.)))
274 temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.)))
275 tempList.append(temp)
275 for ib in range(self.nBaud-1,-1,-1):
276 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:]
276 self.code[ic,ib] = temp[ib/32]%2
277 temp[ib/32] = temp[ib/32]/2
277 self.code = 2.0*self.code - 1.0
278 self.code = 2.0*self.code - 1.0
278
279
279 if self.line5Function == RCfunction.FLIP:
280 if self.line5Function == RCfunction.FLIP:
280 self.flip1 = numpy.fromfile(fp,'<u4',1)
281 self.flip1 = numpy.fromfile(fp,'<u4',1)
281
282
282 if self.line6Function == RCfunction.FLIP:
283 if self.line6Function == RCfunction.FLIP:
283 self.flip2 = numpy.fromfile(fp,'<u4',1)
284 self.flip2 = numpy.fromfile(fp,'<u4',1)
284
285
285 endFp = self.size + startFp
286 endFp = self.size + startFp
286 jumpFp = endFp - fp.tell()
287 jumpFp = endFp - fp.tell()
287 if jumpFp > 0:
288 if jumpFp > 0:
288 fp.seek(jumpFp)
289 fp.seek(jumpFp)
289
290
290 except Exception, e:
291 except Exception, e:
291 print "RadarControllerHeader: " + e
292 print "RadarControllerHeader: " + e
292 return 0
293 return 0
293
294
294 return 1
295 return 1
295
296
296 def write(self, fp):
297 def write(self, fp):
297 headerTuple = (self.size,
298 headerTuple = (self.size,
298 self.expType,
299 self.expType,
299 self.nTx,
300 self.nTx,
300 self.ipp,
301 self.ipp,
301 self.txA,
302 self.txA,
302 self.txB,
303 self.txB,
303 self.nWindows,
304 self.nWindows,
304 self.numTaus,
305 self.numTaus,
305 self.codeType,
306 self.codeType,
306 self.line6Function,
307 self.line6Function,
307 self.line5Function,
308 self.line5Function,
308 self.fClock,
309 self.fClock,
309 self.prePulseBefore,
310 self.prePulseBefore,
310 self.prePulserAfter,
311 self.prePulserAfter,
311 self.rangeIpp,
312 self.rangeIpp,
312 self.rangeTxA,
313 self.rangeTxA,
313 self.rangeTxB)
314 self.rangeTxB)
314
315
315 header = numpy.array(headerTuple,self.struct)
316 header = numpy.array(headerTuple,self.struct)
316 header.tofile(fp)
317 header.tofile(fp)
317
318
318 dynamic = self.dynamic
319 dynamic = self.dynamic
319 dynamic.tofile(fp)
320 dynamic.tofile(fp)
320
321
321 return 1
322 return 1
322
323
323
324
324
325
325 class ProcessingHeader(Header):
326 class ProcessingHeader(Header):
326
327
327 size = None
328 size = None
328 dtype = None
329 dtype = None
329 blockSize = None
330 blockSize = None
330 profilesPerBlock = None
331 profilesPerBlock = None
331 dataBlocksPerFile = None
332 dataBlocksPerFile = None
332 nWindows = None
333 nWindows = None
333 processFlags = None
334 processFlags = None
334 nCohInt = None
335 nCohInt = None
335 nIncohInt = None
336 nIncohInt = None
336 totalSpectra = None
337 totalSpectra = None
337 struct = None
338 struct = None
338 flag_dc = None
339 flag_dc = None
339 flag_cspc = None
340 flag_cspc = None
340
341
341 def __init__(self):
342 def __init__(self):
342 self.size = 0
343 self.size = 0
343 self.dtype = 0
344 self.dtype = 0
344 self.blockSize = 0
345 self.blockSize = 0
345 self.profilesPerBlock = 0
346 self.profilesPerBlock = 0
346 self.dataBlocksPerFile = 0
347 self.dataBlocksPerFile = 0
347 self.nWindows = 0
348 self.nWindows = 0
348 self.processFlags = 0
349 self.processFlags = 0
349 self.nCohInt = 0
350 self.nCohInt = 0
350 self.nIncohInt = 0
351 self.nIncohInt = 0
351 self.totalSpectra = 0
352 self.totalSpectra = 0
352 self.struct = numpy.dtype([
353 self.struct = numpy.dtype([
353 ('nSize','<u4'),
354 ('nSize','<u4'),
354 ('nDataType','<u4'),
355 ('nDataType','<u4'),
355 ('nSizeOfDataBlock','<u4'),
356 ('nSizeOfDataBlock','<u4'),
356 ('nProfilesperBlock','<u4'),
357 ('nProfilesperBlock','<u4'),
357 ('nDataBlocksperFile','<u4'),
358 ('nDataBlocksperFile','<u4'),
358 ('nNumWindows','<u4'),
359 ('nNumWindows','<u4'),
359 ('nProcessFlags','<u4'),
360 ('nProcessFlags','<u4'),
360 ('nCoherentIntegrations','<u4'),
361 ('nCoherentIntegrations','<u4'),
361 ('nIncoherentIntegrations','<u4'),
362 ('nIncoherentIntegrations','<u4'),
362 ('nTotalSpectra','<u4')
363 ('nTotalSpectra','<u4')
363 ])
364 ])
364 self.samplingWindow = 0
365 self.samplingWindow = 0
365 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
366 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
366 self.nHeights = 0
367 self.nHeights = 0
367 self.firstHeight = 0
368 self.firstHeight = 0
368 self.deltaHeight = 0
369 self.deltaHeight = 0
369 self.samplesWin = 0
370 self.samplesWin = 0
370 self.spectraComb = 0
371 self.spectraComb = 0
371 self.nCode = None
372 self.nCode = None
372 self.code = None
373 self.code = None
373 self.nBaud = None
374 self.nBaud = None
374 self.shif_fft = False
375 self.shif_fft = False
375 self.flag_dc = False
376 self.flag_dc = False
376 self.flag_cspc = False
377 self.flag_cspc = False
377
378
378 def read(self, fp):
379 def read(self, fp):
379 # try:
380 # try:
380 header = numpy.fromfile(fp,self.struct,1)
381 header = numpy.fromfile(fp,self.struct,1)
381 self.size = int(header['nSize'][0])
382 self.size = int(header['nSize'][0])
382 self.dtype = int(header['nDataType'][0])
383 self.dtype = int(header['nDataType'][0])
383 self.blockSize = int(header['nSizeOfDataBlock'][0])
384 self.blockSize = int(header['nSizeOfDataBlock'][0])
384 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
385 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
385 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
386 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
386 self.nWindows = int(header['nNumWindows'][0])
387 self.nWindows = int(header['nNumWindows'][0])
387 self.processFlags = header['nProcessFlags']
388 self.processFlags = header['nProcessFlags']
388 self.nCohInt = int(header['nCoherentIntegrations'][0])
389 self.nCohInt = int(header['nCoherentIntegrations'][0])
389 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
390 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
390 self.totalSpectra = int(header['nTotalSpectra'][0])
391 self.totalSpectra = int(header['nTotalSpectra'][0])
391 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
392 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows)
392 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
393 self.nHeights = int(numpy.sum(self.samplingWindow['nsa']))
393 self.firstHeight = float(self.samplingWindow['h0'][0])
394 self.firstHeight = float(self.samplingWindow['h0'][0])
394 self.deltaHeight = float(self.samplingWindow['dh'][0])
395 self.deltaHeight = float(self.samplingWindow['dh'][0])
395 self.samplesWin = self.samplingWindow['nsa']
396 self.samplesWin = self.samplingWindow['nsa']
396 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
397 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
397
398
398 # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
399 # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
399 # self.nCode = int(numpy.fromfile(fp,'<u4',1))
400 # self.nCode = int(numpy.fromfile(fp,'<u4',1))
400 # self.nBaud = int(numpy.fromfile(fp,'<u4',1))
401 # self.nBaud = int(numpy.fromfile(fp,'<u4',1))
401 # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
402 # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
402
403
403 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
404 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
404 self.shif_fft = True
405 self.shif_fft = True
405 else:
406 else:
406 self.shif_fft = False
407 self.shif_fft = False
407
408
408 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
409 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
409 self.flag_dc = True
410 self.flag_dc = True
410
411
411 nChannels = 0
412 nChannels = 0
412 nPairs = 0
413 nPairs = 0
413 pairList = []
414 pairList = []
414
415
415 for i in range( 0, self.totalSpectra*2, 2 ):
416 for i in range( 0, self.totalSpectra*2, 2 ):
416 if self.spectraComb[i] == self.spectraComb[i+1]:
417 if self.spectraComb[i] == self.spectraComb[i+1]:
417 nChannels = nChannels + 1 #par de canales iguales
418 nChannels = nChannels + 1 #par de canales iguales
418 else:
419 else:
419 nPairs = nPairs + 1 #par de canales diferentes
420 nPairs = nPairs + 1 #par de canales diferentes
420 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
421 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
421
422
422 self.flag_cspc = False
423 self.flag_cspc = False
423 if nPairs > 0:
424 if nPairs > 0:
424 self.flag_cspc = True
425 self.flag_cspc = True
425
426
426 # except Exception, e:
427 # except Exception, e:
427 # print "Error ProcessingHeader: "
428 # print "Error ProcessingHeader: "
428 # return 0
429 # return 0
429
430
430 return 1
431 return 1
431
432
432 def write(self, fp):
433 def write(self, fp):
433 headerTuple = (self.size,
434 headerTuple = (self.size,
434 self.dtype,
435 self.dtype,
435 self.blockSize,
436 self.blockSize,
436 self.profilesPerBlock,
437 self.profilesPerBlock,
437 self.dataBlocksPerFile,
438 self.dataBlocksPerFile,
438 self.nWindows,
439 self.nWindows,
439 self.processFlags,
440 self.processFlags,
440 self.nCohInt,
441 self.nCohInt,
441 self.nIncohInt,
442 self.nIncohInt,
442 self.totalSpectra)
443 self.totalSpectra)
443
444
444 header = numpy.array(headerTuple,self.struct)
445 header = numpy.array(headerTuple,self.struct)
445 header.tofile(fp)
446 header.tofile(fp)
446
447
447 if self.nWindows != 0:
448 if self.nWindows != 0:
448 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
449 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
449 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
450 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
450 samplingWindow.tofile(fp)
451 samplingWindow.tofile(fp)
451
452
452
453
453 if self.totalSpectra != 0:
454 if self.totalSpectra != 0:
454 spectraComb = numpy.array([],numpy.dtype('u1'))
455 spectraComb = numpy.array([],numpy.dtype('u1'))
455 spectraComb = self.spectraComb
456 spectraComb = self.spectraComb
456 spectraComb.tofile(fp)
457 spectraComb.tofile(fp)
457
458
458 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
459 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
459 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
460 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
460 # nCode.tofile(fp)
461 # nCode.tofile(fp)
461 #
462 #
462 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
463 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
463 # nBaud.tofile(fp)
464 # nBaud.tofile(fp)
464 #
465 #
465 # code = self.code.reshape(self.nCode*self.nBaud)
466 # code = self.code.reshape(self.nCode*self.nBaud)
466 # code = code.astype(numpy.dtype('<f4'))
467 # code = code.astype(numpy.dtype('<f4'))
467 # code.tofile(fp)
468 # code.tofile(fp)
468
469
469 return 1
470 return 1
470
471
471 class RCfunction:
472 class RCfunction:
472 NONE=0
473 NONE=0
473 FLIP=1
474 FLIP=1
474 CODE=2
475 CODE=2
475 SAMPLING=3
476 SAMPLING=3
476 LIN6DIV256=4
477 LIN6DIV256=4
477 SYNCHRO=5
478 SYNCHRO=5
478
479
479 class nCodeType:
480 class nCodeType:
480 NONE=0
481 NONE=0
481 USERDEFINE=1
482 USERDEFINE=1
482 BARKER2=2
483 BARKER2=2
483 BARKER3=3
484 BARKER3=3
484 BARKER4=4
485 BARKER4=4
485 BARKER5=5
486 BARKER5=5
486 BARKER7=6
487 BARKER7=6
487 BARKER11=7
488 BARKER11=7
488 BARKER13=8
489 BARKER13=8
489 AC128=9
490 AC128=9
490 COMPLEMENTARYCODE2=10
491 COMPLEMENTARYCODE2=10
491 COMPLEMENTARYCODE4=11
492 COMPLEMENTARYCODE4=11
492 COMPLEMENTARYCODE8=12
493 COMPLEMENTARYCODE8=12
493 COMPLEMENTARYCODE16=13
494 COMPLEMENTARYCODE16=13
494 COMPLEMENTARYCODE32=14
495 COMPLEMENTARYCODE32=14
495 COMPLEMENTARYCODE64=15
496 COMPLEMENTARYCODE64=15
496 COMPLEMENTARYCODE128=16
497 COMPLEMENTARYCODE128=16
497 CODE_BINARY28=17
498 CODE_BINARY28=17
498
499
499 class PROCFLAG:
500 class PROCFLAG:
500 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
501 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
501 DECODE_DATA = numpy.uint32(0x00000002)
502 DECODE_DATA = numpy.uint32(0x00000002)
502 SPECTRA_CALC = numpy.uint32(0x00000004)
503 SPECTRA_CALC = numpy.uint32(0x00000004)
503 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
504 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
504 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
505 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
505 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
506 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
506
507
507 DATATYPE_CHAR = numpy.uint32(0x00000040)
508 DATATYPE_CHAR = numpy.uint32(0x00000040)
508 DATATYPE_SHORT = numpy.uint32(0x00000080)
509 DATATYPE_SHORT = numpy.uint32(0x00000080)
509 DATATYPE_LONG = numpy.uint32(0x00000100)
510 DATATYPE_LONG = numpy.uint32(0x00000100)
510 DATATYPE_INT64 = numpy.uint32(0x00000200)
511 DATATYPE_INT64 = numpy.uint32(0x00000200)
511 DATATYPE_FLOAT = numpy.uint32(0x00000400)
512 DATATYPE_FLOAT = numpy.uint32(0x00000400)
512 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
513 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
513
514
514 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
515 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
515 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
516 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
516 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
517 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
517
518
518 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
519 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
519 DEFLIP_DATA = numpy.uint32(0x00010000)
520 DEFLIP_DATA = numpy.uint32(0x00010000)
520 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
521 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
521
522
522 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
523 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
523 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
524 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
524 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
525 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
525 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
526 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
526 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
527 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
527
528
528 EXP_NAME_ESP = numpy.uint32(0x00200000)
529 EXP_NAME_ESP = numpy.uint32(0x00200000)
529 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
530 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
530
531
531 OPERATION_MASK = numpy.uint32(0x0000003F)
532 OPERATION_MASK = numpy.uint32(0x0000003F)
532 DATATYPE_MASK = numpy.uint32(0x00000FC0)
533 DATATYPE_MASK = numpy.uint32(0x00000FC0)
533 DATAARRANGE_MASK = numpy.uint32(0x00007000)
534 DATAARRANGE_MASK = numpy.uint32(0x00007000)
534 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
535 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
General Comments 0
You need to be logged in to leave comments. Login now