##// END OF EJS Templates
hora y fecha en el primer bloque hdf5 >> consola
hora y fecha en el primer bloque hdf5 >> consola

File last commit:

r1338:317db0cd9a09
r1400:005589ae0527
Show More
jroIO_digitalRF.py
793 lines | 28.7 KiB | text/x-python | PythonLexer
/ schainpy / model / io / jroIO_digitalRF.py
Jose Chavez
voltage DigitalRFReader funcionando
r973 '''
Created on Jul 3, 2014
@author: roj-idl71
'''
Jose Chavez
tests
r991 # SUBCHANNELS EN VEZ DE CHANNELS
# BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO
# ACTUALIZACION DE VERSION
# HEADERS
# MODULO DE ESCRITURA
# METADATA
Jose Chavez
voltage DigitalRFReader funcionando
r973 import os
Errors handling and gracefully terminate main process
r1241 import time
Jose Chavez
voltage DigitalRFReader funcionando
r973 import datetime
import numpy
Jose Chavez
lectura de subchannels
r985 import timeit
Jose Chavez
writing rf data, falta metadata
r979 from fractions import Fraction
update jroIO_digitalRF.py
r1263 from time import time
Add sleep for reload in online mode jroIO_digitalRF.py
r1266 from time import sleep
Jose Chavez
voltage DigitalRFReader funcionando
r973
Errors handling and gracefully terminate main process
r1241 import schainpy.admin
Jose Chavez
voltage DigitalRFReader funcionando
r973 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
from schainpy.model.data.jrodata import Voltage
George Yong
Multiprocessing for digitalRF just for reading Unit(Task #1461 )
r1192 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
Jose Chavez
lectura de subchannels
r985
George Yong
Python 2to3, Spectra (all operations) working
r1167 import pickle
Jose Chavez
voltage DigitalRFReader funcionando
r973 try:
import digital_rf
except:
Juan C. Espinoza
Fix CLI and remove imports warnings
r1284 pass
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
formatting, template actualizado, decimation a 300
r1092
Jose Chavez
voltage DigitalRFReader funcionando
r973 class DigitalRFReader(ProcessingUnit):
'''
classdocs
'''
George Yong
Multiprocessing for digitalRF just for reading Unit(Task #1461 )
r1192 def __init__(self):
Jose Chavez
voltage DigitalRFReader funcionando
r973 '''
Constructor
'''
George Yong
Multiprocessing for digitalRF just for reading Unit(Task #1461 )
r1192 ProcessingUnit.__init__(self)
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut = Voltage()
self.__printInfo = True
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.__flagDiscontinuousBlock = False
self.__bufferIndex = 9999999
update jroIO_digitalRF.py
r1263 self.__codeType = 0
self.__ippKm = None
self.__nCode = None
self.__nBaud = None
self.__code = None
self.dtype = None
self.oldAverage = None
self.path = None
Jose Chavez
voltage DigitalRFReader funcionando
r973
Jose Chavez
tests
r991 def close(self):
George Yong
Python 2to3, Spectra (all operations) working
r1167 print('Average of writing to digital rf format is ', self.oldAverage * 1000)
Jose Chavez
tests
r991 return
Jose Chavez
voltage DigitalRFReader funcionando
r973 def __getCurrentSecond(self):
José Chávez
formatting, template actualizado, decimation a 300
r1092 return self.__thisUnixSample / self.__sample_rate
Jose Chavez
voltage DigitalRFReader funcionando
r973
thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
def __setFileHeader(self):
'''
In this method will be initialized every parameter of dataOut object (header, no data)
'''
José Chávez
formatting, template actualizado, decimation a 300
r1092 ippSeconds = 1.0 * self.__nSamples / self.__sample_rate
nProfiles = 1.0 / ippSeconds # Number of profiles in one second
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
merge from master
r1054 try:
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
self.__radarControllerHeader)
José Chávez
merge from master
r1054 except:
self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
José Chávez
formatting, template actualizado, decimation a 300
r1092 txA=0,
txB=0,
nWindows=1,
nHeights=self.__nSamples,
firstHeight=self.__firstHeigth,
deltaHeight=self.__deltaHeigth,
codeType=self.__codeType,
nCode=self.__nCode, nBaud=self.__nBaud,
code=self.__code)
José Chávez
merge from master
r1054 try:
self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader)
except:
self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
nProfiles=nProfiles,
José Chávez
formatting, template actualizado, decimation a 300
r1092 nChannels=len(
self.__channelList),
José Chávez
merge from master
r1054 adcResolution=14)
update jroIO_digitalRF.py
r1263 self.dataOut.type = "Voltage"
José Chávez
formatting, template actualizado, decimation a 300
r1092
update jroIO_digitalRF.py
r1263 self.dataOut.data = None
Jose Chavez
voltage DigitalRFReader funcionando
r973
Jose Chavez
setting all headers all the time
r981 self.dataOut.dtype = self.dtype
Jose Chavez
voltage DigitalRFReader funcionando
r973
Jose Chavez
setting all headers all the time
r981 # self.dataOut.nChannels = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973
Jose Chavez
setting all headers all the time
r981 # self.dataOut.nHeights = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.nProfiles = int(nProfiles)
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.heightList = self.__firstHeigth + \
José Chávez
formatting, template actualizado, decimation a 300
r1092 numpy.arange(self.__nSamples, dtype=numpy.float) * \
self.__deltaHeigth
Jose Chavez
voltage DigitalRFReader funcionando
r973
George Yong
Python 2to3, Spectra (all operations) working
r1167 self.dataOut.channelList = list(range(self.__num_subchannels))
Jose Chavez
voltage DigitalRFReader funcionando
r973
Add metadata attribute to data types
r1338 self.dataOut.blocksize = self.dataOut.nChannels * self.dataOut.nHeights
Jose Chavez
voltage DigitalRFReader funcionando
r973
Jose Chavez
setting all headers all the time
r981 # self.dataOut.channelIndexList = None
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.flagNoData = True
Jose Chavez
algunos cambios
r982
Jose Chavez
setting all headers all the time
r981 self.dataOut.flagDataAsBlock = False
# Set to TRUE if the data is discontinuous
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.dataOut.flagDiscontinuousBlock = False
update jroIO_digitalRF.py
r1263 self.dataOut.utctime = None
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
formatting, template actualizado, decimation a 300
r1092 # timezone like jroheader, difference in minutes between UTC and localtime
update jroIO_digitalRF.py
r1263 self.dataOut.timeZone = self.__timezone / 60
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.dstFlag = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.errorCount = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
merge from master
r1054 try:
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.dataOut.nCohInt = self.fixed_metadata_dict.get(
'nCohInt', self.nCohInt)
Jose Chavez
algunos cambios
r982
José Chávez
formatting, template actualizado, decimation a 300
r1092 # asumo que la data esta decodificada
self.dataOut.flagDecodeData = self.fixed_metadata_dict.get(
'flagDecodeData', self.flagDecodeData)
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
formatting, template actualizado, decimation a 300
r1092 # asumo que la data esta sin flip
self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData']
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT']
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime']
José Chávez
merge from master
r1054 except:
pass
Jose Chavez
voltage DigitalRFReader funcionando
r973
self.dataOut.ippSeconds = ippSeconds
Jose Chavez
setting all headers all the time
r981 # Time interval between profiles
# self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.frequency = self.__frequency
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.realtime = self.__online
Jose Chavez
voltage DigitalRFReader funcionando
r973
def findDatafiles(self, path, startDate=None, endDate=None):
if not os.path.isdir(path):
return []
try:
José Chávez
formatting, template actualizado, decimation a 300
r1092 digitalReadObj = digital_rf.DigitalRFReader(
path, load_all_metadata=True)
Jose Chavez
voltage DigitalRFReader funcionando
r973 except:
digitalReadObj = digital_rf.DigitalRFReader(path)
update jroIO_digitalRF.py
r1263 channelNameList = digitalReadObj.get_channels()
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not channelNameList:
return []
update jroIO_digitalRF.py
r1263 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 sample_rate = metadata_dict['sample_rate'][0]
Jose Chavez
voltage DigitalRFReader funcionando
r973
this_metadata_file = digitalReadObj.get_metadata(channelNameList[0])
try:
update jroIO_digitalRF.py
r1263 timezone = this_metadata_file['timezone'].value
Jose Chavez
voltage DigitalRFReader funcionando
r973 except:
update jroIO_digitalRF.py
r1263 timezone = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
formatting, template actualizado, decimation a 300
r1092 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(
channelNameList[0]) / sample_rate - timezone
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not startDate:
update jroIO_digitalRF.py
r1263 startDate = startDatetime.date()
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not endDate:
update jroIO_digitalRF.py
r1263 endDate = endDatatime.date()
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 dateList = []
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 thisDatetime = startDatetime
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
formatting, template actualizado, decimation a 300
r1092 while(thisDatetime <= endDatatime):
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 thisDate = thisDatetime.date()
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 if thisDate < startDate:
Jose Chavez
voltage DigitalRFReader funcionando
r973 continue
update jroIO_digitalRF.py
r1263 if thisDate > endDate:
Jose Chavez
voltage DigitalRFReader funcionando
r973 break
dateList.append(thisDate)
thisDatetime += datetime.timedelta(1)
return dateList
José Chávez
formatting, template actualizado, decimation a 300
r1092 def setup(self, path=None,
startDate=None,
endDate=None,
startTime=datetime.time(0, 0, 0),
endTime=datetime.time(23, 59, 59),
channelList=None,
nSamples=None,
online=False,
delay=60,
buffer_size=1024,
ippKm=None,
nCohInt=1,
nCode=1,
nBaud=1,
flagDecodeData=False,
code=numpy.ones((1, 1), dtype=numpy.int),
**kwargs):
Jose Chavez
voltage DigitalRFReader funcionando
r973 '''
In this method we should set all initial parameters.
Inputs:
path
startDate
endDate
startTime
update jroIO_digitalRF.py
r1263 endTime
Jose Chavez
voltage DigitalRFReader funcionando
r973 set
expLabel
ext
online
delay
'''
update jroIO_digitalRF.py
r1263 self.path = path
self.nCohInt = nCohInt
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.flagDecodeData = flagDecodeData
update jroIO_digitalRF.py
r1263 self.i = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973 if not os.path.isdir(path):
George Yong
Python 2to3, Spectra (all operations) working
r1167 raise ValueError("[Reading] Directory %s does not exist" % path)
Jose Chavez
voltage DigitalRFReader funcionando
r973
try:
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.digitalReadObj = digital_rf.DigitalRFReader(
path, load_all_metadata=True)
Jose Chavez
voltage DigitalRFReader funcionando
r973 except:
self.digitalReadObj = digital_rf.DigitalRFReader(path)
update jroIO_digitalRF.py
r1263 channelNameList = self.digitalReadObj.get_channels()
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not channelNameList:
George Yong
Python 2to3, Spectra (all operations) working
r1167 raise ValueError("[Reading] Directory %s does not have any files" % path)
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not channelList:
George Yong
Python 2to3, Spectra (all operations) working
r1167 channelList = list(range(len(channelNameList)))
Jose Chavez
voltage DigitalRFReader funcionando
r973
########## Reading metadata ######################
update jroIO_digitalRF.py
r1263 top_properties = self.digitalReadObj.get_properties(
José Chávez
formatting, template actualizado, decimation a 300
r1092 channelNameList[channelList[0]])
Jose Chavez
lectura de subchannels
r985
update jroIO_digitalRF.py
r1263 self.__num_subchannels = top_properties['num_subchannels']
self.__sample_rate = 1.0 * \
José Chávez
formatting, template actualizado, decimation a 300
r1092 top_properties['sample_rate_numerator'] / \
top_properties['sample_rate_denominator']
Jose Chavez
setting all headers all the time
r981 # self.__samples_per_file = top_properties['samples_per_file'][0]
update jroIO_digitalRF.py
r1263 self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15?
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 this_metadata_file = self.digitalReadObj.get_digital_metadata(
José Chávez
formatting, template actualizado, decimation a 300
r1092 channelNameList[channelList[0]])
update jroIO_digitalRF.py
r1263 metadata_bounds = this_metadata_file.get_bounds()
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.fixed_metadata_dict = this_metadata_file.read(
metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER
José Chávez
merge from master
r1054
try:
update jroIO_digitalRF.py
r1263 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
José Chávez
merge from master
r1054 self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader']
update jroIO_digitalRF.py
r1263 self.__systemHeader = self.fixed_metadata_dict['systemHeader']
self.dtype = pickle.loads(self.fixed_metadata_dict['dtype'])
José Chávez
merge from master
r1054 except:
pass
Jose Chavez
voltage DigitalRFReader funcionando
r973
self.__frequency = None
Jose Chavez
setting all headers all the time
r981
José Chávez
merge from master
r1054 self.__frequency = self.fixed_metadata_dict.get('frequency', 1)
Jose Chavez
voltage DigitalRFReader funcionando
r973
Alexander Valdez
Change timezone to 18000 seconds equivalent to 5 hours.
r1239 self.__timezone = self.fixed_metadata_dict.get('timezone', 18000)
Jose Chavez
voltage DigitalRFReader funcionando
r973
Jose Chavez
setting all headers all the time
r981 try:
Jose Chavez
algunos cambios
r982 nSamples = self.fixed_metadata_dict['nSamples']
Jose Chavez
setting all headers all the time
r981 except:
nSamples = None
José Chávez
formatting, template actualizado, decimation a 300
r1092
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.__firstHeigth = 0
try:
update jroIO_digitalRF.py
r1263 codeType = self.__radarControllerHeader['codeType']
Jose Chavez
voltage DigitalRFReader funcionando
r973 except:
update jroIO_digitalRF.py
r1263 codeType = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
merge from master
r1054 try:
if codeType:
nCode = self.__radarControllerHeader['nCode']
nBaud = self.__radarControllerHeader['nBaud']
update jroIO_digitalRF.py
r1263 code = self.__radarControllerHeader['code']
José Chávez
merge from master
r1054 except:
pass
José Chávez
formatting, template actualizado, decimation a 300
r1092
Jose Chavez
voltage DigitalRFReader funcionando
r973 if not ippKm:
try:
Jose Chavez
setting all headers all the time
r981 # seconds to km
Jose Chavez
algunos cambios
r982 ippKm = self.__radarControllerHeader['ipp']
Jose Chavez
voltage DigitalRFReader funcionando
r973 except:
ippKm = None
####################################################
update jroIO_digitalRF.py
r1263 self.__ippKm = ippKm
Jose Chavez
voltage DigitalRFReader funcionando
r973 startUTCSecond = None
update jroIO_digitalRF.py
r1263 endUTCSecond = None
Jose Chavez
voltage DigitalRFReader funcionando
r973
if startDate:
update jroIO_digitalRF.py
r1263 startDatetime = datetime.datetime.combine(startDate, startTime)
José Chávez
formatting, template actualizado, decimation a 300
r1092 startUTCSecond = (
startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone
Jose Chavez
voltage DigitalRFReader funcionando
r973
if endDate:
update jroIO_digitalRF.py
r1263 endDatetime = datetime.datetime.combine(endDate, endTime)
endUTCSecond = (endDatetime - datetime.datetime(1970,
José Chávez
formatting, template actualizado, decimation a 300
r1092 1, 1)).total_seconds() + self.__timezone
Jose Chavez
voltage DigitalRFReader funcionando
r973
José Chávez
formatting, template actualizado, decimation a 300
r1092 start_index, end_index = self.digitalReadObj.get_bounds(
channelNameList[channelList[0]])
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not startUTCSecond:
José Chávez
formatting, template actualizado, decimation a 300
r1092 startUTCSecond = start_index / self.__sample_rate
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 if start_index > startUTCSecond * self.__sample_rate:
José Chávez
formatting, template actualizado, decimation a 300
r1092 startUTCSecond = start_index / self.__sample_rate
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not endUTCSecond:
update jroIO_digitalRF.py
r1263 endUTCSecond = end_index / self.__sample_rate
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 if end_index < endUTCSecond * self.__sample_rate:
endUTCSecond = end_index / self.__sample_rate
Jose Chavez
voltage DigitalRFReader funcionando
r973 if not nSamples:
if not ippKm:
George Yong
Python 2to3, Spectra (all operations) working
r1167 raise ValueError("[Reading] nSamples or ippKm should be defined")
update jroIO_digitalRF.py
r1263 nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate))
channelBoundList = []
Jose Chavez
voltage DigitalRFReader funcionando
r973 channelNameListFiltered = []
for thisIndexChannel in channelList:
update jroIO_digitalRF.py
r1263 thisChannelName = channelNameList[thisIndexChannel]
José Chávez
formatting, template actualizado, decimation a 300
r1092 start_index, end_index = self.digitalReadObj.get_bounds(
thisChannelName)
Jose Chavez
voltage DigitalRFReader funcionando
r973 channelBoundList.append((start_index, end_index))
channelNameListFiltered.append(thisChannelName)
self.profileIndex = 0
update jroIO_digitalRF.py
r1263 self.i = 0
self.__delay = delay
self.__codeType = codeType
self.__nCode = nCode
self.__nBaud = nBaud
self.__code = code
self.__datapath = path
self.__online = online
self.__channelList = channelList
self.__channelNameList = channelNameListFiltered
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.__channelBoundList = channelBoundList
update jroIO_digitalRF.py
r1263 self.__nSamples = nSamples
self.__samples_to_read = int(nSamples) # FIJO: AHORA 40
self.__nChannels = len(self.__channelList)
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.__startUTCSecond = startUTCSecond
self.__endUTCSecond = endUTCSecond
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.__timeInterval = 1.0 * self.__samples_to_read / \
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.__sample_rate # Time interval
Jose Chavez
voltage DigitalRFReader funcionando
r973
if online:
José Chávez
formatting, template actualizado, decimation a 300
r1092 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
Jose Chavez
voltage DigitalRFReader funcionando
r973 startUTCSecond = numpy.floor(endUTCSecond)
José Chávez
formatting, template actualizado, decimation a 300
r1092 # por que en el otro metodo lo primero q se hace es sumar samplestoread
update jroIO_digitalRF.py
r1263 self.__thisUnixSample = int(startUTCSecond * self.__sample_rate) - self.__samples_to_read
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.__data_buffer = numpy.zeros(
José Chávez
formatting, template actualizado, decimation a 300
r1092 (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex)
Jose Chavez
voltage DigitalRFReader funcionando
r973
self.__setFileHeader()
self.isConfig = True
George Yong
Python 2to3, Spectra (all operations) working
r1167 print("[Reading] Digital RF Data was found from %s to %s " % (
José Chávez
formatting, template actualizado, decimation a 300
r1092 datetime.datetime.utcfromtimestamp(
self.__startUTCSecond - self.__timezone),
datetime.datetime.utcfromtimestamp(
self.__endUTCSecond - self.__timezone)
George Yong
Python 2to3, Spectra (all operations) working
r1167 ))
José Chávez
formatting, template actualizado, decimation a 300
r1092
George Yong
Python 2to3, Spectra (all operations) working
r1167 print("[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
José Chávez
formatting, template actualizado, decimation a 300
r1092 datetime.datetime.utcfromtimestamp(
endUTCSecond - self.__timezone)
George Yong
Python 2to3, Spectra (all operations) working
r1167 ))
update jroIO_digitalRF.py
r1263 self.oldAverage = None
self.count = 0
Jose Chavez
tests
r991 self.executionTime = 0
José Chávez
formatting, template actualizado, decimation a 300
r1092
Jose Chavez
voltage DigitalRFReader funcionando
r973 def __reload(self):
# print
# print "%s not in range [%s, %s]" %(
# datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
# datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
# datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
# )
George Yong
Python 2to3, Spectra (all operations) working
r1167 print("[Reading] reloading metadata ...")
Jose Chavez
voltage DigitalRFReader funcionando
r973
try:
self.digitalReadObj.reload(complete_update=True)
except:
update jroIO_digitalRF.py
r1263 self.digitalReadObj = digital_rf.DigitalRFReader(self.path)
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 start_index, end_index = self.digitalReadObj.get_bounds(
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.__channelNameList[self.__channelList[0]])
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 if start_index > self.__startUTCSecond * self.__sample_rate:
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.__startUTCSecond = 1.0 * start_index / self.__sample_rate
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 if end_index > self.__endUTCSecond * self.__sample_rate:
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.__endUTCSecond = 1.0 * end_index / self.__sample_rate
George Yong
Python 2to3, Spectra (all operations) working
r1167 print()
print("[Reading] New timerange found [%s, %s] " % (
José Chávez
formatting, template actualizado, decimation a 300
r1092 datetime.datetime.utcfromtimestamp(
self.__startUTCSecond - self.__timezone),
datetime.datetime.utcfromtimestamp(
self.__endUTCSecond - self.__timezone)
George Yong
Python 2to3, Spectra (all operations) working
r1167 ))
Jose Chavez
voltage DigitalRFReader funcionando
r973
return True
return False
Jose Chavez
tests
r991 def timeit(self, toExecute):
update jroIO_digitalRF.py
r1263 t0 = time.time()
Jose Chavez
tests
r991 toExecute()
update jroIO_digitalRF.py
r1263 self.executionTime = time.time() - t0
José Chávez
formatting, template actualizado, decimation a 300
r1092 if self.oldAverage is None:
self.oldAverage = self.executionTime
update jroIO_digitalRF.py
r1263 self.oldAverage = (self.executionTime + self.count *
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.oldAverage) / (self.count + 1.0)
update jroIO_digitalRF.py
r1263 self.count = self.count + 1.0
Jose Chavez
tests
r991 return
José Chávez
formatting, template actualizado, decimation a 300
r1092 def __readNextBlock(self, seconds=30, volt_scale=1):
Jose Chavez
voltage DigitalRFReader funcionando
r973 '''
'''
Jose Chavez
setting all headers all the time
r981 # Set the next data
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.__flagDiscontinuousBlock = False
update jroIO_digitalRF.py
r1263 self.__thisUnixSample += self.__samples_to_read
José Chávez
formatting, template actualizado, decimation a 300
r1092 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
update jroIO_digitalRF.py
r1263 print ("[Reading] There are no more data into selected time-range")
Jose Chavez
voltage DigitalRFReader funcionando
r973 if self.__online:
Alexander Valdez
Se realizar la lectura en modo online llamando al metodo digitalRFReader(self.path) en reemplazo del metodo reload(), grabando previamente el path de lectura o directorio superior donde se almacena la data. Adicionalmente, se ha definido un tiempo de espera de 3 segundos para dar tiempo suficiente al programa de adquisicion de generar archivos. ...
r1234 sleep(3)
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.__reload()
else:
return False
José Chávez
formatting, template actualizado, decimation a 300
r1092 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
Jose Chavez
voltage DigitalRFReader funcionando
r973 return False
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.__thisUnixSample -= self.__samples_to_read
Jose Chavez
voltage DigitalRFReader funcionando
r973
indexChannel = 0
dataOk = False
update jroIO_digitalRF.py
r1263
José Chávez
formatting, template actualizado, decimation a 300
r1092 for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS?
Jose Chavez
lectura de subchannels
r985 for indexSubchannel in range(self.__num_subchannels):
try:
update jroIO_digitalRF.py
r1263 t0 = time()
Jose Chavez
lectura de subchannels
r985 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
Jose Chavez
tests
r991 self.__samples_to_read,
thisChannelName, sub_channel=indexSubchannel)
update jroIO_digitalRF.py
r1263 self.executionTime = time() - t0
José Chávez
formatting, template actualizado, decimation a 300
r1092 if self.oldAverage is None:
self.oldAverage = self.executionTime
update jroIO_digitalRF.py
r1263 self.oldAverage = (
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.executionTime + self.count * self.oldAverage) / (self.count + 1.0)
Jose Chavez
tests
r991 self.count = self.count + 1.0
José Chávez
formatting, template actualizado, decimation a 300
r1092
George Yong
Python 2to3, Spectra (all operations) working
r1167 except IOError as e:
José Chávez
formatting, template actualizado, decimation a 300
r1092 # read next profile
Jose Chavez
lectura de subchannels
r985 self.__flagDiscontinuousBlock = True
George Yong
Python 2to3, Spectra (all operations) working
r1167 print("[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e)
Jose Chavez
lectura de subchannels
r985 break
Jose Chavez
voltage DigitalRFReader funcionando
r973
Jose Chavez
lectura de subchannels
r985 if result.shape[0] != self.__samples_to_read:
self.__flagDiscontinuousBlock = True
George Yong
Python 2to3, Spectra (all operations) working
r1167 print("[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
José Chávez
formatting, template actualizado, decimation a 300
r1092 result.shape[0],
George Yong
Python 2to3, Spectra (all operations) working
r1167 self.__samples_to_read))
Jose Chavez
lectura de subchannels
r985 break
update jroIO_digitalRF.py
r1263
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.__data_buffer[indexSubchannel, :] = result * volt_scale
update jroIO_digitalRF.py
r1263 indexChannel+=1
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 dataOk = True
José Chávez
formatting, template actualizado, decimation a 300
r1092
update jroIO_digitalRF.py
r1263 self.__utctime = self.__thisUnixSample / self.__sample_rate
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not dataOk:
return False
George Yong
Python 2to3, Spectra (all operations) working
r1167 print("[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.__samples_to_read,
George Yong
Python 2to3, Spectra (all operations) working
r1167 self.__timeInterval))
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.__bufferIndex = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973
return True
def __isBufferEmpty(self):
José Chávez
formatting, template actualizado, decimation a 300
r1092 return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40
Jose Chavez
voltage DigitalRFReader funcionando
r973
def getData(self, seconds=30, nTries=5):
'''
This method gets the data from files and put the data into the dataOut object
In addition, increase el the buffer counter in one.
Return:
data : retorna un perfil de voltages (alturas * canales) copiados desde el
buffer. Si no hay mas archivos a leer retorna None.
Affected:
self.dataOut
self.profileIndex
self.flagDiscontinuousBlock
self.flagIsNewBlock
'''
update jroIO_digitalRF.py
r1263 #print("getdata")
Jose Chavez
voltage DigitalRFReader funcionando
r973 err_counter = 0
self.dataOut.flagNoData = True
if self.__isBufferEmpty():
update jroIO_digitalRF.py
r1263 #print("hi")
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.__flagDiscontinuousBlock = False
while True:
update jroIO_digitalRF.py
r1263 #print ("q ha pasado")
Jose Chavez
voltage DigitalRFReader funcionando
r973 if self.__readNextBlock():
break
José Chávez
formatting, template actualizado, decimation a 300
r1092 if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate:
Errors handling and gracefully terminate main process
r1241 raise schainpy.admin.SchainError('Error')
update jroIO_digitalRF.py
r1263 return
Jose Chavez
voltage DigitalRFReader funcionando
r973
if self.__flagDiscontinuousBlock:
Errors handling and gracefully terminate main process
r1241 raise schainpy.admin.SchainError('discontinuous block found')
George Yong
Multiprocessing for digitalRF just for reading Unit(Task #1461 )
r1192 return
Jose Chavez
voltage DigitalRFReader funcionando
r973
if not self.__online:
Errors handling and gracefully terminate main process
r1241 raise schainpy.admin.SchainError('Online?')
update jroIO_digitalRF.py
r1263 return
Jose Chavez
voltage DigitalRFReader funcionando
r973
err_counter += 1
if err_counter > nTries:
Errors handling and gracefully terminate main process
r1241 raise schainpy.admin.SchainError('Max retrys reach')
George Yong
Multiprocessing for digitalRF just for reading Unit(Task #1461 )
r1192 return
Jose Chavez
voltage DigitalRFReader funcionando
r973
George Yong
Python 2to3, Spectra (all operations) working
r1167 print('[Reading] waiting %d seconds to read a new block' % seconds)
Errors handling and gracefully terminate main process
r1241 time.sleep(seconds)
Jose Chavez
voltage DigitalRFReader funcionando
r973
update jroIO_digitalRF.py
r1263 self.dataOut.data = self.__data_buffer[:, self.__bufferIndex:self.__bufferIndex + self.__nSamples]
self.dataOut.utctime = ( self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate
self.dataOut.flagNoData = False
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
update jroIO_digitalRF.py
r1263 self.dataOut.profileIndex = self.profileIndex
Jose Chavez
voltage DigitalRFReader funcionando
r973
self.__bufferIndex += self.__nSamples
update jroIO_digitalRF.py
r1263 self.profileIndex += 1
Jose Chavez
voltage DigitalRFReader funcionando
r973
if self.profileIndex == self.dataOut.nProfiles:
self.profileIndex = 0
return True
def printInfo(self):
'''
'''
if self.__printInfo == False:
return
Jose Chavez
setting all headers all the time
r981 # self.systemHeaderObj.printInfo()
# self.radarControllerHeaderObj.printInfo()
Jose Chavez
voltage DigitalRFReader funcionando
r973
self.__printInfo = False
def printNumberOfBlock(self):
'''
'''
return
Jose Chavez
setting all headers all the time
r981 # print self.profileIndex
Jose Chavez
voltage DigitalRFReader funcionando
r973
def run(self, **kwargs):
'''
This method will be called many times so here you should put all your code
'''
update jroIO_digitalRF.py
r1263
Jose Chavez
voltage DigitalRFReader funcionando
r973 if not self.isConfig:
self.setup(**kwargs)
José Chávez
algo
r998 #self.i = self.i+1
Jose Chavez
voltage DigitalRFReader funcionando
r973 self.getData(seconds=self.__delay)
update jroIO_digitalRF.py
r1263
Jose Chavez
voltage DigitalRFReader funcionando
r973 return
Juan C. Espinoza
Rewrite controller, remove MPDecorator to units (keep for plots an writers) use of queues for interproc comm instead of zmq, self operations are no longer supported
r1287 @MPDecorator
Jose Chavez
voltage DigitalRFReader funcionando
r973 class DigitalRFWriter(Operation):
'''
classdocs
'''
def __init__(self, **kwargs):
'''
Constructor
'''
Operation.__init__(self, **kwargs)
Jose Chavez
setting all headers all the time
r981 self.metadata_dict = {}
update jroIO_digitalRF.py
r1263 self.dataOut = None
self.dtype = None
self.oldAverage = 0
Jose Chavez
tests
r991
def setHeader(self):
update jroIO_digitalRF.py
r1263 self.metadata_dict['frequency'] = self.dataOut.frequency
self.metadata_dict['timezone'] = self.dataOut.timeZone
self.metadata_dict['dtype'] = pickle.dumps(self.dataOut.dtype)
self.metadata_dict['nProfiles'] = self.dataOut.nProfiles
self.metadata_dict['heightList'] = self.dataOut.heightList
self.metadata_dict['channelList'] = self.dataOut.channelList
Jose Chavez
tests
r991 self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData
self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData
update jroIO_digitalRF.py
r1263 self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT
self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime
self.metadata_dict['nCohInt'] = self.dataOut.nCohInt
self.metadata_dict['type'] = self.dataOut.type
self.metadata_dict['flagDataAsBlock']= getattr(
José Chávez
formatting y raise cuando digitalrf recibe spectra
r1120 self.dataOut, 'flagDataAsBlock', None) # chequear
Jose Chavez
algunos cambios
r982
Jose Chavez
tests
r991 def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'):
Jose Chavez
voltage DigitalRFReader funcionando
r973 '''
In this method we should set all initial parameters.
Input:
Jose Chavez
setting all headers all the time
r981 dataOut: Input data will also be outputa data
Jose Chavez
voltage DigitalRFReader funcionando
r973 '''
Jose Chavez
tests
r991 self.setHeader()
update jroIO_digitalRF.py
r1263 self.__ippSeconds = dataOut.ippSeconds
self.__deltaH = dataOut.getDeltaH()
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.__sample_rate = 1e6 * 0.15 / self.__deltaH
update jroIO_digitalRF.py
r1263 self.__dtype = dataOut.dtype
Jose Chavez
agregado metodos a header class
r980 if len(dataOut.dtype) == 2:
self.__dtype = dataOut.dtype[0]
update jroIO_digitalRF.py
r1263 self.__nSamples = dataOut.systemHeaderObj.nSamples
Jose Chavez
agregado metodos a header class
r980 self.__nProfiles = dataOut.nProfiles
José Chávez
algo
r998
José Chávez
formatting y raise cuando digitalrf recibe spectra
r1120 if self.dataOut.type != 'Voltage':
raise 'Digital RF cannot be used with this data type'
self.arr_data = numpy.ones((1, dataOut.nFFTPoints * len(
self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
else:
self.arr_data = numpy.ones((self.__nSamples, len(
self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
Jose Chavez
agregado metodos a header class
r980
update jroIO_digitalRF.py
r1263 file_cadence_millisecs = 1000
Jose Chavez
agregado metodos a header class
r980
update jroIO_digitalRF.py
r1263 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
sample_rate_numerator = int(sample_rate_fraction.numerator)
George Yong
Python 2to3, Spectra (all operations) working
r1167 sample_rate_denominator = int(sample_rate_fraction.denominator)
update jroIO_digitalRF.py
r1263 start_global_index = dataOut.utctime * self.__sample_rate
José Chávez
formatting, template actualizado, decimation a 300
r1092
update jroIO_digitalRF.py
r1263 uuid = 'prueba'
José Chávez
digital rf fixes
r1103 compression_level = 0
update jroIO_digitalRF.py
r1263 checksum = False
is_complex = True
num_subchannels = len(dataOut.channelList)
is_continuous = True
marching_periods = False
Jose Chavez
writing rf data, falta metadata
r979
Jose Chavez
tests
r991 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence,
José Chávez
formatting, template actualizado, decimation a 300
r1092 fileCadence, start_global_index,
sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
is_complex, num_subchannels, is_continuous, marching_periods)
update jroIO_digitalRF.py
r1263 metadata_dir = os.path.join(path, 'metadata')
Jose Chavez
agregado metodos a header class
r980 os.system('mkdir %s' % (metadata_dir))
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000
sample_rate_numerator, sample_rate_denominator,
metadataFile)
update jroIO_digitalRF.py
r1263 self.isConfig = True
Jose Chavez
agregado metodos a header class
r980 self.currentSample = 0
update jroIO_digitalRF.py
r1263 self.oldAverage = 0
self.count = 0
Jose Chavez
voltage DigitalRFReader funcionando
r973 return
José Chávez
formatting, template actualizado, decimation a 300
r1092
Jose Chavez
setting all headers all the time
r981 def writeMetadata(self):
update jroIO_digitalRF.py
r1263 start_idx = self.__sample_rate * self.dataOut.utctime
José Chávez
formatting, template actualizado, decimation a 300
r1092
update jroIO_digitalRF.py
r1263 self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict(
José Chávez
formatting, template actualizado, decimation a 300
r1092 )
self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict(
)
update jroIO_digitalRF.py
r1263 self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict(
José Chávez
formatting, template actualizado, decimation a 300
r1092 )
Jose Chavez
setting all headers all the time
r981 self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict)
return
Jose Chavez
voltage DigitalRFReader funcionando
r973
Jose Chavez
tests
r991 def timeit(self, toExecute):
Jose Chavez
lectura de subchannels
r985 t0 = time()
Jose Chavez
tests
r991 toExecute()
update jroIO_digitalRF.py
r1263 self.executionTime = time() - t0
José Chávez
formatting, template actualizado, decimation a 300
r1092 if self.oldAverage is None:
self.oldAverage = self.executionTime
update jroIO_digitalRF.py
r1263 self.oldAverage = (self.executionTime + self.count *
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.oldAverage) / (self.count + 1.0)
update jroIO_digitalRF.py
r1263 self.count = self.count + 1.0
Jose Chavez
tests
r991 return
def writeData(self):
José Chávez
formatting y raise cuando digitalrf recibe spectra
r1120 if self.dataOut.type != 'Voltage':
raise 'Digital RF cannot be used with this data type'
Jose Chavez
tests
r991 for channel in self.dataOut.channelList:
José Chávez
formatting y raise cuando digitalrf recibe spectra
r1120 for i in range(self.dataOut.nFFTPoints):
self.arr_data[1][channel * self.dataOut.nFFTPoints +
i]['r'] = self.dataOut.data[channel][i].real
self.arr_data[1][channel * self.dataOut.nFFTPoints +
i]['i'] = self.dataOut.data[channel][i].imag
else:
for i in range(self.dataOut.systemHeaderObj.nSamples):
for channel in self.dataOut.channelList:
self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real
self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag
Jose Chavez
tests
r991
def f(): return self.digitalWriteObj.rf_write(self.arr_data)
self.timeit(f)
José Chávez
formatting, template actualizado, decimation a 300
r1092
Jose Chavez
setting all headers all the time
r981 return
José Chávez
formatting, template actualizado, decimation a 300
r1092
José Chávez
digital rf fixes
r1103 def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=1000, dirCadence=36000, metadataCadence=1, **kwargs):
Jose Chavez
voltage DigitalRFReader funcionando
r973 '''
This method will be called many times so here you should put all your code
Inputs:
Jose Chavez
setting all headers all the time
r981 dataOut: object with the data
Jose Chavez
voltage DigitalRFReader funcionando
r973 '''
Jose Chavez
setting all headers all the time
r981 # print dataOut.__dict__
Jose Chavez
agregado metodos a header class
r980 self.dataOut = dataOut
Jose Chavez
voltage DigitalRFReader funcionando
r973 if not self.isConfig:
José Chávez
formatting, template actualizado, decimation a 300
r1092 self.setup(dataOut, path, frequency, fileCadence,
dirCadence, metadataCadence, **kwargs)
José Chávez
algo
r998 self.writeMetadata()
Jose Chavez
writing rf data, falta metadata
r979
Jose Chavez
setting all headers all the time
r981 self.writeData()
José Chávez
formatting, template actualizado, decimation a 300
r1092
José Chávez
algo
r998 ## self.currentSample += 1
José Chávez
formatting, template actualizado, decimation a 300
r1092 # if self.dataOut.flagDataAsBlock or self.currentSample == 1:
# self.writeMetadata()
José Chávez
algo
r998 ## if self.currentSample == self.__nProfiles: self.currentSample = 0
Jose Chavez
setting all headers all the time
r981
update jroIO_digitalRF.py
r1263 return dataOut# en la version 2.7 no aparece este return
George Yong
Multiprocessing for digitalRF just for reading Unit(Task #1461 )
r1192
Jose Chavez
agregado metodos a header class
r980 def close(self):
George Yong
Python 2to3, Spectra (all operations) working
r1167 print('[Writing] - Closing files ')
print('Average of writing to digital rf format is ', self.oldAverage * 1000)
Jose Chavez
setting all headers all the time
r981 try:
self.digitalWriteObj.close()
except:
pass