##// END OF EJS Templates
agregado metodos a header class
Jose Chavez -
r980:ea5ace19bd59
parent child
Show More
@@ -7,6 +7,7 import sys
7 import numpy
7 import numpy
8 import copy
8 import copy
9 import datetime
9 import datetime
10 import inspect
10
11
11 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 299792458
12 SPEED_OF_LIGHT = 3e8
13 SPEED_OF_LIGHT = 3e8
@@ -82,6 +83,9 class Header(object):
82 def write(self):
83 def write(self):
83
84
84 raise NotImplementedError
85 raise NotImplementedError
86
87 def getAllowedArgs(self):
88 return inspect.getargspec(self.__init__).args
85
89
86 def printInfo(self):
90 def printInfo(self):
87
91
@@ -115,6 +119,7 class BasicHeader(Header):
115 dstFlag = None
119 dstFlag = None
116 errorCount = None
120 errorCount = None
117 datatime = None
121 datatime = None
122 structure = BASIC_STRUCTURE
118 __LOCALTIME = None
123 __LOCALTIME = None
119
124
120 def __init__(self, useLocalTime=True):
125 def __init__(self, useLocalTime=True):
@@ -189,7 +194,8 class SystemHeader(Header):
189 nChannels = None
194 nChannels = None
190 adcResolution = None
195 adcResolution = None
191 pciDioBusWidth = None
196 pciDioBusWidth = None
192
197 structure = SYSTEM_STRUCTURE
198
193 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
199 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
194
200
195 self.size = 24
201 self.size = 24
@@ -198,7 +204,7 class SystemHeader(Header):
198 self.nChannels = nChannels
204 self.nChannels = nChannels
199 self.adcResolution = adcResolution
205 self.adcResolution = adcResolution
200 self.pciDioBusWidth = pciDioBusWith
206 self.pciDioBusWidth = pciDioBusWith
201
207
202 def read(self, fp):
208 def read(self, fp):
203 self.length = 0
209 self.length = 0
204 try:
210 try:
@@ -264,7 +270,7 class RadarControllerHeader(Header):
264 rangeIpp = None
270 rangeIpp = None
265 rangeTxA = None
271 rangeTxA = None
266 rangeTxB = None
272 rangeTxB = None
267
273 structure = RADAR_STRUCTURE
268 __size = None
274 __size = None
269
275
270 def __init__(self, expType=2, nTx=1,
276 def __init__(self, expType=2, nTx=1,
@@ -540,15 +546,18 class ProcessingHeader(Header):
540 nCohInt = None
546 nCohInt = None
541 nIncohInt = None
547 nIncohInt = None
542 totalSpectra = None
548 totalSpectra = None
543
549 structure = PROCESSING_STRUCTURE
544 flag_dc = None
550 flag_dc = None
545 flag_cspc = None
551 flag_cspc = None
546
552
547 def __init__(self):
553 def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0,processFlags=0, nCohInt=0,
554 nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0,
555 code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False
556 ):
548
557
549 # self.size = 0
558 # self.size = 0
550 self.dtype = 0
559 self.dtype = dtype
551 self.blockSize = 0
560 self.blockSize = blockSize
552 self.profilesPerBlock = 0
561 self.profilesPerBlock = 0
553 self.dataBlocksPerFile = 0
562 self.dataBlocksPerFile = 0
554 self.nWindows = 0
563 self.nWindows = 0
@@ -572,6 +581,7 class ProcessingHeader(Header):
572 self.flag_decode = False
581 self.flag_decode = False
573 self.flag_deflip = False
582 self.flag_deflip = False
574 self.length = 0
583 self.length = 0
584
575 def read(self, fp):
585 def read(self, fp):
576 self.length = 0
586 self.length = 0
577 try:
587 try:
@@ -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 from profilehooks import coverage
10 from fractions import Fraction
11 from fractions import Fraction
11
12
12 try:
13 try:
@@ -251,7 +252,6 class DigitalRFReader(ProcessingUnit):
251
252
252 self.__firstHeigth = 0
253 self.__firstHeigth = 0
253
254
254
255 try:
255 try:
256 codeType = self.fixed_metadata_dict['codeType']
256 codeType = self.fixed_metadata_dict['codeType']
257 except:
257 except:
@@ -386,7 +386,7 class DigitalRFReader(ProcessingUnit):
386
386
387 return False
387 return False
388
388
389 def __readNextBlock(self, seconds=30, volt_scale = 218776):
389 def __readNextBlock(self, seconds=30, volt_scale = 1):
390 '''
390 '''
391 '''
391 '''
392
392
@@ -550,32 +550,37 class DigitalRFWriter(Operation):
550 Operation.__init__(self, **kwargs)
550 Operation.__init__(self, **kwargs)
551 self.dataOut = None
551 self.dataOut = None
552
552
553 def setup(self, dataIn, path, set=0, ext='.h5'):
553 def setup(self, dataOut, path, set=0, metadataFile='metadata', ext='.h5'):
554 '''
554 '''
555 In this method we should set all initial parameters.
555 In this method we should set all initial parameters.
556
556
557 Input:
557 Input:
558 dataIn : Input data will also be outputa data
558 dataOut : Input data will also be outputa data
559
559
560 '''
560 '''
561
561
562 self.__ippSeconds = dataIn.ippSeconds
562 self.__ippSeconds = dataOut.ippSeconds
563 self.__deltaH = dataIn.getDeltaH()
563 self.__deltaH = dataOut.getDeltaH()
564 self.__sample_rate = 1e6*0.15/self.__deltaH
564 self.__sample_rate = 1e6*0.15/self.__deltaH
565 self.__dtype = dataIn.dtype
565 self.__dtype = dataOut.dtype
566 if len(dataIn.dtype) == 2:
566 if len(dataOut.dtype) == 2:
567 self.__dtype = dataIn.dtype[0]
567 self.__dtype = dataOut.dtype[0]
568 self.__nSamples = dataIn.systemHeaderObj.nSamples
568 self.__nSamples = dataOut.systemHeaderObj.nSamples
569 self.__nProfiles = dataIn.nProfiles
569 self.__nProfiles = dataOut.nProfiles
570 self.__blocks_per_file = dataIn.processingHeaderObj.dataBlocksPerFile
570 self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile
571
571 self.arr_data = arr_data = numpy.ones((self.__nSamples, 1), dtype=[('r', self.__dtype), ('i', self.__dtype)])
572 file_cadence_millisecs = 1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate * 1000
572
573 sub_cadence_secs = 10 * file_cadence_millisecs
573 file_cadence_millisecs = long(1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate * 1000)
574 sub_cadence_secs = file_cadence_millisecs
575
576 #print file_cadence_millisecs
577 #print sub_cadence_secs
578
574 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
579 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
575 sample_rate_numerator = long(sample_rate_fraction.numerator)
580 sample_rate_numerator = long(sample_rate_fraction.numerator)
576 sample_rate_denominator = long(sample_rate_fraction.denominator)
581 sample_rate_denominator = long(sample_rate_fraction.denominator)
577 start_global_index = dataIn.utctime * self.__sample_rate
582 start_global_index = dataOut.utctime * self.__sample_rate
578 self.arr_data = arr_data = numpy.ones((self.__nSamples, 1), dtype=[('r', self.__dtype), ('i', self.__dtype)])
583
579 uuid = 'prueba'
584 uuid = 'prueba'
580 compression_level = 1
585 compression_level = 1
581 checksum = False
586 checksum = False
@@ -584,42 +589,59 class DigitalRFWriter(Operation):
584 is_continuous = True
589 is_continuous = True
585 marching_periods = False
590 marching_periods = False
586
591
587 self.digitalWriteObj = digital_rf.DigitalRFWriter("/home/jchavez/jicamarca/mocked_data/voltage", self.__dtype, sub_cadence_secs,
592 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, sub_cadence_secs,
588 file_cadence_millisecs, start_global_index,
593 file_cadence_millisecs, start_global_index,
589 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
594 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
590 is_complex, num_subchannels, is_continuous, marching_periods)
595 is_complex, num_subchannels, is_continuous, marching_periods)
596
597 metadata_dir = os.path.join(path, 'metadata')
598 os.system('mkdir %s' % (metadata_dir))
599
600 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, 236, file_cadence_millisecs / 1000,
601 sample_rate_numerator, sample_rate_denominator,
602 metadataFile)
591
603
592
604
593 self.isConfig = True
605 self.isConfig = True
594
606 self.currentSample = 0
595 return
607 return
596
608
597 def run(self, dataIn, path=None, **kwargs):
609 @coverage
610 def run(self, dataOut, path=None, **kwargs):
598 '''
611 '''
599 This method will be called many times so here you should put all your code
612 This method will be called many times so here you should put all your code
600
613
601 Inputs:
614 Inputs:
602
615
603 dataIn : object with the data
616 dataOut : object with the data
604
617
605 '''
618 '''
606
619 #print dataOut.__dict__
607 self.dataOut = dataIn
620 self.dataOut = dataOut
608
621
609 if not self.isConfig:
622 if not self.isConfig:
610 self.setup(dataIn, path, **kwargs)
623 self.setup(dataOut, path, **kwargs)
611
624
612 samples = len(self.dataOut.data[0])
625 samples = len(self.dataOut.data[0])
613
626
614 for i in range(samples):
627 for i in range(samples):
615 self.arr_data[i]['r'] = dataIn.data[0][i].real
628 self.arr_data[i]['r'] = dataOut.data[0][i].real
616 self.arr_data[i]['i'] = dataIn.data[0][i].imag
629 self.arr_data[i]['i'] = dataOut.data[0][i].imag
617
618 if dataIn.flagNoData:
619 self.digitalWriteObj.close()
620
621 self.digitalWriteObj.rf_write(self.arr_data)
630 self.digitalWriteObj.rf_write(self.arr_data)
622
631 start_idx = self.__sample_rate * dataOut.utctime
632 metadata_dict = {}
633 metadata_dict['frequency'] = 49.92e6
634 metadata_dict['blablabla'] = 49.92e6
635 self.currentSample += 1
636 if self.dataOut.flagDataAsBlock:
637 self.digitalMetadataWriteObj.write(start_idx, metadata_dict)
638 elif self.currentSample == 1:
639 print '[Writing] - Writing metadata'
640 self.digitalMetadataWriteObj.write(start_idx, metadata_dict)
641 if self.currentSample == self.__nProfiles: self.currentSample = 0
642 def close(self):
643 print '[Writing] - Closing files '
644 self.digitalWriteObj.close()
623 #raise
645 #raise
624 if __name__ == '__main__':
646 if __name__ == '__main__':
625
647
@@ -628,4 +650,4 if __name__ == '__main__':
628 while True:
650 while True:
629 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
651 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
630 # readObj.printInfo()
652 # readObj.printInfo()
631 readObj.printNumberOfBlock()
653 #readObj.printNumberOfBlock()
@@ -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="/home/jchavez/jicamarca/data_sink/" /></Operation></ProcUnit></Project> No newline at end of file
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="/home/jchavez/jicamarca/mocked_data/voltage" /></Operation></ProcUnit></Project> No newline at end of file
@@ -25,8 +25,12 if __name__ == '__main__':
25 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
25 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
26 inputId=readUnitConfObj.getId())
26 inputId=readUnitConfObj.getId())
27
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
28 opObj10 = procUnitConfObj0.addOperation(name='DigitalRFWriter', optype='other')
32 opObj10 = procUnitConfObj0.addOperation(name='DigitalRFWriter', optype='other')
29 opObj10.addParameter(name='path', value='/home/jchavez/jicamarca/data_sink/', format='str')
33 opObj10.addParameter(name='path', value='/home/jchavez/jicamarca/mocked_data/voltage', format='str')
30 # opObj10.addParameter(name='minHei', value='0', format='float')
34 # opObj10.addParameter(name='minHei', value='0', format='float')
31 # opObj10.addParameter(name='maxHei', value='8', format='float')
35 # opObj10.addParameter(name='maxHei', value='8', format='float')
32
36
General Comments 0
You need to be logged in to leave comments. Login now