##// 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
114 *.log
113 .vscode
115 trash
114 trash
115 *.log
@@ -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 ####################
43 plotter = Project()
44 plotter.setup(id='100', name='receiver', description=desc)
45
46 receiver_plot = plotter.addProcUnit(name='PlotterReceiver')
47 receiver_plot.addParameter(name='throttle', value=20, format='int')
48 receiver_plot.addParameter(name='plottypes', value='rti', format='str')
49
50 rti = receiver_plot.addOperation(name='PlotRTIData', optype='other')
51 rti.addParameter(name='zmin', value='-40.0', format='float')
52 rti.addParameter(name='zmax', value='100.0', format='float')
53 rti.addParameter(name='decimation', value='200', format='int')
54 rti.addParameter(name='xmin', value='0.0', format='int')
55 rti.addParameter(name='colormap', value='jet', format='str')
56
57 plotter.start()
44
58
45 readUnitConf = controller.addReadUnit(datatype='SpectraReader',
59 sleep(2)
60
61 ################
62 # DATA EMITTER #
63 ################
64 project = Project()
65 project.setup(id='200', name="{name}", description=desc)
66
67 spectra_reader = project.addReadUnit(datatype='SpectraReader',
46 path="{path}",
68 path="{path}",
47 startDate=day,
69 startDate={startDate},
48 endDate=day,
70 endDate={endDate},
49 startTime="{startHour}",
71 startTime="{startHour}",
50 endTime="{endHour}",
72 endTime="{endHour}",
51 online=0,
73 online=0,
52 queue=q,
53 cursor=cursor,
54 skip=skip,
55 verbose=1,
74 verbose=1,
56 walk=1,
75 walk=1,
57 )
76 )
58
77
59 procUnitConf1 = controller.addProcUnit(datatype='Spectra', inputId=readUnitConf.getId())
78 spectra_proc = project.addProcUnit(datatype='Spectra', inputId=spectra_reader.getId())
60
61 procUnitConf2 = controller.addProcUnit(datatype='ParametersProc', inputId=readUnitConf.getId())
62 opObj11 = procUnitConf2.addOperation(name='SpectralMoments', optype='other')
63
79
64 opObj12 = procUnitConf2.addOperation(name='PublishData', optype='other')
80 parameters_proc = project.addProcUnit(datatype='ParametersProc', inputId=spectra_proc.getId())
65 opObj12.addParameter(name='zeromq', value=1, format='int')
81 moments = parameters_proc.addOperation(name='SpectralMoments', optype='other')
66 opObj12.addParameter(name='verbose', value=0, format='bool')
67
68 controller.start()
69
82
83 publish = parameters_proc.addOperation(name='PublishData', optype='other')
84 publish.addParameter(name='zeromq', value=1, format='int')
85 publish.addParameter(name='verbose', value=0, format='bool')
70
86
71 if __name__ == '__main__':
87 MPProject(project, 16)
72 multiSchain(fiber, nProcess={nProcess}, startDate="{startDate}", endDate="{endDate}")
73
88
74
89
75 '''
90 '''
@@ -1,7 +1,7
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.
@@ -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
@@ -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
@@ -261,6 +263,7 class ParameterConf():
261
263
262 print 'Parameter[%s]: name = %s, value = %s, format = %s' %(self.id, self.name, self.value, self.format)
264 print 'Parameter[%s]: name = %s, value = %s, format = %s' % (self.id, self.name, self.value, self.format)
263
265
266
264 class OperationConf():
267 class OperationConf():
265
268
266 id = None
269 id = None
@@ -279,7 +282,6 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
@@ -337,7 +339,6 class OperationConf():
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 = {}
@@ -440,7 +441,6 class OperationConf():
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
@@ -505,7 +505,6 class ProcUnitConf():
505
505
506 def updateId(self, new_id, parentId=parentId):
506 def updateId(self, new_id, parentId=parentId):
507
507
508
509 new_id = int(parentId)*10 + (int(self.id) % 10)
508 new_id = int(parentId) * 10 + (int(self.id) % 10)
510 new_inputId = int(parentId)*10 + (int(self.inputId) % 10)
509 new_inputId = int(parentId) * 10 + (int(self.inputId) % 10)
511
510
@@ -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
@@ -659,7 +657,6 class ProcUnitConf():
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]
@@ -678,7 +675,8 class ProcUnitConf():
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)
@@ -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
@@ -757,7 +756,6 class ReadUnitConf(ProcUnitConf):
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
@@ -795,7 +793,8 class ReadUnitConf(ProcUnitConf):
795 self.name = '%sReader' %(datatype)
793 self.name = '%sReader' % (datatype)
796 self.datatype = self.name.replace('Reader', '')
794 self.datatype = self.name.replace('Reader', '')
797
795
798 attrs = ('path', 'startDate', 'endDate', 'startTime', 'endTime', 'parentId')
796 attrs = ('path', 'startDate', 'endDate',
797 'startTime', 'endTime', 'parentId')
799
798
800 for attr in attrs:
799 for attr in attrs:
801 if attr in kwargs:
800 if attr in kwargs:
@@ -816,19 +815,24 class ReadUnitConf(ProcUnitConf):
816 opObj = self.addOperation(name = 'run', optype = 'self')
815 opObj = self.addOperation(name='run', optype='self')
817
816
818 if self.server is None:
817 if self.server is None:
819 opObj.addParameter(name='datatype', value=self.datatype, format='str')
818 opObj.addParameter(
819 name='datatype', value=self.datatype, format='str')
820 opObj.addParameter(name='path', value=self.path, format='str')
820 opObj.addParameter(name='path', value=self.path, format='str')
821 opObj.addParameter(name='startDate', value=self.startDate, format='date')
821 opObj.addParameter(
822 opObj.addParameter(name='endDate', value=self.endDate, format='date')
822 name='startDate', value=self.startDate, format='date')
823 opObj.addParameter(name='startTime', value=self.startTime, format='time')
823 opObj.addParameter(
824 opObj.addParameter(name='endTime', value=self.endTime, format='time')
824 name='endDate', value=self.endDate, format='date')
825 opObj.addParameter(
826 name='startTime', value=self.startTime, format='time')
827 opObj.addParameter(
828 name='endTime', value=self.endTime, format='time')
825
829
826 for key, value in kwargs.items():
830 for key, value in kwargs.items():
827 opObj.addParameter(name=key, value=value, format=type(value).__name__)
831 opObj.addParameter(name=key, value=value,
832 format=type(value).__name__)
828 else:
833 else:
829 opObj.addParameter(name='server' , value=self.server, format='str')
834 opObj.addParameter(name='server', value=self.server, format='str')
830
835
831
832 return opObj
836 return opObj
833
837
834 def updateRunOperation(self, **kwargs):
838 def updateRunOperation(self, **kwargs):
@@ -838,13 +842,16 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
@@ -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
@@ -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
@@ -1101,7 +1111,8 class Project(Process):
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()
@@ -1181,10 +1193,13 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)
1201 subtitle += 'Hostname: %s\n' % socket.gethostbyname(
1202 socket.gethostname())
1188 subtitle += 'Working directory: %s\n' %os.path.abspath('./')
1203 subtitle += 'Working directory: %s\n' % os.path.abspath('./')
1189 subtitle += 'Configuration file: %s\n' %self.filename
1204 subtitle += 'Configuration file: %s\n' % self.filename
1190 subtitle += 'Time: %s\n' %str(datetime.datetime.now())
1205 subtitle += 'Time: %s\n' % str(datetime.datetime.now())
@@ -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 *
@@ -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
@@ -83,6 +84,24 class Header(object):
83
84
84 raise NotImplementedError
85 raise NotImplementedError
85
86
87 def getAllowedArgs(self):
88 args = inspect.getargspec(self.__init__).args
89 try:
90 args.remove('self')
91 except:
92 pass
93 return args
94
95 def getAsDict(self):
96 args = self.getAllowedArgs()
97 asDict = {}
98 for x in args:
99 asDict[x] = self[x]
100 return asDict
101
102 def __getitem__(self, name):
103 return getattr(self, name)
104
86 def printInfo(self):
105 def printInfo(self):
87
106
88 message = "#"*50 + "\n"
107 message = "#"*50 + "\n"
@@ -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,15 +209,16 class SystemHeader(Header):
189 nChannels = None
209 nChannels = None
190 adcResolution = None
210 adcResolution = None
191 pciDioBusWidth = None
211 pciDioBusWidth = None
212 structure = SYSTEM_STRUCTURE
192
213
193 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
214 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0):
194
215
195 self.size = 24
216 self.size = 24
196 self.nSamples = nSamples
217 self.nSamples = nSamples
197 self.nProfiles = nProfiles
218 self.nProfiles = nProfiles
198 self.nChannels = nChannels
219 self.nChannels = nChannels
199 self.adcResolution = adcResolution
220 self.adcResolution = adcResolution
200 self.pciDioBusWidth = pciDioBusWith
221 self.pciDioBusWidth = pciDioBusWidth
201
222
202 def read(self, fp):
223 def read(self, fp):
203 self.length = 0
224 self.length = 0
@@ -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:
@@ -13,8 +13,8 class CorrelationPlot(Figure):
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
@@ -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')]
@@ -354,6 +356,8 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
359 ystep = 200 if ymax >= 800 else 100 if ymax >= 400 else 50 if ymax >= 200 else 20
360
357 for n, ax in enumerate(self.axes):
361 for n, ax in enumerate(self.axes):
358 if ax.firsttime:
362 if ax.firsttime:
359 ax.set_facecolor(self.bgcolor)
363 ax.set_facecolor(self.bgcolor)
@@ -370,7 +374,8 class PlotData(Operation, Process):
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)
@@ -438,7 +443,8 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
@@ -474,6 +480,7 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
@@ -531,7 +538,8 class PlotSpectraData(PlotData):
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':
@@ -628,7 +636,8 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:
@@ -667,7 +676,8 class PlotRTIData(PlotData):
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
@@ -686,7 +696,8 class PlotRTIData(PlotData):
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:
@@ -698,7 +709,8 class PlotRTIData(PlotData):
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
@@ -718,10 +730,12 class PlotCOHData(PlotRTIData):
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):
@@ -813,13 +827,14 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(
837 [self.data['param'][t] for t in self.times])
823 error = arrayParameters[:,-1]
838 error = arrayParameters[:, -1]
824 indValid = numpy.where(error == 0)[0]
839 indValid = numpy.where(error == 0)[0]
825 finalMeteor = arrayParameters[indValid,:]
840 finalMeteor = arrayParameters[indValid, :]
@@ -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
@@ -20,8 +20,9 class SpectraHeisScope(Figure):
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
@@ -179,8 +180,8 class RTIfromSpectraHeis(Figure):
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
@@ -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,7 +4,7 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')
@@ -21,15 +21,19 from matplotlib.ticker import FuncFormatter, LinearLocator
21 # create jro colormap
21 # create jro colormap
22
22
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
23 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
24 blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15]
24 blu_values = matplotlib.pyplot.get_cmap(
25 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values)))
25 "seismic_r", 20)(numpy.arange(20))[10:15]
26 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
27 "jro", numpy.vstack((blu_values, jet_values)))
26 matplotlib.pyplot.register_cmap(cmap=ncmap)
28 matplotlib.pyplot.register_cmap(cmap=ncmap)
27
29
30
28 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80):
31 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80):
29
32
30 matplotlib.pyplot.ioff()
33 matplotlib.pyplot.ioff()
31
34
32 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi))
35 fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(
36 1.0 * width / dpi, 1.0 * height / dpi))
33 fig.canvas.manager.set_window_title(wintitle)
37 fig.canvas.manager.set_window_title(wintitle)
34 # fig.canvas.manager.resize(width, height)
38 # fig.canvas.manager.resize(width, height)
35 matplotlib.pyplot.ion()
39 matplotlib.pyplot.ion()
@@ -39,6 +43,7 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()
@@ -60,24 +65,29 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()
@@ -88,11 +98,10 def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False):
88 rowspan=rowspan,
98 rowspan=rowspan,
89 polar=polar)
99 polar=polar)
90
100
91 axes.grid(True)
92
93 matplotlib.pyplot.ion()
101 matplotlib.pyplot.ion()
94 return axes
102 return axes
95
103
104
96 def setAxesText(ax, text):
105 def setAxesText(ax, text):
97
106
98 ax.annotate(text,
107 ax.annotate(text,
@@ -102,17 +111,18 def setAxesText(ax, text):
102 verticalalignment = 'top',
111 verticalalignment='top',
103 fontsize = 10)
112 fontsize=10)
104
113
114
105 def printLabels(ax, xlabel, ylabel, title):
115 def printLabels(ax, xlabel, ylabel, title):
106
116
107 ax.set_xlabel(xlabel, size=11)
117 ax.set_xlabel(xlabel, size=11)
108 ax.set_ylabel(ylabel, size=11)
118 ax.set_ylabel(ylabel, size=11)
109 ax.set_title(title, size=8)
119 ax.set_title(title, size=8)
110
120
121
111 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
122 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='',
112 ticksize=9, xtick_visible=True, ytick_visible=True,
123 ticksize=9, xtick_visible=True, ytick_visible=True,
113 nxticks=4, nyticks=10,
124 nxticks=4, nyticks=10,
114 grid=None,color='blue'):
125 grid=None, color='blue'):
115
116 """
126 """
117
127
118 Input:
128 Input:
@@ -132,7 +142,8 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title=''
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,18 +181,21 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)
176
188
189
177 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
190 def pline(iplot, x, y, xlabel='', ylabel='', title=''):
178
191
179 ax = iplot.get_axes()
192 ax = iplot.axes
180
193
181 printLabels(ax, xlabel, ylabel, title)
194 printLabels(ax, xlabel, ylabel, title)
182
195
183 set_linedata(ax, x, y, idline=0)
196 set_linedata(ax, x, y, idline=0)
184
197
198
185 def addpline(ax, x, y, color, linestyle, lw):
199 def addpline(ax, x, y, color, linestyle, lw):
186
200
187 ax.plot(x,y,color=color,linestyle=linestyle,lw=lw)
201 ax.plot(x, y, color=color, linestyle=linestyle, lw=lw)
@@ -206,7 +220,7 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax,
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)
@@ -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
@@ -277,17 +285,15 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', col
277 z = numpy.ma.masked_invalid(z)
285 z = numpy.ma.masked_invalid(z)
278
286
279 cmap=matplotlib.pyplot.get_cmap(colormap)
287 cmap = matplotlib.pyplot.get_cmap(colormap)
280 cmap.set_bad('white',1.)
288 cmap.set_bad('black', 1.)
281
289
282 ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap)
290 ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap)
283 ax.grid(True)
284
291
285
292
286 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
293 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
287 ticksize=9, xtick_visible=True, ytick_visible=True,
294 ticksize=9, xtick_visible=True, ytick_visible=True,
288 nxticks=4, nyticks=10,
295 nxticks=4, nyticks=10,
289 grid=None):
296 grid=None):
290
291 """
297 """
292
298
293 Input:
299 Input:
@@ -303,7 +309,8 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', tit
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,7 +347,7 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
@@ -348,11 +355,11 def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''):
348 line = ax.lines[i]
355 line = ax.lines[i]
349 line.set_data(x[i,:],y)
356 line.set_data(x[i, :], y)
350
357
358
351 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
359 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None,
352 ticksize=9, xtick_visible=True, ytick_visible=True,
360 ticksize=9, xtick_visible=True, ytick_visible=True,
353 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
361 nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None",
354 grid=None, XAxisAsTime=False):
362 grid=None, XAxisAsTime=False):
355
356 """
363 """
357
364
358 Input:
365 Input:
@@ -369,7 +376,8 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])
@@ -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,15 +424,18 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, :])
426
437
438
427 def createPolar(ax, x, y,
439 def createPolar(ax, x, y,
428 xlabel='', ylabel='', title='', ticksize = 9,
440 xlabel='', ylabel='', title='', ticksize=9,
429 colormap='jet',cblabel='', cbsize="5%",
441 colormap='jet', cblabel='', cbsize="5%",
@@ -438,7 +450,7 def createPolar(ax, x, y,
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,9 +7,7 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
@@ -31,15 +30,20 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(
34 '/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc', "rb")
35
35
36
36
37 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
37 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
38 ('Hname',numpy.str_,32), #Original file name
38 ('Hname', numpy.str_, 32), # Original file name
39 ('Htime',numpy.str_,32), #Date and time when the file was created
39 # Date and time when the file was created
40 ('Hoper',numpy.str_,64), #Name of operator who created the file
40 ('Htime', numpy.str_, 32),
41 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
41 # Name of operator who created the file
42 ('Hdescr',numpy.str_,256), #Description of measurements
42 ('Hoper', numpy.str_, 64),
43 # Place where the measurements was carried out
44 ('Hplace', numpy.str_, 128),
45 # Description of measurements
46 ('Hdescr', numpy.str_, 256),
43 ('Hdummy',numpy.str_,512), #Reserved space
47 ('Hdummy', numpy.str_, 512), # Reserved space
44 #Main chunk
48 # Main chunk
45 ('Msign','<i4'), #Main chunk signature FZKF or NUIG
49 ('Msign', '<i4'), # Main chunk signature FZKF or NUIG
@@ -50,19 +54,28 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
50 ('PPARprf','<i4'), #Pulse repetition frequency
54 ('PPARprf', '<i4'), # Pulse repetition frequency
51 ('PPARpdr','<i4'), #Pulse duration
55 ('PPARpdr', '<i4'), # Pulse duration
52 ('PPARsft','<i4'), #FFT length
56 ('PPARsft', '<i4'), # FFT length
53 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
57 # Number of spectral (in-coherent) averages
54 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
58 ('PPARavc', '<i4'),
55 ('PPARchg','<i4'), #Count for gates for moment estimation
59 # Number of lowest range gate for moment estimation
56 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
60 ('PPARihp', '<i4'),
61 # Count for gates for moment estimation
62 ('PPARchg', '<i4'),
63 # switch on/off polarimetric measurements. Should be 1.
64 ('PPARpol', '<i4'),
57 #Service DSP parameters
65 # Service DSP parameters
58 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
66 # STC attenuation on the lowest ranges on/off
67 ('SPARatt', '<i4'),
59 ('SPARtx','<i4'), #OBSOLETE
68 ('SPARtx', '<i4'), # OBSOLETE
60 ('SPARaddGain0','<f4'), #OBSOLETE
69 ('SPARaddGain0', '<f4'), # OBSOLETE
61 ('SPARaddGain1','<f4'), #OBSOLETE
70 ('SPARaddGain1', '<f4'), # OBSOLETE
62 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
71 # Debug only. It normal mode it is 0.
63 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
72 ('SPARwnd', '<i4'),
64 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
73 # Delay between sync pulse and tx pulse for phase corr, ns
65 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
74 ('SPARpos', '<i4'),
75 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
76 ('SPARadd', '<i4'),
77 # Time for measuring txn pulse phase. OBSOLETE
78 ('SPARlen', '<i4'),
66 ('SPARcal','<i4'), #OBSOLETE
79 ('SPARcal', '<i4'), # OBSOLETE
67 ('SPARnos','<i4'), #OBSOLETE
80 ('SPARnos', '<i4'), # OBSOLETE
68 ('SPARof0','<i4'), #detection threshold
81 ('SPARof0', '<i4'), # detection threshold
@@ -73,19 +86,23 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
73 ('SPARtst','<i4'), #OBSOLETE
86 ('SPARtst', '<i4'), # OBSOLETE
74 ('SPARcor','<i4'), #OBSOLETE
87 ('SPARcor', '<i4'), # OBSOLETE
75 ('SPARofs','<i4'), #OBSOLETE
88 ('SPARofs', '<i4'), # OBSOLETE
76 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
89 # Hildebrand div noise detection on noise gate
77 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
90 ('SPARhsn', '<i4'),
91 # Hildebrand div noise detection on all gates
92 ('SPARhsa', '<f4'),
78 ('SPARcalibPow_M','<f4'), #OBSOLETE
93 ('SPARcalibPow_M', '<f4'), # OBSOLETE
79 ('SPARcalibSNR_M','<f4'), #OBSOLETE
94 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
80 ('SPARcalibPow_S','<f4'), #OBSOLETE
95 ('SPARcalibPow_S', '<f4'), # OBSOLETE
81 ('SPARcalibSNR_S','<f4'), #OBSOLETE
96 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
82 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
97 # Lowest range gate for spectra saving Raw_Gate1 >=5
83 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
98 ('SPARrawGate1', '<i4'),
84 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
99 # Number of range gates with atmospheric signal
100 ('SPARrawGate2', '<i4'),
101 # flag - IQ or spectra saving on/off
102 ('SPARraw', '<i4'),
85 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
103 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
86
104
87
105
88
89 self.Hname= None
106 self.Hname = None
90 self.Htime= None
107 self.Htime = None
91 self.Hoper= None
108 self.Hoper = None
@@ -136,7 +153,6 self.SPARraw=None
136 self.SPARprc=None
153 self.SPARprc = None
137
154
138
155
139
140 header = numpy.fromfile(fp, FILE_HEADER,1)
156 header = numpy.fromfile(fp, FILE_HEADER, 1)
141 ''' numpy.fromfile(file, dtype, count, sep='')
157 ''' numpy.fromfile(file, dtype, count, sep='')
142 file : file or str
158 file : file or str
@@ -207,9 +223,8 SPARraw=header['SPARraw'][0]
207 SPARprc=header['SPARprc'][0]
223 SPARprc = header['SPARprc'][0]
208
224
209
225
210
211 SRVI_STRUCTURE = numpy.dtype([
226 SRVI_STRUCTURE = numpy.dtype([
212 ('frame_cnt','<u4'),#
227 ('frame_cnt', '<u4'),
213 ('time_t','<u4'), #
228 ('time_t', '<u4'), #
214 ('tpow','<f4'), #
229 ('tpow', '<f4'), #
215 ('npw1','<f4'), #
230 ('npw1', '<f4'), #
@@ -225,19 +240,18 SRVI_STRUCTURE = numpy.dtype([
225 ('azivel','<f4'), #
240 ('azivel', '<f4'), #
226 ('elvpos','<f4'), #
241 ('elvpos', '<f4'), #
227 ('elvvel','<f4'), #
242 ('elvvel', '<f4'), #
228 ('northAngle','<f4'), #
243 ('northAngle', '<f4'),
229 ('microsec','<u4'), #
244 ('microsec', '<u4'), #
230 ('azisetvel','<f4'), #
245 ('azisetvel', '<f4'), #
231 ('elvsetpos','<f4'), #
246 ('elvsetpos', '<f4'), #
232 ('RadarConst','<f4'),]) #
247 ('RadarConst', '<f4'), ]) #
233
248
234 JUMP_STRUCTURE = numpy.dtype([
249 JUMP_STRUCTURE = numpy.dtype([
235 ('jump','<u140'),#
250 ('jump', '<u140'),
236 ('SizeOfDataBlock1',numpy.str_,32),#
251 ('SizeOfDataBlock1', numpy.str_, 32),
237 ('jump','<i4'),#
252 ('jump', '<i4'),
238 ('DataBlockTitleSRVI1',numpy.str_,32),#
253 ('DataBlockTitleSRVI1', numpy.str_, 32),
239 ('SizeOfSRVI1','<i4'),])#
254 ('SizeOfSRVI1', '<i4'), ])
240
241
255
242
256
243 #frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
257 # frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
@@ -269,7 +283,6 elvsetpos = elvsetpos
269 RadarConst5 = RadarConst
283 RadarConst5 = RadarConst
270
284
271
285
272
273 #print fp
286 # print fp
274 #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
287 # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
275 #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
288 # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
@@ -283,7 +296,7 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] #
@@ -316,6 +329,3 endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
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
@@ -130,7 +131,8 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
@@ -144,7 +146,6 class BLTRParamReader(JRODataReader, ProcessingUnit):
144 startDate - Select file from this date
146 startDate - Select file from this date
145 enDate - Select file until this date
147 enDate - Select file until this date
146 ext - Extension of the file to read
148 ext - Extension of the file to read
147
148 '''
149 '''
149
150
150 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
151 log.success('Searching files in {} '.format(path), 'BLTRParamReader')
@@ -192,7 +193,8 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
@@ -308,7 +310,8 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
@@ -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.
@@ -43,6 +45,7 def isNumber(cad):
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.
@@ -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,7 +124,6 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:
@@ -185,7 +186,6 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime):
185
186
186 #If endTime < startTime then endTime belongs to the next day
187 # If endTime < startTime then endTime belongs to the next day
187
188
188
189 #<<<<<<<<<<<o o>>>>>>>>>>>
189 #<<<<<<<<<<<o o>>>>>>>>>>>
190 #-----------o----------------------------o-----------
190 #-----------o----------------------------o-----------
191 # endTime startTime
191 # endTime startTime
@@ -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.
@@ -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.
@@ -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)
@@ -302,7 +305,8 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]
@@ -317,6 +321,7 def getFileFromSet(path, ext, set):
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"
@@ -359,6 +364,7 def getlastFileFromPath(path, ext):
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,
@@ -400,12 +406,16 def checkForRealPath(path, foldercounter, year, doy, set, ext):
400 if prefixDir != None:
406 if prefixDir != None:
401 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
407 # formo el nombre del directorio xYYYYDDD (x=d o x=D)
402 if foldercounter == 0:
408 if foldercounter == 0:
403 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
409 thispath = os.path.join(path, "%s%04d%03d" %
410 (prefixDir, year, doy))
404 else:
411 else:
405 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
412 thispath = os.path.join(path, "%s%04d%03d_%02d" % (
413 prefixDir, year, doy, foldercounter))
406 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
414 for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D"
407 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
415 # formo el nombre del file xYYYYDDDSSS.ext
408 fullfilename = os.path.join( thispath, filename ) #formo el path completo
416 filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext)
417 fullfilename = os.path.join(
418 thispath, filename) # formo el path completo
409
419
410 if os.path.exists( fullfilename ): #verifico que exista
420 if os.path.exists(fullfilename): # verifico que exista
411 find_flag = True
421 find_flag = True
@@ -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,6 +438,7 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])
@@ -437,6 +449,7 def isRadarFile(file):
437
449
438 return 1
450 return 1
439
451
452
440 def getDateFromRadarFile(file):
453 def getDateFromRadarFile(file):
441 try:
454 try:
442 year = int(file[1:5])
455 year = int(file[1:5])
@@ -448,6 +461,7 def getDateFromRadarFile(file):
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])
@@ -458,6 +472,7 def getDateFromRadarFolder(folder):
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
@@ -579,7 +595,6 class JRODataReader(JRODataIO):
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
@@ -619,7 +633,8 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 [], []
@@ -644,7 +659,8 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
@@ -656,7 +672,8 class JRODataReader(JRODataIO):
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
@@ -680,7 +697,6 class JRODataReader(JRODataIO):
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.
@@ -727,10 +743,10 class JRODataReader(JRODataIO):
727 dirList = sorted( dirList, key=str.lower )
743 dirList = sorted(dirList, key=str.lower)
728
744
729 doypath = dirList[-1]
745 doypath = dirList[-1]
730 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
746 foldercounter = int(doypath.split('_')[1]) if len(
747 doypath.split('_')) > 1 else 0
731 fullpath = os.path.join(path, doypath, expLabel)
748 fullpath = os.path.join(path, doypath, expLabel)
732
749
733
734 print "[Reading] %s folder was found: " %(fullpath )
750 print "[Reading] %s folder was found: " % (fullpath)
735
751
736 if set == None:
752 if set == None:
@@ -814,14 +830,16 class JRODataReader(JRODataIO):
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
@@ -835,7 +853,8 class JRODataReader(JRODataIO):
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,7 +868,8 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
@@ -858,7 +878,8 class JRODataReader(JRODataIO):
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
@@ -928,7 +949,6 class JRODataReader(JRODataIO):
928 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
949 print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)
929 sleep( self.delay )
950 sleep(self.delay)
930
951
931
932 return 0
952 return 0
933
953
934 def waitDataBlock(self,pointer_location):
954 def waitDataBlock(self, pointer_location):
@@ -1022,7 +1042,7 class JRODataReader(JRODataIO):
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
@@ -1043,9 +1063,7 class JRODataReader(JRODataIO):
1043 return 0
1063 return 0
1044
1064
1045 self.getBasicHeader()
1065 self.getBasicHeader()
1046
1066 if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)):
1047 if not isTimeInRange(self.dataOut.datatime.time(), self.startTime, self.endTime):
1048
1049 print "[Reading] Block No. %d/%d -> %s [Skipping]" %(self.nReadBlocks,
1067 print "[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks,
1050 self.processingHeaderObj.dataBlocksPerFile,
1068 self.processingHeaderObj.dataBlocksPerFile,
1051 self.dataOut.datatime.ctime())
1069 self.dataOut.datatime.ctime())
@@ -1068,7 +1086,8 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:
@@ -1086,7 +1105,9 class JRODataReader(JRODataIO):
1086
1105
1087 self.dtype = datatype_str
1106 self.dtype = datatype_str
1088 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1107 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
1089 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
1108 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \
1109 self.firstHeaderSize + self.basicHeaderSize * \
1110 (self.processingHeaderObj.dataBlocksPerFile - 1)
1090 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1111 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
1091 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1112 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
1092 self.getBlockDimension()
1113 self.getBlockDimension()
@@ -1297,7 +1318,8 class JRODataReader(JRODataIO):
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
@@ -1345,7 +1367,8 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
1371 self.startDate = startDate
1349 #Added-----------------
1372 # Added-----------------
1350 self.selBlocksize = blocksize
1373 self.selBlocksize = blocksize
1351 self.selBlocktime = blocktime
1374 self.selBlocktime = blocktime
@@ -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
@@ -1391,7 +1416,6 class JRODataReader(JRODataIO):
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
@@ -1499,6 +1523,7 class JRODataReader(JRODataIO):
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
@@ -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)
@@ -1649,7 +1670,6 class JRODataWriter(JRODataIO):
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
@@ -1707,7 +1727,8 class JRODataWriter(JRODataIO):
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:
@@ -1720,7 +1741,8 class JRODataWriter(JRODataIO):
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
@@ -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()
@@ -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
@@ -37,7 +37,6 class Header(object):
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
@@ -67,23 +66,23 class Header(object):
67 #print message
66 # print message
68
67
69
68
70
71
72
73 FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes
69 FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes
74 ('FileMgcNumber','<u4'), #0x23020100
70 ('FileMgcNumber', '<u4'), # 0x23020100
75 ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more)
71 # No Of FDT data records in this file (0 or more)
72 ('nFDTdataRecors', '<u4'),
76 ('OffsetStartHeader','<u4'),
73 ('OffsetStartHeader', '<u4'),
77 ('RadarUnitId','<u4'),
74 ('RadarUnitId', '<u4'),
78 ('SiteName',numpy.str_,32), #Null terminated
75 ('SiteName', numpy.str_, 32), # Null terminated
79 ])
76 ])
80
77
78
81 class FileHeaderBLTR(Header):
79 class FileHeaderBLTR(Header):
82
80
83 def __init__(self):
81 def __init__(self):
84
82
85 self.FileMgcNumber= 0 #0x23020100
83 self.FileMgcNumber = 0 # 0x23020100
86 self.nFDTdataRecors=0 #No Of FDT data records in this file (0 or more)
84 # No Of FDT data records in this file (0 or more)
85 self.nFDTdataRecors = 0
87 self.RadarUnitId= 0
86 self.RadarUnitId = 0
88 self.OffsetStartHeader=0
87 self.OffsetStartHeader = 0
89 self.SiteName= ""
88 self.SiteName = ""
@@ -99,7 +98,6 class FileHeaderBLTR(Header):
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,23 +117,20 class FileHeaderBLTR(Header):
119
117
120 '''
118 '''
121
119
122
123
124 self.FileMgcNumber= hex(header['FileMgcNumber'][0])
120 self.FileMgcNumber = hex(header['FileMgcNumber'][0])
125 self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more)
121 # No Of FDT data records in this file (0 or more)
122 self.nFDTdataRecors = int(header['nFDTdataRecors'][0])
126 self.RadarUnitId= int(header['RadarUnitId'][0])
123 self.RadarUnitId = int(header['RadarUnitId'][0])
127 self.OffsetStartHeader= int(header['OffsetStartHeader'][0])
124 self.OffsetStartHeader = int(header['OffsetStartHeader'][0])
128 self.SiteName= str(header['SiteName'][0])
125 self.SiteName = str(header['SiteName'][0])
129
126
130 #print 'Numero de bloques', self.nFDTdataRecors
127 # print 'Numero de bloques', self.nFDTdataRecors
131
128
132
133 if self.size <48:
129 if self.size < 48:
134 return 0
130 return 0
135
131
136 return 1
132 return 1
137
133
138
139 def write(self, fp):
134 def write(self, fp):
140
135
141 headerTuple = (self.FileMgcNumber,
136 headerTuple = (self.FileMgcNumber,
@@ -144,7 +139,6 class FileHeaderBLTR(Header):
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)
@@ -166,56 +160,92 class FileHeaderBLTR(Header):
166 return 1
160 return 1
167
161
168
162
169
170
171
172 RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes
163 RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes
173 ('RecMgcNumber','<u4'), #0x23030001
164 ('RecMgcNumber', '<u4'), # 0x23030001
174 ('RecCounter','<u4'), #Record counter(0,1, ...)
165 ('RecCounter', '<u4'), # Record counter(0,1, ...)
175 ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record
166 # Offset to start of next record form start of this record
176 ('Off2StartData','<u4'), #Offset to start of data from start of this record
167 ('Off2StartNxtRec', '<u4'),
177 ('nUtime','<i4'), #Epoch time stamp of start of acquisition (seconds)
168 # Offset to start of data from start of this record
178 ('nMilisec','<u4'), #Millisecond component of time stamp (0,...,999)
169 ('Off2StartData', '<u4'),
179 ('ExpTagName',numpy.str_,32), #Experiment tag name (null terminated)
170 # Epoch time stamp of start of acquisition (seconds)
180 ('ExpComment',numpy.str_,32), #Experiment comment (null terminated)
171 ('nUtime', '<i4'),
181 ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North)
172 # Millisecond component of time stamp (0,...,999)
182 ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East)
173 ('nMilisec', '<u4'),
183 ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
174 # Experiment tag name (null terminated)
175 ('ExpTagName', numpy.str_, 32),
176 # Experiment comment (null terminated)
177 ('ExpComment', numpy.str_, 32),
178 # Site latitude (from GPS) in degrees (positive implies North)
179 ('SiteLatDegrees', '<f4'),
180 # Site longitude (from GPS) in degrees (positive implies East)
181 ('SiteLongDegrees', '<f4'),
182 # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE)
183 ('RTCgpsStatus', '<u4'),
184 ('TransmitFrec','<u4'), #Transmit frequency (Hz)
184 ('TransmitFrec', '<u4'), # Transmit frequency (Hz)
185 ('ReceiveFrec','<u4'), #Receive frequency
185 ('ReceiveFrec', '<u4'), # Receive frequency
186 ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz)
186 # First local oscillator frequency (Hz)
187 ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2")
187 ('FirstOsciFrec', '<u4'),
188 ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3)
188 # (0="O", 1="E", 2="linear 1", 3="linear2")
189 ('nModesInUse','<u4'), #Number of modes in use (1 or 2)
189 ('Polarisation', '<u4'),
190 ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1)
190 # Receiver filter settings (0,1,2,3)
191 ('DualModeRange','<u4'), #Dual Mode range correction for these data (m)
191 ('ReceiverFiltSett', '<u4'),
192 ('nDigChannels','<u4'), #Number of digital channels acquired (2*N)
192 # Number of modes in use (1 or 2)
193 ('SampResolution','<u4'), #Sampling resolution (meters)
193 ('nModesInUse', '<u4'),
194 ('nHeights','<u4'), #Number of range gates sampled
194 # Dual Mode index number for these data (0 or 1)
195 ('StartRangeSamp','<u4'), #Start range of sampling (meters)
195 ('DualModeIndex', '<u4'),
196 # Dual Mode range correction for these data (m)
197 ('DualModeRange', '<u4'),
198 # Number of digital channels acquired (2*N)
199 ('nDigChannels', '<u4'),
200 # Sampling resolution (meters)
201 ('SampResolution', '<u4'),
202 # Number of range gates sampled
203 ('nHeights', '<u4'),
204 # Start range of sampling (meters)
205 ('StartRangeSamp', '<u4'),
196 ('PRFhz','<u4'), #PRF (Hz)
206 ('PRFhz', '<u4'), # PRF (Hz)
197 ('nCohInt','<u4'), #Integrations
207 ('nCohInt', '<u4'), # Integrations
198 ('nProfiles','<u4'), #Number of data points transformed
208 # Number of data points transformed
199 ('nChannels','<u4'), #Number of receive beams stored in file (1 or N)
209 ('nProfiles', '<u4'),
210 # Number of receive beams stored in file (1 or N)
211 ('nChannels', '<u4'),
200 ('nIncohInt','<u4'), #Number of spectral averages
212 ('nIncohInt', '<u4'), # Number of spectral averages
201 ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window)
213 # FFT windowing index (0 = no window)
202 ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North)
214 ('FFTwindowingInd', '<u4'),
203 ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical)
215 # Beam steer angle (azimuth) in degrees (clockwise from true North)
204 ('AntennaCoord0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
216 ('BeamAngleAzim', '<f4'),
205 ('AntennaAngl0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
217 # Beam steer angle (zenith) in degrees (0=> vertical)
206 ('AntennaCoord1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
218 ('BeamAngleZen', '<f4'),
207 ('AntennaAngl1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
219 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
208 ('AntennaCoord2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
220 ('AntennaCoord0', '<f4'),
209 ('AntennaAngl2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
221 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
210 ('RecPhaseCalibr0','<f4'), #Receiver phase calibration (degrees) - N values
222 ('AntennaAngl0', '<f4'),
211 ('RecPhaseCalibr1','<f4'), #Receiver phase calibration (degrees) - N values
223 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
212 ('RecPhaseCalibr2','<f4'), #Receiver phase calibration (degrees) - N values
224 ('AntennaCoord1', '<f4'),
213 ('RecAmpCalibr0','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
225 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
214 ('RecAmpCalibr1','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
226 ('AntennaAngl1', '<f4'),
215 ('RecAmpCalibr2','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values
227 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
216 ('ReceiverGaindB0','<i4'), #Receiver gains in dB - N values
228 ('AntennaCoord2', '<f4'),
217 ('ReceiverGaindB1','<i4'), #Receiver gains in dB - N values
229 # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs
218 ('ReceiverGaindB2','<i4'), #Receiver gains in dB - N values
230 ('AntennaAngl2', '<f4'),
231 # Receiver phase calibration (degrees) - N values
232 ('RecPhaseCalibr0', '<f4'),
233 # Receiver phase calibration (degrees) - N values
234 ('RecPhaseCalibr1', '<f4'),
235 # Receiver phase calibration (degrees) - N values
236 ('RecPhaseCalibr2', '<f4'),
237 # Receiver amplitude calibration (ratio relative to receiver one) - N values
238 ('RecAmpCalibr0', '<f4'),
239 # Receiver amplitude calibration (ratio relative to receiver one) - N values
240 ('RecAmpCalibr1', '<f4'),
241 # Receiver amplitude calibration (ratio relative to receiver one) - N values
242 ('RecAmpCalibr2', '<f4'),
243 # Receiver gains in dB - N values
244 ('ReceiverGaindB0', '<i4'),
245 # Receiver gains in dB - N values
246 ('ReceiverGaindB1', '<i4'),
247 # Receiver gains in dB - N values
248 ('ReceiverGaindB2', '<i4'),
219 ])
249 ])
220
250
221
251
@@ -285,12 +315,11 class RecordHeaderBLTR(Header):
285 self.ReceiverGaindB2 = ReceiverGaindB2
315 self.ReceiverGaindB2 = ReceiverGaindB2
286 self.OffsetStartHeader = 48
316 self.OffsetStartHeader = 48
287
317
288
289
290 def RHread(self, fp):
318 def RHread(self, fp):
291 #print fp
319 # print fp
292 #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
320 # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file.
293 startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file.
321 # The method tell() returns the current position of the file read/write pointer within the file.
322 startFp = open(fp, "rb")
294 #RecCounter=0
323 # RecCounter=0
295 #Off2StartNxtRec=811248
324 # Off2StartNxtRec=811248
296 OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec
325 OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec
@@ -298,7 +327,6 class RecordHeaderBLTR(Header):
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 ' '
@@ -416,11 +444,13 class RecordHeaderBLTR(Header):
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
@@ -436,7 +466,6 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
436 walk = None
466 walk = None
437 isConfig = False
467 isConfig = False
438
468
439
440 fileList= None
469 fileList = None
441
470
442 #metadata
471 # metadata
@@ -448,8 +477,6 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
448 data= None
477 data = None
449 utctime= None
478 utctime = None
450
479
451
452
453 def __init__(self, **kwargs):
480 def __init__(self, **kwargs):
454
481
455 #Eliminar de la base la herencia
482 # Eliminar de la base la herencia
@@ -494,8 +521,6 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
494 self.dataOut.velocityY=[]
521 self.dataOut.velocityY = []
495 self.dataOut.velocityV=[]
522 self.dataOut.velocityV = []
496
523
497
498
499 def Files2Read(self, fp):
524 def Files2Read(self, fp):
500 '''
525 '''
501 Function that indicates the number of .fdt files that exist in the folder to be read.
526 Function that indicates the number of .fdt files that exist in the folder to be read.
@@ -503,8 +528,10 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
503 '''
528 '''
504 #self.__checkPath()
529 # self.__checkPath()
505
530
506 ListaData=os.listdir(fp) #Gets the list of files within the fp address
531 # Gets the list of files within the fp address
507 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
532 ListaData = os.listdir(fp)
533 # Sort the list of files from least to largest by names
534 ListaData = sorted(ListaData)
508 nFiles=0 #File Counter
535 nFiles = 0 # File Counter
509 FileList=[] #A list is created that will contain the .fdt files
536 FileList = [] # A list is created that will contain the .fdt files
510 for IndexFile in ListaData :
537 for IndexFile in ListaData:
@@ -517,7 +544,6 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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.
@@ -531,7 +557,6 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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,
@@ -556,7 +581,6 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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,
@@ -583,7 +607,6 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
583 #self.removeDC()
607 # self.removeDC()
584 return self.dataOut.data_spc
608 return self.dataOut.data_spc
585
609
586
587 def readFile(self,fp):
610 def readFile(self, fp):
588 '''
611 '''
589 You must indicate if you are reading in Online or Offline mode and load the
612 You must indicate if you are reading in Online or Offline mode and load the
@@ -600,7 +623,8 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
600
623
601 if self.fileSelector < len(self.filenameList):
624 if self.fileSelector < len(self.filenameList):
602
625
603 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
626 self.fpFile = str(fp) + '/' + \
627 str(self.filenameList[self.fileSelector])
604 #print self.fpFile
628 # print self.fpFile
605 fheader = FileHeaderBLTR()
629 fheader = FileHeaderBLTR()
606 fheader.FHread(self.fpFile) #Bltr FileHeader Reading
630 fheader.FHread(self.fpFile) # Bltr FileHeader Reading
@@ -615,12 +639,15 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
615
639
616 def getVelRange(self, extrapoints=0):
640 def getVelRange(self, extrapoints=0):
617 Lambda= SPEED_OF_LIGHT/50000000
641 Lambda = SPEED_OF_LIGHT / 50000000
618 PRF = self.dataOut.PRF#1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
642 # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt)
643 PRF = self.dataOut.PRF
619 Vmax=-Lambda/(4.*(1./PRF)*self.dataOut.nCohInt*2.)
644 Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.)
620 deltafreq = PRF / (self.nProfiles)
645 deltafreq = PRF / (self.nProfiles)
621 deltavel = (Vmax*2) / (self.nProfiles)
646 deltavel = (Vmax * 2) / (self.nProfiles)
622 freqrange = deltafreq*(numpy.arange(self.nProfiles)-self.nProfiles/2.) - deltafreq/2
647 freqrange = deltafreq * \
623 velrange = deltavel*(numpy.arange(self.nProfiles)-self.nProfiles/2.)
648 (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2
649 velrange = deltavel * \
650 (numpy.arange(self.nProfiles) - self.nProfiles / 2.)
624 return velrange
651 return velrange
625
652
626 def readBlock(self):
653 def readBlock(self):
@@ -661,7 +688,8 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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
@@ -671,8 +699,10 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
671 self.dataOut.nFFTPoints=rheader.nProfiles
699 self.dataOut.nFFTPoints = rheader.nProfiles
672 self.dataOut.utctime=rheader.nUtime
700 self.dataOut.utctime = rheader.nUtime
673 self.dataOut.timeZone=0
701 self.dataOut.timeZone = 0
674 self.dataOut.normFactor= self.dataOut.nProfiles*self.dataOut.nIncohInt*self.dataOut.nCohInt
702 self.dataOut.normFactor = self.dataOut.nProfiles * \
675 self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
703 self.dataOut.nIncohInt * self.dataOut.nCohInt
704 self.dataOut.outputInterval = self.dataOut.ippSeconds * \
705 self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles
676
706
677 self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN
707 self.data_output = numpy.ones([3, rheader.nHeights]) * numpy.NaN
678 print 'self.data_output', shape(self.data_output)
708 print 'self.data_output', shape(self.data_output)
@@ -686,7 +716,8 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
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):
@@ -705,27 +736,26 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
705 y = rho * numpy.sin(phi)
736 y = rho * numpy.sin(phi)
706 return(x, y)
737 return(x, y)
707
738
708
709
710
711 if self.DualModeIndex==self.ReadMode:
739 if self.DualModeIndex == self.ReadMode:
712
740
713 self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights )
741 self.data_fft = numpy.fromfile(
742 startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights)
714
743
715 self.data_fft=self.data_fft.astype(numpy.dtype('complex'))
744 self.data_fft = self.data_fft.astype(numpy.dtype('complex'))
716
745
717 self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles ))
746 self.data_block = numpy.reshape(
747 self.data_fft, (self.nHeights, self.nChannels, self.nProfiles))
718
748
719 self.data_block = numpy.transpose(self.data_block, (1,2,0))
749 self.data_block = numpy.transpose(self.data_block, (1, 2, 0))
720
750
721 copy = self.data_block.copy()
751 copy = self.data_block.copy()
722 spc = copy * numpy.conjugate(copy)
752 spc = copy * numpy.conjugate(copy)
723
753
724 self.data_spc = numpy.absolute(spc) # valor absoluto o magnitud
754 self.data_spc = numpy.absolute(
755 spc) # valor absoluto o magnitud
725
756
726 factor = self.dataOut.normFactor
757 factor = self.dataOut.normFactor
727
758
728
729 z = self.data_spc.copy()#/factor
759 z = self.data_spc.copy() # /factor
730 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
760 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
731 #zdB = 10*numpy.log10(z)
761 #zdB = 10*numpy.log10(z)
@@ -737,13 +767,14 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
737
767
738 self.dataOut.data_spc=self.data_spc
768 self.dataOut.data_spc = self.data_spc
739
769
740 self.noise = self.dataOut.getNoise(ymin_index=80, ymax_index=132)#/factor
770 self.noise = self.dataOut.getNoise(
771 ymin_index=80, ymax_index=132) # /factor
741 #noisedB = 10*numpy.log10(self.noise)
772 #noisedB = 10*numpy.log10(self.noise)
742
773
743
744 ySamples=numpy.ones([3,self.nProfiles])
774 ySamples = numpy.ones([3, self.nProfiles])
745 phase=numpy.ones([3,self.nProfiles])
775 phase = numpy.ones([3, self.nProfiles])
746 CSPCSamples=numpy.ones([3,self.nProfiles],dtype=numpy.complex_)
776 CSPCSamples = numpy.ones(
777 [3, self.nProfiles], dtype=numpy.complex_)
747 coherence=numpy.ones([3,self.nProfiles])
778 coherence = numpy.ones([3, self.nProfiles])
748 PhaseSlope=numpy.ones(3)
779 PhaseSlope = numpy.ones(3)
749 PhaseInter=numpy.ones(3)
780 PhaseInter = numpy.ones(3)
@@ -766,13 +797,16 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
766 chan_index0 = self.dataOut.pairsList[i][0]
797 chan_index0 = self.dataOut.pairsList[i][0]
767 chan_index1 = self.dataOut.pairsList[i][1]
798 chan_index1 = self.dataOut.pairsList[i][1]
768
799
769 self.data_cspc[i,:,:]=cspc[chan_index0,:,:] * numpy.conjugate(cspc[chan_index1,:,:])
800 self.data_cspc[i, :, :] = cspc[chan_index0, :,
770
801 :] * numpy.conjugate(cspc[chan_index1, :, :])
771
802
772 '''Getting Eij and Nij'''
803 '''Getting Eij and Nij'''
773 (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180)
804 (AntennaX0, AntennaY0) = pol2cart(
774 (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180)
805 rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180)
775 (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180)
806 (AntennaX1, AntennaY1) = pol2cart(
807 rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180)
808 (AntennaX2, AntennaY2) = pol2cart(
809 rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180)
776
810
777 E01=AntennaX0-AntennaX1
811 E01 = AntennaX0 - AntennaX1
778 N01=AntennaY0-AntennaY1
812 N01 = AntennaY0 - AntennaY1
@@ -783,7 +817,8 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
783 E12=AntennaX1-AntennaX2
817 E12 = AntennaX1 - AntennaX2
784 N12=AntennaY1-AntennaY2
818 N12 = AntennaY1 - AntennaY2
785
819
786 self.ChanDist= numpy.array([[E01, N01],[E02,N02],[E12,N12]])
820 self.ChanDist = numpy.array(
821 [[E01, N01], [E02, N02], [E12, N12]])
787
822
788 self.dataOut.ChanDist = self.ChanDist
823 self.dataOut.ChanDist = self.ChanDist
789
824
@@ -1139,16 +1174,9 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
1139 #
1174 #
1140 # print ' '
1175 # print ' '
1141
1176
1142
1143
1144 self.BlockCounter+=2
1177 self.BlockCounter += 2
1145
1178
1146 else:
1179 else:
1147 self.fileSelector+=1
1180 self.fileSelector += 1
1148 self.BlockCounter=0
1181 self.BlockCounter = 0
1149 print "Next File"
1182 print "Next File"
1150
1151
1152
1153
1154
@@ -1,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,9 +7,7 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
@@ -30,13 +29,11 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
@@ -68,13 +65,18 class Header(object):
68
65
69 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
66 FILE_HEADER = numpy.dtype([ # HEADER 1024bytes
70 ('Hname','a32'), #Original file name
67 ('Hname', 'a32'), # Original file name
71 ('Htime',numpy.str_,32), #Date and time when the file was created
68 # Date and time when the file was created
72 ('Hoper',numpy.str_,64), #Name of operator who created the file
69 ('Htime', numpy.str_, 32),
73 ('Hplace',numpy.str_,128), #Place where the measurements was carried out
70 # Name of operator who created the file
74 ('Hdescr',numpy.str_,256), #Description of measurements
71 ('Hoper', numpy.str_, 64),
72 # Place where the measurements was carried out
73 ('Hplace', numpy.str_, 128),
74 # Description of measurements
75 ('Hdescr', numpy.str_, 256),
75 ('Hdummy',numpy.str_,512), #Reserved space
76 ('Hdummy', numpy.str_, 512), # Reserved space
76 #Main chunk 8bytes
77 # Main chunk 8bytes
77 ('Msign',numpy.str_,4), #Main chunk signature FZKF or NUIG
78 # Main chunk signature FZKF or NUIG
79 ('Msign', numpy.str_, 4),
78 ('MsizeData','<i4'), #Size of data block main chunk
80 ('MsizeData', '<i4'), # Size of data block main chunk
79 #Processing DSP parameters 36bytes
81 # Processing DSP parameters 36bytes
80 ('PPARsign',numpy.str_,4), #PPAR signature
82 ('PPARsign', numpy.str_, 4), # PPAR signature
@@ -82,19 +84,28 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
82 ('PPARprf','<i4'), #Pulse repetition frequency
84 ('PPARprf', '<i4'), # Pulse repetition frequency
83 ('PPARpdr','<i4'), #Pulse duration
85 ('PPARpdr', '<i4'), # Pulse duration
84 ('PPARsft','<i4'), #FFT length
86 ('PPARsft', '<i4'), # FFT length
85 ('PPARavc','<i4'), #Number of spectral (in-coherent) averages
87 # Number of spectral (in-coherent) averages
86 ('PPARihp','<i4'), #Number of lowest range gate for moment estimation
88 ('PPARavc', '<i4'),
87 ('PPARchg','<i4'), #Count for gates for moment estimation
89 # Number of lowest range gate for moment estimation
88 ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1.
90 ('PPARihp', '<i4'),
91 # Count for gates for moment estimation
92 ('PPARchg', '<i4'),
93 # switch on/off polarimetric measurements. Should be 1.
94 ('PPARpol', '<i4'),
89 #Service DSP parameters 112bytes
95 # Service DSP parameters 112bytes
90 ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off
96 # STC attenuation on the lowest ranges on/off
97 ('SPARatt', '<i4'),
91 ('SPARtx','<i4'), #OBSOLETE
98 ('SPARtx', '<i4'), # OBSOLETE
92 ('SPARaddGain0','<f4'), #OBSOLETE
99 ('SPARaddGain0', '<f4'), # OBSOLETE
93 ('SPARaddGain1','<f4'), #OBSOLETE
100 ('SPARaddGain1', '<f4'), # OBSOLETE
94 ('SPARwnd','<i4'), #Debug only. It normal mode it is 0.
101 # Debug only. It normal mode it is 0.
95 ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns
102 ('SPARwnd', '<i4'),
96 ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
103 # Delay between sync pulse and tx pulse for phase corr, ns
97 ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE
104 ('SPARpos', '<i4'),
105 # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal.
106 ('SPARadd', '<i4'),
107 # Time for measuring txn pulse phase. OBSOLETE
108 ('SPARlen', '<i4'),
98 ('SPARcal','<i4'), #OBSOLETE
109 ('SPARcal', '<i4'), # OBSOLETE
99 ('SPARnos','<i4'), #OBSOLETE
110 ('SPARnos', '<i4'), # OBSOLETE
100 ('SPARof0','<i4'), #detection threshold
111 ('SPARof0', '<i4'), # detection threshold
@@ -105,19 +116,23 FILE_HEADER = numpy.dtype([ #HEADER 1024bytes
105 ('SPARtst','<i4'), #OBSOLETE
116 ('SPARtst', '<i4'), # OBSOLETE
106 ('SPARcor','<i4'), #OBSOLETE
117 ('SPARcor', '<i4'), # OBSOLETE
107 ('SPARofs','<i4'), #OBSOLETE
118 ('SPARofs', '<i4'), # OBSOLETE
108 ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate
119 # Hildebrand div noise detection on noise gate
109 ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates
120 ('SPARhsn', '<i4'),
121 # Hildebrand div noise detection on all gates
122 ('SPARhsa', '<f4'),
110 ('SPARcalibPow_M','<f4'), #OBSOLETE
123 ('SPARcalibPow_M', '<f4'), # OBSOLETE
111 ('SPARcalibSNR_M','<f4'), #OBSOLETE
124 ('SPARcalibSNR_M', '<f4'), # OBSOLETE
112 ('SPARcalibPow_S','<f4'), #OBSOLETE
125 ('SPARcalibPow_S', '<f4'), # OBSOLETE
113 ('SPARcalibSNR_S','<f4'), #OBSOLETE
126 ('SPARcalibSNR_S', '<f4'), # OBSOLETE
114 ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5
127 # Lowest range gate for spectra saving Raw_Gate1 >=5
115 ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal
128 ('SPARrawGate1', '<i4'),
116 ('SPARraw','<i4'), #flag - IQ or spectra saving on/off
129 # Number of range gates with atmospheric signal
130 ('SPARrawGate2', '<i4'),
131 # flag - IQ or spectra saving on/off
132 ('SPARraw', '<i4'),
117 ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off
133 ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off
118
134
119
135
120
121 class FileHeaderMIRA35c(Header):
136 class FileHeaderMIRA35c(Header):
122
137
123 def __init__(self):
138 def __init__(self):
@@ -195,7 +210,6 class FileHeaderMIRA35c(Header):
195
210
196 '''
211 '''
197
212
198
199 self.Hname= str(header['Hname'][0])
213 self.Hname = str(header['Hname'][0])
200 self.Htime= str(header['Htime'][0])
214 self.Htime = str(header['Htime'][0])
201 self.Hoper= str(header['Hoper'][0])
215 self.Hoper = str(header['Hoper'][0])
@@ -272,7 +286,6 class FileHeaderMIRA35c(Header):
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)
@@ -293,11 +306,13 class FileHeaderMIRA35c(Header):
293
306
294 return 1
307 return 1
295
308
309
296 SRVI_HEADER = numpy.dtype([
310 SRVI_HEADER = numpy.dtype([
297 ('SignatureSRVI1',numpy.str_,4),#
311 ('SignatureSRVI1', numpy.str_, 4),
298 ('SizeOfDataBlock1','<i4'),#
312 ('SizeOfDataBlock1', '<i4'),
299 ('DataBlockTitleSRVI1',numpy.str_,4),#
313 ('DataBlockTitleSRVI1', numpy.str_, 4),
300 ('SizeOfSRVI1','<i4'),])#
314 ('SizeOfSRVI1', '<i4'), ])
315
301
316
302 class SRVIHeader(Header):
317 class SRVIHeader(Header):
303 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
318 def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0):
@@ -322,7 +337,7 class SRVIHeader(Header):
322
337
323
338
324 SRVI_STRUCTURE = numpy.dtype([
339 SRVI_STRUCTURE = numpy.dtype([
325 ('frame_cnt','<u4'),#
340 ('frame_cnt', '<u4'),
326 ('time_t','<u4'), #
341 ('time_t', '<u4'), #
327 ('tpow','<f4'), #
342 ('tpow', '<f4'), #
328 ('npw1','<f4'), #
343 ('npw1', '<f4'), #
@@ -338,24 +353,20 SRVI_STRUCTURE = numpy.dtype([
338 ('azivel','<f4'), #
353 ('azivel', '<f4'), #
339 ('elvpos','<f4'), #
354 ('elvpos', '<f4'), #
340 ('elvvel','<f4'), #
355 ('elvvel', '<f4'), #
341 ('northAngle','<f4'), #
356 ('northAngle', '<f4'),
342 ('microsec','<u4'), #
357 ('microsec', '<u4'), #
343 ('azisetvel','<f4'), #
358 ('azisetvel', '<f4'), #
344 ('elvsetpos','<f4'), #
359 ('elvsetpos', '<f4'), #
345 ('RadarConst','<f4'),]) #
360 ('RadarConst', '<f4'), ]) #
346
361
347
362
348
349
350 class RecordHeader(Header):
363 class RecordHeader(Header):
351
364
352
353 def __init__(self, frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0,
365 def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0,
354 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
366 cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0,
355 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
367 grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0,
356 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0 , RecCounter=0, Off2StartNxtRec=0):
368 microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0):
357
369
358
359 self.frame_cnt = frame_cnt
370 self.frame_cnt = frame_cnt
360 self.dwell = time_t
371 self.dwell = time_t
361 self.tpow = tpow
372 self.tpow = tpow
@@ -392,7 +403,7 class RecordHeader(Header):
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] #
@@ -428,9 +439,9 class RecordHeader(Header):
428
439
429 print '=============================================='
440 print '=============================================='
430
441
431
432 return 1
442 return 1
433
443
444
434 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
445 class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader):
435
446
436 path = None
447 path = None
@@ -441,7 +452,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
441 walk = None
452 walk = None
442 isConfig = False
453 isConfig = False
443
454
444
445 fileList= None
455 fileList = None
446
456
447 #metadata
457 # metadata
@@ -453,8 +463,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
453 data= None
463 data = None
454 utctime= None
464 utctime = None
455
465
456
457
458 def __init__(self, **kwargs):
466 def __init__(self, **kwargs):
459
467
460 #Eliminar de la base la herencia
468 # Eliminar de la base la herencia
@@ -498,7 +506,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
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.
@@ -506,8 +513,10 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
506 '''
513 '''
507 #self.__checkPath()
514 # self.__checkPath()
508
515
509 ListaData=os.listdir(fp) #Gets the list of files within the fp address
516 # Gets the list of files within the fp address
510 ListaData=sorted(ListaData) #Sort the list of files from least to largest by names
517 ListaData = os.listdir(fp)
518 # Sort the list of files from least to largest by names
519 ListaData = sorted(ListaData)
511 nFiles=0 #File Counter
520 nFiles = 0 # File Counter
512 FileList=[] #A list is created that will contain the .fdt files
521 FileList = [] # A list is created that will contain the .fdt files
513 for IndexFile in ListaData :
522 for IndexFile in ListaData:
@@ -520,7 +529,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
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.
@@ -533,7 +541,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
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,
@@ -557,7 +564,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
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,
@@ -584,10 +590,8 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
584 self.dataOut.data_spc = self.dataOut.data_spc+self.dataOut.noise
590 self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise
585 #print 'self.dataOut.noise',self.dataOut.noise
591 # print 'self.dataOut.noise',self.dataOut.noise
586
592
587
588 return self.dataOut.data_spc
593 return self.dataOut.data_spc
589
594
590
591 def readFile(self,fp):
595 def readFile(self, fp):
592 '''
596 '''
593 You must indicate if you are reading in Online or Offline mode and load the
597 You must indicate if you are reading in Online or Offline mode and load the
@@ -604,7 +608,8 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
604
608
605 if self.fileSelector < len(self.filenameList):
609 if self.fileSelector < len(self.filenameList):
606
610
607 self.fpFile=str(fp)+'/'+str(self.filenameList[self.fileSelector])
611 self.fpFile = str(fp) + '/' + \
612 str(self.filenameList[self.fileSelector])
608
613
609 if self.nextfileflag==True:
614 if self.nextfileflag == True:
610 self.fp = open(self.fpFile,"rb")
615 self.fp = open(self.fpFile, "rb")
@@ -612,18 +617,15 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
612
617
613 '''HERE STARTING THE FILE READING'''
618 '''HERE STARTING THE FILE READING'''
614
619
615
616 self.fheader = FileHeaderMIRA35c()
620 self.fheader = FileHeaderMIRA35c()
617 self.fheader.FHread(self.fp) #Bltr FileHeader Reading
621 self.fheader.FHread(self.fp) # Bltr FileHeader Reading
618
622
619
620 self.SPARrawGate1 = self.fheader.SPARrawGate1
623 self.SPARrawGate1 = self.fheader.SPARrawGate1
621 self.SPARrawGate2 = self.fheader.SPARrawGate2
624 self.SPARrawGate2 = self.fheader.SPARrawGate2
622 self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
625 self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1
623 self.Num_Bins = self.fheader.PPARsft
626 self.Num_Bins = self.fheader.PPARsft
624 self.dataOut.nFFTPoints = self.fheader.PPARsft
627 self.dataOut.nFFTPoints = self.fheader.PPARsft
625
628
626
627 self.Num_inCoh = self.fheader.PPARavc
629 self.Num_inCoh = self.fheader.PPARavc
628 self.dataOut.PRF = self.fheader.PPARprf
630 self.dataOut.PRF = self.fheader.PPARprf
629 self.dataOut.frequency = 34.85*10**9
631 self.dataOut.frequency = 34.85 * 10**9
@@ -633,14 +635,12 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
633 pulse_width = self.fheader.PPARpdr * 10**-9
635 pulse_width = self.fheader.PPARpdr * 10**-9
634 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
636 self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width
635
637
636 self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins,2))#
638 self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins, 2))
637 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
639 self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2))
638
640
639 self.Ze = numpy.zeros(self.Num_Hei)
641 self.Ze = numpy.zeros(self.Num_Hei)
640 self.ETA = numpy.zeros(([2,self.Num_Hei]))
642 self.ETA = numpy.zeros(([2, self.Num_Hei]))
641
643
642
643
644 self.readBlock() #Block reading
644 self.readBlock() # Block reading
645
645
646 else:
646 else:
@@ -650,8 +650,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
650 self.FileHeaderFlag == True
650 self.FileHeaderFlag == True
651 return 0
651 return 0
652
652
653
654
655 def readBlock(self):
653 def readBlock(self):
656 '''
654 '''
657 It should be checked if the block has data, if it is not passed to the next file.
655 It should be checked if the block has data, if it is not passed to the next file.
@@ -670,8 +668,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
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
@@ -682,7 +678,8 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
682 print 'blocksize == 148 bug'
678 print 'blocksize == 148 bug'
683 jump = numpy.fromfile(self.fp,[('jump',numpy.str_,140)] ,1)
679 jump = numpy.fromfile(self.fp, [('jump', numpy.str_, 140)], 1)
684
680
685 self.srviHeader.SRVIread(self.fp) #Se obtiene la cabecera del SRVI
681 # Se obtiene la cabecera del SRVI
682 self.srviHeader.SRVIread(self.fp)
686
683
687 if not self.srviHeader.SizeOfSRVI1:
684 if not self.srviHeader.SizeOfSRVI1:
688 self.fileSelector+=1
685 self.fileSelector += 1
@@ -696,7 +693,6 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
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
@@ -706,53 +702,65 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
706 self.dataOut.timeZone=0
702 self.dataOut.timeZone = 0
707
703
708 self.dataOut.outputInterval = self.dataOut.getTimeInterval()
704 self.dataOut.outputInterval = self.dataOut.getTimeInterval()
709 self.dataOut.heightList = self.SPARrawGate1*self.__deltaHeigth + numpy.array(range(self.Num_Hei))*self.__deltaHeigth
705 self.dataOut.heightList = self.SPARrawGate1 * self.__deltaHeigth + \
710
706 numpy.array(range(self.Num_Hei)) * self.__deltaHeigth
711
712
707
713 self.HSDVsign = numpy.fromfile( self.fp, [('HSDV',numpy.str_,4)],1)
708 self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1)
714 self.SizeHSDV = numpy.fromfile( self.fp, [('SizeHSDV','<i4')],1)
709 self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1)
715 self.HSDV_Co = numpy.fromfile( self.fp, [('HSDV_Co','<f4')],self.Num_Hei)
710 self.HSDV_Co = numpy.fromfile(
716 self.HSDV_Cx = numpy.fromfile( self.fp, [('HSDV_Cx','<f4')],self.Num_Hei)
711 self.fp, [('HSDV_Co', '<f4')], self.Num_Hei)
712 self.HSDV_Cx = numpy.fromfile(
713 self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei)
717
714
718 self.COFAsign = numpy.fromfile( self.fp, [('COFA',numpy.str_,4)],1)
715 self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1)
719 self.SizeCOFA = numpy.fromfile( self.fp, [('SizeCOFA','<i4')],1)
716 self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1)
720 self.COFA_Co = numpy.fromfile( self.fp, [('COFA_Co','<f4')],self.Num_Hei)
717 self.COFA_Co = numpy.fromfile(
721 self.COFA_Cx = numpy.fromfile( self.fp, [('COFA_Cx','<f4')],self.Num_Hei)
718 self.fp, [('COFA_Co', '<f4')], self.Num_Hei)
719 self.COFA_Cx = numpy.fromfile(
720 self.fp, [('COFA_Cx', '<f4')], self.Num_Hei)
722
721
723 self.ZSPCsign = numpy.fromfile(self.fp, [('ZSPCsign',numpy.str_,4)],1)
722 self.ZSPCsign = numpy.fromfile(
723 self.fp, [('ZSPCsign', numpy.str_, 4)], 1)
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC','<i4')],1)
724 self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1)
725
725
726 self.dataOut.HSDV[0]=self.HSDV_Co[:][0]
726 self.dataOut.HSDV[0] = self.HSDV_Co[:][0]
727 self.dataOut.HSDV[1]=self.HSDV_Cx[:][0]
727 self.dataOut.HSDV[1] = self.HSDV_Cx[:][0]
728
728
729 for irg in range(self.Num_Hei):
729 for irg in range(self.Num_Hei):
730 nspc = numpy.fromfile(self.fp, [('nspc','int16')],1)[0][0] # Number of spectral sub pieces containing significant power
730 # Number of spectral sub pieces containing significant power
731 nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0]
731
732
732 for k in range(nspc):
733 for k in range(nspc):
733 binIndex = numpy.fromfile(self.fp, [('binIndex','int16')],1)[0][0] # Index of the spectral bin where the piece is beginning
734 # Index of the spectral bin where the piece is beginning
734 nbins = numpy.fromfile(self.fp, [('nbins','int16')],1)[0][0] # Number of bins of the piece
735 binIndex = numpy.fromfile(
736 self.fp, [('binIndex', 'int16')], 1)[0][0]
737 nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[
738 0][0] # Number of bins of the piece
735
739
736 #Co_Channel
740 # Co_Channel
737 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0] # Spectrum piece to be normaliced
741 jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[
738 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0] # Maximun piece to be normaliced
742 0][0] # Spectrum piece to be normaliced
739
743 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[
744 0][0] # Maximun piece to be normaliced
740
745
741 self.data_spc[irg,binIndex:binIndex+nbins,0] = self.data_spc[irg,binIndex:binIndex+nbins,0]+jbin/65530.*jmax
746 self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg,
747 binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax
742
748
743 #Cx_Channel
749 # Cx_Channel
744 jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0]
750 jbin = numpy.fromfile(
751 self.fp, [('jbin', 'uint16')], nbins)[0][0]
745 jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0]
752 jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0]
746
753
747
754 self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg,
748 self.data_spc[irg,binIndex:binIndex+nbins,1] = self.data_spc[irg,binIndex:binIndex+nbins,1]+jbin/65530.*jmax
755 binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax
749
756
750 for bin in range(self.Num_Bins):
757 for bin in range(self.Num_Bins):
751
758
752 self.data_spc[:,bin,0] = self.data_spc[:,bin,0] - self.dataOut.HSDV[:,0]
759 self.data_spc[:, bin, 0] = self.data_spc[:,
753
760 bin, 0] - self.dataOut.HSDV[:, 0]
754 self.data_spc[:,bin,1] = self.data_spc[:,bin,1] - self.dataOut.HSDV[:,1]
755
761
762 self.data_spc[:, bin, 1] = self.data_spc[:,
763 bin, 1] - self.dataOut.HSDV[:, 1]
756
764
757 numpy.set_printoptions(threshold='nan')
765 numpy.set_printoptions(threshold='nan')
758
766
@@ -787,17 +795,8 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader):
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,15 +81,12 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
88 Affected:
84 Affected:
89
90 self.dataOut
85 self.dataOut
91
86
92 Return : None
87 Return : None
93 """
88 """
94
89
95
96 #Eliminar de la base la herencia
90 #Eliminar de la base la herencia
97 ProcessingUnit.__init__(self, **kwargs)
91 ProcessingUnit.__init__(self, **kwargs)
98
92
@@ -213,7 +207,6 class SpectraReader(JRODataReader, ProcessingUnit):
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]))
@@ -245,7 +238,6 class SpectraReader(JRODataReader, ProcessingUnit):
245
238
246 Variables afectadas:
239 Variables afectadas:
247
240
248
249 self.flagIsNewFile
241 self.flagIsNewFile
250 self.flagIsNewBlock
242 self.flagIsNewBlock
251 self.nTotalBlocks
243 self.nTotalBlocks
@@ -256,7 +248,6 class SpectraReader(JRODataReader, ProcessingUnit):
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
@@ -286,13 +277,11 class SpectraReader(JRODataReader, ProcessingUnit):
286 self.data_spc = spc
277 self.data_spc = spc
287
278
288 if self.processingHeaderObj.flag_cspc:
279 if self.processingHeaderObj.flag_cspc:
289
290 cspc = numpy.transpose( cspc, (0,2,1) )
280 cspc = numpy.transpose( cspc, (0,2,1) )
291 self.data_cspc = cspc['real'] + cspc['imag']*1j
281 self.data_cspc = cspc['real'] + cspc['imag']*1j
292 else:
282 else:
293 self.data_cspc = None
283 self.data_cspc = None
294
284
295
296 if self.processingHeaderObj.flag_dc:
285 if self.processingHeaderObj.flag_dc:
297 self.data_dc = dc['real'] + dc['imag']*1j
286 self.data_dc = dc['real'] + dc['imag']*1j
298 else:
287 else:
@@ -377,7 +366,6 class SpectraReader(JRODataReader, ProcessingUnit):
377 self.dataOut.flagNoData = True
366 self.dataOut.flagNoData = True
378 return 0
367 return 0
379
368
380
381 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
369 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
382
370
383 if self.data_spc is None:
371 if self.data_spc is None:
@@ -425,12 +413,11 class SpectraWriter(JRODataWriter, Operation):
425
413
426 # dataOut = None
414 # dataOut = None
427
415
428 def __init__(self):
416 def __init__(self, **kwargs):
429 """
417 """
430 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
418 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
431
419
432 Affected:
420 Affected:
433
434 self.dataOut
421 self.dataOut
435 self.basicHeaderObj
422 self.basicHeaderObj
436 self.systemHeaderObj
423 self.systemHeaderObj
@@ -440,7 +427,7 class SpectraWriter(JRODataWriter, Operation):
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
@@ -450,7 +437,6 class SpectraWriter(JRODataWriter, Operation):
450
437
451 self.data_cspc = None
438 self.data_cspc = None
452
439
453
454 self.data_dc = None
440 self.data_dc = None
455
441
456 self.fp = None
442 self.fp = None
@@ -484,7 +470,6 class SpectraWriter(JRODataWriter, Operation):
484 return 1
470 return 1
485
471
486
472
487
488 def setBlockDimension(self):
473 def setBlockDimension(self):
489 """
474 """
490 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
475 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
@@ -512,7 +497,6 class SpectraWriter(JRODataWriter, Operation):
512 """
497 """
513 Escribe el buffer en el file designado
498 Escribe el buffer en el file designado
514
499
515
516 Affected:
500 Affected:
517 self.data_spc
501 self.data_spc
518 self.data_cspc
502 self.data_cspc
@@ -542,7 +526,6 class SpectraWriter(JRODataWriter, Operation):
542 data = data.reshape((-1))
526 data = data.reshape((-1))
543 data.tofile(self.fp)
527 data.tofile(self.fp)
544
528
545
546 if self.data_dc is not None:
529 if self.data_dc is not None:
547 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
530 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
548 dc = self.data_dc
531 dc = self.data_dc
@@ -559,7 +542,6 class SpectraWriter(JRODataWriter, Operation):
559 # if self.data_cspc is not None:
542 # if self.data_cspc is not None:
560 # self.data_cspc.fill(0)
543 # self.data_cspc.fill(0)
561
544
562
563 self.flagIsNewFile = 0
545 self.flagIsNewFile = 0
564 self.flagIsNewBlock = 1
546 self.flagIsNewBlock = 1
565 self.nTotalBlocks += 1
547 self.nTotalBlocks += 1
@@ -572,7 +554,6 class SpectraWriter(JRODataWriter, Operation):
572 """
554 """
573 Setea un bloque de datos y luego los escribe en un file
555 Setea un bloque de datos y luego los escribe en un file
574
556
575
576 Affected:
557 Affected:
577 self.data_spc
558 self.data_spc
578 self.data_cspc
559 self.data_cspc
@@ -590,7 +571,9 class SpectraWriter(JRODataWriter, Operation):
590
571
591 if self.dataOut.flagDiscontinuousBlock:
572 if self.dataOut.flagDiscontinuousBlock:
592 self.data_spc.fill(0)
573 self.data_spc.fill(0)
574 if self.dataOut.data_cspc is not None:
593 self.data_cspc.fill(0)
575 self.data_cspc.fill(0)
576 if self.dataOut.data_dc is not None:
594 self.data_dc.fill(0)
577 self.data_dc.fill(0)
595 self.setNextFile()
578 self.setNextFile()
596
579
@@ -612,7 +595,6 class SpectraWriter(JRODataWriter, Operation):
612
595
613 return 1
596 return 1
614
597
615
616 def __getBlockSize(self):
598 def __getBlockSize(self):
617 '''
599 '''
618 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
600 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
@@ -665,7 +647,6 class SpectraWriter(JRODataWriter, Operation):
665 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
647 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
666 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
648 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
667
649
668
669 if self.processingHeaderObj.totalSpectra > 0:
650 if self.processingHeaderObj.totalSpectra > 0:
670 channelList = []
651 channelList = []
671 for channel in range(self.dataOut.nChannels):
652 for channel in range(self.dataOut.nChannels):
@@ -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
@@ -177,7 +178,6 class VoltageReader(JRODataReader, ProcessingUnit):
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
@@ -188,11 +188,10 class VoltageReader(JRODataReader, ProcessingUnit):
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
@@ -230,13 +229,15 class VoltageReader(JRODataReader, ProcessingUnit):
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
@@ -264,7 +265,6 class VoltageReader(JRODataReader, ProcessingUnit):
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
@@ -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
@@ -302,15 +305,19 class VoltageReader(JRODataReader, ProcessingUnit):
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) * \
320 self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight
314 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
321 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs
315
322
316 return
323 return
@@ -321,7 +328,8 class VoltageReader(JRODataReader, ProcessingUnit):
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:
@@ -339,12 +347,13 class VoltageReader(JRODataReader, ProcessingUnit):
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
348 def getFromServer(self):
357 def getFromServer(self):
349 self.flagDiscontinuousBlock = 0
358 self.flagDiscontinuousBlock = 0
350 self.profileIndex = 0
359 self.profileIndex = 0
@@ -369,15 +378,19 class VoltageReader(JRODataReader, ProcessingUnit):
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
@@ -385,17 +398,21 class VoltageReader(JRODataReader, ProcessingUnit):
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(
415 (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex')
399 buffer[:,:datasize,:] = self.dataOut.data
416 buffer[:, :datasize, :] = self.dataOut.data
400 self.dataOut.data = buffer
417 self.dataOut.data = buffer
401 self.profileIndex = blockIndex
418 self.profileIndex = blockIndex
@@ -487,20 +504,24 class VoltageReader(JRODataReader, ProcessingUnit):
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(
524 (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex')
504 buffer[:,:datasize,:] = self.dataOut.data
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
@@ -515,7 +536,8 class VoltageReader(JRODataReader, ProcessingUnit):
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
@@ -528,11 +550,6 class VoltageReader(JRODataReader, ProcessingUnit):
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
@@ -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
@@ -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
@@ -722,10 +737,13 class VoltageWriter(JRODataWriter, Operation):
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()
@@ -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 NO CONTENT: modified file
NO CONTENT: modified file
@@ -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)
@@ -63,7 +64,6 setup(name="schainpy",
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