import numpy from .jroproc_base import ProcessingUnit, Operation from schainpy.model.data.jrodata import SpectraHeis class SpectraHeisProc(ProcessingUnit): def __init__(self, **kwargs): ProcessingUnit.__init__(self, **kwargs) # self.buffer = None # self.firstdatatime = None # self.profIndex = 0 self.dataOut = SpectraHeis() def __updateObjFromVoltage(self): self.dataOut.timeZone = self.dataIn.timeZone self.dataOut.dstFlag = self.dataIn.dstFlag self.dataOut.errorCount = self.dataIn.errorCount self.dataOut.useLocalTime = self.dataIn.useLocalTime self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# self.dataOut.channelList = self.dataIn.channelList self.dataOut.heightList = self.dataIn.heightList # self.dataOut.dtype = self.dataIn.dtype self.dataOut.dtype = numpy.dtype([('real',' change this line self.n = 9999 self.__byTime = True if overlapping: self.__withOverapping = True self.__buffer = None else: self.__withOverapping = False self.__buffer = 0 self.__profIndex = 0 def putData(self, data): """ Add a profile to the __buffer and increase in one the __profileIndex """ if not self.__withOverapping: self.__buffer += data.copy() self.__profIndex += 1 return #Overlapping data nChannels, nHeis = data.shape data = numpy.reshape(data, (1, nChannels, nHeis)) #If the buffer is empty then it takes the data value if self.__buffer is None: self.__buffer = data self.__profIndex += 1 return #If the buffer length is lower than n then stakcing the data value if self.__profIndex < self.n: self.__buffer = numpy.vstack((self.__buffer, data)) self.__profIndex += 1 return #If the buffer length is equal to n then replacing the last buffer value with the data value self.__buffer = numpy.roll(self.__buffer, -1, axis=0) self.__buffer[self.n-1] = data self.__profIndex = self.n return def pushData(self): """ Return the sum of the last profiles and the profiles used in the sum. Affected: self.__profileIndex """ if not self.__withOverapping: data = self.__buffer n = self.__profIndex self.__buffer = 0 self.__profIndex = 0 return data, n #Integration with Overlapping data = numpy.sum(self.__buffer, axis=0) n = self.__profIndex return data, n def byProfiles(self, data): self.__dataReady = False avgdata = None # n = None self.putData(data) if self.__profIndex == self.n: avgdata, n = self.pushData() self.__dataReady = True return avgdata def byTime(self, data, datatime): self.__dataReady = False avgdata = None n = None self.putData(data) if (datatime - self.__initime) >= self.__integrationtime: avgdata, n = self.pushData() self.n = n self.__dataReady = True return avgdata def integrate(self, data, datatime=None): if self.__initime == None: self.__initime = datatime if self.__byTime: avgdata = self.byTime(data, datatime) else: avgdata = self.byProfiles(data) self.__lastdatatime = datatime if avgdata is None: return None, None avgdatatime = self.__initime deltatime = datatime -self.__lastdatatime if not self.__withOverapping: self.__initime = datatime else: self.__initime += deltatime return avgdata, avgdatatime def run(self, dataOut, n=None, timeInterval=None, overlapping=False, **kwargs): if not self.isConfig: self.setup(n=n, timeInterval=timeInterval, overlapping=overlapping) self.isConfig = True avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) # dataOut.timeInterval *= n dataOut.flagNoData = True if self.__dataReady: dataOut.data_spc = avgdata dataOut.nIncohInt *= self.n # dataOut.nCohInt *= self.n dataOut.utctime = avgdatatime # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt # dataOut.timeInterval = self.__timeInterval*self.n dataOut.flagNoData = False