@@ -1,186 +1,186 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 |
|
9 | |||
10 | path = os.path.split(os.getcwd())[0] |
|
10 | path = os.path.split(os.getcwd())[0] | |
11 | sys.path.append(path) |
|
11 | sys.path.append(path) | |
12 |
|
12 | |||
13 | from Model.Spectra import Spectra |
|
13 | from Model.Spectra import Spectra | |
14 | from IO.SpectraIO import SpectraWriter |
|
14 | from IO.SpectraIO import SpectraWriter | |
15 | from Graphics.SpectraPlot import Spectrum |
|
15 | from Graphics.SpectraPlot import Spectrum | |
16 |
|
16 | |||
17 |
|
17 | |||
18 | class SpectraProcessor: |
|
18 | class SpectraProcessor: | |
19 | ''' |
|
19 | ''' | |
20 | classdocs |
|
20 | classdocs | |
21 | ''' |
|
21 | ''' | |
22 |
|
22 | |||
23 | def __init__(self, spectraInObj, spectraOutObj=None, npts = None): |
|
23 | def __init__(self, spectraInObj, spectraOutObj=None, npts = None): | |
24 | ''' |
|
24 | ''' | |
25 | Constructor |
|
25 | Constructor | |
26 | ''' |
|
26 | ''' | |
27 | self.spectraInObj = spectraInObj |
|
27 | self.spectraInObj = spectraInObj | |
28 |
|
28 | |||
29 | if spectraOutObj == None: |
|
29 | if spectraOutObj == None: | |
30 | self.spectraOutObj = Spectra() |
|
30 | self.spectraOutObj = Spectra() | |
31 | else: |
|
31 | else: | |
32 | self.spectraOutObj = spectraOutObj |
|
32 | self.spectraOutObj = spectraOutObj | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | self.integratorIndex = None |
|
35 | self.integratorIndex = None | |
36 | self.decoderIndex = None |
|
36 | self.decoderIndex = None | |
37 | self.writerIndex = None |
|
37 | self.writerIndex = None | |
38 | self.plotterIndex = None |
|
38 | self.plotterIndex = None | |
39 |
|
39 | |||
40 | if npts != None: |
|
40 | if npts != None: | |
41 | self.spectraOutObj.nPoints = npts |
|
41 | self.spectraOutObj.nPoints = npts | |
42 |
|
42 | |||
43 | self.npts = self.spectraOutObj.nPoints |
|
43 | self.npts = self.spectraOutObj.nPoints | |
44 |
|
44 | |||
45 | self.integratorList = [] |
|
45 | self.integratorList = [] | |
46 | self.decoderList = [] |
|
46 | self.decoderList = [] | |
47 | self.writerList = [] |
|
47 | self.writerList = [] | |
48 | self.plotterList = [] |
|
48 | self.plotterList = [] | |
49 |
|
49 | |||
50 | self.buffer = None |
|
50 | self.buffer = None | |
51 | self.ptsId = 0 |
|
51 | self.ptsId = 0 | |
52 |
|
52 | |||
53 | def init(self): |
|
53 | def init(self): | |
54 | self.integratorIndex = 0 |
|
54 | self.integratorIndex = 0 | |
55 | self.decoderIndex = 0 |
|
55 | self.decoderIndex = 0 | |
56 | self.writerIndex = 0 |
|
56 | self.writerIndex = 0 | |
57 | self.plotterIndex = 0 |
|
57 | self.plotterIndex = 0 | |
58 |
|
58 | |||
59 | if not( isinstance(self.spectraInObj, Spectra) ): |
|
59 | if not( isinstance(self.spectraInObj, Spectra) ): | |
60 | self.getFft() |
|
60 | self.getFft() | |
61 | else: |
|
61 | else: | |
62 | self.spectraOutObj.copy(self.spectraInObj) |
|
62 | self.spectraOutObj.copy(self.spectraInObj) | |
63 |
|
63 | |||
64 |
|
64 | |||
65 | def getFft(self): |
|
65 | def getFft(self): | |
66 |
|
66 | |||
67 | if self.buffer == None: |
|
67 | if self.buffer == None: | |
68 | nheis = self.spectraInObj.data.shape[1] |
|
68 | nheis = self.spectraInObj.data.shape[1] | |
69 | nchannel = self.spectraInObj.data.shape[0] |
|
69 | nchannel = self.spectraInObj.data.shape[0] | |
70 | npoints = self.spectraOutObj.nPoints |
|
70 | npoints = self.spectraOutObj.nPoints | |
71 | self.buffer = numpy.zeros((nchannel,npoints,nheis),dtype='complex') |
|
71 | self.buffer = numpy.zeros((nchannel,npoints,nheis),dtype='complex') | |
72 |
|
72 | |||
73 | self.buffer[:,self.ptsId,:] = self.spectraInObj.data |
|
73 | self.buffer[:,self.ptsId,:] = self.spectraInObj.data | |
74 | self.ptsId += 1 |
|
74 | self.ptsId += 1 | |
75 | self.spectraOutObj.flagNoData = True |
|
75 | self.spectraOutObj.flagNoData = True | |
76 | if self.ptsId >= self.spectraOutObj.nPoints: |
|
76 | if self.ptsId >= self.spectraOutObj.nPoints: | |
77 | data_spc = numpy.fft.fft(self.buffer,axis=1) |
|
77 | data_spc = numpy.fft.fft(self.buffer,axis=1) | |
|
78 | data_spc = numpy.fft.fftshift(data_spc,axes=1) | |||
78 | self.ptsId = 0 |
|
79 | self.ptsId = 0 | |
79 | self.buffer = None |
|
80 | self.buffer = None | |
80 |
|
81 | |||
81 | #calculo de self-spectra |
|
82 | #calculo de self-spectra | |
82 | self.spectraOutObj.data_spc = numpy.abs(data_spc * numpy.conjugate(data_spc)) |
|
83 | self.spectraOutObj.data_spc = numpy.abs(data_spc * numpy.conjugate(data_spc)) | |
83 |
|
84 | |||
84 | #calculo de cross-spectra |
|
85 | #calculo de cross-spectra | |
85 | #self.m_Spectra.data_cspc = self.__data_cspc |
|
86 | #self.m_Spectra.data_cspc = self.__data_cspc | |
86 |
|
87 | |||
87 | #escribiendo dc |
|
88 | #escribiendo dc | |
88 | #self.m_Spectra.data_dc = self.__data_dc |
|
89 | #self.m_Spectra.data_dc = self.__data_dc | |
89 |
|
90 | |||
90 | self.spectraOutObj.flagNoData = False |
|
91 | self.spectraOutObj.flagNoData = False | |
91 |
|
92 | |||
92 | self.spectraOutObj.heights = self.spectraInObj.heights |
|
93 | self.spectraOutObj.heights = self.spectraInObj.heights | |
93 | self.spectraOutObj.m_BasicHeader = self.spectraInObj.m_BasicHeader.copy() |
|
94 | self.spectraOutObj.m_BasicHeader = self.spectraInObj.m_BasicHeader.copy() | |
94 | self.spectraOutObj.m_ProcessingHeader = self.spectraInObj.m_ProcessingHeader.copy() |
|
95 | self.spectraOutObj.m_ProcessingHeader = self.spectraInObj.m_ProcessingHeader.copy() | |
95 | self.spectraOutObj.m_RadarControllerHeader = self.spectraInObj.m_RadarControllerHeader.copy() |
|
96 | self.spectraOutObj.m_RadarControllerHeader = self.spectraInObj.m_RadarControllerHeader.copy() | |
96 | self.spectraOutObj.m_SystemHeader = self.spectraInObj.m_SystemHeader.copy() |
|
97 | self.spectraOutObj.m_SystemHeader = self.spectraInObj.m_SystemHeader.copy() | |
97 |
|
98 | |||
98 | def addWriter(self,wrpath): |
|
99 | def addWriter(self,wrpath): | |
99 | objWriter = SpectraWriter(self.spectraOutObj) |
|
100 | objWriter = SpectraWriter(self.spectraOutObj) | |
100 | objWriter.setup(wrpath) |
|
101 | objWriter.setup(wrpath) | |
101 | self.writerList.append(objWriter) |
|
102 | self.writerList.append(objWriter) | |
102 |
|
103 | |||
103 |
|
104 | |||
104 | def addPlotter(self, index=None): |
|
105 | def addPlotter(self, index=None): | |
105 |
|
106 | |||
106 | if index==None: |
|
107 | if index==None: | |
107 | index = self.plotterIndex |
|
108 | index = self.plotterIndex | |
108 |
|
109 | |||
109 | plotObj = Spectrum(self.spectraOutObj, index) |
|
110 | plotObj = Spectrum(self.spectraOutObj, index) | |
110 | self.plotterList.append(plotObj) |
|
111 | self.plotterList.append(plotObj) | |
111 |
|
112 | |||
112 |
|
113 | |||
113 | def addIntegrator(self,N): |
|
114 | def addIntegrator(self,N): | |
114 |
|
115 | |||
115 | objIncohInt = IncoherentIntegration(N) |
|
116 | objIncohInt = IncoherentIntegration(N) | |
116 | self.integratorList.append(objIncohInt) |
|
117 | self.integratorList.append(objIncohInt) | |
117 |
|
118 | |||
118 |
|
119 | |||
119 | def writeData(self): |
|
120 | def writeData(self): | |
120 | if self.voltageOutObj.flagNoData: |
|
121 | if self.voltageOutObj.flagNoData: | |
121 | return 0 |
|
122 | return 0 | |
122 |
|
123 | |||
123 | if len(self.writerList) <= self.writerIndex: |
|
124 | if len(self.writerList) <= self.writerIndex: | |
124 | self.addWriter(wrpath) |
|
125 | self.addWriter(wrpath) | |
125 |
|
126 | |||
126 | self.writerList[self.writerIndex].putData() |
|
127 | self.writerList[self.writerIndex].putData() | |
127 |
|
128 | |||
128 | self.writerIndex += 1 |
|
129 | self.writerIndex += 1 | |
129 |
|
130 | |||
130 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): |
|
131 | def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle='', index=None): | |
131 | if self.spectraOutObj.flagNoData: |
|
132 | if self.spectraOutObj.flagNoData: | |
132 | return 0 |
|
133 | return 0 | |
133 |
|
134 | |||
134 | if len(self.plotterList) <= self.plotterIndex: |
|
135 | if len(self.plotterList) <= self.plotterIndex: | |
135 | self.addPlotter(index) |
|
136 | self.addPlotter(index) | |
136 |
|
137 | |||
137 | self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) |
|
138 | self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) | |
138 |
|
139 | |||
139 | self.plotterIndex += 1 |
|
140 | self.plotterIndex += 1 | |
140 |
|
141 | |||
141 | def integrator(self, N): |
|
142 | def integrator(self, N): | |
142 | if self.spectraOutObj.flagNoData: |
|
143 | if self.spectraOutObj.flagNoData: | |
143 | return 0 |
|
144 | return 0 | |
144 |
|
145 | |||
145 | if len(self.integratorList) <= self.integratorIndex: |
|
146 | if len(self.integratorList) <= self.integratorIndex: | |
146 | self.addIntegrator(N) |
|
147 | self.addIntegrator(N) | |
147 |
|
148 | |||
148 | myCohIntObj = self.integratorList[self.integratorIndex] |
|
149 | myCohIntObj = self.integratorList[self.integratorIndex] | |
149 | myCohIntObj.exe(self.spectraOutObj.data_spc) |
|
150 | myCohIntObj.exe(self.spectraOutObj.data_spc) | |
150 |
|
151 | |||
151 | if myCohIntObj.flag: |
|
152 | if myCohIntObj.flag: | |
152 | self.spectraOutObj.data_spc = myCohIntObj.data |
|
153 | self.spectraOutObj.data_spc = myCohIntObj.data | |
153 | self.spectraOutObj.m_ProcessingHeader.incoherentInt *= N |
|
154 | self.spectraOutObj.m_ProcessingHeader.incoherentInt *= N | |
154 | self.spectraOutObj.flagNoData = False |
|
155 | self.spectraOutObj.flagNoData = False | |
155 |
|
156 | |||
156 | else: |
|
157 | else: | |
157 | self.spectraOutObj.flagNoData = True |
|
158 | self.spectraOutObj.flagNoData = True | |
158 |
|
159 | |||
159 | self.integratorIndex += 1 |
|
160 | self.integratorIndex += 1 | |
160 |
|
161 | |||
161 | class IncoherentIntegration: |
|
162 | class IncoherentIntegration: | |
162 | def __init__(self, N): |
|
163 | def __init__(self, N): | |
163 | self.profCounter = 1 |
|
164 | self.profCounter = 1 | |
164 | self.data = None |
|
165 | self.data = None | |
165 | self.buffer = None |
|
166 | self.buffer = None | |
166 | self.flag = False |
|
167 | self.flag = False | |
167 | self.nIncohInt = N |
|
168 | self.nIncohInt = N | |
168 |
|
169 | |||
169 | def exe(self,data): |
|
170 | def exe(self,data): | |
170 | print 'intg:', self.profCounter |
|
|||
171 |
|
171 | |||
172 | if self.buffer == None: |
|
172 | if self.buffer == None: | |
173 | self.buffer = data |
|
173 | self.buffer = data | |
174 | else: |
|
174 | else: | |
175 | self.buffer = self.buffer + data |
|
175 | self.buffer = self.buffer + data | |
176 |
|
176 | |||
177 | if self.profCounter == self.nIncohInt: |
|
177 | if self.profCounter == self.nIncohInt: | |
178 | self.data = self.buffer |
|
178 | self.data = self.buffer | |
179 | self.buffer = None |
|
179 | self.buffer = None | |
180 | self.profCounter = 0 |
|
180 | self.profCounter = 0 | |
181 | self.flag = True |
|
181 | self.flag = True | |
182 | else: |
|
182 | else: | |
183 | self.flag = False |
|
183 | self.flag = False | |
184 |
|
184 | |||
185 | self.profCounter += 1 |
|
185 | self.profCounter += 1 | |
186 |
|
186 |
General Comments 0
You need to be logged in to leave comments.
Login now