##// END OF EJS Templates
fixing merge conflicts
jespinoza -
r1090:36f30f86830d merge
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

This diff has been collapsed as it changes many lines, (751 lines changed) Show them Hide them
@@ -0,0 +1,751
1
2 '''
3 Created on Jul 3, 2014
4
5 @author: roj-idl71
6 '''
7 # SUBCHANNELS EN VEZ DE CHANNELS
8 # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO
9 # ACTUALIZACION DE VERSION
10 # HEADERS
11 # MODULO DE ESCRITURA
12 # METADATA
13
14 import os
15 import datetime
16 import numpy
17 import timeit
18 from profilehooks import coverage, profile
19 from fractions import Fraction
20
21 try:
22 from gevent import sleep
23 except:
24 from time import sleep
25
26 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
27 from schainpy.model.data.jrodata import Voltage
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 from time import time
30
31 import cPickle
32 try:
33 import digital_rf
34 except:
35 print 'You should install "digital_rf" module if you want to read Digital RF data'
36
37 class DigitalRFReader(ProcessingUnit):
38 '''
39 classdocs
40 '''
41
42 def __init__(self, **kwargs):
43 '''
44 Constructor
45 '''
46
47 ProcessingUnit.__init__(self, **kwargs)
48
49 self.dataOut = Voltage()
50 self.__printInfo = True
51 self.__flagDiscontinuousBlock = False
52 self.__bufferIndex = 9999999
53 self.__ippKm = None
54 self.__codeType = 0
55 self.__nCode = None
56 self.__nBaud = None
57 self.__code = None
58 self.dtype = None
59
60 def close(self):
61 print 'Average of writing to digital rf format is ', self.oldAverage * 1000
62 return
63
64 def __getCurrentSecond(self):
65
66 return self.__thisUnixSample/self.__sample_rate
67
68 thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
69
70 def __setFileHeader(self):
71 '''
72 In this method will be initialized every parameter of dataOut object (header, no data)
73 '''
74 ippSeconds = 1.0*self.__nSamples/self.__sample_rate
75
76 nProfiles = 1.0/ippSeconds # Number of profiles in one second
77
78 try:
79 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(self.__radarControllerHeader)
80 except:
81 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
82 txA=0,
83 txB=0,
84 nWindows=1,
85 nHeights=self.__nSamples,
86 firstHeight=self.__firstHeigth,
87 deltaHeight=self.__deltaHeigth,
88 codeType=self.__codeType,
89 nCode=self.__nCode, nBaud=self.__nBaud,
90 code = self.__code)
91
92 try:
93 self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader)
94 except:
95 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
96 nProfiles=nProfiles,
97 nChannels=len(self.__channelList),
98 adcResolution=14)
99 self.dataOut.type = "Voltage"
100
101 self.dataOut.data = None
102
103 self.dataOut.dtype = self.dtype
104
105 # self.dataOut.nChannels = 0
106
107 # self.dataOut.nHeights = 0
108
109 self.dataOut.nProfiles = int(nProfiles)
110
111 self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth
112
113 self.dataOut.channelList = range(self.__num_subchannels)
114
115 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
116
117 # self.dataOut.channelIndexList = None
118
119 self.dataOut.flagNoData = True
120
121 self.dataOut.flagDataAsBlock = False
122 # Set to TRUE if the data is discontinuous
123 self.dataOut.flagDiscontinuousBlock = False
124
125 self.dataOut.utctime = None
126
127 self.dataOut.timeZone = self.__timezone/60 # timezone like jroheader, difference in minutes between UTC and localtime
128
129 self.dataOut.dstFlag = 0
130
131 self.dataOut.errorCount = 0
132
133 try:
134 self.dataOut.nCohInt = self.fixed_metadata_dict.get('nCohInt', 1)
135
136 self.dataOut.flagDecodeData = self.fixed_metadata_dict['flagDecodeData'] # asumo que la data esta decodificada
137
138 self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] # asumo que la data esta sin flip
139
140 self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT']
141
142 self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime']
143 except:
144 pass
145
146
147 self.dataOut.ippSeconds = ippSeconds
148
149 # Time interval between profiles
150 # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
151
152 self.dataOut.frequency = self.__frequency
153
154 self.dataOut.realtime = self.__online
155
156 def findDatafiles(self, path, startDate=None, endDate=None):
157
158 if not os.path.isdir(path):
159 return []
160
161 try:
162 digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
163 except:
164 digitalReadObj = digital_rf.DigitalRFReader(path)
165
166 channelNameList = digitalReadObj.get_channels()
167
168 if not channelNameList:
169 return []
170
171 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
172
173 sample_rate = metadata_dict['sample_rate'][0]
174
175 this_metadata_file = digitalReadObj.get_metadata(channelNameList[0])
176
177 try:
178 timezone = this_metadata_file['timezone'].value
179 except:
180 timezone = 0
181
182 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone
183
184 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
185 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
186
187 if not startDate:
188 startDate = startDatetime.date()
189
190 if not endDate:
191 endDate = endDatatime.date()
192
193 dateList = []
194
195 thisDatetime = startDatetime
196
197 while(thisDatetime<=endDatatime):
198
199 thisDate = thisDatetime.date()
200
201 if thisDate < startDate:
202 continue
203
204 if thisDate > endDate:
205 break
206
207 dateList.append(thisDate)
208 thisDatetime += datetime.timedelta(1)
209
210 return dateList
211
212 def setup(self, path = None,
213 startDate = None,
214 endDate = None,
215 startTime = datetime.time(0,0,0),
216 endTime = datetime.time(23,59,59),
217 channelList = None,
218 nSamples = None,
219 online = False,
220 delay = 60,
221 buffer_size = 1024,
222 ippKm=None,
223 **kwargs):
224 '''
225 In this method we should set all initial parameters.
226
227 Inputs:
228 path
229 startDate
230 endDate
231 startTime
232 endTime
233 set
234 expLabel
235 ext
236 online
237 delay
238 '''
239 self.i = 0
240 if not os.path.isdir(path):
241 raise ValueError, "[Reading] Directory %s does not exist" %path
242
243 try:
244 self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
245 except:
246 self.digitalReadObj = digital_rf.DigitalRFReader(path)
247
248 channelNameList = self.digitalReadObj.get_channels()
249
250 if not channelNameList:
251 raise ValueError, "[Reading] Directory %s does not have any files" %path
252
253 if not channelList:
254 channelList = range(len(channelNameList))
255
256
257 ########## Reading metadata ######################
258
259 top_properties = self.digitalReadObj.get_properties(channelNameList[channelList[0]])
260
261
262 self.__num_subchannels = top_properties['num_subchannels']
263 self.__sample_rate = 1.0 * top_properties['sample_rate_numerator'] / top_properties['sample_rate_denominator']
264 # self.__samples_per_file = top_properties['samples_per_file'][0]
265 self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15?
266
267 this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]])
268 metadata_bounds = this_metadata_file.get_bounds()
269 self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ## GET FIRST HEADER
270
271 try:
272 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
273 self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader']
274 self.__systemHeader = self.fixed_metadata_dict['systemHeader']
275 self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype'])
276 except:
277 pass
278
279
280 self.__frequency = None
281
282 self.__frequency = self.fixed_metadata_dict.get('frequency', 1)
283
284 self.__timezone = self.fixed_metadata_dict.get('timezone', 300)
285
286
287 try:
288 nSamples = self.fixed_metadata_dict['nSamples']
289 except:
290 nSamples = None
291
292 self.__firstHeigth = 0
293
294 try:
295 codeType = self.__radarControllerHeader['codeType']
296 except:
297 codeType = 0
298
299 nCode = 1
300 nBaud = 1
301 code = numpy.ones((nCode, nBaud), dtype=numpy.int)
302
303 try:
304 if codeType:
305 nCode = self.__radarControllerHeader['nCode']
306 nBaud = self.__radarControllerHeader['nBaud']
307 code = self.__radarControllerHeader['code']
308 except:
309 pass
310
311
312 if not ippKm:
313 try:
314 # seconds to km
315 ippKm = self.__radarControllerHeader['ipp']
316 except:
317 ippKm = None
318 ####################################################
319 self.__ippKm = ippKm
320 startUTCSecond = None
321 endUTCSecond = None
322
323 if startDate:
324 startDatetime = datetime.datetime.combine(startDate, startTime)
325 startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
326
327 if endDate:
328 endDatetime = datetime.datetime.combine(endDate, endTime)
329 endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
330
331 start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]])
332
333 if not startUTCSecond:
334 startUTCSecond = start_index/self.__sample_rate
335
336 if start_index > startUTCSecond*self.__sample_rate:
337 startUTCSecond = start_index/self.__sample_rate
338
339 if not endUTCSecond:
340 endUTCSecond = end_index/self.__sample_rate
341
342 if end_index < endUTCSecond*self.__sample_rate:
343 endUTCSecond = end_index/self.__sample_rate
344 if not nSamples:
345 if not ippKm:
346 raise ValueError, "[Reading] nSamples or ippKm should be defined"
347 nSamples = int(ippKm / (1e6*0.15/self.__sample_rate))
348 channelBoundList = []
349 channelNameListFiltered = []
350
351 for thisIndexChannel in channelList:
352 thisChannelName = channelNameList[thisIndexChannel]
353 start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName)
354 channelBoundList.append((start_index, end_index))
355 channelNameListFiltered.append(thisChannelName)
356
357 self.profileIndex = 0
358 self.i= 0
359 self.__delay = delay
360
361 self.__codeType = codeType
362 self.__nCode = nCode
363 self.__nBaud = nBaud
364 self.__code = code
365
366 self.__datapath = path
367 self.__online = online
368 self.__channelList = channelList
369 self.__channelNameList = channelNameListFiltered
370 self.__channelBoundList = channelBoundList
371 self.__nSamples = nSamples
372 self.__samples_to_read = long(nSamples) # FIJO: AHORA 40
373 self.__nChannels = len(self.__channelList)
374
375 self.__startUTCSecond = startUTCSecond
376 self.__endUTCSecond = endUTCSecond
377
378 self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate # Time interval
379
380 if online:
381 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
382 startUTCSecond = numpy.floor(endUTCSecond)
383
384 self.__thisUnixSample = long(startUTCSecond*self.__sample_rate) - self.__samples_to_read ## por que en el otro metodo lo primero q se hace es sumar samplestoread
385
386 self.__data_buffer = numpy.zeros((self.__num_subchannels, self.__samples_to_read), dtype = numpy.complex)
387
388 self.__setFileHeader()
389 self.isConfig = True
390
391 print "[Reading] Digital RF Data was found from %s to %s " %(
392 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
393 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
394 )
395
396 print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
397 datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone)
398 )
399 self.oldAverage = None
400 self.count = 0
401 self.executionTime = 0
402 def __reload(self):
403 # print
404 # print "%s not in range [%s, %s]" %(
405 # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
406 # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
407 # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
408 # )
409 print "[Reading] reloading metadata ..."
410
411 try:
412 self.digitalReadObj.reload(complete_update=True)
413 except:
414 self.digitalReadObj.reload()
415
416 start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]])
417
418 if start_index > self.__startUTCSecond*self.__sample_rate:
419 self.__startUTCSecond = 1.0*start_index/self.__sample_rate
420
421 if end_index > self.__endUTCSecond*self.__sample_rate:
422 self.__endUTCSecond = 1.0*end_index/self.__sample_rate
423 print
424 print "[Reading] New timerange found [%s, %s] " %(
425 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
426 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
427 )
428
429 return True
430
431 return False
432
433 def timeit(self, toExecute):
434 t0 = time()
435 toExecute()
436 self.executionTime = time() - t0
437 if self.oldAverage is None: self.oldAverage = self.executionTime
438 self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0)
439 self.count = self.count + 1.0
440 return
441
442 def __readNextBlock(self, seconds=30, volt_scale = 1):
443 '''
444 '''
445
446 # Set the next data
447 self.__flagDiscontinuousBlock = False
448 self.__thisUnixSample += self.__samples_to_read
449
450 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
451 print "[Reading] There are no more data into selected time-range"
452 if self.__online:
453 self.__reload()
454 else:
455 return False
456
457 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
458 return False
459 self.__thisUnixSample -= self.__samples_to_read
460
461 indexChannel = 0
462
463 dataOk = False
464 for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS?
465 for indexSubchannel in range(self.__num_subchannels):
466 try:
467 t0 = time()
468 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
469 self.__samples_to_read,
470 thisChannelName, sub_channel=indexSubchannel)
471 self.executionTime = time() - t0
472 if self.oldAverage is None: self.oldAverage = self.executionTime
473 self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0)
474 self.count = self.count + 1.0
475
476 except IOError, e:
477 #read next profile
478 self.__flagDiscontinuousBlock = True
479 print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
480 break
481
482 if result.shape[0] != self.__samples_to_read:
483 self.__flagDiscontinuousBlock = True
484 print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
485 result.shape[0],
486 self.__samples_to_read)
487 break
488
489 self.__data_buffer[indexSubchannel,:] = result*volt_scale
490
491 indexChannel += 1
492
493 dataOk = True
494
495 self.__utctime = self.__thisUnixSample/self.__sample_rate
496
497 if not dataOk:
498 return False
499
500 print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
501 self.__samples_to_read,
502 self.__timeInterval)
503
504 self.__bufferIndex = 0
505
506 return True
507
508 def __isBufferEmpty(self):
509 return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40
510
511 def getData(self, seconds=30, nTries=5):
512
513 '''
514 This method gets the data from files and put the data into the dataOut object
515
516 In addition, increase el the buffer counter in one.
517
518 Return:
519 data : retorna un perfil de voltages (alturas * canales) copiados desde el
520 buffer. Si no hay mas archivos a leer retorna None.
521
522 Affected:
523 self.dataOut
524 self.profileIndex
525 self.flagDiscontinuousBlock
526 self.flagIsNewBlock
527 '''
528
529 err_counter = 0
530 self.dataOut.flagNoData = True
531
532 if self.__isBufferEmpty():
533 self.__flagDiscontinuousBlock = False
534
535 while True:
536 if self.__readNextBlock():
537 break
538 if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate:
539 return False
540
541 if self.__flagDiscontinuousBlock:
542 print '[Reading] discontinuous block found ... continue with the next block'
543 continue
544
545 if not self.__online:
546 return False
547
548 err_counter += 1
549 if err_counter > nTries:
550 return False
551
552 print '[Reading] waiting %d seconds to read a new block' %seconds
553 sleep(seconds)
554
555 self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples]
556 self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate
557 self.dataOut.flagNoData = False
558 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
559 self.dataOut.profileIndex = self.profileIndex
560
561 self.__bufferIndex += self.__nSamples
562 self.profileIndex += 1
563
564 if self.profileIndex == self.dataOut.nProfiles:
565 self.profileIndex = 0
566
567 return True
568
569 def printInfo(self):
570 '''
571 '''
572 if self.__printInfo == False:
573 return
574
575 # self.systemHeaderObj.printInfo()
576 # self.radarControllerHeaderObj.printInfo()
577
578 self.__printInfo = False
579
580 def printNumberOfBlock(self):
581 '''
582 '''
583 return
584 # print self.profileIndex
585
586
587 def run(self, **kwargs):
588 '''
589 This method will be called many times so here you should put all your code
590 '''
591
592 if not self.isConfig:
593 self.setup(**kwargs)
594 #self.i = self.i+1
595 self.getData(seconds=self.__delay)
596
597 return
598
599 class DigitalRFWriter(Operation):
600 '''
601 classdocs
602 '''
603
604 def __init__(self, **kwargs):
605 '''
606 Constructor
607 '''
608 Operation.__init__(self, **kwargs)
609 self.metadata_dict = {}
610 self.dataOut = None
611 self.dtype = None
612
613 def setHeader(self):
614
615 self.metadata_dict['frequency'] = self.dataOut.frequency
616 self.metadata_dict['timezone'] = self.dataOut.timeZone
617 self.metadata_dict['dtype'] = cPickle.dumps(self.dataOut.dtype)
618 self.metadata_dict['nProfiles'] = self.dataOut.nProfiles
619 self.metadata_dict['heightList'] = self.dataOut.heightList
620 self.metadata_dict['channelList'] = self.dataOut.channelList
621 self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData
622 self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData
623 self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT
624 self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock
625 self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime
626 self.metadata_dict['nCohInt'] = self.dataOut.nCohInt
627
628 return
629
630 def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'):
631 '''
632 In this method we should set all initial parameters.
633 Input:
634 dataOut: Input data will also be outputa data
635 '''
636 self.setHeader()
637 self.__ippSeconds = dataOut.ippSeconds
638 self.__deltaH = dataOut.getDeltaH()
639 self.__sample_rate = 1e6*0.15/self.__deltaH
640 self.__dtype = dataOut.dtype
641 if len(dataOut.dtype) == 2:
642 self.__dtype = dataOut.dtype[0]
643 self.__nSamples = dataOut.systemHeaderObj.nSamples
644 self.__nProfiles = dataOut.nProfiles
645 self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile
646
647 self.arr_data = arr_data = numpy.ones((self.__nSamples, len(self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
648
649 file_cadence_millisecs = long(1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000
650 sub_cadence_secs = file_cadence_millisecs / 500
651
652 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
653 sample_rate_numerator = long(sample_rate_fraction.numerator)
654 sample_rate_denominator = long(sample_rate_fraction.denominator)
655 start_global_index = dataOut.utctime * self.__sample_rate
656
657 uuid = 'prueba'
658 compression_level = 1
659 checksum = False
660 is_complex = True
661 num_subchannels = len(dataOut.channelList)
662 is_continuous = True
663 marching_periods = False
664
665 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence,
666 fileCadence, start_global_index,
667 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
668 is_complex, num_subchannels, is_continuous, marching_periods)
669
670 metadata_dir = os.path.join(path, 'metadata')
671 os.system('mkdir %s' % (metadata_dir))
672
673 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, ##236, file_cadence_millisecs / 1000
674 sample_rate_numerator, sample_rate_denominator,
675 metadataFile)
676
677
678 self.isConfig = True
679 self.currentSample = 0
680 self.oldAverage = 0
681 self.count = 0
682 return
683
684 def writeMetadata(self):
685 print '[Writing] - Writing metadata'
686 start_idx = self.__sample_rate * self.dataOut.utctime
687
688 self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict()
689 self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict()
690 self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict()
691 self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict)
692 return
693
694
695 def timeit(self, toExecute):
696 t0 = time()
697 toExecute()
698 self.executionTime = time() - t0
699 if self.oldAverage is None: self.oldAverage = self.executionTime
700 self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0)
701 self.count = self.count + 1.0
702 return
703
704
705 def writeData(self):
706 for i in range(self.dataOut.systemHeaderObj.nSamples):
707 for channel in self.dataOut.channelList:
708 self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real
709 self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag
710
711 def f(): return self.digitalWriteObj.rf_write(self.arr_data)
712 self.timeit(f)
713
714 return
715
716 def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=100, dirCadence=25, metadataCadence=1, **kwargs):
717 '''
718 This method will be called many times so here you should put all your code
719 Inputs:
720 dataOut: object with the data
721 '''
722 # print dataOut.__dict__
723 self.dataOut = dataOut
724 if not self.isConfig:
725 self.setup(dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, **kwargs)
726 self.writeMetadata()
727
728 self.writeData()
729
730 ## self.currentSample += 1
731 ## if self.dataOut.flagDataAsBlock or self.currentSample == 1:
732 ## self.writeMetadata()
733 ## if self.currentSample == self.__nProfiles: self.currentSample = 0
734
735 def close(self):
736 print '[Writing] - Closing files '
737 print 'Average of writing to digital rf format is ', self.oldAverage * 1000
738 try:
739 self.digitalWriteObj.close()
740 except:
741 pass
742
743 # raise
744 if __name__ == '__main__':
745
746 readObj = DigitalRFReader()
747
748 while True:
749 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
750 # readObj.printInfo()
751 # readObj.printNumberOfBlock()
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: new file 100644
NO CONTENT: new file 100644
The requested commit or file is too big and content was truncated. Show full diff
@@ -1,115 +1,115
1 # Byte-compiled / optimized / DLL files
1 # Byte-compiled / optimized / DLL files
2 __pycache__/
2 __pycache__/
3 *.py[cod]
3 *.py[cod]
4 *$py.class
4 *$py.class
5
5
6 # C extensions
6 # C extensions
7 *.so
7 *.so
8
8
9 # Distribution / packaging
9 # Distribution / packaging
10 .Python
10 .Python
11 env/
11 env/
12 build/
12 build/
13 develop-eggs/
13 develop-eggs/
14 dist/
14 dist/
15 downloads/
15 downloads/
16 eggs/
16 eggs/
17 .eggs/
17 .eggs/
18 lib/
18 lib/
19 lib64/
19 lib64/
20 parts/
20 parts/
21 sdist/
21 sdist/
22 var/
22 var/
23 wheels/
23 wheels/
24 *.egg-info/
24 *.egg-info/
25 .installed.cfg
25 .installed.cfg
26 *.egg
26 *.egg
27
27
28 # PyInstaller
28 # PyInstaller
29 # Usually these files are written by a python script from a template
29 # Usually these files are written by a python script from a template
30 # before PyInstaller builds the exe, so as to inject date/other infos into it.
30 # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 *.manifest
31 *.manifest
32 *.spec
32 *.spec
33
33
34 # Installer logs
34 # Installer logs
35 pip-log.txt
35 pip-log.txt
36 pip-delete-this-directory.txt
36 pip-delete-this-directory.txt
37
37
38 # Unit test / coverage reports
38 # Unit test / coverage reports
39 htmlcov/
39 htmlcov/
40 .tox/
40 .tox/
41 .coverage
41 .coverage
42 .coverage.*
42 .coverage.*
43 .cache
43 .cache
44 nosetests.xml
44 nosetests.xml
45 coverage.xml
45 coverage.xml
46 *,cover
46 *,cover
47 .hypothesis/
47 .hypothesis/
48
48
49 # Translations
49 # Translations
50 *.mo
50 *.mo
51 *.pot
51 *.pot
52
52
53 # Django stuff:
53 # Django stuff:
54 *.log
54 *.log
55 local_settings.py
55 local_settings.py
56
56
57 # Flask stuff:
57 # Flask stuff:
58 instance/
58 instance/
59 .webassets-cache
59 .webassets-cache
60
60
61 # Scrapy stuff:
61 # Scrapy stuff:
62 .scrapy
62 .scrapy
63
63
64 # Sphinx documentation
64 # Sphinx documentation
65 docs/_build/
65 docs/_build/
66
66
67 # PyBuilder
67 # PyBuilder
68 target/
68 target/
69
69
70 # Jupyter Notebook
70 # Jupyter Notebook
71 .ipynb_checkpoints
71 .ipynb_checkpoints
72
72
73 # pyenv
73 # pyenv
74 .python-version
74 .python-version
75
75
76 # celery beat schedule file
76 # celery beat schedule file
77 celerybeat-schedule
77 celerybeat-schedule
78
78
79 # SageMath parsed files
79 # SageMath parsed files
80 *.sage.py
80 *.sage.py
81
81
82 # dotenv
82 # dotenv
83 .env
83 .env
84
84
85 # virtualenv
85 # virtualenv
86 .venv
86 .venv
87 venv/
87 venv/
88 ENV/
88 ENV/
89
89
90 # Spyder project settings
90 # Spyder project settings
91 .spyderproject
91 .spyderproject
92 .spyproject
92 .spyproject
93
93
94 # Rope project settings
94 # Rope project settings
95 .ropeproject
95 .ropeproject
96
96
97 # mkdocs documentation
97 # mkdocs documentation
98 /site
98 /site
99
99
100 # eclipse
100 # eclipse
101 .project
101 .project
102 .pydevproject
102 .pydevproject
103
104 # vscode
103 # vscode
105
104
106 .vscode
105 .vscode
107
106
108 schainpy/scripts/
109 schaingui/node_modules/
107 schaingui/node_modules/
108 schainpy/scripts/
110 .svn/
109 .svn/
111 *.png
110 *.png
112 *.pyc
111 *.pyc
113 *.xml
112 schainpy/scripts
114 *.log
113 .vscode
115 trash
114 trash
115 *.log
@@ -1,9 +1,9
1 # schaing
1 # schain
2
2
3 Command Line Interface for SIGNAL CHAIN - jro
3 Command Line Interface for SIGNAL CHAIN - jro
4
4
5 # Usage
5 # Usage
6
6
7 To use it:
7 To use it:
8
8
9 $ schain-cli --help
9 $ schain-cli --help
@@ -1,157 +1,168
1 import click
1 import click
2 import schainpy
2 import schainpy
3 import subprocess
3 import subprocess
4 import os
4 import os
5 import sys
5 import sys
6 import glob
6 import glob
7 save_stdout = sys.stdout
7 save_stdout = sys.stdout
8 sys.stdout = open('trash', 'w')
8 sys.stdout = open('trash', 'w')
9 from multiprocessing import cpu_count
9 from multiprocessing import cpu_count
10 from schaincli import templates
10 from schaincli import templates
11 from schainpy.controller import Project
11 from schainpy.controller import Project
12 from schainpy.model import Operation, ProcessingUnit
12 from schainpy.model import Operation, ProcessingUnit
13 from schainpy.utils import log
13 from schainpy.utils import log
14 from importlib import import_module
14 from importlib import import_module
15 from pydoc import locate
15 from pydoc import locate
16 from fuzzywuzzy import process
16 from fuzzywuzzy import process
17 from schainpy.utils import paramsFinder
17 from schainpy.utils import paramsFinder
18 sys.stdout = save_stdout
18 sys.stdout = save_stdout
19
19
20
20
21 def print_version(ctx, param, value):
21 def print_version(ctx, param, value):
22 if not value or ctx.resilient_parsing:
22 if not value or ctx.resilient_parsing:
23 return
23 return
24 click.echo(schainpy.__version__)
24 click.echo(schainpy.__version__)
25 ctx.exit()
25 ctx.exit()
26
26
27
27
28 cliLogger = log.makelogger('schain cli')
28 cliLogger = log.makelogger('schain cli')
29 PREFIX = 'experiment'
29 PREFIX = 'experiment'
30
30
31
31
32 @click.command()
32 @click.command()
33 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
33 @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str)
34 @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True))
35 @click.argument('command', default='run', required=True)
34 @click.argument('command', default='run', required=True)
36 @click.argument('nextcommand', default=None, required=False, type=str)
35 @click.argument('nextcommand', default=None, required=False, type=str)
37 def main(command, nextcommand, version, xml):
36 def main(command, nextcommand, version):
38 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY \n
37 """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY \n
39 Available commands.\n
38 Available commands.\n
40 --xml: runs a schain XML generated file\n
39 --xml: runs a schain XML generated file\n
41 run: runs any python script starting 'experiment_'\n
40 run: runs any python script starting 'experiment_'\n
42 generate: generates a template schain script\n
41 generate: generates a template schain script\n
43 search: return avilable operations, procs or arguments of the give operation/proc\n"""
42 search: return avilable operations, procs or arguments of the give operation/proc\n"""
44 if xml is not None:
43 if command == 'xml':
45 runFromXML(xml)
44 runFromXML(nextcommand)
46 elif command == 'generate':
45 elif command == 'generate':
47 generate()
46 generate()
48 elif command == 'test':
47 elif command == 'test':
49 test()
48 test()
50 elif command == 'run':
49 elif command == 'run':
51 runschain(nextcommand)
50 runschain(nextcommand)
52 elif command == 'search':
51 elif command == 'search':
53 search(nextcommand)
52 search(nextcommand)
54 else:
53 else:
55 log.error('Command {} is not defined'.format(command))
54 log.error('Command {} is not defined'.format(command))
56
55
56
57 def check_module(possible, instance):
57 def check_module(possible, instance):
58 def check(x):
58 def check(x):
59 try:
59 try:
60 instancia = locate('schainpy.model.{}'.format(x))
60 instancia = locate('schainpy.model.{}'.format(x))
61 return isinstance(instancia(), instance)
61 return isinstance(instancia(), instance)
62 except Exception as e:
62 except Exception as e:
63 return False
63 return False
64 clean = clean_modules(possible)
64 clean = clean_modules(possible)
65 return [x for x in clean if check(x)]
65 return [x for x in clean if check(x)]
66
66
67
67
68 def clean_modules(module):
68 def clean_modules(module):
69 noEndsUnder = [x for x in module if not x.endswith('__')]
69 noEndsUnder = [x for x in module if not x.endswith('__')]
70 noStartUnder = [x for x in noEndsUnder if not x.startswith('__')]
70 noStartUnder = [x for x in noEndsUnder if not x.startswith('__')]
71 noFullUpper = [x for x in noStartUnder if not x.isupper()]
71 noFullUpper = [x for x in noStartUnder if not x.isupper()]
72 return noFullUpper
72 return noFullUpper
73
73
74
74
75 def search(nextcommand):
75 def search(nextcommand):
76 if nextcommand is None:
76 if nextcommand is None:
77 log.error('There is no Operation/ProcessingUnit to search')
77 log.error('There is no Operation/ProcessingUnit to search')
78 elif nextcommand == 'procs':
78 elif nextcommand == 'procs':
79 procs = paramsFinder.getProcs()
79 procs = paramsFinder.getProcs()
80 log.success('Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs)))
80 log.success(
81 'Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs)))
81
82
82 elif nextcommand == 'operations':
83 elif nextcommand == 'operations':
83 operations = paramsFinder.getOperations()
84 operations = paramsFinder.getOperations()
84 log.success('Current Operations are:\n\033[1m{}\033[0m'.format('\n'.join(operations)))
85 log.success('Current Operations are:\n\033[1m{}\033[0m'.format(
86 '\n'.join(operations)))
85 else:
87 else:
86 try:
88 try:
87 args = paramsFinder.getArgs(nextcommand)
89 args = paramsFinder.getArgs(nextcommand)
88 log.warning('Use this feature with caution. It may not return all the allowed arguments')
90 log.warning(
91 'Use this feature with caution. It may not return all the allowed arguments')
89 if len(args) == 0:
92 if len(args) == 0:
90 log.success('{} has no arguments'.format(nextcommand))
93 log.success('{} has no arguments'.format(nextcommand))
91 else:
94 else:
92 log.success('Showing arguments of {} are:\n\033[1m{}\033[0m'.format(nextcommand, '\n'.join(args)))
95 log.success('Showing {} arguments:\n\033[1m{}\033[0m'.format(
96 nextcommand, '\n'.join(args)))
93 except Exception as e:
97 except Exception as e:
94 log.error('Module {} does not exists'.format(nextcommand))
98 log.error('Module {} does not exists'.format(nextcommand))
95 allModules = paramsFinder.getAll()
99 allModules = paramsFinder.getAll()
96 similar = process.extractOne(nextcommand, allModules)[0]
100 similar = process.extractOne(nextcommand, allModules)[0]
97 log.success('Showing {} instead'.format(similar))
101 log.success('Showing {} instead'.format(similar))
98 search(similar)
102 search(similar)
99
103
100
104
101 def runschain(nextcommand):
105 def runschain(nextcommand):
102 if nextcommand is None:
106 if nextcommand is None:
103 currentfiles = glob.glob('./{}_*.py'.format(PREFIX))
107 currentfiles = glob.glob('./{}_*.py'.format(PREFIX))
104 numberfiles = len(currentfiles)
108 numberfiles = len(currentfiles)
105 if numberfiles > 1:
109 if numberfiles > 1:
106 log.error('There is more than one file to run')
110 log.error('There is more than one file to run')
107 elif numberfiles == 1:
111 elif numberfiles == 1:
108 subprocess.call(['python ' + currentfiles[0]], shell=True)
112 subprocess.call(['python ' + currentfiles[0]], shell=True)
109 else:
113 else:
110 log.error('There is no file to run')
114 log.error('There is no file to run')
111 else:
115 else:
112 try:
116 try:
113 subprocess.call(['python ' + nextcommand], shell=True)
117 subprocess.call(['python ' + nextcommand], shell=True)
114 except Exception as e:
118 except Exception as e:
115 log.error("I cannot run the file. Does it exists?")
119 log.error("I cannot run the file. Does it exists?")
116
120
117
121
118 def basicInputs():
122 def basicInputs():
119 inputs = {}
123 inputs = {}
120 inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str)
124 inputs['desc'] = click.prompt(
121 inputs['name'] = click.prompt('Name of the project', default="project", type=str)
125 'Enter a description', default="A schain project", type=str)
122 inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True))
126 inputs['name'] = click.prompt(
123 inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str)
127 'Name of the project', default="project", type=str)
124 inputs['endDate'] = click.prompt('End date', default='2017/12/31', type=str)
128 inputs['path'] = click.prompt('Data path', default=os.getcwd(
125 inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str)
129 ), type=click.Path(exists=True, resolve_path=True))
130 inputs['startDate'] = click.prompt(
131 'Start date', default='1970/01/01', type=str)
132 inputs['endDate'] = click.prompt(
133 'End date', default='2017/12/31', type=str)
134 inputs['startHour'] = click.prompt(
135 'Start hour', default='00:00:00', type=str)
126 inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str)
136 inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str)
127 inputs['figpath'] = inputs['path'] + '/figs'
137 inputs['figpath'] = inputs['path'] + '/figs'
128 return inputs
138 return inputs
129
139
130
140
131 def generate():
141 def generate():
132 inputs = basicInputs()
142 inputs = basicInputs()
133 inputs['multiprocess'] = click.confirm('Is this a multiprocess script?')
143 inputs['multiprocess'] = click.confirm('Is this a multiprocess script?')
134 if inputs['multiprocess']:
144 if inputs['multiprocess']:
135 inputs['nProcess'] = click.prompt('How many process?', default=cpu_count(), type=int)
145 inputs['nProcess'] = click.prompt(
146 'How many process?', default=cpu_count(), type=int)
136 current = templates.multiprocess.format(**inputs)
147 current = templates.multiprocess.format(**inputs)
137 else:
148 else:
138 current = templates.basic.format(**inputs)
149 current = templates.basic.format(**inputs)
139 scriptname = '{}_{}.py'.format(PREFIX, inputs['name'])
150 scriptname = '{}_{}.py'.format(PREFIX, inputs['name'])
140 script = open(scriptname, 'w')
151 script = open(scriptname, 'w')
141 try:
152 try:
142 script.write(current)
153 script.write(current)
143 log.success('Script {} generated'.format(scriptname))
154 log.success('Script {} generated'.format(scriptname))
144 except Exception as e:
155 except Exception as e:
145 log.error('I cannot create the file. Do you have writing permissions?')
156 log.error('I cannot create the file. Do you have writing permissions?')
146
157
147
158
148 def test():
159 def test():
149 log.warning('testing')
160 log.warning('testing')
150
161
151
162
152 def runFromXML(filename):
163 def runFromXML(filename):
153 controller = Project()
164 controller = Project()
154 if not controller.readXml(filename):
165 if not controller.readXml(filename):
155 return
166 return
156 controller.start()
167 controller.start()
157 return
168 return
@@ -1,75 +1,90
1 basic = '''from schainpy.controller import Project
1 basic = '''from schainpy.controller import Project
2
2
3 desc = "{desc}"
3 desc = "{desc}"
4 project = Project()
5 project.setup(id='200', name="{name}", description=desc)
4
6
5 controller = Project()
7 voltage_reader = project.addReadUnit(datatype='VoltageReader',
6 controller.setup(id='191', name="{name}", description=desc)
7
8 readUnitConf = controller.addReadUnit(datatype='VoltageReader',
9 path="{path}",
8 path="{path}",
10 startDate="{startDate}",
9 startDate="{startDate}",
11 endDate="{endDate}",
10 endDate="{endDate}",
12 startTime="{startHour}",
11 startTime="{startHour}",
13 endTime="{endHour}",
12 endTime="{endHour}",
14 online=0,
13 online=0,
15 verbose=1,
14 verbose=1,
16 walk=1,
15 walk=1,
17 )
16 )
18
17
19 procUnitConf1 = controller.addProcUnit(datatype='VoltageProc', inputId=readUnitConf.getId())
18 voltage_proc = project.addProcUnit(datatype='VoltageProc', inputId=voltage_reader.getId())
20
19
21 opObj11 = procUnitConf1.addOperation(name='ProfileSelector', optype='other')
20 profile = voltage_proc.addOperation(name='ProfileSelector', optype='other')
22 opObj11.addParameter(name='profileRangeList', value='120,183', format='intlist')
21 profile.addParameter(name='profileRangeList', value='120,183', format='intlist')
23
22
24 opObj11 = procUnitConf1.addOperation(name='RTIPlot', optype='other')
23 rti = voltage_proc.addOperation(name='RTIPlot', optype='other')
25 opObj11.addParameter(name='wintitle', value='Jicamarca Radio Observatory', format='str')
24 rti.addParameter(name='wintitle', value='Jicamarca Radio Observatory', format='str')
26 opObj11.addParameter(name='showprofile', value='0', format='int')
25 rti.addParameter(name='showprofile', value='0', format='int')
27 opObj11.addParameter(name='xmin', value='0', format='int')
26 rti.addParameter(name='xmin', value='0', format='int')
28 opObj11.addParameter(name='xmax', value='24', format='int')
27 rti.addParameter(name='xmax', value='24', format='int')
29 opObj11.addParameter(name='figpath', value="{figpath}", format='str')
28 rti.addParameter(name='figpath', value="{figpath}", format='str')
30 opObj11.addParameter(name='wr_period', value='5', format='int')
29 rti.addParameter(name='wr_period', value='5', format='int')
31 opObj11.addParameter(name='exp_code', value='22', format='int')
30 rti.addParameter(name='exp_code', value='22', format='int')
32
31
33
32
34 controller.start()
33 controller.start()
35 '''
34 '''
36
35
37 multiprocess = '''from schainpy.controller import Project, multiSchain
36 multiprocess = '''from schainpy.controller import Project, MPProject
38
37 from time import sleep
39 desc = "{desc}"
38 desc = "{desc}"
40
39
41 def fiber(cursor, skip, q, day):
40 ####################
42 controller = Project()
41 # PLOTTER RECEIVER #
43 controller.setup(id='191', name="{name}", description=desc)
42 ####################
43 plotter = Project()
44 plotter.setup(id='100', name='receiver', description=desc)
45
46 receiver_plot = plotter.addProcUnit(name='PlotterReceiver')
47 receiver_plot.addParameter(name='throttle', value=20, format='int')
48 receiver_plot.addParameter(name='plottypes', value='rti', format='str')
49
50 rti = receiver_plot.addOperation(name='PlotRTIData', optype='other')
51 rti.addParameter(name='zmin', value='-40.0', format='float')
52 rti.addParameter(name='zmax', value='100.0', format='float')
53 rti.addParameter(name='decimation', value='200', format='int')
54 rti.addParameter(name='xmin', value='0.0', format='int')
55 rti.addParameter(name='colormap', value='jet', format='str')
56
57 plotter.start()
44
58
45 readUnitConf = controller.addReadUnit(datatype='SpectraReader',
59 sleep(2)
60
61 ################
62 # DATA EMITTER #
63 ################
64 project = Project()
65 project.setup(id='200', name="{name}", description=desc)
66
67 spectra_reader = project.addReadUnit(datatype='SpectraReader',
46 path="{path}",
68 path="{path}",
47 startDate=day,
69 startDate={startDate},
48 endDate=day,
70 endDate={endDate},
49 startTime="{startHour}",
71 startTime="{startHour}",
50 endTime="{endHour}",
72 endTime="{endHour}",
51 online=0,
73 online=0,
52 queue=q,
53 cursor=cursor,
54 skip=skip,
55 verbose=1,
74 verbose=1,
56 walk=1,
75 walk=1,
57 )
76 )
58
77
59 procUnitConf1 = controller.addProcUnit(datatype='Spectra', inputId=readUnitConf.getId())
78 spectra_proc = project.addProcUnit(datatype='Spectra', inputId=spectra_reader.getId())
60
61 procUnitConf2 = controller.addProcUnit(datatype='ParametersProc', inputId=readUnitConf.getId())
62 opObj11 = procUnitConf2.addOperation(name='SpectralMoments', optype='other')
63
79
64 opObj12 = procUnitConf2.addOperation(name='PublishData', optype='other')
80 parameters_proc = project.addProcUnit(datatype='ParametersProc', inputId=spectra_proc.getId())
65 opObj12.addParameter(name='zeromq', value=1, format='int')
81 moments = parameters_proc.addOperation(name='SpectralMoments', optype='other')
66 opObj12.addParameter(name='verbose', value=0, format='bool')
67
68 controller.start()
69
82
83 publish = parameters_proc.addOperation(name='PublishData', optype='other')
84 publish.addParameter(name='zeromq', value=1, format='int')
85 publish.addParameter(name='verbose', value=0, format='bool')
70
86
71 if __name__ == '__main__':
87 MPProject(project, 16)
72 multiSchain(fiber, nProcess={nProcess}, startDate="{startDate}", endDate="{endDate}")
73
88
74
89
75 '''
90 '''
@@ -1,109 +1,109
1 ## CHANGELOG:
1 ## CHANGELOG:
2
2
3 ### 2.3
3 ### 2.3
4 * Added high order function `multiSchain` for multiprocessing scripts.
4 * Added high order function `MPProject` for multiprocessing scripts.
5 * Added two new Processing Units `PublishData` and `ReceiverData` for receiving and sending dataOut through multiple ways (tcp, ipc, inproc).
5 * Added two new Processing Units `PublishData` and `ReceiverData` for receiving and sending dataOut through multiple ways (tcp, ipc, inproc).
6 * Added a new graphics Processing Unit `PlotterReceiver`. It is decoupled from normal processing sequence with support for data generated by multiprocessing scripts.
6 * Added a new graphics Processing Unit `PlotterReceiver`. It is decoupled from normal processing sequence with support for data generated by multiprocessing scripts.
7 * Added support for sending realtime graphic to web server.
7 * Added support for sending realtime graphic to web server.
8 * GUI command `schain` is now `schainGUI`.
8 * GUI command `schain` is now `schainGUI`.
9 * Added a CLI tool named `schain`.
9 * Added a CLI tool named `schain`.
10 * Scripts templates can be now generated with `schain generate`.
10 * Scripts templates can be now generated with `schain generate`.
11 * Now it is possible to search Processing Units and Operations with `schain search [module]` to get the right name and its allowed parameters.
11 * Now it is possible to search Processing Units and Operations with `schain search [module]` to get the right name and its allowed parameters.
12 * `schain xml` to run xml scripts.
12 * `schain xml` to run xml scripts.
13 * Added suggestions when parameters are poorly written.
13 * Added suggestions when parameters are poorly written.
14 * `Controller.start()` now runs in a different process than the process calling it.
14 * `Controller.start()` now runs in a different process than the process calling it.
15 * Added `schainpy.utils.log` for log standarization.
15 * Added `schainpy.utils.log` for log standarization.
16 * Running script on online mode no longer ignores date and hour. Issue #1109.
16 * Running script on online mode no longer ignores date and hour. Issue #1109.
17 * Added support for receving voltage data directly from JARS (tcp, ipc).
17 * Added support for receving voltage data directly from JARS (tcp, ipc).
18 * Updated README for MAC OS GUI installation.
18 * Updated README for MAC OS GUI installation.
19 * Setup now installs numpy.
19 * Setup now installs numpy.
20
20
21 ### 2.2.6
21 ### 2.2.6
22 * Graphics generated by the GUI are now the same as generated by scripts. Issue #1074.
22 * Graphics generated by the GUI are now the same as generated by scripts. Issue #1074.
23 * Added support for C extensions.
23 * Added support for C extensions.
24 * function `hildebrand_sehkon` optimized with a C wrapper.
24 * Function `hildebrand_sehkon` optimized with a C wrapper.
25 * Numpy version updated.
25 * Numpy version updated.
26 * Migration to GIT.
26 * Migration to GIT.
27
27
28 ### 2.2.5:
28 ### 2.2.5:
29 * splitProfiles and combineProfiles modules were added to VoltageProc and Signal Chain GUI.
29 * splitProfiles and combineProfiles modules were added to VoltageProc and Signal Chain GUI.
30 * nProfiles of USRP data (hdf5) is the number of profiles thera are in one second.
30 * nProfiles of USRP data (hdf5) is the number of profiles thera are in one second.
31 * jroPlotter works directly with data objects instead of dictionaries
31 * jroPlotter works directly with data objects instead of dictionaries
32 * script "schain" was added to Signal Chain installer
32 * script "schain" was added to Signal Chain installer
33
33
34 ### 2.2.4.1:
34 ### 2.2.4.1:
35 * jroIO_usrp.py is update to read Sandra's data
35 * jroIO_usrp.py is update to read Sandra's data
36 * decimation in Spectra and RTI plots is always enabled.
36 * decimation in Spectra and RTI plots is always enabled.
37 * time* window option added to GUI
37 * time* window option added to GUI
38
38
39 ### 2.2.4:
39 ### 2.2.4:
40 * jroproc_spectra_lags.py added to schainpy
40 * jroproc_spectra_lags.py added to schainpy
41 * Bug fixed in schainGUI: ProcUnit was created with the same id in some cases.
41 * Bug fixed in schainGUI: ProcUnit was created with the same id in some cases.
42 * Bug fixed in jroHeaderIO: Header size validation.
42 * Bug fixed in jroHeaderIO: Header size validation.
43
43
44 ### 2.2.3.1:
44 ### 2.2.3.1:
45 * Filtering block by time has been added.
45 * Filtering block by time has been added.
46 * Bug fixed plotting RTI, CoherenceMap and others using xmin and xmax parameters. The first day worked
46 * Bug fixed plotting RTI, CoherenceMap and others using xmin and xmax parameters. The first day worked
47 properly but the next days did not.
47 properly but the next days did not.
48
48
49 ### 2.2.3:
49 ### 2.2.3:
50 * Bug fixed in GUI: Error getting(reading) Code value
50 * Bug fixed in GUI: Error getting(reading) Code value
51 * Bug fixed in GUI: Flip option always needs channelList field
51 * Bug fixed in GUI: Flip option always needs channelList field
52 * Bug fixed in jrodata: when one branch modified a value in "dataOut" (example: dataOut.code) this value
52 * Bug fixed in jrodata: when one branch modified a value in "dataOut" (example: dataOut.code) this value
53 was modified for every branch (because this was a reference). It was modified in data.copy()
53 was modified for every branch (because this was a reference). It was modified in data.copy()
54 * Bug fixed in jroproc_voltage.profileSelector(): rangeList replaces to profileRangeList.
54 * Bug fixed in jroproc_voltage.profileSelector(): rangeList replaces to profileRangeList.
55
55
56 ### 2.2.2:
56 ### 2.2.2:
57 * VoltageProc: ProfileSelector, Reshape, Decoder with nTxs!=1 and getblock=True was tested
57 * VoltageProc: ProfileSelector, Reshape, Decoder with nTxs!=1 and getblock=True was tested
58 * Rawdata and testRawdata.py added to Signal Chain project
58 * Rawdata and testRawdata.py added to Signal Chain project
59
59
60 ### 2.2.1:
60 ### 2.2.1:
61 * Bugs fixed in GUI
61 * Bugs fixed in GUI
62 * Views were improved in GUI
62 * Views were improved in GUI
63 * Support to MST* ISR experiments
63 * Support to MST* ISR experiments
64 * Bug fixed getting noise using hyldebrant. (minimum number of points > 20%)
64 * Bug fixed getting noise using hyldebrant. (minimum number of points > 20%)
65 * handleError added to jroplotter.py
65 * handleError added to jroplotter.py
66
66
67 ### 2.2.0:
67 ### 2.2.0:
68 * GUI: use of external plotter
68 * GUI: use of external plotter
69 * Compatible with matplotlib 1.5.0
69 * Compatible with matplotlib 1.5.0
70
70
71 ### 2.1.5:
71 ### 2.1.5:
72 * serializer module added to Signal Chain
72 * serializer module added to Signal Chain
73 * jroplotter.py added to Signal Chain
73 * jroplotter.py added to Signal Chain
74
74
75 ### 2.1.4.2:
75 ### 2.1.4.2:
76 * A new Plotter Class was added
76 * A new Plotter Class was added
77 * Project.start() does not accept filename as a parameter anymore
77 * Project.start() does not accept filename as a parameter anymore
78
78
79 ### 2.1.4.1:
79 ### 2.1.4.1:
80 * Send notifications when an error different to ValueError is detected
80 * Send notifications when an error different to ValueError is detected
81
81
82 ### 2.1.4:
82 ### 2.1.4:
83 * Sending error notifications to signal chain administrator
83 * Sending error notifications to signal chain administrator
84 * Login to email server added
84 * Login to email server added
85
85
86 ### 2.1.3.3:
86 ### 2.1.3.3:
87 * Colored Button Icons were added to GUI
87 * Colored Button Icons were added to GUI
88
88
89 ### 2.1.3.2:
89 ### 2.1.3.2:
90 * GUI: user interaction enhanced
90 * GUI: user interaction enhanced
91 * controller_api.py: Safe access to ControllerThead
91 * controller_api.py: Safe access to ControllerThead
92
92
93 ### 2.1.3.1:
93 ### 2.1.3.1:
94 * GUI: every icon were resized
94 * GUI: every icon were resized
95 * jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file
95 * jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file
96
96
97 ### 2.1.3:
97 ### 2.1.3:
98 * jroplot_heispectra.py: SpectraHeisScope was not showing the right channels
98 * jroplot_heispectra.py: SpectraHeisScope was not showing the right channels
99 * jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value),
99 * jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value),
100 Bug fixed selecting heights by block (selecting profiles instead heights)
100 Bug fixed selecting heights by block (selecting profiles instead heights)
101 * jroproc_voltage.py: New feature added: decoding data by block using FFT.
101 * jroproc_voltage.py: New feature added: decoding data by block using FFT.
102 * jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits instance instead schainpy.mode.data.jrodata.Fits.
102 * jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits instance instead schainpy.mode.data.jrodata.Fits.
103 * jroIO_heispectra.py: Channel index list does not exist.
103 * jroIO_heispectra.py: Channel index list does not exist.
104
104
105 ### 2.1.2:
105 ### 2.1.2:
106 * jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread
106 * jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread
107 Server thread opens and closes remote server each time file list is sent
107 Server thread opens and closes remote server each time file list is sent
108 * jroplot_spectra.py: Noise path was not being created when noise data is saved.
108 * jroplot_spectra.py: Noise path was not being created when noise data is saved.
109 * jroIO_base.py: startTime can be greater than endTime. Example: SpreadF [18:00 * 07:00] No newline at end of file
109 * jroIO_base.py: startTime can be greater than endTime. Example: SpreadF [18:00 * 07:00]
@@ -1,1302 +1,1317
1 '''
1 '''
2 Created on September , 2012
2 Created on September , 2012
3 @author:
3 @author:
4 '''
4 '''
5
5
6 import sys
6 import sys
7 import ast
7 import ast
8 import datetime
8 import datetime
9 import traceback
9 import traceback
10 import math
10 import math
11 import time
11 import time
12 from multiprocessing import Process, cpu_count
12 from multiprocessing import Process, cpu_count
13
13
14 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
14 from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring
15 from xml.dom import minidom
15 from xml.dom import minidom
16
16
17 import schainpy
17 import schainpy
18 import schainpy.admin
18 import schainpy.admin
19 from schainpy.model import *
19 from schainpy.model import *
20 from schainpy.utils import log
20 from schainpy.utils import log
21
21
22 DTYPES = {
22 DTYPES = {
23 'Voltage': '.r',
23 'Voltage': '.r',
24 'Spectra': '.pdata'
24 'Spectra': '.pdata'
25 }
25 }
26
26
27
27 def MPProject(project, n=cpu_count()):
28 def MPProject(project, n=cpu_count()):
28 '''
29 '''
29 Project wrapper to run schain in n processes
30 Project wrapper to run schain in n processes
30 '''
31 '''
31
32
32 rconf = project.getReadUnitObj()
33 rconf = project.getReadUnitObj()
33 op = rconf.getOperationObj('run')
34 op = rconf.getOperationObj('run')
34 dt1 = op.getParameterValue('startDate')
35 dt1 = op.getParameterValue('startDate')
35 dt2 = op.getParameterValue('endDate')
36 dt2 = op.getParameterValue('endDate')
36 days = (dt2 - dt1).days
37 days = (dt2 - dt1).days
37
38
38 for day in range(days+1):
39 for day in range(days + 1):
39 skip = 0
40 skip = 0
40 cursor = 0
41 cursor = 0
41 processes = []
42 processes = []
42 dt = dt1 + datetime.timedelta(day)
43 dt = dt1 + datetime.timedelta(day)
43 dt_str = dt.strftime('%Y/%m/%d')
44 dt_str = dt.strftime('%Y/%m/%d')
44 reader = JRODataReader()
45 reader = JRODataReader()
45 paths, files = reader.searchFilesOffLine(path=rconf.path,
46 paths, files = reader.searchFilesOffLine(path=rconf.path,
46 startDate=dt,
47 startDate=dt,
47 endDate=dt,
48 endDate=dt,
48 ext=DTYPES[rconf.datatype])
49 ext=DTYPES[rconf.datatype])
49 nFiles = len(files)
50 nFiles = len(files)
50 if nFiles == 0:
51 if nFiles == 0:
51 continue
52 continue
52 skip = int(math.ceil(nFiles/n))
53 skip = int(math.ceil(nFiles / n))
53 while nFiles > cursor*skip:
54 while nFiles > cursor * skip:
54 rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor,
55 rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor,
55 skip=skip)
56 skip=skip)
56 p = project.clone()
57 p = project.clone()
57 p.start()
58 p.start()
58 processes.append(p)
59 processes.append(p)
59 cursor += 1
60 cursor += 1
60
61
61 def beforeExit(exctype, value, trace):
62 def beforeExit(exctype, value, trace):
62 for process in processes:
63 for process in processes:
63 process.terminate()
64 process.terminate()
64 process.join()
65 process.join()
65 print traceback.print_tb(trace)
66 print traceback.print_tb(trace)
66
67
67 sys.excepthook = beforeExit
68 sys.excepthook = beforeExit
68
69
69 for process in processes:
70 for process in processes:
70 process.join()
71 process.join()
71 process.terminate()
72 process.terminate()
72
73
73 time.sleep(3)
74 time.sleep(3)
74
75
76
75 class ParameterConf():
77 class ParameterConf():
76
78
77 id = None
79 id = None
78 name = None
80 name = None
79 value = None
81 value = None
80 format = None
82 format = None
81
83
82 __formated_value = None
84 __formated_value = None
83
85
84 ELEMENTNAME = 'Parameter'
86 ELEMENTNAME = 'Parameter'
85
87
86 def __init__(self):
88 def __init__(self):
87
89
88 self.format = 'str'
90 self.format = 'str'
89
91
90 def getElementName(self):
92 def getElementName(self):
91
93
92 return self.ELEMENTNAME
94 return self.ELEMENTNAME
93
95
94 def getValue(self):
96 def getValue(self):
95
97
96 value = self.value
98 value = self.value
97 format = self.format
99 format = self.format
98
100
99 if self.__formated_value != None:
101 if self.__formated_value != None:
100
102
101 return self.__formated_value
103 return self.__formated_value
102
104
103 if format == 'obj':
105 if format == 'obj':
104 return value
106 return value
105
107
106 if format == 'str':
108 if format == 'str':
107 self.__formated_value = str(value)
109 self.__formated_value = str(value)
108 return self.__formated_value
110 return self.__formated_value
109
111
110 if value == '':
112 if value == '':
111 raise ValueError, '%s: This parameter value is empty' %self.name
113 raise ValueError, '%s: This parameter value is empty' % self.name
112
114
113 if format == 'list':
115 if format == 'list':
114 strList = value.split(',')
116 strList = value.split(',')
115
117
116 self.__formated_value = strList
118 self.__formated_value = strList
117
119
118 return self.__formated_value
120 return self.__formated_value
119
121
120 if format == 'intlist':
122 if format == 'intlist':
121 '''
123 '''
122 Example:
124 Example:
123 value = (0,1,2)
125 value = (0,1,2)
124 '''
126 '''
125
127
126 new_value = ast.literal_eval(value)
128 new_value = ast.literal_eval(value)
127
129
128 if type(new_value) not in (tuple, list):
130 if type(new_value) not in (tuple, list):
129 new_value = [int(new_value)]
131 new_value = [int(new_value)]
130
132
131 self.__formated_value = new_value
133 self.__formated_value = new_value
132
134
133 return self.__formated_value
135 return self.__formated_value
134
136
135 if format == 'floatlist':
137 if format == 'floatlist':
136 '''
138 '''
137 Example:
139 Example:
138 value = (0.5, 1.4, 2.7)
140 value = (0.5, 1.4, 2.7)
139 '''
141 '''
140
142
141 new_value = ast.literal_eval(value)
143 new_value = ast.literal_eval(value)
142
144
143 if type(new_value) not in (tuple, list):
145 if type(new_value) not in (tuple, list):
144 new_value = [float(new_value)]
146 new_value = [float(new_value)]
145
147
146 self.__formated_value = new_value
148 self.__formated_value = new_value
147
149
148 return self.__formated_value
150 return self.__formated_value
149
151
150 if format == 'date':
152 if format == 'date':
151 strList = value.split('/')
153 strList = value.split('/')
152 intList = [int(x) for x in strList]
154 intList = [int(x) for x in strList]
153 date = datetime.date(intList[0], intList[1], intList[2])
155 date = datetime.date(intList[0], intList[1], intList[2])
154
156
155 self.__formated_value = date
157 self.__formated_value = date
156
158
157 return self.__formated_value
159 return self.__formated_value
158
160
159 if format == 'time':
161 if format == 'time':
160 strList = value.split(':')
162 strList = value.split(':')
161 intList = [int(x) for x in strList]
163 intList = [int(x) for x in strList]
162 time = datetime.time(intList[0], intList[1], intList[2])
164 time = datetime.time(intList[0], intList[1], intList[2])
163
165
164 self.__formated_value = time
166 self.__formated_value = time
165
167
166 return self.__formated_value
168 return self.__formated_value
167
169
168 if format == 'pairslist':
170 if format == 'pairslist':
169 '''
171 '''
170 Example:
172 Example:
171 value = (0,1),(1,2)
173 value = (0,1),(1,2)
172 '''
174 '''
173
175
174 new_value = ast.literal_eval(value)
176 new_value = ast.literal_eval(value)
175
177
176 if type(new_value) not in (tuple, list):
178 if type(new_value) not in (tuple, list):
177 raise ValueError, '%s has to be a tuple or list of pairs' %value
179 raise ValueError, '%s has to be a tuple or list of pairs' % value
178
180
179 if type(new_value[0]) not in (tuple, list):
181 if type(new_value[0]) not in (tuple, list):
180 if len(new_value) != 2:
182 if len(new_value) != 2:
181 raise ValueError, '%s has to be a tuple or list of pairs' %value
183 raise ValueError, '%s has to be a tuple or list of pairs' % value
182 new_value = [new_value]
184 new_value = [new_value]
183
185
184 for thisPair in new_value:
186 for thisPair in new_value:
185 if len(thisPair) != 2:
187 if len(thisPair) != 2:
186 raise ValueError, '%s has to be a tuple or list of pairs' %value
188 raise ValueError, '%s has to be a tuple or list of pairs' % value
187
189
188 self.__formated_value = new_value
190 self.__formated_value = new_value
189
191
190 return self.__formated_value
192 return self.__formated_value
191
193
192 if format == 'multilist':
194 if format == 'multilist':
193 '''
195 '''
194 Example:
196 Example:
195 value = (0,1,2),(3,4,5)
197 value = (0,1,2),(3,4,5)
196 '''
198 '''
197 multiList = ast.literal_eval(value)
199 multiList = ast.literal_eval(value)
198
200
199 if type(multiList[0]) == int:
201 if type(multiList[0]) == int:
200 multiList = ast.literal_eval('(' + value + ')')
202 multiList = ast.literal_eval('(' + value + ')')
201
203
202 self.__formated_value = multiList
204 self.__formated_value = multiList
203
205
204 return self.__formated_value
206 return self.__formated_value
205
207
206 if format == 'bool':
208 if format == 'bool':
207 value = int(value)
209 value = int(value)
208
210
209 if format == 'int':
211 if format == 'int':
210 value = float(value)
212 value = float(value)
211
213
212 format_func = eval(format)
214 format_func = eval(format)
213
215
214 self.__formated_value = format_func(value)
216 self.__formated_value = format_func(value)
215
217
216 return self.__formated_value
218 return self.__formated_value
217
219
218 def updateId(self, new_id):
220 def updateId(self, new_id):
219
221
220 self.id = str(new_id)
222 self.id = str(new_id)
221
223
222 def setup(self, id, name, value, format='str'):
224 def setup(self, id, name, value, format='str'):
223 self.id = str(id)
225 self.id = str(id)
224 self.name = name
226 self.name = name
225 if format == 'obj':
227 if format == 'obj':
226 self.value = value
228 self.value = value
227 else:
229 else:
228 self.value = str(value)
230 self.value = str(value)
229 self.format = str.lower(format)
231 self.format = str.lower(format)
230
232
231 self.getValue()
233 self.getValue()
232
234
233 return 1
235 return 1
234
236
235 def update(self, name, value, format='str'):
237 def update(self, name, value, format='str'):
236
238
237 self.name = name
239 self.name = name
238 self.value = str(value)
240 self.value = str(value)
239 self.format = format
241 self.format = format
240
242
241 def makeXml(self, opElement):
243 def makeXml(self, opElement):
242 if self.name not in ('queue',):
244 if self.name not in ('queue',):
243 parmElement = SubElement(opElement, self.ELEMENTNAME)
245 parmElement = SubElement(opElement, self.ELEMENTNAME)
244 parmElement.set('id', str(self.id))
246 parmElement.set('id', str(self.id))
245 parmElement.set('name', self.name)
247 parmElement.set('name', self.name)
246 parmElement.set('value', self.value)
248 parmElement.set('value', self.value)
247 parmElement.set('format', self.format)
249 parmElement.set('format', self.format)
248
250
249 def readXml(self, parmElement):
251 def readXml(self, parmElement):
250
252
251 self.id = parmElement.get('id')
253 self.id = parmElement.get('id')
252 self.name = parmElement.get('name')
254 self.name = parmElement.get('name')
253 self.value = parmElement.get('value')
255 self.value = parmElement.get('value')
254 self.format = str.lower(parmElement.get('format'))
256 self.format = str.lower(parmElement.get('format'))
255
257
256 #Compatible with old signal chain version
258 # Compatible with old signal chain version
257 if self.format == 'int' and self.name == 'idfigure':
259 if self.format == 'int' and self.name == 'idfigure':
258 self.name = 'id'
260 self.name = 'id'
259
261
260 def printattr(self):
262 def printattr(self):
261
263
262 print 'Parameter[%s]: name = %s, value = %s, format = %s' %(self.id, self.name, self.value, self.format)
264 print 'Parameter[%s]: name = %s, value = %s, format = %s' % (self.id, self.name, self.value, self.format)
263
265
266
264 class OperationConf():
267 class OperationConf():
265
268
266 id = None
269 id = None
267 name = None
270 name = None
268 priority = None
271 priority = None
269 type = None
272 type = None
270
273
271 parmConfObjList = []
274 parmConfObjList = []
272
275
273 ELEMENTNAME = 'Operation'
276 ELEMENTNAME = 'Operation'
274
277
275 def __init__(self):
278 def __init__(self):
276
279
277 self.id = '0'
280 self.id = '0'
278 self.name = None
281 self.name = None
279 self.priority = None
282 self.priority = None
280 self.type = 'self'
283 self.type = 'self'
281
284
282
283 def __getNewId(self):
285 def __getNewId(self):
284
286
285 return int(self.id)*10 + len(self.parmConfObjList) + 1
287 return int(self.id) * 10 + len(self.parmConfObjList) + 1
286
288
287 def updateId(self, new_id):
289 def updateId(self, new_id):
288
290
289 self.id = str(new_id)
291 self.id = str(new_id)
290
292
291 n = 1
293 n = 1
292 for parmObj in self.parmConfObjList:
294 for parmObj in self.parmConfObjList:
293
295
294 idParm = str(int(new_id)*10 + n)
296 idParm = str(int(new_id) * 10 + n)
295 parmObj.updateId(idParm)
297 parmObj.updateId(idParm)
296
298
297 n += 1
299 n += 1
298
300
299 def getElementName(self):
301 def getElementName(self):
300
302
301 return self.ELEMENTNAME
303 return self.ELEMENTNAME
302
304
303 def getParameterObjList(self):
305 def getParameterObjList(self):
304
306
305 return self.parmConfObjList
307 return self.parmConfObjList
306
308
307 def getParameterObj(self, parameterName):
309 def getParameterObj(self, parameterName):
308
310
309 for parmConfObj in self.parmConfObjList:
311 for parmConfObj in self.parmConfObjList:
310
312
311 if parmConfObj.name != parameterName:
313 if parmConfObj.name != parameterName:
312 continue
314 continue
313
315
314 return parmConfObj
316 return parmConfObj
315
317
316 return None
318 return None
317
319
318 def getParameterObjfromValue(self, parameterValue):
320 def getParameterObjfromValue(self, parameterValue):
319
321
320 for parmConfObj in self.parmConfObjList:
322 for parmConfObj in self.parmConfObjList:
321
323
322 if parmConfObj.getValue() != parameterValue:
324 if parmConfObj.getValue() != parameterValue:
323 continue
325 continue
324
326
325 return parmConfObj.getValue()
327 return parmConfObj.getValue()
326
328
327 return None
329 return None
328
330
329 def getParameterValue(self, parameterName):
331 def getParameterValue(self, parameterName):
330
332
331 parameterObj = self.getParameterObj(parameterName)
333 parameterObj = self.getParameterObj(parameterName)
332
334
333 # if not parameterObj:
335 # if not parameterObj:
334 # return None
336 # return None
335
337
336 value = parameterObj.getValue()
338 value = parameterObj.getValue()
337
339
338 return value
340 return value
339
341
340
341 def getKwargs(self):
342 def getKwargs(self):
342
343
343 kwargs = {}
344 kwargs = {}
344
345
345 for parmConfObj in self.parmConfObjList:
346 for parmConfObj in self.parmConfObjList:
346 if self.name == 'run' and parmConfObj.name == 'datatype':
347 if self.name == 'run' and parmConfObj.name == 'datatype':
347 continue
348 continue
348
349
349 kwargs[parmConfObj.name] = parmConfObj.getValue()
350 kwargs[parmConfObj.name] = parmConfObj.getValue()
350
351
351 return kwargs
352 return kwargs
352
353
353 def setup(self, id, name, priority, type):
354 def setup(self, id, name, priority, type):
354
355
355 self.id = str(id)
356 self.id = str(id)
356 self.name = name
357 self.name = name
357 self.type = type
358 self.type = type
358 self.priority = priority
359 self.priority = priority
359
360
360 self.parmConfObjList = []
361 self.parmConfObjList = []
361
362
362 def removeParameters(self):
363 def removeParameters(self):
363
364
364 for obj in self.parmConfObjList:
365 for obj in self.parmConfObjList:
365 del obj
366 del obj
366
367
367 self.parmConfObjList = []
368 self.parmConfObjList = []
368
369
369 def addParameter(self, name, value, format='str'):
370 def addParameter(self, name, value, format='str'):
370
371
371 if value is None:
372 if value is None:
372 return None
373 return None
373 id = self.__getNewId()
374 id = self.__getNewId()
374
375
375 parmConfObj = ParameterConf()
376 parmConfObj = ParameterConf()
376 if not parmConfObj.setup(id, name, value, format):
377 if not parmConfObj.setup(id, name, value, format):
377 return None
378 return None
378
379
379 self.parmConfObjList.append(parmConfObj)
380 self.parmConfObjList.append(parmConfObj)
380
381
381 return parmConfObj
382 return parmConfObj
382
383
383 def changeParameter(self, name, value, format='str'):
384 def changeParameter(self, name, value, format='str'):
384
385
385 parmConfObj = self.getParameterObj(name)
386 parmConfObj = self.getParameterObj(name)
386 parmConfObj.update(name, value, format)
387 parmConfObj.update(name, value, format)
387
388
388 return parmConfObj
389 return parmConfObj
389
390
390 def makeXml(self, procUnitElement):
391 def makeXml(self, procUnitElement):
391
392
392 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
393 opElement = SubElement(procUnitElement, self.ELEMENTNAME)
393 opElement.set('id', str(self.id))
394 opElement.set('id', str(self.id))
394 opElement.set('name', self.name)
395 opElement.set('name', self.name)
395 opElement.set('type', self.type)
396 opElement.set('type', self.type)
396 opElement.set('priority', str(self.priority))
397 opElement.set('priority', str(self.priority))
397
398
398 for parmConfObj in self.parmConfObjList:
399 for parmConfObj in self.parmConfObjList:
399 parmConfObj.makeXml(opElement)
400 parmConfObj.makeXml(opElement)
400
401
401 def readXml(self, opElement):
402 def readXml(self, opElement):
402
403
403 self.id = opElement.get('id')
404 self.id = opElement.get('id')
404 self.name = opElement.get('name')
405 self.name = opElement.get('name')
405 self.type = opElement.get('type')
406 self.type = opElement.get('type')
406 self.priority = opElement.get('priority')
407 self.priority = opElement.get('priority')
407
408
408 #Compatible with old signal chain version
409 # Compatible with old signal chain version
409 #Use of 'run' method instead 'init'
410 # Use of 'run' method instead 'init'
410 if self.type == 'self' and self.name == 'init':
411 if self.type == 'self' and self.name == 'init':
411 self.name = 'run'
412 self.name = 'run'
412
413
413 self.parmConfObjList = []
414 self.parmConfObjList = []
414
415
415 parmElementList = opElement.iter(ParameterConf().getElementName())
416 parmElementList = opElement.iter(ParameterConf().getElementName())
416
417
417 for parmElement in parmElementList:
418 for parmElement in parmElementList:
418 parmConfObj = ParameterConf()
419 parmConfObj = ParameterConf()
419 parmConfObj.readXml(parmElement)
420 parmConfObj.readXml(parmElement)
420
421
421 #Compatible with old signal chain version
422 # Compatible with old signal chain version
422 #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
423 # If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER
423 if self.type != 'self' and self.name == 'Plot':
424 if self.type != 'self' and self.name == 'Plot':
424 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
425 if parmConfObj.format == 'str' and parmConfObj.name == 'type':
425 self.name = parmConfObj.value
426 self.name = parmConfObj.value
426 continue
427 continue
427
428
428 self.parmConfObjList.append(parmConfObj)
429 self.parmConfObjList.append(parmConfObj)
429
430
430 def printattr(self):
431 def printattr(self):
431
432
432 print '%s[%s]: name = %s, type = %s, priority = %s' %(self.ELEMENTNAME,
433 print '%s[%s]: name = %s, type = %s, priority = %s' % (self.ELEMENTNAME,
433 self.id,
434 self.id,
434 self.name,
435 self.name,
435 self.type,
436 self.type,
436 self.priority)
437 self.priority)
437
438
438 for parmConfObj in self.parmConfObjList:
439 for parmConfObj in self.parmConfObjList:
439 parmConfObj.printattr()
440 parmConfObj.printattr()
440
441
441 def createObject(self, plotter_queue=None):
442 def createObject(self, plotter_queue=None):
442
443
443
444 if self.type == 'self':
444 if self.type == 'self':
445 raise ValueError, 'This operation type cannot be created'
445 raise ValueError, 'This operation type cannot be created'
446
446
447 if self.type == 'plotter':
447 if self.type == 'plotter':
448 if not plotter_queue:
448 if not plotter_queue:
449 raise ValueError, 'plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)'
449 raise ValueError, 'plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)'
450
450
451 opObj = Plotter(self.name, plotter_queue)
451 opObj = Plotter(self.name, plotter_queue)
452
452
453 if self.type == 'external' or self.type == 'other':
453 if self.type == 'external' or self.type == 'other':
454
454
455 className = eval(self.name)
455 className = eval(self.name)
456 kwargs = self.getKwargs()
456 kwargs = self.getKwargs()
457
457
458 opObj = className(**kwargs)
458 opObj = className(**kwargs)
459
459
460 return opObj
460 return opObj
461
461
462
462
463 class ProcUnitConf():
463 class ProcUnitConf():
464
464
465 id = None
465 id = None
466 name = None
466 name = None
467 datatype = None
467 datatype = None
468 inputId = None
468 inputId = None
469 parentId = None
469 parentId = None
470
470
471 opConfObjList = []
471 opConfObjList = []
472
472
473 procUnitObj = None
473 procUnitObj = None
474 opObjList = []
474 opObjList = []
475
475
476 ELEMENTNAME = 'ProcUnit'
476 ELEMENTNAME = 'ProcUnit'
477
477
478 def __init__(self):
478 def __init__(self):
479
479
480 self.id = None
480 self.id = None
481 self.datatype = None
481 self.datatype = None
482 self.name = None
482 self.name = None
483 self.inputId = None
483 self.inputId = None
484
484
485 self.opConfObjList = []
485 self.opConfObjList = []
486
486
487 self.procUnitObj = None
487 self.procUnitObj = None
488 self.opObjDict = {}
488 self.opObjDict = {}
489
489
490 def __getPriority(self):
490 def __getPriority(self):
491
491
492 return len(self.opConfObjList)+1
492 return len(self.opConfObjList) + 1
493
493
494 def __getNewId(self):
494 def __getNewId(self):
495
495
496 return int(self.id)*10 + len(self.opConfObjList) + 1
496 return int(self.id) * 10 + len(self.opConfObjList) + 1
497
497
498 def getElementName(self):
498 def getElementName(self):
499
499
500 return self.ELEMENTNAME
500 return self.ELEMENTNAME
501
501
502 def getId(self):
502 def getId(self):
503
503
504 return self.id
504 return self.id
505
505
506 def updateId(self, new_id, parentId=parentId):
506 def updateId(self, new_id, parentId=parentId):
507
507
508
509 new_id = int(parentId)*10 + (int(self.id) % 10)
508 new_id = int(parentId) * 10 + (int(self.id) % 10)
510 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
509 new_inputId = int(parentId) * 10 + (int(self.inputId) % 10)
511
510
512 #If this proc unit has not inputs
511 # If this proc unit has not inputs
513 if self.inputId == '0':
512 if self.inputId == '0':
514 new_inputId = 0
513 new_inputId = 0
515
514
516 n = 1
515 n = 1
517 for opConfObj in self.opConfObjList:
516 for opConfObj in self.opConfObjList:
518
517
519 idOp = str(int(new_id)*10 + n)
518 idOp = str(int(new_id) * 10 + n)
520 opConfObj.updateId(idOp)
519 opConfObj.updateId(idOp)
521
520
522 n += 1
521 n += 1
523
522
524 self.parentId = str(parentId)
523 self.parentId = str(parentId)
525 self.id = str(new_id)
524 self.id = str(new_id)
526 self.inputId = str(new_inputId)
525 self.inputId = str(new_inputId)
527
526
528
529 def getInputId(self):
527 def getInputId(self):
530
528
531 return self.inputId
529 return self.inputId
532
530
533 def getOperationObjList(self):
531 def getOperationObjList(self):
534
532
535 return self.opConfObjList
533 return self.opConfObjList
536
534
537 def getOperationObj(self, name=None):
535 def getOperationObj(self, name=None):
538
536
539 for opConfObj in self.opConfObjList:
537 for opConfObj in self.opConfObjList:
540
538
541 if opConfObj.name != name:
539 if opConfObj.name != name:
542 continue
540 continue
543
541
544 return opConfObj
542 return opConfObj
545
543
546 return None
544 return None
547
545
548 def getOpObjfromParamValue(self, value=None):
546 def getOpObjfromParamValue(self, value=None):
549
547
550 for opConfObj in self.opConfObjList:
548 for opConfObj in self.opConfObjList:
551 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
549 if opConfObj.getParameterObjfromValue(parameterValue=value) != value:
552 continue
550 continue
553 return opConfObj
551 return opConfObj
554 return None
552 return None
555
553
556 def getProcUnitObj(self):
554 def getProcUnitObj(self):
557
555
558 return self.procUnitObj
556 return self.procUnitObj
559
557
560 def setup(self, id, name, datatype, inputId, parentId=None):
558 def setup(self, id, name, datatype, inputId, parentId=None):
561
559
562 #Compatible with old signal chain version
560 # Compatible with old signal chain version
563 if datatype==None and name==None:
561 if datatype == None and name == None:
564 raise ValueError, 'datatype or name should be defined'
562 raise ValueError, 'datatype or name should be defined'
565
563
566 if name==None:
564 if name == None:
567 if 'Proc' in datatype:
565 if 'Proc' in datatype:
568 name = datatype
566 name = datatype
569 else:
567 else:
570 name = '%sProc' %(datatype)
568 name = '%sProc' % (datatype)
571
569
572 if datatype==None:
570 if datatype == None:
573 datatype = name.replace('Proc','')
571 datatype = name.replace('Proc', '')
574
572
575 self.id = str(id)
573 self.id = str(id)
576 self.name = name
574 self.name = name
577 self.datatype = datatype
575 self.datatype = datatype
578 self.inputId = inputId
576 self.inputId = inputId
579 self.parentId = parentId
577 self.parentId = parentId
580
578
581 self.opConfObjList = []
579 self.opConfObjList = []
582
580
583 self.addOperation(name='run', optype='self')
581 self.addOperation(name='run', optype='self')
584
582
585 def removeOperations(self):
583 def removeOperations(self):
586
584
587 for obj in self.opConfObjList:
585 for obj in self.opConfObjList:
588 del obj
586 del obj
589
587
590 self.opConfObjList = []
588 self.opConfObjList = []
591 self.addOperation(name='run')
589 self.addOperation(name='run')
592
590
593 def addParameter(self, **kwargs):
591 def addParameter(self, **kwargs):
594 '''
592 '''
595 Add parameters to 'run' operation
593 Add parameters to 'run' operation
596 '''
594 '''
597 opObj = self.opConfObjList[0]
595 opObj = self.opConfObjList[0]
598
596
599 opObj.addParameter(**kwargs)
597 opObj.addParameter(**kwargs)
600
598
601 return opObj
599 return opObj
602
600
603 def addOperation(self, name, optype='self'):
601 def addOperation(self, name, optype='self'):
604
602
605 id = self.__getNewId()
603 id = self.__getNewId()
606 priority = self.__getPriority()
604 priority = self.__getPriority()
607
605
608 opConfObj = OperationConf()
606 opConfObj = OperationConf()
609 opConfObj.setup(id, name=name, priority=priority, type=optype)
607 opConfObj.setup(id, name=name, priority=priority, type=optype)
610
608
611 self.opConfObjList.append(opConfObj)
609 self.opConfObjList.append(opConfObj)
612
610
613 return opConfObj
611 return opConfObj
614
612
615 def makeXml(self, projectElement):
613 def makeXml(self, projectElement):
616
614
617 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
615 procUnitElement = SubElement(projectElement, self.ELEMENTNAME)
618 procUnitElement.set('id', str(self.id))
616 procUnitElement.set('id', str(self.id))
619 procUnitElement.set('name', self.name)
617 procUnitElement.set('name', self.name)
620 procUnitElement.set('datatype', self.datatype)
618 procUnitElement.set('datatype', self.datatype)
621 procUnitElement.set('inputId', str(self.inputId))
619 procUnitElement.set('inputId', str(self.inputId))
622
620
623 for opConfObj in self.opConfObjList:
621 for opConfObj in self.opConfObjList:
624 opConfObj.makeXml(procUnitElement)
622 opConfObj.makeXml(procUnitElement)
625
623
626 def readXml(self, upElement):
624 def readXml(self, upElement):
627
625
628 self.id = upElement.get('id')
626 self.id = upElement.get('id')
629 self.name = upElement.get('name')
627 self.name = upElement.get('name')
630 self.datatype = upElement.get('datatype')
628 self.datatype = upElement.get('datatype')
631 self.inputId = upElement.get('inputId')
629 self.inputId = upElement.get('inputId')
632
630
633 if self.ELEMENTNAME == 'ReadUnit':
631 if self.ELEMENTNAME == 'ReadUnit':
634 self.datatype = self.datatype.replace('Reader', '')
632 self.datatype = self.datatype.replace('Reader', '')
635
633
636 if self.ELEMENTNAME == 'ProcUnit':
634 if self.ELEMENTNAME == 'ProcUnit':
637 self.datatype = self.datatype.replace('Proc', '')
635 self.datatype = self.datatype.replace('Proc', '')
638
636
639 if self.inputId == 'None':
637 if self.inputId == 'None':
640 self.inputId = '0'
638 self.inputId = '0'
641
639
642 self.opConfObjList = []
640 self.opConfObjList = []
643
641
644 opElementList = upElement.iter(OperationConf().getElementName())
642 opElementList = upElement.iter(OperationConf().getElementName())
645
643
646 for opElement in opElementList:
644 for opElement in opElementList:
647 opConfObj = OperationConf()
645 opConfObj = OperationConf()
648 opConfObj.readXml(opElement)
646 opConfObj.readXml(opElement)
649 self.opConfObjList.append(opConfObj)
647 self.opConfObjList.append(opConfObj)
650
648
651 def printattr(self):
649 def printattr(self):
652
650
653 print '%s[%s]: name = %s, datatype = %s, inputId = %s' %(self.ELEMENTNAME,
651 print '%s[%s]: name = %s, datatype = %s, inputId = %s' % (self.ELEMENTNAME,
654 self.id,
652 self.id,
655 self.name,
653 self.name,
656 self.datatype,
654 self.datatype,
657 self.inputId)
655 self.inputId)
658
656
659 for opConfObj in self.opConfObjList:
657 for opConfObj in self.opConfObjList:
660 opConfObj.printattr()
658 opConfObj.printattr()
661
659
662
663 def getKwargs(self):
660 def getKwargs(self):
664
661
665 opObj = self.opConfObjList[0]
662 opObj = self.opConfObjList[0]
666 kwargs = opObj.getKwargs()
663 kwargs = opObj.getKwargs()
667
664
668 return kwargs
665 return kwargs
669
666
670 def createObjects(self, plotter_queue=None):
667 def createObjects(self, plotter_queue=None):
671
668
672 className = eval(self.name)
669 className = eval(self.name)
673 kwargs = self.getKwargs()
670 kwargs = self.getKwargs()
674 procUnitObj = className(**kwargs)
671 procUnitObj = className(**kwargs)
675
672
676 for opConfObj in self.opConfObjList:
673 for opConfObj in self.opConfObjList:
677
674
678 if opConfObj.type=='self' and self.name=='run':
675 if opConfObj.type == 'self' and self.name == 'run':
679 continue
676 continue
680 elif opConfObj.type=='self':
677 elif opConfObj.type == 'self':
681 procUnitObj.addOperationKwargs(opConfObj.id, **opConfObj.getKwargs())
678 procUnitObj.addOperationKwargs(
679 opConfObj.id, **opConfObj.getKwargs())
682 continue
680 continue
683
681
684 opObj = opConfObj.createObject(plotter_queue)
682 opObj = opConfObj.createObject(plotter_queue)
685
683
686 self.opObjDict[opConfObj.id] = opObj
684 self.opObjDict[opConfObj.id] = opObj
687
685
688 procUnitObj.addOperation(opObj, opConfObj.id)
686 procUnitObj.addOperation(opObj, opConfObj.id)
689
687
690 self.procUnitObj = procUnitObj
688 self.procUnitObj = procUnitObj
691
689
692 return procUnitObj
690 return procUnitObj
693
691
694 def run(self):
692 def run(self):
695
693
696 is_ok = False
694 is_ok = False
697
695
698 for opConfObj in self.opConfObjList:
696 for opConfObj in self.opConfObjList:
699
697
700 kwargs = {}
698 kwargs = {}
701 for parmConfObj in opConfObj.getParameterObjList():
699 for parmConfObj in opConfObj.getParameterObjList():
702 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
700 if opConfObj.name == 'run' and parmConfObj.name == 'datatype':
703 continue
701 continue
704
702
705 kwargs[parmConfObj.name] = parmConfObj.getValue()
703 kwargs[parmConfObj.name] = parmConfObj.getValue()
706
704
707 sts = self.procUnitObj.call(opType = opConfObj.type,
705 sts = self.procUnitObj.call(opType=opConfObj.type,
708 opName = opConfObj.name,
706 opName=opConfObj.name,
709 opId = opConfObj.id)
707 opId=opConfObj.id)
710
708
711 is_ok = is_ok or sts
709 is_ok = is_ok or sts
712
710
713 return is_ok
711 return is_ok
714
712
715 def close(self):
713 def close(self):
716
714
717 for opConfObj in self.opConfObjList:
715 for opConfObj in self.opConfObjList:
718 if opConfObj.type == 'self':
716 if opConfObj.type == 'self':
719 continue
717 continue
720
718
721 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
719 opObj = self.procUnitObj.getOperationObj(opConfObj.id)
722 opObj.close()
720 opObj.close()
723
721
724 self.procUnitObj.close()
722 self.procUnitObj.close()
725
723
726 return
724 return
727
725
726
728 class ReadUnitConf(ProcUnitConf):
727 class ReadUnitConf(ProcUnitConf):
729
728
730 path = None
729 path = None
731 startDate = None
730 startDate = None
732 endDate = None
731 endDate = None
733 startTime = None
732 startTime = None
734 endTime = None
733 endTime = None
735
734
736 ELEMENTNAME = 'ReadUnit'
735 ELEMENTNAME = 'ReadUnit'
737
736
738 def __init__(self):
737 def __init__(self):
739
738
740 self.id = None
739 self.id = None
741 self.datatype = None
740 self.datatype = None
742 self.name = None
741 self.name = None
743 self.inputId = None
742 self.inputId = None
744
743
745 self.parentId = None
744 self.parentId = None
746
745
747 self.opConfObjList = []
746 self.opConfObjList = []
748 self.opObjList = []
747 self.opObjList = []
749
748
750 def getElementName(self):
749 def getElementName(self):
751
750
752 return self.ELEMENTNAME
751 return self.ELEMENTNAME
753
752
754 def setup(self, id, name, datatype, path='', startDate='', endDate='',
753 def setup(self, id, name, datatype, path='', startDate='', endDate='',
755 startTime='', endTime='', parentId=None, server=None, **kwargs):
754 startTime='', endTime='', parentId=None, server=None, **kwargs):
756
755
757 #Compatible with old signal chain version
756 # Compatible with old signal chain version
758 if datatype==None and name==None:
757 if datatype == None and name == None:
759 raise ValueError, 'datatype or name should be defined'
758 raise ValueError, 'datatype or name should be defined'
760
761 if name == None:
759 if name == None:
762 if 'Reader' in datatype:
760 if 'Reader' in datatype:
763 name = datatype
761 name = datatype
764 datatype = name.replace('Reader','')
762 datatype = name.replace('Reader','')
765 else:
763 else:
766 name = '{}Reader'.format(datatype)
764 name = '{}Reader'.format(datatype)
767 if datatype == None:
765 if datatype == None:
768 if 'Reader' in name:
766 if 'Reader' in name:
769 datatype = name.replace('Reader','')
767 datatype = name.replace('Reader','')
770 else:
768 else:
771 datatype = name
769 datatype = name
772 name = '{}Reader'.format(name)
770 name = '{}Reader'.format(name)
773
771
774 self.id = id
772 self.id = id
775 self.name = name
773 self.name = name
776 self.datatype = datatype
774 self.datatype = datatype
777 if path != '':
775 if path != '':
778 self.path = os.path.abspath(path)
776 self.path = os.path.abspath(path)
779 self.startDate = startDate
777 self.startDate = startDate
780 self.endDate = endDate
778 self.endDate = endDate
781 self.startTime = startTime
779 self.startTime = startTime
782 self.endTime = endTime
780 self.endTime = endTime
783 self.inputId = '0'
781 self.inputId = '0'
784 self.parentId = parentId
782 self.parentId = parentId
785 self.server = server
783 self.server = server
786 self.addRunOperation(**kwargs)
784 self.addRunOperation(**kwargs)
787
785
788 def update(self, **kwargs):
786 def update(self, **kwargs):
789
787
790 if 'datatype' in kwargs:
788 if 'datatype' in kwargs:
791 datatype = kwargs.pop('datatype')
789 datatype = kwargs.pop('datatype')
792 if 'Reader' in datatype:
790 if 'Reader' in datatype:
793 self.name = datatype
791 self.name = datatype
794 else:
792 else:
795 self.name = '%sReader' %(datatype)
793 self.name = '%sReader' % (datatype)
796 self.datatype = self.name.replace('Reader', '')
794 self.datatype = self.name.replace('Reader', '')
797
795
798 attrs = ('path', 'startDate', 'endDate', 'startTime', 'endTime', 'parentId')
796 attrs = ('path', 'startDate', 'endDate',
797 'startTime', 'endTime', 'parentId')
799
798
800 for attr in attrs:
799 for attr in attrs:
801 if attr in kwargs:
800 if attr in kwargs:
802 setattr(self, attr, kwargs.pop(attr))
801 setattr(self, attr, kwargs.pop(attr))
803
802
804 self.inputId = '0'
803 self.inputId = '0'
805 self.updateRunOperation(**kwargs)
804 self.updateRunOperation(**kwargs)
806
805
807 def removeOperations(self):
806 def removeOperations(self):
808
807
809 for obj in self.opConfObjList:
808 for obj in self.opConfObjList:
810 del obj
809 del obj
811
810
812 self.opConfObjList = []
811 self.opConfObjList = []
813
812
814 def addRunOperation(self, **kwargs):
813 def addRunOperation(self, **kwargs):
815
814
816 opObj = self.addOperation(name = 'run', optype = 'self')
815 opObj = self.addOperation(name='run', optype='self')
817
816
818 if self.server is None:
817 if self.server is None:
819 opObj.addParameter(name='datatype', value=self.datatype, format='str')
818 opObj.addParameter(
819 name='datatype', value=self.datatype, format='str')
820 opObj.addParameter(name='path', value=self.path, format='str')
820 opObj.addParameter(name='path', value=self.path, format='str')
821 opObj.addParameter(name='startDate', value=self.startDate, format='date')
821 opObj.addParameter(
822 opObj.addParameter(name='endDate', value=self.endDate, format='date')
822 name='startDate', value=self.startDate, format='date')
823 opObj.addParameter(name='startTime', value=self.startTime, format='time')
823 opObj.addParameter(
824 opObj.addParameter(name='endTime', value=self.endTime, format='time')
824 name='endDate', value=self.endDate, format='date')
825 opObj.addParameter(
826 name='startTime', value=self.startTime, format='time')
827 opObj.addParameter(
828 name='endTime', value=self.endTime, format='time')
825
829
826 for key, value in kwargs.items():
830 for key, value in kwargs.items():
827 opObj.addParameter(name=key, value=value, format=type(value).__name__)
831 opObj.addParameter(name=key, value=value,
832 format=type(value).__name__)
828 else:
833 else:
829 opObj.addParameter(name='server' , value=self.server, format='str')
834 opObj.addParameter(name='server', value=self.server, format='str')
830
835
831
832 return opObj
836 return opObj
833
837
834 def updateRunOperation(self, **kwargs):
838 def updateRunOperation(self, **kwargs):
835
839
836 opObj = self.getOperationObj(name='run')
840 opObj = self.getOperationObj(name='run')
837 opObj.removeParameters()
841 opObj.removeParameters()
838
842
839 opObj.addParameter(name='datatype', value=self.datatype, format='str')
843 opObj.addParameter(name='datatype', value=self.datatype, format='str')
840 opObj.addParameter(name='path', value=self.path, format='str')
844 opObj.addParameter(name='path', value=self.path, format='str')
841 opObj.addParameter(name='startDate', value=self.startDate, format='date')
845 opObj.addParameter(
846 name='startDate', value=self.startDate, format='date')
842 opObj.addParameter(name='endDate', value=self.endDate, format='date')
847 opObj.addParameter(name='endDate', value=self.endDate, format='date')
843 opObj.addParameter(name='startTime', value=self.startTime, format='time')
848 opObj.addParameter(
849 name='startTime', value=self.startTime, format='time')
844 opObj.addParameter(name='endTime', value=self.endTime, format='time')
850 opObj.addParameter(name='endTime', value=self.endTime, format='time')
845
851
846 for key, value in kwargs.items():
852 for key, value in kwargs.items():
847 opObj.addParameter(name=key, value=value, format=type(value).__name__)
853 opObj.addParameter(name=key, value=value,
854 format=type(value).__name__)
848
855
849 return opObj
856 return opObj
850
857
851 def readXml(self, upElement):
858 def readXml(self, upElement):
852
859
853 self.id = upElement.get('id')
860 self.id = upElement.get('id')
854 self.name = upElement.get('name')
861 self.name = upElement.get('name')
855 self.datatype = upElement.get('datatype')
862 self.datatype = upElement.get('datatype')
856 self.inputId = upElement.get('inputId')
863 self.inputId = upElement.get('inputId')
857
864
858 if self.ELEMENTNAME == 'ReadUnit':
865 if self.ELEMENTNAME == 'ReadUnit':
859 self.datatype = self.datatype.replace('Reader', '')
866 self.datatype = self.datatype.replace('Reader', '')
860
867
861 if self.inputId == 'None':
868 if self.inputId == 'None':
862 self.inputId = '0'
869 self.inputId = '0'
863
870
864 self.opConfObjList = []
871 self.opConfObjList = []
865
872
866 opElementList = upElement.iter(OperationConf().getElementName())
873 opElementList = upElement.iter(OperationConf().getElementName())
867
874
868 for opElement in opElementList:
875 for opElement in opElementList:
869 opConfObj = OperationConf()
876 opConfObj = OperationConf()
870 opConfObj.readXml(opElement)
877 opConfObj.readXml(opElement)
871 self.opConfObjList.append(opConfObj)
878 self.opConfObjList.append(opConfObj)
872
879
873 if opConfObj.name == 'run':
880 if opConfObj.name == 'run':
874 self.path = opConfObj.getParameterValue('path')
881 self.path = opConfObj.getParameterValue('path')
875 self.startDate = opConfObj.getParameterValue('startDate')
882 self.startDate = opConfObj.getParameterValue('startDate')
876 self.endDate = opConfObj.getParameterValue('endDate')
883 self.endDate = opConfObj.getParameterValue('endDate')
877 self.startTime = opConfObj.getParameterValue('startTime')
884 self.startTime = opConfObj.getParameterValue('startTime')
878 self.endTime = opConfObj.getParameterValue('endTime')
885 self.endTime = opConfObj.getParameterValue('endTime')
879
886
887
880 class Project(Process):
888 class Project(Process):
881
889
882 id = None
890 id = None
883 # name = None
891 # name = None
884 description = None
892 description = None
885 filename = None
893 filename = None
886
894
887 procUnitConfObjDict = None
895 procUnitConfObjDict = None
888
896
889 ELEMENTNAME = 'Project'
897 ELEMENTNAME = 'Project'
890
898
891 plotterQueue = None
899 plotterQueue = None
892
900
893 def __init__(self, plotter_queue=None):
901 def __init__(self, plotter_queue=None):
894
902
895 Process.__init__(self)
903 Process.__init__(self)
896 self.id = None
904 self.id = None
897 # self.name = None
905 # self.name = None
898 self.description = None
906 self.description = None
899
907
900 self.plotterQueue = plotter_queue
908 self.plotterQueue = plotter_queue
901
909
902 self.procUnitConfObjDict = {}
910 self.procUnitConfObjDict = {}
903
911
904 def __getNewId(self):
912 def __getNewId(self):
905
913
906 idList = self.procUnitConfObjDict.keys()
914 idList = self.procUnitConfObjDict.keys()
907
915
908 id = int(self.id)*10
916 id = int(self.id) * 10
909
917
910 while True:
918 while True:
911 id += 1
919 id += 1
912
920
913 if str(id) in idList:
921 if str(id) in idList:
914 continue
922 continue
915
923
916 break
924 break
917
925
918 return str(id)
926 return str(id)
919
927
920 def getElementName(self):
928 def getElementName(self):
921
929
922 return self.ELEMENTNAME
930 return self.ELEMENTNAME
923
931
924 def getId(self):
932 def getId(self):
925
933
926 return self.id
934 return self.id
927
935
928 def updateId(self, new_id):
936 def updateId(self, new_id):
929
937
930 self.id = str(new_id)
938 self.id = str(new_id)
931
939
932 keyList = self.procUnitConfObjDict.keys()
940 keyList = self.procUnitConfObjDict.keys()
933 keyList.sort()
941 keyList.sort()
934
942
935 n = 1
943 n = 1
936 newProcUnitConfObjDict = {}
944 newProcUnitConfObjDict = {}
937
945
938 for procKey in keyList:
946 for procKey in keyList:
939
947
940 procUnitConfObj = self.procUnitConfObjDict[procKey]
948 procUnitConfObj = self.procUnitConfObjDict[procKey]
941 idProcUnit = str(int(self.id)*10 + n)
949 idProcUnit = str(int(self.id) * 10 + n)
942 procUnitConfObj.updateId(idProcUnit, parentId = self.id)
950 procUnitConfObj.updateId(idProcUnit, parentId=self.id)
943
951
944 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
952 newProcUnitConfObjDict[idProcUnit] = procUnitConfObj
945 n += 1
953 n += 1
946
954
947 self.procUnitConfObjDict = newProcUnitConfObjDict
955 self.procUnitConfObjDict = newProcUnitConfObjDict
948
956
949 def setup(self, id, name='', description=''):
957 def setup(self, id, name='', description=''):
950
958
951 print
959 print
952 print '*'*60
960 print '*' * 60
953 print ' Starting SIGNAL CHAIN PROCESSING v%s ' % schainpy.__version__
961 print ' Starting SIGNAL CHAIN PROCESSING v%s ' % schainpy.__version__
954 print '*'*60
962 print '*' * 60
955 print
963 print
956 self.id = str(id)
964 self.id = str(id)
957 self.description = description
965 self.description = description
958
966
959 def update(self, name, description):
967 def update(self, name, description):
960
968
961 self.description = description
969 self.description = description
962
970
963 def clone(self):
971 def clone(self):
964
972
965 p = Project()
973 p = Project()
966 p.procUnitConfObjDict = self.procUnitConfObjDict
974 p.procUnitConfObjDict = self.procUnitConfObjDict
967 return p
975 return p
968
976
969 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
977 def addReadUnit(self, id=None, datatype=None, name=None, **kwargs):
970
978
971 if id is None:
979 if id is None:
972 idReadUnit = self.__getNewId()
980 idReadUnit = self.__getNewId()
973 else:
981 else:
974 idReadUnit = str(id)
982 idReadUnit = str(id)
975
983
976 readUnitConfObj = ReadUnitConf()
984 readUnitConfObj = ReadUnitConf()
977 readUnitConfObj.setup(idReadUnit, name, datatype, parentId=self.id, **kwargs)
985 readUnitConfObj.setup(idReadUnit, name, datatype,
986 parentId=self.id, **kwargs)
978
987
979 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
988 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
980
989
981 return readUnitConfObj
990 return readUnitConfObj
982
991
983 def addProcUnit(self, inputId='0', datatype=None, name=None):
992 def addProcUnit(self, inputId='0', datatype=None, name=None):
984
993
985 idProcUnit = self.__getNewId()
994 idProcUnit = self.__getNewId()
986
995
987 procUnitConfObj = ProcUnitConf()
996 procUnitConfObj = ProcUnitConf()
988 procUnitConfObj.setup(idProcUnit, name, datatype, inputId, parentId=self.id)
997 procUnitConfObj.setup(idProcUnit, name, datatype,
998 inputId, parentId=self.id)
989
999
990 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1000 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
991
1001
992 return procUnitConfObj
1002 return procUnitConfObj
993
1003
994 def removeProcUnit(self, id):
1004 def removeProcUnit(self, id):
995
1005
996 if id in self.procUnitConfObjDict.keys():
1006 if id in self.procUnitConfObjDict.keys():
997 self.procUnitConfObjDict.pop(id)
1007 self.procUnitConfObjDict.pop(id)
998
1008
999 def getReadUnitId(self):
1009 def getReadUnitId(self):
1000
1010
1001 readUnitConfObj = self.getReadUnitObj()
1011 readUnitConfObj = self.getReadUnitObj()
1002
1012
1003 return readUnitConfObj.id
1013 return readUnitConfObj.id
1004
1014
1005 def getReadUnitObj(self):
1015 def getReadUnitObj(self):
1006
1016
1007 for obj in self.procUnitConfObjDict.values():
1017 for obj in self.procUnitConfObjDict.values():
1008 if obj.getElementName() == 'ReadUnit':
1018 if obj.getElementName() == 'ReadUnit':
1009 return obj
1019 return obj
1010
1020
1011 return None
1021 return None
1012
1022
1013 def getProcUnitObj(self, id=None, name=None):
1023 def getProcUnitObj(self, id=None, name=None):
1014
1024
1015 if id != None:
1025 if id != None:
1016 return self.procUnitConfObjDict[id]
1026 return self.procUnitConfObjDict[id]
1017
1027
1018 if name != None:
1028 if name != None:
1019 return self.getProcUnitObjByName(name)
1029 return self.getProcUnitObjByName(name)
1020
1030
1021 return None
1031 return None
1022
1032
1023 def getProcUnitObjByName(self, name):
1033 def getProcUnitObjByName(self, name):
1024
1034
1025 for obj in self.procUnitConfObjDict.values():
1035 for obj in self.procUnitConfObjDict.values():
1026 if obj.name == name:
1036 if obj.name == name:
1027 return obj
1037 return obj
1028
1038
1029 return None
1039 return None
1030
1040
1031 def procUnitItems(self):
1041 def procUnitItems(self):
1032
1042
1033 return self.procUnitConfObjDict.items()
1043 return self.procUnitConfObjDict.items()
1034
1044
1035 def makeXml(self):
1045 def makeXml(self):
1036
1046
1037 projectElement = Element('Project')
1047 projectElement = Element('Project')
1038 projectElement.set('id', str(self.id))
1048 projectElement.set('id', str(self.id))
1039 projectElement.set('name', self.name)
1049 projectElement.set('name', self.name)
1040 projectElement.set('description', self.description)
1050 projectElement.set('description', self.description)
1041
1051
1042 for procUnitConfObj in self.procUnitConfObjDict.values():
1052 for procUnitConfObj in self.procUnitConfObjDict.values():
1043 procUnitConfObj.makeXml(projectElement)
1053 procUnitConfObj.makeXml(projectElement)
1044
1054
1045 self.projectElement = projectElement
1055 self.projectElement = projectElement
1046
1056
1047 def writeXml(self, filename=None):
1057 def writeXml(self, filename=None):
1048
1058
1049 if filename == None:
1059 if filename == None:
1050 if self.filename:
1060 if self.filename:
1051 filename = self.filename
1061 filename = self.filename
1052 else:
1062 else:
1053 filename = 'schain.xml'
1063 filename = 'schain.xml'
1054
1064
1055 if not filename:
1065 if not filename:
1056 print 'filename has not been defined. Use setFilename(filename) for do it.'
1066 print 'filename has not been defined. Use setFilename(filename) for do it.'
1057 return 0
1067 return 0
1058
1068
1059 abs_file = os.path.abspath(filename)
1069 abs_file = os.path.abspath(filename)
1060
1070
1061 if not os.access(os.path.dirname(abs_file), os.W_OK):
1071 if not os.access(os.path.dirname(abs_file), os.W_OK):
1062 print 'No write permission on %s' %os.path.dirname(abs_file)
1072 print 'No write permission on %s' % os.path.dirname(abs_file)
1063 return 0
1073 return 0
1064
1074
1065 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
1075 if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)):
1066 print 'File %s already exists and it could not be overwriten' %abs_file
1076 print 'File %s already exists and it could not be overwriten' % abs_file
1067 return 0
1077 return 0
1068
1078
1069 self.makeXml()
1079 self.makeXml()
1070
1080
1071 ElementTree(self.projectElement).write(abs_file, method='xml')
1081 ElementTree(self.projectElement).write(abs_file, method='xml')
1072
1082
1073 self.filename = abs_file
1083 self.filename = abs_file
1074
1084
1075 return 1
1085 return 1
1076
1086
1077 def readXml(self, filename = None):
1087 def readXml(self, filename=None):
1078
1088
1079 if not filename:
1089 if not filename:
1080 print 'filename is not defined'
1090 print 'filename is not defined'
1081 return 0
1091 return 0
1082
1092
1083 abs_file = os.path.abspath(filename)
1093 abs_file = os.path.abspath(filename)
1084
1094
1085 if not os.path.isfile(abs_file):
1095 if not os.path.isfile(abs_file):
1086 print '%s file does not exist' %abs_file
1096 print '%s file does not exist' % abs_file
1087 return 0
1097 return 0
1088
1098
1089 self.projectElement = None
1099 self.projectElement = None
1090 self.procUnitConfObjDict = {}
1100 self.procUnitConfObjDict = {}
1091
1101
1092 try:
1102 try:
1093 self.projectElement = ElementTree().parse(abs_file)
1103 self.projectElement = ElementTree().parse(abs_file)
1094 except:
1104 except:
1095 print 'Error reading %s, verify file format' %filename
1105 print 'Error reading %s, verify file format' % filename
1096 return 0
1106 return 0
1097
1107
1098 self.project = self.projectElement.tag
1108 self.project = self.projectElement.tag
1099
1109
1100 self.id = self.projectElement.get('id')
1110 self.id = self.projectElement.get('id')
1101 self.name = self.projectElement.get('name')
1111 self.name = self.projectElement.get('name')
1102 self.description = self.projectElement.get('description')
1112 self.description = self.projectElement.get('description')
1103
1113
1104 readUnitElementList = self.projectElement.iter(ReadUnitConf().getElementName())
1114 readUnitElementList = self.projectElement.iter(
1115 ReadUnitConf().getElementName())
1105
1116
1106 for readUnitElement in readUnitElementList:
1117 for readUnitElement in readUnitElementList:
1107 readUnitConfObj = ReadUnitConf()
1118 readUnitConfObj = ReadUnitConf()
1108 readUnitConfObj.readXml(readUnitElement)
1119 readUnitConfObj.readXml(readUnitElement)
1109
1120
1110 if readUnitConfObj.parentId == None:
1121 if readUnitConfObj.parentId == None:
1111 readUnitConfObj.parentId = self.id
1122 readUnitConfObj.parentId = self.id
1112
1123
1113 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1124 self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj
1114
1125
1115 procUnitElementList = self.projectElement.iter(ProcUnitConf().getElementName())
1126 procUnitElementList = self.projectElement.iter(
1127 ProcUnitConf().getElementName())
1116
1128
1117 for procUnitElement in procUnitElementList:
1129 for procUnitElement in procUnitElementList:
1118 procUnitConfObj = ProcUnitConf()
1130 procUnitConfObj = ProcUnitConf()
1119 procUnitConfObj.readXml(procUnitElement)
1131 procUnitConfObj.readXml(procUnitElement)
1120
1132
1121 if procUnitConfObj.parentId == None:
1133 if procUnitConfObj.parentId == None:
1122 procUnitConfObj.parentId = self.id
1134 procUnitConfObj.parentId = self.id
1123
1135
1124 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1136 self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj
1125
1137
1126 self.filename = abs_file
1138 self.filename = abs_file
1127
1139
1128 return 1
1140 return 1
1129
1141
1130 def printattr(self):
1142 def printattr(self):
1131
1143
1132 print 'Project[%s]: name = %s, description = %s' %(self.id,
1144 print 'Project[%s]: name = %s, description = %s' % (self.id,
1133 self.name,
1145 self.name,
1134 self.description)
1146 self.description)
1135
1147
1136 for procUnitConfObj in self.procUnitConfObjDict.values():
1148 for procUnitConfObj in self.procUnitConfObjDict.values():
1137 procUnitConfObj.printattr()
1149 procUnitConfObj.printattr()
1138
1150
1139 def createObjects(self):
1151 def createObjects(self):
1140
1152
1141 for procUnitConfObj in self.procUnitConfObjDict.values():
1153 for procUnitConfObj in self.procUnitConfObjDict.values():
1142 procUnitConfObj.createObjects(self.plotterQueue)
1154 procUnitConfObj.createObjects(self.plotterQueue)
1143
1155
1144 def __connect(self, objIN, thisObj):
1156 def __connect(self, objIN, thisObj):
1145
1157
1146 thisObj.setInput(objIN.getOutputObj())
1158 thisObj.setInput(objIN.getOutputObj())
1147
1159
1148 def connectObjects(self):
1160 def connectObjects(self):
1149
1161
1150 for thisPUConfObj in self.procUnitConfObjDict.values():
1162 for thisPUConfObj in self.procUnitConfObjDict.values():
1151
1163
1152 inputId = thisPUConfObj.getInputId()
1164 inputId = thisPUConfObj.getInputId()
1153
1165
1154 if int(inputId) == 0:
1166 if int(inputId) == 0:
1155 continue
1167 continue
1156
1168
1157 #Get input object
1169 # Get input object
1158 puConfINObj = self.procUnitConfObjDict[inputId]
1170 puConfINObj = self.procUnitConfObjDict[inputId]
1159 puObjIN = puConfINObj.getProcUnitObj()
1171 puObjIN = puConfINObj.getProcUnitObj()
1160
1172
1161 #Get current object
1173 # Get current object
1162 thisPUObj = thisPUConfObj.getProcUnitObj()
1174 thisPUObj = thisPUConfObj.getProcUnitObj()
1163
1175
1164 self.__connect(puObjIN, thisPUObj)
1176 self.__connect(puObjIN, thisPUObj)
1165
1177
1166 def __handleError(self, procUnitConfObj, send_email=False):
1178 def __handleError(self, procUnitConfObj, send_email=False):
1167
1179
1168 import socket
1180 import socket
1169
1181
1170 err = traceback.format_exception(sys.exc_info()[0],
1182 err = traceback.format_exception(sys.exc_info()[0],
1171 sys.exc_info()[1],
1183 sys.exc_info()[1],
1172 sys.exc_info()[2])
1184 sys.exc_info()[2])
1173
1185
1174 print '***** Error occurred in %s *****' %(procUnitConfObj.name)
1186 print '***** Error occurred in %s *****' % (procUnitConfObj.name)
1175 print '***** %s' %err[-1]
1187 print '***** %s' % err[-1]
1176
1188
1177 message = ''.join(err)
1189 message = ''.join(err)
1178
1190
1179 sys.stderr.write(message)
1191 sys.stderr.write(message)
1180
1192
1181 if not send_email:
1193 if not send_email:
1182 return
1194 return
1183
1195
1184 subject = 'SChain v%s: Error running %s\n' %(schainpy.__version__, procUnitConfObj.name)
1196 subject = 'SChain v%s: Error running %s\n' % (
1197 schainpy.__version__, procUnitConfObj.name)
1185
1198
1186 subtitle = '%s: %s\n' %(procUnitConfObj.getElementName() ,procUnitConfObj.name)
1199 subtitle = '%s: %s\n' % (
1187 subtitle += 'Hostname: %s\n' %socket.gethostbyname(socket.gethostname())
1200 procUnitConfObj.getElementName(), procUnitConfObj.name)
1201 subtitle += 'Hostname: %s\n' % socket.gethostbyname(
1202 socket.gethostname())
1188 subtitle += 'Working directory: %s\n' %os.path.abspath('./')
1203 subtitle += 'Working directory: %s\n' % os.path.abspath('./')
1189 subtitle += 'Configuration file: %s\n' %self.filename
1204 subtitle += 'Configuration file: %s\n' % self.filename
1190 subtitle += 'Time: %s\n' %str(datetime.datetime.now())
1205 subtitle += 'Time: %s\n' % str(datetime.datetime.now())
1191
1206
1192 readUnitConfObj = self.getReadUnitObj()
1207 readUnitConfObj = self.getReadUnitObj()
1193 if readUnitConfObj:
1208 if readUnitConfObj:
1194 subtitle += '\nInput parameters:\n'
1209 subtitle += '\nInput parameters:\n'
1195 subtitle += '[Data path = %s]\n' %readUnitConfObj.path
1210 subtitle += '[Data path = %s]\n' % readUnitConfObj.path
1196 subtitle += '[Data type = %s]\n' %readUnitConfObj.datatype
1211 subtitle += '[Data type = %s]\n' % readUnitConfObj.datatype
1197 subtitle += '[Start date = %s]\n' %readUnitConfObj.startDate
1212 subtitle += '[Start date = %s]\n' % readUnitConfObj.startDate
1198 subtitle += '[End date = %s]\n' %readUnitConfObj.endDate
1213 subtitle += '[End date = %s]\n' % readUnitConfObj.endDate
1199 subtitle += '[Start time = %s]\n' %readUnitConfObj.startTime
1214 subtitle += '[Start time = %s]\n' % readUnitConfObj.startTime
1200 subtitle += '[End time = %s]\n' %readUnitConfObj.endTime
1215 subtitle += '[End time = %s]\n' % readUnitConfObj.endTime
1201
1216
1202 adminObj = schainpy.admin.SchainNotify()
1217 adminObj = schainpy.admin.SchainNotify()
1203 adminObj.sendAlert(message=message,
1218 adminObj.sendAlert(message=message,
1204 subject=subject,
1219 subject=subject,
1205 subtitle=subtitle,
1220 subtitle=subtitle,
1206 filename=self.filename)
1221 filename=self.filename)
1207
1222
1208 def isPaused(self):
1223 def isPaused(self):
1209 return 0
1224 return 0
1210
1225
1211 def isStopped(self):
1226 def isStopped(self):
1212 return 0
1227 return 0
1213
1228
1214 def runController(self):
1229 def runController(self):
1215 '''
1230 '''
1216 returns 0 when this process has been stopped, 1 otherwise
1231 returns 0 when this process has been stopped, 1 otherwise
1217 '''
1232 '''
1218
1233
1219 if self.isPaused():
1234 if self.isPaused():
1220 print 'Process suspended'
1235 print 'Process suspended'
1221
1236
1222 while True:
1237 while True:
1223 time.sleep(0.1)
1238 time.sleep(0.1)
1224
1239
1225 if not self.isPaused():
1240 if not self.isPaused():
1226 break
1241 break
1227
1242
1228 if self.isStopped():
1243 if self.isStopped():
1229 break
1244 break
1230
1245
1231 print 'Process reinitialized'
1246 print 'Process reinitialized'
1232
1247
1233 if self.isStopped():
1248 if self.isStopped():
1234 print 'Process stopped'
1249 print 'Process stopped'
1235 return 0
1250 return 0
1236
1251
1237 return 1
1252 return 1
1238
1253
1239 def setFilename(self, filename):
1254 def setFilename(self, filename):
1240
1255
1241 self.filename = filename
1256 self.filename = filename
1242
1257
1243 def setPlotterQueue(self, plotter_queue):
1258 def setPlotterQueue(self, plotter_queue):
1244
1259
1245 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1260 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1246
1261
1247 def getPlotterQueue(self):
1262 def getPlotterQueue(self):
1248
1263
1249 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1264 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1250
1265
1251 def useExternalPlotter(self):
1266 def useExternalPlotter(self):
1252
1267
1253 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1268 raise NotImplementedError, 'Use schainpy.controller_api.ControllerThread instead Project class'
1254
1269
1255 def run(self):
1270 def run(self):
1256
1271
1257 log.success('Starting {}'.format(self.name))
1272 log.success('Starting {}'.format(self.name))
1258
1273
1259 self.createObjects()
1274 self.createObjects()
1260 self.connectObjects()
1275 self.connectObjects()
1261
1276
1262 keyList = self.procUnitConfObjDict.keys()
1277 keyList = self.procUnitConfObjDict.keys()
1263 keyList.sort()
1278 keyList.sort()
1264
1279
1265 while(True):
1280 while(True):
1266
1281
1267 is_ok = False
1282 is_ok = False
1268
1283
1269 for procKey in keyList:
1284 for procKey in keyList:
1270
1285
1271 procUnitConfObj = self.procUnitConfObjDict[procKey]
1286 procUnitConfObj = self.procUnitConfObjDict[procKey]
1272
1287
1273 try:
1288 try:
1274 sts = procUnitConfObj.run()
1289 sts = procUnitConfObj.run()
1275 is_ok = is_ok or sts
1290 is_ok = is_ok or sts
1276 except KeyboardInterrupt:
1291 except KeyboardInterrupt:
1277 is_ok = False
1292 is_ok = False
1278 break
1293 break
1279 except ValueError, e:
1294 except ValueError, e:
1280 time.sleep(0.5)
1295 time.sleep(0.5)
1281 self.__handleError(procUnitConfObj, send_email=True)
1296 self.__handleError(procUnitConfObj, send_email=True)
1282 is_ok = False
1297 is_ok = False
1283 break
1298 break
1284 except:
1299 except:
1285 time.sleep(0.5)
1300 time.sleep(0.5)
1286 self.__handleError(procUnitConfObj)
1301 self.__handleError(procUnitConfObj)
1287 is_ok = False
1302 is_ok = False
1288 break
1303 break
1289
1304
1290 #If every process unit finished so end process
1305 # If every process unit finished so end process
1291 if not(is_ok):
1306 if not(is_ok):
1292 break
1307 break
1293
1308
1294 if not self.runController():
1309 if not self.runController():
1295 break
1310 break
1296
1311
1297 #Closing every process
1312 # Closing every process
1298 for procKey in keyList:
1313 for procKey in keyList:
1299 procUnitConfObj = self.procUnitConfObjDict[procKey]
1314 procUnitConfObj = self.procUnitConfObjDict[procKey]
1300 procUnitConfObj.close()
1315 procUnitConfObj.close()
1301
1316
1302 log.success('{} finished'.format(self.name))
1317 log.success('{} finished'.format(self.name))
@@ -1,94 +1,92
1 """
1 """
2 Classes to save parameters from Windows.
2 Classes to save parameters from Windows.
3
3
4 -Project window
4 -Project window
5 -Voltage window
5 -Voltage window
6 -Spectra window
6 -Spectra window
7 -SpectraHeis window
7 -SpectraHeis window
8 -Correlation window
8 -Correlation window
9
9
10 """
10 """
11
11
12 class ProjectParms():
12 class ProjectParms():
13
13
14 parmsOk = False
14 parmsOk = False
15 name = None
15 name = None
16 description = None
16 description = None
17 datatype = None
17 datatype = None
18 ext = None
18 ext = None
19 dpath = None
19 dpath = None
20 startDate = None
20 startDate = None
21 endDate = None
21 endDate = None
22 startTime = None
22 startTime = None
23 endTime = None
23 endTime = None
24 online = None
24 online = None
25 delay = None
25 delay = None
26 walk = None
26 walk = None
27 expLabel = None
27 expLabel = None
28 set = None
28 set = None
29 ippKm = None
29 ippKm = None
30
30
31 def __init__(self):
31 def __init__(self):
32
32
33 self.parmsOk = True
33 self.parmsOk = True
34 self.description = ''
34 self.description = ''
35 self.expLabel = ''
35 self.expLabel = ''
36 self.set = ''
36 self.set = ''
37 self.ippKm = ''
37 self.ippKm = ''
38 self.walk = None
38 self.walk = None
39 self.delay = ''
39 self.delay = ''
40
40
41 def getDatatypeIndex(self):
41 def getDatatypeIndex(self):
42
42
43 indexDatatype = None
43 indexDatatype = None
44
44
45 if 'voltage' in self.datatype.lower():
45 if 'voltage' in self.datatype.lower():
46 indexDatatype = 0
46 indexDatatype = 0
47 if 'spectra' in self.datatype.lower():
47 if 'spectra' in self.datatype.lower():
48 indexDatatype = 1
48 indexDatatype = 1
49 if 'fits' in self.datatype.lower():
49 if 'fits' in self.datatype.lower():
50 indexDatatype = 2
50 indexDatatype = 2
51 if 'usrp' in self.datatype.lower():
51 if 'usrp' in self.datatype.lower():
52 indexDatatype = 3
52 indexDatatype = 3
53
54 return indexDatatype
53 return indexDatatype
55
54
56 def getExt(self):
55 def getExt(self):
57
56
58 ext = None
57 ext = None
59
58
60 if self.datatype.lower() == 'voltage':
59 if self.datatype.lower() == 'voltage':
61 ext = '.r'
60 ext = '.r'
62 if self.datatype.lower() == 'spectra':
61 if self.datatype.lower() == 'spectra':
63 ext = '.pdata'
62 ext = '.pdata'
64 if self.datatype.lower() == 'fits':
63 if self.datatype.lower() == 'fits':
65 ext = '.fits'
64 ext = '.fits'
66 if self.datatype.lower() == 'usrp':
65 if self.datatype.lower() == 'usrp':
67 ext = '.hdf5'
66 ext = '.hdf5'
68
69 return ext
67 return ext
70
68
71 def set(self, project_name, datatype, ext, dpath, online,
69 def set(self, project_name, datatype, ext, dpath, online,
72 startDate=None, endDate=None, startTime=None, endTime=None,
70 startDate=None, endDate=None, startTime=None, endTime=None,
73 delay=None, walk=None, set=None, ippKm=None, parmsOk=True, expLabel=''):
71 delay=None, walk=None, set=None, ippKm=None, parmsOk=True, expLabel=''):
74
72
75 name = project_name
73 name = project_name
76 datatype = datatype
74 datatype = datatype
77 ext = ext
75 ext = ext
78 dpath = dpath
76 dpath = dpath
79 startDate = startDate
77 startDate = startDate
80 endDate = endDate
78 endDate = endDate
81 startTime = startTime
79 startTime = startTime
82 endTime = endTime
80 endTime = endTime
83 online = online
81 online = online
84 delay = delay
82 delay = delay
85 walk = walk
83 walk = walk
86 set = set
84 set = set
87 ippKm = ippKm
85 ippKm = ippKm
88 expLabel = expLabel
86 expLabel = expLabel
89
87
90 self.parmsOk = parmsOk
88 self.parmsOk = parmsOk
91
89
92 def isValid(self):
90 def isValid(self):
93
91
94 return self.parmsOk No newline at end of file
92 return self.parmsOk
@@ -1,12 +1,12
1 #from schainpy.model.data.jrodata import *
1 #from schainpy.model.data.jrodata import *
2 # from schainpy.model.io.jrodataIO import *
2 # from schainpy.model.io.jrodataIO import *
3 # from schainpy.model.proc.jroprocessing import *
3 # from schainpy.model.proc.jroprocessing import *
4 # from schainpy.model.graphics.jroplot import *
4 # from schainpy.model.graphics.jroplot import *
5 # from schainpy.model.utils.jroutils import *
5 # from schainpy.model.utils.jroutils import *
6 # from schainpy.serializer import *
6 # from schainpy.serializer import *
7
7
8 from graphics import *
8 from data import *
9 from data import *
9 from io import *
10 from io import *
10 from proc import *
11 from proc import *
11 from graphics import *
12 from utils import *
12 from utils import *
@@ -1,1229 +1,1227
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
4 $Id: JROData.py 173 2012-11-20 15:06:21Z murco $
5 '''
5 '''
6
6
7 import copy
7 import copy
8 import numpy
8 import numpy
9 import datetime
9 import datetime
10
10
11 from jroheaderIO import SystemHeader, RadarControllerHeader
11 from jroheaderIO import SystemHeader, RadarControllerHeader
12 from schainpy import cSchain
12 from schainpy import cSchain
13
13
14
14
15 def getNumpyDtype(dataTypeCode):
15 def getNumpyDtype(dataTypeCode):
16
16
17 if dataTypeCode == 0:
17 if dataTypeCode == 0:
18 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
18 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
19 elif dataTypeCode == 1:
19 elif dataTypeCode == 1:
20 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
20 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
21 elif dataTypeCode == 2:
21 elif dataTypeCode == 2:
22 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
22 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
23 elif dataTypeCode == 3:
23 elif dataTypeCode == 3:
24 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
24 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
25 elif dataTypeCode == 4:
25 elif dataTypeCode == 4:
26 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
26 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
27 elif dataTypeCode == 5:
27 elif dataTypeCode == 5:
28 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
28 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
29 else:
29 else:
30 raise ValueError, 'dataTypeCode was not defined'
30 raise ValueError, 'dataTypeCode was not defined'
31
31
32 return numpyDtype
32 return numpyDtype
33
33
34 def getDataTypeCode(numpyDtype):
34 def getDataTypeCode(numpyDtype):
35
35
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
37 datatype = 0
37 datatype = 0
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
39 datatype = 1
39 datatype = 1
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
41 datatype = 2
41 datatype = 2
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
43 datatype = 3
43 datatype = 3
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
45 datatype = 4
45 datatype = 4
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
47 datatype = 5
47 datatype = 5
48 else:
48 else:
49 datatype = None
49 datatype = None
50
50
51 return datatype
51 return datatype
52
52
53 def hildebrand_sekhon(data, navg):
53 def hildebrand_sekhon(data, navg):
54 """
54 """
55 This method is for the objective determination of the noise level in Doppler spectra. This
55 This method is for the objective determination of the noise level in Doppler spectra. This
56 implementation technique is based on the fact that the standard deviation of the spectral
56 implementation technique is based on the fact that the standard deviation of the spectral
57 densities is equal to the mean spectral density for white Gaussian noise
57 densities is equal to the mean spectral density for white Gaussian noise
58
58
59 Inputs:
59 Inputs:
60 Data : heights
60 Data : heights
61 navg : numbers of averages
61 navg : numbers of averages
62
62
63 Return:
63 Return:
64 -1 : any error
64 -1 : any error
65 anoise : noise's level
65 anoise : noise's level
66 """
66 """
67
67
68 sortdata = numpy.sort(data, axis=None)
68 sortdata = numpy.sort(data, axis=None)
69 # lenOfData = len(sortdata)
69 # lenOfData = len(sortdata)
70 # nums_min = lenOfData*0.2
70 # nums_min = lenOfData*0.2
71 #
71 #
72 # if nums_min <= 5:
72 # if nums_min <= 5:
73 # nums_min = 5
73 # nums_min = 5
74 #
74 #
75 # sump = 0.
75 # sump = 0.
76 #
76 #
77 # sumq = 0.
77 # sumq = 0.
78 #
78 #
79 # j = 0
79 # j = 0
80 #
80 #
81 # cont = 1
81 # cont = 1
82 #
82 #
83 # while((cont==1)and(j<lenOfData)):
83 # while((cont==1)and(j<lenOfData)):
84 #
84 #
85 # sump += sortdata[j]
85 # sump += sortdata[j]
86 #
86 #
87 # sumq += sortdata[j]**2
87 # sumq += sortdata[j]**2
88 #
88 #
89 # if j > nums_min:
89 # if j > nums_min:
90 # rtest = float(j)/(j-1) + 1.0/navg
90 # rtest = float(j)/(j-1) + 1.0/navg
91 # if ((sumq*j) > (rtest*sump**2)):
91 # if ((sumq*j) > (rtest*sump**2)):
92 # j = j - 1
92 # j = j - 1
93 # sump = sump - sortdata[j]
93 # sump = sump - sortdata[j]
94 # sumq = sumq - sortdata[j]**2
94 # sumq = sumq - sortdata[j]**2
95 # cont = 0
95 # cont = 0
96 #
96 #
97 # j += 1
97 # j += 1
98 #
98 #
99 # lnoise = sump /j
99 # lnoise = sump /j
100 #
100 #
101 # return lnoise
101 # return lnoise
102
102
103 return cSchain.hildebrand_sekhon(sortdata, navg)
103 return cSchain.hildebrand_sekhon(sortdata, navg)
104
104
105
105
106 class Beam:
106 class Beam:
107
107
108 def __init__(self):
108 def __init__(self):
109 self.codeList = []
109 self.codeList = []
110 self.azimuthList = []
110 self.azimuthList = []
111 self.zenithList = []
111 self.zenithList = []
112
112
113 class GenericData(object):
113 class GenericData(object):
114
114
115 flagNoData = True
115 flagNoData = True
116
116
117 def copy(self, inputObj=None):
117 def copy(self, inputObj=None):
118
118
119 if inputObj == None:
119 if inputObj == None:
120 return copy.deepcopy(self)
120 return copy.deepcopy(self)
121
121
122 for key in inputObj.__dict__.keys():
122 for key in inputObj.__dict__.keys():
123
123
124 attribute = inputObj.__dict__[key]
124 attribute = inputObj.__dict__[key]
125
125
126 #If this attribute is a tuple or list
126 #If this attribute is a tuple or list
127 if type(inputObj.__dict__[key]) in (tuple, list):
127 if type(inputObj.__dict__[key]) in (tuple, list):
128 self.__dict__[key] = attribute[:]
128 self.__dict__[key] = attribute[:]
129 continue
129 continue
130
130
131 #If this attribute is another object or instance
131 #If this attribute is another object or instance
132 if hasattr(attribute, '__dict__'):
132 if hasattr(attribute, '__dict__'):
133 self.__dict__[key] = attribute.copy()
133 self.__dict__[key] = attribute.copy()
134 continue
134 continue
135
135
136 self.__dict__[key] = inputObj.__dict__[key]
136 self.__dict__[key] = inputObj.__dict__[key]
137
137
138 def deepcopy(self):
138 def deepcopy(self):
139
139
140 return copy.deepcopy(self)
140 return copy.deepcopy(self)
141
141
142 def isEmpty(self):
142 def isEmpty(self):
143
143
144 return self.flagNoData
144 return self.flagNoData
145
145
146 class JROData(GenericData):
146 class JROData(GenericData):
147
147
148 # m_BasicHeader = BasicHeader()
148 # m_BasicHeader = BasicHeader()
149 # m_ProcessingHeader = ProcessingHeader()
149 # m_ProcessingHeader = ProcessingHeader()
150
150
151 systemHeaderObj = SystemHeader()
151 systemHeaderObj = SystemHeader()
152
152
153 radarControllerHeaderObj = RadarControllerHeader()
153 radarControllerHeaderObj = RadarControllerHeader()
154
154
155 # data = None
155 # data = None
156
156
157 type = None
157 type = None
158
158
159 datatype = None #dtype but in string
159 datatype = None #dtype but in string
160
160
161 # dtype = None
161 # dtype = None
162
162
163 # nChannels = None
163 # nChannels = None
164
164
165 # nHeights = None
165 # nHeights = None
166
166
167 nProfiles = None
167 nProfiles = None
168
168
169 heightList = None
169 heightList = None
170
170
171 channelList = None
171 channelList = None
172
172
173 flagDiscontinuousBlock = False
173 flagDiscontinuousBlock = False
174
174
175 useLocalTime = False
175 useLocalTime = False
176
176
177 utctime = None
177 utctime = None
178
178
179 timeZone = None
179 timeZone = None
180
180
181 dstFlag = None
181 dstFlag = None
182
182
183 errorCount = None
183 errorCount = None
184
184
185 blocksize = None
185 blocksize = None
186
186
187 # nCode = None
187 # nCode = None
188 #
188 #
189 # nBaud = None
189 # nBaud = None
190 #
190 #
191 # code = None
191 # code = None
192
192
193 flagDecodeData = False #asumo q la data no esta decodificada
193 flagDecodeData = False #asumo q la data no esta decodificada
194
194
195 flagDeflipData = False #asumo q la data no esta sin flip
195 flagDeflipData = False #asumo q la data no esta sin flip
196
196
197 flagShiftFFT = False
197 flagShiftFFT = False
198
198
199 # ippSeconds = None
199 # ippSeconds = None
200
200
201 # timeInterval = None
201 # timeInterval = None
202
202
203 nCohInt = None
203 nCohInt = None
204
204
205 # noise = None
205 # noise = None
206
206
207 windowOfFilter = 1
207 windowOfFilter = 1
208
208
209 #Speed of ligth
209 #Speed of ligth
210 C = 3e8
210 C = 3e8
211
211
212 frequency = 49.92e6
212 frequency = 49.92e6
213
213
214 realtime = False
214 realtime = False
215
215
216 beacon_heiIndexList = None
216 beacon_heiIndexList = None
217
217
218 last_block = None
218 last_block = None
219
219
220 blocknow = None
220 blocknow = None
221
221
222 azimuth = None
222 azimuth = None
223
223
224 zenith = None
224 zenith = None
225
225
226 beam = Beam()
226 beam = Beam()
227
227
228 profileIndex = None
228 profileIndex = None
229
229
230 def getNoise(self):
230 def getNoise(self):
231
231
232 raise NotImplementedError
232 raise NotImplementedError
233
233
234 def getNChannels(self):
234 def getNChannels(self):
235
235
236 return len(self.channelList)
236 return len(self.channelList)
237
237
238 def getChannelIndexList(self):
238 def getChannelIndexList(self):
239
239
240 return range(self.nChannels)
240 return range(self.nChannels)
241
241
242 def getNHeights(self):
242 def getNHeights(self):
243
243
244 return len(self.heightList)
244 return len(self.heightList)
245
245
246 def getHeiRange(self, extrapoints=0):
246 def getHeiRange(self, extrapoints=0):
247
247
248 heis = self.heightList
248 heis = self.heightList
249 # deltah = self.heightList[1] - self.heightList[0]
249 # deltah = self.heightList[1] - self.heightList[0]
250 #
250 #
251 # heis.append(self.heightList[-1])
251 # heis.append(self.heightList[-1])
252
252
253 return heis
253 return heis
254
254
255 def getDeltaH(self):
255 def getDeltaH(self):
256
256
257 delta = self.heightList[1] - self.heightList[0]
257 delta = self.heightList[1] - self.heightList[0]
258
258
259 return delta
259 return delta
260
260
261 def getltctime(self):
261 def getltctime(self):
262
262
263 if self.useLocalTime:
263 if self.useLocalTime:
264 return self.utctime - self.timeZone*60
264 return self.utctime - self.timeZone*60
265
265
266 return self.utctime
266 return self.utctime
267
267
268 def getDatatime(self):
268 def getDatatime(self):
269
269
270 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
270 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
271 return datatimeValue
271 return datatimeValue
272
272
273 def getTimeRange(self):
273 def getTimeRange(self):
274
274
275 datatime = []
275 datatime = []
276
276
277 datatime.append(self.ltctime)
277 datatime.append(self.ltctime)
278 datatime.append(self.ltctime + self.timeInterval+1)
278 datatime.append(self.ltctime + self.timeInterval+1)
279
279
280 datatime = numpy.array(datatime)
280 datatime = numpy.array(datatime)
281
281
282 return datatime
282 return datatime
283
283
284 def getFmaxTimeResponse(self):
284 def getFmaxTimeResponse(self):
285
285
286 period = (10**-6)*self.getDeltaH()/(0.15)
286 period = (10**-6)*self.getDeltaH()/(0.15)
287
287
288 PRF = 1./(period * self.nCohInt)
288 PRF = 1./(period * self.nCohInt)
289
289
290 fmax = PRF
290 fmax = PRF
291
291
292 return fmax
292 return fmax
293
293
294 def getFmax(self):
294 def getFmax(self):
295
296 PRF = 1./(self.ippSeconds * self.nCohInt)
295 PRF = 1./(self.ippSeconds * self.nCohInt)
297
296
298 fmax = PRF
297 fmax = PRF
299
300 return fmax
298 return fmax
301
299
302 def getVmax(self):
300 def getVmax(self):
303
301
304 _lambda = self.C/self.frequency
302 _lambda = self.C/self.frequency
305
303
306 vmax = self.getFmax() * _lambda/2
304 vmax = self.getFmax() * _lambda/2
307
305
308 return vmax
306 return vmax
309
307
310 def get_ippSeconds(self):
308 def get_ippSeconds(self):
311 '''
309 '''
312 '''
310 '''
313 return self.radarControllerHeaderObj.ippSeconds
311 return self.radarControllerHeaderObj.ippSeconds
314
312
315 def set_ippSeconds(self, ippSeconds):
313 def set_ippSeconds(self, ippSeconds):
316 '''
314 '''
317 '''
315 '''
318
316
319 self.radarControllerHeaderObj.ippSeconds = ippSeconds
317 self.radarControllerHeaderObj.ippSeconds = ippSeconds
320
318
321 return
319 return
322
320
323 def get_dtype(self):
321 def get_dtype(self):
324 '''
322 '''
325 '''
323 '''
326 return getNumpyDtype(self.datatype)
324 return getNumpyDtype(self.datatype)
327
325
328 def set_dtype(self, numpyDtype):
326 def set_dtype(self, numpyDtype):
329 '''
327 '''
330 '''
328 '''
331
329
332 self.datatype = getDataTypeCode(numpyDtype)
330 self.datatype = getDataTypeCode(numpyDtype)
333
331
334 def get_code(self):
332 def get_code(self):
335 '''
333 '''
336 '''
334 '''
337 return self.radarControllerHeaderObj.code
335 return self.radarControllerHeaderObj.code
338
336
339 def set_code(self, code):
337 def set_code(self, code):
340 '''
338 '''
341 '''
339 '''
342 self.radarControllerHeaderObj.code = code
340 self.radarControllerHeaderObj.code = code
343
341
344 return
342 return
345
343
346 def get_ncode(self):
344 def get_ncode(self):
347 '''
345 '''
348 '''
346 '''
349 return self.radarControllerHeaderObj.nCode
347 return self.radarControllerHeaderObj.nCode
350
348
351 def set_ncode(self, nCode):
349 def set_ncode(self, nCode):
352 '''
350 '''
353 '''
351 '''
354 self.radarControllerHeaderObj.nCode = nCode
352 self.radarControllerHeaderObj.nCode = nCode
355
353
356 return
354 return
357
355
358 def get_nbaud(self):
356 def get_nbaud(self):
359 '''
357 '''
360 '''
358 '''
361 return self.radarControllerHeaderObj.nBaud
359 return self.radarControllerHeaderObj.nBaud
362
360
363 def set_nbaud(self, nBaud):
361 def set_nbaud(self, nBaud):
364 '''
362 '''
365 '''
363 '''
366 self.radarControllerHeaderObj.nBaud = nBaud
364 self.radarControllerHeaderObj.nBaud = nBaud
367
365
368 return
366 return
369
367
370 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
368 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
371 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
369 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
372 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
370 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
373 #noise = property(getNoise, "I'm the 'nHeights' property.")
371 #noise = property(getNoise, "I'm the 'nHeights' property.")
374 datatime = property(getDatatime, "I'm the 'datatime' property")
372 datatime = property(getDatatime, "I'm the 'datatime' property")
375 ltctime = property(getltctime, "I'm the 'ltctime' property")
373 ltctime = property(getltctime, "I'm the 'ltctime' property")
376 ippSeconds = property(get_ippSeconds, set_ippSeconds)
374 ippSeconds = property(get_ippSeconds, set_ippSeconds)
377 dtype = property(get_dtype, set_dtype)
375 dtype = property(get_dtype, set_dtype)
378 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
376 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
379 code = property(get_code, set_code)
377 code = property(get_code, set_code)
380 nCode = property(get_ncode, set_ncode)
378 nCode = property(get_ncode, set_ncode)
381 nBaud = property(get_nbaud, set_nbaud)
379 nBaud = property(get_nbaud, set_nbaud)
382
380
383 class Voltage(JROData):
381 class Voltage(JROData):
384
382
385 #data es un numpy array de 2 dmensiones (canales, alturas)
383 #data es un numpy array de 2 dmensiones (canales, alturas)
386 data = None
384 data = None
387
385
388 def __init__(self):
386 def __init__(self):
389 '''
387 '''
390 Constructor
388 Constructor
391 '''
389 '''
392
390
393 self.useLocalTime = True
391 self.useLocalTime = True
394
392
395 self.radarControllerHeaderObj = RadarControllerHeader()
393 self.radarControllerHeaderObj = RadarControllerHeader()
396
394
397 self.systemHeaderObj = SystemHeader()
395 self.systemHeaderObj = SystemHeader()
398
396
399 self.type = "Voltage"
397 self.type = "Voltage"
400
398
401 self.data = None
399 self.data = None
402
400
403 # self.dtype = None
401 # self.dtype = None
404
402
405 # self.nChannels = 0
403 # self.nChannels = 0
406
404
407 # self.nHeights = 0
405 # self.nHeights = 0
408
406
409 self.nProfiles = None
407 self.nProfiles = None
410
408
411 self.heightList = None
409 self.heightList = None
412
410
413 self.channelList = None
411 self.channelList = None
414
412
415 # self.channelIndexList = None
413 # self.channelIndexList = None
416
414
417 self.flagNoData = True
415 self.flagNoData = True
418
416
419 self.flagDiscontinuousBlock = False
417 self.flagDiscontinuousBlock = False
420
418
421 self.utctime = None
419 self.utctime = None
422
420
423 self.timeZone = None
421 self.timeZone = None
424
422
425 self.dstFlag = None
423 self.dstFlag = None
426
424
427 self.errorCount = None
425 self.errorCount = None
428
426
429 self.nCohInt = None
427 self.nCohInt = None
430
428
431 self.blocksize = None
429 self.blocksize = None
432
430
433 self.flagDecodeData = False #asumo q la data no esta decodificada
431 self.flagDecodeData = False #asumo q la data no esta decodificada
434
432
435 self.flagDeflipData = False #asumo q la data no esta sin flip
433 self.flagDeflipData = False #asumo q la data no esta sin flip
436
434
437 self.flagShiftFFT = False
435 self.flagShiftFFT = False
438
436
439 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
437 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
440
438
441 self.profileIndex = 0
439 self.profileIndex = 0
442
440
443 def getNoisebyHildebrand(self, channel = None):
441 def getNoisebyHildebrand(self, channel = None):
444 """
442 """
445 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
443 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
446
444
447 Return:
445 Return:
448 noiselevel
446 noiselevel
449 """
447 """
450
448
451 if channel != None:
449 if channel != None:
452 data = self.data[channel]
450 data = self.data[channel]
453 nChannels = 1
451 nChannels = 1
454 else:
452 else:
455 data = self.data
453 data = self.data
456 nChannels = self.nChannels
454 nChannels = self.nChannels
457
455
458 noise = numpy.zeros(nChannels)
456 noise = numpy.zeros(nChannels)
459 power = data * numpy.conjugate(data)
457 power = data * numpy.conjugate(data)
460
458
461 for thisChannel in range(nChannels):
459 for thisChannel in range(nChannels):
462 if nChannels == 1:
460 if nChannels == 1:
463 daux = power[:].real
461 daux = power[:].real
464 else:
462 else:
465 daux = power[thisChannel,:].real
463 daux = power[thisChannel,:].real
466 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
464 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
467
465
468 return noise
466 return noise
469
467
470 def getNoise(self, type = 1, channel = None):
468 def getNoise(self, type = 1, channel = None):
471
469
472 if type == 1:
470 if type == 1:
473 noise = self.getNoisebyHildebrand(channel)
471 noise = self.getNoisebyHildebrand(channel)
474
472
475 return noise
473 return noise
476
474
477 def getPower(self, channel = None):
475 def getPower(self, channel = None):
478
476
479 if channel != None:
477 if channel != None:
480 data = self.data[channel]
478 data = self.data[channel]
481 else:
479 else:
482 data = self.data
480 data = self.data
483
481
484 power = data * numpy.conjugate(data)
482 power = data * numpy.conjugate(data)
485 powerdB = 10*numpy.log10(power.real)
483 powerdB = 10*numpy.log10(power.real)
486 powerdB = numpy.squeeze(powerdB)
484 powerdB = numpy.squeeze(powerdB)
487
485
488 return powerdB
486 return powerdB
489
487
490 def getTimeInterval(self):
488 def getTimeInterval(self):
491
489
492 timeInterval = self.ippSeconds * self.nCohInt
490 timeInterval = self.ippSeconds * self.nCohInt
493
491
494 return timeInterval
492 return timeInterval
495
493
496 noise = property(getNoise, "I'm the 'nHeights' property.")
494 noise = property(getNoise, "I'm the 'nHeights' property.")
497 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
495 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
498
496
499 class Spectra(JROData):
497 class Spectra(JROData):
500
498
501 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
499 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
502 data_spc = None
500 data_spc = None
503
501
504 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
502 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
505 data_cspc = None
503 data_cspc = None
506
504
507 #data dc es un numpy array de 2 dmensiones (canales, alturas)
505 #data dc es un numpy array de 2 dmensiones (canales, alturas)
508 data_dc = None
506 data_dc = None
509
507
510 #data power
508 #data power
511 data_pwr = None
509 data_pwr = None
512
510
513 nFFTPoints = None
511 nFFTPoints = None
514
512
515 # nPairs = None
513 # nPairs = None
516
514
517 pairsList = None
515 pairsList = None
518
516
519 nIncohInt = None
517 nIncohInt = None
520
518
521 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
519 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
522
520
523 nCohInt = None #se requiere para determinar el valor de timeInterval
521 nCohInt = None #se requiere para determinar el valor de timeInterval
524
522
525 ippFactor = None
523 ippFactor = None
526
524
527 profileIndex = 0
525 profileIndex = 0
528
526
529 plotting = "spectra"
527 plotting = "spectra"
530
528
531 def __init__(self):
529 def __init__(self):
532 '''
530 '''
533 Constructor
531 Constructor
534 '''
532 '''
535
533
536 self.useLocalTime = True
534 self.useLocalTime = True
537
535
538 self.radarControllerHeaderObj = RadarControllerHeader()
536 self.radarControllerHeaderObj = RadarControllerHeader()
539
537
540 self.systemHeaderObj = SystemHeader()
538 self.systemHeaderObj = SystemHeader()
541
539
542 self.type = "Spectra"
540 self.type = "Spectra"
543
541
544 # self.data = None
542 # self.data = None
545
543
546 # self.dtype = None
544 # self.dtype = None
547
545
548 # self.nChannels = 0
546 # self.nChannels = 0
549
547
550 # self.nHeights = 0
548 # self.nHeights = 0
551
549
552 self.nProfiles = None
550 self.nProfiles = None
553
551
554 self.heightList = None
552 self.heightList = None
555
553
556 self.channelList = None
554 self.channelList = None
557
555
558 # self.channelIndexList = None
556 # self.channelIndexList = None
559
557
560 self.pairsList = None
558 self.pairsList = None
561
559
562 self.flagNoData = True
560 self.flagNoData = True
563
561
564 self.flagDiscontinuousBlock = False
562 self.flagDiscontinuousBlock = False
565
563
566 self.utctime = None
564 self.utctime = None
567
565
568 self.nCohInt = None
566 self.nCohInt = None
569
567
570 self.nIncohInt = None
568 self.nIncohInt = None
571
569
572 self.blocksize = None
570 self.blocksize = None
573
571
574 self.nFFTPoints = None
572 self.nFFTPoints = None
575
573
576 self.wavelength = None
574 self.wavelength = None
577
575
578 self.flagDecodeData = False #asumo q la data no esta decodificada
576 self.flagDecodeData = False #asumo q la data no esta decodificada
579
577
580 self.flagDeflipData = False #asumo q la data no esta sin flip
578 self.flagDeflipData = False #asumo q la data no esta sin flip
581
579
582 self.flagShiftFFT = False
580 self.flagShiftFFT = False
583
581
584 self.ippFactor = 1
582 self.ippFactor = 1
585
583
586 #self.noise = None
584 #self.noise = None
587
585
588 self.beacon_heiIndexList = []
586 self.beacon_heiIndexList = []
589
587
590 self.noise_estimation = None
588 self.noise_estimation = None
591
589
592
590
593 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
591 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
594 """
592 """
595 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
593 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
596
594
597 Return:
595 Return:
598 noiselevel
596 noiselevel
599 """
597 """
600
598
601 noise = numpy.zeros(self.nChannels)
599 noise = numpy.zeros(self.nChannels)
602
600
603 for channel in range(self.nChannels):
601 for channel in range(self.nChannels):
604 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
602 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
605 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
603 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
606
604
607 return noise
605 return noise
608
606
609 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
607 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
610
608
611 if self.noise_estimation is not None:
609 if self.noise_estimation is not None:
612 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
610 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
613 else:
611 else:
614 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
612 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
615 return noise
613 return noise
616
614
617 def getFreqRangeTimeResponse(self, extrapoints=0):
615 def getFreqRangeTimeResponse(self, extrapoints=0):
618
616
619 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
617 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
620 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
618 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
621
619
622 return freqrange
620 return freqrange
623
621
624 def getAcfRange(self, extrapoints=0):
622 def getAcfRange(self, extrapoints=0):
625
623
626 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
624 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
627 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
625 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
628
626
629 return freqrange
627 return freqrange
630
628
631 def getFreqRange(self, extrapoints=0):
629 def getFreqRange(self, extrapoints=0):
632
630
633 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
631 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
634 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
632 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
635
633
636 return freqrange
634 return freqrange
637
635
638 def getVelRange(self, extrapoints=0):
636 def getVelRange(self, extrapoints=0):
639
637
640 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
638 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
641 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
639 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
642
640
643 return velrange
641 return velrange
644
642
645 def getNPairs(self):
643 def getNPairs(self):
646
644
647 return len(self.pairsList)
645 return len(self.pairsList)
648
646
649 def getPairsIndexList(self):
647 def getPairsIndexList(self):
650
648
651 return range(self.nPairs)
649 return range(self.nPairs)
652
650
653 def getNormFactor(self):
651 def getNormFactor(self):
654
652
655 pwcode = 1
653 pwcode = 1
656
654
657 if self.flagDecodeData:
655 if self.flagDecodeData:
658 pwcode = numpy.sum(self.code[0]**2)
656 pwcode = numpy.sum(self.code[0]**2)
659 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
657 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
660 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
658 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
661
659
662 return normFactor
660 return normFactor
663
661
664 def getFlagCspc(self):
662 def getFlagCspc(self):
665
663
666 if self.data_cspc is None:
664 if self.data_cspc is None:
667 return True
665 return True
668
666
669 return False
667 return False
670
668
671 def getFlagDc(self):
669 def getFlagDc(self):
672
670
673 if self.data_dc is None:
671 if self.data_dc is None:
674 return True
672 return True
675
673
676 return False
674 return False
677
675
678 def getTimeInterval(self):
676 def getTimeInterval(self):
679
677
680 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
678 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
681
679
682 return timeInterval
680 return timeInterval
683
681
684 def getPower(self):
682 def getPower(self):
685
683
686 factor = self.normFactor
684 factor = self.normFactor
687 z = self.data_spc/factor
685 z = self.data_spc/factor
688 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
686 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
689 avg = numpy.average(z, axis=1)
687 avg = numpy.average(z, axis=1)
690
688
691 return 10*numpy.log10(avg)
689 return 10*numpy.log10(avg)
692
690
693 def getCoherence(self, pairsList=None, phase=False):
691 def getCoherence(self, pairsList=None, phase=False):
694
692
695 z = []
693 z = []
696 if pairsList is None:
694 if pairsList is None:
697 pairsIndexList = self.pairsIndexList
695 pairsIndexList = self.pairsIndexList
698 else:
696 else:
699 pairsIndexList = []
697 pairsIndexList = []
700 for pair in pairsList:
698 for pair in pairsList:
701 if pair not in self.pairsList:
699 if pair not in self.pairsList:
702 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
700 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
703 pairsIndexList.append(self.pairsList.index(pair))
701 pairsIndexList.append(self.pairsList.index(pair))
704 for i in range(len(pairsIndexList)):
702 for i in range(len(pairsIndexList)):
705 pair = self.pairsList[pairsIndexList[i]]
703 pair = self.pairsList[pairsIndexList[i]]
706 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
704 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
707 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
705 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
708 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
706 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
709 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
707 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
710 if phase:
708 if phase:
711 data = numpy.arctan2(avgcoherenceComplex.imag,
709 data = numpy.arctan2(avgcoherenceComplex.imag,
712 avgcoherenceComplex.real)*180/numpy.pi
710 avgcoherenceComplex.real)*180/numpy.pi
713 else:
711 else:
714 data = numpy.abs(avgcoherenceComplex)
712 data = numpy.abs(avgcoherenceComplex)
715
713
716 z.append(data)
714 z.append(data)
717
715
718 return numpy.array(z)
716 return numpy.array(z)
719
717
720 def setValue(self, value):
718 def setValue(self, value):
721
719
722 print "This property should not be initialized"
720 print "This property should not be initialized"
723
721
724 return
722 return
725
723
726 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
724 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
727 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
725 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
728 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
726 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
729 flag_cspc = property(getFlagCspc, setValue)
727 flag_cspc = property(getFlagCspc, setValue)
730 flag_dc = property(getFlagDc, setValue)
728 flag_dc = property(getFlagDc, setValue)
731 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
729 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
732 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
730 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
733
731
734 class SpectraHeis(Spectra):
732 class SpectraHeis(Spectra):
735
733
736 data_spc = None
734 data_spc = None
737
735
738 data_cspc = None
736 data_cspc = None
739
737
740 data_dc = None
738 data_dc = None
741
739
742 nFFTPoints = None
740 nFFTPoints = None
743
741
744 # nPairs = None
742 # nPairs = None
745
743
746 pairsList = None
744 pairsList = None
747
745
748 nCohInt = None
746 nCohInt = None
749
747
750 nIncohInt = None
748 nIncohInt = None
751
749
752 def __init__(self):
750 def __init__(self):
753
751
754 self.radarControllerHeaderObj = RadarControllerHeader()
752 self.radarControllerHeaderObj = RadarControllerHeader()
755
753
756 self.systemHeaderObj = SystemHeader()
754 self.systemHeaderObj = SystemHeader()
757
755
758 self.type = "SpectraHeis"
756 self.type = "SpectraHeis"
759
757
760 # self.dtype = None
758 # self.dtype = None
761
759
762 # self.nChannels = 0
760 # self.nChannels = 0
763
761
764 # self.nHeights = 0
762 # self.nHeights = 0
765
763
766 self.nProfiles = None
764 self.nProfiles = None
767
765
768 self.heightList = None
766 self.heightList = None
769
767
770 self.channelList = None
768 self.channelList = None
771
769
772 # self.channelIndexList = None
770 # self.channelIndexList = None
773
771
774 self.flagNoData = True
772 self.flagNoData = True
775
773
776 self.flagDiscontinuousBlock = False
774 self.flagDiscontinuousBlock = False
777
775
778 # self.nPairs = 0
776 # self.nPairs = 0
779
777
780 self.utctime = None
778 self.utctime = None
781
779
782 self.blocksize = None
780 self.blocksize = None
783
781
784 self.profileIndex = 0
782 self.profileIndex = 0
785
783
786 self.nCohInt = 1
784 self.nCohInt = 1
787
785
788 self.nIncohInt = 1
786 self.nIncohInt = 1
789
787
790 def getNormFactor(self):
788 def getNormFactor(self):
791 pwcode = 1
789 pwcode = 1
792 if self.flagDecodeData:
790 if self.flagDecodeData:
793 pwcode = numpy.sum(self.code[0]**2)
791 pwcode = numpy.sum(self.code[0]**2)
794
792
795 normFactor = self.nIncohInt*self.nCohInt*pwcode
793 normFactor = self.nIncohInt*self.nCohInt*pwcode
796
794
797 return normFactor
795 return normFactor
798
796
799 def getTimeInterval(self):
797 def getTimeInterval(self):
800
798
801 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
799 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
802
800
803 return timeInterval
801 return timeInterval
804
802
805 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
803 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
806 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
804 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
807
805
808 class Fits(JROData):
806 class Fits(JROData):
809
807
810 heightList = None
808 heightList = None
811
809
812 channelList = None
810 channelList = None
813
811
814 flagNoData = True
812 flagNoData = True
815
813
816 flagDiscontinuousBlock = False
814 flagDiscontinuousBlock = False
817
815
818 useLocalTime = False
816 useLocalTime = False
819
817
820 utctime = None
818 utctime = None
821
819
822 timeZone = None
820 timeZone = None
823
821
824 # ippSeconds = None
822 # ippSeconds = None
825
823
826 # timeInterval = None
824 # timeInterval = None
827
825
828 nCohInt = None
826 nCohInt = None
829
827
830 nIncohInt = None
828 nIncohInt = None
831
829
832 noise = None
830 noise = None
833
831
834 windowOfFilter = 1
832 windowOfFilter = 1
835
833
836 #Speed of ligth
834 #Speed of ligth
837 C = 3e8
835 C = 3e8
838
836
839 frequency = 49.92e6
837 frequency = 49.92e6
840
838
841 realtime = False
839 realtime = False
842
840
843
841
844 def __init__(self):
842 def __init__(self):
845
843
846 self.type = "Fits"
844 self.type = "Fits"
847
845
848 self.nProfiles = None
846 self.nProfiles = None
849
847
850 self.heightList = None
848 self.heightList = None
851
849
852 self.channelList = None
850 self.channelList = None
853
851
854 # self.channelIndexList = None
852 # self.channelIndexList = None
855
853
856 self.flagNoData = True
854 self.flagNoData = True
857
855
858 self.utctime = None
856 self.utctime = None
859
857
860 self.nCohInt = 1
858 self.nCohInt = 1
861
859
862 self.nIncohInt = 1
860 self.nIncohInt = 1
863
861
864 self.useLocalTime = True
862 self.useLocalTime = True
865
863
866 self.profileIndex = 0
864 self.profileIndex = 0
867
865
868 # self.utctime = None
866 # self.utctime = None
869 # self.timeZone = None
867 # self.timeZone = None
870 # self.ltctime = None
868 # self.ltctime = None
871 # self.timeInterval = None
869 # self.timeInterval = None
872 # self.header = None
870 # self.header = None
873 # self.data_header = None
871 # self.data_header = None
874 # self.data = None
872 # self.data = None
875 # self.datatime = None
873 # self.datatime = None
876 # self.flagNoData = False
874 # self.flagNoData = False
877 # self.expName = ''
875 # self.expName = ''
878 # self.nChannels = None
876 # self.nChannels = None
879 # self.nSamples = None
877 # self.nSamples = None
880 # self.dataBlocksPerFile = None
878 # self.dataBlocksPerFile = None
881 # self.comments = ''
879 # self.comments = ''
882 #
880 #
883
881
884
882
885 def getltctime(self):
883 def getltctime(self):
886
884
887 if self.useLocalTime:
885 if self.useLocalTime:
888 return self.utctime - self.timeZone*60
886 return self.utctime - self.timeZone*60
889
887
890 return self.utctime
888 return self.utctime
891
889
892 def getDatatime(self):
890 def getDatatime(self):
893
891
894 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
892 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
895 return datatime
893 return datatime
896
894
897 def getTimeRange(self):
895 def getTimeRange(self):
898
896
899 datatime = []
897 datatime = []
900
898
901 datatime.append(self.ltctime)
899 datatime.append(self.ltctime)
902 datatime.append(self.ltctime + self.timeInterval)
900 datatime.append(self.ltctime + self.timeInterval)
903
901
904 datatime = numpy.array(datatime)
902 datatime = numpy.array(datatime)
905
903
906 return datatime
904 return datatime
907
905
908 def getHeiRange(self):
906 def getHeiRange(self):
909
907
910 heis = self.heightList
908 heis = self.heightList
911
909
912 return heis
910 return heis
913
911
914 def getNHeights(self):
912 def getNHeights(self):
915
913
916 return len(self.heightList)
914 return len(self.heightList)
917
915
918 def getNChannels(self):
916 def getNChannels(self):
919
917
920 return len(self.channelList)
918 return len(self.channelList)
921
919
922 def getChannelIndexList(self):
920 def getChannelIndexList(self):
923
921
924 return range(self.nChannels)
922 return range(self.nChannels)
925
923
926 def getNoise(self, type = 1):
924 def getNoise(self, type = 1):
927
925
928 #noise = numpy.zeros(self.nChannels)
926 #noise = numpy.zeros(self.nChannels)
929
927
930 if type == 1:
928 if type == 1:
931 noise = self.getNoisebyHildebrand()
929 noise = self.getNoisebyHildebrand()
932
930
933 if type == 2:
931 if type == 2:
934 noise = self.getNoisebySort()
932 noise = self.getNoisebySort()
935
933
936 if type == 3:
934 if type == 3:
937 noise = self.getNoisebyWindow()
935 noise = self.getNoisebyWindow()
938
936
939 return noise
937 return noise
940
938
941 def getTimeInterval(self):
939 def getTimeInterval(self):
942
940
943 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
941 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
944
942
945 return timeInterval
943 return timeInterval
946
944
947 datatime = property(getDatatime, "I'm the 'datatime' property")
945 datatime = property(getDatatime, "I'm the 'datatime' property")
948 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
946 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
949 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
947 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
950 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
948 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
951 noise = property(getNoise, "I'm the 'nHeights' property.")
949 noise = property(getNoise, "I'm the 'nHeights' property.")
952
950
953 ltctime = property(getltctime, "I'm the 'ltctime' property")
951 ltctime = property(getltctime, "I'm the 'ltctime' property")
954 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
952 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
955
953
956
954
957 class Correlation(JROData):
955 class Correlation(JROData):
958
956
959 noise = None
957 noise = None
960
958
961 SNR = None
959 SNR = None
962
960
963 #--------------------------------------------------
961 #--------------------------------------------------
964
962
965 mode = None
963 mode = None
966
964
967 split = False
965 split = False
968
966
969 data_cf = None
967 data_cf = None
970
968
971 lags = None
969 lags = None
972
970
973 lagRange = None
971 lagRange = None
974
972
975 pairsList = None
973 pairsList = None
976
974
977 normFactor = None
975 normFactor = None
978
976
979 #--------------------------------------------------
977 #--------------------------------------------------
980
978
981 # calculateVelocity = None
979 # calculateVelocity = None
982
980
983 nLags = None
981 nLags = None
984
982
985 nPairs = None
983 nPairs = None
986
984
987 nAvg = None
985 nAvg = None
988
986
989
987
990 def __init__(self):
988 def __init__(self):
991 '''
989 '''
992 Constructor
990 Constructor
993 '''
991 '''
994 self.radarControllerHeaderObj = RadarControllerHeader()
992 self.radarControllerHeaderObj = RadarControllerHeader()
995
993
996 self.systemHeaderObj = SystemHeader()
994 self.systemHeaderObj = SystemHeader()
997
995
998 self.type = "Correlation"
996 self.type = "Correlation"
999
997
1000 self.data = None
998 self.data = None
1001
999
1002 self.dtype = None
1000 self.dtype = None
1003
1001
1004 self.nProfiles = None
1002 self.nProfiles = None
1005
1003
1006 self.heightList = None
1004 self.heightList = None
1007
1005
1008 self.channelList = None
1006 self.channelList = None
1009
1007
1010 self.flagNoData = True
1008 self.flagNoData = True
1011
1009
1012 self.flagDiscontinuousBlock = False
1010 self.flagDiscontinuousBlock = False
1013
1011
1014 self.utctime = None
1012 self.utctime = None
1015
1013
1016 self.timeZone = None
1014 self.timeZone = None
1017
1015
1018 self.dstFlag = None
1016 self.dstFlag = None
1019
1017
1020 self.errorCount = None
1018 self.errorCount = None
1021
1019
1022 self.blocksize = None
1020 self.blocksize = None
1023
1021
1024 self.flagDecodeData = False #asumo q la data no esta decodificada
1022 self.flagDecodeData = False #asumo q la data no esta decodificada
1025
1023
1026 self.flagDeflipData = False #asumo q la data no esta sin flip
1024 self.flagDeflipData = False #asumo q la data no esta sin flip
1027
1025
1028 self.pairsList = None
1026 self.pairsList = None
1029
1027
1030 self.nPoints = None
1028 self.nPoints = None
1031
1029
1032 def getPairsList(self):
1030 def getPairsList(self):
1033
1031
1034 return self.pairsList
1032 return self.pairsList
1035
1033
1036 def getNoise(self, mode = 2):
1034 def getNoise(self, mode = 2):
1037
1035
1038 indR = numpy.where(self.lagR == 0)[0][0]
1036 indR = numpy.where(self.lagR == 0)[0][0]
1039 indT = numpy.where(self.lagT == 0)[0][0]
1037 indT = numpy.where(self.lagT == 0)[0][0]
1040
1038
1041 jspectra0 = self.data_corr[:,:,indR,:]
1039 jspectra0 = self.data_corr[:,:,indR,:]
1042 jspectra = copy.copy(jspectra0)
1040 jspectra = copy.copy(jspectra0)
1043
1041
1044 num_chan = jspectra.shape[0]
1042 num_chan = jspectra.shape[0]
1045 num_hei = jspectra.shape[2]
1043 num_hei = jspectra.shape[2]
1046
1044
1047 freq_dc = jspectra.shape[1]/2
1045 freq_dc = jspectra.shape[1]/2
1048 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1046 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1049
1047
1050 if ind_vel[0]<0:
1048 if ind_vel[0]<0:
1051 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1049 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1052
1050
1053 if mode == 1:
1051 if mode == 1:
1054 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1052 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1055
1053
1056 if mode == 2:
1054 if mode == 2:
1057
1055
1058 vel = numpy.array([-2,-1,1,2])
1056 vel = numpy.array([-2,-1,1,2])
1059 xx = numpy.zeros([4,4])
1057 xx = numpy.zeros([4,4])
1060
1058
1061 for fil in range(4):
1059 for fil in range(4):
1062 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1060 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1063
1061
1064 xx_inv = numpy.linalg.inv(xx)
1062 xx_inv = numpy.linalg.inv(xx)
1065 xx_aux = xx_inv[0,:]
1063 xx_aux = xx_inv[0,:]
1066
1064
1067 for ich in range(num_chan):
1065 for ich in range(num_chan):
1068 yy = jspectra[ich,ind_vel,:]
1066 yy = jspectra[ich,ind_vel,:]
1069 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1067 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1070
1068
1071 junkid = jspectra[ich,freq_dc,:]<=0
1069 junkid = jspectra[ich,freq_dc,:]<=0
1072 cjunkid = sum(junkid)
1070 cjunkid = sum(junkid)
1073
1071
1074 if cjunkid.any():
1072 if cjunkid.any():
1075 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1073 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1076
1074
1077 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1075 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1078
1076
1079 return noise
1077 return noise
1080
1078
1081 def getTimeInterval(self):
1079 def getTimeInterval(self):
1082
1080
1083 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1081 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
1084
1082
1085 return timeInterval
1083 return timeInterval
1086
1084
1087 def splitFunctions(self):
1085 def splitFunctions(self):
1088
1086
1089 pairsList = self.pairsList
1087 pairsList = self.pairsList
1090 ccf_pairs = []
1088 ccf_pairs = []
1091 acf_pairs = []
1089 acf_pairs = []
1092 ccf_ind = []
1090 ccf_ind = []
1093 acf_ind = []
1091 acf_ind = []
1094 for l in range(len(pairsList)):
1092 for l in range(len(pairsList)):
1095 chan0 = pairsList[l][0]
1093 chan0 = pairsList[l][0]
1096 chan1 = pairsList[l][1]
1094 chan1 = pairsList[l][1]
1097
1095
1098 #Obteniendo pares de Autocorrelacion
1096 #Obteniendo pares de Autocorrelacion
1099 if chan0 == chan1:
1097 if chan0 == chan1:
1100 acf_pairs.append(chan0)
1098 acf_pairs.append(chan0)
1101 acf_ind.append(l)
1099 acf_ind.append(l)
1102 else:
1100 else:
1103 ccf_pairs.append(pairsList[l])
1101 ccf_pairs.append(pairsList[l])
1104 ccf_ind.append(l)
1102 ccf_ind.append(l)
1105
1103
1106 data_acf = self.data_cf[acf_ind]
1104 data_acf = self.data_cf[acf_ind]
1107 data_ccf = self.data_cf[ccf_ind]
1105 data_ccf = self.data_cf[ccf_ind]
1108
1106
1109 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1107 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1110
1108
1111 def getNormFactor(self):
1109 def getNormFactor(self):
1112 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1110 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1113 acf_pairs = numpy.array(acf_pairs)
1111 acf_pairs = numpy.array(acf_pairs)
1114 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1112 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1115
1113
1116 for p in range(self.nPairs):
1114 for p in range(self.nPairs):
1117 pair = self.pairsList[p]
1115 pair = self.pairsList[p]
1118
1116
1119 ch0 = pair[0]
1117 ch0 = pair[0]
1120 ch1 = pair[1]
1118 ch1 = pair[1]
1121
1119
1122 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1120 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1123 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1121 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1124 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1122 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1125
1123
1126 return normFactor
1124 return normFactor
1127
1125
1128 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1126 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1129 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1127 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1130
1128
1131 class Parameters(Spectra):
1129 class Parameters(Spectra):
1132
1130
1133 experimentInfo = None #Information about the experiment
1131 experimentInfo = None #Information about the experiment
1134
1132
1135 #Information from previous data
1133 #Information from previous data
1136
1134
1137 inputUnit = None #Type of data to be processed
1135 inputUnit = None #Type of data to be processed
1138
1136
1139 operation = None #Type of operation to parametrize
1137 operation = None #Type of operation to parametrize
1140
1138
1141 #normFactor = None #Normalization Factor
1139 #normFactor = None #Normalization Factor
1142
1140
1143 groupList = None #List of Pairs, Groups, etc
1141 groupList = None #List of Pairs, Groups, etc
1144
1142
1145 #Parameters
1143 #Parameters
1146
1144
1147 data_param = None #Parameters obtained
1145 data_param = None #Parameters obtained
1148
1146
1149 data_pre = None #Data Pre Parametrization
1147 data_pre = None #Data Pre Parametrization
1150
1148
1151 data_SNR = None #Signal to Noise Ratio
1149 data_SNR = None #Signal to Noise Ratio
1152
1150
1153 # heightRange = None #Heights
1151 # heightRange = None #Heights
1154
1152
1155 abscissaList = None #Abscissa, can be velocities, lags or time
1153 abscissaList = None #Abscissa, can be velocities, lags or time
1156
1154
1157 # noise = None #Noise Potency
1155 # noise = None #Noise Potency
1158
1156
1159 utctimeInit = None #Initial UTC time
1157 utctimeInit = None #Initial UTC time
1160
1158
1161 paramInterval = None #Time interval to calculate Parameters in seconds
1159 paramInterval = None #Time interval to calculate Parameters in seconds
1162
1160
1163 useLocalTime = True
1161 useLocalTime = True
1164
1162
1165 #Fitting
1163 #Fitting
1166
1164
1167 data_error = None #Error of the estimation
1165 data_error = None #Error of the estimation
1168
1166
1169 constants = None
1167 constants = None
1170
1168
1171 library = None
1169 library = None
1172
1170
1173 #Output signal
1171 #Output signal
1174
1172
1175 outputInterval = None #Time interval to calculate output signal in seconds
1173 outputInterval = None #Time interval to calculate output signal in seconds
1176
1174
1177 data_output = None #Out signal
1175 data_output = None #Out signal
1178
1176
1179 nAvg = None
1177 nAvg = None
1180
1178
1181 noise_estimation = None
1179 noise_estimation = None
1182
1180
1183 GauSPC = None #Fit gaussian SPC
1181 GauSPC = None #Fit gaussian SPC
1184
1182
1185
1183
1186 def __init__(self):
1184 def __init__(self):
1187 '''
1185 '''
1188 Constructor
1186 Constructor
1189 '''
1187 '''
1190 self.radarControllerHeaderObj = RadarControllerHeader()
1188 self.radarControllerHeaderObj = RadarControllerHeader()
1191
1189
1192 self.systemHeaderObj = SystemHeader()
1190 self.systemHeaderObj = SystemHeader()
1193
1191
1194 self.type = "Parameters"
1192 self.type = "Parameters"
1195
1193
1196 def getTimeRange1(self, interval):
1194 def getTimeRange1(self, interval):
1197
1195
1198 datatime = []
1196 datatime = []
1199
1197
1200 if self.useLocalTime:
1198 if self.useLocalTime:
1201 time1 = self.utctimeInit - self.timeZone*60
1199 time1 = self.utctimeInit - self.timeZone*60
1202 else:
1200 else:
1203 time1 = self.utctimeInit
1201 time1 = self.utctimeInit
1204
1202
1205 datatime.append(time1)
1203 datatime.append(time1)
1206 datatime.append(time1 + interval)
1204 datatime.append(time1 + interval)
1207 datatime = numpy.array(datatime)
1205 datatime = numpy.array(datatime)
1208
1206
1209 return datatime
1207 return datatime
1210
1208
1211 def getTimeInterval(self):
1209 def getTimeInterval(self):
1212
1210
1213 if hasattr(self, 'timeInterval1'):
1211 if hasattr(self, 'timeInterval1'):
1214 return self.timeInterval1
1212 return self.timeInterval1
1215 else:
1213 else:
1216 return self.paramInterval
1214 return self.paramInterval
1217
1215
1218 def setValue(self, value):
1216 def setValue(self, value):
1219
1217
1220 print "This property should not be initialized"
1218 print "This property should not be initialized"
1221
1219
1222 return
1220 return
1223
1221
1224 def getNoise(self):
1222 def getNoise(self):
1225
1223
1226 return self.spc_noise
1224 return self.spc_noise
1227
1225
1228 timeInterval = property(getTimeInterval)
1226 timeInterval = property(getTimeInterval)
1229 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1227 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
@@ -1,851 +1,876
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 import inspect
10
11
11 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 3e8
13 SPEED_OF_LIGHT = 3e8
13
14
14 BASIC_STRUCTURE = numpy.dtype([
15 BASIC_STRUCTURE = numpy.dtype([
15 ('nSize','<u4'),
16 ('nSize','<u4'),
16 ('nVersion','<u2'),
17 ('nVersion','<u2'),
17 ('nDataBlockId','<u4'),
18 ('nDataBlockId','<u4'),
18 ('nUtime','<u4'),
19 ('nUtime','<u4'),
19 ('nMilsec','<u2'),
20 ('nMilsec','<u2'),
20 ('nTimezone','<i2'),
21 ('nTimezone','<i2'),
21 ('nDstflag','<i2'),
22 ('nDstflag','<i2'),
22 ('nErrorCount','<u4')
23 ('nErrorCount','<u4')
23 ])
24 ])
24
25
25 SYSTEM_STRUCTURE = numpy.dtype([
26 SYSTEM_STRUCTURE = numpy.dtype([
26 ('nSize','<u4'),
27 ('nSize','<u4'),
27 ('nNumSamples','<u4'),
28 ('nNumSamples','<u4'),
28 ('nNumProfiles','<u4'),
29 ('nNumProfiles','<u4'),
29 ('nNumChannels','<u4'),
30 ('nNumChannels','<u4'),
30 ('nADCResolution','<u4'),
31 ('nADCResolution','<u4'),
31 ('nPCDIOBusWidth','<u4'),
32 ('nPCDIOBusWidth','<u4'),
32 ])
33 ])
33
34
34 RADAR_STRUCTURE = numpy.dtype([
35 RADAR_STRUCTURE = numpy.dtype([
35 ('nSize','<u4'),
36 ('nSize','<u4'),
36 ('nExpType','<u4'),
37 ('nExpType','<u4'),
37 ('nNTx','<u4'),
38 ('nNTx','<u4'),
38 ('fIpp','<f4'),
39 ('fIpp','<f4'),
39 ('fTxA','<f4'),
40 ('fTxA','<f4'),
40 ('fTxB','<f4'),
41 ('fTxB','<f4'),
41 ('nNumWindows','<u4'),
42 ('nNumWindows','<u4'),
42 ('nNumTaus','<u4'),
43 ('nNumTaus','<u4'),
43 ('nCodeType','<u4'),
44 ('nCodeType','<u4'),
44 ('nLine6Function','<u4'),
45 ('nLine6Function','<u4'),
45 ('nLine5Function','<u4'),
46 ('nLine5Function','<u4'),
46 ('fClock','<f4'),
47 ('fClock','<f4'),
47 ('nPrePulseBefore','<u4'),
48 ('nPrePulseBefore','<u4'),
48 ('nPrePulseAfter','<u4'),
49 ('nPrePulseAfter','<u4'),
49 ('sRangeIPP','<a20'),
50 ('sRangeIPP','<a20'),
50 ('sRangeTxA','<a20'),
51 ('sRangeTxA','<a20'),
51 ('sRangeTxB','<a20'),
52 ('sRangeTxB','<a20'),
52 ])
53 ])
53
54
54 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
55 SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
55
56
56
57
57 PROCESSING_STRUCTURE = numpy.dtype([
58 PROCESSING_STRUCTURE = numpy.dtype([
58 ('nSize','<u4'),
59 ('nSize','<u4'),
59 ('nDataType','<u4'),
60 ('nDataType','<u4'),
60 ('nSizeOfDataBlock','<u4'),
61 ('nSizeOfDataBlock','<u4'),
61 ('nProfilesperBlock','<u4'),
62 ('nProfilesperBlock','<u4'),
62 ('nDataBlocksperFile','<u4'),
63 ('nDataBlocksperFile','<u4'),
63 ('nNumWindows','<u4'),
64 ('nNumWindows','<u4'),
64 ('nProcessFlags','<u4'),
65 ('nProcessFlags','<u4'),
65 ('nCoherentIntegrations','<u4'),
66 ('nCoherentIntegrations','<u4'),
66 ('nIncoherentIntegrations','<u4'),
67 ('nIncoherentIntegrations','<u4'),
67 ('nTotalSpectra','<u4')
68 ('nTotalSpectra','<u4')
68 ])
69 ])
69
70
70 class Header(object):
71 class Header(object):
71
72
72 def __init__(self):
73 def __init__(self):
73 raise NotImplementedError
74 raise NotImplementedError
74
75
75 def copy(self):
76 def copy(self):
76 return copy.deepcopy(self)
77 return copy.deepcopy(self)
77
78
78 def read(self):
79 def read(self):
79
80
80 raise NotImplementedError
81 raise NotImplementedError
81
82
82 def write(self):
83 def write(self):
83
84
84 raise NotImplementedError
85 raise NotImplementedError
85
86
87 def getAllowedArgs(self):
88 args = inspect.getargspec(self.__init__).args
89 try:
90 args.remove('self')
91 except:
92 pass
93 return args
94
95 def getAsDict(self):
96 args = self.getAllowedArgs()
97 asDict = {}
98 for x in args:
99 asDict[x] = self[x]
100 return asDict
101
102 def __getitem__(self, name):
103 return getattr(self, name)
104
86 def printInfo(self):
105 def printInfo(self):
87
106
88 message = "#"*50 + "\n"
107 message = "#"*50 + "\n"
89 message += self.__class__.__name__.upper() + "\n"
108 message += self.__class__.__name__.upper() + "\n"
90 message += "#"*50 + "\n"
109 message += "#"*50 + "\n"
91
110
92 keyList = self.__dict__.keys()
111 keyList = self.__dict__.keys()
93 keyList.sort()
112 keyList.sort()
94
113
95 for key in keyList:
114 for key in keyList:
96 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
115 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
97
116
98 if "size" not in keyList:
117 if "size" not in keyList:
99 attr = getattr(self, "size")
118 attr = getattr(self, "size")
100
119
101 if attr:
120 if attr:
102 message += "%s = %s" %("size", attr) + "\n"
121 message += "%s = %s" %("size", attr) + "\n"
103
122
104 print message
123 print message
105
124
106 class BasicHeader(Header):
125 class BasicHeader(Header):
107
126
108 size = None
127 size = None
109 version = None
128 version = None
110 dataBlock = None
129 dataBlock = None
111 utc = None
130 utc = None
112 ltc = None
131 ltc = None
113 miliSecond = None
132 miliSecond = None
114 timeZone = None
133 timeZone = None
115 dstFlag = None
134 dstFlag = None
116 errorCount = None
135 errorCount = None
117 datatime = None
136 datatime = None
137 structure = BASIC_STRUCTURE
118 __LOCALTIME = None
138 __LOCALTIME = None
119
139
120 def __init__(self, useLocalTime=True):
140 def __init__(self, useLocalTime=True):
121
141
122 self.size = 24
142 self.size = 24
123 self.version = 0
143 self.version = 0
124 self.dataBlock = 0
144 self.dataBlock = 0
125 self.utc = 0
145 self.utc = 0
126 self.miliSecond = 0
146 self.miliSecond = 0
127 self.timeZone = 0
147 self.timeZone = 0
128 self.dstFlag = 0
148 self.dstFlag = 0
129 self.errorCount = 0
149 self.errorCount = 0
130
150
131 self.useLocalTime = useLocalTime
151 self.useLocalTime = useLocalTime
132
152
133 def read(self, fp):
153 def read(self, fp):
134
154
135 self.length = 0
155 self.length = 0
136 try:
156 try:
137 if hasattr(fp, 'read'):
157 if hasattr(fp, 'read'):
138 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
158 header = numpy.fromfile(fp, BASIC_STRUCTURE,1)
139 else:
159 else:
140 header = numpy.fromstring(fp, BASIC_STRUCTURE,1)
160 header = numpy.fromstring(fp, BASIC_STRUCTURE,1)
141 except Exception, e:
161 except Exception, e:
142 print "BasicHeader: "
162 print "BasicHeader: "
143 print e
163 print e
144 return 0
164 return 0
145
165
146 self.size = int(header['nSize'][0])
166 self.size = int(header['nSize'][0])
147 self.version = int(header['nVersion'][0])
167 self.version = int(header['nVersion'][0])
148 self.dataBlock = int(header['nDataBlockId'][0])
168 self.dataBlock = int(header['nDataBlockId'][0])
149 self.utc = int(header['nUtime'][0])
169 self.utc = int(header['nUtime'][0])
150 self.miliSecond = int(header['nMilsec'][0])
170 self.miliSecond = int(header['nMilsec'][0])
151 self.timeZone = int(header['nTimezone'][0])
171 self.timeZone = int(header['nTimezone'][0])
152 self.dstFlag = int(header['nDstflag'][0])
172 self.dstFlag = int(header['nDstflag'][0])
153 self.errorCount = int(header['nErrorCount'][0])
173 self.errorCount = int(header['nErrorCount'][0])
154
174
155 if self.size < 24:
175 if self.size < 24:
156 return 0
176 return 0
157
177
158 self.length = header.nbytes
178 self.length = header.nbytes
159 return 1
179 return 1
160
180
161 def write(self, fp):
181 def write(self, fp):
162
182
163 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
183 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
164 header = numpy.array(headerTuple, BASIC_STRUCTURE)
184 header = numpy.array(headerTuple, BASIC_STRUCTURE)
165 header.tofile(fp)
185 header.tofile(fp)
166
186
167 return 1
187 return 1
168
188
169 def get_ltc(self):
189 def get_ltc(self):
170
190
171 return self.utc - self.timeZone*60
191 return self.utc - self.timeZone*60
172
192
173 def set_ltc(self, value):
193 def set_ltc(self, value):
174
194
175 self.utc = value + self.timeZone*60
195 self.utc = value + self.timeZone*60
176
196
177 def get_datatime(self):
197 def get_datatime(self):
178
198
179 return datetime.datetime.utcfromtimestamp(self.ltc)
199 return datetime.datetime.utcfromtimestamp(self.ltc)
180
200
181 ltc = property(get_ltc, set_ltc)
201 ltc = property(get_ltc, set_ltc)
182 datatime = property(get_datatime)
202 datatime = property(get_datatime)
183
203
184 class SystemHeader(Header):
204 class SystemHeader(Header):
185
205
186 size = None
206 size = None
187 nSamples = None
207 nSamples = None
188 nProfiles = None
208 nProfiles = None
189 nChannels = None
209 nChannels = None
190 adcResolution = None
210 adcResolution = None
191 pciDioBusWidth = None
211 pciDioBusWidth = None
212 structure = SYSTEM_STRUCTURE
192
213
193 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
214 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
194
215
195 self.size = 24
216 self.size = 24
196 self.nSamples = nSamples
217 self.nSamples = nSamples
197 self.nProfiles = nProfiles
218 self.nProfiles = nProfiles
198 self.nChannels = nChannels
219 self.nChannels = nChannels
199 self.adcResolution = adcResolution
220 self.adcResolution = adcResolution
200 self.pciDioBusWidth = pciDioBusWith
221 self.pciDioBusWidth = pciDioBusWidth
201
222
202 def read(self, fp):
223 def read(self, fp):
203 self.length = 0
224 self.length = 0
204 try:
225 try:
205 startFp = fp.tell()
226 startFp = fp.tell()
206 except Exception, e:
227 except Exception, e:
207 startFp = None
228 startFp = None
208 pass
229 pass
209
230
210 try:
231 try:
211 if hasattr(fp, 'read'):
232 if hasattr(fp, 'read'):
212 header = numpy.fromfile(fp, SYSTEM_STRUCTURE,1)
233 header = numpy.fromfile(fp, SYSTEM_STRUCTURE,1)
213 else:
234 else:
214 header = numpy.fromstring(fp, SYSTEM_STRUCTURE,1)
235 header = numpy.fromstring(fp, SYSTEM_STRUCTURE,1)
215 except Exception, e:
236 except Exception, e:
216 print "System Header: " + str(e)
237 print "System Header: " + str(e)
217 return 0
238 return 0
218
239
219 self.size = header['nSize'][0]
240 self.size = header['nSize'][0]
220 self.nSamples = header['nNumSamples'][0]
241 self.nSamples = header['nNumSamples'][0]
221 self.nProfiles = header['nNumProfiles'][0]
242 self.nProfiles = header['nNumProfiles'][0]
222 self.nChannels = header['nNumChannels'][0]
243 self.nChannels = header['nNumChannels'][0]
223 self.adcResolution = header['nADCResolution'][0]
244 self.adcResolution = header['nADCResolution'][0]
224 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
245 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
225
246
226
247
227 if startFp is not None:
248 if startFp is not None:
228 endFp = self.size + startFp
249 endFp = self.size + startFp
229
250
230 if fp.tell() > endFp:
251 if fp.tell() > endFp:
231 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
252 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name)
232 return 0
253 return 0
233
254
234 if fp.tell() < endFp:
255 if fp.tell() < endFp:
235 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
256 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name)
236 return 0
257 return 0
237
258
238 self.length = header.nbytes
259 self.length = header.nbytes
239 return 1
260 return 1
240
261
241 def write(self, fp):
262 def write(self, fp):
242
263
243 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
264 headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth)
244 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
265 header = numpy.array(headerTuple,SYSTEM_STRUCTURE)
245 header.tofile(fp)
266 header.tofile(fp)
246
267
247 return 1
268 return 1
248
269
249 class RadarControllerHeader(Header):
270 class RadarControllerHeader(Header):
250
271
251 expType = None
272 expType = None
252 nTx = None
273 nTx = None
253 ipp = None
274 ipp = None
254 txA = None
275 txA = None
255 txB = None
276 txB = None
256 nWindows = None
277 nWindows = None
257 numTaus = None
278 numTaus = None
258 codeType = None
279 codeType = None
259 line6Function = None
280 line6Function = None
260 line5Function = None
281 line5Function = None
261 fClock = None
282 fClock = None
262 prePulseBefore = None
283 prePulseBefore = None
263 prePulserAfter = None
284 prePulseAfter = None
264 rangeIpp = None
285 rangeIpp = None
265 rangeTxA = None
286 rangeTxA = None
266 rangeTxB = None
287 rangeTxB = None
267
288 structure = RADAR_STRUCTURE
268 __size = None
289 __size = None
269
290
270 def __init__(self, expType=2, nTx=1,
291 def __init__(self, expType=2, nTx=1,
271 ippKm=None, txA=0, txB=0,
292 ipp=None, txA=0, txB=0,
272 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
293 nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None,
273 numTaus=0, line6Function=0, line5Function=0, fClock=None,
294 numTaus=0, line6Function=0, line5Function=0, fClock=None,
274 prePulseBefore=0, prePulseAfter=0,
295 prePulseBefore=0, prePulseAfter=0,
275 codeType=0, nCode=0, nBaud=0, code=None,
296 codeType=0, nCode=0, nBaud=0, code=None,
276 flip1=0, flip2=0):
297 flip1=0, flip2=0):
277
298
278 # self.size = 116
299 # self.size = 116
279 self.expType = expType
300 self.expType = expType
280 self.nTx = nTx
301 self.nTx = nTx
281 self.ipp = ippKm
302 self.ipp = ipp
282 self.txA = txA
303 self.txA = txA
283 self.txB = txB
304 self.txB = txB
284 self.rangeIpp = ippKm
305 self.rangeIpp = ipp
285 self.rangeTxA = txA
306 self.rangeTxA = txA
286 self.rangeTxB = txB
307 self.rangeTxB = txB
287
308
288 self.nWindows = nWindows
309 self.nWindows = nWindows
289 self.numTaus = numTaus
310 self.numTaus = numTaus
290 self.codeType = codeType
311 self.codeType = codeType
291 self.line6Function = line6Function
312 self.line6Function = line6Function
292 self.line5Function = line5Function
313 self.line5Function = line5Function
293 self.fClock = fClock
314 self.fClock = fClock
294 self.prePulseBefore = prePulseBefore
315 self.prePulseBefore = prePulseBefore
295 self.prePulserAfter = prePulseAfter
316 self.prePulseAfter = prePulseAfter
296
317
297 self.nHeights = nHeights
318 self.nHeights = nHeights
298 self.firstHeight = firstHeight
319 self.firstHeight = firstHeight
299 self.deltaHeight = deltaHeight
320 self.deltaHeight = deltaHeight
300 self.samplesWin = nHeights
321 self.samplesWin = nHeights
301
322
302 self.nCode = nCode
323 self.nCode = nCode
303 self.nBaud = nBaud
324 self.nBaud = nBaud
304 self.code = code
325 self.code = code
305 self.flip1 = flip1
326 self.flip1 = flip1
306 self.flip2 = flip2
327 self.flip2 = flip2
307
328
308 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
329 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
309 # self.dynamic = numpy.array([],numpy.dtype('byte'))
330 # self.dynamic = numpy.array([],numpy.dtype('byte'))
310
331
311 if self.fClock is None and self.deltaHeight is not None:
332 if self.fClock is None and self.deltaHeight is not None:
312 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
333 self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u)
313
334
314 def read(self, fp):
335 def read(self, fp):
315 self.length = 0
336 self.length = 0
316 try:
337 try:
317 startFp = fp.tell()
338 startFp = fp.tell()
318 except Exception, e:
339 except Exception, e:
319 startFp = None
340 startFp = None
320 pass
341 pass
321
342
322 try:
343 try:
323 if hasattr(fp, 'read'):
344 if hasattr(fp, 'read'):
324 header = numpy.fromfile(fp, RADAR_STRUCTURE,1)
345 header = numpy.fromfile(fp, RADAR_STRUCTURE,1)
325 else:
346 else:
326 header = numpy.fromstring(fp, RADAR_STRUCTURE,1)
347 header = numpy.fromstring(fp, RADAR_STRUCTURE,1)
327 self.length += header.nbytes
348 self.length += header.nbytes
328 except Exception, e:
349 except Exception, e:
329 print "RadarControllerHeader: " + str(e)
350 print "RadarControllerHeader: " + str(e)
330 return 0
351 return 0
331
352
332 size = int(header['nSize'][0])
353 size = int(header['nSize'][0])
333 self.expType = int(header['nExpType'][0])
354 self.expType = int(header['nExpType'][0])
334 self.nTx = int(header['nNTx'][0])
355 self.nTx = int(header['nNTx'][0])
335 self.ipp = float(header['fIpp'][0])
356 self.ipp = float(header['fIpp'][0])
336 self.txA = float(header['fTxA'][0])
357 self.txA = float(header['fTxA'][0])
337 self.txB = float(header['fTxB'][0])
358 self.txB = float(header['fTxB'][0])
338 self.nWindows = int(header['nNumWindows'][0])
359 self.nWindows = int(header['nNumWindows'][0])
339 self.numTaus = int(header['nNumTaus'][0])
360 self.numTaus = int(header['nNumTaus'][0])
340 self.codeType = int(header['nCodeType'][0])
361 self.codeType = int(header['nCodeType'][0])
341 self.line6Function = int(header['nLine6Function'][0])
362 self.line6Function = int(header['nLine6Function'][0])
342 self.line5Function = int(header['nLine5Function'][0])
363 self.line5Function = int(header['nLine5Function'][0])
343 self.fClock = float(header['fClock'][0])
364 self.fClock = float(header['fClock'][0])
344 self.prePulseBefore = int(header['nPrePulseBefore'][0])
365 self.prePulseBefore = int(header['nPrePulseBefore'][0])
345 self.prePulserAfter = int(header['nPrePulseAfter'][0])
366 self.prePulseAfter = int(header['nPrePulseAfter'][0])
346 self.rangeIpp = header['sRangeIPP'][0]
367 self.rangeIpp = header['sRangeIPP'][0]
347 self.rangeTxA = header['sRangeTxA'][0]
368 self.rangeTxA = header['sRangeTxA'][0]
348 self.rangeTxB = header['sRangeTxB'][0]
369 self.rangeTxB = header['sRangeTxB'][0]
349
370
350 try:
371 try:
351 if hasattr(fp, 'read'):
372 if hasattr(fp, 'read'):
352 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
373 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
353 else:
374 else:
354 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
375 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
355 self.length += samplingWindow.nbytes
376 self.length += samplingWindow.nbytes
356 except Exception, e:
377 except Exception, e:
357 print "RadarControllerHeader: " + str(e)
378 print "RadarControllerHeader: " + str(e)
358 return 0
379 return 0
359 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
380 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
360 self.firstHeight = samplingWindow['h0']
381 self.firstHeight = samplingWindow['h0']
361 self.deltaHeight = samplingWindow['dh']
382 self.deltaHeight = samplingWindow['dh']
362 self.samplesWin = samplingWindow['nsa']
383 self.samplesWin = samplingWindow['nsa']
363
384
364
385
365
386
366 try:
387 try:
367 if hasattr(fp, 'read'):
388 if hasattr(fp, 'read'):
368 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
389 self.Taus = numpy.fromfile(fp, '<f4', self.numTaus)
369 else:
390 else:
370 self.Taus = numpy.fromstring(fp[self.length:], '<f4', self.numTaus)
391 self.Taus = numpy.fromstring(fp[self.length:], '<f4', self.numTaus)
371 self.length += self.Taus.nbytes
392 self.length += self.Taus.nbytes
372 except Exception, e:
393 except Exception, e:
373 print "RadarControllerHeader: " + str(e)
394 print "RadarControllerHeader: " + str(e)
374 return 0
395 return 0
375
396
376
397
377
398
378 self.code_size = 0
399 self.code_size = 0
379 if self.codeType != 0:
400 if self.codeType != 0:
380
401
381 try:
402 try:
382 if hasattr(fp, 'read'):
403 if hasattr(fp, 'read'):
383 self.nCode = numpy.fromfile(fp, '<u4', 1)[0]
404 self.nCode = numpy.fromfile(fp, '<u4', 1)[0]
384 self.length += self.nCode.nbytes
405 self.length += self.nCode.nbytes
385 self.nBaud = numpy.fromfile(fp, '<u4', 1)[0]
406 self.nBaud = numpy.fromfile(fp, '<u4', 1)[0]
386 self.length += self.nBaud.nbytes
407 self.length += self.nBaud.nbytes
387 else:
408 else:
388 self.nCode = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
409 self.nCode = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
389 self.length += self.nCode.nbytes
410 self.length += self.nCode.nbytes
390 self.nBaud = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
411 self.nBaud = numpy.fromstring(fp[self.length:], '<u4', 1)[0]
391 self.length += self.nBaud.nbytes
412 self.length += self.nBaud.nbytes
392 except Exception, e:
413 except Exception, e:
393 print "RadarControllerHeader: " + str(e)
414 print "RadarControllerHeader: " + str(e)
394 return 0
415 return 0
395 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
416 code = numpy.empty([self.nCode,self.nBaud],dtype='i1')
396
417
397 for ic in range(self.nCode):
418 for ic in range(self.nCode):
398 try:
419 try:
399 if hasattr(fp, 'read'):
420 if hasattr(fp, 'read'):
400 temp = numpy.fromfile(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
421 temp = numpy.fromfile(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
401 else:
422 else:
402 temp = numpy.fromstring(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
423 temp = numpy.fromstring(fp,'u4', int(numpy.ceil(self.nBaud/32.)))
403 self.length += temp.nbytes
424 self.length += temp.nbytes
404 except Exception, e:
425 except Exception, e:
405 print "RadarControllerHeader: " + str(e)
426 print "RadarControllerHeader: " + str(e)
406 return 0
427 return 0
407
428
408 for ib in range(self.nBaud-1,-1,-1):
429 for ib in range(self.nBaud-1,-1,-1):
409 code[ic,ib] = temp[ib/32]%2
430 code[ic,ib] = temp[ib/32]%2
410 temp[ib/32] = temp[ib/32]/2
431 temp[ib/32] = temp[ib/32]/2
411
432
412 self.code = 2.0*code - 1.0
433 self.code = 2.0*code - 1.0
413 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
434 self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4
414
435
415 # if self.line5Function == RCfunction.FLIP:
436 # if self.line5Function == RCfunction.FLIP:
416 # self.flip1 = numpy.fromfile(fp,'<u4',1)
437 # self.flip1 = numpy.fromfile(fp,'<u4',1)
417 #
438 #
418 # if self.line6Function == RCfunction.FLIP:
439 # if self.line6Function == RCfunction.FLIP:
419 # self.flip2 = numpy.fromfile(fp,'<u4',1)
440 # self.flip2 = numpy.fromfile(fp,'<u4',1)
420 if startFp is not None:
441 if startFp is not None:
421 endFp = size + startFp
442 endFp = size + startFp
422
443
423 if fp.tell() != endFp:
444 if fp.tell() != endFp:
424 # fp.seek(endFp)
445 # fp.seek(endFp)
425 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size)
446 print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size)
426 # return 0
447 # return 0
427
448
428 if fp.tell() > endFp:
449 if fp.tell() > endFp:
429 sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name)
450 sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name)
430 # return 0
451 # return 0
431
452
432 if fp.tell() < endFp:
453 if fp.tell() < endFp:
433 sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name)
454 sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name)
434
455
435
456
436 return 1
457 return 1
437
458
438 def write(self, fp):
459 def write(self, fp):
439
460
440 headerTuple = (self.size,
461 headerTuple = (self.size,
441 self.expType,
462 self.expType,
442 self.nTx,
463 self.nTx,
443 self.ipp,
464 self.ipp,
444 self.txA,
465 self.txA,
445 self.txB,
466 self.txB,
446 self.nWindows,
467 self.nWindows,
447 self.numTaus,
468 self.numTaus,
448 self.codeType,
469 self.codeType,
449 self.line6Function,
470 self.line6Function,
450 self.line5Function,
471 self.line5Function,
451 self.fClock,
472 self.fClock,
452 self.prePulseBefore,
473 self.prePulseBefore,
453 self.prePulserAfter,
474 self.prePulseAfter,
454 self.rangeIpp,
475 self.rangeIpp,
455 self.rangeTxA,
476 self.rangeTxA,
456 self.rangeTxB)
477 self.rangeTxB)
457
478
458 header = numpy.array(headerTuple,RADAR_STRUCTURE)
479 header = numpy.array(headerTuple,RADAR_STRUCTURE)
459 header.tofile(fp)
480 header.tofile(fp)
460
481
461 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
482 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
462 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
483 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
463 samplingWindow.tofile(fp)
484 samplingWindow.tofile(fp)
464
485
465 if self.numTaus > 0:
486 if self.numTaus > 0:
466 self.Taus.tofile(fp)
487 self.Taus.tofile(fp)
467
488
468 if self.codeType !=0:
489 if self.codeType !=0:
469 nCode = numpy.array(self.nCode, '<u4')
490 nCode = numpy.array(self.nCode, '<u4')
470 nCode.tofile(fp)
491 nCode.tofile(fp)
471 nBaud = numpy.array(self.nBaud, '<u4')
492 nBaud = numpy.array(self.nBaud, '<u4')
472 nBaud.tofile(fp)
493 nBaud.tofile(fp)
473 code1 = (self.code + 1.0)/2.
494 code1 = (self.code + 1.0)/2.
474
495
475 for ic in range(self.nCode):
496 for ic in range(self.nCode):
476 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
497 tempx = numpy.zeros(numpy.ceil(self.nBaud/32.))
477 start = 0
498 start = 0
478 end = 32
499 end = 32
479 for i in range(len(tempx)):
500 for i in range(len(tempx)):
480 code_selected = code1[ic,start:end]
501 code_selected = code1[ic,start:end]
481 for j in range(len(code_selected)-1,-1,-1):
502 for j in range(len(code_selected)-1,-1,-1):
482 if code_selected[j] == 1:
503 if code_selected[j] == 1:
483 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
504 tempx[i] = tempx[i] + 2**(len(code_selected)-1-j)
484 start = start + 32
505 start = start + 32
485 end = end + 32
506 end = end + 32
486
507
487 tempx = tempx.astype('u4')
508 tempx = tempx.astype('u4')
488 tempx.tofile(fp)
509 tempx.tofile(fp)
489
510
490 # if self.line5Function == RCfunction.FLIP:
511 # if self.line5Function == RCfunction.FLIP:
491 # self.flip1.tofile(fp)
512 # self.flip1.tofile(fp)
492 #
513 #
493 # if self.line6Function == RCfunction.FLIP:
514 # if self.line6Function == RCfunction.FLIP:
494 # self.flip2.tofile(fp)
515 # self.flip2.tofile(fp)
495
516
496 return 1
517 return 1
497
518
498 def get_ippSeconds(self):
519 def get_ippSeconds(self):
499 '''
520 '''
500 '''
521 '''
501 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
522 ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT
502
523
503 return ippSeconds
524 return ippSeconds
504
525
505 def set_ippSeconds(self, ippSeconds):
526 def set_ippSeconds(self, ippSeconds):
506 '''
527 '''
507 '''
528 '''
508
529
509 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
530 self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000)
510
531
511 return
532 return
512
533
513 def get_size(self):
534 def get_size(self):
514
535
515 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
536 self.__size = 116 + 12*self.nWindows + 4*self.numTaus
516
537
517 if self.codeType != 0:
538 if self.codeType != 0:
518 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
539 self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
519
540
520 return self.__size
541 return self.__size
521
542
522 def set_size(self, value):
543 def set_size(self, value):
523
544
524 raise IOError, "size is a property and it cannot be set, just read"
545 raise IOError, "size is a property and it cannot be set, just read"
525
546
526 return
547 return
527
548
528 ippSeconds = property(get_ippSeconds, set_ippSeconds)
549 ippSeconds = property(get_ippSeconds, set_ippSeconds)
529 size = property(get_size, set_size)
550 size = property(get_size, set_size)
530
551
531 class ProcessingHeader(Header):
552 class ProcessingHeader(Header):
532
553
533 # size = None
554 # size = None
534 dtype = None
555 dtype = None
535 blockSize = None
556 blockSize = None
536 profilesPerBlock = None
557 profilesPerBlock = None
537 dataBlocksPerFile = None
558 dataBlocksPerFile = None
538 nWindows = None
559 nWindows = None
539 processFlags = None
560 processFlags = None
540 nCohInt = None
561 nCohInt = None
541 nIncohInt = None
562 nIncohInt = None
542 totalSpectra = None
563 totalSpectra = None
543
564 structure = PROCESSING_STRUCTURE
544 flag_dc = None
565 flag_dc = None
545 flag_cspc = None
566 flag_cspc = None
546
567
547 def __init__(self):
568 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0,processFlags=0, nCohInt=0,
569 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
570 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
571 ):
548
572
549 # self.size = 0
573 # self.size = 0
550 self.dtype = 0
574 self.dtype = dtype
551 self.blockSize = 0
575 self.blockSize = blockSize
552 self.profilesPerBlock = 0
576 self.profilesPerBlock = 0
553 self.dataBlocksPerFile = 0
577 self.dataBlocksPerFile = 0
554 self.nWindows = 0
578 self.nWindows = 0
555 self.processFlags = 0
579 self.processFlags = 0
556 self.nCohInt = 0
580 self.nCohInt = 0
557 self.nIncohInt = 0
581 self.nIncohInt = 0
558 self.totalSpectra = 0
582 self.totalSpectra = 0
559
583
560 self.nHeights = 0
584 self.nHeights = 0
561 self.firstHeight = 0
585 self.firstHeight = 0
562 self.deltaHeight = 0
586 self.deltaHeight = 0
563 self.samplesWin = 0
587 self.samplesWin = 0
564 self.spectraComb = 0
588 self.spectraComb = 0
565 self.nCode = None
589 self.nCode = None
566 self.code = None
590 self.code = None
567 self.nBaud = None
591 self.nBaud = None
568
592
569 self.shif_fft = False
593 self.shif_fft = False
570 self.flag_dc = False
594 self.flag_dc = False
571 self.flag_cspc = False
595 self.flag_cspc = False
572 self.flag_decode = False
596 self.flag_decode = False
573 self.flag_deflip = False
597 self.flag_deflip = False
574 self.length = 0
598 self.length = 0
599
575 def read(self, fp):
600 def read(self, fp):
576 self.length = 0
601 self.length = 0
577 try:
602 try:
578 startFp = fp.tell()
603 startFp = fp.tell()
579 except Exception, e:
604 except Exception, e:
580 startFp = None
605 startFp = None
581 pass
606 pass
582
607
583 try:
608 try:
584 if hasattr(fp, 'read'):
609 if hasattr(fp, 'read'):
585 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
610 header = numpy.fromfile(fp, PROCESSING_STRUCTURE, 1)
586 else:
611 else:
587 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
612 header = numpy.fromstring(fp, PROCESSING_STRUCTURE, 1)
588 self.length += header.nbytes
613 self.length += header.nbytes
589 except Exception, e:
614 except Exception, e:
590 print "ProcessingHeader: " + str(e)
615 print "ProcessingHeader: " + str(e)
591 return 0
616 return 0
592
617
593 size = int(header['nSize'][0])
618 size = int(header['nSize'][0])
594 self.dtype = int(header['nDataType'][0])
619 self.dtype = int(header['nDataType'][0])
595 self.blockSize = int(header['nSizeOfDataBlock'][0])
620 self.blockSize = int(header['nSizeOfDataBlock'][0])
596 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
621 self.profilesPerBlock = int(header['nProfilesperBlock'][0])
597 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
622 self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0])
598 self.nWindows = int(header['nNumWindows'][0])
623 self.nWindows = int(header['nNumWindows'][0])
599 self.processFlags = header['nProcessFlags']
624 self.processFlags = header['nProcessFlags']
600 self.nCohInt = int(header['nCoherentIntegrations'][0])
625 self.nCohInt = int(header['nCoherentIntegrations'][0])
601 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
626 self.nIncohInt = int(header['nIncoherentIntegrations'][0])
602 self.totalSpectra = int(header['nTotalSpectra'][0])
627 self.totalSpectra = int(header['nTotalSpectra'][0])
603
628
604 try:
629 try:
605 if hasattr(fp, 'read'):
630 if hasattr(fp, 'read'):
606 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
631 samplingWindow = numpy.fromfile(fp, SAMPLING_STRUCTURE, self.nWindows)
607 else:
632 else:
608 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
633 samplingWindow = numpy.fromstring(fp[self.length:], SAMPLING_STRUCTURE, self.nWindows)
609 self.length += samplingWindow.nbytes
634 self.length += samplingWindow.nbytes
610 except Exception, e:
635 except Exception, e:
611 print "ProcessingHeader: " + str(e)
636 print "ProcessingHeader: " + str(e)
612 return 0
637 return 0
613
638
614 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
639 self.nHeights = int(numpy.sum(samplingWindow['nsa']))
615 self.firstHeight = float(samplingWindow['h0'][0])
640 self.firstHeight = float(samplingWindow['h0'][0])
616 self.deltaHeight = float(samplingWindow['dh'][0])
641 self.deltaHeight = float(samplingWindow['dh'][0])
617 self.samplesWin = samplingWindow['nsa'][0]
642 self.samplesWin = samplingWindow['nsa'][0]
618
643
619
644
620 try:
645 try:
621 if hasattr(fp, 'read'):
646 if hasattr(fp, 'read'):
622 self.spectraComb = numpy.fromfile(fp, 'u1', 2*self.totalSpectra)
647 self.spectraComb = numpy.fromfile(fp, 'u1', 2*self.totalSpectra)
623 else:
648 else:
624 self.spectraComb = numpy.fromstring(fp[self.length:], 'u1', 2*self.totalSpectra)
649 self.spectraComb = numpy.fromstring(fp[self.length:], 'u1', 2*self.totalSpectra)
625 self.length += self.spectraComb.nbytes
650 self.length += self.spectraComb.nbytes
626 except Exception, e:
651 except Exception, e:
627 print "ProcessingHeader: " + str(e)
652 print "ProcessingHeader: " + str(e)
628 return 0
653 return 0
629
654
630 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
655 if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE):
631 self.nCode = int(numpy.fromfile(fp,'<u4',1))
656 self.nCode = int(numpy.fromfile(fp,'<u4',1))
632 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
657 self.nBaud = int(numpy.fromfile(fp,'<u4',1))
633 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
658 self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud)
634
659
635 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
660 if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP):
636 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
661 exp_name_len = int(numpy.fromfile(fp,'<u4',1))
637 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
662 exp_name = numpy.fromfile(fp,'u1',exp_name_len+1)
638
663
639 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
664 if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA):
640 self.shif_fft = True
665 self.shif_fft = True
641 else:
666 else:
642 self.shif_fft = False
667 self.shif_fft = False
643
668
644 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
669 if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC):
645 self.flag_dc = True
670 self.flag_dc = True
646 else:
671 else:
647 self.flag_dc = False
672 self.flag_dc = False
648
673
649 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
674 if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA):
650 self.flag_decode = True
675 self.flag_decode = True
651 else:
676 else:
652 self.flag_decode = False
677 self.flag_decode = False
653
678
654 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
679 if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA):
655 self.flag_deflip = True
680 self.flag_deflip = True
656 else:
681 else:
657 self.flag_deflip = False
682 self.flag_deflip = False
658
683
659 nChannels = 0
684 nChannels = 0
660 nPairs = 0
685 nPairs = 0
661 pairList = []
686 pairList = []
662
687
663 for i in range( 0, self.totalSpectra*2, 2 ):
688 for i in range( 0, self.totalSpectra*2, 2 ):
664 if self.spectraComb[i] == self.spectraComb[i+1]:
689 if self.spectraComb[i] == self.spectraComb[i+1]:
665 nChannels = nChannels + 1 #par de canales iguales
690 nChannels = nChannels + 1 #par de canales iguales
666 else:
691 else:
667 nPairs = nPairs + 1 #par de canales diferentes
692 nPairs = nPairs + 1 #par de canales diferentes
668 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
693 pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) )
669
694
670 self.flag_cspc = False
695 self.flag_cspc = False
671 if nPairs > 0:
696 if nPairs > 0:
672 self.flag_cspc = True
697 self.flag_cspc = True
673
698
674
699
675
700
676 if startFp is not None:
701 if startFp is not None:
677 endFp = size + startFp
702 endFp = size + startFp
678 if fp.tell() > endFp:
703 if fp.tell() > endFp:
679 sys.stderr.write("Warning: Processing header size is lower than it has to be")
704 sys.stderr.write("Warning: Processing header size is lower than it has to be")
680 return 0
705 return 0
681
706
682 if fp.tell() < endFp:
707 if fp.tell() < endFp:
683 sys.stderr.write("Warning: Processing header size is greater than it is considered")
708 sys.stderr.write("Warning: Processing header size is greater than it is considered")
684
709
685 return 1
710 return 1
686
711
687 def write(self, fp):
712 def write(self, fp):
688 #Clear DEFINE_PROCESS_CODE
713 #Clear DEFINE_PROCESS_CODE
689 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
714 self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE)
690
715
691 headerTuple = (self.size,
716 headerTuple = (self.size,
692 self.dtype,
717 self.dtype,
693 self.blockSize,
718 self.blockSize,
694 self.profilesPerBlock,
719 self.profilesPerBlock,
695 self.dataBlocksPerFile,
720 self.dataBlocksPerFile,
696 self.nWindows,
721 self.nWindows,
697 self.processFlags,
722 self.processFlags,
698 self.nCohInt,
723 self.nCohInt,
699 self.nIncohInt,
724 self.nIncohInt,
700 self.totalSpectra)
725 self.totalSpectra)
701
726
702 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
727 header = numpy.array(headerTuple,PROCESSING_STRUCTURE)
703 header.tofile(fp)
728 header.tofile(fp)
704
729
705 if self.nWindows != 0:
730 if self.nWindows != 0:
706 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
731 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
707 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
732 samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE)
708 samplingWindow.tofile(fp)
733 samplingWindow.tofile(fp)
709
734
710 if self.totalSpectra != 0:
735 if self.totalSpectra != 0:
711 # spectraComb = numpy.array([],numpy.dtype('u1'))
736 # spectraComb = numpy.array([],numpy.dtype('u1'))
712 spectraComb = self.spectraComb
737 spectraComb = self.spectraComb
713 spectraComb.tofile(fp)
738 spectraComb.tofile(fp)
714
739
715 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
740 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
716 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
741 # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba
717 # nCode.tofile(fp)
742 # nCode.tofile(fp)
718 #
743 #
719 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
744 # nBaud = numpy.array([self.nBaud], numpy.dtype('u4'))
720 # nBaud.tofile(fp)
745 # nBaud.tofile(fp)
721 #
746 #
722 # code = self.code.reshape(self.nCode*self.nBaud)
747 # code = self.code.reshape(self.nCode*self.nBaud)
723 # code = code.astype(numpy.dtype('<f4'))
748 # code = code.astype(numpy.dtype('<f4'))
724 # code.tofile(fp)
749 # code.tofile(fp)
725
750
726 return 1
751 return 1
727
752
728 def get_size(self):
753 def get_size(self):
729
754
730 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
755 self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra
731
756
732 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
757 # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
733 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
758 # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.)
734 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
759 # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud
735
760
736 return self.__size
761 return self.__size
737
762
738 def set_size(self, value):
763 def set_size(self, value):
739
764
740 raise IOError, "size is a property and it cannot be set, just read"
765 raise IOError, "size is a property and it cannot be set, just read"
741
766
742 return
767 return
743
768
744 size = property(get_size, set_size)
769 size = property(get_size, set_size)
745
770
746 class RCfunction:
771 class RCfunction:
747 NONE=0
772 NONE=0
748 FLIP=1
773 FLIP=1
749 CODE=2
774 CODE=2
750 SAMPLING=3
775 SAMPLING=3
751 LIN6DIV256=4
776 LIN6DIV256=4
752 SYNCHRO=5
777 SYNCHRO=5
753
778
754 class nCodeType:
779 class nCodeType:
755 NONE=0
780 NONE=0
756 USERDEFINE=1
781 USERDEFINE=1
757 BARKER2=2
782 BARKER2=2
758 BARKER3=3
783 BARKER3=3
759 BARKER4=4
784 BARKER4=4
760 BARKER5=5
785 BARKER5=5
761 BARKER7=6
786 BARKER7=6
762 BARKER11=7
787 BARKER11=7
763 BARKER13=8
788 BARKER13=8
764 AC128=9
789 AC128=9
765 COMPLEMENTARYCODE2=10
790 COMPLEMENTARYCODE2=10
766 COMPLEMENTARYCODE4=11
791 COMPLEMENTARYCODE4=11
767 COMPLEMENTARYCODE8=12
792 COMPLEMENTARYCODE8=12
768 COMPLEMENTARYCODE16=13
793 COMPLEMENTARYCODE16=13
769 COMPLEMENTARYCODE32=14
794 COMPLEMENTARYCODE32=14
770 COMPLEMENTARYCODE64=15
795 COMPLEMENTARYCODE64=15
771 COMPLEMENTARYCODE128=16
796 COMPLEMENTARYCODE128=16
772 CODE_BINARY28=17
797 CODE_BINARY28=17
773
798
774 class PROCFLAG:
799 class PROCFLAG:
775
800
776 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
801 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
777 DECODE_DATA = numpy.uint32(0x00000002)
802 DECODE_DATA = numpy.uint32(0x00000002)
778 SPECTRA_CALC = numpy.uint32(0x00000004)
803 SPECTRA_CALC = numpy.uint32(0x00000004)
779 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
804 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
780 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
805 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
781 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
806 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
782
807
783 DATATYPE_CHAR = numpy.uint32(0x00000040)
808 DATATYPE_CHAR = numpy.uint32(0x00000040)
784 DATATYPE_SHORT = numpy.uint32(0x00000080)
809 DATATYPE_SHORT = numpy.uint32(0x00000080)
785 DATATYPE_LONG = numpy.uint32(0x00000100)
810 DATATYPE_LONG = numpy.uint32(0x00000100)
786 DATATYPE_INT64 = numpy.uint32(0x00000200)
811 DATATYPE_INT64 = numpy.uint32(0x00000200)
787 DATATYPE_FLOAT = numpy.uint32(0x00000400)
812 DATATYPE_FLOAT = numpy.uint32(0x00000400)
788 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
813 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
789
814
790 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
815 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
791 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
816 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
792 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
817 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
793
818
794 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
819 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
795 DEFLIP_DATA = numpy.uint32(0x00010000)
820 DEFLIP_DATA = numpy.uint32(0x00010000)
796 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
821 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
797
822
798 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
823 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
799 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
824 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
800 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
825 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
801 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
826 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
802 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
827 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
803
828
804 EXP_NAME_ESP = numpy.uint32(0x00200000)
829 EXP_NAME_ESP = numpy.uint32(0x00200000)
805 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
830 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
806
831
807 OPERATION_MASK = numpy.uint32(0x0000003F)
832 OPERATION_MASK = numpy.uint32(0x0000003F)
808 DATATYPE_MASK = numpy.uint32(0x00000FC0)
833 DATATYPE_MASK = numpy.uint32(0x00000FC0)
809 DATAARRANGE_MASK = numpy.uint32(0x00007000)
834 DATAARRANGE_MASK = numpy.uint32(0x00007000)
810 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
835 ACQ_SYS_MASK = numpy.uint32(0x001C0000)
811
836
812 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
837 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
813 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
838 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
814 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
839 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
815 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
840 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
816 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
841 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
817 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
842 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
818
843
819 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
844 NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
820
845
821 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
846 PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR,
822 PROCFLAG.DATATYPE_SHORT,
847 PROCFLAG.DATATYPE_SHORT,
823 PROCFLAG.DATATYPE_LONG,
848 PROCFLAG.DATATYPE_LONG,
824 PROCFLAG.DATATYPE_INT64,
849 PROCFLAG.DATATYPE_INT64,
825 PROCFLAG.DATATYPE_FLOAT,
850 PROCFLAG.DATATYPE_FLOAT,
826 PROCFLAG.DATATYPE_DOUBLE]
851 PROCFLAG.DATATYPE_DOUBLE]
827
852
828 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
853 DTYPE_WIDTH = [1, 2, 4, 8, 4, 8]
829
854
830 def get_dtype_index(numpy_dtype):
855 def get_dtype_index(numpy_dtype):
831
856
832 index = None
857 index = None
833
858
834 for i in range(len(NUMPY_DTYPE_LIST)):
859 for i in range(len(NUMPY_DTYPE_LIST)):
835 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
860 if numpy_dtype == NUMPY_DTYPE_LIST[i]:
836 index = i
861 index = i
837 break
862 break
838
863
839 return index
864 return index
840
865
841 def get_numpy_dtype(index):
866 def get_numpy_dtype(index):
842
867
843 return NUMPY_DTYPE_LIST[index]
868 return NUMPY_DTYPE_LIST[index]
844
869
845 def get_procflag_dtype(index):
870 def get_procflag_dtype(index):
846
871
847 return PROCFLAG_DTYPE_LIST[index]
872 return PROCFLAG_DTYPE_LIST[index]
848
873
849 def get_dtype_width(index):
874 def get_dtype_width(index):
850
875
851 return DTYPE_WIDTH[index] No newline at end of file
876 return DTYPE_WIDTH[index]
@@ -1,187 +1,187
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import copy
4 import copy
5 from schainpy.model import *
5 from schainpy.model import *
6 from figure import Figure, isRealtime
6 from figure import Figure, isRealtime
7
7
8 class CorrelationPlot(Figure):
8 class CorrelationPlot(Figure):
9 isConfig = None
9 isConfig = None
10 __nsubplots = None
10 __nsubplots = None
11
11
12 WIDTHPROF = None
12 WIDTHPROF = None
13 HEIGHTPROF = None
13 HEIGHTPROF = None
14 PREFIX = 'corr'
14 PREFIX = 'corr'
15
15
16 def __init__(self):
16 def __init__(self, **kwargs):
17
17 Figure.__init__(self, **kwargs)
18 self.isConfig = False
18 self.isConfig = False
19 self.__nsubplots = 1
19 self.__nsubplots = 1
20
20
21 self.WIDTH = 280
21 self.WIDTH = 280
22 self.HEIGHT = 250
22 self.HEIGHT = 250
23 self.WIDTHPROF = 120
23 self.WIDTHPROF = 120
24 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
25 self.counter_imagwr = 0
25 self.counter_imagwr = 0
26
26
27 self.PLOT_CODE = 1
27 self.PLOT_CODE = 1
28 self.FTP_WEI = None
28 self.FTP_WEI = None
29 self.EXP_CODE = None
29 self.EXP_CODE = None
30 self.SUB_EXP_CODE = None
30 self.SUB_EXP_CODE = None
31 self.PLOT_POS = None
31 self.PLOT_POS = None
32
32
33 def getSubplots(self):
33 def getSubplots(self):
34
34
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
37
37
38 return nrow, ncol
38 return nrow, ncol
39
39
40 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
40 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
41
41
42 showprofile = False
42 showprofile = False
43 self.__showprofile = showprofile
43 self.__showprofile = showprofile
44 self.nplots = nplots
44 self.nplots = nplots
45
45
46 ncolspan = 1
46 ncolspan = 1
47 colspan = 1
47 colspan = 1
48 if showprofile:
48 if showprofile:
49 ncolspan = 3
49 ncolspan = 3
50 colspan = 2
50 colspan = 2
51 self.__nsubplots = 2
51 self.__nsubplots = 2
52
52
53 self.createFigure(id = id,
53 self.createFigure(id = id,
54 wintitle = wintitle,
54 wintitle = wintitle,
55 widthplot = self.WIDTH + self.WIDTHPROF,
55 widthplot = self.WIDTH + self.WIDTHPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 show=show)
57 show=show)
58
58
59 nrow, ncol = self.getSubplots()
59 nrow, ncol = self.getSubplots()
60
60
61 counter = 0
61 counter = 0
62 for y in range(nrow):
62 for y in range(nrow):
63 for x in range(ncol):
63 for x in range(ncol):
64
64
65 if counter >= self.nplots:
65 if counter >= self.nplots:
66 break
66 break
67
67
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69
69
70 if showprofile:
70 if showprofile:
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72
72
73 counter += 1
73 counter += 1
74
74
75 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
75 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
76 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
76 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
77 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
77 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
78 server=None, folder=None, username=None, password=None,
78 server=None, folder=None, username=None, password=None,
79 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
79 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
80
80
81 """
81 """
82
82
83 Input:
83 Input:
84 dataOut :
84 dataOut :
85 id :
85 id :
86 wintitle :
86 wintitle :
87 channelList :
87 channelList :
88 showProfile :
88 showProfile :
89 xmin : None,
89 xmin : None,
90 xmax : None,
90 xmax : None,
91 ymin : None,
91 ymin : None,
92 ymax : None,
92 ymax : None,
93 zmin : None,
93 zmin : None,
94 zmax : None
94 zmax : None
95 """
95 """
96
96
97 if dataOut.flagNoData:
97 if dataOut.flagNoData:
98 return None
98 return None
99
99
100 if realtime:
100 if realtime:
101 if not(isRealtime(utcdatatime = dataOut.utctime)):
101 if not(isRealtime(utcdatatime = dataOut.utctime)):
102 print 'Skipping this plot function'
102 print 'Skipping this plot function'
103 return
103 return
104
104
105 if channelList == None:
105 if channelList == None:
106 channelIndexList = dataOut.channelIndexList
106 channelIndexList = dataOut.channelIndexList
107 else:
107 else:
108 channelIndexList = []
108 channelIndexList = []
109 for channel in channelList:
109 for channel in channelList:
110 if channel not in dataOut.channelList:
110 if channel not in dataOut.channelList:
111 raise ValueError, "Channel %d is not in dataOut.channelList"
111 raise ValueError, "Channel %d is not in dataOut.channelList"
112 channelIndexList.append(dataOut.channelList.index(channel))
112 channelIndexList.append(dataOut.channelList.index(channel))
113
113
114 factor = dataOut.normFactor
114 factor = dataOut.normFactor
115 lenfactor = factor.shape[1]
115 lenfactor = factor.shape[1]
116 x = dataOut.getLagTRange(1)
116 x = dataOut.getLagTRange(1)
117 y = dataOut.getHeiRange()
117 y = dataOut.getHeiRange()
118
118
119 z = copy.copy(dataOut.data_corr[:,:,0,:])
119 z = copy.copy(dataOut.data_corr[:,:,0,:])
120 for i in range(dataOut.data_corr.shape[0]):
120 for i in range(dataOut.data_corr.shape[0]):
121 z[i,:,:] = z[i,:,:]/factor[i,:]
121 z[i,:,:] = z[i,:,:]/factor[i,:]
122 zdB = numpy.abs(z)
122 zdB = numpy.abs(z)
123
123
124 avg = numpy.average(z, axis=1)
124 avg = numpy.average(z, axis=1)
125 # avg = numpy.nanmean(z, axis=1)
125 # avg = numpy.nanmean(z, axis=1)
126 # noise = dataOut.noise/factor
126 # noise = dataOut.noise/factor
127
127
128 #thisDatetime = dataOut.datatime
128 #thisDatetime = dataOut.datatime
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 title = wintitle + " Correlation"
130 title = wintitle + " Correlation"
131 xlabel = "Lag T (s)"
131 xlabel = "Lag T (s)"
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 if not self.isConfig:
134 if not self.isConfig:
135
135
136 nplots = dataOut.data_corr.shape[0]
136 nplots = dataOut.data_corr.shape[0]
137
137
138 self.setup(id=id,
138 self.setup(id=id,
139 nplots=nplots,
139 nplots=nplots,
140 wintitle=wintitle,
140 wintitle=wintitle,
141 showprofile=showprofile,
141 showprofile=showprofile,
142 show=show)
142 show=show)
143
143
144 if xmin == None: xmin = numpy.nanmin(x)
144 if xmin == None: xmin = numpy.nanmin(x)
145 if xmax == None: xmax = numpy.nanmax(x)
145 if xmax == None: xmax = numpy.nanmax(x)
146 if ymin == None: ymin = numpy.nanmin(y)
146 if ymin == None: ymin = numpy.nanmin(y)
147 if ymax == None: ymax = numpy.nanmax(y)
147 if ymax == None: ymax = numpy.nanmax(y)
148 if zmin == None: zmin = 0
148 if zmin == None: zmin = 0
149 if zmax == None: zmax = 1
149 if zmax == None: zmax = 1
150
150
151 self.FTP_WEI = ftp_wei
151 self.FTP_WEI = ftp_wei
152 self.EXP_CODE = exp_code
152 self.EXP_CODE = exp_code
153 self.SUB_EXP_CODE = sub_exp_code
153 self.SUB_EXP_CODE = sub_exp_code
154 self.PLOT_POS = plot_pos
154 self.PLOT_POS = plot_pos
155
155
156 self.isConfig = True
156 self.isConfig = True
157
157
158 self.setWinTitle(title)
158 self.setWinTitle(title)
159
159
160 for i in range(self.nplots):
160 for i in range(self.nplots):
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
162 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
163 axes = self.axesList[i*self.__nsubplots]
163 axes = self.axesList[i*self.__nsubplots]
164 axes.pcolor(x, y, zdB[i,:,:],
164 axes.pcolor(x, y, zdB[i,:,:],
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 xlabel=xlabel, ylabel=ylabel, title=title,
166 xlabel=xlabel, ylabel=ylabel, title=title,
167 ticksize=9, cblabel='')
167 ticksize=9, cblabel='')
168
168
169 # if self.__showprofile:
169 # if self.__showprofile:
170 # axes = self.axesList[i*self.__nsubplots +1]
170 # axes = self.axesList[i*self.__nsubplots +1]
171 # axes.pline(avgdB[i], y,
171 # axes.pline(avgdB[i], y,
172 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
172 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
173 # xlabel='dB', ylabel='', title='',
173 # xlabel='dB', ylabel='', title='',
174 # ytick_visible=False,
174 # ytick_visible=False,
175 # grid='x')
175 # grid='x')
176 #
176 #
177 # noiseline = numpy.repeat(noisedB[i], len(y))
177 # noiseline = numpy.repeat(noisedB[i], len(y))
178 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
178 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
179
179
180 self.draw()
180 self.draw()
181
181
182 self.save(figpath=figpath,
182 self.save(figpath=figpath,
183 figfile=figfile,
183 figfile=figfile,
184 save=save,
184 save=save,
185 ftp=ftp,
185 ftp=ftp,
186 wr_period=wr_period,
186 wr_period=wr_period,
187 thisDatetime=thisDatetime)
187 thisDatetime=thisDatetime)
@@ -1,922 +1,937
1
1
2 import os
2 import os
3 import time
3 import time
4 import glob
4 import glob
5 import datetime
5 import datetime
6 from multiprocessing import Process
6 from multiprocessing import Process
7
7
8 import zmq
8 import zmq
9 import numpy
9 import numpy
10 import matplotlib
10 import matplotlib
11 import matplotlib.pyplot as plt
11 import matplotlib.pyplot as plt
12 from mpl_toolkits.axes_grid1 import make_axes_locatable
12 from mpl_toolkits.axes_grid1 import make_axes_locatable
13 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
13 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
14
14
15 from schainpy.model.proc.jroproc_base import Operation
15 from schainpy.model.proc.jroproc_base import Operation
16 from schainpy.utils import log
16 from schainpy.utils import log
17
17
18 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
18 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
19 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
19 blu_values = matplotlib.pyplot.get_cmap(
20 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
20 "seismic_r", 20)(numpy.arange(20))[10:15]
21 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
22 "jro", numpy.vstack((blu_values, jet_values)))
21 matplotlib.pyplot.register_cmap(cmap=ncmap)
23 matplotlib.pyplot.register_cmap(cmap=ncmap)
22
24
23 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')]
25 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')]
24
26
25 def figpause(interval):
27 def figpause(interval):
26 backend = plt.rcParams['backend']
28 backend = plt.rcParams['backend']
27 if backend in matplotlib.rcsetup.interactive_bk:
29 if backend in matplotlib.rcsetup.interactive_bk:
28 figManager = matplotlib._pylab_helpers.Gcf.get_active()
30 figManager = matplotlib._pylab_helpers.Gcf.get_active()
29 if figManager is not None:
31 if figManager is not None:
30 canvas = figManager.canvas
32 canvas = figManager.canvas
31 if canvas.figure.stale:
33 if canvas.figure.stale:
32 canvas.draw()
34 canvas.draw()
33 canvas.start_event_loop(interval)
35 canvas.start_event_loop(interval)
34 return
36 return
35
37
36 class PlotData(Operation, Process):
38 class PlotData(Operation, Process):
37 '''
39 '''
38 Base class for Schain plotting operations
40 Base class for Schain plotting operations
39 '''
41 '''
40
42
41 CODE = 'Figure'
43 CODE = 'Figure'
42 colormap = 'jro'
44 colormap = 'jro'
43 bgcolor = 'white'
45 bgcolor = 'white'
44 CONFLATE = False
46 CONFLATE = False
45 __MAXNUMX = 80
47 __MAXNUMX = 80
46 __missing = 1E30
48 __missing = 1E30
47
49
48 def __init__(self, **kwargs):
50 def __init__(self, **kwargs):
49
51
50 Operation.__init__(self, plot=True, **kwargs)
52 Operation.__init__(self, plot=True, **kwargs)
51 Process.__init__(self)
53 Process.__init__(self)
52 self.kwargs['code'] = self.CODE
54 self.kwargs['code'] = self.CODE
53 self.mp = False
55 self.mp = False
54 self.data = None
56 self.data = None
55 self.isConfig = False
57 self.isConfig = False
56 self.figures = []
58 self.figures = []
57 self.axes = []
59 self.axes = []
58 self.cb_axes = []
60 self.cb_axes = []
59 self.localtime = kwargs.pop('localtime', True)
61 self.localtime = kwargs.pop('localtime', True)
60 self.show = kwargs.get('show', True)
62 self.show = kwargs.get('show', True)
61 self.save = kwargs.get('save', False)
63 self.save = kwargs.get('save', False)
62 self.colormap = kwargs.get('colormap', self.colormap)
64 self.colormap = kwargs.get('colormap', self.colormap)
63 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
65 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
64 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
66 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
65 self.colormaps = kwargs.get('colormaps', None)
67 self.colormaps = kwargs.get('colormaps', None)
66 self.bgcolor = kwargs.get('bgcolor', self.bgcolor)
68 self.bgcolor = kwargs.get('bgcolor', self.bgcolor)
67 self.showprofile = kwargs.get('showprofile', False)
69 self.showprofile = kwargs.get('showprofile', False)
68 self.title = kwargs.get('wintitle', self.CODE.upper())
70 self.title = kwargs.get('wintitle', self.CODE.upper())
69 self.cb_label = kwargs.get('cb_label', None)
71 self.cb_label = kwargs.get('cb_label', None)
70 self.cb_labels = kwargs.get('cb_labels', None)
72 self.cb_labels = kwargs.get('cb_labels', None)
71 self.xaxis = kwargs.get('xaxis', 'frequency')
73 self.xaxis = kwargs.get('xaxis', 'frequency')
72 self.zmin = kwargs.get('zmin', None)
74 self.zmin = kwargs.get('zmin', None)
73 self.zmax = kwargs.get('zmax', None)
75 self.zmax = kwargs.get('zmax', None)
74 self.zlimits = kwargs.get('zlimits', None)
76 self.zlimits = kwargs.get('zlimits', None)
75 self.xmin = kwargs.get('xmin', None)
77 self.xmin = kwargs.get('xmin', None)
76 self.xmax = kwargs.get('xmax', None)
78 self.xmax = kwargs.get('xmax', None)
77 self.xrange = kwargs.get('xrange', 24)
79 self.xrange = kwargs.get('xrange', 24)
78 self.ymin = kwargs.get('ymin', None)
80 self.ymin = kwargs.get('ymin', None)
79 self.ymax = kwargs.get('ymax', None)
81 self.ymax = kwargs.get('ymax', None)
80 self.xlabel = kwargs.get('xlabel', None)
82 self.xlabel = kwargs.get('xlabel', None)
81 self.__MAXNUMY = kwargs.get('decimation', 100)
83 self.__MAXNUMY = kwargs.get('decimation', 100)
82 self.showSNR = kwargs.get('showSNR', False)
84 self.showSNR = kwargs.get('showSNR', False)
83 self.oneFigure = kwargs.get('oneFigure', True)
85 self.oneFigure = kwargs.get('oneFigure', True)
84 self.width = kwargs.get('width', None)
86 self.width = kwargs.get('width', None)
85 self.height = kwargs.get('height', None)
87 self.height = kwargs.get('height', None)
86 self.colorbar = kwargs.get('colorbar', True)
88 self.colorbar = kwargs.get('colorbar', True)
87 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
89 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
88 self.titles = ['' for __ in range(16)]
90 self.titles = ['' for __ in range(16)]
89
91
90 def __fmtTime(self, x, pos):
92 def __fmtTime(self, x, pos):
91 '''
93 '''
92 '''
94 '''
93
95
94 return '{}'.format(self.getDateTime(x).strftime('%H:%M'))
96 return '{}'.format(self.getDateTime(x).strftime('%H:%M'))
95
97
96 def __setup(self):
98 def __setup(self):
97 '''
99 '''
98 Common setup for all figures, here figures and axes are created
100 Common setup for all figures, here figures and axes are created
99 '''
101 '''
100
102
101 self.setup()
103 self.setup()
102
104
103 self.time_label = 'LT' if self.localtime else 'UTC'
105 self.time_label = 'LT' if self.localtime else 'UTC'
104 if self.data.localtime:
106 if self.data.localtime:
105 self.getDateTime = datetime.datetime.fromtimestamp
107 self.getDateTime = datetime.datetime.fromtimestamp
106 else:
108 else:
107 self.getDateTime = datetime.datetime.utcfromtimestamp
109 self.getDateTime = datetime.datetime.utcfromtimestamp
108
110
109 if self.width is None:
111 if self.width is None:
110 self.width = 8
112 self.width = 8
111
113
112 self.figures = []
114 self.figures = []
113 self.axes = []
115 self.axes = []
114 self.cb_axes = []
116 self.cb_axes = []
115 self.pf_axes = []
117 self.pf_axes = []
116 self.cmaps = []
118 self.cmaps = []
117
119
118 size = '15%' if self.ncols==1 else '30%'
120 size = '15%' if self.ncols == 1 else '30%'
119 pad = '4%' if self.ncols==1 else '8%'
121 pad = '4%' if self.ncols == 1 else '8%'
120
122
121 if self.oneFigure:
123 if self.oneFigure:
122 if self.height is None:
124 if self.height is None:
123 self.height = 1.4*self.nrows + 1
125 self.height = 1.4 * self.nrows + 1
124 fig = plt.figure(figsize=(self.width, self.height),
126 fig = plt.figure(figsize=(self.width, self.height),
125 edgecolor='k',
127 edgecolor='k',
126 facecolor='w')
128 facecolor='w')
127 self.figures.append(fig)
129 self.figures.append(fig)
128 for n in range(self.nplots):
130 for n in range(self.nplots):
129 ax = fig.add_subplot(self.nrows, self.ncols, n+1)
131 ax = fig.add_subplot(self.nrows, self.ncols, n + 1)
130 ax.tick_params(labelsize=8)
132 ax.tick_params(labelsize=8)
131 ax.firsttime = True
133 ax.firsttime = True
132 ax.index = 0
134 ax.index = 0
133 ax.press = None
135 ax.press = None
134 self.axes.append(ax)
136 self.axes.append(ax)
135 if self.showprofile:
137 if self.showprofile:
136 cax = self.__add_axes(ax, size=size, pad=pad)
138 cax = self.__add_axes(ax, size=size, pad=pad)
137 cax.tick_params(labelsize=8)
139 cax.tick_params(labelsize=8)
138 self.pf_axes.append(cax)
140 self.pf_axes.append(cax)
139 else:
141 else:
140 if self.height is None:
142 if self.height is None:
141 self.height = 3
143 self.height = 3
142 for n in range(self.nplots):
144 for n in range(self.nplots):
143 fig = plt.figure(figsize=(self.width, self.height),
145 fig = plt.figure(figsize=(self.width, self.height),
144 edgecolor='k',
146 edgecolor='k',
145 facecolor='w')
147 facecolor='w')
146 ax = fig.add_subplot(1, 1, 1)
148 ax = fig.add_subplot(1, 1, 1)
147 ax.tick_params(labelsize=8)
149 ax.tick_params(labelsize=8)
148 ax.firsttime = True
150 ax.firsttime = True
149 ax.index = 0
151 ax.index = 0
150 ax.press = None
152 ax.press = None
151 self.figures.append(fig)
153 self.figures.append(fig)
152 self.axes.append(ax)
154 self.axes.append(ax)
153 if self.showprofile:
155 if self.showprofile:
154 cax = self.__add_axes(ax, size=size, pad=pad)
156 cax = self.__add_axes(ax, size=size, pad=pad)
155 cax.tick_params(labelsize=8)
157 cax.tick_params(labelsize=8)
156 self.pf_axes.append(cax)
158 self.pf_axes.append(cax)
157
159
158 for n in range(self.nrows):
160 for n in range(self.nrows):
159 if self.colormaps is not None:
161 if self.colormaps is not None:
160 cmap = plt.get_cmap(self.colormaps[n])
162 cmap = plt.get_cmap(self.colormaps[n])
161 else:
163 else:
162 cmap = plt.get_cmap(self.colormap)
164 cmap = plt.get_cmap(self.colormap)
163 cmap.set_bad(self.bgcolor, 1.)
165 cmap.set_bad(self.bgcolor, 1.)
164 self.cmaps.append(cmap)
166 self.cmaps.append(cmap)
165
167
166 for fig in self.figures:
168 for fig in self.figures:
167 fig.canvas.mpl_connect('key_press_event', self.OnKeyPress)
169 fig.canvas.mpl_connect('key_press_event', self.OnKeyPress)
168 fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll)
170 fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll)
169 fig.canvas.mpl_connect('button_press_event', self.onBtnPress)
171 fig.canvas.mpl_connect('button_press_event', self.onBtnPress)
170 fig.canvas.mpl_connect('motion_notify_event', self.onMotion)
172 fig.canvas.mpl_connect('motion_notify_event', self.onMotion)
171 fig.canvas.mpl_connect('button_release_event', self.onBtnRelease)
173 fig.canvas.mpl_connect('button_release_event', self.onBtnRelease)
172 if self.show:
174 if self.show:
173 fig.show()
175 fig.show()
174
176
175 def OnKeyPress(self, event):
177 def OnKeyPress(self, event):
176 '''
178 '''
177 Event for pressing keys (up, down) change colormap
179 Event for pressing keys (up, down) change colormap
178 '''
180 '''
179 ax = event.inaxes
181 ax = event.inaxes
180 if ax in self.axes:
182 if ax in self.axes:
181 if event.key == 'down':
183 if event.key == 'down':
182 ax.index += 1
184 ax.index += 1
183 elif event.key == 'up':
185 elif event.key == 'up':
184 ax.index -= 1
186 ax.index -= 1
185 if ax.index < 0:
187 if ax.index < 0:
186 ax.index = len(CMAPS) - 1
188 ax.index = len(CMAPS) - 1
187 elif ax.index == len(CMAPS):
189 elif ax.index == len(CMAPS):
188 ax.index = 0
190 ax.index = 0
189 cmap = CMAPS[ax.index]
191 cmap = CMAPS[ax.index]
190 ax.cbar.set_cmap(cmap)
192 ax.cbar.set_cmap(cmap)
191 ax.cbar.draw_all()
193 ax.cbar.draw_all()
192 ax.plt.set_cmap(cmap)
194 ax.plt.set_cmap(cmap)
193 ax.cbar.patch.figure.canvas.draw()
195 ax.cbar.patch.figure.canvas.draw()
194 self.colormap = cmap.name
196 self.colormap = cmap.name
195
197
196 def OnBtnScroll(self, event):
198 def OnBtnScroll(self, event):
197 '''
199 '''
198 Event for scrolling, scale figure
200 Event for scrolling, scale figure
199 '''
201 '''
200 cb_ax = event.inaxes
202 cb_ax = event.inaxes
201 if cb_ax in [ax.cbar.ax for ax in self.axes]:
203 if cb_ax in [ax.cbar.ax for ax in self.axes]:
202 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
204 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
203 pt = ax.cbar.ax.bbox.get_points()[:,1]
205 pt = ax.cbar.ax.bbox.get_points()[:,1]
204 nrm = ax.cbar.norm
206 nrm = ax.cbar.norm
205 vmin, vmax, p0, p1, pS = (nrm.vmin, nrm.vmax, pt[0], pt[1], event.y)
207 vmin, vmax, p0, p1, pS = (nrm.vmin, nrm.vmax, pt[0], pt[1], event.y)
206 scale = 2 if event.step == 1 else 0.5
208 scale = 2 if event.step == 1 else 0.5
207 point = vmin + (vmax - vmin) / (p1 - p0)*(pS - p0)
209 point = vmin + (vmax - vmin) / (p1 - p0)*(pS - p0)
208 ax.cbar.norm.vmin = point - scale*(point - vmin)
210 ax.cbar.norm.vmin = point - scale*(point - vmin)
209 ax.cbar.norm.vmax = point - scale*(point - vmax)
211 ax.cbar.norm.vmax = point - scale*(point - vmax)
210 ax.plt.set_norm(ax.cbar.norm)
212 ax.plt.set_norm(ax.cbar.norm)
211 ax.cbar.draw_all()
213 ax.cbar.draw_all()
212 ax.cbar.patch.figure.canvas.draw()
214 ax.cbar.patch.figure.canvas.draw()
213
215
214 def onBtnPress(self, event):
216 def onBtnPress(self, event):
215 '''
217 '''
216 Event for mouse button press
218 Event for mouse button press
217 '''
219 '''
218 cb_ax = event.inaxes
220 cb_ax = event.inaxes
219 if cb_ax is None:
221 if cb_ax is None:
220 return
222 return
221
223
222 if cb_ax in [ax.cbar.ax for ax in self.axes]:
224 if cb_ax in [ax.cbar.ax for ax in self.axes]:
223 cb_ax.press = event.x, event.y
225 cb_ax.press = event.x, event.y
224 else:
226 else:
225 cb_ax.press = None
227 cb_ax.press = None
226
228
227 def onMotion(self, event):
229 def onMotion(self, event):
228 '''
230 '''
229 Event for move inside colorbar
231 Event for move inside colorbar
230 '''
232 '''
231 cb_ax = event.inaxes
233 cb_ax = event.inaxes
232 if cb_ax is None:
234 if cb_ax is None:
233 return
235 return
234 if cb_ax not in [ax.cbar.ax for ax in self.axes]:
236 if cb_ax not in [ax.cbar.ax for ax in self.axes]:
235 return
237 return
236 if cb_ax.press is None:
238 if cb_ax.press is None:
237 return
239 return
238
240
239 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
241 ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0]
240 xprev, yprev = cb_ax.press
242 xprev, yprev = cb_ax.press
241 dx = event.x - xprev
243 dx = event.x - xprev
242 dy = event.y - yprev
244 dy = event.y - yprev
243 cb_ax.press = event.x, event.y
245 cb_ax.press = event.x, event.y
244 scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin
246 scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin
245 perc = 0.03
247 perc = 0.03
246
248
247 if event.button == 1:
249 if event.button == 1:
248 ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy)
250 ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy)
249 ax.cbar.norm.vmax -= (perc*scale)*numpy.sign(dy)
251 ax.cbar.norm.vmax -= (perc*scale)*numpy.sign(dy)
250 elif event.button == 3:
252 elif event.button == 3:
251 ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy)
253 ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy)
252 ax.cbar.norm.vmax += (perc*scale)*numpy.sign(dy)
254 ax.cbar.norm.vmax += (perc*scale)*numpy.sign(dy)
253
255
254 ax.cbar.draw_all()
256 ax.cbar.draw_all()
255 ax.plt.set_norm(ax.cbar.norm)
257 ax.plt.set_norm(ax.cbar.norm)
256 ax.cbar.patch.figure.canvas.draw()
258 ax.cbar.patch.figure.canvas.draw()
257
259
258 def onBtnRelease(self, event):
260 def onBtnRelease(self, event):
259 '''
261 '''
260 Event for mouse button release
262 Event for mouse button release
261 '''
263 '''
262 cb_ax = event.inaxes
264 cb_ax = event.inaxes
263 if cb_ax is not None:
265 if cb_ax is not None:
264 cb_ax.press = None
266 cb_ax.press = None
265
267
266 def __add_axes(self, ax, size='30%', pad='8%'):
268 def __add_axes(self, ax, size='30%', pad='8%'):
267 '''
269 '''
268 Add new axes to the given figure
270 Add new axes to the given figure
269 '''
271 '''
270 divider = make_axes_locatable(ax)
272 divider = make_axes_locatable(ax)
271 nax = divider.new_horizontal(size=size, pad=pad)
273 nax = divider.new_horizontal(size=size, pad=pad)
272 ax.figure.add_axes(nax)
274 ax.figure.add_axes(nax)
273 return nax
275 return nax
274
276
275 self.setup()
277 self.setup()
276
278
277 def setup(self):
279 def setup(self):
278 '''
280 '''
279 This method should be implemented in the child class, the following
281 This method should be implemented in the child class, the following
280 attributes should be set:
282 attributes should be set:
281
283
282 self.nrows: number of rows
284 self.nrows: number of rows
283 self.ncols: number of cols
285 self.ncols: number of cols
284 self.nplots: number of plots (channels or pairs)
286 self.nplots: number of plots (channels or pairs)
285 self.ylabel: label for Y axes
287 self.ylabel: label for Y axes
286 self.titles: list of axes title
288 self.titles: list of axes title
287
289
288 '''
290 '''
289 raise(NotImplementedError, 'Implement this method in child class')
291 raise(NotImplementedError, 'Implement this method in child class')
290
292
291 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
293 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
292 '''
294 '''
293 Create a masked array for missing data
295 Create a masked array for missing data
294 '''
296 '''
295 if x_buffer.shape[0] < 2:
297 if x_buffer.shape[0] < 2:
296 return x_buffer, y_buffer, z_buffer
298 return x_buffer, y_buffer, z_buffer
297
299
298 deltas = x_buffer[1:] - x_buffer[0:-1]
300 deltas = x_buffer[1:] - x_buffer[0:-1]
299 x_median = numpy.median(deltas)
301 x_median = numpy.median(deltas)
300
302
301 index = numpy.where(deltas > 5*x_median)
303 index = numpy.where(deltas > 5 * x_median)
302
304
303 if len(index[0]) != 0:
305 if len(index[0]) != 0:
304 z_buffer[::, index[0], ::] = self.__missing
306 z_buffer[::, index[0], ::] = self.__missing
305 z_buffer = numpy.ma.masked_inside(z_buffer,
307 z_buffer = numpy.ma.masked_inside(z_buffer,
306 0.99*self.__missing,
308 0.99 * self.__missing,
307 1.01*self.__missing)
309 1.01 * self.__missing)
308
310
309 return x_buffer, y_buffer, z_buffer
311 return x_buffer, y_buffer, z_buffer
310
312
311 def decimate(self):
313 def decimate(self):
312
314
313 # dx = int(len(self.x)/self.__MAXNUMX) + 1
315 # dx = int(len(self.x)/self.__MAXNUMX) + 1
314 dy = int(len(self.y)/self.__MAXNUMY) + 1
316 dy = int(len(self.y) / self.__MAXNUMY) + 1
315
317
316 # x = self.x[::dx]
318 # x = self.x[::dx]
317 x = self.x
319 x = self.x
318 y = self.y[::dy]
320 y = self.y[::dy]
319 z = self.z[::, ::, ::dy]
321 z = self.z[::, ::, ::dy]
320
322
321 return x, y, z
323 return x, y, z
322
324
323 def format(self):
325 def format(self):
324 '''
326 '''
325 Set min and max values, labels, ticks and titles
327 Set min and max values, labels, ticks and titles
326 '''
328 '''
327
329
328 if self.xmin is None:
330 if self.xmin is None:
329 xmin = self.min_time
331 xmin = self.min_time
330 else:
332 else:
331 if self.xaxis is 'time':
333 if self.xaxis is 'time':
332 dt = self.getDateTime(self.min_time)
334 dt = self.getDateTime(self.min_time)
333 xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds()
335 xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds()
334 if self.data.localtime:
336 if self.data.localtime:
335 xmin += time.timezone
337 xmin += time.timezone
336 else:
338 else:
337 xmin = self.xmin
339 xmin = self.xmin
338
340
339 if self.xmax is None:
341 if self.xmax is None:
340 xmax = xmin+self.xrange*60*60
342 xmax = xmin + self.xrange * 60 * 60
341 else:
343 else:
342 if self.xaxis is 'time':
344 if self.xaxis is 'time':
343 dt = self.getDateTime(self.max_time)
345 dt = self.getDateTime(self.max_time)
344 xmax = (dt.replace(hour=int(self.xmax), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds()
346 xmax = (dt.replace(hour=int(self.xmax), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds()
345 if self.data.localtime:
347 if self.data.localtime:
346 xmax += time.timezone
348 xmax += time.timezone
347 else:
349 else:
348 xmax = self.xmax
350 xmax = self.xmax
349
351
350 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
352 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
351 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
353 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
352
354
353 Y = numpy.array([10, 20, 50, 100, 200, 500, 1000, 2000])
355 Y = numpy.array([10, 20, 50, 100, 200, 500, 1000, 2000])
354 i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0]
356 i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0]
355 ystep = Y[i-1]/5
357 ystep = Y[i-1]/5
356
358
359 ystep = 200 if ymax >= 800 else 100 if ymax >= 400 else 50 if ymax >= 200 else 20
360
357 for n, ax in enumerate(self.axes):
361 for n, ax in enumerate(self.axes):
358 if ax.firsttime:
362 if ax.firsttime:
359 ax.set_facecolor(self.bgcolor)
363 ax.set_facecolor(self.bgcolor)
360 ax.yaxis.set_major_locator(MultipleLocator(ystep))
364 ax.yaxis.set_major_locator(MultipleLocator(ystep))
361 if self.xaxis is 'time':
365 if self.xaxis is 'time':
362 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime))
366 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime))
363 ax.xaxis.set_major_locator(LinearLocator(9))
367 ax.xaxis.set_major_locator(LinearLocator(9))
364 if self.xlabel is not None:
368 if self.xlabel is not None:
365 ax.set_xlabel(self.xlabel)
369 ax.set_xlabel(self.xlabel)
366 ax.set_ylabel(self.ylabel)
370 ax.set_ylabel(self.ylabel)
367 ax.firsttime = False
371 ax.firsttime = False
368 if self.showprofile:
372 if self.showprofile:
369 self.pf_axes[n].set_ylim(ymin, ymax)
373 self.pf_axes[n].set_ylim(ymin, ymax)
370 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
374 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
371 self.pf_axes[n].set_xlabel('dB')
375 self.pf_axes[n].set_xlabel('dB')
372 self.pf_axes[n].grid(b=True, axis='x')
376 self.pf_axes[n].grid(b=True, axis='x')
373 [tick.set_visible(False) for tick in self.pf_axes[n].get_yticklabels()]
377 [tick.set_visible(False)
378 for tick in self.pf_axes[n].get_yticklabels()]
374 if self.colorbar:
379 if self.colorbar:
375 ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10)
380 ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10)
376 ax.cbar.ax.tick_params(labelsize=8)
381 ax.cbar.ax.tick_params(labelsize=8)
377 ax.cbar.ax.press = None
382 ax.cbar.ax.press = None
378 if self.cb_label:
383 if self.cb_label:
379 ax.cbar.set_label(self.cb_label, size=8)
384 ax.cbar.set_label(self.cb_label, size=8)
380 elif self.cb_labels:
385 elif self.cb_labels:
381 ax.cbar.set_label(self.cb_labels[n], size=8)
386 ax.cbar.set_label(self.cb_labels[n], size=8)
382
387
383 ax.set_title('{} - {} {}'.format(
388 ax.set_title('{} - {} {}'.format(
384 self.titles[n],
389 self.titles[n],
385 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
390 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
386 self.time_label),
391 self.time_label),
387 size=8)
392 size=8)
388 ax.set_xlim(xmin, xmax)
393 ax.set_xlim(xmin, xmax)
389 ax.set_ylim(ymin, ymax)
394 ax.set_ylim(ymin, ymax)
390
395
391 def __plot(self):
396 def __plot(self):
392 '''
397 '''
393 '''
398 '''
394 log.success('Plotting', self.name)
399 log.success('Plotting', self.name)
395
400
396 self.plot()
401 self.plot()
397 self.format()
402 self.format()
398
403
399 for n, fig in enumerate(self.figures):
404 for n, fig in enumerate(self.figures):
400 if self.nrows == 0 or self.nplots == 0:
405 if self.nrows == 0 or self.nplots == 0:
401 log.warning('No data', self.name)
406 log.warning('No data', self.name)
402 continue
407 continue
403
408
404 fig.tight_layout()
409 fig.tight_layout()
405 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
410 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
406 self.getDateTime(self.max_time).strftime('%Y/%m/%d')))
411 self.getDateTime(self.max_time).strftime('%Y/%m/%d')))
407 # fig.canvas.draw()
412 # fig.canvas.draw()
408
413
409 if self.save and self.data.ended:
414 if self.save and self.data.ended:
410 channels = range(self.nrows)
415 channels = range(self.nrows)
411 if self.oneFigure:
416 if self.oneFigure:
412 label = ''
417 label = ''
413 else:
418 else:
414 label = '_{}'.format(channels[n])
419 label = '_{}'.format(channels[n])
415 figname = os.path.join(
420 figname = os.path.join(
416 self.save,
421 self.save,
417 '{}{}_{}.png'.format(
422 '{}{}_{}.png'.format(
418 self.CODE,
423 self.CODE,
419 label,
424 label,
420 self.getDateTime(self.saveTime).strftime('%y%m%d_%H%M%S')
425 self.getDateTime(self.saveTime).strftime('%y%m%d_%H%M%S')
421 )
426 )
422 )
427 )
423 print 'Saving figure: {}'.format(figname)
428 print 'Saving figure: {}'.format(figname)
424 fig.savefig(figname)
429 fig.savefig(figname)
425
430
426 def plot(self):
431 def plot(self):
427 '''
432 '''
428 '''
433 '''
429 raise(NotImplementedError, 'Implement this method in child class')
434 raise(NotImplementedError, 'Implement this method in child class')
430
435
431 def run(self):
436 def run(self):
432
437
433 log.success('Starting', self.name)
438 log.success('Starting', self.name)
434
439
435 context = zmq.Context()
440 context = zmq.Context()
436 receiver = context.socket(zmq.SUB)
441 receiver = context.socket(zmq.SUB)
437 receiver.setsockopt(zmq.SUBSCRIBE, '')
442 receiver.setsockopt(zmq.SUBSCRIBE, '')
438 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
443 receiver.setsockopt(zmq.CONFLATE, self.CONFLATE)
439
444
440 if 'server' in self.kwargs['parent']:
445 if 'server' in self.kwargs['parent']:
441 receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
446 receiver.connect(
447 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server']))
442 else:
448 else:
443 receiver.connect("ipc:///tmp/zmq.plots")
449 receiver.connect("ipc:///tmp/zmq.plots")
444
450
445 while True:
451 while True:
446 try:
452 try:
447 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
453 self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)
448 if self.data.localtime and self.localtime:
454 if self.data.localtime and self.localtime:
449 self.times = self.data.times
455 self.times = self.data.times
450 elif self.data.localtime and not self.localtime:
456 elif self.data.localtime and not self.localtime:
451 self.times = self.data.times + time.timezone
457 self.times = self.data.times + time.timezone
452 elif not self.data.localtime and self.localtime:
458 elif not self.data.localtime and self.localtime:
453 self.times = self.data.times - time.timezone
459 self.times = self.data.times - time.timezone
454 else:
460 else:
455 self.times = self.data.times
461 self.times = self.data.times
456
462
457 self.min_time = self.times[0]
463 self.min_time = self.times[0]
458 self.max_time = self.times[-1]
464 self.max_time = self.times[-1]
459
465
460 if self.isConfig is False:
466 if self.isConfig is False:
461 self.__setup()
467 self.__setup()
462 self.isConfig = True
468 self.isConfig = True
463
469
464 self.__plot()
470 self.__plot()
465
471
466 except zmq.Again as e:
472 except zmq.Again as e:
467 log.log('Waiting for data...')
473 log.log('Waiting for data...')
468 if self.data:
474 if self.data:
469 figpause(self.data.throttle)
475 figpause(self.data.throttle)
470 else:
476 else:
471 time.sleep(2)
477 time.sleep(2)
472
478
473 def close(self):
479 def close(self):
474 if self.data:
480 if self.data:
475 self.__plot()
481 self.__plot()
476
482
483
477 class PlotSpectraData(PlotData):
484 class PlotSpectraData(PlotData):
478 '''
485 '''
479 Plot for Spectra data
486 Plot for Spectra data
480 '''
487 '''
481
488
482 CODE = 'spc'
489 CODE = 'spc'
483 colormap = 'jro'
490 colormap = 'jro'
484
491
485 def setup(self):
492 def setup(self):
486 self.nplots = len(self.data.channels)
493 self.nplots = len(self.data.channels)
487 self.ncols = int(numpy.sqrt(self.nplots)+ 0.9)
494 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
488 self.nrows = int((1.0*self.nplots/self.ncols) + 0.9)
495 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
489 self.width = 3.4*self.ncols
496 self.width = 3.4 * self.ncols
490 self.height = 3*self.nrows
497 self.height = 3 * self.nrows
491 self.cb_label = 'dB'
498 self.cb_label = 'dB'
492 if self.showprofile:
499 if self.showprofile:
493 self.width += 0.8*self.ncols
500 self.width += 0.8 * self.ncols
494
501
495 self.ylabel = 'Range [Km]'
502 self.ylabel = 'Range [Km]'
496
503
497 def plot(self):
504 def plot(self):
498 if self.xaxis == "frequency":
505 if self.xaxis == "frequency":
499 x = self.data.xrange[0]
506 x = self.data.xrange[0]
500 self.xlabel = "Frequency (kHz)"
507 self.xlabel = "Frequency (kHz)"
501 elif self.xaxis == "time":
508 elif self.xaxis == "time":
502 x = self.data.xrange[1]
509 x = self.data.xrange[1]
503 self.xlabel = "Time (ms)"
510 self.xlabel = "Time (ms)"
504 else:
511 else:
505 x = self.data.xrange[2]
512 x = self.data.xrange[2]
506 self.xlabel = "Velocity (m/s)"
513 self.xlabel = "Velocity (m/s)"
507
514
508 if self.CODE == 'spc_mean':
515 if self.CODE == 'spc_mean':
509 x = self.data.xrange[2]
516 x = self.data.xrange[2]
510 self.xlabel = "Velocity (m/s)"
517 self.xlabel = "Velocity (m/s)"
511
518
512 self.titles = []
519 self.titles = []
513
520
514 y = self.data.heights
521 y = self.data.heights
515 self.y = y
522 self.y = y
516 z = self.data['spc']
523 z = self.data['spc']
517
524
518 for n, ax in enumerate(self.axes):
525 for n, ax in enumerate(self.axes):
519 noise = self.data['noise'][n][-1]
526 noise = self.data['noise'][n][-1]
520 if self.CODE == 'spc_mean':
527 if self.CODE == 'spc_mean':
521 mean = self.data['mean'][n][-1]
528 mean = self.data['mean'][n][-1]
522 if ax.firsttime:
529 if ax.firsttime:
523 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
530 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
524 self.xmin = self.xmin if self.xmin else -self.xmax
531 self.xmin = self.xmin if self.xmin else -self.xmax
525 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
532 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
526 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
533 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
527 ax.plt = ax.pcolormesh(x, y, z[n].T,
534 ax.plt = ax.pcolormesh(x, y, z[n].T,
528 vmin=self.zmin,
535 vmin=self.zmin,
529 vmax=self.zmax,
536 vmax=self.zmax,
530 cmap=plt.get_cmap(self.colormap)
537 cmap=plt.get_cmap(self.colormap)
531 )
538 )
532
539
533 if self.showprofile:
540 if self.showprofile:
534 ax.plt_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], y)[0]
541 ax.plt_profile = self.pf_axes[n].plot(
542 self.data['rti'][n][-1], y)[0]
535 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
543 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
536 color="k", linestyle="dashed", lw=1)[0]
544 color="k", linestyle="dashed", lw=1)[0]
537 if self.CODE == 'spc_mean':
545 if self.CODE == 'spc_mean':
538 ax.plt_mean = ax.plot(mean, y, color='k')[0]
546 ax.plt_mean = ax.plot(mean, y, color='k')[0]
539 else:
547 else:
540 ax.plt.set_array(z[n].T.ravel())
548 ax.plt.set_array(z[n].T.ravel())
541 if self.showprofile:
549 if self.showprofile:
542 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
550 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
543 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
551 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
544 if self.CODE == 'spc_mean':
552 if self.CODE == 'spc_mean':
545 ax.plt_mean.set_data(mean, y)
553 ax.plt_mean.set_data(mean, y)
546
554
547 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
555 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
548 self.saveTime = self.max_time
556 self.saveTime = self.max_time
549
557
550
558
551 class PlotCrossSpectraData(PlotData):
559 class PlotCrossSpectraData(PlotData):
552
560
553 CODE = 'cspc'
561 CODE = 'cspc'
554 zmin_coh = None
562 zmin_coh = None
555 zmax_coh = None
563 zmax_coh = None
556 zmin_phase = None
564 zmin_phase = None
557 zmax_phase = None
565 zmax_phase = None
558
566
559 def setup(self):
567 def setup(self):
560
568
561 self.ncols = 4
569 self.ncols = 4
562 self.nrows = len(self.data.pairs)
570 self.nrows = len(self.data.pairs)
563 self.nplots = self.nrows*4
571 self.nplots = self.nrows * 4
564 self.width = 3.4*self.ncols
572 self.width = 3.4 * self.ncols
565 self.height = 3*self.nrows
573 self.height = 3 * self.nrows
566 self.ylabel = 'Range [Km]'
574 self.ylabel = 'Range [Km]'
567 self.showprofile = False
575 self.showprofile = False
568
576
569 def plot(self):
577 def plot(self):
570
578
571 if self.xaxis == "frequency":
579 if self.xaxis == "frequency":
572 x = self.data.xrange[0]
580 x = self.data.xrange[0]
573 self.xlabel = "Frequency (kHz)"
581 self.xlabel = "Frequency (kHz)"
574 elif self.xaxis == "time":
582 elif self.xaxis == "time":
575 x = self.data.xrange[1]
583 x = self.data.xrange[1]
576 self.xlabel = "Time (ms)"
584 self.xlabel = "Time (ms)"
577 else:
585 else:
578 x = self.data.xrange[2]
586 x = self.data.xrange[2]
579 self.xlabel = "Velocity (m/s)"
587 self.xlabel = "Velocity (m/s)"
580
588
581 self.titles = []
589 self.titles = []
582
590
583 y = self.data.heights
591 y = self.data.heights
584 self.y = y
592 self.y = y
585 spc = self.data['spc']
593 spc = self.data['spc']
586 cspc = self.data['cspc']
594 cspc = self.data['cspc']
587
595
588 for n in range(self.nrows):
596 for n in range(self.nrows):
589 noise = self.data['noise'][n][-1]
597 noise = self.data['noise'][n][-1]
590 pair = self.data.pairs[n]
598 pair = self.data.pairs[n]
591 ax = self.axes[4*n]
599 ax = self.axes[4 * n]
592 ax3 = self.axes[4*n+3]
600 ax3 = self.axes[4 * n + 3]
593 if ax.firsttime:
601 if ax.firsttime:
594 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
602 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
595 self.xmin = self.xmin if self.xmin else -self.xmax
603 self.xmin = self.xmin if self.xmin else -self.xmax
596 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
604 self.zmin = self.zmin if self.zmin else numpy.nanmin(spc)
597 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
605 self.zmax = self.zmax if self.zmax else numpy.nanmax(spc)
598 ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T,
606 ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T,
599 vmin=self.zmin,
607 vmin=self.zmin,
600 vmax=self.zmax,
608 vmax=self.zmax,
601 cmap=plt.get_cmap(self.colormap)
609 cmap=plt.get_cmap(self.colormap)
602 )
610 )
603 else:
611 else:
604 ax.plt.set_array(spc[pair[0]].T.ravel())
612 ax.plt.set_array(spc[pair[0]].T.ravel())
605 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
613 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
606
614
607 ax = self.axes[4*n+1]
615 ax = self.axes[4 * n + 1]
608 if ax.firsttime:
616 if ax.firsttime:
609 ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T,
617 ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T,
610 vmin=self.zmin,
618 vmin=self.zmin,
611 vmax=self.zmax,
619 vmax=self.zmax,
612 cmap=plt.get_cmap(self.colormap)
620 cmap=plt.get_cmap(self.colormap)
613 )
621 )
614 else:
622 else:
615 ax.plt.set_array(spc[pair[1]].T.ravel())
623 ax.plt.set_array(spc[pair[1]].T.ravel())
616 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
624 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
617
625
618 out = cspc[n]/numpy.sqrt(spc[pair[0]]*spc[pair[1]])
626 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
619 coh = numpy.abs(out)
627 coh = numpy.abs(out)
620 phase = numpy.arctan2(out.imag, out.real)*180/numpy.pi
628 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
621
629
622 ax = self.axes[4*n+2]
630 ax = self.axes[4 * n + 2]
623 if ax.firsttime:
631 if ax.firsttime:
624 ax.plt = ax.pcolormesh(x, y, coh.T,
632 ax.plt = ax.pcolormesh(x, y, coh.T,
625 vmin=0,
633 vmin=0,
626 vmax=1,
634 vmax=1,
627 cmap=plt.get_cmap(self.colormap_coh)
635 cmap=plt.get_cmap(self.colormap_coh)
628 )
636 )
629 else:
637 else:
630 ax.plt.set_array(coh.T.ravel())
638 ax.plt.set_array(coh.T.ravel())
631 self.titles.append('Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
639 self.titles.append(
640 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
632
641
633 ax = self.axes[4*n+3]
642 ax = self.axes[4 * n + 3]
634 if ax.firsttime:
643 if ax.firsttime:
635 ax.plt = ax.pcolormesh(x, y, phase.T,
644 ax.plt = ax.pcolormesh(x, y, phase.T,
636 vmin=-180,
645 vmin=-180,
637 vmax=180,
646 vmax=180,
638 cmap=plt.get_cmap(self.colormap_phase)
647 cmap=plt.get_cmap(self.colormap_phase)
639 )
648 )
640 else:
649 else:
641 ax.plt.set_array(phase.T.ravel())
650 ax.plt.set_array(phase.T.ravel())
642 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
651 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
643
652
644 self.saveTime = self.max_time
653 self.saveTime = self.max_time
645
654
646
655
647 class PlotSpectraMeanData(PlotSpectraData):
656 class PlotSpectraMeanData(PlotSpectraData):
648 '''
657 '''
649 Plot for Spectra and Mean
658 Plot for Spectra and Mean
650 '''
659 '''
651 CODE = 'spc_mean'
660 CODE = 'spc_mean'
652 colormap = 'jro'
661 colormap = 'jro'
653
662
654
663
655 class PlotRTIData(PlotData):
664 class PlotRTIData(PlotData):
656 '''
665 '''
657 Plot for RTI data
666 Plot for RTI data
658 '''
667 '''
659
668
660 CODE = 'rti'
669 CODE = 'rti'
661 colormap = 'jro'
670 colormap = 'jro'
662
671
663 def setup(self):
672 def setup(self):
664 self.xaxis = 'time'
673 self.xaxis = 'time'
665 self.ncols = 1
674 self.ncols = 1
666 self.nrows = len(self.data.channels)
675 self.nrows = len(self.data.channels)
667 self.nplots = len(self.data.channels)
676 self.nplots = len(self.data.channels)
668 self.ylabel = 'Range [Km]'
677 self.ylabel = 'Range [Km]'
669 self.cb_label = 'dB'
678 self.cb_label = 'dB'
670 self.titles = ['{} Channel {}'.format(self.CODE.upper(), x) for x in range(self.nrows)]
679 self.titles = ['{} Channel {}'.format(
680 self.CODE.upper(), x) for x in range(self.nrows)]
671
681
672 def plot(self):
682 def plot(self):
673 self.x = self.times
683 self.x = self.times
674 self.y = self.data.heights
684 self.y = self.data.heights
675 self.z = self.data[self.CODE]
685 self.z = self.data[self.CODE]
676 self.z = numpy.ma.masked_invalid(self.z)
686 self.z = numpy.ma.masked_invalid(self.z)
677
687
678 for n, ax in enumerate(self.axes):
688 for n, ax in enumerate(self.axes):
679 x, y, z = self.fill_gaps(*self.decimate())
689 x, y, z = self.fill_gaps(*self.decimate())
680 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
690 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
681 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
691 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
682 if ax.firsttime:
692 if ax.firsttime:
683 ax.plt = ax.pcolormesh(x, y, z[n].T,
693 ax.plt = ax.pcolormesh(x, y, z[n].T,
684 vmin=self.zmin,
694 vmin=self.zmin,
685 vmax=self.zmax,
695 vmax=self.zmax,
686 cmap=plt.get_cmap(self.colormap)
696 cmap=plt.get_cmap(self.colormap)
687 )
697 )
688 if self.showprofile:
698 if self.showprofile:
689 ax.plot_profile= self.pf_axes[n].plot(self.data['rti'][n][-1], self.y)[0]
699 ax.plot_profile = self.pf_axes[n].plot(
700 self.data['rti'][n][-1], self.y)[0]
690 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
701 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
691 color="k", linestyle="dashed", lw=1)[0]
702 color="k", linestyle="dashed", lw=1)[0]
692 else:
703 else:
693 ax.collections.remove(ax.collections[0])
704 ax.collections.remove(ax.collections[0])
694 ax.plt = ax.pcolormesh(x, y, z[n].T,
705 ax.plt = ax.pcolormesh(x, y, z[n].T,
695 vmin=self.zmin,
706 vmin=self.zmin,
696 vmax=self.zmax,
707 vmax=self.zmax,
697 cmap=plt.get_cmap(self.colormap)
708 cmap=plt.get_cmap(self.colormap)
698 )
709 )
699 if self.showprofile:
710 if self.showprofile:
700 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
711 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
701 ax.plot_noise.set_data(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y)
712 ax.plot_noise.set_data(numpy.repeat(
713 self.data['noise'][n][-1], len(self.y)), self.y)
702
714
703 self.saveTime = self.min_time
715 self.saveTime = self.min_time
704
716
705
717
706 class PlotCOHData(PlotRTIData):
718 class PlotCOHData(PlotRTIData):
707 '''
719 '''
708 Plot for Coherence data
720 Plot for Coherence data
709 '''
721 '''
710
722
711 CODE = 'coh'
723 CODE = 'coh'
712
724
713 def setup(self):
725 def setup(self):
714 self.xaxis = 'time'
726 self.xaxis = 'time'
715 self.ncols = 1
727 self.ncols = 1
716 self.nrows = len(self.data.pairs)
728 self.nrows = len(self.data.pairs)
717 self.nplots = len(self.data.pairs)
729 self.nplots = len(self.data.pairs)
718 self.ylabel = 'Range [Km]'
730 self.ylabel = 'Range [Km]'
719 if self.CODE == 'coh':
731 if self.CODE == 'coh':
720 self.cb_label = ''
732 self.cb_label = ''
721 self.titles = ['Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
733 self.titles = [
734 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
722 else:
735 else:
723 self.cb_label = 'Degrees'
736 self.cb_label = 'Degrees'
724 self.titles = ['Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
737 self.titles = [
738 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
725
739
726
740
727 class PlotPHASEData(PlotCOHData):
741 class PlotPHASEData(PlotCOHData):
728 '''
742 '''
729 Plot for Phase map data
743 Plot for Phase map data
730 '''
744 '''
731
745
732 CODE = 'phase'
746 CODE = 'phase'
733 colormap = 'seismic'
747 colormap = 'seismic'
734
748
735
749
736 class PlotNoiseData(PlotData):
750 class PlotNoiseData(PlotData):
737 '''
751 '''
738 Plot for noise
752 Plot for noise
739 '''
753 '''
740
754
741 CODE = 'noise'
755 CODE = 'noise'
742
756
743 def setup(self):
757 def setup(self):
744 self.xaxis = 'time'
758 self.xaxis = 'time'
745 self.ncols = 1
759 self.ncols = 1
746 self.nrows = 1
760 self.nrows = 1
747 self.nplots = 1
761 self.nplots = 1
748 self.ylabel = 'Intensity [dB]'
762 self.ylabel = 'Intensity [dB]'
749 self.titles = ['Noise']
763 self.titles = ['Noise']
750 self.colorbar = False
764 self.colorbar = False
751
765
752 def plot(self):
766 def plot(self):
753
767
754 x = self.times
768 x = self.times
755 xmin = self.min_time
769 xmin = self.min_time
756 xmax = xmin+self.xrange*60*60
770 xmax = xmin + self.xrange * 60 * 60
757 Y = self.data[self.CODE]
771 Y = self.data[self.CODE]
758
772
759 if self.axes[0].firsttime:
773 if self.axes[0].firsttime:
760 for ch in self.data.channels:
774 for ch in self.data.channels:
761 y = Y[ch]
775 y = Y[ch]
762 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
776 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
763 plt.legend()
777 plt.legend()
764 else:
778 else:
765 for ch in self.data.channels:
779 for ch in self.data.channels:
766 y = Y[ch]
780 y = Y[ch]
767 self.axes[0].lines[ch].set_data(x, y)
781 self.axes[0].lines[ch].set_data(x, y)
768
782
769 self.ymin = numpy.nanmin(Y) - 5
783 self.ymin = numpy.nanmin(Y) - 5
770 self.ymax = numpy.nanmax(Y) + 5
784 self.ymax = numpy.nanmax(Y) + 5
771 self.saveTime = self.min_time
785 self.saveTime = self.min_time
772
786
773
787
774 class PlotSNRData(PlotRTIData):
788 class PlotSNRData(PlotRTIData):
775 '''
789 '''
776 Plot for SNR Data
790 Plot for SNR Data
777 '''
791 '''
778
792
779 CODE = 'snr'
793 CODE = 'snr'
780 colormap = 'jet'
794 colormap = 'jet'
781
795
782
796
783 class PlotDOPData(PlotRTIData):
797 class PlotDOPData(PlotRTIData):
784 '''
798 '''
785 Plot for DOPPLER Data
799 Plot for DOPPLER Data
786 '''
800 '''
787
801
788 CODE = 'dop'
802 CODE = 'dop'
789 colormap = 'jet'
803 colormap = 'jet'
790
804
791
805
792 class PlotSkyMapData(PlotData):
806 class PlotSkyMapData(PlotData):
793 '''
807 '''
794 Plot for meteors detection data
808 Plot for meteors detection data
795 '''
809 '''
796
810
797 CODE = 'met'
811 CODE = 'met'
798
812
799 def setup(self):
813 def setup(self):
800
814
801 self.ncols = 1
815 self.ncols = 1
802 self.nrows = 1
816 self.nrows = 1
803 self.width = 7.2
817 self.width = 7.2
804 self.height = 7.2
818 self.height = 7.2
805
819
806 self.xlabel = 'Zonal Zenith Angle (deg)'
820 self.xlabel = 'Zonal Zenith Angle (deg)'
807 self.ylabel = 'Meridional Zenith Angle (deg)'
821 self.ylabel = 'Meridional Zenith Angle (deg)'
808
822
809 if self.figure is None:
823 if self.figure is None:
810 self.figure = plt.figure(figsize=(self.width, self.height),
824 self.figure = plt.figure(figsize=(self.width, self.height),
811 edgecolor='k',
825 edgecolor='k',
812 facecolor='w')
826 facecolor='w')
813 else:
827 else:
814 self.figure.clf()
828 self.figure.clf()
815
829
816 self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
830 self.ax = plt.subplot2grid(
831 (self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
817 self.ax.firsttime = True
832 self.ax.firsttime = True
818
833
819
820 def plot(self):
834 def plot(self):
821
835
822 arrayParameters = numpy.concatenate([self.data['param'][t] for t in self.times])
836 arrayParameters = numpy.concatenate(
837 [self.data['param'][t] for t in self.times])
823 error = arrayParameters[:,-1]
838 error = arrayParameters[:, -1]
824 indValid = numpy.where(error == 0)[0]
839 indValid = numpy.where(error == 0)[0]
825 finalMeteor = arrayParameters[indValid,:]
840 finalMeteor = arrayParameters[indValid, :]
826 finalAzimuth = finalMeteor[:,3]
841 finalAzimuth = finalMeteor[:, 3]
827 finalZenith = finalMeteor[:,4]
842 finalZenith = finalMeteor[:, 4]
828
843
829 x = finalAzimuth*numpy.pi/180
844 x = finalAzimuth * numpy.pi / 180
830 y = finalZenith
845 y = finalZenith
831
846
832 if self.ax.firsttime:
847 if self.ax.firsttime:
833 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
848 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
834 self.ax.set_ylim(0,90)
849 self.ax.set_ylim(0, 90)
835 self.ax.set_yticks(numpy.arange(0,90,20))
850 self.ax.set_yticks(numpy.arange(0, 90, 20))
836 self.ax.set_xlabel(self.xlabel)
851 self.ax.set_xlabel(self.xlabel)
837 self.ax.set_ylabel(self.ylabel)
852 self.ax.set_ylabel(self.ylabel)
838 self.ax.yaxis.labelpad = 40
853 self.ax.yaxis.labelpad = 40
839 self.ax.firsttime = False
854 self.ax.firsttime = False
840 else:
855 else:
841 self.ax.plot.set_data(x, y)
856 self.ax.plot.set_data(x, y)
842
857
843
858
844 dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S')
859 dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S')
845 dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S')
860 dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S')
846 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
861 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
847 dt2,
862 dt2,
848 len(x))
863 len(x))
849 self.ax.set_title(title, size=8)
864 self.ax.set_title(title, size=8)
850
851 self.saveTime = self.max_time
865 self.saveTime = self.max_time
852
866
867
853 class PlotParamData(PlotRTIData):
868 class PlotParamData(PlotRTIData):
854 '''
869 '''
855 Plot for data_param object
870 Plot for data_param object
856 '''
871 '''
857
872
858 CODE = 'param'
873 CODE = 'param'
859 colormap = 'seismic'
874 colormap = 'seismic'
860
875
861 def setup(self):
876 def setup(self):
862 self.xaxis = 'time'
877 self.xaxis = 'time'
863 self.ncols = 1
878 self.ncols = 1
864 self.nrows = self.data.shape(self.CODE)[0]
879 self.nrows = self.data.shape(self.CODE)[0]
865 self.nplots = self.nrows
880 self.nplots = self.nrows
866 if self.showSNR:
881 if self.showSNR:
867 self.nrows += 1
882 self.nrows += 1
868 self.nplots += 1
883 self.nplots += 1
869
884
870 self.ylabel = 'Height [Km]'
885 self.ylabel = 'Height [Km]'
871 self.titles = self.data.parameters \
886 self.titles = self.data.parameters \
872 if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)]
887 if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)]
873 if self.showSNR:
888 if self.showSNR:
874 self.titles.append('SNR')
889 self.titles.append('SNR')
875
890
876 def plot(self):
891 def plot(self):
877 self.data.normalize_heights()
892 self.data.normalize_heights()
878 self.x = self.times
893 self.x = self.times
879 self.y = self.data.heights
894 self.y = self.data.heights
880 if self.showSNR:
895 if self.showSNR:
881 self.z = numpy.concatenate(
896 self.z = numpy.concatenate(
882 (self.data[self.CODE], self.data['snr'])
897 (self.data[self.CODE], self.data['snr'])
883 )
898 )
884 else:
899 else:
885 self.z = self.data[self.CODE]
900 self.z = self.data[self.CODE]
886
901
887 self.z = numpy.ma.masked_invalid(self.z)
902 self.z = numpy.ma.masked_invalid(self.z)
888
903
889 for n, ax in enumerate(self.axes):
904 for n, ax in enumerate(self.axes):
890
905
891 x, y, z = self.fill_gaps(*self.decimate())
906 x, y, z = self.fill_gaps(*self.decimate())
892 self.zmax = self.zmax if self.zmax is not None else numpy.max(self.z[n])
907 self.zmax = self.zmax if self.zmax is not None else numpy.max(self.z[n])
893 self.zmin = self.zmin if self.zmin is not None else numpy.min(self.z[n])
908 self.zmin = self.zmin if self.zmin is not None else numpy.min(self.z[n])
894
909
895 if ax.firsttime:
910 if ax.firsttime:
896 if self.zlimits is not None:
911 if self.zlimits is not None:
897 self.zmin, self.zmax = self.zlimits[n]
912 self.zmin, self.zmax = self.zlimits[n]
898
913
899 ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n],
914 ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n],
900 vmin=self.zmin,
915 vmin=self.zmin,
901 vmax=self.zmax,
916 vmax=self.zmax,
902 cmap=self.cmaps[n]
917 cmap=self.cmaps[n]
903 )
918 )
904 else:
919 else:
905 if self.zlimits is not None:
920 if self.zlimits is not None:
906 self.zmin, self.zmax = self.zlimits[n]
921 self.zmin, self.zmax = self.zlimits[n]
907 ax.collections.remove(ax.collections[0])
922 ax.collections.remove(ax.collections[0])
908 ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n],
923 ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n],
909 vmin=self.zmin,
924 vmin=self.zmin,
910 vmax=self.zmax,
925 vmax=self.zmax,
911 cmap=self.cmaps[n]
926 cmap=self.cmaps[n]
912 )
927 )
913
928
914 self.saveTime = self.min_time
929 self.saveTime = self.min_time
915
930
916 class PlotOutputData(PlotParamData):
931 class PlotOutputData(PlotParamData):
917 '''
932 '''
918 Plot data_output object
933 Plot data_output object
919 '''
934 '''
920
935
921 CODE = 'output'
936 CODE = 'output'
922 colormap = 'seismic'
937 colormap = 'seismic'
@@ -1,328 +1,329
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime
10 from figure import Figure, isRealtime
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13 class SpectraHeisScope(Figure):
13 class SpectraHeisScope(Figure):
14
14
15
15
16 isConfig = None
16 isConfig = None
17 __nsubplots = None
17 __nsubplots = None
18
18
19 WIDTHPROF = None
19 WIDTHPROF = None
20 HEIGHTPROF = None
20 HEIGHTPROF = None
21 PREFIX = 'spc'
21 PREFIX = 'spc'
22
22
23 def __init__(self):
23 def __init__(self, **kwargs):
24
24
25 Figure.__init__(self, **kwargs)
25 self.isConfig = False
26 self.isConfig = False
26 self.__nsubplots = 1
27 self.__nsubplots = 1
27
28
28 self.WIDTH = 230
29 self.WIDTH = 230
29 self.HEIGHT = 250
30 self.HEIGHT = 250
30 self.WIDTHPROF = 120
31 self.WIDTHPROF = 120
31 self.HEIGHTPROF = 0
32 self.HEIGHTPROF = 0
32 self.counter_imagwr = 0
33 self.counter_imagwr = 0
33
34
34 self.PLOT_CODE = SPEC_CODE
35 self.PLOT_CODE = SPEC_CODE
35
36
36 def getSubplots(self):
37 def getSubplots(self):
37
38
38 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 nrow = int(self.nplots*1./ncol + 0.9)
40 nrow = int(self.nplots*1./ncol + 0.9)
40
41
41 return nrow, ncol
42 return nrow, ncol
42
43
43 def setup(self, id, nplots, wintitle, show):
44 def setup(self, id, nplots, wintitle, show):
44
45
45 showprofile = False
46 showprofile = False
46 self.__showprofile = showprofile
47 self.__showprofile = showprofile
47 self.nplots = nplots
48 self.nplots = nplots
48
49
49 ncolspan = 1
50 ncolspan = 1
50 colspan = 1
51 colspan = 1
51 if showprofile:
52 if showprofile:
52 ncolspan = 3
53 ncolspan = 3
53 colspan = 2
54 colspan = 2
54 self.__nsubplots = 2
55 self.__nsubplots = 2
55
56
56 self.createFigure(id = id,
57 self.createFigure(id = id,
57 wintitle = wintitle,
58 wintitle = wintitle,
58 widthplot = self.WIDTH + self.WIDTHPROF,
59 widthplot = self.WIDTH + self.WIDTHPROF,
59 heightplot = self.HEIGHT + self.HEIGHTPROF,
60 heightplot = self.HEIGHT + self.HEIGHTPROF,
60 show = show)
61 show = show)
61
62
62 nrow, ncol = self.getSubplots()
63 nrow, ncol = self.getSubplots()
63
64
64 counter = 0
65 counter = 0
65 for y in range(nrow):
66 for y in range(nrow):
66 for x in range(ncol):
67 for x in range(ncol):
67
68
68 if counter >= self.nplots:
69 if counter >= self.nplots:
69 break
70 break
70
71
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
72
73
73 if showprofile:
74 if showprofile:
74 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
75 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
75
76
76 counter += 1
77 counter += 1
77
78
78
79
79 def run(self, dataOut, id, wintitle="", channelList=None,
80 def run(self, dataOut, id, wintitle="", channelList=None,
80 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
81 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
81 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
82 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
82 server=None, folder=None, username=None, password=None,
83 server=None, folder=None, username=None, password=None,
83 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
84
85
85 """
86 """
86
87
87 Input:
88 Input:
88 dataOut :
89 dataOut :
89 id :
90 id :
90 wintitle :
91 wintitle :
91 channelList :
92 channelList :
92 xmin : None,
93 xmin : None,
93 xmax : None,
94 xmax : None,
94 ymin : None,
95 ymin : None,
95 ymax : None,
96 ymax : None,
96 """
97 """
97
98
98 if dataOut.realtime:
99 if dataOut.realtime:
99 if not(isRealtime(utcdatatime = dataOut.utctime)):
100 if not(isRealtime(utcdatatime = dataOut.utctime)):
100 print 'Skipping this plot function'
101 print 'Skipping this plot function'
101 return
102 return
102
103
103 if channelList == None:
104 if channelList == None:
104 channelIndexList = dataOut.channelIndexList
105 channelIndexList = dataOut.channelIndexList
105 else:
106 else:
106 channelIndexList = []
107 channelIndexList = []
107 for channel in channelList:
108 for channel in channelList:
108 if channel not in dataOut.channelList:
109 if channel not in dataOut.channelList:
109 raise ValueError, "Channel %d is not in dataOut.channelList"
110 raise ValueError, "Channel %d is not in dataOut.channelList"
110 channelIndexList.append(dataOut.channelList.index(channel))
111 channelIndexList.append(dataOut.channelList.index(channel))
111
112
112 # x = dataOut.heightList
113 # x = dataOut.heightList
113 c = 3E8
114 c = 3E8
114 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
115 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
115 #deberia cambiar para el caso de 1Mhz y 100KHz
116 #deberia cambiar para el caso de 1Mhz y 100KHz
116 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
117 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
117 #para 1Mhz descomentar la siguiente linea
118 #para 1Mhz descomentar la siguiente linea
118 #x= x/(10000.0)
119 #x= x/(10000.0)
119 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
120 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
120 # y = y.real
121 # y = y.real
121 factor = dataOut.normFactor
122 factor = dataOut.normFactor
122 data = dataOut.data_spc / factor
123 data = dataOut.data_spc / factor
123 datadB = 10.*numpy.log10(data)
124 datadB = 10.*numpy.log10(data)
124 y = datadB
125 y = datadB
125
126
126 #thisDatetime = dataOut.datatime
127 #thisDatetime = dataOut.datatime
127 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
128 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
128 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
129 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
129 xlabel = ""
130 xlabel = ""
130 #para 1Mhz descomentar la siguiente linea
131 #para 1Mhz descomentar la siguiente linea
131 #xlabel = "Frequency x 10000"
132 #xlabel = "Frequency x 10000"
132 ylabel = "Intensity (dB)"
133 ylabel = "Intensity (dB)"
133
134
134 if not self.isConfig:
135 if not self.isConfig:
135 nplots = len(channelIndexList)
136 nplots = len(channelIndexList)
136
137
137 self.setup(id=id,
138 self.setup(id=id,
138 nplots=nplots,
139 nplots=nplots,
139 wintitle=wintitle,
140 wintitle=wintitle,
140 show=show)
141 show=show)
141
142
142 if xmin == None: xmin = numpy.nanmin(x)
143 if xmin == None: xmin = numpy.nanmin(x)
143 if xmax == None: xmax = numpy.nanmax(x)
144 if xmax == None: xmax = numpy.nanmax(x)
144 if ymin == None: ymin = numpy.nanmin(y)
145 if ymin == None: ymin = numpy.nanmin(y)
145 if ymax == None: ymax = numpy.nanmax(y)
146 if ymax == None: ymax = numpy.nanmax(y)
146
147
147 self.FTP_WEI = ftp_wei
148 self.FTP_WEI = ftp_wei
148 self.EXP_CODE = exp_code
149 self.EXP_CODE = exp_code
149 self.SUB_EXP_CODE = sub_exp_code
150 self.SUB_EXP_CODE = sub_exp_code
150 self.PLOT_POS = plot_pos
151 self.PLOT_POS = plot_pos
151
152
152 self.isConfig = True
153 self.isConfig = True
153
154
154 self.setWinTitle(title)
155 self.setWinTitle(title)
155
156
156 for i in range(len(self.axesList)):
157 for i in range(len(self.axesList)):
157 ychannel = y[i,:]
158 ychannel = y[i,:]
158 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
159 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
159 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime)
160 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime)
160 axes = self.axesList[i]
161 axes = self.axesList[i]
161 axes.pline(x, ychannel,
162 axes.pline(x, ychannel,
162 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
163 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
163 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
164 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
164
165
165
166
166 self.draw()
167 self.draw()
167
168
168 self.save(figpath=figpath,
169 self.save(figpath=figpath,
169 figfile=figfile,
170 figfile=figfile,
170 save=save,
171 save=save,
171 ftp=ftp,
172 ftp=ftp,
172 wr_period=wr_period,
173 wr_period=wr_period,
173 thisDatetime=thisDatetime)
174 thisDatetime=thisDatetime)
174
175
175 class RTIfromSpectraHeis(Figure):
176 class RTIfromSpectraHeis(Figure):
176
177
177 isConfig = None
178 isConfig = None
178 __nsubplots = None
179 __nsubplots = None
179
180
180 PREFIX = 'rtinoise'
181 PREFIX = 'rtinoise'
181
182
182 def __init__(self):
183 def __init__(self, **kwargs):
183
184 Figure.__init__(self, **kwargs)
184 self.timerange = 24*60*60
185 self.timerange = 24*60*60
185 self.isConfig = False
186 self.isConfig = False
186 self.__nsubplots = 1
187 self.__nsubplots = 1
187
188
188 self.WIDTH = 820
189 self.WIDTH = 820
189 self.HEIGHT = 200
190 self.HEIGHT = 200
190 self.WIDTHPROF = 120
191 self.WIDTHPROF = 120
191 self.HEIGHTPROF = 0
192 self.HEIGHTPROF = 0
192 self.counter_imagwr = 0
193 self.counter_imagwr = 0
193 self.xdata = None
194 self.xdata = None
194 self.ydata = None
195 self.ydata = None
195 self.figfile = None
196 self.figfile = None
196
197
197 self.PLOT_CODE = RTI_CODE
198 self.PLOT_CODE = RTI_CODE
198
199
199 def getSubplots(self):
200 def getSubplots(self):
200
201
201 ncol = 1
202 ncol = 1
202 nrow = 1
203 nrow = 1
203
204
204 return nrow, ncol
205 return nrow, ncol
205
206
206 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
207 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
207
208
208 self.__showprofile = showprofile
209 self.__showprofile = showprofile
209 self.nplots = nplots
210 self.nplots = nplots
210
211
211 ncolspan = 7
212 ncolspan = 7
212 colspan = 6
213 colspan = 6
213 self.__nsubplots = 2
214 self.__nsubplots = 2
214
215
215 self.createFigure(id = id,
216 self.createFigure(id = id,
216 wintitle = wintitle,
217 wintitle = wintitle,
217 widthplot = self.WIDTH+self.WIDTHPROF,
218 widthplot = self.WIDTH+self.WIDTHPROF,
218 heightplot = self.HEIGHT+self.HEIGHTPROF,
219 heightplot = self.HEIGHT+self.HEIGHTPROF,
219 show = show)
220 show = show)
220
221
221 nrow, ncol = self.getSubplots()
222 nrow, ncol = self.getSubplots()
222
223
223 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
224 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
224
225
225
226
226 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
227 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
227 xmin=None, xmax=None, ymin=None, ymax=None,
228 xmin=None, xmax=None, ymin=None, ymax=None,
228 timerange=None,
229 timerange=None,
229 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
230 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
230 server=None, folder=None, username=None, password=None,
231 server=None, folder=None, username=None, password=None,
231 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
232 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
232
233
233 if channelList == None:
234 if channelList == None:
234 channelIndexList = dataOut.channelIndexList
235 channelIndexList = dataOut.channelIndexList
235 channelList = dataOut.channelList
236 channelList = dataOut.channelList
236 else:
237 else:
237 channelIndexList = []
238 channelIndexList = []
238 for channel in channelList:
239 for channel in channelList:
239 if channel not in dataOut.channelList:
240 if channel not in dataOut.channelList:
240 raise ValueError, "Channel %d is not in dataOut.channelList"
241 raise ValueError, "Channel %d is not in dataOut.channelList"
241 channelIndexList.append(dataOut.channelList.index(channel))
242 channelIndexList.append(dataOut.channelList.index(channel))
242
243
243 if timerange != None:
244 if timerange != None:
244 self.timerange = timerange
245 self.timerange = timerange
245
246
246 x = dataOut.getTimeRange()
247 x = dataOut.getTimeRange()
247 y = dataOut.getHeiRange()
248 y = dataOut.getHeiRange()
248
249
249 factor = dataOut.normFactor
250 factor = dataOut.normFactor
250 data = dataOut.data_spc / factor
251 data = dataOut.data_spc / factor
251 data = numpy.average(data,axis=1)
252 data = numpy.average(data,axis=1)
252 datadB = 10*numpy.log10(data)
253 datadB = 10*numpy.log10(data)
253
254
254 # factor = dataOut.normFactor
255 # factor = dataOut.normFactor
255 # noise = dataOut.getNoise()/factor
256 # noise = dataOut.getNoise()/factor
256 # noisedB = 10*numpy.log10(noise)
257 # noisedB = 10*numpy.log10(noise)
257
258
258 #thisDatetime = dataOut.datatime
259 #thisDatetime = dataOut.datatime
259 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
260 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
260 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
261 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
261 xlabel = "Local Time"
262 xlabel = "Local Time"
262 ylabel = "Intensity (dB)"
263 ylabel = "Intensity (dB)"
263
264
264 if not self.isConfig:
265 if not self.isConfig:
265
266
266 nplots = 1
267 nplots = 1
267
268
268 self.setup(id=id,
269 self.setup(id=id,
269 nplots=nplots,
270 nplots=nplots,
270 wintitle=wintitle,
271 wintitle=wintitle,
271 showprofile=showprofile,
272 showprofile=showprofile,
272 show=show)
273 show=show)
273
274
274 self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax)
275 self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax)
275
276
276 if ymin == None: ymin = numpy.nanmin(datadB)
277 if ymin == None: ymin = numpy.nanmin(datadB)
277 if ymax == None: ymax = numpy.nanmax(datadB)
278 if ymax == None: ymax = numpy.nanmax(datadB)
278
279
279 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
280 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
280 self.isConfig = True
281 self.isConfig = True
281 self.figfile = figfile
282 self.figfile = figfile
282 self.xdata = numpy.array([])
283 self.xdata = numpy.array([])
283 self.ydata = numpy.array([])
284 self.ydata = numpy.array([])
284
285
285 self.FTP_WEI = ftp_wei
286 self.FTP_WEI = ftp_wei
286 self.EXP_CODE = exp_code
287 self.EXP_CODE = exp_code
287 self.SUB_EXP_CODE = sub_exp_code
288 self.SUB_EXP_CODE = sub_exp_code
288 self.PLOT_POS = plot_pos
289 self.PLOT_POS = plot_pos
289
290
290 self.setWinTitle(title)
291 self.setWinTitle(title)
291
292
292
293
293 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
294 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
294 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
295 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
295
296
296 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
297 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
297 axes = self.axesList[0]
298 axes = self.axesList[0]
298
299
299 self.xdata = numpy.hstack((self.xdata, x[0:1]))
300 self.xdata = numpy.hstack((self.xdata, x[0:1]))
300
301
301 if len(self.ydata)==0:
302 if len(self.ydata)==0:
302 self.ydata = datadB[channelIndexList].reshape(-1,1)
303 self.ydata = datadB[channelIndexList].reshape(-1,1)
303 else:
304 else:
304 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
305 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
305
306
306
307
307 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
308 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
308 xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax,
309 xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax,
309 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
310 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
310 XAxisAsTime=True
311 XAxisAsTime=True
311 )
312 )
312
313
313 self.draw()
314 self.draw()
314
315
315 update_figfile = False
316 update_figfile = False
316
317
317 if dataOut.ltctime >= self.tmax:
318 if dataOut.ltctime >= self.tmax:
318 self.counter_imagwr = wr_period
319 self.counter_imagwr = wr_period
319 self.isConfig = False
320 self.isConfig = False
320 update_figfile = True
321 update_figfile = True
321
322
322 self.save(figpath=figpath,
323 self.save(figpath=figpath,
323 figfile=figfile,
324 figfile=figfile,
324 save=save,
325 save=save,
325 ftp=ftp,
326 ftp=ftp,
326 wr_period=wr_period,
327 wr_period=wr_period,
327 thisDatetime=thisDatetime,
328 thisDatetime=thisDatetime,
328 update_figfile=update_figfile)
329 update_figfile=update_figfile)
@@ -1,1542 +1,1542
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure, isRealtime, isTimeInHourRange
10 from figure import Figure, isRealtime, isTimeInHourRange
11 from plotting_codes import *
11 from plotting_codes import *
12
12
13
13
14 class SpectraPlot(Figure):
14 class SpectraPlot(Figure):
15
15
16 isConfig = None
16 isConfig = None
17 __nsubplots = None
17 __nsubplots = None
18
18
19 WIDTHPROF = None
19 WIDTHPROF = None
20 HEIGHTPROF = None
20 HEIGHTPROF = None
21 PREFIX = 'spc'
21 PREFIX = 'spc'
22
22
23 def __init__(self, **kwargs):
23 def __init__(self, **kwargs):
24 Figure.__init__(self, **kwargs)
24 Figure.__init__(self, **kwargs)
25 self.isConfig = False
25 self.isConfig = False
26 self.__nsubplots = 1
26 self.__nsubplots = 1
27
27
28 self.WIDTH = 250
28 self.WIDTH = 300
29 self.HEIGHT = 250
29 self.HEIGHT = 300
30 self.WIDTHPROF = 120
30 self.WIDTHPROF = 120
31 self.HEIGHTPROF = 0
31 self.HEIGHTPROF = 0
32 self.counter_imagwr = 0
32 self.counter_imagwr = 0
33
33
34 self.PLOT_CODE = SPEC_CODE
34 self.PLOT_CODE = SPEC_CODE
35
35
36 self.FTP_WEI = None
36 self.FTP_WEI = None
37 self.EXP_CODE = None
37 self.EXP_CODE = None
38 self.SUB_EXP_CODE = None
38 self.SUB_EXP_CODE = None
39 self.PLOT_POS = None
39 self.PLOT_POS = None
40
40
41 self.__xfilter_ena = False
41 self.__xfilter_ena = False
42 self.__yfilter_ena = False
42 self.__yfilter_ena = False
43
43
44 def getSubplots(self):
44 def getSubplots(self):
45
45
46 ncol = int(numpy.sqrt(self.nplots)+0.9)
46 ncol = int(numpy.sqrt(self.nplots)+0.9)
47 nrow = int(self.nplots*1./ncol + 0.9)
47 nrow = int(self.nplots*1./ncol + 0.9)
48
48
49 return nrow, ncol
49 return nrow, ncol
50
50
51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
51 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
52
52
53 self.__showprofile = showprofile
53 self.__showprofile = showprofile
54 self.nplots = nplots
54 self.nplots = nplots
55
55
56 ncolspan = 1
56 ncolspan = 1
57 colspan = 1
57 colspan = 1
58 if showprofile:
58 if showprofile:
59 ncolspan = 3
59 ncolspan = 3
60 colspan = 2
60 colspan = 2
61 self.__nsubplots = 2
61 self.__nsubplots = 2
62
62
63 self.createFigure(id = id,
63 self.createFigure(id = id,
64 wintitle = wintitle,
64 wintitle = wintitle,
65 widthplot = self.WIDTH + self.WIDTHPROF,
65 widthplot = self.WIDTH + self.WIDTHPROF,
66 heightplot = self.HEIGHT + self.HEIGHTPROF,
66 heightplot = self.HEIGHT + self.HEIGHTPROF,
67 show=show)
67 show=show)
68
68
69 nrow, ncol = self.getSubplots()
69 nrow, ncol = self.getSubplots()
70
70
71 counter = 0
71 counter = 0
72 for y in range(nrow):
72 for y in range(nrow):
73 for x in range(ncol):
73 for x in range(ncol):
74
74
75 if counter >= self.nplots:
75 if counter >= self.nplots:
76 break
76 break
77
77
78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
78 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
79
79
80 if showprofile:
80 if showprofile:
81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
81 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
82
82
83 counter += 1
83 counter += 1
84
84
85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
85 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
86 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
87 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
88 server=None, folder=None, username=None, password=None,
88 server=None, folder=None, username=None, password=None,
89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
89 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False,
90 xaxis="frequency", colormap='jet', normFactor=None):
90 xaxis="frequency", colormap='jet', normFactor=None):
91
91
92 """
92 """
93
93
94 Input:
94 Input:
95 dataOut :
95 dataOut :
96 id :
96 id :
97 wintitle :
97 wintitle :
98 channelList :
98 channelList :
99 showProfile :
99 showProfile :
100 xmin : None,
100 xmin : None,
101 xmax : None,
101 xmax : None,
102 ymin : None,
102 ymin : None,
103 ymax : None,
103 ymax : None,
104 zmin : None,
104 zmin : None,
105 zmax : None
105 zmax : None
106 """
106 """
107 if realtime:
107 if realtime:
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
108 if not(isRealtime(utcdatatime = dataOut.utctime)):
109 print 'Skipping this plot function'
109 print 'Skipping this plot function'
110 return
110 return
111
111
112 if channelList == None:
112 if channelList == None:
113 channelIndexList = dataOut.channelIndexList
113 channelIndexList = dataOut.channelIndexList
114 else:
114 else:
115 channelIndexList = []
115 channelIndexList = []
116 for channel in channelList:
116 for channel in channelList:
117 if channel not in dataOut.channelList:
117 if channel not in dataOut.channelList:
118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
118 raise ValueError, "Channel %d is not in dataOut.channelList" %channel
119 channelIndexList.append(dataOut.channelList.index(channel))
119 channelIndexList.append(dataOut.channelList.index(channel))
120
120
121 if normFactor is None:
121 if normFactor is None:
122 factor = dataOut.normFactor
122 factor = dataOut.normFactor
123 else:
123 else:
124 factor = normFactor
124 factor = normFactor
125 if xaxis == "frequency":
125 if xaxis == "frequency":
126 x = dataOut.getFreqRange(1)/1000.
126 x = dataOut.getFreqRange(1)/1000.
127 xlabel = "Frequency (kHz)"
127 xlabel = "Frequency (kHz)"
128
128
129 elif xaxis == "time":
129 elif xaxis == "time":
130 x = dataOut.getAcfRange(1)
130 x = dataOut.getAcfRange(1)
131 xlabel = "Time (ms)"
131 xlabel = "Time (ms)"
132
132
133 else:
133 else:
134 x = dataOut.getVelRange(1)
134 x = dataOut.getVelRange(1)
135 xlabel = "Velocity (m/s)"
135 xlabel = "Velocity (m/s)"
136
136
137 ylabel = "Range (Km)"
137 ylabel = "Range (Km)"
138
138
139 y = dataOut.getHeiRange()
139 y = dataOut.getHeiRange()
140
140
141 z = dataOut.data_spc/factor
141 z = dataOut.data_spc/factor
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
142 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
143 zdB = 10*numpy.log10(z)
143 zdB = 10*numpy.log10(z)
144
144
145 avg = numpy.average(z, axis=1)
145 avg = numpy.average(z, axis=1)
146 avgdB = 10*numpy.log10(avg)
146 avgdB = 10*numpy.log10(avg)
147
147
148 noise = dataOut.getNoise()/factor
148 noise = dataOut.getNoise()/factor
149 noisedB = 10*numpy.log10(noise)
149 noisedB = 10*numpy.log10(noise)
150
150
151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
151 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
152 title = wintitle + " Spectra"
152 title = wintitle + " Spectra"
153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
153 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
154 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
154 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
155
155
156 if not self.isConfig:
156 if not self.isConfig:
157
157
158 nplots = len(channelIndexList)
158 nplots = len(channelIndexList)
159
159
160 self.setup(id=id,
160 self.setup(id=id,
161 nplots=nplots,
161 nplots=nplots,
162 wintitle=wintitle,
162 wintitle=wintitle,
163 showprofile=showprofile,
163 showprofile=showprofile,
164 show=show)
164 show=show)
165
165
166 if xmin == None: xmin = numpy.nanmin(x)
166 if xmin == None: xmin = numpy.nanmin(x)
167 if xmax == None: xmax = numpy.nanmax(x)
167 if xmax == None: xmax = numpy.nanmax(x)
168 if ymin == None: ymin = numpy.nanmin(y)
168 if ymin == None: ymin = numpy.nanmin(y)
169 if ymax == None: ymax = numpy.nanmax(y)
169 if ymax == None: ymax = numpy.nanmax(y)
170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
170 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
171 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
172
172
173 self.FTP_WEI = ftp_wei
173 self.FTP_WEI = ftp_wei
174 self.EXP_CODE = exp_code
174 self.EXP_CODE = exp_code
175 self.SUB_EXP_CODE = sub_exp_code
175 self.SUB_EXP_CODE = sub_exp_code
176 self.PLOT_POS = plot_pos
176 self.PLOT_POS = plot_pos
177
177
178 self.isConfig = True
178 self.isConfig = True
179
179
180 self.setWinTitle(title)
180 self.setWinTitle(title)
181
181
182 for i in range(self.nplots):
182 for i in range(self.nplots):
183 index = channelIndexList[i]
183 index = channelIndexList[i]
184 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
184 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
185 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
185 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime)
186 if len(dataOut.beam.codeList) != 0:
186 if len(dataOut.beam.codeList) != 0:
187 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
187 title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime)
188
188
189 axes = self.axesList[i*self.__nsubplots]
189 axes = self.axesList[i*self.__nsubplots]
190 axes.pcolor(x, y, zdB[index,:,:],
190 axes.pcolor(x, y, zdB[index,:,:],
191 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
191 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
192 xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap,
193 ticksize=9, cblabel='')
193 ticksize=9, cblabel='')
194
194
195 if self.__showprofile:
195 if self.__showprofile:
196 axes = self.axesList[i*self.__nsubplots +1]
196 axes = self.axesList[i*self.__nsubplots +1]
197 axes.pline(avgdB[index,:], y,
197 axes.pline(avgdB[index,:], y,
198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
198 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
199 xlabel='dB', ylabel='', title='',
199 xlabel='dB', ylabel='', title='',
200 ytick_visible=False,
200 ytick_visible=False,
201 grid='x')
201 grid='x')
202
202
203 noiseline = numpy.repeat(noisedB[index], len(y))
203 noiseline = numpy.repeat(noisedB[index], len(y))
204 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
204 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
205
205
206 self.draw()
206 self.draw()
207
207
208 if figfile == None:
208 if figfile == None:
209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
209 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
210 name = str_datetime
210 name = str_datetime
211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
211 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
212 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
212 name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith)
213 figfile = self.getFilename(name)
213 figfile = self.getFilename(name)
214
214
215 self.save(figpath=figpath,
215 self.save(figpath=figpath,
216 figfile=figfile,
216 figfile=figfile,
217 save=save,
217 save=save,
218 ftp=ftp,
218 ftp=ftp,
219 wr_period=wr_period,
219 wr_period=wr_period,
220 thisDatetime=thisDatetime)
220 thisDatetime=thisDatetime)
221
221
222 class CrossSpectraPlot(Figure):
222 class CrossSpectraPlot(Figure):
223
223
224 isConfig = None
224 isConfig = None
225 __nsubplots = None
225 __nsubplots = None
226
226
227 WIDTH = None
227 WIDTH = None
228 HEIGHT = None
228 HEIGHT = None
229 WIDTHPROF = None
229 WIDTHPROF = None
230 HEIGHTPROF = None
230 HEIGHTPROF = None
231 PREFIX = 'cspc'
231 PREFIX = 'cspc'
232
232
233 def __init__(self, **kwargs):
233 def __init__(self, **kwargs):
234 Figure.__init__(self, **kwargs)
234 Figure.__init__(self, **kwargs)
235 self.isConfig = False
235 self.isConfig = False
236 self.__nsubplots = 4
236 self.__nsubplots = 4
237 self.counter_imagwr = 0
237 self.counter_imagwr = 0
238 self.WIDTH = 250
238 self.WIDTH = 250
239 self.HEIGHT = 250
239 self.HEIGHT = 250
240 self.WIDTHPROF = 0
240 self.WIDTHPROF = 0
241 self.HEIGHTPROF = 0
241 self.HEIGHTPROF = 0
242
242
243 self.PLOT_CODE = CROSS_CODE
243 self.PLOT_CODE = CROSS_CODE
244 self.FTP_WEI = None
244 self.FTP_WEI = None
245 self.EXP_CODE = None
245 self.EXP_CODE = None
246 self.SUB_EXP_CODE = None
246 self.SUB_EXP_CODE = None
247 self.PLOT_POS = None
247 self.PLOT_POS = None
248
248
249 def getSubplots(self):
249 def getSubplots(self):
250
250
251 ncol = 4
251 ncol = 4
252 nrow = self.nplots
252 nrow = self.nplots
253
253
254 return nrow, ncol
254 return nrow, ncol
255
255
256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
256 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
257
257
258 self.__showprofile = showprofile
258 self.__showprofile = showprofile
259 self.nplots = nplots
259 self.nplots = nplots
260
260
261 ncolspan = 1
261 ncolspan = 1
262 colspan = 1
262 colspan = 1
263
263
264 self.createFigure(id = id,
264 self.createFigure(id = id,
265 wintitle = wintitle,
265 wintitle = wintitle,
266 widthplot = self.WIDTH + self.WIDTHPROF,
266 widthplot = self.WIDTH + self.WIDTHPROF,
267 heightplot = self.HEIGHT + self.HEIGHTPROF,
267 heightplot = self.HEIGHT + self.HEIGHTPROF,
268 show=True)
268 show=True)
269
269
270 nrow, ncol = self.getSubplots()
270 nrow, ncol = self.getSubplots()
271
271
272 counter = 0
272 counter = 0
273 for y in range(nrow):
273 for y in range(nrow):
274 for x in range(ncol):
274 for x in range(ncol):
275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
275 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
276
276
277 counter += 1
277 counter += 1
278
278
279 def run(self, dataOut, id, wintitle="", pairsList=None,
279 def run(self, dataOut, id, wintitle="", pairsList=None,
280 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
280 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
281 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
281 coh_min=None, coh_max=None, phase_min=None, phase_max=None,
282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
282 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
283 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
283 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
284 server=None, folder=None, username=None, password=None,
284 server=None, folder=None, username=None, password=None,
285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
285 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None,
286 xaxis='frequency'):
286 xaxis='frequency'):
287
287
288 """
288 """
289
289
290 Input:
290 Input:
291 dataOut :
291 dataOut :
292 id :
292 id :
293 wintitle :
293 wintitle :
294 channelList :
294 channelList :
295 showProfile :
295 showProfile :
296 xmin : None,
296 xmin : None,
297 xmax : None,
297 xmax : None,
298 ymin : None,
298 ymin : None,
299 ymax : None,
299 ymax : None,
300 zmin : None,
300 zmin : None,
301 zmax : None
301 zmax : None
302 """
302 """
303
303
304 if pairsList == None:
304 if pairsList == None:
305 pairsIndexList = dataOut.pairsIndexList
305 pairsIndexList = dataOut.pairsIndexList
306 else:
306 else:
307 pairsIndexList = []
307 pairsIndexList = []
308 for pair in pairsList:
308 for pair in pairsList:
309 if pair not in dataOut.pairsList:
309 if pair not in dataOut.pairsList:
310 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
310 raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair)
311 pairsIndexList.append(dataOut.pairsList.index(pair))
311 pairsIndexList.append(dataOut.pairsList.index(pair))
312
312
313 if not pairsIndexList:
313 if not pairsIndexList:
314 return
314 return
315
315
316 if len(pairsIndexList) > 4:
316 if len(pairsIndexList) > 4:
317 pairsIndexList = pairsIndexList[0:4]
317 pairsIndexList = pairsIndexList[0:4]
318
318
319 if normFactor is None:
319 if normFactor is None:
320 factor = dataOut.normFactor
320 factor = dataOut.normFactor
321 else:
321 else:
322 factor = normFactor
322 factor = normFactor
323 x = dataOut.getVelRange(1)
323 x = dataOut.getVelRange(1)
324 y = dataOut.getHeiRange()
324 y = dataOut.getHeiRange()
325 z = dataOut.data_spc[:,:,:]/factor
325 z = dataOut.data_spc[:,:,:]/factor
326 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
326 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
327
327
328 noise = dataOut.noise/factor
328 noise = dataOut.noise/factor
329
329
330 zdB = 10*numpy.log10(z)
330 zdB = 10*numpy.log10(z)
331 noisedB = 10*numpy.log10(noise)
331 noisedB = 10*numpy.log10(noise)
332
332
333 if coh_min == None:
333 if coh_min == None:
334 coh_min = 0.0
334 coh_min = 0.0
335 if coh_max == None:
335 if coh_max == None:
336 coh_max = 1.0
336 coh_max = 1.0
337
337
338 if phase_min == None:
338 if phase_min == None:
339 phase_min = -180
339 phase_min = -180
340 if phase_max == None:
340 if phase_max == None:
341 phase_max = 180
341 phase_max = 180
342
342
343 #thisDatetime = dataOut.datatime
343 #thisDatetime = dataOut.datatime
344 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
344 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
345 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
345 title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
346 # xlabel = "Velocity (m/s)"
346 # xlabel = "Velocity (m/s)"
347 ylabel = "Range (Km)"
347 ylabel = "Range (Km)"
348
348
349 if xaxis == "frequency":
349 if xaxis == "frequency":
350 x = dataOut.getFreqRange(1)/1000.
350 x = dataOut.getFreqRange(1)/1000.
351 xlabel = "Frequency (kHz)"
351 xlabel = "Frequency (kHz)"
352
352
353 elif xaxis == "time":
353 elif xaxis == "time":
354 x = dataOut.getAcfRange(1)
354 x = dataOut.getAcfRange(1)
355 xlabel = "Time (ms)"
355 xlabel = "Time (ms)"
356
356
357 else:
357 else:
358 x = dataOut.getVelRange(1)
358 x = dataOut.getVelRange(1)
359 xlabel = "Velocity (m/s)"
359 xlabel = "Velocity (m/s)"
360
360
361 if not self.isConfig:
361 if not self.isConfig:
362
362
363 nplots = len(pairsIndexList)
363 nplots = len(pairsIndexList)
364
364
365 self.setup(id=id,
365 self.setup(id=id,
366 nplots=nplots,
366 nplots=nplots,
367 wintitle=wintitle,
367 wintitle=wintitle,
368 showprofile=False,
368 showprofile=False,
369 show=show)
369 show=show)
370
370
371 avg = numpy.abs(numpy.average(z, axis=1))
371 avg = numpy.abs(numpy.average(z, axis=1))
372 avgdB = 10*numpy.log10(avg)
372 avgdB = 10*numpy.log10(avg)
373
373
374 if xmin == None: xmin = numpy.nanmin(x)
374 if xmin == None: xmin = numpy.nanmin(x)
375 if xmax == None: xmax = numpy.nanmax(x)
375 if xmax == None: xmax = numpy.nanmax(x)
376 if ymin == None: ymin = numpy.nanmin(y)
376 if ymin == None: ymin = numpy.nanmin(y)
377 if ymax == None: ymax = numpy.nanmax(y)
377 if ymax == None: ymax = numpy.nanmax(y)
378 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
378 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
379 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
379 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
380
380
381 self.FTP_WEI = ftp_wei
381 self.FTP_WEI = ftp_wei
382 self.EXP_CODE = exp_code
382 self.EXP_CODE = exp_code
383 self.SUB_EXP_CODE = sub_exp_code
383 self.SUB_EXP_CODE = sub_exp_code
384 self.PLOT_POS = plot_pos
384 self.PLOT_POS = plot_pos
385
385
386 self.isConfig = True
386 self.isConfig = True
387
387
388 self.setWinTitle(title)
388 self.setWinTitle(title)
389
389
390 for i in range(self.nplots):
390 for i in range(self.nplots):
391 pair = dataOut.pairsList[pairsIndexList[i]]
391 pair = dataOut.pairsList[pairsIndexList[i]]
392
392
393 chan_index0 = dataOut.channelList.index(pair[0])
393 chan_index0 = dataOut.channelList.index(pair[0])
394 chan_index1 = dataOut.channelList.index(pair[1])
394 chan_index1 = dataOut.channelList.index(pair[1])
395
395
396 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
396 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
397 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
397 title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime)
398 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
398 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor)
399 axes0 = self.axesList[i*self.__nsubplots]
399 axes0 = self.axesList[i*self.__nsubplots]
400 axes0.pcolor(x, y, zdB,
400 axes0.pcolor(x, y, zdB,
401 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
401 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
402 xlabel=xlabel, ylabel=ylabel, title=title,
402 xlabel=xlabel, ylabel=ylabel, title=title,
403 ticksize=9, colormap=power_cmap, cblabel='')
403 ticksize=9, colormap=power_cmap, cblabel='')
404
404
405 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
405 title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime)
406 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
406 zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor)
407 axes0 = self.axesList[i*self.__nsubplots+1]
407 axes0 = self.axesList[i*self.__nsubplots+1]
408 axes0.pcolor(x, y, zdB,
408 axes0.pcolor(x, y, zdB,
409 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
409 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
410 xlabel=xlabel, ylabel=ylabel, title=title,
410 xlabel=xlabel, ylabel=ylabel, title=title,
411 ticksize=9, colormap=power_cmap, cblabel='')
411 ticksize=9, colormap=power_cmap, cblabel='')
412
412
413 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
413 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:])
414 coherence = numpy.abs(coherenceComplex)
414 coherence = numpy.abs(coherenceComplex)
415 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
415 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
416 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
416 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
417
417
418 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
418 title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1])
419 axes0 = self.axesList[i*self.__nsubplots+2]
419 axes0 = self.axesList[i*self.__nsubplots+2]
420 axes0.pcolor(x, y, coherence,
420 axes0.pcolor(x, y, coherence,
421 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
421 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max,
422 xlabel=xlabel, ylabel=ylabel, title=title,
422 xlabel=xlabel, ylabel=ylabel, title=title,
423 ticksize=9, colormap=coherence_cmap, cblabel='')
423 ticksize=9, colormap=coherence_cmap, cblabel='')
424
424
425 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
425 title = "Phase Ch%d * Ch%d" %(pair[0], pair[1])
426 axes0 = self.axesList[i*self.__nsubplots+3]
426 axes0 = self.axesList[i*self.__nsubplots+3]
427 axes0.pcolor(x, y, phase,
427 axes0.pcolor(x, y, phase,
428 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
428 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
429 xlabel=xlabel, ylabel=ylabel, title=title,
429 xlabel=xlabel, ylabel=ylabel, title=title,
430 ticksize=9, colormap=phase_cmap, cblabel='')
430 ticksize=9, colormap=phase_cmap, cblabel='')
431
431
432
432
433
433
434 self.draw()
434 self.draw()
435
435
436 self.save(figpath=figpath,
436 self.save(figpath=figpath,
437 figfile=figfile,
437 figfile=figfile,
438 save=save,
438 save=save,
439 ftp=ftp,
439 ftp=ftp,
440 wr_period=wr_period,
440 wr_period=wr_period,
441 thisDatetime=thisDatetime)
441 thisDatetime=thisDatetime)
442
442
443
443
444 class RTIPlot(Figure):
444 class RTIPlot(Figure):
445
445
446 __isConfig = None
446 __isConfig = None
447 __nsubplots = None
447 __nsubplots = None
448
448
449 WIDTHPROF = None
449 WIDTHPROF = None
450 HEIGHTPROF = None
450 HEIGHTPROF = None
451 PREFIX = 'rti'
451 PREFIX = 'rti'
452
452
453 def __init__(self, **kwargs):
453 def __init__(self, **kwargs):
454
454
455 Figure.__init__(self, **kwargs)
455 Figure.__init__(self, **kwargs)
456 self.timerange = None
456 self.timerange = None
457 self.isConfig = False
457 self.isConfig = False
458 self.__nsubplots = 1
458 self.__nsubplots = 1
459
459
460 self.WIDTH = 800
460 self.WIDTH = 800
461 self.HEIGHT = 180
461 self.HEIGHT = 180
462 self.WIDTHPROF = 120
462 self.WIDTHPROF = 120
463 self.HEIGHTPROF = 0
463 self.HEIGHTPROF = 0
464 self.counter_imagwr = 0
464 self.counter_imagwr = 0
465
465
466 self.PLOT_CODE = RTI_CODE
466 self.PLOT_CODE = RTI_CODE
467
467
468 self.FTP_WEI = None
468 self.FTP_WEI = None
469 self.EXP_CODE = None
469 self.EXP_CODE = None
470 self.SUB_EXP_CODE = None
470 self.SUB_EXP_CODE = None
471 self.PLOT_POS = None
471 self.PLOT_POS = None
472 self.tmin = None
472 self.tmin = None
473 self.tmax = None
473 self.tmax = None
474
474
475 self.xmin = None
475 self.xmin = None
476 self.xmax = None
476 self.xmax = None
477
477
478 self.figfile = None
478 self.figfile = None
479
479
480 def getSubplots(self):
480 def getSubplots(self):
481
481
482 ncol = 1
482 ncol = 1
483 nrow = self.nplots
483 nrow = self.nplots
484
484
485 return nrow, ncol
485 return nrow, ncol
486
486
487 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
487 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
488
488
489 self.__showprofile = showprofile
489 self.__showprofile = showprofile
490 self.nplots = nplots
490 self.nplots = nplots
491
491
492 ncolspan = 1
492 ncolspan = 1
493 colspan = 1
493 colspan = 1
494 if showprofile:
494 if showprofile:
495 ncolspan = 7
495 ncolspan = 7
496 colspan = 6
496 colspan = 6
497 self.__nsubplots = 2
497 self.__nsubplots = 2
498
498
499 self.createFigure(id = id,
499 self.createFigure(id = id,
500 wintitle = wintitle,
500 wintitle = wintitle,
501 widthplot = self.WIDTH + self.WIDTHPROF,
501 widthplot = self.WIDTH + self.WIDTHPROF,
502 heightplot = self.HEIGHT + self.HEIGHTPROF,
502 heightplot = self.HEIGHT + self.HEIGHTPROF,
503 show=show)
503 show=show)
504
504
505 nrow, ncol = self.getSubplots()
505 nrow, ncol = self.getSubplots()
506
506
507 counter = 0
507 counter = 0
508 for y in range(nrow):
508 for y in range(nrow):
509 for x in range(ncol):
509 for x in range(ncol):
510
510
511 if counter >= self.nplots:
511 if counter >= self.nplots:
512 break
512 break
513
513
514 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
514 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
515
515
516 if showprofile:
516 if showprofile:
517 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
517 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
518
518
519 counter += 1
519 counter += 1
520
520
521 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
521 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
522 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
522 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
523 timerange=None, colormap='jet',
523 timerange=None, colormap='jet',
524 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
524 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
525 server=None, folder=None, username=None, password=None,
525 server=None, folder=None, username=None, password=None,
526 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
526 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None):
527
527
528 """
528 """
529
529
530 Input:
530 Input:
531 dataOut :
531 dataOut :
532 id :
532 id :
533 wintitle :
533 wintitle :
534 channelList :
534 channelList :
535 showProfile :
535 showProfile :
536 xmin : None,
536 xmin : None,
537 xmax : None,
537 xmax : None,
538 ymin : None,
538 ymin : None,
539 ymax : None,
539 ymax : None,
540 zmin : None,
540 zmin : None,
541 zmax : None
541 zmax : None
542 """
542 """
543
543
544 #colormap = kwargs.get('colormap', 'jet')
544 #colormap = kwargs.get('colormap', 'jet')
545 if HEIGHT is not None:
545 if HEIGHT is not None:
546 self.HEIGHT = HEIGHT
546 self.HEIGHT = HEIGHT
547
547
548 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
548 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
549 return
549 return
550
550
551 if channelList == None:
551 if channelList == None:
552 channelIndexList = dataOut.channelIndexList
552 channelIndexList = dataOut.channelIndexList
553 else:
553 else:
554 channelIndexList = []
554 channelIndexList = []
555 for channel in channelList:
555 for channel in channelList:
556 if channel not in dataOut.channelList:
556 if channel not in dataOut.channelList:
557 raise ValueError, "Channel %d is not in dataOut.channelList"
557 raise ValueError, "Channel %d is not in dataOut.channelList"
558 channelIndexList.append(dataOut.channelList.index(channel))
558 channelIndexList.append(dataOut.channelList.index(channel))
559
559
560 if normFactor is None:
560 if normFactor is None:
561 factor = dataOut.normFactor
561 factor = dataOut.normFactor
562 else:
562 else:
563 factor = normFactor
563 factor = normFactor
564
564
565 # factor = dataOut.normFactor
565 # factor = dataOut.normFactor
566 x = dataOut.getTimeRange()
566 x = dataOut.getTimeRange()
567 y = dataOut.getHeiRange()
567 y = dataOut.getHeiRange()
568
568
569 z = dataOut.data_spc/factor
569 z = dataOut.data_spc/factor
570 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
570 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
571 avg = numpy.average(z, axis=1)
571 avg = numpy.average(z, axis=1)
572 avgdB = 10.*numpy.log10(avg)
572 avgdB = 10.*numpy.log10(avg)
573 # avgdB = dataOut.getPower()
573 # avgdB = dataOut.getPower()
574
574
575
575
576 thisDatetime = dataOut.datatime
576 thisDatetime = dataOut.datatime
577 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
577 # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
578 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
578 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
579 xlabel = ""
579 xlabel = ""
580 ylabel = "Range (Km)"
580 ylabel = "Range (Km)"
581
581
582 update_figfile = False
582 update_figfile = False
583
583
584 if dataOut.ltctime >= self.xmax:
584 if dataOut.ltctime >= self.xmax:
585 self.counter_imagwr = wr_period
585 self.counter_imagwr = wr_period
586 self.isConfig = False
586 self.isConfig = False
587 update_figfile = True
587 update_figfile = True
588
588
589 if not self.isConfig:
589 if not self.isConfig:
590
590
591 nplots = len(channelIndexList)
591 nplots = len(channelIndexList)
592
592
593 self.setup(id=id,
593 self.setup(id=id,
594 nplots=nplots,
594 nplots=nplots,
595 wintitle=wintitle,
595 wintitle=wintitle,
596 showprofile=showprofile,
596 showprofile=showprofile,
597 show=show)
597 show=show)
598
598
599 if timerange != None:
599 if timerange != None:
600 self.timerange = timerange
600 self.timerange = timerange
601
601
602 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
602 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
603
603
604 noise = dataOut.noise/factor
604 noise = dataOut.noise/factor
605 noisedB = 10*numpy.log10(noise)
605 noisedB = 10*numpy.log10(noise)
606
606
607 if ymin == None: ymin = numpy.nanmin(y)
607 if ymin == None: ymin = numpy.nanmin(y)
608 if ymax == None: ymax = numpy.nanmax(y)
608 if ymax == None: ymax = numpy.nanmax(y)
609 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
609 if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3
610 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
610 if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3
611
611
612 self.FTP_WEI = ftp_wei
612 self.FTP_WEI = ftp_wei
613 self.EXP_CODE = exp_code
613 self.EXP_CODE = exp_code
614 self.SUB_EXP_CODE = sub_exp_code
614 self.SUB_EXP_CODE = sub_exp_code
615 self.PLOT_POS = plot_pos
615 self.PLOT_POS = plot_pos
616
616
617 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
617 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
618 self.isConfig = True
618 self.isConfig = True
619 self.figfile = figfile
619 self.figfile = figfile
620 update_figfile = True
620 update_figfile = True
621
621
622 self.setWinTitle(title)
622 self.setWinTitle(title)
623
623
624 for i in range(self.nplots):
624 for i in range(self.nplots):
625 index = channelIndexList[i]
625 index = channelIndexList[i]
626 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
626 title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
627 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
627 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
628 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
628 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
629 axes = self.axesList[i*self.__nsubplots]
629 axes = self.axesList[i*self.__nsubplots]
630 zdB = avgdB[index].reshape((1,-1))
630 zdB = avgdB[index].reshape((1,-1))
631 axes.pcolorbuffer(x, y, zdB,
631 axes.pcolorbuffer(x, y, zdB,
632 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
632 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
633 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
633 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
634 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
634 ticksize=9, cblabel='', cbsize="1%", colormap=colormap)
635
635
636 if self.__showprofile:
636 if self.__showprofile:
637 axes = self.axesList[i*self.__nsubplots +1]
637 axes = self.axesList[i*self.__nsubplots +1]
638 axes.pline(avgdB[index], y,
638 axes.pline(avgdB[index], y,
639 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
639 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
640 xlabel='dB', ylabel='', title='',
640 xlabel='dB', ylabel='', title='',
641 ytick_visible=False,
641 ytick_visible=False,
642 grid='x')
642 grid='x')
643
643
644 self.draw()
644 self.draw()
645
645
646 self.save(figpath=figpath,
646 self.save(figpath=figpath,
647 figfile=figfile,
647 figfile=figfile,
648 save=save,
648 save=save,
649 ftp=ftp,
649 ftp=ftp,
650 wr_period=wr_period,
650 wr_period=wr_period,
651 thisDatetime=thisDatetime,
651 thisDatetime=thisDatetime,
652 update_figfile=update_figfile)
652 update_figfile=update_figfile)
653
653
654 class CoherenceMap(Figure):
654 class CoherenceMap(Figure):
655 isConfig = None
655 isConfig = None
656 __nsubplots = None
656 __nsubplots = None
657
657
658 WIDTHPROF = None
658 WIDTHPROF = None
659 HEIGHTPROF = None
659 HEIGHTPROF = None
660 PREFIX = 'cmap'
660 PREFIX = 'cmap'
661
661
662 def __init__(self, **kwargs):
662 def __init__(self, **kwargs):
663 Figure.__init__(self, **kwargs)
663 Figure.__init__(self, **kwargs)
664 self.timerange = 2*60*60
664 self.timerange = 2*60*60
665 self.isConfig = False
665 self.isConfig = False
666 self.__nsubplots = 1
666 self.__nsubplots = 1
667
667
668 self.WIDTH = 800
668 self.WIDTH = 800
669 self.HEIGHT = 180
669 self.HEIGHT = 180
670 self.WIDTHPROF = 120
670 self.WIDTHPROF = 120
671 self.HEIGHTPROF = 0
671 self.HEIGHTPROF = 0
672 self.counter_imagwr = 0
672 self.counter_imagwr = 0
673
673
674 self.PLOT_CODE = COH_CODE
674 self.PLOT_CODE = COH_CODE
675
675
676 self.FTP_WEI = None
676 self.FTP_WEI = None
677 self.EXP_CODE = None
677 self.EXP_CODE = None
678 self.SUB_EXP_CODE = None
678 self.SUB_EXP_CODE = None
679 self.PLOT_POS = None
679 self.PLOT_POS = None
680 self.counter_imagwr = 0
680 self.counter_imagwr = 0
681
681
682 self.xmin = None
682 self.xmin = None
683 self.xmax = None
683 self.xmax = None
684
684
685 def getSubplots(self):
685 def getSubplots(self):
686 ncol = 1
686 ncol = 1
687 nrow = self.nplots*2
687 nrow = self.nplots*2
688
688
689 return nrow, ncol
689 return nrow, ncol
690
690
691 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
691 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
692 self.__showprofile = showprofile
692 self.__showprofile = showprofile
693 self.nplots = nplots
693 self.nplots = nplots
694
694
695 ncolspan = 1
695 ncolspan = 1
696 colspan = 1
696 colspan = 1
697 if showprofile:
697 if showprofile:
698 ncolspan = 7
698 ncolspan = 7
699 colspan = 6
699 colspan = 6
700 self.__nsubplots = 2
700 self.__nsubplots = 2
701
701
702 self.createFigure(id = id,
702 self.createFigure(id = id,
703 wintitle = wintitle,
703 wintitle = wintitle,
704 widthplot = self.WIDTH + self.WIDTHPROF,
704 widthplot = self.WIDTH + self.WIDTHPROF,
705 heightplot = self.HEIGHT + self.HEIGHTPROF,
705 heightplot = self.HEIGHT + self.HEIGHTPROF,
706 show=True)
706 show=True)
707
707
708 nrow, ncol = self.getSubplots()
708 nrow, ncol = self.getSubplots()
709
709
710 for y in range(nrow):
710 for y in range(nrow):
711 for x in range(ncol):
711 for x in range(ncol):
712
712
713 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
713 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
714
714
715 if showprofile:
715 if showprofile:
716 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
716 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
717
717
718 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
718 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
719 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
719 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
720 timerange=None, phase_min=None, phase_max=None,
720 timerange=None, phase_min=None, phase_max=None,
721 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
721 save=False, figpath='./', figfile=None, ftp=False, wr_period=1,
722 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
722 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
723 server=None, folder=None, username=None, password=None,
723 server=None, folder=None, username=None, password=None,
724 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
724 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
725
725
726 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
726 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
727 return
727 return
728
728
729 if pairsList == None:
729 if pairsList == None:
730 pairsIndexList = dataOut.pairsIndexList
730 pairsIndexList = dataOut.pairsIndexList
731 else:
731 else:
732 pairsIndexList = []
732 pairsIndexList = []
733 for pair in pairsList:
733 for pair in pairsList:
734 if pair not in dataOut.pairsList:
734 if pair not in dataOut.pairsList:
735 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
735 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
736 pairsIndexList.append(dataOut.pairsList.index(pair))
736 pairsIndexList.append(dataOut.pairsList.index(pair))
737
737
738 if pairsIndexList == []:
738 if pairsIndexList == []:
739 return
739 return
740
740
741 if len(pairsIndexList) > 4:
741 if len(pairsIndexList) > 4:
742 pairsIndexList = pairsIndexList[0:4]
742 pairsIndexList = pairsIndexList[0:4]
743
743
744 if phase_min == None:
744 if phase_min == None:
745 phase_min = -180
745 phase_min = -180
746 if phase_max == None:
746 if phase_max == None:
747 phase_max = 180
747 phase_max = 180
748
748
749 x = dataOut.getTimeRange()
749 x = dataOut.getTimeRange()
750 y = dataOut.getHeiRange()
750 y = dataOut.getHeiRange()
751
751
752 thisDatetime = dataOut.datatime
752 thisDatetime = dataOut.datatime
753
753
754 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
754 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
755 xlabel = ""
755 xlabel = ""
756 ylabel = "Range (Km)"
756 ylabel = "Range (Km)"
757 update_figfile = False
757 update_figfile = False
758
758
759 if not self.isConfig:
759 if not self.isConfig:
760 nplots = len(pairsIndexList)
760 nplots = len(pairsIndexList)
761 self.setup(id=id,
761 self.setup(id=id,
762 nplots=nplots,
762 nplots=nplots,
763 wintitle=wintitle,
763 wintitle=wintitle,
764 showprofile=showprofile,
764 showprofile=showprofile,
765 show=show)
765 show=show)
766
766
767 if timerange != None:
767 if timerange != None:
768 self.timerange = timerange
768 self.timerange = timerange
769
769
770 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
770 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
771
771
772 if ymin == None: ymin = numpy.nanmin(y)
772 if ymin == None: ymin = numpy.nanmin(y)
773 if ymax == None: ymax = numpy.nanmax(y)
773 if ymax == None: ymax = numpy.nanmax(y)
774 if zmin == None: zmin = 0.
774 if zmin == None: zmin = 0.
775 if zmax == None: zmax = 1.
775 if zmax == None: zmax = 1.
776
776
777 self.FTP_WEI = ftp_wei
777 self.FTP_WEI = ftp_wei
778 self.EXP_CODE = exp_code
778 self.EXP_CODE = exp_code
779 self.SUB_EXP_CODE = sub_exp_code
779 self.SUB_EXP_CODE = sub_exp_code
780 self.PLOT_POS = plot_pos
780 self.PLOT_POS = plot_pos
781
781
782 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
782 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
783
783
784 self.isConfig = True
784 self.isConfig = True
785 update_figfile = True
785 update_figfile = True
786
786
787 self.setWinTitle(title)
787 self.setWinTitle(title)
788
788
789 for i in range(self.nplots):
789 for i in range(self.nplots):
790
790
791 pair = dataOut.pairsList[pairsIndexList[i]]
791 pair = dataOut.pairsList[pairsIndexList[i]]
792
792
793 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
793 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
794 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
794 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
795 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
795 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
796
796
797
797
798 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
798 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
799 coherence = numpy.abs(avgcoherenceComplex)
799 coherence = numpy.abs(avgcoherenceComplex)
800
800
801 z = coherence.reshape((1,-1))
801 z = coherence.reshape((1,-1))
802
802
803 counter = 0
803 counter = 0
804
804
805 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
805 title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
806 axes = self.axesList[i*self.__nsubplots*2]
806 axes = self.axesList[i*self.__nsubplots*2]
807 axes.pcolorbuffer(x, y, z,
807 axes.pcolorbuffer(x, y, z,
808 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
808 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
809 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
809 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
810 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
810 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
811
811
812 if self.__showprofile:
812 if self.__showprofile:
813 counter += 1
813 counter += 1
814 axes = self.axesList[i*self.__nsubplots*2 + counter]
814 axes = self.axesList[i*self.__nsubplots*2 + counter]
815 axes.pline(coherence, y,
815 axes.pline(coherence, y,
816 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
816 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
817 xlabel='', ylabel='', title='', ticksize=7,
817 xlabel='', ylabel='', title='', ticksize=7,
818 ytick_visible=False, nxticks=5,
818 ytick_visible=False, nxticks=5,
819 grid='x')
819 grid='x')
820
820
821 counter += 1
821 counter += 1
822
822
823 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
823 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
824
824
825 z = phase.reshape((1,-1))
825 z = phase.reshape((1,-1))
826
826
827 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
827 title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
828 axes = self.axesList[i*self.__nsubplots*2 + counter]
828 axes = self.axesList[i*self.__nsubplots*2 + counter]
829 axes.pcolorbuffer(x, y, z,
829 axes.pcolorbuffer(x, y, z,
830 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
830 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max,
831 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
831 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
832 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
832 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
833
833
834 if self.__showprofile:
834 if self.__showprofile:
835 counter += 1
835 counter += 1
836 axes = self.axesList[i*self.__nsubplots*2 + counter]
836 axes = self.axesList[i*self.__nsubplots*2 + counter]
837 axes.pline(phase, y,
837 axes.pline(phase, y,
838 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
838 xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax,
839 xlabel='', ylabel='', title='', ticksize=7,
839 xlabel='', ylabel='', title='', ticksize=7,
840 ytick_visible=False, nxticks=4,
840 ytick_visible=False, nxticks=4,
841 grid='x')
841 grid='x')
842
842
843 self.draw()
843 self.draw()
844
844
845 if dataOut.ltctime >= self.xmax:
845 if dataOut.ltctime >= self.xmax:
846 self.counter_imagwr = wr_period
846 self.counter_imagwr = wr_period
847 self.isConfig = False
847 self.isConfig = False
848 update_figfile = True
848 update_figfile = True
849
849
850 self.save(figpath=figpath,
850 self.save(figpath=figpath,
851 figfile=figfile,
851 figfile=figfile,
852 save=save,
852 save=save,
853 ftp=ftp,
853 ftp=ftp,
854 wr_period=wr_period,
854 wr_period=wr_period,
855 thisDatetime=thisDatetime,
855 thisDatetime=thisDatetime,
856 update_figfile=update_figfile)
856 update_figfile=update_figfile)
857
857
858 class PowerProfilePlot(Figure):
858 class PowerProfilePlot(Figure):
859
859
860 isConfig = None
860 isConfig = None
861 __nsubplots = None
861 __nsubplots = None
862
862
863 WIDTHPROF = None
863 WIDTHPROF = None
864 HEIGHTPROF = None
864 HEIGHTPROF = None
865 PREFIX = 'spcprofile'
865 PREFIX = 'spcprofile'
866
866
867 def __init__(self, **kwargs):
867 def __init__(self, **kwargs):
868 Figure.__init__(self, **kwargs)
868 Figure.__init__(self, **kwargs)
869 self.isConfig = False
869 self.isConfig = False
870 self.__nsubplots = 1
870 self.__nsubplots = 1
871
871
872 self.PLOT_CODE = POWER_CODE
872 self.PLOT_CODE = POWER_CODE
873
873
874 self.WIDTH = 300
874 self.WIDTH = 300
875 self.HEIGHT = 500
875 self.HEIGHT = 500
876 self.counter_imagwr = 0
876 self.counter_imagwr = 0
877
877
878 def getSubplots(self):
878 def getSubplots(self):
879 ncol = 1
879 ncol = 1
880 nrow = 1
880 nrow = 1
881
881
882 return nrow, ncol
882 return nrow, ncol
883
883
884 def setup(self, id, nplots, wintitle, show):
884 def setup(self, id, nplots, wintitle, show):
885
885
886 self.nplots = nplots
886 self.nplots = nplots
887
887
888 ncolspan = 1
888 ncolspan = 1
889 colspan = 1
889 colspan = 1
890
890
891 self.createFigure(id = id,
891 self.createFigure(id = id,
892 wintitle = wintitle,
892 wintitle = wintitle,
893 widthplot = self.WIDTH,
893 widthplot = self.WIDTH,
894 heightplot = self.HEIGHT,
894 heightplot = self.HEIGHT,
895 show=show)
895 show=show)
896
896
897 nrow, ncol = self.getSubplots()
897 nrow, ncol = self.getSubplots()
898
898
899 counter = 0
899 counter = 0
900 for y in range(nrow):
900 for y in range(nrow):
901 for x in range(ncol):
901 for x in range(ncol):
902 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
902 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
903
903
904 def run(self, dataOut, id, wintitle="", channelList=None,
904 def run(self, dataOut, id, wintitle="", channelList=None,
905 xmin=None, xmax=None, ymin=None, ymax=None,
905 xmin=None, xmax=None, ymin=None, ymax=None,
906 save=False, figpath='./', figfile=None, show=True,
906 save=False, figpath='./', figfile=None, show=True,
907 ftp=False, wr_period=1, server=None,
907 ftp=False, wr_period=1, server=None,
908 folder=None, username=None, password=None):
908 folder=None, username=None, password=None):
909
909
910
910
911 if channelList == None:
911 if channelList == None:
912 channelIndexList = dataOut.channelIndexList
912 channelIndexList = dataOut.channelIndexList
913 channelList = dataOut.channelList
913 channelList = dataOut.channelList
914 else:
914 else:
915 channelIndexList = []
915 channelIndexList = []
916 for channel in channelList:
916 for channel in channelList:
917 if channel not in dataOut.channelList:
917 if channel not in dataOut.channelList:
918 raise ValueError, "Channel %d is not in dataOut.channelList"
918 raise ValueError, "Channel %d is not in dataOut.channelList"
919 channelIndexList.append(dataOut.channelList.index(channel))
919 channelIndexList.append(dataOut.channelList.index(channel))
920
920
921 factor = dataOut.normFactor
921 factor = dataOut.normFactor
922
922
923 y = dataOut.getHeiRange()
923 y = dataOut.getHeiRange()
924
924
925 #for voltage
925 #for voltage
926 if dataOut.type == 'Voltage':
926 if dataOut.type == 'Voltage':
927 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
927 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
928 x = x.real
928 x = x.real
929 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
929 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
930
930
931 #for spectra
931 #for spectra
932 if dataOut.type == 'Spectra':
932 if dataOut.type == 'Spectra':
933 x = dataOut.data_spc[channelIndexList,:,:]/factor
933 x = dataOut.data_spc[channelIndexList,:,:]/factor
934 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
934 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
935 x = numpy.average(x, axis=1)
935 x = numpy.average(x, axis=1)
936
936
937
937
938 xdB = 10*numpy.log10(x)
938 xdB = 10*numpy.log10(x)
939
939
940 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
940 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
941 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
941 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
942 xlabel = "dB"
942 xlabel = "dB"
943 ylabel = "Range (Km)"
943 ylabel = "Range (Km)"
944
944
945 if not self.isConfig:
945 if not self.isConfig:
946
946
947 nplots = 1
947 nplots = 1
948
948
949 self.setup(id=id,
949 self.setup(id=id,
950 nplots=nplots,
950 nplots=nplots,
951 wintitle=wintitle,
951 wintitle=wintitle,
952 show=show)
952 show=show)
953
953
954 if ymin == None: ymin = numpy.nanmin(y)
954 if ymin == None: ymin = numpy.nanmin(y)
955 if ymax == None: ymax = numpy.nanmax(y)
955 if ymax == None: ymax = numpy.nanmax(y)
956 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
956 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
957 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
957 if xmax == None: xmax = numpy.nanmax(xdB)*1.1
958
958
959 self.isConfig = True
959 self.isConfig = True
960
960
961 self.setWinTitle(title)
961 self.setWinTitle(title)
962
962
963 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
963 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
964 axes = self.axesList[0]
964 axes = self.axesList[0]
965
965
966 legendlabels = ["channel %d"%x for x in channelList]
966 legendlabels = ["channel %d"%x for x in channelList]
967 axes.pmultiline(xdB, y,
967 axes.pmultiline(xdB, y,
968 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
968 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
969 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
969 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
970 ytick_visible=True, nxticks=5,
970 ytick_visible=True, nxticks=5,
971 grid='x')
971 grid='x')
972
972
973 self.draw()
973 self.draw()
974
974
975 self.save(figpath=figpath,
975 self.save(figpath=figpath,
976 figfile=figfile,
976 figfile=figfile,
977 save=save,
977 save=save,
978 ftp=ftp,
978 ftp=ftp,
979 wr_period=wr_period,
979 wr_period=wr_period,
980 thisDatetime=thisDatetime)
980 thisDatetime=thisDatetime)
981
981
982 class SpectraCutPlot(Figure):
982 class SpectraCutPlot(Figure):
983
983
984 isConfig = None
984 isConfig = None
985 __nsubplots = None
985 __nsubplots = None
986
986
987 WIDTHPROF = None
987 WIDTHPROF = None
988 HEIGHTPROF = None
988 HEIGHTPROF = None
989 PREFIX = 'spc_cut'
989 PREFIX = 'spc_cut'
990
990
991 def __init__(self, **kwargs):
991 def __init__(self, **kwargs):
992 Figure.__init__(self, **kwargs)
992 Figure.__init__(self, **kwargs)
993 self.isConfig = False
993 self.isConfig = False
994 self.__nsubplots = 1
994 self.__nsubplots = 1
995
995
996 self.PLOT_CODE = POWER_CODE
996 self.PLOT_CODE = POWER_CODE
997
997
998 self.WIDTH = 700
998 self.WIDTH = 700
999 self.HEIGHT = 500
999 self.HEIGHT = 500
1000 self.counter_imagwr = 0
1000 self.counter_imagwr = 0
1001
1001
1002 def getSubplots(self):
1002 def getSubplots(self):
1003 ncol = 1
1003 ncol = 1
1004 nrow = 1
1004 nrow = 1
1005
1005
1006 return nrow, ncol
1006 return nrow, ncol
1007
1007
1008 def setup(self, id, nplots, wintitle, show):
1008 def setup(self, id, nplots, wintitle, show):
1009
1009
1010 self.nplots = nplots
1010 self.nplots = nplots
1011
1011
1012 ncolspan = 1
1012 ncolspan = 1
1013 colspan = 1
1013 colspan = 1
1014
1014
1015 self.createFigure(id = id,
1015 self.createFigure(id = id,
1016 wintitle = wintitle,
1016 wintitle = wintitle,
1017 widthplot = self.WIDTH,
1017 widthplot = self.WIDTH,
1018 heightplot = self.HEIGHT,
1018 heightplot = self.HEIGHT,
1019 show=show)
1019 show=show)
1020
1020
1021 nrow, ncol = self.getSubplots()
1021 nrow, ncol = self.getSubplots()
1022
1022
1023 counter = 0
1023 counter = 0
1024 for y in range(nrow):
1024 for y in range(nrow):
1025 for x in range(ncol):
1025 for x in range(ncol):
1026 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1026 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1027
1027
1028 def run(self, dataOut, id, wintitle="", channelList=None,
1028 def run(self, dataOut, id, wintitle="", channelList=None,
1029 xmin=None, xmax=None, ymin=None, ymax=None,
1029 xmin=None, xmax=None, ymin=None, ymax=None,
1030 save=False, figpath='./', figfile=None, show=True,
1030 save=False, figpath='./', figfile=None, show=True,
1031 ftp=False, wr_period=1, server=None,
1031 ftp=False, wr_period=1, server=None,
1032 folder=None, username=None, password=None,
1032 folder=None, username=None, password=None,
1033 xaxis="frequency"):
1033 xaxis="frequency"):
1034
1034
1035
1035
1036 if channelList == None:
1036 if channelList == None:
1037 channelIndexList = dataOut.channelIndexList
1037 channelIndexList = dataOut.channelIndexList
1038 channelList = dataOut.channelList
1038 channelList = dataOut.channelList
1039 else:
1039 else:
1040 channelIndexList = []
1040 channelIndexList = []
1041 for channel in channelList:
1041 for channel in channelList:
1042 if channel not in dataOut.channelList:
1042 if channel not in dataOut.channelList:
1043 raise ValueError, "Channel %d is not in dataOut.channelList"
1043 raise ValueError, "Channel %d is not in dataOut.channelList"
1044 channelIndexList.append(dataOut.channelList.index(channel))
1044 channelIndexList.append(dataOut.channelList.index(channel))
1045
1045
1046 factor = dataOut.normFactor
1046 factor = dataOut.normFactor
1047
1047
1048 y = dataOut.getHeiRange()
1048 y = dataOut.getHeiRange()
1049
1049
1050 z = dataOut.data_spc/factor
1050 z = dataOut.data_spc/factor
1051 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1051 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
1052
1052
1053 hei_index = numpy.arange(25)*3 + 20
1053 hei_index = numpy.arange(25)*3 + 20
1054
1054
1055 if xaxis == "frequency":
1055 if xaxis == "frequency":
1056 x = dataOut.getFreqRange()/1000.
1056 x = dataOut.getFreqRange()/1000.
1057 zdB = 10*numpy.log10(z[0,:,hei_index])
1057 zdB = 10*numpy.log10(z[0,:,hei_index])
1058 xlabel = "Frequency (kHz)"
1058 xlabel = "Frequency (kHz)"
1059 ylabel = "Power (dB)"
1059 ylabel = "Power (dB)"
1060
1060
1061 elif xaxis == "time":
1061 elif xaxis == "time":
1062 x = dataOut.getAcfRange()
1062 x = dataOut.getAcfRange()
1063 zdB = z[0,:,hei_index]
1063 zdB = z[0,:,hei_index]
1064 xlabel = "Time (ms)"
1064 xlabel = "Time (ms)"
1065 ylabel = "ACF"
1065 ylabel = "ACF"
1066
1066
1067 else:
1067 else:
1068 x = dataOut.getVelRange()
1068 x = dataOut.getVelRange()
1069 zdB = 10*numpy.log10(z[0,:,hei_index])
1069 zdB = 10*numpy.log10(z[0,:,hei_index])
1070 xlabel = "Velocity (m/s)"
1070 xlabel = "Velocity (m/s)"
1071 ylabel = "Power (dB)"
1071 ylabel = "Power (dB)"
1072
1072
1073 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1073 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
1074 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1074 title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y"))
1075
1075
1076 if not self.isConfig:
1076 if not self.isConfig:
1077
1077
1078 nplots = 1
1078 nplots = 1
1079
1079
1080 self.setup(id=id,
1080 self.setup(id=id,
1081 nplots=nplots,
1081 nplots=nplots,
1082 wintitle=wintitle,
1082 wintitle=wintitle,
1083 show=show)
1083 show=show)
1084
1084
1085 if xmin == None: xmin = numpy.nanmin(x)*0.9
1085 if xmin == None: xmin = numpy.nanmin(x)*0.9
1086 if xmax == None: xmax = numpy.nanmax(x)*1.1
1086 if xmax == None: xmax = numpy.nanmax(x)*1.1
1087 if ymin == None: ymin = numpy.nanmin(zdB)
1087 if ymin == None: ymin = numpy.nanmin(zdB)
1088 if ymax == None: ymax = numpy.nanmax(zdB)
1088 if ymax == None: ymax = numpy.nanmax(zdB)
1089
1089
1090 self.isConfig = True
1090 self.isConfig = True
1091
1091
1092 self.setWinTitle(title)
1092 self.setWinTitle(title)
1093
1093
1094 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1094 title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1095 axes = self.axesList[0]
1095 axes = self.axesList[0]
1096
1096
1097 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1097 legendlabels = ["Range = %dKm" %y[i] for i in hei_index]
1098
1098
1099 axes.pmultilineyaxis( x, zdB,
1099 axes.pmultilineyaxis( x, zdB,
1100 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1100 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1101 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1101 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
1102 ytick_visible=True, nxticks=5,
1102 ytick_visible=True, nxticks=5,
1103 grid='x')
1103 grid='x')
1104
1104
1105 self.draw()
1105 self.draw()
1106
1106
1107 self.save(figpath=figpath,
1107 self.save(figpath=figpath,
1108 figfile=figfile,
1108 figfile=figfile,
1109 save=save,
1109 save=save,
1110 ftp=ftp,
1110 ftp=ftp,
1111 wr_period=wr_period,
1111 wr_period=wr_period,
1112 thisDatetime=thisDatetime)
1112 thisDatetime=thisDatetime)
1113
1113
1114 class Noise(Figure):
1114 class Noise(Figure):
1115
1115
1116 isConfig = None
1116 isConfig = None
1117 __nsubplots = None
1117 __nsubplots = None
1118
1118
1119 PREFIX = 'noise'
1119 PREFIX = 'noise'
1120
1120
1121
1121
1122 def __init__(self, **kwargs):
1122 def __init__(self, **kwargs):
1123 Figure.__init__(self, **kwargs)
1123 Figure.__init__(self, **kwargs)
1124 self.timerange = 24*60*60
1124 self.timerange = 24*60*60
1125 self.isConfig = False
1125 self.isConfig = False
1126 self.__nsubplots = 1
1126 self.__nsubplots = 1
1127 self.counter_imagwr = 0
1127 self.counter_imagwr = 0
1128 self.WIDTH = 800
1128 self.WIDTH = 800
1129 self.HEIGHT = 400
1129 self.HEIGHT = 400
1130 self.WIDTHPROF = 120
1130 self.WIDTHPROF = 120
1131 self.HEIGHTPROF = 0
1131 self.HEIGHTPROF = 0
1132 self.xdata = None
1132 self.xdata = None
1133 self.ydata = None
1133 self.ydata = None
1134
1134
1135 self.PLOT_CODE = NOISE_CODE
1135 self.PLOT_CODE = NOISE_CODE
1136
1136
1137 self.FTP_WEI = None
1137 self.FTP_WEI = None
1138 self.EXP_CODE = None
1138 self.EXP_CODE = None
1139 self.SUB_EXP_CODE = None
1139 self.SUB_EXP_CODE = None
1140 self.PLOT_POS = None
1140 self.PLOT_POS = None
1141 self.figfile = None
1141 self.figfile = None
1142
1142
1143 self.xmin = None
1143 self.xmin = None
1144 self.xmax = None
1144 self.xmax = None
1145
1145
1146 def getSubplots(self):
1146 def getSubplots(self):
1147
1147
1148 ncol = 1
1148 ncol = 1
1149 nrow = 1
1149 nrow = 1
1150
1150
1151 return nrow, ncol
1151 return nrow, ncol
1152
1152
1153 def openfile(self, filename):
1153 def openfile(self, filename):
1154 dirname = os.path.dirname(filename)
1154 dirname = os.path.dirname(filename)
1155
1155
1156 if not os.path.exists(dirname):
1156 if not os.path.exists(dirname):
1157 os.mkdir(dirname)
1157 os.mkdir(dirname)
1158
1158
1159 f = open(filename,'w+')
1159 f = open(filename,'w+')
1160 f.write('\n\n')
1160 f.write('\n\n')
1161 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1161 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
1162 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1162 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
1163 f.close()
1163 f.close()
1164
1164
1165 def save_data(self, filename_phase, data, data_datetime):
1165 def save_data(self, filename_phase, data, data_datetime):
1166
1166
1167 f=open(filename_phase,'a')
1167 f=open(filename_phase,'a')
1168
1168
1169 timetuple_data = data_datetime.timetuple()
1169 timetuple_data = data_datetime.timetuple()
1170 day = str(timetuple_data.tm_mday)
1170 day = str(timetuple_data.tm_mday)
1171 month = str(timetuple_data.tm_mon)
1171 month = str(timetuple_data.tm_mon)
1172 year = str(timetuple_data.tm_year)
1172 year = str(timetuple_data.tm_year)
1173 hour = str(timetuple_data.tm_hour)
1173 hour = str(timetuple_data.tm_hour)
1174 minute = str(timetuple_data.tm_min)
1174 minute = str(timetuple_data.tm_min)
1175 second = str(timetuple_data.tm_sec)
1175 second = str(timetuple_data.tm_sec)
1176
1176
1177 data_msg = ''
1177 data_msg = ''
1178 for i in range(len(data)):
1178 for i in range(len(data)):
1179 data_msg += str(data[i]) + ' '
1179 data_msg += str(data[i]) + ' '
1180
1180
1181 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1181 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n')
1182 f.close()
1182 f.close()
1183
1183
1184
1184
1185 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1185 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1186
1186
1187 self.__showprofile = showprofile
1187 self.__showprofile = showprofile
1188 self.nplots = nplots
1188 self.nplots = nplots
1189
1189
1190 ncolspan = 7
1190 ncolspan = 7
1191 colspan = 6
1191 colspan = 6
1192 self.__nsubplots = 2
1192 self.__nsubplots = 2
1193
1193
1194 self.createFigure(id = id,
1194 self.createFigure(id = id,
1195 wintitle = wintitle,
1195 wintitle = wintitle,
1196 widthplot = self.WIDTH+self.WIDTHPROF,
1196 widthplot = self.WIDTH+self.WIDTHPROF,
1197 heightplot = self.HEIGHT+self.HEIGHTPROF,
1197 heightplot = self.HEIGHT+self.HEIGHTPROF,
1198 show=show)
1198 show=show)
1199
1199
1200 nrow, ncol = self.getSubplots()
1200 nrow, ncol = self.getSubplots()
1201
1201
1202 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1202 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1203
1203
1204
1204
1205 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1205 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1206 xmin=None, xmax=None, ymin=None, ymax=None,
1206 xmin=None, xmax=None, ymin=None, ymax=None,
1207 timerange=None,
1207 timerange=None,
1208 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1208 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1209 server=None, folder=None, username=None, password=None,
1209 server=None, folder=None, username=None, password=None,
1210 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1210 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1211
1211
1212 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1212 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1213 return
1213 return
1214
1214
1215 if channelList == None:
1215 if channelList == None:
1216 channelIndexList = dataOut.channelIndexList
1216 channelIndexList = dataOut.channelIndexList
1217 channelList = dataOut.channelList
1217 channelList = dataOut.channelList
1218 else:
1218 else:
1219 channelIndexList = []
1219 channelIndexList = []
1220 for channel in channelList:
1220 for channel in channelList:
1221 if channel not in dataOut.channelList:
1221 if channel not in dataOut.channelList:
1222 raise ValueError, "Channel %d is not in dataOut.channelList"
1222 raise ValueError, "Channel %d is not in dataOut.channelList"
1223 channelIndexList.append(dataOut.channelList.index(channel))
1223 channelIndexList.append(dataOut.channelList.index(channel))
1224
1224
1225 x = dataOut.getTimeRange()
1225 x = dataOut.getTimeRange()
1226 #y = dataOut.getHeiRange()
1226 #y = dataOut.getHeiRange()
1227 factor = dataOut.normFactor
1227 factor = dataOut.normFactor
1228 noise = dataOut.noise[channelIndexList]/factor
1228 noise = dataOut.noise[channelIndexList]/factor
1229 noisedB = 10*numpy.log10(noise)
1229 noisedB = 10*numpy.log10(noise)
1230
1230
1231 thisDatetime = dataOut.datatime
1231 thisDatetime = dataOut.datatime
1232
1232
1233 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1233 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1234 xlabel = ""
1234 xlabel = ""
1235 ylabel = "Intensity (dB)"
1235 ylabel = "Intensity (dB)"
1236 update_figfile = False
1236 update_figfile = False
1237
1237
1238 if not self.isConfig:
1238 if not self.isConfig:
1239
1239
1240 nplots = 1
1240 nplots = 1
1241
1241
1242 self.setup(id=id,
1242 self.setup(id=id,
1243 nplots=nplots,
1243 nplots=nplots,
1244 wintitle=wintitle,
1244 wintitle=wintitle,
1245 showprofile=showprofile,
1245 showprofile=showprofile,
1246 show=show)
1246 show=show)
1247
1247
1248 if timerange != None:
1248 if timerange != None:
1249 self.timerange = timerange
1249 self.timerange = timerange
1250
1250
1251 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1251 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1252
1252
1253 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1253 if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0
1254 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1254 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1255
1255
1256 self.FTP_WEI = ftp_wei
1256 self.FTP_WEI = ftp_wei
1257 self.EXP_CODE = exp_code
1257 self.EXP_CODE = exp_code
1258 self.SUB_EXP_CODE = sub_exp_code
1258 self.SUB_EXP_CODE = sub_exp_code
1259 self.PLOT_POS = plot_pos
1259 self.PLOT_POS = plot_pos
1260
1260
1261
1261
1262 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1262 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1263 self.isConfig = True
1263 self.isConfig = True
1264 self.figfile = figfile
1264 self.figfile = figfile
1265 self.xdata = numpy.array([])
1265 self.xdata = numpy.array([])
1266 self.ydata = numpy.array([])
1266 self.ydata = numpy.array([])
1267
1267
1268 update_figfile = True
1268 update_figfile = True
1269
1269
1270 #open file beacon phase
1270 #open file beacon phase
1271 path = '%s%03d' %(self.PREFIX, self.id)
1271 path = '%s%03d' %(self.PREFIX, self.id)
1272 noise_file = os.path.join(path,'%s.txt'%self.name)
1272 noise_file = os.path.join(path,'%s.txt'%self.name)
1273 self.filename_noise = os.path.join(figpath,noise_file)
1273 self.filename_noise = os.path.join(figpath,noise_file)
1274
1274
1275 self.setWinTitle(title)
1275 self.setWinTitle(title)
1276
1276
1277 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1277 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1278
1278
1279 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1279 legendlabels = ["channel %d"%(idchannel) for idchannel in channelList]
1280 axes = self.axesList[0]
1280 axes = self.axesList[0]
1281
1281
1282 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1282 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1283
1283
1284 if len(self.ydata)==0:
1284 if len(self.ydata)==0:
1285 self.ydata = noisedB.reshape(-1,1)
1285 self.ydata = noisedB.reshape(-1,1)
1286 else:
1286 else:
1287 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1287 self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1)))
1288
1288
1289
1289
1290 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1290 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1291 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1291 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1292 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1292 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1293 XAxisAsTime=True, grid='both'
1293 XAxisAsTime=True, grid='both'
1294 )
1294 )
1295
1295
1296 self.draw()
1296 self.draw()
1297
1297
1298 if dataOut.ltctime >= self.xmax:
1298 if dataOut.ltctime >= self.xmax:
1299 self.counter_imagwr = wr_period
1299 self.counter_imagwr = wr_period
1300 self.isConfig = False
1300 self.isConfig = False
1301 update_figfile = True
1301 update_figfile = True
1302
1302
1303 self.save(figpath=figpath,
1303 self.save(figpath=figpath,
1304 figfile=figfile,
1304 figfile=figfile,
1305 save=save,
1305 save=save,
1306 ftp=ftp,
1306 ftp=ftp,
1307 wr_period=wr_period,
1307 wr_period=wr_period,
1308 thisDatetime=thisDatetime,
1308 thisDatetime=thisDatetime,
1309 update_figfile=update_figfile)
1309 update_figfile=update_figfile)
1310
1310
1311 #store data beacon phase
1311 #store data beacon phase
1312 if save:
1312 if save:
1313 self.save_data(self.filename_noise, noisedB, thisDatetime)
1313 self.save_data(self.filename_noise, noisedB, thisDatetime)
1314
1314
1315 class BeaconPhase(Figure):
1315 class BeaconPhase(Figure):
1316
1316
1317 __isConfig = None
1317 __isConfig = None
1318 __nsubplots = None
1318 __nsubplots = None
1319
1319
1320 PREFIX = 'beacon_phase'
1320 PREFIX = 'beacon_phase'
1321
1321
1322 def __init__(self, **kwargs):
1322 def __init__(self, **kwargs):
1323 Figure.__init__(self, **kwargs)
1323 Figure.__init__(self, **kwargs)
1324 self.timerange = 24*60*60
1324 self.timerange = 24*60*60
1325 self.isConfig = False
1325 self.isConfig = False
1326 self.__nsubplots = 1
1326 self.__nsubplots = 1
1327 self.counter_imagwr = 0
1327 self.counter_imagwr = 0
1328 self.WIDTH = 800
1328 self.WIDTH = 800
1329 self.HEIGHT = 400
1329 self.HEIGHT = 400
1330 self.WIDTHPROF = 120
1330 self.WIDTHPROF = 120
1331 self.HEIGHTPROF = 0
1331 self.HEIGHTPROF = 0
1332 self.xdata = None
1332 self.xdata = None
1333 self.ydata = None
1333 self.ydata = None
1334
1334
1335 self.PLOT_CODE = BEACON_CODE
1335 self.PLOT_CODE = BEACON_CODE
1336
1336
1337 self.FTP_WEI = None
1337 self.FTP_WEI = None
1338 self.EXP_CODE = None
1338 self.EXP_CODE = None
1339 self.SUB_EXP_CODE = None
1339 self.SUB_EXP_CODE = None
1340 self.PLOT_POS = None
1340 self.PLOT_POS = None
1341
1341
1342 self.filename_phase = None
1342 self.filename_phase = None
1343
1343
1344 self.figfile = None
1344 self.figfile = None
1345
1345
1346 self.xmin = None
1346 self.xmin = None
1347 self.xmax = None
1347 self.xmax = None
1348
1348
1349 def getSubplots(self):
1349 def getSubplots(self):
1350
1350
1351 ncol = 1
1351 ncol = 1
1352 nrow = 1
1352 nrow = 1
1353
1353
1354 return nrow, ncol
1354 return nrow, ncol
1355
1355
1356 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1356 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1357
1357
1358 self.__showprofile = showprofile
1358 self.__showprofile = showprofile
1359 self.nplots = nplots
1359 self.nplots = nplots
1360
1360
1361 ncolspan = 7
1361 ncolspan = 7
1362 colspan = 6
1362 colspan = 6
1363 self.__nsubplots = 2
1363 self.__nsubplots = 2
1364
1364
1365 self.createFigure(id = id,
1365 self.createFigure(id = id,
1366 wintitle = wintitle,
1366 wintitle = wintitle,
1367 widthplot = self.WIDTH+self.WIDTHPROF,
1367 widthplot = self.WIDTH+self.WIDTHPROF,
1368 heightplot = self.HEIGHT+self.HEIGHTPROF,
1368 heightplot = self.HEIGHT+self.HEIGHTPROF,
1369 show=show)
1369 show=show)
1370
1370
1371 nrow, ncol = self.getSubplots()
1371 nrow, ncol = self.getSubplots()
1372
1372
1373 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1373 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1374
1374
1375 def save_phase(self, filename_phase):
1375 def save_phase(self, filename_phase):
1376 f = open(filename_phase,'w+')
1376 f = open(filename_phase,'w+')
1377 f.write('\n\n')
1377 f.write('\n\n')
1378 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1378 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1379 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1379 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1380 f.close()
1380 f.close()
1381
1381
1382 def save_data(self, filename_phase, data, data_datetime):
1382 def save_data(self, filename_phase, data, data_datetime):
1383 f=open(filename_phase,'a')
1383 f=open(filename_phase,'a')
1384 timetuple_data = data_datetime.timetuple()
1384 timetuple_data = data_datetime.timetuple()
1385 day = str(timetuple_data.tm_mday)
1385 day = str(timetuple_data.tm_mday)
1386 month = str(timetuple_data.tm_mon)
1386 month = str(timetuple_data.tm_mon)
1387 year = str(timetuple_data.tm_year)
1387 year = str(timetuple_data.tm_year)
1388 hour = str(timetuple_data.tm_hour)
1388 hour = str(timetuple_data.tm_hour)
1389 minute = str(timetuple_data.tm_min)
1389 minute = str(timetuple_data.tm_min)
1390 second = str(timetuple_data.tm_sec)
1390 second = str(timetuple_data.tm_sec)
1391 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1391 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1392 f.close()
1392 f.close()
1393
1393
1394
1394
1395 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1395 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1396 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1396 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
1397 timerange=None,
1397 timerange=None,
1398 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1398 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
1399 server=None, folder=None, username=None, password=None,
1399 server=None, folder=None, username=None, password=None,
1400 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1400 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1401
1401
1402 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1402 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
1403 return
1403 return
1404
1404
1405 if pairsList == None:
1405 if pairsList == None:
1406 pairsIndexList = dataOut.pairsIndexList[:10]
1406 pairsIndexList = dataOut.pairsIndexList[:10]
1407 else:
1407 else:
1408 pairsIndexList = []
1408 pairsIndexList = []
1409 for pair in pairsList:
1409 for pair in pairsList:
1410 if pair not in dataOut.pairsList:
1410 if pair not in dataOut.pairsList:
1411 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1411 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1412 pairsIndexList.append(dataOut.pairsList.index(pair))
1412 pairsIndexList.append(dataOut.pairsList.index(pair))
1413
1413
1414 if pairsIndexList == []:
1414 if pairsIndexList == []:
1415 return
1415 return
1416
1416
1417 # if len(pairsIndexList) > 4:
1417 # if len(pairsIndexList) > 4:
1418 # pairsIndexList = pairsIndexList[0:4]
1418 # pairsIndexList = pairsIndexList[0:4]
1419
1419
1420 hmin_index = None
1420 hmin_index = None
1421 hmax_index = None
1421 hmax_index = None
1422
1422
1423 if hmin != None and hmax != None:
1423 if hmin != None and hmax != None:
1424 indexes = numpy.arange(dataOut.nHeights)
1424 indexes = numpy.arange(dataOut.nHeights)
1425 hmin_list = indexes[dataOut.heightList >= hmin]
1425 hmin_list = indexes[dataOut.heightList >= hmin]
1426 hmax_list = indexes[dataOut.heightList <= hmax]
1426 hmax_list = indexes[dataOut.heightList <= hmax]
1427
1427
1428 if hmin_list.any():
1428 if hmin_list.any():
1429 hmin_index = hmin_list[0]
1429 hmin_index = hmin_list[0]
1430
1430
1431 if hmax_list.any():
1431 if hmax_list.any():
1432 hmax_index = hmax_list[-1]+1
1432 hmax_index = hmax_list[-1]+1
1433
1433
1434 x = dataOut.getTimeRange()
1434 x = dataOut.getTimeRange()
1435 #y = dataOut.getHeiRange()
1435 #y = dataOut.getHeiRange()
1436
1436
1437
1437
1438 thisDatetime = dataOut.datatime
1438 thisDatetime = dataOut.datatime
1439
1439
1440 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1440 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1441 xlabel = "Local Time"
1441 xlabel = "Local Time"
1442 ylabel = "Phase (degrees)"
1442 ylabel = "Phase (degrees)"
1443
1443
1444 update_figfile = False
1444 update_figfile = False
1445
1445
1446 nplots = len(pairsIndexList)
1446 nplots = len(pairsIndexList)
1447 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1447 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1448 phase_beacon = numpy.zeros(len(pairsIndexList))
1448 phase_beacon = numpy.zeros(len(pairsIndexList))
1449 for i in range(nplots):
1449 for i in range(nplots):
1450 pair = dataOut.pairsList[pairsIndexList[i]]
1450 pair = dataOut.pairsList[pairsIndexList[i]]
1451 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1451 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
1452 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1452 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
1453 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1453 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
1454 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1454 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1455 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1455 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1456
1456
1457 #print "Phase %d%d" %(pair[0], pair[1])
1457 #print "Phase %d%d" %(pair[0], pair[1])
1458 #print phase[dataOut.beacon_heiIndexList]
1458 #print phase[dataOut.beacon_heiIndexList]
1459
1459
1460 if dataOut.beacon_heiIndexList:
1460 if dataOut.beacon_heiIndexList:
1461 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1461 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1462 else:
1462 else:
1463 phase_beacon[i] = numpy.average(phase)
1463 phase_beacon[i] = numpy.average(phase)
1464
1464
1465 if not self.isConfig:
1465 if not self.isConfig:
1466
1466
1467 nplots = len(pairsIndexList)
1467 nplots = len(pairsIndexList)
1468
1468
1469 self.setup(id=id,
1469 self.setup(id=id,
1470 nplots=nplots,
1470 nplots=nplots,
1471 wintitle=wintitle,
1471 wintitle=wintitle,
1472 showprofile=showprofile,
1472 showprofile=showprofile,
1473 show=show)
1473 show=show)
1474
1474
1475 if timerange != None:
1475 if timerange != None:
1476 self.timerange = timerange
1476 self.timerange = timerange
1477
1477
1478 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1478 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1479
1479
1480 if ymin == None: ymin = 0
1480 if ymin == None: ymin = 0
1481 if ymax == None: ymax = 360
1481 if ymax == None: ymax = 360
1482
1482
1483 self.FTP_WEI = ftp_wei
1483 self.FTP_WEI = ftp_wei
1484 self.EXP_CODE = exp_code
1484 self.EXP_CODE = exp_code
1485 self.SUB_EXP_CODE = sub_exp_code
1485 self.SUB_EXP_CODE = sub_exp_code
1486 self.PLOT_POS = plot_pos
1486 self.PLOT_POS = plot_pos
1487
1487
1488 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1488 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1489 self.isConfig = True
1489 self.isConfig = True
1490 self.figfile = figfile
1490 self.figfile = figfile
1491 self.xdata = numpy.array([])
1491 self.xdata = numpy.array([])
1492 self.ydata = numpy.array([])
1492 self.ydata = numpy.array([])
1493
1493
1494 update_figfile = True
1494 update_figfile = True
1495
1495
1496 #open file beacon phase
1496 #open file beacon phase
1497 path = '%s%03d' %(self.PREFIX, self.id)
1497 path = '%s%03d' %(self.PREFIX, self.id)
1498 beacon_file = os.path.join(path,'%s.txt'%self.name)
1498 beacon_file = os.path.join(path,'%s.txt'%self.name)
1499 self.filename_phase = os.path.join(figpath,beacon_file)
1499 self.filename_phase = os.path.join(figpath,beacon_file)
1500 #self.save_phase(self.filename_phase)
1500 #self.save_phase(self.filename_phase)
1501
1501
1502
1502
1503 #store data beacon phase
1503 #store data beacon phase
1504 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1504 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1505
1505
1506 self.setWinTitle(title)
1506 self.setWinTitle(title)
1507
1507
1508
1508
1509 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1509 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1510
1510
1511 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1511 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1512
1512
1513 axes = self.axesList[0]
1513 axes = self.axesList[0]
1514
1514
1515 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1515 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1516
1516
1517 if len(self.ydata)==0:
1517 if len(self.ydata)==0:
1518 self.ydata = phase_beacon.reshape(-1,1)
1518 self.ydata = phase_beacon.reshape(-1,1)
1519 else:
1519 else:
1520 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1520 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1521
1521
1522
1522
1523 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1523 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1524 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1524 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1525 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1525 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1526 XAxisAsTime=True, grid='both'
1526 XAxisAsTime=True, grid='both'
1527 )
1527 )
1528
1528
1529 self.draw()
1529 self.draw()
1530
1530
1531 if dataOut.ltctime >= self.xmax:
1531 if dataOut.ltctime >= self.xmax:
1532 self.counter_imagwr = wr_period
1532 self.counter_imagwr = wr_period
1533 self.isConfig = False
1533 self.isConfig = False
1534 update_figfile = True
1534 update_figfile = True
1535
1535
1536 self.save(figpath=figpath,
1536 self.save(figpath=figpath,
1537 figfile=figfile,
1537 figfile=figfile,
1538 save=save,
1538 save=save,
1539 ftp=ftp,
1539 ftp=ftp,
1540 wr_period=wr_period,
1540 wr_period=wr_period,
1541 thisDatetime=thisDatetime,
1541 thisDatetime=thisDatetime,
1542 update_figfile=update_figfile)
1542 update_figfile=update_figfile)
@@ -1,225 +1,225
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure
10 from figure import Figure
11
11
12 class Scope(Figure):
12 class Scope(Figure):
13
13
14 isConfig = None
14 isConfig = None
15
15
16 def __init__(self, **kwargs):
16 def __init__(self, **kwargs):
17 Figure.__init__(self, **kwargs)
17 Figure.__init__(self, **kwargs)
18 self.isConfig = False
18 self.isConfig = False
19 self.WIDTH = 300
19 self.WIDTH = 300
20 self.HEIGHT = 200
20 self.HEIGHT = 200
21 self.counter_imagwr = 0
21 self.counter_imagwr = 0
22
22
23 def getSubplots(self):
23 def getSubplots(self):
24
24
25 nrow = self.nplots
25 nrow = self.nplots
26 ncol = 3
26 ncol = 3
27 return nrow, ncol
27 return nrow, ncol
28
28
29 def setup(self, id, nplots, wintitle, show):
29 def setup(self, id, nplots, wintitle, show):
30
30
31 self.nplots = nplots
31 self.nplots = nplots
32
32
33 self.createFigure(id=id,
33 self.createFigure(id=id,
34 wintitle=wintitle,
34 wintitle=wintitle,
35 show=show)
35 show=show)
36
36
37 nrow,ncol = self.getSubplots()
37 nrow,ncol = self.getSubplots()
38 colspan = 3
38 colspan = 3
39 rowspan = 1
39 rowspan = 1
40
40
41 for i in range(nplots):
41 for i in range(nplots):
42 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
42 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
43
43
44 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
44 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
45 yreal = y[channelIndexList,:].real
45 yreal = y[channelIndexList,:].real
46 yimag = y[channelIndexList,:].imag
46 yimag = y[channelIndexList,:].imag
47
47
48 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
48 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
49 xlabel = "Range (Km)"
49 xlabel = "Range (Km)"
50 ylabel = "Intensity - IQ"
50 ylabel = "Intensity - IQ"
51
51
52 if not self.isConfig:
52 if not self.isConfig:
53 nplots = len(channelIndexList)
53 nplots = len(channelIndexList)
54
54
55 self.setup(id=id,
55 self.setup(id=id,
56 nplots=nplots,
56 nplots=nplots,
57 wintitle='',
57 wintitle='',
58 show=show)
58 show=show)
59
59
60 if xmin == None: xmin = numpy.nanmin(x)
60 if xmin == None: xmin = numpy.nanmin(x)
61 if xmax == None: xmax = numpy.nanmax(x)
61 if xmax == None: xmax = numpy.nanmax(x)
62 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
62 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
63 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
63 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
64
64
65 self.isConfig = True
65 self.isConfig = True
66
66
67 self.setWinTitle(title)
67 self.setWinTitle(title)
68
68
69 for i in range(len(self.axesList)):
69 for i in range(len(self.axesList)):
70 title = "Channel %d" %(i)
70 title = "Channel %d" %(i)
71 axes = self.axesList[i]
71 axes = self.axesList[i]
72
72
73 axes.pline(x, yreal[i,:],
73 axes.pline(x, yreal[i,:],
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
75 xlabel=xlabel, ylabel=ylabel, title=title)
75 xlabel=xlabel, ylabel=ylabel, title=title)
76
76
77 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
77 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
78
78
79 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
79 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
80 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
80 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
81 yreal = y.real
81 yreal = y.real
82
82
83 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
83 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
84 xlabel = "Range (Km)"
84 xlabel = "Range (Km)"
85 ylabel = "Intensity"
85 ylabel = "Intensity"
86
86
87 if not self.isConfig:
87 if not self.isConfig:
88 nplots = len(channelIndexList)
88 nplots = len(channelIndexList)
89
89
90 self.setup(id=id,
90 self.setup(id=id,
91 nplots=nplots,
91 nplots=nplots,
92 wintitle='',
92 wintitle='',
93 show=show)
93 show=show)
94
94
95 if xmin == None: xmin = numpy.nanmin(x)
95 if xmin == None: xmin = numpy.nanmin(x)
96 if xmax == None: xmax = numpy.nanmax(x)
96 if xmax == None: xmax = numpy.nanmax(x)
97 if ymin == None: ymin = numpy.nanmin(yreal)
97 if ymin == None: ymin = numpy.nanmin(yreal)
98 if ymax == None: ymax = numpy.nanmax(yreal)
98 if ymax == None: ymax = numpy.nanmax(yreal)
99
99
100 self.isConfig = True
100 self.isConfig = True
101
101
102 self.setWinTitle(title)
102 self.setWinTitle(title)
103
103
104 for i in range(len(self.axesList)):
104 for i in range(len(self.axesList)):
105 title = "Channel %d" %(i)
105 title = "Channel %d" %(i)
106 axes = self.axesList[i]
106 axes = self.axesList[i]
107 ychannel = yreal[i,:]
107 ychannel = yreal[i,:]
108 axes.pline(x, ychannel,
108 axes.pline(x, ychannel,
109 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
109 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
110 xlabel=xlabel, ylabel=ylabel, title=title)
110 xlabel=xlabel, ylabel=ylabel, title=title)
111
111
112
112
113 def run(self, dataOut, id, wintitle="", channelList=None,
113 def run(self, dataOut, id, wintitle="", channelList=None,
114 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
114 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
115 figpath='./', figfile=None, show=True, wr_period=1,
115 figpath='./', figfile=None, show=True, wr_period=1,
116 ftp=False, server=None, folder=None, username=None, password=None, type='power'):
116 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
117
117
118 """
118 """
119
119
120 Input:
120 Input:
121 dataOut :
121 dataOut :
122 id :
122 id :
123 wintitle :
123 wintitle :
124 channelList :
124 channelList :
125 xmin : None,
125 xmin : None,
126 xmax : None,
126 xmax : None,
127 ymin : None,
127 ymin : None,
128 ymax : None,
128 ymax : None,
129 """
129 """
130
130
131 if channelList == None:
131 if channelList == None:
132 channelIndexList = dataOut.channelIndexList
132 channelIndexList = dataOut.channelIndexList
133 else:
133 else:
134 channelIndexList = []
134 channelIndexList = []
135 for channel in channelList:
135 for channel in channelList:
136 if channel not in dataOut.channelList:
136 if channel not in dataOut.channelList:
137 raise ValueError, "Channel %d is not in dataOut.channelList"
137 raise ValueError, "Channel %d is not in dataOut.channelList"
138 channelIndexList.append(dataOut.channelList.index(channel))
138 channelIndexList.append(dataOut.channelList.index(channel))
139
139
140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
141
141
142 if dataOut.flagDataAsBlock:
142 if dataOut.flagDataAsBlock:
143
143
144 for i in range(dataOut.nProfiles):
144 for i in range(dataOut.nProfiles):
145
145
146 wintitle1 = wintitle + " [Profile = %d] " %i
146 wintitle1 = wintitle + " [Profile = %d] " %i
147
147
148 if type == "power":
148 if type == "power":
149 self.plot_power(dataOut.heightList,
149 self.plot_power(dataOut.heightList,
150 dataOut.data[:,i,:],
150 dataOut.data[:,i,:],
151 id,
151 id,
152 channelIndexList,
152 channelIndexList,
153 thisDatetime,
153 thisDatetime,
154 wintitle1,
154 wintitle1,
155 show,
155 show,
156 xmin,
156 xmin,
157 xmax,
157 xmax,
158 ymin,
158 ymin,
159 ymax)
159 ymax)
160
160
161 if type == "iq":
161 if type == "iq":
162 self.plot_iq(dataOut.heightList,
162 self.plot_iq(dataOut.heightList,
163 dataOut.data[:,i,:],
163 dataOut.data[:,i,:],
164 id,
164 id,
165 channelIndexList,
165 channelIndexList,
166 thisDatetime,
166 thisDatetime,
167 wintitle1,
167 wintitle1,
168 show,
168 show,
169 xmin,
169 xmin,
170 xmax,
170 xmax,
171 ymin,
171 ymin,
172 ymax)
172 ymax)
173
173
174 self.draw()
174 self.draw()
175
175
176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
177 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
177 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
178
178
179 self.save(figpath=figpath,
179 self.save(figpath=figpath,
180 figfile=figfile,
180 figfile=figfile,
181 save=save,
181 save=save,
182 ftp=ftp,
182 ftp=ftp,
183 wr_period=wr_period,
183 wr_period=wr_period,
184 thisDatetime=thisDatetime)
184 thisDatetime=thisDatetime)
185
185
186 else:
186 else:
187 wintitle += " [Profile = %d] " %dataOut.profileIndex
187 wintitle += " [Profile = %d] " %dataOut.profileIndex
188
188
189 if type == "power":
189 if type == "power":
190 self.plot_power(dataOut.heightList,
190 self.plot_power(dataOut.heightList,
191 dataOut.data,
191 dataOut.data,
192 id,
192 id,
193 channelIndexList,
193 channelIndexList,
194 thisDatetime,
194 thisDatetime,
195 wintitle,
195 wintitle,
196 show,
196 show,
197 xmin,
197 xmin,
198 xmax,
198 xmax,
199 ymin,
199 ymin,
200 ymax)
200 ymax)
201
201
202 if type == "iq":
202 if type == "iq":
203 self.plot_iq(dataOut.heightList,
203 self.plot_iq(dataOut.heightList,
204 dataOut.data,
204 dataOut.data,
205 id,
205 id,
206 channelIndexList,
206 channelIndexList,
207 thisDatetime,
207 thisDatetime,
208 wintitle,
208 wintitle,
209 show,
209 show,
210 xmin,
210 xmin,
211 xmax,
211 xmax,
212 ymin,
212 ymin,
213 ymax)
213 ymax)
214
214
215 self.draw()
215 self.draw()
216
216
217 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
217 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
218 figfile = self.getFilename(name = str_datetime)
218 figfile = self.getFilename(name = str_datetime)
219
219
220 self.save(figpath=figpath,
220 self.save(figpath=figpath,
221 figfile=figfile,
221 figfile=figfile,
222 save=save,
222 save=save,
223 ftp=ftp,
223 ftp=ftp,
224 wr_period=wr_period,
224 wr_period=wr_period,
225 thisDatetime=thisDatetime)
225 thisDatetime=thisDatetime)
@@ -1,481 +1,495
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 import sys
3 import sys
4 import matplotlib
4 import matplotlib
5
5
6 if 'linux' in sys.platform:
6 if 'linux' in sys.platform:
7 matplotlib.use("GTK3Agg")
7 matplotlib.use("TkAgg")
8
8
9 if 'darwin' in sys.platform:
9 if 'darwin' in sys.platform:
10 matplotlib.use('TKAgg')
10 matplotlib.use('TKAgg')
11 #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
11 # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX'
12 import matplotlib.pyplot
12 import matplotlib.pyplot
13
13
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
14 from mpl_toolkits.axes_grid1 import make_axes_locatable
15 from matplotlib.ticker import FuncFormatter, LinearLocator
15 from matplotlib.ticker import FuncFormatter, LinearLocator
16
16
17 ###########################################
17 ###########################################
18 #Actualizacion de las funciones del driver
18 # Actualizacion de las funciones del driver
19 ###########################################
19 ###########################################
20
20
21 # create jro colormap
21 # create jro colormap
22
22
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
24 blu_values = matplotlib.pyplot.get_cmap(
25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
25 "seismic_r", 20)(numpy.arange(20))[10:15]
26 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
27 "jro", numpy.vstack((blu_values, jet_values)))
26 matplotlib.pyplot.register_cmap(cmap=ncmap)
28 matplotlib.pyplot.register_cmap(cmap=ncmap)
27
29
30
28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
31 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
29
32
30 matplotlib.pyplot.ioff()
33 matplotlib.pyplot.ioff()
31
34
32 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
35 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
36 1.0 * width / dpi, 1.0 * height / dpi))
33 fig.canvas.manager.set_window_title(wintitle)
37 fig.canvas.manager.set_window_title(wintitle)
34 # fig.canvas.manager.resize(width, height)
38 # fig.canvas.manager.resize(width, height)
35 matplotlib.pyplot.ion()
39 matplotlib.pyplot.ion()
36
40
37 if show:
41 if show:
38 matplotlib.pyplot.show()
42 matplotlib.pyplot.show()
39
43
40 return fig
44 return fig
41
45
46
42 def closeFigure(show=False, fig=None):
47 def closeFigure(show=False, fig=None):
43
48
44 # matplotlib.pyplot.ioff()
49 # matplotlib.pyplot.ioff()
45 # matplotlib.pyplot.pause(0)
50 # matplotlib.pyplot.pause(0)
46
51
47 if show:
52 if show:
48 matplotlib.pyplot.show()
53 matplotlib.pyplot.show()
49
54
50 if fig != None:
55 if fig != None:
51 matplotlib.pyplot.close(fig)
56 matplotlib.pyplot.close(fig)
52 # matplotlib.pyplot.pause(0)
57 # matplotlib.pyplot.pause(0)
53 # matplotlib.pyplot.ion()
58 # matplotlib.pyplot.ion()
54
59
55 return
60 return
56
61
57 matplotlib.pyplot.close("all")
62 matplotlib.pyplot.close("all")
58 # matplotlib.pyplot.pause(0)
63 # matplotlib.pyplot.pause(0)
59 # matplotlib.pyplot.ion()
64 # matplotlib.pyplot.ion()
60
65
61 return
66 return
62
67
68
63 def saveFigure(fig, filename):
69 def saveFigure(fig, filename):
64
70
65 # matplotlib.pyplot.ioff()
71 # matplotlib.pyplot.ioff()
66 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
72 fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi)
67 # matplotlib.pyplot.ion()
73 # matplotlib.pyplot.ion()
68
74
75
69 def clearFigure(fig):
76 def clearFigure(fig):
70
77
71 fig.clf()
78 fig.clf()
72
79
80
73 def setWinTitle(fig, title):
81 def setWinTitle(fig, title):
74
82
75 fig.canvas.manager.set_window_title(title)
83 fig.canvas.manager.set_window_title(title)
76
84
85
77 def setTitle(fig, title):
86 def setTitle(fig, title):
78
87
79 fig.suptitle(title)
88 fig.suptitle(title)
80
89
90
81 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
91 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
82
92
83 matplotlib.pyplot.ioff()
93 matplotlib.pyplot.ioff()
84 matplotlib.pyplot.figure(fig.number)
94 matplotlib.pyplot.figure(fig.number)
85 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
95 axes = matplotlib.pyplot.subplot2grid((nrow, ncol),
86 (xpos, ypos),
96 (xpos, ypos),
87 colspan=colspan,
97 colspan=colspan,
88 rowspan=rowspan,
98 rowspan=rowspan,
89 polar=polar)
99 polar=polar)
90
100
91 axes.grid(True)
92
93 matplotlib.pyplot.ion()
101 matplotlib.pyplot.ion()
94 return axes
102 return axes
95
103
104
96 def setAxesText(ax, text):
105 def setAxesText(ax, text):
97
106
98 ax.annotate(text,
107 ax.annotate(text,
99 xy = (.1, .99),
108 xy=(.1, .99),
100 xycoords = 'figure fraction',
109 xycoords='figure fraction',
101 horizontalalignment = 'left',
110 horizontalalignment='left',
102 verticalalignment = 'top',
111 verticalalignment='top',
103 fontsize = 10)
112 fontsize=10)
104
113
114
105 def printLabels(ax, xlabel, ylabel, title):
115 def printLabels(ax, xlabel, ylabel, title):
106
116
107 ax.set_xlabel(xlabel, size=11)
117 ax.set_xlabel(xlabel, size=11)
108 ax.set_ylabel(ylabel, size=11)
118 ax.set_ylabel(ylabel, size=11)
109 ax.set_title(title, size=8)
119 ax.set_title(title, size=8)
110
120
121
111 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
122 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
112 ticksize=9, xtick_visible=True, ytick_visible=True,
123 ticksize=9, xtick_visible=True, ytick_visible=True,
113 nxticks=4, nyticks=10,
124 nxticks=4, nyticks=10,
114 grid=None,color='blue'):
125 grid=None, color='blue'):
115
116 """
126 """
117
127
118 Input:
128 Input:
119 grid : None, 'both', 'x', 'y'
129 grid : None, 'both', 'x', 'y'
120 """
130 """
121
131
122 matplotlib.pyplot.ioff()
132 matplotlib.pyplot.ioff()
123
133
124 ax.set_xlim([xmin,xmax])
134 ax.set_xlim([xmin, xmax])
125 ax.set_ylim([ymin,ymax])
135 ax.set_ylim([ymin, ymax])
126
136
127 printLabels(ax, xlabel, ylabel, title)
137 printLabels(ax, xlabel, ylabel, title)
128
138
129 ######################################################
139 ######################################################
130 if (xmax-xmin)<=1:
140 if (xmax - xmin) <= 1:
131 xtickspos = numpy.linspace(xmin,xmax,nxticks)
141 xtickspos = numpy.linspace(xmin, xmax, nxticks)
132 xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos])
142 xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos])
133 ax.set_xticks(xtickspos)
143 ax.set_xticks(xtickspos)
134 else:
144 else:
135 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
145 xtickspos = numpy.arange(nxticks) * \
146 int((xmax - xmin) / (nxticks)) + int(xmin)
136 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
147 # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin)
137 ax.set_xticks(xtickspos)
148 ax.set_xticks(xtickspos)
138
149
139 for tick in ax.get_xticklabels():
150 for tick in ax.get_xticklabels():
140 tick.set_visible(xtick_visible)
151 tick.set_visible(xtick_visible)
141
152
142 for tick in ax.xaxis.get_major_ticks():
153 for tick in ax.xaxis.get_major_ticks():
143 tick.label.set_fontsize(ticksize)
154 tick.label.set_fontsize(ticksize)
144
155
145 ######################################################
156 ######################################################
146 for tick in ax.get_yticklabels():
157 for tick in ax.get_yticklabels():
147 tick.set_visible(ytick_visible)
158 tick.set_visible(ytick_visible)
148
159
149 for tick in ax.yaxis.get_major_ticks():
160 for tick in ax.yaxis.get_major_ticks():
150 tick.label.set_fontsize(ticksize)
161 tick.label.set_fontsize(ticksize)
151
162
152 ax.plot(x, y, color=color)
163 ax.plot(x, y, color=color)
153 iplot = ax.lines[-1]
164 iplot = ax.lines[-1]
154
165
155 ######################################################
166 ######################################################
156 if '0.' in matplotlib.__version__[0:2]:
167 if '0.' in matplotlib.__version__[0:2]:
157 print "The matplotlib version has to be updated to 1.1 or newer"
168 print "The matplotlib version has to be updated to 1.1 or newer"
158 return iplot
169 return iplot
159
170
160 if '1.0.' in matplotlib.__version__[0:4]:
171 if '1.0.' in matplotlib.__version__[0:4]:
161 print "The matplotlib version has to be updated to 1.1 or newer"
172 print "The matplotlib version has to be updated to 1.1 or newer"
162 return iplot
173 return iplot
163
174
164 if grid != None:
175 if grid != None:
165 ax.grid(b=True, which='major', axis=grid)
176 ax.grid(b=True, which='major', axis=grid)
166
177
167 matplotlib.pyplot.tight_layout()
178 matplotlib.pyplot.tight_layout()
168
179
169 matplotlib.pyplot.ion()
180 matplotlib.pyplot.ion()
170
181
171 return iplot
182 return iplot
172
183
184
173 def set_linedata(ax, x, y, idline):
185 def set_linedata(ax, x, y, idline):
174
186
175 ax.lines[idline].set_data(x,y)
187 ax.lines[idline].set_data(x, y)
176
188
189
177 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
190 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
178
191
179 ax = iplot.get_axes()
192 ax = iplot.axes
180
193
181 printLabels(ax, xlabel, ylabel, title)
194 printLabels(ax, xlabel, ylabel, title)
182
195
183 set_linedata(ax, x, y, idline=0)
196 set_linedata(ax, x, y, idline=0)
184
197
198
185 def addpline(ax, x, y, color, linestyle, lw):
199 def addpline(ax, x, y, color, linestyle, lw):
186
200
187 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
201 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
188
202
189
203
190 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
204 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
191 xlabel='', ylabel='', title='', ticksize = 9,
205 xlabel='', ylabel='', title='', ticksize=9,
192 colormap='jet',cblabel='', cbsize="5%",
206 colormap='jet', cblabel='', cbsize="5%",
193 XAxisAsTime=False):
207 XAxisAsTime=False):
194
208
195 matplotlib.pyplot.ioff()
209 matplotlib.pyplot.ioff()
196
210
197 divider = make_axes_locatable(ax)
211 divider = make_axes_locatable(ax)
198 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
212 ax_cb = divider.new_horizontal(size=cbsize, pad=0.05)
199 fig = ax.get_figure()
213 fig = ax.get_figure()
200 fig.add_axes(ax_cb)
214 fig.add_axes(ax_cb)
201
215
202 ax.set_xlim([xmin,xmax])
216 ax.set_xlim([xmin, xmax])
203 ax.set_ylim([ymin,ymax])
217 ax.set_ylim([ymin, ymax])
204
218
205 printLabels(ax, xlabel, ylabel, title)
219 printLabels(ax, xlabel, ylabel, title)
206
220
207 z = numpy.ma.masked_invalid(z)
221 z = numpy.ma.masked_invalid(z)
208 cmap=matplotlib.pyplot.get_cmap(colormap)
222 cmap = matplotlib.pyplot.get_cmap(colormap)
209 cmap.set_bad('white',1.)
223 cmap.set_bad('black', 1.)
210 imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap)
224 imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
211 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
225 cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb)
212 cb.set_label(cblabel)
226 cb.set_label(cblabel)
213
227
214 # for tl in ax_cb.get_yticklabels():
228 # for tl in ax_cb.get_yticklabels():
215 # tl.set_visible(True)
229 # tl.set_visible(True)
216
230
217 for tick in ax.yaxis.get_major_ticks():
231 for tick in ax.yaxis.get_major_ticks():
218 tick.label.set_fontsize(ticksize)
232 tick.label.set_fontsize(ticksize)
219
233
220 for tick in ax.xaxis.get_major_ticks():
234 for tick in ax.xaxis.get_major_ticks():
221 tick.label.set_fontsize(ticksize)
235 tick.label.set_fontsize(ticksize)
222
236
223 for tick in cb.ax.get_yticklabels():
237 for tick in cb.ax.get_yticklabels():
224 tick.set_fontsize(ticksize)
238 tick.set_fontsize(ticksize)
225
239
226 ax_cb.yaxis.tick_right()
240 ax_cb.yaxis.tick_right()
227
241
228 if '0.' in matplotlib.__version__[0:2]:
242 if '0.' in matplotlib.__version__[0:2]:
229 print "The matplotlib version has to be updated to 1.1 or newer"
243 print "The matplotlib version has to be updated to 1.1 or newer"
230 return imesh
244 return imesh
231
245
232 if '1.0.' in matplotlib.__version__[0:4]:
246 if '1.0.' in matplotlib.__version__[0:4]:
233 print "The matplotlib version has to be updated to 1.1 or newer"
247 print "The matplotlib version has to be updated to 1.1 or newer"
234 return imesh
248 return imesh
235
249
236 matplotlib.pyplot.tight_layout()
250 matplotlib.pyplot.tight_layout()
237
251
238 if XAxisAsTime:
252 if XAxisAsTime:
239
253
240 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
254 def func(x, pos): return ('%s') % (
255 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
241 ax.xaxis.set_major_formatter(FuncFormatter(func))
256 ax.xaxis.set_major_formatter(FuncFormatter(func))
242 ax.xaxis.set_major_locator(LinearLocator(7))
257 ax.xaxis.set_major_locator(LinearLocator(7))
243
258
244 ax.grid(True)
245 matplotlib.pyplot.ion()
259 matplotlib.pyplot.ion()
246 return imesh
260 return imesh
247
261
248 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
249
262
250 z = numpy.ma.masked_invalid(z)
263 def pcolor(imesh, z, xlabel='', ylabel='', title=''):
251
252 cmap=matplotlib.pyplot.get_cmap('jet')
253 cmap.set_bad('white',1.)
254
264
255 z = z.T
265 z = z.T
256 ax = imesh.get_axes()
266 ax = imesh.axes
257 printLabels(ax, xlabel, ylabel, title)
267 printLabels(ax, xlabel, ylabel, title)
258 imesh.set_array(z.ravel())
268 imesh.set_array(z.ravel())
259 ax.grid(True)
260
269
261
270
262 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
271 def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
263
272
264 printLabels(ax, xlabel, ylabel, title)
273 printLabels(ax, xlabel, ylabel, title)
265 z = numpy.ma.masked_invalid(z)
274
266 cmap=matplotlib.pyplot.get_cmap(colormap)
275 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax,
267 cmap.set_bad('white',1.)
276 cmap=matplotlib.pyplot.get_cmap(colormap))
268 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap))
277
269 ax.grid(True)
270
278
271 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
279 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'):
272
280
273 printLabels(ax, xlabel, ylabel, title)
281 printLabels(ax, xlabel, ylabel, title)
274
282
275 ax.collections.remove(ax.collections[0])
283 ax.collections.remove(ax.collections[0])
276
284
277 z = numpy.ma.masked_invalid(z)
285 z = numpy.ma.masked_invalid(z)
278
286
279 cmap=matplotlib.pyplot.get_cmap(colormap)
287 cmap = matplotlib.pyplot.get_cmap(colormap)
280 cmap.set_bad('white',1.)
288 cmap.set_bad('black', 1.)
281
289
282 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
290 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
283 ax.grid(True)
284
291
285
292
286 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
293 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
287 ticksize=9, xtick_visible=True, ytick_visible=True,
294 ticksize=9, xtick_visible=True, ytick_visible=True,
288 nxticks=4, nyticks=10,
295 nxticks=4, nyticks=10,
289 grid=None):
296 grid=None):
290
291 """
297 """
292
298
293 Input:
299 Input:
294 grid : None, 'both', 'x', 'y'
300 grid : None, 'both', 'x', 'y'
295 """
301 """
296
302
297 matplotlib.pyplot.ioff()
303 matplotlib.pyplot.ioff()
298
304
299 lines = ax.plot(x.T, y)
305 lines = ax.plot(x.T, y)
300 leg = ax.legend(lines, legendlabels, loc='upper right')
306 leg = ax.legend(lines, legendlabels, loc='upper right')
301 leg.get_frame().set_alpha(0.5)
307 leg.get_frame().set_alpha(0.5)
302 ax.set_xlim([xmin,xmax])
308 ax.set_xlim([xmin, xmax])
303 ax.set_ylim([ymin,ymax])
309 ax.set_ylim([ymin, ymax])
304 printLabels(ax, xlabel, ylabel, title)
310 printLabels(ax, xlabel, ylabel, title)
305
311
306 xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
312 xtickspos = numpy.arange(nxticks) * \
313 int((xmax - xmin) / (nxticks)) + int(xmin)
307 ax.set_xticks(xtickspos)
314 ax.set_xticks(xtickspos)
308
315
309 for tick in ax.get_xticklabels():
316 for tick in ax.get_xticklabels():
310 tick.set_visible(xtick_visible)
317 tick.set_visible(xtick_visible)
311
318
312 for tick in ax.xaxis.get_major_ticks():
319 for tick in ax.xaxis.get_major_ticks():
313 tick.label.set_fontsize(ticksize)
320 tick.label.set_fontsize(ticksize)
314
321
315 for tick in ax.get_yticklabels():
322 for tick in ax.get_yticklabels():
316 tick.set_visible(ytick_visible)
323 tick.set_visible(ytick_visible)
317
324
318 for tick in ax.yaxis.get_major_ticks():
325 for tick in ax.yaxis.get_major_ticks():
319 tick.label.set_fontsize(ticksize)
326 tick.label.set_fontsize(ticksize)
320
327
321 iplot = ax.lines[-1]
328 iplot = ax.lines[-1]
322
329
323 if '0.' in matplotlib.__version__[0:2]:
330 if '0.' in matplotlib.__version__[0:2]:
324 print "The matplotlib version has to be updated to 1.1 or newer"
331 print "The matplotlib version has to be updated to 1.1 or newer"
325 return iplot
332 return iplot
326
333
327 if '1.0.' in matplotlib.__version__[0:4]:
334 if '1.0.' in matplotlib.__version__[0:4]:
328 print "The matplotlib version has to be updated to 1.1 or newer"
335 print "The matplotlib version has to be updated to 1.1 or newer"
329 return iplot
336 return iplot
330
337
331 if grid != None:
338 if grid != None:
332 ax.grid(b=True, which='major', axis=grid)
339 ax.grid(b=True, which='major', axis=grid)
333
340
334 matplotlib.pyplot.tight_layout()
341 matplotlib.pyplot.tight_layout()
335
342
336 matplotlib.pyplot.ion()
343 matplotlib.pyplot.ion()
337
344
338 return iplot
345 return iplot
339
346
340
347
341 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
348 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
342
349
343 ax = iplot.get_axes()
350 ax = iplot.axes
344
351
345 printLabels(ax, xlabel, ylabel, title)
352 printLabels(ax, xlabel, ylabel, title)
346
353
347 for i in range(len(ax.lines)):
354 for i in range(len(ax.lines)):
348 line = ax.lines[i]
355 line = ax.lines[i]
349 line.set_data(x[i,:],y)
356 line.set_data(x[i, :], y)
350
357
358
351 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
359 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
352 ticksize=9, xtick_visible=True, ytick_visible=True,
360 ticksize=9, xtick_visible=True, ytick_visible=True,
353 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
361 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
354 grid=None, XAxisAsTime=False):
362 grid=None, XAxisAsTime=False):
355
356 """
363 """
357
364
358 Input:
365 Input:
359 grid : None, 'both', 'x', 'y'
366 grid : None, 'both', 'x', 'y'
360 """
367 """
361
368
362 matplotlib.pyplot.ioff()
369 matplotlib.pyplot.ioff()
363
370
364 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
371 # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle)
365 lines = ax.plot(x, y.T)
372 lines = ax.plot(x, y.T)
366 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
373 # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \
367 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
374 # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.)
368
375
369 leg = ax.legend(lines, legendlabels,
376 leg = ax.legend(lines, legendlabels,
370 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
377 loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0)
371
378
372 for label in leg.get_texts(): label.set_fontsize(9)
379 for label in leg.get_texts():
380 label.set_fontsize(9)
373
381
374 ax.set_xlim([xmin,xmax])
382 ax.set_xlim([xmin, xmax])
375 ax.set_ylim([ymin,ymax])
383 ax.set_ylim([ymin, ymax])
376 printLabels(ax, xlabel, ylabel, title)
384 printLabels(ax, xlabel, ylabel, title)
377
385
378 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
386 # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin)
379 # ax.set_xticks(xtickspos)
387 # ax.set_xticks(xtickspos)
380
388
381 for tick in ax.get_xticklabels():
389 for tick in ax.get_xticklabels():
382 tick.set_visible(xtick_visible)
390 tick.set_visible(xtick_visible)
383
391
384 for tick in ax.xaxis.get_major_ticks():
392 for tick in ax.xaxis.get_major_ticks():
385 tick.label.set_fontsize(ticksize)
393 tick.label.set_fontsize(ticksize)
386
394
387 for tick in ax.get_yticklabels():
395 for tick in ax.get_yticklabels():
388 tick.set_visible(ytick_visible)
396 tick.set_visible(ytick_visible)
389
397
390 for tick in ax.yaxis.get_major_ticks():
398 for tick in ax.yaxis.get_major_ticks():
391 tick.label.set_fontsize(ticksize)
399 tick.label.set_fontsize(ticksize)
392
400
393 iplot = ax.lines[-1]
401 iplot = ax.lines[-1]
394
402
395 if '0.' in matplotlib.__version__[0:2]:
403 if '0.' in matplotlib.__version__[0:2]:
396 print "The matplotlib version has to be updated to 1.1 or newer"
404 print "The matplotlib version has to be updated to 1.1 or newer"
397 return iplot
405 return iplot
398
406
399 if '1.0.' in matplotlib.__version__[0:4]:
407 if '1.0.' in matplotlib.__version__[0:4]:
400 print "The matplotlib version has to be updated to 1.1 or newer"
408 print "The matplotlib version has to be updated to 1.1 or newer"
401 return iplot
409 return iplot
402
410
403 if grid != None:
411 if grid != None:
404 ax.grid(b=True, which='major', axis=grid)
412 ax.grid(b=True, which='major', axis=grid)
405
413
406 matplotlib.pyplot.tight_layout()
414 matplotlib.pyplot.tight_layout()
407
415
408 if XAxisAsTime:
416 if XAxisAsTime:
409
417
410 func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
418 def func(x, pos): return ('%s') % (
419 datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S"))
411 ax.xaxis.set_major_formatter(FuncFormatter(func))
420 ax.xaxis.set_major_formatter(FuncFormatter(func))
412 ax.xaxis.set_major_locator(LinearLocator(7))
421 ax.xaxis.set_major_locator(LinearLocator(7))
413
422
414 matplotlib.pyplot.ion()
423 matplotlib.pyplot.ion()
415
424
416 return iplot
425 return iplot
417
426
427
418 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
428 def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''):
419
429
420 ax = iplot.get_axes()
430 ax = iplot.axes
431
421 printLabels(ax, xlabel, ylabel, title)
432 printLabels(ax, xlabel, ylabel, title)
422
433
423 for i in range(len(ax.lines)):
434 for i in range(len(ax.lines)):
424 line = ax.lines[i]
435 line = ax.lines[i]
425 line.set_data(x,y[i,:])
436 line.set_data(x, y[i, :])
426
437
438
427 def createPolar(ax, x, y,
439 def createPolar(ax, x, y,
428 xlabel='', ylabel='', title='', ticksize = 9,
440 xlabel='', ylabel='', title='', ticksize=9,
429 colormap='jet',cblabel='', cbsize="5%",
441 colormap='jet', cblabel='', cbsize="5%",
430 XAxisAsTime=False):
442 XAxisAsTime=False):
431
443
432 matplotlib.pyplot.ioff()
444 matplotlib.pyplot.ioff()
433
445
434 ax.plot(x,y,'bo', markersize=5)
446 ax.plot(x, y, 'bo', markersize=5)
435 # ax.set_rmax(90)
447 # ax.set_rmax(90)
436 ax.set_ylim(0,90)
448 ax.set_ylim(0, 90)
437 ax.set_yticks(numpy.arange(0,90,20))
449 ax.set_yticks(numpy.arange(0, 90, 20))
438 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
450 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11')
439 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
451 # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11')
440 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
452 # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical')
441 ax.yaxis.labelpad = 230
453 ax.yaxis.labelpad = 40
442 printLabels(ax, xlabel, ylabel, title)
454 printLabels(ax, xlabel, ylabel, title)
443 iplot = ax.lines[-1]
455 iplot = ax.lines[-1]
444
456
445 if '0.' in matplotlib.__version__[0:2]:
457 if '0.' in matplotlib.__version__[0:2]:
446 print "The matplotlib version has to be updated to 1.1 or newer"
458 print "The matplotlib version has to be updated to 1.1 or newer"
447 return iplot
459 return iplot
448
460
449 if '1.0.' in matplotlib.__version__[0:4]:
461 if '1.0.' in matplotlib.__version__[0:4]:
450 print "The matplotlib version has to be updated to 1.1 or newer"
462 print "The matplotlib version has to be updated to 1.1 or newer"
451 return iplot
463 return iplot
452
464
453 # if grid != None:
465 # if grid != None:
454 # ax.grid(b=True, which='major', axis=grid)
466 # ax.grid(b=True, which='major', axis=grid)
455
467
456 matplotlib.pyplot.tight_layout()
468 matplotlib.pyplot.tight_layout()
457
469
458 matplotlib.pyplot.ion()
470 matplotlib.pyplot.ion()
459
471
460
461 return iplot
472 return iplot
462
473
474
463 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
475 def polar(iplot, x, y, xlabel='', ylabel='', title=''):
464
476
465 ax = iplot.get_axes()
477 ax = iplot.axes
466
478
467 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
479 # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11')
468 printLabels(ax, xlabel, ylabel, title)
480 printLabels(ax, xlabel, ylabel, title)
469
481
470 set_linedata(ax, x, y, idline=0)
482 set_linedata(ax, x, y, idline=0)
471
483
484
472 def draw(fig):
485 def draw(fig):
473
486
474 if type(fig) == 'int':
487 if type(fig) == 'int':
475 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
488 raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure"
476
489
477 fig.canvas.draw()
490 fig.canvas.draw()
478
491
492
479 def pause(interval=0.000001):
493 def pause(interval=0.000001):
480
494
481 matplotlib.pyplot.pause(interval)
495 matplotlib.pyplot.pause(interval)
@@ -1,321 +1,331
1 import os, sys
1 import os
2 import sys
2 import glob
3 import glob
3 import fnmatch
4 import fnmatch
4 import datetime
5 import datetime
5 import time
6 import time
6 import re
7 import re
7 import h5py
8 import h5py
8 import numpy
9 import numpy
9 import matplotlib.pyplot as plt
10
10
11 import pylab as plb
12 from scipy.optimize import curve_fit
11 from scipy.optimize import curve_fit
13 from scipy import asarray as ar,exp
12 from scipy import asarray as ar, exp
14 from scipy import stats
13 from scipy import stats
15
14
16 from duplicity.path import Path
15 from duplicity.path import Path
17 from numpy.ma.core import getdata
16 from numpy.ma.core import getdata
18
17
19 SPEED_OF_LIGHT = 299792458
18 SPEED_OF_LIGHT = 299792458
20 SPEED_OF_LIGHT = 3e8
19 SPEED_OF_LIGHT = 3e8
21
20
22 try:
21 try:
23 from gevent import sleep
22 from gevent import sleep
24 except:
23 except:
25 from time import sleep
24 from time import sleep
26
25
27 from schainpy.model.data.jrodata import Spectra
26 from schainpy.model.data.jrodata import Spectra
28 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
29 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
30 #from schainpy.model.io.jroIO_bltr import BLTRReader
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
31 from numpy import imag, shape, NaN
30 from numpy import imag, shape, NaN
32
31
33
32
34 startFp = open('/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc',"rb")
33 startFp = open(
34 '/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc', "rb")
35
35
36
36
37 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
37 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
38 ('Hname',numpy.str_,32), #Original file name
38 ('Hname', numpy.str_, 32), # Original file name
39 ('Htime',numpy.str_,32), #Date and time when the file was created
39 # Date and time when the file was created
40 ('Hoper',numpy.str_,64), #Name of operator who created the file
40 ('Htime', numpy.str_, 32),
41 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
41 # Name of operator who created the file
42 ('Hdescr',numpy.str_,256), #Description of measurements
42 ('Hoper', numpy.str_, 64),
43 # Place where the measurements was carried out
44 ('Hplace', numpy.str_, 128),
45 # Description of measurements
46 ('Hdescr', numpy.str_, 256),
43 ('Hdummy',numpy.str_,512), #Reserved space
47 ('Hdummy', numpy.str_, 512), # Reserved space
44 #Main chunk
48 # Main chunk
45 ('Msign','<i4'), #Main chunk signature FZKF or NUIG
49 ('Msign', '<i4'), # Main chunk signature FZKF or NUIG
46 ('MsizeData','<i4'), #Size of data block main chunk
50 ('MsizeData', '<i4'), # Size of data block main chunk
47 #Processing DSP parameters
51 # Processing DSP parameters
48 ('PPARsign','<i4'), #PPAR signature
52 ('PPARsign', '<i4'), # PPAR signature
49 ('PPARsize','<i4'), #PPAR size of block
53 ('PPARsize', '<i4'), # PPAR size of block
50 ('PPARprf','<i4'), #Pulse repetition frequency
54 ('PPARprf', '<i4'), # Pulse repetition frequency
51 ('PPARpdr','<i4'), #Pulse duration
55 ('PPARpdr', '<i4'), # Pulse duration
52 ('PPARsft','<i4'), #FFT length
56 ('PPARsft', '<i4'), # FFT length
53 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
57 # Number of spectral (in-coherent) averages
54 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
58 ('PPARavc', '<i4'),
55 ('PPARchg','<i4'), #Count for gates for moment estimation
59 # Number of lowest range gate for moment estimation
56 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
60 ('PPARihp', '<i4'),
61 # Count for gates for moment estimation
62 ('PPARchg', '<i4'),
63 # switch on/off polarimetric measurements. Should be 1.
64 ('PPARpol', '<i4'),
57 #Service DSP parameters
65 # Service DSP parameters
58 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
66 # STC attenuation on the lowest ranges on/off
67 ('SPARatt', '<i4'),
59 ('SPARtx','<i4'), #OBSOLETE
68 ('SPARtx', '<i4'), # OBSOLETE
60 ('SPARaddGain0','<f4'), #OBSOLETE
69 ('SPARaddGain0', '<f4'), # OBSOLETE
61 ('SPARaddGain1','<f4'), #OBSOLETE
70 ('SPARaddGain1', '<f4'), # OBSOLETE
62 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
71 # Debug only. It normal mode it is 0.
63 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
72 ('SPARwnd', '<i4'),
64 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
73 # Delay between sync pulse and tx pulse for phase corr, ns
65 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
74 ('SPARpos', '<i4'),
75 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
76 ('SPARadd', '<i4'),
77 # Time for measuring txn pulse phase. OBSOLETE
78 ('SPARlen', '<i4'),
66 ('SPARcal','<i4'), #OBSOLETE
79 ('SPARcal', '<i4'), # OBSOLETE
67 ('SPARnos','<i4'), #OBSOLETE
80 ('SPARnos', '<i4'), # OBSOLETE
68 ('SPARof0','<i4'), #detection threshold
81 ('SPARof0', '<i4'), # detection threshold
69 ('SPARof1','<i4'), #OBSOLETE
82 ('SPARof1', '<i4'), # OBSOLETE
70 ('SPARswt','<i4'), #2nd moment estimation threshold
83 ('SPARswt', '<i4'), # 2nd moment estimation threshold
71 ('SPARsum','<i4'), #OBSOLETE
84 ('SPARsum', '<i4'), # OBSOLETE
72 ('SPARosc','<i4'), #flag Oscillosgram mode
85 ('SPARosc', '<i4'), # flag Oscillosgram mode
73 ('SPARtst','<i4'), #OBSOLETE
86 ('SPARtst', '<i4'), # OBSOLETE
74 ('SPARcor','<i4'), #OBSOLETE
87 ('SPARcor', '<i4'), # OBSOLETE
75 ('SPARofs','<i4'), #OBSOLETE
88 ('SPARofs', '<i4'), # OBSOLETE
76 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
89 # Hildebrand div noise detection on noise gate
77 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
90 ('SPARhsn', '<i4'),
91 # Hildebrand div noise detection on all gates
92 ('SPARhsa', '<f4'),
78 ('SPARcalibPow_M','<f4'), #OBSOLETE
93 ('SPARcalibPow_M', '<f4'), # OBSOLETE
79 ('SPARcalibSNR_M','<f4'), #OBSOLETE
94 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
80 ('SPARcalibPow_S','<f4'), #OBSOLETE
95 ('SPARcalibPow_S', '<f4'), # OBSOLETE
81 ('SPARcalibSNR_S','<f4'), #OBSOLETE
96 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
82 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
97 # Lowest range gate for spectra saving Raw_Gate1 >=5
83 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
98 ('SPARrawGate1', '<i4'),
84 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
99 # Number of range gates with atmospheric signal
100 ('SPARrawGate2', '<i4'),
101 # flag - IQ or spectra saving on/off
102 ('SPARraw', '<i4'),
85 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
103 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
86
104
87
105
88
89 self.Hname= None
106 self.Hname = None
90 self.Htime= None
107 self.Htime = None
91 self.Hoper= None
108 self.Hoper = None
92 self.Hplace= None
109 self.Hplace = None
93 self.Hdescr= None
110 self.Hdescr = None
94 self.Hdummy= None
111 self.Hdummy = None
95
112
96 self.Msign=None
113 self.Msign = None
97 self.MsizeData=None
114 self.MsizeData = None
98
115
99 self.PPARsign=None
116 self.PPARsign = None
100 self.PPARsize=None
117 self.PPARsize = None
101 self.PPARprf=None
118 self.PPARprf = None
102 self.PPARpdr=None
119 self.PPARpdr = None
103 self.PPARsft=None
120 self.PPARsft = None
104 self.PPARavc=None
121 self.PPARavc = None
105 self.PPARihp=None
122 self.PPARihp = None
106 self.PPARchg=None
123 self.PPARchg = None
107 self.PPARpol=None
124 self.PPARpol = None
108 #Service DSP parameters
125 # Service DSP parameters
109 self.SPARatt=None
126 self.SPARatt = None
110 self.SPARtx=None
127 self.SPARtx = None
111 self.SPARaddGain0=None
128 self.SPARaddGain0 = None
112 self.SPARaddGain1=None
129 self.SPARaddGain1 = None
113 self.SPARwnd=None
130 self.SPARwnd = None
114 self.SPARpos=None
131 self.SPARpos = None
115 self.SPARadd=None
132 self.SPARadd = None
116 self.SPARlen=None
133 self.SPARlen = None
117 self.SPARcal=None
134 self.SPARcal = None
118 self.SPARnos=None
135 self.SPARnos = None
119 self.SPARof0=None
136 self.SPARof0 = None
120 self.SPARof1=None
137 self.SPARof1 = None
121 self.SPARswt=None
138 self.SPARswt = None
122 self.SPARsum=None
139 self.SPARsum = None
123 self.SPARosc=None
140 self.SPARosc = None
124 self.SPARtst=None
141 self.SPARtst = None
125 self.SPARcor=None
142 self.SPARcor = None
126 self.SPARofs=None
143 self.SPARofs = None
127 self.SPARhsn=None
144 self.SPARhsn = None
128 self.SPARhsa=None
145 self.SPARhsa = None
129 self.SPARcalibPow_M=None
146 self.SPARcalibPow_M = None
130 self.SPARcalibSNR_M=None
147 self.SPARcalibSNR_M = None
131 self.SPARcalibPow_S=None
148 self.SPARcalibPow_S = None
132 self.SPARcalibSNR_S=None
149 self.SPARcalibSNR_S = None
133 self.SPARrawGate1=None
150 self.SPARrawGate1 = None
134 self.SPARrawGate2=None
151 self.SPARrawGate2 = None
135 self.SPARraw=None
152 self.SPARraw = None
136 self.SPARprc=None
153 self.SPARprc = None
137
154
138
155
139
140 header = numpy.fromfile(fp, FILE_HEADER,1)
156 header = numpy.fromfile(fp, FILE_HEADER, 1)
141 ''' numpy.fromfile(file, dtype, count, sep='')
157 ''' numpy.fromfile(file, dtype, count, sep='')
142 file : file or str
158 file : file or str
143 Open file object or filename.
159 Open file object or filename.
144
160
145 dtype : data-type
161 dtype : data-type
146 Data type of the returned array. For binary files, it is used to determine
162 Data type of the returned array. For binary files, it is used to determine
147 the size and byte-order of the items in the file.
163 the size and byte-order of the items in the file.
148
164
149 count : int
165 count : int
150 Number of items to read. -1 means all items (i.e., the complete file).
166 Number of items to read. -1 means all items (i.e., the complete file).
151
167
152 sep : str
168 sep : str
153 Separator between items if file is a text file. Empty ("") separator means
169 Separator between items if file is a text file. Empty ("") separator means
154 the file should be treated as binary. Spaces (" ") in the separator match zero
170 the file should be treated as binary. Spaces (" ") in the separator match zero
155 or more whitespace characters. A separator consisting only of spaces must match
171 or more whitespace characters. A separator consisting only of spaces must match
156 at least one whitespace.
172 at least one whitespace.
157
173
158 '''
174 '''
159
175
160 Hname= str(header['Hname'][0])
176 Hname = str(header['Hname'][0])
161 Htime= str(header['Htime'][0])
177 Htime = str(header['Htime'][0])
162 Hoper= str(header['Hoper'][0])
178 Hoper = str(header['Hoper'][0])
163 Hplace= str(header['Hplace'][0])
179 Hplace = str(header['Hplace'][0])
164 Hdescr= str(header['Hdescr'][0])
180 Hdescr = str(header['Hdescr'][0])
165 Hdummy= str(header['Hdummy'][0])
181 Hdummy = str(header['Hdummy'][0])
166
182
167 Msign=header['Msign'][0]
183 Msign = header['Msign'][0]
168 MsizeData=header['MsizeData'][0]
184 MsizeData = header['MsizeData'][0]
169
185
170 PPARsign=header['PPARsign'][0]
186 PPARsign = header['PPARsign'][0]
171 PPARsize=header['PPARsize'][0]
187 PPARsize = header['PPARsize'][0]
172 PPARprf=header['PPARprf'][0]
188 PPARprf = header['PPARprf'][0]
173 PPARpdr=header['PPARpdr'][0]
189 PPARpdr = header['PPARpdr'][0]
174 PPARsft=header['PPARsft'][0]
190 PPARsft = header['PPARsft'][0]
175 PPARavc=header['PPARavc'][0]
191 PPARavc = header['PPARavc'][0]
176 PPARihp=header['PPARihp'][0]
192 PPARihp = header['PPARihp'][0]
177 PPARchg=header['PPARchg'][0]
193 PPARchg = header['PPARchg'][0]
178 PPARpol=header['PPARpol'][0]
194 PPARpol = header['PPARpol'][0]
179 #Service DSP parameters
195 # Service DSP parameters
180 SPARatt=header['SPARatt'][0]
196 SPARatt = header['SPARatt'][0]
181 SPARtx=header['SPARtx'][0]
197 SPARtx = header['SPARtx'][0]
182 SPARaddGain0=header['SPARaddGain0'][0]
198 SPARaddGain0 = header['SPARaddGain0'][0]
183 SPARaddGain1=header['SPARaddGain1'][0]
199 SPARaddGain1 = header['SPARaddGain1'][0]
184 SPARwnd=header['SPARwnd'][0]
200 SPARwnd = header['SPARwnd'][0]
185 SPARpos=header['SPARpos'][0]
201 SPARpos = header['SPARpos'][0]
186 SPARadd=header['SPARadd'][0]
202 SPARadd = header['SPARadd'][0]
187 SPARlen=header['SPARlen'][0]
203 SPARlen = header['SPARlen'][0]
188 SPARcal=header['SPARcal'][0]
204 SPARcal = header['SPARcal'][0]
189 SPARnos=header['SPARnos'][0]
205 SPARnos = header['SPARnos'][0]
190 SPARof0=header['SPARof0'][0]
206 SPARof0 = header['SPARof0'][0]
191 SPARof1=header['SPARof1'][0]
207 SPARof1 = header['SPARof1'][0]
192 SPARswt=header['SPARswt'][0]
208 SPARswt = header['SPARswt'][0]
193 SPARsum=header['SPARsum'][0]
209 SPARsum = header['SPARsum'][0]
194 SPARosc=header['SPARosc'][0]
210 SPARosc = header['SPARosc'][0]
195 SPARtst=header['SPARtst'][0]
211 SPARtst = header['SPARtst'][0]
196 SPARcor=header['SPARcor'][0]
212 SPARcor = header['SPARcor'][0]
197 SPARofs=header['SPARofs'][0]
213 SPARofs = header['SPARofs'][0]
198 SPARhsn=header['SPARhsn'][0]
214 SPARhsn = header['SPARhsn'][0]
199 SPARhsa=header['SPARhsa'][0]
215 SPARhsa = header['SPARhsa'][0]
200 SPARcalibPow_M=header['SPARcalibPow_M'][0]
216 SPARcalibPow_M = header['SPARcalibPow_M'][0]
201 SPARcalibSNR_M=header['SPARcalibSNR_M'][0]
217 SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
202 SPARcalibPow_S=header['SPARcalibPow_S'][0]
218 SPARcalibPow_S = header['SPARcalibPow_S'][0]
203 SPARcalibSNR_S=header['SPARcalibSNR_S'][0]
219 SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
204 SPARrawGate1=header['SPARrawGate1'][0]
220 SPARrawGate1 = header['SPARrawGate1'][0]
205 SPARrawGate2=header['SPARrawGate2'][0]
221 SPARrawGate2 = header['SPARrawGate2'][0]
206 SPARraw=header['SPARraw'][0]
222 SPARraw = header['SPARraw'][0]
207 SPARprc=header['SPARprc'][0]
223 SPARprc = header['SPARprc'][0]
208
224
209
225
210
211 SRVI_STRUCTURE = numpy.dtype([
226 SRVI_STRUCTURE = numpy.dtype([
212 ('frame_cnt','<u4'),#
227 ('frame_cnt', '<u4'),
213 ('time_t','<u4'), #
228 ('time_t', '<u4'), #
214 ('tpow','<f4'), #
229 ('tpow', '<f4'), #
215 ('npw1','<f4'), #
230 ('npw1', '<f4'), #
216 ('npw2','<f4'), #
231 ('npw2', '<f4'), #
217 ('cpw1','<f4'), #
232 ('cpw1', '<f4'), #
218 ('pcw2','<f4'), #
233 ('pcw2', '<f4'), #
219 ('ps_err','<u4'), #
234 ('ps_err', '<u4'), #
220 ('te_err','<u4'), #
235 ('te_err', '<u4'), #
221 ('rc_err','<u4'), #
236 ('rc_err', '<u4'), #
222 ('grs1','<u4'), #
237 ('grs1', '<u4'), #
223 ('grs2','<u4'), #
238 ('grs2', '<u4'), #
224 ('azipos','<f4'), #
239 ('azipos', '<f4'), #
225 ('azivel','<f4'), #
240 ('azivel', '<f4'), #
226 ('elvpos','<f4'), #
241 ('elvpos', '<f4'), #
227 ('elvvel','<f4'), #
242 ('elvvel', '<f4'), #
228 ('northAngle','<f4'), #
243 ('northAngle', '<f4'),
229 ('microsec','<u4'), #
244 ('microsec', '<u4'), #
230 ('azisetvel','<f4'), #
245 ('azisetvel', '<f4'), #
231 ('elvsetpos','<f4'), #
246 ('elvsetpos', '<f4'), #
232 ('RadarConst','<f4'),]) #
247 ('RadarConst', '<f4'), ]) #
233
248
234 JUMP_STRUCTURE = numpy.dtype([
249 JUMP_STRUCTURE = numpy.dtype([
235 ('jump','<u140'),#
250 ('jump', '<u140'),
236 ('SizeOfDataBlock1',numpy.str_,32),#
251 ('SizeOfDataBlock1', numpy.str_, 32),
237 ('jump','<i4'),#
252 ('jump', '<i4'),
238 ('DataBlockTitleSRVI1',numpy.str_,32),#
253 ('DataBlockTitleSRVI1', numpy.str_, 32),
239 ('SizeOfSRVI1','<i4'),])#
254 ('SizeOfSRVI1', '<i4'), ])
240
241
255
242
256
243 #frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
257 # frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
244 #cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
258 # cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
245 #grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
259 # grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
246 #microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
260 # microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
247
261
248
262
249 frame_cnt = frame_cnt
263 frame_cnt = frame_cnt
250 dwell = time_t
264 dwell = time_t
251 tpow = tpow
265 tpow = tpow
252 npw1 = npw1
266 npw1 = npw1
253 npw2 = npw2
267 npw2 = npw2
254 cpw1 = cpw1
268 cpw1 = cpw1
255 pcw2 = pcw2
269 pcw2 = pcw2
256 ps_err = ps_err
270 ps_err = ps_err
257 te_err = te_err
271 te_err = te_err
258 rc_err = rc_err
272 rc_err = rc_err
259 grs1 = grs1
273 grs1 = grs1
260 grs2 = grs2
274 grs2 = grs2
261 azipos = azipos
275 azipos = azipos
262 azivel = azivel
276 azivel = azivel
263 elvpos = elvpos
277 elvpos = elvpos
264 elvvel = elvvel
278 elvvel = elvvel
265 northAngle = northAngle
279 northAngle = northAngle
266 microsec = microsec
280 microsec = microsec
267 azisetvel = azisetvel
281 azisetvel = azisetvel
268 elvsetpos = elvsetpos
282 elvsetpos = elvsetpos
269 RadarConst5 = RadarConst
283 RadarConst5 = RadarConst
270
284
271
285
272
273 #print fp
286 # print fp
274 #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
287 # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
275 #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
288 # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
276 #RecCounter=0
289 # RecCounter=0
277 #Off2StartNxtRec=811248
290 # Off2StartNxtRec=811248
278 #print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec
291 # print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec
279 #OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
292 #OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
280 #startFp.seek(OffRHeader, os.SEEK_SET)
293 #startFp.seek(OffRHeader, os.SEEK_SET)
281 print 'debe ser 48, RecCounter*811248', self.OffsetStartHeader,self.RecCounter,self.Off2StartNxtRec
294 print 'debe ser 48, RecCounter*811248', self.OffsetStartHeader, self.RecCounter, self.Off2StartNxtRec
282 print 'Posicion del bloque: ',OffRHeader
295 print 'Posicion del bloque: ', OffRHeader
283
296
284 header = numpy.fromfile(startFp,SRVI_STRUCTURE,1)
297 header = numpy.fromfile(startFp, SRVI_STRUCTURE, 1)
285
298
286 self.frame_cnt = header['frame_cnt'][0]#
299 self.frame_cnt = header['frame_cnt'][0]
287 self.time_t = header['frame_cnt'][0] #
300 self.time_t = header['frame_cnt'][0] #
288 self.tpow = header['frame_cnt'][0] #
301 self.tpow = header['frame_cnt'][0] #
289 self.npw1 = header['frame_cnt'][0] #
302 self.npw1 = header['frame_cnt'][0] #
290 self.npw2 = header['frame_cnt'][0] #
303 self.npw2 = header['frame_cnt'][0] #
291 self.cpw1 = header['frame_cnt'][0] #
304 self.cpw1 = header['frame_cnt'][0] #
292 self.pcw2 = header['frame_cnt'][0] #
305 self.pcw2 = header['frame_cnt'][0] #
293 self.ps_err = header['frame_cnt'][0] #
306 self.ps_err = header['frame_cnt'][0] #
294 self.te_err = header['frame_cnt'][0] #
307 self.te_err = header['frame_cnt'][0] #
295 self.rc_err = header['frame_cnt'][0] #
308 self.rc_err = header['frame_cnt'][0] #
296 self.grs1 = header['frame_cnt'][0] #
309 self.grs1 = header['frame_cnt'][0] #
297 self.grs2 = header['frame_cnt'][0] #
310 self.grs2 = header['frame_cnt'][0] #
298 self.azipos = header['frame_cnt'][0] #
311 self.azipos = header['frame_cnt'][0] #
299 self.azivel = header['frame_cnt'][0] #
312 self.azivel = header['frame_cnt'][0] #
300 self.elvpos = header['frame_cnt'][0] #
313 self.elvpos = header['frame_cnt'][0] #
301 self.elvvel = header['frame_cnt'][0] #
314 self.elvvel = header['frame_cnt'][0] #
302 self.northAngle = header['frame_cnt'][0] #
315 self.northAngle = header['frame_cnt'][0] #
303 self.microsec = header['frame_cnt'][0] #
316 self.microsec = header['frame_cnt'][0] #
304 self.azisetvel = header['frame_cnt'][0] #
317 self.azisetvel = header['frame_cnt'][0] #
305 self.elvsetpos = header['frame_cnt'][0] #
318 self.elvsetpos = header['frame_cnt'][0] #
306 self.RadarConst = header['frame_cnt'][0] #
319 self.RadarConst = header['frame_cnt'][0] #
307
320
308
321
309 self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
322 self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz)
310
323
311 self.RHsize = 180+20*self.nChannels
324 self.RHsize = 180 + 20 * self.nChannels
312 self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
325 self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4
313 #print 'Datasize',self.Datasize
326 # print 'Datasize',self.Datasize
314 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
327 endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
315
328
316 print '=============================================='
329 print '=============================================='
317
330
318 print '=============================================='
331 print '=============================================='
319
320
321 No newline at end of file
@@ -1,20 +1,20
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
5 '''
5 '''
6
6
7 from jroIO_voltage import *
7 from jroIO_voltage import *
8 from jroIO_spectra import *
8 from jroIO_spectra import *
9 from jroIO_heispectra import *
9 from jroIO_heispectra import *
10 from jroIO_usrp import *
10 from jroIO_usrp import *
11
11 from jroIO_digitalRF import *
12 from jroIO_kamisr import *
12 from jroIO_kamisr import *
13 from jroIO_param import *
13 from jroIO_param import *
14 from jroIO_hf import *
14 from jroIO_hf import *
15
15
16 from jroIO_madrigal import *
16 from jroIO_madrigal import *
17
17
18 from bltrIO_param import *
18 from bltrIO_param import *
19 from jroIO_bltr import *
19 from jroIO_bltr import *
20 from jroIO_mira35c import *
20 from jroIO_mira35c import *
@@ -1,366 +1,369
1 '''
1 '''
2 Created on Nov 9, 2016
2 Created on Nov 9, 2016
3
3
4 @author: roj- LouVD
4 @author: roj- LouVD
5 '''
5 '''
6
6
7
7
8 import os
8 import os
9 import sys
9 import sys
10 import time
10 import time
11 import glob
11 import glob
12 import datetime
12 import datetime
13
13
14 import numpy
14 import numpy
15
15
16 from schainpy.model.proc.jroproc_base import ProcessingUnit
16 from schainpy.model.proc.jroproc_base import ProcessingUnit
17 from schainpy.model.data.jrodata import Parameters
17 from schainpy.model.data.jrodata import Parameters
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
18 from schainpy.model.io.jroIO_base import JRODataReader, isNumber
19 from schainpy.utils import log
19 from schainpy.utils import log
20
20
21 FILE_HEADER_STRUCTURE = numpy.dtype([
21 FILE_HEADER_STRUCTURE = numpy.dtype([
22 ('FMN', '<u4'),
22 ('FMN', '<u4'),
23 ('nrec', '<u4'),
23 ('nrec', '<u4'),
24 ('fr_offset', '<u4'),
24 ('fr_offset', '<u4'),
25 ('id', '<u4'),
25 ('id', '<u4'),
26 ('site', 'u1', (32,))
26 ('site', 'u1', (32,))
27 ])
27 ])
28
28
29 REC_HEADER_STRUCTURE = numpy.dtype([
29 REC_HEADER_STRUCTURE = numpy.dtype([
30 ('rmn', '<u4'),
30 ('rmn', '<u4'),
31 ('rcounter', '<u4'),
31 ('rcounter', '<u4'),
32 ('nr_offset', '<u4'),
32 ('nr_offset', '<u4'),
33 ('tr_offset', '<u4'),
33 ('tr_offset', '<u4'),
34 ('time', '<u4'),
34 ('time', '<u4'),
35 ('time_msec', '<u4'),
35 ('time_msec', '<u4'),
36 ('tag', 'u1', (32,)),
36 ('tag', 'u1', (32,)),
37 ('comments', 'u1', (32,)),
37 ('comments', 'u1', (32,)),
38 ('lat', '<f4'),
38 ('lat', '<f4'),
39 ('lon', '<f4'),
39 ('lon', '<f4'),
40 ('gps_status', '<u4'),
40 ('gps_status', '<u4'),
41 ('freq', '<u4'),
41 ('freq', '<u4'),
42 ('freq0', '<u4'),
42 ('freq0', '<u4'),
43 ('nchan', '<u4'),
43 ('nchan', '<u4'),
44 ('delta_r', '<u4'),
44 ('delta_r', '<u4'),
45 ('nranges', '<u4'),
45 ('nranges', '<u4'),
46 ('r0', '<u4'),
46 ('r0', '<u4'),
47 ('prf', '<u4'),
47 ('prf', '<u4'),
48 ('ncoh', '<u4'),
48 ('ncoh', '<u4'),
49 ('npoints', '<u4'),
49 ('npoints', '<u4'),
50 ('polarization', '<i4'),
50 ('polarization', '<i4'),
51 ('rx_filter', '<u4'),
51 ('rx_filter', '<u4'),
52 ('nmodes', '<u4'),
52 ('nmodes', '<u4'),
53 ('dmode_index', '<u4'),
53 ('dmode_index', '<u4'),
54 ('dmode_rngcorr', '<u4'),
54 ('dmode_rngcorr', '<u4'),
55 ('nrxs', '<u4'),
55 ('nrxs', '<u4'),
56 ('acf_length', '<u4'),
56 ('acf_length', '<u4'),
57 ('acf_lags', '<u4'),
57 ('acf_lags', '<u4'),
58 ('sea_to_atmos', '<f4'),
58 ('sea_to_atmos', '<f4'),
59 ('sea_notch', '<u4'),
59 ('sea_notch', '<u4'),
60 ('lh_sea', '<u4'),
60 ('lh_sea', '<u4'),
61 ('hh_sea', '<u4'),
61 ('hh_sea', '<u4'),
62 ('nbins_sea', '<u4'),
62 ('nbins_sea', '<u4'),
63 ('min_snr', '<f4'),
63 ('min_snr', '<f4'),
64 ('min_cc', '<f4'),
64 ('min_cc', '<f4'),
65 ('max_time_diff', '<f4')
65 ('max_time_diff', '<f4')
66 ])
66 ])
67
67
68 DATA_STRUCTURE = numpy.dtype([
68 DATA_STRUCTURE = numpy.dtype([
69 ('range', '<u4'),
69 ('range', '<u4'),
70 ('status', '<u4'),
70 ('status', '<u4'),
71 ('zonal', '<f4'),
71 ('zonal', '<f4'),
72 ('meridional', '<f4'),
72 ('meridional', '<f4'),
73 ('vertical', '<f4'),
73 ('vertical', '<f4'),
74 ('zonal_a', '<f4'),
74 ('zonal_a', '<f4'),
75 ('meridional_a', '<f4'),
75 ('meridional_a', '<f4'),
76 ('corrected_fading', '<f4'), # seconds
76 ('corrected_fading', '<f4'), # seconds
77 ('uncorrected_fading', '<f4'), # seconds
77 ('uncorrected_fading', '<f4'), # seconds
78 ('time_diff', '<f4'),
78 ('time_diff', '<f4'),
79 ('major_axis', '<f4'),
79 ('major_axis', '<f4'),
80 ('axial_ratio', '<f4'),
80 ('axial_ratio', '<f4'),
81 ('orientation', '<f4'),
81 ('orientation', '<f4'),
82 ('sea_power', '<u4'),
82 ('sea_power', '<u4'),
83 ('sea_algorithm', '<u4')
83 ('sea_algorithm', '<u4')
84 ])
84 ])
85
85
86
86 class BLTRParamReader(JRODataReader, ProcessingUnit):
87 class BLTRParamReader(JRODataReader, ProcessingUnit):
87 '''
88 '''
88 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
89 Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files
89 '''
90 '''
90
91
91 ext = '.sswma'
92 ext = '.sswma'
92
93
93 def __init__(self, **kwargs):
94 def __init__(self, **kwargs):
94
95
95 ProcessingUnit.__init__(self , **kwargs)
96 ProcessingUnit.__init__(self, **kwargs)
96
97
97 self.dataOut = Parameters()
98 self.dataOut = Parameters()
98 self.counter_records = 0
99 self.counter_records = 0
99 self.flagNoMoreFiles = 0
100 self.flagNoMoreFiles = 0
100 self.isConfig = False
101 self.isConfig = False
101 self.filename = None
102 self.filename = None
102
103
103 def setup(self,
104 def setup(self,
104 path=None,
105 path=None,
105 startDate=None,
106 startDate=None,
106 endDate=None,
107 endDate=None,
107 ext=None,
108 ext=None,
108 startTime=datetime.time(0, 0, 0),
109 startTime=datetime.time(0, 0, 0),
109 endTime=datetime.time(23, 59, 59),
110 endTime=datetime.time(23, 59, 59),
110 timezone=0,
111 timezone=0,
111 status_value=0,
112 status_value=0,
112 **kwargs):
113 **kwargs):
113
114
114 self.path = path
115 self.path = path
115 self.startDate = startDate
116 self.startDate = startDate
116 self.endDate = endDate
117 self.endDate = endDate
117 self.startTime = startTime
118 self.startTime = startTime
118 self.endTime = endTime
119 self.endTime = endTime
119 self.status_value = status_value
120 self.status_value = status_value
120 self.datatime = datetime.datetime(1900,1,1)
121 self.datatime = datetime.datetime(1900,1,1)
121
122
122 if self.path is None:
123 if self.path is None:
123 raise ValueError, "The path is not valid"
124 raise ValueError, "The path is not valid"
124
125
125 if ext is None:
126 if ext is None:
126 ext = self.ext
127 ext = self.ext
127
128
128 self.search_files(self.path, startDate, endDate, ext)
129 self.search_files(self.path, startDate, endDate, ext)
129 self.timezone = timezone
130 self.timezone = timezone
130 self.fileIndex = 0
131 self.fileIndex = 0
131
132
132 if not self.fileList:
133 if not self.fileList:
133 raise Warning, "There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' "%(path)
134 raise Warning, "There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % (
135 path)
134
136
135 self.setNextFile()
137 self.setNextFile()
136
138
137 def search_files(self, path, startDate, endDate, ext):
139 def search_files(self, path, startDate, endDate, ext):
138 '''
140 '''
139 Searching for BLTR rawdata file in path
141 Searching for BLTR rawdata file in path
140 Creating a list of file to proces included in [startDate,endDate]
142 Creating a list of file to proces included in [startDate,endDate]
141
143
142 Input:
144 Input:
143 path - Path to find BLTR rawdata files
145 path - Path to find BLTR rawdata files
144 startDate - Select file from this date
146 startDate - Select file from this date
145 enDate - Select file until this date
147 enDate - Select file until this date
146 ext - Extension of the file to read
148 ext - Extension of the file to read
147
148 '''
149 '''
149
150
150 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
151 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
151 foldercounter = 0
152 foldercounter = 0
152 fileList0 = glob.glob1(path, "*%s" % ext)
153 fileList0 = glob.glob1(path, "*%s" % ext)
153 fileList0.sort()
154 fileList0.sort()
154
155
155 self.fileList = []
156 self.fileList = []
156 self.dateFileList = []
157 self.dateFileList = []
157
158
158 for thisFile in fileList0:
159 for thisFile in fileList0:
159 year = thisFile[-14:-10]
160 year = thisFile[-14:-10]
160 if not isNumber(year):
161 if not isNumber(year):
161 continue
162 continue
162
163
163 month = thisFile[-10:-8]
164 month = thisFile[-10:-8]
164 if not isNumber(month):
165 if not isNumber(month):
165 continue
166 continue
166
167
167 day = thisFile[-8:-6]
168 day = thisFile[-8:-6]
168 if not isNumber(day):
169 if not isNumber(day):
169 continue
170 continue
170
171
171 year, month, day = int(year), int(month), int(day)
172 year, month, day = int(year), int(month), int(day)
172 dateFile = datetime.date(year, month, day)
173 dateFile = datetime.date(year, month, day)
173
174
174 if (startDate > dateFile) or (endDate < dateFile):
175 if (startDate > dateFile) or (endDate < dateFile):
175 continue
176 continue
176
177
177 self.fileList.append(thisFile)
178 self.fileList.append(thisFile)
178 self.dateFileList.append(dateFile)
179 self.dateFileList.append(dateFile)
179
180
180 return
181 return
181
182
182 def setNextFile(self):
183 def setNextFile(self):
183
184
184 file_id = self.fileIndex
185 file_id = self.fileIndex
185
186
186 if file_id == len(self.fileList):
187 if file_id == len(self.fileList):
187 log.success('No more files in the folder', 'BLTRParamReader')
188 log.success('No more files in the folder', 'BLTRParamReader')
188 self.flagNoMoreFiles = 1
189 self.flagNoMoreFiles = 1
189 return 0
190 return 0
190
191
191 log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader')
192 log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader')
192 filename = os.path.join(self.path, self.fileList[file_id])
193 filename = os.path.join(self.path, self.fileList[file_id])
193
194
194 dirname, name = os.path.split(filename)
195 dirname, name = os.path.split(filename)
195 self.siteFile = name.split('.')[0] # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
196 # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya
197 self.siteFile = name.split('.')[0]
196 if self.filename is not None:
198 if self.filename is not None:
197 self.fp.close()
199 self.fp.close()
198 self.filename = filename
200 self.filename = filename
199 self.fp = open(self.filename, 'rb')
201 self.fp = open(self.filename, 'rb')
200 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
202 self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1)
201 self.nrecords = self.header_file['nrec'][0]
203 self.nrecords = self.header_file['nrec'][0]
202 self.sizeOfFile = os.path.getsize(self.filename)
204 self.sizeOfFile = os.path.getsize(self.filename)
203 self.counter_records = 0
205 self.counter_records = 0
204 self.flagIsNewFile = 0
206 self.flagIsNewFile = 0
205 self.fileIndex += 1
207 self.fileIndex += 1
206
208
207 return 1
209 return 1
208
210
209 def readNextBlock(self):
211 def readNextBlock(self):
210
212
211 while True:
213 while True:
212 if self.counter_records == self.nrecords:
214 if self.counter_records == self.nrecords:
213 self.flagIsNewFile = 1
215 self.flagIsNewFile = 1
214 if not self.setNextFile():
216 if not self.setNextFile():
215 return 0
217 return 0
216
218
217 self.readBlock()
219 self.readBlock()
218
220
219 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
221 if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \
220 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
222 (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
221 log.warning(
223 log.warning(
222 'Reading Record No. {}/{} -> {} [Skipping]'.format(
224 'Reading Record No. {}/{} -> {} [Skipping]'.format(
223 self.counter_records,
225 self.counter_records,
224 self.nrecords,
226 self.nrecords,
225 self.datatime.ctime()),
227 self.datatime.ctime()),
226 'BLTRParamReader')
228 'BLTRParamReader')
227 continue
229 continue
228 break
230 break
229
231
230 log.log('Reading Record No. {}/{} -> {}'.format(
232 log.log('Reading Record No. {}/{} -> {}'.format(
231 self.counter_records,
233 self.counter_records,
232 self.nrecords,
234 self.nrecords,
233 self.datatime.ctime()), 'BLTRParamReader')
235 self.datatime.ctime()), 'BLTRParamReader')
234
236
235 return 1
237 return 1
236
238
237 def readBlock(self):
239 def readBlock(self):
238
240
239 pointer = self.fp.tell()
241 pointer = self.fp.tell()
240 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
242 header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1)
241 self.nchannels = header_rec['nchan'][0]/2
243 self.nchannels = header_rec['nchan'][0] / 2
242 self.kchan = header_rec['nrxs'][0]
244 self.kchan = header_rec['nrxs'][0]
243 self.nmodes = header_rec['nmodes'][0]
245 self.nmodes = header_rec['nmodes'][0]
244 self.nranges = header_rec['nranges'][0]
246 self.nranges = header_rec['nranges'][0]
245 self.fp.seek(pointer)
247 self.fp.seek(pointer)
246 self.height = numpy.empty((self.nmodes, self.nranges))
248 self.height = numpy.empty((self.nmodes, self.nranges))
247 self.snr = numpy.empty((self.nmodes, self.nchannels, self.nranges))
249 self.snr = numpy.empty((self.nmodes, self.nchannels, self.nranges))
248 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
250 self.buffer = numpy.empty((self.nmodes, 3, self.nranges))
249 self.flagDiscontinuousBlock = 0
251 self.flagDiscontinuousBlock = 0
250
252
251 for mode in range(self.nmodes):
253 for mode in range(self.nmodes):
252 self.readHeader()
254 self.readHeader()
253 data = self.readData()
255 data = self.readData()
254 self.height[mode] = (data[0] - self.correction) / 1000.
256 self.height[mode] = (data[0] - self.correction) / 1000.
255 self.buffer[mode] = data[1]
257 self.buffer[mode] = data[1]
256 self.snr[mode] = data[2]
258 self.snr[mode] = data[2]
257
259
258 self.counter_records = self.counter_records + self.nmodes
260 self.counter_records = self.counter_records + self.nmodes
259
261
260 return
262 return
261
263
262 def readHeader(self):
264 def readHeader(self):
263 '''
265 '''
264 RecordHeader of BLTR rawdata file
266 RecordHeader of BLTR rawdata file
265 '''
267 '''
266
268
267 header_structure = numpy.dtype(
269 header_structure = numpy.dtype(
268 REC_HEADER_STRUCTURE.descr + [
270 REC_HEADER_STRUCTURE.descr + [
269 ('antenna_coord', 'f4', (2, self.nchannels)),
271 ('antenna_coord', 'f4', (2, self.nchannels)),
270 ('rx_gains', 'u4', (self.nchannels,)),
272 ('rx_gains', 'u4', (self.nchannels,)),
271 ('rx_analysis', 'u4', (self.nchannels,))
273 ('rx_analysis', 'u4', (self.nchannels,))
272 ]
274 ]
273 )
275 )
274
276
275 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
277 self.header_rec = numpy.fromfile(self.fp, header_structure, 1)
276 self.lat = self.header_rec['lat'][0]
278 self.lat = self.header_rec['lat'][0]
277 self.lon = self.header_rec['lon'][0]
279 self.lon = self.header_rec['lon'][0]
278 self.delta = self.header_rec['delta_r'][0]
280 self.delta = self.header_rec['delta_r'][0]
279 self.correction = self.header_rec['dmode_rngcorr'][0]
281 self.correction = self.header_rec['dmode_rngcorr'][0]
280 self.imode = self.header_rec['dmode_index'][0]
282 self.imode = self.header_rec['dmode_index'][0]
281 self.antenna = self.header_rec['antenna_coord']
283 self.antenna = self.header_rec['antenna_coord']
282 self.rx_gains = self.header_rec['rx_gains']
284 self.rx_gains = self.header_rec['rx_gains']
283 self.time = self.header_rec['time'][0]
285 self.time = self.header_rec['time'][0]
284 dt = datetime.datetime.utcfromtimestamp(self.time)
286 dt = datetime.datetime.utcfromtimestamp(self.time)
285 if dt.date()>self.datatime.date():
287 if dt.date()>self.datatime.date():
286 self.flagDiscontinuousBlock = 1
288 self.flagDiscontinuousBlock = 1
287 self.datatime = dt
289 self.datatime = dt
288
290
289 def readData(self):
291 def readData(self):
290 '''
292 '''
291 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
293 Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value.
292
294
293 Input:
295 Input:
294 status_value - Array data is set to NAN for values that are not equal to status_value
296 status_value - Array data is set to NAN for values that are not equal to status_value
295
297
296 '''
298 '''
297
299
298 data_structure = numpy.dtype(
300 data_structure = numpy.dtype(
299 DATA_STRUCTURE.descr + [
301 DATA_STRUCTURE.descr + [
300 ('rx_saturation', 'u4', (self.nchannels,)),
302 ('rx_saturation', 'u4', (self.nchannels,)),
301 ('chan_offset', 'u4', (2 * self.nchannels,)),
303 ('chan_offset', 'u4', (2 * self.nchannels,)),
302 ('rx_amp', 'u4', (self.nchannels,)),
304 ('rx_amp', 'u4', (self.nchannels,)),
303 ('rx_snr', 'f4', (self.nchannels,)),
305 ('rx_snr', 'f4', (self.nchannels,)),
304 ('cross_snr', 'f4', (self.kchan,)),
306 ('cross_snr', 'f4', (self.kchan,)),
305 ('sea_power_relative', 'f4', (self.kchan,))]
307 ('sea_power_relative', 'f4', (self.kchan,))]
306 )
308 )
307
309
308 data = numpy.fromfile(self.fp, data_structure, self.nranges)
310 data = numpy.fromfile(self.fp, data_structure, self.nranges)
309
311
310 height = data['range']
312 height = data['range']
311 winds = numpy.array((data['zonal'], data['meridional'], data['vertical']))
313 winds = numpy.array(
314 (data['zonal'], data['meridional'], data['vertical']))
312 snr = data['rx_snr'].T
315 snr = data['rx_snr'].T
313
316
314 winds[numpy.where(winds == -9999.)] = numpy.nan
317 winds[numpy.where(winds == -9999.)] = numpy.nan
315 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
318 winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
316 snr[numpy.where(snr == -9999.)] = numpy.nan
319 snr[numpy.where(snr == -9999.)] = numpy.nan
317 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
320 snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan
318 snr = numpy.power(10, snr / 10)
321 snr = numpy.power(10, snr / 10)
319
322
320 return height, winds, snr
323 return height, winds, snr
321
324
322 def set_output(self):
325 def set_output(self):
323 '''
326 '''
324 Storing data from databuffer to dataOut object
327 Storing data from databuffer to dataOut object
325 '''
328 '''
326
329
327 self.dataOut.data_SNR = self.snr
330 self.dataOut.data_SNR = self.snr
328 self.dataOut.height = self.height
331 self.dataOut.height = self.height
329 self.dataOut.data = self.buffer
332 self.dataOut.data = self.buffer
330 self.dataOut.utctimeInit = self.time
333 self.dataOut.utctimeInit = self.time
331 self.dataOut.utctime = self.dataOut.utctimeInit
334 self.dataOut.utctime = self.dataOut.utctimeInit
332 self.dataOut.useLocalTime = False
335 self.dataOut.useLocalTime = False
333 self.dataOut.paramInterval = 157
336 self.dataOut.paramInterval = 157
334 self.dataOut.timezone = self.timezone
337 self.dataOut.timezone = self.timezone
335 self.dataOut.site = self.siteFile
338 self.dataOut.site = self.siteFile
336 self.dataOut.nrecords = self.nrecords/self.nmodes
339 self.dataOut.nrecords = self.nrecords / self.nmodes
337 self.dataOut.sizeOfFile = self.sizeOfFile
340 self.dataOut.sizeOfFile = self.sizeOfFile
338 self.dataOut.lat = self.lat
341 self.dataOut.lat = self.lat
339 self.dataOut.lon = self.lon
342 self.dataOut.lon = self.lon
340 self.dataOut.channelList = range(self.nchannels)
343 self.dataOut.channelList = range(self.nchannels)
341 self.dataOut.kchan = self.kchan
344 self.dataOut.kchan = self.kchan
342 self.dataOut.delta = self.delta
345 self.dataOut.delta = self.delta
343 self.dataOut.correction = self.correction
346 self.dataOut.correction = self.correction
344 self.dataOut.nmodes = self.nmodes
347 self.dataOut.nmodes = self.nmodes
345 self.dataOut.imode = self.imode
348 self.dataOut.imode = self.imode
346 self.dataOut.antenna = self.antenna
349 self.dataOut.antenna = self.antenna
347 self.dataOut.rx_gains = self.rx_gains
350 self.dataOut.rx_gains = self.rx_gains
348 self.dataOut.flagNoData = False
351 self.dataOut.flagNoData = False
349 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
352 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
350
353
351 def getData(self):
354 def getData(self):
352 '''
355 '''
353 Storing data from databuffer to dataOut object
356 Storing data from databuffer to dataOut object
354 '''
357 '''
355 if self.flagNoMoreFiles:
358 if self.flagNoMoreFiles:
356 self.dataOut.flagNoData = True
359 self.dataOut.flagNoData = True
357 log.success('No file left to process', 'BLTRParamReader')
360 log.success('No file left to process', 'BLTRParamReader')
358 return 0
361 return 0
359
362
360 if not self.readNextBlock():
363 if not self.readNextBlock():
361 self.dataOut.flagNoData = True
364 self.dataOut.flagNoData = True
362 return 0
365 return 0
363
366
364 self.set_output()
367 self.set_output()
365
368
366 return 1
369 return 1
@@ -1,1807 +1,1830
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import sys
7 import sys
8 import glob
8 import glob
9 import time
9 import time
10 import numpy
10 import numpy
11 import fnmatch
11 import fnmatch
12 import inspect
12 import inspect
13 import time, datetime
13 import time
14 import datetime
14 import traceback
15 import traceback
15 import zmq
16 import zmq
16
17
17 try:
18 try:
18 from gevent import sleep
19 from gevent import sleep
19 except:
20 except:
20 from time import sleep
21 from time import sleep
21
22
22 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
23 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
23 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
24 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width
24
25
25 LOCALTIME = True
26 LOCALTIME = True
26
27
28
27 def isNumber(cad):
29 def isNumber(cad):
28 """
30 """
29 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
31 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
30
32
31 Excepciones:
33 Excepciones:
32 Si un determinado string no puede ser convertido a numero
34 Si un determinado string no puede ser convertido a numero
33 Input:
35 Input:
34 str, string al cual se le analiza para determinar si convertible a un numero o no
36 str, string al cual se le analiza para determinar si convertible a un numero o no
35
37
36 Return:
38 Return:
37 True : si el string es uno numerico
39 True : si el string es uno numerico
38 False : no es un string numerico
40 False : no es un string numerico
39 """
41 """
40 try:
42 try:
41 float( cad )
43 float(cad)
42 return True
44 return True
43 except:
45 except:
44 return False
46 return False
45
47
48
46 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
49 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
47 """
50 """
48 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
51 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
49
52
50 Inputs:
53 Inputs:
51 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
54 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
52
55
53 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
56 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
54 segundos contados desde 01/01/1970.
57 segundos contados desde 01/01/1970.
55 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
58 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
56 segundos contados desde 01/01/1970.
59 segundos contados desde 01/01/1970.
57
60
58 Return:
61 Return:
59 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
62 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
60 fecha especificado, de lo contrario retorna False.
63 fecha especificado, de lo contrario retorna False.
61
64
62 Excepciones:
65 Excepciones:
63 Si el archivo no existe o no puede ser abierto
66 Si el archivo no existe o no puede ser abierto
64 Si la cabecera no puede ser leida.
67 Si la cabecera no puede ser leida.
65
68
66 """
69 """
67 basicHeaderObj = BasicHeader(LOCALTIME)
70 basicHeaderObj = BasicHeader(LOCALTIME)
68
71
69 try:
72 try:
70 fp = open(filename,'rb')
73 fp = open(filename, 'rb')
71 except IOError:
74 except IOError:
72 print "The file %s can't be opened" %(filename)
75 print "The file %s can't be opened" % (filename)
73 return 0
76 return 0
74
77
75 sts = basicHeaderObj.read(fp)
78 sts = basicHeaderObj.read(fp)
76 fp.close()
79 fp.close()
77
80
78 if not(sts):
81 if not(sts):
79 print "Skipping the file %s because it has not a valid header" %(filename)
82 print "Skipping the file %s because it has not a valid header" % (filename)
80 return 0
83 return 0
81
84
82 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
85 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
83 return 0
86 return 0
84
87
85 return 1
88 return 1
86
89
87 def isTimeInRange(thisTime, startTime, endTime):
88
90
91 def isTimeInRange(thisTime, startTime, endTime):
89 if endTime >= startTime:
92 if endTime >= startTime:
90 if (thisTime < startTime) or (thisTime > endTime):
93 if (thisTime < startTime) or (thisTime > endTime):
91 return 0
94 return 0
92
93 return 1
95 return 1
94 else:
96 else:
95 if (thisTime < startTime) and (thisTime > endTime):
97 if (thisTime < startTime) and (thisTime > endTime):
96 return 0
98 return 0
97
98 return 1
99 return 1
99
100
101
100 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
102 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
101 """
103 """
102 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
104 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
103
105
104 Inputs:
106 Inputs:
105 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
107 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
106
108
107 startDate : fecha inicial del rango seleccionado en formato datetime.date
109 startDate : fecha inicial del rango seleccionado en formato datetime.date
108
110
109 endDate : fecha final del rango seleccionado en formato datetime.date
111 endDate : fecha final del rango seleccionado en formato datetime.date
110
112
111 startTime : tiempo inicial del rango seleccionado en formato datetime.time
113 startTime : tiempo inicial del rango seleccionado en formato datetime.time
112
114
113 endTime : tiempo final del rango seleccionado en formato datetime.time
115 endTime : tiempo final del rango seleccionado en formato datetime.time
114
116
115 Return:
117 Return:
116 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
118 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
117 fecha especificado, de lo contrario retorna False.
119 fecha especificado, de lo contrario retorna False.
118
120
119 Excepciones:
121 Excepciones:
120 Si el archivo no existe o no puede ser abierto
122 Si el archivo no existe o no puede ser abierto
121 Si la cabecera no puede ser leida.
123 Si la cabecera no puede ser leida.
122
124
123 """
125 """
124
126
125
126 try:
127 try:
127 fp = open(filename,'rb')
128 fp = open(filename, 'rb')
128 except IOError:
129 except IOError:
129 print "The file %s can't be opened" %(filename)
130 print "The file %s can't be opened" % (filename)
130 return None
131 return None
131
132
132 firstBasicHeaderObj = BasicHeader(LOCALTIME)
133 firstBasicHeaderObj = BasicHeader(LOCALTIME)
133 systemHeaderObj = SystemHeader()
134 systemHeaderObj = SystemHeader()
134 radarControllerHeaderObj = RadarControllerHeader()
135 radarControllerHeaderObj = RadarControllerHeader()
135 processingHeaderObj = ProcessingHeader()
136 processingHeaderObj = ProcessingHeader()
136
137
137 lastBasicHeaderObj = BasicHeader(LOCALTIME)
138 lastBasicHeaderObj = BasicHeader(LOCALTIME)
138
139
139 sts = firstBasicHeaderObj.read(fp)
140 sts = firstBasicHeaderObj.read(fp)
140
141
141 if not(sts):
142 if not(sts):
142 print "[Reading] Skipping the file %s because it has not a valid header" %(filename)
143 print "[Reading] Skipping the file %s because it has not a valid header" % (filename)
143 return None
144 return None
144
145
145 if not systemHeaderObj.read(fp):
146 if not systemHeaderObj.read(fp):
146 return None
147 return None
147
148
148 if not radarControllerHeaderObj.read(fp):
149 if not radarControllerHeaderObj.read(fp):
149 return None
150 return None
150
151
151 if not processingHeaderObj.read(fp):
152 if not processingHeaderObj.read(fp):
152 return None
153 return None
153
154
154 filesize = os.path.getsize(filename)
155 filesize = os.path.getsize(filename)
155
156
156 offset = processingHeaderObj.blockSize + 24 #header size
157 offset = processingHeaderObj.blockSize + 24 # header size
157
158
158 if filesize <= offset:
159 if filesize <= offset:
159 print "[Reading] %s: This file has not enough data" %filename
160 print "[Reading] %s: This file has not enough data" % filename
160 return None
161 return None
161
162
162 fp.seek(-offset, 2)
163 fp.seek(-offset, 2)
163
164
164 sts = lastBasicHeaderObj.read(fp)
165 sts = lastBasicHeaderObj.read(fp)
165
166
166 fp.close()
167 fp.close()
167
168
168 thisDatetime = lastBasicHeaderObj.datatime
169 thisDatetime = lastBasicHeaderObj.datatime
169 thisTime_last_block = thisDatetime.time()
170 thisTime_last_block = thisDatetime.time()
170
171
171 thisDatetime = firstBasicHeaderObj.datatime
172 thisDatetime = firstBasicHeaderObj.datatime
172 thisDate = thisDatetime.date()
173 thisDate = thisDatetime.date()
173 thisTime_first_block = thisDatetime.time()
174 thisTime_first_block = thisDatetime.time()
174
175
175 #General case
176 # General case
176 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
177 # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o
177 #-----------o----------------------------o-----------
178 #-----------o----------------------------o-----------
178 # startTime endTime
179 # startTime endTime
179
180
180 if endTime >= startTime:
181 if endTime >= startTime:
181 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
182 if (thisTime_last_block < startTime) or (thisTime_first_block > endTime):
182 return None
183 return None
183
184
184 return thisDatetime
185 return thisDatetime
185
186
186 #If endTime < startTime then endTime belongs to the next day
187 # If endTime < startTime then endTime belongs to the next day
187
188
188
189 #<<<<<<<<<<<o o>>>>>>>>>>>
189 #<<<<<<<<<<<o o>>>>>>>>>>>
190 #-----------o----------------------------o-----------
190 #-----------o----------------------------o-----------
191 # endTime startTime
191 # endTime startTime
192
192
193 if (thisDate == startDate) and (thisTime_last_block < startTime):
193 if (thisDate == startDate) and (thisTime_last_block < startTime):
194 return None
194 return None
195
195
196 if (thisDate == endDate) and (thisTime_first_block > endTime):
196 if (thisDate == endDate) and (thisTime_first_block > endTime):
197 return None
197 return None
198
198
199 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
199 if (thisTime_last_block < startTime) and (thisTime_first_block > endTime):
200 return None
200 return None
201
201
202 return thisDatetime
202 return thisDatetime
203
203
204
204 def isFolderInDateRange(folder, startDate=None, endDate=None):
205 def isFolderInDateRange(folder, startDate=None, endDate=None):
205 """
206 """
206 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
207 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
207
208
208 Inputs:
209 Inputs:
209 folder : nombre completo del directorio.
210 folder : nombre completo del directorio.
210 Su formato deberia ser "/path_root/?YYYYDDD"
211 Su formato deberia ser "/path_root/?YYYYDDD"
211
212
212 siendo:
213 siendo:
213 YYYY : Anio (ejemplo 2015)
214 YYYY : Anio (ejemplo 2015)
214 DDD : Dia del anio (ejemplo 305)
215 DDD : Dia del anio (ejemplo 305)
215
216
216 startDate : fecha inicial del rango seleccionado en formato datetime.date
217 startDate : fecha inicial del rango seleccionado en formato datetime.date
217
218
218 endDate : fecha final del rango seleccionado en formato datetime.date
219 endDate : fecha final del rango seleccionado en formato datetime.date
219
220
220 Return:
221 Return:
221 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
222 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
222 fecha especificado, de lo contrario retorna False.
223 fecha especificado, de lo contrario retorna False.
223 Excepciones:
224 Excepciones:
224 Si el directorio no tiene el formato adecuado
225 Si el directorio no tiene el formato adecuado
225 """
226 """
226
227
227 basename = os.path.basename(folder)
228 basename = os.path.basename(folder)
228
229
229 if not isRadarFolder(basename):
230 if not isRadarFolder(basename):
230 print "The folder %s has not the rigth format" %folder
231 print "The folder %s has not the rigth format" % folder
231 return 0
232 return 0
232
233
233 if startDate and endDate:
234 if startDate and endDate:
234 thisDate = getDateFromRadarFolder(basename)
235 thisDate = getDateFromRadarFolder(basename)
235
236
236 if thisDate < startDate:
237 if thisDate < startDate:
237 return 0
238 return 0
238
239
239 if thisDate > endDate:
240 if thisDate > endDate:
240 return 0
241 return 0
241
242
242 return 1
243 return 1
243
244
245
244 def isFileInDateRange(filename, startDate=None, endDate=None):
246 def isFileInDateRange(filename, startDate=None, endDate=None):
245 """
247 """
246 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
248 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
247
249
248 Inputs:
250 Inputs:
249 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
251 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
250
252
251 Su formato deberia ser "?YYYYDDDsss"
253 Su formato deberia ser "?YYYYDDDsss"
252
254
253 siendo:
255 siendo:
254 YYYY : Anio (ejemplo 2015)
256 YYYY : Anio (ejemplo 2015)
255 DDD : Dia del anio (ejemplo 305)
257 DDD : Dia del anio (ejemplo 305)
256 sss : set
258 sss : set
257
259
258 startDate : fecha inicial del rango seleccionado en formato datetime.date
260 startDate : fecha inicial del rango seleccionado en formato datetime.date
259
261
260 endDate : fecha final del rango seleccionado en formato datetime.date
262 endDate : fecha final del rango seleccionado en formato datetime.date
261
263
262 Return:
264 Return:
263 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
265 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
264 fecha especificado, de lo contrario retorna False.
266 fecha especificado, de lo contrario retorna False.
265 Excepciones:
267 Excepciones:
266 Si el archivo no tiene el formato adecuado
268 Si el archivo no tiene el formato adecuado
267 """
269 """
268
270
269 basename = os.path.basename(filename)
271 basename = os.path.basename(filename)
270
272
271 if not isRadarFile(basename):
273 if not isRadarFile(basename):
272 print "The filename %s has not the rigth format" %filename
274 print "The filename %s has not the rigth format" % filename
273 return 0
275 return 0
274
276
275 if startDate and endDate:
277 if startDate and endDate:
276 thisDate = getDateFromRadarFile(basename)
278 thisDate = getDateFromRadarFile(basename)
277
279
278 if thisDate < startDate:
280 if thisDate < startDate:
279 return 0
281 return 0
280
282
281 if thisDate > endDate:
283 if thisDate > endDate:
282 return 0
284 return 0
283
285
284 return 1
286 return 1
285
287
288
286 def getFileFromSet(path, ext, set):
289 def getFileFromSet(path, ext, set):
287 validFilelist = []
290 validFilelist = []
288 fileList = os.listdir(path)
291 fileList = os.listdir(path)
289
292
290 # 0 1234 567 89A BCDE
293 # 0 1234 567 89A BCDE
291 # H YYYY DDD SSS .ext
294 # H YYYY DDD SSS .ext
292
295
293 for thisFile in fileList:
296 for thisFile in fileList:
294 try:
297 try:
295 year = int(thisFile[1:5])
298 year = int(thisFile[1:5])
296 doy = int(thisFile[5:8])
299 doy = int(thisFile[5:8])
297 except:
300 except:
298 continue
301 continue
299
302
300 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
303 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
301 continue
304 continue
302
305
303 validFilelist.append(thisFile)
306 validFilelist.append(thisFile)
304
307
305 myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set))
308 myfile = fnmatch.filter(
309 validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set))
306
310
307 if len(myfile)!= 0:
311 if len(myfile) != 0:
308 return myfile[0]
312 return myfile[0]
309 else:
313 else:
310 filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower())
314 filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower())
311 print 'the filename %s does not exist'%filename
315 print 'the filename %s does not exist' % filename
312 print '...going to the last file: '
316 print '...going to the last file: '
313
317
314 if validFilelist:
318 if validFilelist:
315 validFilelist = sorted( validFilelist, key=str.lower )
319 validFilelist = sorted(validFilelist, key=str.lower)
316 return validFilelist[-1]
320 return validFilelist[-1]
317
321
318 return None
322 return None
319
323
324
320 def getlastFileFromPath(path, ext):
325 def getlastFileFromPath(path, ext):
321 """
326 """
322 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
327 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
323 al final de la depuracion devuelve el ultimo file de la lista que quedo.
328 al final de la depuracion devuelve el ultimo file de la lista que quedo.
324
329
325 Input:
330 Input:
326 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
331 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
327 ext : extension de los files contenidos en una carpeta
332 ext : extension de los files contenidos en una carpeta
328
333
329 Return:
334 Return:
330 El ultimo file de una determinada carpeta, no se considera el path.
335 El ultimo file de una determinada carpeta, no se considera el path.
331 """
336 """
332 validFilelist = []
337 validFilelist = []
333 fileList = os.listdir(path)
338 fileList = os.listdir(path)
334
339
335 # 0 1234 567 89A BCDE
340 # 0 1234 567 89A BCDE
336 # H YYYY DDD SSS .ext
341 # H YYYY DDD SSS .ext
337
342
338 for thisFile in fileList:
343 for thisFile in fileList:
339
344
340 year = thisFile[1:5]
345 year = thisFile[1:5]
341 if not isNumber(year):
346 if not isNumber(year):
342 continue
347 continue
343
348
344 doy = thisFile[5:8]
349 doy = thisFile[5:8]
345 if not isNumber(doy):
350 if not isNumber(doy):
346 continue
351 continue
347
352
348 year = int(year)
353 year = int(year)
349 doy = int(doy)
354 doy = int(doy)
350
355
351 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
356 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
352 continue
357 continue
353
358
354 validFilelist.append(thisFile)
359 validFilelist.append(thisFile)
355
360
356 if validFilelist:
361 if validFilelist:
357 validFilelist = sorted( validFilelist, key=str.lower )
362 validFilelist = sorted(validFilelist, key=str.lower)
358 return validFilelist[-1]
363 return validFilelist[-1]
359
364
360 return None
365 return None
361
366
367
362 def checkForRealPath(path, foldercounter, year, doy, set, ext):
368 def checkForRealPath(path, foldercounter, year, doy, set, ext):
363 """
369 """
364 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
370 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
365 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
371 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
366 el path exacto de un determinado file.
372 el path exacto de un determinado file.
367
373
368 Example :
374 Example :
369 nombre correcto del file es .../.../D2009307/P2009307367.ext
375 nombre correcto del file es .../.../D2009307/P2009307367.ext
370
376
371 Entonces la funcion prueba con las siguientes combinaciones
377 Entonces la funcion prueba con las siguientes combinaciones
372 .../.../y2009307367.ext
378 .../.../y2009307367.ext
373 .../.../Y2009307367.ext
379 .../.../Y2009307367.ext
374 .../.../x2009307/y2009307367.ext
380 .../.../x2009307/y2009307367.ext
375 .../.../x2009307/Y2009307367.ext
381 .../.../x2009307/Y2009307367.ext
376 .../.../X2009307/y2009307367.ext
382 .../.../X2009307/y2009307367.ext
377 .../.../X2009307/Y2009307367.ext
383 .../.../X2009307/Y2009307367.ext
378 siendo para este caso, la ultima combinacion de letras, identica al file buscado
384 siendo para este caso, la ultima combinacion de letras, identica al file buscado
379
385
380 Return:
386 Return:
381 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
387 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
382 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
388 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
383 para el filename
389 para el filename
384 """
390 """
385 fullfilename = None
391 fullfilename = None
386 find_flag = False
392 find_flag = False
387 filename = None
393 filename = None
388
394
389 prefixDirList = [None,'d','D']
395 prefixDirList = [None, 'd', 'D']
390 if ext.lower() == ".r": #voltage
396 if ext.lower() == ".r": # voltage
391 prefixFileList = ['d','D']
397 prefixFileList = ['d', 'D']
392 elif ext.lower() == ".pdata": #spectra
398 elif ext.lower() == ".pdata": # spectra
393 prefixFileList = ['p','P']
399 prefixFileList = ['p', 'P']
394 else:
400 else:
395 return None, filename
401 return None, filename
396
402
397 #barrido por las combinaciones posibles
403 # barrido por las combinaciones posibles
398 for prefixDir in prefixDirList:
404 for prefixDir in prefixDirList:
399 thispath = path
405 thispath = path
400 if prefixDir != None:
406 if prefixDir != None:
401 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
407 # formo el nombre del directorio xYYYYDDD (x=d o x=D)
402 if foldercounter == 0:
408 if foldercounter == 0:
403 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
409 thispath = os.path.join(path, "%s%04d%03d" %
410 (prefixDir, year, doy))
404 else:
411 else:
405 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
412 thispath = os.path.join(path, "%s%04d%03d_%02d" % (
413 prefixDir, year, doy, foldercounter))
406 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
414 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
407 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
415 # formo el nombre del file xYYYYDDDSSS.ext
408 fullfilename = os.path.join( thispath, filename ) #formo el path completo
416 filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext)
417 fullfilename = os.path.join(
418 thispath, filename) # formo el path completo
409
419
410 if os.path.exists( fullfilename ): #verifico que exista
420 if os.path.exists(fullfilename): # verifico que exista
411 find_flag = True
421 find_flag = True
412 break
422 break
413 if find_flag:
423 if find_flag:
414 break
424 break
415
425
416 if not(find_flag):
426 if not(find_flag):
417 return None, filename
427 return None, filename
418
428
419 return fullfilename, filename
429 return fullfilename, filename
420
430
431
421 def isRadarFolder(folder):
432 def isRadarFolder(folder):
422 try:
433 try:
423 year = int(folder[1:5])
434 year = int(folder[1:5])
424 doy = int(folder[5:8])
435 doy = int(folder[5:8])
425 except:
436 except:
426 return 0
437 return 0
427
438
428 return 1
439 return 1
429
440
441
430 def isRadarFile(file):
442 def isRadarFile(file):
431 try:
443 try:
432 year = int(file[1:5])
444 year = int(file[1:5])
433 doy = int(file[5:8])
445 doy = int(file[5:8])
434 set = int(file[8:11])
446 set = int(file[8:11])
435 except:
447 except:
436 return 0
448 return 0
437
449
438 return 1
450 return 1
439
451
452
440 def getDateFromRadarFile(file):
453 def getDateFromRadarFile(file):
441 try:
454 try:
442 year = int(file[1:5])
455 year = int(file[1:5])
443 doy = int(file[5:8])
456 doy = int(file[5:8])
444 set = int(file[8:11])
457 set = int(file[8:11])
445 except:
458 except:
446 return None
459 return None
447
460
448 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
461 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
449 return thisDate
462 return thisDate
450
463
464
451 def getDateFromRadarFolder(folder):
465 def getDateFromRadarFolder(folder):
452 try:
466 try:
453 year = int(folder[1:5])
467 year = int(folder[1:5])
454 doy = int(folder[5:8])
468 doy = int(folder[5:8])
455 except:
469 except:
456 return None
470 return None
457
471
458 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1)
472 thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1)
459 return thisDate
473 return thisDate
460
474
475
461 class JRODataIO:
476 class JRODataIO:
462
477
463 c = 3E8
478 c = 3E8
464
479
465 isConfig = False
480 isConfig = False
466
481
467 basicHeaderObj = None
482 basicHeaderObj = None
468
483
469 systemHeaderObj = None
484 systemHeaderObj = None
470
485
471 radarControllerHeaderObj = None
486 radarControllerHeaderObj = None
472
487
473 processingHeaderObj = None
488 processingHeaderObj = None
474
489
475 dtype = None
490 dtype = None
476
491
477 pathList = []
492 pathList = []
478
493
479 filenameList = []
494 filenameList = []
480
495
481 filename = None
496 filename = None
482
497
483 ext = None
498 ext = None
484
499
485 flagIsNewFile = 1
500 flagIsNewFile = 1
486
501
487 flagDiscontinuousBlock = 0
502 flagDiscontinuousBlock = 0
488
503
489 flagIsNewBlock = 0
504 flagIsNewBlock = 0
490
505
491 fp = None
506 fp = None
492
507
493 firstHeaderSize = 0
508 firstHeaderSize = 0
494
509
495 basicHeaderSize = 24
510 basicHeaderSize = 24
496
511
497 versionFile = 1103
512 versionFile = 1103
498
513
499 fileSize = None
514 fileSize = None
500
515
501 # ippSeconds = None
516 # ippSeconds = None
502
517
503 fileSizeByHeader = None
518 fileSizeByHeader = None
504
519
505 fileIndex = None
520 fileIndex = None
506
521
507 profileIndex = None
522 profileIndex = None
508
523
509 blockIndex = None
524 blockIndex = None
510
525
511 nTotalBlocks = None
526 nTotalBlocks = None
512
527
513 maxTimeStep = 30
528 maxTimeStep = 30
514
529
515 lastUTTime = None
530 lastUTTime = None
516
531
517 datablock = None
532 datablock = None
518
533
519 dataOut = None
534 dataOut = None
520
535
521 blocksize = None
536 blocksize = None
522
537
523 getByBlock = False
538 getByBlock = False
524
539
525 def __init__(self):
540 def __init__(self):
526
541
527 raise NotImplementedError
542 raise NotImplementedError
528
543
529 def run(self):
544 def run(self):
530
545
531 raise NotImplementedError
546 raise NotImplementedError
532
547
533 def getDtypeWidth(self):
548 def getDtypeWidth(self):
534
549
535 dtype_index = get_dtype_index(self.dtype)
550 dtype_index = get_dtype_index(self.dtype)
536 dtype_width = get_dtype_width(dtype_index)
551 dtype_width = get_dtype_width(dtype_index)
537
552
538 return dtype_width
553 return dtype_width
539
554
540 def getAllowedArgs(self):
555 def getAllowedArgs(self):
541 return inspect.getargspec(self.run).args
556 return inspect.getargspec(self.run).args
542
557
558
543 class JRODataReader(JRODataIO):
559 class JRODataReader(JRODataIO):
544
560
545 online = 0
561 online = 0
546
562
547 realtime = 0
563 realtime = 0
548
564
549 nReadBlocks = 0
565 nReadBlocks = 0
550
566
551 delay = 10 #number of seconds waiting a new file
567 delay = 10 # number of seconds waiting a new file
552
568
553 nTries = 3 #quantity tries
569 nTries = 3 # quantity tries
554
570
555 nFiles = 3 #number of files for searching
571 nFiles = 3 # number of files for searching
556
572
557 path = None
573 path = None
558
574
559 foldercounter = 0
575 foldercounter = 0
560
576
561 flagNoMoreFiles = 0
577 flagNoMoreFiles = 0
562
578
563 datetimeList = []
579 datetimeList = []
564
580
565 __isFirstTimeOnline = 1
581 __isFirstTimeOnline = 1
566
582
567 __printInfo = True
583 __printInfo = True
568
584
569 profileIndex = None
585 profileIndex = None
570
586
571 nTxs = 1
587 nTxs = 1
572
588
573 txIndex = None
589 txIndex = None
574
590
575 #Added--------------------
591 # Added--------------------
576
592
577 selBlocksize = None
593 selBlocksize = None
578
594
579 selBlocktime = None
595 selBlocktime = None
580
596
581 def __init__(self):
597 def __init__(self):
582
583 """
598 """
584 This class is used to find data files
599 This class is used to find data files
585
600
586 Example:
601 Example:
587 reader = JRODataReader()
602 reader = JRODataReader()
588 fileList = reader.findDataFiles()
603 fileList = reader.findDataFiles()
589
604
590 """
605 """
591 pass
606 pass
592
607
593
594 def createObjByDefault(self):
608 def createObjByDefault(self):
595 """
609 """
596
610
597 """
611 """
598 raise NotImplementedError
612 raise NotImplementedError
599
613
600 def getBlockDimension(self):
614 def getBlockDimension(self):
601
615
602 raise NotImplementedError
616 raise NotImplementedError
603
617
604 def searchFilesOffLine(self,
618 def searchFilesOffLine(self,
605 path,
619 path,
606 startDate=None,
620 startDate=None,
607 endDate=None,
621 endDate=None,
608 startTime=datetime.time(0,0,0),
622 startTime=datetime.time(0, 0, 0),
609 endTime=datetime.time(23,59,59),
623 endTime=datetime.time(23, 59, 59),
610 set=None,
624 set=None,
611 expLabel='',
625 expLabel='',
612 ext='.r',
626 ext='.r',
613 cursor=None,
627 cursor=None,
614 skip=None,
628 skip=None,
615 walk=True):
629 walk=True):
616
630
617 self.filenameList = []
631 self.filenameList = []
618 self.datetimeList = []
632 self.datetimeList = []
619
633
620 pathList = []
634 pathList = []
621
635
622 dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True)
636 dateList, pathList = self.findDatafiles(
637 path, startDate, endDate, expLabel, ext, walk, include_path=True)
623
638
624 if dateList == []:
639 if dateList == []:
625 return [], []
640 return [], []
626
641
627 if len(dateList) > 1:
642 if len(dateList) > 1:
628 print "[Reading] Data found for date range [%s - %s]: total days = %d" %(startDate, endDate, len(dateList))
643 print "[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList))
629 else:
644 else:
630 print "[Reading] Data found for date range [%s - %s]: date = %s" %(startDate, endDate, dateList[0])
645 print "[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0])
631
646
632 filenameList = []
647 filenameList = []
633 datetimeList = []
648 datetimeList = []
634
649
635 for thisPath in pathList:
650 for thisPath in pathList:
636
651
637 fileList = glob.glob1(thisPath, "*%s" %ext)
652 fileList = glob.glob1(thisPath, "*%s" % ext)
638 fileList.sort()
653 fileList.sort()
639
654
640 skippedFileList = []
655 skippedFileList = []
641
656
642 if cursor is not None and skip is not None:
657 if cursor is not None and skip is not None:
643
658
644 if skip == 0:
659 if skip == 0:
645 skippedFileList = []
660 skippedFileList = []
646 else:
661 else:
647 skippedFileList = fileList[cursor*skip: cursor*skip + skip]
662 skippedFileList = fileList[cursor *
663 skip: cursor * skip + skip]
648
664
649 else:
665 else:
650 skippedFileList = fileList
666 skippedFileList = fileList
651
667
652 for file in skippedFileList:
668 for file in skippedFileList:
653
669
654 filename = os.path.join(thisPath,file)
670 filename = os.path.join(thisPath, file)
655
671
656 if not isFileInDateRange(filename, startDate, endDate):
672 if not isFileInDateRange(filename, startDate, endDate):
657 continue
673 continue
658
674
659 thisDatetime = isFileInTimeRange(filename, startDate, endDate, startTime, endTime)
675 thisDatetime = isFileInTimeRange(
676 filename, startDate, endDate, startTime, endTime)
660
677
661 if not(thisDatetime):
678 if not(thisDatetime):
662 continue
679 continue
663
680
664 filenameList.append(filename)
681 filenameList.append(filename)
665 datetimeList.append(thisDatetime)
682 datetimeList.append(thisDatetime)
666
683
667 if not(filenameList):
684 if not(filenameList):
668 print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" %(startTime, endTime, ext, path)
685 print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path)
669 return [], []
686 return [], []
670
687
671 print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime)
688 print "[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime)
672 print
689 print
673
690
674 # for i in range(len(filenameList)):
691 # for i in range(len(filenameList)):
675 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
692 # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
676
693
677 self.filenameList = filenameList
694 self.filenameList = filenameList
678 self.datetimeList = datetimeList
695 self.datetimeList = datetimeList
679
696
680 return pathList, filenameList
697 return pathList, filenameList
681
698
682 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None):
699 def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None):
683
684 """
700 """
685 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
701 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
686 devuelve el archivo encontrado ademas de otros datos.
702 devuelve el archivo encontrado ademas de otros datos.
687
703
688 Input:
704 Input:
689 path : carpeta donde estan contenidos los files que contiene data
705 path : carpeta donde estan contenidos los files que contiene data
690
706
691 expLabel : Nombre del subexperimento (subfolder)
707 expLabel : Nombre del subexperimento (subfolder)
692
708
693 ext : extension de los files
709 ext : extension de los files
694
710
695 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
711 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
696
712
697 Return:
713 Return:
698 directory : eL directorio donde esta el file encontrado
714 directory : eL directorio donde esta el file encontrado
699 filename : el ultimo file de una determinada carpeta
715 filename : el ultimo file de una determinada carpeta
700 year : el anho
716 year : el anho
701 doy : el numero de dia del anho
717 doy : el numero de dia del anho
702 set : el set del archivo
718 set : el set del archivo
703
719
704
720
705 """
721 """
706 if not os.path.isdir(path):
722 if not os.path.isdir(path):
707 return None, None, None, None, None, None
723 return None, None, None, None, None, None
708
724
709 dirList = []
725 dirList = []
710
726
711 if not walk:
727 if not walk:
712 fullpath = path
728 fullpath = path
713 foldercounter = 0
729 foldercounter = 0
714 else:
730 else:
715 #Filtra solo los directorios
731 # Filtra solo los directorios
716 for thisPath in os.listdir(path):
732 for thisPath in os.listdir(path):
717 if not os.path.isdir(os.path.join(path,thisPath)):
733 if not os.path.isdir(os.path.join(path, thisPath)):
718 continue
734 continue
719 if not isRadarFolder(thisPath):
735 if not isRadarFolder(thisPath):
720 continue
736 continue
721
737
722 dirList.append(thisPath)
738 dirList.append(thisPath)
723
739
724 if not(dirList):
740 if not(dirList):
725 return None, None, None, None, None, None
741 return None, None, None, None, None, None
726
742
727 dirList = sorted( dirList, key=str.lower )
743 dirList = sorted(dirList, key=str.lower)
728
744
729 doypath = dirList[-1]
745 doypath = dirList[-1]
730 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
746 foldercounter = int(doypath.split('_')[1]) if len(
747 doypath.split('_')) > 1 else 0
731 fullpath = os.path.join(path, doypath, expLabel)
748 fullpath = os.path.join(path, doypath, expLabel)
732
749
733
734 print "[Reading] %s folder was found: " %(fullpath )
750 print "[Reading] %s folder was found: " % (fullpath)
735
751
736 if set == None:
752 if set == None:
737 filename = getlastFileFromPath(fullpath, ext)
753 filename = getlastFileFromPath(fullpath, ext)
738 else:
754 else:
739 filename = getFileFromSet(fullpath, ext, set)
755 filename = getFileFromSet(fullpath, ext, set)
740
756
741 if not(filename):
757 if not(filename):
742 return None, None, None, None, None, None
758 return None, None, None, None, None, None
743
759
744 print "[Reading] %s file was found" %(filename)
760 print "[Reading] %s file was found" % (filename)
745
761
746 if not(self.__verifyFile(os.path.join(fullpath, filename))):
762 if not(self.__verifyFile(os.path.join(fullpath, filename))):
747 return None, None, None, None, None, None
763 return None, None, None, None, None, None
748
764
749 year = int( filename[1:5] )
765 year = int(filename[1:5])
750 doy = int( filename[5:8] )
766 doy = int(filename[5:8])
751 set = int( filename[8:11] )
767 set = int(filename[8:11])
752
768
753 return fullpath, foldercounter, filename, year, doy, set
769 return fullpath, foldercounter, filename, year, doy, set
754
770
755 def __setNextFileOffline(self):
771 def __setNextFileOffline(self):
756
772
757 idFile = self.fileIndex
773 idFile = self.fileIndex
758
774
759 while (True):
775 while (True):
760 idFile += 1
776 idFile += 1
761 if not(idFile < len(self.filenameList)):
777 if not(idFile < len(self.filenameList)):
762 self.flagNoMoreFiles = 1
778 self.flagNoMoreFiles = 1
763 # print "[Reading] No more Files"
779 # print "[Reading] No more Files"
764 return 0
780 return 0
765
781
766 filename = self.filenameList[idFile]
782 filename = self.filenameList[idFile]
767
783
768 if not(self.__verifyFile(filename)):
784 if not(self.__verifyFile(filename)):
769 continue
785 continue
770
786
771 fileSize = os.path.getsize(filename)
787 fileSize = os.path.getsize(filename)
772 fp = open(filename,'rb')
788 fp = open(filename, 'rb')
773 break
789 break
774
790
775 self.flagIsNewFile = 1
791 self.flagIsNewFile = 1
776 self.fileIndex = idFile
792 self.fileIndex = idFile
777 self.filename = filename
793 self.filename = filename
778 self.fileSize = fileSize
794 self.fileSize = fileSize
779 self.fp = fp
795 self.fp = fp
780
796
781 # print "[Reading] Setting the file: %s"%self.filename
797 # print "[Reading] Setting the file: %s"%self.filename
782
798
783 return 1
799 return 1
784
800
785 def __setNextFileOnline(self):
801 def __setNextFileOnline(self):
786 """
802 """
787 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
803 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
788 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
804 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
789 siguientes.
805 siguientes.
790
806
791 Affected:
807 Affected:
792 self.flagIsNewFile
808 self.flagIsNewFile
793 self.filename
809 self.filename
794 self.fileSize
810 self.fileSize
795 self.fp
811 self.fp
796 self.set
812 self.set
797 self.flagNoMoreFiles
813 self.flagNoMoreFiles
798
814
799 Return:
815 Return:
800 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
816 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
801 1 : si el file fue abierto con exito y esta listo a ser leido
817 1 : si el file fue abierto con exito y esta listo a ser leido
802
818
803 Excepciones:
819 Excepciones:
804 Si un determinado file no puede ser abierto
820 Si un determinado file no puede ser abierto
805 """
821 """
806 nFiles = 0
822 nFiles = 0
807 fileOk_flag = False
823 fileOk_flag = False
808 firstTime_flag = True
824 firstTime_flag = True
809
825
810 self.set += 1
826 self.set += 1
811
827
812 if self.set > 999:
828 if self.set > 999:
813 self.set = 0
829 self.set = 0
814 self.foldercounter += 1
830 self.foldercounter += 1
815
831
816 #busca el 1er file disponible
832 # busca el 1er file disponible
817 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
833 fullfilename, filename = checkForRealPath(
834 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
818 if fullfilename:
835 if fullfilename:
819 if self.__verifyFile(fullfilename, False):
836 if self.__verifyFile(fullfilename, False):
820 fileOk_flag = True
837 fileOk_flag = True
821
838
822 #si no encuentra un file entonces espera y vuelve a buscar
839 # si no encuentra un file entonces espera y vuelve a buscar
823 if not(fileOk_flag):
840 if not(fileOk_flag):
824 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
841 # busco en los siguientes self.nFiles+1 files posibles
842 for nFiles in range(self.nFiles + 1):
825
843
826 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
844 if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces
827 tries = self.nTries
845 tries = self.nTries
828 else:
846 else:
829 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
847 tries = 1 # si no es la 1era vez entonces solo lo hace una vez
830
848
831 for nTries in range( tries ):
849 for nTries in range(tries):
832 if firstTime_flag:
850 if firstTime_flag:
833 print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
851 print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1)
834 sleep( self.delay )
852 sleep(self.delay)
835 else:
853 else:
836 print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
854 print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
837
855
838 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
856 fullfilename, filename = checkForRealPath(
857 self.path, self.foldercounter, self.year, self.doy, self.set, self.ext)
839 if fullfilename:
858 if fullfilename:
840 if self.__verifyFile(fullfilename):
859 if self.__verifyFile(fullfilename):
841 fileOk_flag = True
860 fileOk_flag = True
842 break
861 break
843
862
844 if fileOk_flag:
863 if fileOk_flag:
845 break
864 break
846
865
847 firstTime_flag = False
866 firstTime_flag = False
848
867
849 print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename
868 print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename
850 self.set += 1
869 self.set += 1
851
870
852 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
871 # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
872 if nFiles == (self.nFiles - 1):
853 self.set = 0
873 self.set = 0
854 self.doy += 1
874 self.doy += 1
855 self.foldercounter = 0
875 self.foldercounter = 0
856
876
857 if fileOk_flag:
877 if fileOk_flag:
858 self.fileSize = os.path.getsize( fullfilename )
878 self.fileSize = os.path.getsize(fullfilename)
859 self.filename = fullfilename
879 self.filename = fullfilename
860 self.flagIsNewFile = 1
880 self.flagIsNewFile = 1
861 if self.fp != None: self.fp.close()
881 if self.fp != None:
882 self.fp.close()
862 self.fp = open(fullfilename, 'rb')
883 self.fp = open(fullfilename, 'rb')
863 self.flagNoMoreFiles = 0
884 self.flagNoMoreFiles = 0
864 # print '[Reading] Setting the file: %s' % fullfilename
885 # print '[Reading] Setting the file: %s' % fullfilename
865 else:
886 else:
866 self.fileSize = 0
887 self.fileSize = 0
867 self.filename = None
888 self.filename = None
868 self.flagIsNewFile = 0
889 self.flagIsNewFile = 0
869 self.fp = None
890 self.fp = None
870 self.flagNoMoreFiles = 1
891 self.flagNoMoreFiles = 1
871 # print '[Reading] No more files to read'
892 # print '[Reading] No more files to read'
872
893
873 return fileOk_flag
894 return fileOk_flag
874
895
875 def setNextFile(self):
896 def setNextFile(self):
876 if self.fp != None:
897 if self.fp != None:
877 self.fp.close()
898 self.fp.close()
878
899
879 if self.online:
900 if self.online:
880 newFile = self.__setNextFileOnline()
901 newFile = self.__setNextFileOnline()
881 else:
902 else:
882 newFile = self.__setNextFileOffline()
903 newFile = self.__setNextFileOffline()
883
904
884 if not(newFile):
905 if not(newFile):
885 print '[Reading] No more files to read'
906 print '[Reading] No more files to read'
886 return 0
907 return 0
887
908
888 if self.verbose:
909 if self.verbose:
889 print '[Reading] Setting the file: %s' % self.filename
910 print '[Reading] Setting the file: %s' % self.filename
890
911
891 self.__readFirstHeader()
912 self.__readFirstHeader()
892 self.nReadBlocks = 0
913 self.nReadBlocks = 0
893 return 1
914 return 1
894
915
895 def __waitNewBlock(self):
916 def __waitNewBlock(self):
896 """
917 """
897 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
918 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
898
919
899 Si el modo de lectura es OffLine siempre retorn 0
920 Si el modo de lectura es OffLine siempre retorn 0
900 """
921 """
901 if not self.online:
922 if not self.online:
902 return 0
923 return 0
903
924
904 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
925 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
905 return 0
926 return 0
906
927
907 currentPointer = self.fp.tell()
928 currentPointer = self.fp.tell()
908
929
909 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
930 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
910
931
911 for nTries in range( self.nTries ):
932 for nTries in range(self.nTries):
912
933
913 self.fp.close()
934 self.fp.close()
914 self.fp = open( self.filename, 'rb' )
935 self.fp = open(self.filename, 'rb')
915 self.fp.seek( currentPointer )
936 self.fp.seek(currentPointer)
916
937
917 self.fileSize = os.path.getsize( self.filename )
938 self.fileSize = os.path.getsize(self.filename)
918 currentSize = self.fileSize - currentPointer
939 currentSize = self.fileSize - currentPointer
919
940
920 if ( currentSize >= neededSize ):
941 if (currentSize >= neededSize):
921 self.basicHeaderObj.read(self.fp)
942 self.basicHeaderObj.read(self.fp)
922 return 1
943 return 1
923
944
924 if self.fileSize == self.fileSizeByHeader:
945 if self.fileSize == self.fileSizeByHeader:
925 # self.flagEoF = True
946 # self.flagEoF = True
926 return 0
947 return 0
927
948
928 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
949 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)
929 sleep( self.delay )
950 sleep(self.delay)
930
951
931
932 return 0
952 return 0
933
953
934 def waitDataBlock(self,pointer_location):
954 def waitDataBlock(self, pointer_location):
935
955
936 currentPointer = pointer_location
956 currentPointer = pointer_location
937
957
938 neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize
958 neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize
939
959
940 for nTries in range( self.nTries ):
960 for nTries in range(self.nTries):
941 self.fp.close()
961 self.fp.close()
942 self.fp = open( self.filename, 'rb' )
962 self.fp = open(self.filename, 'rb')
943 self.fp.seek( currentPointer )
963 self.fp.seek(currentPointer)
944
964
945 self.fileSize = os.path.getsize( self.filename )
965 self.fileSize = os.path.getsize(self.filename)
946 currentSize = self.fileSize - currentPointer
966 currentSize = self.fileSize - currentPointer
947
967
948 if ( currentSize >= neededSize ):
968 if (currentSize >= neededSize):
949 return 1
969 return 1
950
970
951 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
971 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)
952 sleep( self.delay )
972 sleep(self.delay)
953
973
954 return 0
974 return 0
955
975
956 def __jumpToLastBlock(self):
976 def __jumpToLastBlock(self):
957
977
958 if not(self.__isFirstTimeOnline):
978 if not(self.__isFirstTimeOnline):
959 return
979 return
960
980
961 csize = self.fileSize - self.fp.tell()
981 csize = self.fileSize - self.fp.tell()
962 blocksize = self.processingHeaderObj.blockSize
982 blocksize = self.processingHeaderObj.blockSize
963
983
964 #salta el primer bloque de datos
984 # salta el primer bloque de datos
965 if csize > self.processingHeaderObj.blockSize:
985 if csize > self.processingHeaderObj.blockSize:
966 self.fp.seek(self.fp.tell() + blocksize)
986 self.fp.seek(self.fp.tell() + blocksize)
967 else:
987 else:
968 return
988 return
969
989
970 csize = self.fileSize - self.fp.tell()
990 csize = self.fileSize - self.fp.tell()
971 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
991 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
972 while True:
992 while True:
973
993
974 if self.fp.tell()<self.fileSize:
994 if self.fp.tell() < self.fileSize:
975 self.fp.seek(self.fp.tell() + neededsize)
995 self.fp.seek(self.fp.tell() + neededsize)
976 else:
996 else:
977 self.fp.seek(self.fp.tell() - neededsize)
997 self.fp.seek(self.fp.tell() - neededsize)
978 break
998 break
979
999
980 # csize = self.fileSize - self.fp.tell()
1000 # csize = self.fileSize - self.fp.tell()
981 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1001 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
982 # factor = int(csize/neededsize)
1002 # factor = int(csize/neededsize)
983 # if factor > 0:
1003 # if factor > 0:
984 # self.fp.seek(self.fp.tell() + factor*neededsize)
1004 # self.fp.seek(self.fp.tell() + factor*neededsize)
985
1005
986 self.flagIsNewFile = 0
1006 self.flagIsNewFile = 0
987 self.__isFirstTimeOnline = 0
1007 self.__isFirstTimeOnline = 0
988
1008
989 def __setNewBlock(self):
1009 def __setNewBlock(self):
990 #if self.server is None:
1010 # if self.server is None:
991 if self.fp == None:
1011 if self.fp == None:
992 return 0
1012 return 0
993
1013
994 # if self.online:
1014 # if self.online:
995 # self.__jumpToLastBlock()
1015 # self.__jumpToLastBlock()
996
1016
997 if self.flagIsNewFile:
1017 if self.flagIsNewFile:
998 self.lastUTTime = self.basicHeaderObj.utc
1018 self.lastUTTime = self.basicHeaderObj.utc
999 return 1
1019 return 1
1000
1020
1001 if self.realtime:
1021 if self.realtime:
1002 self.flagDiscontinuousBlock = 1
1022 self.flagDiscontinuousBlock = 1
1003 if not(self.setNextFile()):
1023 if not(self.setNextFile()):
1004 return 0
1024 return 0
1005 else:
1025 else:
1006 return 1
1026 return 1
1007 #if self.server is None:
1027 # if self.server is None:
1008 currentSize = self.fileSize - self.fp.tell()
1028 currentSize = self.fileSize - self.fp.tell()
1009 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1029 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
1010 if (currentSize >= neededSize):
1030 if (currentSize >= neededSize):
1011 self.basicHeaderObj.read(self.fp)
1031 self.basicHeaderObj.read(self.fp)
1012 self.lastUTTime = self.basicHeaderObj.utc
1032 self.lastUTTime = self.basicHeaderObj.utc
1013 return 1
1033 return 1
1014 # else:
1034 # else:
1015 # self.basicHeaderObj.read(self.zHeader)
1035 # self.basicHeaderObj.read(self.zHeader)
1016 # self.lastUTTime = self.basicHeaderObj.utc
1036 # self.lastUTTime = self.basicHeaderObj.utc
1017 # return 1
1037 # return 1
1018 if self.__waitNewBlock():
1038 if self.__waitNewBlock():
1019 self.lastUTTime = self.basicHeaderObj.utc
1039 self.lastUTTime = self.basicHeaderObj.utc
1020 return 1
1040 return 1
1021 #if self.server is None:
1041 # if self.server is None:
1022 if not(self.setNextFile()):
1042 if not(self.setNextFile()):
1023 return 0
1043 return 0
1024
1044
1025 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
1045 deltaTime = self.basicHeaderObj.utc - self.lastUTTime
1026 self.lastUTTime = self.basicHeaderObj.utc
1046 self.lastUTTime = self.basicHeaderObj.utc
1027
1047
1028 self.flagDiscontinuousBlock = 0
1048 self.flagDiscontinuousBlock = 0
1029
1049
1030 if deltaTime > self.maxTimeStep:
1050 if deltaTime > self.maxTimeStep:
1031 self.flagDiscontinuousBlock = 1
1051 self.flagDiscontinuousBlock = 1
1032
1052
1033 return 1
1053 return 1
1034
1054
1035 def readNextBlock(self):
1055 def readNextBlock(self):
1036
1056
1037 #Skip block out of startTime and endTime
1057 # Skip block out of startTime and endTime
1038 while True:
1058 while True:
1039 if not(self.__setNewBlock()):
1059 if not(self.__setNewBlock()):
1040 return 0
1060 return 0
1041
1061
1042 if not(self.readBlock()):
1062 if not(self.readBlock()):
1043 return 0
1063 return 0
1044
1064
1045 self.getBasicHeader()
1065 self.getBasicHeader()
1046
1066 if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
1047 if not isTimeInRange(self.dataOut.datatime.time(), self.startTime, self.endTime):
1048
1049 print "[Reading] Block No. %d/%d -> %s [Skipping]" %(self.nReadBlocks,
1067 print "[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
1050 self.processingHeaderObj.dataBlocksPerFile,
1068 self.processingHeaderObj.dataBlocksPerFile,
1051 self.dataOut.datatime.ctime())
1069 self.dataOut.datatime.ctime())
1052 continue
1070 continue
1053
1071
1054 break
1072 break
1055
1073
1056 if self.verbose:
1074 if self.verbose:
1057 print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1075 print "[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks,
1058 self.processingHeaderObj.dataBlocksPerFile,
1076 self.processingHeaderObj.dataBlocksPerFile,
1059 self.dataOut.datatime.ctime())
1077 self.dataOut.datatime.ctime())
1060 return 1
1078 return 1
1061
1079
1062 def __readFirstHeader(self):
1080 def __readFirstHeader(self):
1063
1081
1064 self.basicHeaderObj.read(self.fp)
1082 self.basicHeaderObj.read(self.fp)
1065 self.systemHeaderObj.read(self.fp)
1083 self.systemHeaderObj.read(self.fp)
1066 self.radarControllerHeaderObj.read(self.fp)
1084 self.radarControllerHeaderObj.read(self.fp)
1067 self.processingHeaderObj.read(self.fp)
1085 self.processingHeaderObj.read(self.fp)
1068
1086
1069 self.firstHeaderSize = self.basicHeaderObj.size
1087 self.firstHeaderSize = self.basicHeaderObj.size
1070
1088
1071 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
1089 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
1090 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
1072 if datatype == 0:
1091 if datatype == 0:
1073 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
1092 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
1074 elif datatype == 1:
1093 elif datatype == 1:
1075 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
1094 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
1076 elif datatype == 2:
1095 elif datatype == 2:
1077 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
1096 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
1078 elif datatype == 3:
1097 elif datatype == 3:
1079 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
1098 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
1080 elif datatype == 4:
1099 elif datatype == 4:
1081 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
1100 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
1082 elif datatype == 5:
1101 elif datatype == 5:
1083 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
1102 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
1084 else:
1103 else:
1085 raise ValueError, 'Data type was not defined'
1104 raise ValueError, 'Data type was not defined'
1086
1105
1087 self.dtype = datatype_str
1106 self.dtype = datatype_str
1088 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1107 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1089 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
1108 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
1109 self.firstHeaderSize + self.basicHeaderSize * \
1110 (self.processingHeaderObj.dataBlocksPerFile - 1)
1090 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1111 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1091 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1112 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1092 self.getBlockDimension()
1113 self.getBlockDimension()
1093
1114
1094 def __verifyFile(self, filename, msgFlag=True):
1115 def __verifyFile(self, filename, msgFlag=True):
1095
1116
1096 msg = None
1117 msg = None
1097
1118
1098 try:
1119 try:
1099 fp = open(filename, 'rb')
1120 fp = open(filename, 'rb')
1100 except IOError:
1121 except IOError:
1101
1122
1102 if msgFlag:
1123 if msgFlag:
1103 print "[Reading] File %s can't be opened" % (filename)
1124 print "[Reading] File %s can't be opened" % (filename)
1104
1125
1105 return False
1126 return False
1106
1127
1107 currentPosition = fp.tell()
1128 currentPosition = fp.tell()
1108 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1129 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
1109
1130
1110 if neededSize == 0:
1131 if neededSize == 0:
1111 basicHeaderObj = BasicHeader(LOCALTIME)
1132 basicHeaderObj = BasicHeader(LOCALTIME)
1112 systemHeaderObj = SystemHeader()
1133 systemHeaderObj = SystemHeader()
1113 radarControllerHeaderObj = RadarControllerHeader()
1134 radarControllerHeaderObj = RadarControllerHeader()
1114 processingHeaderObj = ProcessingHeader()
1135 processingHeaderObj = ProcessingHeader()
1115
1136
1116 if not( basicHeaderObj.read(fp) ):
1137 if not(basicHeaderObj.read(fp)):
1117 fp.close()
1138 fp.close()
1118 return False
1139 return False
1119
1140
1120 if not( systemHeaderObj.read(fp) ):
1141 if not(systemHeaderObj.read(fp)):
1121 fp.close()
1142 fp.close()
1122 return False
1143 return False
1123
1144
1124 if not( radarControllerHeaderObj.read(fp) ):
1145 if not(radarControllerHeaderObj.read(fp)):
1125 fp.close()
1146 fp.close()
1126 return False
1147 return False
1127
1148
1128 if not( processingHeaderObj.read(fp) ):
1149 if not(processingHeaderObj.read(fp)):
1129 fp.close()
1150 fp.close()
1130 return False
1151 return False
1131
1152
1132 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1153 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
1133 else:
1154 else:
1134 msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename
1155 msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename
1135
1156
1136 fp.close()
1157 fp.close()
1137
1158
1138 fileSize = os.path.getsize(filename)
1159 fileSize = os.path.getsize(filename)
1139 currentSize = fileSize - currentPosition
1160 currentSize = fileSize - currentPosition
1140
1161
1141 if currentSize < neededSize:
1162 if currentSize < neededSize:
1142 if msgFlag and (msg != None):
1163 if msgFlag and (msg != None):
1143 print msg
1164 print msg
1144 return False
1165 return False
1145
1166
1146 return True
1167 return True
1147
1168
1148 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1169 def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False):
1149
1170
1150 path_empty = True
1171 path_empty = True
1151
1172
1152 dateList = []
1173 dateList = []
1153 pathList = []
1174 pathList = []
1154
1175
1155 multi_path = path.split(',')
1176 multi_path = path.split(',')
1156
1177
1157 if not walk:
1178 if not walk:
1158
1179
1159 for single_path in multi_path:
1180 for single_path in multi_path:
1160
1181
1161 if not os.path.isdir(single_path):
1182 if not os.path.isdir(single_path):
1162 continue
1183 continue
1163
1184
1164 fileList = glob.glob1(single_path, "*"+ext)
1185 fileList = glob.glob1(single_path, "*" + ext)
1165
1186
1166 if not fileList:
1187 if not fileList:
1167 continue
1188 continue
1168
1189
1169 path_empty = False
1190 path_empty = False
1170
1191
1171 fileList.sort()
1192 fileList.sort()
1172
1193
1173 for thisFile in fileList:
1194 for thisFile in fileList:
1174
1195
1175 if not os.path.isfile(os.path.join(single_path, thisFile)):
1196 if not os.path.isfile(os.path.join(single_path, thisFile)):
1176 continue
1197 continue
1177
1198
1178 if not isRadarFile(thisFile):
1199 if not isRadarFile(thisFile):
1179 continue
1200 continue
1180
1201
1181 if not isFileInDateRange(thisFile, startDate, endDate):
1202 if not isFileInDateRange(thisFile, startDate, endDate):
1182 continue
1203 continue
1183
1204
1184 thisDate = getDateFromRadarFile(thisFile)
1205 thisDate = getDateFromRadarFile(thisFile)
1185
1206
1186 if thisDate in dateList:
1207 if thisDate in dateList:
1187 continue
1208 continue
1188
1209
1189 dateList.append(thisDate)
1210 dateList.append(thisDate)
1190 pathList.append(single_path)
1211 pathList.append(single_path)
1191
1212
1192 else:
1213 else:
1193 for single_path in multi_path:
1214 for single_path in multi_path:
1194
1215
1195 if not os.path.isdir(single_path):
1216 if not os.path.isdir(single_path):
1196 continue
1217 continue
1197
1218
1198 dirList = []
1219 dirList = []
1199
1220
1200 for thisPath in os.listdir(single_path):
1221 for thisPath in os.listdir(single_path):
1201
1222
1202 if not os.path.isdir(os.path.join(single_path,thisPath)):
1223 if not os.path.isdir(os.path.join(single_path, thisPath)):
1203 continue
1224 continue
1204
1225
1205 if not isRadarFolder(thisPath):
1226 if not isRadarFolder(thisPath):
1206 continue
1227 continue
1207
1228
1208 if not isFolderInDateRange(thisPath, startDate, endDate):
1229 if not isFolderInDateRange(thisPath, startDate, endDate):
1209 continue
1230 continue
1210
1231
1211 dirList.append(thisPath)
1232 dirList.append(thisPath)
1212
1233
1213 if not dirList:
1234 if not dirList:
1214 continue
1235 continue
1215
1236
1216 dirList.sort()
1237 dirList.sort()
1217
1238
1218 for thisDir in dirList:
1239 for thisDir in dirList:
1219
1240
1220 datapath = os.path.join(single_path, thisDir, expLabel)
1241 datapath = os.path.join(single_path, thisDir, expLabel)
1221 fileList = glob.glob1(datapath, "*"+ext)
1242 fileList = glob.glob1(datapath, "*" + ext)
1222
1243
1223 if not fileList:
1244 if not fileList:
1224 continue
1245 continue
1225
1246
1226 path_empty = False
1247 path_empty = False
1227
1248
1228 thisDate = getDateFromRadarFolder(thisDir)
1249 thisDate = getDateFromRadarFolder(thisDir)
1229
1250
1230 pathList.append(datapath)
1251 pathList.append(datapath)
1231 dateList.append(thisDate)
1252 dateList.append(thisDate)
1232
1253
1233 dateList.sort()
1254 dateList.sort()
1234
1255
1235 if walk:
1256 if walk:
1236 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1257 pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel)
1237 else:
1258 else:
1238 pattern_path = multi_path[0]
1259 pattern_path = multi_path[0]
1239
1260
1240 if path_empty:
1261 if path_empty:
1241 print "[Reading] No *%s files in %s for %s to %s" %(ext, pattern_path, startDate, endDate)
1262 print "[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate)
1242 else:
1263 else:
1243 if not dateList:
1264 if not dateList:
1244 print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path)
1265 print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path)
1245
1266
1246 if include_path:
1267 if include_path:
1247 return dateList, pathList
1268 return dateList, pathList
1248
1269
1249 return dateList
1270 return dateList
1250
1271
1251 def setup(self,
1272 def setup(self,
1252 path=None,
1273 path=None,
1253 startDate=None,
1274 startDate=None,
1254 endDate=None,
1275 endDate=None,
1255 startTime=datetime.time(0,0,0),
1276 startTime=datetime.time(0, 0, 0),
1256 endTime=datetime.time(23,59,59),
1277 endTime=datetime.time(23, 59, 59),
1257 set=None,
1278 set=None,
1258 expLabel = "",
1279 expLabel="",
1259 ext = None,
1280 ext=None,
1260 online = False,
1281 online=False,
1261 delay = 60,
1282 delay=60,
1262 walk = True,
1283 walk=True,
1263 getblock = False,
1284 getblock=False,
1264 nTxs = 1,
1285 nTxs=1,
1265 realtime=False,
1286 realtime=False,
1266 blocksize=None,
1287 blocksize=None,
1267 blocktime=None,
1288 blocktime=None,
1268 skip=None,
1289 skip=None,
1269 cursor=None,
1290 cursor=None,
1270 warnings=True,
1291 warnings=True,
1271 verbose=True,
1292 verbose=True,
1272 server=None,
1293 server=None,
1273 format=None,
1294 format=None,
1274 oneDDict=None,
1295 oneDDict=None,
1275 twoDDict=None,
1296 twoDDict=None,
1276 ind2DList=None):
1297 ind2DList=None):
1277 if server is not None:
1298 if server is not None:
1278 if 'tcp://' in server:
1299 if 'tcp://' in server:
1279 address = server
1300 address = server
1280 else:
1301 else:
1281 address = 'ipc:///tmp/%s' % server
1302 address = 'ipc:///tmp/%s' % server
1282 self.server = address
1303 self.server = address
1283 self.context = zmq.Context()
1304 self.context = zmq.Context()
1284 self.receiver = self.context.socket(zmq.PULL)
1305 self.receiver = self.context.socket(zmq.PULL)
1285 self.receiver.connect(self.server)
1306 self.receiver.connect(self.server)
1286 time.sleep(0.5)
1307 time.sleep(0.5)
1287 print '[Starting] ReceiverData from {}'.format(self.server)
1308 print '[Starting] ReceiverData from {}'.format(self.server)
1288 else:
1309 else:
1289 self.server = None
1310 self.server = None
1290 if path == None:
1311 if path == None:
1291 raise ValueError, "[Reading] The path is not valid"
1312 raise ValueError, "[Reading] The path is not valid"
1292
1313
1293 if ext == None:
1314 if ext == None:
1294 ext = self.ext
1315 ext = self.ext
1295
1316
1296 if online:
1317 if online:
1297 print "[Reading] Searching files in online mode..."
1318 print "[Reading] Searching files in online mode..."
1298
1319
1299 for nTries in range( self.nTries ):
1320 for nTries in range(self.nTries):
1300 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1321 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(
1322 path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
1301
1323
1302 if fullpath:
1324 if fullpath:
1303 break
1325 break
1304
1326
1305 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
1327 print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1)
1306 sleep( self.delay )
1328 sleep(self.delay)
1307
1329
1308 if not(fullpath):
1330 if not(fullpath):
1309 print "[Reading] There 'isn't any valid file in %s" % path
1331 print "[Reading] There 'isn't any valid file in %s" % path
1310 return
1332 return
1311
1333
1312 self.year = year
1334 self.year = year
1313 self.doy = doy
1335 self.doy = doy
1314 self.set = set - 1
1336 self.set = set - 1
1315 self.path = path
1337 self.path = path
1316 self.foldercounter = foldercounter
1338 self.foldercounter = foldercounter
1317 last_set = None
1339 last_set = None
1318 else:
1340 else:
1319 print "[Reading] Searching files in offline mode ..."
1341 print "[Reading] Searching files in offline mode ..."
1320 pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1342 pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate,
1321 startTime=startTime, endTime=endTime,
1343 startTime=startTime, endTime=endTime,
1322 set=set, expLabel=expLabel, ext=ext,
1344 set=set, expLabel=expLabel, ext=ext,
1323 walk=walk, cursor=cursor,
1345 walk=walk, cursor=cursor,
1324 skip=skip)
1346 skip=skip)
1325
1347
1326 if not(pathList):
1348 if not(pathList):
1327 self.fileIndex = -1
1349 self.fileIndex = -1
1328 self.pathList = []
1350 self.pathList = []
1329 self.filenameList = []
1351 self.filenameList = []
1330 return
1352 return
1331
1353
1332 self.fileIndex = -1
1354 self.fileIndex = -1
1333 self.pathList = pathList
1355 self.pathList = pathList
1334 self.filenameList = filenameList
1356 self.filenameList = filenameList
1335 file_name = os.path.basename(filenameList[-1])
1357 file_name = os.path.basename(filenameList[-1])
1336 basename, ext = os.path.splitext(file_name)
1358 basename, ext = os.path.splitext(file_name)
1337 last_set = int(basename[-3:])
1359 last_set = int(basename[-3:])
1338
1360
1339 self.online = online
1361 self.online = online
1340 self.realtime = realtime
1362 self.realtime = realtime
1341 self.delay = delay
1363 self.delay = delay
1342 ext = ext.lower()
1364 ext = ext.lower()
1343 self.ext = ext
1365 self.ext = ext
1344 self.getByBlock = getblock
1366 self.getByBlock = getblock
1345 self.nTxs = nTxs
1367 self.nTxs = nTxs
1346 self.startTime = startTime
1368 self.startTime = startTime
1347 self.endTime = endTime
1369 self.endTime = endTime
1348
1370 self.endDate = endDate
1371 self.startDate = startDate
1349 #Added-----------------
1372 # Added-----------------
1350 self.selBlocksize = blocksize
1373 self.selBlocksize = blocksize
1351 self.selBlocktime = blocktime
1374 self.selBlocktime = blocktime
1352
1375
1353 # Verbose-----------
1376 # Verbose-----------
1354 self.verbose = verbose
1377 self.verbose = verbose
1355 self.warnings = warnings
1378 self.warnings = warnings
1356
1379
1357 if not(self.setNextFile()):
1380 if not(self.setNextFile()):
1358 if (startDate!=None) and (endDate!=None):
1381 if (startDate != None) and (endDate != None):
1359 print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
1382 print "[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime())
1360 elif startDate != None:
1383 elif startDate != None:
1361 print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
1384 print "[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime())
1362 else:
1385 else:
1363 print "[Reading] No files"
1386 print "[Reading] No files"
1364
1387
1365 self.fileIndex = -1
1388 self.fileIndex = -1
1366 self.pathList = []
1389 self.pathList = []
1367 self.filenameList = []
1390 self.filenameList = []
1368 return
1391 return
1369
1392
1370 # self.getBasicHeader()
1393 # self.getBasicHeader()
1371
1394
1372 if last_set != None:
1395 if last_set != None:
1373 self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1396 self.dataOut.last_block = last_set * \
1397 self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1374 return
1398 return
1375
1399
1376 def getBasicHeader(self):
1400 def getBasicHeader(self):
1377
1401
1378 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1402 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \
1403 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1379
1404
1380 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1405 self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock
1381
1406
1382 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1407 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1383
1408
1384 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1409 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1385
1410
1386 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1411 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1387
1412
1388 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1413 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1389
1414
1390 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
1415 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
1391
1416
1392 # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1417 # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1393
1418
1394
1395 def getFirstHeader(self):
1419 def getFirstHeader(self):
1396
1420
1397 raise NotImplementedError
1421 raise NotImplementedError
1398
1422
1399 def getData(self):
1423 def getData(self):
1400
1424
1401 raise NotImplementedError
1425 raise NotImplementedError
1402
1426
1403 def hasNotDataInBuffer(self):
1427 def hasNotDataInBuffer(self):
1404
1428
1405 raise NotImplementedError
1429 raise NotImplementedError
1406
1430
1407 def readBlock(self):
1431 def readBlock(self):
1408
1432
1409 raise NotImplementedError
1433 raise NotImplementedError
1410
1434
1411 def isEndProcess(self):
1435 def isEndProcess(self):
1412
1436
1413 return self.flagNoMoreFiles
1437 return self.flagNoMoreFiles
1414
1438
1415 def printReadBlocks(self):
1439 def printReadBlocks(self):
1416
1440
1417 print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks
1441 print "[Reading] Number of read blocks per file %04d" % self.nReadBlocks
1418
1442
1419 def printTotalBlocks(self):
1443 def printTotalBlocks(self):
1420
1444
1421 print "[Reading] Number of read blocks %04d" %self.nTotalBlocks
1445 print "[Reading] Number of read blocks %04d" % self.nTotalBlocks
1422
1446
1423 def printNumberOfBlock(self):
1447 def printNumberOfBlock(self):
1424 'SPAM!'
1448 'SPAM!'
1425
1449
1426 # if self.flagIsNewBlock:
1450 # if self.flagIsNewBlock:
1427 # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1451 # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks,
1428 # self.processingHeaderObj.dataBlocksPerFile,
1452 # self.processingHeaderObj.dataBlocksPerFile,
1429 # self.dataOut.datatime.ctime())
1453 # self.dataOut.datatime.ctime())
1430
1454
1431 def printInfo(self):
1455 def printInfo(self):
1432
1456
1433 if self.__printInfo == False:
1457 if self.__printInfo == False:
1434 return
1458 return
1435
1459
1436 self.basicHeaderObj.printInfo()
1460 self.basicHeaderObj.printInfo()
1437 self.systemHeaderObj.printInfo()
1461 self.systemHeaderObj.printInfo()
1438 self.radarControllerHeaderObj.printInfo()
1462 self.radarControllerHeaderObj.printInfo()
1439 self.processingHeaderObj.printInfo()
1463 self.processingHeaderObj.printInfo()
1440
1464
1441 self.__printInfo = False
1465 self.__printInfo = False
1442
1466
1443 def run(self,
1467 def run(self,
1444 path=None,
1468 path=None,
1445 startDate=None,
1469 startDate=None,
1446 endDate=None,
1470 endDate=None,
1447 startTime=datetime.time(0,0,0),
1471 startTime=datetime.time(0, 0, 0),
1448 endTime=datetime.time(23,59,59),
1472 endTime=datetime.time(23, 59, 59),
1449 set=None,
1473 set=None,
1450 expLabel = "",
1474 expLabel="",
1451 ext = None,
1475 ext=None,
1452 online = False,
1476 online=False,
1453 delay = 60,
1477 delay=60,
1454 walk = True,
1478 walk=True,
1455 getblock = False,
1479 getblock=False,
1456 nTxs = 1,
1480 nTxs=1,
1457 realtime=False,
1481 realtime=False,
1458 blocksize=None,
1482 blocksize=None,
1459 blocktime=None,
1483 blocktime=None,
1460 skip=None,
1484 skip=None,
1461 cursor=None,
1485 cursor=None,
1462 warnings=True,
1486 warnings=True,
1463 server=None,
1487 server=None,
1464 verbose=True,
1488 verbose=True,
1465 format=None,
1489 format=None,
1466 oneDDict=None,
1490 oneDDict=None,
1467 twoDDict=None,
1491 twoDDict=None,
1468 ind2DList=None, **kwargs):
1492 ind2DList=None, **kwargs):
1469
1493
1470 if not(self.isConfig):
1494 if not(self.isConfig):
1471 self.setup(path=path,
1495 self.setup(path=path,
1472 startDate=startDate,
1496 startDate=startDate,
1473 endDate=endDate,
1497 endDate=endDate,
1474 startTime=startTime,
1498 startTime=startTime,
1475 endTime=endTime,
1499 endTime=endTime,
1476 set=set,
1500 set=set,
1477 expLabel=expLabel,
1501 expLabel=expLabel,
1478 ext=ext,
1502 ext=ext,
1479 online=online,
1503 online=online,
1480 delay=delay,
1504 delay=delay,
1481 walk=walk,
1505 walk=walk,
1482 getblock=getblock,
1506 getblock=getblock,
1483 nTxs=nTxs,
1507 nTxs=nTxs,
1484 realtime=realtime,
1508 realtime=realtime,
1485 blocksize=blocksize,
1509 blocksize=blocksize,
1486 blocktime=blocktime,
1510 blocktime=blocktime,
1487 skip=skip,
1511 skip=skip,
1488 cursor=cursor,
1512 cursor=cursor,
1489 warnings=warnings,
1513 warnings=warnings,
1490 server=server,
1514 server=server,
1491 verbose=verbose,
1515 verbose=verbose,
1492 format=format,
1516 format=format,
1493 oneDDict=oneDDict,
1517 oneDDict=oneDDict,
1494 twoDDict=twoDDict,
1518 twoDDict=twoDDict,
1495 ind2DList=ind2DList)
1519 ind2DList=ind2DList)
1496 self.isConfig = True
1520 self.isConfig = True
1497 if server is None:
1521 if server is None:
1498 self.getData()
1522 self.getData()
1499 else:
1523 else:
1500 self.getFromServer()
1524 self.getFromServer()
1501
1525
1526
1502 class JRODataWriter(JRODataIO):
1527 class JRODataWriter(JRODataIO):
1503
1528
1504 """
1529 """
1505 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1530 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1506 de los datos siempre se realiza por bloques.
1531 de los datos siempre se realiza por bloques.
1507 """
1532 """
1508
1533
1509 blockIndex = 0
1534 blockIndex = 0
1510
1535
1511 path = None
1536 path = None
1512
1537
1513 setFile = None
1538 setFile = None
1514
1539
1515 profilesPerBlock = None
1540 profilesPerBlock = None
1516
1541
1517 blocksPerFile = None
1542 blocksPerFile = None
1518
1543
1519 nWriteBlocks = 0
1544 nWriteBlocks = 0
1520
1545
1521 fileDate = None
1546 fileDate = None
1522
1547
1523 def __init__(self, dataOut=None):
1548 def __init__(self, dataOut=None):
1524 raise NotImplementedError
1549 raise NotImplementedError
1525
1550
1526
1527 def hasAllDataInBuffer(self):
1551 def hasAllDataInBuffer(self):
1528 raise NotImplementedError
1552 raise NotImplementedError
1529
1553
1530
1531 def setBlockDimension(self):
1554 def setBlockDimension(self):
1532 raise NotImplementedError
1555 raise NotImplementedError
1533
1556
1534
1535 def writeBlock(self):
1557 def writeBlock(self):
1536 raise NotImplementedError
1558 raise NotImplementedError
1537
1559
1538
1539 def putData(self):
1560 def putData(self):
1540 raise NotImplementedError
1561 raise NotImplementedError
1541
1562
1542
1543 def getProcessFlags(self):
1563 def getProcessFlags(self):
1544
1564
1545 processFlags = 0
1565 processFlags = 0
1546
1566
1547 dtype_index = get_dtype_index(self.dtype)
1567 dtype_index = get_dtype_index(self.dtype)
1548 procflag_dtype = get_procflag_dtype(dtype_index)
1568 procflag_dtype = get_procflag_dtype(dtype_index)
1549
1569
1550 processFlags += procflag_dtype
1570 processFlags += procflag_dtype
1551
1571
1552 if self.dataOut.flagDecodeData:
1572 if self.dataOut.flagDecodeData:
1553 processFlags += PROCFLAG.DECODE_DATA
1573 processFlags += PROCFLAG.DECODE_DATA
1554
1574
1555 if self.dataOut.flagDeflipData:
1575 if self.dataOut.flagDeflipData:
1556 processFlags += PROCFLAG.DEFLIP_DATA
1576 processFlags += PROCFLAG.DEFLIP_DATA
1557
1577
1558 if self.dataOut.code is not None:
1578 if self.dataOut.code is not None:
1559 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1579 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
1560
1580
1561 if self.dataOut.nCohInt > 1:
1581 if self.dataOut.nCohInt > 1:
1562 processFlags += PROCFLAG.COHERENT_INTEGRATION
1582 processFlags += PROCFLAG.COHERENT_INTEGRATION
1563
1583
1564 if self.dataOut.type == "Spectra":
1584 if self.dataOut.type == "Spectra":
1565 if self.dataOut.nIncohInt > 1:
1585 if self.dataOut.nIncohInt > 1:
1566 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1586 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
1567
1587
1568 if self.dataOut.data_dc is not None:
1588 if self.dataOut.data_dc is not None:
1569 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1589 processFlags += PROCFLAG.SAVE_CHANNELS_DC
1570
1590
1571 if self.dataOut.flagShiftFFT:
1591 if self.dataOut.flagShiftFFT:
1572 processFlags += PROCFLAG.SHIFT_FFT_DATA
1592 processFlags += PROCFLAG.SHIFT_FFT_DATA
1573
1593
1574 return processFlags
1594 return processFlags
1575
1595
1576 def setBasicHeader(self):
1596 def setBasicHeader(self):
1577
1597
1578 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1598 self.basicHeaderObj.size = self.basicHeaderSize # bytes
1579 self.basicHeaderObj.version = self.versionFile
1599 self.basicHeaderObj.version = self.versionFile
1580 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1600 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1581
1601
1582 utc = numpy.floor(self.dataOut.utctime)
1602 utc = numpy.floor(self.dataOut.utctime)
1583 milisecond = (self.dataOut.utctime - utc)* 1000.0
1603 milisecond = (self.dataOut.utctime - utc) * 1000.0
1584
1604
1585 self.basicHeaderObj.utc = utc
1605 self.basicHeaderObj.utc = utc
1586 self.basicHeaderObj.miliSecond = milisecond
1606 self.basicHeaderObj.miliSecond = milisecond
1587 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1607 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1588 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1608 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1589 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1609 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1590
1610
1591 def setFirstHeader(self):
1611 def setFirstHeader(self):
1592 """
1612 """
1593 Obtiene una copia del First Header
1613 Obtiene una copia del First Header
1594
1614
1595 Affected:
1615 Affected:
1596
1616
1597 self.basicHeaderObj
1617 self.basicHeaderObj
1598 self.systemHeaderObj
1618 self.systemHeaderObj
1599 self.radarControllerHeaderObj
1619 self.radarControllerHeaderObj
1600 self.processingHeaderObj self.
1620 self.processingHeaderObj self.
1601
1621
1602 Return:
1622 Return:
1603 None
1623 None
1604 """
1624 """
1605
1625
1606 raise NotImplementedError
1626 raise NotImplementedError
1607
1627
1608 def __writeFirstHeader(self):
1628 def __writeFirstHeader(self):
1609 """
1629 """
1610 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1630 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1611
1631
1612 Affected:
1632 Affected:
1613 __dataType
1633 __dataType
1614
1634
1615 Return:
1635 Return:
1616 None
1636 None
1617 """
1637 """
1618
1638
1619 # CALCULAR PARAMETROS
1639 # CALCULAR PARAMETROS
1620
1640
1621 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1641 sizeLongHeader = self.systemHeaderObj.size + \
1642 self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1622 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1643 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1623
1644
1624 self.basicHeaderObj.write(self.fp)
1645 self.basicHeaderObj.write(self.fp)
1625 self.systemHeaderObj.write(self.fp)
1646 self.systemHeaderObj.write(self.fp)
1626 self.radarControllerHeaderObj.write(self.fp)
1647 self.radarControllerHeaderObj.write(self.fp)
1627 self.processingHeaderObj.write(self.fp)
1648 self.processingHeaderObj.write(self.fp)
1628
1649
1629 def __setNewBlock(self):
1650 def __setNewBlock(self):
1630 """
1651 """
1631 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1652 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1632
1653
1633 Return:
1654 Return:
1634 0 : si no pudo escribir nada
1655 0 : si no pudo escribir nada
1635 1 : Si escribio el Basic el First Header
1656 1 : Si escribio el Basic el First Header
1636 """
1657 """
1637 if self.fp == None:
1658 if self.fp == None:
1638 self.setNextFile()
1659 self.setNextFile()
1639
1660
1640 if self.flagIsNewFile:
1661 if self.flagIsNewFile:
1641 return 1
1662 return 1
1642
1663
1643 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1664 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1644 self.basicHeaderObj.write(self.fp)
1665 self.basicHeaderObj.write(self.fp)
1645 return 1
1666 return 1
1646
1667
1647 if not( self.setNextFile() ):
1668 if not(self.setNextFile()):
1648 return 0
1669 return 0
1649
1670
1650 return 1
1671 return 1
1651
1672
1652
1653 def writeNextBlock(self):
1673 def writeNextBlock(self):
1654 """
1674 """
1655 Selecciona el bloque siguiente de datos y los escribe en un file
1675 Selecciona el bloque siguiente de datos y los escribe en un file
1656
1676
1657 Return:
1677 Return:
1658 0 : Si no hizo pudo escribir el bloque de datos
1678 0 : Si no hizo pudo escribir el bloque de datos
1659 1 : Si no pudo escribir el bloque de datos
1679 1 : Si no pudo escribir el bloque de datos
1660 """
1680 """
1661 if not( self.__setNewBlock() ):
1681 if not(self.__setNewBlock()):
1662 return 0
1682 return 0
1663
1683
1664 self.writeBlock()
1684 self.writeBlock()
1665
1685
1666 print "[Writing] Block No. %d/%d" %(self.blockIndex,
1686 print "[Writing] Block No. %d/%d" % (self.blockIndex,
1667 self.processingHeaderObj.dataBlocksPerFile)
1687 self.processingHeaderObj.dataBlocksPerFile)
1668
1688
1669 return 1
1689 return 1
1670
1690
1671 def setNextFile(self):
1691 def setNextFile(self):
1672 """
1692 """
1673 Determina el siguiente file que sera escrito
1693 Determina el siguiente file que sera escrito
1674
1694
1675 Affected:
1695 Affected:
1676 self.filename
1696 self.filename
1677 self.subfolder
1697 self.subfolder
1678 self.fp
1698 self.fp
1679 self.setFile
1699 self.setFile
1680 self.flagIsNewFile
1700 self.flagIsNewFile
1681
1701
1682 Return:
1702 Return:
1683 0 : Si el archivo no puede ser escrito
1703 0 : Si el archivo no puede ser escrito
1684 1 : Si el archivo esta listo para ser escrito
1704 1 : Si el archivo esta listo para ser escrito
1685 """
1705 """
1686 ext = self.ext
1706 ext = self.ext
1687 path = self.path
1707 path = self.path
1688
1708
1689 if self.fp != None:
1709 if self.fp != None:
1690 self.fp.close()
1710 self.fp.close()
1691
1711
1692 timeTuple = time.localtime( self.dataOut.utctime)
1712 timeTuple = time.localtime(self.dataOut.utctime)
1693 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1713 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday)
1694
1714
1695 fullpath = os.path.join( path, subfolder )
1715 fullpath = os.path.join(path, subfolder)
1696 setFile = self.setFile
1716 setFile = self.setFile
1697
1717
1698 if not( os.path.exists(fullpath) ):
1718 if not(os.path.exists(fullpath)):
1699 os.mkdir(fullpath)
1719 os.mkdir(fullpath)
1700 setFile = -1 #inicializo mi contador de seteo
1720 setFile = -1 # inicializo mi contador de seteo
1701 else:
1721 else:
1702 filesList = os.listdir( fullpath )
1722 filesList = os.listdir(fullpath)
1703 if len( filesList ) > 0:
1723 if len(filesList) > 0:
1704 filesList = sorted( filesList, key=str.lower )
1724 filesList = sorted(filesList, key=str.lower)
1705 filen = filesList[-1]
1725 filen = filesList[-1]
1706 # el filename debera tener el siguiente formato
1726 # el filename debera tener el siguiente formato
1707 # 0 1234 567 89A BCDE (hex)
1727 # 0 1234 567 89A BCDE (hex)
1708 # x YYYY DDD SSS .ext
1728 # x YYYY DDD SSS .ext
1709 if isNumber( filen[8:11] ):
1729 if isNumber(filen[8:11]):
1710 setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1730 # inicializo mi contador de seteo al seteo del ultimo file
1731 setFile = int(filen[8:11])
1711 else:
1732 else:
1712 setFile = -1
1733 setFile = -1
1713 else:
1734 else:
1714 setFile = -1 #inicializo mi contador de seteo
1735 setFile = -1 # inicializo mi contador de seteo
1715
1736
1716 setFile += 1
1737 setFile += 1
1717
1738
1718 #If this is a new day it resets some values
1739 # If this is a new day it resets some values
1719 if self.dataOut.datatime.date() > self.fileDate:
1740 if self.dataOut.datatime.date() > self.fileDate:
1720 setFile = 0
1741 setFile = 0
1721 self.nTotalBlocks = 0
1742 self.nTotalBlocks = 0
1722
1743
1723 filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext )
1744 filen = '%s%4.4d%3.3d%3.3d%s' % (
1745 self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext)
1724
1746
1725 filename = os.path.join( path, subfolder, filen )
1747 filename = os.path.join(path, subfolder, filen)
1726
1748
1727 fp = open( filename,'wb' )
1749 fp = open(filename, 'wb')
1728
1750
1729 self.blockIndex = 0
1751 self.blockIndex = 0
1730
1752
1731 #guardando atributos
1753 # guardando atributos
1732 self.filename = filename
1754 self.filename = filename
1733 self.subfolder = subfolder
1755 self.subfolder = subfolder
1734 self.fp = fp
1756 self.fp = fp
1735 self.setFile = setFile
1757 self.setFile = setFile
1736 self.flagIsNewFile = 1
1758 self.flagIsNewFile = 1
1737 self.fileDate = self.dataOut.datatime.date()
1759 self.fileDate = self.dataOut.datatime.date()
1738
1760
1739 self.setFirstHeader()
1761 self.setFirstHeader()
1740
1762
1741 print '[Writing] Opening file: %s'%self.filename
1763 print '[Writing] Opening file: %s' % self.filename
1742
1764
1743 self.__writeFirstHeader()
1765 self.__writeFirstHeader()
1744
1766
1745 return 1
1767 return 1
1746
1768
1747 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1769 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4):
1748 """
1770 """
1749 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1771 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1750
1772
1751 Inputs:
1773 Inputs:
1752 path : directory where data will be saved
1774 path : directory where data will be saved
1753 profilesPerBlock : number of profiles per block
1775 profilesPerBlock : number of profiles per block
1754 set : initial file set
1776 set : initial file set
1755 datatype : An integer number that defines data type:
1777 datatype : An integer number that defines data type:
1756 0 : int8 (1 byte)
1778 0 : int8 (1 byte)
1757 1 : int16 (2 bytes)
1779 1 : int16 (2 bytes)
1758 2 : int32 (4 bytes)
1780 2 : int32 (4 bytes)
1759 3 : int64 (8 bytes)
1781 3 : int64 (8 bytes)
1760 4 : float32 (4 bytes)
1782 4 : float32 (4 bytes)
1761 5 : double64 (8 bytes)
1783 5 : double64 (8 bytes)
1762
1784
1763 Return:
1785 Return:
1764 0 : Si no realizo un buen seteo
1786 0 : Si no realizo un buen seteo
1765 1 : Si realizo un buen seteo
1787 1 : Si realizo un buen seteo
1766 """
1788 """
1767
1789
1768 if ext == None:
1790 if ext == None:
1769 ext = self.ext
1791 ext = self.ext
1770
1792
1771 self.ext = ext.lower()
1793 self.ext = ext.lower()
1772
1794
1773 self.path = path
1795 self.path = path
1774
1796
1775 if set is None:
1797 if set is None:
1776 self.setFile = -1
1798 self.setFile = -1
1777 else:
1799 else:
1778 self.setFile = set - 1
1800 self.setFile = set - 1
1779
1801
1780 self.blocksPerFile = blocksPerFile
1802 self.blocksPerFile = blocksPerFile
1781
1803
1782 self.profilesPerBlock = profilesPerBlock
1804 self.profilesPerBlock = profilesPerBlock
1783
1805
1784 self.dataOut = dataOut
1806 self.dataOut = dataOut
1785 self.fileDate = self.dataOut.datatime.date()
1807 self.fileDate = self.dataOut.datatime.date()
1786 #By default
1808 # By default
1787 self.dtype = self.dataOut.dtype
1809 self.dtype = self.dataOut.dtype
1788
1810
1789 if datatype is not None:
1811 if datatype is not None:
1790 self.dtype = get_numpy_dtype(datatype)
1812 self.dtype = get_numpy_dtype(datatype)
1791
1813
1792 if not(self.setNextFile()):
1814 if not(self.setNextFile()):
1793 print "[Writing] There isn't a next file"
1815 print "[Writing] There isn't a next file"
1794 return 0
1816 return 0
1795
1817
1796 self.setBlockDimension()
1818 self.setBlockDimension()
1797
1819
1798 return 1
1820 return 1
1799
1821
1800 def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1822 def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs):
1801
1823
1802 if not(self.isConfig):
1824 if not(self.isConfig):
1803
1825
1804 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, set=set, ext=ext, datatype=datatype, **kwargs)
1826 self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock,
1827 set=set, ext=ext, datatype=datatype, **kwargs)
1805 self.isConfig = True
1828 self.isConfig = True
1806
1829
1807 self.putData()
1830 self.putData()
@@ -1,1154 +1,1182
1 import os, sys
1 import os
2 import sys
2 import glob
3 import glob
3 import fnmatch
4 import fnmatch
4 import datetime
5 import datetime
5 import time
6 import time
6 import re
7 import re
7 import h5py
8 import h5py
8 import numpy
9 import numpy
9 import matplotlib.pyplot as plt
10
10
11 import pylab as plb
11 import pylab as plb
12 from scipy.optimize import curve_fit
12 from scipy.optimize import curve_fit
13 from scipy import asarray as ar, exp
13 from scipy import asarray as ar, exp
14 from scipy import stats
14 from scipy import stats
15
15
16 from numpy.ma.core import getdata
16 from numpy.ma.core import getdata
17
17
18 SPEED_OF_LIGHT = 299792458
18 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 3e8
19 SPEED_OF_LIGHT = 3e8
20
20
21 try:
21 try:
22 from gevent import sleep
22 from gevent import sleep
23 except:
23 except:
24 from time import sleep
24 from time import sleep
25
25
26 from schainpy.model.data.jrodata import Spectra
26 from schainpy.model.data.jrodata import Spectra
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 from numpy import imag, shape, NaN
30 from numpy import imag, shape, NaN
31
31
32 from jroIO_base import JRODataReader
32 from jroIO_base import JRODataReader
33
33
34
34
35 class Header(object):
35 class Header(object):
36
36
37 def __init__(self):
37 def __init__(self):
38 raise NotImplementedError
38 raise NotImplementedError
39
39
40
41 def read(self):
40 def read(self):
42
41
43 raise NotImplementedError
42 raise NotImplementedError
44
43
45 def write(self):
44 def write(self):
46
45
47 raise NotImplementedError
46 raise NotImplementedError
48
47
49 def printInfo(self):
48 def printInfo(self):
50
49
51 message = "#"*50 + "\n"
50 message = "#" * 50 + "\n"
52 message += self.__class__.__name__.upper() + "\n"
51 message += self.__class__.__name__.upper() + "\n"
53 message += "#"*50 + "\n"
52 message += "#" * 50 + "\n"
54
53
55 keyList = self.__dict__.keys()
54 keyList = self.__dict__.keys()
56 keyList.sort()
55 keyList.sort()
57
56
58 for key in keyList:
57 for key in keyList:
59 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
58 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
60
59
61 if "size" not in keyList:
60 if "size" not in keyList:
62 attr = getattr(self, "size")
61 attr = getattr(self, "size")
63
62
64 if attr:
63 if attr:
65 message += "%s = %s" %("size", attr) + "\n"
64 message += "%s = %s" % ("size", attr) + "\n"
66
65
67 #print message
66 # print message
68
67
69
68
70
71
72
73 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
69 FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes
74 ('FileMgcNumber','<u4'), #0x23020100
70 ('FileMgcNumber', '<u4'), # 0x23020100
75 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
71 # No Of FDT data records in this file (0 or more)
72 ('nFDTdataRecors', '<u4'),
76 ('OffsetStartHeader','<u4'),
73 ('OffsetStartHeader', '<u4'),
77 ('RadarUnitId','<u4'),
74 ('RadarUnitId', '<u4'),
78 ('SiteName',numpy.str_,32), #Null terminated
75 ('SiteName', numpy.str_, 32), # Null terminated
79 ])
76 ])
80
77
78
81 class FileHeaderBLTR(Header):
79 class FileHeaderBLTR(Header):
82
80
83 def __init__(self):
81 def __init__(self):
84
82
85 self.FileMgcNumber= 0 #0x23020100
83 self.FileMgcNumber = 0 # 0x23020100
86 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
84 # No Of FDT data records in this file (0 or more)
85 self.nFDTdataRecors = 0
87 self.RadarUnitId= 0
86 self.RadarUnitId = 0
88 self.OffsetStartHeader=0
87 self.OffsetStartHeader = 0
89 self.SiteName= ""
88 self.SiteName = ""
90 self.size = 48
89 self.size = 48
91
90
92 def FHread(self, fp):
91 def FHread(self, fp):
93 #try:
92 # try:
94 startFp = open(fp,"rb")
93 startFp = open(fp, "rb")
95
94
96 header = numpy.fromfile(startFp, FILE_STRUCTURE,1)
95 header = numpy.fromfile(startFp, FILE_STRUCTURE, 1)
97
96
98 print ' '
97 print ' '
99 print 'puntero file header', startFp.tell()
98 print 'puntero file header', startFp.tell()
100 print ' '
99 print ' '
101
100
102
103 ''' numpy.fromfile(file, dtype, count, sep='')
101 ''' numpy.fromfile(file, dtype, count, sep='')
104 file : file or str
102 file : file or str
105 Open file object or filename.
103 Open file object or filename.
106
104
107 dtype : data-type
105 dtype : data-type
108 Data type of the returned array. For binary files, it is used to determine
106 Data type of the returned array. For binary files, it is used to determine
109 the size and byte-order of the items in the file.
107 the size and byte-order of the items in the file.
110
108
111 count : int
109 count : int
112 Number of items to read. -1 means all items (i.e., the complete file).
110 Number of items to read. -1 means all items (i.e., the complete file).
113
111
114 sep : str
112 sep : str
115 Separator between items if file is a text file. Empty ("") separator means
113 Separator between items if file is a text file. Empty ("") separator means
116 the file should be treated as binary. Spaces (" ") in the separator match zero
114 the file should be treated as binary. Spaces (" ") in the separator match zero
117 or more whitespace characters. A separator consisting only of spaces must match
115 or more whitespace characters. A separator consisting only of spaces must match
118 at least one whitespace.
116 at least one whitespace.
119
117
120 '''
118 '''
121
119
122
123
124 self.FileMgcNumber= hex(header['FileMgcNumber'][0])
120 self.FileMgcNumber = hex(header['FileMgcNumber'][0])
125 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
121 # No Of FDT data records in this file (0 or more)
122 self.nFDTdataRecors = int(header['nFDTdataRecors'][0])
126 self.RadarUnitId= int(header['RadarUnitId'][0])
123 self.RadarUnitId = int(header['RadarUnitId'][0])
127 self.OffsetStartHeader= int(header['OffsetStartHeader'][0])
124 self.OffsetStartHeader = int(header['OffsetStartHeader'][0])
128 self.SiteName= str(header['SiteName'][0])
125 self.SiteName = str(header['SiteName'][0])
129
126
130 #print 'Numero de bloques', self.nFDTdataRecors
127 # print 'Numero de bloques', self.nFDTdataRecors
131
128
132
133 if self.size <48:
129 if self.size < 48:
134 return 0
130 return 0
135
131
136 return 1
132 return 1
137
133
138
139 def write(self, fp):
134 def write(self, fp):
140
135
141 headerTuple = (self.FileMgcNumber,
136 headerTuple = (self.FileMgcNumber,
142 self.nFDTdataRecors,
137 self.nFDTdataRecors,
143 self.RadarUnitId,
138 self.RadarUnitId,
144 self.SiteName,
139 self.SiteName,
145 self.size)
140 self.size)
146
141
147
148 header = numpy.array(headerTuple, FILE_STRUCTURE)
142 header = numpy.array(headerTuple, FILE_STRUCTURE)
149 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
143 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
150 header.tofile(fp)
144 header.tofile(fp)
151 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
145 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
152
146
153 fid : file or str
147 fid : file or str
154 An open file object, or a string containing a filename.
148 An open file object, or a string containing a filename.
155
149
156 sep : str
150 sep : str
157 Separator between array items for text output. If "" (empty), a binary file is written,
151 Separator between array items for text output. If "" (empty), a binary file is written,
158 equivalent to file.write(a.tobytes()).
152 equivalent to file.write(a.tobytes()).
159
153
160 format : str
154 format : str
161 Format string for text file output. Each entry in the array is formatted to text by
155 Format string for text file output. Each entry in the array is formatted to text by
162 first converting it to the closest Python type, and then using "format" % item.
156 first converting it to the closest Python type, and then using "format" % item.
163
157
164 '''
158 '''
165
159
166 return 1
160 return 1
167
161
168
162
169
170
171
172 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
163 RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes
173 ('RecMgcNumber','<u4'), #0x23030001
164 ('RecMgcNumber', '<u4'), # 0x23030001
174 ('RecCounter','<u4'), #Record counter(0,1, ...)
165 ('RecCounter', '<u4'), # Record counter(0,1, ...)
175 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
166 # Offset to start of next record form start of this record
176 ('Off2StartData','<u4'), #Offset to start of data from start of this record
167 ('Off2StartNxtRec', '<u4'),
177 ('nUtime','<i4'), #Epoch time stamp of start of acquisition (seconds)
168 # Offset to start of data from start of this record
178 ('nMilisec','<u4'), #Millisecond component of time stamp (0,...,999)
169 ('Off2StartData', '<u4'),
179 ('ExpTagName',numpy.str_,32), #Experiment tag name (null terminated)
170 # Epoch time stamp of start of acquisition (seconds)
180 ('ExpComment',numpy.str_,32), #Experiment comment (null terminated)
171 ('nUtime', '<i4'),
181 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
172 # Millisecond component of time stamp (0,...,999)
182 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
173 ('nMilisec', '<u4'),
183 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
174 # Experiment tag name (null terminated)
175 ('ExpTagName', numpy.str_, 32),
176 # Experiment comment (null terminated)
177 ('ExpComment', numpy.str_, 32),
178 # Site latitude (from GPS) in degrees (positive implies North)
179 ('SiteLatDegrees', '<f4'),
180 # Site longitude (from GPS) in degrees (positive implies East)
181 ('SiteLongDegrees', '<f4'),
182 # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
183 ('RTCgpsStatus', '<u4'),
184 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
184 ('TransmitFrec', '<u4'), # Transmit frequency (Hz)
185 ('ReceiveFrec','<u4'), #Receive frequency
185 ('ReceiveFrec', '<u4'), # Receive frequency
186 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
186 # First local oscillator frequency (Hz)
187 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
187 ('FirstOsciFrec', '<u4'),
188 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
188 # (0="O", 1="E", 2="linear 1", 3="linear2")
189 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
189 ('Polarisation', '<u4'),
190 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
190 # Receiver filter settings (0,1,2,3)
191 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
191 ('ReceiverFiltSett', '<u4'),
192 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
192 # Number of modes in use (1 or 2)
193 ('SampResolution','<u4'), #Sampling resolution (meters)
193 ('nModesInUse', '<u4'),
194 ('nHeights','<u4'), #Number of range gates sampled
194 # Dual Mode index number for these data (0 or 1)
195 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
195 ('DualModeIndex', '<u4'),
196 # Dual Mode range correction for these data (m)
197 ('DualModeRange', '<u4'),
198 # Number of digital channels acquired (2*N)
199 ('nDigChannels', '<u4'),
200 # Sampling resolution (meters)
201 ('SampResolution', '<u4'),
202 # Number of range gates sampled
203 ('nHeights', '<u4'),
204 # Start range of sampling (meters)
205 ('StartRangeSamp', '<u4'),
196 ('PRFhz','<u4'), #PRF (Hz)
206 ('PRFhz', '<u4'), # PRF (Hz)
197 ('nCohInt','<u4'), #Integrations
207 ('nCohInt', '<u4'), # Integrations
198 ('nProfiles','<u4'), #Number of data points transformed
208 # Number of data points transformed
199 ('nChannels','<u4'), #Number of receive beams stored in file (1 or N)
209 ('nProfiles', '<u4'),
210 # Number of receive beams stored in file (1 or N)
211 ('nChannels', '<u4'),
200 ('nIncohInt','<u4'), #Number of spectral averages
212 ('nIncohInt', '<u4'), # Number of spectral averages
201 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
213 # FFT windowing index (0 = no window)
202 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
214 ('FFTwindowingInd', '<u4'),
203 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
215 # Beam steer angle (azimuth) in degrees (clockwise from true North)
204 ('AntennaCoord0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
216 ('BeamAngleAzim', '<f4'),
205 ('AntennaAngl0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
217 # Beam steer angle (zenith) in degrees (0=> vertical)
206 ('AntennaCoord1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
218 ('BeamAngleZen', '<f4'),
207 ('AntennaAngl1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
219 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
208 ('AntennaCoord2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
220 ('AntennaCoord0', '<f4'),
209 ('AntennaAngl2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
221 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
210 ('RecPhaseCalibr0','<f4'), #Receiver phase calibration (degrees) - N values
222 ('AntennaAngl0', '<f4'),
211 ('RecPhaseCalibr1','<f4'), #Receiver phase calibration (degrees) - N values
223 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
212 ('RecPhaseCalibr2','<f4'), #Receiver phase calibration (degrees) - N values
224 ('AntennaCoord1', '<f4'),
213 ('RecAmpCalibr0','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
225 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
214 ('RecAmpCalibr1','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
226 ('AntennaAngl1', '<f4'),
215 ('RecAmpCalibr2','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
227 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
216 ('ReceiverGaindB0','<i4'), #Receiver gains in dB - N values
228 ('AntennaCoord2', '<f4'),
217 ('ReceiverGaindB1','<i4'), #Receiver gains in dB - N values
229 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
218 ('ReceiverGaindB2','<i4'), #Receiver gains in dB - N values
230 ('AntennaAngl2', '<f4'),
231 # Receiver phase calibration (degrees) - N values
232 ('RecPhaseCalibr0', '<f4'),
233 # Receiver phase calibration (degrees) - N values
234 ('RecPhaseCalibr1', '<f4'),
235 # Receiver phase calibration (degrees) - N values
236 ('RecPhaseCalibr2', '<f4'),
237 # Receiver amplitude calibration (ratio relative to receiver one) - N values
238 ('RecAmpCalibr0', '<f4'),
239 # Receiver amplitude calibration (ratio relative to receiver one) - N values
240 ('RecAmpCalibr1', '<f4'),
241 # Receiver amplitude calibration (ratio relative to receiver one) - N values
242 ('RecAmpCalibr2', '<f4'),
243 # Receiver gains in dB - N values
244 ('ReceiverGaindB0', '<i4'),
245 # Receiver gains in dB - N values
246 ('ReceiverGaindB1', '<i4'),
247 # Receiver gains in dB - N values
248 ('ReceiverGaindB2', '<i4'),
219 ])
249 ])
220
250
221
251
222 class RecordHeaderBLTR(Header):
252 class RecordHeaderBLTR(Header):
223
253
224 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 811248,
254 def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248,
225 nUtime= 0, nMilisec= 0, ExpTagName= None,
255 nUtime=0, nMilisec=0, ExpTagName=None,
226 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
256 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0,
227 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
257 RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0,
228 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
258 FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0,
229 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
259 nModesInUse=0, DualModeIndex=0, DualModeRange=0,
230 nDigChannels= 0, SampResolution= 0, nHeights= 0,
260 nDigChannels=0, SampResolution=0, nHeights=0,
231 StartRangeSamp= 0, PRFhz= 0, nCohInt= 0,
261 StartRangeSamp=0, PRFhz=0, nCohInt=0,
232 nProfiles= 0, nChannels= 0, nIncohInt= 0,
262 nProfiles=0, nChannels=0, nIncohInt=0,
233 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
263 FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0,
234 AntennaCoord0= 0, AntennaCoord1= 0, AntennaCoord2= 0,
264 AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0,
235 RecPhaseCalibr0= 0, RecPhaseCalibr1= 0, RecPhaseCalibr2= 0,
265 RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0,
236 RecAmpCalibr0= 0, RecAmpCalibr1= 0, RecAmpCalibr2= 0,
266 RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0,
237 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
267 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
238 ReceiverGaindB0= 0, ReceiverGaindB1= 0, ReceiverGaindB2= 0, Off2StartData=0, OffsetStartHeader=0):
268 ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0):
239
269
240 self.RecMgcNumber = RecMgcNumber #0x23030001
270 self.RecMgcNumber = RecMgcNumber # 0x23030001
241 self.RecCounter = RecCounter
271 self.RecCounter = RecCounter
242 self.Off2StartNxtRec = Off2StartNxtRec
272 self.Off2StartNxtRec = Off2StartNxtRec
243 self.Off2StartData = Off2StartData
273 self.Off2StartData = Off2StartData
244 self.nUtime = nUtime
274 self.nUtime = nUtime
245 self.nMilisec = nMilisec
275 self.nMilisec = nMilisec
246 self.ExpTagName = ExpTagName
276 self.ExpTagName = ExpTagName
247 self.ExpComment = ExpComment
277 self.ExpComment = ExpComment
248 self.SiteLatDegrees = SiteLatDegrees
278 self.SiteLatDegrees = SiteLatDegrees
249 self.SiteLongDegrees = SiteLongDegrees
279 self.SiteLongDegrees = SiteLongDegrees
250 self.RTCgpsStatus = RTCgpsStatus
280 self.RTCgpsStatus = RTCgpsStatus
251 self.TransmitFrec = TransmitFrec
281 self.TransmitFrec = TransmitFrec
252 self.ReceiveFrec = ReceiveFrec
282 self.ReceiveFrec = ReceiveFrec
253 self.FirstOsciFrec = FirstOsciFrec
283 self.FirstOsciFrec = FirstOsciFrec
254 self.Polarisation = Polarisation
284 self.Polarisation = Polarisation
255 self.ReceiverFiltSett = ReceiverFiltSett
285 self.ReceiverFiltSett = ReceiverFiltSett
256 self.nModesInUse = nModesInUse
286 self.nModesInUse = nModesInUse
257 self.DualModeIndex = DualModeIndex
287 self.DualModeIndex = DualModeIndex
258 self.DualModeRange = DualModeRange
288 self.DualModeRange = DualModeRange
259 self.nDigChannels = nDigChannels
289 self.nDigChannels = nDigChannels
260 self.SampResolution = SampResolution
290 self.SampResolution = SampResolution
261 self.nHeights = nHeights
291 self.nHeights = nHeights
262 self.StartRangeSamp = StartRangeSamp
292 self.StartRangeSamp = StartRangeSamp
263 self.PRFhz = PRFhz
293 self.PRFhz = PRFhz
264 self.nCohInt = nCohInt
294 self.nCohInt = nCohInt
265 self.nProfiles = nProfiles
295 self.nProfiles = nProfiles
266 self.nChannels = nChannels
296 self.nChannels = nChannels
267 self.nIncohInt = nIncohInt
297 self.nIncohInt = nIncohInt
268 self.FFTwindowingInd = FFTwindowingInd
298 self.FFTwindowingInd = FFTwindowingInd
269 self.BeamAngleAzim = BeamAngleAzim
299 self.BeamAngleAzim = BeamAngleAzim
270 self.BeamAngleZen = BeamAngleZen
300 self.BeamAngleZen = BeamAngleZen
271 self.AntennaCoord0 = AntennaCoord0
301 self.AntennaCoord0 = AntennaCoord0
272 self.AntennaAngl0 = AntennaAngl0
302 self.AntennaAngl0 = AntennaAngl0
273 self.AntennaAngl1 = AntennaAngl1
303 self.AntennaAngl1 = AntennaAngl1
274 self.AntennaAngl2 = AntennaAngl2
304 self.AntennaAngl2 = AntennaAngl2
275 self.AntennaCoord1 = AntennaCoord1
305 self.AntennaCoord1 = AntennaCoord1
276 self.AntennaCoord2 = AntennaCoord2
306 self.AntennaCoord2 = AntennaCoord2
277 self.RecPhaseCalibr0 = RecPhaseCalibr0
307 self.RecPhaseCalibr0 = RecPhaseCalibr0
278 self.RecPhaseCalibr1 = RecPhaseCalibr1
308 self.RecPhaseCalibr1 = RecPhaseCalibr1
279 self.RecPhaseCalibr2 = RecPhaseCalibr2
309 self.RecPhaseCalibr2 = RecPhaseCalibr2
280 self.RecAmpCalibr0 = RecAmpCalibr0
310 self.RecAmpCalibr0 = RecAmpCalibr0
281 self.RecAmpCalibr1 = RecAmpCalibr1
311 self.RecAmpCalibr1 = RecAmpCalibr1
282 self.RecAmpCalibr2 = RecAmpCalibr2
312 self.RecAmpCalibr2 = RecAmpCalibr2
283 self.ReceiverGaindB0 = ReceiverGaindB0
313 self.ReceiverGaindB0 = ReceiverGaindB0
284 self.ReceiverGaindB1 = ReceiverGaindB1
314 self.ReceiverGaindB1 = ReceiverGaindB1
285 self.ReceiverGaindB2 = ReceiverGaindB2
315 self.ReceiverGaindB2 = ReceiverGaindB2
286 self.OffsetStartHeader = 48
316 self.OffsetStartHeader = 48
287
317
288
289
290 def RHread(self, fp):
318 def RHread(self, fp):
291 #print fp
319 # print fp
292 #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
320 # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
293 startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
321 # The method tell() returns the current position of the file read/write pointer within the file.
322 startFp = open(fp, "rb")
294 #RecCounter=0
323 # RecCounter=0
295 #Off2StartNxtRec=811248
324 # Off2StartNxtRec=811248
296 OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
325 OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
297 print ' '
326 print ' '
298 print 'puntero Record Header', startFp.tell()
327 print 'puntero Record Header', startFp.tell()
299 print ' '
328 print ' '
300
329
301
302 startFp.seek(OffRHeader, os.SEEK_SET)
330 startFp.seek(OffRHeader, os.SEEK_SET)
303
331
304 print ' '
332 print ' '
305 print 'puntero Record Header con seek', startFp.tell()
333 print 'puntero Record Header con seek', startFp.tell()
306 print ' '
334 print ' '
307
335
308 #print 'Posicion del bloque: ',OffRHeader
336 # print 'Posicion del bloque: ',OffRHeader
309
337
310 header = numpy.fromfile(startFp,RECORD_STRUCTURE,1)
338 header = numpy.fromfile(startFp, RECORD_STRUCTURE, 1)
311
339
312 print ' '
340 print ' '
313 print 'puntero Record Header con seek', startFp.tell()
341 print 'puntero Record Header con seek', startFp.tell()
314 print ' '
342 print ' '
315
343
316 print ' '
344 print ' '
317 #
345 #
318 #print 'puntero Record Header despues de seek', header.tell()
346 # print 'puntero Record Header despues de seek', header.tell()
319 print ' '
347 print ' '
320
348
321 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) #0x23030001
349 self.RecMgcNumber = hex(header['RecMgcNumber'][0]) # 0x23030001
322 self.RecCounter = int(header['RecCounter'][0])
350 self.RecCounter = int(header['RecCounter'][0])
323 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
351 self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0])
324 self.Off2StartData = int(header['Off2StartData'][0])
352 self.Off2StartData = int(header['Off2StartData'][0])
325 self.nUtime = header['nUtime'][0]
353 self.nUtime = header['nUtime'][0]
326 self.nMilisec = header['nMilisec'][0]
354 self.nMilisec = header['nMilisec'][0]
327 self.ExpTagName = str(header['ExpTagName'][0])
355 self.ExpTagName = str(header['ExpTagName'][0])
328 self.ExpComment = str(header['ExpComment'][0])
356 self.ExpComment = str(header['ExpComment'][0])
329 self.SiteLatDegrees = header['SiteLatDegrees'][0]
357 self.SiteLatDegrees = header['SiteLatDegrees'][0]
330 self.SiteLongDegrees = header['SiteLongDegrees'][0]
358 self.SiteLongDegrees = header['SiteLongDegrees'][0]
331 self.RTCgpsStatus = header['RTCgpsStatus'][0]
359 self.RTCgpsStatus = header['RTCgpsStatus'][0]
332 self.TransmitFrec = header['TransmitFrec'][0]
360 self.TransmitFrec = header['TransmitFrec'][0]
333 self.ReceiveFrec = header['ReceiveFrec'][0]
361 self.ReceiveFrec = header['ReceiveFrec'][0]
334 self.FirstOsciFrec = header['FirstOsciFrec'][0]
362 self.FirstOsciFrec = header['FirstOsciFrec'][0]
335 self.Polarisation = header['Polarisation'][0]
363 self.Polarisation = header['Polarisation'][0]
336 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
364 self.ReceiverFiltSett = header['ReceiverFiltSett'][0]
337 self.nModesInUse = header['nModesInUse'][0]
365 self.nModesInUse = header['nModesInUse'][0]
338 self.DualModeIndex = header['DualModeIndex'][0]
366 self.DualModeIndex = header['DualModeIndex'][0]
339 self.DualModeRange = header['DualModeRange'][0]
367 self.DualModeRange = header['DualModeRange'][0]
340 self.nDigChannels = header['nDigChannels'][0]
368 self.nDigChannels = header['nDigChannels'][0]
341 self.SampResolution = header['SampResolution'][0]
369 self.SampResolution = header['SampResolution'][0]
342 self.nHeights = header['nHeights'][0]
370 self.nHeights = header['nHeights'][0]
343 self.StartRangeSamp = header['StartRangeSamp'][0]
371 self.StartRangeSamp = header['StartRangeSamp'][0]
344 self.PRFhz = header['PRFhz'][0]
372 self.PRFhz = header['PRFhz'][0]
345 self.nCohInt = header['nCohInt'][0]
373 self.nCohInt = header['nCohInt'][0]
346 self.nProfiles = header['nProfiles'][0]
374 self.nProfiles = header['nProfiles'][0]
347 self.nChannels = header['nChannels'][0]
375 self.nChannels = header['nChannels'][0]
348 self.nIncohInt = header['nIncohInt'][0]
376 self.nIncohInt = header['nIncohInt'][0]
349 self.FFTwindowingInd = header['FFTwindowingInd'][0]
377 self.FFTwindowingInd = header['FFTwindowingInd'][0]
350 self.BeamAngleAzim = header['BeamAngleAzim'][0]
378 self.BeamAngleAzim = header['BeamAngleAzim'][0]
351 self.BeamAngleZen = header['BeamAngleZen'][0]
379 self.BeamAngleZen = header['BeamAngleZen'][0]
352 self.AntennaCoord0 = header['AntennaCoord0'][0]
380 self.AntennaCoord0 = header['AntennaCoord0'][0]
353 self.AntennaAngl0 = header['AntennaAngl0'][0]
381 self.AntennaAngl0 = header['AntennaAngl0'][0]
354 self.AntennaCoord1 = header['AntennaCoord1'][0]
382 self.AntennaCoord1 = header['AntennaCoord1'][0]
355 self.AntennaAngl1 = header['AntennaAngl1'][0]
383 self.AntennaAngl1 = header['AntennaAngl1'][0]
356 self.AntennaCoord2 = header['AntennaCoord2'][0]
384 self.AntennaCoord2 = header['AntennaCoord2'][0]
357 self.AntennaAngl2 = header['AntennaAngl2'][0]
385 self.AntennaAngl2 = header['AntennaAngl2'][0]
358 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
386 self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0]
359 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
387 self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0]
360 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
388 self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0]
361 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
389 self.RecAmpCalibr0 = header['RecAmpCalibr0'][0]
362 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
390 self.RecAmpCalibr1 = header['RecAmpCalibr1'][0]
363 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
391 self.RecAmpCalibr2 = header['RecAmpCalibr2'][0]
364 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
392 self.ReceiverGaindB0 = header['ReceiverGaindB0'][0]
365 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
393 self.ReceiverGaindB1 = header['ReceiverGaindB1'][0]
366 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
394 self.ReceiverGaindB2 = header['ReceiverGaindB2'][0]
367
395
368 self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
396 self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz)
369
397
370 self.RHsize = 180+20*self.nChannels
398 self.RHsize = 180 + 20 * self.nChannels
371 self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
399 self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4
372 #print 'Datasize',self.Datasize
400 # print 'Datasize',self.Datasize
373 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
401 endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
374
402
375 print '=============================================='
403 print '=============================================='
376 print 'RecMgcNumber ',self.RecMgcNumber
404 print 'RecMgcNumber ', self.RecMgcNumber
377 print 'RecCounter ',self.RecCounter
405 print 'RecCounter ', self.RecCounter
378 print 'Off2StartNxtRec ',self.Off2StartNxtRec
406 print 'Off2StartNxtRec ', self.Off2StartNxtRec
379 print 'Off2StartData ',self.Off2StartData
407 print 'Off2StartData ', self.Off2StartData
380 print 'Range Resolution ',self.SampResolution
408 print 'Range Resolution ', self.SampResolution
381 print 'First Height ',self.StartRangeSamp
409 print 'First Height ', self.StartRangeSamp
382 print 'PRF (Hz) ',self.PRFhz
410 print 'PRF (Hz) ', self.PRFhz
383 print 'Heights (K) ',self.nHeights
411 print 'Heights (K) ', self.nHeights
384 print 'Channels (N) ',self.nChannels
412 print 'Channels (N) ', self.nChannels
385 print 'Profiles (J) ',self.nProfiles
413 print 'Profiles (J) ', self.nProfiles
386 print 'iCoh ',self.nCohInt
414 print 'iCoh ', self.nCohInt
387 print 'iInCoh ',self.nIncohInt
415 print 'iInCoh ', self.nIncohInt
388 print 'BeamAngleAzim ',self.BeamAngleAzim
416 print 'BeamAngleAzim ', self.BeamAngleAzim
389 print 'BeamAngleZen ',self.BeamAngleZen
417 print 'BeamAngleZen ', self.BeamAngleZen
390
418
391 #print 'ModoEnUso ',self.DualModeIndex
419 # print 'ModoEnUso ',self.DualModeIndex
392 #print 'UtcTime ',self.nUtime
420 # print 'UtcTime ',self.nUtime
393 #print 'MiliSec ',self.nMilisec
421 # print 'MiliSec ',self.nMilisec
394 #print 'Exp TagName ',self.ExpTagName
422 # print 'Exp TagName ',self.ExpTagName
395 #print 'Exp Comment ',self.ExpComment
423 # print 'Exp Comment ',self.ExpComment
396 #print 'FFT Window Index ',self.FFTwindowingInd
424 # print 'FFT Window Index ',self.FFTwindowingInd
397 #print 'N Dig. Channels ',self.nDigChannels
425 # print 'N Dig. Channels ',self.nDigChannels
398 print 'Size de bloque ',self.RHsize
426 print 'Size de bloque ', self.RHsize
399 print 'DataSize ',self.Datasize
427 print 'DataSize ', self.Datasize
400 print 'BeamAngleAzim ',self.BeamAngleAzim
428 print 'BeamAngleAzim ', self.BeamAngleAzim
401 #print 'AntennaCoord0 ',self.AntennaCoord0
429 # print 'AntennaCoord0 ',self.AntennaCoord0
402 #print 'AntennaAngl0 ',self.AntennaAngl0
430 # print 'AntennaAngl0 ',self.AntennaAngl0
403 #print 'AntennaCoord1 ',self.AntennaCoord1
431 # print 'AntennaCoord1 ',self.AntennaCoord1
404 #print 'AntennaAngl1 ',self.AntennaAngl1
432 # print 'AntennaAngl1 ',self.AntennaAngl1
405 #print 'AntennaCoord2 ',self.AntennaCoord2
433 # print 'AntennaCoord2 ',self.AntennaCoord2
406 #print 'AntennaAngl2 ',self.AntennaAngl2
434 # print 'AntennaAngl2 ',self.AntennaAngl2
407 print 'RecPhaseCalibr0 ',self.RecPhaseCalibr0
435 print 'RecPhaseCalibr0 ', self.RecPhaseCalibr0
408 print 'RecPhaseCalibr1 ',self.RecPhaseCalibr1
436 print 'RecPhaseCalibr1 ', self.RecPhaseCalibr1
409 print 'RecPhaseCalibr2 ',self.RecPhaseCalibr2
437 print 'RecPhaseCalibr2 ', self.RecPhaseCalibr2
410 print 'RecAmpCalibr0 ',self.RecAmpCalibr0
438 print 'RecAmpCalibr0 ', self.RecAmpCalibr0
411 print 'RecAmpCalibr1 ',self.RecAmpCalibr1
439 print 'RecAmpCalibr1 ', self.RecAmpCalibr1
412 print 'RecAmpCalibr2 ',self.RecAmpCalibr2
440 print 'RecAmpCalibr2 ', self.RecAmpCalibr2
413 print 'ReceiverGaindB0 ',self.ReceiverGaindB0
441 print 'ReceiverGaindB0 ', self.ReceiverGaindB0
414 print 'ReceiverGaindB1 ',self.ReceiverGaindB1
442 print 'ReceiverGaindB1 ', self.ReceiverGaindB1
415 print 'ReceiverGaindB2 ',self.ReceiverGaindB2
443 print 'ReceiverGaindB2 ', self.ReceiverGaindB2
416 print '=============================================='
444 print '=============================================='
417
445
418 if OffRHeader > endFp:
446 if OffRHeader > endFp:
419 sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp)
447 sys.stderr.write(
448 "Warning %s: Size value read from System Header is lower than it has to be\n" % fp)
420 return 0
449 return 0
421
450
422 if OffRHeader < endFp:
451 if OffRHeader < endFp:
423 sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp)
452 sys.stderr.write(
453 "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp)
424 return 0
454 return 0
425
455
426 return 1
456 return 1
427
457
428
458
429 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
459 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader):
430
460
431 path = None
461 path = None
432 startDate = None
462 startDate = None
433 endDate = None
463 endDate = None
434 startTime = None
464 startTime = None
435 endTime = None
465 endTime = None
436 walk = None
466 walk = None
437 isConfig = False
467 isConfig = False
438
468
439
440 fileList= None
469 fileList = None
441
470
442 #metadata
471 # metadata
443 TimeZone= None
472 TimeZone = None
444 Interval= None
473 Interval = None
445 heightList= None
474 heightList = None
446
475
447 #data
476 # data
448 data= None
477 data = None
449 utctime= None
478 utctime = None
450
479
451
452
453 def __init__(self, **kwargs):
480 def __init__(self, **kwargs):
454
481
455 #Eliminar de la base la herencia
482 # Eliminar de la base la herencia
456 ProcessingUnit.__init__(self, **kwargs)
483 ProcessingUnit.__init__(self, **kwargs)
457
484
458 #self.isConfig = False
485 #self.isConfig = False
459
486
460 #self.pts2read_SelfSpectra = 0
487 #self.pts2read_SelfSpectra = 0
461 #self.pts2read_CrossSpectra = 0
488 #self.pts2read_CrossSpectra = 0
462 #self.pts2read_DCchannels = 0
489 #self.pts2read_DCchannels = 0
463 #self.datablock = None
490 #self.datablock = None
464 self.utc = None
491 self.utc = None
465 self.ext = ".fdt"
492 self.ext = ".fdt"
466 self.optchar = "P"
493 self.optchar = "P"
467 self.fpFile=None
494 self.fpFile = None
468 self.fp = None
495 self.fp = None
469 self.BlockCounter=0
496 self.BlockCounter = 0
470 self.dtype = None
497 self.dtype = None
471 self.fileSizeByHeader = None
498 self.fileSizeByHeader = None
472 self.filenameList = []
499 self.filenameList = []
473 self.fileSelector = 0
500 self.fileSelector = 0
474 self.Off2StartNxtRec=0
501 self.Off2StartNxtRec = 0
475 self.RecCounter=0
502 self.RecCounter = 0
476 self.flagNoMoreFiles = 0
503 self.flagNoMoreFiles = 0
477 self.data_spc=None
504 self.data_spc = None
478 self.data_cspc=None
505 self.data_cspc = None
479 self.data_output=None
506 self.data_output = None
480 self.path = None
507 self.path = None
481 self.OffsetStartHeader=0
508 self.OffsetStartHeader = 0
482 self.Off2StartData=0
509 self.Off2StartData = 0
483 self.ipp = 0
510 self.ipp = 0
484 self.nFDTdataRecors=0
511 self.nFDTdataRecors = 0
485 self.blocksize = 0
512 self.blocksize = 0
486 self.dataOut = Spectra()
513 self.dataOut = Spectra()
487 self.profileIndex = 1 #Always
514 self.profileIndex = 1 # Always
488 self.dataOut.flagNoData=False
515 self.dataOut.flagNoData = False
489 self.dataOut.nRdPairs = 0
516 self.dataOut.nRdPairs = 0
490 self.dataOut.pairsList = []
517 self.dataOut.pairsList = []
491 self.dataOut.data_spc=None
518 self.dataOut.data_spc = None
492 self.dataOut.noise=[]
519 self.dataOut.noise = []
493 self.dataOut.velocityX=[]
520 self.dataOut.velocityX = []
494 self.dataOut.velocityY=[]
521 self.dataOut.velocityY = []
495 self.dataOut.velocityV=[]
522 self.dataOut.velocityV = []
496
523
497
498
499 def Files2Read(self, fp):
524 def Files2Read(self, fp):
500 '''
525 '''
501 Function that indicates the number of .fdt files that exist in the folder to be read.
526 Function that indicates the number of .fdt files that exist in the folder to be read.
502 It also creates an organized list with the names of the files to read.
527 It also creates an organized list with the names of the files to read.
503 '''
528 '''
504 #self.__checkPath()
529 # self.__checkPath()
505
530
506 ListaData=os.listdir(fp) #Gets the list of files within the fp address
531 # Gets the list of files within the fp address
507 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
532 ListaData = os.listdir(fp)
533 # Sort the list of files from least to largest by names
534 ListaData = sorted(ListaData)
508 nFiles=0 #File Counter
535 nFiles = 0 # File Counter
509 FileList=[] #A list is created that will contain the .fdt files
536 FileList = [] # A list is created that will contain the .fdt files
510 for IndexFile in ListaData :
537 for IndexFile in ListaData:
511 if '.fdt' in IndexFile:
538 if '.fdt' in IndexFile:
512 FileList.append(IndexFile)
539 FileList.append(IndexFile)
513 nFiles+=1
540 nFiles += 1
514
541
515 #print 'Files2Read'
542 # print 'Files2Read'
516 #print 'Existen '+str(nFiles)+' archivos .fdt'
543 # print 'Existen '+str(nFiles)+' archivos .fdt'
517
544
518 self.filenameList=FileList #List of files from least to largest by names
545 self.filenameList = FileList # List of files from least to largest by names
519
546
520
521 def run(self, **kwargs):
547 def run(self, **kwargs):
522 '''
548 '''
523 This method will be the one that will initiate the data entry, will be called constantly.
549 This method will be the one that will initiate the data entry, will be called constantly.
524 You should first verify that your Setup () is set up and then continue to acquire
550 You should first verify that your Setup () is set up and then continue to acquire
525 the data to be processed with getData ().
551 the data to be processed with getData ().
526 '''
552 '''
527 if not self.isConfig:
553 if not self.isConfig:
528 self.setup(**kwargs)
554 self.setup(**kwargs)
529 self.isConfig = True
555 self.isConfig = True
530
556
531 self.getData()
557 self.getData()
532 #print 'running'
558 # print 'running'
533
559
534
535 def setup(self, path=None,
560 def setup(self, path=None,
536 startDate=None,
561 startDate=None,
537 endDate=None,
562 endDate=None,
538 startTime=None,
563 startTime=None,
539 endTime=None,
564 endTime=None,
540 walk=True,
565 walk=True,
541 timezone='utc',
566 timezone='utc',
542 code = None,
567 code=None,
543 online=False,
568 online=False,
544 ReadMode=None,
569 ReadMode=None,
545 **kwargs):
570 **kwargs):
546
571
547 self.isConfig = True
572 self.isConfig = True
548
573
549 self.path=path
574 self.path = path
550 self.startDate=startDate
575 self.startDate = startDate
551 self.endDate=endDate
576 self.endDate = endDate
552 self.startTime=startTime
577 self.startTime = startTime
553 self.endTime=endTime
578 self.endTime = endTime
554 self.walk=walk
579 self.walk = walk
555 self.ReadMode=int(ReadMode)
580 self.ReadMode = int(ReadMode)
556
581
557 pass
582 pass
558
583
559
560 def getData(self):
584 def getData(self):
561 '''
585 '''
562 Before starting this function, you should check that there is still an unread file,
586 Before starting this function, you should check that there is still an unread file,
563 If there are still blocks to read or if the data block is empty.
587 If there are still blocks to read or if the data block is empty.
564
588
565 You should call the file "read".
589 You should call the file "read".
566
590
567 '''
591 '''
568
592
569 if self.flagNoMoreFiles:
593 if self.flagNoMoreFiles:
570 self.dataOut.flagNoData = True
594 self.dataOut.flagNoData = True
571 print 'NoData se vuelve true'
595 print 'NoData se vuelve true'
572 return 0
596 return 0
573
597
574 self.fp=self.path
598 self.fp = self.path
575 self.Files2Read(self.fp)
599 self.Files2Read(self.fp)
576 self.readFile(self.fp)
600 self.readFile(self.fp)
577 self.dataOut.data_spc = self.data_spc
601 self.dataOut.data_spc = self.data_spc
578 self.dataOut.data_cspc =self.data_cspc
602 self.dataOut.data_cspc = self.data_cspc
579 self.dataOut.data_output=self.data_output
603 self.dataOut.data_output = self.data_output
580
604
581 print 'self.dataOut.data_output', shape(self.dataOut.data_output)
605 print 'self.dataOut.data_output', shape(self.dataOut.data_output)
582
606
583 #self.removeDC()
607 # self.removeDC()
584 return self.dataOut.data_spc
608 return self.dataOut.data_spc
585
609
586
587 def readFile(self,fp):
610 def readFile(self, fp):
588 '''
611 '''
589 You must indicate if you are reading in Online or Offline mode and load the
612 You must indicate if you are reading in Online or Offline mode and load the
590 The parameters for this file reading mode.
613 The parameters for this file reading mode.
591
614
592 Then you must do 2 actions:
615 Then you must do 2 actions:
593
616
594 1. Get the BLTR FileHeader.
617 1. Get the BLTR FileHeader.
595 2. Start reading the first block.
618 2. Start reading the first block.
596 '''
619 '''
597
620
598 #The address of the folder is generated the name of the .fdt file that will be read
621 # The address of the folder is generated the name of the .fdt file that will be read
599 print "File: ",self.fileSelector+1
622 print "File: ", self.fileSelector + 1
600
623
601 if self.fileSelector < len(self.filenameList):
624 if self.fileSelector < len(self.filenameList):
602
625
603 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
626 self.fpFile = str(fp) + '/' + \
627 str(self.filenameList[self.fileSelector])
604 #print self.fpFile
628 # print self.fpFile
605 fheader = FileHeaderBLTR()
629 fheader = FileHeaderBLTR()
606 fheader.FHread(self.fpFile) #Bltr FileHeader Reading
630 fheader.FHread(self.fpFile) # Bltr FileHeader Reading
607 self.nFDTdataRecors=fheader.nFDTdataRecors
631 self.nFDTdataRecors = fheader.nFDTdataRecors
608
632
609 self.readBlock() #Block reading
633 self.readBlock() # Block reading
610 else:
634 else:
611 print 'readFile FlagNoData becomes true'
635 print 'readFile FlagNoData becomes true'
612 self.flagNoMoreFiles=True
636 self.flagNoMoreFiles = True
613 self.dataOut.flagNoData = True
637 self.dataOut.flagNoData = True
614 return 0
638 return 0
615
639
616 def getVelRange(self, extrapoints=0):
640 def getVelRange(self, extrapoints=0):
617 Lambda= SPEED_OF_LIGHT/50000000
641 Lambda = SPEED_OF_LIGHT / 50000000
618 PRF = self.dataOut.PRF#1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
642 # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
643 PRF = self.dataOut.PRF
619 Vmax=-Lambda/(4.*(1./PRF)*self.dataOut.nCohInt*2.)
644 Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.)
620 deltafreq = PRF / (self.nProfiles)
645 deltafreq = PRF / (self.nProfiles)
621 deltavel = (Vmax*2) / (self.nProfiles)
646 deltavel = (Vmax * 2) / (self.nProfiles)
622 freqrange = deltafreq*(numpy.arange(self.nProfiles)-self.nProfiles/2.) - deltafreq/2
647 freqrange = deltafreq * \
623 velrange = deltavel*(numpy.arange(self.nProfiles)-self.nProfiles/2.)
648 (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2
649 velrange = deltavel * \
650 (numpy.arange(self.nProfiles) - self.nProfiles / 2.)
624 return velrange
651 return velrange
625
652
626 def readBlock(self):
653 def readBlock(self):
627 '''
654 '''
628 It should be checked if the block has data, if it is not passed to the next file.
655 It should be checked if the block has data, if it is not passed to the next file.
629
656
630 Then the following is done:
657 Then the following is done:
631
658
632 1. Read the RecordHeader
659 1. Read the RecordHeader
633 2. Fill the buffer with the current block number.
660 2. Fill the buffer with the current block number.
634
661
635 '''
662 '''
636
663
637 if self.BlockCounter < self.nFDTdataRecors-2:
664 if self.BlockCounter < self.nFDTdataRecors - 2:
638 print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
665 print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
639 if self.ReadMode==1:
666 if self.ReadMode == 1:
640 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter+1)
667 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter + 1)
641 elif self.ReadMode==0:
668 elif self.ReadMode == 0:
642 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
669 rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter)
643
670
644 rheader.RHread(self.fpFile) #Bltr FileHeader Reading
671 rheader.RHread(self.fpFile) # Bltr FileHeader Reading
645
672
646 self.OffsetStartHeader=rheader.OffsetStartHeader
673 self.OffsetStartHeader = rheader.OffsetStartHeader
647 self.RecCounter=rheader.RecCounter
674 self.RecCounter = rheader.RecCounter
648 self.Off2StartNxtRec=rheader.Off2StartNxtRec
675 self.Off2StartNxtRec = rheader.Off2StartNxtRec
649 self.Off2StartData=rheader.Off2StartData
676 self.Off2StartData = rheader.Off2StartData
650 self.nProfiles=rheader.nProfiles
677 self.nProfiles = rheader.nProfiles
651 self.nChannels=rheader.nChannels
678 self.nChannels = rheader.nChannels
652 self.nHeights=rheader.nHeights
679 self.nHeights = rheader.nHeights
653 self.frequency=rheader.TransmitFrec
680 self.frequency = rheader.TransmitFrec
654 self.DualModeIndex=rheader.DualModeIndex
681 self.DualModeIndex = rheader.DualModeIndex
655
682
656 self.pairsList =[(0,1),(0,2),(1,2)]
683 self.pairsList = [(0, 1), (0, 2), (1, 2)]
657 self.dataOut.pairsList = self.pairsList
684 self.dataOut.pairsList = self.pairsList
658
685
659 self.nRdPairs=len(self.dataOut.pairsList)
686 self.nRdPairs = len(self.dataOut.pairsList)
660 self.dataOut.nRdPairs = self.nRdPairs
687 self.dataOut.nRdPairs = self.nRdPairs
661
688
662 self.__firstHeigth=rheader.StartRangeSamp
689 self.__firstHeigth = rheader.StartRangeSamp
663 self.__deltaHeigth=rheader.SampResolution
690 self.__deltaHeigth = rheader.SampResolution
664 self.dataOut.heightList= self.__firstHeigth + numpy.array(range(self.nHeights))*self.__deltaHeigth
691 self.dataOut.heightList = self.__firstHeigth + \
692 numpy.array(range(self.nHeights)) * self.__deltaHeigth
665 self.dataOut.channelList = range(self.nChannels)
693 self.dataOut.channelList = range(self.nChannels)
666 self.dataOut.nProfiles=rheader.nProfiles
694 self.dataOut.nProfiles = rheader.nProfiles
667 self.dataOut.nIncohInt=rheader.nIncohInt
695 self.dataOut.nIncohInt = rheader.nIncohInt
668 self.dataOut.nCohInt=rheader.nCohInt
696 self.dataOut.nCohInt = rheader.nCohInt
669 self.dataOut.ippSeconds= 1/float(rheader.PRFhz)
697 self.dataOut.ippSeconds = 1 / float(rheader.PRFhz)
670 self.dataOut.PRF=rheader.PRFhz
698 self.dataOut.PRF = rheader.PRFhz
671 self.dataOut.nFFTPoints=rheader.nProfiles
699 self.dataOut.nFFTPoints = rheader.nProfiles
672 self.dataOut.utctime=rheader.nUtime
700 self.dataOut.utctime = rheader.nUtime
673 self.dataOut.timeZone=0
701 self.dataOut.timeZone = 0
674 self.dataOut.normFactor= self.dataOut.nProfiles*self.dataOut.nIncohInt*self.dataOut.nCohInt
702 self.dataOut.normFactor = self.dataOut.nProfiles * \
675 self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
703 self.dataOut.nIncohInt * self.dataOut.nCohInt
704 self.dataOut.outputInterval = self.dataOut.ippSeconds * \
705 self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
676
706
677 self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN
707 self.data_output = numpy.ones([3, rheader.nHeights]) * numpy.NaN
678 print 'self.data_output', shape(self.data_output)
708 print 'self.data_output', shape(self.data_output)
679 self.dataOut.velocityX=[]
709 self.dataOut.velocityX = []
680 self.dataOut.velocityY=[]
710 self.dataOut.velocityY = []
681 self.dataOut.velocityV=[]
711 self.dataOut.velocityV = []
682
712
683 '''Block Reading, the Block Data is received and Reshape is used to give it
713 '''Block Reading, the Block Data is received and Reshape is used to give it
684 shape.
714 shape.
685 '''
715 '''
686
716
687 #Procedure to take the pointer to where the date block starts
717 # Procedure to take the pointer to where the date block starts
688 startDATA = open(self.fpFile,"rb")
718 startDATA = open(self.fpFile, "rb")
689 OffDATA= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec+self.Off2StartData
719 OffDATA = self.OffsetStartHeader + self.RecCounter * \
720 self.Off2StartNxtRec + self.Off2StartData
690 startDATA.seek(OffDATA, os.SEEK_SET)
721 startDATA.seek(OffDATA, os.SEEK_SET)
691
722
692 def moving_average(x, N=2):
723 def moving_average(x, N=2):
693 return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):]
724 return numpy.convolve(x, numpy.ones((N,)) / N)[(N - 1):]
694
725
695 def gaus(xSamples,a,x0,sigma):
726 def gaus(xSamples, a, x0, sigma):
696 return a*exp(-(xSamples-x0)**2/(2*sigma**2))
727 return a * exp(-(xSamples - x0)**2 / (2 * sigma**2))
697
728
698 def Find(x,value):
729 def Find(x, value):
699 for index in range(len(x)):
730 for index in range(len(x)):
700 if x[index]==value:
731 if x[index] == value:
701 return index
732 return index
702
733
703 def pol2cart(rho, phi):
734 def pol2cart(rho, phi):
704 x = rho * numpy.cos(phi)
735 x = rho * numpy.cos(phi)
705 y = rho * numpy.sin(phi)
736 y = rho * numpy.sin(phi)
706 return(x, y)
737 return(x, y)
707
738
708
709
710
711 if self.DualModeIndex==self.ReadMode:
739 if self.DualModeIndex == self.ReadMode:
712
740
713 self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights )
741 self.data_fft = numpy.fromfile(
742 startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights)
714
743
715 self.data_fft=self.data_fft.astype(numpy.dtype('complex'))
744 self.data_fft = self.data_fft.astype(numpy.dtype('complex'))
716
745
717 self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles ))
746 self.data_block = numpy.reshape(
747 self.data_fft, (self.nHeights, self.nChannels, self.nProfiles))
718
748
719 self.data_block = numpy.transpose(self.data_block, (1,2,0))
749 self.data_block = numpy.transpose(self.data_block, (1, 2, 0))
720
750
721 copy = self.data_block.copy()
751 copy = self.data_block.copy()
722 spc = copy * numpy.conjugate(copy)
752 spc = copy * numpy.conjugate(copy)
723
753
724 self.data_spc = numpy.absolute(spc) # valor absoluto o magnitud
754 self.data_spc = numpy.absolute(
755 spc) # valor absoluto o magnitud
725
756
726 factor = self.dataOut.normFactor
757 factor = self.dataOut.normFactor
727
758
728
729 z = self.data_spc.copy()#/factor
759 z = self.data_spc.copy() # /factor
730 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
760 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
731 #zdB = 10*numpy.log10(z)
761 #zdB = 10*numpy.log10(z)
732 print ' '
762 print ' '
733 print 'Z: '
763 print 'Z: '
734 print shape(z)
764 print shape(z)
735 print ' '
765 print ' '
736 print ' '
766 print ' '
737
767
738 self.dataOut.data_spc=self.data_spc
768 self.dataOut.data_spc = self.data_spc
739
769
740 self.noise = self.dataOut.getNoise(ymin_index=80, ymax_index=132)#/factor
770 self.noise = self.dataOut.getNoise(
771 ymin_index=80, ymax_index=132) # /factor
741 #noisedB = 10*numpy.log10(self.noise)
772 #noisedB = 10*numpy.log10(self.noise)
742
773
743
744 ySamples=numpy.ones([3,self.nProfiles])
774 ySamples = numpy.ones([3, self.nProfiles])
745 phase=numpy.ones([3,self.nProfiles])
775 phase = numpy.ones([3, self.nProfiles])
746 CSPCSamples=numpy.ones([3,self.nProfiles],dtype=numpy.complex_)
776 CSPCSamples = numpy.ones(
777 [3, self.nProfiles], dtype=numpy.complex_)
747 coherence=numpy.ones([3,self.nProfiles])
778 coherence = numpy.ones([3, self.nProfiles])
748 PhaseSlope=numpy.ones(3)
779 PhaseSlope = numpy.ones(3)
749 PhaseInter=numpy.ones(3)
780 PhaseInter = numpy.ones(3)
750
781
751 '''****** Getting CrossSpectra ******'''
782 '''****** Getting CrossSpectra ******'''
752 cspc=self.data_block.copy()
783 cspc = self.data_block.copy()
753 self.data_cspc=self.data_block.copy()
784 self.data_cspc = self.data_block.copy()
754
785
755 xFrec=self.getVelRange(1)
786 xFrec = self.getVelRange(1)
756 VelRange=self.getVelRange(1)
787 VelRange = self.getVelRange(1)
757 self.dataOut.VelRange=VelRange
788 self.dataOut.VelRange = VelRange
758 #print ' '
789 # print ' '
759 #print ' '
790 # print ' '
760 #print 'xFrec',xFrec
791 # print 'xFrec',xFrec
761 #print ' '
792 # print ' '
762 #print ' '
793 # print ' '
763 #Height=35
794 # Height=35
764 for i in range(self.nRdPairs):
795 for i in range(self.nRdPairs):
765
796
766 chan_index0 = self.dataOut.pairsList[i][0]
797 chan_index0 = self.dataOut.pairsList[i][0]
767 chan_index1 = self.dataOut.pairsList[i][1]
798 chan_index1 = self.dataOut.pairsList[i][1]
768
799
769 self.data_cspc[i,:,:]=cspc[chan_index0,:,:] * numpy.conjugate(cspc[chan_index1,:,:])
800 self.data_cspc[i, :, :] = cspc[chan_index0, :,
770
801 :] * numpy.conjugate(cspc[chan_index1, :, :])
771
802
772 '''Getting Eij and Nij'''
803 '''Getting Eij and Nij'''
773 (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
804 (AntennaX0, AntennaY0) = pol2cart(
774 (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
805 rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180)
775 (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
806 (AntennaX1, AntennaY1) = pol2cart(
807 rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180)
808 (AntennaX2, AntennaY2) = pol2cart(
809 rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180)
776
810
777 E01=AntennaX0-AntennaX1
811 E01 = AntennaX0 - AntennaX1
778 N01=AntennaY0-AntennaY1
812 N01 = AntennaY0 - AntennaY1
779
813
780 E02=AntennaX0-AntennaX2
814 E02 = AntennaX0 - AntennaX2
781 N02=AntennaY0-AntennaY2
815 N02 = AntennaY0 - AntennaY2
782
816
783 E12=AntennaX1-AntennaX2
817 E12 = AntennaX1 - AntennaX2
784 N12=AntennaY1-AntennaY2
818 N12 = AntennaY1 - AntennaY2
785
819
786 self.ChanDist= numpy.array([[E01, N01],[E02,N02],[E12,N12]])
820 self.ChanDist = numpy.array(
821 [[E01, N01], [E02, N02], [E12, N12]])
787
822
788 self.dataOut.ChanDist = self.ChanDist
823 self.dataOut.ChanDist = self.ChanDist
789
824
790
825
791 # for Height in range(self.nHeights):
826 # for Height in range(self.nHeights):
792 #
827 #
793 # for i in range(self.nRdPairs):
828 # for i in range(self.nRdPairs):
794 #
829 #
795 # '''****** Line of Data SPC ******'''
830 # '''****** Line of Data SPC ******'''
796 # zline=z[i,:,Height]
831 # zline=z[i,:,Height]
797 #
832 #
798 # '''****** DC is removed ******'''
833 # '''****** DC is removed ******'''
799 # DC=Find(zline,numpy.amax(zline))
834 # DC=Find(zline,numpy.amax(zline))
800 # zline[DC]=(zline[DC-1]+zline[DC+1])/2
835 # zline[DC]=(zline[DC-1]+zline[DC+1])/2
801 #
836 #
802 #
837 #
803 # '''****** SPC is normalized ******'''
838 # '''****** SPC is normalized ******'''
804 # FactNorm= zline.copy() / numpy.sum(zline.copy())
839 # FactNorm= zline.copy() / numpy.sum(zline.copy())
805 # FactNorm= FactNorm/numpy.sum(FactNorm)
840 # FactNorm= FactNorm/numpy.sum(FactNorm)
806 #
841 #
807 # SmoothSPC=moving_average(FactNorm,N=3)
842 # SmoothSPC=moving_average(FactNorm,N=3)
808 #
843 #
809 # xSamples = ar(range(len(SmoothSPC)))
844 # xSamples = ar(range(len(SmoothSPC)))
810 # ySamples[i] = SmoothSPC-self.noise[i]
845 # ySamples[i] = SmoothSPC-self.noise[i]
811 #
846 #
812 # for i in range(self.nRdPairs):
847 # for i in range(self.nRdPairs):
813 #
848 #
814 # '''****** Line of Data CSPC ******'''
849 # '''****** Line of Data CSPC ******'''
815 # cspcLine=self.data_cspc[i,:,Height].copy()
850 # cspcLine=self.data_cspc[i,:,Height].copy()
816 #
851 #
817 #
852 #
818 #
853 #
819 # '''****** CSPC is normalized ******'''
854 # '''****** CSPC is normalized ******'''
820 # chan_index0 = self.dataOut.pairsList[i][0]
855 # chan_index0 = self.dataOut.pairsList[i][0]
821 # chan_index1 = self.dataOut.pairsList[i][1]
856 # chan_index1 = self.dataOut.pairsList[i][1]
822 # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])
857 # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1])
823 #
858 #
824 #
859 #
825 # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor)
860 # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor)
826 #
861 #
827 #
862 #
828 # CSPCSamples[i] = CSPCNorm-self.noise[i]
863 # CSPCSamples[i] = CSPCNorm-self.noise[i]
829 # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
864 # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor)
830 #
865 #
831 # '''****** DC is removed ******'''
866 # '''****** DC is removed ******'''
832 # DC=Find(coherence[i],numpy.amax(coherence[i]))
867 # DC=Find(coherence[i],numpy.amax(coherence[i]))
833 # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2
868 # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2
834 # coherence[i]= moving_average(coherence[i],N=2)
869 # coherence[i]= moving_average(coherence[i],N=2)
835 #
870 #
836 # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
871 # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi
837 #
872 #
838 #
873 #
839 # '''****** Getting fij width ******'''
874 # '''****** Getting fij width ******'''
840 #
875 #
841 # yMean=[]
876 # yMean=[]
842 # yMean2=[]
877 # yMean2=[]
843 #
878 #
844 # for j in range(len(ySamples[1])):
879 # for j in range(len(ySamples[1])):
845 # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
880 # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]]))
846 #
881 #
847 # '''******* Getting fitting Gaussian ******'''
882 # '''******* Getting fitting Gaussian ******'''
848 # meanGauss=sum(xSamples*yMean) / len(xSamples)
883 # meanGauss=sum(xSamples*yMean) / len(xSamples)
849 # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
884 # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples)
850 # #print 'Height',Height,'SNR', meanGauss/sigma**2
885 # #print 'Height',Height,'SNR', meanGauss/sigma**2
851 #
886 #
852 # if (abs(meanGauss/sigma**2) > 0.0001) :
887 # if (abs(meanGauss/sigma**2) > 0.0001) :
853 #
888 #
854 # try:
889 # try:
855 # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
890 # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma])
856 #
891 #
857 # if numpy.amax(popt)>numpy.amax(yMean)*0.3:
892 # if numpy.amax(popt)>numpy.amax(yMean)*0.3:
858 # FitGauss=gaus(xSamples,*popt)
893 # FitGauss=gaus(xSamples,*popt)
859 #
894 #
860 # else:
895 # else:
861 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
896 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
862 # print 'Verificador: Dentro', Height
897 # print 'Verificador: Dentro', Height
863 # except RuntimeError:
898 # except RuntimeError:
864 #
899 #
865 # try:
900 # try:
866 # for j in range(len(ySamples[1])):
901 # for j in range(len(ySamples[1])):
867 # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]]))
902 # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]]))
868 # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma])
903 # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma])
869 # FitGauss=gaus(xSamples,*popt)
904 # FitGauss=gaus(xSamples,*popt)
870 # print 'Verificador: Exepcion1', Height
905 # print 'Verificador: Exepcion1', Height
871 # except RuntimeError:
906 # except RuntimeError:
872 #
907 #
873 # try:
908 # try:
874 # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma])
909 # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma])
875 # FitGauss=gaus(xSamples,*popt)
910 # FitGauss=gaus(xSamples,*popt)
876 # print 'Verificador: Exepcion2', Height
911 # print 'Verificador: Exepcion2', Height
877 # except RuntimeError:
912 # except RuntimeError:
878 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
913 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
879 # print 'Verificador: Exepcion3', Height
914 # print 'Verificador: Exepcion3', Height
880 # else:
915 # else:
881 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
916 # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean)
882 # #print 'Verificador: Fuera', Height
917 # #print 'Verificador: Fuera', Height
883 #
918 #
884 #
919 #
885 #
920 #
886 # Maximun=numpy.amax(yMean)
921 # Maximun=numpy.amax(yMean)
887 # eMinus1=Maximun*numpy.exp(-1)
922 # eMinus1=Maximun*numpy.exp(-1)
888 #
923 #
889 # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
924 # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1)))
890 # HalfWidth= xFrec[HWpos]
925 # HalfWidth= xFrec[HWpos]
891 # GCpos=Find(FitGauss, numpy.amax(FitGauss))
926 # GCpos=Find(FitGauss, numpy.amax(FitGauss))
892 # Vpos=Find(FactNorm, numpy.amax(FactNorm))
927 # Vpos=Find(FactNorm, numpy.amax(FactNorm))
893 # #Vpos=numpy.sum(FactNorm)/len(FactNorm)
928 # #Vpos=numpy.sum(FactNorm)/len(FactNorm)
894 # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) )))
929 # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) )))
895 # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos
930 # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos
896 # '''****** Getting Fij ******'''
931 # '''****** Getting Fij ******'''
897 #
932 #
898 # GaussCenter=xFrec[GCpos]
933 # GaussCenter=xFrec[GCpos]
899 # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
934 # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0):
900 # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
935 # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001
901 # else:
936 # else:
902 # Fij=abs(GaussCenter-HalfWidth)+0.0000001
937 # Fij=abs(GaussCenter-HalfWidth)+0.0000001
903 #
938 #
904 # '''****** Getting Frecuency range of significant data ******'''
939 # '''****** Getting Frecuency range of significant data ******'''
905 #
940 #
906 # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
941 # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10)))
907 #
942 #
908 # if Rangpos<GCpos:
943 # if Rangpos<GCpos:
909 # Range=numpy.array([Rangpos,2*GCpos-Rangpos])
944 # Range=numpy.array([Rangpos,2*GCpos-Rangpos])
910 # else:
945 # else:
911 # Range=numpy.array([2*GCpos-Rangpos,Rangpos])
946 # Range=numpy.array([2*GCpos-Rangpos,Rangpos])
912 #
947 #
913 # FrecRange=xFrec[Range[0]:Range[1]]
948 # FrecRange=xFrec[Range[0]:Range[1]]
914 #
949 #
915 # #print 'FrecRange', FrecRange
950 # #print 'FrecRange', FrecRange
916 # '''****** Getting SCPC Slope ******'''
951 # '''****** Getting SCPC Slope ******'''
917 #
952 #
918 # for i in range(self.nRdPairs):
953 # for i in range(self.nRdPairs):
919 #
954 #
920 # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5:
955 # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5:
921 # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3)
956 # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3)
922 #
957 #
923 # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
958 # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange)
924 # PhaseSlope[i]=slope
959 # PhaseSlope[i]=slope
925 # PhaseInter[i]=intercept
960 # PhaseInter[i]=intercept
926 # else:
961 # else:
927 # PhaseSlope[i]=0
962 # PhaseSlope[i]=0
928 # PhaseInter[i]=0
963 # PhaseInter[i]=0
929 #
964 #
930 # # plt.figure(i+15)
965 # # plt.figure(i+15)
931 # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1]))
966 # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1]))
932 # # plt.xlabel('Frecuencia (KHz)')
967 # # plt.xlabel('Frecuencia (KHz)')
933 # # plt.ylabel('Magnitud')
968 # # plt.ylabel('Magnitud')
934 # # #plt.subplot(311+i)
969 # # #plt.subplot(311+i)
935 # # plt.plot(FrecRange,PhaseRange,'b')
970 # # plt.plot(FrecRange,PhaseRange,'b')
936 # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r')
971 # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r')
937 #
972 #
938 # #plt.axis([-0.6, 0.2, -3.2, 3.2])
973 # #plt.axis([-0.6, 0.2, -3.2, 3.2])
939 #
974 #
940 #
975 #
941 # '''Getting constant C'''
976 # '''Getting constant C'''
942 # cC=(Fij*numpy.pi)**2
977 # cC=(Fij*numpy.pi)**2
943 #
978 #
944 # # '''Getting Eij and Nij'''
979 # # '''Getting Eij and Nij'''
945 # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
980 # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
946 # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
981 # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
947 # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
982 # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
948 # #
983 # #
949 # # E01=AntennaX0-AntennaX1
984 # # E01=AntennaX0-AntennaX1
950 # # N01=AntennaY0-AntennaY1
985 # # N01=AntennaY0-AntennaY1
951 # #
986 # #
952 # # E02=AntennaX0-AntennaX2
987 # # E02=AntennaX0-AntennaX2
953 # # N02=AntennaY0-AntennaY2
988 # # N02=AntennaY0-AntennaY2
954 # #
989 # #
955 # # E12=AntennaX1-AntennaX2
990 # # E12=AntennaX1-AntennaX2
956 # # N12=AntennaY1-AntennaY2
991 # # N12=AntennaY1-AntennaY2
957 #
992 #
958 # '''****** Getting constants F and G ******'''
993 # '''****** Getting constants F and G ******'''
959 # MijEijNij=numpy.array([[E02,N02], [E12,N12]])
994 # MijEijNij=numpy.array([[E02,N02], [E12,N12]])
960 # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
995 # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi)
961 # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
996 # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi)
962 # MijResults=numpy.array([MijResult0,MijResult1])
997 # MijResults=numpy.array([MijResult0,MijResult1])
963 # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
998 # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults)
964 #
999 #
965 # '''****** Getting constants A, B and H ******'''
1000 # '''****** Getting constants A, B and H ******'''
966 # W01=numpy.amax(coherence[0])
1001 # W01=numpy.amax(coherence[0])
967 # W02=numpy.amax(coherence[1])
1002 # W02=numpy.amax(coherence[1])
968 # W12=numpy.amax(coherence[2])
1003 # W12=numpy.amax(coherence[2])
969 #
1004 #
970 # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
1005 # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC))
971 # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
1006 # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC))
972 # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
1007 # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC))
973 #
1008 #
974 # WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
1009 # WijResults=numpy.array([WijResult0, WijResult1, WijResult2])
975 #
1010 #
976 # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
1011 # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ])
977 # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
1012 # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults)
978 #
1013 #
979 # VxVy=numpy.array([[cA,cH],[cH,cB]])
1014 # VxVy=numpy.array([[cA,cH],[cH,cB]])
980 #
1015 #
981 # VxVyResults=numpy.array([-cF,-cG])
1016 # VxVyResults=numpy.array([-cF,-cG])
982 # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
1017 # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults)
983 # Vzon = Vy
1018 # Vzon = Vy
984 # Vmer = Vx
1019 # Vmer = Vx
985 # Vmag=numpy.sqrt(Vzon**2+Vmer**2)
1020 # Vmag=numpy.sqrt(Vzon**2+Vmer**2)
986 # Vang=numpy.arctan2(Vmer,Vzon)
1021 # Vang=numpy.arctan2(Vmer,Vzon)
987 #
1022 #
988 # if abs(Vy)<100 and abs(Vy)> 0.:
1023 # if abs(Vy)<100 and abs(Vy)> 0.:
989 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag
1024 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag
990 # #print 'Vmag',Vmag
1025 # #print 'Vmag',Vmag
991 # else:
1026 # else:
992 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN)
1027 # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN)
993 #
1028 #
994 # if abs(Vx)<100 and abs(Vx) > 0.:
1029 # if abs(Vx)<100 and abs(Vx) > 0.:
995 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang
1030 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang
996 # #print 'Vang',Vang
1031 # #print 'Vang',Vang
997 # else:
1032 # else:
998 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN)
1033 # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN)
999 #
1034 #
1000 # if abs(GaussCenter)<2:
1035 # if abs(GaussCenter)<2:
1001 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos])
1036 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos])
1002 #
1037 #
1003 # else:
1038 # else:
1004 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN)
1039 # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN)
1005 #
1040 #
1006 #
1041 #
1007 # # print '********************************************'
1042 # # print '********************************************'
1008 # # print 'HalfWidth ', HalfWidth
1043 # # print 'HalfWidth ', HalfWidth
1009 # # print 'Maximun ', Maximun
1044 # # print 'Maximun ', Maximun
1010 # # print 'eMinus1 ', eMinus1
1045 # # print 'eMinus1 ', eMinus1
1011 # # print 'Rangpos ', Rangpos
1046 # # print 'Rangpos ', Rangpos
1012 # # print 'GaussCenter ',GaussCenter
1047 # # print 'GaussCenter ',GaussCenter
1013 # # print 'E01 ',E01
1048 # # print 'E01 ',E01
1014 # # print 'N01 ',N01
1049 # # print 'N01 ',N01
1015 # # print 'E02 ',E02
1050 # # print 'E02 ',E02
1016 # # print 'N02 ',N02
1051 # # print 'N02 ',N02
1017 # # print 'E12 ',E12
1052 # # print 'E12 ',E12
1018 # # print 'N12 ',N12
1053 # # print 'N12 ',N12
1019 # #print 'self.dataOut.velocityX ', self.dataOut.velocityX
1054 # #print 'self.dataOut.velocityX ', self.dataOut.velocityX
1020 # # print 'Fij ', Fij
1055 # # print 'Fij ', Fij
1021 # # print 'cC ', cC
1056 # # print 'cC ', cC
1022 # # print 'cF ', cF
1057 # # print 'cF ', cF
1023 # # print 'cG ', cG
1058 # # print 'cG ', cG
1024 # # print 'cA ', cA
1059 # # print 'cA ', cA
1025 # # print 'cB ', cB
1060 # # print 'cB ', cB
1026 # # print 'cH ', cH
1061 # # print 'cH ', cH
1027 # # print 'Vx ', Vx
1062 # # print 'Vx ', Vx
1028 # # print 'Vy ', Vy
1063 # # print 'Vy ', Vy
1029 # # print 'Vmag ', Vmag
1064 # # print 'Vmag ', Vmag
1030 # # print 'Vang ', Vang*180/numpy.pi
1065 # # print 'Vang ', Vang*180/numpy.pi
1031 # # print 'PhaseSlope ',PhaseSlope[0]
1066 # # print 'PhaseSlope ',PhaseSlope[0]
1032 # # print 'PhaseSlope ',PhaseSlope[1]
1067 # # print 'PhaseSlope ',PhaseSlope[1]
1033 # # print 'PhaseSlope ',PhaseSlope[2]
1068 # # print 'PhaseSlope ',PhaseSlope[2]
1034 # # print '********************************************'
1069 # # print '********************************************'
1035 # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY)
1070 # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY)
1036 #
1071 #
1037 # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX)
1072 # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX)
1038 # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY)
1073 # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY)
1039 # #print 'self.dataOut.velocityV', self.dataOut.velocityV
1074 # #print 'self.dataOut.velocityV', self.dataOut.velocityV
1040 #
1075 #
1041 # self.data_output[0]=numpy.array(self.dataOut.velocityX)
1076 # self.data_output[0]=numpy.array(self.dataOut.velocityX)
1042 # self.data_output[1]=numpy.array(self.dataOut.velocityY)
1077 # self.data_output[1]=numpy.array(self.dataOut.velocityY)
1043 # self.data_output[2]=numpy.array(self.dataOut.velocityV)
1078 # self.data_output[2]=numpy.array(self.dataOut.velocityV)
1044 #
1079 #
1045 # prin= self.data_output[0][~numpy.isnan(self.data_output[0])]
1080 # prin= self.data_output[0][~numpy.isnan(self.data_output[0])]
1046 # print ' '
1081 # print ' '
1047 # print 'VmagAverage',numpy.mean(prin)
1082 # print 'VmagAverage',numpy.mean(prin)
1048 # print ' '
1083 # print ' '
1049 # # plt.figure(5)
1084 # # plt.figure(5)
1050 # # plt.subplot(211)
1085 # # plt.subplot(211)
1051 # # plt.plot(self.dataOut.velocityX,'yo:')
1086 # # plt.plot(self.dataOut.velocityX,'yo:')
1052 # # plt.subplot(212)
1087 # # plt.subplot(212)
1053 # # plt.plot(self.dataOut.velocityY,'yo:')
1088 # # plt.plot(self.dataOut.velocityY,'yo:')
1054 #
1089 #
1055 # # plt.figure(1)
1090 # # plt.figure(1)
1056 # # # plt.subplot(121)
1091 # # # plt.subplot(121)
1057 # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0')
1092 # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0')
1058 # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1')
1093 # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1')
1059 # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1094 # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1060 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1095 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1061 # # # plt.legend()
1096 # # # plt.legend()
1062 # # plt.title('DATOS A ALTURA DE 2850 METROS')
1097 # # plt.title('DATOS A ALTURA DE 2850 METROS')
1063 # #
1098 # #
1064 # # plt.xlabel('Frecuencia (KHz)')
1099 # # plt.xlabel('Frecuencia (KHz)')
1065 # # plt.ylabel('Magnitud')
1100 # # plt.ylabel('Magnitud')
1066 # # # plt.subplot(122)
1101 # # # plt.subplot(122)
1067 # # # plt.title('Fit for Time Constant')
1102 # # # plt.title('Fit for Time Constant')
1068 # # #plt.plot(xFrec,zline)
1103 # # #plt.plot(xFrec,zline)
1069 # # #plt.plot(xFrec,SmoothSPC,'g')
1104 # # #plt.plot(xFrec,SmoothSPC,'g')
1070 # # plt.plot(xFrec,FactNorm)
1105 # # plt.plot(xFrec,FactNorm)
1071 # # plt.axis([-4, 4, 0, 0.15])
1106 # # plt.axis([-4, 4, 0, 0.15])
1072 # # # plt.xlabel('SelfSpectra KHz')
1107 # # # plt.xlabel('SelfSpectra KHz')
1073 # #
1108 # #
1074 # # plt.figure(10)
1109 # # plt.figure(10)
1075 # # # plt.subplot(121)
1110 # # # plt.subplot(121)
1076 # # plt.plot(xFrec,ySamples[0],'b',label='Ch0')
1111 # # plt.plot(xFrec,ySamples[0],'b',label='Ch0')
1077 # # plt.plot(xFrec,ySamples[1],'y',label='Ch1')
1112 # # plt.plot(xFrec,ySamples[1],'y',label='Ch1')
1078 # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1113 # # plt.plot(xFrec,ySamples[2],'r',label='Ch2')
1079 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1114 # # # plt.plot(xFrec,FitGauss,'yo:',label='fit')
1080 # # plt.legend()
1115 # # plt.legend()
1081 # # plt.title('SELFSPECTRA EN CANALES')
1116 # # plt.title('SELFSPECTRA EN CANALES')
1082 # #
1117 # #
1083 # # plt.xlabel('Frecuencia (KHz)')
1118 # # plt.xlabel('Frecuencia (KHz)')
1084 # # plt.ylabel('Magnitud')
1119 # # plt.ylabel('Magnitud')
1085 # # # plt.subplot(122)
1120 # # # plt.subplot(122)
1086 # # # plt.title('Fit for Time Constant')
1121 # # # plt.title('Fit for Time Constant')
1087 # # #plt.plot(xFrec,zline)
1122 # # #plt.plot(xFrec,zline)
1088 # # #plt.plot(xFrec,SmoothSPC,'g')
1123 # # #plt.plot(xFrec,SmoothSPC,'g')
1089 # # # plt.plot(xFrec,FactNorm)
1124 # # # plt.plot(xFrec,FactNorm)
1090 # # # plt.axis([-4, 4, 0, 0.15])
1125 # # # plt.axis([-4, 4, 0, 0.15])
1091 # # # plt.xlabel('SelfSpectra KHz')
1126 # # # plt.xlabel('SelfSpectra KHz')
1092 # #
1127 # #
1093 # # plt.figure(9)
1128 # # plt.figure(9)
1094 # #
1129 # #
1095 # #
1130 # #
1096 # # plt.title('DATOS SUAVIZADOS')
1131 # # plt.title('DATOS SUAVIZADOS')
1097 # # plt.xlabel('Frecuencia (KHz)')
1132 # # plt.xlabel('Frecuencia (KHz)')
1098 # # plt.ylabel('Magnitud')
1133 # # plt.ylabel('Magnitud')
1099 # # plt.plot(xFrec,SmoothSPC,'g')
1134 # # plt.plot(xFrec,SmoothSPC,'g')
1100 # #
1135 # #
1101 # # #plt.plot(xFrec,FactNorm)
1136 # # #plt.plot(xFrec,FactNorm)
1102 # # plt.axis([-4, 4, 0, 0.15])
1137 # # plt.axis([-4, 4, 0, 0.15])
1103 # # # plt.xlabel('SelfSpectra KHz')
1138 # # # plt.xlabel('SelfSpectra KHz')
1104 # # #
1139 # # #
1105 # # plt.figure(2)
1140 # # plt.figure(2)
1106 # # # #plt.subplot(121)
1141 # # # #plt.subplot(121)
1107 # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra')
1142 # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra')
1108 # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano')
1143 # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano')
1109 # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo')
1144 # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo')
1110 # # # #plt.plot(xFrec,phase)
1145 # # # #plt.plot(xFrec,phase)
1111 # # # plt.xlabel('Suavizado, promediado KHz')
1146 # # # plt.xlabel('Suavizado, promediado KHz')
1112 # # plt.title('SELFSPECTRA PROMEDIADO')
1147 # # plt.title('SELFSPECTRA PROMEDIADO')
1113 # # # #plt.subplot(122)
1148 # # # #plt.subplot(122)
1114 # # # #plt.plot(xSamples,zline)
1149 # # # #plt.plot(xSamples,zline)
1115 # # plt.xlabel('Frecuencia (KHz)')
1150 # # plt.xlabel('Frecuencia (KHz)')
1116 # # plt.ylabel('Magnitud')
1151 # # plt.ylabel('Magnitud')
1117 # # plt.legend()
1152 # # plt.legend()
1118 # # #
1153 # # #
1119 # # # plt.figure(3)
1154 # # # plt.figure(3)
1120 # # # plt.subplot(311)
1155 # # # plt.subplot(311)
1121 # # # #plt.plot(xFrec,phase[0])
1156 # # # #plt.plot(xFrec,phase[0])
1122 # # # plt.plot(xFrec,phase[0],'g')
1157 # # # plt.plot(xFrec,phase[0],'g')
1123 # # # plt.subplot(312)
1158 # # # plt.subplot(312)
1124 # # # plt.plot(xFrec,phase[1],'g')
1159 # # # plt.plot(xFrec,phase[1],'g')
1125 # # # plt.subplot(313)
1160 # # # plt.subplot(313)
1126 # # # plt.plot(xFrec,phase[2],'g')
1161 # # # plt.plot(xFrec,phase[2],'g')
1127 # # # #plt.plot(xFrec,phase[2])
1162 # # # #plt.plot(xFrec,phase[2])
1128 # # #
1163 # # #
1129 # # # plt.figure(4)
1164 # # # plt.figure(4)
1130 # # #
1165 # # #
1131 # # # plt.plot(xSamples,coherence[0],'b')
1166 # # # plt.plot(xSamples,coherence[0],'b')
1132 # # # plt.plot(xSamples,coherence[1],'r')
1167 # # # plt.plot(xSamples,coherence[1],'r')
1133 # # # plt.plot(xSamples,coherence[2],'g')
1168 # # # plt.plot(xSamples,coherence[2],'g')
1134 # # plt.show()
1169 # # plt.show()
1135 # # #
1170 # # #
1136 # # # plt.clf()
1171 # # # plt.clf()
1137 # # # plt.cla()
1172 # # # plt.cla()
1138 # # # plt.close()
1173 # # # plt.close()
1139 #
1174 #
1140 # print ' '
1175 # print ' '
1141
1176
1142
1143
1144 self.BlockCounter+=2
1177 self.BlockCounter += 2
1145
1178
1146 else:
1179 else:
1147 self.fileSelector+=1
1180 self.fileSelector += 1
1148 self.BlockCounter=0
1181 self.BlockCounter = 0
1149 print "Next File"
1182 print "Next File"
1150
1151
1152
1153
1154
@@ -1,803 +1,802
1 import os, sys
1 import os
2 import sys
2 import glob
3 import glob
3 import fnmatch
4 import fnmatch
4 import datetime
5 import datetime
5 import time
6 import time
6 import re
7 import re
7 import h5py
8 import h5py
8 import numpy
9 import numpy
9 import matplotlib.pyplot as plt
10
10
11 import pylab as plb
12 from scipy.optimize import curve_fit
11 from scipy.optimize import curve_fit
13 from scipy import asarray as ar,exp
12 from scipy import asarray as ar, exp
14 from scipy import stats
13 from scipy import stats
15
14
16 from numpy.ma.core import getdata
15 from numpy.ma.core import getdata
17
16
18 SPEED_OF_LIGHT = 299792458
17 SPEED_OF_LIGHT = 299792458
19 SPEED_OF_LIGHT = 3e8
18 SPEED_OF_LIGHT = 3e8
20
19
21 try:
20 try:
22 from gevent import sleep
21 from gevent import sleep
23 except:
22 except:
24 from time import sleep
23 from time import sleep
25
24
26 from schainpy.model.data.jrodata import Spectra
25 from schainpy.model.data.jrodata import Spectra
27 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
26 #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader
28 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
27 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
29 #from schainpy.model.io.jroIO_bltr import BLTRReader
28 #from schainpy.model.io.jroIO_bltr import BLTRReader
30 from numpy import imag, shape, NaN, empty
29 from numpy import imag, shape, NaN, empty
31
30
32
31
33
34 class Header(object):
32 class Header(object):
35
33
36 def __init__(self):
34 def __init__(self):
37 raise NotImplementedError
35 raise NotImplementedError
38
36
39
40 def read(self):
37 def read(self):
41
38
42 raise NotImplementedError
39 raise NotImplementedError
43
40
44 def write(self):
41 def write(self):
45
42
46 raise NotImplementedError
43 raise NotImplementedError
47
44
48 def printInfo(self):
45 def printInfo(self):
49
46
50 message = "#"*50 + "\n"
47 message = "#" * 50 + "\n"
51 message += self.__class__.__name__.upper() + "\n"
48 message += self.__class__.__name__.upper() + "\n"
52 message += "#"*50 + "\n"
49 message += "#" * 50 + "\n"
53
50
54 keyList = self.__dict__.keys()
51 keyList = self.__dict__.keys()
55 keyList.sort()
52 keyList.sort()
56
53
57 for key in keyList:
54 for key in keyList:
58 message += "%s = %s" %(key, self.__dict__[key]) + "\n"
55 message += "%s = %s" % (key, self.__dict__[key]) + "\n"
59
56
60 if "size" not in keyList:
57 if "size" not in keyList:
61 attr = getattr(self, "size")
58 attr = getattr(self, "size")
62
59
63 if attr:
60 if attr:
64 message += "%s = %s" %("size", attr) + "\n"
61 message += "%s = %s" % ("size", attr) + "\n"
65
62
66 #print message
63 # print message
67
64
68
65
69 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
66 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
70 ('Hname','a32'), #Original file name
67 ('Hname', 'a32'), # Original file name
71 ('Htime',numpy.str_,32), #Date and time when the file was created
68 # Date and time when the file was created
72 ('Hoper',numpy.str_,64), #Name of operator who created the file
69 ('Htime', numpy.str_, 32),
73 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
70 # Name of operator who created the file
74 ('Hdescr',numpy.str_,256), #Description of measurements
71 ('Hoper', numpy.str_, 64),
72 # Place where the measurements was carried out
73 ('Hplace', numpy.str_, 128),
74 # Description of measurements
75 ('Hdescr', numpy.str_, 256),
75 ('Hdummy',numpy.str_,512), #Reserved space
76 ('Hdummy', numpy.str_, 512), # Reserved space
76 #Main chunk 8bytes
77 # Main chunk 8bytes
77 ('Msign',numpy.str_,4), #Main chunk signature FZKF or NUIG
78 # Main chunk signature FZKF or NUIG
79 ('Msign', numpy.str_, 4),
78 ('MsizeData','<i4'), #Size of data block main chunk
80 ('MsizeData', '<i4'), # Size of data block main chunk
79 #Processing DSP parameters 36bytes
81 # Processing DSP parameters 36bytes
80 ('PPARsign',numpy.str_,4), #PPAR signature
82 ('PPARsign', numpy.str_, 4), # PPAR signature
81 ('PPARsize','<i4'), #PPAR size of block
83 ('PPARsize', '<i4'), # PPAR size of block
82 ('PPARprf','<i4'), #Pulse repetition frequency
84 ('PPARprf', '<i4'), # Pulse repetition frequency
83 ('PPARpdr','<i4'), #Pulse duration
85 ('PPARpdr', '<i4'), # Pulse duration
84 ('PPARsft','<i4'), #FFT length
86 ('PPARsft', '<i4'), # FFT length
85 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
87 # Number of spectral (in-coherent) averages
86 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
88 ('PPARavc', '<i4'),
87 ('PPARchg','<i4'), #Count for gates for moment estimation
89 # Number of lowest range gate for moment estimation
88 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
90 ('PPARihp', '<i4'),
91 # Count for gates for moment estimation
92 ('PPARchg', '<i4'),
93 # switch on/off polarimetric measurements. Should be 1.
94 ('PPARpol', '<i4'),
89 #Service DSP parameters 112bytes
95 # Service DSP parameters 112bytes
90 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
96 # STC attenuation on the lowest ranges on/off
97 ('SPARatt', '<i4'),
91 ('SPARtx','<i4'), #OBSOLETE
98 ('SPARtx', '<i4'), # OBSOLETE
92 ('SPARaddGain0','<f4'), #OBSOLETE
99 ('SPARaddGain0', '<f4'), # OBSOLETE
93 ('SPARaddGain1','<f4'), #OBSOLETE
100 ('SPARaddGain1', '<f4'), # OBSOLETE
94 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
101 # Debug only. It normal mode it is 0.
95 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
102 ('SPARwnd', '<i4'),
96 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
103 # Delay between sync pulse and tx pulse for phase corr, ns
97 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
104 ('SPARpos', '<i4'),
105 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
106 ('SPARadd', '<i4'),
107 # Time for measuring txn pulse phase. OBSOLETE
108 ('SPARlen', '<i4'),
98 ('SPARcal','<i4'), #OBSOLETE
109 ('SPARcal', '<i4'), # OBSOLETE
99 ('SPARnos','<i4'), #OBSOLETE
110 ('SPARnos', '<i4'), # OBSOLETE
100 ('SPARof0','<i4'), #detection threshold
111 ('SPARof0', '<i4'), # detection threshold
101 ('SPARof1','<i4'), #OBSOLETE
112 ('SPARof1', '<i4'), # OBSOLETE
102 ('SPARswt','<i4'), #2nd moment estimation threshold
113 ('SPARswt', '<i4'), # 2nd moment estimation threshold
103 ('SPARsum','<i4'), #OBSOLETE
114 ('SPARsum', '<i4'), # OBSOLETE
104 ('SPARosc','<i4'), #flag Oscillosgram mode
115 ('SPARosc', '<i4'), # flag Oscillosgram mode
105 ('SPARtst','<i4'), #OBSOLETE
116 ('SPARtst', '<i4'), # OBSOLETE
106 ('SPARcor','<i4'), #OBSOLETE
117 ('SPARcor', '<i4'), # OBSOLETE
107 ('SPARofs','<i4'), #OBSOLETE
118 ('SPARofs', '<i4'), # OBSOLETE
108 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
119 # Hildebrand div noise detection on noise gate
109 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
120 ('SPARhsn', '<i4'),
121 # Hildebrand div noise detection on all gates
122 ('SPARhsa', '<f4'),
110 ('SPARcalibPow_M','<f4'), #OBSOLETE
123 ('SPARcalibPow_M', '<f4'), # OBSOLETE
111 ('SPARcalibSNR_M','<f4'), #OBSOLETE
124 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
112 ('SPARcalibPow_S','<f4'), #OBSOLETE
125 ('SPARcalibPow_S', '<f4'), # OBSOLETE
113 ('SPARcalibSNR_S','<f4'), #OBSOLETE
126 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
114 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
127 # Lowest range gate for spectra saving Raw_Gate1 >=5
115 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
128 ('SPARrawGate1', '<i4'),
116 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
129 # Number of range gates with atmospheric signal
130 ('SPARrawGate2', '<i4'),
131 # flag - IQ or spectra saving on/off
132 ('SPARraw', '<i4'),
117 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
133 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
118
134
119
135
120
121 class FileHeaderMIRA35c(Header):
136 class FileHeaderMIRA35c(Header):
122
137
123 def __init__(self):
138 def __init__(self):
124
139
125 self.Hname= None
140 self.Hname = None
126 self.Htime= None
141 self.Htime = None
127 self.Hoper= None
142 self.Hoper = None
128 self.Hplace= None
143 self.Hplace = None
129 self.Hdescr= None
144 self.Hdescr = None
130 self.Hdummy= None
145 self.Hdummy = None
131
146
132 self.Msign=None
147 self.Msign = None
133 self.MsizeData=None
148 self.MsizeData = None
134
149
135 self.PPARsign=None
150 self.PPARsign = None
136 self.PPARsize=None
151 self.PPARsize = None
137 self.PPARprf=None
152 self.PPARprf = None
138 self.PPARpdr=None
153 self.PPARpdr = None
139 self.PPARsft=None
154 self.PPARsft = None
140 self.PPARavc=None
155 self.PPARavc = None
141 self.PPARihp=None
156 self.PPARihp = None
142 self.PPARchg=None
157 self.PPARchg = None
143 self.PPARpol=None
158 self.PPARpol = None
144 #Service DSP parameters
159 # Service DSP parameters
145 self.SPARatt=None
160 self.SPARatt = None
146 self.SPARtx=None
161 self.SPARtx = None
147 self.SPARaddGain0=None
162 self.SPARaddGain0 = None
148 self.SPARaddGain1=None
163 self.SPARaddGain1 = None
149 self.SPARwnd=None
164 self.SPARwnd = None
150 self.SPARpos=None
165 self.SPARpos = None
151 self.SPARadd=None
166 self.SPARadd = None
152 self.SPARlen=None
167 self.SPARlen = None
153 self.SPARcal=None
168 self.SPARcal = None
154 self.SPARnos=None
169 self.SPARnos = None
155 self.SPARof0=None
170 self.SPARof0 = None
156 self.SPARof1=None
171 self.SPARof1 = None
157 self.SPARswt=None
172 self.SPARswt = None
158 self.SPARsum=None
173 self.SPARsum = None
159 self.SPARosc=None
174 self.SPARosc = None
160 self.SPARtst=None
175 self.SPARtst = None
161 self.SPARcor=None
176 self.SPARcor = None
162 self.SPARofs=None
177 self.SPARofs = None
163 self.SPARhsn=None
178 self.SPARhsn = None
164 self.SPARhsa=None
179 self.SPARhsa = None
165 self.SPARcalibPow_M=None
180 self.SPARcalibPow_M = None
166 self.SPARcalibSNR_M=None
181 self.SPARcalibSNR_M = None
167 self.SPARcalibPow_S=None
182 self.SPARcalibPow_S = None
168 self.SPARcalibSNR_S=None
183 self.SPARcalibSNR_S = None
169 self.SPARrawGate1=None
184 self.SPARrawGate1 = None
170 self.SPARrawGate2=None
185 self.SPARrawGate2 = None
171 self.SPARraw=None
186 self.SPARraw = None
172 self.SPARprc=None
187 self.SPARprc = None
173
188
174 self.FHsize=1180
189 self.FHsize = 1180
175
190
176 def FHread(self, fp):
191 def FHread(self, fp):
177
192
178 header = numpy.fromfile(fp, FILE_HEADER,1)
193 header = numpy.fromfile(fp, FILE_HEADER, 1)
179 ''' numpy.fromfile(file, dtype, count, sep='')
194 ''' numpy.fromfile(file, dtype, count, sep='')
180 file : file or str
195 file : file or str
181 Open file object or filename.
196 Open file object or filename.
182
197
183 dtype : data-type
198 dtype : data-type
184 Data type of the returned array. For binary files, it is used to determine
199 Data type of the returned array. For binary files, it is used to determine
185 the size and byte-order of the items in the file.
200 the size and byte-order of the items in the file.
186
201
187 count : int
202 count : int
188 Number of items to read. -1 means all items (i.e., the complete file).
203 Number of items to read. -1 means all items (i.e., the complete file).
189
204
190 sep : str
205 sep : str
191 Separator between items if file is a text file. Empty ("") separator means
206 Separator between items if file is a text file. Empty ("") separator means
192 the file should be treated as binary. Spaces (" ") in the separator match zero
207 the file should be treated as binary. Spaces (" ") in the separator match zero
193 or more whitespace characters. A separator consisting only of spaces must match
208 or more whitespace characters. A separator consisting only of spaces must match
194 at least one whitespace.
209 at least one whitespace.
195
210
196 '''
211 '''
197
212
198
199 self.Hname= str(header['Hname'][0])
213 self.Hname = str(header['Hname'][0])
200 self.Htime= str(header['Htime'][0])
214 self.Htime = str(header['Htime'][0])
201 self.Hoper= str(header['Hoper'][0])
215 self.Hoper = str(header['Hoper'][0])
202 self.Hplace= str(header['Hplace'][0])
216 self.Hplace = str(header['Hplace'][0])
203 self.Hdescr= str(header['Hdescr'][0])
217 self.Hdescr = str(header['Hdescr'][0])
204 self.Hdummy= str(header['Hdummy'][0])
218 self.Hdummy = str(header['Hdummy'][0])
205 #1024
219 # 1024
206
220
207 self.Msign=str(header['Msign'][0])
221 self.Msign = str(header['Msign'][0])
208 self.MsizeData=header['MsizeData'][0]
222 self.MsizeData = header['MsizeData'][0]
209 #8
223 # 8
210
224
211 self.PPARsign=str(header['PPARsign'][0])
225 self.PPARsign = str(header['PPARsign'][0])
212 self.PPARsize=header['PPARsize'][0]
226 self.PPARsize = header['PPARsize'][0]
213 self.PPARprf=header['PPARprf'][0]
227 self.PPARprf = header['PPARprf'][0]
214 self.PPARpdr=header['PPARpdr'][0]
228 self.PPARpdr = header['PPARpdr'][0]
215 self.PPARsft=header['PPARsft'][0]
229 self.PPARsft = header['PPARsft'][0]
216 self.PPARavc=header['PPARavc'][0]
230 self.PPARavc = header['PPARavc'][0]
217 self.PPARihp=header['PPARihp'][0]
231 self.PPARihp = header['PPARihp'][0]
218 self.PPARchg=header['PPARchg'][0]
232 self.PPARchg = header['PPARchg'][0]
219 self.PPARpol=header['PPARpol'][0]
233 self.PPARpol = header['PPARpol'][0]
220 #Service DSP parameters
234 # Service DSP parameters
221 #36
235 # 36
222
236
223 self.SPARatt=header['SPARatt'][0]
237 self.SPARatt = header['SPARatt'][0]
224 self.SPARtx=header['SPARtx'][0]
238 self.SPARtx = header['SPARtx'][0]
225 self.SPARaddGain0=header['SPARaddGain0'][0]
239 self.SPARaddGain0 = header['SPARaddGain0'][0]
226 self.SPARaddGain1=header['SPARaddGain1'][0]
240 self.SPARaddGain1 = header['SPARaddGain1'][0]
227 self.SPARwnd=header['SPARwnd'][0]
241 self.SPARwnd = header['SPARwnd'][0]
228 self.SPARpos=header['SPARpos'][0]
242 self.SPARpos = header['SPARpos'][0]
229 self.SPARadd=header['SPARadd'][0]
243 self.SPARadd = header['SPARadd'][0]
230 self.SPARlen=header['SPARlen'][0]
244 self.SPARlen = header['SPARlen'][0]
231 self.SPARcal=header['SPARcal'][0]
245 self.SPARcal = header['SPARcal'][0]
232 self.SPARnos=header['SPARnos'][0]
246 self.SPARnos = header['SPARnos'][0]
233 self.SPARof0=header['SPARof0'][0]
247 self.SPARof0 = header['SPARof0'][0]
234 self.SPARof1=header['SPARof1'][0]
248 self.SPARof1 = header['SPARof1'][0]
235 self.SPARswt=header['SPARswt'][0]
249 self.SPARswt = header['SPARswt'][0]
236 self.SPARsum=header['SPARsum'][0]
250 self.SPARsum = header['SPARsum'][0]
237 self.SPARosc=header['SPARosc'][0]
251 self.SPARosc = header['SPARosc'][0]
238 self.SPARtst=header['SPARtst'][0]
252 self.SPARtst = header['SPARtst'][0]
239 self.SPARcor=header['SPARcor'][0]
253 self.SPARcor = header['SPARcor'][0]
240 self.SPARofs=header['SPARofs'][0]
254 self.SPARofs = header['SPARofs'][0]
241 self.SPARhsn=header['SPARhsn'][0]
255 self.SPARhsn = header['SPARhsn'][0]
242 self.SPARhsa=header['SPARhsa'][0]
256 self.SPARhsa = header['SPARhsa'][0]
243 self.SPARcalibPow_M=header['SPARcalibPow_M'][0]
257 self.SPARcalibPow_M = header['SPARcalibPow_M'][0]
244 self.SPARcalibSNR_M=header['SPARcalibSNR_M'][0]
258 self.SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
245 self.SPARcalibPow_S=header['SPARcalibPow_S'][0]
259 self.SPARcalibPow_S = header['SPARcalibPow_S'][0]
246 self.SPARcalibSNR_S=header['SPARcalibSNR_S'][0]
260 self.SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
247 self.SPARrawGate1=header['SPARrawGate1'][0]
261 self.SPARrawGate1 = header['SPARrawGate1'][0]
248 self.SPARrawGate2=header['SPARrawGate2'][0]
262 self.SPARrawGate2 = header['SPARrawGate2'][0]
249 self.SPARraw=header['SPARraw'][0]
263 self.SPARraw = header['SPARraw'][0]
250 self.SPARprc=header['SPARprc'][0]
264 self.SPARprc = header['SPARprc'][0]
251 #112
265 # 112
252 #1180
266 # 1180
253 #print 'Pointer fp header', fp.tell()
267 # print 'Pointer fp header', fp.tell()
254 #print ' '
268 # print ' '
255 #print 'SPARrawGate'
269 # print 'SPARrawGate'
256 #print self.SPARrawGate2 - self.SPARrawGate1
270 # print self.SPARrawGate2 - self.SPARrawGate1
257
271
258 #print ' '
272 # print ' '
259 #print 'Hname'
273 # print 'Hname'
260 #print self.Hname
274 # print self.Hname
261
275
262 #print ' '
276 # print ' '
263 #print 'Msign'
277 # print 'Msign'
264 #print self.Msign
278 # print self.Msign
265
279
266 def write(self, fp):
280 def write(self, fp):
267
281
268 headerTuple = (self.Hname,
282 headerTuple = (self.Hname,
269 self.Htime,
283 self.Htime,
270 self.Hoper,
284 self.Hoper,
271 self.Hplace,
285 self.Hplace,
272 self.Hdescr,
286 self.Hdescr,
273 self.Hdummy)
287 self.Hdummy)
274
288
275
276 header = numpy.array(headerTuple, FILE_HEADER)
289 header = numpy.array(headerTuple, FILE_HEADER)
277 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
290 # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0)
278 header.tofile(fp)
291 header.tofile(fp)
279 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
292 ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default).
280
293
281 fid : file or str
294 fid : file or str
282 An open file object, or a string containing a filename.
295 An open file object, or a string containing a filename.
283
296
284 sep : str
297 sep : str
285 Separator between array items for text output. If "" (empty), a binary file is written,
298 Separator between array items for text output. If "" (empty), a binary file is written,
286 equivalent to file.write(a.tobytes()).
299 equivalent to file.write(a.tobytes()).
287
300
288 format : str
301 format : str
289 Format string for text file output. Each entry in the array is formatted to text by
302 Format string for text file output. Each entry in the array is formatted to text by
290 first converting it to the closest Python type, and then using "format" % item.
303 first converting it to the closest Python type, and then using "format" % item.
291
304
292 '''
305 '''
293
306
294 return 1
307 return 1
295
308
309
296 SRVI_HEADER = numpy.dtype([
310 SRVI_HEADER = numpy.dtype([
297 ('SignatureSRVI1',numpy.str_,4),#
311 ('SignatureSRVI1', numpy.str_, 4),
298 ('SizeOfDataBlock1','<i4'),#
312 ('SizeOfDataBlock1', '<i4'),
299 ('DataBlockTitleSRVI1',numpy.str_,4),#
313 ('DataBlockTitleSRVI1', numpy.str_, 4),
300 ('SizeOfSRVI1','<i4'),])#
314 ('SizeOfSRVI1', '<i4'), ])
315
301
316
302 class SRVIHeader(Header):
317 class SRVIHeader(Header):
303 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
318 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
304
319
305 self.SignatureSRVI1 = SignatureSRVI1
320 self.SignatureSRVI1 = SignatureSRVI1
306 self.SizeOfDataBlock1 = SizeOfDataBlock1
321 self.SizeOfDataBlock1 = SizeOfDataBlock1
307 self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1
322 self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1
308 self.SizeOfSRVI1 = SizeOfSRVI1
323 self.SizeOfSRVI1 = SizeOfSRVI1
309
324
310 self.SRVIHsize=16
325 self.SRVIHsize = 16
311
326
312 def SRVIread(self, fp):
327 def SRVIread(self, fp):
313
328
314 header = numpy.fromfile(fp, SRVI_HEADER,1)
329 header = numpy.fromfile(fp, SRVI_HEADER, 1)
315
330
316 self.SignatureSRVI1 = str(header['SignatureSRVI1'][0])
331 self.SignatureSRVI1 = str(header['SignatureSRVI1'][0])
317 self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0]
332 self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0]
318 self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0])
333 self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0])
319 self.SizeOfSRVI1 = header['SizeOfSRVI1'][0]
334 self.SizeOfSRVI1 = header['SizeOfSRVI1'][0]
320 #16
335 # 16
321 print 'Pointer fp SRVIheader', fp.tell()
336 print 'Pointer fp SRVIheader', fp.tell()
322
337
323
338
324 SRVI_STRUCTURE = numpy.dtype([
339 SRVI_STRUCTURE = numpy.dtype([
325 ('frame_cnt','<u4'),#
340 ('frame_cnt', '<u4'),
326 ('time_t','<u4'), #
341 ('time_t', '<u4'), #
327 ('tpow','<f4'), #
342 ('tpow', '<f4'), #
328 ('npw1','<f4'), #
343 ('npw1', '<f4'), #
329 ('npw2','<f4'), #
344 ('npw2', '<f4'), #
330 ('cpw1','<f4'), #
345 ('cpw1', '<f4'), #
331 ('pcw2','<f4'), #
346 ('pcw2', '<f4'), #
332 ('ps_err','<u4'), #
347 ('ps_err', '<u4'), #
333 ('te_err','<u4'), #
348 ('te_err', '<u4'), #
334 ('rc_err','<u4'), #
349 ('rc_err', '<u4'), #
335 ('grs1','<u4'), #
350 ('grs1', '<u4'), #
336 ('grs2','<u4'), #
351 ('grs2', '<u4'), #
337 ('azipos','<f4'), #
352 ('azipos', '<f4'), #
338 ('azivel','<f4'), #
353 ('azivel', '<f4'), #
339 ('elvpos','<f4'), #
354 ('elvpos', '<f4'), #
340 ('elvvel','<f4'), #
355 ('elvvel', '<f4'), #
341 ('northAngle','<f4'), #
356 ('northAngle', '<f4'),
342 ('microsec','<u4'), #
357 ('microsec', '<u4'), #
343 ('azisetvel','<f4'), #
358 ('azisetvel', '<f4'), #
344 ('elvsetpos','<f4'), #
359 ('elvsetpos', '<f4'), #
345 ('RadarConst','<f4'),]) #
360 ('RadarConst', '<f4'), ]) #
346
361
347
362
348
349
350 class RecordHeader(Header):
363 class RecordHeader(Header):
351
364
352
353 def __init__(self, frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
365 def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0,
354 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
366 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
355 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
367 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
356 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0 , RecCounter=0, Off2StartNxtRec=0):
368 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0):
357
369
358
359 self.frame_cnt = frame_cnt
370 self.frame_cnt = frame_cnt
360 self.dwell = time_t
371 self.dwell = time_t
361 self.tpow = tpow
372 self.tpow = tpow
362 self.npw1 = npw1
373 self.npw1 = npw1
363 self.npw2 = npw2
374 self.npw2 = npw2
364 self.cpw1 = cpw1
375 self.cpw1 = cpw1
365 self.pcw2 = pcw2
376 self.pcw2 = pcw2
366 self.ps_err = ps_err
377 self.ps_err = ps_err
367 self.te_err = te_err
378 self.te_err = te_err
368 self.rc_err = rc_err
379 self.rc_err = rc_err
369 self.grs1 = grs1
380 self.grs1 = grs1
370 self.grs2 = grs2
381 self.grs2 = grs2
371 self.azipos = azipos
382 self.azipos = azipos
372 self.azivel = azivel
383 self.azivel = azivel
373 self.elvpos = elvpos
384 self.elvpos = elvpos
374 self.elvvel = elvvel
385 self.elvvel = elvvel
375 self.northAngle = northangle
386 self.northAngle = northangle
376 self.microsec = microsec
387 self.microsec = microsec
377 self.azisetvel = azisetvel
388 self.azisetvel = azisetvel
378 self.elvsetpos = elvsetpos
389 self.elvsetpos = elvsetpos
379 self.RadarConst = RadarConst
390 self.RadarConst = RadarConst
380 self.RHsize=84
391 self.RHsize = 84
381 self.RecCounter = RecCounter
392 self.RecCounter = RecCounter
382 self.Off2StartNxtRec=Off2StartNxtRec
393 self.Off2StartNxtRec = Off2StartNxtRec
383
394
384 def RHread(self, fp):
395 def RHread(self, fp):
385
396
386 #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
397 # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
387
398
388 #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec)
399 #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec)
389 #startFp.seek(OffRHeader, os.SEEK_SET)
400 #startFp.seek(OffRHeader, os.SEEK_SET)
390
401
391 #print 'Posicion del bloque: ',OffRHeader
402 # print 'Posicion del bloque: ',OffRHeader
392
403
393 header = numpy.fromfile(fp,SRVI_STRUCTURE,1)
404 header = numpy.fromfile(fp, SRVI_STRUCTURE, 1)
394
405
395 self.frame_cnt = header['frame_cnt'][0]#
406 self.frame_cnt = header['frame_cnt'][0]
396 self.time_t = header['time_t'][0] #
407 self.time_t = header['time_t'][0] #
397 self.tpow = header['tpow'][0] #
408 self.tpow = header['tpow'][0] #
398 self.npw1 = header['npw1'][0] #
409 self.npw1 = header['npw1'][0] #
399 self.npw2 = header['npw2'][0] #
410 self.npw2 = header['npw2'][0] #
400 self.cpw1 = header['cpw1'][0] #
411 self.cpw1 = header['cpw1'][0] #
401 self.pcw2 = header['pcw2'][0] #
412 self.pcw2 = header['pcw2'][0] #
402 self.ps_err = header['ps_err'][0] #
413 self.ps_err = header['ps_err'][0] #
403 self.te_err = header['te_err'][0] #
414 self.te_err = header['te_err'][0] #
404 self.rc_err = header['rc_err'][0] #
415 self.rc_err = header['rc_err'][0] #
405 self.grs1 = header['grs1'][0] #
416 self.grs1 = header['grs1'][0] #
406 self.grs2 = header['grs2'][0] #
417 self.grs2 = header['grs2'][0] #
407 self.azipos = header['azipos'][0] #
418 self.azipos = header['azipos'][0] #
408 self.azivel = header['azivel'][0] #
419 self.azivel = header['azivel'][0] #
409 self.elvpos = header['elvpos'][0] #
420 self.elvpos = header['elvpos'][0] #
410 self.elvvel = header['elvvel'][0] #
421 self.elvvel = header['elvvel'][0] #
411 self.northAngle = header['northAngle'][0] #
422 self.northAngle = header['northAngle'][0] #
412 self.microsec = header['microsec'][0] #
423 self.microsec = header['microsec'][0] #
413 self.azisetvel = header['azisetvel'][0] #
424 self.azisetvel = header['azisetvel'][0] #
414 self.elvsetpos = header['elvsetpos'][0] #
425 self.elvsetpos = header['elvsetpos'][0] #
415 self.RadarConst = header['RadarConst'][0] #
426 self.RadarConst = header['RadarConst'][0] #
416 #84
427 # 84
417
428
418 #print 'Pointer fp RECheader', fp.tell()
429 # print 'Pointer fp RECheader', fp.tell()
419
430
420 #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
431 #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz)
421
432
422 #self.RHsize = 180+20*self.nChannels
433 #self.RHsize = 180+20*self.nChannels
423 #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
434 #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4
424 #print 'Datasize',self.Datasize
435 # print 'Datasize',self.Datasize
425 #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
436 #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
426
437
427 print '=============================================='
438 print '=============================================='
428
439
429 print '=============================================='
440 print '=============================================='
430
441
431
432 return 1
442 return 1
433
443
444
434 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
445 class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader):
435
446
436 path = None
447 path = None
437 startDate = None
448 startDate = None
438 endDate = None
449 endDate = None
439 startTime = None
450 startTime = None
440 endTime = None
451 endTime = None
441 walk = None
452 walk = None
442 isConfig = False
453 isConfig = False
443
454
444
445 fileList= None
455 fileList = None
446
456
447 #metadata
457 # metadata
448 TimeZone= None
458 TimeZone = None
449 Interval= None
459 Interval = None
450 heightList= None
460 heightList = None
451
461
452 #data
462 # data
453 data= None
463 data = None
454 utctime= None
464 utctime = None
455
465
456
457
458 def __init__(self, **kwargs):
466 def __init__(self, **kwargs):
459
467
460 #Eliminar de la base la herencia
468 # Eliminar de la base la herencia
461 ProcessingUnit.__init__(self, **kwargs)
469 ProcessingUnit.__init__(self, **kwargs)
462 self.PointerReader = 0
470 self.PointerReader = 0
463 self.FileHeaderFlag = False
471 self.FileHeaderFlag = False
464 self.utc = None
472 self.utc = None
465 self.ext = ".zspca"
473 self.ext = ".zspca"
466 self.optchar = "P"
474 self.optchar = "P"
467 self.fpFile=None
475 self.fpFile = None
468 self.fp = None
476 self.fp = None
469 self.BlockCounter=0
477 self.BlockCounter = 0
470 self.dtype = None
478 self.dtype = None
471 self.fileSizeByHeader = None
479 self.fileSizeByHeader = None
472 self.filenameList = []
480 self.filenameList = []
473 self.fileSelector = 0
481 self.fileSelector = 0
474 self.Off2StartNxtRec=0
482 self.Off2StartNxtRec = 0
475 self.RecCounter=0
483 self.RecCounter = 0
476 self.flagNoMoreFiles = 0
484 self.flagNoMoreFiles = 0
477 self.data_spc=None
485 self.data_spc = None
478 #self.data_cspc=None
486 # self.data_cspc=None
479 self.data_output=None
487 self.data_output = None
480 self.path = None
488 self.path = None
481 self.OffsetStartHeader=0
489 self.OffsetStartHeader = 0
482 self.Off2StartData=0
490 self.Off2StartData = 0
483 self.ipp = 0
491 self.ipp = 0
484 self.nFDTdataRecors=0
492 self.nFDTdataRecors = 0
485 self.blocksize = 0
493 self.blocksize = 0
486 self.dataOut = Spectra()
494 self.dataOut = Spectra()
487 self.profileIndex = 1 #Always
495 self.profileIndex = 1 # Always
488 self.dataOut.flagNoData=False
496 self.dataOut.flagNoData = False
489 self.dataOut.nRdPairs = 0
497 self.dataOut.nRdPairs = 0
490 self.dataOut.pairsList = []
498 self.dataOut.pairsList = []
491 self.dataOut.data_spc=None
499 self.dataOut.data_spc = None
492
500
493 self.dataOut.normFactor=1
501 self.dataOut.normFactor = 1
494 self.nextfileflag = True
502 self.nextfileflag = True
495 self.dataOut.RadarConst = 0
503 self.dataOut.RadarConst = 0
496 self.dataOut.HSDV = []
504 self.dataOut.HSDV = []
497 self.dataOut.NPW = []
505 self.dataOut.NPW = []
498 self.dataOut.COFA = []
506 self.dataOut.COFA = []
499 self.dataOut.noise = 0
507 self.dataOut.noise = 0
500
508
501
502 def Files2Read(self, fp):
509 def Files2Read(self, fp):
503 '''
510 '''
504 Function that indicates the number of .fdt files that exist in the folder to be read.
511 Function that indicates the number of .fdt files that exist in the folder to be read.
505 It also creates an organized list with the names of the files to read.
512 It also creates an organized list with the names of the files to read.
506 '''
513 '''
507 #self.__checkPath()
514 # self.__checkPath()
508
515
509 ListaData=os.listdir(fp) #Gets the list of files within the fp address
516 # Gets the list of files within the fp address
510 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
517 ListaData = os.listdir(fp)
518 # Sort the list of files from least to largest by names
519 ListaData = sorted(ListaData)
511 nFiles=0 #File Counter
520 nFiles = 0 # File Counter
512 FileList=[] #A list is created that will contain the .fdt files
521 FileList = [] # A list is created that will contain the .fdt files
513 for IndexFile in ListaData :
522 for IndexFile in ListaData:
514 if '.zspca' in IndexFile and '.gz' not in IndexFile:
523 if '.zspca' in IndexFile and '.gz' not in IndexFile:
515 FileList.append(IndexFile)
524 FileList.append(IndexFile)
516 nFiles+=1
525 nFiles += 1
517
526
518 #print 'Files2Read'
527 # print 'Files2Read'
519 #print 'Existen '+str(nFiles)+' archivos .fdt'
528 # print 'Existen '+str(nFiles)+' archivos .fdt'
520
529
521 self.filenameList=FileList #List of files from least to largest by names
530 self.filenameList = FileList # List of files from least to largest by names
522
531
523
524 def run(self, **kwargs):
532 def run(self, **kwargs):
525 '''
533 '''
526 This method will be the one that will initiate the data entry, will be called constantly.
534 This method will be the one that will initiate the data entry, will be called constantly.
527 You should first verify that your Setup () is set up and then continue to acquire
535 You should first verify that your Setup () is set up and then continue to acquire
528 the data to be processed with getData ().
536 the data to be processed with getData ().
529 '''
537 '''
530 if not self.isConfig:
538 if not self.isConfig:
531 self.setup(**kwargs)
539 self.setup(**kwargs)
532 self.isConfig = True
540 self.isConfig = True
533
541
534 self.getData()
542 self.getData()
535
543
536
537 def setup(self, path=None,
544 def setup(self, path=None,
538 startDate=None,
545 startDate=None,
539 endDate=None,
546 endDate=None,
540 startTime=None,
547 startTime=None,
541 endTime=None,
548 endTime=None,
542 walk=True,
549 walk=True,
543 timezone='utc',
550 timezone='utc',
544 code = None,
551 code=None,
545 online=False,
552 online=False,
546 ReadMode=None, **kwargs):
553 ReadMode=None, **kwargs):
547
554
548 self.isConfig = True
555 self.isConfig = True
549
556
550 self.path=path
557 self.path = path
551 self.startDate=startDate
558 self.startDate = startDate
552 self.endDate=endDate
559 self.endDate = endDate
553 self.startTime=startTime
560 self.startTime = startTime
554 self.endTime=endTime
561 self.endTime = endTime
555 self.walk=walk
562 self.walk = walk
556 #self.ReadMode=int(ReadMode)
563 # self.ReadMode=int(ReadMode)
557
564
558 pass
565 pass
559
566
560
561 def getData(self):
567 def getData(self):
562 '''
568 '''
563 Before starting this function, you should check that there is still an unread file,
569 Before starting this function, you should check that there is still an unread file,
564 If there are still blocks to read or if the data block is empty.
570 If there are still blocks to read or if the data block is empty.
565
571
566 You should call the file "read".
572 You should call the file "read".
567
573
568 '''
574 '''
569
575
570 if self.flagNoMoreFiles:
576 if self.flagNoMoreFiles:
571 self.dataOut.flagNoData = True
577 self.dataOut.flagNoData = True
572 print 'NoData se vuelve true'
578 print 'NoData se vuelve true'
573 return 0
579 return 0
574
580
575 self.fp=self.path
581 self.fp = self.path
576 self.Files2Read(self.fp)
582 self.Files2Read(self.fp)
577 self.readFile(self.fp)
583 self.readFile(self.fp)
578
584
579 self.dataOut.data_spc = self.dataOut_spc#self.data_spc.copy()
585 self.dataOut.data_spc = self.dataOut_spc # self.data_spc.copy()
580 self.dataOut.RadarConst = self.RadarConst
586 self.dataOut.RadarConst = self.RadarConst
581 self.dataOut.data_output=self.data_output
587 self.dataOut.data_output = self.data_output
582 self.dataOut.noise = self.dataOut.getNoise()
588 self.dataOut.noise = self.dataOut.getNoise()
583 #print 'ACAAAAAA', self.dataOut.noise
589 # print 'ACAAAAAA', self.dataOut.noise
584 self.dataOut.data_spc = self.dataOut.data_spc+self.dataOut.noise
590 self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise
585 #print 'self.dataOut.noise',self.dataOut.noise
591 # print 'self.dataOut.noise',self.dataOut.noise
586
592
587
588 return self.dataOut.data_spc
593 return self.dataOut.data_spc
589
594
590
591 def readFile(self,fp):
595 def readFile(self, fp):
592 '''
596 '''
593 You must indicate if you are reading in Online or Offline mode and load the
597 You must indicate if you are reading in Online or Offline mode and load the
594 The parameters for this file reading mode.
598 The parameters for this file reading mode.
595
599
596 Then you must do 2 actions:
600 Then you must do 2 actions:
597
601
598 1. Get the BLTR FileHeader.
602 1. Get the BLTR FileHeader.
599 2. Start reading the first block.
603 2. Start reading the first block.
600 '''
604 '''
601
605
602 #The address of the folder is generated the name of the .fdt file that will be read
606 # The address of the folder is generated the name of the .fdt file that will be read
603 print "File: ",self.fileSelector+1
607 print "File: ", self.fileSelector + 1
604
608
605 if self.fileSelector < len(self.filenameList):
609 if self.fileSelector < len(self.filenameList):
606
610
607 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
611 self.fpFile = str(fp) + '/' + \
612 str(self.filenameList[self.fileSelector])
608
613
609 if self.nextfileflag==True:
614 if self.nextfileflag == True:
610 self.fp = open(self.fpFile,"rb")
615 self.fp = open(self.fpFile, "rb")
611 self.nextfileflag==False
616 self.nextfileflag == False
612
617
613 '''HERE STARTING THE FILE READING'''
618 '''HERE STARTING THE FILE READING'''
614
619
615
616 self.fheader = FileHeaderMIRA35c()
620 self.fheader = FileHeaderMIRA35c()
617 self.fheader.FHread(self.fp) #Bltr FileHeader Reading
621 self.fheader.FHread(self.fp) # Bltr FileHeader Reading
618
622
619
620 self.SPARrawGate1 = self.fheader.SPARrawGate1
623 self.SPARrawGate1 = self.fheader.SPARrawGate1
621 self.SPARrawGate2 = self.fheader.SPARrawGate2
624 self.SPARrawGate2 = self.fheader.SPARrawGate2
622 self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
625 self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
623 self.Num_Bins = self.fheader.PPARsft
626 self.Num_Bins = self.fheader.PPARsft
624 self.dataOut.nFFTPoints = self.fheader.PPARsft
627 self.dataOut.nFFTPoints = self.fheader.PPARsft
625
628
626
627 self.Num_inCoh = self.fheader.PPARavc
629 self.Num_inCoh = self.fheader.PPARavc
628 self.dataOut.PRF = self.fheader.PPARprf
630 self.dataOut.PRF = self.fheader.PPARprf
629 self.dataOut.frequency = 34.85*10**9
631 self.dataOut.frequency = 34.85 * 10**9
630 self.Lambda = SPEED_OF_LIGHT/self.dataOut.frequency
632 self.Lambda = SPEED_OF_LIGHT / self.dataOut.frequency
631 self.dataOut.ippSeconds= 1./float(self.dataOut.PRF)
633 self.dataOut.ippSeconds = 1. / float(self.dataOut.PRF)
632
634
633 pulse_width = self.fheader.PPARpdr * 10**-9
635 pulse_width = self.fheader.PPARpdr * 10**-9
634 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
636 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
635
637
636 self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins,2))#
638 self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins, 2))
637 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
639 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
638
640
639 self.Ze = numpy.zeros(self.Num_Hei)
641 self.Ze = numpy.zeros(self.Num_Hei)
640 self.ETA = numpy.zeros(([2,self.Num_Hei]))
642 self.ETA = numpy.zeros(([2, self.Num_Hei]))
641
643
642
643
644 self.readBlock() #Block reading
644 self.readBlock() # Block reading
645
645
646 else:
646 else:
647 print 'readFile FlagNoData becomes true'
647 print 'readFile FlagNoData becomes true'
648 self.flagNoMoreFiles=True
648 self.flagNoMoreFiles = True
649 self.dataOut.flagNoData = True
649 self.dataOut.flagNoData = True
650 self.FileHeaderFlag == True
650 self.FileHeaderFlag == True
651 return 0
651 return 0
652
652
653
654
655 def readBlock(self):
653 def readBlock(self):
656 '''
654 '''
657 It should be checked if the block has data, if it is not passed to the next file.
655 It should be checked if the block has data, if it is not passed to the next file.
658
656
659 Then the following is done:
657 Then the following is done:
660
658
661 1. Read the RecordHeader
659 1. Read the RecordHeader
662 2. Fill the buffer with the current block number.
660 2. Fill the buffer with the current block number.
663
661
664 '''
662 '''
665
663
666 if self.PointerReader > 1180:
664 if self.PointerReader > 1180:
667 self.fp.seek(self.PointerReader , os.SEEK_SET)
665 self.fp.seek(self.PointerReader, os.SEEK_SET)
668 self.FirstPoint = self.PointerReader
666 self.FirstPoint = self.PointerReader
669
667
670 else :
668 else:
671 self.FirstPoint = 1180
669 self.FirstPoint = 1180
672
670
673
674
675 self.srviHeader = SRVIHeader()
671 self.srviHeader = SRVIHeader()
676
672
677 self.srviHeader.SRVIread(self.fp) #Se obtiene la cabecera del SRVI
673 self.srviHeader.SRVIread(self.fp) # Se obtiene la cabecera del SRVI
678
674
679 self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque
675 self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque
680
676
681 if self.blocksize == 148:
677 if self.blocksize == 148:
682 print 'blocksize == 148 bug'
678 print 'blocksize == 148 bug'
683 jump = numpy.fromfile(self.fp,[('jump',numpy.str_,140)] ,1)
679 jump = numpy.fromfile(self.fp, [('jump', numpy.str_, 140)], 1)
684
680
685 self.srviHeader.SRVIread(self.fp) #Se obtiene la cabecera del SRVI
681 # Se obtiene la cabecera del SRVI
682 self.srviHeader.SRVIread(self.fp)
686
683
687 if not self.srviHeader.SizeOfSRVI1:
684 if not self.srviHeader.SizeOfSRVI1:
688 self.fileSelector+=1
685 self.fileSelector += 1
689 self.nextfileflag==True
686 self.nextfileflag == True
690 self.FileHeaderFlag == True
687 self.FileHeaderFlag == True
691
688
692 self.recordheader = RecordHeader()
689 self.recordheader = RecordHeader()
693 self.recordheader.RHread(self.fp)
690 self.recordheader.RHread(self.fp)
694 self.RadarConst = self.recordheader.RadarConst
691 self.RadarConst = self.recordheader.RadarConst
695 dwell = self.recordheader.time_t
692 dwell = self.recordheader.time_t
696 npw1 = self.recordheader.npw1
693 npw1 = self.recordheader.npw1
697 npw2 = self.recordheader.npw2
694 npw2 = self.recordheader.npw2
698
695
699
700 self.dataOut.channelList = range(1)
696 self.dataOut.channelList = range(1)
701 self.dataOut.nIncohInt = self.Num_inCoh
697 self.dataOut.nIncohInt = self.Num_inCoh
702 self.dataOut.nProfiles = self.Num_Bins
698 self.dataOut.nProfiles = self.Num_Bins
703 self.dataOut.nCohInt = 1
699 self.dataOut.nCohInt = 1
704 self.dataOut.windowOfFilter = 1
700 self.dataOut.windowOfFilter = 1
705 self.dataOut.utctime = dwell
701 self.dataOut.utctime = dwell
706 self.dataOut.timeZone=0
702 self.dataOut.timeZone = 0
707
703
708 self.dataOut.outputInterval = self.dataOut.getTimeInterval()
704 self.dataOut.outputInterval = self.dataOut.getTimeInterval()
709 self.dataOut.heightList = self.SPARrawGate1*self.__deltaHeigth + numpy.array(range(self.Num_Hei))*self.__deltaHeigth
705 self.dataOut.heightList = self.SPARrawGate1 * self.__deltaHeigth + \
710
706 numpy.array(range(self.Num_Hei)) * self.__deltaHeigth
711
712
707
713 self.HSDVsign = numpy.fromfile( self.fp, [('HSDV',numpy.str_,4)],1)
708 self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1)
714 self.SizeHSDV = numpy.fromfile( self.fp, [('SizeHSDV','<i4')],1)
709 self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1)
715 self.HSDV_Co = numpy.fromfile( self.fp, [('HSDV_Co','<f4')],self.Num_Hei)
710 self.HSDV_Co = numpy.fromfile(
716 self.HSDV_Cx = numpy.fromfile( self.fp, [('HSDV_Cx','<f4')],self.Num_Hei)
711 self.fp, [('HSDV_Co', '<f4')], self.Num_Hei)
712 self.HSDV_Cx = numpy.fromfile(
713 self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei)
717
714
718 self.COFAsign = numpy.fromfile( self.fp, [('COFA',numpy.str_,4)],1)
715 self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1)
719 self.SizeCOFA = numpy.fromfile( self.fp, [('SizeCOFA','<i4')],1)
716 self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1)
720 self.COFA_Co = numpy.fromfile( self.fp, [('COFA_Co','<f4')],self.Num_Hei)
717 self.COFA_Co = numpy.fromfile(
721 self.COFA_Cx = numpy.fromfile( self.fp, [('COFA_Cx','<f4')],self.Num_Hei)
718 self.fp, [('COFA_Co', '<f4')], self.Num_Hei)
719 self.COFA_Cx = numpy.fromfile(
720 self.fp, [('COFA_Cx', '<f4')], self.Num_Hei)
722
721
723 self.ZSPCsign = numpy.fromfile(self.fp, [('ZSPCsign',numpy.str_,4)],1)
722 self.ZSPCsign = numpy.fromfile(
723 self.fp, [('ZSPCsign', numpy.str_, 4)], 1)
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC','<i4')],1)
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1)
725
725
726 self.dataOut.HSDV[0]=self.HSDV_Co[:][0]
726 self.dataOut.HSDV[0] = self.HSDV_Co[:][0]
727 self.dataOut.HSDV[1]=self.HSDV_Cx[:][0]
727 self.dataOut.HSDV[1] = self.HSDV_Cx[:][0]
728
728
729 for irg in range(self.Num_Hei):
729 for irg in range(self.Num_Hei):
730 nspc = numpy.fromfile(self.fp, [('nspc','int16')],1)[0][0] # Number of spectral sub pieces containing significant power
730 # Number of spectral sub pieces containing significant power
731 nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0]
731
732
732 for k in range(nspc):
733 for k in range(nspc):
733 binIndex = numpy.fromfile(self.fp, [('binIndex','int16')],1)[0][0] # Index of the spectral bin where the piece is beginning
734 # Index of the spectral bin where the piece is beginning
734 nbins = numpy.fromfile(self.fp, [('nbins','int16')],1)[0][0] # Number of bins of the piece
735 binIndex = numpy.fromfile(
736 self.fp, [('binIndex', 'int16')], 1)[0][0]
737 nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[
738 0][0] # Number of bins of the piece
735
739
736 #Co_Channel
740 # Co_Channel
737 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0] # Spectrum piece to be normaliced
741 jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[
738 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0] # Maximun piece to be normaliced
742 0][0] # Spectrum piece to be normaliced
739
743 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[
744 0][0] # Maximun piece to be normaliced
740
745
741 self.data_spc[irg,binIndex:binIndex+nbins,0] = self.data_spc[irg,binIndex:binIndex+nbins,0]+jbin/65530.*jmax
746 self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg,
747 binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax
742
748
743 #Cx_Channel
749 # Cx_Channel
744 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0]
750 jbin = numpy.fromfile(
751 self.fp, [('jbin', 'uint16')], nbins)[0][0]
745 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0]
752 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0]
746
753
747
754 self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg,
748 self.data_spc[irg,binIndex:binIndex+nbins,1] = self.data_spc[irg,binIndex:binIndex+nbins,1]+jbin/65530.*jmax
755 binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax
749
756
750 for bin in range(self.Num_Bins):
757 for bin in range(self.Num_Bins):
751
758
752 self.data_spc[:,bin,0] = self.data_spc[:,bin,0] - self.dataOut.HSDV[:,0]
759 self.data_spc[:, bin, 0] = self.data_spc[:,
753
760 bin, 0] - self.dataOut.HSDV[:, 0]
754 self.data_spc[:,bin,1] = self.data_spc[:,bin,1] - self.dataOut.HSDV[:,1]
755
761
762 self.data_spc[:, bin, 1] = self.data_spc[:,
763 bin, 1] - self.dataOut.HSDV[:, 1]
756
764
757 numpy.set_printoptions(threshold='nan')
765 numpy.set_printoptions(threshold='nan')
758
766
759 self.data_spc = numpy.where(self.data_spc > 0. , self.data_spc, 0)
767 self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0)
760
768
761 self.dataOut.COFA = numpy.array([self.COFA_Co , self.COFA_Cx])
769 self.dataOut.COFA = numpy.array([self.COFA_Co, self.COFA_Cx])
762
770
763 print ' '
771 print ' '
764 print 'SPC',numpy.shape(self.dataOut.data_spc)
772 print 'SPC', numpy.shape(self.dataOut.data_spc)
765 #print 'SPC',self.dataOut.data_spc
773 # print 'SPC',self.dataOut.data_spc
766
774
767 noinor1 = 713031680
775 noinor1 = 713031680
768 noinor2 = 30
776 noinor2 = 30
769
777
770 npw1 = 1#0**(npw1/10) * noinor1 * noinor2
778 npw1 = 1 # 0**(npw1/10) * noinor1 * noinor2
771 npw2 = 1#0**(npw2/10) * noinor1 * noinor2
779 npw2 = 1 # 0**(npw2/10) * noinor1 * noinor2
772 self.dataOut.NPW = numpy.array([npw1, npw2])
780 self.dataOut.NPW = numpy.array([npw1, npw2])
773
781
774 print ' '
782 print ' '
775
783
776 self.data_spc = numpy.transpose(self.data_spc, (2,1,0))
784 self.data_spc = numpy.transpose(self.data_spc, (2, 1, 0))
777 self.data_spc = numpy.fft.fftshift(self.data_spc, axes = 1)
785 self.data_spc = numpy.fft.fftshift(self.data_spc, axes=1)
778
786
779 self.data_spc = numpy.fliplr(self.data_spc)
787 self.data_spc = numpy.fliplr(self.data_spc)
780
788
781 self.data_spc = numpy.where(self.data_spc > 0. , self.data_spc, 0)
789 self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0)
782 self.dataOut_spc= numpy.ones([1, self.Num_Bins , self.Num_Hei])
790 self.dataOut_spc = numpy.ones([1, self.Num_Bins, self.Num_Hei])
783 self.dataOut_spc[0,:,:] = self.data_spc[0,:,:]
791 self.dataOut_spc[0, :, :] = self.data_spc[0, :, :]
784 #print 'SHAPE', self.dataOut_spc.shape
792 # print 'SHAPE', self.dataOut_spc.shape
785 #For nyquist correction:
793 # For nyquist correction:
786 #fix = 20 # ~3m/s
794 # fix = 20 # ~3m/s
787 #shift = self.Num_Bins/2 + fix
795 #shift = self.Num_Bins/2 + fix
788 #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]])
796 #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]])
789
797
790
791
792 '''Block Reading, the Block Data is received and Reshape is used to give it
798 '''Block Reading, the Block Data is received and Reshape is used to give it
793 shape.
799 shape.
794 '''
800 '''
795
801
796 self.PointerReader = self.fp.tell()
802 self.PointerReader = self.fp.tell()
797
798
799
800
801
802
803 No newline at end of file
@@ -1,698 +1,679
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import numpy
6 import numpy
7
7
8 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
8 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
11 from schainpy.model.data.jrodata import Spectra
11 from schainpy.model.data.jrodata import Spectra
12
12
13 class SpectraReader(JRODataReader, ProcessingUnit):
13 class SpectraReader(JRODataReader, ProcessingUnit):
14
15 """
14 """
16 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
15 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
17 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
16 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
18 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
17 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
19
18
20 paresCanalesIguales * alturas * perfiles (Self Spectra)
19 paresCanalesIguales * alturas * perfiles (Self Spectra)
21 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
20 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
22 canales * alturas (DC Channels)
21 canales * alturas (DC Channels)
23
22
24
25 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
26 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
24 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
27 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
25 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
28 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
26 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
29
27
30 Example:
28 Example:
31 dpath = "/home/myuser/data"
29 dpath = "/home/myuser/data"
32
30
33 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
31 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
34
32
35 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
33 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
36
34
37 readerObj = SpectraReader()
35 readerObj = SpectraReader()
38
36
39 readerObj.setup(dpath, startTime, endTime)
37 readerObj.setup(dpath, startTime, endTime)
40
38
41 while(True):
39 while(True):
42
40
43 readerObj.getData()
41 readerObj.getData()
44
42
45 print readerObj.data_spc
43 print readerObj.data_spc
46
44
47 print readerObj.data_cspc
45 print readerObj.data_cspc
48
46
49 print readerObj.data_dc
47 print readerObj.data_dc
50
48
51 if readerObj.flagNoMoreFiles:
49 if readerObj.flagNoMoreFiles:
52 break
50 break
53
51
54 """
52 """
55
53
56 pts2read_SelfSpectra = 0
54 pts2read_SelfSpectra = 0
57
55
58 pts2read_CrossSpectra = 0
56 pts2read_CrossSpectra = 0
59
57
60 pts2read_DCchannels = 0
58 pts2read_DCchannels = 0
61
59
62 ext = ".pdata"
60 ext = ".pdata"
63
61
64 optchar = "P"
62 optchar = "P"
65
63
66 dataOut = None
64 dataOut = None
67
65
68 nRdChannels = None
66 nRdChannels = None
69
67
70 nRdPairs = None
68 nRdPairs = None
71
69
72 rdPairList = []
70 rdPairList = []
73
71
74 def __init__(self, **kwargs):
72 def __init__(self, **kwargs):
75 """
73 """
76 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
74 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
77
75
78 Inputs:
76 Inputs:
79
80 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
77 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
81 almacenar un perfil de datos cada vez que se haga un requerimiento
78 almacenar un perfil de datos cada vez que se haga un requerimiento
82 (getData). El perfil sera obtenido a partir del buffer de datos,
79 (getData). El perfil sera obtenido a partir del buffer de datos,
83 si el buffer esta vacio se hara un nuevo proceso de lectura de un
80 si el buffer esta vacio se hara un nuevo proceso de lectura de un
84 bloque de datos.
81 bloque de datos.
85 Si este parametro no es pasado se creara uno internamente.
82 Si este parametro no es pasado se creara uno internamente.
86
83
87
88 Affected:
84 Affected:
89
90 self.dataOut
85 self.dataOut
91
86
92 Return : None
87 Return : None
93 """
88 """
94
89
95
96 #Eliminar de la base la herencia
90 #Eliminar de la base la herencia
97 ProcessingUnit.__init__(self, **kwargs)
91 ProcessingUnit.__init__(self, **kwargs)
98
92
99 # self.isConfig = False
93 # self.isConfig = False
100
94
101 self.pts2read_SelfSpectra = 0
95 self.pts2read_SelfSpectra = 0
102
96
103 self.pts2read_CrossSpectra = 0
97 self.pts2read_CrossSpectra = 0
104
98
105 self.pts2read_DCchannels = 0
99 self.pts2read_DCchannels = 0
106
100
107 self.datablock = None
101 self.datablock = None
108
102
109 self.utc = None
103 self.utc = None
110
104
111 self.ext = ".pdata"
105 self.ext = ".pdata"
112
106
113 self.optchar = "P"
107 self.optchar = "P"
114
108
115 self.basicHeaderObj = BasicHeader(LOCALTIME)
109 self.basicHeaderObj = BasicHeader(LOCALTIME)
116
110
117 self.systemHeaderObj = SystemHeader()
111 self.systemHeaderObj = SystemHeader()
118
112
119 self.radarControllerHeaderObj = RadarControllerHeader()
113 self.radarControllerHeaderObj = RadarControllerHeader()
120
114
121 self.processingHeaderObj = ProcessingHeader()
115 self.processingHeaderObj = ProcessingHeader()
122
116
123 self.online = 0
117 self.online = 0
124
118
125 self.fp = None
119 self.fp = None
126
120
127 self.idFile = None
121 self.idFile = None
128
122
129 self.dtype = None
123 self.dtype = None
130
124
131 self.fileSizeByHeader = None
125 self.fileSizeByHeader = None
132
126
133 self.filenameList = []
127 self.filenameList = []
134
128
135 self.filename = None
129 self.filename = None
136
130
137 self.fileSize = None
131 self.fileSize = None
138
132
139 self.firstHeaderSize = 0
133 self.firstHeaderSize = 0
140
134
141 self.basicHeaderSize = 24
135 self.basicHeaderSize = 24
142
136
143 self.pathList = []
137 self.pathList = []
144
138
145 self.lastUTTime = 0
139 self.lastUTTime = 0
146
140
147 self.maxTimeStep = 30
141 self.maxTimeStep = 30
148
142
149 self.flagNoMoreFiles = 0
143 self.flagNoMoreFiles = 0
150
144
151 self.set = 0
145 self.set = 0
152
146
153 self.path = None
147 self.path = None
154
148
155 self.delay = 60 #seconds
149 self.delay = 60 #seconds
156
150
157 self.nTries = 3 #quantity tries
151 self.nTries = 3 #quantity tries
158
152
159 self.nFiles = 3 #number of files for searching
153 self.nFiles = 3 #number of files for searching
160
154
161 self.nReadBlocks = 0
155 self.nReadBlocks = 0
162
156
163 self.flagIsNewFile = 1
157 self.flagIsNewFile = 1
164
158
165 self.__isFirstTimeOnline = 1
159 self.__isFirstTimeOnline = 1
166
160
167 # self.ippSeconds = 0
161 # self.ippSeconds = 0
168
162
169 self.flagDiscontinuousBlock = 0
163 self.flagDiscontinuousBlock = 0
170
164
171 self.flagIsNewBlock = 0
165 self.flagIsNewBlock = 0
172
166
173 self.nTotalBlocks = 0
167 self.nTotalBlocks = 0
174
168
175 self.blocksize = 0
169 self.blocksize = 0
176
170
177 self.dataOut = self.createObjByDefault()
171 self.dataOut = self.createObjByDefault()
178
172
179 self.profileIndex = 1 #Always
173 self.profileIndex = 1 #Always
180
174
181
175
182 def createObjByDefault(self):
176 def createObjByDefault(self):
183
177
184 dataObj = Spectra()
178 dataObj = Spectra()
185
179
186 return dataObj
180 return dataObj
187
181
188 def __hasNotDataInBuffer(self):
182 def __hasNotDataInBuffer(self):
189 return 1
183 return 1
190
184
191
185
192 def getBlockDimension(self):
186 def getBlockDimension(self):
193 """
187 """
194 Obtiene la cantidad de puntos a leer por cada bloque de datos
188 Obtiene la cantidad de puntos a leer por cada bloque de datos
195
189
196 Affected:
190 Affected:
197 self.nRdChannels
191 self.nRdChannels
198 self.nRdPairs
192 self.nRdPairs
199 self.pts2read_SelfSpectra
193 self.pts2read_SelfSpectra
200 self.pts2read_CrossSpectra
194 self.pts2read_CrossSpectra
201 self.pts2read_DCchannels
195 self.pts2read_DCchannels
202 self.blocksize
196 self.blocksize
203 self.dataOut.nChannels
197 self.dataOut.nChannels
204 self.dataOut.nPairs
198 self.dataOut.nPairs
205
199
206 Return:
200 Return:
207 None
201 None
208 """
202 """
209 self.nRdChannels = 0
203 self.nRdChannels = 0
210 self.nRdPairs = 0
204 self.nRdPairs = 0
211 self.rdPairList = []
205 self.rdPairList = []
212
206
213 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
207 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
214 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
208 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
215 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
209 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
216
217 else:
210 else:
218 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
211 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
219 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
212 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
220
213
221 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
214 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
222
215
223 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
216 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
224 self.blocksize = self.pts2read_SelfSpectra
217 self.blocksize = self.pts2read_SelfSpectra
225
218
226 if self.processingHeaderObj.flag_cspc:
219 if self.processingHeaderObj.flag_cspc:
227 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
220 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
228 self.blocksize += self.pts2read_CrossSpectra
221 self.blocksize += self.pts2read_CrossSpectra
229
222
230 if self.processingHeaderObj.flag_dc:
223 if self.processingHeaderObj.flag_dc:
231 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
224 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
232 self.blocksize += self.pts2read_DCchannels
225 self.blocksize += self.pts2read_DCchannels
233
226
234 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
227 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
235
228
236
229
237 def readBlock(self):
230 def readBlock(self):
238 """
231 """
239 Lee el bloque de datos desde la posicion actual del puntero del archivo
232 Lee el bloque de datos desde la posicion actual del puntero del archivo
240 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
233 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
241 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
234 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
242 es seteado a 0
235 es seteado a 0
243
236
244 Return: None
237 Return: None
245
238
246 Variables afectadas:
239 Variables afectadas:
247
240
248
249 self.flagIsNewFile
241 self.flagIsNewFile
250 self.flagIsNewBlock
242 self.flagIsNewBlock
251 self.nTotalBlocks
243 self.nTotalBlocks
252 self.data_spc
244 self.data_spc
253 self.data_cspc
245 self.data_cspc
254 self.data_dc
246 self.data_dc
255
247
256 Exceptions:
248 Exceptions:
257 Si un bloque leido no es un bloque valido
249 Si un bloque leido no es un bloque valido
258 """
250 """
259
260 blockOk_flag = False
251 blockOk_flag = False
261 fpointer = self.fp.tell()
252 fpointer = self.fp.tell()
262
253
263 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
254 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
264 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
255 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
265
256
266 if self.processingHeaderObj.flag_cspc:
257 if self.processingHeaderObj.flag_cspc:
267 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
258 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
268 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
259 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
269
260
270 if self.processingHeaderObj.flag_dc:
261 if self.processingHeaderObj.flag_dc:
271 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
262 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
272 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
263 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
273
264
274
265
275 if not(self.processingHeaderObj.shif_fft):
266 if not(self.processingHeaderObj.shif_fft):
276 #desplaza a la derecha en el eje 2 determinadas posiciones
267 #desplaza a la derecha en el eje 2 determinadas posiciones
277 shift = int(self.processingHeaderObj.profilesPerBlock/2)
268 shift = int(self.processingHeaderObj.profilesPerBlock/2)
278 spc = numpy.roll( spc, shift , axis=2 )
269 spc = numpy.roll( spc, shift , axis=2 )
279
270
280 if self.processingHeaderObj.flag_cspc:
271 if self.processingHeaderObj.flag_cspc:
281 #desplaza a la derecha en el eje 2 determinadas posiciones
272 #desplaza a la derecha en el eje 2 determinadas posiciones
282 cspc = numpy.roll( cspc, shift, axis=2 )
273 cspc = numpy.roll( cspc, shift, axis=2 )
283
274
284 #Dimensions : nChannels, nProfiles, nSamples
275 #Dimensions : nChannels, nProfiles, nSamples
285 spc = numpy.transpose( spc, (0,2,1) )
276 spc = numpy.transpose( spc, (0,2,1) )
286 self.data_spc = spc
277 self.data_spc = spc
287
278
288 if self.processingHeaderObj.flag_cspc:
279 if self.processingHeaderObj.flag_cspc:
289
290 cspc = numpy.transpose( cspc, (0,2,1) )
280 cspc = numpy.transpose( cspc, (0,2,1) )
291 self.data_cspc = cspc['real'] + cspc['imag']*1j
281 self.data_cspc = cspc['real'] + cspc['imag']*1j
292 else:
282 else:
293 self.data_cspc = None
283 self.data_cspc = None
294
284
295
296 if self.processingHeaderObj.flag_dc:
285 if self.processingHeaderObj.flag_dc:
297 self.data_dc = dc['real'] + dc['imag']*1j
286 self.data_dc = dc['real'] + dc['imag']*1j
298 else:
287 else:
299 self.data_dc = None
288 self.data_dc = None
300
289
301 self.flagIsNewFile = 0
290 self.flagIsNewFile = 0
302 self.flagIsNewBlock = 1
291 self.flagIsNewBlock = 1
303
292
304 self.nTotalBlocks += 1
293 self.nTotalBlocks += 1
305 self.nReadBlocks += 1
294 self.nReadBlocks += 1
306
295
307 return 1
296 return 1
308
297
309 def getFirstHeader(self):
298 def getFirstHeader(self):
310
299
311 self.getBasicHeader()
300 self.getBasicHeader()
312
301
313 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
302 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
314
303
315 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
304 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
316
305
317 # self.dataOut.ippSeconds = self.ippSeconds
306 # self.dataOut.ippSeconds = self.ippSeconds
318
307
319 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
308 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
320
309
321 self.dataOut.dtype = self.dtype
310 self.dataOut.dtype = self.dtype
322
311
323 # self.dataOut.nPairs = self.nPairs
312 # self.dataOut.nPairs = self.nPairs
324
313
325 self.dataOut.pairsList = self.rdPairList
314 self.dataOut.pairsList = self.rdPairList
326
315
327 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
316 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
328
317
329 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
318 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
330
319
331 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
320 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
332
321
333 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
322 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
334
323
335 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
324 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
336
325
337 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
326 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
338
327
339 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
328 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
340
329
341 self.dataOut.flagShiftFFT = True #Data is always shifted
330 self.dataOut.flagShiftFFT = True #Data is always shifted
342
331
343 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
332 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
344
333
345 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
334 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip
346
335
347 def getData(self):
336 def getData(self):
348 """
337 """
349 First method to execute before "RUN" is called.
338 First method to execute before "RUN" is called.
350
339
351 Copia el buffer de lectura a la clase "Spectra",
340 Copia el buffer de lectura a la clase "Spectra",
352 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
341 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
353 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
342 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
354
343
355 Return:
344 Return:
356 0 : Si no hay mas archivos disponibles
345 0 : Si no hay mas archivos disponibles
357 1 : Si hizo una buena copia del buffer
346 1 : Si hizo una buena copia del buffer
358
347
359 Affected:
348 Affected:
360 self.dataOut
349 self.dataOut
361
350
362 self.flagDiscontinuousBlock
351 self.flagDiscontinuousBlock
363 self.flagIsNewBlock
352 self.flagIsNewBlock
364 """
353 """
365
354
366 if self.flagNoMoreFiles:
355 if self.flagNoMoreFiles:
367 self.dataOut.flagNoData = True
356 self.dataOut.flagNoData = True
368 print 'Process finished'
357 print 'Process finished'
369 return 0
358 return 0
370
359
371 self.flagDiscontinuousBlock = 0
360 self.flagDiscontinuousBlock = 0
372 self.flagIsNewBlock = 0
361 self.flagIsNewBlock = 0
373
362
374 if self.__hasNotDataInBuffer():
363 if self.__hasNotDataInBuffer():
375
364
376 if not( self.readNextBlock() ):
365 if not( self.readNextBlock() ):
377 self.dataOut.flagNoData = True
366 self.dataOut.flagNoData = True
378 return 0
367 return 0
379
368
380
381 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
369 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
382
370
383 if self.data_spc is None:
371 if self.data_spc is None:
384 self.dataOut.flagNoData = True
372 self.dataOut.flagNoData = True
385 return 0
373 return 0
386
374
387 self.getBasicHeader()
375 self.getBasicHeader()
388
376
389 self.getFirstHeader()
377 self.getFirstHeader()
390
378
391 self.dataOut.data_spc = self.data_spc
379 self.dataOut.data_spc = self.data_spc
392
380
393 self.dataOut.data_cspc = self.data_cspc
381 self.dataOut.data_cspc = self.data_cspc
394
382
395 self.dataOut.data_dc = self.data_dc
383 self.dataOut.data_dc = self.data_dc
396
384
397 self.dataOut.flagNoData = False
385 self.dataOut.flagNoData = False
398
386
399 self.dataOut.realtime = self.online
387 self.dataOut.realtime = self.online
400
388
401 return self.dataOut.data_spc
389 return self.dataOut.data_spc
402
390
403 class SpectraWriter(JRODataWriter, Operation):
391 class SpectraWriter(JRODataWriter, Operation):
404
392
405 """
393 """
406 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
394 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
407 de los datos siempre se realiza por bloques.
395 de los datos siempre se realiza por bloques.
408 """
396 """
409
397
410 ext = ".pdata"
398 ext = ".pdata"
411
399
412 optchar = "P"
400 optchar = "P"
413
401
414 shape_spc_Buffer = None
402 shape_spc_Buffer = None
415
403
416 shape_cspc_Buffer = None
404 shape_cspc_Buffer = None
417
405
418 shape_dc_Buffer = None
406 shape_dc_Buffer = None
419
407
420 data_spc = None
408 data_spc = None
421
409
422 data_cspc = None
410 data_cspc = None
423
411
424 data_dc = None
412 data_dc = None
425
413
426 # dataOut = None
414 # dataOut = None
427
415
428 def __init__(self):
416 def __init__(self, **kwargs):
429 """
417 """
430 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
418 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
431
419
432 Affected:
420 Affected:
433
434 self.dataOut
421 self.dataOut
435 self.basicHeaderObj
422 self.basicHeaderObj
436 self.systemHeaderObj
423 self.systemHeaderObj
437 self.radarControllerHeaderObj
424 self.radarControllerHeaderObj
438 self.processingHeaderObj
425 self.processingHeaderObj
439
426
440 Return: None
427 Return: None
441 """
428 """
442
429
443 Operation.__init__(self)
430 Operation.__init__(self, **kwargs)
444
431
445 self.isConfig = False
432 self.isConfig = False
446
433
447 self.nTotalBlocks = 0
434 self.nTotalBlocks = 0
448
435
449 self.data_spc = None
436 self.data_spc = None
450
437
451 self.data_cspc = None
438 self.data_cspc = None
452
439
453
454 self.data_dc = None
440 self.data_dc = None
455
441
456 self.fp = None
442 self.fp = None
457
443
458 self.flagIsNewFile = 1
444 self.flagIsNewFile = 1
459
445
460 self.nTotalBlocks = 0
446 self.nTotalBlocks = 0
461
447
462 self.flagIsNewBlock = 0
448 self.flagIsNewBlock = 0
463
449
464 self.setFile = None
450 self.setFile = None
465
451
466 self.dtype = None
452 self.dtype = None
467
453
468 self.path = None
454 self.path = None
469
455
470 self.noMoreFiles = 0
456 self.noMoreFiles = 0
471
457
472 self.filename = None
458 self.filename = None
473
459
474 self.basicHeaderObj = BasicHeader(LOCALTIME)
460 self.basicHeaderObj = BasicHeader(LOCALTIME)
475
461
476 self.systemHeaderObj = SystemHeader()
462 self.systemHeaderObj = SystemHeader()
477
463
478 self.radarControllerHeaderObj = RadarControllerHeader()
464 self.radarControllerHeaderObj = RadarControllerHeader()
479
465
480 self.processingHeaderObj = ProcessingHeader()
466 self.processingHeaderObj = ProcessingHeader()
481
467
482
468
483 def hasAllDataInBuffer(self):
469 def hasAllDataInBuffer(self):
484 return 1
470 return 1
485
471
486
472
487
488 def setBlockDimension(self):
473 def setBlockDimension(self):
489 """
474 """
490 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
475 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
491
476
492 Affected:
477 Affected:
493 self.shape_spc_Buffer
478 self.shape_spc_Buffer
494 self.shape_cspc_Buffer
479 self.shape_cspc_Buffer
495 self.shape_dc_Buffer
480 self.shape_dc_Buffer
496
481
497 Return: None
482 Return: None
498 """
483 """
499 self.shape_spc_Buffer = (self.dataOut.nChannels,
484 self.shape_spc_Buffer = (self.dataOut.nChannels,
500 self.processingHeaderObj.nHeights,
485 self.processingHeaderObj.nHeights,
501 self.processingHeaderObj.profilesPerBlock)
486 self.processingHeaderObj.profilesPerBlock)
502
487
503 self.shape_cspc_Buffer = (self.dataOut.nPairs,
488 self.shape_cspc_Buffer = (self.dataOut.nPairs,
504 self.processingHeaderObj.nHeights,
489 self.processingHeaderObj.nHeights,
505 self.processingHeaderObj.profilesPerBlock)
490 self.processingHeaderObj.profilesPerBlock)
506
491
507 self.shape_dc_Buffer = (self.dataOut.nChannels,
492 self.shape_dc_Buffer = (self.dataOut.nChannels,
508 self.processingHeaderObj.nHeights)
493 self.processingHeaderObj.nHeights)
509
494
510
495
511 def writeBlock(self):
496 def writeBlock(self):
512 """
497 """
513 Escribe el buffer en el file designado
498 Escribe el buffer en el file designado
514
499
515
516 Affected:
500 Affected:
517 self.data_spc
501 self.data_spc
518 self.data_cspc
502 self.data_cspc
519 self.data_dc
503 self.data_dc
520 self.flagIsNewFile
504 self.flagIsNewFile
521 self.flagIsNewBlock
505 self.flagIsNewBlock
522 self.nTotalBlocks
506 self.nTotalBlocks
523 self.nWriteBlocks
507 self.nWriteBlocks
524
508
525 Return: None
509 Return: None
526 """
510 """
527
511
528 spc = numpy.transpose( self.data_spc, (0,2,1) )
512 spc = numpy.transpose( self.data_spc, (0,2,1) )
529 if not( self.processingHeaderObj.shif_fft ):
513 if not( self.processingHeaderObj.shif_fft ):
530 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
514 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
531 data = spc.reshape((-1))
515 data = spc.reshape((-1))
532 data = data.astype(self.dtype[0])
516 data = data.astype(self.dtype[0])
533 data.tofile(self.fp)
517 data.tofile(self.fp)
534
518
535 if self.data_cspc is not None:
519 if self.data_cspc is not None:
536 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
520 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
537 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
521 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
538 if not( self.processingHeaderObj.shif_fft ):
522 if not( self.processingHeaderObj.shif_fft ):
539 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
523 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
540 data['real'] = cspc.real
524 data['real'] = cspc.real
541 data['imag'] = cspc.imag
525 data['imag'] = cspc.imag
542 data = data.reshape((-1))
526 data = data.reshape((-1))
543 data.tofile(self.fp)
527 data.tofile(self.fp)
544
528
545
546 if self.data_dc is not None:
529 if self.data_dc is not None:
547 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
530 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
548 dc = self.data_dc
531 dc = self.data_dc
549 data['real'] = dc.real
532 data['real'] = dc.real
550 data['imag'] = dc.imag
533 data['imag'] = dc.imag
551 data = data.reshape((-1))
534 data = data.reshape((-1))
552 data.tofile(self.fp)
535 data.tofile(self.fp)
553
536
554 # self.data_spc.fill(0)
537 # self.data_spc.fill(0)
555 #
538 #
556 # if self.data_dc is not None:
539 # if self.data_dc is not None:
557 # self.data_dc.fill(0)
540 # self.data_dc.fill(0)
558 #
541 #
559 # if self.data_cspc is not None:
542 # if self.data_cspc is not None:
560 # self.data_cspc.fill(0)
543 # self.data_cspc.fill(0)
561
544
562
563 self.flagIsNewFile = 0
545 self.flagIsNewFile = 0
564 self.flagIsNewBlock = 1
546 self.flagIsNewBlock = 1
565 self.nTotalBlocks += 1
547 self.nTotalBlocks += 1
566 self.nWriteBlocks += 1
548 self.nWriteBlocks += 1
567 self.blockIndex += 1
549 self.blockIndex += 1
568
550
569 # print "[Writing] Block = %d04" %self.blockIndex
551 # print "[Writing] Block = %d04" %self.blockIndex
570
552
571 def putData(self):
553 def putData(self):
572 """
554 """
573 Setea un bloque de datos y luego los escribe en un file
555 Setea un bloque de datos y luego los escribe en un file
574
556
575
576 Affected:
557 Affected:
577 self.data_spc
558 self.data_spc
578 self.data_cspc
559 self.data_cspc
579 self.data_dc
560 self.data_dc
580
561
581 Return:
562 Return:
582 0 : Si no hay data o no hay mas files que puedan escribirse
563 0 : Si no hay data o no hay mas files que puedan escribirse
583 1 : Si se escribio la data de un bloque en un file
564 1 : Si se escribio la data de un bloque en un file
584 """
565 """
585
566
586 if self.dataOut.flagNoData:
567 if self.dataOut.flagNoData:
587 return 0
568 return 0
588
569
589 self.flagIsNewBlock = 0
570 self.flagIsNewBlock = 0
590
571
591 if self.dataOut.flagDiscontinuousBlock:
572 if self.dataOut.flagDiscontinuousBlock:
592 self.data_spc.fill(0)
573 self.data_spc.fill(0)
574 if self.dataOut.data_cspc is not None:
593 self.data_cspc.fill(0)
575 self.data_cspc.fill(0)
576 if self.dataOut.data_dc is not None:
594 self.data_dc.fill(0)
577 self.data_dc.fill(0)
595 self.setNextFile()
578 self.setNextFile()
596
579
597 if self.flagIsNewFile == 0:
580 if self.flagIsNewFile == 0:
598 self.setBasicHeader()
581 self.setBasicHeader()
599
582
600 self.data_spc = self.dataOut.data_spc.copy()
583 self.data_spc = self.dataOut.data_spc.copy()
601
584
602 if self.dataOut.data_cspc is not None:
585 if self.dataOut.data_cspc is not None:
603 self.data_cspc = self.dataOut.data_cspc.copy()
586 self.data_cspc = self.dataOut.data_cspc.copy()
604
587
605 if self.dataOut.data_dc is not None:
588 if self.dataOut.data_dc is not None:
606 self.data_dc = self.dataOut.data_dc.copy()
589 self.data_dc = self.dataOut.data_dc.copy()
607
590
608 # #self.processingHeaderObj.dataBlocksPerFile)
591 # #self.processingHeaderObj.dataBlocksPerFile)
609 if self.hasAllDataInBuffer():
592 if self.hasAllDataInBuffer():
610 # self.setFirstHeader()
593 # self.setFirstHeader()
611 self.writeNextBlock()
594 self.writeNextBlock()
612
595
613 return 1
596 return 1
614
597
615
616 def __getBlockSize(self):
598 def __getBlockSize(self):
617 '''
599 '''
618 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
600 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
619 '''
601 '''
620
602
621 dtype_width = self.getDtypeWidth()
603 dtype_width = self.getDtypeWidth()
622
604
623 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
605 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
624
606
625 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
607 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
626 blocksize = (pts2write_SelfSpectra*dtype_width)
608 blocksize = (pts2write_SelfSpectra*dtype_width)
627
609
628 if self.dataOut.data_cspc is not None:
610 if self.dataOut.data_cspc is not None:
629 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
611 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
630 blocksize += (pts2write_CrossSpectra*dtype_width*2)
612 blocksize += (pts2write_CrossSpectra*dtype_width*2)
631
613
632 if self.dataOut.data_dc is not None:
614 if self.dataOut.data_dc is not None:
633 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
615 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
634 blocksize += (pts2write_DCchannels*dtype_width*2)
616 blocksize += (pts2write_DCchannels*dtype_width*2)
635
617
636 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
618 # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
637
619
638 return blocksize
620 return blocksize
639
621
640 def setFirstHeader(self):
622 def setFirstHeader(self):
641
623
642 """
624 """
643 Obtiene una copia del First Header
625 Obtiene una copia del First Header
644
626
645 Affected:
627 Affected:
646 self.systemHeaderObj
628 self.systemHeaderObj
647 self.radarControllerHeaderObj
629 self.radarControllerHeaderObj
648 self.dtype
630 self.dtype
649
631
650 Return:
632 Return:
651 None
633 None
652 """
634 """
653
635
654 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
636 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
655 self.systemHeaderObj.nChannels = self.dataOut.nChannels
637 self.systemHeaderObj.nChannels = self.dataOut.nChannels
656 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
638 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
657
639
658 self.processingHeaderObj.dtype = 1 # Spectra
640 self.processingHeaderObj.dtype = 1 # Spectra
659 self.processingHeaderObj.blockSize = self.__getBlockSize()
641 self.processingHeaderObj.blockSize = self.__getBlockSize()
660 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
642 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
661 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
643 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
662 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
644 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
663 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
645 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
664 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
646 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
665 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
647 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
666 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
648 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
667
649
668
669 if self.processingHeaderObj.totalSpectra > 0:
650 if self.processingHeaderObj.totalSpectra > 0:
670 channelList = []
651 channelList = []
671 for channel in range(self.dataOut.nChannels):
652 for channel in range(self.dataOut.nChannels):
672 channelList.append(channel)
653 channelList.append(channel)
673 channelList.append(channel)
654 channelList.append(channel)
674
655
675 pairsList = []
656 pairsList = []
676 if self.dataOut.nPairs > 0:
657 if self.dataOut.nPairs > 0:
677 for pair in self.dataOut.pairsList:
658 for pair in self.dataOut.pairsList:
678 pairsList.append(pair[0])
659 pairsList.append(pair[0])
679 pairsList.append(pair[1])
660 pairsList.append(pair[1])
680
661
681 spectraComb = channelList + pairsList
662 spectraComb = channelList + pairsList
682 spectraComb = numpy.array(spectraComb, dtype="u1")
663 spectraComb = numpy.array(spectraComb, dtype="u1")
683 self.processingHeaderObj.spectraComb = spectraComb
664 self.processingHeaderObj.spectraComb = spectraComb
684
665
685 if self.dataOut.code is not None:
666 if self.dataOut.code is not None:
686 self.processingHeaderObj.code = self.dataOut.code
667 self.processingHeaderObj.code = self.dataOut.code
687 self.processingHeaderObj.nCode = self.dataOut.nCode
668 self.processingHeaderObj.nCode = self.dataOut.nCode
688 self.processingHeaderObj.nBaud = self.dataOut.nBaud
669 self.processingHeaderObj.nBaud = self.dataOut.nBaud
689
670
690 if self.processingHeaderObj.nWindows != 0:
671 if self.processingHeaderObj.nWindows != 0:
691 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
672 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
692 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
673 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
693 self.processingHeaderObj.nHeights = self.dataOut.nHeights
674 self.processingHeaderObj.nHeights = self.dataOut.nHeights
694 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
675 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
695
676
696 self.processingHeaderObj.processFlags = self.getProcessFlags()
677 self.processingHeaderObj.processFlags = self.getProcessFlags()
697
678
698 self.setBasicHeader()
679 self.setBasicHeader()
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: modified file
NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now