##// END OF EJS Templates
Merge remote-tracking branch 'HF/ind_plt_chs' into schain_mp
Juan C. Espinoza -
r1003:62df0cc8d2f7 merge
parent child
Show More
@@ -69,8 +69,10 def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_da
69 for process in processes:
69 for process in processes:
70 process.join()
70 process.join()
71 process.terminate()
71 process.terminate()
72
72 time.sleep(3)
73 time.sleep(3)
73
74
75
74 class ParameterConf():
76 class ParameterConf():
75
77
76 id = None
78 id = None
@@ -6,6 +6,7 import numpy
6 import datetime
6 import datetime
7 import numpy as np
7 import numpy as np
8 import matplotlib
8 import matplotlib
9 import glob
9 matplotlib.use('TkAgg')
10 matplotlib.use('TkAgg')
10 import matplotlib.pyplot as plt
11 import matplotlib.pyplot as plt
11 from mpl_toolkits.axes_grid1 import make_axes_locatable
12 from mpl_toolkits.axes_grid1 import make_axes_locatable
@@ -59,6 +60,15 class PlotData(Operation, Process):
59 self.times = []
60 self.times = []
60 #self.interactive = self.kwargs['parent']
61 #self.interactive = self.kwargs['parent']
61
62
63 '''
64 this new parameter is created to plot data from varius channels at different figures
65 1. crear una lista de figuras donde se puedan plotear las figuras,
66 2. dar las opciones de configuracion a cada figura, estas opciones son iguales para ambas figuras
67 3. probar?
68 '''
69 self.ind_plt_ch = kwargs.get('ind_plt_ch', False)
70 self.figurelist = None
71
62
72
63 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
73 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
64
74
@@ -90,25 +100,98 class PlotData(Operation, Process):
90
100
91 return x, y, z
101 return x, y, z
92
102
103 '''
104 JM:
105 elimana las otras imagenes generadas debido a que lso workers no llegan en orden y le pueden
106 poner otro tiempo a la figura q no necesariamente es el ultimo.
107 Solo se realiza cuando termina la imagen.
108 Problemas:
109
110 File "/home/ci-81/workspace/schainv2.3/schainpy/model/graphics/jroplot_data.py", line 145, in __plot
111 for n, eachfigure in enumerate(self.figurelist):
112 TypeError: 'NoneType' object is not iterable
113
114 '''
115 def deleteanotherfiles(self):
116 figurenames=[]
117 if self.figurelist != None:
118 for n, eachfigure in enumerate(self.figurelist):
119 #add specific name for each channel in channelList
120 ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE,
121 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d')))
122 figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE,
123 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
124
125 for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures
126 if ghostfigure != figname:
127 os.remove(ghostfigure)
128 print 'Removing GhostFigures:' , figname
129 else :
130 '''Erasing ghost images for just on******************'''
131 ghostfigname = os.path.join(self.save, '{}_{}'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d')))
132 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
133 for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures
134 if ghostfigure != figname:
135 os.remove(ghostfigure)
136 print 'Removing GhostFigures:' , figname
137
93 def __plot(self):
138 def __plot(self):
94
139
95 print 'plotting...{}'.format(self.CODE)
140 print 'plotting...{}'.format(self.CODE)
96
141 if self.ind_plt_ch is False : #standard
97 if self.show:
142 if self.show:
98 self.figure.show()
143 self.figure.show()
99
100 self.plot()
144 self.plot()
101 plt.tight_layout()
145 plt.tight_layout()
102 self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(),
146 self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(),
103 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
147 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
148 else :
149 print 'len(self.figurelist): ',len(self.figurelist)
150 for n, eachfigure in enumerate(self.figurelist):
151 if self.show:
152 eachfigure.show()
153
154 self.plot()
155 eachfigure.tight_layout() # ajuste de cada subplot
156 eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(),
157 datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d')))
158
159 # if self.save:
160 # if self.ind_plt_ch is False : #standard
161 # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
162 # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
163 # print 'Saving figure: {}'.format(figname)
164 # self.figure.savefig(figname)
165 # else :
166 # for n, eachfigure in enumerate(self.figurelist):
167 # #add specific name for each channel in channelList
168 # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE,
169 # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
170 #
171 # print 'Saving figure: {}'.format(figname)
172 # eachfigure.savefig(figname)
173
174 if self.ind_plt_ch is False :
175 self.figure.canvas.draw()
176 else :
177 for eachfigure in self.figurelist:
178 eachfigure.canvas.draw()
104
179
105 if self.save:
180 if self.save:
181 if self.ind_plt_ch is False : #standard
106 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
182 figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE,
107 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
183 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
108 print 'Saving figure: {}'.format(figname)
184 print 'Saving figure: {}'.format(figname)
109 self.figure.savefig(figname)
185 self.figure.savefig(figname)
186 else :
187 for n, eachfigure in enumerate(self.figurelist):
188 #add specific name for each channel in channelList
189 figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE,
190 datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S')))
191
192 print 'Saving figure: {}'.format(figname)
193 eachfigure.savefig(figname)
110
194
111 self.figure.canvas.draw()
112
195
113 def plot(self):
196 def plot(self):
114
197
@@ -157,6 +240,7 class PlotData(Operation, Process):
157 self.ended = True
240 self.ended = True
158 self.isConfig = False
241 self.isConfig = False
159 self.__plot()
242 self.__plot()
243 self.deleteanotherfiles() #CLPDG
160 elif seconds_passed >= self.data['throttle']:
244 elif seconds_passed >= self.data['throttle']:
161 print 'passed', seconds_passed
245 print 'passed', seconds_passed
162 self.__plot()
246 self.__plot()
@@ -230,7 +314,6 class PlotSpectraData(PlotData):
230 z = self.data[self.CODE]
314 z = self.data[self.CODE]
231
315
232 for n, ax in enumerate(self.axes):
316 for n, ax in enumerate(self.axes):
233
234 if ax.firsttime:
317 if ax.firsttime:
235 self.xmax = self.xmax if self.xmax else np.nanmax(x)
318 self.xmax = self.xmax if self.xmax else np.nanmax(x)
236 self.xmin = self.xmin if self.xmin else -self.xmax
319 self.xmin = self.xmin if self.xmin else -self.xmax
@@ -462,13 +545,29 class PlotRTIData(PlotData):
462 self.ncols = 1
545 self.ncols = 1
463 self.nrows = self.dataOut.nChannels
546 self.nrows = self.dataOut.nChannels
464 self.width = 10
547 self.width = 10
548 #TODO : arreglar la altura de la figura, esta hardcodeada.
549 #Se arreglo, testear!
550 if self.ind_plt_ch:
551 self.height = 3.2#*self.nrows if self.nrows<6 else 12
552 else:
465 self.height = 2.2*self.nrows if self.nrows<6 else 12
553 self.height = 2.2*self.nrows if self.nrows<6 else 12
554
555 '''
466 if self.nrows==1:
556 if self.nrows==1:
467 self.height += 1
557 self.height += 1
558 '''
468 self.ylabel = 'Range [Km]'
559 self.ylabel = 'Range [Km]'
469 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
560 self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList]
470
561
471 if self.figure is None:
562 '''
563 Logica:
564 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura
565 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el
566 axis dentro de "Figures" como un diccionario.
567 '''
568 if self.ind_plt_ch is False: #standard mode
569
570 if self.figure is None: #solo para la priemra vez
472 self.figure = plt.figure(figsize=(self.width, self.height),
571 self.figure = plt.figure(figsize=(self.width, self.height),
473 edgecolor='k',
572 edgecolor='k',
474 facecolor='w')
573 facecolor='w')
@@ -476,13 +575,40 class PlotRTIData(PlotData):
476 self.figure.clf()
575 self.figure.clf()
477 self.axes = []
576 self.axes = []
478
577
578
479 for n in range(self.nrows):
579 for n in range(self.nrows):
480 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
580 ax = self.figure.add_subplot(self.nrows, self.ncols, n+1)
581 #ax = self.figure(n+1)
481 ax.firsttime = True
582 ax.firsttime = True
482 self.axes.append(ax)
583 self.axes.append(ax)
483
584
585 else : #append one figure foreach channel in channelList
586 if self.figurelist == None:
587 self.figurelist = []
588 for n in range(self.nrows):
589 self.figure = plt.figure(figsize=(self.width, self.height),
590 edgecolor='k',
591 facecolor='w')
592 #add always one subplot
593 self.figurelist.append(self.figure)
594
595 else : # cada dia nuevo limpia el axes, pero mantiene el figure
596 for eachfigure in self.figurelist:
597 eachfigure.clf() # eliminaria todas las figuras de la lista?
598 self.axes = []
599
600 for eachfigure in self.figurelist:
601 ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura
602 #ax = self.figure(n+1)
603 ax.firsttime = True
604 #Cada figura tiene un distinto puntero
605 self.axes.append(ax)
606 #plt.close(eachfigure)
607
608
484 def plot(self):
609 def plot(self):
485
610
611 if self.ind_plt_ch is False: #standard mode
486 self.x = np.array(self.times)
612 self.x = np.array(self.times)
487 self.y = self.dataOut.getHeiRange()
613 self.y = self.dataOut.getHeiRange()
488 self.z = []
614 self.z = []
@@ -510,18 +636,14 class PlotRTIData(PlotData):
510 self.figure.add_axes(cax)
636 self.figure.add_axes(cax)
511 plt.colorbar(plot, cax)
637 plt.colorbar(plot, cax)
512 ax.set_ylim(self.ymin, self.ymax)
638 ax.set_ylim(self.ymin, self.ymax)
513
514 ax.xaxis.set_major_formatter(FuncFormatter(func))
639 ax.xaxis.set_major_formatter(FuncFormatter(func))
515 ax.xaxis.set_major_locator(LinearLocator(6))
640 ax.xaxis.set_major_locator(LinearLocator(6))
516
517 ax.set_ylabel(self.ylabel)
641 ax.set_ylabel(self.ylabel)
518
642 if self.xmin is None:
519 # if self.xmin is None:
643 xmin = self.min_time
520 # xmin = self.min_time
644 else:
521 # else:
645 xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
522 # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
646 datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
523 # datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
524
525 ax.set_xlim(xmin, xmax)
647 ax.set_xlim(xmin, xmax)
526 ax.firsttime = False
648 ax.firsttime = False
527 else:
649 else:
@@ -537,6 +659,63 class PlotRTIData(PlotData):
537 size=8)
659 size=8)
538
660
539 self.saveTime = self.min_time
661 self.saveTime = self.min_time
662 else :
663 self.x = np.array(self.times)
664 self.y = self.dataOut.getHeiRange()
665 self.z = []
666
667 for ch in range(self.nrows):
668 self.z.append([self.data[self.CODE][t][ch] for t in self.times])
669
670 self.z = np.array(self.z)
671 for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes
672
673 x, y, z = self.fill_gaps(*self.decimate())
674 xmin = self.min_time
675 xmax = xmin+self.xrange*60*60
676 self.zmin = self.zmin if self.zmin else np.min(self.z)
677 self.zmax = self.zmax if self.zmax else np.max(self.z)
678 if self.axes[n].firsttime:
679 self.ymin = self.ymin if self.ymin else np.nanmin(self.y)
680 self.ymax = self.ymax if self.ymax else np.nanmax(self.y)
681 plot = self.axes[n].pcolormesh(x, y, z[n].T,
682 vmin=self.zmin,
683 vmax=self.zmax,
684 cmap=plt.get_cmap(self.colormap)
685 )
686 divider = make_axes_locatable(self.axes[n])
687 cax = divider.new_horizontal(size='2%', pad=0.05)
688 eachfigure.add_axes(cax)
689 #self.figure2.add_axes(cax)
690 plt.colorbar(plot, cax)
691 self.axes[n].set_ylim(self.ymin, self.ymax)
692
693 self.axes[n].xaxis.set_major_formatter(FuncFormatter(func))
694 self.axes[n].xaxis.set_major_locator(LinearLocator(6))
695
696 self.axes[n].set_ylabel(self.ylabel)
697
698 if self.xmin is None:
699 xmin = self.min_time
700 else:
701 xmin = (datetime.datetime.combine(self.dataOut.datatime.date(),
702 datetime.time(self.xmin, 0, 0))-d1970).total_seconds()
703
704 self.axes[n].set_xlim(xmin, xmax)
705 self.axes[n].firsttime = False
706 else:
707 self.axes[n].collections.remove(self.axes[n].collections[0])
708 self.axes[n].set_xlim(xmin, xmax)
709 plot = self.axes[n].pcolormesh(x, y, z[n].T,
710 vmin=self.zmin,
711 vmax=self.zmax,
712 cmap=plt.get_cmap(self.colormap)
713 )
714 self.axes[n].set_title('{} {}'.format(self.titles[n],
715 datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')),
716 size=8)
717
718 self.saveTime = self.min_time
540
719
541
720
542 class PlotCOHData(PlotRTIData):
721 class PlotCOHData(PlotRTIData):
@@ -549,6 +728,7 class PlotCOHData(PlotRTIData):
549 self.nrows = self.dataOut.nPairs
728 self.nrows = self.dataOut.nPairs
550 self.width = 10
729 self.width = 10
551 self.height = 2.2*self.nrows if self.nrows<6 else 12
730 self.height = 2.2*self.nrows if self.nrows<6 else 12
731 self.ind_plt_ch = False #just for coherence and phase
552 if self.nrows==1:
732 if self.nrows==1:
553 self.height += 1
733 self.height += 1
554 self.ylabel = 'Range [Km]'
734 self.ylabel = 'Range [Km]'
General Comments 0
You need to be logged in to leave comments. Login now