##// END OF EJS Templates
Se agregan las clases para Procesamiento en Alturas: SpectraHeis, sus graficos tambien son agregados en jroplot.py....
Daniel Valdez -
r334:39d6a3ac95d1
parent child
Show More
@@ -0,0 +1,66
1 import os, sys
2
3 path = os.path.split(os.getcwd())[0]
4 sys.path.append(path)
5
6 from controller import *
7
8 desc = "EWDrifts Experiment Test"
9 filename = "ewdrifts.xml"
10
11 controllerObj = Project()
12
13 controllerObj.setup(id = '191', name='test01', description=desc)
14
15 readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage',
16 path='/Volumes/data_e/PaseDelSol/Raw/100KHZ',
17 startDate='2013/02/06',
18 endDate='2013/12/31',
19 startTime='17:30:00',
20 endTime='17:40:59',
21 online=0,
22 walk=1)
23
24 procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId())
25
26 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraHeis', inputId=procUnitConfObj0.getId())
27
28 opObj11 = procUnitConfObj1.addOperation(name='IncohInt4SpectraHeis', optype='other')
29 opObj11.addParameter(name='timeInterval', value='5', format='float')
30
31 opObj11 = procUnitConfObj1.addOperation(name='SpectraHeisScope', optype='other')
32 opObj11.addParameter(name='idfigure', value='10', format='int')
33 opObj11.addParameter(name='wintitle', value='SpectraHeisPlot', format='str')
34 opObj11.addParameter(name='ymin', value='125', format='int')
35 opObj11.addParameter(name='ymax', value='140', format='int')
36 #opObj11.addParameter(name='channelList', value='0,1,2', format='intlist')
37 #opObj11.addParameter(name='showprofile', value='1', format='int')
38 opObj11.addParameter(name='save', value='1', format='bool')
39 opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/sun_pics', format='str')
40
41
42 #opObj11 = procUnitConfObj1.addOperation(name='RTIfromSpectraHeis', optype='other')
43 #opObj11.addParameter(name='idfigure', value='6', format='int')
44 #opObj11.addParameter(name='wintitle', value='RTIPLot', format='str')
45 ##opObj11.addParameter(name='zmin', value='10', format='int')
46 ##opObj11.addParameter(name='zmax', value='40', format='int')
47 #opObj11.addParameter(name='ymin', value='60', format='int')
48 #opObj11.addParameter(name='ymax', value='130', format='int')
49 ##opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
50 #opObj11.addParameter(name='timerange', value='600', format='int')
51 ##opObj11.addParameter(name='showprofile', value='0', format='int')
52 #opObj11.addParameter(name='save', value='1', format='bool')
53 #opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/sun_pics', format='str')
54
55
56
57 print "Escribiendo el archivo XML"
58 controllerObj.writeXml(filename)
59 print "Leyendo el archivo XML"
60 controllerObj.readXml(filename)
61
62 controllerObj.createObjects()
63 controllerObj.connectObjects()
64 controllerObj.run()
65
66 No newline at end of file
@@ -1,1004 +1,1308
1 import numpy
1 import numpy
2 import time, datetime, os
2 import time, datetime, os
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class CrossSpectraPlot(Figure):
5 class CrossSpectraPlot(Figure):
6
6
7 __isConfig = None
7 __isConfig = None
8 __nsubplots = None
8 __nsubplots = None
9
9
10 WIDTH = None
10 WIDTH = None
11 HEIGHT = None
11 HEIGHT = None
12 WIDTHPROF = None
12 WIDTHPROF = None
13 HEIGHTPROF = None
13 HEIGHTPROF = None
14 PREFIX = 'cspc'
14 PREFIX = 'cspc'
15
15
16 def __init__(self):
16 def __init__(self):
17
17
18 self.__isConfig = False
18 self.__isConfig = False
19 self.__nsubplots = 4
19 self.__nsubplots = 4
20
20
21 self.WIDTH = 250
21 self.WIDTH = 250
22 self.HEIGHT = 250
22 self.HEIGHT = 250
23 self.WIDTHPROF = 0
23 self.WIDTHPROF = 0
24 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
25
25
26 def getSubplots(self):
26 def getSubplots(self):
27
27
28 ncol = 4
28 ncol = 4
29 nrow = self.nplots
29 nrow = self.nplots
30
30
31 return nrow, ncol
31 return nrow, ncol
32
32
33 def setup(self, idfigure, nplots, wintitle, showprofile=True):
33 def setup(self, idfigure, nplots, wintitle, showprofile=True):
34
34
35 self.__showprofile = showprofile
35 self.__showprofile = showprofile
36 self.nplots = nplots
36 self.nplots = nplots
37
37
38 ncolspan = 1
38 ncolspan = 1
39 colspan = 1
39 colspan = 1
40
40
41 self.createFigure(idfigure = idfigure,
41 self.createFigure(idfigure = idfigure,
42 wintitle = wintitle,
42 wintitle = wintitle,
43 widthplot = self.WIDTH + self.WIDTHPROF,
43 widthplot = self.WIDTH + self.WIDTHPROF,
44 heightplot = self.HEIGHT + self.HEIGHTPROF)
44 heightplot = self.HEIGHT + self.HEIGHTPROF)
45
45
46 nrow, ncol = self.getSubplots()
46 nrow, ncol = self.getSubplots()
47
47
48 counter = 0
48 counter = 0
49 for y in range(nrow):
49 for y in range(nrow):
50 for x in range(ncol):
50 for x in range(ncol):
51 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
51 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
52
52
53 counter += 1
53 counter += 1
54
54
55 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
55 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
56 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
56 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
57 save=False, figpath='./', figfile=None,
57 save=False, figpath='./', figfile=None,
58 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r'):
58 power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r'):
59
59
60 """
60 """
61
61
62 Input:
62 Input:
63 dataOut :
63 dataOut :
64 idfigure :
64 idfigure :
65 wintitle :
65 wintitle :
66 channelList :
66 channelList :
67 showProfile :
67 showProfile :
68 xmin : None,
68 xmin : None,
69 xmax : None,
69 xmax : None,
70 ymin : None,
70 ymin : None,
71 ymax : None,
71 ymax : None,
72 zmin : None,
72 zmin : None,
73 zmax : None
73 zmax : None
74 """
74 """
75
75
76 if pairsList == None:
76 if pairsList == None:
77 pairsIndexList = dataOut.pairsIndexList
77 pairsIndexList = dataOut.pairsIndexList
78 else:
78 else:
79 pairsIndexList = []
79 pairsIndexList = []
80 for pair in pairsList:
80 for pair in pairsList:
81 if pair not in dataOut.pairsList:
81 if pair not in dataOut.pairsList:
82 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
82 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
83 pairsIndexList.append(dataOut.pairsList.index(pair))
83 pairsIndexList.append(dataOut.pairsList.index(pair))
84
84
85 if pairsIndexList == []:
85 if pairsIndexList == []:
86 return
86 return
87
87
88 if len(pairsIndexList) > 4:
88 if len(pairsIndexList) > 4:
89 pairsIndexList = pairsIndexList[0:4]
89 pairsIndexList = pairsIndexList[0:4]
90 factor = dataOut.normFactor
90 factor = dataOut.normFactor
91 x = dataOut.getVelRange(1)
91 x = dataOut.getVelRange(1)
92 y = dataOut.getHeiRange()
92 y = dataOut.getHeiRange()
93 z = dataOut.data_spc[:,:,:]/factor
93 z = dataOut.data_spc[:,:,:]/factor
94 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
94 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
95 avg = numpy.abs(numpy.average(z, axis=1))
95 avg = numpy.abs(numpy.average(z, axis=1))
96 noise = dataOut.getNoise()/factor
96 noise = dataOut.getNoise()/factor
97
97
98 zdB = 10*numpy.log10(z)
98 zdB = 10*numpy.log10(z)
99 avgdB = 10*numpy.log10(avg)
99 avgdB = 10*numpy.log10(avg)
100 noisedB = 10*numpy.log10(noise)
100 noisedB = 10*numpy.log10(noise)
101
101
102
102
103 thisDatetime = dataOut.datatime
103 thisDatetime = dataOut.datatime
104 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
104 title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
105 xlabel = "Velocity (m/s)"
105 xlabel = "Velocity (m/s)"
106 ylabel = "Range (Km)"
106 ylabel = "Range (Km)"
107
107
108 if not self.__isConfig:
108 if not self.__isConfig:
109
109
110 nplots = len(pairsIndexList)
110 nplots = len(pairsIndexList)
111
111
112 self.setup(idfigure=idfigure,
112 self.setup(idfigure=idfigure,
113 nplots=nplots,
113 nplots=nplots,
114 wintitle=wintitle,
114 wintitle=wintitle,
115 showprofile=showprofile)
115 showprofile=showprofile)
116
116
117 if xmin == None: xmin = numpy.nanmin(x)
117 if xmin == None: xmin = numpy.nanmin(x)
118 if xmax == None: xmax = numpy.nanmax(x)
118 if xmax == None: xmax = numpy.nanmax(x)
119 if ymin == None: ymin = numpy.nanmin(y)
119 if ymin == None: ymin = numpy.nanmin(y)
120 if ymax == None: ymax = numpy.nanmax(y)
120 if ymax == None: ymax = numpy.nanmax(y)
121 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
121 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
122 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
122 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
123
123
124 self.__isConfig = True
124 self.__isConfig = True
125
125
126 self.setWinTitle(title)
126 self.setWinTitle(title)
127
127
128 for i in range(self.nplots):
128 for i in range(self.nplots):
129 pair = dataOut.pairsList[pairsIndexList[i]]
129 pair = dataOut.pairsList[pairsIndexList[i]]
130
130
131 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
131 title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]])
132 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
132 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
133 axes0 = self.axesList[i*self.__nsubplots]
133 axes0 = self.axesList[i*self.__nsubplots]
134 axes0.pcolor(x, y, zdB,
134 axes0.pcolor(x, y, zdB,
135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
135 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
136 xlabel=xlabel, ylabel=ylabel, title=title,
136 xlabel=xlabel, ylabel=ylabel, title=title,
137 ticksize=9, colormap=power_cmap, cblabel='')
137 ticksize=9, colormap=power_cmap, cblabel='')
138
138
139 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
139 title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]])
140 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
140 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
141 axes0 = self.axesList[i*self.__nsubplots+1]
141 axes0 = self.axesList[i*self.__nsubplots+1]
142 axes0.pcolor(x, y, zdB,
142 axes0.pcolor(x, y, zdB,
143 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
143 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
144 xlabel=xlabel, ylabel=ylabel, title=title,
144 xlabel=xlabel, ylabel=ylabel, title=title,
145 ticksize=9, colormap=power_cmap, cblabel='')
145 ticksize=9, colormap=power_cmap, cblabel='')
146
146
147 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
147 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
148 coherence = numpy.abs(coherenceComplex)
148 coherence = numpy.abs(coherenceComplex)
149 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
149 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
150 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
150 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
151
151
152 title = "Coherence %d%d" %(pair[0], pair[1])
152 title = "Coherence %d%d" %(pair[0], pair[1])
153 axes0 = self.axesList[i*self.__nsubplots+2]
153 axes0 = self.axesList[i*self.__nsubplots+2]
154 axes0.pcolor(x, y, coherence,
154 axes0.pcolor(x, y, coherence,
155 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
155 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
156 xlabel=xlabel, ylabel=ylabel, title=title,
156 xlabel=xlabel, ylabel=ylabel, title=title,
157 ticksize=9, colormap=coherence_cmap, cblabel='')
157 ticksize=9, colormap=coherence_cmap, cblabel='')
158
158
159 title = "Phase %d%d" %(pair[0], pair[1])
159 title = "Phase %d%d" %(pair[0], pair[1])
160 axes0 = self.axesList[i*self.__nsubplots+3]
160 axes0 = self.axesList[i*self.__nsubplots+3]
161 axes0.pcolor(x, y, phase,
161 axes0.pcolor(x, y, phase,
162 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
162 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
163 xlabel=xlabel, ylabel=ylabel, title=title,
163 xlabel=xlabel, ylabel=ylabel, title=title,
164 ticksize=9, colormap=phase_cmap, cblabel='')
164 ticksize=9, colormap=phase_cmap, cblabel='')
165
165
166
166
167
167
168 self.draw()
168 self.draw()
169
169
170 if save:
170 if save:
171 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
171 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
172 if figfile == None:
172 if figfile == None:
173 figfile = self.getFilename(name = date)
173 figfile = self.getFilename(name = date)
174
174
175 self.saveFigure(figpath, figfile)
175 self.saveFigure(figpath, figfile)
176
176
177
177
178 class RTIPlot(Figure):
178 class RTIPlot(Figure):
179
179
180 __isConfig = None
180 __isConfig = None
181 __nsubplots = None
181 __nsubplots = None
182
182
183 WIDTHPROF = None
183 WIDTHPROF = None
184 HEIGHTPROF = None
184 HEIGHTPROF = None
185 PREFIX = 'rti'
185 PREFIX = 'rti'
186
186
187 def __init__(self):
187 def __init__(self):
188
188
189 self.timerange = 2*60*60
189 self.timerange = 2*60*60
190 self.__isConfig = False
190 self.__isConfig = False
191 self.__nsubplots = 1
191 self.__nsubplots = 1
192
192
193 self.WIDTH = 800
193 self.WIDTH = 800
194 self.HEIGHT = 150
194 self.HEIGHT = 150
195 self.WIDTHPROF = 120
195 self.WIDTHPROF = 120
196 self.HEIGHTPROF = 0
196 self.HEIGHTPROF = 0
197 self.counterftp = 0
197 self.counterftp = 0
198
198
199 def getSubplots(self):
199 def getSubplots(self):
200
200
201 ncol = 1
201 ncol = 1
202 nrow = self.nplots
202 nrow = self.nplots
203
203
204 return nrow, ncol
204 return nrow, ncol
205
205
206 def setup(self, idfigure, nplots, wintitle, showprofile=True):
206 def setup(self, idfigure, nplots, wintitle, showprofile=True):
207
207
208 self.__showprofile = showprofile
208 self.__showprofile = showprofile
209 self.nplots = nplots
209 self.nplots = nplots
210
210
211 ncolspan = 1
211 ncolspan = 1
212 colspan = 1
212 colspan = 1
213 if showprofile:
213 if showprofile:
214 ncolspan = 7
214 ncolspan = 7
215 colspan = 6
215 colspan = 6
216 self.__nsubplots = 2
216 self.__nsubplots = 2
217
217
218 self.createFigure(idfigure = idfigure,
218 self.createFigure(idfigure = idfigure,
219 wintitle = wintitle,
219 wintitle = wintitle,
220 widthplot = self.WIDTH + self.WIDTHPROF,
220 widthplot = self.WIDTH + self.WIDTHPROF,
221 heightplot = self.HEIGHT + self.HEIGHTPROF)
221 heightplot = self.HEIGHT + self.HEIGHTPROF)
222
222
223 nrow, ncol = self.getSubplots()
223 nrow, ncol = self.getSubplots()
224
224
225 counter = 0
225 counter = 0
226 for y in range(nrow):
226 for y in range(nrow):
227 for x in range(ncol):
227 for x in range(ncol):
228
228
229 if counter >= self.nplots:
229 if counter >= self.nplots:
230 break
230 break
231
231
232 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
232 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
233
233
234 if showprofile:
234 if showprofile:
235 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
235 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
236
236
237 counter += 1
237 counter += 1
238
238
239 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
239 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
240 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
240 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
241 timerange=None,
241 timerange=None,
242 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1):
242 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1):
243
243
244 """
244 """
245
245
246 Input:
246 Input:
247 dataOut :
247 dataOut :
248 idfigure :
248 idfigure :
249 wintitle :
249 wintitle :
250 channelList :
250 channelList :
251 showProfile :
251 showProfile :
252 xmin : None,
252 xmin : None,
253 xmax : None,
253 xmax : None,
254 ymin : None,
254 ymin : None,
255 ymax : None,
255 ymax : None,
256 zmin : None,
256 zmin : None,
257 zmax : None
257 zmax : None
258 """
258 """
259
259
260 if channelList == None:
260 if channelList == None:
261 channelIndexList = dataOut.channelIndexList
261 channelIndexList = dataOut.channelIndexList
262 else:
262 else:
263 channelIndexList = []
263 channelIndexList = []
264 for channel in channelList:
264 for channel in channelList:
265 if channel not in dataOut.channelList:
265 if channel not in dataOut.channelList:
266 raise ValueError, "Channel %d is not in dataOut.channelList"
266 raise ValueError, "Channel %d is not in dataOut.channelList"
267 channelIndexList.append(dataOut.channelList.index(channel))
267 channelIndexList.append(dataOut.channelList.index(channel))
268
268
269 if timerange != None:
269 if timerange != None:
270 self.timerange = timerange
270 self.timerange = timerange
271
271
272 tmin = None
272 tmin = None
273 tmax = None
273 tmax = None
274 factor = dataOut.normFactor
274 factor = dataOut.normFactor
275 x = dataOut.getTimeRange()
275 x = dataOut.getTimeRange()
276 y = dataOut.getHeiRange()
276 y = dataOut.getHeiRange()
277
277
278 z = dataOut.data_spc[channelIndexList,:,:]/factor
278 z = dataOut.data_spc[channelIndexList,:,:]/factor
279 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
279 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
280 avg = numpy.average(z, axis=1)
280 avg = numpy.average(z, axis=1)
281
281
282 avgdB = 10.*numpy.log10(avg)
282 avgdB = 10.*numpy.log10(avg)
283
283
284
284
285 thisDatetime = dataOut.datatime
285 thisDatetime = dataOut.datatime
286 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
286 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
287 xlabel = ""
287 xlabel = ""
288 ylabel = "Range (Km)"
288 ylabel = "Range (Km)"
289
289
290 if not self.__isConfig:
290 if not self.__isConfig:
291
291
292 nplots = len(channelIndexList)
292 nplots = len(channelIndexList)
293
293
294 self.setup(idfigure=idfigure,
294 self.setup(idfigure=idfigure,
295 nplots=nplots,
295 nplots=nplots,
296 wintitle=wintitle,
296 wintitle=wintitle,
297 showprofile=showprofile)
297 showprofile=showprofile)
298
298
299 tmin, tmax = self.getTimeLim(x, xmin, xmax)
299 tmin, tmax = self.getTimeLim(x, xmin, xmax)
300 if ymin == None: ymin = numpy.nanmin(y)
300 if ymin == None: ymin = numpy.nanmin(y)
301 if ymax == None: ymax = numpy.nanmax(y)
301 if ymax == None: ymax = numpy.nanmax(y)
302 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
302 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
303 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
303 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
304
304
305 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
305 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
306 self.__isConfig = True
306 self.__isConfig = True
307
307
308
308
309 self.setWinTitle(title)
309 self.setWinTitle(title)
310
310
311 for i in range(self.nplots):
311 for i in range(self.nplots):
312 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
312 title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
313 axes = self.axesList[i*self.__nsubplots]
313 axes = self.axesList[i*self.__nsubplots]
314 zdB = avgdB[i].reshape((1,-1))
314 zdB = avgdB[i].reshape((1,-1))
315 axes.pcolorbuffer(x, y, zdB,
315 axes.pcolorbuffer(x, y, zdB,
316 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
316 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
317 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
317 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
318 ticksize=9, cblabel='', cbsize="1%")
318 ticksize=9, cblabel='', cbsize="1%")
319
319
320 if self.__showprofile:
320 if self.__showprofile:
321 axes = self.axesList[i*self.__nsubplots +1]
321 axes = self.axesList[i*self.__nsubplots +1]
322 axes.pline(avgdB[i], y,
322 axes.pline(avgdB[i], y,
323 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
323 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
324 xlabel='dB', ylabel='', title='',
324 xlabel='dB', ylabel='', title='',
325 ytick_visible=False,
325 ytick_visible=False,
326 grid='x')
326 grid='x')
327
327
328 self.draw()
328 self.draw()
329
329
330 if save:
330 if save:
331
331
332 if figfile == None:
332 if figfile == None:
333 figfile = self.getFilename(name = self.name)
333 figfile = self.getFilename(name = self.name)
334
334
335 self.saveFigure(figpath, figfile)
335 self.saveFigure(figpath, figfile)
336
336
337 self.counterftp += 1
337 self.counterftp += 1
338 if (ftp and (self.counterftp==ftpratio)):
338 if (ftp and (self.counterftp==ftpratio)):
339 figfilename = os.path.join(figpath,figfile)
339 figfilename = os.path.join(figpath,figfile)
340 self.sendByFTP(figfilename)
340 self.sendByFTP(figfilename)
341 self.counterftp = 0
341 self.counterftp = 0
342
342
343 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
343 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
344 self.__isConfig = False
344 self.__isConfig = False
345
345
346 class SpectraPlot(Figure):
346 class SpectraPlot(Figure):
347
347
348 __isConfig = None
348 __isConfig = None
349 __nsubplots = None
349 __nsubplots = None
350
350
351 WIDTHPROF = None
351 WIDTHPROF = None
352 HEIGHTPROF = None
352 HEIGHTPROF = None
353 PREFIX = 'spc'
353 PREFIX = 'spc'
354
354
355 def __init__(self):
355 def __init__(self):
356
356
357 self.__isConfig = False
357 self.__isConfig = False
358 self.__nsubplots = 1
358 self.__nsubplots = 1
359
359
360 self.WIDTH = 230
360 self.WIDTH = 230
361 self.HEIGHT = 250
361 self.HEIGHT = 250
362 self.WIDTHPROF = 120
362 self.WIDTHPROF = 120
363 self.HEIGHTPROF = 0
363 self.HEIGHTPROF = 0
364
364
365 def getSubplots(self):
365 def getSubplots(self):
366
366
367 ncol = int(numpy.sqrt(self.nplots)+0.9)
367 ncol = int(numpy.sqrt(self.nplots)+0.9)
368 nrow = int(self.nplots*1./ncol + 0.9)
368 nrow = int(self.nplots*1./ncol + 0.9)
369
369
370 return nrow, ncol
370 return nrow, ncol
371
371
372 def setup(self, idfigure, nplots, wintitle, showprofile=True):
372 def setup(self, idfigure, nplots, wintitle, showprofile=True):
373
373
374 self.__showprofile = showprofile
374 self.__showprofile = showprofile
375 self.nplots = nplots
375 self.nplots = nplots
376
376
377 ncolspan = 1
377 ncolspan = 1
378 colspan = 1
378 colspan = 1
379 if showprofile:
379 if showprofile:
380 ncolspan = 3
380 ncolspan = 3
381 colspan = 2
381 colspan = 2
382 self.__nsubplots = 2
382 self.__nsubplots = 2
383
383
384 self.createFigure(idfigure = idfigure,
384 self.createFigure(idfigure = idfigure,
385 wintitle = wintitle,
385 wintitle = wintitle,
386 widthplot = self.WIDTH + self.WIDTHPROF,
386 widthplot = self.WIDTH + self.WIDTHPROF,
387 heightplot = self.HEIGHT + self.HEIGHTPROF)
387 heightplot = self.HEIGHT + self.HEIGHTPROF)
388
388
389 nrow, ncol = self.getSubplots()
389 nrow, ncol = self.getSubplots()
390
390
391 counter = 0
391 counter = 0
392 for y in range(nrow):
392 for y in range(nrow):
393 for x in range(ncol):
393 for x in range(ncol):
394
394
395 if counter >= self.nplots:
395 if counter >= self.nplots:
396 break
396 break
397
397
398 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
398 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
399
399
400 if showprofile:
400 if showprofile:
401 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
401 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
402
402
403 counter += 1
403 counter += 1
404
404
405 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
405 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
406 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
406 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
407 save=False, figpath='./', figfile=None):
407 save=False, figpath='./', figfile=None):
408
408
409 """
409 """
410
410
411 Input:
411 Input:
412 dataOut :
412 dataOut :
413 idfigure :
413 idfigure :
414 wintitle :
414 wintitle :
415 channelList :
415 channelList :
416 showProfile :
416 showProfile :
417 xmin : None,
417 xmin : None,
418 xmax : None,
418 xmax : None,
419 ymin : None,
419 ymin : None,
420 ymax : None,
420 ymax : None,
421 zmin : None,
421 zmin : None,
422 zmax : None
422 zmax : None
423 """
423 """
424
424
425 if channelList == None:
425 if channelList == None:
426 channelIndexList = dataOut.channelIndexList
426 channelIndexList = dataOut.channelIndexList
427 else:
427 else:
428 channelIndexList = []
428 channelIndexList = []
429 for channel in channelList:
429 for channel in channelList:
430 if channel not in dataOut.channelList:
430 if channel not in dataOut.channelList:
431 raise ValueError, "Channel %d is not in dataOut.channelList"
431 raise ValueError, "Channel %d is not in dataOut.channelList"
432 channelIndexList.append(dataOut.channelList.index(channel))
432 channelIndexList.append(dataOut.channelList.index(channel))
433 factor = dataOut.normFactor
433 factor = dataOut.normFactor
434 x = dataOut.getVelRange(1)
434 x = dataOut.getVelRange(1)
435 y = dataOut.getHeiRange()
435 y = dataOut.getHeiRange()
436
436
437 z = dataOut.data_spc[channelIndexList,:,:]/factor
437 z = dataOut.data_spc[channelIndexList,:,:]/factor
438 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
438 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
439 avg = numpy.average(z, axis=1)
439 avg = numpy.average(z, axis=1)
440 noise = dataOut.getNoise()/factor
440 noise = dataOut.getNoise()/factor
441
441
442 zdB = 10*numpy.log10(z)
442 zdB = 10*numpy.log10(z)
443 avgdB = 10*numpy.log10(avg)
443 avgdB = 10*numpy.log10(avg)
444 noisedB = 10*numpy.log10(noise)
444 noisedB = 10*numpy.log10(noise)
445
445
446 thisDatetime = dataOut.datatime
446 thisDatetime = dataOut.datatime
447 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
447 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
448 xlabel = "Velocity (m/s)"
448 xlabel = "Velocity (m/s)"
449 ylabel = "Range (Km)"
449 ylabel = "Range (Km)"
450
450
451 if not self.__isConfig:
451 if not self.__isConfig:
452
452
453 nplots = len(channelIndexList)
453 nplots = len(channelIndexList)
454
454
455 self.setup(idfigure=idfigure,
455 self.setup(idfigure=idfigure,
456 nplots=nplots,
456 nplots=nplots,
457 wintitle=wintitle,
457 wintitle=wintitle,
458 showprofile=showprofile)
458 showprofile=showprofile)
459
459
460 if xmin == None: xmin = numpy.nanmin(x)
460 if xmin == None: xmin = numpy.nanmin(x)
461 if xmax == None: xmax = numpy.nanmax(x)
461 if xmax == None: xmax = numpy.nanmax(x)
462 if ymin == None: ymin = numpy.nanmin(y)
462 if ymin == None: ymin = numpy.nanmin(y)
463 if ymax == None: ymax = numpy.nanmax(y)
463 if ymax == None: ymax = numpy.nanmax(y)
464 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
464 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
465 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
465 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
466
466
467 self.__isConfig = True
467 self.__isConfig = True
468
468
469 self.setWinTitle(title)
469 self.setWinTitle(title)
470
470
471 for i in range(self.nplots):
471 for i in range(self.nplots):
472 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
472 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i])
473 axes = self.axesList[i*self.__nsubplots]
473 axes = self.axesList[i*self.__nsubplots]
474 axes.pcolor(x, y, zdB[i,:,:],
474 axes.pcolor(x, y, zdB[i,:,:],
475 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
475 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
476 xlabel=xlabel, ylabel=ylabel, title=title,
476 xlabel=xlabel, ylabel=ylabel, title=title,
477 ticksize=9, cblabel='')
477 ticksize=9, cblabel='')
478
478
479 if self.__showprofile:
479 if self.__showprofile:
480 axes = self.axesList[i*self.__nsubplots +1]
480 axes = self.axesList[i*self.__nsubplots +1]
481 axes.pline(avgdB[i], y,
481 axes.pline(avgdB[i], y,
482 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
482 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
483 xlabel='dB', ylabel='', title='',
483 xlabel='dB', ylabel='', title='',
484 ytick_visible=False,
484 ytick_visible=False,
485 grid='x')
485 grid='x')
486
486
487 noiseline = numpy.repeat(noisedB[i], len(y))
487 noiseline = numpy.repeat(noisedB[i], len(y))
488 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
488 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
489
489
490 self.draw()
490 self.draw()
491
491
492 if save:
492 if save:
493 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
493 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
494 if figfile == None:
494 if figfile == None:
495 figfile = self.getFilename(name = date)
495 figfile = self.getFilename(name = date)
496
496
497 self.saveFigure(figpath, figfile)
497 self.saveFigure(figpath, figfile)
498
498
499 class Scope(Figure):
499 class Scope(Figure):
500
500
501 __isConfig = None
501 __isConfig = None
502
502
503 def __init__(self):
503 def __init__(self):
504
504
505 self.__isConfig = False
505 self.__isConfig = False
506 self.WIDTH = 600
506 self.WIDTH = 600
507 self.HEIGHT = 200
507 self.HEIGHT = 200
508
508
509 def getSubplots(self):
509 def getSubplots(self):
510
510
511 nrow = self.nplots
511 nrow = self.nplots
512 ncol = 3
512 ncol = 3
513 return nrow, ncol
513 return nrow, ncol
514
514
515 def setup(self, idfigure, nplots, wintitle):
515 def setup(self, idfigure, nplots, wintitle):
516
516
517 self.nplots = nplots
517 self.nplots = nplots
518
518
519 self.createFigure(idfigure, wintitle)
519 self.createFigure(idfigure, wintitle)
520
520
521 nrow,ncol = self.getSubplots()
521 nrow,ncol = self.getSubplots()
522 colspan = 3
522 colspan = 3
523 rowspan = 1
523 rowspan = 1
524
524
525 for i in range(nplots):
525 for i in range(nplots):
526 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
526 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
527
527
528
528
529
529
530 def run(self, dataOut, idfigure, wintitle="", channelList=None,
530 def run(self, dataOut, idfigure, wintitle="", channelList=None,
531 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
531 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
532 figpath='./', figfile=None):
532 figpath='./', figfile=None):
533
533
534 """
534 """
535
535
536 Input:
536 Input:
537 dataOut :
537 dataOut :
538 idfigure :
538 idfigure :
539 wintitle :
539 wintitle :
540 channelList :
540 channelList :
541 xmin : None,
541 xmin : None,
542 xmax : None,
542 xmax : None,
543 ymin : None,
543 ymin : None,
544 ymax : None,
544 ymax : None,
545 """
545 """
546
546
547 if channelList == None:
547 if channelList == None:
548 channelIndexList = dataOut.channelIndexList
548 channelIndexList = dataOut.channelIndexList
549 else:
549 else:
550 channelIndexList = []
550 channelIndexList = []
551 for channel in channelList:
551 for channel in channelList:
552 if channel not in dataOut.channelList:
552 if channel not in dataOut.channelList:
553 raise ValueError, "Channel %d is not in dataOut.channelList"
553 raise ValueError, "Channel %d is not in dataOut.channelList"
554 channelIndexList.append(dataOut.channelList.index(channel))
554 channelIndexList.append(dataOut.channelList.index(channel))
555
555
556 x = dataOut.heightList
556 x = dataOut.heightList
557 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
557 y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
558 y = y.real
558 y = y.real
559
559
560 thisDatetime = dataOut.datatime
560 thisDatetime = dataOut.datatime
561 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
561 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
562 xlabel = "Range (Km)"
562 xlabel = "Range (Km)"
563 ylabel = "Intensity"
563 ylabel = "Intensity"
564
564
565 if not self.__isConfig:
565 if not self.__isConfig:
566 nplots = len(channelIndexList)
566 nplots = len(channelIndexList)
567
567
568 self.setup(idfigure=idfigure,
568 self.setup(idfigure=idfigure,
569 nplots=nplots,
569 nplots=nplots,
570 wintitle=wintitle)
570 wintitle=wintitle)
571
571
572 if xmin == None: xmin = numpy.nanmin(x)
572 if xmin == None: xmin = numpy.nanmin(x)
573 if xmax == None: xmax = numpy.nanmax(x)
573 if xmax == None: xmax = numpy.nanmax(x)
574 if ymin == None: ymin = numpy.nanmin(y)
574 if ymin == None: ymin = numpy.nanmin(y)
575 if ymax == None: ymax = numpy.nanmax(y)
575 if ymax == None: ymax = numpy.nanmax(y)
576
576
577 self.__isConfig = True
577 self.__isConfig = True
578
578
579 self.setWinTitle(title)
579 self.setWinTitle(title)
580
580
581 for i in range(len(self.axesList)):
581 for i in range(len(self.axesList)):
582 title = "Channel %d" %(i)
582 title = "Channel %d" %(i)
583 axes = self.axesList[i]
583 axes = self.axesList[i]
584 ychannel = y[i,:]
584 ychannel = y[i,:]
585 axes.pline(x, ychannel,
585 axes.pline(x, ychannel,
586 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
586 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
587 xlabel=xlabel, ylabel=ylabel, title=title)
587 xlabel=xlabel, ylabel=ylabel, title=title)
588
588
589 self.draw()
589 self.draw()
590
590
591 if save:
591 if save:
592 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
592 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
593 if figfile == None:
593 if figfile == None:
594 figfile = self.getFilename(name = date)
594 figfile = self.getFilename(name = date)
595
595
596 self.saveFigure(figpath, figfile)
596 self.saveFigure(figpath, figfile)
597
597
598 class ProfilePlot(Figure):
598 class ProfilePlot(Figure):
599 __isConfig = None
599 __isConfig = None
600 __nsubplots = None
600 __nsubplots = None
601
601
602 WIDTHPROF = None
602 WIDTHPROF = None
603 HEIGHTPROF = None
603 HEIGHTPROF = None
604 PREFIX = 'spcprofile'
604 PREFIX = 'spcprofile'
605
605
606 def __init__(self):
606 def __init__(self):
607 self.__isConfig = False
607 self.__isConfig = False
608 self.__nsubplots = 1
608 self.__nsubplots = 1
609
609
610 self.WIDTH = 300
610 self.WIDTH = 300
611 self.HEIGHT = 500
611 self.HEIGHT = 500
612
612
613 def getSubplots(self):
613 def getSubplots(self):
614 ncol = 1
614 ncol = 1
615 nrow = 1
615 nrow = 1
616
616
617 return nrow, ncol
617 return nrow, ncol
618
618
619 def setup(self, idfigure, nplots, wintitle):
619 def setup(self, idfigure, nplots, wintitle):
620
620
621 self.nplots = nplots
621 self.nplots = nplots
622
622
623 ncolspan = 1
623 ncolspan = 1
624 colspan = 1
624 colspan = 1
625
625
626 self.createFigure(idfigure = idfigure,
626 self.createFigure(idfigure = idfigure,
627 wintitle = wintitle,
627 wintitle = wintitle,
628 widthplot = self.WIDTH,
628 widthplot = self.WIDTH,
629 heightplot = self.HEIGHT)
629 heightplot = self.HEIGHT)
630
630
631 nrow, ncol = self.getSubplots()
631 nrow, ncol = self.getSubplots()
632
632
633 counter = 0
633 counter = 0
634 for y in range(nrow):
634 for y in range(nrow):
635 for x in range(ncol):
635 for x in range(ncol):
636 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
636 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
637
637
638 def run(self, dataOut, idfigure, wintitle="", channelList=None,
638 def run(self, dataOut, idfigure, wintitle="", channelList=None,
639 xmin=None, xmax=None, ymin=None, ymax=None,
639 xmin=None, xmax=None, ymin=None, ymax=None,
640 save=False, figpath='./', figfile=None):
640 save=False, figpath='./', figfile=None):
641
641
642 if channelList == None:
642 if channelList == None:
643 channelIndexList = dataOut.channelIndexList
643 channelIndexList = dataOut.channelIndexList
644 channelList = dataOut.channelList
644 channelList = dataOut.channelList
645 else:
645 else:
646 channelIndexList = []
646 channelIndexList = []
647 for channel in channelList:
647 for channel in channelList:
648 if channel not in dataOut.channelList:
648 if channel not in dataOut.channelList:
649 raise ValueError, "Channel %d is not in dataOut.channelList"
649 raise ValueError, "Channel %d is not in dataOut.channelList"
650 channelIndexList.append(dataOut.channelList.index(channel))
650 channelIndexList.append(dataOut.channelList.index(channel))
651
651
652 factor = dataOut.normFactor
652 factor = dataOut.normFactor
653 y = dataOut.getHeiRange()
653 y = dataOut.getHeiRange()
654 x = dataOut.data_spc[channelIndexList,:,:]/factor
654 x = dataOut.data_spc[channelIndexList,:,:]/factor
655 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
655 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
656 avg = numpy.average(x, axis=1)
656 avg = numpy.average(x, axis=1)
657
657
658 avgdB = 10*numpy.log10(avg)
658 avgdB = 10*numpy.log10(avg)
659
659
660 thisDatetime = dataOut.datatime
660 thisDatetime = dataOut.datatime
661 title = "Power Profile"
661 title = "Power Profile"
662 xlabel = "dB"
662 xlabel = "dB"
663 ylabel = "Range (Km)"
663 ylabel = "Range (Km)"
664
664
665 if not self.__isConfig:
665 if not self.__isConfig:
666
666
667 nplots = 1
667 nplots = 1
668
668
669 self.setup(idfigure=idfigure,
669 self.setup(idfigure=idfigure,
670 nplots=nplots,
670 nplots=nplots,
671 wintitle=wintitle)
671 wintitle=wintitle)
672
672
673 if ymin == None: ymin = numpy.nanmin(y)
673 if ymin == None: ymin = numpy.nanmin(y)
674 if ymax == None: ymax = numpy.nanmax(y)
674 if ymax == None: ymax = numpy.nanmax(y)
675 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
675 if xmin == None: xmin = numpy.nanmin(avgdB)*0.9
676 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
676 if xmax == None: xmax = numpy.nanmax(avgdB)*0.9
677
677
678 self.__isConfig = True
678 self.__isConfig = True
679
679
680 self.setWinTitle(title)
680 self.setWinTitle(title)
681
681
682
682
683 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
683 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
684 axes = self.axesList[0]
684 axes = self.axesList[0]
685
685
686 legendlabels = ["channel %d"%x for x in channelList]
686 legendlabels = ["channel %d"%x for x in channelList]
687 axes.pmultiline(avgdB, y,
687 axes.pmultiline(avgdB, y,
688 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
688 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
689 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
689 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
690 ytick_visible=True, nxticks=5,
690 ytick_visible=True, nxticks=5,
691 grid='x')
691 grid='x')
692
692
693 self.draw()
693 self.draw()
694
694
695 if save:
695 if save:
696 date = thisDatetime.strftime("%Y%m%d")
696 date = thisDatetime.strftime("%Y%m%d")
697 if figfile == None:
697 if figfile == None:
698 figfile = self.getFilename(name = date)
698 figfile = self.getFilename(name = date)
699
699
700 self.saveFigure(figpath, figfile)
700 self.saveFigure(figpath, figfile)
701
701
702 class CoherenceMap(Figure):
702 class CoherenceMap(Figure):
703 __isConfig = None
703 __isConfig = None
704 __nsubplots = None
704 __nsubplots = None
705
705
706 WIDTHPROF = None
706 WIDTHPROF = None
707 HEIGHTPROF = None
707 HEIGHTPROF = None
708 PREFIX = 'cmap'
708 PREFIX = 'cmap'
709
709
710 def __init__(self):
710 def __init__(self):
711 self.timerange = 2*60*60
711 self.timerange = 2*60*60
712 self.__isConfig = False
712 self.__isConfig = False
713 self.__nsubplots = 1
713 self.__nsubplots = 1
714
714
715 self.WIDTH = 800
715 self.WIDTH = 800
716 self.HEIGHT = 150
716 self.HEIGHT = 150
717 self.WIDTHPROF = 120
717 self.WIDTHPROF = 120
718 self.HEIGHTPROF = 0
718 self.HEIGHTPROF = 0
719 self.counterftp = 0
719 self.counterftp = 0
720
720
721 def getSubplots(self):
721 def getSubplots(self):
722 ncol = 1
722 ncol = 1
723 nrow = self.nplots*2
723 nrow = self.nplots*2
724
724
725 return nrow, ncol
725 return nrow, ncol
726
726
727 def setup(self, idfigure, nplots, wintitle, showprofile=True):
727 def setup(self, idfigure, nplots, wintitle, showprofile=True):
728 self.__showprofile = showprofile
728 self.__showprofile = showprofile
729 self.nplots = nplots
729 self.nplots = nplots
730
730
731 ncolspan = 1
731 ncolspan = 1
732 colspan = 1
732 colspan = 1
733 if showprofile:
733 if showprofile:
734 ncolspan = 7
734 ncolspan = 7
735 colspan = 6
735 colspan = 6
736 self.__nsubplots = 2
736 self.__nsubplots = 2
737
737
738 self.createFigure(idfigure = idfigure,
738 self.createFigure(idfigure = idfigure,
739 wintitle = wintitle,
739 wintitle = wintitle,
740 widthplot = self.WIDTH + self.WIDTHPROF,
740 widthplot = self.WIDTH + self.WIDTHPROF,
741 heightplot = self.HEIGHT + self.HEIGHTPROF)
741 heightplot = self.HEIGHT + self.HEIGHTPROF)
742
742
743 nrow, ncol = self.getSubplots()
743 nrow, ncol = self.getSubplots()
744
744
745 for y in range(nrow):
745 for y in range(nrow):
746 for x in range(ncol):
746 for x in range(ncol):
747
747
748 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
748 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
749
749
750 if showprofile:
750 if showprofile:
751 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
751 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
752
752
753 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
753 def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True',
754 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
754 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
755 timerange=None,
755 timerange=None,
756 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
756 save=False, figpath='./', figfile=None, ftp=False, ftpratio=1,
757 coherence_cmap='jet', phase_cmap='RdBu_r'):
757 coherence_cmap='jet', phase_cmap='RdBu_r'):
758
758
759 if pairsList == None:
759 if pairsList == None:
760 pairsIndexList = dataOut.pairsIndexList
760 pairsIndexList = dataOut.pairsIndexList
761 else:
761 else:
762 pairsIndexList = []
762 pairsIndexList = []
763 for pair in pairsList:
763 for pair in pairsList:
764 if pair not in dataOut.pairsList:
764 if pair not in dataOut.pairsList:
765 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
765 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
766 pairsIndexList.append(dataOut.pairsList.index(pair))
766 pairsIndexList.append(dataOut.pairsList.index(pair))
767
767
768 if timerange != None:
768 if timerange != None:
769 self.timerange = timerange
769 self.timerange = timerange
770
770
771 if pairsIndexList == []:
771 if pairsIndexList == []:
772 return
772 return
773
773
774 if len(pairsIndexList) > 4:
774 if len(pairsIndexList) > 4:
775 pairsIndexList = pairsIndexList[0:4]
775 pairsIndexList = pairsIndexList[0:4]
776
776
777 tmin = None
777 tmin = None
778 tmax = None
778 tmax = None
779 x = dataOut.getTimeRange()
779 x = dataOut.getTimeRange()
780 y = dataOut.getHeiRange()
780 y = dataOut.getHeiRange()
781
781
782 thisDatetime = dataOut.datatime
782 thisDatetime = dataOut.datatime
783 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
783 title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y"))
784 xlabel = ""
784 xlabel = ""
785 ylabel = "Range (Km)"
785 ylabel = "Range (Km)"
786
786
787 if not self.__isConfig:
787 if not self.__isConfig:
788 nplots = len(pairsIndexList)
788 nplots = len(pairsIndexList)
789 self.setup(idfigure=idfigure,
789 self.setup(idfigure=idfigure,
790 nplots=nplots,
790 nplots=nplots,
791 wintitle=wintitle,
791 wintitle=wintitle,
792 showprofile=showprofile)
792 showprofile=showprofile)
793
793
794 tmin, tmax = self.getTimeLim(x, xmin, xmax)
794 tmin, tmax = self.getTimeLim(x, xmin, xmax)
795 if ymin == None: ymin = numpy.nanmin(y)
795 if ymin == None: ymin = numpy.nanmin(y)
796 if ymax == None: ymax = numpy.nanmax(y)
796 if ymax == None: ymax = numpy.nanmax(y)
797
797
798 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
798 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
799
799
800 self.__isConfig = True
800 self.__isConfig = True
801
801
802 self.setWinTitle(title)
802 self.setWinTitle(title)
803
803
804 for i in range(self.nplots):
804 for i in range(self.nplots):
805
805
806 pair = dataOut.pairsList[pairsIndexList[i]]
806 pair = dataOut.pairsList[pairsIndexList[i]]
807 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
807 coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:])
808 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
808 avgcoherenceComplex = numpy.average(coherenceComplex, axis=0)
809 coherence = numpy.abs(avgcoherenceComplex)
809 coherence = numpy.abs(avgcoherenceComplex)
810 # coherence = numpy.abs(coherenceComplex)
810 # coherence = numpy.abs(coherenceComplex)
811 # avg = numpy.average(coherence, axis=0)
811 # avg = numpy.average(coherence, axis=0)
812
812
813 z = coherence.reshape((1,-1))
813 z = coherence.reshape((1,-1))
814
814
815 counter = 0
815 counter = 0
816
816
817 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
817 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
818 axes = self.axesList[i*self.__nsubplots*2]
818 axes = self.axesList[i*self.__nsubplots*2]
819 axes.pcolorbuffer(x, y, z,
819 axes.pcolorbuffer(x, y, z,
820 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
820 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1,
821 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
821 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
822 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
822 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
823
823
824 if self.__showprofile:
824 if self.__showprofile:
825 counter += 1
825 counter += 1
826 axes = self.axesList[i*self.__nsubplots*2 + counter]
826 axes = self.axesList[i*self.__nsubplots*2 + counter]
827 axes.pline(coherence, y,
827 axes.pline(coherence, y,
828 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
828 xmin=0, xmax=1, ymin=ymin, ymax=ymax,
829 xlabel='', ylabel='', title='', ticksize=7,
829 xlabel='', ylabel='', title='', ticksize=7,
830 ytick_visible=False, nxticks=5,
830 ytick_visible=False, nxticks=5,
831 grid='x')
831 grid='x')
832
832
833 counter += 1
833 counter += 1
834 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
834 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
835 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
835 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
836 # avg = numpy.average(phase, axis=0)
836 # avg = numpy.average(phase, axis=0)
837 z = phase.reshape((1,-1))
837 z = phase.reshape((1,-1))
838
838
839 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
839 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
840 axes = self.axesList[i*self.__nsubplots*2 + counter]
840 axes = self.axesList[i*self.__nsubplots*2 + counter]
841 axes.pcolorbuffer(x, y, z,
841 axes.pcolorbuffer(x, y, z,
842 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
842 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
843 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
843 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
844 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
844 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
845
845
846 if self.__showprofile:
846 if self.__showprofile:
847 counter += 1
847 counter += 1
848 axes = self.axesList[i*self.__nsubplots*2 + counter]
848 axes = self.axesList[i*self.__nsubplots*2 + counter]
849 axes.pline(phase, y,
849 axes.pline(phase, y,
850 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
850 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
851 xlabel='', ylabel='', title='', ticksize=7,
851 xlabel='', ylabel='', title='', ticksize=7,
852 ytick_visible=False, nxticks=4,
852 ytick_visible=False, nxticks=4,
853 grid='x')
853 grid='x')
854
854
855 self.draw()
855 self.draw()
856
856
857 if save:
857 if save:
858
858
859 if figfile == None:
859 if figfile == None:
860 figfile = self.getFilename(name = self.name)
860 figfile = self.getFilename(name = self.name)
861
861
862 self.saveFigure(figpath, figfile)
862 self.saveFigure(figpath, figfile)
863
863
864 self.counterftp += 1
864 self.counterftp += 1
865 if (ftp and (self.counterftp==ftpratio)):
865 if (ftp and (self.counterftp==ftpratio)):
866 figfilename = os.path.join(figpath,figfile)
866 figfilename = os.path.join(figpath,figfile)
867 self.sendByFTP(figfilename)
867 self.sendByFTP(figfilename)
868 self.counterftp = 0
868 self.counterftp = 0
869
869
870 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
870 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
871 self.__isConfig = False
871 self.__isConfig = False
872
872
873 class RTIfromNoise(Figure):
873 class RTIfromNoise(Figure):
874
874
875 __isConfig = None
875 __isConfig = None
876 __nsubplots = None
876 __nsubplots = None
877
877
878 PREFIX = 'rtinoise'
878 PREFIX = 'rtinoise'
879
879
880 def __init__(self):
880 def __init__(self):
881
881
882 self.timerange = 24*60*60
882 self.timerange = 24*60*60
883 self.__isConfig = False
883 self.__isConfig = False
884 self.__nsubplots = 1
884 self.__nsubplots = 1
885
885
886 self.WIDTH = 820
886 self.WIDTH = 820
887 self.HEIGHT = 200
887 self.HEIGHT = 200
888 self.WIDTHPROF = 120
888 self.WIDTHPROF = 120
889 self.HEIGHTPROF = 0
889 self.HEIGHTPROF = 0
890 self.xdata = None
890 self.xdata = None
891 self.ydata = None
891 self.ydata = None
892
892
893 def getSubplots(self):
893 def getSubplots(self):
894
894
895 ncol = 1
895 ncol = 1
896 nrow = 1
896 nrow = 1
897
897
898 return nrow, ncol
898 return nrow, ncol
899
899
900 def setup(self, idfigure, nplots, wintitle, showprofile=True):
900 def setup(self, idfigure, nplots, wintitle, showprofile=True):
901
901
902 self.__showprofile = showprofile
902 self.__showprofile = showprofile
903 self.nplots = nplots
903 self.nplots = nplots
904
904
905 ncolspan = 7
905 ncolspan = 7
906 colspan = 6
906 colspan = 6
907 self.__nsubplots = 2
907 self.__nsubplots = 2
908
908
909 self.createFigure(idfigure = idfigure,
909 self.createFigure(idfigure = idfigure,
910 wintitle = wintitle,
910 wintitle = wintitle,
911 widthplot = self.WIDTH+self.WIDTHPROF,
911 widthplot = self.WIDTH+self.WIDTHPROF,
912 heightplot = self.HEIGHT+self.HEIGHTPROF)
912 heightplot = self.HEIGHT+self.HEIGHTPROF)
913
913
914 nrow, ncol = self.getSubplots()
914 nrow, ncol = self.getSubplots()
915
915
916 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
916 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
917
917
918
918
919 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
919 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
920 xmin=None, xmax=None, ymin=None, ymax=None,
920 xmin=None, xmax=None, ymin=None, ymax=None,
921 timerange=None,
921 timerange=None,
922 save=False, figpath='./', figfile=None):
922 save=False, figpath='./', figfile=None):
923
923
924 if channelList == None:
924 if channelList == None:
925 channelIndexList = dataOut.channelIndexList
925 channelIndexList = dataOut.channelIndexList
926 channelList = dataOut.channelList
926 channelList = dataOut.channelList
927 else:
927 else:
928 channelIndexList = []
928 channelIndexList = []
929 for channel in channelList:
929 for channel in channelList:
930 if channel not in dataOut.channelList:
930 if channel not in dataOut.channelList:
931 raise ValueError, "Channel %d is not in dataOut.channelList"
931 raise ValueError, "Channel %d is not in dataOut.channelList"
932 channelIndexList.append(dataOut.channelList.index(channel))
932 channelIndexList.append(dataOut.channelList.index(channel))
933
933
934 if timerange != None:
934 if timerange != None:
935 self.timerange = timerange
935 self.timerange = timerange
936
936
937 tmin = None
937 tmin = None
938 tmax = None
938 tmax = None
939 x = dataOut.getTimeRange()
939 x = dataOut.getTimeRange()
940 y = dataOut.getHeiRange()
940 y = dataOut.getHeiRange()
941 factor = dataOut.normFactor
941 factor = dataOut.normFactor
942 noise = dataOut.getNoise()/factor
942 noise = dataOut.getNoise()/factor
943 noisedB = 10*numpy.log10(noise)
943 noisedB = 10*numpy.log10(noise)
944
944
945 thisDatetime = dataOut.datatime
945 thisDatetime = dataOut.datatime
946 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
946 title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y"))
947 xlabel = ""
947 xlabel = ""
948 ylabel = "Range (Km)"
948 ylabel = "Range (Km)"
949
949
950 if not self.__isConfig:
950 if not self.__isConfig:
951
951
952 nplots = 1
952 nplots = 1
953
953
954 self.setup(idfigure=idfigure,
954 self.setup(idfigure=idfigure,
955 nplots=nplots,
955 nplots=nplots,
956 wintitle=wintitle,
956 wintitle=wintitle,
957 showprofile=showprofile)
957 showprofile=showprofile)
958
958
959 tmin, tmax = self.getTimeLim(x, xmin, xmax)
959 tmin, tmax = self.getTimeLim(x, xmin, xmax)
960 if ymin == None: ymin = numpy.nanmin(noisedB)
960 if ymin == None: ymin = numpy.nanmin(noisedB)
961 if ymax == None: ymax = numpy.nanmax(noisedB)
961 if ymax == None: ymax = numpy.nanmax(noisedB)
962
962
963 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
963 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
964 self.__isConfig = True
964 self.__isConfig = True
965
965
966 self.xdata = numpy.array([])
966 self.xdata = numpy.array([])
967 self.ydata = numpy.array([])
967 self.ydata = numpy.array([])
968
968
969 self.setWinTitle(title)
969 self.setWinTitle(title)
970
970
971
971
972 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
972 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
973
973
974 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
974 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
975 axes = self.axesList[0]
975 axes = self.axesList[0]
976
976
977 self.xdata = numpy.hstack((self.xdata, x[0:1]))
977 self.xdata = numpy.hstack((self.xdata, x[0:1]))
978
978
979 if len(self.ydata)==0:
979 if len(self.ydata)==0:
980 self.ydata = noisedB[channelIndexList].reshape(-1,1)
980 self.ydata = noisedB[channelIndexList].reshape(-1,1)
981 else:
981 else:
982 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
982 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
983
983
984
984
985 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
985 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
986 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
986 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
987 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
987 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
988 XAxisAsTime=True
988 XAxisAsTime=True
989 )
989 )
990
990
991 self.draw()
991 self.draw()
992
992
993 if save:
993 if save:
994
994
995 if figfile == None:
995 if figfile == None:
996 figfile = self.getFilename(name = self.name)
996 figfile = self.getFilename(name = self.name)
997
997
998 self.saveFigure(figpath, figfile)
998 self.saveFigure(figpath, figfile)
999
999
1000 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1000 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1001 self.__isConfig = False
1001 self.__isConfig = False
1002 del self.xdata
1002 del self.xdata
1003 del self.ydata
1003 del self.ydata
1004
1004
1005
1006 class SpectraHeisScope(Figure):
1007
1008
1009 __isConfig = None
1010 __nsubplots = None
1011
1012 WIDTHPROF = None
1013 HEIGHTPROF = None
1014 PREFIX = 'spc'
1015
1016 def __init__(self):
1017
1018 self.__isConfig = False
1019 self.__nsubplots = 1
1020
1021 self.WIDTH = 230
1022 self.HEIGHT = 250
1023 self.WIDTHPROF = 120
1024 self.HEIGHTPROF = 0
1025
1026 def getSubplots(self):
1027
1028 ncol = int(numpy.sqrt(self.nplots)+0.9)
1029 nrow = int(self.nplots*1./ncol + 0.9)
1030
1031 return nrow, ncol
1032
1033 def setup(self, idfigure, nplots, wintitle):
1034
1035 showprofile = False
1036 self.__showprofile = showprofile
1037 self.nplots = nplots
1038
1039 ncolspan = 1
1040 colspan = 1
1041 if showprofile:
1042 ncolspan = 3
1043 colspan = 2
1044 self.__nsubplots = 2
1045
1046 self.createFigure(idfigure = idfigure,
1047 wintitle = wintitle,
1048 widthplot = self.WIDTH + self.WIDTHPROF,
1049 heightplot = self.HEIGHT + self.HEIGHTPROF)
1050
1051 nrow, ncol = self.getSubplots()
1052
1053 counter = 0
1054 for y in range(nrow):
1055 for x in range(ncol):
1056
1057 if counter >= self.nplots:
1058 break
1059
1060 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
1061
1062 if showprofile:
1063 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
1064
1065 counter += 1
1066
1067 # __isConfig = None
1068 # def __init__(self):
1069 #
1070 # self.__isConfig = False
1071 # self.WIDTH = 600
1072 # self.HEIGHT = 200
1073 #
1074 # def getSubplots(self):
1075 #
1076 # nrow = self.nplots
1077 # ncol = 3
1078 # return nrow, ncol
1079 #
1080 # def setup(self, idfigure, nplots, wintitle):
1081 #
1082 # self.nplots = nplots
1083 #
1084 # self.createFigure(idfigure, wintitle)
1085 #
1086 # nrow,ncol = self.getSubplots()
1087 # colspan = 3
1088 # rowspan = 1
1089 #
1090 # for i in range(nplots):
1091 # self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
1092
1093 def run(self, dataOut, idfigure, wintitle="", channelList=None,
1094 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
1095 figpath='./', figfile=None):
1096
1097 """
1098
1099 Input:
1100 dataOut :
1101 idfigure :
1102 wintitle :
1103 channelList :
1104 xmin : None,
1105 xmax : None,
1106 ymin : None,
1107 ymax : None,
1108 """
1109
1110 if channelList == None:
1111 channelIndexList = dataOut.channelIndexList
1112 else:
1113 channelIndexList = []
1114 for channel in channelList:
1115 if channel not in dataOut.channelList:
1116 raise ValueError, "Channel %d is not in dataOut.channelList"
1117 channelIndexList.append(dataOut.channelList.index(channel))
1118
1119 # x = dataOut.heightList
1120 c = 3E8
1121 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
1122 #deberia cambiar para el caso de 1Mhz y 100KHz
1123 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
1124 x= x/(10000.0)
1125 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
1126 # y = y.real
1127 datadB = 10.*numpy.log10(dataOut.data_spc)
1128 y = datadB
1129
1130 thisDatetime = dataOut.datatime
1131 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
1132 xlabel = "Frequency"
1133 ylabel = "Intensity (dB)"
1134
1135 if not self.__isConfig:
1136 nplots = len(channelIndexList)
1137
1138 self.setup(idfigure=idfigure,
1139 nplots=nplots,
1140 wintitle=wintitle)
1141
1142 if xmin == None: xmin = numpy.nanmin(x)
1143 if xmax == None: xmax = numpy.nanmax(x)
1144 if ymin == None: ymin = numpy.nanmin(y)
1145 if ymax == None: ymax = numpy.nanmax(y)
1146
1147 self.__isConfig = True
1148
1149 self.setWinTitle(title)
1150
1151 for i in range(len(self.axesList)):
1152 title = "Channel %d" %(i)
1153 axes = self.axesList[i]
1154 ychannel = y[i,:]
1155 axes.pline(x, ychannel,
1156 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
1157 xlabel=xlabel, ylabel=ylabel, title=title)
1158
1159 self.draw()
1160
1161 if save:
1162 date = thisDatetime.strftime("%Y%m%d_%H%M%S")
1163 if figfile == None:
1164 figfile = self.getFilename(name = date)
1165
1166 self.saveFigure(figpath, figfile)
1167
1168
1169 class RTIfromSpectraHeis(Figure):
1170
1171 __isConfig = None
1172 __nsubplots = None
1173
1174 PREFIX = 'rtinoise'
1175
1176 def __init__(self):
1177
1178 self.timerange = 24*60*60
1179 self.__isConfig = False
1180 self.__nsubplots = 1
1181
1182 self.WIDTH = 820
1183 self.HEIGHT = 200
1184 self.WIDTHPROF = 120
1185 self.HEIGHTPROF = 0
1186 self.xdata = None
1187 self.ydata = None
1188
1189 def getSubplots(self):
1190
1191 ncol = 1
1192 nrow = 1
1193
1194 return nrow, ncol
1195
1196 def setup(self, idfigure, nplots, wintitle, showprofile=True):
1197
1198 self.__showprofile = showprofile
1199 self.nplots = nplots
1200
1201 ncolspan = 7
1202 colspan = 6
1203 self.__nsubplots = 2
1204
1205 self.createFigure(idfigure = idfigure,
1206 wintitle = wintitle,
1207 widthplot = self.WIDTH+self.WIDTHPROF,
1208 heightplot = self.HEIGHT+self.HEIGHTPROF)
1209
1210 nrow, ncol = self.getSubplots()
1211
1212 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1213
1214
1215 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
1216 xmin=None, xmax=None, ymin=None, ymax=None,
1217 timerange=None,
1218 save=False, figpath='./', figfile=None):
1219
1220 if channelList == None:
1221 channelIndexList = dataOut.channelIndexList
1222 channelList = dataOut.channelList
1223 else:
1224 channelIndexList = []
1225 for channel in channelList:
1226 if channel not in dataOut.channelList:
1227 raise ValueError, "Channel %d is not in dataOut.channelList"
1228 channelIndexList.append(dataOut.channelList.index(channel))
1229
1230 if timerange != None:
1231 self.timerange = timerange
1232
1233 tmin = None
1234 tmax = None
1235 x = dataOut.getTimeRange()
1236 y = dataOut.getHeiRange()
1237
1238 factor = 1
1239 data = dataOut.data_spc/factor
1240 data = numpy.average(data,axis=1)
1241 datadB = 10*numpy.log10(data)
1242
1243 # factor = dataOut.normFactor
1244 # noise = dataOut.getNoise()/factor
1245 # noisedB = 10*numpy.log10(noise)
1246
1247 thisDatetime = dataOut.datatime
1248 title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
1249 xlabel = "Local Time"
1250 ylabel = "Intensity (dB)"
1251
1252 if not self.__isConfig:
1253
1254 nplots = 1
1255
1256 self.setup(idfigure=idfigure,
1257 nplots=nplots,
1258 wintitle=wintitle,
1259 showprofile=showprofile)
1260
1261 tmin, tmax = self.getTimeLim(x, xmin, xmax)
1262 if ymin == None: ymin = numpy.nanmin(datadB)
1263 if ymax == None: ymax = numpy.nanmax(datadB)
1264
1265 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1266 self.__isConfig = True
1267
1268 self.xdata = numpy.array([])
1269 self.ydata = numpy.array([])
1270
1271 self.setWinTitle(title)
1272
1273
1274 title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y"))
1275
1276 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
1277 axes = self.axesList[0]
1278
1279 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1280
1281 if len(self.ydata)==0:
1282 self.ydata = datadB[channelIndexList].reshape(-1,1)
1283 else:
1284 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
1285
1286
1287 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1288 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1289 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1290 XAxisAsTime=True
1291 )
1292
1293 self.draw()
1294
1295 if save:
1296
1297 if figfile == None:
1298 figfile = self.getFilename(name = self.name)
1299
1300 self.saveFigure(figpath, figfile)
1301
1302 if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax:
1303 self.__isConfig = False
1304 del self.xdata
1305 del self.ydata
1306
1307
1308 No newline at end of file
@@ -1,1310 +1,1616
1 '''
1 '''
2
2
3 $Author: dsuarez $
3 $Author: dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
4 $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $
5 '''
5 '''
6 import os
6 import os
7 import numpy
7 import numpy
8 import datetime
8 import datetime
9 import time
9 import time
10
10
11 from jrodata import *
11 from jrodata import *
12 from jrodataIO import *
12 from jrodataIO import *
13 from jroplot import *
13 from jroplot import *
14
14
15 try:
15 try:
16 import cfunctions
16 import cfunctions
17 except:
17 except:
18 pass
18 pass
19
19
20 class ProcessingUnit:
20 class ProcessingUnit:
21
21
22 """
22 """
23 Esta es la clase base para el procesamiento de datos.
23 Esta es la clase base para el procesamiento de datos.
24
24
25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
25 Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser:
26 - Metodos internos (callMethod)
26 - Metodos internos (callMethod)
27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
27 - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos
28 tienen que ser agreagados con el metodo "add".
28 tienen que ser agreagados con el metodo "add".
29
29
30 """
30 """
31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
31 # objeto de datos de entrada (Voltage, Spectra o Correlation)
32 dataIn = None
32 dataIn = None
33
33
34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
34 # objeto de datos de entrada (Voltage, Spectra o Correlation)
35 dataOut = None
35 dataOut = None
36
36
37
37
38 objectDict = None
38 objectDict = None
39
39
40 def __init__(self):
40 def __init__(self):
41
41
42 self.objectDict = {}
42 self.objectDict = {}
43
43
44 def init(self):
44 def init(self):
45
45
46 raise ValueError, "Not implemented"
46 raise ValueError, "Not implemented"
47
47
48 def addOperation(self, object, objId):
48 def addOperation(self, object, objId):
49
49
50 """
50 """
51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
51 Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el
52 identificador asociado a este objeto.
52 identificador asociado a este objeto.
53
53
54 Input:
54 Input:
55
55
56 object : objeto de la clase "Operation"
56 object : objeto de la clase "Operation"
57
57
58 Return:
58 Return:
59
59
60 objId : identificador del objeto, necesario para ejecutar la operacion
60 objId : identificador del objeto, necesario para ejecutar la operacion
61 """
61 """
62
62
63 self.objectDict[objId] = object
63 self.objectDict[objId] = object
64
64
65 return objId
65 return objId
66
66
67 def operation(self, **kwargs):
67 def operation(self, **kwargs):
68
68
69 """
69 """
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
70 Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los
71 atributos del objeto dataOut
71 atributos del objeto dataOut
72
72
73 Input:
73 Input:
74
74
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
75 **kwargs : Diccionario de argumentos de la funcion a ejecutar
76 """
76 """
77
77
78 raise ValueError, "ImplementedError"
78 raise ValueError, "ImplementedError"
79
79
80 def callMethod(self, name, **kwargs):
80 def callMethod(self, name, **kwargs):
81
81
82 """
82 """
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
83 Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase.
84
84
85 Input:
85 Input:
86 name : nombre del metodo a ejecutar
86 name : nombre del metodo a ejecutar
87
87
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
88 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
89
89
90 """
90 """
91 if name != 'run':
91 if name != 'run':
92
92
93 if name == 'init' and self.dataIn.isEmpty():
93 if name == 'init' and self.dataIn.isEmpty():
94 self.dataOut.flagNoData = True
94 self.dataOut.flagNoData = True
95 return False
95 return False
96
96
97 if name != 'init' and self.dataOut.isEmpty():
97 if name != 'init' and self.dataOut.isEmpty():
98 return False
98 return False
99
99
100 methodToCall = getattr(self, name)
100 methodToCall = getattr(self, name)
101
101
102 methodToCall(**kwargs)
102 methodToCall(**kwargs)
103
103
104 if name != 'run':
104 if name != 'run':
105 return True
105 return True
106
106
107 if self.dataOut.isEmpty():
107 if self.dataOut.isEmpty():
108 return False
108 return False
109
109
110 return True
110 return True
111
111
112 def callObject(self, objId, **kwargs):
112 def callObject(self, objId, **kwargs):
113
113
114 """
114 """
115 Ejecuta la operacion asociada al identificador del objeto "objId"
115 Ejecuta la operacion asociada al identificador del objeto "objId"
116
116
117 Input:
117 Input:
118
118
119 objId : identificador del objeto a ejecutar
119 objId : identificador del objeto a ejecutar
120
120
121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
121 **kwargs : diccionario con los nombres y valores de la funcion a ejecutar.
122
122
123 Return:
123 Return:
124
124
125 None
125 None
126 """
126 """
127
127
128 if self.dataOut.isEmpty():
128 if self.dataOut.isEmpty():
129 return False
129 return False
130
130
131 object = self.objectDict[objId]
131 object = self.objectDict[objId]
132
132
133 object.run(self.dataOut, **kwargs)
133 object.run(self.dataOut, **kwargs)
134
134
135 return True
135 return True
136
136
137 def call(self, operationConf, **kwargs):
137 def call(self, operationConf, **kwargs):
138
138
139 """
139 """
140 Return True si ejecuta la operacion "operationConf.name" con los
140 Return True si ejecuta la operacion "operationConf.name" con los
141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
141 argumentos "**kwargs". False si la operacion no se ha ejecutado.
142 La operacion puede ser de dos tipos:
142 La operacion puede ser de dos tipos:
143
143
144 1. Un metodo propio de esta clase:
144 1. Un metodo propio de esta clase:
145
145
146 operation.type = "self"
146 operation.type = "self"
147
147
148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
148 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella:
149 operation.type = "other".
149 operation.type = "other".
150
150
151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
151 Este objeto de tipo Operation debe de haber sido agregado antes con el metodo:
152 "addOperation" e identificado con el operation.id
152 "addOperation" e identificado con el operation.id
153
153
154
154
155 con el id de la operacion.
155 con el id de la operacion.
156
156
157 Input:
157 Input:
158
158
159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
159 Operation : Objeto del tipo operacion con los atributos: name, type y id.
160
160
161 """
161 """
162
162
163 if operationConf.type == 'self':
163 if operationConf.type == 'self':
164 sts = self.callMethod(operationConf.name, **kwargs)
164 sts = self.callMethod(operationConf.name, **kwargs)
165
165
166 if operationConf.type == 'other':
166 if operationConf.type == 'other':
167 sts = self.callObject(operationConf.id, **kwargs)
167 sts = self.callObject(operationConf.id, **kwargs)
168
168
169 return sts
169 return sts
170
170
171 def setInput(self, dataIn):
171 def setInput(self, dataIn):
172
172
173 self.dataIn = dataIn
173 self.dataIn = dataIn
174
174
175 def getOutput(self):
175 def getOutput(self):
176
176
177 return self.dataOut
177 return self.dataOut
178
178
179 class Operation():
179 class Operation():
180
180
181 """
181 """
182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
182 Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit
183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
183 y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de
184 acumulacion dentro de esta clase
184 acumulacion dentro de esta clase
185
185
186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
186 Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer)
187
187
188 """
188 """
189
189
190 __buffer = None
190 __buffer = None
191 __isConfig = False
191 __isConfig = False
192
192
193 def __init__(self):
193 def __init__(self):
194
194
195 pass
195 pass
196
196
197 def run(self, dataIn, **kwargs):
197 def run(self, dataIn, **kwargs):
198
198
199 """
199 """
200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
200 Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn.
201
201
202 Input:
202 Input:
203
203
204 dataIn : objeto del tipo JROData
204 dataIn : objeto del tipo JROData
205
205
206 Return:
206 Return:
207
207
208 None
208 None
209
209
210 Affected:
210 Affected:
211 __buffer : buffer de recepcion de datos.
211 __buffer : buffer de recepcion de datos.
212
212
213 """
213 """
214
214
215 raise ValueError, "ImplementedError"
215 raise ValueError, "ImplementedError"
216
216
217 class VoltageProc(ProcessingUnit):
217 class VoltageProc(ProcessingUnit):
218
218
219
219
220 def __init__(self):
220 def __init__(self):
221
221
222 self.objectDict = {}
222 self.objectDict = {}
223 self.dataOut = Voltage()
223 self.dataOut = Voltage()
224 self.flip = 1
224 self.flip = 1
225
225
226 def init(self):
226 def init(self):
227
227
228 self.dataOut.copy(self.dataIn)
228 self.dataOut.copy(self.dataIn)
229 # No necesita copiar en cada init() los atributos de dataIn
229 # No necesita copiar en cada init() los atributos de dataIn
230 # la copia deberia hacerse por cada nuevo bloque de datos
230 # la copia deberia hacerse por cada nuevo bloque de datos
231
231
232 def selectChannels(self, channelList):
232 def selectChannels(self, channelList):
233
233
234 channelIndexList = []
234 channelIndexList = []
235
235
236 for channel in channelList:
236 for channel in channelList:
237 index = self.dataOut.channelList.index(channel)
237 index = self.dataOut.channelList.index(channel)
238 channelIndexList.append(index)
238 channelIndexList.append(index)
239
239
240 self.selectChannelsByIndex(channelIndexList)
240 self.selectChannelsByIndex(channelIndexList)
241
241
242 def selectChannelsByIndex(self, channelIndexList):
242 def selectChannelsByIndex(self, channelIndexList):
243 """
243 """
244 Selecciona un bloque de datos en base a canales segun el channelIndexList
244 Selecciona un bloque de datos en base a canales segun el channelIndexList
245
245
246 Input:
246 Input:
247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
247 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
248
248
249 Affected:
249 Affected:
250 self.dataOut.data
250 self.dataOut.data
251 self.dataOut.channelIndexList
251 self.dataOut.channelIndexList
252 self.dataOut.nChannels
252 self.dataOut.nChannels
253 self.dataOut.m_ProcessingHeader.totalSpectra
253 self.dataOut.m_ProcessingHeader.totalSpectra
254 self.dataOut.systemHeaderObj.numChannels
254 self.dataOut.systemHeaderObj.numChannels
255 self.dataOut.m_ProcessingHeader.blockSize
255 self.dataOut.m_ProcessingHeader.blockSize
256
256
257 Return:
257 Return:
258 None
258 None
259 """
259 """
260
260
261 for channelIndex in channelIndexList:
261 for channelIndex in channelIndexList:
262 if channelIndex not in self.dataOut.channelIndexList:
262 if channelIndex not in self.dataOut.channelIndexList:
263 print channelIndexList
263 print channelIndexList
264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
264 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
265
265
266 nChannels = len(channelIndexList)
266 nChannels = len(channelIndexList)
267
267
268 data = self.dataOut.data[channelIndexList,:]
268 data = self.dataOut.data[channelIndexList,:]
269
269
270 self.dataOut.data = data
270 self.dataOut.data = data
271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
271 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
272 # self.dataOut.nChannels = nChannels
272 # self.dataOut.nChannels = nChannels
273
273
274 return 1
274 return 1
275
275
276 def selectHeights(self, minHei, maxHei):
276 def selectHeights(self, minHei, maxHei):
277 """
277 """
278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
278 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
279 minHei <= height <= maxHei
279 minHei <= height <= maxHei
280
280
281 Input:
281 Input:
282 minHei : valor minimo de altura a considerar
282 minHei : valor minimo de altura a considerar
283 maxHei : valor maximo de altura a considerar
283 maxHei : valor maximo de altura a considerar
284
284
285 Affected:
285 Affected:
286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
286 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
287
287
288 Return:
288 Return:
289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
289 1 si el metodo se ejecuto con exito caso contrario devuelve 0
290 """
290 """
291 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
291 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
292 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
292 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
293
293
294 if (maxHei > self.dataOut.heightList[-1]):
294 if (maxHei > self.dataOut.heightList[-1]):
295 maxHei = self.dataOut.heightList[-1]
295 maxHei = self.dataOut.heightList[-1]
296 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
296 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
297
297
298 minIndex = 0
298 minIndex = 0
299 maxIndex = 0
299 maxIndex = 0
300 heights = self.dataOut.heightList
300 heights = self.dataOut.heightList
301
301
302 inda = numpy.where(heights >= minHei)
302 inda = numpy.where(heights >= minHei)
303 indb = numpy.where(heights <= maxHei)
303 indb = numpy.where(heights <= maxHei)
304
304
305 try:
305 try:
306 minIndex = inda[0][0]
306 minIndex = inda[0][0]
307 except:
307 except:
308 minIndex = 0
308 minIndex = 0
309
309
310 try:
310 try:
311 maxIndex = indb[0][-1]
311 maxIndex = indb[0][-1]
312 except:
312 except:
313 maxIndex = len(heights)
313 maxIndex = len(heights)
314
314
315 self.selectHeightsByIndex(minIndex, maxIndex)
315 self.selectHeightsByIndex(minIndex, maxIndex)
316
316
317 return 1
317 return 1
318
318
319
319
320 def selectHeightsByIndex(self, minIndex, maxIndex):
320 def selectHeightsByIndex(self, minIndex, maxIndex):
321 """
321 """
322 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
322 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
323 minIndex <= index <= maxIndex
323 minIndex <= index <= maxIndex
324
324
325 Input:
325 Input:
326 minIndex : valor de indice minimo de altura a considerar
326 minIndex : valor de indice minimo de altura a considerar
327 maxIndex : valor de indice maximo de altura a considerar
327 maxIndex : valor de indice maximo de altura a considerar
328
328
329 Affected:
329 Affected:
330 self.dataOut.data
330 self.dataOut.data
331 self.dataOut.heightList
331 self.dataOut.heightList
332
332
333 Return:
333 Return:
334 1 si el metodo se ejecuto con exito caso contrario devuelve 0
334 1 si el metodo se ejecuto con exito caso contrario devuelve 0
335 """
335 """
336
336
337 if (minIndex < 0) or (minIndex > maxIndex):
337 if (minIndex < 0) or (minIndex > maxIndex):
338 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
338 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
339
339
340 if (maxIndex >= self.dataOut.nHeights):
340 if (maxIndex >= self.dataOut.nHeights):
341 maxIndex = self.dataOut.nHeights-1
341 maxIndex = self.dataOut.nHeights-1
342 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
342 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
343
343
344 nHeights = maxIndex - minIndex + 1
344 nHeights = maxIndex - minIndex + 1
345
345
346 #voltage
346 #voltage
347 data = self.dataOut.data[:,minIndex:maxIndex+1]
347 data = self.dataOut.data[:,minIndex:maxIndex+1]
348
348
349 firstHeight = self.dataOut.heightList[minIndex]
349 firstHeight = self.dataOut.heightList[minIndex]
350
350
351 self.dataOut.data = data
351 self.dataOut.data = data
352 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
352 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
353
353
354 return 1
354 return 1
355
355
356
356
357 def filterByHeights(self, window):
357 def filterByHeights(self, window):
358 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
358 deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
359
359
360 if window == None:
360 if window == None:
361 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
361 window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight
362
362
363 newdelta = deltaHeight * window
363 newdelta = deltaHeight * window
364 r = self.dataOut.data.shape[1] % window
364 r = self.dataOut.data.shape[1] % window
365 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
365 buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r]
366 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
366 buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window)
367 buffer = numpy.sum(buffer,2)
367 buffer = numpy.sum(buffer,2)
368 self.dataOut.data = buffer
368 self.dataOut.data = buffer
369 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window-newdelta,newdelta)
369 self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window-newdelta,newdelta)
370 self.dataOut.windowOfFilter = window
370 self.dataOut.windowOfFilter = window
371
371
372 def deFlip(self):
372 def deFlip(self):
373 self.dataOut.data *= self.flip
373 self.dataOut.data *= self.flip
374 self.flip *= -1.
374 self.flip *= -1.
375
375
376
376
377 class CohInt(Operation):
377 class CohInt(Operation):
378
378
379 __isConfig = False
379 __isConfig = False
380
380
381 __profIndex = 0
381 __profIndex = 0
382 __withOverapping = False
382 __withOverapping = False
383
383
384 __byTime = False
384 __byTime = False
385 __initime = None
385 __initime = None
386 __lastdatatime = None
386 __lastdatatime = None
387 __integrationtime = None
387 __integrationtime = None
388
388
389 __buffer = None
389 __buffer = None
390
390
391 __dataReady = False
391 __dataReady = False
392
392
393 n = None
393 n = None
394
394
395
395
396 def __init__(self):
396 def __init__(self):
397
397
398 self.__isConfig = False
398 self.__isConfig = False
399
399
400 def setup(self, n=None, timeInterval=None, overlapping=False):
400 def setup(self, n=None, timeInterval=None, overlapping=False):
401 """
401 """
402 Set the parameters of the integration class.
402 Set the parameters of the integration class.
403
403
404 Inputs:
404 Inputs:
405
405
406 n : Number of coherent integrations
406 n : Number of coherent integrations
407 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
407 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
408 overlapping :
408 overlapping :
409
409
410 """
410 """
411
411
412 self.__initime = None
412 self.__initime = None
413 self.__lastdatatime = 0
413 self.__lastdatatime = 0
414 self.__buffer = None
414 self.__buffer = None
415 self.__dataReady = False
415 self.__dataReady = False
416
416
417
417
418 if n == None and timeInterval == None:
418 if n == None and timeInterval == None:
419 raise ValueError, "n or timeInterval should be specified ..."
419 raise ValueError, "n or timeInterval should be specified ..."
420
420
421 if n != None:
421 if n != None:
422 self.n = n
422 self.n = n
423 self.__byTime = False
423 self.__byTime = False
424 else:
424 else:
425 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
425 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
426 self.n = 9999
426 self.n = 9999
427 self.__byTime = True
427 self.__byTime = True
428
428
429 if overlapping:
429 if overlapping:
430 self.__withOverapping = True
430 self.__withOverapping = True
431 self.__buffer = None
431 self.__buffer = None
432 else:
432 else:
433 self.__withOverapping = False
433 self.__withOverapping = False
434 self.__buffer = 0
434 self.__buffer = 0
435
435
436 self.__profIndex = 0
436 self.__profIndex = 0
437
437
438 def putData(self, data):
438 def putData(self, data):
439
439
440 """
440 """
441 Add a profile to the __buffer and increase in one the __profileIndex
441 Add a profile to the __buffer and increase in one the __profileIndex
442
442
443 """
443 """
444
444
445 if not self.__withOverapping:
445 if not self.__withOverapping:
446 self.__buffer += data.copy()
446 self.__buffer += data.copy()
447 self.__profIndex += 1
447 self.__profIndex += 1
448 return
448 return
449
449
450 #Overlapping data
450 #Overlapping data
451 nChannels, nHeis = data.shape
451 nChannels, nHeis = data.shape
452 data = numpy.reshape(data, (1, nChannels, nHeis))
452 data = numpy.reshape(data, (1, nChannels, nHeis))
453
453
454 #If the buffer is empty then it takes the data value
454 #If the buffer is empty then it takes the data value
455 if self.__buffer == None:
455 if self.__buffer == None:
456 self.__buffer = data
456 self.__buffer = data
457 self.__profIndex += 1
457 self.__profIndex += 1
458 return
458 return
459
459
460 #If the buffer length is lower than n then stakcing the data value
460 #If the buffer length is lower than n then stakcing the data value
461 if self.__profIndex < self.n:
461 if self.__profIndex < self.n:
462 self.__buffer = numpy.vstack((self.__buffer, data))
462 self.__buffer = numpy.vstack((self.__buffer, data))
463 self.__profIndex += 1
463 self.__profIndex += 1
464 return
464 return
465
465
466 #If the buffer length is equal to n then replacing the last buffer value with the data value
466 #If the buffer length is equal to n then replacing the last buffer value with the data value
467 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
467 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
468 self.__buffer[self.n-1] = data
468 self.__buffer[self.n-1] = data
469 self.__profIndex = self.n
469 self.__profIndex = self.n
470 return
470 return
471
471
472
472
473 def pushData(self):
473 def pushData(self):
474 """
474 """
475 Return the sum of the last profiles and the profiles used in the sum.
475 Return the sum of the last profiles and the profiles used in the sum.
476
476
477 Affected:
477 Affected:
478
478
479 self.__profileIndex
479 self.__profileIndex
480
480
481 """
481 """
482
482
483 if not self.__withOverapping:
483 if not self.__withOverapping:
484 data = self.__buffer
484 data = self.__buffer
485 n = self.__profIndex
485 n = self.__profIndex
486
486
487 self.__buffer = 0
487 self.__buffer = 0
488 self.__profIndex = 0
488 self.__profIndex = 0
489
489
490 return data, n
490 return data, n
491
491
492 #Integration with Overlapping
492 #Integration with Overlapping
493 data = numpy.sum(self.__buffer, axis=0)
493 data = numpy.sum(self.__buffer, axis=0)
494 n = self.__profIndex
494 n = self.__profIndex
495
495
496 return data, n
496 return data, n
497
497
498 def byProfiles(self, data):
498 def byProfiles(self, data):
499
499
500 self.__dataReady = False
500 self.__dataReady = False
501 avgdata = None
501 avgdata = None
502 n = None
502 n = None
503
503
504 self.putData(data)
504 self.putData(data)
505
505
506 if self.__profIndex == self.n:
506 if self.__profIndex == self.n:
507
507
508 avgdata, n = self.pushData()
508 avgdata, n = self.pushData()
509 self.__dataReady = True
509 self.__dataReady = True
510
510
511 return avgdata
511 return avgdata
512
512
513 def byTime(self, data, datatime):
513 def byTime(self, data, datatime):
514
514
515 self.__dataReady = False
515 self.__dataReady = False
516 avgdata = None
516 avgdata = None
517 n = None
517 n = None
518
518
519 self.putData(data)
519 self.putData(data)
520
520
521 if (datatime - self.__initime) >= self.__integrationtime:
521 if (datatime - self.__initime) >= self.__integrationtime:
522 avgdata, n = self.pushData()
522 avgdata, n = self.pushData()
523 self.n = n
523 self.n = n
524 self.__dataReady = True
524 self.__dataReady = True
525
525
526 return avgdata
526 return avgdata
527
527
528 def integrate(self, data, datatime=None):
528 def integrate(self, data, datatime=None):
529
529
530 if self.__initime == None:
530 if self.__initime == None:
531 self.__initime = datatime
531 self.__initime = datatime
532
532
533 if self.__byTime:
533 if self.__byTime:
534 avgdata = self.byTime(data, datatime)
534 avgdata = self.byTime(data, datatime)
535 else:
535 else:
536 avgdata = self.byProfiles(data)
536 avgdata = self.byProfiles(data)
537
537
538
538
539 self.__lastdatatime = datatime
539 self.__lastdatatime = datatime
540
540
541 if avgdata == None:
541 if avgdata == None:
542 return None, None
542 return None, None
543
543
544 avgdatatime = self.__initime
544 avgdatatime = self.__initime
545
545
546 deltatime = datatime -self.__lastdatatime
546 deltatime = datatime -self.__lastdatatime
547
547
548 if not self.__withOverapping:
548 if not self.__withOverapping:
549 self.__initime = datatime
549 self.__initime = datatime
550 else:
550 else:
551 self.__initime += deltatime
551 self.__initime += deltatime
552
552
553 return avgdata, avgdatatime
553 return avgdata, avgdatatime
554
554
555 def run(self, dataOut, **kwargs):
555 def run(self, dataOut, **kwargs):
556
556
557 if not self.__isConfig:
557 if not self.__isConfig:
558 self.setup(**kwargs)
558 self.setup(**kwargs)
559 self.__isConfig = True
559 self.__isConfig = True
560
560
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
561 avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime)
562
562
563 # dataOut.timeInterval *= n
563 # dataOut.timeInterval *= n
564 dataOut.flagNoData = True
564 dataOut.flagNoData = True
565
565
566 if self.__dataReady:
566 if self.__dataReady:
567 dataOut.data = avgdata
567 dataOut.data = avgdata
568 dataOut.nCohInt *= self.n
568 dataOut.nCohInt *= self.n
569 dataOut.utctime = avgdatatime
569 dataOut.utctime = avgdatatime
570 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
570 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt
571 dataOut.flagNoData = False
571 dataOut.flagNoData = False
572
572
573
573
574 class Decoder(Operation):
574 class Decoder(Operation):
575
575
576 __isConfig = False
576 __isConfig = False
577 __profIndex = 0
577 __profIndex = 0
578
578
579 code = None
579 code = None
580
580
581 nCode = None
581 nCode = None
582 nBaud = None
582 nBaud = None
583
583
584 def __init__(self):
584 def __init__(self):
585
585
586 self.__isConfig = False
586 self.__isConfig = False
587
587
588 def setup(self, code, shape):
588 def setup(self, code, shape):
589
589
590 self.__profIndex = 0
590 self.__profIndex = 0
591
591
592 self.code = code
592 self.code = code
593
593
594 self.nCode = len(code)
594 self.nCode = len(code)
595 self.nBaud = len(code[0])
595 self.nBaud = len(code[0])
596
596
597 self.__nChannels, self.__nHeis = shape
597 self.__nChannels, self.__nHeis = shape
598
598
599 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
599 __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex)
600
600
601 __codeBuffer[:,0:self.nBaud] = self.code
601 __codeBuffer[:,0:self.nBaud] = self.code
602
602
603 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
603 self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1))
604
604
605 self.ndatadec = self.__nHeis - self.nBaud + 1
605 self.ndatadec = self.__nHeis - self.nBaud + 1
606
606
607 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
607 self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex)
608
608
609 def convolutionInFreq(self, data):
609 def convolutionInFreq(self, data):
610
610
611 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
611 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
612
612
613 fft_data = numpy.fft.fft(data, axis=1)
613 fft_data = numpy.fft.fft(data, axis=1)
614
614
615 conv = fft_data*fft_code
615 conv = fft_data*fft_code
616
616
617 data = numpy.fft.ifft(conv,axis=1)
617 data = numpy.fft.ifft(conv,axis=1)
618
618
619 datadec = data[:,:-self.nBaud+1]
619 datadec = data[:,:-self.nBaud+1]
620
620
621 return datadec
621 return datadec
622
622
623 def convolutionInFreqOpt(self, data):
623 def convolutionInFreqOpt(self, data):
624
624
625 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
625 fft_code = self.fft_code[self.__profIndex].reshape(1,-1)
626
626
627 data = cfunctions.decoder(fft_code, data)
627 data = cfunctions.decoder(fft_code, data)
628
628
629 datadec = data[:,:-self.nBaud+1]
629 datadec = data[:,:-self.nBaud+1]
630
630
631 return datadec
631 return datadec
632
632
633 def convolutionInTime(self, data):
633 def convolutionInTime(self, data):
634
634
635 code = self.code[self.__profIndex]
635 code = self.code[self.__profIndex]
636
636
637 for i in range(self.__nChannels):
637 for i in range(self.__nChannels):
638 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
638 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid')
639
639
640 return self.datadecTime
640 return self.datadecTime
641
641
642 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
642 def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0):
643
643
644 if not self.__isConfig:
644 if not self.__isConfig:
645
645
646 if code == None:
646 if code == None:
647 code = dataOut.code
647 code = dataOut.code
648 else:
648 else:
649 code = numpy.array(code).reshape(nCode,nBaud)
649 code = numpy.array(code).reshape(nCode,nBaud)
650 dataOut.code = code
650 dataOut.code = code
651 dataOut.nCode = nCode
651 dataOut.nCode = nCode
652 dataOut.nBaud = nBaud
652 dataOut.nBaud = nBaud
653
653
654 if code == None:
654 if code == None:
655 return 1
655 return 1
656
656
657 self.setup(code, dataOut.data.shape)
657 self.setup(code, dataOut.data.shape)
658 self.__isConfig = True
658 self.__isConfig = True
659
659
660 if mode == 0:
660 if mode == 0:
661 datadec = self.convolutionInTime(dataOut.data)
661 datadec = self.convolutionInTime(dataOut.data)
662
662
663 if mode == 1:
663 if mode == 1:
664 datadec = self.convolutionInFreq(dataOut.data)
664 datadec = self.convolutionInFreq(dataOut.data)
665
665
666 if mode == 2:
666 if mode == 2:
667 datadec = self.convolutionInFreqOpt(dataOut.data)
667 datadec = self.convolutionInFreqOpt(dataOut.data)
668
668
669 dataOut.data = datadec
669 dataOut.data = datadec
670
670
671 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
671 dataOut.heightList = dataOut.heightList[0:self.ndatadec]
672
672
673 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
673 dataOut.flagDecodeData = True #asumo q la data no esta decodificada
674
674
675 if self.__profIndex == self.nCode-1:
675 if self.__profIndex == self.nCode-1:
676 self.__profIndex = 0
676 self.__profIndex = 0
677 return 1
677 return 1
678
678
679 self.__profIndex += 1
679 self.__profIndex += 1
680
680
681 return 1
681 return 1
682 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
682 # dataOut.flagDeflipData = True #asumo q la data no esta sin flip
683
683
684
684
685
685
686 class SpectraProc(ProcessingUnit):
686 class SpectraProc(ProcessingUnit):
687
687
688 def __init__(self):
688 def __init__(self):
689
689
690 self.objectDict = {}
690 self.objectDict = {}
691 self.buffer = None
691 self.buffer = None
692 self.firstdatatime = None
692 self.firstdatatime = None
693 self.profIndex = 0
693 self.profIndex = 0
694 self.dataOut = Spectra()
694 self.dataOut = Spectra()
695
695
696 def __updateObjFromInput(self):
696 def __updateObjFromInput(self):
697
697
698 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
698 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
699 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
699 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
700 self.dataOut.channelList = self.dataIn.channelList
700 self.dataOut.channelList = self.dataIn.channelList
701 self.dataOut.heightList = self.dataIn.heightList
701 self.dataOut.heightList = self.dataIn.heightList
702 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
702 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
703 # self.dataOut.nHeights = self.dataIn.nHeights
703 # self.dataOut.nHeights = self.dataIn.nHeights
704 # self.dataOut.nChannels = self.dataIn.nChannels
704 # self.dataOut.nChannels = self.dataIn.nChannels
705 self.dataOut.nBaud = self.dataIn.nBaud
705 self.dataOut.nBaud = self.dataIn.nBaud
706 self.dataOut.nCode = self.dataIn.nCode
706 self.dataOut.nCode = self.dataIn.nCode
707 self.dataOut.code = self.dataIn.code
707 self.dataOut.code = self.dataIn.code
708 self.dataOut.nProfiles = self.dataOut.nFFTPoints
708 self.dataOut.nProfiles = self.dataOut.nFFTPoints
709 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
709 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
710 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
710 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
711 self.dataOut.utctime = self.firstdatatime
711 self.dataOut.utctime = self.firstdatatime
712 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
712 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
713 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
713 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
714 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
714 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
715 self.dataOut.nCohInt = self.dataIn.nCohInt
715 self.dataOut.nCohInt = self.dataIn.nCohInt
716 self.dataOut.nIncohInt = 1
716 self.dataOut.nIncohInt = 1
717 self.dataOut.ippSeconds = self.dataIn.ippSeconds
717 self.dataOut.ippSeconds = self.dataIn.ippSeconds
718 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
718 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
719
719
720 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
720 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
721
721
722 def __getFft(self):
722 def __getFft(self):
723 """
723 """
724 Convierte valores de Voltaje a Spectra
724 Convierte valores de Voltaje a Spectra
725
725
726 Affected:
726 Affected:
727 self.dataOut.data_spc
727 self.dataOut.data_spc
728 self.dataOut.data_cspc
728 self.dataOut.data_cspc
729 self.dataOut.data_dc
729 self.dataOut.data_dc
730 self.dataOut.heightList
730 self.dataOut.heightList
731 self.profIndex
731 self.profIndex
732 self.buffer
732 self.buffer
733 self.dataOut.flagNoData
733 self.dataOut.flagNoData
734 """
734 """
735 fft_volt = numpy.fft.fft(self.buffer,axis=1)
735 fft_volt = numpy.fft.fft(self.buffer,axis=1)
736 fft_volt = fft_volt.astype(numpy.dtype('complex'))
736 fft_volt = fft_volt.astype(numpy.dtype('complex'))
737 dc = fft_volt[:,0,:]
737 dc = fft_volt[:,0,:]
738
738
739 #calculo de self-spectra
739 #calculo de self-spectra
740 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
740 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
741 spc = fft_volt * numpy.conjugate(fft_volt)
741 spc = fft_volt * numpy.conjugate(fft_volt)
742 spc = spc.real
742 spc = spc.real
743
743
744 blocksize = 0
744 blocksize = 0
745 blocksize += dc.size
745 blocksize += dc.size
746 blocksize += spc.size
746 blocksize += spc.size
747
747
748 cspc = None
748 cspc = None
749 pairIndex = 0
749 pairIndex = 0
750 if self.dataOut.pairsList != None:
750 if self.dataOut.pairsList != None:
751 #calculo de cross-spectra
751 #calculo de cross-spectra
752 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
752 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
753 for pair in self.dataOut.pairsList:
753 for pair in self.dataOut.pairsList:
754 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
754 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
755 pairIndex += 1
755 pairIndex += 1
756 blocksize += cspc.size
756 blocksize += cspc.size
757
757
758 self.dataOut.data_spc = spc
758 self.dataOut.data_spc = spc
759 self.dataOut.data_cspc = cspc
759 self.dataOut.data_cspc = cspc
760 self.dataOut.data_dc = dc
760 self.dataOut.data_dc = dc
761 self.dataOut.blockSize = blocksize
761 self.dataOut.blockSize = blocksize
762
762
763 def init(self, nFFTPoints=None, pairsList=None):
763 def init(self, nFFTPoints=None, pairsList=None):
764
764
765 self.dataOut.flagNoData = True
765 self.dataOut.flagNoData = True
766
766
767 if self.dataIn.type == "Spectra":
767 if self.dataIn.type == "Spectra":
768 self.dataOut.copy(self.dataIn)
768 self.dataOut.copy(self.dataIn)
769 return
769 return
770
770
771 if self.dataIn.type == "Voltage":
771 if self.dataIn.type == "Voltage":
772
772
773 if nFFTPoints == None:
773 if nFFTPoints == None:
774 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
774 raise ValueError, "This SpectraProc.init() need nFFTPoints input variable"
775
775
776 if pairsList == None:
776 if pairsList == None:
777 nPairs = 0
777 nPairs = 0
778 else:
778 else:
779 nPairs = len(pairsList)
779 nPairs = len(pairsList)
780
780
781 self.dataOut.nFFTPoints = nFFTPoints
781 self.dataOut.nFFTPoints = nFFTPoints
782 self.dataOut.pairsList = pairsList
782 self.dataOut.pairsList = pairsList
783 self.dataOut.nPairs = nPairs
783 self.dataOut.nPairs = nPairs
784
784
785 if self.buffer == None:
785 if self.buffer == None:
786 self.buffer = numpy.zeros((self.dataIn.nChannels,
786 self.buffer = numpy.zeros((self.dataIn.nChannels,
787 self.dataOut.nFFTPoints,
787 self.dataOut.nFFTPoints,
788 self.dataIn.nHeights),
788 self.dataIn.nHeights),
789 dtype='complex')
789 dtype='complex')
790
790
791
791
792 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
792 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
793 self.profIndex += 1
793 self.profIndex += 1
794
794
795 if self.firstdatatime == None:
795 if self.firstdatatime == None:
796 self.firstdatatime = self.dataIn.utctime
796 self.firstdatatime = self.dataIn.utctime
797
797
798 if self.profIndex == self.dataOut.nFFTPoints:
798 if self.profIndex == self.dataOut.nFFTPoints:
799 self.__updateObjFromInput()
799 self.__updateObjFromInput()
800 self.__getFft()
800 self.__getFft()
801
801
802 self.dataOut.flagNoData = False
802 self.dataOut.flagNoData = False
803
803
804 self.buffer = None
804 self.buffer = None
805 self.firstdatatime = None
805 self.firstdatatime = None
806 self.profIndex = 0
806 self.profIndex = 0
807
807
808 return
808 return
809
809
810 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
810 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
811
811
812 def selectChannels(self, channelList):
812 def selectChannels(self, channelList):
813
813
814 channelIndexList = []
814 channelIndexList = []
815
815
816 for channel in channelList:
816 for channel in channelList:
817 index = self.dataOut.channelList.index(channel)
817 index = self.dataOut.channelList.index(channel)
818 channelIndexList.append(index)
818 channelIndexList.append(index)
819
819
820 self.selectChannelsByIndex(channelIndexList)
820 self.selectChannelsByIndex(channelIndexList)
821
821
822 def selectChannelsByIndex(self, channelIndexList):
822 def selectChannelsByIndex(self, channelIndexList):
823 """
823 """
824 Selecciona un bloque de datos en base a canales segun el channelIndexList
824 Selecciona un bloque de datos en base a canales segun el channelIndexList
825
825
826 Input:
826 Input:
827 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
827 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
828
828
829 Affected:
829 Affected:
830 self.dataOut.data_spc
830 self.dataOut.data_spc
831 self.dataOut.channelIndexList
831 self.dataOut.channelIndexList
832 self.dataOut.nChannels
832 self.dataOut.nChannels
833
833
834 Return:
834 Return:
835 None
835 None
836 """
836 """
837
837
838 for channelIndex in channelIndexList:
838 for channelIndex in channelIndexList:
839 if channelIndex not in self.dataOut.channelIndexList:
839 if channelIndex not in self.dataOut.channelIndexList:
840 print channelIndexList
840 print channelIndexList
841 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
841 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
842
842
843 nChannels = len(channelIndexList)
843 nChannels = len(channelIndexList)
844
844
845 data_spc = self.dataOut.data_spc[channelIndexList,:]
845 data_spc = self.dataOut.data_spc[channelIndexList,:]
846
846
847 self.dataOut.data_spc = data_spc
847 self.dataOut.data_spc = data_spc
848 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
848 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
849 # self.dataOut.nChannels = nChannels
849 # self.dataOut.nChannels = nChannels
850
850
851 return 1
851 return 1
852
852
853 def selectHeights(self, minHei, maxHei):
853 def selectHeights(self, minHei, maxHei):
854 """
854 """
855 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
855 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
856 minHei <= height <= maxHei
856 minHei <= height <= maxHei
857
857
858 Input:
858 Input:
859 minHei : valor minimo de altura a considerar
859 minHei : valor minimo de altura a considerar
860 maxHei : valor maximo de altura a considerar
860 maxHei : valor maximo de altura a considerar
861
861
862 Affected:
862 Affected:
863 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
863 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
864
864
865 Return:
865 Return:
866 1 si el metodo se ejecuto con exito caso contrario devuelve 0
866 1 si el metodo se ejecuto con exito caso contrario devuelve 0
867 """
867 """
868 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
868 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
869 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
869 raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
870
870
871 if (maxHei > self.dataOut.heightList[-1]):
871 if (maxHei > self.dataOut.heightList[-1]):
872 maxHei = self.dataOut.heightList[-1]
872 maxHei = self.dataOut.heightList[-1]
873 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
873 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
874
874
875 minIndex = 0
875 minIndex = 0
876 maxIndex = 0
876 maxIndex = 0
877 heights = self.dataOut.heightList
877 heights = self.dataOut.heightList
878
878
879 inda = numpy.where(heights >= minHei)
879 inda = numpy.where(heights >= minHei)
880 indb = numpy.where(heights <= maxHei)
880 indb = numpy.where(heights <= maxHei)
881
881
882 try:
882 try:
883 minIndex = inda[0][0]
883 minIndex = inda[0][0]
884 except:
884 except:
885 minIndex = 0
885 minIndex = 0
886
886
887 try:
887 try:
888 maxIndex = indb[0][-1]
888 maxIndex = indb[0][-1]
889 except:
889 except:
890 maxIndex = len(heights)
890 maxIndex = len(heights)
891
891
892 self.selectHeightsByIndex(minIndex, maxIndex)
892 self.selectHeightsByIndex(minIndex, maxIndex)
893
893
894 return 1
894 return 1
895
895
896
896
897 def selectHeightsByIndex(self, minIndex, maxIndex):
897 def selectHeightsByIndex(self, minIndex, maxIndex):
898 """
898 """
899 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
899 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
900 minIndex <= index <= maxIndex
900 minIndex <= index <= maxIndex
901
901
902 Input:
902 Input:
903 minIndex : valor de indice minimo de altura a considerar
903 minIndex : valor de indice minimo de altura a considerar
904 maxIndex : valor de indice maximo de altura a considerar
904 maxIndex : valor de indice maximo de altura a considerar
905
905
906 Affected:
906 Affected:
907 self.dataOut.data_spc
907 self.dataOut.data_spc
908 self.dataOut.data_cspc
908 self.dataOut.data_cspc
909 self.dataOut.data_dc
909 self.dataOut.data_dc
910 self.dataOut.heightList
910 self.dataOut.heightList
911
911
912 Return:
912 Return:
913 1 si el metodo se ejecuto con exito caso contrario devuelve 0
913 1 si el metodo se ejecuto con exito caso contrario devuelve 0
914 """
914 """
915
915
916 if (minIndex < 0) or (minIndex > maxIndex):
916 if (minIndex < 0) or (minIndex > maxIndex):
917 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
917 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
918
918
919 if (maxIndex >= self.dataOut.nHeights):
919 if (maxIndex >= self.dataOut.nHeights):
920 maxIndex = self.dataOut.nHeights-1
920 maxIndex = self.dataOut.nHeights-1
921 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
921 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
922
922
923 nHeights = maxIndex - minIndex + 1
923 nHeights = maxIndex - minIndex + 1
924
924
925 #Spectra
925 #Spectra
926 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
926 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
927
927
928 data_cspc = None
928 data_cspc = None
929 if self.dataOut.data_cspc != None:
929 if self.dataOut.data_cspc != None:
930 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
930 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
931
931
932 data_dc = None
932 data_dc = None
933 if self.dataOut.data_dc != None:
933 if self.dataOut.data_dc != None:
934 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
934 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
935
935
936 self.dataOut.data_spc = data_spc
936 self.dataOut.data_spc = data_spc
937 self.dataOut.data_cspc = data_cspc
937 self.dataOut.data_cspc = data_cspc
938 self.dataOut.data_dc = data_dc
938 self.dataOut.data_dc = data_dc
939
939
940 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
940 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
941
941
942 return 1
942 return 1
943
943
944 def removeDC(self, mode = 1):
944 def removeDC(self, mode = 1):
945
945
946 dc_index = 0
946 dc_index = 0
947 freq_index = numpy.array([-2,-1,1,2])
947 freq_index = numpy.array([-2,-1,1,2])
948 data_spc = self.dataOut.data_spc
948 data_spc = self.dataOut.data_spc
949 data_cspc = self.dataOut.data_cspc
949 data_cspc = self.dataOut.data_cspc
950 data_dc = self.dataOut.data_dc
950 data_dc = self.dataOut.data_dc
951
951
952 if self.dataOut.flagShiftFFT:
952 if self.dataOut.flagShiftFFT:
953 dc_index += self.dataOut.nFFTPoints/2
953 dc_index += self.dataOut.nFFTPoints/2
954 freq_index += self.dataOut.nFFTPoints/2
954 freq_index += self.dataOut.nFFTPoints/2
955
955
956 if mode == 1:
956 if mode == 1:
957 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
957 data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2
958 if data_cspc != None:
958 if data_cspc != None:
959 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
959 data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2
960 return 1
960 return 1
961
961
962 if mode == 2:
962 if mode == 2:
963 pass
963 pass
964
964
965 if mode == 3:
965 if mode == 3:
966 pass
966 pass
967
967
968 raise ValueError, "mode parameter has to be 1, 2 or 3"
968 raise ValueError, "mode parameter has to be 1, 2 or 3"
969
969
970 def removeInterference(self):
970 def removeInterference(self):
971
971
972 pass
972 pass
973
973
974
974
975 class IncohInt(Operation):
975 class IncohInt(Operation):
976
976
977
977
978 __profIndex = 0
978 __profIndex = 0
979 __withOverapping = False
979 __withOverapping = False
980
980
981 __byTime = False
981 __byTime = False
982 __initime = None
982 __initime = None
983 __lastdatatime = None
983 __lastdatatime = None
984 __integrationtime = None
984 __integrationtime = None
985
985
986 __buffer_spc = None
986 __buffer_spc = None
987 __buffer_cspc = None
987 __buffer_cspc = None
988 __buffer_dc = None
988 __buffer_dc = None
989
989
990 __dataReady = False
990 __dataReady = False
991
991
992 __timeInterval = None
992 __timeInterval = None
993
993
994 n = None
994 n = None
995
995
996
996
997
997
998 def __init__(self):
998 def __init__(self):
999
999
1000 self.__isConfig = False
1000 self.__isConfig = False
1001
1001
1002 def setup(self, n=None, timeInterval=None, overlapping=False):
1002 def setup(self, n=None, timeInterval=None, overlapping=False):
1003 """
1003 """
1004 Set the parameters of the integration class.
1004 Set the parameters of the integration class.
1005
1005
1006 Inputs:
1006 Inputs:
1007
1007
1008 n : Number of coherent integrations
1008 n : Number of coherent integrations
1009 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1009 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1010 overlapping :
1010 overlapping :
1011
1011
1012 """
1012 """
1013
1013
1014 self.__initime = None
1014 self.__initime = None
1015 self.__lastdatatime = 0
1015 self.__lastdatatime = 0
1016 self.__buffer_spc = None
1016 self.__buffer_spc = None
1017 self.__buffer_cspc = None
1017 self.__buffer_cspc = None
1018 self.__buffer_dc = None
1018 self.__buffer_dc = None
1019 self.__dataReady = False
1019 self.__dataReady = False
1020
1020
1021
1021
1022 if n == None and timeInterval == None:
1022 if n == None and timeInterval == None:
1023 raise ValueError, "n or timeInterval should be specified ..."
1023 raise ValueError, "n or timeInterval should be specified ..."
1024
1024
1025 if n != None:
1025 if n != None:
1026 self.n = n
1026 self.n = n
1027 self.__byTime = False
1027 self.__byTime = False
1028 else:
1028 else:
1029 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
1029 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
1030 self.n = 9999
1030 self.n = 9999
1031 self.__byTime = True
1031 self.__byTime = True
1032
1032
1033 if overlapping:
1033 if overlapping:
1034 self.__withOverapping = True
1034 self.__withOverapping = True
1035 else:
1035 else:
1036 self.__withOverapping = False
1036 self.__withOverapping = False
1037 self.__buffer_spc = 0
1037 self.__buffer_spc = 0
1038 self.__buffer_cspc = 0
1038 self.__buffer_cspc = 0
1039 self.__buffer_dc = 0
1039 self.__buffer_dc = 0
1040
1040
1041 self.__profIndex = 0
1041 self.__profIndex = 0
1042
1042
1043 def putData(self, data_spc, data_cspc, data_dc):
1043 def putData(self, data_spc, data_cspc, data_dc):
1044
1044
1045 """
1045 """
1046 Add a profile to the __buffer_spc and increase in one the __profileIndex
1046 Add a profile to the __buffer_spc and increase in one the __profileIndex
1047
1047
1048 """
1048 """
1049
1049
1050 if not self.__withOverapping:
1050 if not self.__withOverapping:
1051 self.__buffer_spc += data_spc
1051 self.__buffer_spc += data_spc
1052
1052
1053 if data_cspc == None:
1053 if data_cspc == None:
1054 self.__buffer_cspc = None
1054 self.__buffer_cspc = None
1055 else:
1055 else:
1056 self.__buffer_cspc += data_cspc
1056 self.__buffer_cspc += data_cspc
1057
1057
1058 if data_dc == None:
1058 if data_dc == None:
1059 self.__buffer_dc = None
1059 self.__buffer_dc = None
1060 else:
1060 else:
1061 self.__buffer_dc += data_dc
1061 self.__buffer_dc += data_dc
1062
1062
1063 self.__profIndex += 1
1063 self.__profIndex += 1
1064 return
1064 return
1065
1065
1066 #Overlapping data
1066 #Overlapping data
1067 nChannels, nFFTPoints, nHeis = data_spc.shape
1067 nChannels, nFFTPoints, nHeis = data_spc.shape
1068 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1068 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
1069 if data_cspc != None:
1069 if data_cspc != None:
1070 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1070 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
1071 if data_dc != None:
1071 if data_dc != None:
1072 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1072 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
1073
1073
1074 #If the buffer is empty then it takes the data value
1074 #If the buffer is empty then it takes the data value
1075 if self.__buffer_spc == None:
1075 if self.__buffer_spc == None:
1076 self.__buffer_spc = data_spc
1076 self.__buffer_spc = data_spc
1077
1077
1078 if data_cspc == None:
1078 if data_cspc == None:
1079 self.__buffer_cspc = None
1079 self.__buffer_cspc = None
1080 else:
1080 else:
1081 self.__buffer_cspc += data_cspc
1081 self.__buffer_cspc += data_cspc
1082
1082
1083 if data_dc == None:
1083 if data_dc == None:
1084 self.__buffer_dc = None
1084 self.__buffer_dc = None
1085 else:
1085 else:
1086 self.__buffer_dc += data_dc
1086 self.__buffer_dc += data_dc
1087
1087
1088 self.__profIndex += 1
1088 self.__profIndex += 1
1089 return
1089 return
1090
1090
1091 #If the buffer length is lower than n then stakcing the data value
1091 #If the buffer length is lower than n then stakcing the data value
1092 if self.__profIndex < self.n:
1092 if self.__profIndex < self.n:
1093 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1093 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
1094
1094
1095 if data_cspc != None:
1095 if data_cspc != None:
1096 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1096 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
1097
1097
1098 if data_dc != None:
1098 if data_dc != None:
1099 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1099 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
1100
1100
1101 self.__profIndex += 1
1101 self.__profIndex += 1
1102 return
1102 return
1103
1103
1104 #If the buffer length is equal to n then replacing the last buffer value with the data value
1104 #If the buffer length is equal to n then replacing the last buffer value with the data value
1105 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1105 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
1106 self.__buffer_spc[self.n-1] = data_spc
1106 self.__buffer_spc[self.n-1] = data_spc
1107
1107
1108 if data_cspc != None:
1108 if data_cspc != None:
1109 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1109 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
1110 self.__buffer_cspc[self.n-1] = data_cspc
1110 self.__buffer_cspc[self.n-1] = data_cspc
1111
1111
1112 if data_dc != None:
1112 if data_dc != None:
1113 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1113 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
1114 self.__buffer_dc[self.n-1] = data_dc
1114 self.__buffer_dc[self.n-1] = data_dc
1115
1115
1116 self.__profIndex = self.n
1116 self.__profIndex = self.n
1117 return
1117 return
1118
1118
1119
1119
1120 def pushData(self):
1120 def pushData(self):
1121 """
1121 """
1122 Return the sum of the last profiles and the profiles used in the sum.
1122 Return the sum of the last profiles and the profiles used in the sum.
1123
1123
1124 Affected:
1124 Affected:
1125
1125
1126 self.__profileIndex
1126 self.__profileIndex
1127
1127
1128 """
1128 """
1129 data_spc = None
1129 data_spc = None
1130 data_cspc = None
1130 data_cspc = None
1131 data_dc = None
1131 data_dc = None
1132
1132
1133 if not self.__withOverapping:
1133 if not self.__withOverapping:
1134 data_spc = self.__buffer_spc
1134 data_spc = self.__buffer_spc
1135 data_cspc = self.__buffer_cspc
1135 data_cspc = self.__buffer_cspc
1136 data_dc = self.__buffer_dc
1136 data_dc = self.__buffer_dc
1137
1137
1138 n = self.__profIndex
1138 n = self.__profIndex
1139
1139
1140 self.__buffer_spc = 0
1140 self.__buffer_spc = 0
1141 self.__buffer_cspc = 0
1141 self.__buffer_cspc = 0
1142 self.__buffer_dc = 0
1142 self.__buffer_dc = 0
1143 self.__profIndex = 0
1143 self.__profIndex = 0
1144
1144
1145 return data_spc, data_cspc, data_dc, n
1145 return data_spc, data_cspc, data_dc, n
1146
1146
1147 #Integration with Overlapping
1147 #Integration with Overlapping
1148 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1148 data_spc = numpy.sum(self.__buffer_spc, axis=0)
1149
1149
1150 if self.__buffer_cspc != None:
1150 if self.__buffer_cspc != None:
1151 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1151 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
1152
1152
1153 if self.__buffer_dc != None:
1153 if self.__buffer_dc != None:
1154 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1154 data_dc = numpy.sum(self.__buffer_dc, axis=0)
1155
1155
1156 n = self.__profIndex
1156 n = self.__profIndex
1157
1157
1158 return data_spc, data_cspc, data_dc, n
1158 return data_spc, data_cspc, data_dc, n
1159
1159
1160 def byProfiles(self, *args):
1160 def byProfiles(self, *args):
1161
1161
1162 self.__dataReady = False
1162 self.__dataReady = False
1163 avgdata_spc = None
1163 avgdata_spc = None
1164 avgdata_cspc = None
1164 avgdata_cspc = None
1165 avgdata_dc = None
1165 avgdata_dc = None
1166 n = None
1166 n = None
1167
1167
1168 self.putData(*args)
1168 self.putData(*args)
1169
1169
1170 if self.__profIndex == self.n:
1170 if self.__profIndex == self.n:
1171
1171
1172 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1172 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1173 self.__dataReady = True
1173 self.__dataReady = True
1174
1174
1175 return avgdata_spc, avgdata_cspc, avgdata_dc
1175 return avgdata_spc, avgdata_cspc, avgdata_dc
1176
1176
1177 def byTime(self, datatime, *args):
1177 def byTime(self, datatime, *args):
1178
1178
1179 self.__dataReady = False
1179 self.__dataReady = False
1180 avgdata_spc = None
1180 avgdata_spc = None
1181 avgdata_cspc = None
1181 avgdata_cspc = None
1182 avgdata_dc = None
1182 avgdata_dc = None
1183 n = None
1183 n = None
1184
1184
1185 self.putData(*args)
1185 self.putData(*args)
1186
1186
1187 if (datatime - self.__initime) >= self.__integrationtime:
1187 if (datatime - self.__initime) >= self.__integrationtime:
1188 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1188 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
1189 self.n = n
1189 self.n = n
1190 self.__dataReady = True
1190 self.__dataReady = True
1191
1191
1192 return avgdata_spc, avgdata_cspc, avgdata_dc
1192 return avgdata_spc, avgdata_cspc, avgdata_dc
1193
1193
1194 def integrate(self, datatime, *args):
1194 def integrate(self, datatime, *args):
1195
1195
1196 if self.__initime == None:
1196 if self.__initime == None:
1197 self.__initime = datatime
1197 self.__initime = datatime
1198
1198
1199 if self.__byTime:
1199 if self.__byTime:
1200 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1200 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
1201 else:
1201 else:
1202 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1202 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
1203
1203
1204 self.__lastdatatime = datatime
1204 self.__lastdatatime = datatime
1205
1205
1206 if avgdata_spc == None:
1206 if avgdata_spc == None:
1207 return None, None, None, None
1207 return None, None, None, None
1208
1208
1209 avgdatatime = self.__initime
1209 avgdatatime = self.__initime
1210 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1210 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
1211
1211
1212 deltatime = datatime -self.__lastdatatime
1212 deltatime = datatime -self.__lastdatatime
1213
1213
1214 if not self.__withOverapping:
1214 if not self.__withOverapping:
1215 self.__initime = datatime
1215 self.__initime = datatime
1216 else:
1216 else:
1217 self.__initime += deltatime
1217 self.__initime += deltatime
1218
1218
1219 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1219 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
1220
1220
1221 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1221 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
1222
1222
1223 if n==1:
1223 if n==1:
1224 dataOut.flagNoData = False
1224 dataOut.flagNoData = False
1225 return
1225 return
1226
1226
1227 if not self.__isConfig:
1227 if not self.__isConfig:
1228 self.setup(n, timeInterval, overlapping)
1228 self.setup(n, timeInterval, overlapping)
1229 self.__isConfig = True
1229 self.__isConfig = True
1230
1230
1231 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1231 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
1232 dataOut.data_spc,
1232 dataOut.data_spc,
1233 dataOut.data_cspc,
1233 dataOut.data_cspc,
1234 dataOut.data_dc)
1234 dataOut.data_dc)
1235
1235
1236 # dataOut.timeInterval *= n
1236 # dataOut.timeInterval *= n
1237 dataOut.flagNoData = True
1237 dataOut.flagNoData = True
1238
1238
1239 if self.__dataReady:
1239 if self.__dataReady:
1240
1240
1241 dataOut.data_spc = avgdata_spc
1241 dataOut.data_spc = avgdata_spc
1242 dataOut.data_cspc = avgdata_cspc
1242 dataOut.data_cspc = avgdata_cspc
1243 dataOut.data_dc = avgdata_dc
1243 dataOut.data_dc = avgdata_dc
1244
1244
1245 dataOut.nIncohInt *= self.n
1245 dataOut.nIncohInt *= self.n
1246 dataOut.utctime = avgdatatime
1246 dataOut.utctime = avgdatatime
1247 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1247 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
1248 dataOut.timeInterval = self.__timeInterval*self.n
1248 dataOut.timeInterval = self.__timeInterval*self.n
1249 dataOut.flagNoData = False
1249 dataOut.flagNoData = False
1250
1250
1251 class ProfileSelector(Operation):
1251 class ProfileSelector(Operation):
1252
1252
1253 profileIndex = None
1253 profileIndex = None
1254 # Tamanho total de los perfiles
1254 # Tamanho total de los perfiles
1255 nProfiles = None
1255 nProfiles = None
1256
1256
1257 def __init__(self):
1257 def __init__(self):
1258
1258
1259 self.profileIndex = 0
1259 self.profileIndex = 0
1260
1260
1261 def incIndex(self):
1261 def incIndex(self):
1262 self.profileIndex += 1
1262 self.profileIndex += 1
1263
1263
1264 if self.profileIndex >= self.nProfiles:
1264 if self.profileIndex >= self.nProfiles:
1265 self.profileIndex = 0
1265 self.profileIndex = 0
1266
1266
1267 def isProfileInRange(self, minIndex, maxIndex):
1267 def isProfileInRange(self, minIndex, maxIndex):
1268
1268
1269 if self.profileIndex < minIndex:
1269 if self.profileIndex < minIndex:
1270 return False
1270 return False
1271
1271
1272 if self.profileIndex > maxIndex:
1272 if self.profileIndex > maxIndex:
1273 return False
1273 return False
1274
1274
1275 return True
1275 return True
1276
1276
1277 def isProfileInList(self, profileList):
1277 def isProfileInList(self, profileList):
1278
1278
1279 if self.profileIndex not in profileList:
1279 if self.profileIndex not in profileList:
1280 return False
1280 return False
1281
1281
1282 return True
1282 return True
1283
1283
1284 def run(self, dataOut, profileList=None, profileRangeList=None):
1284 def run(self, dataOut, profileList=None, profileRangeList=None):
1285
1285
1286 dataOut.flagNoData = True
1286 dataOut.flagNoData = True
1287 self.nProfiles = dataOut.nProfiles
1287 self.nProfiles = dataOut.nProfiles
1288
1288
1289 if profileList != None:
1289 if profileList != None:
1290 if self.isProfileInList(profileList):
1290 if self.isProfileInList(profileList):
1291 dataOut.flagNoData = False
1291 dataOut.flagNoData = False
1292
1292
1293 self.incIndex()
1293 self.incIndex()
1294 return 1
1294 return 1
1295
1295
1296
1296
1297 elif profileRangeList != None:
1297 elif profileRangeList != None:
1298 minIndex = profileRangeList[0]
1298 minIndex = profileRangeList[0]
1299 maxIndex = profileRangeList[1]
1299 maxIndex = profileRangeList[1]
1300 if self.isProfileInRange(minIndex, maxIndex):
1300 if self.isProfileInRange(minIndex, maxIndex):
1301 dataOut.flagNoData = False
1301 dataOut.flagNoData = False
1302
1302
1303 self.incIndex()
1303 self.incIndex()
1304 return 1
1304 return 1
1305
1305
1306 else:
1306 else:
1307 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1307 raise ValueError, "ProfileSelector needs profileList or profileRangeList"
1308
1308
1309 return 0
1309 return 0
1310
1310
1311 class SpectraHeisProc(ProcessingUnit):
1312 def __init__(self):
1313 self.objectDict = {}
1314 # self.buffer = None
1315 # self.firstdatatime = None
1316 # self.profIndex = 0
1317 self.dataOut = SpectraHeis()
1318
1319 def __updateObjFromInput(self):
1320 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()#
1321 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()#
1322 self.dataOut.channelList = self.dataIn.channelList
1323 self.dataOut.heightList = self.dataIn.heightList
1324 # self.dataOut.dtype = self.dataIn.dtype
1325 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
1326 # self.dataOut.nHeights = self.dataIn.nHeights
1327 # self.dataOut.nChannels = self.dataIn.nChannels
1328 self.dataOut.nBaud = self.dataIn.nBaud
1329 self.dataOut.nCode = self.dataIn.nCode
1330 self.dataOut.code = self.dataIn.code
1331 # self.dataOut.nProfiles = 1
1332 # self.dataOut.nProfiles = self.dataOut.nFFTPoints
1333 self.dataOut.nFFTPoints = self.dataIn.nHeights
1334 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
1335 # self.dataOut.flagNoData = self.dataIn.flagNoData
1336 self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock
1337 self.dataOut.utctime = self.dataIn.utctime
1338 # self.dataOut.utctime = self.firstdatatime
1339 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
1340 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
1341 self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
1342 self.dataOut.nCohInt = self.dataIn.nCohInt
1343 self.dataOut.nIncohInt = 1
1344 self.dataOut.ippSeconds= self.dataIn.ippSeconds
1345 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
1346
1347 self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt
1348 # self.dataOut.set=self.dataIn.set
1349 # self.dataOut.deltaHeight=self.dataIn.deltaHeight
1350
1351
1352 def __getFft(self):
1353
1354 fft_volt = numpy.fft.fft(self.dataIn.data, axis=1)
1355 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
1356 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints)
1357 self.dataOut.data_spc = spc
1358
1359 def init(self):
1360
1361 self.dataOut.flagNoData = True
1362
1363 if self.dataIn.type == "SpectraHeis":
1364 self.dataOut.copy(self.dataIn)
1365 return
1366
1367 if self.dataIn.type == "Voltage":
1368 self.__updateObjFromInput()
1369 self.__getFft()
1370 self.dataOut.flagNoData = False
1371
1372 return
1373
1374 raise ValuError, "The type object %s is not valid"%(self.dataIn.type)
1375
1376
1377 def selectChannels(self, channelList):
1378
1379 channelIndexList = []
1380
1381 for channel in channelList:
1382 index = self.dataOut.channelList.index(channel)
1383 channelIndexList.append(index)
1384
1385 self.selectChannelsByIndex(channelIndexList)
1386
1387 def selectChannelsByIndex(self, channelIndexList):
1388 """
1389 Selecciona un bloque de datos en base a canales segun el channelIndexList
1390
1391 Input:
1392 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
1393
1394 Affected:
1395 self.dataOut.data
1396 self.dataOut.channelIndexList
1397 self.dataOut.nChannels
1398 self.dataOut.m_ProcessingHeader.totalSpectra
1399 self.dataOut.systemHeaderObj.numChannels
1400 self.dataOut.m_ProcessingHeader.blockSize
1401
1402 Return:
1403 None
1404 """
1405
1406 for channelIndex in channelIndexList:
1407 if channelIndex not in self.dataOut.channelIndexList:
1408 print channelIndexList
1409 raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex
1410
1411 nChannels = len(channelIndexList)
1412
1413 data_spc = self.dataOut.data_spc[channelIndexList,:]
1414
1415 self.dataOut.data_spc = data_spc
1416 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
1417
1418 return 1
1419
1420 class IncohInt4SpectraHeis(Operation):
1421
1422 __isConfig = False
1423
1424 __profIndex = 0
1425 __withOverapping = False
1426
1427 __byTime = False
1428 __initime = None
1429 __lastdatatime = None
1430 __integrationtime = None
1431
1432 __buffer = None
1433
1434 __dataReady = False
1435
1436 n = None
1437
1438
1439 def __init__(self):
1440
1441 self.__isConfig = False
1442
1443 def setup(self, n=None, timeInterval=None, overlapping=False):
1444 """
1445 Set the parameters of the integration class.
1446
1447 Inputs:
1448
1449 n : Number of coherent integrations
1450 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
1451 overlapping :
1452
1453 """
1454
1455 self.__initime = None
1456 self.__lastdatatime = 0
1457 self.__buffer = None
1458 self.__dataReady = False
1459
1460
1461 if n == None and timeInterval == None:
1462 raise ValueError, "n or timeInterval should be specified ..."
1463
1464 if n != None:
1465 self.n = n
1466 self.__byTime = False
1467 else:
1468 self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line
1469 self.n = 9999
1470 self.__byTime = True
1471
1472 if overlapping:
1473 self.__withOverapping = True
1474 self.__buffer = None
1475 else:
1476 self.__withOverapping = False
1477 self.__buffer = 0
1478
1479 self.__profIndex = 0
1480
1481 def putData(self, data):
1482
1483 """
1484 Add a profile to the __buffer and increase in one the __profileIndex
1485
1486 """
1487
1488 if not self.__withOverapping:
1489 self.__buffer += data.copy()
1490 self.__profIndex += 1
1491 return
1492
1493 #Overlapping data
1494 nChannels, nHeis = data.shape
1495 data = numpy.reshape(data, (1, nChannels, nHeis))
1496
1497 #If the buffer is empty then it takes the data value
1498 if self.__buffer == None:
1499 self.__buffer = data
1500 self.__profIndex += 1
1501 return
1502
1503 #If the buffer length is lower than n then stakcing the data value
1504 if self.__profIndex < self.n:
1505 self.__buffer = numpy.vstack((self.__buffer, data))
1506 self.__profIndex += 1
1507 return
1508
1509 #If the buffer length is equal to n then replacing the last buffer value with the data value
1510 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
1511 self.__buffer[self.n-1] = data
1512 self.__profIndex = self.n
1513 return
1514
1515
1516 def pushData(self):
1517 """
1518 Return the sum of the last profiles and the profiles used in the sum.
1519
1520 Affected:
1521
1522 self.__profileIndex
1523
1524 """
1525
1526 if not self.__withOverapping:
1527 data = self.__buffer
1528 n = self.__profIndex
1529
1530 self.__buffer = 0
1531 self.__profIndex = 0
1532
1533 return data, n
1534
1535 #Integration with Overlapping
1536 data = numpy.sum(self.__buffer, axis=0)
1537 n = self.__profIndex
1538
1539 return data, n
1540
1541 def byProfiles(self, data):
1542
1543 self.__dataReady = False
1544 avgdata = None
1545 n = None
1546
1547 self.putData(data)
1548
1549 if self.__profIndex == self.n:
1550
1551 avgdata, n = self.pushData()
1552 self.__dataReady = True
1553
1554 return avgdata
1555
1556 def byTime(self, data, datatime):
1557
1558 self.__dataReady = False
1559 avgdata = None
1560 n = None
1561
1562 self.putData(data)
1563
1564 if (datatime - self.__initime) >= self.__integrationtime:
1565 avgdata, n = self.pushData()
1566 self.n = n
1567 self.__dataReady = True
1568
1569 return avgdata
1570
1571 def integrate(self, data, datatime=None):
1572
1573 if self.__initime == None:
1574 self.__initime = datatime
1575
1576 if self.__byTime:
1577 avgdata = self.byTime(data, datatime)
1578 else:
1579 avgdata = self.byProfiles(data)
1580
1581
1582 self.__lastdatatime = datatime
1583
1584 if avgdata == None:
1585 return None, None
1586
1587 avgdatatime = self.__initime
1588
1589 deltatime = datatime -self.__lastdatatime
1590
1591 if not self.__withOverapping:
1592 self.__initime = datatime
1593 else:
1594 self.__initime += deltatime
1595
1596 return avgdata, avgdatatime
1597
1598 def run(self, dataOut, **kwargs):
1599
1600 if not self.__isConfig:
1601 self.setup(**kwargs)
1602 self.__isConfig = True
1603
1604 avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime)
1605
1606 # dataOut.timeInterval *= n
1607 dataOut.flagNoData = True
1608
1609 if self.__dataReady:
1610 dataOut.data_spc = avgdata
1611 dataOut.nIncohInt *= self.n
1612 # dataOut.nCohInt *= self.n
1613 dataOut.utctime = avgdatatime
1614 dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt
1615 # dataOut.timeInterval = self.__timeInterval*self.n
1616 dataOut.flagNoData = False No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now