@@ -1,958 +1,955 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
3 | import zmq |
|
3 | import zmq | |
4 | import time |
|
4 | import time | |
5 | import numpy |
|
5 | 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 | import glob | |
10 | matplotlib.use('TkAgg') |
|
10 | matplotlib.use('TkAgg') | |
11 | import matplotlib.pyplot as plt |
|
11 | import matplotlib.pyplot as plt | |
12 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
12 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
13 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
13 | from matplotlib.ticker import FuncFormatter, LinearLocator | |
14 | from multiprocessing import Process |
|
14 | from multiprocessing import Process | |
15 |
|
15 | |||
16 | from schainpy.model.proc.jroproc_base import Operation |
|
16 | from schainpy.model.proc.jroproc_base import Operation | |
17 |
|
17 | |||
18 | plt.ion() |
|
18 | plt.ion() | |
19 |
|
19 | |||
20 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) |
|
20 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime('%H:%M')) | |
21 |
|
21 | |||
22 | d1970 = datetime.datetime(1970,1,1) |
|
22 | d1970 = datetime.datetime(1970,1,1) | |
23 |
|
23 | |||
24 | class PlotData(Operation, Process): |
|
24 | class PlotData(Operation, Process): | |
25 |
|
25 | |||
26 | CODE = 'Figure' |
|
26 | CODE = 'Figure' | |
27 | colormap = 'jro' |
|
27 | colormap = 'jro' | |
28 | CONFLATE = False |
|
28 | CONFLATE = False | |
29 | __MAXNUMX = 80 |
|
29 | __MAXNUMX = 80 | |
30 | __missing = 1E30 |
|
30 | __missing = 1E30 | |
31 |
|
31 | |||
32 | def __init__(self, **kwargs): |
|
32 | def __init__(self, **kwargs): | |
33 |
|
33 | |||
34 | Operation.__init__(self, plot=True, **kwargs) |
|
34 | Operation.__init__(self, plot=True, **kwargs) | |
35 | Process.__init__(self) |
|
35 | Process.__init__(self) | |
36 | self.kwargs['code'] = self.CODE |
|
36 | self.kwargs['code'] = self.CODE | |
37 | self.mp = False |
|
37 | self.mp = False | |
38 | self.dataOut = None |
|
38 | self.dataOut = None | |
39 | self.isConfig = False |
|
39 | self.isConfig = False | |
40 | self.figure = None |
|
40 | self.figure = None | |
41 | self.axes = [] |
|
41 | self.axes = [] | |
42 | self.localtime = kwargs.pop('localtime', True) |
|
42 | self.localtime = kwargs.pop('localtime', True) | |
43 | self.show = kwargs.get('show', True) |
|
43 | self.show = kwargs.get('show', True) | |
44 | self.save = kwargs.get('save', False) |
|
44 | self.save = kwargs.get('save', False) | |
45 | self.colormap = kwargs.get('colormap', self.colormap) |
|
45 | self.colormap = kwargs.get('colormap', self.colormap) | |
46 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
46 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
47 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
47 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
48 | self.showprofile = kwargs.get('showprofile', True) |
|
48 | self.showprofile = kwargs.get('showprofile', True) | |
49 | self.title = kwargs.get('wintitle', '') |
|
49 | self.title = kwargs.get('wintitle', '') | |
50 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
50 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
51 | self.zmin = kwargs.get('zmin', None) |
|
51 | self.zmin = kwargs.get('zmin', None) | |
52 | self.zmax = kwargs.get('zmax', None) |
|
52 | self.zmax = kwargs.get('zmax', None) | |
53 | self.xmin = kwargs.get('xmin', None) |
|
53 | self.xmin = kwargs.get('xmin', None) | |
54 | self.xmax = kwargs.get('xmax', None) |
|
54 | self.xmax = kwargs.get('xmax', None) | |
55 | self.xrange = kwargs.get('xrange', 24) |
|
55 | self.xrange = kwargs.get('xrange', 24) | |
56 | self.ymin = kwargs.get('ymin', None) |
|
56 | self.ymin = kwargs.get('ymin', None) | |
57 | self.ymax = kwargs.get('ymax', None) |
|
57 | self.ymax = kwargs.get('ymax', None) | |
58 | self.__MAXNUMY = kwargs.get('decimation', 80) |
|
58 | self.__MAXNUMY = kwargs.get('decimation', 80) | |
59 | self.throttle_value = 5 |
|
59 | self.throttle_value = 5 | |
60 | self.times = [] |
|
60 | self.times = [] | |
61 | #self.interactive = self.kwargs['parent'] |
|
61 | #self.interactive = self.kwargs['parent'] | |
62 |
|
62 | |||
63 | ''' |
|
63 | ''' | |
64 | this new parameter is created to plot data from varius channels at different figures |
|
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, |
|
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 |
|
66 | 2. dar las opciones de configuracion a cada figura, estas opciones son iguales para ambas figuras | |
67 | 3. probar? |
|
67 | 3. probar? | |
68 | ''' |
|
68 | ''' | |
69 | self.ind_plt_ch = kwargs.get('ind_plt_ch', False) |
|
69 | self.ind_plt_ch = kwargs.get('ind_plt_ch', False) | |
70 | self.figurelist = None |
|
70 | self.figurelist = None | |
71 |
|
71 | |||
72 |
|
72 | |||
73 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
73 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
74 |
|
74 | |||
75 | if x_buffer.shape[0] < 2: |
|
75 | if x_buffer.shape[0] < 2: | |
76 | return x_buffer, y_buffer, z_buffer |
|
76 | return x_buffer, y_buffer, z_buffer | |
77 |
|
77 | |||
78 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
78 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
79 | x_median = np.median(deltas) |
|
79 | x_median = np.median(deltas) | |
80 |
|
80 | |||
81 | index = np.where(deltas > 5*x_median) |
|
81 | index = np.where(deltas > 5*x_median) | |
82 |
|
82 | |||
83 | if len(index[0]) != 0: |
|
83 | if len(index[0]) != 0: | |
84 | z_buffer[::, index[0], ::] = self.__missing |
|
84 | z_buffer[::, index[0], ::] = self.__missing | |
85 | z_buffer = np.ma.masked_inside(z_buffer, |
|
85 | z_buffer = np.ma.masked_inside(z_buffer, | |
86 | 0.99*self.__missing, |
|
86 | 0.99*self.__missing, | |
87 | 1.01*self.__missing) |
|
87 | 1.01*self.__missing) | |
88 |
|
88 | |||
89 | return x_buffer, y_buffer, z_buffer |
|
89 | return x_buffer, y_buffer, z_buffer | |
90 |
|
90 | |||
91 | def decimate(self): |
|
91 | def decimate(self): | |
92 |
|
92 | |||
93 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
93 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
94 | dy = int(len(self.y)/self.__MAXNUMY) + 1 |
|
94 | dy = int(len(self.y)/self.__MAXNUMY) + 1 | |
95 |
|
95 | |||
96 | # x = self.x[::dx] |
|
96 | # x = self.x[::dx] | |
97 | x = self.x |
|
97 | x = self.x | |
98 | y = self.y[::dy] |
|
98 | y = self.y[::dy] | |
99 | z = self.z[::, ::, ::dy] |
|
99 | z = self.z[::, ::, ::dy] | |
100 |
|
100 | |||
101 | return x, y, z |
|
101 | return x, y, z | |
102 |
|
102 | |||
103 | ''' |
|
103 | ''' | |
104 | JM: |
|
104 | JM: | |
105 | elimana las otras imagenes generadas debido a que lso workers no llegan en orden y le pueden |
|
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. |
|
106 | poner otro tiempo a la figura q no necesariamente es el ultimo. | |
107 | Solo se realiza cuando termina la imagen. |
|
107 | Solo se realiza cuando termina la imagen. | |
108 | Problemas: |
|
108 | Problemas: | |
109 |
|
109 | |||
110 | File "/home/ci-81/workspace/schainv2.3/schainpy/model/graphics/jroplot_data.py", line 145, in __plot |
|
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): |
|
111 | for n, eachfigure in enumerate(self.figurelist): | |
112 | TypeError: 'NoneType' object is not iterable |
|
112 | TypeError: 'NoneType' object is not iterable | |
113 |
|
113 | |||
114 | ''' |
|
114 | ''' | |
115 | def deleteanotherfiles(self): |
|
115 | def deleteanotherfiles(self): | |
116 | figurenames=[] |
|
116 | figurenames=[] | |
117 | if self.figurelist != None: |
|
117 | if self.figurelist != None: | |
118 | for n, eachfigure in enumerate(self.figurelist): |
|
118 | for n, eachfigure in enumerate(self.figurelist): | |
119 | #add specific name for each channel in channelList |
|
119 | #add specific name for each channel in channelList | |
120 | ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE, |
|
120 | ghostfigname = os.path.join(self.save, '{}_{}_{}'.format(self.titles[n].replace(' ',''),self.CODE, | |
121 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d'))) |
|
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, |
|
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'))) |
|
123 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
124 |
|
124 | |||
125 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures |
|
125 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures | |
126 | if ghostfigure != figname: |
|
126 | if ghostfigure != figname: | |
127 | os.remove(ghostfigure) |
|
127 | os.remove(ghostfigure) | |
128 | print 'Removing GhostFigures:' , figname |
|
128 | print 'Removing GhostFigures:' , figname | |
129 | else : |
|
129 | else : | |
130 | '''Erasing ghost images for just on******************''' |
|
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'))) |
|
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'))) |
|
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 |
|
133 | for ghostfigure in glob.glob(ghostfigname+'*'): #ghostfigure will adopt all posible names of figures | |
134 | if ghostfigure != figname: |
|
134 | if ghostfigure != figname: | |
135 | os.remove(ghostfigure) |
|
135 | os.remove(ghostfigure) | |
136 | print 'Removing GhostFigures:' , figname |
|
136 | print 'Removing GhostFigures:' , figname | |
137 |
|
137 | |||
138 | def __plot(self): |
|
138 | def __plot(self): | |
139 |
|
139 | |||
140 | print 'plotting...{}'.format(self.CODE) |
|
140 | print 'plotting...{}'.format(self.CODE) | |
141 | if self.ind_plt_ch is False : #standard |
|
141 | if self.ind_plt_ch is False : #standard | |
142 | if self.show: |
|
142 | if self.show: | |
143 | self.figure.show() |
|
143 | self.figure.show() | |
144 | self.plot() |
|
144 | self.plot() | |
145 | plt.tight_layout() |
|
145 | plt.tight_layout() | |
146 | 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(), | |
147 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) |
|
147 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) | |
148 | else : |
|
148 | else : | |
149 | print 'len(self.figurelist): ',len(self.figurelist) |
|
149 | print 'len(self.figurelist): ',len(self.figurelist) | |
150 | for n, eachfigure in enumerate(self.figurelist): |
|
150 | for n, eachfigure in enumerate(self.figurelist): | |
151 | if self.show: |
|
151 | if self.show: | |
152 | eachfigure.show() |
|
152 | eachfigure.show() | |
153 |
|
153 | |||
154 |
self.plot() |
|
154 | self.plot() | |
155 | #eachfigure.subplots_adjust(left=0.2) |
|
|||
156 | #eachfigure.subplots_adjuccst(right=0.2) |
|
|||
157 | eachfigure.tight_layout() # ajuste de cada subplot |
|
155 | eachfigure.tight_layout() # ajuste de cada subplot | |
158 | eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(), |
|
156 | eachfigure.canvas.manager.set_window_title('{} {} - {}'.format(self.title[n], self.CODE.upper(), | |
159 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) |
|
157 | datetime.datetime.fromtimestamp(self.max_time).strftime('%Y/%m/%d'))) | |
160 |
|
158 | |||
161 | # if self.save: |
|
159 | # if self.save: | |
162 | # if self.ind_plt_ch is False : #standard |
|
160 | # if self.ind_plt_ch is False : #standard | |
163 | # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
161 | # figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
164 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
162 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
165 | # print 'Saving figure: {}'.format(figname) |
|
163 | # print 'Saving figure: {}'.format(figname) | |
166 | # self.figure.savefig(figname) |
|
164 | # self.figure.savefig(figname) | |
167 | # else : |
|
165 | # else : | |
168 | # for n, eachfigure in enumerate(self.figurelist): |
|
166 | # for n, eachfigure in enumerate(self.figurelist): | |
169 | # #add specific name for each channel in channelList |
|
167 | # #add specific name for each channel in channelList | |
170 | # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE, |
|
168 | # figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n],self.CODE, | |
171 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
169 | # datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
172 | # |
|
170 | # | |
173 | # print 'Saving figure: {}'.format(figname) |
|
171 | # print 'Saving figure: {}'.format(figname) | |
174 | # eachfigure.savefig(figname) |
|
172 | # eachfigure.savefig(figname) | |
175 |
|
173 | |||
176 | if self.ind_plt_ch is False : |
|
174 | if self.ind_plt_ch is False : | |
177 | self.figure.canvas.draw() |
|
175 | self.figure.canvas.draw() | |
178 | else : |
|
176 | else : | |
179 | for eachfigure in self.figurelist: |
|
177 | for eachfigure in self.figurelist: | |
180 | eachfigure.canvas.draw() |
|
178 | eachfigure.canvas.draw() | |
181 |
|
179 | |||
182 | if self.save: |
|
180 | if self.save: | |
183 | if self.ind_plt_ch is False : #standard |
|
181 | if self.ind_plt_ch is False : #standard | |
184 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, |
|
182 | figname = os.path.join(self.save, '{}_{}.png'.format(self.CODE, | |
185 | 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'))) | |
186 | print 'Saving figure: {}'.format(figname) |
|
184 | print 'Saving figure: {}'.format(figname) | |
187 | self.figure.savefig(figname) |
|
185 | self.figure.savefig(figname) | |
188 | else : |
|
186 | else : | |
189 | for n, eachfigure in enumerate(self.figurelist): |
|
187 | for n, eachfigure in enumerate(self.figurelist): | |
190 | #add specific name for each channel in channelList |
|
188 | #add specific name for each channel in channelList | |
191 | figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE, |
|
189 | figname = os.path.join(self.save, '{}_{}_{}.png'.format(self.titles[n].replace(' ',''),self.CODE, | |
192 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) |
|
190 | datetime.datetime.fromtimestamp(self.saveTime).strftime('%y%m%d_%H%M%S'))) | |
193 |
|
191 | |||
194 | print 'Saving figure: {}'.format(figname) |
|
192 | print 'Saving figure: {}'.format(figname) | |
195 | eachfigure.savefig(figname) |
|
193 | eachfigure.savefig(figname) | |
196 |
|
194 | |||
197 |
|
195 | |||
198 | def plot(self): |
|
196 | def plot(self): | |
199 |
|
197 | |||
200 | print 'plotting...{}'.format(self.CODE.upper()) |
|
198 | print 'plotting...{}'.format(self.CODE.upper()) | |
201 | return |
|
199 | return | |
202 |
|
200 | |||
203 | def run(self): |
|
201 | def run(self): | |
204 |
|
202 | |||
205 | print '[Starting] {}'.format(self.name) |
|
203 | print '[Starting] {}'.format(self.name) | |
206 |
|
204 | |||
207 | context = zmq.Context() |
|
205 | context = zmq.Context() | |
208 | receiver = context.socket(zmq.SUB) |
|
206 | receiver = context.socket(zmq.SUB) | |
209 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
207 | receiver.setsockopt(zmq.SUBSCRIBE, '') | |
210 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
208 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) | |
211 |
|
209 | |||
212 | if 'server' in self.kwargs['parent']: |
|
210 | if 'server' in self.kwargs['parent']: | |
213 | receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) |
|
211 | receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |
214 | else: |
|
212 | else: | |
215 | receiver.connect("ipc:///tmp/zmq.plots") |
|
213 | receiver.connect("ipc:///tmp/zmq.plots") | |
216 |
|
214 | |||
217 | seconds_passed = 0 |
|
215 | seconds_passed = 0 | |
218 |
|
216 | |||
219 | while True: |
|
217 | while True: | |
220 | try: |
|
218 | try: | |
221 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK |
|
219 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK)#flags=zmq.NOBLOCK | |
222 | self.started = self.data['STARTED'] |
|
220 | self.started = self.data['STARTED'] | |
223 | self.dataOut = self.data['dataOut'] |
|
221 | self.dataOut = self.data['dataOut'] | |
224 |
|
222 | |||
225 | if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']): |
|
223 | if (len(self.times) < len(self.data['times']) and not self.started and self.data['ENDED']): | |
226 | continue |
|
224 | continue | |
227 |
|
225 | |||
228 | self.times = self.data['times'] |
|
226 | self.times = self.data['times'] | |
229 | self.times.sort() |
|
227 | self.times.sort() | |
230 | self.throttle_value = self.data['throttle'] |
|
228 | self.throttle_value = self.data['throttle'] | |
231 | self.min_time = self.times[0] |
|
229 | self.min_time = self.times[0] | |
232 | self.max_time = self.times[-1] |
|
230 | self.max_time = self.times[-1] | |
233 |
|
231 | |||
234 | if self.isConfig is False: |
|
232 | if self.isConfig is False: | |
235 | print 'setting up' |
|
233 | print 'setting up' | |
236 | self.setup() |
|
234 | self.setup() | |
237 | self.isConfig = True |
|
235 | self.isConfig = True | |
238 | self.__plot() |
|
236 | self.__plot() | |
239 |
|
237 | |||
240 | if self.data['ENDED'] is True: |
|
238 | if self.data['ENDED'] is True: | |
241 | print '********GRAPHIC ENDED********' |
|
239 | print '********GRAPHIC ENDED********' | |
242 | self.ended = True |
|
240 | self.ended = True | |
243 | self.isConfig = False |
|
241 | self.isConfig = False | |
244 | self.__plot() |
|
242 | self.__plot() | |
245 | #TODO : AUN NO FUNCIONA PARA COHERENCIA. |
|
|||
246 | self.deleteanotherfiles() #CLPDG |
|
243 | self.deleteanotherfiles() #CLPDG | |
247 | elif seconds_passed >= self.data['throttle']: |
|
244 | elif seconds_passed >= self.data['throttle']: | |
248 | print 'passed', seconds_passed |
|
245 | print 'passed', seconds_passed | |
249 | self.__plot() |
|
246 | self.__plot() | |
250 | seconds_passed = 0 |
|
247 | seconds_passed = 0 | |
251 |
|
248 | |||
252 | except zmq.Again as e: |
|
249 | except zmq.Again as e: | |
253 | print 'Waiting for data...' |
|
250 | print 'Waiting for data...' | |
254 | plt.pause(2) |
|
251 | plt.pause(2) | |
255 | seconds_passed += 2 |
|
252 | seconds_passed += 2 | |
256 |
|
253 | |||
257 | def close(self): |
|
254 | def close(self): | |
258 | if self.dataOut: |
|
255 | if self.dataOut: | |
259 | self.__plot() |
|
256 | self.__plot() | |
260 |
|
257 | |||
261 |
|
258 | |||
262 | class PlotSpectraData(PlotData): |
|
259 | class PlotSpectraData(PlotData): | |
263 |
|
260 | |||
264 | CODE = 'spc' |
|
261 | CODE = 'spc' | |
265 | colormap = 'jro' |
|
262 | colormap = 'jro' | |
266 | CONFLATE = False |
|
263 | CONFLATE = False | |
267 |
|
264 | |||
268 | def setup(self): |
|
265 | def setup(self): | |
269 |
|
266 | |||
270 | ncolspan = 1 |
|
267 | ncolspan = 1 | |
271 | colspan = 1 |
|
268 | colspan = 1 | |
272 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) |
|
269 | self.ncols = int(numpy.sqrt(self.dataOut.nChannels)+0.9) | |
273 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) |
|
270 | self.nrows = int(self.dataOut.nChannels*1./self.ncols + 0.9) | |
274 | self.width = 3.6*self.ncols |
|
271 | self.width = 3.6*self.ncols | |
275 | self.height = 3.2*self.nrows |
|
272 | self.height = 3.2*self.nrows | |
276 | if self.showprofile: |
|
273 | if self.showprofile: | |
277 | ncolspan = 3 |
|
274 | ncolspan = 3 | |
278 | colspan = 2 |
|
275 | colspan = 2 | |
279 | self.width += 1.2*self.ncols |
|
276 | self.width += 1.2*self.ncols | |
280 |
|
277 | |||
281 | self.ylabel = 'Range [Km]' |
|
278 | self.ylabel = 'Range [Km]' | |
282 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
279 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
283 |
|
280 | |||
284 | if self.figure is None: |
|
281 | if self.figure is None: | |
285 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
282 | self.figure = plt.figure(figsize=(self.width, self.height), | |
286 | edgecolor='k', |
|
283 | edgecolor='k', | |
287 | facecolor='w') |
|
284 | facecolor='w') | |
288 | else: |
|
285 | else: | |
289 | self.figure.clf() |
|
286 | self.figure.clf() | |
290 |
|
287 | |||
291 | n = 0 |
|
288 | n = 0 | |
292 | for y in range(self.nrows): |
|
289 | for y in range(self.nrows): | |
293 | for x in range(self.ncols): |
|
290 | for x in range(self.ncols): | |
294 | if n >= self.dataOut.nChannels: |
|
291 | if n >= self.dataOut.nChannels: | |
295 | break |
|
292 | break | |
296 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) |
|
293 | ax = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan), 1, colspan) | |
297 | if self.showprofile: |
|
294 | if self.showprofile: | |
298 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) |
|
295 | ax.ax_profile = plt.subplot2grid((self.nrows, self.ncols*ncolspan), (y, x*ncolspan+colspan), 1, 1) | |
299 |
|
296 | |||
300 | ax.firsttime = True |
|
297 | ax.firsttime = True | |
301 | self.axes.append(ax) |
|
298 | self.axes.append(ax) | |
302 | n += 1 |
|
299 | n += 1 | |
303 |
|
300 | |||
304 | def plot(self): |
|
301 | def plot(self): | |
305 |
|
302 | |||
306 | if self.xaxis == "frequency": |
|
303 | if self.xaxis == "frequency": | |
307 | x = self.dataOut.getFreqRange(1)/1000. |
|
304 | x = self.dataOut.getFreqRange(1)/1000. | |
308 | xlabel = "Frequency (kHz)" |
|
305 | xlabel = "Frequency (kHz)" | |
309 | elif self.xaxis == "time": |
|
306 | elif self.xaxis == "time": | |
310 | x = self.dataOut.getAcfRange(1) |
|
307 | x = self.dataOut.getAcfRange(1) | |
311 | xlabel = "Time (ms)" |
|
308 | xlabel = "Time (ms)" | |
312 | else: |
|
309 | else: | |
313 | x = self.dataOut.getVelRange(1) |
|
310 | x = self.dataOut.getVelRange(1) | |
314 | xlabel = "Velocity (m/s)" |
|
311 | xlabel = "Velocity (m/s)" | |
315 |
|
312 | |||
316 | y = self.dataOut.getHeiRange() |
|
313 | y = self.dataOut.getHeiRange() | |
317 | z = self.data[self.CODE] |
|
314 | z = self.data[self.CODE] | |
318 |
|
315 | |||
319 | for n, ax in enumerate(self.axes): |
|
316 | for n, ax in enumerate(self.axes): | |
320 | if ax.firsttime: |
|
317 | if ax.firsttime: | |
321 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
318 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
322 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
319 | self.xmin = self.xmin if self.xmin else -self.xmax | |
323 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
320 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
324 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
321 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
325 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
322 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |
326 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
323 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |
327 | ax.plot = ax.pcolormesh(x, y, z[n].T, |
|
324 | ax.plot = ax.pcolormesh(x, y, z[n].T, | |
328 | vmin=self.zmin, |
|
325 | vmin=self.zmin, | |
329 | vmax=self.zmax, |
|
326 | vmax=self.zmax, | |
330 | cmap=plt.get_cmap(self.colormap) |
|
327 | cmap=plt.get_cmap(self.colormap) | |
331 | ) |
|
328 | ) | |
332 | divider = make_axes_locatable(ax) |
|
329 | divider = make_axes_locatable(ax) | |
333 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
330 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
334 | self.figure.add_axes(cax) |
|
331 | self.figure.add_axes(cax) | |
335 | plt.colorbar(ax.plot, cax) |
|
332 | plt.colorbar(ax.plot, cax) | |
336 |
|
333 | |||
337 | ax.set_xlim(self.xmin, self.xmax) |
|
334 | ax.set_xlim(self.xmin, self.xmax) | |
338 | ax.set_ylim(self.ymin, self.ymax) |
|
335 | ax.set_ylim(self.ymin, self.ymax) | |
339 |
|
336 | |||
340 | ax.set_ylabel(self.ylabel) |
|
337 | ax.set_ylabel(self.ylabel) | |
341 | ax.set_xlabel(xlabel) |
|
338 | ax.set_xlabel(xlabel) | |
342 |
|
339 | |||
343 | ax.firsttime = False |
|
340 | ax.firsttime = False | |
344 |
|
341 | |||
345 | if self.showprofile: |
|
342 | if self.showprofile: | |
346 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
343 | ax.plot_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] | |
347 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
344 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |
348 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
345 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |
349 | ax.ax_profile.set_xlabel('dB') |
|
346 | ax.ax_profile.set_xlabel('dB') | |
350 | ax.ax_profile.grid(b=True, axis='x') |
|
347 | ax.ax_profile.grid(b=True, axis='x') | |
351 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
348 | ax.plot_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, | |
352 | color="k", linestyle="dashed", lw=2)[0] |
|
349 | color="k", linestyle="dashed", lw=2)[0] | |
353 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
350 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |
354 | else: |
|
351 | else: | |
355 | ax.plot.set_array(z[n].T.ravel()) |
|
352 | ax.plot.set_array(z[n].T.ravel()) | |
356 | if self.showprofile: |
|
353 | if self.showprofile: | |
357 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
354 | ax.plot_profile.set_data(self.data['rti'][self.max_time][n], y) | |
358 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
355 | ax.plot_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) | |
359 |
|
356 | |||
360 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
357 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), | |
361 | size=8) |
|
358 | size=8) | |
362 | self.saveTime = self.max_time |
|
359 | self.saveTime = self.max_time | |
363 |
|
360 | |||
364 |
|
361 | |||
365 | class PlotCrossSpectraData(PlotData): |
|
362 | class PlotCrossSpectraData(PlotData): | |
366 |
|
363 | |||
367 | CODE = 'cspc' |
|
364 | CODE = 'cspc' | |
368 | zmin_coh = None |
|
365 | zmin_coh = None | |
369 | zmax_coh = None |
|
366 | zmax_coh = None | |
370 | zmin_phase = None |
|
367 | zmin_phase = None | |
371 | zmax_phase = None |
|
368 | zmax_phase = None | |
372 | CONFLATE = False |
|
369 | CONFLATE = False | |
373 |
|
370 | |||
374 | def setup(self): |
|
371 | def setup(self): | |
375 |
|
372 | |||
376 | ncolspan = 1 |
|
373 | ncolspan = 1 | |
377 | colspan = 1 |
|
374 | colspan = 1 | |
378 | self.ncols = 2 |
|
375 | self.ncols = 2 | |
379 | self.nrows = self.dataOut.nPairs |
|
376 | self.nrows = self.dataOut.nPairs | |
380 | self.width = 3.6*self.ncols |
|
377 | self.width = 3.6*self.ncols | |
381 | self.height = 3.2*self.nrows |
|
378 | self.height = 3.2*self.nrows | |
382 |
|
379 | |||
383 | self.ylabel = 'Range [Km]' |
|
380 | self.ylabel = 'Range [Km]' | |
384 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
381 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
385 |
|
382 | |||
386 | if self.figure is None: |
|
383 | if self.figure is None: | |
387 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
384 | self.figure = plt.figure(figsize=(self.width, self.height), | |
388 | edgecolor='k', |
|
385 | edgecolor='k', | |
389 | facecolor='w') |
|
386 | facecolor='w') | |
390 | else: |
|
387 | else: | |
391 | self.figure.clf() |
|
388 | self.figure.clf() | |
392 |
|
389 | |||
393 | for y in range(self.nrows): |
|
390 | for y in range(self.nrows): | |
394 | for x in range(self.ncols): |
|
391 | for x in range(self.ncols): | |
395 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) |
|
392 | ax = plt.subplot2grid((self.nrows, self.ncols), (y, x), 1, 1) | |
396 | ax.firsttime = True |
|
393 | ax.firsttime = True | |
397 | self.axes.append(ax) |
|
394 | self.axes.append(ax) | |
398 |
|
395 | |||
399 | def plot(self): |
|
396 | def plot(self): | |
400 |
|
397 | |||
401 | if self.xaxis == "frequency": |
|
398 | if self.xaxis == "frequency": | |
402 | x = self.dataOut.getFreqRange(1)/1000. |
|
399 | x = self.dataOut.getFreqRange(1)/1000. | |
403 | xlabel = "Frequency (kHz)" |
|
400 | xlabel = "Frequency (kHz)" | |
404 | elif self.xaxis == "time": |
|
401 | elif self.xaxis == "time": | |
405 | x = self.dataOut.getAcfRange(1) |
|
402 | x = self.dataOut.getAcfRange(1) | |
406 | xlabel = "Time (ms)" |
|
403 | xlabel = "Time (ms)" | |
407 | else: |
|
404 | else: | |
408 | x = self.dataOut.getVelRange(1) |
|
405 | x = self.dataOut.getVelRange(1) | |
409 | xlabel = "Velocity (m/s)" |
|
406 | xlabel = "Velocity (m/s)" | |
410 |
|
407 | |||
411 | y = self.dataOut.getHeiRange() |
|
408 | y = self.dataOut.getHeiRange() | |
412 | z_coh = self.data['cspc_coh'] |
|
409 | z_coh = self.data['cspc_coh'] | |
413 | z_phase = self.data['cspc_phase'] |
|
410 | z_phase = self.data['cspc_phase'] | |
414 |
|
411 | |||
415 | for n in range(self.nrows): |
|
412 | for n in range(self.nrows): | |
416 | ax = self.axes[2*n] |
|
413 | ax = self.axes[2*n] | |
417 | ax1 = self.axes[2*n+1] |
|
414 | ax1 = self.axes[2*n+1] | |
418 | if ax.firsttime: |
|
415 | if ax.firsttime: | |
419 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
416 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
420 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
417 | self.xmin = self.xmin if self.xmin else -self.xmax | |
421 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
418 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
422 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
419 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
423 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 |
|
420 | self.zmin_coh = self.zmin_coh if self.zmin_coh else 0.0 | |
424 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 |
|
421 | self.zmax_coh = self.zmax_coh if self.zmax_coh else 1.0 | |
425 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 |
|
422 | self.zmin_phase = self.zmin_phase if self.zmin_phase else -180 | |
426 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 |
|
423 | self.zmax_phase = self.zmax_phase if self.zmax_phase else 180 | |
427 |
|
424 | |||
428 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, |
|
425 | ax.plot = ax.pcolormesh(x, y, z_coh[n].T, | |
429 | vmin=self.zmin_coh, |
|
426 | vmin=self.zmin_coh, | |
430 | vmax=self.zmax_coh, |
|
427 | vmax=self.zmax_coh, | |
431 | cmap=plt.get_cmap(self.colormap_coh) |
|
428 | cmap=plt.get_cmap(self.colormap_coh) | |
432 | ) |
|
429 | ) | |
433 | divider = make_axes_locatable(ax) |
|
430 | divider = make_axes_locatable(ax) | |
434 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
431 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
435 | self.figure.add_axes(cax) |
|
432 | self.figure.add_axes(cax) | |
436 | plt.colorbar(ax.plot, cax) |
|
433 | plt.colorbar(ax.plot, cax) | |
437 |
|
434 | |||
438 | ax.set_xlim(self.xmin, self.xmax) |
|
435 | ax.set_xlim(self.xmin, self.xmax) | |
439 | ax.set_ylim(self.ymin, self.ymax) |
|
436 | ax.set_ylim(self.ymin, self.ymax) | |
440 |
|
437 | |||
441 | ax.set_ylabel(self.ylabel) |
|
438 | ax.set_ylabel(self.ylabel) | |
442 | ax.set_xlabel(xlabel) |
|
439 | ax.set_xlabel(xlabel) | |
443 | ax.firsttime = False |
|
440 | ax.firsttime = False | |
444 |
|
441 | |||
445 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, |
|
442 | ax1.plot = ax1.pcolormesh(x, y, z_phase[n].T, | |
446 | vmin=self.zmin_phase, |
|
443 | vmin=self.zmin_phase, | |
447 | vmax=self.zmax_phase, |
|
444 | vmax=self.zmax_phase, | |
448 | cmap=plt.get_cmap(self.colormap_phase) |
|
445 | cmap=plt.get_cmap(self.colormap_phase) | |
449 | ) |
|
446 | ) | |
450 | divider = make_axes_locatable(ax1) |
|
447 | divider = make_axes_locatable(ax1) | |
451 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
448 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
452 | self.figure.add_axes(cax) |
|
449 | self.figure.add_axes(cax) | |
453 | plt.colorbar(ax1.plot, cax) |
|
450 | plt.colorbar(ax1.plot, cax) | |
454 |
|
451 | |||
455 | ax1.set_xlim(self.xmin, self.xmax) |
|
452 | ax1.set_xlim(self.xmin, self.xmax) | |
456 | ax1.set_ylim(self.ymin, self.ymax) |
|
453 | ax1.set_ylim(self.ymin, self.ymax) | |
457 |
|
454 | |||
458 | ax1.set_ylabel(self.ylabel) |
|
455 | ax1.set_ylabel(self.ylabel) | |
459 | ax1.set_xlabel(xlabel) |
|
456 | ax1.set_xlabel(xlabel) | |
460 | ax1.firsttime = False |
|
457 | ax1.firsttime = False | |
461 | else: |
|
458 | else: | |
462 | ax.plot.set_array(z_coh[n].T.ravel()) |
|
459 | ax.plot.set_array(z_coh[n].T.ravel()) | |
463 | ax1.plot.set_array(z_phase[n].T.ravel()) |
|
460 | ax1.plot.set_array(z_phase[n].T.ravel()) | |
464 |
|
461 | |||
465 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
462 | ax.set_title('Coherence Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) | |
466 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) |
|
463 | ax1.set_title('Phase Ch{} * Ch{}'.format(self.dataOut.pairsList[n][0], self.dataOut.pairsList[n][1]), size=8) | |
467 | self.saveTime = self.max_time |
|
464 | self.saveTime = self.max_time | |
468 |
|
465 | |||
469 |
|
466 | |||
470 | class PlotSpectraMeanData(PlotSpectraData): |
|
467 | class PlotSpectraMeanData(PlotSpectraData): | |
471 |
|
468 | |||
472 | CODE = 'spc_mean' |
|
469 | CODE = 'spc_mean' | |
473 | colormap = 'jet' |
|
470 | colormap = 'jet' | |
474 |
|
471 | |||
475 | def plot(self): |
|
472 | def plot(self): | |
476 |
|
473 | |||
477 | if self.xaxis == "frequency": |
|
474 | if self.xaxis == "frequency": | |
478 | x = self.dataOut.getFreqRange(1)/1000. |
|
475 | x = self.dataOut.getFreqRange(1)/1000. | |
479 | xlabel = "Frequency (kHz)" |
|
476 | xlabel = "Frequency (kHz)" | |
480 | elif self.xaxis == "time": |
|
477 | elif self.xaxis == "time": | |
481 | x = self.dataOut.getAcfRange(1) |
|
478 | x = self.dataOut.getAcfRange(1) | |
482 | xlabel = "Time (ms)" |
|
479 | xlabel = "Time (ms)" | |
483 | else: |
|
480 | else: | |
484 | x = self.dataOut.getVelRange(1) |
|
481 | x = self.dataOut.getVelRange(1) | |
485 | xlabel = "Velocity (m/s)" |
|
482 | xlabel = "Velocity (m/s)" | |
486 |
|
483 | |||
487 | y = self.dataOut.getHeiRange() |
|
484 | y = self.dataOut.getHeiRange() | |
488 | z = self.data['spc'] |
|
485 | z = self.data['spc'] | |
489 | mean = self.data['mean'][self.max_time] |
|
486 | mean = self.data['mean'][self.max_time] | |
490 |
|
487 | |||
491 | for n, ax in enumerate(self.axes): |
|
488 | for n, ax in enumerate(self.axes): | |
492 |
|
489 | |||
493 | if ax.firsttime: |
|
490 | if ax.firsttime: | |
494 | self.xmax = self.xmax if self.xmax else np.nanmax(x) |
|
491 | self.xmax = self.xmax if self.xmax else np.nanmax(x) | |
495 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
492 | self.xmin = self.xmin if self.xmin else -self.xmax | |
496 | self.ymin = self.ymin if self.ymin else np.nanmin(y) |
|
493 | self.ymin = self.ymin if self.ymin else np.nanmin(y) | |
497 | self.ymax = self.ymax if self.ymax else np.nanmax(y) |
|
494 | self.ymax = self.ymax if self.ymax else np.nanmax(y) | |
498 | self.zmin = self.zmin if self.zmin else np.nanmin(z) |
|
495 | self.zmin = self.zmin if self.zmin else np.nanmin(z) | |
499 | self.zmax = self.zmax if self.zmax else np.nanmax(z) |
|
496 | self.zmax = self.zmax if self.zmax else np.nanmax(z) | |
500 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
497 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
501 | vmin=self.zmin, |
|
498 | vmin=self.zmin, | |
502 | vmax=self.zmax, |
|
499 | vmax=self.zmax, | |
503 | cmap=plt.get_cmap(self.colormap) |
|
500 | cmap=plt.get_cmap(self.colormap) | |
504 | ) |
|
501 | ) | |
505 | ax.plt_dop = ax.plot(mean[n], y, |
|
502 | ax.plt_dop = ax.plot(mean[n], y, | |
506 | color='k')[0] |
|
503 | color='k')[0] | |
507 |
|
504 | |||
508 | divider = make_axes_locatable(ax) |
|
505 | divider = make_axes_locatable(ax) | |
509 | cax = divider.new_horizontal(size='3%', pad=0.05) |
|
506 | cax = divider.new_horizontal(size='3%', pad=0.05) | |
510 | self.figure.add_axes(cax) |
|
507 | self.figure.add_axes(cax) | |
511 | plt.colorbar(ax.plt, cax) |
|
508 | plt.colorbar(ax.plt, cax) | |
512 |
|
509 | |||
513 | ax.set_xlim(self.xmin, self.xmax) |
|
510 | ax.set_xlim(self.xmin, self.xmax) | |
514 | ax.set_ylim(self.ymin, self.ymax) |
|
511 | ax.set_ylim(self.ymin, self.ymax) | |
515 |
|
512 | |||
516 | ax.set_ylabel(self.ylabel) |
|
513 | ax.set_ylabel(self.ylabel) | |
517 | ax.set_xlabel(xlabel) |
|
514 | ax.set_xlabel(xlabel) | |
518 |
|
515 | |||
519 | ax.firsttime = False |
|
516 | ax.firsttime = False | |
520 |
|
517 | |||
521 | if self.showprofile: |
|
518 | if self.showprofile: | |
522 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] |
|
519 | ax.plt_profile= ax.ax_profile.plot(self.data['rti'][self.max_time][n], y)[0] | |
523 | ax.ax_profile.set_xlim(self.zmin, self.zmax) |
|
520 | ax.ax_profile.set_xlim(self.zmin, self.zmax) | |
524 | ax.ax_profile.set_ylim(self.ymin, self.ymax) |
|
521 | ax.ax_profile.set_ylim(self.ymin, self.ymax) | |
525 | ax.ax_profile.set_xlabel('dB') |
|
522 | ax.ax_profile.set_xlabel('dB') | |
526 | ax.ax_profile.grid(b=True, axis='x') |
|
523 | ax.ax_profile.grid(b=True, axis='x') | |
527 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, |
|
524 | ax.plt_noise = ax.ax_profile.plot(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y, | |
528 | color="k", linestyle="dashed", lw=2)[0] |
|
525 | color="k", linestyle="dashed", lw=2)[0] | |
529 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] |
|
526 | [tick.set_visible(False) for tick in ax.ax_profile.get_yticklabels()] | |
530 | else: |
|
527 | else: | |
531 | ax.plt.set_array(z[n].T.ravel()) |
|
528 | ax.plt.set_array(z[n].T.ravel()) | |
532 | ax.plt_dop.set_data(mean[n], y) |
|
529 | ax.plt_dop.set_data(mean[n], y) | |
533 | if self.showprofile: |
|
530 | if self.showprofile: | |
534 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) |
|
531 | ax.plt_profile.set_data(self.data['rti'][self.max_time][n], y) | |
535 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) |
|
532 | ax.plt_noise.set_data(numpy.repeat(self.data['noise'][self.max_time][n], len(y)), y) | |
536 |
|
533 | |||
537 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), |
|
534 | ax.set_title('{} - Noise: {:.2f} dB'.format(self.titles[n], self.data['noise'][self.max_time][n]), | |
538 | size=8) |
|
535 | size=8) | |
539 | self.saveTime = self.max_time |
|
536 | self.saveTime = self.max_time | |
540 |
|
537 | |||
541 |
|
538 | |||
542 | class PlotRTIData(PlotData): |
|
539 | class PlotRTIData(PlotData): | |
543 |
|
540 | |||
544 | CODE = 'rti' |
|
541 | CODE = 'rti' | |
545 | colormap = 'jro' |
|
542 | colormap = 'jro' | |
546 |
|
543 | |||
547 | def setup(self): |
|
544 | def setup(self): | |
548 | self.ncols = 1 |
|
545 | self.ncols = 1 | |
549 | self.nrows = self.dataOut.nChannels |
|
546 | self.nrows = self.dataOut.nChannels | |
550 | self.width = 10 |
|
547 | self.width = 10 | |
551 | #TODO : arreglar la altura de la figura, esta hardcodeada. |
|
548 | #TODO : arreglar la altura de la figura, esta hardcodeada. | |
552 | #Se arreglo, testear! |
|
549 | #Se arreglo, testear! | |
553 | if self.ind_plt_ch: |
|
550 | if self.ind_plt_ch: | |
554 | self.height = 3.2#*self.nrows if self.nrows<6 else 12 |
|
551 | self.height = 3.2#*self.nrows if self.nrows<6 else 12 | |
555 | else: |
|
552 | else: | |
556 | 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 | |
557 |
|
554 | |||
558 | ''' |
|
555 | ''' | |
559 | if self.nrows==1: |
|
556 | if self.nrows==1: | |
560 | self.height += 1 |
|
557 | self.height += 1 | |
561 | ''' |
|
558 | ''' | |
562 | self.ylabel = 'Range [Km]' |
|
559 | self.ylabel = 'Range [Km]' | |
563 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] |
|
560 | self.titles = ['Channel {}'.format(x) for x in self.dataOut.channelList] | |
564 |
|
561 | |||
565 | ''' |
|
562 | ''' | |
566 | Logica: |
|
563 | Logica: | |
567 | 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura |
|
564 | 1) Si la variable ind_plt_ch es True, va a crear mas de 1 figura | |
568 | 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el |
|
565 | 2) guardamos "Figures" en una lista y "axes" en otra, quizas se deberia guardar el | |
569 | axis dentro de "Figures" como un diccionario. |
|
566 | axis dentro de "Figures" como un diccionario. | |
570 | ''' |
|
567 | ''' | |
571 | if self.ind_plt_ch is False: #standard mode |
|
568 | if self.ind_plt_ch is False: #standard mode | |
572 |
|
569 | |||
573 | if self.figure is None: #solo para la priemra vez |
|
570 | if self.figure is None: #solo para la priemra vez | |
574 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
571 | self.figure = plt.figure(figsize=(self.width, self.height), | |
575 | edgecolor='k', |
|
572 | edgecolor='k', | |
576 | facecolor='w') |
|
573 | facecolor='w') | |
577 | else: |
|
574 | else: | |
578 | self.figure.clf() |
|
575 | self.figure.clf() | |
579 | self.axes = [] |
|
576 | self.axes = [] | |
580 |
|
577 | |||
581 |
|
578 | |||
582 | for n in range(self.nrows): |
|
579 | for n in range(self.nrows): | |
583 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
580 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
584 | #ax = self.figure(n+1) |
|
581 | #ax = self.figure(n+1) | |
585 | ax.firsttime = True |
|
582 | ax.firsttime = True | |
586 | self.axes.append(ax) |
|
583 | self.axes.append(ax) | |
587 |
|
584 | |||
588 | else : #append one figure foreach channel in channelList |
|
585 | else : #append one figure foreach channel in channelList | |
589 | if self.figurelist == None: |
|
586 | if self.figurelist == None: | |
590 | self.figurelist = [] |
|
587 | self.figurelist = [] | |
591 | for n in range(self.nrows): |
|
588 | for n in range(self.nrows): | |
592 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
589 | self.figure = plt.figure(figsize=(self.width, self.height), | |
593 | edgecolor='k', |
|
590 | edgecolor='k', | |
594 | facecolor='w') |
|
591 | facecolor='w') | |
595 | #add always one subplot |
|
592 | #add always one subplot | |
596 | self.figurelist.append(self.figure) |
|
593 | self.figurelist.append(self.figure) | |
597 |
|
594 | |||
598 | else : # cada dia nuevo limpia el axes, pero mantiene el figure |
|
595 | else : # cada dia nuevo limpia el axes, pero mantiene el figure | |
599 | for eachfigure in self.figurelist: |
|
596 | for eachfigure in self.figurelist: | |
600 | eachfigure.clf() # eliminaria todas las figuras de la lista? |
|
597 | eachfigure.clf() # eliminaria todas las figuras de la lista? | |
601 | self.axes = [] |
|
598 | self.axes = [] | |
602 |
|
599 | |||
603 | for eachfigure in self.figurelist: |
|
600 | for eachfigure in self.figurelist: | |
604 | ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura |
|
601 | ax = eachfigure.add_subplot(1,1,1) #solo 1 axis por figura | |
605 | #ax = self.figure(n+1) |
|
602 | #ax = self.figure(n+1) | |
606 | ax.firsttime = True |
|
603 | ax.firsttime = True | |
607 | #Cada figura tiene un distinto puntero |
|
604 | #Cada figura tiene un distinto puntero | |
608 | self.axes.append(ax) |
|
605 | self.axes.append(ax) | |
609 | #plt.close(eachfigure) |
|
606 | #plt.close(eachfigure) | |
610 |
|
607 | |||
611 |
|
608 | |||
612 | def plot(self): |
|
609 | def plot(self): | |
613 |
|
610 | |||
614 | if self.ind_plt_ch is False: #standard mode |
|
611 | if self.ind_plt_ch is False: #standard mode | |
615 | self.x = np.array(self.times) |
|
612 | self.x = np.array(self.times) | |
616 | self.y = self.dataOut.getHeiRange() |
|
613 | self.y = self.dataOut.getHeiRange() | |
617 | self.z = [] |
|
614 | self.z = [] | |
618 |
|
615 | |||
619 | for ch in range(self.nrows): |
|
616 | for ch in range(self.nrows): | |
620 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
617 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
621 |
|
618 | |||
622 | self.z = np.array(self.z) |
|
619 | self.z = np.array(self.z) | |
623 | for n, ax in enumerate(self.axes): |
|
620 | for n, ax in enumerate(self.axes): | |
624 | x, y, z = self.fill_gaps(*self.decimate()) |
|
621 | x, y, z = self.fill_gaps(*self.decimate()) | |
625 | xmin = self.min_time |
|
622 | xmin = self.min_time | |
626 | xmax = xmin+self.xrange*60*60 |
|
623 | xmax = xmin+self.xrange*60*60 | |
627 | self.zmin = self.zmin if self.zmin else np.min(self.z) |
|
624 | self.zmin = self.zmin if self.zmin else np.min(self.z) | |
628 | self.zmax = self.zmax if self.zmax else np.max(self.z) |
|
625 | self.zmax = self.zmax if self.zmax else np.max(self.z) | |
629 | if ax.firsttime: |
|
626 | if ax.firsttime: | |
630 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
627 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
631 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
628 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
632 | plot = ax.pcolormesh(x, y, z[n].T, |
|
629 | plot = ax.pcolormesh(x, y, z[n].T, | |
633 | vmin=self.zmin, |
|
630 | vmin=self.zmin, | |
634 | vmax=self.zmax, |
|
631 | vmax=self.zmax, | |
635 | cmap=plt.get_cmap(self.colormap) |
|
632 | cmap=plt.get_cmap(self.colormap) | |
636 | ) |
|
633 | ) | |
637 | divider = make_axes_locatable(ax) |
|
634 | divider = make_axes_locatable(ax) | |
638 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
635 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
639 | self.figure.add_axes(cax) |
|
636 | self.figure.add_axes(cax) | |
640 | plt.colorbar(plot, cax) |
|
637 | plt.colorbar(plot, cax) | |
641 | ax.set_ylim(self.ymin, self.ymax) |
|
638 | ax.set_ylim(self.ymin, self.ymax) | |
642 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
639 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
643 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
640 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
644 | ax.set_ylabel(self.ylabel) |
|
641 | ax.set_ylabel(self.ylabel) | |
645 | if self.xmin is None: |
|
642 | if self.xmin is None: | |
646 | xmin = self.min_time |
|
643 | xmin = self.min_time | |
647 | else: |
|
644 | else: | |
648 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
645 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |
649 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
646 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |
650 | ax.set_xlim(xmin, xmax) |
|
647 | ax.set_xlim(xmin, xmax) | |
651 | ax.firsttime = False |
|
648 | ax.firsttime = False | |
652 | else: |
|
649 | else: | |
653 | ax.collections.remove(ax.collections[0]) |
|
650 | ax.collections.remove(ax.collections[0]) | |
654 | ax.set_xlim(xmin, xmax) |
|
651 | ax.set_xlim(xmin, xmax) | |
655 | plot = ax.pcolormesh(x, y, z[n].T, |
|
652 | plot = ax.pcolormesh(x, y, z[n].T, | |
656 | vmin=self.zmin, |
|
653 | vmin=self.zmin, | |
657 | vmax=self.zmax, |
|
654 | vmax=self.zmax, | |
658 | cmap=plt.get_cmap(self.colormap) |
|
655 | cmap=plt.get_cmap(self.colormap) | |
659 | ) |
|
656 | ) | |
660 | ax.set_title('{} {}'.format(self.titles[n], |
|
657 | ax.set_title('{} {}'.format(self.titles[n], | |
661 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
658 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
662 | size=8) |
|
659 | size=8) | |
663 |
|
660 | |||
664 | self.saveTime = self.min_time |
|
661 | self.saveTime = self.min_time | |
665 | else : |
|
662 | else : | |
666 | self.x = np.array(self.times) |
|
663 | self.x = np.array(self.times) | |
667 | self.y = self.dataOut.getHeiRange() |
|
664 | self.y = self.dataOut.getHeiRange() | |
668 | self.z = [] |
|
665 | self.z = [] | |
669 |
|
666 | |||
670 | for ch in range(self.nrows): |
|
667 | for ch in range(self.nrows): | |
671 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) |
|
668 | self.z.append([self.data[self.CODE][t][ch] for t in self.times]) | |
672 |
|
669 | |||
673 | self.z = np.array(self.z) |
|
670 | self.z = np.array(self.z) | |
674 | for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes |
|
671 | for n, eachfigure in enumerate(self.figurelist): #estaba ax in axes | |
675 |
|
672 | |||
676 | x, y, z = self.fill_gaps(*self.decimate()) |
|
673 | x, y, z = self.fill_gaps(*self.decimate()) | |
677 | xmin = self.min_time |
|
674 | xmin = self.min_time | |
678 | xmax = xmin+self.xrange*60*60 |
|
675 | xmax = xmin+self.xrange*60*60 | |
679 | self.zmin = self.zmin if self.zmin else np.min(self.z) |
|
676 | self.zmin = self.zmin if self.zmin else np.min(self.z) | |
680 | self.zmax = self.zmax if self.zmax else np.max(self.z) |
|
677 | self.zmax = self.zmax if self.zmax else np.max(self.z) | |
681 | if self.axes[n].firsttime: |
|
678 | if self.axes[n].firsttime: | |
682 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
679 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
683 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
680 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
684 | plot = self.axes[n].pcolormesh(x, y, z[n].T, |
|
681 | plot = self.axes[n].pcolormesh(x, y, z[n].T, | |
685 | vmin=self.zmin, |
|
682 | vmin=self.zmin, | |
686 | vmax=self.zmax, |
|
683 | vmax=self.zmax, | |
687 | cmap=plt.get_cmap(self.colormap) |
|
684 | cmap=plt.get_cmap(self.colormap) | |
688 | ) |
|
685 | ) | |
689 | divider = make_axes_locatable(self.axes[n]) |
|
686 | divider = make_axes_locatable(self.axes[n]) | |
690 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
687 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
691 | eachfigure.add_axes(cax) |
|
688 | eachfigure.add_axes(cax) | |
692 | #self.figure2.add_axes(cax) |
|
689 | #self.figure2.add_axes(cax) | |
693 | plt.colorbar(plot, cax) |
|
690 | plt.colorbar(plot, cax) | |
694 | self.axes[n].set_ylim(self.ymin, self.ymax) |
|
691 | self.axes[n].set_ylim(self.ymin, self.ymax) | |
695 |
|
692 | |||
696 | self.axes[n].xaxis.set_major_formatter(FuncFormatter(func)) |
|
693 | self.axes[n].xaxis.set_major_formatter(FuncFormatter(func)) | |
697 | self.axes[n].xaxis.set_major_locator(LinearLocator(6)) |
|
694 | self.axes[n].xaxis.set_major_locator(LinearLocator(6)) | |
698 |
|
695 | |||
699 | self.axes[n].set_ylabel(self.ylabel) |
|
696 | self.axes[n].set_ylabel(self.ylabel) | |
700 |
|
697 | |||
701 | if self.xmin is None: |
|
698 | if self.xmin is None: | |
702 | xmin = self.min_time |
|
699 | xmin = self.min_time | |
703 | else: |
|
700 | else: | |
704 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), |
|
701 | xmin = (datetime.datetime.combine(self.dataOut.datatime.date(), | |
705 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() |
|
702 | datetime.time(self.xmin, 0, 0))-d1970).total_seconds() | |
706 |
|
703 | |||
707 | self.axes[n].set_xlim(xmin, xmax) |
|
704 | self.axes[n].set_xlim(xmin, xmax) | |
708 | self.axes[n].firsttime = False |
|
705 | self.axes[n].firsttime = False | |
709 | else: |
|
706 | else: | |
710 | self.axes[n].collections.remove(self.axes[n].collections[0]) |
|
707 | self.axes[n].collections.remove(self.axes[n].collections[0]) | |
711 | self.axes[n].set_xlim(xmin, xmax) |
|
708 | self.axes[n].set_xlim(xmin, xmax) | |
712 | plot = self.axes[n].pcolormesh(x, y, z[n].T, |
|
709 | plot = self.axes[n].pcolormesh(x, y, z[n].T, | |
713 | vmin=self.zmin, |
|
710 | vmin=self.zmin, | |
714 | vmax=self.zmax, |
|
711 | vmax=self.zmax, | |
715 | cmap=plt.get_cmap(self.colormap) |
|
712 | cmap=plt.get_cmap(self.colormap) | |
716 | ) |
|
713 | ) | |
717 | self.axes[n].set_title('{} {}'.format(self.titles[n], |
|
714 | self.axes[n].set_title('{} {}'.format(self.titles[n], | |
718 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
715 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
719 | size=8) |
|
716 | size=8) | |
720 |
|
717 | |||
721 | self.saveTime = self.min_time |
|
718 | self.saveTime = self.min_time | |
722 |
|
719 | |||
723 |
|
720 | |||
724 | class PlotCOHData(PlotRTIData): |
|
721 | class PlotCOHData(PlotRTIData): | |
725 |
|
722 | |||
726 | CODE = 'coh' |
|
723 | CODE = 'coh' | |
727 |
|
724 | |||
728 | def setup(self): |
|
725 | def setup(self): | |
729 |
|
726 | |||
730 | self.ncols = 1 |
|
727 | self.ncols = 1 | |
731 | self.nrows = self.dataOut.nPairs |
|
728 | self.nrows = self.dataOut.nPairs | |
732 | self.width = 10 |
|
729 | self.width = 10 | |
733 | 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 | |
734 | self.ind_plt_ch = False #just for coherence and phase |
|
731 | self.ind_plt_ch = False #just for coherence and phase | |
735 | if self.nrows==1: |
|
732 | if self.nrows==1: | |
736 | self.height += 1 |
|
733 | self.height += 1 | |
737 | self.ylabel = 'Range [Km]' |
|
734 | self.ylabel = 'Range [Km]' | |
738 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] |
|
735 | self.titles = ['{} Ch{} * Ch{}'.format(self.CODE.upper(), x[0], x[1]) for x in self.dataOut.pairsList] | |
739 |
|
736 | |||
740 | if self.figure is None: |
|
737 | if self.figure is None: | |
741 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
738 | self.figure = plt.figure(figsize=(self.width, self.height), | |
742 | edgecolor='k', |
|
739 | edgecolor='k', | |
743 | facecolor='w') |
|
740 | facecolor='w') | |
744 | else: |
|
741 | else: | |
745 | self.figure.clf() |
|
742 | self.figure.clf() | |
746 | self.axes = [] |
|
743 | self.axes = [] | |
747 |
|
744 | |||
748 | for n in range(self.nrows): |
|
745 | for n in range(self.nrows): | |
749 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
746 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
750 | ax.firsttime = True |
|
747 | ax.firsttime = True | |
751 | self.axes.append(ax) |
|
748 | self.axes.append(ax) | |
752 |
|
749 | |||
753 |
|
750 | |||
754 | class PlotNoiseData(PlotData): |
|
751 | class PlotNoiseData(PlotData): | |
755 | CODE = 'noise' |
|
752 | CODE = 'noise' | |
756 |
|
753 | |||
757 | def setup(self): |
|
754 | def setup(self): | |
758 |
|
755 | |||
759 | self.ncols = 1 |
|
756 | self.ncols = 1 | |
760 | self.nrows = 1 |
|
757 | self.nrows = 1 | |
761 | self.width = 10 |
|
758 | self.width = 10 | |
762 | self.height = 3.2 |
|
759 | self.height = 3.2 | |
763 | self.ylabel = 'Intensity [dB]' |
|
760 | self.ylabel = 'Intensity [dB]' | |
764 | self.titles = ['Noise'] |
|
761 | self.titles = ['Noise'] | |
765 |
|
762 | |||
766 | if self.figure is None: |
|
763 | if self.figure is None: | |
767 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
764 | self.figure = plt.figure(figsize=(self.width, self.height), | |
768 | edgecolor='k', |
|
765 | edgecolor='k', | |
769 | facecolor='w') |
|
766 | facecolor='w') | |
770 | else: |
|
767 | else: | |
771 | self.figure.clf() |
|
768 | self.figure.clf() | |
772 | self.axes = [] |
|
769 | self.axes = [] | |
773 |
|
770 | |||
774 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) |
|
771 | self.ax = self.figure.add_subplot(self.nrows, self.ncols, 1) | |
775 | self.ax.firsttime = True |
|
772 | self.ax.firsttime = True | |
776 |
|
773 | |||
777 | def plot(self): |
|
774 | def plot(self): | |
778 |
|
775 | |||
779 | x = self.times |
|
776 | x = self.times | |
780 | xmin = self.min_time |
|
777 | xmin = self.min_time | |
781 | xmax = xmin+self.xrange*60*60 |
|
778 | xmax = xmin+self.xrange*60*60 | |
782 | if self.ax.firsttime: |
|
779 | if self.ax.firsttime: | |
783 | for ch in self.dataOut.channelList: |
|
780 | for ch in self.dataOut.channelList: | |
784 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
781 | y = [self.data[self.CODE][t][ch] for t in self.times] | |
785 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
782 | self.ax.plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
786 | self.ax.firsttime = False |
|
783 | self.ax.firsttime = False | |
787 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
784 | self.ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
788 | self.ax.xaxis.set_major_locator(LinearLocator(6)) |
|
785 | self.ax.xaxis.set_major_locator(LinearLocator(6)) | |
789 | self.ax.set_ylabel(self.ylabel) |
|
786 | self.ax.set_ylabel(self.ylabel) | |
790 | plt.legend() |
|
787 | plt.legend() | |
791 | else: |
|
788 | else: | |
792 | for ch in self.dataOut.channelList: |
|
789 | for ch in self.dataOut.channelList: | |
793 | y = [self.data[self.CODE][t][ch] for t in self.times] |
|
790 | y = [self.data[self.CODE][t][ch] for t in self.times] | |
794 | self.ax.lines[ch].set_data(x, y) |
|
791 | self.ax.lines[ch].set_data(x, y) | |
795 |
|
792 | |||
796 | self.ax.set_xlim(xmin, xmax) |
|
793 | self.ax.set_xlim(xmin, xmax) | |
797 | self.ax.set_ylim(min(y)-5, max(y)+5) |
|
794 | self.ax.set_ylim(min(y)-5, max(y)+5) | |
798 | self.saveTime = self.min_time |
|
795 | self.saveTime = self.min_time | |
799 |
|
796 | |||
800 |
|
797 | |||
801 | class PlotWindProfilerData(PlotRTIData): |
|
798 | class PlotWindProfilerData(PlotRTIData): | |
802 |
|
799 | |||
803 | CODE = 'wind' |
|
800 | CODE = 'wind' | |
804 | colormap = 'seismic' |
|
801 | colormap = 'seismic' | |
805 |
|
802 | |||
806 | def setup(self): |
|
803 | def setup(self): | |
807 | self.ncols = 1 |
|
804 | self.ncols = 1 | |
808 | self.nrows = self.dataOut.data_output.shape[0] |
|
805 | self.nrows = self.dataOut.data_output.shape[0] | |
809 | self.width = 10 |
|
806 | self.width = 10 | |
810 | self.height = 2.2*self.nrows |
|
807 | self.height = 2.2*self.nrows | |
811 | self.ylabel = 'Height [Km]' |
|
808 | self.ylabel = 'Height [Km]' | |
812 | self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind'] |
|
809 | self.titles = ['Zonal Wind' ,'Meridional Wind', 'Vertical Wind'] | |
813 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
810 | self.clabels = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] | |
814 | self.windFactor = [1, 1, 100] |
|
811 | self.windFactor = [1, 1, 100] | |
815 |
|
812 | |||
816 | if self.figure is None: |
|
813 | if self.figure is None: | |
817 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
814 | self.figure = plt.figure(figsize=(self.width, self.height), | |
818 | edgecolor='k', |
|
815 | edgecolor='k', | |
819 | facecolor='w') |
|
816 | facecolor='w') | |
820 | else: |
|
817 | else: | |
821 | self.figure.clf() |
|
818 | self.figure.clf() | |
822 | self.axes = [] |
|
819 | self.axes = [] | |
823 |
|
820 | |||
824 | for n in range(self.nrows): |
|
821 | for n in range(self.nrows): | |
825 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) |
|
822 | ax = self.figure.add_subplot(self.nrows, self.ncols, n+1) | |
826 | ax.firsttime = True |
|
823 | ax.firsttime = True | |
827 | self.axes.append(ax) |
|
824 | self.axes.append(ax) | |
828 |
|
825 | |||
829 | def plot(self): |
|
826 | def plot(self): | |
830 |
|
827 | |||
831 | self.x = np.array(self.times) |
|
828 | self.x = np.array(self.times) | |
832 | self.y = self.dataOut.heightList |
|
829 | self.y = self.dataOut.heightList | |
833 | self.z = [] |
|
830 | self.z = [] | |
834 |
|
831 | |||
835 | for ch in range(self.nrows): |
|
832 | for ch in range(self.nrows): | |
836 | self.z.append([self.data['output'][t][ch] for t in self.times]) |
|
833 | self.z.append([self.data['output'][t][ch] for t in self.times]) | |
837 |
|
834 | |||
838 | self.z = np.array(self.z) |
|
835 | self.z = np.array(self.z) | |
839 | self.z = numpy.ma.masked_invalid(self.z) |
|
836 | self.z = numpy.ma.masked_invalid(self.z) | |
840 |
|
837 | |||
841 | cmap=plt.get_cmap(self.colormap) |
|
838 | cmap=plt.get_cmap(self.colormap) | |
842 | cmap.set_bad('black', 1.) |
|
839 | cmap.set_bad('black', 1.) | |
843 |
|
840 | |||
844 | for n, ax in enumerate(self.axes): |
|
841 | for n, ax in enumerate(self.axes): | |
845 | x, y, z = self.fill_gaps(*self.decimate()) |
|
842 | x, y, z = self.fill_gaps(*self.decimate()) | |
846 | xmin = self.min_time |
|
843 | xmin = self.min_time | |
847 | xmax = xmin+self.xrange*60*60 |
|
844 | xmax = xmin+self.xrange*60*60 | |
848 | if ax.firsttime: |
|
845 | if ax.firsttime: | |
849 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) |
|
846 | self.ymin = self.ymin if self.ymin else np.nanmin(self.y) | |
850 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) |
|
847 | self.ymax = self.ymax if self.ymax else np.nanmax(self.y) | |
851 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) |
|
848 | self.zmax = self.zmax if self.zmax else numpy.nanmax(abs(self.z[:-1, :])) | |
852 | self.zmin = self.zmin if self.zmin else -self.zmax |
|
849 | self.zmin = self.zmin if self.zmin else -self.zmax | |
853 |
|
850 | |||
854 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
851 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], | |
855 | vmin=self.zmin, |
|
852 | vmin=self.zmin, | |
856 | vmax=self.zmax, |
|
853 | vmax=self.zmax, | |
857 | cmap=cmap |
|
854 | cmap=cmap | |
858 | ) |
|
855 | ) | |
859 | divider = make_axes_locatable(ax) |
|
856 | divider = make_axes_locatable(ax) | |
860 | cax = divider.new_horizontal(size='2%', pad=0.05) |
|
857 | cax = divider.new_horizontal(size='2%', pad=0.05) | |
861 | self.figure.add_axes(cax) |
|
858 | self.figure.add_axes(cax) | |
862 | cb = plt.colorbar(plot, cax) |
|
859 | cb = plt.colorbar(plot, cax) | |
863 | cb.set_label(self.clabels[n]) |
|
860 | cb.set_label(self.clabels[n]) | |
864 | ax.set_ylim(self.ymin, self.ymax) |
|
861 | ax.set_ylim(self.ymin, self.ymax) | |
865 |
|
862 | |||
866 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
863 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
867 | ax.xaxis.set_major_locator(LinearLocator(6)) |
|
864 | ax.xaxis.set_major_locator(LinearLocator(6)) | |
868 |
|
865 | |||
869 | ax.set_ylabel(self.ylabel) |
|
866 | ax.set_ylabel(self.ylabel) | |
870 |
|
867 | |||
871 | ax.set_xlim(xmin, xmax) |
|
868 | ax.set_xlim(xmin, xmax) | |
872 | ax.firsttime = False |
|
869 | ax.firsttime = False | |
873 | else: |
|
870 | else: | |
874 | ax.collections.remove(ax.collections[0]) |
|
871 | ax.collections.remove(ax.collections[0]) | |
875 | ax.set_xlim(xmin, xmax) |
|
872 | ax.set_xlim(xmin, xmax) | |
876 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], |
|
873 | plot = ax.pcolormesh(x, y, z[n].T*self.windFactor[n], | |
877 | vmin=self.zmin, |
|
874 | vmin=self.zmin, | |
878 | vmax=self.zmax, |
|
875 | vmax=self.zmax, | |
879 | cmap=plt.get_cmap(self.colormap) |
|
876 | cmap=plt.get_cmap(self.colormap) | |
880 | ) |
|
877 | ) | |
881 | ax.set_title('{} {}'.format(self.titles[n], |
|
878 | ax.set_title('{} {}'.format(self.titles[n], | |
882 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), |
|
879 | datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S')), | |
883 | size=8) |
|
880 | size=8) | |
884 |
|
881 | |||
885 | self.saveTime = self.min_time |
|
882 | self.saveTime = self.min_time | |
886 |
|
883 | |||
887 |
|
884 | |||
888 | class PlotSNRData(PlotRTIData): |
|
885 | class PlotSNRData(PlotRTIData): | |
889 | CODE = 'snr' |
|
886 | CODE = 'snr' | |
890 | colormap = 'jet' |
|
887 | colormap = 'jet' | |
891 |
|
888 | |||
892 | class PlotDOPData(PlotRTIData): |
|
889 | class PlotDOPData(PlotRTIData): | |
893 | CODE = 'dop' |
|
890 | CODE = 'dop' | |
894 | colormap = 'jet' |
|
891 | colormap = 'jet' | |
895 |
|
892 | |||
896 |
|
893 | |||
897 | class PlotPHASEData(PlotCOHData): |
|
894 | class PlotPHASEData(PlotCOHData): | |
898 | CODE = 'phase' |
|
895 | CODE = 'phase' | |
899 | colormap = 'seismic' |
|
896 | colormap = 'seismic' | |
900 |
|
897 | |||
901 |
|
898 | |||
902 | class PlotSkyMapData(PlotData): |
|
899 | class PlotSkyMapData(PlotData): | |
903 |
|
900 | |||
904 | CODE = 'met' |
|
901 | CODE = 'met' | |
905 |
|
902 | |||
906 | def setup(self): |
|
903 | def setup(self): | |
907 |
|
904 | |||
908 | self.ncols = 1 |
|
905 | self.ncols = 1 | |
909 | self.nrows = 1 |
|
906 | self.nrows = 1 | |
910 | self.width = 7.2 |
|
907 | self.width = 7.2 | |
911 | self.height = 7.2 |
|
908 | self.height = 7.2 | |
912 |
|
909 | |||
913 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
910 | self.xlabel = 'Zonal Zenith Angle (deg)' | |
914 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
911 | self.ylabel = 'Meridional Zenith Angle (deg)' | |
915 |
|
912 | |||
916 | if self.figure is None: |
|
913 | if self.figure is None: | |
917 | self.figure = plt.figure(figsize=(self.width, self.height), |
|
914 | self.figure = plt.figure(figsize=(self.width, self.height), | |
918 | edgecolor='k', |
|
915 | edgecolor='k', | |
919 | facecolor='w') |
|
916 | facecolor='w') | |
920 | else: |
|
917 | else: | |
921 | self.figure.clf() |
|
918 | self.figure.clf() | |
922 |
|
919 | |||
923 | self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True) |
|
920 | self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True) | |
924 | self.ax.firsttime = True |
|
921 | self.ax.firsttime = True | |
925 |
|
922 | |||
926 |
|
923 | |||
927 | def plot(self): |
|
924 | def plot(self): | |
928 |
|
925 | |||
929 | arrayParameters = np.concatenate([self.data['param'][t] for t in self.times]) |
|
926 | arrayParameters = np.concatenate([self.data['param'][t] for t in self.times]) | |
930 | error = arrayParameters[:,-1] |
|
927 | error = arrayParameters[:,-1] | |
931 | indValid = numpy.where(error == 0)[0] |
|
928 | indValid = numpy.where(error == 0)[0] | |
932 | finalMeteor = arrayParameters[indValid,:] |
|
929 | finalMeteor = arrayParameters[indValid,:] | |
933 | finalAzimuth = finalMeteor[:,3] |
|
930 | finalAzimuth = finalMeteor[:,3] | |
934 | finalZenith = finalMeteor[:,4] |
|
931 | finalZenith = finalMeteor[:,4] | |
935 |
|
932 | |||
936 | x = finalAzimuth*numpy.pi/180 |
|
933 | x = finalAzimuth*numpy.pi/180 | |
937 | y = finalZenith |
|
934 | y = finalZenith | |
938 |
|
935 | |||
939 | if self.ax.firsttime: |
|
936 | if self.ax.firsttime: | |
940 | self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0] |
|
937 | self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0] | |
941 | self.ax.set_ylim(0,90) |
|
938 | self.ax.set_ylim(0,90) | |
942 | self.ax.set_yticks(numpy.arange(0,90,20)) |
|
939 | self.ax.set_yticks(numpy.arange(0,90,20)) | |
943 | self.ax.set_xlabel(self.xlabel) |
|
940 | self.ax.set_xlabel(self.xlabel) | |
944 | self.ax.set_ylabel(self.ylabel) |
|
941 | self.ax.set_ylabel(self.ylabel) | |
945 | self.ax.yaxis.labelpad = 40 |
|
942 | self.ax.yaxis.labelpad = 40 | |
946 | self.ax.firsttime = False |
|
943 | self.ax.firsttime = False | |
947 | else: |
|
944 | else: | |
948 | self.ax.plot.set_data(x, y) |
|
945 | self.ax.plot.set_data(x, y) | |
949 |
|
946 | |||
950 |
|
947 | |||
951 | dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
948 | dt1 = datetime.datetime.fromtimestamp(self.min_time).strftime('%y/%m/%d %H:%M:%S') | |
952 | dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
949 | dt2 = datetime.datetime.fromtimestamp(self.max_time).strftime('%y/%m/%d %H:%M:%S') | |
953 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
950 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |
954 | dt2, |
|
951 | dt2, | |
955 | len(x)) |
|
952 | len(x)) | |
956 | self.ax.set_title(title, size=8) |
|
953 | self.ax.set_title(title, size=8) | |
957 |
|
954 | |||
958 | self.saveTime = self.max_time |
|
955 | self.saveTime = self.max_time |
General Comments 0
You need to be logged in to leave comments.
Login now