##// END OF EJS Templates
lectura de subchannels
Jose Chavez -
r985:c13d556a2908
parent child
Show More
@@ -7,6 +7,7 Created on Jul 3, 2014
7 import os
7 import os
8 import datetime
8 import datetime
9 import numpy
9 import numpy
10 import timeit
10 from profilehooks import coverage, profile
11 from profilehooks import coverage, profile
11 from fractions import Fraction
12 from fractions import Fraction
12
13
@@ -19,6 +20,7 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
19 from schainpy.model.data.jrodata import Voltage
20 from schainpy.model.data.jrodata import Voltage
20 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
21 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
21 from time import time
22 from time import time
23
22 import cPickle
24 import cPickle
23 try:
25 try:
24 import digital_rf
26 import digital_rf
@@ -79,7 +81,7 class DigitalRFReader(ProcessingUnit):
79
81
80 self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth
82 self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth
81
83
82 self.dataOut.channelList = self.__channelList
84 self.dataOut.channelList = range(self.__num_subchannels)
83
85
84 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
86 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
85
87
@@ -223,12 +225,19 class DigitalRFReader(ProcessingUnit):
223
225
224 top_properties = self.digitalReadObj.get_properties(channelNameList[channelList[0]])
226 top_properties = self.digitalReadObj.get_properties(channelNameList[channelList[0]])
225
227
228
229
230
231
232
233 self.__num_subchannels = top_properties['num_subchannels']
226 self.__sample_rate = 1.0 * top_properties['sample_rate_numerator'] / top_properties['sample_rate_denominator']
234 self.__sample_rate = 1.0 * top_properties['sample_rate_numerator'] / top_properties['sample_rate_denominator']
227
235
228 # self.__samples_per_file = top_properties['samples_per_file'][0]
236 # self.__samples_per_file = top_properties['samples_per_file'][0]
229 self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15?
237 self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15?
230
238
231 this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]])
239 this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]])
240 print this_metadata_file
232 metadata_bounds = this_metadata_file.get_bounds()
241 metadata_bounds = this_metadata_file.get_bounds()
233 self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ## GET FIRST HEADER
242 self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ## GET FIRST HEADER
234 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
243 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
@@ -345,7 +354,7 class DigitalRFReader(ProcessingUnit):
345
354
346 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
355 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
347
356
348 self.__data_buffer = numpy.zeros((self.__nChannels, self.__samples_to_read), dtype = numpy.complex)
357 self.__data_buffer = numpy.zeros((self.__num_subchannels, self.__samples_to_read), dtype = numpy.complex)
349
358
350 self.__setFileHeader()
359 self.__setFileHeader()
351 self.isConfig = True
360 self.isConfig = True
@@ -413,28 +422,29 class DigitalRFReader(ProcessingUnit):
413
422
414 dataOk = False
423 dataOk = False
415 for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS?
424 for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS?
416 try:
425 for indexSubchannel in range(self.__num_subchannels):
417 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
426 try:
418 self.__samples_to_read,
427 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
419 thisChannelName)
428 self.__samples_to_read,
420 except IOError, e:
429 thisChannelName, sub_channel=indexSubchannel)
421 #read next profile
430 except IOError, e:
422 self.__flagDiscontinuousBlock = True
431 #read next profile
423 print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
432 self.__flagDiscontinuousBlock = True
424 break
433 print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
434 break
425
435
426 if result.shape[0] != self.__samples_to_read:
436 if result.shape[0] != self.__samples_to_read:
427 self.__flagDiscontinuousBlock = True
437 self.__flagDiscontinuousBlock = True
428 print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
438 print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
429 result.shape[0],
439 result.shape[0],
430 self.__samples_to_read)
440 self.__samples_to_read)
431 break
441 break
432
442
433 self.__data_buffer[indexChannel,:] = result*volt_scale
443 self.__data_buffer[indexSubchannel,:] = result*volt_scale
434
444
435 indexChannel += 1
445 indexChannel += 1
436
446
437 dataOk = True
447 dataOk = True
438
448
439 self.__utctime = self.__thisUnixSample/self.__sample_rate
449 self.__utctime = self.__thisUnixSample/self.__sample_rate
440
450
@@ -601,12 +611,12 class DigitalRFWriter(Operation):
601 compression_level = 1
611 compression_level = 1
602 checksum = False
612 checksum = False
603 is_complex = True
613 is_complex = True
604 num_subchannels = 2
614 num_subchannels = len(dataOut.channelList)
605 is_continuous = True
615 is_continuous = True
606 marching_periods = False
616 marching_periods = False
607
617
608 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, 100,
618 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, 100,
609 1000, start_global_index,
619 100, start_global_index,
610 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
620 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
611 is_complex, num_subchannels, is_continuous, marching_periods)
621 is_complex, num_subchannels, is_continuous, marching_periods)
612
622
@@ -620,6 +630,8 class DigitalRFWriter(Operation):
620
630
621 self.isConfig = True
631 self.isConfig = True
622 self.currentSample = 0
632 self.currentSample = 0
633 self.oldAverage = 0
634 self.count = 0
623 return
635 return
624
636
625 def writeMetadata(self):
637 def writeMetadata(self):
@@ -638,7 +650,14 class DigitalRFWriter(Operation):
638 for channel in self.dataOut.channelList:
650 for channel in self.dataOut.channelList:
639 self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real
651 self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real
640 self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag
652 self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag
653 t0 = time()
641 self.digitalWriteObj.rf_write(self.arr_data)
654 self.digitalWriteObj.rf_write(self.arr_data)
655 self.executionTime = time() - t0
656 if self.oldAverage is None: self.oldAverage = self.executionTime
657 self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0)
658 self.count = self.count + 1.0
659 if self.oldAverage is None: self.oldAverage = self.executionTime
660
642 return
661 return
643
662
644 def run(self, dataOut, frequency=49.92e6, path=None, **kwargs):
663 def run(self, dataOut, frequency=49.92e6, path=None, **kwargs):
@@ -661,6 +680,7 class DigitalRFWriter(Operation):
661
680
662 def close(self):
681 def close(self):
663 print '[Writing] - Closing files '
682 print '[Writing] - Closing files '
683 print 'Average of writing to digital rf format is ', self.oldAverage * 1000
664 try:
684 try:
665 self.digitalWriteObj.close()
685 self.digitalWriteObj.close()
666 except:
686 except:
@@ -1,1 +1,1
1 <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="VoltageReader" id="1911" inputId="0" name="VoltageReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="VoltageReader" /><Parameter format="str" id="191112" name="path" value="/home/jchavez/jicamarca/jro_data/rawdata" /><Parameter format="date" id="191113" name="startDate" value="2010/10/28" /><Parameter format="date" id="191114" name="endDate" value="2017/10/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="online" value="0" /><Parameter format="int" id="191119" name="walk" value="0" /></Operation><Operation id="19112" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="VoltageProc" id="1912" inputId="1911" name="VoltageProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="DigitalRFWriter" priority="2" type="other"><Parameter format="str" id="191221" name="path" value="/media/jchavez/DATA/mocked_data/voltage" /></Operation></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="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="Scope" priority="2" type="external"><Parameter format="int" id="191221" name="id" value="121" /><Parameter format="str" id="191222" 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