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