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