##// END OF EJS Templates
merge v2.3
José Chávez -
r1098:831d2c3bd88d merge
parent child
Show More
@@ -15,11 +15,11 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
15 15 from schainpy.model.proc.jroproc_base import Operation
16 16 from schainpy.utils import log
17 17
18 jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90]
18 jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90]
19 19 blu_values = matplotlib.pyplot.get_cmap(
20 "seismic_r", 20)(numpy.arange(20))[10:15]
20 'seismic_r', 20)(numpy.arange(20))[10:15]
21 21 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
22 "jro", numpy.vstack((blu_values, jet_values)))
22 'jro', numpy.vstack((blu_values, jet_values)))
23 23 matplotlib.pyplot.register_cmap(cmap=ncmap)
24 24
25 25 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')]
@@ -49,6 +49,10 class PlotData(Operation, Process):
49 49 __MAXNUMX = 80
50 50 __missing = 1E30
51 51
52 __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax',
53 'zlimits', 'xlabel', 'ylabel', 'cb_label', 'title', 'titles', 'colorbar',
54 'bgcolor', 'width', 'height', 'localtime', 'oneFigure', 'showprofile']
55
52 56 def __init__(self, **kwargs):
53 57
54 58 Operation.__init__(self, plot=True, **kwargs)
@@ -91,6 +95,7 class PlotData(Operation, Process):
91 95 self.colorbar = kwargs.get('colorbar', True)
92 96 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
93 97 self.titles = ['' for __ in range(16)]
98 self.polar = False
94 99
95 100 def __fmtTime(self, x, pos):
96 101 '''
@@ -103,6 +108,10 class PlotData(Operation, Process):
103 108 Common setup for all figures, here figures and axes are created
104 109 '''
105 110
111 if self.CODE not in self.data:
112 raise ValueError(log.error('Missing data for {}'.format(self.CODE),
113 self.name))
114
106 115 self.setup()
107 116
108 117 self.time_label = 'LT' if self.localtime else 'UTC'
@@ -131,7 +140,8 class PlotData(Operation, Process):
131 140 facecolor='w')
132 141 self.figures.append(fig)
133 142 for n in range(self.nplots):
134 ax = fig.add_subplot(self.nrows, self.ncols, n + 1)
143 ax = fig.add_subplot(self.nrows, self.ncols,
144 n + 1, polar=self.polar)
135 145 ax.tick_params(labelsize=8)
136 146 ax.firsttime = True
137 147 ax.index = 0
@@ -148,7 +158,7 class PlotData(Operation, Process):
148 158 fig = plt.figure(figsize=(self.width, self.height),
149 159 edgecolor='k',
150 160 facecolor='w')
151 ax = fig.add_subplot(1, 1, 1)
161 ax = fig.add_subplot(1, 1, 1, polar=self.polar)
152 162 ax.tick_params(labelsize=8)
153 163 ax.firsttime = True
154 164 ax.index = 0
@@ -348,7 +358,7 class PlotData(Operation, Process):
348 358 else:
349 359 if self.xaxis is 'time':
350 360 dt = self.getDateTime(self.max_time)
351 xmax = (dt.replace(hour=int(self.xmax), minute=0, second=0) -
361 xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) -
352 362 datetime.datetime(1970, 1, 1)).total_seconds()
353 363 if self.data.localtime:
354 364 xmax += time.timezone
@@ -363,8 +373,6 class PlotData(Operation, Process):
363 373 0][0] < 0 else numpy.where(ymax < Y)[0][0]
364 374 ystep = Y[i - 1] / 5
365 375
366 ystep = 200 if ymax >= 800 else 100 if ymax >= 400 else 50 if ymax >= 200 else 20
367
368 376 for n, ax in enumerate(self.axes):
369 377 if ax.firsttime:
370 378 ax.set_facecolor(self.bgcolor)
@@ -384,7 +392,8 class PlotData(Operation, Process):
384 392 [tick.set_visible(False)
385 393 for tick in self.pf_axes[n].get_yticklabels()]
386 394 if self.colorbar:
387 ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10)
395 ax.cbar = plt.colorbar(
396 ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10)
388 397 ax.cbar.ax.tick_params(labelsize=8)
389 398 ax.cbar.ax.press = None
390 399 if self.cb_label:
@@ -394,13 +403,19 class PlotData(Operation, Process):
394 403 else:
395 404 ax.cbar = None
396 405
397 ax.set_title('{} - {} {}'.format(
398 self.titles[n],
399 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
400 self.time_label),
401 size=8)
402 ax.set_xlim(xmin, xmax)
403 ax.set_ylim(ymin, ymax)
406 if not self.polar:
407 ax.set_xlim(xmin, xmax)
408 ax.set_ylim(ymin, ymax)
409 ax.set_title('{} - {} {}'.format(
410 self.titles[n],
411 self.getDateTime(self.max_time).strftime('%H:%M:%S'),
412 self.time_label),
413 size=8)
414 else:
415 ax.set_title('{}'.format(self.titles[n]), size=8)
416 ax.set_ylim(0, 90)
417 ax.set_yticks(numpy.arange(0, 90, 20))
418 ax.yaxis.labelpad = 40
404 419
405 420 def __plot(self):
406 421 '''
@@ -413,6 +428,7 class PlotData(Operation, Process):
413 428 for n, fig in enumerate(self.figures):
414 429 if self.nrows == 0 or self.nplots == 0:
415 430 log.warning('No data', self.name)
431 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
416 432 continue
417 433
418 434 fig.tight_layout()
@@ -437,7 +453,7 class PlotData(Operation, Process):
437 453 str(self.contador),
438 454 )
439 455 )
440 print 'Saving figure: {}'.format(figname)
456 log.log('Saving figure: {}'.format(figname), self.name)
441 457 fig.savefig(figname)
442 458
443 459 def plot(self):
@@ -820,7 +836,7 class PlotSkyMapData(PlotData):
820 836 Plot for meteors detection data
821 837 '''
822 838
823 CODE = 'met'
839 CODE = 'param'
824 840
825 841 def setup(self):
826 842
@@ -828,25 +844,17 class PlotSkyMapData(PlotData):
828 844 self.nrows = 1
829 845 self.width = 7.2
830 846 self.height = 7.2
831
847 self.nplots = 1
832 848 self.xlabel = 'Zonal Zenith Angle (deg)'
833 849 self.ylabel = 'Meridional Zenith Angle (deg)'
834
835 if self.figure is None:
836 self.figure = plt.figure(figsize=(self.width, self.height),
837 edgecolor='k',
838 facecolor='w')
839 else:
840 self.figure.clf()
841
842 self.ax = plt.subplot2grid(
843 (self.nrows, self.ncols), (0, 0), 1, 1, polar=True)
844 self.ax.firsttime = True
850 self.polar = True
851 self.ymin = -180
852 self.ymax = 180
853 self.colorbar = False
845 854
846 855 def plot(self):
847 856
848 arrayParameters = numpy.concatenate(
849 [self.data['param'][t] for t in self.times])
857 arrayParameters = numpy.concatenate(self.data['param'])
850 858 error = arrayParameters[:, -1]
851 859 indValid = numpy.where(error == 0)[0]
852 860 finalMeteor = arrayParameters[indValid, :]
@@ -856,23 +864,19 class PlotSkyMapData(PlotData):
856 864 x = finalAzimuth * numpy.pi / 180
857 865 y = finalZenith
858 866
859 if self.ax.firsttime:
860 self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0]
861 self.ax.set_ylim(0, 90)
862 self.ax.set_yticks(numpy.arange(0, 90, 20))
863 self.ax.set_xlabel(self.xlabel)
864 self.ax.set_ylabel(self.ylabel)
865 self.ax.yaxis.labelpad = 40
866 self.ax.firsttime = False
867 ax = self.axes[0]
868
869 if ax.firsttime:
870 ax.plot = ax.plot(x, y, 'bo', markersize=5)[0]
867 871 else:
868 self.ax.plot.set_data(x, y)
872 ax.plot.set_data(x, y)
869 873
870 874 dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S')
871 875 dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S')
872 876 title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1,
873 877 dt2,
874 878 len(x))
875 self.ax.set_title(title, size=8)
879 self.titles[0] = title
876 880 self.saveTime = self.max_time
877 881
878 882
@@ -553,7 +553,10 class JRODataIO:
553 553 return dtype_width
554 554
555 555 def getAllowedArgs(self):
556 return inspect.getargspec(self.run).args
556 if hasattr(self, '__attrs__'):
557 return self.__attrs__
558 else:
559 return inspect.getargspec(self.run).args
557 560
558 561
559 562 class JRODataReader(JRODataIO):
@@ -513,10 +513,8 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa
513 513 self.dataOut = Spectra()
514 514 self.profileIndex = 1 # Always
515 515 self.dataOut.flagNoData = False
516 self.dataOut.nRdPairs = 0
517 self.dataOut.pairsList = []
518 self.dataOut.data_spc = None
519 self.dataOut.noise = []
516 self.dataOut.nRdPairs = 0
517 self.dataOut.data_spc = None
520 518 self.dataOut.velocityX = []
521 519 self.dataOut.velocityY = []
522 520 self.dataOut.velocityV = []
@@ -494,17 +494,14 class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader
494 494 self.dataOut = Spectra()
495 495 self.profileIndex = 1 # Always
496 496 self.dataOut.flagNoData = False
497 self.dataOut.nRdPairs = 0
498 self.dataOut.pairsList = []
499 self.dataOut.data_spc = None
500
501 self.dataOut.normFactor = 1
497 self.dataOut.nRdPairs = 0
498 self.dataOut.data_spc = None
502 499 self.nextfileflag = True
503 500 self.dataOut.RadarConst = 0
504 501 self.dataOut.HSDV = []
505 502 self.dataOut.NPW = []
506 503 self.dataOut.COFA = []
507 self.dataOut.noise = 0
504 # self.dataOut.noise = 0
508 505
509 506 def Files2Read(self, fp):
510 507 '''
@@ -588,6 +585,7 class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader
588 585 self.dataOut.noise = self.dataOut.getNoise()
589 586 # print 'ACAAAAAA', self.dataOut.noise
590 587 self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise
588 self.dataOut.normFactor = 1
591 589 # print 'self.dataOut.noise',self.dataOut.noise
592 590
593 591 return self.dataOut.data_spc
@@ -64,10 +64,17 class ProcessingUnit(object):
64 64
65 65 self.args = args
66 66 self.kwargs = kwargs
67
68 if not hasattr(self, 'name'):
69 self.name = self.__class__.__name__
70
67 71 checkKwargs(self.run, kwargs)
68 72
69 73 def getAllowedArgs(self):
70 return inspect.getargspec(self.run).args
74 if hasattr(self, '__attrs__'):
75 return self.__attrs__
76 else:
77 return inspect.getargspec(self.run).args
71 78
72 79 def addOperationKwargs(self, objId, **kwargs):
73 80 '''
@@ -309,10 +316,15 class Operation(object):
309 316 self.__buffer = None
310 317 self.isConfig = False
311 318 self.kwargs = kwargs
319 if not hasattr(self, 'name'):
320 self.name = self.__class__.__name__
312 321 checkKwargs(self.run, kwargs)
313 322
314 323 def getAllowedArgs(self):
315 return inspect.getargspec(self.run).args
324 if hasattr(self, '__attrs__'):
325 return self.__attrs__
326 else:
327 return inspect.getargspec(self.run).args
316 328
317 329 def setup(self):
318 330
@@ -1408,18 +1408,18 class SpectralMoments(Operation):
1408 1408 def __calculateMoments(self, oldspec, oldfreq, n0,
1409 1409 nicoh = None, graph = None, smooth = None, type1 = None, fwindow = None, snrth = None, dc = None, aliasing = None, oldfd = None, wwauto = None):
1410 1410
1411 if (nicoh == None): nicoh = 1
1412 if (graph == None): graph = 0
1413 if (smooth == None): smooth = 0
1411 if (nicoh is None): nicoh = 1
1412 if (graph is None): graph = 0
1413 if (smooth is None): smooth = 0
1414 1414 elif (self.smooth < 3): smooth = 0
1415 1415
1416 if (type1 == None): type1 = 0
1417 if (fwindow == None): fwindow = numpy.zeros(oldfreq.size) + 1
1418 if (snrth == None): snrth = -3
1419 if (dc == None): dc = 0
1420 if (aliasing == None): aliasing = 0
1421 if (oldfd == None): oldfd = 0
1422 if (wwauto == None): wwauto = 0
1416 if (type1 is None): type1 = 0
1417 if (fwindow is None): fwindow = numpy.zeros(oldfreq.size) + 1
1418 if (snrth is None): snrth = -3
1419 if (dc is None): dc = 0
1420 if (aliasing is None): aliasing = 0
1421 if (oldfd is None): oldfd = 0
1422 if (wwauto is None): wwauto = 0
1423 1423
1424 1424 if (n0 < 1.e-20): n0 = 1.e-20
1425 1425
@@ -1719,7 +1719,7 class SpectralFitting(Operation):
1719 1719 error1 = p0*numpy.nan
1720 1720
1721 1721 #Save
1722 if self.dataOut.data_param == None:
1722 if self.dataOut.data_param is None:
1723 1723 self.dataOut.data_param = numpy.zeros((nGroups, p0.size, nHeights))*numpy.nan
1724 1724 self.dataOut.data_error = numpy.zeros((nGroups, p0.size + 1, nHeights))*numpy.nan
1725 1725
@@ -2382,7 +2382,7 class WindProfiler(Operation):
2382 2382
2383 2383 self.__isConfig = True
2384 2384
2385 if self.__buffer == None:
2385 if self.__buffer is None:
2386 2386 self.__buffer = dataOut.data_param
2387 2387 self.__firstdata = copy.copy(dataOut)
2388 2388
@@ -2424,7 +2424,7 class WindProfiler(Operation):
2424 2424 else: mode = 'SA'
2425 2425
2426 2426 #Borrar luego esto
2427 if dataOut.groupList == None:
2427 if dataOut.groupList is None:
2428 2428 dataOut.groupList = [(0,1),(0,2),(1,2)]
2429 2429 groupList = dataOut.groupList
2430 2430 C = 3e8
@@ -2446,7 +2446,7 class WindProfiler(Operation):
2446 2446
2447 2447 self.__isConfig = True
2448 2448
2449 if self.__buffer == None:
2449 if self.__buffer is None:
2450 2450 self.__buffer = dataOut.data_param
2451 2451 self.__firstdata = copy.copy(dataOut)
2452 2452
@@ -2808,7 +2808,7 class SMDetection(Operation):
2808 2808
2809 2809
2810 2810 #Getting Pairslist
2811 if channelPositions == None:
2811 if channelPositions is None:
2812 2812 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
2813 2813 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
2814 2814 meteorOps = SMOperations()
@@ -2939,7 +2939,7 class SMDetection(Operation):
2939 2939 # arrayFinal = arrayParameters.reshape((1,arrayParameters.shape[0],arrayParameters.shape[1]))
2940 2940 dataOut.data_param = arrayParameters
2941 2941
2942 if arrayParameters == None:
2942 if arrayParameters is None:
2943 2943 dataOut.flagNoData = True
2944 2944 else:
2945 2945 dataOut.flagNoData = True
@@ -3475,7 +3475,7 class CorrectSMPhases(Operation):
3475 3475 arrayParameters[:,8:12] = numpy.angle(numpy.exp(1j*(arrayParameters[:,8:12] + phaseOffsets)))
3476 3476
3477 3477 meteorOps = SMOperations()
3478 if channelPositions == None:
3478 if channelPositions is None:
3479 3479 # channelPositions = [(2.5,0), (0,2.5), (0,0), (0,4.5), (-2,0)] #T
3480 3480 channelPositions = [(4.5,2), (2,4.5), (2,2), (2,0), (0,2)] #Estrella
3481 3481
@@ -3652,7 +3652,7 class SMPhaseCalibration(Operation):
3652 3652
3653 3653 self.__isConfig = True
3654 3654
3655 if self.__buffer == None:
3655 if self.__buffer is None:
3656 3656 self.__buffer = dataOut.data_param.copy()
3657 3657
3658 3658 else:
@@ -60,12 +60,17 class throttle(object):
60 60 def __call__(self, fn):
61 61 @wraps(fn)
62 62 def wrapper(*args, **kwargs):
63 now = datetime.datetime.now()
64 time_since_last_call = now - self.time_of_last_call
65 time_left = self.throttle_period - time_since_last_call
63 coerce = kwargs.pop('coerce', None)
64 if coerce:
65 self.time_of_last_call = datetime.datetime.now()
66 return fn(*args, **kwargs)
67 else:
68 now = datetime.datetime.now()
69 time_since_last_call = now - self.time_of_last_call
70 time_left = self.throttle_period - time_since_last_call
66 71
67 if time_left > datetime.timedelta(seconds=0):
68 return
72 if time_left > datetime.timedelta(seconds=0):
73 return
69 74
70 75 self.time_of_last_call = datetime.datetime.now()
71 76 return fn(*args, **kwargs)
@@ -104,6 +109,9 class Data(object):
104 109 ret = numpy.swapaxes(ret, 0, 1)
105 110 return ret
106 111
112 def __contains__(self, key):
113 return key in self.data
114
107 115 def setup(self):
108 116 '''
109 117 Configure object
@@ -242,6 +250,8 class PublishData(Operation):
242 250 Operation to send data over zmq.
243 251 '''
244 252
253 __attrs__ = ['host', 'port', 'delay', 'zeromq', 'mqtt', 'verbose']
254
245 255 def __init__(self, **kwargs):
246 256 """Inicio."""
247 257 Operation.__init__(self, **kwargs)
@@ -426,6 +436,8 class PublishData(Operation):
426 436
427 437 class ReceiverData(ProcessingUnit):
428 438
439 __attrs__ = ['server']
440
429 441 def __init__(self, **kwargs):
430 442
431 443 ProcessingUnit.__init__(self, **kwargs)
@@ -464,6 +476,7 class ReceiverData(ProcessingUnit):
464 476 class PlotterReceiver(ProcessingUnit, Process):
465 477
466 478 throttle_value = 5
479 __attrs__ = ['server', 'plottypes', 'realtime', 'localtime', 'throttle']
467 480
468 481 def __init__(self, **kwargs):
469 482
@@ -564,26 +577,30 class PlotterReceiver(ProcessingUnit, Process):
564 577
565 578 while True:
566 579 dataOut = self.receiver.recv_pyobj()
567 tm = dataOut.utctime
568 if dataOut.useLocalTime:
569 if not self.localtime:
570 tm += time.timezone
571 dt = datetime.datetime.fromtimestamp(tm).date()
572 else:
573 if self.localtime:
574 tm -= time.timezone
575 dt = datetime.datetime.utcfromtimestamp(tm).date()
576 sended = False
577 if dt not in self.dates:
578 if self.data:
579 self.data.ended = True
580 self.send(self.data)
581 sended = True
582 self.data.setup()
583 self.dates.append(dt)
584
585 self.data.update(dataOut)
580 if not dataOut.flagNoData:
581 if dataOut.type == 'Parameters':
582 tm = dataOut.utctimeInit
583 else:
584 tm = dataOut.utctime
585 if dataOut.useLocalTime:
586 if not self.localtime:
587 tm += time.timezone
588 dt = datetime.datetime.fromtimestamp(tm).date()
589 else:
590 if self.localtime:
591 tm -= time.timezone
592 dt = datetime.datetime.utcfromtimestamp(tm).date()
593 coerce = False
594 if dt not in self.dates:
595 if self.data:
596 self.data.ended = True
597 self.send(self.data)
598 coerce = True
599 self.data.setup()
600 self.dates.append(dt)
586 601
602 self.data.update(dataOut)
603
587 604 if dataOut.finished is True:
588 605 self.connections -= 1
589 606 if self.connections == 0 and dt in self.dates:
@@ -594,9 +611,9 class PlotterReceiver(ProcessingUnit, Process):
594 611 if self.realtime:
595 612 self.send(self.data)
596 613 # self.sender_web.send_string(self.data.jsonify())
597 else:
598 if not sended:
599 self.sendData(self.send, self.data)
614 else:
615 self.sendData(self.send, self.data, coerce=coerce)
616 coerce = False
600 617
601 618 return
602 619
@@ -1,6 +1,5
1 1 import schainpy
2 2 from schainpy.model import Operation, ProcessingUnit
3 from importlib import import_module
4 3 from pydoc import locate
5 4
6 5 def clean_modules(module):
@@ -11,17 +10,17 def clean_modules(module):
11 10
12 11 def check_module(possible, instance):
13 12 def check(x):
14 try:
13 try:
15 14 instancia = locate('schainpy.model.{}'.format(x))
16 15 return isinstance(instancia(), instance)
17 16 except Exception as e:
18 return False
17 return False
19 18 clean = clean_modules(possible)
20 19 return [x for x in clean if check(x)]
21 20
22 21
23 22 def getProcs():
24 module = dir(import_module('schainpy.model'))
23 module = dir(schainpy.model)
25 24 procs = check_module(module, ProcessingUnit)
26 25 try:
27 26 procs.remove('ProcessingUnit')
@@ -30,7 +29,7 def getProcs():
30 29 return procs
31 30
32 31 def getOperations():
33 module = dir(import_module('schainpy.model'))
32 module = dir(schainpy.model)
34 33 noProcs = [x for x in module if not x.endswith('Proc')]
35 34 operations = check_module(noProcs, Operation)
36 35 try:
@@ -53,7 +52,7 def getArgs(op):
53 52 return args
54 53
55 54 def getAll():
56 allModules = dir(import_module('schainpy.model'))
55 allModules = dir(schainpy.model)
57 56 modules = check_module(allModules, Operation)
58 57 modules.extend(check_module(allModules, ProcessingUnit))
59 58 return modules
General Comments 0
You need to be logged in to leave comments. Login now