##// END OF EJS Templates
agregado metodos a header class
Jose Chavez -
r980:ea5ace19bd59
parent child
Show More
@@ -7,6 +7,7 import sys
7 7 import numpy
8 8 import copy
9 9 import datetime
10 import inspect
10 11
11 12 SPEED_OF_LIGHT = 299792458
12 13 SPEED_OF_LIGHT = 3e8
@@ -82,6 +83,9 class Header(object):
82 83 def write(self):
83 84
84 85 raise NotImplementedError
86
87 def getAllowedArgs(self):
88 return inspect.getargspec(self.__init__).args
85 89
86 90 def printInfo(self):
87 91
@@ -115,6 +119,7 class BasicHeader(Header):
115 119 dstFlag = None
116 120 errorCount = None
117 121 datatime = None
122 structure = BASIC_STRUCTURE
118 123 __LOCALTIME = None
119 124
120 125 def __init__(self, useLocalTime=True):
@@ -189,7 +194,8 class SystemHeader(Header):
189 194 nChannels = None
190 195 adcResolution = None
191 196 pciDioBusWidth = None
192
197 structure = SYSTEM_STRUCTURE
198
193 199 def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0):
194 200
195 201 self.size = 24
@@ -198,7 +204,7 class SystemHeader(Header):
198 204 self.nChannels = nChannels
199 205 self.adcResolution = adcResolution
200 206 self.pciDioBusWidth = pciDioBusWith
201
207
202 208 def read(self, fp):
203 209 self.length = 0
204 210 try:
@@ -264,7 +270,7 class RadarControllerHeader(Header):
264 270 rangeIpp = None
265 271 rangeTxA = None
266 272 rangeTxB = None
267
273 structure = RADAR_STRUCTURE
268 274 __size = None
269 275
270 276 def __init__(self, expType=2, nTx=1,
@@ -540,15 +546,18 class ProcessingHeader(Header):
540 546 nCohInt = None
541 547 nIncohInt = None
542 548 totalSpectra = None
543
549 structure = PROCESSING_STRUCTURE
544 550 flag_dc = None
545 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 558 # self.size = 0
550 self.dtype = 0
551 self.blockSize = 0
559 self.dtype = dtype
560 self.blockSize = blockSize
552 561 self.profilesPerBlock = 0
553 562 self.dataBlocksPerFile = 0
554 563 self.nWindows = 0
@@ -572,6 +581,7 class ProcessingHeader(Header):
572 581 self.flag_decode = False
573 582 self.flag_deflip = False
574 583 self.length = 0
584
575 585 def read(self, fp):
576 586 self.length = 0
577 587 try:
@@ -7,6 +7,7 Created on Jul 3, 2014
7 7 import os
8 8 import datetime
9 9 import numpy
10 from profilehooks import coverage
10 11 from fractions import Fraction
11 12
12 13 try:
@@ -251,7 +252,6 class DigitalRFReader(ProcessingUnit):
251 252
252 253 self.__firstHeigth = 0
253 254
254
255 255 try:
256 256 codeType = self.fixed_metadata_dict['codeType']
257 257 except:
@@ -386,7 +386,7 class DigitalRFReader(ProcessingUnit):
386 386
387 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 550 Operation.__init__(self, **kwargs)
551 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 555 In this method we should set all initial parameters.
556 556
557 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
563 self.__deltaH = dataIn.getDeltaH()
562 self.__ippSeconds = dataOut.ippSeconds
563 self.__deltaH = dataOut.getDeltaH()
564 564 self.__sample_rate = 1e6*0.15/self.__deltaH
565 self.__dtype = dataIn.dtype
566 if len(dataIn.dtype) == 2:
567 self.__dtype = dataIn.dtype[0]
568 self.__nSamples = dataIn.systemHeaderObj.nSamples
569 self.__nProfiles = dataIn.nProfiles
570 self.__blocks_per_file = dataIn.processingHeaderObj.dataBlocksPerFile
571
572 file_cadence_millisecs = 1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate * 1000
573 sub_cadence_secs = 10 * file_cadence_millisecs
565 self.__dtype = dataOut.dtype
566 if len(dataOut.dtype) == 2:
567 self.__dtype = dataOut.dtype[0]
568 self.__nSamples = dataOut.systemHeaderObj.nSamples
569 self.__nProfiles = dataOut.nProfiles
570 self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile
571 self.arr_data = arr_data = numpy.ones((self.__nSamples, 1), dtype=[('r', self.__dtype), ('i', self.__dtype)])
572
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 579 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
575 580 sample_rate_numerator = long(sample_rate_fraction.numerator)
576 581 sample_rate_denominator = long(sample_rate_fraction.denominator)
577 start_global_index = dataIn.utctime * self.__sample_rate
578 self.arr_data = arr_data = numpy.ones((self.__nSamples, 1), dtype=[('r', self.__dtype), ('i', self.__dtype)])
582 start_global_index = dataOut.utctime * self.__sample_rate
583
579 584 uuid = 'prueba'
580 585 compression_level = 1
581 586 checksum = False
@@ -584,42 +589,59 class DigitalRFWriter(Operation):
584 589 is_continuous = True
585 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 593 file_cadence_millisecs, start_global_index,
589 594 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
590 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 605 self.isConfig = True
594
606 self.currentSample = 0
595 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 612 This method will be called many times so here you should put all your code
600 613
601 614 Inputs:
602 615
603 dataIn : object with the data
616 dataOut : object with the data
604 617
605 618 '''
606
607 self.dataOut = dataIn
619 #print dataOut.__dict__
620 self.dataOut = dataOut
608 621
609 622 if not self.isConfig:
610 self.setup(dataIn, path, **kwargs)
623 self.setup(dataOut, path, **kwargs)
611 624
612 625 samples = len(self.dataOut.data[0])
613 626
614 627 for i in range(samples):
615 self.arr_data[i]['r'] = dataIn.data[0][i].real
616 self.arr_data[i]['i'] = dataIn.data[0][i].imag
617
618 if dataIn.flagNoData:
619 self.digitalWriteObj.close()
620
628 self.arr_data[i]['r'] = dataOut.data[0][i].real
629 self.arr_data[i]['i'] = dataOut.data[0][i].imag
621 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 645 #raise
624 646 if __name__ == '__main__':
625 647
@@ -628,4 +650,4 if __name__ == '__main__':
628 650 while True:
629 651 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
630 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 25 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc',
26 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 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 34 # opObj10.addParameter(name='minHei', value='0', format='float')
31 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