SpectraProcessor.py
183 lines
| 5.1 KiB
| text/x-python
|
PythonLexer
|
r10 | ''' | ||
Created on Feb 7, 2012 | ||||
|
r16 | @author $Author$ | ||
@version $Id$ | ||||
|
r10 | ''' | ||
|
r72 | import os, sys | ||
import numpy | ||||
path = os.path.split(os.getcwd())[0] | ||||
sys.path.append(path) | ||||
from Model.Spectra import Spectra | ||||
from IO.SpectraIO import SpectraWriter | ||||
from Graphics.SpectraPlot import Spectrum | ||||
|
r10 | |||
class SpectraProcessor: | ||||
''' | ||||
classdocs | ||||
''' | ||||
|
r72 | |||
def __init__(self, spectraInObj, spectraOutObj=None, npts = None): | ||||
|
r10 | ''' | ||
Constructor | ||||
''' | ||||
|
r72 | self.spectraInObj = spectraInObj | ||
if spectraOutObj == None: | ||||
self.spectraOutObj = Spectra() | ||||
else: | ||||
self.spectraOutObj = spectraOutObj | ||||
self.integratorIndex = None | ||||
self.decoderIndex = None | ||||
self.writerIndex = None | ||||
self.plotterIndex = None | ||||
if npts != None: | ||||
self.spectraOutObj.nPoints = npts | ||||
self.npts = self.spectraOutObj.nPoints | ||||
self.integratorList = [] | ||||
self.decoderList = [] | ||||
self.writerList = [] | ||||
self.plotterList = [] | ||||
self.buffer = None | ||||
self.ptsId = 0 | ||||
def init(self): | ||||
self.integratorIndex = 0 | ||||
self.decoderIndex = 0 | ||||
self.writerIndex = 0 | ||||
self.plotterIndex = 0 | ||||
if not( isinstance(self.spectraInObj, Spectra) ): | ||||
self.getFft() | ||||
else: | ||||
self.spectraOutObj.copy(self.spectraInObj) | ||||
def getFft(self): | ||||
if self.buffer == None: | ||||
nheis = self.spectraInObj.data.shape[0] | ||||
nchannel = self.spectraInObj.data.shape[1] | ||||
npoints = self.spectraOutObj.nPoints | ||||
self.buffer = numpy.zeros((nchannel,nheis,npoints),dtype='complex') | ||||
data = numpy.transpose(self.spectraInObj.data) | ||||
self.buffer[:,:,self.ptsId] = data | ||||
self.ptsId += 1 | ||||
self.spectraOutObj.flagNoData = True | ||||
if self.ptsId >= self.spectraOutObj.nPoints: | ||||
data_spc = numpy.fft.fft(self.buffer,axis=2) | ||||
self.ptsId = 0 | ||||
self.buffer = None | ||||
#calculo de self-spectra | ||||
self.spectraOutObj.data_spc = numpy.abs(data_spc * numpy.conjugate(data_spc)) | ||||
#calculo de cross-spectra | ||||
#self.m_Spectra.data_cspc = self.__data_cspc | ||||
#escribiendo dc | ||||
#self.m_Spectra.data_dc = self.__data_dc | ||||
self.spectraOutObj.flagNoData = False | ||||
def addWriter(self,wrpath): | ||||
objWriter = SpectraWriter(self.spectraOutObj) | ||||
objWriter.setup(wrpath) | ||||
self.writerList.append(objWriter) | ||||
def addPlotter(self): | ||||
plotObj = Spectrum(self.spectraOutObj,self.plotterIndex) | ||||
self.plotterList.append(plotObj) | ||||
def addIntegrator(self,N): | ||||
objIncohInt = IncoherentIntegration(N) | ||||
self.integratorList.append(objIncohInt) | ||||
def writeData(self): | ||||
if self.voltageOutObj.flagNoData: | ||||
return 0 | ||||
if len(self.writerList) <= self.writerIndex: | ||||
self.addWriter(wrpath) | ||||
self.writerList[self.writerIndex].putData() | ||||
self.writerIndex += 1 | ||||
def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): | ||||
if self.spectraOutObj.flagNoData: | ||||
return 0 | ||||
if len(self.plotterList) <= self.plotterIndex: | ||||
self.addPlotter() | ||||
self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | ||||
self.plotterIndex += 1 | ||||
def integrator(self, N): | ||||
if self.spectraOutObj.flagNoData: | ||||
return 0 | ||||
if len(self.integratorList) <= self.integratorIndex: | ||||
self.addIntegrator(N) | ||||
myCohIntObj = self.integratorList[self.integratorIndex] | ||||
myCohIntObj.exe(self.spectraOutObj.data_spc) | ||||
if myCohIntObj.flag: | ||||
self.spectraOutObj.data_spc = myCohIntObj.data | ||||
self.spectraOutObj.m_ProcessingHeader.incoherentInt *= N | ||||
self.spectraOutObj.flagNoData = False | ||||
else: | ||||
self.spectraOutObj.flagNoData = True | ||||
self.integratorIndex += 1 | ||||
class IncoherentIntegration: | ||||
def __init__(self, N): | ||||
self.profCounter = 1 | ||||
self.data = None | ||||
self.buffer = None | ||||
self.flag = False | ||||
self.nIncohInt = N | ||||
def exe(self,data): | ||||
print 'intg:', self.profCounter | ||||
if self.buffer == None: | ||||
self.buffer = data | ||||
else: | ||||
self.buffer = self.buffer + data | ||||
if self.profCounter == self.nIncohInt: | ||||
self.data = self.buffer | ||||
self.buffer = None | ||||
self.profCounter = 0 | ||||
self.flag = True | ||||
else: | ||||
self.flag = False | ||||
self.profCounter += 1 | ||||