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