##// END OF EJS Templates
fixing merge conflicts
jespinoza -
r1090:36f30f86830d merge
parent child
Show More
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()
@@ -0,0 +1,15
1 Lectura
2 200samples -> 0.47m HDD 1000''
3 200samples -> 6 HDD 100ms file 100s folder
4 200samples -> 0.48ms HDD 100ms file 1000s folder
5 200samples -> 116ms HDD 5000ms file 100s folder
6 200samples -> 182 HDD 10000ms file 100s folder
7 200samples -> 143 HDD 10000ms file 100s folder SSD
8
9 Escritura
10 200samples -> 0.78m HDD 100ms file 1000s folder
11 200samples -> 0.066m HDD 100ms file 1000s folder
12 200samples -> 0.30 HDD 100ms file 100s folder
13 200samples -> 0.23 HDD 5000ms file 100s folder
14 200samples -> 0.176 HDD 10000ms file 100s folder
15
@@ -0,0 +1,117
1 #!/usr/bin/env python
2 '''
3 Created on Jul 7, 2014
4
5 @author: roj-idl71
6 '''
7 import os, sys
8
9 from schainpy.controller import Project
10
11 def main():
12
13 desc = "Testing USRP data reader"
14 filename = "schain.xml"
15 figpath = "./"
16 remotefolder = "/home/wmaster/graficos"
17
18 #this controller object save all user configuration and then execute each module
19 #with their parameters.
20 controllerObj = Project()
21
22 controllerObj.setup(id = '191', name='test01', description=desc)
23
24 #Creating a reader object with its parameters
25 #schainpy.model.io.jroIO_usrp.USRPReader.setup()
26 readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRF',
27 path='/home/nanosat/data/',
28 startDate='2000/07/03',
29 endDate='2017/07/03',
30 startTime='00:00:00',
31 endTime='23:59:59',
32 online=0)
33
34 # procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage',
35 # inputId=readUnitConfObj.getId())
36
37 # opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
38 # opObj10.addParameter(name='minHei', value='0', format='float')
39 # opObj10.addParameter(name='maxHei', value='8', format='float')
40
41 # opObj10 = procUnitConfObj0.addOperation(name='setH0')
42 # opObj10.addParameter(name='h0', value='5.4', format='float')
43
44 # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
45 # opObj10.addParameter(name='code', value='1,-1', format='intlist')
46 # opObj10.addParameter(name='nCode', value='2', format='float')
47 # opObj10.addParameter(name='nBaud', value='1', format='float')
48
49 # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
50 # opObj10.addParameter(name='n', value='128', format='float')
51
52 # opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='external')
53 # opObj11.addParameter(name='id', value='121', format='int')
54 # opObj11.addParameter(name='wintitle', value='Scope', format='str')
55
56 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra',
57 # inputId=procUnitConfObj0.getId())
58
59 # #Creating a processing object with its parameters
60 # #schainpy.model.proc.jroproc_spectra.SpectraProc.run()
61 # #If you need to add more parameters can use the "addParameter method"
62 # procUnitConfObj1.addParameter(name='nFFTPoints', value='8', format='int')
63 # procUnitConfObj1.addParameter(name='pairsList', value='(0,1)', format='pairslist')
64
65 # opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
66 # opObj10.addParameter(name='n', value='2', format='float')
67 #
68 #Using internal methods
69 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
70 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
71 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
72
73 #Using internal methods
74 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
75 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
76 # opObj10.addParameter(name='minHei', value='90', format='float')
77 # opObj10.addParameter(name='maxHei', value='180', format='float')
78
79 #Using external methods (new modules)
80 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
81 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
82 # opObj12.addParameter(name='n', value='1', format='int')
83
84 #Using external methods (new modules)
85 #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
86 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
87 # opObj11.addParameter(name='id', value='11', format='int')
88 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
89 # opObj11.addParameter(name='zmin', value='0', format='int')
90 # opObj11.addParameter(name='zmax', value='90', format='int')
91 # opObj11.addParameter(name='save', value='1', format='int')
92 # opObj11.addParameter(name='xmin', value='-20', format='float')
93 # opObj11.addParameter(name='xmax', value='20', format='float')
94
95 #Using external methods (new modules)
96 #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
97 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
98 # opObj11.addParameter(name='id', value='30', format='int')
99 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
100 # # opObj11.addParameter(name='zmin', value='0', format='int')
101 # # opObj11.addParameter(name='zmax', value='90', format='int')
102 # opObj11.addParameter(name='showprofile', value='1', format='int')
103 # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
104 # opObj11.addParameter(name='xmin', value='19.5', format='float')
105 # opObj11.addParameter(name='xmax', value='20', format='float')
106
107 # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
108 # opObj11.addParameter(name='id', value='3', format='int')
109 # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str')
110 # opObj11.addParameter(name='zmin', value='30', format='int')
111 # opObj11.addParameter(name='zmax', value='120', format='int')
112 # opObj11.addParameter(name='pairsList', value='(0,1)', format='pairslist')
113
114 controllerObj.start()
115
116 if __name__ == '__main__':
117 main()
@@ -0,0 +1,98
1 import os, sys
2
3 from schainpy.controller import Project
4
5 if __name__ == '__main__':
6
7 desc = "Segundo Test"
8 filename = "schain.xml"
9
10 controllerObj = Project()
11
12 controllerObj.setup(id = '191', name='test01', description=desc)
13
14 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
15 path='/home/nanosat/data/John',
16 startDate='2010/10/28',
17 endDate='2017/10/28',
18 startTime='00:00:00',
19 endTime='23:59:59',
20 online=0,
21 walk=0)
22
23 opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock')
24
25 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
26 inputId=readUnitConfObj.getId())
27
28 # opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='external')
29 # opObj11.addParameter(name='id', value='121', format='int')
30 # opObj11.addParameter(name='wintitle', value='Scope', format='str')
31
32 opObj10 = procUnitConfObj0.addOperation(name='DigitalRFWriter', optype='other')
33 opObj10.addParameter(name='path', value='/home/nanosat/data/digitalrf', format='str')
34 # opObj10.addParameter(name='minHei', value='0', format='float')
35 # opObj10.addParameter(name='maxHei', value='8', format='float')
36
37 # opObj10 = procUnitConfObj0.addOperation(name='filterByHeights')
38 # opObj10.addParameter(name='window', value='2', format='float')
39
40 # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
41 # opObj10.addParameter(name='code', value='1,-1', format='intlist')
42 # opObj10.addParameter(name='nCode', value='2', format='float')
43 # opObj10.addParameter(name='nBaud', value='1', format='float')
44
45
46 # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
47 # opObj10.addParameter(name='n', value='1296', format='float')
48
49 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc',
50 # inputId=procUnitConfObj0.getId())
51
52 #Creating a processing object with its parameters
53 #schainpy.model.proc.jroproc_spectra.SpectraProc.run()
54 #If you need to add more parameters can use the "addParameter method"
55 # procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int')
56
57 # opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
58 # opObj10.addParameter(name='n', value='2', format='float')
59
60 #Using internal methods
61 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
62 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
63 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
64
65 #Using internal methods
66 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
67 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
68 # opObj10.addParameter(name='minHei', value='90', format='float')
69 # opObj10.addParameter(name='maxHei', value='180', format='float')
70
71 #Using external methods (new modules)
72 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
73 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
74 # opObj12.addParameter(name='n', value='1', format='int')
75
76 #Using external methods (new modules)
77 #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
78 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
79 # opObj11.addParameter(name='id', value='11', format='int')
80 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
81 # opObj11.addParameter(name='zmin', value='-60', format='int')
82 # opObj11.addParameter(name='zmax', value='10', format='int')
83 # opObj11.addParameter(name='save', value='1', format='int')
84
85 # #Using external methods (new modules)
86 # #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
87 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
88 # opObj11.addParameter(name='id', value='30', format='int')
89 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
90 # opObj11.addParameter(name='zmin', value='-60', format='int')
91 # opObj11.addParameter(name='zmax', value='-10', format='int')
92 # opObj11.addParameter(name='showprofile', value='1', format='int')
93 # # opObj11.addParameter(name='timerange', value=str(5*60*60*60), format='int')
94 # opObj11.addParameter(name='xmin', value='14', format='float')
95 # opObj11.addParameter(name='xmax', value='23.9', format='float')
96 # opObj11.addParameter(name='save', value='1', format='int')
97
98 controllerObj.start()
@@ -0,0 +1,1
1 You should install "digital_rf_hdf5" module if you want to read USRP data
@@ -100,16 +100,16 ENV/
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
113 .vscode
114 trash
114 *.log
115 *.log
115 trash No newline at end of file
@@ -1,4 +1,4
1 # schaing
1 # schain
2
2
3 Command Line Interface for SIGNAL CHAIN - jro
3 Command Line Interface for SIGNAL CHAIN - jro
4
4
@@ -31,18 +31,17 PREFIX = 'experiment'
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':
@@ -54,6 +53,7 def main(command, nextcommand, version, xml):
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:
@@ -77,19 +77,23 def search(nextcommand):
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()
@@ -117,12 +121,18 def runschain(nextcommand):
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
@@ -132,7 +142,8 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)
@@ -1,11 +1,10
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}",
@@ -16,60 +15,76 readUnitConf = controller.addReadUnit(datatype='VoltageReader',
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 ####################
44
43 plotter = Project()
45 readUnitConf = controller.addReadUnit(datatype='SpectraReader',
44 plotter.setup(id='100', name='receiver', description=desc)
46 path="{path}",
45
47 startDate=day,
46 receiver_plot = plotter.addProcUnit(name='PlotterReceiver')
48 endDate=day,
47 receiver_plot.addParameter(name='throttle', value=20, format='int')
49 startTime="{startHour}",
48 receiver_plot.addParameter(name='plottypes', value='rti', format='str')
50 endTime="{endHour}",
49
51 online=0,
50 rti = receiver_plot.addOperation(name='PlotRTIData', optype='other')
52 queue=q,
51 rti.addParameter(name='zmin', value='-40.0', format='float')
53 cursor=cursor,
52 rti.addParameter(name='zmax', value='100.0', format='float')
54 skip=skip,
53 rti.addParameter(name='decimation', value='200', format='int')
55 verbose=1,
54 rti.addParameter(name='xmin', value='0.0', format='int')
56 walk=1,
55 rti.addParameter(name='colormap', value='jet', format='str')
57 )
56
58
57 plotter.start()
59 procUnitConf1 = controller.addProcUnit(datatype='Spectra', inputId=readUnitConf.getId())
58
60
59 sleep(2)
61 procUnitConf2 = controller.addProcUnit(datatype='ParametersProc', inputId=readUnitConf.getId())
60
62 opObj11 = procUnitConf2.addOperation(name='SpectralMoments', optype='other')
61 ################
63
62 # DATA EMITTER #
64 opObj12 = procUnitConf2.addOperation(name='PublishData', optype='other')
63 ################
65 opObj12.addParameter(name='zeromq', value=1, format='int')
64 project = Project()
66 opObj12.addParameter(name='verbose', value=0, format='bool')
65 project.setup(id='200', name="{name}", description=desc)
67
66
68 controller.start()
67 spectra_reader = project.addReadUnit(datatype='SpectraReader',
69
68 path="{path}",
70
69 startDate={startDate},
71 if __name__ == '__main__':
70 endDate={endDate},
72 multiSchain(fiber, nProcess={nProcess}, startDate="{startDate}", endDate="{endDate}")
71 startTime="{startHour}",
72 endTime="{endHour}",
73 online=0,
74 verbose=1,
75 walk=1,
76 )
77
78 spectra_proc = project.addProcUnit(datatype='Spectra', inputId=spectra_reader.getId())
79
80 parameters_proc = project.addProcUnit(datatype='ParametersProc', inputId=spectra_proc.getId())
81 moments = parameters_proc.addOperation(name='SpectralMoments', optype='other')
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')
86
87 MPProject(project, 16)
73
88
74
89
75 '''
90 '''
@@ -1,11 +1,11
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.
@@ -21,7 +21,7
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
@@ -24,6 +24,7 DTYPES = {
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
@@ -34,8 +35,8 def MPProject(project, n=cpu_count()):
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 = []
@@ -43,17 +44,17 def MPProject(project, n=cpu_count()):
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
@@ -72,6 +73,7 def MPProject(project, n=cpu_count()):
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
@@ -108,7 +110,7 class ParameterConf():
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(',')
@@ -174,16 +176,16 class ParameterConf():
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
@@ -253,13 +255,14 class ParameterConf():
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)
265
263
266
264 class OperationConf():
267 class OperationConf():
265
268
@@ -279,10 +282,9 class OperationConf():
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
@@ -291,7 +293,7 class OperationConf():
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
@@ -329,15 +331,14 class OperationConf():
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 = {}
@@ -367,7 +368,7 class OperationConf():
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()
@@ -405,8 +406,8 class OperationConf():
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
@@ -418,8 +419,8 class OperationConf():
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
@@ -429,22 +430,21 class OperationConf():
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
@@ -489,11 +489,11 class ProcUnitConf():
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
@@ -505,18 +505,17 class ProcUnitConf():
505
505
506 def updateId(self, new_id, parentId=parentId):
506 def updateId(self, new_id, parentId=parentId):
507
507
508 new_id = int(parentId) * 10 + (int(self.id) % 10)
509 new_inputId = int(parentId) * 10 + (int(self.inputId) % 10)
508
510
509 new_id = int(parentId)*10 + (int(self.id) % 10)
511 # If this proc unit has not inputs
510 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
511
512 #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
@@ -525,7 +524,6 class ProcUnitConf():
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
@@ -559,18 +557,18 class ProcUnitConf():
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
@@ -650,16 +648,15 class ProcUnitConf():
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]
@@ -675,10 +672,11 class ProcUnitConf():
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)
@@ -704,10 +702,10 class ProcUnitConf():
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
@@ -725,6 +723,7 class ProcUnitConf():
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
@@ -754,10 +753,9 class ReadUnitConf(ProcUnitConf):
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
@@ -792,15 +790,16 class ReadUnitConf(ProcUnitConf):
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',
799
797 'startTime', 'endTime', 'parentId')
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
@@ -813,21 +812,26 class ReadUnitConf(ProcUnitConf):
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
825 opObj.addParameter(
826 name='startTime', value=self.startTime, format='time')
827 opObj.addParameter(
828 name='endTime', value=self.endTime, format='time')
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
831
835
832 return opObj
836 return opObj
833
837
@@ -838,16 +842,19 class ReadUnitConf(ProcUnitConf):
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')
@@ -877,6 +884,7 class ReadUnitConf(ProcUnitConf):
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
@@ -905,7 +913,7 class Project(Process):
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
@@ -938,8 +946,8 class Project(Process):
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
@@ -949,9 +957,9 class Project(Process):
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
@@ -974,7 +982,8 class Project(Process):
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
@@ -985,7 +994,8 class Project(Process):
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
@@ -1059,11 +1069,11 class Project(Process):
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()
@@ -1074,7 +1084,7 class Project(Process):
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'
@@ -1083,7 +1093,7 class Project(Process):
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
@@ -1092,16 +1102,17 class Project(Process):
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()
@@ -1112,7 +1123,8 class Project(Process):
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()
@@ -1129,10 +1141,10 class Project(Process):
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
@@ -1154,11 +1166,11 class Project(Process):
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)
@@ -1168,11 +1180,11 class Project(Process):
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
@@ -1181,30 +1193,33 class Project(Process):
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)
1188 subtitle += 'Working directory: %s\n' %os.path.abspath('./')
1201 subtitle += 'Hostname: %s\n' % socket.gethostbyname(
1189 subtitle += 'Configuration file: %s\n' %self.filename
1202 socket.gethostname())
1190 subtitle += 'Time: %s\n' %str(datetime.datetime.now())
1203 subtitle += 'Working directory: %s\n' % os.path.abspath('./')
1204 subtitle += 'Configuration file: %s\n' % self.filename
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
@@ -1255,7 +1270,7 class Project(Process):
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
@@ -1287,14 +1302,14 class Project(Process):
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()
@@ -50,7 +50,6 class ProjectParms():
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):
@@ -65,7 +64,6 class ProjectParms():
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,
@@ -5,8 +5,8
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 * No newline at end of file
@@ -292,11 +292,9 class JROData(GenericData):
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):
@@ -7,6 +7,7 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
@@ -82,7 +83,25 class Header(object):
82 def write(self):
83 def write(self):
83
84
84 raise NotImplementedError
85 raise NotImplementedError
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
85
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"
@@ -115,6 +134,7 class BasicHeader(Header):
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):
@@ -189,16 +209,17 class SystemHeader(Header):
189 nChannels = None
209 nChannels = None
190 adcResolution = None
210 adcResolution = None
191 pciDioBusWidth = None
211 pciDioBusWidth = None
192
212 structure = SYSTEM_STRUCTURE
193 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
213
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:
@@ -260,15 +281,15 class RadarControllerHeader(Header):
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,
@@ -278,10 +299,10 class RadarControllerHeader(Header):
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
@@ -292,7 +313,7 class RadarControllerHeader(Header):
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
@@ -342,7 +363,7 class RadarControllerHeader(Header):
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]
@@ -450,7 +471,7 class RadarControllerHeader(Header):
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)
@@ -540,15 +561,18 class ProcessingHeader(Header):
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
@@ -572,6 +596,7 class ProcessingHeader(Header):
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:
@@ -8,78 +8,78 from figure import Figure, isRealtime
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 :
@@ -93,15 +93,15 class CorrelationPlot(Figure):
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:
@@ -110,53 +110,53 class CorrelationPlot(Figure):
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)
@@ -165,7 +165,7 class CorrelationPlot(Figure):
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,
@@ -173,15 +173,15 class CorrelationPlot(Figure):
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)
@@ -16,8 +16,10 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')]
@@ -52,7 +54,7 class PlotData(Operation, Process):
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 = []
@@ -72,13 +74,13 class PlotData(Operation, Process):
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)
@@ -115,18 +117,18 class PlotData(Operation, Process):
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
@@ -134,15 +136,15 class PlotData(Operation, Process):
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
@@ -152,12 +154,12 class PlotData(Operation, Process):
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.)
@@ -269,7 +271,7 class PlotData(Operation, Process):
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()
@@ -278,7 +280,7 class PlotData(Operation, Process):
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)
@@ -298,26 +300,26 class PlotData(Operation, Process):
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):
@@ -337,7 +339,7 class PlotData(Operation, Process):
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)
@@ -354,7 +356,9 class PlotData(Operation, Process):
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
357 for n, ax in enumerate(self.axes):
359 ystep = 200 if ymax >= 800 else 100 if ymax >= 400 else 50 if ymax >= 200 else 20
360
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))
@@ -363,14 +367,15 class PlotData(Operation, Process):
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)
@@ -379,7 +384,7 class PlotData(Operation, Process):
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'),
@@ -392,10 +397,10 class PlotData(Operation, Process):
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)
@@ -405,7 +410,7 class PlotData(Operation, Process):
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:
@@ -438,9 +443,10 class PlotData(Operation, Process):
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:
@@ -460,7 +466,7 class PlotData(Operation, Process):
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:
@@ -474,23 +480,24 class PlotData(Operation, Process):
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
@@ -514,7 +521,7 class PlotSpectraData(PlotData):
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':
@@ -525,15 +532,16 class PlotSpectraData(PlotData):
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:
@@ -554,17 +562,17 class PlotCrossSpectraData(PlotData):
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
@@ -588,24 +596,24 class PlotCrossSpectraData(PlotData):
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,
@@ -615,12 +623,12 class PlotCrossSpectraData(PlotData):
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,
@@ -628,9 +636,10 class PlotCrossSpectraData(PlotData):
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,
@@ -640,7 +649,7 class PlotCrossSpectraData(PlotData):
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
@@ -662,12 +671,13 class PlotRTIData(PlotData):
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
@@ -676,17 +686,18 class PlotRTIData(PlotData):
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:
@@ -695,12 +706,13 class PlotRTIData(PlotData):
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):
@@ -715,13 +727,15 class PlotCOHData(PlotRTIData):
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):
@@ -753,9 +767,9 class PlotNoiseData(PlotData):
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]
@@ -765,7 +779,7 class PlotNoiseData(PlotData):
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
@@ -813,26 +827,27 class PlotSkyMapData(PlotData):
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(
823 error = arrayParameters[:,-1]
837 [self.data['param'][t] for t in self.times])
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
@@ -847,9 +862,9 class PlotSkyMapData(PlotData):
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
@@ -866,7 +881,7 class PlotParamData(PlotRTIData):
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)]
@@ -874,10 +889,10 class PlotParamData(PlotRTIData):
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 )
@@ -900,7 +915,7 class PlotParamData(PlotRTIData):
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]
@@ -909,7 +924,7 class PlotParamData(PlotRTIData):
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
@@ -11,79 +11,80 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 :
@@ -94,12 +95,12 class SpectraHeisScope(Figure):
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:
@@ -108,9 +109,9 class SpectraHeisScope(Figure):
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))
@@ -122,7 +123,7 class SpectraHeisScope(Figure):
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"))
@@ -130,29 +131,29 class SpectraHeisScope(Figure):
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"))
@@ -161,10 +162,10 class SpectraHeisScope(Figure):
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,
@@ -173,18 +174,18 class SpectraHeisScope(Figure):
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
@@ -193,43 +194,43 class RTIfromSpectraHeis(Figure):
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
@@ -239,86 +240,86 class RTIfromSpectraHeis(Figure):
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,
@@ -25,8 +25,8 class SpectraPlot(Figure):
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
@@ -113,7 +113,7 class Scope(Figure):
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
@@ -4,32 +4,36 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
28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
30
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()
@@ -39,10 +43,11 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80
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()
@@ -60,47 +65,52 def closeFigure(show=False, fig=None):
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
91 axes.grid(True)
92
100
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)
113
104
114
105 def printLabels(ax, xlabel, ylabel, title):
115 def printLabels(ax, xlabel, ylabel, title):
106
116
@@ -108,11 +118,11 def printLabels(ax, xlabel, ylabel, title):
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:
@@ -121,18 +131,19 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title=''
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
@@ -170,26 +181,29 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title=''
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)
188
176
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()
@@ -199,16 +213,16 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
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():
@@ -237,36 +251,30 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
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
@@ -275,19 +283,17 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', col
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
279 cmap=matplotlib.pyplot.get_cmap(colormap)
280 cmap.set_bad('white',1.)
281
286
282 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
287 cmap = matplotlib.pyplot.get_cmap(colormap)
283 ax.grid(True)
288 cmap.set_bad('black', 1.)
284
289
290 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
285
291
286 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
287 ticksize=9, xtick_visible=True, ytick_visible=True,
288 nxticks=4, nyticks=10,
289 grid=None):
290
292
293 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
294 ticksize=9, xtick_visible=True, ytick_visible=True,
295 nxticks=4, nyticks=10,
296 grid=None):
291 """
297 """
292
298
293 Input:
299 Input:
@@ -299,11 +305,12 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', tit
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():
@@ -340,19 +347,19 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', tit
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
351 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
352 ticksize=9, xtick_visible=True, ytick_visible=True,
353 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
354 grid=None, XAxisAsTime=False):
355
358
359 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
360 ticksize=9, xtick_visible=True, ytick_visible=True,
361 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
362 grid=None, XAxisAsTime=False):
356 """
363 """
357
364
358 Input:
365 Input:
@@ -369,10 +376,11 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel=''
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)
@@ -407,7 +415,8 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel=''
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
@@ -415,30 +424,33 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel=''
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, :])
437
426
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
@@ -457,18 +469,19 def createPolar(ax, x, y,
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':
@@ -476,6 +489,7 def draw(fig):
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,4 +1,5
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
@@ -6,11 +7,9 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
@@ -31,113 +30,130 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
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(
35
34 '/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc', "rb")
36
35
37 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
36
38 ('Hname',numpy.str_,32), #Original file name
37 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
39 ('Htime',numpy.str_,32), #Date and time when the file was created
38 ('Hname', numpy.str_, 32), # Original file name
40 ('Hoper',numpy.str_,64), #Name of operator who created the file
39 # Date and time when the file was created
41 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
40 ('Htime', numpy.str_, 32),
42 ('Hdescr',numpy.str_,256), #Description of measurements
41 # Name of operator who created the file
43 ('Hdummy',numpy.str_,512), #Reserved space
42 ('Hoper', numpy.str_, 64),
44 #Main chunk
43 # Place where the measurements was carried out
45 ('Msign','<i4'), #Main chunk signature FZKF or NUIG
44 ('Hplace', numpy.str_, 128),
46 ('MsizeData','<i4'), #Size of data block main chunk
45 # Description of measurements
47 #Processing DSP parameters
46 ('Hdescr', numpy.str_, 256),
48 ('PPARsign','<i4'), #PPAR signature
47 ('Hdummy', numpy.str_, 512), # Reserved space
49 ('PPARsize','<i4'), #PPAR size of block
48 # Main chunk
50 ('PPARprf','<i4'), #Pulse repetition frequency
49 ('Msign', '<i4'), # Main chunk signature FZKF or NUIG
51 ('PPARpdr','<i4'), #Pulse duration
50 ('MsizeData', '<i4'), # Size of data block main chunk
52 ('PPARsft','<i4'), #FFT length
51 # Processing DSP parameters
53 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
52 ('PPARsign', '<i4'), # PPAR signature
54 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
53 ('PPARsize', '<i4'), # PPAR size of block
55 ('PPARchg','<i4'), #Count for gates for moment estimation
54 ('PPARprf', '<i4'), # Pulse repetition frequency
56 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
55 ('PPARpdr', '<i4'), # Pulse duration
57 #Service DSP parameters
56 ('PPARsft', '<i4'), # FFT length
58 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
57 # Number of spectral (in-coherent) averages
59 ('SPARtx','<i4'), #OBSOLETE
58 ('PPARavc', '<i4'),
60 ('SPARaddGain0','<f4'), #OBSOLETE
59 # Number of lowest range gate for moment estimation
61 ('SPARaddGain1','<f4'), #OBSOLETE
60 ('PPARihp', '<i4'),
62 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
61 # Count for gates for moment estimation
63 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
62 ('PPARchg', '<i4'),
64 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
63 # switch on/off polarimetric measurements. Should be 1.
65 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
64 ('PPARpol', '<i4'),
66 ('SPARcal','<i4'), #OBSOLETE
65 # Service DSP parameters
67 ('SPARnos','<i4'), #OBSOLETE
66 # STC attenuation on the lowest ranges on/off
68 ('SPARof0','<i4'), #detection threshold
67 ('SPARatt', '<i4'),
69 ('SPARof1','<i4'), #OBSOLETE
68 ('SPARtx', '<i4'), # OBSOLETE
70 ('SPARswt','<i4'), #2nd moment estimation threshold
69 ('SPARaddGain0', '<f4'), # OBSOLETE
71 ('SPARsum','<i4'), #OBSOLETE
70 ('SPARaddGain1', '<f4'), # OBSOLETE
72 ('SPARosc','<i4'), #flag Oscillosgram mode
71 # Debug only. It normal mode it is 0.
73 ('SPARtst','<i4'), #OBSOLETE
72 ('SPARwnd', '<i4'),
74 ('SPARcor','<i4'), #OBSOLETE
73 # Delay between sync pulse and tx pulse for phase corr, ns
75 ('SPARofs','<i4'), #OBSOLETE
74 ('SPARpos', '<i4'),
76 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
75 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
77 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
76 ('SPARadd', '<i4'),
78 ('SPARcalibPow_M','<f4'), #OBSOLETE
77 # Time for measuring txn pulse phase. OBSOLETE
79 ('SPARcalibSNR_M','<f4'), #OBSOLETE
78 ('SPARlen', '<i4'),
80 ('SPARcalibPow_S','<f4'), #OBSOLETE
79 ('SPARcal', '<i4'), # OBSOLETE
81 ('SPARcalibSNR_S','<f4'), #OBSOLETE
80 ('SPARnos', '<i4'), # OBSOLETE
82 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
81 ('SPARof0', '<i4'), # detection threshold
83 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
82 ('SPARof1', '<i4'), # OBSOLETE
84 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
83 ('SPARswt', '<i4'), # 2nd moment estimation threshold
85 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
84 ('SPARsum', '<i4'), # OBSOLETE
86
85 ('SPARosc', '<i4'), # flag Oscillosgram mode
87
86 ('SPARtst', '<i4'), # OBSOLETE
88
87 ('SPARcor', '<i4'), # OBSOLETE
89 self.Hname= None
88 ('SPARofs', '<i4'), # OBSOLETE
90 self.Htime= None
89 # Hildebrand div noise detection on noise gate
91 self.Hoper= None
90 ('SPARhsn', '<i4'),
92 self.Hplace= None
91 # Hildebrand div noise detection on all gates
93 self.Hdescr= None
92 ('SPARhsa', '<f4'),
94 self.Hdummy= None
93 ('SPARcalibPow_M', '<f4'), # OBSOLETE
95
94 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
96 self.Msign=None
95 ('SPARcalibPow_S', '<f4'), # OBSOLETE
97 self.MsizeData=None
96 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
98
97 # Lowest range gate for spectra saving Raw_Gate1 >=5
99 self.PPARsign=None
98 ('SPARrawGate1', '<i4'),
100 self.PPARsize=None
99 # Number of range gates with atmospheric signal
101 self.PPARprf=None
100 ('SPARrawGate2', '<i4'),
102 self.PPARpdr=None
101 # flag - IQ or spectra saving on/off
103 self.PPARsft=None
102 ('SPARraw', '<i4'),
104 self.PPARavc=None
103 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
105 self.PPARihp=None
104
106 self.PPARchg=None
105
107 self.PPARpol=None
106 self.Hname = None
108 #Service DSP parameters
107 self.Htime = None
109 self.SPARatt=None
108 self.Hoper = None
110 self.SPARtx=None
109 self.Hplace = None
111 self.SPARaddGain0=None
110 self.Hdescr = None
112 self.SPARaddGain1=None
111 self.Hdummy = None
113 self.SPARwnd=None
112
114 self.SPARpos=None
113 self.Msign = None
115 self.SPARadd=None
114 self.MsizeData = None
116 self.SPARlen=None
115
117 self.SPARcal=None
116 self.PPARsign = None
118 self.SPARnos=None
117 self.PPARsize = None
119 self.SPARof0=None
118 self.PPARprf = None
120 self.SPARof1=None
119 self.PPARpdr = None
121 self.SPARswt=None
120 self.PPARsft = None
122 self.SPARsum=None
121 self.PPARavc = None
123 self.SPARosc=None
122 self.PPARihp = None
124 self.SPARtst=None
123 self.PPARchg = None
125 self.SPARcor=None
124 self.PPARpol = None
126 self.SPARofs=None
125 # Service DSP parameters
127 self.SPARhsn=None
126 self.SPARatt = None
128 self.SPARhsa=None
127 self.SPARtx = None
129 self.SPARcalibPow_M=None
128 self.SPARaddGain0 = None
130 self.SPARcalibSNR_M=None
129 self.SPARaddGain1 = None
131 self.SPARcalibPow_S=None
130 self.SPARwnd = None
132 self.SPARcalibSNR_S=None
131 self.SPARpos = None
133 self.SPARrawGate1=None
132 self.SPARadd = None
134 self.SPARrawGate2=None
133 self.SPARlen = None
135 self.SPARraw=None
134 self.SPARcal = None
136 self.SPARprc=None
135 self.SPARnos = None
137
136 self.SPARof0 = None
138
137 self.SPARof1 = None
139
138 self.SPARswt = None
140 header = numpy.fromfile(fp, FILE_HEADER,1)
139 self.SPARsum = None
140 self.SPARosc = None
141 self.SPARtst = None
142 self.SPARcor = None
143 self.SPARofs = None
144 self.SPARhsn = None
145 self.SPARhsa = None
146 self.SPARcalibPow_M = None
147 self.SPARcalibSNR_M = None
148 self.SPARcalibPow_S = None
149 self.SPARcalibSNR_S = None
150 self.SPARrawGate1 = None
151 self.SPARrawGate2 = None
152 self.SPARraw = None
153 self.SPARprc = None
154
155
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.
@@ -157,95 +173,93 header = numpy.fromfile(fp, FILE_HEADER,1)
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
226 SRVI_STRUCTURE = numpy.dtype([
211 SRVI_STRUCTURE = numpy.dtype([
227 ('frame_cnt', '<u4'),
212 ('frame_cnt','<u4'),#
228 ('time_t', '<u4'), #
213 ('time_t','<u4'), #
229 ('tpow', '<f4'), #
214 ('tpow','<f4'), #
230 ('npw1', '<f4'), #
215 ('npw1','<f4'), #
231 ('npw2', '<f4'), #
216 ('npw2','<f4'), #
232 ('cpw1', '<f4'), #
217 ('cpw1','<f4'), #
233 ('pcw2', '<f4'), #
218 ('pcw2','<f4'), #
234 ('ps_err', '<u4'), #
219 ('ps_err','<u4'), #
235 ('te_err', '<u4'), #
220 ('te_err','<u4'), #
236 ('rc_err', '<u4'), #
221 ('rc_err','<u4'), #
237 ('grs1', '<u4'), #
222 ('grs1','<u4'), #
238 ('grs2', '<u4'), #
223 ('grs2','<u4'), #
239 ('azipos', '<f4'), #
224 ('azipos','<f4'), #
240 ('azivel', '<f4'), #
225 ('azivel','<f4'), #
241 ('elvpos', '<f4'), #
226 ('elvpos','<f4'), #
242 ('elvvel', '<f4'), #
227 ('elvvel','<f4'), #
243 ('northAngle', '<f4'),
228 ('northAngle','<f4'), #
244 ('microsec', '<u4'), #
229 ('microsec','<u4'), #
245 ('azisetvel', '<f4'), #
230 ('azisetvel','<f4'), #
246 ('elvsetpos', '<f4'), #
231 ('elvsetpos','<f4'), #
247 ('RadarConst', '<f4'), ]) #
232 ('RadarConst','<f4'),]) #
248
233
249 JUMP_STRUCTURE = numpy.dtype([
234 JUMP_STRUCTURE = numpy.dtype([
250 ('jump', '<u140'),
235 ('jump','<u140'),#
251 ('SizeOfDataBlock1', numpy.str_, 32),
236 ('SizeOfDataBlock1',numpy.str_,32),#
252 ('jump', '<i4'),
237 ('jump','<i4'),#
253 ('DataBlockTitleSRVI1', numpy.str_, 32),
238 ('DataBlockTitleSRVI1',numpy.str_,32),#
254 ('SizeOfSRVI1', '<i4'), ])
239 ('SizeOfSRVI1','<i4'),])#
255
240
256
241
257 # frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
242
258 # cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
243 #frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
259 # grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
244 #cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
260 # microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
245 #grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
261
246 #microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0
262
247
248
249 frame_cnt = frame_cnt
263 frame_cnt = frame_cnt
250 dwell = time_t
264 dwell = time_t
251 tpow = tpow
265 tpow = tpow
@@ -267,23 +281,22 microsec = microsec
267 azisetvel = azisetvel
281 azisetvel = azisetvel
268 elvsetpos = elvsetpos
282 elvsetpos = elvsetpos
269 RadarConst5 = RadarConst
283 RadarConst5 = RadarConst
270
271
284
272
285
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] #
@@ -303,19 +316,16 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
@@ -8,7 +8,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 *
@@ -83,6 +83,7 DATA_STRUCTURE = numpy.dtype([
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
@@ -92,14 +93,14 class BLTRParamReader(JRODataReader, ProcessingUnit):
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,
@@ -122,7 +123,7 class BLTRParamReader(JRODataReader, ProcessingUnit):
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)
@@ -130,50 +131,50 class BLTRParamReader(JRODataReader, ProcessingUnit):
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
149 '''
148 '''
150
149
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
@@ -192,14 +193,15 class BLTRParamReader(JRODataReader, ProcessingUnit):
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
@@ -238,7 +240,7 class BLTRParamReader(JRODataReader, ProcessingUnit):
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]
@@ -249,7 +251,7 class BLTRParamReader(JRODataReader, ProcessingUnit):
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]
@@ -263,7 +265,7 class BLTRParamReader(JRODataReader, ProcessingUnit):
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)),
@@ -277,7 +279,7 class BLTRParamReader(JRODataReader, ProcessingUnit):
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]
@@ -308,22 +310,23 class BLTRParamReader(JRODataReader, ProcessingUnit):
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
@@ -333,7 +336,7 class BLTRParamReader(JRODataReader, ProcessingUnit):
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
@@ -357,7 +360,7 class BLTRParamReader(JRODataReader, ProcessingUnit):
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
This diff has been collapsed as it changes many lines, (535 lines changed) Show them Hide them
@@ -10,7 +10,8 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
@@ -24,6 +25,7 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, ge
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.
@@ -38,11 +40,12 def isNumber(cad):
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.
@@ -67,16 +70,16 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
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)):
@@ -84,19 +87,18 def isFileInEpoch(filename, startUTSeconds, endUTSeconds):
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.
@@ -122,11 +124,10 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
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)
@@ -139,7 +140,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
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):
@@ -153,10 +154,10 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
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)
@@ -172,7 +173,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
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
@@ -183,8 +184,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
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-----------
@@ -201,6 +201,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
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.
@@ -227,7 +228,7 def isFolderInDateRange(folder, startDate=None, endDate=None):
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:
@@ -241,6 +242,7 def isFolderInDateRange(folder, startDate=None, endDate=None):
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.
@@ -269,7 +271,7 def isFileInDateRange(filename, startDate=None, endDate=None):
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:
@@ -283,6 +285,7 def isFileInDateRange(filename, startDate=None, endDate=None):
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)
@@ -293,7 +296,7 def getFileFromSet(path, ext, set):
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
@@ -302,21 +305,23 def getFileFromSet(path, ext, set):
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"
@@ -354,11 +359,12 def getlastFileFromPath(path, ext):
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,
@@ -386,28 +392,32 def checkForRealPath(path, foldercounter, year, doy, set, ext):
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" % (
406 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
413 prefixDir, year, doy, foldercounter))
407 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
414 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
408 fullfilename = os.path.join( thispath, filename ) #formo el path completo
415 # formo el nombre del file xYYYYDDDSSS.ext
409
416 filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext)
410 if os.path.exists( fullfilename ): #verifico que exista
417 fullfilename = os.path.join(
418 thispath, filename) # formo el path completo
419
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:
@@ -418,6 +428,7 def checkForRealPath(path, foldercounter, year, doy, set, ext):
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])
@@ -427,15 +438,17 def isRadarFolder(folder):
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
449
450 return 1
437
451
438 return 1
439
452
440 def getDateFromRadarFile(file):
453 def getDateFromRadarFile(file):
441 try:
454 try:
@@ -445,9 +458,10 def getDateFromRadarFile(file):
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])
@@ -455,9 +469,10 def getDateFromRadarFolder(folder):
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
@@ -540,6 +555,7 class JRODataIO:
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
@@ -548,11 +564,11 class JRODataReader(JRODataIO):
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
@@ -572,14 +588,13 class JRODataReader(JRODataIO):
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
@@ -590,7 +605,6 class JRODataReader(JRODataIO):
590 """
605 """
591 pass
606 pass
592
607
593
594 def createObjByDefault(self):
608 def createObjByDefault(self):
595 """
609 """
596
610
@@ -605,8 +619,8 class JRODataReader(JRODataIO):
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',
@@ -619,22 +633,23 class JRODataReader(JRODataIO):
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 = []
@@ -644,19 +659,21 class JRODataReader(JRODataIO):
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
@@ -665,10 +682,10 class JRODataReader(JRODataIO):
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)):
@@ -679,8 +696,7 class JRODataReader(JRODataIO):
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.
@@ -712,9 +728,9 class JRODataReader(JRODataIO):
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
@@ -724,14 +740,14 class JRODataReader(JRODataIO):
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
750 print "[Reading] %s folder was found: " % (fullpath)
734 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)
@@ -741,14 +757,14 class JRODataReader(JRODataIO):
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
@@ -769,7 +785,7 class JRODataReader(JRODataIO):
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
@@ -813,29 +829,32 class JRODataReader(JRODataIO):
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
@@ -849,16 +868,18 class JRODataReader(JRODataIO):
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
@@ -908,48 +929,47 class JRODataReader(JRODataIO):
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
931
951
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
@@ -961,7 +981,7 class JRODataReader(JRODataIO):
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:
@@ -971,7 +991,7 class JRODataReader(JRODataIO):
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)
@@ -987,12 +1007,12 class JRODataReader(JRODataIO):
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
@@ -1003,8 +1023,8 class JRODataReader(JRODataIO):
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):
@@ -1018,11 +1038,11 class JRODataReader(JRODataIO):
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
@@ -1034,29 +1054,27 class JRODataReader(JRODataIO):
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):
1067 print "[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
1048
1068 self.processingHeaderObj.dataBlocksPerFile,
1049 print "[Reading] Block No. %d/%d -> %s [Skipping]" %(self.nReadBlocks,
1069 self.dataOut.datatime.ctime())
1050 self.processingHeaderObj.dataBlocksPerFile,
1051 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):
@@ -1068,27 +1086,30 class JRODataReader(JRODataIO):
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 + \
1090 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1109 self.firstHeaderSize + self.basicHeaderSize * \
1091 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1110 (self.processingHeaderObj.dataBlocksPerFile - 1)
1111 # self.dataOut.channelList = 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):
@@ -1113,25 +1134,25 class JRODataReader(JRODataIO):
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
@@ -1161,7 +1182,7 class JRODataReader(JRODataIO):
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
@@ -1199,7 +1220,7 class JRODataReader(JRODataIO):
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):
@@ -1218,7 +1239,7 class JRODataReader(JRODataIO):
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
@@ -1238,10 +1259,10 class JRODataReader(JRODataIO):
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
@@ -1249,31 +1270,31 class JRODataReader(JRODataIO):
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
@@ -1285,7 +1306,7 class JRODataReader(JRODataIO):
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"
@@ -1296,32 +1317,33 class JRODataReader(JRODataIO):
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
@@ -1345,8 +1367,9 class JRODataReader(JRODataIO):
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
1349 #Added-----------------
1371 self.startDate = startDate
1372 # Added-----------------
1350 self.selBlocksize = blocksize
1373 self.selBlocksize = blocksize
1351 self.selBlocktime = blocktime
1374 self.selBlocktime = blocktime
1352
1375
@@ -1355,10 +1378,10 class JRODataReader(JRODataIO):
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
@@ -1370,12 +1393,14 class JRODataReader(JRODataIO):
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
@@ -1387,11 +1412,10 class JRODataReader(JRODataIO):
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
@@ -1414,11 +1438,11 class JRODataReader(JRODataIO):
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!'
@@ -1441,31 +1465,31 class JRODataReader(JRODataIO):
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,
@@ -1496,9 +1520,10 class JRODataReader(JRODataIO):
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 """
@@ -1523,23 +1548,18 class JRODataWriter(JRODataIO):
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
@@ -1575,12 +1595,12 class JRODataWriter(JRODataIO):
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
@@ -1618,7 +1638,8 class JRODataWriter(JRODataIO):
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)
@@ -1644,12 +1665,11 class JRODataWriter(JRODataIO):
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
@@ -1658,13 +1678,13 class JRODataWriter(JRODataIO):
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
@@ -1689,46 +1709,48 class JRODataWriter(JRODataIO):
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
@@ -1738,7 +1760,7 class JRODataWriter(JRODataIO):
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
@@ -1783,7 +1805,7 class JRODataWriter(JRODataIO):
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:
@@ -1801,7 +1823,8 class JRODataWriter(JRODataIO):
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()
This diff has been collapsed as it changes many lines, (1270 lines changed) Show them Hide them
@@ -1,4 +1,5
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
@@ -6,7 +7,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
@@ -33,73 +33,71 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
64 if attr:
65 message += "%s = %s" %("size", attr) + "\n"
66
67 #print message
68
62
63 if attr:
64 message += "%s = %s" % ("size", attr) + "\n"
69
65
66 # print message
70
67
71
68
69 FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes
70 ('FileMgcNumber', '<u4'), # 0x23020100
71 # No Of FDT data records in this file (0 or more)
72 ('nFDTdataRecors', '<u4'),
73 ('OffsetStartHeader', '<u4'),
74 ('RadarUnitId', '<u4'),
75 ('SiteName', numpy.str_, 32), # Null terminated
76 ])
72
77
73 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
74 ('FileMgcNumber','<u4'), #0x23020100
75 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
76 ('OffsetStartHeader','<u4'),
77 ('RadarUnitId','<u4'),
78 ('SiteName',numpy.str_,32), #Null terminated
79 ])
80
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)
87 self.RadarUnitId= 0
85 self.nFDTdataRecors = 0
88 self.OffsetStartHeader=0
86 self.RadarUnitId = 0
89 self.SiteName= ""
87 self.OffsetStartHeader = 0
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.
@@ -119,32 +117,28 class FileHeaderBLTR(Header):
119
117
120 '''
118 '''
121
119
120 self.FileMgcNumber = hex(header['FileMgcNumber'][0])
121 # No Of FDT data records in this file (0 or more)
122 self.nFDTdataRecors = int(header['nFDTdataRecors'][0])
123 self.RadarUnitId = int(header['RadarUnitId'][0])
124 self.OffsetStartHeader = int(header['OffsetStartHeader'][0])
125 self.SiteName = str(header['SiteName'][0])
126
127 # print 'Numero de bloques', self.nFDTdataRecors
122
128
123
129 if self.size < 48:
124 self.FileMgcNumber= hex(header['FileMgcNumber'][0])
125 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
126 self.RadarUnitId= int(header['RadarUnitId'][0])
127 self.OffsetStartHeader= int(header['OffsetStartHeader'][0])
128 self.SiteName= str(header['SiteName'][0])
129
130 #print 'Numero de bloques', self.nFDTdataRecors
131
132
133 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)
@@ -162,272 +156,308 class FileHeaderBLTR(Header):
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
166 return 1
167
159
160 return 1
168
161
169
162
163 RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes
164 ('RecMgcNumber', '<u4'), # 0x23030001
165 ('RecCounter', '<u4'), # Record counter(0,1, ...)
166 # Offset to start of next record form start of this record
167 ('Off2StartNxtRec', '<u4'),
168 # Offset to start of data from start of this record
169 ('Off2StartData', '<u4'),
170 # Epoch time stamp of start of acquisition (seconds)
171 ('nUtime', '<i4'),
172 # Millisecond component of time stamp (0,...,999)
173 ('nMilisec', '<u4'),
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)
185 ('ReceiveFrec', '<u4'), # Receive frequency
186 # First local oscillator frequency (Hz)
187 ('FirstOsciFrec', '<u4'),
188 # (0="O", 1="E", 2="linear 1", 3="linear2")
189 ('Polarisation', '<u4'),
190 # Receiver filter settings (0,1,2,3)
191 ('ReceiverFiltSett', '<u4'),
192 # Number of modes in use (1 or 2)
193 ('nModesInUse', '<u4'),
194 # Dual Mode index number for these data (0 or 1)
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'),
206 ('PRFhz', '<u4'), # PRF (Hz)
207 ('nCohInt', '<u4'), # Integrations
208 # Number of data points transformed
209 ('nProfiles', '<u4'),
210 # Number of receive beams stored in file (1 or N)
211 ('nChannels', '<u4'),
212 ('nIncohInt', '<u4'), # Number of spectral averages
213 # FFT windowing index (0 = no window)
214 ('FFTwindowingInd', '<u4'),
215 # Beam steer angle (azimuth) in degrees (clockwise from true North)
216 ('BeamAngleAzim', '<f4'),
217 # Beam steer angle (zenith) in degrees (0=> vertical)
218 ('BeamAngleZen', '<f4'),
219 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
220 ('AntennaCoord0', '<f4'),
221 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
222 ('AntennaAngl0', '<f4'),
223 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
224 ('AntennaCoord1', '<f4'),
225 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
226 ('AntennaAngl1', '<f4'),
227 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
228 ('AntennaCoord2', '<f4'),
229 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
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'),
249 ])
170
250
171
251
172 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
252 class RecordHeaderBLTR(Header):
173 ('RecMgcNumber','<u4'), #0x23030001
174 ('RecCounter','<u4'), #Record counter(0,1, ...)
175 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
176 ('Off2StartData','<u4'), #Offset to start of data from start of this record
177 ('nUtime','<i4'), #Epoch time stamp of start of acquisition (seconds)
178 ('nMilisec','<u4'), #Millisecond component of time stamp (0,...,999)
179 ('ExpTagName',numpy.str_,32), #Experiment tag name (null terminated)
180 ('ExpComment',numpy.str_,32), #Experiment comment (null terminated)
181 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
182 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
183 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
184 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
185 ('ReceiveFrec','<u4'), #Receive frequency
186 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
187 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
188 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
189 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
190 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
191 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
192 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
193 ('SampResolution','<u4'), #Sampling resolution (meters)
194 ('nHeights','<u4'), #Number of range gates sampled
195 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
196 ('PRFhz','<u4'), #PRF (Hz)
197 ('nCohInt','<u4'), #Integrations
198 ('nProfiles','<u4'), #Number of data points transformed
199 ('nChannels','<u4'), #Number of receive beams stored in file (1 or N)
200 ('nIncohInt','<u4'), #Number of spectral averages
201 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
202 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
203 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
204 ('AntennaCoord0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
205 ('AntennaAngl0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
206 ('AntennaCoord1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
207 ('AntennaAngl1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
208 ('AntennaCoord2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
209 ('AntennaAngl2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
210 ('RecPhaseCalibr0','<f4'), #Receiver phase calibration (degrees) - N values
211 ('RecPhaseCalibr1','<f4'), #Receiver phase calibration (degrees) - N values
212 ('RecPhaseCalibr2','<f4'), #Receiver phase calibration (degrees) - N values
213 ('RecAmpCalibr0','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
214 ('RecAmpCalibr1','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
215 ('RecAmpCalibr2','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
216 ('ReceiverGaindB0','<i4'), #Receiver gains in dB - N values
217 ('ReceiverGaindB1','<i4'), #Receiver gains in dB - N values
218 ('ReceiverGaindB2','<i4'), #Receiver gains in dB - N values
219 ])
220
253
254 def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248,
255 nUtime=0, nMilisec=0, ExpTagName=None,
256 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0,
257 RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0,
258 FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0,
259 nModesInUse=0, DualModeIndex=0, DualModeRange=0,
260 nDigChannels=0, SampResolution=0, nHeights=0,
261 StartRangeSamp=0, PRFhz=0, nCohInt=0,
262 nProfiles=0, nChannels=0, nIncohInt=0,
263 FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0,
264 AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0,
265 RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0,
266 RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0,
267 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
268 ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0):
221
269
222 class RecordHeaderBLTR(Header):
270 self.RecMgcNumber = RecMgcNumber # 0x23030001
223
271 self.RecCounter = RecCounter
224 def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 811248,
272 self.Off2StartNxtRec = Off2StartNxtRec
225 nUtime= 0, nMilisec= 0, ExpTagName= None,
226 ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0,
227 RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0,
228 FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0,
229 nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0,
230 nDigChannels= 0, SampResolution= 0, nHeights= 0,
231 StartRangeSamp= 0, PRFhz= 0, nCohInt= 0,
232 nProfiles= 0, nChannels= 0, nIncohInt= 0,
233 FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0,
234 AntennaCoord0= 0, AntennaCoord1= 0, AntennaCoord2= 0,
235 RecPhaseCalibr0= 0, RecPhaseCalibr1= 0, RecPhaseCalibr2= 0,
236 RecAmpCalibr0= 0, RecAmpCalibr1= 0, RecAmpCalibr2= 0,
237 AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0,
238 ReceiverGaindB0= 0, ReceiverGaindB1= 0, ReceiverGaindB2= 0, Off2StartData=0, OffsetStartHeader=0):
239
240 self.RecMgcNumber = RecMgcNumber #0x23030001
241 self.RecCounter = RecCounter
242 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.
294 #RecCounter=0
322 startFp = open(fp, "rb")
295 #Off2StartNxtRec=811248
323 # RecCounter=0
296 OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
324 # Off2StartNxtRec=811248
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
@@ -435,28 +465,25 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
435 endTime = None
465 endTime = None
436 walk = None
466 walk = None
437 isConfig = False
467 isConfig = False
438
468
439
469 fileList = None
440 fileList= None
470
441
471 # metadata
442 #metadata
472 TimeZone = None
443 TimeZone= None
473 Interval = None
444 Interval= None
474 heightList = None
445 heightList= None
475
446
476 # data
447 #data
477 data = None
448 data= None
478 utctime = None
449 utctime= None
479
450
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
@@ -464,60 +491,59 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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
497
498
523
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)
508 nFiles=0 #File Counter
533 # Sort the list of files from least to largest by names
509 FileList=[] #A list is created that will contain the .fdt files
534 ListaData = sorted(ListaData)
510 for IndexFile in ListaData :
535 nFiles = 0 # File Counter
511 if '.fdt' in IndexFile:
536 FileList = [] # A list is created that will contain the .fdt files
537 for IndexFile in ListaData:
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.
@@ -527,341 +553,350 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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
610 def readFile(self, fp):
587 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) + '/' + \
604 #print self.fpFile
627 str(self.filenameList[self.fileSelector])
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)
619 Vmax=-Lambda/(4.*(1./PRF)*self.dataOut.nCohInt*2.)
643 PRF = self.dataOut.PRF
620 deltafreq = PRF / (self.nProfiles)
644 Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.)
621 deltavel = (Vmax*2) / (self.nProfiles)
645 deltafreq = PRF / (self.nProfiles)
622 freqrange = deltafreq*(numpy.arange(self.nProfiles)-self.nProfiles/2.) - deltafreq/2
646 deltavel = (Vmax * 2) / (self.nProfiles)
623 velrange = deltavel*(numpy.arange(self.nProfiles)-self.nProfiles/2.)
647 freqrange = deltafreq * \
624 return velrange
648 (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2
625
649 velrange = deltavel * \
626 def readBlock(self):
650 (numpy.arange(self.nProfiles) - self.nProfiles / 2.)
651 return velrange
652
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
676
704 self.dataOut.outputInterval = self.dataOut.ippSeconds * \
677 self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN
705 self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
706
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
739 if self.DualModeIndex == self.ReadMode:
709
740
710
741 self.data_fft = numpy.fromfile(
711 if self.DualModeIndex==self.ReadMode:
742 startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights)
712
743
713 self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights )
744 self.data_fft = self.data_fft.astype(numpy.dtype('complex'))
714
745
715 self.data_fft=self.data_fft.astype(numpy.dtype('complex'))
746 self.data_block = numpy.reshape(
716
747 self.data_fft, (self.nHeights, self.nChannels, self.nProfiles))
717 self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles ))
748
718
749 self.data_block = numpy.transpose(self.data_block, (1, 2, 0))
719 self.data_block = numpy.transpose(self.data_block, (1,2,0))
750
720
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(
725
755 spc) # valor absoluto o magnitud
756
726 factor = self.dataOut.normFactor
757 factor = self.dataOut.normFactor
727
758
728
759 z = self.data_spc.copy() # /factor
729 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
774 ySamples = numpy.ones([3, self.nProfiles])
744 ySamples=numpy.ones([3,self.nProfiles])
775 phase = numpy.ones([3, self.nProfiles])
745 phase=numpy.ones([3,self.nProfiles])
776 CSPCSamples = numpy.ones(
746 CSPCSamples=numpy.ones([3,self.nProfiles],dtype=numpy.complex_)
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(
776
807 rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180)
777 E01=AntennaX0-AntennaX1
808 (AntennaX2, AntennaY2) = pol2cart(
778 N01=AntennaY0-AntennaY1
809 rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180)
779
810
780 E02=AntennaX0-AntennaX2
811 E01 = AntennaX0 - AntennaX1
781 N02=AntennaY0-AntennaY2
812 N01 = AntennaY0 - AntennaY1
782
813
783 E12=AntennaX1-AntennaX2
814 E02 = AntennaX0 - AntennaX2
784 N12=AntennaY1-AntennaY2
815 N02 = AntennaY0 - AntennaY2
785
816
786 self.ChanDist= numpy.array([[E01, N01],[E02,N02],[E12,N12]])
817 E12 = AntennaX1 - AntennaX2
787
818 N12 = AntennaY1 - AntennaY2
819
820 self.ChanDist = numpy.array(
821 [[E01, N01], [E02, N02], [E12, N12]])
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]]))
@@ -869,7 +904,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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)
@@ -880,12 +915,12 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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))
@@ -894,39 +929,39 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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)')
@@ -934,76 +969,76 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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
@@ -1033,25 +1068,25 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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')
@@ -1060,7 +1095,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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)
@@ -1070,7 +1105,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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')
@@ -1079,7 +1114,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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)
@@ -1089,19 +1124,19 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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')
@@ -1115,7 +1150,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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])
@@ -1125,30 +1160,23 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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
1177 self.BlockCounter += 2
1143
1178
1144 self.BlockCounter+=2
1145
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
This diff has been collapsed as it changes many lines, (1027 lines changed) Show them Hide them
@@ -1,4 +1,5
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
@@ -6,11 +7,9 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
@@ -30,152 +29,168 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
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),
75 ('Hdummy',numpy.str_,512), #Reserved space
72 # Place where the measurements was carried out
76 #Main chunk 8bytes
73 ('Hplace', numpy.str_, 128),
77 ('Msign',numpy.str_,4), #Main chunk signature FZKF or NUIG
74 # Description of measurements
78 ('MsizeData','<i4'), #Size of data block main chunk
75 ('Hdescr', numpy.str_, 256),
79 #Processing DSP parameters 36bytes
76 ('Hdummy', numpy.str_, 512), # Reserved space
80 ('PPARsign',numpy.str_,4), #PPAR signature
77 # Main chunk 8bytes
81 ('PPARsize','<i4'), #PPAR size of block
78 # Main chunk signature FZKF or NUIG
82 ('PPARprf','<i4'), #Pulse repetition frequency
79 ('Msign', numpy.str_, 4),
83 ('PPARpdr','<i4'), #Pulse duration
80 ('MsizeData', '<i4'), # Size of data block main chunk
84 ('PPARsft','<i4'), #FFT length
81 # Processing DSP parameters 36bytes
85 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
82 ('PPARsign', numpy.str_, 4), # PPAR signature
86 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
83 ('PPARsize', '<i4'), # PPAR size of block
87 ('PPARchg','<i4'), #Count for gates for moment estimation
84 ('PPARprf', '<i4'), # Pulse repetition frequency
88 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
85 ('PPARpdr', '<i4'), # Pulse duration
89 #Service DSP parameters 112bytes
86 ('PPARsft', '<i4'), # FFT length
90 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
87 # Number of spectral (in-coherent) averages
91 ('SPARtx','<i4'), #OBSOLETE
88 ('PPARavc', '<i4'),
92 ('SPARaddGain0','<f4'), #OBSOLETE
89 # Number of lowest range gate for moment estimation
93 ('SPARaddGain1','<f4'), #OBSOLETE
90 ('PPARihp', '<i4'),
94 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
91 # Count for gates for moment estimation
95 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
92 ('PPARchg', '<i4'),
96 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
93 # switch on/off polarimetric measurements. Should be 1.
97 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
94 ('PPARpol', '<i4'),
98 ('SPARcal','<i4'), #OBSOLETE
95 # Service DSP parameters 112bytes
99 ('SPARnos','<i4'), #OBSOLETE
96 # STC attenuation on the lowest ranges on/off
100 ('SPARof0','<i4'), #detection threshold
97 ('SPARatt', '<i4'),
101 ('SPARof1','<i4'), #OBSOLETE
98 ('SPARtx', '<i4'), # OBSOLETE
102 ('SPARswt','<i4'), #2nd moment estimation threshold
99 ('SPARaddGain0', '<f4'), # OBSOLETE
103 ('SPARsum','<i4'), #OBSOLETE
100 ('SPARaddGain1', '<f4'), # OBSOLETE
104 ('SPARosc','<i4'), #flag Oscillosgram mode
101 # Debug only. It normal mode it is 0.
105 ('SPARtst','<i4'), #OBSOLETE
102 ('SPARwnd', '<i4'),
106 ('SPARcor','<i4'), #OBSOLETE
103 # Delay between sync pulse and tx pulse for phase corr, ns
107 ('SPARofs','<i4'), #OBSOLETE
104 ('SPARpos', '<i4'),
108 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
105 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
109 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
106 ('SPARadd', '<i4'),
110 ('SPARcalibPow_M','<f4'), #OBSOLETE
107 # Time for measuring txn pulse phase. OBSOLETE
111 ('SPARcalibSNR_M','<f4'), #OBSOLETE
108 ('SPARlen', '<i4'),
112 ('SPARcalibPow_S','<f4'), #OBSOLETE
109 ('SPARcal', '<i4'), # OBSOLETE
113 ('SPARcalibSNR_S','<f4'), #OBSOLETE
110 ('SPARnos', '<i4'), # OBSOLETE
114 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
111 ('SPARof0', '<i4'), # detection threshold
115 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
112 ('SPARof1', '<i4'), # OBSOLETE
116 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
113 ('SPARswt', '<i4'), # 2nd moment estimation threshold
117 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
114 ('SPARsum', '<i4'), # OBSOLETE
118
115 ('SPARosc', '<i4'), # flag Oscillosgram mode
119
116 ('SPARtst', '<i4'), # OBSOLETE
120
117 ('SPARcor', '<i4'), # OBSOLETE
118 ('SPARofs', '<i4'), # OBSOLETE
119 # Hildebrand div noise detection on noise gate
120 ('SPARhsn', '<i4'),
121 # Hildebrand div noise detection on all gates
122 ('SPARhsa', '<f4'),
123 ('SPARcalibPow_M', '<f4'), # OBSOLETE
124 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
125 ('SPARcalibPow_S', '<f4'), # OBSOLETE
126 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
127 # Lowest range gate for spectra saving Raw_Gate1 >=5
128 ('SPARrawGate1', '<i4'),
129 # Number of range gates with atmospheric signal
130 ('SPARrawGate2', '<i4'),
131 # flag - IQ or spectra saving on/off
132 ('SPARraw', '<i4'),
133 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
134
135
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.
@@ -194,85 +209,83 class FileHeaderMIRA35c(Header):
194 at least one whitespace.
209 at least one whitespace.
195
210
196 '''
211 '''
197
212
198
213 self.Hname = str(header['Hname'][0])
199 self.Hname= str(header['Hname'][0])
214 self.Htime = str(header['Htime'][0])
200 self.Htime= str(header['Htime'][0])
215 self.Hoper = str(header['Hoper'][0])
201 self.Hoper= str(header['Hoper'][0])
216 self.Hplace = str(header['Hplace'][0])
202 self.Hplace= str(header['Hplace'][0])
217 self.Hdescr = str(header['Hdescr'][0])
203 self.Hdescr= str(header['Hdescr'][0])
218 self.Hdummy = str(header['Hdummy'][0])
204 self.Hdummy= str(header['Hdummy'][0])
219 # 1024
205 #1024
220
206
221 self.Msign = str(header['Msign'][0])
207 self.Msign=str(header['Msign'][0])
222 self.MsizeData = header['MsizeData'][0]
208 self.MsizeData=header['MsizeData'][0]
223 # 8
209 #8
224
210
225 self.PPARsign = str(header['PPARsign'][0])
211 self.PPARsign=str(header['PPARsign'][0])
226 self.PPARsize = header['PPARsize'][0]
212 self.PPARsize=header['PPARsize'][0]
227 self.PPARprf = header['PPARprf'][0]
213 self.PPARprf=header['PPARprf'][0]
228 self.PPARpdr = header['PPARpdr'][0]
214 self.PPARpdr=header['PPARpdr'][0]
229 self.PPARsft = header['PPARsft'][0]
215 self.PPARsft=header['PPARsft'][0]
230 self.PPARavc = header['PPARavc'][0]
216 self.PPARavc=header['PPARavc'][0]
231 self.PPARihp = header['PPARihp'][0]
217 self.PPARihp=header['PPARihp'][0]
232 self.PPARchg = header['PPARchg'][0]
218 self.PPARchg=header['PPARchg'][0]
233 self.PPARpol = header['PPARpol'][0]
219 self.PPARpol=header['PPARpol'][0]
234 # Service DSP parameters
220 #Service DSP parameters
235 # 36
221 #36
236
222
237 self.SPARatt = header['SPARatt'][0]
223 self.SPARatt=header['SPARatt'][0]
238 self.SPARtx = header['SPARtx'][0]
224 self.SPARtx=header['SPARtx'][0]
239 self.SPARaddGain0 = header['SPARaddGain0'][0]
225 self.SPARaddGain0=header['SPARaddGain0'][0]
240 self.SPARaddGain1 = header['SPARaddGain1'][0]
226 self.SPARaddGain1=header['SPARaddGain1'][0]
241 self.SPARwnd = header['SPARwnd'][0]
227 self.SPARwnd=header['SPARwnd'][0]
242 self.SPARpos = header['SPARpos'][0]
228 self.SPARpos=header['SPARpos'][0]
243 self.SPARadd = header['SPARadd'][0]
229 self.SPARadd=header['SPARadd'][0]
244 self.SPARlen = header['SPARlen'][0]
230 self.SPARlen=header['SPARlen'][0]
245 self.SPARcal = header['SPARcal'][0]
231 self.SPARcal=header['SPARcal'][0]
246 self.SPARnos = header['SPARnos'][0]
232 self.SPARnos=header['SPARnos'][0]
247 self.SPARof0 = header['SPARof0'][0]
233 self.SPARof0=header['SPARof0'][0]
248 self.SPARof1 = header['SPARof1'][0]
234 self.SPARof1=header['SPARof1'][0]
249 self.SPARswt = header['SPARswt'][0]
235 self.SPARswt=header['SPARswt'][0]
250 self.SPARsum = header['SPARsum'][0]
236 self.SPARsum=header['SPARsum'][0]
251 self.SPARosc = header['SPARosc'][0]
237 self.SPARosc=header['SPARosc'][0]
252 self.SPARtst = header['SPARtst'][0]
238 self.SPARtst=header['SPARtst'][0]
253 self.SPARcor = header['SPARcor'][0]
239 self.SPARcor=header['SPARcor'][0]
254 self.SPARofs = header['SPARofs'][0]
240 self.SPARofs=header['SPARofs'][0]
255 self.SPARhsn = header['SPARhsn'][0]
241 self.SPARhsn=header['SPARhsn'][0]
256 self.SPARhsa = header['SPARhsa'][0]
242 self.SPARhsa=header['SPARhsa'][0]
257 self.SPARcalibPow_M = header['SPARcalibPow_M'][0]
243 self.SPARcalibPow_M=header['SPARcalibPow_M'][0]
258 self.SPARcalibSNR_M = header['SPARcalibSNR_M'][0]
244 self.SPARcalibSNR_M=header['SPARcalibSNR_M'][0]
259 self.SPARcalibPow_S = header['SPARcalibPow_S'][0]
245 self.SPARcalibPow_S=header['SPARcalibPow_S'][0]
260 self.SPARcalibSNR_S = header['SPARcalibSNR_S'][0]
246 self.SPARcalibSNR_S=header['SPARcalibSNR_S'][0]
261 self.SPARrawGate1 = header['SPARrawGate1'][0]
247 self.SPARrawGate1=header['SPARrawGate1'][0]
262 self.SPARrawGate2 = header['SPARrawGate2'][0]
248 self.SPARrawGate2=header['SPARrawGate2'][0]
263 self.SPARraw = header['SPARraw'][0]
249 self.SPARraw=header['SPARraw'][0]
264 self.SPARprc = header['SPARprc'][0]
250 self.SPARprc=header['SPARprc'][0]
265 # 112
251 #112
266 # 1180
252 #1180
267 # print 'Pointer fp header', fp.tell()
253 #print 'Pointer fp header', fp.tell()
268 # print ' '
254 #print ' '
269 # print 'SPARrawGate'
255 #print 'SPARrawGate'
270 # print self.SPARrawGate2 - self.SPARrawGate1
256 #print self.SPARrawGate2 - self.SPARrawGate1
271
257
272 # print ' '
258 #print ' '
273 # print 'Hname'
259 #print 'Hname'
274 # print self.Hname
260 #print self.Hname
275
261
276 # print ' '
262 #print ' '
277 # print 'Msign'
263 #print 'Msign'
278 # print self.Msign
264 #print self.Msign
279
265
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)
@@ -290,72 +303,70 class FileHeaderMIRA35c(Header):
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
296 SRVI_HEADER = numpy.dtype([
309
297 ('SignatureSRVI1',numpy.str_,4),#
310 SRVI_HEADER = numpy.dtype([
298 ('SizeOfDataBlock1','<i4'),#
311 ('SignatureSRVI1', numpy.str_, 4),
299 ('DataBlockTitleSRVI1',numpy.str_,4),#
312 ('SizeOfDataBlock1', '<i4'),
300 ('SizeOfSRVI1','<i4'),])#
313 ('DataBlockTitleSRVI1', numpy.str_, 4),
301
314 ('SizeOfSRVI1', '<i4'), ])
302 class SRVIHeader(Header):
315
316
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
323
324 SRVI_STRUCTURE = numpy.dtype([
325 ('frame_cnt','<u4'),#
326 ('time_t','<u4'), #
327 ('tpow','<f4'), #
328 ('npw1','<f4'), #
329 ('npw2','<f4'), #
330 ('cpw1','<f4'), #
331 ('pcw2','<f4'), #
332 ('ps_err','<u4'), #
333 ('te_err','<u4'), #
334 ('rc_err','<u4'), #
335 ('grs1','<u4'), #
336 ('grs2','<u4'), #
337 ('azipos','<f4'), #
338 ('azivel','<f4'), #
339 ('elvpos','<f4'), #
340 ('elvvel','<f4'), #
341 ('northAngle','<f4'), #
342 ('microsec','<u4'), #
343 ('azisetvel','<f4'), #
344 ('elvsetpos','<f4'), #
345 ('RadarConst','<f4'),]) #
346
337
347
338
339 SRVI_STRUCTURE = numpy.dtype([
340 ('frame_cnt', '<u4'),
341 ('time_t', '<u4'), #
342 ('tpow', '<f4'), #
343 ('npw1', '<f4'), #
344 ('npw2', '<f4'), #
345 ('cpw1', '<f4'), #
346 ('pcw2', '<f4'), #
347 ('ps_err', '<u4'), #
348 ('te_err', '<u4'), #
349 ('rc_err', '<u4'), #
350 ('grs1', '<u4'), #
351 ('grs2', '<u4'), #
352 ('azipos', '<f4'), #
353 ('azivel', '<f4'), #
354 ('elvpos', '<f4'), #
355 ('elvvel', '<f4'), #
356 ('northAngle', '<f4'),
357 ('microsec', '<u4'), #
358 ('azisetvel', '<f4'), #
359 ('elvsetpos', '<f4'), #
360 ('RadarConst', '<f4'), ]) #
348
361
349
362
350 class RecordHeader(Header):
363 class RecordHeader(Header):
351
364
352
365 def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0,
353 def __init__(self, frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
366 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
354 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
367 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
355 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
368 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0):
356 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0 , RecCounter=0, Off2StartNxtRec=0):
369
357
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
@@ -377,22 +388,22 class RecordHeader(Header):
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] #
@@ -413,26 +424,26 class RecordHeader(Header):
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
434 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
444
435
445 class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader):
446
436 path = None
447 path = None
437 startDate = None
448 startDate = None
438 endDate = None
449 endDate = None
@@ -440,87 +451,84 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
440 endTime = None
451 endTime = None
441 walk = None
452 walk = None
442 isConfig = False
453 isConfig = False
443
454
444
455 fileList = None
445 fileList= None
456
446
457 # metadata
447 #metadata
458 TimeZone = None
448 TimeZone= None
459 Interval = None
449 Interval= None
460 heightList = None
450 heightList= None
461
451
462 # data
452 #data
463 data = None
453 data= None
464 utctime = None
454 utctime= None
465
455
466 def __init__(self, **kwargs):
456
467
457
468 # Eliminar de la base la herencia
458 def __init__(self, **kwargs):
459
460 #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)
511 nFiles=0 #File Counter
518 # Sort the list of files from least to largest by names
512 FileList=[] #A list is created that will contain the .fdt files
519 ListaData = sorted(ListaData)
513 for IndexFile in ListaData :
520 nFiles = 0 # File Counter
514 if '.zspca' in IndexFile and '.gz' not in IndexFile:
521 FileList = [] # A list is created that will contain the .fdt files
522 for IndexFile in ListaData:
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.
@@ -530,274 +538,265 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
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
595 def readFile(self, fp):
591 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) + '/' + \
608
612 str(self.filenameList[self.fileSelector])
609 if self.nextfileflag==True:
613
610 self.fp = open(self.fpFile,"rb")
614 if self.nextfileflag == True:
611 self.nextfileflag==False
615 self.fp = open(self.fpFile, "rb")
612
616 self.nextfileflag == False
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
619
622
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
644 self.readBlock() # Block reading
643
645
644 self.readBlock() #Block reading
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
653 def readBlock(self):
654
655 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
686
682 self.srviHeader.SRVIread(self.fp)
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
707
712
708 self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1)
713 self.HSDVsign = numpy.fromfile( self.fp, [('HSDV',numpy.str_,4)],1)
709 self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1)
714 self.SizeHSDV = numpy.fromfile( self.fp, [('SizeHSDV','<i4')],1)
710 self.HSDV_Co = numpy.fromfile(
715 self.HSDV_Co = numpy.fromfile( self.fp, [('HSDV_Co','<f4')],self.Num_Hei)
711 self.fp, [('HSDV_Co', '<f4')], self.Num_Hei)
716 self.HSDV_Cx = numpy.fromfile( self.fp, [('HSDV_Cx','<f4')],self.Num_Hei)
712 self.HSDV_Cx = numpy.fromfile(
717
713 self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei)
718 self.COFAsign = numpy.fromfile( self.fp, [('COFA',numpy.str_,4)],1)
714
719 self.SizeCOFA = numpy.fromfile( self.fp, [('SizeCOFA','<i4')],1)
715 self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1)
720 self.COFA_Co = numpy.fromfile( self.fp, [('COFA_Co','<f4')],self.Num_Hei)
716 self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1)
721 self.COFA_Cx = numpy.fromfile( self.fp, [('COFA_Cx','<f4')],self.Num_Hei)
717 self.COFA_Co = numpy.fromfile(
722
718 self.fp, [('COFA_Co', '<f4')], self.Num_Hei)
723 self.ZSPCsign = numpy.fromfile(self.fp, [('ZSPCsign',numpy.str_,4)],1)
719 self.COFA_Cx = numpy.fromfile(
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC','<i4')],1)
720 self.fp, [('COFA_Cx', '<f4')], self.Num_Hei)
725
721
726 self.dataOut.HSDV[0]=self.HSDV_Co[:][0]
722 self.ZSPCsign = numpy.fromfile(
727 self.dataOut.HSDV[1]=self.HSDV_Cx[:][0]
723 self.fp, [('ZSPCsign', numpy.str_, 4)], 1)
728
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1)
725
726 self.dataOut.HSDV[0] = self.HSDV_Co[:][0]
727 self.dataOut.HSDV[1] = self.HSDV_Cx[:][0]
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
731 nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0]
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(
735
736 self.fp, [('binIndex', 'int16')], 1)[0][0]
736 #Co_Channel
737 nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[
737 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0] # Spectrum piece to be normaliced
738 0][0] # Number of bins of the piece
738 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0] # Maximun piece to be normaliced
739
739
740 # Co_Channel
740
741 jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[
741 self.data_spc[irg,binIndex:binIndex+nbins,0] = self.data_spc[irg,binIndex:binIndex+nbins,0]+jbin/65530.*jmax
742 0][0] # Spectrum piece to be normaliced
742
743 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[
743 #Cx_Channel
744 0][0] # Maximun piece to be normaliced
744 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0]
745
745 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0]
746 self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg,
746
747 binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax
747
748
748 self.data_spc[irg,binIndex:binIndex+nbins,1] = self.data_spc[irg,binIndex:binIndex+nbins,1]+jbin/65530.*jmax
749 # Cx_Channel
749
750 jbin = numpy.fromfile(
750 for bin in range(self.Num_Bins):
751 self.fp, [('jbin', 'uint16')], nbins)[0][0]
751
752 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0]
752 self.data_spc[:,bin,0] = self.data_spc[:,bin,0] - self.dataOut.HSDV[:,0]
753
753
754 self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg,
754 self.data_spc[:,bin,1] = self.data_spc[:,bin,1] - self.dataOut.HSDV[:,1]
755 binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax
755
756
756
757 for bin in range(self.Num_Bins):
758
759 self.data_spc[:, bin, 0] = self.data_spc[:,
760 bin, 0] - self.dataOut.HSDV[:, 0]
761
762 self.data_spc[:, bin, 1] = self.data_spc[:,
763 bin, 1] - self.dataOut.HSDV[:, 1]
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
@@ -11,7 +11,6 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader,
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)
@@ -21,7 +20,6 class SpectraReader(JRODataReader, ProcessingUnit):
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
@@ -76,7 +74,6 class SpectraReader(JRODataReader, ProcessingUnit):
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,
@@ -84,107 +81,104 class SpectraReader(JRODataReader, ProcessingUnit):
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
84 Affected:
88 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
@@ -192,7 +186,7 class SpectraReader(JRODataReader, ProcessingUnit):
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
@@ -212,39 +206,37 class SpectraReader(JRODataReader, ProcessingUnit):
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
248
240
249 self.flagIsNewFile
241 self.flagIsNewFile
250 self.flagIsNewBlock
242 self.flagIsNewBlock
@@ -253,10 +245,9 class SpectraReader(JRODataReader, ProcessingUnit):
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
@@ -266,32 +257,30 class SpectraReader(JRODataReader, ProcessingUnit):
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
288 if self.processingHeaderObj.flag_cspc:
289
278
279 if self.processingHeaderObj.flag_cspc:
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
295
284
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
@@ -305,60 +294,60 class SpectraReader(JRODataReader, ProcessingUnit):
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 """
@@ -367,70 +356,68 class SpectraReader(JRODataReader, ProcessingUnit):
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
380
368
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
432 Affected:
433
419
420 Affected:
434 self.dataOut
421 self.dataOut
435 self.basicHeaderObj
422 self.basicHeaderObj
436 self.systemHeaderObj
423 self.systemHeaderObj
@@ -439,51 +426,49 class SpectraWriter(JRODataWriter, Operation):
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
453
439
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
487
472
488 def setBlockDimension(self):
473 def setBlockDimension(self):
489 """
474 """
@@ -503,15 +488,14 class SpectraWriter(JRODataWriter, Operation):
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
515
499
516 Affected:
500 Affected:
517 self.data_spc
501 self.data_spc
@@ -520,11 +504,11 class SpectraWriter(JRODataWriter, Operation):
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
@@ -541,7 +525,6 class SpectraWriter(JRODataWriter, Operation):
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
545
528
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 )
@@ -552,147 +535,145 class SpectraWriter(JRODataWriter, Operation):
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
562
544
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
575
556
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)
593 self.data_cspc.fill(0)
574 if self.dataOut.data_cspc is not None:
594 self.data_dc.fill(0)
575 self.data_cspc.fill(0)
576 if self.dataOut.data_dc is not None:
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
615
597
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
668
649
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()
@@ -15,6 +15,7 import tempfile
15 from StringIO import StringIO
15 from StringIO import StringIO
16 # from _sha import blocksize
16 # from _sha import blocksize
17
17
18
18 class VoltageReader(JRODataReader, ProcessingUnit):
19 class VoltageReader(JRODataReader, ProcessingUnit):
19 """
20 """
20 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
21 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
@@ -134,13 +135,13 class VoltageReader(JRODataReader, ProcessingUnit):
134
135
135 self.path = None
136 self.path = None
136
137
137 self.profileIndex = 2**32-1
138 self.profileIndex = 2**32 - 1
138
139
139 self.delay = 3 #seconds
140 self.delay = 3 # seconds
140
141
141 self.nTries = 3 #quantity tries
142 self.nTries = 3 # quantity tries
142
143
143 self.nFiles = 3 #number of files for searching
144 self.nFiles = 3 # number of files for searching
144
145
145 self.nReadBlocks = 0
146 self.nReadBlocks = 0
146
147
@@ -172,51 +173,49 class VoltageReader(JRODataReader, ProcessingUnit):
172
173
173 def __hasNotDataInBuffer(self):
174 def __hasNotDataInBuffer(self):
174
175
175 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs:
176 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock * self.nTxs:
176 return 1
177 return 1
177
178
178 return 0
179 return 0
179
180
180
181 def getBlockDimension(self):
181 def getBlockDimension(self):
182 """
182 """
183 Obtiene la cantidad de puntos a leer por cada bloque de datos
183 Obtiene la cantidad de puntos a leer por cada bloque de datos
184
184
185 Affected:
185 Affected:
186 self.blocksize
186 self.blocksize
187
187
188 Return:
188 Return:
189 None
189 None
190 """
190 """
191 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
191 pts2read = self.processingHeaderObj.profilesPerBlock * \
192 self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
192 self.blocksize = pts2read
193 self.blocksize = pts2read
193
194
194
195
196 def readBlock(self):
195 def readBlock(self):
197 """
196 """
198 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
197 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
199 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
198 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
200 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
199 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
201 es seteado a 0
200 es seteado a 0
202
201
203 Inputs:
202 Inputs:
204 None
203 None
205
204
206 Return:
205 Return:
207 None
206 None
208
207
209 Affected:
208 Affected:
210 self.profileIndex
209 self.profileIndex
211 self.datablock
210 self.datablock
212 self.flagIsNewFile
211 self.flagIsNewFile
213 self.flagIsNewBlock
212 self.flagIsNewBlock
214 self.nTotalBlocks
213 self.nTotalBlocks
215
214
216 Exceptions:
215 Exceptions:
217 Si un bloque leido no es un bloque valido
216 Si un bloque leido no es un bloque valido
218 """
217 """
219
218
220 # if self.server is not None:
219 # if self.server is not None:
221 # self.zBlock = self.receiver.recv()
220 # self.zBlock = self.receiver.recv()
222 # self.zHeader = self.zBlock[:24]
221 # self.zHeader = self.zBlock[:24]
@@ -227,22 +226,24 class VoltageReader(JRODataReader, ProcessingUnit):
227 # self.systemHeaderObj.nChannels
226 # self.systemHeaderObj.nChannels
228 # else:
227 # else:
229 current_pointer_location = self.fp.tell()
228 current_pointer_location = self.fp.tell()
230 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
229 junk = numpy.fromfile(self.fp, self.dtype, self.blocksize)
231
230
232 try:
231 try:
233 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
232 junk = junk.reshape((self.processingHeaderObj.profilesPerBlock,
233 self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels))
234 except:
234 except:
235 #print "The read block (%3d) has not enough data" %self.nReadBlocks
235 # print "The read block (%3d) has not enough data" %self.nReadBlocks
236
236
237 if self.waitDataBlock(pointer_location=current_pointer_location):
237 if self.waitDataBlock(pointer_location=current_pointer_location):
238 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
238 junk = numpy.fromfile(self.fp, self.dtype, self.blocksize)
239 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
239 junk = junk.reshape((self.processingHeaderObj.profilesPerBlock,
240 self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels))
240 # return 0
241 # return 0
241
242
242 #Dimensions : nChannels, nProfiles, nSamples
243 # Dimensions : nChannels, nProfiles, nSamples
243
244
244 junk = numpy.transpose(junk, (2,0,1))
245 junk = numpy.transpose(junk, (2, 0, 1))
245 self.datablock = junk['real'] + junk['imag']*1j
246 self.datablock = junk['real'] + junk['imag'] * 1j
246
247
247 self.profileIndex = 0
248 self.profileIndex = 0
248
249
@@ -263,9 +264,8 class VoltageReader(JRODataReader, ProcessingUnit):
263 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
264 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
264
265
265 if self.nTxs > 1:
266 if self.nTxs > 1:
266 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
267 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
267
268 # Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj.
268 #Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj.
269
269
270 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
270 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
271 #
271 #
@@ -281,15 +281,18 class VoltageReader(JRODataReader, ProcessingUnit):
281
281
282 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
282 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
283
283
284 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
284 self.dataOut.heightList = numpy.arange(
285 self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
285
286
286 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
287 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
287
288
288 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
289 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
289
290
290 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada
291 # asumo q la data no esta decodificada
292 self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode
291
293
292 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip
294 # asumo q la data no esta sin flip
295 self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip
293
296
294 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
297 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
295
298
@@ -301,51 +304,57 class VoltageReader(JRODataReader, ProcessingUnit):
301 if self.nTxs == 1:
304 if self.nTxs == 1:
302 return
305 return
303
306
304 if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0:
307 if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1. / self.nTxs) != 0:
305 raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %(1./self.nTxs, self.processingHeaderObj.profilesPerBlock)
308 raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" % (
309 1. / self.nTxs, self.processingHeaderObj.profilesPerBlock)
306
310
307 if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0:
311 if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0:
308 raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %(self.nTxs, self.processingHeaderObj.nHeights)
312 raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" % (
313 self.nTxs, self.processingHeaderObj.nHeights)
309
314
310 self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs))
315 self.datablock = self.datablock.reshape(
316 (self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock * self.nTxs, self.processingHeaderObj.nHeights / self.nTxs))
311
317
312 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
318 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock * self.nTxs
313 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
319 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights / self.nTxs) * \
314 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
320 self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
321 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
315
322
316 return
323 return
317
324
318 def readFirstHeaderFromServer(self):
325 def readFirstHeaderFromServer(self):
319
326
320 self.getFirstHeader()
327 self.getFirstHeader()
321
328
322 self.firstHeaderSize = self.basicHeaderObj.size
329 self.firstHeaderSize = self.basicHeaderObj.size
323
330
324 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
331 datatype = int(numpy.log2((self.processingHeaderObj.processFlags &
332 PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR))
325 if datatype == 0:
333 if datatype == 0:
326 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
334 datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
327 elif datatype == 1:
335 elif datatype == 1:
328 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
336 datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
329 elif datatype == 2:
337 elif datatype == 2:
330 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
338 datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
331 elif datatype == 3:
339 elif datatype == 3:
332 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
340 datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
333 elif datatype == 4:
341 elif datatype == 4:
334 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
342 datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
335 elif datatype == 5:
343 elif datatype == 5:
336 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
344 datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
337 else:
345 else:
338 raise ValueError, 'Data type was not defined'
346 raise ValueError, 'Data type was not defined'
339
347
340 self.dtype = datatype_str
348 self.dtype = datatype_str
341 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
349 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
342 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
350 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
351 self.firstHeaderSize + self.basicHeaderSize * \
352 (self.processingHeaderObj.dataBlocksPerFile - 1)
343 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
353 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
344 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
354 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
345 self.getBlockDimension()
355 self.getBlockDimension()
346
356
347
357 def getFromServer(self):
348 def getFromServer(self):
349 self.flagDiscontinuousBlock = 0
358 self.flagDiscontinuousBlock = 0
350 self.profileIndex = 0
359 self.profileIndex = 0
351 self.flagIsNewBlock = 1
360 self.flagIsNewBlock = 1
@@ -365,38 +374,46 class VoltageReader(JRODataReader, ProcessingUnit):
365 self.processingHeaderObj.read(block[self.blockPointer:])
374 self.processingHeaderObj.read(block[self.blockPointer:])
366 self.blockPointer += self.processingHeaderObj.length
375 self.blockPointer += self.processingHeaderObj.length
367 self.readFirstHeaderFromServer()
376 self.readFirstHeaderFromServer()
368
377
369 timestamp = self.basicHeaderObj.get_datatime()
378 timestamp = self.basicHeaderObj.get_datatime()
370 print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp)
379 print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp)
371 current_pointer_location = self.blockPointer
380 current_pointer_location = self.blockPointer
372 junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize )
381 junk = numpy.fromstring(
382 block[self.blockPointer:], self.dtype, self.blocksize)
373
383
374 try:
384 try:
375 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
385 junk = junk.reshape((self.processingHeaderObj.profilesPerBlock,
386 self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels))
376 except:
387 except:
377 #print "The read block (%3d) has not enough data" %self.nReadBlocks
388 # print "The read block (%3d) has not enough data" %self.nReadBlocks
378 if self.waitDataBlock(pointer_location=current_pointer_location):
389 if self.waitDataBlock(pointer_location=current_pointer_location):
379 junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize )
390 junk = numpy.fromstring(
380 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
391 block[self.blockPointer:], self.dtype, self.blocksize)
392 junk = junk.reshape((self.processingHeaderObj.profilesPerBlock,
393 self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels))
381 # return 0
394 # return 0
382
395
383 #Dimensions : nChannels, nProfiles, nSamples
396 # Dimensions : nChannels, nProfiles, nSamples
384
397
385 junk = numpy.transpose(junk, (2,0,1))
398 junk = numpy.transpose(junk, (2, 0, 1))
386 self.datablock = junk['real'] + junk['imag'] * 1j
399 self.datablock = junk['real'] + junk['imag'] * 1j
387 self.profileIndex = 0
400 self.profileIndex = 0
388 if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles
401 if self.selBlocksize == None:
402 self.selBlocksize = self.dataOut.nProfiles
389 if self.selBlocktime != None:
403 if self.selBlocktime != None:
390 if self.dataOut.nCohInt is not None:
404 if self.dataOut.nCohInt is not None:
391 nCohInt = self.dataOut.nCohInt
405 nCohInt = self.dataOut.nCohInt
392 else:
406 else:
393 nCohInt = 1
407 nCohInt = 1
394 self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles)))
408 self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / (
395 self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:]
409 nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles)))
410 self.dataOut.data = self.datablock[:,
411 self.profileIndex:self.profileIndex + self.selBlocksize, :]
396 datasize = self.dataOut.data.shape[1]
412 datasize = self.dataOut.data.shape[1]
397 if datasize < self.selBlocksize:
413 if datasize < self.selBlocksize:
398 buffer = numpy.zeros((self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype = 'complex')
414 buffer = numpy.zeros(
399 buffer[:,:datasize,:] = self.dataOut.data
415 (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex')
416 buffer[:, :datasize, :] = self.dataOut.data
400 self.dataOut.data = buffer
417 self.dataOut.data = buffer
401 self.profileIndex = blockIndex
418 self.profileIndex = blockIndex
402
419
@@ -412,30 +429,30 class VoltageReader(JRODataReader, ProcessingUnit):
412 del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos
429 del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos
413 en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando
430 en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando
414 "readNextBlock"
431 "readNextBlock"
415
432
416 Ademas incrementa el contador del buffer "self.profileIndex" en 1.
433 Ademas incrementa el contador del buffer "self.profileIndex" en 1.
417
434
418 Return:
435 Return:
419
436
420 Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex
437 Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex
421 es igual al total de perfiles leidos desde el archivo.
438 es igual al total de perfiles leidos desde el archivo.
422
439
423 Si self.getByBlock == False:
440 Si self.getByBlock == False:
424
441
425 self.dataOut.data = buffer[:, thisProfile, :]
442 self.dataOut.data = buffer[:, thisProfile, :]
426
443
427 shape = [nChannels, nHeis]
444 shape = [nChannels, nHeis]
428
445
429 Si self.getByBlock == True:
446 Si self.getByBlock == True:
430
447
431 self.dataOut.data = buffer[:, :, :]
448 self.dataOut.data = buffer[:, :, :]
432
449
433 shape = [nChannels, nProfiles, nHeis]
450 shape = [nChannels, nProfiles, nHeis]
434
451
435 Variables afectadas:
452 Variables afectadas:
436 self.dataOut
453 self.dataOut
437 self.profileIndex
454 self.profileIndex
438
455
439 Affected:
456 Affected:
440 self.dataOut
457 self.dataOut
441 self.profileIndex
458 self.profileIndex
@@ -449,7 +466,7 class VoltageReader(JRODataReader, ProcessingUnit):
449 self.flagDiscontinuousBlock = 0
466 self.flagDiscontinuousBlock = 0
450 self.flagIsNewBlock = 0
467 self.flagIsNewBlock = 0
451 if self.__hasNotDataInBuffer():
468 if self.__hasNotDataInBuffer():
452 if not( self.readNextBlock() ):
469 if not(self.readNextBlock()):
453 return 0
470 return 0
454
471
455 self.getFirstHeader()
472 self.getFirstHeader()
@@ -468,11 +485,11 class VoltageReader(JRODataReader, ProcessingUnit):
468 blocks is increased by nTxs (nProfiles *= nTxs)
485 blocks is increased by nTxs (nProfiles *= nTxs)
469 """
486 """
470 self.dataOut.flagDataAsBlock = False
487 self.dataOut.flagDataAsBlock = False
471 self.dataOut.data = self.datablock[:,self.profileIndex,:]
488 self.dataOut.data = self.datablock[:, self.profileIndex, :]
472 self.dataOut.profileIndex = self.profileIndex
489 self.dataOut.profileIndex = self.profileIndex
473
490
474 self.profileIndex += 1
491 self.profileIndex += 1
475
492
476 # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles:
493 # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles:
477 # """
494 # """
478 # Return all block
495 # Return all block
@@ -480,42 +497,47 class VoltageReader(JRODataReader, ProcessingUnit):
480 # self.dataOut.flagDataAsBlock = True
497 # self.dataOut.flagDataAsBlock = True
481 # self.dataOut.data = self.datablock
498 # self.dataOut.data = self.datablock
482 # self.dataOut.profileIndex = self.dataOut.nProfiles - 1
499 # self.dataOut.profileIndex = self.dataOut.nProfiles - 1
483 #
500 #
484 # self.profileIndex = self.dataOut.nProfiles
501 # self.profileIndex = self.dataOut.nProfiles
485
502
486 else:
503 else:
487 """
504 """
488 Return a block
505 Return a block
489 """
506 """
490 if self.selBlocksize == None: self.selBlocksize = self.dataOut.nProfiles
507 if self.selBlocksize == None:
508 self.selBlocksize = self.dataOut.nProfiles
491 if self.selBlocktime != None:
509 if self.selBlocktime != None:
492 if self.dataOut.nCohInt is not None:
510 if self.dataOut.nCohInt is not None:
493 nCohInt = self.dataOut.nCohInt
511 nCohInt = self.dataOut.nCohInt
494 else:
512 else:
495 nCohInt = 1
513 nCohInt = 1
496 self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/(nCohInt*self.dataOut.ippSeconds*self.dataOut.nProfiles)))
514 self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / (
515 nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles)))
497
516
498 self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:]
517 self.dataOut.data = self.datablock[:,
518 self.profileIndex:self.profileIndex + self.selBlocksize, :]
499 self.profileIndex += self.selBlocksize
519 self.profileIndex += self.selBlocksize
500 datasize = self.dataOut.data.shape[1]
520 datasize = self.dataOut.data.shape[1]
501
521
502 if datasize < self.selBlocksize:
522 if datasize < self.selBlocksize:
503 buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex')
523 buffer = numpy.zeros(
504 buffer[:,:datasize,:] = self.dataOut.data
524 (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex')
525 buffer[:, :datasize, :] = self.dataOut.data
505
526
506 while datasize < self.selBlocksize: #Not enough profiles to fill the block
527 while datasize < self.selBlocksize: # Not enough profiles to fill the block
507 if not( self.readNextBlock() ):
528 if not(self.readNextBlock()):
508 return 0
529 return 0
509 self.getFirstHeader()
530 self.getFirstHeader()
510 self.reshapeData()
531 self.reshapeData()
511 if self.datablock is None:
532 if self.datablock is None:
512 self.dataOut.flagNoData = True
533 self.dataOut.flagNoData = True
513 return 0
534 return 0
514 #stack data
535 # stack data
515 blockIndex = self.selBlocksize - datasize
536 blockIndex = self.selBlocksize - datasize
516 datablock1 = self.datablock[:,:blockIndex,:]
537 datablock1 = self.datablock[:, :blockIndex, :]
517
538
518 buffer[:,datasize:datasize+datablock1.shape[1],:] = datablock1
539 buffer[:, datasize:datasize +
540 datablock1.shape[1], :] = datablock1
519 datasize += datablock1.shape[1]
541 datasize += datablock1.shape[1]
520
542
521 self.dataOut.data = buffer
543 self.dataOut.data = buffer
@@ -527,16 +549,11 class VoltageReader(JRODataReader, ProcessingUnit):
527 self.dataOut.flagNoData = False
549 self.dataOut.flagNoData = False
528
550
529 self.getBasicHeader()
551 self.getBasicHeader()
530
552
531 #print self.basicHeaderObj.printInfo()
532 #print self.systemHeaderObj.printInfo()
533 #print self.radarControllerHeaderObj.printInfo()
534 #print self.processingHeaderObj.printInfo()
535
536 self.dataOut.realtime = self.online
553 self.dataOut.realtime = self.online
537
554
538 return self.dataOut.data
555 return self.dataOut.data
539
556
540
557
541 class VoltageWriter(JRODataWriter, Operation):
558 class VoltageWriter(JRODataWriter, Operation):
542 """
559 """
@@ -550,7 +567,6 class VoltageWriter(JRODataWriter, Operation):
550
567
551 shapeBuffer = None
568 shapeBuffer = None
552
569
553
554 def __init__(self, **kwargs):
570 def __init__(self, **kwargs):
555 """
571 """
556 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
572 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
@@ -597,7 +613,6 class VoltageWriter(JRODataWriter, Operation):
597 return 1
613 return 1
598 return 0
614 return 0
599
615
600
601 def setBlockDimension(self):
616 def setBlockDimension(self):
602 """
617 """
603 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
618 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
@@ -614,8 +629,8 class VoltageWriter(JRODataWriter, Operation):
614 self.systemHeaderObj.nChannels)
629 self.systemHeaderObj.nChannels)
615
630
616 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
631 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
617 self.processingHeaderObj.profilesPerBlock,
632 self.processingHeaderObj.profilesPerBlock,
618 self.processingHeaderObj.nHeights),
633 self.processingHeaderObj.nHeights),
619 dtype=numpy.dtype('complex64'))
634 dtype=numpy.dtype('complex64'))
620
635
621 def writeBlock(self):
636 def writeBlock(self):
@@ -631,16 +646,16 class VoltageWriter(JRODataWriter, Operation):
631
646
632 Return: None
647 Return: None
633 """
648 """
634 data = numpy.zeros( self.shapeBuffer, self.dtype )
649 data = numpy.zeros(self.shapeBuffer, self.dtype)
635
650
636 junk = numpy.transpose(self.datablock, (1,2,0))
651 junk = numpy.transpose(self.datablock, (1, 2, 0))
637
652
638 data['real'] = junk.real
653 data['real'] = junk.real
639 data['imag'] = junk.imag
654 data['imag'] = junk.imag
640
655
641 data = data.reshape( (-1) )
656 data = data.reshape((-1))
642
657
643 data.tofile( self.fp )
658 data.tofile(self.fp)
644
659
645 self.datablock.fill(0)
660 self.datablock.fill(0)
646
661
@@ -678,12 +693,12 class VoltageWriter(JRODataWriter, Operation):
678 if self.profileIndex == 0:
693 if self.profileIndex == 0:
679 self.setBasicHeader()
694 self.setBasicHeader()
680
695
681 self.datablock[:,self.profileIndex,:] = self.dataOut.data
696 self.datablock[:, self.profileIndex, :] = self.dataOut.data
682
697
683 self.profileIndex += 1
698 self.profileIndex += 1
684
699
685 if self.hasAllDataInBuffer():
700 if self.hasAllDataInBuffer():
686 #if self.flagIsNewFile:
701 # if self.flagIsNewFile:
687 self.writeNextBlock()
702 self.writeNextBlock()
688 # self.setFirstHeader()
703 # self.setFirstHeader()
689
704
@@ -696,12 +711,12 class VoltageWriter(JRODataWriter, Operation):
696
711
697 dtype_width = self.getDtypeWidth()
712 dtype_width = self.getDtypeWidth()
698
713
699 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * dtype_width * 2)
714 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels *
715 self.profilesPerBlock * dtype_width * 2)
700
716
701 return blocksize
717 return blocksize
702
718
703 def setFirstHeader(self):
719 def setFirstHeader(self):
704
705 """
720 """
706 Obtiene una copia del First Header
721 Obtiene una copia del First Header
707
722
@@ -718,14 +733,17 class VoltageWriter(JRODataWriter, Operation):
718 self.systemHeaderObj.nChannels = self.dataOut.nChannels
733 self.systemHeaderObj.nChannels = self.dataOut.nChannels
719 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
734 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
720
735
721 self.processingHeaderObj.dtype = 0 # Voltage
736 self.processingHeaderObj.dtype = 0 # Voltage
722 self.processingHeaderObj.blockSize = self.__getBlockSize()
737 self.processingHeaderObj.blockSize = self.__getBlockSize()
723 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
738 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
724 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
739 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
725 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
740 # podria ser 1 o self.dataOut.processingHeaderObj.nWindows
741 self.processingHeaderObj.nWindows = 1
726 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
742 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
727 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
743 # Cuando la data de origen es de tipo Voltage
728 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
744 self.processingHeaderObj.nIncohInt = 1
745 # Cuando la data de origen es de tipo Voltage
746 self.processingHeaderObj.totalSpectra = 0
729
747
730 if self.dataOut.code is not None:
748 if self.dataOut.code is not None:
731 self.processingHeaderObj.code = self.dataOut.code
749 self.processingHeaderObj.code = self.dataOut.code
@@ -734,7 +752,8 class VoltageWriter(JRODataWriter, Operation):
734
752
735 if self.processingHeaderObj.nWindows != 0:
753 if self.processingHeaderObj.nWindows != 0:
736 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
754 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
737 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
755 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - \
756 self.dataOut.heightList[0]
738 self.processingHeaderObj.nHeights = self.dataOut.nHeights
757 self.processingHeaderObj.nHeights = self.dataOut.nHeights
739 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
758 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
740
759
@@ -6,8 +6,8 from jroproc_base import ProcessingUnit, Operation
6 from schainpy.model.data.jroamisr import AMISR
6 from schainpy.model.data.jroamisr import AMISR
7
7
8 class AMISRProc(ProcessingUnit):
8 class AMISRProc(ProcessingUnit):
9 def __init__(self):
9 def __init__(self, **kwargs):
10 ProcessingUnit.__init__(self)
10 ProcessingUnit.__init__(self, **kwargs)
11 self.objectDict = {}
11 self.objectDict = {}
12 self.dataOut = AMISR()
12 self.dataOut = AMISR()
13
13
@@ -17,7 +17,8 class AMISRProc(ProcessingUnit):
17
17
18
18
19 class PrintInfo(Operation):
19 class PrintInfo(Operation):
20 def __init__(self):
20 def __init__(self, **kwargs):
21 Operation.__init__(self, **kwargs)
21 self.__isPrinted = False
22 self.__isPrinted = False
22
23
23 def run(self, dataOut):
24 def run(self, dataOut):
@@ -42,8 +43,8 class BeamSelector(Operation):
42 profileIndex = None
43 profileIndex = None
43 nProfiles = None
44 nProfiles = None
44
45
45 def __init__(self):
46 def __init__(self, **kwargs):
46
47 Operation.__init__(self, **kwargs)
47 self.profileIndex = 0
48 self.profileIndex = 0
48 self.__isConfig = False
49 self.__isConfig = False
49
50
@@ -98,7 +99,8 class BeamSelector(Operation):
98
99
99 class ProfileToChannels(Operation):
100 class ProfileToChannels(Operation):
100
101
101 def __init__(self):
102 def __init__(self, **kwargs):
103 Operation.__init__(self, **kwargs)
102 self.__isConfig = False
104 self.__isConfig = False
103 self.__counter_chan = 0
105 self.__counter_chan = 0
104 self.buffer = None
106 self.buffer = None
@@ -17,7 +17,6 from functools import partial
17 import time
17 import time
18 #from sklearn.cluster import KMeans
18 #from sklearn.cluster import KMeans
19
19
20 import matplotlib.pyplot as plt
21
20
22 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
21 from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters
23 from jroproc_base import ProcessingUnit, Operation
22 from jroproc_base import ProcessingUnit, Operation
@@ -1766,8 +1765,8 class WindProfiler(Operation):
1766
1765
1767 n = None
1766 n = None
1768
1767
1769 def __init__(self):
1768 def __init__(self, **kwargs):
1770 Operation.__init__(self)
1769 Operation.__init__(self, **kwargs)
1771
1770
1772 def __calculateCosDir(self, elev, azim):
1771 def __calculateCosDir(self, elev, azim):
1773 zen = (90 - elev)*numpy.pi/180
1772 zen = (90 - elev)*numpy.pi/180
@@ -2473,8 +2472,8 class WindProfiler(Operation):
2473
2472
2474 class EWDriftsEstimation(Operation):
2473 class EWDriftsEstimation(Operation):
2475
2474
2476 def __init__(self):
2475 def __init__(self, **kwargs):
2477 Operation.__init__(self)
2476 Operation.__init__(self, **kwargs)
2478
2477
2479 def __correctValues(self, heiRang, phi, velRadial, SNR):
2478 def __correctValues(self, heiRang, phi, velRadial, SNR):
2480 listPhi = phi.tolist()
2479 listPhi = phi.tolist()
@@ -142,7 +142,7 class SpectraProc(ProcessingUnit):
142 if self.dataIn.flagDataAsBlock:
142 if self.dataIn.flagDataAsBlock:
143 #data dimension: [nChannels, nProfiles, nSamples]
143 #data dimension: [nChannels, nProfiles, nSamples]
144 nVoltProfiles = self.dataIn.data.shape[1]
144 nVoltProfiles = self.dataIn.data.shape[1]
145 # nVoltProfiles = self.dataIn.nProfiles
145 # nVoltProfiles = self.dataIn.nProfiles
146
146
147 if nVoltProfiles == nProfiles:
147 if nVoltProfiles == nProfiles:
148 self.buffer = self.dataIn.data.copy()
148 self.buffer = self.dataIn.data.copy()
@@ -197,7 +197,6 class SpectraProc(ProcessingUnit):
197
197
198 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
198 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex]
199 self.dataOut.pairsList = pairs
199 self.dataOut.pairsList = pairs
200 self.dataOut.pairsIndexList = pairsIndex
201
200
202 return
201 return
203
202
@@ -877,7 +876,6 class IncohInt(Operation):
877 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
876 return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc
878
877
879 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
878 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
880
881 if n==1:
879 if n==1:
882 return
880 return
883
881
@@ -901,4 +899,3 class IncohInt(Operation):
901 dataOut.nIncohInt *= self.n
899 dataOut.nIncohInt *= self.n
902 dataOut.utctime = avgdatatime
900 dataOut.utctime = avgdatatime
903 dataOut.flagNoData = False
901 dataOut.flagNoData = False
904
@@ -1,1 +1,1
1 <Project description="Claire" id="002" name="script02"><ReadUnit datatype="VoltageReader" id="21" inputId="0" name="VoltageReader"><Operation id="211" name="run" priority="1" type="self"><Parameter format="str" id="2111" name="datatype" value="VoltageReader" /><Parameter format="str" id="2112" name="path" value="/media/nanosat/0BDE10E00BDE10E0/CLAIRE" /><Parameter format="date" id="2113" name="startDate" value="2017/07/26" /><Parameter format="date" id="2114" name="endDate" value="2017/07/26" /><Parameter format="time" id="2115" name="startTime" value="15:00:00" /><Parameter format="time" id="2116" name="endTime" value="16:00:00" /><Parameter format="int" id="2118" name="delay" value="30" /><Parameter format="int" id="2119" name="walk" value="1" /><Parameter format="int" id="2120" name="online" value="0" /></Operation><Operation id="212" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="VoltageProc" id="22" inputId="21" name="VoltageProc"><Operation id="221" name="run" priority="1" type="self" /></ProcUnit><ProcUnit datatype="SpectraProc" id="23" inputId="22" name="SpectraProc"><Operation id="231" name="run" priority="1" type="self"><Parameter format="int" id="2311" name="nFFTPoints" value="128" /><Parameter format="int" id="2312" name="nProfiles" value="128" /><Parameter format="pairslist" id="2313" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="232" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="2321" name="frequency" value="445000000.0" /></Operation><Operation id="233" name="IncohInt" priority="3" type="other"><Parameter format="float" id="2331" name="timeInterval" value="128" /></Operation><Operation id="234" name="removeDC" priority="4" type="self"><Parameter format="int" id="2341" name="mode" value="2" /></Operation><Operation id="235" name="RTIPlot" priority="5" type="other"><Parameter format="int" id="2351" name="id" value="237" /><Parameter format="float" id="2352" name="xmin" value="9.0" /><Parameter format="float" id="2353" name="xmax" value="16.0" /><Parameter format="float" id="2354" name="zmin" value="15.0" /><Parameter format="float" id="2355" name="zmax" value="50.0" /></Operation></ProcUnit></Project> No newline at end of file
1 <Project description="Claire" id="002" name="script02"><ReadUnit datatype="VoltageReader" id="21" inputId="0" name="VoltageReader"><Operation id="211" name="run" priority="1" type="self"><Parameter format="str" id="2111" name="datatype" value="VoltageReader" /><Parameter format="str" id="2112" name="path" value="/media/nanosat/0BDE10E00BDE10E0/CLAIRE" /><Parameter format="date" id="2113" name="startDate" value="2017/07/26" /><Parameter format="date" id="2114" name="endDate" value="2017/07/26" /><Parameter format="time" id="2115" name="startTime" value="15:00:00" /><Parameter format="time" id="2116" name="endTime" value="16:00:00" /><Parameter format="int" id="2118" name="delay" value="30" /><Parameter format="int" id="2119" name="walk" value="1" /><Parameter format="int" id="2120" name="online" value="0" /></Operation><Operation id="212" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="VoltageProc" id="22" inputId="21" name="VoltageProc"><Operation id="221" name="run" priority="1" type="self" /></ProcUnit><ProcUnit datatype="SpectraProc" id="23" inputId="22" name="SpectraProc"><Operation id="231" name="run" priority="1" type="self"><Parameter format="int" id="2311" name="nFFTPoints" value="128" /><Parameter format="int" id="2312" name="nProfiles" value="128" /><Parameter format="pairslist" id="2313" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="232" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="2321" name="frequency" value="445000000.0" /></Operation><Operation id="233" name="IncohInt" priority="3" type="other"><Parameter format="float" id="2331" name="timeInterval" value="128" /></Operation><Operation id="234" name="removeDC" priority="4" type="self"><Parameter format="int" id="2341" name="mode" value="2" /></Operation><Operation id="235" name="RTIPlot" priority="5" type="other"><Parameter format="int" id="2351" name="id" value="237" /><Parameter format="float" id="2352" name="xmin" value="9.0" /><Parameter format="float" id="2353" name="xmax" value="16.0" /><Parameter format="float" id="2354" name="zmin" value="15.0" /><Parameter format="float" id="2355" name="zmax" value="50.0" /></Operation></ProcUnit></Project>
@@ -17,6 +17,7 SCHAINPY - LOG
17
17
18 import click
18 import click
19
19
20
20 def warning(message, tag='Warning'):
21 def warning(message, tag='Warning'):
21 click.echo(click.style('[{}] {}'.format(tag, message), fg='yellow'))
22 click.echo(click.style('[{}] {}'.format(tag, message), fg='yellow'))
22 pass
23 pass
@@ -39,6 +40,6 def log(message, tag='Info'):
39
40
40 def makelogger(tag, bg='reset', fg='reset'):
41 def makelogger(tag, bg='reset', fg='reset'):
41 def func(message):
42 def func(message):
42 click.echo(click.style('[{}] {}'.format(tag.upper(), message),
43 click.echo(click.style('[{}] {}'.format(
43 bg=bg, fg=fg))
44 tag.upper(), message), bg=bg, fg=fg))
44 return func
45 return func
@@ -8,6 +8,7 from setuptools import setup, Extension
8 from setuptools.command.build_ext import build_ext as _build_ext
8 from setuptools.command.build_ext import build_ext as _build_ext
9 from schainpy import __version__
9 from schainpy import __version__
10
10
11
11 class build_ext(_build_ext):
12 class build_ext(_build_ext):
12 def finalize_options(self):
13 def finalize_options(self):
13 _build_ext.finalize_options(self)
14 _build_ext.finalize_options(self)
@@ -23,7 +24,7 setup(name="schainpy",
23 author="Miguel Urco",
24 author="Miguel Urco",
24 author_email="miguel.urco@jro.igp.gob.pe",
25 author_email="miguel.urco@jro.igp.gob.pe",
25 url="http://jro.igp.gob.pe",
26 url="http://jro.igp.gob.pe",
26 packages = {'schainpy',
27 packages={'schainpy',
27 'schainpy.model',
28 'schainpy.model',
28 'schainpy.model.data',
29 'schainpy.model.data',
29 'schainpy.model.graphics',
30 'schainpy.model.graphics',
@@ -39,31 +40,30 setup(name="schainpy",
39 ext_package='schainpy',
40 ext_package='schainpy',
40 py_modules=[''],
41 py_modules=[''],
41 package_data={'': ['schain.conf.template'],
42 package_data={'': ['schain.conf.template'],
42 'schainpy.gui.figures': ['*.png','*.jpg'],
43 'schainpy.gui.figures': ['*.png', '*.jpg'],
43 },
44 },
44 include_package_data=False,
45 include_package_data=False,
45 scripts =['schainpy/gui/schainGUI'],
46 scripts=['schainpy/gui/schainGUI'],
46 ext_modules=[
47 ext_modules=[
47 Extension("cSchain", ["schainpy/model/proc/extensions.c"]
48 Extension("cSchain", ["schainpy/model/proc/extensions.c"]
48 )],
49 )],
49 entry_points={
50 entry_points={
50 'console_scripts': [
51 'console_scripts': [
51 'schain = schaincli.cli:main',
52 'schain = schaincli.cli:main',
52 ],
53 ],
53 },
54 },
54 cmdclass={'build_ext':build_ext},
55 cmdclass={'build_ext': build_ext},
55 setup_requires=["numpy >= 1.11.2"],
56 setup_requires=["numpy >= 1.11.2"],
56 install_requires=[
57 install_requires=[
57 "scipy >= 0.14.0",
58 "scipy >= 0.14.0",
58 "h5py >= 2.2.1",
59 "h5py >= 2.2.1",
59 "matplotlib >= 1.4.2",
60 "matplotlib >= 1.4.2",
60 "pyfits >= 3.4",
61 "pyfits >= 3.4",
61 "paramiko >= 2.1.2",
62 "paramiko >= 2.1.2",
62 "paho-mqtt >= 1.2",
63 "paho-mqtt >= 1.2",
63 "zmq",
64 "zmq",
64 "fuzzywuzzy",
65 "fuzzywuzzy",
65 "click",
66 "click",
66 "colorama",
67 "python-Levenshtein"
67 "python-Levenshtein"
68 ],
68 ],
69 )
69 )
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