##// END OF EJS Templates
El numero de alturas son actualizadas cuando se realiza la decodificación nHeigths = nHeigths - nBauds + 1
Miguel Valdez -
r116:0a45d4fb137d
parent child
Show More
@@ -1,170 +1,170
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
7
8 import numpy
8 import numpy
9 import os
9 import os
10 import sys
10 import sys
11 import plplot
11 import plplot
12 import datetime
12 import datetime
13
13
14 path = os.path.split(os.getcwd())[0]
14 path = os.path.split(os.getcwd())[0]
15 sys.path.append(path)
15 sys.path.append(path)
16
16
17 from Graphics.BaseGraph import *
17 from Graphics.BaseGraph import *
18 from Model.Spectra import Spectra
18 from Model.Spectra import Spectra
19
19
20 class Spectrum:
20 class Spectrum:
21 colorplotObj = None
21 colorplotObj = None
22
22
23 def __init__(self,Spectra, index):
23 def __init__(self, spectraObj, index):
24 self.__isPlotConfig = False
24 self.__isPlotConfig = False
25 self.__isPlotIni = False
25 self.__isPlotIni = False
26 self.__xrange = None
26 self.__xrange = None
27 self.__yrange = None
27 self.__yrange = None
28 self.nsubplots = 0
28 self.nsubplots = 0
29 self.indexPlot = index
29 self.indexPlot = index
30 self.spectraObj = Spectra
30 self.spectraObj = spectraObj
31
31
32 def setup(self,indexPlot, nsubplots, winTitle='', colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
32 def setup(self,indexPlot, nsubplots, winTitle='', colormap="br_green", showColorbar=False, showPowerProfile=False, XAxisAsTime=False):
33 """
33 """
34 Crea un objeto colorPlot con las opciones seleccinoadas
34 Crea un objeto colorPlot con las opciones seleccinoadas
35 """
35 """
36
36
37 self.nsubplots = nsubplots
37 self.nsubplots = nsubplots
38 self.colorplotObj = PcolorPlot(indexPlot,
38 self.colorplotObj = PcolorPlot(indexPlot,
39 nsubplots,
39 nsubplots,
40 winTitle,
40 winTitle,
41 colormap,
41 colormap,
42 showColorbar,
42 showColorbar,
43 showPowerProfile,
43 showPowerProfile,
44 XAxisAsTime)
44 XAxisAsTime)
45
45
46 def createObjects(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList):
46 def createObjects(self,xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList):
47 """
47 """
48 Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos
48 Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos
49 """
49 """
50
50
51 for index in range(self.nsubplots):
51 for index in range(self.nsubplots):
52 title = titleList[index]
52 title = titleList[index]
53 xlabel = xlabelList[index]
53 xlabel = xlabelList[index]
54 ylabel = ylabelList[index]
54 ylabel = ylabelList[index]
55 subplot = index
55 subplot = index
56 self.colorplotObj.createObjects(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
56 self.colorplotObj.createObjects(subplot+1,xmin,xmax,ymin,ymax,zmin,zmax,title,xlabel,ylabel)
57
57
58 def initPlot(self):
58 def initPlot(self):
59 """
59 """
60 Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos
60 Configura cada subplot con los valores maximos y minimos incluyendo los subtitulos
61 """
61 """
62
62
63
63
64 for index in range(self.nsubplots):
64 for index in range(self.nsubplots):
65 subplot = index
65 subplot = index
66 self.colorplotObj.iniPlot(subplot+1)
66 self.colorplotObj.iniPlot(subplot+1)
67
67
68
68
69 def plotData(self,
69 def plotData(self,
70 xmin=None,
70 xmin=None,
71 xmax=None,
71 xmax=None,
72 ymin=None,
72 ymin=None,
73 ymax=None,
73 ymax=None,
74 zmin=None,
74 zmin=None,
75 zmax=None,
75 zmax=None,
76 titleList=None,
76 titleList=None,
77 xlabelList=None,
77 xlabelList=None,
78 ylabelList=None,
78 ylabelList=None,
79 winTitle='',
79 winTitle='',
80 colormap = "br_green",
80 colormap = "br_green",
81 showColorbar = True,
81 showColorbar = True,
82 showPowerProfile = True,
82 showPowerProfile = True,
83 XAxisAsTime = False,
83 XAxisAsTime = False,
84 save = False,
84 save = False,
85 channelList=[]):
85 channelList=[]):
86
86
87 if channelList == []:
87 if channelList == []:
88 channelList = numpy.arange(self.spectraObj.nChannels)
88 channelList = numpy.arange(self.spectraObj.nChannels)
89
89
90
90
91 nsubplots = len(channelList)
91 nsubplots = len(channelList)
92 nX = self.spectraObj.nFFTPoints
92 nX = self.spectraObj.nFFTPoints
93 nY = self.spectraObj.nHeights
93 nY = self.spectraObj.nHeights
94
94
95 if self.spectraObj.noise == None:
95 if self.spectraObj.noise == None:
96 noise = numpy.ones(nsubplots)
96 noise = numpy.ones(nsubplots)
97 else:
97 else:
98 noise = 10.*numpy.log10(self.spectraObj.noise[channelList])
98 noise = 10.*numpy.log10(self.spectraObj.noise[channelList])
99
99
100 datadB = 10.*numpy.log10(self.spectraObj.data_spc[channelList,:,:])
100 datadB = 10.*numpy.log10(self.spectraObj.data_spc[channelList,:,:])
101 noisedB = 10.*numpy.log10(noise)
101 noisedB = 10.*numpy.log10(noise)
102
102
103 x = numpy.arange(nX)
103 x = numpy.arange(nX)
104 y = self.spectraObj.heightList
104 y = self.spectraObj.heightList
105
105
106 indexPlot = self.indexPlot
106 indexPlot = self.indexPlot
107
107
108 if not(self.__isPlotConfig):
108 if not(self.__isPlotConfig):
109 self.setup(indexPlot,
109 self.setup(indexPlot,
110 nsubplots,
110 nsubplots,
111 winTitle,
111 winTitle,
112 colormap,
112 colormap,
113 showColorbar,
113 showColorbar,
114 showPowerProfile,
114 showPowerProfile,
115 XAxisAsTime)
115 XAxisAsTime)
116
116
117
117
118 self.__isPlotConfig = True
118 self.__isPlotConfig = True
119
119
120 if not(self.__isPlotIni):
120 if not(self.__isPlotIni):
121 if titleList == None:
121 if titleList == None:
122 titleList = []
122 titleList = []
123 for i in range(nsubplots):
123 for i in range(nsubplots):
124 titleList.append("Channel: %d - Noise: %.2f" %(i, noise[i]))
124 titleList.append("Channel: %d - Noise: %.2f" %(i, noise[i]))
125
125
126 if xlabelList == None:
126 if xlabelList == None:
127 xlabelList = []
127 xlabelList = []
128 for i in range(nsubplots):
128 for i in range(nsubplots):
129 xlabelList.append("")
129 xlabelList.append("")
130
130
131 if ylabelList == None:
131 if ylabelList == None:
132 ylabelList = []
132 ylabelList = []
133 for i in range(nsubplots):
133 for i in range(nsubplots):
134 ylabelList.append("Range (Km)")
134 ylabelList.append("Range (Km)")
135
135
136 if xmin == None: xmin = x[0]
136 if xmin == None: xmin = x[0]
137 if xmax == None: xmax = x[-1]
137 if xmax == None: xmax = x[-1]
138 if ymin == None: ymin = y[0]
138 if ymin == None: ymin = y[0]
139 if ymax == None: ymax = y[-1]
139 if ymax == None: ymax = y[-1]
140 if zmin == None: zmin = 0
140 if zmin == None: zmin = datadB.min()
141 if zmax == None: zmax = 120
141 if zmax == None: zmax = datadB.max()
142
142
143 self.createObjects(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList)
143 self.createObjects(xmin,xmax,ymin,ymax,zmin,zmax,titleList,xlabelList,ylabelList)
144 self.__isPlotIni = True
144 self.__isPlotIni = True
145
145
146 thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc)
146 thisDatetime = datetime.datetime.fromtimestamp(self.spectraObj.m_BasicHeader.utc)
147 pltitle = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
147 pltitle = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
148
148
149 self.colorplotObj.setFigure(indexPlot)
149 self.colorplotObj.setFigure(indexPlot)
150 self.colorplotObj.setNewPage(pltitle)
150 self.colorplotObj.setNewPage(pltitle)
151 self.initPlot()
151 self.initPlot()
152
152
153 for channel in range(nsubplots):
153 for channel in range(nsubplots):
154 data = datadB[channel,:,:]
154 data = datadB[channel,:,:]
155 subtitle = "Channel: %d - Noise: %.2f" %(channel, noise[channel])
155 subtitle = "Channel: %d - Noise: %.2f" %(channel, noise[channel])
156 self.colorplotObj.plot(channel+1, x, y, data, subtitle)
156 self.colorplotObj.plot(channel+1, x, y, data, subtitle)
157
157
158 self.colorplotObj.refresh()
158 self.colorplotObj.refresh()
159
159
160 if save:
160 if save:
161 self.colorplotObj.setFigure(indexPlot)
161 self.colorplotObj.setFigure(indexPlot)
162 path = "/home/roj-idl71/tmp/"
162 path = "/home/roj-idl71/tmp/"
163 now = datetime.datetime.now().timetuple()
163 now = datetime.datetime.now().timetuple()
164 file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5])
164 file = "spc_img%02d_%03d_%02d%02d%02d.png"%(indexPlot,now[7],now[3],now[4],now[5])
165 filename = os.path.join(path,file)
165 filename = os.path.join(path,file)
166 self.colorplotObj.savePlot(indexPlot, filename)
166 self.colorplotObj.savePlot(indexPlot, filename)
167
167
168 self.colorplotObj.closePage()
168 self.colorplotObj.closePage()
169
169
170
170
@@ -1,696 +1,700
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 import time
9 import time
10
10
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Model.Spectra import Spectra
14 from Model.Spectra import Spectra
15 from IO.SpectraIO import SpectraWriter
15 from IO.SpectraIO import SpectraWriter
16 from Graphics.SpectraPlot import Spectrum
16 from Graphics.SpectraPlot import Spectrum
17 from JRONoise import Noise
17 from JRONoise import Noise
18
18
19 class SpectraProcessor:
19 class SpectraProcessor:
20 '''
20 '''
21 classdocs
21 classdocs
22 '''
22 '''
23
23
24 dataInObj = None
24 dataInObj = None
25
25
26 dataOutObj = None
26 dataOutObj = None
27
27
28 noiseObj = None
28 noiseObj = None
29
29
30 integratorObjList = []
30 integratorObjList = []
31
31
32 decoderObjList = []
32 decoderObjList = []
33
33
34 writerObjList = []
34 writerObjList = []
35
35
36 plotterObjList = []
36 plotterObjList = []
37
37
38 integratorObjIndex = None
38 integratorObjIndex = None
39
39
40 decoderObjIndex = None
40 decoderObjIndex = None
41
41
42 writerObjIndex = None
42 writerObjIndex = None
43
43
44 plotterObjIndex = None
44 plotterObjIndex = None
45
45
46 buffer = None
46 buffer = None
47
47
48 profIndex = 0
48 profIndex = 0
49
49
50 nFFTPoints = None
50 nFFTPoints = None
51
51
52 nChannels = None
52 nChannels = None
53
53
54 nHeights = None
54 nHeights = None
55
55
56 nPairs = None
56 nPairs = None
57
57
58 pairList = None
58 pairList = None
59
59
60
60
61 def __init__(self):
61 def __init__(self):
62 '''
62 '''
63 Constructor
63 Constructor
64 '''
64 '''
65
65
66 self.integratorObjIndex = None
66 self.integratorObjIndex = None
67 self.decoderObjIndex = None
67 self.decoderObjIndex = None
68 self.writerObjIndex = None
68 self.writerObjIndex = None
69 self.plotterObjIndex = None
69 self.plotterObjIndex = None
70
70
71 self.integratorObjList = []
71 self.integratorObjList = []
72 self.decoderObjList = []
72 self.decoderObjList = []
73 self.writerObjList = []
73 self.writerObjList = []
74 self.plotterObjList = []
74 self.plotterObjList = []
75
75
76 self.noiseObj = None
76 self.noiseObj = None
77 self.buffer = None
77 self.buffer = None
78 self.profIndex = 0
78 self.profIndex = 0
79
79
80 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
80 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
81
81
82 if dataInObj == None:
82 if dataInObj == None:
83 raise ValueError, ""
83 raise ValueError, ""
84
84
85 if nFFTPoints == None:
85 if nFFTPoints == None:
86 raise ValueError, ""
86 raise ValueError, ""
87
87
88 self.dataInObj = dataInObj
88 self.dataInObj = dataInObj
89
89
90 if dataOutObj == None:
90 if dataOutObj == None:
91 dataOutObj = Spectra()
91 dataOutObj = Spectra()
92
92
93 self.dataOutObj = dataOutObj
93 self.dataOutObj = dataOutObj
94 self.noiseObj = Noise()
94 self.noiseObj = Noise()
95
95
96 ##########################################
96 ##########################################
97 self.nFFTPoints = nFFTPoints
97 self.nFFTPoints = nFFTPoints
98 self.nChannels = self.dataInObj.nChannels
98 self.nChannels = self.dataInObj.nChannels
99 self.nHeights = self.dataInObj.nHeights
99 self.nHeights = self.dataInObj.nHeights
100 self.pairList = pairList
100 self.pairList = pairList
101 if pairList != None:
101 if pairList != None:
102 self.nPairs = len(pairList)
102 self.nPairs = len(pairList)
103 else:
103 else:
104 self.nPairs = 0
104 self.nPairs = 0
105
105
106 self.dataOutObj.heightList = self.dataInObj.heightList
106 self.dataOutObj.heightList = self.dataInObj.heightList
107 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
107 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
108 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
108 self.dataOutObj.m_BasicHeader = self.dataInObj.m_BasicHeader.copy()
109 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
109 self.dataOutObj.m_ProcessingHeader = self.dataInObj.m_ProcessingHeader.copy()
110 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
110 self.dataOutObj.m_RadarControllerHeader = self.dataInObj.m_RadarControllerHeader.copy()
111 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
111 self.dataOutObj.m_SystemHeader = self.dataInObj.m_SystemHeader.copy()
112
112
113 self.dataOutObj.dataType = self.dataInObj.dataType
113 self.dataOutObj.dataType = self.dataInObj.dataType
114 self.dataOutObj.nPairs = self.nPairs
114 self.dataOutObj.nPairs = self.nPairs
115 self.dataOutObj.nChannels = self.nChannels
115 self.dataOutObj.nChannels = self.nChannels
116 self.dataOutObj.nProfiles = self.nFFTPoints
116 self.dataOutObj.nProfiles = self.nFFTPoints
117 self.dataOutObj.nHeights = self.nHeights
117 self.dataOutObj.nHeights = self.nHeights
118 self.dataOutObj.nFFTPoints = self.nFFTPoints
118 self.dataOutObj.nFFTPoints = self.nFFTPoints
119 #self.dataOutObj.data = None
119 #self.dataOutObj.data = None
120
120
121 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
121 self.dataOutObj.m_SystemHeader.numChannels = self.nChannels
122 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
122 self.dataOutObj.m_SystemHeader.nProfiles = self.nFFTPoints
123
123
124 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
124 self.dataOutObj.m_ProcessingHeader.totalSpectra = self.nChannels + self.nPairs
125 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
125 self.dataOutObj.m_ProcessingHeader.profilesPerBlock = self.nFFTPoints
126 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
126 self.dataOutObj.m_ProcessingHeader.numHeights = self.nHeights
127 self.dataOutObj.m_ProcessingHeader.shif_fft = True
127 self.dataOutObj.m_ProcessingHeader.shif_fft = True
128
128
129 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
129 spectraComb = numpy.zeros( (self.nChannels+self.nPairs)*2,numpy.dtype('u1'))
130 k = 0
130 k = 0
131 for i in range( 0,self.nChannels*2,2 ):
131 for i in range( 0,self.nChannels*2,2 ):
132 spectraComb[i] = k
132 spectraComb[i] = k
133 spectraComb[i+1] = k
133 spectraComb[i+1] = k
134 k += 1
134 k += 1
135
135
136 k *= 2
136 k *= 2
137
137
138 if self.pairList != None:
138 if self.pairList != None:
139
139
140 for pair in self.pairList:
140 for pair in self.pairList:
141 spectraComb[k] = pair[0]
141 spectraComb[k] = pair[0]
142 spectraComb[k+1] = pair[1]
142 spectraComb[k+1] = pair[1]
143 k += 2
143 k += 2
144
144
145 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
145 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
146
146
147 return self.dataOutObj
147 return self.dataOutObj
148
148
149 def init(self):
149 def init(self):
150
150
151 self.nHeights = self.dataInObj.nHeights
152 self.dataOutObj.nHeights = self.nHeights
153 self.dataOutObj.heightList = self.dataInObj.heightList
154
151 self.integratorObjIndex = 0
155 self.integratorObjIndex = 0
152 self.decoderObjIndex = 0
156 self.decoderObjIndex = 0
153 self.writerObjIndex = 0
157 self.writerObjIndex = 0
154 self.plotterObjIndex = 0
158 self.plotterObjIndex = 0
155
159
156 if self.dataInObj.type == "Voltage":
160 if self.dataInObj.type == "Voltage":
157
161
158 if self.buffer == None:
162 if self.buffer == None:
159 self.buffer = numpy.zeros((self.nChannels,
163 self.buffer = numpy.zeros((self.nChannels,
160 self.nFFTPoints,
164 self.nFFTPoints,
161 self.nHeights),
165 self.dataInObj.nHeights),
162 dtype='complex')
166 dtype='complex')
163
167
164 self.buffer[:,self.profIndex,:] = self.dataInObj.data
168 self.buffer[:,self.profIndex,:] = self.dataInObj.data
165 self.profIndex += 1
169 self.profIndex += 1
166
170
167 if self.profIndex == self.nFFTPoints:
171 if self.profIndex == self.nFFTPoints:
168 self.__getFft()
172 self.__getFft()
169 self.dataOutObj.flagNoData = False
173 self.dataOutObj.flagNoData = False
170
174
171 self.buffer = None
175 self.buffer = None
172 self.profIndex = 0
176 self.profIndex = 0
173 return
177 return
174
178
175 self.dataOutObj.flagNoData = True
179 self.dataOutObj.flagNoData = True
176
180
177 return
181 return
178
182
179 #Other kind of data
183 #Other kind of data
180 if self.dataInObj.type == "Spectra":
184 if self.dataInObj.type == "Spectra":
181 self.dataOutObj.copy(self.dataInObj)
185 self.dataOutObj.copy(self.dataInObj)
182 self.dataOutObj.flagNoData = False
186 self.dataOutObj.flagNoData = False
183 return
187 return
184
188
185 raise ValueError, "The datatype is not valid"
189 raise ValueError, "The datatype is not valid"
186
190
187 def __getFft(self):
191 def __getFft(self):
188 """
192 """
189 Convierte valores de Voltaje a Spectra
193 Convierte valores de Voltaje a Spectra
190
194
191 Affected:
195 Affected:
192 self.dataOutObj.data_spc
196 self.dataOutObj.data_spc
193 self.dataOutObj.data_cspc
197 self.dataOutObj.data_cspc
194 self.dataOutObj.data_dc
198 self.dataOutObj.data_dc
195 self.dataOutObj.heightList
199 self.dataOutObj.heightList
196 self.dataOutObj.m_BasicHeader
200 self.dataOutObj.m_BasicHeader
197 self.dataOutObj.m_ProcessingHeader
201 self.dataOutObj.m_ProcessingHeader
198 self.dataOutObj.m_RadarControllerHeader
202 self.dataOutObj.m_RadarControllerHeader
199 self.dataOutObj.m_SystemHeader
203 self.dataOutObj.m_SystemHeader
200 self.profIndex
204 self.profIndex
201 self.buffer
205 self.buffer
202 self.dataOutObj.flagNoData
206 self.dataOutObj.flagNoData
203 self.dataOutObj.dataType
207 self.dataOutObj.dataType
204 self.dataOutObj.nPairs
208 self.dataOutObj.nPairs
205 self.dataOutObj.nChannels
209 self.dataOutObj.nChannels
206 self.dataOutObj.nProfiles
210 self.dataOutObj.nProfiles
207 self.dataOutObj.m_SystemHeader.numChannels
211 self.dataOutObj.m_SystemHeader.numChannels
208 self.dataOutObj.m_ProcessingHeader.totalSpectra
212 self.dataOutObj.m_ProcessingHeader.totalSpectra
209 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
213 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
210 self.dataOutObj.m_ProcessingHeader.numHeights
214 self.dataOutObj.m_ProcessingHeader.numHeights
211 self.dataOutObj.m_ProcessingHeader.spectraComb
215 self.dataOutObj.m_ProcessingHeader.spectraComb
212 self.dataOutObj.m_ProcessingHeader.shif_fft
216 self.dataOutObj.m_ProcessingHeader.shif_fft
213 """
217 """
214
218
215 if self.dataInObj.flagNoData:
219 if self.dataInObj.flagNoData:
216 return 0
220 return 0
217
221
218 fft_volt = numpy.fft.fft(self.buffer,axis=1)
222 fft_volt = numpy.fft.fft(self.buffer,axis=1)
219 dc = fft_volt[:,0,:]
223 dc = fft_volt[:,0,:]
220
224
221 #calculo de self-spectra
225 #calculo de self-spectra
222 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
226 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
223 spc = fft_volt * numpy.conjugate(fft_volt)
227 spc = fft_volt * numpy.conjugate(fft_volt)
224 spc = spc.real
228 spc = spc.real
225
229
226 blocksize = 0
230 blocksize = 0
227 blocksize += dc.size
231 blocksize += dc.size
228 blocksize += spc.size
232 blocksize += spc.size
229
233
230 cspc = None
234 cspc = None
231 pairIndex = 0
235 pairIndex = 0
232 if self.pairList != None:
236 if self.pairList != None:
233 #calculo de cross-spectra
237 #calculo de cross-spectra
234 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
238 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
235 for pair in self.pairList:
239 for pair in self.pairList:
236 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
240 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
237 pairIndex += 1
241 pairIndex += 1
238 blocksize += cspc.size
242 blocksize += cspc.size
239
243
240 self.dataOutObj.data_spc = spc
244 self.dataOutObj.data_spc = spc
241 self.dataOutObj.data_cspc = cspc
245 self.dataOutObj.data_cspc = cspc
242 self.dataOutObj.data_dc = dc
246 self.dataOutObj.data_dc = dc
243 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
247 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
244 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
248 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
245
249
246 # self.getNoise()
250 # self.getNoise()
247
251
248 def addWriter(self,wrpath):
252 def addWriter(self,wrpath):
249 objWriter = SpectraWriter(self.dataOutObj)
253 objWriter = SpectraWriter(self.dataOutObj)
250 objWriter.setup(wrpath)
254 objWriter.setup(wrpath)
251 self.writerObjList.append(objWriter)
255 self.writerObjList.append(objWriter)
252
256
253 def addPlotter(self,index=None):
257 def addPlotter(self,index=None):
254 if index==None:
258 if index==None:
255 index = self.plotterObjIndex
259 index = self.plotterObjIndex
256
260
257 plotObj = Spectrum(self.dataOutObj, index)
261 plotObj = Spectrum(self.dataOutObj, index)
258 self.plotterObjList.append(plotObj)
262 self.plotterObjList.append(plotObj)
259
263
260 def addIntegrator(self,N,timeInterval):
264 def addIntegrator(self,N,timeInterval):
261
265
262 objIncohInt = IncoherentIntegration(N,timeInterval)
266 objIncohInt = IncoherentIntegration(N,timeInterval)
263 self.integratorObjList.append(objIncohInt)
267 self.integratorObjList.append(objIncohInt)
264
268
265 def writeData(self, wrpath):
269 def writeData(self, wrpath):
266 if self.dataOutObj.flagNoData:
270 if self.dataOutObj.flagNoData:
267 return 0
271 return 0
268
272
269 if len(self.writerObjList) <= self.writerObjIndex:
273 if len(self.writerObjList) <= self.writerObjIndex:
270 self.addWriter(wrpath)
274 self.addWriter(wrpath)
271
275
272 self.writerObjList[self.writerObjIndex].putData()
276 self.writerObjList[self.writerObjIndex].putData()
273
277
274 self.writerObjIndex += 1
278 self.writerObjIndex += 1
275
279
276 def plotData(self,
280 def plotData(self,
277 xmin=None,
281 xmin=None,
278 xmax=None,
282 xmax=None,
279 ymin=None,
283 ymin=None,
280 ymax=None,
284 ymax=None,
281 zmin=None,
285 zmin=None,
282 zmax=None,
286 zmax=None,
283 titleList=None,
287 titleList=None,
284 xlabelList=None,
288 xlabelList=None,
285 ylabelList=None,
289 ylabelList=None,
286 winTitle='',
290 winTitle='',
287 colormap="br_green",
291 colormap="br_green",
288 showColorbar=False,
292 showColorbar=False,
289 showPowerProfile=False,
293 showPowerProfile=False,
290 XAxisAsTime=False,
294 XAxisAsTime=False,
291 save=False,
295 save=False,
292 index=None,
296 index=None,
293 channelList=[]):
297 channelList=[]):
294
298
295 if self.dataOutObj.flagNoData:
299 if self.dataOutObj.flagNoData:
296 return 0
300 return 0
297
301
298 if len(self.plotterObjList) <= self.plotterObjIndex:
302 if len(self.plotterObjList) <= self.plotterObjIndex:
299 self.addPlotter(index)
303 self.addPlotter(index)
300
304
301 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
305 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
302 xmax,
306 xmax,
303 ymin,
307 ymin,
304 ymax,
308 ymax,
305 zmin,
309 zmin,
306 zmax,
310 zmax,
307 titleList,
311 titleList,
308 xlabelList,
312 xlabelList,
309 ylabelList,
313 ylabelList,
310 winTitle,
314 winTitle,
311 colormap,
315 colormap,
312 showColorbar,
316 showColorbar,
313 showPowerProfile,
317 showPowerProfile,
314 XAxisAsTime,
318 XAxisAsTime,
315 save,
319 save,
316 channelList)
320 channelList)
317
321
318 self.plotterObjIndex += 1
322 self.plotterObjIndex += 1
319
323
320 def integrator(self, N=None, timeInterval=None):
324 def integrator(self, N=None, timeInterval=None):
321
325
322 if self.dataOutObj.flagNoData:
326 if self.dataOutObj.flagNoData:
323 return 0
327 return 0
324
328
325 if len(self.integratorObjList) <= self.integratorObjIndex:
329 if len(self.integratorObjList) <= self.integratorObjIndex:
326 self.addIntegrator(N,timeInterval)
330 self.addIntegrator(N,timeInterval)
327
331
328 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
332 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
329 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
333 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
330
334
331 if myIncohIntObj.isReady:
335 if myIncohIntObj.isReady:
332 self.dataOutObj.data_spc = myIncohIntObj.data
336 self.dataOutObj.data_spc = myIncohIntObj.data
333 self.dataOutObj.nAvg = myIncohIntObj.navg
337 self.dataOutObj.nAvg = myIncohIntObj.navg
334 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
338 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
335 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
339 #print "myIncohIntObj.navg: ",myIncohIntObj.navg
336 self.dataOutObj.flagNoData = False
340 self.dataOutObj.flagNoData = False
337
341
338 """Calcular el ruido"""
342 """Calcular el ruido"""
339 self.getNoise()
343 self.getNoise()
340 else:
344 else:
341 self.dataOutObj.flagNoData = True
345 self.dataOutObj.flagNoData = True
342
346
343 self.integratorObjIndex += 1
347 self.integratorObjIndex += 1
344
348
345
349
346
350
347 def removeDC(self, type):
351 def removeDC(self, type):
348
352
349 if self.dataOutObj.flagNoData:
353 if self.dataOutObj.flagNoData:
350 return 0
354 return 0
351
355
352 def removeInterference(self):
356 def removeInterference(self):
353
357
354 if self.dataOutObj.flagNoData:
358 if self.dataOutObj.flagNoData:
355 return 0
359 return 0
356
360
357 def removeSatellites(self):
361 def removeSatellites(self):
358
362
359 if self.dataOutObj.flagNoData:
363 if self.dataOutObj.flagNoData:
360 return 0
364 return 0
361
365
362 def getNoise(self, type="hildebrand", parm=None):
366 def getNoise(self, type="hildebrand", parm=None):
363
367
364 if parm == None:
368 if parm == None:
365 parm =self.dataOutObj.m_ProcessingHeader.incoherentInt
369 parm =self.dataOutObj.m_ProcessingHeader.incoherentInt
366
370
367 self.noiseObj.setNoise(self.dataOutObj.data_spc)
371 self.noiseObj.setNoise(self.dataOutObj.data_spc)
368
372
369 if type == "hildebrand":
373 if type == "hildebrand":
370 noise = self.noiseObj.byHildebrand(parm)
374 noise = self.noiseObj.byHildebrand(parm)
371
375
372 if type == "window":
376 if type == "window":
373 noise = self.noiseObj.byWindow(parm)
377 noise = self.noiseObj.byWindow(parm)
374
378
375 if type == "sort":
379 if type == "sort":
376 noise = self.noiseObj.bySort(parm)
380 noise = self.noiseObj.bySort(parm)
377
381
378 self.dataOutObj.noise = noise
382 self.dataOutObj.noise = noise
379 # print 10*numpy.log10(noise)
383 # print 10*numpy.log10(noise)
380
384
381 def selectChannels(self, channelList, pairList=[]):
385 def selectChannels(self, channelList, pairList=[]):
382
386
383 channelIndexList = []
387 channelIndexList = []
384
388
385 for channel in channelList:
389 for channel in channelList:
386 if channel in self.dataOutObj.channelList:
390 if channel in self.dataOutObj.channelList:
387 index = self.dataOutObj.channelList.index(channel)
391 index = self.dataOutObj.channelList.index(channel)
388 channelIndexList.append(index)
392 channelIndexList.append(index)
389
393
390 pairIndexList = []
394 pairIndexList = []
391
395
392 for pair in pairList:
396 for pair in pairList:
393 if pair in self.dataOutObj.pairList:
397 if pair in self.dataOutObj.pairList:
394 index = self.dataOutObj.pairList.index(pair)
398 index = self.dataOutObj.pairList.index(pair)
395 pairIndexList.append(index)
399 pairIndexList.append(index)
396
400
397 self.selectChannelsByIndex(channelIndexList, pairIndexList)
401 self.selectChannelsByIndex(channelIndexList, pairIndexList)
398
402
399 def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]):
403 def selectChannelsByIndex(self, channelIndexList, pairIndexList=[]):
400 """
404 """
401 Selecciona un bloque de datos en base a canales y pares segun el
405 Selecciona un bloque de datos en base a canales y pares segun el
402 channelIndexList y el pairIndexList
406 channelIndexList y el pairIndexList
403
407
404 Input:
408 Input:
405 channelIndexList : lista de indices de los canales a seleccionar por ej.
409 channelIndexList : lista de indices de los canales a seleccionar por ej.
406
410
407 Si tenemos los canales
411 Si tenemos los canales
408
412
409 self.channelList = (2,3,5,7)
413 self.channelList = (2,3,5,7)
410
414
411 y deseamos escoger los canales (3,7)
415 y deseamos escoger los canales (3,7)
412 entonces colocaremos el parametro
416 entonces colocaremos el parametro
413
417
414 channelndexList = (1,3)
418 channelndexList = (1,3)
415
419
416 pairIndexList : tupla de indice depares que se desea selecionar por ej.
420 pairIndexList : tupla de indice depares que se desea selecionar por ej.
417
421
418 Si tenemos los pares :
422 Si tenemos los pares :
419
423
420 ( (0,1), (0,2), (1,3), (2,5) )
424 ( (0,1), (0,2), (1,3), (2,5) )
421
425
422 y deseamos seleccionar los pares ((0,2), (2,5))
426 y deseamos seleccionar los pares ((0,2), (2,5))
423 entonces colocaremos el parametro
427 entonces colocaremos el parametro
424
428
425 pairIndexList = (1,3)
429 pairIndexList = (1,3)
426
430
427 Affected:
431 Affected:
428 self.dataOutObj.data_spc
432 self.dataOutObj.data_spc
429 self.dataOutObj.data_cspc
433 self.dataOutObj.data_cspc
430 self.dataOutObj.data_dc
434 self.dataOutObj.data_dc
431 self.dataOutObj.nChannels
435 self.dataOutObj.nChannels
432 self.dataOutObj.nPairs
436 self.dataOutObj.nPairs
433 self.dataOutObj.m_ProcessingHeader.spectraComb
437 self.dataOutObj.m_ProcessingHeader.spectraComb
434 self.dataOutObj.m_SystemHeader.numChannels
438 self.dataOutObj.m_SystemHeader.numChannels
435
439
436 self.dataOutObj.noise
440 self.dataOutObj.noise
437 Return:
441 Return:
438 None
442 None
439 """
443 """
440
444
441 if self.dataOutObj.flagNoData:
445 if self.dataOutObj.flagNoData:
442 return 0
446 return 0
443
447
444 if pairIndexList == []:
448 if pairIndexList == []:
445 pairIndexList = numpy.arange(len(self.dataOutObj.pairList))
449 pairIndexList = numpy.arange(len(self.dataOutObj.pairList))
446
450
447 nChannels = len(channelIndexList)
451 nChannels = len(channelIndexList)
448 nPairs = len(pairIndexList)
452 nPairs = len(pairIndexList)
449
453
450 blocksize = 0
454 blocksize = 0
451 #self spectra
455 #self spectra
452 spc = self.dataOutObj.data_spc[channelIndexList,:,:]
456 spc = self.dataOutObj.data_spc[channelIndexList,:,:]
453 blocksize += spc.size
457 blocksize += spc.size
454
458
455 cspc = None
459 cspc = None
456 if pairIndexList != []:
460 if pairIndexList != []:
457 cspc = self.dataOutObj.data_cspc[pairIndexList,:,:]
461 cspc = self.dataOutObj.data_cspc[pairIndexList,:,:]
458 blocksize += cspc.size
462 blocksize += cspc.size
459
463
460 #DC channel
464 #DC channel
461 dc = None
465 dc = None
462 if self.dataOutObj.m_ProcessingHeader.flag_dc:
466 if self.dataOutObj.m_ProcessingHeader.flag_dc:
463 dc = self.dataOutObj.data_dc[channelIndexList,:]
467 dc = self.dataOutObj.data_dc[channelIndexList,:]
464 blocksize += dc.size
468 blocksize += dc.size
465
469
466 #Almacenar las combinaciones de canales y cros espectros
470 #Almacenar las combinaciones de canales y cros espectros
467
471
468 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
472 spectraComb = numpy.zeros( (nChannels+nPairs)*2,numpy.dtype('u1'))
469 i = 0
473 i = 0
470 for spcChannel in channelIndexList:
474 for spcChannel in channelIndexList:
471 spectraComb[i] = spcChannel
475 spectraComb[i] = spcChannel
472 spectraComb[i+1] = spcChannel
476 spectraComb[i+1] = spcChannel
473 i += 2
477 i += 2
474
478
475 if pairList != None:
479 if pairList != None:
476 for pair in pairList:
480 for pair in pairList:
477 spectraComb[i] = pair[0]
481 spectraComb[i] = pair[0]
478 spectraComb[i+1] = pair[1]
482 spectraComb[i+1] = pair[1]
479 i += 2
483 i += 2
480
484
481 #######
485 #######
482
486
483 self.dataOutObj.data_spc = spc
487 self.dataOutObj.data_spc = spc
484 self.dataOutObj.data_cspc = cspc
488 self.dataOutObj.data_cspc = cspc
485 self.dataOutObj.data_dc = dc
489 self.dataOutObj.data_dc = dc
486 self.dataOutObj.nChannels = nChannels
490 self.dataOutObj.nChannels = nChannels
487 self.dataOutObj.nPairs = nPairs
491 self.dataOutObj.nPairs = nPairs
488
492
489 self.dataOutObj.channelIndexList = channelIndexList
493 self.dataOutObj.channelIndexList = channelIndexList
490
494
491 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
495 self.dataOutObj.m_ProcessingHeader.spectraComb = spectraComb
492 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
496 self.dataOutObj.m_ProcessingHeader.totalSpectra = nChannels + nPairs
493 self.dataOutObj.m_SystemHeader.numChannels = nChannels
497 self.dataOutObj.m_SystemHeader.numChannels = nChannels
494 self.dataOutObj.nChannels = nChannels
498 self.dataOutObj.nChannels = nChannels
495 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
499 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
496
500
497 if cspc == None:
501 if cspc == None:
498 self.dataOutObj.m_ProcessingHeader.flag_dc = False
502 self.dataOutObj.m_ProcessingHeader.flag_dc = False
499 if dc == None:
503 if dc == None:
500 self.dataOutObj.m_ProcessingHeader.flag_cpsc = False
504 self.dataOutObj.m_ProcessingHeader.flag_cpsc = False
501
505
502 def selectHeightsByValue(self, minHei, maxHei):
506 def selectHeightsByValue(self, minHei, maxHei):
503 """
507 """
504 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
508 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
505 minHei <= height <= maxHei
509 minHei <= height <= maxHei
506
510
507 Input:
511 Input:
508 minHei : valor minimo de altura a considerar
512 minHei : valor minimo de altura a considerar
509 maxHei : valor maximo de altura a considerar
513 maxHei : valor maximo de altura a considerar
510
514
511 Affected:
515 Affected:
512 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
516 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
513
517
514 Return:
518 Return:
515 None
519 None
516 """
520 """
517
521
518 if self.dataOutObj.flagNoData:
522 if self.dataOutObj.flagNoData:
519 return 0
523 return 0
520
524
521 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
525 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
522 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
526 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
523
527
524 if (maxHei > self.dataOutObj.heightList[-1]):
528 if (maxHei > self.dataOutObj.heightList[-1]):
525 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
529 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
526
530
527 minIndex = 0
531 minIndex = 0
528 maxIndex = 0
532 maxIndex = 0
529 data = self.dataOutObj.heightList
533 data = self.dataOutObj.heightList
530
534
531 for i,val in enumerate(data):
535 for i,val in enumerate(data):
532 if val < minHei:
536 if val < minHei:
533 continue
537 continue
534 else:
538 else:
535 minIndex = i;
539 minIndex = i;
536 break
540 break
537
541
538 for i,val in enumerate(data):
542 for i,val in enumerate(data):
539 if val <= maxHei:
543 if val <= maxHei:
540 maxIndex = i;
544 maxIndex = i;
541 else:
545 else:
542 break
546 break
543
547
544 self.selectHeightsByIndex(minIndex, maxIndex)
548 self.selectHeightsByIndex(minIndex, maxIndex)
545
549
546 def selectHeightsByIndex(self, minIndex, maxIndex):
550 def selectHeightsByIndex(self, minIndex, maxIndex):
547 """
551 """
548 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
552 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
549 minIndex <= index <= maxIndex
553 minIndex <= index <= maxIndex
550
554
551 Input:
555 Input:
552 minIndex : valor minimo de altura a considerar
556 minIndex : valor minimo de altura a considerar
553 maxIndex : valor maximo de altura a considerar
557 maxIndex : valor maximo de altura a considerar
554
558
555 Affected:
559 Affected:
556 self.dataOutObj.data_spc
560 self.dataOutObj.data_spc
557 self.dataOutObj.data_cspc
561 self.dataOutObj.data_cspc
558 self.dataOutObj.data_dc
562 self.dataOutObj.data_dc
559 self.dataOutObj.heightList
563 self.dataOutObj.heightList
560 self.dataOutObj.nHeights
564 self.dataOutObj.nHeights
561 self.dataOutObj.m_ProcessingHeader.numHeights
565 self.dataOutObj.m_ProcessingHeader.numHeights
562 self.dataOutObj.m_ProcessingHeader.blockSize
566 self.dataOutObj.m_ProcessingHeader.blockSize
563 self.dataOutObj.m_ProcessingHeader.firstHeight
567 self.dataOutObj.m_ProcessingHeader.firstHeight
564 self.dataOutObj.m_RadarControllerHeader.numHeights
568 self.dataOutObj.m_RadarControllerHeader.numHeights
565
569
566 Return:
570 Return:
567 None
571 None
568 """
572 """
569
573
570 if self.dataOutObj.flagNoData:
574 if self.dataOutObj.flagNoData:
571 return 0
575 return 0
572
576
573 if (minIndex < 0) or (minIndex > maxIndex):
577 if (minIndex < 0) or (minIndex > maxIndex):
574 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
578 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
575
579
576 if (maxIndex >= self.dataOutObj.nHeights):
580 if (maxIndex >= self.dataOutObj.nHeights):
577 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
581 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
578
582
579 nChannels = self.dataOutObj.nChannels
583 nChannels = self.dataOutObj.nChannels
580 nPairs = self.dataOutObj.nPairs
584 nPairs = self.dataOutObj.nPairs
581 nProfiles = self.dataOutObj.nProfiles
585 nProfiles = self.dataOutObj.nProfiles
582 dataType = self.dataOutObj.dataType
586 dataType = self.dataOutObj.dataType
583 nHeights = maxIndex - minIndex + 1
587 nHeights = maxIndex - minIndex + 1
584 blockSize = 0
588 blockSize = 0
585
589
586 #self spectra
590 #self spectra
587 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
591 spc = self.dataOutObj.data_spc[:,:,minIndex:maxIndex+1]
588 blockSize += spc.size
592 blockSize += spc.size
589
593
590 #cross spectra
594 #cross spectra
591 cspc = None
595 cspc = None
592 if self.dataOutObj.data_cspc != None:
596 if self.dataOutObj.data_cspc != None:
593 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
597 cspc = self.dataOutObj.data_cspc[:,:,minIndex:maxIndex+1]
594 blockSize += cspc.size
598 blockSize += cspc.size
595
599
596 #DC channel
600 #DC channel
597 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
601 dc = self.dataOutObj.data_dc[:,minIndex:maxIndex+1]
598 blockSize += dc.size
602 blockSize += dc.size
599
603
600 self.dataOutObj.data_spc = spc
604 self.dataOutObj.data_spc = spc
601 if cspc != None:
605 if cspc != None:
602 self.dataOutObj.data_cspc = cspc
606 self.dataOutObj.data_cspc = cspc
603 self.dataOutObj.data_dc = dc
607 self.dataOutObj.data_dc = dc
604
608
605 firstHeight = self.dataOutObj.heightList[minIndex]
609 firstHeight = self.dataOutObj.heightList[minIndex]
606
610
607 self.dataOutObj.nHeights = nHeights
611 self.dataOutObj.nHeights = nHeights
608 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
612 self.dataOutObj.m_ProcessingHeader.blockSize = blockSize
609 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
613 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
610 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
614 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
611 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
615 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
612
616
613 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
617 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
614
618
615
619
616 class IncoherentIntegration:
620 class IncoherentIntegration:
617
621
618 integ_counter = None
622 integ_counter = None
619 data = None
623 data = None
620 navg = None
624 navg = None
621 buffer = None
625 buffer = None
622 nIncohInt = None
626 nIncohInt = None
623
627
624 def __init__(self, N = None, timeInterval = None):
628 def __init__(self, N = None, timeInterval = None):
625 """
629 """
626 N
630 N
627 timeInterval - interval time [min], integer value
631 timeInterval - interval time [min], integer value
628 """
632 """
629
633
630 self.data = None
634 self.data = None
631 self.navg = None
635 self.navg = None
632 self.buffer = None
636 self.buffer = None
633 self.timeOut = None
637 self.timeOut = None
634 self.exitCondition = False
638 self.exitCondition = False
635 self.isReady = False
639 self.isReady = False
636 self.nIncohInt = N
640 self.nIncohInt = N
637 self.integ_counter = 0
641 self.integ_counter = 0
638 if timeInterval!=None:
642 if timeInterval!=None:
639 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
643 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
640
644
641 if ((timeInterval==None) and (N==None)):
645 if ((timeInterval==None) and (N==None)):
642 print 'N = None ; timeInterval = None'
646 print 'N = None ; timeInterval = None'
643 sys.exit(0)
647 sys.exit(0)
644 elif timeInterval == None:
648 elif timeInterval == None:
645 self.timeFlag = False
649 self.timeFlag = False
646 else:
650 else:
647 self.timeFlag = True
651 self.timeFlag = True
648
652
649
653
650 def exe(self,data,timeOfData):
654 def exe(self,data,timeOfData):
651 """
655 """
652 data
656 data
653
657
654 timeOfData [seconds]
658 timeOfData [seconds]
655 """
659 """
656
660
657 if self.timeFlag:
661 if self.timeFlag:
658 if self.timeOut == None:
662 if self.timeOut == None:
659 self.timeOut = timeOfData + self.timeIntervalInSeconds
663 self.timeOut = timeOfData + self.timeIntervalInSeconds
660
664
661 if timeOfData < self.timeOut:
665 if timeOfData < self.timeOut:
662 if self.buffer == None:
666 if self.buffer == None:
663 self.buffer = data
667 self.buffer = data
664 else:
668 else:
665 self.buffer = self.buffer + data
669 self.buffer = self.buffer + data
666 self.integ_counter += 1
670 self.integ_counter += 1
667 else:
671 else:
668 self.exitCondition = True
672 self.exitCondition = True
669
673
670 else:
674 else:
671 if self.integ_counter < self.nIncohInt:
675 if self.integ_counter < self.nIncohInt:
672 if self.buffer == None:
676 if self.buffer == None:
673 self.buffer = data
677 self.buffer = data
674 else:
678 else:
675 self.buffer = self.buffer + data
679 self.buffer = self.buffer + data
676
680
677 self.integ_counter += 1
681 self.integ_counter += 1
678
682
679 if self.integ_counter == self.nIncohInt:
683 if self.integ_counter == self.nIncohInt:
680 self.exitCondition = True
684 self.exitCondition = True
681
685
682 if self.exitCondition:
686 if self.exitCondition:
683 self.data = self.buffer
687 self.data = self.buffer
684 self.navg = self.integ_counter
688 self.navg = self.integ_counter
685 self.isReady = True
689 self.isReady = True
686 self.buffer = None
690 self.buffer = None
687 self.timeOut = None
691 self.timeOut = None
688 self.integ_counter = 0
692 self.integ_counter = 0
689 self.exitCondition = False
693 self.exitCondition = False
690
694
691 if self.timeFlag:
695 if self.timeFlag:
692 self.buffer = data
696 self.buffer = data
693 self.timeOut = timeOfData + self.timeIntervalInSeconds
697 self.timeOut = timeOfData + self.timeIntervalInSeconds
694 else:
698 else:
695 self.isReady = False
699 self.isReady = False
696 No newline at end of file
700
@@ -1,674 +1,679
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
7
8 import os, sys
8 import os, sys
9 import numpy
9 import numpy
10
10
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Model.Voltage import Voltage
14 from Model.Voltage import Voltage
15 from IO.VoltageIO import VoltageWriter
15 from IO.VoltageIO import VoltageWriter
16 from Graphics.VoltagePlot import Osciloscope
16 from Graphics.VoltagePlot import Osciloscope
17 from Graphics.VoltagePlot import RTI
17 from Graphics.VoltagePlot import RTI
18
18
19 class VoltageProcessor:
19 class VoltageProcessor:
20 '''
20 '''
21 classdocs
21 classdocs
22 '''
22 '''
23
23
24 dataInObj = None
24 dataInObj = None
25 dataOutObj = None
25 dataOutObj = None
26
26
27 integratorObjIndex = None
27 integratorObjIndex = None
28 decoderObjIndex = None
28 decoderObjIndex = None
29 profSelectorObjIndex = None
29 profSelectorObjIndex = None
30 writerObjIndex = None
30 writerObjIndex = None
31 plotterObjIndex = None
31 plotterObjIndex = None
32 flipIndex = None
32 flipIndex = None
33
33
34 integratorObjList = []
34 integratorObjList = []
35 decoderObjList = []
35 decoderObjList = []
36 profileSelectorObjList = []
36 profileSelectorObjList = []
37 writerObjList = []
37 writerObjList = []
38 plotterObjList = []
38 plotterObjList = []
39 m_Voltage= Voltage()
39 m_Voltage= Voltage()
40
40
41 def __init__(self):
41 def __init__(self):
42 '''
42 '''
43 Constructor
43 Constructor
44 '''
44 '''
45
45
46 self.integratorObjIndex = None
46 self.integratorObjIndex = None
47 self.decoderObjIndex = None
47 self.decoderObjIndex = None
48 self.profSelectorObjIndex = None
48 self.profSelectorObjIndex = None
49 self.writerObjIndex = None
49 self.writerObjIndex = None
50 self.plotterObjIndex = None
50 self.plotterObjIndex = None
51 self.flipIndex = 1
51 self.flipIndex = 1
52 self.integratorObjList = []
52 self.integratorObjList = []
53 self.decoderObjList = []
53 self.decoderObjList = []
54 self.profileSelectorObjList = []
54 self.profileSelectorObjList = []
55 self.writerObjList = []
55 self.writerObjList = []
56 self.plotterObjList = []
56 self.plotterObjList = []
57
57
58 def setup(self, dataInObj=None, dataOutObj=None):
58 def setup(self, dataInObj=None, dataOutObj=None):
59
59
60 self.dataInObj = dataInObj
60 self.dataInObj = dataInObj
61
61
62 if dataOutObj == None:
62 if dataOutObj == None:
63 dataOutObj = Voltage()
63 dataOutObj = Voltage()
64
64
65 dataOutObj.copy(dataInObj)
65 dataOutObj.copy(dataInObj)
66
66
67 self.dataOutObj = dataOutObj
67 self.dataOutObj = dataOutObj
68
68
69 return self.dataOutObj
69 return self.dataOutObj
70
70
71
71
72 def init(self):
72 def init(self):
73
73
74 self.integratorObjIndex = 0
74 self.integratorObjIndex = 0
75 self.decoderObjIndex = 0
75 self.decoderObjIndex = 0
76 self.profSelectorObjIndex = 0
76 self.profSelectorObjIndex = 0
77 self.writerObjIndex = 0
77 self.writerObjIndex = 0
78 self.plotterObjIndex = 0
78 self.plotterObjIndex = 0
79 self.dataOutObj.copy(self.dataInObj)
79 self.dataOutObj.copy(self.dataInObj)
80
80
81 if self.profSelectorObjIndex != None:
81 if self.profSelectorObjIndex != None:
82 for profSelObj in self.profileSelectorObjList:
82 for profSelObj in self.profileSelectorObjList:
83 profSelObj.incIndex()
83 profSelObj.incIndex()
84
84
85 def addWriter(self, wrpath):
85 def addWriter(self, wrpath):
86 objWriter = VoltageWriter(self.dataOutObj)
86 objWriter = VoltageWriter(self.dataOutObj)
87 objWriter.setup(wrpath)
87 objWriter.setup(wrpath)
88 self.writerObjList.append(objWriter)
88 self.writerObjList.append(objWriter)
89
89
90 def addRti(self,index=None):
90 def addRti(self,index=None):
91 if index==None:
91 if index==None:
92 index = self.plotterObjIndex
92 index = self.plotterObjIndex
93
93
94 plotObj = RTI(self.dataOutObj, index)
94 plotObj = RTI(self.dataOutObj, index)
95 self.plotterObjList.append(plotObj)
95 self.plotterObjList.append(plotObj)
96
96
97 def addPlotter(self, index=None):
97 def addPlotter(self, index=None):
98 if index==None:
98 if index==None:
99 index = self.plotterObjIndex
99 index = self.plotterObjIndex
100
100
101 plotObj = Osciloscope(self.dataOutObj, index)
101 plotObj = Osciloscope(self.dataOutObj, index)
102 self.plotterObjList.append(plotObj)
102 self.plotterObjList.append(plotObj)
103
103
104 def addIntegrator(self, N,timeInterval):
104 def addIntegrator(self, N,timeInterval):
105
105
106 objCohInt = CoherentIntegrator(N,timeInterval)
106 objCohInt = CoherentIntegrator(N,timeInterval)
107 self.integratorObjList.append(objCohInt)
107 self.integratorObjList.append(objCohInt)
108
108
109 def addDecoder(self, code, ncode, nbaud):
109 def addDecoder(self, code, ncode, nbaud):
110
110
111 objDecoder = Decoder(code,ncode,nbaud)
111 objDecoder = Decoder(code,ncode,nbaud)
112 self.decoderObjList.append(objDecoder)
112 self.decoderObjList.append(objDecoder)
113
113
114 def addProfileSelector(self, nProfiles):
114 def addProfileSelector(self, nProfiles):
115
115
116 objProfSelector = ProfileSelector(nProfiles)
116 objProfSelector = ProfileSelector(nProfiles)
117 self.profileSelectorObjList.append(objProfSelector)
117 self.profileSelectorObjList.append(objProfSelector)
118
118
119 def writeData(self,wrpath):
119 def writeData(self,wrpath):
120
120
121 if self.dataOutObj.flagNoData:
121 if self.dataOutObj.flagNoData:
122 return 0
122 return 0
123
123
124 if len(self.writerObjList) <= self.writerObjIndex:
124 if len(self.writerObjList) <= self.writerObjIndex:
125 self.addWriter(wrpath)
125 self.addWriter(wrpath)
126
126
127 self.writerObjList[self.writerObjIndex].putData()
127 self.writerObjList[self.writerObjIndex].putData()
128
128
129 self.writerObjIndex += 1
129 self.writerObjIndex += 1
130
130
131 def addScope(self,index=None):
131 def addScope(self,index=None):
132 if index==None:
132 if index==None:
133 index = self.plotterObjIndex
133 index = self.plotterObjIndex
134
134
135 plotObj = Osciloscope(self.dataOutObj, index)
135 plotObj = Osciloscope(self.dataOutObj, index)
136 self.plotterObjList.append(plotObj)
136 self.plotterObjList.append(plotObj)
137
137
138 def plotScope(self,
138 def plotScope(self,
139 xmin=None,
139 xmin=None,
140 xmax=None,
140 xmax=None,
141 ymin=None,
141 ymin=None,
142 ymax=None,
142 ymax=None,
143 titleList=None,
143 titleList=None,
144 xlabelList=None,
144 xlabelList=None,
145 ylabelList=None,
145 ylabelList=None,
146 winTitle='',
146 winTitle='',
147 type="power",
147 type="power",
148 index=None):
148 index=None):
149
149
150 if self.dataOutObj.flagNoData:
150 if self.dataOutObj.flagNoData:
151 return 0
151 return 0
152
152
153 if len(self.plotterObjList) <= self.plotterObjIndex:
153 if len(self.plotterObjList) <= self.plotterObjIndex:
154 self.addScope(index)
154 self.addScope(index)
155
155
156 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
156 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
157 xmax,
157 xmax,
158 ymin,
158 ymin,
159 ymax,
159 ymax,
160 titleList,
160 titleList,
161 xlabelList,
161 xlabelList,
162 ylabelList,
162 ylabelList,
163 winTitle,
163 winTitle,
164 type)
164 type)
165
165
166 self.plotterObjIndex += 1
166 self.plotterObjIndex += 1
167
167
168 def plotRti(self,
168 def plotRti(self,
169 xmin=None,
169 xmin=None,
170 xmax=None,
170 xmax=None,
171 ymin=None,
171 ymin=None,
172 ymax=None,
172 ymax=None,
173 zmin=None,
173 zmin=None,
174 zmax=None,
174 zmax=None,
175 titleList=None,
175 titleList=None,
176 xlabelList=None,
176 xlabelList=None,
177 ylabelList=None,
177 ylabelList=None,
178 winTitle='',
178 winTitle='',
179 timezone='lt',
179 timezone='lt',
180 npoints=1000.0,
180 npoints=1000.0,
181 colormap="br_green",
181 colormap="br_green",
182 showColorbar=True,
182 showColorbar=True,
183 showPowerProfile=False,
183 showPowerProfile=False,
184 XAxisAsTime=True,
184 XAxisAsTime=True,
185 save=False,
185 save=False,
186 index=None):
186 index=None):
187
187
188 if self.dataOutObj.flagNoData:
188 if self.dataOutObj.flagNoData:
189 return 0
189 return 0
190
190
191 if len(self.plotterObjList) <= self.plotterObjIndex:
191 if len(self.plotterObjList) <= self.plotterObjIndex:
192 self.addRti(index)
192 self.addRti(index)
193
193
194 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
194 self.plotterObjList[self.plotterObjIndex].plotData(xmin,
195 xmax,
195 xmax,
196 ymin,
196 ymin,
197 ymax,
197 ymax,
198 zmin,
198 zmin,
199 zmax,
199 zmax,
200 titleList,
200 titleList,
201 xlabelList,
201 xlabelList,
202 ylabelList,
202 ylabelList,
203 winTitle,
203 winTitle,
204 timezone,
204 timezone,
205 npoints,
205 npoints,
206 colormap,
206 colormap,
207 showColorbar,
207 showColorbar,
208 showPowerProfile,
208 showPowerProfile,
209 XAxisAsTime,
209 XAxisAsTime,
210 save)
210 save)
211
211
212 self.plotterObjIndex += 1
212 self.plotterObjIndex += 1
213
213
214
214
215 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None):
215 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, type='iq', winTitle='', index=None):
216 if self.dataOutObj.flagNoData:
216 if self.dataOutObj.flagNoData:
217 return 0
217 return 0
218
218
219 if len(self.plotterObjList) <= self.plotterObjIndex:
219 if len(self.plotterObjList) <= self.plotterObjIndex:
220 self.addPlotter(index)
220 self.addPlotter(index)
221
221
222 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,type=type, winTitle=winTitle)
222 self.plotterObjList[self.plotterObjIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,type=type, winTitle=winTitle)
223
223
224 self.plotterObjIndex += 1
224 self.plotterObjIndex += 1
225
225
226 def integrator(self, N=None, timeInterval=None):
226 def integrator(self, N=None, timeInterval=None):
227
227
228 if self.dataOutObj.flagNoData:
228 if self.dataOutObj.flagNoData:
229 return 0
229 return 0
230
230
231 if len(self.integratorObjList) <= self.integratorObjIndex:
231 if len(self.integratorObjList) <= self.integratorObjIndex:
232 self.addIntegrator(N,timeInterval)
232 self.addIntegrator(N,timeInterval)
233
233
234 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
234 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
235 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=self.dataOutObj.m_BasicHeader.utc)
235 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=self.dataOutObj.m_BasicHeader.utc)
236
236
237 if myCohIntObj.isReady:
237 if myCohIntObj.isReady:
238 self.dataOutObj.data = myCohIntObj.data
238 self.dataOutObj.data = myCohIntObj.data
239 self.dataOutObj.nAvg = myCohIntObj.navg
239 self.dataOutObj.nAvg = myCohIntObj.navg
240 self.dataOutObj.m_ProcessingHeader.coherentInt *= myCohIntObj.navg
240 self.dataOutObj.m_ProcessingHeader.coherentInt *= myCohIntObj.navg
241 #print "myCohIntObj.navg: ",myCohIntObj.navg
241 #print "myCohIntObj.navg: ",myCohIntObj.navg
242 self.dataOutObj.flagNoData = False
242 self.dataOutObj.flagNoData = False
243
243
244 else:
244 else:
245 self.dataOutObj.flagNoData = True
245 self.dataOutObj.flagNoData = True
246
246
247 self.integratorObjIndex += 1
247 self.integratorObjIndex += 1
248
248
249 def decoder(self,code=None,type = 0):
249 def decoder(self,code=None, mode = 0):
250
250
251 if self.dataOutObj.flagNoData:
251 if self.dataOutObj.flagNoData:
252 return 0
252 return 0
253
253
254 if code == None:
254 if code == None:
255 code = self.dataOutObj.m_RadarControllerHeader.code
255 code = self.dataOutObj.m_RadarControllerHeader.code
256 ncode, nbaud = code.shape
256 ncode, nbaud = code.shape
257
257
258 if len(self.decoderObjList) <= self.decoderObjIndex:
258 if len(self.decoderObjList) <= self.decoderObjIndex:
259 self.addDecoder(code,ncode,nbaud)
259 self.addDecoder(code,ncode,nbaud)
260
260
261 myDecodObj = self.decoderObjList[self.decoderObjIndex]
261 myDecodObj = self.decoderObjList[self.decoderObjIndex]
262 myDecodObj.exe(data=self.dataOutObj.data,type=type)
262 data, ndata = myDecodObj.exe(data=self.dataOutObj.data,mode=mode)
263
263
264 if myDecodObj.flag:
264 self.dataOutObj.data = data
265 self.dataOutObj.data = myDecodObj.data
265 self.dataOutObj.nHeights = ndata
266 self.dataOutObj.flagNoData = False
266 self.dataOutObj.heightList = self.dataInObj.heightList[:ndata]
267 else:
267 self.dataOutObj.flagNoData = False
268 self.dataOutObj.flagNoData = True
269
268
270 self.decoderObjIndex += 1
269 self.decoderObjIndex += 1
271
270
272
271
273 def filterByHei(self, window):
272 def filterByHei(self, window):
274 if window == None:
273 if window == None:
275 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
274 window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0]
276
275
277 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
276 newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window
278 dim1 = self.dataOutObj.data.shape[0]
277 dim1 = self.dataOutObj.data.shape[0]
279 dim2 = self.dataOutObj.data.shape[1]
278 dim2 = self.dataOutObj.data.shape[1]
280 r = dim2 % window
279 r = dim2 % window
281
280
282 buffer = self.dataOutObj.data[:,0:dim2-r]
281 buffer = self.dataOutObj.data[:,0:dim2-r]
283 buffer = buffer.reshape(dim1,dim2/window,window)
282 buffer = buffer.reshape(dim1,dim2/window,window)
284 buffer = numpy.sum(buffer,2)
283 buffer = numpy.sum(buffer,2)
285 self.dataOutObj.data = buffer
284 self.dataOutObj.data = buffer
286
285
287 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
286 self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta
288 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
287 self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1]
289
288
290 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
289 self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights
291
290
292 #self.dataOutObj.heightList es un numpy.array
291 #self.dataOutObj.heightList es un numpy.array
293 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
292 self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta)
294
293
295 def deFlip(self):
294 def deFlip(self):
296 self.dataOutObj.data *= self.flipIndex
295 self.dataOutObj.data *= self.flipIndex
297 self.flipIndex *= -1.
296 self.flipIndex *= -1.
298
297
299 def selectChannels(self, channelList):
298 def selectChannels(self, channelList):
300 pass
299 pass
301
300
302 def selectChannelsByIndex(self, channelIndexList):
301 def selectChannelsByIndex(self, channelIndexList):
303 """
302 """
304 Selecciona un bloque de datos en base a canales segun el channelIndexList
303 Selecciona un bloque de datos en base a canales segun el channelIndexList
305
304
306 Input:
305 Input:
307 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
306 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
308
307
309 Affected:
308 Affected:
310 self.dataOutObj.data
309 self.dataOutObj.data
311 self.dataOutObj.channelIndexList
310 self.dataOutObj.channelIndexList
312 self.dataOutObj.nChannels
311 self.dataOutObj.nChannels
313 self.dataOutObj.m_ProcessingHeader.totalSpectra
312 self.dataOutObj.m_ProcessingHeader.totalSpectra
314 self.dataOutObj.m_SystemHeader.numChannels
313 self.dataOutObj.m_SystemHeader.numChannels
315 self.dataOutObj.m_ProcessingHeader.blockSize
314 self.dataOutObj.m_ProcessingHeader.blockSize
316
315
317 Return:
316 Return:
318 None
317 None
319 """
318 """
320 if self.dataOutObj.flagNoData:
319 if self.dataOutObj.flagNoData:
321 return 0
320 return 0
322
321
323 for channel in channelIndexList:
322 for channel in channelIndexList:
324 if channel not in self.dataOutObj.channelIndexList:
323 if channel not in self.dataOutObj.channelIndexList:
325 raise ValueError, "The value %d in channelIndexList is not valid" %channel
324 raise ValueError, "The value %d in channelIndexList is not valid" %channel
326
325
327 nChannels = len(channelIndexList)
326 nChannels = len(channelIndexList)
328
327
329 data = self.dataOutObj.data[channelIndexList,:]
328 data = self.dataOutObj.data[channelIndexList,:]
330
329
331 self.dataOutObj.data = data
330 self.dataOutObj.data = data
332 self.dataOutObj.channelIndexList = channelIndexList
331 self.dataOutObj.channelIndexList = channelIndexList
333 self.dataOutObj.nChannels = nChannels
332 self.dataOutObj.nChannels = nChannels
334
333
335 self.dataOutObj.m_ProcessingHeader.totalSpectra = 0
334 self.dataOutObj.m_ProcessingHeader.totalSpectra = 0
336 self.dataOutObj.m_SystemHeader.numChannels = nChannels
335 self.dataOutObj.m_SystemHeader.numChannels = nChannels
337 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
336 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
338 return 1
337 return 1
339
338
340
339
341 def selectHeightsByValue(self, minHei, maxHei):
340 def selectHeightsByValue(self, minHei, maxHei):
342 """
341 """
343 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
342 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
344 minHei <= height <= maxHei
343 minHei <= height <= maxHei
345
344
346 Input:
345 Input:
347 minHei : valor minimo de altura a considerar
346 minHei : valor minimo de altura a considerar
348 maxHei : valor maximo de altura a considerar
347 maxHei : valor maximo de altura a considerar
349
348
350 Affected:
349 Affected:
351 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
350 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
352
351
353 Return:
352 Return:
354 1 si el metodo se ejecuto con exito caso contrario devuelve 0
353 1 si el metodo se ejecuto con exito caso contrario devuelve 0
355 """
354 """
356 if self.dataOutObj.flagNoData:
355 if self.dataOutObj.flagNoData:
357 return 0
356 return 0
358
357
359 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
358 if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei):
360 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
359 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
361
360
362 if (maxHei > self.dataOutObj.heightList[-1]):
361 if (maxHei > self.dataOutObj.heightList[-1]):
363 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
362 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
364
363
365 minIndex = 0
364 minIndex = 0
366 maxIndex = 0
365 maxIndex = 0
367 data = self.dataOutObj.heightList
366 data = self.dataOutObj.heightList
368
367
369 for i,val in enumerate(data):
368 for i,val in enumerate(data):
370 if val < minHei:
369 if val < minHei:
371 continue
370 continue
372 else:
371 else:
373 minIndex = i;
372 minIndex = i;
374 break
373 break
375
374
376 for i,val in enumerate(data):
375 for i,val in enumerate(data):
377 if val <= maxHei:
376 if val <= maxHei:
378 maxIndex = i;
377 maxIndex = i;
379 else:
378 else:
380 break
379 break
381
380
382 self.selectHeightsByIndex(minIndex, maxIndex)
381 self.selectHeightsByIndex(minIndex, maxIndex)
383 return 1
382 return 1
384
383
385
384
386 def selectHeightsByIndex(self, minIndex, maxIndex):
385 def selectHeightsByIndex(self, minIndex, maxIndex):
387 """
386 """
388 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
387 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
389 minIndex <= index <= maxIndex
388 minIndex <= index <= maxIndex
390
389
391 Input:
390 Input:
392 minIndex : valor de indice minimo de altura a considerar
391 minIndex : valor de indice minimo de altura a considerar
393 maxIndex : valor de indice maximo de altura a considerar
392 maxIndex : valor de indice maximo de altura a considerar
394
393
395 Affected:
394 Affected:
396 self.dataOutObj.data
395 self.dataOutObj.data
397 self.dataOutObj.heightList
396 self.dataOutObj.heightList
398 self.dataOutObj.nHeights
397 self.dataOutObj.nHeights
399 self.dataOutObj.m_ProcessingHeader.blockSize
398 self.dataOutObj.m_ProcessingHeader.blockSize
400 self.dataOutObj.m_ProcessingHeader.numHeights
399 self.dataOutObj.m_ProcessingHeader.numHeights
401 self.dataOutObj.m_ProcessingHeader.firstHeight
400 self.dataOutObj.m_ProcessingHeader.firstHeight
402 self.dataOutObj.m_RadarControllerHeader
401 self.dataOutObj.m_RadarControllerHeader
403
402
404 Return:
403 Return:
405 1 si el metodo se ejecuto con exito caso contrario devuelve 0
404 1 si el metodo se ejecuto con exito caso contrario devuelve 0
406 """
405 """
407 if self.dataOutObj.flagNoData:
406 if self.dataOutObj.flagNoData:
408 return 0
407 return 0
409
408
410 if (minIndex < 0) or (minIndex > maxIndex):
409 if (minIndex < 0) or (minIndex > maxIndex):
411 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
410 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
412
411
413 if (maxIndex >= self.dataOutObj.nHeights):
412 if (maxIndex >= self.dataOutObj.nHeights):
414 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
413 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
415
414
416 nHeights = maxIndex - minIndex + 1
415 nHeights = maxIndex - minIndex + 1
417
416
418 #voltage
417 #voltage
419 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
418 data = self.dataOutObj.data[:,minIndex:maxIndex+1]
420
419
421 firstHeight = self.dataOutObj.heightList[minIndex]
420 firstHeight = self.dataOutObj.heightList[minIndex]
422
421
423 self.dataOutObj.data = data
422 self.dataOutObj.data = data
424 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
423 self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1]
425 self.dataOutObj.nHeights = nHeights
424 self.dataOutObj.nHeights = nHeights
426 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
425 self.dataOutObj.m_ProcessingHeader.blockSize = data.size
427 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
426 self.dataOutObj.m_ProcessingHeader.numHeights = nHeights
428 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
427 self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight
429 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
428 self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights
430 return 1
429 return 1
431
430
432 def selectProfilesByValue(self,indexList, nProfiles):
431 def selectProfilesByValue(self,indexList, nProfiles):
433 if self.dataOutObj.flagNoData:
432 if self.dataOutObj.flagNoData:
434 return 0
433 return 0
435
434
436 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
435 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
437 self.addProfileSelector(nProfiles)
436 self.addProfileSelector(nProfiles)
438
437
439 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
438 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
440
439
441 if not(profileSelectorObj.isProfileInList(indexList)):
440 if not(profileSelectorObj.isProfileInList(indexList)):
442 self.dataOutObj.flagNoData = True
441 self.dataOutObj.flagNoData = True
443 self.profSelectorObjIndex += 1
442 self.profSelectorObjIndex += 1
444 return 0
443 return 0
445
444
446 self.dataOutObj.flagNoData = False
445 self.dataOutObj.flagNoData = False
447 self.profSelectorObjIndex += 1
446 self.profSelectorObjIndex += 1
448
447
449 return 1
448 return 1
450
449
451
450
452 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
451 def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles):
453 """
452 """
454 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
453 Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango
455 minIndex <= index <= maxIndex
454 minIndex <= index <= maxIndex
456
455
457 Input:
456 Input:
458 minIndex : valor de indice minimo de perfil a considerar
457 minIndex : valor de indice minimo de perfil a considerar
459 maxIndex : valor de indice maximo de perfil a considerar
458 maxIndex : valor de indice maximo de perfil a considerar
460 nProfiles : numero de profiles
459 nProfiles : numero de profiles
461
460
462 Affected:
461 Affected:
463 self.dataOutObj.flagNoData
462 self.dataOutObj.flagNoData
464 self.profSelectorObjIndex
463 self.profSelectorObjIndex
465
464
466 Return:
465 Return:
467 1 si el metodo se ejecuto con exito caso contrario devuelve 0
466 1 si el metodo se ejecuto con exito caso contrario devuelve 0
468 """
467 """
469
468
470 if self.dataOutObj.flagNoData:
469 if self.dataOutObj.flagNoData:
471 return 0
470 return 0
472
471
473 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
472 if self.profSelectorObjIndex >= len(self.profileSelectorObjList):
474 self.addProfileSelector(nProfiles)
473 self.addProfileSelector(nProfiles)
475
474
476 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
475 profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex]
477
476
478 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
477 if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)):
479 self.dataOutObj.flagNoData = True
478 self.dataOutObj.flagNoData = True
480 self.profSelectorObjIndex += 1
479 self.profSelectorObjIndex += 1
481 return 0
480 return 0
482
481
483 self.dataOutObj.flagNoData = False
482 self.dataOutObj.flagNoData = False
484 self.profSelectorObjIndex += 1
483 self.profSelectorObjIndex += 1
485
484
486 return 1
485 return 1
487
486
488 def selectNtxs(self, ntx):
487 def selectNtxs(self, ntx):
489 pass
488 pass
490
489
491
490
492 class Decoder:
491 class Decoder:
493
492
494 data = None
493 data = None
495 profCounter = 1
494 profCounter = 1
496 nCode = None
495 nCode = None
497 nBaud = None
496 nBaud = None
498 codeIndex = 0
497 codeIndex = 0
499 code = None
498 code = None
500 flag = False
499 flag = False
501
500
502 def __init__(self,code, ncode, nbaud):
501 def __init__(self,code, ncode, nbaud):
503
502
504 self.data = None
503 self.data = None
504 self.ndata = None
505 self.profCounter = 1
505 self.profCounter = 1
506 self.nCode = ncode
506 self.nCode = ncode
507 self.nBaud = nbaud
507 self.nBaud = nbaud
508 self.codeIndex = 0
508 self.codeIndex = 0
509 self.code = code #this is a List
509 self.code = code #this is a List
510 self.flag = False
510 self.flag = False
511
511
512 def exe(self, data, ndata=None, type = 0):
512 def exe(self, data, ndata=None, mode = 0):
513
513
514 if ndata == None: ndata = data.shape[1]
514 if ndata == None: ndata = data.shape[1]
515
515
516 if type == 0:
516 if mode == 0:
517 self.convolutionInFreq(data,ndata)
517 self.convolutionInFreq(data,ndata)
518
518
519 if type == 1:
519 if mode == 1:
520 self.convolutionInTime(data, ndata)
520 self.convolutionInTime(data, ndata)
521
521
522 self.ndata = ndata - self.nBaud + 1
523
524 return self.data, self.ndata
525
522 def convolutionInFreq(self,data, ndata):
526 def convolutionInFreq(self,data, ndata):
523
527
524 newcode = numpy.zeros(ndata)
528 newcode = numpy.zeros(ndata)
525 newcode[0:self.nBaud] = self.code[self.codeIndex]
529 newcode[0:self.nBaud] = self.code[self.codeIndex]
526
530
527 self.codeIndex += 1
531 self.codeIndex += 1
528
532
529 fft_data = numpy.fft.fft(data, axis=1)
533 fft_data = numpy.fft.fft(data, axis=1)
530 fft_code = numpy.conj(numpy.fft.fft(newcode))
534 fft_code = numpy.conj(numpy.fft.fft(newcode))
531 fft_code = fft_code.reshape(1,len(fft_code))
535 fft_code = fft_code.reshape(1,len(fft_code))
532
536
533 conv = fft_data.copy()
537 conv = fft_data.copy()
534 conv.fill(0)
538 conv.fill(0)
535
539
536 conv = fft_data*fft_code
540 conv = fft_data*fft_code
537
541
538 self.data = numpy.fft.ifft(conv,axis=1)
542 data = numpy.fft.ifft(conv,axis=1)
543 self.data = data[:,:-self.nBaud+1]
539 self.flag = True
544 self.flag = True
540
545
541 if self.profCounter == self.nCode:
546 if self.profCounter == self.nCode:
542 self.profCounter = 0
547 self.profCounter = 0
543 self.codeIndex = 0
548 self.codeIndex = 0
544
549
545 self.profCounter += 1
550 self.profCounter += 1
546
551
547 def convolutionInTime(self, data, ndata):
552 def convolutionInTime(self, data, ndata):
548
553
549 nchannel = data.shape[1]
554 nchannel = data.shape[1]
550 newcode = self.code[self.codeIndex]
555 newcode = self.code[self.codeIndex]
551 self.codeIndex += 1
556 self.codeIndex += 1
552 conv = data.copy()
557 conv = data.copy()
553 for i in range(nchannel):
558 for i in range(nchannel):
554 conv[i,:] = numpy.correlate(data[i,:], newcode, 'same')
559 conv[i,:] = numpy.correlate(data[i,:], newcode)
555
560
556 self.data = conv
561 self.data = conv
557 self.flag = True
562 self.flag = True
558
563
559 if self.profCounter == self.nCode:
564 if self.profCounter == self.nCode:
560 self.profCounter = 0
565 self.profCounter = 0
561 self.codeIndex = 0
566 self.codeIndex = 0
562
567
563 self.profCounter += 1
568 self.profCounter += 1
564
569
565
570
566 class CoherentIntegrator:
571 class CoherentIntegrator:
567
572
568 integ_counter = None
573 integ_counter = None
569 data = None
574 data = None
570 navg = None
575 navg = None
571 buffer = None
576 buffer = None
572 nCohInt = None
577 nCohInt = None
573
578
574 def __init__(self, N=None,timeInterval=None):
579 def __init__(self, N=None,timeInterval=None):
575
580
576 self.data = None
581 self.data = None
577 self.navg = None
582 self.navg = None
578 self.buffer = None
583 self.buffer = None
579 self.timeOut = None
584 self.timeOut = None
580 self.exitCondition = False
585 self.exitCondition = False
581 self.isReady = False
586 self.isReady = False
582 self.nCohInt = N
587 self.nCohInt = N
583 self.integ_counter = 0
588 self.integ_counter = 0
584 if timeInterval!=None:
589 if timeInterval!=None:
585 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
590 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
586
591
587 if ((timeInterval==None) and (N==None)):
592 if ((timeInterval==None) and (N==None)):
588 print 'N = None ; timeInterval = None'
593 raise ValueError, "N = None ; timeInterval = None"
589 sys.exit(0)
594
590 elif timeInterval == None:
595 if timeInterval == None:
591 self.timeFlag = False
596 self.timeFlag = False
592 else:
597 else:
593 self.timeFlag = True
598 self.timeFlag = True
594
599
595 def exe(self, data, timeOfData):
600 def exe(self, data, timeOfData):
596
601
597 if self.timeFlag:
602 if self.timeFlag:
598 if self.timeOut == None:
603 if self.timeOut == None:
599 self.timeOut = timeOfData + self.timeIntervalInSeconds
604 self.timeOut = timeOfData + self.timeIntervalInSeconds
600
605
601 if timeOfData < self.timeOut:
606 if timeOfData < self.timeOut:
602 if self.buffer == None:
607 if self.buffer == None:
603 self.buffer = data
608 self.buffer = data
604 else:
609 else:
605 self.buffer = self.buffer + data
610 self.buffer = self.buffer + data
606 self.integ_counter += 1
611 self.integ_counter += 1
607 else:
612 else:
608 self.exitCondition = True
613 self.exitCondition = True
609
614
610 else:
615 else:
611 if self.integ_counter < self.nCohInt:
616 if self.integ_counter < self.nCohInt:
612 if self.buffer == None:
617 if self.buffer == None:
613 self.buffer = data
618 self.buffer = data
614 else:
619 else:
615 self.buffer = self.buffer + data
620 self.buffer = self.buffer + data
616
621
617 self.integ_counter += 1
622 self.integ_counter += 1
618
623
619 if self.integ_counter == self.nCohInt:
624 if self.integ_counter == self.nCohInt:
620 self.exitCondition = True
625 self.exitCondition = True
621
626
622 if self.exitCondition:
627 if self.exitCondition:
623 self.data = self.buffer
628 self.data = self.buffer
624 self.navg = self.integ_counter
629 self.navg = self.integ_counter
625 self.isReady = True
630 self.isReady = True
626 self.buffer = None
631 self.buffer = None
627 self.timeOut = None
632 self.timeOut = None
628 self.integ_counter = 0
633 self.integ_counter = 0
629 self.exitCondition = False
634 self.exitCondition = False
630
635
631 if self.timeFlag:
636 if self.timeFlag:
632 self.buffer = data
637 self.buffer = data
633 self.timeOut = timeOfData + self.timeIntervalInSeconds
638 self.timeOut = timeOfData + self.timeIntervalInSeconds
634 else:
639 else:
635 self.isReady = False
640 self.isReady = False
636
641
637
642
638
643
639 class ProfileSelector:
644 class ProfileSelector:
640
645
641 profileIndex = None
646 profileIndex = None
642 # Tamanho total de los perfiles
647 # Tamanho total de los perfiles
643 nProfiles = None
648 nProfiles = None
644
649
645 def __init__(self, nProfiles):
650 def __init__(self, nProfiles):
646
651
647 self.profileIndex = 0
652 self.profileIndex = 0
648 self.nProfiles = nProfiles
653 self.nProfiles = nProfiles
649
654
650 def incIndex(self):
655 def incIndex(self):
651 self.profileIndex += 1
656 self.profileIndex += 1
652
657
653 if self.profileIndex >= self.nProfiles:
658 if self.profileIndex >= self.nProfiles:
654 self.profileIndex = 0
659 self.profileIndex = 0
655
660
656 def isProfileInRange(self, minIndex, maxIndex):
661 def isProfileInRange(self, minIndex, maxIndex):
657
662
658 if self.profileIndex < minIndex:
663 if self.profileIndex < minIndex:
659 return False
664 return False
660
665
661 if self.profileIndex > maxIndex:
666 if self.profileIndex > maxIndex:
662 return False
667 return False
663
668
664 return True
669 return True
665
670
666 def isProfileInList(self, profileList):
671 def isProfileInList(self, profileList):
667
672
668 if self.profileIndex not in profileList:
673 if self.profileIndex not in profileList:
669 return False
674 return False
670
675
671 return True
676 return True
672
677
673
678
674 No newline at end of file
679
General Comments 0
You need to be logged in to leave comments. Login now