##// END OF EJS Templates
-Bug fixed: selecting channels and cross pairs...
Miguel Valdez -
r612:d0a641be5ae3
parent child
Show More
@@ -1,1363 +1,1363
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4
4
5 from figure import Figure, isRealtime
5 from figure import Figure, isRealtime
6 from plotting_codes import *
6 from plotting_codes import *
7
7
8 class MomentsPlot(Figure):
8 class MomentsPlot(Figure):
9
9
10 isConfig = None
10 isConfig = None
11 __nsubplots = None
11 __nsubplots = None
12
12
13 WIDTHPROF = None
13 WIDTHPROF = None
14 HEIGHTPROF = None
14 HEIGHTPROF = None
15 PREFIX = 'prm'
15 PREFIX = 'prm'
16
16
17 def __init__(self):
17 def __init__(self):
18
18
19 self.isConfig = False
19 self.isConfig = False
20 self.__nsubplots = 1
20 self.__nsubplots = 1
21
21
22 self.WIDTH = 280
22 self.WIDTH = 280
23 self.HEIGHT = 250
23 self.HEIGHT = 250
24 self.WIDTHPROF = 120
24 self.WIDTHPROF = 120
25 self.HEIGHTPROF = 0
25 self.HEIGHTPROF = 0
26 self.counter_imagwr = 0
26 self.counter_imagwr = 0
27
27
28 self.PLOT_CODE = MOMENTS_CODE
28 self.PLOT_CODE = MOMENTS_CODE
29
29
30 self.FTP_WEI = None
30 self.FTP_WEI = None
31 self.EXP_CODE = None
31 self.EXP_CODE = None
32 self.SUB_EXP_CODE = None
32 self.SUB_EXP_CODE = None
33 self.PLOT_POS = None
33 self.PLOT_POS = None
34
34
35 def getSubplots(self):
35 def getSubplots(self):
36
36
37 ncol = int(numpy.sqrt(self.nplots)+0.9)
37 ncol = int(numpy.sqrt(self.nplots)+0.9)
38 nrow = int(self.nplots*1./ncol + 0.9)
38 nrow = int(self.nplots*1./ncol + 0.9)
39
39
40 return nrow, ncol
40 return nrow, ncol
41
41
42 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
42 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
43
43
44 self.__showprofile = showprofile
44 self.__showprofile = showprofile
45 self.nplots = nplots
45 self.nplots = nplots
46
46
47 ncolspan = 1
47 ncolspan = 1
48 colspan = 1
48 colspan = 1
49 if showprofile:
49 if showprofile:
50 ncolspan = 3
50 ncolspan = 3
51 colspan = 2
51 colspan = 2
52 self.__nsubplots = 2
52 self.__nsubplots = 2
53
53
54 self.createFigure(id = id,
54 self.createFigure(id = id,
55 wintitle = wintitle,
55 wintitle = wintitle,
56 widthplot = self.WIDTH + self.WIDTHPROF,
56 widthplot = self.WIDTH + self.WIDTHPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 heightplot = self.HEIGHT + self.HEIGHTPROF,
58 show=show)
58 show=show)
59
59
60 nrow, ncol = self.getSubplots()
60 nrow, ncol = self.getSubplots()
61
61
62 counter = 0
62 counter = 0
63 for y in range(nrow):
63 for y in range(nrow):
64 for x in range(ncol):
64 for x in range(ncol):
65
65
66 if counter >= self.nplots:
66 if counter >= self.nplots:
67 break
67 break
68
68
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
70
70
71 if showprofile:
71 if showprofile:
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
73
73
74 counter += 1
74 counter += 1
75
75
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
76 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
77 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
78 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
79 server=None, folder=None, username=None, password=None,
79 server=None, folder=None, username=None, password=None,
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
80 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
81
81
82 """
82 """
83
83
84 Input:
84 Input:
85 dataOut :
85 dataOut :
86 id :
86 id :
87 wintitle :
87 wintitle :
88 channelList :
88 channelList :
89 showProfile :
89 showProfile :
90 xmin : None,
90 xmin : None,
91 xmax : None,
91 xmax : None,
92 ymin : None,
92 ymin : None,
93 ymax : None,
93 ymax : None,
94 zmin : None,
94 zmin : None,
95 zmax : None
95 zmax : None
96 """
96 """
97
97
98 if dataOut.flagNoData:
98 if dataOut.flagNoData:
99 return None
99 return None
100
100
101 if realtime:
101 if realtime:
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
102 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 print 'Skipping this plot function'
103 print 'Skipping this plot function'
104 return
104 return
105
105
106 if channelList == None:
106 if channelList == None:
107 channelIndexList = dataOut.channelIndexList
107 channelIndexList = dataOut.channelIndexList
108 else:
108 else:
109 channelIndexList = []
109 channelIndexList = []
110 for channel in channelList:
110 for channel in channelList:
111 if channel not in dataOut.channelList:
111 if channel not in dataOut.channelList:
112 raise ValueError, "Channel %d is not in dataOut.channelList"
112 raise ValueError, "Channel %d is not in dataOut.channelList"
113 channelIndexList.append(dataOut.channelList.index(channel))
113 channelIndexList.append(dataOut.channelList.index(channel))
114
114
115 factor = dataOut.normFactor
115 factor = dataOut.normFactor
116 x = dataOut.abscissaList
116 x = dataOut.abscissaList
117 y = dataOut.heightList
117 y = dataOut.heightList
118
118
119 z = dataOut.data_pre[channelIndexList,:,:]/factor
119 z = dataOut.data_pre[channelIndexList,:,:]/factor
120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
120 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
121 avg = numpy.average(z, axis=1)
121 avg = numpy.average(z, axis=1)
122 noise = dataOut.noise/factor
122 noise = dataOut.noise/factor
123
123
124 zdB = 10*numpy.log10(z)
124 zdB = 10*numpy.log10(z)
125 avgdB = 10*numpy.log10(avg)
125 avgdB = 10*numpy.log10(avg)
126 noisedB = 10*numpy.log10(noise)
126 noisedB = 10*numpy.log10(noise)
127
127
128 #thisDatetime = dataOut.datatime
128 #thisDatetime = dataOut.datatime
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 title = wintitle + " Parameters"
130 title = wintitle + " Parameters"
131 xlabel = "Velocity (m/s)"
131 xlabel = "Velocity (m/s)"
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 if not self.isConfig:
134 if not self.isConfig:
135
135
136 nplots = len(channelIndexList)
136 nplots = len(channelIndexList)
137
137
138 self.setup(id=id,
138 self.setup(id=id,
139 nplots=nplots,
139 nplots=nplots,
140 wintitle=wintitle,
140 wintitle=wintitle,
141 showprofile=showprofile,
141 showprofile=showprofile,
142 show=show)
142 show=show)
143
143
144 if xmin == None: xmin = numpy.nanmin(x)
144 if xmin == None: xmin = numpy.nanmin(x)
145 if xmax == None: xmax = numpy.nanmax(x)
145 if xmax == None: xmax = numpy.nanmax(x)
146 if ymin == None: ymin = numpy.nanmin(y)
146 if ymin == None: ymin = numpy.nanmin(y)
147 if ymax == None: ymax = numpy.nanmax(y)
147 if ymax == None: ymax = numpy.nanmax(y)
148 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
148 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
149 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
149 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
150
150
151 self.FTP_WEI = ftp_wei
151 self.FTP_WEI = ftp_wei
152 self.EXP_CODE = exp_code
152 self.EXP_CODE = exp_code
153 self.SUB_EXP_CODE = sub_exp_code
153 self.SUB_EXP_CODE = sub_exp_code
154 self.PLOT_POS = plot_pos
154 self.PLOT_POS = plot_pos
155
155
156 self.isConfig = True
156 self.isConfig = True
157
157
158 self.setWinTitle(title)
158 self.setWinTitle(title)
159
159
160 for i in range(self.nplots):
160 for i in range(self.nplots):
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
162 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime)
163 axes = self.axesList[i*self.__nsubplots]
163 axes = self.axesList[i*self.__nsubplots]
164 axes.pcolor(x, y, zdB[i,:,:],
164 axes.pcolor(x, y, zdB[i,:,:],
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 xlabel=xlabel, ylabel=ylabel, title=title,
166 xlabel=xlabel, ylabel=ylabel, title=title,
167 ticksize=9, cblabel='')
167 ticksize=9, cblabel='')
168 #Mean Line
168 #Mean Line
169 mean = dataOut.data_param[i, 1, :]
169 mean = dataOut.data_param[i, 1, :]
170 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
170 axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1)
171
171
172 if self.__showprofile:
172 if self.__showprofile:
173 axes = self.axesList[i*self.__nsubplots +1]
173 axes = self.axesList[i*self.__nsubplots +1]
174 axes.pline(avgdB[i], y,
174 axes.pline(avgdB[i], y,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
175 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
176 xlabel='dB', ylabel='', title='',
176 xlabel='dB', ylabel='', title='',
177 ytick_visible=False,
177 ytick_visible=False,
178 grid='x')
178 grid='x')
179
179
180 noiseline = numpy.repeat(noisedB[i], len(y))
180 noiseline = numpy.repeat(noisedB[i], len(y))
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
181 axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
182
182
183 self.draw()
183 self.draw()
184
184
185 self.save(figpath=figpath,
185 self.save(figpath=figpath,
186 figfile=figfile,
186 figfile=figfile,
187 save=save,
187 save=save,
188 ftp=ftp,
188 ftp=ftp,
189 wr_period=wr_period,
189 wr_period=wr_period,
190 thisDatetime=thisDatetime)
190 thisDatetime=thisDatetime)
191
191
192
192
193
193
194 class SkyMapPlot(Figure):
194 class SkyMapPlot(Figure):
195
195
196 __isConfig = None
196 __isConfig = None
197 __nsubplots = None
197 __nsubplots = None
198
198
199 WIDTHPROF = None
199 WIDTHPROF = None
200 HEIGHTPROF = None
200 HEIGHTPROF = None
201 PREFIX = 'mmap'
201 PREFIX = 'mmap'
202
202
203 def __init__(self):
203 def __init__(self):
204
204
205 self.__isConfig = False
205 self.__isConfig = False
206 self.__nsubplots = 1
206 self.__nsubplots = 1
207
207
208 # self.WIDTH = 280
208 # self.WIDTH = 280
209 # self.HEIGHT = 250
209 # self.HEIGHT = 250
210 self.WIDTH = 600
210 self.WIDTH = 600
211 self.HEIGHT = 600
211 self.HEIGHT = 600
212 self.WIDTHPROF = 120
212 self.WIDTHPROF = 120
213 self.HEIGHTPROF = 0
213 self.HEIGHTPROF = 0
214 self.counter_imagwr = 0
214 self.counter_imagwr = 0
215
215
216 self.PLOT_CODE = MSKYMAP_CODE
216 self.PLOT_CODE = MSKYMAP_CODE
217
217
218 self.FTP_WEI = None
218 self.FTP_WEI = None
219 self.EXP_CODE = None
219 self.EXP_CODE = None
220 self.SUB_EXP_CODE = None
220 self.SUB_EXP_CODE = None
221 self.PLOT_POS = None
221 self.PLOT_POS = None
222
222
223 def getSubplots(self):
223 def getSubplots(self):
224
224
225 ncol = int(numpy.sqrt(self.nplots)+0.9)
225 ncol = int(numpy.sqrt(self.nplots)+0.9)
226 nrow = int(self.nplots*1./ncol + 0.9)
226 nrow = int(self.nplots*1./ncol + 0.9)
227
227
228 return nrow, ncol
228 return nrow, ncol
229
229
230 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
230 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
231
231
232 self.__showprofile = showprofile
232 self.__showprofile = showprofile
233 self.nplots = nplots
233 self.nplots = nplots
234
234
235 ncolspan = 1
235 ncolspan = 1
236 colspan = 1
236 colspan = 1
237
237
238 self.createFigure(id = id,
238 self.createFigure(id = id,
239 wintitle = wintitle,
239 wintitle = wintitle,
240 widthplot = self.WIDTH, #+ self.WIDTHPROF,
240 widthplot = self.WIDTH, #+ self.WIDTHPROF,
241 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
241 heightplot = self.HEIGHT,# + self.HEIGHTPROF,
242 show=show)
242 show=show)
243
243
244 nrow, ncol = 1,1
244 nrow, ncol = 1,1
245 counter = 0
245 counter = 0
246 x = 0
246 x = 0
247 y = 0
247 y = 0
248 self.addAxes(1, 1, 0, 0, 1, 1, True)
248 self.addAxes(1, 1, 0, 0, 1, 1, True)
249
249
250 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
250 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
251 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
251 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
252 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
252 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
253 server=None, folder=None, username=None, password=None,
253 server=None, folder=None, username=None, password=None,
254 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
254 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
255
255
256 """
256 """
257
257
258 Input:
258 Input:
259 dataOut :
259 dataOut :
260 id :
260 id :
261 wintitle :
261 wintitle :
262 channelList :
262 channelList :
263 showProfile :
263 showProfile :
264 xmin : None,
264 xmin : None,
265 xmax : None,
265 xmax : None,
266 ymin : None,
266 ymin : None,
267 ymax : None,
267 ymax : None,
268 zmin : None,
268 zmin : None,
269 zmax : None
269 zmax : None
270 """
270 """
271
271
272 arrayParameters = dataOut.data_param[0,:]
272 arrayParameters = dataOut.data_param[0,:]
273 error = arrayParameters[:,-1]
273 error = arrayParameters[:,-1]
274 indValid = numpy.where(error == 0)[0]
274 indValid = numpy.where(error == 0)[0]
275 finalMeteor = arrayParameters[indValid,:]
275 finalMeteor = arrayParameters[indValid,:]
276 finalAzimuth = finalMeteor[:,4]
276 finalAzimuth = finalMeteor[:,4]
277 finalZenith = finalMeteor[:,5]
277 finalZenith = finalMeteor[:,5]
278
278
279 x = finalAzimuth*numpy.pi/180
279 x = finalAzimuth*numpy.pi/180
280 y = finalZenith
280 y = finalZenith
281
281
282
282
283 #thisDatetime = dataOut.datatime
283 #thisDatetime = dataOut.datatime
284 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
284 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
285 title = wintitle + " Parameters"
285 title = wintitle + " Parameters"
286 xlabel = "Zonal Zenith Angle (deg) "
286 xlabel = "Zonal Zenith Angle (deg) "
287 ylabel = "Meridional Zenith Angle (deg)"
287 ylabel = "Meridional Zenith Angle (deg)"
288
288
289 if not self.__isConfig:
289 if not self.__isConfig:
290
290
291 nplots = 1
291 nplots = 1
292
292
293 self.setup(id=id,
293 self.setup(id=id,
294 nplots=nplots,
294 nplots=nplots,
295 wintitle=wintitle,
295 wintitle=wintitle,
296 showprofile=showprofile,
296 showprofile=showprofile,
297 show=show)
297 show=show)
298
298
299 self.FTP_WEI = ftp_wei
299 self.FTP_WEI = ftp_wei
300 self.EXP_CODE = exp_code
300 self.EXP_CODE = exp_code
301 self.SUB_EXP_CODE = sub_exp_code
301 self.SUB_EXP_CODE = sub_exp_code
302 self.PLOT_POS = plot_pos
302 self.PLOT_POS = plot_pos
303 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
303 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
304 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
304 self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
305 self.__isConfig = True
305 self.__isConfig = True
306
306
307 self.setWinTitle(title)
307 self.setWinTitle(title)
308
308
309 i = 0
309 i = 0
310 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
310 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
311
311
312 axes = self.axesList[i*self.__nsubplots]
312 axes = self.axesList[i*self.__nsubplots]
313 nevents = axes.x_buffer.shape[0] + x.shape[0]
313 nevents = axes.x_buffer.shape[0] + x.shape[0]
314 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
314 title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents)
315 axes.polar(x, y,
315 axes.polar(x, y,
316 title=title, xlabel=xlabel, ylabel=ylabel,
316 title=title, xlabel=xlabel, ylabel=ylabel,
317 ticksize=9, cblabel='')
317 ticksize=9, cblabel='')
318
318
319 self.draw()
319 self.draw()
320
320
321 self.save(figpath=figpath,
321 self.save(figpath=figpath,
322 figfile=figfile,
322 figfile=figfile,
323 save=save,
323 save=save,
324 ftp=ftp,
324 ftp=ftp,
325 wr_period=wr_period,
325 wr_period=wr_period,
326 thisDatetime=thisDatetime)
326 thisDatetime=thisDatetime)
327
327
328
328
329 class WindProfilerPlot(Figure):
329 class WindProfilerPlot(Figure):
330
330
331 __isConfig = None
331 __isConfig = None
332 __nsubplots = None
332 __nsubplots = None
333
333
334 WIDTHPROF = None
334 WIDTHPROF = None
335 HEIGHTPROF = None
335 HEIGHTPROF = None
336 PREFIX = 'wind'
336 PREFIX = 'wind'
337
337
338 def __init__(self):
338 def __init__(self):
339
339
340 self.timerange = None
340 self.timerange = None
341 self.__isConfig = False
341 self.__isConfig = False
342 self.__nsubplots = 1
342 self.__nsubplots = 1
343
343
344 self.WIDTH = 800
344 self.WIDTH = 800
345 self.HEIGHT = 150
345 self.HEIGHT = 150
346 self.WIDTHPROF = 120
346 self.WIDTHPROF = 120
347 self.HEIGHTPROF = 0
347 self.HEIGHTPROF = 0
348 self.counter_imagwr = 0
348 self.counter_imagwr = 0
349
349
350 self.PLOT_CODE = WIND_CODE
350 self.PLOT_CODE = WIND_CODE
351
351
352 self.FTP_WEI = None
352 self.FTP_WEI = None
353 self.EXP_CODE = None
353 self.EXP_CODE = None
354 self.SUB_EXP_CODE = None
354 self.SUB_EXP_CODE = None
355 self.PLOT_POS = None
355 self.PLOT_POS = None
356 self.tmin = None
356 self.tmin = None
357 self.tmax = None
357 self.tmax = None
358
358
359 self.xmin = None
359 self.xmin = None
360 self.xmax = None
360 self.xmax = None
361
361
362 self.figfile = None
362 self.figfile = None
363
363
364 def getSubplots(self):
364 def getSubplots(self):
365
365
366 ncol = 1
366 ncol = 1
367 nrow = self.nplots
367 nrow = self.nplots
368
368
369 return nrow, ncol
369 return nrow, ncol
370
370
371 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
371 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
372
372
373 self.__showprofile = showprofile
373 self.__showprofile = showprofile
374 self.nplots = nplots
374 self.nplots = nplots
375
375
376 ncolspan = 1
376 ncolspan = 1
377 colspan = 1
377 colspan = 1
378
378
379 self.createFigure(id = id,
379 self.createFigure(id = id,
380 wintitle = wintitle,
380 wintitle = wintitle,
381 widthplot = self.WIDTH + self.WIDTHPROF,
381 widthplot = self.WIDTH + self.WIDTHPROF,
382 heightplot = self.HEIGHT + self.HEIGHTPROF,
382 heightplot = self.HEIGHT + self.HEIGHTPROF,
383 show=show)
383 show=show)
384
384
385 nrow, ncol = self.getSubplots()
385 nrow, ncol = self.getSubplots()
386
386
387 counter = 0
387 counter = 0
388 for y in range(nrow):
388 for y in range(nrow):
389 if counter >= self.nplots:
389 if counter >= self.nplots:
390 break
390 break
391
391
392 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
392 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
393 counter += 1
393 counter += 1
394
394
395 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
395 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False',
396 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
396 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
397 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
397 zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None,
398 timerange=None, SNRthresh = None,
398 timerange=None, SNRthresh = None,
399 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
399 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
400 server=None, folder=None, username=None, password=None,
400 server=None, folder=None, username=None, password=None,
401 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
401 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
402 """
402 """
403
403
404 Input:
404 Input:
405 dataOut :
405 dataOut :
406 id :
406 id :
407 wintitle :
407 wintitle :
408 channelList :
408 channelList :
409 showProfile :
409 showProfile :
410 xmin : None,
410 xmin : None,
411 xmax : None,
411 xmax : None,
412 ymin : None,
412 ymin : None,
413 ymax : None,
413 ymax : None,
414 zmin : None,
414 zmin : None,
415 zmax : None
415 zmax : None
416 """
416 """
417
417
418 if channelList == None:
418 if channelList == None:
419 channelIndexList = dataOut.channelIndexList
419 channelIndexList = dataOut.channelIndexList
420 else:
420 else:
421 channelIndexList = []
421 channelIndexList = []
422 for channel in channelList:
422 for channel in channelList:
423 if channel not in dataOut.channelList:
423 if channel not in dataOut.channelList:
424 raise ValueError, "Channel %d is not in dataOut.channelList"
424 raise ValueError, "Channel %d is not in dataOut.channelList"
425 channelIndexList.append(dataOut.channelList.index(channel))
425 channelIndexList.append(dataOut.channelList.index(channel))
426
426
427 # if timerange != None:
427 # if timerange is not None:
428 # self.timerange = timerange
428 # self.timerange = timerange
429 #
429 #
430 # tmin = None
430 # tmin = None
431 # tmax = None
431 # tmax = None
432
432
433 x = dataOut.getTimeRange1()
433 x = dataOut.getTimeRange1()
434 # y = dataOut.heightList
434 # y = dataOut.heightList
435 y = dataOut.heightList
435 y = dataOut.heightList
436
436
437 z = dataOut.data_output.copy()
437 z = dataOut.data_output.copy()
438 nplots = z.shape[0] #Number of wind dimensions estimated
438 nplots = z.shape[0] #Number of wind dimensions estimated
439 nplotsw = nplots
439 nplotsw = nplots
440
440
441 #If there is a SNR function defined
441 #If there is a SNR function defined
442 if dataOut.data_SNR != None:
442 if dataOut.data_SNR is not None:
443 nplots += 1
443 nplots += 1
444 SNR = dataOut.data_SNR
444 SNR = dataOut.data_SNR
445 SNRavg = numpy.average(SNR, axis=0)
445 SNRavg = numpy.average(SNR, axis=0)
446
446
447 SNRdB = 10*numpy.log10(SNR)
447 SNRdB = 10*numpy.log10(SNR)
448 SNRavgdB = 10*numpy.log10(SNRavg)
448 SNRavgdB = 10*numpy.log10(SNRavg)
449
449
450 if SNRthresh == None: SNRthresh = -5.0
450 if SNRthresh == None: SNRthresh = -5.0
451 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
451 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
452
452
453 for i in range(nplotsw):
453 for i in range(nplotsw):
454 z[i,ind] = numpy.nan
454 z[i,ind] = numpy.nan
455
455
456
456
457 # showprofile = False
457 # showprofile = False
458 # thisDatetime = dataOut.datatime
458 # thisDatetime = dataOut.datatime
459 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
459 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
460 title = wintitle + "Wind"
460 title = wintitle + "Wind"
461 xlabel = ""
461 xlabel = ""
462 ylabel = "Range (Km)"
462 ylabel = "Range (Km)"
463
463
464 if not self.__isConfig:
464 if not self.__isConfig:
465
465
466 self.setup(id=id,
466 self.setup(id=id,
467 nplots=nplots,
467 nplots=nplots,
468 wintitle=wintitle,
468 wintitle=wintitle,
469 showprofile=showprofile,
469 showprofile=showprofile,
470 show=show)
470 show=show)
471
471
472 if timerange != None:
472 if timerange is not None:
473 self.timerange = timerange
473 self.timerange = timerange
474
474
475 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
475 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
476
476
477 if ymin == None: ymin = numpy.nanmin(y)
477 if ymin == None: ymin = numpy.nanmin(y)
478 if ymax == None: ymax = numpy.nanmax(y)
478 if ymax == None: ymax = numpy.nanmax(y)
479
479
480 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
480 if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:]))
481 #if numpy.isnan(zmax): zmax = 50
481 #if numpy.isnan(zmax): zmax = 50
482 if zmin == None: zmin = -zmax
482 if zmin == None: zmin = -zmax
483
483
484 if nplotsw == 3:
484 if nplotsw == 3:
485 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
485 if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:]))
486 if zmin_ver == None: zmin_ver = -zmax_ver
486 if zmin_ver == None: zmin_ver = -zmax_ver
487
487
488 if dataOut.data_SNR != None:
488 if dataOut.data_SNR is not None:
489 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
489 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
490 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
490 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
491
491
492
492
493 self.FTP_WEI = ftp_wei
493 self.FTP_WEI = ftp_wei
494 self.EXP_CODE = exp_code
494 self.EXP_CODE = exp_code
495 self.SUB_EXP_CODE = sub_exp_code
495 self.SUB_EXP_CODE = sub_exp_code
496 self.PLOT_POS = plot_pos
496 self.PLOT_POS = plot_pos
497
497
498 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
498 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
499 self.__isConfig = True
499 self.__isConfig = True
500 self.figfile = figfile
500 self.figfile = figfile
501
501
502 self.setWinTitle(title)
502 self.setWinTitle(title)
503
503
504 if ((self.xmax - x[1]) < (x[1]-x[0])):
504 if ((self.xmax - x[1]) < (x[1]-x[0])):
505 x[1] = self.xmax
505 x[1] = self.xmax
506
506
507 strWind = ['Zonal', 'Meridional', 'Vertical']
507 strWind = ['Zonal', 'Meridional', 'Vertical']
508 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
508 strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)']
509 zmaxVector = [zmax, zmax, zmax_ver]
509 zmaxVector = [zmax, zmax, zmax_ver]
510 zminVector = [zmin, zmin, zmin_ver]
510 zminVector = [zmin, zmin, zmin_ver]
511 windFactor = [1,1,100]
511 windFactor = [1,1,100]
512
512
513 for i in range(nplotsw):
513 for i in range(nplotsw):
514
514
515 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
515 title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
516 axes = self.axesList[i*self.__nsubplots]
516 axes = self.axesList[i*self.__nsubplots]
517
517
518 z1 = z[i,:].reshape((1,-1))*windFactor[i]
518 z1 = z[i,:].reshape((1,-1))*windFactor[i]
519
519
520 axes.pcolorbuffer(x, y, z1,
520 axes.pcolorbuffer(x, y, z1,
521 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
521 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
522 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
522 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
523 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
523 ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" )
524
524
525 if dataOut.data_SNR != None:
525 if dataOut.data_SNR is not None:
526 i += 1
526 i += 1
527 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
527 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
528 axes = self.axesList[i*self.__nsubplots]
528 axes = self.axesList[i*self.__nsubplots]
529
529
530 SNRavgdB = SNRavgdB.reshape((1,-1))
530 SNRavgdB = SNRavgdB.reshape((1,-1))
531
531
532 axes.pcolorbuffer(x, y, SNRavgdB,
532 axes.pcolorbuffer(x, y, SNRavgdB,
533 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
533 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
534 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
534 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
535 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
535 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
536
536
537 self.draw()
537 self.draw()
538
538
539 if x[1] >= self.axesList[0].xmax:
539 if x[1] >= self.axesList[0].xmax:
540 self.counter_imagwr = wr_period
540 self.counter_imagwr = wr_period
541 self.__isConfig = False
541 self.__isConfig = False
542 self.figfile = None
542 self.figfile = None
543
543
544 self.save(figpath=figpath,
544 self.save(figpath=figpath,
545 figfile=figfile,
545 figfile=figfile,
546 save=save,
546 save=save,
547 ftp=ftp,
547 ftp=ftp,
548 wr_period=wr_period,
548 wr_period=wr_period,
549 thisDatetime=thisDatetime,
549 thisDatetime=thisDatetime,
550 update_figfile=False)
550 update_figfile=False)
551
551
552
552
553 class ParametersPlot(Figure):
553 class ParametersPlot(Figure):
554
554
555 __isConfig = None
555 __isConfig = None
556 __nsubplots = None
556 __nsubplots = None
557
557
558 WIDTHPROF = None
558 WIDTHPROF = None
559 HEIGHTPROF = None
559 HEIGHTPROF = None
560 PREFIX = 'prm'
560 PREFIX = 'prm'
561
561
562 def __init__(self):
562 def __init__(self):
563
563
564 self.timerange = 2*60*60
564 self.timerange = 2*60*60
565 self.__isConfig = False
565 self.__isConfig = False
566 self.__nsubplots = 1
566 self.__nsubplots = 1
567
567
568 self.WIDTH = 800
568 self.WIDTH = 800
569 self.HEIGHT = 150
569 self.HEIGHT = 150
570 self.WIDTHPROF = 120
570 self.WIDTHPROF = 120
571 self.HEIGHTPROF = 0
571 self.HEIGHTPROF = 0
572 self.counter_imagwr = 0
572 self.counter_imagwr = 0
573
573
574 self.PLOT_CODE = PARMS_CODE
574 self.PLOT_CODE = PARMS_CODE
575
575
576 self.FTP_WEI = None
576 self.FTP_WEI = None
577 self.EXP_CODE = None
577 self.EXP_CODE = None
578 self.SUB_EXP_CODE = None
578 self.SUB_EXP_CODE = None
579 self.PLOT_POS = None
579 self.PLOT_POS = None
580 self.tmin = None
580 self.tmin = None
581 self.tmax = None
581 self.tmax = None
582
582
583 self.xmin = None
583 self.xmin = None
584 self.xmax = None
584 self.xmax = None
585
585
586 self.figfile = None
586 self.figfile = None
587
587
588 def getSubplots(self):
588 def getSubplots(self):
589
589
590 ncol = 1
590 ncol = 1
591 nrow = self.nplots
591 nrow = self.nplots
592
592
593 return nrow, ncol
593 return nrow, ncol
594
594
595 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
595 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
596
596
597 self.__showprofile = showprofile
597 self.__showprofile = showprofile
598 self.nplots = nplots
598 self.nplots = nplots
599
599
600 ncolspan = 1
600 ncolspan = 1
601 colspan = 1
601 colspan = 1
602
602
603 self.createFigure(id = id,
603 self.createFigure(id = id,
604 wintitle = wintitle,
604 wintitle = wintitle,
605 widthplot = self.WIDTH + self.WIDTHPROF,
605 widthplot = self.WIDTH + self.WIDTHPROF,
606 heightplot = self.HEIGHT + self.HEIGHTPROF,
606 heightplot = self.HEIGHT + self.HEIGHTPROF,
607 show=show)
607 show=show)
608
608
609 nrow, ncol = self.getSubplots()
609 nrow, ncol = self.getSubplots()
610
610
611 counter = 0
611 counter = 0
612 for y in range(nrow):
612 for y in range(nrow):
613 for x in range(ncol):
613 for x in range(ncol):
614
614
615 if counter >= self.nplots:
615 if counter >= self.nplots:
616 break
616 break
617
617
618 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
618 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
619
619
620 if showprofile:
620 if showprofile:
621 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
621 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
622
622
623 counter += 1
623 counter += 1
624
624
625 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
625 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
626 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
626 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None,
627 parameterIndex = None, onlyPositive = False,
627 parameterIndex = None, onlyPositive = False,
628 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
628 SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False,
629 DOP = True,
629 DOP = True,
630 zlabel = "", parameterName = "", parameterObject = "data_param",
630 zlabel = "", parameterName = "", parameterObject = "data_param",
631 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
631 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
632 server=None, folder=None, username=None, password=None,
632 server=None, folder=None, username=None, password=None,
633 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
633 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
634
634
635 """
635 """
636
636
637 Input:
637 Input:
638 dataOut :
638 dataOut :
639 id :
639 id :
640 wintitle :
640 wintitle :
641 channelList :
641 channelList :
642 showProfile :
642 showProfile :
643 xmin : None,
643 xmin : None,
644 xmax : None,
644 xmax : None,
645 ymin : None,
645 ymin : None,
646 ymax : None,
646 ymax : None,
647 zmin : None,
647 zmin : None,
648 zmax : None
648 zmax : None
649 """
649 """
650
650
651 data_param = getattr(dataOut, parameterObject)
651 data_param = getattr(dataOut, parameterObject)
652
652
653 if channelList == None:
653 if channelList == None:
654 channelIndexList = numpy.arange(data_param.shape[0])
654 channelIndexList = numpy.arange(data_param.shape[0])
655 else:
655 else:
656 channelIndexList = numpy.array(channelList)
656 channelIndexList = numpy.array(channelList)
657
657
658 nchan = len(channelIndexList) #Number of channels being plotted
658 nchan = len(channelIndexList) #Number of channels being plotted
659
659
660 if nchan < 1:
660 if nchan < 1:
661 return
661 return
662
662
663 nGraphsByChannel = 0
663 nGraphsByChannel = 0
664
664
665 if SNR:
665 if SNR:
666 nGraphsByChannel += 1
666 nGraphsByChannel += 1
667 if DOP:
667 if DOP:
668 nGraphsByChannel += 1
668 nGraphsByChannel += 1
669
669
670 if nGraphsByChannel < 1:
670 if nGraphsByChannel < 1:
671 return
671 return
672
672
673 nplots = nGraphsByChannel*nchan
673 nplots = nGraphsByChannel*nchan
674
674
675 if timerange != None:
675 if timerange is not None:
676 self.timerange = timerange
676 self.timerange = timerange
677
677
678 #tmin = None
678 #tmin = None
679 #tmax = None
679 #tmax = None
680 if parameterIndex == None:
680 if parameterIndex == None:
681 parameterIndex = 1
681 parameterIndex = 1
682
682
683 x = dataOut.getTimeRange1()
683 x = dataOut.getTimeRange1()
684 y = dataOut.heightList
684 y = dataOut.heightList
685 z = data_param[channelIndexList,parameterIndex,:].copy()
685 z = data_param[channelIndexList,parameterIndex,:].copy()
686
686
687 zRange = dataOut.abscissaList
687 zRange = dataOut.abscissaList
688 # nChannels = z.shape[0] #Number of wind dimensions estimated
688 # nChannels = z.shape[0] #Number of wind dimensions estimated
689 # thisDatetime = dataOut.datatime
689 # thisDatetime = dataOut.datatime
690
690
691 if dataOut.data_SNR != None:
691 if dataOut.data_SNR is not None:
692 SNRarray = dataOut.data_SNR[channelIndexList,:]
692 SNRarray = dataOut.data_SNR[channelIndexList,:]
693 SNRdB = 10*numpy.log10(SNRarray)
693 SNRdB = 10*numpy.log10(SNRarray)
694 # SNRavgdB = 10*numpy.log10(SNRavg)
694 # SNRavgdB = 10*numpy.log10(SNRavg)
695 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
695 ind = numpy.where(SNRdB < 10**(SNRthresh/10))
696 z[ind] = numpy.nan
696 z[ind] = numpy.nan
697
697
698 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
698 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
699 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
699 title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
700 xlabel = ""
700 xlabel = ""
701 ylabel = "Range (Km)"
701 ylabel = "Range (Km)"
702
702
703 if (SNR and not onlySNR): nplots = 2*nplots
703 if (SNR and not onlySNR): nplots = 2*nplots
704
704
705 if onlyPositive:
705 if onlyPositive:
706 colormap = "jet"
706 colormap = "jet"
707 zmin = 0
707 zmin = 0
708 else: colormap = "RdBu_r"
708 else: colormap = "RdBu_r"
709
709
710 if not self.__isConfig:
710 if not self.__isConfig:
711
711
712 self.setup(id=id,
712 self.setup(id=id,
713 nplots=nplots,
713 nplots=nplots,
714 wintitle=wintitle,
714 wintitle=wintitle,
715 showprofile=showprofile,
715 showprofile=showprofile,
716 show=show)
716 show=show)
717
717
718 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
718 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
719
719
720 if ymin == None: ymin = numpy.nanmin(y)
720 if ymin == None: ymin = numpy.nanmin(y)
721 if ymax == None: ymax = numpy.nanmax(y)
721 if ymax == None: ymax = numpy.nanmax(y)
722 if zmin == None: zmin = numpy.nanmin(zRange)
722 if zmin == None: zmin = numpy.nanmin(zRange)
723 if zmax == None: zmax = numpy.nanmax(zRange)
723 if zmax == None: zmax = numpy.nanmax(zRange)
724
724
725 if SNR:
725 if SNR:
726 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
726 if SNRmin == None: SNRmin = numpy.nanmin(SNRdB)
727 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
727 if SNRmax == None: SNRmax = numpy.nanmax(SNRdB)
728
728
729 self.FTP_WEI = ftp_wei
729 self.FTP_WEI = ftp_wei
730 self.EXP_CODE = exp_code
730 self.EXP_CODE = exp_code
731 self.SUB_EXP_CODE = sub_exp_code
731 self.SUB_EXP_CODE = sub_exp_code
732 self.PLOT_POS = plot_pos
732 self.PLOT_POS = plot_pos
733
733
734 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
734 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
735 self.__isConfig = True
735 self.__isConfig = True
736 self.figfile = figfile
736 self.figfile = figfile
737
737
738 self.setWinTitle(title)
738 self.setWinTitle(title)
739
739
740 if ((self.xmax - x[1]) < (x[1]-x[0])):
740 if ((self.xmax - x[1]) < (x[1]-x[0])):
741 x[1] = self.xmax
741 x[1] = self.xmax
742
742
743 for i in range(nchan):
743 for i in range(nchan):
744
744
745 if (SNR and not onlySNR): j = 2*i
745 if (SNR and not onlySNR): j = 2*i
746 else: j = i
746 else: j = i
747
747
748 j = nGraphsByChannel*i
748 j = nGraphsByChannel*i
749
749
750 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
750 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
751 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
751 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
752
752
753 if not onlySNR:
753 if not onlySNR:
754 axes = self.axesList[j*self.__nsubplots]
754 axes = self.axesList[j*self.__nsubplots]
755 z1 = z[i,:].reshape((1,-1))
755 z1 = z[i,:].reshape((1,-1))
756 axes.pcolorbuffer(x, y, z1,
756 axes.pcolorbuffer(x, y, z1,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
757 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
758 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
759 ticksize=9, cblabel=zlabel, cbsize="1%")
759 ticksize=9, cblabel=zlabel, cbsize="1%")
760
760
761 if DOP:
761 if DOP:
762 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
762 title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
763
763
764 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
764 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
765 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
765 title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith)
766 axes = self.axesList[j]
766 axes = self.axesList[j]
767 z1 = z[i,:].reshape((1,-1))
767 z1 = z[i,:].reshape((1,-1))
768 axes.pcolorbuffer(x, y, z1,
768 axes.pcolorbuffer(x, y, z1,
769 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
769 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
770 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
770 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap,
771 ticksize=9, cblabel=zlabel, cbsize="1%")
771 ticksize=9, cblabel=zlabel, cbsize="1%")
772
772
773 if SNR:
773 if SNR:
774 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
774 title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
775 axes = self.axesList[(j)*self.__nsubplots]
775 axes = self.axesList[(j)*self.__nsubplots]
776 if not onlySNR:
776 if not onlySNR:
777 axes = self.axesList[(j + 1)*self.__nsubplots]
777 axes = self.axesList[(j + 1)*self.__nsubplots]
778
778
779 axes = self.axesList[(j + nGraphsByChannel-1)]
779 axes = self.axesList[(j + nGraphsByChannel-1)]
780
780
781 z1 = SNRdB[i,:].reshape((1,-1))
781 z1 = SNRdB[i,:].reshape((1,-1))
782 axes.pcolorbuffer(x, y, z1,
782 axes.pcolorbuffer(x, y, z1,
783 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
783 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
784 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
784 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet",
785 ticksize=9, cblabel=zlabel, cbsize="1%")
785 ticksize=9, cblabel=zlabel, cbsize="1%")
786
786
787
787
788
788
789 self.draw()
789 self.draw()
790
790
791 if x[1] >= self.axesList[0].xmax:
791 if x[1] >= self.axesList[0].xmax:
792 self.counter_imagwr = wr_period
792 self.counter_imagwr = wr_period
793 self.__isConfig = False
793 self.__isConfig = False
794 self.figfile = None
794 self.figfile = None
795
795
796 self.save(figpath=figpath,
796 self.save(figpath=figpath,
797 figfile=figfile,
797 figfile=figfile,
798 save=save,
798 save=save,
799 ftp=ftp,
799 ftp=ftp,
800 wr_period=wr_period,
800 wr_period=wr_period,
801 thisDatetime=thisDatetime,
801 thisDatetime=thisDatetime,
802 update_figfile=False)
802 update_figfile=False)
803
803
804 class SpectralFittingPlot(Figure):
804 class SpectralFittingPlot(Figure):
805
805
806 __isConfig = None
806 __isConfig = None
807 __nsubplots = None
807 __nsubplots = None
808
808
809 WIDTHPROF = None
809 WIDTHPROF = None
810 HEIGHTPROF = None
810 HEIGHTPROF = None
811 PREFIX = 'prm'
811 PREFIX = 'prm'
812
812
813
813
814 N = None
814 N = None
815 ippSeconds = None
815 ippSeconds = None
816
816
817 def __init__(self):
817 def __init__(self):
818 self.__isConfig = False
818 self.__isConfig = False
819 self.__nsubplots = 1
819 self.__nsubplots = 1
820
820
821 self.PLOT_CODE = SPECFIT_CODE
821 self.PLOT_CODE = SPECFIT_CODE
822
822
823 self.WIDTH = 450
823 self.WIDTH = 450
824 self.HEIGHT = 250
824 self.HEIGHT = 250
825 self.WIDTHPROF = 0
825 self.WIDTHPROF = 0
826 self.HEIGHTPROF = 0
826 self.HEIGHTPROF = 0
827
827
828 def getSubplots(self):
828 def getSubplots(self):
829
829
830 ncol = int(numpy.sqrt(self.nplots)+0.9)
830 ncol = int(numpy.sqrt(self.nplots)+0.9)
831 nrow = int(self.nplots*1./ncol + 0.9)
831 nrow = int(self.nplots*1./ncol + 0.9)
832
832
833 return nrow, ncol
833 return nrow, ncol
834
834
835 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
835 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
836
836
837 showprofile = False
837 showprofile = False
838 self.__showprofile = showprofile
838 self.__showprofile = showprofile
839 self.nplots = nplots
839 self.nplots = nplots
840
840
841 ncolspan = 5
841 ncolspan = 5
842 colspan = 4
842 colspan = 4
843 if showprofile:
843 if showprofile:
844 ncolspan = 5
844 ncolspan = 5
845 colspan = 4
845 colspan = 4
846 self.__nsubplots = 2
846 self.__nsubplots = 2
847
847
848 self.createFigure(id = id,
848 self.createFigure(id = id,
849 wintitle = wintitle,
849 wintitle = wintitle,
850 widthplot = self.WIDTH + self.WIDTHPROF,
850 widthplot = self.WIDTH + self.WIDTHPROF,
851 heightplot = self.HEIGHT + self.HEIGHTPROF,
851 heightplot = self.HEIGHT + self.HEIGHTPROF,
852 show=show)
852 show=show)
853
853
854 nrow, ncol = self.getSubplots()
854 nrow, ncol = self.getSubplots()
855
855
856 counter = 0
856 counter = 0
857 for y in range(nrow):
857 for y in range(nrow):
858 for x in range(ncol):
858 for x in range(ncol):
859
859
860 if counter >= self.nplots:
860 if counter >= self.nplots:
861 break
861 break
862
862
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
864
864
865 if showprofile:
865 if showprofile:
866 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
866 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
867
867
868 counter += 1
868 counter += 1
869
869
870 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
870 def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True,
871 xmin=None, xmax=None, ymin=None, ymax=None,
871 xmin=None, xmax=None, ymin=None, ymax=None,
872 save=False, figpath='./', figfile=None, show=True):
872 save=False, figpath='./', figfile=None, show=True):
873
873
874 """
874 """
875
875
876 Input:
876 Input:
877 dataOut :
877 dataOut :
878 id :
878 id :
879 wintitle :
879 wintitle :
880 channelList :
880 channelList :
881 showProfile :
881 showProfile :
882 xmin : None,
882 xmin : None,
883 xmax : None,
883 xmax : None,
884 zmin : None,
884 zmin : None,
885 zmax : None
885 zmax : None
886 """
886 """
887
887
888 if cutHeight==None:
888 if cutHeight==None:
889 h=270
889 h=270
890 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
890 heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin()
891 cutHeight = dataOut.heightList[heightindex]
891 cutHeight = dataOut.heightList[heightindex]
892
892
893 factor = dataOut.normFactor
893 factor = dataOut.normFactor
894 x = dataOut.abscissaList[:-1]
894 x = dataOut.abscissaList[:-1]
895 #y = dataOut.getHeiRange()
895 #y = dataOut.getHeiRange()
896
896
897 z = dataOut.data_pre[:,:,heightindex]/factor
897 z = dataOut.data_pre[:,:,heightindex]/factor
898 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
898 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
899 avg = numpy.average(z, axis=1)
899 avg = numpy.average(z, axis=1)
900 listChannels = z.shape[0]
900 listChannels = z.shape[0]
901
901
902 #Reconstruct Function
902 #Reconstruct Function
903 if fit==True:
903 if fit==True:
904 groupArray = dataOut.groupList
904 groupArray = dataOut.groupList
905 listChannels = groupArray.reshape((groupArray.size))
905 listChannels = groupArray.reshape((groupArray.size))
906 listChannels.sort()
906 listChannels.sort()
907 spcFitLine = numpy.zeros(z.shape)
907 spcFitLine = numpy.zeros(z.shape)
908 constants = dataOut.constants
908 constants = dataOut.constants
909
909
910 nGroups = groupArray.shape[0]
910 nGroups = groupArray.shape[0]
911 nChannels = groupArray.shape[1]
911 nChannels = groupArray.shape[1]
912 nProfiles = z.shape[1]
912 nProfiles = z.shape[1]
913
913
914 for f in range(nGroups):
914 for f in range(nGroups):
915 groupChann = groupArray[f,:]
915 groupChann = groupArray[f,:]
916 p = dataOut.data_param[f,:,heightindex]
916 p = dataOut.data_param[f,:,heightindex]
917 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
917 # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167])
918 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
918 fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles
919 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
919 fitLineAux = fitLineAux.reshape((nChannels,nProfiles))
920 spcFitLine[groupChann,:] = fitLineAux
920 spcFitLine[groupChann,:] = fitLineAux
921 # spcFitLine = spcFitLine/factor
921 # spcFitLine = spcFitLine/factor
922
922
923 z = z[listChannels,:]
923 z = z[listChannels,:]
924 spcFitLine = spcFitLine[listChannels,:]
924 spcFitLine = spcFitLine[listChannels,:]
925 spcFitLinedB = 10*numpy.log10(spcFitLine)
925 spcFitLinedB = 10*numpy.log10(spcFitLine)
926
926
927 zdB = 10*numpy.log10(z)
927 zdB = 10*numpy.log10(z)
928 #thisDatetime = dataOut.datatime
928 #thisDatetime = dataOut.datatime
929 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
929 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
930 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
930 title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
931 xlabel = "Velocity (m/s)"
931 xlabel = "Velocity (m/s)"
932 ylabel = "Spectrum"
932 ylabel = "Spectrum"
933
933
934 if not self.__isConfig:
934 if not self.__isConfig:
935
935
936 nplots = listChannels.size
936 nplots = listChannels.size
937
937
938 self.setup(id=id,
938 self.setup(id=id,
939 nplots=nplots,
939 nplots=nplots,
940 wintitle=wintitle,
940 wintitle=wintitle,
941 showprofile=showprofile,
941 showprofile=showprofile,
942 show=show)
942 show=show)
943
943
944 if xmin == None: xmin = numpy.nanmin(x)
944 if xmin == None: xmin = numpy.nanmin(x)
945 if xmax == None: xmax = numpy.nanmax(x)
945 if xmax == None: xmax = numpy.nanmax(x)
946 if ymin == None: ymin = numpy.nanmin(zdB)
946 if ymin == None: ymin = numpy.nanmin(zdB)
947 if ymax == None: ymax = numpy.nanmax(zdB)+2
947 if ymax == None: ymax = numpy.nanmax(zdB)+2
948
948
949 self.__isConfig = True
949 self.__isConfig = True
950
950
951 self.setWinTitle(title)
951 self.setWinTitle(title)
952 for i in range(self.nplots):
952 for i in range(self.nplots):
953 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
953 # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i])
954 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1)
954 title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1)
955 axes = self.axesList[i*self.__nsubplots]
955 axes = self.axesList[i*self.__nsubplots]
956 if fit == False:
956 if fit == False:
957 axes.pline(x, zdB[i,:],
957 axes.pline(x, zdB[i,:],
958 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
958 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
959 xlabel=xlabel, ylabel=ylabel, title=title
959 xlabel=xlabel, ylabel=ylabel, title=title
960 )
960 )
961 if fit == True:
961 if fit == True:
962 fitline=spcFitLinedB[i,:]
962 fitline=spcFitLinedB[i,:]
963 y=numpy.vstack([zdB[i,:],fitline] )
963 y=numpy.vstack([zdB[i,:],fitline] )
964 legendlabels=['Data','Fitting']
964 legendlabels=['Data','Fitting']
965 axes.pmultilineyaxis(x, y,
965 axes.pmultilineyaxis(x, y,
966 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
966 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
967 xlabel=xlabel, ylabel=ylabel, title=title,
967 xlabel=xlabel, ylabel=ylabel, title=title,
968 legendlabels=legendlabels, marker=None,
968 legendlabels=legendlabels, marker=None,
969 linestyle='solid', grid='both')
969 linestyle='solid', grid='both')
970
970
971 self.draw()
971 self.draw()
972
972
973 self.save(figpath=figpath,
973 self.save(figpath=figpath,
974 figfile=figfile,
974 figfile=figfile,
975 save=save,
975 save=save,
976 ftp=ftp,
976 ftp=ftp,
977 wr_period=wr_period,
977 wr_period=wr_period,
978 thisDatetime=thisDatetime)
978 thisDatetime=thisDatetime)
979
979
980
980
981 class EWDriftsPlot(Figure):
981 class EWDriftsPlot(Figure):
982
982
983 __isConfig = None
983 __isConfig = None
984 __nsubplots = None
984 __nsubplots = None
985
985
986 WIDTHPROF = None
986 WIDTHPROF = None
987 HEIGHTPROF = None
987 HEIGHTPROF = None
988 PREFIX = 'drift'
988 PREFIX = 'drift'
989
989
990 def __init__(self):
990 def __init__(self):
991
991
992 self.timerange = 2*60*60
992 self.timerange = 2*60*60
993 self.isConfig = False
993 self.isConfig = False
994 self.__nsubplots = 1
994 self.__nsubplots = 1
995
995
996 self.WIDTH = 800
996 self.WIDTH = 800
997 self.HEIGHT = 150
997 self.HEIGHT = 150
998 self.WIDTHPROF = 120
998 self.WIDTHPROF = 120
999 self.HEIGHTPROF = 0
999 self.HEIGHTPROF = 0
1000 self.counter_imagwr = 0
1000 self.counter_imagwr = 0
1001
1001
1002 self.PLOT_CODE = EWDRIFT_CODE
1002 self.PLOT_CODE = EWDRIFT_CODE
1003
1003
1004 self.FTP_WEI = None
1004 self.FTP_WEI = None
1005 self.EXP_CODE = None
1005 self.EXP_CODE = None
1006 self.SUB_EXP_CODE = None
1006 self.SUB_EXP_CODE = None
1007 self.PLOT_POS = None
1007 self.PLOT_POS = None
1008 self.tmin = None
1008 self.tmin = None
1009 self.tmax = None
1009 self.tmax = None
1010
1010
1011 self.xmin = None
1011 self.xmin = None
1012 self.xmax = None
1012 self.xmax = None
1013
1013
1014 self.figfile = None
1014 self.figfile = None
1015
1015
1016 def getSubplots(self):
1016 def getSubplots(self):
1017
1017
1018 ncol = 1
1018 ncol = 1
1019 nrow = self.nplots
1019 nrow = self.nplots
1020
1020
1021 return nrow, ncol
1021 return nrow, ncol
1022
1022
1023 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1023 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1024
1024
1025 self.__showprofile = showprofile
1025 self.__showprofile = showprofile
1026 self.nplots = nplots
1026 self.nplots = nplots
1027
1027
1028 ncolspan = 1
1028 ncolspan = 1
1029 colspan = 1
1029 colspan = 1
1030
1030
1031 self.createFigure(id = id,
1031 self.createFigure(id = id,
1032 wintitle = wintitle,
1032 wintitle = wintitle,
1033 widthplot = self.WIDTH + self.WIDTHPROF,
1033 widthplot = self.WIDTH + self.WIDTHPROF,
1034 heightplot = self.HEIGHT + self.HEIGHTPROF,
1034 heightplot = self.HEIGHT + self.HEIGHTPROF,
1035 show=show)
1035 show=show)
1036
1036
1037 nrow, ncol = self.getSubplots()
1037 nrow, ncol = self.getSubplots()
1038
1038
1039 counter = 0
1039 counter = 0
1040 for y in range(nrow):
1040 for y in range(nrow):
1041 if counter >= self.nplots:
1041 if counter >= self.nplots:
1042 break
1042 break
1043
1043
1044 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1044 self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1)
1045 counter += 1
1045 counter += 1
1046
1046
1047 def run(self, dataOut, id, wintitle="", channelList=None,
1047 def run(self, dataOut, id, wintitle="", channelList=None,
1048 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1048 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
1049 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1049 zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None,
1050 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1050 timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False,
1051 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1051 save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True,
1052 server=None, folder=None, username=None, password=None,
1052 server=None, folder=None, username=None, password=None,
1053 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1053 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1054 """
1054 """
1055
1055
1056 Input:
1056 Input:
1057 dataOut :
1057 dataOut :
1058 id :
1058 id :
1059 wintitle :
1059 wintitle :
1060 channelList :
1060 channelList :
1061 showProfile :
1061 showProfile :
1062 xmin : None,
1062 xmin : None,
1063 xmax : None,
1063 xmax : None,
1064 ymin : None,
1064 ymin : None,
1065 ymax : None,
1065 ymax : None,
1066 zmin : None,
1066 zmin : None,
1067 zmax : None
1067 zmax : None
1068 """
1068 """
1069
1069
1070 if timerange != None:
1070 if timerange is not None:
1071 self.timerange = timerange
1071 self.timerange = timerange
1072
1072
1073 tmin = None
1073 tmin = None
1074 tmax = None
1074 tmax = None
1075
1075
1076 x = dataOut.getTimeRange1()
1076 x = dataOut.getTimeRange1()
1077 # y = dataOut.heightList
1077 # y = dataOut.heightList
1078 y = dataOut.heightList
1078 y = dataOut.heightList
1079
1079
1080 z = dataOut.data_output
1080 z = dataOut.data_output
1081 nplots = z.shape[0] #Number of wind dimensions estimated
1081 nplots = z.shape[0] #Number of wind dimensions estimated
1082 nplotsw = nplots
1082 nplotsw = nplots
1083
1083
1084 #If there is a SNR function defined
1084 #If there is a SNR function defined
1085 if dataOut.data_SNR != None:
1085 if dataOut.data_SNR is not None:
1086 nplots += 1
1086 nplots += 1
1087 SNR = dataOut.data_SNR
1087 SNR = dataOut.data_SNR
1088
1088
1089 if SNR_1:
1089 if SNR_1:
1090 SNR += 1
1090 SNR += 1
1091
1091
1092 SNRavg = numpy.average(SNR, axis=0)
1092 SNRavg = numpy.average(SNR, axis=0)
1093
1093
1094 SNRdB = 10*numpy.log10(SNR)
1094 SNRdB = 10*numpy.log10(SNR)
1095 SNRavgdB = 10*numpy.log10(SNRavg)
1095 SNRavgdB = 10*numpy.log10(SNRavg)
1096
1096
1097 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1097 ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0]
1098
1098
1099 for i in range(nplotsw):
1099 for i in range(nplotsw):
1100 z[i,ind] = numpy.nan
1100 z[i,ind] = numpy.nan
1101
1101
1102
1102
1103 showprofile = False
1103 showprofile = False
1104 # thisDatetime = dataOut.datatime
1104 # thisDatetime = dataOut.datatime
1105 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1105 thisDatetime = datetime.datetime.utcfromtimestamp(x[1])
1106 title = wintitle + " EW Drifts"
1106 title = wintitle + " EW Drifts"
1107 xlabel = ""
1107 xlabel = ""
1108 ylabel = "Height (Km)"
1108 ylabel = "Height (Km)"
1109
1109
1110 if not self.__isConfig:
1110 if not self.__isConfig:
1111
1111
1112 self.setup(id=id,
1112 self.setup(id=id,
1113 nplots=nplots,
1113 nplots=nplots,
1114 wintitle=wintitle,
1114 wintitle=wintitle,
1115 showprofile=showprofile,
1115 showprofile=showprofile,
1116 show=show)
1116 show=show)
1117
1117
1118 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1118 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1119
1119
1120 if ymin == None: ymin = numpy.nanmin(y)
1120 if ymin == None: ymin = numpy.nanmin(y)
1121 if ymax == None: ymax = numpy.nanmax(y)
1121 if ymax == None: ymax = numpy.nanmax(y)
1122
1122
1123 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1123 if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:]))
1124 if zminZonal == None: zminZonal = -zmaxZonal
1124 if zminZonal == None: zminZonal = -zmaxZonal
1125 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1125 if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:]))
1126 if zminVertical == None: zminVertical = -zmaxVertical
1126 if zminVertical == None: zminVertical = -zmaxVertical
1127
1127
1128 if dataOut.data_SNR != None:
1128 if dataOut.data_SNR is not None:
1129 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1129 if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB)
1130 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1130 if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB)
1131
1131
1132 self.FTP_WEI = ftp_wei
1132 self.FTP_WEI = ftp_wei
1133 self.EXP_CODE = exp_code
1133 self.EXP_CODE = exp_code
1134 self.SUB_EXP_CODE = sub_exp_code
1134 self.SUB_EXP_CODE = sub_exp_code
1135 self.PLOT_POS = plot_pos
1135 self.PLOT_POS = plot_pos
1136
1136
1137 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1137 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1138 self.__isConfig = True
1138 self.__isConfig = True
1139
1139
1140
1140
1141 self.setWinTitle(title)
1141 self.setWinTitle(title)
1142
1142
1143 if ((self.xmax - x[1]) < (x[1]-x[0])):
1143 if ((self.xmax - x[1]) < (x[1]-x[0])):
1144 x[1] = self.xmax
1144 x[1] = self.xmax
1145
1145
1146 strWind = ['Zonal','Vertical']
1146 strWind = ['Zonal','Vertical']
1147 strCb = 'Velocity (m/s)'
1147 strCb = 'Velocity (m/s)'
1148 zmaxVector = [zmaxZonal, zmaxVertical]
1148 zmaxVector = [zmaxZonal, zmaxVertical]
1149 zminVector = [zminZonal, zminVertical]
1149 zminVector = [zminZonal, zminVertical]
1150
1150
1151 for i in range(nplotsw):
1151 for i in range(nplotsw):
1152
1152
1153 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1153 title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1154 axes = self.axesList[i*self.__nsubplots]
1154 axes = self.axesList[i*self.__nsubplots]
1155
1155
1156 z1 = z[i,:].reshape((1,-1))
1156 z1 = z[i,:].reshape((1,-1))
1157
1157
1158 axes.pcolorbuffer(x, y, z1,
1158 axes.pcolorbuffer(x, y, z1,
1159 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1159 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i],
1160 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1160 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1161 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1161 ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r")
1162
1162
1163 if dataOut.data_SNR != None:
1163 if dataOut.data_SNR is not None:
1164 i += 1
1164 i += 1
1165 if SNR_1:
1165 if SNR_1:
1166 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1166 title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1167 else:
1167 else:
1168 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1168 title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1169 axes = self.axesList[i*self.__nsubplots]
1169 axes = self.axesList[i*self.__nsubplots]
1170 SNRavgdB = SNRavgdB.reshape((1,-1))
1170 SNRavgdB = SNRavgdB.reshape((1,-1))
1171
1171
1172 axes.pcolorbuffer(x, y, SNRavgdB,
1172 axes.pcolorbuffer(x, y, SNRavgdB,
1173 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1173 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax,
1174 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1174 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
1175 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1175 ticksize=9, cblabel='', cbsize="1%", colormap="jet")
1176
1176
1177 self.draw()
1177 self.draw()
1178
1178
1179 if x[1] >= self.axesList[0].xmax:
1179 if x[1] >= self.axesList[0].xmax:
1180 self.counter_imagwr = wr_period
1180 self.counter_imagwr = wr_period
1181 self.__isConfig = False
1181 self.__isConfig = False
1182 self.figfile = None
1182 self.figfile = None
1183
1183
1184
1184
1185
1185
1186
1186
1187 class PhasePlot(Figure):
1187 class PhasePlot(Figure):
1188
1188
1189 __isConfig = None
1189 __isConfig = None
1190 __nsubplots = None
1190 __nsubplots = None
1191
1191
1192 PREFIX = 'mphase'
1192 PREFIX = 'mphase'
1193
1193
1194 def __init__(self):
1194 def __init__(self):
1195
1195
1196 self.timerange = 24*60*60
1196 self.timerange = 24*60*60
1197 self.__isConfig = False
1197 self.__isConfig = False
1198 self.__nsubplots = 1
1198 self.__nsubplots = 1
1199 self.counter_imagwr = 0
1199 self.counter_imagwr = 0
1200 self.WIDTH = 600
1200 self.WIDTH = 600
1201 self.HEIGHT = 300
1201 self.HEIGHT = 300
1202 self.WIDTHPROF = 120
1202 self.WIDTHPROF = 120
1203 self.HEIGHTPROF = 0
1203 self.HEIGHTPROF = 0
1204 self.xdata = None
1204 self.xdata = None
1205 self.ydata = None
1205 self.ydata = None
1206
1206
1207 self.PLOT_CODE = MPHASE_CODE
1207 self.PLOT_CODE = MPHASE_CODE
1208
1208
1209 self.FTP_WEI = None
1209 self.FTP_WEI = None
1210 self.EXP_CODE = None
1210 self.EXP_CODE = None
1211 self.SUB_EXP_CODE = None
1211 self.SUB_EXP_CODE = None
1212 self.PLOT_POS = None
1212 self.PLOT_POS = None
1213
1213
1214
1214
1215 self.filename_phase = None
1215 self.filename_phase = None
1216
1216
1217 self.figfile = None
1217 self.figfile = None
1218
1218
1219 def getSubplots(self):
1219 def getSubplots(self):
1220
1220
1221 ncol = 1
1221 ncol = 1
1222 nrow = 1
1222 nrow = 1
1223
1223
1224 return nrow, ncol
1224 return nrow, ncol
1225
1225
1226 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1226 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1227
1227
1228 self.__showprofile = showprofile
1228 self.__showprofile = showprofile
1229 self.nplots = nplots
1229 self.nplots = nplots
1230
1230
1231 ncolspan = 7
1231 ncolspan = 7
1232 colspan = 6
1232 colspan = 6
1233 self.__nsubplots = 2
1233 self.__nsubplots = 2
1234
1234
1235 self.createFigure(id = id,
1235 self.createFigure(id = id,
1236 wintitle = wintitle,
1236 wintitle = wintitle,
1237 widthplot = self.WIDTH+self.WIDTHPROF,
1237 widthplot = self.WIDTH+self.WIDTHPROF,
1238 heightplot = self.HEIGHT+self.HEIGHTPROF,
1238 heightplot = self.HEIGHT+self.HEIGHTPROF,
1239 show=show)
1239 show=show)
1240
1240
1241 nrow, ncol = self.getSubplots()
1241 nrow, ncol = self.getSubplots()
1242
1242
1243 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1243 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1244
1244
1245
1245
1246 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1246 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1247 xmin=None, xmax=None, ymin=None, ymax=None,
1247 xmin=None, xmax=None, ymin=None, ymax=None,
1248 timerange=None,
1248 timerange=None,
1249 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1249 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1250 server=None, folder=None, username=None, password=None,
1250 server=None, folder=None, username=None, password=None,
1251 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1251 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1252
1252
1253
1253
1254 tmin = None
1254 tmin = None
1255 tmax = None
1255 tmax = None
1256 x = dataOut.getTimeRange1()
1256 x = dataOut.getTimeRange1()
1257 y = dataOut.getHeiRange()
1257 y = dataOut.getHeiRange()
1258
1258
1259
1259
1260 #thisDatetime = dataOut.datatime
1260 #thisDatetime = dataOut.datatime
1261 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1261 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1262 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1262 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1263 xlabel = "Local Time"
1263 xlabel = "Local Time"
1264 ylabel = "Phase"
1264 ylabel = "Phase"
1265
1265
1266
1266
1267 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1267 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1268 phase_beacon = dataOut.data_output
1268 phase_beacon = dataOut.data_output
1269
1269
1270
1270
1271 if not self.__isConfig:
1271 if not self.__isConfig:
1272
1272
1273 self.nplots = phase_beacon.size
1273 self.nplots = phase_beacon.size
1274
1274
1275 self.setup(id=id,
1275 self.setup(id=id,
1276 nplots=self.nplots,
1276 nplots=self.nplots,
1277 wintitle=wintitle,
1277 wintitle=wintitle,
1278 showprofile=showprofile,
1278 showprofile=showprofile,
1279 show=show)
1279 show=show)
1280
1280
1281 if timerange != None:
1281 if timerange is not None:
1282 self.timerange = timerange
1282 self.timerange = timerange
1283
1283
1284 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1284 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
1285
1285
1286 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1286 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1287 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1287 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1288
1288
1289 self.FTP_WEI = ftp_wei
1289 self.FTP_WEI = ftp_wei
1290 self.EXP_CODE = exp_code
1290 self.EXP_CODE = exp_code
1291 self.SUB_EXP_CODE = sub_exp_code
1291 self.SUB_EXP_CODE = sub_exp_code
1292 self.PLOT_POS = plot_pos
1292 self.PLOT_POS = plot_pos
1293
1293
1294 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1294 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1295 self.__isConfig = True
1295 self.__isConfig = True
1296 self.figfile = figfile
1296 self.figfile = figfile
1297 self.xdata = numpy.array([])
1297 self.xdata = numpy.array([])
1298 self.ydata = numpy.array([])
1298 self.ydata = numpy.array([])
1299
1299
1300 #open file beacon phase
1300 #open file beacon phase
1301 path = '%s%03d' %(self.PREFIX, self.id)
1301 path = '%s%03d' %(self.PREFIX, self.id)
1302 beacon_file = os.path.join(path,'%s.txt'%self.name)
1302 beacon_file = os.path.join(path,'%s.txt'%self.name)
1303 self.filename_phase = os.path.join(figpath,beacon_file)
1303 self.filename_phase = os.path.join(figpath,beacon_file)
1304 #self.save_phase(self.filename_phase)
1304 #self.save_phase(self.filename_phase)
1305
1305
1306
1306
1307 #store data beacon phase
1307 #store data beacon phase
1308 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1308 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1309
1309
1310 self.setWinTitle(title)
1310 self.setWinTitle(title)
1311
1311
1312
1312
1313 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1313 title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1314
1314
1315 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1315 legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)]
1316
1316
1317 axes = self.axesList[0]
1317 axes = self.axesList[0]
1318
1318
1319 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1319 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1320
1320
1321 if len(self.ydata)==0:
1321 if len(self.ydata)==0:
1322 self.ydata = phase_beacon.reshape(-1,1)
1322 self.ydata = phase_beacon.reshape(-1,1)
1323 else:
1323 else:
1324 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1324 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1325
1325
1326
1326
1327 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1327 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1328 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1328 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
1329 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1329 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1330 XAxisAsTime=True, grid='both'
1330 XAxisAsTime=True, grid='both'
1331 )
1331 )
1332
1332
1333 self.draw()
1333 self.draw()
1334
1334
1335 if x[1] >= self.axesList[0].xmax:
1335 if x[1] >= self.axesList[0].xmax:
1336 self.counter_imagwr = wr_period
1336 self.counter_imagwr = wr_period
1337 del self.xdata
1337 del self.xdata
1338 del self.ydata
1338 del self.ydata
1339 self.__isConfig = False
1339 self.__isConfig = False
1340
1340
1341 if self.figfile == None:
1341 if self.figfile == None:
1342 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1342 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1343 self.figfile = self.getFilename(name = str_datetime)
1343 self.figfile = self.getFilename(name = str_datetime)
1344
1344
1345 if figpath != '':
1345 if figpath != '':
1346 self.counter_imagwr += 1
1346 self.counter_imagwr += 1
1347 if (self.counter_imagwr>=wr_period):
1347 if (self.counter_imagwr>=wr_period):
1348 # store png plot to local folder
1348 # store png plot to local folder
1349 self.saveFigure(figpath, self.figfile)
1349 self.saveFigure(figpath, self.figfile)
1350 # store png plot to FTP server according to RT-Web format
1350 # store png plot to FTP server according to RT-Web format
1351 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1351 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1352 ftp_filename = os.path.join(figpath, name)
1352 ftp_filename = os.path.join(figpath, name)
1353 self.saveFigure(figpath, ftp_filename)
1353 self.saveFigure(figpath, ftp_filename)
1354 self.counter_imagwr = 0
1354 self.counter_imagwr = 0
1355 self.figfile = None
1355 self.figfile = None
1356
1356
1357 self.save(figpath=figpath,
1357 self.save(figpath=figpath,
1358 figfile=figfile,
1358 figfile=figfile,
1359 save=save,
1359 save=save,
1360 ftp=ftp,
1360 ftp=ftp,
1361 wr_period=wr_period,
1361 wr_period=wr_period,
1362 thisDatetime=thisDatetime,
1362 thisDatetime=thisDatetime,
1363 update_figfile=False)
1363 update_figfile=False)
@@ -1,764 +1,764
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import numpy
6 import numpy
7
7
8 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
8 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
9 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
10 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
11 from schainpy.model.data.jrodata import Spectra
11 from schainpy.model.data.jrodata import Spectra
12
12
13 class SpectraReader(JRODataReader, ProcessingUnit):
13 class SpectraReader(JRODataReader, ProcessingUnit):
14 """
14 """
15 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
15 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
16 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
16 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
17 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
17 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
18
18
19 paresCanalesIguales * alturas * perfiles (Self Spectra)
19 paresCanalesIguales * alturas * perfiles (Self Spectra)
20 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
20 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
21 canales * alturas (DC Channels)
21 canales * alturas (DC Channels)
22
22
23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
23 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
24 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
24 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
25 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
25 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
26 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
26 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
27
27
28 Example:
28 Example:
29 dpath = "/home/myuser/data"
29 dpath = "/home/myuser/data"
30
30
31 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
31 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
32
32
33 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
33 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
34
34
35 readerObj = SpectraReader()
35 readerObj = SpectraReader()
36
36
37 readerObj.setup(dpath, startTime, endTime)
37 readerObj.setup(dpath, startTime, endTime)
38
38
39 while(True):
39 while(True):
40
40
41 readerObj.getData()
41 readerObj.getData()
42
42
43 print readerObj.data_spc
43 print readerObj.data_spc
44
44
45 print readerObj.data_cspc
45 print readerObj.data_cspc
46
46
47 print readerObj.data_dc
47 print readerObj.data_dc
48
48
49 if readerObj.flagNoMoreFiles:
49 if readerObj.flagNoMoreFiles:
50 break
50 break
51
51
52 """
52 """
53
53
54 pts2read_SelfSpectra = 0
54 pts2read_SelfSpectra = 0
55
55
56 pts2read_CrossSpectra = 0
56 pts2read_CrossSpectra = 0
57
57
58 pts2read_DCchannels = 0
58 pts2read_DCchannels = 0
59
59
60 ext = ".pdata"
60 ext = ".pdata"
61
61
62 optchar = "P"
62 optchar = "P"
63
63
64 dataOut = None
64 dataOut = None
65
65
66 nRdChannels = None
66 nRdChannels = None
67
67
68 nRdPairs = None
68 nRdPairs = None
69
69
70 rdPairList = []
70 rdPairList = []
71
71
72 def __init__(self):
72 def __init__(self):
73 """
73 """
74 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
74 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
75
75
76 Inputs:
76 Inputs:
77 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
77 dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para
78 almacenar un perfil de datos cada vez que se haga un requerimiento
78 almacenar un perfil de datos cada vez que se haga un requerimiento
79 (getData). El perfil sera obtenido a partir del buffer de datos,
79 (getData). El perfil sera obtenido a partir del buffer de datos,
80 si el buffer esta vacio se hara un nuevo proceso de lectura de un
80 si el buffer esta vacio se hara un nuevo proceso de lectura de un
81 bloque de datos.
81 bloque de datos.
82 Si este parametro no es pasado se creara uno internamente.
82 Si este parametro no es pasado se creara uno internamente.
83
83
84 Affected:
84 Affected:
85 self.dataOut
85 self.dataOut
86
86
87 Return : None
87 Return : None
88 """
88 """
89
89
90 #Eliminar de la base la herencia
90 #Eliminar de la base la herencia
91 ProcessingUnit.__init__(self)
91 ProcessingUnit.__init__(self)
92
92
93 # self.isConfig = False
93 # self.isConfig = False
94
94
95 self.pts2read_SelfSpectra = 0
95 self.pts2read_SelfSpectra = 0
96
96
97 self.pts2read_CrossSpectra = 0
97 self.pts2read_CrossSpectra = 0
98
98
99 self.pts2read_DCchannels = 0
99 self.pts2read_DCchannels = 0
100
100
101 self.datablock = None
101 self.datablock = None
102
102
103 self.utc = None
103 self.utc = None
104
104
105 self.ext = ".pdata"
105 self.ext = ".pdata"
106
106
107 self.optchar = "P"
107 self.optchar = "P"
108
108
109 self.basicHeaderObj = BasicHeader(LOCALTIME)
109 self.basicHeaderObj = BasicHeader(LOCALTIME)
110
110
111 self.systemHeaderObj = SystemHeader()
111 self.systemHeaderObj = SystemHeader()
112
112
113 self.radarControllerHeaderObj = RadarControllerHeader()
113 self.radarControllerHeaderObj = RadarControllerHeader()
114
114
115 self.processingHeaderObj = ProcessingHeader()
115 self.processingHeaderObj = ProcessingHeader()
116
116
117 self.online = 0
117 self.online = 0
118
118
119 self.fp = None
119 self.fp = None
120
120
121 self.idFile = None
121 self.idFile = None
122
122
123 self.dtype = None
123 self.dtype = None
124
124
125 self.fileSizeByHeader = None
125 self.fileSizeByHeader = None
126
126
127 self.filenameList = []
127 self.filenameList = []
128
128
129 self.filename = None
129 self.filename = None
130
130
131 self.fileSize = None
131 self.fileSize = None
132
132
133 self.firstHeaderSize = 0
133 self.firstHeaderSize = 0
134
134
135 self.basicHeaderSize = 24
135 self.basicHeaderSize = 24
136
136
137 self.pathList = []
137 self.pathList = []
138
138
139 self.lastUTTime = 0
139 self.lastUTTime = 0
140
140
141 self.maxTimeStep = 30
141 self.maxTimeStep = 30
142
142
143 self.flagNoMoreFiles = 0
143 self.flagNoMoreFiles = 0
144
144
145 self.set = 0
145 self.set = 0
146
146
147 self.path = None
147 self.path = None
148
148
149 self.delay = 60 #seconds
149 self.delay = 60 #seconds
150
150
151 self.nTries = 3 #quantity tries
151 self.nTries = 3 #quantity tries
152
152
153 self.nFiles = 3 #number of files for searching
153 self.nFiles = 3 #number of files for searching
154
154
155 self.nReadBlocks = 0
155 self.nReadBlocks = 0
156
156
157 self.flagIsNewFile = 1
157 self.flagIsNewFile = 1
158
158
159 self.__isFirstTimeOnline = 1
159 self.__isFirstTimeOnline = 1
160
160
161 # self.ippSeconds = 0
161 # self.ippSeconds = 0
162
162
163 self.flagDiscontinuousBlock = 0
163 self.flagDiscontinuousBlock = 0
164
164
165 self.flagIsNewBlock = 0
165 self.flagIsNewBlock = 0
166
166
167 self.nTotalBlocks = 0
167 self.nTotalBlocks = 0
168
168
169 self.blocksize = 0
169 self.blocksize = 0
170
170
171 self.dataOut = self.createObjByDefault()
171 self.dataOut = self.createObjByDefault()
172
172
173 self.profileIndex = 1 #Always
173 self.profileIndex = 1 #Always
174
174
175
175
176 def createObjByDefault(self):
176 def createObjByDefault(self):
177
177
178 dataObj = Spectra()
178 dataObj = Spectra()
179
179
180 return dataObj
180 return dataObj
181
181
182 def __hasNotDataInBuffer(self):
182 def __hasNotDataInBuffer(self):
183 return 1
183 return 1
184
184
185
185
186 def getBlockDimension(self):
186 def getBlockDimension(self):
187 """
187 """
188 Obtiene la cantidad de puntos a leer por cada bloque de datos
188 Obtiene la cantidad de puntos a leer por cada bloque de datos
189
189
190 Affected:
190 Affected:
191 self.nRdChannels
191 self.nRdChannels
192 self.nRdPairs
192 self.nRdPairs
193 self.pts2read_SelfSpectra
193 self.pts2read_SelfSpectra
194 self.pts2read_CrossSpectra
194 self.pts2read_CrossSpectra
195 self.pts2read_DCchannels
195 self.pts2read_DCchannels
196 self.blocksize
196 self.blocksize
197 self.dataOut.nChannels
197 self.dataOut.nChannels
198 self.dataOut.nPairs
198 self.dataOut.nPairs
199
199
200 Return:
200 Return:
201 None
201 None
202 """
202 """
203 self.nRdChannels = 0
203 self.nRdChannels = 0
204 self.nRdPairs = 0
204 self.nRdPairs = 0
205 self.rdPairList = []
205 self.rdPairList = []
206
206
207 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
207 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
208 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
208 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
209 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
209 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
210 else:
210 else:
211 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
211 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
212 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
212 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
213
213
214 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
214 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
215
215
216 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
216 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
217 self.blocksize = self.pts2read_SelfSpectra
217 self.blocksize = self.pts2read_SelfSpectra
218
218
219 if self.processingHeaderObj.flag_cspc:
219 if self.processingHeaderObj.flag_cspc:
220 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
220 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
221 self.blocksize += self.pts2read_CrossSpectra
221 self.blocksize += self.pts2read_CrossSpectra
222
222
223 if self.processingHeaderObj.flag_dc:
223 if self.processingHeaderObj.flag_dc:
224 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
224 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
225 self.blocksize += self.pts2read_DCchannels
225 self.blocksize += self.pts2read_DCchannels
226
226
227 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
227 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
228
228
229
229
230 def readBlock(self):
230 def readBlock(self):
231 """
231 """
232 Lee el bloque de datos desde la posicion actual del puntero del archivo
232 Lee el bloque de datos desde la posicion actual del puntero del archivo
233 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
233 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
234 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
234 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
235 es seteado a 0
235 es seteado a 0
236
236
237 Return: None
237 Return: None
238
238
239 Variables afectadas:
239 Variables afectadas:
240
240
241 self.flagIsNewFile
241 self.flagIsNewFile
242 self.flagIsNewBlock
242 self.flagIsNewBlock
243 self.nTotalBlocks
243 self.nTotalBlocks
244 self.data_spc
244 self.data_spc
245 self.data_cspc
245 self.data_cspc
246 self.data_dc
246 self.data_dc
247
247
248 Exceptions:
248 Exceptions:
249 Si un bloque leido no es un bloque valido
249 Si un bloque leido no es un bloque valido
250 """
250 """
251 blockOk_flag = False
251 blockOk_flag = False
252 fpointer = self.fp.tell()
252 fpointer = self.fp.tell()
253
253
254 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
254 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
255 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
255 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
256
256
257 if self.processingHeaderObj.flag_cspc:
257 if self.processingHeaderObj.flag_cspc:
258 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
258 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
259 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
259 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
260
260
261 if self.processingHeaderObj.flag_dc:
261 if self.processingHeaderObj.flag_dc:
262 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
262 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
263 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
263 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
264
264
265
265
266 if not(self.processingHeaderObj.shif_fft):
266 if not(self.processingHeaderObj.shif_fft):
267 #desplaza a la derecha en el eje 2 determinadas posiciones
267 #desplaza a la derecha en el eje 2 determinadas posiciones
268 shift = int(self.processingHeaderObj.profilesPerBlock/2)
268 shift = int(self.processingHeaderObj.profilesPerBlock/2)
269 spc = numpy.roll( spc, shift , axis=2 )
269 spc = numpy.roll( spc, shift , axis=2 )
270
270
271 if self.processingHeaderObj.flag_cspc:
271 if self.processingHeaderObj.flag_cspc:
272 #desplaza a la derecha en el eje 2 determinadas posiciones
272 #desplaza a la derecha en el eje 2 determinadas posiciones
273 cspc = numpy.roll( cspc, shift, axis=2 )
273 cspc = numpy.roll( cspc, shift, axis=2 )
274
274
275 # self.processingHeaderObj.shif_fft = True
275 # self.processingHeaderObj.shif_fft = True
276
276
277 spc = numpy.transpose( spc, (0,2,1) )
277 spc = numpy.transpose( spc, (0,2,1) )
278 self.data_spc = spc
278 self.data_spc = spc
279
279
280 if self.processingHeaderObj.flag_cspc:
280 if self.processingHeaderObj.flag_cspc:
281 cspc = numpy.transpose( cspc, (0,2,1) )
281 cspc = numpy.transpose( cspc, (0,2,1) )
282 self.data_cspc = cspc['real'] + cspc['imag']*1j
282 self.data_cspc = cspc['real'] + cspc['imag']*1j
283 else:
283 else:
284 self.data_cspc = None
284 self.data_cspc = None
285
285
286 if self.processingHeaderObj.flag_dc:
286 if self.processingHeaderObj.flag_dc:
287 self.data_dc = dc['real'] + dc['imag']*1j
287 self.data_dc = dc['real'] + dc['imag']*1j
288 else:
288 else:
289 self.data_dc = None
289 self.data_dc = None
290
290
291 self.flagIsNewFile = 0
291 self.flagIsNewFile = 0
292 self.flagIsNewBlock = 1
292 self.flagIsNewBlock = 1
293
293
294 self.nTotalBlocks += 1
294 self.nTotalBlocks += 1
295 self.nReadBlocks += 1
295 self.nReadBlocks += 1
296
296
297 return 1
297 return 1
298
298
299 def getFirstHeader(self):
299 def getFirstHeader(self):
300
300
301 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
301 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
302
302
303 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
303 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
304
304
305 # self.dataOut.ippSeconds = self.ippSeconds
305 # self.dataOut.ippSeconds = self.ippSeconds
306
306
307 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
307 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock
308
308
309 self.dataOut.dtype = self.dtype
309 self.dataOut.dtype = self.dtype
310
310
311 # self.dataOut.nPairs = self.nPairs
311 # self.dataOut.nPairs = self.nPairs
312
312
313 self.dataOut.pairsList = self.rdPairList
313 self.dataOut.pairsList = self.rdPairList
314
314
315 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
315 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock
316
316
317 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
317 self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock
318
318
319 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
319 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
320
320
321 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
321 self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt
322
322
323 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
323 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
324
324
325 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
325 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
326
326
327 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
327 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
328
328
329 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
329 self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft
330
330
331 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
331 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
332
332
333 self.dataOut.flagDeflipData = False #asumo q la data esta sin flip
333 self.dataOut.flagDeflipData = False #asumo q la data esta sin flip
334
334
335 if self.radarControllerHeaderObj.code != None:
335 if self.radarControllerHeaderObj.code is not None:
336
336
337 # self.dataOut.nCode = self.radarControllerHeaderObj.nCode
337 # self.dataOut.nCode = self.radarControllerHeaderObj.nCode
338 #
338 #
339 # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
339 # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
340 #
340 #
341 # self.dataOut.code = self.radarControllerHeaderObj.code
341 # self.dataOut.code = self.radarControllerHeaderObj.code
342
342
343 self.dataOut.flagDecodeData = True
343 self.dataOut.flagDecodeData = True
344
344
345 def getData(self):
345 def getData(self):
346 """
346 """
347 First method to execute before "RUN" is called.
347 First method to execute before "RUN" is called.
348
348
349 Copia el buffer de lectura a la clase "Spectra",
349 Copia el buffer de lectura a la clase "Spectra",
350 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
350 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
351 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
351 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
352
352
353 Return:
353 Return:
354 0 : Si no hay mas archivos disponibles
354 0 : Si no hay mas archivos disponibles
355 1 : Si hizo una buena copia del buffer
355 1 : Si hizo una buena copia del buffer
356
356
357 Affected:
357 Affected:
358 self.dataOut
358 self.dataOut
359
359
360 self.flagDiscontinuousBlock
360 self.flagDiscontinuousBlock
361 self.flagIsNewBlock
361 self.flagIsNewBlock
362 """
362 """
363
363
364 if self.flagNoMoreFiles:
364 if self.flagNoMoreFiles:
365 self.dataOut.flagNoData = True
365 self.dataOut.flagNoData = True
366 print 'Process finished'
366 print 'Process finished'
367 return 0
367 return 0
368
368
369 self.flagDiscontinuousBlock = 0
369 self.flagDiscontinuousBlock = 0
370 self.flagIsNewBlock = 0
370 self.flagIsNewBlock = 0
371
371
372 if self.__hasNotDataInBuffer():
372 if self.__hasNotDataInBuffer():
373
373
374 if not( self.readNextBlock() ):
374 if not( self.readNextBlock() ):
375 self.dataOut.flagNoData = True
375 self.dataOut.flagNoData = True
376 return 0
376 return 0
377
377
378 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
378 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
379
379
380 if self.data_dc == None:
380 if self.data_dc is None:
381 self.dataOut.flagNoData = True
381 self.dataOut.flagNoData = True
382 return 0
382 return 0
383
383
384 self.getBasicHeader()
384 self.getBasicHeader()
385
385
386 self.getFirstHeader()
386 self.getFirstHeader()
387
387
388 self.dataOut.data_spc = self.data_spc
388 self.dataOut.data_spc = self.data_spc
389
389
390 self.dataOut.data_cspc = self.data_cspc
390 self.dataOut.data_cspc = self.data_cspc
391
391
392 self.dataOut.data_dc = self.data_dc
392 self.dataOut.data_dc = self.data_dc
393
393
394 self.dataOut.flagNoData = False
394 self.dataOut.flagNoData = False
395
395
396 self.dataOut.realtime = self.online
396 self.dataOut.realtime = self.online
397
397
398 return self.dataOut.data_spc
398 return self.dataOut.data_spc
399
399
400 class SpectraWriter(JRODataWriter, Operation):
400 class SpectraWriter(JRODataWriter, Operation):
401
401
402 """
402 """
403 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
403 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
404 de los datos siempre se realiza por bloques.
404 de los datos siempre se realiza por bloques.
405 """
405 """
406
406
407 ext = ".pdata"
407 ext = ".pdata"
408
408
409 optchar = "P"
409 optchar = "P"
410
410
411 shape_spc_Buffer = None
411 shape_spc_Buffer = None
412
412
413 shape_cspc_Buffer = None
413 shape_cspc_Buffer = None
414
414
415 shape_dc_Buffer = None
415 shape_dc_Buffer = None
416
416
417 data_spc = None
417 data_spc = None
418
418
419 data_cspc = None
419 data_cspc = None
420
420
421 data_dc = None
421 data_dc = None
422
422
423 # dataOut = None
423 # dataOut = None
424
424
425 def __init__(self):
425 def __init__(self):
426 """
426 """
427 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
427 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
428
428
429 Affected:
429 Affected:
430 self.dataOut
430 self.dataOut
431 self.basicHeaderObj
431 self.basicHeaderObj
432 self.systemHeaderObj
432 self.systemHeaderObj
433 self.radarControllerHeaderObj
433 self.radarControllerHeaderObj
434 self.processingHeaderObj
434 self.processingHeaderObj
435
435
436 Return: None
436 Return: None
437 """
437 """
438
438
439 Operation.__init__(self)
439 Operation.__init__(self)
440
440
441 self.isConfig = False
441 self.isConfig = False
442
442
443 self.nTotalBlocks = 0
443 self.nTotalBlocks = 0
444
444
445 self.data_spc = None
445 self.data_spc = None
446
446
447 self.data_cspc = None
447 self.data_cspc = None
448
448
449 self.data_dc = None
449 self.data_dc = None
450
450
451 self.fp = None
451 self.fp = None
452
452
453 self.flagIsNewFile = 1
453 self.flagIsNewFile = 1
454
454
455 self.nTotalBlocks = 0
455 self.nTotalBlocks = 0
456
456
457 self.flagIsNewBlock = 0
457 self.flagIsNewBlock = 0
458
458
459 self.setFile = None
459 self.setFile = None
460
460
461 self.dtype = None
461 self.dtype = None
462
462
463 self.path = None
463 self.path = None
464
464
465 self.noMoreFiles = 0
465 self.noMoreFiles = 0
466
466
467 self.filename = None
467 self.filename = None
468
468
469 self.basicHeaderObj = BasicHeader(LOCALTIME)
469 self.basicHeaderObj = BasicHeader(LOCALTIME)
470
470
471 self.systemHeaderObj = SystemHeader()
471 self.systemHeaderObj = SystemHeader()
472
472
473 self.radarControllerHeaderObj = RadarControllerHeader()
473 self.radarControllerHeaderObj = RadarControllerHeader()
474
474
475 self.processingHeaderObj = ProcessingHeader()
475 self.processingHeaderObj = ProcessingHeader()
476
476
477
477
478 def hasAllDataInBuffer(self):
478 def hasAllDataInBuffer(self):
479 return 1
479 return 1
480
480
481
481
482 def setBlockDimension(self):
482 def setBlockDimension(self):
483 """
483 """
484 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
484 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
485
485
486 Affected:
486 Affected:
487 self.shape_spc_Buffer
487 self.shape_spc_Buffer
488 self.shape_cspc_Buffer
488 self.shape_cspc_Buffer
489 self.shape_dc_Buffer
489 self.shape_dc_Buffer
490
490
491 Return: None
491 Return: None
492 """
492 """
493 self.shape_spc_Buffer = (self.dataOut.nChannels,
493 self.shape_spc_Buffer = (self.dataOut.nChannels,
494 self.processingHeaderObj.nHeights,
494 self.processingHeaderObj.nHeights,
495 self.processingHeaderObj.profilesPerBlock)
495 self.processingHeaderObj.profilesPerBlock)
496
496
497 self.shape_cspc_Buffer = (self.dataOut.nPairs,
497 self.shape_cspc_Buffer = (self.dataOut.nPairs,
498 self.processingHeaderObj.nHeights,
498 self.processingHeaderObj.nHeights,
499 self.processingHeaderObj.profilesPerBlock)
499 self.processingHeaderObj.profilesPerBlock)
500
500
501 self.shape_dc_Buffer = (self.dataOut.nChannels,
501 self.shape_dc_Buffer = (self.dataOut.nChannels,
502 self.processingHeaderObj.nHeights)
502 self.processingHeaderObj.nHeights)
503
503
504
504
505 def writeBlock(self):
505 def writeBlock(self):
506 """
506 """
507 Escribe el buffer en el file designado
507 Escribe el buffer en el file designado
508
508
509 Affected:
509 Affected:
510 self.data_spc
510 self.data_spc
511 self.data_cspc
511 self.data_cspc
512 self.data_dc
512 self.data_dc
513 self.flagIsNewFile
513 self.flagIsNewFile
514 self.flagIsNewBlock
514 self.flagIsNewBlock
515 self.nTotalBlocks
515 self.nTotalBlocks
516 self.nWriteBlocks
516 self.nWriteBlocks
517
517
518 Return: None
518 Return: None
519 """
519 """
520
520
521 spc = numpy.transpose( self.data_spc, (0,2,1) )
521 spc = numpy.transpose( self.data_spc, (0,2,1) )
522 if not( self.processingHeaderObj.shif_fft ):
522 if not( self.processingHeaderObj.shif_fft ):
523 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
523 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
524 data = spc.reshape((-1))
524 data = spc.reshape((-1))
525 data = data.astype(self.dtype[0])
525 data = data.astype(self.dtype[0])
526 data.tofile(self.fp)
526 data.tofile(self.fp)
527
527
528 if self.data_cspc != None:
528 if self.data_cspc is not None:
529 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
529 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
530 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
530 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
531 if not( self.processingHeaderObj.shif_fft ):
531 if not( self.processingHeaderObj.shif_fft ):
532 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
532 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
533 data['real'] = cspc.real
533 data['real'] = cspc.real
534 data['imag'] = cspc.imag
534 data['imag'] = cspc.imag
535 data = data.reshape((-1))
535 data = data.reshape((-1))
536 data.tofile(self.fp)
536 data.tofile(self.fp)
537
537
538 if self.data_dc != None:
538 if self.data_dc is not None:
539 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
539 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
540 dc = self.data_dc
540 dc = self.data_dc
541 data['real'] = dc.real
541 data['real'] = dc.real
542 data['imag'] = dc.imag
542 data['imag'] = dc.imag
543 data = data.reshape((-1))
543 data = data.reshape((-1))
544 data.tofile(self.fp)
544 data.tofile(self.fp)
545
545
546 self.data_spc.fill(0)
546 self.data_spc.fill(0)
547
547
548 if self.data_dc != None:
548 if self.data_dc is not None:
549 self.data_dc.fill(0)
549 self.data_dc.fill(0)
550
550
551 if self.data_cspc != None:
551 if self.data_cspc is not None:
552 self.data_cspc.fill(0)
552 self.data_cspc.fill(0)
553
553
554 self.flagIsNewFile = 0
554 self.flagIsNewFile = 0
555 self.flagIsNewBlock = 1
555 self.flagIsNewBlock = 1
556 self.nTotalBlocks += 1
556 self.nTotalBlocks += 1
557 self.nWriteBlocks += 1
557 self.nWriteBlocks += 1
558 self.blockIndex += 1
558 self.blockIndex += 1
559
559
560 # print "[Writing] Block = %d04" %self.blockIndex
560 # print "[Writing] Block = %d04" %self.blockIndex
561
561
562 def putData(self):
562 def putData(self):
563 """
563 """
564 Setea un bloque de datos y luego los escribe en un file
564 Setea un bloque de datos y luego los escribe en un file
565
565
566 Affected:
566 Affected:
567 self.data_spc
567 self.data_spc
568 self.data_cspc
568 self.data_cspc
569 self.data_dc
569 self.data_dc
570
570
571 Return:
571 Return:
572 0 : Si no hay data o no hay mas files que puedan escribirse
572 0 : Si no hay data o no hay mas files que puedan escribirse
573 1 : Si se escribio la data de un bloque en un file
573 1 : Si se escribio la data de un bloque en un file
574 """
574 """
575
575
576 if self.dataOut.flagNoData:
576 if self.dataOut.flagNoData:
577 return 0
577 return 0
578
578
579 self.flagIsNewBlock = 0
579 self.flagIsNewBlock = 0
580
580
581 if self.dataOut.flagDiscontinuousBlock:
581 if self.dataOut.flagDiscontinuousBlock:
582 self.data_spc.fill(0)
582 self.data_spc.fill(0)
583 self.data_cspc.fill(0)
583 self.data_cspc.fill(0)
584 self.data_dc.fill(0)
584 self.data_dc.fill(0)
585 self.setNextFile()
585 self.setNextFile()
586
586
587 if self.flagIsNewFile == 0:
587 if self.flagIsNewFile == 0:
588 self.setBasicHeader()
588 self.setBasicHeader()
589
589
590 self.data_spc = self.dataOut.data_spc.copy()
590 self.data_spc = self.dataOut.data_spc.copy()
591 if self.dataOut.data_cspc != None:
591 if self.dataOut.data_cspc is not None:
592 self.data_cspc = self.dataOut.data_cspc.copy()
592 self.data_cspc = self.dataOut.data_cspc.copy()
593 self.data_dc = self.dataOut.data_dc.copy()
593 self.data_dc = self.dataOut.data_dc.copy()
594
594
595 # #self.processingHeaderObj.dataBlocksPerFile)
595 # #self.processingHeaderObj.dataBlocksPerFile)
596 if self.hasAllDataInBuffer():
596 if self.hasAllDataInBuffer():
597 # self.setFirstHeader()
597 # self.setFirstHeader()
598 self.writeNextBlock()
598 self.writeNextBlock()
599
599
600 return 1
600 return 1
601
601
602
602
603 def __getProcessFlags(self):
603 def __getProcessFlags(self):
604
604
605 processFlags = 0
605 processFlags = 0
606
606
607 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
607 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
608 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
608 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
609 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
609 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
610 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
610 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
611 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
611 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
612 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
612 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
613
613
614 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
614 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
615
615
616
616
617
617
618 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
618 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
619 PROCFLAG.DATATYPE_SHORT,
619 PROCFLAG.DATATYPE_SHORT,
620 PROCFLAG.DATATYPE_LONG,
620 PROCFLAG.DATATYPE_LONG,
621 PROCFLAG.DATATYPE_INT64,
621 PROCFLAG.DATATYPE_INT64,
622 PROCFLAG.DATATYPE_FLOAT,
622 PROCFLAG.DATATYPE_FLOAT,
623 PROCFLAG.DATATYPE_DOUBLE]
623 PROCFLAG.DATATYPE_DOUBLE]
624
624
625
625
626 for index in range(len(dtypeList)):
626 for index in range(len(dtypeList)):
627 if self.dataOut.dtype == dtypeList[index]:
627 if self.dataOut.dtype == dtypeList[index]:
628 dtypeValue = datatypeValueList[index]
628 dtypeValue = datatypeValueList[index]
629 break
629 break
630
630
631 processFlags += dtypeValue
631 processFlags += dtypeValue
632
632
633 if self.dataOut.flagDecodeData:
633 if self.dataOut.flagDecodeData:
634 processFlags += PROCFLAG.DECODE_DATA
634 processFlags += PROCFLAG.DECODE_DATA
635
635
636 if self.dataOut.flagDeflipData:
636 if self.dataOut.flagDeflipData:
637 processFlags += PROCFLAG.DEFLIP_DATA
637 processFlags += PROCFLAG.DEFLIP_DATA
638
638
639 if self.dataOut.code != None:
639 if self.dataOut.code is not None:
640 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
640 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
641
641
642 if self.dataOut.nIncohInt > 1:
642 if self.dataOut.nIncohInt > 1:
643 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
643 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
644
644
645 if self.dataOut.data_dc != None:
645 if self.dataOut.data_dc is not None:
646 processFlags += PROCFLAG.SAVE_CHANNELS_DC
646 processFlags += PROCFLAG.SAVE_CHANNELS_DC
647
647
648 return processFlags
648 return processFlags
649
649
650
650
651 def __getBlockSize(self):
651 def __getBlockSize(self):
652 '''
652 '''
653 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
653 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
654 '''
654 '''
655
655
656 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
656 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
657 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
657 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
658 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
658 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
659 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
659 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
660 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
660 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
661 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
661 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
662
662
663 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
663 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
664 datatypeValueList = [1,2,4,8,4,8]
664 datatypeValueList = [1,2,4,8,4,8]
665 for index in range(len(dtypeList)):
665 for index in range(len(dtypeList)):
666 if self.dataOut.dtype == dtypeList[index]:
666 if self.dataOut.dtype == dtypeList[index]:
667 datatypeValue = datatypeValueList[index]
667 datatypeValue = datatypeValueList[index]
668 break
668 break
669
669
670
670
671 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
671 pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints
672
672
673 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
673 pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write)
674 blocksize = (pts2write_SelfSpectra*datatypeValue)
674 blocksize = (pts2write_SelfSpectra*datatypeValue)
675
675
676 if self.dataOut.data_cspc != None:
676 if self.dataOut.data_cspc is not None:
677 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
677 pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write)
678 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
678 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
679
679
680 if self.dataOut.data_dc != None:
680 if self.dataOut.data_dc is not None:
681 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
681 pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights)
682 blocksize += (pts2write_DCchannels*datatypeValue*2)
682 blocksize += (pts2write_DCchannels*datatypeValue*2)
683
683
684 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
684 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
685
685
686 return blocksize
686 return blocksize
687
687
688 def setFirstHeader(self):
688 def setFirstHeader(self):
689
689
690 """
690 """
691 Obtiene una copia del First Header
691 Obtiene una copia del First Header
692
692
693 Affected:
693 Affected:
694 self.systemHeaderObj
694 self.systemHeaderObj
695 self.radarControllerHeaderObj
695 self.radarControllerHeaderObj
696 self.dtype
696 self.dtype
697
697
698 Return:
698 Return:
699 None
699 None
700 """
700 """
701
701
702 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
702 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
703 self.systemHeaderObj.nChannels = self.dataOut.nChannels
703 self.systemHeaderObj.nChannels = self.dataOut.nChannels
704 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
704 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
705 old_code_size = self.dataOut.radarControllerHeaderObj.code_size
705 old_code_size = self.dataOut.radarControllerHeaderObj.code_size
706 new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4
706 new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4
707 self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size
707 self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size
708
708
709 self.setBasicHeader()
709 self.setBasicHeader()
710
710
711 processingHeaderSize = 40 # bytes
711 processingHeaderSize = 40 # bytes
712 self.processingHeaderObj.dtype = 1 # Spectra
712 self.processingHeaderObj.dtype = 1 # Spectra
713 self.processingHeaderObj.blockSize = self.__getBlockSize()
713 self.processingHeaderObj.blockSize = self.__getBlockSize()
714 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
714 self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints
715 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
715 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
716 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
716 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
717 self.processingHeaderObj.processFlags = self.__getProcessFlags()
717 self.processingHeaderObj.processFlags = self.__getProcessFlags()
718 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
718 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval
719 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
719 self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt
720 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
720 self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels
721 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
721 self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT
722
722
723 if self.processingHeaderObj.totalSpectra > 0:
723 if self.processingHeaderObj.totalSpectra > 0:
724 channelList = []
724 channelList = []
725 for channel in range(self.dataOut.nChannels):
725 for channel in range(self.dataOut.nChannels):
726 channelList.append(channel)
726 channelList.append(channel)
727 channelList.append(channel)
727 channelList.append(channel)
728
728
729 pairsList = []
729 pairsList = []
730 if self.dataOut.nPairs > 0:
730 if self.dataOut.nPairs > 0:
731 for pair in self.dataOut.pairsList:
731 for pair in self.dataOut.pairsList:
732 pairsList.append(pair[0])
732 pairsList.append(pair[0])
733 pairsList.append(pair[1])
733 pairsList.append(pair[1])
734
734
735 spectraComb = channelList + pairsList
735 spectraComb = channelList + pairsList
736 spectraComb = numpy.array(spectraComb,dtype="u1")
736 spectraComb = numpy.array(spectraComb,dtype="u1")
737 self.processingHeaderObj.spectraComb = spectraComb
737 self.processingHeaderObj.spectraComb = spectraComb
738 sizeOfSpcComb = len(spectraComb)
738 sizeOfSpcComb = len(spectraComb)
739 processingHeaderSize += sizeOfSpcComb
739 processingHeaderSize += sizeOfSpcComb
740
740
741 # The processing header should not have information about code
741 # The processing header should not have information about code
742 # if self.dataOut.code != None:
742 # if self.dataOut.code is not None:
743 # self.processingHeaderObj.code = self.dataOut.code
743 # self.processingHeaderObj.code = self.dataOut.code
744 # self.processingHeaderObj.nCode = self.dataOut.nCode
744 # self.processingHeaderObj.nCode = self.dataOut.nCode
745 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
745 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
746 # nCodeSize = 4 # bytes
746 # nCodeSize = 4 # bytes
747 # nBaudSize = 4 # bytes
747 # nBaudSize = 4 # bytes
748 # codeSize = 4 # bytes
748 # codeSize = 4 # bytes
749 # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
749 # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud)
750 # processingHeaderSize += sizeOfCode
750 # processingHeaderSize += sizeOfCode
751
751
752 if self.processingHeaderObj.nWindows != 0:
752 if self.processingHeaderObj.nWindows != 0:
753 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
753 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
754 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
754 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
755 self.processingHeaderObj.nHeights = self.dataOut.nHeights
755 self.processingHeaderObj.nHeights = self.dataOut.nHeights
756 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
756 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
757 sizeOfFirstHeight = 4
757 sizeOfFirstHeight = 4
758 sizeOfdeltaHeight = 4
758 sizeOfdeltaHeight = 4
759 sizeOfnHeights = 4
759 sizeOfnHeights = 4
760 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
760 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
761 processingHeaderSize += sizeOfWindows
761 processingHeaderSize += sizeOfWindows
762
762
763 self.processingHeaderObj.size = processingHeaderSize
763 self.processingHeaderObj.size = processingHeaderSize
764
764
@@ -1,652 +1,652
1 '''
1 '''
2 Created on Jul 2, 2014
2 Created on Jul 2, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6
6
7 import numpy
7 import numpy
8
8
9 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
9 from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter
10 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
10 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
11 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
11 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
12 from schainpy.model.data.jrodata import Voltage
12 from schainpy.model.data.jrodata import Voltage
13
13
14 class VoltageReader(JRODataReader, ProcessingUnit):
14 class VoltageReader(JRODataReader, ProcessingUnit):
15 """
15 """
16 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
16 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
17 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
17 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
18 perfiles*alturas*canales) son almacenados en la variable "buffer".
18 perfiles*alturas*canales) son almacenados en la variable "buffer".
19
19
20 perfiles * alturas * canales
20 perfiles * alturas * canales
21
21
22 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
22 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
23 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
23 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
24 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
24 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
25 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
25 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
26
26
27 Example:
27 Example:
28
28
29 dpath = "/home/myuser/data"
29 dpath = "/home/myuser/data"
30
30
31 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
31 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
32
32
33 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
33 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
34
34
35 readerObj = VoltageReader()
35 readerObj = VoltageReader()
36
36
37 readerObj.setup(dpath, startTime, endTime)
37 readerObj.setup(dpath, startTime, endTime)
38
38
39 while(True):
39 while(True):
40
40
41 #to get one profile
41 #to get one profile
42 profile = readerObj.getData()
42 profile = readerObj.getData()
43
43
44 #print the profile
44 #print the profile
45 print profile
45 print profile
46
46
47 #If you want to see all datablock
47 #If you want to see all datablock
48 print readerObj.datablock
48 print readerObj.datablock
49
49
50 if readerObj.flagNoMoreFiles:
50 if readerObj.flagNoMoreFiles:
51 break
51 break
52
52
53 """
53 """
54
54
55 ext = ".r"
55 ext = ".r"
56
56
57 optchar = "D"
57 optchar = "D"
58 dataOut = None
58 dataOut = None
59
59
60
60
61 def __init__(self):
61 def __init__(self):
62 """
62 """
63 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
63 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
64
64
65 Input:
65 Input:
66 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
66 dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para
67 almacenar un perfil de datos cada vez que se haga un requerimiento
67 almacenar un perfil de datos cada vez que se haga un requerimiento
68 (getData). El perfil sera obtenido a partir del buffer de datos,
68 (getData). El perfil sera obtenido a partir del buffer de datos,
69 si el buffer esta vacio se hara un nuevo proceso de lectura de un
69 si el buffer esta vacio se hara un nuevo proceso de lectura de un
70 bloque de datos.
70 bloque de datos.
71 Si este parametro no es pasado se creara uno internamente.
71 Si este parametro no es pasado se creara uno internamente.
72
72
73 Variables afectadas:
73 Variables afectadas:
74 self.dataOut
74 self.dataOut
75
75
76 Return:
76 Return:
77 None
77 None
78 """
78 """
79
79
80 ProcessingUnit.__init__(self)
80 ProcessingUnit.__init__(self)
81
81
82 self.isConfig = False
82 self.isConfig = False
83
83
84 self.datablock = None
84 self.datablock = None
85
85
86 self.utc = 0
86 self.utc = 0
87
87
88 self.ext = ".r"
88 self.ext = ".r"
89
89
90 self.optchar = "D"
90 self.optchar = "D"
91
91
92 self.basicHeaderObj = BasicHeader(LOCALTIME)
92 self.basicHeaderObj = BasicHeader(LOCALTIME)
93
93
94 self.systemHeaderObj = SystemHeader()
94 self.systemHeaderObj = SystemHeader()
95
95
96 self.radarControllerHeaderObj = RadarControllerHeader()
96 self.radarControllerHeaderObj = RadarControllerHeader()
97
97
98 self.processingHeaderObj = ProcessingHeader()
98 self.processingHeaderObj = ProcessingHeader()
99
99
100 self.online = 0
100 self.online = 0
101
101
102 self.fp = None
102 self.fp = None
103
103
104 self.idFile = None
104 self.idFile = None
105
105
106 self.dtype = None
106 self.dtype = None
107
107
108 self.fileSizeByHeader = None
108 self.fileSizeByHeader = None
109
109
110 self.filenameList = []
110 self.filenameList = []
111
111
112 self.filename = None
112 self.filename = None
113
113
114 self.fileSize = None
114 self.fileSize = None
115
115
116 self.firstHeaderSize = 0
116 self.firstHeaderSize = 0
117
117
118 self.basicHeaderSize = 24
118 self.basicHeaderSize = 24
119
119
120 self.pathList = []
120 self.pathList = []
121
121
122 self.filenameList = []
122 self.filenameList = []
123
123
124 self.lastUTTime = 0
124 self.lastUTTime = 0
125
125
126 self.maxTimeStep = 30
126 self.maxTimeStep = 30
127
127
128 self.flagNoMoreFiles = 0
128 self.flagNoMoreFiles = 0
129
129
130 self.set = 0
130 self.set = 0
131
131
132 self.path = None
132 self.path = None
133
133
134 self.profileIndex = 2**32-1
134 self.profileIndex = 2**32-1
135
135
136 self.delay = 3 #seconds
136 self.delay = 3 #seconds
137
137
138 self.nTries = 3 #quantity tries
138 self.nTries = 3 #quantity tries
139
139
140 self.nFiles = 3 #number of files for searching
140 self.nFiles = 3 #number of files for searching
141
141
142 self.nReadBlocks = 0
142 self.nReadBlocks = 0
143
143
144 self.flagIsNewFile = 1
144 self.flagIsNewFile = 1
145
145
146 self.__isFirstTimeOnline = 1
146 self.__isFirstTimeOnline = 1
147
147
148 # self.ippSeconds = 0
148 # self.ippSeconds = 0
149
149
150 self.flagDiscontinuousBlock = 0
150 self.flagDiscontinuousBlock = 0
151
151
152 self.flagIsNewBlock = 0
152 self.flagIsNewBlock = 0
153
153
154 self.nTotalBlocks = 0
154 self.nTotalBlocks = 0
155
155
156 self.blocksize = 0
156 self.blocksize = 0
157
157
158 self.dataOut = self.createObjByDefault()
158 self.dataOut = self.createObjByDefault()
159
159
160 self.nTxs = 1
160 self.nTxs = 1
161
161
162 self.txIndex = 0
162 self.txIndex = 0
163
163
164 def createObjByDefault(self):
164 def createObjByDefault(self):
165
165
166 dataObj = Voltage()
166 dataObj = Voltage()
167
167
168 return dataObj
168 return dataObj
169
169
170 def __hasNotDataInBuffer(self):
170 def __hasNotDataInBuffer(self):
171
171
172 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
172 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
173 return 1
173 return 1
174
174
175 return 0
175 return 0
176
176
177
177
178 def getBlockDimension(self):
178 def getBlockDimension(self):
179 """
179 """
180 Obtiene la cantidad de puntos a leer por cada bloque de datos
180 Obtiene la cantidad de puntos a leer por cada bloque de datos
181
181
182 Affected:
182 Affected:
183 self.blocksize
183 self.blocksize
184
184
185 Return:
185 Return:
186 None
186 None
187 """
187 """
188 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
188 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
189 self.blocksize = pts2read
189 self.blocksize = pts2read
190
190
191
191
192 def readBlock(self):
192 def readBlock(self):
193 """
193 """
194 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
194 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
195 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
195 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
196 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
196 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
197 es seteado a 0
197 es seteado a 0
198
198
199 Inputs:
199 Inputs:
200 None
200 None
201
201
202 Return:
202 Return:
203 None
203 None
204
204
205 Affected:
205 Affected:
206 self.profileIndex
206 self.profileIndex
207 self.datablock
207 self.datablock
208 self.flagIsNewFile
208 self.flagIsNewFile
209 self.flagIsNewBlock
209 self.flagIsNewBlock
210 self.nTotalBlocks
210 self.nTotalBlocks
211
211
212 Exceptions:
212 Exceptions:
213 Si un bloque leido no es un bloque valido
213 Si un bloque leido no es un bloque valido
214 """
214 """
215 current_pointer_location = self.fp.tell()
215 current_pointer_location = self.fp.tell()
216 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
216 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
217
217
218 try:
218 try:
219 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
219 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
220 except:
220 except:
221 #print "The read block (%3d) has not enough data" %self.nReadBlocks
221 #print "The read block (%3d) has not enough data" %self.nReadBlocks
222
222
223 if self.waitDataBlock(pointer_location=current_pointer_location):
223 if self.waitDataBlock(pointer_location=current_pointer_location):
224 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
224 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
225 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
225 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
226 # return 0
226 # return 0
227
227
228 junk = numpy.transpose(junk, (2,0,1))
228 junk = numpy.transpose(junk, (2,0,1))
229 self.datablock = junk['real'] + junk['imag']*1j
229 self.datablock = junk['real'] + junk['imag']*1j
230
230
231 self.profileIndex = 0
231 self.profileIndex = 0
232
232
233 self.flagIsNewFile = 0
233 self.flagIsNewFile = 0
234 self.flagIsNewBlock = 1
234 self.flagIsNewBlock = 1
235
235
236 self.nTotalBlocks += 1
236 self.nTotalBlocks += 1
237 self.nReadBlocks += 1
237 self.nReadBlocks += 1
238
238
239 return 1
239 return 1
240
240
241 def getFirstHeader(self):
241 def getFirstHeader(self):
242
242
243 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
243 self.dataOut.systemHeaderObj = self.systemHeaderObj.copy()
244
244
245 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
245 self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
246
246
247 if self.nTxs > 1:
247 if self.nTxs > 1:
248 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
248 self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
249
249
250 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
250 # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt
251 #
251 #
252 # if self.radarControllerHeaderObj.code != None:
252 # if self.radarControllerHeaderObj.code is not None:
253 #
253 #
254 # self.dataOut.nCode = self.radarControllerHeaderObj.nCode
254 # self.dataOut.nCode = self.radarControllerHeaderObj.nCode
255 #
255 #
256 # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
256 # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud
257 #
257 #
258 # self.dataOut.code = self.radarControllerHeaderObj.code
258 # self.dataOut.code = self.radarControllerHeaderObj.code
259
259
260 self.dataOut.dtype = self.dtype
260 self.dataOut.dtype = self.dtype
261
261
262 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
262 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
263
263
264 if self.processingHeaderObj.nHeights % self.nTxs != 0:
264 if self.processingHeaderObj.nHeights % self.nTxs != 0:
265 raise ValueError, "nTxs (%d) should be a multiple of nHeights (%d)" %(self.nTxs, self.processingHeaderObj.nHeights)
265 raise ValueError, "nTxs (%d) should be a multiple of nHeights (%d)" %(self.nTxs, self.processingHeaderObj.nHeights)
266
266
267 xf = self.processingHeaderObj.firstHeight + int(self.processingHeaderObj.nHeights/self.nTxs)*self.processingHeaderObj.deltaHeight
267 xf = self.processingHeaderObj.firstHeight + int(self.processingHeaderObj.nHeights/self.nTxs)*self.processingHeaderObj.deltaHeight
268
268
269 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
269 self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
270
270
271 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
271 self.dataOut.channelList = range(self.systemHeaderObj.nChannels)
272
272
273 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
273 self.dataOut.nCohInt = self.processingHeaderObj.nCohInt
274
274
275 self.dataOut.flagShiftFFT = False
275 self.dataOut.flagShiftFFT = False
276
276
277 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
277 self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada
278
278
279 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
279 self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip
280
280
281 self.dataOut.flagShiftFFT = False
281 self.dataOut.flagShiftFFT = False
282
282
283 def getData(self):
283 def getData(self):
284 """
284 """
285 getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut
285 getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut
286 del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos
286 del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos
287 en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando
287 en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando
288 "readNextBlock"
288 "readNextBlock"
289
289
290 Ademas incrementa el contador del buffer "self.profileIndex" en 1.
290 Ademas incrementa el contador del buffer "self.profileIndex" en 1.
291
291
292 Return:
292 Return:
293
293
294 Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex
294 Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex
295 es igual al total de perfiles leidos desde el archivo.
295 es igual al total de perfiles leidos desde el archivo.
296
296
297 Si self.getByBlock == False:
297 Si self.getByBlock == False:
298
298
299 self.dataOut.data = buffer[:, thisProfile, :]
299 self.dataOut.data = buffer[:, thisProfile, :]
300
300
301 shape = [nChannels, nHeis]
301 shape = [nChannels, nHeis]
302
302
303 Si self.getByBlock == True:
303 Si self.getByBlock == True:
304
304
305 self.dataOut.data = buffer[:, :, :]
305 self.dataOut.data = buffer[:, :, :]
306
306
307 shape = [nChannels, nProfiles, nHeis]
307 shape = [nChannels, nProfiles, nHeis]
308
308
309 Variables afectadas:
309 Variables afectadas:
310 self.dataOut
310 self.dataOut
311 self.profileIndex
311 self.profileIndex
312
312
313 Affected:
313 Affected:
314 self.dataOut
314 self.dataOut
315 self.profileIndex
315 self.profileIndex
316 self.flagDiscontinuousBlock
316 self.flagDiscontinuousBlock
317 self.flagIsNewBlock
317 self.flagIsNewBlock
318 """
318 """
319
319
320 if self.flagNoMoreFiles:
320 if self.flagNoMoreFiles:
321 self.dataOut.flagNoData = True
321 self.dataOut.flagNoData = True
322 print 'Process finished'
322 print 'Process finished'
323 return 0
323 return 0
324
324
325 self.flagDiscontinuousBlock = 0
325 self.flagDiscontinuousBlock = 0
326 self.flagIsNewBlock = 0
326 self.flagIsNewBlock = 0
327
327
328 if self.__hasNotDataInBuffer():
328 if self.__hasNotDataInBuffer():
329
329
330 if not( self.readNextBlock() ):
330 if not( self.readNextBlock() ):
331 return 0
331 return 0
332
332
333 self.getFirstHeader()
333 self.getFirstHeader()
334
334
335 if self.datablock is None:
335 if self.datablock is None:
336 self.dataOut.flagNoData = True
336 self.dataOut.flagNoData = True
337 return 0
337 return 0
338
338
339 if not self.getByBlock:
339 if not self.getByBlock:
340
340
341 """
341 """
342 Return profile by profile
342 Return profile by profile
343
343
344 If nTxs > 1 then one profile is divided by nTxs and number of total
344 If nTxs > 1 then one profile is divided by nTxs and number of total
345 blocks is increased by nTxs (nProfiles *= nTxs)
345 blocks is increased by nTxs (nProfiles *= nTxs)
346 """
346 """
347 self.dataOut.flagDataAsBlock = False
347 self.dataOut.flagDataAsBlock = False
348
348
349 if self.nTxs == 1:
349 if self.nTxs == 1:
350 self.dataOut.data = self.datablock[:,self.profileIndex,:]
350 self.dataOut.data = self.datablock[:,self.profileIndex,:]
351 self.dataOut.profileIndex = self.profileIndex
351 self.dataOut.profileIndex = self.profileIndex
352
352
353 self.profileIndex += 1
353 self.profileIndex += 1
354
354
355 else:
355 else:
356 iniHei_ForThisTx = (self.txIndex)*int(self.processingHeaderObj.nHeights/self.nTxs)
356 iniHei_ForThisTx = (self.txIndex)*int(self.processingHeaderObj.nHeights/self.nTxs)
357 endHei_ForThisTx = (self.txIndex+1)*int(self.processingHeaderObj.nHeights/self.nTxs)
357 endHei_ForThisTx = (self.txIndex+1)*int(self.processingHeaderObj.nHeights/self.nTxs)
358
358
359 # print iniHei_ForThisTx, endHei_ForThisTx
359 # print iniHei_ForThisTx, endHei_ForThisTx
360
360
361 self.dataOut.data = self.datablock[:, self.profileIndex, iniHei_ForThisTx:endHei_ForThisTx]
361 self.dataOut.data = self.datablock[:, self.profileIndex, iniHei_ForThisTx:endHei_ForThisTx]
362 self.dataOut.profileIndex = self.profileIndex*self.nTxs + self.txIndex
362 self.dataOut.profileIndex = self.profileIndex*self.nTxs + self.txIndex
363
363
364 self.txIndex += 1
364 self.txIndex += 1
365
365
366 if self.txIndex == self.nTxs:
366 if self.txIndex == self.nTxs:
367 self.txIndex = 0
367 self.txIndex = 0
368 self.profileIndex += 1
368 self.profileIndex += 1
369
369
370 else:
370 else:
371 """
371 """
372 Return all block
372 Return all block
373 """
373 """
374 self.dataOut.flagDataAsBlock = True
374 self.dataOut.flagDataAsBlock = True
375 self.dataOut.data = self.datablock
375 self.dataOut.data = self.datablock
376 self.dataOut.profileIndex = self.processingHeaderObj.profilesPerBlock
376 self.dataOut.profileIndex = self.processingHeaderObj.profilesPerBlock
377
377
378 self.profileIndex = self.processingHeaderObj.profilesPerBlock
378 self.profileIndex = self.processingHeaderObj.profilesPerBlock
379
379
380 self.dataOut.flagNoData = False
380 self.dataOut.flagNoData = False
381
381
382 self.getBasicHeader()
382 self.getBasicHeader()
383
383
384 self.dataOut.realtime = self.online
384 self.dataOut.realtime = self.online
385
385
386 return self.dataOut.data
386 return self.dataOut.data
387
387
388 class VoltageWriter(JRODataWriter, Operation):
388 class VoltageWriter(JRODataWriter, Operation):
389 """
389 """
390 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
390 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
391 de los datos siempre se realiza por bloques.
391 de los datos siempre se realiza por bloques.
392 """
392 """
393
393
394 ext = ".r"
394 ext = ".r"
395
395
396 optchar = "D"
396 optchar = "D"
397
397
398 shapeBuffer = None
398 shapeBuffer = None
399
399
400
400
401 def __init__(self):
401 def __init__(self):
402 """
402 """
403 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
403 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
404
404
405 Affected:
405 Affected:
406 self.dataOut
406 self.dataOut
407
407
408 Return: None
408 Return: None
409 """
409 """
410 Operation.__init__(self)
410 Operation.__init__(self)
411
411
412 self.nTotalBlocks = 0
412 self.nTotalBlocks = 0
413
413
414 self.profileIndex = 0
414 self.profileIndex = 0
415
415
416 self.isConfig = False
416 self.isConfig = False
417
417
418 self.fp = None
418 self.fp = None
419
419
420 self.flagIsNewFile = 1
420 self.flagIsNewFile = 1
421
421
422 self.nTotalBlocks = 0
422 self.nTotalBlocks = 0
423
423
424 self.flagIsNewBlock = 0
424 self.flagIsNewBlock = 0
425
425
426 self.setFile = None
426 self.setFile = None
427
427
428 self.dtype = None
428 self.dtype = None
429
429
430 self.path = None
430 self.path = None
431
431
432 self.filename = None
432 self.filename = None
433
433
434 self.basicHeaderObj = BasicHeader(LOCALTIME)
434 self.basicHeaderObj = BasicHeader(LOCALTIME)
435
435
436 self.systemHeaderObj = SystemHeader()
436 self.systemHeaderObj = SystemHeader()
437
437
438 self.radarControllerHeaderObj = RadarControllerHeader()
438 self.radarControllerHeaderObj = RadarControllerHeader()
439
439
440 self.processingHeaderObj = ProcessingHeader()
440 self.processingHeaderObj = ProcessingHeader()
441
441
442 def hasAllDataInBuffer(self):
442 def hasAllDataInBuffer(self):
443 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
443 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
444 return 1
444 return 1
445 return 0
445 return 0
446
446
447
447
448 def setBlockDimension(self):
448 def setBlockDimension(self):
449 """
449 """
450 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
450 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
451
451
452 Affected:
452 Affected:
453 self.shape_spc_Buffer
453 self.shape_spc_Buffer
454 self.shape_cspc_Buffer
454 self.shape_cspc_Buffer
455 self.shape_dc_Buffer
455 self.shape_dc_Buffer
456
456
457 Return: None
457 Return: None
458 """
458 """
459 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
459 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
460 self.processingHeaderObj.nHeights,
460 self.processingHeaderObj.nHeights,
461 self.systemHeaderObj.nChannels)
461 self.systemHeaderObj.nChannels)
462
462
463 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
463 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
464 self.processingHeaderObj.profilesPerBlock,
464 self.processingHeaderObj.profilesPerBlock,
465 self.processingHeaderObj.nHeights),
465 self.processingHeaderObj.nHeights),
466 dtype=numpy.dtype('complex64'))
466 dtype=numpy.dtype('complex64'))
467
467
468 def writeBlock(self):
468 def writeBlock(self):
469 """
469 """
470 Escribe el buffer en el file designado
470 Escribe el buffer en el file designado
471
471
472 Affected:
472 Affected:
473 self.profileIndex
473 self.profileIndex
474 self.flagIsNewFile
474 self.flagIsNewFile
475 self.flagIsNewBlock
475 self.flagIsNewBlock
476 self.nTotalBlocks
476 self.nTotalBlocks
477 self.blockIndex
477 self.blockIndex
478
478
479 Return: None
479 Return: None
480 """
480 """
481 data = numpy.zeros( self.shapeBuffer, self.dtype )
481 data = numpy.zeros( self.shapeBuffer, self.dtype )
482
482
483 junk = numpy.transpose(self.datablock, (1,2,0))
483 junk = numpy.transpose(self.datablock, (1,2,0))
484
484
485 data['real'] = junk.real
485 data['real'] = junk.real
486 data['imag'] = junk.imag
486 data['imag'] = junk.imag
487
487
488 data = data.reshape( (-1) )
488 data = data.reshape( (-1) )
489
489
490 data.tofile( self.fp )
490 data.tofile( self.fp )
491
491
492 self.datablock.fill(0)
492 self.datablock.fill(0)
493
493
494 self.profileIndex = 0
494 self.profileIndex = 0
495 self.flagIsNewFile = 0
495 self.flagIsNewFile = 0
496 self.flagIsNewBlock = 1
496 self.flagIsNewBlock = 1
497
497
498 self.blockIndex += 1
498 self.blockIndex += 1
499 self.nTotalBlocks += 1
499 self.nTotalBlocks += 1
500
500
501 # print "[Writing] Block = %04d" %self.blockIndex
501 # print "[Writing] Block = %04d" %self.blockIndex
502
502
503 def putData(self):
503 def putData(self):
504 """
504 """
505 Setea un bloque de datos y luego los escribe en un file
505 Setea un bloque de datos y luego los escribe en un file
506
506
507 Affected:
507 Affected:
508 self.flagIsNewBlock
508 self.flagIsNewBlock
509 self.profileIndex
509 self.profileIndex
510
510
511 Return:
511 Return:
512 0 : Si no hay data o no hay mas files que puedan escribirse
512 0 : Si no hay data o no hay mas files que puedan escribirse
513 1 : Si se escribio la data de un bloque en un file
513 1 : Si se escribio la data de un bloque en un file
514 """
514 """
515 if self.dataOut.flagNoData:
515 if self.dataOut.flagNoData:
516 return 0
516 return 0
517
517
518 self.flagIsNewBlock = 0
518 self.flagIsNewBlock = 0
519
519
520 if self.dataOut.flagDiscontinuousBlock:
520 if self.dataOut.flagDiscontinuousBlock:
521 self.datablock.fill(0)
521 self.datablock.fill(0)
522 self.profileIndex = 0
522 self.profileIndex = 0
523 self.setNextFile()
523 self.setNextFile()
524
524
525 if self.profileIndex == 0:
525 if self.profileIndex == 0:
526 self.setBasicHeader()
526 self.setBasicHeader()
527
527
528 self.datablock[:,self.profileIndex,:] = self.dataOut.data
528 self.datablock[:,self.profileIndex,:] = self.dataOut.data
529
529
530 self.profileIndex += 1
530 self.profileIndex += 1
531
531
532 if self.hasAllDataInBuffer():
532 if self.hasAllDataInBuffer():
533 #if self.flagIsNewFile:
533 #if self.flagIsNewFile:
534 self.writeNextBlock()
534 self.writeNextBlock()
535 # self.setFirstHeader()
535 # self.setFirstHeader()
536
536
537 return 1
537 return 1
538
538
539 def __getProcessFlags(self):
539 def __getProcessFlags(self):
540
540
541 processFlags = 0
541 processFlags = 0
542
542
543 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
543 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
544 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
544 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
545 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
545 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
546 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
546 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
547 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
547 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
548 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
548 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
549
549
550 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
550 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
551
551
552
552
553
553
554 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
554 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
555 PROCFLAG.DATATYPE_SHORT,
555 PROCFLAG.DATATYPE_SHORT,
556 PROCFLAG.DATATYPE_LONG,
556 PROCFLAG.DATATYPE_LONG,
557 PROCFLAG.DATATYPE_INT64,
557 PROCFLAG.DATATYPE_INT64,
558 PROCFLAG.DATATYPE_FLOAT,
558 PROCFLAG.DATATYPE_FLOAT,
559 PROCFLAG.DATATYPE_DOUBLE]
559 PROCFLAG.DATATYPE_DOUBLE]
560
560
561
561
562 for index in range(len(dtypeList)):
562 for index in range(len(dtypeList)):
563 if self.dataOut.dtype == dtypeList[index]:
563 if self.dataOut.dtype == dtypeList[index]:
564 dtypeValue = datatypeValueList[index]
564 dtypeValue = datatypeValueList[index]
565 break
565 break
566
566
567 processFlags += dtypeValue
567 processFlags += dtypeValue
568
568
569 if self.dataOut.flagDecodeData:
569 if self.dataOut.flagDecodeData:
570 processFlags += PROCFLAG.DECODE_DATA
570 processFlags += PROCFLAG.DECODE_DATA
571
571
572 if self.dataOut.flagDeflipData:
572 if self.dataOut.flagDeflipData:
573 processFlags += PROCFLAG.DEFLIP_DATA
573 processFlags += PROCFLAG.DEFLIP_DATA
574
574
575 if self.dataOut.code != None:
575 if self.dataOut.code is not None:
576 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
576 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
577
577
578 if self.dataOut.nCohInt > 1:
578 if self.dataOut.nCohInt > 1:
579 processFlags += PROCFLAG.COHERENT_INTEGRATION
579 processFlags += PROCFLAG.COHERENT_INTEGRATION
580
580
581 return processFlags
581 return processFlags
582
582
583
583
584 def __getBlockSize(self):
584 def __getBlockSize(self):
585 '''
585 '''
586 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
586 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
587 '''
587 '''
588
588
589 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
589 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
590 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
590 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
591 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
591 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
592 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
592 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
593 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
593 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
594 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
594 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
595
595
596 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
596 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
597 datatypeValueList = [1,2,4,8,4,8]
597 datatypeValueList = [1,2,4,8,4,8]
598 for index in range(len(dtypeList)):
598 for index in range(len(dtypeList)):
599 if self.dataOut.dtype == dtypeList[index]:
599 if self.dataOut.dtype == dtypeList[index]:
600 datatypeValue = datatypeValueList[index]
600 datatypeValue = datatypeValueList[index]
601 break
601 break
602
602
603 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * datatypeValue * 2)
603 blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * datatypeValue * 2)
604
604
605 return blocksize
605 return blocksize
606
606
607 def setFirstHeader(self):
607 def setFirstHeader(self):
608
608
609 """
609 """
610 Obtiene una copia del First Header
610 Obtiene una copia del First Header
611
611
612 Affected:
612 Affected:
613 self.systemHeaderObj
613 self.systemHeaderObj
614 self.radarControllerHeaderObj
614 self.radarControllerHeaderObj
615 self.dtype
615 self.dtype
616
616
617 Return:
617 Return:
618 None
618 None
619 """
619 """
620
620
621 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
621 self.systemHeaderObj = self.dataOut.systemHeaderObj.copy()
622 self.systemHeaderObj.nChannels = self.dataOut.nChannels
622 self.systemHeaderObj.nChannels = self.dataOut.nChannels
623 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
623 self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy()
624
624
625 self.setBasicHeader()
625 self.setBasicHeader()
626
626
627 processingHeaderSize = 40 # bytes
627 processingHeaderSize = 40 # bytes
628 self.processingHeaderObj.dtype = 0 # Voltage
628 self.processingHeaderObj.dtype = 0 # Voltage
629 self.processingHeaderObj.blockSize = self.__getBlockSize()
629 self.processingHeaderObj.blockSize = self.__getBlockSize()
630 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
630 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
631 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
631 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
632 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
632 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows
633 self.processingHeaderObj.processFlags = self.__getProcessFlags()
633 self.processingHeaderObj.processFlags = self.__getProcessFlags()
634 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
634 self.processingHeaderObj.nCohInt = self.dataOut.nCohInt
635 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
635 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
636 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
636 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
637
637
638 # if self.dataOut.code != None:
638 # if self.dataOut.code is not None:
639 # self.processingHeaderObj.code = self.dataOut.code
639 # self.processingHeaderObj.code = self.dataOut.code
640 # self.processingHeaderObj.nCode = self.dataOut.nCode
640 # self.processingHeaderObj.nCode = self.dataOut.nCode
641 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
641 # self.processingHeaderObj.nBaud = self.dataOut.nBaud
642 # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
642 # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud)
643 # processingHeaderSize += codesize
643 # processingHeaderSize += codesize
644
644
645 if self.processingHeaderObj.nWindows != 0:
645 if self.processingHeaderObj.nWindows != 0:
646 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
646 self.processingHeaderObj.firstHeight = self.dataOut.heightList[0]
647 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
647 self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0]
648 self.processingHeaderObj.nHeights = self.dataOut.nHeights
648 self.processingHeaderObj.nHeights = self.dataOut.nHeights
649 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
649 self.processingHeaderObj.samplesWin = self.dataOut.nHeights
650 processingHeaderSize += 12
650 processingHeaderSize += 12
651
651
652 self.processingHeaderObj.size = processingHeaderSize No newline at end of file
652 self.processingHeaderObj.size = processingHeaderSize
@@ -1,978 +1,978
1 import numpy
1 import numpy
2 import math
2 import math
3
3
4 from jroproc_base import ProcessingUnit, Operation
4 from jroproc_base import ProcessingUnit, Operation
5 from schainpy.model.data.jrodata import Spectra
5 from schainpy.model.data.jrodata import Spectra
6 from schainpy.model.data.jrodata import hildebrand_sekhon
6 from schainpy.model.data.jrodata import hildebrand_sekhon
7
7
8 class SpectraProc(ProcessingUnit):
8 class SpectraProc(ProcessingUnit):
9
9
10 def __init__(self):
10 def __init__(self):
11
11
12 ProcessingUnit.__init__(self)
12 ProcessingUnit.__init__(self)
13
13
14 self.buffer = None
14 self.buffer = None
15 self.firstdatatime = None
15 self.firstdatatime = None
16 self.profIndex = 0
16 self.profIndex = 0
17 self.dataOut = Spectra()
17 self.dataOut = Spectra()
18 self.id_min = None
18 self.id_min = None
19 self.id_max = None
19 self.id_max = None
20
20
21 def __updateObjFromInput(self):
21 def __updateObjFromInput(self):
22
22
23 self.dataOut.timeZone = self.dataIn.timeZone
23 self.dataOut.timeZone = self.dataIn.timeZone
24 self.dataOut.dstFlag = self.dataIn.dstFlag
24 self.dataOut.dstFlag = self.dataIn.dstFlag
25 self.dataOut.errorCount = self.dataIn.errorCount
25 self.dataOut.errorCount = self.dataIn.errorCount
26 self.dataOut.useLocalTime = self.dataIn.useLocalTime
26 self.dataOut.useLocalTime = self.dataIn.useLocalTime
27
27
28 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
28 self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()
29 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
29 self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()
30 self.dataOut.channelList = self.dataIn.channelList
30 self.dataOut.channelList = self.dataIn.channelList
31 self.dataOut.heightList = self.dataIn.heightList
31 self.dataOut.heightList = self.dataIn.heightList
32 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
32 self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')])
33 # self.dataOut.nHeights = self.dataIn.nHeights
33 # self.dataOut.nHeights = self.dataIn.nHeights
34 # self.dataOut.nChannels = self.dataIn.nChannels
34 # self.dataOut.nChannels = self.dataIn.nChannels
35 self.dataOut.nBaud = self.dataIn.nBaud
35 self.dataOut.nBaud = self.dataIn.nBaud
36 self.dataOut.nCode = self.dataIn.nCode
36 self.dataOut.nCode = self.dataIn.nCode
37 self.dataOut.code = self.dataIn.code
37 self.dataOut.code = self.dataIn.code
38 self.dataOut.nProfiles = self.dataOut.nFFTPoints
38 self.dataOut.nProfiles = self.dataOut.nFFTPoints
39 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
39 # self.dataOut.channelIndexList = self.dataIn.channelIndexList
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
40 self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock
41 self.dataOut.utctime = self.firstdatatime
41 self.dataOut.utctime = self.firstdatatime
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
42 self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
43 self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip
44 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
44 # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT
45 self.dataOut.nCohInt = self.dataIn.nCohInt
45 self.dataOut.nCohInt = self.dataIn.nCohInt
46 self.dataOut.nIncohInt = 1
46 self.dataOut.nIncohInt = 1
47 # self.dataOut.ippSeconds = self.dataIn.ippSeconds
47 # self.dataOut.ippSeconds = self.dataIn.ippSeconds
48 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
48 self.dataOut.windowOfFilter = self.dataIn.windowOfFilter
49
49
50 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
50 # self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt
51 self.dataOut.frequency = self.dataIn.frequency
51 self.dataOut.frequency = self.dataIn.frequency
52 self.dataOut.realtime = self.dataIn.realtime
52 self.dataOut.realtime = self.dataIn.realtime
53
53
54 self.dataOut.azimuth = self.dataIn.azimuth
54 self.dataOut.azimuth = self.dataIn.azimuth
55 self.dataOut.zenith = self.dataIn.zenith
55 self.dataOut.zenith = self.dataIn.zenith
56
56
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
57 self.dataOut.beam.codeList = self.dataIn.beam.codeList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
58 self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
59 self.dataOut.beam.zenithList = self.dataIn.beam.zenithList
60
60
61 def __getFft(self):
61 def __getFft(self):
62 """
62 """
63 Convierte valores de Voltaje a Spectra
63 Convierte valores de Voltaje a Spectra
64
64
65 Affected:
65 Affected:
66 self.dataOut.data_spc
66 self.dataOut.data_spc
67 self.dataOut.data_cspc
67 self.dataOut.data_cspc
68 self.dataOut.data_dc
68 self.dataOut.data_dc
69 self.dataOut.heightList
69 self.dataOut.heightList
70 self.profIndex
70 self.profIndex
71 self.buffer
71 self.buffer
72 self.dataOut.flagNoData
72 self.dataOut.flagNoData
73 """
73 """
74 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
74 fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1)
75 fft_volt = fft_volt.astype(numpy.dtype('complex'))
75 fft_volt = fft_volt.astype(numpy.dtype('complex'))
76 dc = fft_volt[:,0,:]
76 dc = fft_volt[:,0,:]
77
77
78 #calculo de self-spectra
78 #calculo de self-spectra
79 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
79 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
80 spc = fft_volt * numpy.conjugate(fft_volt)
80 spc = fft_volt * numpy.conjugate(fft_volt)
81 spc = spc.real
81 spc = spc.real
82
82
83 blocksize = 0
83 blocksize = 0
84 blocksize += dc.size
84 blocksize += dc.size
85 blocksize += spc.size
85 blocksize += spc.size
86
86
87 cspc = None
87 cspc = None
88 pairIndex = 0
88 pairIndex = 0
89 if self.dataOut.pairsList != None:
89 if self.dataOut.pairsList != None:
90 #calculo de cross-spectra
90 #calculo de cross-spectra
91 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
91 cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex')
92 for pair in self.dataOut.pairsList:
92 for pair in self.dataOut.pairsList:
93 if pair[0] not in self.dataOut.channelList:
93 if pair[0] not in self.dataOut.channelList:
94 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
94 raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
95 if pair[1] not in self.dataOut.channelList:
95 if pair[1] not in self.dataOut.channelList:
96 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
96 raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList))
97
97
98 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
98 cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:])
99 pairIndex += 1
99 pairIndex += 1
100 blocksize += cspc.size
100 blocksize += cspc.size
101
101
102 self.dataOut.data_spc = spc
102 self.dataOut.data_spc = spc
103 self.dataOut.data_cspc = cspc
103 self.dataOut.data_cspc = cspc
104 self.dataOut.data_dc = dc
104 self.dataOut.data_dc = dc
105 self.dataOut.blockSize = blocksize
105 self.dataOut.blockSize = blocksize
106 self.dataOut.flagShiftFFT = False
106 self.dataOut.flagShiftFFT = False
107
107
108 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
108 def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None):
109
109
110 self.dataOut.flagNoData = True
110 self.dataOut.flagNoData = True
111
111
112 if self.dataIn.type == "Spectra":
112 if self.dataIn.type == "Spectra":
113 self.dataOut.copy(self.dataIn)
113 self.dataOut.copy(self.dataIn)
114 return True
114 return True
115
115
116 if self.dataIn.type == "Voltage":
116 if self.dataIn.type == "Voltage":
117
117
118 if nFFTPoints == None:
118 if nFFTPoints == None:
119 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
119 raise ValueError, "This SpectraProc.run() need nFFTPoints input variable"
120
120
121 if nProfiles == None:
121 if nProfiles == None:
122 nProfiles = nFFTPoints
122 nProfiles = nFFTPoints
123 # raise ValueError, "This SpectraProc.run() need nProfiles input variable"
123 # raise ValueError, "This SpectraProc.run() need nProfiles input variable"
124
124
125
125
126 if ippFactor == None:
126 if ippFactor == None:
127 ippFactor = 1
127 ippFactor = 1
128 self.dataOut.ippFactor = ippFactor
128 self.dataOut.ippFactor = ippFactor
129
129
130 self.dataOut.nFFTPoints = nFFTPoints
130 self.dataOut.nFFTPoints = nFFTPoints
131 self.dataOut.pairsList = pairsList
131 self.dataOut.pairsList = pairsList
132
132
133 if self.buffer is None:
133 if self.buffer is None:
134 self.buffer = numpy.zeros((self.dataIn.nChannels,
134 self.buffer = numpy.zeros((self.dataIn.nChannels,
135 nProfiles,
135 nProfiles,
136 self.dataIn.nHeights),
136 self.dataIn.nHeights),
137 dtype='complex')
137 dtype='complex')
138 self.id_min = 0
138 self.id_min = 0
139 self.id_max = self.dataIn.data.shape[1]
139 self.id_max = self.dataIn.data.shape[1]
140
140
141 if len(self.dataIn.data.shape) == 2:
141 if len(self.dataIn.data.shape) == 2:
142 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
142 self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()
143 self.profIndex += 1
143 self.profIndex += 1
144 else:
144 else:
145 if self.dataIn.data.shape[1] == nProfiles:
145 if self.dataIn.data.shape[1] == nProfiles:
146 self.buffer = self.dataIn.data.copy()
146 self.buffer = self.dataIn.data.copy()
147 self.profIndex = nProfiles
147 self.profIndex = nProfiles
148 elif self.dataIn.data.shape[1] < nProfiles:
148 elif self.dataIn.data.shape[1] < nProfiles:
149 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
149 self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data
150 self.profIndex += self.dataIn.data.shape[1]
150 self.profIndex += self.dataIn.data.shape[1]
151 self.id_min += self.dataIn.data.shape[1]
151 self.id_min += self.dataIn.data.shape[1]
152 self.id_max += self.dataIn.data.shape[1]
152 self.id_max += self.dataIn.data.shape[1]
153 else:
153 else:
154 raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
154 raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles)
155 self.dataOut.flagNoData = True
155 self.dataOut.flagNoData = True
156 return 0
156 return 0
157
157
158
158
159 if self.firstdatatime == None:
159 if self.firstdatatime == None:
160 self.firstdatatime = self.dataIn.utctime
160 self.firstdatatime = self.dataIn.utctime
161
161
162 if self.profIndex == nProfiles:
162 if self.profIndex == nProfiles:
163 self.__updateObjFromInput()
163 self.__updateObjFromInput()
164 self.__getFft()
164 self.__getFft()
165
165
166 self.dataOut.flagNoData = False
166 self.dataOut.flagNoData = False
167
167
168 self.buffer = None
168 self.buffer = None
169 self.firstdatatime = None
169 self.firstdatatime = None
170 self.profIndex = 0
170 self.profIndex = 0
171
171
172 return True
172 return True
173
173
174 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
174 raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type)
175
175
176 def __selectPairs(self, channelList=None):
176 def __selectPairs(self, channelList=None):
177
177
178 if channelList == None:
178 if channelList == None:
179 return
179 return
180
180
181 pairsIndexListSelected = []
181 pairsIndexListSelected = []
182 for pairIndex in self.dataOut.pairsIndexList:
182 for pairIndex in self.dataOut.pairsIndexList:
183 #First pair
183 #First pair
184 if self.dataOut.pairsList[pairIndex][0] not in channelList:
184 if self.dataOut.pairsList[pairIndex][0] not in channelList:
185 continue
185 continue
186 #Second pair
186 #Second pair
187 if self.dataOut.pairsList[pairIndex][1] not in channelList:
187 if self.dataOut.pairsList[pairIndex][1] not in channelList:
188 continue
188 continue
189
189
190 pairsIndexListSelected.append(pairIndex)
190 pairsIndexListSelected.append(pairIndex)
191
191
192 if not pairsIndexListSelected:
192 if not pairsIndexListSelected:
193 self.dataOut.data_cspc = None
193 self.dataOut.data_cspc = None
194 self.dataOut.pairsList = []
194 self.dataOut.pairsList = []
195 return
195 return
196
196
197 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
197 self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected]
198 self.dataOut.pairsList = self.dataOut.pairsList[pairsIndexListSelected]
198 self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected]
199
199
200 return
200 return
201
201
202 def selectChannels(self, channelList):
202 def selectChannels(self, channelList):
203
203
204 channelIndexList = []
204 channelIndexList = []
205
205
206 for channel in channelList:
206 for channel in channelList:
207 if channel not in self.dataOut.channelList:
207 if channel not in self.dataOut.channelList:
208 raise ValueError, "Error selecting channels: The value %d in channelList is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
208 raise ValueError, "Error selecting channels: The value %d in channelList is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList))
209
209
210 index = self.dataOut.channelList.index(channel)
210 index = self.dataOut.channelList.index(channel)
211 channelIndexList.append(index)
211 channelIndexList.append(index)
212
212
213 self.selectChannelsByIndex(channelIndexList)
213 self.selectChannelsByIndex(channelIndexList)
214
214
215 def selectChannelsByIndex(self, channelIndexList):
215 def selectChannelsByIndex(self, channelIndexList):
216 """
216 """
217 Selecciona un bloque de datos en base a canales segun el channelIndexList
217 Selecciona un bloque de datos en base a canales segun el channelIndexList
218
218
219 Input:
219 Input:
220 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
220 channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7]
221
221
222 Affected:
222 Affected:
223 self.dataOut.data_spc
223 self.dataOut.data_spc
224 self.dataOut.channelIndexList
224 self.dataOut.channelIndexList
225 self.dataOut.nChannels
225 self.dataOut.nChannels
226
226
227 Return:
227 Return:
228 None
228 None
229 """
229 """
230
230
231 for channelIndex in channelIndexList:
231 for channelIndex in channelIndexList:
232 if channelIndex not in self.dataOut.channelIndexList:
232 if channelIndex not in self.dataOut.channelIndexList:
233 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
233 raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList)
234
234
235 # nChannels = len(channelIndexList)
235 # nChannels = len(channelIndexList)
236
236
237 data_spc = self.dataOut.data_spc[channelIndexList,:]
237 data_spc = self.dataOut.data_spc[channelIndexList,:]
238 data_dc = self.dataOut.data_dc[channelIndexList,:]
238 data_dc = self.dataOut.data_dc[channelIndexList,:]
239
239
240 self.dataOut.data_spc = data_spc
240 self.dataOut.data_spc = data_spc
241 self.dataOut.data_dc = data_dc
241 self.dataOut.data_dc = data_dc
242
242
243 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
243 self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList]
244 # self.dataOut.nChannels = nChannels
244 # self.dataOut.nChannels = nChannels
245
245
246 self.__selectPairs(self.dataOut.channelList)
246 self.__selectPairs(self.dataOut.channelList)
247
247
248 return 1
248 return 1
249
249
250 def selectHeights(self, minHei, maxHei):
250 def selectHeights(self, minHei, maxHei):
251 """
251 """
252 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
252 Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango
253 minHei <= height <= maxHei
253 minHei <= height <= maxHei
254
254
255 Input:
255 Input:
256 minHei : valor minimo de altura a considerar
256 minHei : valor minimo de altura a considerar
257 maxHei : valor maximo de altura a considerar
257 maxHei : valor maximo de altura a considerar
258
258
259 Affected:
259 Affected:
260 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
260 Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex
261
261
262 Return:
262 Return:
263 1 si el metodo se ejecuto con exito caso contrario devuelve 0
263 1 si el metodo se ejecuto con exito caso contrario devuelve 0
264 """
264 """
265
265
266 if (minHei > maxHei):
266 if (minHei > maxHei):
267 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
267 raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei)
268
268
269 if (minHei < self.dataOut.heightList[0]):
269 if (minHei < self.dataOut.heightList[0]):
270 minHei = self.dataOut.heightList[0]
270 minHei = self.dataOut.heightList[0]
271
271
272 if (maxHei > self.dataOut.heightList[-1]):
272 if (maxHei > self.dataOut.heightList[-1]):
273 maxHei = self.dataOut.heightList[-1]
273 maxHei = self.dataOut.heightList[-1]
274 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
274 # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei)
275
275
276 minIndex = 0
276 minIndex = 0
277 maxIndex = 0
277 maxIndex = 0
278 heights = self.dataOut.heightList
278 heights = self.dataOut.heightList
279
279
280 inda = numpy.where(heights >= minHei)
280 inda = numpy.where(heights >= minHei)
281 indb = numpy.where(heights <= maxHei)
281 indb = numpy.where(heights <= maxHei)
282
282
283 try:
283 try:
284 minIndex = inda[0][0]
284 minIndex = inda[0][0]
285 except:
285 except:
286 minIndex = 0
286 minIndex = 0
287
287
288 try:
288 try:
289 maxIndex = indb[0][-1]
289 maxIndex = indb[0][-1]
290 except:
290 except:
291 maxIndex = len(heights)
291 maxIndex = len(heights)
292
292
293 self.selectHeightsByIndex(minIndex, maxIndex)
293 self.selectHeightsByIndex(minIndex, maxIndex)
294
294
295 return 1
295 return 1
296
296
297 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
297 def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None):
298 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
298 newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex])
299
299
300 if hei_ref != None:
300 if hei_ref != None:
301 newheis = numpy.where(self.dataOut.heightList>hei_ref)
301 newheis = numpy.where(self.dataOut.heightList>hei_ref)
302
302
303 minIndex = min(newheis[0])
303 minIndex = min(newheis[0])
304 maxIndex = max(newheis[0])
304 maxIndex = max(newheis[0])
305 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
305 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
306 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
306 heightList = self.dataOut.heightList[minIndex:maxIndex+1]
307
307
308 # determina indices
308 # determina indices
309 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
309 nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0]))
310 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
310 avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0))
311 beacon_dB = numpy.sort(avg_dB)[-nheis:]
311 beacon_dB = numpy.sort(avg_dB)[-nheis:]
312 beacon_heiIndexList = []
312 beacon_heiIndexList = []
313 for val in avg_dB.tolist():
313 for val in avg_dB.tolist():
314 if val >= beacon_dB[0]:
314 if val >= beacon_dB[0]:
315 beacon_heiIndexList.append(avg_dB.tolist().index(val))
315 beacon_heiIndexList.append(avg_dB.tolist().index(val))
316
316
317 #data_spc = data_spc[:,:,beacon_heiIndexList]
317 #data_spc = data_spc[:,:,beacon_heiIndexList]
318 data_cspc = None
318 data_cspc = None
319 if self.dataOut.data_cspc != None:
319 if self.dataOut.data_cspc is not None:
320 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
320 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
321 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
321 #data_cspc = data_cspc[:,:,beacon_heiIndexList]
322
322
323 data_dc = None
323 data_dc = None
324 if self.dataOut.data_dc != None:
324 if self.dataOut.data_dc is not None:
325 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
325 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
326 #data_dc = data_dc[:,beacon_heiIndexList]
326 #data_dc = data_dc[:,beacon_heiIndexList]
327
327
328 self.dataOut.data_spc = data_spc
328 self.dataOut.data_spc = data_spc
329 self.dataOut.data_cspc = data_cspc
329 self.dataOut.data_cspc = data_cspc
330 self.dataOut.data_dc = data_dc
330 self.dataOut.data_dc = data_dc
331 self.dataOut.heightList = heightList
331 self.dataOut.heightList = heightList
332 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
332 self.dataOut.beacon_heiIndexList = beacon_heiIndexList
333
333
334 return 1
334 return 1
335
335
336
336
337 def selectHeightsByIndex(self, minIndex, maxIndex):
337 def selectHeightsByIndex(self, minIndex, maxIndex):
338 """
338 """
339 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
339 Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango
340 minIndex <= index <= maxIndex
340 minIndex <= index <= maxIndex
341
341
342 Input:
342 Input:
343 minIndex : valor de indice minimo de altura a considerar
343 minIndex : valor de indice minimo de altura a considerar
344 maxIndex : valor de indice maximo de altura a considerar
344 maxIndex : valor de indice maximo de altura a considerar
345
345
346 Affected:
346 Affected:
347 self.dataOut.data_spc
347 self.dataOut.data_spc
348 self.dataOut.data_cspc
348 self.dataOut.data_cspc
349 self.dataOut.data_dc
349 self.dataOut.data_dc
350 self.dataOut.heightList
350 self.dataOut.heightList
351
351
352 Return:
352 Return:
353 1 si el metodo se ejecuto con exito caso contrario devuelve 0
353 1 si el metodo se ejecuto con exito caso contrario devuelve 0
354 """
354 """
355
355
356 if (minIndex < 0) or (minIndex > maxIndex):
356 if (minIndex < 0) or (minIndex > maxIndex):
357 raise ValueError, "Error selecting heights by index: Index range in (%d,%d) is not valid" % (minIndex, maxIndex)
357 raise ValueError, "Error selecting heights by index: Index range in (%d,%d) is not valid" % (minIndex, maxIndex)
358
358
359 if (maxIndex >= self.dataOut.nHeights):
359 if (maxIndex >= self.dataOut.nHeights):
360 maxIndex = self.dataOut.nHeights-1
360 maxIndex = self.dataOut.nHeights-1
361 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
361 # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
362
362
363 # nHeights = maxIndex - minIndex + 1
363 # nHeights = maxIndex - minIndex + 1
364
364
365 #Spectra
365 #Spectra
366 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
366 data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1]
367
367
368 data_cspc = None
368 data_cspc = None
369 if self.dataOut.data_cspc != None:
369 if self.dataOut.data_cspc is not None:
370 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
370 data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1]
371
371
372 data_dc = None
372 data_dc = None
373 if self.dataOut.data_dc != None:
373 if self.dataOut.data_dc is not None:
374 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
374 data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1]
375
375
376 self.dataOut.data_spc = data_spc
376 self.dataOut.data_spc = data_spc
377 self.dataOut.data_cspc = data_cspc
377 self.dataOut.data_cspc = data_cspc
378 self.dataOut.data_dc = data_dc
378 self.dataOut.data_dc = data_dc
379
379
380 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
380 self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1]
381
381
382 return 1
382 return 1
383
383
384 def removeDC(self, mode = 2):
384 def removeDC(self, mode = 2):
385 jspectra = self.dataOut.data_spc
385 jspectra = self.dataOut.data_spc
386 jcspectra = self.dataOut.data_cspc
386 jcspectra = self.dataOut.data_cspc
387
387
388
388
389 num_chan = jspectra.shape[0]
389 num_chan = jspectra.shape[0]
390 num_hei = jspectra.shape[2]
390 num_hei = jspectra.shape[2]
391
391
392 if jcspectra != None:
392 if jcspectra is not None:
393 jcspectraExist = True
393 jcspectraExist = True
394 num_pairs = jcspectra.shape[0]
394 num_pairs = jcspectra.shape[0]
395 else: jcspectraExist = False
395 else: jcspectraExist = False
396
396
397 freq_dc = jspectra.shape[1]/2
397 freq_dc = jspectra.shape[1]/2
398 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
398 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
399
399
400 if ind_vel[0]<0:
400 if ind_vel[0]<0:
401 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
401 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
402
402
403 if mode == 1:
403 if mode == 1:
404 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
404 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
405
405
406 if jcspectraExist:
406 if jcspectraExist:
407 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
407 jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2
408
408
409 if mode == 2:
409 if mode == 2:
410
410
411 vel = numpy.array([-2,-1,1,2])
411 vel = numpy.array([-2,-1,1,2])
412 xx = numpy.zeros([4,4])
412 xx = numpy.zeros([4,4])
413
413
414 for fil in range(4):
414 for fil in range(4):
415 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
415 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
416
416
417 xx_inv = numpy.linalg.inv(xx)
417 xx_inv = numpy.linalg.inv(xx)
418 xx_aux = xx_inv[0,:]
418 xx_aux = xx_inv[0,:]
419
419
420 for ich in range(num_chan):
420 for ich in range(num_chan):
421 yy = jspectra[ich,ind_vel,:]
421 yy = jspectra[ich,ind_vel,:]
422 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
422 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
423
423
424 junkid = jspectra[ich,freq_dc,:]<=0
424 junkid = jspectra[ich,freq_dc,:]<=0
425 cjunkid = sum(junkid)
425 cjunkid = sum(junkid)
426
426
427 if cjunkid.any():
427 if cjunkid.any():
428 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
428 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
429
429
430 if jcspectraExist:
430 if jcspectraExist:
431 for ip in range(num_pairs):
431 for ip in range(num_pairs):
432 yy = jcspectra[ip,ind_vel,:]
432 yy = jcspectra[ip,ind_vel,:]
433 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
433 jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy)
434
434
435
435
436 self.dataOut.data_spc = jspectra
436 self.dataOut.data_spc = jspectra
437 self.dataOut.data_cspc = jcspectra
437 self.dataOut.data_cspc = jcspectra
438
438
439 return 1
439 return 1
440
440
441 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
441 def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None):
442
442
443 jspectra = self.dataOut.data_spc
443 jspectra = self.dataOut.data_spc
444 jcspectra = self.dataOut.data_cspc
444 jcspectra = self.dataOut.data_cspc
445 jnoise = self.dataOut.getNoise()
445 jnoise = self.dataOut.getNoise()
446 num_incoh = self.dataOut.nIncohInt
446 num_incoh = self.dataOut.nIncohInt
447
447
448 num_channel = jspectra.shape[0]
448 num_channel = jspectra.shape[0]
449 num_prof = jspectra.shape[1]
449 num_prof = jspectra.shape[1]
450 num_hei = jspectra.shape[2]
450 num_hei = jspectra.shape[2]
451
451
452 #hei_interf
452 #hei_interf
453 if hei_interf == None:
453 if hei_interf is None:
454 count_hei = num_hei/2 #Como es entero no importa
454 count_hei = num_hei/2 #Como es entero no importa
455 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
455 hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei
456 hei_interf = numpy.asarray(hei_interf)[0]
456 hei_interf = numpy.asarray(hei_interf)[0]
457 #nhei_interf
457 #nhei_interf
458 if (nhei_interf == None):
458 if (nhei_interf == None):
459 nhei_interf = 5
459 nhei_interf = 5
460 if (nhei_interf < 1):
460 if (nhei_interf < 1):
461 nhei_interf = 1
461 nhei_interf = 1
462 if (nhei_interf > count_hei):
462 if (nhei_interf > count_hei):
463 nhei_interf = count_hei
463 nhei_interf = count_hei
464 if (offhei_interf == None):
464 if (offhei_interf == None):
465 offhei_interf = 0
465 offhei_interf = 0
466
466
467 ind_hei = range(num_hei)
467 ind_hei = range(num_hei)
468 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
468 # mask_prof = numpy.asarray(range(num_prof - 2)) + 1
469 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
469 # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1
470 mask_prof = numpy.asarray(range(num_prof))
470 mask_prof = numpy.asarray(range(num_prof))
471 num_mask_prof = mask_prof.size
471 num_mask_prof = mask_prof.size
472 comp_mask_prof = [0, num_prof/2]
472 comp_mask_prof = [0, num_prof/2]
473
473
474
474
475 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
475 #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal
476 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
476 if (jnoise.size < num_channel or numpy.isnan(jnoise).any()):
477 jnoise = numpy.nan
477 jnoise = numpy.nan
478 noise_exist = jnoise[0] < numpy.Inf
478 noise_exist = jnoise[0] < numpy.Inf
479
479
480 #Subrutina de Remocion de la Interferencia
480 #Subrutina de Remocion de la Interferencia
481 for ich in range(num_channel):
481 for ich in range(num_channel):
482 #Se ordena los espectros segun su potencia (menor a mayor)
482 #Se ordena los espectros segun su potencia (menor a mayor)
483 power = jspectra[ich,mask_prof,:]
483 power = jspectra[ich,mask_prof,:]
484 power = power[:,hei_interf]
484 power = power[:,hei_interf]
485 power = power.sum(axis = 0)
485 power = power.sum(axis = 0)
486 psort = power.ravel().argsort()
486 psort = power.ravel().argsort()
487
487
488 #Se estima la interferencia promedio en los Espectros de Potencia empleando
488 #Se estima la interferencia promedio en los Espectros de Potencia empleando
489 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
489 junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]]
490
490
491 if noise_exist:
491 if noise_exist:
492 # tmp_noise = jnoise[ich] / num_prof
492 # tmp_noise = jnoise[ich] / num_prof
493 tmp_noise = jnoise[ich]
493 tmp_noise = jnoise[ich]
494 junkspc_interf = junkspc_interf - tmp_noise
494 junkspc_interf = junkspc_interf - tmp_noise
495 #junkspc_interf[:,comp_mask_prof] = 0
495 #junkspc_interf[:,comp_mask_prof] = 0
496
496
497 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
497 jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf
498 jspc_interf = jspc_interf.transpose()
498 jspc_interf = jspc_interf.transpose()
499 #Calculando el espectro de interferencia promedio
499 #Calculando el espectro de interferencia promedio
500 noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh))
500 noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh))
501 noiseid = noiseid[0]
501 noiseid = noiseid[0]
502 cnoiseid = noiseid.size
502 cnoiseid = noiseid.size
503 interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh))
503 interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh))
504 interfid = interfid[0]
504 interfid = interfid[0]
505 cinterfid = interfid.size
505 cinterfid = interfid.size
506
506
507 if (cnoiseid > 0): jspc_interf[noiseid] = 0
507 if (cnoiseid > 0): jspc_interf[noiseid] = 0
508
508
509 #Expandiendo los perfiles a limpiar
509 #Expandiendo los perfiles a limpiar
510 if (cinterfid > 0):
510 if (cinterfid > 0):
511 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
511 new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof
512 new_interfid = numpy.asarray(new_interfid)
512 new_interfid = numpy.asarray(new_interfid)
513 new_interfid = {x for x in new_interfid}
513 new_interfid = {x for x in new_interfid}
514 new_interfid = numpy.array(list(new_interfid))
514 new_interfid = numpy.array(list(new_interfid))
515 new_cinterfid = new_interfid.size
515 new_cinterfid = new_interfid.size
516 else: new_cinterfid = 0
516 else: new_cinterfid = 0
517
517
518 for ip in range(new_cinterfid):
518 for ip in range(new_cinterfid):
519 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
519 ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort()
520 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
520 jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]]
521
521
522
522
523 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
523 jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices
524
524
525 #Removiendo la interferencia del punto de mayor interferencia
525 #Removiendo la interferencia del punto de mayor interferencia
526 ListAux = jspc_interf[mask_prof].tolist()
526 ListAux = jspc_interf[mask_prof].tolist()
527 maxid = ListAux.index(max(ListAux))
527 maxid = ListAux.index(max(ListAux))
528
528
529
529
530 if cinterfid > 0:
530 if cinterfid > 0:
531 for ip in range(cinterfid*(interf == 2) - 1):
531 for ip in range(cinterfid*(interf == 2) - 1):
532 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero()
532 ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero()
533 cind = len(ind)
533 cind = len(ind)
534
534
535 if (cind > 0):
535 if (cind > 0):
536 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh))
536 jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh))
537
537
538 ind = numpy.array([-2,-1,1,2])
538 ind = numpy.array([-2,-1,1,2])
539 xx = numpy.zeros([4,4])
539 xx = numpy.zeros([4,4])
540
540
541 for id1 in range(4):
541 for id1 in range(4):
542 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
542 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
543
543
544 xx_inv = numpy.linalg.inv(xx)
544 xx_inv = numpy.linalg.inv(xx)
545 xx = xx_inv[:,0]
545 xx = xx_inv[:,0]
546 ind = (ind + maxid + num_mask_prof)%num_mask_prof
546 ind = (ind + maxid + num_mask_prof)%num_mask_prof
547 yy = jspectra[ich,mask_prof[ind],:]
547 yy = jspectra[ich,mask_prof[ind],:]
548 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
548 jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
549
549
550
550
551 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero()
551 indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero()
552 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh))
552 jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh))
553
553
554 #Remocion de Interferencia en el Cross Spectra
554 #Remocion de Interferencia en el Cross Spectra
555 if jcspectra == None: return jspectra, jcspectra
555 if jcspectra is None: return jspectra, jcspectra
556 num_pairs = jcspectra.size/(num_prof*num_hei)
556 num_pairs = jcspectra.size/(num_prof*num_hei)
557 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
557 jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei)
558
558
559 for ip in range(num_pairs):
559 for ip in range(num_pairs):
560
560
561 #-------------------------------------------
561 #-------------------------------------------
562
562
563 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
563 cspower = numpy.abs(jcspectra[ip,mask_prof,:])
564 cspower = cspower[:,hei_interf]
564 cspower = cspower[:,hei_interf]
565 cspower = cspower.sum(axis = 0)
565 cspower = cspower.sum(axis = 0)
566
566
567 cspsort = cspower.ravel().argsort()
567 cspsort = cspower.ravel().argsort()
568 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
568 junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]]
569 junkcspc_interf = junkcspc_interf.transpose()
569 junkcspc_interf = junkcspc_interf.transpose()
570 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
570 jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf
571
571
572 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
572 ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort()
573
573
574 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
574 median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
575 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
575 median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:]))
576 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
576 junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag)
577
577
578 for iprof in range(num_prof):
578 for iprof in range(num_prof):
579 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
579 ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort()
580 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
580 jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]]
581
581
582 #Removiendo la Interferencia
582 #Removiendo la Interferencia
583 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
583 jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf
584
584
585 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
585 ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist()
586 maxid = ListAux.index(max(ListAux))
586 maxid = ListAux.index(max(ListAux))
587
587
588 ind = numpy.array([-2,-1,1,2])
588 ind = numpy.array([-2,-1,1,2])
589 xx = numpy.zeros([4,4])
589 xx = numpy.zeros([4,4])
590
590
591 for id1 in range(4):
591 for id1 in range(4):
592 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
592 xx[:,id1] = ind[id1]**numpy.asarray(range(4))
593
593
594 xx_inv = numpy.linalg.inv(xx)
594 xx_inv = numpy.linalg.inv(xx)
595 xx = xx_inv[:,0]
595 xx = xx_inv[:,0]
596
596
597 ind = (ind + maxid + num_mask_prof)%num_mask_prof
597 ind = (ind + maxid + num_mask_prof)%num_mask_prof
598 yy = jcspectra[ip,mask_prof[ind],:]
598 yy = jcspectra[ip,mask_prof[ind],:]
599 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
599 jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx)
600
600
601 #Guardar Resultados
601 #Guardar Resultados
602 self.dataOut.data_spc = jspectra
602 self.dataOut.data_spc = jspectra
603 self.dataOut.data_cspc = jcspectra
603 self.dataOut.data_cspc = jcspectra
604
604
605 return 1
605 return 1
606
606
607 def setRadarFrequency(self, frequency=None):
607 def setRadarFrequency(self, frequency=None):
608 if frequency != None:
608 if frequency != None:
609 self.dataOut.frequency = frequency
609 self.dataOut.frequency = frequency
610
610
611 return 1
611 return 1
612
612
613 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
613 def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None):
614 #validacion de rango
614 #validacion de rango
615 if minHei == None:
615 if minHei == None:
616 minHei = self.dataOut.heightList[0]
616 minHei = self.dataOut.heightList[0]
617
617
618 if maxHei == None:
618 if maxHei == None:
619 maxHei = self.dataOut.heightList[-1]
619 maxHei = self.dataOut.heightList[-1]
620
620
621 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
621 if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei):
622 print 'minHei: %.2f is out of the heights range'%(minHei)
622 print 'minHei: %.2f is out of the heights range'%(minHei)
623 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
623 print 'minHei is setting to %.2f'%(self.dataOut.heightList[0])
624 minHei = self.dataOut.heightList[0]
624 minHei = self.dataOut.heightList[0]
625
625
626 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
626 if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei):
627 print 'maxHei: %.2f is out of the heights range'%(maxHei)
627 print 'maxHei: %.2f is out of the heights range'%(maxHei)
628 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
628 print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1])
629 maxHei = self.dataOut.heightList[-1]
629 maxHei = self.dataOut.heightList[-1]
630
630
631 # validacion de velocidades
631 # validacion de velocidades
632 velrange = self.dataOut.getVelRange(1)
632 velrange = self.dataOut.getVelRange(1)
633
633
634 if minVel == None:
634 if minVel == None:
635 minVel = velrange[0]
635 minVel = velrange[0]
636
636
637 if maxVel == None:
637 if maxVel == None:
638 maxVel = velrange[-1]
638 maxVel = velrange[-1]
639
639
640 if (minVel < velrange[0]) or (minVel > maxVel):
640 if (minVel < velrange[0]) or (minVel > maxVel):
641 print 'minVel: %.2f is out of the velocity range'%(minVel)
641 print 'minVel: %.2f is out of the velocity range'%(minVel)
642 print 'minVel is setting to %.2f'%(velrange[0])
642 print 'minVel is setting to %.2f'%(velrange[0])
643 minVel = velrange[0]
643 minVel = velrange[0]
644
644
645 if (maxVel > velrange[-1]) or (maxVel < minVel):
645 if (maxVel > velrange[-1]) or (maxVel < minVel):
646 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
646 print 'maxVel: %.2f is out of the velocity range'%(maxVel)
647 print 'maxVel is setting to %.2f'%(velrange[-1])
647 print 'maxVel is setting to %.2f'%(velrange[-1])
648 maxVel = velrange[-1]
648 maxVel = velrange[-1]
649
649
650 # seleccion de indices para rango
650 # seleccion de indices para rango
651 minIndex = 0
651 minIndex = 0
652 maxIndex = 0
652 maxIndex = 0
653 heights = self.dataOut.heightList
653 heights = self.dataOut.heightList
654
654
655 inda = numpy.where(heights >= minHei)
655 inda = numpy.where(heights >= minHei)
656 indb = numpy.where(heights <= maxHei)
656 indb = numpy.where(heights <= maxHei)
657
657
658 try:
658 try:
659 minIndex = inda[0][0]
659 minIndex = inda[0][0]
660 except:
660 except:
661 minIndex = 0
661 minIndex = 0
662
662
663 try:
663 try:
664 maxIndex = indb[0][-1]
664 maxIndex = indb[0][-1]
665 except:
665 except:
666 maxIndex = len(heights)
666 maxIndex = len(heights)
667
667
668 if (minIndex < 0) or (minIndex > maxIndex):
668 if (minIndex < 0) or (minIndex > maxIndex):
669 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
669 raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex)
670
670
671 if (maxIndex >= self.dataOut.nHeights):
671 if (maxIndex >= self.dataOut.nHeights):
672 maxIndex = self.dataOut.nHeights-1
672 maxIndex = self.dataOut.nHeights-1
673
673
674 # seleccion de indices para velocidades
674 # seleccion de indices para velocidades
675 indminvel = numpy.where(velrange >= minVel)
675 indminvel = numpy.where(velrange >= minVel)
676 indmaxvel = numpy.where(velrange <= maxVel)
676 indmaxvel = numpy.where(velrange <= maxVel)
677 try:
677 try:
678 minIndexVel = indminvel[0][0]
678 minIndexVel = indminvel[0][0]
679 except:
679 except:
680 minIndexVel = 0
680 minIndexVel = 0
681
681
682 try:
682 try:
683 maxIndexVel = indmaxvel[0][-1]
683 maxIndexVel = indmaxvel[0][-1]
684 except:
684 except:
685 maxIndexVel = len(velrange)
685 maxIndexVel = len(velrange)
686
686
687 #seleccion del espectro
687 #seleccion del espectro
688 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
688 data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1]
689 #estimacion de ruido
689 #estimacion de ruido
690 noise = numpy.zeros(self.dataOut.nChannels)
690 noise = numpy.zeros(self.dataOut.nChannels)
691
691
692 for channel in range(self.dataOut.nChannels):
692 for channel in range(self.dataOut.nChannels):
693 daux = data_spc[channel,:,:]
693 daux = data_spc[channel,:,:]
694 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
694 noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt)
695
695
696 self.dataOut.noise_estimation = noise.copy()
696 self.dataOut.noise_estimation = noise.copy()
697
697
698 return 1
698 return 1
699
699
700 class IncohInt(Operation):
700 class IncohInt(Operation):
701
701
702
702
703 __profIndex = 0
703 __profIndex = 0
704 __withOverapping = False
704 __withOverapping = False
705
705
706 __byTime = False
706 __byTime = False
707 __initime = None
707 __initime = None
708 __lastdatatime = None
708 __lastdatatime = None
709 __integrationtime = None
709 __integrationtime = None
710
710
711 __buffer_spc = None
711 __buffer_spc = None
712 __buffer_cspc = None
712 __buffer_cspc = None
713 __buffer_dc = None
713 __buffer_dc = None
714
714
715 __dataReady = False
715 __dataReady = False
716
716
717 __timeInterval = None
717 __timeInterval = None
718
718
719 n = None
719 n = None
720
720
721
721
722
722
723 def __init__(self):
723 def __init__(self):
724
724
725 Operation.__init__(self)
725 Operation.__init__(self)
726 # self.isConfig = False
726 # self.isConfig = False
727
727
728 def setup(self, n=None, timeInterval=None, overlapping=False):
728 def setup(self, n=None, timeInterval=None, overlapping=False):
729 """
729 """
730 Set the parameters of the integration class.
730 Set the parameters of the integration class.
731
731
732 Inputs:
732 Inputs:
733
733
734 n : Number of coherent integrations
734 n : Number of coherent integrations
735 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
735 timeInterval : Time of integration. If the parameter "n" is selected this one does not work
736 overlapping :
736 overlapping :
737
737
738 """
738 """
739
739
740 self.__initime = None
740 self.__initime = None
741 self.__lastdatatime = 0
741 self.__lastdatatime = 0
742 self.__buffer_spc = None
742 self.__buffer_spc = None
743 self.__buffer_cspc = None
743 self.__buffer_cspc = None
744 self.__buffer_dc = None
744 self.__buffer_dc = None
745 self.__dataReady = False
745 self.__dataReady = False
746
746
747
747
748 if n == None and timeInterval == None:
748 if n == None and timeInterval == None:
749 raise ValueError, "n or timeInterval should be specified ..."
749 raise ValueError, "n or timeInterval should be specified ..."
750
750
751 if n != None:
751 if n != None:
752 self.n = n
752 self.n = n
753 self.__byTime = False
753 self.__byTime = False
754 else:
754 else:
755 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
755 self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line
756 self.n = 9999
756 self.n = 9999
757 self.__byTime = True
757 self.__byTime = True
758
758
759 if overlapping:
759 if overlapping:
760 self.__withOverapping = True
760 self.__withOverapping = True
761 else:
761 else:
762 self.__withOverapping = False
762 self.__withOverapping = False
763 self.__buffer_spc = 0
763 self.__buffer_spc = 0
764 self.__buffer_cspc = 0
764 self.__buffer_cspc = 0
765 self.__buffer_dc = 0
765 self.__buffer_dc = 0
766
766
767 self.__profIndex = 0
767 self.__profIndex = 0
768
768
769 def putData(self, data_spc, data_cspc, data_dc):
769 def putData(self, data_spc, data_cspc, data_dc):
770
770
771 """
771 """
772 Add a profile to the __buffer_spc and increase in one the __profileIndex
772 Add a profile to the __buffer_spc and increase in one the __profileIndex
773
773
774 """
774 """
775
775
776 if not self.__withOverapping:
776 if not self.__withOverapping:
777 self.__buffer_spc += data_spc
777 self.__buffer_spc += data_spc
778
778
779 if data_cspc is None:
779 if data_cspc is None:
780 self.__buffer_cspc = None
780 self.__buffer_cspc = None
781 else:
781 else:
782 self.__buffer_cspc += data_cspc
782 self.__buffer_cspc += data_cspc
783
783
784 if data_dc is None:
784 if data_dc is None:
785 self.__buffer_dc = None
785 self.__buffer_dc = None
786 else:
786 else:
787 self.__buffer_dc += data_dc
787 self.__buffer_dc += data_dc
788
788
789 self.__profIndex += 1
789 self.__profIndex += 1
790 return
790 return
791
791
792 #Overlapping data
792 #Overlapping data
793 nChannels, nFFTPoints, nHeis = data_spc.shape
793 nChannels, nFFTPoints, nHeis = data_spc.shape
794 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
794 data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis))
795 if data_cspc != None:
795 if data_cspc is not None:
796 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
796 data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis))
797 if data_dc != None:
797 if data_dc is not None:
798 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
798 data_dc = numpy.reshape(data_dc, (1, -1, nHeis))
799
799
800 #If the buffer is empty then it takes the data value
800 #If the buffer is empty then it takes the data value
801 if self.__buffer_spc is None:
801 if self.__buffer_spc is None:
802 self.__buffer_spc = data_spc
802 self.__buffer_spc = data_spc
803
803
804 if data_cspc is None:
804 if data_cspc is None:
805 self.__buffer_cspc = None
805 self.__buffer_cspc = None
806 else:
806 else:
807 self.__buffer_cspc += data_cspc
807 self.__buffer_cspc += data_cspc
808
808
809 if data_dc is None:
809 if data_dc is None:
810 self.__buffer_dc = None
810 self.__buffer_dc = None
811 else:
811 else:
812 self.__buffer_dc += data_dc
812 self.__buffer_dc += data_dc
813
813
814 self.__profIndex += 1
814 self.__profIndex += 1
815 return
815 return
816
816
817 #If the buffer length is lower than n then stakcing the data value
817 #If the buffer length is lower than n then stakcing the data value
818 if self.__profIndex < self.n:
818 if self.__profIndex < self.n:
819 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
819 self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc))
820
820
821 if data_cspc != None:
821 if data_cspc is not None:
822 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
822 self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc))
823
823
824 if data_dc != None:
824 if data_dc is not None:
825 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
825 self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc))
826
826
827 self.__profIndex += 1
827 self.__profIndex += 1
828 return
828 return
829
829
830 #If the buffer length is equal to n then replacing the last buffer value with the data value
830 #If the buffer length is equal to n then replacing the last buffer value with the data value
831 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
831 self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0)
832 self.__buffer_spc[self.n-1] = data_spc
832 self.__buffer_spc[self.n-1] = data_spc
833
833
834 if data_cspc != None:
834 if data_cspc is not None:
835 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
835 self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0)
836 self.__buffer_cspc[self.n-1] = data_cspc
836 self.__buffer_cspc[self.n-1] = data_cspc
837
837
838 if data_dc != None:
838 if data_dc is not None:
839 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
839 self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0)
840 self.__buffer_dc[self.n-1] = data_dc
840 self.__buffer_dc[self.n-1] = data_dc
841
841
842 self.__profIndex = self.n
842 self.__profIndex = self.n
843 return
843 return
844
844
845
845
846 def pushData(self):
846 def pushData(self):
847 """
847 """
848 Return the sum of the last profiles and the profiles used in the sum.
848 Return the sum of the last profiles and the profiles used in the sum.
849
849
850 Affected:
850 Affected:
851
851
852 self.__profileIndex
852 self.__profileIndex
853
853
854 """
854 """
855 data_spc = None
855 data_spc = None
856 data_cspc = None
856 data_cspc = None
857 data_dc = None
857 data_dc = None
858
858
859 if not self.__withOverapping:
859 if not self.__withOverapping:
860 data_spc = self.__buffer_spc
860 data_spc = self.__buffer_spc
861 data_cspc = self.__buffer_cspc
861 data_cspc = self.__buffer_cspc
862 data_dc = self.__buffer_dc
862 data_dc = self.__buffer_dc
863
863
864 n = self.__profIndex
864 n = self.__profIndex
865
865
866 self.__buffer_spc = 0
866 self.__buffer_spc = 0
867 self.__buffer_cspc = 0
867 self.__buffer_cspc = 0
868 self.__buffer_dc = 0
868 self.__buffer_dc = 0
869 self.__profIndex = 0
869 self.__profIndex = 0
870
870
871 return data_spc, data_cspc, data_dc, n
871 return data_spc, data_cspc, data_dc, n
872
872
873 #Integration with Overlapping
873 #Integration with Overlapping
874 data_spc = numpy.sum(self.__buffer_spc, axis=0)
874 data_spc = numpy.sum(self.__buffer_spc, axis=0)
875
875
876 if self.__buffer_cspc != None:
876 if self.__buffer_cspc is not None:
877 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
877 data_cspc = numpy.sum(self.__buffer_cspc, axis=0)
878
878
879 if self.__buffer_dc != None:
879 if self.__buffer_dc is not None:
880 data_dc = numpy.sum(self.__buffer_dc, axis=0)
880 data_dc = numpy.sum(self.__buffer_dc, axis=0)
881
881
882 n = self.__profIndex
882 n = self.__profIndex
883
883
884 return data_spc, data_cspc, data_dc, n
884 return data_spc, data_cspc, data_dc, n
885
885
886 def byProfiles(self, *args):
886 def byProfiles(self, *args):
887
887
888 self.__dataReady = False
888 self.__dataReady = False
889 avgdata_spc = None
889 avgdata_spc = None
890 avgdata_cspc = None
890 avgdata_cspc = None
891 avgdata_dc = None
891 avgdata_dc = None
892 # n = None
892 # n = None
893
893
894 self.putData(*args)
894 self.putData(*args)
895
895
896 if self.__profIndex == self.n:
896 if self.__profIndex == self.n:
897
897
898 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
898 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
899 self.__dataReady = True
899 self.__dataReady = True
900
900
901 return avgdata_spc, avgdata_cspc, avgdata_dc
901 return avgdata_spc, avgdata_cspc, avgdata_dc
902
902
903 def byTime(self, datatime, *args):
903 def byTime(self, datatime, *args):
904
904
905 self.__dataReady = False
905 self.__dataReady = False
906 avgdata_spc = None
906 avgdata_spc = None
907 avgdata_cspc = None
907 avgdata_cspc = None
908 avgdata_dc = None
908 avgdata_dc = None
909 n = None
909 n = None
910
910
911 self.putData(*args)
911 self.putData(*args)
912
912
913 if (datatime - self.__initime) >= self.__integrationtime:
913 if (datatime - self.__initime) >= self.__integrationtime:
914 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
914 avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData()
915 self.n = n
915 self.n = n
916 self.__dataReady = True
916 self.__dataReady = True
917
917
918 return avgdata_spc, avgdata_cspc, avgdata_dc
918 return avgdata_spc, avgdata_cspc, avgdata_dc
919
919
920 def integrate(self, datatime, *args):
920 def integrate(self, datatime, *args):
921
921
922 if self.__initime == None:
922 if self.__initime == None:
923 self.__initime = datatime
923 self.__initime = datatime
924
924
925 if self.__byTime:
925 if self.__byTime:
926 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
926 avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args)
927 else:
927 else:
928 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
928 avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args)
929
929
930 self.__lastdatatime = datatime
930 self.__lastdatatime = datatime
931
931
932 if avgdata_spc is None:
932 if avgdata_spc is None:
933 return None, None, None, None
933 return None, None, None, None
934
934
935 avgdatatime = self.__initime
935 avgdatatime = self.__initime
936 try:
936 try:
937 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
937 self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1)
938 except:
938 except:
939 self.__timeInterval = self.__lastdatatime - self.__initime
939 self.__timeInterval = self.__lastdatatime - self.__initime
940
940
941 deltatime = datatime -self.__lastdatatime
941 deltatime = datatime -self.__lastdatatime
942
942
943 if not self.__withOverapping:
943 if not self.__withOverapping:
944 self.__initime = datatime
944 self.__initime = datatime
945 else:
945 else:
946 self.__initime += deltatime
946 self.__initime += deltatime
947
947
948 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
948 return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc
949
949
950 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
950 def run(self, dataOut, n=None, timeInterval=None, overlapping=False):
951
951
952 if n==1:
952 if n==1:
953 dataOut.flagNoData = False
953 dataOut.flagNoData = False
954 return
954 return
955
955
956 if not self.isConfig:
956 if not self.isConfig:
957 self.setup(n, timeInterval, overlapping)
957 self.setup(n, timeInterval, overlapping)
958 self.isConfig = True
958 self.isConfig = True
959
959
960 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
960 avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime,
961 dataOut.data_spc,
961 dataOut.data_spc,
962 dataOut.data_cspc,
962 dataOut.data_cspc,
963 dataOut.data_dc)
963 dataOut.data_dc)
964
964
965 # dataOut.timeInterval *= n
965 # dataOut.timeInterval *= n
966 dataOut.flagNoData = True
966 dataOut.flagNoData = True
967
967
968 if self.__dataReady:
968 if self.__dataReady:
969
969
970 dataOut.data_spc = avgdata_spc
970 dataOut.data_spc = avgdata_spc
971 dataOut.data_cspc = avgdata_cspc
971 dataOut.data_cspc = avgdata_cspc
972 dataOut.data_dc = avgdata_dc
972 dataOut.data_dc = avgdata_dc
973
973
974 dataOut.nIncohInt *= self.n
974 dataOut.nIncohInt *= self.n
975 dataOut.utctime = avgdatatime
975 dataOut.utctime = avgdatatime
976 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
976 #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints
977 # dataOut.timeInterval = self.__timeInterval*self.n
977 # dataOut.timeInterval = self.__timeInterval*self.n
978 dataOut.flagNoData = False
978 dataOut.flagNoData = False
@@ -1,31 +1,31
1 '''
1 '''
2 Created on Jul 16, 2014
2 Created on Jul 16, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6
6
7 from distutils.core import setup, Extension
7 from distutils.core import setup, Extension
8
8
9 setup(name="schainpy",
9 setup(name="schainpy",
10 version="2.0",
10 version="2.1.0",
11 description="Python tools to read, write and process Jicamarca data",
11 description="Python tools to read, write and process Jicamarca data",
12 author="Miguel Urco",
12 author="Miguel Urco",
13 author_email="miguel.urco@jro.igp.gob.pe",
13 author_email="miguel.urco@jro.igp.gob.pe",
14 url="http://jro.igp.gob.pe",
14 url="http://jro.igp.gob.pe",
15 packages = {'schainpy',
15 packages = {'schainpy',
16 'schainpy.model',
16 'schainpy.model',
17 'schainpy.model.data',
17 'schainpy.model.data',
18 'schainpy.model.graphics',
18 'schainpy.model.graphics',
19 'schainpy.model.io',
19 'schainpy.model.io',
20 'schainpy.model.proc',
20 'schainpy.model.proc',
21 'schainpy.model.utils',
21 'schainpy.model.utils',
22 'schainpy.gui',
22 'schainpy.gui',
23 'schainpy.gui.figures',
23 'schainpy.gui.figures',
24 'schainpy.gui.viewcontroller',
24 'schainpy.gui.viewcontroller',
25 'schainpy.gui.viewer',
25 'schainpy.gui.viewer',
26 'schainpy.gui.viewer.windows'},
26 'schainpy.gui.viewer.windows'},
27 py_modules=['schainpy.serializer.DataTranslate',
27 py_modules=['schainpy.serializer.DataTranslate',
28 'schainpy.serializer.JROSerializer'],
28 'schainpy.serializer.JROSerializer'],
29 package_data={'schainpy.gui.figures': ['*.jpg', '*.jpeg', '*.png', '*.gif']},
29 package_data={'schainpy.gui.figures': ['*.jpg', '*.jpeg', '*.png', '*.gif']},
30 include_package_data=True,
30 include_package_data=True,
31 scripts =['schainpy/gui/schainGUI']) No newline at end of file
31 scripts =['schainpy/gui/schainGUI'])
General Comments 0
You need to be logged in to leave comments. Login now