The requested changes are too big and content was truncated. Show full diff
@@ -1,1229 +1,1231 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import copy |
|
8 | 8 | import numpy |
|
9 | 9 | import datetime |
|
10 | 10 | |
|
11 | 11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
12 | 12 | from schainpy import cSchain |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | def getNumpyDtype(dataTypeCode): |
|
16 | 16 | |
|
17 | 17 | if dataTypeCode == 0: |
|
18 | 18 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
19 | 19 | elif dataTypeCode == 1: |
|
20 | 20 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
21 | 21 | elif dataTypeCode == 2: |
|
22 | 22 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
23 | 23 | elif dataTypeCode == 3: |
|
24 | 24 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
25 | 25 | elif dataTypeCode == 4: |
|
26 | 26 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
27 | 27 | elif dataTypeCode == 5: |
|
28 | 28 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
29 | 29 | else: |
|
30 | 30 | raise ValueError, 'dataTypeCode was not defined' |
|
31 | 31 | |
|
32 | 32 | return numpyDtype |
|
33 | 33 | |
|
34 | 34 | def getDataTypeCode(numpyDtype): |
|
35 | 35 | |
|
36 | 36 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
|
37 | 37 | datatype = 0 |
|
38 | 38 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): |
|
39 | 39 | datatype = 1 |
|
40 | 40 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): |
|
41 | 41 | datatype = 2 |
|
42 | 42 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): |
|
43 | 43 | datatype = 3 |
|
44 | 44 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): |
|
45 | 45 | datatype = 4 |
|
46 | 46 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): |
|
47 | 47 | datatype = 5 |
|
48 | 48 | else: |
|
49 | 49 | datatype = None |
|
50 | 50 | |
|
51 | 51 | return datatype |
|
52 | 52 | |
|
53 | 53 | def hildebrand_sekhon(data, navg): |
|
54 | 54 | """ |
|
55 | 55 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
56 | 56 | implementation technique is based on the fact that the standard deviation of the spectral |
|
57 | 57 | densities is equal to the mean spectral density for white Gaussian noise |
|
58 | 58 | |
|
59 | 59 | Inputs: |
|
60 | 60 | Data : heights |
|
61 | 61 | navg : numbers of averages |
|
62 | 62 | |
|
63 | 63 | Return: |
|
64 | 64 | -1 : any error |
|
65 | 65 | anoise : noise's level |
|
66 | 66 | """ |
|
67 | 67 | |
|
68 | 68 | sortdata = numpy.sort(data, axis=None) |
|
69 | 69 | # lenOfData = len(sortdata) |
|
70 | 70 | # nums_min = lenOfData*0.2 |
|
71 | 71 | # |
|
72 | 72 | # if nums_min <= 5: |
|
73 | 73 | # nums_min = 5 |
|
74 | 74 | # |
|
75 | 75 | # sump = 0. |
|
76 | 76 | # |
|
77 | 77 | # sumq = 0. |
|
78 | 78 | # |
|
79 | 79 | # j = 0 |
|
80 | 80 | # |
|
81 | 81 | # cont = 1 |
|
82 | 82 | # |
|
83 | 83 | # while((cont==1)and(j<lenOfData)): |
|
84 | 84 | # |
|
85 | 85 | # sump += sortdata[j] |
|
86 | 86 | # |
|
87 | 87 | # sumq += sortdata[j]**2 |
|
88 | 88 | # |
|
89 | 89 | # if j > nums_min: |
|
90 | 90 | # rtest = float(j)/(j-1) + 1.0/navg |
|
91 | 91 | # if ((sumq*j) > (rtest*sump**2)): |
|
92 | 92 | # j = j - 1 |
|
93 | 93 | # sump = sump - sortdata[j] |
|
94 | 94 | # sumq = sumq - sortdata[j]**2 |
|
95 | 95 | # cont = 0 |
|
96 | 96 | # |
|
97 | 97 | # j += 1 |
|
98 | 98 | # |
|
99 | 99 | # lnoise = sump /j |
|
100 | 100 | # |
|
101 | 101 | # return lnoise |
|
102 | 102 | |
|
103 | 103 | return cSchain.hildebrand_sekhon(sortdata, navg) |
|
104 | 104 | |
|
105 | 105 | |
|
106 | 106 | class Beam: |
|
107 | 107 | |
|
108 | 108 | def __init__(self): |
|
109 | 109 | self.codeList = [] |
|
110 | 110 | self.azimuthList = [] |
|
111 | 111 | self.zenithList = [] |
|
112 | 112 | |
|
113 | 113 | class GenericData(object): |
|
114 | 114 | |
|
115 | 115 | flagNoData = True |
|
116 | 116 | |
|
117 | 117 | def copy(self, inputObj=None): |
|
118 | 118 | |
|
119 | 119 | if inputObj == None: |
|
120 | 120 | return copy.deepcopy(self) |
|
121 | 121 | |
|
122 | 122 | for key in inputObj.__dict__.keys(): |
|
123 | 123 | |
|
124 | 124 | attribute = inputObj.__dict__[key] |
|
125 | 125 | |
|
126 | 126 | #If this attribute is a tuple or list |
|
127 | 127 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
128 | 128 | self.__dict__[key] = attribute[:] |
|
129 | 129 | continue |
|
130 | 130 | |
|
131 | 131 | #If this attribute is another object or instance |
|
132 | 132 | if hasattr(attribute, '__dict__'): |
|
133 | 133 | self.__dict__[key] = attribute.copy() |
|
134 | 134 | continue |
|
135 | 135 | |
|
136 | 136 | self.__dict__[key] = inputObj.__dict__[key] |
|
137 | 137 | |
|
138 | 138 | def deepcopy(self): |
|
139 | 139 | |
|
140 | 140 | return copy.deepcopy(self) |
|
141 | 141 | |
|
142 | 142 | def isEmpty(self): |
|
143 | 143 | |
|
144 | 144 | return self.flagNoData |
|
145 | 145 | |
|
146 | 146 | class JROData(GenericData): |
|
147 | 147 | |
|
148 | 148 | # m_BasicHeader = BasicHeader() |
|
149 | 149 | # m_ProcessingHeader = ProcessingHeader() |
|
150 | 150 | |
|
151 | 151 | systemHeaderObj = SystemHeader() |
|
152 | 152 | |
|
153 | 153 | radarControllerHeaderObj = RadarControllerHeader() |
|
154 | 154 | |
|
155 | 155 | # data = None |
|
156 | 156 | |
|
157 | 157 | type = None |
|
158 | 158 | |
|
159 | 159 | datatype = None #dtype but in string |
|
160 | 160 | |
|
161 | 161 | # dtype = None |
|
162 | 162 | |
|
163 | 163 | # nChannels = None |
|
164 | 164 | |
|
165 | 165 | # nHeights = None |
|
166 | 166 | |
|
167 | 167 | nProfiles = None |
|
168 | 168 | |
|
169 | 169 | heightList = None |
|
170 | 170 | |
|
171 | 171 | channelList = None |
|
172 | 172 | |
|
173 | 173 | flagDiscontinuousBlock = False |
|
174 | 174 | |
|
175 | 175 | useLocalTime = False |
|
176 | 176 | |
|
177 | 177 | utctime = None |
|
178 | 178 | |
|
179 | 179 | timeZone = None |
|
180 | 180 | |
|
181 | 181 | dstFlag = None |
|
182 | 182 | |
|
183 | 183 | errorCount = None |
|
184 | 184 | |
|
185 | 185 | blocksize = None |
|
186 | 186 | |
|
187 | 187 | # nCode = None |
|
188 | 188 | # |
|
189 | 189 | # nBaud = None |
|
190 | 190 | # |
|
191 | 191 | # code = None |
|
192 | 192 | |
|
193 | 193 | flagDecodeData = False #asumo q la data no esta decodificada |
|
194 | 194 | |
|
195 | 195 | flagDeflipData = False #asumo q la data no esta sin flip |
|
196 | 196 | |
|
197 | 197 | flagShiftFFT = False |
|
198 | 198 | |
|
199 | 199 | # ippSeconds = None |
|
200 | 200 | |
|
201 | 201 | # timeInterval = None |
|
202 | 202 | |
|
203 | 203 | nCohInt = None |
|
204 | 204 | |
|
205 | 205 | # noise = None |
|
206 | 206 | |
|
207 | 207 | windowOfFilter = 1 |
|
208 | 208 | |
|
209 | 209 | #Speed of ligth |
|
210 | 210 | C = 3e8 |
|
211 | 211 | |
|
212 | 212 | frequency = 49.92e6 |
|
213 | 213 | |
|
214 | 214 | realtime = False |
|
215 | 215 | |
|
216 | 216 | beacon_heiIndexList = None |
|
217 | 217 | |
|
218 | 218 | last_block = None |
|
219 | 219 | |
|
220 | 220 | blocknow = None |
|
221 | 221 | |
|
222 | 222 | azimuth = None |
|
223 | 223 | |
|
224 | 224 | zenith = None |
|
225 | 225 | |
|
226 | 226 | beam = Beam() |
|
227 | 227 | |
|
228 | 228 | profileIndex = None |
|
229 | 229 | |
|
230 | 230 | def getNoise(self): |
|
231 | 231 | |
|
232 | 232 | raise NotImplementedError |
|
233 | 233 | |
|
234 | 234 | def getNChannels(self): |
|
235 | 235 | |
|
236 | 236 | return len(self.channelList) |
|
237 | 237 | |
|
238 | 238 | def getChannelIndexList(self): |
|
239 | 239 | |
|
240 | 240 | return range(self.nChannels) |
|
241 | 241 | |
|
242 | 242 | def getNHeights(self): |
|
243 | 243 | |
|
244 | 244 | return len(self.heightList) |
|
245 | 245 | |
|
246 | 246 | def getHeiRange(self, extrapoints=0): |
|
247 | 247 | |
|
248 | 248 | heis = self.heightList |
|
249 | 249 | # deltah = self.heightList[1] - self.heightList[0] |
|
250 | 250 | # |
|
251 | 251 | # heis.append(self.heightList[-1]) |
|
252 | 252 | |
|
253 | 253 | return heis |
|
254 | 254 | |
|
255 | 255 | def getDeltaH(self): |
|
256 | 256 | |
|
257 | 257 | delta = self.heightList[1] - self.heightList[0] |
|
258 | 258 | |
|
259 | 259 | return delta |
|
260 | 260 | |
|
261 | 261 | def getltctime(self): |
|
262 | 262 | |
|
263 | 263 | if self.useLocalTime: |
|
264 | 264 | return self.utctime - self.timeZone*60 |
|
265 | 265 | |
|
266 | 266 | return self.utctime |
|
267 | 267 | |
|
268 | 268 | def getDatatime(self): |
|
269 | 269 | |
|
270 | 270 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
271 | 271 | return datatimeValue |
|
272 | 272 | |
|
273 | 273 | def getTimeRange(self): |
|
274 | 274 | |
|
275 | 275 | datatime = [] |
|
276 | 276 | |
|
277 | 277 | datatime.append(self.ltctime) |
|
278 | 278 | datatime.append(self.ltctime + self.timeInterval+1) |
|
279 | 279 | |
|
280 | 280 | datatime = numpy.array(datatime) |
|
281 | 281 | |
|
282 | 282 | return datatime |
|
283 | 283 | |
|
284 | 284 | def getFmaxTimeResponse(self): |
|
285 | 285 | |
|
286 | 286 | period = (10**-6)*self.getDeltaH()/(0.15) |
|
287 | 287 | |
|
288 | 288 | PRF = 1./(period * self.nCohInt) |
|
289 | 289 | |
|
290 | 290 | fmax = PRF |
|
291 | 291 | |
|
292 | 292 | return fmax |
|
293 | 293 | |
|
294 | 294 | def getFmax(self): |
|
295 | 295 | |
|
296 | 296 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
297 | 297 | |
|
298 | 298 | fmax = PRF |
|
299 | 299 | |
|
300 | 300 | return fmax |
|
301 | 301 | |
|
302 | 302 | def getVmax(self): |
|
303 | 303 | |
|
304 | 304 | _lambda = self.C/self.frequency |
|
305 | 305 | |
|
306 | 306 | vmax = self.getFmax() * _lambda/2 |
|
307 | 307 | |
|
308 | 308 | return vmax |
|
309 | 309 | |
|
310 | 310 | def get_ippSeconds(self): |
|
311 | 311 | ''' |
|
312 | 312 | ''' |
|
313 | 313 | return self.radarControllerHeaderObj.ippSeconds |
|
314 | 314 | |
|
315 | 315 | def set_ippSeconds(self, ippSeconds): |
|
316 | 316 | ''' |
|
317 | 317 | ''' |
|
318 | 318 | |
|
319 | 319 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
320 | 320 | |
|
321 | 321 | return |
|
322 | 322 | |
|
323 | 323 | def get_dtype(self): |
|
324 | 324 | ''' |
|
325 | 325 | ''' |
|
326 | 326 | return getNumpyDtype(self.datatype) |
|
327 | 327 | |
|
328 | 328 | def set_dtype(self, numpyDtype): |
|
329 | 329 | ''' |
|
330 | 330 | ''' |
|
331 | 331 | |
|
332 | 332 | self.datatype = getDataTypeCode(numpyDtype) |
|
333 | 333 | |
|
334 | 334 | def get_code(self): |
|
335 | 335 | ''' |
|
336 | 336 | ''' |
|
337 | 337 | return self.radarControllerHeaderObj.code |
|
338 | 338 | |
|
339 | 339 | def set_code(self, code): |
|
340 | 340 | ''' |
|
341 | 341 | ''' |
|
342 | 342 | self.radarControllerHeaderObj.code = code |
|
343 | 343 | |
|
344 | 344 | return |
|
345 | 345 | |
|
346 | 346 | def get_ncode(self): |
|
347 | 347 | ''' |
|
348 | 348 | ''' |
|
349 | 349 | return self.radarControllerHeaderObj.nCode |
|
350 | 350 | |
|
351 | 351 | def set_ncode(self, nCode): |
|
352 | 352 | ''' |
|
353 | 353 | ''' |
|
354 | 354 | self.radarControllerHeaderObj.nCode = nCode |
|
355 | 355 | |
|
356 | 356 | return |
|
357 | 357 | |
|
358 | 358 | def get_nbaud(self): |
|
359 | 359 | ''' |
|
360 | 360 | ''' |
|
361 | 361 | return self.radarControllerHeaderObj.nBaud |
|
362 | 362 | |
|
363 | 363 | def set_nbaud(self, nBaud): |
|
364 | 364 | ''' |
|
365 | 365 | ''' |
|
366 | 366 | self.radarControllerHeaderObj.nBaud = nBaud |
|
367 | 367 | |
|
368 | 368 | return |
|
369 | 369 | |
|
370 | 370 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
371 | 371 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
372 | 372 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
373 | 373 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
374 | 374 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
375 | 375 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
376 | 376 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
377 | 377 | dtype = property(get_dtype, set_dtype) |
|
378 | 378 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
379 | 379 | code = property(get_code, set_code) |
|
380 | 380 | nCode = property(get_ncode, set_ncode) |
|
381 | 381 | nBaud = property(get_nbaud, set_nbaud) |
|
382 | 382 | |
|
383 | 383 | class Voltage(JROData): |
|
384 | 384 | |
|
385 | 385 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
386 | 386 | data = None |
|
387 | 387 | |
|
388 | 388 | def __init__(self): |
|
389 | 389 | ''' |
|
390 | 390 | Constructor |
|
391 | 391 | ''' |
|
392 | 392 | |
|
393 | 393 | self.useLocalTime = True |
|
394 | 394 | |
|
395 | 395 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
396 | 396 | |
|
397 | 397 | self.systemHeaderObj = SystemHeader() |
|
398 | 398 | |
|
399 | 399 | self.type = "Voltage" |
|
400 | 400 | |
|
401 | 401 | self.data = None |
|
402 | 402 | |
|
403 | 403 | # self.dtype = None |
|
404 | 404 | |
|
405 | 405 | # self.nChannels = 0 |
|
406 | 406 | |
|
407 | 407 | # self.nHeights = 0 |
|
408 | 408 | |
|
409 | 409 | self.nProfiles = None |
|
410 | 410 | |
|
411 | 411 | self.heightList = None |
|
412 | 412 | |
|
413 | 413 | self.channelList = None |
|
414 | 414 | |
|
415 | 415 | # self.channelIndexList = None |
|
416 | 416 | |
|
417 | 417 | self.flagNoData = True |
|
418 | 418 | |
|
419 | 419 | self.flagDiscontinuousBlock = False |
|
420 | 420 | |
|
421 | 421 | self.utctime = None |
|
422 | 422 | |
|
423 | 423 | self.timeZone = None |
|
424 | 424 | |
|
425 | 425 | self.dstFlag = None |
|
426 | 426 | |
|
427 | 427 | self.errorCount = None |
|
428 | 428 | |
|
429 | 429 | self.nCohInt = None |
|
430 | 430 | |
|
431 | 431 | self.blocksize = None |
|
432 | 432 | |
|
433 | 433 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
434 | 434 | |
|
435 | 435 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
436 | 436 | |
|
437 | 437 | self.flagShiftFFT = False |
|
438 | 438 | |
|
439 | 439 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil |
|
440 | 440 | |
|
441 | 441 | self.profileIndex = 0 |
|
442 | 442 | |
|
443 | 443 | def getNoisebyHildebrand(self, channel = None): |
|
444 | 444 | """ |
|
445 | 445 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
446 | 446 | |
|
447 | 447 | Return: |
|
448 | 448 | noiselevel |
|
449 | 449 | """ |
|
450 | 450 | |
|
451 | 451 | if channel != None: |
|
452 | 452 | data = self.data[channel] |
|
453 | 453 | nChannels = 1 |
|
454 | 454 | else: |
|
455 | 455 | data = self.data |
|
456 | 456 | nChannels = self.nChannels |
|
457 | 457 | |
|
458 | 458 | noise = numpy.zeros(nChannels) |
|
459 | 459 | power = data * numpy.conjugate(data) |
|
460 | 460 | |
|
461 | 461 | for thisChannel in range(nChannels): |
|
462 | 462 | if nChannels == 1: |
|
463 | 463 | daux = power[:].real |
|
464 | 464 | else: |
|
465 | 465 | daux = power[thisChannel,:].real |
|
466 | 466 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
467 | 467 | |
|
468 | 468 | return noise |
|
469 | 469 | |
|
470 | 470 | def getNoise(self, type = 1, channel = None): |
|
471 | 471 | |
|
472 | 472 | if type == 1: |
|
473 | 473 | noise = self.getNoisebyHildebrand(channel) |
|
474 | 474 | |
|
475 | 475 | return noise |
|
476 | 476 | |
|
477 | 477 | def getPower(self, channel = None): |
|
478 | 478 | |
|
479 | 479 | if channel != None: |
|
480 | 480 | data = self.data[channel] |
|
481 | 481 | else: |
|
482 | 482 | data = self.data |
|
483 | 483 | |
|
484 | 484 | power = data * numpy.conjugate(data) |
|
485 | 485 | powerdB = 10*numpy.log10(power.real) |
|
486 | 486 | powerdB = numpy.squeeze(powerdB) |
|
487 | 487 | |
|
488 | 488 | return powerdB |
|
489 | 489 | |
|
490 | 490 | def getTimeInterval(self): |
|
491 | 491 | |
|
492 | 492 | timeInterval = self.ippSeconds * self.nCohInt |
|
493 | 493 | |
|
494 | 494 | return timeInterval |
|
495 | 495 | |
|
496 | 496 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
497 | 497 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
498 | 498 | |
|
499 | 499 | class Spectra(JROData): |
|
500 | 500 | |
|
501 | 501 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
502 | 502 | data_spc = None |
|
503 | 503 | |
|
504 | 504 | #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
505 | 505 | data_cspc = None |
|
506 | 506 | |
|
507 | 507 | #data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
508 | 508 | data_dc = None |
|
509 | 509 | |
|
510 | 510 | #data power |
|
511 | 511 | data_pwr = None |
|
512 | 512 | |
|
513 | 513 | nFFTPoints = None |
|
514 | 514 | |
|
515 | 515 | # nPairs = None |
|
516 | 516 | |
|
517 | 517 | pairsList = None |
|
518 | 518 | |
|
519 | 519 | nIncohInt = None |
|
520 | 520 | |
|
521 | 521 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
522 | 522 | |
|
523 | 523 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
524 | 524 | |
|
525 | 525 | ippFactor = None |
|
526 | 526 | |
|
527 | 527 | profileIndex = 0 |
|
528 | 528 | |
|
529 | 529 | plotting = "spectra" |
|
530 | 530 | |
|
531 | 531 | def __init__(self): |
|
532 | 532 | ''' |
|
533 | 533 | Constructor |
|
534 | 534 | ''' |
|
535 | 535 | |
|
536 | 536 | self.useLocalTime = True |
|
537 | 537 | |
|
538 | 538 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
539 | 539 | |
|
540 | 540 | self.systemHeaderObj = SystemHeader() |
|
541 | 541 | |
|
542 | 542 | self.type = "Spectra" |
|
543 | 543 | |
|
544 | 544 | # self.data = None |
|
545 | 545 | |
|
546 | 546 | # self.dtype = None |
|
547 | 547 | |
|
548 | 548 | # self.nChannels = 0 |
|
549 | 549 | |
|
550 | 550 | # self.nHeights = 0 |
|
551 | 551 | |
|
552 | 552 | self.nProfiles = None |
|
553 | 553 | |
|
554 | 554 | self.heightList = None |
|
555 | 555 | |
|
556 | 556 | self.channelList = None |
|
557 | 557 | |
|
558 | 558 | # self.channelIndexList = None |
|
559 | 559 | |
|
560 | 560 | self.pairsList = None |
|
561 | 561 | |
|
562 | 562 | self.flagNoData = True |
|
563 | 563 | |
|
564 | 564 | self.flagDiscontinuousBlock = False |
|
565 | 565 | |
|
566 | 566 | self.utctime = None |
|
567 | 567 | |
|
568 | 568 | self.nCohInt = None |
|
569 | 569 | |
|
570 | 570 | self.nIncohInt = None |
|
571 | 571 | |
|
572 | 572 | self.blocksize = None |
|
573 | 573 | |
|
574 | 574 | self.nFFTPoints = None |
|
575 | 575 | |
|
576 | 576 | self.wavelength = None |
|
577 | 577 | |
|
578 | 578 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
579 | 579 | |
|
580 | 580 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
581 | 581 | |
|
582 | 582 | self.flagShiftFFT = False |
|
583 | 583 | |
|
584 | 584 | self.ippFactor = 1 |
|
585 | 585 | |
|
586 | 586 | #self.noise = None |
|
587 | 587 | |
|
588 | 588 | self.beacon_heiIndexList = [] |
|
589 | 589 | |
|
590 | 590 | self.noise_estimation = None |
|
591 | 591 | |
|
592 | 592 | |
|
593 | 593 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
594 | 594 | """ |
|
595 | 595 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
596 | 596 | |
|
597 | 597 | Return: |
|
598 | 598 | noiselevel |
|
599 | 599 | """ |
|
600 | 600 | |
|
601 | 601 | noise = numpy.zeros(self.nChannels) |
|
602 | 602 | |
|
603 | 603 | for channel in range(self.nChannels): |
|
604 | 604 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] |
|
605 | 605 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
606 | 606 | |
|
607 | 607 | return noise |
|
608 | 608 | |
|
609 | 609 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
610 | 610 | |
|
611 | 611 | if self.noise_estimation is not None: |
|
612 | 612 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
613 | 613 | else: |
|
614 | 614 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) |
|
615 | 615 | return noise |
|
616 | 616 | |
|
617 | 617 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
618 | 618 | |
|
619 | 619 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor) |
|
620 | 620 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
621 | 621 | |
|
622 | 622 | return freqrange |
|
623 | 623 | |
|
624 | 624 | def getAcfRange(self, extrapoints=0): |
|
625 | 625 | |
|
626 | 626 | deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor)) |
|
627 | 627 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
628 | 628 | |
|
629 | 629 | return freqrange |
|
630 | 630 | |
|
631 | 631 | def getFreqRange(self, extrapoints=0): |
|
632 | 632 | |
|
633 | 633 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
634 | 634 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
635 | 635 | |
|
636 | 636 | return freqrange |
|
637 | 637 | |
|
638 | 638 | def getVelRange(self, extrapoints=0): |
|
639 | ||
|
639 | ||
|
640 | print 'VELMAX', self.getVmax() | |
|
641 | asdasdasd | |
|
640 | 642 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
641 | 643 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2 |
|
642 | 644 | |
|
643 | 645 | return velrange |
|
644 | 646 | |
|
645 | 647 | def getNPairs(self): |
|
646 | 648 | |
|
647 | 649 | return len(self.pairsList) |
|
648 | 650 | |
|
649 | 651 | def getPairsIndexList(self): |
|
650 | 652 | |
|
651 | 653 | return range(self.nPairs) |
|
652 | 654 | |
|
653 | 655 | def getNormFactor(self): |
|
654 | 656 | |
|
655 | 657 | pwcode = 1 |
|
656 | 658 | |
|
657 | 659 | if self.flagDecodeData: |
|
658 | 660 | pwcode = numpy.sum(self.code[0]**2) |
|
659 | 661 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
660 | 662 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
661 | 663 | |
|
662 | 664 | return normFactor |
|
663 | 665 | |
|
664 | 666 | def getFlagCspc(self): |
|
665 | 667 | |
|
666 | 668 | if self.data_cspc is None: |
|
667 | 669 | return True |
|
668 | 670 | |
|
669 | 671 | return False |
|
670 | 672 | |
|
671 | 673 | def getFlagDc(self): |
|
672 | 674 | |
|
673 | 675 | if self.data_dc is None: |
|
674 | 676 | return True |
|
675 | 677 | |
|
676 | 678 | return False |
|
677 | 679 | |
|
678 | 680 | def getTimeInterval(self): |
|
679 | 681 | |
|
680 | 682 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles |
|
681 | 683 | |
|
682 | 684 | return timeInterval |
|
683 | 685 | |
|
684 | 686 | def getPower(self): |
|
685 | 687 | |
|
686 | 688 | factor = self.normFactor |
|
687 | 689 | z = self.data_spc/factor |
|
688 | 690 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
689 | 691 | avg = numpy.average(z, axis=1) |
|
690 | 692 | |
|
691 | 693 | return 10*numpy.log10(avg) |
|
692 | 694 | |
|
693 | 695 | def getCoherence(self, pairsList=None, phase=False): |
|
694 | 696 | |
|
695 | 697 | z = [] |
|
696 | 698 | if pairsList is None: |
|
697 | 699 | pairsIndexList = self.pairsIndexList |
|
698 | 700 | else: |
|
699 | 701 | pairsIndexList = [] |
|
700 | 702 | for pair in pairsList: |
|
701 | 703 | if pair not in self.pairsList: |
|
702 | 704 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
703 | 705 | pairsIndexList.append(self.pairsList.index(pair)) |
|
704 | 706 | for i in range(len(pairsIndexList)): |
|
705 | 707 | pair = self.pairsList[pairsIndexList[i]] |
|
706 | 708 | ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
707 | 709 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
708 | 710 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
709 | 711 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
710 | 712 | if phase: |
|
711 | 713 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
712 | 714 | avgcoherenceComplex.real)*180/numpy.pi |
|
713 | 715 | else: |
|
714 | 716 | data = numpy.abs(avgcoherenceComplex) |
|
715 | 717 | |
|
716 | 718 | z.append(data) |
|
717 | 719 | |
|
718 | 720 | return numpy.array(z) |
|
719 | 721 | |
|
720 | 722 | def setValue(self, value): |
|
721 | 723 | |
|
722 | 724 | print "This property should not be initialized" |
|
723 | 725 | |
|
724 | 726 | return |
|
725 | 727 | |
|
726 | 728 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
727 | 729 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
728 | 730 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") |
|
729 | 731 | flag_cspc = property(getFlagCspc, setValue) |
|
730 | 732 | flag_dc = property(getFlagDc, setValue) |
|
731 | 733 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
732 | 734 | timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property") |
|
733 | 735 | |
|
734 | 736 | class SpectraHeis(Spectra): |
|
735 | 737 | |
|
736 | 738 | data_spc = None |
|
737 | 739 | |
|
738 | 740 | data_cspc = None |
|
739 | 741 | |
|
740 | 742 | data_dc = None |
|
741 | 743 | |
|
742 | 744 | nFFTPoints = None |
|
743 | 745 | |
|
744 | 746 | # nPairs = None |
|
745 | 747 | |
|
746 | 748 | pairsList = None |
|
747 | 749 | |
|
748 | 750 | nCohInt = None |
|
749 | 751 | |
|
750 | 752 | nIncohInt = None |
|
751 | 753 | |
|
752 | 754 | def __init__(self): |
|
753 | 755 | |
|
754 | 756 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
755 | 757 | |
|
756 | 758 | self.systemHeaderObj = SystemHeader() |
|
757 | 759 | |
|
758 | 760 | self.type = "SpectraHeis" |
|
759 | 761 | |
|
760 | 762 | # self.dtype = None |
|
761 | 763 | |
|
762 | 764 | # self.nChannels = 0 |
|
763 | 765 | |
|
764 | 766 | # self.nHeights = 0 |
|
765 | 767 | |
|
766 | 768 | self.nProfiles = None |
|
767 | 769 | |
|
768 | 770 | self.heightList = None |
|
769 | 771 | |
|
770 | 772 | self.channelList = None |
|
771 | 773 | |
|
772 | 774 | # self.channelIndexList = None |
|
773 | 775 | |
|
774 | 776 | self.flagNoData = True |
|
775 | 777 | |
|
776 | 778 | self.flagDiscontinuousBlock = False |
|
777 | 779 | |
|
778 | 780 | # self.nPairs = 0 |
|
779 | 781 | |
|
780 | 782 | self.utctime = None |
|
781 | 783 | |
|
782 | 784 | self.blocksize = None |
|
783 | 785 | |
|
784 | 786 | self.profileIndex = 0 |
|
785 | 787 | |
|
786 | 788 | self.nCohInt = 1 |
|
787 | 789 | |
|
788 | 790 | self.nIncohInt = 1 |
|
789 | 791 | |
|
790 | 792 | def getNormFactor(self): |
|
791 | 793 | pwcode = 1 |
|
792 | 794 | if self.flagDecodeData: |
|
793 | 795 | pwcode = numpy.sum(self.code[0]**2) |
|
794 | 796 | |
|
795 | 797 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
796 | 798 | |
|
797 | 799 | return normFactor |
|
798 | 800 | |
|
799 | 801 | def getTimeInterval(self): |
|
800 | 802 | |
|
801 | 803 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
802 | 804 | |
|
803 | 805 | return timeInterval |
|
804 | 806 | |
|
805 | 807 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
806 | 808 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
807 | 809 | |
|
808 | 810 | class Fits(JROData): |
|
809 | 811 | |
|
810 | 812 | heightList = None |
|
811 | 813 | |
|
812 | 814 | channelList = None |
|
813 | 815 | |
|
814 | 816 | flagNoData = True |
|
815 | 817 | |
|
816 | 818 | flagDiscontinuousBlock = False |
|
817 | 819 | |
|
818 | 820 | useLocalTime = False |
|
819 | 821 | |
|
820 | 822 | utctime = None |
|
821 | 823 | |
|
822 | 824 | timeZone = None |
|
823 | 825 | |
|
824 | 826 | # ippSeconds = None |
|
825 | 827 | |
|
826 | 828 | # timeInterval = None |
|
827 | 829 | |
|
828 | 830 | nCohInt = None |
|
829 | 831 | |
|
830 | 832 | nIncohInt = None |
|
831 | 833 | |
|
832 | 834 | noise = None |
|
833 | 835 | |
|
834 | 836 | windowOfFilter = 1 |
|
835 | 837 | |
|
836 | 838 | #Speed of ligth |
|
837 | 839 | C = 3e8 |
|
838 | 840 | |
|
839 | 841 | frequency = 49.92e6 |
|
840 | 842 | |
|
841 | 843 | realtime = False |
|
842 | 844 | |
|
843 | 845 | |
|
844 | 846 | def __init__(self): |
|
845 | 847 | |
|
846 | 848 | self.type = "Fits" |
|
847 | 849 | |
|
848 | 850 | self.nProfiles = None |
|
849 | 851 | |
|
850 | 852 | self.heightList = None |
|
851 | 853 | |
|
852 | 854 | self.channelList = None |
|
853 | 855 | |
|
854 | 856 | # self.channelIndexList = None |
|
855 | 857 | |
|
856 | 858 | self.flagNoData = True |
|
857 | 859 | |
|
858 | 860 | self.utctime = None |
|
859 | 861 | |
|
860 | 862 | self.nCohInt = 1 |
|
861 | 863 | |
|
862 | 864 | self.nIncohInt = 1 |
|
863 | 865 | |
|
864 | 866 | self.useLocalTime = True |
|
865 | 867 | |
|
866 | 868 | self.profileIndex = 0 |
|
867 | 869 | |
|
868 | 870 | # self.utctime = None |
|
869 | 871 | # self.timeZone = None |
|
870 | 872 | # self.ltctime = None |
|
871 | 873 | # self.timeInterval = None |
|
872 | 874 | # self.header = None |
|
873 | 875 | # self.data_header = None |
|
874 | 876 | # self.data = None |
|
875 | 877 | # self.datatime = None |
|
876 | 878 | # self.flagNoData = False |
|
877 | 879 | # self.expName = '' |
|
878 | 880 | # self.nChannels = None |
|
879 | 881 | # self.nSamples = None |
|
880 | 882 | # self.dataBlocksPerFile = None |
|
881 | 883 | # self.comments = '' |
|
882 | 884 | # |
|
883 | 885 | |
|
884 | 886 | |
|
885 | 887 | def getltctime(self): |
|
886 | 888 | |
|
887 | 889 | if self.useLocalTime: |
|
888 | 890 | return self.utctime - self.timeZone*60 |
|
889 | 891 | |
|
890 | 892 | return self.utctime |
|
891 | 893 | |
|
892 | 894 | def getDatatime(self): |
|
893 | 895 | |
|
894 | 896 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
895 | 897 | return datatime |
|
896 | 898 | |
|
897 | 899 | def getTimeRange(self): |
|
898 | 900 | |
|
899 | 901 | datatime = [] |
|
900 | 902 | |
|
901 | 903 | datatime.append(self.ltctime) |
|
902 | 904 | datatime.append(self.ltctime + self.timeInterval) |
|
903 | 905 | |
|
904 | 906 | datatime = numpy.array(datatime) |
|
905 | 907 | |
|
906 | 908 | return datatime |
|
907 | 909 | |
|
908 | 910 | def getHeiRange(self): |
|
909 | 911 | |
|
910 | 912 | heis = self.heightList |
|
911 | 913 | |
|
912 | 914 | return heis |
|
913 | 915 | |
|
914 | 916 | def getNHeights(self): |
|
915 | 917 | |
|
916 | 918 | return len(self.heightList) |
|
917 | 919 | |
|
918 | 920 | def getNChannels(self): |
|
919 | 921 | |
|
920 | 922 | return len(self.channelList) |
|
921 | 923 | |
|
922 | 924 | def getChannelIndexList(self): |
|
923 | 925 | |
|
924 | 926 | return range(self.nChannels) |
|
925 | 927 | |
|
926 | 928 | def getNoise(self, type = 1): |
|
927 | 929 | |
|
928 | 930 | #noise = numpy.zeros(self.nChannels) |
|
929 | 931 | |
|
930 | 932 | if type == 1: |
|
931 | 933 | noise = self.getNoisebyHildebrand() |
|
932 | 934 | |
|
933 | 935 | if type == 2: |
|
934 | 936 | noise = self.getNoisebySort() |
|
935 | 937 | |
|
936 | 938 | if type == 3: |
|
937 | 939 | noise = self.getNoisebyWindow() |
|
938 | 940 | |
|
939 | 941 | return noise |
|
940 | 942 | |
|
941 | 943 | def getTimeInterval(self): |
|
942 | 944 | |
|
943 | 945 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
944 | 946 | |
|
945 | 947 | return timeInterval |
|
946 | 948 | |
|
947 | 949 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
948 | 950 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
949 | 951 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
950 | 952 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
951 | 953 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
952 | 954 | |
|
953 | 955 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
954 | 956 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
955 | 957 | |
|
956 | 958 | |
|
957 | 959 | class Correlation(JROData): |
|
958 | 960 | |
|
959 | 961 | noise = None |
|
960 | 962 | |
|
961 | 963 | SNR = None |
|
962 | 964 | |
|
963 | 965 | #-------------------------------------------------- |
|
964 | 966 | |
|
965 | 967 | mode = None |
|
966 | 968 | |
|
967 | 969 | split = False |
|
968 | 970 | |
|
969 | 971 | data_cf = None |
|
970 | 972 | |
|
971 | 973 | lags = None |
|
972 | 974 | |
|
973 | 975 | lagRange = None |
|
974 | 976 | |
|
975 | 977 | pairsList = None |
|
976 | 978 | |
|
977 | 979 | normFactor = None |
|
978 | 980 | |
|
979 | 981 | #-------------------------------------------------- |
|
980 | 982 | |
|
981 | 983 | # calculateVelocity = None |
|
982 | 984 | |
|
983 | 985 | nLags = None |
|
984 | 986 | |
|
985 | 987 | nPairs = None |
|
986 | 988 | |
|
987 | 989 | nAvg = None |
|
988 | 990 | |
|
989 | 991 | |
|
990 | 992 | def __init__(self): |
|
991 | 993 | ''' |
|
992 | 994 | Constructor |
|
993 | 995 | ''' |
|
994 | 996 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
995 | 997 | |
|
996 | 998 | self.systemHeaderObj = SystemHeader() |
|
997 | 999 | |
|
998 | 1000 | self.type = "Correlation" |
|
999 | 1001 | |
|
1000 | 1002 | self.data = None |
|
1001 | 1003 | |
|
1002 | 1004 | self.dtype = None |
|
1003 | 1005 | |
|
1004 | 1006 | self.nProfiles = None |
|
1005 | 1007 | |
|
1006 | 1008 | self.heightList = None |
|
1007 | 1009 | |
|
1008 | 1010 | self.channelList = None |
|
1009 | 1011 | |
|
1010 | 1012 | self.flagNoData = True |
|
1011 | 1013 | |
|
1012 | 1014 | self.flagDiscontinuousBlock = False |
|
1013 | 1015 | |
|
1014 | 1016 | self.utctime = None |
|
1015 | 1017 | |
|
1016 | 1018 | self.timeZone = None |
|
1017 | 1019 | |
|
1018 | 1020 | self.dstFlag = None |
|
1019 | 1021 | |
|
1020 | 1022 | self.errorCount = None |
|
1021 | 1023 | |
|
1022 | 1024 | self.blocksize = None |
|
1023 | 1025 | |
|
1024 | 1026 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
1025 | 1027 | |
|
1026 | 1028 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
1027 | 1029 | |
|
1028 | 1030 | self.pairsList = None |
|
1029 | 1031 | |
|
1030 | 1032 | self.nPoints = None |
|
1031 | 1033 | |
|
1032 | 1034 | def getPairsList(self): |
|
1033 | 1035 | |
|
1034 | 1036 | return self.pairsList |
|
1035 | 1037 | |
|
1036 | 1038 | def getNoise(self, mode = 2): |
|
1037 | 1039 | |
|
1038 | 1040 | indR = numpy.where(self.lagR == 0)[0][0] |
|
1039 | 1041 | indT = numpy.where(self.lagT == 0)[0][0] |
|
1040 | 1042 | |
|
1041 | 1043 | jspectra0 = self.data_corr[:,:,indR,:] |
|
1042 | 1044 | jspectra = copy.copy(jspectra0) |
|
1043 | 1045 | |
|
1044 | 1046 | num_chan = jspectra.shape[0] |
|
1045 | 1047 | num_hei = jspectra.shape[2] |
|
1046 | 1048 | |
|
1047 | 1049 | freq_dc = jspectra.shape[1]/2 |
|
1048 | 1050 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1049 | 1051 | |
|
1050 | 1052 | if ind_vel[0]<0: |
|
1051 | 1053 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1052 | 1054 | |
|
1053 | 1055 | if mode == 1: |
|
1054 | 1056 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1055 | 1057 | |
|
1056 | 1058 | if mode == 2: |
|
1057 | 1059 | |
|
1058 | 1060 | vel = numpy.array([-2,-1,1,2]) |
|
1059 | 1061 | xx = numpy.zeros([4,4]) |
|
1060 | 1062 | |
|
1061 | 1063 | for fil in range(4): |
|
1062 | 1064 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1063 | 1065 | |
|
1064 | 1066 | xx_inv = numpy.linalg.inv(xx) |
|
1065 | 1067 | xx_aux = xx_inv[0,:] |
|
1066 | 1068 | |
|
1067 | 1069 | for ich in range(num_chan): |
|
1068 | 1070 | yy = jspectra[ich,ind_vel,:] |
|
1069 | 1071 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1070 | 1072 | |
|
1071 | 1073 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1072 | 1074 | cjunkid = sum(junkid) |
|
1073 | 1075 | |
|
1074 | 1076 | if cjunkid.any(): |
|
1075 | 1077 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1076 | 1078 | |
|
1077 | 1079 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] |
|
1078 | 1080 | |
|
1079 | 1081 | return noise |
|
1080 | 1082 | |
|
1081 | 1083 | def getTimeInterval(self): |
|
1082 | 1084 | |
|
1083 | 1085 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
1084 | 1086 | |
|
1085 | 1087 | return timeInterval |
|
1086 | 1088 | |
|
1087 | 1089 | def splitFunctions(self): |
|
1088 | 1090 | |
|
1089 | 1091 | pairsList = self.pairsList |
|
1090 | 1092 | ccf_pairs = [] |
|
1091 | 1093 | acf_pairs = [] |
|
1092 | 1094 | ccf_ind = [] |
|
1093 | 1095 | acf_ind = [] |
|
1094 | 1096 | for l in range(len(pairsList)): |
|
1095 | 1097 | chan0 = pairsList[l][0] |
|
1096 | 1098 | chan1 = pairsList[l][1] |
|
1097 | 1099 | |
|
1098 | 1100 | #Obteniendo pares de Autocorrelacion |
|
1099 | 1101 | if chan0 == chan1: |
|
1100 | 1102 | acf_pairs.append(chan0) |
|
1101 | 1103 | acf_ind.append(l) |
|
1102 | 1104 | else: |
|
1103 | 1105 | ccf_pairs.append(pairsList[l]) |
|
1104 | 1106 | ccf_ind.append(l) |
|
1105 | 1107 | |
|
1106 | 1108 | data_acf = self.data_cf[acf_ind] |
|
1107 | 1109 | data_ccf = self.data_cf[ccf_ind] |
|
1108 | 1110 | |
|
1109 | 1111 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
1110 | 1112 | |
|
1111 | 1113 | def getNormFactor(self): |
|
1112 | 1114 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1113 | 1115 | acf_pairs = numpy.array(acf_pairs) |
|
1114 | 1116 | normFactor = numpy.zeros((self.nPairs,self.nHeights)) |
|
1115 | 1117 | |
|
1116 | 1118 | for p in range(self.nPairs): |
|
1117 | 1119 | pair = self.pairsList[p] |
|
1118 | 1120 | |
|
1119 | 1121 | ch0 = pair[0] |
|
1120 | 1122 | ch1 = pair[1] |
|
1121 | 1123 | |
|
1122 | 1124 | ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1) |
|
1123 | 1125 | ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1) |
|
1124 | 1126 | normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max) |
|
1125 | 1127 | |
|
1126 | 1128 | return normFactor |
|
1127 | 1129 | |
|
1128 | 1130 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1129 | 1131 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1130 | 1132 | |
|
1131 | 1133 | class Parameters(Spectra): |
|
1132 | 1134 | |
|
1133 | 1135 | experimentInfo = None #Information about the experiment |
|
1134 | 1136 | |
|
1135 | 1137 | #Information from previous data |
|
1136 | 1138 | |
|
1137 | 1139 | inputUnit = None #Type of data to be processed |
|
1138 | 1140 | |
|
1139 | 1141 | operation = None #Type of operation to parametrize |
|
1140 | 1142 | |
|
1141 | 1143 | #normFactor = None #Normalization Factor |
|
1142 | 1144 | |
|
1143 | 1145 | groupList = None #List of Pairs, Groups, etc |
|
1144 | 1146 | |
|
1145 | 1147 | #Parameters |
|
1146 | 1148 | |
|
1147 | 1149 | data_param = None #Parameters obtained |
|
1148 | 1150 | |
|
1149 | 1151 | data_pre = None #Data Pre Parametrization |
|
1150 | 1152 | |
|
1151 | 1153 | data_SNR = None #Signal to Noise Ratio |
|
1152 | 1154 | |
|
1153 | 1155 | # heightRange = None #Heights |
|
1154 | 1156 | |
|
1155 | 1157 | abscissaList = None #Abscissa, can be velocities, lags or time |
|
1156 | 1158 | |
|
1157 | 1159 | # noise = None #Noise Potency |
|
1158 | 1160 | |
|
1159 | 1161 | utctimeInit = None #Initial UTC time |
|
1160 | 1162 | |
|
1161 | 1163 | paramInterval = None #Time interval to calculate Parameters in seconds |
|
1162 | 1164 | |
|
1163 | 1165 | useLocalTime = True |
|
1164 | 1166 | |
|
1165 | 1167 | #Fitting |
|
1166 | 1168 | |
|
1167 | 1169 | data_error = None #Error of the estimation |
|
1168 | 1170 | |
|
1169 | 1171 | constants = None |
|
1170 | 1172 | |
|
1171 | 1173 | library = None |
|
1172 | 1174 | |
|
1173 | 1175 | #Output signal |
|
1174 | 1176 | |
|
1175 | 1177 | outputInterval = None #Time interval to calculate output signal in seconds |
|
1176 | 1178 | |
|
1177 | 1179 | data_output = None #Out signal |
|
1178 | 1180 | |
|
1179 | 1181 | nAvg = None |
|
1180 | 1182 | |
|
1181 | 1183 | noise_estimation = None |
|
1182 | 1184 | |
|
1183 | 1185 | GauSPC = None #Fit gaussian SPC |
|
1184 | 1186 | |
|
1185 | 1187 | |
|
1186 | 1188 | def __init__(self): |
|
1187 | 1189 | ''' |
|
1188 | 1190 | Constructor |
|
1189 | 1191 | ''' |
|
1190 | 1192 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1191 | 1193 | |
|
1192 | 1194 | self.systemHeaderObj = SystemHeader() |
|
1193 | 1195 | |
|
1194 | 1196 | self.type = "Parameters" |
|
1195 | 1197 | |
|
1196 | 1198 | def getTimeRange1(self, interval): |
|
1197 | 1199 | |
|
1198 | 1200 | datatime = [] |
|
1199 | 1201 | |
|
1200 | 1202 | if self.useLocalTime: |
|
1201 | 1203 | time1 = self.utctimeInit - self.timeZone*60 |
|
1202 | 1204 | else: |
|
1203 | 1205 | time1 = self.utctimeInit |
|
1204 | 1206 | |
|
1205 | 1207 | datatime.append(time1) |
|
1206 | 1208 | datatime.append(time1 + interval) |
|
1207 | 1209 | datatime = numpy.array(datatime) |
|
1208 | 1210 | |
|
1209 | 1211 | return datatime |
|
1210 | 1212 | |
|
1211 | 1213 | def getTimeInterval(self): |
|
1212 | 1214 | |
|
1213 | 1215 | if hasattr(self, 'timeInterval1'): |
|
1214 | 1216 | return self.timeInterval1 |
|
1215 | 1217 | else: |
|
1216 | 1218 | return self.paramInterval |
|
1217 | 1219 | |
|
1218 | 1220 | def setValue(self, value): |
|
1219 | 1221 | |
|
1220 | 1222 | print "This property should not be initialized" |
|
1221 | 1223 | |
|
1222 | 1224 | return |
|
1223 | 1225 | |
|
1224 | 1226 | def getNoise(self): |
|
1225 | 1227 | |
|
1226 | 1228 | return self.spc_noise |
|
1227 | 1229 | |
|
1228 | 1230 | timeInterval = property(getTimeInterval) |
|
1229 | 1231 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") |
@@ -1,762 +1,762 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | import sys |
|
7 | 7 | import numpy |
|
8 | 8 | import copy |
|
9 | 9 | import datetime |
|
10 | 10 | |
|
11 | 11 | SPEED_OF_LIGHT = 299792458 |
|
12 | 12 | SPEED_OF_LIGHT = 3e8 |
|
13 | 13 | |
|
14 | 14 | BASIC_STRUCTURE = numpy.dtype([ |
|
15 | 15 | ('nSize','<u4'), |
|
16 | 16 | ('nVersion','<u2'), |
|
17 | 17 | ('nDataBlockId','<u4'), |
|
18 | 18 | ('nUtime','<u4'), |
|
19 | 19 | ('nMilsec','<u2'), |
|
20 | 20 | ('nTimezone','<i2'), |
|
21 | 21 | ('nDstflag','<i2'), |
|
22 | 22 | ('nErrorCount','<u4') |
|
23 | 23 | ]) |
|
24 | 24 | |
|
25 | 25 | SYSTEM_STRUCTURE = numpy.dtype([ |
|
26 | 26 | ('nSize','<u4'), |
|
27 | 27 | ('nNumSamples','<u4'), |
|
28 | 28 | ('nNumProfiles','<u4'), |
|
29 | 29 | ('nNumChannels','<u4'), |
|
30 | 30 | ('nADCResolution','<u4'), |
|
31 | 31 | ('nPCDIOBusWidth','<u4'), |
|
32 | 32 | ]) |
|
33 | 33 | |
|
34 | 34 | RADAR_STRUCTURE = numpy.dtype([ |
|
35 | 35 | ('nSize','<u4'), |
|
36 | 36 | ('nExpType','<u4'), |
|
37 | 37 | ('nNTx','<u4'), |
|
38 | 38 | ('fIpp','<f4'), |
|
39 | 39 | ('fTxA','<f4'), |
|
40 | 40 | ('fTxB','<f4'), |
|
41 | 41 | ('nNumWindows','<u4'), |
|
42 | 42 | ('nNumTaus','<u4'), |
|
43 | 43 | ('nCodeType','<u4'), |
|
44 | 44 | ('nLine6Function','<u4'), |
|
45 | 45 | ('nLine5Function','<u4'), |
|
46 | 46 | ('fClock','<f4'), |
|
47 | 47 | ('nPrePulseBefore','<u4'), |
|
48 | 48 | ('nPrePulseAfter','<u4'), |
|
49 | 49 | ('sRangeIPP','<a20'), |
|
50 | 50 | ('sRangeTxA','<a20'), |
|
51 | 51 | ('sRangeTxB','<a20'), |
|
52 | 52 | ]) |
|
53 | 53 | |
|
54 | 54 | SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
55 | 55 | |
|
56 | 56 | |
|
57 | 57 | PROCESSING_STRUCTURE = numpy.dtype([ |
|
58 | 58 | ('nSize','<u4'), |
|
59 | 59 | ('nDataType','<u4'), |
|
60 | 60 | ('nSizeOfDataBlock','<u4'), |
|
61 | 61 | ('nProfilesperBlock','<u4'), |
|
62 | 62 | ('nDataBlocksperFile','<u4'), |
|
63 | 63 | ('nNumWindows','<u4'), |
|
64 | 64 | ('nProcessFlags','<u4'), |
|
65 | 65 | ('nCoherentIntegrations','<u4'), |
|
66 | 66 | ('nIncoherentIntegrations','<u4'), |
|
67 | 67 | ('nTotalSpectra','<u4') |
|
68 | 68 | ]) |
|
69 | 69 | |
|
70 | 70 | class Header(object): |
|
71 | 71 | |
|
72 | 72 | def __init__(self): |
|
73 | 73 | raise NotImplementedError |
|
74 | 74 | |
|
75 | 75 | def copy(self): |
|
76 | 76 | return copy.deepcopy(self) |
|
77 | 77 | |
|
78 | 78 | def read(self): |
|
79 | 79 | |
|
80 | 80 | raise NotImplementedError |
|
81 | 81 | |
|
82 | 82 | def write(self): |
|
83 | 83 | |
|
84 | 84 | raise NotImplementedError |
|
85 | 85 | |
|
86 | 86 | def printInfo(self): |
|
87 | 87 | |
|
88 | 88 | message = "#"*50 + "\n" |
|
89 | 89 | message += self.__class__.__name__.upper() + "\n" |
|
90 | 90 | message += "#"*50 + "\n" |
|
91 | 91 | |
|
92 | 92 | keyList = self.__dict__.keys() |
|
93 | 93 | keyList.sort() |
|
94 | 94 | |
|
95 | 95 | for key in keyList: |
|
96 | 96 | message += "%s = %s" %(key, self.__dict__[key]) + "\n" |
|
97 | 97 | |
|
98 | 98 | if "size" not in keyList: |
|
99 | 99 | attr = getattr(self, "size") |
|
100 | 100 | |
|
101 | 101 | if attr: |
|
102 | 102 | message += "%s = %s" %("size", attr) + "\n" |
|
103 | 103 | |
|
104 | 104 | print message |
|
105 | 105 | |
|
106 | 106 | class BasicHeader(Header): |
|
107 | 107 | |
|
108 | 108 | size = None |
|
109 | 109 | version = None |
|
110 | 110 | dataBlock = None |
|
111 | 111 | utc = None |
|
112 | 112 | ltc = None |
|
113 | 113 | miliSecond = None |
|
114 | 114 | timeZone = None |
|
115 | 115 | dstFlag = None |
|
116 | 116 | errorCount = None |
|
117 | 117 | datatime = None |
|
118 | 118 | |
|
119 | 119 | __LOCALTIME = None |
|
120 | 120 | |
|
121 | 121 | def __init__(self, useLocalTime=True): |
|
122 | 122 | |
|
123 | 123 | self.size = 24 |
|
124 | 124 | self.version = 0 |
|
125 | 125 | self.dataBlock = 0 |
|
126 | 126 | self.utc = 0 |
|
127 | 127 | self.miliSecond = 0 |
|
128 | 128 | self.timeZone = 0 |
|
129 | 129 | self.dstFlag = 0 |
|
130 | 130 | self.errorCount = 0 |
|
131 | 131 | |
|
132 | 132 | self.useLocalTime = useLocalTime |
|
133 | 133 | |
|
134 | 134 | def read(self, fp): |
|
135 | 135 | |
|
136 | 136 | try: |
|
137 | 137 | header = numpy.fromfile(fp, BASIC_STRUCTURE,1) |
|
138 | 138 | |
|
139 | 139 | except Exception, e: |
|
140 | 140 | print "BasicHeader: " |
|
141 | 141 | print e |
|
142 | 142 | return 0 |
|
143 | 143 | |
|
144 | 144 | self.size = int(header['nSize'][0]) |
|
145 | 145 | self.version = int(header['nVersion'][0]) |
|
146 | 146 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
147 | 147 | self.utc = int(header['nUtime'][0]) |
|
148 | 148 | self.miliSecond = int(header['nMilsec'][0]) |
|
149 | 149 | self.timeZone = int(header['nTimezone'][0]) |
|
150 | 150 | self.dstFlag = int(header['nDstflag'][0]) |
|
151 | 151 | self.errorCount = int(header['nErrorCount'][0]) |
|
152 | 152 | |
|
153 | 153 | if self.size < 24: |
|
154 | 154 | return 0 |
|
155 | 155 | |
|
156 | 156 | return 1 |
|
157 | 157 | |
|
158 | 158 | def write(self, fp): |
|
159 | 159 | |
|
160 | 160 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
161 | 161 | header = numpy.array(headerTuple, BASIC_STRUCTURE) |
|
162 | 162 | header.tofile(fp) |
|
163 | 163 | |
|
164 | 164 | return 1 |
|
165 | 165 | |
|
166 | 166 | def get_ltc(self): |
|
167 | 167 | |
|
168 | 168 | return self.utc - self.timeZone*60 |
|
169 | 169 | |
|
170 | 170 | def set_ltc(self, value): |
|
171 | 171 | |
|
172 | 172 | self.utc = value + self.timeZone*60 |
|
173 | 173 | |
|
174 | 174 | def get_datatime(self): |
|
175 | 175 | |
|
176 | 176 | return datetime.datetime.utcfromtimestamp(self.ltc) |
|
177 | 177 | |
|
178 | 178 | ltc = property(get_ltc, set_ltc) |
|
179 | 179 | datatime = property(get_datatime) |
|
180 | 180 | |
|
181 | 181 | class SystemHeader(Header): |
|
182 | 182 | |
|
183 | 183 | size = None |
|
184 | 184 | nSamples = None |
|
185 | 185 | nProfiles = None |
|
186 | 186 | nChannels = None |
|
187 | 187 | adcResolution = None |
|
188 | 188 | pciDioBusWidth = None |
|
189 | 189 | |
|
190 | 190 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0): |
|
191 | 191 | |
|
192 | 192 | self.size = 24 |
|
193 | 193 | self.nSamples = nSamples |
|
194 | 194 | self.nProfiles = nProfiles |
|
195 | 195 | self.nChannels = nChannels |
|
196 | 196 | self.adcResolution = adcResolution |
|
197 | 197 | self.pciDioBusWidth = pciDioBusWith |
|
198 | 198 | |
|
199 | 199 | def read(self, fp): |
|
200 | 200 | |
|
201 | 201 | startFp = fp.tell() |
|
202 | 202 | |
|
203 | 203 | try: |
|
204 | 204 | header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1) |
|
205 | 205 | except Exception, e: |
|
206 | 206 | print "System Header: " + e |
|
207 | 207 | return 0 |
|
208 | 208 | |
|
209 | 209 | self.size = header['nSize'][0] |
|
210 | 210 | self.nSamples = header['nNumSamples'][0] |
|
211 | 211 | self.nProfiles = header['nNumProfiles'][0] |
|
212 | 212 | self.nChannels = header['nNumChannels'][0] |
|
213 | 213 | self.adcResolution = header['nADCResolution'][0] |
|
214 | 214 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
215 | 215 | |
|
216 | 216 | endFp = self.size + startFp |
|
217 | 217 | |
|
218 | 218 | if fp.tell() > endFp: |
|
219 | 219 | sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp.name) |
|
220 | 220 | return 0 |
|
221 | 221 | |
|
222 | 222 | if fp.tell() < endFp: |
|
223 | 223 | sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp.name) |
|
224 | 224 | return 0 |
|
225 | 225 | |
|
226 | 226 | return 1 |
|
227 | 227 | |
|
228 | 228 | def write(self, fp): |
|
229 | 229 | |
|
230 | 230 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
231 | 231 | header = numpy.array(headerTuple,SYSTEM_STRUCTURE) |
|
232 | 232 | header.tofile(fp) |
|
233 | 233 | |
|
234 | 234 | return 1 |
|
235 | 235 | |
|
236 | 236 | class RadarControllerHeader(Header): |
|
237 | 237 | |
|
238 | 238 | expType = None |
|
239 | 239 | nTx = None |
|
240 | 240 | ipp = None |
|
241 | 241 | txA = None |
|
242 | 242 | txB = None |
|
243 | 243 | nWindows = None |
|
244 | 244 | numTaus = None |
|
245 | 245 | codeType = None |
|
246 | 246 | line6Function = None |
|
247 | 247 | line5Function = None |
|
248 | 248 | fClock = None |
|
249 | 249 | prePulseBefore = None |
|
250 | 250 | prePulserAfter = None |
|
251 | 251 | rangeIpp = None |
|
252 | 252 | rangeTxA = None |
|
253 | 253 | rangeTxB = None |
|
254 | 254 | |
|
255 | 255 | __size = None |
|
256 | 256 | |
|
257 | 257 | def __init__(self, expType=2, nTx=1, |
|
258 | 258 | ippKm=None, txA=0, txB=0, |
|
259 | 259 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, |
|
260 | 260 | numTaus=0, line6Function=0, line5Function=0, fClock=None, |
|
261 | 261 | prePulseBefore=0, prePulseAfter=0, |
|
262 | 262 | codeType=0, nCode=0, nBaud=0, code=None, |
|
263 | 263 | flip1=0, flip2=0): |
|
264 | 264 | |
|
265 | 265 | # self.size = 116 |
|
266 | 266 | self.expType = expType |
|
267 | 267 | self.nTx = nTx |
|
268 | 268 | self.ipp = ippKm |
|
269 | 269 | self.txA = txA |
|
270 | 270 | self.txB = txB |
|
271 | 271 | self.rangeIpp = ippKm |
|
272 | 272 | self.rangeTxA = txA |
|
273 | 273 | self.rangeTxB = txB |
|
274 | 274 | |
|
275 | 275 | self.nWindows = nWindows |
|
276 | 276 | self.numTaus = numTaus |
|
277 | 277 | self.codeType = codeType |
|
278 | 278 | self.line6Function = line6Function |
|
279 | 279 | self.line5Function = line5Function |
|
280 | 280 | self.fClock = fClock |
|
281 | 281 | self.prePulseBefore = prePulseBefore |
|
282 | 282 | self.prePulserAfter = prePulseAfter |
|
283 | 283 | |
|
284 | 284 | self.nHeights = nHeights |
|
285 | 285 | self.firstHeight = firstHeight |
|
286 | 286 | self.deltaHeight = deltaHeight |
|
287 | 287 | self.samplesWin = nHeights |
|
288 | 288 | |
|
289 | 289 | self.nCode = nCode |
|
290 | 290 | self.nBaud = nBaud |
|
291 | 291 | self.code = code |
|
292 | 292 | self.flip1 = flip1 |
|
293 | 293 | self.flip2 = flip2 |
|
294 | 294 | |
|
295 | 295 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 |
|
296 | 296 | # self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
297 | 297 | |
|
298 | 298 | if self.fClock is None and self.deltaHeight is not None: |
|
299 | 299 | self.fClock = 0.15/(deltaHeight*1e-6) #0.15Km / (height * 1u) |
|
300 | 300 | |
|
301 | 301 | def read(self, fp): |
|
302 | 302 | |
|
303 | 303 | |
|
304 | 304 | startFp = fp.tell() |
|
305 | 305 | try: |
|
306 | 306 | header = numpy.fromfile(fp,RADAR_STRUCTURE,1) |
|
307 | 307 | except Exception, e: |
|
308 | 308 | print "RadarControllerHeader: " + e |
|
309 | 309 | return 0 |
|
310 | 310 | |
|
311 | 311 | size = int(header['nSize'][0]) |
|
312 | 312 | self.expType = int(header['nExpType'][0]) |
|
313 | 313 | self.nTx = int(header['nNTx'][0]) |
|
314 | 314 | self.ipp = float(header['fIpp'][0]) |
|
315 | 315 | self.txA = float(header['fTxA'][0]) |
|
316 | 316 | self.txB = float(header['fTxB'][0]) |
|
317 | 317 | self.nWindows = int(header['nNumWindows'][0]) |
|
318 | 318 | self.numTaus = int(header['nNumTaus'][0]) |
|
319 | 319 | self.codeType = int(header['nCodeType'][0]) |
|
320 | 320 | self.line6Function = int(header['nLine6Function'][0]) |
|
321 | 321 | self.line5Function = int(header['nLine5Function'][0]) |
|
322 | 322 | self.fClock = float(header['fClock'][0]) |
|
323 | 323 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
324 | 324 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) |
|
325 | 325 | self.rangeIpp = header['sRangeIPP'][0] |
|
326 | 326 | self.rangeTxA = header['sRangeTxA'][0] |
|
327 | 327 | self.rangeTxB = header['sRangeTxB'][0] |
|
328 | 328 | |
|
329 | 329 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) |
|
330 | 330 | |
|
331 | 331 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
332 | 332 | self.firstHeight = samplingWindow['h0'] |
|
333 | 333 | self.deltaHeight = samplingWindow['dh'] |
|
334 | 334 | self.samplesWin = samplingWindow['nsa'] |
|
335 | 335 | |
|
336 | 336 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
337 | 337 | |
|
338 | 338 | self.code_size = 0 |
|
339 | 339 | if self.codeType != 0: |
|
340 | 340 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
341 | 341 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
342 | 342 | |
|
343 | 343 | code = numpy.empty([self.nCode,self.nBaud],dtype='i1') |
|
344 | 344 | for ic in range(self.nCode): |
|
345 | 345 | temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.))) |
|
346 | 346 | for ib in range(self.nBaud-1,-1,-1): |
|
347 | 347 | code[ic,ib] = temp[ib/32]%2 |
|
348 | 348 | temp[ib/32] = temp[ib/32]/2 |
|
349 | 349 | |
|
350 | 350 | self.code = 2.0*code - 1.0 |
|
351 | 351 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 |
|
352 | 352 | |
|
353 | 353 | # if self.line5Function == RCfunction.FLIP: |
|
354 | 354 | # self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
355 | 355 | # |
|
356 | 356 | # if self.line6Function == RCfunction.FLIP: |
|
357 | 357 | # self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
358 | 358 | |
|
359 | 359 | endFp = size + startFp |
|
360 | 360 | |
|
361 | 361 | if fp.tell() != endFp: |
|
362 | 362 | # fp.seek(endFp) |
|
363 | 363 | print "%s: Radar Controller Header size is not consistent: from data [%d] != from header field [%d]" %(fp.name, fp.tell()-startFp, size) |
|
364 | 364 | # return 0 |
|
365 | 365 | |
|
366 | 366 | if fp.tell() > endFp: |
|
367 | 367 | sys.stderr.write("Warning %s: Size value read from Radar Controller header is lower than it has to be\n" %fp.name) |
|
368 | 368 | # return 0 |
|
369 | 369 | |
|
370 | 370 | if fp.tell() < endFp: |
|
371 | 371 | sys.stderr.write("Warning %s: Size value read from Radar Controller header is greater than it has to be\n" %fp.name) |
|
372 | 372 | |
|
373 | 373 | |
|
374 | 374 | return 1 |
|
375 | 375 | |
|
376 | 376 | def write(self, fp): |
|
377 | 377 | |
|
378 | 378 | headerTuple = (self.size, |
|
379 | 379 | self.expType, |
|
380 | 380 | self.nTx, |
|
381 | 381 | self.ipp, |
|
382 | 382 | self.txA, |
|
383 | 383 | self.txB, |
|
384 | 384 | self.nWindows, |
|
385 | 385 | self.numTaus, |
|
386 | 386 | self.codeType, |
|
387 | 387 | self.line6Function, |
|
388 | 388 | self.line5Function, |
|
389 | 389 | self.fClock, |
|
390 | 390 | self.prePulseBefore, |
|
391 | 391 | self.prePulserAfter, |
|
392 | 392 | self.rangeIpp, |
|
393 | 393 | self.rangeTxA, |
|
394 | 394 | self.rangeTxB) |
|
395 | 395 | |
|
396 | 396 | header = numpy.array(headerTuple,RADAR_STRUCTURE) |
|
397 | 397 | header.tofile(fp) |
|
398 | 398 | |
|
399 | 399 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
400 | 400 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
401 | 401 | samplingWindow.tofile(fp) |
|
402 | 402 | |
|
403 | 403 | if self.numTaus > 0: |
|
404 | 404 | self.Taus.tofile(fp) |
|
405 | 405 | |
|
406 | 406 | if self.codeType !=0: |
|
407 | 407 | nCode = numpy.array(self.nCode, '<u4') |
|
408 | 408 | nCode.tofile(fp) |
|
409 | 409 | nBaud = numpy.array(self.nBaud, '<u4') |
|
410 | 410 | nBaud.tofile(fp) |
|
411 | 411 | code1 = (self.code + 1.0)/2. |
|
412 | 412 | |
|
413 | 413 | for ic in range(self.nCode): |
|
414 | tempx = numpy.zeros(numpy.ceil(self.nBaud/32.)) | |
|
414 | tempx = numpy.zeros(int(numpy.ceil(self.nBaud/32.))) | |
|
415 | 415 | start = 0 |
|
416 | 416 | end = 32 |
|
417 | 417 | for i in range(len(tempx)): |
|
418 | 418 | code_selected = code1[ic,start:end] |
|
419 | 419 | for j in range(len(code_selected)-1,-1,-1): |
|
420 | 420 | if code_selected[j] == 1: |
|
421 | 421 | tempx[i] = tempx[i] + 2**(len(code_selected)-1-j) |
|
422 | 422 | start = start + 32 |
|
423 | 423 | end = end + 32 |
|
424 | 424 | |
|
425 | 425 | tempx = tempx.astype('u4') |
|
426 | 426 | tempx.tofile(fp) |
|
427 | 427 | |
|
428 | 428 | # if self.line5Function == RCfunction.FLIP: |
|
429 | 429 | # self.flip1.tofile(fp) |
|
430 | 430 | # |
|
431 | 431 | # if self.line6Function == RCfunction.FLIP: |
|
432 | 432 | # self.flip2.tofile(fp) |
|
433 | 433 | |
|
434 | 434 | return 1 |
|
435 | 435 | |
|
436 | 436 | def get_ippSeconds(self): |
|
437 | 437 | ''' |
|
438 | 438 | ''' |
|
439 | 439 | ippSeconds = 2.0 * 1000 * self.ipp / SPEED_OF_LIGHT |
|
440 | 440 | |
|
441 | 441 | return ippSeconds |
|
442 | 442 | |
|
443 | 443 | def set_ippSeconds(self, ippSeconds): |
|
444 | 444 | ''' |
|
445 | 445 | ''' |
|
446 | 446 | |
|
447 | 447 | self.ipp = ippSeconds * SPEED_OF_LIGHT / (2.0*1000) |
|
448 | 448 | |
|
449 | 449 | return |
|
450 | 450 | |
|
451 | 451 | def get_size(self): |
|
452 | 452 | |
|
453 | 453 | self.__size = 116 + 12*self.nWindows + 4*self.numTaus |
|
454 | 454 | |
|
455 | 455 | if self.codeType != 0: |
|
456 | 456 | self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) |
|
457 | 457 | |
|
458 | 458 | return self.__size |
|
459 | 459 | |
|
460 | 460 | def set_size(self, value): |
|
461 | 461 | |
|
462 | 462 | raise IOError, "size is a property and it cannot be set, just read" |
|
463 | 463 | |
|
464 | 464 | return |
|
465 | 465 | |
|
466 | 466 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
467 | 467 | size = property(get_size, set_size) |
|
468 | 468 | |
|
469 | 469 | class ProcessingHeader(Header): |
|
470 | 470 | |
|
471 | 471 | # size = None |
|
472 | 472 | dtype = None |
|
473 | 473 | blockSize = None |
|
474 | 474 | profilesPerBlock = None |
|
475 | 475 | dataBlocksPerFile = None |
|
476 | 476 | nWindows = None |
|
477 | 477 | processFlags = None |
|
478 | 478 | nCohInt = None |
|
479 | 479 | nIncohInt = None |
|
480 | 480 | totalSpectra = None |
|
481 | 481 | |
|
482 | 482 | flag_dc = None |
|
483 | 483 | flag_cspc = None |
|
484 | 484 | |
|
485 | 485 | def __init__(self): |
|
486 | 486 | |
|
487 | 487 | # self.size = 0 |
|
488 | 488 | self.dtype = 0 |
|
489 | 489 | self.blockSize = 0 |
|
490 | 490 | self.profilesPerBlock = 0 |
|
491 | 491 | self.dataBlocksPerFile = 0 |
|
492 | 492 | self.nWindows = 0 |
|
493 | 493 | self.processFlags = 0 |
|
494 | 494 | self.nCohInt = 0 |
|
495 | 495 | self.nIncohInt = 0 |
|
496 | 496 | self.totalSpectra = 0 |
|
497 | 497 | |
|
498 | 498 | self.nHeights = 0 |
|
499 | 499 | self.firstHeight = 0 |
|
500 | 500 | self.deltaHeight = 0 |
|
501 | 501 | self.samplesWin = 0 |
|
502 | 502 | self.spectraComb = 0 |
|
503 | 503 | self.nCode = None |
|
504 | 504 | self.code = None |
|
505 | 505 | self.nBaud = None |
|
506 | 506 | |
|
507 | 507 | self.shif_fft = False |
|
508 | 508 | self.flag_dc = False |
|
509 | 509 | self.flag_cspc = False |
|
510 | 510 | self.flag_decode = False |
|
511 | 511 | self.flag_deflip = False |
|
512 | 512 | |
|
513 | 513 | def read(self, fp): |
|
514 | 514 | |
|
515 | 515 | startFp = fp.tell() |
|
516 | 516 | |
|
517 | 517 | try: |
|
518 | 518 | header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1) |
|
519 | 519 | except Exception, e: |
|
520 | 520 | print "ProcessingHeader: " + e |
|
521 | 521 | return 0 |
|
522 | 522 | |
|
523 | 523 | size = int(header['nSize'][0]) |
|
524 | 524 | self.dtype = int(header['nDataType'][0]) |
|
525 | 525 | self.blockSize = int(header['nSizeOfDataBlock'][0]) |
|
526 | 526 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) |
|
527 | 527 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) |
|
528 | 528 | self.nWindows = int(header['nNumWindows'][0]) |
|
529 | 529 | self.processFlags = header['nProcessFlags'] |
|
530 | 530 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
531 | 531 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
532 | 532 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
533 | 533 | |
|
534 | 534 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) |
|
535 | 535 | |
|
536 | 536 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) |
|
537 | 537 | self.firstHeight = float(samplingWindow['h0'][0]) |
|
538 | 538 | self.deltaHeight = float(samplingWindow['dh'][0]) |
|
539 | 539 | self.samplesWin = samplingWindow['nsa'][0] |
|
540 | 540 | |
|
541 | 541 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
542 | 542 | |
|
543 | 543 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
544 | 544 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
545 | 545 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
546 | 546 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) |
|
547 | 547 | |
|
548 | 548 | if ((self.processFlags & PROCFLAG.EXP_NAME_ESP) == PROCFLAG.EXP_NAME_ESP): |
|
549 | 549 | exp_name_len = int(numpy.fromfile(fp,'<u4',1)) |
|
550 | 550 | exp_name = numpy.fromfile(fp,'u1',exp_name_len+1) |
|
551 | 551 | |
|
552 | 552 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
553 | 553 | self.shif_fft = True |
|
554 | 554 | else: |
|
555 | 555 | self.shif_fft = False |
|
556 | 556 | |
|
557 | 557 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
558 | 558 | self.flag_dc = True |
|
559 | 559 | else: |
|
560 | 560 | self.flag_dc = False |
|
561 | 561 | |
|
562 | 562 | if ((self.processFlags & PROCFLAG.DECODE_DATA) == PROCFLAG.DECODE_DATA): |
|
563 | 563 | self.flag_decode = True |
|
564 | 564 | else: |
|
565 | 565 | self.flag_decode = False |
|
566 | 566 | |
|
567 | 567 | if ((self.processFlags & PROCFLAG.DEFLIP_DATA) == PROCFLAG.DEFLIP_DATA): |
|
568 | 568 | self.flag_deflip = True |
|
569 | 569 | else: |
|
570 | 570 | self.flag_deflip = False |
|
571 | 571 | |
|
572 | 572 | nChannels = 0 |
|
573 | 573 | nPairs = 0 |
|
574 | 574 | pairList = [] |
|
575 | 575 | |
|
576 | 576 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
577 | 577 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
578 | 578 | nChannels = nChannels + 1 #par de canales iguales |
|
579 | 579 | else: |
|
580 | 580 | nPairs = nPairs + 1 #par de canales diferentes |
|
581 | 581 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
582 | 582 | |
|
583 | 583 | self.flag_cspc = False |
|
584 | 584 | if nPairs > 0: |
|
585 | 585 | self.flag_cspc = True |
|
586 | 586 | |
|
587 | 587 | endFp = size + startFp |
|
588 | 588 | |
|
589 | 589 | if fp.tell() > endFp: |
|
590 | 590 | sys.stderr.write("Warning: Processing header size is lower than it has to be") |
|
591 | 591 | return 0 |
|
592 | 592 | |
|
593 | 593 | if fp.tell() < endFp: |
|
594 | 594 | sys.stderr.write("Warning: Processing header size is greater than it is considered") |
|
595 | 595 | |
|
596 | 596 | return 1 |
|
597 | 597 | |
|
598 | 598 | def write(self, fp): |
|
599 | 599 | #Clear DEFINE_PROCESS_CODE |
|
600 | 600 | self.processFlags = self.processFlags & (~PROCFLAG.DEFINE_PROCESS_CODE) |
|
601 | 601 | |
|
602 | 602 | headerTuple = (self.size, |
|
603 | 603 | self.dtype, |
|
604 | 604 | self.blockSize, |
|
605 | 605 | self.profilesPerBlock, |
|
606 | 606 | self.dataBlocksPerFile, |
|
607 | 607 | self.nWindows, |
|
608 | 608 | self.processFlags, |
|
609 | 609 | self.nCohInt, |
|
610 | 610 | self.nIncohInt, |
|
611 | 611 | self.totalSpectra) |
|
612 | 612 | |
|
613 | 613 | header = numpy.array(headerTuple,PROCESSING_STRUCTURE) |
|
614 | 614 | header.tofile(fp) |
|
615 | 615 | |
|
616 | 616 | if self.nWindows != 0: |
|
617 | 617 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
618 | 618 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
619 | 619 | samplingWindow.tofile(fp) |
|
620 | 620 | |
|
621 | 621 | if self.totalSpectra != 0: |
|
622 | 622 | # spectraComb = numpy.array([],numpy.dtype('u1')) |
|
623 | 623 | spectraComb = self.spectraComb |
|
624 | 624 | spectraComb.tofile(fp) |
|
625 | 625 | |
|
626 | 626 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
627 | 627 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
628 | 628 | # nCode.tofile(fp) |
|
629 | 629 | # |
|
630 | 630 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) |
|
631 | 631 | # nBaud.tofile(fp) |
|
632 | 632 | # |
|
633 | 633 | # code = self.code.reshape(self.nCode*self.nBaud) |
|
634 | 634 | # code = code.astype(numpy.dtype('<f4')) |
|
635 | 635 | # code.tofile(fp) |
|
636 | 636 | |
|
637 | 637 | return 1 |
|
638 | 638 | |
|
639 | 639 | def get_size(self): |
|
640 | 640 | |
|
641 | 641 | self.__size = 40 + 12*self.nWindows + 2*self.totalSpectra |
|
642 | 642 | |
|
643 | 643 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
644 | 644 | # self.__size += 4 + 4 + 4*self.nCode*numpy.ceil(self.nBaud/32.) |
|
645 | 645 | # self.__size += 4 + 4 + 4 * self.nCode * self.nBaud |
|
646 | 646 | |
|
647 | 647 | return self.__size |
|
648 | 648 | |
|
649 | 649 | def set_size(self, value): |
|
650 | 650 | |
|
651 | 651 | raise IOError, "size is a property and it cannot be set, just read" |
|
652 | 652 | |
|
653 | 653 | return |
|
654 | 654 | |
|
655 | 655 | size = property(get_size, set_size) |
|
656 | 656 | |
|
657 | 657 | class RCfunction: |
|
658 | 658 | NONE=0 |
|
659 | 659 | FLIP=1 |
|
660 | 660 | CODE=2 |
|
661 | 661 | SAMPLING=3 |
|
662 | 662 | LIN6DIV256=4 |
|
663 | 663 | SYNCHRO=5 |
|
664 | 664 | |
|
665 | 665 | class nCodeType: |
|
666 | 666 | NONE=0 |
|
667 | 667 | USERDEFINE=1 |
|
668 | 668 | BARKER2=2 |
|
669 | 669 | BARKER3=3 |
|
670 | 670 | BARKER4=4 |
|
671 | 671 | BARKER5=5 |
|
672 | 672 | BARKER7=6 |
|
673 | 673 | BARKER11=7 |
|
674 | 674 | BARKER13=8 |
|
675 | 675 | AC128=9 |
|
676 | 676 | COMPLEMENTARYCODE2=10 |
|
677 | 677 | COMPLEMENTARYCODE4=11 |
|
678 | 678 | COMPLEMENTARYCODE8=12 |
|
679 | 679 | COMPLEMENTARYCODE16=13 |
|
680 | 680 | COMPLEMENTARYCODE32=14 |
|
681 | 681 | COMPLEMENTARYCODE64=15 |
|
682 | 682 | COMPLEMENTARYCODE128=16 |
|
683 | 683 | CODE_BINARY28=17 |
|
684 | 684 | |
|
685 | 685 | class PROCFLAG: |
|
686 | 686 | |
|
687 | 687 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
688 | 688 | DECODE_DATA = numpy.uint32(0x00000002) |
|
689 | 689 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
690 | 690 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
691 | 691 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
692 | 692 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
693 | 693 | |
|
694 | 694 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
695 | 695 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
696 | 696 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
697 | 697 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
698 | 698 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
699 | 699 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
700 | 700 | |
|
701 | 701 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
702 | 702 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
703 | 703 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
704 | 704 | |
|
705 | 705 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
706 | 706 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
707 | 707 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
708 | 708 | |
|
709 | 709 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
710 | 710 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
711 | 711 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
712 | 712 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
713 | 713 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
714 | 714 | |
|
715 | 715 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
716 | 716 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
717 | 717 | |
|
718 | 718 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
719 | 719 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
720 | 720 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
721 | 721 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
|
722 | 722 | |
|
723 | 723 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
724 | 724 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
725 | 725 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
726 | 726 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
727 | 727 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
728 | 728 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
729 | 729 | |
|
730 | 730 | NUMPY_DTYPE_LIST = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
731 | 731 | |
|
732 | 732 | PROCFLAG_DTYPE_LIST = [PROCFLAG.DATATYPE_CHAR, |
|
733 | 733 | PROCFLAG.DATATYPE_SHORT, |
|
734 | 734 | PROCFLAG.DATATYPE_LONG, |
|
735 | 735 | PROCFLAG.DATATYPE_INT64, |
|
736 | 736 | PROCFLAG.DATATYPE_FLOAT, |
|
737 | 737 | PROCFLAG.DATATYPE_DOUBLE] |
|
738 | 738 | |
|
739 | 739 | DTYPE_WIDTH = [1, 2, 4, 8, 4, 8] |
|
740 | 740 | |
|
741 | 741 | def get_dtype_index(numpy_dtype): |
|
742 | 742 | |
|
743 | 743 | index = None |
|
744 | 744 | |
|
745 | 745 | for i in range(len(NUMPY_DTYPE_LIST)): |
|
746 | 746 | if numpy_dtype == NUMPY_DTYPE_LIST[i]: |
|
747 | 747 | index = i |
|
748 | 748 | break |
|
749 | 749 | |
|
750 | 750 | return index |
|
751 | 751 | |
|
752 | 752 | def get_numpy_dtype(index): |
|
753 | 753 | |
|
754 | 754 | return NUMPY_DTYPE_LIST[index] |
|
755 | 755 | |
|
756 | 756 | def get_procflag_dtype(index): |
|
757 | 757 | |
|
758 | 758 | return PROCFLAG_DTYPE_LIST[index] |
|
759 | 759 | |
|
760 | 760 | def get_dtype_width(index): |
|
761 | 761 | |
|
762 | 762 | return DTYPE_WIDTH[index] No newline at end of file |
@@ -1,2155 +1,2160 | |||
|
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 FitGauPlot(Figure): |
|
10 | 10 | |
|
11 | 11 | isConfig = None |
|
12 | 12 | __nsubplots = None |
|
13 | 13 | |
|
14 | 14 | WIDTHPROF = None |
|
15 | 15 | HEIGHTPROF = None |
|
16 | 16 | PREFIX = 'fitgau' |
|
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 , GauSelector = 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.spc_range[0] |
|
122 | 122 | xlabel = "Frequency (kHz)" |
|
123 | 123 | |
|
124 | 124 | elif xaxis == "time": |
|
125 | 125 | x = dataOut.spc_range[1] |
|
126 | 126 | xlabel = "Time (ms)" |
|
127 | 127 | |
|
128 | 128 | else: |
|
129 | 129 | x = dataOut.spc_range[2] |
|
130 | 130 | xlabel = "Velocity (m/s)" |
|
131 | 131 | |
|
132 | 132 | ylabel = "Range (Km)" |
|
133 | 133 | |
|
134 | 134 | y = dataOut.getHeiRange() |
|
135 | 135 | |
|
136 | 136 | z = dataOut.GauSPC[:,GauSelector,:,:] #GauSelector] #dataOut.data_spc/factor |
|
137 | 137 | print 'GausSPC', z[0,32,10:40] |
|
138 | 138 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
139 | 139 | zdB = 10*numpy.log10(z) |
|
140 | 140 | |
|
141 | 141 | avg = numpy.average(z, axis=1) |
|
142 | 142 | avgdB = 10*numpy.log10(avg) |
|
143 | 143 | |
|
144 | 144 | noise = dataOut.spc_noise |
|
145 | 145 | noisedB = 10*numpy.log10(noise) |
|
146 | 146 | |
|
147 | 147 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
148 | 148 | title = wintitle + " Spectra" |
|
149 | 149 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
150 | 150 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
151 | 151 | |
|
152 | 152 | if not self.isConfig: |
|
153 | 153 | |
|
154 | 154 | nplots = len(channelIndexList) |
|
155 | 155 | |
|
156 | 156 | self.setup(id=id, |
|
157 | 157 | nplots=nplots, |
|
158 | 158 | wintitle=wintitle, |
|
159 | 159 | showprofile=showprofile, |
|
160 | 160 | show=show) |
|
161 | 161 | |
|
162 | 162 | if xmin == None: xmin = numpy.nanmin(x) |
|
163 | 163 | if xmax == None: xmax = numpy.nanmax(x) |
|
164 | 164 | if ymin == None: ymin = numpy.nanmin(y) |
|
165 | 165 | if ymax == None: ymax = numpy.nanmax(y) |
|
166 | 166 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
167 | 167 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
168 | 168 | |
|
169 | 169 | self.FTP_WEI = ftp_wei |
|
170 | 170 | self.EXP_CODE = exp_code |
|
171 | 171 | self.SUB_EXP_CODE = sub_exp_code |
|
172 | 172 | self.PLOT_POS = plot_pos |
|
173 | 173 | |
|
174 | 174 | self.isConfig = True |
|
175 | 175 | |
|
176 | 176 | self.setWinTitle(title) |
|
177 | 177 | |
|
178 | 178 | for i in range(self.nplots): |
|
179 | 179 | index = channelIndexList[i] |
|
180 | 180 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
181 | 181 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
182 | 182 | if len(dataOut.beam.codeList) != 0: |
|
183 | 183 | 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) |
|
184 | 184 | |
|
185 | 185 | axes = self.axesList[i*self.__nsubplots] |
|
186 | 186 | axes.pcolor(x, y, zdB[index,:,:], |
|
187 | 187 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
188 | 188 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, |
|
189 | 189 | ticksize=9, cblabel='') |
|
190 | 190 | |
|
191 | 191 | if self.__showprofile: |
|
192 | 192 | axes = self.axesList[i*self.__nsubplots +1] |
|
193 | 193 | axes.pline(avgdB[index,:], y, |
|
194 | 194 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
195 | 195 | xlabel='dB', ylabel='', title='', |
|
196 | 196 | ytick_visible=False, |
|
197 | 197 | grid='x') |
|
198 | 198 | |
|
199 | 199 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
200 | 200 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
201 | 201 | |
|
202 | 202 | self.draw() |
|
203 | 203 | |
|
204 | 204 | if figfile == None: |
|
205 | 205 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
206 | 206 | name = str_datetime |
|
207 | 207 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
208 | 208 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
209 | 209 | figfile = self.getFilename(name) |
|
210 | 210 | |
|
211 | 211 | self.save(figpath=figpath, |
|
212 | 212 | figfile=figfile, |
|
213 | 213 | save=save, |
|
214 | 214 | ftp=ftp, |
|
215 | 215 | wr_period=wr_period, |
|
216 | 216 | thisDatetime=thisDatetime) |
|
217 | 217 | |
|
218 | 218 | |
|
219 | 219 | |
|
220 | 220 | class MomentsPlot(Figure): |
|
221 | 221 | |
|
222 | 222 | isConfig = None |
|
223 | 223 | __nsubplots = None |
|
224 | 224 | |
|
225 | 225 | WIDTHPROF = None |
|
226 | 226 | HEIGHTPROF = None |
|
227 | 227 | PREFIX = 'prm' |
|
228 | 228 | |
|
229 | 229 | def __init__(self, **kwargs): |
|
230 | 230 | Figure.__init__(self, **kwargs) |
|
231 | 231 | self.isConfig = False |
|
232 | 232 | self.__nsubplots = 1 |
|
233 | 233 | |
|
234 | 234 | self.WIDTH = 280 |
|
235 | 235 | self.HEIGHT = 250 |
|
236 | 236 | self.WIDTHPROF = 120 |
|
237 | 237 | self.HEIGHTPROF = 0 |
|
238 | 238 | self.counter_imagwr = 0 |
|
239 | 239 | |
|
240 | 240 | self.PLOT_CODE = MOMENTS_CODE |
|
241 | 241 | |
|
242 | 242 | self.FTP_WEI = None |
|
243 | 243 | self.EXP_CODE = None |
|
244 | 244 | self.SUB_EXP_CODE = None |
|
245 | 245 | self.PLOT_POS = None |
|
246 | 246 | |
|
247 | 247 | def getSubplots(self): |
|
248 | 248 | |
|
249 | 249 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
250 | 250 | nrow = int(self.nplots*1./ncol + 0.9) |
|
251 | 251 | |
|
252 | 252 | return nrow, ncol |
|
253 | 253 | |
|
254 | 254 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
255 | 255 | |
|
256 | 256 | self.__showprofile = showprofile |
|
257 | 257 | self.nplots = nplots |
|
258 | 258 | |
|
259 | 259 | ncolspan = 1 |
|
260 | 260 | colspan = 1 |
|
261 | 261 | if showprofile: |
|
262 | 262 | ncolspan = 3 |
|
263 | 263 | colspan = 2 |
|
264 | 264 | self.__nsubplots = 2 |
|
265 | 265 | |
|
266 | 266 | self.createFigure(id = id, |
|
267 | 267 | wintitle = wintitle, |
|
268 | 268 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
269 | 269 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
270 | 270 | show=show) |
|
271 | 271 | |
|
272 | 272 | nrow, ncol = self.getSubplots() |
|
273 | 273 | |
|
274 | 274 | counter = 0 |
|
275 | 275 | for y in range(nrow): |
|
276 | 276 | for x in range(ncol): |
|
277 | 277 | |
|
278 | 278 | if counter >= self.nplots: |
|
279 | 279 | break |
|
280 | 280 | |
|
281 | 281 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
282 | 282 | |
|
283 | 283 | if showprofile: |
|
284 | 284 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
285 | 285 | |
|
286 | 286 | counter += 1 |
|
287 | 287 | |
|
288 | 288 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
289 | 289 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
290 | 290 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
291 | 291 | server=None, folder=None, username=None, password=None, |
|
292 | 292 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
293 | 293 | |
|
294 | 294 | """ |
|
295 | 295 | |
|
296 | 296 | Input: |
|
297 | 297 | dataOut : |
|
298 | 298 | id : |
|
299 | 299 | wintitle : |
|
300 | 300 | channelList : |
|
301 | 301 | showProfile : |
|
302 | 302 | xmin : None, |
|
303 | 303 | xmax : None, |
|
304 | 304 | ymin : None, |
|
305 | 305 | ymax : None, |
|
306 | 306 | zmin : None, |
|
307 | 307 | zmax : None |
|
308 | 308 | """ |
|
309 | 309 | |
|
310 | 310 | if dataOut.flagNoData: |
|
311 | 311 | return None |
|
312 | 312 | |
|
313 | 313 | if realtime: |
|
314 | 314 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
315 | 315 | print 'Skipping this plot function' |
|
316 | 316 | return |
|
317 | 317 | |
|
318 | 318 | if channelList == None: |
|
319 | 319 | channelIndexList = dataOut.channelIndexList |
|
320 | 320 | else: |
|
321 | 321 | channelIndexList = [] |
|
322 | 322 | for channel in channelList: |
|
323 | 323 | if channel not in dataOut.channelList: |
|
324 | 324 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
325 | 325 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
326 | 326 | |
|
327 | 327 | factor = dataOut.normFactor |
|
328 | 328 | x = dataOut.abscissaList |
|
329 | 329 | y = dataOut.heightList |
|
330 | 330 | |
|
331 | 331 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
332 | 332 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
333 | 333 | avg = numpy.average(z, axis=1) |
|
334 | 334 | noise = dataOut.noise/factor |
|
335 | 335 | |
|
336 | 336 | zdB = 10*numpy.log10(z) |
|
337 | 337 | avgdB = 10*numpy.log10(avg) |
|
338 | 338 | noisedB = 10*numpy.log10(noise) |
|
339 | 339 | |
|
340 | 340 | #thisDatetime = dataOut.datatime |
|
341 | 341 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
342 | 342 | title = wintitle + " Parameters" |
|
343 | 343 | xlabel = "Velocity (m/s)" |
|
344 | 344 | ylabel = "Range (Km)" |
|
345 | 345 | |
|
346 | 346 | update_figfile = False |
|
347 | 347 | |
|
348 | 348 | if not self.isConfig: |
|
349 | 349 | |
|
350 | 350 | nplots = len(channelIndexList) |
|
351 | 351 | |
|
352 | 352 | self.setup(id=id, |
|
353 | 353 | nplots=nplots, |
|
354 | 354 | wintitle=wintitle, |
|
355 | 355 | showprofile=showprofile, |
|
356 | 356 | show=show) |
|
357 | 357 | |
|
358 | 358 | if xmin == None: xmin = numpy.nanmin(x) |
|
359 | 359 | if xmax == None: xmax = numpy.nanmax(x) |
|
360 | 360 | if ymin == None: ymin = numpy.nanmin(y) |
|
361 | 361 | if ymax == None: ymax = numpy.nanmax(y) |
|
362 | 362 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
363 | 363 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
364 | 364 | |
|
365 | 365 | self.FTP_WEI = ftp_wei |
|
366 | 366 | self.EXP_CODE = exp_code |
|
367 | 367 | self.SUB_EXP_CODE = sub_exp_code |
|
368 | 368 | self.PLOT_POS = plot_pos |
|
369 | 369 | |
|
370 | 370 | self.isConfig = True |
|
371 | 371 | update_figfile = True |
|
372 | 372 | |
|
373 | 373 | self.setWinTitle(title) |
|
374 | 374 | |
|
375 | 375 | for i in range(self.nplots): |
|
376 | 376 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
377 | 377 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime) |
|
378 | 378 | axes = self.axesList[i*self.__nsubplots] |
|
379 | 379 | axes.pcolor(x, y, zdB[i,:,:], |
|
380 | 380 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
381 | 381 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
382 | 382 | ticksize=9, cblabel='') |
|
383 | 383 | #Mean Line |
|
384 | 384 | mean = dataOut.data_param[i, 1, :] |
|
385 | 385 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
386 | 386 | |
|
387 | 387 | if self.__showprofile: |
|
388 | 388 | axes = self.axesList[i*self.__nsubplots +1] |
|
389 | 389 | axes.pline(avgdB[i], y, |
|
390 | 390 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
391 | 391 | xlabel='dB', ylabel='', title='', |
|
392 | 392 | ytick_visible=False, |
|
393 | 393 | grid='x') |
|
394 | 394 | |
|
395 | 395 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
396 | 396 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
397 | 397 | |
|
398 | 398 | self.draw() |
|
399 | 399 | |
|
400 | 400 | self.save(figpath=figpath, |
|
401 | 401 | figfile=figfile, |
|
402 | 402 | save=save, |
|
403 | 403 | ftp=ftp, |
|
404 | 404 | wr_period=wr_period, |
|
405 | 405 | thisDatetime=thisDatetime) |
|
406 | 406 | |
|
407 | 407 | |
|
408 | 408 | |
|
409 | 409 | class SkyMapPlot(Figure): |
|
410 | 410 | |
|
411 | 411 | __isConfig = None |
|
412 | 412 | __nsubplots = None |
|
413 | 413 | |
|
414 | 414 | WIDTHPROF = None |
|
415 | 415 | HEIGHTPROF = None |
|
416 | 416 | PREFIX = 'mmap' |
|
417 | 417 | |
|
418 | 418 | def __init__(self, **kwargs): |
|
419 | 419 | Figure.__init__(self, **kwargs) |
|
420 | 420 | self.isConfig = False |
|
421 | 421 | self.__nsubplots = 1 |
|
422 | 422 | |
|
423 | 423 | # self.WIDTH = 280 |
|
424 | 424 | # self.HEIGHT = 250 |
|
425 | 425 | self.WIDTH = 600 |
|
426 | 426 | self.HEIGHT = 600 |
|
427 | 427 | self.WIDTHPROF = 120 |
|
428 | 428 | self.HEIGHTPROF = 0 |
|
429 | 429 | self.counter_imagwr = 0 |
|
430 | 430 | |
|
431 | 431 | self.PLOT_CODE = MSKYMAP_CODE |
|
432 | 432 | |
|
433 | 433 | self.FTP_WEI = None |
|
434 | 434 | self.EXP_CODE = None |
|
435 | 435 | self.SUB_EXP_CODE = None |
|
436 | 436 | self.PLOT_POS = None |
|
437 | 437 | |
|
438 | 438 | def getSubplots(self): |
|
439 | 439 | |
|
440 | 440 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
441 | 441 | nrow = int(self.nplots*1./ncol + 0.9) |
|
442 | 442 | |
|
443 | 443 | return nrow, ncol |
|
444 | 444 | |
|
445 | 445 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
446 | 446 | |
|
447 | 447 | self.__showprofile = showprofile |
|
448 | 448 | self.nplots = nplots |
|
449 | 449 | |
|
450 | 450 | ncolspan = 1 |
|
451 | 451 | colspan = 1 |
|
452 | 452 | |
|
453 | 453 | self.createFigure(id = id, |
|
454 | 454 | wintitle = wintitle, |
|
455 | 455 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
456 | 456 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
457 | 457 | show=show) |
|
458 | 458 | |
|
459 | 459 | nrow, ncol = 1,1 |
|
460 | 460 | counter = 0 |
|
461 | 461 | x = 0 |
|
462 | 462 | y = 0 |
|
463 | 463 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
464 | 464 | |
|
465 | 465 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
466 | 466 | tmin=0, tmax=24, timerange=None, |
|
467 | 467 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
468 | 468 | server=None, folder=None, username=None, password=None, |
|
469 | 469 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
470 | 470 | |
|
471 | 471 | """ |
|
472 | 472 | |
|
473 | 473 | Input: |
|
474 | 474 | dataOut : |
|
475 | 475 | id : |
|
476 | 476 | wintitle : |
|
477 | 477 | channelList : |
|
478 | 478 | showProfile : |
|
479 | 479 | xmin : None, |
|
480 | 480 | xmax : None, |
|
481 | 481 | ymin : None, |
|
482 | 482 | ymax : None, |
|
483 | 483 | zmin : None, |
|
484 | 484 | zmax : None |
|
485 | 485 | """ |
|
486 | 486 | |
|
487 | 487 | arrayParameters = dataOut.data_param |
|
488 | 488 | error = arrayParameters[:,-1] |
|
489 | 489 | indValid = numpy.where(error == 0)[0] |
|
490 | 490 | finalMeteor = arrayParameters[indValid,:] |
|
491 | 491 | finalAzimuth = finalMeteor[:,3] |
|
492 | 492 | finalZenith = finalMeteor[:,4] |
|
493 | 493 | |
|
494 | 494 | x = finalAzimuth*numpy.pi/180 |
|
495 | 495 | y = finalZenith |
|
496 | 496 | x1 = [dataOut.ltctime, dataOut.ltctime] |
|
497 | 497 | |
|
498 | 498 | #thisDatetime = dataOut.datatime |
|
499 | 499 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
500 | 500 | title = wintitle + " Parameters" |
|
501 | 501 | xlabel = "Zonal Zenith Angle (deg) " |
|
502 | 502 | ylabel = "Meridional Zenith Angle (deg)" |
|
503 | 503 | update_figfile = False |
|
504 | 504 | |
|
505 | 505 | if not self.isConfig: |
|
506 | 506 | |
|
507 | 507 | nplots = 1 |
|
508 | 508 | |
|
509 | 509 | self.setup(id=id, |
|
510 | 510 | nplots=nplots, |
|
511 | 511 | wintitle=wintitle, |
|
512 | 512 | showprofile=showprofile, |
|
513 | 513 | show=show) |
|
514 | 514 | |
|
515 | 515 | if self.xmin is None and self.xmax is None: |
|
516 | 516 | self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange) |
|
517 | 517 | |
|
518 | 518 | if timerange != None: |
|
519 | 519 | self.timerange = timerange |
|
520 | 520 | else: |
|
521 | 521 | self.timerange = self.xmax - self.xmin |
|
522 | 522 | |
|
523 | 523 | self.FTP_WEI = ftp_wei |
|
524 | 524 | self.EXP_CODE = exp_code |
|
525 | 525 | self.SUB_EXP_CODE = sub_exp_code |
|
526 | 526 | self.PLOT_POS = plot_pos |
|
527 | 527 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
528 | 528 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
529 | 529 | self.isConfig = True |
|
530 | 530 | update_figfile = True |
|
531 | 531 | |
|
532 | 532 | self.setWinTitle(title) |
|
533 | 533 | |
|
534 | 534 | i = 0 |
|
535 | 535 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
536 | 536 | |
|
537 | 537 | axes = self.axesList[i*self.__nsubplots] |
|
538 | 538 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
539 | 539 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
540 | 540 | axes.polar(x, y, |
|
541 | 541 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
542 | 542 | ticksize=9, cblabel='') |
|
543 | 543 | |
|
544 | 544 | self.draw() |
|
545 | 545 | |
|
546 | 546 | self.save(figpath=figpath, |
|
547 | 547 | figfile=figfile, |
|
548 | 548 | save=save, |
|
549 | 549 | ftp=ftp, |
|
550 | 550 | wr_period=wr_period, |
|
551 | 551 | thisDatetime=thisDatetime, |
|
552 | 552 | update_figfile=update_figfile) |
|
553 | 553 | |
|
554 | 554 | if dataOut.ltctime >= self.xmax: |
|
555 | 555 | self.isConfigmagwr = wr_period |
|
556 | 556 | self.isConfig = False |
|
557 | 557 | update_figfile = True |
|
558 | 558 | axes.__firsttime = True |
|
559 | 559 | self.xmin += self.timerange |
|
560 | 560 | self.xmax += self.timerange |
|
561 | 561 | |
|
562 | 562 | |
|
563 | 563 | |
|
564 | 564 | |
|
565 | 565 | class WindProfilerPlot(Figure): |
|
566 | 566 | |
|
567 | 567 | __isConfig = None |
|
568 | 568 | __nsubplots = None |
|
569 | 569 | |
|
570 | 570 | WIDTHPROF = None |
|
571 | 571 | HEIGHTPROF = None |
|
572 | 572 | PREFIX = 'wind' |
|
573 | 573 | |
|
574 | 574 | def __init__(self, **kwargs): |
|
575 | 575 | Figure.__init__(self, **kwargs) |
|
576 | 576 | self.timerange = None |
|
577 | 577 | self.isConfig = False |
|
578 | 578 | self.__nsubplots = 1 |
|
579 | 579 | |
|
580 | 580 | self.WIDTH = 800 |
|
581 | 581 | self.HEIGHT = 300 |
|
582 | 582 | self.WIDTHPROF = 120 |
|
583 | 583 | self.HEIGHTPROF = 0 |
|
584 | 584 | self.counter_imagwr = 0 |
|
585 | 585 | |
|
586 | 586 | self.PLOT_CODE = WIND_CODE |
|
587 | 587 | |
|
588 | 588 | self.FTP_WEI = None |
|
589 | 589 | self.EXP_CODE = None |
|
590 | 590 | self.SUB_EXP_CODE = None |
|
591 | 591 | self.PLOT_POS = None |
|
592 | 592 | self.tmin = None |
|
593 | 593 | self.tmax = None |
|
594 | 594 | |
|
595 | 595 | self.xmin = None |
|
596 | 596 | self.xmax = None |
|
597 | 597 | |
|
598 | 598 | self.figfile = None |
|
599 | 599 | |
|
600 | 600 | def getSubplots(self): |
|
601 | 601 | |
|
602 | 602 | ncol = 1 |
|
603 | 603 | nrow = self.nplots |
|
604 | 604 | |
|
605 | 605 | return nrow, ncol |
|
606 | 606 | |
|
607 | 607 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
608 | 608 | |
|
609 | 609 | self.__showprofile = showprofile |
|
610 | 610 | self.nplots = nplots |
|
611 | 611 | |
|
612 | 612 | ncolspan = 1 |
|
613 | 613 | colspan = 1 |
|
614 | 614 | |
|
615 | 615 | self.createFigure(id = id, |
|
616 | 616 | wintitle = wintitle, |
|
617 | 617 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
618 | 618 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
619 | 619 | show=show) |
|
620 | 620 | |
|
621 | 621 | nrow, ncol = self.getSubplots() |
|
622 | 622 | |
|
623 | 623 | counter = 0 |
|
624 | 624 | for y in range(nrow): |
|
625 | 625 | if counter >= self.nplots: |
|
626 | 626 | break |
|
627 | 627 | |
|
628 | 628 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
629 | 629 | counter += 1 |
|
630 | 630 | |
|
631 | 631 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False', |
|
632 | 632 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
633 | 633 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
634 | 634 | timerange=None, SNRthresh = None, |
|
635 | 635 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
636 | 636 | server=None, folder=None, username=None, password=None, |
|
637 | 637 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
638 | 638 | """ |
|
639 | 639 | |
|
640 | 640 | Input: |
|
641 | 641 | dataOut : |
|
642 | 642 | id : |
|
643 | 643 | wintitle : |
|
644 | 644 | channelList : |
|
645 | 645 | showProfile : |
|
646 | 646 | xmin : None, |
|
647 | 647 | xmax : None, |
|
648 | 648 | ymin : None, |
|
649 | 649 | ymax : None, |
|
650 | 650 | zmin : None, |
|
651 | 651 | zmax : None |
|
652 | 652 | """ |
|
653 | 653 | |
|
654 | 654 | # if timerange is not None: |
|
655 | 655 | # self.timerange = timerange |
|
656 | 656 | # |
|
657 | 657 | # tmin = None |
|
658 | 658 | # tmax = None |
|
659 | 659 | |
|
660 | 660 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
661 |
y = dataOut.heightList |
|
|
661 | y = dataOut.heightList | |
|
662 | 662 | z = dataOut.data_output.copy() |
|
663 | 663 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
664 | 664 | nplotsw = nplots |
|
665 | 665 | |
|
666 | 666 | |
|
667 | 667 | #If there is a SNR function defined |
|
668 | 668 | if dataOut.data_SNR is not None: |
|
669 | 669 | nplots += 1 |
|
670 | 670 | SNR = dataOut.data_SNR[0] |
|
671 | 671 | SNRavg = SNR#numpy.average(SNR, axis=0) |
|
672 | 672 | |
|
673 | 673 | SNRdB = 10*numpy.log10(SNR) |
|
674 | 674 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
675 | 675 | |
|
676 | 676 | if SNRthresh == None: |
|
677 | 677 | SNRthresh = -5.0 |
|
678 | 678 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
679 | 679 | |
|
680 | 680 | for i in range(nplotsw): |
|
681 | 681 | z[i,ind] = numpy.nan |
|
682 | 682 | |
|
683 | 683 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
684 | 684 | #thisDatetime = datetime.datetime.now() |
|
685 | 685 | title = wintitle + "Wind" |
|
686 | 686 | xlabel = "" |
|
687 | 687 | ylabel = "Height (km)" |
|
688 | 688 | update_figfile = False |
|
689 | 689 | |
|
690 | 690 | if not self.isConfig: |
|
691 | 691 | |
|
692 | 692 | self.setup(id=id, |
|
693 | 693 | nplots=nplots, |
|
694 | 694 | wintitle=wintitle, |
|
695 | 695 | showprofile=showprofile, |
|
696 | 696 | show=show) |
|
697 | 697 | |
|
698 | 698 | if timerange is not None: |
|
699 | 699 | self.timerange = timerange |
|
700 | 700 | |
|
701 | 701 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
702 | 702 | |
|
703 | 703 | if ymin == None: ymin = numpy.nanmin(y) |
|
704 | 704 | if ymax == None: ymax = numpy.nanmax(y) |
|
705 | 705 | |
|
706 | 706 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) |
|
707 | 707 | #if numpy.isnan(zmax): zmax = 50 |
|
708 | 708 | if zmin == None: zmin = -zmax |
|
709 | 709 | |
|
710 | 710 | if nplotsw == 3: |
|
711 | 711 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
712 | 712 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
713 | 713 | |
|
714 | 714 | if dataOut.data_SNR is not None: |
|
715 | 715 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
716 | 716 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
717 | 717 | |
|
718 | 718 | |
|
719 | 719 | self.FTP_WEI = ftp_wei |
|
720 | 720 | self.EXP_CODE = exp_code |
|
721 | 721 | self.SUB_EXP_CODE = sub_exp_code |
|
722 | 722 | self.PLOT_POS = plot_pos |
|
723 | 723 | |
|
724 | 724 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
725 | 725 | self.isConfig = True |
|
726 | 726 | self.figfile = figfile |
|
727 | 727 | update_figfile = True |
|
728 | 728 | |
|
729 | 729 | self.setWinTitle(title) |
|
730 | 730 | |
|
731 | 731 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
732 | 732 | x[1] = self.xmax |
|
733 | 733 | |
|
734 | 734 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
735 | 735 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
736 | 736 | zmaxVector = [zmax, zmax, zmax_ver] |
|
737 | 737 | zminVector = [zmin, zmin, zmin_ver] |
|
738 | 738 | windFactor = [1,1,100] |
|
739 | 739 | |
|
740 | 740 | for i in range(nplotsw): |
|
741 | 741 | |
|
742 | 742 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
743 | 743 | axes = self.axesList[i*self.__nsubplots] |
|
744 | 744 | |
|
745 | 745 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
746 | ||
|
747 | print 'x', x | |
|
748 | print datetime.datetime.utcfromtimestamp(x[0]) | |
|
749 | print datetime.datetime.utcfromtimestamp(x[1]) | |
|
750 | ||
|
746 | 751 | #z1=numpy.ma.masked_where(z1==0.,z1) |
|
747 | 752 | |
|
748 | 753 | axes.pcolorbuffer(x, y, z1, |
|
749 | 754 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
750 | 755 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
751 | 756 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" ) |
|
752 | 757 | |
|
753 | 758 | if dataOut.data_SNR is not None: |
|
754 | 759 | i += 1 |
|
755 | 760 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
756 | 761 | axes = self.axesList[i*self.__nsubplots] |
|
757 | 762 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
758 | 763 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
759 | 764 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
760 | 765 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
761 | 766 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
762 | 767 | |
|
763 | 768 | self.draw() |
|
764 | 769 | |
|
765 | 770 | self.save(figpath=figpath, |
|
766 | 771 | figfile=figfile, |
|
767 | 772 | save=save, |
|
768 | 773 | ftp=ftp, |
|
769 | 774 | wr_period=wr_period, |
|
770 | 775 | thisDatetime=thisDatetime, |
|
771 | 776 | update_figfile=update_figfile) |
|
772 | 777 | |
|
773 | 778 | if dataOut.ltctime + dataOut.paramInterval >= self.xmax: |
|
774 | 779 | self.counter_imagwr = wr_period |
|
775 | 780 | self.isConfig = False |
|
776 | 781 | update_figfile = True |
|
777 | 782 | |
|
778 | 783 | |
|
779 | 784 | class ParametersPlot(Figure): |
|
780 | 785 | |
|
781 | 786 | __isConfig = None |
|
782 | 787 | __nsubplots = None |
|
783 | 788 | |
|
784 | 789 | WIDTHPROF = None |
|
785 | 790 | HEIGHTPROF = None |
|
786 | 791 | PREFIX = 'param' |
|
787 | 792 | |
|
788 | 793 | nplots = None |
|
789 | 794 | nchan = None |
|
790 | 795 | |
|
791 | 796 | def __init__(self, **kwargs): |
|
792 | 797 | Figure.__init__(self, **kwargs) |
|
793 | 798 | self.timerange = None |
|
794 | 799 | self.isConfig = False |
|
795 | 800 | self.__nsubplots = 1 |
|
796 | 801 | |
|
797 | 802 | self.WIDTH = 800 |
|
798 | 803 | self.HEIGHT = 180 |
|
799 | 804 | self.WIDTHPROF = 120 |
|
800 | 805 | self.HEIGHTPROF = 0 |
|
801 | 806 | self.counter_imagwr = 0 |
|
802 | 807 | |
|
803 | 808 | self.PLOT_CODE = RTI_CODE |
|
804 | 809 | |
|
805 | 810 | self.FTP_WEI = None |
|
806 | 811 | self.EXP_CODE = None |
|
807 | 812 | self.SUB_EXP_CODE = None |
|
808 | 813 | self.PLOT_POS = None |
|
809 | 814 | self.tmin = None |
|
810 | 815 | self.tmax = None |
|
811 | 816 | |
|
812 | 817 | self.xmin = None |
|
813 | 818 | self.xmax = None |
|
814 | 819 | |
|
815 | 820 | self.figfile = None |
|
816 | 821 | |
|
817 | 822 | def getSubplots(self): |
|
818 | 823 | |
|
819 | 824 | ncol = 1 |
|
820 | 825 | nrow = self.nplots |
|
821 | 826 | |
|
822 | 827 | return nrow, ncol |
|
823 | 828 | |
|
824 | 829 | def setup(self, id, nplots, wintitle, show=True): |
|
825 | 830 | |
|
826 | 831 | self.nplots = nplots |
|
827 | 832 | |
|
828 | 833 | ncolspan = 1 |
|
829 | 834 | colspan = 1 |
|
830 | 835 | |
|
831 | 836 | self.createFigure(id = id, |
|
832 | 837 | wintitle = wintitle, |
|
833 | 838 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
834 | 839 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
835 | 840 | show=show) |
|
836 | 841 | |
|
837 | 842 | nrow, ncol = self.getSubplots() |
|
838 | 843 | |
|
839 | 844 | counter = 0 |
|
840 | 845 | for y in range(nrow): |
|
841 | 846 | for x in range(ncol): |
|
842 | 847 | |
|
843 | 848 | if counter >= self.nplots: |
|
844 | 849 | break |
|
845 | 850 | |
|
846 | 851 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
847 | 852 | |
|
848 | 853 | counter += 1 |
|
849 | 854 | |
|
850 | 855 | def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet", |
|
851 | 856 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None, |
|
852 | 857 | showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None, |
|
853 | 858 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
854 | 859 | server=None, folder=None, username=None, password=None, |
|
855 | 860 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None): |
|
856 | 861 | """ |
|
857 | 862 | |
|
858 | 863 | Input: |
|
859 | 864 | dataOut : |
|
860 | 865 | id : |
|
861 | 866 | wintitle : |
|
862 | 867 | channelList : |
|
863 | 868 | showProfile : |
|
864 | 869 | xmin : None, |
|
865 | 870 | xmax : None, |
|
866 | 871 | ymin : None, |
|
867 | 872 | ymax : None, |
|
868 | 873 | zmin : None, |
|
869 | 874 | zmax : None |
|
870 | 875 | """ |
|
871 | 876 | |
|
872 | 877 | if HEIGHT is not None: |
|
873 | 878 | self.HEIGHT = HEIGHT |
|
874 | 879 | |
|
875 | 880 | |
|
876 | 881 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
877 | 882 | return |
|
878 | 883 | |
|
879 | 884 | if channelList == None: |
|
880 | 885 | channelIndexList = range(dataOut.data_param.shape[0]) |
|
881 | 886 | else: |
|
882 | 887 | channelIndexList = [] |
|
883 | 888 | for channel in channelList: |
|
884 | 889 | if channel not in dataOut.channelList: |
|
885 | 890 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
886 | 891 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
887 | 892 | |
|
888 | 893 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
889 | 894 | y = dataOut.getHeiRange() |
|
890 | 895 | |
|
891 | 896 | if dataOut.data_param.ndim == 3: |
|
892 | 897 | z = dataOut.data_param[channelIndexList,paramIndex,:] |
|
893 | 898 | else: |
|
894 | 899 | z = dataOut.data_param[channelIndexList,:] |
|
895 | 900 | |
|
896 | 901 | if showSNR: |
|
897 | 902 | #SNR data |
|
898 | 903 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
899 | 904 | SNRdB = 10*numpy.log10(SNRarray) |
|
900 | 905 | ind = numpy.where(SNRdB < SNRthresh) |
|
901 | 906 | z[ind] = numpy.nan |
|
902 | 907 | |
|
903 | 908 | thisDatetime = dataOut.datatime |
|
904 | 909 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
905 | 910 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
906 | 911 | xlabel = "" |
|
907 | 912 | ylabel = "Range (Km)" |
|
908 | 913 | |
|
909 | 914 | update_figfile = False |
|
910 | 915 | |
|
911 | 916 | if not self.isConfig: |
|
912 | 917 | |
|
913 | 918 | nchan = len(channelIndexList) |
|
914 | 919 | self.nchan = nchan |
|
915 | 920 | self.plotFact = 1 |
|
916 | 921 | nplots = nchan |
|
917 | 922 | |
|
918 | 923 | if showSNR: |
|
919 | 924 | nplots = nchan*2 |
|
920 | 925 | self.plotFact = 2 |
|
921 | 926 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
922 | 927 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
923 | 928 | |
|
924 | 929 | self.setup(id=id, |
|
925 | 930 | nplots=nplots, |
|
926 | 931 | wintitle=wintitle, |
|
927 | 932 | show=show) |
|
928 | 933 | |
|
929 | 934 | if timerange != None: |
|
930 | 935 | self.timerange = timerange |
|
931 | 936 | |
|
932 | 937 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
933 | 938 | |
|
934 | 939 | if ymin == None: ymin = numpy.nanmin(y) |
|
935 | 940 | if ymax == None: ymax = numpy.nanmax(y) |
|
936 | 941 | if zmin == None: zmin = numpy.nanmin(z) |
|
937 | 942 | if zmax == None: zmax = numpy.nanmax(z) |
|
938 | 943 | |
|
939 | 944 | self.FTP_WEI = ftp_wei |
|
940 | 945 | self.EXP_CODE = exp_code |
|
941 | 946 | self.SUB_EXP_CODE = sub_exp_code |
|
942 | 947 | self.PLOT_POS = plot_pos |
|
943 | 948 | |
|
944 | 949 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
945 | 950 | self.isConfig = True |
|
946 | 951 | self.figfile = figfile |
|
947 | 952 | update_figfile = True |
|
948 | 953 | |
|
949 | 954 | self.setWinTitle(title) |
|
950 | 955 | |
|
951 | 956 | for i in range(self.nchan): |
|
952 | 957 | index = channelIndexList[i] |
|
953 | 958 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
954 | 959 | axes = self.axesList[i*self.plotFact] |
|
955 | 960 | z1 = z[i,:].reshape((1,-1)) |
|
956 | 961 | axes.pcolorbuffer(x, y, z1, |
|
957 | 962 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
958 | 963 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
959 | 964 | ticksize=9, cblabel='', cbsize="1%",colormap=colormap) |
|
960 | 965 | |
|
961 | 966 | if showSNR: |
|
962 | 967 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
963 | 968 | axes = self.axesList[i*self.plotFact + 1] |
|
964 | 969 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) |
|
965 | 970 | axes.pcolorbuffer(x, y, SNRdB1, |
|
966 | 971 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
967 | 972 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
968 | 973 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') |
|
969 | 974 | |
|
970 | 975 | |
|
971 | 976 | self.draw() |
|
972 | 977 | |
|
973 | 978 | if dataOut.ltctime >= self.xmax: |
|
974 | 979 | self.counter_imagwr = wr_period |
|
975 | 980 | self.isConfig = False |
|
976 | 981 | update_figfile = True |
|
977 | 982 | |
|
978 | 983 | self.save(figpath=figpath, |
|
979 | 984 | figfile=figfile, |
|
980 | 985 | save=save, |
|
981 | 986 | ftp=ftp, |
|
982 | 987 | wr_period=wr_period, |
|
983 | 988 | thisDatetime=thisDatetime, |
|
984 | 989 | update_figfile=update_figfile) |
|
985 | 990 | |
|
986 | 991 | |
|
987 | 992 | |
|
988 | 993 | class Parameters1Plot(Figure): |
|
989 | 994 | |
|
990 | 995 | __isConfig = None |
|
991 | 996 | __nsubplots = None |
|
992 | 997 | |
|
993 | 998 | WIDTHPROF = None |
|
994 | 999 | HEIGHTPROF = None |
|
995 | 1000 | PREFIX = 'prm' |
|
996 | 1001 | |
|
997 | 1002 | def __init__(self, **kwargs): |
|
998 | 1003 | Figure.__init__(self, **kwargs) |
|
999 | 1004 | self.timerange = 2*60*60 |
|
1000 | 1005 | self.isConfig = False |
|
1001 | 1006 | self.__nsubplots = 1 |
|
1002 | 1007 | |
|
1003 | 1008 | self.WIDTH = 800 |
|
1004 | 1009 | self.HEIGHT = 180 |
|
1005 | 1010 | self.WIDTHPROF = 120 |
|
1006 | 1011 | self.HEIGHTPROF = 0 |
|
1007 | 1012 | self.counter_imagwr = 0 |
|
1008 | 1013 | |
|
1009 | 1014 | self.PLOT_CODE = PARMS_CODE |
|
1010 | 1015 | |
|
1011 | 1016 | self.FTP_WEI = None |
|
1012 | 1017 | self.EXP_CODE = None |
|
1013 | 1018 | self.SUB_EXP_CODE = None |
|
1014 | 1019 | self.PLOT_POS = None |
|
1015 | 1020 | self.tmin = None |
|
1016 | 1021 | self.tmax = None |
|
1017 | 1022 | |
|
1018 | 1023 | self.xmin = None |
|
1019 | 1024 | self.xmax = None |
|
1020 | 1025 | |
|
1021 | 1026 | self.figfile = None |
|
1022 | 1027 | |
|
1023 | 1028 | def getSubplots(self): |
|
1024 | 1029 | |
|
1025 | 1030 | ncol = 1 |
|
1026 | 1031 | nrow = self.nplots |
|
1027 | 1032 | |
|
1028 | 1033 | return nrow, ncol |
|
1029 | 1034 | |
|
1030 | 1035 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1031 | 1036 | |
|
1032 | 1037 | self.__showprofile = showprofile |
|
1033 | 1038 | self.nplots = nplots |
|
1034 | 1039 | |
|
1035 | 1040 | ncolspan = 1 |
|
1036 | 1041 | colspan = 1 |
|
1037 | 1042 | |
|
1038 | 1043 | self.createFigure(id = id, |
|
1039 | 1044 | wintitle = wintitle, |
|
1040 | 1045 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1041 | 1046 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1042 | 1047 | show=show) |
|
1043 | 1048 | |
|
1044 | 1049 | nrow, ncol = self.getSubplots() |
|
1045 | 1050 | |
|
1046 | 1051 | counter = 0 |
|
1047 | 1052 | for y in range(nrow): |
|
1048 | 1053 | for x in range(ncol): |
|
1049 | 1054 | |
|
1050 | 1055 | if counter >= self.nplots: |
|
1051 | 1056 | break |
|
1052 | 1057 | |
|
1053 | 1058 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1054 | 1059 | |
|
1055 | 1060 | if showprofile: |
|
1056 | 1061 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1057 | 1062 | |
|
1058 | 1063 | counter += 1 |
|
1059 | 1064 | |
|
1060 | 1065 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
1061 | 1066 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
1062 | 1067 | parameterIndex = None, onlyPositive = False, |
|
1063 | 1068 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False, |
|
1064 | 1069 | DOP = True, |
|
1065 | 1070 | zlabel = "", parameterName = "", parameterObject = "data_param", |
|
1066 | 1071 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1067 | 1072 | server=None, folder=None, username=None, password=None, |
|
1068 | 1073 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1069 | 1074 | #print inspect.getargspec(self.run).args |
|
1070 | 1075 | """ |
|
1071 | 1076 | |
|
1072 | 1077 | Input: |
|
1073 | 1078 | dataOut : |
|
1074 | 1079 | id : |
|
1075 | 1080 | wintitle : |
|
1076 | 1081 | channelList : |
|
1077 | 1082 | showProfile : |
|
1078 | 1083 | xmin : None, |
|
1079 | 1084 | xmax : None, |
|
1080 | 1085 | ymin : None, |
|
1081 | 1086 | ymax : None, |
|
1082 | 1087 | zmin : None, |
|
1083 | 1088 | zmax : None |
|
1084 | 1089 | """ |
|
1085 | 1090 | |
|
1086 | 1091 | data_param = getattr(dataOut, parameterObject) |
|
1087 | 1092 | |
|
1088 | 1093 | if channelList == None: |
|
1089 | 1094 | channelIndexList = numpy.arange(data_param.shape[0]) |
|
1090 | 1095 | else: |
|
1091 | 1096 | channelIndexList = numpy.array(channelList) |
|
1092 | 1097 | |
|
1093 | 1098 | nchan = len(channelIndexList) #Number of channels being plotted |
|
1094 | 1099 | |
|
1095 | 1100 | if nchan < 1: |
|
1096 | 1101 | return |
|
1097 | 1102 | |
|
1098 | 1103 | nGraphsByChannel = 0 |
|
1099 | 1104 | |
|
1100 | 1105 | if SNR: |
|
1101 | 1106 | nGraphsByChannel += 1 |
|
1102 | 1107 | if DOP: |
|
1103 | 1108 | nGraphsByChannel += 1 |
|
1104 | 1109 | |
|
1105 | 1110 | if nGraphsByChannel < 1: |
|
1106 | 1111 | return |
|
1107 | 1112 | |
|
1108 | 1113 | nplots = nGraphsByChannel*nchan |
|
1109 | 1114 | |
|
1110 | 1115 | if timerange is not None: |
|
1111 | 1116 | self.timerange = timerange |
|
1112 | 1117 | |
|
1113 | 1118 | #tmin = None |
|
1114 | 1119 | #tmax = None |
|
1115 | 1120 | if parameterIndex == None: |
|
1116 | 1121 | parameterIndex = 1 |
|
1117 | 1122 | |
|
1118 | 1123 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
1119 | 1124 | y = dataOut.heightList |
|
1120 | 1125 | z = data_param[channelIndexList,parameterIndex,:].copy() |
|
1121 | 1126 | |
|
1122 | 1127 | zRange = dataOut.abscissaList |
|
1123 | 1128 | # nChannels = z.shape[0] #Number of wind dimensions estimated |
|
1124 | 1129 | # thisDatetime = dataOut.datatime |
|
1125 | 1130 | |
|
1126 | 1131 | if dataOut.data_SNR is not None: |
|
1127 | 1132 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
1128 | 1133 | SNRdB = 10*numpy.log10(SNRarray) |
|
1129 | 1134 | # SNRavgdB = 10*numpy.log10(SNRavg) |
|
1130 | 1135 | ind = numpy.where(SNRdB < 10**(SNRthresh/10)) |
|
1131 | 1136 | z[ind] = numpy.nan |
|
1132 | 1137 | |
|
1133 | 1138 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1134 | 1139 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1135 | 1140 | xlabel = "" |
|
1136 | 1141 | ylabel = "Range (Km)" |
|
1137 | 1142 | |
|
1138 | 1143 | if (SNR and not onlySNR): nplots = 2*nplots |
|
1139 | 1144 | |
|
1140 | 1145 | if onlyPositive: |
|
1141 | 1146 | colormap = "jet" |
|
1142 | 1147 | zmin = 0 |
|
1143 | 1148 | else: colormap = "RdBu_r" |
|
1144 | 1149 | |
|
1145 | 1150 | if not self.isConfig: |
|
1146 | 1151 | |
|
1147 | 1152 | self.setup(id=id, |
|
1148 | 1153 | nplots=nplots, |
|
1149 | 1154 | wintitle=wintitle, |
|
1150 | 1155 | showprofile=showprofile, |
|
1151 | 1156 | show=show) |
|
1152 | 1157 | |
|
1153 | 1158 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1154 | 1159 | |
|
1155 | 1160 | if ymin == None: ymin = numpy.nanmin(y) |
|
1156 | 1161 | if ymax == None: ymax = numpy.nanmax(y) |
|
1157 | 1162 | if zmin == None: zmin = numpy.nanmin(zRange) |
|
1158 | 1163 | if zmax == None: zmax = numpy.nanmax(zRange) |
|
1159 | 1164 | |
|
1160 | 1165 | if SNR: |
|
1161 | 1166 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
1162 | 1167 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
1163 | 1168 | |
|
1164 | 1169 | self.FTP_WEI = ftp_wei |
|
1165 | 1170 | self.EXP_CODE = exp_code |
|
1166 | 1171 | self.SUB_EXP_CODE = sub_exp_code |
|
1167 | 1172 | self.PLOT_POS = plot_pos |
|
1168 | 1173 | |
|
1169 | 1174 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1170 | 1175 | self.isConfig = True |
|
1171 | 1176 | self.figfile = figfile |
|
1172 | 1177 | |
|
1173 | 1178 | self.setWinTitle(title) |
|
1174 | 1179 | |
|
1175 | 1180 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1176 | 1181 | x[1] = self.xmax |
|
1177 | 1182 | |
|
1178 | 1183 | for i in range(nchan): |
|
1179 | 1184 | |
|
1180 | 1185 | if (SNR and not onlySNR): j = 2*i |
|
1181 | 1186 | else: j = i |
|
1182 | 1187 | |
|
1183 | 1188 | j = nGraphsByChannel*i |
|
1184 | 1189 | |
|
1185 | 1190 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1186 | 1191 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
1187 | 1192 | |
|
1188 | 1193 | if not onlySNR: |
|
1189 | 1194 | axes = self.axesList[j*self.__nsubplots] |
|
1190 | 1195 | z1 = z[i,:].reshape((1,-1)) |
|
1191 | 1196 | axes.pcolorbuffer(x, y, z1, |
|
1192 | 1197 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1193 | 1198 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
1194 | 1199 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1195 | 1200 | |
|
1196 | 1201 | if DOP: |
|
1197 | 1202 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1198 | 1203 | |
|
1199 | 1204 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1200 | 1205 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
1201 | 1206 | axes = self.axesList[j] |
|
1202 | 1207 | z1 = z[i,:].reshape((1,-1)) |
|
1203 | 1208 | axes.pcolorbuffer(x, y, z1, |
|
1204 | 1209 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1205 | 1210 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
1206 | 1211 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1207 | 1212 | |
|
1208 | 1213 | if SNR: |
|
1209 | 1214 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1210 | 1215 | axes = self.axesList[(j)*self.__nsubplots] |
|
1211 | 1216 | if not onlySNR: |
|
1212 | 1217 | axes = self.axesList[(j + 1)*self.__nsubplots] |
|
1213 | 1218 | |
|
1214 | 1219 | axes = self.axesList[(j + nGraphsByChannel-1)] |
|
1215 | 1220 | |
|
1216 | 1221 | z1 = SNRdB[i,:].reshape((1,-1)) |
|
1217 | 1222 | axes.pcolorbuffer(x, y, z1, |
|
1218 | 1223 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1219 | 1224 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", |
|
1220 | 1225 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1221 | 1226 | |
|
1222 | 1227 | |
|
1223 | 1228 | |
|
1224 | 1229 | self.draw() |
|
1225 | 1230 | |
|
1226 | 1231 | if x[1] >= self.axesList[0].xmax: |
|
1227 | 1232 | self.counter_imagwr = wr_period |
|
1228 | 1233 | self.isConfig = False |
|
1229 | 1234 | self.figfile = None |
|
1230 | 1235 | |
|
1231 | 1236 | self.save(figpath=figpath, |
|
1232 | 1237 | figfile=figfile, |
|
1233 | 1238 | save=save, |
|
1234 | 1239 | ftp=ftp, |
|
1235 | 1240 | wr_period=wr_period, |
|
1236 | 1241 | thisDatetime=thisDatetime, |
|
1237 | 1242 | update_figfile=False) |
|
1238 | 1243 | |
|
1239 | 1244 | class SpectralFittingPlot(Figure): |
|
1240 | 1245 | |
|
1241 | 1246 | __isConfig = None |
|
1242 | 1247 | __nsubplots = None |
|
1243 | 1248 | |
|
1244 | 1249 | WIDTHPROF = None |
|
1245 | 1250 | HEIGHTPROF = None |
|
1246 | 1251 | PREFIX = 'prm' |
|
1247 | 1252 | |
|
1248 | 1253 | |
|
1249 | 1254 | N = None |
|
1250 | 1255 | ippSeconds = None |
|
1251 | 1256 | |
|
1252 | 1257 | def __init__(self, **kwargs): |
|
1253 | 1258 | Figure.__init__(self, **kwargs) |
|
1254 | 1259 | self.isConfig = False |
|
1255 | 1260 | self.__nsubplots = 1 |
|
1256 | 1261 | |
|
1257 | 1262 | self.PLOT_CODE = SPECFIT_CODE |
|
1258 | 1263 | |
|
1259 | 1264 | self.WIDTH = 450 |
|
1260 | 1265 | self.HEIGHT = 250 |
|
1261 | 1266 | self.WIDTHPROF = 0 |
|
1262 | 1267 | self.HEIGHTPROF = 0 |
|
1263 | 1268 | |
|
1264 | 1269 | def getSubplots(self): |
|
1265 | 1270 | |
|
1266 | 1271 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1267 | 1272 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1268 | 1273 | |
|
1269 | 1274 | return nrow, ncol |
|
1270 | 1275 | |
|
1271 | 1276 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
1272 | 1277 | |
|
1273 | 1278 | showprofile = False |
|
1274 | 1279 | self.__showprofile = showprofile |
|
1275 | 1280 | self.nplots = nplots |
|
1276 | 1281 | |
|
1277 | 1282 | ncolspan = 5 |
|
1278 | 1283 | colspan = 4 |
|
1279 | 1284 | if showprofile: |
|
1280 | 1285 | ncolspan = 5 |
|
1281 | 1286 | colspan = 4 |
|
1282 | 1287 | self.__nsubplots = 2 |
|
1283 | 1288 | |
|
1284 | 1289 | self.createFigure(id = id, |
|
1285 | 1290 | wintitle = wintitle, |
|
1286 | 1291 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1287 | 1292 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1288 | 1293 | show=show) |
|
1289 | 1294 | |
|
1290 | 1295 | nrow, ncol = self.getSubplots() |
|
1291 | 1296 | |
|
1292 | 1297 | counter = 0 |
|
1293 | 1298 | for y in range(nrow): |
|
1294 | 1299 | for x in range(ncol): |
|
1295 | 1300 | |
|
1296 | 1301 | if counter >= self.nplots: |
|
1297 | 1302 | break |
|
1298 | 1303 | |
|
1299 | 1304 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1300 | 1305 | |
|
1301 | 1306 | if showprofile: |
|
1302 | 1307 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1303 | 1308 | |
|
1304 | 1309 | counter += 1 |
|
1305 | 1310 | |
|
1306 | 1311 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, |
|
1307 | 1312 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1308 | 1313 | save=False, figpath='./', figfile=None, show=True): |
|
1309 | 1314 | |
|
1310 | 1315 | """ |
|
1311 | 1316 | |
|
1312 | 1317 | Input: |
|
1313 | 1318 | dataOut : |
|
1314 | 1319 | id : |
|
1315 | 1320 | wintitle : |
|
1316 | 1321 | channelList : |
|
1317 | 1322 | showProfile : |
|
1318 | 1323 | xmin : None, |
|
1319 | 1324 | xmax : None, |
|
1320 | 1325 | zmin : None, |
|
1321 | 1326 | zmax : None |
|
1322 | 1327 | """ |
|
1323 | 1328 | |
|
1324 | 1329 | if cutHeight==None: |
|
1325 | 1330 | h=270 |
|
1326 | 1331 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() |
|
1327 | 1332 | cutHeight = dataOut.heightList[heightindex] |
|
1328 | 1333 | |
|
1329 | 1334 | factor = dataOut.normFactor |
|
1330 | 1335 | x = dataOut.abscissaList[:-1] |
|
1331 | 1336 | #y = dataOut.getHeiRange() |
|
1332 | 1337 | |
|
1333 | 1338 | z = dataOut.data_pre[:,:,heightindex]/factor |
|
1334 | 1339 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1335 | 1340 | avg = numpy.average(z, axis=1) |
|
1336 | 1341 | listChannels = z.shape[0] |
|
1337 | 1342 | |
|
1338 | 1343 | #Reconstruct Function |
|
1339 | 1344 | if fit==True: |
|
1340 | 1345 | groupArray = dataOut.groupList |
|
1341 | 1346 | listChannels = groupArray.reshape((groupArray.size)) |
|
1342 | 1347 | listChannels.sort() |
|
1343 | 1348 | spcFitLine = numpy.zeros(z.shape) |
|
1344 | 1349 | constants = dataOut.constants |
|
1345 | 1350 | |
|
1346 | 1351 | nGroups = groupArray.shape[0] |
|
1347 | 1352 | nChannels = groupArray.shape[1] |
|
1348 | 1353 | nProfiles = z.shape[1] |
|
1349 | 1354 | |
|
1350 | 1355 | for f in range(nGroups): |
|
1351 | 1356 | groupChann = groupArray[f,:] |
|
1352 | 1357 | p = dataOut.data_param[f,:,heightindex] |
|
1353 | 1358 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) |
|
1354 | 1359 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles |
|
1355 | 1360 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) |
|
1356 | 1361 | spcFitLine[groupChann,:] = fitLineAux |
|
1357 | 1362 | # spcFitLine = spcFitLine/factor |
|
1358 | 1363 | |
|
1359 | 1364 | z = z[listChannels,:] |
|
1360 | 1365 | spcFitLine = spcFitLine[listChannels,:] |
|
1361 | 1366 | spcFitLinedB = 10*numpy.log10(spcFitLine) |
|
1362 | 1367 | |
|
1363 | 1368 | zdB = 10*numpy.log10(z) |
|
1364 | 1369 | #thisDatetime = dataOut.datatime |
|
1365 | 1370 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1366 | 1371 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1367 | 1372 | xlabel = "Velocity (m/s)" |
|
1368 | 1373 | ylabel = "Spectrum" |
|
1369 | 1374 | |
|
1370 | 1375 | if not self.isConfig: |
|
1371 | 1376 | |
|
1372 | 1377 | nplots = listChannels.size |
|
1373 | 1378 | |
|
1374 | 1379 | self.setup(id=id, |
|
1375 | 1380 | nplots=nplots, |
|
1376 | 1381 | wintitle=wintitle, |
|
1377 | 1382 | showprofile=showprofile, |
|
1378 | 1383 | show=show) |
|
1379 | 1384 | |
|
1380 | 1385 | if xmin == None: xmin = numpy.nanmin(x) |
|
1381 | 1386 | if xmax == None: xmax = numpy.nanmax(x) |
|
1382 | 1387 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1383 | 1388 | if ymax == None: ymax = numpy.nanmax(zdB)+2 |
|
1384 | 1389 | |
|
1385 | 1390 | self.isConfig = True |
|
1386 | 1391 | |
|
1387 | 1392 | self.setWinTitle(title) |
|
1388 | 1393 | for i in range(self.nplots): |
|
1389 | 1394 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
1390 | 1395 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]) |
|
1391 | 1396 | axes = self.axesList[i*self.__nsubplots] |
|
1392 | 1397 | if fit == False: |
|
1393 | 1398 | axes.pline(x, zdB[i,:], |
|
1394 | 1399 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1395 | 1400 | xlabel=xlabel, ylabel=ylabel, title=title |
|
1396 | 1401 | ) |
|
1397 | 1402 | if fit == True: |
|
1398 | 1403 | fitline=spcFitLinedB[i,:] |
|
1399 | 1404 | y=numpy.vstack([zdB[i,:],fitline] ) |
|
1400 | 1405 | legendlabels=['Data','Fitting'] |
|
1401 | 1406 | axes.pmultilineyaxis(x, y, |
|
1402 | 1407 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1403 | 1408 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
1404 | 1409 | legendlabels=legendlabels, marker=None, |
|
1405 | 1410 | linestyle='solid', grid='both') |
|
1406 | 1411 | |
|
1407 | 1412 | self.draw() |
|
1408 | 1413 | |
|
1409 | 1414 | self.save(figpath=figpath, |
|
1410 | 1415 | figfile=figfile, |
|
1411 | 1416 | save=save, |
|
1412 | 1417 | ftp=ftp, |
|
1413 | 1418 | wr_period=wr_period, |
|
1414 | 1419 | thisDatetime=thisDatetime) |
|
1415 | 1420 | |
|
1416 | 1421 | |
|
1417 | 1422 | class EWDriftsPlot(Figure): |
|
1418 | 1423 | |
|
1419 | 1424 | __isConfig = None |
|
1420 | 1425 | __nsubplots = None |
|
1421 | 1426 | |
|
1422 | 1427 | WIDTHPROF = None |
|
1423 | 1428 | HEIGHTPROF = None |
|
1424 | 1429 | PREFIX = 'drift' |
|
1425 | 1430 | |
|
1426 | 1431 | def __init__(self, **kwargs): |
|
1427 | 1432 | Figure.__init__(self, **kwargs) |
|
1428 | 1433 | self.timerange = 2*60*60 |
|
1429 | 1434 | self.isConfig = False |
|
1430 | 1435 | self.__nsubplots = 1 |
|
1431 | 1436 | |
|
1432 | 1437 | self.WIDTH = 800 |
|
1433 | 1438 | self.HEIGHT = 150 |
|
1434 | 1439 | self.WIDTHPROF = 120 |
|
1435 | 1440 | self.HEIGHTPROF = 0 |
|
1436 | 1441 | self.counter_imagwr = 0 |
|
1437 | 1442 | |
|
1438 | 1443 | self.PLOT_CODE = EWDRIFT_CODE |
|
1439 | 1444 | |
|
1440 | 1445 | self.FTP_WEI = None |
|
1441 | 1446 | self.EXP_CODE = None |
|
1442 | 1447 | self.SUB_EXP_CODE = None |
|
1443 | 1448 | self.PLOT_POS = None |
|
1444 | 1449 | self.tmin = None |
|
1445 | 1450 | self.tmax = None |
|
1446 | 1451 | |
|
1447 | 1452 | self.xmin = None |
|
1448 | 1453 | self.xmax = None |
|
1449 | 1454 | |
|
1450 | 1455 | self.figfile = None |
|
1451 | 1456 | |
|
1452 | 1457 | def getSubplots(self): |
|
1453 | 1458 | |
|
1454 | 1459 | ncol = 1 |
|
1455 | 1460 | nrow = self.nplots |
|
1456 | 1461 | |
|
1457 | 1462 | return nrow, ncol |
|
1458 | 1463 | |
|
1459 | 1464 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1460 | 1465 | |
|
1461 | 1466 | self.__showprofile = showprofile |
|
1462 | 1467 | self.nplots = nplots |
|
1463 | 1468 | |
|
1464 | 1469 | ncolspan = 1 |
|
1465 | 1470 | colspan = 1 |
|
1466 | 1471 | |
|
1467 | 1472 | self.createFigure(id = id, |
|
1468 | 1473 | wintitle = wintitle, |
|
1469 | 1474 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1470 | 1475 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1471 | 1476 | show=show) |
|
1472 | 1477 | |
|
1473 | 1478 | nrow, ncol = self.getSubplots() |
|
1474 | 1479 | |
|
1475 | 1480 | counter = 0 |
|
1476 | 1481 | for y in range(nrow): |
|
1477 | 1482 | if counter >= self.nplots: |
|
1478 | 1483 | break |
|
1479 | 1484 | |
|
1480 | 1485 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
1481 | 1486 | counter += 1 |
|
1482 | 1487 | |
|
1483 | 1488 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1484 | 1489 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1485 | 1490 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, |
|
1486 | 1491 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, |
|
1487 | 1492 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1488 | 1493 | server=None, folder=None, username=None, password=None, |
|
1489 | 1494 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1490 | 1495 | """ |
|
1491 | 1496 | |
|
1492 | 1497 | Input: |
|
1493 | 1498 | dataOut : |
|
1494 | 1499 | id : |
|
1495 | 1500 | wintitle : |
|
1496 | 1501 | channelList : |
|
1497 | 1502 | showProfile : |
|
1498 | 1503 | xmin : None, |
|
1499 | 1504 | xmax : None, |
|
1500 | 1505 | ymin : None, |
|
1501 | 1506 | ymax : None, |
|
1502 | 1507 | zmin : None, |
|
1503 | 1508 | zmax : None |
|
1504 | 1509 | """ |
|
1505 | 1510 | |
|
1506 | 1511 | if timerange is not None: |
|
1507 | 1512 | self.timerange = timerange |
|
1508 | 1513 | |
|
1509 | 1514 | tmin = None |
|
1510 | 1515 | tmax = None |
|
1511 | 1516 | |
|
1512 | 1517 | x = dataOut.getTimeRange1(dataOut.outputInterval) |
|
1513 | 1518 | # y = dataOut.heightList |
|
1514 | 1519 | y = dataOut.heightList |
|
1515 | 1520 | |
|
1516 | 1521 | z = dataOut.data_output |
|
1517 | 1522 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
1518 | 1523 | nplotsw = nplots |
|
1519 | 1524 | |
|
1520 | 1525 | #If there is a SNR function defined |
|
1521 | 1526 | if dataOut.data_SNR is not None: |
|
1522 | 1527 | nplots += 1 |
|
1523 | 1528 | SNR = dataOut.data_SNR |
|
1524 | 1529 | |
|
1525 | 1530 | if SNR_1: |
|
1526 | 1531 | SNR += 1 |
|
1527 | 1532 | |
|
1528 | 1533 | SNRavg = numpy.average(SNR, axis=0) |
|
1529 | 1534 | |
|
1530 | 1535 | SNRdB = 10*numpy.log10(SNR) |
|
1531 | 1536 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
1532 | 1537 | |
|
1533 | 1538 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
1534 | 1539 | |
|
1535 | 1540 | for i in range(nplotsw): |
|
1536 | 1541 | z[i,ind] = numpy.nan |
|
1537 | 1542 | |
|
1538 | 1543 | |
|
1539 | 1544 | showprofile = False |
|
1540 | 1545 | # thisDatetime = dataOut.datatime |
|
1541 | 1546 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) |
|
1542 | 1547 | title = wintitle + " EW Drifts" |
|
1543 | 1548 | xlabel = "" |
|
1544 | 1549 | ylabel = "Height (Km)" |
|
1545 | 1550 | |
|
1546 | 1551 | if not self.isConfig: |
|
1547 | 1552 | |
|
1548 | 1553 | self.setup(id=id, |
|
1549 | 1554 | nplots=nplots, |
|
1550 | 1555 | wintitle=wintitle, |
|
1551 | 1556 | showprofile=showprofile, |
|
1552 | 1557 | show=show) |
|
1553 | 1558 | |
|
1554 | 1559 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1555 | 1560 | |
|
1556 | 1561 | if ymin == None: ymin = numpy.nanmin(y) |
|
1557 | 1562 | if ymax == None: ymax = numpy.nanmax(y) |
|
1558 | 1563 | |
|
1559 | 1564 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) |
|
1560 | 1565 | if zminZonal == None: zminZonal = -zmaxZonal |
|
1561 | 1566 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) |
|
1562 | 1567 | if zminVertical == None: zminVertical = -zmaxVertical |
|
1563 | 1568 | |
|
1564 | 1569 | if dataOut.data_SNR is not None: |
|
1565 | 1570 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
1566 | 1571 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
1567 | 1572 | |
|
1568 | 1573 | self.FTP_WEI = ftp_wei |
|
1569 | 1574 | self.EXP_CODE = exp_code |
|
1570 | 1575 | self.SUB_EXP_CODE = sub_exp_code |
|
1571 | 1576 | self.PLOT_POS = plot_pos |
|
1572 | 1577 | |
|
1573 | 1578 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1574 | 1579 | self.isConfig = True |
|
1575 | 1580 | |
|
1576 | 1581 | |
|
1577 | 1582 | self.setWinTitle(title) |
|
1578 | 1583 | |
|
1579 | 1584 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1580 | 1585 | x[1] = self.xmax |
|
1581 | 1586 | |
|
1582 | 1587 | strWind = ['Zonal','Vertical'] |
|
1583 | 1588 | strCb = 'Velocity (m/s)' |
|
1584 | 1589 | zmaxVector = [zmaxZonal, zmaxVertical] |
|
1585 | 1590 | zminVector = [zminZonal, zminVertical] |
|
1586 | 1591 | |
|
1587 | 1592 | for i in range(nplotsw): |
|
1588 | 1593 | |
|
1589 | 1594 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1590 | 1595 | axes = self.axesList[i*self.__nsubplots] |
|
1591 | 1596 | |
|
1592 | 1597 | z1 = z[i,:].reshape((1,-1)) |
|
1593 | 1598 | |
|
1594 | 1599 | axes.pcolorbuffer(x, y, z1, |
|
1595 | 1600 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
1596 | 1601 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1597 | 1602 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") |
|
1598 | 1603 | |
|
1599 | 1604 | if dataOut.data_SNR is not None: |
|
1600 | 1605 | i += 1 |
|
1601 | 1606 | if SNR_1: |
|
1602 | 1607 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1603 | 1608 | else: |
|
1604 | 1609 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1605 | 1610 | axes = self.axesList[i*self.__nsubplots] |
|
1606 | 1611 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
1607 | 1612 | |
|
1608 | 1613 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
1609 | 1614 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1610 | 1615 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1611 | 1616 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
1612 | 1617 | |
|
1613 | 1618 | self.draw() |
|
1614 | 1619 | |
|
1615 | 1620 | if x[1] >= self.axesList[0].xmax: |
|
1616 | 1621 | self.counter_imagwr = wr_period |
|
1617 | 1622 | self.isConfig = False |
|
1618 | 1623 | self.figfile = None |
|
1619 | 1624 | |
|
1620 | 1625 | |
|
1621 | 1626 | |
|
1622 | 1627 | |
|
1623 | 1628 | class PhasePlot(Figure): |
|
1624 | 1629 | |
|
1625 | 1630 | __isConfig = None |
|
1626 | 1631 | __nsubplots = None |
|
1627 | 1632 | |
|
1628 | 1633 | PREFIX = 'mphase' |
|
1629 | 1634 | |
|
1630 | 1635 | def __init__(self, **kwargs): |
|
1631 | 1636 | Figure.__init__(self, **kwargs) |
|
1632 | 1637 | self.timerange = 24*60*60 |
|
1633 | 1638 | self.isConfig = False |
|
1634 | 1639 | self.__nsubplots = 1 |
|
1635 | 1640 | self.counter_imagwr = 0 |
|
1636 | 1641 | self.WIDTH = 600 |
|
1637 | 1642 | self.HEIGHT = 300 |
|
1638 | 1643 | self.WIDTHPROF = 120 |
|
1639 | 1644 | self.HEIGHTPROF = 0 |
|
1640 | 1645 | self.xdata = None |
|
1641 | 1646 | self.ydata = None |
|
1642 | 1647 | |
|
1643 | 1648 | self.PLOT_CODE = MPHASE_CODE |
|
1644 | 1649 | |
|
1645 | 1650 | self.FTP_WEI = None |
|
1646 | 1651 | self.EXP_CODE = None |
|
1647 | 1652 | self.SUB_EXP_CODE = None |
|
1648 | 1653 | self.PLOT_POS = None |
|
1649 | 1654 | |
|
1650 | 1655 | |
|
1651 | 1656 | self.filename_phase = None |
|
1652 | 1657 | |
|
1653 | 1658 | self.figfile = None |
|
1654 | 1659 | |
|
1655 | 1660 | def getSubplots(self): |
|
1656 | 1661 | |
|
1657 | 1662 | ncol = 1 |
|
1658 | 1663 | nrow = 1 |
|
1659 | 1664 | |
|
1660 | 1665 | return nrow, ncol |
|
1661 | 1666 | |
|
1662 | 1667 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1663 | 1668 | |
|
1664 | 1669 | self.__showprofile = showprofile |
|
1665 | 1670 | self.nplots = nplots |
|
1666 | 1671 | |
|
1667 | 1672 | ncolspan = 7 |
|
1668 | 1673 | colspan = 6 |
|
1669 | 1674 | self.__nsubplots = 2 |
|
1670 | 1675 | |
|
1671 | 1676 | self.createFigure(id = id, |
|
1672 | 1677 | wintitle = wintitle, |
|
1673 | 1678 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1674 | 1679 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1675 | 1680 | show=show) |
|
1676 | 1681 | |
|
1677 | 1682 | nrow, ncol = self.getSubplots() |
|
1678 | 1683 | |
|
1679 | 1684 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1680 | 1685 | |
|
1681 | 1686 | |
|
1682 | 1687 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1683 | 1688 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1684 | 1689 | timerange=None, |
|
1685 | 1690 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1686 | 1691 | server=None, folder=None, username=None, password=None, |
|
1687 | 1692 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1688 | 1693 | |
|
1689 | 1694 | |
|
1690 | 1695 | tmin = None |
|
1691 | 1696 | tmax = None |
|
1692 | 1697 | x = dataOut.getTimeRange1(dataOut.outputInterval) |
|
1693 | 1698 | y = dataOut.getHeiRange() |
|
1694 | 1699 | |
|
1695 | 1700 | |
|
1696 | 1701 | #thisDatetime = dataOut.datatime |
|
1697 | 1702 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
1698 | 1703 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1699 | 1704 | xlabel = "Local Time" |
|
1700 | 1705 | ylabel = "Phase" |
|
1701 | 1706 | |
|
1702 | 1707 | |
|
1703 | 1708 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1704 | 1709 | phase_beacon = dataOut.data_output |
|
1705 | 1710 | update_figfile = False |
|
1706 | 1711 | |
|
1707 | 1712 | if not self.isConfig: |
|
1708 | 1713 | |
|
1709 | 1714 | self.nplots = phase_beacon.size |
|
1710 | 1715 | |
|
1711 | 1716 | self.setup(id=id, |
|
1712 | 1717 | nplots=self.nplots, |
|
1713 | 1718 | wintitle=wintitle, |
|
1714 | 1719 | showprofile=showprofile, |
|
1715 | 1720 | show=show) |
|
1716 | 1721 | |
|
1717 | 1722 | if timerange is not None: |
|
1718 | 1723 | self.timerange = timerange |
|
1719 | 1724 | |
|
1720 | 1725 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1721 | 1726 | |
|
1722 | 1727 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1723 | 1728 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1724 | 1729 | |
|
1725 | 1730 | self.FTP_WEI = ftp_wei |
|
1726 | 1731 | self.EXP_CODE = exp_code |
|
1727 | 1732 | self.SUB_EXP_CODE = sub_exp_code |
|
1728 | 1733 | self.PLOT_POS = plot_pos |
|
1729 | 1734 | |
|
1730 | 1735 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1731 | 1736 | self.isConfig = True |
|
1732 | 1737 | self.figfile = figfile |
|
1733 | 1738 | self.xdata = numpy.array([]) |
|
1734 | 1739 | self.ydata = numpy.array([]) |
|
1735 | 1740 | |
|
1736 | 1741 | #open file beacon phase |
|
1737 | 1742 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1738 | 1743 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1739 | 1744 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1740 | 1745 | update_figfile = True |
|
1741 | 1746 | |
|
1742 | 1747 | |
|
1743 | 1748 | #store data beacon phase |
|
1744 | 1749 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1745 | 1750 | |
|
1746 | 1751 | self.setWinTitle(title) |
|
1747 | 1752 | |
|
1748 | 1753 | |
|
1749 | 1754 | title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1750 | 1755 | |
|
1751 | 1756 | legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)] |
|
1752 | 1757 | |
|
1753 | 1758 | axes = self.axesList[0] |
|
1754 | 1759 | |
|
1755 | 1760 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1756 | 1761 | |
|
1757 | 1762 | if len(self.ydata)==0: |
|
1758 | 1763 | self.ydata = phase_beacon.reshape(-1,1) |
|
1759 | 1764 | else: |
|
1760 | 1765 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1761 | 1766 | |
|
1762 | 1767 | |
|
1763 | 1768 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1764 | 1769 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1765 | 1770 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1766 | 1771 | XAxisAsTime=True, grid='both' |
|
1767 | 1772 | ) |
|
1768 | 1773 | |
|
1769 | 1774 | self.draw() |
|
1770 | 1775 | |
|
1771 | 1776 | self.save(figpath=figpath, |
|
1772 | 1777 | figfile=figfile, |
|
1773 | 1778 | save=save, |
|
1774 | 1779 | ftp=ftp, |
|
1775 | 1780 | wr_period=wr_period, |
|
1776 | 1781 | thisDatetime=thisDatetime, |
|
1777 | 1782 | update_figfile=update_figfile) |
|
1778 | 1783 | |
|
1779 | 1784 | if dataOut.ltctime + dataOut.outputInterval >= self.xmax: |
|
1780 | 1785 | self.counter_imagwr = wr_period |
|
1781 | 1786 | self.isConfig = False |
|
1782 | 1787 | update_figfile = True |
|
1783 | 1788 | |
|
1784 | 1789 | |
|
1785 | 1790 | |
|
1786 | 1791 | class NSMeteorDetection1Plot(Figure): |
|
1787 | 1792 | |
|
1788 | 1793 | isConfig = None |
|
1789 | 1794 | __nsubplots = None |
|
1790 | 1795 | |
|
1791 | 1796 | WIDTHPROF = None |
|
1792 | 1797 | HEIGHTPROF = None |
|
1793 | 1798 | PREFIX = 'nsm' |
|
1794 | 1799 | |
|
1795 | 1800 | zminList = None |
|
1796 | 1801 | zmaxList = None |
|
1797 | 1802 | cmapList = None |
|
1798 | 1803 | titleList = None |
|
1799 | 1804 | nPairs = None |
|
1800 | 1805 | nChannels = None |
|
1801 | 1806 | nParam = None |
|
1802 | 1807 | |
|
1803 | 1808 | def __init__(self, **kwargs): |
|
1804 | 1809 | Figure.__init__(self, **kwargs) |
|
1805 | 1810 | self.isConfig = False |
|
1806 | 1811 | self.__nsubplots = 1 |
|
1807 | 1812 | |
|
1808 | 1813 | self.WIDTH = 750 |
|
1809 | 1814 | self.HEIGHT = 250 |
|
1810 | 1815 | self.WIDTHPROF = 120 |
|
1811 | 1816 | self.HEIGHTPROF = 0 |
|
1812 | 1817 | self.counter_imagwr = 0 |
|
1813 | 1818 | |
|
1814 | 1819 | self.PLOT_CODE = SPEC_CODE |
|
1815 | 1820 | |
|
1816 | 1821 | self.FTP_WEI = None |
|
1817 | 1822 | self.EXP_CODE = None |
|
1818 | 1823 | self.SUB_EXP_CODE = None |
|
1819 | 1824 | self.PLOT_POS = None |
|
1820 | 1825 | |
|
1821 | 1826 | self.__xfilter_ena = False |
|
1822 | 1827 | self.__yfilter_ena = False |
|
1823 | 1828 | |
|
1824 | 1829 | def getSubplots(self): |
|
1825 | 1830 | |
|
1826 | 1831 | ncol = 3 |
|
1827 | 1832 | nrow = int(numpy.ceil(self.nplots/3.0)) |
|
1828 | 1833 | |
|
1829 | 1834 | return nrow, ncol |
|
1830 | 1835 | |
|
1831 | 1836 | def setup(self, id, nplots, wintitle, show=True): |
|
1832 | 1837 | |
|
1833 | 1838 | self.nplots = nplots |
|
1834 | 1839 | |
|
1835 | 1840 | ncolspan = 1 |
|
1836 | 1841 | colspan = 1 |
|
1837 | 1842 | |
|
1838 | 1843 | self.createFigure(id = id, |
|
1839 | 1844 | wintitle = wintitle, |
|
1840 | 1845 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1841 | 1846 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1842 | 1847 | show=show) |
|
1843 | 1848 | |
|
1844 | 1849 | nrow, ncol = self.getSubplots() |
|
1845 | 1850 | |
|
1846 | 1851 | counter = 0 |
|
1847 | 1852 | for y in range(nrow): |
|
1848 | 1853 | for x in range(ncol): |
|
1849 | 1854 | |
|
1850 | 1855 | if counter >= self.nplots: |
|
1851 | 1856 | break |
|
1852 | 1857 | |
|
1853 | 1858 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1854 | 1859 | |
|
1855 | 1860 | counter += 1 |
|
1856 | 1861 | |
|
1857 | 1862 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
1858 | 1863 | xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None, |
|
1859 | 1864 | vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA', |
|
1860 | 1865 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1861 | 1866 | server=None, folder=None, username=None, password=None, |
|
1862 | 1867 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
1863 | 1868 | xaxis="frequency"): |
|
1864 | 1869 | |
|
1865 | 1870 | """ |
|
1866 | 1871 | |
|
1867 | 1872 | Input: |
|
1868 | 1873 | dataOut : |
|
1869 | 1874 | id : |
|
1870 | 1875 | wintitle : |
|
1871 | 1876 | channelList : |
|
1872 | 1877 | showProfile : |
|
1873 | 1878 | xmin : None, |
|
1874 | 1879 | xmax : None, |
|
1875 | 1880 | ymin : None, |
|
1876 | 1881 | ymax : None, |
|
1877 | 1882 | zmin : None, |
|
1878 | 1883 | zmax : None |
|
1879 | 1884 | """ |
|
1880 | 1885 | #SEPARAR EN DOS PLOTS |
|
1881 | 1886 | nParam = dataOut.data_param.shape[1] - 3 |
|
1882 | 1887 | |
|
1883 | 1888 | utctime = dataOut.data_param[0,0] |
|
1884 | 1889 | tmet = dataOut.data_param[:,1].astype(int) |
|
1885 | 1890 | hmet = dataOut.data_param[:,2].astype(int) |
|
1886 | 1891 | |
|
1887 | 1892 | x = dataOut.abscissaList |
|
1888 | 1893 | y = dataOut.heightList |
|
1889 | 1894 | |
|
1890 | 1895 | z = numpy.zeros((nParam, y.size, x.size - 1)) |
|
1891 | 1896 | z[:,:] = numpy.nan |
|
1892 | 1897 | z[:,hmet,tmet] = dataOut.data_param[:,3:].T |
|
1893 | 1898 | z[0,:,:] = 10*numpy.log10(z[0,:,:]) |
|
1894 | 1899 | |
|
1895 | 1900 | xlabel = "Time (s)" |
|
1896 | 1901 | ylabel = "Range (km)" |
|
1897 | 1902 | |
|
1898 | 1903 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
1899 | 1904 | |
|
1900 | 1905 | if not self.isConfig: |
|
1901 | 1906 | |
|
1902 | 1907 | nplots = nParam |
|
1903 | 1908 | |
|
1904 | 1909 | self.setup(id=id, |
|
1905 | 1910 | nplots=nplots, |
|
1906 | 1911 | wintitle=wintitle, |
|
1907 | 1912 | show=show) |
|
1908 | 1913 | |
|
1909 | 1914 | if xmin is None: xmin = numpy.nanmin(x) |
|
1910 | 1915 | if xmax is None: xmax = numpy.nanmax(x) |
|
1911 | 1916 | if ymin is None: ymin = numpy.nanmin(y) |
|
1912 | 1917 | if ymax is None: ymax = numpy.nanmax(y) |
|
1913 | 1918 | if SNRmin is None: SNRmin = numpy.nanmin(z[0,:]) |
|
1914 | 1919 | if SNRmax is None: SNRmax = numpy.nanmax(z[0,:]) |
|
1915 | 1920 | if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:])) |
|
1916 | 1921 | if vmin is None: vmin = -vmax |
|
1917 | 1922 | if wmin is None: wmin = 0 |
|
1918 | 1923 | if wmax is None: wmax = 50 |
|
1919 | 1924 | |
|
1920 | 1925 | pairsList = dataOut.groupList |
|
1921 | 1926 | self.nPairs = len(dataOut.groupList) |
|
1922 | 1927 | |
|
1923 | 1928 | zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs |
|
1924 | 1929 | zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs |
|
1925 | 1930 | titleList = ["SNR","Radial Velocity","Coherence"] |
|
1926 | 1931 | cmapList = ["jet","RdBu_r","jet"] |
|
1927 | 1932 | |
|
1928 | 1933 | for i in range(self.nPairs): |
|
1929 | 1934 | strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1]) |
|
1930 | 1935 | titleList = titleList + [strAux1] |
|
1931 | 1936 | cmapList = cmapList + ["RdBu_r"] |
|
1932 | 1937 | |
|
1933 | 1938 | self.zminList = zminList |
|
1934 | 1939 | self.zmaxList = zmaxList |
|
1935 | 1940 | self.cmapList = cmapList |
|
1936 | 1941 | self.titleList = titleList |
|
1937 | 1942 | |
|
1938 | 1943 | self.FTP_WEI = ftp_wei |
|
1939 | 1944 | self.EXP_CODE = exp_code |
|
1940 | 1945 | self.SUB_EXP_CODE = sub_exp_code |
|
1941 | 1946 | self.PLOT_POS = plot_pos |
|
1942 | 1947 | |
|
1943 | 1948 | self.isConfig = True |
|
1944 | 1949 | |
|
1945 | 1950 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
1946 | 1951 | |
|
1947 | 1952 | for i in range(nParam): |
|
1948 | 1953 | title = self.titleList[i] + ": " +str_datetime |
|
1949 | 1954 | axes = self.axesList[i] |
|
1950 | 1955 | axes.pcolor(x, y, z[i,:].T, |
|
1951 | 1956 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i], |
|
1952 | 1957 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='') |
|
1953 | 1958 | self.draw() |
|
1954 | 1959 | |
|
1955 | 1960 | if figfile == None: |
|
1956 | 1961 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1957 | 1962 | name = str_datetime |
|
1958 | 1963 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1959 | 1964 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
1960 | 1965 | figfile = self.getFilename(name) |
|
1961 | 1966 | |
|
1962 | 1967 | self.save(figpath=figpath, |
|
1963 | 1968 | figfile=figfile, |
|
1964 | 1969 | save=save, |
|
1965 | 1970 | ftp=ftp, |
|
1966 | 1971 | wr_period=wr_period, |
|
1967 | 1972 | thisDatetime=thisDatetime) |
|
1968 | 1973 | |
|
1969 | 1974 | |
|
1970 | 1975 | class NSMeteorDetection2Plot(Figure): |
|
1971 | 1976 | |
|
1972 | 1977 | isConfig = None |
|
1973 | 1978 | __nsubplots = None |
|
1974 | 1979 | |
|
1975 | 1980 | WIDTHPROF = None |
|
1976 | 1981 | HEIGHTPROF = None |
|
1977 | 1982 | PREFIX = 'nsm' |
|
1978 | 1983 | |
|
1979 | 1984 | zminList = None |
|
1980 | 1985 | zmaxList = None |
|
1981 | 1986 | cmapList = None |
|
1982 | 1987 | titleList = None |
|
1983 | 1988 | nPairs = None |
|
1984 | 1989 | nChannels = None |
|
1985 | 1990 | nParam = None |
|
1986 | 1991 | |
|
1987 | 1992 | def __init__(self, **kwargs): |
|
1988 | 1993 | Figure.__init__(self, **kwargs) |
|
1989 | 1994 | self.isConfig = False |
|
1990 | 1995 | self.__nsubplots = 1 |
|
1991 | 1996 | |
|
1992 | 1997 | self.WIDTH = 750 |
|
1993 | 1998 | self.HEIGHT = 250 |
|
1994 | 1999 | self.WIDTHPROF = 120 |
|
1995 | 2000 | self.HEIGHTPROF = 0 |
|
1996 | 2001 | self.counter_imagwr = 0 |
|
1997 | 2002 | |
|
1998 | 2003 | self.PLOT_CODE = SPEC_CODE |
|
1999 | 2004 | |
|
2000 | 2005 | self.FTP_WEI = None |
|
2001 | 2006 | self.EXP_CODE = None |
|
2002 | 2007 | self.SUB_EXP_CODE = None |
|
2003 | 2008 | self.PLOT_POS = None |
|
2004 | 2009 | |
|
2005 | 2010 | self.__xfilter_ena = False |
|
2006 | 2011 | self.__yfilter_ena = False |
|
2007 | 2012 | |
|
2008 | 2013 | def getSubplots(self): |
|
2009 | 2014 | |
|
2010 | 2015 | ncol = 3 |
|
2011 | 2016 | nrow = int(numpy.ceil(self.nplots/3.0)) |
|
2012 | 2017 | |
|
2013 | 2018 | return nrow, ncol |
|
2014 | 2019 | |
|
2015 | 2020 | def setup(self, id, nplots, wintitle, show=True): |
|
2016 | 2021 | |
|
2017 | 2022 | self.nplots = nplots |
|
2018 | 2023 | |
|
2019 | 2024 | ncolspan = 1 |
|
2020 | 2025 | colspan = 1 |
|
2021 | 2026 | |
|
2022 | 2027 | self.createFigure(id = id, |
|
2023 | 2028 | wintitle = wintitle, |
|
2024 | 2029 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
2025 | 2030 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
2026 | 2031 | show=show) |
|
2027 | 2032 | |
|
2028 | 2033 | nrow, ncol = self.getSubplots() |
|
2029 | 2034 | |
|
2030 | 2035 | counter = 0 |
|
2031 | 2036 | for y in range(nrow): |
|
2032 | 2037 | for x in range(ncol): |
|
2033 | 2038 | |
|
2034 | 2039 | if counter >= self.nplots: |
|
2035 | 2040 | break |
|
2036 | 2041 | |
|
2037 | 2042 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
2038 | 2043 | |
|
2039 | 2044 | counter += 1 |
|
2040 | 2045 | |
|
2041 | 2046 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
2042 | 2047 | xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None, |
|
2043 | 2048 | vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA', |
|
2044 | 2049 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
2045 | 2050 | server=None, folder=None, username=None, password=None, |
|
2046 | 2051 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
2047 | 2052 | xaxis="frequency"): |
|
2048 | 2053 | |
|
2049 | 2054 | """ |
|
2050 | 2055 | |
|
2051 | 2056 | Input: |
|
2052 | 2057 | dataOut : |
|
2053 | 2058 | id : |
|
2054 | 2059 | wintitle : |
|
2055 | 2060 | channelList : |
|
2056 | 2061 | showProfile : |
|
2057 | 2062 | xmin : None, |
|
2058 | 2063 | xmax : None, |
|
2059 | 2064 | ymin : None, |
|
2060 | 2065 | ymax : None, |
|
2061 | 2066 | zmin : None, |
|
2062 | 2067 | zmax : None |
|
2063 | 2068 | """ |
|
2064 | 2069 | #Rebuild matrix |
|
2065 | 2070 | utctime = dataOut.data_param[0,0] |
|
2066 | 2071 | cmet = dataOut.data_param[:,1].astype(int) |
|
2067 | 2072 | tmet = dataOut.data_param[:,2].astype(int) |
|
2068 | 2073 | hmet = dataOut.data_param[:,3].astype(int) |
|
2069 | 2074 | |
|
2070 | 2075 | nParam = 3 |
|
2071 | 2076 | nChan = len(dataOut.groupList) |
|
2072 | 2077 | x = dataOut.abscissaList |
|
2073 | 2078 | y = dataOut.heightList |
|
2074 | 2079 | |
|
2075 | 2080 | z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan) |
|
2076 | 2081 | z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:] |
|
2077 | 2082 | z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale |
|
2078 | 2083 | z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1)) |
|
2079 | 2084 | |
|
2080 | 2085 | xlabel = "Time (s)" |
|
2081 | 2086 | ylabel = "Range (km)" |
|
2082 | 2087 | |
|
2083 | 2088 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
2084 | 2089 | |
|
2085 | 2090 | if not self.isConfig: |
|
2086 | 2091 | |
|
2087 | 2092 | nplots = nParam*nChan |
|
2088 | 2093 | |
|
2089 | 2094 | self.setup(id=id, |
|
2090 | 2095 | nplots=nplots, |
|
2091 | 2096 | wintitle=wintitle, |
|
2092 | 2097 | show=show) |
|
2093 | 2098 | |
|
2094 | 2099 | if xmin is None: xmin = numpy.nanmin(x) |
|
2095 | 2100 | if xmax is None: xmax = numpy.nanmax(x) |
|
2096 | 2101 | if ymin is None: ymin = numpy.nanmin(y) |
|
2097 | 2102 | if ymax is None: ymax = numpy.nanmax(y) |
|
2098 | 2103 | if SNRmin is None: SNRmin = numpy.nanmin(z[0,:]) |
|
2099 | 2104 | if SNRmax is None: SNRmax = numpy.nanmax(z[0,:]) |
|
2100 | 2105 | if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:])) |
|
2101 | 2106 | if vmin is None: vmin = -vmax |
|
2102 | 2107 | if wmin is None: wmin = 0 |
|
2103 | 2108 | if wmax is None: wmax = 50 |
|
2104 | 2109 | |
|
2105 | 2110 | self.nChannels = nChan |
|
2106 | 2111 | |
|
2107 | 2112 | zminList = [] |
|
2108 | 2113 | zmaxList = [] |
|
2109 | 2114 | titleList = [] |
|
2110 | 2115 | cmapList = [] |
|
2111 | 2116 | for i in range(self.nChannels): |
|
2112 | 2117 | strAux1 = "SNR Channel "+ str(i) |
|
2113 | 2118 | strAux2 = "Radial Velocity Channel "+ str(i) |
|
2114 | 2119 | strAux3 = "Spectral Width Channel "+ str(i) |
|
2115 | 2120 | |
|
2116 | 2121 | titleList = titleList + [strAux1,strAux2,strAux3] |
|
2117 | 2122 | cmapList = cmapList + ["jet","RdBu_r","jet"] |
|
2118 | 2123 | zminList = zminList + [SNRmin,vmin,wmin] |
|
2119 | 2124 | zmaxList = zmaxList + [SNRmax,vmax,wmax] |
|
2120 | 2125 | |
|
2121 | 2126 | self.zminList = zminList |
|
2122 | 2127 | self.zmaxList = zmaxList |
|
2123 | 2128 | self.cmapList = cmapList |
|
2124 | 2129 | self.titleList = titleList |
|
2125 | 2130 | |
|
2126 | 2131 | self.FTP_WEI = ftp_wei |
|
2127 | 2132 | self.EXP_CODE = exp_code |
|
2128 | 2133 | self.SUB_EXP_CODE = sub_exp_code |
|
2129 | 2134 | self.PLOT_POS = plot_pos |
|
2130 | 2135 | |
|
2131 | 2136 | self.isConfig = True |
|
2132 | 2137 | |
|
2133 | 2138 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
2134 | 2139 | |
|
2135 | 2140 | for i in range(self.nplots): |
|
2136 | 2141 | title = self.titleList[i] + ": " +str_datetime |
|
2137 | 2142 | axes = self.axesList[i] |
|
2138 | 2143 | axes.pcolor(x, y, z[i,:].T, |
|
2139 | 2144 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i], |
|
2140 | 2145 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='') |
|
2141 | 2146 | self.draw() |
|
2142 | 2147 | |
|
2143 | 2148 | if figfile == None: |
|
2144 | 2149 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
2145 | 2150 | name = str_datetime |
|
2146 | 2151 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
2147 | 2152 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
2148 | 2153 | figfile = self.getFilename(name) |
|
2149 | 2154 | |
|
2150 | 2155 | self.save(figpath=figpath, |
|
2151 | 2156 | figfile=figfile, |
|
2152 | 2157 | save=save, |
|
2153 | 2158 | ftp=ftp, |
|
2154 | 2159 | wr_period=wr_period, |
|
2155 | 2160 | thisDatetime=thisDatetime) |
@@ -1,1609 +1,1611 | |||
|
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 | print 'FRECUENCIA MAXIMA', numpy.amax(x) | |
|
132 | asfasfasdfaf | |
|
131 | 133 | print '#######################################################' |
|
132 | 134 | print 'xlen', len(x) |
|
133 | 135 | print x |
|
134 | 136 | print '#######################################################' |
|
135 | 137 | xlabel = "Frequency (kHz)" |
|
136 | 138 | |
|
137 | 139 | elif xaxis == "time": |
|
138 | 140 | x = dataOut.getAcfRange(1) |
|
139 | 141 | xlabel = "Time (ms)" |
|
140 | 142 | |
|
141 | 143 | else: |
|
142 | 144 | x = dataOut.getVelRange(1) |
|
143 | 145 | xlabel = "Velocity (m/s)" |
|
144 | 146 | |
|
145 | 147 | ylabel = "Range (Km)" |
|
146 | 148 | |
|
147 | 149 | y = dataOut.getHeiRange() |
|
148 | 150 | |
|
149 | 151 | z = dataOut.data_spc/factor |
|
150 | 152 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
151 | 153 | zdB = 10*numpy.log10(z) |
|
152 | 154 | |
|
153 | 155 | avg = numpy.average(z, axis=1) |
|
154 | 156 | avgdB = 10*numpy.log10(avg) |
|
155 | 157 | |
|
156 | 158 | noise = dataOut.getNoise()/factor |
|
157 | 159 | noisedB = 10*numpy.log10(noise) |
|
158 | 160 | |
|
159 | 161 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
160 | 162 | title = wintitle + " Spectra" |
|
161 | 163 | |
|
162 | 164 | |
|
163 | 165 | |
|
164 | 166 | print 'len de X',len(x), numpy.shape(x), 'len de spc line',len(dataOut.data_spc[1,:,15]), numpy.shape(dataOut.data_spc) |
|
165 | 167 | print 'Altura:', y[0], y[1], y[13], y[14], y[10] |
|
166 | 168 | #a=z[1,:,15] |
|
167 | 169 | |
|
168 | 170 | # fig = plt.figure(10+self.indice) |
|
169 | 171 | # plt.plot( x[0:128], zdB[0,:,10] ) |
|
170 | 172 | # plt.axis([-12, 12, 15, 50]) |
|
171 | 173 | # plt.title(" %s" %( '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))) ) |
|
172 | 174 | # plt.ylabel('Intensidad [dB]') |
|
173 | 175 | # plt.xlabel('Velocidad [m/s]') |
|
174 | 176 | # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice)) |
|
175 | 177 | # |
|
176 | 178 | # plt.show() |
|
177 | 179 | # |
|
178 | 180 | # self.indice=self.indice+1 |
|
179 | 181 | |
|
180 | 182 | |
|
181 | 183 | |
|
182 | 184 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
183 | 185 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
184 | 186 | |
|
185 | 187 | if not self.isConfig: |
|
186 | 188 | |
|
187 | 189 | nplots = len(channelIndexList) |
|
188 | 190 | |
|
189 | 191 | self.setup(id=id, |
|
190 | 192 | nplots=nplots, |
|
191 | 193 | wintitle=wintitle, |
|
192 | 194 | showprofile=showprofile, |
|
193 | 195 | show=show) |
|
194 | 196 | |
|
195 | 197 | if xmin == None: xmin = numpy.nanmin(x) |
|
196 | 198 | if xmax == None: xmax = numpy.nanmax(x) |
|
197 | 199 | if ymin == None: ymin = numpy.nanmin(y) |
|
198 | 200 | if ymax == None: ymax = numpy.nanmax(y) |
|
199 | 201 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
200 | 202 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
201 | 203 | |
|
202 | 204 | self.FTP_WEI = ftp_wei |
|
203 | 205 | self.EXP_CODE = exp_code |
|
204 | 206 | self.SUB_EXP_CODE = sub_exp_code |
|
205 | 207 | self.PLOT_POS = plot_pos |
|
206 | 208 | |
|
207 | 209 | self.isConfig = True |
|
208 | 210 | |
|
209 | 211 | self.setWinTitle(title) |
|
210 | 212 | |
|
211 | 213 | for i in range(self.nplots): |
|
212 | 214 | index = channelIndexList[i] |
|
213 | 215 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
214 | 216 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
215 | 217 | if len(dataOut.beam.codeList) != 0: |
|
216 | 218 | 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) |
|
217 | 219 | |
|
218 | 220 | axes = self.axesList[i*self.__nsubplots] |
|
219 | 221 | axes.pcolor(x, y, zdB[index,:,:], |
|
220 | 222 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
221 | 223 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, |
|
222 | 224 | ticksize=9, cblabel='') |
|
223 | 225 | |
|
224 | 226 | if self.__showprofile: |
|
225 | 227 | axes = self.axesList[i*self.__nsubplots +1] |
|
226 | 228 | axes.pline(avgdB[index,:], y, |
|
227 | 229 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
228 | 230 | xlabel='dB', ylabel='', title='', |
|
229 | 231 | ytick_visible=False, |
|
230 | 232 | grid='x') |
|
231 | 233 | |
|
232 | 234 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
233 | 235 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
234 | 236 | |
|
235 | 237 | self.draw() |
|
236 | 238 | |
|
237 | 239 | if figfile == None: |
|
238 | 240 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
239 | 241 | name = str_datetime |
|
240 | 242 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
241 | 243 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
242 | 244 | figfile = self.getFilename(name) |
|
243 | 245 | |
|
244 | 246 | self.save(figpath=figpath, |
|
245 | 247 | figfile=figfile, |
|
246 | 248 | save=save, |
|
247 | 249 | ftp=ftp, |
|
248 | 250 | wr_period=wr_period, |
|
249 | 251 | thisDatetime=thisDatetime) |
|
250 | 252 | |
|
251 | 253 | |
|
252 | 254 | class CrossSpectraPlot(Figure): |
|
253 | 255 | |
|
254 | 256 | isConfig = None |
|
255 | 257 | __nsubplots = None |
|
256 | 258 | |
|
257 | 259 | WIDTH = None |
|
258 | 260 | HEIGHT = None |
|
259 | 261 | WIDTHPROF = None |
|
260 | 262 | HEIGHTPROF = None |
|
261 | 263 | PREFIX = 'cspc' |
|
262 | 264 | |
|
263 | 265 | def __init__(self, **kwargs): |
|
264 | 266 | Figure.__init__(self, **kwargs) |
|
265 | 267 | self.isConfig = False |
|
266 | 268 | self.__nsubplots = 4 |
|
267 | 269 | self.counter_imagwr = 0 |
|
268 | 270 | self.WIDTH = 250 |
|
269 | 271 | self.HEIGHT = 250 |
|
270 | 272 | self.WIDTHPROF = 0 |
|
271 | 273 | self.HEIGHTPROF = 0 |
|
272 | 274 | |
|
273 | 275 | self.PLOT_CODE = CROSS_CODE |
|
274 | 276 | self.FTP_WEI = None |
|
275 | 277 | self.EXP_CODE = None |
|
276 | 278 | self.SUB_EXP_CODE = None |
|
277 | 279 | self.PLOT_POS = None |
|
278 | 280 | |
|
279 | 281 | self.indice=0 |
|
280 | 282 | |
|
281 | 283 | def getSubplots(self): |
|
282 | 284 | |
|
283 | 285 | ncol = 4 |
|
284 | 286 | nrow = self.nplots |
|
285 | 287 | |
|
286 | 288 | return nrow, ncol |
|
287 | 289 | |
|
288 | 290 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
289 | 291 | |
|
290 | 292 | self.__showprofile = showprofile |
|
291 | 293 | self.nplots = nplots |
|
292 | 294 | |
|
293 | 295 | ncolspan = 1 |
|
294 | 296 | colspan = 1 |
|
295 | 297 | |
|
296 | 298 | self.createFigure(id = id, |
|
297 | 299 | wintitle = wintitle, |
|
298 | 300 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
299 | 301 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
300 | 302 | show=True) |
|
301 | 303 | |
|
302 | 304 | nrow, ncol = self.getSubplots() |
|
303 | 305 | |
|
304 | 306 | counter = 0 |
|
305 | 307 | for y in range(nrow): |
|
306 | 308 | for x in range(ncol): |
|
307 | 309 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
308 | 310 | |
|
309 | 311 | counter += 1 |
|
310 | 312 | |
|
311 | 313 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
312 | 314 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
313 | 315 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, |
|
314 | 316 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
315 | 317 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
316 | 318 | server=None, folder=None, username=None, password=None, |
|
317 | 319 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, |
|
318 | 320 | xaxis='frequency'): |
|
319 | 321 | |
|
320 | 322 | """ |
|
321 | 323 | |
|
322 | 324 | Input: |
|
323 | 325 | dataOut : |
|
324 | 326 | id : |
|
325 | 327 | wintitle : |
|
326 | 328 | channelList : |
|
327 | 329 | showProfile : |
|
328 | 330 | xmin : None, |
|
329 | 331 | xmax : None, |
|
330 | 332 | ymin : None, |
|
331 | 333 | ymax : None, |
|
332 | 334 | zmin : None, |
|
333 | 335 | zmax : None |
|
334 | 336 | """ |
|
335 | 337 | |
|
336 | 338 | if pairsList == None: |
|
337 | 339 | pairsIndexList = dataOut.pairsIndexList |
|
338 | 340 | else: |
|
339 | 341 | pairsIndexList = [] |
|
340 | 342 | for pair in pairsList: |
|
341 | 343 | if pair not in dataOut.pairsList: |
|
342 | 344 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) |
|
343 | 345 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
344 | 346 | |
|
345 | 347 | if not pairsIndexList: |
|
346 | 348 | return |
|
347 | 349 | |
|
348 | 350 | if len(pairsIndexList) > 4: |
|
349 | 351 | pairsIndexList = pairsIndexList[0:4] |
|
350 | 352 | |
|
351 | 353 | if normFactor is None: |
|
352 | 354 | factor = dataOut.normFactor |
|
353 | 355 | else: |
|
354 | 356 | factor = normFactor |
|
355 | 357 | x = dataOut.getVelRange(1) |
|
356 | 358 | y = dataOut.getHeiRange() |
|
357 | 359 | z = dataOut.data_spc[:,:,:]/factor |
|
358 | 360 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
359 | 361 | |
|
360 | 362 | noise = dataOut.noise/factor |
|
361 | 363 | |
|
362 | 364 | zdB = 10*numpy.log10(z) |
|
363 | 365 | noisedB = 10*numpy.log10(noise) |
|
364 | 366 | |
|
365 | 367 | if coh_min == None: |
|
366 | 368 | coh_min = 0.0 |
|
367 | 369 | if coh_max == None: |
|
368 | 370 | coh_max = 1.0 |
|
369 | 371 | |
|
370 | 372 | if phase_min == None: |
|
371 | 373 | phase_min = -180 |
|
372 | 374 | if phase_max == None: |
|
373 | 375 | phase_max = 180 |
|
374 | 376 | |
|
375 | 377 | #thisDatetime = dataOut.datatime |
|
376 | 378 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
377 | 379 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
378 | 380 | # xlabel = "Velocity (m/s)" |
|
379 | 381 | ylabel = "Range (Km)" |
|
380 | 382 | |
|
381 | 383 | if xaxis == "frequency": |
|
382 | 384 | x = dataOut.getFreqRange(1)/1000. |
|
383 | 385 | xlabel = "Frequency (kHz)" |
|
384 | 386 | |
|
385 | 387 | elif xaxis == "time": |
|
386 | 388 | x = dataOut.getAcfRange(1) |
|
387 | 389 | xlabel = "Time (ms)" |
|
388 | 390 | |
|
389 | 391 | else: |
|
390 | 392 | x = dataOut.getVelRange(1) |
|
391 | 393 | xlabel = "Velocity (m/s)" |
|
392 | 394 | |
|
393 | 395 | if not self.isConfig: |
|
394 | 396 | |
|
395 | 397 | nplots = len(pairsIndexList) |
|
396 | 398 | |
|
397 | 399 | self.setup(id=id, |
|
398 | 400 | nplots=nplots, |
|
399 | 401 | wintitle=wintitle, |
|
400 | 402 | showprofile=False, |
|
401 | 403 | show=show) |
|
402 | 404 | |
|
403 | 405 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
404 | 406 | avgdB = 10*numpy.log10(avg) |
|
405 | 407 | |
|
406 | 408 | if xmin == None: xmin = numpy.nanmin(x) |
|
407 | 409 | if xmax == None: xmax = numpy.nanmax(x) |
|
408 | 410 | if ymin == None: ymin = numpy.nanmin(y) |
|
409 | 411 | if ymax == None: ymax = numpy.nanmax(y) |
|
410 | 412 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
411 | 413 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
412 | 414 | |
|
413 | 415 | self.FTP_WEI = ftp_wei |
|
414 | 416 | self.EXP_CODE = exp_code |
|
415 | 417 | self.SUB_EXP_CODE = sub_exp_code |
|
416 | 418 | self.PLOT_POS = plot_pos |
|
417 | 419 | |
|
418 | 420 | self.isConfig = True |
|
419 | 421 | |
|
420 | 422 | self.setWinTitle(title) |
|
421 | 423 | |
|
422 | 424 | |
|
423 | 425 | for i in range(self.nplots): |
|
424 | 426 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
425 | 427 | |
|
426 | 428 | chan_index0 = dataOut.channelList.index(pair[0]) |
|
427 | 429 | chan_index1 = dataOut.channelList.index(pair[1]) |
|
428 | 430 | |
|
429 | 431 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
430 | 432 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) |
|
431 | 433 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) |
|
432 | 434 | axes0 = self.axesList[i*self.__nsubplots] |
|
433 | 435 | axes0.pcolor(x, y, zdB, |
|
434 | 436 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
435 | 437 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
436 | 438 | ticksize=9, colormap=power_cmap, cblabel='') |
|
437 | 439 | |
|
438 | 440 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) |
|
439 | 441 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) |
|
440 | 442 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
441 | 443 | axes0.pcolor(x, y, zdB, |
|
442 | 444 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
443 | 445 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
444 | 446 | ticksize=9, colormap=power_cmap, cblabel='') |
|
445 | 447 | |
|
446 | 448 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] ) |
|
447 | 449 | coherence = numpy.abs(coherenceComplex) |
|
448 | 450 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
449 | 451 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
450 | 452 | |
|
451 | 453 | |
|
452 | 454 | |
|
453 | 455 | |
|
454 | 456 | # #print 'FASE', numpy.shape(phase), y[25] |
|
455 | 457 | # fig = plt.figure(10+self.indice) |
|
456 | 458 | # #plt.plot( x[0:256],coherence[:,25] ) |
|
457 | 459 | # cohAv = numpy.average(coherence,1) |
|
458 | 460 | # |
|
459 | 461 | # plt.plot( x[0:256],cohAv ) |
|
460 | 462 | # #plt.axis([-12, 12, 15, 50]) |
|
461 | 463 | # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i))) |
|
462 | 464 | # plt.ylabel('Desfase [grados]') |
|
463 | 465 | # plt.xlabel('Velocidad [m/s]') |
|
464 | 466 | # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice)) |
|
465 | 467 | # |
|
466 | 468 | # plt.show() |
|
467 | 469 | # self.indice=self.indice+1 |
|
468 | 470 | |
|
469 | 471 | |
|
470 | 472 | # print 'FASE', numpy.shape(phase), y[25] |
|
471 | 473 | # fig = plt.figure(10+self.indice) |
|
472 | 474 | # plt.plot( x[0:256],phase[:,25] ) |
|
473 | 475 | # #plt.axis([-12, 12, 15, 50]) |
|
474 | 476 | # plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i))) |
|
475 | 477 | # plt.ylabel('Desfase [grados]') |
|
476 | 478 | # plt.xlabel('Velocidad [m/s]') |
|
477 | 479 | # fig.savefig('/home/erick/Documents/Pics/to{}.png'.format(self.indice)) |
|
478 | 480 | # |
|
479 | 481 | # plt.show() |
|
480 | 482 | # self.indice=self.indice+1 |
|
481 | 483 | |
|
482 | 484 | |
|
483 | 485 | |
|
484 | 486 | |
|
485 | 487 | title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) |
|
486 | 488 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
487 | 489 | axes0.pcolor(x, y, coherence, |
|
488 | 490 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, |
|
489 | 491 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
490 | 492 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
491 | 493 | |
|
492 | 494 | title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) |
|
493 | 495 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
494 | 496 | axes0.pcolor(x, y, phase, |
|
495 | 497 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
496 | 498 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
497 | 499 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
498 | 500 | |
|
499 | 501 | |
|
500 | 502 | |
|
501 | 503 | self.draw() |
|
502 | 504 | |
|
503 | 505 | self.save(figpath=figpath, |
|
504 | 506 | figfile=figfile, |
|
505 | 507 | save=save, |
|
506 | 508 | ftp=ftp, |
|
507 | 509 | wr_period=wr_period, |
|
508 | 510 | thisDatetime=thisDatetime) |
|
509 | 511 | |
|
510 | 512 | |
|
511 | 513 | class RTIPlot(Figure): |
|
512 | 514 | |
|
513 | 515 | __isConfig = None |
|
514 | 516 | __nsubplots = None |
|
515 | 517 | |
|
516 | 518 | WIDTHPROF = None |
|
517 | 519 | HEIGHTPROF = None |
|
518 | 520 | PREFIX = 'rti' |
|
519 | 521 | |
|
520 | 522 | def __init__(self, **kwargs): |
|
521 | 523 | |
|
522 | 524 | Figure.__init__(self, **kwargs) |
|
523 | 525 | self.timerange = None |
|
524 | 526 | self.isConfig = False |
|
525 | 527 | self.__nsubplots = 1 |
|
526 | 528 | |
|
527 | 529 | self.WIDTH = 800 |
|
528 | 530 | self.HEIGHT = 250 |
|
529 | 531 | self.WIDTHPROF = 120 |
|
530 | 532 | self.HEIGHTPROF = 0 |
|
531 | 533 | self.counter_imagwr = 0 |
|
532 | 534 | |
|
533 | 535 | self.PLOT_CODE = RTI_CODE |
|
534 | 536 | |
|
535 | 537 | self.FTP_WEI = None |
|
536 | 538 | self.EXP_CODE = None |
|
537 | 539 | self.SUB_EXP_CODE = None |
|
538 | 540 | self.PLOT_POS = None |
|
539 | 541 | self.tmin = None |
|
540 | 542 | self.tmax = None |
|
541 | 543 | |
|
542 | 544 | self.xmin = None |
|
543 | 545 | self.xmax = None |
|
544 | 546 | |
|
545 | 547 | self.figfile = None |
|
546 | 548 | |
|
547 | 549 | def getSubplots(self): |
|
548 | 550 | |
|
549 | 551 | ncol = 1 |
|
550 | 552 | nrow = self.nplots |
|
551 | 553 | |
|
552 | 554 | return nrow, ncol |
|
553 | 555 | |
|
554 | 556 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
555 | 557 | |
|
556 | 558 | self.__showprofile = showprofile |
|
557 | 559 | self.nplots = nplots |
|
558 | 560 | |
|
559 | 561 | ncolspan = 1 |
|
560 | 562 | colspan = 1 |
|
561 | 563 | if showprofile: |
|
562 | 564 | ncolspan = 7 |
|
563 | 565 | colspan = 6 |
|
564 | 566 | self.__nsubplots = 2 |
|
565 | 567 | |
|
566 | 568 | self.createFigure(id = id, |
|
567 | 569 | wintitle = wintitle, |
|
568 | 570 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
569 | 571 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
570 | 572 | show=show) |
|
571 | 573 | |
|
572 | 574 | nrow, ncol = self.getSubplots() |
|
573 | 575 | |
|
574 | 576 | counter = 0 |
|
575 | 577 | for y in range(nrow): |
|
576 | 578 | for x in range(ncol): |
|
577 | 579 | |
|
578 | 580 | if counter >= self.nplots: |
|
579 | 581 | break |
|
580 | 582 | |
|
581 | 583 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
582 | 584 | |
|
583 | 585 | if showprofile: |
|
584 | 586 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
585 | 587 | |
|
586 | 588 | counter += 1 |
|
587 | 589 | |
|
588 | 590 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
589 | 591 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
590 | 592 | timerange=None, colormap='jet', |
|
591 | 593 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
592 | 594 | server=None, folder=None, username=None, password=None, |
|
593 | 595 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None): |
|
594 | 596 | |
|
595 | 597 | """ |
|
596 | 598 | |
|
597 | 599 | Input: |
|
598 | 600 | dataOut : |
|
599 | 601 | id : |
|
600 | 602 | wintitle : |
|
601 | 603 | channelList : |
|
602 | 604 | showProfile : |
|
603 | 605 | xmin : None, |
|
604 | 606 | xmax : None, |
|
605 | 607 | ymin : None, |
|
606 | 608 | ymax : None, |
|
607 | 609 | zmin : None, |
|
608 | 610 | zmax : None |
|
609 | 611 | """ |
|
610 | 612 | |
|
611 | 613 | #colormap = kwargs.get('colormap', 'jet') |
|
612 | 614 | if HEIGHT is not None: |
|
613 | 615 | self.HEIGHT = HEIGHT |
|
614 | 616 | |
|
615 | 617 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
616 | 618 | return |
|
617 | 619 | |
|
618 | 620 | if channelList == None: |
|
619 | 621 | channelIndexList = dataOut.channelIndexList |
|
620 | 622 | else: |
|
621 | 623 | channelIndexList = [] |
|
622 | 624 | for channel in channelList: |
|
623 | 625 | if channel not in dataOut.channelList: |
|
624 | 626 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
625 | 627 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
626 | 628 | |
|
627 | 629 | if normFactor is None: |
|
628 | 630 | factor = dataOut.normFactor |
|
629 | 631 | else: |
|
630 | 632 | factor = normFactor |
|
631 | 633 | |
|
632 | 634 | # factor = dataOut.normFactor |
|
633 | 635 | x = dataOut.getTimeRange() |
|
634 | 636 | y = dataOut.getHeiRange() |
|
635 | 637 | |
|
636 | 638 | z = dataOut.data_spc/factor |
|
637 | 639 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
638 | 640 | avg = numpy.average(z, axis=1) |
|
639 | 641 | avgdB = 10.*numpy.log10(avg) |
|
640 | 642 | # avgdB = dataOut.getPower() |
|
641 | 643 | |
|
642 | 644 | |
|
643 | 645 | thisDatetime = dataOut.datatime |
|
644 | 646 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
645 | 647 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
646 | 648 | xlabel = "" |
|
647 | 649 | ylabel = "Range (Km)" |
|
648 | 650 | |
|
649 | 651 | update_figfile = False |
|
650 | 652 | |
|
651 | 653 | if dataOut.ltctime >= self.xmax: |
|
652 | 654 | self.counter_imagwr = wr_period |
|
653 | 655 | self.isConfig = False |
|
654 | 656 | update_figfile = True |
|
655 | 657 | |
|
656 | 658 | if not self.isConfig: |
|
657 | 659 | |
|
658 | 660 | nplots = len(channelIndexList) |
|
659 | 661 | |
|
660 | 662 | self.setup(id=id, |
|
661 | 663 | nplots=nplots, |
|
662 | 664 | wintitle=wintitle, |
|
663 | 665 | showprofile=showprofile, |
|
664 | 666 | show=show) |
|
665 | 667 | |
|
666 | 668 | if timerange != None: |
|
667 | 669 | self.timerange = timerange |
|
668 | 670 | |
|
669 | 671 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
670 | 672 | |
|
671 | 673 | noise = dataOut.noise/factor |
|
672 | 674 | noisedB = 10*numpy.log10(noise) |
|
673 | 675 | |
|
674 | 676 | if ymin == None: ymin = numpy.nanmin(y) |
|
675 | 677 | if ymax == None: ymax = numpy.nanmax(y) |
|
676 | 678 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
677 | 679 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
678 | 680 | |
|
679 | 681 | self.FTP_WEI = ftp_wei |
|
680 | 682 | self.EXP_CODE = exp_code |
|
681 | 683 | self.SUB_EXP_CODE = sub_exp_code |
|
682 | 684 | self.PLOT_POS = plot_pos |
|
683 | 685 | |
|
684 | 686 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
685 | 687 | self.isConfig = True |
|
686 | 688 | self.figfile = figfile |
|
687 | 689 | update_figfile = True |
|
688 | 690 | |
|
689 | 691 | self.setWinTitle(title) |
|
690 | 692 | |
|
691 | 693 | for i in range(self.nplots): |
|
692 | 694 | index = channelIndexList[i] |
|
693 | 695 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
694 | 696 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
695 | 697 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
696 | 698 | axes = self.axesList[i*self.__nsubplots] |
|
697 | 699 | zdB = avgdB[index].reshape((1,-1)) |
|
698 | 700 | axes.pcolorbuffer(x, y, zdB, |
|
699 | 701 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
700 | 702 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
701 | 703 | ticksize=9, cblabel='', cbsize="1%", colormap=colormap) |
|
702 | 704 | |
|
703 | 705 | if self.__showprofile: |
|
704 | 706 | axes = self.axesList[i*self.__nsubplots +1] |
|
705 | 707 | axes.pline(avgdB[index], y, |
|
706 | 708 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
707 | 709 | xlabel='dB', ylabel='', title='', |
|
708 | 710 | ytick_visible=False, |
|
709 | 711 | grid='x') |
|
710 | 712 | |
|
711 | 713 | self.draw() |
|
712 | 714 | |
|
713 | 715 | self.save(figpath=figpath, |
|
714 | 716 | figfile=figfile, |
|
715 | 717 | save=save, |
|
716 | 718 | ftp=ftp, |
|
717 | 719 | wr_period=wr_period, |
|
718 | 720 | thisDatetime=thisDatetime, |
|
719 | 721 | update_figfile=update_figfile) |
|
720 | 722 | |
|
721 | 723 | class CoherenceMap(Figure): |
|
722 | 724 | isConfig = None |
|
723 | 725 | __nsubplots = None |
|
724 | 726 | |
|
725 | 727 | WIDTHPROF = None |
|
726 | 728 | HEIGHTPROF = None |
|
727 | 729 | PREFIX = 'cmap' |
|
728 | 730 | |
|
729 | 731 | def __init__(self, **kwargs): |
|
730 | 732 | Figure.__init__(self, **kwargs) |
|
731 | 733 | self.timerange = 2*60*60 |
|
732 | 734 | self.isConfig = False |
|
733 | 735 | self.__nsubplots = 1 |
|
734 | 736 | |
|
735 | 737 | self.WIDTH = 800 |
|
736 | 738 | self.HEIGHT = 180 |
|
737 | 739 | self.WIDTHPROF = 120 |
|
738 | 740 | self.HEIGHTPROF = 0 |
|
739 | 741 | self.counter_imagwr = 0 |
|
740 | 742 | |
|
741 | 743 | self.PLOT_CODE = COH_CODE |
|
742 | 744 | |
|
743 | 745 | self.FTP_WEI = None |
|
744 | 746 | self.EXP_CODE = None |
|
745 | 747 | self.SUB_EXP_CODE = None |
|
746 | 748 | self.PLOT_POS = None |
|
747 | 749 | self.counter_imagwr = 0 |
|
748 | 750 | |
|
749 | 751 | self.xmin = None |
|
750 | 752 | self.xmax = None |
|
751 | 753 | |
|
752 | 754 | def getSubplots(self): |
|
753 | 755 | ncol = 1 |
|
754 | 756 | nrow = self.nplots*2 |
|
755 | 757 | |
|
756 | 758 | return nrow, ncol |
|
757 | 759 | |
|
758 | 760 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
759 | 761 | self.__showprofile = showprofile |
|
760 | 762 | self.nplots = nplots |
|
761 | 763 | |
|
762 | 764 | ncolspan = 1 |
|
763 | 765 | colspan = 1 |
|
764 | 766 | if showprofile: |
|
765 | 767 | ncolspan = 7 |
|
766 | 768 | colspan = 6 |
|
767 | 769 | self.__nsubplots = 2 |
|
768 | 770 | |
|
769 | 771 | self.createFigure(id = id, |
|
770 | 772 | wintitle = wintitle, |
|
771 | 773 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
772 | 774 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
773 | 775 | show=True) |
|
774 | 776 | |
|
775 | 777 | nrow, ncol = self.getSubplots() |
|
776 | 778 | |
|
777 | 779 | for y in range(nrow): |
|
778 | 780 | for x in range(ncol): |
|
779 | 781 | |
|
780 | 782 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
781 | 783 | |
|
782 | 784 | if showprofile: |
|
783 | 785 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
784 | 786 | |
|
785 | 787 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
786 | 788 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
787 | 789 | timerange=None, phase_min=None, phase_max=None, |
|
788 | 790 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
789 | 791 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
790 | 792 | server=None, folder=None, username=None, password=None, |
|
791 | 793 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
792 | 794 | |
|
793 | 795 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
794 | 796 | return |
|
795 | 797 | |
|
796 | 798 | if pairsList == None: |
|
797 | 799 | pairsIndexList = dataOut.pairsIndexList |
|
798 | 800 | else: |
|
799 | 801 | pairsIndexList = [] |
|
800 | 802 | for pair in pairsList: |
|
801 | 803 | if pair not in dataOut.pairsList: |
|
802 | 804 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
803 | 805 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
804 | 806 | |
|
805 | 807 | if pairsIndexList == []: |
|
806 | 808 | return |
|
807 | 809 | |
|
808 | 810 | if len(pairsIndexList) > 4: |
|
809 | 811 | pairsIndexList = pairsIndexList[0:4] |
|
810 | 812 | |
|
811 | 813 | if phase_min == None: |
|
812 | 814 | phase_min = -180 |
|
813 | 815 | if phase_max == None: |
|
814 | 816 | phase_max = 180 |
|
815 | 817 | |
|
816 | 818 | x = dataOut.getTimeRange() |
|
817 | 819 | y = dataOut.getHeiRange() |
|
818 | 820 | |
|
819 | 821 | thisDatetime = dataOut.datatime |
|
820 | 822 | |
|
821 | 823 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
822 | 824 | xlabel = "" |
|
823 | 825 | ylabel = "Range (Km)" |
|
824 | 826 | update_figfile = False |
|
825 | 827 | |
|
826 | 828 | if not self.isConfig: |
|
827 | 829 | nplots = len(pairsIndexList) |
|
828 | 830 | self.setup(id=id, |
|
829 | 831 | nplots=nplots, |
|
830 | 832 | wintitle=wintitle, |
|
831 | 833 | showprofile=showprofile, |
|
832 | 834 | show=show) |
|
833 | 835 | |
|
834 | 836 | if timerange != None: |
|
835 | 837 | self.timerange = timerange |
|
836 | 838 | |
|
837 | 839 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
838 | 840 | |
|
839 | 841 | if ymin == None: ymin = numpy.nanmin(y) |
|
840 | 842 | if ymax == None: ymax = numpy.nanmax(y) |
|
841 | 843 | if zmin == None: zmin = 0. |
|
842 | 844 | if zmax == None: zmax = 1. |
|
843 | 845 | |
|
844 | 846 | self.FTP_WEI = ftp_wei |
|
845 | 847 | self.EXP_CODE = exp_code |
|
846 | 848 | self.SUB_EXP_CODE = sub_exp_code |
|
847 | 849 | self.PLOT_POS = plot_pos |
|
848 | 850 | |
|
849 | 851 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
850 | 852 | |
|
851 | 853 | self.isConfig = True |
|
852 | 854 | update_figfile = True |
|
853 | 855 | |
|
854 | 856 | self.setWinTitle(title) |
|
855 | 857 | |
|
856 | 858 | for i in range(self.nplots): |
|
857 | 859 | |
|
858 | 860 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
859 | 861 | |
|
860 | 862 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
861 | 863 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
862 | 864 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
863 | 865 | |
|
864 | 866 | |
|
865 | 867 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
866 | 868 | coherence = numpy.abs(avgcoherenceComplex) |
|
867 | 869 | |
|
868 | 870 | z = coherence.reshape((1,-1)) |
|
869 | 871 | |
|
870 | 872 | counter = 0 |
|
871 | 873 | |
|
872 | 874 | title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
873 | 875 | axes = self.axesList[i*self.__nsubplots*2] |
|
874 | 876 | axes.pcolorbuffer(x, y, z, |
|
875 | 877 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
876 | 878 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
877 | 879 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
878 | 880 | |
|
879 | 881 | if self.__showprofile: |
|
880 | 882 | counter += 1 |
|
881 | 883 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
882 | 884 | axes.pline(coherence, y, |
|
883 | 885 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
884 | 886 | xlabel='', ylabel='', title='', ticksize=7, |
|
885 | 887 | ytick_visible=False, nxticks=5, |
|
886 | 888 | grid='x') |
|
887 | 889 | |
|
888 | 890 | counter += 1 |
|
889 | 891 | |
|
890 | 892 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
891 | 893 | |
|
892 | 894 | z = phase.reshape((1,-1)) |
|
893 | 895 | |
|
894 | 896 | title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
895 | 897 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
896 | 898 | axes.pcolorbuffer(x, y, z, |
|
897 | 899 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
898 | 900 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
899 | 901 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
900 | 902 | |
|
901 | 903 | if self.__showprofile: |
|
902 | 904 | counter += 1 |
|
903 | 905 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
904 | 906 | axes.pline(phase, y, |
|
905 | 907 | xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax, |
|
906 | 908 | xlabel='', ylabel='', title='', ticksize=7, |
|
907 | 909 | ytick_visible=False, nxticks=4, |
|
908 | 910 | grid='x') |
|
909 | 911 | |
|
910 | 912 | self.draw() |
|
911 | 913 | |
|
912 | 914 | if dataOut.ltctime >= self.xmax: |
|
913 | 915 | self.counter_imagwr = wr_period |
|
914 | 916 | self.isConfig = False |
|
915 | 917 | update_figfile = True |
|
916 | 918 | |
|
917 | 919 | self.save(figpath=figpath, |
|
918 | 920 | figfile=figfile, |
|
919 | 921 | save=save, |
|
920 | 922 | ftp=ftp, |
|
921 | 923 | wr_period=wr_period, |
|
922 | 924 | thisDatetime=thisDatetime, |
|
923 | 925 | update_figfile=update_figfile) |
|
924 | 926 | |
|
925 | 927 | class PowerProfilePlot(Figure): |
|
926 | 928 | |
|
927 | 929 | isConfig = None |
|
928 | 930 | __nsubplots = None |
|
929 | 931 | |
|
930 | 932 | WIDTHPROF = None |
|
931 | 933 | HEIGHTPROF = None |
|
932 | 934 | PREFIX = 'spcprofile' |
|
933 | 935 | |
|
934 | 936 | def __init__(self, **kwargs): |
|
935 | 937 | Figure.__init__(self, **kwargs) |
|
936 | 938 | self.isConfig = False |
|
937 | 939 | self.__nsubplots = 1 |
|
938 | 940 | |
|
939 | 941 | self.PLOT_CODE = POWER_CODE |
|
940 | 942 | |
|
941 | 943 | self.WIDTH = 300 |
|
942 | 944 | self.HEIGHT = 500 |
|
943 | 945 | self.counter_imagwr = 0 |
|
944 | 946 | |
|
945 | 947 | def getSubplots(self): |
|
946 | 948 | ncol = 1 |
|
947 | 949 | nrow = 1 |
|
948 | 950 | |
|
949 | 951 | return nrow, ncol |
|
950 | 952 | |
|
951 | 953 | def setup(self, id, nplots, wintitle, show): |
|
952 | 954 | |
|
953 | 955 | self.nplots = nplots |
|
954 | 956 | |
|
955 | 957 | ncolspan = 1 |
|
956 | 958 | colspan = 1 |
|
957 | 959 | |
|
958 | 960 | self.createFigure(id = id, |
|
959 | 961 | wintitle = wintitle, |
|
960 | 962 | widthplot = self.WIDTH, |
|
961 | 963 | heightplot = self.HEIGHT, |
|
962 | 964 | show=show) |
|
963 | 965 | |
|
964 | 966 | nrow, ncol = self.getSubplots() |
|
965 | 967 | |
|
966 | 968 | counter = 0 |
|
967 | 969 | for y in range(nrow): |
|
968 | 970 | for x in range(ncol): |
|
969 | 971 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
970 | 972 | |
|
971 | 973 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
972 | 974 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
973 | 975 | save=False, figpath='./', figfile=None, show=True, |
|
974 | 976 | ftp=False, wr_period=1, server=None, |
|
975 | 977 | folder=None, username=None, password=None): |
|
976 | 978 | |
|
977 | 979 | |
|
978 | 980 | if channelList == None: |
|
979 | 981 | channelIndexList = dataOut.channelIndexList |
|
980 | 982 | channelList = dataOut.channelList |
|
981 | 983 | else: |
|
982 | 984 | channelIndexList = [] |
|
983 | 985 | for channel in channelList: |
|
984 | 986 | if channel not in dataOut.channelList: |
|
985 | 987 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
986 | 988 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
987 | 989 | |
|
988 | 990 | factor = dataOut.normFactor |
|
989 | 991 | |
|
990 | 992 | y = dataOut.getHeiRange() |
|
991 | 993 | |
|
992 | 994 | #for voltage |
|
993 | 995 | if dataOut.type == 'Voltage': |
|
994 | 996 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
995 | 997 | x = x.real |
|
996 | 998 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
997 | 999 | |
|
998 | 1000 | #for spectra |
|
999 | 1001 | if dataOut.type == 'Spectra': |
|
1000 | 1002 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
1001 | 1003 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
1002 | 1004 | x = numpy.average(x, axis=1) |
|
1003 | 1005 | |
|
1004 | 1006 | |
|
1005 | 1007 | xdB = 10*numpy.log10(x) |
|
1006 | 1008 | |
|
1007 | 1009 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1008 | 1010 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1009 | 1011 | xlabel = "dB" |
|
1010 | 1012 | ylabel = "Range (Km)" |
|
1011 | 1013 | |
|
1012 | 1014 | if not self.isConfig: |
|
1013 | 1015 | |
|
1014 | 1016 | nplots = 1 |
|
1015 | 1017 | |
|
1016 | 1018 | self.setup(id=id, |
|
1017 | 1019 | nplots=nplots, |
|
1018 | 1020 | wintitle=wintitle, |
|
1019 | 1021 | show=show) |
|
1020 | 1022 | |
|
1021 | 1023 | if ymin == None: ymin = numpy.nanmin(y) |
|
1022 | 1024 | if ymax == None: ymax = numpy.nanmax(y) |
|
1023 | 1025 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
1024 | 1026 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 |
|
1025 | 1027 | |
|
1026 | 1028 | self.isConfig = True |
|
1027 | 1029 | |
|
1028 | 1030 | self.setWinTitle(title) |
|
1029 | 1031 | |
|
1030 | 1032 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1031 | 1033 | axes = self.axesList[0] |
|
1032 | 1034 | |
|
1033 | 1035 | legendlabels = ["channel %d"%x for x in channelList] |
|
1034 | 1036 | axes.pmultiline(xdB, y, |
|
1035 | 1037 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1036 | 1038 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1037 | 1039 | ytick_visible=True, nxticks=5, |
|
1038 | 1040 | grid='x') |
|
1039 | 1041 | |
|
1040 | 1042 | self.draw() |
|
1041 | 1043 | |
|
1042 | 1044 | self.save(figpath=figpath, |
|
1043 | 1045 | figfile=figfile, |
|
1044 | 1046 | save=save, |
|
1045 | 1047 | ftp=ftp, |
|
1046 | 1048 | wr_period=wr_period, |
|
1047 | 1049 | thisDatetime=thisDatetime) |
|
1048 | 1050 | |
|
1049 | 1051 | class SpectraCutPlot(Figure): |
|
1050 | 1052 | |
|
1051 | 1053 | isConfig = None |
|
1052 | 1054 | __nsubplots = None |
|
1053 | 1055 | |
|
1054 | 1056 | WIDTHPROF = None |
|
1055 | 1057 | HEIGHTPROF = None |
|
1056 | 1058 | PREFIX = 'spc_cut' |
|
1057 | 1059 | |
|
1058 | 1060 | def __init__(self, **kwargs): |
|
1059 | 1061 | Figure.__init__(self, **kwargs) |
|
1060 | 1062 | self.isConfig = False |
|
1061 | 1063 | self.__nsubplots = 1 |
|
1062 | 1064 | |
|
1063 | 1065 | self.PLOT_CODE = POWER_CODE |
|
1064 | 1066 | |
|
1065 | 1067 | self.WIDTH = 700 |
|
1066 | 1068 | self.HEIGHT = 500 |
|
1067 | 1069 | self.counter_imagwr = 0 |
|
1068 | 1070 | |
|
1069 | 1071 | def getSubplots(self): |
|
1070 | 1072 | ncol = 1 |
|
1071 | 1073 | nrow = 1 |
|
1072 | 1074 | |
|
1073 | 1075 | return nrow, ncol |
|
1074 | 1076 | |
|
1075 | 1077 | def setup(self, id, nplots, wintitle, show): |
|
1076 | 1078 | |
|
1077 | 1079 | self.nplots = nplots |
|
1078 | 1080 | |
|
1079 | 1081 | ncolspan = 1 |
|
1080 | 1082 | colspan = 1 |
|
1081 | 1083 | |
|
1082 | 1084 | self.createFigure(id = id, |
|
1083 | 1085 | wintitle = wintitle, |
|
1084 | 1086 | widthplot = self.WIDTH, |
|
1085 | 1087 | heightplot = self.HEIGHT, |
|
1086 | 1088 | show=show) |
|
1087 | 1089 | |
|
1088 | 1090 | nrow, ncol = self.getSubplots() |
|
1089 | 1091 | |
|
1090 | 1092 | counter = 0 |
|
1091 | 1093 | for y in range(nrow): |
|
1092 | 1094 | for x in range(ncol): |
|
1093 | 1095 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1094 | 1096 | |
|
1095 | 1097 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1096 | 1098 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1097 | 1099 | save=False, figpath='./', figfile=None, show=True, |
|
1098 | 1100 | ftp=False, wr_period=1, server=None, |
|
1099 | 1101 | folder=None, username=None, password=None, |
|
1100 | 1102 | xaxis="frequency"): |
|
1101 | 1103 | |
|
1102 | 1104 | |
|
1103 | 1105 | if channelList == None: |
|
1104 | 1106 | channelIndexList = dataOut.channelIndexList |
|
1105 | 1107 | channelList = dataOut.channelList |
|
1106 | 1108 | else: |
|
1107 | 1109 | channelIndexList = [] |
|
1108 | 1110 | for channel in channelList: |
|
1109 | 1111 | if channel not in dataOut.channelList: |
|
1110 | 1112 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1111 | 1113 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1112 | 1114 | |
|
1113 | 1115 | factor = dataOut.normFactor |
|
1114 | 1116 | |
|
1115 | 1117 | y = dataOut.getHeiRange() |
|
1116 | 1118 | |
|
1117 | 1119 | z = dataOut.data_spc/factor |
|
1118 | 1120 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1119 | 1121 | |
|
1120 | 1122 | hei_index = numpy.arange(25)*3 + 20 |
|
1121 | 1123 | |
|
1122 | 1124 | if xaxis == "frequency": |
|
1123 | 1125 | x = dataOut.getFreqRange()/1000. |
|
1124 | 1126 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1125 | 1127 | xlabel = "Frequency (kHz)" |
|
1126 | 1128 | ylabel = "Power (dB)" |
|
1127 | 1129 | |
|
1128 | 1130 | elif xaxis == "time": |
|
1129 | 1131 | x = dataOut.getAcfRange() |
|
1130 | 1132 | zdB = z[0,:,hei_index] |
|
1131 | 1133 | xlabel = "Time (ms)" |
|
1132 | 1134 | ylabel = "ACF" |
|
1133 | 1135 | |
|
1134 | 1136 | else: |
|
1135 | 1137 | x = dataOut.getVelRange() |
|
1136 | 1138 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1137 | 1139 | xlabel = "Velocity (m/s)" |
|
1138 | 1140 | ylabel = "Power (dB)" |
|
1139 | 1141 | |
|
1140 | 1142 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1141 | 1143 | title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1142 | 1144 | |
|
1143 | 1145 | if not self.isConfig: |
|
1144 | 1146 | |
|
1145 | 1147 | nplots = 1 |
|
1146 | 1148 | |
|
1147 | 1149 | self.setup(id=id, |
|
1148 | 1150 | nplots=nplots, |
|
1149 | 1151 | wintitle=wintitle, |
|
1150 | 1152 | show=show) |
|
1151 | 1153 | |
|
1152 | 1154 | if xmin == None: xmin = numpy.nanmin(x)*0.9 |
|
1153 | 1155 | if xmax == None: xmax = numpy.nanmax(x)*1.1 |
|
1154 | 1156 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1155 | 1157 | if ymax == None: ymax = numpy.nanmax(zdB) |
|
1156 | 1158 | |
|
1157 | 1159 | self.isConfig = True |
|
1158 | 1160 | |
|
1159 | 1161 | self.setWinTitle(title) |
|
1160 | 1162 | |
|
1161 | 1163 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1162 | 1164 | axes = self.axesList[0] |
|
1163 | 1165 | |
|
1164 | 1166 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] |
|
1165 | 1167 | |
|
1166 | 1168 | axes.pmultilineyaxis( x, zdB, |
|
1167 | 1169 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1168 | 1170 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1169 | 1171 | ytick_visible=True, nxticks=5, |
|
1170 | 1172 | grid='x') |
|
1171 | 1173 | |
|
1172 | 1174 | self.draw() |
|
1173 | 1175 | |
|
1174 | 1176 | self.save(figpath=figpath, |
|
1175 | 1177 | figfile=figfile, |
|
1176 | 1178 | save=save, |
|
1177 | 1179 | ftp=ftp, |
|
1178 | 1180 | wr_period=wr_period, |
|
1179 | 1181 | thisDatetime=thisDatetime) |
|
1180 | 1182 | |
|
1181 | 1183 | class Noise(Figure): |
|
1182 | 1184 | |
|
1183 | 1185 | isConfig = None |
|
1184 | 1186 | __nsubplots = None |
|
1185 | 1187 | |
|
1186 | 1188 | PREFIX = 'noise' |
|
1187 | 1189 | |
|
1188 | 1190 | |
|
1189 | 1191 | def __init__(self, **kwargs): |
|
1190 | 1192 | Figure.__init__(self, **kwargs) |
|
1191 | 1193 | self.timerange = 24*60*60 |
|
1192 | 1194 | self.isConfig = False |
|
1193 | 1195 | self.__nsubplots = 1 |
|
1194 | 1196 | self.counter_imagwr = 0 |
|
1195 | 1197 | self.WIDTH = 800 |
|
1196 | 1198 | self.HEIGHT = 400 |
|
1197 | 1199 | self.WIDTHPROF = 120 |
|
1198 | 1200 | self.HEIGHTPROF = 0 |
|
1199 | 1201 | self.xdata = None |
|
1200 | 1202 | self.ydata = None |
|
1201 | 1203 | |
|
1202 | 1204 | self.PLOT_CODE = NOISE_CODE |
|
1203 | 1205 | |
|
1204 | 1206 | self.FTP_WEI = None |
|
1205 | 1207 | self.EXP_CODE = None |
|
1206 | 1208 | self.SUB_EXP_CODE = None |
|
1207 | 1209 | self.PLOT_POS = None |
|
1208 | 1210 | self.figfile = None |
|
1209 | 1211 | |
|
1210 | 1212 | self.xmin = None |
|
1211 | 1213 | self.xmax = None |
|
1212 | 1214 | |
|
1213 | 1215 | def getSubplots(self): |
|
1214 | 1216 | |
|
1215 | 1217 | ncol = 1 |
|
1216 | 1218 | nrow = 1 |
|
1217 | 1219 | |
|
1218 | 1220 | return nrow, ncol |
|
1219 | 1221 | |
|
1220 | 1222 | def openfile(self, filename): |
|
1221 | 1223 | dirname = os.path.dirname(filename) |
|
1222 | 1224 | |
|
1223 | 1225 | if not os.path.exists(dirname): |
|
1224 | 1226 | os.mkdir(dirname) |
|
1225 | 1227 | |
|
1226 | 1228 | f = open(filename,'w+') |
|
1227 | 1229 | f.write('\n\n') |
|
1228 | 1230 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1229 | 1231 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1230 | 1232 | f.close() |
|
1231 | 1233 | |
|
1232 | 1234 | def save_data(self, filename_phase, data, data_datetime): |
|
1233 | 1235 | |
|
1234 | 1236 | f=open(filename_phase,'a') |
|
1235 | 1237 | |
|
1236 | 1238 | timetuple_data = data_datetime.timetuple() |
|
1237 | 1239 | day = str(timetuple_data.tm_mday) |
|
1238 | 1240 | month = str(timetuple_data.tm_mon) |
|
1239 | 1241 | year = str(timetuple_data.tm_year) |
|
1240 | 1242 | hour = str(timetuple_data.tm_hour) |
|
1241 | 1243 | minute = str(timetuple_data.tm_min) |
|
1242 | 1244 | second = str(timetuple_data.tm_sec) |
|
1243 | 1245 | |
|
1244 | 1246 | data_msg = '' |
|
1245 | 1247 | for i in range(len(data)): |
|
1246 | 1248 | data_msg += str(data[i]) + ' ' |
|
1247 | 1249 | |
|
1248 | 1250 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') |
|
1249 | 1251 | f.close() |
|
1250 | 1252 | |
|
1251 | 1253 | |
|
1252 | 1254 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1253 | 1255 | |
|
1254 | 1256 | self.__showprofile = showprofile |
|
1255 | 1257 | self.nplots = nplots |
|
1256 | 1258 | |
|
1257 | 1259 | ncolspan = 7 |
|
1258 | 1260 | colspan = 6 |
|
1259 | 1261 | self.__nsubplots = 2 |
|
1260 | 1262 | |
|
1261 | 1263 | self.createFigure(id = id, |
|
1262 | 1264 | wintitle = wintitle, |
|
1263 | 1265 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1264 | 1266 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1265 | 1267 | show=show) |
|
1266 | 1268 | |
|
1267 | 1269 | nrow, ncol = self.getSubplots() |
|
1268 | 1270 | |
|
1269 | 1271 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1270 | 1272 | |
|
1271 | 1273 | |
|
1272 | 1274 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1273 | 1275 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1274 | 1276 | timerange=None, |
|
1275 | 1277 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1276 | 1278 | server=None, folder=None, username=None, password=None, |
|
1277 | 1279 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1278 | 1280 | |
|
1279 | 1281 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1280 | 1282 | return |
|
1281 | 1283 | |
|
1282 | 1284 | if channelList == None: |
|
1283 | 1285 | channelIndexList = dataOut.channelIndexList |
|
1284 | 1286 | channelList = dataOut.channelList |
|
1285 | 1287 | else: |
|
1286 | 1288 | channelIndexList = [] |
|
1287 | 1289 | for channel in channelList: |
|
1288 | 1290 | if channel not in dataOut.channelList: |
|
1289 | 1291 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1290 | 1292 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1291 | 1293 | |
|
1292 | 1294 | x = dataOut.getTimeRange() |
|
1293 | 1295 | #y = dataOut.getHeiRange() |
|
1294 | 1296 | factor = dataOut.normFactor |
|
1295 | 1297 | noise = dataOut.noise[channelIndexList]/factor |
|
1296 | 1298 | noisedB = 10*numpy.log10(noise) |
|
1297 | 1299 | |
|
1298 | 1300 | thisDatetime = dataOut.datatime |
|
1299 | 1301 | |
|
1300 | 1302 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1301 | 1303 | xlabel = "" |
|
1302 | 1304 | ylabel = "Intensity (dB)" |
|
1303 | 1305 | update_figfile = False |
|
1304 | 1306 | |
|
1305 | 1307 | if not self.isConfig: |
|
1306 | 1308 | |
|
1307 | 1309 | nplots = 1 |
|
1308 | 1310 | |
|
1309 | 1311 | self.setup(id=id, |
|
1310 | 1312 | nplots=nplots, |
|
1311 | 1313 | wintitle=wintitle, |
|
1312 | 1314 | showprofile=showprofile, |
|
1313 | 1315 | show=show) |
|
1314 | 1316 | |
|
1315 | 1317 | if timerange != None: |
|
1316 | 1318 | self.timerange = timerange |
|
1317 | 1319 | |
|
1318 | 1320 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1319 | 1321 | |
|
1320 | 1322 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 |
|
1321 | 1323 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1322 | 1324 | |
|
1323 | 1325 | self.FTP_WEI = ftp_wei |
|
1324 | 1326 | self.EXP_CODE = exp_code |
|
1325 | 1327 | self.SUB_EXP_CODE = sub_exp_code |
|
1326 | 1328 | self.PLOT_POS = plot_pos |
|
1327 | 1329 | |
|
1328 | 1330 | |
|
1329 | 1331 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1330 | 1332 | self.isConfig = True |
|
1331 | 1333 | self.figfile = figfile |
|
1332 | 1334 | self.xdata = numpy.array([]) |
|
1333 | 1335 | self.ydata = numpy.array([]) |
|
1334 | 1336 | |
|
1335 | 1337 | update_figfile = True |
|
1336 | 1338 | |
|
1337 | 1339 | #open file beacon phase |
|
1338 | 1340 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1339 | 1341 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1340 | 1342 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1341 | 1343 | |
|
1342 | 1344 | self.setWinTitle(title) |
|
1343 | 1345 | |
|
1344 | 1346 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1345 | 1347 | |
|
1346 | 1348 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] |
|
1347 | 1349 | axes = self.axesList[0] |
|
1348 | 1350 | |
|
1349 | 1351 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1350 | 1352 | |
|
1351 | 1353 | if len(self.ydata)==0: |
|
1352 | 1354 | self.ydata = noisedB.reshape(-1,1) |
|
1353 | 1355 | else: |
|
1354 | 1356 | self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) |
|
1355 | 1357 | |
|
1356 | 1358 | |
|
1357 | 1359 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1358 | 1360 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1359 | 1361 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1360 | 1362 | XAxisAsTime=True, grid='both' |
|
1361 | 1363 | ) |
|
1362 | 1364 | |
|
1363 | 1365 | self.draw() |
|
1364 | 1366 | |
|
1365 | 1367 | if dataOut.ltctime >= self.xmax: |
|
1366 | 1368 | self.counter_imagwr = wr_period |
|
1367 | 1369 | self.isConfig = False |
|
1368 | 1370 | update_figfile = True |
|
1369 | 1371 | |
|
1370 | 1372 | self.save(figpath=figpath, |
|
1371 | 1373 | figfile=figfile, |
|
1372 | 1374 | save=save, |
|
1373 | 1375 | ftp=ftp, |
|
1374 | 1376 | wr_period=wr_period, |
|
1375 | 1377 | thisDatetime=thisDatetime, |
|
1376 | 1378 | update_figfile=update_figfile) |
|
1377 | 1379 | |
|
1378 | 1380 | #store data beacon phase |
|
1379 | 1381 | if save: |
|
1380 | 1382 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1381 | 1383 | |
|
1382 | 1384 | class BeaconPhase(Figure): |
|
1383 | 1385 | |
|
1384 | 1386 | __isConfig = None |
|
1385 | 1387 | __nsubplots = None |
|
1386 | 1388 | |
|
1387 | 1389 | PREFIX = 'beacon_phase' |
|
1388 | 1390 | |
|
1389 | 1391 | def __init__(self, **kwargs): |
|
1390 | 1392 | Figure.__init__(self, **kwargs) |
|
1391 | 1393 | self.timerange = 24*60*60 |
|
1392 | 1394 | self.isConfig = False |
|
1393 | 1395 | self.__nsubplots = 1 |
|
1394 | 1396 | self.counter_imagwr = 0 |
|
1395 | 1397 | self.WIDTH = 800 |
|
1396 | 1398 | self.HEIGHT = 400 |
|
1397 | 1399 | self.WIDTHPROF = 120 |
|
1398 | 1400 | self.HEIGHTPROF = 0 |
|
1399 | 1401 | self.xdata = None |
|
1400 | 1402 | self.ydata = None |
|
1401 | 1403 | |
|
1402 | 1404 | self.PLOT_CODE = BEACON_CODE |
|
1403 | 1405 | |
|
1404 | 1406 | self.FTP_WEI = None |
|
1405 | 1407 | self.EXP_CODE = None |
|
1406 | 1408 | self.SUB_EXP_CODE = None |
|
1407 | 1409 | self.PLOT_POS = None |
|
1408 | 1410 | |
|
1409 | 1411 | self.filename_phase = None |
|
1410 | 1412 | |
|
1411 | 1413 | self.figfile = None |
|
1412 | 1414 | |
|
1413 | 1415 | self.xmin = None |
|
1414 | 1416 | self.xmax = None |
|
1415 | 1417 | |
|
1416 | 1418 | def getSubplots(self): |
|
1417 | 1419 | |
|
1418 | 1420 | ncol = 1 |
|
1419 | 1421 | nrow = 1 |
|
1420 | 1422 | |
|
1421 | 1423 | return nrow, ncol |
|
1422 | 1424 | |
|
1423 | 1425 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1424 | 1426 | |
|
1425 | 1427 | self.__showprofile = showprofile |
|
1426 | 1428 | self.nplots = nplots |
|
1427 | 1429 | |
|
1428 | 1430 | ncolspan = 7 |
|
1429 | 1431 | colspan = 6 |
|
1430 | 1432 | self.__nsubplots = 2 |
|
1431 | 1433 | |
|
1432 | 1434 | self.createFigure(id = id, |
|
1433 | 1435 | wintitle = wintitle, |
|
1434 | 1436 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1435 | 1437 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1436 | 1438 | show=show) |
|
1437 | 1439 | |
|
1438 | 1440 | nrow, ncol = self.getSubplots() |
|
1439 | 1441 | |
|
1440 | 1442 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1441 | 1443 | |
|
1442 | 1444 | def save_phase(self, filename_phase): |
|
1443 | 1445 | f = open(filename_phase,'w+') |
|
1444 | 1446 | f.write('\n\n') |
|
1445 | 1447 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1446 | 1448 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1447 | 1449 | f.close() |
|
1448 | 1450 | |
|
1449 | 1451 | def save_data(self, filename_phase, data, data_datetime): |
|
1450 | 1452 | f=open(filename_phase,'a') |
|
1451 | 1453 | timetuple_data = data_datetime.timetuple() |
|
1452 | 1454 | day = str(timetuple_data.tm_mday) |
|
1453 | 1455 | month = str(timetuple_data.tm_mon) |
|
1454 | 1456 | year = str(timetuple_data.tm_year) |
|
1455 | 1457 | hour = str(timetuple_data.tm_hour) |
|
1456 | 1458 | minute = str(timetuple_data.tm_min) |
|
1457 | 1459 | second = str(timetuple_data.tm_sec) |
|
1458 | 1460 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1459 | 1461 | f.close() |
|
1460 | 1462 | |
|
1461 | 1463 | |
|
1462 | 1464 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1463 | 1465 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, |
|
1464 | 1466 | timerange=None, |
|
1465 | 1467 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1466 | 1468 | server=None, folder=None, username=None, password=None, |
|
1467 | 1469 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1468 | 1470 | |
|
1469 | 1471 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1470 | 1472 | return |
|
1471 | 1473 | |
|
1472 | 1474 | if pairsList == None: |
|
1473 | 1475 | pairsIndexList = dataOut.pairsIndexList[:10] |
|
1474 | 1476 | else: |
|
1475 | 1477 | pairsIndexList = [] |
|
1476 | 1478 | for pair in pairsList: |
|
1477 | 1479 | if pair not in dataOut.pairsList: |
|
1478 | 1480 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1479 | 1481 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1480 | 1482 | |
|
1481 | 1483 | if pairsIndexList == []: |
|
1482 | 1484 | return |
|
1483 | 1485 | |
|
1484 | 1486 | # if len(pairsIndexList) > 4: |
|
1485 | 1487 | # pairsIndexList = pairsIndexList[0:4] |
|
1486 | 1488 | |
|
1487 | 1489 | hmin_index = None |
|
1488 | 1490 | hmax_index = None |
|
1489 | 1491 | |
|
1490 | 1492 | if hmin != None and hmax != None: |
|
1491 | 1493 | indexes = numpy.arange(dataOut.nHeights) |
|
1492 | 1494 | hmin_list = indexes[dataOut.heightList >= hmin] |
|
1493 | 1495 | hmax_list = indexes[dataOut.heightList <= hmax] |
|
1494 | 1496 | |
|
1495 | 1497 | if hmin_list.any(): |
|
1496 | 1498 | hmin_index = hmin_list[0] |
|
1497 | 1499 | |
|
1498 | 1500 | if hmax_list.any(): |
|
1499 | 1501 | hmax_index = hmax_list[-1]+1 |
|
1500 | 1502 | |
|
1501 | 1503 | x = dataOut.getTimeRange() |
|
1502 | 1504 | #y = dataOut.getHeiRange() |
|
1503 | 1505 | |
|
1504 | 1506 | |
|
1505 | 1507 | thisDatetime = dataOut.datatime |
|
1506 | 1508 | |
|
1507 | 1509 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1508 | 1510 | xlabel = "Local Time" |
|
1509 | 1511 | ylabel = "Phase (degrees)" |
|
1510 | 1512 | |
|
1511 | 1513 | update_figfile = False |
|
1512 | 1514 | |
|
1513 | 1515 | nplots = len(pairsIndexList) |
|
1514 | 1516 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1515 | 1517 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1516 | 1518 | for i in range(nplots): |
|
1517 | 1519 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1518 | 1520 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) |
|
1519 | 1521 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) |
|
1520 | 1522 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) |
|
1521 | 1523 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1522 | 1524 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1523 | 1525 | |
|
1524 | 1526 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1525 | 1527 | #print phase[dataOut.beacon_heiIndexList] |
|
1526 | 1528 | |
|
1527 | 1529 | if dataOut.beacon_heiIndexList: |
|
1528 | 1530 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1529 | 1531 | else: |
|
1530 | 1532 | phase_beacon[i] = numpy.average(phase) |
|
1531 | 1533 | |
|
1532 | 1534 | if not self.isConfig: |
|
1533 | 1535 | |
|
1534 | 1536 | nplots = len(pairsIndexList) |
|
1535 | 1537 | |
|
1536 | 1538 | self.setup(id=id, |
|
1537 | 1539 | nplots=nplots, |
|
1538 | 1540 | wintitle=wintitle, |
|
1539 | 1541 | showprofile=showprofile, |
|
1540 | 1542 | show=show) |
|
1541 | 1543 | |
|
1542 | 1544 | if timerange != None: |
|
1543 | 1545 | self.timerange = timerange |
|
1544 | 1546 | |
|
1545 | 1547 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1546 | 1548 | |
|
1547 | 1549 | if ymin == None: ymin = 0 |
|
1548 | 1550 | if ymax == None: ymax = 360 |
|
1549 | 1551 | |
|
1550 | 1552 | self.FTP_WEI = ftp_wei |
|
1551 | 1553 | self.EXP_CODE = exp_code |
|
1552 | 1554 | self.SUB_EXP_CODE = sub_exp_code |
|
1553 | 1555 | self.PLOT_POS = plot_pos |
|
1554 | 1556 | |
|
1555 | 1557 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1556 | 1558 | self.isConfig = True |
|
1557 | 1559 | self.figfile = figfile |
|
1558 | 1560 | self.xdata = numpy.array([]) |
|
1559 | 1561 | self.ydata = numpy.array([]) |
|
1560 | 1562 | |
|
1561 | 1563 | update_figfile = True |
|
1562 | 1564 | |
|
1563 | 1565 | #open file beacon phase |
|
1564 | 1566 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1565 | 1567 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1566 | 1568 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1567 | 1569 | #self.save_phase(self.filename_phase) |
|
1568 | 1570 | |
|
1569 | 1571 | |
|
1570 | 1572 | #store data beacon phase |
|
1571 | 1573 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1572 | 1574 | |
|
1573 | 1575 | self.setWinTitle(title) |
|
1574 | 1576 | |
|
1575 | 1577 | |
|
1576 | 1578 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1577 | 1579 | |
|
1578 | 1580 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1579 | 1581 | |
|
1580 | 1582 | axes = self.axesList[0] |
|
1581 | 1583 | |
|
1582 | 1584 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1583 | 1585 | |
|
1584 | 1586 | if len(self.ydata)==0: |
|
1585 | 1587 | self.ydata = phase_beacon.reshape(-1,1) |
|
1586 | 1588 | else: |
|
1587 | 1589 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1588 | 1590 | |
|
1589 | 1591 | |
|
1590 | 1592 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1591 | 1593 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1592 | 1594 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1593 | 1595 | XAxisAsTime=True, grid='both' |
|
1594 | 1596 | ) |
|
1595 | 1597 | |
|
1596 | 1598 | self.draw() |
|
1597 | 1599 | |
|
1598 | 1600 | if dataOut.ltctime >= self.xmax: |
|
1599 | 1601 | self.counter_imagwr = wr_period |
|
1600 | 1602 | self.isConfig = False |
|
1601 | 1603 | update_figfile = True |
|
1602 | 1604 | |
|
1603 | 1605 | self.save(figpath=figpath, |
|
1604 | 1606 | figfile=figfile, |
|
1605 | 1607 | save=save, |
|
1606 | 1608 | ftp=ftp, |
|
1607 | 1609 | wr_period=wr_period, |
|
1608 | 1610 | thisDatetime=thisDatetime, |
|
1609 | 1611 | update_figfile=update_figfile) |
@@ -1,481 +1,481 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import sys |
|
4 | 4 | import matplotlib |
|
5 | 5 | |
|
6 | 6 | if 'linux' in sys.platform: |
|
7 | 7 | matplotlib.use("TKAgg") |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 | 10 | matplotlib.use('TKAgg') |
|
11 | 11 | #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
|
14 | 14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
15 | 15 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
16 | 16 | |
|
17 | 17 | ########################################### |
|
18 | 18 | #Actualizacion de las funciones del driver |
|
19 | 19 | ########################################### |
|
20 | 20 | |
|
21 | 21 | # create jro colormap |
|
22 | 22 | |
|
23 | 23 | jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90] |
|
24 | 24 | blu_values = matplotlib.pyplot.get_cmap("seismic_r", 20)(numpy.arange(20))[10:15] |
|
25 | 25 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values))) |
|
26 | 26 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
27 | 27 | |
|
28 | 28 | def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80): |
|
29 | 29 | |
|
30 | 30 | matplotlib.pyplot.ioff() |
|
31 | 31 | |
|
32 | 32 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=(1.0*width/dpi, 1.0*height/dpi)) |
|
33 | 33 | fig.canvas.manager.set_window_title(wintitle) |
|
34 | 34 | # fig.canvas.manager.resize(width, height) |
|
35 | 35 | matplotlib.pyplot.ion() |
|
36 | 36 | |
|
37 | 37 | if show: |
|
38 | 38 | matplotlib.pyplot.show() |
|
39 | 39 | |
|
40 | 40 | return fig |
|
41 | 41 | |
|
42 | 42 | def closeFigure(show=False, fig=None): |
|
43 | 43 | |
|
44 | 44 | # matplotlib.pyplot.ioff() |
|
45 | 45 | # matplotlib.pyplot.pause(0) |
|
46 | 46 | |
|
47 | 47 | if show: |
|
48 | 48 | matplotlib.pyplot.show() |
|
49 | 49 | |
|
50 | 50 | if fig != None: |
|
51 | 51 | matplotlib.pyplot.close(fig) |
|
52 | 52 | # matplotlib.pyplot.pause(0) |
|
53 | 53 | # matplotlib.pyplot.ion() |
|
54 | 54 | |
|
55 | 55 | return |
|
56 | 56 | |
|
57 | 57 | matplotlib.pyplot.close("all") |
|
58 | 58 | # matplotlib.pyplot.pause(0) |
|
59 | 59 | # matplotlib.pyplot.ion() |
|
60 | 60 | |
|
61 | 61 | return |
|
62 | 62 | |
|
63 | 63 | def saveFigure(fig, filename): |
|
64 | 64 | |
|
65 | 65 | # matplotlib.pyplot.ioff() |
|
66 | 66 | fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi) |
|
67 | 67 | # matplotlib.pyplot.ion() |
|
68 | 68 | |
|
69 | 69 | def clearFigure(fig): |
|
70 | 70 | |
|
71 | 71 | fig.clf() |
|
72 | 72 | |
|
73 | 73 | def setWinTitle(fig, title): |
|
74 | 74 | |
|
75 | 75 | fig.canvas.manager.set_window_title(title) |
|
76 | 76 | |
|
77 | 77 | def setTitle(fig, title): |
|
78 | 78 | |
|
79 | 79 | fig.suptitle(title) |
|
80 | 80 | |
|
81 | 81 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): |
|
82 | 82 | |
|
83 | 83 | matplotlib.pyplot.ioff() |
|
84 | 84 | matplotlib.pyplot.figure(fig.number) |
|
85 | 85 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
86 | 86 | (xpos, ypos), |
|
87 | 87 | colspan=colspan, |
|
88 | 88 | rowspan=rowspan, |
|
89 | 89 | polar=polar) |
|
90 | 90 | |
|
91 | 91 | axes.grid(True) |
|
92 | 92 | |
|
93 | 93 | matplotlib.pyplot.ion() |
|
94 | 94 | return axes |
|
95 | 95 | |
|
96 | 96 | def setAxesText(ax, text): |
|
97 | 97 | |
|
98 | 98 | ax.annotate(text, |
|
99 | 99 | xy = (.1, .99), |
|
100 | 100 | xycoords = 'figure fraction', |
|
101 | 101 | horizontalalignment = 'left', |
|
102 | 102 | verticalalignment = 'top', |
|
103 | 103 | fontsize = 10) |
|
104 | 104 | |
|
105 | 105 | def printLabels(ax, xlabel, ylabel, title): |
|
106 | 106 | |
|
107 | 107 | ax.set_xlabel(xlabel, size=11) |
|
108 | 108 | ax.set_ylabel(ylabel, size=11) |
|
109 | 109 | ax.set_title(title, size=8) |
|
110 | 110 | |
|
111 | 111 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
112 | 112 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
113 | 113 | nxticks=4, nyticks=10, |
|
114 | 114 | grid=None,color='blue'): |
|
115 | 115 | |
|
116 | 116 | """ |
|
117 | 117 | |
|
118 | 118 | Input: |
|
119 | 119 | grid : None, 'both', 'x', 'y' |
|
120 | 120 | """ |
|
121 | 121 | |
|
122 | 122 | matplotlib.pyplot.ioff() |
|
123 | 123 | |
|
124 | 124 | ax.set_xlim([xmin,xmax]) |
|
125 | 125 | ax.set_ylim([ymin,ymax]) |
|
126 | 126 | |
|
127 | 127 | printLabels(ax, xlabel, ylabel, title) |
|
128 | 128 | |
|
129 | 129 | ###################################################### |
|
130 | 130 | if (xmax-xmin)<=1: |
|
131 | 131 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
132 | 132 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
133 | 133 | ax.set_xticks(xtickspos) |
|
134 | 134 | else: |
|
135 | 135 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
136 | 136 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
137 | 137 | ax.set_xticks(xtickspos) |
|
138 | 138 | |
|
139 | 139 | for tick in ax.get_xticklabels(): |
|
140 | 140 | tick.set_visible(xtick_visible) |
|
141 | 141 | |
|
142 | 142 | for tick in ax.xaxis.get_major_ticks(): |
|
143 | 143 | tick.label.set_fontsize(ticksize) |
|
144 | 144 | |
|
145 | 145 | ###################################################### |
|
146 | 146 | for tick in ax.get_yticklabels(): |
|
147 | 147 | tick.set_visible(ytick_visible) |
|
148 | 148 | |
|
149 | 149 | for tick in ax.yaxis.get_major_ticks(): |
|
150 | 150 | tick.label.set_fontsize(ticksize) |
|
151 | 151 | |
|
152 | 152 | ax.plot(x, y, color=color) |
|
153 | 153 | iplot = ax.lines[-1] |
|
154 | 154 | |
|
155 | 155 | ###################################################### |
|
156 | 156 | if '0.' in matplotlib.__version__[0:2]: |
|
157 | 157 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
158 | 158 | return iplot |
|
159 | 159 | |
|
160 | 160 | if '1.0.' in matplotlib.__version__[0:4]: |
|
161 | 161 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
162 | 162 | return iplot |
|
163 | 163 | |
|
164 | 164 | if grid != None: |
|
165 | 165 | ax.grid(b=True, which='major', axis=grid) |
|
166 | 166 | |
|
167 | 167 | matplotlib.pyplot.tight_layout() |
|
168 | 168 | |
|
169 | 169 | matplotlib.pyplot.ion() |
|
170 | 170 | |
|
171 | 171 | return iplot |
|
172 | 172 | |
|
173 | 173 | def set_linedata(ax, x, y, idline): |
|
174 | 174 | |
|
175 | 175 | ax.lines[idline].set_data(x,y) |
|
176 | 176 | |
|
177 | 177 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
178 | 178 | |
|
179 |
ax = iplot. |
|
|
179 | ax = iplot.axes | |
|
180 | 180 | |
|
181 | 181 | printLabels(ax, xlabel, ylabel, title) |
|
182 | 182 | |
|
183 | 183 | set_linedata(ax, x, y, idline=0) |
|
184 | 184 | |
|
185 | 185 | def addpline(ax, x, y, color, linestyle, lw): |
|
186 | 186 | |
|
187 | 187 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
188 | 188 | |
|
189 | 189 | |
|
190 | 190 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
191 | 191 | xlabel='', ylabel='', title='', ticksize = 9, |
|
192 | 192 | colormap='jet',cblabel='', cbsize="5%", |
|
193 | 193 | XAxisAsTime=False): |
|
194 | 194 | |
|
195 | 195 | matplotlib.pyplot.ioff() |
|
196 | 196 | |
|
197 | 197 | divider = make_axes_locatable(ax) |
|
198 | 198 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
199 | 199 | fig = ax.get_figure() |
|
200 | 200 | fig.add_axes(ax_cb) |
|
201 | 201 | |
|
202 | 202 | ax.set_xlim([xmin,xmax]) |
|
203 | 203 | ax.set_ylim([ymin,ymax]) |
|
204 | 204 | |
|
205 | 205 | printLabels(ax, xlabel, ylabel, title) |
|
206 | 206 | |
|
207 | 207 | z = numpy.ma.masked_invalid(z) |
|
208 | 208 | cmap=matplotlib.pyplot.get_cmap(colormap) |
|
209 | 209 | cmap.set_bad('white',1.) |
|
210 | 210 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap) |
|
211 | 211 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
212 | 212 | cb.set_label(cblabel) |
|
213 | 213 | |
|
214 | 214 | # for tl in ax_cb.get_yticklabels(): |
|
215 | 215 | # tl.set_visible(True) |
|
216 | 216 | |
|
217 | 217 | for tick in ax.yaxis.get_major_ticks(): |
|
218 | 218 | tick.label.set_fontsize(ticksize) |
|
219 | 219 | |
|
220 | 220 | for tick in ax.xaxis.get_major_ticks(): |
|
221 | 221 | tick.label.set_fontsize(ticksize) |
|
222 | 222 | |
|
223 | 223 | for tick in cb.ax.get_yticklabels(): |
|
224 | 224 | tick.set_fontsize(ticksize) |
|
225 | 225 | |
|
226 | 226 | ax_cb.yaxis.tick_right() |
|
227 | 227 | |
|
228 | 228 | if '0.' in matplotlib.__version__[0:2]: |
|
229 | 229 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
230 | 230 | return imesh |
|
231 | 231 | |
|
232 | 232 | if '1.0.' in matplotlib.__version__[0:4]: |
|
233 | 233 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
234 | 234 | return imesh |
|
235 | 235 | |
|
236 | 236 | matplotlib.pyplot.tight_layout() |
|
237 | 237 | |
|
238 | 238 | if XAxisAsTime: |
|
239 | 239 | |
|
240 | 240 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
241 | 241 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
242 | 242 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
243 | 243 | |
|
244 | 244 | ax.grid(True) |
|
245 | 245 | matplotlib.pyplot.ion() |
|
246 | 246 | return imesh |
|
247 | 247 | |
|
248 | 248 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
249 | 249 | |
|
250 | 250 | z = numpy.ma.masked_invalid(z) |
|
251 | 251 | |
|
252 | 252 | cmap=matplotlib.pyplot.get_cmap('jet') |
|
253 | 253 | cmap.set_bad('white',1.) |
|
254 | 254 | |
|
255 | 255 | z = z.T |
|
256 |
ax = imesh. |
|
|
256 | ax = imesh.axes | |
|
257 | 257 | printLabels(ax, xlabel, ylabel, title) |
|
258 | 258 | imesh.set_array(z.ravel()) |
|
259 | 259 | ax.grid(True) |
|
260 | 260 | |
|
261 | 261 | |
|
262 | 262 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
263 | 263 | |
|
264 | 264 | printLabels(ax, xlabel, ylabel, title) |
|
265 | 265 | z = numpy.ma.masked_invalid(z) |
|
266 | 266 | cmap=matplotlib.pyplot.get_cmap(colormap) |
|
267 | 267 | cmap.set_bad('white',1.) |
|
268 | 268 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
269 | 269 | ax.grid(True) |
|
270 | 270 | |
|
271 | 271 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
272 | 272 | |
|
273 | 273 | printLabels(ax, xlabel, ylabel, title) |
|
274 | 274 | |
|
275 | 275 | ax.collections.remove(ax.collections[0]) |
|
276 | 276 | |
|
277 | 277 | z = numpy.ma.masked_invalid(z) |
|
278 | 278 | |
|
279 | 279 | cmap=matplotlib.pyplot.get_cmap(colormap) |
|
280 | 280 | cmap.set_bad('white',1.) |
|
281 | 281 | |
|
282 | 282 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap) |
|
283 | 283 | ax.grid(True) |
|
284 | 284 | |
|
285 | 285 | |
|
286 | 286 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
287 | 287 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
288 | 288 | nxticks=4, nyticks=10, |
|
289 | 289 | grid=None): |
|
290 | 290 | |
|
291 | 291 | """ |
|
292 | 292 | |
|
293 | 293 | Input: |
|
294 | 294 | grid : None, 'both', 'x', 'y' |
|
295 | 295 | """ |
|
296 | 296 | |
|
297 | 297 | matplotlib.pyplot.ioff() |
|
298 | 298 | |
|
299 | 299 | lines = ax.plot(x.T, y) |
|
300 | 300 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
301 | 301 | leg.get_frame().set_alpha(0.5) |
|
302 | 302 | ax.set_xlim([xmin,xmax]) |
|
303 | 303 | ax.set_ylim([ymin,ymax]) |
|
304 | 304 | printLabels(ax, xlabel, ylabel, title) |
|
305 | 305 | |
|
306 | 306 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
307 | 307 | ax.set_xticks(xtickspos) |
|
308 | 308 | |
|
309 | 309 | for tick in ax.get_xticklabels(): |
|
310 | 310 | tick.set_visible(xtick_visible) |
|
311 | 311 | |
|
312 | 312 | for tick in ax.xaxis.get_major_ticks(): |
|
313 | 313 | tick.label.set_fontsize(ticksize) |
|
314 | 314 | |
|
315 | 315 | for tick in ax.get_yticklabels(): |
|
316 | 316 | tick.set_visible(ytick_visible) |
|
317 | 317 | |
|
318 | 318 | for tick in ax.yaxis.get_major_ticks(): |
|
319 | 319 | tick.label.set_fontsize(ticksize) |
|
320 | 320 | |
|
321 | 321 | iplot = ax.lines[-1] |
|
322 | 322 | |
|
323 | 323 | if '0.' in matplotlib.__version__[0:2]: |
|
324 | 324 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
325 | 325 | return iplot |
|
326 | 326 | |
|
327 | 327 | if '1.0.' in matplotlib.__version__[0:4]: |
|
328 | 328 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
329 | 329 | return iplot |
|
330 | 330 | |
|
331 | 331 | if grid != None: |
|
332 | 332 | ax.grid(b=True, which='major', axis=grid) |
|
333 | 333 | |
|
334 | 334 | matplotlib.pyplot.tight_layout() |
|
335 | 335 | |
|
336 | 336 | matplotlib.pyplot.ion() |
|
337 | 337 | |
|
338 | 338 | return iplot |
|
339 | 339 | |
|
340 | 340 | |
|
341 | 341 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
342 | 342 | |
|
343 |
ax = iplot. |
|
|
343 | ax = iplot.axes | |
|
344 | 344 | |
|
345 | 345 | printLabels(ax, xlabel, ylabel, title) |
|
346 | 346 | |
|
347 | 347 | for i in range(len(ax.lines)): |
|
348 | 348 | line = ax.lines[i] |
|
349 | 349 | line.set_data(x[i,:],y) |
|
350 | 350 | |
|
351 | 351 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
352 | 352 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
353 | 353 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
354 | 354 | grid=None, XAxisAsTime=False): |
|
355 | 355 | |
|
356 | 356 | """ |
|
357 | 357 | |
|
358 | 358 | Input: |
|
359 | 359 | grid : None, 'both', 'x', 'y' |
|
360 | 360 | """ |
|
361 | 361 | |
|
362 | 362 | matplotlib.pyplot.ioff() |
|
363 | 363 | |
|
364 | 364 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
365 | 365 | lines = ax.plot(x, y.T) |
|
366 | 366 | # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
367 | 367 | # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
368 | 368 | |
|
369 | 369 | leg = ax.legend(lines, legendlabels, |
|
370 | 370 | loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0) |
|
371 | 371 | |
|
372 | 372 | for label in leg.get_texts(): label.set_fontsize(9) |
|
373 | 373 | |
|
374 | 374 | ax.set_xlim([xmin,xmax]) |
|
375 | 375 | ax.set_ylim([ymin,ymax]) |
|
376 | 376 | printLabels(ax, xlabel, ylabel, title) |
|
377 | 377 | |
|
378 | 378 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
379 | 379 | # ax.set_xticks(xtickspos) |
|
380 | 380 | |
|
381 | 381 | for tick in ax.get_xticklabels(): |
|
382 | 382 | tick.set_visible(xtick_visible) |
|
383 | 383 | |
|
384 | 384 | for tick in ax.xaxis.get_major_ticks(): |
|
385 | 385 | tick.label.set_fontsize(ticksize) |
|
386 | 386 | |
|
387 | 387 | for tick in ax.get_yticklabels(): |
|
388 | 388 | tick.set_visible(ytick_visible) |
|
389 | 389 | |
|
390 | 390 | for tick in ax.yaxis.get_major_ticks(): |
|
391 | 391 | tick.label.set_fontsize(ticksize) |
|
392 | 392 | |
|
393 | 393 | iplot = ax.lines[-1] |
|
394 | 394 | |
|
395 | 395 | if '0.' in matplotlib.__version__[0:2]: |
|
396 | 396 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
397 | 397 | return iplot |
|
398 | 398 | |
|
399 | 399 | if '1.0.' in matplotlib.__version__[0:4]: |
|
400 | 400 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
401 | 401 | return iplot |
|
402 | 402 | |
|
403 | 403 | if grid != None: |
|
404 | 404 | ax.grid(b=True, which='major', axis=grid) |
|
405 | 405 | |
|
406 | 406 | matplotlib.pyplot.tight_layout() |
|
407 | 407 | |
|
408 | 408 | if XAxisAsTime: |
|
409 | 409 | |
|
410 | 410 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
411 | 411 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
412 | 412 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
413 | 413 | |
|
414 | 414 | matplotlib.pyplot.ion() |
|
415 | 415 | |
|
416 | 416 | return iplot |
|
417 | 417 | |
|
418 | 418 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
419 | 419 | |
|
420 |
ax = iplot. |
|
|
420 | ax = iplot.axes | |
|
421 | 421 | printLabels(ax, xlabel, ylabel, title) |
|
422 | 422 | |
|
423 | 423 | for i in range(len(ax.lines)): |
|
424 | 424 | line = ax.lines[i] |
|
425 | 425 | line.set_data(x,y[i,:]) |
|
426 | 426 | |
|
427 | 427 | def createPolar(ax, x, y, |
|
428 | 428 | xlabel='', ylabel='', title='', ticksize = 9, |
|
429 | 429 | colormap='jet',cblabel='', cbsize="5%", |
|
430 | 430 | XAxisAsTime=False): |
|
431 | 431 | |
|
432 | 432 | matplotlib.pyplot.ioff() |
|
433 | 433 | |
|
434 | 434 | ax.plot(x,y,'bo', markersize=5) |
|
435 | 435 | # ax.set_rmax(90) |
|
436 | 436 | ax.set_ylim(0,90) |
|
437 | 437 | ax.set_yticks(numpy.arange(0,90,20)) |
|
438 | 438 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') |
|
439 | 439 | # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11') |
|
440 | 440 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') |
|
441 | 441 | ax.yaxis.labelpad = 230 |
|
442 | 442 | printLabels(ax, xlabel, ylabel, title) |
|
443 | 443 | iplot = ax.lines[-1] |
|
444 | 444 | |
|
445 | 445 | if '0.' in matplotlib.__version__[0:2]: |
|
446 | 446 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
447 | 447 | return iplot |
|
448 | 448 | |
|
449 | 449 | if '1.0.' in matplotlib.__version__[0:4]: |
|
450 | 450 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
451 | 451 | return iplot |
|
452 | 452 | |
|
453 | 453 | # if grid != None: |
|
454 | 454 | # ax.grid(b=True, which='major', axis=grid) |
|
455 | 455 | |
|
456 | 456 | matplotlib.pyplot.tight_layout() |
|
457 | 457 | |
|
458 | 458 | matplotlib.pyplot.ion() |
|
459 | 459 | |
|
460 | 460 | |
|
461 | 461 | return iplot |
|
462 | 462 | |
|
463 | 463 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): |
|
464 | 464 | |
|
465 |
ax = iplot. |
|
|
465 | ax = iplot.axes | |
|
466 | 466 | |
|
467 | 467 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') |
|
468 | 468 | printLabels(ax, xlabel, ylabel, title) |
|
469 | 469 | |
|
470 | 470 | set_linedata(ax, x, y, idline=0) |
|
471 | 471 | |
|
472 | 472 | def draw(fig): |
|
473 | 473 | |
|
474 | 474 | if type(fig) == 'int': |
|
475 | 475 | raise ValueError, "Error drawing: Fig parameter should be a matplotlib figure object figure" |
|
476 | 476 | |
|
477 | 477 | fig.canvas.draw() |
|
478 | 478 | |
|
479 | 479 | def pause(interval=0.000001): |
|
480 | 480 | |
|
481 | 481 | matplotlib.pyplot.pause(interval) |
@@ -1,1090 +1,1091 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time |
|
3 | 3 | import os |
|
4 | 4 | import h5py |
|
5 | 5 | import re |
|
6 | 6 | import datetime |
|
7 | 7 | |
|
8 | 8 | from schainpy.model.data.jrodata import * |
|
9 | 9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
10 | 10 | # from jroIO_base import * |
|
11 | 11 | from schainpy.model.io.jroIO_base import * |
|
12 | 12 | import schainpy |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | class ParamReader(ProcessingUnit): |
|
16 | 16 | ''' |
|
17 | 17 | Reads HDF5 format files |
|
18 | 18 | |
|
19 | 19 | path |
|
20 | 20 | |
|
21 | 21 | startDate |
|
22 | 22 | |
|
23 | 23 | endDate |
|
24 | 24 | |
|
25 | 25 | startTime |
|
26 | 26 | |
|
27 | 27 | endTime |
|
28 | 28 | ''' |
|
29 | 29 | |
|
30 | 30 | ext = ".hdf5" |
|
31 | 31 | |
|
32 | 32 | optchar = "D" |
|
33 | 33 | |
|
34 | 34 | timezone = None |
|
35 | 35 | |
|
36 | 36 | startTime = None |
|
37 | 37 | |
|
38 | 38 | endTime = None |
|
39 | 39 | |
|
40 | 40 | fileIndex = None |
|
41 | 41 | |
|
42 | 42 | utcList = None #To select data in the utctime list |
|
43 | 43 | |
|
44 | 44 | blockList = None #List to blocks to be read from the file |
|
45 | 45 | |
|
46 | 46 | blocksPerFile = None #Number of blocks to be read |
|
47 | 47 | |
|
48 | 48 | blockIndex = None |
|
49 | 49 | |
|
50 | 50 | path = None |
|
51 | 51 | |
|
52 | 52 | #List of Files |
|
53 | 53 | |
|
54 | 54 | filenameList = None |
|
55 | 55 | |
|
56 | 56 | datetimeList = None |
|
57 | 57 | |
|
58 | 58 | #Hdf5 File |
|
59 | 59 | |
|
60 | 60 | listMetaname = None |
|
61 | 61 | |
|
62 | 62 | listMeta = None |
|
63 | 63 | |
|
64 | 64 | listDataname = None |
|
65 | 65 | |
|
66 | 66 | listData = None |
|
67 | 67 | |
|
68 | 68 | listShapes = None |
|
69 | 69 | |
|
70 | 70 | fp = None |
|
71 | 71 | |
|
72 | 72 | #dataOut reconstruction |
|
73 | 73 | |
|
74 | 74 | dataOut = None |
|
75 | 75 | |
|
76 | 76 | |
|
77 | 77 | def __init__(self, **kwargs): |
|
78 | 78 | ProcessingUnit.__init__(self, **kwargs) |
|
79 | 79 | self.dataOut = Parameters() |
|
80 | 80 | return |
|
81 | 81 | |
|
82 | 82 | def setup(self, **kwargs): |
|
83 | 83 | |
|
84 | 84 | path = kwargs['path'] |
|
85 | 85 | startDate = kwargs['startDate'] |
|
86 | 86 | endDate = kwargs['endDate'] |
|
87 | 87 | startTime = kwargs['startTime'] |
|
88 | 88 | endTime = kwargs['endTime'] |
|
89 | 89 | walk = kwargs['walk'] |
|
90 | 90 | if kwargs.has_key('ext'): |
|
91 | 91 | ext = kwargs['ext'] |
|
92 | 92 | else: |
|
93 | 93 | ext = '.hdf5' |
|
94 | 94 | if kwargs.has_key('timezone'): |
|
95 | 95 | self.timezone = kwargs['timezone'] |
|
96 | 96 | else: |
|
97 | 97 | self.timezone = 'lt' |
|
98 | 98 | |
|
99 | 99 | print "[Reading] Searching files in offline mode ..." |
|
100 | 100 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
101 | 101 | startTime=startTime, endTime=endTime, |
|
102 | 102 | ext=ext, walk=walk) |
|
103 | 103 | |
|
104 | 104 | if not(filenameList): |
|
105 | 105 | print "There is no files into the folder: %s"%(path) |
|
106 | 106 | sys.exit(-1) |
|
107 | 107 | |
|
108 | 108 | self.fileIndex = -1 |
|
109 | 109 | self.startTime = startTime |
|
110 | 110 | self.endTime = endTime |
|
111 | 111 | |
|
112 | 112 | self.__readMetadata() |
|
113 | 113 | |
|
114 | 114 | self.__setNextFileOffline() |
|
115 | 115 | |
|
116 | 116 | return |
|
117 | 117 | |
|
118 | 118 | def __searchFilesOffLine(self, |
|
119 | 119 | path, |
|
120 | 120 | startDate=None, |
|
121 | 121 | endDate=None, |
|
122 | 122 | startTime=datetime.time(0,0,0), |
|
123 | 123 | endTime=datetime.time(23,59,59), |
|
124 | 124 | ext='.hdf5', |
|
125 | 125 | walk=True): |
|
126 | 126 | |
|
127 | 127 | expLabel = '' |
|
128 | 128 | self.filenameList = [] |
|
129 | 129 | self.datetimeList = [] |
|
130 | 130 | |
|
131 | 131 | pathList = [] |
|
132 | 132 | |
|
133 | 133 | JRODataObj = JRODataReader() |
|
134 | 134 | dateList, pathList = JRODataObj.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True) |
|
135 | 135 | |
|
136 | 136 | if dateList == []: |
|
137 | 137 | print "[Reading] No *%s files in %s from %s to %s)"%(ext, path, |
|
138 | 138 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
139 | 139 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
140 | 140 | |
|
141 | 141 | return None, None |
|
142 | 142 | |
|
143 | 143 | if len(dateList) > 1: |
|
144 | 144 | print "[Reading] %d days were found in date range: %s - %s" %(len(dateList), startDate, endDate) |
|
145 | 145 | else: |
|
146 | 146 | print "[Reading] data was found for the date %s" %(dateList[0]) |
|
147 | 147 | |
|
148 | 148 | filenameList = [] |
|
149 | 149 | datetimeList = [] |
|
150 | 150 | |
|
151 | 151 | #---------------------------------------------------------------------------------- |
|
152 | 152 | |
|
153 | 153 | for thisPath in pathList: |
|
154 | 154 | # thisPath = pathList[pathDict[file]] |
|
155 | 155 | |
|
156 | 156 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
157 | 157 | fileList.sort() |
|
158 | 158 | |
|
159 | 159 | for file in fileList: |
|
160 | 160 | |
|
161 | 161 | filename = os.path.join(thisPath,file) |
|
162 | 162 | |
|
163 | 163 | if not isFileInDateRange(filename, startDate, endDate): |
|
164 | 164 | continue |
|
165 | 165 | |
|
166 | 166 | thisDatetime = self.__isFileInTimeRange(filename, startDate, endDate, startTime, endTime) |
|
167 | 167 | |
|
168 | 168 | if not(thisDatetime): |
|
169 | 169 | continue |
|
170 | 170 | |
|
171 | 171 | filenameList.append(filename) |
|
172 | 172 | datetimeList.append(thisDatetime) |
|
173 | 173 | |
|
174 | 174 | if not(filenameList): |
|
175 | 175 | print "[Reading] Any file was found int time range %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
176 | 176 | return None, None |
|
177 | 177 | |
|
178 | 178 | print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
179 | 179 | |
|
180 | 180 | |
|
181 | 181 | # for i in range(len(filenameList)): |
|
182 | 182 | # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
183 | 183 | |
|
184 | 184 | self.filenameList = filenameList |
|
185 | 185 | self.datetimeList = datetimeList |
|
186 | 186 | |
|
187 | 187 | return pathList, filenameList |
|
188 | 188 | |
|
189 | 189 | def __isFileInTimeRange(self,filename, startDate, endDate, startTime, endTime): |
|
190 | 190 | |
|
191 | 191 | """ |
|
192 | 192 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
193 | 193 | |
|
194 | 194 | Inputs: |
|
195 | 195 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
196 | 196 | |
|
197 | 197 | startDate : fecha inicial del rango seleccionado en formato datetime.date |
|
198 | 198 | |
|
199 | 199 | endDate : fecha final del rango seleccionado en formato datetime.date |
|
200 | 200 | |
|
201 | 201 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
202 | 202 | |
|
203 | 203 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
204 | 204 | |
|
205 | 205 | Return: |
|
206 | 206 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
207 | 207 | fecha especificado, de lo contrario retorna False. |
|
208 | 208 | |
|
209 | 209 | Excepciones: |
|
210 | 210 | Si el archivo no existe o no puede ser abierto |
|
211 | 211 | Si la cabecera no puede ser leida. |
|
212 | 212 | |
|
213 | 213 | """ |
|
214 | 214 | |
|
215 | 215 | try: |
|
216 | 216 | fp = h5py.File(filename,'r') |
|
217 | 217 | grp1 = fp['Data'] |
|
218 | 218 | |
|
219 | 219 | except IOError: |
|
220 | 220 | traceback.print_exc() |
|
221 | 221 | raise IOError, "The file %s can't be opened" %(filename) |
|
222 | 222 | #chino rata |
|
223 | 223 | #In case has utctime attribute |
|
224 | 224 | grp2 = grp1['utctime'] |
|
225 | 225 | # thisUtcTime = grp2.value[0] - 5*3600 #To convert to local time |
|
226 | 226 | thisUtcTime = grp2.value[0] |
|
227 | 227 | |
|
228 | 228 | fp.close() |
|
229 | 229 | |
|
230 | 230 | if self.timezone == 'lt': |
|
231 | 231 | thisUtcTime -= 5*3600 |
|
232 | 232 | |
|
233 | 233 | thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600) |
|
234 | 234 | # thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0]) |
|
235 | 235 | thisDate = thisDatetime.date() |
|
236 | 236 | thisTime = thisDatetime.time() |
|
237 | 237 | |
|
238 | 238 | startUtcTime = (datetime.datetime.combine(thisDate,startTime)- datetime.datetime(1970, 1, 1)).total_seconds() |
|
239 | 239 | endUtcTime = (datetime.datetime.combine(thisDate,endTime)- datetime.datetime(1970, 1, 1)).total_seconds() |
|
240 | 240 | |
|
241 | 241 | #General case |
|
242 | 242 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o |
|
243 | 243 | #-----------o----------------------------o----------- |
|
244 | 244 | # startTime endTime |
|
245 | 245 | |
|
246 | 246 | if endTime >= startTime: |
|
247 | 247 | thisUtcLog = numpy.logical_and(thisUtcTime > startUtcTime, thisUtcTime < endUtcTime) |
|
248 | 248 | if numpy.any(thisUtcLog): #If there is one block between the hours mentioned |
|
249 | 249 | return thisDatetime |
|
250 | 250 | return None |
|
251 | 251 | |
|
252 | 252 | #If endTime < startTime then endTime belongs to the next day |
|
253 | 253 | #<<<<<<<<<<<o o>>>>>>>>>>> |
|
254 | 254 | #-----------o----------------------------o----------- |
|
255 | 255 | # endTime startTime |
|
256 | 256 | |
|
257 | 257 | if (thisDate == startDate) and numpy.all(thisUtcTime < startUtcTime): |
|
258 | 258 | return None |
|
259 | 259 | |
|
260 | 260 | if (thisDate == endDate) and numpy.all(thisUtcTime > endUtcTime): |
|
261 | 261 | return None |
|
262 | 262 | |
|
263 | 263 | if numpy.all(thisUtcTime < startUtcTime) and numpy.all(thisUtcTime > endUtcTime): |
|
264 | 264 | return None |
|
265 | 265 | |
|
266 | 266 | return thisDatetime |
|
267 | 267 | |
|
268 | 268 | def __setNextFileOffline(self): |
|
269 | 269 | |
|
270 | 270 | self.fileIndex += 1 |
|
271 | 271 | idFile = self.fileIndex |
|
272 | 272 | |
|
273 | 273 | if not(idFile < len(self.filenameList)): |
|
274 | 274 | print "No more Files" |
|
275 | 275 | return 0 |
|
276 | 276 | |
|
277 | 277 | filename = self.filenameList[idFile] |
|
278 | 278 | |
|
279 | 279 | filePointer = h5py.File(filename,'r') |
|
280 | 280 | |
|
281 | 281 | self.filename = filename |
|
282 | 282 | |
|
283 | 283 | self.fp = filePointer |
|
284 | 284 | |
|
285 | 285 | print "Setting the file: %s"%self.filename |
|
286 | 286 | |
|
287 | 287 | # self.__readMetadata() |
|
288 | 288 | self.__setBlockList() |
|
289 | 289 | self.__readData() |
|
290 | 290 | # self.nRecords = self.fp['Data'].attrs['blocksPerFile'] |
|
291 | 291 | # self.nRecords = self.fp['Data'].attrs['nRecords'] |
|
292 | 292 | self.blockIndex = 0 |
|
293 | 293 | return 1 |
|
294 | 294 | |
|
295 | 295 | def __setBlockList(self): |
|
296 | 296 | ''' |
|
297 | 297 | Selects the data within the times defined |
|
298 | 298 | |
|
299 | 299 | self.fp |
|
300 | 300 | self.startTime |
|
301 | 301 | self.endTime |
|
302 | 302 | |
|
303 | 303 | self.blockList |
|
304 | 304 | self.blocksPerFile |
|
305 | 305 | |
|
306 | 306 | ''' |
|
307 | 307 | fp = self.fp |
|
308 | 308 | startTime = self.startTime |
|
309 | 309 | endTime = self.endTime |
|
310 | 310 | |
|
311 | 311 | grp = fp['Data'] |
|
312 | 312 | thisUtcTime = grp['utctime'].value.astype(numpy.float)[0] |
|
313 | 313 | |
|
314 | 314 | #ERROOOOR |
|
315 | 315 | if self.timezone == 'lt': |
|
316 | 316 | thisUtcTime -= 5*3600 |
|
317 | 317 | |
|
318 | 318 | thisDatetime = datetime.datetime.fromtimestamp(thisUtcTime[0] + 5*3600) |
|
319 | 319 | |
|
320 | 320 | thisDate = thisDatetime.date() |
|
321 | 321 | thisTime = thisDatetime.time() |
|
322 | 322 | |
|
323 | 323 | startUtcTime = (datetime.datetime.combine(thisDate,startTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
324 | 324 | endUtcTime = (datetime.datetime.combine(thisDate,endTime) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
325 | 325 | |
|
326 | 326 | ind = numpy.where(numpy.logical_and(thisUtcTime >= startUtcTime, thisUtcTime < endUtcTime))[0] |
|
327 | 327 | |
|
328 | 328 | self.blockList = ind |
|
329 | 329 | self.blocksPerFile = len(ind) |
|
330 | 330 | |
|
331 | 331 | return |
|
332 | 332 | |
|
333 | 333 | def __readMetadata(self): |
|
334 | 334 | ''' |
|
335 | 335 | Reads Metadata |
|
336 | 336 | |
|
337 | 337 | self.pathMeta |
|
338 | 338 | |
|
339 | 339 | self.listShapes |
|
340 | 340 | self.listMetaname |
|
341 | 341 | self.listMeta |
|
342 | 342 | |
|
343 | 343 | ''' |
|
344 | 344 | |
|
345 | 345 | # grp = self.fp['Data'] |
|
346 | 346 | # pathMeta = os.path.join(self.path, grp.attrs['metadata']) |
|
347 | 347 | # |
|
348 | 348 | # if pathMeta == self.pathMeta: |
|
349 | 349 | # return |
|
350 | 350 | # else: |
|
351 | 351 | # self.pathMeta = pathMeta |
|
352 | 352 | # |
|
353 | 353 | # filePointer = h5py.File(self.pathMeta,'r') |
|
354 | 354 | # groupPointer = filePointer['Metadata'] |
|
355 | 355 | |
|
356 | 356 | filename = self.filenameList[0] |
|
357 | 357 | |
|
358 | 358 | fp = h5py.File(filename,'r') |
|
359 | 359 | |
|
360 | 360 | gp = fp['Metadata'] |
|
361 | 361 | |
|
362 | 362 | listMetaname = [] |
|
363 | 363 | listMetadata = [] |
|
364 | 364 | for item in gp.items(): |
|
365 | 365 | name = item[0] |
|
366 | 366 | |
|
367 | 367 | if name=='array dimensions': |
|
368 | 368 | table = gp[name][:] |
|
369 | 369 | listShapes = {} |
|
370 | 370 | for shapes in table: |
|
371 | 371 | listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4],shapes[5]]) |
|
372 | 372 | else: |
|
373 | 373 | data = gp[name].value |
|
374 | 374 | listMetaname.append(name) |
|
375 | 375 | listMetadata.append(data) |
|
376 | 376 | |
|
377 | 377 | # if name=='type': |
|
378 | 378 | # self.__initDataOut(data) |
|
379 | 379 | |
|
380 | 380 | self.listShapes = listShapes |
|
381 | 381 | self.listMetaname = listMetaname |
|
382 | 382 | self.listMeta = listMetadata |
|
383 | 383 | |
|
384 | 384 | fp.close() |
|
385 | 385 | return |
|
386 | 386 | |
|
387 | 387 | def __readData(self): |
|
388 | 388 | grp = self.fp['Data'] |
|
389 | 389 | listdataname = [] |
|
390 | 390 | listdata = [] |
|
391 | 391 | |
|
392 | 392 | for item in grp.items(): |
|
393 | 393 | name = item[0] |
|
394 | 394 | listdataname.append(name) |
|
395 | 395 | |
|
396 | 396 | array = self.__setDataArray(grp[name],self.listShapes[name]) |
|
397 | 397 | listdata.append(array) |
|
398 | 398 | |
|
399 | 399 | self.listDataname = listdataname |
|
400 | 400 | self.listData = listdata |
|
401 | 401 | return |
|
402 | 402 | |
|
403 | 403 | def __setDataArray(self, dataset, shapes): |
|
404 | 404 | |
|
405 | 405 | nDims = shapes[0] |
|
406 | 406 | |
|
407 | 407 | nDim2 = shapes[1] #Dimension 0 |
|
408 | 408 | |
|
409 | 409 | nDim1 = shapes[2] #Dimension 1, number of Points or Parameters |
|
410 | 410 | |
|
411 | 411 | nDim0 = shapes[3] #Dimension 2, number of samples or ranges |
|
412 | 412 | |
|
413 | 413 | mode = shapes[4] #Mode of storing |
|
414 | 414 | |
|
415 | 415 | blockList = self.blockList |
|
416 | 416 | |
|
417 | 417 | blocksPerFile = self.blocksPerFile |
|
418 | 418 | |
|
419 | 419 | #Depending on what mode the data was stored |
|
420 | 420 | if mode == 0: #Divided in channels |
|
421 | 421 | arrayData = dataset.value.astype(numpy.float)[0][blockList] |
|
422 | 422 | if mode == 1: #Divided in parameter |
|
423 | 423 | strds = 'table' |
|
424 | 424 | nDatas = nDim1 |
|
425 | 425 | newShapes = (blocksPerFile,nDim2,nDim0) |
|
426 | 426 | elif mode==2: #Concatenated in a table |
|
427 | 427 | strds = 'table0' |
|
428 | 428 | arrayData = dataset[strds].value |
|
429 | 429 | #Selecting part of the dataset |
|
430 | 430 | utctime = arrayData[:,0] |
|
431 | 431 | u, indices = numpy.unique(utctime, return_index=True) |
|
432 | 432 | |
|
433 | 433 | if blockList.size != indices.size: |
|
434 | 434 | indMin = indices[blockList[0]] |
|
435 | 435 | if blockList[1] + 1 >= indices.size: |
|
436 | 436 | arrayData = arrayData[indMin:,:] |
|
437 | 437 | else: |
|
438 | 438 | indMax = indices[blockList[1] + 1] |
|
439 | 439 | arrayData = arrayData[indMin:indMax,:] |
|
440 | 440 | return arrayData |
|
441 | 441 | |
|
442 | 442 | # One dimension |
|
443 | 443 | if nDims == 0: |
|
444 | 444 | arrayData = dataset.value.astype(numpy.float)[0][blockList] |
|
445 | 445 | |
|
446 | 446 | # Two dimensions |
|
447 | 447 | elif nDims == 2: |
|
448 | 448 | arrayData = numpy.zeros((blocksPerFile,nDim1,nDim0)) |
|
449 | 449 | newShapes = (blocksPerFile,nDim0) |
|
450 | 450 | nDatas = nDim1 |
|
451 | 451 | |
|
452 | 452 | for i in range(nDatas): |
|
453 | 453 | data = dataset[strds + str(i)].value |
|
454 | 454 | arrayData[:,i,:] = data[blockList,:] |
|
455 | 455 | |
|
456 | 456 | # Three dimensions |
|
457 | 457 | else: |
|
458 | 458 | arrayData = numpy.zeros((blocksPerFile,nDim2,nDim1,nDim0)) |
|
459 | 459 | for i in range(nDatas): |
|
460 | 460 | |
|
461 | 461 | data = dataset[strds + str(i)].value |
|
462 | 462 | |
|
463 | 463 | for b in range(blockList.size): |
|
464 | 464 | arrayData[b,:,i,:] = data[:,:,blockList[b]] |
|
465 | 465 | |
|
466 | 466 | return arrayData |
|
467 | 467 | |
|
468 | 468 | def __setDataOut(self): |
|
469 | 469 | listMeta = self.listMeta |
|
470 | 470 | listMetaname = self.listMetaname |
|
471 | 471 | listDataname = self.listDataname |
|
472 | 472 | listData = self.listData |
|
473 | 473 | listShapes = self.listShapes |
|
474 | 474 | |
|
475 | 475 | blockIndex = self.blockIndex |
|
476 | 476 | # blockList = self.blockList |
|
477 | 477 | |
|
478 | 478 | for i in range(len(listMeta)): |
|
479 | 479 | setattr(self.dataOut,listMetaname[i],listMeta[i]) |
|
480 | 480 | |
|
481 | 481 | for j in range(len(listData)): |
|
482 | 482 | nShapes = listShapes[listDataname[j]][0] |
|
483 | 483 | mode = listShapes[listDataname[j]][4] |
|
484 | 484 | if nShapes == 1: |
|
485 | 485 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex]) |
|
486 | 486 | elif nShapes > 1: |
|
487 | 487 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex,:]) |
|
488 | 488 | elif mode==0: |
|
489 | 489 | setattr(self.dataOut,listDataname[j],listData[j][blockIndex]) |
|
490 | 490 | #Mode Meteors |
|
491 | 491 | elif mode ==2: |
|
492 | 492 | selectedData = self.__selectDataMode2(listData[j], blockIndex) |
|
493 | 493 | setattr(self.dataOut, listDataname[j], selectedData) |
|
494 | 494 | return |
|
495 | 495 | |
|
496 | 496 | def __selectDataMode2(self, data, blockIndex): |
|
497 | 497 | utctime = data[:,0] |
|
498 | 498 | aux, indices = numpy.unique(utctime, return_inverse=True) |
|
499 | 499 | selInd = numpy.where(indices == blockIndex)[0] |
|
500 | 500 | selData = data[selInd,:] |
|
501 | 501 | |
|
502 | 502 | return selData |
|
503 | 503 | |
|
504 | 504 | def getData(self): |
|
505 | 505 | |
|
506 | 506 | # if self.flagNoMoreFiles: |
|
507 | 507 | # self.dataOut.flagNoData = True |
|
508 | 508 | # print 'Process finished' |
|
509 | 509 | # return 0 |
|
510 | 510 | # |
|
511 | 511 | if self.blockIndex==self.blocksPerFile: |
|
512 | 512 | if not( self.__setNextFileOffline() ): |
|
513 | 513 | self.dataOut.flagNoData = True |
|
514 | 514 | return 0 |
|
515 | 515 | |
|
516 | 516 | # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
517 | 517 | # self.dataOut.flagNoData = True |
|
518 | 518 | # return 0 |
|
519 | 519 | # self.__readData() |
|
520 | 520 | self.__setDataOut() |
|
521 | 521 | self.dataOut.flagNoData = False |
|
522 | 522 | |
|
523 | 523 | self.blockIndex += 1 |
|
524 | 524 | |
|
525 | 525 | return |
|
526 | 526 | |
|
527 | 527 | def run(self, **kwargs): |
|
528 | 528 | |
|
529 | 529 | if not(self.isConfig): |
|
530 | 530 | self.setup(**kwargs) |
|
531 | 531 | # self.setObjProperties() |
|
532 | 532 | self.isConfig = True |
|
533 | 533 | |
|
534 | 534 | self.getData() |
|
535 | 535 | |
|
536 | 536 | return |
|
537 | 537 | |
|
538 | 538 | class ParamWriter(Operation): |
|
539 | 539 | ''' |
|
540 | 540 | HDF5 Writer, stores parameters data in HDF5 format files |
|
541 | 541 | |
|
542 | 542 | path: path where the files will be stored |
|
543 | 543 | |
|
544 | 544 | blocksPerFile: number of blocks that will be saved in per HDF5 format file |
|
545 | 545 | |
|
546 | 546 | mode: selects the data stacking mode: '0' channels, '1' parameters, '3' table (for meteors) |
|
547 | 547 | |
|
548 | 548 | metadataList: list of attributes that will be stored as metadata |
|
549 | 549 | |
|
550 | 550 | dataList: list of attributes that will be stores as data |
|
551 | 551 | |
|
552 | 552 | ''' |
|
553 | 553 | |
|
554 | 554 | |
|
555 | 555 | ext = ".hdf5" |
|
556 | 556 | |
|
557 | 557 | optchar = "D" |
|
558 | 558 | |
|
559 | 559 | metaoptchar = "M" |
|
560 | 560 | |
|
561 | 561 | metaFile = None |
|
562 | 562 | |
|
563 | 563 | filename = None |
|
564 | 564 | |
|
565 | 565 | path = None |
|
566 | 566 | |
|
567 | 567 | setFile = None |
|
568 | 568 | |
|
569 | 569 | fp = None |
|
570 | 570 | |
|
571 | 571 | grp = None |
|
572 | 572 | |
|
573 | 573 | ds = None |
|
574 | 574 | |
|
575 | 575 | firsttime = True |
|
576 | 576 | |
|
577 | 577 | #Configurations |
|
578 | 578 | |
|
579 | 579 | blocksPerFile = None |
|
580 | 580 | |
|
581 | 581 | blockIndex = None |
|
582 | 582 | |
|
583 | 583 | dataOut = None |
|
584 | 584 | |
|
585 | 585 | #Data Arrays |
|
586 | 586 | |
|
587 | 587 | dataList = None |
|
588 | 588 | |
|
589 | 589 | metadataList = None |
|
590 | 590 | |
|
591 | 591 | # arrayDim = None |
|
592 | 592 | |
|
593 | 593 | dsList = None #List of dictionaries with dataset properties |
|
594 | 594 | |
|
595 | 595 | tableDim = None |
|
596 | 596 | |
|
597 | 597 | # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')] |
|
598 | 598 | |
|
599 | 599 | dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')] |
|
600 | 600 | |
|
601 | 601 | currentDay = None |
|
602 | 602 | |
|
603 | 603 | lastTime = None |
|
604 | 604 | |
|
605 | 605 | def __init__(self, **kwargs): |
|
606 | 606 | Operation.__init__(self, **kwargs) |
|
607 | 607 | self.isConfig = False |
|
608 | 608 | return |
|
609 | 609 | |
|
610 | 610 | def setup(self, dataOut, **kwargs): |
|
611 | 611 | |
|
612 | 612 | self.path = kwargs['path'] |
|
613 | 613 | |
|
614 | 614 | if kwargs.has_key('blocksPerFile'): |
|
615 | 615 | self.blocksPerFile = kwargs['blocksPerFile'] |
|
616 | 616 | else: |
|
617 | 617 | self.blocksPerFile = 10 |
|
618 | 618 | |
|
619 | 619 | self.metadataList = kwargs['metadataList'] |
|
620 | 620 | self.dataList = kwargs['dataList'] |
|
621 | 621 | self.dataOut = dataOut |
|
622 | 622 | |
|
623 | 623 | if kwargs.has_key('mode'): |
|
624 | 624 | mode = kwargs['mode'] |
|
625 | 625 | |
|
626 | 626 | if type(mode) == int: |
|
627 | 627 | mode = numpy.zeros(len(self.dataList)) + mode |
|
628 | 628 | else: |
|
629 | 629 | mode = numpy.ones(len(self.dataList)) |
|
630 | 630 | |
|
631 | 631 | self.mode = mode |
|
632 | 632 | |
|
633 | 633 | arrayDim = numpy.zeros((len(self.dataList),5)) |
|
634 | 634 | |
|
635 | 635 | #Table dimensions |
|
636 | 636 | dtype0 = self.dtype |
|
637 | 637 | tableList = [] |
|
638 | 638 | |
|
639 | 639 | #Dictionary and list of tables |
|
640 | 640 | dsList = [] |
|
641 | 641 | |
|
642 | 642 | for i in range(len(self.dataList)): |
|
643 | 643 | dsDict = {} |
|
644 | 644 | dataAux = getattr(self.dataOut, self.dataList[i]) |
|
645 | 645 | dsDict['variable'] = self.dataList[i] |
|
646 | 646 | #--------------------- Conditionals ------------------------ |
|
647 | 647 | #There is no data |
|
648 | 648 | if dataAux is None: |
|
649 | 649 | return 0 |
|
650 | 650 | |
|
651 | 651 | #Not array, just a number |
|
652 | 652 | #Mode 0 |
|
653 | 653 | if type(dataAux)==float or type(dataAux)==int: |
|
654 | 654 | dsDict['mode'] = 0 |
|
655 | 655 | dsDict['nDim'] = 0 |
|
656 | 656 | arrayDim[i,0] = 0 |
|
657 | 657 | dsList.append(dsDict) |
|
658 | 658 | |
|
659 | 659 | #Mode 2: meteors |
|
660 | 660 | elif mode[i] == 2: |
|
661 | 661 | # dsDict['nDim'] = 0 |
|
662 | 662 | dsDict['dsName'] = 'table0' |
|
663 | 663 | dsDict['mode'] = 2 # Mode meteors |
|
664 | 664 | dsDict['shape'] = dataAux.shape[-1] |
|
665 | 665 | dsDict['nDim'] = 0 |
|
666 | 666 | dsDict['dsNumber'] = 1 |
|
667 | 667 | |
|
668 | 668 | arrayDim[i,3] = dataAux.shape[-1] |
|
669 | 669 | arrayDim[i,4] = mode[i] #Mode the data was stored |
|
670 | 670 | |
|
671 | 671 | dsList.append(dsDict) |
|
672 | 672 | |
|
673 | 673 | #Mode 1 |
|
674 | 674 | else: |
|
675 | 675 | arrayDim0 = dataAux.shape #Data dimensions |
|
676 | 676 | arrayDim[i,0] = len(arrayDim0) #Number of array dimensions |
|
677 | 677 | arrayDim[i,4] = mode[i] #Mode the data was stored |
|
678 | 678 | |
|
679 | 679 | strtable = 'table' |
|
680 | 680 | dsDict['mode'] = 1 # Mode parameters |
|
681 | 681 | |
|
682 | 682 | # Three-dimension arrays |
|
683 | 683 | if len(arrayDim0) == 3: |
|
684 | 684 | arrayDim[i,1:-1] = numpy.array(arrayDim0) |
|
685 | 685 | nTables = int(arrayDim[i,2]) |
|
686 | 686 | dsDict['dsNumber'] = nTables |
|
687 | 687 | dsDict['shape'] = arrayDim[i,2:4] |
|
688 | 688 | dsDict['nDim'] = 3 |
|
689 | 689 | |
|
690 | 690 | for j in range(nTables): |
|
691 | 691 | dsDict = dsDict.copy() |
|
692 | 692 | dsDict['dsName'] = strtable + str(j) |
|
693 | 693 | dsList.append(dsDict) |
|
694 | 694 | |
|
695 | 695 | # Two-dimension arrays |
|
696 | 696 | elif len(arrayDim0) == 2: |
|
697 | 697 | arrayDim[i,2:-1] = numpy.array(arrayDim0) |
|
698 | 698 | nTables = int(arrayDim[i,2]) |
|
699 | 699 | dsDict['dsNumber'] = nTables |
|
700 | 700 | dsDict['shape'] = arrayDim[i,3] |
|
701 | 701 | dsDict['nDim'] = 2 |
|
702 | 702 | |
|
703 | 703 | for j in range(nTables): |
|
704 | 704 | dsDict = dsDict.copy() |
|
705 | 705 | dsDict['dsName'] = strtable + str(j) |
|
706 | 706 | dsList.append(dsDict) |
|
707 | 707 | |
|
708 | 708 | # One-dimension arrays |
|
709 | 709 | elif len(arrayDim0) == 1: |
|
710 | 710 | arrayDim[i,3] = arrayDim0[0] |
|
711 | 711 | dsDict['shape'] = arrayDim0[0] |
|
712 | 712 | dsDict['dsNumber'] = 1 |
|
713 | 713 | dsDict['dsName'] = strtable + str(0) |
|
714 | 714 | dsDict['nDim'] = 1 |
|
715 | 715 | dsList.append(dsDict) |
|
716 | 716 | |
|
717 | 717 | table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0) |
|
718 | 718 | tableList.append(table) |
|
719 | 719 | |
|
720 | 720 | # self.arrayDim = arrayDim |
|
721 | 721 | self.dsList = dsList |
|
722 | 722 | self.tableDim = numpy.array(tableList, dtype = dtype0) |
|
723 | 723 | self.blockIndex = 0 |
|
724 | 724 | |
|
725 | 725 | timeTuple = time.localtime(dataOut.utctime) |
|
726 | 726 | self.currentDay = timeTuple.tm_yday |
|
727 | 727 | return 1 |
|
728 | 728 | |
|
729 | 729 | def putMetadata(self): |
|
730 | 730 | |
|
731 | 731 | fp = self.createMetadataFile() |
|
732 | 732 | self.writeMetadata(fp) |
|
733 | 733 | fp.close() |
|
734 | 734 | return |
|
735 | 735 | |
|
736 | 736 | def createMetadataFile(self): |
|
737 | 737 | ext = self.ext |
|
738 | 738 | path = self.path |
|
739 | 739 | setFile = self.setFile |
|
740 | 740 | |
|
741 | 741 | timeTuple = time.localtime(self.dataOut.utctime) |
|
742 | 742 | |
|
743 | 743 | subfolder = '' |
|
744 | 744 | fullpath = os.path.join( path, subfolder ) |
|
745 | 745 | |
|
746 | 746 | if not( os.path.exists(fullpath) ): |
|
747 | 747 | os.mkdir(fullpath) |
|
748 | 748 | setFile = -1 #inicializo mi contador de seteo |
|
749 | 749 | |
|
750 | 750 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
751 | 751 | fullpath = os.path.join( path, subfolder ) |
|
752 | 752 | |
|
753 | 753 | if not( os.path.exists(fullpath) ): |
|
754 | 754 | os.mkdir(fullpath) |
|
755 | 755 | setFile = -1 #inicializo mi contador de seteo |
|
756 | 756 | |
|
757 | 757 | else: |
|
758 | 758 | filesList = os.listdir( fullpath ) |
|
759 | 759 | filesList = sorted( filesList, key=str.lower ) |
|
760 | 760 | if len( filesList ) > 0: |
|
761 | 761 | filesList = [k for k in filesList if 'M' in k] |
|
762 | 762 | filen = filesList[-1] |
|
763 | 763 | # el filename debera tener el siguiente formato |
|
764 | 764 | # 0 1234 567 89A BCDE (hex) |
|
765 | 765 | # x YYYY DDD SSS .ext |
|
766 | 766 | if isNumber( filen[8:11] ): |
|
767 | 767 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
768 | 768 | else: |
|
769 | 769 | setFile = -1 |
|
770 | 770 | else: |
|
771 | 771 | setFile = -1 #inicializo mi contador de seteo |
|
772 | 772 | |
|
773 | 773 | setFile += 1 |
|
774 | 774 | |
|
775 | 775 | file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar, |
|
776 | 776 | timeTuple.tm_year, |
|
777 | 777 | timeTuple.tm_yday, |
|
778 | 778 | setFile, |
|
779 | 779 | ext ) |
|
780 | 780 | |
|
781 | 781 | filename = os.path.join( path, subfolder, file ) |
|
782 | 782 | self.metaFile = file |
|
783 | 783 | #Setting HDF5 File |
|
784 | 784 | fp = h5py.File(filename,'w') |
|
785 | 785 | |
|
786 | 786 | return fp |
|
787 | 787 | |
|
788 | 788 | def writeMetadata(self, fp): |
|
789 | 789 | |
|
790 | 790 | grp = fp.create_group("Metadata") |
|
791 | 791 | grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype) |
|
792 | 792 | |
|
793 | 793 | for i in range(len(self.metadataList)): |
|
794 | print '#####',self.metadataList[i], getattr(self.dataOut, self.metadataList[i]) | |
|
794 | 795 | grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i])) |
|
795 | 796 | return |
|
796 | 797 | |
|
797 | 798 | def timeFlag(self): |
|
798 | 799 | currentTime = self.dataOut.utctime |
|
799 | 800 | |
|
800 | 801 | if self.lastTime is None: |
|
801 | 802 | self.lastTime = currentTime |
|
802 | 803 | |
|
803 | 804 | #Day |
|
804 | 805 | timeTuple = time.localtime(currentTime) |
|
805 | 806 | dataDay = timeTuple.tm_yday |
|
806 | 807 | |
|
807 | 808 | #Time |
|
808 | 809 | timeDiff = currentTime - self.lastTime |
|
809 | 810 | |
|
810 | 811 | #Si el dia es diferente o si la diferencia entre un dato y otro supera la hora |
|
811 | 812 | if dataDay != self.currentDay: |
|
812 | 813 | self.currentDay = dataDay |
|
813 | 814 | return True |
|
814 | 815 | elif timeDiff > 3*60*60: |
|
815 | 816 | self.lastTime = currentTime |
|
816 | 817 | return True |
|
817 | 818 | else: |
|
818 | 819 | self.lastTime = currentTime |
|
819 | 820 | return False |
|
820 | 821 | |
|
821 | 822 | def setNextFile(self): |
|
822 | 823 | |
|
823 | 824 | ext = self.ext |
|
824 | 825 | path = self.path |
|
825 | 826 | setFile = self.setFile |
|
826 | 827 | mode = self.mode |
|
827 | 828 | |
|
828 | 829 | timeTuple = time.localtime(self.dataOut.utctime) |
|
829 | 830 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
830 | 831 | |
|
831 | 832 | fullpath = os.path.join( path, subfolder ) |
|
832 | 833 | |
|
833 | 834 | if os.path.exists(fullpath): |
|
834 | 835 | filesList = os.listdir( fullpath ) |
|
835 | 836 | filesList = [k for k in filesList if 'D' in k] |
|
836 | 837 | if len( filesList ) > 0: |
|
837 | 838 | filesList = sorted( filesList, key=str.lower ) |
|
838 | 839 | filen = filesList[-1] |
|
839 | 840 | # el filename debera tener el siguiente formato |
|
840 | 841 | # 0 1234 567 89A BCDE (hex) |
|
841 | 842 | # x YYYY DDD SSS .ext |
|
842 | 843 | if isNumber( filen[8:11] ): |
|
843 | 844 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
844 | 845 | else: |
|
845 | 846 | setFile = -1 |
|
846 | 847 | else: |
|
847 | 848 | setFile = -1 #inicializo mi contador de seteo |
|
848 | 849 | else: |
|
849 | 850 | os.makedirs(fullpath) |
|
850 | 851 | setFile = -1 #inicializo mi contador de seteo |
|
851 | 852 | |
|
852 | 853 | setFile += 1 |
|
853 | 854 | |
|
854 | 855 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
855 | 856 | timeTuple.tm_year, |
|
856 | 857 | timeTuple.tm_yday, |
|
857 | 858 | setFile, |
|
858 | 859 | ext ) |
|
859 | 860 | |
|
860 | 861 | filename = os.path.join( path, subfolder, file ) |
|
861 | 862 | |
|
862 | 863 | #Setting HDF5 File |
|
863 | 864 | fp = h5py.File(filename,'w') |
|
864 | 865 | #write metadata |
|
865 | 866 | self.writeMetadata(fp) |
|
866 | 867 | #Write data |
|
867 | 868 | grp = fp.create_group("Data") |
|
868 | 869 | # grp.attrs['metadata'] = self.metaFile |
|
869 | 870 | |
|
870 | 871 | # grp.attrs['blocksPerFile'] = 0 |
|
871 | 872 | ds = [] |
|
872 | 873 | data = [] |
|
873 | 874 | dsList = self.dsList |
|
874 | 875 | i = 0 |
|
875 | 876 | while i < len(dsList): |
|
876 | 877 | dsInfo = dsList[i] |
|
877 | 878 | #One-dimension data |
|
878 | 879 | if dsInfo['mode'] == 0: |
|
879 | 880 | # ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype='S20') |
|
880 | 881 | ds0 = grp.create_dataset(dsInfo['variable'], (1,1), maxshape=(1,self.blocksPerFile) , chunks = True, dtype=numpy.float64) |
|
881 | 882 | ds.append(ds0) |
|
882 | 883 | data.append([]) |
|
883 | 884 | i += 1 |
|
884 | 885 | continue |
|
885 | 886 | # nDimsForDs.append(nDims[i]) |
|
886 | 887 | |
|
887 | 888 | elif dsInfo['mode'] == 2: |
|
888 | 889 | grp0 = grp.create_group(dsInfo['variable']) |
|
889 | 890 | ds0 = grp0.create_dataset(dsInfo['dsName'], (1,dsInfo['shape']), data = numpy.zeros((1,dsInfo['shape'])) , maxshape=(None,dsInfo['shape']), chunks=True) |
|
890 | 891 | ds.append(ds0) |
|
891 | 892 | data.append([]) |
|
892 | 893 | i += 1 |
|
893 | 894 | continue |
|
894 | 895 | |
|
895 | 896 | elif dsInfo['mode'] == 1: |
|
896 | 897 | grp0 = grp.create_group(dsInfo['variable']) |
|
897 | 898 | |
|
898 | 899 | for j in range(dsInfo['dsNumber']): |
|
899 | 900 | dsInfo = dsList[i] |
|
900 | 901 | tableName = dsInfo['dsName'] |
|
901 | 902 | shape = int(dsInfo['shape']) |
|
902 | 903 | |
|
903 | 904 | if dsInfo['nDim'] == 3: |
|
904 | 905 | ds0 = grp0.create_dataset(tableName, (shape[0],shape[1],1) , data = numpy.zeros((shape[0],shape[1],1)), maxshape = (None,shape[1],None), chunks=True) |
|
905 | 906 | else: |
|
906 | 907 | ds0 = grp0.create_dataset(tableName, (1,shape), data = numpy.zeros((1,shape)) , maxshape=(None,shape), chunks=True) |
|
907 | 908 | |
|
908 | 909 | ds.append(ds0) |
|
909 | 910 | data.append([]) |
|
910 | 911 | i += 1 |
|
911 | 912 | # nDimsForDs.append(nDims[i]) |
|
912 | 913 | |
|
913 | 914 | fp.flush() |
|
914 | 915 | fp.close() |
|
915 | 916 | |
|
916 | 917 | # self.nDatas = nDatas |
|
917 | 918 | # self.nDims = nDims |
|
918 | 919 | # self.nDimsForDs = nDimsForDs |
|
919 | 920 | #Saving variables |
|
920 | 921 | print 'Writing the file: %s'%filename |
|
921 | 922 | self.filename = filename |
|
922 | 923 | # self.fp = fp |
|
923 | 924 | # self.grp = grp |
|
924 | 925 | # self.grp.attrs.modify('nRecords', 1) |
|
925 | 926 | self.ds = ds |
|
926 | 927 | self.data = data |
|
927 | 928 | # self.setFile = setFile |
|
928 | 929 | self.firsttime = True |
|
929 | 930 | self.blockIndex = 0 |
|
930 | 931 | return |
|
931 | 932 | |
|
932 | 933 | def putData(self): |
|
933 | 934 | |
|
934 | 935 | if self.blockIndex == self.blocksPerFile or self.timeFlag(): |
|
935 | 936 | self.setNextFile() |
|
936 | 937 | |
|
937 | 938 | # if not self.firsttime: |
|
938 | 939 | self.readBlock() |
|
939 | 940 | self.setBlock() #Prepare data to be written |
|
940 | 941 | self.writeBlock() #Write data |
|
941 | 942 | |
|
942 | 943 | return |
|
943 | 944 | |
|
944 | 945 | def readBlock(self): |
|
945 | 946 | |
|
946 | 947 | ''' |
|
947 | 948 | data Array configured |
|
948 | 949 | |
|
949 | 950 | |
|
950 | 951 | self.data |
|
951 | 952 | ''' |
|
952 | 953 | dsList = self.dsList |
|
953 | 954 | ds = self.ds |
|
954 | 955 | #Setting HDF5 File |
|
955 | 956 | fp = h5py.File(self.filename,'r+') |
|
956 | 957 | grp = fp["Data"] |
|
957 | 958 | ind = 0 |
|
958 | 959 | |
|
959 | 960 | # grp.attrs['blocksPerFile'] = 0 |
|
960 | 961 | while ind < len(dsList): |
|
961 | 962 | dsInfo = dsList[ind] |
|
962 | 963 | |
|
963 | 964 | if dsInfo['mode'] == 0: |
|
964 | 965 | ds0 = grp[dsInfo['variable']] |
|
965 | 966 | ds[ind] = ds0 |
|
966 | 967 | ind += 1 |
|
967 | 968 | else: |
|
968 | 969 | |
|
969 | 970 | grp0 = grp[dsInfo['variable']] |
|
970 | 971 | |
|
971 | 972 | for j in range(dsInfo['dsNumber']): |
|
972 | 973 | dsInfo = dsList[ind] |
|
973 | 974 | ds0 = grp0[dsInfo['dsName']] |
|
974 | 975 | ds[ind] = ds0 |
|
975 | 976 | ind += 1 |
|
976 | 977 | |
|
977 | 978 | self.fp = fp |
|
978 | 979 | self.grp = grp |
|
979 | 980 | self.ds = ds |
|
980 | 981 | |
|
981 | 982 | return |
|
982 | 983 | |
|
983 | 984 | def setBlock(self): |
|
984 | 985 | ''' |
|
985 | 986 | data Array configured |
|
986 | 987 | |
|
987 | 988 | |
|
988 | 989 | self.data |
|
989 | 990 | ''' |
|
990 | 991 | #Creating Arrays |
|
991 | 992 | dsList = self.dsList |
|
992 | 993 | data = self.data |
|
993 | 994 | ind = 0 |
|
994 | 995 | |
|
995 | 996 | while ind < len(dsList): |
|
996 | 997 | dsInfo = dsList[ind] |
|
997 | 998 | dataAux = getattr(self.dataOut, dsInfo['variable']) |
|
998 | 999 | |
|
999 | 1000 | mode = dsInfo['mode'] |
|
1000 | 1001 | nDim = dsInfo['nDim'] |
|
1001 | 1002 | |
|
1002 | 1003 | if mode == 0 or mode == 2 or nDim == 1: |
|
1003 | 1004 | data[ind] = dataAux |
|
1004 | 1005 | ind += 1 |
|
1005 | 1006 | # elif nDim == 1: |
|
1006 | 1007 | # data[ind] = numpy.reshape(dataAux,(numpy.size(dataAux),1)) |
|
1007 | 1008 | # ind += 1 |
|
1008 | 1009 | elif nDim == 2: |
|
1009 | 1010 | for j in range(dsInfo['dsNumber']): |
|
1010 | 1011 | data[ind] = dataAux[j,:] |
|
1011 | 1012 | ind += 1 |
|
1012 | 1013 | elif nDim == 3: |
|
1013 | 1014 | for j in range(dsInfo['dsNumber']): |
|
1014 | 1015 | data[ind] = dataAux[:,j,:] |
|
1015 | 1016 | ind += 1 |
|
1016 | 1017 | |
|
1017 | 1018 | self.data = data |
|
1018 | 1019 | return |
|
1019 | 1020 | |
|
1020 | 1021 | def writeBlock(self): |
|
1021 | 1022 | ''' |
|
1022 | 1023 | Saves the block in the HDF5 file |
|
1023 | 1024 | ''' |
|
1024 | 1025 | dsList = self.dsList |
|
1025 | 1026 | |
|
1026 | 1027 | for i in range(len(self.ds)): |
|
1027 | 1028 | dsInfo = dsList[i] |
|
1028 | 1029 | nDim = dsInfo['nDim'] |
|
1029 | 1030 | mode = dsInfo['mode'] |
|
1030 | 1031 | |
|
1031 | 1032 | # First time |
|
1032 | 1033 | if self.firsttime: |
|
1033 | 1034 | # self.ds[i].resize(self.data[i].shape) |
|
1034 | 1035 | # self.ds[i][self.blockIndex,:] = self.data[i] |
|
1035 | 1036 | if type(self.data[i]) == numpy.ndarray: |
|
1036 | 1037 | |
|
1037 | 1038 | if nDim == 3: |
|
1038 | 1039 | self.data[i] = self.data[i].reshape((self.data[i].shape[0],self.data[i].shape[1],1)) |
|
1039 | 1040 | self.ds[i].resize(self.data[i].shape) |
|
1040 | 1041 | if mode == 2: |
|
1041 | 1042 | self.ds[i].resize(self.data[i].shape) |
|
1042 | 1043 | self.ds[i][:] = self.data[i] |
|
1043 | 1044 | else: |
|
1044 | 1045 | |
|
1045 | 1046 | # From second time |
|
1046 | 1047 | # Meteors! |
|
1047 | 1048 | if mode == 2: |
|
1048 | 1049 | dataShape = self.data[i].shape |
|
1049 | 1050 | dsShape = self.ds[i].shape |
|
1050 | 1051 | self.ds[i].resize((self.ds[i].shape[0] + dataShape[0],self.ds[i].shape[1])) |
|
1051 | 1052 | self.ds[i][dsShape[0]:,:] = self.data[i] |
|
1052 | 1053 | # No dimension |
|
1053 | 1054 | elif mode == 0: |
|
1054 | 1055 | self.ds[i].resize((self.ds[i].shape[0], self.ds[i].shape[1] + 1)) |
|
1055 | 1056 | self.ds[i][0,-1] = self.data[i] |
|
1056 | 1057 | # One dimension |
|
1057 | 1058 | elif nDim == 1: |
|
1058 | 1059 | self.ds[i].resize((self.ds[i].shape[0] + 1, self.ds[i].shape[1])) |
|
1059 | 1060 | self.ds[i][-1,:] = self.data[i] |
|
1060 | 1061 | # Two dimension |
|
1061 | 1062 | elif nDim == 2: |
|
1062 | 1063 | self.ds[i].resize((self.ds[i].shape[0] + 1,self.ds[i].shape[1])) |
|
1063 | 1064 | self.ds[i][self.blockIndex,:] = self.data[i] |
|
1064 | 1065 | # Three dimensions |
|
1065 | 1066 | elif nDim == 3: |
|
1066 | 1067 | self.ds[i].resize((self.ds[i].shape[0],self.ds[i].shape[1],self.ds[i].shape[2]+1)) |
|
1067 | 1068 | self.ds[i][:,:,-1] = self.data[i] |
|
1068 | 1069 | |
|
1069 | 1070 | self.firsttime = False |
|
1070 | 1071 | self.blockIndex += 1 |
|
1071 | 1072 | |
|
1072 | 1073 | #Close to save changes |
|
1073 | 1074 | self.fp.flush() |
|
1074 | 1075 | self.fp.close() |
|
1075 | 1076 | return |
|
1076 | 1077 | |
|
1077 | 1078 | def run(self, dataOut, **kwargs): |
|
1078 | 1079 | |
|
1079 | 1080 | if not(self.isConfig): |
|
1080 | 1081 | flagdata = self.setup(dataOut, **kwargs) |
|
1081 | 1082 | |
|
1082 | 1083 | if not(flagdata): |
|
1083 | 1084 | return |
|
1084 | 1085 | |
|
1085 | 1086 | self.isConfig = True |
|
1086 | 1087 | # self.putMetadata() |
|
1087 | 1088 | self.setNextFile() |
|
1088 | 1089 | |
|
1089 | 1090 | self.putData() |
|
1090 | 1091 | return |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,1064 +1,1068 | |||
|
1 | 1 | import numpy |
|
2 | 2 | |
|
3 | 3 | from jroproc_base import ProcessingUnit, Operation |
|
4 | 4 | from schainpy.model.data.jrodata import Spectra |
|
5 | 5 | from schainpy.model.data.jrodata import hildebrand_sekhon |
|
6 | 6 | |
|
7 | 7 | import matplotlib.pyplot as plt |
|
8 | 8 | |
|
9 | 9 | class SpectraProc(ProcessingUnit): |
|
10 | 10 | |
|
11 | 11 | def __init__(self, **kwargs): |
|
12 | 12 | |
|
13 | 13 | ProcessingUnit.__init__(self, **kwargs) |
|
14 | 14 | |
|
15 | 15 | self.buffer = None |
|
16 | 16 | self.firstdatatime = None |
|
17 | 17 | self.profIndex = 0 |
|
18 | 18 | self.dataOut = Spectra() |
|
19 | 19 | self.id_min = None |
|
20 | 20 | self.id_max = None |
|
21 | 21 | |
|
22 | 22 | def __updateSpecFromVoltage(self): |
|
23 | 23 | |
|
24 | 24 | self.dataOut.timeZone = self.dataIn.timeZone |
|
25 | 25 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
26 | 26 | self.dataOut.errorCount = self.dataIn.errorCount |
|
27 | 27 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
28 | 28 | |
|
29 | 29 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
30 | 30 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
31 | 31 | self.dataOut.channelList = self.dataIn.channelList |
|
32 | 32 | self.dataOut.heightList = self.dataIn.heightList |
|
33 | 33 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
34 | 34 | |
|
35 | 35 | self.dataOut.nBaud = self.dataIn.nBaud |
|
36 | 36 | self.dataOut.nCode = self.dataIn.nCode |
|
37 | 37 | self.dataOut.code = self.dataIn.code |
|
38 | 38 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
39 | 39 | |
|
40 | 40 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock |
|
41 | 41 | self.dataOut.utctime = self.firstdatatime |
|
42 | 42 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
43 | 43 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
44 | 44 | self.dataOut.flagShiftFFT = False |
|
45 | 45 | |
|
46 | 46 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
47 | 47 | self.dataOut.nIncohInt = 1 |
|
48 | 48 | |
|
49 | 49 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
50 | 50 | |
|
51 | 51 | self.dataOut.frequency = self.dataIn.frequency |
|
52 | 52 | self.dataOut.realtime = self.dataIn.realtime |
|
53 | 53 | |
|
54 | 54 | self.dataOut.azimuth = self.dataIn.azimuth |
|
55 | 55 | self.dataOut.zenith = self.dataIn.zenith |
|
56 | 56 | |
|
57 | 57 | self.dataOut.beam.codeList = self.dataIn.beam.codeList |
|
58 | 58 | self.dataOut.beam.azimuthList = self.dataIn.beam.azimuthList |
|
59 | 59 | self.dataOut.beam.zenithList = self.dataIn.beam.zenithList |
|
60 | 60 | |
|
61 | 61 | def __getFft(self): |
|
62 | 62 | """ |
|
63 | 63 | Convierte valores de Voltaje a Spectra |
|
64 | 64 | |
|
65 | 65 | Affected: |
|
66 | 66 | self.dataOut.data_spc |
|
67 | 67 | self.dataOut.data_cspc |
|
68 | 68 | self.dataOut.data_dc |
|
69 | 69 | self.dataOut.heightList |
|
70 | 70 | self.profIndex |
|
71 | 71 | self.buffer |
|
72 | 72 | self.dataOut.flagNoData |
|
73 | 73 | """ |
|
74 | 74 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
75 | ||
|
75 | 76 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
76 | 77 | dc = fft_volt[:,0,:] |
|
77 | 78 | |
|
78 | 79 | #calculo de self-spectra |
|
79 | 80 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
80 | 81 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
81 | 82 | spc = spc.real |
|
82 | 83 | |
|
83 | 84 | blocksize = 0 |
|
84 | 85 | blocksize += dc.size |
|
85 | 86 | blocksize += spc.size |
|
86 | 87 | |
|
87 | 88 | cspc = None |
|
88 | 89 | pairIndex = 0 |
|
89 | 90 | if self.dataOut.pairsList != None: |
|
90 | 91 | #calculo de cross-spectra |
|
91 | 92 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
92 | 93 | for pair in self.dataOut.pairsList: |
|
93 | 94 | if pair[0] not in self.dataOut.channelList: |
|
94 | 95 | raise ValueError, "Error getting CrossSpectra: pair 0 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) |
|
95 | 96 | if pair[1] not in self.dataOut.channelList: |
|
96 | 97 | raise ValueError, "Error getting CrossSpectra: pair 1 of %s is not in channelList = %s" %(str(pair), str(self.dataOut.channelList)) |
|
97 | 98 | |
|
98 | 99 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
99 | 100 | pairIndex += 1 |
|
100 | 101 | blocksize += cspc.size |
|
101 | 102 | |
|
102 | 103 | self.dataOut.data_spc = spc |
|
103 | 104 | self.dataOut.data_cspc = cspc |
|
104 | 105 | self.dataOut.data_dc = dc |
|
105 | 106 | self.dataOut.blockSize = blocksize |
|
106 | 107 | self.dataOut.flagShiftFFT = True |
|
107 | 108 | |
|
108 | 109 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None): |
|
109 | 110 | |
|
110 | 111 | self.dataOut.flagNoData = True |
|
111 | 112 | |
|
112 | 113 | if self.dataIn.type == "Spectra": |
|
113 | 114 | self.dataOut.copy(self.dataIn) |
|
114 | 115 | # self.__selectPairs(pairsList) |
|
115 | 116 | return True |
|
116 | 117 | |
|
117 | 118 | if self.dataIn.type == "Voltage": |
|
118 | 119 | |
|
119 | 120 | if nFFTPoints == None: |
|
120 | 121 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" |
|
121 | 122 | |
|
122 | 123 | if nProfiles == None: |
|
123 | 124 | nProfiles = nFFTPoints |
|
124 | 125 | |
|
125 | 126 | if ippFactor == None: |
|
126 | 127 | ippFactor = 1 |
|
127 | 128 | |
|
128 | 129 | self.dataOut.ippFactor = ippFactor |
|
129 | 130 | |
|
130 | 131 | self.dataOut.nFFTPoints = nFFTPoints |
|
131 | 132 | self.dataOut.pairsList = pairsList |
|
132 | 133 | |
|
133 | 134 | if self.buffer is None: |
|
134 | 135 | self.buffer = numpy.zeros( (self.dataIn.nChannels, |
|
135 | 136 | nProfiles, |
|
136 | 137 | self.dataIn.nHeights), |
|
137 | 138 | dtype='complex') |
|
138 | 139 | |
|
139 | 140 | if self.dataIn.flagDataAsBlock: |
|
140 | 141 | #data dimension: [nChannels, nProfiles, nSamples] |
|
142 | ||
|
141 | 143 | nVoltProfiles = self.dataIn.data.shape[1] |
|
142 | 144 | # nVoltProfiles = self.dataIn.nProfiles |
|
143 | 145 | |
|
144 | 146 | if nVoltProfiles == nProfiles: |
|
145 | 147 | self.buffer = self.dataIn.data.copy() |
|
146 | 148 | self.profIndex = nVoltProfiles |
|
147 | 149 | |
|
148 | 150 | elif nVoltProfiles < nProfiles: |
|
149 | 151 | |
|
150 | 152 | if self.profIndex == 0: |
|
151 | 153 | self.id_min = 0 |
|
152 | 154 | self.id_max = nVoltProfiles |
|
153 | 155 | |
|
154 | 156 | self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data |
|
155 | 157 | self.profIndex += nVoltProfiles |
|
156 | 158 | self.id_min += nVoltProfiles |
|
157 | 159 | self.id_max += nVoltProfiles |
|
158 | 160 | else: |
|
159 | 161 | raise ValueError, "The type object %s has %d profiles, it should just has %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles) |
|
160 | 162 | self.dataOut.flagNoData = True |
|
161 | 163 | return 0 |
|
162 | 164 | else: |
|
165 | print 'DATA shape', self.dataIn.data.shape | |
|
166 | sadsdf | |
|
163 | 167 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
164 | 168 | self.profIndex += 1 |
|
165 | 169 | |
|
166 | 170 | if self.firstdatatime == None: |
|
167 | 171 | self.firstdatatime = self.dataIn.utctime |
|
168 | 172 | |
|
169 | 173 | if self.profIndex == nProfiles: |
|
170 | 174 | self.__updateSpecFromVoltage() |
|
171 | 175 | self.__getFft() |
|
172 | 176 | |
|
173 | 177 | self.dataOut.flagNoData = False |
|
174 | 178 | self.firstdatatime = None |
|
175 | 179 | self.profIndex = 0 |
|
176 | 180 | |
|
177 | 181 | return True |
|
178 | 182 | |
|
179 | 183 | raise ValueError, "The type of input object '%s' is not valid"%(self.dataIn.type) |
|
180 | 184 | |
|
181 | 185 | def __selectPairs(self, pairsList): |
|
182 | 186 | |
|
183 | 187 | if channelList == None: |
|
184 | 188 | return |
|
185 | 189 | |
|
186 | 190 | pairsIndexListSelected = [] |
|
187 | 191 | |
|
188 | 192 | for thisPair in pairsList: |
|
189 | 193 | |
|
190 | 194 | if thisPair not in self.dataOut.pairsList: |
|
191 | 195 | continue |
|
192 | 196 | |
|
193 | 197 | pairIndex = self.dataOut.pairsList.index(thisPair) |
|
194 | 198 | |
|
195 | 199 | pairsIndexListSelected.append(pairIndex) |
|
196 | 200 | |
|
197 | 201 | if not pairsIndexListSelected: |
|
198 | 202 | self.dataOut.data_cspc = None |
|
199 | 203 | self.dataOut.pairsList = [] |
|
200 | 204 | return |
|
201 | 205 | |
|
202 | 206 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
203 | 207 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] |
|
204 | 208 | |
|
205 | 209 | return |
|
206 | 210 | |
|
207 | 211 | def __selectPairsByChannel(self, channelList=None): |
|
208 | 212 | |
|
209 | 213 | if channelList == None: |
|
210 | 214 | return |
|
211 | 215 | |
|
212 | 216 | pairsIndexListSelected = [] |
|
213 | 217 | for pairIndex in self.dataOut.pairsIndexList: |
|
214 | 218 | #First pair |
|
215 | 219 | if self.dataOut.pairsList[pairIndex][0] not in channelList: |
|
216 | 220 | continue |
|
217 | 221 | #Second pair |
|
218 | 222 | if self.dataOut.pairsList[pairIndex][1] not in channelList: |
|
219 | 223 | continue |
|
220 | 224 | |
|
221 | 225 | pairsIndexListSelected.append(pairIndex) |
|
222 | 226 | |
|
223 | 227 | if not pairsIndexListSelected: |
|
224 | 228 | self.dataOut.data_cspc = None |
|
225 | 229 | self.dataOut.pairsList = [] |
|
226 | 230 | return |
|
227 | 231 | |
|
228 | 232 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndexListSelected] |
|
229 | 233 | self.dataOut.pairsList = [self.dataOut.pairsList[i] for i in pairsIndexListSelected] |
|
230 | 234 | |
|
231 | 235 | return |
|
232 | 236 | |
|
233 | 237 | def selectChannels(self, channelList): |
|
234 | 238 | |
|
235 | 239 | channelIndexList = [] |
|
236 | 240 | |
|
237 | 241 | for channel in channelList: |
|
238 | 242 | if channel not in self.dataOut.channelList: |
|
239 | 243 | raise ValueError, "Error selecting channels, Channel %d is not valid.\nAvailable channels = %s" %(channel, str(self.dataOut.channelList)) |
|
240 | 244 | |
|
241 | 245 | index = self.dataOut.channelList.index(channel) |
|
242 | 246 | channelIndexList.append(index) |
|
243 | 247 | |
|
244 | 248 | self.selectChannelsByIndex(channelIndexList) |
|
245 | 249 | |
|
246 | 250 | def selectChannelsByIndex(self, channelIndexList): |
|
247 | 251 | """ |
|
248 | 252 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
249 | 253 | |
|
250 | 254 | Input: |
|
251 | 255 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
252 | 256 | |
|
253 | 257 | Affected: |
|
254 | 258 | self.dataOut.data_spc |
|
255 | 259 | self.dataOut.channelIndexList |
|
256 | 260 | self.dataOut.nChannels |
|
257 | 261 | |
|
258 | 262 | Return: |
|
259 | 263 | None |
|
260 | 264 | """ |
|
261 | 265 | |
|
262 | 266 | for channelIndex in channelIndexList: |
|
263 | 267 | if channelIndex not in self.dataOut.channelIndexList: |
|
264 | 268 | raise ValueError, "Error selecting channels: The value %d in channelIndexList is not valid.\nAvailable channel indexes = " %(channelIndex, self.dataOut.channelIndexList) |
|
265 | 269 | |
|
266 | 270 | # nChannels = len(channelIndexList) |
|
267 | 271 | |
|
268 | 272 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
269 | 273 | data_dc = self.dataOut.data_dc[channelIndexList,:] |
|
270 | 274 | |
|
271 | 275 | self.dataOut.data_spc = data_spc |
|
272 | 276 | self.dataOut.data_dc = data_dc |
|
273 | 277 | |
|
274 | 278 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
275 | 279 | # self.dataOut.nChannels = nChannels |
|
276 | 280 | |
|
277 | 281 | self.__selectPairsByChannel(self.dataOut.channelList) |
|
278 | 282 | |
|
279 | 283 | return 1 |
|
280 | 284 | |
|
281 | 285 | |
|
282 | 286 | def selectFFTs(self, minFFT, maxFFT ): |
|
283 | 287 | """ |
|
284 | 288 | Selecciona un bloque de datos en base a un grupo de valores de puntos FFTs segun el rango |
|
285 | 289 | minFFT<= FFT <= maxFFT |
|
286 | 290 | """ |
|
287 | 291 | |
|
288 | 292 | if (minFFT > maxFFT): |
|
289 | 293 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minFFT, maxFFT) |
|
290 | 294 | |
|
291 | 295 | if (minFFT < self.dataOut.getFreqRange()[0]): |
|
292 | 296 | minFFT = self.dataOut.getFreqRange()[0] |
|
293 | 297 | |
|
294 | 298 | if (maxFFT > self.dataOut.getFreqRange()[-1]): |
|
295 | 299 | maxFFT = self.dataOut.getFreqRange()[-1] |
|
296 | 300 | |
|
297 | 301 | minIndex = 0 |
|
298 | 302 | maxIndex = 0 |
|
299 | 303 | FFTs = self.dataOut.getFreqRange() |
|
300 | 304 | |
|
301 | 305 | inda = numpy.where(FFTs >= minFFT) |
|
302 | 306 | indb = numpy.where(FFTs <= maxFFT) |
|
303 | 307 | |
|
304 | 308 | try: |
|
305 | 309 | minIndex = inda[0][0] |
|
306 | 310 | except: |
|
307 | 311 | minIndex = 0 |
|
308 | 312 | |
|
309 | 313 | try: |
|
310 | 314 | maxIndex = indb[0][-1] |
|
311 | 315 | except: |
|
312 | 316 | maxIndex = len(FFTs) |
|
313 | 317 | |
|
314 | 318 | self.selectFFTsByIndex(minIndex, maxIndex) |
|
315 | 319 | |
|
316 | 320 | return 1 |
|
317 | 321 | |
|
318 | 322 | |
|
319 | 323 | |
|
320 | 324 | def selectHeights(self, minHei, maxHei): |
|
321 | 325 | """ |
|
322 | 326 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
323 | 327 | minHei <= height <= maxHei |
|
324 | 328 | |
|
325 | 329 | Input: |
|
326 | 330 | minHei : valor minimo de altura a considerar |
|
327 | 331 | maxHei : valor maximo de altura a considerar |
|
328 | 332 | |
|
329 | 333 | Affected: |
|
330 | 334 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
331 | 335 | |
|
332 | 336 | Return: |
|
333 | 337 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
334 | 338 | """ |
|
335 | 339 | |
|
336 | 340 | |
|
337 | 341 | if (minHei > maxHei): |
|
338 | 342 | raise ValueError, "Error selecting heights: Height range (%d,%d) is not valid" % (minHei, maxHei) |
|
339 | 343 | |
|
340 | 344 | if (minHei < self.dataOut.heightList[0]): |
|
341 | 345 | minHei = self.dataOut.heightList[0] |
|
342 | 346 | |
|
343 | 347 | if (maxHei > self.dataOut.heightList[-1]): |
|
344 | 348 | maxHei = self.dataOut.heightList[-1] |
|
345 | 349 | |
|
346 | 350 | minIndex = 0 |
|
347 | 351 | maxIndex = 0 |
|
348 | 352 | heights = self.dataOut.heightList |
|
349 | 353 | |
|
350 | 354 | inda = numpy.where(heights >= minHei) |
|
351 | 355 | indb = numpy.where(heights <= maxHei) |
|
352 | 356 | |
|
353 | 357 | try: |
|
354 | 358 | minIndex = inda[0][0] |
|
355 | 359 | except: |
|
356 | 360 | minIndex = 0 |
|
357 | 361 | |
|
358 | 362 | try: |
|
359 | 363 | maxIndex = indb[0][-1] |
|
360 | 364 | except: |
|
361 | 365 | maxIndex = len(heights) |
|
362 | 366 | |
|
363 | 367 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
364 | 368 | |
|
365 | 369 | |
|
366 | 370 | return 1 |
|
367 | 371 | |
|
368 | 372 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
369 | 373 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
370 | 374 | |
|
371 | 375 | if hei_ref != None: |
|
372 | 376 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
373 | 377 | |
|
374 | 378 | minIndex = min(newheis[0]) |
|
375 | 379 | maxIndex = max(newheis[0]) |
|
376 | 380 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
377 | 381 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
378 | 382 | |
|
379 | 383 | # determina indices |
|
380 | 384 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
381 | 385 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
382 | 386 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
383 | 387 | beacon_heiIndexList = [] |
|
384 | 388 | for val in avg_dB.tolist(): |
|
385 | 389 | if val >= beacon_dB[0]: |
|
386 | 390 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
387 | 391 | |
|
388 | 392 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
389 | 393 | data_cspc = None |
|
390 | 394 | if self.dataOut.data_cspc is not None: |
|
391 | 395 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
392 | 396 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
393 | 397 | |
|
394 | 398 | data_dc = None |
|
395 | 399 | if self.dataOut.data_dc is not None: |
|
396 | 400 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
397 | 401 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
398 | 402 | |
|
399 | 403 | self.dataOut.data_spc = data_spc |
|
400 | 404 | self.dataOut.data_cspc = data_cspc |
|
401 | 405 | self.dataOut.data_dc = data_dc |
|
402 | 406 | self.dataOut.heightList = heightList |
|
403 | 407 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
404 | 408 | |
|
405 | 409 | return 1 |
|
406 | 410 | |
|
407 | 411 | def selectFFTsByIndex(self, minIndex, maxIndex): |
|
408 | 412 | """ |
|
409 | 413 | |
|
410 | 414 | """ |
|
411 | 415 | |
|
412 | 416 | if (minIndex < 0) or (minIndex > maxIndex): |
|
413 | 417 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex) |
|
414 | 418 | |
|
415 | 419 | if (maxIndex >= self.dataOut.nProfiles): |
|
416 | 420 | maxIndex = self.dataOut.nProfiles-1 |
|
417 | 421 | |
|
418 | 422 | #Spectra |
|
419 | 423 | data_spc = self.dataOut.data_spc[:,minIndex:maxIndex+1,:] |
|
420 | 424 | |
|
421 | 425 | data_cspc = None |
|
422 | 426 | if self.dataOut.data_cspc is not None: |
|
423 | 427 | data_cspc = self.dataOut.data_cspc[:,minIndex:maxIndex+1,:] |
|
424 | 428 | |
|
425 | 429 | data_dc = None |
|
426 | 430 | if self.dataOut.data_dc is not None: |
|
427 | 431 | data_dc = self.dataOut.data_dc[minIndex:maxIndex+1,:] |
|
428 | 432 | |
|
429 | 433 | self.dataOut.data_spc = data_spc |
|
430 | 434 | self.dataOut.data_cspc = data_cspc |
|
431 | 435 | self.dataOut.data_dc = data_dc |
|
432 | 436 | |
|
433 | 437 | self.dataOut.ippSeconds = self.dataOut.ippSeconds*(self.dataOut.nFFTPoints / numpy.shape(data_cspc)[1]) |
|
434 | 438 | self.dataOut.nFFTPoints = numpy.shape(data_cspc)[1] |
|
435 | 439 | self.dataOut.profilesPerBlock = numpy.shape(data_cspc)[1] |
|
436 | 440 | |
|
437 | 441 | #self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
438 | 442 | |
|
439 | 443 | return 1 |
|
440 | 444 | |
|
441 | 445 | |
|
442 | 446 | |
|
443 | 447 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
444 | 448 | """ |
|
445 | 449 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
446 | 450 | minIndex <= index <= maxIndex |
|
447 | 451 | |
|
448 | 452 | Input: |
|
449 | 453 | minIndex : valor de indice minimo de altura a considerar |
|
450 | 454 | maxIndex : valor de indice maximo de altura a considerar |
|
451 | 455 | |
|
452 | 456 | Affected: |
|
453 | 457 | self.dataOut.data_spc |
|
454 | 458 | self.dataOut.data_cspc |
|
455 | 459 | self.dataOut.data_dc |
|
456 | 460 | self.dataOut.heightList |
|
457 | 461 | |
|
458 | 462 | Return: |
|
459 | 463 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
460 | 464 | """ |
|
461 | 465 | |
|
462 | 466 | if (minIndex < 0) or (minIndex > maxIndex): |
|
463 | 467 | raise ValueError, "Error selecting heights: Index range (%d,%d) is not valid" % (minIndex, maxIndex) |
|
464 | 468 | |
|
465 | 469 | if (maxIndex >= self.dataOut.nHeights): |
|
466 | 470 | maxIndex = self.dataOut.nHeights-1 |
|
467 | 471 | |
|
468 | 472 | #Spectra |
|
469 | 473 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
470 | 474 | |
|
471 | 475 | data_cspc = None |
|
472 | 476 | if self.dataOut.data_cspc is not None: |
|
473 | 477 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
474 | 478 | |
|
475 | 479 | data_dc = None |
|
476 | 480 | if self.dataOut.data_dc is not None: |
|
477 | 481 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
478 | 482 | |
|
479 | 483 | self.dataOut.data_spc = data_spc |
|
480 | 484 | self.dataOut.data_cspc = data_cspc |
|
481 | 485 | self.dataOut.data_dc = data_dc |
|
482 | 486 | |
|
483 | 487 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
484 | 488 | |
|
485 | 489 | return 1 |
|
486 | 490 | |
|
487 | 491 | |
|
488 | 492 | def removeDC(self, mode = 2): |
|
489 | 493 | jspectra = self.dataOut.data_spc |
|
490 | 494 | jcspectra = self.dataOut.data_cspc |
|
491 | 495 | |
|
492 | 496 | |
|
493 | 497 | num_chan = jspectra.shape[0] |
|
494 | 498 | num_hei = jspectra.shape[2] |
|
495 | 499 | |
|
496 | 500 | if jcspectra is not None: |
|
497 | 501 | jcspectraExist = True |
|
498 | 502 | num_pairs = jcspectra.shape[0] |
|
499 | 503 | else: jcspectraExist = False |
|
500 | 504 | |
|
501 | 505 | freq_dc = jspectra.shape[1]/2 |
|
502 | 506 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
503 | 507 | |
|
504 | 508 | if ind_vel[0]<0: |
|
505 | 509 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
506 | 510 | |
|
507 | 511 | if mode == 1: |
|
508 | 512 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
509 | 513 | |
|
510 | 514 | if jcspectraExist: |
|
511 | 515 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
512 | 516 | |
|
513 | 517 | if mode == 2: |
|
514 | 518 | |
|
515 | 519 | vel = numpy.array([-2,-1,1,2]) |
|
516 | 520 | xx = numpy.zeros([4,4]) |
|
517 | 521 | |
|
518 | 522 | for fil in range(4): |
|
519 | 523 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
520 | 524 | |
|
521 | 525 | xx_inv = numpy.linalg.inv(xx) |
|
522 | 526 | xx_aux = xx_inv[0,:] |
|
523 | 527 | |
|
524 | 528 | for ich in range(num_chan): |
|
525 | 529 | yy = jspectra[ich,ind_vel,:] |
|
526 | 530 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
527 | 531 | |
|
528 | 532 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
529 | 533 | cjunkid = sum(junkid) |
|
530 | 534 | |
|
531 | 535 | if cjunkid.any(): |
|
532 | 536 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
533 | 537 | |
|
534 | 538 | if jcspectraExist: |
|
535 | 539 | for ip in range(num_pairs): |
|
536 | 540 | yy = jcspectra[ip,ind_vel,:] |
|
537 | 541 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
538 | 542 | |
|
539 | 543 | |
|
540 | 544 | self.dataOut.data_spc = jspectra |
|
541 | 545 | self.dataOut.data_cspc = jcspectra |
|
542 | 546 | |
|
543 | 547 | return 1 |
|
544 | 548 | |
|
545 | 549 | def removeInterference2(self): |
|
546 | 550 | |
|
547 | 551 | cspc = self.dataOut.data_cspc |
|
548 | 552 | spc = self.dataOut.data_spc |
|
549 | 553 | print numpy.shape(spc) |
|
550 | 554 | Heights = numpy.arange(cspc.shape[2]) |
|
551 | 555 | realCspc = numpy.abs(cspc) |
|
552 | 556 | |
|
553 | 557 | for i in range(cspc.shape[0]): |
|
554 | 558 | LinePower= numpy.sum(realCspc[i], axis=0) |
|
555 | 559 | Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)] |
|
556 | 560 | SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ] |
|
557 | 561 | #print numpy.shape(realCspc) |
|
558 | 562 | #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights]) |
|
559 | 563 | InterferenceSum = numpy.sum( realCspc[i,:,SelectedHeights], axis=0 ) |
|
560 | 564 | print SelectedHeights |
|
561 | 565 | InterferenceThresholdMin = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)] |
|
562 | 566 | InterferenceThresholdMax = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.99)] |
|
563 | 567 | |
|
564 | 568 | |
|
565 | 569 | InterferenceRange = numpy.where( ([InterferenceSum > InterferenceThresholdMin]))# , InterferenceSum < InterferenceThresholdMax]) ) |
|
566 | 570 | #InterferenceRange = numpy.where( ([InterferenceRange < InterferenceThresholdMax])) |
|
567 | 571 | if len(InterferenceRange)<int(cspc.shape[1]*0.3): |
|
568 | 572 | cspc[i,InterferenceRange,:] = numpy.NaN |
|
569 | 573 | |
|
570 | 574 | print '########################################################################################' |
|
571 | 575 | print 'Len interference sum',len(InterferenceSum) |
|
572 | 576 | print 'InterferenceThresholdMin', InterferenceThresholdMin, 'InterferenceThresholdMax', InterferenceThresholdMax |
|
573 | 577 | print 'InterferenceRange',InterferenceRange |
|
574 | 578 | print '########################################################################################' |
|
575 | 579 | |
|
576 | 580 | ''' Ploteo ''' |
|
577 | 581 | |
|
578 | 582 | #for i in range(3): |
|
579 | 583 | #print 'FASE', numpy.shape(phase), y[25] |
|
580 | 584 | #print numpy.shape(coherence) |
|
581 | 585 | #fig = plt.figure(10+ int(numpy.random.rand()*100)) |
|
582 | 586 | #plt.plot( x[0:256],coherence[:,25] ) |
|
583 | 587 | #cohAv = numpy.average(coherence[i],1) |
|
584 | 588 | #Pendiente = FrecRange * PhaseSlope[i] |
|
585 | 589 | #plt.plot( InterferenceSum) |
|
586 | 590 | #plt.plot( numpy.sort(InterferenceSum)) |
|
587 | 591 | #plt.plot( LinePower ) |
|
588 | 592 | #plt.plot( xFrec,phase[i]) |
|
589 | 593 | |
|
590 | 594 | #CSPCmean = numpy.mean(numpy.abs(CSPCSamples),0) |
|
591 | 595 | #plt.plot(xFrec, FitGauss01) |
|
592 | 596 | #plt.plot(xFrec, CSPCmean) |
|
593 | 597 | #plt.plot(xFrec, numpy.abs(CSPCSamples[0])) |
|
594 | 598 | #plt.plot(xFrec, FitGauss) |
|
595 | 599 | #plt.plot(xFrec, yMean) |
|
596 | 600 | #plt.plot(xFrec, numpy.abs(coherence[0])) |
|
597 | 601 | |
|
598 | 602 | #plt.axis([-12, 12, 15, 50]) |
|
599 | 603 | #plt.title("%s" %( '%s %s, Channel %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S") , i))) |
|
600 | 604 | |
|
601 | 605 | |
|
602 | 606 | #fig.savefig('/home/erick/Documents/Pics/nom{}.png'.format(int(numpy.random.rand()*100))) |
|
603 | 607 | |
|
604 | 608 | #plt.show() |
|
605 | 609 | #self.indice=self.indice+1 |
|
606 | 610 | #raise |
|
607 | 611 | |
|
608 | 612 | |
|
609 | 613 | self.dataOut.data_cspc = cspc |
|
610 | 614 | |
|
611 | 615 | # for i in range(spc.shape[0]): |
|
612 | 616 | # LinePower= numpy.sum(spc[i], axis=0) |
|
613 | 617 | # Threshold = numpy.amax(LinePower)-numpy.sort(LinePower)[len(Heights)-int(len(Heights)*0.1)] |
|
614 | 618 | # SelectedHeights = Heights[ numpy.where( LinePower < Threshold ) ] |
|
615 | 619 | # #print numpy.shape(realCspc) |
|
616 | 620 | # #print '',SelectedHeights, '', numpy.shape(realCspc[i,:,SelectedHeights]) |
|
617 | 621 | # InterferenceSum = numpy.sum( spc[i,:,SelectedHeights], axis=0 ) |
|
618 | 622 | # InterferenceThreshold = numpy.sort(InterferenceSum)[int(len(InterferenceSum)*0.98)] |
|
619 | 623 | # InterferenceRange = numpy.where( InterferenceSum > InterferenceThreshold ) |
|
620 | 624 | # if len(InterferenceRange)<int(spc.shape[1]*0.03): |
|
621 | 625 | # spc[i,InterferenceRange,:] = numpy.NaN |
|
622 | 626 | |
|
623 | 627 | #self.dataOut.data_spc = spc |
|
624 | 628 | |
|
625 | 629 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
626 | 630 | |
|
627 | 631 | jspectra = self.dataOut.data_spc |
|
628 | 632 | jcspectra = self.dataOut.data_cspc |
|
629 | 633 | jnoise = self.dataOut.getNoise() |
|
630 | 634 | num_incoh = self.dataOut.nIncohInt |
|
631 | 635 | |
|
632 | 636 | num_channel = jspectra.shape[0] |
|
633 | 637 | num_prof = jspectra.shape[1] |
|
634 | 638 | num_hei = jspectra.shape[2] |
|
635 | 639 | |
|
636 | 640 | #hei_interf |
|
637 | 641 | if hei_interf is None: |
|
638 | 642 | count_hei = num_hei/2 #Como es entero no importa |
|
639 | 643 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
640 | 644 | hei_interf = numpy.asarray(hei_interf)[0] |
|
641 | 645 | #nhei_interf |
|
642 | 646 | if (nhei_interf == None): |
|
643 | 647 | nhei_interf = 5 |
|
644 | 648 | if (nhei_interf < 1): |
|
645 | 649 | nhei_interf = 1 |
|
646 | 650 | if (nhei_interf > count_hei): |
|
647 | 651 | nhei_interf = count_hei |
|
648 | 652 | if (offhei_interf == None): |
|
649 | 653 | offhei_interf = 0 |
|
650 | 654 | |
|
651 | 655 | ind_hei = range(num_hei) |
|
652 | 656 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
653 | 657 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
654 | 658 | mask_prof = numpy.asarray(range(num_prof)) |
|
655 | 659 | num_mask_prof = mask_prof.size |
|
656 | 660 | comp_mask_prof = [0, num_prof/2] |
|
657 | 661 | |
|
658 | 662 | |
|
659 | 663 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
660 | 664 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
661 | 665 | jnoise = numpy.nan |
|
662 | 666 | noise_exist = jnoise[0] < numpy.Inf |
|
663 | 667 | |
|
664 | 668 | #Subrutina de Remocion de la Interferencia |
|
665 | 669 | for ich in range(num_channel): |
|
666 | 670 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
667 | 671 | power = jspectra[ich,mask_prof,:] |
|
668 | 672 | power = power[:,hei_interf] |
|
669 | 673 | power = power.sum(axis = 0) |
|
670 | 674 | psort = power.ravel().argsort() |
|
671 | 675 | |
|
672 | 676 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
673 | 677 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
674 | 678 | |
|
675 | 679 | if noise_exist: |
|
676 | 680 | # tmp_noise = jnoise[ich] / num_prof |
|
677 | 681 | tmp_noise = jnoise[ich] |
|
678 | 682 | junkspc_interf = junkspc_interf - tmp_noise |
|
679 | 683 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
680 | 684 | |
|
681 | 685 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
682 | 686 | jspc_interf = jspc_interf.transpose() |
|
683 | 687 | #Calculando el espectro de interferencia promedio |
|
684 | 688 | noiseid = numpy.where(jspc_interf <= tmp_noise/ numpy.sqrt(num_incoh)) |
|
685 | 689 | noiseid = noiseid[0] |
|
686 | 690 | cnoiseid = noiseid.size |
|
687 | 691 | interfid = numpy.where(jspc_interf > tmp_noise/ numpy.sqrt(num_incoh)) |
|
688 | 692 | interfid = interfid[0] |
|
689 | 693 | cinterfid = interfid.size |
|
690 | 694 | |
|
691 | 695 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
692 | 696 | |
|
693 | 697 | #Expandiendo los perfiles a limpiar |
|
694 | 698 | if (cinterfid > 0): |
|
695 | 699 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
696 | 700 | new_interfid = numpy.asarray(new_interfid) |
|
697 | 701 | new_interfid = {x for x in new_interfid} |
|
698 | 702 | new_interfid = numpy.array(list(new_interfid)) |
|
699 | 703 | new_cinterfid = new_interfid.size |
|
700 | 704 | else: new_cinterfid = 0 |
|
701 | 705 | |
|
702 | 706 | for ip in range(new_cinterfid): |
|
703 | 707 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
704 | 708 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
705 | 709 | |
|
706 | 710 | |
|
707 | 711 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
708 | 712 | |
|
709 | 713 | #Removiendo la interferencia del punto de mayor interferencia |
|
710 | 714 | ListAux = jspc_interf[mask_prof].tolist() |
|
711 | 715 | maxid = ListAux.index(max(ListAux)) |
|
712 | 716 | |
|
713 | 717 | |
|
714 | 718 | if cinterfid > 0: |
|
715 | 719 | for ip in range(cinterfid*(interf == 2) - 1): |
|
716 | 720 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/numpy.sqrt(num_incoh))).nonzero() |
|
717 | 721 | cind = len(ind) |
|
718 | 722 | |
|
719 | 723 | if (cind > 0): |
|
720 | 724 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/numpy.sqrt(num_incoh)) |
|
721 | 725 | |
|
722 | 726 | ind = numpy.array([-2,-1,1,2]) |
|
723 | 727 | xx = numpy.zeros([4,4]) |
|
724 | 728 | |
|
725 | 729 | for id1 in range(4): |
|
726 | 730 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
727 | 731 | |
|
728 | 732 | xx_inv = numpy.linalg.inv(xx) |
|
729 | 733 | xx = xx_inv[:,0] |
|
730 | 734 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
731 | 735 | yy = jspectra[ich,mask_prof[ind],:] |
|
732 | 736 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
733 | 737 | |
|
734 | 738 | |
|
735 | 739 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/numpy.sqrt(num_incoh))).nonzero() |
|
736 | 740 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/numpy.sqrt(num_incoh)) |
|
737 | 741 | |
|
738 | 742 | #Remocion de Interferencia en el Cross Spectra |
|
739 | 743 | if jcspectra is None: return jspectra, jcspectra |
|
740 | 744 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
741 | 745 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
742 | 746 | |
|
743 | 747 | for ip in range(num_pairs): |
|
744 | 748 | |
|
745 | 749 | #------------------------------------------- |
|
746 | 750 | |
|
747 | 751 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
748 | 752 | cspower = cspower[:,hei_interf] |
|
749 | 753 | cspower = cspower.sum(axis = 0) |
|
750 | 754 | |
|
751 | 755 | cspsort = cspower.ravel().argsort() |
|
752 | 756 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
753 | 757 | junkcspc_interf = junkcspc_interf.transpose() |
|
754 | 758 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
755 | 759 | |
|
756 | 760 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
757 | 761 | |
|
758 | 762 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
759 | 763 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
760 | 764 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
761 | 765 | |
|
762 | 766 | for iprof in range(num_prof): |
|
763 | 767 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
764 | 768 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
765 | 769 | |
|
766 | 770 | #Removiendo la Interferencia |
|
767 | 771 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
768 | 772 | |
|
769 | 773 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
770 | 774 | maxid = ListAux.index(max(ListAux)) |
|
771 | 775 | |
|
772 | 776 | ind = numpy.array([-2,-1,1,2]) |
|
773 | 777 | xx = numpy.zeros([4,4]) |
|
774 | 778 | |
|
775 | 779 | for id1 in range(4): |
|
776 | 780 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
777 | 781 | |
|
778 | 782 | xx_inv = numpy.linalg.inv(xx) |
|
779 | 783 | xx = xx_inv[:,0] |
|
780 | 784 | |
|
781 | 785 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
782 | 786 | yy = jcspectra[ip,mask_prof[ind],:] |
|
783 | 787 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
784 | 788 | |
|
785 | 789 | #Guardar Resultados |
|
786 | 790 | self.dataOut.data_spc = jspectra |
|
787 | 791 | self.dataOut.data_cspc = jcspectra |
|
788 | 792 | |
|
789 | 793 | return 1 |
|
790 | 794 | |
|
791 | 795 | def setRadarFrequency(self, frequency=None): |
|
792 | 796 | |
|
793 | 797 | if frequency != None: |
|
794 | 798 | self.dataOut.frequency = frequency |
|
795 | 799 | |
|
796 | 800 | return 1 |
|
797 | 801 | |
|
798 | 802 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
799 | 803 | #validacion de rango |
|
800 | 804 | if minHei == None: |
|
801 | 805 | minHei = self.dataOut.heightList[0] |
|
802 | 806 | |
|
803 | 807 | if maxHei == None: |
|
804 | 808 | maxHei = self.dataOut.heightList[-1] |
|
805 | 809 | |
|
806 | 810 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
807 | 811 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
808 | 812 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
809 | 813 | minHei = self.dataOut.heightList[0] |
|
810 | 814 | |
|
811 | 815 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
812 | 816 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
813 | 817 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
814 | 818 | maxHei = self.dataOut.heightList[-1] |
|
815 | 819 | |
|
816 | 820 | # validacion de velocidades |
|
817 | 821 | velrange = self.dataOut.getVelRange(1) |
|
818 | 822 | |
|
819 | 823 | if minVel == None: |
|
820 | 824 | minVel = velrange[0] |
|
821 | 825 | |
|
822 | 826 | if maxVel == None: |
|
823 | 827 | maxVel = velrange[-1] |
|
824 | 828 | |
|
825 | 829 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
826 | 830 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
827 | 831 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
828 | 832 | minVel = velrange[0] |
|
829 | 833 | |
|
830 | 834 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
831 | 835 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
832 | 836 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
833 | 837 | maxVel = velrange[-1] |
|
834 | 838 | |
|
835 | 839 | # seleccion de indices para rango |
|
836 | 840 | minIndex = 0 |
|
837 | 841 | maxIndex = 0 |
|
838 | 842 | heights = self.dataOut.heightList |
|
839 | 843 | |
|
840 | 844 | inda = numpy.where(heights >= minHei) |
|
841 | 845 | indb = numpy.where(heights <= maxHei) |
|
842 | 846 | |
|
843 | 847 | try: |
|
844 | 848 | minIndex = inda[0][0] |
|
845 | 849 | except: |
|
846 | 850 | minIndex = 0 |
|
847 | 851 | |
|
848 | 852 | try: |
|
849 | 853 | maxIndex = indb[0][-1] |
|
850 | 854 | except: |
|
851 | 855 | maxIndex = len(heights) |
|
852 | 856 | |
|
853 | 857 | if (minIndex < 0) or (minIndex > maxIndex): |
|
854 | 858 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
855 | 859 | |
|
856 | 860 | if (maxIndex >= self.dataOut.nHeights): |
|
857 | 861 | maxIndex = self.dataOut.nHeights-1 |
|
858 | 862 | |
|
859 | 863 | # seleccion de indices para velocidades |
|
860 | 864 | indminvel = numpy.where(velrange >= minVel) |
|
861 | 865 | indmaxvel = numpy.where(velrange <= maxVel) |
|
862 | 866 | try: |
|
863 | 867 | minIndexVel = indminvel[0][0] |
|
864 | 868 | except: |
|
865 | 869 | minIndexVel = 0 |
|
866 | 870 | |
|
867 | 871 | try: |
|
868 | 872 | maxIndexVel = indmaxvel[0][-1] |
|
869 | 873 | except: |
|
870 | 874 | maxIndexVel = len(velrange) |
|
871 | 875 | |
|
872 | 876 | #seleccion del espectro |
|
873 | 877 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
874 | 878 | #estimacion de ruido |
|
875 | 879 | noise = numpy.zeros(self.dataOut.nChannels) |
|
876 | 880 | |
|
877 | 881 | for channel in range(self.dataOut.nChannels): |
|
878 | 882 | daux = data_spc[channel,:,:] |
|
879 | 883 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
880 | 884 | |
|
881 | 885 | self.dataOut.noise_estimation = noise.copy() |
|
882 | 886 | |
|
883 | 887 | return 1 |
|
884 | 888 | |
|
885 | 889 | class IncohInt(Operation): |
|
886 | 890 | |
|
887 | 891 | |
|
888 | 892 | __profIndex = 0 |
|
889 | 893 | __withOverapping = False |
|
890 | 894 | |
|
891 | 895 | __byTime = False |
|
892 | 896 | __initime = None |
|
893 | 897 | __lastdatatime = None |
|
894 | 898 | __integrationtime = None |
|
895 | 899 | |
|
896 | 900 | __buffer_spc = None |
|
897 | 901 | __buffer_cspc = None |
|
898 | 902 | __buffer_dc = None |
|
899 | 903 | |
|
900 | 904 | __dataReady = False |
|
901 | 905 | |
|
902 | 906 | __timeInterval = None |
|
903 | 907 | |
|
904 | 908 | n = None |
|
905 | 909 | |
|
906 | 910 | |
|
907 | 911 | |
|
908 | 912 | def __init__(self, **kwargs): |
|
909 | 913 | |
|
910 | 914 | Operation.__init__(self, **kwargs) |
|
911 | 915 | # self.isConfig = False |
|
912 | 916 | |
|
913 | 917 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
914 | 918 | """ |
|
915 | 919 | Set the parameters of the integration class. |
|
916 | 920 | |
|
917 | 921 | Inputs: |
|
918 | 922 | |
|
919 | 923 | n : Number of coherent integrations |
|
920 | 924 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
921 | 925 | overlapping : |
|
922 | 926 | |
|
923 | 927 | """ |
|
924 | 928 | |
|
925 | 929 | self.__initime = None |
|
926 | 930 | self.__lastdatatime = 0 |
|
927 | 931 | |
|
928 | 932 | self.__buffer_spc = 0 |
|
929 | 933 | self.__buffer_cspc = 0 |
|
930 | 934 | self.__buffer_dc = 0 |
|
931 | 935 | |
|
932 | 936 | self.__profIndex = 0 |
|
933 | 937 | self.__dataReady = False |
|
934 | 938 | self.__byTime = False |
|
935 | 939 | |
|
936 | 940 | if n is None and timeInterval is None: |
|
937 | 941 | raise ValueError, "n or timeInterval should be specified ..." |
|
938 | 942 | |
|
939 | 943 | if n is not None: |
|
940 | 944 | self.n = int(n) |
|
941 | 945 | else: |
|
942 | 946 | self.__integrationtime = int(timeInterval) #if (type(timeInterval)!=integer) -> change this line |
|
943 | 947 | self.n = None |
|
944 | 948 | self.__byTime = True |
|
945 | 949 | |
|
946 | 950 | def putData(self, data_spc, data_cspc, data_dc): |
|
947 | 951 | |
|
948 | 952 | """ |
|
949 | 953 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
950 | 954 | |
|
951 | 955 | """ |
|
952 | 956 | |
|
953 | 957 | self.__buffer_spc += data_spc |
|
954 | 958 | |
|
955 | 959 | if data_cspc is None: |
|
956 | 960 | self.__buffer_cspc = None |
|
957 | 961 | else: |
|
958 | 962 | self.__buffer_cspc += data_cspc |
|
959 | 963 | |
|
960 | 964 | if data_dc is None: |
|
961 | 965 | self.__buffer_dc = None |
|
962 | 966 | else: |
|
963 | 967 | self.__buffer_dc += data_dc |
|
964 | 968 | |
|
965 | 969 | self.__profIndex += 1 |
|
966 | 970 | |
|
967 | 971 | return |
|
968 | 972 | |
|
969 | 973 | def pushData(self): |
|
970 | 974 | """ |
|
971 | 975 | Return the sum of the last profiles and the profiles used in the sum. |
|
972 | 976 | |
|
973 | 977 | Affected: |
|
974 | 978 | |
|
975 | 979 | self.__profileIndex |
|
976 | 980 | |
|
977 | 981 | """ |
|
978 | 982 | |
|
979 | 983 | data_spc = self.__buffer_spc |
|
980 | 984 | data_cspc = self.__buffer_cspc |
|
981 | 985 | data_dc = self.__buffer_dc |
|
982 | 986 | n = self.__profIndex |
|
983 | 987 | |
|
984 | 988 | self.__buffer_spc = 0 |
|
985 | 989 | self.__buffer_cspc = 0 |
|
986 | 990 | self.__buffer_dc = 0 |
|
987 | 991 | self.__profIndex = 0 |
|
988 | 992 | |
|
989 | 993 | return data_spc, data_cspc, data_dc, n |
|
990 | 994 | |
|
991 | 995 | def byProfiles(self, *args): |
|
992 | 996 | |
|
993 | 997 | self.__dataReady = False |
|
994 | 998 | avgdata_spc = None |
|
995 | 999 | avgdata_cspc = None |
|
996 | 1000 | avgdata_dc = None |
|
997 | 1001 | |
|
998 | 1002 | self.putData(*args) |
|
999 | 1003 | |
|
1000 | 1004 | if self.__profIndex == self.n: |
|
1001 | 1005 | |
|
1002 | 1006 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1003 | 1007 | self.n = n |
|
1004 | 1008 | self.__dataReady = True |
|
1005 | 1009 | |
|
1006 | 1010 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1007 | 1011 | |
|
1008 | 1012 | def byTime(self, datatime, *args): |
|
1009 | 1013 | |
|
1010 | 1014 | self.__dataReady = False |
|
1011 | 1015 | avgdata_spc = None |
|
1012 | 1016 | avgdata_cspc = None |
|
1013 | 1017 | avgdata_dc = None |
|
1014 | 1018 | |
|
1015 | 1019 | self.putData(*args) |
|
1016 | 1020 | |
|
1017 | 1021 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1018 | 1022 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1019 | 1023 | self.n = n |
|
1020 | 1024 | self.__dataReady = True |
|
1021 | 1025 | |
|
1022 | 1026 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1023 | 1027 | |
|
1024 | 1028 | def integrate(self, datatime, *args): |
|
1025 | 1029 | |
|
1026 | 1030 | if self.__profIndex == 0: |
|
1027 | 1031 | self.__initime = datatime |
|
1028 | 1032 | |
|
1029 | 1033 | if self.__byTime: |
|
1030 | 1034 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
1031 | 1035 | else: |
|
1032 | 1036 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1033 | 1037 | |
|
1034 | 1038 | if not self.__dataReady: |
|
1035 | 1039 | return None, None, None, None |
|
1036 | 1040 | |
|
1037 | 1041 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1038 | 1042 | |
|
1039 | 1043 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1040 | 1044 | |
|
1041 | 1045 | if n==1: |
|
1042 | 1046 | return |
|
1043 | 1047 | |
|
1044 | 1048 | dataOut.flagNoData = True |
|
1045 | 1049 | |
|
1046 | 1050 | if not self.isConfig: |
|
1047 | 1051 | self.setup(n, timeInterval, overlapping) |
|
1048 | 1052 | self.isConfig = True |
|
1049 | 1053 | |
|
1050 | 1054 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1051 | 1055 | dataOut.data_spc, |
|
1052 | 1056 | dataOut.data_cspc, |
|
1053 | 1057 | dataOut.data_dc) |
|
1054 | 1058 | |
|
1055 | 1059 | if self.__dataReady: |
|
1056 | 1060 | |
|
1057 | 1061 | dataOut.data_spc = avgdata_spc |
|
1058 | 1062 | dataOut.data_cspc = avgdata_cspc |
|
1059 | 1063 | dataOut.data_dc = avgdata_dc |
|
1060 | 1064 | |
|
1061 | 1065 | dataOut.nIncohInt *= self.n |
|
1062 | 1066 | dataOut.utctime = avgdatatime |
|
1063 | 1067 | dataOut.flagNoData = False |
|
1064 | 1068 |
@@ -1,129 +1,130 | |||
|
1 | 1 | # DIAS 19 Y 20 FEB 2014 |
|
2 | 2 | # Comprobacion de Resultados DBS con SA |
|
3 | 3 | |
|
4 | 4 | import os, sys |
|
5 | 5 | |
|
6 | 6 | path = os.path.split(os.getcwd())[0] |
|
7 | 7 | path = os.path.split(path)[0] |
|
8 | 8 | |
|
9 | 9 | sys.path.insert(0, path) |
|
10 | 10 | |
|
11 | 11 | from schainpy.controller import Project |
|
12 | 12 | |
|
13 | 13 | desc = "SA Experiment Test" |
|
14 | 14 | filename = "SA2014050.xml" |
|
15 | 15 | |
|
16 | 16 | controllerObj = Project() |
|
17 | 17 | |
|
18 | 18 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | #Experimentos |
|
22 | 22 | |
|
23 | 23 | #2014050 19 Feb 2014 |
|
24 | 24 | path = '/media/joscanoa/84A65E64A65E5730/soporte/Data/MST/SA/d2014050' |
|
25 | 25 | pathFigure = '/media/joscanoa/84A65E64A65E5730/soporte/workspace/Graficos/SA/prueba1/' |
|
26 | 26 | xmin = '15.5' |
|
27 | 27 | xmax = '24' |
|
28 | 28 | startTime = '15:30:00' |
|
29 | 29 | filehdf5 = "SA_2014050.hdf5" |
|
30 | 30 | |
|
31 | 31 | #2014051 20 Feb 2014 |
|
32 | # path = '/home/soporte/Data/MST/SA/d2014051' | |
|
32 | path = '/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/' #'/home/soporte/Data/MST/SA/d2014051' | |
|
33 | 33 | # pathFigure = '/home/soporte/workspace/Graficos/SA/new/' |
|
34 | 34 | # xmin = '0.0' |
|
35 | 35 | # xmax = '8.0' |
|
36 | 36 | # startTime = '00:00:00' |
|
37 | 37 | # filehdf5 = "SA_2014051.hdf5" |
|
38 | 38 | |
|
39 | 39 | readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', |
|
40 | 40 | path=path, |
|
41 |
startDate='201 |
|
|
42 |
endDate='201 |
|
|
43 |
startTime= |
|
|
44 |
endTime=' |
|
|
41 | startDate='2017/08/22', | |
|
42 | endDate='2018/08/22', | |
|
43 | startTime='00:00:00', | |
|
44 | endTime='6:00:59', | |
|
45 | 45 | online=0, |
|
46 | 46 | delay=5, |
|
47 |
walk= |
|
|
48 | getblock=1, | |
|
49 | blocksize=32768) | |
|
47 | walk=1) | |
|
48 | #getblock=1, | |
|
49 | #blocksize=32768) | |
|
50 | 50 | |
|
51 | 51 | opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') |
|
52 | 52 | |
|
53 | 53 | |
|
54 | 54 | #-------------------------------------------------------------------------------------------------- |
|
55 | 55 | |
|
56 | 56 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId()) |
|
57 | 57 | |
|
58 | 58 | opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') |
|
59 | 59 | |
|
60 | 60 | opObj11 = procUnitConfObj0.addOperation(name='CohInt', optype='other') |
|
61 | 61 | # opObj11.addParameter(name='n', value='600', format='int') |
|
62 |
opObj11.addParameter(name='n', value=' |
|
|
62 | opObj11.addParameter(name='n', value='4', format='int') | |
|
63 | 63 | |
|
64 | 64 | opObj11 = procUnitConfObj0.addOperation(name='selectHeightsByIndex') |
|
65 | 65 | opObj11.addParameter(name='minIndex', value='10', format='float') |
|
66 | 66 | opObj11.addParameter(name='maxIndex', value='60', format='float') |
|
67 | 67 | #--------------------------------------------------------------------------------------------------- |
|
68 | 68 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj0.getId()) |
|
69 | 69 | procUnitConfObj1.addParameter(name='pairsList', value='(0,0),(1,1),(2,2),(3,3),(1,0),(2,3)', format='pairsList') |
|
70 | # procUnitConfObj1.addParameter(name='removeDC', value='1', format='bool') | |
|
70 | ||
|
71 | #procUnitConfObj1.addParameter(name='removeDC', value='1', format='bool') | |
|
71 | 72 | # #procUnitConfObj1.addParameter(name='lagT', value='0,1,2,3', format='intlist') |
|
72 | 73 | # |
|
73 | 74 | # opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other') |
|
74 | 75 | # opObj12.addParameter(name='id', value='1', format='int') |
|
75 | 76 | # opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str') |
|
76 | 77 | # opObj12.addParameter(name='save', value='1', format='bool') |
|
77 | 78 | # opObj12.addParameter(name='zmin', value='0', format='int') |
|
78 | 79 | # opObj12.addParameter(name='zmax', value='1', format='int') |
|
79 | 80 | # opObj12.addParameter(name='figpath', value = pathFigure, format='str') |
|
80 | 81 | # |
|
81 | 82 | # opObj12 = procUnitConfObj1.addOperation(name='removeNoise') |
|
82 | 83 | # opObj12.addParameter(name='mode', value='2', format='int') |
|
83 | 84 | # opObj12 = procUnitConfObj1.addOperation(name='calculateNormFactor') |
|
84 | 85 | # |
|
85 | 86 | # opObj12 = procUnitConfObj1.addOperation(name='CorrelationPlot', optype='other') |
|
86 | 87 | # opObj12.addParameter(name='id', value='2', format='int') |
|
87 | 88 | # opObj12.addParameter(name='wintitle', value='CrossCorrelation Plot', format='str') |
|
88 | 89 | # opObj12.addParameter(name='save', value='1', format='bool') |
|
89 | 90 | # opObj12.addParameter(name='zmin', value='0', format='int') |
|
90 | 91 | # opObj12.addParameter(name='zmax', value='1', format='int') |
|
91 | 92 | # opObj12.addParameter(name='figpath', value = pathFigure, format='str') |
|
92 | 93 | # |
|
93 | 94 | # #--------------------------------------------------------------------------------------------------- |
|
94 | 95 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='ParametersProc', inputId=procUnitConfObj1.getId()) |
|
95 | 96 | |
|
96 | 97 | opObj20 = procUnitConfObj2.addOperation(name='SALags', optype='other') |
|
97 | 98 | # |
|
98 | 99 | opObj21 = procUnitConfObj2.addOperation(name='WindProfiler', optype='other') |
|
99 | 100 | opObj21.addParameter(name='technique', value='SA', format='str') |
|
100 | 101 | # # opObj21.addParameter(name='correctFactor', value='-1', format='float') |
|
101 |
opObj21.addParameter(name='positionX', value=' |
|
|
102 |
opObj21.addParameter(name='positionY', value=' |
|
|
103 |
opObj21.addParameter(name='azimuth', value=' |
|
|
104 | ||
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
# |
|
|
109 |
# |
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
102 | opObj21.addParameter(name='positionX', value='1.5,0,1.5', format='floatlist') | |
|
103 | opObj21.addParameter(name='positionY', value='0.875,0,-0.875', format='floatlist') | |
|
104 | opObj21.addParameter(name='azimuth', value='0.0', format='float') | |
|
105 | ||
|
106 | opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other') | |
|
107 | opObj22.addParameter(name='id', value='4', format='int') | |
|
108 | opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str') | |
|
109 | #opObj22.addParameter(name='save', value='1', format='bool') | |
|
110 | #opObj22.addParameter(name='figpath', value = pathFigure, format='str') | |
|
111 | opObj22.addParameter(name='zmin', value='-15', format='int') | |
|
112 | opObj22.addParameter(name='zmax', value='15', format='int') | |
|
113 | opObj22.addParameter(name='zmin_ver', value='-80', format='float') | |
|
114 | opObj22.addParameter(name='zmax_ver', value='80', format='float') | |
|
115 | opObj22.addParameter(name='SNRmin', value='-20', format='int') | |
|
116 | opObj22.addParameter(name='SNRmax', value='40', format='int') | |
|
117 | opObj22.addParameter(name='SNRthresh', value='-3.5', format='float') | |
|
118 | opObj22.addParameter(name='xmin', value=xmin, format='float') | |
|
119 | opObj22.addParameter(name='xmax', value=xmax, format='float') | |
|
119 | 120 | |
|
120 | 121 | #----------------------------------------------------------------------------------- |
|
121 | 122 | |
|
122 | 123 | print "Escribiendo el archivo XML" |
|
123 | 124 | controllerObj.writeXml(filename) |
|
124 | 125 | print "Leyendo el archivo XML" |
|
125 | 126 | controllerObj.readXml(filename) |
|
126 | 127 | |
|
127 | 128 | controllerObj.createObjects() |
|
128 | 129 | controllerObj.connectObjects() |
|
129 | controllerObj.run() No newline at end of file | |
|
130 | controllerObj.run() |
@@ -1,1 +1,1 | |||
|
1 | <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="VoltageReader" id="1911" inputId="0" name="VoltageReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="VoltageReader" /><Parameter format="str" id="191112" name="path" value="/home/erick/Documents/Data/Claire_Data/raw" /><Parameter format="date" id="191113" name="startDate" value="2017/07/26" /><Parameter format="date" id="191114" name="endDate" value="2017/07/26" /><Parameter format="time" id="191115" name="startTime" value="10:02:00" /><Parameter format="time" id="191116" name="endTime" value="10:11:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="1" /></Operation><Operation id="19112" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="SpectraProc" id="1913" inputId="1912" name="SpectraProc"><Operation id="19131" name="run" priority="1" type="self"><Parameter format="int" id="191311" name="nFFTPoints" value="128" /><Parameter format="pairslist" id="191312" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="19132" name="removeDC" priority="2" type="self" /><Operation id="19133" name="IncohInt" priority="3" type="external"><Parameter format="float" id="191331" name="n" value="30" /></Operation><Operation id="19134" name="CrossSpectraPlot" priority="4" type="other"><Parameter format="str" id="191341" name="phase_cmap" value="bwr" /><Parameter format="int" id="191342" name="id" value="2005" /><Parameter format="str" id="191343" name="wintitle" value="CrossSpectraPlot_ShortPulse" /><Parameter format="str" id="191344" name="xaxis" value="Velocity" /><Parameter format="float" id="191345" name="ymin" value="1" /><Parameter format="int" id="191346" name="ymax" value="7" /><Parameter format="int" id="191347" name="zmin" value="15" /><Parameter format="int" id="191348" name="zmax" value="60" /><Parameter format="int" id="191349" name="save" value="2" /><Parameter format="str" id="191350" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images" /></Operation></ProcUnit><ProcUnit datatype="VoltageProc" id="1912" inputId="1911" name="VoltageProc"><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><Operation id="19123" name="selectHeights" priority="3" type="self"><Parameter format="float" id="191231" name="minHei" value="0" /><Parameter format="float" id="191232" name="maxHei" value="64" /></Operation></ProcUnit><ProcUnit datatype="Parameters" id="1914" inputId="1913" name="ParametersProc"><Operation id="19141" name="run" priority="1" type="self" /><Operation id="19142" name="GaussianFit" priority="2" type="other" /></ProcUnit></Project> No newline at end of file | |
|
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="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024/d2017234" /><Parameter format="date" id="191113" name="startDate" value="2017/08/22" /><Parameter format="date" id="191114" name="endDate" value="2017/08/22" /><Parameter format="time" id="191115" name="startTime" value="02:00:00" /><Parameter format="time" id="191116" name="endTime" value="06:00:00" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="0" /></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="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="FullSpectralAnalysis" priority="3" type="other"><Parameter format="float" id="191331" name="SNRlimit" value="-16" /><Parameter format="float" id="191332" name="E01" value="1.500" /><Parameter format="float" id="191333" name="E02" value="1.500" /><Parameter format="float" id="191334" name="E12" value="0" /><Parameter format="float" id="191335" name="N01" value="0.875" /><Parameter format="float" id="191336" name="N02" value="-0.875" /><Parameter format="float" id="191337" name="N12" value="-1.750" /></Operation><Operation id="19134" name="ParamWriter" priority="4" type="other"><Parameter format="str" id="191341" name="path" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024" /><Parameter format="int" id="191342" name="blocksPerFile" value="100" /><Parameter format="list" id="191343" name="metadataList" value="heightList,timeZone,paramInterval" /><Parameter format="list" id="191344" name="dataList" value="data_output,data_SNR,utctime,utctimeInit" /></Operation></ProcUnit><ProcUnit datatype="SpectraProc" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self"><Parameter format="pairslist" id="191211" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="19122" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="191221" name="frequency" value="445.09e6" /></Operation><Operation id="19123" name="IncohInt" priority="3" type="external"><Parameter format="float" id="191231" name="n" value="5" /></Operation><Operation id="19124" name="SpectraPlot" priority="4" type="external"><Parameter format="int" id="191241" name="id" value="11" /><Parameter format="str" id="191242" name="wintitle" value="SpectraPlot" /><Parameter format="str" id="191243" name="xaxis" value="frequency" /><Parameter format="float" id="191244" name="ymin" value="1" /><Parameter format="int" id="191245" name="ymax" value="5" /><Parameter format="int" id="191246" name="zmin" value="15" /><Parameter format="int" id="191247" name="zmax" value="50" /><Parameter format="int" id="191248" name="save" value="2" /><Parameter format="int" id="191249" name="save" value="5" /><Parameter format="str" id="191250" name="figpath" value="/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images/FirstResults1024" /></Operation><Operation id="19125" name="CrossSpectraPlot" priority="5" type="other"><Parameter format="int" id="191251" name="id" value="2005" /><Parameter format="str" id="191252" name="wintitle" value="CrossSpectraPlot_ShortPulse" /><Parameter format="str" id="191253" name="xaxis" value="Velocity" /><Parameter format="float" id="191254" name="xmin" value="-10" /><Parameter format="float" id="191255" name="xmax" value="10" /><Parameter format="int" id="191256" name="zmin" value="15" /><Parameter format="int" id="191257" name="zmax" value="50" /><Parameter format="str" id="191258" name="phase_cmap" value="bwr" /><Parameter format="float" id="191259" name="ymin" value="1" /><Parameter format="float" id="191260" name="ymax" value="5" /></Operation></ProcUnit></Project> No newline at end of file |
@@ -1,171 +1,63 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Nov 09, 2016 |
|
3 | 3 | |
|
4 | 4 | @author: roj- LouVD |
|
5 | 5 | ''' |
|
6 | 6 | import os, sys |
|
7 | 7 | |
|
8 | 8 | |
|
9 | 9 | path = os.path.split(os.getcwd())[0] |
|
10 | 10 | path = os.path.split(path)[0] |
|
11 | 11 | |
|
12 | 12 | sys.path.insert(0, path) |
|
13 | 13 | |
|
14 | 14 | from schainpy.controller import Project |
|
15 | 15 | |
|
16 | 16 | filename = 'test1.xml' |
|
17 | 17 | # path = '/home/jespinoza/workspace/data/bltr/' |
|
18 |
path = '/me |
|
|
18 | path = '/home/erick/Documents/Data/BLTR_Data/sswma/'#'/media/erick/6F60F7113095A154/BLTR/' | |
|
19 | 19 | desc = "read bltr data sswma file" |
|
20 | 20 | figpath = '/media/erick/6F60F7113095A154/BLTR/' |
|
21 | 21 | pathhdf5 = '/tmp/' |
|
22 | 22 | |
|
23 | 23 | controllerObj = Project() |
|
24 | 24 | |
|
25 | 25 | controllerObj.setup(id = '191', name='test1', description=desc) |
|
26 |
readUnitConfObj = controllerObj.addReadUnit(datatype=' |
|
|
26 | readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRParamReader', | |
|
27 | 27 | path=path, |
|
28 | 28 | startDate='2017/01/17', |
|
29 | 29 | endDate='2018/01/01', |
|
30 |
startTime='0 |
|
|
30 | startTime='06:00:00', | |
|
31 | 31 | endTime='23:59:59', |
|
32 |
|
|
|
32 | verbose=0, | |
|
33 | ) | |
|
33 | 34 | |
|
34 |
procUnitConfObj1 = controllerObj.addProcUnit(datatype='BLTRProc |
|
|
35 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='BLTRParametersProc', | |
|
35 | 36 | inputId=readUnitConfObj.getId()) |
|
37 | ||
|
38 | procUnitConfObj1.addParameter(name='mode', value='1', format='int') | |
|
39 | # procUnitConfObj1.addParameter(name='snr_threshold', value='10', format='float') | |
|
36 | 40 | |
|
37 | '''-------------------------------------------Processing--------------------------------------------''' | |
|
38 | ||
|
39 | '''MODE 1: LOW ATMOSPHERE: 0- 3 km''' | |
|
40 | # opObj10 = procUnitConfObj1.addOperation(name='SnrFilter') | |
|
41 | # opObj10.addParameter(name='snr_val', value='-10', format='float') | |
|
42 | # opObj10.addParameter(name='modetofilter', value='1', format='int') | |
|
43 | # | |
|
44 | # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter') | |
|
45 | # opObj10.addParameter(name='svalue', value='meridional', format='str') | |
|
46 | # opObj10.addParameter(name='svalue2', value='inTime', format='str') | |
|
47 | # opObj10.addParameter(name='method', value='0', format='float') | |
|
48 | # opObj10.addParameter(name='factor', value='1', format='float') | |
|
49 | # opObj10.addParameter(name='filter', value='0', format='float') | |
|
50 | # opObj10.addParameter(name='npoints', value='5', format='float') | |
|
51 | # opObj10.addParameter(name='modetofilter', value='1', format='int') | |
|
52 | # # | |
|
53 | # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter') | |
|
54 | # opObj10.addParameter(name='svalue', value='zonal', format='str') | |
|
55 | # opObj10.addParameter(name='svalue2', value='inTime', format='str') | |
|
56 | # opObj10.addParameter(name='method', value='0', format='float') | |
|
57 | # opObj10.addParameter(name='factor', value='1', format='float') | |
|
58 | # opObj10.addParameter(name='filter', value='0', format='float') | |
|
59 | # opObj10.addParameter(name='npoints', value='5', format='float') | |
|
60 | # opObj10.addParameter(name='modetofilter', value='1', format='int') | |
|
61 | # # | |
|
62 | # opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter') | |
|
63 | # opObj10.addParameter(name='svalue', value='vertical', format='str') | |
|
64 | # opObj10.addParameter(name='svalue2', value='inHeight', format='str') | |
|
65 | # opObj10.addParameter(name='method', value='0', format='float') | |
|
66 | # opObj10.addParameter(name='factor', value='2', format='float') | |
|
67 | # opObj10.addParameter(name='filter', value='0', format='float') | |
|
68 | # opObj10.addParameter(name='npoints', value='9', format='float') | |
|
69 | # opObj10.addParameter(name='modetofilter', value='1', format='int') | |
|
70 | # | |
|
71 | ||
|
72 | ''' MODE 2: 0 - 10 km ''' | |
|
73 | ||
|
74 | opObj10 = procUnitConfObj1.addOperation(name='SnrFilter') | |
|
75 | opObj10.addParameter(name='snr_val', value='-20', format='float') | |
|
76 | opObj10.addParameter(name='modetofilter', value='2', format='int') | |
|
77 | ||
|
78 | opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter') | |
|
79 | opObj10.addParameter(name='svalue', value='meridional', format='str') | |
|
80 | opObj10.addParameter(name='svalue2', value='inTime', format='str') | |
|
81 | opObj10.addParameter(name='method', value='0', format='float') | |
|
82 | opObj10.addParameter(name='factor', value='2', format='float') | |
|
83 | opObj10.addParameter(name='filter', value='0', format='float') | |
|
84 | opObj10.addParameter(name='npoints', value='9', format='float') | |
|
85 | opObj10.addParameter(name='modetofilter', value='2', format='int') | |
|
86 | # # | |
|
87 | opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter') | |
|
88 | opObj10.addParameter(name='svalue', value='zonal', format='str') | |
|
89 | opObj10.addParameter(name='svalue2', value='inTime', format='str') | |
|
90 | opObj10.addParameter(name='method', value='0', format='float') | |
|
91 | opObj10.addParameter(name='factor', value='2', format='float') | |
|
92 | opObj10.addParameter(name='filter', value='0', format='float') | |
|
93 | opObj10.addParameter(name='npoints', value='9', format='float') | |
|
94 | opObj10.addParameter(name='modetofilter', value='2', format='int') | |
|
95 | # # | |
|
96 | opObj10 = procUnitConfObj1.addOperation(name='OutliersFilter') | |
|
97 | opObj10.addParameter(name='svalue', value='vertical', format='str') | |
|
98 | opObj10.addParameter(name='svalue2', value='inHeight', format='str') | |
|
99 | opObj10.addParameter(name='method', value='0', format='float') | |
|
100 | opObj10.addParameter(name='factor', value='2', format='float') | |
|
101 | opObj10.addParameter(name='filter', value='0', format='float') | |
|
102 | opObj10.addParameter(name='npoints', value='9', format='float') | |
|
103 | opObj10.addParameter(name='modetofilter', value='2', format='int') | |
|
104 | ||
|
105 | # '''-----------------------------------------Writing-------------------------------------------''' | |
|
106 | # | |
|
107 | # # opObj10 = procUnitConfObj1.addOperation(name='testBLTRWriter',optype='other') | |
|
108 | # # opObj10.addParameter(name='path', value = pathhdf5) | |
|
109 | # # opObj10.addParameter(name='modetowrite', value = '2',format='int') | |
|
110 | # # | |
|
111 | # # opObj10 = procUnitConfObj1.addOperation(name='testBLTRWriter',optype='other') | |
|
112 | # # opObj10.addParameter(name='path', value = pathhdf5) | |
|
113 | # # opObj10.addParameter(name='modetowrite', value = '1',format='int') | |
|
114 | # | |
|
115 | # '''----------------------------------------Plotting--------------------------------------------''' | |
|
116 | # | |
|
117 | opObj10 = procUnitConfObj1.addOperation(name='prePlot') | |
|
118 | opObj10.addParameter(name='modeselect',value='1',format='int') | |
|
119 | # # | |
|
120 | opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other') | |
|
121 | opObj10.addParameter(name='id', value='1', format='int') | |
|
122 | opObj10.addParameter(name='wintitle', value='', format='str') | |
|
123 | opObj10.addParameter(name='channelList', value='0', format='intlist') | |
|
124 | #opObj10.addParameter(name='save', value='1', format='bool') | |
|
125 | #opObj10.addParameter(name='figpath', value=figpath, format='str') | |
|
126 | opObj10.addParameter(name='SNRmin', value='-10', format='int') | |
|
127 | opObj10.addParameter(name='SNRmax', value='50', format='int') | |
|
128 | opObj10.addParameter(name='SNRthresh', value='0', format='float') | |
|
129 | opObj10.addParameter(name='xmin', value='0', format='float') | |
|
130 | opObj10.addParameter(name='xmax', value='24', format='float') | |
|
131 | opObj10.addParameter(name='ymax', value='3', format='float') | |
|
132 | opObj10.addParameter(name='zmin', value='-20', format='float') | |
|
133 | opObj10.addParameter(name='zmax', value='20', format='float') | |
|
134 | opObj10.addParameter(name='zmin_ver', value='-200', format='float') | |
|
135 | opObj10.addParameter(name='zmax_ver', value='200', format='float') | |
|
136 | #opObj10.addParameter(name='showprofile', value='1', format='bool') | |
|
137 | #opObj10.addParameter(name='show', value='1', format='bool') | |
|
138 | ||
|
139 | opObj10 = procUnitConfObj1.addOperation(name='prePlot') | |
|
140 | opObj10.addParameter(name='modeselect',value='2',format='int') | |
|
141 | # | |
|
41 | ||
|
142 | 42 | opObj10 = procUnitConfObj1.addOperation(name='WindProfilerPlot', optype='other') |
|
143 | 43 | opObj10.addParameter(name='id', value='2', format='int') |
|
144 | 44 | opObj10.addParameter(name='wintitle', value='', format='str') |
|
145 | #opObj10.addParameter(name='channelList', value='0', format='intlist') | |
|
146 | opObj10.addParameter(name='save', value='1', format='bool') | |
|
147 | opObj10.addParameter(name='figpath', value=figpath, format='str') | |
|
45 | ||
|
46 | # opObj10.addParameter(name='save', value='1', format='bool') | |
|
47 | # opObj10.addParameter(name='figpath', value=figpath, format='str') | |
|
148 | 48 | opObj10.addParameter(name='SNRmin', value='-20', format='int') |
|
149 | 49 | opObj10.addParameter(name='SNRmax', value='40', format='int') |
|
150 | 50 | opObj10.addParameter(name='SNRthresh', value='0', format='float') |
|
151 | 51 | opObj10.addParameter(name='xmin', value='0', format='float') |
|
152 | 52 | opObj10.addParameter(name='xmax', value='24', format='float') |
|
153 | 53 | opObj10.addParameter(name='ymin', value='0', format='float') |
|
154 | 54 | opObj10.addParameter(name='ymax', value='7', format='float') |
|
155 | 55 | opObj10.addParameter(name='zmin', value='-4', format='float') |
|
156 | 56 | opObj10.addParameter(name='zmax', value='4', format='float') |
|
157 | 57 | opObj10.addParameter(name='zmin_ver', value='-200', format='float') |
|
158 | 58 | opObj10.addParameter(name='zmax_ver', value='200', format='float') |
|
159 | 59 | #opObj10.addParameter(name='showprofile', value='1', format='bool') |
|
160 | 60 | #opObj10.addParameter(name='show', value='1', format='bool') |
|
161 | 61 | |
|
162 | # # print "Escribiendo el archivo XML" | |
|
163 | # controllerObj.writeXml(filename) | |
|
164 | # # print "Leyendo el archivo XML" | |
|
165 | # controllerObj.readXml(filename) | |
|
166 | ||
|
167 | # controllerObj.createObjects() | |
|
168 | # controllerObj.connectObjects() | |
|
169 | # controllerObj.run() | |
|
170 | 62 | controllerObj.start() |
|
171 | 63 |
@@ -1,151 +1,151 | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | import os, sys |
|
3 | 3 | |
|
4 | 4 | # path = os.path.dirname(os.getcwd()) |
|
5 | 5 | # path = os.path.join(path, 'source') |
|
6 | 6 | # sys.path.insert(0, '../') |
|
7 | 7 | |
|
8 | 8 | from schainpy.controller import Project |
|
9 | 9 | |
|
10 | 10 | xmin = '15.5' |
|
11 | 11 | xmax = '24' |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | desc = "ProcBLTR Test" |
|
15 | 15 | filename = "ProcBLTR.xml" |
|
16 | 16 | figpath = '/media/erick/6F60F7113095A154/BLTR' |
|
17 | 17 | |
|
18 | 18 | controllerObj = Project() |
|
19 | 19 | |
|
20 | 20 | |
|
21 | 21 | controllerObj.setup(id='191', name='test01', description=desc) |
|
22 | 22 | |
|
23 | readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRReader', | |
|
24 | path='/media/erick/6F60F7113095A154/BLTR/', | |
|
25 | ||
|
23 | readUnitConfObj = controllerObj.addReadUnit(datatype='BLTRSpectraReader', | |
|
24 | #path='/media/erick/6F60F7113095A154/BLTR/', | |
|
25 | path='/home/erick/Documents/Data/BLTR_Data/fdt/', | |
|
26 | 26 | endDate='2017/10/19', |
|
27 | 27 | startTime='13:00:00', |
|
28 | 28 | startDate='2016/11/8', |
|
29 | 29 | endTime='23:59:59', |
|
30 | 30 | |
|
31 | 31 | |
|
32 | 32 | online=0, |
|
33 | 33 | walk=0, |
|
34 | 34 | ReadMode='1') |
|
35 | 35 | # expLabel='') |
|
36 | 36 | |
|
37 | 37 | # opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock') |
|
38 | 38 | |
|
39 | 39 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
40 | 40 | |
|
41 | 41 | |
|
42 | ||
|
43 | 42 | opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
44 |
opObj11.addParameter(name='n', value=' |
|
|
43 | opObj11.addParameter(name='n', value='2', format='float') | |
|
45 | 44 | |
|
46 | 45 | opObj10 = procUnitConfObj1.addOperation(name='removeDC') |
|
46 | #opObj10 = procUnitConfObj1.addOperation(name='removeInterference2') | |
|
47 | 47 | |
|
48 | 48 | # opObj10 = procUnitConfObj1.addOperation(name='calcMag') |
|
49 | 49 | |
|
50 | 50 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
51 | 51 | # opObj11.addParameter(name='id', value='21', format='int') |
|
52 | 52 | # opObj11.addParameter(name='wintitle', value='SpectraCutPlot', format='str') |
|
53 | 53 | # opObj11.addParameter(name='xaxis', value='frequency', format='str') |
|
54 | 54 | # opObj11.addParameter(name='colormap', value='winter', format='str') |
|
55 | 55 | # opObj11.addParameter(name='xmin', value='-0.005', format='float') |
|
56 | 56 | # opObj11.addParameter(name='xmax', value='0.005', format='float') |
|
57 | 57 | # #opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
58 | 58 | # #opObj10.addParameter(name='channelList', value='0,1', format='intlist') |
|
59 | 59 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
60 | 60 | # opObj11.addParameter(name='id', value='21', format='int') |
|
61 | 61 | # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') |
|
62 | 62 | # #opObj11.addParameter(name='xaxis', value='Velocity', format='str') |
|
63 | 63 | |
|
64 | 64 | # opObj11.addParameter(name='xaxis', value='velocity', format='str') |
|
65 | 65 | # opObj11.addParameter(name='xmin', value='-0.005', format='float') |
|
66 | 66 | # opObj11.addParameter(name='xmax', value='0.005', format='float') |
|
67 | 67 | |
|
68 | 68 | # opObj11.addParameter(name='ymin', value='225', format='float') |
|
69 | 69 | # opObj11.addParameter(name='ymax', value='3000', format='float') |
|
70 | 70 | # opObj11.addParameter(name='zmin', value='-100', format='int') |
|
71 | 71 | # opObj11.addParameter(name='zmax', value='-65', format='int') |
|
72 | 72 | |
|
73 | 73 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') |
|
74 | 74 | # opObj11.addParameter(name='id', value='10', format='int') |
|
75 | 75 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
76 | 76 | # opObj11.addParameter(name='ymin', value='0', format='float') |
|
77 | 77 | # opObj11.addParameter(name='ymax', value='4000', format='float') |
|
78 | 78 | # #opObj11.addParameter(name='zmin', value='-100', format='int') |
|
79 | 79 | # #opObj11.addParameter(name='zmax', value='-70', format='int') |
|
80 | 80 | # opObj11.addParameter(name='zmin', value='-90', format='int') |
|
81 | 81 | # opObj11.addParameter(name='zmax', value='-40', format='int') |
|
82 | 82 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
83 | 83 | # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int') |
|
84 | 84 | |
|
85 | 85 | opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') |
|
86 | 86 | procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList') |
|
87 | 87 | opObj11.addParameter(name='id', value='2005', format='int') |
|
88 | 88 | opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str') |
|
89 | 89 | # opObj11.addParameter(name='exp_code', value='13', format='int') |
|
90 | 90 | opObj11.addParameter(name='xaxis', value='Velocity', format='str') |
|
91 | 91 | #opObj11.addParameter(name='xmin', value='-10', format='float') |
|
92 | 92 | #opObj11.addParameter(name='xmax', value='10', format='float') |
|
93 | 93 | #opObj11.addParameter(name='ymin', value='225', format='float') |
|
94 | 94 | #opObj11.addParameter(name='ymax', value='3000', format='float') |
|
95 | 95 | #opObj11.addParameter(name='phase_min', value='-4', format='int') |
|
96 | 96 | #opObj11.addParameter(name='phase_max', value='4', format='int') |
|
97 | 97 | |
|
98 | 98 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='CorrelationProc', inputId=procUnitConfObj1.getId()) |
|
99 | 99 | # procUnitConfObj2.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList') |
|
100 | 100 | |
|
101 | 101 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId()) |
|
102 | 102 | opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other') |
|
103 | 103 | opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other') |
|
104 |
opObj22.addParameter(name='SNRlimit', value=' |
|
|
105 | # | |
|
104 | opObj22.addParameter(name='SNRlimit', value='7', format='float') | |
|
105 | ||
|
106 | 106 | opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other') |
|
107 | 107 | opObj22.addParameter(name='id', value='4', format='int') |
|
108 | 108 | opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str') |
|
109 | 109 | opObj22.addParameter(name='save', value='1', format='bool') |
|
110 | 110 | # opObj22.addParameter(name='figpath', value = '/home/erick/Pictures', format='str') |
|
111 | 111 | |
|
112 | 112 | opObj22.addParameter(name='zmin', value='-20', format='int') |
|
113 | 113 | opObj22.addParameter(name='zmax', value='20', format='int') |
|
114 |
opObj22.addParameter(name='zmin_ver', value='- |
|
|
115 |
opObj22.addParameter(name='zmax_ver', value=' |
|
|
114 | opObj22.addParameter(name='zmin_ver', value='-300', format='float') | |
|
115 | opObj22.addParameter(name='zmax_ver', value='300', format='float') | |
|
116 | 116 | opObj22.addParameter(name='SNRmin', value='-5', format='int') |
|
117 | 117 | opObj22.addParameter(name='SNRmax', value='30', format='int') |
|
118 | 118 | # opObj22.addParameter(name='SNRthresh', value='-3.5', format='float') |
|
119 | 119 | opObj22.addParameter(name='xmin', value='0', format='float') |
|
120 | 120 | opObj22.addParameter(name='xmax', value='24', format='float') |
|
121 | 121 | opObj22.addParameter(name='ymin', value='225', format='float') |
|
122 | 122 | #opObj22.addParameter(name='ymax', value='2000', format='float') |
|
123 | 123 | opObj22.addParameter(name='save', value='1', format='int') |
|
124 | 124 | opObj22.addParameter(name='figpath', value=figpath, format='str') |
|
125 | 125 | |
|
126 | 126 | |
|
127 | 127 | # opObj11.addParameter(name='pairlist', value='(1,0),(0,2),(1,2)', format='pairsList') |
|
128 | 128 | #opObj10 = procUnitConfObj1.addOperation(name='selectHeights') |
|
129 | 129 | #opObj10.addParameter(name='minHei', value='225', format='float') |
|
130 | 130 | #opObj10.addParameter(name='maxHei', value='1000', format='float') |
|
131 | 131 | |
|
132 | 132 | # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other') |
|
133 | 133 | # opObj11.addParameter(name='id', value='102', format='int') |
|
134 | 134 | # opObj11.addParameter(name='wintitle', value='Coherence', format='str') |
|
135 | 135 | # opObj11.addParameter(name='ymin', value='225', format='float') |
|
136 | 136 | # opObj11.addParameter(name='ymax', value='4000', format='float') |
|
137 | 137 | |
|
138 | 138 | # opObj11.addParameter(name='phase_cmap', value='jet', format='str') |
|
139 | 139 | # opObj11.addParameter(name='xmin', value='8.5', format='float') |
|
140 | 140 | # opObj11.addParameter(name='xmax', value='9.5', format='float') |
|
141 | 141 | # opObj11.addParameter(name='figpath', value=figpath, format='str') |
|
142 | 142 | # opObj11.addParameter(name='save', value=1, format='bool') |
|
143 | 143 | # opObj11.addParameter(name='pairsList', value='(1,0),(3,2)', format='pairsList') |
|
144 | 144 | |
|
145 | 145 | # opObj12 = procUnitConfObj1.addOperation(name='PublishData', optype='other') |
|
146 | 146 | # opObj12.addParameter(name='zeromq', value=1, format='int') |
|
147 | 147 | # opObj12.addParameter(name='verbose', value=0, format='bool') |
|
148 | 148 | # opObj12.addParameter(name='server', value='erick2', format='str') |
|
149 | 149 | controllerObj.start() |
|
150 | 150 | |
|
151 | 151 |
@@ -1,104 +1,112 | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | ''' |
|
3 | 3 | Created on Jul 7, 2014 |
|
4 | 4 | |
|
5 | 5 | @author: roj-idl71 |
|
6 | 6 | ''' |
|
7 | 7 | import os, sys |
|
8 | 8 | |
|
9 | 9 | from schainpy.controller import Project |
|
10 | 10 | |
|
11 | 11 | def main(): |
|
12 | 12 | desc = "Segundo Test" |
|
13 | 13 | filename = "schain.xml" |
|
14 | 14 | |
|
15 | 15 | controllerObj = Project() |
|
16 | 16 | |
|
17 | 17 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
18 | 18 | |
|
19 | 19 | readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra', |
|
20 |
path='/ |
|
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
|
20 | path='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdata', | |
|
21 | #path='/home/erick/Documents/Data/Claire_Data/raw', | |
|
22 | startDate='2017/07/20', | |
|
23 | endDate='2017/07/26', | |
|
24 | startTime='10:02:00', | |
|
25 | endTime='10:11:00', | |
|
25 | 26 | online=0, |
|
26 |
walk= |
|
|
27 |
|
|
|
27 | walk=1) | |
|
28 | # path='/home/erick/Documents/Data/d2015106', | |
|
29 | # startDate='2010/12/18', | |
|
30 | # endDate='2017/12/22', | |
|
31 | # startTime='00:00:00', | |
|
32 | # endTime='23:59:59', | |
|
33 | # online=0, | |
|
34 | # walk=0, | |
|
35 | # expLabel='') | |
|
28 | 36 | |
|
29 | 37 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
30 | 38 | |
|
31 | 39 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
32 | 40 | opObj10.addParameter(name='channelList', value='0,1', format='intlist') |
|
33 | 41 | |
|
34 | 42 | #opObj10 = procUnitConfObj1.addOperation(name='selectHeights') |
|
35 | 43 | #opObj10.addParameter(name='minHei', value='90', format='float') |
|
36 | 44 | #opObj10.addParameter(name='maxHei', value='180', format='float') |
|
37 | 45 | |
|
38 | 46 | opObj10 = procUnitConfObj1.addOperation(name='removeDC') |
|
39 | 47 | |
|
40 | 48 | #opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
41 | 49 | #opObj12.addParameter(name='n', value='1', format='int') |
|
42 | 50 | |
|
43 | 51 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
44 | 52 | opObj11.addParameter(name='id', value='1', format='int') |
|
45 | 53 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
46 | 54 | opObj11.addParameter(name='xaxis', value='velocity', format='str') |
|
47 | 55 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
48 | 56 | opObj11.addParameter(name='save', value='1', format='int') |
|
49 | 57 | opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106') |
|
50 | 58 | |
|
51 | 59 | #opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') |
|
52 | 60 | #opObj11.addParameter(name='id', value='10', format='int') |
|
53 | 61 | #opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
54 | 62 | # opObj11.addParameter(name='xmin', value='21', format='float') |
|
55 | 63 | # opObj11.addParameter(name='xmax', value='22', format='float') |
|
56 | 64 | #opObj11.addParameter(name='zmin', value='12', format='int') |
|
57 | 65 | #opObj11.addParameter(name='zmax', value='32', format='int') |
|
58 | 66 | #opObj11.addParameter(name='showprofile', value='1', format='int') |
|
59 | 67 | #opObj11.addParameter(name='timerange', value=str(2*60*60), format='int') |
|
60 | 68 | |
|
61 | 69 | procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=readUnitConfObj.getId()) |
|
62 | 70 | opObj11 = procUnitConfObj2.addOperation(name='GaussianFit', optype='other') |
|
63 | opObj11.addParameter(name='vel_arr', value='32,0,0,0', format='intList') | |
|
71 | #opObj11.addParameter(name='vel_arr', value='32,0,0,0', format='intList') | |
|
64 | 72 | opObj11.addParameter(name='SNRlimit', value='-3', format='int') |
|
65 | 73 | |
|
66 | 74 | #opObj12 = procUnitConfObj2.addOperation(name='ParametersPlot', optype='other') |
|
67 | 75 | #opObj12.addParameter(name='id',value='4',format='int') |
|
68 | 76 | #opObj12.addParameter(name='wintitle',value='First_gg',format='str') |
|
69 | 77 | |
|
70 | 78 | opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other') |
|
71 | 79 | opObj11.addParameter(name='id', value='21', format='int') |
|
72 | 80 | opObj11.addParameter(name='wintitle', value='FitGauPlot', format='str') |
|
73 | 81 | opObj11.addParameter(name='xaxis', value='frequency', format='str') |
|
74 | 82 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
75 | 83 | opObj11.addParameter(name='zmin', value='-20', format='int') |
|
76 | 84 | opObj11.addParameter(name='zmax', value='20', format='int') |
|
77 | 85 | opObj11.addParameter(name='GauSelector', value='1', format='int') |
|
78 | 86 | #opObj11.addParameter(name='save', value='1', format='int') |
|
79 | 87 | #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106') |
|
80 | 88 | |
|
81 | 89 | opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other') |
|
82 | 90 | opObj11.addParameter(name='id', value='22', format='int') |
|
83 | 91 | opObj11.addParameter(name='wintitle', value='FitGauPlot', format='str') |
|
84 | 92 | opObj11.addParameter(name='xaxis', value='frequency', format='str') |
|
85 | 93 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
86 | 94 | opObj11.addParameter(name='zmin', value='-20', format='int') |
|
87 | 95 | opObj11.addParameter(name='zmax', value='20', format='int') |
|
88 | 96 | opObj11.addParameter(name='GauSelector', value='0', format='int') |
|
89 | 97 | |
|
90 | 98 | #opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other') |
|
91 | 99 | #opObj11.addParameter(name='id', value='55', format='int') |
|
92 | 100 | #opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') |
|
93 | 101 | #opObj11.addParameter(name='xaxis', value='velocity', format='str') |
|
94 | 102 | #opObj11.addParameter(name='showprofile', value='1', format='int') |
|
95 | 103 | #opObj11.addParameter(name='save', value='1', format='int') |
|
96 | 104 | #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106') |
|
97 | 105 | |
|
98 | 106 | controllerObj.start() |
|
99 | 107 | |
|
100 | 108 | if __name__ == '__main__': |
|
101 | 109 | import time |
|
102 | 110 | start_time = time.time() |
|
103 | 111 | main() |
|
104 | 112 | print("--- %s seconds ---" % (time.time() - start_time)) |
@@ -1,93 +1,238 | |||
|
1 | 1 | import os, sys |
|
2 | 2 | |
|
3 | 3 | from schainpy.controller import Project |
|
4 | 4 | |
|
5 | 5 | if __name__ == '__main__': |
|
6 | 6 | |
|
7 | 7 | desc = "Segundo Test" |
|
8 | 8 | filename = "schain.xml" |
|
9 | 9 | |
|
10 | pathW='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/pdatatest/test1024' | |
|
11 | figpath = '/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/Images/test1024' | |
|
12 | ||
|
10 | 13 | controllerObj = Project() |
|
11 | 14 | |
|
12 |
controllerObj.setup(id |
|
|
15 | controllerObj.setup(id='191', name='test01', description=desc) | |
|
13 | 16 | |
|
14 | 17 | readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', |
|
15 |
path='/ |
|
|
16 |
|
|
|
17 |
|
|
|
18 |
|
|
|
19 |
|
|
|
18 | path='/media/erick/6F60F7113095A154/CLAIRE/CLAIRE_WINDS_2MHZ/DATA/', | |
|
19 | #path='/home/erick/Documents/Data/Claire_Data/raw', | |
|
20 | startDate='2017/08/22', | |
|
21 | endDate='2017/08/22', | |
|
22 | startTime='01:00:00', | |
|
23 | endTime='06:00:00', | |
|
20 | 24 | online=0, |
|
21 | 25 | walk=1) |
|
22 | 26 | |
|
27 | opObj00 = readUnitConfObj.addOperation(name='printInfo') | |
|
28 | # | |
|
29 | # procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', | |
|
30 | # inputId=readUnitConfObj.getId()) | |
|
31 | # | |
|
32 | # opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
|
33 | # opObj10.addParameter(name='minHei', value='0', format='float') | |
|
34 | # opObj10.addParameter(name='maxHei', value='8', format='float') | |
|
35 | # | |
|
36 | # opObj10 = procUnitConfObj0.addOperation(name='filterByHeights') | |
|
37 | # opObj10.addParameter(name='window', value='2', format='float') | |
|
38 | # | |
|
39 | # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external') | |
|
40 | # opObj10.addParameter(name='code', value='1,-1', format='intlist') | |
|
41 | # opObj10.addParameter(name='nCode', value='2', format='float') | |
|
42 | # opObj10.addParameter(name='nBaud', value='1', format='float') | |
|
43 | # | |
|
44 | # | |
|
45 | # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
|
46 | # opObj10.addParameter(name='n', value='1296', format='float') | |
|
47 | ||
|
23 | 48 | opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock') |
|
24 | 49 | |
|
25 | 50 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', |
|
26 | 51 | inputId=readUnitConfObj.getId()) |
|
27 | ||
|
28 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
|
29 | opObj10.addParameter(name='minHei', value='0', format='float') | |
|
30 | opObj10.addParameter(name='maxHei', value='8', format='float') | |
|
31 | ||
|
32 | opObj10 = procUnitConfObj0.addOperation(name='filterByHeights') | |
|
33 | opObj10.addParameter(name='window', value='2', format='float') | |
|
34 | 52 | |
|
35 | opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external') | |
|
36 | opObj10.addParameter(name='code', value='1,-1', format='intlist') | |
|
37 | opObj10.addParameter(name='nCode', value='2', format='float') | |
|
38 | opObj10.addParameter(name='nBaud', value='1', format='float') | |
|
39 | ||
|
40 | ||
|
41 | opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
|
42 | opObj10.addParameter(name='n', value='1296', format='float') | |
|
43 | 53 | |
|
54 | opObj10 = procUnitConfObj0.addOperation(name='setRadarFrequency') | |
|
55 | opObj10.addParameter(name='frequency', value='445.09e6', format='float') | |
|
56 | ||
|
57 | #opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
|
58 | #opObj10.addParameter(name='n', value='1', format='float') | |
|
59 | ||
|
60 | #opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
|
61 | #opObj10.addParameter(name='minHei', value='1', format='float') | |
|
62 | #opObj10.addParameter(name='maxHei', value='15', format='float') | |
|
63 | ||
|
64 | #opObj10 = procUnitConfObj0.addOperation(name='selectFFTs') | |
|
65 | #opObj10.addParameter(name='minHei', value='', format='float') | |
|
66 | #opObj10.addParameter(name='maxHei', value='', format='float') | |
|
67 | ||
|
44 | 68 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', |
|
45 | 69 | inputId=procUnitConfObj0.getId()) |
|
46 | 70 | |
|
47 | #Creating a processing object with its parameters | |
|
48 | #schainpy.model.proc.jroproc_spectra.SpectraProc.run() | |
|
49 | #If you need to add more parameters can use the "addParameter method" | |
|
50 |
procUnitConfObj1.addParameter(name='nFFTPoints', value='1 |
|
|
51 | ||
|
52 | opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') | |
|
53 | opObj10.addParameter(name='n', value='2', format='float') | |
|
71 | # Creating a processing object with its parameters | |
|
72 | # schainpy.model.proc.jroproc_spectra.SpectraProc.run() | |
|
73 | # If you need to add more parameters can use the "addParameter method" | |
|
74 | procUnitConfObj1.addParameter(name='nFFTPoints', value='1024', format='int') | |
|
75 | ||
|
76 | ||
|
77 | opObj10 = procUnitConfObj1.addOperation(name='removeDC') | |
|
78 | #opObj10 = procUnitConfObj1.addOperation(name='removeInterference') | |
|
79 | #opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') | |
|
80 | #opObj10.addParameter(name='n', value='30', format='float') | |
|
54 | 81 | |
|
55 | #Using internal methods | |
|
56 | #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels() | |
|
82 | ||
|
83 | ||
|
84 | #opObj10 = procUnitConfObj1.addOperation(name='selectFFTs') | |
|
85 | #opObj10.addParameter(name='minFFT', value='-15', format='float') | |
|
86 | #opObj10.addParameter(name='maxFFT', value='15', format='float') | |
|
87 | ||
|
88 | ||
|
89 | ||
|
90 | opObj10 = procUnitConfObj1.addOperation(name='SpectraWriter', optype='other') | |
|
91 | opObj10.addParameter(name='blocksPerFile', value='64', format = 'int') | |
|
92 | opObj10.addParameter(name='path', value=pathW) | |
|
93 | # Using internal methods | |
|
94 | # schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels() | |
|
57 | 95 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
58 | 96 | # opObj10.addParameter(name='channelList', value='0,1', format='intlist') |
|
59 | 97 | |
|
60 | #Using internal methods | |
|
61 | #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights() | |
|
98 | # Using internal methods | |
|
99 | # schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights() | |
|
62 | 100 | # opObj10 = procUnitConfObj1.addOperation(name='selectHeights') |
|
63 | 101 | # opObj10.addParameter(name='minHei', value='90', format='float') |
|
64 | 102 | # opObj10.addParameter(name='maxHei', value='180', format='float') |
|
65 | 103 | |
|
66 | #Using external methods (new modules) | |
|
104 | # Using external methods (new modules) | |
|
67 | 105 | # #schainpy.model.proc.jroproc_spectra.IncohInt.setup() |
|
68 | 106 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') |
|
69 | 107 | # opObj12.addParameter(name='n', value='1', format='int') |
|
70 | 108 | |
|
71 | #Using external methods (new modules) | |
|
72 | #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup() | |
|
109 | # Using external methods (new modules) | |
|
110 | # schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup() | |
|
73 | 111 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
74 | 112 | opObj11.addParameter(name='id', value='11', format='int') |
|
75 | 113 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') |
|
76 |
opObj11.addParameter(name=' |
|
|
77 |
opObj11.addParameter(name=' |
|
|
78 |
opObj11.addParameter(name=' |
|
|
114 | opObj11.addParameter(name='xaxis', value='velocity', format='str') | |
|
115 | # opObj11.addParameter(name='xmin', value='-10', format='int') | |
|
116 | # opObj11.addParameter(name='xmax', value='10', format='int') | |
|
79 | 117 | |
|
80 | #Using external methods (new modules) | |
|
81 | #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup() | |
|
118 | # opObj11.addParameter(name='ymin', value='1', format='float') | |
|
119 | # opObj11.addParameter(name='ymax', value='3', format='int') | |
|
120 | #opObj11.addParameter(name='zmin', value='10', format='int') | |
|
121 | #opObj11.addParameter(name='zmax', value='35', format='int') | |
|
122 | # opObj11.addParameter(name='save', value='2', format='int') | |
|
123 | # opObj11.addParameter(name='save', value='5', format='int') | |
|
124 | # opObj11.addParameter(name='figpath', value=figpath, format='str') | |
|
125 | ||
|
126 | ||
|
127 | opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') | |
|
128 | procUnitConfObj1.addParameter(name='pairsList', value='(0,1),(0,2),(1,2)', format='pairsList') | |
|
129 | opObj11.addParameter(name='id', value='2005', format='int') | |
|
130 | #opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str') | |
|
131 | #opObj11.addParameter(name='exp_code', value='13', format='int') | |
|
132 | opObj11.addParameter(name='xaxis', value='Velocity', format='str') | |
|
133 | #opObj11.addParameter(name='xmin', value='-6', format='float') | |
|
134 | #opObj11.addParameter(name='xmax', value='6', format='float') | |
|
135 | opObj11.addParameter(name='zmin', value='15', format='float') | |
|
136 | opObj11.addParameter(name='zmax', value='50', format='float') | |
|
137 | opObj11.addParameter(name='ymin', value='0', format='float') | |
|
138 | opObj11.addParameter(name='ymax', value='7', format='float') | |
|
139 | #opObj11.addParameter(name='phase_min', value='-4', format='int') | |
|
140 | #opObj11.addParameter(name='phase_max', value='4', format='int') | |
|
141 | # | |
|
142 | ||
|
143 | # Using external methods (new modules) | |
|
144 | # schainpy.model.graphics.jroplot_spectra.RTIPlot.setup() | |
|
82 | 145 | opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') |
|
83 | 146 | opObj11.addParameter(name='id', value='30', format='int') |
|
84 | 147 | opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
85 |
opObj11.addParameter(name='zmin', value=' |
|
|
86 |
opObj11.addParameter(name='zmax', value=' |
|
|
148 | opObj11.addParameter(name='zmin', value='15', format='int') | |
|
149 | opObj11.addParameter(name='zmax', value='40', format='int') | |
|
150 | opObj11.addParameter(name='ymin', value='1', format='int') | |
|
151 | opObj11.addParameter(name='ymax', value='7', format='int') | |
|
87 | 152 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
88 | 153 | # opObj11.addParameter(name='timerange', value=str(5*60*60*60), format='int') |
|
89 |
opObj11.addParameter(name='xmin', value='1 |
|
|
90 |
opObj11.addParameter(name='xmax', value=' |
|
|
154 | opObj11.addParameter(name='xmin', value='1', format='float') | |
|
155 | opObj11.addParameter(name='xmax', value='6', format='float') | |
|
91 | 156 | opObj11.addParameter(name='save', value='1', format='int') |
|
157 | ||
|
158 | ||
|
159 | # '''#########################################################################################''' | |
|
160 | # | |
|
161 | # | |
|
162 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Parameters', inputId=procUnitConfObj1.getId()) | |
|
163 | # opObj11 = procUnitConfObj2.addOperation(name='SpectralMoments', optype='other') | |
|
164 | # | |
|
165 | # ''' | |
|
166 | # # Discriminacion de ecos | |
|
167 | # opObj11 = procUnitConfObj2.addOperation(name='GaussianFit', optype='other') | |
|
168 | # opObj11.addParameter(name='SNRlimit', value='0', format='int') | |
|
169 | # ''' | |
|
170 | # | |
|
171 | # ''' | |
|
172 | # # Estimacion de Precipitacion | |
|
173 | # opObj11 = procUnitConfObj2.addOperation(name='PrecipitationProc', optype='other') | |
|
174 | # ''' | |
|
175 | # | |
|
176 | # opObj22 = procUnitConfObj2.addOperation(name='FullSpectralAnalysis', optype='other') | |
|
177 | # | |
|
178 | # opObj22.addParameter(name='SNRlimit', value='-10', format='float') | |
|
179 | # opObj22.addParameter(name='E01', value='1.500', format='float') | |
|
180 | # opObj22.addParameter(name='E02', value='1.500', format='float') | |
|
181 | # opObj22.addParameter(name='E12', value='0', format='float') | |
|
182 | # opObj22.addParameter(name='N01', value='0.875', format='float') | |
|
183 | # opObj22.addParameter(name='N02', value='-0.875', format='float') | |
|
184 | # opObj22.addParameter(name='N12', value='-1.750', format='float') | |
|
185 | # | |
|
186 | # | |
|
187 | # opObj22 = procUnitConfObj2.addOperation(name='WindProfilerPlot', optype='other') | |
|
188 | # opObj22.addParameter(name='id', value='4', format='int') | |
|
189 | # opObj22.addParameter(name='wintitle', value='Wind Profiler', format='str') | |
|
190 | # opObj22.addParameter(name='save', value='1', format='bool') | |
|
191 | # opObj22.addParameter(name='xmin', value='0', format='float') | |
|
192 | # opObj22.addParameter(name='xmax', value='6', format='float') | |
|
193 | # opObj22.addParameter(name='ymin', value='1', format='float') | |
|
194 | # opObj22.addParameter(name='ymax', value='3.5', format='float') | |
|
195 | # opObj22.addParameter(name='zmin', value='-1', format='float') | |
|
196 | # opObj22.addParameter(name='zmax', value='1', format='float') | |
|
197 | # opObj22.addParameter(name='SNRmin', value='-15', format='float') | |
|
198 | # opObj22.addParameter(name='SNRmax', value='20', format='float') | |
|
199 | # opObj22.addParameter(name='zmin_ver', value='-200', format='float') | |
|
200 | # opObj22.addParameter(name='zmax_ver', value='200', format='float') | |
|
201 | # opObj22.addParameter(name='save', value='1', format='int') | |
|
202 | # opObj22.addParameter(name='figpath', value=figpath, format='str') | |
|
203 | # | |
|
204 | # | |
|
205 | # | |
|
206 | # #opObj11.addParameter(name='zmin', value='75', format='int') | |
|
207 | # | |
|
208 | # #opObj12 = procUnitConfObj2.addOperation(name='ParametersPlot', optype='other') | |
|
209 | # #opObj12.addParameter(name='id',value='4',format='int') | |
|
210 | # #opObj12.addParameter(name='wintitle',value='First_gg',format='str') | |
|
211 | # ''' | |
|
212 | # #Ploteo de Discriminacion de Gaussianas | |
|
213 | # | |
|
214 | # opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other') | |
|
215 | # opObj11.addParameter(name='id', value='21', format='int') | |
|
216 | # opObj11.addParameter(name='wintitle', value='Rainfall Gaussian', format='str') | |
|
217 | # opObj11.addParameter(name='xaxis', value='velocity', format='str') | |
|
218 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
219 | # opObj11.addParameter(name='zmin', value='75', format='int') | |
|
220 | # opObj11.addParameter(name='zmax', value='100', format='int') | |
|
221 | # opObj11.addParameter(name='GauSelector', value='1', format='int') | |
|
222 | # #opObj11.addParameter(name='save', value='1', format='int') | |
|
223 | # #opObj11.addParameter(name='figpath', value='/home/erick/Documents/Data/d2015106') | |
|
224 | # | |
|
225 | # opObj11 = procUnitConfObj2.addOperation(name='FitGauPlot', optype='other') | |
|
226 | # opObj11.addParameter(name='id', value='22', format='int') | |
|
227 | # opObj11.addParameter(name='wintitle', value='Wind Gaussian', format='str') | |
|
228 | # opObj11.addParameter(name='xaxis', value='velocity', format='str') | |
|
229 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
230 | # opObj11.addParameter(name='zmin', value='75', format='int') | |
|
231 | # opObj11.addParameter(name='zmax', value='100', format='int') | |
|
232 | # opObj11.addParameter(name='GauSelector', value='0', format='int') | |
|
233 | # ''' | |
|
234 | # | |
|
235 | # | |
|
236 | ||
|
92 | 237 | |
|
93 | 238 | controllerObj.start() |
General Comments 0
You need to be logged in to leave comments.
Login now