##// END OF EJS Templates
voltage DigitalRFReader funcionando
Jose Chavez -
r973:168a55cfc83e
parent child
Show More
This diff has been collapsed as it changes many lines, (590 lines changed) Show them Hide them
@@ -0,0 +1,590
1 '''
2 Created on Jul 3, 2014
3
4 @author: roj-idl71
5 '''
6 import os
7 import datetime
8 import numpy
9
10 try:
11 from gevent import sleep
12 except:
13 from time import sleep
14
15 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
16 from schainpy.model.data.jrodata import Voltage
17 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
18
19 try:
20 import digital_rf
21 except:
22 print 'You should install "digital_rf" module if you want to read Digital RF data'
23
24 class DigitalRFReader(ProcessingUnit):
25 '''
26 classdocs
27 '''
28
29 def __init__(self, **kwargs):
30 '''
31 Constructor
32 '''
33
34 ProcessingUnit.__init__(self, **kwargs)
35
36 self.dataOut = Voltage()
37 self.__printInfo = True
38 self.__flagDiscontinuousBlock = False
39 self.__bufferIndex = 9999999
40
41 self.__ippKm = None
42 self.__codeType = 0
43 self.__nCode = None
44 self.__nBaud = None
45 self.__code = None
46
47 def __getCurrentSecond(self):
48
49 return self.__thisUnixSample/self.__sample_rate
50
51 thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
52
53 def __setFileHeader(self):
54 '''
55 In this method will be initialized every parameter of dataOut object (header, no data)
56 '''
57 ippSeconds = 1.0*self.__nSamples/self.__sample_rate
58
59 nProfiles = 1.0/ippSeconds #Number of profiles in one second
60
61 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ippKm=self.__ippKm,
62 txA=0,
63 txB=0,
64 nWindows=1,
65 nHeights=self.__nSamples,
66 firstHeight=self.__firstHeigth,
67 deltaHeight=self.__deltaHeigth,
68 codeType=self.__codeType,
69 nCode=self.__nCode, nBaud=self.__nBaud,
70 code = self.__code)
71
72 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
73 nProfiles=nProfiles,
74 nChannels=len(self.__channelList),
75 adcResolution=14)
76
77 self.dataOut.type = "Voltage"
78
79 self.dataOut.data = None
80
81 self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')])
82
83 # self.dataOut.nChannels = 0
84
85 # self.dataOut.nHeights = 0
86
87 self.dataOut.nProfiles = nProfiles
88
89 self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth
90
91 self.dataOut.channelList = self.__channelList
92
93 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
94
95 # self.dataOut.channelIndexList = None
96
97 self.dataOut.flagNoData = True
98
99 #Set to TRUE if the data is discontinuous
100 self.dataOut.flagDiscontinuousBlock = False
101
102 self.dataOut.utctime = None
103
104 self.dataOut.timeZone = self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime
105
106 self.dataOut.dstFlag = 0
107
108 self.dataOut.errorCount = 0
109
110 self.dataOut.nCohInt = 1
111
112 self.dataOut.flagDecodeData = False #asumo que la data esta decodificada
113
114 self.dataOut.flagDeflipData = False #asumo que la data esta sin flip
115
116 self.dataOut.flagShiftFFT = False
117
118 self.dataOut.ippSeconds = ippSeconds
119
120 #Time interval between profiles
121 #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
122
123 self.dataOut.frequency = self.__frequency
124
125 self.dataOut.realtime = self.__online
126
127 def findDatafiles(self, path, startDate=None, endDate=None):
128
129 if not os.path.isdir(path):
130 return []
131
132 try:
133 digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
134 except:
135 digitalReadObj = digital_rf.DigitalRFReader(path)
136
137 channelNameList = digitalReadObj.get_channels()
138
139 if not channelNameList:
140 return []
141
142 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
143
144 sample_rate = metadata_dict['sample_rate'][0]
145
146 this_metadata_file = digitalReadObj.get_metadata(channelNameList[0])
147
148 try:
149 timezone = this_metadata_file['timezone'].value
150 except:
151 timezone = 0
152
153 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone
154
155 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
156 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
157
158 if not startDate:
159 startDate = startDatetime.date()
160
161 if not endDate:
162 endDate = endDatatime.date()
163
164 dateList = []
165
166 thisDatetime = startDatetime
167
168 while(thisDatetime<=endDatatime):
169
170 thisDate = thisDatetime.date()
171
172 if thisDate < startDate:
173 continue
174
175 if thisDate > endDate:
176 break
177
178 dateList.append(thisDate)
179 thisDatetime += datetime.timedelta(1)
180
181 return dateList
182
183 def setup(self, path = None,
184 startDate = None,
185 endDate = None,
186 startTime = datetime.time(0,0,0),
187 endTime = datetime.time(23,59,59),
188 channelList = None,
189 nSamples = None,
190 ippKm = 60,
191 online = False,
192 delay = 60,
193 buffer_size = 1024,
194 **kwargs):
195 '''
196 In this method we should set all initial parameters.
197
198 Inputs:
199 path
200 startDate
201 endDate
202 startTime
203 endTime
204 set
205 expLabel
206 ext
207 online
208 delay
209 '''
210
211 if not os.path.isdir(path):
212 raise ValueError, "[Reading] Directory %s does not exist" %path
213
214 try:
215 self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
216 except:
217 self.digitalReadObj = digital_rf.DigitalRFReader(path)
218
219 channelNameList = self.digitalReadObj.get_channels()
220
221 if not channelNameList:
222 raise ValueError, "[Reading] Directory %s does not have any files" %path
223
224 if not channelList:
225 channelList = range(len(channelNameList))
226
227 ########## Reading metadata ######################
228
229 metadata_dict = self.digitalReadObj.get_properties(channelNameList[channelList[0]])
230
231 self.__sample_rate = metadata_dict['sample_rate_numerator'] / metadata_dict['sample_rate_denominator']
232 # self.__samples_per_file = metadata_dict['samples_per_file'][0]
233 self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15?
234
235 this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]])
236 metadata_bounds = this_metadata_file.get_bounds()
237 self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ##GET FIRST HEADER
238
239 self.__frequency = None
240 try:
241 self.__frequency = self.fixed_metadata_dict['frequency']
242 except:
243 self.__frequency = None
244
245 try:
246 self.__timezone = self.fixed_metadata_dict['timezone']
247 except:
248 self.__timezone = 0
249
250 self.__firstHeigth = 0
251
252
253 try:
254 codeType = self.fixed_metadata_dict['codeType']
255 except:
256 codeType = 0
257
258 nCode = 1
259 nBaud = 1
260 code = numpy.ones((nCode, nBaud), dtype=numpy.int)
261
262 if codeType:
263 nCode = self.fixed_metadata_dict['nCode']
264 nBaud = self.fixed_metadata_dict['nBaud']
265 code = self.fixed_metadata_dict['code']
266
267 if not ippKm:
268 try:
269 #seconds to km
270 ippKm = 1e6*0.15*self.fixed_metadata_dict['ipp']
271 except:
272 ippKm = None
273 ####################################################
274 startUTCSecond = None
275 endUTCSecond = None
276
277 if startDate:
278 startDatetime = datetime.datetime.combine(startDate, startTime)
279 startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
280
281 if endDate:
282 endDatetime = datetime.datetime.combine(endDate, endTime)
283 endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
284
285 start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]])
286
287 if not startUTCSecond:
288 startUTCSecond = start_index/self.__sample_rate
289
290 if start_index > startUTCSecond*self.__sample_rate:
291 startUTCSecond = start_index/self.__sample_rate
292
293 if not endUTCSecond:
294 endUTCSecond = end_index/self.__sample_rate
295
296 if end_index < endUTCSecond*self.__sample_rate:
297 endUTCSecond = end_index/self.__sample_rate
298
299 if not nSamples:
300 if not ippKm:
301 raise ValueError, "[Reading] nSamples or ippKm should be defined"
302 nSamples = int(ippKm / (1e6*0.15/self.__sample_rate))
303
304 channelBoundList = []
305 channelNameListFiltered = []
306
307 for thisIndexChannel in channelList:
308 thisChannelName = channelNameList[thisIndexChannel]
309 start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName)
310 channelBoundList.append((start_index, end_index))
311 channelNameListFiltered.append(thisChannelName)
312
313 self.profileIndex = 0
314
315 self.__delay = delay
316 self.__ippKm = ippKm
317 self.__codeType = codeType
318 self.__nCode = nCode
319 self.__nBaud = nBaud
320 self.__code = code
321
322 self.__datapath = path
323 self.__online = online
324 self.__channelList = channelList
325 self.__channelNameList = channelNameListFiltered
326 self.__channelBoundList = channelBoundList
327 self.__nSamples = nSamples
328 self.__samples_to_read = long(buffer_size*nSamples) #FIJO: AHORA 40
329 self.__nChannels = len(self.__channelList)
330
331 self.__startUTCSecond = startUTCSecond
332 self.__endUTCSecond = endUTCSecond
333
334 self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate #Time interval
335
336 if online:
337 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
338 startUTCSecond = numpy.floor(endUTCSecond)
339
340 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
341
342 self.__data_buffer = numpy.zeros((self.__nChannels, self.__samples_to_read), dtype = numpy.complex)
343
344 self.__setFileHeader()
345 self.isConfig = True
346
347 print "[Reading] Digital RF Data was found from %s to %s " %(
348 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
349 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
350 )
351
352 print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
353 datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone)
354 )
355
356 def __reload(self):
357 # print
358 # print "%s not in range [%s, %s]" %(
359 # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
360 # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
361 # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
362 # )
363 print "[Reading] reloading metadata ..."
364
365 try:
366 self.digitalReadObj.reload(complete_update=True)
367 except:
368 self.digitalReadObj.reload()
369
370 start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]])
371
372 if start_index > self.__startUTCSecond*self.__sample_rate:
373 self.__startUTCSecond = 1.0*start_index/self.__sample_rate
374
375 if end_index > self.__endUTCSecond*self.__sample_rate:
376 self.__endUTCSecond = 1.0*end_index/self.__sample_rate
377 print
378 print "[Reading] New timerange found [%s, %s] " %(
379 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
380 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
381 )
382
383 return True
384
385 return False
386
387 def __readNextBlock(self, seconds=30, volt_scale = 218776):
388 '''
389 '''
390
391 #Set the next data
392 self.__flagDiscontinuousBlock = False
393 self.__thisUnixSample += self.__samples_to_read
394
395 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
396 print "[Reading] There are no more data into selected time-range"
397 if self.__online:
398 self.__reload()
399 else:
400 return False
401
402 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
403 return False
404 self.__thisUnixSample -= self.__samples_to_read
405
406 indexChannel = 0
407
408 dataOk = False
409
410 for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS?
411
412 try:
413 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
414 self.__samples_to_read,
415 thisChannelName)
416 except IOError, e:
417 #read next profile
418 self.__flagDiscontinuousBlock = True
419 print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
420 break
421
422 if result.shape[0] != self.__samples_to_read:
423 self.__flagDiscontinuousBlock = True
424 print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
425 result.shape[0],
426 self.__samples_to_read)
427 break
428
429 self.__data_buffer[indexChannel,:] = result*volt_scale
430
431 indexChannel += 1
432
433 dataOk = True
434
435 self.__utctime = self.__thisUnixSample/self.__sample_rate
436
437 if not dataOk:
438 return False
439
440 print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
441 self.__samples_to_read,
442 self.__timeInterval)
443
444 self.__bufferIndex = 0
445
446 return True
447
448 def __isBufferEmpty(self):
449 return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40
450
451 def getData(self, seconds=30, nTries=5):
452
453 '''
454 This method gets the data from files and put the data into the dataOut object
455
456 In addition, increase el the buffer counter in one.
457
458 Return:
459 data : retorna un perfil de voltages (alturas * canales) copiados desde el
460 buffer. Si no hay mas archivos a leer retorna None.
461
462 Affected:
463 self.dataOut
464 self.profileIndex
465 self.flagDiscontinuousBlock
466 self.flagIsNewBlock
467 '''
468
469 err_counter = 0
470 self.dataOut.flagNoData = True
471
472 if self.__isBufferEmpty():
473
474 self.__flagDiscontinuousBlock = False
475
476 while True:
477 if self.__readNextBlock():
478 break
479 if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate:
480 return False
481
482 if self.__flagDiscontinuousBlock:
483 print '[Reading] discontinuous block found ... continue with the next block'
484 continue
485
486 if not self.__online:
487 return False
488
489 err_counter += 1
490 if err_counter > nTries:
491 return False
492
493 print '[Reading] waiting %d seconds to read a new block' %seconds
494 sleep(seconds)
495
496 self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples]
497 self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate
498 self.dataOut.flagNoData = False
499 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
500 self.dataOut.profileIndex = self.profileIndex
501
502 self.__bufferIndex += self.__nSamples
503 self.profileIndex += 1
504
505 if self.profileIndex == self.dataOut.nProfiles:
506 self.profileIndex = 0
507
508 return True
509
510 def printInfo(self):
511 '''
512 '''
513 if self.__printInfo == False:
514 return
515
516 # self.systemHeaderObj.printInfo()
517 # self.radarControllerHeaderObj.printInfo()
518
519 self.__printInfo = False
520
521 def printNumberOfBlock(self):
522 '''
523 '''
524 return
525 #print self.profileIndex
526
527 def run(self, **kwargs):
528 '''
529 This method will be called many times so here you should put all your code
530 '''
531
532 if not self.isConfig:
533 self.setup(**kwargs)
534
535 self.getData(seconds=self.__delay)
536
537 return
538
539 class DigitalRFWriter(Operation):
540 '''
541 classdocs
542 '''
543
544 def __init__(self, **kwargs):
545 '''
546 Constructor
547 '''
548 Operation.__init__(self, **kwargs)
549 self.dataOut = None
550
551 def setup(self, dataIn, path, blocksPerFile, set=0, ext=None):
552 '''
553 In this method we should set all initial parameters.
554
555 Input:
556 dataIn : Input data will also be outputa data
557
558 '''
559 self.dataOut = dataIn
560
561
562
563
564
565 self.isConfig = True
566
567 return
568
569 def run(self, dataIn, **kwargs):
570 '''
571 This method will be called many times so here you should put all your code
572
573 Inputs:
574
575 dataIn : object with the data
576
577 '''
578
579 if not self.isConfig:
580 self.setup(dataIn, **kwargs)
581
582
583 if __name__ == '__main__':
584
585 readObj = DigitalRFReader()
586
587 while True:
588 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
589 # readObj.printInfo()
590 readObj.printNumberOfBlock()
@@ -0,0 +1,118
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/jchavez/jicamarca/mocked_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 ippKm = 60)
34
35 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage',
36 inputId=readUnitConfObj.getId())
37
38 # opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
39 # opObj10.addParameter(name='minHei', value='0', format='float')
40 # opObj10.addParameter(name='maxHei', value='8', format='float')
41
42 # opObj10 = procUnitConfObj0.addOperation(name='setH0')
43 # opObj10.addParameter(name='h0', value='5.4', format='float')
44
45 # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external')
46 # opObj10.addParameter(name='code', value='1,-1', format='intlist')
47 # opObj10.addParameter(name='nCode', value='2', format='float')
48 # opObj10.addParameter(name='nBaud', value='1', format='float')
49
50 opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external')
51 opObj10.addParameter(name='n', value='1', format='float')
52
53 opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='external')
54 opObj11.addParameter(name='id', value='121', format='int')
55 opObj11.addParameter(name='wintitle', value='Scope', format='str')
56
57 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra',
58 # inputId=procUnitConfObj0.getId())
59
60 # #Creating a processing object with its parameters
61 # #schainpy.model.proc.jroproc_spectra.SpectraProc.run()
62 # #If you need to add more parameters can use the "addParameter method"
63 # procUnitConfObj1.addParameter(name='nFFTPoints', value='8', format='int')
64 # procUnitConfObj1.addParameter(name='pairsList', value='(0,1)', format='pairslist')
65
66 # opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external')
67 # opObj10.addParameter(name='n', value='2', format='float')
68 #
69 #Using internal methods
70 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels()
71 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
72 # opObj10.addParameter(name='channelList', value='0,1', format='intlist')
73
74 #Using internal methods
75 #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights()
76 # opObj10 = procUnitConfObj1.addOperation(name='selectHeights')
77 # opObj10.addParameter(name='minHei', value='90', format='float')
78 # opObj10.addParameter(name='maxHei', value='180', format='float')
79
80 #Using external methods (new modules)
81 # #schainpy.model.proc.jroproc_spectra.IncohInt.setup()
82 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
83 # opObj12.addParameter(name='n', value='1', format='int')
84
85 #Using external methods (new modules)
86 #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup()
87 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external')
88 # opObj11.addParameter(name='id', value='11', format='int')
89 # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str')
90 # opObj11.addParameter(name='zmin', value='0', format='int')
91 # opObj11.addParameter(name='zmax', value='90', format='int')
92 # opObj11.addParameter(name='save', value='1', format='int')
93 # opObj11.addParameter(name='xmin', value='-20', format='float')
94 # opObj11.addParameter(name='xmax', value='20', format='float')
95
96 #Using external methods (new modules)
97 #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup()
98 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
99 # opObj11.addParameter(name='id', value='30', format='int')
100 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
101 # # opObj11.addParameter(name='zmin', value='0', format='int')
102 # # opObj11.addParameter(name='zmax', value='90', format='int')
103 # opObj11.addParameter(name='showprofile', value='1', format='int')
104 # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
105 # opObj11.addParameter(name='xmin', value='19.5', format='float')
106 # opObj11.addParameter(name='xmax', value='20', format='float')
107
108 # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
109 # opObj11.addParameter(name='id', value='3', format='int')
110 # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str')
111 # opObj11.addParameter(name='zmin', value='30', format='int')
112 # opObj11.addParameter(name='zmax', value='120', format='int')
113 # opObj11.addParameter(name='pairsList', value='(0,1)', format='pairslist')
114
115 controllerObj.start()
116
117 if __name__ == '__main__':
118 main()
@@ -1,94 +1,92
1 """
1 """
2 Classes to save parameters from Windows.
2 Classes to save parameters from Windows.
3
3
4 -Project window
4 -Project window
5 -Voltage window
5 -Voltage window
6 -Spectra window
6 -Spectra window
7 -SpectraHeis window
7 -SpectraHeis window
8 -Correlation window
8 -Correlation window
9
9
10 """
10 """
11
11
12 class ProjectParms():
12 class ProjectParms():
13
13
14 parmsOk = False
14 parmsOk = False
15 name = None
15 name = None
16 description = None
16 description = None
17 datatype = None
17 datatype = None
18 ext = None
18 ext = None
19 dpath = None
19 dpath = None
20 startDate = None
20 startDate = None
21 endDate = None
21 endDate = None
22 startTime = None
22 startTime = None
23 endTime = None
23 endTime = None
24 online = None
24 online = None
25 delay = None
25 delay = None
26 walk = None
26 walk = None
27 expLabel = None
27 expLabel = None
28 set = None
28 set = None
29 ippKm = None
29 ippKm = None
30
30
31 def __init__(self):
31 def __init__(self):
32
32
33 self.parmsOk = True
33 self.parmsOk = True
34 self.description = ''
34 self.description = ''
35 self.expLabel = ''
35 self.expLabel = ''
36 self.set = ''
36 self.set = ''
37 self.ippKm = ''
37 self.ippKm = ''
38 self.walk = None
38 self.walk = None
39 self.delay = ''
39 self.delay = ''
40
40
41 def getDatatypeIndex(self):
41 def getDatatypeIndex(self):
42
42
43 indexDatatype = None
43 indexDatatype = None
44
44
45 if 'voltage' in self.datatype.lower():
45 if 'voltage' in self.datatype.lower():
46 indexDatatype = 0
46 indexDatatype = 0
47 if 'spectra' in self.datatype.lower():
47 if 'spectra' in self.datatype.lower():
48 indexDatatype = 1
48 indexDatatype = 1
49 if 'fits' in self.datatype.lower():
49 if 'fits' in self.datatype.lower():
50 indexDatatype = 2
50 indexDatatype = 2
51 if 'usrp' in self.datatype.lower():
51 if 'usrp' in self.datatype.lower():
52 indexDatatype = 3
52 indexDatatype = 3
53
54 return indexDatatype
53 return indexDatatype
55
54
56 def getExt(self):
55 def getExt(self):
57
56
58 ext = None
57 ext = None
59
58
60 if self.datatype.lower() == 'voltage':
59 if self.datatype.lower() == 'voltage':
61 ext = '.r'
60 ext = '.r'
62 if self.datatype.lower() == 'spectra':
61 if self.datatype.lower() == 'spectra':
63 ext = '.pdata'
62 ext = '.pdata'
64 if self.datatype.lower() == 'fits':
63 if self.datatype.lower() == 'fits':
65 ext = '.fits'
64 ext = '.fits'
66 if self.datatype.lower() == 'usrp':
65 if self.datatype.lower() == 'usrp':
67 ext = '.hdf5'
66 ext = '.hdf5'
68
69 return ext
67 return ext
70
68
71 def set(self, project_name, datatype, ext, dpath, online,
69 def set(self, project_name, datatype, ext, dpath, online,
72 startDate=None, endDate=None, startTime=None, endTime=None,
70 startDate=None, endDate=None, startTime=None, endTime=None,
73 delay=None, walk=None, set=None, ippKm=None, parmsOk=True, expLabel=''):
71 delay=None, walk=None, set=None, ippKm=None, parmsOk=True, expLabel=''):
74
72
75 name = project_name
73 name = project_name
76 datatype = datatype
74 datatype = datatype
77 ext = ext
75 ext = ext
78 dpath = dpath
76 dpath = dpath
79 startDate = startDate
77 startDate = startDate
80 endDate = endDate
78 endDate = endDate
81 startTime = startTime
79 startTime = startTime
82 endTime = endTime
80 endTime = endTime
83 online = online
81 online = online
84 delay = delay
82 delay = delay
85 walk = walk
83 walk = walk
86 set = set
84 set = set
87 ippKm = ippKm
85 ippKm = ippKm
88 expLabel = expLabel
86 expLabel = expLabel
89
87
90 self.parmsOk = parmsOk
88 self.parmsOk = parmsOk
91
89
92 def isValid(self):
90 def isValid(self):
93
91
94 return self.parmsOk No newline at end of file
92 return self.parmsOk
@@ -1,225 +1,225
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from figure import Figure
10 from figure import Figure
11
11
12 class Scope(Figure):
12 class Scope(Figure):
13
13
14 isConfig = None
14 isConfig = None
15
15
16 def __init__(self):
16 def __init__(self, **kwargs):
17
17 Figure.__init__(self, **kwargs)
18 self.isConfig = False
18 self.isConfig = False
19 self.WIDTH = 300
19 self.WIDTH = 300
20 self.HEIGHT = 200
20 self.HEIGHT = 200
21 self.counter_imagwr = 0
21 self.counter_imagwr = 0
22
22
23 def getSubplots(self):
23 def getSubplots(self):
24
24
25 nrow = self.nplots
25 nrow = self.nplots
26 ncol = 3
26 ncol = 3
27 return nrow, ncol
27 return nrow, ncol
28
28
29 def setup(self, id, nplots, wintitle, show):
29 def setup(self, id, nplots, wintitle, show):
30
30
31 self.nplots = nplots
31 self.nplots = nplots
32
32
33 self.createFigure(id=id,
33 self.createFigure(id=id,
34 wintitle=wintitle,
34 wintitle=wintitle,
35 show=show)
35 show=show)
36
36
37 nrow,ncol = self.getSubplots()
37 nrow,ncol = self.getSubplots()
38 colspan = 3
38 colspan = 3
39 rowspan = 1
39 rowspan = 1
40
40
41 for i in range(nplots):
41 for i in range(nplots):
42 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
42 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
43
43
44 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
44 def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
45 yreal = y[channelIndexList,:].real
45 yreal = y[channelIndexList,:].real
46 yimag = y[channelIndexList,:].imag
46 yimag = y[channelIndexList,:].imag
47
47
48 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
48 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
49 xlabel = "Range (Km)"
49 xlabel = "Range (Km)"
50 ylabel = "Intensity - IQ"
50 ylabel = "Intensity - IQ"
51
51
52 if not self.isConfig:
52 if not self.isConfig:
53 nplots = len(channelIndexList)
53 nplots = len(channelIndexList)
54
54
55 self.setup(id=id,
55 self.setup(id=id,
56 nplots=nplots,
56 nplots=nplots,
57 wintitle='',
57 wintitle='',
58 show=show)
58 show=show)
59
59
60 if xmin == None: xmin = numpy.nanmin(x)
60 if xmin == None: xmin = numpy.nanmin(x)
61 if xmax == None: xmax = numpy.nanmax(x)
61 if xmax == None: xmax = numpy.nanmax(x)
62 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
62 if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag))
63 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
63 if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag))
64
64
65 self.isConfig = True
65 self.isConfig = True
66
66
67 self.setWinTitle(title)
67 self.setWinTitle(title)
68
68
69 for i in range(len(self.axesList)):
69 for i in range(len(self.axesList)):
70 title = "Channel %d" %(i)
70 title = "Channel %d" %(i)
71 axes = self.axesList[i]
71 axes = self.axesList[i]
72
72
73 axes.pline(x, yreal[i,:],
73 axes.pline(x, yreal[i,:],
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
74 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
75 xlabel=xlabel, ylabel=ylabel, title=title)
75 xlabel=xlabel, ylabel=ylabel, title=title)
76
76
77 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
77 axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2)
78
78
79 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
79 def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax):
80 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
80 y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:])
81 yreal = y.real
81 yreal = y.real
82
82
83 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
83 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
84 xlabel = "Range (Km)"
84 xlabel = "Range (Km)"
85 ylabel = "Intensity"
85 ylabel = "Intensity"
86
86
87 if not self.isConfig:
87 if not self.isConfig:
88 nplots = len(channelIndexList)
88 nplots = len(channelIndexList)
89
89
90 self.setup(id=id,
90 self.setup(id=id,
91 nplots=nplots,
91 nplots=nplots,
92 wintitle='',
92 wintitle='',
93 show=show)
93 show=show)
94
94
95 if xmin == None: xmin = numpy.nanmin(x)
95 if xmin == None: xmin = numpy.nanmin(x)
96 if xmax == None: xmax = numpy.nanmax(x)
96 if xmax == None: xmax = numpy.nanmax(x)
97 if ymin == None: ymin = numpy.nanmin(yreal)
97 if ymin == None: ymin = numpy.nanmin(yreal)
98 if ymax == None: ymax = numpy.nanmax(yreal)
98 if ymax == None: ymax = numpy.nanmax(yreal)
99
99
100 self.isConfig = True
100 self.isConfig = True
101
101
102 self.setWinTitle(title)
102 self.setWinTitle(title)
103
103
104 for i in range(len(self.axesList)):
104 for i in range(len(self.axesList)):
105 title = "Channel %d" %(i)
105 title = "Channel %d" %(i)
106 axes = self.axesList[i]
106 axes = self.axesList[i]
107 ychannel = yreal[i,:]
107 ychannel = yreal[i,:]
108 axes.pline(x, ychannel,
108 axes.pline(x, ychannel,
109 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
109 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
110 xlabel=xlabel, ylabel=ylabel, title=title)
110 xlabel=xlabel, ylabel=ylabel, title=title)
111
111
112
112
113 def run(self, dataOut, id, wintitle="", channelList=None,
113 def run(self, dataOut, id, wintitle="", channelList=None,
114 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
114 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
115 figpath='./', figfile=None, show=True, wr_period=1,
115 figpath='./', figfile=None, show=True, wr_period=1,
116 ftp=False, server=None, folder=None, username=None, password=None, type='power'):
116 ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs):
117
117
118 """
118 """
119
119
120 Input:
120 Input:
121 dataOut :
121 dataOut :
122 id :
122 id :
123 wintitle :
123 wintitle :
124 channelList :
124 channelList :
125 xmin : None,
125 xmin : None,
126 xmax : None,
126 xmax : None,
127 ymin : None,
127 ymin : None,
128 ymax : None,
128 ymax : None,
129 """
129 """
130
130
131 if channelList == None:
131 if channelList == None:
132 channelIndexList = dataOut.channelIndexList
132 channelIndexList = dataOut.channelIndexList
133 else:
133 else:
134 channelIndexList = []
134 channelIndexList = []
135 for channel in channelList:
135 for channel in channelList:
136 if channel not in dataOut.channelList:
136 if channel not in dataOut.channelList:
137 raise ValueError, "Channel %d is not in dataOut.channelList"
137 raise ValueError, "Channel %d is not in dataOut.channelList"
138 channelIndexList.append(dataOut.channelList.index(channel))
138 channelIndexList.append(dataOut.channelList.index(channel))
139
139
140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
140 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
141
141
142 if dataOut.flagDataAsBlock:
142 if dataOut.flagDataAsBlock:
143
143
144 for i in range(dataOut.nProfiles):
144 for i in range(dataOut.nProfiles):
145
145
146 wintitle1 = wintitle + " [Profile = %d] " %i
146 wintitle1 = wintitle + " [Profile = %d] " %i
147
147
148 if type == "power":
148 if type == "power":
149 self.plot_power(dataOut.heightList,
149 self.plot_power(dataOut.heightList,
150 dataOut.data[:,i,:],
150 dataOut.data[:,i,:],
151 id,
151 id,
152 channelIndexList,
152 channelIndexList,
153 thisDatetime,
153 thisDatetime,
154 wintitle1,
154 wintitle1,
155 show,
155 show,
156 xmin,
156 xmin,
157 xmax,
157 xmax,
158 ymin,
158 ymin,
159 ymax)
159 ymax)
160
160
161 if type == "iq":
161 if type == "iq":
162 self.plot_iq(dataOut.heightList,
162 self.plot_iq(dataOut.heightList,
163 dataOut.data[:,i,:],
163 dataOut.data[:,i,:],
164 id,
164 id,
165 channelIndexList,
165 channelIndexList,
166 thisDatetime,
166 thisDatetime,
167 wintitle1,
167 wintitle1,
168 show,
168 show,
169 xmin,
169 xmin,
170 xmax,
170 xmax,
171 ymin,
171 ymin,
172 ymax)
172 ymax)
173
173
174 self.draw()
174 self.draw()
175
175
176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
176 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
177 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
177 figfile = self.getFilename(name = str_datetime) + "_" + str(i)
178
178
179 self.save(figpath=figpath,
179 self.save(figpath=figpath,
180 figfile=figfile,
180 figfile=figfile,
181 save=save,
181 save=save,
182 ftp=ftp,
182 ftp=ftp,
183 wr_period=wr_period,
183 wr_period=wr_period,
184 thisDatetime=thisDatetime)
184 thisDatetime=thisDatetime)
185
185
186 else:
186 else:
187 wintitle += " [Profile = %d] " %dataOut.profileIndex
187 wintitle += " [Profile = %d] " %dataOut.profileIndex
188
188
189 if type == "power":
189 if type == "power":
190 self.plot_power(dataOut.heightList,
190 self.plot_power(dataOut.heightList,
191 dataOut.data,
191 dataOut.data,
192 id,
192 id,
193 channelIndexList,
193 channelIndexList,
194 thisDatetime,
194 thisDatetime,
195 wintitle,
195 wintitle,
196 show,
196 show,
197 xmin,
197 xmin,
198 xmax,
198 xmax,
199 ymin,
199 ymin,
200 ymax)
200 ymax)
201
201
202 if type == "iq":
202 if type == "iq":
203 self.plot_iq(dataOut.heightList,
203 self.plot_iq(dataOut.heightList,
204 dataOut.data,
204 dataOut.data,
205 id,
205 id,
206 channelIndexList,
206 channelIndexList,
207 thisDatetime,
207 thisDatetime,
208 wintitle,
208 wintitle,
209 show,
209 show,
210 xmin,
210 xmin,
211 xmax,
211 xmax,
212 ymin,
212 ymin,
213 ymax)
213 ymax)
214
214
215 self.draw()
215 self.draw()
216
216
217 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
217 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex)
218 figfile = self.getFilename(name = str_datetime)
218 figfile = self.getFilename(name = str_datetime)
219
219
220 self.save(figpath=figpath,
220 self.save(figpath=figpath,
221 figfile=figfile,
221 figfile=figfile,
222 save=save,
222 save=save,
223 ftp=ftp,
223 ftp=ftp,
224 wr_period=wr_period,
224 wr_period=wr_period,
225 thisDatetime=thisDatetime)
225 thisDatetime=thisDatetime)
@@ -1,14 +1,14
1 '''
1 '''
2
2
3 $Author: murco $
3 $Author: murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
4 $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $
5 '''
5 '''
6
6
7 from jroIO_voltage import *
7 from jroIO_voltage import *
8 from jroIO_spectra import *
8 from jroIO_spectra import *
9 from jroIO_heispectra import *
9 from jroIO_heispectra import *
10 from jroIO_usrp import *
10 from jroIO_usrp import *
11
11 from jroIO_digitalRF import *
12 from jroIO_kamisr import *
12 from jroIO_kamisr import *
13 from jroIO_param import *
13 from jroIO_param import *
14 from jroIO_hf import *
14 from jroIO_hf import *
@@ -1,1 +1,1
1 <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="Spectra" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/sp1_f0" /><Parameter format="date" id="191113" name="startDate" value="2017/01/28" /><Parameter format="date" id="191114" name="endDate" value="2017/01/28" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="cursor" value="5" /><Parameter format="int" id="191119" name="skip" value="177" /><Parameter format="int" id="191120" name="walk" value="1" /><Parameter format="int" id="191121" name="verbose" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="PublishData" priority="3" type="other"><Parameter format="int" id="191331" name="zeromq" value="1" /><Parameter format="bool" id="191332" name="verbose" value="0" /><Parameter format="int" id="191333" name="delay" value="0" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></ProcUnit></Project> No newline at end of file
1 <Project description="Testing USRP data reader" id="191" name="test01"><ReadUnit datatype="DigitalRF" id="1911" inputId="0" name="DigitalRFReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="DigitalRF" /><Parameter format="str" id="191112" name="path" value="/home/jchavez/jicamarca/mocked_data" /><Parameter format="date" id="191113" name="startDate" value="2000/07/03" /><Parameter format="date" id="191114" name="endDate" value="2017/07/03" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="ippKm" value="60" /><Parameter format="int" id="191119" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="Voltage" id="1912" inputId="1911" name="VoltageProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="CohInt" priority="2" type="external"><Parameter format="float" id="191221" name="n" value="1" /></Operation><Operation id="19123" name="Scope" priority="3" type="external"><Parameter format="int" id="191231" name="id" value="121" /><Parameter format="str" id="191232" name="wintitle" value="Scope" /></Operation></ProcUnit></Project> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now