@@ -1,2161 +1,2161 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | import inspect |
|
5 | 5 | from figure import Figure, isRealtime, isTimeInHourRange |
|
6 | 6 | from plotting_codes import * |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | class SpcParamPlot(Figure): |
|
10 | 10 | |
|
11 | 11 | isConfig = None |
|
12 | 12 | __nsubplots = None |
|
13 | 13 | |
|
14 | 14 | WIDTHPROF = None |
|
15 | 15 | HEIGHTPROF = None |
|
16 | 16 | PREFIX = 'SpcParam' |
|
17 | 17 | |
|
18 | 18 | def __init__(self, **kwargs): |
|
19 | 19 | Figure.__init__(self, **kwargs) |
|
20 | 20 | self.isConfig = False |
|
21 | 21 | self.__nsubplots = 1 |
|
22 | 22 | |
|
23 | 23 | self.WIDTH = 250 |
|
24 | 24 | self.HEIGHT = 250 |
|
25 | 25 | self.WIDTHPROF = 120 |
|
26 | 26 | self.HEIGHTPROF = 0 |
|
27 | 27 | self.counter_imagwr = 0 |
|
28 | 28 | |
|
29 | 29 | self.PLOT_CODE = SPEC_CODE |
|
30 | 30 | |
|
31 | 31 | self.FTP_WEI = None |
|
32 | 32 | self.EXP_CODE = None |
|
33 | 33 | self.SUB_EXP_CODE = None |
|
34 | 34 | self.PLOT_POS = None |
|
35 | 35 | |
|
36 | 36 | self.__xfilter_ena = False |
|
37 | 37 | self.__yfilter_ena = False |
|
38 | 38 | |
|
39 | 39 | def getSubplots(self): |
|
40 | 40 | |
|
41 | 41 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
42 | 42 | nrow = int(self.nplots*1./ncol + 0.9) |
|
43 | 43 | |
|
44 | 44 | return nrow, ncol |
|
45 | 45 | |
|
46 | 46 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
47 | 47 | |
|
48 | 48 | self.__showprofile = showprofile |
|
49 | 49 | self.nplots = nplots |
|
50 | 50 | |
|
51 | 51 | ncolspan = 1 |
|
52 | 52 | colspan = 1 |
|
53 | 53 | if showprofile: |
|
54 | 54 | ncolspan = 3 |
|
55 | 55 | colspan = 2 |
|
56 | 56 | self.__nsubplots = 2 |
|
57 | 57 | |
|
58 | 58 | self.createFigure(id = id, |
|
59 | 59 | wintitle = wintitle, |
|
60 | 60 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
61 | 61 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
62 | 62 | show=show) |
|
63 | 63 | |
|
64 | 64 | nrow, ncol = self.getSubplots() |
|
65 | 65 | |
|
66 | 66 | counter = 0 |
|
67 | 67 | for y in range(nrow): |
|
68 | 68 | for x in range(ncol): |
|
69 | 69 | |
|
70 | 70 | if counter >= self.nplots: |
|
71 | 71 | break |
|
72 | 72 | |
|
73 | 73 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
74 | 74 | |
|
75 | 75 | if showprofile: |
|
76 | 76 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
77 | 77 | |
|
78 | 78 | counter += 1 |
|
79 | 79 | |
|
80 | 80 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
81 | 81 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
82 | 82 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
83 | 83 | server=None, folder=None, username=None, password=None, |
|
84 | 84 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
85 | 85 | xaxis="frequency", colormap='jet', normFactor=None , Selector = 0): |
|
86 | 86 | |
|
87 | 87 | """ |
|
88 | 88 | |
|
89 | 89 | Input: |
|
90 | 90 | dataOut : |
|
91 | 91 | id : |
|
92 | 92 | wintitle : |
|
93 | 93 | channelList : |
|
94 | 94 | showProfile : |
|
95 | 95 | xmin : None, |
|
96 | 96 | xmax : None, |
|
97 | 97 | ymin : None, |
|
98 | 98 | ymax : None, |
|
99 | 99 | zmin : None, |
|
100 | 100 | zmax : None |
|
101 | 101 | """ |
|
102 | 102 | if realtime: |
|
103 | 103 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
104 | 104 | print 'Skipping this plot function' |
|
105 | 105 | return |
|
106 | 106 | |
|
107 | 107 | if channelList == None: |
|
108 | 108 | channelIndexList = dataOut.channelIndexList |
|
109 | 109 | else: |
|
110 | 110 | channelIndexList = [] |
|
111 | 111 | for channel in channelList: |
|
112 | 112 | if channel not in dataOut.channelList: |
|
113 | 113 | raise ValueError, "Channel %d is not in dataOut.channelList" %channel |
|
114 | 114 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
115 | 115 | |
|
116 | 116 | # if normFactor is None: |
|
117 | 117 | # factor = dataOut.normFactor |
|
118 | 118 | # else: |
|
119 | 119 | # factor = normFactor |
|
120 | 120 | if xaxis == "frequency": |
|
121 | 121 | x = dataOut.spcparam_range[0] |
|
122 | 122 | xlabel = "Frequency (kHz)" |
|
123 | 123 | |
|
124 | 124 | elif xaxis == "time": |
|
125 | 125 | x = dataOut.spcparam_range[1] |
|
126 | 126 | xlabel = "Time (ms)" |
|
127 | 127 | |
|
128 | 128 | else: |
|
129 | 129 | x = dataOut.spcparam_range[2] |
|
130 | 130 | xlabel = "Velocity (m/s)" |
|
131 | 131 | print "Vmax=",x[-1] |
|
132 | 132 | |
|
133 |
ylabel = "Range ( |
|
|
133 | ylabel = "Range (km)" | |
|
134 | 134 | |
|
135 | 135 | y = dataOut.getHeiRange() |
|
136 | 136 | |
|
137 | 137 | z = dataOut.SPCparam[Selector] /1966080.0#/ dataOut.normFactor#GauSelector] #dataOut.data_spc/factor |
|
138 | 138 | #print 'GausSPC', z[0,32,10:40] |
|
139 | 139 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
140 | 140 | zdB = 10*numpy.log10(z) |
|
141 | 141 | |
|
142 | 142 | avg = numpy.average(z, axis=1) |
|
143 | 143 | avgdB = 10*numpy.log10(avg) |
|
144 | 144 | |
|
145 | 145 | noise = dataOut.spc_noise |
|
146 | 146 | noisedB = 10*numpy.log10(noise) |
|
147 | 147 | |
|
148 | 148 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
149 | 149 | title = wintitle + " Spectra" |
|
150 | 150 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
151 | 151 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
152 | 152 | |
|
153 | 153 | if not self.isConfig: |
|
154 | 154 | |
|
155 | 155 | nplots = len(channelIndexList) |
|
156 | 156 | |
|
157 | 157 | self.setup(id=id, |
|
158 | 158 | nplots=nplots, |
|
159 | 159 | wintitle=wintitle, |
|
160 | 160 | showprofile=showprofile, |
|
161 | 161 | show=show) |
|
162 | 162 | |
|
163 | 163 | if xmin == None: xmin = numpy.nanmin(x) |
|
164 | 164 | if xmax == None: xmax = numpy.nanmax(x) |
|
165 | 165 | if ymin == None: ymin = numpy.nanmin(y) |
|
166 | 166 | if ymax == None: ymax = numpy.nanmax(y) |
|
167 | 167 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
168 | 168 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
169 | 169 | |
|
170 | 170 | self.FTP_WEI = ftp_wei |
|
171 | 171 | self.EXP_CODE = exp_code |
|
172 | 172 | self.SUB_EXP_CODE = sub_exp_code |
|
173 | 173 | self.PLOT_POS = plot_pos |
|
174 | 174 | |
|
175 | 175 | self.isConfig = True |
|
176 | 176 | |
|
177 | 177 | self.setWinTitle(title) |
|
178 | 178 | |
|
179 | 179 | for i in range(self.nplots): |
|
180 | 180 | index = channelIndexList[i] |
|
181 | 181 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
182 | 182 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
183 | 183 | if len(dataOut.beam.codeList) != 0: |
|
184 | 184 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) |
|
185 | 185 | |
|
186 | 186 | axes = self.axesList[i*self.__nsubplots] |
|
187 | 187 | axes.pcolor(x, y, zdB[index,:,:], |
|
188 | 188 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
189 | 189 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, |
|
190 | 190 | ticksize=9, cblabel='') |
|
191 | 191 | |
|
192 | 192 | if self.__showprofile: |
|
193 | 193 | axes = self.axesList[i*self.__nsubplots +1] |
|
194 | 194 | axes.pline(avgdB[index,:], y, |
|
195 | 195 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
196 | 196 | xlabel='dB', ylabel='', title='', |
|
197 | 197 | ytick_visible=False, |
|
198 | 198 | grid='x') |
|
199 | 199 | |
|
200 | 200 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
201 | 201 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
202 | 202 | |
|
203 | 203 | self.draw() |
|
204 | 204 | |
|
205 | 205 | if figfile == None: |
|
206 | 206 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
207 | 207 | name = str_datetime |
|
208 | 208 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
209 | 209 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
210 | 210 | figfile = self.getFilename(name) |
|
211 | 211 | |
|
212 | 212 | self.save(figpath=figpath, |
|
213 | 213 | figfile=figfile, |
|
214 | 214 | save=save, |
|
215 | 215 | ftp=ftp, |
|
216 | 216 | wr_period=wr_period, |
|
217 | 217 | thisDatetime=thisDatetime) |
|
218 | 218 | |
|
219 | 219 | |
|
220 | 220 | |
|
221 | 221 | class MomentsPlot(Figure): |
|
222 | 222 | |
|
223 | 223 | isConfig = None |
|
224 | 224 | __nsubplots = None |
|
225 | 225 | |
|
226 | 226 | WIDTHPROF = None |
|
227 | 227 | HEIGHTPROF = None |
|
228 | 228 | PREFIX = 'prm' |
|
229 | 229 | |
|
230 | 230 | def __init__(self, **kwargs): |
|
231 | 231 | Figure.__init__(self, **kwargs) |
|
232 | 232 | self.isConfig = False |
|
233 | 233 | self.__nsubplots = 1 |
|
234 | 234 | |
|
235 | 235 | self.WIDTH = 280 |
|
236 | 236 | self.HEIGHT = 250 |
|
237 | 237 | self.WIDTHPROF = 120 |
|
238 | 238 | self.HEIGHTPROF = 0 |
|
239 | 239 | self.counter_imagwr = 0 |
|
240 | 240 | |
|
241 | 241 | self.PLOT_CODE = MOMENTS_CODE |
|
242 | 242 | |
|
243 | 243 | self.FTP_WEI = None |
|
244 | 244 | self.EXP_CODE = None |
|
245 | 245 | self.SUB_EXP_CODE = None |
|
246 | 246 | self.PLOT_POS = None |
|
247 | 247 | |
|
248 | 248 | def getSubplots(self): |
|
249 | 249 | |
|
250 | 250 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
251 | 251 | nrow = int(self.nplots*1./ncol + 0.9) |
|
252 | 252 | |
|
253 | 253 | return nrow, ncol |
|
254 | 254 | |
|
255 | 255 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
256 | 256 | |
|
257 | 257 | self.__showprofile = showprofile |
|
258 | 258 | self.nplots = nplots |
|
259 | 259 | |
|
260 | 260 | ncolspan = 1 |
|
261 | 261 | colspan = 1 |
|
262 | 262 | if showprofile: |
|
263 | 263 | ncolspan = 3 |
|
264 | 264 | colspan = 2 |
|
265 | 265 | self.__nsubplots = 2 |
|
266 | 266 | |
|
267 | 267 | self.createFigure(id = id, |
|
268 | 268 | wintitle = wintitle, |
|
269 | 269 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
270 | 270 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
271 | 271 | show=show) |
|
272 | 272 | |
|
273 | 273 | nrow, ncol = self.getSubplots() |
|
274 | 274 | |
|
275 | 275 | counter = 0 |
|
276 | 276 | for y in range(nrow): |
|
277 | 277 | for x in range(ncol): |
|
278 | 278 | |
|
279 | 279 | if counter >= self.nplots: |
|
280 | 280 | break |
|
281 | 281 | |
|
282 | 282 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
283 | 283 | |
|
284 | 284 | if showprofile: |
|
285 | 285 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
286 | 286 | |
|
287 | 287 | counter += 1 |
|
288 | 288 | |
|
289 | 289 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
290 | 290 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
291 | 291 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
292 | 292 | server=None, folder=None, username=None, password=None, |
|
293 | 293 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
294 | 294 | |
|
295 | 295 | """ |
|
296 | 296 | |
|
297 | 297 | Input: |
|
298 | 298 | dataOut : |
|
299 | 299 | id : |
|
300 | 300 | wintitle : |
|
301 | 301 | channelList : |
|
302 | 302 | showProfile : |
|
303 | 303 | xmin : None, |
|
304 | 304 | xmax : None, |
|
305 | 305 | ymin : None, |
|
306 | 306 | ymax : None, |
|
307 | 307 | zmin : None, |
|
308 | 308 | zmax : None |
|
309 | 309 | """ |
|
310 | 310 | |
|
311 | 311 | if dataOut.flagNoData: |
|
312 | 312 | return None |
|
313 | 313 | |
|
314 | 314 | if realtime: |
|
315 | 315 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
316 | 316 | print 'Skipping this plot function' |
|
317 | 317 | return |
|
318 | 318 | |
|
319 | 319 | if channelList == None: |
|
320 | 320 | channelIndexList = dataOut.channelIndexList |
|
321 | 321 | else: |
|
322 | 322 | channelIndexList = [] |
|
323 | 323 | for channel in channelList: |
|
324 | 324 | if channel not in dataOut.channelList: |
|
325 | 325 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
326 | 326 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
327 | 327 | |
|
328 | 328 | factor = dataOut.normFactor |
|
329 | 329 | x = dataOut.abscissaList |
|
330 | 330 | y = dataOut.heightList |
|
331 | 331 | |
|
332 | 332 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
333 | 333 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
334 | 334 | avg = numpy.average(z, axis=1) |
|
335 | 335 | noise = dataOut.noise/factor |
|
336 | 336 | |
|
337 | 337 | zdB = 10*numpy.log10(z) |
|
338 | 338 | avgdB = 10*numpy.log10(avg) |
|
339 | 339 | noisedB = 10*numpy.log10(noise) |
|
340 | 340 | |
|
341 | 341 | #thisDatetime = dataOut.datatime |
|
342 | 342 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
343 | 343 | title = wintitle + " Parameters" |
|
344 | 344 | xlabel = "Velocity (m/s)" |
|
345 | 345 | ylabel = "Range (Km)" |
|
346 | 346 | |
|
347 | 347 | update_figfile = False |
|
348 | 348 | |
|
349 | 349 | if not self.isConfig: |
|
350 | 350 | |
|
351 | 351 | nplots = len(channelIndexList) |
|
352 | 352 | |
|
353 | 353 | self.setup(id=id, |
|
354 | 354 | nplots=nplots, |
|
355 | 355 | wintitle=wintitle, |
|
356 | 356 | showprofile=showprofile, |
|
357 | 357 | show=show) |
|
358 | 358 | |
|
359 | 359 | if xmin == None: xmin = numpy.nanmin(x) |
|
360 | 360 | if xmax == None: xmax = numpy.nanmax(x) |
|
361 | 361 | if ymin == None: ymin = numpy.nanmin(y) |
|
362 | 362 | if ymax == None: ymax = numpy.nanmax(y) |
|
363 | 363 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
364 | 364 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
365 | 365 | |
|
366 | 366 | self.FTP_WEI = ftp_wei |
|
367 | 367 | self.EXP_CODE = exp_code |
|
368 | 368 | self.SUB_EXP_CODE = sub_exp_code |
|
369 | 369 | self.PLOT_POS = plot_pos |
|
370 | 370 | |
|
371 | 371 | self.isConfig = True |
|
372 | 372 | update_figfile = True |
|
373 | 373 | |
|
374 | 374 | self.setWinTitle(title) |
|
375 | 375 | |
|
376 | 376 | for i in range(self.nplots): |
|
377 | 377 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
378 | 378 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime) |
|
379 | 379 | axes = self.axesList[i*self.__nsubplots] |
|
380 | 380 | axes.pcolor(x, y, zdB[i,:,:], |
|
381 | 381 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
382 | 382 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
383 | 383 | ticksize=9, cblabel='') |
|
384 | 384 | #Mean Line |
|
385 | 385 | mean = dataOut.data_param[i, 1, :] |
|
386 | 386 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
387 | 387 | |
|
388 | 388 | if self.__showprofile: |
|
389 | 389 | axes = self.axesList[i*self.__nsubplots +1] |
|
390 | 390 | axes.pline(avgdB[i], y, |
|
391 | 391 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
392 | 392 | xlabel='dB', ylabel='', title='', |
|
393 | 393 | ytick_visible=False, |
|
394 | 394 | grid='x') |
|
395 | 395 | |
|
396 | 396 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
397 | 397 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
398 | 398 | |
|
399 | 399 | self.draw() |
|
400 | 400 | |
|
401 | 401 | self.save(figpath=figpath, |
|
402 | 402 | figfile=figfile, |
|
403 | 403 | save=save, |
|
404 | 404 | ftp=ftp, |
|
405 | 405 | wr_period=wr_period, |
|
406 | 406 | thisDatetime=thisDatetime) |
|
407 | 407 | |
|
408 | 408 | |
|
409 | 409 | |
|
410 | 410 | class SkyMapPlot(Figure): |
|
411 | 411 | |
|
412 | 412 | __isConfig = None |
|
413 | 413 | __nsubplots = None |
|
414 | 414 | |
|
415 | 415 | WIDTHPROF = None |
|
416 | 416 | HEIGHTPROF = None |
|
417 | 417 | PREFIX = 'mmap' |
|
418 | 418 | |
|
419 | 419 | def __init__(self, **kwargs): |
|
420 | 420 | Figure.__init__(self, **kwargs) |
|
421 | 421 | self.isConfig = False |
|
422 | 422 | self.__nsubplots = 1 |
|
423 | 423 | |
|
424 | 424 | # self.WIDTH = 280 |
|
425 | 425 | # self.HEIGHT = 250 |
|
426 | 426 | self.WIDTH = 600 |
|
427 | 427 | self.HEIGHT = 600 |
|
428 | 428 | self.WIDTHPROF = 120 |
|
429 | 429 | self.HEIGHTPROF = 0 |
|
430 | 430 | self.counter_imagwr = 0 |
|
431 | 431 | |
|
432 | 432 | self.PLOT_CODE = MSKYMAP_CODE |
|
433 | 433 | |
|
434 | 434 | self.FTP_WEI = None |
|
435 | 435 | self.EXP_CODE = None |
|
436 | 436 | self.SUB_EXP_CODE = None |
|
437 | 437 | self.PLOT_POS = None |
|
438 | 438 | |
|
439 | 439 | def getSubplots(self): |
|
440 | 440 | |
|
441 | 441 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
442 | 442 | nrow = int(self.nplots*1./ncol + 0.9) |
|
443 | 443 | |
|
444 | 444 | return nrow, ncol |
|
445 | 445 | |
|
446 | 446 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
447 | 447 | |
|
448 | 448 | self.__showprofile = showprofile |
|
449 | 449 | self.nplots = nplots |
|
450 | 450 | |
|
451 | 451 | ncolspan = 1 |
|
452 | 452 | colspan = 1 |
|
453 | 453 | |
|
454 | 454 | self.createFigure(id = id, |
|
455 | 455 | wintitle = wintitle, |
|
456 | 456 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
457 | 457 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
458 | 458 | show=show) |
|
459 | 459 | |
|
460 | 460 | nrow, ncol = 1,1 |
|
461 | 461 | counter = 0 |
|
462 | 462 | x = 0 |
|
463 | 463 | y = 0 |
|
464 | 464 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
465 | 465 | |
|
466 | 466 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
467 | 467 | tmin=0, tmax=24, timerange=None, |
|
468 | 468 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
469 | 469 | server=None, folder=None, username=None, password=None, |
|
470 | 470 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
471 | 471 | |
|
472 | 472 | """ |
|
473 | 473 | |
|
474 | 474 | Input: |
|
475 | 475 | dataOut : |
|
476 | 476 | id : |
|
477 | 477 | wintitle : |
|
478 | 478 | channelList : |
|
479 | 479 | showProfile : |
|
480 | 480 | xmin : None, |
|
481 | 481 | xmax : None, |
|
482 | 482 | ymin : None, |
|
483 | 483 | ymax : None, |
|
484 | 484 | zmin : None, |
|
485 | 485 | zmax : None |
|
486 | 486 | """ |
|
487 | 487 | |
|
488 | 488 | arrayParameters = dataOut.data_param |
|
489 | 489 | error = arrayParameters[:,-1] |
|
490 | 490 | indValid = numpy.where(error == 0)[0] |
|
491 | 491 | finalMeteor = arrayParameters[indValid,:] |
|
492 | 492 | finalAzimuth = finalMeteor[:,3] |
|
493 | 493 | finalZenith = finalMeteor[:,4] |
|
494 | 494 | |
|
495 | 495 | x = finalAzimuth*numpy.pi/180 |
|
496 | 496 | y = finalZenith |
|
497 | 497 | x1 = [dataOut.ltctime, dataOut.ltctime] |
|
498 | 498 | |
|
499 | 499 | #thisDatetime = dataOut.datatime |
|
500 | 500 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
501 | 501 | title = wintitle + " Parameters" |
|
502 | 502 | xlabel = "Zonal Zenith Angle (deg) " |
|
503 | 503 | ylabel = "Meridional Zenith Angle (deg)" |
|
504 | 504 | update_figfile = False |
|
505 | 505 | |
|
506 | 506 | if not self.isConfig: |
|
507 | 507 | |
|
508 | 508 | nplots = 1 |
|
509 | 509 | |
|
510 | 510 | self.setup(id=id, |
|
511 | 511 | nplots=nplots, |
|
512 | 512 | wintitle=wintitle, |
|
513 | 513 | showprofile=showprofile, |
|
514 | 514 | show=show) |
|
515 | 515 | |
|
516 | 516 | if self.xmin is None and self.xmax is None: |
|
517 | 517 | self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange) |
|
518 | 518 | |
|
519 | 519 | if timerange != None: |
|
520 | 520 | self.timerange = timerange |
|
521 | 521 | else: |
|
522 | 522 | self.timerange = self.xmax - self.xmin |
|
523 | 523 | |
|
524 | 524 | self.FTP_WEI = ftp_wei |
|
525 | 525 | self.EXP_CODE = exp_code |
|
526 | 526 | self.SUB_EXP_CODE = sub_exp_code |
|
527 | 527 | self.PLOT_POS = plot_pos |
|
528 | 528 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
529 | 529 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
530 | 530 | self.isConfig = True |
|
531 | 531 | update_figfile = True |
|
532 | 532 | |
|
533 | 533 | self.setWinTitle(title) |
|
534 | 534 | |
|
535 | 535 | i = 0 |
|
536 | 536 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
537 | 537 | |
|
538 | 538 | axes = self.axesList[i*self.__nsubplots] |
|
539 | 539 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
540 | 540 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
541 | 541 | axes.polar(x, y, |
|
542 | 542 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
543 | 543 | ticksize=9, cblabel='') |
|
544 | 544 | |
|
545 | 545 | self.draw() |
|
546 | 546 | |
|
547 | 547 | self.save(figpath=figpath, |
|
548 | 548 | figfile=figfile, |
|
549 | 549 | save=save, |
|
550 | 550 | ftp=ftp, |
|
551 | 551 | wr_period=wr_period, |
|
552 | 552 | thisDatetime=thisDatetime, |
|
553 | 553 | update_figfile=update_figfile) |
|
554 | 554 | |
|
555 | 555 | if dataOut.ltctime >= self.xmax: |
|
556 | 556 | self.isConfigmagwr = wr_period |
|
557 | 557 | self.isConfig = False |
|
558 | 558 | update_figfile = True |
|
559 | 559 | axes.__firsttime = True |
|
560 | 560 | self.xmin += self.timerange |
|
561 | 561 | self.xmax += self.timerange |
|
562 | 562 | |
|
563 | 563 | |
|
564 | 564 | |
|
565 | 565 | |
|
566 | 566 | class WindProfilerPlot(Figure): |
|
567 | 567 | |
|
568 | 568 | __isConfig = None |
|
569 | 569 | __nsubplots = None |
|
570 | 570 | |
|
571 | 571 | WIDTHPROF = None |
|
572 | 572 | HEIGHTPROF = None |
|
573 | 573 | PREFIX = 'wind' |
|
574 | 574 | |
|
575 | 575 | def __init__(self, **kwargs): |
|
576 | 576 | Figure.__init__(self, **kwargs) |
|
577 | 577 | self.timerange = None |
|
578 | 578 | self.isConfig = False |
|
579 | 579 | self.__nsubplots = 1 |
|
580 | 580 | |
|
581 | 581 | self.WIDTH = 800 |
|
582 | 582 | self.HEIGHT = 300 |
|
583 | 583 | self.WIDTHPROF = 120 |
|
584 | 584 | self.HEIGHTPROF = 0 |
|
585 | 585 | self.counter_imagwr = 0 |
|
586 | 586 | |
|
587 | 587 | self.PLOT_CODE = WIND_CODE |
|
588 | 588 | |
|
589 | 589 | self.FTP_WEI = None |
|
590 | 590 | self.EXP_CODE = None |
|
591 | 591 | self.SUB_EXP_CODE = None |
|
592 | 592 | self.PLOT_POS = None |
|
593 | 593 | self.tmin = None |
|
594 | 594 | self.tmax = None |
|
595 | 595 | |
|
596 | 596 | self.xmin = None |
|
597 | 597 | self.xmax = None |
|
598 | 598 | |
|
599 | 599 | self.figfile = None |
|
600 | 600 | |
|
601 | 601 | def getSubplots(self): |
|
602 | 602 | |
|
603 | 603 | ncol = 1 |
|
604 | 604 | nrow = self.nplots |
|
605 | 605 | |
|
606 | 606 | return nrow, ncol |
|
607 | 607 | |
|
608 | 608 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
609 | 609 | |
|
610 | 610 | self.__showprofile = showprofile |
|
611 | 611 | self.nplots = nplots |
|
612 | 612 | |
|
613 | 613 | ncolspan = 1 |
|
614 | 614 | colspan = 1 |
|
615 | 615 | |
|
616 | 616 | self.createFigure(id = id, |
|
617 | 617 | wintitle = wintitle, |
|
618 | 618 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
619 | 619 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
620 | 620 | show=show) |
|
621 | 621 | |
|
622 | 622 | nrow, ncol = self.getSubplots() |
|
623 | 623 | |
|
624 | 624 | counter = 0 |
|
625 | 625 | for y in range(nrow): |
|
626 | 626 | if counter >= self.nplots: |
|
627 | 627 | break |
|
628 | 628 | |
|
629 | 629 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
630 | 630 | counter += 1 |
|
631 | 631 | |
|
632 | 632 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False', |
|
633 | 633 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
634 | 634 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
635 | 635 | timerange=None, SNRthresh = None, |
|
636 | 636 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
637 | 637 | server=None, folder=None, username=None, password=None, |
|
638 | 638 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
639 | 639 | """ |
|
640 | 640 | |
|
641 | 641 | Input: |
|
642 | 642 | dataOut : |
|
643 | 643 | id : |
|
644 | 644 | wintitle : |
|
645 | 645 | channelList : |
|
646 | 646 | showProfile : |
|
647 | 647 | xmin : None, |
|
648 | 648 | xmax : None, |
|
649 | 649 | ymin : None, |
|
650 | 650 | ymax : None, |
|
651 | 651 | zmin : None, |
|
652 | 652 | zmax : None |
|
653 | 653 | """ |
|
654 | 654 | |
|
655 | 655 | # if timerange is not None: |
|
656 | 656 | # self.timerange = timerange |
|
657 | 657 | # |
|
658 | 658 | # tmin = None |
|
659 | 659 | # tmax = None |
|
660 | 660 | |
|
661 | 661 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
662 | 662 | y = dataOut.heightList |
|
663 | 663 | z = dataOut.data_output.copy() |
|
664 | 664 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
665 | 665 | nplotsw = nplots |
|
666 | 666 | |
|
667 | 667 | |
|
668 | 668 | #If there is a SNR function defined |
|
669 | 669 | if dataOut.data_SNR is not None: |
|
670 | 670 | nplots += 1 |
|
671 | 671 | SNR = dataOut.data_SNR[0] |
|
672 | 672 | SNRavg = SNR#numpy.average(SNR, axis=0) |
|
673 | 673 | |
|
674 | 674 | SNRdB = 10*numpy.log10(SNR) |
|
675 | 675 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
676 | 676 | |
|
677 | 677 | if SNRthresh == None: |
|
678 | 678 | SNRthresh = -5.0 |
|
679 | 679 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
680 | 680 | |
|
681 | 681 | for i in range(nplotsw): |
|
682 | 682 | z[i,ind] = numpy.nan |
|
683 | 683 | |
|
684 | 684 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
685 | 685 | #thisDatetime = datetime.datetime.now() |
|
686 | 686 | title = wintitle + "Wind" |
|
687 | 687 | xlabel = "" |
|
688 | 688 | ylabel = "Height (km)" |
|
689 | 689 | update_figfile = False |
|
690 | 690 | |
|
691 | 691 | if not self.isConfig: |
|
692 | 692 | |
|
693 | 693 | self.setup(id=id, |
|
694 | 694 | nplots=nplots, |
|
695 | 695 | wintitle=wintitle, |
|
696 | 696 | showprofile=showprofile, |
|
697 | 697 | show=show) |
|
698 | 698 | |
|
699 | 699 | if timerange is not None: |
|
700 | 700 | self.timerange = timerange |
|
701 | 701 | |
|
702 | 702 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
703 | 703 | |
|
704 | 704 | if ymin == None: ymin = numpy.nanmin(y) |
|
705 | 705 | if ymax == None: ymax = numpy.nanmax(y) |
|
706 | 706 | |
|
707 | 707 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) |
|
708 | 708 | #if numpy.isnan(zmax): zmax = 50 |
|
709 | 709 | if zmin == None: zmin = -zmax |
|
710 | 710 | |
|
711 | 711 | if nplotsw == 3: |
|
712 | 712 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
713 | 713 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
714 | 714 | |
|
715 | 715 | if dataOut.data_SNR is not None: |
|
716 | 716 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
717 | 717 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
718 | 718 | |
|
719 | 719 | |
|
720 | 720 | self.FTP_WEI = ftp_wei |
|
721 | 721 | self.EXP_CODE = exp_code |
|
722 | 722 | self.SUB_EXP_CODE = sub_exp_code |
|
723 | 723 | self.PLOT_POS = plot_pos |
|
724 | 724 | |
|
725 | 725 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
726 | 726 | self.isConfig = True |
|
727 | 727 | self.figfile = figfile |
|
728 | 728 | update_figfile = True |
|
729 | 729 | |
|
730 | 730 | self.setWinTitle(title) |
|
731 | 731 | |
|
732 | 732 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
733 | 733 | x[1] = self.xmax |
|
734 | 734 | |
|
735 | 735 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
736 | 736 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
737 | 737 | zmaxVector = [zmax, zmax, zmax_ver] |
|
738 | 738 | zminVector = [zmin, zmin, zmin_ver] |
|
739 | 739 | windFactor = [1,1,100] |
|
740 | 740 | |
|
741 | 741 | for i in range(nplotsw): |
|
742 | 742 | |
|
743 | 743 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
744 | 744 | axes = self.axesList[i*self.__nsubplots] |
|
745 | 745 | |
|
746 | 746 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
747 | 747 | |
|
748 | 748 | print 'x', x |
|
749 | 749 | print datetime.datetime.utcfromtimestamp(x[0]) |
|
750 | 750 | print datetime.datetime.utcfromtimestamp(x[1]) |
|
751 | 751 | |
|
752 | 752 | #z1=numpy.ma.masked_where(z1==0.,z1) |
|
753 | 753 | |
|
754 | 754 | axes.pcolorbuffer(x, y, z1, |
|
755 | 755 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
756 | 756 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
757 | 757 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" ) |
|
758 | 758 | |
|
759 | 759 | if dataOut.data_SNR is not None: |
|
760 | 760 | i += 1 |
|
761 | 761 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
762 | 762 | axes = self.axesList[i*self.__nsubplots] |
|
763 | 763 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
764 | 764 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
765 | 765 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
766 | 766 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
767 | 767 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
768 | 768 | |
|
769 | 769 | self.draw() |
|
770 | 770 | |
|
771 | 771 | self.save(figpath=figpath, |
|
772 | 772 | figfile=figfile, |
|
773 | 773 | save=save, |
|
774 | 774 | ftp=ftp, |
|
775 | 775 | wr_period=wr_period, |
|
776 | 776 | thisDatetime=thisDatetime, |
|
777 | 777 | update_figfile=update_figfile) |
|
778 | 778 | |
|
779 | 779 | if dataOut.ltctime + dataOut.paramInterval >= self.xmax: |
|
780 | 780 | self.counter_imagwr = wr_period |
|
781 | 781 | self.isConfig = False |
|
782 | 782 | update_figfile = True |
|
783 | 783 | |
|
784 | 784 | |
|
785 | 785 | class ParametersPlot(Figure): |
|
786 | 786 | |
|
787 | 787 | __isConfig = None |
|
788 | 788 | __nsubplots = None |
|
789 | 789 | |
|
790 | 790 | WIDTHPROF = None |
|
791 | 791 | HEIGHTPROF = None |
|
792 | 792 | PREFIX = 'param' |
|
793 | 793 | |
|
794 | 794 | nplots = None |
|
795 | 795 | nchan = None |
|
796 | 796 | |
|
797 | 797 | def __init__(self, **kwargs): |
|
798 | 798 | Figure.__init__(self, **kwargs) |
|
799 | 799 | self.timerange = None |
|
800 | 800 | self.isConfig = False |
|
801 | 801 | self.__nsubplots = 1 |
|
802 | 802 | |
|
803 | 803 | self.WIDTH = 800 |
|
804 |
self.HEIGHT = |
|
|
804 | self.HEIGHT = 250 | |
|
805 | 805 | self.WIDTHPROF = 120 |
|
806 | 806 | self.HEIGHTPROF = 0 |
|
807 | 807 | self.counter_imagwr = 0 |
|
808 | 808 | |
|
809 | 809 | self.PLOT_CODE = RTI_CODE |
|
810 | 810 | |
|
811 | 811 | self.FTP_WEI = None |
|
812 | 812 | self.EXP_CODE = None |
|
813 | 813 | self.SUB_EXP_CODE = None |
|
814 | 814 | self.PLOT_POS = None |
|
815 | 815 | self.tmin = None |
|
816 | 816 | self.tmax = None |
|
817 | 817 | |
|
818 | 818 | self.xmin = None |
|
819 | 819 | self.xmax = None |
|
820 | 820 | |
|
821 | 821 | self.figfile = None |
|
822 | 822 | |
|
823 | 823 | def getSubplots(self): |
|
824 | 824 | |
|
825 | 825 | ncol = 1 |
|
826 | 826 | nrow = self.nplots |
|
827 | 827 | |
|
828 | 828 | return nrow, ncol |
|
829 | 829 | |
|
830 | 830 | def setup(self, id, nplots, wintitle, show=True): |
|
831 | 831 | |
|
832 | 832 | self.nplots = nplots |
|
833 | 833 | |
|
834 | 834 | ncolspan = 1 |
|
835 | 835 | colspan = 1 |
|
836 | 836 | |
|
837 | 837 | self.createFigure(id = id, |
|
838 | 838 | wintitle = wintitle, |
|
839 | 839 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
840 | 840 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
841 | 841 | show=show) |
|
842 | 842 | |
|
843 | 843 | nrow, ncol = self.getSubplots() |
|
844 | 844 | |
|
845 | 845 | counter = 0 |
|
846 | 846 | for y in range(nrow): |
|
847 | 847 | for x in range(ncol): |
|
848 | 848 | |
|
849 | 849 | if counter >= self.nplots: |
|
850 | 850 | break |
|
851 | 851 | |
|
852 | 852 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
853 | 853 | |
|
854 | 854 | counter += 1 |
|
855 | 855 | |
|
856 | 856 | def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet", |
|
857 | 857 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None, |
|
858 | 858 | showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None, |
|
859 | 859 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
860 | 860 | server=None, folder=None, username=None, password=None, |
|
861 | 861 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None): |
|
862 | 862 | """ |
|
863 | 863 | |
|
864 | 864 | Input: |
|
865 | 865 | dataOut : |
|
866 | 866 | id : |
|
867 | 867 | wintitle : |
|
868 | 868 | channelList : |
|
869 | 869 | showProfile : |
|
870 | 870 | xmin : None, |
|
871 | 871 | xmax : None, |
|
872 | 872 | ymin : None, |
|
873 | 873 | ymax : None, |
|
874 | 874 | zmin : None, |
|
875 | 875 | zmax : None |
|
876 | 876 | """ |
|
877 | 877 | |
|
878 | 878 | if HEIGHT is not None: |
|
879 | 879 | self.HEIGHT = HEIGHT |
|
880 | 880 | |
|
881 | 881 | |
|
882 | 882 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
883 | 883 | return |
|
884 | 884 | |
|
885 | 885 | if channelList == None: |
|
886 | 886 | channelIndexList = range(dataOut.data_param.shape[0]) |
|
887 | 887 | else: |
|
888 | 888 | channelIndexList = [] |
|
889 | 889 | for channel in channelList: |
|
890 | 890 | if channel not in dataOut.channelList: |
|
891 | 891 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
892 | 892 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
893 | 893 | |
|
894 | 894 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
895 | 895 | y = dataOut.getHeiRange() |
|
896 | 896 | |
|
897 | 897 | if dataOut.data_param.ndim == 3: |
|
898 | 898 | z = dataOut.data_param[channelIndexList,paramIndex,:] |
|
899 | 899 | else: |
|
900 | 900 | z = dataOut.data_param[channelIndexList,:] |
|
901 | 901 | |
|
902 | 902 | if showSNR: |
|
903 | 903 | #SNR data |
|
904 | 904 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
905 | 905 | SNRdB = 10*numpy.log10(SNRarray) |
|
906 | 906 | ind = numpy.where(SNRdB < SNRthresh) |
|
907 | 907 | z[ind] = numpy.nan |
|
908 | 908 | |
|
909 | 909 | thisDatetime = dataOut.datatime |
|
910 | 910 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
911 | 911 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
912 | 912 | xlabel = "" |
|
913 | 913 | ylabel = "Range (Km)" |
|
914 | 914 | |
|
915 | 915 | update_figfile = False |
|
916 | 916 | |
|
917 | 917 | if not self.isConfig: |
|
918 | 918 | |
|
919 | 919 | nchan = len(channelIndexList) |
|
920 | 920 | self.nchan = nchan |
|
921 | 921 | self.plotFact = 1 |
|
922 | 922 | nplots = nchan |
|
923 | 923 | |
|
924 | 924 | if showSNR: |
|
925 | 925 | nplots = nchan*2 |
|
926 | 926 | self.plotFact = 2 |
|
927 | 927 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
928 | 928 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
929 | 929 | |
|
930 | 930 | self.setup(id=id, |
|
931 | 931 | nplots=nplots, |
|
932 | 932 | wintitle=wintitle, |
|
933 | 933 | show=show) |
|
934 | 934 | |
|
935 | 935 | if timerange != None: |
|
936 | 936 | self.timerange = timerange |
|
937 | 937 | |
|
938 | 938 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
939 | 939 | |
|
940 | 940 | if ymin == None: ymin = numpy.nanmin(y) |
|
941 | 941 | if ymax == None: ymax = numpy.nanmax(y) |
|
942 | 942 | if zmin == None: zmin = numpy.nanmin(z) |
|
943 | 943 | if zmax == None: zmax = numpy.nanmax(z) |
|
944 | 944 | |
|
945 | 945 | self.FTP_WEI = ftp_wei |
|
946 | 946 | self.EXP_CODE = exp_code |
|
947 | 947 | self.SUB_EXP_CODE = sub_exp_code |
|
948 | 948 | self.PLOT_POS = plot_pos |
|
949 | 949 | |
|
950 | 950 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
951 | 951 | self.isConfig = True |
|
952 | 952 | self.figfile = figfile |
|
953 | 953 | update_figfile = True |
|
954 | 954 | |
|
955 | 955 | self.setWinTitle(title) |
|
956 | 956 | |
|
957 | 957 | for i in range(self.nchan): |
|
958 | 958 | index = channelIndexList[i] |
|
959 | 959 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
960 | 960 | axes = self.axesList[i*self.plotFact] |
|
961 | 961 | z1 = z[i,:].reshape((1,-1)) |
|
962 | 962 | axes.pcolorbuffer(x, y, z1, |
|
963 | 963 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
964 | 964 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
965 | 965 | ticksize=9, cblabel='', cbsize="1%",colormap=colormap) |
|
966 | 966 | |
|
967 | 967 | if showSNR: |
|
968 | 968 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
969 | 969 | axes = self.axesList[i*self.plotFact + 1] |
|
970 | 970 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) |
|
971 | 971 | axes.pcolorbuffer(x, y, SNRdB1, |
|
972 | 972 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
973 | 973 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
974 | 974 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') |
|
975 | 975 | |
|
976 | 976 | |
|
977 | 977 | self.draw() |
|
978 | 978 | |
|
979 | 979 | if dataOut.ltctime >= self.xmax: |
|
980 | 980 | self.counter_imagwr = wr_period |
|
981 | 981 | self.isConfig = False |
|
982 | 982 | update_figfile = True |
|
983 | 983 | |
|
984 | 984 | self.save(figpath=figpath, |
|
985 | 985 | figfile=figfile, |
|
986 | 986 | save=save, |
|
987 | 987 | ftp=ftp, |
|
988 | 988 | wr_period=wr_period, |
|
989 | 989 | thisDatetime=thisDatetime, |
|
990 | 990 | update_figfile=update_figfile) |
|
991 | 991 | |
|
992 | 992 | |
|
993 | 993 | |
|
994 | 994 | class Parameters1Plot(Figure): |
|
995 | 995 | |
|
996 | 996 | __isConfig = None |
|
997 | 997 | __nsubplots = None |
|
998 | 998 | |
|
999 | 999 | WIDTHPROF = None |
|
1000 | 1000 | HEIGHTPROF = None |
|
1001 | 1001 | PREFIX = 'prm' |
|
1002 | 1002 | |
|
1003 | 1003 | def __init__(self, **kwargs): |
|
1004 | 1004 | Figure.__init__(self, **kwargs) |
|
1005 | 1005 | self.timerange = 2*60*60 |
|
1006 | 1006 | self.isConfig = False |
|
1007 | 1007 | self.__nsubplots = 1 |
|
1008 | 1008 | |
|
1009 | 1009 | self.WIDTH = 800 |
|
1010 | 1010 | self.HEIGHT = 180 |
|
1011 | 1011 | self.WIDTHPROF = 120 |
|
1012 | 1012 | self.HEIGHTPROF = 0 |
|
1013 | 1013 | self.counter_imagwr = 0 |
|
1014 | 1014 | |
|
1015 | 1015 | self.PLOT_CODE = PARMS_CODE |
|
1016 | 1016 | |
|
1017 | 1017 | self.FTP_WEI = None |
|
1018 | 1018 | self.EXP_CODE = None |
|
1019 | 1019 | self.SUB_EXP_CODE = None |
|
1020 | 1020 | self.PLOT_POS = None |
|
1021 | 1021 | self.tmin = None |
|
1022 | 1022 | self.tmax = None |
|
1023 | 1023 | |
|
1024 | 1024 | self.xmin = None |
|
1025 | 1025 | self.xmax = None |
|
1026 | 1026 | |
|
1027 | 1027 | self.figfile = None |
|
1028 | 1028 | |
|
1029 | 1029 | def getSubplots(self): |
|
1030 | 1030 | |
|
1031 | 1031 | ncol = 1 |
|
1032 | 1032 | nrow = self.nplots |
|
1033 | 1033 | |
|
1034 | 1034 | return nrow, ncol |
|
1035 | 1035 | |
|
1036 | 1036 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1037 | 1037 | |
|
1038 | 1038 | self.__showprofile = showprofile |
|
1039 | 1039 | self.nplots = nplots |
|
1040 | 1040 | |
|
1041 | 1041 | ncolspan = 1 |
|
1042 | 1042 | colspan = 1 |
|
1043 | 1043 | |
|
1044 | 1044 | self.createFigure(id = id, |
|
1045 | 1045 | wintitle = wintitle, |
|
1046 | 1046 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1047 | 1047 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1048 | 1048 | show=show) |
|
1049 | 1049 | |
|
1050 | 1050 | nrow, ncol = self.getSubplots() |
|
1051 | 1051 | |
|
1052 | 1052 | counter = 0 |
|
1053 | 1053 | for y in range(nrow): |
|
1054 | 1054 | for x in range(ncol): |
|
1055 | 1055 | |
|
1056 | 1056 | if counter >= self.nplots: |
|
1057 | 1057 | break |
|
1058 | 1058 | |
|
1059 | 1059 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1060 | 1060 | |
|
1061 | 1061 | if showprofile: |
|
1062 | 1062 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1063 | 1063 | |
|
1064 | 1064 | counter += 1 |
|
1065 | 1065 | |
|
1066 | 1066 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
1067 | 1067 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
1068 | 1068 | parameterIndex = None, onlyPositive = False, |
|
1069 | 1069 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False, |
|
1070 | 1070 | DOP = True, |
|
1071 | 1071 | zlabel = "", parameterName = "", parameterObject = "data_param", |
|
1072 | 1072 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1073 | 1073 | server=None, folder=None, username=None, password=None, |
|
1074 | 1074 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1075 | 1075 | #print inspect.getargspec(self.run).args |
|
1076 | 1076 | """ |
|
1077 | 1077 | |
|
1078 | 1078 | Input: |
|
1079 | 1079 | dataOut : |
|
1080 | 1080 | id : |
|
1081 | 1081 | wintitle : |
|
1082 | 1082 | channelList : |
|
1083 | 1083 | showProfile : |
|
1084 | 1084 | xmin : None, |
|
1085 | 1085 | xmax : None, |
|
1086 | 1086 | ymin : None, |
|
1087 | 1087 | ymax : None, |
|
1088 | 1088 | zmin : None, |
|
1089 | 1089 | zmax : None |
|
1090 | 1090 | """ |
|
1091 | 1091 | |
|
1092 | 1092 | data_param = getattr(dataOut, parameterObject) |
|
1093 | 1093 | |
|
1094 | 1094 | if channelList == None: |
|
1095 | 1095 | channelIndexList = numpy.arange(data_param.shape[0]) |
|
1096 | 1096 | else: |
|
1097 | 1097 | channelIndexList = numpy.array(channelList) |
|
1098 | 1098 | |
|
1099 | 1099 | nchan = len(channelIndexList) #Number of channels being plotted |
|
1100 | 1100 | |
|
1101 | 1101 | if nchan < 1: |
|
1102 | 1102 | return |
|
1103 | 1103 | |
|
1104 | 1104 | nGraphsByChannel = 0 |
|
1105 | 1105 | |
|
1106 | 1106 | if SNR: |
|
1107 | 1107 | nGraphsByChannel += 1 |
|
1108 | 1108 | if DOP: |
|
1109 | 1109 | nGraphsByChannel += 1 |
|
1110 | 1110 | |
|
1111 | 1111 | if nGraphsByChannel < 1: |
|
1112 | 1112 | return |
|
1113 | 1113 | |
|
1114 | 1114 | nplots = nGraphsByChannel*nchan |
|
1115 | 1115 | |
|
1116 | 1116 | if timerange is not None: |
|
1117 | 1117 | self.timerange = timerange |
|
1118 | 1118 | |
|
1119 | 1119 | #tmin = None |
|
1120 | 1120 | #tmax = None |
|
1121 | 1121 | if parameterIndex == None: |
|
1122 | 1122 | parameterIndex = 1 |
|
1123 | 1123 | |
|
1124 | 1124 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
1125 | 1125 | y = dataOut.heightList |
|
1126 | 1126 | z = data_param[channelIndexList,parameterIndex,:].copy() |
|
1127 | 1127 | |
|
1128 | 1128 | zRange = dataOut.abscissaList |
|
1129 | 1129 | # nChannels = z.shape[0] #Number of wind dimensions estimated |
|
1130 | 1130 | # thisDatetime = dataOut.datatime |
|
1131 | 1131 | |
|
1132 | 1132 | if dataOut.data_SNR is not None: |
|
1133 | 1133 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
1134 | 1134 | SNRdB = 10*numpy.log10(SNRarray) |
|
1135 | 1135 | # SNRavgdB = 10*numpy.log10(SNRavg) |
|
1136 | 1136 | ind = numpy.where(SNRdB < 10**(SNRthresh/10)) |
|
1137 | 1137 | z[ind] = numpy.nan |
|
1138 | 1138 | |
|
1139 | 1139 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1140 | 1140 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1141 | 1141 | xlabel = "" |
|
1142 | 1142 | ylabel = "Range (Km)" |
|
1143 | 1143 | |
|
1144 | 1144 | if (SNR and not onlySNR): nplots = 2*nplots |
|
1145 | 1145 | |
|
1146 | 1146 | if onlyPositive: |
|
1147 | 1147 | colormap = "jet" |
|
1148 | 1148 | zmin = 0 |
|
1149 | 1149 | else: colormap = "RdBu_r" |
|
1150 | 1150 | |
|
1151 | 1151 | if not self.isConfig: |
|
1152 | 1152 | |
|
1153 | 1153 | self.setup(id=id, |
|
1154 | 1154 | nplots=nplots, |
|
1155 | 1155 | wintitle=wintitle, |
|
1156 | 1156 | showprofile=showprofile, |
|
1157 | 1157 | show=show) |
|
1158 | 1158 | |
|
1159 | 1159 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1160 | 1160 | |
|
1161 | 1161 | if ymin == None: ymin = numpy.nanmin(y) |
|
1162 | 1162 | if ymax == None: ymax = numpy.nanmax(y) |
|
1163 | 1163 | if zmin == None: zmin = numpy.nanmin(zRange) |
|
1164 | 1164 | if zmax == None: zmax = numpy.nanmax(zRange) |
|
1165 | 1165 | |
|
1166 | 1166 | if SNR: |
|
1167 | 1167 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
1168 | 1168 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
1169 | 1169 | |
|
1170 | 1170 | self.FTP_WEI = ftp_wei |
|
1171 | 1171 | self.EXP_CODE = exp_code |
|
1172 | 1172 | self.SUB_EXP_CODE = sub_exp_code |
|
1173 | 1173 | self.PLOT_POS = plot_pos |
|
1174 | 1174 | |
|
1175 | 1175 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1176 | 1176 | self.isConfig = True |
|
1177 | 1177 | self.figfile = figfile |
|
1178 | 1178 | |
|
1179 | 1179 | self.setWinTitle(title) |
|
1180 | 1180 | |
|
1181 | 1181 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1182 | 1182 | x[1] = self.xmax |
|
1183 | 1183 | |
|
1184 | 1184 | for i in range(nchan): |
|
1185 | 1185 | |
|
1186 | 1186 | if (SNR and not onlySNR): j = 2*i |
|
1187 | 1187 | else: j = i |
|
1188 | 1188 | |
|
1189 | 1189 | j = nGraphsByChannel*i |
|
1190 | 1190 | |
|
1191 | 1191 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1192 | 1192 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
1193 | 1193 | |
|
1194 | 1194 | if not onlySNR: |
|
1195 | 1195 | axes = self.axesList[j*self.__nsubplots] |
|
1196 | 1196 | z1 = z[i,:].reshape((1,-1)) |
|
1197 | 1197 | axes.pcolorbuffer(x, y, z1, |
|
1198 | 1198 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1199 | 1199 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
1200 | 1200 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1201 | 1201 | |
|
1202 | 1202 | if DOP: |
|
1203 | 1203 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1204 | 1204 | |
|
1205 | 1205 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1206 | 1206 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
1207 | 1207 | axes = self.axesList[j] |
|
1208 | 1208 | z1 = z[i,:].reshape((1,-1)) |
|
1209 | 1209 | axes.pcolorbuffer(x, y, z1, |
|
1210 | 1210 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1211 | 1211 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
1212 | 1212 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1213 | 1213 | |
|
1214 | 1214 | if SNR: |
|
1215 | 1215 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1216 | 1216 | axes = self.axesList[(j)*self.__nsubplots] |
|
1217 | 1217 | if not onlySNR: |
|
1218 | 1218 | axes = self.axesList[(j + 1)*self.__nsubplots] |
|
1219 | 1219 | |
|
1220 | 1220 | axes = self.axesList[(j + nGraphsByChannel-1)] |
|
1221 | 1221 | |
|
1222 | 1222 | z1 = SNRdB[i,:].reshape((1,-1)) |
|
1223 | 1223 | axes.pcolorbuffer(x, y, z1, |
|
1224 | 1224 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1225 | 1225 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", |
|
1226 | 1226 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1227 | 1227 | |
|
1228 | 1228 | |
|
1229 | 1229 | |
|
1230 | 1230 | self.draw() |
|
1231 | 1231 | |
|
1232 | 1232 | if x[1] >= self.axesList[0].xmax: |
|
1233 | 1233 | self.counter_imagwr = wr_period |
|
1234 | 1234 | self.isConfig = False |
|
1235 | 1235 | self.figfile = None |
|
1236 | 1236 | |
|
1237 | 1237 | self.save(figpath=figpath, |
|
1238 | 1238 | figfile=figfile, |
|
1239 | 1239 | save=save, |
|
1240 | 1240 | ftp=ftp, |
|
1241 | 1241 | wr_period=wr_period, |
|
1242 | 1242 | thisDatetime=thisDatetime, |
|
1243 | 1243 | update_figfile=False) |
|
1244 | 1244 | |
|
1245 | 1245 | class SpectralFittingPlot(Figure): |
|
1246 | 1246 | |
|
1247 | 1247 | __isConfig = None |
|
1248 | 1248 | __nsubplots = None |
|
1249 | 1249 | |
|
1250 | 1250 | WIDTHPROF = None |
|
1251 | 1251 | HEIGHTPROF = None |
|
1252 | 1252 | PREFIX = 'prm' |
|
1253 | 1253 | |
|
1254 | 1254 | |
|
1255 | 1255 | N = None |
|
1256 | 1256 | ippSeconds = None |
|
1257 | 1257 | |
|
1258 | 1258 | def __init__(self, **kwargs): |
|
1259 | 1259 | Figure.__init__(self, **kwargs) |
|
1260 | 1260 | self.isConfig = False |
|
1261 | 1261 | self.__nsubplots = 1 |
|
1262 | 1262 | |
|
1263 | 1263 | self.PLOT_CODE = SPECFIT_CODE |
|
1264 | 1264 | |
|
1265 | 1265 | self.WIDTH = 450 |
|
1266 | 1266 | self.HEIGHT = 250 |
|
1267 | 1267 | self.WIDTHPROF = 0 |
|
1268 | 1268 | self.HEIGHTPROF = 0 |
|
1269 | 1269 | |
|
1270 | 1270 | def getSubplots(self): |
|
1271 | 1271 | |
|
1272 | 1272 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1273 | 1273 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1274 | 1274 | |
|
1275 | 1275 | return nrow, ncol |
|
1276 | 1276 | |
|
1277 | 1277 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
1278 | 1278 | |
|
1279 | 1279 | showprofile = False |
|
1280 | 1280 | self.__showprofile = showprofile |
|
1281 | 1281 | self.nplots = nplots |
|
1282 | 1282 | |
|
1283 | 1283 | ncolspan = 5 |
|
1284 | 1284 | colspan = 4 |
|
1285 | 1285 | if showprofile: |
|
1286 | 1286 | ncolspan = 5 |
|
1287 | 1287 | colspan = 4 |
|
1288 | 1288 | self.__nsubplots = 2 |
|
1289 | 1289 | |
|
1290 | 1290 | self.createFigure(id = id, |
|
1291 | 1291 | wintitle = wintitle, |
|
1292 | 1292 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1293 | 1293 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1294 | 1294 | show=show) |
|
1295 | 1295 | |
|
1296 | 1296 | nrow, ncol = self.getSubplots() |
|
1297 | 1297 | |
|
1298 | 1298 | counter = 0 |
|
1299 | 1299 | for y in range(nrow): |
|
1300 | 1300 | for x in range(ncol): |
|
1301 | 1301 | |
|
1302 | 1302 | if counter >= self.nplots: |
|
1303 | 1303 | break |
|
1304 | 1304 | |
|
1305 | 1305 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1306 | 1306 | |
|
1307 | 1307 | if showprofile: |
|
1308 | 1308 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1309 | 1309 | |
|
1310 | 1310 | counter += 1 |
|
1311 | 1311 | |
|
1312 | 1312 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, |
|
1313 | 1313 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1314 | 1314 | save=False, figpath='./', figfile=None, show=True): |
|
1315 | 1315 | |
|
1316 | 1316 | """ |
|
1317 | 1317 | |
|
1318 | 1318 | Input: |
|
1319 | 1319 | dataOut : |
|
1320 | 1320 | id : |
|
1321 | 1321 | wintitle : |
|
1322 | 1322 | channelList : |
|
1323 | 1323 | showProfile : |
|
1324 | 1324 | xmin : None, |
|
1325 | 1325 | xmax : None, |
|
1326 | 1326 | zmin : None, |
|
1327 | 1327 | zmax : None |
|
1328 | 1328 | """ |
|
1329 | 1329 | |
|
1330 | 1330 | if cutHeight==None: |
|
1331 | 1331 | h=270 |
|
1332 | 1332 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() |
|
1333 | 1333 | cutHeight = dataOut.heightList[heightindex] |
|
1334 | 1334 | |
|
1335 | 1335 | factor = dataOut.normFactor |
|
1336 | 1336 | x = dataOut.abscissaList[:-1] |
|
1337 | 1337 | #y = dataOut.getHeiRange() |
|
1338 | 1338 | |
|
1339 | 1339 | z = dataOut.data_pre[:,:,heightindex]/factor |
|
1340 | 1340 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1341 | 1341 | avg = numpy.average(z, axis=1) |
|
1342 | 1342 | listChannels = z.shape[0] |
|
1343 | 1343 | |
|
1344 | 1344 | #Reconstruct Function |
|
1345 | 1345 | if fit==True: |
|
1346 | 1346 | groupArray = dataOut.groupList |
|
1347 | 1347 | listChannels = groupArray.reshape((groupArray.size)) |
|
1348 | 1348 | listChannels.sort() |
|
1349 | 1349 | spcFitLine = numpy.zeros(z.shape) |
|
1350 | 1350 | constants = dataOut.constants |
|
1351 | 1351 | |
|
1352 | 1352 | nGroups = groupArray.shape[0] |
|
1353 | 1353 | nChannels = groupArray.shape[1] |
|
1354 | 1354 | nProfiles = z.shape[1] |
|
1355 | 1355 | |
|
1356 | 1356 | for f in range(nGroups): |
|
1357 | 1357 | groupChann = groupArray[f,:] |
|
1358 | 1358 | p = dataOut.data_param[f,:,heightindex] |
|
1359 | 1359 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) |
|
1360 | 1360 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles |
|
1361 | 1361 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) |
|
1362 | 1362 | spcFitLine[groupChann,:] = fitLineAux |
|
1363 | 1363 | # spcFitLine = spcFitLine/factor |
|
1364 | 1364 | |
|
1365 | 1365 | z = z[listChannels,:] |
|
1366 | 1366 | spcFitLine = spcFitLine[listChannels,:] |
|
1367 | 1367 | spcFitLinedB = 10*numpy.log10(spcFitLine) |
|
1368 | 1368 | |
|
1369 | 1369 | zdB = 10*numpy.log10(z) |
|
1370 | 1370 | #thisDatetime = dataOut.datatime |
|
1371 | 1371 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1372 | 1372 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1373 | 1373 | xlabel = "Velocity (m/s)" |
|
1374 | 1374 | ylabel = "Spectrum" |
|
1375 | 1375 | |
|
1376 | 1376 | if not self.isConfig: |
|
1377 | 1377 | |
|
1378 | 1378 | nplots = listChannels.size |
|
1379 | 1379 | |
|
1380 | 1380 | self.setup(id=id, |
|
1381 | 1381 | nplots=nplots, |
|
1382 | 1382 | wintitle=wintitle, |
|
1383 | 1383 | showprofile=showprofile, |
|
1384 | 1384 | show=show) |
|
1385 | 1385 | |
|
1386 | 1386 | if xmin == None: xmin = numpy.nanmin(x) |
|
1387 | 1387 | if xmax == None: xmax = numpy.nanmax(x) |
|
1388 | 1388 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1389 | 1389 | if ymax == None: ymax = numpy.nanmax(zdB)+2 |
|
1390 | 1390 | |
|
1391 | 1391 | self.isConfig = True |
|
1392 | 1392 | |
|
1393 | 1393 | self.setWinTitle(title) |
|
1394 | 1394 | for i in range(self.nplots): |
|
1395 | 1395 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
1396 | 1396 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]) |
|
1397 | 1397 | axes = self.axesList[i*self.__nsubplots] |
|
1398 | 1398 | if fit == False: |
|
1399 | 1399 | axes.pline(x, zdB[i,:], |
|
1400 | 1400 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1401 | 1401 | xlabel=xlabel, ylabel=ylabel, title=title |
|
1402 | 1402 | ) |
|
1403 | 1403 | if fit == True: |
|
1404 | 1404 | fitline=spcFitLinedB[i,:] |
|
1405 | 1405 | y=numpy.vstack([zdB[i,:],fitline] ) |
|
1406 | 1406 | legendlabels=['Data','Fitting'] |
|
1407 | 1407 | axes.pmultilineyaxis(x, y, |
|
1408 | 1408 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1409 | 1409 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
1410 | 1410 | legendlabels=legendlabels, marker=None, |
|
1411 | 1411 | linestyle='solid', grid='both') |
|
1412 | 1412 | |
|
1413 | 1413 | self.draw() |
|
1414 | 1414 | |
|
1415 | 1415 | self.save(figpath=figpath, |
|
1416 | 1416 | figfile=figfile, |
|
1417 | 1417 | save=save, |
|
1418 | 1418 | ftp=ftp, |
|
1419 | 1419 | wr_period=wr_period, |
|
1420 | 1420 | thisDatetime=thisDatetime) |
|
1421 | 1421 | |
|
1422 | 1422 | |
|
1423 | 1423 | class EWDriftsPlot(Figure): |
|
1424 | 1424 | |
|
1425 | 1425 | __isConfig = None |
|
1426 | 1426 | __nsubplots = None |
|
1427 | 1427 | |
|
1428 | 1428 | WIDTHPROF = None |
|
1429 | 1429 | HEIGHTPROF = None |
|
1430 | 1430 | PREFIX = 'drift' |
|
1431 | 1431 | |
|
1432 | 1432 | def __init__(self, **kwargs): |
|
1433 | 1433 | Figure.__init__(self, **kwargs) |
|
1434 | 1434 | self.timerange = 2*60*60 |
|
1435 | 1435 | self.isConfig = False |
|
1436 | 1436 | self.__nsubplots = 1 |
|
1437 | 1437 | |
|
1438 | 1438 | self.WIDTH = 800 |
|
1439 | 1439 | self.HEIGHT = 150 |
|
1440 | 1440 | self.WIDTHPROF = 120 |
|
1441 | 1441 | self.HEIGHTPROF = 0 |
|
1442 | 1442 | self.counter_imagwr = 0 |
|
1443 | 1443 | |
|
1444 | 1444 | self.PLOT_CODE = EWDRIFT_CODE |
|
1445 | 1445 | |
|
1446 | 1446 | self.FTP_WEI = None |
|
1447 | 1447 | self.EXP_CODE = None |
|
1448 | 1448 | self.SUB_EXP_CODE = None |
|
1449 | 1449 | self.PLOT_POS = None |
|
1450 | 1450 | self.tmin = None |
|
1451 | 1451 | self.tmax = None |
|
1452 | 1452 | |
|
1453 | 1453 | self.xmin = None |
|
1454 | 1454 | self.xmax = None |
|
1455 | 1455 | |
|
1456 | 1456 | self.figfile = None |
|
1457 | 1457 | |
|
1458 | 1458 | def getSubplots(self): |
|
1459 | 1459 | |
|
1460 | 1460 | ncol = 1 |
|
1461 | 1461 | nrow = self.nplots |
|
1462 | 1462 | |
|
1463 | 1463 | return nrow, ncol |
|
1464 | 1464 | |
|
1465 | 1465 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1466 | 1466 | |
|
1467 | 1467 | self.__showprofile = showprofile |
|
1468 | 1468 | self.nplots = nplots |
|
1469 | 1469 | |
|
1470 | 1470 | ncolspan = 1 |
|
1471 | 1471 | colspan = 1 |
|
1472 | 1472 | |
|
1473 | 1473 | self.createFigure(id = id, |
|
1474 | 1474 | wintitle = wintitle, |
|
1475 | 1475 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1476 | 1476 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1477 | 1477 | show=show) |
|
1478 | 1478 | |
|
1479 | 1479 | nrow, ncol = self.getSubplots() |
|
1480 | 1480 | |
|
1481 | 1481 | counter = 0 |
|
1482 | 1482 | for y in range(nrow): |
|
1483 | 1483 | if counter >= self.nplots: |
|
1484 | 1484 | break |
|
1485 | 1485 | |
|
1486 | 1486 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
1487 | 1487 | counter += 1 |
|
1488 | 1488 | |
|
1489 | 1489 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1490 | 1490 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1491 | 1491 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, |
|
1492 | 1492 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, |
|
1493 | 1493 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1494 | 1494 | server=None, folder=None, username=None, password=None, |
|
1495 | 1495 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1496 | 1496 | """ |
|
1497 | 1497 | |
|
1498 | 1498 | Input: |
|
1499 | 1499 | dataOut : |
|
1500 | 1500 | id : |
|
1501 | 1501 | wintitle : |
|
1502 | 1502 | channelList : |
|
1503 | 1503 | showProfile : |
|
1504 | 1504 | xmin : None, |
|
1505 | 1505 | xmax : None, |
|
1506 | 1506 | ymin : None, |
|
1507 | 1507 | ymax : None, |
|
1508 | 1508 | zmin : None, |
|
1509 | 1509 | zmax : None |
|
1510 | 1510 | """ |
|
1511 | 1511 | |
|
1512 | 1512 | if timerange is not None: |
|
1513 | 1513 | self.timerange = timerange |
|
1514 | 1514 | |
|
1515 | 1515 | tmin = None |
|
1516 | 1516 | tmax = None |
|
1517 | 1517 | |
|
1518 | 1518 | x = dataOut.getTimeRange1(dataOut.outputInterval) |
|
1519 | 1519 | # y = dataOut.heightList |
|
1520 | 1520 | y = dataOut.heightList |
|
1521 | 1521 | |
|
1522 | 1522 | z = dataOut.data_output |
|
1523 | 1523 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
1524 | 1524 | nplotsw = nplots |
|
1525 | 1525 | |
|
1526 | 1526 | #If there is a SNR function defined |
|
1527 | 1527 | if dataOut.data_SNR is not None: |
|
1528 | 1528 | nplots += 1 |
|
1529 | 1529 | SNR = dataOut.data_SNR |
|
1530 | 1530 | |
|
1531 | 1531 | if SNR_1: |
|
1532 | 1532 | SNR += 1 |
|
1533 | 1533 | |
|
1534 | 1534 | SNRavg = numpy.average(SNR, axis=0) |
|
1535 | 1535 | |
|
1536 | 1536 | SNRdB = 10*numpy.log10(SNR) |
|
1537 | 1537 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
1538 | 1538 | |
|
1539 | 1539 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
1540 | 1540 | |
|
1541 | 1541 | for i in range(nplotsw): |
|
1542 | 1542 | z[i,ind] = numpy.nan |
|
1543 | 1543 | |
|
1544 | 1544 | |
|
1545 | 1545 | showprofile = False |
|
1546 | 1546 | # thisDatetime = dataOut.datatime |
|
1547 | 1547 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) |
|
1548 | 1548 | title = wintitle + " EW Drifts" |
|
1549 | 1549 | xlabel = "" |
|
1550 | 1550 | ylabel = "Height (Km)" |
|
1551 | 1551 | |
|
1552 | 1552 | if not self.isConfig: |
|
1553 | 1553 | |
|
1554 | 1554 | self.setup(id=id, |
|
1555 | 1555 | nplots=nplots, |
|
1556 | 1556 | wintitle=wintitle, |
|
1557 | 1557 | showprofile=showprofile, |
|
1558 | 1558 | show=show) |
|
1559 | 1559 | |
|
1560 | 1560 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1561 | 1561 | |
|
1562 | 1562 | if ymin == None: ymin = numpy.nanmin(y) |
|
1563 | 1563 | if ymax == None: ymax = numpy.nanmax(y) |
|
1564 | 1564 | |
|
1565 | 1565 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) |
|
1566 | 1566 | if zminZonal == None: zminZonal = -zmaxZonal |
|
1567 | 1567 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) |
|
1568 | 1568 | if zminVertical == None: zminVertical = -zmaxVertical |
|
1569 | 1569 | |
|
1570 | 1570 | if dataOut.data_SNR is not None: |
|
1571 | 1571 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
1572 | 1572 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
1573 | 1573 | |
|
1574 | 1574 | self.FTP_WEI = ftp_wei |
|
1575 | 1575 | self.EXP_CODE = exp_code |
|
1576 | 1576 | self.SUB_EXP_CODE = sub_exp_code |
|
1577 | 1577 | self.PLOT_POS = plot_pos |
|
1578 | 1578 | |
|
1579 | 1579 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1580 | 1580 | self.isConfig = True |
|
1581 | 1581 | |
|
1582 | 1582 | |
|
1583 | 1583 | self.setWinTitle(title) |
|
1584 | 1584 | |
|
1585 | 1585 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1586 | 1586 | x[1] = self.xmax |
|
1587 | 1587 | |
|
1588 | 1588 | strWind = ['Zonal','Vertical'] |
|
1589 | 1589 | strCb = 'Velocity (m/s)' |
|
1590 | 1590 | zmaxVector = [zmaxZonal, zmaxVertical] |
|
1591 | 1591 | zminVector = [zminZonal, zminVertical] |
|
1592 | 1592 | |
|
1593 | 1593 | for i in range(nplotsw): |
|
1594 | 1594 | |
|
1595 | 1595 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1596 | 1596 | axes = self.axesList[i*self.__nsubplots] |
|
1597 | 1597 | |
|
1598 | 1598 | z1 = z[i,:].reshape((1,-1)) |
|
1599 | 1599 | |
|
1600 | 1600 | axes.pcolorbuffer(x, y, z1, |
|
1601 | 1601 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
1602 | 1602 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1603 | 1603 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") |
|
1604 | 1604 | |
|
1605 | 1605 | if dataOut.data_SNR is not None: |
|
1606 | 1606 | i += 1 |
|
1607 | 1607 | if SNR_1: |
|
1608 | 1608 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1609 | 1609 | else: |
|
1610 | 1610 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1611 | 1611 | axes = self.axesList[i*self.__nsubplots] |
|
1612 | 1612 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
1613 | 1613 | |
|
1614 | 1614 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
1615 | 1615 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1616 | 1616 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1617 | 1617 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
1618 | 1618 | |
|
1619 | 1619 | self.draw() |
|
1620 | 1620 | |
|
1621 | 1621 | if x[1] >= self.axesList[0].xmax: |
|
1622 | 1622 | self.counter_imagwr = wr_period |
|
1623 | 1623 | self.isConfig = False |
|
1624 | 1624 | self.figfile = None |
|
1625 | 1625 | |
|
1626 | 1626 | |
|
1627 | 1627 | |
|
1628 | 1628 | |
|
1629 | 1629 | class PhasePlot(Figure): |
|
1630 | 1630 | |
|
1631 | 1631 | __isConfig = None |
|
1632 | 1632 | __nsubplots = None |
|
1633 | 1633 | |
|
1634 | 1634 | PREFIX = 'mphase' |
|
1635 | 1635 | |
|
1636 | 1636 | def __init__(self, **kwargs): |
|
1637 | 1637 | Figure.__init__(self, **kwargs) |
|
1638 | 1638 | self.timerange = 24*60*60 |
|
1639 | 1639 | self.isConfig = False |
|
1640 | 1640 | self.__nsubplots = 1 |
|
1641 | 1641 | self.counter_imagwr = 0 |
|
1642 | 1642 | self.WIDTH = 600 |
|
1643 | 1643 | self.HEIGHT = 300 |
|
1644 | 1644 | self.WIDTHPROF = 120 |
|
1645 | 1645 | self.HEIGHTPROF = 0 |
|
1646 | 1646 | self.xdata = None |
|
1647 | 1647 | self.ydata = None |
|
1648 | 1648 | |
|
1649 | 1649 | self.PLOT_CODE = MPHASE_CODE |
|
1650 | 1650 | |
|
1651 | 1651 | self.FTP_WEI = None |
|
1652 | 1652 | self.EXP_CODE = None |
|
1653 | 1653 | self.SUB_EXP_CODE = None |
|
1654 | 1654 | self.PLOT_POS = None |
|
1655 | 1655 | |
|
1656 | 1656 | |
|
1657 | 1657 | self.filename_phase = None |
|
1658 | 1658 | |
|
1659 | 1659 | self.figfile = None |
|
1660 | 1660 | |
|
1661 | 1661 | def getSubplots(self): |
|
1662 | 1662 | |
|
1663 | 1663 | ncol = 1 |
|
1664 | 1664 | nrow = 1 |
|
1665 | 1665 | |
|
1666 | 1666 | return nrow, ncol |
|
1667 | 1667 | |
|
1668 | 1668 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1669 | 1669 | |
|
1670 | 1670 | self.__showprofile = showprofile |
|
1671 | 1671 | self.nplots = nplots |
|
1672 | 1672 | |
|
1673 | 1673 | ncolspan = 7 |
|
1674 | 1674 | colspan = 6 |
|
1675 | 1675 | self.__nsubplots = 2 |
|
1676 | 1676 | |
|
1677 | 1677 | self.createFigure(id = id, |
|
1678 | 1678 | wintitle = wintitle, |
|
1679 | 1679 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1680 | 1680 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1681 | 1681 | show=show) |
|
1682 | 1682 | |
|
1683 | 1683 | nrow, ncol = self.getSubplots() |
|
1684 | 1684 | |
|
1685 | 1685 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1686 | 1686 | |
|
1687 | 1687 | |
|
1688 | 1688 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1689 | 1689 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1690 | 1690 | timerange=None, |
|
1691 | 1691 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1692 | 1692 | server=None, folder=None, username=None, password=None, |
|
1693 | 1693 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1694 | 1694 | |
|
1695 | 1695 | |
|
1696 | 1696 | tmin = None |
|
1697 | 1697 | tmax = None |
|
1698 | 1698 | x = dataOut.getTimeRange1(dataOut.outputInterval) |
|
1699 | 1699 | y = dataOut.getHeiRange() |
|
1700 | 1700 | |
|
1701 | 1701 | |
|
1702 | 1702 | #thisDatetime = dataOut.datatime |
|
1703 | 1703 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
1704 | 1704 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1705 | 1705 | xlabel = "Local Time" |
|
1706 | 1706 | ylabel = "Phase" |
|
1707 | 1707 | |
|
1708 | 1708 | |
|
1709 | 1709 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1710 | 1710 | phase_beacon = dataOut.data_output |
|
1711 | 1711 | update_figfile = False |
|
1712 | 1712 | |
|
1713 | 1713 | if not self.isConfig: |
|
1714 | 1714 | |
|
1715 | 1715 | self.nplots = phase_beacon.size |
|
1716 | 1716 | |
|
1717 | 1717 | self.setup(id=id, |
|
1718 | 1718 | nplots=self.nplots, |
|
1719 | 1719 | wintitle=wintitle, |
|
1720 | 1720 | showprofile=showprofile, |
|
1721 | 1721 | show=show) |
|
1722 | 1722 | |
|
1723 | 1723 | if timerange is not None: |
|
1724 | 1724 | self.timerange = timerange |
|
1725 | 1725 | |
|
1726 | 1726 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1727 | 1727 | |
|
1728 | 1728 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1729 | 1729 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1730 | 1730 | |
|
1731 | 1731 | self.FTP_WEI = ftp_wei |
|
1732 | 1732 | self.EXP_CODE = exp_code |
|
1733 | 1733 | self.SUB_EXP_CODE = sub_exp_code |
|
1734 | 1734 | self.PLOT_POS = plot_pos |
|
1735 | 1735 | |
|
1736 | 1736 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1737 | 1737 | self.isConfig = True |
|
1738 | 1738 | self.figfile = figfile |
|
1739 | 1739 | self.xdata = numpy.array([]) |
|
1740 | 1740 | self.ydata = numpy.array([]) |
|
1741 | 1741 | |
|
1742 | 1742 | #open file beacon phase |
|
1743 | 1743 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1744 | 1744 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1745 | 1745 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1746 | 1746 | update_figfile = True |
|
1747 | 1747 | |
|
1748 | 1748 | |
|
1749 | 1749 | #store data beacon phase |
|
1750 | 1750 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1751 | 1751 | |
|
1752 | 1752 | self.setWinTitle(title) |
|
1753 | 1753 | |
|
1754 | 1754 | |
|
1755 | 1755 | title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1756 | 1756 | |
|
1757 | 1757 | legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)] |
|
1758 | 1758 | |
|
1759 | 1759 | axes = self.axesList[0] |
|
1760 | 1760 | |
|
1761 | 1761 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1762 | 1762 | |
|
1763 | 1763 | if len(self.ydata)==0: |
|
1764 | 1764 | self.ydata = phase_beacon.reshape(-1,1) |
|
1765 | 1765 | else: |
|
1766 | 1766 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1767 | 1767 | |
|
1768 | 1768 | |
|
1769 | 1769 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1770 | 1770 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1771 | 1771 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1772 | 1772 | XAxisAsTime=True, grid='both' |
|
1773 | 1773 | ) |
|
1774 | 1774 | |
|
1775 | 1775 | self.draw() |
|
1776 | 1776 | |
|
1777 | 1777 | self.save(figpath=figpath, |
|
1778 | 1778 | figfile=figfile, |
|
1779 | 1779 | save=save, |
|
1780 | 1780 | ftp=ftp, |
|
1781 | 1781 | wr_period=wr_period, |
|
1782 | 1782 | thisDatetime=thisDatetime, |
|
1783 | 1783 | update_figfile=update_figfile) |
|
1784 | 1784 | |
|
1785 | 1785 | if dataOut.ltctime + dataOut.outputInterval >= self.xmax: |
|
1786 | 1786 | self.counter_imagwr = wr_period |
|
1787 | 1787 | self.isConfig = False |
|
1788 | 1788 | update_figfile = True |
|
1789 | 1789 | |
|
1790 | 1790 | |
|
1791 | 1791 | |
|
1792 | 1792 | class NSMeteorDetection1Plot(Figure): |
|
1793 | 1793 | |
|
1794 | 1794 | isConfig = None |
|
1795 | 1795 | __nsubplots = None |
|
1796 | 1796 | |
|
1797 | 1797 | WIDTHPROF = None |
|
1798 | 1798 | HEIGHTPROF = None |
|
1799 | 1799 | PREFIX = 'nsm' |
|
1800 | 1800 | |
|
1801 | 1801 | zminList = None |
|
1802 | 1802 | zmaxList = None |
|
1803 | 1803 | cmapList = None |
|
1804 | 1804 | titleList = None |
|
1805 | 1805 | nPairs = None |
|
1806 | 1806 | nChannels = None |
|
1807 | 1807 | nParam = None |
|
1808 | 1808 | |
|
1809 | 1809 | def __init__(self, **kwargs): |
|
1810 | 1810 | Figure.__init__(self, **kwargs) |
|
1811 | 1811 | self.isConfig = False |
|
1812 | 1812 | self.__nsubplots = 1 |
|
1813 | 1813 | |
|
1814 | 1814 | self.WIDTH = 750 |
|
1815 | 1815 | self.HEIGHT = 250 |
|
1816 | 1816 | self.WIDTHPROF = 120 |
|
1817 | 1817 | self.HEIGHTPROF = 0 |
|
1818 | 1818 | self.counter_imagwr = 0 |
|
1819 | 1819 | |
|
1820 | 1820 | self.PLOT_CODE = SPEC_CODE |
|
1821 | 1821 | |
|
1822 | 1822 | self.FTP_WEI = None |
|
1823 | 1823 | self.EXP_CODE = None |
|
1824 | 1824 | self.SUB_EXP_CODE = None |
|
1825 | 1825 | self.PLOT_POS = None |
|
1826 | 1826 | |
|
1827 | 1827 | self.__xfilter_ena = False |
|
1828 | 1828 | self.__yfilter_ena = False |
|
1829 | 1829 | |
|
1830 | 1830 | def getSubplots(self): |
|
1831 | 1831 | |
|
1832 | 1832 | ncol = 3 |
|
1833 | 1833 | nrow = int(numpy.ceil(self.nplots/3.0)) |
|
1834 | 1834 | |
|
1835 | 1835 | return nrow, ncol |
|
1836 | 1836 | |
|
1837 | 1837 | def setup(self, id, nplots, wintitle, show=True): |
|
1838 | 1838 | |
|
1839 | 1839 | self.nplots = nplots |
|
1840 | 1840 | |
|
1841 | 1841 | ncolspan = 1 |
|
1842 | 1842 | colspan = 1 |
|
1843 | 1843 | |
|
1844 | 1844 | self.createFigure(id = id, |
|
1845 | 1845 | wintitle = wintitle, |
|
1846 | 1846 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1847 | 1847 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1848 | 1848 | show=show) |
|
1849 | 1849 | |
|
1850 | 1850 | nrow, ncol = self.getSubplots() |
|
1851 | 1851 | |
|
1852 | 1852 | counter = 0 |
|
1853 | 1853 | for y in range(nrow): |
|
1854 | 1854 | for x in range(ncol): |
|
1855 | 1855 | |
|
1856 | 1856 | if counter >= self.nplots: |
|
1857 | 1857 | break |
|
1858 | 1858 | |
|
1859 | 1859 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1860 | 1860 | |
|
1861 | 1861 | counter += 1 |
|
1862 | 1862 | |
|
1863 | 1863 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
1864 | 1864 | xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None, |
|
1865 | 1865 | vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA', |
|
1866 | 1866 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1867 | 1867 | server=None, folder=None, username=None, password=None, |
|
1868 | 1868 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
1869 | 1869 | xaxis="frequency"): |
|
1870 | 1870 | |
|
1871 | 1871 | """ |
|
1872 | 1872 | |
|
1873 | 1873 | Input: |
|
1874 | 1874 | dataOut : |
|
1875 | 1875 | id : |
|
1876 | 1876 | wintitle : |
|
1877 | 1877 | channelList : |
|
1878 | 1878 | showProfile : |
|
1879 | 1879 | xmin : None, |
|
1880 | 1880 | xmax : None, |
|
1881 | 1881 | ymin : None, |
|
1882 | 1882 | ymax : None, |
|
1883 | 1883 | zmin : None, |
|
1884 | 1884 | zmax : None |
|
1885 | 1885 | """ |
|
1886 | 1886 | #SEPARAR EN DOS PLOTS |
|
1887 | 1887 | nParam = dataOut.data_param.shape[1] - 3 |
|
1888 | 1888 | |
|
1889 | 1889 | utctime = dataOut.data_param[0,0] |
|
1890 | 1890 | tmet = dataOut.data_param[:,1].astype(int) |
|
1891 | 1891 | hmet = dataOut.data_param[:,2].astype(int) |
|
1892 | 1892 | |
|
1893 | 1893 | x = dataOut.abscissaList |
|
1894 | 1894 | y = dataOut.heightList |
|
1895 | 1895 | |
|
1896 | 1896 | z = numpy.zeros((nParam, y.size, x.size - 1)) |
|
1897 | 1897 | z[:,:] = numpy.nan |
|
1898 | 1898 | z[:,hmet,tmet] = dataOut.data_param[:,3:].T |
|
1899 | 1899 | z[0,:,:] = 10*numpy.log10(z[0,:,:]) |
|
1900 | 1900 | |
|
1901 | 1901 | xlabel = "Time (s)" |
|
1902 | 1902 | ylabel = "Range (km)" |
|
1903 | 1903 | |
|
1904 | 1904 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
1905 | 1905 | |
|
1906 | 1906 | if not self.isConfig: |
|
1907 | 1907 | |
|
1908 | 1908 | nplots = nParam |
|
1909 | 1909 | |
|
1910 | 1910 | self.setup(id=id, |
|
1911 | 1911 | nplots=nplots, |
|
1912 | 1912 | wintitle=wintitle, |
|
1913 | 1913 | show=show) |
|
1914 | 1914 | |
|
1915 | 1915 | if xmin is None: xmin = numpy.nanmin(x) |
|
1916 | 1916 | if xmax is None: xmax = numpy.nanmax(x) |
|
1917 | 1917 | if ymin is None: ymin = numpy.nanmin(y) |
|
1918 | 1918 | if ymax is None: ymax = numpy.nanmax(y) |
|
1919 | 1919 | if SNRmin is None: SNRmin = numpy.nanmin(z[0,:]) |
|
1920 | 1920 | if SNRmax is None: SNRmax = numpy.nanmax(z[0,:]) |
|
1921 | 1921 | if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:])) |
|
1922 | 1922 | if vmin is None: vmin = -vmax |
|
1923 | 1923 | if wmin is None: wmin = 0 |
|
1924 | 1924 | if wmax is None: wmax = 50 |
|
1925 | 1925 | |
|
1926 | 1926 | pairsList = dataOut.groupList |
|
1927 | 1927 | self.nPairs = len(dataOut.groupList) |
|
1928 | 1928 | |
|
1929 | 1929 | zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs |
|
1930 | 1930 | zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs |
|
1931 | 1931 | titleList = ["SNR","Radial Velocity","Coherence"] |
|
1932 | 1932 | cmapList = ["jet","RdBu_r","jet"] |
|
1933 | 1933 | |
|
1934 | 1934 | for i in range(self.nPairs): |
|
1935 | 1935 | strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1]) |
|
1936 | 1936 | titleList = titleList + [strAux1] |
|
1937 | 1937 | cmapList = cmapList + ["RdBu_r"] |
|
1938 | 1938 | |
|
1939 | 1939 | self.zminList = zminList |
|
1940 | 1940 | self.zmaxList = zmaxList |
|
1941 | 1941 | self.cmapList = cmapList |
|
1942 | 1942 | self.titleList = titleList |
|
1943 | 1943 | |
|
1944 | 1944 | self.FTP_WEI = ftp_wei |
|
1945 | 1945 | self.EXP_CODE = exp_code |
|
1946 | 1946 | self.SUB_EXP_CODE = sub_exp_code |
|
1947 | 1947 | self.PLOT_POS = plot_pos |
|
1948 | 1948 | |
|
1949 | 1949 | self.isConfig = True |
|
1950 | 1950 | |
|
1951 | 1951 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
1952 | 1952 | |
|
1953 | 1953 | for i in range(nParam): |
|
1954 | 1954 | title = self.titleList[i] + ": " +str_datetime |
|
1955 | 1955 | axes = self.axesList[i] |
|
1956 | 1956 | axes.pcolor(x, y, z[i,:].T, |
|
1957 | 1957 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i], |
|
1958 | 1958 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='') |
|
1959 | 1959 | self.draw() |
|
1960 | 1960 | |
|
1961 | 1961 | if figfile == None: |
|
1962 | 1962 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1963 | 1963 | name = str_datetime |
|
1964 | 1964 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1965 | 1965 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
1966 | 1966 | figfile = self.getFilename(name) |
|
1967 | 1967 | |
|
1968 | 1968 | self.save(figpath=figpath, |
|
1969 | 1969 | figfile=figfile, |
|
1970 | 1970 | save=save, |
|
1971 | 1971 | ftp=ftp, |
|
1972 | 1972 | wr_period=wr_period, |
|
1973 | 1973 | thisDatetime=thisDatetime) |
|
1974 | 1974 | |
|
1975 | 1975 | |
|
1976 | 1976 | class NSMeteorDetection2Plot(Figure): |
|
1977 | 1977 | |
|
1978 | 1978 | isConfig = None |
|
1979 | 1979 | __nsubplots = None |
|
1980 | 1980 | |
|
1981 | 1981 | WIDTHPROF = None |
|
1982 | 1982 | HEIGHTPROF = None |
|
1983 | 1983 | PREFIX = 'nsm' |
|
1984 | 1984 | |
|
1985 | 1985 | zminList = None |
|
1986 | 1986 | zmaxList = None |
|
1987 | 1987 | cmapList = None |
|
1988 | 1988 | titleList = None |
|
1989 | 1989 | nPairs = None |
|
1990 | 1990 | nChannels = None |
|
1991 | 1991 | nParam = None |
|
1992 | 1992 | |
|
1993 | 1993 | def __init__(self, **kwargs): |
|
1994 | 1994 | Figure.__init__(self, **kwargs) |
|
1995 | 1995 | self.isConfig = False |
|
1996 | 1996 | self.__nsubplots = 1 |
|
1997 | 1997 | |
|
1998 | 1998 | self.WIDTH = 750 |
|
1999 | 1999 | self.HEIGHT = 250 |
|
2000 | 2000 | self.WIDTHPROF = 120 |
|
2001 | 2001 | self.HEIGHTPROF = 0 |
|
2002 | 2002 | self.counter_imagwr = 0 |
|
2003 | 2003 | |
|
2004 | 2004 | self.PLOT_CODE = SPEC_CODE |
|
2005 | 2005 | |
|
2006 | 2006 | self.FTP_WEI = None |
|
2007 | 2007 | self.EXP_CODE = None |
|
2008 | 2008 | self.SUB_EXP_CODE = None |
|
2009 | 2009 | self.PLOT_POS = None |
|
2010 | 2010 | |
|
2011 | 2011 | self.__xfilter_ena = False |
|
2012 | 2012 | self.__yfilter_ena = False |
|
2013 | 2013 | |
|
2014 | 2014 | def getSubplots(self): |
|
2015 | 2015 | |
|
2016 | 2016 | ncol = 3 |
|
2017 | 2017 | nrow = int(numpy.ceil(self.nplots/3.0)) |
|
2018 | 2018 | |
|
2019 | 2019 | return nrow, ncol |
|
2020 | 2020 | |
|
2021 | 2021 | def setup(self, id, nplots, wintitle, show=True): |
|
2022 | 2022 | |
|
2023 | 2023 | self.nplots = nplots |
|
2024 | 2024 | |
|
2025 | 2025 | ncolspan = 1 |
|
2026 | 2026 | colspan = 1 |
|
2027 | 2027 | |
|
2028 | 2028 | self.createFigure(id = id, |
|
2029 | 2029 | wintitle = wintitle, |
|
2030 | 2030 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
2031 | 2031 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
2032 | 2032 | show=show) |
|
2033 | 2033 | |
|
2034 | 2034 | nrow, ncol = self.getSubplots() |
|
2035 | 2035 | |
|
2036 | 2036 | counter = 0 |
|
2037 | 2037 | for y in range(nrow): |
|
2038 | 2038 | for x in range(ncol): |
|
2039 | 2039 | |
|
2040 | 2040 | if counter >= self.nplots: |
|
2041 | 2041 | break |
|
2042 | 2042 | |
|
2043 | 2043 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
2044 | 2044 | |
|
2045 | 2045 | counter += 1 |
|
2046 | 2046 | |
|
2047 | 2047 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
2048 | 2048 | xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None, |
|
2049 | 2049 | vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA', |
|
2050 | 2050 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
2051 | 2051 | server=None, folder=None, username=None, password=None, |
|
2052 | 2052 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
2053 | 2053 | xaxis="frequency"): |
|
2054 | 2054 | |
|
2055 | 2055 | """ |
|
2056 | 2056 | |
|
2057 | 2057 | Input: |
|
2058 | 2058 | dataOut : |
|
2059 | 2059 | id : |
|
2060 | 2060 | wintitle : |
|
2061 | 2061 | channelList : |
|
2062 | 2062 | showProfile : |
|
2063 | 2063 | xmin : None, |
|
2064 | 2064 | xmax : None, |
|
2065 | 2065 | ymin : None, |
|
2066 | 2066 | ymax : None, |
|
2067 | 2067 | zmin : None, |
|
2068 | 2068 | zmax : None |
|
2069 | 2069 | """ |
|
2070 | 2070 | #Rebuild matrix |
|
2071 | 2071 | utctime = dataOut.data_param[0,0] |
|
2072 | 2072 | cmet = dataOut.data_param[:,1].astype(int) |
|
2073 | 2073 | tmet = dataOut.data_param[:,2].astype(int) |
|
2074 | 2074 | hmet = dataOut.data_param[:,3].astype(int) |
|
2075 | 2075 | |
|
2076 | 2076 | nParam = 3 |
|
2077 | 2077 | nChan = len(dataOut.groupList) |
|
2078 | 2078 | x = dataOut.abscissaList |
|
2079 | 2079 | y = dataOut.heightList |
|
2080 | 2080 | |
|
2081 | 2081 | z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan) |
|
2082 | 2082 | z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:] |
|
2083 | 2083 | z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale |
|
2084 | 2084 | z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1)) |
|
2085 | 2085 | |
|
2086 | 2086 | xlabel = "Time (s)" |
|
2087 | 2087 | ylabel = "Range (km)" |
|
2088 | 2088 | |
|
2089 | 2089 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
2090 | 2090 | |
|
2091 | 2091 | if not self.isConfig: |
|
2092 | 2092 | |
|
2093 | 2093 | nplots = nParam*nChan |
|
2094 | 2094 | |
|
2095 | 2095 | self.setup(id=id, |
|
2096 | 2096 | nplots=nplots, |
|
2097 | 2097 | wintitle=wintitle, |
|
2098 | 2098 | show=show) |
|
2099 | 2099 | |
|
2100 | 2100 | if xmin is None: xmin = numpy.nanmin(x) |
|
2101 | 2101 | if xmax is None: xmax = numpy.nanmax(x) |
|
2102 | 2102 | if ymin is None: ymin = numpy.nanmin(y) |
|
2103 | 2103 | if ymax is None: ymax = numpy.nanmax(y) |
|
2104 | 2104 | if SNRmin is None: SNRmin = numpy.nanmin(z[0,:]) |
|
2105 | 2105 | if SNRmax is None: SNRmax = numpy.nanmax(z[0,:]) |
|
2106 | 2106 | if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:])) |
|
2107 | 2107 | if vmin is None: vmin = -vmax |
|
2108 | 2108 | if wmin is None: wmin = 0 |
|
2109 | 2109 | if wmax is None: wmax = 50 |
|
2110 | 2110 | |
|
2111 | 2111 | self.nChannels = nChan |
|
2112 | 2112 | |
|
2113 | 2113 | zminList = [] |
|
2114 | 2114 | zmaxList = [] |
|
2115 | 2115 | titleList = [] |
|
2116 | 2116 | cmapList = [] |
|
2117 | 2117 | for i in range(self.nChannels): |
|
2118 | 2118 | strAux1 = "SNR Channel "+ str(i) |
|
2119 | 2119 | strAux2 = "Radial Velocity Channel "+ str(i) |
|
2120 | 2120 | strAux3 = "Spectral Width Channel "+ str(i) |
|
2121 | 2121 | |
|
2122 | 2122 | titleList = titleList + [strAux1,strAux2,strAux3] |
|
2123 | 2123 | cmapList = cmapList + ["jet","RdBu_r","jet"] |
|
2124 | 2124 | zminList = zminList + [SNRmin,vmin,wmin] |
|
2125 | 2125 | zmaxList = zmaxList + [SNRmax,vmax,wmax] |
|
2126 | 2126 | |
|
2127 | 2127 | self.zminList = zminList |
|
2128 | 2128 | self.zmaxList = zmaxList |
|
2129 | 2129 | self.cmapList = cmapList |
|
2130 | 2130 | self.titleList = titleList |
|
2131 | 2131 | |
|
2132 | 2132 | self.FTP_WEI = ftp_wei |
|
2133 | 2133 | self.EXP_CODE = exp_code |
|
2134 | 2134 | self.SUB_EXP_CODE = sub_exp_code |
|
2135 | 2135 | self.PLOT_POS = plot_pos |
|
2136 | 2136 | |
|
2137 | 2137 | self.isConfig = True |
|
2138 | 2138 | |
|
2139 | 2139 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
2140 | 2140 | |
|
2141 | 2141 | for i in range(self.nplots): |
|
2142 | 2142 | title = self.titleList[i] + ": " +str_datetime |
|
2143 | 2143 | axes = self.axesList[i] |
|
2144 | 2144 | axes.pcolor(x, y, z[i,:].T, |
|
2145 | 2145 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i], |
|
2146 | 2146 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='') |
|
2147 | 2147 | self.draw() |
|
2148 | 2148 | |
|
2149 | 2149 | if figfile == None: |
|
2150 | 2150 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
2151 | 2151 | name = str_datetime |
|
2152 | 2152 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
2153 | 2153 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
2154 | 2154 | figfile = self.getFilename(name) |
|
2155 | 2155 | |
|
2156 | 2156 | self.save(figpath=figpath, |
|
2157 | 2157 | figfile=figfile, |
|
2158 | 2158 | save=save, |
|
2159 | 2159 | ftp=ftp, |
|
2160 | 2160 | wr_period=wr_period, |
|
2161 | 2161 | thisDatetime=thisDatetime) |
@@ -1,1605 +1,1605 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 9, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | |
|
10 | 10 | import matplotlib.pyplot as plt |
|
11 | 11 | |
|
12 | 12 | from figure import Figure, isRealtime, isTimeInHourRange |
|
13 | 13 | from plotting_codes import * |
|
14 | 14 | from matplotlib.pyplot import savefig |
|
15 | 15 | |
|
16 | 16 | class SpectraPlot(Figure): |
|
17 | 17 | |
|
18 | 18 | isConfig = None |
|
19 | 19 | __nsubplots = None |
|
20 | 20 | |
|
21 | 21 | WIDTHPROF = None |
|
22 | 22 | HEIGHTPROF = None |
|
23 | 23 | PREFIX = 'spc' |
|
24 | 24 | |
|
25 | 25 | def __init__(self, **kwargs): |
|
26 | 26 | Figure.__init__(self, **kwargs) |
|
27 | 27 | self.isConfig = False |
|
28 | 28 | self.__nsubplots = 1 |
|
29 | 29 | |
|
30 | 30 | self.WIDTH = 300 |
|
31 | 31 | self.HEIGHT = 300 |
|
32 | 32 | self.WIDTHPROF = 120 |
|
33 | 33 | self.HEIGHTPROF = 0 |
|
34 | 34 | self.counter_imagwr = 0 |
|
35 | 35 | |
|
36 | 36 | self.PLOT_CODE = SPEC_CODE |
|
37 | 37 | |
|
38 | 38 | self.FTP_WEI = None |
|
39 | 39 | self.EXP_CODE = None |
|
40 | 40 | self.SUB_EXP_CODE = None |
|
41 | 41 | self.PLOT_POS = None |
|
42 | 42 | |
|
43 | 43 | self.__xfilter_ena = False |
|
44 | 44 | self.__yfilter_ena = False |
|
45 | 45 | |
|
46 | 46 | self.indice=1 |
|
47 | 47 | |
|
48 | 48 | def getSubplots(self): |
|
49 | 49 | |
|
50 | 50 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
51 | 51 | nrow = int(self.nplots*1./ncol + 0.9) |
|
52 | 52 | |
|
53 | 53 | return nrow, ncol |
|
54 | 54 | |
|
55 | 55 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
56 | 56 | |
|
57 | 57 | self.__showprofile = showprofile |
|
58 | 58 | self.nplots = nplots |
|
59 | 59 | |
|
60 | 60 | ncolspan = 1 |
|
61 | 61 | colspan = 1 |
|
62 | 62 | if showprofile: |
|
63 | 63 | ncolspan = 3 |
|
64 | 64 | colspan = 2 |
|
65 | 65 | self.__nsubplots = 2 |
|
66 | 66 | |
|
67 | 67 | self.createFigure(id = id, |
|
68 | 68 | wintitle = wintitle, |
|
69 | 69 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
70 | 70 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
71 | 71 | show=show) |
|
72 | 72 | |
|
73 | 73 | nrow, ncol = self.getSubplots() |
|
74 | 74 | |
|
75 | 75 | counter = 0 |
|
76 | 76 | for y in range(nrow): |
|
77 | 77 | for x in range(ncol): |
|
78 | 78 | |
|
79 | 79 | if counter >= self.nplots: |
|
80 | 80 | break |
|
81 | 81 | |
|
82 | 82 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
83 | 83 | |
|
84 | 84 | if showprofile: |
|
85 | 85 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
86 | 86 | |
|
87 | 87 | counter += 1 |
|
88 | 88 | |
|
89 | 89 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
90 | 90 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
91 | 91 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
92 | 92 | server=None, folder=None, username=None, password=None, |
|
93 | 93 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
94 | 94 | xaxis="frequency", colormap='jet', normFactor=None): |
|
95 | 95 | |
|
96 | 96 | """ |
|
97 | 97 | |
|
98 | 98 | Input: |
|
99 | 99 | dataOut : |
|
100 | 100 | id : |
|
101 | 101 | wintitle : |
|
102 | 102 | channelList : |
|
103 | 103 | showProfile : |
|
104 | 104 | xmin : None, |
|
105 | 105 | xmax : None, |
|
106 | 106 | ymin : None, |
|
107 | 107 | ymax : None, |
|
108 | 108 | zmin : None, |
|
109 | 109 | zmax : None |
|
110 | 110 | """ |
|
111 | 111 | if realtime: |
|
112 | 112 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
113 | 113 | print 'Skipping this plot function' |
|
114 | 114 | return |
|
115 | 115 | |
|
116 | 116 | if channelList == None: |
|
117 | 117 | channelIndexList = dataOut.channelIndexList |
|
118 | 118 | else: |
|
119 | 119 | channelIndexList = [] |
|
120 | 120 | for channel in channelList: |
|
121 | 121 | if channel not in dataOut.channelList: |
|
122 | 122 | raise ValueError, "Channel %d is not in dataOut.channelList" %channel |
|
123 | 123 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
124 | 124 | |
|
125 | 125 | if normFactor is None: |
|
126 | 126 | factor = dataOut.normFactor |
|
127 | 127 | else: |
|
128 | 128 | factor = normFactor |
|
129 | 129 | if xaxis == "frequency": |
|
130 | 130 | x = dataOut.getFreqRange(1)/1000. |
|
131 | 131 | xlabel = "Frequency (kHz)" |
|
132 | 132 | |
|
133 | 133 | elif xaxis == "time": |
|
134 | 134 | x = dataOut.getAcfRange(1) |
|
135 | 135 | xlabel = "Time (ms)" |
|
136 | 136 | |
|
137 | 137 | else: |
|
138 | 138 | x = dataOut.getVelRange(1) |
|
139 | 139 | xlabel = "Velocity (m/s)" |
|
140 | 140 | |
|
141 |
ylabel = "Range ( |
|
|
141 | ylabel = "Range (km)" | |
|
142 | 142 | |
|
143 | 143 | y = dataOut.getHeiRange() |
|
144 | 144 | print 'dataOut.normFactor', dataOut.normFactor |
|
145 | 145 | z = dataOut.data_spc/factor |
|
146 | 146 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
147 | 147 | zdB = 10*numpy.log10(z) |
|
148 | 148 | |
|
149 | 149 | avg = numpy.average(z, axis=1) |
|
150 | 150 | avgdB = 10*numpy.log10(avg) |
|
151 | 151 | |
|
152 | 152 | noise = dataOut.getNoise()/factor |
|
153 | 153 | noisedB = 10*numpy.log10(noise) |
|
154 | 154 | |
|
155 | 155 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
156 | 156 | title = wintitle + " Spectra" |
|
157 | 157 | |
|
158 | 158 | |
|
159 | 159 | |
|
160 | 160 | print 'len de X',len(x), numpy.shape(x), 'len de spc line',len(dataOut.data_spc[1,:,15]), numpy.shape(dataOut.data_spc) |
|
161 | 161 | print 'Altura:', y[0], y[1], y[13], y[14], y[10] |
|
162 | 162 | #a=z[1,:,15] |
|
163 | 163 | |
|
164 | 164 | # fig = plt.figure(10+self.indice) |
|
165 | 165 | # plt.plot( x[0:128], zdB[0,:,10] ) |
|
166 | 166 | # plt.axis([-12, 12, 15, 50]) |
|
167 | 167 | # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) ) |
|
168 | 168 | # plt.ylabel('Intensidad [dB]') |
|
169 | 169 | # plt.xlabel('Velocidad [m/s]') |
|
170 | 170 | # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice)) |
|
171 | 171 | # |
|
172 | 172 | # plt.show() |
|
173 | 173 | # |
|
174 | 174 | # self.indice=self.indice+1 |
|
175 | 175 | |
|
176 | 176 | |
|
177 | 177 | |
|
178 | 178 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
179 | 179 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
180 | 180 | |
|
181 | 181 | if not self.isConfig: |
|
182 | 182 | |
|
183 | 183 | nplots = len(channelIndexList) |
|
184 | 184 | |
|
185 | 185 | self.setup(id=id, |
|
186 | 186 | nplots=nplots, |
|
187 | 187 | wintitle=wintitle, |
|
188 | 188 | showprofile=showprofile, |
|
189 | 189 | show=show) |
|
190 | 190 | |
|
191 | 191 | if xmin == None: xmin = numpy.nanmin(x) |
|
192 | 192 | if xmax == None: xmax = numpy.nanmax(x) |
|
193 | 193 | if ymin == None: ymin = numpy.nanmin(y) |
|
194 | 194 | if ymax == None: ymax = numpy.nanmax(y) |
|
195 | 195 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
196 | 196 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
197 | 197 | |
|
198 | 198 | self.FTP_WEI = ftp_wei |
|
199 | 199 | self.EXP_CODE = exp_code |
|
200 | 200 | self.SUB_EXP_CODE = sub_exp_code |
|
201 | 201 | self.PLOT_POS = plot_pos |
|
202 | 202 | |
|
203 | 203 | self.isConfig = True |
|
204 | 204 | |
|
205 | 205 | self.setWinTitle(title) |
|
206 | 206 | |
|
207 | 207 | for i in range(self.nplots): |
|
208 | 208 | index = channelIndexList[i] |
|
209 | 209 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
210 | 210 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
211 | 211 | if len(dataOut.beam.codeList) != 0: |
|
212 | 212 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) |
|
213 | 213 | |
|
214 | 214 | axes = self.axesList[i*self.__nsubplots] |
|
215 | 215 | axes.pcolor(x, y, zdB[index,:,:], |
|
216 | 216 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
217 | 217 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, |
|
218 | 218 | ticksize=9, cblabel='') |
|
219 | 219 | |
|
220 | 220 | if self.__showprofile: |
|
221 | 221 | axes = self.axesList[i*self.__nsubplots +1] |
|
222 | 222 | axes.pline(avgdB[index,:], y, |
|
223 | 223 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
224 | 224 | xlabel='dB', ylabel='', title='', |
|
225 | 225 | ytick_visible=False, |
|
226 | 226 | grid='x') |
|
227 | 227 | |
|
228 | 228 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
229 | 229 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
230 | 230 | |
|
231 | 231 | self.draw() |
|
232 | 232 | |
|
233 | 233 | if figfile == None: |
|
234 | 234 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
235 | 235 | name = str_datetime |
|
236 | 236 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
237 | 237 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
238 | 238 | figfile = self.getFilename(name) |
|
239 | 239 | |
|
240 | 240 | self.save(figpath=figpath, |
|
241 | 241 | figfile=figfile, |
|
242 | 242 | save=save, |
|
243 | 243 | ftp=ftp, |
|
244 | 244 | wr_period=wr_period, |
|
245 | 245 | thisDatetime=thisDatetime) |
|
246 | 246 | |
|
247 | 247 | |
|
248 | 248 | class CrossSpectraPlot(Figure): |
|
249 | 249 | |
|
250 | 250 | isConfig = None |
|
251 | 251 | __nsubplots = None |
|
252 | 252 | |
|
253 | 253 | WIDTH = None |
|
254 | 254 | HEIGHT = None |
|
255 | 255 | WIDTHPROF = None |
|
256 | 256 | HEIGHTPROF = None |
|
257 | 257 | PREFIX = 'cspc' |
|
258 | 258 | |
|
259 | 259 | def __init__(self, **kwargs): |
|
260 | 260 | Figure.__init__(self, **kwargs) |
|
261 | 261 | self.isConfig = False |
|
262 | 262 | self.__nsubplots = 4 |
|
263 | 263 | self.counter_imagwr = 0 |
|
264 | 264 | self.WIDTH = 250 |
|
265 | 265 | self.HEIGHT = 250 |
|
266 | 266 | self.WIDTHPROF = 0 |
|
267 | 267 | self.HEIGHTPROF = 0 |
|
268 | 268 | |
|
269 | 269 | self.PLOT_CODE = CROSS_CODE |
|
270 | 270 | self.FTP_WEI = None |
|
271 | 271 | self.EXP_CODE = None |
|
272 | 272 | self.SUB_EXP_CODE = None |
|
273 | 273 | self.PLOT_POS = None |
|
274 | 274 | |
|
275 | 275 | self.indice=0 |
|
276 | 276 | |
|
277 | 277 | def getSubplots(self): |
|
278 | 278 | |
|
279 | 279 | ncol = 4 |
|
280 | 280 | nrow = self.nplots |
|
281 | 281 | |
|
282 | 282 | return nrow, ncol |
|
283 | 283 | |
|
284 | 284 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
285 | 285 | |
|
286 | 286 | self.__showprofile = showprofile |
|
287 | 287 | self.nplots = nplots |
|
288 | 288 | |
|
289 | 289 | ncolspan = 1 |
|
290 | 290 | colspan = 1 |
|
291 | 291 | |
|
292 | 292 | self.createFigure(id = id, |
|
293 | 293 | wintitle = wintitle, |
|
294 | 294 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
295 | 295 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
296 | 296 | show=True) |
|
297 | 297 | |
|
298 | 298 | nrow, ncol = self.getSubplots() |
|
299 | 299 | |
|
300 | 300 | counter = 0 |
|
301 | 301 | for y in range(nrow): |
|
302 | 302 | for x in range(ncol): |
|
303 | 303 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
304 | 304 | |
|
305 | 305 | counter += 1 |
|
306 | 306 | |
|
307 | 307 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
308 | 308 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
309 | 309 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, |
|
310 | 310 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
311 | 311 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
312 | 312 | server=None, folder=None, username=None, password=None, |
|
313 | 313 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, |
|
314 | 314 | xaxis='frequency'): |
|
315 | 315 | |
|
316 | 316 | """ |
|
317 | 317 | |
|
318 | 318 | Input: |
|
319 | 319 | dataOut : |
|
320 | 320 | id : |
|
321 | 321 | wintitle : |
|
322 | 322 | channelList : |
|
323 | 323 | showProfile : |
|
324 | 324 | xmin : None, |
|
325 | 325 | xmax : None, |
|
326 | 326 | ymin : None, |
|
327 | 327 | ymax : None, |
|
328 | 328 | zmin : None, |
|
329 | 329 | zmax : None |
|
330 | 330 | """ |
|
331 | 331 | |
|
332 | 332 | if pairsList == None: |
|
333 | 333 | pairsIndexList = dataOut.pairsIndexList |
|
334 | 334 | else: |
|
335 | 335 | pairsIndexList = [] |
|
336 | 336 | for pair in pairsList: |
|
337 | 337 | if pair not in dataOut.pairsList: |
|
338 | 338 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) |
|
339 | 339 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
340 | 340 | |
|
341 | 341 | if not pairsIndexList: |
|
342 | 342 | return |
|
343 | 343 | |
|
344 | 344 | if len(pairsIndexList) > 4: |
|
345 | 345 | pairsIndexList = pairsIndexList[0:4] |
|
346 | 346 | |
|
347 | 347 | if normFactor is None: |
|
348 | 348 | factor = dataOut.normFactor |
|
349 | 349 | else: |
|
350 | 350 | factor = normFactor |
|
351 | 351 | x = dataOut.getVelRange(1) |
|
352 | 352 | y = dataOut.getHeiRange() |
|
353 | 353 | z = dataOut.data_spc[:,:,:]/factor |
|
354 | 354 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
355 | 355 | |
|
356 | 356 | noise = dataOut.noise/factor |
|
357 | 357 | |
|
358 | 358 | zdB = 10*numpy.log10(z) |
|
359 | 359 | noisedB = 10*numpy.log10(noise) |
|
360 | 360 | |
|
361 | 361 | if coh_min == None: |
|
362 | 362 | coh_min = 0.0 |
|
363 | 363 | if coh_max == None: |
|
364 | 364 | coh_max = 1.0 |
|
365 | 365 | |
|
366 | 366 | if phase_min == None: |
|
367 | 367 | phase_min = -180 |
|
368 | 368 | if phase_max == None: |
|
369 | 369 | phase_max = 180 |
|
370 | 370 | |
|
371 | 371 | #thisDatetime = dataOut.datatime |
|
372 | 372 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
373 | 373 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
374 | 374 | # xlabel = "Velocity (m/s)" |
|
375 | 375 | ylabel = "Range (Km)" |
|
376 | 376 | |
|
377 | 377 | if xaxis == "frequency": |
|
378 | 378 | x = dataOut.getFreqRange(1)/1000. |
|
379 | 379 | xlabel = "Frequency (kHz)" |
|
380 | 380 | |
|
381 | 381 | elif xaxis == "time": |
|
382 | 382 | x = dataOut.getAcfRange(1) |
|
383 | 383 | xlabel = "Time (ms)" |
|
384 | 384 | |
|
385 | 385 | else: |
|
386 | 386 | x = dataOut.getVelRange(1) |
|
387 | 387 | xlabel = "Velocity (m/s)" |
|
388 | 388 | |
|
389 | 389 | if not self.isConfig: |
|
390 | 390 | |
|
391 | 391 | nplots = len(pairsIndexList) |
|
392 | 392 | |
|
393 | 393 | self.setup(id=id, |
|
394 | 394 | nplots=nplots, |
|
395 | 395 | wintitle=wintitle, |
|
396 | 396 | showprofile=False, |
|
397 | 397 | show=show) |
|
398 | 398 | |
|
399 | 399 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
400 | 400 | avgdB = 10*numpy.log10(avg) |
|
401 | 401 | |
|
402 | 402 | if xmin == None: xmin = numpy.nanmin(x) |
|
403 | 403 | if xmax == None: xmax = numpy.nanmax(x) |
|
404 | 404 | if ymin == None: ymin = numpy.nanmin(y) |
|
405 | 405 | if ymax == None: ymax = numpy.nanmax(y) |
|
406 | 406 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
407 | 407 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
408 | 408 | |
|
409 | 409 | self.FTP_WEI = ftp_wei |
|
410 | 410 | self.EXP_CODE = exp_code |
|
411 | 411 | self.SUB_EXP_CODE = sub_exp_code |
|
412 | 412 | self.PLOT_POS = plot_pos |
|
413 | 413 | |
|
414 | 414 | self.isConfig = True |
|
415 | 415 | |
|
416 | 416 | self.setWinTitle(title) |
|
417 | 417 | |
|
418 | 418 | |
|
419 | 419 | for i in range(self.nplots): |
|
420 | 420 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
421 | 421 | |
|
422 | 422 | chan_index0 = dataOut.channelList.index(pair[0]) |
|
423 | 423 | chan_index1 = dataOut.channelList.index(pair[1]) |
|
424 | 424 | |
|
425 | 425 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
426 | 426 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) |
|
427 | 427 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) |
|
428 | 428 | axes0 = self.axesList[i*self.__nsubplots] |
|
429 | 429 | axes0.pcolor(x, y, zdB, |
|
430 | 430 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
431 | 431 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
432 | 432 | ticksize=9, colormap=power_cmap, cblabel='') |
|
433 | 433 | |
|
434 | 434 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) |
|
435 | 435 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) |
|
436 | 436 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
437 | 437 | axes0.pcolor(x, y, zdB, |
|
438 | 438 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
439 | 439 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
440 | 440 | ticksize=9, colormap=power_cmap, cblabel='') |
|
441 | 441 | |
|
442 | 442 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] ) |
|
443 | 443 | coherence = numpy.abs(coherenceComplex) |
|
444 | 444 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
445 | 445 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
446 | 446 | |
|
447 | 447 | |
|
448 | 448 | |
|
449 | 449 | |
|
450 | 450 | # #print 'FASE', numpy.shape(phase), y[25] |
|
451 | 451 | # fig = plt.figure(10+self.indice) |
|
452 | 452 | # #plt.plot( x[0:256],coherence[:,25] ) |
|
453 | 453 | # cohAv = numpy.average(coherence,1) |
|
454 | 454 | # |
|
455 | 455 | # plt.plot( x[0:256],cohAv ) |
|
456 | 456 | # #plt.axis([-12, 12, 15, 50]) |
|
457 | 457 | # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i))) |
|
458 | 458 | # plt.ylabel('Desfase [grados]') |
|
459 | 459 | # plt.xlabel('Velocidad [m/s]') |
|
460 | 460 | # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice)) |
|
461 | 461 | # |
|
462 | 462 | # plt.show() |
|
463 | 463 | # self.indice=self.indice+1 |
|
464 | 464 | |
|
465 | 465 | |
|
466 | 466 | # print 'FASE', numpy.shape(phase), y[25] |
|
467 | 467 | # fig = plt.figure(10+self.indice) |
|
468 | 468 | # plt.plot( x[0:256],phase[:,25] ) |
|
469 | 469 | # #plt.axis([-12, 12, 15, 50]) |
|
470 | 470 | # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i))) |
|
471 | 471 | # plt.ylabel('Desfase [grados]') |
|
472 | 472 | # plt.xlabel('Velocidad [m/s]') |
|
473 | 473 | # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice)) |
|
474 | 474 | # |
|
475 | 475 | # plt.show() |
|
476 | 476 | # self.indice=self.indice+1 |
|
477 | 477 | |
|
478 | 478 | |
|
479 | 479 | |
|
480 | 480 | |
|
481 | 481 | title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) |
|
482 | 482 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
483 | 483 | axes0.pcolor(x, y, coherence, |
|
484 | 484 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, |
|
485 | 485 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
486 | 486 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
487 | 487 | |
|
488 | 488 | title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) |
|
489 | 489 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
490 | 490 | axes0.pcolor(x, y, phase, |
|
491 | 491 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
492 | 492 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
493 | 493 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
494 | 494 | |
|
495 | 495 | |
|
496 | 496 | |
|
497 | 497 | self.draw() |
|
498 | 498 | |
|
499 | 499 | self.save(figpath=figpath, |
|
500 | 500 | figfile=figfile, |
|
501 | 501 | save=save, |
|
502 | 502 | ftp=ftp, |
|
503 | 503 | wr_period=wr_period, |
|
504 | 504 | thisDatetime=thisDatetime) |
|
505 | 505 | |
|
506 | 506 | |
|
507 | 507 | class RTIPlot(Figure): |
|
508 | 508 | |
|
509 | 509 | __isConfig = None |
|
510 | 510 | __nsubplots = None |
|
511 | 511 | |
|
512 | 512 | WIDTHPROF = None |
|
513 | 513 | HEIGHTPROF = None |
|
514 | 514 | PREFIX = 'rti' |
|
515 | 515 | |
|
516 | 516 | def __init__(self, **kwargs): |
|
517 | 517 | |
|
518 | 518 | Figure.__init__(self, **kwargs) |
|
519 | 519 | self.timerange = None |
|
520 | 520 | self.isConfig = False |
|
521 | 521 | self.__nsubplots = 1 |
|
522 | 522 | |
|
523 | 523 | self.WIDTH = 800 |
|
524 | 524 | self.HEIGHT = 250 |
|
525 | 525 | self.WIDTHPROF = 120 |
|
526 | 526 | self.HEIGHTPROF = 0 |
|
527 | 527 | self.counter_imagwr = 0 |
|
528 | 528 | |
|
529 | 529 | self.PLOT_CODE = RTI_CODE |
|
530 | 530 | |
|
531 | 531 | self.FTP_WEI = None |
|
532 | 532 | self.EXP_CODE = None |
|
533 | 533 | self.SUB_EXP_CODE = None |
|
534 | 534 | self.PLOT_POS = None |
|
535 | 535 | self.tmin = None |
|
536 | 536 | self.tmax = None |
|
537 | 537 | |
|
538 | 538 | self.xmin = None |
|
539 | 539 | self.xmax = None |
|
540 | 540 | |
|
541 | 541 | self.figfile = None |
|
542 | 542 | |
|
543 | 543 | def getSubplots(self): |
|
544 | 544 | |
|
545 | 545 | ncol = 1 |
|
546 | 546 | nrow = self.nplots |
|
547 | 547 | |
|
548 | 548 | return nrow, ncol |
|
549 | 549 | |
|
550 | 550 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
551 | 551 | |
|
552 | 552 | self.__showprofile = showprofile |
|
553 | 553 | self.nplots = nplots |
|
554 | 554 | |
|
555 | 555 | ncolspan = 1 |
|
556 | 556 | colspan = 1 |
|
557 | 557 | if showprofile: |
|
558 | 558 | ncolspan = 7 |
|
559 | 559 | colspan = 6 |
|
560 | 560 | self.__nsubplots = 2 |
|
561 | 561 | |
|
562 | 562 | self.createFigure(id = id, |
|
563 | 563 | wintitle = wintitle, |
|
564 | 564 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
565 | 565 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
566 | 566 | show=show) |
|
567 | 567 | |
|
568 | 568 | nrow, ncol = self.getSubplots() |
|
569 | 569 | |
|
570 | 570 | counter = 0 |
|
571 | 571 | for y in range(nrow): |
|
572 | 572 | for x in range(ncol): |
|
573 | 573 | |
|
574 | 574 | if counter >= self.nplots: |
|
575 | 575 | break |
|
576 | 576 | |
|
577 | 577 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
578 | 578 | |
|
579 | 579 | if showprofile: |
|
580 | 580 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
581 | 581 | |
|
582 | 582 | counter += 1 |
|
583 | 583 | |
|
584 | 584 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
585 | 585 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
586 | 586 | timerange=None, colormap='jet', |
|
587 | 587 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
588 | 588 | server=None, folder=None, username=None, password=None, |
|
589 | 589 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None): |
|
590 | 590 | |
|
591 | 591 | """ |
|
592 | 592 | |
|
593 | 593 | Input: |
|
594 | 594 | dataOut : |
|
595 | 595 | id : |
|
596 | 596 | wintitle : |
|
597 | 597 | channelList : |
|
598 | 598 | showProfile : |
|
599 | 599 | xmin : None, |
|
600 | 600 | xmax : None, |
|
601 | 601 | ymin : None, |
|
602 | 602 | ymax : None, |
|
603 | 603 | zmin : None, |
|
604 | 604 | zmax : None |
|
605 | 605 | """ |
|
606 | 606 | |
|
607 | 607 | #colormap = kwargs.get('colormap', 'jet') |
|
608 | 608 | if HEIGHT is not None: |
|
609 | 609 | self.HEIGHT = HEIGHT |
|
610 | 610 | |
|
611 | 611 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
612 | 612 | return |
|
613 | 613 | |
|
614 | 614 | if channelList == None: |
|
615 | 615 | channelIndexList = dataOut.channelIndexList |
|
616 | 616 | else: |
|
617 | 617 | channelIndexList = [] |
|
618 | 618 | for channel in channelList: |
|
619 | 619 | if channel not in dataOut.channelList: |
|
620 | 620 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
621 | 621 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
622 | 622 | |
|
623 | 623 | if normFactor is None: |
|
624 | 624 | factor = dataOut.normFactor |
|
625 | 625 | else: |
|
626 | 626 | factor = normFactor |
|
627 | 627 | |
|
628 | 628 | # factor = dataOut.normFactor |
|
629 | 629 | x = dataOut.getTimeRange() |
|
630 | 630 | y = dataOut.getHeiRange() |
|
631 | 631 | |
|
632 | 632 | z = dataOut.data_spc/factor |
|
633 | 633 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
634 | 634 | avg = numpy.average(z, axis=1) |
|
635 | 635 | avgdB = 10.*numpy.log10(avg) |
|
636 | 636 | # avgdB = dataOut.getPower() |
|
637 | 637 | |
|
638 | 638 | |
|
639 | 639 | thisDatetime = dataOut.datatime |
|
640 | 640 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
641 | 641 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
642 | 642 | xlabel = "" |
|
643 | 643 | ylabel = "Range (Km)" |
|
644 | 644 | |
|
645 | 645 | update_figfile = False |
|
646 | 646 | |
|
647 | 647 | if dataOut.ltctime >= self.xmax: |
|
648 | 648 | self.counter_imagwr = wr_period |
|
649 | 649 | self.isConfig = False |
|
650 | 650 | update_figfile = True |
|
651 | 651 | |
|
652 | 652 | if not self.isConfig: |
|
653 | 653 | |
|
654 | 654 | nplots = len(channelIndexList) |
|
655 | 655 | |
|
656 | 656 | self.setup(id=id, |
|
657 | 657 | nplots=nplots, |
|
658 | 658 | wintitle=wintitle, |
|
659 | 659 | showprofile=showprofile, |
|
660 | 660 | show=show) |
|
661 | 661 | |
|
662 | 662 | if timerange != None: |
|
663 | 663 | self.timerange = timerange |
|
664 | 664 | |
|
665 | 665 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
666 | 666 | |
|
667 | 667 | noise = dataOut.noise/factor |
|
668 | 668 | noisedB = 10*numpy.log10(noise) |
|
669 | 669 | |
|
670 | 670 | if ymin == None: ymin = numpy.nanmin(y) |
|
671 | 671 | if ymax == None: ymax = numpy.nanmax(y) |
|
672 | 672 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
673 | 673 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
674 | 674 | |
|
675 | 675 | self.FTP_WEI = ftp_wei |
|
676 | 676 | self.EXP_CODE = exp_code |
|
677 | 677 | self.SUB_EXP_CODE = sub_exp_code |
|
678 | 678 | self.PLOT_POS = plot_pos |
|
679 | 679 | |
|
680 | 680 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
681 | 681 | self.isConfig = True |
|
682 | 682 | self.figfile = figfile |
|
683 | 683 | update_figfile = True |
|
684 | 684 | |
|
685 | 685 | self.setWinTitle(title) |
|
686 | 686 | |
|
687 | 687 | for i in range(self.nplots): |
|
688 | 688 | index = channelIndexList[i] |
|
689 | 689 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
690 | 690 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
691 | 691 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
692 | 692 | axes = self.axesList[i*self.__nsubplots] |
|
693 | 693 | zdB = avgdB[index].reshape((1,-1)) |
|
694 | 694 | axes.pcolorbuffer(x, y, zdB, |
|
695 | 695 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
696 | 696 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
697 | 697 | ticksize=9, cblabel='', cbsize="1%", colormap=colormap) |
|
698 | 698 | |
|
699 | 699 | if self.__showprofile: |
|
700 | 700 | axes = self.axesList[i*self.__nsubplots +1] |
|
701 | 701 | axes.pline(avgdB[index], y, |
|
702 | 702 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
703 | 703 | xlabel='dB', ylabel='', title='', |
|
704 | 704 | ytick_visible=False, |
|
705 | 705 | grid='x') |
|
706 | 706 | |
|
707 | 707 | self.draw() |
|
708 | 708 | |
|
709 | 709 | self.save(figpath=figpath, |
|
710 | 710 | figfile=figfile, |
|
711 | 711 | save=save, |
|
712 | 712 | ftp=ftp, |
|
713 | 713 | wr_period=wr_period, |
|
714 | 714 | thisDatetime=thisDatetime, |
|
715 | 715 | update_figfile=update_figfile) |
|
716 | 716 | |
|
717 | 717 | class CoherenceMap(Figure): |
|
718 | 718 | isConfig = None |
|
719 | 719 | __nsubplots = None |
|
720 | 720 | |
|
721 | 721 | WIDTHPROF = None |
|
722 | 722 | HEIGHTPROF = None |
|
723 | 723 | PREFIX = 'cmap' |
|
724 | 724 | |
|
725 | 725 | def __init__(self, **kwargs): |
|
726 | 726 | Figure.__init__(self, **kwargs) |
|
727 | 727 | self.timerange = 2*60*60 |
|
728 | 728 | self.isConfig = False |
|
729 | 729 | self.__nsubplots = 1 |
|
730 | 730 | |
|
731 | 731 | self.WIDTH = 800 |
|
732 | 732 | self.HEIGHT = 180 |
|
733 | 733 | self.WIDTHPROF = 120 |
|
734 | 734 | self.HEIGHTPROF = 0 |
|
735 | 735 | self.counter_imagwr = 0 |
|
736 | 736 | |
|
737 | 737 | self.PLOT_CODE = COH_CODE |
|
738 | 738 | |
|
739 | 739 | self.FTP_WEI = None |
|
740 | 740 | self.EXP_CODE = None |
|
741 | 741 | self.SUB_EXP_CODE = None |
|
742 | 742 | self.PLOT_POS = None |
|
743 | 743 | self.counter_imagwr = 0 |
|
744 | 744 | |
|
745 | 745 | self.xmin = None |
|
746 | 746 | self.xmax = None |
|
747 | 747 | |
|
748 | 748 | def getSubplots(self): |
|
749 | 749 | ncol = 1 |
|
750 | 750 | nrow = self.nplots*2 |
|
751 | 751 | |
|
752 | 752 | return nrow, ncol |
|
753 | 753 | |
|
754 | 754 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
755 | 755 | self.__showprofile = showprofile |
|
756 | 756 | self.nplots = nplots |
|
757 | 757 | |
|
758 | 758 | ncolspan = 1 |
|
759 | 759 | colspan = 1 |
|
760 | 760 | if showprofile: |
|
761 | 761 | ncolspan = 7 |
|
762 | 762 | colspan = 6 |
|
763 | 763 | self.__nsubplots = 2 |
|
764 | 764 | |
|
765 | 765 | self.createFigure(id = id, |
|
766 | 766 | wintitle = wintitle, |
|
767 | 767 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
768 | 768 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
769 | 769 | show=True) |
|
770 | 770 | |
|
771 | 771 | nrow, ncol = self.getSubplots() |
|
772 | 772 | |
|
773 | 773 | for y in range(nrow): |
|
774 | 774 | for x in range(ncol): |
|
775 | 775 | |
|
776 | 776 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
777 | 777 | |
|
778 | 778 | if showprofile: |
|
779 | 779 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
780 | 780 | |
|
781 | 781 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
782 | 782 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
783 | 783 | timerange=None, phase_min=None, phase_max=None, |
|
784 | 784 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
785 | 785 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
786 | 786 | server=None, folder=None, username=None, password=None, |
|
787 | 787 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
788 | 788 | |
|
789 | 789 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
790 | 790 | return |
|
791 | 791 | |
|
792 | 792 | if pairsList == None: |
|
793 | 793 | pairsIndexList = dataOut.pairsIndexList |
|
794 | 794 | else: |
|
795 | 795 | pairsIndexList = [] |
|
796 | 796 | for pair in pairsList: |
|
797 | 797 | if pair not in dataOut.pairsList: |
|
798 | 798 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
799 | 799 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
800 | 800 | |
|
801 | 801 | if pairsIndexList == []: |
|
802 | 802 | return |
|
803 | 803 | |
|
804 | 804 | if len(pairsIndexList) > 4: |
|
805 | 805 | pairsIndexList = pairsIndexList[0:4] |
|
806 | 806 | |
|
807 | 807 | if phase_min == None: |
|
808 | 808 | phase_min = -180 |
|
809 | 809 | if phase_max == None: |
|
810 | 810 | phase_max = 180 |
|
811 | 811 | |
|
812 | 812 | x = dataOut.getTimeRange() |
|
813 | 813 | y = dataOut.getHeiRange() |
|
814 | 814 | |
|
815 | 815 | thisDatetime = dataOut.datatime |
|
816 | 816 | |
|
817 | 817 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
818 | 818 | xlabel = "" |
|
819 | 819 | ylabel = "Range (Km)" |
|
820 | 820 | update_figfile = False |
|
821 | 821 | |
|
822 | 822 | if not self.isConfig: |
|
823 | 823 | nplots = len(pairsIndexList) |
|
824 | 824 | self.setup(id=id, |
|
825 | 825 | nplots=nplots, |
|
826 | 826 | wintitle=wintitle, |
|
827 | 827 | showprofile=showprofile, |
|
828 | 828 | show=show) |
|
829 | 829 | |
|
830 | 830 | if timerange != None: |
|
831 | 831 | self.timerange = timerange |
|
832 | 832 | |
|
833 | 833 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
834 | 834 | |
|
835 | 835 | if ymin == None: ymin = numpy.nanmin(y) |
|
836 | 836 | if ymax == None: ymax = numpy.nanmax(y) |
|
837 | 837 | if zmin == None: zmin = 0. |
|
838 | 838 | if zmax == None: zmax = 1. |
|
839 | 839 | |
|
840 | 840 | self.FTP_WEI = ftp_wei |
|
841 | 841 | self.EXP_CODE = exp_code |
|
842 | 842 | self.SUB_EXP_CODE = sub_exp_code |
|
843 | 843 | self.PLOT_POS = plot_pos |
|
844 | 844 | |
|
845 | 845 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
846 | 846 | |
|
847 | 847 | self.isConfig = True |
|
848 | 848 | update_figfile = True |
|
849 | 849 | |
|
850 | 850 | self.setWinTitle(title) |
|
851 | 851 | |
|
852 | 852 | for i in range(self.nplots): |
|
853 | 853 | |
|
854 | 854 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
855 | 855 | |
|
856 | 856 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
857 | 857 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
858 | 858 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
859 | 859 | |
|
860 | 860 | |
|
861 | 861 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
862 | 862 | coherence = numpy.abs(avgcoherenceComplex) |
|
863 | 863 | |
|
864 | 864 | z = coherence.reshape((1,-1)) |
|
865 | 865 | |
|
866 | 866 | counter = 0 |
|
867 | 867 | |
|
868 | 868 | title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
869 | 869 | axes = self.axesList[i*self.__nsubplots*2] |
|
870 | 870 | axes.pcolorbuffer(x, y, z, |
|
871 | 871 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
872 | 872 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
873 | 873 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
874 | 874 | |
|
875 | 875 | if self.__showprofile: |
|
876 | 876 | counter += 1 |
|
877 | 877 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
878 | 878 | axes.pline(coherence, y, |
|
879 | 879 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
880 | 880 | xlabel='', ylabel='', title='', ticksize=7, |
|
881 | 881 | ytick_visible=False, nxticks=5, |
|
882 | 882 | grid='x') |
|
883 | 883 | |
|
884 | 884 | counter += 1 |
|
885 | 885 | |
|
886 | 886 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
887 | 887 | |
|
888 | 888 | z = phase.reshape((1,-1)) |
|
889 | 889 | |
|
890 | 890 | title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
891 | 891 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
892 | 892 | axes.pcolorbuffer(x, y, z, |
|
893 | 893 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
894 | 894 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
895 | 895 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
896 | 896 | |
|
897 | 897 | if self.__showprofile: |
|
898 | 898 | counter += 1 |
|
899 | 899 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
900 | 900 | axes.pline(phase, y, |
|
901 | 901 | xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax, |
|
902 | 902 | xlabel='', ylabel='', title='', ticksize=7, |
|
903 | 903 | ytick_visible=False, nxticks=4, |
|
904 | 904 | grid='x') |
|
905 | 905 | |
|
906 | 906 | self.draw() |
|
907 | 907 | |
|
908 | 908 | if dataOut.ltctime >= self.xmax: |
|
909 | 909 | self.counter_imagwr = wr_period |
|
910 | 910 | self.isConfig = False |
|
911 | 911 | update_figfile = True |
|
912 | 912 | |
|
913 | 913 | self.save(figpath=figpath, |
|
914 | 914 | figfile=figfile, |
|
915 | 915 | save=save, |
|
916 | 916 | ftp=ftp, |
|
917 | 917 | wr_period=wr_period, |
|
918 | 918 | thisDatetime=thisDatetime, |
|
919 | 919 | update_figfile=update_figfile) |
|
920 | 920 | |
|
921 | 921 | class PowerProfilePlot(Figure): |
|
922 | 922 | |
|
923 | 923 | isConfig = None |
|
924 | 924 | __nsubplots = None |
|
925 | 925 | |
|
926 | 926 | WIDTHPROF = None |
|
927 | 927 | HEIGHTPROF = None |
|
928 | 928 | PREFIX = 'spcprofile' |
|
929 | 929 | |
|
930 | 930 | def __init__(self, **kwargs): |
|
931 | 931 | Figure.__init__(self, **kwargs) |
|
932 | 932 | self.isConfig = False |
|
933 | 933 | self.__nsubplots = 1 |
|
934 | 934 | |
|
935 | 935 | self.PLOT_CODE = POWER_CODE |
|
936 | 936 | |
|
937 | 937 | self.WIDTH = 300 |
|
938 | 938 | self.HEIGHT = 500 |
|
939 | 939 | self.counter_imagwr = 0 |
|
940 | 940 | |
|
941 | 941 | def getSubplots(self): |
|
942 | 942 | ncol = 1 |
|
943 | 943 | nrow = 1 |
|
944 | 944 | |
|
945 | 945 | return nrow, ncol |
|
946 | 946 | |
|
947 | 947 | def setup(self, id, nplots, wintitle, show): |
|
948 | 948 | |
|
949 | 949 | self.nplots = nplots |
|
950 | 950 | |
|
951 | 951 | ncolspan = 1 |
|
952 | 952 | colspan = 1 |
|
953 | 953 | |
|
954 | 954 | self.createFigure(id = id, |
|
955 | 955 | wintitle = wintitle, |
|
956 | 956 | widthplot = self.WIDTH, |
|
957 | 957 | heightplot = self.HEIGHT, |
|
958 | 958 | show=show) |
|
959 | 959 | |
|
960 | 960 | nrow, ncol = self.getSubplots() |
|
961 | 961 | |
|
962 | 962 | counter = 0 |
|
963 | 963 | for y in range(nrow): |
|
964 | 964 | for x in range(ncol): |
|
965 | 965 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
966 | 966 | |
|
967 | 967 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
968 | 968 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
969 | 969 | save=False, figpath='./', figfile=None, show=True, |
|
970 | 970 | ftp=False, wr_period=1, server=None, |
|
971 | 971 | folder=None, username=None, password=None): |
|
972 | 972 | |
|
973 | 973 | |
|
974 | 974 | if channelList == None: |
|
975 | 975 | channelIndexList = dataOut.channelIndexList |
|
976 | 976 | channelList = dataOut.channelList |
|
977 | 977 | else: |
|
978 | 978 | channelIndexList = [] |
|
979 | 979 | for channel in channelList: |
|
980 | 980 | if channel not in dataOut.channelList: |
|
981 | 981 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
982 | 982 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
983 | 983 | |
|
984 | 984 | factor = dataOut.normFactor |
|
985 | 985 | |
|
986 | 986 | y = dataOut.getHeiRange() |
|
987 | 987 | |
|
988 | 988 | #for voltage |
|
989 | 989 | if dataOut.type == 'Voltage': |
|
990 | 990 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
991 | 991 | x = x.real |
|
992 | 992 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
993 | 993 | |
|
994 | 994 | #for spectra |
|
995 | 995 | if dataOut.type == 'Spectra': |
|
996 | 996 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
997 | 997 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
998 | 998 | x = numpy.average(x, axis=1) |
|
999 | 999 | |
|
1000 | 1000 | |
|
1001 | 1001 | xdB = 10*numpy.log10(x) |
|
1002 | 1002 | |
|
1003 | 1003 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1004 | 1004 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1005 | 1005 | xlabel = "dB" |
|
1006 | 1006 | ylabel = "Range (Km)" |
|
1007 | 1007 | |
|
1008 | 1008 | if not self.isConfig: |
|
1009 | 1009 | |
|
1010 | 1010 | nplots = 1 |
|
1011 | 1011 | |
|
1012 | 1012 | self.setup(id=id, |
|
1013 | 1013 | nplots=nplots, |
|
1014 | 1014 | wintitle=wintitle, |
|
1015 | 1015 | show=show) |
|
1016 | 1016 | |
|
1017 | 1017 | if ymin == None: ymin = numpy.nanmin(y) |
|
1018 | 1018 | if ymax == None: ymax = numpy.nanmax(y) |
|
1019 | 1019 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
1020 | 1020 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 |
|
1021 | 1021 | |
|
1022 | 1022 | self.isConfig = True |
|
1023 | 1023 | |
|
1024 | 1024 | self.setWinTitle(title) |
|
1025 | 1025 | |
|
1026 | 1026 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1027 | 1027 | axes = self.axesList[0] |
|
1028 | 1028 | |
|
1029 | 1029 | legendlabels = ["channel %d"%x for x in channelList] |
|
1030 | 1030 | axes.pmultiline(xdB, y, |
|
1031 | 1031 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1032 | 1032 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1033 | 1033 | ytick_visible=True, nxticks=5, |
|
1034 | 1034 | grid='x') |
|
1035 | 1035 | |
|
1036 | 1036 | self.draw() |
|
1037 | 1037 | |
|
1038 | 1038 | self.save(figpath=figpath, |
|
1039 | 1039 | figfile=figfile, |
|
1040 | 1040 | save=save, |
|
1041 | 1041 | ftp=ftp, |
|
1042 | 1042 | wr_period=wr_period, |
|
1043 | 1043 | thisDatetime=thisDatetime) |
|
1044 | 1044 | |
|
1045 | 1045 | class SpectraCutPlot(Figure): |
|
1046 | 1046 | |
|
1047 | 1047 | isConfig = None |
|
1048 | 1048 | __nsubplots = None |
|
1049 | 1049 | |
|
1050 | 1050 | WIDTHPROF = None |
|
1051 | 1051 | HEIGHTPROF = None |
|
1052 | 1052 | PREFIX = 'spc_cut' |
|
1053 | 1053 | |
|
1054 | 1054 | def __init__(self, **kwargs): |
|
1055 | 1055 | Figure.__init__(self, **kwargs) |
|
1056 | 1056 | self.isConfig = False |
|
1057 | 1057 | self.__nsubplots = 1 |
|
1058 | 1058 | |
|
1059 | 1059 | self.PLOT_CODE = POWER_CODE |
|
1060 | 1060 | |
|
1061 | 1061 | self.WIDTH = 700 |
|
1062 | 1062 | self.HEIGHT = 500 |
|
1063 | 1063 | self.counter_imagwr = 0 |
|
1064 | 1064 | |
|
1065 | 1065 | def getSubplots(self): |
|
1066 | 1066 | ncol = 1 |
|
1067 | 1067 | nrow = 1 |
|
1068 | 1068 | |
|
1069 | 1069 | return nrow, ncol |
|
1070 | 1070 | |
|
1071 | 1071 | def setup(self, id, nplots, wintitle, show): |
|
1072 | 1072 | |
|
1073 | 1073 | self.nplots = nplots |
|
1074 | 1074 | |
|
1075 | 1075 | ncolspan = 1 |
|
1076 | 1076 | colspan = 1 |
|
1077 | 1077 | |
|
1078 | 1078 | self.createFigure(id = id, |
|
1079 | 1079 | wintitle = wintitle, |
|
1080 | 1080 | widthplot = self.WIDTH, |
|
1081 | 1081 | heightplot = self.HEIGHT, |
|
1082 | 1082 | show=show) |
|
1083 | 1083 | |
|
1084 | 1084 | nrow, ncol = self.getSubplots() |
|
1085 | 1085 | |
|
1086 | 1086 | counter = 0 |
|
1087 | 1087 | for y in range(nrow): |
|
1088 | 1088 | for x in range(ncol): |
|
1089 | 1089 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1090 | 1090 | |
|
1091 | 1091 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1092 | 1092 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1093 | 1093 | save=False, figpath='./', figfile=None, show=True, |
|
1094 | 1094 | ftp=False, wr_period=1, server=None, |
|
1095 | 1095 | folder=None, username=None, password=None, |
|
1096 | 1096 | xaxis="frequency"): |
|
1097 | 1097 | |
|
1098 | 1098 | |
|
1099 | 1099 | if channelList == None: |
|
1100 | 1100 | channelIndexList = dataOut.channelIndexList |
|
1101 | 1101 | channelList = dataOut.channelList |
|
1102 | 1102 | else: |
|
1103 | 1103 | channelIndexList = [] |
|
1104 | 1104 | for channel in channelList: |
|
1105 | 1105 | if channel not in dataOut.channelList: |
|
1106 | 1106 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1107 | 1107 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1108 | 1108 | |
|
1109 | 1109 | factor = dataOut.normFactor |
|
1110 | 1110 | |
|
1111 | 1111 | y = dataOut.getHeiRange() |
|
1112 | 1112 | |
|
1113 | 1113 | z = dataOut.data_spc/factor |
|
1114 | 1114 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1115 | 1115 | |
|
1116 | 1116 | hei_index = numpy.arange(25)*3 + 20 |
|
1117 | 1117 | |
|
1118 | 1118 | if xaxis == "frequency": |
|
1119 | 1119 | x = dataOut.getFreqRange()/1000. |
|
1120 | 1120 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1121 | 1121 | xlabel = "Frequency (kHz)" |
|
1122 | 1122 | ylabel = "Power (dB)" |
|
1123 | 1123 | |
|
1124 | 1124 | elif xaxis == "time": |
|
1125 | 1125 | x = dataOut.getAcfRange() |
|
1126 | 1126 | zdB = z[0,:,hei_index] |
|
1127 | 1127 | xlabel = "Time (ms)" |
|
1128 | 1128 | ylabel = "ACF" |
|
1129 | 1129 | |
|
1130 | 1130 | else: |
|
1131 | 1131 | x = dataOut.getVelRange() |
|
1132 | 1132 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1133 | 1133 | xlabel = "Velocity (m/s)" |
|
1134 | 1134 | ylabel = "Power (dB)" |
|
1135 | 1135 | |
|
1136 | 1136 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1137 | 1137 | title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1138 | 1138 | |
|
1139 | 1139 | if not self.isConfig: |
|
1140 | 1140 | |
|
1141 | 1141 | nplots = 1 |
|
1142 | 1142 | |
|
1143 | 1143 | self.setup(id=id, |
|
1144 | 1144 | nplots=nplots, |
|
1145 | 1145 | wintitle=wintitle, |
|
1146 | 1146 | show=show) |
|
1147 | 1147 | |
|
1148 | 1148 | if xmin == None: xmin = numpy.nanmin(x)*0.9 |
|
1149 | 1149 | if xmax == None: xmax = numpy.nanmax(x)*1.1 |
|
1150 | 1150 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1151 | 1151 | if ymax == None: ymax = numpy.nanmax(zdB) |
|
1152 | 1152 | |
|
1153 | 1153 | self.isConfig = True |
|
1154 | 1154 | |
|
1155 | 1155 | self.setWinTitle(title) |
|
1156 | 1156 | |
|
1157 | 1157 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1158 | 1158 | axes = self.axesList[0] |
|
1159 | 1159 | |
|
1160 | 1160 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] |
|
1161 | 1161 | |
|
1162 | 1162 | axes.pmultilineyaxis( x, zdB, |
|
1163 | 1163 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1164 | 1164 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1165 | 1165 | ytick_visible=True, nxticks=5, |
|
1166 | 1166 | grid='x') |
|
1167 | 1167 | |
|
1168 | 1168 | self.draw() |
|
1169 | 1169 | |
|
1170 | 1170 | self.save(figpath=figpath, |
|
1171 | 1171 | figfile=figfile, |
|
1172 | 1172 | save=save, |
|
1173 | 1173 | ftp=ftp, |
|
1174 | 1174 | wr_period=wr_period, |
|
1175 | 1175 | thisDatetime=thisDatetime) |
|
1176 | 1176 | |
|
1177 | 1177 | class Noise(Figure): |
|
1178 | 1178 | |
|
1179 | 1179 | isConfig = None |
|
1180 | 1180 | __nsubplots = None |
|
1181 | 1181 | |
|
1182 | 1182 | PREFIX = 'noise' |
|
1183 | 1183 | |
|
1184 | 1184 | |
|
1185 | 1185 | def __init__(self, **kwargs): |
|
1186 | 1186 | Figure.__init__(self, **kwargs) |
|
1187 | 1187 | self.timerange = 24*60*60 |
|
1188 | 1188 | self.isConfig = False |
|
1189 | 1189 | self.__nsubplots = 1 |
|
1190 | 1190 | self.counter_imagwr = 0 |
|
1191 | 1191 | self.WIDTH = 800 |
|
1192 | 1192 | self.HEIGHT = 400 |
|
1193 | 1193 | self.WIDTHPROF = 120 |
|
1194 | 1194 | self.HEIGHTPROF = 0 |
|
1195 | 1195 | self.xdata = None |
|
1196 | 1196 | self.ydata = None |
|
1197 | 1197 | |
|
1198 | 1198 | self.PLOT_CODE = NOISE_CODE |
|
1199 | 1199 | |
|
1200 | 1200 | self.FTP_WEI = None |
|
1201 | 1201 | self.EXP_CODE = None |
|
1202 | 1202 | self.SUB_EXP_CODE = None |
|
1203 | 1203 | self.PLOT_POS = None |
|
1204 | 1204 | self.figfile = None |
|
1205 | 1205 | |
|
1206 | 1206 | self.xmin = None |
|
1207 | 1207 | self.xmax = None |
|
1208 | 1208 | |
|
1209 | 1209 | def getSubplots(self): |
|
1210 | 1210 | |
|
1211 | 1211 | ncol = 1 |
|
1212 | 1212 | nrow = 1 |
|
1213 | 1213 | |
|
1214 | 1214 | return nrow, ncol |
|
1215 | 1215 | |
|
1216 | 1216 | def openfile(self, filename): |
|
1217 | 1217 | dirname = os.path.dirname(filename) |
|
1218 | 1218 | |
|
1219 | 1219 | if not os.path.exists(dirname): |
|
1220 | 1220 | os.mkdir(dirname) |
|
1221 | 1221 | |
|
1222 | 1222 | f = open(filename,'w+') |
|
1223 | 1223 | f.write('\n\n') |
|
1224 | 1224 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1225 | 1225 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1226 | 1226 | f.close() |
|
1227 | 1227 | |
|
1228 | 1228 | def save_data(self, filename_phase, data, data_datetime): |
|
1229 | 1229 | |
|
1230 | 1230 | f=open(filename_phase,'a') |
|
1231 | 1231 | |
|
1232 | 1232 | timetuple_data = data_datetime.timetuple() |
|
1233 | 1233 | day = str(timetuple_data.tm_mday) |
|
1234 | 1234 | month = str(timetuple_data.tm_mon) |
|
1235 | 1235 | year = str(timetuple_data.tm_year) |
|
1236 | 1236 | hour = str(timetuple_data.tm_hour) |
|
1237 | 1237 | minute = str(timetuple_data.tm_min) |
|
1238 | 1238 | second = str(timetuple_data.tm_sec) |
|
1239 | 1239 | |
|
1240 | 1240 | data_msg = '' |
|
1241 | 1241 | for i in range(len(data)): |
|
1242 | 1242 | data_msg += str(data[i]) + ' ' |
|
1243 | 1243 | |
|
1244 | 1244 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') |
|
1245 | 1245 | f.close() |
|
1246 | 1246 | |
|
1247 | 1247 | |
|
1248 | 1248 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1249 | 1249 | |
|
1250 | 1250 | self.__showprofile = showprofile |
|
1251 | 1251 | self.nplots = nplots |
|
1252 | 1252 | |
|
1253 | 1253 | ncolspan = 7 |
|
1254 | 1254 | colspan = 6 |
|
1255 | 1255 | self.__nsubplots = 2 |
|
1256 | 1256 | |
|
1257 | 1257 | self.createFigure(id = id, |
|
1258 | 1258 | wintitle = wintitle, |
|
1259 | 1259 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1260 | 1260 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1261 | 1261 | show=show) |
|
1262 | 1262 | |
|
1263 | 1263 | nrow, ncol = self.getSubplots() |
|
1264 | 1264 | |
|
1265 | 1265 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1266 | 1266 | |
|
1267 | 1267 | |
|
1268 | 1268 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1269 | 1269 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1270 | 1270 | timerange=None, |
|
1271 | 1271 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1272 | 1272 | server=None, folder=None, username=None, password=None, |
|
1273 | 1273 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1274 | 1274 | |
|
1275 | 1275 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1276 | 1276 | return |
|
1277 | 1277 | |
|
1278 | 1278 | if channelList == None: |
|
1279 | 1279 | channelIndexList = dataOut.channelIndexList |
|
1280 | 1280 | channelList = dataOut.channelList |
|
1281 | 1281 | else: |
|
1282 | 1282 | channelIndexList = [] |
|
1283 | 1283 | for channel in channelList: |
|
1284 | 1284 | if channel not in dataOut.channelList: |
|
1285 | 1285 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1286 | 1286 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1287 | 1287 | |
|
1288 | 1288 | x = dataOut.getTimeRange() |
|
1289 | 1289 | #y = dataOut.getHeiRange() |
|
1290 | 1290 | factor = dataOut.normFactor |
|
1291 | 1291 | noise = dataOut.noise[channelIndexList]/factor |
|
1292 | 1292 | noisedB = 10*numpy.log10(noise) |
|
1293 | 1293 | |
|
1294 | 1294 | thisDatetime = dataOut.datatime |
|
1295 | 1295 | |
|
1296 | 1296 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1297 | 1297 | xlabel = "" |
|
1298 | 1298 | ylabel = "Intensity (dB)" |
|
1299 | 1299 | update_figfile = False |
|
1300 | 1300 | |
|
1301 | 1301 | if not self.isConfig: |
|
1302 | 1302 | |
|
1303 | 1303 | nplots = 1 |
|
1304 | 1304 | |
|
1305 | 1305 | self.setup(id=id, |
|
1306 | 1306 | nplots=nplots, |
|
1307 | 1307 | wintitle=wintitle, |
|
1308 | 1308 | showprofile=showprofile, |
|
1309 | 1309 | show=show) |
|
1310 | 1310 | |
|
1311 | 1311 | if timerange != None: |
|
1312 | 1312 | self.timerange = timerange |
|
1313 | 1313 | |
|
1314 | 1314 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1315 | 1315 | |
|
1316 | 1316 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 |
|
1317 | 1317 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1318 | 1318 | |
|
1319 | 1319 | self.FTP_WEI = ftp_wei |
|
1320 | 1320 | self.EXP_CODE = exp_code |
|
1321 | 1321 | self.SUB_EXP_CODE = sub_exp_code |
|
1322 | 1322 | self.PLOT_POS = plot_pos |
|
1323 | 1323 | |
|
1324 | 1324 | |
|
1325 | 1325 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1326 | 1326 | self.isConfig = True |
|
1327 | 1327 | self.figfile = figfile |
|
1328 | 1328 | self.xdata = numpy.array([]) |
|
1329 | 1329 | self.ydata = numpy.array([]) |
|
1330 | 1330 | |
|
1331 | 1331 | update_figfile = True |
|
1332 | 1332 | |
|
1333 | 1333 | #open file beacon phase |
|
1334 | 1334 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1335 | 1335 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1336 | 1336 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1337 | 1337 | |
|
1338 | 1338 | self.setWinTitle(title) |
|
1339 | 1339 | |
|
1340 | 1340 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1341 | 1341 | |
|
1342 | 1342 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] |
|
1343 | 1343 | axes = self.axesList[0] |
|
1344 | 1344 | |
|
1345 | 1345 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1346 | 1346 | |
|
1347 | 1347 | if len(self.ydata)==0: |
|
1348 | 1348 | self.ydata = noisedB.reshape(-1,1) |
|
1349 | 1349 | else: |
|
1350 | 1350 | self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) |
|
1351 | 1351 | |
|
1352 | 1352 | |
|
1353 | 1353 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1354 | 1354 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1355 | 1355 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1356 | 1356 | XAxisAsTime=True, grid='both' |
|
1357 | 1357 | ) |
|
1358 | 1358 | |
|
1359 | 1359 | self.draw() |
|
1360 | 1360 | |
|
1361 | 1361 | if dataOut.ltctime >= self.xmax: |
|
1362 | 1362 | self.counter_imagwr = wr_period |
|
1363 | 1363 | self.isConfig = False |
|
1364 | 1364 | update_figfile = True |
|
1365 | 1365 | |
|
1366 | 1366 | self.save(figpath=figpath, |
|
1367 | 1367 | figfile=figfile, |
|
1368 | 1368 | save=save, |
|
1369 | 1369 | ftp=ftp, |
|
1370 | 1370 | wr_period=wr_period, |
|
1371 | 1371 | thisDatetime=thisDatetime, |
|
1372 | 1372 | update_figfile=update_figfile) |
|
1373 | 1373 | |
|
1374 | 1374 | #store data beacon phase |
|
1375 | 1375 | if save: |
|
1376 | 1376 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1377 | 1377 | |
|
1378 | 1378 | class BeaconPhase(Figure): |
|
1379 | 1379 | |
|
1380 | 1380 | __isConfig = None |
|
1381 | 1381 | __nsubplots = None |
|
1382 | 1382 | |
|
1383 | 1383 | PREFIX = 'beacon_phase' |
|
1384 | 1384 | |
|
1385 | 1385 | def __init__(self, **kwargs): |
|
1386 | 1386 | Figure.__init__(self, **kwargs) |
|
1387 | 1387 | self.timerange = 24*60*60 |
|
1388 | 1388 | self.isConfig = False |
|
1389 | 1389 | self.__nsubplots = 1 |
|
1390 | 1390 | self.counter_imagwr = 0 |
|
1391 | 1391 | self.WIDTH = 800 |
|
1392 | 1392 | self.HEIGHT = 400 |
|
1393 | 1393 | self.WIDTHPROF = 120 |
|
1394 | 1394 | self.HEIGHTPROF = 0 |
|
1395 | 1395 | self.xdata = None |
|
1396 | 1396 | self.ydata = None |
|
1397 | 1397 | |
|
1398 | 1398 | self.PLOT_CODE = BEACON_CODE |
|
1399 | 1399 | |
|
1400 | 1400 | self.FTP_WEI = None |
|
1401 | 1401 | self.EXP_CODE = None |
|
1402 | 1402 | self.SUB_EXP_CODE = None |
|
1403 | 1403 | self.PLOT_POS = None |
|
1404 | 1404 | |
|
1405 | 1405 | self.filename_phase = None |
|
1406 | 1406 | |
|
1407 | 1407 | self.figfile = None |
|
1408 | 1408 | |
|
1409 | 1409 | self.xmin = None |
|
1410 | 1410 | self.xmax = None |
|
1411 | 1411 | |
|
1412 | 1412 | def getSubplots(self): |
|
1413 | 1413 | |
|
1414 | 1414 | ncol = 1 |
|
1415 | 1415 | nrow = 1 |
|
1416 | 1416 | |
|
1417 | 1417 | return nrow, ncol |
|
1418 | 1418 | |
|
1419 | 1419 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1420 | 1420 | |
|
1421 | 1421 | self.__showprofile = showprofile |
|
1422 | 1422 | self.nplots = nplots |
|
1423 | 1423 | |
|
1424 | 1424 | ncolspan = 7 |
|
1425 | 1425 | colspan = 6 |
|
1426 | 1426 | self.__nsubplots = 2 |
|
1427 | 1427 | |
|
1428 | 1428 | self.createFigure(id = id, |
|
1429 | 1429 | wintitle = wintitle, |
|
1430 | 1430 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1431 | 1431 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1432 | 1432 | show=show) |
|
1433 | 1433 | |
|
1434 | 1434 | nrow, ncol = self.getSubplots() |
|
1435 | 1435 | |
|
1436 | 1436 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1437 | 1437 | |
|
1438 | 1438 | def save_phase(self, filename_phase): |
|
1439 | 1439 | f = open(filename_phase,'w+') |
|
1440 | 1440 | f.write('\n\n') |
|
1441 | 1441 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1442 | 1442 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1443 | 1443 | f.close() |
|
1444 | 1444 | |
|
1445 | 1445 | def save_data(self, filename_phase, data, data_datetime): |
|
1446 | 1446 | f=open(filename_phase,'a') |
|
1447 | 1447 | timetuple_data = data_datetime.timetuple() |
|
1448 | 1448 | day = str(timetuple_data.tm_mday) |
|
1449 | 1449 | month = str(timetuple_data.tm_mon) |
|
1450 | 1450 | year = str(timetuple_data.tm_year) |
|
1451 | 1451 | hour = str(timetuple_data.tm_hour) |
|
1452 | 1452 | minute = str(timetuple_data.tm_min) |
|
1453 | 1453 | second = str(timetuple_data.tm_sec) |
|
1454 | 1454 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1455 | 1455 | f.close() |
|
1456 | 1456 | |
|
1457 | 1457 | |
|
1458 | 1458 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1459 | 1459 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, |
|
1460 | 1460 | timerange=None, |
|
1461 | 1461 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1462 | 1462 | server=None, folder=None, username=None, password=None, |
|
1463 | 1463 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1464 | 1464 | |
|
1465 | 1465 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1466 | 1466 | return |
|
1467 | 1467 | |
|
1468 | 1468 | if pairsList == None: |
|
1469 | 1469 | pairsIndexList = dataOut.pairsIndexList[:10] |
|
1470 | 1470 | else: |
|
1471 | 1471 | pairsIndexList = [] |
|
1472 | 1472 | for pair in pairsList: |
|
1473 | 1473 | if pair not in dataOut.pairsList: |
|
1474 | 1474 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1475 | 1475 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1476 | 1476 | |
|
1477 | 1477 | if pairsIndexList == []: |
|
1478 | 1478 | return |
|
1479 | 1479 | |
|
1480 | 1480 | # if len(pairsIndexList) > 4: |
|
1481 | 1481 | # pairsIndexList = pairsIndexList[0:4] |
|
1482 | 1482 | |
|
1483 | 1483 | hmin_index = None |
|
1484 | 1484 | hmax_index = None |
|
1485 | 1485 | |
|
1486 | 1486 | if hmin != None and hmax != None: |
|
1487 | 1487 | indexes = numpy.arange(dataOut.nHeights) |
|
1488 | 1488 | hmin_list = indexes[dataOut.heightList >= hmin] |
|
1489 | 1489 | hmax_list = indexes[dataOut.heightList <= hmax] |
|
1490 | 1490 | |
|
1491 | 1491 | if hmin_list.any(): |
|
1492 | 1492 | hmin_index = hmin_list[0] |
|
1493 | 1493 | |
|
1494 | 1494 | if hmax_list.any(): |
|
1495 | 1495 | hmax_index = hmax_list[-1]+1 |
|
1496 | 1496 | |
|
1497 | 1497 | x = dataOut.getTimeRange() |
|
1498 | 1498 | #y = dataOut.getHeiRange() |
|
1499 | 1499 | |
|
1500 | 1500 | |
|
1501 | 1501 | thisDatetime = dataOut.datatime |
|
1502 | 1502 | |
|
1503 | 1503 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1504 | 1504 | xlabel = "Local Time" |
|
1505 | 1505 | ylabel = "Phase (degrees)" |
|
1506 | 1506 | |
|
1507 | 1507 | update_figfile = False |
|
1508 | 1508 | |
|
1509 | 1509 | nplots = len(pairsIndexList) |
|
1510 | 1510 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1511 | 1511 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1512 | 1512 | for i in range(nplots): |
|
1513 | 1513 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1514 | 1514 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) |
|
1515 | 1515 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) |
|
1516 | 1516 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) |
|
1517 | 1517 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1518 | 1518 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1519 | 1519 | |
|
1520 | 1520 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1521 | 1521 | #print phase[dataOut.beacon_heiIndexList] |
|
1522 | 1522 | |
|
1523 | 1523 | if dataOut.beacon_heiIndexList: |
|
1524 | 1524 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1525 | 1525 | else: |
|
1526 | 1526 | phase_beacon[i] = numpy.average(phase) |
|
1527 | 1527 | |
|
1528 | 1528 | if not self.isConfig: |
|
1529 | 1529 | |
|
1530 | 1530 | nplots = len(pairsIndexList) |
|
1531 | 1531 | |
|
1532 | 1532 | self.setup(id=id, |
|
1533 | 1533 | nplots=nplots, |
|
1534 | 1534 | wintitle=wintitle, |
|
1535 | 1535 | showprofile=showprofile, |
|
1536 | 1536 | show=show) |
|
1537 | 1537 | |
|
1538 | 1538 | if timerange != None: |
|
1539 | 1539 | self.timerange = timerange |
|
1540 | 1540 | |
|
1541 | 1541 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1542 | 1542 | |
|
1543 | 1543 | if ymin == None: ymin = 0 |
|
1544 | 1544 | if ymax == None: ymax = 360 |
|
1545 | 1545 | |
|
1546 | 1546 | self.FTP_WEI = ftp_wei |
|
1547 | 1547 | self.EXP_CODE = exp_code |
|
1548 | 1548 | self.SUB_EXP_CODE = sub_exp_code |
|
1549 | 1549 | self.PLOT_POS = plot_pos |
|
1550 | 1550 | |
|
1551 | 1551 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1552 | 1552 | self.isConfig = True |
|
1553 | 1553 | self.figfile = figfile |
|
1554 | 1554 | self.xdata = numpy.array([]) |
|
1555 | 1555 | self.ydata = numpy.array([]) |
|
1556 | 1556 | |
|
1557 | 1557 | update_figfile = True |
|
1558 | 1558 | |
|
1559 | 1559 | #open file beacon phase |
|
1560 | 1560 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1561 | 1561 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1562 | 1562 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1563 | 1563 | #self.save_phase(self.filename_phase) |
|
1564 | 1564 | |
|
1565 | 1565 | |
|
1566 | 1566 | #store data beacon phase |
|
1567 | 1567 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1568 | 1568 | |
|
1569 | 1569 | self.setWinTitle(title) |
|
1570 | 1570 | |
|
1571 | 1571 | |
|
1572 | 1572 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1573 | 1573 | |
|
1574 | 1574 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1575 | 1575 | |
|
1576 | 1576 | axes = self.axesList[0] |
|
1577 | 1577 | |
|
1578 | 1578 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1579 | 1579 | |
|
1580 | 1580 | if len(self.ydata)==0: |
|
1581 | 1581 | self.ydata = phase_beacon.reshape(-1,1) |
|
1582 | 1582 | else: |
|
1583 | 1583 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1584 | 1584 | |
|
1585 | 1585 | |
|
1586 | 1586 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1587 | 1587 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1588 | 1588 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1589 | 1589 | XAxisAsTime=True, grid='both' |
|
1590 | 1590 | ) |
|
1591 | 1591 | |
|
1592 | 1592 | self.draw() |
|
1593 | 1593 | |
|
1594 | 1594 | if dataOut.ltctime >= self.xmax: |
|
1595 | 1595 | self.counter_imagwr = wr_period |
|
1596 | 1596 | self.isConfig = False |
|
1597 | 1597 | update_figfile = True |
|
1598 | 1598 | |
|
1599 | 1599 | self.save(figpath=figpath, |
|
1600 | 1600 | figfile=figfile, |
|
1601 | 1601 | save=save, |
|
1602 | 1602 | ftp=ftp, |
|
1603 | 1603 | wr_period=wr_period, |
|
1604 | 1604 | thisDatetime=thisDatetime, |
|
1605 | 1605 | update_figfile=update_figfile) |
@@ -1,4025 +1,4027 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import math |
|
3 | 3 | from scipy import optimize, interpolate, signal, stats, ndimage |
|
4 | 4 | import scipy |
|
5 | 5 | import re |
|
6 | 6 | import datetime |
|
7 | 7 | import copy |
|
8 | 8 | import sys |
|
9 | 9 | import importlib |
|
10 | 10 | import itertools |
|
11 | 11 | from multiprocessing import Pool, TimeoutError |
|
12 | 12 | from multiprocessing.pool import ThreadPool |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | import time |
|
17 | 17 | #from sklearn.cluster import KMeans |
|
18 | 18 | |
|
19 | 19 | import matplotlib.pyplot as plt |
|
20 | 20 | |
|
21 | 21 | from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters |
|
22 | 22 | from jroproc_base import ProcessingUnit, Operation |
|
23 | 23 | from schainpy.model.data.jrodata import Parameters, hildebrand_sekhon |
|
24 | 24 | from scipy import asarray as ar,exp |
|
25 | 25 | from scipy.optimize import curve_fit |
|
26 | 26 | |
|
27 | 27 | import warnings |
|
28 | 28 | from numpy import NaN |
|
29 | 29 | from scipy.optimize.optimize import OptimizeWarning |
|
30 | 30 | warnings.filterwarnings('ignore') |
|
31 | 31 | |
|
32 | 32 | |
|
33 | 33 | SPEED_OF_LIGHT = 299792458 |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | '''solving pickling issue''' |
|
37 | 37 | |
|
38 | 38 | def _pickle_method(method): |
|
39 | 39 | func_name = method.im_func.__name__ |
|
40 | 40 | obj = method.im_self |
|
41 | 41 | cls = method.im_class |
|
42 | 42 | return _unpickle_method, (func_name, obj, cls) |
|
43 | 43 | |
|
44 | 44 | def _unpickle_method(func_name, obj, cls): |
|
45 | 45 | for cls in cls.mro(): |
|
46 | 46 | try: |
|
47 | 47 | func = cls.__dict__[func_name] |
|
48 | 48 | except KeyError: |
|
49 | 49 | pass |
|
50 | 50 | else: |
|
51 | 51 | break |
|
52 | 52 | return func.__get__(obj, cls) |
|
53 | 53 | |
|
54 | 54 | class ParametersProc(ProcessingUnit): |
|
55 | 55 | |
|
56 | 56 | nSeconds = None |
|
57 | 57 | |
|
58 | 58 | def __init__(self): |
|
59 | 59 | ProcessingUnit.__init__(self) |
|
60 | 60 | |
|
61 | 61 | # self.objectDict = {} |
|
62 | 62 | self.buffer = None |
|
63 | 63 | self.firstdatatime = None |
|
64 | 64 | self.profIndex = 0 |
|
65 | 65 | self.dataOut = Parameters() |
|
66 | 66 | |
|
67 | 67 | def __updateObjFromInput(self): |
|
68 | 68 | |
|
69 | 69 | self.dataOut.inputUnit = self.dataIn.type |
|
70 | 70 | |
|
71 | 71 | self.dataOut.timeZone = self.dataIn.timeZone |
|
72 | 72 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
73 | 73 | self.dataOut.errorCount = self.dataIn.errorCount |
|
74 | 74 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
75 | 75 | |
|
76 | 76 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
77 | 77 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
78 | 78 | self.dataOut.channelList = self.dataIn.channelList |
|
79 | 79 | self.dataOut.heightList = self.dataIn.heightList |
|
80 | 80 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
81 | 81 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
82 | 82 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
83 | 83 | self.dataOut.nBaud = self.dataIn.nBaud |
|
84 | 84 | self.dataOut.nCode = self.dataIn.nCode |
|
85 | 85 | self.dataOut.code = self.dataIn.code |
|
86 | 86 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
87 | 87 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
88 | 88 | # self.dataOut.utctime = self.firstdatatime |
|
89 | 89 | self.dataOut.utctime = self.dataIn.utctime |
|
90 | 90 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
91 | 91 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
92 | 92 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
93 | 93 | # self.dataOut.nIncohInt = 1 |
|
94 | 94 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
95 | 95 | # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
96 | 96 | self.dataOut.timeInterval1 = self.dataIn.timeInterval |
|
97 | 97 | self.dataOut.heightList = self.dataIn.getHeiRange() |
|
98 | 98 | self.dataOut.frequency = self.dataIn.frequency |
|
99 | 99 | self.dataOut.noise = self.dataIn.noise |
|
100 | 100 | |
|
101 | 101 | |
|
102 | 102 | |
|
103 | 103 | def run(self): |
|
104 | 104 | |
|
105 | 105 | #---------------------- Voltage Data --------------------------- |
|
106 | 106 | |
|
107 | 107 | if self.dataIn.type == "Voltage": |
|
108 | 108 | |
|
109 | 109 | self.__updateObjFromInput() |
|
110 | 110 | self.dataOut.data_pre = self.dataIn.data.copy() |
|
111 | 111 | self.dataOut.flagNoData = False |
|
112 | 112 | self.dataOut.utctimeInit = self.dataIn.utctime |
|
113 | 113 | self.dataOut.paramInterval = self.dataIn.nProfiles*self.dataIn.nCohInt*self.dataIn.ippSeconds |
|
114 | 114 | return |
|
115 | 115 | |
|
116 | 116 | #---------------------- Spectra Data --------------------------- |
|
117 | 117 | |
|
118 | 118 | if self.dataIn.type == "Spectra": |
|
119 | 119 | |
|
120 | 120 | self.dataOut.data_pre = (self.dataIn.data_spc , self.dataIn.data_cspc) |
|
121 | 121 | print 'self.dataIn.data_spc', self.dataIn.data_spc.shape |
|
122 | 122 | self.dataOut.abscissaList = self.dataIn.getVelRange(1) |
|
123 | 123 | self.dataOut.spc_noise = self.dataIn.getNoise() |
|
124 | 124 | self.dataOut.spc_range = numpy.asanyarray((self.dataIn.getFreqRange(1) , self.dataIn.getAcfRange(1) , self.dataIn.getVelRange(1) )) |
|
125 | 125 | |
|
126 | 126 | self.dataOut.normFactor = self.dataIn.normFactor |
|
127 | 127 | #self.dataOut.outputInterval = self.dataIn.outputInterval |
|
128 | 128 | self.dataOut.groupList = self.dataIn.pairsList |
|
129 | 129 | self.dataOut.flagNoData = False |
|
130 | 130 | #print 'datain chandist ',self.dataIn.ChanDist |
|
131 | 131 | if hasattr(self.dataIn, 'ChanDist'): #Distances of receiver channels |
|
132 | 132 | self.dataOut.ChanDist = self.dataIn.ChanDist |
|
133 | 133 | else: self.dataOut.ChanDist = None |
|
134 | 134 | |
|
135 | 135 | print 'datain chandist ',self.dataOut.ChanDist |
|
136 | 136 | |
|
137 | 137 | #if hasattr(self.dataIn, 'VelRange'): #Velocities range |
|
138 | 138 | # self.dataOut.VelRange = self.dataIn.VelRange |
|
139 | 139 | #else: self.dataOut.VelRange = None |
|
140 | 140 | |
|
141 | 141 | if hasattr(self.dataIn, 'RadarConst'): #Radar Constant |
|
142 | 142 | self.dataOut.RadarConst = self.dataIn.RadarConst |
|
143 | 143 | |
|
144 | 144 | if hasattr(self.dataIn, 'NPW'): #NPW |
|
145 | 145 | self.dataOut.NPW = self.dataIn.NPW |
|
146 | 146 | |
|
147 | 147 | if hasattr(self.dataIn, 'COFA'): #COFA |
|
148 | 148 | self.dataOut.COFA = self.dataIn.COFA |
|
149 | 149 | |
|
150 | 150 | |
|
151 | 151 | |
|
152 | 152 | #---------------------- Correlation Data --------------------------- |
|
153 | 153 | |
|
154 | 154 | if self.dataIn.type == "Correlation": |
|
155 | 155 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.dataIn.splitFunctions() |
|
156 | 156 | |
|
157 | 157 | self.dataOut.data_pre = (self.dataIn.data_cf[acf_ind,:], self.dataIn.data_cf[ccf_ind,:,:]) |
|
158 | 158 | self.dataOut.normFactor = (self.dataIn.normFactor[acf_ind,:], self.dataIn.normFactor[ccf_ind,:]) |
|
159 | 159 | self.dataOut.groupList = (acf_pairs, ccf_pairs) |
|
160 | 160 | |
|
161 | 161 | self.dataOut.abscissaList = self.dataIn.lagRange |
|
162 | 162 | self.dataOut.noise = self.dataIn.noise |
|
163 | 163 | self.dataOut.data_SNR = self.dataIn.SNR |
|
164 | 164 | self.dataOut.flagNoData = False |
|
165 | 165 | self.dataOut.nAvg = self.dataIn.nAvg |
|
166 | 166 | |
|
167 | 167 | #---------------------- Parameters Data --------------------------- |
|
168 | 168 | |
|
169 | 169 | if self.dataIn.type == "Parameters": |
|
170 | 170 | self.dataOut.copy(self.dataIn) |
|
171 | 171 | self.dataOut.flagNoData = False |
|
172 | 172 | |
|
173 | 173 | return True |
|
174 | 174 | |
|
175 | 175 | self.__updateObjFromInput() |
|
176 | 176 | self.dataOut.utctimeInit = self.dataIn.utctime |
|
177 | 177 | self.dataOut.paramInterval = self.dataIn.timeInterval |
|
178 | 178 | |
|
179 | 179 | return |
|
180 | 180 | |
|
181 | 181 | |
|
182 | 182 | def target(tups): |
|
183 | 183 | |
|
184 | 184 | obj, args = tups |
|
185 | 185 | #print 'TARGETTT', obj, args |
|
186 | 186 | return obj.FitGau(args) |
|
187 | 187 | |
|
188 | 188 | |
|
189 | 189 | class SpectralFilters(Operation): |
|
190 | 190 | |
|
191 | 191 | '''This class allows the Rainfall / Wind Selection for CLAIRE RADAR |
|
192 | 192 | |
|
193 | 193 | LimitR : It is the limit in m/s of Rainfall |
|
194 | 194 | LimitW : It is the limit in m/s for Winds |
|
195 | 195 | |
|
196 | 196 | Input: |
|
197 | 197 | |
|
198 | 198 | self.dataOut.data_pre : SPC and CSPC |
|
199 | 199 | self.dataOut.spc_range : To select wind and rainfall velocities |
|
200 | 200 | |
|
201 | 201 | Affected: |
|
202 | 202 | |
|
203 | 203 | self.dataOut.data_pre : It is used for the new SPC and CSPC ranges of wind |
|
204 | 204 | self.dataOut.spcparam_range : Used in SpcParamPlot |
|
205 | 205 | self.dataOut.SPCparam : Used in PrecipitationProc |
|
206 | 206 | |
|
207 | 207 | |
|
208 | 208 | ''' |
|
209 | 209 | |
|
210 | 210 | def __init__(self, **kwargs): |
|
211 | 211 | Operation.__init__(self, **kwargs) |
|
212 | 212 | self.i=0 |
|
213 | 213 | |
|
214 | 214 | def run(self, dataOut, PositiveLimit=1.5, NegativeLimit=2.5): |
|
215 | 215 | |
|
216 | 216 | |
|
217 | 217 | #Limite de vientos |
|
218 | 218 | LimitR = PositiveLimit |
|
219 | 219 | LimitN = NegativeLimit |
|
220 | 220 | |
|
221 | 221 | self.spc = dataOut.data_pre[0].copy() |
|
222 | 222 | self.cspc = dataOut.data_pre[1].copy() |
|
223 | 223 | |
|
224 | 224 | self.Num_Hei = self.spc.shape[2] |
|
225 | 225 | self.Num_Bin = self.spc.shape[1] |
|
226 | 226 | self.Num_Chn = self.spc.shape[0] |
|
227 | 227 | |
|
228 | 228 | VelRange = dataOut.spc_range[2] |
|
229 | 229 | TimeRange = dataOut.spc_range[1] |
|
230 | 230 | FrecRange = dataOut.spc_range[0] |
|
231 | 231 | |
|
232 | 232 | Vmax= 2*numpy.max(dataOut.spc_range[2]) |
|
233 | 233 | Tmax= 2*numpy.max(dataOut.spc_range[1]) |
|
234 | 234 | Fmax= 2*numpy.max(dataOut.spc_range[0]) |
|
235 | 235 | |
|
236 | 236 | Breaker1R=VelRange[numpy.abs(VelRange-(-LimitN)).argmin()] |
|
237 | 237 | Breaker1R=numpy.where(VelRange == Breaker1R) |
|
238 | 238 | |
|
239 | 239 | Delta = self.Num_Bin/2 - Breaker1R[0] |
|
240 | 240 | |
|
241 | 241 | #Breaker1W=VelRange[numpy.abs(VelRange-(-LimitW)).argmin()] |
|
242 | 242 | #Breaker1W=numpy.where(VelRange == Breaker1W) |
|
243 | 243 | |
|
244 | 244 | #Breaker2W=VelRange[numpy.abs(VelRange-(LimitW)).argmin()] |
|
245 | 245 | #Breaker2W=numpy.where(VelRange == Breaker2W) |
|
246 | 246 | |
|
247 | 247 | |
|
248 | 248 | '''Reacomodando SPCrange''' |
|
249 | 249 | |
|
250 | 250 | VelRange=numpy.roll(VelRange,-(self.Num_Bin/2) ,axis=0) |
|
251 | 251 | |
|
252 | 252 | VelRange[-(self.Num_Bin/2):]+= Vmax |
|
253 | 253 | |
|
254 | 254 | FrecRange=numpy.roll(FrecRange,-(self.Num_Bin/2),axis=0) |
|
255 | 255 | |
|
256 | 256 | FrecRange[-(self.Num_Bin/2):]+= Fmax |
|
257 | 257 | |
|
258 | 258 | TimeRange=numpy.roll(TimeRange,-(self.Num_Bin/2),axis=0) |
|
259 | 259 | |
|
260 | 260 | TimeRange[-(self.Num_Bin/2):]+= Tmax |
|
261 | 261 | |
|
262 | 262 | ''' ------------------ ''' |
|
263 | 263 | |
|
264 | 264 | Breaker2R=VelRange[numpy.abs(VelRange-(LimitR)).argmin()] |
|
265 | 265 | Breaker2R=numpy.where(VelRange == Breaker2R) |
|
266 | 266 | |
|
267 | 267 | |
|
268 | 268 | SPCroll = numpy.roll(self.spc,-(self.Num_Bin/2) ,axis=1) |
|
269 | 269 | |
|
270 | 270 | SPCcut = SPCroll.copy() |
|
271 | 271 | for i in range(self.Num_Chn): |
|
272 | 272 | |
|
273 | 273 | SPCcut[i,0:int(Breaker2R[0]),:] = dataOut.noise[i] |
|
274 | 274 | SPCcut[i,-int(Delta):,:] = dataOut.noise[i] |
|
275 | 275 | |
|
276 | 276 | SPCcut[i]=SPCcut[i]- dataOut.noise[i] |
|
277 | 277 | SPCcut[ numpy.where( SPCcut<0 ) ] = 1e-20 |
|
278 | 278 | |
|
279 | 279 | SPCroll[i]=SPCroll[i]-dataOut.noise[i] |
|
280 | 280 | SPCroll[ numpy.where( SPCroll<0 ) ] = 1e-20 |
|
281 | 281 | |
|
282 | 282 | #self.spc[i, 0:int(Breaker1W[0]) ,:] = dataOut.noise[i] |
|
283 | 283 | #self.spc[i, int(Breaker2W[0]):self.Num_Bin ,:] = dataOut.noise[i] |
|
284 | 284 | |
|
285 | 285 | #self.cspc[i, 0:int(Breaker1W[0]) ,:] = dataOut.noise[i] |
|
286 | 286 | #self.cspc[i, int(Breaker2W[0]):self.Num_Bin ,:] = dataOut.noise[i] |
|
287 | 287 | |
|
288 | 288 | |
|
289 | 289 | |
|
290 | 290 | |
|
291 | 291 | |
|
292 | 292 | SPC_ch1 = SPCroll |
|
293 | 293 | |
|
294 | 294 | SPC_ch2 = SPCcut |
|
295 | 295 | |
|
296 | 296 | SPCparam = (SPC_ch1, SPC_ch2, self.spc) |
|
297 | 297 | dataOut.SPCparam = numpy.asarray(SPCparam) |
|
298 | 298 | |
|
299 | 299 | #dataOut.data_pre= (self.spc , self.cspc) |
|
300 | 300 | |
|
301 | 301 | #dataOut.data_preParam = (self.spc , self.cspc) |
|
302 | 302 | |
|
303 | 303 | dataOut.spcparam_range=numpy.zeros([self.Num_Chn,self.Num_Bin+1]) |
|
304 | 304 | |
|
305 | 305 | dataOut.spcparam_range[2]=VelRange |
|
306 | 306 | dataOut.spcparam_range[1]=TimeRange |
|
307 | 307 | dataOut.spcparam_range[0]=FrecRange |
|
308 | 308 | |
|
309 | 309 | |
|
310 | 310 | |
|
311 | 311 | |
|
312 | 312 | class GaussianFit(Operation): |
|
313 | 313 | |
|
314 | 314 | ''' |
|
315 | 315 | Function that fit of one and two generalized gaussians (gg) based |
|
316 | 316 | on the PSD shape across an "power band" identified from a cumsum of |
|
317 | 317 | the measured spectrum - noise. |
|
318 | 318 | |
|
319 | 319 | Input: |
|
320 | 320 | self.dataOut.data_pre : SelfSpectra |
|
321 | 321 | |
|
322 | 322 | Output: |
|
323 | 323 | self.dataOut.SPCparam : SPC_ch1, SPC_ch2 |
|
324 | 324 | |
|
325 | 325 | ''' |
|
326 | 326 | def __init__(self, **kwargs): |
|
327 | 327 | Operation.__init__(self, **kwargs) |
|
328 | 328 | self.i=0 |
|
329 | 329 | |
|
330 | 330 | |
|
331 | 331 | def run(self, dataOut, num_intg=7, pnoise=1., SNRlimit=-9): #num_intg: Incoherent integrations, pnoise: Noise, vel_arr: range of velocities, similar to the ftt points |
|
332 | 332 | """This routine will find a couple of generalized Gaussians to a power spectrum |
|
333 | 333 | input: spc |
|
334 | 334 | output: |
|
335 | 335 | Amplitude0,shift0,width0,p0,Amplitude1,shift1,width1,p1,noise |
|
336 | 336 | """ |
|
337 | 337 | |
|
338 | 338 | self.spc = dataOut.data_pre[0].copy() |
|
339 | 339 | |
|
340 | 340 | |
|
341 | 341 | print 'SelfSpectra Shape', numpy.asarray(self.spc).shape |
|
342 | 342 | |
|
343 | 343 | |
|
344 | 344 | #plt.figure(50) |
|
345 | 345 | #plt.subplot(121) |
|
346 | 346 | #plt.plot(self.spc,'k',label='spc(66)') |
|
347 | 347 | #plt.plot(xFrec,ySamples[1],'g',label='Ch1') |
|
348 | 348 | #plt.plot(xFrec,ySamples[2],'r',label='Ch2') |
|
349 | 349 | #plt.plot(xFrec,FitGauss,'yo:',label='fit') |
|
350 | 350 | #plt.legend() |
|
351 | 351 | #plt.title('DATOS A ALTURA DE 7500 METROS') |
|
352 | 352 | #plt.show() |
|
353 | 353 | |
|
354 | 354 | self.Num_Hei = self.spc.shape[2] |
|
355 | 355 | #self.Num_Bin = len(self.spc) |
|
356 | 356 | self.Num_Bin = self.spc.shape[1] |
|
357 | 357 | self.Num_Chn = self.spc.shape[0] |
|
358 | 358 | Vrange = dataOut.abscissaList |
|
359 | 359 | |
|
360 | 360 | GauSPC = numpy.empty([self.Num_Chn,self.Num_Bin,self.Num_Hei]) |
|
361 | 361 | SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei]) |
|
362 | 362 | SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei]) |
|
363 | 363 | SPC_ch1[:] = numpy.NaN |
|
364 | 364 | SPC_ch2[:] = numpy.NaN |
|
365 | 365 | |
|
366 | 366 | |
|
367 | 367 | start_time = time.time() |
|
368 | 368 | |
|
369 | 369 | noise_ = dataOut.spc_noise[0].copy() |
|
370 | 370 | |
|
371 | 371 | |
|
372 | 372 | pool = Pool(processes=self.Num_Chn) |
|
373 | 373 | args = [(Vrange, Ch, pnoise, noise_, num_intg, SNRlimit) for Ch in range(self.Num_Chn)] |
|
374 | 374 | objs = [self for __ in range(self.Num_Chn)] |
|
375 | 375 | attrs = zip(objs, args) |
|
376 | 376 | gauSPC = pool.map(target, attrs) |
|
377 | 377 | dataOut.SPCparam = numpy.asarray(SPCparam) |
|
378 | 378 | |
|
379 | 379 | |
|
380 | 380 | |
|
381 | 381 | print '========================================================' |
|
382 | 382 | print 'total_time: ', time.time()-start_time |
|
383 | 383 | |
|
384 | 384 | # re-normalizing spc and noise |
|
385 | 385 | # This part differs from gg1 |
|
386 | 386 | |
|
387 | 387 | |
|
388 | 388 | |
|
389 | 389 | ''' Parameters: |
|
390 | 390 | 1. Amplitude |
|
391 | 391 | 2. Shift |
|
392 | 392 | 3. Width |
|
393 | 393 | 4. Power |
|
394 | 394 | ''' |
|
395 | 395 | |
|
396 | 396 | |
|
397 | 397 | ############################################################################### |
|
398 | 398 | def FitGau(self, X): |
|
399 | 399 | |
|
400 | 400 | Vrange, ch, pnoise, noise_, num_intg, SNRlimit = X |
|
401 | 401 | #print 'VARSSSS', ch, pnoise, noise, num_intg |
|
402 | 402 | |
|
403 | 403 | #print 'HEIGHTS', self.Num_Hei |
|
404 | 404 | |
|
405 | 405 | SPCparam = [] |
|
406 | 406 | SPC_ch1 = numpy.empty([self.Num_Bin,self.Num_Hei]) |
|
407 | 407 | SPC_ch2 = numpy.empty([self.Num_Bin,self.Num_Hei]) |
|
408 | 408 | SPC_ch1[:] = 0#numpy.NaN |
|
409 | 409 | SPC_ch2[:] = 0#numpy.NaN |
|
410 | 410 | |
|
411 | 411 | |
|
412 | 412 | |
|
413 | 413 | for ht in range(self.Num_Hei): |
|
414 | 414 | #print (numpy.asarray(self.spc).shape) |
|
415 | 415 | |
|
416 | 416 | #print 'TTTTT', ch , ht |
|
417 | 417 | #print self.spc.shape |
|
418 | 418 | |
|
419 | 419 | |
|
420 | 420 | spc = numpy.asarray(self.spc)[ch,:,ht] |
|
421 | 421 | |
|
422 | 422 | ############################################# |
|
423 | 423 | # normalizing spc and noise |
|
424 | 424 | # This part differs from gg1 |
|
425 | 425 | spc_norm_max = max(spc) |
|
426 | 426 | #spc = spc / spc_norm_max |
|
427 | 427 | pnoise = pnoise #/ spc_norm_max |
|
428 | 428 | ############################################# |
|
429 | 429 | |
|
430 | 430 | fatspectra=1.0 |
|
431 | 431 | |
|
432 | 432 | wnoise = noise_ #/ spc_norm_max |
|
433 | 433 | #wnoise,stdv,i_max,index =enoise(spc,num_intg) #noise estimate using Hildebrand Sekhon, only wnoise is used |
|
434 | 434 | #if wnoise>1.1*pnoise: # to be tested later |
|
435 | 435 | # wnoise=pnoise |
|
436 | 436 | noisebl=wnoise*0.9; |
|
437 | 437 | noisebh=wnoise*1.1 |
|
438 | 438 | spc=spc-wnoise |
|
439 | 439 | # print 'wnoise', noise_[0], spc_norm_max, wnoise |
|
440 | 440 | minx=numpy.argmin(spc) |
|
441 | 441 | #spcs=spc.copy() |
|
442 | 442 | spcs=numpy.roll(spc,-minx) |
|
443 | 443 | cum=numpy.cumsum(spcs) |
|
444 | 444 | tot_noise=wnoise * self.Num_Bin #64; |
|
445 | 445 | #print 'spc' , spcs[5:8] , 'tot_noise', tot_noise |
|
446 | 446 | #tot_signal=sum(cum[-5:])/5.; ''' How does this line work? ''' |
|
447 | 447 | #snr=tot_signal/tot_noise |
|
448 | 448 | #snr=cum[-1]/tot_noise |
|
449 | 449 | snr = sum(spcs)/tot_noise |
|
450 | 450 | snrdB=10.*numpy.log10(snr) |
|
451 | 451 | |
|
452 | 452 | if snrdB < SNRlimit : |
|
453 | 453 | snr = numpy.NaN |
|
454 | 454 | SPC_ch1[:,ht] = 0#numpy.NaN |
|
455 | 455 | SPC_ch1[:,ht] = 0#numpy.NaN |
|
456 | 456 | SPCparam = (SPC_ch1,SPC_ch2) |
|
457 | 457 | continue |
|
458 | 458 | #print 'snr',snrdB #, sum(spcs) , tot_noise |
|
459 | 459 | |
|
460 | 460 | |
|
461 | 461 | |
|
462 | 462 | #if snrdB<-18 or numpy.isnan(snrdB) or num_intg<4: |
|
463 | 463 | # return [None,]*4,[None,]*4,None,snrdB,None,None,[None,]*5,[None,]*9,None |
|
464 | 464 | |
|
465 | 465 | cummax=max(cum); |
|
466 | 466 | epsi=0.08*fatspectra # cumsum to narrow down the energy region |
|
467 | 467 | cumlo=cummax*epsi; |
|
468 | 468 | cumhi=cummax*(1-epsi) |
|
469 | 469 | powerindex=numpy.array(numpy.where(numpy.logical_and(cum>cumlo, cum<cumhi))[0]) |
|
470 | 470 | |
|
471 | 471 | |
|
472 | 472 | if len(powerindex) < 1:# case for powerindex 0 |
|
473 | 473 | continue |
|
474 | 474 | powerlo=powerindex[0] |
|
475 | 475 | powerhi=powerindex[-1] |
|
476 | 476 | powerwidth=powerhi-powerlo |
|
477 | 477 | |
|
478 | 478 | firstpeak=powerlo+powerwidth/10.# first gaussian energy location |
|
479 | 479 | secondpeak=powerhi-powerwidth/10.#second gaussian energy location |
|
480 | 480 | midpeak=(firstpeak+secondpeak)/2. |
|
481 | 481 | firstamp=spcs[int(firstpeak)] |
|
482 | 482 | secondamp=spcs[int(secondpeak)] |
|
483 | 483 | midamp=spcs[int(midpeak)] |
|
484 | 484 | |
|
485 | 485 | x=numpy.arange( self.Num_Bin ) |
|
486 | 486 | y_data=spc+wnoise |
|
487 | 487 | |
|
488 | 488 | ''' single Gaussian ''' |
|
489 | 489 | shift0=numpy.mod(midpeak+minx, self.Num_Bin ) |
|
490 | 490 | width0=powerwidth/4.#Initialization entire power of spectrum divided by 4 |
|
491 | 491 | power0=2. |
|
492 | 492 | amplitude0=midamp |
|
493 | 493 | state0=[shift0,width0,amplitude0,power0,wnoise] |
|
494 | 494 | bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth),(0,None),(0.5,3.),(noisebl,noisebh)) |
|
495 | 495 | lsq1=fmin_l_bfgs_b(self.misfit1,state0,args=(y_data,x,num_intg),bounds=bnds,approx_grad=True) |
|
496 | 496 | |
|
497 | 497 | chiSq1=lsq1[1]; |
|
498 | 498 | |
|
499 | 499 | |
|
500 | 500 | if fatspectra<1.0 and powerwidth<4: |
|
501 | 501 | choice=0 |
|
502 | 502 | Amplitude0=lsq1[0][2] |
|
503 | 503 | shift0=lsq1[0][0] |
|
504 | 504 | width0=lsq1[0][1] |
|
505 | 505 | p0=lsq1[0][3] |
|
506 | 506 | Amplitude1=0. |
|
507 | 507 | shift1=0. |
|
508 | 508 | width1=0. |
|
509 | 509 | p1=0. |
|
510 | 510 | noise=lsq1[0][4] |
|
511 | 511 | #return (numpy.array([shift0,width0,Amplitude0,p0]), |
|
512 | 512 | # numpy.array([shift1,width1,Amplitude1,p1]),noise,snrdB,chiSq1,6.,sigmas1,[None,]*9,choice) |
|
513 | 513 | |
|
514 | 514 | ''' two gaussians ''' |
|
515 | 515 | #shift0=numpy.mod(firstpeak+minx,64); shift1=numpy.mod(secondpeak+minx,64) |
|
516 | 516 | shift0=numpy.mod(firstpeak+minx, self.Num_Bin ); |
|
517 | 517 | shift1=numpy.mod(secondpeak+minx, self.Num_Bin ) |
|
518 | 518 | width0=powerwidth/6.; |
|
519 | 519 | width1=width0 |
|
520 | 520 | power0=2.; |
|
521 | 521 | power1=power0 |
|
522 | 522 | amplitude0=firstamp; |
|
523 | 523 | amplitude1=secondamp |
|
524 | 524 | state0=[shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,wnoise] |
|
525 | 525 | #bnds=((0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(0,63),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh)) |
|
526 | 526 | bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(noisebl,noisebh)) |
|
527 | 527 | #bnds=(( 0,(self.Num_Bin-1) ),(1,powerwidth/2.),(0,None),(0.5,3.),( 0,(self.Num_Bin-1)),(1,powerwidth/2.),(0,None),(0.5,3.),(0.1,0.5)) |
|
528 | 528 | |
|
529 | 529 | lsq2 = fmin_l_bfgs_b( self.misfit2 , state0 , args=(y_data,x,num_intg) , bounds=bnds , approx_grad=True ) |
|
530 | 530 | |
|
531 | 531 | |
|
532 | 532 | chiSq2=lsq2[1]; |
|
533 | 533 | |
|
534 | 534 | |
|
535 | 535 | |
|
536 | 536 | oneG=(chiSq1<5 and chiSq1/chiSq2<2.0) and (abs(lsq2[0][0]-lsq2[0][4])<(lsq2[0][1]+lsq2[0][5])/3. or abs(lsq2[0][0]-lsq2[0][4])<10) |
|
537 | 537 | |
|
538 | 538 | if snrdB>-12: # when SNR is strong pick the peak with least shift (LOS velocity) error |
|
539 | 539 | if oneG: |
|
540 | 540 | choice=0 |
|
541 | 541 | else: |
|
542 | 542 | w1=lsq2[0][1]; w2=lsq2[0][5] |
|
543 | 543 | a1=lsq2[0][2]; a2=lsq2[0][6] |
|
544 | 544 | p1=lsq2[0][3]; p2=lsq2[0][7] |
|
545 | 545 | s1=(2**(1+1./p1))*scipy.special.gamma(1./p1)/p1; |
|
546 | 546 | s2=(2**(1+1./p2))*scipy.special.gamma(1./p2)/p2; |
|
547 | 547 | gp1=a1*w1*s1; gp2=a2*w2*s2 # power content of each ggaussian with proper p scaling |
|
548 | 548 | |
|
549 | 549 | if gp1>gp2: |
|
550 | 550 | if a1>0.7*a2: |
|
551 | 551 | choice=1 |
|
552 | 552 | else: |
|
553 | 553 | choice=2 |
|
554 | 554 | elif gp2>gp1: |
|
555 | 555 | if a2>0.7*a1: |
|
556 | 556 | choice=2 |
|
557 | 557 | else: |
|
558 | 558 | choice=1 |
|
559 | 559 | else: |
|
560 | 560 | choice=numpy.argmax([a1,a2])+1 |
|
561 | 561 | #else: |
|
562 | 562 | #choice=argmin([std2a,std2b])+1 |
|
563 | 563 | |
|
564 | 564 | else: # with low SNR go to the most energetic peak |
|
565 | 565 | choice=numpy.argmax([lsq1[0][2]*lsq1[0][1],lsq2[0][2]*lsq2[0][1],lsq2[0][6]*lsq2[0][5]]) |
|
566 | 566 | |
|
567 | 567 | |
|
568 | 568 | shift0=lsq2[0][0]; |
|
569 | 569 | vel0=Vrange[0] + shift0*(Vrange[1]-Vrange[0]) |
|
570 | 570 | shift1=lsq2[0][4]; |
|
571 | 571 | vel1=Vrange[0] + shift1*(Vrange[1]-Vrange[0]) |
|
572 | 572 | |
|
573 | 573 | max_vel = 1.0 |
|
574 | 574 | |
|
575 | 575 | #first peak will be 0, second peak will be 1 |
|
576 | 576 | if vel0 > -1.0 and vel0 < max_vel : #first peak is in the correct range |
|
577 | 577 | shift0=lsq2[0][0] |
|
578 | 578 | width0=lsq2[0][1] |
|
579 | 579 | Amplitude0=lsq2[0][2] |
|
580 | 580 | p0=lsq2[0][3] |
|
581 | 581 | |
|
582 | 582 | shift1=lsq2[0][4] |
|
583 | 583 | width1=lsq2[0][5] |
|
584 | 584 | Amplitude1=lsq2[0][6] |
|
585 | 585 | p1=lsq2[0][7] |
|
586 | 586 | noise=lsq2[0][8] |
|
587 | 587 | else: |
|
588 | 588 | shift1=lsq2[0][0] |
|
589 | 589 | width1=lsq2[0][1] |
|
590 | 590 | Amplitude1=lsq2[0][2] |
|
591 | 591 | p1=lsq2[0][3] |
|
592 | 592 | |
|
593 | 593 | shift0=lsq2[0][4] |
|
594 | 594 | width0=lsq2[0][5] |
|
595 | 595 | Amplitude0=lsq2[0][6] |
|
596 | 596 | p0=lsq2[0][7] |
|
597 | 597 | noise=lsq2[0][8] |
|
598 | 598 | |
|
599 | 599 | if Amplitude0<0.05: # in case the peak is noise |
|
600 | 600 | shift0,width0,Amplitude0,p0 = [0,0,0,0]#4*[numpy.NaN] |
|
601 | 601 | if Amplitude1<0.05: |
|
602 | 602 | shift1,width1,Amplitude1,p1 = [0,0,0,0]#4*[numpy.NaN] |
|
603 | 603 | |
|
604 | 604 | |
|
605 | 605 | # if choice==0: # pick the single gaussian fit |
|
606 | 606 | # Amplitude0=lsq1[0][2] |
|
607 | 607 | # shift0=lsq1[0][0] |
|
608 | 608 | # width0=lsq1[0][1] |
|
609 | 609 | # p0=lsq1[0][3] |
|
610 | 610 | # Amplitude1=0. |
|
611 | 611 | # shift1=0. |
|
612 | 612 | # width1=0. |
|
613 | 613 | # p1=0. |
|
614 | 614 | # noise=lsq1[0][4] |
|
615 | 615 | # elif choice==1: # take the first one of the 2 gaussians fitted |
|
616 | 616 | # Amplitude0 = lsq2[0][2] |
|
617 | 617 | # shift0 = lsq2[0][0] |
|
618 | 618 | # width0 = lsq2[0][1] |
|
619 | 619 | # p0 = lsq2[0][3] |
|
620 | 620 | # Amplitude1 = lsq2[0][6] # This is 0 in gg1 |
|
621 | 621 | # shift1 = lsq2[0][4] # This is 0 in gg1 |
|
622 | 622 | # width1 = lsq2[0][5] # This is 0 in gg1 |
|
623 | 623 | # p1 = lsq2[0][7] # This is 0 in gg1 |
|
624 | 624 | # noise = lsq2[0][8] |
|
625 | 625 | # else: # the second one |
|
626 | 626 | # Amplitude0 = lsq2[0][6] |
|
627 | 627 | # shift0 = lsq2[0][4] |
|
628 | 628 | # width0 = lsq2[0][5] |
|
629 | 629 | # p0 = lsq2[0][7] |
|
630 | 630 | # Amplitude1 = lsq2[0][2] # This is 0 in gg1 |
|
631 | 631 | # shift1 = lsq2[0][0] # This is 0 in gg1 |
|
632 | 632 | # width1 = lsq2[0][1] # This is 0 in gg1 |
|
633 | 633 | # p1 = lsq2[0][3] # This is 0 in gg1 |
|
634 | 634 | # noise = lsq2[0][8] |
|
635 | 635 | |
|
636 | 636 | #print len(noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0) |
|
637 | 637 | SPC_ch1[:,ht] = noise + Amplitude0*numpy.exp(-0.5*(abs(x-shift0))/width0)**p0 |
|
638 | 638 | SPC_ch2[:,ht] = noise + Amplitude1*numpy.exp(-0.5*(abs(x-shift1))/width1)**p1 |
|
639 | 639 | #print 'SPC_ch1.shape',SPC_ch1.shape |
|
640 | 640 | #print 'SPC_ch2.shape',SPC_ch2.shape |
|
641 | 641 | #dataOut.data_param = SPC_ch1 |
|
642 | 642 | SPCparam = (SPC_ch1,SPC_ch2) |
|
643 | 643 | #GauSPC[1] = SPC_ch2 |
|
644 | 644 | |
|
645 | 645 | # print 'shift0', shift0 |
|
646 | 646 | # print 'Amplitude0', Amplitude0 |
|
647 | 647 | # print 'width0', width0 |
|
648 | 648 | # print 'p0', p0 |
|
649 | 649 | # print '========================' |
|
650 | 650 | # print 'shift1', shift1 |
|
651 | 651 | # print 'Amplitude1', Amplitude1 |
|
652 | 652 | # print 'width1', width1 |
|
653 | 653 | # print 'p1', p1 |
|
654 | 654 | # print 'noise', noise |
|
655 | 655 | # print 's_noise', wnoise |
|
656 | 656 | |
|
657 | 657 | return GauSPC |
|
658 | 658 | |
|
659 | 659 | def y_model1(self,x,state): |
|
660 | 660 | shift0,width0,amplitude0,power0,noise=state |
|
661 | 661 | model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0) |
|
662 | 662 | |
|
663 | 663 | model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0) |
|
664 | 664 | |
|
665 | 665 | model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0) |
|
666 | 666 | return model0+model0u+model0d+noise |
|
667 | 667 | |
|
668 | 668 | def y_model2(self,x,state): #Equation for two generalized Gaussians with Nyquist |
|
669 | 669 | shift0,width0,amplitude0,power0,shift1,width1,amplitude1,power1,noise=state |
|
670 | 670 | model0=amplitude0*numpy.exp(-0.5*abs((x-shift0)/width0)**power0) |
|
671 | 671 | |
|
672 | 672 | model0u=amplitude0*numpy.exp(-0.5*abs((x-shift0- self.Num_Bin )/width0)**power0) |
|
673 | 673 | |
|
674 | 674 | model0d=amplitude0*numpy.exp(-0.5*abs((x-shift0+ self.Num_Bin )/width0)**power0) |
|
675 | 675 | model1=amplitude1*numpy.exp(-0.5*abs((x-shift1)/width1)**power1) |
|
676 | 676 | |
|
677 | 677 | model1u=amplitude1*numpy.exp(-0.5*abs((x-shift1- self.Num_Bin )/width1)**power1) |
|
678 | 678 | |
|
679 | 679 | model1d=amplitude1*numpy.exp(-0.5*abs((x-shift1+ self.Num_Bin )/width1)**power1) |
|
680 | 680 | return model0+model0u+model0d+model1+model1u+model1d+noise |
|
681 | 681 | |
|
682 | 682 | def misfit1(self,state,y_data,x,num_intg): # This function compares how close real data is with the model data, the close it is, the better it is. |
|
683 | 683 | |
|
684 | 684 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model1(x,state)))**2)#/(64-5.) # /(64-5.) can be commented |
|
685 | 685 | |
|
686 | 686 | def misfit2(self,state,y_data,x,num_intg): |
|
687 | 687 | return num_intg*sum((numpy.log(y_data)-numpy.log(self.y_model2(x,state)))**2)#/(64-9.) |
|
688 | 688 | |
|
689 | 689 | |
|
690 | 690 | |
|
691 | 691 | class PrecipitationProc(Operation): |
|
692 | 692 | |
|
693 | 693 | ''' |
|
694 | 694 | Operator that estimates Reflectivity factor (Z), and estimates rainfall Rate (R) |
|
695 | 695 | |
|
696 | 696 | Input: |
|
697 | 697 | self.dataOut.data_pre : SelfSpectra |
|
698 | 698 | |
|
699 | 699 | Output: |
|
700 | 700 | |
|
701 | 701 | self.dataOut.data_output : Reflectivity factor, rainfall Rate |
|
702 | 702 | |
|
703 | 703 | |
|
704 | 704 | Parameters affected: |
|
705 | 705 | ''' |
|
706 | 706 | def gaus(self,xSamples,Amp,Mu,Sigma): |
|
707 | 707 | return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) )) |
|
708 | 708 | |
|
709 | 709 | |
|
710 | 710 | |
|
711 | 711 | def Moments(self, ySamples, xSamples): |
|
712 | 712 | Pot = numpy.nansum( ySamples ) # Potencia, momento 0 |
|
713 | 713 | yNorm = ySamples / Pot |
|
714 | 714 | |
|
715 | 715 | Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento |
|
716 | 716 | Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento |
|
717 | 717 | Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral |
|
718 | 718 | |
|
719 | 719 | return numpy.array([Pot, Vr, Desv]) |
|
720 | 720 | |
|
721 | 721 | def run(self, dataOut, radar=None, Pt=5000, Gt=295.1209, Gr=70.7945, Lambda=0.6741, aL=2.5118, |
|
722 | 722 | tauW=4e-06, ThetaT=0.1656317, ThetaR=0.36774087, Km = 0.93, Altitude=3350): |
|
723 | 723 | |
|
724 | 724 | |
|
725 | 725 | Velrange = dataOut.spcparam_range[2] |
|
726 | 726 | FrecRange = dataOut.spcparam_range[0] |
|
727 | 727 | |
|
728 | 728 | dV= Velrange[1]-Velrange[0] |
|
729 | 729 | dF= FrecRange[1]-FrecRange[0] |
|
730 | 730 | |
|
731 | 731 | if radar == "MIRA35C" : |
|
732 | 732 | |
|
733 | 733 | self.spc = dataOut.data_pre[0].copy() |
|
734 | 734 | self.Num_Hei = self.spc.shape[2] |
|
735 | 735 | self.Num_Bin = self.spc.shape[1] |
|
736 | 736 | self.Num_Chn = self.spc.shape[0] |
|
737 | 737 | Ze = self.dBZeMODE2(dataOut) |
|
738 | 738 | |
|
739 | 739 | else: |
|
740 | 740 | |
|
741 | 741 | self.spc = dataOut.SPCparam[1].copy() #dataOut.data_pre[0].copy() # |
|
742 | 742 | self.Num_Hei = self.spc.shape[2] |
|
743 | 743 | self.Num_Bin = self.spc.shape[1] |
|
744 | 744 | self.Num_Chn = self.spc.shape[0] |
|
745 | 745 | print '==================== SPC SHAPE',numpy.shape(self.spc) |
|
746 | 746 | |
|
747 | 747 | |
|
748 | 748 | ''' Se obtiene la constante del RADAR ''' |
|
749 | 749 | |
|
750 | 750 | self.Pt = Pt |
|
751 | 751 | self.Gt = Gt |
|
752 | 752 | self.Gr = Gr |
|
753 | 753 | self.Lambda = Lambda |
|
754 | 754 | self.aL = aL |
|
755 | 755 | self.tauW = tauW |
|
756 | 756 | self.ThetaT = ThetaT |
|
757 | 757 | self.ThetaR = ThetaR |
|
758 | 758 | |
|
759 | 759 | Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) |
|
760 | 760 | Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * tauW * numpy.pi * ThetaT * ThetaR) |
|
761 | 761 | RadarConstant = 5e-27 * Numerator / Denominator # |
|
762 | 762 | print '***' |
|
763 | 763 | print '*** RadarConstant' , RadarConstant, '****' |
|
764 | 764 | print '***' |
|
765 | 765 | ''' ============================= ''' |
|
766 | 766 | |
|
767 | 767 | self.spc[0] = (self.spc[0]-dataOut.noise[0]) |
|
768 | 768 | self.spc[1] = (self.spc[1]-dataOut.noise[1]) |
|
769 | 769 | self.spc[2] = (self.spc[2]-dataOut.noise[2]) |
|
770 | 770 | |
|
771 | 771 | self.spc[ numpy.where(self.spc < 0)] = 0 |
|
772 |
|
|
|
772 | ||
|
773 | 773 | SPCmean = (numpy.mean(self.spc,0) - numpy.mean(dataOut.noise)) |
|
774 | 774 | SPCmean[ numpy.where(SPCmean < 0)] = 0 |
|
775 | 775 | |
|
776 | 776 | ETAn = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
777 | 777 | ETAv = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
778 | 778 | ETAd = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
779 | 779 | |
|
780 | 780 | Pr = SPCmean[:,:] |
|
781 | 781 | |
|
782 | 782 | VelMeteoro = numpy.mean(SPCmean,axis=0) |
|
783 | 783 | |
|
784 | 784 | #print '==================== Vel SHAPE',VelMeteoro |
|
785 | 785 | |
|
786 | 786 | D_range = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
787 | 787 | SIGMA = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
788 | 788 | N_dist = numpy.zeros([self.Num_Bin,self.Num_Hei]) |
|
789 | 789 | V_mean = numpy.zeros(self.Num_Hei) |
|
790 | 790 | del_V = numpy.zeros(self.Num_Hei) |
|
791 | 791 | Z = numpy.zeros(self.Num_Hei) |
|
792 | 792 | Ze = numpy.zeros(self.Num_Hei) |
|
793 | 793 | RR = numpy.zeros(self.Num_Hei) |
|
794 | 794 | |
|
795 | 795 | Range = dataOut.heightList*1000. |
|
796 | 796 | |
|
797 | 797 | for R in range(self.Num_Hei): |
|
798 |
|
|
|
798 | ||
|
799 | 799 | h = Range[R] + Altitude #Range from ground to radar pulse altitude |
|
800 | 800 | del_V[R] = 1 + 3.68 * 10**-5 * h + 1.71 * 10**-9 * h**2 #Density change correction for velocity |
|
801 | 801 | |
|
802 | 802 | D_range[:,R] = numpy.log( (9.65 - (Velrange[0:self.Num_Bin] / del_V[R])) / 10.3 ) / -0.6 #Diameter range [m]x10**-3 |
|
803 | 803 | |
|
804 | 804 | '''NOTA: ETA(n) dn = ETA(f) df |
|
805 | 805 | |
|
806 | 806 | dn = 1 Diferencial de muestreo |
|
807 | 807 | df = ETA(n) / ETA(f) |
|
808 | 808 | |
|
809 | 809 | ''' |
|
810 | 810 | |
|
811 | 811 | ETAn[:,R] = RadarConstant * Pr[:,R] * (Range[R] )**2 #Reflectivity (ETA) |
|
812 | 812 | |
|
813 | 813 | ETAv[:,R]=ETAn[:,R]/dV |
|
814 | 814 | |
|
815 | 815 | ETAd[:,R]=ETAv[:,R]*6.18*exp(-0.6*D_range[:,R]) |
|
816 | 816 | |
|
817 | 817 | SIGMA[:,R] = Km * (D_range[:,R] * 1e-3 )**6 * numpy.pi**5 / Lambda**4 #Equivalent Section of drops (sigma) |
|
818 | 818 | |
|
819 | 819 | N_dist[:,R] = ETAn[:,R] / SIGMA[:,R] |
|
820 | 820 | |
|
821 | 821 | DMoments = self.Moments(Pr[:,R], Velrange[0:self.Num_Bin]) |
|
822 | 822 | |
|
823 | 823 | try: |
|
824 | 824 | popt01,pcov = curve_fit(self.gaus, Velrange[0:self.Num_Bin] , Pr[:,R] , p0=DMoments) |
|
825 | 825 | except: |
|
826 | 826 | popt01=numpy.zeros(3) |
|
827 | 827 | popt01[1]= DMoments[1] |
|
828 | ||
|
828 | 829 | if popt01[1]<0 or popt01[1]>20: |
|
829 | 830 | popt01[1]=numpy.NaN |
|
830 |
|
|
|
831 | ||
|
832 | ||
|
831 | 833 | V_mean[R]=popt01[1] |
|
832 | ||
|
834 | ||
|
833 | 835 | Z[R] = numpy.nansum( N_dist[:,R] * (D_range[:,R])**6 )#*10**-18 |
|
834 | 836 | |
|
835 | 837 | RR[R] = 0.0006*numpy.pi * numpy.nansum( D_range[:,R]**3 * N_dist[:,R] * Velrange[0:self.Num_Bin] ) #Rainfall rate |
|
836 | ||
|
838 | ||
|
837 | 839 | Ze[R] = (numpy.nansum( ETAn[:,R]) * Lambda**4) / ( 10**-18*numpy.pi**5 * Km) |
|
838 | ||
|
840 | ||
|
839 | 841 | |
|
840 | 842 | |
|
841 | 843 | RR2 = (Z/200)**(1/1.6) |
|
842 | 844 | dBRR = 10*numpy.log10(RR) |
|
843 | 845 | dBRR2 = 10*numpy.log10(RR2) |
|
844 | 846 | |
|
845 | 847 | dBZe = 10*numpy.log10(Ze) |
|
846 | 848 | dBZ = 10*numpy.log10(Z) |
|
847 | 849 | |
|
848 | 850 | dataOut.data_output = Z |
|
849 | 851 | dataOut.data_param = numpy.ones([3,self.Num_Hei]) |
|
850 | 852 | dataOut.channelList = [0,1,2] |
|
851 | 853 | |
|
852 | 854 | dataOut.data_param[0]=dBZ |
|
853 | 855 | dataOut.data_param[1]=V_mean |
|
854 | 856 | dataOut.data_param[2]=RR |
|
855 |
|
|
|
857 | ||
|
856 | 858 | #print 'VELRANGE', Velrange |
|
857 | 859 | #print 'Range', len(Range) |
|
858 | 860 | #print 'delv',del_V |
|
859 | 861 | # print 'DRANGE', D_range[:,56] |
|
860 | 862 | # #print 'NOISE', dataOut.noise[0], 10*numpy.log10(dataOut.noise[0]) |
|
861 | 863 | # print 'radarconstant', RadarConstant |
|
862 | 864 | # #print 'ETAn SHAPE', ETAn.shape |
|
863 | 865 | # # print 'ETAn ', numpy.nansum(ETAn, axis=0) |
|
864 | 866 | # # print 'ETAd ', numpy.nansum(ETAd, axis=0) |
|
865 | 867 | # print 'Pr ', numpy.nansum(Pr, axis=0) |
|
866 | 868 | # print 'dataOut.SPCparam[1]', numpy.nansum(dataOut.SPCparam[1][0], axis=0) |
|
867 | 869 | # print 'Ze ', dBZe |
|
868 | 870 | print 'Z ', dBZ |
|
869 | 871 | # print 'Ndist',N_dist[:,56] |
|
870 | 872 | print 'RR2 ', RR2 |
|
871 | 873 | print 'RR ', RR |
|
872 | 874 | print 'Vr', V_mean |
|
873 | 875 | #print 'RR2 ', dBRR2 |
|
874 | 876 | #print 'D_mean', D_mean |
|
875 | 877 | #print 'del_V', del_V |
|
876 | 878 | #print 'D_range',D_range.shape, D_range[:,30] |
|
877 | 879 | #print 'Velrange', Velrange |
|
878 | 880 | #print 'numpy.nansum( N_dist[:,R]', numpy.nansum( N_dist, axis=0) |
|
879 | 881 | #print 'dataOut.data_param SHAPE', dataOut.data_param.shape |
|
880 | 882 | |
|
881 | 883 | |
|
882 | 884 | def dBZeMODE2(self, dataOut): # Processing for MIRA35C |
|
883 | 885 | |
|
884 | 886 | NPW = dataOut.NPW |
|
885 | 887 | COFA = dataOut.COFA |
|
886 | 888 | |
|
887 | 889 | SNR = numpy.array([self.spc[0,:,:] / NPW[0]]) #, self.spc[1,:,:] / NPW[1]]) |
|
888 | 890 | RadarConst = dataOut.RadarConst |
|
889 | 891 | #frequency = 34.85*10**9 |
|
890 | 892 | |
|
891 | 893 | ETA = numpy.zeros(([self.Num_Chn ,self.Num_Hei])) |
|
892 | 894 | data_output = numpy.ones([self.Num_Chn , self.Num_Hei])*numpy.NaN |
|
893 | 895 | |
|
894 | 896 | ETA = numpy.sum(SNR,1) |
|
895 | 897 | print 'ETA' , ETA |
|
896 | 898 | ETA = numpy.where(ETA is not 0. , ETA, numpy.NaN) |
|
897 | 899 | |
|
898 | 900 | Ze = numpy.ones([self.Num_Chn, self.Num_Hei] ) |
|
899 | 901 | |
|
900 | 902 | for r in range(self.Num_Hei): |
|
901 | 903 | |
|
902 | 904 | Ze[0,r] = ( ETA[0,r] ) * COFA[0,r][0] * RadarConst * ((r/5000.)**2) |
|
903 | 905 | #Ze[1,r] = ( ETA[1,r] ) * COFA[1,r][0] * RadarConst * ((r/5000.)**2) |
|
904 | 906 | |
|
905 | 907 | return Ze |
|
906 | 908 | |
|
907 | 909 | # def GetRadarConstant(self): |
|
908 | 910 | # |
|
909 | 911 | # """ |
|
910 | 912 | # Constants: |
|
911 | 913 | # |
|
912 | 914 | # Pt: Transmission Power dB 5kW 5000 |
|
913 | 915 | # Gt: Transmission Gain dB 24.7 dB 295.1209 |
|
914 | 916 | # Gr: Reception Gain dB 18.5 dB 70.7945 |
|
915 | 917 | # Lambda: Wavelenght m 0.6741 m 0.6741 |
|
916 | 918 | # aL: Attenuation loses dB 4dB 2.5118 |
|
917 | 919 | # tauW: Width of transmission pulse s 4us 4e-6 |
|
918 | 920 | # ThetaT: Transmission antenna bean angle rad 0.1656317 rad 0.1656317 |
|
919 | 921 | # ThetaR: Reception antenna beam angle rad 0.36774087 rad 0.36774087 |
|
920 | 922 | # |
|
921 | 923 | # """ |
|
922 | 924 | # |
|
923 | 925 | # Numerator = ( (4*numpy.pi)**3 * aL**2 * 16 * numpy.log(2) ) |
|
924 | 926 | # Denominator = ( Pt * Gt * Gr * Lambda**2 * SPEED_OF_LIGHT * TauW * numpy.pi * ThetaT * TheraR) |
|
925 | 927 | # RadarConstant = Numerator / Denominator |
|
926 | 928 | # |
|
927 | 929 | # return RadarConstant |
|
928 | 930 | |
|
929 | 931 | |
|
930 | 932 | |
|
931 | 933 | class FullSpectralAnalysis(Operation): |
|
932 | 934 | |
|
933 | 935 | """ |
|
934 | 936 | Function that implements Full Spectral Analisys technique. |
|
935 | 937 | |
|
936 | 938 | Input: |
|
937 | 939 | self.dataOut.data_pre : SelfSpectra and CrossSPectra data |
|
938 | 940 | self.dataOut.groupList : Pairlist of channels |
|
939 | 941 | self.dataOut.ChanDist : Physical distance between receivers |
|
940 | 942 | |
|
941 | 943 | |
|
942 | 944 | Output: |
|
943 | 945 | |
|
944 | 946 | self.dataOut.data_output : Zonal wind, Meridional wind and Vertical wind |
|
945 | 947 | |
|
946 | 948 | |
|
947 | 949 | Parameters affected: Winds, height range, SNR |
|
948 | 950 | |
|
949 | 951 | """ |
|
950 |
def run(self, dataOut, |
|
|
952 | def run(self, dataOut, Xi01=None, Xi02=None, Xi12=None, Eta01=None, Eta02=None, Eta12=None, SNRlimit=7): | |
|
951 | 953 | |
|
952 | 954 | self.indice=int(numpy.random.rand()*1000) |
|
953 | 955 | |
|
954 | 956 | spc = dataOut.data_pre[0].copy() |
|
955 | 957 | cspc = dataOut.data_pre[1] |
|
956 | 958 | |
|
957 | 959 | nChannel = spc.shape[0] |
|
958 | 960 | nProfiles = spc.shape[1] |
|
959 | 961 | nHeights = spc.shape[2] |
|
960 | 962 | |
|
961 | 963 | pairsList = dataOut.groupList |
|
962 | 964 | if dataOut.ChanDist is not None : |
|
963 | 965 | ChanDist = dataOut.ChanDist |
|
964 | 966 | else: |
|
965 |
ChanDist = numpy.array([[ |
|
|
967 | ChanDist = numpy.array([[Xi01, Eta01],[Xi02,Eta02],[Xi12,Eta12]]) | |
|
966 | 968 | |
|
967 | 969 | FrecRange = dataOut.spc_range[0] |
|
968 | 970 | |
|
969 | 971 | ySamples=numpy.ones([nChannel,nProfiles]) |
|
970 | 972 | phase=numpy.ones([nChannel,nProfiles]) |
|
971 | 973 | CSPCSamples=numpy.ones([nChannel,nProfiles],dtype=numpy.complex_) |
|
972 | 974 | coherence=numpy.ones([nChannel,nProfiles]) |
|
973 | 975 | PhaseSlope=numpy.ones(nChannel) |
|
974 | 976 | PhaseInter=numpy.ones(nChannel) |
|
975 | 977 | data_SNR=numpy.zeros([nProfiles]) |
|
976 | 978 | |
|
977 | 979 | data = dataOut.data_pre |
|
978 | 980 | noise = dataOut.noise |
|
979 | 981 | |
|
980 | 982 | dataOut.data_SNR = (numpy.mean(spc,axis=1)- noise[0]) / noise[0] |
|
981 | 983 | |
|
982 | 984 | dataOut.data_SNR[numpy.where( dataOut.data_SNR <0 )] = 1e-20 |
|
983 | 985 | |
|
984 | 986 | |
|
985 | 987 | #FirstMoment = dataOut.moments[0,1,:]#numpy.average(dataOut.data_param[:,1,:],0) |
|
986 | 988 | #SecondMoment = numpy.average(dataOut.moments[:,2,:],0) |
|
987 | 989 | |
|
988 | 990 | #SNRdBMean = [] |
|
989 | 991 | |
|
990 | 992 | data_output=numpy.ones([spc.shape[0],spc.shape[2]])*numpy.NaN |
|
991 | 993 | |
|
992 | 994 | velocityX=[] |
|
993 | 995 | velocityY=[] |
|
994 | 996 | velocityV=[] |
|
995 | 997 | PhaseLine=[] |
|
996 | 998 | |
|
997 | 999 | dbSNR = 10*numpy.log10(dataOut.data_SNR) |
|
998 | 1000 | dbSNR = numpy.average(dbSNR,0) |
|
999 | 1001 | |
|
1000 | 1002 | for Height in range(nHeights): |
|
1001 | 1003 | |
|
1002 | 1004 | [Vzon,Vmer,Vver, GaussCenter, PhaseSlope, FitGaussCSPC]= self.WindEstimation(spc, cspc, pairsList, ChanDist, Height, noise, dataOut.spc_range.copy(), dbSNR[Height], SNRlimit) |
|
1003 | 1005 | PhaseLine = numpy.append(PhaseLine, PhaseSlope) |
|
1004 | 1006 | |
|
1005 | 1007 | if abs(Vzon)<100. and abs(Vzon)> 0.: |
|
1006 |
velocityX=numpy.append(velocityX, |
|
|
1008 | velocityX=numpy.append(velocityX, Vzon)#Vmag | |
|
1007 | 1009 | |
|
1008 | 1010 | else: |
|
1009 | 1011 | #print 'Vzon',Vzon |
|
1010 | 1012 | velocityX=numpy.append(velocityX, numpy.NaN) |
|
1011 | 1013 | |
|
1012 | 1014 | if abs(Vmer)<100. and abs(Vmer) > 0.: |
|
1013 | 1015 | velocityY=numpy.append(velocityY, -Vmer)#Vang |
|
1014 | 1016 | |
|
1015 | 1017 | else: |
|
1016 | 1018 | #print 'Vmer',Vmer |
|
1017 | 1019 | velocityY=numpy.append(velocityY, numpy.NaN) |
|
1018 | 1020 | |
|
1019 | 1021 | if dbSNR[Height] > SNRlimit: |
|
1020 | 1022 | velocityV=numpy.append(velocityV, -Vver)#FirstMoment[Height]) |
|
1021 | 1023 | else: |
|
1022 | 1024 | velocityV=numpy.append(velocityV, numpy.NaN) |
|
1023 | 1025 | #FirstMoment[Height]= numpy.NaN |
|
1024 | 1026 | # if SNRdBMean[Height] <12: |
|
1025 | 1027 | # FirstMoment[Height] = numpy.NaN |
|
1026 | 1028 | # velocityX[Height] = numpy.NaN |
|
1027 | 1029 | # velocityY[Height] = numpy.NaN |
|
1028 | 1030 | |
|
1029 | 1031 | |
|
1030 | 1032 | |
|
1031 | 1033 | data_output[0] = numpy.array(velocityX) #self.moving_average(numpy.array(velocityX) , N=1) |
|
1032 | 1034 | data_output[1] = numpy.array(velocityY) #self.moving_average(numpy.array(velocityY) , N=1) |
|
1033 |
data_output[2] = |
|
|
1035 | data_output[2] = velocityV#FirstMoment | |
|
1034 | 1036 | |
|
1035 | 1037 | print 'data_output', data_output.shape |
|
1036 | 1038 | #print FirstMoment |
|
1037 | 1039 | # print 'velocityX',numpy.shape(data_output[0]) |
|
1038 | 1040 | # print 'velocityX',data_output[0] |
|
1039 | 1041 | # print ' ' |
|
1040 | 1042 | # print 'velocityY',numpy.shape(data_output[1]) |
|
1041 | 1043 | # print 'velocityY',data_output[1] |
|
1042 | 1044 | # print 'velocityV',data_output[2] |
|
1043 | 1045 | # print 'PhaseLine',PhaseLine |
|
1044 | 1046 | #print numpy.array(velocityY) |
|
1045 | 1047 | #print 'SNR' |
|
1046 | 1048 | #print 10*numpy.log10(dataOut.data_SNR) |
|
1047 | 1049 | #print numpy.shape(10*numpy.log10(dataOut.data_SNR)) |
|
1048 | 1050 | print ' ' |
|
1049 | 1051 | |
|
1050 | 1052 | xFrec=FrecRange[0:spc.shape[1]] |
|
1051 | 1053 | |
|
1052 | 1054 | dataOut.data_output=data_output |
|
1053 | 1055 | |
|
1054 | 1056 | return |
|
1055 | 1057 | |
|
1056 | 1058 | |
|
1057 | 1059 | def moving_average(self,x, N=2): |
|
1058 | 1060 | return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):] |
|
1059 | 1061 | |
|
1060 | 1062 | def gaus(self,xSamples,Amp,Mu,Sigma): |
|
1061 | 1063 | return ( Amp / ((2*numpy.pi)**0.5 * Sigma) ) * numpy.exp( -( xSamples - Mu )**2 / ( 2 * (Sigma**2) )) |
|
1062 | 1064 | |
|
1063 | 1065 | |
|
1064 | 1066 | |
|
1065 | 1067 | def Moments(self, ySamples, xSamples): |
|
1066 | 1068 | Pot = numpy.nansum( ySamples ) # Potencia, momento 0 |
|
1067 | 1069 | yNorm = ySamples / Pot |
|
1068 | 1070 | Vr = numpy.nansum( yNorm * xSamples ) # Velocidad radial, mu, corrimiento doppler, primer momento |
|
1069 | 1071 | Sigma2 = abs(numpy.nansum( yNorm * ( xSamples - Vr )**2 )) # Segundo Momento |
|
1070 | 1072 | Desv = Sigma2**0.5 # Desv. Estandar, Ancho espectral |
|
1071 | 1073 | |
|
1072 | 1074 | return numpy.array([Pot, Vr, Desv]) |
|
1073 | 1075 | |
|
1074 | 1076 | def WindEstimation(self, spc, cspc, pairsList, ChanDist, Height, noise, AbbsisaRange, dbSNR, SNRlimit): |
|
1075 | 1077 | |
|
1076 | 1078 | |
|
1077 | 1079 | |
|
1078 | 1080 | ySamples=numpy.ones([spc.shape[0],spc.shape[1]]) |
|
1079 | 1081 | phase=numpy.ones([spc.shape[0],spc.shape[1]]) |
|
1080 | 1082 | CSPCSamples=numpy.ones([spc.shape[0],spc.shape[1]],dtype=numpy.complex_) |
|
1081 | 1083 | coherence=numpy.ones([spc.shape[0],spc.shape[1]]) |
|
1082 | 1084 | PhaseSlope=numpy.zeros(spc.shape[0]) |
|
1083 | 1085 | PhaseInter=numpy.ones(spc.shape[0]) |
|
1084 | 1086 | xFrec=AbbsisaRange[0][0:spc.shape[1]] |
|
1085 | 1087 | xVel =AbbsisaRange[2][0:spc.shape[1]] |
|
1086 | 1088 | Vv=numpy.empty(spc.shape[2])*0 |
|
1087 | 1089 | SPCav = numpy.average(spc, axis=0)-numpy.average(noise) #spc[0]-noise[0]# |
|
1088 | 1090 | |
|
1089 | 1091 | SPCmoments = self.Moments(SPCav[:,Height], xVel ) |
|
1090 | 1092 | CSPCmoments = [] |
|
1091 | 1093 | cspcNoise = numpy.empty(3) |
|
1092 | 1094 | |
|
1093 | 1095 | '''Getting Eij and Nij''' |
|
1094 | 1096 | |
|
1095 |
|
|
|
1096 |
|
|
|
1097 | Xi01=ChanDist[0][0] | |
|
1098 | Eta01=ChanDist[0][1] | |
|
1097 | 1099 | |
|
1098 |
|
|
|
1099 |
|
|
|
1100 | Xi02=ChanDist[1][0] | |
|
1101 | Eta02=ChanDist[1][1] | |
|
1100 | 1102 | |
|
1101 |
|
|
|
1102 |
|
|
|
1103 | Xi12=ChanDist[2][0] | |
|
1104 | Eta12=ChanDist[2][1] | |
|
1103 | 1105 | |
|
1104 | 1106 | z = spc.copy() |
|
1105 | 1107 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1106 | 1108 | |
|
1107 | 1109 | for i in range(spc.shape[0]): |
|
1108 | 1110 | |
|
1109 | 1111 | '''****** Line of Data SPC ******''' |
|
1110 | 1112 | zline=z[i,:,Height].copy() - noise[i] # Se resta ruido |
|
1111 | 1113 | |
|
1112 | 1114 | '''****** SPC is normalized ******''' |
|
1113 | 1115 | SmoothSPC =self.moving_average(zline.copy(),N=1) # Se suaviza el ruido |
|
1114 | 1116 | FactNorm = SmoothSPC/numpy.nansum(SmoothSPC) # SPC Normalizado y suavizado |
|
1115 | 1117 | |
|
1116 | 1118 | xSamples = xFrec # Se toma el rango de frecuncias |
|
1117 | 1119 | ySamples[i] = FactNorm # Se toman los valores de SPC normalizado |
|
1118 | 1120 | |
|
1119 | 1121 | for i in range(spc.shape[0]): |
|
1120 | 1122 | |
|
1121 | 1123 | '''****** Line of Data CSPC ******''' |
|
1122 | 1124 | cspcLine = ( cspc[i,:,Height].copy())# - noise[i] ) # no! Se resta el ruido |
|
1123 | 1125 | SmoothCSPC =self.moving_average(cspcLine,N=1) # Se suaviza el ruido |
|
1124 | 1126 | cspcNorm = SmoothCSPC/numpy.nansum(SmoothCSPC) # CSPC normalizado y suavizado |
|
1125 | 1127 | |
|
1126 | 1128 | '''****** CSPC is normalized with respect to Briggs and Vincent ******''' |
|
1127 | 1129 | chan_index0 = pairsList[i][0] |
|
1128 | 1130 | chan_index1 = pairsList[i][1] |
|
1129 | 1131 | |
|
1130 | 1132 | CSPCFactor= numpy.abs(numpy.nansum(ySamples[chan_index0]))**2 * numpy.abs(numpy.nansum(ySamples[chan_index1]))**2 |
|
1131 | 1133 | CSPCNorm = cspcNorm / numpy.sqrt(CSPCFactor) |
|
1132 | 1134 | |
|
1133 | 1135 | CSPCSamples[i] = CSPCNorm |
|
1134 | 1136 | |
|
1135 | 1137 | coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor) |
|
1136 | 1138 | |
|
1137 | 1139 | #coherence[i]= self.moving_average(coherence[i],N=1) |
|
1138 | 1140 | |
|
1139 | 1141 | phase[i] = self.moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi |
|
1140 | 1142 | |
|
1141 | 1143 | CSPCmoments = numpy.vstack([self.Moments(numpy.abs(CSPCSamples[0]), xSamples), |
|
1142 | 1144 | self.Moments(numpy.abs(CSPCSamples[1]), xSamples), |
|
1143 | 1145 | self.Moments(numpy.abs(CSPCSamples[2]), xSamples)]) |
|
1144 | 1146 | |
|
1145 | 1147 | #print '##### SUMA de SPC #####', len(ySamples) |
|
1146 | 1148 | #print numpy.sum(ySamples[0]) |
|
1147 | 1149 | #print '##### SUMA de CSPC #####', len(coherence) |
|
1148 | 1150 | #print numpy.sum(numpy.abs(CSPCNorm)) |
|
1149 | 1151 | #print numpy.sum(coherence[0]) |
|
1150 | 1152 | # print 'len',len(xSamples) |
|
1151 | 1153 | # print 'CSPCmoments', numpy.shape(CSPCmoments) |
|
1152 | 1154 | # print CSPCmoments |
|
1153 | 1155 | # print '#######################' |
|
1154 | 1156 | |
|
1155 | 1157 | popt=[1e-10,0,1e-10] |
|
1156 | 1158 | popt01, popt02, popt12 = [1e-10,1e-10,1e-10], [1e-10,1e-10,1e-10] ,[1e-10,1e-10,1e-10] |
|
1157 | 1159 | FitGauss01, FitGauss02, FitGauss12 = numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0, numpy.empty(len(xSamples))*0 |
|
1158 | 1160 | |
|
1159 | 1161 | CSPCMask01 = numpy.abs(CSPCSamples[0]) |
|
1160 | 1162 | CSPCMask02 = numpy.abs(CSPCSamples[1]) |
|
1161 | 1163 | CSPCMask12 = numpy.abs(CSPCSamples[2]) |
|
1162 | 1164 | |
|
1163 | 1165 | mask01 = ~numpy.isnan(CSPCMask01) |
|
1164 | 1166 | mask02 = ~numpy.isnan(CSPCMask02) |
|
1165 | 1167 | mask12 = ~numpy.isnan(CSPCMask12) |
|
1166 | 1168 | |
|
1167 | 1169 | #mask = ~numpy.isnan(CSPCMask01) |
|
1168 | 1170 | CSPCMask01 = CSPCMask01[mask01] |
|
1169 | 1171 | CSPCMask02 = CSPCMask02[mask02] |
|
1170 | 1172 | CSPCMask12 = CSPCMask12[mask12] |
|
1171 | 1173 | #CSPCMask01 = numpy.ma.masked_invalid(CSPCMask01) |
|
1172 | 1174 | |
|
1173 | 1175 | |
|
1174 | 1176 | |
|
1175 | 1177 | '''***Fit Gauss CSPC01***''' |
|
1176 | 1178 | if dbSNR > SNRlimit and numpy.abs(SPCmoments[1])<3 : |
|
1177 | 1179 | try: |
|
1178 | 1180 | popt01,pcov = curve_fit(self.gaus,xSamples[mask01],numpy.abs(CSPCMask01),p0=CSPCmoments[0]) |
|
1179 | 1181 | popt02,pcov = curve_fit(self.gaus,xSamples[mask02],numpy.abs(CSPCMask02),p0=CSPCmoments[1]) |
|
1180 | 1182 | popt12,pcov = curve_fit(self.gaus,xSamples[mask12],numpy.abs(CSPCMask12),p0=CSPCmoments[2]) |
|
1181 | 1183 | FitGauss01 = self.gaus(xSamples,*popt01) |
|
1182 | 1184 | FitGauss02 = self.gaus(xSamples,*popt02) |
|
1183 | 1185 | FitGauss12 = self.gaus(xSamples,*popt12) |
|
1184 | 1186 | except: |
|
1185 | 1187 | FitGauss01=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[0])) |
|
1186 | 1188 | FitGauss02=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[1])) |
|
1187 | 1189 | FitGauss12=numpy.ones(len(xSamples))*numpy.mean(numpy.abs(CSPCSamples[2])) |
|
1188 | 1190 | |
|
1189 | 1191 | |
|
1190 | 1192 | CSPCopt = numpy.vstack([popt01,popt02,popt12]) |
|
1191 | 1193 | |
|
1192 | 1194 | '''****** Getting fij width ******''' |
|
1193 | 1195 | |
|
1194 | 1196 | yMean = numpy.average(ySamples, axis=0) # ySamples[0] |
|
1195 | 1197 | |
|
1196 | 1198 | '''******* Getting fitting Gaussian *******''' |
|
1197 | 1199 | meanGauss = sum(xSamples*yMean) / len(xSamples) # Mu, velocidad radial (frecuencia) |
|
1198 | 1200 | sigma2 = sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) # Varianza, Ancho espectral (frecuencia) |
|
1199 | 1201 | |
|
1200 | 1202 | yMoments = self.Moments(yMean, xSamples) |
|
1201 | 1203 | |
|
1202 | 1204 | if dbSNR > SNRlimit and numpy.abs(SPCmoments[1])<3: # and abs(meanGauss/sigma2) > 0.00001: |
|
1203 | 1205 | try: |
|
1204 | 1206 | popt,pcov = curve_fit(self.gaus,xSamples,yMean,p0=yMoments) |
|
1205 | 1207 | FitGauss=self.gaus(xSamples,*popt) |
|
1206 | 1208 | |
|
1207 | 1209 | except :#RuntimeError: |
|
1208 | 1210 | FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) |
|
1209 | 1211 | |
|
1210 | 1212 | |
|
1211 | 1213 | else: |
|
1212 | 1214 | FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) |
|
1213 | 1215 | |
|
1214 | 1216 | |
|
1215 | 1217 | |
|
1216 | 1218 | '''****** Getting Fij ******''' |
|
1217 | 1219 | Fijcspc = CSPCopt[:,2]/2*3 |
|
1218 | 1220 | |
|
1219 | 1221 | |
|
1220 | 1222 | GaussCenter = popt[1] #xFrec[GCpos] |
|
1221 | 1223 | #Punto en Eje X de la Gaussiana donde se encuentra el centro |
|
1222 | 1224 | ClosestCenter = xSamples[numpy.abs(xSamples-GaussCenter).argmin()] |
|
1223 | 1225 | PointGauCenter = numpy.where(xSamples==ClosestCenter)[0][0] |
|
1224 | 1226 | |
|
1225 | 1227 | #Punto e^-1 hubicado en la Gaussiana |
|
1226 | 1228 | PeMinus1 = numpy.max(FitGauss)* numpy.exp(-1) |
|
1227 | 1229 | FijClosest = FitGauss[numpy.abs(FitGauss-PeMinus1).argmin()] # El punto mas cercano a "Peminus1" dentro de "FitGauss" |
|
1228 | 1230 | PointFij = numpy.where(FitGauss==FijClosest)[0][0] |
|
1229 | 1231 | |
|
1230 | 1232 | if xSamples[PointFij] > xSamples[PointGauCenter]: |
|
1231 | 1233 | Fij = xSamples[PointFij] - xSamples[PointGauCenter] |
|
1232 | 1234 | |
|
1233 | 1235 | else: |
|
1234 | 1236 | Fij = xSamples[PointGauCenter] - xSamples[PointFij] |
|
1235 | 1237 | |
|
1236 | 1238 | # print 'CSPCopt' |
|
1237 | 1239 | # print CSPCopt |
|
1238 | 1240 | # print 'popt' |
|
1239 | 1241 | # print popt |
|
1240 | 1242 | # print '#######################################' |
|
1241 | 1243 | #print 'dataOut.data_param', numpy.shape(data_param) |
|
1242 | 1244 | #print 'dataOut.data_param0', data_param[0,0,Height] |
|
1243 | 1245 | #print 'dataOut.data_param1', data_param[0,1,Height] |
|
1244 | 1246 | #print 'dataOut.data_param2', data_param[0,2,Height] |
|
1245 | 1247 | |
|
1246 | 1248 | |
|
1247 | 1249 | # print 'yMoments', yMoments |
|
1248 | 1250 | # print 'Moments', SPCmoments |
|
1249 | 1251 | # print 'Fij2 Moment', Fij |
|
1250 | 1252 | # #print 'Fij', Fij, 'popt[2]/2',popt[2]/2 |
|
1251 | 1253 | # print 'Fijcspc',Fijcspc |
|
1252 | 1254 | # print '#######################################' |
|
1253 | 1255 | |
|
1254 | 1256 | |
|
1255 | 1257 | '''****** Taking frequency ranges from SPCs ******''' |
|
1256 | 1258 | |
|
1257 | 1259 | |
|
1258 | 1260 | #GaussCenter = popt[1] #Primer momento 01 |
|
1259 | 1261 | GauWidth = popt[2] *3/2 #Ancho de banda de Gau01 |
|
1260 | 1262 | Range = numpy.empty(2) |
|
1261 | 1263 | Range[0] = GaussCenter - GauWidth |
|
1262 | 1264 | Range[1] = GaussCenter + GauWidth |
|
1263 | 1265 | #Punto en Eje X de la Gaussiana donde se encuentra ancho de banda (min:max) |
|
1264 | 1266 | ClosRangeMin = xSamples[numpy.abs(xSamples-Range[0]).argmin()] |
|
1265 | 1267 | ClosRangeMax = xSamples[numpy.abs(xSamples-Range[1]).argmin()] |
|
1266 | 1268 | |
|
1267 | 1269 | PointRangeMin = numpy.where(xSamples==ClosRangeMin)[0][0] |
|
1268 | 1270 | PointRangeMax = numpy.where(xSamples==ClosRangeMax)[0][0] |
|
1269 | 1271 | |
|
1270 | 1272 | Range=numpy.array([ PointRangeMin, PointRangeMax ]) |
|
1271 | 1273 | |
|
1272 | 1274 | FrecRange = xFrec[ Range[0] : Range[1] ] |
|
1273 | 1275 | VelRange = xVel[ Range[0] : Range[1] ] |
|
1274 | 1276 | |
|
1275 | 1277 | |
|
1276 | 1278 | #print 'RANGE: ', Range |
|
1277 | 1279 | #print 'FrecRange', numpy.shape(FrecRange)#,FrecRange |
|
1278 | 1280 | #print 'len: ', len(FrecRange) |
|
1279 | 1281 | |
|
1280 | 1282 | '''****** Getting SCPC Slope ******''' |
|
1281 | 1283 | |
|
1282 | 1284 | for i in range(spc.shape[0]): |
|
1283 | 1285 | |
|
1284 | 1286 | if len(FrecRange)>5 and len(FrecRange)<spc.shape[1]*0.3: |
|
1285 | 1287 | PhaseRange=self.moving_average(phase[i,Range[0]:Range[1]],N=3) |
|
1286 | 1288 | |
|
1287 | 1289 | #print 'Ancho espectral Frecuencias', FrecRange[-1]-FrecRange[0], 'Hz' |
|
1288 | 1290 | #print 'Ancho espectral Velocidades', VelRange[-1]-VelRange[0], 'm/s' |
|
1289 | 1291 | #print 'FrecRange', len(FrecRange) , FrecRange |
|
1290 | 1292 | #print 'VelRange', len(VelRange) , VelRange |
|
1291 | 1293 | #print 'PhaseRange', numpy.shape(PhaseRange), PhaseRange |
|
1292 | 1294 | #print ' ' |
|
1293 | 1295 | |
|
1294 | 1296 | '''***********************VelRange******************''' |
|
1295 | 1297 | |
|
1296 | 1298 | mask = ~numpy.isnan(FrecRange) & ~numpy.isnan(PhaseRange) |
|
1297 | 1299 | |
|
1298 | 1300 | if len(FrecRange) == len(PhaseRange): |
|
1299 | 1301 | try: |
|
1300 | 1302 | slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange[mask], PhaseRange[mask]) |
|
1301 | 1303 | PhaseSlope[i]=slope |
|
1302 | 1304 | PhaseInter[i]=intercept |
|
1303 | 1305 | except: |
|
1304 | 1306 | PhaseSlope[i]=0 |
|
1305 | 1307 | PhaseInter[i]=0 |
|
1306 | 1308 | else: |
|
1307 | 1309 | PhaseSlope[i]=0 |
|
1308 | 1310 | PhaseInter[i]=0 |
|
1309 | 1311 | else: |
|
1310 | 1312 | PhaseSlope[i]=0 |
|
1311 | 1313 | PhaseInter[i]=0 |
|
1312 | 1314 | |
|
1313 | 1315 | |
|
1314 | 1316 | '''Getting constant C''' |
|
1315 | 1317 | cC=(Fij*numpy.pi)**2 |
|
1316 | 1318 | |
|
1317 | 1319 | '''****** Getting constants F and G ******''' |
|
1318 |
MijEijNij=numpy.array([[ |
|
|
1320 | MijEijNij=numpy.array([[Xi02,Eta02], [Xi12,Eta12]]) | |
|
1319 | 1321 | MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi) |
|
1320 | 1322 | MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi) |
|
1321 | 1323 | MijResults=numpy.array([MijResult0,MijResult1]) |
|
1322 | 1324 | (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) |
|
1323 | 1325 | |
|
1324 | 1326 | '''****** Getting constants A, B and H ******''' |
|
1325 | 1327 | W01=numpy.nanmax( FitGauss01 ) #numpy.abs(CSPCSamples[0])) |
|
1326 | 1328 | W02=numpy.nanmax( FitGauss02 ) #numpy.abs(CSPCSamples[1])) |
|
1327 | 1329 | W12=numpy.nanmax( FitGauss12 ) #numpy.abs(CSPCSamples[2])) |
|
1328 | 1330 | |
|
1329 |
WijResult0=((cF* |
|
|
1330 |
WijResult1=((cF* |
|
|
1331 |
WijResult2=((cF* |
|
|
1331 | WijResult0=((cF*Xi01+cG*Eta01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC)) | |
|
1332 | WijResult1=((cF*Xi02+cG*Eta02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC)) | |
|
1333 | WijResult2=((cF*Xi12+cG*Eta12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC)) | |
|
1332 | 1334 | |
|
1333 | 1335 | WijResults=numpy.array([WijResult0, WijResult1, WijResult2]) |
|
1334 | 1336 | |
|
1335 |
WijEijNij=numpy.array([ [ |
|
|
1337 | WijEijNij=numpy.array([ [Xi01**2, Eta01**2, 2*Xi01*Eta01] , [Xi02**2, Eta02**2, 2*Xi02*Eta02] , [Xi12**2, Eta12**2, 2*Xi12*Eta12] ]) | |
|
1336 | 1338 | (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) |
|
1337 | 1339 | |
|
1338 | 1340 | VxVy=numpy.array([[cA,cH],[cH,cB]]) |
|
1339 | 1341 | VxVyResults=numpy.array([-cF,-cG]) |
|
1340 | 1342 | (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults) |
|
1341 | 1343 | |
|
1342 | 1344 | #print 'MijResults, cC, PhaseSlope', MijResults, cC, PhaseSlope |
|
1343 | 1345 | #print 'W01,02,12', W01, W02, W12 |
|
1344 | 1346 | #print 'WijResult0,1,2',WijResult0, WijResult1, WijResult2, 'Results', WijResults |
|
1345 | 1347 | #print 'cA,cB,cH, cF, cG', cA, cB, cH, cF, cG |
|
1346 | 1348 | #print 'VxVy', VxVyResults |
|
1347 | 1349 | #print '###########################****************************************' |
|
1348 | 1350 | Vzon = Vy |
|
1349 | 1351 | Vmer = Vx |
|
1350 | 1352 | Vmag=numpy.sqrt(Vzon**2+Vmer**2) |
|
1351 | 1353 | Vang=numpy.arctan2(Vmer,Vzon) |
|
1352 | 1354 | if numpy.abs( popt[1] ) < 3.5 and len(FrecRange)>4: |
|
1353 | 1355 | Vver=popt[1] |
|
1354 | 1356 | else: |
|
1355 | 1357 | Vver=numpy.NaN |
|
1356 | 1358 | FitGaussCSPC = numpy.array([FitGauss01,FitGauss02,FitGauss12]) |
|
1357 | 1359 | |
|
1358 | 1360 | |
|
1359 | 1361 | # ''' Ploteo por altura ''' |
|
1360 | 1362 | # if Height == 28: |
|
1361 | 1363 | # for i in range(3): |
|
1362 | 1364 | # #print 'FASE', numpy.shape(phase), y[25] |
|
1363 | 1365 | # #print numpy.shape(coherence) |
|
1364 | 1366 | # fig = plt.figure(10+self.indice) |
|
1365 | 1367 | # #plt.plot( x[0:256],coherence[:,25] ) |
|
1366 | 1368 | # #cohAv = numpy.average(coherence[i],1) |
|
1367 | 1369 | # Pendiente = FrecRange * PhaseSlope[i] |
|
1368 | 1370 | # plt.plot( FrecRange, Pendiente) |
|
1369 | 1371 | # plt.plot( xFrec,phase[i]) |
|
1370 | 1372 | # |
|
1371 | 1373 | # CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0) |
|
1372 | 1374 | # #plt.plot(xFrec, FitGauss01) |
|
1373 | 1375 | # #plt.plot(xFrec, CSPCmean) |
|
1374 | 1376 | # #plt.plot(xFrec, numpy.abs(CSPCSamples[0])) |
|
1375 | 1377 | # #plt.plot(xFrec, FitGauss) |
|
1376 | 1378 | # #plt.plot(xFrec, yMean) |
|
1377 | 1379 | # #plt.plot(xFrec, numpy.abs(coherence[0])) |
|
1378 | 1380 | # |
|
1379 | 1381 | # #plt.axis([-12, 12, 15, 50]) |
|
1380 | 1382 | # #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i))) |
|
1381 | 1383 | # plt.ylabel('Desfase [rad]') |
|
1382 | 1384 | # #plt.ylabel('CSPC normalizado') |
|
1383 | 1385 | # plt.xlabel('Frec range [Hz]') |
|
1384 | 1386 | |
|
1385 | 1387 | #fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice)) |
|
1386 | 1388 | |
|
1387 | 1389 | # plt.show() |
|
1388 | 1390 | # self.indice=self.indice+1 |
|
1389 | 1391 | |
|
1390 | 1392 | |
|
1391 | 1393 | |
|
1392 | 1394 | |
|
1393 | 1395 | |
|
1394 | 1396 | # print 'vzon y vmer', Vzon, Vmer |
|
1395 | 1397 | return Vzon, Vmer, Vver, GaussCenter, PhaseSlope, FitGaussCSPC |
|
1396 | 1398 | |
|
1397 | 1399 | class SpectralMoments(Operation): |
|
1398 | 1400 | |
|
1399 | 1401 | ''' |
|
1400 | 1402 | Function SpectralMoments() |
|
1401 | 1403 | |
|
1402 | 1404 | Calculates moments (power, mean, standard deviation) and SNR of the signal |
|
1403 | 1405 | |
|
1404 | 1406 | Type of dataIn: Spectra |
|
1405 | 1407 | |
|
1406 | 1408 | Configuration Parameters: |
|
1407 | 1409 | |
|
1408 | 1410 | dirCosx : Cosine director in X axis |
|
1409 | 1411 | dirCosy : Cosine director in Y axis |
|
1410 | 1412 | |
|
1411 | 1413 | elevation : |
|
1412 | 1414 | azimuth : |
|
1413 | 1415 | |
|
1414 | 1416 | Input: |
|
1415 | 1417 | channelList : simple channel list to select e.g. [2,3,7] |
|
1416 | 1418 | self.dataOut.data_pre : Spectral data |
|
1417 | 1419 | self.dataOut.abscissaList : List of frequencies |
|
1418 | 1420 | self.dataOut.noise : Noise level per channel |
|
1419 | 1421 | |
|
1420 | 1422 | Affected: |
|
1421 | 1423 | self.dataOut.moments : Parameters per channel |
|
1422 | 1424 | self.dataOut.data_SNR : SNR per channel |
|
1423 | 1425 | |
|
1424 | 1426 | ''' |
|
1425 | 1427 | |
|
1426 | 1428 | def run(self, dataOut): |
|
1427 | 1429 | |
|
1428 | 1430 | #dataOut.data_pre = dataOut.data_pre[0] |
|
1429 | 1431 | data = dataOut.data_pre[0] |
|
1430 | 1432 | absc = dataOut.abscissaList[:-1] |
|
1431 | 1433 | noise = dataOut.noise |
|
1432 | 1434 | nChannel = data.shape[0] |
|
1433 | 1435 | data_param = numpy.zeros((nChannel, 4, data.shape[2])) |
|
1434 | 1436 | |
|
1435 | 1437 | for ind in range(nChannel): |
|
1436 | 1438 | data_param[ind,:,:] = self.__calculateMoments( data[ind,:,:] , absc , noise[ind] ) |
|
1437 | 1439 | |
|
1438 | 1440 | dataOut.moments = data_param[:,1:,:] |
|
1439 | 1441 | dataOut.data_SNR = data_param[:,0] |
|
1440 | 1442 | return |
|
1441 | 1443 | |
|
1442 | 1444 | def __calculateMoments(self, oldspec, oldfreq, n0, |
|
1443 | 1445 | nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None): |
|
1444 | 1446 | |
|
1445 | 1447 | if (nicoh == None): nicoh = 1 |
|
1446 | 1448 | if (graph == None): graph = 0 |
|
1447 | 1449 | if (smooth == None): smooth = 0 |
|
1448 | 1450 | elif (self.smooth < 3): smooth = 0 |
|
1449 | 1451 | |
|
1450 | 1452 | if (type1 == None): type1 = 0 |
|
1451 | 1453 | if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1 |
|
1452 | 1454 | if (snrth == None): snrth = -3 |
|
1453 | 1455 | if (dc == None): dc = 0 |
|
1454 | 1456 | if (aliasing == None): aliasing = 0 |
|
1455 | 1457 | if (oldfd == None): oldfd = 0 |
|
1456 | 1458 | if (wwauto == None): wwauto = 0 |
|
1457 | 1459 | |
|
1458 | 1460 | if (n0 < 1.e-20): n0 = 1.e-20 |
|
1459 | 1461 | |
|
1460 | 1462 | freq = oldfreq |
|
1461 | 1463 | vec_power = numpy.zeros(oldspec.shape[1]) |
|
1462 | 1464 | vec_fd = numpy.zeros(oldspec.shape[1]) |
|
1463 | 1465 | vec_w = numpy.zeros(oldspec.shape[1]) |
|
1464 | 1466 | vec_snr = numpy.zeros(oldspec.shape[1]) |
|
1465 | 1467 | |
|
1466 | 1468 | oldspec = numpy.ma.masked_invalid(oldspec) |
|
1467 | 1469 | |
|
1468 | 1470 | for ind in range(oldspec.shape[1]): |
|
1469 | 1471 | |
|
1470 | 1472 | spec = oldspec[:,ind] |
|
1471 | 1473 | aux = spec*fwindow |
|
1472 | 1474 | max_spec = aux.max() |
|
1473 | 1475 | m = list(aux).index(max_spec) |
|
1474 | 1476 | |
|
1475 | 1477 | #Smooth |
|
1476 | 1478 | if (smooth == 0): spec2 = spec |
|
1477 | 1479 | else: spec2 = scipy.ndimage.filters.uniform_filter1d(spec,size=smooth) |
|
1478 | 1480 | |
|
1479 | 1481 | # Calculo de Momentos |
|
1480 | 1482 | bb = spec2[range(m,spec2.size)] |
|
1481 | 1483 | bb = (bb<n0).nonzero() |
|
1482 | 1484 | bb = bb[0] |
|
1483 | 1485 | |
|
1484 | 1486 | ss = spec2[range(0,m + 1)] |
|
1485 | 1487 | ss = (ss<n0).nonzero() |
|
1486 | 1488 | ss = ss[0] |
|
1487 | 1489 | |
|
1488 | 1490 | if (bb.size == 0): |
|
1489 | 1491 | bb0 = spec.size - 1 - m |
|
1490 | 1492 | else: |
|
1491 | 1493 | bb0 = bb[0] - 1 |
|
1492 | 1494 | if (bb0 < 0): |
|
1493 | 1495 | bb0 = 0 |
|
1494 | 1496 | |
|
1495 | 1497 | if (ss.size == 0): ss1 = 1 |
|
1496 | 1498 | else: ss1 = max(ss) + 1 |
|
1497 | 1499 | |
|
1498 | 1500 | if (ss1 > m): ss1 = m |
|
1499 | 1501 | |
|
1500 | 1502 | valid = numpy.asarray(range(int(m + bb0 - ss1 + 1))) + ss1 |
|
1501 | 1503 | power = ( (spec2[valid] - n0) * fwindow[valid] ).sum() |
|
1502 | 1504 | fd = ( (spec2[valid]- n0) * freq[valid] * fwindow[valid] ).sum() / power |
|
1503 | 1505 | |
|
1504 | 1506 | w = math.sqrt(((spec2[valid] - n0)*fwindow[valid]*(freq[valid]- fd)**2).sum()/power) |
|
1505 | 1507 | snr = (spec2.mean()-n0)/n0 |
|
1506 | 1508 | |
|
1507 | 1509 | if (snr < 1.e-20) : |
|
1508 | 1510 | snr = 1.e-20 |
|
1509 | 1511 | |
|
1510 | 1512 | vec_power[ind] = power |
|
1511 | 1513 | vec_fd[ind] = fd |
|
1512 | 1514 | vec_w[ind] = w |
|
1513 | 1515 | vec_snr[ind] = snr |
|
1514 | 1516 | |
|
1515 | 1517 | moments = numpy.vstack((vec_snr, vec_power, vec_fd, vec_w)) |
|
1516 | 1518 | return moments |
|
1517 | 1519 | |
|
1518 | 1520 | #------------------ Get SA Parameters -------------------------- |
|
1519 | 1521 | |
|
1520 | 1522 | def GetSAParameters(self): |
|
1521 | 1523 | #SA en frecuencia |
|
1522 | 1524 | pairslist = self.dataOut.groupList |
|
1523 | 1525 | num_pairs = len(pairslist) |
|
1524 | 1526 | |
|
1525 | 1527 | vel = self.dataOut.abscissaList |
|
1526 | 1528 | spectra = self.dataOut.data_pre |
|
1527 | 1529 | cspectra = self.dataIn.data_cspc |
|
1528 | 1530 | delta_v = vel[1] - vel[0] |
|
1529 | 1531 | |
|
1530 | 1532 | #Calculating the power spectrum |
|
1531 | 1533 | spc_pow = numpy.sum(spectra, 3)*delta_v |
|
1532 | 1534 | #Normalizing Spectra |
|
1533 | 1535 | norm_spectra = spectra/spc_pow |
|
1534 | 1536 | #Calculating the norm_spectra at peak |
|
1535 | 1537 | max_spectra = numpy.max(norm_spectra, 3) |
|
1536 | 1538 | |
|
1537 | 1539 | #Normalizing Cross Spectra |
|
1538 | 1540 | norm_cspectra = numpy.zeros(cspectra.shape) |
|
1539 | 1541 | |
|
1540 | 1542 | for i in range(num_chan): |
|
1541 | 1543 | norm_cspectra[i,:,:] = cspectra[i,:,:]/numpy.sqrt(spc_pow[pairslist[i][0],:]*spc_pow[pairslist[i][1],:]) |
|
1542 | 1544 | |
|
1543 | 1545 | max_cspectra = numpy.max(norm_cspectra,2) |
|
1544 | 1546 | max_cspectra_index = numpy.argmax(norm_cspectra, 2) |
|
1545 | 1547 | |
|
1546 | 1548 | for i in range(num_pairs): |
|
1547 | 1549 | cspc_par[i,:,:] = __calculateMoments(norm_cspectra) |
|
1548 | 1550 | #------------------- Get Lags ---------------------------------- |
|
1549 | 1551 | |
|
1550 | 1552 | class SALags(Operation): |
|
1551 | 1553 | ''' |
|
1552 | 1554 | Function GetMoments() |
|
1553 | 1555 | |
|
1554 | 1556 | Input: |
|
1555 | 1557 | self.dataOut.data_pre |
|
1556 | 1558 | self.dataOut.abscissaList |
|
1557 | 1559 | self.dataOut.noise |
|
1558 | 1560 | self.dataOut.normFactor |
|
1559 | 1561 | self.dataOut.data_SNR |
|
1560 | 1562 | self.dataOut.groupList |
|
1561 | 1563 | self.dataOut.nChannels |
|
1562 | 1564 | |
|
1563 | 1565 | Affected: |
|
1564 | 1566 | self.dataOut.data_param |
|
1565 | 1567 | |
|
1566 | 1568 | ''' |
|
1567 | 1569 | def run(self, dataOut): |
|
1568 | 1570 | data_acf = dataOut.data_pre[0] |
|
1569 | 1571 | data_ccf = dataOut.data_pre[1] |
|
1570 | 1572 | normFactor_acf = dataOut.normFactor[0] |
|
1571 | 1573 | normFactor_ccf = dataOut.normFactor[1] |
|
1572 | 1574 | pairs_acf = dataOut.groupList[0] |
|
1573 | 1575 | pairs_ccf = dataOut.groupList[1] |
|
1574 | 1576 | |
|
1575 | 1577 | nHeights = dataOut.nHeights |
|
1576 | 1578 | absc = dataOut.abscissaList |
|
1577 | 1579 | noise = dataOut.noise |
|
1578 | 1580 | SNR = dataOut.data_SNR |
|
1579 | 1581 | nChannels = dataOut.nChannels |
|
1580 | 1582 | # pairsList = dataOut.groupList |
|
1581 | 1583 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairsList, nChannels) |
|
1582 | 1584 | |
|
1583 | 1585 | for l in range(len(pairs_acf)): |
|
1584 | 1586 | data_acf[l,:,:] = data_acf[l,:,:]/normFactor_acf[l,:] |
|
1585 | 1587 | |
|
1586 | 1588 | for l in range(len(pairs_ccf)): |
|
1587 | 1589 | data_ccf[l,:,:] = data_ccf[l,:,:]/normFactor_ccf[l,:] |
|
1588 | 1590 | |
|
1589 | 1591 | dataOut.data_param = numpy.zeros((len(pairs_ccf)*2 + 1, nHeights)) |
|
1590 | 1592 | dataOut.data_param[:-1,:] = self.__calculateTaus(data_acf, data_ccf, absc) |
|
1591 | 1593 | dataOut.data_param[-1,:] = self.__calculateLag1Phase(data_acf, absc) |
|
1592 | 1594 | return |
|
1593 | 1595 | |
|
1594 | 1596 | # def __getPairsAutoCorr(self, pairsList, nChannels): |
|
1595 | 1597 | # |
|
1596 | 1598 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan |
|
1597 | 1599 | # |
|
1598 | 1600 | # for l in range(len(pairsList)): |
|
1599 | 1601 | # firstChannel = pairsList[l][0] |
|
1600 | 1602 | # secondChannel = pairsList[l][1] |
|
1601 | 1603 | # |
|
1602 | 1604 | # #Obteniendo pares de Autocorrelacion |
|
1603 | 1605 | # if firstChannel == secondChannel: |
|
1604 | 1606 | # pairsAutoCorr[firstChannel] = int(l) |
|
1605 | 1607 | # |
|
1606 | 1608 | # pairsAutoCorr = pairsAutoCorr.astype(int) |
|
1607 | 1609 | # |
|
1608 | 1610 | # pairsCrossCorr = range(len(pairsList)) |
|
1609 | 1611 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) |
|
1610 | 1612 | # |
|
1611 | 1613 | # return pairsAutoCorr, pairsCrossCorr |
|
1612 | 1614 | |
|
1613 | 1615 | def __calculateTaus(self, data_acf, data_ccf, lagRange): |
|
1614 | 1616 | |
|
1615 | 1617 | lag0 = data_acf.shape[1]/2 |
|
1616 | 1618 | #Funcion de Autocorrelacion |
|
1617 | 1619 | mean_acf = stats.nanmean(data_acf, axis = 0) |
|
1618 | 1620 | |
|
1619 | 1621 | #Obtencion Indice de TauCross |
|
1620 | 1622 | ind_ccf = data_ccf.argmax(axis = 1) |
|
1621 | 1623 | #Obtencion Indice de TauAuto |
|
1622 | 1624 | ind_acf = numpy.zeros(ind_ccf.shape,dtype = 'int') |
|
1623 | 1625 | ccf_lag0 = data_ccf[:,lag0,:] |
|
1624 | 1626 | |
|
1625 | 1627 | for i in range(ccf_lag0.shape[0]): |
|
1626 | 1628 | ind_acf[i,:] = numpy.abs(mean_acf - ccf_lag0[i,:]).argmin(axis = 0) |
|
1627 | 1629 | |
|
1628 | 1630 | #Obtencion de TauCross y TauAuto |
|
1629 | 1631 | tau_ccf = lagRange[ind_ccf] |
|
1630 | 1632 | tau_acf = lagRange[ind_acf] |
|
1631 | 1633 | |
|
1632 | 1634 | Nan1, Nan2 = numpy.where(tau_ccf == lagRange[0]) |
|
1633 | 1635 | |
|
1634 | 1636 | tau_ccf[Nan1,Nan2] = numpy.nan |
|
1635 | 1637 | tau_acf[Nan1,Nan2] = numpy.nan |
|
1636 | 1638 | tau = numpy.vstack((tau_ccf,tau_acf)) |
|
1637 | 1639 | |
|
1638 | 1640 | return tau |
|
1639 | 1641 | |
|
1640 | 1642 | def __calculateLag1Phase(self, data, lagTRange): |
|
1641 | 1643 | data1 = stats.nanmean(data, axis = 0) |
|
1642 | 1644 | lag1 = numpy.where(lagTRange == 0)[0][0] + 1 |
|
1643 | 1645 | |
|
1644 | 1646 | phase = numpy.angle(data1[lag1,:]) |
|
1645 | 1647 | |
|
1646 | 1648 | return phase |
|
1647 | 1649 | |
|
1648 | 1650 | class SpectralFitting(Operation): |
|
1649 | 1651 | ''' |
|
1650 | 1652 | Function GetMoments() |
|
1651 | 1653 | |
|
1652 | 1654 | Input: |
|
1653 | 1655 | Output: |
|
1654 | 1656 | Variables modified: |
|
1655 | 1657 | ''' |
|
1656 | 1658 | |
|
1657 | 1659 | def run(self, dataOut, getSNR = True, path=None, file=None, groupList=None): |
|
1658 | 1660 | |
|
1659 | 1661 | |
|
1660 | 1662 | if path != None: |
|
1661 | 1663 | sys.path.append(path) |
|
1662 | 1664 | self.dataOut.library = importlib.import_module(file) |
|
1663 | 1665 | |
|
1664 | 1666 | #To be inserted as a parameter |
|
1665 | 1667 | groupArray = numpy.array(groupList) |
|
1666 | 1668 | # groupArray = numpy.array([[0,1],[2,3]]) |
|
1667 | 1669 | self.dataOut.groupList = groupArray |
|
1668 | 1670 | |
|
1669 | 1671 | nGroups = groupArray.shape[0] |
|
1670 | 1672 | nChannels = self.dataIn.nChannels |
|
1671 | 1673 | nHeights=self.dataIn.heightList.size |
|
1672 | 1674 | |
|
1673 | 1675 | #Parameters Array |
|
1674 | 1676 | self.dataOut.data_param = None |
|
1675 | 1677 | |
|
1676 | 1678 | #Set constants |
|
1677 | 1679 | constants = self.dataOut.library.setConstants(self.dataIn) |
|
1678 | 1680 | self.dataOut.constants = constants |
|
1679 | 1681 | M = self.dataIn.normFactor |
|
1680 | 1682 | N = self.dataIn.nFFTPoints |
|
1681 | 1683 | ippSeconds = self.dataIn.ippSeconds |
|
1682 | 1684 | K = self.dataIn.nIncohInt |
|
1683 | 1685 | pairsArray = numpy.array(self.dataIn.pairsList) |
|
1684 | 1686 | |
|
1685 | 1687 | #List of possible combinations |
|
1686 | 1688 | listComb = itertools.combinations(numpy.arange(groupArray.shape[1]),2) |
|
1687 | 1689 | indCross = numpy.zeros(len(list(listComb)), dtype = 'int') |
|
1688 | 1690 | |
|
1689 | 1691 | if getSNR: |
|
1690 | 1692 | listChannels = groupArray.reshape((groupArray.size)) |
|
1691 | 1693 | listChannels.sort() |
|
1692 | 1694 | noise = self.dataIn.getNoise() |
|
1693 | 1695 | self.dataOut.data_SNR = self.__getSNR(self.dataIn.data_spc[listChannels,:,:], noise[listChannels]) |
|
1694 | 1696 | |
|
1695 | 1697 | for i in range(nGroups): |
|
1696 | 1698 | coord = groupArray[i,:] |
|
1697 | 1699 | |
|
1698 | 1700 | #Input data array |
|
1699 | 1701 | data = self.dataIn.data_spc[coord,:,:]/(M*N) |
|
1700 | 1702 | data = data.reshape((data.shape[0]*data.shape[1],data.shape[2])) |
|
1701 | 1703 | |
|
1702 | 1704 | #Cross Spectra data array for Covariance Matrixes |
|
1703 | 1705 | ind = 0 |
|
1704 | 1706 | for pairs in listComb: |
|
1705 | 1707 | pairsSel = numpy.array([coord[x],coord[y]]) |
|
1706 | 1708 | indCross[ind] = int(numpy.where(numpy.all(pairsArray == pairsSel, axis = 1))[0][0]) |
|
1707 | 1709 | ind += 1 |
|
1708 | 1710 | dataCross = self.dataIn.data_cspc[indCross,:,:]/(M*N) |
|
1709 | 1711 | dataCross = dataCross**2/K |
|
1710 | 1712 | |
|
1711 | 1713 | for h in range(nHeights): |
|
1712 | 1714 | # print self.dataOut.heightList[h] |
|
1713 | 1715 | |
|
1714 | 1716 | #Input |
|
1715 | 1717 | d = data[:,h] |
|
1716 | 1718 | |
|
1717 | 1719 | #Covariance Matrix |
|
1718 | 1720 | D = numpy.diag(d**2/K) |
|
1719 | 1721 | ind = 0 |
|
1720 | 1722 | for pairs in listComb: |
|
1721 | 1723 | #Coordinates in Covariance Matrix |
|
1722 | 1724 | x = pairs[0] |
|
1723 | 1725 | y = pairs[1] |
|
1724 | 1726 | #Channel Index |
|
1725 | 1727 | S12 = dataCross[ind,:,h] |
|
1726 | 1728 | D12 = numpy.diag(S12) |
|
1727 | 1729 | #Completing Covariance Matrix with Cross Spectras |
|
1728 | 1730 | D[x*N:(x+1)*N,y*N:(y+1)*N] = D12 |
|
1729 | 1731 | D[y*N:(y+1)*N,x*N:(x+1)*N] = D12 |
|
1730 | 1732 | ind += 1 |
|
1731 | 1733 | Dinv=numpy.linalg.inv(D) |
|
1732 | 1734 | L=numpy.linalg.cholesky(Dinv) |
|
1733 | 1735 | LT=L.T |
|
1734 | 1736 | |
|
1735 | 1737 | dp = numpy.dot(LT,d) |
|
1736 | 1738 | |
|
1737 | 1739 | #Initial values |
|
1738 | 1740 | data_spc = self.dataIn.data_spc[coord,:,h] |
|
1739 | 1741 | |
|
1740 | 1742 | if (h>0)and(error1[3]<5): |
|
1741 | 1743 | p0 = self.dataOut.data_param[i,:,h-1] |
|
1742 | 1744 | else: |
|
1743 | 1745 | p0 = numpy.array(self.dataOut.library.initialValuesFunction(data_spc, constants, i)) |
|
1744 | 1746 | |
|
1745 | 1747 | try: |
|
1746 | 1748 | #Least Squares |
|
1747 | 1749 | minp,covp,infodict,mesg,ier = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants),full_output=True) |
|
1748 | 1750 | # minp,covp = optimize.leastsq(self.__residFunction,p0,args=(dp,LT,constants)) |
|
1749 | 1751 | #Chi square error |
|
1750 | 1752 | error0 = numpy.sum(infodict['fvec']**2)/(2*N) |
|
1751 | 1753 | #Error with Jacobian |
|
1752 | 1754 | error1 = self.dataOut.library.errorFunction(minp,constants,LT) |
|
1753 | 1755 | except: |
|
1754 | 1756 | minp = p0*numpy.nan |
|
1755 | 1757 | error0 = numpy.nan |
|
1756 | 1758 | error1 = p0*numpy.nan |
|
1757 | 1759 | |
|
1758 | 1760 | #Save |
|
1759 | 1761 | if self.dataOut.data_param == None: |
|
1760 | 1762 | self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan |
|
1761 | 1763 | self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan |
|
1762 | 1764 | |
|
1763 | 1765 | self.dataOut.data_error[i,:,h] = numpy.hstack((error0,error1)) |
|
1764 | 1766 | self.dataOut.data_param[i,:,h] = minp |
|
1765 | 1767 | return |
|
1766 | 1768 | |
|
1767 | 1769 | def __residFunction(self, p, dp, LT, constants): |
|
1768 | 1770 | |
|
1769 | 1771 | fm = self.dataOut.library.modelFunction(p, constants) |
|
1770 | 1772 | fmp=numpy.dot(LT,fm) |
|
1771 | 1773 | |
|
1772 | 1774 | return dp-fmp |
|
1773 | 1775 | |
|
1774 | 1776 | def __getSNR(self, z, noise): |
|
1775 | 1777 | |
|
1776 | 1778 | avg = numpy.average(z, axis=1) |
|
1777 | 1779 | SNR = (avg.T-noise)/noise |
|
1778 | 1780 | SNR = SNR.T |
|
1779 | 1781 | return SNR |
|
1780 | 1782 | |
|
1781 | 1783 | def __chisq(p,chindex,hindex): |
|
1782 | 1784 | #similar to Resid but calculates CHI**2 |
|
1783 | 1785 | [LT,d,fm]=setupLTdfm(p,chindex,hindex) |
|
1784 | 1786 | dp=numpy.dot(LT,d) |
|
1785 | 1787 | fmp=numpy.dot(LT,fm) |
|
1786 | 1788 | chisq=numpy.dot((dp-fmp).T,(dp-fmp)) |
|
1787 | 1789 | return chisq |
|
1788 | 1790 | |
|
1789 | 1791 | class WindProfiler(Operation): |
|
1790 | 1792 | |
|
1791 | 1793 | __isConfig = False |
|
1792 | 1794 | |
|
1793 | 1795 | __initime = None |
|
1794 | 1796 | __lastdatatime = None |
|
1795 | 1797 | __integrationtime = None |
|
1796 | 1798 | |
|
1797 | 1799 | __buffer = None |
|
1798 | 1800 | |
|
1799 | 1801 | __dataReady = False |
|
1800 | 1802 | |
|
1801 | 1803 | __firstdata = None |
|
1802 | 1804 | |
|
1803 | 1805 | n = None |
|
1804 | 1806 | |
|
1805 | 1807 | def __init__(self, **kwargs): |
|
1806 | 1808 | Operation.__init__(self, **kwargs) |
|
1807 | 1809 | |
|
1808 | 1810 | def __calculateCosDir(self, elev, azim): |
|
1809 | 1811 | zen = (90 - elev)*numpy.pi/180 |
|
1810 | 1812 | azim = azim*numpy.pi/180 |
|
1811 | 1813 | cosDirX = numpy.sqrt((1-numpy.cos(zen)**2)/((1+numpy.tan(azim)**2))) |
|
1812 | 1814 | cosDirY = numpy.sqrt(1-numpy.cos(zen)**2-cosDirX**2) |
|
1813 | 1815 | |
|
1814 | 1816 | signX = numpy.sign(numpy.cos(azim)) |
|
1815 | 1817 | signY = numpy.sign(numpy.sin(azim)) |
|
1816 | 1818 | |
|
1817 | 1819 | cosDirX = numpy.copysign(cosDirX, signX) |
|
1818 | 1820 | cosDirY = numpy.copysign(cosDirY, signY) |
|
1819 | 1821 | return cosDirX, cosDirY |
|
1820 | 1822 | |
|
1821 | 1823 | def __calculateAngles(self, theta_x, theta_y, azimuth): |
|
1822 | 1824 | |
|
1823 | 1825 | dir_cosw = numpy.sqrt(1-theta_x**2-theta_y**2) |
|
1824 | 1826 | zenith_arr = numpy.arccos(dir_cosw) |
|
1825 | 1827 | azimuth_arr = numpy.arctan2(theta_x,theta_y) + azimuth*math.pi/180 |
|
1826 | 1828 | |
|
1827 | 1829 | dir_cosu = numpy.sin(azimuth_arr)*numpy.sin(zenith_arr) |
|
1828 | 1830 | dir_cosv = numpy.cos(azimuth_arr)*numpy.sin(zenith_arr) |
|
1829 | 1831 | |
|
1830 | 1832 | return azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw |
|
1831 | 1833 | |
|
1832 | 1834 | def __calculateMatA(self, dir_cosu, dir_cosv, dir_cosw, horOnly): |
|
1833 | 1835 | |
|
1834 | 1836 | # |
|
1835 | 1837 | if horOnly: |
|
1836 | 1838 | A = numpy.c_[dir_cosu,dir_cosv] |
|
1837 | 1839 | else: |
|
1838 | 1840 | A = numpy.c_[dir_cosu,dir_cosv,dir_cosw] |
|
1839 | 1841 | A = numpy.asmatrix(A) |
|
1840 | 1842 | A1 = numpy.linalg.inv(A.transpose()*A)*A.transpose() |
|
1841 | 1843 | |
|
1842 | 1844 | return A1 |
|
1843 | 1845 | |
|
1844 | 1846 | def __correctValues(self, heiRang, phi, velRadial, SNR): |
|
1845 | 1847 | listPhi = phi.tolist() |
|
1846 | 1848 | maxid = listPhi.index(max(listPhi)) |
|
1847 | 1849 | minid = listPhi.index(min(listPhi)) |
|
1848 | 1850 | |
|
1849 | 1851 | rango = range(len(phi)) |
|
1850 | 1852 | # rango = numpy.delete(rango,maxid) |
|
1851 | 1853 | |
|
1852 | 1854 | heiRang1 = heiRang*math.cos(phi[maxid]) |
|
1853 | 1855 | heiRangAux = heiRang*math.cos(phi[minid]) |
|
1854 | 1856 | indOut = (heiRang1 < heiRangAux[0]).nonzero() |
|
1855 | 1857 | heiRang1 = numpy.delete(heiRang1,indOut) |
|
1856 | 1858 | |
|
1857 | 1859 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
1858 | 1860 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
1859 | 1861 | |
|
1860 | 1862 | for i in rango: |
|
1861 | 1863 | x = heiRang*math.cos(phi[i]) |
|
1862 | 1864 | y1 = velRadial[i,:] |
|
1863 | 1865 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') |
|
1864 | 1866 | |
|
1865 | 1867 | x1 = heiRang1 |
|
1866 | 1868 | y11 = f1(x1) |
|
1867 | 1869 | |
|
1868 | 1870 | y2 = SNR[i,:] |
|
1869 | 1871 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') |
|
1870 | 1872 | y21 = f2(x1) |
|
1871 | 1873 | |
|
1872 | 1874 | velRadial1[i,:] = y11 |
|
1873 | 1875 | SNR1[i,:] = y21 |
|
1874 | 1876 | |
|
1875 | 1877 | return heiRang1, velRadial1, SNR1 |
|
1876 | 1878 | |
|
1877 | 1879 | def __calculateVelUVW(self, A, velRadial): |
|
1878 | 1880 | |
|
1879 | 1881 | #Operacion Matricial |
|
1880 | 1882 | # velUVW = numpy.zeros((velRadial.shape[1],3)) |
|
1881 | 1883 | # for ind in range(velRadial.shape[1]): |
|
1882 | 1884 | # velUVW[ind,:] = numpy.dot(A,velRadial[:,ind]) |
|
1883 | 1885 | # velUVW = velUVW.transpose() |
|
1884 | 1886 | velUVW = numpy.zeros((A.shape[0],velRadial.shape[1])) |
|
1885 | 1887 | velUVW[:,:] = numpy.dot(A,velRadial) |
|
1886 | 1888 | |
|
1887 | 1889 | |
|
1888 | 1890 | return velUVW |
|
1889 | 1891 | |
|
1890 | 1892 | # def techniqueDBS(self, velRadial0, dirCosx, disrCosy, azimuth, correct, horizontalOnly, heiRang, SNR0): |
|
1891 | 1893 | |
|
1892 | 1894 | def techniqueDBS(self, kwargs): |
|
1893 | 1895 | """ |
|
1894 | 1896 | Function that implements Doppler Beam Swinging (DBS) technique. |
|
1895 | 1897 | |
|
1896 | 1898 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, |
|
1897 | 1899 | Direction correction (if necessary), Ranges and SNR |
|
1898 | 1900 | |
|
1899 | 1901 | Output: Winds estimation (Zonal, Meridional and Vertical) |
|
1900 | 1902 | |
|
1901 | 1903 | Parameters affected: Winds, height range, SNR |
|
1902 | 1904 | """ |
|
1903 | 1905 | velRadial0 = kwargs['velRadial'] |
|
1904 | 1906 | heiRang = kwargs['heightList'] |
|
1905 | 1907 | SNR0 = kwargs['SNR'] |
|
1906 | 1908 | |
|
1907 | 1909 | if kwargs.has_key('dirCosx') and kwargs.has_key('dirCosy'): |
|
1908 | 1910 | theta_x = numpy.array(kwargs['dirCosx']) |
|
1909 | 1911 | theta_y = numpy.array(kwargs['dirCosy']) |
|
1910 | 1912 | else: |
|
1911 | 1913 | elev = numpy.array(kwargs['elevation']) |
|
1912 | 1914 | azim = numpy.array(kwargs['azimuth']) |
|
1913 | 1915 | theta_x, theta_y = self.__calculateCosDir(elev, azim) |
|
1914 | 1916 | azimuth = kwargs['correctAzimuth'] |
|
1915 | 1917 | if kwargs.has_key('horizontalOnly'): |
|
1916 | 1918 | horizontalOnly = kwargs['horizontalOnly'] |
|
1917 | 1919 | else: horizontalOnly = False |
|
1918 | 1920 | if kwargs.has_key('correctFactor'): |
|
1919 | 1921 | correctFactor = kwargs['correctFactor'] |
|
1920 | 1922 | else: correctFactor = 1 |
|
1921 | 1923 | if kwargs.has_key('channelList'): |
|
1922 | 1924 | channelList = kwargs['channelList'] |
|
1923 | 1925 | if len(channelList) == 2: |
|
1924 | 1926 | horizontalOnly = True |
|
1925 | 1927 | arrayChannel = numpy.array(channelList) |
|
1926 | 1928 | param = param[arrayChannel,:,:] |
|
1927 | 1929 | theta_x = theta_x[arrayChannel] |
|
1928 | 1930 | theta_y = theta_y[arrayChannel] |
|
1929 | 1931 | |
|
1930 | 1932 | azimuth_arr, zenith_arr, dir_cosu, dir_cosv, dir_cosw = self.__calculateAngles(theta_x, theta_y, azimuth) |
|
1931 | 1933 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, zenith_arr, correctFactor*velRadial0, SNR0) |
|
1932 | 1934 | A = self.__calculateMatA(dir_cosu, dir_cosv, dir_cosw, horizontalOnly) |
|
1933 | 1935 | |
|
1934 | 1936 | #Calculo de Componentes de la velocidad con DBS |
|
1935 | 1937 | winds = self.__calculateVelUVW(A,velRadial1) |
|
1936 | 1938 | |
|
1937 | 1939 | return winds, heiRang1, SNR1 |
|
1938 | 1940 | |
|
1939 | 1941 | def __calculateDistance(self, posx, posy, pairs_ccf, azimuth = None): |
|
1940 | 1942 | |
|
1941 | 1943 | nPairs = len(pairs_ccf) |
|
1942 | 1944 | posx = numpy.asarray(posx) |
|
1943 | 1945 | posy = numpy.asarray(posy) |
|
1944 | 1946 | |
|
1945 | 1947 | #Rotacion Inversa para alinear con el azimuth |
|
1946 | 1948 | if azimuth!= None: |
|
1947 | 1949 | azimuth = azimuth*math.pi/180 |
|
1948 | 1950 | posx1 = posx*math.cos(azimuth) + posy*math.sin(azimuth) |
|
1949 | 1951 | posy1 = -posx*math.sin(azimuth) + posy*math.cos(azimuth) |
|
1950 | 1952 | else: |
|
1951 | 1953 | posx1 = posx |
|
1952 | 1954 | posy1 = posy |
|
1953 | 1955 | |
|
1954 | 1956 | #Calculo de Distancias |
|
1955 | 1957 | distx = numpy.zeros(nPairs) |
|
1956 | 1958 | disty = numpy.zeros(nPairs) |
|
1957 | 1959 | dist = numpy.zeros(nPairs) |
|
1958 | 1960 | ang = numpy.zeros(nPairs) |
|
1959 | 1961 | |
|
1960 | 1962 | for i in range(nPairs): |
|
1961 | 1963 | distx[i] = posx1[pairs_ccf[i][1]] - posx1[pairs_ccf[i][0]] |
|
1962 | 1964 | disty[i] = posy1[pairs_ccf[i][1]] - posy1[pairs_ccf[i][0]] |
|
1963 | 1965 | dist[i] = numpy.sqrt(distx[i]**2 + disty[i]**2) |
|
1964 | 1966 | ang[i] = numpy.arctan2(disty[i],distx[i]) |
|
1965 | 1967 | |
|
1966 | 1968 | return distx, disty, dist, ang |
|
1967 | 1969 | #Calculo de Matrices |
|
1968 | 1970 | # nPairs = len(pairs) |
|
1969 | 1971 | # ang1 = numpy.zeros((nPairs, 2, 1)) |
|
1970 | 1972 | # dist1 = numpy.zeros((nPairs, 2, 1)) |
|
1971 | 1973 | # |
|
1972 | 1974 | # for j in range(nPairs): |
|
1973 | 1975 | # dist1[j,0,0] = dist[pairs[j][0]] |
|
1974 | 1976 | # dist1[j,1,0] = dist[pairs[j][1]] |
|
1975 | 1977 | # ang1[j,0,0] = ang[pairs[j][0]] |
|
1976 | 1978 | # ang1[j,1,0] = ang[pairs[j][1]] |
|
1977 | 1979 | # |
|
1978 | 1980 | # return distx,disty, dist1,ang1 |
|
1979 | 1981 | |
|
1980 | 1982 | |
|
1981 | 1983 | def __calculateVelVer(self, phase, lagTRange, _lambda): |
|
1982 | 1984 | |
|
1983 | 1985 | Ts = lagTRange[1] - lagTRange[0] |
|
1984 | 1986 | velW = -_lambda*phase/(4*math.pi*Ts) |
|
1985 | 1987 | |
|
1986 | 1988 | return velW |
|
1987 | 1989 | |
|
1988 | 1990 | def __calculateVelHorDir(self, dist, tau1, tau2, ang): |
|
1989 | 1991 | nPairs = tau1.shape[0] |
|
1990 | 1992 | nHeights = tau1.shape[1] |
|
1991 | 1993 | vel = numpy.zeros((nPairs,3,nHeights)) |
|
1992 | 1994 | dist1 = numpy.reshape(dist, (dist.size,1)) |
|
1993 | 1995 | |
|
1994 | 1996 | angCos = numpy.cos(ang) |
|
1995 | 1997 | angSin = numpy.sin(ang) |
|
1996 | 1998 | |
|
1997 | 1999 | vel0 = dist1*tau1/(2*tau2**2) |
|
1998 | 2000 | vel[:,0,:] = (vel0*angCos).sum(axis = 1) |
|
1999 | 2001 | vel[:,1,:] = (vel0*angSin).sum(axis = 1) |
|
2000 | 2002 | |
|
2001 | 2003 | ind = numpy.where(numpy.isinf(vel)) |
|
2002 | 2004 | vel[ind] = numpy.nan |
|
2003 | 2005 | |
|
2004 | 2006 | return vel |
|
2005 | 2007 | |
|
2006 | 2008 | # def __getPairsAutoCorr(self, pairsList, nChannels): |
|
2007 | 2009 | # |
|
2008 | 2010 | # pairsAutoCorr = numpy.zeros(nChannels, dtype = 'int')*numpy.nan |
|
2009 | 2011 | # |
|
2010 | 2012 | # for l in range(len(pairsList)): |
|
2011 | 2013 | # firstChannel = pairsList[l][0] |
|
2012 | 2014 | # secondChannel = pairsList[l][1] |
|
2013 | 2015 | # |
|
2014 | 2016 | # #Obteniendo pares de Autocorrelacion |
|
2015 | 2017 | # if firstChannel == secondChannel: |
|
2016 | 2018 | # pairsAutoCorr[firstChannel] = int(l) |
|
2017 | 2019 | # |
|
2018 | 2020 | # pairsAutoCorr = pairsAutoCorr.astype(int) |
|
2019 | 2021 | # |
|
2020 | 2022 | # pairsCrossCorr = range(len(pairsList)) |
|
2021 | 2023 | # pairsCrossCorr = numpy.delete(pairsCrossCorr,pairsAutoCorr) |
|
2022 | 2024 | # |
|
2023 | 2025 | # return pairsAutoCorr, pairsCrossCorr |
|
2024 | 2026 | |
|
2025 | 2027 | # def techniqueSA(self, pairsSelected, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, lagTRange, correctFactor): |
|
2026 | 2028 | def techniqueSA(self, kwargs): |
|
2027 | 2029 | |
|
2028 | 2030 | """ |
|
2029 | 2031 | Function that implements Spaced Antenna (SA) technique. |
|
2030 | 2032 | |
|
2031 | 2033 | Input: Radial velocities, Direction cosines (x and y) of the Beam, Antenna azimuth, |
|
2032 | 2034 | Direction correction (if necessary), Ranges and SNR |
|
2033 | 2035 | |
|
2034 | 2036 | Output: Winds estimation (Zonal, Meridional and Vertical) |
|
2035 | 2037 | |
|
2036 | 2038 | Parameters affected: Winds |
|
2037 | 2039 | """ |
|
2038 | 2040 | position_x = kwargs['positionX'] |
|
2039 | 2041 | position_y = kwargs['positionY'] |
|
2040 | 2042 | azimuth = kwargs['azimuth'] |
|
2041 | 2043 | |
|
2042 | 2044 | if kwargs.has_key('correctFactor'): |
|
2043 | 2045 | correctFactor = kwargs['correctFactor'] |
|
2044 | 2046 | else: |
|
2045 | 2047 | correctFactor = 1 |
|
2046 | 2048 | |
|
2047 | 2049 | groupList = kwargs['groupList'] |
|
2048 | 2050 | pairs_ccf = groupList[1] |
|
2049 | 2051 | tau = kwargs['tau'] |
|
2050 | 2052 | _lambda = kwargs['_lambda'] |
|
2051 | 2053 | |
|
2052 | 2054 | #Cross Correlation pairs obtained |
|
2053 | 2055 | # pairsAutoCorr, pairsCrossCorr = self.__getPairsAutoCorr(pairssList, nChannels) |
|
2054 | 2056 | # pairsArray = numpy.array(pairsList)[pairsCrossCorr] |
|
2055 | 2057 | # pairsSelArray = numpy.array(pairsSelected) |
|
2056 | 2058 | # pairs = [] |
|
2057 | 2059 | # |
|
2058 | 2060 | # #Wind estimation pairs obtained |
|
2059 | 2061 | # for i in range(pairsSelArray.shape[0]/2): |
|
2060 | 2062 | # ind1 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i], axis = 1))[0][0] |
|
2061 | 2063 | # ind2 = numpy.where(numpy.all(pairsArray == pairsSelArray[2*i + 1], axis = 1))[0][0] |
|
2062 | 2064 | # pairs.append((ind1,ind2)) |
|
2063 | 2065 | |
|
2064 | 2066 | indtau = tau.shape[0]/2 |
|
2065 | 2067 | tau1 = tau[:indtau,:] |
|
2066 | 2068 | tau2 = tau[indtau:-1,:] |
|
2067 | 2069 | # tau1 = tau1[pairs,:] |
|
2068 | 2070 | # tau2 = tau2[pairs,:] |
|
2069 | 2071 | phase1 = tau[-1,:] |
|
2070 | 2072 | |
|
2071 | 2073 | #--------------------------------------------------------------------- |
|
2072 | 2074 | #Metodo Directo |
|
2073 | 2075 | distx, disty, dist, ang = self.__calculateDistance(position_x, position_y, pairs_ccf,azimuth) |
|
2074 | 2076 | winds = self.__calculateVelHorDir(dist, tau1, tau2, ang) |
|
2075 | 2077 | winds = stats.nanmean(winds, axis=0) |
|
2076 | 2078 | #--------------------------------------------------------------------- |
|
2077 | 2079 | #Metodo General |
|
2078 | 2080 | # distx, disty, dist = self.calculateDistance(position_x,position_y,pairsCrossCorr, pairsList, azimuth) |
|
2079 | 2081 | # #Calculo Coeficientes de Funcion de Correlacion |
|
2080 | 2082 | # F,G,A,B,H = self.calculateCoef(tau1,tau2,distx,disty,n) |
|
2081 | 2083 | # #Calculo de Velocidades |
|
2082 | 2084 | # winds = self.calculateVelUV(F,G,A,B,H) |
|
2083 | 2085 | |
|
2084 | 2086 | #--------------------------------------------------------------------- |
|
2085 | 2087 | winds[2,:] = self.__calculateVelVer(phase1, lagTRange, _lambda) |
|
2086 | 2088 | winds = correctFactor*winds |
|
2087 | 2089 | return winds |
|
2088 | 2090 | |
|
2089 | 2091 | def __checkTime(self, currentTime, paramInterval, outputInterval): |
|
2090 | 2092 | |
|
2091 | 2093 | dataTime = currentTime + paramInterval |
|
2092 | 2094 | deltaTime = dataTime - self.__initime |
|
2093 | 2095 | |
|
2094 | 2096 | if deltaTime >= outputInterval or deltaTime < 0: |
|
2095 | 2097 | self.__dataReady = True |
|
2096 | 2098 | return |
|
2097 | 2099 | |
|
2098 | 2100 | def techniqueMeteors(self, arrayMeteor, meteorThresh, heightMin, heightMax): |
|
2099 | 2101 | ''' |
|
2100 | 2102 | Function that implements winds estimation technique with detected meteors. |
|
2101 | 2103 | |
|
2102 | 2104 | Input: Detected meteors, Minimum meteor quantity to wind estimation |
|
2103 | 2105 | |
|
2104 | 2106 | Output: Winds estimation (Zonal and Meridional) |
|
2105 | 2107 | |
|
2106 | 2108 | Parameters affected: Winds |
|
2107 | 2109 | ''' |
|
2108 | 2110 | # print arrayMeteor.shape |
|
2109 | 2111 | #Settings |
|
2110 | 2112 | nInt = (heightMax - heightMin)/2 |
|
2111 | 2113 | # print nInt |
|
2112 | 2114 | nInt = int(nInt) |
|
2113 | 2115 | # print nInt |
|
2114 | 2116 | winds = numpy.zeros((2,nInt))*numpy.nan |
|
2115 | 2117 | |
|
2116 | 2118 | #Filter errors |
|
2117 | 2119 | error = numpy.where(arrayMeteor[:,-1] == 0)[0] |
|
2118 | 2120 | finalMeteor = arrayMeteor[error,:] |
|
2119 | 2121 | |
|
2120 | 2122 | #Meteor Histogram |
|
2121 | 2123 | finalHeights = finalMeteor[:,2] |
|
2122 | 2124 | hist = numpy.histogram(finalHeights, bins = nInt, range = (heightMin,heightMax)) |
|
2123 | 2125 | nMeteorsPerI = hist[0] |
|
2124 | 2126 | heightPerI = hist[1] |
|
2125 | 2127 | |
|
2126 | 2128 | #Sort of meteors |
|
2127 | 2129 | indSort = finalHeights.argsort() |
|
2128 | 2130 | finalMeteor2 = finalMeteor[indSort,:] |
|
2129 | 2131 | |
|
2130 | 2132 | # Calculating winds |
|
2131 | 2133 | ind1 = 0 |
|
2132 | 2134 | ind2 = 0 |
|
2133 | 2135 | |
|
2134 | 2136 | for i in range(nInt): |
|
2135 | 2137 | nMet = nMeteorsPerI[i] |
|
2136 | 2138 | ind1 = ind2 |
|
2137 | 2139 | ind2 = ind1 + nMet |
|
2138 | 2140 | |
|
2139 | 2141 | meteorAux = finalMeteor2[ind1:ind2,:] |
|
2140 | 2142 | |
|
2141 | 2143 | if meteorAux.shape[0] >= meteorThresh: |
|
2142 | 2144 | vel = meteorAux[:, 6] |
|
2143 | 2145 | zen = meteorAux[:, 4]*numpy.pi/180 |
|
2144 | 2146 | azim = meteorAux[:, 3]*numpy.pi/180 |
|
2145 | 2147 | |
|
2146 | 2148 | n = numpy.cos(zen) |
|
2147 | 2149 | # m = (1 - n**2)/(1 - numpy.tan(azim)**2) |
|
2148 | 2150 | # l = m*numpy.tan(azim) |
|
2149 | 2151 | l = numpy.sin(zen)*numpy.sin(azim) |
|
2150 | 2152 | m = numpy.sin(zen)*numpy.cos(azim) |
|
2151 | 2153 | |
|
2152 | 2154 | A = numpy.vstack((l, m)).transpose() |
|
2153 | 2155 | A1 = numpy.dot(numpy.linalg.inv( numpy.dot(A.transpose(),A) ),A.transpose()) |
|
2154 | 2156 | windsAux = numpy.dot(A1, vel) |
|
2155 | 2157 | |
|
2156 | 2158 | winds[0,i] = windsAux[0] |
|
2157 | 2159 | winds[1,i] = windsAux[1] |
|
2158 | 2160 | |
|
2159 | 2161 | return winds, heightPerI[:-1] |
|
2160 | 2162 | |
|
2161 | 2163 | def techniqueNSM_SA(self, **kwargs): |
|
2162 | 2164 | metArray = kwargs['metArray'] |
|
2163 | 2165 | heightList = kwargs['heightList'] |
|
2164 | 2166 | timeList = kwargs['timeList'] |
|
2165 | 2167 | |
|
2166 | 2168 | rx_location = kwargs['rx_location'] |
|
2167 | 2169 | groupList = kwargs['groupList'] |
|
2168 | 2170 | azimuth = kwargs['azimuth'] |
|
2169 | 2171 | dfactor = kwargs['dfactor'] |
|
2170 | 2172 | k = kwargs['k'] |
|
2171 | 2173 | |
|
2172 | 2174 | azimuth1, dist = self.__calculateAzimuth1(rx_location, groupList, azimuth) |
|
2173 | 2175 | d = dist*dfactor |
|
2174 | 2176 | #Phase calculation |
|
2175 | 2177 | metArray1 = self.__getPhaseSlope(metArray, heightList, timeList) |
|
2176 | 2178 | |
|
2177 | 2179 | metArray1[:,-2] = metArray1[:,-2]*metArray1[:,2]*1000/(k*d[metArray1[:,1].astype(int)]) #angles into velocities |
|
2178 | 2180 | |
|
2179 | 2181 | velEst = numpy.zeros((heightList.size,2))*numpy.nan |
|
2180 | 2182 | azimuth1 = azimuth1*numpy.pi/180 |
|
2181 | 2183 | |
|
2182 | 2184 | for i in range(heightList.size): |
|
2183 | 2185 | h = heightList[i] |
|
2184 | 2186 | indH = numpy.where((metArray1[:,2] == h)&(numpy.abs(metArray1[:,-2]) < 100))[0] |
|
2185 | 2187 | metHeight = metArray1[indH,:] |
|
2186 | 2188 | if metHeight.shape[0] >= 2: |
|
2187 | 2189 | velAux = numpy.asmatrix(metHeight[:,-2]).T #Radial Velocities |
|
2188 | 2190 | iazim = metHeight[:,1].astype(int) |
|
2189 | 2191 | azimAux = numpy.asmatrix(azimuth1[iazim]).T #Azimuths |
|
2190 | 2192 | A = numpy.hstack((numpy.cos(azimAux),numpy.sin(azimAux))) |
|
2191 | 2193 | A = numpy.asmatrix(A) |
|
2192 | 2194 | A1 = numpy.linalg.pinv(A.transpose()*A)*A.transpose() |
|
2193 | 2195 | velHor = numpy.dot(A1,velAux) |
|
2194 | 2196 | |
|
2195 | 2197 | velEst[i,:] = numpy.squeeze(velHor) |
|
2196 | 2198 | return velEst |
|
2197 | 2199 | |
|
2198 | 2200 | def __getPhaseSlope(self, metArray, heightList, timeList): |
|
2199 | 2201 | meteorList = [] |
|
2200 | 2202 | #utctime sec1 height SNR velRad ph0 ph1 ph2 coh0 coh1 coh2 |
|
2201 | 2203 | #Putting back together the meteor matrix |
|
2202 | 2204 | utctime = metArray[:,0] |
|
2203 | 2205 | uniqueTime = numpy.unique(utctime) |
|
2204 | 2206 | |
|
2205 | 2207 | phaseDerThresh = 0.5 |
|
2206 | 2208 | ippSeconds = timeList[1] - timeList[0] |
|
2207 | 2209 | sec = numpy.where(timeList>1)[0][0] |
|
2208 | 2210 | nPairs = metArray.shape[1] - 6 |
|
2209 | 2211 | nHeights = len(heightList) |
|
2210 | 2212 | |
|
2211 | 2213 | for t in uniqueTime: |
|
2212 | 2214 | metArray1 = metArray[utctime==t,:] |
|
2213 | 2215 | # phaseDerThresh = numpy.pi/4 #reducir Phase thresh |
|
2214 | 2216 | tmet = metArray1[:,1].astype(int) |
|
2215 | 2217 | hmet = metArray1[:,2].astype(int) |
|
2216 | 2218 | |
|
2217 | 2219 | metPhase = numpy.zeros((nPairs, heightList.size, timeList.size - 1)) |
|
2218 | 2220 | metPhase[:,:] = numpy.nan |
|
2219 | 2221 | metPhase[:,hmet,tmet] = metArray1[:,6:].T |
|
2220 | 2222 | |
|
2221 | 2223 | #Delete short trails |
|
2222 | 2224 | metBool = ~numpy.isnan(metPhase[0,:,:]) |
|
2223 | 2225 | heightVect = numpy.sum(metBool, axis = 1) |
|
2224 | 2226 | metBool[heightVect<sec,:] = False |
|
2225 | 2227 | metPhase[:,heightVect<sec,:] = numpy.nan |
|
2226 | 2228 | |
|
2227 | 2229 | #Derivative |
|
2228 | 2230 | metDer = numpy.abs(metPhase[:,:,1:] - metPhase[:,:,:-1]) |
|
2229 | 2231 | phDerAux = numpy.dstack((numpy.full((nPairs,nHeights,1), False, dtype=bool),metDer > phaseDerThresh)) |
|
2230 | 2232 | metPhase[phDerAux] = numpy.nan |
|
2231 | 2233 | |
|
2232 | 2234 | #--------------------------METEOR DETECTION ----------------------------------------- |
|
2233 | 2235 | indMet = numpy.where(numpy.any(metBool,axis=1))[0] |
|
2234 | 2236 | |
|
2235 | 2237 | for p in numpy.arange(nPairs): |
|
2236 | 2238 | phase = metPhase[p,:,:] |
|
2237 | 2239 | phDer = metDer[p,:,:] |
|
2238 | 2240 | |
|
2239 | 2241 | for h in indMet: |
|
2240 | 2242 | height = heightList[h] |
|
2241 | 2243 | phase1 = phase[h,:] #82 |
|
2242 | 2244 | phDer1 = phDer[h,:] |
|
2243 | 2245 | |
|
2244 | 2246 | phase1[~numpy.isnan(phase1)] = numpy.unwrap(phase1[~numpy.isnan(phase1)]) #Unwrap |
|
2245 | 2247 | |
|
2246 | 2248 | indValid = numpy.where(~numpy.isnan(phase1))[0] |
|
2247 | 2249 | initMet = indValid[0] |
|
2248 | 2250 | endMet = 0 |
|
2249 | 2251 | |
|
2250 | 2252 | for i in range(len(indValid)-1): |
|
2251 | 2253 | |
|
2252 | 2254 | #Time difference |
|
2253 | 2255 | inow = indValid[i] |
|
2254 | 2256 | inext = indValid[i+1] |
|
2255 | 2257 | idiff = inext - inow |
|
2256 | 2258 | #Phase difference |
|
2257 | 2259 | phDiff = numpy.abs(phase1[inext] - phase1[inow]) |
|
2258 | 2260 | |
|
2259 | 2261 | if idiff>sec or phDiff>numpy.pi/4 or inext==indValid[-1]: #End of Meteor |
|
2260 | 2262 | sizeTrail = inow - initMet + 1 |
|
2261 | 2263 | if sizeTrail>3*sec: #Too short meteors |
|
2262 | 2264 | x = numpy.arange(initMet,inow+1)*ippSeconds |
|
2263 | 2265 | y = phase1[initMet:inow+1] |
|
2264 | 2266 | ynnan = ~numpy.isnan(y) |
|
2265 | 2267 | x = x[ynnan] |
|
2266 | 2268 | y = y[ynnan] |
|
2267 | 2269 | slope, intercept, r_value, p_value, std_err = stats.linregress(x,y) |
|
2268 | 2270 | ylin = x*slope + intercept |
|
2269 | 2271 | rsq = r_value**2 |
|
2270 | 2272 | if rsq > 0.5: |
|
2271 | 2273 | vel = slope#*height*1000/(k*d) |
|
2272 | 2274 | estAux = numpy.array([utctime,p,height, vel, rsq]) |
|
2273 | 2275 | meteorList.append(estAux) |
|
2274 | 2276 | initMet = inext |
|
2275 | 2277 | metArray2 = numpy.array(meteorList) |
|
2276 | 2278 | |
|
2277 | 2279 | return metArray2 |
|
2278 | 2280 | |
|
2279 | 2281 | def __calculateAzimuth1(self, rx_location, pairslist, azimuth0): |
|
2280 | 2282 | |
|
2281 | 2283 | azimuth1 = numpy.zeros(len(pairslist)) |
|
2282 | 2284 | dist = numpy.zeros(len(pairslist)) |
|
2283 | 2285 | |
|
2284 | 2286 | for i in range(len(rx_location)): |
|
2285 | 2287 | ch0 = pairslist[i][0] |
|
2286 | 2288 | ch1 = pairslist[i][1] |
|
2287 | 2289 | |
|
2288 | 2290 | diffX = rx_location[ch0][0] - rx_location[ch1][0] |
|
2289 | 2291 | diffY = rx_location[ch0][1] - rx_location[ch1][1] |
|
2290 | 2292 | azimuth1[i] = numpy.arctan2(diffY,diffX)*180/numpy.pi |
|
2291 | 2293 | dist[i] = numpy.sqrt(diffX**2 + diffY**2) |
|
2292 | 2294 | |
|
2293 | 2295 | azimuth1 -= azimuth0 |
|
2294 | 2296 | return azimuth1, dist |
|
2295 | 2297 | |
|
2296 | 2298 | def techniqueNSM_DBS(self, **kwargs): |
|
2297 | 2299 | metArray = kwargs['metArray'] |
|
2298 | 2300 | heightList = kwargs['heightList'] |
|
2299 | 2301 | timeList = kwargs['timeList'] |
|
2300 | 2302 | zenithList = kwargs['zenithList'] |
|
2301 | 2303 | nChan = numpy.max(cmet) + 1 |
|
2302 | 2304 | nHeights = len(heightList) |
|
2303 | 2305 | |
|
2304 | 2306 | utctime = metArray[:,0] |
|
2305 | 2307 | cmet = metArray[:,1] |
|
2306 | 2308 | hmet = metArray1[:,3].astype(int) |
|
2307 | 2309 | h1met = heightList[hmet]*zenithList[cmet] |
|
2308 | 2310 | vmet = metArray1[:,5] |
|
2309 | 2311 | |
|
2310 | 2312 | for i in range(nHeights - 1): |
|
2311 | 2313 | hmin = heightList[i] |
|
2312 | 2314 | hmax = heightList[i + 1] |
|
2313 | 2315 | |
|
2314 | 2316 | vthisH = vmet[(h1met>=hmin) & (h1met<hmax)] |
|
2315 | 2317 | |
|
2316 | 2318 | |
|
2317 | 2319 | |
|
2318 | 2320 | return data_output |
|
2319 | 2321 | |
|
2320 | 2322 | def run(self, dataOut, technique, positionY, positionX, azimuth, **kwargs): |
|
2321 | 2323 | |
|
2322 | 2324 | param = dataOut.data_param |
|
2323 | 2325 | if dataOut.abscissaList != None: |
|
2324 | 2326 | absc = dataOut.abscissaList[:-1] |
|
2325 | 2327 | noise = dataOut.noise |
|
2326 | 2328 | heightList = dataOut.heightList |
|
2327 | 2329 | SNR = dataOut.data_SNR |
|
2328 | 2330 | |
|
2329 | 2331 | if technique == 'DBS': |
|
2330 | 2332 | |
|
2331 | 2333 | kwargs['velRadial'] = param[:,1,:] #Radial velocity |
|
2332 | 2334 | kwargs['heightList'] = heightList |
|
2333 | 2335 | kwargs['SNR'] = SNR |
|
2334 | 2336 | |
|
2335 | 2337 | dataOut.data_output, dataOut.heightList, dataOut.data_SNR = self.techniqueDBS(kwargs) #DBS Function |
|
2336 | 2338 | dataOut.utctimeInit = dataOut.utctime |
|
2337 | 2339 | dataOut.outputInterval = dataOut.paramInterval |
|
2338 | 2340 | |
|
2339 | 2341 | elif technique == 'SA': |
|
2340 | 2342 | |
|
2341 | 2343 | #Parameters |
|
2342 | 2344 | # position_x = kwargs['positionX'] |
|
2343 | 2345 | # position_y = kwargs['positionY'] |
|
2344 | 2346 | # azimuth = kwargs['azimuth'] |
|
2345 | 2347 | # |
|
2346 | 2348 | # if kwargs.has_key('crosspairsList'): |
|
2347 | 2349 | # pairs = kwargs['crosspairsList'] |
|
2348 | 2350 | # else: |
|
2349 | 2351 | # pairs = None |
|
2350 | 2352 | # |
|
2351 | 2353 | # if kwargs.has_key('correctFactor'): |
|
2352 | 2354 | # correctFactor = kwargs['correctFactor'] |
|
2353 | 2355 | # else: |
|
2354 | 2356 | # correctFactor = 1 |
|
2355 | 2357 | |
|
2356 | 2358 | # tau = dataOut.data_param |
|
2357 | 2359 | # _lambda = dataOut.C/dataOut.frequency |
|
2358 | 2360 | # pairsList = dataOut.groupList |
|
2359 | 2361 | # nChannels = dataOut.nChannels |
|
2360 | 2362 | |
|
2361 | 2363 | kwargs['groupList'] = dataOut.groupList |
|
2362 | 2364 | kwargs['tau'] = dataOut.data_param |
|
2363 | 2365 | kwargs['_lambda'] = dataOut.C/dataOut.frequency |
|
2364 | 2366 | # dataOut.data_output = self.techniqueSA(pairs, pairsList, nChannels, tau, azimuth, _lambda, position_x, position_y, absc, correctFactor) |
|
2365 | 2367 | dataOut.data_output = self.techniqueSA(kwargs) |
|
2366 | 2368 | dataOut.utctimeInit = dataOut.utctime |
|
2367 | 2369 | dataOut.outputInterval = dataOut.timeInterval |
|
2368 | 2370 | |
|
2369 | 2371 | elif technique == 'Meteors': |
|
2370 | 2372 | dataOut.flagNoData = True |
|
2371 | 2373 | self.__dataReady = False |
|
2372 | 2374 | |
|
2373 | 2375 | if kwargs.has_key('nHours'): |
|
2374 | 2376 | nHours = kwargs['nHours'] |
|
2375 | 2377 | else: |
|
2376 | 2378 | nHours = 1 |
|
2377 | 2379 | |
|
2378 | 2380 | if kwargs.has_key('meteorsPerBin'): |
|
2379 | 2381 | meteorThresh = kwargs['meteorsPerBin'] |
|
2380 | 2382 | else: |
|
2381 | 2383 | meteorThresh = 6 |
|
2382 | 2384 | |
|
2383 | 2385 | if kwargs.has_key('hmin'): |
|
2384 | 2386 | hmin = kwargs['hmin'] |
|
2385 | 2387 | else: hmin = 70 |
|
2386 | 2388 | if kwargs.has_key('hmax'): |
|
2387 | 2389 | hmax = kwargs['hmax'] |
|
2388 | 2390 | else: hmax = 110 |
|
2389 | 2391 | |
|
2390 | 2392 | dataOut.outputInterval = nHours*3600 |
|
2391 | 2393 | |
|
2392 | 2394 | if self.__isConfig == False: |
|
2393 | 2395 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
2394 | 2396 | #Get Initial LTC time |
|
2395 | 2397 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
2396 | 2398 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
2397 | 2399 | |
|
2398 | 2400 | self.__isConfig = True |
|
2399 | 2401 | |
|
2400 | 2402 | if self.__buffer == None: |
|
2401 | 2403 | self.__buffer = dataOut.data_param |
|
2402 | 2404 | self.__firstdata = copy.copy(dataOut) |
|
2403 | 2405 | |
|
2404 | 2406 | else: |
|
2405 | 2407 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
2406 | 2408 | |
|
2407 | 2409 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
2408 | 2410 | |
|
2409 | 2411 | if self.__dataReady: |
|
2410 | 2412 | dataOut.utctimeInit = self.__initime |
|
2411 | 2413 | |
|
2412 | 2414 | self.__initime += dataOut.outputInterval #to erase time offset |
|
2413 | 2415 | |
|
2414 | 2416 | dataOut.data_output, dataOut.heightList = self.techniqueMeteors(self.__buffer, meteorThresh, hmin, hmax) |
|
2415 | 2417 | dataOut.flagNoData = False |
|
2416 | 2418 | self.__buffer = None |
|
2417 | 2419 | |
|
2418 | 2420 | elif technique == 'Meteors1': |
|
2419 | 2421 | dataOut.flagNoData = True |
|
2420 | 2422 | self.__dataReady = False |
|
2421 | 2423 | |
|
2422 | 2424 | if kwargs.has_key('nMins'): |
|
2423 | 2425 | nMins = kwargs['nMins'] |
|
2424 | 2426 | else: nMins = 20 |
|
2425 | 2427 | if kwargs.has_key('rx_location'): |
|
2426 | 2428 | rx_location = kwargs['rx_location'] |
|
2427 | 2429 | else: rx_location = [(0,1),(1,1),(1,0)] |
|
2428 | 2430 | if kwargs.has_key('azimuth'): |
|
2429 | 2431 | azimuth = kwargs['azimuth'] |
|
2430 | 2432 | else: azimuth = 51 |
|
2431 | 2433 | if kwargs.has_key('dfactor'): |
|
2432 | 2434 | dfactor = kwargs['dfactor'] |
|
2433 | 2435 | if kwargs.has_key('mode'): |
|
2434 | 2436 | mode = kwargs['mode'] |
|
2435 | 2437 | else: mode = 'SA' |
|
2436 | 2438 | |
|
2437 | 2439 | #Borrar luego esto |
|
2438 | 2440 | if dataOut.groupList == None: |
|
2439 | 2441 | dataOut.groupList = [(0,1),(0,2),(1,2)] |
|
2440 | 2442 | groupList = dataOut.groupList |
|
2441 | 2443 | C = 3e8 |
|
2442 | 2444 | freq = 50e6 |
|
2443 | 2445 | lamb = C/freq |
|
2444 | 2446 | k = 2*numpy.pi/lamb |
|
2445 | 2447 | |
|
2446 | 2448 | timeList = dataOut.abscissaList |
|
2447 | 2449 | heightList = dataOut.heightList |
|
2448 | 2450 | |
|
2449 | 2451 | if self.__isConfig == False: |
|
2450 | 2452 | dataOut.outputInterval = nMins*60 |
|
2451 | 2453 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
2452 | 2454 | #Get Initial LTC time |
|
2453 | 2455 | initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
2454 | 2456 | minuteAux = initime.minute |
|
2455 | 2457 | minuteNew = int(numpy.floor(minuteAux/nMins)*nMins) |
|
2456 | 2458 | self.__initime = (initime.replace(minute = minuteNew, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
2457 | 2459 | |
|
2458 | 2460 | self.__isConfig = True |
|
2459 | 2461 | |
|
2460 | 2462 | if self.__buffer == None: |
|
2461 | 2463 | self.__buffer = dataOut.data_param |
|
2462 | 2464 | self.__firstdata = copy.copy(dataOut) |
|
2463 | 2465 | |
|
2464 | 2466 | else: |
|
2465 | 2467 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
2466 | 2468 | |
|
2467 | 2469 | self.__checkTime(dataOut.utctime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
2468 | 2470 | |
|
2469 | 2471 | if self.__dataReady: |
|
2470 | 2472 | dataOut.utctimeInit = self.__initime |
|
2471 | 2473 | self.__initime += dataOut.outputInterval #to erase time offset |
|
2472 | 2474 | |
|
2473 | 2475 | metArray = self.__buffer |
|
2474 | 2476 | if mode == 'SA': |
|
2475 | 2477 | dataOut.data_output = self.techniqueNSM_SA(rx_location=rx_location, groupList=groupList, azimuth=azimuth, dfactor=dfactor, k=k,metArray=metArray, heightList=heightList,timeList=timeList) |
|
2476 | 2478 | elif mode == 'DBS': |
|
2477 | 2479 | dataOut.data_output = self.techniqueNSM_DBS(metArray=metArray,heightList=heightList,timeList=timeList) |
|
2478 | 2480 | dataOut.data_output = dataOut.data_output.T |
|
2479 | 2481 | dataOut.flagNoData = False |
|
2480 | 2482 | self.__buffer = None |
|
2481 | 2483 | |
|
2482 | 2484 | return |
|
2483 | 2485 | |
|
2484 | 2486 | class EWDriftsEstimation(Operation): |
|
2485 | 2487 | |
|
2486 | 2488 | def __init__(self): |
|
2487 | 2489 | Operation.__init__(self) |
|
2488 | 2490 | |
|
2489 | 2491 | def __correctValues(self, heiRang, phi, velRadial, SNR): |
|
2490 | 2492 | listPhi = phi.tolist() |
|
2491 | 2493 | maxid = listPhi.index(max(listPhi)) |
|
2492 | 2494 | minid = listPhi.index(min(listPhi)) |
|
2493 | 2495 | |
|
2494 | 2496 | rango = range(len(phi)) |
|
2495 | 2497 | # rango = numpy.delete(rango,maxid) |
|
2496 | 2498 | |
|
2497 | 2499 | heiRang1 = heiRang*math.cos(phi[maxid]) |
|
2498 | 2500 | heiRangAux = heiRang*math.cos(phi[minid]) |
|
2499 | 2501 | indOut = (heiRang1 < heiRangAux[0]).nonzero() |
|
2500 | 2502 | heiRang1 = numpy.delete(heiRang1,indOut) |
|
2501 | 2503 | |
|
2502 | 2504 | velRadial1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
2503 | 2505 | SNR1 = numpy.zeros([len(phi),len(heiRang1)]) |
|
2504 | 2506 | |
|
2505 | 2507 | for i in rango: |
|
2506 | 2508 | x = heiRang*math.cos(phi[i]) |
|
2507 | 2509 | y1 = velRadial[i,:] |
|
2508 | 2510 | f1 = interpolate.interp1d(x,y1,kind = 'cubic') |
|
2509 | 2511 | |
|
2510 | 2512 | x1 = heiRang1 |
|
2511 | 2513 | y11 = f1(x1) |
|
2512 | 2514 | |
|
2513 | 2515 | y2 = SNR[i,:] |
|
2514 | 2516 | f2 = interpolate.interp1d(x,y2,kind = 'cubic') |
|
2515 | 2517 | y21 = f2(x1) |
|
2516 | 2518 | |
|
2517 | 2519 | velRadial1[i,:] = y11 |
|
2518 | 2520 | SNR1[i,:] = y21 |
|
2519 | 2521 | |
|
2520 | 2522 | return heiRang1, velRadial1, SNR1 |
|
2521 | 2523 | |
|
2522 | 2524 | def run(self, dataOut, zenith, zenithCorrection): |
|
2523 | 2525 | heiRang = dataOut.heightList |
|
2524 | 2526 | velRadial = dataOut.data_param[:,3,:] |
|
2525 | 2527 | SNR = dataOut.data_SNR |
|
2526 | 2528 | |
|
2527 | 2529 | zenith = numpy.array(zenith) |
|
2528 | 2530 | zenith -= zenithCorrection |
|
2529 | 2531 | zenith *= numpy.pi/180 |
|
2530 | 2532 | |
|
2531 | 2533 | heiRang1, velRadial1, SNR1 = self.__correctValues(heiRang, numpy.abs(zenith), velRadial, SNR) |
|
2532 | 2534 | |
|
2533 | 2535 | alp = zenith[0] |
|
2534 | 2536 | bet = zenith[1] |
|
2535 | 2537 | |
|
2536 | 2538 | w_w = velRadial1[0,:] |
|
2537 | 2539 | w_e = velRadial1[1,:] |
|
2538 | 2540 | |
|
2539 | 2541 | w = (w_w*numpy.sin(bet) - w_e*numpy.sin(alp))/(numpy.cos(alp)*numpy.sin(bet) - numpy.cos(bet)*numpy.sin(alp)) |
|
2540 | 2542 | u = (w_w*numpy.cos(bet) - w_e*numpy.cos(alp))/(numpy.sin(alp)*numpy.cos(bet) - numpy.sin(bet)*numpy.cos(alp)) |
|
2541 | 2543 | |
|
2542 | 2544 | winds = numpy.vstack((u,w)) |
|
2543 | 2545 | |
|
2544 | 2546 | dataOut.heightList = heiRang1 |
|
2545 | 2547 | dataOut.data_output = winds |
|
2546 | 2548 | dataOut.data_SNR = SNR1 |
|
2547 | 2549 | |
|
2548 | 2550 | dataOut.utctimeInit = dataOut.utctime |
|
2549 | 2551 | dataOut.outputInterval = dataOut.timeInterval |
|
2550 | 2552 | return |
|
2551 | 2553 | |
|
2552 | 2554 | #--------------- Non Specular Meteor ---------------- |
|
2553 | 2555 | |
|
2554 | 2556 | class NonSpecularMeteorDetection(Operation): |
|
2555 | 2557 | |
|
2556 | 2558 | def run(self, mode, SNRthresh=8, phaseDerThresh=0.5, cohThresh=0.8, allData = False): |
|
2557 | 2559 | data_acf = self.dataOut.data_pre[0] |
|
2558 | 2560 | data_ccf = self.dataOut.data_pre[1] |
|
2559 | 2561 | |
|
2560 | 2562 | lamb = self.dataOut.C/self.dataOut.frequency |
|
2561 | 2563 | tSamp = self.dataOut.ippSeconds*self.dataOut.nCohInt |
|
2562 | 2564 | paramInterval = self.dataOut.paramInterval |
|
2563 | 2565 | |
|
2564 | 2566 | nChannels = data_acf.shape[0] |
|
2565 | 2567 | nLags = data_acf.shape[1] |
|
2566 | 2568 | nProfiles = data_acf.shape[2] |
|
2567 | 2569 | nHeights = self.dataOut.nHeights |
|
2568 | 2570 | nCohInt = self.dataOut.nCohInt |
|
2569 | 2571 | sec = numpy.round(nProfiles/self.dataOut.paramInterval) |
|
2570 | 2572 | heightList = self.dataOut.heightList |
|
2571 | 2573 | ippSeconds = self.dataOut.ippSeconds*self.dataOut.nCohInt*self.dataOut.nAvg |
|
2572 | 2574 | utctime = self.dataOut.utctime |
|
2573 | 2575 | |
|
2574 | 2576 | self.dataOut.abscissaList = numpy.arange(0,paramInterval+ippSeconds,ippSeconds) |
|
2575 | 2577 | |
|
2576 | 2578 | #------------------------ SNR -------------------------------------- |
|
2577 | 2579 | power = data_acf[:,0,:,:].real |
|
2578 | 2580 | noise = numpy.zeros(nChannels) |
|
2579 | 2581 | SNR = numpy.zeros(power.shape) |
|
2580 | 2582 | for i in range(nChannels): |
|
2581 | 2583 | noise[i] = hildebrand_sekhon(power[i,:], nCohInt) |
|
2582 | 2584 | SNR[i] = (power[i]-noise[i])/noise[i] |
|
2583 | 2585 | SNRm = numpy.nanmean(SNR, axis = 0) |
|
2584 | 2586 | SNRdB = 10*numpy.log10(SNR) |
|
2585 | 2587 | |
|
2586 | 2588 | if mode == 'SA': |
|
2587 | 2589 | nPairs = data_ccf.shape[0] |
|
2588 | 2590 | #---------------------- Coherence and Phase -------------------------- |
|
2589 | 2591 | phase = numpy.zeros(data_ccf[:,0,:,:].shape) |
|
2590 | 2592 | # phase1 = numpy.copy(phase) |
|
2591 | 2593 | coh1 = numpy.zeros(data_ccf[:,0,:,:].shape) |
|
2592 | 2594 | |
|
2593 | 2595 | for p in range(nPairs): |
|
2594 | 2596 | ch0 = self.dataOut.groupList[p][0] |
|
2595 | 2597 | ch1 = self.dataOut.groupList[p][1] |
|
2596 | 2598 | ccf = data_ccf[p,0,:,:]/numpy.sqrt(data_acf[ch0,0,:,:]*data_acf[ch1,0,:,:]) |
|
2597 | 2599 | phase[p,:,:] = ndimage.median_filter(numpy.angle(ccf), size = (5,1)) #median filter |
|
2598 | 2600 | # phase1[p,:,:] = numpy.angle(ccf) #median filter |
|
2599 | 2601 | coh1[p,:,:] = ndimage.median_filter(numpy.abs(ccf), 5) #median filter |
|
2600 | 2602 | # coh1[p,:,:] = numpy.abs(ccf) #median filter |
|
2601 | 2603 | coh = numpy.nanmax(coh1, axis = 0) |
|
2602 | 2604 | # struc = numpy.ones((5,1)) |
|
2603 | 2605 | # coh = ndimage.morphology.grey_dilation(coh, size=(10,1)) |
|
2604 | 2606 | #---------------------- Radial Velocity ---------------------------- |
|
2605 | 2607 | phaseAux = numpy.mean(numpy.angle(data_acf[:,1,:,:]), axis = 0) |
|
2606 | 2608 | velRad = phaseAux*lamb/(4*numpy.pi*tSamp) |
|
2607 | 2609 | |
|
2608 | 2610 | if allData: |
|
2609 | 2611 | boolMetFin = ~numpy.isnan(SNRm) |
|
2610 | 2612 | # coh[:-1,:] = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) |
|
2611 | 2613 | else: |
|
2612 | 2614 | #------------------------ Meteor mask --------------------------------- |
|
2613 | 2615 | # #SNR mask |
|
2614 | 2616 | # boolMet = (SNRdB>SNRthresh)#|(~numpy.isnan(SNRdB)) |
|
2615 | 2617 | # |
|
2616 | 2618 | # #Erase small objects |
|
2617 | 2619 | # boolMet1 = self.__erase_small(boolMet, 2*sec, 5) |
|
2618 | 2620 | # |
|
2619 | 2621 | # auxEEJ = numpy.sum(boolMet1,axis=0) |
|
2620 | 2622 | # indOver = auxEEJ>nProfiles*0.8 #Use this later |
|
2621 | 2623 | # indEEJ = numpy.where(indOver)[0] |
|
2622 | 2624 | # indNEEJ = numpy.where(~indOver)[0] |
|
2623 | 2625 | # |
|
2624 | 2626 | # boolMetFin = boolMet1 |
|
2625 | 2627 | # |
|
2626 | 2628 | # if indEEJ.size > 0: |
|
2627 | 2629 | # boolMet1[:,indEEJ] = False #Erase heights with EEJ |
|
2628 | 2630 | # |
|
2629 | 2631 | # boolMet2 = coh > cohThresh |
|
2630 | 2632 | # boolMet2 = self.__erase_small(boolMet2, 2*sec,5) |
|
2631 | 2633 | # |
|
2632 | 2634 | # #Final Meteor mask |
|
2633 | 2635 | # boolMetFin = boolMet1|boolMet2 |
|
2634 | 2636 | |
|
2635 | 2637 | #Coherence mask |
|
2636 | 2638 | boolMet1 = coh > 0.75 |
|
2637 | 2639 | struc = numpy.ones((30,1)) |
|
2638 | 2640 | boolMet1 = ndimage.morphology.binary_dilation(boolMet1, structure=struc) |
|
2639 | 2641 | |
|
2640 | 2642 | #Derivative mask |
|
2641 | 2643 | derPhase = numpy.nanmean(numpy.abs(phase[:,1:,:] - phase[:,:-1,:]),axis=0) |
|
2642 | 2644 | boolMet2 = derPhase < 0.2 |
|
2643 | 2645 | # boolMet2 = ndimage.morphology.binary_opening(boolMet2) |
|
2644 | 2646 | # boolMet2 = ndimage.morphology.binary_closing(boolMet2, structure = numpy.ones((10,1))) |
|
2645 | 2647 | boolMet2 = ndimage.median_filter(boolMet2,size=5) |
|
2646 | 2648 | boolMet2 = numpy.vstack((boolMet2,numpy.full((1,nHeights), True, dtype=bool))) |
|
2647 | 2649 | # #Final mask |
|
2648 | 2650 | # boolMetFin = boolMet2 |
|
2649 | 2651 | boolMetFin = boolMet1&boolMet2 |
|
2650 | 2652 | # boolMetFin = ndimage.morphology.binary_dilation(boolMetFin) |
|
2651 | 2653 | #Creating data_param |
|
2652 | 2654 | coordMet = numpy.where(boolMetFin) |
|
2653 | 2655 | |
|
2654 | 2656 | tmet = coordMet[0] |
|
2655 | 2657 | hmet = coordMet[1] |
|
2656 | 2658 | |
|
2657 | 2659 | data_param = numpy.zeros((tmet.size, 6 + nPairs)) |
|
2658 | 2660 | data_param[:,0] = utctime |
|
2659 | 2661 | data_param[:,1] = tmet |
|
2660 | 2662 | data_param[:,2] = hmet |
|
2661 | 2663 | data_param[:,3] = SNRm[tmet,hmet] |
|
2662 | 2664 | data_param[:,4] = velRad[tmet,hmet] |
|
2663 | 2665 | data_param[:,5] = coh[tmet,hmet] |
|
2664 | 2666 | data_param[:,6:] = phase[:,tmet,hmet].T |
|
2665 | 2667 | |
|
2666 | 2668 | elif mode == 'DBS': |
|
2667 | 2669 | self.dataOut.groupList = numpy.arange(nChannels) |
|
2668 | 2670 | |
|
2669 | 2671 | #Radial Velocities |
|
2670 | 2672 | # phase = numpy.angle(data_acf[:,1,:,:]) |
|
2671 | 2673 | phase = ndimage.median_filter(numpy.angle(data_acf[:,1,:,:]), size = (1,5,1)) |
|
2672 | 2674 | velRad = phase*lamb/(4*numpy.pi*tSamp) |
|
2673 | 2675 | |
|
2674 | 2676 | #Spectral width |
|
2675 | 2677 | acf1 = ndimage.median_filter(numpy.abs(data_acf[:,1,:,:]), size = (1,5,1)) |
|
2676 | 2678 | acf2 = ndimage.median_filter(numpy.abs(data_acf[:,2,:,:]), size = (1,5,1)) |
|
2677 | 2679 | |
|
2678 | 2680 | spcWidth = (lamb/(2*numpy.sqrt(6)*numpy.pi*tSamp))*numpy.sqrt(numpy.log(acf1/acf2)) |
|
2679 | 2681 | # velRad = ndimage.median_filter(velRad, size = (1,5,1)) |
|
2680 | 2682 | if allData: |
|
2681 | 2683 | boolMetFin = ~numpy.isnan(SNRdB) |
|
2682 | 2684 | else: |
|
2683 | 2685 | #SNR |
|
2684 | 2686 | boolMet1 = (SNRdB>SNRthresh) #SNR mask |
|
2685 | 2687 | boolMet1 = ndimage.median_filter(boolMet1, size=(1,5,5)) |
|
2686 | 2688 | |
|
2687 | 2689 | #Radial velocity |
|
2688 | 2690 | boolMet2 = numpy.abs(velRad) < 30 |
|
2689 | 2691 | boolMet2 = ndimage.median_filter(boolMet2, (1,5,5)) |
|
2690 | 2692 | |
|
2691 | 2693 | #Spectral Width |
|
2692 | 2694 | boolMet3 = spcWidth < 30 |
|
2693 | 2695 | boolMet3 = ndimage.median_filter(boolMet3, (1,5,5)) |
|
2694 | 2696 | # boolMetFin = self.__erase_small(boolMet1, 10,5) |
|
2695 | 2697 | boolMetFin = boolMet1&boolMet2&boolMet3 |
|
2696 | 2698 | |
|
2697 | 2699 | #Creating data_param |
|
2698 | 2700 | coordMet = numpy.where(boolMetFin) |
|
2699 | 2701 | |
|
2700 | 2702 | cmet = coordMet[0] |
|
2701 | 2703 | tmet = coordMet[1] |
|
2702 | 2704 | hmet = coordMet[2] |
|
2703 | 2705 | |
|
2704 | 2706 | data_param = numpy.zeros((tmet.size, 7)) |
|
2705 | 2707 | data_param[:,0] = utctime |
|
2706 | 2708 | data_param[:,1] = cmet |
|
2707 | 2709 | data_param[:,2] = tmet |
|
2708 | 2710 | data_param[:,3] = hmet |
|
2709 | 2711 | data_param[:,4] = SNR[cmet,tmet,hmet].T |
|
2710 | 2712 | data_param[:,5] = velRad[cmet,tmet,hmet].T |
|
2711 | 2713 | data_param[:,6] = spcWidth[cmet,tmet,hmet].T |
|
2712 | 2714 | |
|
2713 | 2715 | # self.dataOut.data_param = data_int |
|
2714 | 2716 | if len(data_param) == 0: |
|
2715 | 2717 | self.dataOut.flagNoData = True |
|
2716 | 2718 | else: |
|
2717 | 2719 | self.dataOut.data_param = data_param |
|
2718 | 2720 | |
|
2719 | 2721 | def __erase_small(self, binArray, threshX, threshY): |
|
2720 | 2722 | labarray, numfeat = ndimage.measurements.label(binArray) |
|
2721 | 2723 | binArray1 = numpy.copy(binArray) |
|
2722 | 2724 | |
|
2723 | 2725 | for i in range(1,numfeat + 1): |
|
2724 | 2726 | auxBin = (labarray==i) |
|
2725 | 2727 | auxSize = auxBin.sum() |
|
2726 | 2728 | |
|
2727 | 2729 | x,y = numpy.where(auxBin) |
|
2728 | 2730 | widthX = x.max() - x.min() |
|
2729 | 2731 | widthY = y.max() - y.min() |
|
2730 | 2732 | |
|
2731 | 2733 | #width X: 3 seg -> 12.5*3 |
|
2732 | 2734 | #width Y: |
|
2733 | 2735 | |
|
2734 | 2736 | if (auxSize < 50) or (widthX < threshX) or (widthY < threshY): |
|
2735 | 2737 | binArray1[auxBin] = False |
|
2736 | 2738 | |
|
2737 | 2739 | return binArray1 |
|
2738 | 2740 | |
|
2739 | 2741 | #--------------- Specular Meteor ---------------- |
|
2740 | 2742 | |
|
2741 | 2743 | class SMDetection(Operation): |
|
2742 | 2744 | ''' |
|
2743 | 2745 | Function DetectMeteors() |
|
2744 | 2746 | Project developed with paper: |
|
2745 | 2747 | HOLDSWORTH ET AL. 2004 |
|
2746 | 2748 | |
|
2747 | 2749 | Input: |
|
2748 | 2750 | self.dataOut.data_pre |
|
2749 | 2751 | |
|
2750 | 2752 | centerReceiverIndex: From the channels, which is the center receiver |
|
2751 | 2753 | |
|
2752 | 2754 | hei_ref: Height reference for the Beacon signal extraction |
|
2753 | 2755 | tauindex: |
|
2754 | 2756 | predefinedPhaseShifts: Predefined phase offset for the voltge signals |
|
2755 | 2757 | |
|
2756 | 2758 | cohDetection: Whether to user Coherent detection or not |
|
2757 | 2759 | cohDet_timeStep: Coherent Detection calculation time step |
|
2758 | 2760 | cohDet_thresh: Coherent Detection phase threshold to correct phases |
|
2759 | 2761 | |
|
2760 | 2762 | noise_timeStep: Noise calculation time step |
|
2761 | 2763 | noise_multiple: Noise multiple to define signal threshold |
|
2762 | 2764 | |
|
2763 | 2765 | multDet_timeLimit: Multiple Detection Removal time limit in seconds |
|
2764 | 2766 | multDet_rangeLimit: Multiple Detection Removal range limit in km |
|
2765 | 2767 | |
|
2766 | 2768 | phaseThresh: Maximum phase difference between receiver to be consider a meteor |
|
2767 | 2769 | SNRThresh: Minimum SNR threshold of the meteor signal to be consider a meteor |
|
2768 | 2770 | |
|
2769 | 2771 | hmin: Minimum Height of the meteor to use it in the further wind estimations |
|
2770 | 2772 | hmax: Maximum Height of the meteor to use it in the further wind estimations |
|
2771 | 2773 | azimuth: Azimuth angle correction |
|
2772 | 2774 | |
|
2773 | 2775 | Affected: |
|
2774 | 2776 | self.dataOut.data_param |
|
2775 | 2777 | |
|
2776 | 2778 | Rejection Criteria (Errors): |
|
2777 | 2779 | 0: No error; analysis OK |
|
2778 | 2780 | 1: SNR < SNR threshold |
|
2779 | 2781 | 2: angle of arrival (AOA) ambiguously determined |
|
2780 | 2782 | 3: AOA estimate not feasible |
|
2781 | 2783 | 4: Large difference in AOAs obtained from different antenna baselines |
|
2782 | 2784 | 5: echo at start or end of time series |
|
2783 | 2785 | 6: echo less than 5 examples long; too short for analysis |
|
2784 | 2786 | 7: echo rise exceeds 0.3s |
|
2785 | 2787 | 8: echo decay time less than twice rise time |
|
2786 | 2788 | 9: large power level before echo |
|
2787 | 2789 | 10: large power level after echo |
|
2788 | 2790 | 11: poor fit to amplitude for estimation of decay time |
|
2789 | 2791 | 12: poor fit to CCF phase variation for estimation of radial drift velocity |
|
2790 | 2792 | 13: height unresolvable echo: not valid height within 70 to 110 km |
|
2791 | 2793 | 14: height ambiguous echo: more then one possible height within 70 to 110 km |
|
2792 | 2794 | 15: radial drift velocity or projected horizontal velocity exceeds 200 m/s |
|
2793 | 2795 | 16: oscilatory echo, indicating event most likely not an underdense echo |
|
2794 | 2796 | |
|
2795 | 2797 | 17: phase difference in meteor Reestimation |
|
2796 | 2798 | |
|
2797 | 2799 | Data Storage: |
|
2798 | 2800 | Meteors for Wind Estimation (8): |
|
2799 | 2801 | Utc Time | Range Height |
|
2800 | 2802 | Azimuth Zenith errorCosDir |
|
2801 | 2803 | VelRad errorVelRad |
|
2802 | 2804 | Phase0 Phase1 Phase2 Phase3 |
|
2803 | 2805 | TypeError |
|
2804 | 2806 | |
|
2805 | 2807 | ''' |
|
2806 | 2808 | |
|
2807 | 2809 | def run(self, dataOut, hei_ref = None, tauindex = 0, |
|
2808 | 2810 | phaseOffsets = None, |
|
2809 | 2811 | cohDetection = False, cohDet_timeStep = 1, cohDet_thresh = 25, |
|
2810 | 2812 | noise_timeStep = 4, noise_multiple = 4, |
|
2811 | 2813 | multDet_timeLimit = 1, multDet_rangeLimit = 3, |
|
2812 | 2814 | phaseThresh = 20, SNRThresh = 5, |
|
2813 | 2815 | hmin = 50, hmax=150, azimuth = 0, |
|
2814 | 2816 | channelPositions = None) : |
|
2815 | 2817 | |
|
2816 | 2818 | |
|
2817 | 2819 | #Getting Pairslist |
|
2818 | 2820 | if channelPositions == None: |
|
2819 | 2821 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
2820 | 2822 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
2821 | 2823 | meteorOps = SMOperations() |
|
2822 | 2824 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
2823 | 2825 | heiRang = dataOut.getHeiRange() |
|
2824 | 2826 | #Get Beacon signal - No Beacon signal anymore |
|
2825 | 2827 | # newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
2826 | 2828 | # |
|
2827 | 2829 | # if hei_ref != None: |
|
2828 | 2830 | # newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
2829 | 2831 | # |
|
2830 | 2832 | |
|
2831 | 2833 | |
|
2832 | 2834 | #****************REMOVING HARDWARE PHASE DIFFERENCES*************** |
|
2833 | 2835 | # see if the user put in pre defined phase shifts |
|
2834 | 2836 | voltsPShift = dataOut.data_pre.copy() |
|
2835 | 2837 | |
|
2836 | 2838 | # if predefinedPhaseShifts != None: |
|
2837 | 2839 | # hardwarePhaseShifts = numpy.array(predefinedPhaseShifts)*numpy.pi/180 |
|
2838 | 2840 | # |
|
2839 | 2841 | # # elif beaconPhaseShifts: |
|
2840 | 2842 | # # #get hardware phase shifts using beacon signal |
|
2841 | 2843 | # # hardwarePhaseShifts = self.__getHardwarePhaseDiff(self.dataOut.data_pre, pairslist, newheis, 10) |
|
2842 | 2844 | # # hardwarePhaseShifts = numpy.insert(hardwarePhaseShifts,centerReceiverIndex,0) |
|
2843 | 2845 | # |
|
2844 | 2846 | # else: |
|
2845 | 2847 | # hardwarePhaseShifts = numpy.zeros(5) |
|
2846 | 2848 | # |
|
2847 | 2849 | # voltsPShift = numpy.zeros((self.dataOut.data_pre.shape[0],self.dataOut.data_pre.shape[1],self.dataOut.data_pre.shape[2]), dtype = 'complex') |
|
2848 | 2850 | # for i in range(self.dataOut.data_pre.shape[0]): |
|
2849 | 2851 | # voltsPShift[i,:,:] = self.__shiftPhase(self.dataOut.data_pre[i,:,:], hardwarePhaseShifts[i]) |
|
2850 | 2852 | |
|
2851 | 2853 | #******************END OF REMOVING HARDWARE PHASE DIFFERENCES********* |
|
2852 | 2854 | |
|
2853 | 2855 | #Remove DC |
|
2854 | 2856 | voltsDC = numpy.mean(voltsPShift,1) |
|
2855 | 2857 | voltsDC = numpy.mean(voltsDC,1) |
|
2856 | 2858 | for i in range(voltsDC.shape[0]): |
|
2857 | 2859 | voltsPShift[i] = voltsPShift[i] - voltsDC[i] |
|
2858 | 2860 | |
|
2859 | 2861 | #Don't considerate last heights, theyre used to calculate Hardware Phase Shift |
|
2860 | 2862 | # voltsPShift = voltsPShift[:,:,:newheis[0][0]] |
|
2861 | 2863 | |
|
2862 | 2864 | #************ FIND POWER OF DATA W/COH OR NON COH DETECTION (3.4) ********** |
|
2863 | 2865 | #Coherent Detection |
|
2864 | 2866 | if cohDetection: |
|
2865 | 2867 | #use coherent detection to get the net power |
|
2866 | 2868 | cohDet_thresh = cohDet_thresh*numpy.pi/180 |
|
2867 | 2869 | voltsPShift = self.__coherentDetection(voltsPShift, cohDet_timeStep, dataOut.timeInterval, pairslist0, cohDet_thresh) |
|
2868 | 2870 | |
|
2869 | 2871 | #Non-coherent detection! |
|
2870 | 2872 | powerNet = numpy.nansum(numpy.abs(voltsPShift[:,:,:])**2,0) |
|
2871 | 2873 | #********** END OF COH/NON-COH POWER CALCULATION********************** |
|
2872 | 2874 | |
|
2873 | 2875 | #********** FIND THE NOISE LEVEL AND POSSIBLE METEORS **************** |
|
2874 | 2876 | #Get noise |
|
2875 | 2877 | noise, noise1 = self.__getNoise(powerNet, noise_timeStep, dataOut.timeInterval) |
|
2876 | 2878 | # noise = self.getNoise1(powerNet, noise_timeStep, self.dataOut.timeInterval) |
|
2877 | 2879 | #Get signal threshold |
|
2878 | 2880 | signalThresh = noise_multiple*noise |
|
2879 | 2881 | #Meteor echoes detection |
|
2880 | 2882 | listMeteors = self.__findMeteors(powerNet, signalThresh) |
|
2881 | 2883 | #******* END OF NOISE LEVEL AND POSSIBLE METEORS CACULATION ********** |
|
2882 | 2884 | |
|
2883 | 2885 | #************** REMOVE MULTIPLE DETECTIONS (3.5) *************************** |
|
2884 | 2886 | #Parameters |
|
2885 | 2887 | heiRange = dataOut.getHeiRange() |
|
2886 | 2888 | rangeInterval = heiRange[1] - heiRange[0] |
|
2887 | 2889 | rangeLimit = multDet_rangeLimit/rangeInterval |
|
2888 | 2890 | timeLimit = multDet_timeLimit/dataOut.timeInterval |
|
2889 | 2891 | #Multiple detection removals |
|
2890 | 2892 | listMeteors1 = self.__removeMultipleDetections(listMeteors, rangeLimit, timeLimit) |
|
2891 | 2893 | #************ END OF REMOVE MULTIPLE DETECTIONS ********************** |
|
2892 | 2894 | |
|
2893 | 2895 | #********************* METEOR REESTIMATION (3.7, 3.8, 3.9, 3.10) ******************** |
|
2894 | 2896 | #Parameters |
|
2895 | 2897 | phaseThresh = phaseThresh*numpy.pi/180 |
|
2896 | 2898 | thresh = [phaseThresh, noise_multiple, SNRThresh] |
|
2897 | 2899 | #Meteor reestimation (Errors N 1, 6, 12, 17) |
|
2898 | 2900 | listMeteors2, listMeteorsPower, listMeteorsVolts = self.__meteorReestimation(listMeteors1, voltsPShift, pairslist0, thresh, noise, dataOut.timeInterval, dataOut.frequency) |
|
2899 | 2901 | # listMeteors2, listMeteorsPower, listMeteorsVolts = self.meteorReestimation3(listMeteors2, listMeteorsPower, listMeteorsVolts, voltsPShift, pairslist, thresh, noise) |
|
2900 | 2902 | #Estimation of decay times (Errors N 7, 8, 11) |
|
2901 | 2903 | listMeteors3 = self.__estimateDecayTime(listMeteors2, listMeteorsPower, dataOut.timeInterval, dataOut.frequency) |
|
2902 | 2904 | #******************* END OF METEOR REESTIMATION ******************* |
|
2903 | 2905 | |
|
2904 | 2906 | #********************* METEOR PARAMETERS CALCULATION (3.11, 3.12, 3.13) ************************** |
|
2905 | 2907 | #Calculating Radial Velocity (Error N 15) |
|
2906 | 2908 | radialStdThresh = 10 |
|
2907 | 2909 | listMeteors4 = self.__getRadialVelocity(listMeteors3, listMeteorsVolts, radialStdThresh, pairslist0, dataOut.timeInterval) |
|
2908 | 2910 | |
|
2909 | 2911 | if len(listMeteors4) > 0: |
|
2910 | 2912 | #Setting New Array |
|
2911 | 2913 | date = dataOut.utctime |
|
2912 | 2914 | arrayParameters = self.__setNewArrays(listMeteors4, date, heiRang) |
|
2913 | 2915 | |
|
2914 | 2916 | #Correcting phase offset |
|
2915 | 2917 | if phaseOffsets != None: |
|
2916 | 2918 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 |
|
2917 | 2919 | arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) |
|
2918 | 2920 | |
|
2919 | 2921 | #Second Pairslist |
|
2920 | 2922 | pairsList = [] |
|
2921 | 2923 | pairx = (0,1) |
|
2922 | 2924 | pairy = (2,3) |
|
2923 | 2925 | pairsList.append(pairx) |
|
2924 | 2926 | pairsList.append(pairy) |
|
2925 | 2927 | |
|
2926 | 2928 | jph = numpy.array([0,0,0,0]) |
|
2927 | 2929 | h = (hmin,hmax) |
|
2928 | 2930 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) |
|
2929 | 2931 | |
|
2930 | 2932 | # #Calculate AOA (Error N 3, 4) |
|
2931 | 2933 | # #JONES ET AL. 1998 |
|
2932 | 2934 | # error = arrayParameters[:,-1] |
|
2933 | 2935 | # AOAthresh = numpy.pi/8 |
|
2934 | 2936 | # phases = -arrayParameters[:,9:13] |
|
2935 | 2937 | # arrayParameters[:,4:7], arrayParameters[:,-1] = meteorOps.getAOA(phases, pairsList, error, AOAthresh, azimuth) |
|
2936 | 2938 | # |
|
2937 | 2939 | # #Calculate Heights (Error N 13 and 14) |
|
2938 | 2940 | # error = arrayParameters[:,-1] |
|
2939 | 2941 | # Ranges = arrayParameters[:,2] |
|
2940 | 2942 | # zenith = arrayParameters[:,5] |
|
2941 | 2943 | # arrayParameters[:,3], arrayParameters[:,-1] = meteorOps.getHeights(Ranges, zenith, error, hmin, hmax) |
|
2942 | 2944 | # error = arrayParameters[:,-1] |
|
2943 | 2945 | #********************* END OF PARAMETERS CALCULATION ************************** |
|
2944 | 2946 | |
|
2945 | 2947 | #***************************+ PASS DATA TO NEXT STEP ********************** |
|
2946 | 2948 | # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1])) |
|
2947 | 2949 | dataOut.data_param = arrayParameters |
|
2948 | 2950 | |
|
2949 | 2951 | if arrayParameters == None: |
|
2950 | 2952 | dataOut.flagNoData = True |
|
2951 | 2953 | else: |
|
2952 | 2954 | dataOut.flagNoData = True |
|
2953 | 2955 | |
|
2954 | 2956 | return |
|
2955 | 2957 | |
|
2956 | 2958 | def __getHardwarePhaseDiff(self, voltage0, pairslist, newheis, n): |
|
2957 | 2959 | |
|
2958 | 2960 | minIndex = min(newheis[0]) |
|
2959 | 2961 | maxIndex = max(newheis[0]) |
|
2960 | 2962 | |
|
2961 | 2963 | voltage = voltage0[:,:,minIndex:maxIndex+1] |
|
2962 | 2964 | nLength = voltage.shape[1]/n |
|
2963 | 2965 | nMin = 0 |
|
2964 | 2966 | nMax = 0 |
|
2965 | 2967 | phaseOffset = numpy.zeros((len(pairslist),n)) |
|
2966 | 2968 | |
|
2967 | 2969 | for i in range(n): |
|
2968 | 2970 | nMax += nLength |
|
2969 | 2971 | phaseCCF = -numpy.angle(self.__calculateCCF(voltage[:,nMin:nMax,:], pairslist, [0])) |
|
2970 | 2972 | phaseCCF = numpy.mean(phaseCCF, axis = 2) |
|
2971 | 2973 | phaseOffset[:,i] = phaseCCF.transpose() |
|
2972 | 2974 | nMin = nMax |
|
2973 | 2975 | # phaseDiff, phaseArrival = self.estimatePhaseDifference(voltage, pairslist) |
|
2974 | 2976 | |
|
2975 | 2977 | #Remove Outliers |
|
2976 | 2978 | factor = 2 |
|
2977 | 2979 | wt = phaseOffset - signal.medfilt(phaseOffset,(1,5)) |
|
2978 | 2980 | dw = numpy.std(wt,axis = 1) |
|
2979 | 2981 | dw = dw.reshape((dw.size,1)) |
|
2980 | 2982 | ind = numpy.where(numpy.logical_or(wt>dw*factor,wt<-dw*factor)) |
|
2981 | 2983 | phaseOffset[ind] = numpy.nan |
|
2982 | 2984 | phaseOffset = stats.nanmean(phaseOffset, axis=1) |
|
2983 | 2985 | |
|
2984 | 2986 | return phaseOffset |
|
2985 | 2987 | |
|
2986 | 2988 | def __shiftPhase(self, data, phaseShift): |
|
2987 | 2989 | #this will shift the phase of a complex number |
|
2988 | 2990 | dataShifted = numpy.abs(data) * numpy.exp((numpy.angle(data)+phaseShift)*1j) |
|
2989 | 2991 | return dataShifted |
|
2990 | 2992 | |
|
2991 | 2993 | def __estimatePhaseDifference(self, array, pairslist): |
|
2992 | 2994 | nChannel = array.shape[0] |
|
2993 | 2995 | nHeights = array.shape[2] |
|
2994 | 2996 | numPairs = len(pairslist) |
|
2995 | 2997 | # phaseCCF = numpy.zeros((nChannel, 5, nHeights)) |
|
2996 | 2998 | phaseCCF = numpy.angle(self.__calculateCCF(array, pairslist, [-2,-1,0,1,2])) |
|
2997 | 2999 | |
|
2998 | 3000 | #Correct phases |
|
2999 | 3001 | derPhaseCCF = phaseCCF[:,1:,:] - phaseCCF[:,0:-1,:] |
|
3000 | 3002 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) |
|
3001 | 3003 | |
|
3002 | 3004 | if indDer[0].shape[0] > 0: |
|
3003 | 3005 | for i in range(indDer[0].shape[0]): |
|
3004 | 3006 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i],indDer[2][i]]) |
|
3005 | 3007 | phaseCCF[indDer[0][i],indDer[1][i]+1:,:] += signo*2*numpy.pi |
|
3006 | 3008 | |
|
3007 | 3009 | # for j in range(numSides): |
|
3008 | 3010 | # phaseCCFAux = self.calculateCCF(arrayCenter, arraySides[j,:,:], [-2,1,0,1,2]) |
|
3009 | 3011 | # phaseCCF[j,:,:] = numpy.angle(phaseCCFAux) |
|
3010 | 3012 | # |
|
3011 | 3013 | #Linear |
|
3012 | 3014 | phaseInt = numpy.zeros((numPairs,1)) |
|
3013 | 3015 | angAllCCF = phaseCCF[:,[0,1,3,4],0] |
|
3014 | 3016 | for j in range(numPairs): |
|
3015 | 3017 | fit = stats.linregress([-2,-1,1,2],angAllCCF[j,:]) |
|
3016 | 3018 | phaseInt[j] = fit[1] |
|
3017 | 3019 | #Phase Differences |
|
3018 | 3020 | phaseDiff = phaseInt - phaseCCF[:,2,:] |
|
3019 | 3021 | phaseArrival = phaseInt.reshape(phaseInt.size) |
|
3020 | 3022 | |
|
3021 | 3023 | #Dealias |
|
3022 | 3024 | phaseArrival = numpy.angle(numpy.exp(1j*phaseArrival)) |
|
3023 | 3025 | # indAlias = numpy.where(phaseArrival > numpy.pi) |
|
3024 | 3026 | # phaseArrival[indAlias] -= 2*numpy.pi |
|
3025 | 3027 | # indAlias = numpy.where(phaseArrival < -numpy.pi) |
|
3026 | 3028 | # phaseArrival[indAlias] += 2*numpy.pi |
|
3027 | 3029 | |
|
3028 | 3030 | return phaseDiff, phaseArrival |
|
3029 | 3031 | |
|
3030 | 3032 | def __coherentDetection(self, volts, timeSegment, timeInterval, pairslist, thresh): |
|
3031 | 3033 | #this function will run the coherent detection used in Holdworth et al. 2004 and return the net power |
|
3032 | 3034 | #find the phase shifts of each channel over 1 second intervals |
|
3033 | 3035 | #only look at ranges below the beacon signal |
|
3034 | 3036 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) |
|
3035 | 3037 | numBlocks = int(volts.shape[1]/numProfPerBlock) |
|
3036 | 3038 | numHeights = volts.shape[2] |
|
3037 | 3039 | nChannel = volts.shape[0] |
|
3038 | 3040 | voltsCohDet = volts.copy() |
|
3039 | 3041 | |
|
3040 | 3042 | pairsarray = numpy.array(pairslist) |
|
3041 | 3043 | indSides = pairsarray[:,1] |
|
3042 | 3044 | # indSides = numpy.array(range(nChannel)) |
|
3043 | 3045 | # indSides = numpy.delete(indSides, indCenter) |
|
3044 | 3046 | # |
|
3045 | 3047 | # listCenter = numpy.array_split(volts[indCenter,:,:], numBlocks, 0) |
|
3046 | 3048 | listBlocks = numpy.array_split(volts, numBlocks, 1) |
|
3047 | 3049 | |
|
3048 | 3050 | startInd = 0 |
|
3049 | 3051 | endInd = 0 |
|
3050 | 3052 | |
|
3051 | 3053 | for i in range(numBlocks): |
|
3052 | 3054 | startInd = endInd |
|
3053 | 3055 | endInd = endInd + listBlocks[i].shape[1] |
|
3054 | 3056 | |
|
3055 | 3057 | arrayBlock = listBlocks[i] |
|
3056 | 3058 | # arrayBlockCenter = listCenter[i] |
|
3057 | 3059 | |
|
3058 | 3060 | #Estimate the Phase Difference |
|
3059 | 3061 | phaseDiff, aux = self.__estimatePhaseDifference(arrayBlock, pairslist) |
|
3060 | 3062 | #Phase Difference RMS |
|
3061 | 3063 | arrayPhaseRMS = numpy.abs(phaseDiff) |
|
3062 | 3064 | phaseRMSaux = numpy.sum(arrayPhaseRMS < thresh,0) |
|
3063 | 3065 | indPhase = numpy.where(phaseRMSaux==4) |
|
3064 | 3066 | #Shifting |
|
3065 | 3067 | if indPhase[0].shape[0] > 0: |
|
3066 | 3068 | for j in range(indSides.size): |
|
3067 | 3069 | arrayBlock[indSides[j],:,indPhase] = self.__shiftPhase(arrayBlock[indSides[j],:,indPhase], phaseDiff[j,indPhase].transpose()) |
|
3068 | 3070 | voltsCohDet[:,startInd:endInd,:] = arrayBlock |
|
3069 | 3071 | |
|
3070 | 3072 | return voltsCohDet |
|
3071 | 3073 | |
|
3072 | 3074 | def __calculateCCF(self, volts, pairslist ,laglist): |
|
3073 | 3075 | |
|
3074 | 3076 | nHeights = volts.shape[2] |
|
3075 | 3077 | nPoints = volts.shape[1] |
|
3076 | 3078 | voltsCCF = numpy.zeros((len(pairslist), len(laglist), nHeights),dtype = 'complex') |
|
3077 | 3079 | |
|
3078 | 3080 | for i in range(len(pairslist)): |
|
3079 | 3081 | volts1 = volts[pairslist[i][0]] |
|
3080 | 3082 | volts2 = volts[pairslist[i][1]] |
|
3081 | 3083 | |
|
3082 | 3084 | for t in range(len(laglist)): |
|
3083 | 3085 | idxT = laglist[t] |
|
3084 | 3086 | if idxT >= 0: |
|
3085 | 3087 | vStacked = numpy.vstack((volts2[idxT:,:], |
|
3086 | 3088 | numpy.zeros((idxT, nHeights),dtype='complex'))) |
|
3087 | 3089 | else: |
|
3088 | 3090 | vStacked = numpy.vstack((numpy.zeros((-idxT, nHeights),dtype='complex'), |
|
3089 | 3091 | volts2[:(nPoints + idxT),:])) |
|
3090 | 3092 | voltsCCF[i,t,:] = numpy.sum((numpy.conjugate(volts1)*vStacked),axis=0) |
|
3091 | 3093 | |
|
3092 | 3094 | vStacked = None |
|
3093 | 3095 | return voltsCCF |
|
3094 | 3096 | |
|
3095 | 3097 | def __getNoise(self, power, timeSegment, timeInterval): |
|
3096 | 3098 | numProfPerBlock = numpy.ceil(timeSegment/timeInterval) |
|
3097 | 3099 | numBlocks = int(power.shape[0]/numProfPerBlock) |
|
3098 | 3100 | numHeights = power.shape[1] |
|
3099 | 3101 | |
|
3100 | 3102 | listPower = numpy.array_split(power, numBlocks, 0) |
|
3101 | 3103 | noise = numpy.zeros((power.shape[0], power.shape[1])) |
|
3102 | 3104 | noise1 = numpy.zeros((power.shape[0], power.shape[1])) |
|
3103 | 3105 | |
|
3104 | 3106 | startInd = 0 |
|
3105 | 3107 | endInd = 0 |
|
3106 | 3108 | |
|
3107 | 3109 | for i in range(numBlocks): #split por canal |
|
3108 | 3110 | startInd = endInd |
|
3109 | 3111 | endInd = endInd + listPower[i].shape[0] |
|
3110 | 3112 | |
|
3111 | 3113 | arrayBlock = listPower[i] |
|
3112 | 3114 | noiseAux = numpy.mean(arrayBlock, 0) |
|
3113 | 3115 | # noiseAux = numpy.median(noiseAux) |
|
3114 | 3116 | # noiseAux = numpy.mean(arrayBlock) |
|
3115 | 3117 | noise[startInd:endInd,:] = noise[startInd:endInd,:] + noiseAux |
|
3116 | 3118 | |
|
3117 | 3119 | noiseAux1 = numpy.mean(arrayBlock) |
|
3118 | 3120 | noise1[startInd:endInd,:] = noise1[startInd:endInd,:] + noiseAux1 |
|
3119 | 3121 | |
|
3120 | 3122 | return noise, noise1 |
|
3121 | 3123 | |
|
3122 | 3124 | def __findMeteors(self, power, thresh): |
|
3123 | 3125 | nProf = power.shape[0] |
|
3124 | 3126 | nHeights = power.shape[1] |
|
3125 | 3127 | listMeteors = [] |
|
3126 | 3128 | |
|
3127 | 3129 | for i in range(nHeights): |
|
3128 | 3130 | powerAux = power[:,i] |
|
3129 | 3131 | threshAux = thresh[:,i] |
|
3130 | 3132 | |
|
3131 | 3133 | indUPthresh = numpy.where(powerAux > threshAux)[0] |
|
3132 | 3134 | indDNthresh = numpy.where(powerAux <= threshAux)[0] |
|
3133 | 3135 | |
|
3134 | 3136 | j = 0 |
|
3135 | 3137 | |
|
3136 | 3138 | while (j < indUPthresh.size - 2): |
|
3137 | 3139 | if (indUPthresh[j + 2] == indUPthresh[j] + 2): |
|
3138 | 3140 | indDNAux = numpy.where(indDNthresh > indUPthresh[j]) |
|
3139 | 3141 | indDNthresh = indDNthresh[indDNAux] |
|
3140 | 3142 | |
|
3141 | 3143 | if (indDNthresh.size > 0): |
|
3142 | 3144 | indEnd = indDNthresh[0] - 1 |
|
3143 | 3145 | indInit = indUPthresh[j] |
|
3144 | 3146 | |
|
3145 | 3147 | meteor = powerAux[indInit:indEnd + 1] |
|
3146 | 3148 | indPeak = meteor.argmax() + indInit |
|
3147 | 3149 | FLA = sum(numpy.conj(meteor)*numpy.hstack((meteor[1:],0))) |
|
3148 | 3150 | |
|
3149 | 3151 | listMeteors.append(numpy.array([i,indInit,indPeak,indEnd,FLA])) #CHEQUEAR!!!!! |
|
3150 | 3152 | j = numpy.where(indUPthresh == indEnd)[0] + 1 |
|
3151 | 3153 | else: j+=1 |
|
3152 | 3154 | else: j+=1 |
|
3153 | 3155 | |
|
3154 | 3156 | return listMeteors |
|
3155 | 3157 | |
|
3156 | 3158 | def __removeMultipleDetections(self,listMeteors, rangeLimit, timeLimit): |
|
3157 | 3159 | |
|
3158 | 3160 | arrayMeteors = numpy.asarray(listMeteors) |
|
3159 | 3161 | listMeteors1 = [] |
|
3160 | 3162 | |
|
3161 | 3163 | while arrayMeteors.shape[0] > 0: |
|
3162 | 3164 | FLAs = arrayMeteors[:,4] |
|
3163 | 3165 | maxFLA = FLAs.argmax() |
|
3164 | 3166 | listMeteors1.append(arrayMeteors[maxFLA,:]) |
|
3165 | 3167 | |
|
3166 | 3168 | MeteorInitTime = arrayMeteors[maxFLA,1] |
|
3167 | 3169 | MeteorEndTime = arrayMeteors[maxFLA,3] |
|
3168 | 3170 | MeteorHeight = arrayMeteors[maxFLA,0] |
|
3169 | 3171 | |
|
3170 | 3172 | #Check neighborhood |
|
3171 | 3173 | maxHeightIndex = MeteorHeight + rangeLimit |
|
3172 | 3174 | minHeightIndex = MeteorHeight - rangeLimit |
|
3173 | 3175 | minTimeIndex = MeteorInitTime - timeLimit |
|
3174 | 3176 | maxTimeIndex = MeteorEndTime + timeLimit |
|
3175 | 3177 | |
|
3176 | 3178 | #Check Heights |
|
3177 | 3179 | indHeight = numpy.logical_and(arrayMeteors[:,0] >= minHeightIndex, arrayMeteors[:,0] <= maxHeightIndex) |
|
3178 | 3180 | indTime = numpy.logical_and(arrayMeteors[:,3] >= minTimeIndex, arrayMeteors[:,1] <= maxTimeIndex) |
|
3179 | 3181 | indBoth = numpy.where(numpy.logical_and(indTime,indHeight)) |
|
3180 | 3182 | |
|
3181 | 3183 | arrayMeteors = numpy.delete(arrayMeteors, indBoth, axis = 0) |
|
3182 | 3184 | |
|
3183 | 3185 | return listMeteors1 |
|
3184 | 3186 | |
|
3185 | 3187 | def __meteorReestimation(self, listMeteors, volts, pairslist, thresh, noise, timeInterval,frequency): |
|
3186 | 3188 | numHeights = volts.shape[2] |
|
3187 | 3189 | nChannel = volts.shape[0] |
|
3188 | 3190 | |
|
3189 | 3191 | thresholdPhase = thresh[0] |
|
3190 | 3192 | thresholdNoise = thresh[1] |
|
3191 | 3193 | thresholdDB = float(thresh[2]) |
|
3192 | 3194 | |
|
3193 | 3195 | thresholdDB1 = 10**(thresholdDB/10) |
|
3194 | 3196 | pairsarray = numpy.array(pairslist) |
|
3195 | 3197 | indSides = pairsarray[:,1] |
|
3196 | 3198 | |
|
3197 | 3199 | pairslist1 = list(pairslist) |
|
3198 | 3200 | pairslist1.append((0,1)) |
|
3199 | 3201 | pairslist1.append((3,4)) |
|
3200 | 3202 | |
|
3201 | 3203 | listMeteors1 = [] |
|
3202 | 3204 | listPowerSeries = [] |
|
3203 | 3205 | listVoltageSeries = [] |
|
3204 | 3206 | #volts has the war data |
|
3205 | 3207 | |
|
3206 | 3208 | if frequency == 30e6: |
|
3207 | 3209 | timeLag = 45*10**-3 |
|
3208 | 3210 | else: |
|
3209 | 3211 | timeLag = 15*10**-3 |
|
3210 | 3212 | lag = numpy.ceil(timeLag/timeInterval) |
|
3211 | 3213 | |
|
3212 | 3214 | for i in range(len(listMeteors)): |
|
3213 | 3215 | |
|
3214 | 3216 | ###################### 3.6 - 3.7 PARAMETERS REESTIMATION ######################### |
|
3215 | 3217 | meteorAux = numpy.zeros(16) |
|
3216 | 3218 | |
|
3217 | 3219 | #Loading meteor Data (mHeight, mStart, mPeak, mEnd) |
|
3218 | 3220 | mHeight = listMeteors[i][0] |
|
3219 | 3221 | mStart = listMeteors[i][1] |
|
3220 | 3222 | mPeak = listMeteors[i][2] |
|
3221 | 3223 | mEnd = listMeteors[i][3] |
|
3222 | 3224 | |
|
3223 | 3225 | #get the volt data between the start and end times of the meteor |
|
3224 | 3226 | meteorVolts = volts[:,mStart:mEnd+1,mHeight] |
|
3225 | 3227 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) |
|
3226 | 3228 | |
|
3227 | 3229 | #3.6. Phase Difference estimation |
|
3228 | 3230 | phaseDiff, aux = self.__estimatePhaseDifference(meteorVolts, pairslist) |
|
3229 | 3231 | |
|
3230 | 3232 | #3.7. Phase difference removal & meteor start, peak and end times reestimated |
|
3231 | 3233 | #meteorVolts0.- all Channels, all Profiles |
|
3232 | 3234 | meteorVolts0 = volts[:,:,mHeight] |
|
3233 | 3235 | meteorThresh = noise[:,mHeight]*thresholdNoise |
|
3234 | 3236 | meteorNoise = noise[:,mHeight] |
|
3235 | 3237 | meteorVolts0[indSides,:] = self.__shiftPhase(meteorVolts0[indSides,:], phaseDiff) #Phase Shifting |
|
3236 | 3238 | powerNet0 = numpy.nansum(numpy.abs(meteorVolts0)**2, axis = 0) #Power |
|
3237 | 3239 | |
|
3238 | 3240 | #Times reestimation |
|
3239 | 3241 | mStart1 = numpy.where(powerNet0[:mPeak] < meteorThresh[:mPeak])[0] |
|
3240 | 3242 | if mStart1.size > 0: |
|
3241 | 3243 | mStart1 = mStart1[-1] + 1 |
|
3242 | 3244 | |
|
3243 | 3245 | else: |
|
3244 | 3246 | mStart1 = mPeak |
|
3245 | 3247 | |
|
3246 | 3248 | mEnd1 = numpy.where(powerNet0[mPeak:] < meteorThresh[mPeak:])[0][0] + mPeak - 1 |
|
3247 | 3249 | mEndDecayTime1 = numpy.where(powerNet0[mPeak:] < meteorNoise[mPeak:])[0] |
|
3248 | 3250 | if mEndDecayTime1.size == 0: |
|
3249 | 3251 | mEndDecayTime1 = powerNet0.size |
|
3250 | 3252 | else: |
|
3251 | 3253 | mEndDecayTime1 = mEndDecayTime1[0] + mPeak - 1 |
|
3252 | 3254 | # mPeak1 = meteorVolts0[mStart1:mEnd1 + 1].argmax() |
|
3253 | 3255 | |
|
3254 | 3256 | #meteorVolts1.- all Channels, from start to end |
|
3255 | 3257 | meteorVolts1 = meteorVolts0[:,mStart1:mEnd1 + 1] |
|
3256 | 3258 | meteorVolts2 = meteorVolts0[:,mPeak + lag:mEnd1 + 1] |
|
3257 | 3259 | if meteorVolts2.shape[1] == 0: |
|
3258 | 3260 | meteorVolts2 = meteorVolts0[:,mPeak:mEnd1 + 1] |
|
3259 | 3261 | meteorVolts1 = meteorVolts1.reshape(meteorVolts1.shape[0], meteorVolts1.shape[1], 1) |
|
3260 | 3262 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1], 1) |
|
3261 | 3263 | ##################### END PARAMETERS REESTIMATION ######################### |
|
3262 | 3264 | |
|
3263 | 3265 | ##################### 3.8 PHASE DIFFERENCE REESTIMATION ######################## |
|
3264 | 3266 | # if mEnd1 - mStart1 > 4: #Error Number 6: echo less than 5 samples long; too short for analysis |
|
3265 | 3267 | if meteorVolts2.shape[1] > 0: |
|
3266 | 3268 | #Phase Difference re-estimation |
|
3267 | 3269 | phaseDiff1, phaseDiffint = self.__estimatePhaseDifference(meteorVolts2, pairslist1) #Phase Difference Estimation |
|
3268 | 3270 | # phaseDiff1, phaseDiffint = self.estimatePhaseDifference(meteorVolts2, pairslist) |
|
3269 | 3271 | meteorVolts2 = meteorVolts2.reshape(meteorVolts2.shape[0], meteorVolts2.shape[1]) |
|
3270 | 3272 | phaseDiff11 = numpy.reshape(phaseDiff1, (phaseDiff1.shape[0],1)) |
|
3271 | 3273 | meteorVolts2[indSides,:] = self.__shiftPhase(meteorVolts2[indSides,:], phaseDiff11[0:4]) #Phase Shifting |
|
3272 | 3274 | |
|
3273 | 3275 | #Phase Difference RMS |
|
3274 | 3276 | phaseRMS1 = numpy.sqrt(numpy.mean(numpy.square(phaseDiff1))) |
|
3275 | 3277 | powerNet1 = numpy.nansum(numpy.abs(meteorVolts1[:,:])**2,0) |
|
3276 | 3278 | #Data from Meteor |
|
3277 | 3279 | mPeak1 = powerNet1.argmax() + mStart1 |
|
3278 | 3280 | mPeakPower1 = powerNet1.max() |
|
3279 | 3281 | noiseAux = sum(noise[mStart1:mEnd1 + 1,mHeight]) |
|
3280 | 3282 | mSNR1 = (sum(powerNet1)-noiseAux)/noiseAux |
|
3281 | 3283 | Meteor1 = numpy.array([mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1]) |
|
3282 | 3284 | Meteor1 = numpy.hstack((Meteor1,phaseDiffint)) |
|
3283 | 3285 | PowerSeries = powerNet0[mStart1:mEndDecayTime1 + 1] |
|
3284 | 3286 | #Vectorize |
|
3285 | 3287 | meteorAux[0:7] = [mHeight, mStart1, mPeak1, mEnd1, mPeakPower1, mSNR1, phaseRMS1] |
|
3286 | 3288 | meteorAux[7:11] = phaseDiffint[0:4] |
|
3287 | 3289 | |
|
3288 | 3290 | #Rejection Criterions |
|
3289 | 3291 | if phaseRMS1 > thresholdPhase: #Error Number 17: Phase variation |
|
3290 | 3292 | meteorAux[-1] = 17 |
|
3291 | 3293 | elif mSNR1 < thresholdDB1: #Error Number 1: SNR < threshold dB |
|
3292 | 3294 | meteorAux[-1] = 1 |
|
3293 | 3295 | |
|
3294 | 3296 | |
|
3295 | 3297 | else: |
|
3296 | 3298 | meteorAux[0:4] = [mHeight, mStart, mPeak, mEnd] |
|
3297 | 3299 | meteorAux[-1] = 6 #Error Number 6: echo less than 5 samples long; too short for analysis |
|
3298 | 3300 | PowerSeries = 0 |
|
3299 | 3301 | |
|
3300 | 3302 | listMeteors1.append(meteorAux) |
|
3301 | 3303 | listPowerSeries.append(PowerSeries) |
|
3302 | 3304 | listVoltageSeries.append(meteorVolts1) |
|
3303 | 3305 | |
|
3304 | 3306 | return listMeteors1, listPowerSeries, listVoltageSeries |
|
3305 | 3307 | |
|
3306 | 3308 | def __estimateDecayTime(self, listMeteors, listPower, timeInterval, frequency): |
|
3307 | 3309 | |
|
3308 | 3310 | threshError = 10 |
|
3309 | 3311 | #Depending if it is 30 or 50 MHz |
|
3310 | 3312 | if frequency == 30e6: |
|
3311 | 3313 | timeLag = 45*10**-3 |
|
3312 | 3314 | else: |
|
3313 | 3315 | timeLag = 15*10**-3 |
|
3314 | 3316 | lag = numpy.ceil(timeLag/timeInterval) |
|
3315 | 3317 | |
|
3316 | 3318 | listMeteors1 = [] |
|
3317 | 3319 | |
|
3318 | 3320 | for i in range(len(listMeteors)): |
|
3319 | 3321 | meteorPower = listPower[i] |
|
3320 | 3322 | meteorAux = listMeteors[i] |
|
3321 | 3323 | |
|
3322 | 3324 | if meteorAux[-1] == 0: |
|
3323 | 3325 | |
|
3324 | 3326 | try: |
|
3325 | 3327 | indmax = meteorPower.argmax() |
|
3326 | 3328 | indlag = indmax + lag |
|
3327 | 3329 | |
|
3328 | 3330 | y = meteorPower[indlag:] |
|
3329 | 3331 | x = numpy.arange(0, y.size)*timeLag |
|
3330 | 3332 | |
|
3331 | 3333 | #first guess |
|
3332 | 3334 | a = y[0] |
|
3333 | 3335 | tau = timeLag |
|
3334 | 3336 | #exponential fit |
|
3335 | 3337 | popt, pcov = optimize.curve_fit(self.__exponential_function, x, y, p0 = [a, tau]) |
|
3336 | 3338 | y1 = self.__exponential_function(x, *popt) |
|
3337 | 3339 | #error estimation |
|
3338 | 3340 | error = sum((y - y1)**2)/(numpy.var(y)*(y.size - popt.size)) |
|
3339 | 3341 | |
|
3340 | 3342 | decayTime = popt[1] |
|
3341 | 3343 | riseTime = indmax*timeInterval |
|
3342 | 3344 | meteorAux[11:13] = [decayTime, error] |
|
3343 | 3345 | |
|
3344 | 3346 | #Table items 7, 8 and 11 |
|
3345 | 3347 | if (riseTime > 0.3): #Number 7: Echo rise exceeds 0.3s |
|
3346 | 3348 | meteorAux[-1] = 7 |
|
3347 | 3349 | elif (decayTime < 2*riseTime) : #Number 8: Echo decay time less than than twice rise time |
|
3348 | 3350 | meteorAux[-1] = 8 |
|
3349 | 3351 | if (error > threshError): #Number 11: Poor fit to amplitude for estimation of decay time |
|
3350 | 3352 | meteorAux[-1] = 11 |
|
3351 | 3353 | |
|
3352 | 3354 | |
|
3353 | 3355 | except: |
|
3354 | 3356 | meteorAux[-1] = 11 |
|
3355 | 3357 | |
|
3356 | 3358 | |
|
3357 | 3359 | listMeteors1.append(meteorAux) |
|
3358 | 3360 | |
|
3359 | 3361 | return listMeteors1 |
|
3360 | 3362 | |
|
3361 | 3363 | #Exponential Function |
|
3362 | 3364 | |
|
3363 | 3365 | def __exponential_function(self, x, a, tau): |
|
3364 | 3366 | y = a*numpy.exp(-x/tau) |
|
3365 | 3367 | return y |
|
3366 | 3368 | |
|
3367 | 3369 | def __getRadialVelocity(self, listMeteors, listVolts, radialStdThresh, pairslist, timeInterval): |
|
3368 | 3370 | |
|
3369 | 3371 | pairslist1 = list(pairslist) |
|
3370 | 3372 | pairslist1.append((0,1)) |
|
3371 | 3373 | pairslist1.append((3,4)) |
|
3372 | 3374 | numPairs = len(pairslist1) |
|
3373 | 3375 | #Time Lag |
|
3374 | 3376 | timeLag = 45*10**-3 |
|
3375 | 3377 | c = 3e8 |
|
3376 | 3378 | lag = numpy.ceil(timeLag/timeInterval) |
|
3377 | 3379 | freq = 30e6 |
|
3378 | 3380 | |
|
3379 | 3381 | listMeteors1 = [] |
|
3380 | 3382 | |
|
3381 | 3383 | for i in range(len(listMeteors)): |
|
3382 | 3384 | meteorAux = listMeteors[i] |
|
3383 | 3385 | if meteorAux[-1] == 0: |
|
3384 | 3386 | mStart = listMeteors[i][1] |
|
3385 | 3387 | mPeak = listMeteors[i][2] |
|
3386 | 3388 | mLag = mPeak - mStart + lag |
|
3387 | 3389 | |
|
3388 | 3390 | #get the volt data between the start and end times of the meteor |
|
3389 | 3391 | meteorVolts = listVolts[i] |
|
3390 | 3392 | meteorVolts = meteorVolts.reshape(meteorVolts.shape[0], meteorVolts.shape[1], 1) |
|
3391 | 3393 | |
|
3392 | 3394 | #Get CCF |
|
3393 | 3395 | allCCFs = self.__calculateCCF(meteorVolts, pairslist1, [-2,-1,0,1,2]) |
|
3394 | 3396 | |
|
3395 | 3397 | #Method 2 |
|
3396 | 3398 | slopes = numpy.zeros(numPairs) |
|
3397 | 3399 | time = numpy.array([-2,-1,1,2])*timeInterval |
|
3398 | 3400 | angAllCCF = numpy.angle(allCCFs[:,[0,1,3,4],0]) |
|
3399 | 3401 | |
|
3400 | 3402 | #Correct phases |
|
3401 | 3403 | derPhaseCCF = angAllCCF[:,1:] - angAllCCF[:,0:-1] |
|
3402 | 3404 | indDer = numpy.where(numpy.abs(derPhaseCCF) > numpy.pi) |
|
3403 | 3405 | |
|
3404 | 3406 | if indDer[0].shape[0] > 0: |
|
3405 | 3407 | for i in range(indDer[0].shape[0]): |
|
3406 | 3408 | signo = -numpy.sign(derPhaseCCF[indDer[0][i],indDer[1][i]]) |
|
3407 | 3409 | angAllCCF[indDer[0][i],indDer[1][i]+1:] += signo*2*numpy.pi |
|
3408 | 3410 | |
|
3409 | 3411 | # fit = scipy.stats.linregress(numpy.array([-2,-1,1,2])*timeInterval, numpy.array([phaseLagN2s[i],phaseLagN1s[i],phaseLag1s[i],phaseLag2s[i]])) |
|
3410 | 3412 | for j in range(numPairs): |
|
3411 | 3413 | fit = stats.linregress(time, angAllCCF[j,:]) |
|
3412 | 3414 | slopes[j] = fit[0] |
|
3413 | 3415 | |
|
3414 | 3416 | #Remove Outlier |
|
3415 | 3417 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) |
|
3416 | 3418 | # slopes = numpy.delete(slopes,indOut) |
|
3417 | 3419 | # indOut = numpy.argmax(numpy.abs(slopes - numpy.mean(slopes))) |
|
3418 | 3420 | # slopes = numpy.delete(slopes,indOut) |
|
3419 | 3421 | |
|
3420 | 3422 | radialVelocity = -numpy.mean(slopes)*(0.25/numpy.pi)*(c/freq) |
|
3421 | 3423 | radialError = numpy.std(slopes)*(0.25/numpy.pi)*(c/freq) |
|
3422 | 3424 | meteorAux[-2] = radialError |
|
3423 | 3425 | meteorAux[-3] = radialVelocity |
|
3424 | 3426 | |
|
3425 | 3427 | #Setting Error |
|
3426 | 3428 | #Number 15: Radial Drift velocity or projected horizontal velocity exceeds 200 m/s |
|
3427 | 3429 | if numpy.abs(radialVelocity) > 200: |
|
3428 | 3430 | meteorAux[-1] = 15 |
|
3429 | 3431 | #Number 12: Poor fit to CCF variation for estimation of radial drift velocity |
|
3430 | 3432 | elif radialError > radialStdThresh: |
|
3431 | 3433 | meteorAux[-1] = 12 |
|
3432 | 3434 | |
|
3433 | 3435 | listMeteors1.append(meteorAux) |
|
3434 | 3436 | return listMeteors1 |
|
3435 | 3437 | |
|
3436 | 3438 | def __setNewArrays(self, listMeteors, date, heiRang): |
|
3437 | 3439 | |
|
3438 | 3440 | #New arrays |
|
3439 | 3441 | arrayMeteors = numpy.array(listMeteors) |
|
3440 | 3442 | arrayParameters = numpy.zeros((len(listMeteors), 13)) |
|
3441 | 3443 | |
|
3442 | 3444 | #Date inclusion |
|
3443 | 3445 | # date = re.findall(r'\((.*?)\)', date) |
|
3444 | 3446 | # date = date[0].split(',') |
|
3445 | 3447 | # date = map(int, date) |
|
3446 | 3448 | # |
|
3447 | 3449 | # if len(date)<6: |
|
3448 | 3450 | # date.append(0) |
|
3449 | 3451 | # |
|
3450 | 3452 | # date = [date[0]*10000 + date[1]*100 + date[2], date[3]*10000 + date[4]*100 + date[5]] |
|
3451 | 3453 | # arrayDate = numpy.tile(date, (len(listMeteors), 1)) |
|
3452 | 3454 | arrayDate = numpy.tile(date, (len(listMeteors))) |
|
3453 | 3455 | |
|
3454 | 3456 | #Meteor array |
|
3455 | 3457 | # arrayMeteors[:,0] = heiRang[arrayMeteors[:,0].astype(int)] |
|
3456 | 3458 | # arrayMeteors = numpy.hstack((arrayDate, arrayMeteors)) |
|
3457 | 3459 | |
|
3458 | 3460 | #Parameters Array |
|
3459 | 3461 | arrayParameters[:,0] = arrayDate #Date |
|
3460 | 3462 | arrayParameters[:,1] = heiRang[arrayMeteors[:,0].astype(int)] #Range |
|
3461 | 3463 | arrayParameters[:,6:8] = arrayMeteors[:,-3:-1] #Radial velocity and its error |
|
3462 | 3464 | arrayParameters[:,8:12] = arrayMeteors[:,7:11] #Phases |
|
3463 | 3465 | arrayParameters[:,-1] = arrayMeteors[:,-1] #Error |
|
3464 | 3466 | |
|
3465 | 3467 | |
|
3466 | 3468 | return arrayParameters |
|
3467 | 3469 | |
|
3468 | 3470 | class CorrectSMPhases(Operation): |
|
3469 | 3471 | |
|
3470 | 3472 | def run(self, dataOut, phaseOffsets, hmin = 50, hmax = 150, azimuth = 45, channelPositions = None): |
|
3471 | 3473 | |
|
3472 | 3474 | arrayParameters = dataOut.data_param |
|
3473 | 3475 | pairsList = [] |
|
3474 | 3476 | pairx = (0,1) |
|
3475 | 3477 | pairy = (2,3) |
|
3476 | 3478 | pairsList.append(pairx) |
|
3477 | 3479 | pairsList.append(pairy) |
|
3478 | 3480 | jph = numpy.zeros(4) |
|
3479 | 3481 | |
|
3480 | 3482 | phaseOffsets = numpy.array(phaseOffsets)*numpy.pi/180 |
|
3481 | 3483 | # arrayParameters[:,8:12] = numpy.unwrap(arrayParameters[:,8:12] + phaseOffsets) |
|
3482 | 3484 | arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets))) |
|
3483 | 3485 | |
|
3484 | 3486 | meteorOps = SMOperations() |
|
3485 | 3487 | if channelPositions == None: |
|
3486 | 3488 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
3487 | 3489 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
3488 | 3490 | |
|
3489 | 3491 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
3490 | 3492 | h = (hmin,hmax) |
|
3491 | 3493 | |
|
3492 | 3494 | arrayParameters = meteorOps.getMeteorParams(arrayParameters, azimuth, h, pairsList, distances, jph) |
|
3493 | 3495 | |
|
3494 | 3496 | dataOut.data_param = arrayParameters |
|
3495 | 3497 | return |
|
3496 | 3498 | |
|
3497 | 3499 | class SMPhaseCalibration(Operation): |
|
3498 | 3500 | |
|
3499 | 3501 | __buffer = None |
|
3500 | 3502 | |
|
3501 | 3503 | __initime = None |
|
3502 | 3504 | |
|
3503 | 3505 | __dataReady = False |
|
3504 | 3506 | |
|
3505 | 3507 | __isConfig = False |
|
3506 | 3508 | |
|
3507 | 3509 | def __checkTime(self, currentTime, initTime, paramInterval, outputInterval): |
|
3508 | 3510 | |
|
3509 | 3511 | dataTime = currentTime + paramInterval |
|
3510 | 3512 | deltaTime = dataTime - initTime |
|
3511 | 3513 | |
|
3512 | 3514 | if deltaTime >= outputInterval or deltaTime < 0: |
|
3513 | 3515 | return True |
|
3514 | 3516 | |
|
3515 | 3517 | return False |
|
3516 | 3518 | |
|
3517 | 3519 | def __getGammas(self, pairs, d, phases): |
|
3518 | 3520 | gammas = numpy.zeros(2) |
|
3519 | 3521 | |
|
3520 | 3522 | for i in range(len(pairs)): |
|
3521 | 3523 | |
|
3522 | 3524 | pairi = pairs[i] |
|
3523 | 3525 | |
|
3524 | 3526 | phip3 = phases[:,pairi[1]] |
|
3525 | 3527 | d3 = d[pairi[1]] |
|
3526 | 3528 | phip2 = phases[:,pairi[0]] |
|
3527 | 3529 | d2 = d[pairi[0]] |
|
3528 | 3530 | #Calculating gamma |
|
3529 | 3531 | # jdcos = alp1/(k*d1) |
|
3530 | 3532 | # jgamma = numpy.angle(numpy.exp(1j*(d0*alp1/d1 - alp0))) |
|
3531 | 3533 | jgamma = -phip2*d3/d2 - phip3 |
|
3532 | 3534 | jgamma = numpy.angle(numpy.exp(1j*jgamma)) |
|
3533 | 3535 | # jgamma[jgamma>numpy.pi] -= 2*numpy.pi |
|
3534 | 3536 | # jgamma[jgamma<-numpy.pi] += 2*numpy.pi |
|
3535 | 3537 | |
|
3536 | 3538 | #Revised distribution |
|
3537 | 3539 | jgammaArray = numpy.hstack((jgamma,jgamma+0.5*numpy.pi,jgamma-0.5*numpy.pi)) |
|
3538 | 3540 | |
|
3539 | 3541 | #Histogram |
|
3540 | 3542 | nBins = 64.0 |
|
3541 | 3543 | rmin = -0.5*numpy.pi |
|
3542 | 3544 | rmax = 0.5*numpy.pi |
|
3543 | 3545 | phaseHisto = numpy.histogram(jgammaArray, bins=nBins, range=(rmin,rmax)) |
|
3544 | 3546 | |
|
3545 | 3547 | meteorsY = phaseHisto[0] |
|
3546 | 3548 | phasesX = phaseHisto[1][:-1] |
|
3547 | 3549 | width = phasesX[1] - phasesX[0] |
|
3548 | 3550 | phasesX += width/2 |
|
3549 | 3551 | |
|
3550 | 3552 | #Gaussian aproximation |
|
3551 | 3553 | bpeak = meteorsY.argmax() |
|
3552 | 3554 | peak = meteorsY.max() |
|
3553 | 3555 | jmin = bpeak - 5 |
|
3554 | 3556 | jmax = bpeak + 5 + 1 |
|
3555 | 3557 | |
|
3556 | 3558 | if jmin<0: |
|
3557 | 3559 | jmin = 0 |
|
3558 | 3560 | jmax = 6 |
|
3559 | 3561 | elif jmax > meteorsY.size: |
|
3560 | 3562 | jmin = meteorsY.size - 6 |
|
3561 | 3563 | jmax = meteorsY.size |
|
3562 | 3564 | |
|
3563 | 3565 | x0 = numpy.array([peak,bpeak,50]) |
|
3564 | 3566 | coeff = optimize.leastsq(self.__residualFunction, x0, args=(meteorsY[jmin:jmax], phasesX[jmin:jmax])) |
|
3565 | 3567 | |
|
3566 | 3568 | #Gammas |
|
3567 | 3569 | gammas[i] = coeff[0][1] |
|
3568 | 3570 | |
|
3569 | 3571 | return gammas |
|
3570 | 3572 | |
|
3571 | 3573 | def __residualFunction(self, coeffs, y, t): |
|
3572 | 3574 | |
|
3573 | 3575 | return y - self.__gauss_function(t, coeffs) |
|
3574 | 3576 | |
|
3575 | 3577 | def __gauss_function(self, t, coeffs): |
|
3576 | 3578 | |
|
3577 | 3579 | return coeffs[0]*numpy.exp(-0.5*((t - coeffs[1]) / coeffs[2])**2) |
|
3578 | 3580 | |
|
3579 | 3581 | def __getPhases(self, azimuth, h, pairsList, d, gammas, meteorsArray): |
|
3580 | 3582 | meteorOps = SMOperations() |
|
3581 | 3583 | nchan = 4 |
|
3582 | 3584 | pairx = pairsList[0] |
|
3583 | 3585 | pairy = pairsList[1] |
|
3584 | 3586 | center_xangle = 0 |
|
3585 | 3587 | center_yangle = 0 |
|
3586 | 3588 | range_angle = numpy.array([10*numpy.pi,numpy.pi,numpy.pi/2,numpy.pi/4]) |
|
3587 | 3589 | ntimes = len(range_angle) |
|
3588 | 3590 | |
|
3589 | 3591 | nstepsx = 20.0 |
|
3590 | 3592 | nstepsy = 20.0 |
|
3591 | 3593 | |
|
3592 | 3594 | for iz in range(ntimes): |
|
3593 | 3595 | min_xangle = -range_angle[iz]/2 + center_xangle |
|
3594 | 3596 | max_xangle = range_angle[iz]/2 + center_xangle |
|
3595 | 3597 | min_yangle = -range_angle[iz]/2 + center_yangle |
|
3596 | 3598 | max_yangle = range_angle[iz]/2 + center_yangle |
|
3597 | 3599 | |
|
3598 | 3600 | inc_x = (max_xangle-min_xangle)/nstepsx |
|
3599 | 3601 | inc_y = (max_yangle-min_yangle)/nstepsy |
|
3600 | 3602 | |
|
3601 | 3603 | alpha_y = numpy.arange(nstepsy)*inc_y + min_yangle |
|
3602 | 3604 | alpha_x = numpy.arange(nstepsx)*inc_x + min_xangle |
|
3603 | 3605 | penalty = numpy.zeros((nstepsx,nstepsy)) |
|
3604 | 3606 | jph_array = numpy.zeros((nchan,nstepsx,nstepsy)) |
|
3605 | 3607 | jph = numpy.zeros(nchan) |
|
3606 | 3608 | |
|
3607 | 3609 | # Iterations looking for the offset |
|
3608 | 3610 | for iy in range(int(nstepsy)): |
|
3609 | 3611 | for ix in range(int(nstepsx)): |
|
3610 | 3612 | jph[pairy[1]] = alpha_y[iy] |
|
3611 | 3613 | jph[pairy[0]] = -gammas[1] - alpha_y[iy]*d[pairy[1]]/d[pairy[0]] |
|
3612 | 3614 | |
|
3613 | 3615 | jph[pairx[1]] = alpha_x[ix] |
|
3614 | 3616 | jph[pairx[0]] = -gammas[0] - alpha_x[ix]*d[pairx[1]]/d[pairx[0]] |
|
3615 | 3617 | |
|
3616 | 3618 | jph_array[:,ix,iy] = jph |
|
3617 | 3619 | |
|
3618 | 3620 | meteorsArray1 = meteorOps.getMeteorParams(meteorsArray, azimuth, h, pairsList, d, jph) |
|
3619 | 3621 | error = meteorsArray1[:,-1] |
|
3620 | 3622 | ind1 = numpy.where(error==0)[0] |
|
3621 | 3623 | penalty[ix,iy] = ind1.size |
|
3622 | 3624 | |
|
3623 | 3625 | i,j = numpy.unravel_index(penalty.argmax(), penalty.shape) |
|
3624 | 3626 | phOffset = jph_array[:,i,j] |
|
3625 | 3627 | |
|
3626 | 3628 | center_xangle = phOffset[pairx[1]] |
|
3627 | 3629 | center_yangle = phOffset[pairy[1]] |
|
3628 | 3630 | |
|
3629 | 3631 | phOffset = numpy.angle(numpy.exp(1j*jph_array[:,i,j])) |
|
3630 | 3632 | phOffset = phOffset*180/numpy.pi |
|
3631 | 3633 | return phOffset |
|
3632 | 3634 | |
|
3633 | 3635 | |
|
3634 | 3636 | def run(self, dataOut, hmin, hmax, channelPositions=None, nHours = 1): |
|
3635 | 3637 | |
|
3636 | 3638 | dataOut.flagNoData = True |
|
3637 | 3639 | self.__dataReady = False |
|
3638 | 3640 | dataOut.outputInterval = nHours*3600 |
|
3639 | 3641 | |
|
3640 | 3642 | if self.__isConfig == False: |
|
3641 | 3643 | # self.__initime = dataOut.datatime.replace(minute = 0, second = 0, microsecond = 03) |
|
3642 | 3644 | #Get Initial LTC time |
|
3643 | 3645 | self.__initime = datetime.datetime.utcfromtimestamp(dataOut.utctime) |
|
3644 | 3646 | self.__initime = (self.__initime.replace(minute = 0, second = 0, microsecond = 0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
3645 | 3647 | |
|
3646 | 3648 | self.__isConfig = True |
|
3647 | 3649 | |
|
3648 | 3650 | if self.__buffer == None: |
|
3649 | 3651 | self.__buffer = dataOut.data_param.copy() |
|
3650 | 3652 | |
|
3651 | 3653 | else: |
|
3652 | 3654 | self.__buffer = numpy.vstack((self.__buffer, dataOut.data_param)) |
|
3653 | 3655 | |
|
3654 | 3656 | self.__dataReady = self.__checkTime(dataOut.utctime, self.__initime, dataOut.paramInterval, dataOut.outputInterval) #Check if the buffer is ready |
|
3655 | 3657 | |
|
3656 | 3658 | if self.__dataReady: |
|
3657 | 3659 | dataOut.utctimeInit = self.__initime |
|
3658 | 3660 | self.__initime += dataOut.outputInterval #to erase time offset |
|
3659 | 3661 | |
|
3660 | 3662 | freq = dataOut.frequency |
|
3661 | 3663 | c = dataOut.C #m/s |
|
3662 | 3664 | lamb = c/freq |
|
3663 | 3665 | k = 2*numpy.pi/lamb |
|
3664 | 3666 | azimuth = 0 |
|
3665 | 3667 | h = (hmin, hmax) |
|
3666 | 3668 | pairs = ((0,1),(2,3)) |
|
3667 | 3669 | |
|
3668 | 3670 | if channelPositions == None: |
|
3669 | 3671 | # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T |
|
3670 | 3672 | channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella |
|
3671 | 3673 | meteorOps = SMOperations() |
|
3672 | 3674 | pairslist0, distances = meteorOps.getPhasePairs(channelPositions) |
|
3673 | 3675 | |
|
3674 | 3676 | # distances1 = [-distances[0]*lamb, distances[1]*lamb, -distances[2]*lamb, distances[3]*lamb] |
|
3675 | 3677 | |
|
3676 | 3678 | meteorsArray = self.__buffer |
|
3677 | 3679 | error = meteorsArray[:,-1] |
|
3678 | 3680 | boolError = (error==0)|(error==3)|(error==4)|(error==13)|(error==14) |
|
3679 | 3681 | ind1 = numpy.where(boolError)[0] |
|
3680 | 3682 | meteorsArray = meteorsArray[ind1,:] |
|
3681 | 3683 | meteorsArray[:,-1] = 0 |
|
3682 | 3684 | phases = meteorsArray[:,8:12] |
|
3683 | 3685 | |
|
3684 | 3686 | #Calculate Gammas |
|
3685 | 3687 | gammas = self.__getGammas(pairs, distances, phases) |
|
3686 | 3688 | # gammas = numpy.array([-21.70409463,45.76935864])*numpy.pi/180 |
|
3687 | 3689 | #Calculate Phases |
|
3688 | 3690 | phasesOff = self.__getPhases(azimuth, h, pairs, distances, gammas, meteorsArray) |
|
3689 | 3691 | phasesOff = phasesOff.reshape((1,phasesOff.size)) |
|
3690 | 3692 | dataOut.data_output = -phasesOff |
|
3691 | 3693 | dataOut.flagNoData = False |
|
3692 | 3694 | self.__buffer = None |
|
3693 | 3695 | |
|
3694 | 3696 | |
|
3695 | 3697 | return |
|
3696 | 3698 | |
|
3697 | 3699 | class SMOperations(): |
|
3698 | 3700 | |
|
3699 | 3701 | def __init__(self): |
|
3700 | 3702 | |
|
3701 | 3703 | return |
|
3702 | 3704 | |
|
3703 | 3705 | def getMeteorParams(self, arrayParameters0, azimuth, h, pairsList, distances, jph): |
|
3704 | 3706 | |
|
3705 | 3707 | arrayParameters = arrayParameters0.copy() |
|
3706 | 3708 | hmin = h[0] |
|
3707 | 3709 | hmax = h[1] |
|
3708 | 3710 | |
|
3709 | 3711 | #Calculate AOA (Error N 3, 4) |
|
3710 | 3712 | #JONES ET AL. 1998 |
|
3711 | 3713 | AOAthresh = numpy.pi/8 |
|
3712 | 3714 | error = arrayParameters[:,-1] |
|
3713 | 3715 | phases = -arrayParameters[:,8:12] + jph |
|
3714 | 3716 | # phases = numpy.unwrap(phases) |
|
3715 | 3717 | arrayParameters[:,3:6], arrayParameters[:,-1] = self.__getAOA(phases, pairsList, distances, error, AOAthresh, azimuth) |
|
3716 | 3718 | |
|
3717 | 3719 | #Calculate Heights (Error N 13 and 14) |
|
3718 | 3720 | error = arrayParameters[:,-1] |
|
3719 | 3721 | Ranges = arrayParameters[:,1] |
|
3720 | 3722 | zenith = arrayParameters[:,4] |
|
3721 | 3723 | arrayParameters[:,2], arrayParameters[:,-1] = self.__getHeights(Ranges, zenith, error, hmin, hmax) |
|
3722 | 3724 | |
|
3723 | 3725 | #----------------------- Get Final data ------------------------------------ |
|
3724 | 3726 | # error = arrayParameters[:,-1] |
|
3725 | 3727 | # ind1 = numpy.where(error==0)[0] |
|
3726 | 3728 | # arrayParameters = arrayParameters[ind1,:] |
|
3727 | 3729 | |
|
3728 | 3730 | return arrayParameters |
|
3729 | 3731 | |
|
3730 | 3732 | def __getAOA(self, phases, pairsList, directions, error, AOAthresh, azimuth): |
|
3731 | 3733 | |
|
3732 | 3734 | arrayAOA = numpy.zeros((phases.shape[0],3)) |
|
3733 | 3735 | cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList,directions) |
|
3734 | 3736 | |
|
3735 | 3737 | arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) |
|
3736 | 3738 | cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) |
|
3737 | 3739 | arrayAOA[:,2] = cosDirError |
|
3738 | 3740 | |
|
3739 | 3741 | azimuthAngle = arrayAOA[:,0] |
|
3740 | 3742 | zenithAngle = arrayAOA[:,1] |
|
3741 | 3743 | |
|
3742 | 3744 | #Setting Error |
|
3743 | 3745 | indError = numpy.where(numpy.logical_or(error == 3, error == 4))[0] |
|
3744 | 3746 | error[indError] = 0 |
|
3745 | 3747 | #Number 3: AOA not fesible |
|
3746 | 3748 | indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] |
|
3747 | 3749 | error[indInvalid] = 3 |
|
3748 | 3750 | #Number 4: Large difference in AOAs obtained from different antenna baselines |
|
3749 | 3751 | indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] |
|
3750 | 3752 | error[indInvalid] = 4 |
|
3751 | 3753 | return arrayAOA, error |
|
3752 | 3754 | |
|
3753 | 3755 | def __getDirectionCosines(self, arrayPhase, pairsList, distances): |
|
3754 | 3756 | |
|
3755 | 3757 | #Initializing some variables |
|
3756 | 3758 | ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi |
|
3757 | 3759 | ang_aux = ang_aux.reshape(1,ang_aux.size) |
|
3758 | 3760 | |
|
3759 | 3761 | cosdir = numpy.zeros((arrayPhase.shape[0],2)) |
|
3760 | 3762 | cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) |
|
3761 | 3763 | |
|
3762 | 3764 | |
|
3763 | 3765 | for i in range(2): |
|
3764 | 3766 | ph0 = arrayPhase[:,pairsList[i][0]] |
|
3765 | 3767 | ph1 = arrayPhase[:,pairsList[i][1]] |
|
3766 | 3768 | d0 = distances[pairsList[i][0]] |
|
3767 | 3769 | d1 = distances[pairsList[i][1]] |
|
3768 | 3770 | |
|
3769 | 3771 | ph0_aux = ph0 + ph1 |
|
3770 | 3772 | ph0_aux = numpy.angle(numpy.exp(1j*ph0_aux)) |
|
3771 | 3773 | # ph0_aux[ph0_aux > numpy.pi] -= 2*numpy.pi |
|
3772 | 3774 | # ph0_aux[ph0_aux < -numpy.pi] += 2*numpy.pi |
|
3773 | 3775 | #First Estimation |
|
3774 | 3776 | cosdir0[:,i] = (ph0_aux)/(2*numpy.pi*(d0 - d1)) |
|
3775 | 3777 | |
|
3776 | 3778 | #Most-Accurate Second Estimation |
|
3777 | 3779 | phi1_aux = ph0 - ph1 |
|
3778 | 3780 | phi1_aux = phi1_aux.reshape(phi1_aux.size,1) |
|
3779 | 3781 | #Direction Cosine 1 |
|
3780 | 3782 | cosdir1 = (phi1_aux + ang_aux)/(2*numpy.pi*(d0 + d1)) |
|
3781 | 3783 | |
|
3782 | 3784 | #Searching the correct Direction Cosine |
|
3783 | 3785 | cosdir0_aux = cosdir0[:,i] |
|
3784 | 3786 | cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) |
|
3785 | 3787 | #Minimum Distance |
|
3786 | 3788 | cosDiff = (cosdir1 - cosdir0_aux)**2 |
|
3787 | 3789 | indcos = cosDiff.argmin(axis = 1) |
|
3788 | 3790 | #Saving Value obtained |
|
3789 | 3791 | cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] |
|
3790 | 3792 | |
|
3791 | 3793 | return cosdir0, cosdir |
|
3792 | 3794 | |
|
3793 | 3795 | def __calculateAOA(self, cosdir, azimuth): |
|
3794 | 3796 | cosdirX = cosdir[:,0] |
|
3795 | 3797 | cosdirY = cosdir[:,1] |
|
3796 | 3798 | |
|
3797 | 3799 | zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi |
|
3798 | 3800 | azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth#0 deg north, 90 deg east |
|
3799 | 3801 | angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() |
|
3800 | 3802 | |
|
3801 | 3803 | return angles |
|
3802 | 3804 | |
|
3803 | 3805 | def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): |
|
3804 | 3806 | |
|
3805 | 3807 | Ramb = 375 #Ramb = c/(2*PRF) |
|
3806 | 3808 | Re = 6371 #Earth Radius |
|
3807 | 3809 | heights = numpy.zeros(Ranges.shape) |
|
3808 | 3810 | |
|
3809 | 3811 | R_aux = numpy.array([0,1,2])*Ramb |
|
3810 | 3812 | R_aux = R_aux.reshape(1,R_aux.size) |
|
3811 | 3813 | |
|
3812 | 3814 | Ranges = Ranges.reshape(Ranges.size,1) |
|
3813 | 3815 | |
|
3814 | 3816 | Ri = Ranges + R_aux |
|
3815 | 3817 | hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re |
|
3816 | 3818 | |
|
3817 | 3819 | #Check if there is a height between 70 and 110 km |
|
3818 | 3820 | h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) |
|
3819 | 3821 | ind_h = numpy.where(h_bool == 1)[0] |
|
3820 | 3822 | |
|
3821 | 3823 | hCorr = hi[ind_h, :] |
|
3822 | 3824 | ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) |
|
3823 | 3825 | |
|
3824 | 3826 | hCorr = hi[ind_hCorr] |
|
3825 | 3827 | heights[ind_h] = hCorr |
|
3826 | 3828 | |
|
3827 | 3829 | #Setting Error |
|
3828 | 3830 | #Number 13: Height unresolvable echo: not valid height within 70 to 110 km |
|
3829 | 3831 | #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km |
|
3830 | 3832 | indError = numpy.where(numpy.logical_or(error == 13, error == 14))[0] |
|
3831 | 3833 | error[indError] = 0 |
|
3832 | 3834 | indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] |
|
3833 | 3835 | error[indInvalid2] = 14 |
|
3834 | 3836 | indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] |
|
3835 | 3837 | error[indInvalid1] = 13 |
|
3836 | 3838 | |
|
3837 | 3839 | return heights, error |
|
3838 | 3840 | |
|
3839 | 3841 | def getPhasePairs(self, channelPositions): |
|
3840 | 3842 | chanPos = numpy.array(channelPositions) |
|
3841 | 3843 | listOper = list(itertools.combinations(range(5),2)) |
|
3842 | 3844 | |
|
3843 | 3845 | distances = numpy.zeros(4) |
|
3844 | 3846 | axisX = [] |
|
3845 | 3847 | axisY = [] |
|
3846 | 3848 | distX = numpy.zeros(3) |
|
3847 | 3849 | distY = numpy.zeros(3) |
|
3848 | 3850 | ix = 0 |
|
3849 | 3851 | iy = 0 |
|
3850 | 3852 | |
|
3851 | 3853 | pairX = numpy.zeros((2,2)) |
|
3852 | 3854 | pairY = numpy.zeros((2,2)) |
|
3853 | 3855 | |
|
3854 | 3856 | for i in range(len(listOper)): |
|
3855 | 3857 | pairi = listOper[i] |
|
3856 | 3858 | |
|
3857 | 3859 | posDif = numpy.abs(chanPos[pairi[0],:] - chanPos[pairi[1],:]) |
|
3858 | 3860 | |
|
3859 | 3861 | if posDif[0] == 0: |
|
3860 | 3862 | axisY.append(pairi) |
|
3861 | 3863 | distY[iy] = posDif[1] |
|
3862 | 3864 | iy += 1 |
|
3863 | 3865 | elif posDif[1] == 0: |
|
3864 | 3866 | axisX.append(pairi) |
|
3865 | 3867 | distX[ix] = posDif[0] |
|
3866 | 3868 | ix += 1 |
|
3867 | 3869 | |
|
3868 | 3870 | for i in range(2): |
|
3869 | 3871 | if i==0: |
|
3870 | 3872 | dist0 = distX |
|
3871 | 3873 | axis0 = axisX |
|
3872 | 3874 | else: |
|
3873 | 3875 | dist0 = distY |
|
3874 | 3876 | axis0 = axisY |
|
3875 | 3877 | |
|
3876 | 3878 | side = numpy.argsort(dist0)[:-1] |
|
3877 | 3879 | axis0 = numpy.array(axis0)[side,:] |
|
3878 | 3880 | chanC = int(numpy.intersect1d(axis0[0,:], axis0[1,:])[0]) |
|
3879 | 3881 | axis1 = numpy.unique(numpy.reshape(axis0,4)) |
|
3880 | 3882 | side = axis1[axis1 != chanC] |
|
3881 | 3883 | diff1 = chanPos[chanC,i] - chanPos[side[0],i] |
|
3882 | 3884 | diff2 = chanPos[chanC,i] - chanPos[side[1],i] |
|
3883 | 3885 | if diff1<0: |
|
3884 | 3886 | chan2 = side[0] |
|
3885 | 3887 | d2 = numpy.abs(diff1) |
|
3886 | 3888 | chan1 = side[1] |
|
3887 | 3889 | d1 = numpy.abs(diff2) |
|
3888 | 3890 | else: |
|
3889 | 3891 | chan2 = side[1] |
|
3890 | 3892 | d2 = numpy.abs(diff2) |
|
3891 | 3893 | chan1 = side[0] |
|
3892 | 3894 | d1 = numpy.abs(diff1) |
|
3893 | 3895 | |
|
3894 | 3896 | if i==0: |
|
3895 | 3897 | chanCX = chanC |
|
3896 | 3898 | chan1X = chan1 |
|
3897 | 3899 | chan2X = chan2 |
|
3898 | 3900 | distances[0:2] = numpy.array([d1,d2]) |
|
3899 | 3901 | else: |
|
3900 | 3902 | chanCY = chanC |
|
3901 | 3903 | chan1Y = chan1 |
|
3902 | 3904 | chan2Y = chan2 |
|
3903 | 3905 | distances[2:4] = numpy.array([d1,d2]) |
|
3904 | 3906 | # axisXsides = numpy.reshape(axisX[ix,:],4) |
|
3905 | 3907 | # |
|
3906 | 3908 | # channelCentX = int(numpy.intersect1d(pairX[0,:], pairX[1,:])[0]) |
|
3907 | 3909 | # channelCentY = int(numpy.intersect1d(pairY[0,:], pairY[1,:])[0]) |
|
3908 | 3910 | # |
|
3909 | 3911 | # ind25X = numpy.where(pairX[0,:] != channelCentX)[0][0] |
|
3910 | 3912 | # ind20X = numpy.where(pairX[1,:] != channelCentX)[0][0] |
|
3911 | 3913 | # channel25X = int(pairX[0,ind25X]) |
|
3912 | 3914 | # channel20X = int(pairX[1,ind20X]) |
|
3913 | 3915 | # ind25Y = numpy.where(pairY[0,:] != channelCentY)[0][0] |
|
3914 | 3916 | # ind20Y = numpy.where(pairY[1,:] != channelCentY)[0][0] |
|
3915 | 3917 | # channel25Y = int(pairY[0,ind25Y]) |
|
3916 | 3918 | # channel20Y = int(pairY[1,ind20Y]) |
|
3917 | 3919 | |
|
3918 | 3920 | # pairslist = [(channelCentX, channel25X),(channelCentX, channel20X),(channelCentY,channel25Y),(channelCentY, channel20Y)] |
|
3919 | 3921 | pairslist = [(chanCX, chan1X),(chanCX, chan2X),(chanCY,chan1Y),(chanCY, chan2Y)] |
|
3920 | 3922 | |
|
3921 | 3923 | return pairslist, distances |
|
3922 | 3924 | # def __getAOA(self, phases, pairsList, error, AOAthresh, azimuth): |
|
3923 | 3925 | # |
|
3924 | 3926 | # arrayAOA = numpy.zeros((phases.shape[0],3)) |
|
3925 | 3927 | # cosdir0, cosdir = self.__getDirectionCosines(phases, pairsList) |
|
3926 | 3928 | # |
|
3927 | 3929 | # arrayAOA[:,:2] = self.__calculateAOA(cosdir, azimuth) |
|
3928 | 3930 | # cosDirError = numpy.sum(numpy.abs(cosdir0 - cosdir), axis = 1) |
|
3929 | 3931 | # arrayAOA[:,2] = cosDirError |
|
3930 | 3932 | # |
|
3931 | 3933 | # azimuthAngle = arrayAOA[:,0] |
|
3932 | 3934 | # zenithAngle = arrayAOA[:,1] |
|
3933 | 3935 | # |
|
3934 | 3936 | # #Setting Error |
|
3935 | 3937 | # #Number 3: AOA not fesible |
|
3936 | 3938 | # indInvalid = numpy.where(numpy.logical_and((numpy.logical_or(numpy.isnan(zenithAngle), numpy.isnan(azimuthAngle))),error == 0))[0] |
|
3937 | 3939 | # error[indInvalid] = 3 |
|
3938 | 3940 | # #Number 4: Large difference in AOAs obtained from different antenna baselines |
|
3939 | 3941 | # indInvalid = numpy.where(numpy.logical_and(cosDirError > AOAthresh,error == 0))[0] |
|
3940 | 3942 | # error[indInvalid] = 4 |
|
3941 | 3943 | # return arrayAOA, error |
|
3942 | 3944 | # |
|
3943 | 3945 | # def __getDirectionCosines(self, arrayPhase, pairsList): |
|
3944 | 3946 | # |
|
3945 | 3947 | # #Initializing some variables |
|
3946 | 3948 | # ang_aux = numpy.array([-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8])*2*numpy.pi |
|
3947 | 3949 | # ang_aux = ang_aux.reshape(1,ang_aux.size) |
|
3948 | 3950 | # |
|
3949 | 3951 | # cosdir = numpy.zeros((arrayPhase.shape[0],2)) |
|
3950 | 3952 | # cosdir0 = numpy.zeros((arrayPhase.shape[0],2)) |
|
3951 | 3953 | # |
|
3952 | 3954 | # |
|
3953 | 3955 | # for i in range(2): |
|
3954 | 3956 | # #First Estimation |
|
3955 | 3957 | # phi0_aux = arrayPhase[:,pairsList[i][0]] + arrayPhase[:,pairsList[i][1]] |
|
3956 | 3958 | # #Dealias |
|
3957 | 3959 | # indcsi = numpy.where(phi0_aux > numpy.pi) |
|
3958 | 3960 | # phi0_aux[indcsi] -= 2*numpy.pi |
|
3959 | 3961 | # indcsi = numpy.where(phi0_aux < -numpy.pi) |
|
3960 | 3962 | # phi0_aux[indcsi] += 2*numpy.pi |
|
3961 | 3963 | # #Direction Cosine 0 |
|
3962 | 3964 | # cosdir0[:,i] = -(phi0_aux)/(2*numpy.pi*0.5) |
|
3963 | 3965 | # |
|
3964 | 3966 | # #Most-Accurate Second Estimation |
|
3965 | 3967 | # phi1_aux = arrayPhase[:,pairsList[i][0]] - arrayPhase[:,pairsList[i][1]] |
|
3966 | 3968 | # phi1_aux = phi1_aux.reshape(phi1_aux.size,1) |
|
3967 | 3969 | # #Direction Cosine 1 |
|
3968 | 3970 | # cosdir1 = -(phi1_aux + ang_aux)/(2*numpy.pi*4.5) |
|
3969 | 3971 | # |
|
3970 | 3972 | # #Searching the correct Direction Cosine |
|
3971 | 3973 | # cosdir0_aux = cosdir0[:,i] |
|
3972 | 3974 | # cosdir0_aux = cosdir0_aux.reshape(cosdir0_aux.size,1) |
|
3973 | 3975 | # #Minimum Distance |
|
3974 | 3976 | # cosDiff = (cosdir1 - cosdir0_aux)**2 |
|
3975 | 3977 | # indcos = cosDiff.argmin(axis = 1) |
|
3976 | 3978 | # #Saving Value obtained |
|
3977 | 3979 | # cosdir[:,i] = cosdir1[numpy.arange(len(indcos)),indcos] |
|
3978 | 3980 | # |
|
3979 | 3981 | # return cosdir0, cosdir |
|
3980 | 3982 | # |
|
3981 | 3983 | # def __calculateAOA(self, cosdir, azimuth): |
|
3982 | 3984 | # cosdirX = cosdir[:,0] |
|
3983 | 3985 | # cosdirY = cosdir[:,1] |
|
3984 | 3986 | # |
|
3985 | 3987 | # zenithAngle = numpy.arccos(numpy.sqrt(1 - cosdirX**2 - cosdirY**2))*180/numpy.pi |
|
3986 | 3988 | # azimuthAngle = numpy.arctan2(cosdirX,cosdirY)*180/numpy.pi + azimuth #0 deg north, 90 deg east |
|
3987 | 3989 | # angles = numpy.vstack((azimuthAngle, zenithAngle)).transpose() |
|
3988 | 3990 | # |
|
3989 | 3991 | # return angles |
|
3990 | 3992 | # |
|
3991 | 3993 | # def __getHeights(self, Ranges, zenith, error, minHeight, maxHeight): |
|
3992 | 3994 | # |
|
3993 | 3995 | # Ramb = 375 #Ramb = c/(2*PRF) |
|
3994 | 3996 | # Re = 6371 #Earth Radius |
|
3995 | 3997 | # heights = numpy.zeros(Ranges.shape) |
|
3996 | 3998 | # |
|
3997 | 3999 | # R_aux = numpy.array([0,1,2])*Ramb |
|
3998 | 4000 | # R_aux = R_aux.reshape(1,R_aux.size) |
|
3999 | 4001 | # |
|
4000 | 4002 | # Ranges = Ranges.reshape(Ranges.size,1) |
|
4001 | 4003 | # |
|
4002 | 4004 | # Ri = Ranges + R_aux |
|
4003 | 4005 | # hi = numpy.sqrt(Re**2 + Ri**2 + (2*Re*numpy.cos(zenith*numpy.pi/180)*Ri.transpose()).transpose()) - Re |
|
4004 | 4006 | # |
|
4005 | 4007 | # #Check if there is a height between 70 and 110 km |
|
4006 | 4008 | # h_bool = numpy.sum(numpy.logical_and(hi > minHeight, hi < maxHeight), axis = 1) |
|
4007 | 4009 | # ind_h = numpy.where(h_bool == 1)[0] |
|
4008 | 4010 | # |
|
4009 | 4011 | # hCorr = hi[ind_h, :] |
|
4010 | 4012 | # ind_hCorr = numpy.where(numpy.logical_and(hi > minHeight, hi < maxHeight)) |
|
4011 | 4013 | # |
|
4012 | 4014 | # hCorr = hi[ind_hCorr] |
|
4013 | 4015 | # heights[ind_h] = hCorr |
|
4014 | 4016 | # |
|
4015 | 4017 | # #Setting Error |
|
4016 | 4018 | # #Number 13: Height unresolvable echo: not valid height within 70 to 110 km |
|
4017 | 4019 | # #Number 14: Height ambiguous echo: more than one possible height within 70 to 110 km |
|
4018 | 4020 | # |
|
4019 | 4021 | # indInvalid2 = numpy.where(numpy.logical_and(h_bool > 1, error == 0))[0] |
|
4020 | 4022 | # error[indInvalid2] = 14 |
|
4021 | 4023 | # indInvalid1 = numpy.where(numpy.logical_and(h_bool == 0, error == 0))[0] |
|
4022 | 4024 | # error[indInvalid1] = 13 |
|
4023 | 4025 | # |
|
4024 | 4026 | # return heights, error |
|
4025 | 4027 | No newline at end of file |
@@ -1,1 +1,1 | |||
|
1 |
<Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/data/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/ |
|
|
1 | <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="SpectraReader" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/data/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/2018" /><Parameter format="date" id="191113" name="startDate" value="2018/01/26" /><Parameter format="date" id="191114" name="endDate" value="2018/01/26" /><Parameter format="time" id="191115" name="startTime" value="17:45:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="1" /></Operation><Operation id="19112" name="printInfo" priority="2" type="self" /><Operation id="19113" name="printNumberOfBlock" priority="3" type="self" /></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1912" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralFilters" priority="2" type="other"><Parameter format="float" id="191321" name="PositiveLimit" value="1.5" /><Parameter format="float" id="191322" name="NegativeLimit" value="12.5" /></Operation><Operation id="19133" name="PrecipitationProc" priority="3" type="other" /><Operation id="19134" name="ParametersPlot" priority="4" type="other"><Parameter format="int" id="191341" name="id" value="10" /><Parameter format="str" id="191342" name="wintitle" value="First_gg" /><Parameter format="str" id="191343" name="colormap" value="ocean_r" /><Parameter format="int" id="191344" name="zmin" value="00" /><Parameter format="int" id="191345" name="zmax" value="40" /><Parameter format="int" id="191346" name="ymin" value="0" /><Parameter format="int" id="191347" name="ymax" value="11" /><Parameter format="int" id="191348" name="xmin" value="17" /><Parameter format="int" id="191349" name="xmax" value="24" /><Parameter format="int" id="191350" name="save" value="1" /><Parameter format="str" id="191351" name="figpath" value="/data/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdataCLAIRE/2018" /></Operation><Operation id="19135" name="SpcParamPlot" priority="5" type="other"><Parameter format="int" id="191351" name="id" value="21" /><Parameter format="str" id="191352" name="wintitle" value="Primer eco removido" /><Parameter format="str" id="191353" name="xaxis" value="velocity" /><Parameter format="int" id="191354" name="showprofile" value="1" /><Parameter format="int" id="191355" name="zmin" value="10" /><Parameter format="int" id="191356" name="zmax" value="40" /><Parameter format="int" id="191357" name="ymin" value="0" /><Parameter format="int" id="191358" name="ymax" value="10" /><Parameter format="int" id="191359" name="Selector" value="1" /></Operation></ProcUnit><ProcUnit datatype="SpectraProc" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="191221" name="frequency" value="445.09e6" /></Operation></ProcUnit></Project> No newline at end of file |
@@ -1,63 +1,40 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Nov 09, 2016 |
|
3 | 3 | |
|
4 | 4 | @author: roj- LouVD |
|
5 | 5 | ''' |
|
6 | 6 | import os, sys |
|
7 | from time import sleep | |
|
7 | 8 | |
|
8 | 9 | |
|
9 | 10 | path = os.path.split(os.getcwd())[0] |
|
10 | 11 | path = os.path.split(path)[0] |
|
11 | 12 | |
|
12 | 13 | sys.path.insert(0, path) |
|
13 | 14 | |
|
14 | 15 | from schainpy.controller import Project |
|
15 | 16 | |
|
16 | 17 | filename = 'test1.xml' |
|
17 | 18 | # path = '/home/jespinoza/workspace/data/bltr/' |
|
18 |
path = '/ |
|
|
19 | path = '/data/BLTR/nuevos_datos/'#'/media/erick/6F60F7113095A154/BLTR/' | |
|
19 | 20 | desc = "read bltr data sswma file" |
|
20 | figpath = '/media/erick/6F60F7113095A154/BLTR/' | |
|
21 | figpath = '/data/BLTR/nuevos_datos/' | |
|
21 | 22 | pathhdf5 = '/tmp/' |
|
22 | 23 | |
|
23 | controllerObj = Project() | |
|
24 | ||
|
25 |
controller |
|
|
26 | readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRParamReader', | |
|
27 | path=path, | |
|
28 | startDate='2017/01/17', | |
|
29 | endDate='2018/01/01', | |
|
30 | startTime='06:00:00', | |
|
31 | endTime='23:59:59', | |
|
32 | verbose=0, | |
|
33 | ) | |
|
34 | ||
|
35 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='BLTRParametersProc', | |
|
36 | inputId=readUnitConfObj.getId()) | |
|
37 | ||
|
38 | procUnitConfObj1.addParameter(name='mode', value='1', format='int') | |
|
39 | # procUnitConfObj1.addParameter(name='snr_threshold', value='10', format='float') | |
|
40 | ||
|
41 | ||
|
42 | opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other') | |
|
43 | opObj10.addParameter(name='id', value='2', format='int') | |
|
44 | opObj10.addParameter(name='wintitle', value='', format='str') | |
|
45 | ||
|
46 | # opObj10.addParameter(name='save', value='1', format='bool') | |
|
47 | # opObj10.addParameter(name='figpath', value=figpath, format='str') | |
|
48 | opObj10.addParameter(name='SNRmin', value='-20', format='int') | |
|
49 | opObj10.addParameter(name='SNRmax', value='40', format='int') | |
|
50 | opObj10.addParameter(name='SNRthresh', value='0', format='float') | |
|
51 | opObj10.addParameter(name='xmin', value='0', format='float') | |
|
52 | opObj10.addParameter(name='xmax', value='24', format='float') | |
|
53 | opObj10.addParameter(name='ymin', value='0', format='float') | |
|
54 | opObj10.addParameter(name='ymax', value='7', format='float') | |
|
55 | opObj10.addParameter(name='zmin', value='-4', format='float') | |
|
56 | opObj10.addParameter(name='zmax', value='4', format='float') | |
|
57 | opObj10.addParameter(name='zmin_ver', value='-200', format='float') | |
|
58 | opObj10.addParameter(name='zmax_ver', value='200', format='float') | |
|
59 | #opObj10.addParameter(name='showprofile', value='1', format='bool') | |
|
60 | #opObj10.addParameter(name='show', value='1', format='bool') | |
|
61 | ||
|
62 | controllerObj.start() | |
|
24 | ||
|
25 | controller = Project() | |
|
26 | controller.setup(id = '195', name='test1', description=desc) | |
|
27 | receiver = controller.addProcUnit(name='PlotterReceiver') | |
|
28 | receiver.addParameter(name='plottypes', value='output') | |
|
29 | receiver.addParameter(name='localtime', value='0', format='int') | |
|
30 | ||
|
31 | op = receiver.addOperation(name='PlotWindProfilerData', optype='other') | |
|
32 | op.addParameter(name='save', value=figpath) | |
|
33 | op.addParameter(name='bgcolor', value='white') | |
|
34 | op.addParameter(name='localtime', value='0', format='int') | |
|
35 | op.addParameter(name='zlimits', value='(-20,20),(-20,20),(-2,2)', format='pairslist') | |
|
36 | ||
|
37 | controller.start() | |
|
38 | ||
|
39 | ||
|
63 | 40 |
General Comments 0
You need to be logged in to leave comments.
Login now