@@ -69,8 +69,10 def multiSchain(child, nProcess=cpu_count(), startDate=None, endDate=None, by_da | |||
|
69 | 69 | for process in processes: |
|
70 | 70 | process.join() |
|
71 | 71 | process.terminate() |
|
72 | ||
|
72 | 73 | time.sleep(3) |
|
73 | 74 | |
|
75 | ||
|
74 | 76 | class ParameterConf(): |
|
75 | 77 | |
|
76 | 78 | id = None |
@@ -6,6 +6,7 import numpy | |||
|
6 | 6 | import datetime |
|
7 | 7 | import numpy as np |
|
8 | 8 | import matplotlib |
|
9 | import glob | |
|
9 | 10 | matplotlib.use('TkAgg') |
|
10 | 11 | import matplotlib.pyplot as plt |
|
11 | 12 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
@@ -59,6 +60,15 class PlotData(Operation, Process): | |||
|
59 | 60 | self.times = [] |
|
60 | 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 | 73 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
64 | 74 | |
@@ -90,25 +100,98 class PlotData(Operation, Process): | |||
|
90 | 100 | |
|
91 | 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 | 138 | def __plot(self): |
|
94 | 139 | |
|
95 | 140 | print 'plotting...{}'.format(self.CODE) |
|
96 | ||
|
97 | if self.show: | |
|
98 | self.figure.show() | |
|
99 | ||
|
100 | self.plot() | |
|
101 | plt.tight_layout() | |
|
102 | self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(), | |
|
141 | if self.ind_plt_ch is False : #standard | |
|
142 | if self.show: | |
|
143 | self.figure.show() | |
|
144 | self.plot() | |
|
145 | plt.tight_layout() | |
|
146 | self.figure.canvas.manager.set_window_title('{} {} - {}'.format(self.title, self.CODE.upper(), | |
|
103 | 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 | 180 | if self.save: |
|
106 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
|
107 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
108 | print 'Saving figure: {}'.format(figname) | |
|
109 | self.figure.savefig(figname) | |
|
181 | if self.ind_plt_ch is False : #standard | |
|
182 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
|
183 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
|
184 | print 'Saving figure: {}'.format(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 | 196 | def plot(self): |
|
114 | 197 | |
@@ -123,7 +206,7 class PlotData(Operation, Process): | |||
|
123 | 206 | receiver = context.socket(zmq.SUB) |
|
124 | 207 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
125 | 208 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
126 | ||
|
209 | ||
|
127 | 210 | if 'server' in self.kwargs['parent']: |
|
128 | 211 | receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) |
|
129 | 212 | else: |
@@ -157,6 +240,7 class PlotData(Operation, Process): | |||
|
157 | 240 | self.ended = True |
|
158 | 241 | self.isConfig = False |
|
159 | 242 | self.__plot() |
|
243 | self.deleteanotherfiles() #CLPDG | |
|
160 | 244 | elif seconds_passed >= self.data['throttle']: |
|
161 | 245 | print 'passed', seconds_passed |
|
162 | 246 | self.__plot() |
@@ -230,7 +314,6 class PlotSpectraData(PlotData): | |||
|
230 | 314 | z = self.data[self.CODE] |
|
231 | 315 | |
|
232 | 316 | for n, ax in enumerate(self.axes): |
|
233 | ||
|
234 | 317 | if ax.firsttime: |
|
235 | 318 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
236 | 319 | self.xmin = self.xmin if self.xmin else -self.xmax |
@@ -462,81 +545,177 class PlotRTIData(PlotData): | |||
|
462 | 545 | self.ncols = 1 |
|
463 | 546 | self.nrows = self.dataOut.nChannels |
|
464 | 547 | self.width = 10 |
|
465 | self.height = 2.2*self.nrows if self.nrows<6 else 12 | |
|
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: | |
|
553 | self.height = 2.2*self.nrows if self.nrows<6 else 12 | |
|
554 | ||
|
555 | ''' | |
|
466 | 556 | if self.nrows==1: |
|
467 | 557 | self.height += 1 |
|
558 | ''' | |
|
468 | 559 | self.ylabel = 'Range [Km]' |
|
469 | 560 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
470 | 561 | |
|
471 | if self.figure is None: | |
|
472 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
473 | edgecolor='k', | |
|
474 | facecolor='w') | |
|
475 | else: | |
|
476 | self.figure.clf() | |
|
477 | self.axes = [] | |
|
478 | ||
|
479 | for n in range(self.nrows): | |
|
480 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
|
481 | ax.firsttime = True | |
|
482 | self.axes.append(ax) | |
|
483 | ||
|
484 | def plot(self): | |
|
485 | ||
|
486 | self.x = np.array(self.times) | |
|
487 | self.y = self.dataOut.getHeiRange() | |
|
488 | self.z = [] | |
|
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 | |
|
571 | self.figure = plt.figure(figsize=(self.width, self.height), | |
|
572 | edgecolor='k', | |
|
573 | facecolor='w') | |
|
574 | else: | |
|
575 | self.figure.clf() | |
|
576 | self.axes = [] | |
|
489 | 577 | |
|
490 | for ch in range(self.nrows): | |
|
491 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
|
492 | 578 | |
|
493 | self.z = np.array(self.z) | |
|
494 | for n, ax in enumerate(self.axes): | |
|
495 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
496 | xmin = self.min_time | |
|
497 | xmax = xmin+self.xrange*60*60 | |
|
498 | self.zmin = self.zmin if self.zmin else np.min(self.z) | |
|
499 | self.zmax = self.zmax if self.zmax else np.max(self.z) | |
|
500 | if ax.firsttime: | |
|
501 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
|
502 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
|
503 | plot = ax.pcolormesh(x, y, z[n].T, | |
|
504 | vmin=self.zmin, | |
|
505 | vmax=self.zmax, | |
|
506 | cmap=plt.get_cmap(self.colormap) | |
|
507 | ) | |
|
508 | divider = make_axes_locatable(ax) | |
|
509 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
|
510 | self.figure.add_axes(cax) | |
|
511 | plt.colorbar(plot, cax) | |
|
512 | ax.set_ylim(self.ymin, self.ymax) | |
|
513 | ||
|
514 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
|
515 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
|
579 | for n in range(self.nrows): | |
|
580 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
|
581 | #ax = self.figure(n+1) | |
|
582 | ax.firsttime = True | |
|
583 | self.axes.append(ax) | |
|
516 | 584 | |
|
517 | ax.set_ylabel(self.ylabel) | |
|
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) | |
|
518 | 607 | |
|
519 | # if self.xmin is None: | |
|
520 | # xmin = self.min_time | |
|
521 | # else: | |
|
522 | # xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |
|
523 | # datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |
|
524 | 608 | |
|
525 | ax.set_xlim(xmin, xmax) | |
|
526 | ax.firsttime = False | |
|
527 | else: | |
|
528 | ax.collections.remove(ax.collections[0]) | |
|
529 | ax.set_xlim(xmin, xmax) | |
|
530 | plot = ax.pcolormesh(x, y, z[n].T, | |
|
531 | vmin=self.zmin, | |
|
532 | vmax=self.zmax, | |
|
533 | cmap=plt.get_cmap(self.colormap) | |
|
534 | ) | |
|
535 | ax.set_title('{} {}'.format(self.titles[n], | |
|
536 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
|
537 | size=8) | |
|
609 | def plot(self): | |
|
538 | 610 | |
|
539 | self.saveTime = self.min_time | |
|
611 | if self.ind_plt_ch is False: #standard mode | |
|
612 | self.x = np.array(self.times) | |
|
613 | self.y = self.dataOut.getHeiRange() | |
|
614 | self.z = [] | |
|
615 | ||
|
616 | for ch in range(self.nrows): | |
|
617 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
|
618 | ||
|
619 | self.z = np.array(self.z) | |
|
620 | for n, ax in enumerate(self.axes): | |
|
621 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
622 | xmin = self.min_time | |
|
623 | xmax = xmin+self.xrange*60*60 | |
|
624 | self.zmin = self.zmin if self.zmin else np.min(self.z) | |
|
625 | self.zmax = self.zmax if self.zmax else np.max(self.z) | |
|
626 | if ax.firsttime: | |
|
627 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
|
628 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
|
629 | plot = ax.pcolormesh(x, y, z[n].T, | |
|
630 | vmin=self.zmin, | |
|
631 | vmax=self.zmax, | |
|
632 | cmap=plt.get_cmap(self.colormap) | |
|
633 | ) | |
|
634 | divider = make_axes_locatable(ax) | |
|
635 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
|
636 | self.figure.add_axes(cax) | |
|
637 | plt.colorbar(plot, cax) | |
|
638 | ax.set_ylim(self.ymin, self.ymax) | |
|
639 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
|
640 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
|
641 | ax.set_ylabel(self.ylabel) | |
|
642 | if self.xmin is None: | |
|
643 | xmin = self.min_time | |
|
644 | else: | |
|
645 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |
|
646 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |
|
647 | ax.set_xlim(xmin, xmax) | |
|
648 | ax.firsttime = False | |
|
649 | else: | |
|
650 | ax.collections.remove(ax.collections[0]) | |
|
651 | ax.set_xlim(xmin, xmax) | |
|
652 | plot = ax.pcolormesh(x, y, z[n].T, | |
|
653 | vmin=self.zmin, | |
|
654 | vmax=self.zmax, | |
|
655 | cmap=plt.get_cmap(self.colormap) | |
|
656 | ) | |
|
657 | ax.set_title('{} {}'.format(self.titles[n], | |
|
658 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
|
659 | size=8) | |
|
660 | ||
|
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 | 721 | class PlotCOHData(PlotRTIData): |
@@ -549,6 +728,7 class PlotCOHData(PlotRTIData): | |||
|
549 | 728 | self.nrows = self.dataOut.nPairs |
|
550 | 729 | self.width = 10 |
|
551 | 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 | 732 | if self.nrows==1: |
|
553 | 733 | self.height += 1 |
|
554 | 734 | self.ylabel = 'Range [Km]' |
General Comments 0
You need to be logged in to leave comments.
Login now