##// END OF EJS Templates
Update noise C extension to properly work with python 3
Juan C. Espinoza -
r1286:a59b24777aee
parent child
Show More
@@ -0,0 +1,82
1 #include <Python.h>
2 #include <numpy/arrayobject.h>
3 #include <math.h>
4
5
6 static PyObject *hildebrand_sekhon(PyObject *self, PyObject *args) {
7 double navg;
8 PyObject *data_obj, *data_array;
9
10 if (!PyArg_ParseTuple(args, "Od", &data_obj, &navg)) {
11 return NULL;
12 }
13
14 data_array = PyArray_FROM_OTF(data_obj, NPY_FLOAT64, NPY_IN_ARRAY);
15
16 if (data_array == NULL) {
17 Py_XDECREF(data_array);
18 Py_XDECREF(data_obj);
19 return NULL;
20 }
21 double *sortdata = (double*)PyArray_DATA(data_array);
22 int lenOfData = (int)PyArray_SIZE(data_array) ;
23 double nums_min = lenOfData*0.2;
24 if (nums_min <= 5) nums_min = 5;
25 double sump = 0;
26 double sumq = 0;
27 int j = 0;
28 int cont = 1;
29 double rtest = 0;
30 while ((cont == 1) && (j < lenOfData)) {
31 sump = sump + sortdata[j];
32 sumq = sumq + pow(sortdata[j], 2);
33 if (j > nums_min) {
34 rtest = (double)j/(j-1) + 1/navg;
35 if ((sumq*j) > (rtest*pow(sump, 2))) {
36 j = j - 1;
37 sump = sump - sortdata[j];
38 sumq = sumq - pow(sortdata[j],2);
39 cont = 0;
40 }
41 }
42 j = j + 1;
43 }
44
45 double lnoise = sump / j;
46
47 Py_DECREF(data_array);
48
49 return PyLong_FromLong(lnoise);
50 //return Py_BuildValue("d", lnoise);
51 }
52
53
54 static PyMethodDef noiseMethods[] = {
55 { "hildebrand_sekhon", hildebrand_sekhon, METH_VARARGS, "Get noise with hildebrand_sekhon algorithm" },
56 { NULL, NULL, 0, NULL }
57 };
58
59 #if PY_MAJOR_VERSION >= 3
60
61 static struct PyModuleDef noisemodule = {
62 PyModuleDef_HEAD_INIT,
63 "_noise",
64 "Get noise with hildebrand_sekhon algorithm",
65 -1,
66 noiseMethods
67 };
68
69 #endif
70
71 #if PY_MAJOR_VERSION >= 3
72 PyMODINIT_FUNC PyInit__noise(void) {
73 Py_Initialize();
74 import_array();
75 return PyModule_Create(&noisemodule);
76 }
77 #else
78 PyMODINIT_FUNC init_noise() {
79 Py_InitModule("_noise", noiseMethods);
80 import_array();
81 }
82 #endif
@@ -1,1384 +1,1386
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 import json
11 11
12 12 import schainpy.admin
13 13 from schainpy.utils import log
14 14 from .jroheaderIO import SystemHeader, RadarControllerHeader
15 from schainpy.model.data import _noise
15 16
16 17
17 18 def getNumpyDtype(dataTypeCode):
18 19
19 20 if dataTypeCode == 0:
20 21 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
21 22 elif dataTypeCode == 1:
22 23 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
23 24 elif dataTypeCode == 2:
24 25 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
25 26 elif dataTypeCode == 3:
26 27 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
27 28 elif dataTypeCode == 4:
28 29 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
29 30 elif dataTypeCode == 5:
30 31 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
31 32 else:
32 33 raise ValueError('dataTypeCode was not defined')
33 34
34 35 return numpyDtype
35 36
36 37
37 38 def getDataTypeCode(numpyDtype):
38 39
39 40 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
40 41 datatype = 0
41 42 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
42 43 datatype = 1
43 44 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
44 45 datatype = 2
45 46 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
46 47 datatype = 3
47 48 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
48 49 datatype = 4
49 50 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
50 51 datatype = 5
51 52 else:
52 53 datatype = None
53 54
54 55 return datatype
55 56
56 57
57 58 def hildebrand_sekhon(data, navg):
58 59 """
59 60 This method is for the objective determination of the noise level in Doppler spectra. This
60 61 implementation technique is based on the fact that the standard deviation of the spectral
61 62 densities is equal to the mean spectral density for white Gaussian noise
62 63
63 64 Inputs:
64 65 Data : heights
65 66 navg : numbers of averages
66 67
67 68 Return:
68 69 mean : noise's level
69 70 """
70 71
71 72 sortdata = numpy.sort(data, axis=None)
73 '''
72 74 lenOfData = len(sortdata)
73 75 nums_min = lenOfData*0.2
74 76
75 77 if nums_min <= 5:
76 78
77 79 nums_min = 5
78 80
79 81 sump = 0.
80 82 sumq = 0.
81 83
82 84 j = 0
83 85 cont = 1
84 86
85 87 while((cont == 1)and(j < lenOfData)):
86 88
87 89 sump += sortdata[j]
88 90 sumq += sortdata[j]**2
89 91
90 92 if j > nums_min:
91 93 rtest = float(j)/(j-1) + 1.0/navg
92 94 if ((sumq*j) > (rtest*sump**2)):
93 95 j = j - 1
94 96 sump = sump - sortdata[j]
95 97 sumq = sumq - sortdata[j]**2
96 98 cont = 0
97 99
98 100 j += 1
99 101
100 102 lnoise = sump / j
101
102 return lnoise
103 '''
104 return _noise.hildebrand_sekhon(sortdata, navg)
103 105
104 106
105 107 class Beam:
106 108
107 109 def __init__(self):
108 110 self.codeList = []
109 111 self.azimuthList = []
110 112 self.zenithList = []
111 113
112 114
113 115 class GenericData(object):
114 116
115 117 flagNoData = True
116 118
117 119 def copy(self, inputObj=None):
118 120
119 121 if inputObj == None:
120 122 return copy.deepcopy(self)
121 123
122 124 for key in list(inputObj.__dict__.keys()):
123 125
124 126 attribute = inputObj.__dict__[key]
125 127
126 128 # If this attribute is a tuple or list
127 129 if type(inputObj.__dict__[key]) in (tuple, list):
128 130 self.__dict__[key] = attribute[:]
129 131 continue
130 132
131 133 # If this attribute is another object or instance
132 134 if hasattr(attribute, '__dict__'):
133 135 self.__dict__[key] = attribute.copy()
134 136 continue
135 137
136 138 self.__dict__[key] = inputObj.__dict__[key]
137 139
138 140 def deepcopy(self):
139 141
140 142 return copy.deepcopy(self)
141 143
142 144 def isEmpty(self):
143 145
144 146 return self.flagNoData
145 147
146 148 def isReady(self):
147 149
148 150 return not self.flagNoData
149 151
150 152
151 153 class JROData(GenericData):
152 154
153 155 # m_BasicHeader = BasicHeader()
154 156 # m_ProcessingHeader = ProcessingHeader()
155 157
156 158 systemHeaderObj = SystemHeader()
157 159 radarControllerHeaderObj = RadarControllerHeader()
158 160 # data = None
159 161 type = None
160 162 datatype = None # dtype but in string
161 163 # dtype = None
162 164 # nChannels = None
163 165 # nHeights = None
164 166 nProfiles = None
165 167 heightList = None
166 168 channelList = None
167 169 flagDiscontinuousBlock = False
168 170 useLocalTime = False
169 171 utctime = None
170 172 timeZone = None
171 173 dstFlag = None
172 174 errorCount = None
173 175 blocksize = None
174 176 # nCode = None
175 177 # nBaud = None
176 178 # code = None
177 179 flagDecodeData = False # asumo q la data no esta decodificada
178 180 flagDeflipData = False # asumo q la data no esta sin flip
179 181 flagShiftFFT = False
180 182 # ippSeconds = None
181 183 # timeInterval = None
182 184 nCohInt = None
183 185 # noise = None
184 186 windowOfFilter = 1
185 187 # Speed of ligth
186 188 C = 3e8
187 189 frequency = 49.92e6
188 190 realtime = False
189 191 beacon_heiIndexList = None
190 192 last_block = None
191 193 blocknow = None
192 194 azimuth = None
193 195 zenith = None
194 196 beam = Beam()
195 197 profileIndex = None
196 198 error = None
197 199 data = None
198 200 nmodes = None
199 201
200 202 def __str__(self):
201 203
202 204 return '{} - {}'.format(self.type, self.getDatatime())
203 205
204 206 def getNoise(self):
205 207
206 208 raise NotImplementedError
207 209
208 210 def getNChannels(self):
209 211
210 212 return len(self.channelList)
211 213
212 214 def getChannelIndexList(self):
213 215
214 216 return list(range(self.nChannels))
215 217
216 218 def getNHeights(self):
217 219
218 220 return len(self.heightList)
219 221
220 222 def getHeiRange(self, extrapoints=0):
221 223
222 224 heis = self.heightList
223 225 # deltah = self.heightList[1] - self.heightList[0]
224 226 #
225 227 # heis.append(self.heightList[-1])
226 228
227 229 return heis
228 230
229 231 def getDeltaH(self):
230 232
231 233 delta = self.heightList[1] - self.heightList[0]
232 234
233 235 return delta
234 236
235 237 def getltctime(self):
236 238
237 239 if self.useLocalTime:
238 240 return self.utctime - self.timeZone * 60
239 241
240 242 return self.utctime
241 243
242 244 def getDatatime(self):
243 245
244 246 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
245 247 return datatimeValue
246 248
247 249 def getTimeRange(self):
248 250
249 251 datatime = []
250 252
251 253 datatime.append(self.ltctime)
252 254 datatime.append(self.ltctime + self.timeInterval + 1)
253 255
254 256 datatime = numpy.array(datatime)
255 257
256 258 return datatime
257 259
258 260 def getFmaxTimeResponse(self):
259 261
260 262 period = (10**-6) * self.getDeltaH() / (0.15)
261 263
262 264 PRF = 1. / (period * self.nCohInt)
263 265
264 266 fmax = PRF
265 267
266 268 return fmax
267 269
268 270 def getFmax(self):
269 271 PRF = 1. / (self.ippSeconds * self.nCohInt)
270 272
271 273 fmax = PRF
272 274 return fmax
273 275
274 276 def getVmax(self):
275 277
276 278 _lambda = self.C / self.frequency
277 279
278 280 vmax = self.getFmax() * _lambda / 2
279 281
280 282 return vmax
281 283
282 284 def get_ippSeconds(self):
283 285 '''
284 286 '''
285 287 return self.radarControllerHeaderObj.ippSeconds
286 288
287 289 def set_ippSeconds(self, ippSeconds):
288 290 '''
289 291 '''
290 292
291 293 self.radarControllerHeaderObj.ippSeconds = ippSeconds
292 294
293 295 return
294 296
295 297 def get_dtype(self):
296 298 '''
297 299 '''
298 300 return getNumpyDtype(self.datatype)
299 301
300 302 def set_dtype(self, numpyDtype):
301 303 '''
302 304 '''
303 305
304 306 self.datatype = getDataTypeCode(numpyDtype)
305 307
306 308 def get_code(self):
307 309 '''
308 310 '''
309 311 return self.radarControllerHeaderObj.code
310 312
311 313 def set_code(self, code):
312 314 '''
313 315 '''
314 316 self.radarControllerHeaderObj.code = code
315 317
316 318 return
317 319
318 320 def get_ncode(self):
319 321 '''
320 322 '''
321 323 return self.radarControllerHeaderObj.nCode
322 324
323 325 def set_ncode(self, nCode):
324 326 '''
325 327 '''
326 328 self.radarControllerHeaderObj.nCode = nCode
327 329
328 330 return
329 331
330 332 def get_nbaud(self):
331 333 '''
332 334 '''
333 335 return self.radarControllerHeaderObj.nBaud
334 336
335 337 def set_nbaud(self, nBaud):
336 338 '''
337 339 '''
338 340 self.radarControllerHeaderObj.nBaud = nBaud
339 341
340 342 return
341 343
342 344 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
343 345 channelIndexList = property(
344 346 getChannelIndexList, "I'm the 'channelIndexList' property.")
345 347 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
346 348 #noise = property(getNoise, "I'm the 'nHeights' property.")
347 349 datatime = property(getDatatime, "I'm the 'datatime' property")
348 350 ltctime = property(getltctime, "I'm the 'ltctime' property")
349 351 ippSeconds = property(get_ippSeconds, set_ippSeconds)
350 352 dtype = property(get_dtype, set_dtype)
351 353 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
352 354 code = property(get_code, set_code)
353 355 nCode = property(get_ncode, set_ncode)
354 356 nBaud = property(get_nbaud, set_nbaud)
355 357
356 358
357 359 class Voltage(JROData):
358 360
359 361 # data es un numpy array de 2 dmensiones (canales, alturas)
360 362 data = None
361 363
362 364 def __init__(self):
363 365 '''
364 366 Constructor
365 367 '''
366 368
367 369 self.useLocalTime = True
368 370 self.radarControllerHeaderObj = RadarControllerHeader()
369 371 self.systemHeaderObj = SystemHeader()
370 372 self.type = "Voltage"
371 373 self.data = None
372 374 # self.dtype = None
373 375 # self.nChannels = 0
374 376 # self.nHeights = 0
375 377 self.nProfiles = None
376 378 self.heightList = None
377 379 self.channelList = None
378 380 # self.channelIndexList = None
379 381 self.flagNoData = True
380 382 self.flagDiscontinuousBlock = False
381 383 self.utctime = None
382 384 self.timeZone = None
383 385 self.dstFlag = None
384 386 self.errorCount = None
385 387 self.nCohInt = None
386 388 self.blocksize = None
387 389 self.flagDecodeData = False # asumo q la data no esta decodificada
388 390 self.flagDeflipData = False # asumo q la data no esta sin flip
389 391 self.flagShiftFFT = False
390 392 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
391 393 self.profileIndex = 0
392 394
393 395 def getNoisebyHildebrand(self, channel=None):
394 396 """
395 397 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
396 398
397 399 Return:
398 400 noiselevel
399 401 """
400 402
401 403 if channel != None:
402 404 data = self.data[channel]
403 405 nChannels = 1
404 406 else:
405 407 data = self.data
406 408 nChannels = self.nChannels
407 409
408 410 noise = numpy.zeros(nChannels)
409 411 power = data * numpy.conjugate(data)
410 412
411 413 for thisChannel in range(nChannels):
412 414 if nChannels == 1:
413 415 daux = power[:].real
414 416 else:
415 417 daux = power[thisChannel, :].real
416 418 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
417 419
418 420 return noise
419 421
420 422 def getNoise(self, type=1, channel=None):
421 423
422 424 if type == 1:
423 425 noise = self.getNoisebyHildebrand(channel)
424 426
425 427 return noise
426 428
427 429 def getPower(self, channel=None):
428 430
429 431 if channel != None:
430 432 data = self.data[channel]
431 433 else:
432 434 data = self.data
433 435
434 436 power = data * numpy.conjugate(data)
435 437 powerdB = 10 * numpy.log10(power.real)
436 438 powerdB = numpy.squeeze(powerdB)
437 439
438 440 return powerdB
439 441
440 442 def getTimeInterval(self):
441 443
442 444 timeInterval = self.ippSeconds * self.nCohInt
443 445
444 446 return timeInterval
445 447
446 448 noise = property(getNoise, "I'm the 'nHeights' property.")
447 449 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
448 450
449 451
450 452 class Spectra(JROData):
451 453
452 454 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
453 455 data_spc = None
454 456 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
455 457 data_cspc = None
456 458 # data dc es un numpy array de 2 dmensiones (canales, alturas)
457 459 data_dc = None
458 460 # data power
459 461 data_pwr = None
460 462 nFFTPoints = None
461 463 # nPairs = None
462 464 pairsList = None
463 465 nIncohInt = None
464 466 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
465 467 nCohInt = None # se requiere para determinar el valor de timeInterval
466 468 ippFactor = None
467 469 profileIndex = 0
468 470 plotting = "spectra"
469 471
470 472 def __init__(self):
471 473 '''
472 474 Constructor
473 475 '''
474 476
475 477 self.useLocalTime = True
476 478 self.radarControllerHeaderObj = RadarControllerHeader()
477 479 self.systemHeaderObj = SystemHeader()
478 480 self.type = "Spectra"
479 481 # self.data = None
480 482 # self.dtype = None
481 483 # self.nChannels = 0
482 484 # self.nHeights = 0
483 485 self.nProfiles = None
484 486 self.heightList = None
485 487 self.channelList = None
486 488 # self.channelIndexList = None
487 489 self.pairsList = None
488 490 self.flagNoData = True
489 491 self.flagDiscontinuousBlock = False
490 492 self.utctime = None
491 493 self.nCohInt = None
492 494 self.nIncohInt = None
493 495 self.blocksize = None
494 496 self.nFFTPoints = None
495 497 self.wavelength = None
496 498 self.flagDecodeData = False # asumo q la data no esta decodificada
497 499 self.flagDeflipData = False # asumo q la data no esta sin flip
498 500 self.flagShiftFFT = False
499 501 self.ippFactor = 1
500 502 #self.noise = None
501 503 self.beacon_heiIndexList = []
502 504 self.noise_estimation = None
503 505
504 506 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
505 507 """
506 508 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
507 509
508 510 Return:
509 511 noiselevel
510 512 """
511 513
512 514 noise = numpy.zeros(self.nChannels)
513 515
514 516 for channel in range(self.nChannels):
515 517 daux = self.data_spc[channel,
516 518 xmin_index:xmax_index, ymin_index:ymax_index]
517 519 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
518 520
519 521 return noise
520 522
521 523 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
522 524
523 525 if self.noise_estimation is not None:
524 526 # this was estimated by getNoise Operation defined in jroproc_spectra.py
525 527 return self.noise_estimation
526 528 else:
527 529 noise = self.getNoisebyHildebrand(
528 530 xmin_index, xmax_index, ymin_index, ymax_index)
529 531 return noise
530 532
531 533 def getFreqRangeTimeResponse(self, extrapoints=0):
532 534
533 535 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
534 536 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.) - deltafreq / 2
535 537
536 538 return freqrange
537 539
538 540 def getAcfRange(self, extrapoints=0):
539 541
540 542 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
541 543 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
542 544
543 545 return freqrange
544 546
545 547 def getFreqRange(self, extrapoints=0):
546 548
547 549 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
548 550 freqrange = deltafreq * (numpy.arange(self.nFFTPoints + extrapoints) -self.nFFTPoints / 2.) - deltafreq / 2
549 551
550 552 return freqrange
551 553
552 554 def getVelRange(self, extrapoints=0):
553 555
554 556 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
555 557 velrange = deltav * (numpy.arange(self.nFFTPoints + extrapoints) - self.nFFTPoints / 2.)
556 558
557 559 if self.nmodes:
558 560 return velrange/self.nmodes
559 561 else:
560 562 return velrange
561 563
562 564 def getNPairs(self):
563 565
564 566 return len(self.pairsList)
565 567
566 568 def getPairsIndexList(self):
567 569
568 570 return list(range(self.nPairs))
569 571
570 572 def getNormFactor(self):
571 573
572 574 pwcode = 1
573 575
574 576 if self.flagDecodeData:
575 577 pwcode = numpy.sum(self.code[0]**2)
576 578 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
577 579 normFactor = self.nProfiles * self.nIncohInt * self.nCohInt * pwcode * self.windowOfFilter
578 580
579 581 return normFactor
580 582
581 583 def getFlagCspc(self):
582 584
583 585 if self.data_cspc is None:
584 586 return True
585 587
586 588 return False
587 589
588 590 def getFlagDc(self):
589 591
590 592 if self.data_dc is None:
591 593 return True
592 594
593 595 return False
594 596
595 597 def getTimeInterval(self):
596 598
597 599 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles * self.ippFactor
598 600 if self.nmodes:
599 601 return self.nmodes*timeInterval
600 602 else:
601 603 return timeInterval
602 604
603 605 def getPower(self):
604 606
605 607 factor = self.normFactor
606 608 z = self.data_spc / factor
607 609 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
608 610 avg = numpy.average(z, axis=1)
609 611
610 612 return 10 * numpy.log10(avg)
611 613
612 614 def getCoherence(self, pairsList=None, phase=False):
613 615
614 616 z = []
615 617 if pairsList is None:
616 618 pairsIndexList = self.pairsIndexList
617 619 else:
618 620 pairsIndexList = []
619 621 for pair in pairsList:
620 622 if pair not in self.pairsList:
621 623 raise ValueError("Pair %s is not in dataOut.pairsList" % (
622 624 pair))
623 625 pairsIndexList.append(self.pairsList.index(pair))
624 626 for i in range(len(pairsIndexList)):
625 627 pair = self.pairsList[pairsIndexList[i]]
626 628 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
627 629 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
628 630 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
629 631 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
630 632 if phase:
631 633 data = numpy.arctan2(avgcoherenceComplex.imag,
632 634 avgcoherenceComplex.real) * 180 / numpy.pi
633 635 else:
634 636 data = numpy.abs(avgcoherenceComplex)
635 637
636 638 z.append(data)
637 639
638 640 return numpy.array(z)
639 641
640 642 def setValue(self, value):
641 643
642 644 print("This property should not be initialized")
643 645
644 646 return
645 647
646 648 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
647 649 pairsIndexList = property(
648 650 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
649 651 normFactor = property(getNormFactor, setValue,
650 652 "I'm the 'getNormFactor' property.")
651 653 flag_cspc = property(getFlagCspc, setValue)
652 654 flag_dc = property(getFlagDc, setValue)
653 655 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
654 656 timeInterval = property(getTimeInterval, setValue,
655 657 "I'm the 'timeInterval' property")
656 658
657 659
658 660 class SpectraHeis(Spectra):
659 661
660 662 data_spc = None
661 663 data_cspc = None
662 664 data_dc = None
663 665 nFFTPoints = None
664 666 # nPairs = None
665 667 pairsList = None
666 668 nCohInt = None
667 669 nIncohInt = None
668 670
669 671 def __init__(self):
670 672
671 673 self.radarControllerHeaderObj = RadarControllerHeader()
672 674
673 675 self.systemHeaderObj = SystemHeader()
674 676
675 677 self.type = "SpectraHeis"
676 678
677 679 # self.dtype = None
678 680
679 681 # self.nChannels = 0
680 682
681 683 # self.nHeights = 0
682 684
683 685 self.nProfiles = None
684 686
685 687 self.heightList = None
686 688
687 689 self.channelList = None
688 690
689 691 # self.channelIndexList = None
690 692
691 693 self.flagNoData = True
692 694
693 695 self.flagDiscontinuousBlock = False
694 696
695 697 # self.nPairs = 0
696 698
697 699 self.utctime = None
698 700
699 701 self.blocksize = None
700 702
701 703 self.profileIndex = 0
702 704
703 705 self.nCohInt = 1
704 706
705 707 self.nIncohInt = 1
706 708
707 709 def getNormFactor(self):
708 710 pwcode = 1
709 711 if self.flagDecodeData:
710 712 pwcode = numpy.sum(self.code[0]**2)
711 713
712 714 normFactor = self.nIncohInt * self.nCohInt * pwcode
713 715
714 716 return normFactor
715 717
716 718 def getTimeInterval(self):
717 719
718 720 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
719 721
720 722 return timeInterval
721 723
722 724 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
723 725 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
724 726
725 727
726 728 class Fits(JROData):
727 729
728 730 heightList = None
729 731 channelList = None
730 732 flagNoData = True
731 733 flagDiscontinuousBlock = False
732 734 useLocalTime = False
733 735 utctime = None
734 736 timeZone = None
735 737 # ippSeconds = None
736 738 # timeInterval = None
737 739 nCohInt = None
738 740 nIncohInt = None
739 741 noise = None
740 742 windowOfFilter = 1
741 743 # Speed of ligth
742 744 C = 3e8
743 745 frequency = 49.92e6
744 746 realtime = False
745 747
746 748 def __init__(self):
747 749
748 750 self.type = "Fits"
749 751
750 752 self.nProfiles = None
751 753
752 754 self.heightList = None
753 755
754 756 self.channelList = None
755 757
756 758 # self.channelIndexList = None
757 759
758 760 self.flagNoData = True
759 761
760 762 self.utctime = None
761 763
762 764 self.nCohInt = 1
763 765
764 766 self.nIncohInt = 1
765 767
766 768 self.useLocalTime = True
767 769
768 770 self.profileIndex = 0
769 771
770 772 # self.utctime = None
771 773 # self.timeZone = None
772 774 # self.ltctime = None
773 775 # self.timeInterval = None
774 776 # self.header = None
775 777 # self.data_header = None
776 778 # self.data = None
777 779 # self.datatime = None
778 780 # self.flagNoData = False
779 781 # self.expName = ''
780 782 # self.nChannels = None
781 783 # self.nSamples = None
782 784 # self.dataBlocksPerFile = None
783 785 # self.comments = ''
784 786 #
785 787
786 788 def getltctime(self):
787 789
788 790 if self.useLocalTime:
789 791 return self.utctime - self.timeZone * 60
790 792
791 793 return self.utctime
792 794
793 795 def getDatatime(self):
794 796
795 797 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
796 798 return datatime
797 799
798 800 def getTimeRange(self):
799 801
800 802 datatime = []
801 803
802 804 datatime.append(self.ltctime)
803 805 datatime.append(self.ltctime + self.timeInterval)
804 806
805 807 datatime = numpy.array(datatime)
806 808
807 809 return datatime
808 810
809 811 def getHeiRange(self):
810 812
811 813 heis = self.heightList
812 814
813 815 return heis
814 816
815 817 def getNHeights(self):
816 818
817 819 return len(self.heightList)
818 820
819 821 def getNChannels(self):
820 822
821 823 return len(self.channelList)
822 824
823 825 def getChannelIndexList(self):
824 826
825 827 return list(range(self.nChannels))
826 828
827 829 def getNoise(self, type=1):
828 830
829 831 #noise = numpy.zeros(self.nChannels)
830 832
831 833 if type == 1:
832 834 noise = self.getNoisebyHildebrand()
833 835
834 836 if type == 2:
835 837 noise = self.getNoisebySort()
836 838
837 839 if type == 3:
838 840 noise = self.getNoisebyWindow()
839 841
840 842 return noise
841 843
842 844 def getTimeInterval(self):
843 845
844 846 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
845 847
846 848 return timeInterval
847 849
848 850 def get_ippSeconds(self):
849 851 '''
850 852 '''
851 853 return self.ipp_sec
852 854
853 855
854 856 datatime = property(getDatatime, "I'm the 'datatime' property")
855 857 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
856 858 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
857 859 channelIndexList = property(
858 860 getChannelIndexList, "I'm the 'channelIndexList' property.")
859 861 noise = property(getNoise, "I'm the 'nHeights' property.")
860 862
861 863 ltctime = property(getltctime, "I'm the 'ltctime' property")
862 864 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
863 865 ippSeconds = property(get_ippSeconds, '')
864 866
865 867 class Correlation(JROData):
866 868
867 869 noise = None
868 870 SNR = None
869 871 #--------------------------------------------------
870 872 mode = None
871 873 split = False
872 874 data_cf = None
873 875 lags = None
874 876 lagRange = None
875 877 pairsList = None
876 878 normFactor = None
877 879 #--------------------------------------------------
878 880 # calculateVelocity = None
879 881 nLags = None
880 882 nPairs = None
881 883 nAvg = None
882 884
883 885 def __init__(self):
884 886 '''
885 887 Constructor
886 888 '''
887 889 self.radarControllerHeaderObj = RadarControllerHeader()
888 890
889 891 self.systemHeaderObj = SystemHeader()
890 892
891 893 self.type = "Correlation"
892 894
893 895 self.data = None
894 896
895 897 self.dtype = None
896 898
897 899 self.nProfiles = None
898 900
899 901 self.heightList = None
900 902
901 903 self.channelList = None
902 904
903 905 self.flagNoData = True
904 906
905 907 self.flagDiscontinuousBlock = False
906 908
907 909 self.utctime = None
908 910
909 911 self.timeZone = None
910 912
911 913 self.dstFlag = None
912 914
913 915 self.errorCount = None
914 916
915 917 self.blocksize = None
916 918
917 919 self.flagDecodeData = False # asumo q la data no esta decodificada
918 920
919 921 self.flagDeflipData = False # asumo q la data no esta sin flip
920 922
921 923 self.pairsList = None
922 924
923 925 self.nPoints = None
924 926
925 927 def getPairsList(self):
926 928
927 929 return self.pairsList
928 930
929 931 def getNoise(self, mode=2):
930 932
931 933 indR = numpy.where(self.lagR == 0)[0][0]
932 934 indT = numpy.where(self.lagT == 0)[0][0]
933 935
934 936 jspectra0 = self.data_corr[:, :, indR, :]
935 937 jspectra = copy.copy(jspectra0)
936 938
937 939 num_chan = jspectra.shape[0]
938 940 num_hei = jspectra.shape[2]
939 941
940 942 freq_dc = jspectra.shape[1] / 2
941 943 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
942 944
943 945 if ind_vel[0] < 0:
944 946 ind_vel[list(range(0, 1))] = ind_vel[list(
945 947 range(0, 1))] + self.num_prof
946 948
947 949 if mode == 1:
948 950 jspectra[:, freq_dc, :] = (
949 951 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
950 952
951 953 if mode == 2:
952 954
953 955 vel = numpy.array([-2, -1, 1, 2])
954 956 xx = numpy.zeros([4, 4])
955 957
956 958 for fil in range(4):
957 959 xx[fil, :] = vel[fil]**numpy.asarray(list(range(4)))
958 960
959 961 xx_inv = numpy.linalg.inv(xx)
960 962 xx_aux = xx_inv[0, :]
961 963
962 964 for ich in range(num_chan):
963 965 yy = jspectra[ich, ind_vel, :]
964 966 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
965 967
966 968 junkid = jspectra[ich, freq_dc, :] <= 0
967 969 cjunkid = sum(junkid)
968 970
969 971 if cjunkid.any():
970 972 jspectra[ich, freq_dc, junkid.nonzero()] = (
971 973 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
972 974
973 975 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
974 976
975 977 return noise
976 978
977 979 def getTimeInterval(self):
978 980
979 981 timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles
980 982
981 983 return timeInterval
982 984
983 985 def splitFunctions(self):
984 986
985 987 pairsList = self.pairsList
986 988 ccf_pairs = []
987 989 acf_pairs = []
988 990 ccf_ind = []
989 991 acf_ind = []
990 992 for l in range(len(pairsList)):
991 993 chan0 = pairsList[l][0]
992 994 chan1 = pairsList[l][1]
993 995
994 996 # Obteniendo pares de Autocorrelacion
995 997 if chan0 == chan1:
996 998 acf_pairs.append(chan0)
997 999 acf_ind.append(l)
998 1000 else:
999 1001 ccf_pairs.append(pairsList[l])
1000 1002 ccf_ind.append(l)
1001 1003
1002 1004 data_acf = self.data_cf[acf_ind]
1003 1005 data_ccf = self.data_cf[ccf_ind]
1004 1006
1005 1007 return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf
1006 1008
1007 1009 def getNormFactor(self):
1008 1010 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1009 1011 acf_pairs = numpy.array(acf_pairs)
1010 1012 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1011 1013
1012 1014 for p in range(self.nPairs):
1013 1015 pair = self.pairsList[p]
1014 1016
1015 1017 ch0 = pair[0]
1016 1018 ch1 = pair[1]
1017 1019
1018 1020 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1019 1021 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1020 1022 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1021 1023
1022 1024 return normFactor
1023 1025
1024 1026 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1025 1027 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1026 1028
1027 1029
1028 1030 class Parameters(Spectra):
1029 1031
1030 1032 experimentInfo = None # Information about the experiment
1031 1033 # Information from previous data
1032 1034 inputUnit = None # Type of data to be processed
1033 1035 operation = None # Type of operation to parametrize
1034 1036 # normFactor = None #Normalization Factor
1035 1037 groupList = None # List of Pairs, Groups, etc
1036 1038 # Parameters
1037 1039 data_param = None # Parameters obtained
1038 1040 data_pre = None # Data Pre Parametrization
1039 1041 data_SNR = None # Signal to Noise Ratio
1040 1042 # heightRange = None #Heights
1041 1043 abscissaList = None # Abscissa, can be velocities, lags or time
1042 1044 # noise = None #Noise Potency
1043 1045 utctimeInit = None # Initial UTC time
1044 1046 paramInterval = None # Time interval to calculate Parameters in seconds
1045 1047 useLocalTime = True
1046 1048 # Fitting
1047 1049 data_error = None # Error of the estimation
1048 1050 constants = None
1049 1051 library = None
1050 1052 # Output signal
1051 1053 outputInterval = None # Time interval to calculate output signal in seconds
1052 1054 data_output = None # Out signal
1053 1055 nAvg = None
1054 1056 noise_estimation = None
1055 1057 GauSPC = None # Fit gaussian SPC
1056 1058
1057 1059 def __init__(self):
1058 1060 '''
1059 1061 Constructor
1060 1062 '''
1061 1063 self.radarControllerHeaderObj = RadarControllerHeader()
1062 1064
1063 1065 self.systemHeaderObj = SystemHeader()
1064 1066
1065 1067 self.type = "Parameters"
1066 1068
1067 1069 def getTimeRange1(self, interval):
1068 1070
1069 1071 datatime = []
1070 1072
1071 1073 if self.useLocalTime:
1072 1074 time1 = self.utctimeInit - self.timeZone * 60
1073 1075 else:
1074 1076 time1 = self.utctimeInit
1075 1077
1076 1078 datatime.append(time1)
1077 1079 datatime.append(time1 + interval)
1078 1080 datatime = numpy.array(datatime)
1079 1081
1080 1082 return datatime
1081 1083
1082 1084 def getTimeInterval(self):
1083 1085
1084 1086 if hasattr(self, 'timeInterval1'):
1085 1087 return self.timeInterval1
1086 1088 else:
1087 1089 return self.paramInterval
1088 1090
1089 1091 def setValue(self, value):
1090 1092
1091 1093 print("This property should not be initialized")
1092 1094
1093 1095 return
1094 1096
1095 1097 def getNoise(self):
1096 1098
1097 1099 return self.spc_noise
1098 1100
1099 1101 timeInterval = property(getTimeInterval)
1100 1102 noise = property(getNoise, setValue, "I'm the 'Noise' property.")
1101 1103
1102 1104
1103 1105 class PlotterData(object):
1104 1106 '''
1105 1107 Object to hold data to be plotted
1106 1108 '''
1107 1109
1108 1110 MAXNUMX = 100
1109 1111 MAXNUMY = 100
1110 1112
1111 1113 def __init__(self, code, throttle_value, exp_code, buffering=True, snr=False):
1112 1114
1113 1115 self.key = code
1114 1116 self.throttle = throttle_value
1115 1117 self.exp_code = exp_code
1116 1118 self.buffering = buffering
1117 1119 self.ready = False
1118 1120 self.flagNoData = False
1119 1121 self.localtime = False
1120 1122 self.data = {}
1121 1123 self.meta = {}
1122 1124 self.__times = []
1123 1125 self.__heights = []
1124 1126
1125 1127 if 'snr' in code:
1126 1128 self.plottypes = ['snr']
1127 1129 elif code == 'spc':
1128 1130 self.plottypes = ['spc', 'noise', 'rti']
1129 1131 elif code == 'rti':
1130 1132 self.plottypes = ['noise', 'rti']
1131 1133 else:
1132 1134 self.plottypes = [code]
1133 1135
1134 1136 if 'snr' not in self.plottypes and snr:
1135 1137 self.plottypes.append('snr')
1136 1138
1137 1139 for plot in self.plottypes:
1138 1140 self.data[plot] = {}
1139 1141
1140 1142 def __str__(self):
1141 1143 dum = ['{}{}'.format(key, self.shape(key)) for key in self.data]
1142 1144 return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times))
1143 1145
1144 1146 def __len__(self):
1145 1147 return len(self.__times)
1146 1148
1147 1149 def __getitem__(self, key):
1148 1150
1149 1151 if key not in self.data:
1150 1152 raise KeyError(log.error('Missing key: {}'.format(key)))
1151 1153 if 'spc' in key or not self.buffering:
1152 1154 ret = self.data[key]
1153 1155 elif 'scope' in key:
1154 1156 ret = numpy.array(self.data[key][float(self.tm)])
1155 1157 else:
1156 1158 ret = numpy.array([self.data[key][x] for x in self.times])
1157 1159 if ret.ndim > 1:
1158 1160 ret = numpy.swapaxes(ret, 0, 1)
1159 1161 return ret
1160 1162
1161 1163 def __contains__(self, key):
1162 1164 return key in self.data
1163 1165
1164 1166 def setup(self):
1165 1167 '''
1166 1168 Configure object
1167 1169 '''
1168 1170
1169 1171 self.type = ''
1170 1172 self.ready = False
1171 1173 self.data = {}
1172 1174 self.__times = []
1173 1175 self.__heights = []
1174 1176 self.__all_heights = set()
1175 1177 for plot in self.plottypes:
1176 1178 if 'snr' in plot:
1177 1179 plot = 'snr'
1178 1180 elif 'spc_moments' == plot:
1179 1181 plot = 'moments'
1180 1182 self.data[plot] = {}
1181 1183
1182 1184 if 'spc' in self.data or 'rti' in self.data or 'cspc' in self.data or 'moments' in self.data:
1183 1185 self.data['noise'] = {}
1184 1186 self.data['rti'] = {}
1185 1187 if 'noise' not in self.plottypes:
1186 1188 self.plottypes.append('noise')
1187 1189 if 'rti' not in self.plottypes:
1188 1190 self.plottypes.append('rti')
1189 1191
1190 1192 def shape(self, key):
1191 1193 '''
1192 1194 Get the shape of the one-element data for the given key
1193 1195 '''
1194 1196
1195 1197 if len(self.data[key]):
1196 1198 if 'spc' in key or not self.buffering:
1197 1199 return self.data[key].shape
1198 1200 return self.data[key][self.__times[0]].shape
1199 1201 return (0,)
1200 1202
1201 1203 def update(self, dataOut, tm):
1202 1204 '''
1203 1205 Update data object with new dataOut
1204 1206 '''
1205 1207
1206 1208 if tm in self.__times:
1207 1209 return
1208 1210 self.profileIndex = dataOut.profileIndex
1209 1211 self.tm = tm
1210 1212 self.type = dataOut.type
1211 1213 self.parameters = getattr(dataOut, 'parameters', [])
1212 1214
1213 1215 if hasattr(dataOut, 'meta'):
1214 1216 self.meta.update(dataOut.meta)
1215 1217
1216 1218 if hasattr(dataOut, 'pairsList'):
1217 1219 self.pairs = dataOut.pairsList
1218 1220
1219 1221 self.interval = dataOut.getTimeInterval()
1220 1222 self.localtime = dataOut.useLocalTime
1221 1223 if True in ['spc' in ptype for ptype in self.plottypes]:
1222 1224 self.xrange = (dataOut.getFreqRange(1)/1000.,
1223 1225 dataOut.getAcfRange(1), dataOut.getVelRange(1))
1224 1226 self.factor = dataOut.normFactor
1225 1227 self.__heights.append(dataOut.heightList)
1226 1228 self.__all_heights.update(dataOut.heightList)
1227 1229 self.__times.append(tm)
1228 1230
1229 1231 for plot in self.plottypes:
1230 1232 if plot in ('spc', 'spc_moments', 'spc_cut'):
1231 1233 z = dataOut.data_spc/dataOut.normFactor
1232 1234 buffer = 10*numpy.log10(z)
1233 1235 if plot == 'cspc':
1234 1236 z = dataOut.data_spc/dataOut.normFactor
1235 1237 buffer = (dataOut.data_spc, dataOut.data_cspc)
1236 1238 if plot == 'noise':
1237 1239 buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor)
1238 1240 if plot in ('rti', 'spcprofile'):
1239 1241 buffer = dataOut.getPower()
1240 1242 if plot == 'snr_db':
1241 1243 buffer = dataOut.data_SNR
1242 1244 if plot == 'snr':
1243 1245 buffer = 10*numpy.log10(dataOut.data_SNR)
1244 1246 if plot == 'dop':
1245 1247 buffer = dataOut.data_DOP
1246 1248 if plot == 'pow':
1247 1249 buffer = 10*numpy.log10(dataOut.data_POW)
1248 1250 if plot == 'width':
1249 1251 buffer = dataOut.data_WIDTH
1250 1252 if plot == 'coh':
1251 1253 buffer = dataOut.getCoherence()
1252 1254 if plot == 'phase':
1253 1255 buffer = dataOut.getCoherence(phase=True)
1254 1256 if plot == 'output':
1255 1257 buffer = dataOut.data_output
1256 1258 if plot == 'param':
1257 1259 buffer = dataOut.data_param
1258 1260 if plot == 'scope':
1259 1261 buffer = dataOut.data
1260 1262 self.flagDataAsBlock = dataOut.flagDataAsBlock
1261 1263 self.nProfiles = dataOut.nProfiles
1262 1264
1263 1265 if plot == 'spc':
1264 1266 self.data['spc'] = buffer
1265 1267 elif plot == 'cspc':
1266 1268 self.data['spc'] = buffer[0]
1267 1269 self.data['cspc'] = buffer[1]
1268 1270 elif plot == 'spc_moments':
1269 1271 self.data['spc'] = buffer
1270 1272 self.data['moments'][tm] = dataOut.moments
1271 1273 else:
1272 1274 if self.buffering:
1273 1275 self.data[plot][tm] = buffer
1274 1276 else:
1275 1277 self.data[plot] = buffer
1276 1278
1277 1279 if dataOut.channelList is None:
1278 1280 self.channels = range(buffer.shape[0])
1279 1281 else:
1280 1282 self.channels = dataOut.channelList
1281 1283
1282 1284 if buffer is None:
1283 1285 self.flagNoData = True
1284 1286 raise schainpy.admin.SchainWarning('Attribute data_{} is empty'.format(self.key))
1285 1287
1286 1288 def normalize_heights(self):
1287 1289 '''
1288 1290 Ensure same-dimension of the data for different heighList
1289 1291 '''
1290 1292
1291 1293 H = numpy.array(list(self.__all_heights))
1292 1294 H.sort()
1293 1295 for key in self.data:
1294 1296 shape = self.shape(key)[:-1] + H.shape
1295 1297 for tm, obj in list(self.data[key].items()):
1296 1298 h = self.__heights[self.__times.index(tm)]
1297 1299 if H.size == h.size:
1298 1300 continue
1299 1301 index = numpy.where(numpy.in1d(H, h))[0]
1300 1302 dummy = numpy.zeros(shape) + numpy.nan
1301 1303 if len(shape) == 2:
1302 1304 dummy[:, index] = obj
1303 1305 else:
1304 1306 dummy[index] = obj
1305 1307 self.data[key][tm] = dummy
1306 1308
1307 1309 self.__heights = [H for tm in self.__times]
1308 1310
1309 1311 def jsonify(self, plot_name, plot_type, decimate=False):
1310 1312 '''
1311 1313 Convert data to json
1312 1314 '''
1313 1315
1314 1316 tm = self.times[-1]
1315 1317 dy = int(self.heights.size/self.MAXNUMY) + 1
1316 1318 if self.key in ('spc', 'cspc') or not self.buffering:
1317 1319 dx = int(self.data[self.key].shape[1]/self.MAXNUMX) + 1
1318 1320 data = self.roundFloats(
1319 1321 self.data[self.key][::, ::dx, ::dy].tolist())
1320 1322 else:
1321 1323 data = self.roundFloats(self.data[self.key][tm].tolist())
1322 1324 if self.key is 'noise':
1323 1325 data = [[x] for x in data]
1324 1326
1325 1327 meta = {}
1326 1328 ret = {
1327 1329 'plot': plot_name,
1328 1330 'code': self.exp_code,
1329 1331 'time': float(tm),
1330 1332 'data': data,
1331 1333 }
1332 1334 meta['type'] = plot_type
1333 1335 meta['interval'] = float(self.interval)
1334 1336 meta['localtime'] = self.localtime
1335 1337 meta['yrange'] = self.roundFloats(self.heights[::dy].tolist())
1336 1338 if 'spc' in self.data or 'cspc' in self.data:
1337 1339 meta['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist())
1338 1340 else:
1339 1341 meta['xrange'] = []
1340 1342
1341 1343 meta.update(self.meta)
1342 1344 ret['metadata'] = meta
1343 1345 return json.dumps(ret)
1344 1346
1345 1347 @property
1346 1348 def times(self):
1347 1349 '''
1348 1350 Return the list of times of the current data
1349 1351 '''
1350 1352
1351 1353 ret = numpy.array(self.__times)
1352 1354 ret.sort()
1353 1355 return ret
1354 1356
1355 1357 @property
1356 1358 def min_time(self):
1357 1359 '''
1358 1360 Return the minimun time value
1359 1361 '''
1360 1362
1361 1363 return self.times[0]
1362 1364
1363 1365 @property
1364 1366 def max_time(self):
1365 1367 '''
1366 1368 Return the maximun time value
1367 1369 '''
1368 1370
1369 1371 return self.times[-1]
1370 1372
1371 1373 @property
1372 1374 def heights(self):
1373 1375 '''
1374 1376 Return the list of heights of the current data
1375 1377 '''
1376 1378
1377 1379 return numpy.array(self.__heights[-1])
1378 1380
1379 1381 @staticmethod
1380 1382 def roundFloats(obj):
1381 1383 if isinstance(obj, list):
1382 1384 return list(map(PlotterData.roundFloats, obj))
1383 1385 elif isinstance(obj, float):
1384 1386 return round(obj, 2)
@@ -1,63 +1,68
1 1 '''
2 2 Created on Jul 16, 2014
3 3
4 4 @author: Miguel Urco
5 @author: Juan C. Espinoza
5 6 '''
6 7
7 8 import os
8 9 from setuptools import setup, Extension
9 10 from setuptools.command.build_ext import build_ext as _build_ext
10 11 from schainpy import __version__
11 12
12 13 class build_ext(_build_ext):
13 14 def finalize_options(self):
14 15 _build_ext.finalize_options(self)
15 16 # Prevent numpy from thinking it is still in its setup process:
16 17 __builtins__.__NUMPY_SETUP__ = False
17 18 import numpy
18 19 self.include_dirs.append(numpy.get_include())
19 20
20 setup(name = "schainpy",
21 version = __version__,
22 description = "Python tools to read, write and process Jicamarca data",
23 author = "Miguel Urco",
24 author_email = "miguel.urco@jro.igp.gob.pe",
25 url = "http://jro.igp.gob.pe",
26 packages = {'schainpy',
27 'schainpy.model',
28 'schainpy.model.data',
29 'schainpy.model.graphics',
30 'schainpy.model.io',
31 'schainpy.model.proc',
32 'schainpy.model.serializer',
33 'schainpy.model.utils',
34 'schainpy.utils',
35 'schainpy.gui',
36 'schainpy.gui.figures',
37 'schainpy.gui.viewcontroller',
38 'schainpy.gui.viewer',
39 'schainpy.gui.viewer.windows',
40 'schainpy.cli'},
41 ext_package = 'schainpy',
42 package_data = {'': ['schain.conf.template'],
43 'schainpy.gui.figures': ['*.png', '*.jpg'],
44 'schainpy.files': ['*.oga']
45 },
46 include_package_data = False,
47 scripts = ['schainpy/gui/schainGUI'],
48 entry_points = {
49 'console_scripts': [
50 'schain = schainpy.cli.cli:main',
51 ],
52 },
53 cmdclass = {'build_ext': build_ext},
54 setup_requires = ["numpy >= 1.11.2"],
55 install_requires = [
56 "scipy",
57 "h5py",
58 "matplotlib",
59 "pyzmq",
60 "fuzzywuzzy",
61 "click",
62 ],
21 setup(
22 name = "schainpy",
23 version = __version__,
24 description = "Python tools to read, write and process Jicamarca data",
25 author = "Miguel Urco, Juan C. Espinoza",
26 author_email = "juan.espinoza@jro.igp.gob.pe",
27 url = "http://jro-dev.igp.gob.pe/rhodecode/schain",
28 packages = {
29 'schainpy',
30 'schainpy.model',
31 'schainpy.model.data',
32 'schainpy.model.graphics',
33 'schainpy.model.io',
34 'schainpy.model.proc',
35 'schainpy.model.utils',
36 'schainpy.utils',
37 'schainpy.gui',
38 'schainpy.gui.figures',
39 'schainpy.gui.viewcontroller',
40 'schainpy.gui.viewer',
41 'schainpy.gui.viewer.windows',
42 'schainpy.cli',
43 },
44 package_data = {'': ['schain.conf.template'],
45 'schainpy.gui.figures': ['*.png', '*.jpg'],
46 'schainpy.files': ['*.oga']
47 },
48 include_package_data = False,
49 scripts = ['schainpy/gui/schainGUI'],
50 entry_points = {
51 'console_scripts': [
52 'schain = schainpy.cli.cli:main',
53 ],
54 },
55 cmdclass = {'build_ext': build_ext},
56 ext_modules=[
57 Extension("schainpy.model.data._noise", ["schainc/_noise.c"]),
58 ],
59 setup_requires = ["numpy"],
60 install_requires = [
61 "scipy",
62 "h5py",
63 "matplotlib",
64 "pyzmq",
65 "fuzzywuzzy",
66 "click",
67 ],
63 68 )
General Comments 0
You need to be logged in to leave comments. Login now