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