##// END OF EJS Templates
Update plot parameters
jespinoza -
r1336:fc3be1cf6768
parent child
Show More
@@ -1,665 +1,665
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
1 # Copyright (c) 2012-2020 Jicamarca Radio Observatory
2 # All rights reserved.
2 # All rights reserved.
3 #
3 #
4 # Distributed under the terms of the BSD 3-clause license.
4 # Distributed under the terms of the BSD 3-clause license.
5 """Base class to create plot operations
5 """Base class to create plot operations
6
6
7 """
7 """
8
8
9 import os
9 import os
10 import sys
10 import sys
11 import zmq
11 import zmq
12 import time
12 import time
13 import numpy
13 import numpy
14 import datetime
14 import datetime
15 from multiprocessing import Queue
15 from multiprocessing import Queue
16 from functools import wraps
16 from functools import wraps
17 from threading import Thread
17 from threading import Thread
18 import matplotlib
18 import matplotlib
19
19
20 if 'BACKEND' in os.environ:
20 if 'BACKEND' in os.environ:
21 matplotlib.use(os.environ['BACKEND'])
21 matplotlib.use(os.environ['BACKEND'])
22 elif 'linux' in sys.platform:
22 elif 'linux' in sys.platform:
23 matplotlib.use("TkAgg")
23 matplotlib.use("TkAgg")
24 elif 'darwin' in sys.platform:
24 elif 'darwin' in sys.platform:
25 matplotlib.use('WxAgg')
25 matplotlib.use('WxAgg')
26 else:
26 else:
27 from schainpy.utils import log
27 from schainpy.utils import log
28 log.warning('Using default Backend="Agg"', 'INFO')
28 log.warning('Using default Backend="Agg"', 'INFO')
29 matplotlib.use('Agg')
29 matplotlib.use('Agg')
30
30
31 import matplotlib.pyplot as plt
31 import matplotlib.pyplot as plt
32 from matplotlib.patches import Polygon
32 from matplotlib.patches import Polygon
33 from mpl_toolkits.axes_grid1 import make_axes_locatable
33 from mpl_toolkits.axes_grid1 import make_axes_locatable
34 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
34 from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator
35
35
36 from schainpy.model.data.jrodata import PlotterData
36 from schainpy.model.data.jrodata import PlotterData
37 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
37 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator
38 from schainpy.utils import log
38 from schainpy.utils import log
39
39
40 jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90]
40 jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90]
41 blu_values = matplotlib.pyplot.get_cmap(
41 blu_values = matplotlib.pyplot.get_cmap(
42 'seismic_r', 20)(numpy.arange(20))[10:15]
42 'seismic_r', 20)(numpy.arange(20))[10:15]
43 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
43 ncmap = matplotlib.colors.LinearSegmentedColormap.from_list(
44 'jro', numpy.vstack((blu_values, jet_values)))
44 'jro', numpy.vstack((blu_values, jet_values)))
45 matplotlib.pyplot.register_cmap(cmap=ncmap)
45 matplotlib.pyplot.register_cmap(cmap=ncmap)
46
46
47 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis',
47 CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis',
48 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')]
48 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')]
49
49
50 EARTH_RADIUS = 6.3710e3
50 EARTH_RADIUS = 6.3710e3
51
51
52 def ll2xy(lat1, lon1, lat2, lon2):
52 def ll2xy(lat1, lon1, lat2, lon2):
53
53
54 p = 0.017453292519943295
54 p = 0.017453292519943295
55 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
55 a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \
56 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
56 numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2
57 r = 12742 * numpy.arcsin(numpy.sqrt(a))
57 r = 12742 * numpy.arcsin(numpy.sqrt(a))
58 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
58 theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p)
59 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
59 * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p))
60 theta = -theta + numpy.pi/2
60 theta = -theta + numpy.pi/2
61 return r*numpy.cos(theta), r*numpy.sin(theta)
61 return r*numpy.cos(theta), r*numpy.sin(theta)
62
62
63
63
64 def km2deg(km):
64 def km2deg(km):
65 '''
65 '''
66 Convert distance in km to degrees
66 Convert distance in km to degrees
67 '''
67 '''
68
68
69 return numpy.rad2deg(km/EARTH_RADIUS)
69 return numpy.rad2deg(km/EARTH_RADIUS)
70
70
71
71
72 def figpause(interval):
72 def figpause(interval):
73 backend = plt.rcParams['backend']
73 backend = plt.rcParams['backend']
74 if backend in matplotlib.rcsetup.interactive_bk:
74 if backend in matplotlib.rcsetup.interactive_bk:
75 figManager = matplotlib._pylab_helpers.Gcf.get_active()
75 figManager = matplotlib._pylab_helpers.Gcf.get_active()
76 if figManager is not None:
76 if figManager is not None:
77 canvas = figManager.canvas
77 canvas = figManager.canvas
78 if canvas.figure.stale:
78 if canvas.figure.stale:
79 canvas.draw()
79 canvas.draw()
80 try:
80 try:
81 canvas.start_event_loop(interval)
81 canvas.start_event_loop(interval)
82 except:
82 except:
83 pass
83 pass
84 return
84 return
85
85
86
86
87 def popup(message):
87 def popup(message):
88 '''
88 '''
89 '''
89 '''
90
90
91 fig = plt.figure(figsize=(12, 8), facecolor='r')
91 fig = plt.figure(figsize=(12, 8), facecolor='r')
92 text = '\n'.join([s.strip() for s in message.split(':')])
92 text = '\n'.join([s.strip() for s in message.split(':')])
93 fig.text(0.01, 0.5, text, ha='left', va='center',
93 fig.text(0.01, 0.5, text, ha='left', va='center',
94 size='20', weight='heavy', color='w')
94 size='20', weight='heavy', color='w')
95 fig.show()
95 fig.show()
96 figpause(1000)
96 figpause(1000)
97
97
98
98
99 class Throttle(object):
99 class Throttle(object):
100 '''
100 '''
101 Decorator that prevents a function from being called more than once every
101 Decorator that prevents a function from being called more than once every
102 time period.
102 time period.
103 To create a function that cannot be called more than once a minute, but
103 To create a function that cannot be called more than once a minute, but
104 will sleep until it can be called:
104 will sleep until it can be called:
105 @Throttle(minutes=1)
105 @Throttle(minutes=1)
106 def foo():
106 def foo():
107 pass
107 pass
108
108
109 for i in range(10):
109 for i in range(10):
110 foo()
110 foo()
111 print "This function has run %s times." % i
111 print "This function has run %s times." % i
112 '''
112 '''
113
113
114 def __init__(self, seconds=0, minutes=0, hours=0):
114 def __init__(self, seconds=0, minutes=0, hours=0):
115 self.throttle_period = datetime.timedelta(
115 self.throttle_period = datetime.timedelta(
116 seconds=seconds, minutes=minutes, hours=hours
116 seconds=seconds, minutes=minutes, hours=hours
117 )
117 )
118
118
119 self.time_of_last_call = datetime.datetime.min
119 self.time_of_last_call = datetime.datetime.min
120
120
121 def __call__(self, fn):
121 def __call__(self, fn):
122 @wraps(fn)
122 @wraps(fn)
123 def wrapper(*args, **kwargs):
123 def wrapper(*args, **kwargs):
124 coerce = kwargs.pop('coerce', None)
124 coerce = kwargs.pop('coerce', None)
125 if coerce:
125 if coerce:
126 self.time_of_last_call = datetime.datetime.now()
126 self.time_of_last_call = datetime.datetime.now()
127 return fn(*args, **kwargs)
127 return fn(*args, **kwargs)
128 else:
128 else:
129 now = datetime.datetime.now()
129 now = datetime.datetime.now()
130 time_since_last_call = now - self.time_of_last_call
130 time_since_last_call = now - self.time_of_last_call
131 time_left = self.throttle_period - time_since_last_call
131 time_left = self.throttle_period - time_since_last_call
132
132
133 if time_left > datetime.timedelta(seconds=0):
133 if time_left > datetime.timedelta(seconds=0):
134 return
134 return
135
135
136 self.time_of_last_call = datetime.datetime.now()
136 self.time_of_last_call = datetime.datetime.now()
137 return fn(*args, **kwargs)
137 return fn(*args, **kwargs)
138
138
139 return wrapper
139 return wrapper
140
140
141 def apply_throttle(value):
141 def apply_throttle(value):
142
142
143 @Throttle(seconds=value)
143 @Throttle(seconds=value)
144 def fnThrottled(fn):
144 def fnThrottled(fn):
145 fn()
145 fn()
146
146
147 return fnThrottled
147 return fnThrottled
148
148
149
149
150 @MPDecorator
150 @MPDecorator
151 class Plot(Operation):
151 class Plot(Operation):
152 """Base class for Schain plotting operations
152 """Base class for Schain plotting operations
153
153
154 This class should never be use directtly you must subclass a new operation,
154 This class should never be use directtly you must subclass a new operation,
155 children classes must be defined as follow:
155 children classes must be defined as follow:
156
156
157 ExamplePlot(Plot):
157 ExamplePlot(Plot):
158
158
159 CODE = 'code'
159 CODE = 'code'
160 colormap = 'jet'
160 colormap = 'jet'
161 plot_type = 'pcolor' # options are ('pcolor', 'pcolorbuffer', 'scatter', 'scatterbuffer')
161 plot_type = 'pcolor' # options are ('pcolor', 'pcolorbuffer', 'scatter', 'scatterbuffer')
162
162
163 def setup(self):
163 def setup(self):
164 pass
164 pass
165
165
166 def plot(self):
166 def plot(self):
167 pass
167 pass
168
168
169 """
169 """
170
170
171 CODE = 'Figure'
171 CODE = 'Figure'
172 colormap = 'jet'
172 colormap = 'jet'
173 bgcolor = 'white'
173 bgcolor = 'white'
174 buffering = True
174 buffering = True
175 __missing = 1E30
175 __missing = 1E30
176
176
177 __attrs__ = ['show', 'save', 'ymin', 'ymax', 'zmin', 'zmax', 'title',
177 __attrs__ = ['show', 'save', 'ymin', 'ymax', 'zmin', 'zmax', 'title',
178 'showprofile']
178 'showprofile']
179
179
180 def __init__(self):
180 def __init__(self):
181
181
182 Operation.__init__(self)
182 Operation.__init__(self)
183 self.isConfig = False
183 self.isConfig = False
184 self.isPlotConfig = False
184 self.isPlotConfig = False
185 self.save_time = 0
185 self.save_time = 0
186 self.sender_time = 0
186 self.sender_time = 0
187 self.data = None
187 self.data = None
188 self.firsttime = True
188 self.firsttime = True
189 self.sender_queue = Queue(maxsize=60)
189 self.sender_queue = Queue(maxsize=60)
190 self.plots_adjust = {'left': 0.125, 'right': 0.9, 'bottom': 0.15, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2}
190 self.plots_adjust = {'left': 0.125, 'right': 0.9, 'bottom': 0.15, 'top': 0.9, 'wspace': 0.2, 'hspace': 0.2}
191
191
192 def __fmtTime(self, x, pos):
192 def __fmtTime(self, x, pos):
193 '''
193 '''
194 '''
194 '''
195
195
196 return '{}'.format(self.getDateTime(x).strftime('%H:%M'))
196 return '{}'.format(self.getDateTime(x).strftime('%H:%M'))
197
197
198 def __setup(self, **kwargs):
198 def __setup(self, **kwargs):
199 '''
199 '''
200 Initialize variables
200 Initialize variables
201 '''
201 '''
202
202
203 self.figures = []
203 self.figures = []
204 self.axes = []
204 self.axes = []
205 self.cb_axes = []
205 self.cb_axes = []
206 self.localtime = kwargs.pop('localtime', True)
206 self.localtime = kwargs.pop('localtime', True)
207 self.show = kwargs.get('show', True)
207 self.show = kwargs.get('show', True)
208 self.save = kwargs.get('save', False)
208 self.save = kwargs.get('save', False)
209 self.save_period = kwargs.get('save_period', 60)
209 self.save_period = kwargs.get('save_period', 0)
210 self.colormap = kwargs.get('colormap', self.colormap)
210 self.colormap = kwargs.get('colormap', self.colormap)
211 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
211 self.colormap_coh = kwargs.get('colormap_coh', 'jet')
212 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
212 self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r')
213 self.colormaps = kwargs.get('colormaps', None)
213 self.colormaps = kwargs.get('colormaps', None)
214 self.bgcolor = kwargs.get('bgcolor', self.bgcolor)
214 self.bgcolor = kwargs.get('bgcolor', self.bgcolor)
215 self.showprofile = kwargs.get('showprofile', False)
215 self.showprofile = kwargs.get('showprofile', False)
216 self.title = kwargs.get('wintitle', self.CODE.upper())
216 self.title = kwargs.get('wintitle', self.CODE.upper())
217 self.cb_label = kwargs.get('cb_label', None)
217 self.cb_label = kwargs.get('cb_label', None)
218 self.cb_labels = kwargs.get('cb_labels', None)
218 self.cb_labels = kwargs.get('cb_labels', None)
219 self.labels = kwargs.get('labels', None)
219 self.labels = kwargs.get('labels', None)
220 self.xaxis = kwargs.get('xaxis', 'frequency')
220 self.xaxis = kwargs.get('xaxis', 'frequency')
221 self.zmin = kwargs.get('zmin', None)
221 self.zmin = kwargs.get('zmin', None)
222 self.zmax = kwargs.get('zmax', None)
222 self.zmax = kwargs.get('zmax', None)
223 self.zlimits = kwargs.get('zlimits', None)
223 self.zlimits = kwargs.get('zlimits', None)
224 self.xmin = kwargs.get('xmin', None)
224 self.xmin = kwargs.get('xmin', None)
225 self.xmax = kwargs.get('xmax', None)
225 self.xmax = kwargs.get('xmax', None)
226 self.xrange = kwargs.get('xrange', 12)
226 self.xrange = kwargs.get('xrange', 12)
227 self.xscale = kwargs.get('xscale', None)
227 self.xscale = kwargs.get('xscale', None)
228 self.ymin = kwargs.get('ymin', None)
228 self.ymin = kwargs.get('ymin', None)
229 self.ymax = kwargs.get('ymax', None)
229 self.ymax = kwargs.get('ymax', None)
230 self.yscale = kwargs.get('yscale', None)
230 self.yscale = kwargs.get('yscale', None)
231 self.xlabel = kwargs.get('xlabel', None)
231 self.xlabel = kwargs.get('xlabel', None)
232 self.attr_time = kwargs.get('attr_time', 'utctime')
232 self.attr_time = kwargs.get('attr_time', 'utctime')
233 self.decimation = kwargs.get('decimation', None)
233 self.decimation = kwargs.get('decimation', None)
234 self.showSNR = kwargs.get('showSNR', False)
234 self.showSNR = kwargs.get('showSNR', False)
235 self.oneFigure = kwargs.get('oneFigure', True)
235 self.oneFigure = kwargs.get('oneFigure', True)
236 self.width = kwargs.get('width', None)
236 self.width = kwargs.get('width', None)
237 self.height = kwargs.get('height', None)
237 self.height = kwargs.get('height', None)
238 self.colorbar = kwargs.get('colorbar', True)
238 self.colorbar = kwargs.get('colorbar', True)
239 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
239 self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1])
240 self.channels = kwargs.get('channels', None)
240 self.channels = kwargs.get('channels', None)
241 self.titles = kwargs.get('titles', [])
241 self.titles = kwargs.get('titles', [])
242 self.polar = False
242 self.polar = False
243 self.type = kwargs.get('type', 'iq')
243 self.type = kwargs.get('type', 'iq')
244 self.grid = kwargs.get('grid', False)
244 self.grid = kwargs.get('grid', False)
245 self.pause = kwargs.get('pause', False)
245 self.pause = kwargs.get('pause', False)
246 self.save_code = kwargs.get('save_code', self.CODE)
246 self.save_code = kwargs.get('save_code', self.CODE)
247 self.throttle = kwargs.get('throttle', 0)
247 self.throttle = kwargs.get('throttle', 0)
248 self.exp_code = kwargs.get('exp_code', None)
248 self.exp_code = kwargs.get('exp_code', None)
249 self.plot_server = kwargs.get('plot_server', False)
249 self.server = kwargs.get('server', False)
250 self.sender_period = kwargs.get('sender_period', 60)
250 self.sender_period = kwargs.get('sender_period', 60)
251 self.tag = kwargs.get('tag', '')
251 self.tag = kwargs.get('tag', '')
252 self.height_index = kwargs.get('height_index', None)
252 self.height_index = kwargs.get('height_index', None)
253 self.__throttle_plot = apply_throttle(self.throttle)
253 self.__throttle_plot = apply_throttle(self.throttle)
254 self.data = PlotterData(
254 self.data = PlotterData(
255 self.CODE, self.throttle, self.exp_code, self.localtime, self.buffering, snr=self.showSNR)
255 self.CODE, self.throttle, self.exp_code, self.localtime, self.buffering, snr=self.showSNR)
256
256
257 if self.plot_server:
257 if self.server:
258 if not self.plot_server.startswith('tcp://'):
258 if not self.server.startswith('tcp://'):
259 self.plot_server = 'tcp://{}'.format(self.plot_server)
259 self.server = 'tcp://{}'.format(self.server)
260 log.success(
260 log.success(
261 'Sending to server: {}'.format(self.plot_server),
261 'Sending to server: {}'.format(self.server),
262 self.name
262 self.name
263 )
263 )
264
264
265 def __setup_plot(self):
265 def __setup_plot(self):
266 '''
266 '''
267 Common setup for all figures, here figures and axes are created
267 Common setup for all figures, here figures and axes are created
268 '''
268 '''
269
269
270 self.setup()
270 self.setup()
271
271
272 self.time_label = 'LT' if self.localtime else 'UTC'
272 self.time_label = 'LT' if self.localtime else 'UTC'
273
273
274 if self.width is None:
274 if self.width is None:
275 self.width = 8
275 self.width = 8
276
276
277 self.figures = []
277 self.figures = []
278 self.axes = []
278 self.axes = []
279 self.cb_axes = []
279 self.cb_axes = []
280 self.pf_axes = []
280 self.pf_axes = []
281 self.cmaps = []
281 self.cmaps = []
282
282
283 size = '15%' if self.ncols == 1 else '30%'
283 size = '15%' if self.ncols == 1 else '30%'
284 pad = '4%' if self.ncols == 1 else '8%'
284 pad = '4%' if self.ncols == 1 else '8%'
285
285
286 if self.oneFigure:
286 if self.oneFigure:
287 if self.height is None:
287 if self.height is None:
288 self.height = 1.4 * self.nrows + 1
288 self.height = 1.4 * self.nrows + 1
289 fig = plt.figure(figsize=(self.width, self.height),
289 fig = plt.figure(figsize=(self.width, self.height),
290 edgecolor='k',
290 edgecolor='k',
291 facecolor='w')
291 facecolor='w')
292 self.figures.append(fig)
292 self.figures.append(fig)
293 for n in range(self.nplots):
293 for n in range(self.nplots):
294 ax = fig.add_subplot(self.nrows, self.ncols,
294 ax = fig.add_subplot(self.nrows, self.ncols,
295 n + 1, polar=self.polar)
295 n + 1, polar=self.polar)
296 ax.tick_params(labelsize=8)
296 ax.tick_params(labelsize=8)
297 ax.firsttime = True
297 ax.firsttime = True
298 ax.index = 0
298 ax.index = 0
299 ax.press = None
299 ax.press = None
300 self.axes.append(ax)
300 self.axes.append(ax)
301 if self.showprofile:
301 if self.showprofile:
302 cax = self.__add_axes(ax, size=size, pad=pad)
302 cax = self.__add_axes(ax, size=size, pad=pad)
303 cax.tick_params(labelsize=8)
303 cax.tick_params(labelsize=8)
304 self.pf_axes.append(cax)
304 self.pf_axes.append(cax)
305 else:
305 else:
306 if self.height is None:
306 if self.height is None:
307 self.height = 3
307 self.height = 3
308 for n in range(self.nplots):
308 for n in range(self.nplots):
309 fig = plt.figure(figsize=(self.width, self.height),
309 fig = plt.figure(figsize=(self.width, self.height),
310 edgecolor='k',
310 edgecolor='k',
311 facecolor='w')
311 facecolor='w')
312 ax = fig.add_subplot(1, 1, 1, polar=self.polar)
312 ax = fig.add_subplot(1, 1, 1, polar=self.polar)
313 ax.tick_params(labelsize=8)
313 ax.tick_params(labelsize=8)
314 ax.firsttime = True
314 ax.firsttime = True
315 ax.index = 0
315 ax.index = 0
316 ax.press = None
316 ax.press = None
317 self.figures.append(fig)
317 self.figures.append(fig)
318 self.axes.append(ax)
318 self.axes.append(ax)
319 if self.showprofile:
319 if self.showprofile:
320 cax = self.__add_axes(ax, size=size, pad=pad)
320 cax = self.__add_axes(ax, size=size, pad=pad)
321 cax.tick_params(labelsize=8)
321 cax.tick_params(labelsize=8)
322 self.pf_axes.append(cax)
322 self.pf_axes.append(cax)
323
323
324 for n in range(self.nrows):
324 for n in range(self.nrows):
325 if self.colormaps is not None:
325 if self.colormaps is not None:
326 cmap = plt.get_cmap(self.colormaps[n])
326 cmap = plt.get_cmap(self.colormaps[n])
327 else:
327 else:
328 cmap = plt.get_cmap(self.colormap)
328 cmap = plt.get_cmap(self.colormap)
329 cmap.set_bad(self.bgcolor, 1.)
329 cmap.set_bad(self.bgcolor, 1.)
330 self.cmaps.append(cmap)
330 self.cmaps.append(cmap)
331
331
332 def __add_axes(self, ax, size='30%', pad='8%'):
332 def __add_axes(self, ax, size='30%', pad='8%'):
333 '''
333 '''
334 Add new axes to the given figure
334 Add new axes to the given figure
335 '''
335 '''
336 divider = make_axes_locatable(ax)
336 divider = make_axes_locatable(ax)
337 nax = divider.new_horizontal(size=size, pad=pad)
337 nax = divider.new_horizontal(size=size, pad=pad)
338 ax.figure.add_axes(nax)
338 ax.figure.add_axes(nax)
339 return nax
339 return nax
340
340
341 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
341 def fill_gaps(self, x_buffer, y_buffer, z_buffer):
342 '''
342 '''
343 Create a masked array for missing data
343 Create a masked array for missing data
344 '''
344 '''
345 if x_buffer.shape[0] < 2:
345 if x_buffer.shape[0] < 2:
346 return x_buffer, y_buffer, z_buffer
346 return x_buffer, y_buffer, z_buffer
347
347
348 deltas = x_buffer[1:] - x_buffer[0:-1]
348 deltas = x_buffer[1:] - x_buffer[0:-1]
349 x_median = numpy.median(deltas)
349 x_median = numpy.median(deltas)
350
350
351 index = numpy.where(deltas > 5 * x_median)
351 index = numpy.where(deltas > 5 * x_median)
352
352
353 if len(index[0]) != 0:
353 if len(index[0]) != 0:
354 z_buffer[::, index[0], ::] = self.__missing
354 z_buffer[::, index[0], ::] = self.__missing
355 z_buffer = numpy.ma.masked_inside(z_buffer,
355 z_buffer = numpy.ma.masked_inside(z_buffer,
356 0.99 * self.__missing,
356 0.99 * self.__missing,
357 1.01 * self.__missing)
357 1.01 * self.__missing)
358
358
359 return x_buffer, y_buffer, z_buffer
359 return x_buffer, y_buffer, z_buffer
360
360
361 def decimate(self):
361 def decimate(self):
362
362
363 # dx = int(len(self.x)/self.__MAXNUMX) + 1
363 # dx = int(len(self.x)/self.__MAXNUMX) + 1
364 dy = int(len(self.y) / self.decimation) + 1
364 dy = int(len(self.y) / self.decimation) + 1
365
365
366 # x = self.x[::dx]
366 # x = self.x[::dx]
367 x = self.x
367 x = self.x
368 y = self.y[::dy]
368 y = self.y[::dy]
369 z = self.z[::, ::, ::dy]
369 z = self.z[::, ::, ::dy]
370
370
371 return x, y, z
371 return x, y, z
372
372
373 def format(self):
373 def format(self):
374 '''
374 '''
375 Set min and max values, labels, ticks and titles
375 Set min and max values, labels, ticks and titles
376 '''
376 '''
377
377
378 for n, ax in enumerate(self.axes):
378 for n, ax in enumerate(self.axes):
379 if ax.firsttime:
379 if ax.firsttime:
380 if self.xaxis != 'time':
380 if self.xaxis != 'time':
381 xmin = self.xmin
381 xmin = self.xmin
382 xmax = self.xmax
382 xmax = self.xmax
383 else:
383 else:
384 xmin = self.tmin
384 xmin = self.tmin
385 xmax = self.tmin + self.xrange*60*60
385 xmax = self.tmin + self.xrange*60*60
386 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime))
386 ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime))
387 ax.xaxis.set_major_locator(LinearLocator(9))
387 ax.xaxis.set_major_locator(LinearLocator(9))
388 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
388 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
389 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
389 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
390 ax.set_facecolor(self.bgcolor)
390 ax.set_facecolor(self.bgcolor)
391 if self.xscale:
391 if self.xscale:
392 ax.xaxis.set_major_formatter(FuncFormatter(
392 ax.xaxis.set_major_formatter(FuncFormatter(
393 lambda x, pos: '{0:g}'.format(x*self.xscale)))
393 lambda x, pos: '{0:g}'.format(x*self.xscale)))
394 if self.yscale:
394 if self.yscale:
395 ax.yaxis.set_major_formatter(FuncFormatter(
395 ax.yaxis.set_major_formatter(FuncFormatter(
396 lambda x, pos: '{0:g}'.format(x*self.yscale)))
396 lambda x, pos: '{0:g}'.format(x*self.yscale)))
397 if self.xlabel is not None:
397 if self.xlabel is not None:
398 ax.set_xlabel(self.xlabel)
398 ax.set_xlabel(self.xlabel)
399 if self.ylabel is not None:
399 if self.ylabel is not None:
400 ax.set_ylabel(self.ylabel)
400 ax.set_ylabel(self.ylabel)
401 if self.showprofile:
401 if self.showprofile:
402 self.pf_axes[n].set_ylim(ymin, ymax)
402 self.pf_axes[n].set_ylim(ymin, ymax)
403 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
403 self.pf_axes[n].set_xlim(self.zmin, self.zmax)
404 self.pf_axes[n].set_xlabel('dB')
404 self.pf_axes[n].set_xlabel('dB')
405 self.pf_axes[n].grid(b=True, axis='x')
405 self.pf_axes[n].grid(b=True, axis='x')
406 [tick.set_visible(False)
406 [tick.set_visible(False)
407 for tick in self.pf_axes[n].get_yticklabels()]
407 for tick in self.pf_axes[n].get_yticklabels()]
408 if self.colorbar:
408 if self.colorbar:
409 ax.cbar = plt.colorbar(
409 ax.cbar = plt.colorbar(
410 ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10)
410 ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10)
411 ax.cbar.ax.tick_params(labelsize=8)
411 ax.cbar.ax.tick_params(labelsize=8)
412 ax.cbar.ax.press = None
412 ax.cbar.ax.press = None
413 if self.cb_label:
413 if self.cb_label:
414 ax.cbar.set_label(self.cb_label, size=8)
414 ax.cbar.set_label(self.cb_label, size=8)
415 elif self.cb_labels:
415 elif self.cb_labels:
416 ax.cbar.set_label(self.cb_labels[n], size=8)
416 ax.cbar.set_label(self.cb_labels[n], size=8)
417 else:
417 else:
418 ax.cbar = None
418 ax.cbar = None
419 ax.set_xlim(xmin, xmax)
419 ax.set_xlim(xmin, xmax)
420 ax.set_ylim(ymin, ymax)
420 ax.set_ylim(ymin, ymax)
421 ax.firsttime = False
421 ax.firsttime = False
422 if self.grid:
422 if self.grid:
423 ax.grid(True)
423 ax.grid(True)
424 if not self.polar:
424 if not self.polar:
425 ax.set_title('{} {} {}'.format(
425 ax.set_title('{} {} {}'.format(
426 self.titles[n],
426 self.titles[n],
427 self.getDateTime(self.data.max_time).strftime(
427 self.getDateTime(self.data.max_time).strftime(
428 '%Y-%m-%d %H:%M:%S'),
428 '%Y-%m-%d %H:%M:%S'),
429 self.time_label),
429 self.time_label),
430 size=8)
430 size=8)
431 else:
431 else:
432 ax.set_title('{}'.format(self.titles[n]), size=8)
432 ax.set_title('{}'.format(self.titles[n]), size=8)
433 ax.set_ylim(0, 90)
433 ax.set_ylim(0, 90)
434 ax.set_yticks(numpy.arange(0, 90, 20))
434 ax.set_yticks(numpy.arange(0, 90, 20))
435 ax.yaxis.labelpad = 40
435 ax.yaxis.labelpad = 40
436
436
437 if self.firsttime:
437 if self.firsttime:
438 for n, fig in enumerate(self.figures):
438 for n, fig in enumerate(self.figures):
439 fig.subplots_adjust(**self.plots_adjust)
439 fig.subplots_adjust(**self.plots_adjust)
440 self.firsttime = False
440 self.firsttime = False
441
441
442 def clear_figures(self):
442 def clear_figures(self):
443 '''
443 '''
444 Reset axes for redraw plots
444 Reset axes for redraw plots
445 '''
445 '''
446
446
447 for ax in self.axes+self.pf_axes+self.cb_axes:
447 for ax in self.axes+self.pf_axes+self.cb_axes:
448 ax.clear()
448 ax.clear()
449 ax.firsttime = True
449 ax.firsttime = True
450 if hasattr(ax, 'cbar') and ax.cbar:
450 if hasattr(ax, 'cbar') and ax.cbar:
451 ax.cbar.remove()
451 ax.cbar.remove()
452
452
453 def __plot(self):
453 def __plot(self):
454 '''
454 '''
455 Main function to plot, format and save figures
455 Main function to plot, format and save figures
456 '''
456 '''
457
457
458 self.plot()
458 self.plot()
459 self.format()
459 self.format()
460
460
461 for n, fig in enumerate(self.figures):
461 for n, fig in enumerate(self.figures):
462 if self.nrows == 0 or self.nplots == 0:
462 if self.nrows == 0 or self.nplots == 0:
463 log.warning('No data', self.name)
463 log.warning('No data', self.name)
464 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
464 fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center')
465 fig.canvas.manager.set_window_title(self.CODE)
465 fig.canvas.manager.set_window_title(self.CODE)
466 continue
466 continue
467
467
468 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
468 fig.canvas.manager.set_window_title('{} - {}'.format(self.title,
469 self.getDateTime(self.data.max_time).strftime('%Y/%m/%d')))
469 self.getDateTime(self.data.max_time).strftime('%Y/%m/%d')))
470 fig.canvas.draw()
470 fig.canvas.draw()
471 if self.show:
471 if self.show:
472 fig.show()
472 fig.show()
473 figpause(0.01)
473 figpause(0.01)
474
474
475 if self.save:
475 if self.save:
476 self.save_figure(n)
476 self.save_figure(n)
477
477
478 if self.plot_server:
478 if self.server:
479 self.send_to_server()
479 self.send_to_server()
480
480
481 def save_figure(self, n):
481 def save_figure(self, n):
482 '''
482 '''
483 '''
483 '''
484
484
485 if (self.data.tm - self.save_time) < self.sender_period:
485 if (self.data.tm - self.save_time) <= self.save_period:
486 return
486 return
487
487
488 self.save_time = self.data.tm
488 self.save_time = self.data.tm
489
489
490 fig = self.figures[n]
490 fig = self.figures[n]
491
491
492 figname = os.path.join(
492 figname = os.path.join(
493 self.save,
493 self.save,
494 self.save_code,
494 self.save_code,
495 '{}_{}.png'.format(
495 '{}_{}.png'.format(
496 self.save_code,
496 self.save_code,
497 self.getDateTime(self.data.max_time).strftime(
497 self.getDateTime(self.data.max_time).strftime(
498 '%Y%m%d_%H%M%S'
498 '%Y%m%d_%H%M%S'
499 ),
499 ),
500 )
500 )
501 )
501 )
502 log.log('Saving figure: {}'.format(figname), self.name)
502 log.log('Saving figure: {}'.format(figname), self.name)
503 if not os.path.isdir(os.path.dirname(figname)):
503 if not os.path.isdir(os.path.dirname(figname)):
504 os.makedirs(os.path.dirname(figname))
504 os.makedirs(os.path.dirname(figname))
505 fig.savefig(figname)
505 fig.savefig(figname)
506
506
507 if self.throttle == 0:
507 if self.throttle == 0:
508 figname = os.path.join(
508 figname = os.path.join(
509 self.save,
509 self.save,
510 '{}_{}.png'.format(
510 '{}_{}.png'.format(
511 self.save_code,
511 self.save_code,
512 self.getDateTime(self.data.min_time).strftime(
512 self.getDateTime(self.data.min_time).strftime(
513 '%Y%m%d'
513 '%Y%m%d'
514 ),
514 ),
515 )
515 )
516 )
516 )
517 fig.savefig(figname)
517 fig.savefig(figname)
518
518
519 def send_to_server(self):
519 def send_to_server(self):
520 '''
520 '''
521 '''
521 '''
522
522
523 interval = self.data.tm - self.sender_time
523 interval = self.data.tm - self.sender_time
524 if interval < self.sender_period:
524 if interval < self.sender_period:
525 return
525 return
526
526
527 self.sender_time = self.data.tm
527 self.sender_time = self.data.tm
528
528
529 attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax']
529 attrs = ['titles', 'zmin', 'zmax', 'tag', 'ymin', 'ymax']
530 for attr in attrs:
530 for attr in attrs:
531 value = getattr(self, attr)
531 value = getattr(self, attr)
532 if value:
532 if value:
533 if isinstance(value, (numpy.float32, numpy.float64)):
533 if isinstance(value, (numpy.float32, numpy.float64)):
534 value = round(float(value), 2)
534 value = round(float(value), 2)
535 self.data.meta[attr] = value
535 self.data.meta[attr] = value
536 if self.colormap == 'jet':
536 if self.colormap == 'jet':
537 self.data.meta['colormap'] = 'Jet'
537 self.data.meta['colormap'] = 'Jet'
538 elif 'RdBu' in self.colormap:
538 elif 'RdBu' in self.colormap:
539 self.data.meta['colormap'] = 'RdBu'
539 self.data.meta['colormap'] = 'RdBu'
540 else:
540 else:
541 self.data.meta['colormap'] = 'Viridis'
541 self.data.meta['colormap'] = 'Viridis'
542 self.data.meta['interval'] = int(interval)
542 self.data.meta['interval'] = int(interval)
543
543
544 try:
544 try:
545 self.sender_queue.put(self.data.tm, block=False)
545 self.sender_queue.put(self.data.tm, block=False)
546 except:
546 except:
547 tm = self.sender_queue.get()
547 tm = self.sender_queue.get()
548 self.sender_queue.put(self.data.tm)
548 self.sender_queue.put(self.data.tm)
549
549
550 while True:
550 while True:
551 if self.sender_queue.empty():
551 if self.sender_queue.empty():
552 break
552 break
553 tm = self.sender_queue.get()
553 tm = self.sender_queue.get()
554 try:
554 try:
555 msg = self.data.jsonify(tm, self.save_code, self.plot_type)
555 msg = self.data.jsonify(tm, self.save_code, self.plot_type)
556 except:
556 except:
557 continue
557 continue
558 self.socket.send_string(msg)
558 self.socket.send_string(msg)
559 socks = dict(self.poll.poll(5000))
559 socks = dict(self.poll.poll(5000))
560 if socks.get(self.socket) == zmq.POLLIN:
560 if socks.get(self.socket) == zmq.POLLIN:
561 reply = self.socket.recv_string()
561 reply = self.socket.recv_string()
562 if reply == 'ok':
562 if reply == 'ok':
563 log.log("Response from server ok", self.name)
563 log.log("Response from server ok", self.name)
564 time.sleep(0.2)
564 time.sleep(0.2)
565 continue
565 continue
566 else:
566 else:
567 log.warning(
567 log.warning(
568 "Malformed reply from server: {}".format(reply), self.name)
568 "Malformed reply from server: {}".format(reply), self.name)
569 else:
569 else:
570 log.warning(
570 log.warning(
571 "No response from server, retrying...", self.name)
571 "No response from server, retrying...", self.name)
572 self.sender_queue.put(self.data.tm)
572 self.sender_queue.put(self.data.tm)
573 self.socket.setsockopt(zmq.LINGER, 0)
573 self.socket.setsockopt(zmq.LINGER, 0)
574 self.socket.close()
574 self.socket.close()
575 self.poll.unregister(self.socket)
575 self.poll.unregister(self.socket)
576 time.sleep(0.1)
576 time.sleep(0.1)
577 self.socket = self.context.socket(zmq.REQ)
577 self.socket = self.context.socket(zmq.REQ)
578 self.socket.connect(self.plot_server)
578 self.socket.connect(self.server)
579 self.poll.register(self.socket, zmq.POLLIN)
579 self.poll.register(self.socket, zmq.POLLIN)
580 break
580 break
581
581
582 def setup(self):
582 def setup(self):
583 '''
583 '''
584 This method should be implemented in the child class, the following
584 This method should be implemented in the child class, the following
585 attributes should be set:
585 attributes should be set:
586
586
587 self.nrows: number of rows
587 self.nrows: number of rows
588 self.ncols: number of cols
588 self.ncols: number of cols
589 self.nplots: number of plots (channels or pairs)
589 self.nplots: number of plots (channels or pairs)
590 self.ylabel: label for Y axes
590 self.ylabel: label for Y axes
591 self.titles: list of axes title
591 self.titles: list of axes title
592
592
593 '''
593 '''
594 raise NotImplementedError
594 raise NotImplementedError
595
595
596 def plot(self):
596 def plot(self):
597 '''
597 '''
598 Must be defined in the child class
598 Must be defined in the child class
599 '''
599 '''
600 raise NotImplementedError
600 raise NotImplementedError
601
601
602 def run(self, dataOut, **kwargs):
602 def run(self, dataOut, **kwargs):
603 '''
603 '''
604 Main plotting routine
604 Main plotting routine
605 '''
605 '''
606
606
607 if self.isConfig is False:
607 if self.isConfig is False:
608 self.__setup(**kwargs)
608 self.__setup(**kwargs)
609
609
610 if self.localtime:
610 if self.localtime:
611 self.getDateTime = datetime.datetime.fromtimestamp
611 self.getDateTime = datetime.datetime.fromtimestamp
612 else:
612 else:
613 self.getDateTime = datetime.datetime.utcfromtimestamp
613 self.getDateTime = datetime.datetime.utcfromtimestamp
614
614
615 self.data.setup()
615 self.data.setup()
616 self.isConfig = True
616 self.isConfig = True
617 if self.plot_server:
617 if self.server:
618 self.context = zmq.Context()
618 self.context = zmq.Context()
619 self.socket = self.context.socket(zmq.REQ)
619 self.socket = self.context.socket(zmq.REQ)
620 self.socket.connect(self.plot_server)
620 self.socket.connect(self.server)
621 self.poll = zmq.Poller()
621 self.poll = zmq.Poller()
622 self.poll.register(self.socket, zmq.POLLIN)
622 self.poll.register(self.socket, zmq.POLLIN)
623
623
624 tm = getattr(dataOut, self.attr_time)
624 tm = getattr(dataOut, self.attr_time)
625
625
626 if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60:
626 if self.data and 'time' in self.xaxis and (tm - self.tmin) >= self.xrange*60*60:
627 self.save_counter = self.save_period
627 self.save_time = tm
628 self.__plot()
628 self.__plot()
629 self.tmin += self.xrange*60*60
629 self.tmin += self.xrange*60*60
630 self.data.setup()
630 self.data.setup()
631 self.clear_figures()
631 self.clear_figures()
632
632
633 self.data.update(dataOut, tm)
633 self.data.update(dataOut, tm)
634
634
635 if self.isPlotConfig is False:
635 if self.isPlotConfig is False:
636 self.__setup_plot()
636 self.__setup_plot()
637 self.isPlotConfig = True
637 self.isPlotConfig = True
638 if self.xaxis == 'time':
638 if self.xaxis == 'time':
639 dt = self.getDateTime(tm)
639 dt = self.getDateTime(tm)
640 if self.xmin is None:
640 if self.xmin is None:
641 self.tmin = tm
641 self.tmin = tm
642 self.xmin = dt.hour
642 self.xmin = dt.hour
643 minutes = (self.xmin-int(self.xmin)) * 60
643 minutes = (self.xmin-int(self.xmin)) * 60
644 seconds = (minutes - int(minutes)) * 60
644 seconds = (minutes - int(minutes)) * 60
645 self.tmin = (dt.replace(hour=int(self.xmin), minute=int(minutes), second=int(seconds)) -
645 self.tmin = (dt.replace(hour=int(self.xmin), minute=int(minutes), second=int(seconds)) -
646 datetime.datetime(1970, 1, 1)).total_seconds()
646 datetime.datetime(1970, 1, 1)).total_seconds()
647 if self.localtime:
647 if self.localtime:
648 self.tmin += time.timezone
648 self.tmin += time.timezone
649
649
650 if self.xmin is not None and self.xmax is not None:
650 if self.xmin is not None and self.xmax is not None:
651 self.xrange = self.xmax - self.xmin
651 self.xrange = self.xmax - self.xmin
652
652
653 if self.throttle == 0:
653 if self.throttle == 0:
654 self.__plot()
654 self.__plot()
655 else:
655 else:
656 self.__throttle_plot(self.__plot)#, coerce=coerce)
656 self.__throttle_plot(self.__plot)#, coerce=coerce)
657
657
658 def close(self):
658 def close(self):
659
659
660 if self.data and not self.data.flagNoData:
660 if self.data and not self.data.flagNoData:
661 self.save_counter = self.save_period
661 self.save_time = self.data.tm
662 self.__plot()
662 self.__plot()
663 if self.data and not self.data.flagNoData and self.pause:
663 if self.data and not self.data.flagNoData and self.pause:
664 figpause(10)
664 figpause(10)
665
665
@@ -1,187 +1,187
1 import os
1 import os
2 import datetime
2 import datetime
3 import numpy
3 import numpy
4 import copy
4 import copy
5 from schainpy.model.graphics.jroplot_base import Plot
5 from schainpy.model.graphics.jroplot_base import Plot
6
6
7
7
8 class CorrelationPlot(Plot):
8 class CorrelationPlot(Plot):
9 isConfig = None
9 isConfig = None
10 __nsubplots = None
10 __nsubplots = None
11
11
12 WIDTHPROF = None
12 WIDTHPROF = None
13 HEIGHTPROF = None
13 HEIGHTPROF = None
14 PREFIX = 'corr'
14 PREFIX = 'corr'
15
15
16 def __init__(self, **kwargs):
16 def __init__(self, **kwargs):
17 Figure.__init__(self, **kwargs)
17 Figure.__init__(self, **kwargs)
18 self.isConfig = False
18 self.isConfig = False
19 self.__nsubplots = 1
19 self.__nsubplots = 1
20
20
21 self.WIDTH = 280
21 self.WIDTH = 280
22 self.HEIGHT = 250
22 self.HEIGHT = 250
23 self.WIDTHPROF = 120
23 self.WIDTHPROF = 120
24 self.HEIGHTPROF = 0
24 self.HEIGHTPROF = 0
25 self.counter_imagwr = 0
25 self.counter_imagwr = 0
26
26
27 self.PLOT_CODE = 1
27 self.PLOT_CODE = 1
28 self.FTP_WEI = None
28 self.FTP_WEI = None
29 self.EXP_CODE = None
29 self.EXP_CODE = None
30 self.SUB_EXP_CODE = None
30 self.SUB_EXP_CODE = None
31 self.PLOT_POS = None
31 self.PLOT_POS = None
32
32
33 def getSubplots(self):
33 def getSubplots(self):
34
34
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
35 ncol = int(numpy.sqrt(self.nplots)+0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
36 nrow = int(self.nplots*1./ncol + 0.9)
37
37
38 return nrow, ncol
38 return nrow, ncol
39
39
40 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
40 def setup(self, id, nplots, wintitle, showprofile=False, show=True):
41
41
42 showprofile = False
42 showprofile = False
43 self.__showprofile = showprofile
43 self.__showprofile = showprofile
44 self.nplots = nplots
44 self.nplots = nplots
45
45
46 ncolspan = 1
46 ncolspan = 1
47 colspan = 1
47 colspan = 1
48 if showprofile:
48 if showprofile:
49 ncolspan = 3
49 ncolspan = 3
50 colspan = 2
50 colspan = 2
51 self.__nsubplots = 2
51 self.__nsubplots = 2
52
52
53 self.createFigure(id = id,
53 self.createFigure(id = id,
54 wintitle = wintitle,
54 wintitle = wintitle,
55 widthplot = self.WIDTH + self.WIDTHPROF,
55 widthplot = self.WIDTH + self.WIDTHPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
56 heightplot = self.HEIGHT + self.HEIGHTPROF,
57 show=show)
57 show=show)
58
58
59 nrow, ncol = self.getSubplots()
59 nrow, ncol = self.getSubplots()
60
60
61 counter = 0
61 counter = 0
62 for y in range(nrow):
62 for y in range(nrow):
63 for x in range(ncol):
63 for x in range(ncol):
64
64
65 if counter >= self.nplots:
65 if counter >= self.nplots:
66 break
66 break
67
67
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
68 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
69
69
70 if showprofile:
70 if showprofile:
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
71 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
72
72
73 counter += 1
73 counter += 1
74
74
75 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
75 def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False,
76 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
76 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
77 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
77 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
78 server=None, folder=None, username=None, password=None,
78 server=None, folder=None, username=None, password=None,
79 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
79 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False):
80
80
81 """
81 """
82
82
83 Input:
83 Input:
84 dataOut :
84 dataOut :
85 id :
85 id :
86 wintitle :
86 wintitle :
87 channelList :
87 channelList :
88 showProfile :
88 showProfile :
89 xmin : None,
89 xmin : None,
90 xmax : None,
90 xmax : None,
91 ymin : None,
91 ymin : None,
92 ymax : None,
92 ymax : None,
93 zmin : None,
93 zmin : None,
94 zmax : None
94 zmax : None
95 """
95 """
96
96
97 if dataOut.flagNoData:
97 if dataOut.flagNoData:
98 return None
98 return None
99
99
100 if realtime:
100 if realtime:
101 if not(isRealtime(utcdatatime = dataOut.utctime)):
101 if not(isRealtime(utcdatatime = dataOut.utctime)):
102 print('Skipping this plot function')
102 print('Skipping this plot function')
103 return
103 return
104
104
105 if channelList == None:
105 if channelList == None:
106 channelIndexList = dataOut.channelIndexList
106 channelIndexList = dataOut.channelIndexList
107 else:
107 else:
108 channelIndexList = []
108 channelIndexList = []
109 for channel in channelList:
109 for channel in channelList:
110 if channel not in dataOut.channelList:
110 if channel not in dataOut.channelList:
111 raise ValueError("Channel %d is not in dataOut.channelList")
111 raise ValueError("Channel %d is not in dataOut.channelList")
112 channelIndexList.append(dataOut.channelList.index(channel))
112 channelIndexList.append(dataOut.channelList.index(channel))
113
113
114 factor = dataOut.normFactor
114 factor = dataOut.normFactor
115 lenfactor = factor.shape[1]
115 lenfactor = factor.shape[1]
116 x = dataOut.getLagTRange(1)
116 x = dataOut.getLagTRange(1)
117 y = dataOut.getHeiRange()
117 y = dataOut.heightList
118
118
119 z = copy.copy(dataOut.data_corr[:,:,0,:])
119 z = copy.copy(dataOut.data_corr[:,:,0,:])
120 for i in range(dataOut.data_corr.shape[0]):
120 for i in range(dataOut.data_corr.shape[0]):
121 z[i,:,:] = z[i,:,:]/factor[i,:]
121 z[i,:,:] = z[i,:,:]/factor[i,:]
122 zdB = numpy.abs(z)
122 zdB = numpy.abs(z)
123
123
124 avg = numpy.average(z, axis=1)
124 avg = numpy.average(z, axis=1)
125 # avg = numpy.nanmean(z, axis=1)
125 # avg = numpy.nanmean(z, axis=1)
126 # noise = dataOut.noise/factor
126 # noise = dataOut.noise/factor
127
127
128 #thisDatetime = dataOut.datatime
128 #thisDatetime = dataOut.datatime
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
129 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
130 title = wintitle + " Correlation"
130 title = wintitle + " Correlation"
131 xlabel = "Lag T (s)"
131 xlabel = "Lag T (s)"
132 ylabel = "Range (Km)"
132 ylabel = "Range (Km)"
133
133
134 if not self.isConfig:
134 if not self.isConfig:
135
135
136 nplots = dataOut.data_corr.shape[0]
136 nplots = dataOut.data_corr.shape[0]
137
137
138 self.setup(id=id,
138 self.setup(id=id,
139 nplots=nplots,
139 nplots=nplots,
140 wintitle=wintitle,
140 wintitle=wintitle,
141 showprofile=showprofile,
141 showprofile=showprofile,
142 show=show)
142 show=show)
143
143
144 if xmin == None: xmin = numpy.nanmin(x)
144 if xmin == None: xmin = numpy.nanmin(x)
145 if xmax == None: xmax = numpy.nanmax(x)
145 if xmax == None: xmax = numpy.nanmax(x)
146 if ymin == None: ymin = numpy.nanmin(y)
146 if ymin == None: ymin = numpy.nanmin(y)
147 if ymax == None: ymax = numpy.nanmax(y)
147 if ymax == None: ymax = numpy.nanmax(y)
148 if zmin == None: zmin = 0
148 if zmin == None: zmin = 0
149 if zmax == None: zmax = 1
149 if zmax == None: zmax = 1
150
150
151 self.FTP_WEI = ftp_wei
151 self.FTP_WEI = ftp_wei
152 self.EXP_CODE = exp_code
152 self.EXP_CODE = exp_code
153 self.SUB_EXP_CODE = sub_exp_code
153 self.SUB_EXP_CODE = sub_exp_code
154 self.PLOT_POS = plot_pos
154 self.PLOT_POS = plot_pos
155
155
156 self.isConfig = True
156 self.isConfig = True
157
157
158 self.setWinTitle(title)
158 self.setWinTitle(title)
159
159
160 for i in range(self.nplots):
160 for i in range(self.nplots):
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
161 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
162 title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime)
163 axes = self.axesList[i*self.__nsubplots]
163 axes = self.axesList[i*self.__nsubplots]
164 axes.pcolor(x, y, zdB[i,:,:],
164 axes.pcolor(x, y, zdB[i,:,:],
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
165 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
166 xlabel=xlabel, ylabel=ylabel, title=title,
166 xlabel=xlabel, ylabel=ylabel, title=title,
167 ticksize=9, cblabel='')
167 ticksize=9, cblabel='')
168
168
169 # if self.__showprofile:
169 # if self.__showprofile:
170 # axes = self.axesList[i*self.__nsubplots +1]
170 # axes = self.axesList[i*self.__nsubplots +1]
171 # axes.pline(avgdB[i], y,
171 # axes.pline(avgdB[i], y,
172 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
172 # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
173 # xlabel='dB', ylabel='', title='',
173 # xlabel='dB', ylabel='', title='',
174 # ytick_visible=False,
174 # ytick_visible=False,
175 # grid='x')
175 # grid='x')
176 #
176 #
177 # noiseline = numpy.repeat(noisedB[i], len(y))
177 # noiseline = numpy.repeat(noisedB[i], len(y))
178 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
178 # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2)
179
179
180 self.draw()
180 self.draw()
181
181
182 self.save(figpath=figpath,
182 self.save(figpath=figpath,
183 figfile=figfile,
183 figfile=figfile,
184 save=save,
184 save=save,
185 ftp=ftp,
185 ftp=ftp,
186 wr_period=wr_period,
186 wr_period=wr_period,
187 thisDatetime=thisDatetime) No newline at end of file
187 thisDatetime=thisDatetime)
@@ -1,342 +1,342
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3
3
4 @author: roj-idl71
4 @author: roj-idl71
5 '''
5 '''
6 import os
6 import os
7 import datetime
7 import datetime
8 import numpy
8 import numpy
9
9
10 from schainpy.model.graphics.jroplot_base import Plot
10 from schainpy.model.graphics.jroplot_base import Plot
11
11
12
12
13 class SpectraHeisScope(Plot):
13 class SpectraHeisScope(Plot):
14
14
15
15
16 isConfig = None
16 isConfig = None
17 __nsubplots = None
17 __nsubplots = None
18
18
19 WIDTHPROF = None
19 WIDTHPROF = None
20 HEIGHTPROF = None
20 HEIGHTPROF = None
21 PREFIX = 'spc'
21 PREFIX = 'spc'
22
22
23 def __init__(self):#, **kwargs):
23 def __init__(self):#, **kwargs):
24
24
25 Plot.__init__(self)#, **kwargs)
25 Plot.__init__(self)#, **kwargs)
26 self.isConfig = False
26 self.isConfig = False
27 self.__nsubplots = 1
27 self.__nsubplots = 1
28
28
29 self.WIDTH = 230
29 self.WIDTH = 230
30 self.HEIGHT = 250
30 self.HEIGHT = 250
31 self.WIDTHPROF = 120
31 self.WIDTHPROF = 120
32 self.HEIGHTPROF = 0
32 self.HEIGHTPROF = 0
33 self.counter_imagwr = 0
33 self.counter_imagwr = 0
34
34
35 self.PLOT_CODE = SPEC_CODE
35 self.PLOT_CODE = SPEC_CODE
36
36
37 def getSubplots(self):
37 def getSubplots(self):
38
38
39 ncol = int(numpy.sqrt(self.nplots)+0.9)
39 ncol = int(numpy.sqrt(self.nplots)+0.9)
40 nrow = int(self.nplots*1./ncol + 0.9)
40 nrow = int(self.nplots*1./ncol + 0.9)
41
41
42 return nrow, ncol
42 return nrow, ncol
43
43
44 def setup(self, id, nplots, wintitle, show):
44 def setup(self, id, nplots, wintitle, show):
45
45
46 showprofile = False
46 showprofile = False
47 self.__showprofile = showprofile
47 self.__showprofile = showprofile
48 self.nplots = nplots
48 self.nplots = nplots
49
49
50 ncolspan = 1
50 ncolspan = 1
51 colspan = 1
51 colspan = 1
52 if showprofile:
52 if showprofile:
53 ncolspan = 3
53 ncolspan = 3
54 colspan = 2
54 colspan = 2
55 self.__nsubplots = 2
55 self.__nsubplots = 2
56
56
57 self.createFigure(id = id,
57 self.createFigure(id = id,
58 wintitle = wintitle,
58 wintitle = wintitle,
59 widthplot = self.WIDTH + self.WIDTHPROF,
59 widthplot = self.WIDTH + self.WIDTHPROF,
60 heightplot = self.HEIGHT + self.HEIGHTPROF,
60 heightplot = self.HEIGHT + self.HEIGHTPROF,
61 show = show)
61 show = show)
62
62
63 nrow, ncol = self.getSubplots()
63 nrow, ncol = self.getSubplots()
64
64
65 counter = 0
65 counter = 0
66 for y in range(nrow):
66 for y in range(nrow):
67 for x in range(ncol):
67 for x in range(ncol):
68
68
69 if counter >= self.nplots:
69 if counter >= self.nplots:
70 break
70 break
71
71
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
72 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
73
73
74 if showprofile:
74 if showprofile:
75 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
75 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
76
76
77 counter += 1
77 counter += 1
78
78
79
79
80 def run(self, dataOut, id, wintitle="", channelList=None,
80 def run(self, dataOut, id, wintitle="", channelList=None,
81 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
81 xmin=None, xmax=None, ymin=None, ymax=None, save=False,
82 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
82 figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
83 server=None, folder=None, username=None, password=None,
83 server=None, folder=None, username=None, password=None,
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
84 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
85
85
86 """
86 """
87
87
88 Input:
88 Input:
89 dataOut :
89 dataOut :
90 id :
90 id :
91 wintitle :
91 wintitle :
92 channelList :
92 channelList :
93 xmin : None,
93 xmin : None,
94 xmax : None,
94 xmax : None,
95 ymin : None,
95 ymin : None,
96 ymax : None,
96 ymax : None,
97 """
97 """
98
98
99 if dataOut.flagNoData:
99 if dataOut.flagNoData:
100 return dataOut
100 return dataOut
101
101
102 if dataOut.realtime:
102 if dataOut.realtime:
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
103 if not(isRealtime(utcdatatime = dataOut.utctime)):
104 print('Skipping this plot function')
104 print('Skipping this plot function')
105 return
105 return
106
106
107 if channelList == None:
107 if channelList == None:
108 channelIndexList = dataOut.channelIndexList
108 channelIndexList = dataOut.channelIndexList
109 else:
109 else:
110 channelIndexList = []
110 channelIndexList = []
111 for channel in channelList:
111 for channel in channelList:
112 if channel not in dataOut.channelList:
112 if channel not in dataOut.channelList:
113 raise ValueError("Channel %d is not in dataOut.channelList")
113 raise ValueError("Channel %d is not in dataOut.channelList")
114 channelIndexList.append(dataOut.channelList.index(channel))
114 channelIndexList.append(dataOut.channelList.index(channel))
115
115
116 # x = dataOut.heightList
116 # x = dataOut.heightList
117 c = 3E8
117 c = 3E8
118 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
118 deltaHeight = dataOut.heightList[1] - dataOut.heightList[0]
119 #deberia cambiar para el caso de 1Mhz y 100KHz
119 #deberia cambiar para el caso de 1Mhz y 100KHz
120 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
120 x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000))
121 #para 1Mhz descomentar la siguiente linea
121 #para 1Mhz descomentar la siguiente linea
122 #x= x/(10000.0)
122 #x= x/(10000.0)
123 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
123 # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
124 # y = y.real
124 # y = y.real
125 factor = dataOut.normFactor
125 factor = dataOut.normFactor
126 data = dataOut.data_spc / factor
126 data = dataOut.data_spc / factor
127 datadB = 10.*numpy.log10(data)
127 datadB = 10.*numpy.log10(data)
128 y = datadB
128 y = datadB
129
129
130 #thisDatetime = dataOut.datatime
130 #thisDatetime = dataOut.datatime
131 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
131 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
132 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
132 title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
133 xlabel = ""
133 xlabel = ""
134 #para 1Mhz descomentar la siguiente linea
134 #para 1Mhz descomentar la siguiente linea
135 #xlabel = "Frequency x 10000"
135 #xlabel = "Frequency x 10000"
136 ylabel = "Intensity (dB)"
136 ylabel = "Intensity (dB)"
137
137
138 if not self.isConfig:
138 if not self.isConfig:
139 nplots = len(channelIndexList)
139 nplots = len(channelIndexList)
140
140
141 self.setup(id=id,
141 self.setup(id=id,
142 nplots=nplots,
142 nplots=nplots,
143 wintitle=wintitle,
143 wintitle=wintitle,
144 show=show)
144 show=show)
145
145
146 if xmin == None: xmin = numpy.nanmin(x)
146 if xmin == None: xmin = numpy.nanmin(x)
147 if xmax == None: xmax = numpy.nanmax(x)
147 if xmax == None: xmax = numpy.nanmax(x)
148 if ymin == None: ymin = numpy.nanmin(y)
148 if ymin == None: ymin = numpy.nanmin(y)
149 if ymax == None: ymax = numpy.nanmax(y)
149 if ymax == None: ymax = numpy.nanmax(y)
150
150
151 self.FTP_WEI = ftp_wei
151 self.FTP_WEI = ftp_wei
152 self.EXP_CODE = exp_code
152 self.EXP_CODE = exp_code
153 self.SUB_EXP_CODE = sub_exp_code
153 self.SUB_EXP_CODE = sub_exp_code
154 self.PLOT_POS = plot_pos
154 self.PLOT_POS = plot_pos
155
155
156 self.isConfig = True
156 self.isConfig = True
157
157
158 self.setWinTitle(title)
158 self.setWinTitle(title)
159
159
160 for i in range(len(self.axesList)):
160 for i in range(len(self.axesList)):
161 ychannel = y[i,:]
161 ychannel = y[i,:]
162 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
162 str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S"))
163 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime)
163 title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime)
164 axes = self.axesList[i]
164 axes = self.axesList[i]
165 axes.pline(x, ychannel,
165 axes.pline(x, ychannel,
166 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
166 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
167 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
167 xlabel=xlabel, ylabel=ylabel, title=title, grid='both')
168
168
169
169
170 self.draw()
170 self.draw()
171
171
172 self.save(figpath=figpath,
172 self.save(figpath=figpath,
173 figfile=figfile,
173 figfile=figfile,
174 save=save,
174 save=save,
175 ftp=ftp,
175 ftp=ftp,
176 wr_period=wr_period,
176 wr_period=wr_period,
177 thisDatetime=thisDatetime)
177 thisDatetime=thisDatetime)
178
178
179 return dataOut
179 return dataOut
180
180
181
181
182 class RTIfromSpectraHeis(Plot):
182 class RTIfromSpectraHeis(Plot):
183
183
184 isConfig = None
184 isConfig = None
185 __nsubplots = None
185 __nsubplots = None
186
186
187 PREFIX = 'rtinoise'
187 PREFIX = 'rtinoise'
188
188
189 def __init__(self):#, **kwargs):
189 def __init__(self):#, **kwargs):
190 Plot.__init__(self)#, **kwargs)
190 Plot.__init__(self)#, **kwargs)
191 self.timerange = 24*60*60
191 self.timerange = 24*60*60
192 self.isConfig = False
192 self.isConfig = False
193 self.__nsubplots = 1
193 self.__nsubplots = 1
194
194
195 self.WIDTH = 820
195 self.WIDTH = 820
196 self.HEIGHT = 200
196 self.HEIGHT = 200
197 self.WIDTHPROF = 120
197 self.WIDTHPROF = 120
198 self.HEIGHTPROF = 0
198 self.HEIGHTPROF = 0
199 self.counter_imagwr = 0
199 self.counter_imagwr = 0
200 self.xdata = None
200 self.xdata = None
201 self.ydata = None
201 self.ydata = None
202 self.figfile = None
202 self.figfile = None
203
203
204 self.PLOT_CODE = RTI_CODE
204 self.PLOT_CODE = RTI_CODE
205
205
206 def getSubplots(self):
206 def getSubplots(self):
207
207
208 ncol = 1
208 ncol = 1
209 nrow = 1
209 nrow = 1
210
210
211 return nrow, ncol
211 return nrow, ncol
212
212
213 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
213 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
214
214
215 self.__showprofile = showprofile
215 self.__showprofile = showprofile
216 self.nplots = nplots
216 self.nplots = nplots
217
217
218 ncolspan = 7
218 ncolspan = 7
219 colspan = 6
219 colspan = 6
220 self.__nsubplots = 2
220 self.__nsubplots = 2
221
221
222 self.createFigure(id = id,
222 self.createFigure(id = id,
223 wintitle = wintitle,
223 wintitle = wintitle,
224 widthplot = self.WIDTH+self.WIDTHPROF,
224 widthplot = self.WIDTH+self.WIDTHPROF,
225 heightplot = self.HEIGHT+self.HEIGHTPROF,
225 heightplot = self.HEIGHT+self.HEIGHTPROF,
226 show = show)
226 show = show)
227
227
228 nrow, ncol = self.getSubplots()
228 nrow, ncol = self.getSubplots()
229
229
230 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
230 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
231
231
232
232
233 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
233 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
234 xmin=None, xmax=None, ymin=None, ymax=None,
234 xmin=None, xmax=None, ymin=None, ymax=None,
235 timerange=None,
235 timerange=None,
236 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
236 save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True,
237 server=None, folder=None, username=None, password=None,
237 server=None, folder=None, username=None, password=None,
238 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
238 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
239
239
240 if dataOut.flagNoData:
240 if dataOut.flagNoData:
241 return dataOut
241 return dataOut
242
242
243
243
244 if channelList == None:
244 if channelList == None:
245 channelIndexList = dataOut.channelIndexList
245 channelIndexList = dataOut.channelIndexList
246 channelList = dataOut.channelList
246 channelList = dataOut.channelList
247 else:
247 else:
248 channelIndexList = []
248 channelIndexList = []
249 for channel in channelList:
249 for channel in channelList:
250 if channel not in dataOut.channelList:
250 if channel not in dataOut.channelList:
251 raise ValueError("Channel %d is not in dataOut.channelList")
251 raise ValueError("Channel %d is not in dataOut.channelList")
252 channelIndexList.append(dataOut.channelList.index(channel))
252 channelIndexList.append(dataOut.channelList.index(channel))
253
253
254 if timerange != None:
254 if timerange != None:
255 self.timerange = timerange
255 self.timerange = timerange
256
256
257 x = dataOut.getTimeRange()
257 x = dataOut.getTimeRange()
258 y = dataOut.getHeiRange()
258 y = dataOut.heightList
259
259
260 factor = dataOut.normFactor
260 factor = dataOut.normFactor
261 data = dataOut.data_spc / factor
261 data = dataOut.data_spc / factor
262 data = numpy.average(data,axis=1)
262 data = numpy.average(data,axis=1)
263 datadB = 10*numpy.log10(data)
263 datadB = 10*numpy.log10(data)
264
264
265 # factor = dataOut.normFactor
265 # factor = dataOut.normFactor
266 # noise = dataOut.getNoise()/factor
266 # noise = dataOut.getNoise()/factor
267 # noisedB = 10*numpy.log10(noise)
267 # noisedB = 10*numpy.log10(noise)
268
268
269 #thisDatetime = dataOut.datatime
269 #thisDatetime = dataOut.datatime
270 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
270 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0])
271 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
271 title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y"))
272 xlabel = "Local Time"
272 xlabel = "Local Time"
273 ylabel = "Intensity (dB)"
273 ylabel = "Intensity (dB)"
274
274
275 if not self.isConfig:
275 if not self.isConfig:
276
276
277 nplots = 1
277 nplots = 1
278
278
279 self.setup(id=id,
279 self.setup(id=id,
280 nplots=nplots,
280 nplots=nplots,
281 wintitle=wintitle,
281 wintitle=wintitle,
282 showprofile=showprofile,
282 showprofile=showprofile,
283 show=show)
283 show=show)
284
284
285 self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax)
285 self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax)
286
286
287 if ymin == None: ymin = numpy.nanmin(datadB)
287 if ymin == None: ymin = numpy.nanmin(datadB)
288 if ymax == None: ymax = numpy.nanmax(datadB)
288 if ymax == None: ymax = numpy.nanmax(datadB)
289
289
290 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
290 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
291 self.isConfig = True
291 self.isConfig = True
292 self.figfile = figfile
292 self.figfile = figfile
293 self.xdata = numpy.array([])
293 self.xdata = numpy.array([])
294 self.ydata = numpy.array([])
294 self.ydata = numpy.array([])
295
295
296 self.FTP_WEI = ftp_wei
296 self.FTP_WEI = ftp_wei
297 self.EXP_CODE = exp_code
297 self.EXP_CODE = exp_code
298 self.SUB_EXP_CODE = sub_exp_code
298 self.SUB_EXP_CODE = sub_exp_code
299 self.PLOT_POS = plot_pos
299 self.PLOT_POS = plot_pos
300
300
301 self.setWinTitle(title)
301 self.setWinTitle(title)
302
302
303
303
304 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
304 # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y"))
305 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
305 title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
306
306
307 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
307 legendlabels = ["channel %d"%idchannel for idchannel in channelList]
308 axes = self.axesList[0]
308 axes = self.axesList[0]
309
309
310 self.xdata = numpy.hstack((self.xdata, x[0:1]))
310 self.xdata = numpy.hstack((self.xdata, x[0:1]))
311
311
312 if len(self.ydata)==0:
312 if len(self.ydata)==0:
313 self.ydata = datadB[channelIndexList].reshape(-1,1)
313 self.ydata = datadB[channelIndexList].reshape(-1,1)
314 else:
314 else:
315 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
315 self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1)))
316
316
317
317
318 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
318 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
319 xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax,
319 xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax,
320 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
320 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both',
321 XAxisAsTime=True
321 XAxisAsTime=True
322 )
322 )
323
323
324 self.draw()
324 self.draw()
325
325
326 update_figfile = False
326 update_figfile = False
327
327
328 if dataOut.ltctime >= self.tmax:
328 if dataOut.ltctime >= self.tmax:
329 self.counter_imagwr = wr_period
329 self.counter_imagwr = wr_period
330 self.isConfig = False
330 self.isConfig = False
331 update_figfile = True
331 update_figfile = True
332
332
333 self.save(figpath=figpath,
333 self.save(figpath=figpath,
334 figfile=figfile,
334 figfile=figfile,
335 save=save,
335 save=save,
336 ftp=ftp,
336 ftp=ftp,
337 wr_period=wr_period,
337 wr_period=wr_period,
338 thisDatetime=thisDatetime,
338 thisDatetime=thisDatetime,
339 update_figfile=update_figfile)
339 update_figfile=update_figfile)
340
340
341
341
342 return dataOut No newline at end of file
342 return dataOut
@@ -1,643 +1,641
1 '''
1 '''
2 Created on Jul 9, 2014
2 Created on Jul 9, 2014
3 Modified on May 10, 2020
3 Modified on May 10, 2020
4
4
5 @author: Juan C. Espinoza
5 @author: Juan C. Espinoza
6 '''
6 '''
7
7
8 import os
8 import os
9 import datetime
9 import datetime
10 import numpy
10 import numpy
11
11
12 from schainpy.model.graphics.jroplot_base import Plot, plt
12 from schainpy.model.graphics.jroplot_base import Plot, plt
13
13
14
14
15 class SpectraPlot(Plot):
15 class SpectraPlot(Plot):
16 '''
16 '''
17 Plot for Spectra data
17 Plot for Spectra data
18 '''
18 '''
19
19
20 CODE = 'spc'
20 CODE = 'spc'
21 colormap = 'jet'
21 colormap = 'jet'
22 plot_type = 'pcolor'
22 plot_type = 'pcolor'
23
23
24 def setup(self):
24 def setup(self):
25 self.nplots = len(self.data.channels)
25 self.nplots = len(self.data.channels)
26 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
26 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
27 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
27 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
28 self.height = 2.6 * self.nrows
28 self.height = 2.6 * self.nrows
29 self.cb_label = 'dB'
29 self.cb_label = 'dB'
30 if self.showprofile:
30 if self.showprofile:
31 self.width = 4 * self.ncols
31 self.width = 4 * self.ncols
32 else:
32 else:
33 self.width = 3.5 * self.ncols
33 self.width = 3.5 * self.ncols
34 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
34 self.plots_adjust.update({'wspace': 0.4, 'hspace':0.4, 'left': 0.1, 'right': 0.9, 'bottom': 0.08})
35 self.ylabel = 'Range [km]'
35 self.ylabel = 'Range [km]'
36
36
37 def plot(self):
37 def plot(self):
38 if self.xaxis == "frequency":
38 if self.xaxis == "frequency":
39 x = self.data.xrange[0]
39 x = self.data.xrange[0]
40 self.xlabel = "Frequency (kHz)"
40 self.xlabel = "Frequency (kHz)"
41 elif self.xaxis == "time":
41 elif self.xaxis == "time":
42 x = self.data.xrange[1]
42 x = self.data.xrange[1]
43 self.xlabel = "Time (ms)"
43 self.xlabel = "Time (ms)"
44 else:
44 else:
45 x = self.data.xrange[2]
45 x = self.data.xrange[2]
46 self.xlabel = "Velocity (m/s)"
46 self.xlabel = "Velocity (m/s)"
47
47
48 if self.CODE == 'spc_moments':
48 if self.CODE == 'spc_moments':
49 x = self.data.xrange[2]
49 x = self.data.xrange[2]
50 self.xlabel = "Velocity (m/s)"
50 self.xlabel = "Velocity (m/s)"
51
51
52 self.titles = []
52 self.titles = []
53
53
54 y = self.data.heights
54 y = self.data.heights
55 self.y = y
55 self.y = y
56 z = self.data['spc']
56 z = self.data['spc']
57
57
58 for n, ax in enumerate(self.axes):
58 for n, ax in enumerate(self.axes):
59 noise = self.data['noise'][n][-1]
59 noise = self.data['noise'][n][-1]
60 if self.CODE == 'spc_moments':
60 if self.CODE == 'spc_moments':
61 mean = self.data['moments'][n, :, 1, :][-1]
61 mean = self.data['moments'][n, :, 1, :][-1]
62 if ax.firsttime:
62 if ax.firsttime:
63 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
63 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
64 self.xmin = self.xmin if self.xmin else -self.xmax
64 self.xmin = self.xmin if self.xmin else -self.xmax
65 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
65 self.zmin = self.zmin if self.zmin else numpy.nanmin(z)
66 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
66 self.zmax = self.zmax if self.zmax else numpy.nanmax(z)
67 ax.plt = ax.pcolormesh(x, y, z[n].T,
67 ax.plt = ax.pcolormesh(x, y, z[n].T,
68 vmin=self.zmin,
68 vmin=self.zmin,
69 vmax=self.zmax,
69 vmax=self.zmax,
70 cmap=plt.get_cmap(self.colormap)
70 cmap=plt.get_cmap(self.colormap)
71 )
71 )
72
72
73 if self.showprofile:
73 if self.showprofile:
74 ax.plt_profile = self.pf_axes[n].plot(
74 ax.plt_profile = self.pf_axes[n].plot(
75 self.data['rti'][n][-1], y)[0]
75 self.data['rti'][n][-1], y)[0]
76 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
76 ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y,
77 color="k", linestyle="dashed", lw=1)[0]
77 color="k", linestyle="dashed", lw=1)[0]
78 if self.CODE == 'spc_moments':
78 if self.CODE == 'spc_moments':
79 ax.plt_mean = ax.plot(mean, y, color='k')[0]
79 ax.plt_mean = ax.plot(mean, y, color='k')[0]
80 else:
80 else:
81 ax.plt.set_array(z[n].T.ravel())
81 ax.plt.set_array(z[n].T.ravel())
82 if self.showprofile:
82 if self.showprofile:
83 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
83 ax.plt_profile.set_data(self.data['rti'][n][-1], y)
84 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
84 ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y)
85 if self.CODE == 'spc_moments':
85 if self.CODE == 'spc_moments':
86 ax.plt_mean.set_data(mean, y)
86 ax.plt_mean.set_data(mean, y)
87 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
87 self.titles.append('CH {}: {:3.2f}dB'.format(n, noise))
88
88
89
89
90 class CrossSpectraPlot(Plot):
90 class CrossSpectraPlot(Plot):
91
91
92 CODE = 'cspc'
92 CODE = 'cspc'
93 colormap = 'jet'
93 colormap = 'jet'
94 plot_type = 'pcolor'
94 plot_type = 'pcolor'
95 zmin_coh = None
95 zmin_coh = None
96 zmax_coh = None
96 zmax_coh = None
97 zmin_phase = None
97 zmin_phase = None
98 zmax_phase = None
98 zmax_phase = None
99
99
100 def setup(self):
100 def setup(self):
101
101
102 self.ncols = 4
102 self.ncols = 4
103 self.nrows = len(self.data.pairs)
103 self.nrows = len(self.data.pairs)
104 self.nplots = self.nrows * 4
104 self.nplots = self.nrows * 4
105 self.width = 3.1 * self.ncols
105 self.width = 3.1 * self.ncols
106 self.height = 2.6 * self.nrows
106 self.height = 2.6 * self.nrows
107 self.ylabel = 'Range [km]'
107 self.ylabel = 'Range [km]'
108 self.showprofile = False
108 self.showprofile = False
109 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
109 self.plots_adjust.update({'left': 0.08, 'right': 0.92, 'wspace': 0.5, 'hspace':0.4, 'top':0.95, 'bottom': 0.08})
110
110
111 def plot(self):
111 def plot(self):
112
112
113 if self.xaxis == "frequency":
113 if self.xaxis == "frequency":
114 x = self.data.xrange[0]
114 x = self.data.xrange[0]
115 self.xlabel = "Frequency (kHz)"
115 self.xlabel = "Frequency (kHz)"
116 elif self.xaxis == "time":
116 elif self.xaxis == "time":
117 x = self.data.xrange[1]
117 x = self.data.xrange[1]
118 self.xlabel = "Time (ms)"
118 self.xlabel = "Time (ms)"
119 else:
119 else:
120 x = self.data.xrange[2]
120 x = self.data.xrange[2]
121 self.xlabel = "Velocity (m/s)"
121 self.xlabel = "Velocity (m/s)"
122
122
123 self.titles = []
123 self.titles = []
124
124
125 y = self.data.heights
125 y = self.data.heights
126 self.y = y
126 self.y = y
127 nspc = self.data['spc']
127 nspc = self.data['spc']
128 spc = self.data['cspc'][0]
128 spc = self.data['cspc'][0]
129 cspc = self.data['cspc'][1]
129 cspc = self.data['cspc'][1]
130
130
131 for n in range(self.nrows):
131 for n in range(self.nrows):
132 noise = self.data['noise'][:,-1]
132 noise = self.data['noise'][:,-1]
133 pair = self.data.pairs[n]
133 pair = self.data.pairs[n]
134 ax = self.axes[4 * n]
134 ax = self.axes[4 * n]
135 if ax.firsttime:
135 if ax.firsttime:
136 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
136 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
137 self.xmin = self.xmin if self.xmin else -self.xmax
137 self.xmin = self.xmin if self.xmin else -self.xmax
138 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
138 self.zmin = self.zmin if self.zmin else numpy.nanmin(nspc)
139 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
139 self.zmax = self.zmax if self.zmax else numpy.nanmax(nspc)
140 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
140 ax.plt = ax.pcolormesh(x , y , nspc[pair[0]].T,
141 vmin=self.zmin,
141 vmin=self.zmin,
142 vmax=self.zmax,
142 vmax=self.zmax,
143 cmap=plt.get_cmap(self.colormap)
143 cmap=plt.get_cmap(self.colormap)
144 )
144 )
145 else:
145 else:
146 ax.plt.set_array(nspc[pair[0]].T.ravel())
146 ax.plt.set_array(nspc[pair[0]].T.ravel())
147 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
147 self.titles.append('CH {}: {:3.2f}dB'.format(pair[0], noise[pair[0]]))
148
148
149 ax = self.axes[4 * n + 1]
149 ax = self.axes[4 * n + 1]
150 if ax.firsttime:
150 if ax.firsttime:
151 ax.plt = ax.pcolormesh(x , y, nspc[pair[1]].T,
151 ax.plt = ax.pcolormesh(x , y, nspc[pair[1]].T,
152 vmin=self.zmin,
152 vmin=self.zmin,
153 vmax=self.zmax,
153 vmax=self.zmax,
154 cmap=plt.get_cmap(self.colormap)
154 cmap=plt.get_cmap(self.colormap)
155 )
155 )
156 else:
156 else:
157 ax.plt.set_array(nspc[pair[1]].T.ravel())
157 ax.plt.set_array(nspc[pair[1]].T.ravel())
158 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
158 self.titles.append('CH {}: {:3.2f}dB'.format(pair[1], noise[pair[1]]))
159
159
160 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
160 out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]])
161 coh = numpy.abs(out)
161 coh = numpy.abs(out)
162 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
162 phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi
163
163
164 ax = self.axes[4 * n + 2]
164 ax = self.axes[4 * n + 2]
165 if ax.firsttime:
165 if ax.firsttime:
166 ax.plt = ax.pcolormesh(x, y, coh.T,
166 ax.plt = ax.pcolormesh(x, y, coh.T,
167 vmin=0,
167 vmin=0,
168 vmax=1,
168 vmax=1,
169 cmap=plt.get_cmap(self.colormap_coh)
169 cmap=plt.get_cmap(self.colormap_coh)
170 )
170 )
171 else:
171 else:
172 ax.plt.set_array(coh.T.ravel())
172 ax.plt.set_array(coh.T.ravel())
173 self.titles.append(
173 self.titles.append(
174 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
174 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1]))
175
175
176 ax = self.axes[4 * n + 3]
176 ax = self.axes[4 * n + 3]
177 if ax.firsttime:
177 if ax.firsttime:
178 ax.plt = ax.pcolormesh(x, y, phase.T,
178 ax.plt = ax.pcolormesh(x, y, phase.T,
179 vmin=-180,
179 vmin=-180,
180 vmax=180,
180 vmax=180,
181 cmap=plt.get_cmap(self.colormap_phase)
181 cmap=plt.get_cmap(self.colormap_phase)
182 )
182 )
183 else:
183 else:
184 ax.plt.set_array(phase.T.ravel())
184 ax.plt.set_array(phase.T.ravel())
185 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
185 self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1]))
186
186
187
187
188 class RTIPlot(Plot):
188 class RTIPlot(Plot):
189 '''
189 '''
190 Plot for RTI data
190 Plot for RTI data
191 '''
191 '''
192
192
193 CODE = 'rti'
193 CODE = 'rti'
194 colormap = 'jet'
194 colormap = 'jet'
195 plot_type = 'pcolorbuffer'
195 plot_type = 'pcolorbuffer'
196
196
197 def setup(self):
197 def setup(self):
198 self.xaxis = 'time'
198 self.xaxis = 'time'
199 self.ncols = 1
199 self.ncols = 1
200 self.nrows = len(self.data.channels)
200 self.nrows = len(self.data.channels)
201 self.nplots = len(self.data.channels)
201 self.nplots = len(self.data.channels)
202 self.ylabel = 'Range [km]'
202 self.ylabel = 'Range [km]'
203 self.xlabel = 'Time'
203 self.xlabel = 'Time'
204 self.cb_label = 'dB'
204 self.cb_label = 'dB'
205 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95})
205 self.plots_adjust.update({'hspace':0.8, 'left': 0.1, 'bottom': 0.08, 'right':0.95})
206 self.titles = ['{} Channel {}'.format(
206 self.titles = ['{} Channel {}'.format(
207 self.CODE.upper(), x) for x in range(self.nrows)]
207 self.CODE.upper(), x) for x in range(self.nrows)]
208
208
209 def plot(self):
209 def plot(self):
210 self.x = self.data.times
210 self.x = self.data.times
211 self.y = self.data.heights
211 self.y = self.data.heights
212 self.z = self.data[self.CODE]
212 self.z = self.data[self.CODE]
213 self.z = numpy.ma.masked_invalid(self.z)
213 self.z = numpy.ma.masked_invalid(self.z)
214
214
215 if self.decimation is None:
215 if self.decimation is None:
216 x, y, z = self.fill_gaps(self.x, self.y, self.z)
216 x, y, z = self.fill_gaps(self.x, self.y, self.z)
217 else:
217 else:
218 x, y, z = self.fill_gaps(*self.decimate())
218 x, y, z = self.fill_gaps(*self.decimate())
219
219
220 for n, ax in enumerate(self.axes):
220 for n, ax in enumerate(self.axes):
221 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
221 self.zmin = self.zmin if self.zmin else numpy.min(self.z)
222 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
222 self.zmax = self.zmax if self.zmax else numpy.max(self.z)
223 if ax.firsttime:
223 if ax.firsttime:
224 ax.plt = ax.pcolormesh(x, y, z[n].T,
224 ax.plt = ax.pcolormesh(x, y, z[n].T,
225 vmin=self.zmin,
225 vmin=self.zmin,
226 vmax=self.zmax,
226 vmax=self.zmax,
227 cmap=plt.get_cmap(self.colormap)
227 cmap=plt.get_cmap(self.colormap)
228 )
228 )
229 if self.showprofile:
229 if self.showprofile:
230 ax.plot_profile = self.pf_axes[n].plot(
230 ax.plot_profile = self.pf_axes[n].plot(
231 self.data['rti'][n][-1], self.y)[0]
231 self.data['rti'][n][-1], self.y)[0]
232 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
232 ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y,
233 color="k", linestyle="dashed", lw=1)[0]
233 color="k", linestyle="dashed", lw=1)[0]
234 else:
234 else:
235 ax.collections.remove(ax.collections[0])
235 ax.collections.remove(ax.collections[0])
236 ax.plt = ax.pcolormesh(x, y, z[n].T,
236 ax.plt = ax.pcolormesh(x, y, z[n].T,
237 vmin=self.zmin,
237 vmin=self.zmin,
238 vmax=self.zmax,
238 vmax=self.zmax,
239 cmap=plt.get_cmap(self.colormap)
239 cmap=plt.get_cmap(self.colormap)
240 )
240 )
241 if self.showprofile:
241 if self.showprofile:
242 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
242 ax.plot_profile.set_data(self.data['rti'][n][-1], self.y)
243 ax.plot_noise.set_data(numpy.repeat(
243 ax.plot_noise.set_data(numpy.repeat(
244 self.data['noise'][n][-1], len(self.y)), self.y)
244 self.data['noise'][n][-1], len(self.y)), self.y)
245
245
246
246
247 class CoherencePlot(RTIPlot):
247 class CoherencePlot(RTIPlot):
248 '''
248 '''
249 Plot for Coherence data
249 Plot for Coherence data
250 '''
250 '''
251
251
252 CODE = 'coh'
252 CODE = 'coh'
253
253
254 def setup(self):
254 def setup(self):
255 self.xaxis = 'time'
255 self.xaxis = 'time'
256 self.ncols = 1
256 self.ncols = 1
257 self.nrows = len(self.data.pairs)
257 self.nrows = len(self.data.pairs)
258 self.nplots = len(self.data.pairs)
258 self.nplots = len(self.data.pairs)
259 self.ylabel = 'Range [km]'
259 self.ylabel = 'Range [km]'
260 self.xlabel = 'Time'
260 self.xlabel = 'Time'
261 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
261 self.plots_adjust.update({'hspace':0.6, 'left': 0.1, 'bottom': 0.1,'right':0.95})
262 if self.CODE == 'coh':
262 if self.CODE == 'coh':
263 self.cb_label = ''
263 self.cb_label = ''
264 self.titles = [
264 self.titles = [
265 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
265 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
266 else:
266 else:
267 self.cb_label = 'Degrees'
267 self.cb_label = 'Degrees'
268 self.titles = [
268 self.titles = [
269 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
269 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs]
270
270
271
271
272 class PhasePlot(CoherencePlot):
272 class PhasePlot(CoherencePlot):
273 '''
273 '''
274 Plot for Phase map data
274 Plot for Phase map data
275 '''
275 '''
276
276
277 CODE = 'phase'
277 CODE = 'phase'
278 colormap = 'seismic'
278 colormap = 'seismic'
279
279
280
280
281 class NoisePlot(Plot):
281 class NoisePlot(Plot):
282 '''
282 '''
283 Plot for noise
283 Plot for noise
284 '''
284 '''
285
285
286 CODE = 'noise'
286 CODE = 'noise'
287 plot_type = 'scatterbuffer'
287 plot_type = 'scatterbuffer'
288
288
289
289
290 def setup(self):
290 def setup(self):
291 self.xaxis = 'time'
291 self.xaxis = 'time'
292 self.ncols = 1
292 self.ncols = 1
293 self.nrows = 1
293 self.nrows = 1
294 self.nplots = 1
294 self.nplots = 1
295 self.ylabel = 'Intensity [dB]'
295 self.ylabel = 'Intensity [dB]'
296 self.xlabel = 'Time'
296 self.xlabel = 'Time'
297 self.titles = ['Noise']
297 self.titles = ['Noise']
298 self.colorbar = False
298 self.colorbar = False
299
299
300 def plot(self):
300 def plot(self):
301
301
302 x = self.data.times
302 x = self.data.times
303 xmin = self.data.min_time
303 xmin = self.data.min_time
304 xmax = xmin + self.xrange * 60 * 60
304 xmax = xmin + self.xrange * 60 * 60
305 Y = self.data[self.CODE]
305 Y = self.data[self.CODE]
306
306
307 if self.axes[0].firsttime:
307 if self.axes[0].firsttime:
308 for ch in self.data.channels:
308 for ch in self.data.channels:
309 y = Y[ch]
309 y = Y[ch]
310 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
310 self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch))
311 plt.legend()
311 plt.legend()
312 else:
312 else:
313 for ch in self.data.channels:
313 for ch in self.data.channels:
314 y = Y[ch]
314 y = Y[ch]
315 self.axes[0].lines[ch].set_data(x, y)
315 self.axes[0].lines[ch].set_data(x, y)
316
316
317 self.ymin = numpy.nanmin(Y) - 5
317 self.ymin = numpy.nanmin(Y) - 5
318 self.ymax = numpy.nanmax(Y) + 5
318 self.ymax = numpy.nanmax(Y) + 5
319
319
320
320
321 class PowerProfilePlot(Plot):
321 class PowerProfilePlot(Plot):
322
322
323 CODE = 'spcprofile'
323 CODE = 'spcprofile'
324 plot_type = 'scatter'
324 plot_type = 'scatter'
325 buffering = False
325 buffering = False
326
326
327 def setup(self):
327 def setup(self):
328
328
329 self.ncols = 1
329 self.ncols = 1
330 self.nrows = 1
330 self.nrows = 1
331 self.nplots = 1
331 self.nplots = 1
332 self.height = 4
332 self.height = 4
333 self.width = 3
333 self.width = 3
334 self.ylabel = 'Range [km]'
334 self.ylabel = 'Range [km]'
335 self.xlabel = 'Intensity [dB]'
335 self.xlabel = 'Intensity [dB]'
336 self.titles = ['Power Profile']
336 self.titles = ['Power Profile']
337 self.colorbar = False
337 self.colorbar = False
338
338
339 def plot(self):
339 def plot(self):
340
340
341 y = self.data.heights
341 y = self.data.heights
342 self.y = y
342 self.y = y
343
343
344 x = self.data['spcprofile']
344 x = self.data['spcprofile']
345
345
346 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
346 if self.xmin is None: self.xmin = numpy.nanmin(x)*0.9
347 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
347 if self.xmax is None: self.xmax = numpy.nanmax(x)*1.1
348
348
349 if self.axes[0].firsttime:
349 if self.axes[0].firsttime:
350 for ch in self.data.channels:
350 for ch in self.data.channels:
351 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
351 self.axes[0].plot(x[ch], y, lw=1, label='Ch{}'.format(ch))
352 plt.legend()
352 plt.legend()
353 else:
353 else:
354 for ch in self.data.channels:
354 for ch in self.data.channels:
355 self.axes[0].lines[ch].set_data(x[ch], y)
355 self.axes[0].lines[ch].set_data(x[ch], y)
356
356
357
357
358 class SpectraCutPlot(Plot):
358 class SpectraCutPlot(Plot):
359
359
360 CODE = 'spc_cut'
360 CODE = 'spc_cut'
361 plot_type = 'scatter'
361 plot_type = 'scatter'
362 buffering = False
362 buffering = False
363
363
364 def setup(self):
364 def setup(self):
365
365
366 self.nplots = len(self.data.channels)
366 self.nplots = len(self.data.channels)
367 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
367 self.ncols = int(numpy.sqrt(self.nplots) + 0.9)
368 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
368 self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9)
369 self.width = 3.4 * self.ncols + 1.5
369 self.width = 3.4 * self.ncols + 1.5
370 self.height = 3 * self.nrows
370 self.height = 3 * self.nrows
371 self.ylabel = 'Power [dB]'
371 self.ylabel = 'Power [dB]'
372 self.colorbar = False
372 self.colorbar = False
373 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
373 self.plots_adjust.update({'left':0.1, 'hspace':0.3, 'right': 0.75, 'bottom':0.08})
374
374
375 def plot(self):
375 def plot(self):
376 if self.xaxis == "frequency":
376 if self.xaxis == "frequency":
377 x = self.data.xrange[0][1:]
377 x = self.data.xrange[0][1:]
378 self.xlabel = "Frequency (kHz)"
378 self.xlabel = "Frequency (kHz)"
379 elif self.xaxis == "time":
379 elif self.xaxis == "time":
380 x = self.data.xrange[1]
380 x = self.data.xrange[1]
381 self.xlabel = "Time (ms)"
381 self.xlabel = "Time (ms)"
382 else:
382 else:
383 x = self.data.xrange[2]
383 x = self.data.xrange[2]
384 self.xlabel = "Velocity (m/s)"
384 self.xlabel = "Velocity (m/s)"
385
385
386 self.titles = []
386 self.titles = []
387
387
388 y = self.data.heights
388 y = self.data.heights
389 #self.y = y
389 #self.y = y
390 z = self.data['spc_cut']
390 z = self.data['spc_cut']
391
391
392 if self.height_index:
392 if self.height_index:
393 index = numpy.array(self.height_index)
393 index = numpy.array(self.height_index)
394 else:
394 else:
395 index = numpy.arange(0, len(y), int((len(y))/9))
395 index = numpy.arange(0, len(y), int((len(y))/9))
396
396
397 for n, ax in enumerate(self.axes):
397 for n, ax in enumerate(self.axes):
398 if ax.firsttime:
398 if ax.firsttime:
399 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
399 self.xmax = self.xmax if self.xmax else numpy.nanmax(x)
400 self.xmin = self.xmin if self.xmin else -self.xmax
400 self.xmin = self.xmin if self.xmin else -self.xmax
401 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
401 self.ymin = self.ymin if self.ymin else numpy.nanmin(z)
402 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
402 self.ymax = self.ymax if self.ymax else numpy.nanmax(z)
403 ax.plt = ax.plot(x, z[n, :, index].T)
403 ax.plt = ax.plot(x, z[n, :, index].T)
404 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
404 labels = ['Range = {:2.1f}km'.format(y[i]) for i in index]
405 self.figures[0].legend(ax.plt, labels, loc='center right')
405 self.figures[0].legend(ax.plt, labels, loc='center right')
406 else:
406 else:
407 for i, line in enumerate(ax.plt):
407 for i, line in enumerate(ax.plt):
408 line.set_data(x, z[n, :, i])
408 line.set_data(x, z[n, :, i])
409 self.titles.append('CH {}'.format(n))
409 self.titles.append('CH {}'.format(n))
410
410
411
411
412 class BeaconPhase(Plot):
412 class BeaconPhase(Plot):
413
413
414 __isConfig = None
414 __isConfig = None
415 __nsubplots = None
415 __nsubplots = None
416
416
417 PREFIX = 'beacon_phase'
417 PREFIX = 'beacon_phase'
418
418
419 def __init__(self):
419 def __init__(self):
420 Plot.__init__(self)
420 Plot.__init__(self)
421 self.timerange = 24*60*60
421 self.timerange = 24*60*60
422 self.isConfig = False
422 self.isConfig = False
423 self.__nsubplots = 1
423 self.__nsubplots = 1
424 self.counter_imagwr = 0
424 self.counter_imagwr = 0
425 self.WIDTH = 800
425 self.WIDTH = 800
426 self.HEIGHT = 400
426 self.HEIGHT = 400
427 self.WIDTHPROF = 120
427 self.WIDTHPROF = 120
428 self.HEIGHTPROF = 0
428 self.HEIGHTPROF = 0
429 self.xdata = None
429 self.xdata = None
430 self.ydata = None
430 self.ydata = None
431
431
432 self.PLOT_CODE = BEACON_CODE
432 self.PLOT_CODE = BEACON_CODE
433
433
434 self.FTP_WEI = None
434 self.FTP_WEI = None
435 self.EXP_CODE = None
435 self.EXP_CODE = None
436 self.SUB_EXP_CODE = None
436 self.SUB_EXP_CODE = None
437 self.PLOT_POS = None
437 self.PLOT_POS = None
438
438
439 self.filename_phase = None
439 self.filename_phase = None
440
440
441 self.figfile = None
441 self.figfile = None
442
442
443 self.xmin = None
443 self.xmin = None
444 self.xmax = None
444 self.xmax = None
445
445
446 def getSubplots(self):
446 def getSubplots(self):
447
447
448 ncol = 1
448 ncol = 1
449 nrow = 1
449 nrow = 1
450
450
451 return nrow, ncol
451 return nrow, ncol
452
452
453 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
453 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
454
454
455 self.__showprofile = showprofile
455 self.__showprofile = showprofile
456 self.nplots = nplots
456 self.nplots = nplots
457
457
458 ncolspan = 7
458 ncolspan = 7
459 colspan = 6
459 colspan = 6
460 self.__nsubplots = 2
460 self.__nsubplots = 2
461
461
462 self.createFigure(id = id,
462 self.createFigure(id = id,
463 wintitle = wintitle,
463 wintitle = wintitle,
464 widthplot = self.WIDTH+self.WIDTHPROF,
464 widthplot = self.WIDTH+self.WIDTHPROF,
465 heightplot = self.HEIGHT+self.HEIGHTPROF,
465 heightplot = self.HEIGHT+self.HEIGHTPROF,
466 show=show)
466 show=show)
467
467
468 nrow, ncol = self.getSubplots()
468 nrow, ncol = self.getSubplots()
469
469
470 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
470 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
471
471
472 def save_phase(self, filename_phase):
472 def save_phase(self, filename_phase):
473 f = open(filename_phase,'w+')
473 f = open(filename_phase,'w+')
474 f.write('\n\n')
474 f.write('\n\n')
475 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
475 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
476 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
476 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
477 f.close()
477 f.close()
478
478
479 def save_data(self, filename_phase, data, data_datetime):
479 def save_data(self, filename_phase, data, data_datetime):
480 f=open(filename_phase,'a')
480 f=open(filename_phase,'a')
481 timetuple_data = data_datetime.timetuple()
481 timetuple_data = data_datetime.timetuple()
482 day = str(timetuple_data.tm_mday)
482 day = str(timetuple_data.tm_mday)
483 month = str(timetuple_data.tm_mon)
483 month = str(timetuple_data.tm_mon)
484 year = str(timetuple_data.tm_year)
484 year = str(timetuple_data.tm_year)
485 hour = str(timetuple_data.tm_hour)
485 hour = str(timetuple_data.tm_hour)
486 minute = str(timetuple_data.tm_min)
486 minute = str(timetuple_data.tm_min)
487 second = str(timetuple_data.tm_sec)
487 second = str(timetuple_data.tm_sec)
488 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
488 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
489 f.close()
489 f.close()
490
490
491 def plot(self):
491 def plot(self):
492 log.warning('TODO: Not yet implemented...')
492 log.warning('TODO: Not yet implemented...')
493
493
494 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
494 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
495 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
495 xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None,
496 timerange=None,
496 timerange=None,
497 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
497 save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1,
498 server=None, folder=None, username=None, password=None,
498 server=None, folder=None, username=None, password=None,
499 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
499 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
500
500
501 if dataOut.flagNoData:
501 if dataOut.flagNoData:
502 return dataOut
502 return dataOut
503
503
504 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
504 if not isTimeInHourRange(dataOut.datatime, xmin, xmax):
505 return
505 return
506
506
507 if pairsList == None:
507 if pairsList == None:
508 pairsIndexList = dataOut.pairsIndexList[:10]
508 pairsIndexList = dataOut.pairsIndexList[:10]
509 else:
509 else:
510 pairsIndexList = []
510 pairsIndexList = []
511 for pair in pairsList:
511 for pair in pairsList:
512 if pair not in dataOut.pairsList:
512 if pair not in dataOut.pairsList:
513 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
513 raise ValueError("Pair %s is not in dataOut.pairsList" %(pair))
514 pairsIndexList.append(dataOut.pairsList.index(pair))
514 pairsIndexList.append(dataOut.pairsList.index(pair))
515
515
516 if pairsIndexList == []:
516 if pairsIndexList == []:
517 return
517 return
518
518
519 # if len(pairsIndexList) > 4:
519 # if len(pairsIndexList) > 4:
520 # pairsIndexList = pairsIndexList[0:4]
520 # pairsIndexList = pairsIndexList[0:4]
521
521
522 hmin_index = None
522 hmin_index = None
523 hmax_index = None
523 hmax_index = None
524
524
525 if hmin != None and hmax != None:
525 if hmin != None and hmax != None:
526 indexes = numpy.arange(dataOut.nHeights)
526 indexes = numpy.arange(dataOut.nHeights)
527 hmin_list = indexes[dataOut.heightList >= hmin]
527 hmin_list = indexes[dataOut.heightList >= hmin]
528 hmax_list = indexes[dataOut.heightList <= hmax]
528 hmax_list = indexes[dataOut.heightList <= hmax]
529
529
530 if hmin_list.any():
530 if hmin_list.any():
531 hmin_index = hmin_list[0]
531 hmin_index = hmin_list[0]
532
532
533 if hmax_list.any():
533 if hmax_list.any():
534 hmax_index = hmax_list[-1]+1
534 hmax_index = hmax_list[-1]+1
535
535
536 x = dataOut.getTimeRange()
536 x = dataOut.getTimeRange()
537 #y = dataOut.getHeiRange()
538
539
537
540 thisDatetime = dataOut.datatime
538 thisDatetime = dataOut.datatime
541
539
542 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
540 title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
543 xlabel = "Local Time"
541 xlabel = "Local Time"
544 ylabel = "Phase (degrees)"
542 ylabel = "Phase (degrees)"
545
543
546 update_figfile = False
544 update_figfile = False
547
545
548 nplots = len(pairsIndexList)
546 nplots = len(pairsIndexList)
549 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
547 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
550 phase_beacon = numpy.zeros(len(pairsIndexList))
548 phase_beacon = numpy.zeros(len(pairsIndexList))
551 for i in range(nplots):
549 for i in range(nplots):
552 pair = dataOut.pairsList[pairsIndexList[i]]
550 pair = dataOut.pairsList[pairsIndexList[i]]
553 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
551 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0)
554 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
552 powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0)
555 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
553 powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0)
556 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
554 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
557 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
555 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
558
556
559 if dataOut.beacon_heiIndexList:
557 if dataOut.beacon_heiIndexList:
560 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
558 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
561 else:
559 else:
562 phase_beacon[i] = numpy.average(phase)
560 phase_beacon[i] = numpy.average(phase)
563
561
564 if not self.isConfig:
562 if not self.isConfig:
565
563
566 nplots = len(pairsIndexList)
564 nplots = len(pairsIndexList)
567
565
568 self.setup(id=id,
566 self.setup(id=id,
569 nplots=nplots,
567 nplots=nplots,
570 wintitle=wintitle,
568 wintitle=wintitle,
571 showprofile=showprofile,
569 showprofile=showprofile,
572 show=show)
570 show=show)
573
571
574 if timerange != None:
572 if timerange != None:
575 self.timerange = timerange
573 self.timerange = timerange
576
574
577 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
575 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
578
576
579 if ymin == None: ymin = 0
577 if ymin == None: ymin = 0
580 if ymax == None: ymax = 360
578 if ymax == None: ymax = 360
581
579
582 self.FTP_WEI = ftp_wei
580 self.FTP_WEI = ftp_wei
583 self.EXP_CODE = exp_code
581 self.EXP_CODE = exp_code
584 self.SUB_EXP_CODE = sub_exp_code
582 self.SUB_EXP_CODE = sub_exp_code
585 self.PLOT_POS = plot_pos
583 self.PLOT_POS = plot_pos
586
584
587 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
585 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
588 self.isConfig = True
586 self.isConfig = True
589 self.figfile = figfile
587 self.figfile = figfile
590 self.xdata = numpy.array([])
588 self.xdata = numpy.array([])
591 self.ydata = numpy.array([])
589 self.ydata = numpy.array([])
592
590
593 update_figfile = True
591 update_figfile = True
594
592
595 #open file beacon phase
593 #open file beacon phase
596 path = '%s%03d' %(self.PREFIX, self.id)
594 path = '%s%03d' %(self.PREFIX, self.id)
597 beacon_file = os.path.join(path,'%s.txt'%self.name)
595 beacon_file = os.path.join(path,'%s.txt'%self.name)
598 self.filename_phase = os.path.join(figpath,beacon_file)
596 self.filename_phase = os.path.join(figpath,beacon_file)
599 #self.save_phase(self.filename_phase)
597 #self.save_phase(self.filename_phase)
600
598
601
599
602 #store data beacon phase
600 #store data beacon phase
603 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
601 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
604
602
605 self.setWinTitle(title)
603 self.setWinTitle(title)
606
604
607
605
608 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
606 title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
609
607
610 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
608 legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList]
611
609
612 axes = self.axesList[0]
610 axes = self.axesList[0]
613
611
614 self.xdata = numpy.hstack((self.xdata, x[0:1]))
612 self.xdata = numpy.hstack((self.xdata, x[0:1]))
615
613
616 if len(self.ydata)==0:
614 if len(self.ydata)==0:
617 self.ydata = phase_beacon.reshape(-1,1)
615 self.ydata = phase_beacon.reshape(-1,1)
618 else:
616 else:
619 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
617 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
620
618
621
619
622 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
620 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
623 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
621 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax,
624 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
622 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
625 XAxisAsTime=True, grid='both'
623 XAxisAsTime=True, grid='both'
626 )
624 )
627
625
628 self.draw()
626 self.draw()
629
627
630 if dataOut.ltctime >= self.xmax:
628 if dataOut.ltctime >= self.xmax:
631 self.counter_imagwr = wr_period
629 self.counter_imagwr = wr_period
632 self.isConfig = False
630 self.isConfig = False
633 update_figfile = True
631 update_figfile = True
634
632
635 self.save(figpath=figpath,
633 self.save(figpath=figpath,
636 figfile=figfile,
634 figfile=figfile,
637 save=save,
635 save=save,
638 ftp=ftp,
636 ftp=ftp,
639 wr_period=wr_period,
637 wr_period=wr_period,
640 thisDatetime=thisDatetime,
638 thisDatetime=thisDatetime,
641 update_figfile=update_figfile)
639 update_figfile=update_figfile)
642
640
643 return dataOut No newline at end of file
641 return dataOut
General Comments 0
You need to be logged in to leave comments. Login now