The requested changes are too big and content was truncated. Show full diff
This diff has been collapsed as it changes many lines, (803 lines changed) Show them Hide them | |||
@@ -0,0 +1,803 | |||
|
1 | ||
|
2 | import os | |
|
3 | import sys | |
|
4 | import zmq | |
|
5 | import time | |
|
6 | import datetime | |
|
7 | from functools import wraps | |
|
8 | import numpy | |
|
9 | import matplotlib | |
|
10 | ||
|
11 | if 'BACKEND' in os.environ: | |
|
12 | matplotlib.use(os.environ['BACKEND']) | |
|
13 | elif 'linux' in sys.platform: | |
|
14 | matplotlib.use("TkAgg") | |
|
15 | elif 'darwin' in sys.platform: | |
|
16 | matplotlib.use('TkAgg') | |
|
17 | else: | |
|
18 | from schainpy.utils import log | |
|
19 | log.warning('Using default Backend="Agg"', 'INFO') | |
|
20 | matplotlib.use('Agg') | |
|
21 | ||
|
22 | import matplotlib.pyplot as plt | |
|
23 | from matplotlib.patches import Polygon | |
|
24 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
|
25 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
|
26 | ||
|
27 | from schainpy.model.data.jrodata import PlotterData | |
|
28 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
|
29 | from schainpy.utils import log | |
|
30 | ||
|
31 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] | |
|
32 | blu_values = matplotlib.pyplot.get_cmap( | |
|
33 | 'seismic_r', 20)(numpy.arange(20))[10:15] | |
|
34 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
|
35 | 'jro', numpy.vstack((blu_values, jet_values))) | |
|
36 | matplotlib.pyplot.register_cmap(cmap=ncmap) | |
|
37 | ||
|
38 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', | |
|
39 | 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')] | |
|
40 | ||
|
41 | EARTH_RADIUS = 6.3710e3 | |
|
42 | ||
|
43 | ||
|
44 | def ll2xy(lat1, lon1, lat2, lon2): | |
|
45 | ||
|
46 | p = 0.017453292519943295 | |
|
47 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ | |
|
48 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |
|
49 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) | |
|
50 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) | |
|
51 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |
|
52 | theta = -theta + numpy.pi/2 | |
|
53 | return r*numpy.cos(theta), r*numpy.sin(theta) | |
|
54 | ||
|
55 | ||
|
56 | def km2deg(km): | |
|
57 | ''' | |
|
58 | Convert distance in km to degrees | |
|
59 | ''' | |
|
60 | ||
|
61 | return numpy.rad2deg(km/EARTH_RADIUS) | |
|
62 | ||
|
63 | ||
|
64 | def figpause(interval): | |
|
65 | backend = plt.rcParams['backend'] | |
|
66 | if backend in matplotlib.rcsetup.interactive_bk: | |
|
67 | figManager = matplotlib._pylab_helpers.Gcf.get_active() | |
|
68 | if figManager is not None: | |
|
69 | canvas = figManager.canvas | |
|
70 | if canvas.figure.stale: | |
|
71 | canvas.draw() | |
|
72 | try: | |
|
73 | canvas.start_event_loop(interval) | |
|
74 | except: | |
|
75 | pass | |
|
76 | return | |
|
77 | ||
|
78 | ||
|
79 | def popup(message): | |
|
80 | ''' | |
|
81 | ''' | |
|
82 | ||
|
83 | fig = plt.figure(figsize=(12, 8), facecolor='r') | |
|
84 | text = '\n'.join([s.strip() for s in message.split(':')]) | |
|
85 | fig.text(0.01, 0.5, text, ha='left', va='center', | |
|
86 | size='20', weight='heavy', color='w') | |
|
87 | fig.show() | |
|
88 | figpause(1000) | |
|
89 | ||
|
90 | ||
|
91 | class Throttle(object): | |
|
92 | ''' | |
|
93 | Decorator that prevents a function from being called more than once every | |
|
94 | time period. | |
|
95 | To create a function that cannot be called more than once a minute, but | |
|
96 | will sleep until it can be called: | |
|
97 | @Throttle(minutes=1) | |
|
98 | def foo(): | |
|
99 | pass | |
|
100 | ||
|
101 | for i in range(10): | |
|
102 | foo() | |
|
103 | print "This function has run %s times." % i | |
|
104 | ''' | |
|
105 | ||
|
106 | def __init__(self, seconds=0, minutes=0, hours=0): | |
|
107 | self.throttle_period = datetime.timedelta( | |
|
108 | seconds=seconds, minutes=minutes, hours=hours | |
|
109 | ) | |
|
110 | ||
|
111 | self.time_of_last_call = datetime.datetime.min | |
|
112 | ||
|
113 | def __call__(self, fn): | |
|
114 | @wraps(fn) | |
|
115 | def wrapper(*args, **kwargs): | |
|
116 | coerce = kwargs.pop('coerce', None) | |
|
117 | if coerce: | |
|
118 | self.time_of_last_call = datetime.datetime.now() | |
|
119 | return fn(*args, **kwargs) | |
|
120 | else: | |
|
121 | now = datetime.datetime.now() | |
|
122 | time_since_last_call = now - self.time_of_last_call | |
|
123 | time_left = self.throttle_period - time_since_last_call | |
|
124 | ||
|
125 | if time_left > datetime.timedelta(seconds=0): | |
|
126 | return | |
|
127 | ||
|
128 | self.time_of_last_call = datetime.datetime.now() | |
|
129 | return fn(*args, **kwargs) | |
|
130 | ||
|
131 | return wrapper | |
|
132 | ||
|
133 | def apply_throttle(value): | |
|
134 | ||
|
135 | @Throttle(seconds=value) | |
|
136 | def fnThrottled(fn): | |
|
137 | fn() | |
|
138 | ||
|
139 | return fnThrottled | |
|
140 | ||
|
141 | @MPDecorator | |
|
142 | class Plotter(ProcessingUnit): | |
|
143 | ''' | |
|
144 | Proccessing unit to handle plot operations | |
|
145 | ''' | |
|
146 | ||
|
147 | def __init__(self): | |
|
148 | ||
|
149 | ProcessingUnit.__init__(self) | |
|
150 | ||
|
151 | def setup(self, **kwargs): | |
|
152 | ||
|
153 | self.connections = 0 | |
|
154 | self.web_address = kwargs.get('web_server', False) | |
|
155 | self.realtime = kwargs.get('realtime', False) | |
|
156 | self.localtime = kwargs.get('localtime', True) | |
|
157 | self.buffering = kwargs.get('buffering', True) | |
|
158 | self.throttle = kwargs.get('throttle', 2) | |
|
159 | self.exp_code = kwargs.get('exp_code', None) | |
|
160 | self.set_ready = apply_throttle(self.throttle) | |
|
161 | self.dates = [] | |
|
162 | self.data = PlotterData( | |
|
163 | self.plots, self.throttle, self.exp_code, self.buffering) | |
|
164 | self.isConfig = True | |
|
165 | ||
|
166 | def ready(self): | |
|
167 | ''' | |
|
168 | Set dataOut ready | |
|
169 | ''' | |
|
170 | ||
|
171 | self.data.ready = True | |
|
172 | self.dataOut.data_plt = self.data | |
|
173 | ||
|
174 | def run(self, realtime=True, localtime=True, buffering=True, | |
|
175 | throttle=2, exp_code=None, web_server=None): | |
|
176 | ||
|
177 | if not self.isConfig: | |
|
178 | self.setup(realtime=realtime, localtime=localtime, | |
|
179 | buffering=buffering, throttle=throttle, exp_code=exp_code, | |
|
180 | web_server=web_server) | |
|
181 | ||
|
182 | if self.web_address: | |
|
183 | log.success( | |
|
184 | 'Sending to web: {}'.format(self.web_address), | |
|
185 | self.name | |
|
186 | ) | |
|
187 | self.context = zmq.Context() | |
|
188 | self.sender_web = self.context.socket(zmq.REQ) | |
|
189 | self.sender_web.connect(self.web_address) | |
|
190 | self.poll = zmq.Poller() | |
|
191 | self.poll.register(self.sender_web, zmq.POLLIN) | |
|
192 | time.sleep(1) | |
|
193 | ||
|
194 | # t = Thread(target=self.event_monitor, args=(monitor,)) | |
|
195 | # t.start() | |
|
196 | ||
|
197 | self.dataOut = self.dataIn | |
|
198 | self.data.ready = False | |
|
199 | ||
|
200 | if self.dataOut.flagNoData: | |
|
201 | coerce = True | |
|
202 | else: | |
|
203 | coerce = False | |
|
204 | ||
|
205 | if self.dataOut.type == 'Parameters': | |
|
206 | tm = self.dataOut.utctimeInit | |
|
207 | else: | |
|
208 | tm = self.dataOut.utctime | |
|
209 | if self.dataOut.useLocalTime: | |
|
210 | if not self.localtime: | |
|
211 | tm += time.timezone | |
|
212 | dt = datetime.datetime.fromtimestamp(tm).date() | |
|
213 | else: | |
|
214 | if self.localtime: | |
|
215 | tm -= time.timezone | |
|
216 | dt = datetime.datetime.utcfromtimestamp(tm).date() | |
|
217 | if dt not in self.dates: | |
|
218 | if self.data: | |
|
219 | self.ready() | |
|
220 | self.data.setup() | |
|
221 | self.dates.append(dt) | |
|
222 | ||
|
223 | self.data.update(self.dataOut, tm) | |
|
224 | ||
|
225 | if False: # TODO check when publishers ends | |
|
226 | self.connections -= 1 | |
|
227 | if self.connections == 0 and dt in self.dates: | |
|
228 | self.data.ended = True | |
|
229 | self.ready() | |
|
230 | time.sleep(1) | |
|
231 | else: | |
|
232 | if self.realtime: | |
|
233 | self.ready() | |
|
234 | if self.web_address: | |
|
235 | retries = 5 | |
|
236 | while True: | |
|
237 | self.sender_web.send(self.data.jsonify()) | |
|
238 | socks = dict(self.poll.poll(5000)) | |
|
239 | if socks.get(self.sender_web) == zmq.POLLIN: | |
|
240 | reply = self.sender_web.recv_string() | |
|
241 | if reply == 'ok': | |
|
242 | log.log("Response from server ok", self.name) | |
|
243 | break | |
|
244 | else: | |
|
245 | log.warning( | |
|
246 | "Malformed reply from server: {}".format(reply), self.name) | |
|
247 | ||
|
248 | else: | |
|
249 | log.warning( | |
|
250 | "No response from server, retrying...", self.name) | |
|
251 | self.sender_web.setsockopt(zmq.LINGER, 0) | |
|
252 | self.sender_web.close() | |
|
253 | self.poll.unregister(self.sender_web) | |
|
254 | retries -= 1 | |
|
255 | if retries == 0: | |
|
256 | log.error( | |
|
257 | "Server seems to be offline, abandoning", self.name) | |
|
258 | self.sender_web = self.context.socket(zmq.REQ) | |
|
259 | self.sender_web.connect(self.web_address) | |
|
260 | self.poll.register(self.sender_web, zmq.POLLIN) | |
|
261 | time.sleep(1) | |
|
262 | break | |
|
263 | self.sender_web = self.context.socket(zmq.REQ) | |
|
264 | self.sender_web.connect(self.web_address) | |
|
265 | self.poll.register(self.sender_web, zmq.POLLIN) | |
|
266 | time.sleep(1) | |
|
267 | else: | |
|
268 | self.set_ready(self.ready, coerce=coerce) | |
|
269 | ||
|
270 | return | |
|
271 | ||
|
272 | def close(self): | |
|
273 | pass | |
|
274 | ||
|
275 | ||
|
276 | @MPDecorator | |
|
277 | class Plot(Operation): | |
|
278 | ''' | |
|
279 | Base class for Schain plotting operations | |
|
280 | ''' | |
|
281 | ||
|
282 | CODE = 'Figure' | |
|
283 | colormap = 'jro' | |
|
284 | bgcolor = 'white' | |
|
285 | __missing = 1E30 | |
|
286 | ||
|
287 | __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax', | |
|
288 | 'zlimits', 'xlabel', 'ylabel', 'xaxis', 'cb_label', 'title', | |
|
289 | 'colorbar', 'bgcolor', 'width', 'height', 'localtime', 'oneFigure', | |
|
290 | 'showprofile', 'decimation', 'pause'] | |
|
291 | ||
|
292 | def __init__(self): | |
|
293 | ||
|
294 | Operation.__init__(self) | |
|
295 | self.isConfig = False | |
|
296 | self.isPlotConfig = False | |
|
297 | ||
|
298 | def __fmtTime(self, x, pos): | |
|
299 | ''' | |
|
300 | ''' | |
|
301 | ||
|
302 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) | |
|
303 | ||
|
304 | def __setup(self, **kwargs): | |
|
305 | ''' | |
|
306 | Initialize variables | |
|
307 | ''' | |
|
308 | ||
|
309 | self.figures = [] | |
|
310 | self.axes = [] | |
|
311 | self.cb_axes = [] | |
|
312 | self.localtime = kwargs.pop('localtime', True) | |
|
313 | self.show = kwargs.get('show', True) | |
|
314 | self.save = kwargs.get('save', False) | |
|
315 | self.ftp = kwargs.get('ftp', False) | |
|
316 | self.colormap = kwargs.get('colormap', self.colormap) | |
|
317 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
|
318 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
|
319 | self.colormaps = kwargs.get('colormaps', None) | |
|
320 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |
|
321 | self.showprofile = kwargs.get('showprofile', False) | |
|
322 | self.title = kwargs.get('wintitle', self.CODE.upper()) | |
|
323 | self.cb_label = kwargs.get('cb_label', None) | |
|
324 | self.cb_labels = kwargs.get('cb_labels', None) | |
|
325 | self.labels = kwargs.get('labels', None) | |
|
326 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
|
327 | self.zmin = kwargs.get('zmin', None) | |
|
328 | self.zmax = kwargs.get('zmax', None) | |
|
329 | self.zlimits = kwargs.get('zlimits', None) | |
|
330 | self.xmin = kwargs.get('xmin', None) | |
|
331 | self.xmax = kwargs.get('xmax', None) | |
|
332 | self.xrange = kwargs.get('xrange', 12) | |
|
333 | self.xscale = kwargs.get('xscale', None) | |
|
334 | self.ymin = kwargs.get('ymin', None) | |
|
335 | self.ymax = kwargs.get('ymax', None) | |
|
336 | self.yscale = kwargs.get('yscale', None) | |
|
337 | self.xlabel = kwargs.get('xlabel', None) | |
|
338 | self.decimation = kwargs.get('decimation', None) | |
|
339 | self.showSNR = kwargs.get('showSNR', False) | |
|
340 | self.oneFigure = kwargs.get('oneFigure', True) | |
|
341 | self.width = kwargs.get('width', None) | |
|
342 | self.height = kwargs.get('height', None) | |
|
343 | self.colorbar = kwargs.get('colorbar', True) | |
|
344 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |
|
345 | self.channels = kwargs.get('channels', None) | |
|
346 | self.titles = kwargs.get('titles', []) | |
|
347 | self.polar = False | |
|
348 | self.grid = kwargs.get('grid', False) | |
|
349 | self.pause = kwargs.get('pause', False) | |
|
350 | self.save_labels = kwargs.get('save_labels', None) | |
|
351 | self.realtime = kwargs.get('realtime', True) | |
|
352 | self.buffering = kwargs.get('buffering', True) | |
|
353 | self.throttle = kwargs.get('throttle', 2) | |
|
354 | self.exp_code = kwargs.get('exp_code', None) | |
|
355 | self.__throttle_plot = apply_throttle(self.throttle) | |
|
356 | self.data = PlotterData( | |
|
357 | self.CODE, self.throttle, self.exp_code, self.buffering) | |
|
358 | ||
|
359 | def __setup_plot(self): | |
|
360 | ''' | |
|
361 | Common setup for all figures, here figures and axes are created | |
|
362 | ''' | |
|
363 | ||
|
364 | self.setup() | |
|
365 | ||
|
366 | self.time_label = 'LT' if self.localtime else 'UTC' | |
|
367 | if self.data.localtime: | |
|
368 | self.getDateTime = datetime.datetime.fromtimestamp | |
|
369 | else: | |
|
370 | self.getDateTime = datetime.datetime.utcfromtimestamp | |
|
371 | ||
|
372 | if self.width is None: | |
|
373 | self.width = 8 | |
|
374 | ||
|
375 | self.figures = [] | |
|
376 | self.axes = [] | |
|
377 | self.cb_axes = [] | |
|
378 | self.pf_axes = [] | |
|
379 | self.cmaps = [] | |
|
380 | ||
|
381 | size = '15%' if self.ncols == 1 else '30%' | |
|
382 | pad = '4%' if self.ncols == 1 else '8%' | |
|
383 | ||
|
384 | if self.oneFigure: | |
|
385 | if self.height is None: | |
|
386 | self.height = 1.4 * self.nrows + 1 | |
|
387 | fig = plt.figure(figsize=(self.width, self.height), | |
|
388 | edgecolor='k', | |
|
389 | facecolor='w') | |
|
390 | self.figures.append(fig) | |
|
391 | for n in range(self.nplots): | |
|
392 | ax = fig.add_subplot(self.nrows, self.ncols, | |
|
393 | n + 1, polar=self.polar) | |
|
394 | ax.tick_params(labelsize=8) | |
|
395 | ax.firsttime = True | |
|
396 | ax.index = 0 | |
|
397 | ax.press = None | |
|
398 | self.axes.append(ax) | |
|
399 | if self.showprofile: | |
|
400 | cax = self.__add_axes(ax, size=size, pad=pad) | |
|
401 | cax.tick_params(labelsize=8) | |
|
402 | self.pf_axes.append(cax) | |
|
403 | else: | |
|
404 | if self.height is None: | |
|
405 | self.height = 3 | |
|
406 | for n in range(self.nplots): | |
|
407 | fig = plt.figure(figsize=(self.width, self.height), | |
|
408 | edgecolor='k', | |
|
409 | facecolor='w') | |
|
410 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) | |
|
411 | ax.tick_params(labelsize=8) | |
|
412 | ax.firsttime = True | |
|
413 | ax.index = 0 | |
|
414 | ax.press = None | |
|
415 | self.figures.append(fig) | |
|
416 | self.axes.append(ax) | |
|
417 | if self.showprofile: | |
|
418 | cax = self.__add_axes(ax, size=size, pad=pad) | |
|
419 | cax.tick_params(labelsize=8) | |
|
420 | self.pf_axes.append(cax) | |
|
421 | ||
|
422 | for n in range(self.nrows): | |
|
423 | if self.colormaps is not None: | |
|
424 | cmap = plt.get_cmap(self.colormaps[n]) | |
|
425 | else: | |
|
426 | cmap = plt.get_cmap(self.colormap) | |
|
427 | cmap.set_bad(self.bgcolor, 1.) | |
|
428 | self.cmaps.append(cmap) | |
|
429 | ||
|
430 | for fig in self.figures: | |
|
431 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) | |
|
432 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) | |
|
433 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) | |
|
434 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) | |
|
435 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) | |
|
436 | if self.show: | |
|
437 | fig.show() | |
|
438 | ||
|
439 | def OnKeyPress(self, event): | |
|
440 | ''' | |
|
441 | Event for pressing keys (up, down) change colormap | |
|
442 | ''' | |
|
443 | ax = event.inaxes | |
|
444 | if ax in self.axes: | |
|
445 | if event.key == 'down': | |
|
446 | ax.index += 1 | |
|
447 | elif event.key == 'up': | |
|
448 | ax.index -= 1 | |
|
449 | if ax.index < 0: | |
|
450 | ax.index = len(CMAPS) - 1 | |
|
451 | elif ax.index == len(CMAPS): | |
|
452 | ax.index = 0 | |
|
453 | cmap = CMAPS[ax.index] | |
|
454 | ax.cbar.set_cmap(cmap) | |
|
455 | ax.cbar.draw_all() | |
|
456 | ax.plt.set_cmap(cmap) | |
|
457 | ax.cbar.patch.figure.canvas.draw() | |
|
458 | self.colormap = cmap.name | |
|
459 | ||
|
460 | def OnBtnScroll(self, event): | |
|
461 | ''' | |
|
462 | Event for scrolling, scale figure | |
|
463 | ''' | |
|
464 | cb_ax = event.inaxes | |
|
465 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
|
466 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
|
467 | pt = ax.cbar.ax.bbox.get_points()[:, 1] | |
|
468 | nrm = ax.cbar.norm | |
|
469 | vmin, vmax, p0, p1, pS = ( | |
|
470 | nrm.vmin, nrm.vmax, pt[0], pt[1], event.y) | |
|
471 | scale = 2 if event.step == 1 else 0.5 | |
|
472 | point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0) | |
|
473 | ax.cbar.norm.vmin = point - scale * (point - vmin) | |
|
474 | ax.cbar.norm.vmax = point - scale * (point - vmax) | |
|
475 | ax.plt.set_norm(ax.cbar.norm) | |
|
476 | ax.cbar.draw_all() | |
|
477 | ax.cbar.patch.figure.canvas.draw() | |
|
478 | ||
|
479 | def onBtnPress(self, event): | |
|
480 | ''' | |
|
481 | Event for mouse button press | |
|
482 | ''' | |
|
483 | cb_ax = event.inaxes | |
|
484 | if cb_ax is None: | |
|
485 | return | |
|
486 | ||
|
487 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
|
488 | cb_ax.press = event.x, event.y | |
|
489 | else: | |
|
490 | cb_ax.press = None | |
|
491 | ||
|
492 | def onMotion(self, event): | |
|
493 | ''' | |
|
494 | Event for move inside colorbar | |
|
495 | ''' | |
|
496 | cb_ax = event.inaxes | |
|
497 | if cb_ax is None: | |
|
498 | return | |
|
499 | if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
|
500 | return | |
|
501 | if cb_ax.press is None: | |
|
502 | return | |
|
503 | ||
|
504 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
|
505 | xprev, yprev = cb_ax.press | |
|
506 | dx = event.x - xprev | |
|
507 | dy = event.y - yprev | |
|
508 | cb_ax.press = event.x, event.y | |
|
509 | scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin | |
|
510 | perc = 0.03 | |
|
511 | ||
|
512 | if event.button == 1: | |
|
513 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) | |
|
514 | ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy) | |
|
515 | elif event.button == 3: | |
|
516 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) | |
|
517 | ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy) | |
|
518 | ||
|
519 | ax.cbar.draw_all() | |
|
520 | ax.plt.set_norm(ax.cbar.norm) | |
|
521 | ax.cbar.patch.figure.canvas.draw() | |
|
522 | ||
|
523 | def onBtnRelease(self, event): | |
|
524 | ''' | |
|
525 | Event for mouse button release | |
|
526 | ''' | |
|
527 | cb_ax = event.inaxes | |
|
528 | if cb_ax is not None: | |
|
529 | cb_ax.press = None | |
|
530 | ||
|
531 | def __add_axes(self, ax, size='30%', pad='8%'): | |
|
532 | ''' | |
|
533 | Add new axes to the given figure | |
|
534 | ''' | |
|
535 | divider = make_axes_locatable(ax) | |
|
536 | nax = divider.new_horizontal(size=size, pad=pad) | |
|
537 | ax.figure.add_axes(nax) | |
|
538 | return nax | |
|
539 | ||
|
540 | def setup(self): | |
|
541 | ''' | |
|
542 | This method should be implemented in the child class, the following | |
|
543 | attributes should be set: | |
|
544 | ||
|
545 | self.nrows: number of rows | |
|
546 | self.ncols: number of cols | |
|
547 | self.nplots: number of plots (channels or pairs) | |
|
548 | self.ylabel: label for Y axes | |
|
549 | self.titles: list of axes title | |
|
550 | ||
|
551 | ''' | |
|
552 | raise NotImplementedError | |
|
553 | ||
|
554 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
|
555 | ''' | |
|
556 | Create a masked array for missing data | |
|
557 | ''' | |
|
558 | if x_buffer.shape[0] < 2: | |
|
559 | return x_buffer, y_buffer, z_buffer | |
|
560 | ||
|
561 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
|
562 | x_median = numpy.median(deltas) | |
|
563 | ||
|
564 | index = numpy.where(deltas > 5 * x_median) | |
|
565 | ||
|
566 | if len(index[0]) != 0: | |
|
567 | z_buffer[::, index[0], ::] = self.__missing | |
|
568 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
|
569 | 0.99 * self.__missing, | |
|
570 | 1.01 * self.__missing) | |
|
571 | ||
|
572 | return x_buffer, y_buffer, z_buffer | |
|
573 | ||
|
574 | def decimate(self): | |
|
575 | ||
|
576 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
|
577 | dy = int(len(self.y) / self.decimation) + 1 | |
|
578 | ||
|
579 | # x = self.x[::dx] | |
|
580 | x = self.x | |
|
581 | y = self.y[::dy] | |
|
582 | z = self.z[::, ::, ::dy] | |
|
583 | ||
|
584 | return x, y, z | |
|
585 | ||
|
586 | def format(self): | |
|
587 | ''' | |
|
588 | Set min and max values, labels, ticks and titles | |
|
589 | ''' | |
|
590 | ||
|
591 | if self.xmin is None: | |
|
592 | xmin = self.data.min_time | |
|
593 | else: | |
|
594 | if self.xaxis is 'time': | |
|
595 | dt = self.getDateTime(self.data.min_time) | |
|
596 | xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - | |
|
597 | datetime.datetime(1970, 1, 1)).total_seconds() | |
|
598 | if self.data.localtime: | |
|
599 | xmin += time.timezone | |
|
600 | else: | |
|
601 | xmin = self.xmin | |
|
602 | ||
|
603 | if self.xmax is None: | |
|
604 | xmax = xmin + self.xrange * 60 * 60 | |
|
605 | else: | |
|
606 | if self.xaxis is 'time': | |
|
607 | dt = self.getDateTime(self.data.max_time) | |
|
608 | xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) - | |
|
609 | datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds() | |
|
610 | if self.data.localtime: | |
|
611 | xmax += time.timezone | |
|
612 | else: | |
|
613 | xmax = self.xmax | |
|
614 | ||
|
615 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) | |
|
616 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
|
617 | ||
|
618 | Y = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]) | |
|
619 | i = 1 if numpy.where( | |
|
620 | abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0] | |
|
621 | ystep = Y[i] / 10. | |
|
622 | ||
|
623 | if self.xaxis is not 'time': | |
|
624 | X = numpy.array([1, 2, 5, 10, 20, 50, 100, | |
|
625 | 200, 500, 1000, 2000, 5000])/2. | |
|
626 | i = 1 if numpy.where( | |
|
627 | abs(xmax-xmin) <= X)[0][0] < 0 else numpy.where(abs(xmax-xmin) <= X)[0][0] | |
|
628 | xstep = X[i] / 10. | |
|
629 | ||
|
630 | for n, ax in enumerate(self.axes): | |
|
631 | if ax.firsttime: | |
|
632 | ax.set_facecolor(self.bgcolor) | |
|
633 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) | |
|
634 | if self.xscale: | |
|
635 | ax.xaxis.set_major_formatter(FuncFormatter( | |
|
636 | lambda x, pos: '{0:g}'.format(x*self.xscale))) | |
|
637 | if self.xscale: | |
|
638 | ax.yaxis.set_major_formatter(FuncFormatter( | |
|
639 | lambda x, pos: '{0:g}'.format(x*self.yscale))) | |
|
640 | if self.xaxis is 'time': | |
|
641 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) | |
|
642 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
|
643 | else: | |
|
644 | ax.xaxis.set_major_locator(MultipleLocator(xstep)) | |
|
645 | if self.xlabel is not None: | |
|
646 | ax.set_xlabel(self.xlabel) | |
|
647 | ax.set_ylabel(self.ylabel) | |
|
648 | ax.firsttime = False | |
|
649 | if self.showprofile: | |
|
650 | self.pf_axes[n].set_ylim(ymin, ymax) | |
|
651 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
|
652 | self.pf_axes[n].set_xlabel('dB') | |
|
653 | self.pf_axes[n].grid(b=True, axis='x') | |
|
654 | [tick.set_visible(False) | |
|
655 | for tick in self.pf_axes[n].get_yticklabels()] | |
|
656 | if self.colorbar: | |
|
657 | ax.cbar = plt.colorbar( | |
|
658 | ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) | |
|
659 | ax.cbar.ax.tick_params(labelsize=8) | |
|
660 | ax.cbar.ax.press = None | |
|
661 | if self.cb_label: | |
|
662 | ax.cbar.set_label(self.cb_label, size=8) | |
|
663 | elif self.cb_labels: | |
|
664 | ax.cbar.set_label(self.cb_labels[n], size=8) | |
|
665 | else: | |
|
666 | ax.cbar = None | |
|
667 | if self.grid: | |
|
668 | ax.grid(True) | |
|
669 | ||
|
670 | if not self.polar: | |
|
671 | ax.set_xlim(xmin, xmax) | |
|
672 | ax.set_ylim(ymin, ymax) | |
|
673 | ax.set_title('{} {} {}'.format( | |
|
674 | self.titles[n], | |
|
675 | self.getDateTime(self.data.max_time).strftime( | |
|
676 | '%Y-%m-%dT%H:%M:%S'), | |
|
677 | self.time_label), | |
|
678 | size=8) | |
|
679 | else: | |
|
680 | ax.set_title('{}'.format(self.titles[n]), size=8) | |
|
681 | ax.set_ylim(0, 90) | |
|
682 | ax.set_yticks(numpy.arange(0, 90, 20)) | |
|
683 | ax.yaxis.labelpad = 40 | |
|
684 | ||
|
685 | def clear_figures(self): | |
|
686 | ''' | |
|
687 | Reset axes for redraw plots | |
|
688 | ''' | |
|
689 | ||
|
690 | for ax in self.axes: | |
|
691 | ax.clear() | |
|
692 | ax.firsttime = True | |
|
693 | if ax.cbar: | |
|
694 | ax.cbar.remove() | |
|
695 | ||
|
696 | def __plot(self): | |
|
697 | ''' | |
|
698 | Main function to plot, format and save figures | |
|
699 | ''' | |
|
700 | ||
|
701 | #try: | |
|
702 | self.plot() | |
|
703 | self.format() | |
|
704 | #except Exception as e: | |
|
705 | # log.warning('{} Plot could not be updated... check data'.format( | |
|
706 | # self.CODE), self.name) | |
|
707 | # log.error(str(e), '') | |
|
708 | # return | |
|
709 | ||
|
710 | for n, fig in enumerate(self.figures): | |
|
711 | if self.nrows == 0 or self.nplots == 0: | |
|
712 | log.warning('No data', self.name) | |
|
713 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') | |
|
714 | fig.canvas.manager.set_window_title(self.CODE) | |
|
715 | continue | |
|
716 | ||
|
717 | fig.tight_layout() | |
|
718 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
|
719 | self.getDateTime(self.data.max_time).strftime('%Y/%m/%d'))) | |
|
720 | fig.canvas.draw() | |
|
721 | ||
|
722 | if self.save: | |
|
723 | ||
|
724 | if self.save_labels: | |
|
725 | labels = self.save_labels | |
|
726 | else: | |
|
727 | labels = list(range(self.nrows)) | |
|
728 | ||
|
729 | if self.oneFigure: | |
|
730 | label = '' | |
|
731 | else: | |
|
732 | label = '-{}'.format(labels[n]) | |
|
733 | figname = os.path.join( | |
|
734 | self.save, | |
|
735 | self.CODE, | |
|
736 | '{}{}_{}.png'.format( | |
|
737 | self.CODE, | |
|
738 | label, | |
|
739 | self.getDateTime(self.data.max_time).strftime( | |
|
740 | '%Y%m%d_%H%M%S'), | |
|
741 | ) | |
|
742 | ) | |
|
743 | log.log('Saving figure: {}'.format(figname), self.name) | |
|
744 | if not os.path.isdir(os.path.dirname(figname)): | |
|
745 | os.makedirs(os.path.dirname(figname)) | |
|
746 | fig.savefig(figname) | |
|
747 | ||
|
748 | def plot(self): | |
|
749 | ''' | |
|
750 | Must be defined in the child class | |
|
751 | ''' | |
|
752 | raise NotImplementedError | |
|
753 | ||
|
754 | def run(self, dataOut, **kwargs): | |
|
755 | ||
|
756 | if dataOut.flagNoData and not dataOut.error: | |
|
757 | return dataOut | |
|
758 | ||
|
759 | if dataOut.error: | |
|
760 | coerce = True | |
|
761 | else: | |
|
762 | coerce = False | |
|
763 | ||
|
764 | if self.isConfig is False: | |
|
765 | self.__setup(**kwargs) | |
|
766 | self.data.setup() | |
|
767 | self.isConfig = True | |
|
768 | ||
|
769 | if dataOut.type == 'Parameters': | |
|
770 | tm = dataOut.utctimeInit | |
|
771 | else: | |
|
772 | tm = dataOut.utctime | |
|
773 | ||
|
774 | if dataOut.useLocalTime: | |
|
775 | if not self.localtime: | |
|
776 | tm += time.timezone | |
|
777 | else: | |
|
778 | if self.localtime: | |
|
779 | tm -= time.timezone | |
|
780 | ||
|
781 | if self.data and (tm - self.data.min_time) >= self.xrange*60*60: | |
|
782 | self.__plot() | |
|
783 | self.data.setup() | |
|
784 | self.clear_figures() | |
|
785 | ||
|
786 | self.data.update(dataOut, tm) | |
|
787 | ||
|
788 | if self.isPlotConfig is False: | |
|
789 | self.__setup_plot() | |
|
790 | self.isPlotConfig = True | |
|
791 | ||
|
792 | if self.realtime: | |
|
793 | self.__plot() | |
|
794 | else: | |
|
795 | self.__throttle_plot(self.__plot, coerce=coerce) | |
|
796 | ||
|
797 | figpause(0.001) | |
|
798 | ||
|
799 | def close(self): | |
|
800 | ||
|
801 | if self.data and self.pause: | |
|
802 | figpause(10) | |
|
803 |
@@ -1,116 +1,114 | |||
|
1 | 1 | # Byte-compiled / optimized / DLL files |
|
2 | 2 | __pycache__/ |
|
3 | 3 | *.py[cod] |
|
4 | 4 | *$py.class |
|
5 | 5 | |
|
6 | 6 | # C extensions |
|
7 | 7 | *.so |
|
8 | 8 | |
|
9 | 9 | # Distribution / packaging |
|
10 | 10 | .Python |
|
11 | 11 | env/ |
|
12 | 12 | build/ |
|
13 | 13 | develop-eggs/ |
|
14 | 14 | dist/ |
|
15 | 15 | downloads/ |
|
16 | 16 | eggs/ |
|
17 | 17 | .eggs/ |
|
18 | 18 | lib/ |
|
19 | 19 | lib64/ |
|
20 | 20 | parts/ |
|
21 | 21 | sdist/ |
|
22 | 22 | var/ |
|
23 | 23 | wheels/ |
|
24 | 24 | *.egg-info/ |
|
25 | 25 | .installed.cfg |
|
26 | 26 | *.egg |
|
27 | 27 | |
|
28 | 28 | # PyInstaller |
|
29 | 29 | # Usually these files are written by a python script from a template |
|
30 | 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. |
|
31 | 31 | *.manifest |
|
32 | 32 | *.spec |
|
33 | 33 | |
|
34 | 34 | # Installer logs |
|
35 | 35 | pip-log.txt |
|
36 | 36 | pip-delete-this-directory.txt |
|
37 | 37 | |
|
38 | 38 | # Unit test / coverage reports |
|
39 | 39 | htmlcov/ |
|
40 | 40 | .tox/ |
|
41 | 41 | .coverage |
|
42 | 42 | .coverage.* |
|
43 | 43 | .cache |
|
44 | 44 | nosetests.xml |
|
45 | 45 | coverage.xml |
|
46 | 46 | *,cover |
|
47 | 47 | .hypothesis/ |
|
48 | 48 | |
|
49 | 49 | # Translations |
|
50 | 50 | *.mo |
|
51 | 51 | *.pot |
|
52 | 52 | |
|
53 | 53 | # Django stuff: |
|
54 | 54 | *.log |
|
55 | 55 | local_settings.py |
|
56 | 56 | |
|
57 | 57 | # Flask stuff: |
|
58 | 58 | instance/ |
|
59 | 59 | .webassets-cache |
|
60 | 60 | |
|
61 | 61 | # Scrapy stuff: |
|
62 | 62 | .scrapy |
|
63 | 63 | |
|
64 | 64 | # Sphinx documentation |
|
65 | 65 | docs/_build/ |
|
66 | 66 | |
|
67 | 67 | # PyBuilder |
|
68 | 68 | target/ |
|
69 | 69 | |
|
70 | 70 | # Jupyter Notebook |
|
71 | 71 | .ipynb_checkpoints |
|
72 | 72 | |
|
73 | 73 | # pyenv |
|
74 | 74 | .python-version |
|
75 | 75 | |
|
76 | 76 | # celery beat schedule file |
|
77 | 77 | celerybeat-schedule |
|
78 | 78 | |
|
79 | 79 | # SageMath parsed files |
|
80 | 80 | *.sage.py |
|
81 | 81 | |
|
82 | 82 | # dotenv |
|
83 | 83 | .env |
|
84 | 84 | |
|
85 | 85 | # virtualenv |
|
86 | 86 | .venv |
|
87 | 87 | venv/ |
|
88 | 88 | ENV/ |
|
89 | 89 | |
|
90 | 90 | # Spyder project settings |
|
91 | 91 | .spyderproject |
|
92 | 92 | .spyproject |
|
93 | 93 | |
|
94 | 94 | # Rope project settings |
|
95 | 95 | .ropeproject |
|
96 | 96 | |
|
97 | 97 | # mkdocs documentation |
|
98 | 98 | /site |
|
99 | 99 | |
|
100 | 100 | # eclipse |
|
101 | 101 | .project |
|
102 | 102 | .pydevproject |
|
103 | 103 | # vscode |
|
104 | 104 | |
|
105 | 105 | .vscode |
|
106 | 106 | |
|
107 | 107 | schaingui/node_modules/ |
|
108 | 108 | schainpy/scripts/ |
|
109 | 109 | .svn/ |
|
110 | 110 | *.png |
|
111 | 111 | *.pyc |
|
112 | 112 | .vscode |
|
113 | 113 | trash |
|
114 | 114 | *.log |
|
115 | schainpy/scripts/testDigitalRF.py | |
|
116 | schainpy/scripts/testDigitalRFWriter.py |
@@ -1,112 +1,119 | |||
|
1 | 1 | ## CHANGELOG: |
|
2 | 2 | |
|
3 | ### 3.0 | |
|
4 | * Python 3.x compatible | |
|
5 | * New architecture with multiprocessing and IPC communication | |
|
6 | * Add @MPDecorator for multiprocessing Units and Operations | |
|
7 | * Added new type of operation `external` for non-locking operations | |
|
8 | * New plotting architecture with buffering/throttle capabilities to speed up plots | |
|
9 | ||
|
3 | 10 | ### 2.3 |
|
4 | 11 | * Added support for Madrigal formats (reading/writing). |
|
5 | 12 | * Added support for reading BLTR parameters (*.sswma). |
|
6 | 13 | * Added support for reading Julia format (*.dat). |
|
7 | 14 | * Added high order function `MPProject` for multiprocessing scripts. |
|
8 | 15 | * Added two new Processing Units `PublishData` and `ReceiverData` for receiving and sending dataOut through multiple ways (tcp, ipc, inproc). |
|
9 | 16 | * Added a new graphics Processing Unit `PlotterReceiver`. It is decoupled from normal processing sequence with support for data generated by multiprocessing scripts. |
|
10 | 17 | * Added support for sending realtime graphic to web server. |
|
11 | 18 | * GUI command `schain` is now `schainGUI`. |
|
12 | 19 | * Added a CLI tool named `schain`. |
|
13 | 20 | * Scripts templates can be now generated with `schain generate`. |
|
14 | 21 | * Now it is possible to search Processing Units and Operations with `schain search [module]` to get the right name and its allowed parameters. |
|
15 | 22 | * `schain xml` to run xml scripts. |
|
16 | 23 | * Added suggestions when parameters are poorly written. |
|
17 | 24 | * `Controller.start()` now runs in a different process than the process calling it. |
|
18 | 25 | * Added `schainpy.utils.log` for log standarization. |
|
19 | 26 | * Running script on online mode no longer ignores date and hour. Issue #1109. |
|
20 | 27 | * Added support for receving voltage data directly from JARS (tcp, ipc). |
|
21 | 28 | * Updated README for MAC OS GUI installation. |
|
22 | 29 | * Setup now installs numpy. |
|
23 | 30 | |
|
24 | 31 | ### 2.2.6 |
|
25 | 32 | * Graphics generated by the GUI are now the same as generated by scripts. Issue #1074. |
|
26 | 33 | * Added support for C extensions. |
|
27 | 34 | * Function `hildebrand_sehkon` optimized with a C wrapper. |
|
28 | 35 | * Numpy version updated. |
|
29 | 36 | * Migration to GIT. |
|
30 | 37 | |
|
31 | 38 | ### 2.2.5: |
|
32 | 39 | * splitProfiles and combineProfiles modules were added to VoltageProc and Signal Chain GUI. |
|
33 | 40 | * nProfiles of USRP data (hdf5) is the number of profiles thera are in one second. |
|
34 | 41 | * jroPlotter works directly with data objects instead of dictionaries |
|
35 | 42 | * script "schain" was added to Signal Chain installer |
|
36 | 43 | |
|
37 | 44 | ### 2.2.4.1: |
|
38 | 45 | * jroIO_usrp.py is update to read Sandra's data |
|
39 | 46 | * decimation in Spectra and RTI plots is always enabled. |
|
40 | 47 | * time* window option added to GUI |
|
41 | 48 | |
|
42 | 49 | ### 2.2.4: |
|
43 | 50 | * jroproc_spectra_lags.py added to schainpy |
|
44 | 51 | * Bug fixed in schainGUI: ProcUnit was created with the same id in some cases. |
|
45 | 52 | * Bug fixed in jroHeaderIO: Header size validation. |
|
46 | 53 | |
|
47 | 54 | ### 2.2.3.1: |
|
48 | 55 | * Filtering block by time has been added. |
|
49 | 56 | * Bug fixed plotting RTI, CoherenceMap and others using xmin and xmax parameters. The first day worked |
|
50 | 57 | properly but the next days did not. |
|
51 | 58 | |
|
52 | 59 | ### 2.2.3: |
|
53 | 60 | * Bug fixed in GUI: Error getting(reading) Code value |
|
54 | 61 | * Bug fixed in GUI: Flip option always needs channelList field |
|
55 | 62 | * Bug fixed in jrodata: when one branch modified a value in "dataOut" (example: dataOut.code) this value |
|
56 | 63 | was modified for every branch (because this was a reference). It was modified in data.copy() |
|
57 | 64 | * Bug fixed in jroproc_voltage.profileSelector(): rangeList replaces to profileRangeList. |
|
58 | 65 | |
|
59 | 66 | ### 2.2.2: |
|
60 | 67 | * VoltageProc: ProfileSelector, Reshape, Decoder with nTxs!=1 and getblock=True was tested |
|
61 | 68 | * Rawdata and testRawdata.py added to Signal Chain project |
|
62 | 69 | |
|
63 | 70 | ### 2.2.1: |
|
64 | 71 | * Bugs fixed in GUI |
|
65 | 72 | * Views were improved in GUI |
|
66 | 73 | * Support to MST* ISR experiments |
|
67 | 74 | * Bug fixed getting noise using hyldebrant. (minimum number of points > 20%) |
|
68 | 75 | * handleError added to jroplotter.py |
|
69 | 76 | |
|
70 | 77 | ### 2.2.0: |
|
71 | 78 | * GUI: use of external plotter |
|
72 | 79 | * Compatible with matplotlib 1.5.0 |
|
73 | 80 | |
|
74 | 81 | ### 2.1.5: |
|
75 | 82 | * serializer module added to Signal Chain |
|
76 | 83 | * jroplotter.py added to Signal Chain |
|
77 | 84 | |
|
78 | 85 | ### 2.1.4.2: |
|
79 | 86 | * A new Plotter Class was added |
|
80 | 87 | * Project.start() does not accept filename as a parameter anymore |
|
81 | 88 | |
|
82 | 89 | ### 2.1.4.1: |
|
83 | 90 | * Send notifications when an error different to ValueError is detected |
|
84 | 91 | |
|
85 | 92 | ### 2.1.4: |
|
86 | 93 | * Sending error notifications to signal chain administrator |
|
87 | 94 | * Login to email server added |
|
88 | 95 | |
|
89 | 96 | ### 2.1.3.3: |
|
90 | 97 | * Colored Button Icons were added to GUI |
|
91 | 98 | |
|
92 | 99 | ### 2.1.3.2: |
|
93 | 100 | * GUI: user interaction enhanced |
|
94 | 101 | * controller_api.py: Safe access to ControllerThead |
|
95 | 102 | |
|
96 | 103 | ### 2.1.3.1: |
|
97 | 104 | * GUI: every icon were resized |
|
98 | 105 | * jroproc_voltage.py: Print a message when "Read from code" option is selected and the code is not defined inside data file |
|
99 | 106 | |
|
100 | 107 | ### 2.1.3: |
|
101 | 108 | * jroplot_heispectra.py: SpectraHeisScope was not showing the right channels |
|
102 | 109 | * jroproc_voltage.py: Bug fixed selecting profiles (self.nProfiles took a wrong value), |
|
103 | 110 | Bug fixed selecting heights by block (selecting profiles instead heights) |
|
104 | 111 | * jroproc_voltage.py: New feature added: decoding data by block using FFT. |
|
105 | 112 | * jroIO_heispectra.py: Bug fixed in FitsReader. Using local Fits instance instead schainpy.mode.data.jrodata.Fits. |
|
106 | 113 | * jroIO_heispectra.py: Channel index list does not exist. |
|
107 | 114 | |
|
108 | 115 | ### 2.1.2: |
|
109 | 116 | * jroutils_ftp.py: Bug fixed, Any error sending file stopped the Server Thread |
|
110 | 117 | Server thread opens and closes remote server each time file list is sent |
|
111 | 118 | * jroplot_spectra.py: Noise path was not being created when noise data is saved. |
|
112 | 119 | * jroIO_base.py: startTime can be greater than endTime. Example: SpreadF [18:00 * 07:00] No newline at end of file |
@@ -1,506 +1,506 | |||
|
1 | 1 | """ |
|
2 | 2 | The admin module contains all administrative classes relating to the schain python api. |
|
3 | 3 | |
|
4 | 4 | The main role of this module is to send some reports. It contains a |
|
5 | 5 | notification class and a standard error handing class. |
|
6 | 6 | |
|
7 | 7 | $Id: admin.py 3966 2015-12-01 14:32:29Z miguel.urco $ |
|
8 | 8 | """ |
|
9 | 9 | import os |
|
10 | 10 | import sys |
|
11 | 11 | import time |
|
12 | 12 | import traceback |
|
13 | 13 | import smtplib |
|
14 | 14 | if sys.version[0] == '3': |
|
15 | 15 | from configparser import ConfigParser |
|
16 | 16 | else: |
|
17 | 17 | from ConfigParser import ConfigParser |
|
18 | 18 | import io |
|
19 | 19 | from threading import Thread |
|
20 | 20 | from multiprocessing import Process |
|
21 | 21 | from email.mime.text import MIMEText |
|
22 | 22 | from email.mime.application import MIMEApplication |
|
23 | 23 | from email.mime.multipart import MIMEMultipart |
|
24 | 24 | |
|
25 | 25 | import schainpy |
|
26 | 26 | from schainpy.utils import log |
|
27 |
from schainpy.model.graphics.jroplot_ |
|
|
27 | from schainpy.model.graphics.jroplot_base import popup | |
|
28 | 28 | |
|
29 | 29 | def get_path(): |
|
30 | 30 | ''' |
|
31 | 31 | Return schainpy path |
|
32 | 32 | ''' |
|
33 | 33 | |
|
34 | 34 | try: |
|
35 | 35 | root = __file__ |
|
36 | 36 | if os.path.islink(root): |
|
37 | 37 | root = os.path.realpath(root) |
|
38 | 38 | |
|
39 | 39 | return os.path.dirname(os.path.abspath(root)) |
|
40 | 40 | except: |
|
41 | 41 | log.error('I am sorry, but something is wrong... __file__ not found') |
|
42 | 42 | |
|
43 | 43 | class Alarm(Process): |
|
44 | 44 | ''' |
|
45 | 45 | modes: |
|
46 | 46 | 0 - All |
|
47 | 47 | 1 - Send email |
|
48 | 48 | 2 - Popup message |
|
49 | 49 | 3 - Sound alarm |
|
50 | 50 | 4 - Send to alarm system TODO |
|
51 | 51 | ''' |
|
52 | 52 | |
|
53 | 53 | def __init__(self, modes=[], **kwargs): |
|
54 | 54 | Process.__init__(self) |
|
55 | 55 | self.modes = modes |
|
56 | 56 | self.kwargs = kwargs |
|
57 | 57 | |
|
58 | 58 | @staticmethod |
|
59 | 59 | def play_sound(): |
|
60 | 60 | sound = os.path.join(get_path(), 'alarm1.oga') |
|
61 | 61 | if os.path.exists(sound): |
|
62 | 62 | for __ in range(2): |
|
63 | 63 | os.system('paplay {}'.format(sound)) |
|
64 | 64 | time.sleep(0.5) |
|
65 | 65 | else: |
|
66 | 66 | log.warning('Unable to play alarm, sound file not found', 'ADMIN') |
|
67 | 67 | |
|
68 | 68 | @staticmethod |
|
69 | 69 | def send_email(**kwargs): |
|
70 | 70 | notifier = SchainNotify() |
|
71 | 71 | print(kwargs) |
|
72 | 72 | notifier.notify(**kwargs) |
|
73 | 73 | |
|
74 | 74 | @staticmethod |
|
75 | 75 | def show_popup(message): |
|
76 | 76 | if isinstance(message, list): |
|
77 | 77 | message = message[-1] |
|
78 | 78 | popup(message) |
|
79 | 79 | |
|
80 | 80 | @staticmethod |
|
81 | 81 | def send_alarm(): |
|
82 | 82 | pass |
|
83 | 83 | |
|
84 | 84 | @staticmethod |
|
85 | 85 | def get_kwargs(kwargs, keys): |
|
86 | 86 | ret = {} |
|
87 | 87 | for key in keys: |
|
88 | 88 | ret[key] = kwargs[key] |
|
89 | 89 | return ret |
|
90 | 90 | |
|
91 | 91 | def run(self): |
|
92 | 92 | tasks = { |
|
93 | 93 | 1 : self.send_email, |
|
94 | 94 | 2 : self.show_popup, |
|
95 | 95 | 3 : self.play_sound, |
|
96 | 96 | 4 : self.send_alarm, |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | tasks_args = { |
|
100 | 100 | 1: ['email', 'message', 'subject', 'subtitle', 'filename'], |
|
101 | 101 | 2: ['message'], |
|
102 | 102 | 3: [], |
|
103 | 103 | 4: [], |
|
104 | 104 | } |
|
105 | 105 | procs = [] |
|
106 | 106 | for mode in self.modes: |
|
107 | 107 | if 0 in self.modes: |
|
108 | 108 | for x in tasks: |
|
109 | 109 | t = Thread(target=tasks[x], kwargs=self.get_kwargs(self.kwargs, tasks_args[x])) |
|
110 | 110 | t.start() |
|
111 | 111 | procs.append(t) |
|
112 | 112 | break |
|
113 | 113 | else: |
|
114 | 114 | t = Thread(target=tasks[mode], kwargs=self.get_kwargs(self.kwargs, tasks_args[mode])) |
|
115 | 115 | t.start() |
|
116 | 116 | procs.append(t) |
|
117 | 117 | for t in procs: |
|
118 | 118 | t.join() |
|
119 | 119 | |
|
120 | 120 | |
|
121 | 121 | class SchainConfigure(): |
|
122 | 122 | |
|
123 | 123 | __DEFAULT_ADMINISTRATOR_EMAIL = "juan.espinoza@jro.igp.gob.pe" |
|
124 | 124 | __DEFAULT_EMAIL_SERVER = "jro-zimbra.igp.gob.pe" |
|
125 | 125 | __DEFAULT_SENDER_EMAIL = "notifier-schain@jro.igp.gob.pe" |
|
126 | 126 | __DEFAULT_SENDER_PASS = "" |
|
127 | 127 | |
|
128 | 128 | __SCHAIN_ADMINISTRATOR_EMAIL = "CONTACT" |
|
129 | 129 | __SCHAIN_EMAIL_SERVER = "MAILSERVER" |
|
130 | 130 | __SCHAIN_SENDER_EMAIL = "MAILSERVER_ACCOUNT" |
|
131 | 131 | __SCHAIN_SENDER_PASS = "MAILSERVER_PASSWORD" |
|
132 | 132 | |
|
133 | 133 | def __init__(self, initFile = None): |
|
134 | 134 | |
|
135 | 135 | # Set configuration file |
|
136 | 136 | if (initFile == None): |
|
137 | 137 | self.__confFilePath = "/etc/schain.conf" |
|
138 | 138 | else: |
|
139 | 139 | self.__confFilePath = initFile |
|
140 | 140 | |
|
141 | 141 | # open configuration file |
|
142 | 142 | try: |
|
143 | 143 | self.__confFile = open(self.__confFilePath, "r") |
|
144 | 144 | except IOError: |
|
145 | 145 | # can't read from file - use all hard-coded values |
|
146 | 146 | self.__initFromHardCode() |
|
147 | 147 | return |
|
148 | 148 | |
|
149 | 149 | # create Parser using standard module ConfigParser |
|
150 | 150 | self.__parser = ConfigParser() |
|
151 | 151 | |
|
152 | 152 | # read conf file into a StringIO with "[madrigal]\n" section heading prepended |
|
153 | 153 | strConfFile = io.StringIO("[schain]\n" + self.__confFile.read()) |
|
154 | 154 | |
|
155 | 155 | # parse StringIO configuration file |
|
156 | 156 | self.__parser.readfp(strConfFile) |
|
157 | 157 | |
|
158 | 158 | # read information from configuration file |
|
159 | 159 | self.__readConfFile() |
|
160 | 160 | |
|
161 | 161 | # close conf file |
|
162 | 162 | self.__confFile.close() |
|
163 | 163 | |
|
164 | 164 | |
|
165 | 165 | def __initFromHardCode(self): |
|
166 | 166 | |
|
167 | 167 | self.__sender_email = self.__DEFAULT_SENDER_EMAIL |
|
168 | 168 | self.__sender_pass = self.__DEFAULT_SENDER_PASS |
|
169 | 169 | self.__admin_email = self.__DEFAULT_ADMINISTRATOR_EMAIL |
|
170 | 170 | self.__email_server = self.__DEFAULT_EMAIL_SERVER |
|
171 | 171 | |
|
172 | 172 | def __readConfFile(self): |
|
173 | 173 | """__readConfFile is a private helper function that reads information from the parsed config file. |
|
174 | 174 | |
|
175 | 175 | Inputs: None |
|
176 | 176 | |
|
177 | 177 | Returns: Void. |
|
178 | 178 | |
|
179 | 179 | Affects: Initializes class member variables that are found in the config file. |
|
180 | 180 | |
|
181 | 181 | Exceptions: MadrigalError thrown if any key not found. |
|
182 | 182 | """ |
|
183 | 183 | |
|
184 | 184 | # get the sender email |
|
185 | 185 | try: |
|
186 | 186 | self.__sender_email = self.__parser.get("schain", self.__SCHAIN_SENDER_EMAIL) |
|
187 | 187 | except: |
|
188 | 188 | self.__sender_email = self.__DEFAULT_SENDER_EMAIL |
|
189 | 189 | |
|
190 | 190 | # get the sender password |
|
191 | 191 | try: |
|
192 | 192 | self.__sender_pass = self.__parser.get("schain", self.__SCHAIN_SENDER_PASS) |
|
193 | 193 | except: |
|
194 | 194 | self.__sender_pass = self.__DEFAULT_SENDER_PASS |
|
195 | 195 | |
|
196 | 196 | # get the administrator email |
|
197 | 197 | try: |
|
198 | 198 | self.__admin_email = self.__parser.get("schain", self.__SCHAIN_ADMINISTRATOR_EMAIL) |
|
199 | 199 | except: |
|
200 | 200 | self.__admin_email = self.__DEFAULT_ADMINISTRATOR_EMAIL |
|
201 | 201 | |
|
202 | 202 | # get the server email |
|
203 | 203 | try: |
|
204 | 204 | self.__email_server = self.__parser.get("schain", self.__SCHAIN_EMAIL_SERVER) |
|
205 | 205 | except: |
|
206 | 206 | self.__email_server = self.__DEFAULT_EMAIL_SERVER |
|
207 | 207 | |
|
208 | 208 | def getEmailServer(self): |
|
209 | 209 | |
|
210 | 210 | return self.__email_server |
|
211 | 211 | |
|
212 | 212 | def getSenderEmail(self): |
|
213 | 213 | |
|
214 | 214 | return self.__sender_email |
|
215 | 215 | |
|
216 | 216 | def getSenderPass(self): |
|
217 | 217 | |
|
218 | 218 | return self.__sender_pass |
|
219 | 219 | |
|
220 | 220 | def getAdminEmail(self): |
|
221 | 221 | |
|
222 | 222 | return self.__admin_email |
|
223 | 223 | |
|
224 | 224 | class SchainNotify: |
|
225 | 225 | """SchainNotify is an object used to send messages to an administrator about a Schain software. |
|
226 | 226 | |
|
227 | 227 | This object provides functions needed to send messages to an administrator about a Schain , for now |
|
228 | 228 | only sendAlert, which sends an email to the site administrator found is ADMIN_EMAIL |
|
229 | 229 | |
|
230 | 230 | Usage example: |
|
231 | 231 | |
|
232 | 232 | import schainpy.admin |
|
233 | 233 | |
|
234 | 234 | try: |
|
235 | 235 | |
|
236 | 236 | adminObj = schainpy.admin.SchainNotify() |
|
237 | 237 | adminObj.sendAlert('This is important!', 'Important Message') |
|
238 | 238 | |
|
239 | 239 | except schainpy.admin.SchainError, e: |
|
240 | 240 | |
|
241 | 241 | print e.getExceptionStr() |
|
242 | 242 | |
|
243 | 243 | |
|
244 | 244 | Non-standard Python modules used: |
|
245 | 245 | None |
|
246 | 246 | |
|
247 | 247 | Exceptions thrown: None - Note that SchainNotify tries every trick it knows to avoid |
|
248 | 248 | throwing exceptions, since this is the class that will generally be called when there is a problem. |
|
249 | 249 | |
|
250 | 250 | Change history: |
|
251 | 251 | |
|
252 | 252 | Written by "Miguel Urco":mailto:miguel.urco@jro.igp.gob.pe Dec. 1, 2015 |
|
253 | 253 | """ |
|
254 | 254 | |
|
255 | 255 | #constants |
|
256 | 256 | |
|
257 | 257 | def __init__(self): |
|
258 | 258 | """__init__ initializes SchainNotify by getting some basic information from SchainDB and SchainSite. |
|
259 | 259 | |
|
260 | 260 | Note that SchainNotify tries every trick it knows to avoid throwing exceptions, since |
|
261 | 261 | this is the class that will generally be called when there is a problem. |
|
262 | 262 | |
|
263 | 263 | Inputs: Existing SchainDB object, by default = None. |
|
264 | 264 | |
|
265 | 265 | Returns: void |
|
266 | 266 | |
|
267 | 267 | Affects: Initializes self.__binDir. |
|
268 | 268 | |
|
269 | 269 | Exceptions: None. |
|
270 | 270 | """ |
|
271 | 271 | |
|
272 | 272 | # note that the main configuration file is unavailable |
|
273 | 273 | # the best that can be done is send an email to root using localhost mailserver |
|
274 | 274 | confObj = SchainConfigure() |
|
275 | 275 | |
|
276 | 276 | self.__emailFromAddress = confObj.getSenderEmail() |
|
277 | 277 | self.__emailPass = confObj.getSenderPass() |
|
278 | 278 | self.__emailToAddress = confObj.getAdminEmail() |
|
279 | 279 | self.__emailServer = confObj.getEmailServer() |
|
280 | 280 | |
|
281 | 281 | def sendEmail(self, email_from, email_to, subject='Error running ...', message="", subtitle="", filename="", html_format=True): |
|
282 | 282 | |
|
283 | 283 | if not email_to: |
|
284 | 284 | return 0 |
|
285 | 285 | |
|
286 | 286 | if not self.__emailServer: |
|
287 | 287 | return 0 |
|
288 | 288 | |
|
289 | 289 | log.success('Sending email to {}...'.format(email_to), 'System') |
|
290 | 290 | |
|
291 | 291 | msg = MIMEMultipart() |
|
292 | 292 | msg['Subject'] = subject |
|
293 | 293 | msg['From'] = "(Python SChain API): " + email_from |
|
294 | 294 | msg['Reply-to'] = email_from |
|
295 | 295 | msg['To'] = email_to |
|
296 | 296 | |
|
297 | 297 | # That is what u see if dont have an email reader: |
|
298 | 298 | msg.preamble = 'SChainPy' |
|
299 | 299 | |
|
300 | 300 | if html_format: |
|
301 | 301 | message = "<h1> %s </h1>" %subject + "<h3>" + subtitle.replace("\n", "</h3><h3>\n") + "</h3>" + message.replace("\n", "<br>\n") |
|
302 | 302 | message = "<html>\n" + message + '</html>' |
|
303 | 303 | |
|
304 | 304 | # This is the textual part: |
|
305 | 305 | part = MIMEText(message, "html") |
|
306 | 306 | else: |
|
307 | 307 | message = subject + "\n" + subtitle + "\n" + message |
|
308 | 308 | part = MIMEText(message) |
|
309 | 309 | |
|
310 | 310 | msg.attach(part) |
|
311 | 311 | |
|
312 | 312 | if filename and os.path.isfile(filename): |
|
313 | 313 | # This is the binary part(The Attachment): |
|
314 | 314 | part = MIMEApplication(open(filename,"rb").read()) |
|
315 | 315 | part.add_header('Content-Disposition', |
|
316 | 316 | 'attachment', |
|
317 | 317 | filename=os.path.basename(filename)) |
|
318 | 318 | msg.attach(part) |
|
319 | 319 | |
|
320 | 320 | # Create an instance in SMTP server |
|
321 | 321 | try: |
|
322 | 322 | smtp = smtplib.SMTP(self.__emailServer) |
|
323 | 323 | except: |
|
324 | 324 | log.error('Could not connect to server {}'.format(self.__emailServer), 'System') |
|
325 | 325 | return 0 |
|
326 | 326 | |
|
327 | 327 | # Start the server: |
|
328 | 328 | # smtp.ehlo() |
|
329 | 329 | if self.__emailPass: |
|
330 | 330 | smtp.login(self.__emailFromAddress, self.__emailPass) |
|
331 | 331 | |
|
332 | 332 | # Send the email |
|
333 | 333 | try: |
|
334 | 334 | smtp.sendmail(msg['From'], msg['To'], msg.as_string()) |
|
335 | 335 | except: |
|
336 | 336 | log.error('Could not send the email to {}'.format(msg['To']), 'System') |
|
337 | 337 | smtp.quit() |
|
338 | 338 | return 0 |
|
339 | 339 | |
|
340 | 340 | smtp.quit() |
|
341 | 341 | |
|
342 | 342 | log.success('Email sent ', 'System') |
|
343 | 343 | |
|
344 | 344 | return 1 |
|
345 | 345 | |
|
346 | 346 | def sendAlert(self, message, subject = "", subtitle="", filename=""): |
|
347 | 347 | """sendAlert sends an email with the given message and optional title. |
|
348 | 348 | |
|
349 | 349 | Inputs: message (string), and optional title (string) |
|
350 | 350 | |
|
351 | 351 | Returns: void |
|
352 | 352 | |
|
353 | 353 | Affects: none |
|
354 | 354 | |
|
355 | 355 | Exceptions: None. |
|
356 | 356 | """ |
|
357 | 357 | |
|
358 | 358 | if not self.__emailToAddress: |
|
359 | 359 | return 0 |
|
360 | 360 | |
|
361 | 361 | print("***** Sending alert to %s *****" %self.__emailToAddress) |
|
362 | 362 | # set up message |
|
363 | 363 | |
|
364 | 364 | sent=self.sendEmail(email_from=self.__emailFromAddress, |
|
365 | 365 | email_to=self.__emailToAddress, |
|
366 | 366 | subject=subject, |
|
367 | 367 | message=message, |
|
368 | 368 | subtitle=subtitle, |
|
369 | 369 | filename=filename) |
|
370 | 370 | |
|
371 | 371 | if not sent: |
|
372 | 372 | return 0 |
|
373 | 373 | |
|
374 | 374 | return 1 |
|
375 | 375 | |
|
376 | 376 | def notify(self, email, message, subject = "", subtitle="", filename=""): |
|
377 | 377 | """notify sends an email with the given message and title to email. |
|
378 | 378 | |
|
379 | 379 | Inputs: email (string), message (string), and subject (string) |
|
380 | 380 | |
|
381 | 381 | Returns: void |
|
382 | 382 | |
|
383 | 383 | Affects: none |
|
384 | 384 | |
|
385 | 385 | Exceptions: None. |
|
386 | 386 | """ |
|
387 | 387 | |
|
388 | 388 | if email is None: |
|
389 | 389 | email = self.__emailToAddress |
|
390 | 390 | |
|
391 | 391 | self.sendEmail( |
|
392 | 392 | email_from=self.__emailFromAddress, |
|
393 | 393 | email_to=email, |
|
394 | 394 | subject=subject, |
|
395 | 395 | message=message, |
|
396 | 396 | subtitle=subtitle, |
|
397 | 397 | filename=filename |
|
398 | 398 | ) |
|
399 | 399 | |
|
400 | 400 | |
|
401 | 401 | class SchainError(Exception): |
|
402 | 402 | """SchainError is an exception class that is thrown for all known errors using Schain Py lib. |
|
403 | 403 | |
|
404 | 404 | Usage example: |
|
405 | 405 | |
|
406 | 406 | import sys, traceback |
|
407 | 407 | import schainpy.admin |
|
408 | 408 | |
|
409 | 409 | try: |
|
410 | 410 | |
|
411 | 411 | test = open('ImportantFile.txt', 'r') |
|
412 | 412 | |
|
413 | 413 | except: |
|
414 | 414 | |
|
415 | 415 | raise schainpy.admin.SchainError('ImportantFile.txt not opened!', |
|
416 | 416 | traceback.format_exception(sys.exc_info()[0], |
|
417 | 417 | sys.exc_info()[1], |
|
418 | 418 | sys.exc_info()[2])) |
|
419 | 419 | """ |
|
420 | 420 | |
|
421 | 421 | |
|
422 | 422 | def __init__(self, strInterpretation, exceptionList=None): |
|
423 | 423 | """ __init__ gathers the interpretation string along with all information from sys.exc_info(). |
|
424 | 424 | |
|
425 | 425 | Inputs: |
|
426 | 426 | strIntepretation - A string representing the programmer's interpretation of |
|
427 | 427 | why the exception occurred |
|
428 | 428 | |
|
429 | 429 | exceptionList - a list of strings completely describing the exception. |
|
430 | 430 | Generated by traceback.format_exception(sys.exc_info()[0], |
|
431 | 431 | sys.exc_info()[1], |
|
432 | 432 | sys.exc_info()[2]) |
|
433 | 433 | |
|
434 | 434 | Returns: Void. |
|
435 | 435 | |
|
436 | 436 | Affects: Initializes class member variables _strInterp, _strExcList. |
|
437 | 437 | |
|
438 | 438 | Exceptions: None. |
|
439 | 439 | """ |
|
440 | 440 | |
|
441 | 441 | if not exceptionList: |
|
442 | 442 | exceptionList = traceback.format_exception(sys.exc_info()[0], |
|
443 | 443 | sys.exc_info()[1], |
|
444 | 444 | sys.exc_info()[2]) |
|
445 | 445 | |
|
446 | 446 | self._strInterp = strInterpretation |
|
447 | 447 | self._strExcList = exceptionList |
|
448 | 448 | |
|
449 | 449 | |
|
450 | 450 | def getExceptionStr(self): |
|
451 | 451 | """ getExceptionStr returns a formatted string ready for printing completely describing the exception. |
|
452 | 452 | |
|
453 | 453 | Inputs: None |
|
454 | 454 | |
|
455 | 455 | Returns: A formatted string ready for printing completely describing the exception. |
|
456 | 456 | |
|
457 | 457 | Affects: None |
|
458 | 458 | |
|
459 | 459 | Exceptions: None. |
|
460 | 460 | """ |
|
461 | 461 | excStr = '' |
|
462 | 462 | excStr = excStr + self._strInterp + '\n\n' |
|
463 | 463 | |
|
464 | 464 | if self._strExcList != None: |
|
465 | 465 | for item in self._strExcList: |
|
466 | 466 | excStr = excStr + str(item) + '\n' |
|
467 | 467 | |
|
468 | 468 | return excStr |
|
469 | 469 | |
|
470 | 470 | def __str__(self): |
|
471 | 471 | |
|
472 | 472 | return(self.getExceptionStr()) |
|
473 | 473 | |
|
474 | 474 | |
|
475 | 475 | def getExceptionHtml(self): |
|
476 | 476 | """ getExceptionHtml returns an Html formatted string completely describing the exception. |
|
477 | 477 | |
|
478 | 478 | Inputs: None |
|
479 | 479 | |
|
480 | 480 | Returns: A formatted string ready for printing completely describing the exception. |
|
481 | 481 | |
|
482 | 482 | Affects: None |
|
483 | 483 | |
|
484 | 484 | Exceptions: None. |
|
485 | 485 | """ |
|
486 | 486 | |
|
487 | 487 | excStr = '<BR>The following Schain Python exception has occurred:\n<BR>' |
|
488 | 488 | excStr = excStr + self._strInterp + '\n<BR>\n' |
|
489 | 489 | |
|
490 | 490 | if self._strExcList != None: |
|
491 | 491 | for item in self._strExcList: |
|
492 | 492 | excStr = excStr + str(item) + '\n<BR>' |
|
493 | 493 | |
|
494 | 494 | return excStr |
|
495 | 495 | |
|
496 | 496 | class SchainWarning(Exception): |
|
497 | 497 | pass |
|
498 | 498 | |
|
499 | 499 | |
|
500 | 500 | if __name__ == '__main__': |
|
501 | 501 | |
|
502 | 502 | test = SchainNotify() |
|
503 | 503 | |
|
504 | 504 | test.sendAlert('This is a message from the python module SchainNotify', 'Test from SchainNotify') |
|
505 | 505 | |
|
506 | 506 | print('Hopefully message sent - check.') No newline at end of file |
@@ -1,1265 +1,1263 | |||
|
1 | 1 | ''' |
|
2 | 2 | Updated on January , 2018, for multiprocessing purposes |
|
3 | 3 | Author: Sergio Cortez |
|
4 | 4 | Created on September , 2012 |
|
5 | 5 | ''' |
|
6 | 6 | from platform import python_version |
|
7 | 7 | import sys |
|
8 | 8 | import ast |
|
9 | 9 | import datetime |
|
10 | 10 | import traceback |
|
11 | 11 | import math |
|
12 | 12 | import time |
|
13 | 13 | import zmq |
|
14 | 14 | from multiprocessing import Process, cpu_count |
|
15 | 15 | from threading import Thread |
|
16 | 16 | from xml.etree.ElementTree import ElementTree, Element, SubElement, tostring |
|
17 | 17 | from xml.dom import minidom |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | from schainpy.admin import Alarm, SchainWarning |
|
21 | 21 | |
|
22 | 22 | ### Temporary imports!!! |
|
23 | 23 | # from schainpy.model import * |
|
24 | 24 | from schainpy.model.io import * |
|
25 | 25 | from schainpy.model.graphics import * |
|
26 | 26 | from schainpy.model.proc.jroproc_base import * |
|
27 | 27 | from schainpy.model.proc.bltrproc_parameters import * |
|
28 | 28 | from schainpy.model.proc.jroproc_spectra import * |
|
29 | 29 | from schainpy.model.proc.jroproc_voltage import * |
|
30 | 30 | from schainpy.model.proc.jroproc_parameters import * |
|
31 | 31 | from schainpy.model.utils.jroutils_publish import * |
|
32 | 32 | from schainpy.utils import log |
|
33 | 33 | ### |
|
34 | 34 | |
|
35 | 35 | DTYPES = { |
|
36 | 36 | 'Voltage': '.r', |
|
37 | 37 | 'Spectra': '.pdata' |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | def MPProject(project, n=cpu_count()): |
|
42 | 42 | ''' |
|
43 | 43 | Project wrapper to run schain in n processes |
|
44 | 44 | ''' |
|
45 | 45 | |
|
46 | 46 | rconf = project.getReadUnitObj() |
|
47 | 47 | op = rconf.getOperationObj('run') |
|
48 | 48 | dt1 = op.getParameterValue('startDate') |
|
49 | 49 | dt2 = op.getParameterValue('endDate') |
|
50 | 50 | tm1 = op.getParameterValue('startTime') |
|
51 | 51 | tm2 = op.getParameterValue('endTime') |
|
52 | 52 | days = (dt2 - dt1).days |
|
53 | 53 | |
|
54 | 54 | for day in range(days + 1): |
|
55 | 55 | skip = 0 |
|
56 | 56 | cursor = 0 |
|
57 | 57 | processes = [] |
|
58 | 58 | dt = dt1 + datetime.timedelta(day) |
|
59 | 59 | dt_str = dt.strftime('%Y/%m/%d') |
|
60 | 60 | reader = JRODataReader() |
|
61 | 61 | paths, files = reader.searchFilesOffLine(path=rconf.path, |
|
62 | 62 | startDate=dt, |
|
63 | 63 | endDate=dt, |
|
64 | 64 | startTime=tm1, |
|
65 | 65 | endTime=tm2, |
|
66 | 66 | ext=DTYPES[rconf.datatype]) |
|
67 | 67 | nFiles = len(files) |
|
68 | 68 | if nFiles == 0: |
|
69 | 69 | continue |
|
70 | 70 | skip = int(math.ceil(nFiles / n)) |
|
71 | 71 | while nFiles > cursor * skip: |
|
72 | 72 | rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor, |
|
73 | 73 | skip=skip) |
|
74 | 74 | p = project.clone() |
|
75 | 75 | p.start() |
|
76 | 76 | processes.append(p) |
|
77 | 77 | cursor += 1 |
|
78 | 78 | |
|
79 | 79 | def beforeExit(exctype, value, trace): |
|
80 | 80 | for process in processes: |
|
81 | 81 | process.terminate() |
|
82 | 82 | process.join() |
|
83 | 83 | print(traceback.print_tb(trace)) |
|
84 | 84 | |
|
85 | 85 | sys.excepthook = beforeExit |
|
86 | 86 | |
|
87 | 87 | for process in processes: |
|
88 | 88 | process.join() |
|
89 | 89 | process.terminate() |
|
90 | 90 | |
|
91 | 91 | time.sleep(3) |
|
92 | 92 | |
|
93 | 93 | def wait(context): |
|
94 | 94 | |
|
95 | 95 | time.sleep(1) |
|
96 | 96 | c = zmq.Context() |
|
97 | 97 | receiver = c.socket(zmq.SUB) |
|
98 | 98 | receiver.connect('ipc:///tmp/schain_{}_pub'.format(self.id)) |
|
99 | 99 | receiver.setsockopt(zmq.SUBSCRIBE, self.id.encode()) |
|
100 | log.error('startinggg') | |
|
101 | 100 | msg = receiver.recv_multipart()[1] |
|
102 | #log.error(msg) | |
|
103 | 101 | context.terminate() |
|
104 | 102 | |
|
105 | 103 | class ParameterConf(): |
|
106 | 104 | |
|
107 | 105 | id = None |
|
108 | 106 | name = None |
|
109 | 107 | value = None |
|
110 | 108 | format = None |
|
111 | 109 | |
|
112 | 110 | __formated_value = None |
|
113 | 111 | |
|
114 | 112 | ELEMENTNAME = 'Parameter' |
|
115 | 113 | |
|
116 | 114 | def __init__(self): |
|
117 | 115 | |
|
118 | 116 | self.format = 'str' |
|
119 | 117 | |
|
120 | 118 | def getElementName(self): |
|
121 | 119 | |
|
122 | 120 | return self.ELEMENTNAME |
|
123 | 121 | |
|
124 | 122 | def getValue(self): |
|
125 | 123 | |
|
126 | 124 | value = self.value |
|
127 | 125 | format = self.format |
|
128 | 126 | |
|
129 | 127 | if self.__formated_value != None: |
|
130 | 128 | |
|
131 | 129 | return self.__formated_value |
|
132 | 130 | |
|
133 | 131 | if format == 'obj': |
|
134 | 132 | return value |
|
135 | 133 | |
|
136 | 134 | if format == 'str': |
|
137 | 135 | self.__formated_value = str(value) |
|
138 | 136 | return self.__formated_value |
|
139 | 137 | |
|
140 | 138 | if value == '': |
|
141 | 139 | raise ValueError('%s: This parameter value is empty' % self.name) |
|
142 | 140 | |
|
143 | 141 | if format == 'list': |
|
144 | 142 | strList = value.split(',') |
|
145 | 143 | |
|
146 | 144 | self.__formated_value = strList |
|
147 | 145 | |
|
148 | 146 | return self.__formated_value |
|
149 | 147 | |
|
150 | 148 | if format == 'intlist': |
|
151 | 149 | ''' |
|
152 | 150 | Example: |
|
153 | 151 | value = (0,1,2) |
|
154 | 152 | ''' |
|
155 | 153 | |
|
156 | 154 | new_value = ast.literal_eval(value) |
|
157 | 155 | |
|
158 | 156 | if type(new_value) not in (tuple, list): |
|
159 | 157 | new_value = [int(new_value)] |
|
160 | 158 | |
|
161 | 159 | self.__formated_value = new_value |
|
162 | 160 | |
|
163 | 161 | return self.__formated_value |
|
164 | 162 | |
|
165 | 163 | if format == 'floatlist': |
|
166 | 164 | ''' |
|
167 | 165 | Example: |
|
168 | 166 | value = (0.5, 1.4, 2.7) |
|
169 | 167 | ''' |
|
170 | 168 | |
|
171 | 169 | new_value = ast.literal_eval(value) |
|
172 | 170 | |
|
173 | 171 | if type(new_value) not in (tuple, list): |
|
174 | 172 | new_value = [float(new_value)] |
|
175 | 173 | |
|
176 | 174 | self.__formated_value = new_value |
|
177 | 175 | |
|
178 | 176 | return self.__formated_value |
|
179 | 177 | |
|
180 | 178 | if format == 'date': |
|
181 | 179 | strList = value.split('/') |
|
182 | 180 | intList = [int(x) for x in strList] |
|
183 | 181 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
184 | 182 | |
|
185 | 183 | self.__formated_value = date |
|
186 | 184 | |
|
187 | 185 | return self.__formated_value |
|
188 | 186 | |
|
189 | 187 | if format == 'time': |
|
190 | 188 | strList = value.split(':') |
|
191 | 189 | intList = [int(x) for x in strList] |
|
192 | 190 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
193 | 191 | |
|
194 | 192 | self.__formated_value = time |
|
195 | 193 | |
|
196 | 194 | return self.__formated_value |
|
197 | 195 | |
|
198 | 196 | if format == 'pairslist': |
|
199 | 197 | ''' |
|
200 | 198 | Example: |
|
201 | 199 | value = (0,1),(1,2) |
|
202 | 200 | ''' |
|
203 | 201 | |
|
204 | 202 | new_value = ast.literal_eval(value) |
|
205 | 203 | |
|
206 | 204 | if type(new_value) not in (tuple, list): |
|
207 | 205 | raise ValueError('%s has to be a tuple or list of pairs' % value) |
|
208 | 206 | |
|
209 | 207 | if type(new_value[0]) not in (tuple, list): |
|
210 | 208 | if len(new_value) != 2: |
|
211 | 209 | raise ValueError('%s has to be a tuple or list of pairs' % value) |
|
212 | 210 | new_value = [new_value] |
|
213 | 211 | |
|
214 | 212 | for thisPair in new_value: |
|
215 | 213 | if len(thisPair) != 2: |
|
216 | 214 | raise ValueError('%s has to be a tuple or list of pairs' % value) |
|
217 | 215 | |
|
218 | 216 | self.__formated_value = new_value |
|
219 | 217 | |
|
220 | 218 | return self.__formated_value |
|
221 | 219 | |
|
222 | 220 | if format == 'multilist': |
|
223 | 221 | ''' |
|
224 | 222 | Example: |
|
225 | 223 | value = (0,1,2),(3,4,5) |
|
226 | 224 | ''' |
|
227 | 225 | multiList = ast.literal_eval(value) |
|
228 | 226 | |
|
229 | 227 | if type(multiList[0]) == int: |
|
230 | 228 | multiList = ast.literal_eval('(' + value + ')') |
|
231 | 229 | |
|
232 | 230 | self.__formated_value = multiList |
|
233 | 231 | |
|
234 | 232 | return self.__formated_value |
|
235 | 233 | |
|
236 | 234 | if format == 'bool': |
|
237 | 235 | value = int(value) |
|
238 | 236 | |
|
239 | 237 | if format == 'int': |
|
240 | 238 | value = float(value) |
|
241 | 239 | |
|
242 | 240 | format_func = eval(format) |
|
243 | 241 | |
|
244 | 242 | self.__formated_value = format_func(value) |
|
245 | 243 | |
|
246 | 244 | return self.__formated_value |
|
247 | 245 | |
|
248 | 246 | def updateId(self, new_id): |
|
249 | 247 | |
|
250 | 248 | self.id = str(new_id) |
|
251 | 249 | |
|
252 | 250 | def setup(self, id, name, value, format='str'): |
|
253 | 251 | self.id = str(id) |
|
254 | 252 | self.name = name |
|
255 | 253 | if format == 'obj': |
|
256 | 254 | self.value = value |
|
257 | 255 | else: |
|
258 | 256 | self.value = str(value) |
|
259 | 257 | self.format = str.lower(format) |
|
260 | 258 | |
|
261 | 259 | self.getValue() |
|
262 | 260 | |
|
263 | 261 | return 1 |
|
264 | 262 | |
|
265 | 263 | def update(self, name, value, format='str'): |
|
266 | 264 | |
|
267 | 265 | self.name = name |
|
268 | 266 | self.value = str(value) |
|
269 | 267 | self.format = format |
|
270 | 268 | |
|
271 | 269 | def makeXml(self, opElement): |
|
272 | 270 | if self.name not in ('queue',): |
|
273 | 271 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
274 | 272 | parmElement.set('id', str(self.id)) |
|
275 | 273 | parmElement.set('name', self.name) |
|
276 | 274 | parmElement.set('value', self.value) |
|
277 | 275 | parmElement.set('format', self.format) |
|
278 | 276 | |
|
279 | 277 | def readXml(self, parmElement): |
|
280 | 278 | |
|
281 | 279 | self.id = parmElement.get('id') |
|
282 | 280 | self.name = parmElement.get('name') |
|
283 | 281 | self.value = parmElement.get('value') |
|
284 | 282 | self.format = str.lower(parmElement.get('format')) |
|
285 | 283 | |
|
286 | 284 | # Compatible with old signal chain version |
|
287 | 285 | if self.format == 'int' and self.name == 'idfigure': |
|
288 | 286 | self.name = 'id' |
|
289 | 287 | |
|
290 | 288 | def printattr(self): |
|
291 | 289 | |
|
292 | 290 | print('Parameter[%s]: name = %s, value = %s, format = %s, project_id = %s' % (self.id, self.name, self.value, self.format, self.project_id)) |
|
293 | 291 | |
|
294 | 292 | class OperationConf(): |
|
295 | 293 | |
|
296 | 294 | ELEMENTNAME = 'Operation' |
|
297 | 295 | |
|
298 | 296 | def __init__(self): |
|
299 | 297 | |
|
300 | 298 | self.id = '0' |
|
301 | 299 | self.name = None |
|
302 | 300 | self.priority = None |
|
303 | 301 | self.topic = None |
|
304 | 302 | |
|
305 | 303 | def __getNewId(self): |
|
306 | 304 | |
|
307 | 305 | return int(self.id) * 10 + len(self.parmConfObjList) + 1 |
|
308 | 306 | |
|
309 | 307 | def getId(self): |
|
310 | 308 | return self.id |
|
311 | 309 | |
|
312 | 310 | def updateId(self, new_id): |
|
313 | 311 | |
|
314 | 312 | self.id = str(new_id) |
|
315 | 313 | |
|
316 | 314 | n = 1 |
|
317 | 315 | for parmObj in self.parmConfObjList: |
|
318 | 316 | |
|
319 | 317 | idParm = str(int(new_id) * 10 + n) |
|
320 | 318 | parmObj.updateId(idParm) |
|
321 | 319 | |
|
322 | 320 | n += 1 |
|
323 | 321 | |
|
324 | 322 | def getElementName(self): |
|
325 | 323 | |
|
326 | 324 | return self.ELEMENTNAME |
|
327 | 325 | |
|
328 | 326 | def getParameterObjList(self): |
|
329 | 327 | |
|
330 | 328 | return self.parmConfObjList |
|
331 | 329 | |
|
332 | 330 | def getParameterObj(self, parameterName): |
|
333 | 331 | |
|
334 | 332 | for parmConfObj in self.parmConfObjList: |
|
335 | 333 | |
|
336 | 334 | if parmConfObj.name != parameterName: |
|
337 | 335 | continue |
|
338 | 336 | |
|
339 | 337 | return parmConfObj |
|
340 | 338 | |
|
341 | 339 | return None |
|
342 | 340 | |
|
343 | 341 | def getParameterObjfromValue(self, parameterValue): |
|
344 | 342 | |
|
345 | 343 | for parmConfObj in self.parmConfObjList: |
|
346 | 344 | |
|
347 | 345 | if parmConfObj.getValue() != parameterValue: |
|
348 | 346 | continue |
|
349 | 347 | |
|
350 | 348 | return parmConfObj.getValue() |
|
351 | 349 | |
|
352 | 350 | return None |
|
353 | 351 | |
|
354 | 352 | def getParameterValue(self, parameterName): |
|
355 | 353 | |
|
356 | 354 | parameterObj = self.getParameterObj(parameterName) |
|
357 | 355 | |
|
358 | 356 | # if not parameterObj: |
|
359 | 357 | # return None |
|
360 | 358 | |
|
361 | 359 | value = parameterObj.getValue() |
|
362 | 360 | |
|
363 | 361 | return value |
|
364 | 362 | |
|
365 | 363 | def getKwargs(self): |
|
366 | 364 | |
|
367 | 365 | kwargs = {} |
|
368 | 366 | |
|
369 | 367 | for parmConfObj in self.parmConfObjList: |
|
370 | 368 | if self.name == 'run' and parmConfObj.name == 'datatype': |
|
371 | 369 | continue |
|
372 | 370 | |
|
373 | 371 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
374 | 372 | |
|
375 | 373 | return kwargs |
|
376 | 374 | |
|
377 | 375 | def setup(self, id, name, priority, type, project_id): |
|
378 | 376 | |
|
379 | 377 | self.id = str(id) |
|
380 | 378 | self.project_id = project_id |
|
381 | 379 | self.name = name |
|
382 | 380 | self.type = type |
|
383 | 381 | self.priority = priority |
|
384 | 382 | self.parmConfObjList = [] |
|
385 | 383 | |
|
386 | 384 | def removeParameters(self): |
|
387 | 385 | |
|
388 | 386 | for obj in self.parmConfObjList: |
|
389 | 387 | del obj |
|
390 | 388 | |
|
391 | 389 | self.parmConfObjList = [] |
|
392 | 390 | |
|
393 | 391 | def addParameter(self, name, value, format='str'): |
|
394 | 392 | |
|
395 | 393 | if value is None: |
|
396 | 394 | return None |
|
397 | 395 | id = self.__getNewId() |
|
398 | 396 | |
|
399 | 397 | parmConfObj = ParameterConf() |
|
400 | 398 | if not parmConfObj.setup(id, name, value, format): |
|
401 | 399 | return None |
|
402 | 400 | |
|
403 | 401 | self.parmConfObjList.append(parmConfObj) |
|
404 | 402 | |
|
405 | 403 | return parmConfObj |
|
406 | 404 | |
|
407 | 405 | def changeParameter(self, name, value, format='str'): |
|
408 | 406 | |
|
409 | 407 | parmConfObj = self.getParameterObj(name) |
|
410 | 408 | parmConfObj.update(name, value, format) |
|
411 | 409 | |
|
412 | 410 | return parmConfObj |
|
413 | 411 | |
|
414 | 412 | def makeXml(self, procUnitElement): |
|
415 | 413 | |
|
416 | 414 | opElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
417 | 415 | opElement.set('id', str(self.id)) |
|
418 | 416 | opElement.set('name', self.name) |
|
419 | 417 | opElement.set('type', self.type) |
|
420 | 418 | opElement.set('priority', str(self.priority)) |
|
421 | 419 | |
|
422 | 420 | for parmConfObj in self.parmConfObjList: |
|
423 | 421 | parmConfObj.makeXml(opElement) |
|
424 | 422 | |
|
425 | 423 | def readXml(self, opElement, project_id): |
|
426 | 424 | |
|
427 | 425 | self.id = opElement.get('id') |
|
428 | 426 | self.name = opElement.get('name') |
|
429 | 427 | self.type = opElement.get('type') |
|
430 | 428 | self.priority = opElement.get('priority') |
|
431 | 429 | self.project_id = str(project_id) #yong |
|
432 | 430 | |
|
433 | 431 | # Compatible with old signal chain version |
|
434 | 432 | # Use of 'run' method instead 'init' |
|
435 | 433 | if self.type == 'self' and self.name == 'init': |
|
436 | 434 | self.name = 'run' |
|
437 | 435 | |
|
438 | 436 | self.parmConfObjList = [] |
|
439 | 437 | |
|
440 | 438 | parmElementList = opElement.iter(ParameterConf().getElementName()) |
|
441 | 439 | |
|
442 | 440 | for parmElement in parmElementList: |
|
443 | 441 | parmConfObj = ParameterConf() |
|
444 | 442 | parmConfObj.readXml(parmElement) |
|
445 | 443 | |
|
446 | 444 | # Compatible with old signal chain version |
|
447 | 445 | # If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER |
|
448 | 446 | if self.type != 'self' and self.name == 'Plot': |
|
449 | 447 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
450 | 448 | self.name = parmConfObj.value |
|
451 | 449 | continue |
|
452 | 450 | |
|
453 | 451 | self.parmConfObjList.append(parmConfObj) |
|
454 | 452 | |
|
455 | 453 | def printattr(self): |
|
456 | 454 | |
|
457 | 455 | print('%s[%s]: name = %s, type = %s, priority = %s, project_id = %s' % (self.ELEMENTNAME, |
|
458 | 456 | self.id, |
|
459 | 457 | self.name, |
|
460 | 458 | self.type, |
|
461 | 459 | self.priority, |
|
462 | 460 | self.project_id)) |
|
463 | 461 | |
|
464 | 462 | for parmConfObj in self.parmConfObjList: |
|
465 | 463 | parmConfObj.printattr() |
|
466 | 464 | |
|
467 | 465 | def createObject(self): |
|
468 | 466 | |
|
469 | 467 | className = eval(self.name) |
|
470 | 468 | |
|
471 | 469 | if self.type == 'other': |
|
472 | 470 | opObj = className() |
|
473 | 471 | elif self.type == 'external': |
|
474 | 472 | kwargs = self.getKwargs() |
|
475 | 473 | opObj = className(self.id, self.project_id, **kwargs) |
|
476 | 474 | opObj.start() |
|
477 | 475 | |
|
478 | 476 | return opObj |
|
479 | 477 | |
|
480 | 478 | class ProcUnitConf(): |
|
481 | 479 | |
|
482 | 480 | ELEMENTNAME = 'ProcUnit' |
|
483 | 481 | |
|
484 | 482 | def __init__(self): |
|
485 | 483 | |
|
486 | 484 | self.id = None |
|
487 | 485 | self.datatype = None |
|
488 | 486 | self.name = None |
|
489 | 487 | self.inputId = None |
|
490 | 488 | self.opConfObjList = [] |
|
491 | 489 | self.procUnitObj = None |
|
492 | 490 | self.opObjDict = {} |
|
493 | 491 | |
|
494 | 492 | def __getPriority(self): |
|
495 | 493 | |
|
496 | 494 | return len(self.opConfObjList) + 1 |
|
497 | 495 | |
|
498 | 496 | def __getNewId(self): |
|
499 | 497 | |
|
500 | 498 | return int(self.id) * 10 + len(self.opConfObjList) + 1 |
|
501 | 499 | |
|
502 | 500 | def getElementName(self): |
|
503 | 501 | |
|
504 | 502 | return self.ELEMENTNAME |
|
505 | 503 | |
|
506 | 504 | def getId(self): |
|
507 | 505 | |
|
508 | 506 | return self.id |
|
509 | 507 | |
|
510 | 508 | def updateId(self, new_id): |
|
511 | 509 | ''' |
|
512 | 510 | new_id = int(parentId) * 10 + (int(self.id) % 10) |
|
513 | 511 | new_inputId = int(parentId) * 10 + (int(self.inputId) % 10) |
|
514 | 512 | |
|
515 | 513 | # If this proc unit has not inputs |
|
516 | 514 | #if self.inputId == '0': |
|
517 | 515 | #new_inputId = 0 |
|
518 | 516 | |
|
519 | 517 | n = 1 |
|
520 | 518 | for opConfObj in self.opConfObjList: |
|
521 | 519 | |
|
522 | 520 | idOp = str(int(new_id) * 10 + n) |
|
523 | 521 | opConfObj.updateId(idOp) |
|
524 | 522 | |
|
525 | 523 | n += 1 |
|
526 | 524 | |
|
527 | 525 | self.parentId = str(parentId) |
|
528 | 526 | self.id = str(new_id) |
|
529 | 527 | #self.inputId = str(new_inputId) |
|
530 | 528 | ''' |
|
531 | 529 | n = 1 |
|
532 | 530 | |
|
533 | 531 | def getInputId(self): |
|
534 | 532 | |
|
535 | 533 | return self.inputId |
|
536 | 534 | |
|
537 | 535 | def getOperationObjList(self): |
|
538 | 536 | |
|
539 | 537 | return self.opConfObjList |
|
540 | 538 | |
|
541 | 539 | def getOperationObj(self, name=None): |
|
542 | 540 | |
|
543 | 541 | for opConfObj in self.opConfObjList: |
|
544 | 542 | |
|
545 | 543 | if opConfObj.name != name: |
|
546 | 544 | continue |
|
547 | 545 | |
|
548 | 546 | return opConfObj |
|
549 | 547 | |
|
550 | 548 | return None |
|
551 | 549 | |
|
552 | 550 | def getOpObjfromParamValue(self, value=None): |
|
553 | 551 | |
|
554 | 552 | for opConfObj in self.opConfObjList: |
|
555 | 553 | if opConfObj.getParameterObjfromValue(parameterValue=value) != value: |
|
556 | 554 | continue |
|
557 | 555 | return opConfObj |
|
558 | 556 | return None |
|
559 | 557 | |
|
560 | 558 | def getProcUnitObj(self): |
|
561 | 559 | |
|
562 | 560 | return self.procUnitObj |
|
563 | 561 | |
|
564 | 562 | def setup(self, project_id, id, name, datatype, inputId): |
|
565 | 563 | ''' |
|
566 | 564 | id sera el topico a publicar |
|
567 | 565 | inputId sera el topico a subscribirse |
|
568 | 566 | ''' |
|
569 | 567 | |
|
570 | 568 | # Compatible with old signal chain version |
|
571 | 569 | if datatype == None and name == None: |
|
572 | 570 | raise ValueError('datatype or name should be defined') |
|
573 | 571 | |
|
574 | 572 | #Definir una condicion para inputId cuando sea 0 |
|
575 | 573 | |
|
576 | 574 | if name == None: |
|
577 | 575 | if 'Proc' in datatype: |
|
578 | 576 | name = datatype |
|
579 | 577 | else: |
|
580 | 578 | name = '%sProc' % (datatype) |
|
581 | 579 | |
|
582 | 580 | if datatype == None: |
|
583 | 581 | datatype = name.replace('Proc', '') |
|
584 | 582 | |
|
585 | 583 | self.id = str(id) |
|
586 | 584 | self.project_id = project_id |
|
587 | 585 | self.name = name |
|
588 | 586 | self.datatype = datatype |
|
589 | 587 | self.inputId = inputId |
|
590 | 588 | self.opConfObjList = [] |
|
591 | 589 | |
|
592 | 590 | self.addOperation(name='run', optype='self') |
|
593 | 591 | |
|
594 | 592 | def removeOperations(self): |
|
595 | 593 | |
|
596 | 594 | for obj in self.opConfObjList: |
|
597 | 595 | del obj |
|
598 | 596 | |
|
599 | 597 | self.opConfObjList = [] |
|
600 | 598 | self.addOperation(name='run') |
|
601 | 599 | |
|
602 | 600 | def addParameter(self, **kwargs): |
|
603 | 601 | ''' |
|
604 | 602 | Add parameters to 'run' operation |
|
605 | 603 | ''' |
|
606 | 604 | opObj = self.opConfObjList[0] |
|
607 | 605 | |
|
608 | 606 | opObj.addParameter(**kwargs) |
|
609 | 607 | |
|
610 | 608 | return opObj |
|
611 | 609 | |
|
612 | 610 | def addOperation(self, name, optype='self'): |
|
613 | 611 | ''' |
|
614 | 612 | Actualizacion - > proceso comunicacion |
|
615 | 613 | En el caso de optype='self', elminar. DEfinir comuncacion IPC -> Topic |
|
616 | 614 | definir el tipoc de socket o comunicacion ipc++ |
|
617 | 615 | |
|
618 | 616 | ''' |
|
619 | 617 | |
|
620 | 618 | id = self.__getNewId() |
|
621 | 619 | priority = self.__getPriority() # Sin mucho sentido, pero puede usarse |
|
622 | 620 | opConfObj = OperationConf() |
|
623 | 621 | opConfObj.setup(id, name=name, priority=priority, type=optype, project_id=self.project_id) |
|
624 | 622 | self.opConfObjList.append(opConfObj) |
|
625 | 623 | |
|
626 | 624 | return opConfObj |
|
627 | 625 | |
|
628 | 626 | def makeXml(self, projectElement): |
|
629 | 627 | |
|
630 | 628 | procUnitElement = SubElement(projectElement, self.ELEMENTNAME) |
|
631 | 629 | procUnitElement.set('id', str(self.id)) |
|
632 | 630 | procUnitElement.set('name', self.name) |
|
633 | 631 | procUnitElement.set('datatype', self.datatype) |
|
634 | 632 | procUnitElement.set('inputId', str(self.inputId)) |
|
635 | 633 | |
|
636 | 634 | for opConfObj in self.opConfObjList: |
|
637 | 635 | opConfObj.makeXml(procUnitElement) |
|
638 | 636 | |
|
639 | 637 | def readXml(self, upElement, project_id): |
|
640 | 638 | |
|
641 | 639 | self.id = upElement.get('id') |
|
642 | 640 | self.name = upElement.get('name') |
|
643 | 641 | self.datatype = upElement.get('datatype') |
|
644 | 642 | self.inputId = upElement.get('inputId') |
|
645 | 643 | self.project_id = str(project_id) |
|
646 | 644 | |
|
647 | 645 | if self.ELEMENTNAME == 'ReadUnit': |
|
648 | 646 | self.datatype = self.datatype.replace('Reader', '') |
|
649 | 647 | |
|
650 | 648 | if self.ELEMENTNAME == 'ProcUnit': |
|
651 | 649 | self.datatype = self.datatype.replace('Proc', '') |
|
652 | 650 | |
|
653 | 651 | if self.inputId == 'None': |
|
654 | 652 | self.inputId = '0' |
|
655 | 653 | |
|
656 | 654 | self.opConfObjList = [] |
|
657 | 655 | |
|
658 | 656 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
659 | 657 | |
|
660 | 658 | for opElement in opElementList: |
|
661 | 659 | opConfObj = OperationConf() |
|
662 | 660 | opConfObj.readXml(opElement, project_id) |
|
663 | 661 | self.opConfObjList.append(opConfObj) |
|
664 | 662 | |
|
665 | 663 | def printattr(self): |
|
666 | 664 | |
|
667 | 665 | print('%s[%s]: name = %s, datatype = %s, inputId = %s, project_id = %s' % (self.ELEMENTNAME, |
|
668 | 666 | self.id, |
|
669 | 667 | self.name, |
|
670 | 668 | self.datatype, |
|
671 | 669 | self.inputId, |
|
672 | 670 | self.project_id)) |
|
673 | 671 | |
|
674 | 672 | for opConfObj in self.opConfObjList: |
|
675 | 673 | opConfObj.printattr() |
|
676 | 674 | |
|
677 | 675 | def getKwargs(self): |
|
678 | 676 | |
|
679 | 677 | opObj = self.opConfObjList[0] |
|
680 | 678 | kwargs = opObj.getKwargs() |
|
681 | 679 | |
|
682 | 680 | return kwargs |
|
683 | 681 | |
|
684 | 682 | def createObjects(self): |
|
685 | 683 | ''' |
|
686 | 684 | Instancia de unidades de procesamiento. |
|
687 | 685 | ''' |
|
688 | 686 | className = eval(self.name) |
|
689 | 687 | kwargs = self.getKwargs() |
|
690 | 688 | procUnitObj = className(self.id, self.inputId, self.project_id, **kwargs) # necesitan saber su id y su entrada por fines de ipc |
|
691 | 689 | log.success('creating process...', self.name) |
|
692 | 690 | |
|
693 | 691 | for opConfObj in self.opConfObjList: |
|
694 | 692 | |
|
695 | 693 | if opConfObj.type == 'self' and opConfObj.name == 'run': |
|
696 | 694 | continue |
|
697 | 695 | elif opConfObj.type == 'self': |
|
698 | 696 | opObj = getattr(procUnitObj, opConfObj.name) |
|
699 | 697 | else: |
|
700 | 698 | opObj = opConfObj.createObject() |
|
701 | 699 | |
|
702 | 700 | log.success('creating operation: {}, type:{}'.format( |
|
703 | 701 | opConfObj.name, |
|
704 | 702 | opConfObj.type), self.name) |
|
705 | 703 | |
|
706 | 704 | procUnitObj.addOperation(opConfObj, opObj) |
|
707 | 705 | |
|
708 | 706 | procUnitObj.start() |
|
709 | 707 | self.procUnitObj = procUnitObj |
|
710 | 708 | |
|
711 | 709 | def close(self): |
|
712 | 710 | |
|
713 | 711 | for opConfObj in self.opConfObjList: |
|
714 | 712 | if opConfObj.type == 'self': |
|
715 | 713 | continue |
|
716 | 714 | |
|
717 | 715 | opObj = self.procUnitObj.getOperationObj(opConfObj.id) |
|
718 | 716 | opObj.close() |
|
719 | 717 | |
|
720 | 718 | self.procUnitObj.close() |
|
721 | 719 | |
|
722 | 720 | return |
|
723 | 721 | |
|
724 | 722 | |
|
725 | 723 | class ReadUnitConf(ProcUnitConf): |
|
726 | 724 | |
|
727 | 725 | ELEMENTNAME = 'ReadUnit' |
|
728 | 726 | |
|
729 | 727 | def __init__(self): |
|
730 | 728 | |
|
731 | 729 | self.id = None |
|
732 | 730 | self.datatype = None |
|
733 | 731 | self.name = None |
|
734 | 732 | self.inputId = None |
|
735 | 733 | self.opConfObjList = [] |
|
736 | 734 | |
|
737 | 735 | def getElementName(self): |
|
738 | 736 | |
|
739 | 737 | return self.ELEMENTNAME |
|
740 | 738 | |
|
741 | 739 | def setup(self, project_id, id, name, datatype, path='', startDate='', endDate='', |
|
742 | 740 | startTime='', endTime='', server=None, **kwargs): |
|
743 | 741 | |
|
744 | 742 | |
|
745 | 743 | ''' |
|
746 | 744 | *****el id del proceso sera el Topico |
|
747 | 745 | |
|
748 | 746 | Adicion de {topic}, si no esta presente -> error |
|
749 | 747 | kwargs deben ser trasmitidos en la instanciacion |
|
750 | 748 | |
|
751 | 749 | ''' |
|
752 | 750 | |
|
753 | 751 | # Compatible with old signal chain version |
|
754 | 752 | if datatype == None and name == None: |
|
755 | 753 | raise ValueError('datatype or name should be defined') |
|
756 | 754 | if name == None: |
|
757 | 755 | if 'Reader' in datatype: |
|
758 | 756 | name = datatype |
|
759 | 757 | datatype = name.replace('Reader','') |
|
760 | 758 | else: |
|
761 | 759 | name = '{}Reader'.format(datatype) |
|
762 | 760 | if datatype == None: |
|
763 | 761 | if 'Reader' in name: |
|
764 | 762 | datatype = name.replace('Reader','') |
|
765 | 763 | else: |
|
766 | 764 | datatype = name |
|
767 | 765 | name = '{}Reader'.format(name) |
|
768 | 766 | |
|
769 | 767 | self.id = id |
|
770 | 768 | self.project_id = project_id |
|
771 | 769 | self.name = name |
|
772 | 770 | self.datatype = datatype |
|
773 | 771 | if path != '': |
|
774 | 772 | self.path = os.path.abspath(path) |
|
775 | 773 | self.startDate = startDate |
|
776 | 774 | self.endDate = endDate |
|
777 | 775 | self.startTime = startTime |
|
778 | 776 | self.endTime = endTime |
|
779 | 777 | self.server = server |
|
780 | 778 | self.addRunOperation(**kwargs) |
|
781 | 779 | |
|
782 | 780 | def update(self, **kwargs): |
|
783 | 781 | |
|
784 | 782 | if 'datatype' in kwargs: |
|
785 | 783 | datatype = kwargs.pop('datatype') |
|
786 | 784 | if 'Reader' in datatype: |
|
787 | 785 | self.name = datatype |
|
788 | 786 | else: |
|
789 | 787 | self.name = '%sReader' % (datatype) |
|
790 | 788 | self.datatype = self.name.replace('Reader', '') |
|
791 | 789 | |
|
792 | 790 | attrs = ('path', 'startDate', 'endDate', |
|
793 | 791 | 'startTime', 'endTime') |
|
794 | 792 | |
|
795 | 793 | for attr in attrs: |
|
796 | 794 | if attr in kwargs: |
|
797 | 795 | setattr(self, attr, kwargs.pop(attr)) |
|
798 | 796 | |
|
799 | 797 | self.updateRunOperation(**kwargs) |
|
800 | 798 | |
|
801 | 799 | def removeOperations(self): |
|
802 | 800 | |
|
803 | 801 | for obj in self.opConfObjList: |
|
804 | 802 | del obj |
|
805 | 803 | |
|
806 | 804 | self.opConfObjList = [] |
|
807 | 805 | |
|
808 | 806 | def addRunOperation(self, **kwargs): |
|
809 | 807 | |
|
810 | 808 | opObj = self.addOperation(name='run', optype='self') |
|
811 | 809 | |
|
812 | 810 | if self.server is None: |
|
813 | 811 | opObj.addParameter( |
|
814 | 812 | name='datatype', value=self.datatype, format='str') |
|
815 | 813 | opObj.addParameter(name='path', value=self.path, format='str') |
|
816 | 814 | opObj.addParameter( |
|
817 | 815 | name='startDate', value=self.startDate, format='date') |
|
818 | 816 | opObj.addParameter( |
|
819 | 817 | name='endDate', value=self.endDate, format='date') |
|
820 | 818 | opObj.addParameter( |
|
821 | 819 | name='startTime', value=self.startTime, format='time') |
|
822 | 820 | opObj.addParameter( |
|
823 | 821 | name='endTime', value=self.endTime, format='time') |
|
824 | 822 | |
|
825 | 823 | for key, value in list(kwargs.items()): |
|
826 | 824 | opObj.addParameter(name=key, value=value, |
|
827 | 825 | format=type(value).__name__) |
|
828 | 826 | else: |
|
829 | 827 | opObj.addParameter(name='server', value=self.server, format='str') |
|
830 | 828 | |
|
831 | 829 | return opObj |
|
832 | 830 | |
|
833 | 831 | def updateRunOperation(self, **kwargs): |
|
834 | 832 | |
|
835 | 833 | opObj = self.getOperationObj(name='run') |
|
836 | 834 | opObj.removeParameters() |
|
837 | 835 | |
|
838 | 836 | opObj.addParameter(name='datatype', value=self.datatype, format='str') |
|
839 | 837 | opObj.addParameter(name='path', value=self.path, format='str') |
|
840 | 838 | opObj.addParameter( |
|
841 | 839 | name='startDate', value=self.startDate, format='date') |
|
842 | 840 | opObj.addParameter(name='endDate', value=self.endDate, format='date') |
|
843 | 841 | opObj.addParameter( |
|
844 | 842 | name='startTime', value=self.startTime, format='time') |
|
845 | 843 | opObj.addParameter(name='endTime', value=self.endTime, format='time') |
|
846 | 844 | |
|
847 | 845 | for key, value in list(kwargs.items()): |
|
848 | 846 | opObj.addParameter(name=key, value=value, |
|
849 | 847 | format=type(value).__name__) |
|
850 | 848 | |
|
851 | 849 | return opObj |
|
852 | 850 | |
|
853 | 851 | def readXml(self, upElement, project_id): |
|
854 | 852 | |
|
855 | 853 | self.id = upElement.get('id') |
|
856 | 854 | self.name = upElement.get('name') |
|
857 | 855 | self.datatype = upElement.get('datatype') |
|
858 | 856 | self.project_id = str(project_id) #yong |
|
859 | 857 | |
|
860 | 858 | if self.ELEMENTNAME == 'ReadUnit': |
|
861 | 859 | self.datatype = self.datatype.replace('Reader', '') |
|
862 | 860 | |
|
863 | 861 | self.opConfObjList = [] |
|
864 | 862 | |
|
865 | 863 | opElementList = upElement.iter(OperationConf().getElementName()) |
|
866 | 864 | |
|
867 | 865 | for opElement in opElementList: |
|
868 | 866 | opConfObj = OperationConf() |
|
869 | 867 | opConfObj.readXml(opElement, project_id) |
|
870 | 868 | self.opConfObjList.append(opConfObj) |
|
871 | 869 | |
|
872 | 870 | if opConfObj.name == 'run': |
|
873 | 871 | self.path = opConfObj.getParameterValue('path') |
|
874 | 872 | self.startDate = opConfObj.getParameterValue('startDate') |
|
875 | 873 | self.endDate = opConfObj.getParameterValue('endDate') |
|
876 | 874 | self.startTime = opConfObj.getParameterValue('startTime') |
|
877 | 875 | self.endTime = opConfObj.getParameterValue('endTime') |
|
878 | 876 | |
|
879 | 877 | |
|
880 | 878 | class Project(Process): |
|
881 | 879 | |
|
882 | 880 | ELEMENTNAME = 'Project' |
|
883 | 881 | |
|
884 | 882 | def __init__(self): |
|
885 | 883 | |
|
886 | 884 | Process.__init__(self) |
|
887 | 885 | self.id = None |
|
888 | 886 | self.filename = None |
|
889 | 887 | self.description = None |
|
890 | 888 | self.email = None |
|
891 | 889 | self.alarm = None |
|
892 | 890 | self.procUnitConfObjDict = {} |
|
893 | 891 | |
|
894 | 892 | def __getNewId(self): |
|
895 | 893 | |
|
896 | 894 | idList = list(self.procUnitConfObjDict.keys()) |
|
897 | 895 | id = int(self.id) * 10 |
|
898 | 896 | |
|
899 | 897 | while True: |
|
900 | 898 | id += 1 |
|
901 | 899 | |
|
902 | 900 | if str(id) in idList: |
|
903 | 901 | continue |
|
904 | 902 | |
|
905 | 903 | break |
|
906 | 904 | |
|
907 | 905 | return str(id) |
|
908 | 906 | |
|
909 | 907 | def getElementName(self): |
|
910 | 908 | |
|
911 | 909 | return self.ELEMENTNAME |
|
912 | 910 | |
|
913 | 911 | def getId(self): |
|
914 | 912 | |
|
915 | 913 | return self.id |
|
916 | 914 | |
|
917 | 915 | def updateId(self, new_id): |
|
918 | 916 | |
|
919 | 917 | self.id = str(new_id) |
|
920 | 918 | |
|
921 | 919 | keyList = list(self.procUnitConfObjDict.keys()) |
|
922 | 920 | keyList.sort() |
|
923 | 921 | |
|
924 | 922 | n = 1 |
|
925 | 923 | newProcUnitConfObjDict = {} |
|
926 | 924 | |
|
927 | 925 | for procKey in keyList: |
|
928 | 926 | |
|
929 | 927 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
930 | 928 | idProcUnit = str(int(self.id) * 10 + n) |
|
931 | 929 | procUnitConfObj.updateId(idProcUnit) |
|
932 | 930 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
933 | 931 | n += 1 |
|
934 | 932 | |
|
935 | 933 | self.procUnitConfObjDict = newProcUnitConfObjDict |
|
936 | 934 | |
|
937 | 935 | def setup(self, id=1, name='', description='', email=None, alarm=[]): |
|
938 | 936 | |
|
939 | 937 | print(' ') |
|
940 | 938 | print('*' * 60) |
|
941 | 939 | print('* Starting SIGNAL CHAIN PROCESSING (Multiprocessing) v%s *' % schainpy.__version__) |
|
942 | 940 | print('*' * 60) |
|
943 | 941 | print("* Python " + python_version() + " *") |
|
944 | 942 | print('*' * 19) |
|
945 | 943 | print(' ') |
|
946 | 944 | self.id = str(id) |
|
947 | 945 | self.description = description |
|
948 | 946 | self.email = email |
|
949 | 947 | self.alarm = alarm |
|
950 | 948 | |
|
951 | 949 | def update(self, **kwargs): |
|
952 | 950 | |
|
953 | 951 | for key, value in list(kwargs.items()): |
|
954 | 952 | setattr(self, key, value) |
|
955 | 953 | |
|
956 | 954 | def clone(self): |
|
957 | 955 | |
|
958 | 956 | p = Project() |
|
959 | 957 | p.procUnitConfObjDict = self.procUnitConfObjDict |
|
960 | 958 | return p |
|
961 | 959 | |
|
962 | 960 | def addReadUnit(self, id=None, datatype=None, name=None, **kwargs): |
|
963 | 961 | |
|
964 | 962 | ''' |
|
965 | 963 | Actualizacion: |
|
966 | 964 | Se agrego un nuevo argumento: topic -relativo a la forma de comunicar los procesos simultaneos |
|
967 | 965 | |
|
968 | 966 | * El id del proceso sera el topico al que se deben subscribir los procUnits para recibir la informacion(data) |
|
969 | 967 | |
|
970 | 968 | ''' |
|
971 | 969 | |
|
972 | 970 | if id is None: |
|
973 | 971 | idReadUnit = self.__getNewId() |
|
974 | 972 | else: |
|
975 | 973 | idReadUnit = str(id) |
|
976 | 974 | |
|
977 | 975 | readUnitConfObj = ReadUnitConf() |
|
978 | 976 | readUnitConfObj.setup(self.id, idReadUnit, name, datatype, **kwargs) |
|
979 | 977 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
980 | 978 | |
|
981 | 979 | return readUnitConfObj |
|
982 | 980 | |
|
983 | 981 | def addProcUnit(self, inputId='0', datatype=None, name=None): |
|
984 | 982 | |
|
985 | 983 | ''' |
|
986 | 984 | Actualizacion: |
|
987 | 985 | Se agrego dos nuevos argumentos: topic_read (lee data de otro procUnit) y topic_write(escribe o envia data a otro procUnit) |
|
988 | 986 | Deberia reemplazar a "inputId" |
|
989 | 987 | |
|
990 | 988 | ** A fin de mantener el inputID, este sera la representaacion del topicoal que deben subscribirse. El ID propio de la intancia |
|
991 | 989 | (proceso) sera el topico de la publicacion, todo sera asignado de manera dinamica. |
|
992 | 990 | |
|
993 | 991 | ''' |
|
994 | 992 | |
|
995 | 993 | idProcUnit = self.__getNewId() #Topico para subscripcion |
|
996 | 994 | procUnitConfObj = ProcUnitConf() |
|
997 | 995 | procUnitConfObj.setup(self.id, idProcUnit, name, datatype, inputId) #topic_read, topic_write, |
|
998 | 996 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
999 | 997 | |
|
1000 | 998 | return procUnitConfObj |
|
1001 | 999 | |
|
1002 | 1000 | def removeProcUnit(self, id): |
|
1003 | 1001 | |
|
1004 | 1002 | if id in list(self.procUnitConfObjDict.keys()): |
|
1005 | 1003 | self.procUnitConfObjDict.pop(id) |
|
1006 | 1004 | |
|
1007 | 1005 | def getReadUnitId(self): |
|
1008 | 1006 | |
|
1009 | 1007 | readUnitConfObj = self.getReadUnitObj() |
|
1010 | 1008 | |
|
1011 | 1009 | return readUnitConfObj.id |
|
1012 | 1010 | |
|
1013 | 1011 | def getReadUnitObj(self): |
|
1014 | 1012 | |
|
1015 | 1013 | for obj in list(self.procUnitConfObjDict.values()): |
|
1016 | 1014 | if obj.getElementName() == 'ReadUnit': |
|
1017 | 1015 | return obj |
|
1018 | 1016 | |
|
1019 | 1017 | return None |
|
1020 | 1018 | |
|
1021 | 1019 | def getProcUnitObj(self, id=None, name=None): |
|
1022 | 1020 | |
|
1023 | 1021 | if id != None: |
|
1024 | 1022 | return self.procUnitConfObjDict[id] |
|
1025 | 1023 | |
|
1026 | 1024 | if name != None: |
|
1027 | 1025 | return self.getProcUnitObjByName(name) |
|
1028 | 1026 | |
|
1029 | 1027 | return None |
|
1030 | 1028 | |
|
1031 | 1029 | def getProcUnitObjByName(self, name): |
|
1032 | 1030 | |
|
1033 | 1031 | for obj in list(self.procUnitConfObjDict.values()): |
|
1034 | 1032 | if obj.name == name: |
|
1035 | 1033 | return obj |
|
1036 | 1034 | |
|
1037 | 1035 | return None |
|
1038 | 1036 | |
|
1039 | 1037 | def procUnitItems(self): |
|
1040 | 1038 | |
|
1041 | 1039 | return list(self.procUnitConfObjDict.items()) |
|
1042 | 1040 | |
|
1043 | 1041 | def makeXml(self): |
|
1044 | 1042 | |
|
1045 | 1043 | projectElement = Element('Project') |
|
1046 | 1044 | projectElement.set('id', str(self.id)) |
|
1047 | 1045 | projectElement.set('name', self.name) |
|
1048 | 1046 | projectElement.set('description', self.description) |
|
1049 | 1047 | |
|
1050 | 1048 | for procUnitConfObj in list(self.procUnitConfObjDict.values()): |
|
1051 | 1049 | procUnitConfObj.makeXml(projectElement) |
|
1052 | 1050 | |
|
1053 | 1051 | self.projectElement = projectElement |
|
1054 | 1052 | |
|
1055 | 1053 | def writeXml(self, filename=None): |
|
1056 | 1054 | |
|
1057 | 1055 | if filename == None: |
|
1058 | 1056 | if self.filename: |
|
1059 | 1057 | filename = self.filename |
|
1060 | 1058 | else: |
|
1061 | 1059 | filename = 'schain.xml' |
|
1062 | 1060 | |
|
1063 | 1061 | if not filename: |
|
1064 | 1062 | print('filename has not been defined. Use setFilename(filename) for do it.') |
|
1065 | 1063 | return 0 |
|
1066 | 1064 | |
|
1067 | 1065 | abs_file = os.path.abspath(filename) |
|
1068 | 1066 | |
|
1069 | 1067 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
1070 | 1068 | print('No write permission on %s' % os.path.dirname(abs_file)) |
|
1071 | 1069 | return 0 |
|
1072 | 1070 | |
|
1073 | 1071 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
1074 | 1072 | print('File %s already exists and it could not be overwriten' % abs_file) |
|
1075 | 1073 | return 0 |
|
1076 | 1074 | |
|
1077 | 1075 | self.makeXml() |
|
1078 | 1076 | |
|
1079 | 1077 | ElementTree(self.projectElement).write(abs_file, method='xml') |
|
1080 | 1078 | |
|
1081 | 1079 | self.filename = abs_file |
|
1082 | 1080 | |
|
1083 | 1081 | return 1 |
|
1084 | 1082 | |
|
1085 | 1083 | def readXml(self, filename=None): |
|
1086 | 1084 | |
|
1087 | 1085 | if not filename: |
|
1088 | 1086 | print('filename is not defined') |
|
1089 | 1087 | return 0 |
|
1090 | 1088 | |
|
1091 | 1089 | abs_file = os.path.abspath(filename) |
|
1092 | 1090 | |
|
1093 | 1091 | if not os.path.isfile(abs_file): |
|
1094 | 1092 | print('%s file does not exist' % abs_file) |
|
1095 | 1093 | return 0 |
|
1096 | 1094 | |
|
1097 | 1095 | self.projectElement = None |
|
1098 | 1096 | self.procUnitConfObjDict = {} |
|
1099 | 1097 | |
|
1100 | 1098 | try: |
|
1101 | 1099 | self.projectElement = ElementTree().parse(abs_file) |
|
1102 | 1100 | except: |
|
1103 | 1101 | print('Error reading %s, verify file format' % filename) |
|
1104 | 1102 | return 0 |
|
1105 | 1103 | |
|
1106 | 1104 | self.project = self.projectElement.tag |
|
1107 | 1105 | |
|
1108 | 1106 | self.id = self.projectElement.get('id') |
|
1109 | 1107 | self.name = self.projectElement.get('name') |
|
1110 | 1108 | self.description = self.projectElement.get('description') |
|
1111 | 1109 | |
|
1112 | 1110 | readUnitElementList = self.projectElement.iter( |
|
1113 | 1111 | ReadUnitConf().getElementName()) |
|
1114 | 1112 | |
|
1115 | 1113 | for readUnitElement in readUnitElementList: |
|
1116 | 1114 | readUnitConfObj = ReadUnitConf() |
|
1117 | 1115 | readUnitConfObj.readXml(readUnitElement, self.id) |
|
1118 | 1116 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1119 | 1117 | |
|
1120 | 1118 | procUnitElementList = self.projectElement.iter( |
|
1121 | 1119 | ProcUnitConf().getElementName()) |
|
1122 | 1120 | |
|
1123 | 1121 | for procUnitElement in procUnitElementList: |
|
1124 | 1122 | procUnitConfObj = ProcUnitConf() |
|
1125 | 1123 | procUnitConfObj.readXml(procUnitElement, self.id) |
|
1126 | 1124 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
1127 | 1125 | |
|
1128 | 1126 | self.filename = abs_file |
|
1129 | 1127 | |
|
1130 | 1128 | return 1 |
|
1131 | 1129 | |
|
1132 | 1130 | def __str__(self): |
|
1133 | 1131 | |
|
1134 | 1132 | print('Project[%s]: name = %s, description = %s, project_id = %s' % (self.id, |
|
1135 | 1133 | self.name, |
|
1136 | 1134 | self.description, |
|
1137 | 1135 | self.project_id)) |
|
1138 | 1136 | |
|
1139 | 1137 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1140 | 1138 | print(procUnitConfObj) |
|
1141 | 1139 | |
|
1142 | 1140 | def createObjects(self): |
|
1143 | 1141 | |
|
1144 | 1142 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1145 | 1143 | procUnitConfObj.createObjects() |
|
1146 | 1144 | |
|
1147 | 1145 | def __handleError(self, procUnitConfObj, modes=None, stdout=True): |
|
1148 | 1146 | |
|
1149 | 1147 | import socket |
|
1150 | 1148 | |
|
1151 | 1149 | if modes is None: |
|
1152 | 1150 | modes = self.alarm |
|
1153 | 1151 | |
|
1154 | 1152 | if not self.alarm: |
|
1155 | 1153 | modes = [] |
|
1156 | 1154 | |
|
1157 | 1155 | err = traceback.format_exception(sys.exc_info()[0], |
|
1158 | 1156 | sys.exc_info()[1], |
|
1159 | 1157 | sys.exc_info()[2]) |
|
1160 | 1158 | |
|
1161 | 1159 | log.error('{}'.format(err[-1]), procUnitConfObj.name) |
|
1162 | 1160 | |
|
1163 | 1161 | message = ''.join(err) |
|
1164 | 1162 | |
|
1165 | 1163 | if stdout: |
|
1166 | 1164 | sys.stderr.write(message) |
|
1167 | 1165 | |
|
1168 | 1166 | subject = 'SChain v%s: Error running %s\n' % ( |
|
1169 | 1167 | schainpy.__version__, procUnitConfObj.name) |
|
1170 | 1168 | |
|
1171 | 1169 | subtitle = '%s: %s\n' % ( |
|
1172 | 1170 | procUnitConfObj.getElementName(), procUnitConfObj.name) |
|
1173 | 1171 | subtitle += 'Hostname: %s\n' % socket.gethostbyname( |
|
1174 | 1172 | socket.gethostname()) |
|
1175 | 1173 | subtitle += 'Working directory: %s\n' % os.path.abspath('./') |
|
1176 | 1174 | subtitle += 'Configuration file: %s\n' % self.filename |
|
1177 | 1175 | subtitle += 'Time: %s\n' % str(datetime.datetime.now()) |
|
1178 | 1176 | |
|
1179 | 1177 | readUnitConfObj = self.getReadUnitObj() |
|
1180 | 1178 | if readUnitConfObj: |
|
1181 | 1179 | subtitle += '\nInput parameters:\n' |
|
1182 | 1180 | subtitle += '[Data path = %s]\n' % readUnitConfObj.path |
|
1183 | 1181 | subtitle += '[Data type = %s]\n' % readUnitConfObj.datatype |
|
1184 | 1182 | subtitle += '[Start date = %s]\n' % readUnitConfObj.startDate |
|
1185 | 1183 | subtitle += '[End date = %s]\n' % readUnitConfObj.endDate |
|
1186 | 1184 | subtitle += '[Start time = %s]\n' % readUnitConfObj.startTime |
|
1187 | 1185 | subtitle += '[End time = %s]\n' % readUnitConfObj.endTime |
|
1188 | 1186 | |
|
1189 | 1187 | a = Alarm( |
|
1190 | 1188 | modes=modes, |
|
1191 | 1189 | email=self.email, |
|
1192 | 1190 | message=message, |
|
1193 | 1191 | subject=subject, |
|
1194 | 1192 | subtitle=subtitle, |
|
1195 | 1193 | filename=self.filename |
|
1196 | 1194 | ) |
|
1197 | 1195 | |
|
1198 | 1196 | return a |
|
1199 | 1197 | |
|
1200 | 1198 | def isPaused(self): |
|
1201 | 1199 | return 0 |
|
1202 | 1200 | |
|
1203 | 1201 | def isStopped(self): |
|
1204 | 1202 | return 0 |
|
1205 | 1203 | |
|
1206 | 1204 | def runController(self): |
|
1207 | 1205 | ''' |
|
1208 | 1206 | returns 0 when this process has been stopped, 1 otherwise |
|
1209 | 1207 | ''' |
|
1210 | 1208 | |
|
1211 | 1209 | if self.isPaused(): |
|
1212 | 1210 | print('Process suspended') |
|
1213 | 1211 | |
|
1214 | 1212 | while True: |
|
1215 | 1213 | time.sleep(0.1) |
|
1216 | 1214 | |
|
1217 | 1215 | if not self.isPaused(): |
|
1218 | 1216 | break |
|
1219 | 1217 | |
|
1220 | 1218 | if self.isStopped(): |
|
1221 | 1219 | break |
|
1222 | 1220 | |
|
1223 | 1221 | print('Process reinitialized') |
|
1224 | 1222 | |
|
1225 | 1223 | if self.isStopped(): |
|
1226 | 1224 | print('Process stopped') |
|
1227 | 1225 | return 0 |
|
1228 | 1226 | |
|
1229 | 1227 | return 1 |
|
1230 | 1228 | |
|
1231 | 1229 | def setFilename(self, filename): |
|
1232 | 1230 | |
|
1233 | 1231 | self.filename = filename |
|
1234 | 1232 | |
|
1235 | 1233 | def setProxyCom(self): |
|
1236 | 1234 | |
|
1237 | 1235 | if not os.path.exists('/tmp/schain'): |
|
1238 | 1236 | os.mkdir('/tmp/schain') |
|
1239 | 1237 | |
|
1240 | 1238 | self.ctx = zmq.Context() |
|
1241 | 1239 | xpub = self.ctx.socket(zmq.XPUB) |
|
1242 | 1240 | xpub.bind('ipc:///tmp/schain/{}_pub'.format(self.id)) |
|
1243 | 1241 | xsub = self.ctx.socket(zmq.XSUB) |
|
1244 | 1242 | xsub.bind('ipc:///tmp/schain/{}_sub'.format(self.id)) |
|
1245 | 1243 | |
|
1246 | 1244 | try: |
|
1247 | 1245 | zmq.proxy(xpub, xsub) |
|
1248 | except zmq.ContextTerminated: | |
|
1246 | except: # zmq.ContextTerminated: | |
|
1249 | 1247 | xpub.close() |
|
1250 | 1248 | xsub.close() |
|
1251 | 1249 | |
|
1252 | 1250 | def run(self): |
|
1253 | 1251 | |
|
1254 | 1252 | log.success('Starting {}: {}'.format(self.name, self.id), tag='') |
|
1255 | 1253 | self.start_time = time.time() |
|
1256 | 1254 | self.createObjects() |
|
1257 | 1255 | # t = Thread(target=wait, args=(self.ctx, )) |
|
1258 | 1256 | # t.start() |
|
1259 | 1257 | self.setProxyCom() |
|
1260 | 1258 | |
|
1261 | 1259 | # Iniciar todos los procesos .start(), monitoreo de procesos. ELiminar lo de abajo |
|
1262 | 1260 | |
|
1263 |
log.success('{} |
|
|
1261 | log.success('{} Done (time: {}s)'.format( | |
|
1264 | 1262 | self.name, |
|
1265 | 1263 | time.time()-self.start_time)) |
@@ -1,1251 +1,1345 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import copy |
|
8 | 8 | import numpy |
|
9 | 9 | import datetime |
|
10 | import json | |
|
10 | 11 | |
|
12 | from schainpy.utils import log | |
|
11 | 13 | from .jroheaderIO import SystemHeader, RadarControllerHeader |
|
12 | 14 | |
|
13 | 15 | |
|
14 | 16 | def getNumpyDtype(dataTypeCode): |
|
15 | 17 | |
|
16 | 18 | if dataTypeCode == 0: |
|
17 | 19 | numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
18 | 20 | elif dataTypeCode == 1: |
|
19 | 21 | numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
20 | 22 | elif dataTypeCode == 2: |
|
21 | 23 | numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
22 | 24 | elif dataTypeCode == 3: |
|
23 | 25 | numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
24 | 26 | elif dataTypeCode == 4: |
|
25 | 27 | numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
26 | 28 | elif dataTypeCode == 5: |
|
27 | 29 | numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
28 | 30 | else: |
|
29 | 31 | raise ValueError('dataTypeCode was not defined') |
|
30 | 32 | |
|
31 | 33 | return numpyDtype |
|
32 | 34 | |
|
33 | 35 | |
|
34 | 36 | def getDataTypeCode(numpyDtype): |
|
35 | 37 | |
|
36 | 38 | if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]): |
|
37 | 39 | datatype = 0 |
|
38 | 40 | elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]): |
|
39 | 41 | datatype = 1 |
|
40 | 42 | elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]): |
|
41 | 43 | datatype = 2 |
|
42 | 44 | elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]): |
|
43 | 45 | datatype = 3 |
|
44 | 46 | elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]): |
|
45 | 47 | datatype = 4 |
|
46 | 48 | elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]): |
|
47 | 49 | datatype = 5 |
|
48 | 50 | else: |
|
49 | 51 | datatype = None |
|
50 | 52 | |
|
51 | 53 | return datatype |
|
52 | 54 | |
|
53 | 55 | |
|
54 | 56 | def hildebrand_sekhon(data, navg): |
|
55 | 57 | """ |
|
56 | 58 | This method is for the objective determination of the noise level in Doppler spectra. This |
|
57 | 59 | implementation technique is based on the fact that the standard deviation of the spectral |
|
58 | 60 | densities is equal to the mean spectral density for white Gaussian noise |
|
59 | 61 | |
|
60 | 62 | Inputs: |
|
61 | 63 | Data : heights |
|
62 | 64 | navg : numbers of averages |
|
63 | 65 | |
|
64 | 66 | Return: |
|
65 | 67 | mean : noise's level |
|
66 | 68 | """ |
|
67 | 69 | |
|
68 | 70 | sortdata = numpy.sort(data, axis=None) |
|
69 | 71 | lenOfData = len(sortdata) |
|
70 | 72 | nums_min = lenOfData*0.2 |
|
71 | 73 | |
|
72 | 74 | if nums_min <= 5: |
|
73 | 75 | |
|
74 | 76 | nums_min = 5 |
|
75 | 77 | |
|
76 | 78 | sump = 0. |
|
77 | 79 | sumq = 0. |
|
78 | 80 | |
|
79 | 81 | j = 0 |
|
80 | 82 | cont = 1 |
|
81 | 83 | |
|
82 | while((cont==1)and(j<lenOfData)): | |
|
84 | while((cont == 1)and(j < lenOfData)): | |
|
83 | 85 | |
|
84 | 86 | sump += sortdata[j] |
|
85 | 87 | sumq += sortdata[j]**2 |
|
86 | 88 | |
|
87 | 89 | if j > nums_min: |
|
88 | 90 | rtest = float(j)/(j-1) + 1.0/navg |
|
89 | 91 | if ((sumq*j) > (rtest*sump**2)): |
|
90 | 92 | j = j - 1 |
|
91 |
sump |
|
|
92 |
sumq = |
|
|
93 | sump = sump - sortdata[j] | |
|
94 | sumq = sumq - sortdata[j]**2 | |
|
93 | 95 | cont = 0 |
|
94 | 96 | |
|
95 | 97 | j += 1 |
|
96 | 98 | |
|
97 | lnoise = sump /j | |
|
99 | lnoise = sump / j | |
|
98 | 100 | |
|
99 | 101 | return lnoise |
|
100 | 102 | |
|
101 | 103 | |
|
102 | 104 | class Beam: |
|
103 | 105 | |
|
104 | 106 | def __init__(self): |
|
105 | 107 | self.codeList = [] |
|
106 | 108 | self.azimuthList = [] |
|
107 | 109 | self.zenithList = [] |
|
108 | 110 | |
|
109 | 111 | |
|
110 | 112 | class GenericData(object): |
|
111 | 113 | |
|
112 | 114 | flagNoData = True |
|
113 | 115 | |
|
114 | 116 | def copy(self, inputObj=None): |
|
115 | 117 | |
|
116 | 118 | if inputObj == None: |
|
117 | 119 | return copy.deepcopy(self) |
|
118 | 120 | |
|
119 | 121 | for key in list(inputObj.__dict__.keys()): |
|
120 | 122 | |
|
121 | 123 | attribute = inputObj.__dict__[key] |
|
122 | 124 | |
|
123 | 125 | # If this attribute is a tuple or list |
|
124 | 126 | if type(inputObj.__dict__[key]) in (tuple, list): |
|
125 | 127 | self.__dict__[key] = attribute[:] |
|
126 | 128 | continue |
|
127 | 129 | |
|
128 | 130 | # If this attribute is another object or instance |
|
129 | 131 | if hasattr(attribute, '__dict__'): |
|
130 | 132 | self.__dict__[key] = attribute.copy() |
|
131 | 133 | continue |
|
132 | 134 | |
|
133 | 135 | self.__dict__[key] = inputObj.__dict__[key] |
|
134 | 136 | |
|
135 | 137 | def deepcopy(self): |
|
136 | 138 | |
|
137 | 139 | return copy.deepcopy(self) |
|
138 | 140 | |
|
139 | 141 | def isEmpty(self): |
|
140 | 142 | |
|
141 | 143 | return self.flagNoData |
|
142 | 144 | |
|
143 | 145 | |
|
144 | 146 | class JROData(GenericData): |
|
145 | 147 | |
|
146 | 148 | # m_BasicHeader = BasicHeader() |
|
147 | 149 | # m_ProcessingHeader = ProcessingHeader() |
|
148 | 150 | |
|
149 | 151 | systemHeaderObj = SystemHeader() |
|
150 | ||
|
151 | 152 | radarControllerHeaderObj = RadarControllerHeader() |
|
152 | ||
|
153 | 153 | # data = None |
|
154 | ||
|
155 | 154 | type = None |
|
156 | ||
|
157 | 155 | datatype = None # dtype but in string |
|
158 | ||
|
159 | 156 | # dtype = None |
|
160 | ||
|
161 | 157 | # nChannels = None |
|
162 | ||
|
163 | 158 | # nHeights = None |
|
164 | ||
|
165 | 159 | nProfiles = None |
|
166 | ||
|
167 | 160 | heightList = None |
|
168 | ||
|
169 | 161 | channelList = None |
|
170 | ||
|
171 | 162 | flagDiscontinuousBlock = False |
|
172 | ||
|
173 | 163 | useLocalTime = False |
|
174 | ||
|
175 | 164 | utctime = None |
|
176 | ||
|
177 | 165 | timeZone = None |
|
178 | ||
|
179 | 166 | dstFlag = None |
|
180 | ||
|
181 | 167 | errorCount = None |
|
182 | ||
|
183 | 168 | blocksize = None |
|
184 | ||
|
185 | 169 | # nCode = None |
|
186 | # | |
|
187 | 170 | # nBaud = None |
|
188 | # | |
|
189 | 171 | # code = None |
|
190 | ||
|
191 | 172 | flagDecodeData = False # asumo q la data no esta decodificada |
|
192 | ||
|
193 | 173 | flagDeflipData = False # asumo q la data no esta sin flip |
|
194 | ||
|
195 | 174 | flagShiftFFT = False |
|
196 | ||
|
197 | 175 | # ippSeconds = None |
|
198 | ||
|
199 | 176 | # timeInterval = None |
|
200 | ||
|
201 | 177 | nCohInt = None |
|
202 | ||
|
203 | 178 | # noise = None |
|
204 | ||
|
205 | 179 | windowOfFilter = 1 |
|
206 | ||
|
207 | 180 | # Speed of ligth |
|
208 | 181 | C = 3e8 |
|
209 | ||
|
210 | 182 | frequency = 49.92e6 |
|
211 | ||
|
212 | 183 | realtime = False |
|
213 | ||
|
214 | 184 | beacon_heiIndexList = None |
|
215 | ||
|
216 | 185 | last_block = None |
|
217 | ||
|
218 | 186 | blocknow = None |
|
219 | ||
|
220 | 187 | azimuth = None |
|
221 | ||
|
222 | 188 | zenith = None |
|
223 | ||
|
224 | 189 | beam = Beam() |
|
225 | ||
|
226 | 190 | profileIndex = None |
|
227 | ||
|
228 | error = (0, '') | |
|
191 | error = None | |
|
192 | data = None | |
|
193 | nmodes = None | |
|
229 | 194 | |
|
230 | 195 | def __str__(self): |
|
231 | 196 | |
|
232 | 197 | return '{} - {}'.format(self.type, self.getDatatime()) |
|
233 | 198 | |
|
234 | 199 | def getNoise(self): |
|
235 | 200 | |
|
236 | 201 | raise NotImplementedError |
|
237 | 202 | |
|
238 | 203 | def getNChannels(self): |
|
239 | 204 | |
|
240 | 205 | return len(self.channelList) |
|
241 | 206 | |
|
242 | 207 | def getChannelIndexList(self): |
|
243 | 208 | |
|
244 | 209 | return list(range(self.nChannels)) |
|
245 | 210 | |
|
246 | 211 | def getNHeights(self): |
|
247 | 212 | |
|
248 | 213 | return len(self.heightList) |
|
249 | 214 | |
|
250 | 215 | def getHeiRange(self, extrapoints=0): |
|
251 | 216 | |
|
252 | 217 | heis = self.heightList |
|
253 | 218 | # deltah = self.heightList[1] - self.heightList[0] |
|
254 | 219 | # |
|
255 | 220 | # heis.append(self.heightList[-1]) |
|
256 | 221 | |
|
257 | 222 | return heis |
|
258 | 223 | |
|
259 | 224 | def getDeltaH(self): |
|
260 | 225 | |
|
261 | 226 | delta = self.heightList[1] - self.heightList[0] |
|
262 | 227 | |
|
263 | 228 | return delta |
|
264 | 229 | |
|
265 | 230 | def getltctime(self): |
|
266 | 231 | |
|
267 | 232 | if self.useLocalTime: |
|
268 | 233 | return self.utctime - self.timeZone * 60 |
|
269 | 234 | |
|
270 | 235 | return self.utctime |
|
271 | 236 | |
|
272 | 237 | def getDatatime(self): |
|
273 | 238 | |
|
274 | 239 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
275 | 240 | return datatimeValue |
|
276 | 241 | |
|
277 | 242 | def getTimeRange(self): |
|
278 | 243 | |
|
279 | 244 | datatime = [] |
|
280 | 245 | |
|
281 | 246 | datatime.append(self.ltctime) |
|
282 | 247 | datatime.append(self.ltctime + self.timeInterval + 1) |
|
283 | 248 | |
|
284 | 249 | datatime = numpy.array(datatime) |
|
285 | 250 | |
|
286 | 251 | return datatime |
|
287 | 252 | |
|
288 | 253 | def getFmaxTimeResponse(self): |
|
289 | 254 | |
|
290 | 255 | period = (10**-6) * self.getDeltaH() / (0.15) |
|
291 | 256 | |
|
292 | 257 | PRF = 1. / (period * self.nCohInt) |
|
293 | 258 | |
|
294 | 259 | fmax = PRF |
|
295 | 260 | |
|
296 | 261 | return fmax |
|
297 | 262 | |
|
298 | 263 | def getFmax(self): |
|
299 | 264 | PRF = 1. / (self.ippSeconds * self.nCohInt) |
|
300 | 265 | |
|
301 | 266 | fmax = PRF |
|
302 | 267 | return fmax |
|
303 | 268 | |
|
304 | 269 | def getVmax(self): |
|
305 | 270 | |
|
306 | 271 | _lambda = self.C / self.frequency |
|
307 | 272 | |
|
308 | 273 | vmax = self.getFmax() * _lambda / 2 |
|
309 | 274 | |
|
310 | 275 | return vmax |
|
311 | 276 | |
|
312 | 277 | def get_ippSeconds(self): |
|
313 | 278 | ''' |
|
314 | 279 | ''' |
|
315 | 280 | return self.radarControllerHeaderObj.ippSeconds |
|
316 | 281 | |
|
317 | 282 | def set_ippSeconds(self, ippSeconds): |
|
318 | 283 | ''' |
|
319 | 284 | ''' |
|
320 | 285 | |
|
321 | 286 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
322 | 287 | |
|
323 | 288 | return |
|
324 | 289 | |
|
325 | 290 | def get_dtype(self): |
|
326 | 291 | ''' |
|
327 | 292 | ''' |
|
328 | 293 | return getNumpyDtype(self.datatype) |
|
329 | 294 | |
|
330 | 295 | def set_dtype(self, numpyDtype): |
|
331 | 296 | ''' |
|
332 | 297 | ''' |
|
333 | 298 | |
|
334 | 299 | self.datatype = getDataTypeCode(numpyDtype) |
|
335 | 300 | |
|
336 | 301 | def get_code(self): |
|
337 | 302 | ''' |
|
338 | 303 | ''' |
|
339 | 304 | return self.radarControllerHeaderObj.code |
|
340 | 305 | |
|
341 | 306 | def set_code(self, code): |
|
342 | 307 | ''' |
|
343 | 308 | ''' |
|
344 | 309 | self.radarControllerHeaderObj.code = code |
|
345 | 310 | |
|
346 | 311 | return |
|
347 | 312 | |
|
348 | 313 | def get_ncode(self): |
|
349 | 314 | ''' |
|
350 | 315 | ''' |
|
351 | 316 | return self.radarControllerHeaderObj.nCode |
|
352 | 317 | |
|
353 | 318 | def set_ncode(self, nCode): |
|
354 | 319 | ''' |
|
355 | 320 | ''' |
|
356 | 321 | self.radarControllerHeaderObj.nCode = nCode |
|
357 | 322 | |
|
358 | 323 | return |
|
359 | 324 | |
|
360 | 325 | def get_nbaud(self): |
|
361 | 326 | ''' |
|
362 | 327 | ''' |
|
363 | 328 | return self.radarControllerHeaderObj.nBaud |
|
364 | 329 | |
|
365 | 330 | def set_nbaud(self, nBaud): |
|
366 | 331 | ''' |
|
367 | 332 | ''' |
|
368 | 333 | self.radarControllerHeaderObj.nBaud = nBaud |
|
369 | 334 | |
|
370 | 335 | return |
|
371 | 336 | |
|
372 | 337 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
373 | 338 | channelIndexList = property( |
|
374 | 339 | getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
375 | 340 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
376 | 341 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
377 | 342 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
378 | 343 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
379 | 344 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
380 | 345 | dtype = property(get_dtype, set_dtype) |
|
381 | 346 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
382 | 347 | code = property(get_code, set_code) |
|
383 | 348 | nCode = property(get_ncode, set_ncode) |
|
384 | 349 | nBaud = property(get_nbaud, set_nbaud) |
|
385 | 350 | |
|
386 | 351 | |
|
387 | 352 | class Voltage(JROData): |
|
388 | 353 | |
|
389 | 354 | # data es un numpy array de 2 dmensiones (canales, alturas) |
|
390 | 355 | data = None |
|
391 | 356 | |
|
392 | 357 | def __init__(self): |
|
393 | 358 | ''' |
|
394 | 359 | Constructor |
|
395 | 360 | ''' |
|
396 | 361 | |
|
397 | 362 | self.useLocalTime = True |
|
398 | ||
|
399 | 363 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
400 | ||
|
401 | 364 | self.systemHeaderObj = SystemHeader() |
|
402 | ||
|
403 | 365 | self.type = "Voltage" |
|
404 | ||
|
405 | 366 | self.data = None |
|
406 | ||
|
407 | 367 | # self.dtype = None |
|
408 | ||
|
409 | 368 | # self.nChannels = 0 |
|
410 | ||
|
411 | 369 | # self.nHeights = 0 |
|
412 | ||
|
413 | 370 | self.nProfiles = None |
|
414 | ||
|
415 | self.heightList = None | |
|
416 | ||
|
371 | self.heightList = Non | |
|
417 | 372 | self.channelList = None |
|
418 | ||
|
419 | 373 | # self.channelIndexList = None |
|
420 | ||
|
421 | 374 | self.flagNoData = True |
|
422 | ||
|
423 | 375 | self.flagDiscontinuousBlock = False |
|
424 | ||
|
425 | 376 | self.utctime = None |
|
426 | ||
|
427 | 377 | self.timeZone = None |
|
428 | ||
|
429 | 378 | self.dstFlag = None |
|
430 | ||
|
431 | 379 | self.errorCount = None |
|
432 | ||
|
433 | 380 | self.nCohInt = None |
|
434 | ||
|
435 | 381 | self.blocksize = None |
|
436 | ||
|
437 | 382 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
438 | ||
|
439 | 383 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
440 | ||
|
441 | 384 | self.flagShiftFFT = False |
|
442 | ||
|
443 | 385 | self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil |
|
444 | ||
|
445 | 386 | self.profileIndex = 0 |
|
446 | 387 | |
|
447 | 388 | def getNoisebyHildebrand(self, channel=None): |
|
448 | 389 | """ |
|
449 | 390 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
450 | 391 | |
|
451 | 392 | Return: |
|
452 | 393 | noiselevel |
|
453 | 394 | """ |
|
454 | 395 | |
|
455 | 396 | if channel != None: |
|
456 | 397 | data = self.data[channel] |
|
457 | 398 | nChannels = 1 |
|
458 | 399 | else: |
|
459 | 400 | data = self.data |
|
460 | 401 | nChannels = self.nChannels |
|
461 | 402 | |
|
462 | 403 | noise = numpy.zeros(nChannels) |
|
463 | 404 | power = data * numpy.conjugate(data) |
|
464 | 405 | |
|
465 | 406 | for thisChannel in range(nChannels): |
|
466 | 407 | if nChannels == 1: |
|
467 | 408 | daux = power[:].real |
|
468 | 409 | else: |
|
469 | 410 | daux = power[thisChannel, :].real |
|
470 | 411 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) |
|
471 | 412 | |
|
472 | 413 | return noise |
|
473 | 414 | |
|
474 | 415 | def getNoise(self, type=1, channel=None): |
|
475 | 416 | |
|
476 | 417 | if type == 1: |
|
477 | 418 | noise = self.getNoisebyHildebrand(channel) |
|
478 | 419 | |
|
479 | 420 | return noise |
|
480 | 421 | |
|
481 | 422 | def getPower(self, channel=None): |
|
482 | 423 | |
|
483 | 424 | if channel != None: |
|
484 | 425 | data = self.data[channel] |
|
485 | 426 | else: |
|
486 | 427 | data = self.data |
|
487 | 428 | |
|
488 | 429 | power = data * numpy.conjugate(data) |
|
489 | 430 | powerdB = 10 * numpy.log10(power.real) |
|
490 | 431 | powerdB = numpy.squeeze(powerdB) |
|
491 | 432 | |
|
492 | 433 | return powerdB |
|
493 | 434 | |
|
494 | 435 | def getTimeInterval(self): |
|
495 | 436 | |
|
496 | 437 | timeInterval = self.ippSeconds * self.nCohInt |
|
497 | 438 | |
|
498 | 439 | return timeInterval |
|
499 | 440 | |
|
500 | 441 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
501 | 442 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
502 | 443 | |
|
503 | 444 | |
|
504 | 445 | class Spectra(JROData): |
|
505 | 446 | |
|
506 | 447 | # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
507 | 448 | data_spc = None |
|
508 | ||
|
509 | 449 | # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
510 | 450 | data_cspc = None |
|
511 | ||
|
512 | 451 | # data dc es un numpy array de 2 dmensiones (canales, alturas) |
|
513 | 452 | data_dc = None |
|
514 | ||
|
515 | 453 | # data power |
|
516 | 454 | data_pwr = None |
|
517 | ||
|
518 | 455 | nFFTPoints = None |
|
519 | ||
|
520 | 456 | # nPairs = None |
|
521 | ||
|
522 | 457 | pairsList = None |
|
523 | ||
|
524 | 458 | nIncohInt = None |
|
525 | ||
|
526 | 459 | wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia |
|
527 | ||
|
528 | 460 | nCohInt = None # se requiere para determinar el valor de timeInterval |
|
529 | ||
|
530 | 461 | ippFactor = None |
|
531 | ||
|
532 | 462 | profileIndex = 0 |
|
533 | ||
|
534 | 463 | plotting = "spectra" |
|
535 | 464 | |
|
536 | 465 | def __init__(self): |
|
537 | 466 | ''' |
|
538 | 467 | Constructor |
|
539 | 468 | ''' |
|
540 | 469 | |
|
541 | 470 | self.useLocalTime = True |
|
542 | ||
|
543 | 471 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
544 | ||
|
545 | 472 | self.systemHeaderObj = SystemHeader() |
|
546 | ||
|
547 | 473 | self.type = "Spectra" |
|
548 | ||
|
549 | 474 | # self.data = None |
|
550 | ||
|
551 | 475 | # self.dtype = None |
|
552 | ||
|
553 | 476 | # self.nChannels = 0 |
|
554 | ||
|
555 | 477 | # self.nHeights = 0 |
|
556 | ||
|
557 | 478 | self.nProfiles = None |
|
558 | ||
|
559 | 479 | self.heightList = None |
|
560 | ||
|
561 | 480 | self.channelList = None |
|
562 | ||
|
563 | 481 | # self.channelIndexList = None |
|
564 | ||
|
565 | 482 | self.pairsList = None |
|
566 | ||
|
567 | 483 | self.flagNoData = True |
|
568 | ||
|
569 | 484 | self.flagDiscontinuousBlock = False |
|
570 | ||
|
571 | 485 | self.utctime = None |
|
572 | ||
|
573 | 486 | self.nCohInt = None |
|
574 | ||
|
575 | 487 | self.nIncohInt = None |
|
576 | ||
|
577 | 488 | self.blocksize = None |
|
578 | ||
|
579 | 489 | self.nFFTPoints = None |
|
580 | ||
|
581 | 490 | self.wavelength = None |
|
582 | ||
|
583 | 491 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
584 | ||
|
585 | 492 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
586 | ||
|
587 | 493 | self.flagShiftFFT = False |
|
588 | ||
|
589 | 494 | self.ippFactor = 1 |
|
590 | ||
|
591 | 495 | #self.noise = None |
|
592 | ||
|
593 | 496 | self.beacon_heiIndexList = [] |
|
594 | ||
|
595 | 497 | self.noise_estimation = None |
|
596 | 498 | |
|
597 | 499 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
598 | 500 | """ |
|
599 | 501 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
600 | 502 | |
|
601 | 503 | Return: |
|
602 | 504 | noiselevel |
|
603 | 505 | """ |
|
604 | 506 | |
|
605 | 507 | noise = numpy.zeros(self.nChannels) |
|
606 | 508 | |
|
607 | 509 | for channel in range(self.nChannels): |
|
608 | 510 | daux = self.data_spc[channel, |
|
609 | 511 | xmin_index:xmax_index, ymin_index:ymax_index] |
|
610 | 512 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
611 | 513 | |
|
612 | 514 | return noise |
|
613 | 515 | |
|
614 | 516 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
615 | 517 | |
|
616 | 518 | if self.noise_estimation is not None: |
|
617 | 519 | # this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
618 | 520 | return self.noise_estimation |
|
619 | 521 | else: |
|
620 | 522 | noise = self.getNoisebyHildebrand( |
|
621 | 523 | xmin_index, xmax_index, ymin_index, ymax_index) |
|
622 | 524 | return noise |
|
623 | 525 | |
|
624 | 526 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
625 | 527 | |
|
626 | 528 | deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor) |
|
627 | 529 | freqrange = deltafreq * \ |
|
628 | 530 | (numpy.arange(self.nFFTPoints + extrapoints) - |
|
629 | 531 | self.nFFTPoints / 2.) - deltafreq / 2 |
|
630 | 532 | |
|
631 | 533 | return freqrange |
|
632 | 534 | |
|
633 | 535 | def getAcfRange(self, extrapoints=0): |
|
634 | 536 | |
|
635 | 537 | deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor)) |
|
636 | 538 | freqrange = deltafreq * \ |
|
637 | 539 | (numpy.arange(self.nFFTPoints + extrapoints) - |
|
638 | 540 | self.nFFTPoints / 2.) - deltafreq / 2 |
|
639 | 541 | |
|
640 | 542 | return freqrange |
|
641 | 543 | |
|
642 | 544 | def getFreqRange(self, extrapoints=0): |
|
643 | 545 | |
|
644 | 546 | deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor) |
|
645 | 547 | freqrange = deltafreq * \ |
|
646 | 548 | (numpy.arange(self.nFFTPoints + extrapoints) - |
|
647 | 549 | self.nFFTPoints / 2.) - deltafreq / 2 |
|
648 | 550 | |
|
649 | 551 | return freqrange |
|
650 | 552 | |
|
651 | 553 | def getVelRange(self, extrapoints=0): |
|
652 | 554 | |
|
653 | 555 | deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor) |
|
654 | 556 | velrange = deltav * (numpy.arange(self.nFFTPoints + |
|
655 |
extrapoints) - self.nFFTPoints / 2.) |
|
|
557 | extrapoints) - self.nFFTPoints / 2.) | |
|
656 | 558 | |
|
657 | return velrange | |
|
559 | if self.nmodes: | |
|
560 | return velrange/self.nmodes | |
|
561 | else: | |
|
562 | return velrange | |
|
658 | 563 | |
|
659 | 564 | def getNPairs(self): |
|
660 | 565 | |
|
661 | 566 | return len(self.pairsList) |
|
662 | 567 | |
|
663 | 568 | def getPairsIndexList(self): |
|
664 | 569 | |
|
665 | 570 | return list(range(self.nPairs)) |
|
666 | 571 | |
|
667 | 572 | def getNormFactor(self): |
|
668 | 573 | |
|
669 | 574 | pwcode = 1 |
|
670 | 575 | |
|
671 | 576 | if self.flagDecodeData: |
|
672 | 577 | pwcode = numpy.sum(self.code[0]**2) |
|
673 | 578 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
674 | 579 | normFactor = self.nProfiles * self.nIncohInt * \ |
|
675 | 580 | self.nCohInt * pwcode * self.windowOfFilter |
|
676 | 581 | |
|
677 | 582 | return normFactor |
|
678 | 583 | |
|
679 | 584 | def getFlagCspc(self): |
|
680 | 585 | |
|
681 | 586 | if self.data_cspc is None: |
|
682 | 587 | return True |
|
683 | 588 | |
|
684 | 589 | return False |
|
685 | 590 | |
|
686 | 591 | def getFlagDc(self): |
|
687 | 592 | |
|
688 | 593 | if self.data_dc is None: |
|
689 | 594 | return True |
|
690 | 595 | |
|
691 | 596 | return False |
|
692 | 597 | |
|
693 | 598 | def getTimeInterval(self): |
|
694 | 599 | |
|
695 |
timeInterval = self.ippSeconds * self.nCohInt * |
|
|
600 | timeInterval = self.ippSeconds * self.nCohInt * \ | |
|
601 | self.nIncohInt * self.nProfiles * self.ippFactor | |
|
696 | 602 | |
|
697 | 603 | return timeInterval |
|
698 | 604 | |
|
699 | 605 | def getPower(self): |
|
700 | 606 | |
|
701 | 607 | factor = self.normFactor |
|
702 | 608 | z = self.data_spc / factor |
|
703 | 609 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
704 | 610 | avg = numpy.average(z, axis=1) |
|
705 | 611 | |
|
706 | 612 | return 10 * numpy.log10(avg) |
|
707 | 613 | |
|
708 | 614 | def getCoherence(self, pairsList=None, phase=False): |
|
709 | 615 | |
|
710 | 616 | z = [] |
|
711 | 617 | if pairsList is None: |
|
712 | 618 | pairsIndexList = self.pairsIndexList |
|
713 | 619 | else: |
|
714 | 620 | pairsIndexList = [] |
|
715 | 621 | for pair in pairsList: |
|
716 | 622 | if pair not in self.pairsList: |
|
717 | 623 | raise ValueError("Pair %s is not in dataOut.pairsList" % ( |
|
718 | 624 | pair)) |
|
719 | 625 | pairsIndexList.append(self.pairsList.index(pair)) |
|
720 | 626 | for i in range(len(pairsIndexList)): |
|
721 | 627 | pair = self.pairsList[pairsIndexList[i]] |
|
722 | 628 | ccf = numpy.average( |
|
723 | 629 | self.data_cspc[pairsIndexList[i], :, :], axis=0) |
|
724 | 630 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
725 | 631 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
726 | 632 | avgcoherenceComplex = ccf / numpy.sqrt(powa * powb) |
|
727 | 633 | if phase: |
|
728 | 634 | data = numpy.arctan2(avgcoherenceComplex.imag, |
|
729 | 635 | avgcoherenceComplex.real) * 180 / numpy.pi |
|
730 | 636 | else: |
|
731 | 637 | data = numpy.abs(avgcoherenceComplex) |
|
732 | 638 | |
|
733 | 639 | z.append(data) |
|
734 | 640 | |
|
735 | 641 | return numpy.array(z) |
|
736 | 642 | |
|
737 | 643 | def setValue(self, value): |
|
738 | 644 | |
|
739 | 645 | print("This property should not be initialized") |
|
740 | 646 | |
|
741 | 647 | return |
|
742 | 648 | |
|
743 | 649 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
744 | 650 | pairsIndexList = property( |
|
745 | 651 | getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") |
|
746 | 652 | normFactor = property(getNormFactor, setValue, |
|
747 | 653 | "I'm the 'getNormFactor' property.") |
|
748 | 654 | flag_cspc = property(getFlagCspc, setValue) |
|
749 | 655 | flag_dc = property(getFlagDc, setValue) |
|
750 | 656 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
751 | 657 | timeInterval = property(getTimeInterval, setValue, |
|
752 | 658 | "I'm the 'timeInterval' property") |
|
753 | 659 | |
|
754 | 660 | |
|
755 | 661 | class SpectraHeis(Spectra): |
|
756 | 662 | |
|
757 | 663 | data_spc = None |
|
758 | ||
|
759 | 664 | data_cspc = None |
|
760 | ||
|
761 | 665 | data_dc = None |
|
762 | ||
|
763 | 666 | nFFTPoints = None |
|
764 | ||
|
765 | 667 | # nPairs = None |
|
766 | ||
|
767 | 668 | pairsList = None |
|
768 | ||
|
769 | 669 | nCohInt = None |
|
770 | ||
|
771 | 670 | nIncohInt = None |
|
772 | 671 | |
|
773 | 672 | def __init__(self): |
|
774 | 673 | |
|
775 | 674 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
776 | 675 | |
|
777 | 676 | self.systemHeaderObj = SystemHeader() |
|
778 | 677 | |
|
779 | 678 | self.type = "SpectraHeis" |
|
780 | 679 | |
|
781 | 680 | # self.dtype = None |
|
782 | 681 | |
|
783 | 682 | # self.nChannels = 0 |
|
784 | 683 | |
|
785 | 684 | # self.nHeights = 0 |
|
786 | 685 | |
|
787 | 686 | self.nProfiles = None |
|
788 | 687 | |
|
789 | 688 | self.heightList = None |
|
790 | 689 | |
|
791 | 690 | self.channelList = None |
|
792 | 691 | |
|
793 | 692 | # self.channelIndexList = None |
|
794 | 693 | |
|
795 | 694 | self.flagNoData = True |
|
796 | 695 | |
|
797 | 696 | self.flagDiscontinuousBlock = False |
|
798 | 697 | |
|
799 | 698 | # self.nPairs = 0 |
|
800 | 699 | |
|
801 | 700 | self.utctime = None |
|
802 | 701 | |
|
803 | 702 | self.blocksize = None |
|
804 | 703 | |
|
805 | 704 | self.profileIndex = 0 |
|
806 | 705 | |
|
807 | 706 | self.nCohInt = 1 |
|
808 | 707 | |
|
809 | 708 | self.nIncohInt = 1 |
|
810 | 709 | |
|
811 | 710 | def getNormFactor(self): |
|
812 | 711 | pwcode = 1 |
|
813 | 712 | if self.flagDecodeData: |
|
814 | 713 | pwcode = numpy.sum(self.code[0]**2) |
|
815 | 714 | |
|
816 | 715 | normFactor = self.nIncohInt * self.nCohInt * pwcode |
|
817 | 716 | |
|
818 | 717 | return normFactor |
|
819 | 718 | |
|
820 | 719 | def getTimeInterval(self): |
|
821 | 720 | |
|
822 | 721 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
823 | 722 | |
|
824 | 723 | return timeInterval |
|
825 | 724 | |
|
826 | 725 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
827 | 726 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
828 | 727 | |
|
829 | 728 | |
|
830 | 729 | class Fits(JROData): |
|
831 | 730 | |
|
832 | 731 | heightList = None |
|
833 | ||
|
834 | 732 | channelList = None |
|
835 | ||
|
836 | 733 | flagNoData = True |
|
837 | ||
|
838 | 734 | flagDiscontinuousBlock = False |
|
839 | ||
|
840 | 735 | useLocalTime = False |
|
841 | ||
|
842 | 736 | utctime = None |
|
843 | ||
|
844 | 737 | timeZone = None |
|
845 | ||
|
846 | 738 | # ippSeconds = None |
|
847 | ||
|
848 | 739 | # timeInterval = None |
|
849 | ||
|
850 | 740 | nCohInt = None |
|
851 | ||
|
852 | 741 | nIncohInt = None |
|
853 | ||
|
854 | 742 | noise = None |
|
855 | ||
|
856 | 743 | windowOfFilter = 1 |
|
857 | ||
|
858 | 744 | # Speed of ligth |
|
859 | 745 | C = 3e8 |
|
860 | ||
|
861 | 746 | frequency = 49.92e6 |
|
862 | ||
|
863 | 747 | realtime = False |
|
864 | 748 | |
|
865 | 749 | def __init__(self): |
|
866 | 750 | |
|
867 | 751 | self.type = "Fits" |
|
868 | 752 | |
|
869 | 753 | self.nProfiles = None |
|
870 | 754 | |
|
871 | 755 | self.heightList = None |
|
872 | 756 | |
|
873 | 757 | self.channelList = None |
|
874 | 758 | |
|
875 | 759 | # self.channelIndexList = None |
|
876 | 760 | |
|
877 | 761 | self.flagNoData = True |
|
878 | 762 | |
|
879 | 763 | self.utctime = None |
|
880 | 764 | |
|
881 | 765 | self.nCohInt = 1 |
|
882 | 766 | |
|
883 | 767 | self.nIncohInt = 1 |
|
884 | 768 | |
|
885 | 769 | self.useLocalTime = True |
|
886 | 770 | |
|
887 | 771 | self.profileIndex = 0 |
|
888 | 772 | |
|
889 | 773 | # self.utctime = None |
|
890 | 774 | # self.timeZone = None |
|
891 | 775 | # self.ltctime = None |
|
892 | 776 | # self.timeInterval = None |
|
893 | 777 | # self.header = None |
|
894 | 778 | # self.data_header = None |
|
895 | 779 | # self.data = None |
|
896 | 780 | # self.datatime = None |
|
897 | 781 | # self.flagNoData = False |
|
898 | 782 | # self.expName = '' |
|
899 | 783 | # self.nChannels = None |
|
900 | 784 | # self.nSamples = None |
|
901 | 785 | # self.dataBlocksPerFile = None |
|
902 | 786 | # self.comments = '' |
|
903 | 787 | # |
|
904 | 788 | |
|
905 | 789 | def getltctime(self): |
|
906 | 790 | |
|
907 | 791 | if self.useLocalTime: |
|
908 | 792 | return self.utctime - self.timeZone * 60 |
|
909 | 793 | |
|
910 | 794 | return self.utctime |
|
911 | 795 | |
|
912 | 796 | def getDatatime(self): |
|
913 | 797 | |
|
914 | 798 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
915 | 799 | return datatime |
|
916 | 800 | |
|
917 | 801 | def getTimeRange(self): |
|
918 | 802 | |
|
919 | 803 | datatime = [] |
|
920 | 804 | |
|
921 | 805 | datatime.append(self.ltctime) |
|
922 | 806 | datatime.append(self.ltctime + self.timeInterval) |
|
923 | 807 | |
|
924 | 808 | datatime = numpy.array(datatime) |
|
925 | 809 | |
|
926 | 810 | return datatime |
|
927 | 811 | |
|
928 | 812 | def getHeiRange(self): |
|
929 | 813 | |
|
930 | 814 | heis = self.heightList |
|
931 | 815 | |
|
932 | 816 | return heis |
|
933 | 817 | |
|
934 | 818 | def getNHeights(self): |
|
935 | 819 | |
|
936 | 820 | return len(self.heightList) |
|
937 | 821 | |
|
938 | 822 | def getNChannels(self): |
|
939 | 823 | |
|
940 | 824 | return len(self.channelList) |
|
941 | 825 | |
|
942 | 826 | def getChannelIndexList(self): |
|
943 | 827 | |
|
944 | 828 | return list(range(self.nChannels)) |
|
945 | 829 | |
|
946 | 830 | def getNoise(self, type=1): |
|
947 | 831 | |
|
948 | 832 | #noise = numpy.zeros(self.nChannels) |
|
949 | 833 | |
|
950 | 834 | if type == 1: |
|
951 | 835 | noise = self.getNoisebyHildebrand() |
|
952 | 836 | |
|
953 | 837 | if type == 2: |
|
954 | 838 | noise = self.getNoisebySort() |
|
955 | 839 | |
|
956 | 840 | if type == 3: |
|
957 | 841 | noise = self.getNoisebyWindow() |
|
958 | 842 | |
|
959 | 843 | return noise |
|
960 | 844 | |
|
961 | 845 | def getTimeInterval(self): |
|
962 | 846 | |
|
963 | 847 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
964 | 848 | |
|
965 | 849 | return timeInterval |
|
966 | 850 | |
|
967 | 851 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
968 | 852 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
969 | 853 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
970 | 854 | channelIndexList = property( |
|
971 | 855 | getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
972 | 856 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
973 | 857 | |
|
974 | 858 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
975 | 859 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
976 | 860 | |
|
977 | 861 | |
|
978 | 862 | class Correlation(JROData): |
|
979 | 863 | |
|
980 | 864 | noise = None |
|
981 | ||
|
982 | 865 | SNR = None |
|
983 | ||
|
984 | 866 | #-------------------------------------------------- |
|
985 | ||
|
986 | 867 | mode = None |
|
987 | ||
|
988 | 868 | split = False |
|
989 | ||
|
990 | 869 | data_cf = None |
|
991 | ||
|
992 | 870 | lags = None |
|
993 | ||
|
994 | 871 | lagRange = None |
|
995 | ||
|
996 | 872 | pairsList = None |
|
997 | ||
|
998 | 873 | normFactor = None |
|
999 | ||
|
1000 | 874 | #-------------------------------------------------- |
|
1001 | ||
|
1002 | 875 | # calculateVelocity = None |
|
1003 | ||
|
1004 | 876 | nLags = None |
|
1005 | ||
|
1006 | 877 | nPairs = None |
|
1007 | ||
|
1008 | 878 | nAvg = None |
|
1009 | 879 | |
|
1010 | 880 | def __init__(self): |
|
1011 | 881 | ''' |
|
1012 | 882 | Constructor |
|
1013 | 883 | ''' |
|
1014 | 884 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1015 | 885 | |
|
1016 | 886 | self.systemHeaderObj = SystemHeader() |
|
1017 | 887 | |
|
1018 | 888 | self.type = "Correlation" |
|
1019 | 889 | |
|
1020 | 890 | self.data = None |
|
1021 | 891 | |
|
1022 | 892 | self.dtype = None |
|
1023 | 893 | |
|
1024 | 894 | self.nProfiles = None |
|
1025 | 895 | |
|
1026 | 896 | self.heightList = None |
|
1027 | 897 | |
|
1028 | 898 | self.channelList = None |
|
1029 | 899 | |
|
1030 | 900 | self.flagNoData = True |
|
1031 | 901 | |
|
1032 | 902 | self.flagDiscontinuousBlock = False |
|
1033 | 903 | |
|
1034 | 904 | self.utctime = None |
|
1035 | 905 | |
|
1036 | 906 | self.timeZone = None |
|
1037 | 907 | |
|
1038 | 908 | self.dstFlag = None |
|
1039 | 909 | |
|
1040 | 910 | self.errorCount = None |
|
1041 | 911 | |
|
1042 | 912 | self.blocksize = None |
|
1043 | 913 | |
|
1044 | 914 | self.flagDecodeData = False # asumo q la data no esta decodificada |
|
1045 | 915 | |
|
1046 | 916 | self.flagDeflipData = False # asumo q la data no esta sin flip |
|
1047 | 917 | |
|
1048 | 918 | self.pairsList = None |
|
1049 | 919 | |
|
1050 | 920 | self.nPoints = None |
|
1051 | 921 | |
|
1052 | 922 | def getPairsList(self): |
|
1053 | 923 | |
|
1054 | 924 | return self.pairsList |
|
1055 | 925 | |
|
1056 | 926 | def getNoise(self, mode=2): |
|
1057 | 927 | |
|
1058 | 928 | indR = numpy.where(self.lagR == 0)[0][0] |
|
1059 | 929 | indT = numpy.where(self.lagT == 0)[0][0] |
|
1060 | 930 | |
|
1061 | 931 | jspectra0 = self.data_corr[:, :, indR, :] |
|
1062 | 932 | jspectra = copy.copy(jspectra0) |
|
1063 | 933 | |
|
1064 | 934 | num_chan = jspectra.shape[0] |
|
1065 | 935 | num_hei = jspectra.shape[2] |
|
1066 | 936 | |
|
1067 | 937 | freq_dc = jspectra.shape[1] / 2 |
|
1068 | 938 | ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc |
|
1069 | 939 | |
|
1070 | 940 | if ind_vel[0] < 0: |
|
1071 |
ind_vel[list(range(0, 1))] = ind_vel[list( |
|
|
941 | ind_vel[list(range(0, 1))] = ind_vel[list( | |
|
942 | range(0, 1))] + self.num_prof | |
|
1072 | 943 | |
|
1073 | 944 | if mode == 1: |
|
1074 | 945 | jspectra[:, freq_dc, :] = ( |
|
1075 | 946 | jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION |
|
1076 | 947 | |
|
1077 | 948 | if mode == 2: |
|
1078 | 949 | |
|
1079 | 950 | vel = numpy.array([-2, -1, 1, 2]) |
|
1080 | 951 | xx = numpy.zeros([4, 4]) |
|
1081 | 952 | |
|
1082 | 953 | for fil in range(4): |
|
1083 | 954 | xx[fil, :] = vel[fil]**numpy.asarray(list(range(4))) |
|
1084 | 955 | |
|
1085 | 956 | xx_inv = numpy.linalg.inv(xx) |
|
1086 | 957 | xx_aux = xx_inv[0, :] |
|
1087 | 958 | |
|
1088 | 959 | for ich in range(num_chan): |
|
1089 | 960 | yy = jspectra[ich, ind_vel, :] |
|
1090 | 961 | jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy) |
|
1091 | 962 | |
|
1092 | 963 | junkid = jspectra[ich, freq_dc, :] <= 0 |
|
1093 | 964 | cjunkid = sum(junkid) |
|
1094 | 965 | |
|
1095 | 966 | if cjunkid.any(): |
|
1096 | 967 | jspectra[ich, freq_dc, junkid.nonzero()] = ( |
|
1097 | 968 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 |
|
1098 | 969 | |
|
1099 | 970 | noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :] |
|
1100 | 971 | |
|
1101 | 972 | return noise |
|
1102 | 973 | |
|
1103 | 974 | def getTimeInterval(self): |
|
1104 | 975 | |
|
1105 | 976 | timeInterval = self.ippSeconds * self.nCohInt * self.nProfiles |
|
1106 | 977 | |
|
1107 | 978 | return timeInterval |
|
1108 | 979 | |
|
1109 | 980 | def splitFunctions(self): |
|
1110 | 981 | |
|
1111 | 982 | pairsList = self.pairsList |
|
1112 | 983 | ccf_pairs = [] |
|
1113 | 984 | acf_pairs = [] |
|
1114 | 985 | ccf_ind = [] |
|
1115 | 986 | acf_ind = [] |
|
1116 | 987 | for l in range(len(pairsList)): |
|
1117 | 988 | chan0 = pairsList[l][0] |
|
1118 | 989 | chan1 = pairsList[l][1] |
|
1119 | 990 | |
|
1120 | 991 | # Obteniendo pares de Autocorrelacion |
|
1121 | 992 | if chan0 == chan1: |
|
1122 | 993 | acf_pairs.append(chan0) |
|
1123 | 994 | acf_ind.append(l) |
|
1124 | 995 | else: |
|
1125 | 996 | ccf_pairs.append(pairsList[l]) |
|
1126 | 997 | ccf_ind.append(l) |
|
1127 | 998 | |
|
1128 | 999 | data_acf = self.data_cf[acf_ind] |
|
1129 | 1000 | data_ccf = self.data_cf[ccf_ind] |
|
1130 | 1001 | |
|
1131 | 1002 | return acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf |
|
1132 | 1003 | |
|
1133 | 1004 | def getNormFactor(self): |
|
1134 | 1005 | acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions() |
|
1135 | 1006 | acf_pairs = numpy.array(acf_pairs) |
|
1136 | 1007 | normFactor = numpy.zeros((self.nPairs, self.nHeights)) |
|
1137 | 1008 | |
|
1138 | 1009 | for p in range(self.nPairs): |
|
1139 | 1010 | pair = self.pairsList[p] |
|
1140 | 1011 | |
|
1141 | 1012 | ch0 = pair[0] |
|
1142 | 1013 | ch1 = pair[1] |
|
1143 | 1014 | |
|
1144 | 1015 | ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1) |
|
1145 | 1016 | ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1) |
|
1146 | 1017 | normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max) |
|
1147 | 1018 | |
|
1148 | 1019 | return normFactor |
|
1149 | 1020 | |
|
1150 | 1021 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1151 | 1022 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1152 | 1023 | |
|
1153 | 1024 | |
|
1154 | 1025 | class Parameters(Spectra): |
|
1155 | 1026 | |
|
1156 | 1027 | experimentInfo = None # Information about the experiment |
|
1157 | ||
|
1158 | 1028 | # Information from previous data |
|
1159 | ||
|
1160 | 1029 | inputUnit = None # Type of data to be processed |
|
1161 | ||
|
1162 | 1030 | operation = None # Type of operation to parametrize |
|
1163 | ||
|
1164 | 1031 | # normFactor = None #Normalization Factor |
|
1165 | ||
|
1166 | 1032 | groupList = None # List of Pairs, Groups, etc |
|
1167 | ||
|
1168 | 1033 | # Parameters |
|
1169 | ||
|
1170 | 1034 | data_param = None # Parameters obtained |
|
1171 | ||
|
1172 | 1035 | data_pre = None # Data Pre Parametrization |
|
1173 | ||
|
1174 | 1036 | data_SNR = None # Signal to Noise Ratio |
|
1175 | ||
|
1176 | 1037 | # heightRange = None #Heights |
|
1177 | ||
|
1178 | 1038 | abscissaList = None # Abscissa, can be velocities, lags or time |
|
1179 | ||
|
1180 | 1039 | # noise = None #Noise Potency |
|
1181 | ||
|
1182 | 1040 | utctimeInit = None # Initial UTC time |
|
1183 | ||
|
1184 | 1041 | paramInterval = None # Time interval to calculate Parameters in seconds |
|
1185 | ||
|
1186 | 1042 | useLocalTime = True |
|
1187 | ||
|
1188 | 1043 | # Fitting |
|
1189 | ||
|
1190 | 1044 | data_error = None # Error of the estimation |
|
1191 | ||
|
1192 | 1045 | constants = None |
|
1193 | ||
|
1194 | 1046 | library = None |
|
1195 | ||
|
1196 | 1047 | # Output signal |
|
1197 | ||
|
1198 | 1048 | outputInterval = None # Time interval to calculate output signal in seconds |
|
1199 | ||
|
1200 | 1049 | data_output = None # Out signal |
|
1201 | ||
|
1202 | 1050 | nAvg = None |
|
1203 | ||
|
1204 | 1051 | noise_estimation = None |
|
1205 | ||
|
1206 | 1052 | GauSPC = None # Fit gaussian SPC |
|
1207 | 1053 | |
|
1208 | 1054 | def __init__(self): |
|
1209 | 1055 | ''' |
|
1210 | 1056 | Constructor |
|
1211 | 1057 | ''' |
|
1212 | 1058 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1213 | 1059 | |
|
1214 | 1060 | self.systemHeaderObj = SystemHeader() |
|
1215 | 1061 | |
|
1216 | 1062 | self.type = "Parameters" |
|
1217 | 1063 | |
|
1218 | 1064 | def getTimeRange1(self, interval): |
|
1219 | 1065 | |
|
1220 | 1066 | datatime = [] |
|
1221 | 1067 | |
|
1222 | 1068 | if self.useLocalTime: |
|
1223 | 1069 | time1 = self.utctimeInit - self.timeZone * 60 |
|
1224 | 1070 | else: |
|
1225 | 1071 | time1 = self.utctimeInit |
|
1226 | 1072 | |
|
1227 | 1073 | datatime.append(time1) |
|
1228 | 1074 | datatime.append(time1 + interval) |
|
1229 | 1075 | datatime = numpy.array(datatime) |
|
1230 | 1076 | |
|
1231 | 1077 | return datatime |
|
1232 | 1078 | |
|
1233 | 1079 | def getTimeInterval(self): |
|
1234 | 1080 | |
|
1235 | 1081 | if hasattr(self, 'timeInterval1'): |
|
1236 | 1082 | return self.timeInterval1 |
|
1237 | 1083 | else: |
|
1238 | 1084 | return self.paramInterval |
|
1239 | 1085 | |
|
1240 | 1086 | def setValue(self, value): |
|
1241 | 1087 | |
|
1242 | 1088 | print("This property should not be initialized") |
|
1243 | 1089 | |
|
1244 | 1090 | return |
|
1245 | 1091 | |
|
1246 | 1092 | def getNoise(self): |
|
1247 | 1093 | |
|
1248 | 1094 | return self.spc_noise |
|
1249 | 1095 | |
|
1250 | 1096 | timeInterval = property(getTimeInterval) |
|
1251 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") No newline at end of file | |
|
1097 | noise = property(getNoise, setValue, "I'm the 'Noise' property.") | |
|
1098 | ||
|
1099 | ||
|
1100 | class PlotterData(object): | |
|
1101 | ''' | |
|
1102 | Object to hold data to be plotted | |
|
1103 | ''' | |
|
1104 | ||
|
1105 | MAXNUMX = 100 | |
|
1106 | MAXNUMY = 100 | |
|
1107 | ||
|
1108 | def __init__(self, code, throttle_value, exp_code, buffering=True): | |
|
1109 | ||
|
1110 | self.throttle = throttle_value | |
|
1111 | self.exp_code = exp_code | |
|
1112 | self.buffering = buffering | |
|
1113 | self.ready = False | |
|
1114 | self.localtime = False | |
|
1115 | self.data = {} | |
|
1116 | self.meta = {} | |
|
1117 | self.__times = [] | |
|
1118 | self.__heights = [] | |
|
1119 | ||
|
1120 | if 'snr' in code: | |
|
1121 | self.plottypes = ['snr'] | |
|
1122 | elif code == 'spc': | |
|
1123 | self.plottypes = ['spc', 'noise', 'rti'] | |
|
1124 | elif code == 'rti': | |
|
1125 | self.plottypes = ['noise', 'rti'] | |
|
1126 | else: | |
|
1127 | self.plottypes = [code] | |
|
1128 | ||
|
1129 | for plot in self.plottypes: | |
|
1130 | self.data[plot] = {} | |
|
1131 | ||
|
1132 | def __str__(self): | |
|
1133 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] | |
|
1134 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) | |
|
1135 | ||
|
1136 | def __len__(self): | |
|
1137 | return len(self.__times) | |
|
1138 | ||
|
1139 | def __getitem__(self, key): | |
|
1140 | ||
|
1141 | if key not in self.data: | |
|
1142 | raise KeyError(log.error('Missing key: {}'.format(key))) | |
|
1143 | if 'spc' in key or not self.buffering: | |
|
1144 | ret = self.data[key] | |
|
1145 | else: | |
|
1146 | ret = numpy.array([self.data[key][x] for x in self.times]) | |
|
1147 | if ret.ndim > 1: | |
|
1148 | ret = numpy.swapaxes(ret, 0, 1) | |
|
1149 | return ret | |
|
1150 | ||
|
1151 | def __contains__(self, key): | |
|
1152 | return key in self.data | |
|
1153 | ||
|
1154 | def setup(self): | |
|
1155 | ''' | |
|
1156 | Configure object | |
|
1157 | ''' | |
|
1158 | ||
|
1159 | self.type = '' | |
|
1160 | self.ready = False | |
|
1161 | self.data = {} | |
|
1162 | self.__times = [] | |
|
1163 | self.__heights = [] | |
|
1164 | self.__all_heights = set() | |
|
1165 | for plot in self.plottypes: | |
|
1166 | if 'snr' in plot: | |
|
1167 | plot = 'snr' | |
|
1168 | self.data[plot] = {} | |
|
1169 | ||
|
1170 | if 'spc' in self.data or 'rti' in self.data: | |
|
1171 | self.data['noise'] = {} | |
|
1172 | if 'noise' not in self.plottypes: | |
|
1173 | self.plottypes.append('noise') | |
|
1174 | ||
|
1175 | def shape(self, key): | |
|
1176 | ''' | |
|
1177 | Get the shape of the one-element data for the given key | |
|
1178 | ''' | |
|
1179 | ||
|
1180 | if len(self.data[key]): | |
|
1181 | if 'spc' in key or not self.buffering: | |
|
1182 | return self.data[key].shape | |
|
1183 | return self.data[key][self.__times[0]].shape | |
|
1184 | return (0,) | |
|
1185 | ||
|
1186 | def update(self, dataOut, tm): | |
|
1187 | ''' | |
|
1188 | Update data object with new dataOut | |
|
1189 | ''' | |
|
1190 | ||
|
1191 | if tm in self.__times: | |
|
1192 | return | |
|
1193 | ||
|
1194 | self.type = dataOut.type | |
|
1195 | self.parameters = getattr(dataOut, 'parameters', []) | |
|
1196 | if hasattr(dataOut, 'pairsList'): | |
|
1197 | self.pairs = dataOut.pairsList | |
|
1198 | if hasattr(dataOut, 'meta'): | |
|
1199 | self.meta = dataOut.meta | |
|
1200 | self.channels = dataOut.channelList | |
|
1201 | self.interval = dataOut.getTimeInterval() | |
|
1202 | self.localtime = dataOut.useLocalTime | |
|
1203 | if 'spc' in self.plottypes or 'cspc' in self.plottypes: | |
|
1204 | self.xrange = (dataOut.getFreqRange(1)/1000., | |
|
1205 | dataOut.getAcfRange(1), dataOut.getVelRange(1)) | |
|
1206 | self.__heights.append(dataOut.heightList) | |
|
1207 | self.__all_heights.update(dataOut.heightList) | |
|
1208 | self.__times.append(tm) | |
|
1209 | ||
|
1210 | for plot in self.plottypes: | |
|
1211 | if plot == 'spc': | |
|
1212 | z = dataOut.data_spc/dataOut.normFactor | |
|
1213 | buffer = 10*numpy.log10(z) | |
|
1214 | if plot == 'cspc': | |
|
1215 | buffer = dataOut.data_cspc | |
|
1216 | if plot == 'noise': | |
|
1217 | buffer = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) | |
|
1218 | if plot == 'rti': | |
|
1219 | buffer = dataOut.getPower() | |
|
1220 | if plot == 'snr_db': | |
|
1221 | buffer = dataOut.data_SNR | |
|
1222 | if plot == 'snr': | |
|
1223 | buffer = 10*numpy.log10(dataOut.data_SNR) | |
|
1224 | if plot == 'dop': | |
|
1225 | buffer = 10*numpy.log10(dataOut.data_DOP) | |
|
1226 | if plot == 'mean': | |
|
1227 | buffer = dataOut.data_MEAN | |
|
1228 | if plot == 'std': | |
|
1229 | buffer = dataOut.data_STD | |
|
1230 | if plot == 'coh': | |
|
1231 | buffer = dataOut.getCoherence() | |
|
1232 | if plot == 'phase': | |
|
1233 | buffer = dataOut.getCoherence(phase=True) | |
|
1234 | if plot == 'output': | |
|
1235 | buffer = dataOut.data_output | |
|
1236 | if plot == 'param': | |
|
1237 | buffer = dataOut.data_param | |
|
1238 | ||
|
1239 | if 'spc' in plot: | |
|
1240 | self.data[plot] = buffer | |
|
1241 | else: | |
|
1242 | if self.buffering: | |
|
1243 | self.data[plot][tm] = buffer | |
|
1244 | else: | |
|
1245 | self.data[plot] = buffer | |
|
1246 | ||
|
1247 | def normalize_heights(self): | |
|
1248 | ''' | |
|
1249 | Ensure same-dimension of the data for different heighList | |
|
1250 | ''' | |
|
1251 | ||
|
1252 | H = numpy.array(list(self.__all_heights)) | |
|
1253 | H.sort() | |
|
1254 | for key in self.data: | |
|
1255 | shape = self.shape(key)[:-1] + H.shape | |
|
1256 | for tm, obj in list(self.data[key].items()): | |
|
1257 | h = self.__heights[self.__times.index(tm)] | |
|
1258 | if H.size == h.size: | |
|
1259 | continue | |
|
1260 | index = numpy.where(numpy.in1d(H, h))[0] | |
|
1261 | dummy = numpy.zeros(shape) + numpy.nan | |
|
1262 | if len(shape) == 2: | |
|
1263 | dummy[:, index] = obj | |
|
1264 | else: | |
|
1265 | dummy[index] = obj | |
|
1266 | self.data[key][tm] = dummy | |
|
1267 | ||
|
1268 | self.__heights = [H for tm in self.__times] | |
|
1269 | ||
|
1270 | def jsonify(self, decimate=False): | |
|
1271 | ''' | |
|
1272 | Convert data to json | |
|
1273 | ''' | |
|
1274 | ||
|
1275 | data = {} | |
|
1276 | tm = self.times[-1] | |
|
1277 | dy = int(self.heights.size/self.MAXNUMY) + 1 | |
|
1278 | for key in self.data: | |
|
1279 | if key in ('spc', 'cspc') or not self.buffering: | |
|
1280 | dx = int(self.data[key].shape[1]/self.MAXNUMX) + 1 | |
|
1281 | data[key] = self.roundFloats( | |
|
1282 | self.data[key][::, ::dx, ::dy].tolist()) | |
|
1283 | else: | |
|
1284 | data[key] = self.roundFloats(self.data[key][tm].tolist()) | |
|
1285 | ||
|
1286 | ret = {'data': data} | |
|
1287 | ret['exp_code'] = self.exp_code | |
|
1288 | ret['time'] = float(tm) | |
|
1289 | ret['interval'] = float(self.interval) | |
|
1290 | ret['localtime'] = self.localtime | |
|
1291 | ret['yrange'] = self.roundFloats(self.heights[::dy].tolist()) | |
|
1292 | if 'spc' in self.data or 'cspc' in self.data: | |
|
1293 | ret['xrange'] = self.roundFloats(self.xrange[2][::dx].tolist()) | |
|
1294 | else: | |
|
1295 | ret['xrange'] = [] | |
|
1296 | if hasattr(self, 'pairs'): | |
|
1297 | ret['pairs'] = [(int(p[0]), int(p[1])) for p in self.pairs] | |
|
1298 | else: | |
|
1299 | ret['pairs'] = [] | |
|
1300 | ||
|
1301 | for key, value in list(self.meta.items()): | |
|
1302 | ret[key] = value | |
|
1303 | ||
|
1304 | return json.dumps(ret) | |
|
1305 | ||
|
1306 | @property | |
|
1307 | def times(self): | |
|
1308 | ''' | |
|
1309 | Return the list of times of the current data | |
|
1310 | ''' | |
|
1311 | ||
|
1312 | ret = numpy.array(self.__times) | |
|
1313 | ret.sort() | |
|
1314 | return ret | |
|
1315 | ||
|
1316 | @property | |
|
1317 | def min_time(self): | |
|
1318 | ''' | |
|
1319 | Return the minimun time value | |
|
1320 | ''' | |
|
1321 | ||
|
1322 | return self.times[0] | |
|
1323 | ||
|
1324 | @property | |
|
1325 | def max_time(self): | |
|
1326 | ''' | |
|
1327 | Return the maximun time value | |
|
1328 | ''' | |
|
1329 | ||
|
1330 | return self.times[-1] | |
|
1331 | ||
|
1332 | @property | |
|
1333 | def heights(self): | |
|
1334 | ''' | |
|
1335 | Return the list of heights of the current data | |
|
1336 | ''' | |
|
1337 | ||
|
1338 | return numpy.array(self.__heights[-1]) | |
|
1339 | ||
|
1340 | @staticmethod | |
|
1341 | def roundFloats(obj): | |
|
1342 | if isinstance(obj, list): | |
|
1343 | return list(map(PlotterData.roundFloats, obj)) | |
|
1344 | elif isinstance(obj, float): | |
|
1345 | return round(obj, 2) |
@@ -1,7 +1,6 | |||
|
1 | 1 | from .jroplot_voltage import * |
|
2 | 2 | from .jroplot_spectra import * |
|
3 | 3 | from .jroplot_heispectra import * |
|
4 | 4 | from .jroplot_correlation import * |
|
5 | 5 | from .jroplot_parameters import * |
|
6 | 6 | from .jroplot_data import * |
|
7 | from .jroplotter import * |
@@ -1,187 +1,187 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | import copy |
|
5 | 5 | from schainpy.model import * |
|
6 | 6 | from .figure import Figure, isRealtime |
|
7 | 7 | |
|
8 | class CorrelationPlot(Figure): | |
|
8 | class CorrelationPlot_(Figure): | |
|
9 | 9 | isConfig = None |
|
10 | 10 | __nsubplots = None |
|
11 | 11 | |
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'corr' |
|
15 | 15 | |
|
16 | 16 | def __init__(self, **kwargs): |
|
17 | 17 | Figure.__init__(self, **kwargs) |
|
18 | 18 | self.isConfig = False |
|
19 | 19 | self.__nsubplots = 1 |
|
20 | 20 | |
|
21 | 21 | self.WIDTH = 280 |
|
22 | 22 | self.HEIGHT = 250 |
|
23 | 23 | self.WIDTHPROF = 120 |
|
24 | 24 | self.HEIGHTPROF = 0 |
|
25 | 25 | self.counter_imagwr = 0 |
|
26 | 26 | |
|
27 | 27 | self.PLOT_CODE = 1 |
|
28 | 28 | self.FTP_WEI = None |
|
29 | 29 | self.EXP_CODE = None |
|
30 | 30 | self.SUB_EXP_CODE = None |
|
31 | 31 | self.PLOT_POS = None |
|
32 | 32 | |
|
33 | 33 | def getSubplots(self): |
|
34 | 34 | |
|
35 | 35 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
36 | 36 | nrow = int(self.nplots*1./ncol + 0.9) |
|
37 | 37 | |
|
38 | 38 | return nrow, ncol |
|
39 | 39 | |
|
40 | 40 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
41 | 41 | |
|
42 | 42 | showprofile = False |
|
43 | 43 | self.__showprofile = showprofile |
|
44 | 44 | self.nplots = nplots |
|
45 | 45 | |
|
46 | 46 | ncolspan = 1 |
|
47 | 47 | colspan = 1 |
|
48 | 48 | if showprofile: |
|
49 | 49 | ncolspan = 3 |
|
50 | 50 | colspan = 2 |
|
51 | 51 | self.__nsubplots = 2 |
|
52 | 52 | |
|
53 | 53 | self.createFigure(id = id, |
|
54 | 54 | wintitle = wintitle, |
|
55 | 55 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
56 | 56 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
57 | 57 | show=show) |
|
58 | 58 | |
|
59 | 59 | nrow, ncol = self.getSubplots() |
|
60 | 60 | |
|
61 | 61 | counter = 0 |
|
62 | 62 | for y in range(nrow): |
|
63 | 63 | for x in range(ncol): |
|
64 | 64 | |
|
65 | 65 | if counter >= self.nplots: |
|
66 | 66 | break |
|
67 | 67 | |
|
68 | 68 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
69 | 69 | |
|
70 | 70 | if showprofile: |
|
71 | 71 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
72 | 72 | |
|
73 | 73 | counter += 1 |
|
74 | 74 | |
|
75 | 75 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
76 | 76 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
77 | 77 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
78 | 78 | server=None, folder=None, username=None, password=None, |
|
79 | 79 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
80 | 80 | |
|
81 | 81 | """ |
|
82 | 82 | |
|
83 | 83 | Input: |
|
84 | 84 | dataOut : |
|
85 | 85 | id : |
|
86 | 86 | wintitle : |
|
87 | 87 | channelList : |
|
88 | 88 | showProfile : |
|
89 | 89 | xmin : None, |
|
90 | 90 | xmax : None, |
|
91 | 91 | ymin : None, |
|
92 | 92 | ymax : None, |
|
93 | 93 | zmin : None, |
|
94 | 94 | zmax : None |
|
95 | 95 | """ |
|
96 | 96 | |
|
97 | 97 | if dataOut.flagNoData: |
|
98 | 98 | return None |
|
99 | 99 | |
|
100 | 100 | if realtime: |
|
101 | 101 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
102 | 102 | print('Skipping this plot function') |
|
103 | 103 | return |
|
104 | 104 | |
|
105 | 105 | if channelList == None: |
|
106 | 106 | channelIndexList = dataOut.channelIndexList |
|
107 | 107 | else: |
|
108 | 108 | channelIndexList = [] |
|
109 | 109 | for channel in channelList: |
|
110 | 110 | if channel not in dataOut.channelList: |
|
111 | 111 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
112 | 112 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
113 | 113 | |
|
114 | 114 | factor = dataOut.normFactor |
|
115 | 115 | lenfactor = factor.shape[1] |
|
116 | 116 | x = dataOut.getLagTRange(1) |
|
117 | 117 | y = dataOut.getHeiRange() |
|
118 | 118 | |
|
119 | 119 | z = copy.copy(dataOut.data_corr[:,:,0,:]) |
|
120 | 120 | for i in range(dataOut.data_corr.shape[0]): |
|
121 | 121 | z[i,:,:] = z[i,:,:]/factor[i,:] |
|
122 | 122 | zdB = numpy.abs(z) |
|
123 | 123 | |
|
124 | 124 | avg = numpy.average(z, axis=1) |
|
125 | 125 | # avg = numpy.nanmean(z, axis=1) |
|
126 | 126 | # noise = dataOut.noise/factor |
|
127 | 127 | |
|
128 | 128 | #thisDatetime = dataOut.datatime |
|
129 | 129 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
130 | 130 | title = wintitle + " Correlation" |
|
131 | 131 | xlabel = "Lag T (s)" |
|
132 | 132 | ylabel = "Range (Km)" |
|
133 | 133 | |
|
134 | 134 | if not self.isConfig: |
|
135 | 135 | |
|
136 | 136 | nplots = dataOut.data_corr.shape[0] |
|
137 | 137 | |
|
138 | 138 | self.setup(id=id, |
|
139 | 139 | nplots=nplots, |
|
140 | 140 | wintitle=wintitle, |
|
141 | 141 | showprofile=showprofile, |
|
142 | 142 | show=show) |
|
143 | 143 | |
|
144 | 144 | if xmin == None: xmin = numpy.nanmin(x) |
|
145 | 145 | if xmax == None: xmax = numpy.nanmax(x) |
|
146 | 146 | if ymin == None: ymin = numpy.nanmin(y) |
|
147 | 147 | if ymax == None: ymax = numpy.nanmax(y) |
|
148 | 148 | if zmin == None: zmin = 0 |
|
149 | 149 | if zmax == None: zmax = 1 |
|
150 | 150 | |
|
151 | 151 | self.FTP_WEI = ftp_wei |
|
152 | 152 | self.EXP_CODE = exp_code |
|
153 | 153 | self.SUB_EXP_CODE = sub_exp_code |
|
154 | 154 | self.PLOT_POS = plot_pos |
|
155 | 155 | |
|
156 | 156 | self.isConfig = True |
|
157 | 157 | |
|
158 | 158 | self.setWinTitle(title) |
|
159 | 159 | |
|
160 | 160 | for i in range(self.nplots): |
|
161 | 161 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
162 | 162 | title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime) |
|
163 | 163 | axes = self.axesList[i*self.__nsubplots] |
|
164 | 164 | axes.pcolor(x, y, zdB[i,:,:], |
|
165 | 165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
166 | 166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
167 | 167 | ticksize=9, cblabel='') |
|
168 | 168 | |
|
169 | 169 | # if self.__showprofile: |
|
170 | 170 | # axes = self.axesList[i*self.__nsubplots +1] |
|
171 | 171 | # axes.pline(avgdB[i], y, |
|
172 | 172 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
173 | 173 | # xlabel='dB', ylabel='', title='', |
|
174 | 174 | # ytick_visible=False, |
|
175 | 175 | # grid='x') |
|
176 | 176 | # |
|
177 | 177 | # noiseline = numpy.repeat(noisedB[i], len(y)) |
|
178 | 178 | # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
179 | 179 | |
|
180 | 180 | self.draw() |
|
181 | 181 | |
|
182 | 182 | self.save(figpath=figpath, |
|
183 | 183 | figfile=figfile, |
|
184 | 184 | save=save, |
|
185 | 185 | ftp=ftp, |
|
186 | 186 | wr_period=wr_period, |
|
187 | 187 | thisDatetime=thisDatetime) No newline at end of file |
This diff has been collapsed as it changes many lines, (685 lines changed) Show them Hide them | |||
@@ -1,1154 +1,613 | |||
|
1 | ''' | |
|
2 | New Plots Operations | |
|
3 | ||
|
4 | @author: juan.espinoza@jro.igp.gob.pe | |
|
5 | ''' | |
|
6 | ||
|
1 | 7 | |
|
2 | import os | |
|
3 | 8 | import time |
|
4 | import glob | |
|
5 | 9 | import datetime |
|
6 | from multiprocessing import Process | |
|
7 | ||
|
8 | import zmq | |
|
9 | 10 | import numpy |
|
10 | import matplotlib | |
|
11 | import matplotlib.pyplot as plt | |
|
12 | from matplotlib.patches import Polygon | |
|
13 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
|
14 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
|
15 | 11 | |
|
16 |
from schainpy.model. |
|
|
12 | from schainpy.model.graphics.jroplot_base import Plot, plt | |
|
17 | 13 | from schainpy.utils import log |
|
18 | 14 | |
|
19 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] | |
|
20 | blu_values = matplotlib.pyplot.get_cmap( | |
|
21 | 'seismic_r', 20)(numpy.arange(20))[10:15] | |
|
22 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
|
23 | 'jro', numpy.vstack((blu_values, jet_values))) | |
|
24 | matplotlib.pyplot.register_cmap(cmap=ncmap) | |
|
25 | ||
|
26 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'viridis', 'plasma', 'inferno', 'Greys', 'seismic', 'bwr', 'coolwarm')] | |
|
27 | ||
|
28 | 15 | EARTH_RADIUS = 6.3710e3 |
|
29 | 16 | |
|
17 | ||
|
30 | 18 | def ll2xy(lat1, lon1, lat2, lon2): |
|
31 | 19 | |
|
32 | 20 | p = 0.017453292519943295 |
|
33 |
a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * |
|
|
21 | a = 0.5 - numpy.cos((lat2 - lat1) * p)/2 + numpy.cos(lat1 * p) * \ | |
|
22 | numpy.cos(lat2 * p) * (1 - numpy.cos((lon2 - lon1) * p)) / 2 | |
|
34 | 23 | r = 12742 * numpy.arcsin(numpy.sqrt(a)) |
|
35 |
theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) |
|
|
24 | theta = numpy.arctan2(numpy.sin((lon2-lon1)*p)*numpy.cos(lat2*p), numpy.cos(lat1*p) | |
|
25 | * numpy.sin(lat2*p)-numpy.sin(lat1*p)*numpy.cos(lat2*p)*numpy.cos((lon2-lon1)*p)) | |
|
36 | 26 | theta = -theta + numpy.pi/2 |
|
37 | 27 | return r*numpy.cos(theta), r*numpy.sin(theta) |
|
38 | 28 | |
|
29 | ||
|
39 | 30 | def km2deg(km): |
|
40 | 31 | ''' |
|
41 | 32 | Convert distance in km to degrees |
|
42 | 33 | ''' |
|
43 | 34 | |
|
44 | 35 | return numpy.rad2deg(km/EARTH_RADIUS) |
|
45 | 36 | |
|
46 | def figpause(interval): | |
|
47 | backend = plt.rcParams['backend'] | |
|
48 | if backend in matplotlib.rcsetup.interactive_bk: | |
|
49 | figManager = matplotlib._pylab_helpers.Gcf.get_active() | |
|
50 | if figManager is not None: | |
|
51 | canvas = figManager.canvas | |
|
52 | if canvas.figure.stale: | |
|
53 | canvas.draw() | |
|
54 | try: | |
|
55 | canvas.start_event_loop(interval) | |
|
56 | except: | |
|
57 | pass | |
|
58 | return | |
|
59 | ||
|
60 | def popup(message): | |
|
61 | ''' | |
|
62 | ''' | |
|
63 | ||
|
64 | fig = plt.figure(figsize=(12, 8), facecolor='r') | |
|
65 | text = '\n'.join([s.strip() for s in message.split(':')]) | |
|
66 | fig.text(0.01, 0.5, text, ha='left', va='center', size='20', weight='heavy', color='w') | |
|
67 | fig.show() | |
|
68 | figpause(1000) | |
|
69 | ||
|
70 | ||
|
71 | class PlotData(Operation, Process): | |
|
72 | ''' | |
|
73 | Base class for Schain plotting operations | |
|
74 | ''' | |
|
75 | ||
|
76 | CODE = 'Figure' | |
|
77 | colormap = 'jro' | |
|
78 | bgcolor = 'white' | |
|
79 | CONFLATE = False | |
|
80 | __missing = 1E30 | |
|
81 | ||
|
82 | __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax', | |
|
83 | 'zlimits', 'xlabel', 'ylabel', 'xaxis','cb_label', 'title', | |
|
84 | 'colorbar', 'bgcolor', 'width', 'height', 'localtime', 'oneFigure', | |
|
85 | 'showprofile', 'decimation', 'ftp'] | |
|
86 | ||
|
87 | def __init__(self, **kwargs): | |
|
88 | ||
|
89 | Operation.__init__(self, plot=True, **kwargs) | |
|
90 | Process.__init__(self) | |
|
91 | ||
|
92 | self.kwargs['code'] = self.CODE | |
|
93 | self.mp = False | |
|
94 | self.data = None | |
|
95 | self.isConfig = False | |
|
96 | self.figures = [] | |
|
97 | self.axes = [] | |
|
98 | self.cb_axes = [] | |
|
99 | self.localtime = kwargs.pop('localtime', True) | |
|
100 | self.show = kwargs.get('show', True) | |
|
101 | self.save = kwargs.get('save', False) | |
|
102 | self.ftp = kwargs.get('ftp', False) | |
|
103 | self.colormap = kwargs.get('colormap', self.colormap) | |
|
104 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
|
105 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
|
106 | self.colormaps = kwargs.get('colormaps', None) | |
|
107 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |
|
108 | self.showprofile = kwargs.get('showprofile', False) | |
|
109 | self.title = kwargs.get('wintitle', self.CODE.upper()) | |
|
110 | self.cb_label = kwargs.get('cb_label', None) | |
|
111 | self.cb_labels = kwargs.get('cb_labels', None) | |
|
112 | self.labels = kwargs.get('labels', None) | |
|
113 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
|
114 | self.zmin = kwargs.get('zmin', None) | |
|
115 | self.zmax = kwargs.get('zmax', None) | |
|
116 | self.zlimits = kwargs.get('zlimits', None) | |
|
117 | self.xmin = kwargs.get('xmin', None) | |
|
118 | self.xmax = kwargs.get('xmax', None) | |
|
119 | self.xrange = kwargs.get('xrange', 24) | |
|
120 | self.xscale = kwargs.get('xscale', None) | |
|
121 | self.ymin = kwargs.get('ymin', None) | |
|
122 | self.ymax = kwargs.get('ymax', None) | |
|
123 | self.yscale = kwargs.get('yscale', None) | |
|
124 | self.xlabel = kwargs.get('xlabel', None) | |
|
125 | self.decimation = kwargs.get('decimation', None) | |
|
126 | self.showSNR = kwargs.get('showSNR', False) | |
|
127 | self.oneFigure = kwargs.get('oneFigure', True) | |
|
128 | self.width = kwargs.get('width', None) | |
|
129 | self.height = kwargs.get('height', None) | |
|
130 | self.colorbar = kwargs.get('colorbar', True) | |
|
131 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |
|
132 | self.channels = kwargs.get('channels', None) | |
|
133 | self.titles = kwargs.get('titles', []) | |
|
134 | self.polar = False | |
|
135 | self.grid = kwargs.get('grid', False) | |
|
136 | ||
|
137 | def __fmtTime(self, x, pos): | |
|
138 | ''' | |
|
139 | ''' | |
|
140 | ||
|
141 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) | |
|
142 | ||
|
143 | def __setup(self): | |
|
144 | ''' | |
|
145 | Common setup for all figures, here figures and axes are created | |
|
146 | ''' | |
|
147 | ||
|
148 | if self.CODE not in self.data: | |
|
149 | raise ValueError(log.error('Missing data for {}'.format(self.CODE), | |
|
150 | self.name)) | |
|
151 | ||
|
152 | self.setup() | |
|
153 | ||
|
154 | self.time_label = 'LT' if self.localtime else 'UTC' | |
|
155 | if self.data.localtime: | |
|
156 | self.getDateTime = datetime.datetime.fromtimestamp | |
|
157 | else: | |
|
158 | self.getDateTime = datetime.datetime.utcfromtimestamp | |
|
159 | ||
|
160 | if self.width is None: | |
|
161 | self.width = 8 | |
|
162 | ||
|
163 | self.figures = [] | |
|
164 | self.axes = [] | |
|
165 | self.cb_axes = [] | |
|
166 | self.pf_axes = [] | |
|
167 | self.cmaps = [] | |
|
168 | ||
|
169 | size = '15%' if self.ncols == 1 else '30%' | |
|
170 | pad = '4%' if self.ncols == 1 else '8%' | |
|
171 | ||
|
172 | if self.oneFigure: | |
|
173 | if self.height is None: | |
|
174 | self.height = 1.4 * self.nrows + 1 | |
|
175 | fig = plt.figure(figsize=(self.width, self.height), | |
|
176 | edgecolor='k', | |
|
177 | facecolor='w') | |
|
178 | self.figures.append(fig) | |
|
179 | for n in range(self.nplots): | |
|
180 | ax = fig.add_subplot(self.nrows, self.ncols, | |
|
181 | n + 1, polar=self.polar) | |
|
182 | ax.tick_params(labelsize=8) | |
|
183 | ax.firsttime = True | |
|
184 | ax.index = 0 | |
|
185 | ax.press = None | |
|
186 | self.axes.append(ax) | |
|
187 | if self.showprofile: | |
|
188 | cax = self.__add_axes(ax, size=size, pad=pad) | |
|
189 | cax.tick_params(labelsize=8) | |
|
190 | self.pf_axes.append(cax) | |
|
191 | else: | |
|
192 | if self.height is None: | |
|
193 | self.height = 3 | |
|
194 | for n in range(self.nplots): | |
|
195 | fig = plt.figure(figsize=(self.width, self.height), | |
|
196 | edgecolor='k', | |
|
197 | facecolor='w') | |
|
198 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) | |
|
199 | ax.tick_params(labelsize=8) | |
|
200 | ax.firsttime = True | |
|
201 | ax.index = 0 | |
|
202 | ax.press = None | |
|
203 | self.figures.append(fig) | |
|
204 | self.axes.append(ax) | |
|
205 | if self.showprofile: | |
|
206 | cax = self.__add_axes(ax, size=size, pad=pad) | |
|
207 | cax.tick_params(labelsize=8) | |
|
208 | self.pf_axes.append(cax) | |
|
209 | ||
|
210 | for n in range(self.nrows): | |
|
211 | if self.colormaps is not None: | |
|
212 | cmap = plt.get_cmap(self.colormaps[n]) | |
|
213 | else: | |
|
214 | cmap = plt.get_cmap(self.colormap) | |
|
215 | cmap.set_bad(self.bgcolor, 1.) | |
|
216 | self.cmaps.append(cmap) | |
|
217 | ||
|
218 | for fig in self.figures: | |
|
219 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) | |
|
220 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) | |
|
221 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) | |
|
222 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) | |
|
223 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) | |
|
224 | if self.show: | |
|
225 | fig.show() | |
|
226 | ||
|
227 | def OnKeyPress(self, event): | |
|
228 | ''' | |
|
229 | Event for pressing keys (up, down) change colormap | |
|
230 | ''' | |
|
231 | ax = event.inaxes | |
|
232 | if ax in self.axes: | |
|
233 | if event.key == 'down': | |
|
234 | ax.index += 1 | |
|
235 | elif event.key == 'up': | |
|
236 | ax.index -= 1 | |
|
237 | if ax.index < 0: | |
|
238 | ax.index = len(CMAPS) - 1 | |
|
239 | elif ax.index == len(CMAPS): | |
|
240 | ax.index = 0 | |
|
241 | cmap = CMAPS[ax.index] | |
|
242 | ax.cbar.set_cmap(cmap) | |
|
243 | ax.cbar.draw_all() | |
|
244 | ax.plt.set_cmap(cmap) | |
|
245 | ax.cbar.patch.figure.canvas.draw() | |
|
246 | self.colormap = cmap.name | |
|
247 | ||
|
248 | def OnBtnScroll(self, event): | |
|
249 | ''' | |
|
250 | Event for scrolling, scale figure | |
|
251 | ''' | |
|
252 | cb_ax = event.inaxes | |
|
253 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
|
254 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
|
255 | pt = ax.cbar.ax.bbox.get_points()[:, 1] | |
|
256 | nrm = ax.cbar.norm | |
|
257 | vmin, vmax, p0, p1, pS = ( | |
|
258 | nrm.vmin, nrm.vmax, pt[0], pt[1], event.y) | |
|
259 | scale = 2 if event.step == 1 else 0.5 | |
|
260 | point = vmin + (vmax - vmin) / (p1 - p0) * (pS - p0) | |
|
261 | ax.cbar.norm.vmin = point - scale * (point - vmin) | |
|
262 | ax.cbar.norm.vmax = point - scale * (point - vmax) | |
|
263 | ax.plt.set_norm(ax.cbar.norm) | |
|
264 | ax.cbar.draw_all() | |
|
265 | ax.cbar.patch.figure.canvas.draw() | |
|
266 | ||
|
267 | def onBtnPress(self, event): | |
|
268 | ''' | |
|
269 | Event for mouse button press | |
|
270 | ''' | |
|
271 | cb_ax = event.inaxes | |
|
272 | if cb_ax is None: | |
|
273 | return | |
|
274 | ||
|
275 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
|
276 | cb_ax.press = event.x, event.y | |
|
277 | else: | |
|
278 | cb_ax.press = None | |
|
279 | ||
|
280 | def onMotion(self, event): | |
|
281 | ''' | |
|
282 | Event for move inside colorbar | |
|
283 | ''' | |
|
284 | cb_ax = event.inaxes | |
|
285 | if cb_ax is None: | |
|
286 | return | |
|
287 | if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
|
288 | return | |
|
289 | if cb_ax.press is None: | |
|
290 | return | |
|
291 | ||
|
292 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
|
293 | xprev, yprev = cb_ax.press | |
|
294 | dx = event.x - xprev | |
|
295 | dy = event.y - yprev | |
|
296 | cb_ax.press = event.x, event.y | |
|
297 | scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin | |
|
298 | perc = 0.03 | |
|
299 | ||
|
300 | if event.button == 1: | |
|
301 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) | |
|
302 | ax.cbar.norm.vmax -= (perc * scale) * numpy.sign(dy) | |
|
303 | elif event.button == 3: | |
|
304 | ax.cbar.norm.vmin -= (perc * scale) * numpy.sign(dy) | |
|
305 | ax.cbar.norm.vmax += (perc * scale) * numpy.sign(dy) | |
|
306 | ||
|
307 | ax.cbar.draw_all() | |
|
308 | ax.plt.set_norm(ax.cbar.norm) | |
|
309 | ax.cbar.patch.figure.canvas.draw() | |
|
310 | ||
|
311 | def onBtnRelease(self, event): | |
|
312 | ''' | |
|
313 | Event for mouse button release | |
|
314 | ''' | |
|
315 | cb_ax = event.inaxes | |
|
316 | if cb_ax is not None: | |
|
317 | cb_ax.press = None | |
|
318 | ||
|
319 | def __add_axes(self, ax, size='30%', pad='8%'): | |
|
320 | ''' | |
|
321 | Add new axes to the given figure | |
|
322 | ''' | |
|
323 | divider = make_axes_locatable(ax) | |
|
324 | nax = divider.new_horizontal(size=size, pad=pad) | |
|
325 | ax.figure.add_axes(nax) | |
|
326 | return nax | |
|
327 | ||
|
328 | self.setup() | |
|
329 | ||
|
330 | def setup(self): | |
|
331 | ''' | |
|
332 | This method should be implemented in the child class, the following | |
|
333 | attributes should be set: | |
|
334 | ||
|
335 | self.nrows: number of rows | |
|
336 | self.ncols: number of cols | |
|
337 | self.nplots: number of plots (channels or pairs) | |
|
338 | self.ylabel: label for Y axes | |
|
339 | self.titles: list of axes title | |
|
340 | ||
|
341 | ''' | |
|
342 | raise NotImplementedError | |
|
343 | ||
|
344 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
|
345 | ''' | |
|
346 | Create a masked array for missing data | |
|
347 | ''' | |
|
348 | if x_buffer.shape[0] < 2: | |
|
349 | return x_buffer, y_buffer, z_buffer | |
|
350 | ||
|
351 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
|
352 | x_median = numpy.median(deltas) | |
|
353 | ||
|
354 | index = numpy.where(deltas > 5 * x_median) | |
|
355 | ||
|
356 | if len(index[0]) != 0: | |
|
357 | z_buffer[::, index[0], ::] = self.__missing | |
|
358 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
|
359 | 0.99 * self.__missing, | |
|
360 | 1.01 * self.__missing) | |
|
361 | ||
|
362 | return x_buffer, y_buffer, z_buffer | |
|
363 | ||
|
364 | def decimate(self): | |
|
365 | ||
|
366 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
|
367 | dy = int(len(self.y) / self.decimation) + 1 | |
|
368 | ||
|
369 | # x = self.x[::dx] | |
|
370 | x = self.x | |
|
371 | y = self.y[::dy] | |
|
372 | z = self.z[::, ::, ::dy] | |
|
373 | ||
|
374 | return x, y, z | |
|
375 | 37 | |
|
376 | def format(self): | |
|
377 | ''' | |
|
378 | Set min and max values, labels, ticks and titles | |
|
379 | ''' | |
|
380 | ||
|
381 | if self.xmin is None: | |
|
382 | xmin = self.min_time | |
|
383 | else: | |
|
384 | if self.xaxis is 'time': | |
|
385 | dt = self.getDateTime(self.min_time) | |
|
386 | xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - | |
|
387 | datetime.datetime(1970, 1, 1)).total_seconds() | |
|
388 | if self.data.localtime: | |
|
389 | xmin += time.timezone | |
|
390 | else: | |
|
391 | xmin = self.xmin | |
|
392 | ||
|
393 | if self.xmax is None: | |
|
394 | xmax = xmin + self.xrange * 60 * 60 | |
|
395 | else: | |
|
396 | if self.xaxis is 'time': | |
|
397 | dt = self.getDateTime(self.max_time) | |
|
398 | xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) - | |
|
399 | datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds() | |
|
400 | if self.data.localtime: | |
|
401 | xmax += time.timezone | |
|
402 | else: | |
|
403 | xmax = self.xmax | |
|
404 | ||
|
405 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) | |
|
406 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
|
407 | ||
|
408 | Y = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000]) | |
|
409 | i = 1 if numpy.where(abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0] | |
|
410 | ystep = Y[i] / 10. | |
|
411 | ||
|
412 | if self.xaxis is not 'time': | |
|
413 | X = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000])/2. | |
|
414 | i = 1 if numpy.where(abs(xmax-xmin) <= X)[0][0] < 0 else numpy.where(abs(xmax-xmin) <= X)[0][0] | |
|
415 | xstep = X[i] / 10. | |
|
416 | ||
|
417 | for n, ax in enumerate(self.axes): | |
|
418 | if ax.firsttime: | |
|
419 | ax.set_facecolor(self.bgcolor) | |
|
420 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) | |
|
421 | if self.xscale: | |
|
422 | ax.xaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.xscale))) | |
|
423 | if self.xscale: | |
|
424 | ax.yaxis.set_major_formatter(FuncFormatter(lambda x, pos: '{0:g}'.format(x*self.yscale))) | |
|
425 | if self.xaxis is 'time': | |
|
426 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) | |
|
427 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
|
428 | else: | |
|
429 | ax.xaxis.set_major_locator(MultipleLocator(xstep)) | |
|
430 | if self.xlabel is not None: | |
|
431 | ax.set_xlabel(self.xlabel) | |
|
432 | ax.set_ylabel(self.ylabel) | |
|
433 | ax.firsttime = False | |
|
434 | if self.showprofile: | |
|
435 | self.pf_axes[n].set_ylim(ymin, ymax) | |
|
436 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
|
437 | self.pf_axes[n].set_xlabel('dB') | |
|
438 | self.pf_axes[n].grid(b=True, axis='x') | |
|
439 | [tick.set_visible(False) | |
|
440 | for tick in self.pf_axes[n].get_yticklabels()] | |
|
441 | if self.colorbar: | |
|
442 | ax.cbar = plt.colorbar( | |
|
443 | ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) | |
|
444 | ax.cbar.ax.tick_params(labelsize=8) | |
|
445 | ax.cbar.ax.press = None | |
|
446 | if self.cb_label: | |
|
447 | ax.cbar.set_label(self.cb_label, size=8) | |
|
448 | elif self.cb_labels: | |
|
449 | ax.cbar.set_label(self.cb_labels[n], size=8) | |
|
450 | else: | |
|
451 | ax.cbar = None | |
|
452 | if self.grid: | |
|
453 | ax.grid(True) | |
|
454 | ||
|
455 | if not self.polar: | |
|
456 | ax.set_xlim(xmin, xmax) | |
|
457 | ax.set_ylim(ymin, ymax) | |
|
458 | ax.set_title('{} {} {}'.format( | |
|
459 | self.titles[n], | |
|
460 | self.getDateTime(self.max_time).strftime('%Y-%m-%dT%H:%M:%S'), | |
|
461 | self.time_label), | |
|
462 | size=8) | |
|
463 | else: | |
|
464 | ax.set_title('{}'.format(self.titles[n]), size=8) | |
|
465 | ax.set_ylim(0, 90) | |
|
466 | ax.set_yticks(numpy.arange(0, 90, 20)) | |
|
467 | ax.yaxis.labelpad = 40 | |
|
468 | ||
|
469 | def __plot(self): | |
|
470 | ''' | |
|
471 | ''' | |
|
472 | log.log('Plotting', self.name) | |
|
473 | ||
|
474 | try: | |
|
475 | self.plot() | |
|
476 | self.format() | |
|
477 | except Exception as e: | |
|
478 | log.warning('{} Plot could not be updated... check data'.format(self.CODE), self.name) | |
|
479 | log.error(str(e), '') | |
|
480 | return | |
|
481 | ||
|
482 | for n, fig in enumerate(self.figures): | |
|
483 | if self.nrows == 0 or self.nplots == 0: | |
|
484 | log.warning('No data', self.name) | |
|
485 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') | |
|
486 | fig.canvas.manager.set_window_title(self.CODE) | |
|
487 | continue | |
|
488 | ||
|
489 | fig.tight_layout() | |
|
490 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
|
491 | self.getDateTime(self.max_time).strftime('%Y/%m/%d'))) | |
|
492 | fig.canvas.draw() | |
|
493 | ||
|
494 | if self.save and (self.data.ended or not self.data.buffering): | |
|
495 | ||
|
496 | if self.save_labels: | |
|
497 | labels = self.save_labels | |
|
498 | else: | |
|
499 | labels = list(range(self.nrows)) | |
|
500 | ||
|
501 | if self.oneFigure: | |
|
502 | label = '' | |
|
503 | else: | |
|
504 | label = '-{}'.format(labels[n]) | |
|
505 | figname = os.path.join( | |
|
506 | self.save, | |
|
507 | self.CODE, | |
|
508 | '{}{}_{}.png'.format( | |
|
509 | self.CODE, | |
|
510 | label, | |
|
511 | self.getDateTime(self.saveTime).strftime( | |
|
512 | '%Y%m%d_%H%M%S'), | |
|
513 | ) | |
|
514 | ) | |
|
515 | log.log('Saving figure: {}'.format(figname), self.name) | |
|
516 | if not os.path.isdir(os.path.dirname(figname)): | |
|
517 | os.makedirs(os.path.dirname(figname)) | |
|
518 | fig.savefig(figname) | |
|
519 | ||
|
520 | def plot(self): | |
|
521 | ''' | |
|
522 | ''' | |
|
523 | raise NotImplementedError | |
|
524 | ||
|
525 | def run(self): | |
|
526 | ||
|
527 | log.log('Starting', self.name) | |
|
528 | ||
|
529 | context = zmq.Context() | |
|
530 | receiver = context.socket(zmq.SUB) | |
|
531 | receiver.setsockopt(zmq.SUBSCRIBE, '') | |
|
532 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) | |
|
533 | ||
|
534 | if 'server' in self.kwargs['parent']: | |
|
535 | receiver.connect( | |
|
536 | 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |
|
537 | else: | |
|
538 | receiver.connect("ipc:///tmp/zmq.plots") | |
|
539 | ||
|
540 | while True: | |
|
541 | try: | |
|
542 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | |
|
543 | if self.data.localtime and self.localtime: | |
|
544 | self.times = self.data.times | |
|
545 | elif self.data.localtime and not self.localtime: | |
|
546 | self.times = self.data.times + time.timezone | |
|
547 | elif not self.data.localtime and self.localtime: | |
|
548 | self.times = self.data.times - time.timezone | |
|
549 | else: | |
|
550 | self.times = self.data.times | |
|
551 | ||
|
552 | self.min_time = self.times[0] | |
|
553 | self.max_time = self.times[-1] | |
|
554 | ||
|
555 | if self.isConfig is False: | |
|
556 | self.__setup() | |
|
557 | self.isConfig = True | |
|
558 | ||
|
559 | self.__plot() | |
|
560 | ||
|
561 | except zmq.Again as e: | |
|
562 | if self.data and self.data.ended: | |
|
563 | break | |
|
564 | log.log('Waiting for data...') | |
|
565 | if self.data: | |
|
566 | figpause(self.data.throttle) | |
|
567 | else: | |
|
568 | time.sleep(2) | |
|
569 | ||
|
570 | def close(self): | |
|
571 | if self.data: | |
|
572 | self.__plot() | |
|
573 | ||
|
574 | ||
|
575 | class PlotSpectraData(PlotData): | |
|
38 | class SpectraPlot(Plot): | |
|
576 | 39 | ''' |
|
577 | 40 | Plot for Spectra data |
|
578 | 41 | ''' |
|
579 | 42 | |
|
580 | 43 | CODE = 'spc' |
|
581 | 44 | colormap = 'jro' |
|
582 | 45 | |
|
583 | 46 | def setup(self): |
|
584 | 47 | self.nplots = len(self.data.channels) |
|
585 | 48 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) |
|
586 | 49 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) |
|
587 | 50 | self.width = 3.4 * self.ncols |
|
588 | 51 | self.height = 3 * self.nrows |
|
589 | 52 | self.cb_label = 'dB' |
|
590 | 53 | if self.showprofile: |
|
591 | 54 | self.width += 0.8 * self.ncols |
|
592 | 55 | |
|
593 | 56 | self.ylabel = 'Range [km]' |
|
594 | 57 | |
|
595 | 58 | def plot(self): |
|
596 | 59 | if self.xaxis == "frequency": |
|
597 | 60 | x = self.data.xrange[0] |
|
598 | 61 | self.xlabel = "Frequency (kHz)" |
|
599 | 62 | elif self.xaxis == "time": |
|
600 | 63 | x = self.data.xrange[1] |
|
601 | 64 | self.xlabel = "Time (ms)" |
|
602 | 65 | else: |
|
603 | 66 | x = self.data.xrange[2] |
|
604 | 67 | self.xlabel = "Velocity (m/s)" |
|
605 | 68 | |
|
606 | 69 | if self.CODE == 'spc_mean': |
|
607 | 70 | x = self.data.xrange[2] |
|
608 | 71 | self.xlabel = "Velocity (m/s)" |
|
609 | 72 | |
|
610 | 73 | self.titles = [] |
|
611 | 74 | |
|
612 | 75 | y = self.data.heights |
|
613 | 76 | self.y = y |
|
614 | 77 | z = self.data['spc'] |
|
615 | 78 | |
|
616 | 79 | for n, ax in enumerate(self.axes): |
|
617 | 80 | noise = self.data['noise'][n][-1] |
|
618 | 81 | if self.CODE == 'spc_mean': |
|
619 | 82 | mean = self.data['mean'][n][-1] |
|
620 | 83 | if ax.firsttime: |
|
621 | 84 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
622 | 85 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
623 | 86 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) |
|
624 | 87 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) |
|
625 | 88 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
626 | 89 | vmin=self.zmin, |
|
627 | 90 | vmax=self.zmax, |
|
628 | 91 | cmap=plt.get_cmap(self.colormap) |
|
629 | 92 | ) |
|
630 | 93 | |
|
631 | 94 | if self.showprofile: |
|
632 | 95 | ax.plt_profile = self.pf_axes[n].plot( |
|
633 | 96 | self.data['rti'][n][-1], y)[0] |
|
634 | 97 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, |
|
635 | 98 | color="k", linestyle="dashed", lw=1)[0] |
|
636 | 99 | if self.CODE == 'spc_mean': |
|
637 | 100 | ax.plt_mean = ax.plot(mean, y, color='k')[0] |
|
638 | 101 | else: |
|
639 | 102 | ax.plt.set_array(z[n].T.ravel()) |
|
640 | 103 | if self.showprofile: |
|
641 | 104 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) |
|
642 | 105 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) |
|
643 | 106 | if self.CODE == 'spc_mean': |
|
644 | 107 | ax.plt_mean.set_data(mean, y) |
|
645 | 108 | |
|
646 | 109 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
647 | self.saveTime = self.max_time | |
|
648 | 110 | |
|
649 | 111 | |
|
650 |
class |
|
|
112 | class CrossSpectraPlot(Plot): | |
|
651 | 113 | |
|
652 | 114 | CODE = 'cspc' |
|
653 | 115 | zmin_coh = None |
|
654 | 116 | zmax_coh = None |
|
655 | 117 | zmin_phase = None |
|
656 | 118 | zmax_phase = None |
|
657 | 119 | |
|
658 | 120 | def setup(self): |
|
659 | 121 | |
|
660 | 122 | self.ncols = 4 |
|
661 | 123 | self.nrows = len(self.data.pairs) |
|
662 | 124 | self.nplots = self.nrows * 4 |
|
663 | 125 | self.width = 3.4 * self.ncols |
|
664 | 126 | self.height = 3 * self.nrows |
|
665 | 127 | self.ylabel = 'Range [km]' |
|
666 | 128 | self.showprofile = False |
|
667 | 129 | |
|
668 | 130 | def plot(self): |
|
669 | 131 | |
|
670 | 132 | if self.xaxis == "frequency": |
|
671 | 133 | x = self.data.xrange[0] |
|
672 | 134 | self.xlabel = "Frequency (kHz)" |
|
673 | 135 | elif self.xaxis == "time": |
|
674 | 136 | x = self.data.xrange[1] |
|
675 | 137 | self.xlabel = "Time (ms)" |
|
676 | 138 | else: |
|
677 | 139 | x = self.data.xrange[2] |
|
678 | 140 | self.xlabel = "Velocity (m/s)" |
|
679 | 141 | |
|
680 | 142 | self.titles = [] |
|
681 | 143 | |
|
682 | 144 | y = self.data.heights |
|
683 | 145 | self.y = y |
|
684 | 146 | spc = self.data['spc'] |
|
685 | 147 | cspc = self.data['cspc'] |
|
686 | 148 | |
|
687 | 149 | for n in range(self.nrows): |
|
688 | 150 | noise = self.data['noise'][n][-1] |
|
689 | 151 | pair = self.data.pairs[n] |
|
690 | 152 | ax = self.axes[4 * n] |
|
691 | 153 | ax3 = self.axes[4 * n + 3] |
|
692 | 154 | if ax.firsttime: |
|
693 | 155 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
694 | 156 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
695 | 157 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) |
|
696 | 158 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) |
|
697 | 159 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, |
|
698 | 160 | vmin=self.zmin, |
|
699 | 161 | vmax=self.zmax, |
|
700 | 162 | cmap=plt.get_cmap(self.colormap) |
|
701 | 163 | ) |
|
702 | 164 | else: |
|
703 | 165 | ax.plt.set_array(spc[pair[0]].T.ravel()) |
|
704 | 166 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
705 | 167 | |
|
706 | 168 | ax = self.axes[4 * n + 1] |
|
707 | 169 | if ax.firsttime: |
|
708 | 170 | ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, |
|
709 | 171 | vmin=self.zmin, |
|
710 | 172 | vmax=self.zmax, |
|
711 | 173 | cmap=plt.get_cmap(self.colormap) |
|
712 | 174 | ) |
|
713 | 175 | else: |
|
714 | 176 | ax.plt.set_array(spc[pair[1]].T.ravel()) |
|
715 | 177 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
716 | 178 | |
|
717 | 179 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) |
|
718 | 180 | coh = numpy.abs(out) |
|
719 | 181 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi |
|
720 | 182 | |
|
721 | 183 | ax = self.axes[4 * n + 2] |
|
722 | 184 | if ax.firsttime: |
|
723 | 185 | ax.plt = ax.pcolormesh(x, y, coh.T, |
|
724 | 186 | vmin=0, |
|
725 | 187 | vmax=1, |
|
726 | 188 | cmap=plt.get_cmap(self.colormap_coh) |
|
727 | 189 | ) |
|
728 | 190 | else: |
|
729 | 191 | ax.plt.set_array(coh.T.ravel()) |
|
730 | 192 | self.titles.append( |
|
731 | 193 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) |
|
732 | 194 | |
|
733 | 195 | ax = self.axes[4 * n + 3] |
|
734 | 196 | if ax.firsttime: |
|
735 | 197 | ax.plt = ax.pcolormesh(x, y, phase.T, |
|
736 | 198 | vmin=-180, |
|
737 | 199 | vmax=180, |
|
738 | 200 | cmap=plt.get_cmap(self.colormap_phase) |
|
739 | 201 | ) |
|
740 | 202 | else: |
|
741 | 203 | ax.plt.set_array(phase.T.ravel()) |
|
742 | 204 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) |
|
743 | 205 | |
|
744 | self.saveTime = self.max_time | |
|
745 | ||
|
746 | 206 | |
|
747 |
class |
|
|
207 | class SpectraMeanPlot(SpectraPlot): | |
|
748 | 208 | ''' |
|
749 | 209 | Plot for Spectra and Mean |
|
750 | 210 | ''' |
|
751 | 211 | CODE = 'spc_mean' |
|
752 | 212 | colormap = 'jro' |
|
753 | 213 | |
|
754 | 214 | |
|
755 |
class |
|
|
215 | class RTIPlot(Plot): | |
|
756 | 216 | ''' |
|
757 | 217 | Plot for RTI data |
|
758 | 218 | ''' |
|
759 | 219 | |
|
760 | 220 | CODE = 'rti' |
|
761 | 221 | colormap = 'jro' |
|
762 | 222 | |
|
763 | 223 | def setup(self): |
|
764 | 224 | self.xaxis = 'time' |
|
765 | 225 | self.ncols = 1 |
|
766 | 226 | self.nrows = len(self.data.channels) |
|
767 | 227 | self.nplots = len(self.data.channels) |
|
768 | 228 | self.ylabel = 'Range [km]' |
|
769 | 229 | self.cb_label = 'dB' |
|
770 | 230 | self.titles = ['{} Channel {}'.format( |
|
771 | 231 | self.CODE.upper(), x) for x in range(self.nrows)] |
|
772 | 232 | |
|
773 | 233 | def plot(self): |
|
774 | self.x = self.times | |
|
234 | self.x = self.data.times | |
|
775 | 235 | self.y = self.data.heights |
|
776 | 236 | self.z = self.data[self.CODE] |
|
777 | 237 | self.z = numpy.ma.masked_invalid(self.z) |
|
778 | 238 | |
|
779 | 239 | if self.decimation is None: |
|
780 | 240 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
781 | 241 | else: |
|
782 | 242 | x, y, z = self.fill_gaps(*self.decimate()) |
|
783 | 243 | |
|
784 |
for n, ax in enumerate(self.axes): |
|
|
244 | for n, ax in enumerate(self.axes): | |
|
785 | 245 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) |
|
786 | 246 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) |
|
787 | 247 | if ax.firsttime: |
|
788 | 248 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
789 | 249 | vmin=self.zmin, |
|
790 | 250 | vmax=self.zmax, |
|
791 | 251 | cmap=plt.get_cmap(self.colormap) |
|
792 | 252 | ) |
|
793 | 253 | if self.showprofile: |
|
794 | 254 | ax.plot_profile = self.pf_axes[n].plot( |
|
795 | 255 | self.data['rti'][n][-1], self.y)[0] |
|
796 | 256 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, |
|
797 | 257 | color="k", linestyle="dashed", lw=1)[0] |
|
798 | 258 | else: |
|
799 | 259 | ax.collections.remove(ax.collections[0]) |
|
800 | 260 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
801 | 261 | vmin=self.zmin, |
|
802 | 262 | vmax=self.zmax, |
|
803 | 263 | cmap=plt.get_cmap(self.colormap) |
|
804 | 264 | ) |
|
805 | 265 | if self.showprofile: |
|
806 | 266 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) |
|
807 | 267 | ax.plot_noise.set_data(numpy.repeat( |
|
808 | 268 | self.data['noise'][n][-1], len(self.y)), self.y) |
|
809 | 269 | |
|
810 | self.saveTime = self.min_time | |
|
811 | ||
|
812 | 270 | |
|
813 | class PlotCOHData(PlotRTIData): | |
|
271 | class CoherencePlot(RTIPlot): | |
|
814 | 272 | ''' |
|
815 | 273 | Plot for Coherence data |
|
816 | 274 | ''' |
|
817 | 275 | |
|
818 | 276 | CODE = 'coh' |
|
819 | 277 | |
|
820 | 278 | def setup(self): |
|
821 | 279 | self.xaxis = 'time' |
|
822 | 280 | self.ncols = 1 |
|
823 | 281 | self.nrows = len(self.data.pairs) |
|
824 | 282 | self.nplots = len(self.data.pairs) |
|
825 | 283 | self.ylabel = 'Range [km]' |
|
826 | 284 | if self.CODE == 'coh': |
|
827 | 285 | self.cb_label = '' |
|
828 | 286 | self.titles = [ |
|
829 | 287 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
830 | 288 | else: |
|
831 | 289 | self.cb_label = 'Degrees' |
|
832 | 290 | self.titles = [ |
|
833 | 291 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
834 | 292 | |
|
835 | 293 | |
|
836 | class PlotPHASEData(PlotCOHData): | |
|
294 | class PhasePlot(CoherencePlot): | |
|
837 | 295 | ''' |
|
838 | 296 | Plot for Phase map data |
|
839 | 297 | ''' |
|
840 | 298 | |
|
841 | 299 | CODE = 'phase' |
|
842 | 300 | colormap = 'seismic' |
|
843 | 301 | |
|
844 | 302 | |
|
845 |
class |
|
|
303 | class NoisePlot(Plot): | |
|
846 | 304 | ''' |
|
847 | 305 | Plot for noise |
|
848 | 306 | ''' |
|
849 | 307 | |
|
850 | 308 | CODE = 'noise' |
|
851 | 309 | |
|
852 | 310 | def setup(self): |
|
853 | 311 | self.xaxis = 'time' |
|
854 | 312 | self.ncols = 1 |
|
855 | 313 | self.nrows = 1 |
|
856 | 314 | self.nplots = 1 |
|
857 | 315 | self.ylabel = 'Intensity [dB]' |
|
858 | 316 | self.titles = ['Noise'] |
|
859 | 317 | self.colorbar = False |
|
860 | 318 | |
|
861 | 319 | def plot(self): |
|
862 | 320 | |
|
863 | x = self.times | |
|
864 | xmin = self.min_time | |
|
321 | x = self.data.times | |
|
322 | xmin = self.data.min_time | |
|
865 | 323 | xmax = xmin + self.xrange * 60 * 60 |
|
866 | 324 | Y = self.data[self.CODE] |
|
867 | 325 | |
|
868 | 326 | if self.axes[0].firsttime: |
|
869 | 327 | for ch in self.data.channels: |
|
870 | 328 | y = Y[ch] |
|
871 | 329 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
872 | 330 | plt.legend() |
|
873 | 331 | else: |
|
874 | 332 | for ch in self.data.channels: |
|
875 | 333 | y = Y[ch] |
|
876 | 334 | self.axes[0].lines[ch].set_data(x, y) |
|
877 | 335 | |
|
878 | 336 | self.ymin = numpy.nanmin(Y) - 5 |
|
879 | 337 | self.ymax = numpy.nanmax(Y) + 5 |
|
880 | self.saveTime = self.min_time | |
|
881 | 338 | |
|
882 | 339 | |
|
883 |
class Plot |
|
|
340 | class SnrPlot(RTIPlot): | |
|
884 | 341 | ''' |
|
885 | 342 | Plot for SNR Data |
|
886 | 343 | ''' |
|
887 | 344 | |
|
888 | 345 | CODE = 'snr' |
|
889 | 346 | colormap = 'jet' |
|
890 | 347 | |
|
891 | 348 | |
|
892 | class PlotDOPData(PlotRTIData): | |
|
349 | class DopplerPlot(RTIPlot): | |
|
893 | 350 | ''' |
|
894 | 351 | Plot for DOPPLER Data |
|
895 | 352 | ''' |
|
896 | 353 | |
|
897 | 354 | CODE = 'dop' |
|
898 | 355 | colormap = 'jet' |
|
899 | 356 | |
|
900 | 357 | |
|
901 |
class |
|
|
358 | class SkyMapPlot(Plot): | |
|
902 | 359 | ''' |
|
903 | 360 | Plot for meteors detection data |
|
904 | 361 | ''' |
|
905 | 362 | |
|
906 | 363 | CODE = 'param' |
|
907 | 364 | |
|
908 | 365 | def setup(self): |
|
909 | 366 | |
|
910 | 367 | self.ncols = 1 |
|
911 | 368 | self.nrows = 1 |
|
912 | 369 | self.width = 7.2 |
|
913 | 370 | self.height = 7.2 |
|
914 | 371 | self.nplots = 1 |
|
915 | 372 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
916 | 373 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
917 | 374 | self.polar = True |
|
918 | 375 | self.ymin = -180 |
|
919 | 376 | self.ymax = 180 |
|
920 | 377 | self.colorbar = False |
|
921 | 378 | |
|
922 | 379 | def plot(self): |
|
923 | 380 | |
|
924 | 381 | arrayParameters = numpy.concatenate(self.data['param']) |
|
925 | 382 | error = arrayParameters[:, -1] |
|
926 | 383 | indValid = numpy.where(error == 0)[0] |
|
927 | 384 | finalMeteor = arrayParameters[indValid, :] |
|
928 | 385 | finalAzimuth = finalMeteor[:, 3] |
|
929 | 386 | finalZenith = finalMeteor[:, 4] |
|
930 | 387 | |
|
931 | 388 | x = finalAzimuth * numpy.pi / 180 |
|
932 | 389 | y = finalZenith |
|
933 | 390 | |
|
934 | 391 | ax = self.axes[0] |
|
935 | 392 | |
|
936 | 393 | if ax.firsttime: |
|
937 | 394 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
938 | 395 | else: |
|
939 | 396 | ax.plot.set_data(x, y) |
|
940 | 397 | |
|
941 | dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S') | |
|
942 | dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S') | |
|
398 | dt1 = self.getDateTime(self.data.min_time).strftime('%y/%m/%d %H:%M:%S') | |
|
399 | dt2 = self.getDateTime(self.data.max_time).strftime('%y/%m/%d %H:%M:%S') | |
|
943 | 400 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
944 | 401 | dt2, |
|
945 | 402 | len(x)) |
|
946 | 403 | self.titles[0] = title |
|
947 | self.saveTime = self.max_time | |
|
948 | 404 | |
|
949 | 405 | |
|
950 |
class P |
|
|
406 | class ParametersPlot(RTIPlot): | |
|
951 | 407 | ''' |
|
952 | 408 | Plot for data_param object |
|
953 | 409 | ''' |
|
954 | 410 | |
|
955 | 411 | CODE = 'param' |
|
956 | 412 | colormap = 'seismic' |
|
957 | 413 | |
|
958 | 414 | def setup(self): |
|
959 | 415 | self.xaxis = 'time' |
|
960 | 416 | self.ncols = 1 |
|
961 | 417 | self.nrows = self.data.shape(self.CODE)[0] |
|
962 | 418 | self.nplots = self.nrows |
|
963 | 419 | if self.showSNR: |
|
964 | 420 | self.nrows += 1 |
|
965 | 421 | self.nplots += 1 |
|
966 | 422 | |
|
967 | 423 | self.ylabel = 'Height [km]' |
|
968 | 424 | if not self.titles: |
|
969 | 425 | self.titles = self.data.parameters \ |
|
970 | 426 | if self.data.parameters else ['Param {}'.format(x) for x in range(self.nrows)] |
|
971 | 427 | if self.showSNR: |
|
972 | 428 | self.titles.append('SNR') |
|
973 | 429 | |
|
974 | 430 | def plot(self): |
|
975 | 431 | self.data.normalize_heights() |
|
976 | self.x = self.times | |
|
432 | self.x = self.data.times | |
|
977 | 433 | self.y = self.data.heights |
|
978 | 434 | if self.showSNR: |
|
979 | 435 | self.z = numpy.concatenate( |
|
980 | 436 | (self.data[self.CODE], self.data['snr']) |
|
981 | 437 | ) |
|
982 | 438 | else: |
|
983 | 439 | self.z = self.data[self.CODE] |
|
984 | 440 | |
|
985 | 441 | self.z = numpy.ma.masked_invalid(self.z) |
|
986 | 442 | |
|
987 | 443 | if self.decimation is None: |
|
988 | 444 | x, y, z = self.fill_gaps(self.x, self.y, self.z) |
|
989 | 445 | else: |
|
990 | 446 | x, y, z = self.fill_gaps(*self.decimate()) |
|
991 | 447 | |
|
992 | 448 | for n, ax in enumerate(self.axes): |
|
993 | ||
|
449 | ||
|
994 | 450 | self.zmax = self.zmax if self.zmax is not None else numpy.max( |
|
995 | 451 | self.z[n]) |
|
996 | 452 | self.zmin = self.zmin if self.zmin is not None else numpy.min( |
|
997 | 453 | self.z[n]) |
|
998 | 454 | |
|
999 | 455 | if ax.firsttime: |
|
1000 | 456 | if self.zlimits is not None: |
|
1001 | 457 | self.zmin, self.zmax = self.zlimits[n] |
|
1002 | 458 | |
|
1003 | 459 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
1004 | 460 | vmin=self.zmin, |
|
1005 | 461 | vmax=self.zmax, |
|
1006 | 462 | cmap=self.cmaps[n] |
|
1007 | 463 | ) |
|
1008 | 464 | else: |
|
1009 | 465 | if self.zlimits is not None: |
|
1010 | 466 | self.zmin, self.zmax = self.zlimits[n] |
|
1011 | 467 | ax.collections.remove(ax.collections[0]) |
|
1012 | 468 | ax.plt = ax.pcolormesh(x, y, z[n].T * self.factors[n], |
|
1013 | 469 | vmin=self.zmin, |
|
1014 | 470 | vmax=self.zmax, |
|
1015 | 471 | cmap=self.cmaps[n] |
|
1016 | 472 | ) |
|
1017 | 473 | |
|
1018 | self.saveTime = self.min_time | |
|
1019 | ||
|
1020 | 474 | |
|
1021 |
class |
|
|
475 | class OutputPlot(ParametersPlot): | |
|
1022 | 476 | ''' |
|
1023 | 477 | Plot data_output object |
|
1024 | 478 | ''' |
|
1025 | 479 | |
|
1026 | 480 | CODE = 'output' |
|
1027 | 481 | colormap = 'seismic' |
|
1028 | 482 | |
|
1029 | 483 | |
|
1030 |
class |
|
|
484 | class PolarMapPlot(Plot): | |
|
1031 | 485 | ''' |
|
1032 |
Plot for |
|
|
486 | Plot for weather radar | |
|
1033 | 487 | ''' |
|
1034 | 488 | |
|
1035 | 489 | CODE = 'param' |
|
1036 | 490 | colormap = 'seismic' |
|
1037 | 491 | |
|
1038 | 492 | def setup(self): |
|
1039 | 493 | self.ncols = 1 |
|
1040 | 494 | self.nrows = 1 |
|
1041 | 495 | self.width = 9 |
|
1042 | 496 | self.height = 8 |
|
1043 | 497 | self.mode = self.data.meta['mode'] |
|
1044 | 498 | if self.channels is not None: |
|
1045 | 499 | self.nplots = len(self.channels) |
|
1046 | 500 | self.nrows = len(self.channels) |
|
1047 | 501 | else: |
|
1048 | 502 | self.nplots = self.data.shape(self.CODE)[0] |
|
1049 | 503 | self.nrows = self.nplots |
|
1050 | 504 | self.channels = list(range(self.nplots)) |
|
1051 | 505 | if self.mode == 'E': |
|
1052 | 506 | self.xlabel = 'Longitude' |
|
1053 | 507 | self.ylabel = 'Latitude' |
|
1054 | 508 | else: |
|
1055 | 509 | self.xlabel = 'Range (km)' |
|
1056 | 510 | self.ylabel = 'Height (km)' |
|
1057 | 511 | self.bgcolor = 'white' |
|
1058 | 512 | self.cb_labels = self.data.meta['units'] |
|
1059 | 513 | self.lat = self.data.meta['latitude'] |
|
1060 | 514 | self.lon = self.data.meta['longitude'] |
|
1061 | self.xmin, self.xmax = float(km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) | |
|
1062 |
|
|
|
515 | self.xmin, self.xmax = float( | |
|
516 | km2deg(self.xmin) + self.lon), float(km2deg(self.xmax) + self.lon) | |
|
517 | self.ymin, self.ymax = float( | |
|
518 | km2deg(self.ymin) + self.lat), float(km2deg(self.ymax) + self.lat) | |
|
1063 | 519 | # self.polar = True |
|
1064 | 520 | |
|
1065 |
def plot(self): |
|
|
1066 | ||
|
521 | def plot(self): | |
|
522 | ||
|
1067 | 523 | for n, ax in enumerate(self.axes): |
|
1068 | 524 | data = self.data['param'][self.channels[n]] |
|
1069 | ||
|
1070 |
zeniths = numpy.linspace( |
|
|
1071 | if self.mode == 'E': | |
|
525 | ||
|
526 | zeniths = numpy.linspace( | |
|
527 | 0, self.data.meta['max_range'], data.shape[1]) | |
|
528 | if self.mode == 'E': | |
|
1072 | 529 | azimuths = -numpy.radians(self.data.heights)+numpy.pi/2 |
|
1073 | 530 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
1074 |
x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( |
|
|
531 | x, y = r*numpy.cos(theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])), r*numpy.sin( | |
|
532 | theta)*numpy.cos(numpy.radians(self.data.meta['elevation'])) | |
|
1075 | 533 | x = km2deg(x) + self.lon |
|
1076 | 534 | y = km2deg(y) + self.lat |
|
1077 | 535 | else: |
|
1078 | 536 | azimuths = numpy.radians(self.data.heights) |
|
1079 | 537 | r, theta = numpy.meshgrid(zeniths, azimuths) |
|
1080 | 538 | x, y = r*numpy.cos(theta), r*numpy.sin(theta) |
|
1081 | 539 | self.y = zeniths |
|
1082 | 540 | |
|
1083 | 541 | if ax.firsttime: |
|
1084 | 542 | if self.zlimits is not None: |
|
1085 | 543 | self.zmin, self.zmax = self.zlimits[n] |
|
1086 | ax.plt = ax.pcolormesh(#r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
|
1087 |
|
|
|
1088 |
|
|
|
1089 |
|
|
|
1090 |
|
|
|
544 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
|
545 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
|
546 | vmin=self.zmin, | |
|
547 | vmax=self.zmax, | |
|
548 | cmap=self.cmaps[n]) | |
|
1091 | 549 | else: |
|
1092 | 550 | if self.zlimits is not None: |
|
1093 | 551 | self.zmin, self.zmax = self.zlimits[n] |
|
1094 | 552 | ax.collections.remove(ax.collections[0]) |
|
1095 | ax.plt = ax.pcolormesh(# r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
|
1096 |
|
|
|
1097 |
|
|
|
1098 |
|
|
|
1099 |
|
|
|
553 | ax.plt = ax.pcolormesh( # r, theta, numpy.ma.array(data, mask=numpy.isnan(data)), | |
|
554 | x, y, numpy.ma.array(data, mask=numpy.isnan(data)), | |
|
555 | vmin=self.zmin, | |
|
556 | vmax=self.zmax, | |
|
557 | cmap=self.cmaps[n]) | |
|
1100 | 558 | |
|
1101 | 559 | if self.mode == 'A': |
|
1102 | 560 | continue |
|
1103 | ||
|
561 | ||
|
1104 | 562 | # plot district names |
|
1105 | 563 | f = open('/data/workspace/schain_scripts/distrito.csv') |
|
1106 | 564 | for line in f: |
|
1107 | 565 | label, lon, lat = [s.strip() for s in line.split(',') if s] |
|
1108 | 566 | lat = float(lat) |
|
1109 |
lon = float(lon) |
|
|
567 | lon = float(lon) | |
|
1110 | 568 | # ax.plot(lon, lat, '.b', ms=2) |
|
1111 |
ax.text(lon, lat, label.decode('utf8'), ha='center', |
|
|
1112 | ||
|
569 | ax.text(lon, lat, label.decode('utf8'), ha='center', | |
|
570 | va='bottom', size='8', color='black') | |
|
571 | ||
|
1113 | 572 | # plot limites |
|
1114 | limites =[] | |
|
573 | limites = [] | |
|
1115 | 574 | tmp = [] |
|
1116 | 575 | for line in open('/data/workspace/schain_scripts/lima.csv'): |
|
1117 | 576 | if '#' in line: |
|
1118 | 577 | if tmp: |
|
1119 | 578 | limites.append(tmp) |
|
1120 | 579 | tmp = [] |
|
1121 | 580 | continue |
|
1122 | 581 | values = line.strip().split(',') |
|
1123 | 582 | tmp.append((float(values[0]), float(values[1]))) |
|
1124 | 583 | for points in limites: |
|
1125 | ax.add_patch(Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) | |
|
584 | ax.add_patch( | |
|
585 | Polygon(points, ec='k', fc='none', ls='--', lw=0.5)) | |
|
1126 | 586 | |
|
1127 | 587 | # plot Cuencas |
|
1128 | 588 | for cuenca in ('rimac', 'lurin', 'mala', 'chillon', 'chilca', 'chancay-huaral'): |
|
1129 | 589 | f = open('/data/workspace/schain_scripts/{}.csv'.format(cuenca)) |
|
1130 | 590 | values = [line.strip().split(',') for line in f] |
|
1131 | 591 | points = [(float(s[0]), float(s[1])) for s in values] |
|
1132 | 592 | ax.add_patch(Polygon(points, ec='b', fc='none')) |
|
1133 | 593 | |
|
1134 | 594 | # plot grid |
|
1135 | 595 | for r in (15, 30, 45, 60): |
|
1136 |
ax.add_artist(plt.Circle((self.lon, self.lat), |
|
|
596 | ax.add_artist(plt.Circle((self.lon, self.lat), | |
|
597 | km2deg(r), color='0.6', fill=False, lw=0.2)) | |
|
1137 | 598 | ax.text( |
|
1138 | 599 | self.lon + (km2deg(r))*numpy.cos(60*numpy.pi/180), |
|
1139 | 600 | self.lat + (km2deg(r))*numpy.sin(60*numpy.pi/180), |
|
1140 |
'{}km'.format(r), |
|
|
601 | '{}km'.format(r), | |
|
1141 | 602 | ha='center', va='bottom', size='8', color='0.6', weight='heavy') |
|
1142 | ||
|
603 | ||
|
1143 | 604 | if self.mode == 'E': |
|
1144 | 605 | title = 'El={}$^\circ$'.format(self.data.meta['elevation']) |
|
1145 | 606 | label = 'E{:02d}'.format(int(self.data.meta['elevation'])) |
|
1146 | 607 | else: |
|
1147 | 608 | title = 'Az={}$^\circ$'.format(self.data.meta['azimuth']) |
|
1148 | 609 | label = 'A{:02d}'.format(int(self.data.meta['azimuth'])) |
|
1149 | ||
|
1150 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] | |
|
1151 | self.titles = ['{} {}'.format(self.data.parameters[x], title) for x in self.channels] | |
|
1152 | self.saveTime = self.max_time | |
|
1153 | 610 | |
|
1154 | No newline at end of file | |
|
611 | self.save_labels = ['{}-{}'.format(lbl, label) for lbl in self.labels] | |
|
612 | self.titles = ['{} {}'.format( | |
|
613 | self.data.parameters[x], title) for x in self.channels] |
@@ -1,329 +1,329 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 9, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | |
|
10 | 10 | from .figure import Figure, isRealtime |
|
11 | 11 | from .plotting_codes import * |
|
12 | 12 | |
|
13 | class SpectraHeisScope(Figure): | |
|
13 | class SpectraHeisScope_(Figure): | |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | isConfig = None |
|
17 | 17 | __nsubplots = None |
|
18 | 18 | |
|
19 | 19 | WIDTHPROF = None |
|
20 | 20 | HEIGHTPROF = None |
|
21 | 21 | PREFIX = 'spc' |
|
22 | 22 | |
|
23 | 23 | def __init__(self, **kwargs): |
|
24 | 24 | |
|
25 | 25 | Figure.__init__(self, **kwargs) |
|
26 | 26 | self.isConfig = False |
|
27 | 27 | self.__nsubplots = 1 |
|
28 | 28 | |
|
29 | 29 | self.WIDTH = 230 |
|
30 | 30 | self.HEIGHT = 250 |
|
31 | 31 | self.WIDTHPROF = 120 |
|
32 | 32 | self.HEIGHTPROF = 0 |
|
33 | 33 | self.counter_imagwr = 0 |
|
34 | 34 | |
|
35 | 35 | self.PLOT_CODE = SPEC_CODE |
|
36 | 36 | |
|
37 | 37 | def getSubplots(self): |
|
38 | 38 | |
|
39 | 39 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
40 | 40 | nrow = int(self.nplots*1./ncol + 0.9) |
|
41 | 41 | |
|
42 | 42 | return nrow, ncol |
|
43 | 43 | |
|
44 | 44 | def setup(self, id, nplots, wintitle, show): |
|
45 | 45 | |
|
46 | 46 | showprofile = False |
|
47 | 47 | self.__showprofile = showprofile |
|
48 | 48 | self.nplots = nplots |
|
49 | 49 | |
|
50 | 50 | ncolspan = 1 |
|
51 | 51 | colspan = 1 |
|
52 | 52 | if showprofile: |
|
53 | 53 | ncolspan = 3 |
|
54 | 54 | colspan = 2 |
|
55 | 55 | self.__nsubplots = 2 |
|
56 | 56 | |
|
57 | 57 | self.createFigure(id = id, |
|
58 | 58 | wintitle = wintitle, |
|
59 | 59 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
60 | 60 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
61 | 61 | show = show) |
|
62 | 62 | |
|
63 | 63 | nrow, ncol = self.getSubplots() |
|
64 | 64 | |
|
65 | 65 | counter = 0 |
|
66 | 66 | for y in range(nrow): |
|
67 | 67 | for x in range(ncol): |
|
68 | 68 | |
|
69 | 69 | if counter >= self.nplots: |
|
70 | 70 | break |
|
71 | 71 | |
|
72 | 72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
73 | 73 | |
|
74 | 74 | if showprofile: |
|
75 | 75 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
76 | 76 | |
|
77 | 77 | counter += 1 |
|
78 | 78 | |
|
79 | 79 | |
|
80 | 80 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
81 | 81 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
82 | 82 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
83 | 83 | server=None, folder=None, username=None, password=None, |
|
84 | 84 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
85 | 85 | |
|
86 | 86 | """ |
|
87 | 87 | |
|
88 | 88 | Input: |
|
89 | 89 | dataOut : |
|
90 | 90 | id : |
|
91 | 91 | wintitle : |
|
92 | 92 | channelList : |
|
93 | 93 | xmin : None, |
|
94 | 94 | xmax : None, |
|
95 | 95 | ymin : None, |
|
96 | 96 | ymax : None, |
|
97 | 97 | """ |
|
98 | 98 | |
|
99 | 99 | if dataOut.realtime: |
|
100 | 100 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
101 | 101 | print('Skipping this plot function') |
|
102 | 102 | return |
|
103 | 103 | |
|
104 | 104 | if channelList == None: |
|
105 | 105 | channelIndexList = dataOut.channelIndexList |
|
106 | 106 | else: |
|
107 | 107 | channelIndexList = [] |
|
108 | 108 | for channel in channelList: |
|
109 | 109 | if channel not in dataOut.channelList: |
|
110 | 110 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
111 | 111 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
112 | 112 | |
|
113 | 113 | # x = dataOut.heightList |
|
114 | 114 | c = 3E8 |
|
115 | 115 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
116 | 116 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
117 | 117 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
118 | 118 | #para 1Mhz descomentar la siguiente linea |
|
119 | 119 | #x= x/(10000.0) |
|
120 | 120 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
121 | 121 | # y = y.real |
|
122 | 122 | factor = dataOut.normFactor |
|
123 | 123 | data = dataOut.data_spc / factor |
|
124 | 124 | datadB = 10.*numpy.log10(data) |
|
125 | 125 | y = datadB |
|
126 | 126 | |
|
127 | 127 | #thisDatetime = dataOut.datatime |
|
128 | 128 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
129 | 129 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
130 | 130 | xlabel = "" |
|
131 | 131 | #para 1Mhz descomentar la siguiente linea |
|
132 | 132 | #xlabel = "Frequency x 10000" |
|
133 | 133 | ylabel = "Intensity (dB)" |
|
134 | 134 | |
|
135 | 135 | if not self.isConfig: |
|
136 | 136 | nplots = len(channelIndexList) |
|
137 | 137 | |
|
138 | 138 | self.setup(id=id, |
|
139 | 139 | nplots=nplots, |
|
140 | 140 | wintitle=wintitle, |
|
141 | 141 | show=show) |
|
142 | 142 | |
|
143 | 143 | if xmin == None: xmin = numpy.nanmin(x) |
|
144 | 144 | if xmax == None: xmax = numpy.nanmax(x) |
|
145 | 145 | if ymin == None: ymin = numpy.nanmin(y) |
|
146 | 146 | if ymax == None: ymax = numpy.nanmax(y) |
|
147 | 147 | |
|
148 | 148 | self.FTP_WEI = ftp_wei |
|
149 | 149 | self.EXP_CODE = exp_code |
|
150 | 150 | self.SUB_EXP_CODE = sub_exp_code |
|
151 | 151 | self.PLOT_POS = plot_pos |
|
152 | 152 | |
|
153 | 153 | self.isConfig = True |
|
154 | 154 | |
|
155 | 155 | self.setWinTitle(title) |
|
156 | 156 | |
|
157 | 157 | for i in range(len(self.axesList)): |
|
158 | 158 | ychannel = y[i,:] |
|
159 | 159 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
160 | 160 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[channelIndexList[i]], numpy.max(ychannel), str_datetime) |
|
161 | 161 | axes = self.axesList[i] |
|
162 | 162 | axes.pline(x, ychannel, |
|
163 | 163 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
164 | 164 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
165 | 165 | |
|
166 | 166 | |
|
167 | 167 | self.draw() |
|
168 | 168 | |
|
169 | 169 | self.save(figpath=figpath, |
|
170 | 170 | figfile=figfile, |
|
171 | 171 | save=save, |
|
172 | 172 | ftp=ftp, |
|
173 | 173 | wr_period=wr_period, |
|
174 | 174 | thisDatetime=thisDatetime) |
|
175 | 175 | |
|
176 | class RTIfromSpectraHeis(Figure): | |
|
176 | class RTIfromSpectraHeis_(Figure): | |
|
177 | 177 | |
|
178 | 178 | isConfig = None |
|
179 | 179 | __nsubplots = None |
|
180 | 180 | |
|
181 | 181 | PREFIX = 'rtinoise' |
|
182 | 182 | |
|
183 | 183 | def __init__(self, **kwargs): |
|
184 | 184 | Figure.__init__(self, **kwargs) |
|
185 | 185 | self.timerange = 24*60*60 |
|
186 | 186 | self.isConfig = False |
|
187 | 187 | self.__nsubplots = 1 |
|
188 | 188 | |
|
189 | 189 | self.WIDTH = 820 |
|
190 | 190 | self.HEIGHT = 200 |
|
191 | 191 | self.WIDTHPROF = 120 |
|
192 | 192 | self.HEIGHTPROF = 0 |
|
193 | 193 | self.counter_imagwr = 0 |
|
194 | 194 | self.xdata = None |
|
195 | 195 | self.ydata = None |
|
196 | 196 | self.figfile = None |
|
197 | 197 | |
|
198 | 198 | self.PLOT_CODE = RTI_CODE |
|
199 | 199 | |
|
200 | 200 | def getSubplots(self): |
|
201 | 201 | |
|
202 | 202 | ncol = 1 |
|
203 | 203 | nrow = 1 |
|
204 | 204 | |
|
205 | 205 | return nrow, ncol |
|
206 | 206 | |
|
207 | 207 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
208 | 208 | |
|
209 | 209 | self.__showprofile = showprofile |
|
210 | 210 | self.nplots = nplots |
|
211 | 211 | |
|
212 | 212 | ncolspan = 7 |
|
213 | 213 | colspan = 6 |
|
214 | 214 | self.__nsubplots = 2 |
|
215 | 215 | |
|
216 | 216 | self.createFigure(id = id, |
|
217 | 217 | wintitle = wintitle, |
|
218 | 218 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
219 | 219 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
220 | 220 | show = show) |
|
221 | 221 | |
|
222 | 222 | nrow, ncol = self.getSubplots() |
|
223 | 223 | |
|
224 | 224 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
225 | 225 | |
|
226 | 226 | |
|
227 | 227 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
228 | 228 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
229 | 229 | timerange=None, |
|
230 | 230 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
231 | 231 | server=None, folder=None, username=None, password=None, |
|
232 | 232 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
233 | 233 | |
|
234 | 234 | if channelList == None: |
|
235 | 235 | channelIndexList = dataOut.channelIndexList |
|
236 | 236 | channelList = dataOut.channelList |
|
237 | 237 | else: |
|
238 | 238 | channelIndexList = [] |
|
239 | 239 | for channel in channelList: |
|
240 | 240 | if channel not in dataOut.channelList: |
|
241 | 241 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
242 | 242 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
243 | 243 | |
|
244 | 244 | if timerange != None: |
|
245 | 245 | self.timerange = timerange |
|
246 | 246 | |
|
247 | 247 | x = dataOut.getTimeRange() |
|
248 | 248 | y = dataOut.getHeiRange() |
|
249 | 249 | |
|
250 | 250 | factor = dataOut.normFactor |
|
251 | 251 | data = dataOut.data_spc / factor |
|
252 | 252 | data = numpy.average(data,axis=1) |
|
253 | 253 | datadB = 10*numpy.log10(data) |
|
254 | 254 | |
|
255 | 255 | # factor = dataOut.normFactor |
|
256 | 256 | # noise = dataOut.getNoise()/factor |
|
257 | 257 | # noisedB = 10*numpy.log10(noise) |
|
258 | 258 | |
|
259 | 259 | #thisDatetime = dataOut.datatime |
|
260 | 260 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
261 | 261 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
262 | 262 | xlabel = "Local Time" |
|
263 | 263 | ylabel = "Intensity (dB)" |
|
264 | 264 | |
|
265 | 265 | if not self.isConfig: |
|
266 | 266 | |
|
267 | 267 | nplots = 1 |
|
268 | 268 | |
|
269 | 269 | self.setup(id=id, |
|
270 | 270 | nplots=nplots, |
|
271 | 271 | wintitle=wintitle, |
|
272 | 272 | showprofile=showprofile, |
|
273 | 273 | show=show) |
|
274 | 274 | |
|
275 | 275 | self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax) |
|
276 | 276 | |
|
277 | 277 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
278 | 278 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
279 | 279 | |
|
280 | 280 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
281 | 281 | self.isConfig = True |
|
282 | 282 | self.figfile = figfile |
|
283 | 283 | self.xdata = numpy.array([]) |
|
284 | 284 | self.ydata = numpy.array([]) |
|
285 | 285 | |
|
286 | 286 | self.FTP_WEI = ftp_wei |
|
287 | 287 | self.EXP_CODE = exp_code |
|
288 | 288 | self.SUB_EXP_CODE = sub_exp_code |
|
289 | 289 | self.PLOT_POS = plot_pos |
|
290 | 290 | |
|
291 | 291 | self.setWinTitle(title) |
|
292 | 292 | |
|
293 | 293 | |
|
294 | 294 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
295 | 295 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
296 | 296 | |
|
297 | 297 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
298 | 298 | axes = self.axesList[0] |
|
299 | 299 | |
|
300 | 300 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
301 | 301 | |
|
302 | 302 | if len(self.ydata)==0: |
|
303 | 303 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
304 | 304 | else: |
|
305 | 305 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
306 | 306 | |
|
307 | 307 | |
|
308 | 308 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
309 | 309 | xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax, |
|
310 | 310 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
311 | 311 | XAxisAsTime=True |
|
312 | 312 | ) |
|
313 | 313 | |
|
314 | 314 | self.draw() |
|
315 | 315 | |
|
316 | 316 | update_figfile = False |
|
317 | 317 | |
|
318 | 318 | if dataOut.ltctime >= self.tmax: |
|
319 | 319 | self.counter_imagwr = wr_period |
|
320 | 320 | self.isConfig = False |
|
321 | 321 | update_figfile = True |
|
322 | 322 | |
|
323 | 323 | self.save(figpath=figpath, |
|
324 | 324 | figfile=figfile, |
|
325 | 325 | save=save, |
|
326 | 326 | ftp=ftp, |
|
327 | 327 | wr_period=wr_period, |
|
328 | 328 | thisDatetime=thisDatetime, |
|
329 | 329 | update_figfile=update_figfile) No newline at end of file |
@@ -1,2158 +1,2389 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | import inspect |
|
5 | 5 | from .figure import Figure, isRealtime, isTimeInHourRange |
|
6 | 6 | from .plotting_codes import * |
|
7 | 7 | from schainpy.model.proc.jroproc_base import MPDecorator |
|
8 | 8 | from schainpy.utils import log |
|
9 | 9 | |
|
10 |
class |
|
|
10 | class ParamLine_(Figure): | |
|
11 | ||
|
12 | isConfig = None | |
|
13 | ||
|
14 | def __init__(self): | |
|
15 | ||
|
16 | self.isConfig = False | |
|
17 | self.WIDTH = 300 | |
|
18 | self.HEIGHT = 200 | |
|
19 | self.counter_imagwr = 0 | |
|
20 | ||
|
21 | def getSubplots(self): | |
|
22 | ||
|
23 | nrow = self.nplots | |
|
24 | ncol = 3 | |
|
25 | return nrow, ncol | |
|
26 | ||
|
27 | def setup(self, id, nplots, wintitle, show): | |
|
28 | ||
|
29 | self.nplots = nplots | |
|
30 | ||
|
31 | self.createFigure(id=id, | |
|
32 | wintitle=wintitle, | |
|
33 | show=show) | |
|
34 | ||
|
35 | nrow,ncol = self.getSubplots() | |
|
36 | colspan = 3 | |
|
37 | rowspan = 1 | |
|
38 | ||
|
39 | for i in range(nplots): | |
|
40 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
|
41 | ||
|
42 | def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): | |
|
43 | yreal = y[channelIndexList,:].real | |
|
44 | yimag = y[channelIndexList,:].imag | |
|
45 | ||
|
46 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
47 | xlabel = "Range (Km)" | |
|
48 | ylabel = "Intensity - IQ" | |
|
49 | ||
|
50 | if not self.isConfig: | |
|
51 | nplots = len(channelIndexList) | |
|
52 | ||
|
53 | self.setup(id=id, | |
|
54 | nplots=nplots, | |
|
55 | wintitle='', | |
|
56 | show=show) | |
|
57 | ||
|
58 | if xmin == None: xmin = numpy.nanmin(x) | |
|
59 | if xmax == None: xmax = numpy.nanmax(x) | |
|
60 | if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag)) | |
|
61 | if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag)) | |
|
62 | ||
|
63 | self.isConfig = True | |
|
64 | ||
|
65 | self.setWinTitle(title) | |
|
66 | ||
|
67 | for i in range(len(self.axesList)): | |
|
68 | title = "Channel %d" %(i) | |
|
69 | axes = self.axesList[i] | |
|
70 | ||
|
71 | axes.pline(x, yreal[i,:], | |
|
72 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
|
73 | xlabel=xlabel, ylabel=ylabel, title=title) | |
|
74 | ||
|
75 | axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2) | |
|
76 | ||
|
77 | def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): | |
|
78 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) | |
|
79 | yreal = y.real | |
|
80 | ||
|
81 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
82 | xlabel = "Range (Km)" | |
|
83 | ylabel = "Intensity" | |
|
84 | ||
|
85 | if not self.isConfig: | |
|
86 | nplots = len(channelIndexList) | |
|
87 | ||
|
88 | self.setup(id=id, | |
|
89 | nplots=nplots, | |
|
90 | wintitle='', | |
|
91 | show=show) | |
|
92 | ||
|
93 | if xmin == None: xmin = numpy.nanmin(x) | |
|
94 | if xmax == None: xmax = numpy.nanmax(x) | |
|
95 | if ymin == None: ymin = numpy.nanmin(yreal) | |
|
96 | if ymax == None: ymax = numpy.nanmax(yreal) | |
|
97 | ||
|
98 | self.isConfig = True | |
|
99 | ||
|
100 | self.setWinTitle(title) | |
|
101 | ||
|
102 | for i in range(len(self.axesList)): | |
|
103 | title = "Channel %d" %(i) | |
|
104 | axes = self.axesList[i] | |
|
105 | ychannel = yreal[i,:] | |
|
106 | axes.pline(x, ychannel, | |
|
107 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
|
108 | xlabel=xlabel, ylabel=ylabel, title=title) | |
|
109 | ||
|
110 | ||
|
111 | def run(self, dataOut, id, wintitle="", channelList=None, | |
|
112 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
|
113 | figpath='./', figfile=None, show=True, wr_period=1, | |
|
114 | ftp=False, server=None, folder=None, username=None, password=None): | |
|
115 | ||
|
116 | """ | |
|
117 | ||
|
118 | Input: | |
|
119 | dataOut : | |
|
120 | id : | |
|
121 | wintitle : | |
|
122 | channelList : | |
|
123 | xmin : None, | |
|
124 | xmax : None, | |
|
125 | ymin : None, | |
|
126 | ymax : None, | |
|
127 | """ | |
|
128 | ||
|
129 | if channelList == None: | |
|
130 | channelIndexList = dataOut.channelIndexList | |
|
131 | else: | |
|
132 | channelIndexList = [] | |
|
133 | for channel in channelList: | |
|
134 | if channel not in dataOut.channelList: | |
|
135 | raise ValueError("Channel %d is not in dataOut.channelList" % channel) | |
|
136 | channelIndexList.append(dataOut.channelList.index(channel)) | |
|
137 | ||
|
138 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
139 | ||
|
140 | y = dataOut.RR | |
|
141 | ||
|
142 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
143 | xlabel = "Range (Km)" | |
|
144 | ylabel = "Intensity" | |
|
145 | ||
|
146 | if not self.isConfig: | |
|
147 | nplots = len(channelIndexList) | |
|
148 | ||
|
149 | self.setup(id=id, | |
|
150 | nplots=nplots, | |
|
151 | wintitle='', | |
|
152 | show=show) | |
|
153 | ||
|
154 | if xmin == None: xmin = numpy.nanmin(x) | |
|
155 | if xmax == None: xmax = numpy.nanmax(x) | |
|
156 | if ymin == None: ymin = numpy.nanmin(y) | |
|
157 | if ymax == None: ymax = numpy.nanmax(y) | |
|
158 | ||
|
159 | self.isConfig = True | |
|
160 | ||
|
161 | self.setWinTitle(title) | |
|
162 | ||
|
163 | for i in range(len(self.axesList)): | |
|
164 | title = "Channel %d" %(i) | |
|
165 | axes = self.axesList[i] | |
|
166 | ychannel = y[i,:] | |
|
167 | axes.pline(x, ychannel, | |
|
168 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
|
169 | xlabel=xlabel, ylabel=ylabel, title=title) | |
|
170 | ||
|
171 | ||
|
172 | self.draw() | |
|
173 | ||
|
174 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex) | |
|
175 | figfile = self.getFilename(name = str_datetime) | |
|
176 | ||
|
177 | self.save(figpath=figpath, | |
|
178 | figfile=figfile, | |
|
179 | save=save, | |
|
180 | ftp=ftp, | |
|
181 | wr_period=wr_period, | |
|
182 | thisDatetime=thisDatetime) | |
|
183 | ||
|
184 | ||
|
185 | ||
|
186 | class SpcParamPlot_(Figure): | |
|
11 | 187 | |
|
12 | 188 | isConfig = None |
|
13 | 189 | __nsubplots = None |
|
14 | 190 | |
|
15 | 191 | WIDTHPROF = None |
|
16 | 192 | HEIGHTPROF = None |
|
17 |
PREFIX = ' |
|
|
193 | PREFIX = 'SpcParam' | |
|
18 | 194 | |
|
19 | 195 | def __init__(self, **kwargs): |
|
20 | 196 | Figure.__init__(self, **kwargs) |
|
21 | 197 | self.isConfig = False |
|
22 | 198 | self.__nsubplots = 1 |
|
23 | 199 | |
|
24 | 200 | self.WIDTH = 250 |
|
25 | 201 | self.HEIGHT = 250 |
|
26 | 202 | self.WIDTHPROF = 120 |
|
27 | 203 | self.HEIGHTPROF = 0 |
|
28 | 204 | self.counter_imagwr = 0 |
|
29 | 205 | |
|
30 | 206 | self.PLOT_CODE = SPEC_CODE |
|
31 | 207 | |
|
32 | 208 | self.FTP_WEI = None |
|
33 | 209 | self.EXP_CODE = None |
|
34 | 210 | self.SUB_EXP_CODE = None |
|
35 | 211 | self.PLOT_POS = None |
|
36 | 212 | |
|
37 | 213 | self.__xfilter_ena = False |
|
38 | 214 | self.__yfilter_ena = False |
|
39 | 215 | |
|
40 | 216 | def getSubplots(self): |
|
41 | 217 | |
|
42 | 218 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
43 | 219 | nrow = int(self.nplots*1./ncol + 0.9) |
|
44 | 220 | |
|
45 | 221 | return nrow, ncol |
|
46 | 222 | |
|
47 | 223 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
48 | 224 | |
|
49 | 225 | self.__showprofile = showprofile |
|
50 | 226 | self.nplots = nplots |
|
51 | 227 | |
|
52 | 228 | ncolspan = 1 |
|
53 | 229 | colspan = 1 |
|
54 | 230 | if showprofile: |
|
55 | 231 | ncolspan = 3 |
|
56 | 232 | colspan = 2 |
|
57 | 233 | self.__nsubplots = 2 |
|
58 | 234 | |
|
59 | 235 | self.createFigure(id = id, |
|
60 | 236 | wintitle = wintitle, |
|
61 | 237 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
62 | 238 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
63 | 239 | show=show) |
|
64 | 240 | |
|
65 | 241 | nrow, ncol = self.getSubplots() |
|
66 | 242 | |
|
67 | 243 | counter = 0 |
|
68 | 244 | for y in range(nrow): |
|
69 | 245 | for x in range(ncol): |
|
70 | 246 | |
|
71 | 247 | if counter >= self.nplots: |
|
72 | 248 | break |
|
73 | 249 | |
|
74 | 250 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
75 | 251 | |
|
76 | 252 | if showprofile: |
|
77 | 253 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
78 | 254 | |
|
79 | 255 | counter += 1 |
|
80 | 256 | |
|
81 | 257 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
82 | 258 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
83 | 259 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
84 | 260 | server=None, folder=None, username=None, password=None, |
|
85 | 261 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
86 |
xaxis="frequency", colormap='jet', normFactor=None , |
|
|
262 | xaxis="frequency", colormap='jet', normFactor=None , Selector = 0): | |
|
87 | 263 | |
|
88 | 264 | """ |
|
89 | 265 | |
|
90 | 266 | Input: |
|
91 | 267 | dataOut : |
|
92 | 268 | id : |
|
93 | 269 | wintitle : |
|
94 | 270 | channelList : |
|
95 | 271 | showProfile : |
|
96 | 272 | xmin : None, |
|
97 | 273 | xmax : None, |
|
98 | 274 | ymin : None, |
|
99 | 275 | ymax : None, |
|
100 | 276 | zmin : None, |
|
101 | 277 | zmax : None |
|
102 | 278 | """ |
|
103 | 279 | if realtime: |
|
104 | 280 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
105 | 281 | print('Skipping this plot function') |
|
106 | 282 | return |
|
107 | 283 | |
|
108 | 284 | if channelList == None: |
|
109 | 285 | channelIndexList = dataOut.channelIndexList |
|
110 | 286 | else: |
|
111 | 287 | channelIndexList = [] |
|
112 | 288 | for channel in channelList: |
|
113 | 289 | if channel not in dataOut.channelList: |
|
114 | 290 | raise ValueError("Channel %d is not in dataOut.channelList" %channel) |
|
115 | 291 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
116 | 292 | |
|
117 | 293 | # if normFactor is None: |
|
118 | 294 | # factor = dataOut.normFactor |
|
119 | 295 | # else: |
|
120 | 296 | # factor = normFactor |
|
121 | 297 | if xaxis == "frequency": |
|
122 | x = dataOut.spc_range[0] | |
|
298 | x = dataOut.spcparam_range[0] | |
|
123 | 299 | xlabel = "Frequency (kHz)" |
|
124 | 300 | |
|
125 | 301 | elif xaxis == "time": |
|
126 | x = dataOut.spc_range[1] | |
|
302 | x = dataOut.spcparam_range[1] | |
|
127 | 303 | xlabel = "Time (ms)" |
|
128 | 304 | |
|
129 | else: | |
|
130 | x = dataOut.spc_range[2] | |
|
305 | else: | |
|
306 | x = dataOut.spcparam_range[2] | |
|
131 | 307 | xlabel = "Velocity (m/s)" |
|
132 | 308 | |
|
133 |
ylabel = "Range ( |
|
|
309 | ylabel = "Range (km)" | |
|
134 | 310 | |
|
135 | 311 | y = dataOut.getHeiRange() |
|
136 | 312 | |
|
137 |
z = dataOut. |
|
|
138 | print('GausSPC', z[0,32,10:40]) | |
|
313 | z = dataOut.SPCparam[Selector] /1966080.0#/ dataOut.normFactor#GauSelector] #dataOut.data_spc/factor | |
|
139 | 314 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
140 | 315 | zdB = 10*numpy.log10(z) |
|
141 | 316 | |
|
142 | 317 | avg = numpy.average(z, axis=1) |
|
143 | 318 | avgdB = 10*numpy.log10(avg) |
|
144 | 319 | |
|
145 | 320 | noise = dataOut.spc_noise |
|
146 | 321 | noisedB = 10*numpy.log10(noise) |
|
147 | 322 | |
|
148 | 323 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
149 | 324 | title = wintitle + " Spectra" |
|
150 | 325 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
151 | 326 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
152 | 327 | |
|
153 | 328 | if not self.isConfig: |
|
154 | 329 | |
|
155 | 330 | nplots = len(channelIndexList) |
|
156 | 331 | |
|
157 | 332 | self.setup(id=id, |
|
158 | 333 | nplots=nplots, |
|
159 | 334 | wintitle=wintitle, |
|
160 | 335 | showprofile=showprofile, |
|
161 | 336 | show=show) |
|
162 | 337 | |
|
163 | 338 | if xmin == None: xmin = numpy.nanmin(x) |
|
164 | 339 | if xmax == None: xmax = numpy.nanmax(x) |
|
165 | 340 | if ymin == None: ymin = numpy.nanmin(y) |
|
166 | 341 | if ymax == None: ymax = numpy.nanmax(y) |
|
167 | 342 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
168 | 343 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
169 | 344 | |
|
170 | 345 | self.FTP_WEI = ftp_wei |
|
171 | 346 | self.EXP_CODE = exp_code |
|
172 | 347 | self.SUB_EXP_CODE = sub_exp_code |
|
173 | 348 | self.PLOT_POS = plot_pos |
|
174 | 349 | |
|
175 | 350 | self.isConfig = True |
|
176 | 351 | |
|
177 | 352 | self.setWinTitle(title) |
|
178 | 353 | |
|
179 | 354 | for i in range(self.nplots): |
|
180 | 355 | index = channelIndexList[i] |
|
181 | 356 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
182 | 357 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
183 | 358 | if len(dataOut.beam.codeList) != 0: |
|
184 | 359 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) |
|
185 | 360 | |
|
186 | 361 | axes = self.axesList[i*self.__nsubplots] |
|
187 | 362 | axes.pcolor(x, y, zdB[index,:,:], |
|
188 | 363 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
189 | 364 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, |
|
190 | 365 | ticksize=9, cblabel='') |
|
191 | 366 | |
|
192 | 367 | if self.__showprofile: |
|
193 | 368 | axes = self.axesList[i*self.__nsubplots +1] |
|
194 | 369 | axes.pline(avgdB[index,:], y, |
|
195 | 370 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
196 | 371 | xlabel='dB', ylabel='', title='', |
|
197 | 372 | ytick_visible=False, |
|
198 | 373 | grid='x') |
|
199 | 374 | |
|
200 | 375 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
201 | 376 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
202 | 377 | |
|
203 | 378 | self.draw() |
|
204 | 379 | |
|
205 | 380 | if figfile == None: |
|
206 | 381 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
207 | 382 | name = str_datetime |
|
208 | 383 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
209 | 384 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
210 | 385 | figfile = self.getFilename(name) |
|
211 | 386 | |
|
212 | 387 | self.save(figpath=figpath, |
|
213 | 388 | figfile=figfile, |
|
214 | 389 | save=save, |
|
215 | 390 | ftp=ftp, |
|
216 | 391 | wr_period=wr_period, |
|
217 | 392 | thisDatetime=thisDatetime) |
|
218 | 393 | |
|
219 | 394 | |
|
220 | 395 | |
|
221 | class MomentsPlot(Figure): | |
|
396 | class MomentsPlot_(Figure): | |
|
222 | 397 | |
|
223 | 398 | isConfig = None |
|
224 | 399 | __nsubplots = None |
|
225 | 400 | |
|
226 | 401 | WIDTHPROF = None |
|
227 | 402 | HEIGHTPROF = None |
|
228 | 403 | PREFIX = 'prm' |
|
229 | 404 | def __init__(self): |
|
230 | 405 | Figure.__init__(self) |
|
231 | 406 | self.isConfig = False |
|
232 | 407 | self.__nsubplots = 1 |
|
233 | 408 | |
|
234 | 409 | self.WIDTH = 280 |
|
235 | 410 | self.HEIGHT = 250 |
|
236 | 411 | self.WIDTHPROF = 120 |
|
237 | 412 | self.HEIGHTPROF = 0 |
|
238 | 413 | self.counter_imagwr = 0 |
|
239 | 414 | |
|
240 | 415 | self.PLOT_CODE = MOMENTS_CODE |
|
241 | 416 | |
|
242 | 417 | self.FTP_WEI = None |
|
243 | 418 | self.EXP_CODE = None |
|
244 | 419 | self.SUB_EXP_CODE = None |
|
245 | 420 | self.PLOT_POS = None |
|
246 | 421 | |
|
247 | 422 | def getSubplots(self): |
|
248 | 423 | |
|
249 | 424 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
250 | 425 | nrow = int(self.nplots*1./ncol + 0.9) |
|
251 | 426 | |
|
252 | 427 | return nrow, ncol |
|
253 | 428 | |
|
254 | 429 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
255 | 430 | |
|
256 | 431 | self.__showprofile = showprofile |
|
257 | 432 | self.nplots = nplots |
|
258 | 433 | |
|
259 | 434 | ncolspan = 1 |
|
260 | 435 | colspan = 1 |
|
261 | 436 | if showprofile: |
|
262 | 437 | ncolspan = 3 |
|
263 | 438 | colspan = 2 |
|
264 | 439 | self.__nsubplots = 2 |
|
265 | 440 | |
|
266 | 441 | self.createFigure(id = id, |
|
267 | 442 | wintitle = wintitle, |
|
268 | 443 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
269 | 444 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
270 | 445 | show=show) |
|
271 | 446 | |
|
272 | 447 | nrow, ncol = self.getSubplots() |
|
273 | 448 | |
|
274 | 449 | counter = 0 |
|
275 | 450 | for y in range(nrow): |
|
276 | 451 | for x in range(ncol): |
|
277 | 452 | |
|
278 | 453 | if counter >= self.nplots: |
|
279 | 454 | break |
|
280 | 455 | |
|
281 | 456 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
282 | 457 | |
|
283 | 458 | if showprofile: |
|
284 | 459 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
285 | 460 | |
|
286 | 461 | counter += 1 |
|
287 | 462 | |
|
288 | 463 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
289 | 464 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
290 | 465 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
291 | 466 | server=None, folder=None, username=None, password=None, |
|
292 | 467 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
293 | 468 | |
|
294 | 469 | """ |
|
295 | 470 | |
|
296 | 471 | Input: |
|
297 | 472 | dataOut : |
|
298 | 473 | id : |
|
299 | 474 | wintitle : |
|
300 | 475 | channelList : |
|
301 | 476 | showProfile : |
|
302 | 477 | xmin : None, |
|
303 | 478 | xmax : None, |
|
304 | 479 | ymin : None, |
|
305 | 480 | ymax : None, |
|
306 | 481 | zmin : None, |
|
307 | 482 | zmax : None |
|
308 | 483 | """ |
|
309 | 484 | |
|
310 | 485 | if dataOut.flagNoData: |
|
311 | 486 | return None |
|
312 | 487 | |
|
313 | 488 | if realtime: |
|
314 | 489 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
315 | 490 | print('Skipping this plot function') |
|
316 | 491 | return |
|
317 | 492 | |
|
318 | 493 | if channelList == None: |
|
319 | 494 | channelIndexList = dataOut.channelIndexList |
|
320 | 495 | else: |
|
321 | 496 | channelIndexList = [] |
|
322 | 497 | for channel in channelList: |
|
323 | 498 | if channel not in dataOut.channelList: |
|
324 | 499 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
325 | 500 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
326 | 501 | |
|
327 | 502 | factor = dataOut.normFactor |
|
328 | 503 | x = dataOut.abscissaList |
|
329 | 504 | y = dataOut.heightList |
|
330 | 505 | |
|
331 | 506 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
332 | 507 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
333 | 508 | avg = numpy.average(z, axis=1) |
|
334 | 509 | noise = dataOut.noise/factor |
|
335 | 510 | |
|
336 | 511 | zdB = 10*numpy.log10(z) |
|
337 | 512 | avgdB = 10*numpy.log10(avg) |
|
338 | 513 | noisedB = 10*numpy.log10(noise) |
|
339 | 514 | |
|
340 | 515 | #thisDatetime = dataOut.datatime |
|
341 | 516 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
342 | 517 | title = wintitle + " Parameters" |
|
343 | 518 | xlabel = "Velocity (m/s)" |
|
344 | 519 | ylabel = "Range (Km)" |
|
345 | 520 | |
|
346 | 521 | update_figfile = False |
|
347 | 522 | |
|
348 | 523 | if not self.isConfig: |
|
349 | 524 | |
|
350 | 525 | nplots = len(channelIndexList) |
|
351 | 526 | |
|
352 | 527 | self.setup(id=id, |
|
353 | 528 | nplots=nplots, |
|
354 | 529 | wintitle=wintitle, |
|
355 | 530 | showprofile=showprofile, |
|
356 | 531 | show=show) |
|
357 | 532 | |
|
358 | 533 | if xmin == None: xmin = numpy.nanmin(x) |
|
359 | 534 | if xmax == None: xmax = numpy.nanmax(x) |
|
360 | 535 | if ymin == None: ymin = numpy.nanmin(y) |
|
361 | 536 | if ymax == None: ymax = numpy.nanmax(y) |
|
362 | 537 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
363 | 538 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
364 | 539 | |
|
365 | 540 | self.FTP_WEI = ftp_wei |
|
366 | 541 | self.EXP_CODE = exp_code |
|
367 | 542 | self.SUB_EXP_CODE = sub_exp_code |
|
368 | 543 | self.PLOT_POS = plot_pos |
|
369 | 544 | |
|
370 | 545 | self.isConfig = True |
|
371 | 546 | update_figfile = True |
|
372 | 547 | |
|
373 | 548 | self.setWinTitle(title) |
|
374 | 549 | |
|
375 | 550 | for i in range(self.nplots): |
|
376 | 551 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
377 | 552 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i], noisedB[i], str_datetime) |
|
378 | 553 | axes = self.axesList[i*self.__nsubplots] |
|
379 | 554 | axes.pcolor(x, y, zdB[i,:,:], |
|
380 | 555 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
381 | 556 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
382 | 557 | ticksize=9, cblabel='') |
|
383 | 558 | #Mean Line |
|
384 | 559 | mean = dataOut.data_param[i, 1, :] |
|
385 | 560 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
386 | 561 | |
|
387 | 562 | if self.__showprofile: |
|
388 | 563 | axes = self.axesList[i*self.__nsubplots +1] |
|
389 | 564 | axes.pline(avgdB[i], y, |
|
390 | 565 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
391 | 566 | xlabel='dB', ylabel='', title='', |
|
392 | 567 | ytick_visible=False, |
|
393 | 568 | grid='x') |
|
394 | 569 | |
|
395 | 570 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
396 | 571 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
397 | 572 | |
|
398 | 573 | self.draw() |
|
399 | 574 | |
|
400 | 575 | self.save(figpath=figpath, |
|
401 | 576 | figfile=figfile, |
|
402 | 577 | save=save, |
|
403 | 578 | ftp=ftp, |
|
404 | 579 | wr_period=wr_period, |
|
405 | 580 | thisDatetime=thisDatetime) |
|
406 | 581 | |
|
407 | 582 | |
|
408 | class SkyMapPlot(Figure): | |
|
583 | class SkyMapPlot_(Figure): | |
|
409 | 584 | |
|
410 | 585 | __isConfig = None |
|
411 | 586 | __nsubplots = None |
|
412 | 587 | |
|
413 | 588 | WIDTHPROF = None |
|
414 | 589 | HEIGHTPROF = None |
|
415 | 590 | PREFIX = 'mmap' |
|
416 | 591 | |
|
417 | 592 | def __init__(self, **kwargs): |
|
418 | 593 | Figure.__init__(self, **kwargs) |
|
419 | 594 | self.isConfig = False |
|
420 | 595 | self.__nsubplots = 1 |
|
421 | 596 | |
|
422 | 597 | # self.WIDTH = 280 |
|
423 | 598 | # self.HEIGHT = 250 |
|
424 | 599 | self.WIDTH = 600 |
|
425 | 600 | self.HEIGHT = 600 |
|
426 | 601 | self.WIDTHPROF = 120 |
|
427 | 602 | self.HEIGHTPROF = 0 |
|
428 | 603 | self.counter_imagwr = 0 |
|
429 | 604 | |
|
430 | 605 | self.PLOT_CODE = MSKYMAP_CODE |
|
431 | 606 | |
|
432 | 607 | self.FTP_WEI = None |
|
433 | 608 | self.EXP_CODE = None |
|
434 | 609 | self.SUB_EXP_CODE = None |
|
435 | 610 | self.PLOT_POS = None |
|
436 | 611 | |
|
437 | 612 | def getSubplots(self): |
|
438 | 613 | |
|
439 | 614 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
440 | 615 | nrow = int(self.nplots*1./ncol + 0.9) |
|
441 | 616 | |
|
442 | 617 | return nrow, ncol |
|
443 | 618 | |
|
444 | 619 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
445 | 620 | |
|
446 | 621 | self.__showprofile = showprofile |
|
447 | 622 | self.nplots = nplots |
|
448 | 623 | |
|
449 | 624 | ncolspan = 1 |
|
450 | 625 | colspan = 1 |
|
451 | 626 | |
|
452 | 627 | self.createFigure(id = id, |
|
453 | 628 | wintitle = wintitle, |
|
454 | 629 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
455 | 630 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
456 | 631 | show=show) |
|
457 | 632 | |
|
458 | 633 | nrow, ncol = 1,1 |
|
459 | 634 | counter = 0 |
|
460 | 635 | x = 0 |
|
461 | 636 | y = 0 |
|
462 | 637 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
463 | 638 | |
|
464 | 639 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
465 | 640 | tmin=0, tmax=24, timerange=None, |
|
466 | 641 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
467 | 642 | server=None, folder=None, username=None, password=None, |
|
468 | 643 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
469 | 644 | |
|
470 | 645 | """ |
|
471 | 646 | |
|
472 | 647 | Input: |
|
473 | 648 | dataOut : |
|
474 | 649 | id : |
|
475 | 650 | wintitle : |
|
476 | 651 | channelList : |
|
477 | 652 | showProfile : |
|
478 | 653 | xmin : None, |
|
479 | 654 | xmax : None, |
|
480 | 655 | ymin : None, |
|
481 | 656 | ymax : None, |
|
482 | 657 | zmin : None, |
|
483 | 658 | zmax : None |
|
484 | 659 | """ |
|
485 | 660 | |
|
486 | 661 | arrayParameters = dataOut.data_param |
|
487 | 662 | error = arrayParameters[:,-1] |
|
488 | 663 | indValid = numpy.where(error == 0)[0] |
|
489 | 664 | finalMeteor = arrayParameters[indValid,:] |
|
490 | 665 | finalAzimuth = finalMeteor[:,3] |
|
491 | 666 | finalZenith = finalMeteor[:,4] |
|
492 | 667 | |
|
493 | 668 | x = finalAzimuth*numpy.pi/180 |
|
494 | 669 | y = finalZenith |
|
495 | 670 | x1 = [dataOut.ltctime, dataOut.ltctime] |
|
496 | 671 | |
|
497 | 672 | #thisDatetime = dataOut.datatime |
|
498 | 673 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
499 | 674 | title = wintitle + " Parameters" |
|
500 | 675 | xlabel = "Zonal Zenith Angle (deg) " |
|
501 | 676 | ylabel = "Meridional Zenith Angle (deg)" |
|
502 | 677 | update_figfile = False |
|
503 | 678 | |
|
504 | 679 | if not self.isConfig: |
|
505 | 680 | |
|
506 | 681 | nplots = 1 |
|
507 | 682 | |
|
508 | 683 | self.setup(id=id, |
|
509 | 684 | nplots=nplots, |
|
510 | 685 | wintitle=wintitle, |
|
511 | 686 | showprofile=showprofile, |
|
512 | 687 | show=show) |
|
513 | 688 | |
|
514 | 689 | if self.xmin is None and self.xmax is None: |
|
515 | 690 | self.xmin, self.xmax = self.getTimeLim(x1, tmin, tmax, timerange) |
|
516 | 691 | |
|
517 | 692 | if timerange != None: |
|
518 | 693 | self.timerange = timerange |
|
519 | 694 | else: |
|
520 | 695 | self.timerange = self.xmax - self.xmin |
|
521 | 696 | |
|
522 | 697 | self.FTP_WEI = ftp_wei |
|
523 | 698 | self.EXP_CODE = exp_code |
|
524 | 699 | self.SUB_EXP_CODE = sub_exp_code |
|
525 | 700 | self.PLOT_POS = plot_pos |
|
526 | 701 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
527 | 702 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
528 | 703 | self.isConfig = True |
|
529 | 704 | update_figfile = True |
|
530 | 705 | |
|
531 | 706 | self.setWinTitle(title) |
|
532 | 707 | |
|
533 | 708 | i = 0 |
|
534 | 709 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
535 | 710 | |
|
536 | 711 | axes = self.axesList[i*self.__nsubplots] |
|
537 | 712 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
538 | 713 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
539 | 714 | axes.polar(x, y, |
|
540 | 715 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
541 | 716 | ticksize=9, cblabel='') |
|
542 | 717 | |
|
543 | 718 | self.draw() |
|
544 | 719 | |
|
545 | 720 | self.save(figpath=figpath, |
|
546 | 721 | figfile=figfile, |
|
547 | 722 | save=save, |
|
548 | 723 | ftp=ftp, |
|
549 | 724 | wr_period=wr_period, |
|
550 | 725 | thisDatetime=thisDatetime, |
|
551 | 726 | update_figfile=update_figfile) |
|
552 | 727 | |
|
553 | 728 | if dataOut.ltctime >= self.xmax: |
|
554 | 729 | self.isConfigmagwr = wr_period |
|
555 | 730 | self.isConfig = False |
|
556 | 731 | update_figfile = True |
|
557 | 732 | axes.__firsttime = True |
|
558 | 733 | self.xmin += self.timerange |
|
559 | 734 | self.xmax += self.timerange |
|
560 | 735 | |
|
561 | 736 | |
|
562 | 737 | |
|
563 | 738 | |
|
564 | class WindProfilerPlot(Figure): | |
|
739 | class WindProfilerPlot_(Figure): | |
|
565 | 740 | |
|
566 | 741 | __isConfig = None |
|
567 | 742 | __nsubplots = None |
|
568 | 743 | |
|
569 | 744 | WIDTHPROF = None |
|
570 | 745 | HEIGHTPROF = None |
|
571 | 746 | PREFIX = 'wind' |
|
572 | 747 | |
|
573 | 748 | def __init__(self, **kwargs): |
|
574 | 749 | Figure.__init__(self, **kwargs) |
|
575 | 750 | self.timerange = None |
|
576 | 751 | self.isConfig = False |
|
577 | 752 | self.__nsubplots = 1 |
|
578 | 753 | |
|
579 | 754 | self.WIDTH = 800 |
|
580 | 755 | self.HEIGHT = 300 |
|
581 | 756 | self.WIDTHPROF = 120 |
|
582 | 757 | self.HEIGHTPROF = 0 |
|
583 | 758 | self.counter_imagwr = 0 |
|
584 | 759 | |
|
585 | 760 | self.PLOT_CODE = WIND_CODE |
|
586 | 761 | |
|
587 | 762 | self.FTP_WEI = None |
|
588 | 763 | self.EXP_CODE = None |
|
589 | 764 | self.SUB_EXP_CODE = None |
|
590 | 765 | self.PLOT_POS = None |
|
591 | 766 | self.tmin = None |
|
592 | 767 | self.tmax = None |
|
593 | 768 | |
|
594 | 769 | self.xmin = None |
|
595 | 770 | self.xmax = None |
|
596 | 771 | |
|
597 | 772 | self.figfile = None |
|
598 | 773 | |
|
599 | 774 | def getSubplots(self): |
|
600 | 775 | |
|
601 | 776 | ncol = 1 |
|
602 | 777 | nrow = self.nplots |
|
603 | 778 | |
|
604 | 779 | return nrow, ncol |
|
605 | 780 | |
|
606 | 781 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
607 | 782 | |
|
608 | 783 | self.__showprofile = showprofile |
|
609 | 784 | self.nplots = nplots |
|
610 | 785 | |
|
611 | 786 | ncolspan = 1 |
|
612 | 787 | colspan = 1 |
|
613 | 788 | |
|
614 | 789 | self.createFigure(id = id, |
|
615 | 790 | wintitle = wintitle, |
|
616 | 791 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
617 | 792 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
618 | 793 | show=show) |
|
619 | 794 | |
|
620 | 795 | nrow, ncol = self.getSubplots() |
|
621 | 796 | |
|
622 | 797 | counter = 0 |
|
623 | 798 | for y in range(nrow): |
|
624 | 799 | if counter >= self.nplots: |
|
625 | 800 | break |
|
626 | 801 | |
|
627 | 802 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
628 | 803 | counter += 1 |
|
629 | 804 | |
|
630 | 805 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='False', |
|
631 | 806 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
632 | 807 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
633 | 808 | timerange=None, SNRthresh = None, |
|
634 | 809 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
635 | 810 | server=None, folder=None, username=None, password=None, |
|
636 | 811 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
637 | 812 | """ |
|
638 | 813 | |
|
639 | 814 | Input: |
|
640 | 815 | dataOut : |
|
641 | 816 | id : |
|
642 | 817 | wintitle : |
|
643 | 818 | channelList : |
|
644 | 819 | showProfile : |
|
645 | 820 | xmin : None, |
|
646 | 821 | xmax : None, |
|
647 | 822 | ymin : None, |
|
648 | 823 | ymax : None, |
|
649 | 824 | zmin : None, |
|
650 | 825 | zmax : None |
|
651 | 826 | """ |
|
652 | 827 | |
|
653 | 828 | # if timerange is not None: |
|
654 | 829 | # self.timerange = timerange |
|
655 | 830 | # |
|
656 | 831 | # tmin = None |
|
657 | 832 | # tmax = None |
|
658 | 833 | |
|
659 | 834 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
660 |
y = dataOut.heightList |
|
|
835 | y = dataOut.heightList | |
|
661 | 836 | z = dataOut.data_output.copy() |
|
662 | 837 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
663 | 838 | nplotsw = nplots |
|
664 | 839 | |
|
665 | 840 | |
|
666 | 841 | #If there is a SNR function defined |
|
667 | 842 | if dataOut.data_SNR is not None: |
|
668 | 843 | nplots += 1 |
|
669 | SNR = dataOut.data_SNR | |
|
670 |
SNRavg = |
|
|
844 | SNR = dataOut.data_SNR[0] | |
|
845 | SNRavg = SNR#numpy.average(SNR, axis=0) | |
|
671 | 846 | |
|
672 | 847 | SNRdB = 10*numpy.log10(SNR) |
|
673 | 848 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
674 | 849 | |
|
675 |
if SNRthresh == None: |
|
|
850 | if SNRthresh == None: | |
|
851 | SNRthresh = -5.0 | |
|
676 | 852 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
677 | 853 | |
|
678 | 854 | for i in range(nplotsw): |
|
679 | 855 | z[i,ind] = numpy.nan |
|
680 | 856 | |
|
681 | 857 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
682 | 858 | #thisDatetime = datetime.datetime.now() |
|
683 | 859 | title = wintitle + "Wind" |
|
684 | 860 | xlabel = "" |
|
685 | 861 | ylabel = "Height (km)" |
|
686 | 862 | update_figfile = False |
|
687 | 863 | |
|
688 | 864 | if not self.isConfig: |
|
689 | 865 | |
|
690 | 866 | self.setup(id=id, |
|
691 | 867 | nplots=nplots, |
|
692 | 868 | wintitle=wintitle, |
|
693 | 869 | showprofile=showprofile, |
|
694 | 870 | show=show) |
|
695 | 871 | |
|
696 | 872 | if timerange is not None: |
|
697 | 873 | self.timerange = timerange |
|
698 | 874 | |
|
699 | 875 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
700 | 876 | |
|
701 | 877 | if ymin == None: ymin = numpy.nanmin(y) |
|
702 | 878 | if ymax == None: ymax = numpy.nanmax(y) |
|
703 | 879 | |
|
704 | 880 | if zmax == None: zmax = numpy.nanmax(abs(z[list(range(2)),:])) |
|
705 | 881 | #if numpy.isnan(zmax): zmax = 50 |
|
706 | 882 | if zmin == None: zmin = -zmax |
|
707 | 883 | |
|
708 | 884 | if nplotsw == 3: |
|
709 | 885 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
710 | 886 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
711 | 887 | |
|
712 | 888 | if dataOut.data_SNR is not None: |
|
713 | 889 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
714 | 890 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
715 | 891 | |
|
716 | 892 | |
|
717 | 893 | self.FTP_WEI = ftp_wei |
|
718 | 894 | self.EXP_CODE = exp_code |
|
719 | 895 | self.SUB_EXP_CODE = sub_exp_code |
|
720 | 896 | self.PLOT_POS = plot_pos |
|
721 | 897 | |
|
722 | 898 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
723 | 899 | self.isConfig = True |
|
724 | 900 | self.figfile = figfile |
|
725 | 901 | update_figfile = True |
|
726 | 902 | |
|
727 | 903 | self.setWinTitle(title) |
|
728 | 904 | |
|
729 | 905 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
730 | 906 | x[1] = self.xmax |
|
731 | 907 | |
|
732 | 908 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
733 | 909 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
734 | 910 | zmaxVector = [zmax, zmax, zmax_ver] |
|
735 | 911 | zminVector = [zmin, zmin, zmin_ver] |
|
736 | 912 | windFactor = [1,1,100] |
|
737 | 913 | |
|
738 | 914 | for i in range(nplotsw): |
|
739 | 915 | |
|
740 | 916 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
741 | 917 | axes = self.axesList[i*self.__nsubplots] |
|
742 | 918 | |
|
743 | 919 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
744 | #z1=numpy.ma.masked_where(z1==0.,z1) | |
|
745 | ||
|
920 | ||
|
746 | 921 | axes.pcolorbuffer(x, y, z1, |
|
747 | 922 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
748 | 923 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
749 | 924 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="seismic" ) |
|
750 | 925 | |
|
751 | 926 | if dataOut.data_SNR is not None: |
|
752 | 927 | i += 1 |
|
753 | 928 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
754 | 929 | axes = self.axesList[i*self.__nsubplots] |
|
755 | 930 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
756 | 931 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
757 | 932 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
758 | 933 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
759 | 934 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
760 | 935 | |
|
761 | 936 | self.draw() |
|
762 | 937 | |
|
763 | 938 | self.save(figpath=figpath, |
|
764 | 939 | figfile=figfile, |
|
765 | 940 | save=save, |
|
766 | 941 | ftp=ftp, |
|
767 | 942 | wr_period=wr_period, |
|
768 | 943 | thisDatetime=thisDatetime, |
|
769 | 944 | update_figfile=update_figfile) |
|
770 | 945 | |
|
771 | 946 | if dataOut.ltctime + dataOut.paramInterval >= self.xmax: |
|
772 | 947 | self.counter_imagwr = wr_period |
|
773 | 948 | self.isConfig = False |
|
774 | 949 | update_figfile = True |
|
775 | 950 | |
|
776 | 951 | @MPDecorator |
|
777 | class ParametersPlot(Figure): | |
|
952 | class ParametersPlot_(Figure): | |
|
778 | 953 | |
|
779 | 954 | __isConfig = None |
|
780 | 955 | __nsubplots = None |
|
781 | 956 | |
|
782 | 957 | WIDTHPROF = None |
|
783 | 958 | HEIGHTPROF = None |
|
784 | 959 | PREFIX = 'param' |
|
785 | 960 | |
|
786 | 961 | nplots = None |
|
787 | 962 | nchan = None |
|
788 | 963 | |
|
789 | 964 | def __init__(self):#, **kwargs): |
|
790 | 965 | Figure.__init__(self)#, **kwargs) |
|
791 | 966 | self.timerange = None |
|
792 | 967 | self.isConfig = False |
|
793 | 968 | self.__nsubplots = 1 |
|
794 | 969 | |
|
795 |
self.WIDTH = |
|
|
796 |
self.HEIGHT = |
|
|
970 | self.WIDTH = 300 | |
|
971 | self.HEIGHT = 550 | |
|
797 | 972 | self.WIDTHPROF = 120 |
|
798 | 973 | self.HEIGHTPROF = 0 |
|
799 | 974 | self.counter_imagwr = 0 |
|
800 | 975 | |
|
801 | 976 | self.PLOT_CODE = RTI_CODE |
|
802 | 977 | |
|
803 | 978 | self.FTP_WEI = None |
|
804 | 979 | self.EXP_CODE = None |
|
805 | 980 | self.SUB_EXP_CODE = None |
|
806 | 981 | self.PLOT_POS = None |
|
807 | 982 | self.tmin = None |
|
808 | 983 | self.tmax = None |
|
809 | 984 | |
|
810 | 985 | self.xmin = None |
|
811 | 986 | self.xmax = None |
|
812 | 987 | |
|
813 | 988 | self.figfile = None |
|
814 | 989 | |
|
815 | 990 | def getSubplots(self): |
|
816 | 991 | |
|
817 | 992 | ncol = 1 |
|
818 | 993 | nrow = self.nplots |
|
819 | 994 | |
|
820 | 995 | return nrow, ncol |
|
821 | 996 | |
|
822 | 997 | def setup(self, id, nplots, wintitle, show=True): |
|
823 | 998 | |
|
824 | 999 | self.nplots = nplots |
|
825 | 1000 | |
|
826 | 1001 | ncolspan = 1 |
|
827 | 1002 | colspan = 1 |
|
828 | 1003 | |
|
829 | 1004 | self.createFigure(id = id, |
|
830 | 1005 | wintitle = wintitle, |
|
831 | 1006 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
832 | 1007 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
833 | 1008 | show=show) |
|
834 | 1009 | |
|
835 | 1010 | nrow, ncol = self.getSubplots() |
|
836 | 1011 | |
|
837 | 1012 | counter = 0 |
|
838 | 1013 | for y in range(nrow): |
|
839 | 1014 | for x in range(ncol): |
|
840 | 1015 | |
|
841 | 1016 | if counter >= self.nplots: |
|
842 | 1017 | break |
|
843 | 1018 | |
|
844 | 1019 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
845 | 1020 | |
|
846 | 1021 | counter += 1 |
|
847 | 1022 | |
|
848 | 1023 | def run(self, dataOut, id, wintitle="", channelList=None, paramIndex = 0, colormap="jet", |
|
849 | 1024 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, timerange=None, |
|
850 | 1025 | showSNR=False, SNRthresh = -numpy.inf, SNRmin=None, SNRmax=None, |
|
851 | 1026 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
852 | 1027 | server=None, folder=None, username=None, password=None, |
|
853 | 1028 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, HEIGHT=None): |
|
854 | 1029 | """ |
|
855 | 1030 | |
|
856 | 1031 | Input: |
|
857 | 1032 | dataOut : |
|
858 | 1033 | id : |
|
859 | 1034 | wintitle : |
|
860 | 1035 | channelList : |
|
861 | 1036 | showProfile : |
|
862 | 1037 | xmin : None, |
|
863 | 1038 | xmax : None, |
|
864 | 1039 | ymin : None, |
|
865 | 1040 | ymax : None, |
|
866 | 1041 | zmin : None, |
|
867 | 1042 | zmax : None |
|
868 | 1043 | """ |
|
869 | 1044 | if dataOut.flagNoData: |
|
870 | 1045 | return dataOut |
|
871 | 1046 | |
|
872 | 1047 | |
|
873 | 1048 | if HEIGHT is not None: |
|
874 | 1049 | self.HEIGHT = HEIGHT |
|
875 | 1050 | |
|
876 | 1051 | |
|
877 | 1052 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
878 | 1053 | return |
|
879 | 1054 | |
|
880 | 1055 | if channelList == None: |
|
881 | 1056 | channelIndexList = list(range(dataOut.data_param.shape[0])) |
|
882 | 1057 | else: |
|
883 | 1058 | channelIndexList = [] |
|
884 | 1059 | for channel in channelList: |
|
885 | 1060 | if channel not in dataOut.channelList: |
|
886 | 1061 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
887 | 1062 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
888 | 1063 | |
|
889 | 1064 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
890 | 1065 | y = dataOut.getHeiRange() |
|
891 | 1066 | |
|
892 | 1067 | if dataOut.data_param.ndim == 3: |
|
893 | 1068 | z = dataOut.data_param[channelIndexList,paramIndex,:] |
|
894 | 1069 | else: |
|
895 | 1070 | z = dataOut.data_param[channelIndexList,:] |
|
896 | 1071 | |
|
897 | 1072 | if showSNR: |
|
898 | 1073 | #SNR data |
|
899 | 1074 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
900 | 1075 | SNRdB = 10*numpy.log10(SNRarray) |
|
901 | 1076 | ind = numpy.where(SNRdB < SNRthresh) |
|
902 | 1077 | z[ind] = numpy.nan |
|
903 | 1078 | |
|
904 | 1079 | thisDatetime = dataOut.datatime |
|
905 | 1080 | # thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
906 | 1081 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
907 | 1082 | xlabel = "" |
|
908 |
ylabel = "Range ( |
|
|
1083 | ylabel = "Range (km)" | |
|
909 | 1084 | |
|
910 | 1085 | update_figfile = False |
|
911 | 1086 | |
|
912 | 1087 | if not self.isConfig: |
|
913 | 1088 | |
|
914 | 1089 | nchan = len(channelIndexList) |
|
915 | 1090 | self.nchan = nchan |
|
916 | 1091 | self.plotFact = 1 |
|
917 | 1092 | nplots = nchan |
|
918 | 1093 | |
|
919 | 1094 | if showSNR: |
|
920 | 1095 | nplots = nchan*2 |
|
921 | 1096 | self.plotFact = 2 |
|
922 | 1097 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
923 | 1098 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
924 | 1099 | |
|
925 | 1100 | self.setup(id=id, |
|
926 | 1101 | nplots=nplots, |
|
927 | 1102 | wintitle=wintitle, |
|
928 | 1103 | show=show) |
|
929 | 1104 | |
|
930 | 1105 | if timerange != None: |
|
931 | 1106 | self.timerange = timerange |
|
932 | 1107 | |
|
933 | 1108 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
934 | 1109 | |
|
935 | 1110 | if ymin == None: ymin = numpy.nanmin(y) |
|
936 | 1111 | if ymax == None: ymax = numpy.nanmax(y) |
|
937 | 1112 | if zmin == None: zmin = numpy.nanmin(z) |
|
938 | 1113 | if zmax == None: zmax = numpy.nanmax(z) |
|
939 | 1114 | |
|
940 | 1115 | self.FTP_WEI = ftp_wei |
|
941 | 1116 | self.EXP_CODE = exp_code |
|
942 | 1117 | self.SUB_EXP_CODE = sub_exp_code |
|
943 | 1118 | self.PLOT_POS = plot_pos |
|
944 | 1119 | |
|
945 | 1120 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
946 | 1121 | self.isConfig = True |
|
947 | 1122 | self.figfile = figfile |
|
948 | 1123 | update_figfile = True |
|
949 | 1124 | |
|
950 | 1125 | self.setWinTitle(title) |
|
951 | 1126 | |
|
952 | for i in range(self.nchan): | |
|
953 | index = channelIndexList[i] | |
|
954 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
955 | axes = self.axesList[i*self.plotFact] | |
|
956 | z1 = z[i,:].reshape((1,-1)) | |
|
957 | axes.pcolorbuffer(x, y, z1, | |
|
958 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
959 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
960 | ticksize=9, cblabel='', cbsize="1%",colormap=colormap) | |
|
961 | ||
|
962 | if showSNR: | |
|
963 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
964 | axes = self.axesList[i*self.plotFact + 1] | |
|
965 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) | |
|
966 | axes.pcolorbuffer(x, y, SNRdB1, | |
|
967 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
|
968 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
969 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') | |
|
1127 | # for i in range(self.nchan): | |
|
1128 | # index = channelIndexList[i] | |
|
1129 | # title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
1130 | # axes = self.axesList[i*self.plotFact] | |
|
1131 | # z1 = z[i,:].reshape((1,-1)) | |
|
1132 | # axes.pcolorbuffer(x, y, z1, | |
|
1133 | # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
1134 | # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
1135 | # ticksize=9, cblabel='', cbsize="1%",colormap=colormap) | |
|
1136 | # | |
|
1137 | # if showSNR: | |
|
1138 | # title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
1139 | # axes = self.axesList[i*self.plotFact + 1] | |
|
1140 | # SNRdB1 = SNRdB[i,:].reshape((1,-1)) | |
|
1141 | # axes.pcolorbuffer(x, y, SNRdB1, | |
|
1142 | # xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
|
1143 | # xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
1144 | # ticksize=9, cblabel='', cbsize="1%",colormap='jet') | |
|
1145 | ||
|
1146 | i=0 | |
|
1147 | index = channelIndexList[i] | |
|
1148 | title = "Factor de reflectividad Z [dBZ]" | |
|
1149 | axes = self.axesList[i*self.plotFact] | |
|
1150 | z1 = z[i,:].reshape((1,-1)) | |
|
1151 | axes.pcolorbuffer(x, y, z1, | |
|
1152 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
1153 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
1154 | ticksize=9, cblabel='', cbsize="1%",colormap=colormap) | |
|
1155 | ||
|
1156 | if showSNR: | |
|
1157 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
1158 | axes = self.axesList[i*self.plotFact + 1] | |
|
1159 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) | |
|
1160 | axes.pcolorbuffer(x, y, SNRdB1, | |
|
1161 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
|
1162 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
1163 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') | |
|
1164 | ||
|
1165 | i=1 | |
|
1166 | index = channelIndexList[i] | |
|
1167 | title = "Velocidad vertical Doppler [m/s]" | |
|
1168 | axes = self.axesList[i*self.plotFact] | |
|
1169 | z1 = z[i,:].reshape((1,-1)) | |
|
1170 | axes.pcolorbuffer(x, y, z1, | |
|
1171 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-10, zmax=10, | |
|
1172 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
1173 | ticksize=9, cblabel='', cbsize="1%",colormap='seismic_r') | |
|
1174 | ||
|
1175 | if showSNR: | |
|
1176 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
1177 | axes = self.axesList[i*self.plotFact + 1] | |
|
1178 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) | |
|
1179 | axes.pcolorbuffer(x, y, SNRdB1, | |
|
1180 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
|
1181 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
1182 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') | |
|
1183 | ||
|
1184 | i=2 | |
|
1185 | index = channelIndexList[i] | |
|
1186 | title = "Intensidad de lluvia [mm/h]" | |
|
1187 | axes = self.axesList[i*self.plotFact] | |
|
1188 | z1 = z[i,:].reshape((1,-1)) | |
|
1189 | axes.pcolorbuffer(x, y, z1, | |
|
1190 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=40, | |
|
1191 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
1192 | ticksize=9, cblabel='', cbsize="1%",colormap='ocean_r') | |
|
1193 | ||
|
1194 | if showSNR: | |
|
1195 | title = "Channel %d SNR: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
1196 | axes = self.axesList[i*self.plotFact + 1] | |
|
1197 | SNRdB1 = SNRdB[i,:].reshape((1,-1)) | |
|
1198 | axes.pcolorbuffer(x, y, SNRdB1, | |
|
1199 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, | |
|
1200 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
|
1201 | ticksize=9, cblabel='', cbsize="1%",colormap='jet') | |
|
970 | 1202 | |
|
971 | 1203 | |
|
972 | 1204 | self.draw() |
|
973 | 1205 | |
|
974 | 1206 | if dataOut.ltctime >= self.xmax: |
|
975 | 1207 | self.counter_imagwr = wr_period |
|
976 | 1208 | self.isConfig = False |
|
977 | 1209 | update_figfile = True |
|
978 | 1210 | |
|
979 | 1211 | self.save(figpath=figpath, |
|
980 | 1212 | figfile=figfile, |
|
981 | 1213 | save=save, |
|
982 | 1214 | ftp=ftp, |
|
983 | 1215 | wr_period=wr_period, |
|
984 | 1216 | thisDatetime=thisDatetime, |
|
985 | 1217 | update_figfile=update_figfile) |
|
986 | 1218 | |
|
987 | 1219 | return dataOut |
|
988 | 1220 | @MPDecorator |
|
989 | class Parameters1Plot(Figure): | |
|
1221 | class Parameters1Plot_(Figure): | |
|
990 | 1222 | |
|
991 | 1223 | __isConfig = None |
|
992 | 1224 | __nsubplots = None |
|
993 | 1225 | |
|
994 | 1226 | WIDTHPROF = None |
|
995 | 1227 | HEIGHTPROF = None |
|
996 | 1228 | PREFIX = 'prm' |
|
997 | 1229 | |
|
998 | 1230 | def __init__(self): |
|
999 | 1231 | Figure.__init__(self) |
|
1000 | 1232 | self.timerange = 2*60*60 |
|
1001 | 1233 | self.isConfig = False |
|
1002 | 1234 | self.__nsubplots = 1 |
|
1003 | 1235 | |
|
1004 | 1236 | self.WIDTH = 800 |
|
1005 | 1237 | self.HEIGHT = 180 |
|
1006 | 1238 | self.WIDTHPROF = 120 |
|
1007 | 1239 | self.HEIGHTPROF = 0 |
|
1008 | 1240 | self.counter_imagwr = 0 |
|
1009 | 1241 | |
|
1010 | 1242 | self.PLOT_CODE = PARMS_CODE |
|
1011 | 1243 | |
|
1012 | 1244 | self.FTP_WEI = None |
|
1013 | 1245 | self.EXP_CODE = None |
|
1014 | 1246 | self.SUB_EXP_CODE = None |
|
1015 | 1247 | self.PLOT_POS = None |
|
1016 | 1248 | self.tmin = None |
|
1017 | 1249 | self.tmax = None |
|
1018 | 1250 | |
|
1019 | 1251 | self.xmin = None |
|
1020 | 1252 | self.xmax = None |
|
1021 | 1253 | |
|
1022 | 1254 | self.figfile = None |
|
1023 | 1255 | |
|
1024 | 1256 | def getSubplots(self): |
|
1025 | 1257 | |
|
1026 | 1258 | ncol = 1 |
|
1027 | 1259 | nrow = self.nplots |
|
1028 | 1260 | |
|
1029 | 1261 | return nrow, ncol |
|
1030 | 1262 | |
|
1031 | 1263 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1032 | 1264 | |
|
1033 | 1265 | self.__showprofile = showprofile |
|
1034 | 1266 | self.nplots = nplots |
|
1035 | 1267 | |
|
1036 | 1268 | ncolspan = 1 |
|
1037 | 1269 | colspan = 1 |
|
1038 | 1270 | |
|
1039 | 1271 | self.createFigure(id = id, |
|
1040 | 1272 | wintitle = wintitle, |
|
1041 | 1273 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1042 | 1274 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1043 | 1275 | show=show) |
|
1044 | 1276 | |
|
1045 | 1277 | nrow, ncol = self.getSubplots() |
|
1046 | 1278 | |
|
1047 | 1279 | counter = 0 |
|
1048 | 1280 | for y in range(nrow): |
|
1049 | 1281 | for x in range(ncol): |
|
1050 | 1282 | |
|
1051 | 1283 | if counter >= self.nplots: |
|
1052 | 1284 | break |
|
1053 | 1285 | |
|
1054 | 1286 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1055 | 1287 | |
|
1056 | 1288 | if showprofile: |
|
1057 | 1289 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1058 | 1290 | |
|
1059 | 1291 | counter += 1 |
|
1060 | 1292 | |
|
1061 | 1293 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
1062 | 1294 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
1063 | 1295 | parameterIndex = None, onlyPositive = False, |
|
1064 | 1296 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, onlySNR = False, |
|
1065 | 1297 | DOP = True, |
|
1066 | 1298 | zlabel = "", parameterName = "", parameterObject = "data_param", |
|
1067 | 1299 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1068 | 1300 | server=None, folder=None, username=None, password=None, |
|
1069 | 1301 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1070 | #print inspect.getargspec(self.run).args | |
|
1071 | """ | |
|
1072 | 1302 | |
|
1303 | """ | |
|
1073 | 1304 | Input: |
|
1074 | 1305 | dataOut : |
|
1075 | 1306 | id : |
|
1076 | 1307 | wintitle : |
|
1077 | 1308 | channelList : |
|
1078 | 1309 | showProfile : |
|
1079 | 1310 | xmin : None, |
|
1080 | 1311 | xmax : None, |
|
1081 | 1312 | ymin : None, |
|
1082 | 1313 | ymax : None, |
|
1083 | 1314 | zmin : None, |
|
1084 | 1315 | zmax : None |
|
1085 | 1316 | """ |
|
1086 | 1317 | if dataOut.flagNoData: |
|
1087 | 1318 | return dataOut |
|
1088 | 1319 | |
|
1089 | 1320 | data_param = getattr(dataOut, parameterObject) |
|
1090 | 1321 | |
|
1091 | 1322 | if channelList == None: |
|
1092 | 1323 | channelIndexList = numpy.arange(data_param.shape[0]) |
|
1093 | 1324 | else: |
|
1094 | 1325 | channelIndexList = numpy.array(channelList) |
|
1095 | 1326 | |
|
1096 | 1327 | nchan = len(channelIndexList) #Number of channels being plotted |
|
1097 | 1328 | |
|
1098 | 1329 | if nchan < 1: |
|
1099 | 1330 | return |
|
1100 | 1331 | |
|
1101 | 1332 | nGraphsByChannel = 0 |
|
1102 | 1333 | |
|
1103 | 1334 | if SNR: |
|
1104 | 1335 | nGraphsByChannel += 1 |
|
1105 | 1336 | if DOP: |
|
1106 | 1337 | nGraphsByChannel += 1 |
|
1107 | 1338 | |
|
1108 | 1339 | if nGraphsByChannel < 1: |
|
1109 | 1340 | return |
|
1110 | 1341 | |
|
1111 | 1342 | nplots = nGraphsByChannel*nchan |
|
1112 | 1343 | |
|
1113 | 1344 | if timerange is not None: |
|
1114 | 1345 | self.timerange = timerange |
|
1115 | 1346 | |
|
1116 | 1347 | #tmin = None |
|
1117 | 1348 | #tmax = None |
|
1118 | 1349 | if parameterIndex == None: |
|
1119 | 1350 | parameterIndex = 1 |
|
1120 | 1351 | |
|
1121 | 1352 | x = dataOut.getTimeRange1(dataOut.paramInterval) |
|
1122 | 1353 | y = dataOut.heightList |
|
1123 | 1354 | |
|
1124 | 1355 | if dataOut.data_param.ndim == 3: |
|
1125 | 1356 | z = dataOut.data_param[channelIndexList,parameterIndex,:] |
|
1126 | 1357 | else: |
|
1127 | 1358 | z = dataOut.data_param[channelIndexList,:] |
|
1128 | 1359 | |
|
1129 | 1360 | if dataOut.data_SNR is not None: |
|
1130 | 1361 | if dataOut.data_SNR.ndim == 2: |
|
1131 | 1362 | SNRavg = numpy.average(dataOut.data_SNR, axis=0) |
|
1132 | 1363 | else: |
|
1133 | 1364 | SNRavg = dataOut.data_SNR |
|
1134 | 1365 | SNRdB = 10*numpy.log10(SNRavg) |
|
1135 | 1366 | |
|
1136 | 1367 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1137 | 1368 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1138 | 1369 | xlabel = "" |
|
1139 | 1370 | ylabel = "Range (Km)" |
|
1140 | 1371 | |
|
1141 | 1372 | if onlyPositive: |
|
1142 | 1373 | colormap = "jet" |
|
1143 | 1374 | zmin = 0 |
|
1144 | 1375 | else: colormap = "RdBu_r" |
|
1145 | 1376 | |
|
1146 | 1377 | if not self.isConfig: |
|
1147 | 1378 | |
|
1148 | 1379 | self.setup(id=id, |
|
1149 | 1380 | nplots=nplots, |
|
1150 | 1381 | wintitle=wintitle, |
|
1151 | 1382 | showprofile=showprofile, |
|
1152 | 1383 | show=show) |
|
1153 | 1384 | |
|
1154 | 1385 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1155 | 1386 | |
|
1156 | 1387 | if ymin == None: ymin = numpy.nanmin(y) |
|
1157 | 1388 | if ymax == None: ymax = numpy.nanmax(y) |
|
1158 | 1389 | if zmin == None: zmin = numpy.nanmin(z) |
|
1159 | 1390 | if zmax == None: zmax = numpy.nanmax(z) |
|
1160 | 1391 | |
|
1161 | 1392 | if SNR: |
|
1162 | 1393 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
1163 | 1394 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
1164 | 1395 | |
|
1165 | 1396 | self.FTP_WEI = ftp_wei |
|
1166 | 1397 | self.EXP_CODE = exp_code |
|
1167 | 1398 | self.SUB_EXP_CODE = sub_exp_code |
|
1168 | 1399 | self.PLOT_POS = plot_pos |
|
1169 | 1400 | |
|
1170 | 1401 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1171 | 1402 | self.isConfig = True |
|
1172 | 1403 | self.figfile = figfile |
|
1173 | 1404 | |
|
1174 | 1405 | self.setWinTitle(title) |
|
1175 | 1406 | |
|
1176 | 1407 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1177 | 1408 | x[1] = self.xmax |
|
1178 | 1409 | |
|
1179 | 1410 | for i in range(nchan): |
|
1180 | 1411 | |
|
1181 | 1412 | if (SNR and not onlySNR): j = 2*i |
|
1182 | 1413 | else: j = i |
|
1183 | 1414 | |
|
1184 | 1415 | j = nGraphsByChannel*i |
|
1185 | 1416 | |
|
1186 | 1417 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1187 | 1418 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
1188 | 1419 | |
|
1189 | 1420 | if not onlySNR: |
|
1190 | 1421 | axes = self.axesList[j*self.__nsubplots] |
|
1191 | 1422 | z1 = z[i,:].reshape((1,-1)) |
|
1192 | 1423 | axes.pcolorbuffer(x, y, z1, |
|
1193 | 1424 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1194 | 1425 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
1195 | 1426 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1196 | 1427 | |
|
1197 | 1428 | if DOP: |
|
1198 | 1429 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1199 | 1430 | |
|
1200 | 1431 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1201 | 1432 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
1202 | 1433 | axes = self.axesList[j] |
|
1203 | 1434 | z1 = z[i,:].reshape((1,-1)) |
|
1204 | 1435 | axes.pcolorbuffer(x, y, z1, |
|
1205 | 1436 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1206 | 1437 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
1207 | 1438 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1208 | 1439 | |
|
1209 | 1440 | if SNR: |
|
1210 | 1441 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1211 | 1442 | axes = self.axesList[(j)*self.__nsubplots] |
|
1212 | 1443 | if not onlySNR: |
|
1213 | 1444 | axes = self.axesList[(j + 1)*self.__nsubplots] |
|
1214 | 1445 | |
|
1215 | 1446 | axes = self.axesList[(j + nGraphsByChannel-1)] |
|
1216 | 1447 | z1 = SNRdB.reshape((1,-1)) |
|
1217 | 1448 | axes.pcolorbuffer(x, y, z1, |
|
1218 | 1449 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1219 | 1450 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", |
|
1220 | 1451 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
1221 | 1452 | |
|
1222 | 1453 | |
|
1223 | 1454 | |
|
1224 | 1455 | self.draw() |
|
1225 | 1456 | |
|
1226 | 1457 | if x[1] >= self.axesList[0].xmax: |
|
1227 | 1458 | self.counter_imagwr = wr_period |
|
1228 | 1459 | self.isConfig = False |
|
1229 | 1460 | self.figfile = None |
|
1230 | 1461 | |
|
1231 | 1462 | self.save(figpath=figpath, |
|
1232 | 1463 | figfile=figfile, |
|
1233 | 1464 | save=save, |
|
1234 | 1465 | ftp=ftp, |
|
1235 | 1466 | wr_period=wr_period, |
|
1236 | 1467 | thisDatetime=thisDatetime, |
|
1237 | 1468 | update_figfile=False) |
|
1238 | 1469 | return dataOut |
|
1239 | 1470 | |
|
1240 | class SpectralFittingPlot(Figure): | |
|
1471 | class SpectralFittingPlot_(Figure): | |
|
1241 | 1472 | |
|
1242 | 1473 | __isConfig = None |
|
1243 | 1474 | __nsubplots = None |
|
1244 | 1475 | |
|
1245 | 1476 | WIDTHPROF = None |
|
1246 | 1477 | HEIGHTPROF = None |
|
1247 | 1478 | PREFIX = 'prm' |
|
1248 | 1479 | |
|
1249 | 1480 | |
|
1250 | 1481 | N = None |
|
1251 | 1482 | ippSeconds = None |
|
1252 | 1483 | |
|
1253 | 1484 | def __init__(self, **kwargs): |
|
1254 | 1485 | Figure.__init__(self, **kwargs) |
|
1255 | 1486 | self.isConfig = False |
|
1256 | 1487 | self.__nsubplots = 1 |
|
1257 | 1488 | |
|
1258 | 1489 | self.PLOT_CODE = SPECFIT_CODE |
|
1259 | 1490 | |
|
1260 | 1491 | self.WIDTH = 450 |
|
1261 | 1492 | self.HEIGHT = 250 |
|
1262 | 1493 | self.WIDTHPROF = 0 |
|
1263 | 1494 | self.HEIGHTPROF = 0 |
|
1264 | 1495 | |
|
1265 | 1496 | def getSubplots(self): |
|
1266 | 1497 | |
|
1267 | 1498 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1268 | 1499 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1269 | 1500 | |
|
1270 | 1501 | return nrow, ncol |
|
1271 | 1502 | |
|
1272 | 1503 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
1273 | 1504 | |
|
1274 | 1505 | showprofile = False |
|
1275 | 1506 | self.__showprofile = showprofile |
|
1276 | 1507 | self.nplots = nplots |
|
1277 | 1508 | |
|
1278 | 1509 | ncolspan = 5 |
|
1279 | 1510 | colspan = 4 |
|
1280 | 1511 | if showprofile: |
|
1281 | 1512 | ncolspan = 5 |
|
1282 | 1513 | colspan = 4 |
|
1283 | 1514 | self.__nsubplots = 2 |
|
1284 | 1515 | |
|
1285 | 1516 | self.createFigure(id = id, |
|
1286 | 1517 | wintitle = wintitle, |
|
1287 | 1518 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1288 | 1519 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1289 | 1520 | show=show) |
|
1290 | 1521 | |
|
1291 | 1522 | nrow, ncol = self.getSubplots() |
|
1292 | 1523 | |
|
1293 | 1524 | counter = 0 |
|
1294 | 1525 | for y in range(nrow): |
|
1295 | 1526 | for x in range(ncol): |
|
1296 | 1527 | |
|
1297 | 1528 | if counter >= self.nplots: |
|
1298 | 1529 | break |
|
1299 | 1530 | |
|
1300 | 1531 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1301 | 1532 | |
|
1302 | 1533 | if showprofile: |
|
1303 | 1534 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1304 | 1535 | |
|
1305 | 1536 | counter += 1 |
|
1306 | 1537 | |
|
1307 | 1538 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, |
|
1308 | 1539 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1309 | 1540 | save=False, figpath='./', figfile=None, show=True): |
|
1310 | 1541 | |
|
1311 | 1542 | """ |
|
1312 | 1543 | |
|
1313 | 1544 | Input: |
|
1314 | 1545 | dataOut : |
|
1315 | 1546 | id : |
|
1316 | 1547 | wintitle : |
|
1317 | 1548 | channelList : |
|
1318 | 1549 | showProfile : |
|
1319 | 1550 | xmin : None, |
|
1320 | 1551 | xmax : None, |
|
1321 | 1552 | zmin : None, |
|
1322 | 1553 | zmax : None |
|
1323 | 1554 | """ |
|
1324 | 1555 | |
|
1325 | 1556 | if cutHeight==None: |
|
1326 | 1557 | h=270 |
|
1327 | 1558 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() |
|
1328 | 1559 | cutHeight = dataOut.heightList[heightindex] |
|
1329 | 1560 | |
|
1330 | 1561 | factor = dataOut.normFactor |
|
1331 | 1562 | x = dataOut.abscissaList[:-1] |
|
1332 | 1563 | #y = dataOut.getHeiRange() |
|
1333 | 1564 | |
|
1334 | 1565 | z = dataOut.data_pre[:,:,heightindex]/factor |
|
1335 | 1566 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1336 | 1567 | avg = numpy.average(z, axis=1) |
|
1337 | 1568 | listChannels = z.shape[0] |
|
1338 | 1569 | |
|
1339 | 1570 | #Reconstruct Function |
|
1340 | 1571 | if fit==True: |
|
1341 | 1572 | groupArray = dataOut.groupList |
|
1342 | 1573 | listChannels = groupArray.reshape((groupArray.size)) |
|
1343 | 1574 | listChannels.sort() |
|
1344 | 1575 | spcFitLine = numpy.zeros(z.shape) |
|
1345 | 1576 | constants = dataOut.constants |
|
1346 | 1577 | |
|
1347 | 1578 | nGroups = groupArray.shape[0] |
|
1348 | 1579 | nChannels = groupArray.shape[1] |
|
1349 | 1580 | nProfiles = z.shape[1] |
|
1350 | 1581 | |
|
1351 | 1582 | for f in range(nGroups): |
|
1352 | 1583 | groupChann = groupArray[f,:] |
|
1353 | 1584 | p = dataOut.data_param[f,:,heightindex] |
|
1354 | 1585 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) |
|
1355 | 1586 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles |
|
1356 | 1587 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) |
|
1357 | 1588 | spcFitLine[groupChann,:] = fitLineAux |
|
1358 | 1589 | # spcFitLine = spcFitLine/factor |
|
1359 | 1590 | |
|
1360 | 1591 | z = z[listChannels,:] |
|
1361 | 1592 | spcFitLine = spcFitLine[listChannels,:] |
|
1362 | 1593 | spcFitLinedB = 10*numpy.log10(spcFitLine) |
|
1363 | 1594 | |
|
1364 | 1595 | zdB = 10*numpy.log10(z) |
|
1365 | 1596 | #thisDatetime = dataOut.datatime |
|
1366 | 1597 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1367 | 1598 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1368 | 1599 | xlabel = "Velocity (m/s)" |
|
1369 | 1600 | ylabel = "Spectrum" |
|
1370 | 1601 | |
|
1371 | 1602 | if not self.isConfig: |
|
1372 | 1603 | |
|
1373 | 1604 | nplots = listChannels.size |
|
1374 | 1605 | |
|
1375 | 1606 | self.setup(id=id, |
|
1376 | 1607 | nplots=nplots, |
|
1377 | 1608 | wintitle=wintitle, |
|
1378 | 1609 | showprofile=showprofile, |
|
1379 | 1610 | show=show) |
|
1380 | 1611 | |
|
1381 | 1612 | if xmin == None: xmin = numpy.nanmin(x) |
|
1382 | 1613 | if xmax == None: xmax = numpy.nanmax(x) |
|
1383 | 1614 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1384 | 1615 | if ymax == None: ymax = numpy.nanmax(zdB)+2 |
|
1385 | 1616 | |
|
1386 | 1617 | self.isConfig = True |
|
1387 | 1618 | |
|
1388 | 1619 | self.setWinTitle(title) |
|
1389 | 1620 | for i in range(self.nplots): |
|
1390 | 1621 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
1391 | 1622 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]) |
|
1392 | 1623 | axes = self.axesList[i*self.__nsubplots] |
|
1393 | 1624 | if fit == False: |
|
1394 | 1625 | axes.pline(x, zdB[i,:], |
|
1395 | 1626 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1396 | 1627 | xlabel=xlabel, ylabel=ylabel, title=title |
|
1397 | 1628 | ) |
|
1398 | 1629 | if fit == True: |
|
1399 | 1630 | fitline=spcFitLinedB[i,:] |
|
1400 | 1631 | y=numpy.vstack([zdB[i,:],fitline] ) |
|
1401 | 1632 | legendlabels=['Data','Fitting'] |
|
1402 | 1633 | axes.pmultilineyaxis(x, y, |
|
1403 | 1634 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1404 | 1635 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
1405 | 1636 | legendlabels=legendlabels, marker=None, |
|
1406 | 1637 | linestyle='solid', grid='both') |
|
1407 | 1638 | |
|
1408 | 1639 | self.draw() |
|
1409 | 1640 | |
|
1410 | 1641 | self.save(figpath=figpath, |
|
1411 | 1642 | figfile=figfile, |
|
1412 | 1643 | save=save, |
|
1413 | 1644 | ftp=ftp, |
|
1414 | 1645 | wr_period=wr_period, |
|
1415 | 1646 | thisDatetime=thisDatetime) |
|
1416 | 1647 | |
|
1417 | 1648 | |
|
1418 | class EWDriftsPlot(Figure): | |
|
1649 | class EWDriftsPlot_(Figure): | |
|
1419 | 1650 | |
|
1420 | 1651 | __isConfig = None |
|
1421 | 1652 | __nsubplots = None |
|
1422 | 1653 | |
|
1423 | 1654 | WIDTHPROF = None |
|
1424 | 1655 | HEIGHTPROF = None |
|
1425 | 1656 | PREFIX = 'drift' |
|
1426 | 1657 | |
|
1427 | 1658 | def __init__(self, **kwargs): |
|
1428 | 1659 | Figure.__init__(self, **kwargs) |
|
1429 | 1660 | self.timerange = 2*60*60 |
|
1430 | 1661 | self.isConfig = False |
|
1431 | 1662 | self.__nsubplots = 1 |
|
1432 | 1663 | |
|
1433 | 1664 | self.WIDTH = 800 |
|
1434 | 1665 | self.HEIGHT = 150 |
|
1435 | 1666 | self.WIDTHPROF = 120 |
|
1436 | 1667 | self.HEIGHTPROF = 0 |
|
1437 | 1668 | self.counter_imagwr = 0 |
|
1438 | 1669 | |
|
1439 | 1670 | self.PLOT_CODE = EWDRIFT_CODE |
|
1440 | 1671 | |
|
1441 | 1672 | self.FTP_WEI = None |
|
1442 | 1673 | self.EXP_CODE = None |
|
1443 | 1674 | self.SUB_EXP_CODE = None |
|
1444 | 1675 | self.PLOT_POS = None |
|
1445 | 1676 | self.tmin = None |
|
1446 | 1677 | self.tmax = None |
|
1447 | 1678 | |
|
1448 | 1679 | self.xmin = None |
|
1449 | 1680 | self.xmax = None |
|
1450 | 1681 | |
|
1451 | 1682 | self.figfile = None |
|
1452 | 1683 | |
|
1453 | 1684 | def getSubplots(self): |
|
1454 | 1685 | |
|
1455 | 1686 | ncol = 1 |
|
1456 | 1687 | nrow = self.nplots |
|
1457 | 1688 | |
|
1458 | 1689 | return nrow, ncol |
|
1459 | 1690 | |
|
1460 | 1691 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1461 | 1692 | |
|
1462 | 1693 | self.__showprofile = showprofile |
|
1463 | 1694 | self.nplots = nplots |
|
1464 | 1695 | |
|
1465 | 1696 | ncolspan = 1 |
|
1466 | 1697 | colspan = 1 |
|
1467 | 1698 | |
|
1468 | 1699 | self.createFigure(id = id, |
|
1469 | 1700 | wintitle = wintitle, |
|
1470 | 1701 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1471 | 1702 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1472 | 1703 | show=show) |
|
1473 | 1704 | |
|
1474 | 1705 | nrow, ncol = self.getSubplots() |
|
1475 | 1706 | |
|
1476 | 1707 | counter = 0 |
|
1477 | 1708 | for y in range(nrow): |
|
1478 | 1709 | if counter >= self.nplots: |
|
1479 | 1710 | break |
|
1480 | 1711 | |
|
1481 | 1712 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
1482 | 1713 | counter += 1 |
|
1483 | 1714 | |
|
1484 | 1715 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1485 | 1716 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1486 | 1717 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, |
|
1487 | 1718 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, |
|
1488 | 1719 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
1489 | 1720 | server=None, folder=None, username=None, password=None, |
|
1490 | 1721 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1491 | 1722 | """ |
|
1492 | 1723 | |
|
1493 | 1724 | Input: |
|
1494 | 1725 | dataOut : |
|
1495 | 1726 | id : |
|
1496 | 1727 | wintitle : |
|
1497 | 1728 | channelList : |
|
1498 | 1729 | showProfile : |
|
1499 | 1730 | xmin : None, |
|
1500 | 1731 | xmax : None, |
|
1501 | 1732 | ymin : None, |
|
1502 | 1733 | ymax : None, |
|
1503 | 1734 | zmin : None, |
|
1504 | 1735 | zmax : None |
|
1505 | 1736 | """ |
|
1506 | 1737 | |
|
1507 | 1738 | if timerange is not None: |
|
1508 | 1739 | self.timerange = timerange |
|
1509 | 1740 | |
|
1510 | 1741 | tmin = None |
|
1511 | 1742 | tmax = None |
|
1512 | 1743 | |
|
1513 | 1744 | x = dataOut.getTimeRange1(dataOut.outputInterval) |
|
1514 | 1745 | # y = dataOut.heightList |
|
1515 | 1746 | y = dataOut.heightList |
|
1516 | 1747 | |
|
1517 | 1748 | z = dataOut.data_output |
|
1518 | 1749 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
1519 | 1750 | nplotsw = nplots |
|
1520 | 1751 | |
|
1521 | 1752 | #If there is a SNR function defined |
|
1522 | 1753 | if dataOut.data_SNR is not None: |
|
1523 | 1754 | nplots += 1 |
|
1524 | 1755 | SNR = dataOut.data_SNR |
|
1525 | 1756 | |
|
1526 | 1757 | if SNR_1: |
|
1527 | 1758 | SNR += 1 |
|
1528 | 1759 | |
|
1529 | 1760 | SNRavg = numpy.average(SNR, axis=0) |
|
1530 | 1761 | |
|
1531 | 1762 | SNRdB = 10*numpy.log10(SNR) |
|
1532 | 1763 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
1533 | 1764 | |
|
1534 | 1765 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
1535 | 1766 | |
|
1536 | 1767 | for i in range(nplotsw): |
|
1537 | 1768 | z[i,ind] = numpy.nan |
|
1538 | 1769 | |
|
1539 | 1770 | |
|
1540 | 1771 | showprofile = False |
|
1541 | 1772 | # thisDatetime = dataOut.datatime |
|
1542 | 1773 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) |
|
1543 | 1774 | title = wintitle + " EW Drifts" |
|
1544 | 1775 | xlabel = "" |
|
1545 | 1776 | ylabel = "Height (Km)" |
|
1546 | 1777 | |
|
1547 | 1778 | if not self.isConfig: |
|
1548 | 1779 | |
|
1549 | 1780 | self.setup(id=id, |
|
1550 | 1781 | nplots=nplots, |
|
1551 | 1782 | wintitle=wintitle, |
|
1552 | 1783 | showprofile=showprofile, |
|
1553 | 1784 | show=show) |
|
1554 | 1785 | |
|
1555 | 1786 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1556 | 1787 | |
|
1557 | 1788 | if ymin == None: ymin = numpy.nanmin(y) |
|
1558 | 1789 | if ymax == None: ymax = numpy.nanmax(y) |
|
1559 | 1790 | |
|
1560 | 1791 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) |
|
1561 | 1792 | if zminZonal == None: zminZonal = -zmaxZonal |
|
1562 | 1793 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) |
|
1563 | 1794 | if zminVertical == None: zminVertical = -zmaxVertical |
|
1564 | 1795 | |
|
1565 | 1796 | if dataOut.data_SNR is not None: |
|
1566 | 1797 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
1567 | 1798 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
1568 | 1799 | |
|
1569 | 1800 | self.FTP_WEI = ftp_wei |
|
1570 | 1801 | self.EXP_CODE = exp_code |
|
1571 | 1802 | self.SUB_EXP_CODE = sub_exp_code |
|
1572 | 1803 | self.PLOT_POS = plot_pos |
|
1573 | 1804 | |
|
1574 | 1805 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1575 | 1806 | self.isConfig = True |
|
1576 | 1807 | |
|
1577 | 1808 | |
|
1578 | 1809 | self.setWinTitle(title) |
|
1579 | 1810 | |
|
1580 | 1811 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1581 | 1812 | x[1] = self.xmax |
|
1582 | 1813 | |
|
1583 | 1814 | strWind = ['Zonal','Vertical'] |
|
1584 | 1815 | strCb = 'Velocity (m/s)' |
|
1585 | 1816 | zmaxVector = [zmaxZonal, zmaxVertical] |
|
1586 | 1817 | zminVector = [zminZonal, zminVertical] |
|
1587 | 1818 | |
|
1588 | 1819 | for i in range(nplotsw): |
|
1589 | 1820 | |
|
1590 | 1821 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1591 | 1822 | axes = self.axesList[i*self.__nsubplots] |
|
1592 | 1823 | |
|
1593 | 1824 | z1 = z[i,:].reshape((1,-1)) |
|
1594 | 1825 | |
|
1595 | 1826 | axes.pcolorbuffer(x, y, z1, |
|
1596 | 1827 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
1597 | 1828 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1598 | 1829 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") |
|
1599 | 1830 | |
|
1600 | 1831 | if dataOut.data_SNR is not None: |
|
1601 | 1832 | i += 1 |
|
1602 | 1833 | if SNR_1: |
|
1603 | 1834 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1604 | 1835 | else: |
|
1605 | 1836 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1606 | 1837 | axes = self.axesList[i*self.__nsubplots] |
|
1607 | 1838 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
1608 | 1839 | |
|
1609 | 1840 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
1610 | 1841 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1611 | 1842 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1612 | 1843 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
1613 | 1844 | |
|
1614 | 1845 | self.draw() |
|
1615 | 1846 | |
|
1616 | 1847 | if x[1] >= self.axesList[0].xmax: |
|
1617 | 1848 | self.counter_imagwr = wr_period |
|
1618 | 1849 | self.isConfig = False |
|
1619 | 1850 | self.figfile = None |
|
1620 | 1851 | |
|
1621 | 1852 | |
|
1622 | 1853 | |
|
1623 | 1854 | |
|
1624 | class PhasePlot(Figure): | |
|
1855 | class PhasePlot_(Figure): | |
|
1625 | 1856 | |
|
1626 | 1857 | __isConfig = None |
|
1627 | 1858 | __nsubplots = None |
|
1628 | 1859 | |
|
1629 | 1860 | PREFIX = 'mphase' |
|
1630 | 1861 | |
|
1631 | 1862 | |
|
1632 | 1863 | def __init__(self, **kwargs): |
|
1633 | 1864 | Figure.__init__(self, **kwargs) |
|
1634 | 1865 | self.timerange = 24*60*60 |
|
1635 | 1866 | self.isConfig = False |
|
1636 | 1867 | self.__nsubplots = 1 |
|
1637 | 1868 | self.counter_imagwr = 0 |
|
1638 | 1869 | self.WIDTH = 600 |
|
1639 | 1870 | self.HEIGHT = 300 |
|
1640 | 1871 | self.WIDTHPROF = 120 |
|
1641 | 1872 | self.HEIGHTPROF = 0 |
|
1642 | 1873 | self.xdata = None |
|
1643 | 1874 | self.ydata = None |
|
1644 | 1875 | |
|
1645 | 1876 | self.PLOT_CODE = MPHASE_CODE |
|
1646 | 1877 | |
|
1647 | 1878 | self.FTP_WEI = None |
|
1648 | 1879 | self.EXP_CODE = None |
|
1649 | 1880 | self.SUB_EXP_CODE = None |
|
1650 | 1881 | self.PLOT_POS = None |
|
1651 | 1882 | |
|
1652 | 1883 | |
|
1653 | 1884 | self.filename_phase = None |
|
1654 | 1885 | |
|
1655 | 1886 | self.figfile = None |
|
1656 | 1887 | |
|
1657 | 1888 | def getSubplots(self): |
|
1658 | 1889 | |
|
1659 | 1890 | ncol = 1 |
|
1660 | 1891 | nrow = 1 |
|
1661 | 1892 | |
|
1662 | 1893 | return nrow, ncol |
|
1663 | 1894 | |
|
1664 | 1895 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1665 | 1896 | |
|
1666 | 1897 | self.__showprofile = showprofile |
|
1667 | 1898 | self.nplots = nplots |
|
1668 | 1899 | |
|
1669 | 1900 | ncolspan = 7 |
|
1670 | 1901 | colspan = 6 |
|
1671 | 1902 | self.__nsubplots = 2 |
|
1672 | 1903 | |
|
1673 | 1904 | self.createFigure(id = id, |
|
1674 | 1905 | wintitle = wintitle, |
|
1675 | 1906 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1676 | 1907 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1677 | 1908 | show=show) |
|
1678 | 1909 | |
|
1679 | 1910 | nrow, ncol = self.getSubplots() |
|
1680 | 1911 | |
|
1681 | 1912 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1682 | 1913 | |
|
1683 | 1914 | |
|
1684 | 1915 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1685 | 1916 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1686 | 1917 | timerange=None, |
|
1687 | 1918 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1688 | 1919 | server=None, folder=None, username=None, password=None, |
|
1689 | 1920 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1690 | 1921 | |
|
1691 | 1922 | |
|
1692 | 1923 | tmin = None |
|
1693 | 1924 | tmax = None |
|
1694 | 1925 | x = dataOut.getTimeRange1(dataOut.outputInterval) |
|
1695 | 1926 | y = dataOut.getHeiRange() |
|
1696 | 1927 | |
|
1697 | 1928 | |
|
1698 | 1929 | #thisDatetime = dataOut.datatime |
|
1699 | 1930 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
1700 | 1931 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1701 | 1932 | xlabel = "Local Time" |
|
1702 | 1933 | ylabel = "Phase" |
|
1703 | 1934 | |
|
1704 | 1935 | |
|
1705 | 1936 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1706 | 1937 | phase_beacon = dataOut.data_output |
|
1707 | 1938 | update_figfile = False |
|
1708 | 1939 | |
|
1709 | 1940 | if not self.isConfig: |
|
1710 | 1941 | |
|
1711 | 1942 | self.nplots = phase_beacon.size |
|
1712 | 1943 | |
|
1713 | 1944 | self.setup(id=id, |
|
1714 | 1945 | nplots=self.nplots, |
|
1715 | 1946 | wintitle=wintitle, |
|
1716 | 1947 | showprofile=showprofile, |
|
1717 | 1948 | show=show) |
|
1718 | 1949 | |
|
1719 | 1950 | if timerange is not None: |
|
1720 | 1951 | self.timerange = timerange |
|
1721 | 1952 | |
|
1722 | 1953 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1723 | 1954 | |
|
1724 | 1955 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1725 | 1956 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1726 | 1957 | |
|
1727 | 1958 | self.FTP_WEI = ftp_wei |
|
1728 | 1959 | self.EXP_CODE = exp_code |
|
1729 | 1960 | self.SUB_EXP_CODE = sub_exp_code |
|
1730 | 1961 | self.PLOT_POS = plot_pos |
|
1731 | 1962 | |
|
1732 | 1963 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1733 | 1964 | self.isConfig = True |
|
1734 | 1965 | self.figfile = figfile |
|
1735 | 1966 | self.xdata = numpy.array([]) |
|
1736 | 1967 | self.ydata = numpy.array([]) |
|
1737 | 1968 | |
|
1738 | 1969 | #open file beacon phase |
|
1739 | 1970 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1740 | 1971 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1741 | 1972 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1742 | 1973 | update_figfile = True |
|
1743 | 1974 | |
|
1744 | 1975 | |
|
1745 | 1976 | #store data beacon phase |
|
1746 | 1977 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1747 | 1978 | |
|
1748 | 1979 | self.setWinTitle(title) |
|
1749 | 1980 | |
|
1750 | 1981 | |
|
1751 | 1982 | title = "Phase Offset %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1752 | 1983 | |
|
1753 | 1984 | legendlabels = ["phase %d"%(chan) for chan in numpy.arange(self.nplots)] |
|
1754 | 1985 | |
|
1755 | 1986 | axes = self.axesList[0] |
|
1756 | 1987 | |
|
1757 | 1988 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1758 | 1989 | |
|
1759 | 1990 | if len(self.ydata)==0: |
|
1760 | 1991 | self.ydata = phase_beacon.reshape(-1,1) |
|
1761 | 1992 | else: |
|
1762 | 1993 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1763 | 1994 | |
|
1764 | 1995 | |
|
1765 | 1996 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1766 | 1997 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1767 | 1998 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1768 | 1999 | XAxisAsTime=True, grid='both' |
|
1769 | 2000 | ) |
|
1770 | 2001 | |
|
1771 | 2002 | self.draw() |
|
1772 | 2003 | |
|
1773 | 2004 | self.save(figpath=figpath, |
|
1774 | 2005 | figfile=figfile, |
|
1775 | 2006 | save=save, |
|
1776 | 2007 | ftp=ftp, |
|
1777 | 2008 | wr_period=wr_period, |
|
1778 | 2009 | thisDatetime=thisDatetime, |
|
1779 | 2010 | update_figfile=update_figfile) |
|
1780 | 2011 | |
|
1781 | 2012 | if dataOut.ltctime + dataOut.outputInterval >= self.xmax: |
|
1782 | 2013 | self.counter_imagwr = wr_period |
|
1783 | 2014 | self.isConfig = False |
|
1784 | 2015 | update_figfile = True |
|
1785 | 2016 | |
|
1786 | 2017 | |
|
1787 | 2018 | |
|
1788 | class NSMeteorDetection1Plot(Figure): | |
|
2019 | class NSMeteorDetection1Plot_(Figure): | |
|
1789 | 2020 | |
|
1790 | 2021 | isConfig = None |
|
1791 | 2022 | __nsubplots = None |
|
1792 | 2023 | |
|
1793 | 2024 | WIDTHPROF = None |
|
1794 | 2025 | HEIGHTPROF = None |
|
1795 | 2026 | PREFIX = 'nsm' |
|
1796 | 2027 | |
|
1797 | 2028 | zminList = None |
|
1798 | 2029 | zmaxList = None |
|
1799 | 2030 | cmapList = None |
|
1800 | 2031 | titleList = None |
|
1801 | 2032 | nPairs = None |
|
1802 | 2033 | nChannels = None |
|
1803 | 2034 | nParam = None |
|
1804 | 2035 | |
|
1805 | 2036 | def __init__(self, **kwargs): |
|
1806 | 2037 | Figure.__init__(self, **kwargs) |
|
1807 | 2038 | self.isConfig = False |
|
1808 | 2039 | self.__nsubplots = 1 |
|
1809 | 2040 | |
|
1810 | 2041 | self.WIDTH = 750 |
|
1811 | 2042 | self.HEIGHT = 250 |
|
1812 | 2043 | self.WIDTHPROF = 120 |
|
1813 | 2044 | self.HEIGHTPROF = 0 |
|
1814 | 2045 | self.counter_imagwr = 0 |
|
1815 | 2046 | |
|
1816 | 2047 | self.PLOT_CODE = SPEC_CODE |
|
1817 | 2048 | |
|
1818 | 2049 | self.FTP_WEI = None |
|
1819 | 2050 | self.EXP_CODE = None |
|
1820 | 2051 | self.SUB_EXP_CODE = None |
|
1821 | 2052 | self.PLOT_POS = None |
|
1822 | 2053 | |
|
1823 | 2054 | self.__xfilter_ena = False |
|
1824 | 2055 | self.__yfilter_ena = False |
|
1825 | 2056 | |
|
1826 | 2057 | def getSubplots(self): |
|
1827 | 2058 | |
|
1828 | 2059 | ncol = 3 |
|
1829 | 2060 | nrow = int(numpy.ceil(self.nplots/3.0)) |
|
1830 | 2061 | |
|
1831 | 2062 | return nrow, ncol |
|
1832 | 2063 | |
|
1833 | 2064 | def setup(self, id, nplots, wintitle, show=True): |
|
1834 | 2065 | |
|
1835 | 2066 | self.nplots = nplots |
|
1836 | 2067 | |
|
1837 | 2068 | ncolspan = 1 |
|
1838 | 2069 | colspan = 1 |
|
1839 | 2070 | |
|
1840 | 2071 | self.createFigure(id = id, |
|
1841 | 2072 | wintitle = wintitle, |
|
1842 | 2073 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1843 | 2074 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1844 | 2075 | show=show) |
|
1845 | 2076 | |
|
1846 | 2077 | nrow, ncol = self.getSubplots() |
|
1847 | 2078 | |
|
1848 | 2079 | counter = 0 |
|
1849 | 2080 | for y in range(nrow): |
|
1850 | 2081 | for x in range(ncol): |
|
1851 | 2082 | |
|
1852 | 2083 | if counter >= self.nplots: |
|
1853 | 2084 | break |
|
1854 | 2085 | |
|
1855 | 2086 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1856 | 2087 | |
|
1857 | 2088 | counter += 1 |
|
1858 | 2089 | |
|
1859 | 2090 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
1860 | 2091 | xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None, |
|
1861 | 2092 | vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA', |
|
1862 | 2093 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1863 | 2094 | server=None, folder=None, username=None, password=None, |
|
1864 | 2095 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
1865 | 2096 | xaxis="frequency"): |
|
1866 | 2097 | |
|
1867 | 2098 | """ |
|
1868 | 2099 | |
|
1869 | 2100 | Input: |
|
1870 | 2101 | dataOut : |
|
1871 | 2102 | id : |
|
1872 | 2103 | wintitle : |
|
1873 | 2104 | channelList : |
|
1874 | 2105 | showProfile : |
|
1875 | 2106 | xmin : None, |
|
1876 | 2107 | xmax : None, |
|
1877 | 2108 | ymin : None, |
|
1878 | 2109 | ymax : None, |
|
1879 | 2110 | zmin : None, |
|
1880 | 2111 | zmax : None |
|
1881 | 2112 | """ |
|
1882 | 2113 | #SEPARAR EN DOS PLOTS |
|
1883 | 2114 | nParam = dataOut.data_param.shape[1] - 3 |
|
1884 | 2115 | |
|
1885 | 2116 | utctime = dataOut.data_param[0,0] |
|
1886 | 2117 | tmet = dataOut.data_param[:,1].astype(int) |
|
1887 | 2118 | hmet = dataOut.data_param[:,2].astype(int) |
|
1888 | 2119 | |
|
1889 | 2120 | x = dataOut.abscissaList |
|
1890 | 2121 | y = dataOut.heightList |
|
1891 | 2122 | |
|
1892 | 2123 | z = numpy.zeros((nParam, y.size, x.size - 1)) |
|
1893 | 2124 | z[:,:] = numpy.nan |
|
1894 | 2125 | z[:,hmet,tmet] = dataOut.data_param[:,3:].T |
|
1895 | 2126 | z[0,:,:] = 10*numpy.log10(z[0,:,:]) |
|
1896 | 2127 | |
|
1897 | 2128 | xlabel = "Time (s)" |
|
1898 | 2129 | ylabel = "Range (km)" |
|
1899 | 2130 | |
|
1900 | 2131 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
1901 | 2132 | |
|
1902 | 2133 | if not self.isConfig: |
|
1903 | 2134 | |
|
1904 | 2135 | nplots = nParam |
|
1905 | 2136 | |
|
1906 | 2137 | self.setup(id=id, |
|
1907 | 2138 | nplots=nplots, |
|
1908 | 2139 | wintitle=wintitle, |
|
1909 | 2140 | show=show) |
|
1910 | 2141 | |
|
1911 | 2142 | if xmin is None: xmin = numpy.nanmin(x) |
|
1912 | 2143 | if xmax is None: xmax = numpy.nanmax(x) |
|
1913 | 2144 | if ymin is None: ymin = numpy.nanmin(y) |
|
1914 | 2145 | if ymax is None: ymax = numpy.nanmax(y) |
|
1915 | 2146 | if SNRmin is None: SNRmin = numpy.nanmin(z[0,:]) |
|
1916 | 2147 | if SNRmax is None: SNRmax = numpy.nanmax(z[0,:]) |
|
1917 | 2148 | if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:])) |
|
1918 | 2149 | if vmin is None: vmin = -vmax |
|
1919 | 2150 | if wmin is None: wmin = 0 |
|
1920 | 2151 | if wmax is None: wmax = 50 |
|
1921 | 2152 | |
|
1922 | 2153 | pairsList = dataOut.groupList |
|
1923 | 2154 | self.nPairs = len(dataOut.groupList) |
|
1924 | 2155 | |
|
1925 | 2156 | zminList = [SNRmin, vmin, cmin] + [pmin]*self.nPairs |
|
1926 | 2157 | zmaxList = [SNRmax, vmax, cmax] + [pmax]*self.nPairs |
|
1927 | 2158 | titleList = ["SNR","Radial Velocity","Coherence"] |
|
1928 | 2159 | cmapList = ["jet","RdBu_r","jet"] |
|
1929 | 2160 | |
|
1930 | 2161 | for i in range(self.nPairs): |
|
1931 | 2162 | strAux1 = "Phase Difference "+ str(pairsList[i][0]) + str(pairsList[i][1]) |
|
1932 | 2163 | titleList = titleList + [strAux1] |
|
1933 | 2164 | cmapList = cmapList + ["RdBu_r"] |
|
1934 | 2165 | |
|
1935 | 2166 | self.zminList = zminList |
|
1936 | 2167 | self.zmaxList = zmaxList |
|
1937 | 2168 | self.cmapList = cmapList |
|
1938 | 2169 | self.titleList = titleList |
|
1939 | 2170 | |
|
1940 | 2171 | self.FTP_WEI = ftp_wei |
|
1941 | 2172 | self.EXP_CODE = exp_code |
|
1942 | 2173 | self.SUB_EXP_CODE = sub_exp_code |
|
1943 | 2174 | self.PLOT_POS = plot_pos |
|
1944 | 2175 | |
|
1945 | 2176 | self.isConfig = True |
|
1946 | 2177 | |
|
1947 | 2178 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
1948 | 2179 | |
|
1949 | 2180 | for i in range(nParam): |
|
1950 | 2181 | title = self.titleList[i] + ": " +str_datetime |
|
1951 | 2182 | axes = self.axesList[i] |
|
1952 | 2183 | axes.pcolor(x, y, z[i,:].T, |
|
1953 | 2184 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i], |
|
1954 | 2185 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='') |
|
1955 | 2186 | self.draw() |
|
1956 | 2187 | |
|
1957 | 2188 | if figfile == None: |
|
1958 | 2189 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1959 | 2190 | name = str_datetime |
|
1960 | 2191 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
1961 | 2192 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
1962 | 2193 | figfile = self.getFilename(name) |
|
1963 | 2194 | |
|
1964 | 2195 | self.save(figpath=figpath, |
|
1965 | 2196 | figfile=figfile, |
|
1966 | 2197 | save=save, |
|
1967 | 2198 | ftp=ftp, |
|
1968 | 2199 | wr_period=wr_period, |
|
1969 | 2200 | thisDatetime=thisDatetime) |
|
1970 | 2201 | |
|
1971 | 2202 | |
|
1972 | class NSMeteorDetection2Plot(Figure): | |
|
2203 | class NSMeteorDetection2Plot_(Figure): | |
|
1973 | 2204 | |
|
1974 | 2205 | isConfig = None |
|
1975 | 2206 | __nsubplots = None |
|
1976 | 2207 | |
|
1977 | 2208 | WIDTHPROF = None |
|
1978 | 2209 | HEIGHTPROF = None |
|
1979 | 2210 | PREFIX = 'nsm' |
|
1980 | 2211 | |
|
1981 | 2212 | zminList = None |
|
1982 | 2213 | zmaxList = None |
|
1983 | 2214 | cmapList = None |
|
1984 | 2215 | titleList = None |
|
1985 | 2216 | nPairs = None |
|
1986 | 2217 | nChannels = None |
|
1987 | 2218 | nParam = None |
|
1988 | 2219 | |
|
1989 | 2220 | def __init__(self, **kwargs): |
|
1990 | 2221 | Figure.__init__(self, **kwargs) |
|
1991 | 2222 | self.isConfig = False |
|
1992 | 2223 | self.__nsubplots = 1 |
|
1993 | 2224 | |
|
1994 | 2225 | self.WIDTH = 750 |
|
1995 | 2226 | self.HEIGHT = 250 |
|
1996 | 2227 | self.WIDTHPROF = 120 |
|
1997 | 2228 | self.HEIGHTPROF = 0 |
|
1998 | 2229 | self.counter_imagwr = 0 |
|
1999 | 2230 | |
|
2000 | 2231 | self.PLOT_CODE = SPEC_CODE |
|
2001 | 2232 | |
|
2002 | 2233 | self.FTP_WEI = None |
|
2003 | 2234 | self.EXP_CODE = None |
|
2004 | 2235 | self.SUB_EXP_CODE = None |
|
2005 | 2236 | self.PLOT_POS = None |
|
2006 | 2237 | |
|
2007 | 2238 | self.__xfilter_ena = False |
|
2008 | 2239 | self.__yfilter_ena = False |
|
2009 | 2240 | |
|
2010 | 2241 | def getSubplots(self): |
|
2011 | 2242 | |
|
2012 | 2243 | ncol = 3 |
|
2013 | 2244 | nrow = int(numpy.ceil(self.nplots/3.0)) |
|
2014 | 2245 | |
|
2015 | 2246 | return nrow, ncol |
|
2016 | 2247 | |
|
2017 | 2248 | def setup(self, id, nplots, wintitle, show=True): |
|
2018 | 2249 | |
|
2019 | 2250 | self.nplots = nplots |
|
2020 | 2251 | |
|
2021 | 2252 | ncolspan = 1 |
|
2022 | 2253 | colspan = 1 |
|
2023 | 2254 | |
|
2024 | 2255 | self.createFigure(id = id, |
|
2025 | 2256 | wintitle = wintitle, |
|
2026 | 2257 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
2027 | 2258 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
2028 | 2259 | show=show) |
|
2029 | 2260 | |
|
2030 | 2261 | nrow, ncol = self.getSubplots() |
|
2031 | 2262 | |
|
2032 | 2263 | counter = 0 |
|
2033 | 2264 | for y in range(nrow): |
|
2034 | 2265 | for x in range(ncol): |
|
2035 | 2266 | |
|
2036 | 2267 | if counter >= self.nplots: |
|
2037 | 2268 | break |
|
2038 | 2269 | |
|
2039 | 2270 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
2040 | 2271 | |
|
2041 | 2272 | counter += 1 |
|
2042 | 2273 | |
|
2043 | 2274 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
2044 | 2275 | xmin=None, xmax=None, ymin=None, ymax=None, SNRmin=None, SNRmax=None, |
|
2045 | 2276 | vmin=None, vmax=None, wmin=None, wmax=None, mode = 'SA', |
|
2046 | 2277 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
2047 | 2278 | server=None, folder=None, username=None, password=None, |
|
2048 | 2279 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
2049 | 2280 | xaxis="frequency"): |
|
2050 | 2281 | |
|
2051 | 2282 | """ |
|
2052 | 2283 | |
|
2053 | 2284 | Input: |
|
2054 | 2285 | dataOut : |
|
2055 | 2286 | id : |
|
2056 | 2287 | wintitle : |
|
2057 | 2288 | channelList : |
|
2058 | 2289 | showProfile : |
|
2059 | 2290 | xmin : None, |
|
2060 | 2291 | xmax : None, |
|
2061 | 2292 | ymin : None, |
|
2062 | 2293 | ymax : None, |
|
2063 | 2294 | zmin : None, |
|
2064 | 2295 | zmax : None |
|
2065 | 2296 | """ |
|
2066 | 2297 | #Rebuild matrix |
|
2067 | 2298 | utctime = dataOut.data_param[0,0] |
|
2068 | 2299 | cmet = dataOut.data_param[:,1].astype(int) |
|
2069 | 2300 | tmet = dataOut.data_param[:,2].astype(int) |
|
2070 | 2301 | hmet = dataOut.data_param[:,3].astype(int) |
|
2071 | 2302 | |
|
2072 | 2303 | nParam = 3 |
|
2073 | 2304 | nChan = len(dataOut.groupList) |
|
2074 | 2305 | x = dataOut.abscissaList |
|
2075 | 2306 | y = dataOut.heightList |
|
2076 | 2307 | |
|
2077 | 2308 | z = numpy.full((nChan, nParam, y.size, x.size - 1),numpy.nan) |
|
2078 | 2309 | z[cmet,:,hmet,tmet] = dataOut.data_param[:,4:] |
|
2079 | 2310 | z[:,0,:,:] = 10*numpy.log10(z[:,0,:,:]) #logarithmic scale |
|
2080 | 2311 | z = numpy.reshape(z, (nChan*nParam, y.size, x.size-1)) |
|
2081 | 2312 | |
|
2082 | 2313 | xlabel = "Time (s)" |
|
2083 | 2314 | ylabel = "Range (km)" |
|
2084 | 2315 | |
|
2085 | 2316 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.ltctime) |
|
2086 | 2317 | |
|
2087 | 2318 | if not self.isConfig: |
|
2088 | 2319 | |
|
2089 | 2320 | nplots = nParam*nChan |
|
2090 | 2321 | |
|
2091 | 2322 | self.setup(id=id, |
|
2092 | 2323 | nplots=nplots, |
|
2093 | 2324 | wintitle=wintitle, |
|
2094 | 2325 | show=show) |
|
2095 | 2326 | |
|
2096 | 2327 | if xmin is None: xmin = numpy.nanmin(x) |
|
2097 | 2328 | if xmax is None: xmax = numpy.nanmax(x) |
|
2098 | 2329 | if ymin is None: ymin = numpy.nanmin(y) |
|
2099 | 2330 | if ymax is None: ymax = numpy.nanmax(y) |
|
2100 | 2331 | if SNRmin is None: SNRmin = numpy.nanmin(z[0,:]) |
|
2101 | 2332 | if SNRmax is None: SNRmax = numpy.nanmax(z[0,:]) |
|
2102 | 2333 | if vmax is None: vmax = numpy.nanmax(numpy.abs(z[1,:])) |
|
2103 | 2334 | if vmin is None: vmin = -vmax |
|
2104 | 2335 | if wmin is None: wmin = 0 |
|
2105 | 2336 | if wmax is None: wmax = 50 |
|
2106 | 2337 | |
|
2107 | 2338 | self.nChannels = nChan |
|
2108 | 2339 | |
|
2109 | 2340 | zminList = [] |
|
2110 | 2341 | zmaxList = [] |
|
2111 | 2342 | titleList = [] |
|
2112 | 2343 | cmapList = [] |
|
2113 | 2344 | for i in range(self.nChannels): |
|
2114 | 2345 | strAux1 = "SNR Channel "+ str(i) |
|
2115 | 2346 | strAux2 = "Radial Velocity Channel "+ str(i) |
|
2116 | 2347 | strAux3 = "Spectral Width Channel "+ str(i) |
|
2117 | 2348 | |
|
2118 | 2349 | titleList = titleList + [strAux1,strAux2,strAux3] |
|
2119 | 2350 | cmapList = cmapList + ["jet","RdBu_r","jet"] |
|
2120 | 2351 | zminList = zminList + [SNRmin,vmin,wmin] |
|
2121 | 2352 | zmaxList = zmaxList + [SNRmax,vmax,wmax] |
|
2122 | 2353 | |
|
2123 | 2354 | self.zminList = zminList |
|
2124 | 2355 | self.zmaxList = zmaxList |
|
2125 | 2356 | self.cmapList = cmapList |
|
2126 | 2357 | self.titleList = titleList |
|
2127 | 2358 | |
|
2128 | 2359 | self.FTP_WEI = ftp_wei |
|
2129 | 2360 | self.EXP_CODE = exp_code |
|
2130 | 2361 | self.SUB_EXP_CODE = sub_exp_code |
|
2131 | 2362 | self.PLOT_POS = plot_pos |
|
2132 | 2363 | |
|
2133 | 2364 | self.isConfig = True |
|
2134 | 2365 | |
|
2135 | 2366 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
2136 | 2367 | |
|
2137 | 2368 | for i in range(self.nplots): |
|
2138 | 2369 | title = self.titleList[i] + ": " +str_datetime |
|
2139 | 2370 | axes = self.axesList[i] |
|
2140 | 2371 | axes.pcolor(x, y, z[i,:].T, |
|
2141 | 2372 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=self.zminList[i], zmax=self.zmaxList[i], |
|
2142 | 2373 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=self.cmapList[i],ticksize=9, cblabel='') |
|
2143 | 2374 | self.draw() |
|
2144 | 2375 | |
|
2145 | 2376 | if figfile == None: |
|
2146 | 2377 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
2147 | 2378 | name = str_datetime |
|
2148 | 2379 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
2149 | 2380 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
2150 | 2381 | figfile = self.getFilename(name) |
|
2151 | 2382 | |
|
2152 | 2383 | self.save(figpath=figpath, |
|
2153 | 2384 | figfile=figfile, |
|
2154 | 2385 | save=save, |
|
2155 | 2386 | ftp=ftp, |
|
2156 | 2387 | wr_period=wr_period, |
|
2157 | 2388 | thisDatetime=thisDatetime) |
|
2158 | 2389 | No newline at end of file |
@@ -1,1587 +1,1588 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 9, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | |
|
10 | 10 | from .figure import Figure, isRealtime, isTimeInHourRange |
|
11 | 11 | from .plotting_codes import * |
|
12 | 12 | from schainpy.model.proc.jroproc_base import MPDecorator |
|
13 | 13 | |
|
14 | 14 | from schainpy.utils import log |
|
15 | 15 | |
|
16 | 16 | @MPDecorator |
|
17 | class SpectraPlot(Figure): | |
|
17 | class SpectraPlot_(Figure): | |
|
18 | 18 | |
|
19 | 19 | isConfig = None |
|
20 | 20 | __nsubplots = None |
|
21 | 21 | |
|
22 | 22 | WIDTHPROF = None |
|
23 | 23 | HEIGHTPROF = None |
|
24 | 24 | PREFIX = 'spc' |
|
25 | 25 | |
|
26 | 26 | def __init__(self): |
|
27 | 27 | Figure.__init__(self) |
|
28 | 28 | self.isConfig = False |
|
29 | 29 | self.__nsubplots = 1 |
|
30 | 30 | self.WIDTH = 250 |
|
31 | 31 | self.HEIGHT = 250 |
|
32 | 32 | self.WIDTHPROF = 120 |
|
33 | 33 | self.HEIGHTPROF = 0 |
|
34 | 34 | self.counter_imagwr = 0 |
|
35 | 35 | |
|
36 | 36 | self.PLOT_CODE = SPEC_CODE |
|
37 | 37 | |
|
38 | 38 | self.FTP_WEI = None |
|
39 | 39 | self.EXP_CODE = None |
|
40 | 40 | self.SUB_EXP_CODE = None |
|
41 | 41 | self.PLOT_POS = None |
|
42 | 42 | |
|
43 | 43 | self.__xfilter_ena = False |
|
44 | 44 | self.__yfilter_ena = False |
|
45 | ||
|
46 | self.indice=1 | |
|
45 | 47 | |
|
46 | 48 | def getSubplots(self): |
|
47 | 49 | |
|
48 | 50 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
49 | 51 | nrow = int(self.nplots*1./ncol + 0.9) |
|
50 | 52 | |
|
51 | 53 | return nrow, ncol |
|
52 | 54 | |
|
53 | 55 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
54 | 56 | |
|
55 | 57 | self.__showprofile = showprofile |
|
56 | 58 | self.nplots = nplots |
|
57 | 59 | |
|
58 | 60 | ncolspan = 1 |
|
59 | 61 | colspan = 1 |
|
60 | 62 | if showprofile: |
|
61 | 63 | ncolspan = 3 |
|
62 | 64 | colspan = 2 |
|
63 | 65 | self.__nsubplots = 2 |
|
64 | 66 | |
|
65 | 67 | self.createFigure(id = id, |
|
66 | 68 | wintitle = wintitle, |
|
67 | 69 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
68 | 70 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
69 | 71 | show=show) |
|
70 | 72 | |
|
71 | 73 | nrow, ncol = self.getSubplots() |
|
72 | 74 | |
|
73 | 75 | counter = 0 |
|
74 | 76 | for y in range(nrow): |
|
75 | 77 | for x in range(ncol): |
|
76 | 78 | |
|
77 | 79 | if counter >= self.nplots: |
|
78 | 80 | break |
|
79 | 81 | |
|
80 | 82 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
81 | 83 | |
|
82 | 84 | if showprofile: |
|
83 | 85 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
84 | 86 | |
|
85 | 87 | counter += 1 |
|
86 | 88 | |
|
87 | 89 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
88 | 90 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
89 | 91 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
90 | 92 | server=None, folder=None, username=None, password=None, |
|
91 | 93 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False, |
|
92 | 94 | xaxis="frequency", colormap='jet', normFactor=None): |
|
93 | 95 | |
|
94 | 96 | """ |
|
95 | 97 | |
|
96 | 98 | Input: |
|
97 | 99 | dataOut : |
|
98 | 100 | id : |
|
99 | 101 | wintitle : |
|
100 | 102 | channelList : |
|
101 | 103 | showProfile : |
|
102 | 104 | xmin : None, |
|
103 | 105 | xmax : None, |
|
104 | 106 | ymin : None, |
|
105 | 107 | ymax : None, |
|
106 | 108 | zmin : None, |
|
107 | 109 | zmax : None |
|
108 | 110 | """ |
|
109 | 111 | if dataOut.flagNoData: |
|
110 | 112 | return dataOut |
|
111 | 113 | |
|
112 | 114 | if realtime: |
|
113 | 115 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
114 | 116 | print('Skipping this plot function') |
|
115 | 117 | return |
|
116 | 118 | |
|
117 | 119 | if channelList == None: |
|
118 | 120 | channelIndexList = dataOut.channelIndexList |
|
119 | 121 | else: |
|
120 | 122 | channelIndexList = [] |
|
121 | 123 | for channel in channelList: |
|
122 | 124 | if channel not in dataOut.channelList: |
|
123 | 125 | raise ValueError("Channel %d is not in dataOut.channelList" %channel) |
|
124 | 126 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
125 | 127 | |
|
126 | 128 | if normFactor is None: |
|
127 | 129 | factor = dataOut.normFactor |
|
128 | 130 | else: |
|
129 | 131 | factor = normFactor |
|
130 | 132 | if xaxis == "frequency": |
|
131 | 133 | x = dataOut.getFreqRange(1)/1000. |
|
132 | 134 | xlabel = "Frequency (kHz)" |
|
133 | 135 | |
|
134 | 136 | elif xaxis == "time": |
|
135 | 137 | x = dataOut.getAcfRange(1) |
|
136 | 138 | xlabel = "Time (ms)" |
|
137 | 139 | |
|
138 | 140 | else: |
|
139 | 141 | x = dataOut.getVelRange(1) |
|
140 | 142 | xlabel = "Velocity (m/s)" |
|
141 | 143 | |
|
142 |
ylabel = "Range ( |
|
|
144 | ylabel = "Range (km)" | |
|
143 | 145 | |
|
144 | 146 | y = dataOut.getHeiRange() |
|
145 | ||
|
146 | 147 | z = dataOut.data_spc/factor |
|
147 | 148 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
148 | 149 | zdB = 10*numpy.log10(z) |
|
149 | 150 | |
|
150 | 151 | avg = numpy.average(z, axis=1) |
|
151 | 152 | avgdB = 10*numpy.log10(avg) |
|
152 | 153 | |
|
153 | 154 | noise = dataOut.getNoise()/factor |
|
154 | 155 | noisedB = 10*numpy.log10(noise) |
|
155 | 156 | |
|
156 | 157 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
157 | 158 | title = wintitle + " Spectra" |
|
159 | ||
|
158 | 160 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
159 | 161 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
160 | 162 | |
|
161 | 163 | if not self.isConfig: |
|
162 | 164 | |
|
163 | 165 | nplots = len(channelIndexList) |
|
164 | 166 | |
|
165 | 167 | self.setup(id=id, |
|
166 | 168 | nplots=nplots, |
|
167 | 169 | wintitle=wintitle, |
|
168 | 170 | showprofile=showprofile, |
|
169 | 171 | show=show) |
|
170 | 172 | |
|
171 | 173 | if xmin == None: xmin = numpy.nanmin(x) |
|
172 | 174 | if xmax == None: xmax = numpy.nanmax(x) |
|
173 | 175 | if ymin == None: ymin = numpy.nanmin(y) |
|
174 | 176 | if ymax == None: ymax = numpy.nanmax(y) |
|
175 | 177 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
176 | 178 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
177 | 179 | |
|
178 | 180 | self.FTP_WEI = ftp_wei |
|
179 | 181 | self.EXP_CODE = exp_code |
|
180 | 182 | self.SUB_EXP_CODE = sub_exp_code |
|
181 | 183 | self.PLOT_POS = plot_pos |
|
182 | 184 | |
|
183 | 185 | self.isConfig = True |
|
184 | 186 | |
|
185 | 187 | self.setWinTitle(title) |
|
186 | 188 | |
|
187 | 189 | for i in range(self.nplots): |
|
188 | 190 | index = channelIndexList[i] |
|
189 | 191 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
190 | 192 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[index], noisedB[index], str_datetime) |
|
191 | 193 | if len(dataOut.beam.codeList) != 0: |
|
192 | 194 | title = "Ch%d:%4.2fdB,%2.2f,%2.2f:%s" %(dataOut.channelList[index], noisedB[index], dataOut.beam.azimuthList[index], dataOut.beam.zenithList[index], str_datetime) |
|
193 | 195 | |
|
194 | 196 | axes = self.axesList[i*self.__nsubplots] |
|
195 | 197 | axes.pcolor(x, y, zdB[index,:,:], |
|
196 | 198 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
197 | 199 | xlabel=xlabel, ylabel=ylabel, title=title, colormap=colormap, |
|
198 | 200 | ticksize=9, cblabel='') |
|
199 | 201 | |
|
200 | 202 | if self.__showprofile: |
|
201 | 203 | axes = self.axesList[i*self.__nsubplots +1] |
|
202 | 204 | axes.pline(avgdB[index,:], y, |
|
203 | 205 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
204 | 206 | xlabel='dB', ylabel='', title='', |
|
205 | 207 | ytick_visible=False, |
|
206 | 208 | grid='x') |
|
207 | 209 | |
|
208 | 210 | noiseline = numpy.repeat(noisedB[index], len(y)) |
|
209 | 211 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
210 | 212 | |
|
211 | 213 | self.draw() |
|
212 | 214 | |
|
213 | 215 | if figfile == None: |
|
214 | 216 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
215 | 217 | name = str_datetime |
|
216 | 218 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
217 | 219 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) |
|
218 | 220 | figfile = self.getFilename(name) |
|
219 | 221 | |
|
220 | 222 | self.save(figpath=figpath, |
|
221 | 223 | figfile=figfile, |
|
222 | 224 | save=save, |
|
223 | 225 | ftp=ftp, |
|
224 | 226 | wr_period=wr_period, |
|
225 | 227 | thisDatetime=thisDatetime) |
|
228 | ||
|
226 | 229 | |
|
227 | 230 | return dataOut |
|
228 | 231 | @MPDecorator |
|
229 | class CrossSpectraPlot(Figure): | |
|
232 | class CrossSpectraPlot_(Figure): | |
|
230 | 233 | |
|
231 | 234 | isConfig = None |
|
232 | 235 | __nsubplots = None |
|
233 | 236 | |
|
234 | 237 | WIDTH = None |
|
235 | 238 | HEIGHT = None |
|
236 | 239 | WIDTHPROF = None |
|
237 | 240 | HEIGHTPROF = None |
|
238 | 241 | PREFIX = 'cspc' |
|
239 | 242 | |
|
240 | 243 | def __init__(self): |
|
241 | 244 | Figure.__init__(self) |
|
242 | 245 | self.isConfig = False |
|
243 | 246 | self.__nsubplots = 4 |
|
244 | 247 | self.counter_imagwr = 0 |
|
245 | 248 | self.WIDTH = 250 |
|
246 | 249 | self.HEIGHT = 250 |
|
247 | 250 | self.WIDTHPROF = 0 |
|
248 | 251 | self.HEIGHTPROF = 0 |
|
249 | 252 | |
|
250 | 253 | self.PLOT_CODE = CROSS_CODE |
|
251 | 254 | self.FTP_WEI = None |
|
252 | 255 | self.EXP_CODE = None |
|
253 | 256 | self.SUB_EXP_CODE = None |
|
254 | 257 | self.PLOT_POS = None |
|
258 | ||
|
259 | self.indice=0 | |
|
255 | 260 | |
|
256 | 261 | def getSubplots(self): |
|
257 | 262 | |
|
258 | 263 | ncol = 4 |
|
259 | 264 | nrow = self.nplots |
|
260 | 265 | |
|
261 | 266 | return nrow, ncol |
|
262 | 267 | |
|
263 | 268 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
264 | 269 | |
|
265 | 270 | self.__showprofile = showprofile |
|
266 | 271 | self.nplots = nplots |
|
267 | 272 | |
|
268 | 273 | ncolspan = 1 |
|
269 | 274 | colspan = 1 |
|
270 | 275 | |
|
271 | 276 | self.createFigure(id = id, |
|
272 | 277 | wintitle = wintitle, |
|
273 | 278 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
274 | 279 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
275 | 280 | show=True) |
|
276 | 281 | |
|
277 | 282 | nrow, ncol = self.getSubplots() |
|
278 | 283 | |
|
279 | 284 | counter = 0 |
|
280 | 285 | for y in range(nrow): |
|
281 | 286 | for x in range(ncol): |
|
282 | 287 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
283 | 288 | |
|
284 | 289 | counter += 1 |
|
285 | 290 | |
|
286 | 291 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
287 | 292 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
288 | 293 | coh_min=None, coh_max=None, phase_min=None, phase_max=None, |
|
289 | 294 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
290 | 295 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
291 | 296 | server=None, folder=None, username=None, password=None, |
|
292 | 297 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, |
|
293 | 298 | xaxis='frequency'): |
|
294 | 299 | |
|
295 | 300 | """ |
|
296 | 301 | |
|
297 | 302 | Input: |
|
298 | 303 | dataOut : |
|
299 | 304 | id : |
|
300 | 305 | wintitle : |
|
301 | 306 | channelList : |
|
302 | 307 | showProfile : |
|
303 | 308 | xmin : None, |
|
304 | 309 | xmax : None, |
|
305 | 310 | ymin : None, |
|
306 | 311 | ymax : None, |
|
307 | 312 | zmin : None, |
|
308 | 313 | zmax : None |
|
309 | 314 | """ |
|
310 | 315 | |
|
311 | 316 | if dataOut.flagNoData: |
|
312 | 317 | return dataOut |
|
313 | 318 | |
|
314 | 319 | if pairsList == None: |
|
315 | 320 | pairsIndexList = dataOut.pairsIndexList |
|
316 | 321 | else: |
|
317 | 322 | pairsIndexList = [] |
|
318 | 323 | for pair in pairsList: |
|
319 | 324 | if pair not in dataOut.pairsList: |
|
320 | 325 | raise ValueError("Pair %s is not in dataOut.pairsList" %str(pair)) |
|
321 | 326 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
322 | 327 | |
|
323 | 328 | if not pairsIndexList: |
|
324 | 329 | return |
|
325 | 330 | |
|
326 | 331 | if len(pairsIndexList) > 4: |
|
327 | 332 | pairsIndexList = pairsIndexList[0:4] |
|
328 | 333 | |
|
329 | 334 | if normFactor is None: |
|
330 | 335 | factor = dataOut.normFactor |
|
331 | 336 | else: |
|
332 | 337 | factor = normFactor |
|
333 | 338 | x = dataOut.getVelRange(1) |
|
334 | 339 | y = dataOut.getHeiRange() |
|
335 | 340 | z = dataOut.data_spc[:,:,:]/factor |
|
336 | 341 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
337 | 342 | |
|
338 | 343 | noise = dataOut.noise/factor |
|
339 | 344 | |
|
340 | 345 | zdB = 10*numpy.log10(z) |
|
341 | 346 | noisedB = 10*numpy.log10(noise) |
|
342 | 347 | |
|
343 | 348 | if coh_min == None: |
|
344 | 349 | coh_min = 0.0 |
|
345 | 350 | if coh_max == None: |
|
346 | 351 | coh_max = 1.0 |
|
347 | 352 | |
|
348 | 353 | if phase_min == None: |
|
349 | 354 | phase_min = -180 |
|
350 | 355 | if phase_max == None: |
|
351 | 356 | phase_max = 180 |
|
352 | 357 | |
|
353 | 358 | #thisDatetime = dataOut.datatime |
|
354 | 359 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
355 | 360 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
356 | 361 | # xlabel = "Velocity (m/s)" |
|
357 | 362 | ylabel = "Range (Km)" |
|
358 | 363 | |
|
359 | 364 | if xaxis == "frequency": |
|
360 | 365 | x = dataOut.getFreqRange(1)/1000. |
|
361 | 366 | xlabel = "Frequency (kHz)" |
|
362 | 367 | |
|
363 | 368 | elif xaxis == "time": |
|
364 | 369 | x = dataOut.getAcfRange(1) |
|
365 | 370 | xlabel = "Time (ms)" |
|
366 | 371 | |
|
367 | 372 | else: |
|
368 | 373 | x = dataOut.getVelRange(1) |
|
369 | 374 | xlabel = "Velocity (m/s)" |
|
370 | 375 | |
|
371 | 376 | if not self.isConfig: |
|
372 | 377 | |
|
373 | 378 | nplots = len(pairsIndexList) |
|
374 | 379 | |
|
375 | 380 | self.setup(id=id, |
|
376 | 381 | nplots=nplots, |
|
377 | 382 | wintitle=wintitle, |
|
378 | 383 | showprofile=False, |
|
379 | 384 | show=show) |
|
380 | 385 | |
|
381 | 386 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
382 | 387 | avgdB = 10*numpy.log10(avg) |
|
383 | 388 | |
|
384 | 389 | if xmin == None: xmin = numpy.nanmin(x) |
|
385 | 390 | if xmax == None: xmax = numpy.nanmax(x) |
|
386 | 391 | if ymin == None: ymin = numpy.nanmin(y) |
|
387 | 392 | if ymax == None: ymax = numpy.nanmax(y) |
|
388 | 393 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
389 | 394 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
390 | 395 | |
|
391 | 396 | self.FTP_WEI = ftp_wei |
|
392 | 397 | self.EXP_CODE = exp_code |
|
393 | 398 | self.SUB_EXP_CODE = sub_exp_code |
|
394 | 399 | self.PLOT_POS = plot_pos |
|
395 | 400 | |
|
396 | 401 | self.isConfig = True |
|
397 | 402 | |
|
398 | 403 | self.setWinTitle(title) |
|
404 | ||
|
399 | 405 | |
|
400 | 406 | for i in range(self.nplots): |
|
401 | 407 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
402 | 408 | |
|
403 | 409 | chan_index0 = dataOut.channelList.index(pair[0]) |
|
404 | 410 | chan_index1 = dataOut.channelList.index(pair[1]) |
|
405 | 411 | |
|
406 | 412 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
407 | 413 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[chan_index0], str_datetime) |
|
408 | 414 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index0,:,:]/factor) |
|
409 | 415 | axes0 = self.axesList[i*self.__nsubplots] |
|
410 | 416 | axes0.pcolor(x, y, zdB, |
|
411 | 417 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
412 | 418 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
413 | 419 | ticksize=9, colormap=power_cmap, cblabel='') |
|
414 | 420 | |
|
415 | 421 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[chan_index1], str_datetime) |
|
416 | 422 | zdB = 10.*numpy.log10(dataOut.data_spc[chan_index1,:,:]/factor) |
|
417 | 423 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
418 | 424 | axes0.pcolor(x, y, zdB, |
|
419 | 425 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
420 | 426 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
421 | 427 | ticksize=9, colormap=power_cmap, cblabel='') |
|
422 | 428 | |
|
423 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:]) | |
|
429 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:] / numpy.sqrt( dataOut.data_spc[chan_index0,:,:]*dataOut.data_spc[chan_index1,:,:] ) | |
|
424 | 430 | coherence = numpy.abs(coherenceComplex) |
|
425 | 431 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
426 | 432 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
427 | 433 | |
|
428 | 434 | title = "Coherence Ch%d * Ch%d" %(pair[0], pair[1]) |
|
429 | 435 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
430 | 436 | axes0.pcolor(x, y, coherence, |
|
431 | 437 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=coh_min, zmax=coh_max, |
|
432 | 438 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
433 | 439 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
434 | 440 | |
|
435 | 441 | title = "Phase Ch%d * Ch%d" %(pair[0], pair[1]) |
|
436 | 442 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
437 | 443 | axes0.pcolor(x, y, phase, |
|
438 | 444 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
439 | 445 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
440 | 446 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
441 | 447 | |
|
442 | ||
|
443 | ||
|
444 | 448 | self.draw() |
|
445 | 449 | |
|
446 | 450 | self.save(figpath=figpath, |
|
447 | 451 | figfile=figfile, |
|
448 | 452 | save=save, |
|
449 | 453 | ftp=ftp, |
|
450 | 454 | wr_period=wr_period, |
|
451 | 455 | thisDatetime=thisDatetime) |
|
452 | 456 | |
|
453 | 457 | return dataOut |
|
454 | 458 | |
|
455 | 459 | @MPDecorator |
|
456 | class RTIPlot(Figure): | |
|
460 | class RTIPlot_(Figure): | |
|
457 | 461 | |
|
458 | 462 | __isConfig = None |
|
459 | 463 | __nsubplots = None |
|
460 | 464 | |
|
461 | 465 | WIDTHPROF = None |
|
462 | 466 | HEIGHTPROF = None |
|
463 | 467 | PREFIX = 'rti' |
|
464 | 468 | |
|
465 | 469 | def __init__(self): |
|
466 | 470 | |
|
467 | 471 | Figure.__init__(self) |
|
468 | 472 | self.timerange = None |
|
469 | 473 | self.isConfig = False |
|
470 | 474 | self.__nsubplots = 1 |
|
471 | 475 | |
|
472 | 476 | self.WIDTH = 800 |
|
473 |
self.HEIGHT = |
|
|
477 | self.HEIGHT = 250 | |
|
474 | 478 | self.WIDTHPROF = 120 |
|
475 | 479 | self.HEIGHTPROF = 0 |
|
476 | 480 | self.counter_imagwr = 0 |
|
477 | 481 | |
|
478 | 482 | self.PLOT_CODE = RTI_CODE |
|
479 | 483 | |
|
480 | 484 | self.FTP_WEI = None |
|
481 | 485 | self.EXP_CODE = None |
|
482 | 486 | self.SUB_EXP_CODE = None |
|
483 | 487 | self.PLOT_POS = None |
|
484 | 488 | self.tmin = None |
|
485 | 489 | self.tmax = None |
|
486 | 490 | |
|
487 | 491 | self.xmin = None |
|
488 | 492 | self.xmax = None |
|
489 | 493 | |
|
490 | 494 | self.figfile = None |
|
491 | 495 | |
|
492 | 496 | def getSubplots(self): |
|
493 | 497 | |
|
494 | 498 | ncol = 1 |
|
495 | 499 | nrow = self.nplots |
|
496 | 500 | |
|
497 | 501 | return nrow, ncol |
|
498 | 502 | |
|
499 | 503 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
500 | 504 | |
|
501 | 505 | self.__showprofile = showprofile |
|
502 | 506 | self.nplots = nplots |
|
503 | 507 | |
|
504 | 508 | ncolspan = 1 |
|
505 | 509 | colspan = 1 |
|
506 | 510 | if showprofile: |
|
507 | 511 | ncolspan = 7 |
|
508 | 512 | colspan = 6 |
|
509 | 513 | self.__nsubplots = 2 |
|
510 | 514 | |
|
511 | 515 | self.createFigure(id = id, |
|
512 | 516 | wintitle = wintitle, |
|
513 | 517 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
514 | 518 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
515 | 519 | show=show) |
|
516 | 520 | |
|
517 | 521 | nrow, ncol = self.getSubplots() |
|
518 | 522 | |
|
519 | 523 | counter = 0 |
|
520 | 524 | for y in range(nrow): |
|
521 | 525 | for x in range(ncol): |
|
522 | 526 | |
|
523 | 527 | if counter >= self.nplots: |
|
524 | 528 | break |
|
525 | 529 | |
|
526 | 530 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
527 | 531 | |
|
528 | 532 | if showprofile: |
|
529 | 533 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
530 | 534 | |
|
531 | 535 | counter += 1 |
|
532 | 536 | |
|
533 | 537 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
534 | 538 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
535 | 539 | timerange=None, colormap='jet', |
|
536 | 540 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
537 | 541 | server=None, folder=None, username=None, password=None, |
|
538 | 542 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, normFactor=None, HEIGHT=None): |
|
539 | 543 | |
|
540 | 544 | """ |
|
541 | 545 | |
|
542 | 546 | Input: |
|
543 | 547 | dataOut : |
|
544 | 548 | id : |
|
545 | 549 | wintitle : |
|
546 | 550 | channelList : |
|
547 | 551 | showProfile : |
|
548 | 552 | xmin : None, |
|
549 | 553 | xmax : None, |
|
550 | 554 | ymin : None, |
|
551 | 555 | ymax : None, |
|
552 | 556 | zmin : None, |
|
553 | 557 | zmax : None |
|
554 | 558 | """ |
|
555 | 559 | if dataOut.flagNoData: |
|
556 | 560 | return dataOut |
|
557 | 561 | |
|
558 | 562 | #colormap = kwargs.get('colormap', 'jet') |
|
559 | 563 | if HEIGHT is not None: |
|
560 | 564 | self.HEIGHT = HEIGHT |
|
561 | 565 | |
|
562 | 566 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
563 | 567 | return |
|
564 | 568 | |
|
565 | 569 | if channelList == None: |
|
566 | 570 | channelIndexList = dataOut.channelIndexList |
|
567 | 571 | else: |
|
568 | 572 | channelIndexList = [] |
|
569 | 573 | for channel in channelList: |
|
570 | 574 | if channel not in dataOut.channelList: |
|
571 | 575 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
572 | 576 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
573 | 577 | |
|
574 | 578 | if normFactor is None: |
|
575 | 579 | factor = dataOut.normFactor |
|
576 | 580 | else: |
|
577 | 581 | factor = normFactor |
|
578 | 582 | |
|
579 | 583 | #factor = dataOut.normFactor |
|
580 | 584 | x = dataOut.getTimeRange() |
|
581 | 585 | y = dataOut.getHeiRange() |
|
582 | 586 | |
|
583 | 587 | z = dataOut.data_spc/factor |
|
584 | 588 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
585 | 589 | avg = numpy.average(z, axis=1) |
|
586 | 590 | avgdB = 10.*numpy.log10(avg) |
|
587 | 591 | # avgdB = dataOut.getPower() |
|
588 | 592 | |
|
589 | 593 | |
|
590 | 594 | thisDatetime = dataOut.datatime |
|
591 | 595 | #thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
592 | 596 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
593 | 597 | xlabel = "" |
|
594 | 598 | ylabel = "Range (Km)" |
|
595 | 599 | |
|
596 | 600 | update_figfile = False |
|
597 | 601 | |
|
598 | 602 | if self.xmax is not None and dataOut.ltctime >= self.xmax: #yong |
|
599 | 603 | self.counter_imagwr = wr_period |
|
600 | 604 | self.isConfig = False |
|
601 | 605 | update_figfile = True |
|
602 | 606 | |
|
603 | 607 | if not self.isConfig: |
|
604 | 608 | |
|
605 | 609 | nplots = len(channelIndexList) |
|
606 | 610 | |
|
607 | 611 | self.setup(id=id, |
|
608 | 612 | nplots=nplots, |
|
609 | 613 | wintitle=wintitle, |
|
610 | 614 | showprofile=showprofile, |
|
611 | 615 | show=show) |
|
612 | 616 | |
|
613 | 617 | if timerange != None: |
|
614 | 618 | self.timerange = timerange |
|
615 | 619 | |
|
616 | 620 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
617 | 621 | |
|
618 | 622 | noise = dataOut.noise/factor |
|
619 | 623 | noisedB = 10*numpy.log10(noise) |
|
620 | 624 | |
|
621 | 625 | if ymin == None: ymin = numpy.nanmin(y) |
|
622 | 626 | if ymax == None: ymax = numpy.nanmax(y) |
|
623 | 627 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 |
|
624 | 628 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 |
|
625 | 629 | |
|
626 | 630 | self.FTP_WEI = ftp_wei |
|
627 | 631 | self.EXP_CODE = exp_code |
|
628 | 632 | self.SUB_EXP_CODE = sub_exp_code |
|
629 | 633 | self.PLOT_POS = plot_pos |
|
630 | 634 | |
|
631 | 635 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
632 | 636 | self.isConfig = True |
|
633 | 637 | self.figfile = figfile |
|
634 | 638 | update_figfile = True |
|
635 | 639 | |
|
636 | 640 | self.setWinTitle(title) |
|
637 | 641 | |
|
638 | 642 | for i in range(self.nplots): |
|
639 | 643 | index = channelIndexList[i] |
|
640 | 644 | title = "Channel %d: %s" %(dataOut.channelList[index], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
641 | 645 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
642 | 646 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
643 | 647 | axes = self.axesList[i*self.__nsubplots] |
|
644 | 648 | zdB = avgdB[index].reshape((1,-1)) |
|
645 | 649 | axes.pcolorbuffer(x, y, zdB, |
|
646 | 650 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
647 | 651 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
648 | 652 | ticksize=9, cblabel='', cbsize="1%", colormap=colormap) |
|
649 | 653 | |
|
650 | 654 | if self.__showprofile: |
|
651 | 655 | axes = self.axesList[i*self.__nsubplots +1] |
|
652 | 656 | axes.pline(avgdB[index], y, |
|
653 | 657 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
654 | 658 | xlabel='dB', ylabel='', title='', |
|
655 | 659 | ytick_visible=False, |
|
656 | 660 | grid='x') |
|
657 | 661 | |
|
658 | 662 | self.draw() |
|
659 | 663 | |
|
660 | 664 | self.save(figpath=figpath, |
|
661 | 665 | figfile=figfile, |
|
662 | 666 | save=save, |
|
663 | 667 | ftp=ftp, |
|
664 | 668 | wr_period=wr_period, |
|
665 | 669 | thisDatetime=thisDatetime, |
|
666 | 670 | update_figfile=update_figfile) |
|
667 | 671 | return dataOut |
|
668 | 672 | |
|
669 | 673 | @MPDecorator |
|
670 | class CoherenceMap(Figure): | |
|
674 | class CoherenceMap_(Figure): | |
|
671 | 675 | isConfig = None |
|
672 | 676 | __nsubplots = None |
|
673 | 677 | |
|
674 | 678 | WIDTHPROF = None |
|
675 | 679 | HEIGHTPROF = None |
|
676 | 680 | PREFIX = 'cmap' |
|
677 | 681 | |
|
678 | 682 | def __init__(self): |
|
679 | 683 | Figure.__init__(self) |
|
680 | 684 | self.timerange = 2*60*60 |
|
681 | 685 | self.isConfig = False |
|
682 | 686 | self.__nsubplots = 1 |
|
683 | 687 | |
|
684 | 688 | self.WIDTH = 800 |
|
685 | 689 | self.HEIGHT = 180 |
|
686 | 690 | self.WIDTHPROF = 120 |
|
687 | 691 | self.HEIGHTPROF = 0 |
|
688 | 692 | self.counter_imagwr = 0 |
|
689 | 693 | |
|
690 | 694 | self.PLOT_CODE = COH_CODE |
|
691 | 695 | |
|
692 | 696 | self.FTP_WEI = None |
|
693 | 697 | self.EXP_CODE = None |
|
694 | 698 | self.SUB_EXP_CODE = None |
|
695 | 699 | self.PLOT_POS = None |
|
696 | 700 | self.counter_imagwr = 0 |
|
697 | 701 | |
|
698 | 702 | self.xmin = None |
|
699 | 703 | self.xmax = None |
|
700 | 704 | |
|
701 | 705 | def getSubplots(self): |
|
702 | 706 | ncol = 1 |
|
703 | 707 | nrow = self.nplots*2 |
|
704 | 708 | |
|
705 | 709 | return nrow, ncol |
|
706 | 710 | |
|
707 | 711 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
708 | 712 | self.__showprofile = showprofile |
|
709 | 713 | self.nplots = nplots |
|
710 | 714 | |
|
711 | 715 | ncolspan = 1 |
|
712 | 716 | colspan = 1 |
|
713 | 717 | if showprofile: |
|
714 | 718 | ncolspan = 7 |
|
715 | 719 | colspan = 6 |
|
716 | 720 | self.__nsubplots = 2 |
|
717 | 721 | |
|
718 | 722 | self.createFigure(id = id, |
|
719 | 723 | wintitle = wintitle, |
|
720 | 724 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
721 | 725 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
722 | 726 | show=True) |
|
723 | 727 | |
|
724 | 728 | nrow, ncol = self.getSubplots() |
|
725 | 729 | |
|
726 | 730 | for y in range(nrow): |
|
727 | 731 | for x in range(ncol): |
|
728 | 732 | |
|
729 | 733 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
730 | 734 | |
|
731 | 735 | if showprofile: |
|
732 | 736 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
733 | 737 | |
|
734 | 738 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
735 | 739 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
736 | 740 | timerange=None, phase_min=None, phase_max=None, |
|
737 | 741 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
738 | 742 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
739 | 743 | server=None, folder=None, username=None, password=None, |
|
740 | 744 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
741 | 745 | |
|
742 | 746 | |
|
743 | 747 | if dataOut.flagNoData: |
|
744 | 748 | return dataOut |
|
745 | 749 | |
|
746 | 750 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
747 | 751 | return |
|
748 | 752 | |
|
749 | 753 | if pairsList == None: |
|
750 | 754 | pairsIndexList = dataOut.pairsIndexList |
|
751 | 755 | else: |
|
752 | 756 | pairsIndexList = [] |
|
753 | 757 | for pair in pairsList: |
|
754 | 758 | if pair not in dataOut.pairsList: |
|
755 | 759 | raise ValueError("Pair %s is not in dataOut.pairsList" %(pair)) |
|
756 | 760 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
757 | 761 | |
|
758 | 762 | if pairsIndexList == []: |
|
759 | 763 | return |
|
760 | 764 | |
|
761 | 765 | if len(pairsIndexList) > 4: |
|
762 | 766 | pairsIndexList = pairsIndexList[0:4] |
|
763 | 767 | |
|
764 | 768 | if phase_min == None: |
|
765 | 769 | phase_min = -180 |
|
766 | 770 | if phase_max == None: |
|
767 | 771 | phase_max = 180 |
|
768 | 772 | |
|
769 | 773 | x = dataOut.getTimeRange() |
|
770 | 774 | y = dataOut.getHeiRange() |
|
771 | 775 | |
|
772 | 776 | thisDatetime = dataOut.datatime |
|
773 | 777 | |
|
774 | 778 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
775 | 779 | xlabel = "" |
|
776 | 780 | ylabel = "Range (Km)" |
|
777 | 781 | update_figfile = False |
|
778 | 782 | |
|
779 | 783 | if not self.isConfig: |
|
780 | 784 | nplots = len(pairsIndexList) |
|
781 | 785 | self.setup(id=id, |
|
782 | 786 | nplots=nplots, |
|
783 | 787 | wintitle=wintitle, |
|
784 | 788 | showprofile=showprofile, |
|
785 | 789 | show=show) |
|
786 | 790 | |
|
787 | 791 | if timerange != None: |
|
788 | 792 | self.timerange = timerange |
|
789 | 793 | |
|
790 | 794 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
791 | 795 | |
|
792 | 796 | if ymin == None: ymin = numpy.nanmin(y) |
|
793 | 797 | if ymax == None: ymax = numpy.nanmax(y) |
|
794 | 798 | if zmin == None: zmin = 0. |
|
795 | 799 | if zmax == None: zmax = 1. |
|
796 | 800 | |
|
797 | 801 | self.FTP_WEI = ftp_wei |
|
798 | 802 | self.EXP_CODE = exp_code |
|
799 | 803 | self.SUB_EXP_CODE = sub_exp_code |
|
800 | 804 | self.PLOT_POS = plot_pos |
|
801 | 805 | |
|
802 | 806 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
803 | 807 | |
|
804 | 808 | self.isConfig = True |
|
805 | 809 | update_figfile = True |
|
806 | 810 | |
|
807 | 811 | self.setWinTitle(title) |
|
808 | 812 | |
|
809 | 813 | for i in range(self.nplots): |
|
810 | 814 | |
|
811 | 815 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
812 | 816 | |
|
813 | 817 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
814 | 818 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
815 | 819 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
816 | 820 | |
|
817 | 821 | |
|
818 | 822 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
819 | 823 | coherence = numpy.abs(avgcoherenceComplex) |
|
820 | 824 | |
|
821 | 825 | z = coherence.reshape((1,-1)) |
|
822 | 826 | |
|
823 | 827 | counter = 0 |
|
824 | 828 | |
|
825 | 829 | title = "Coherence Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
826 | 830 | axes = self.axesList[i*self.__nsubplots*2] |
|
827 | 831 | axes.pcolorbuffer(x, y, z, |
|
828 | 832 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
829 | 833 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
830 | 834 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
831 | 835 | |
|
832 | 836 | if self.__showprofile: |
|
833 | 837 | counter += 1 |
|
834 | 838 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
835 | 839 | axes.pline(coherence, y, |
|
836 | 840 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
837 | 841 | xlabel='', ylabel='', title='', ticksize=7, |
|
838 | 842 | ytick_visible=False, nxticks=5, |
|
839 | 843 | grid='x') |
|
840 | 844 | |
|
841 | 845 | counter += 1 |
|
842 | 846 | |
|
843 | 847 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
844 | 848 | |
|
845 | 849 | z = phase.reshape((1,-1)) |
|
846 | 850 | |
|
847 | 851 | title = "Phase Ch%d * Ch%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
848 | 852 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
849 | 853 | axes.pcolorbuffer(x, y, z, |
|
850 | 854 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=phase_min, zmax=phase_max, |
|
851 | 855 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
852 | 856 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
853 | 857 | |
|
854 | 858 | if self.__showprofile: |
|
855 | 859 | counter += 1 |
|
856 | 860 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
857 | 861 | axes.pline(phase, y, |
|
858 | 862 | xmin=phase_min, xmax=phase_max, ymin=ymin, ymax=ymax, |
|
859 | 863 | xlabel='', ylabel='', title='', ticksize=7, |
|
860 | 864 | ytick_visible=False, nxticks=4, |
|
861 | 865 | grid='x') |
|
862 | 866 | |
|
863 | 867 | self.draw() |
|
864 | 868 | |
|
865 | 869 | if dataOut.ltctime >= self.xmax: |
|
866 | 870 | self.counter_imagwr = wr_period |
|
867 | 871 | self.isConfig = False |
|
868 | 872 | update_figfile = True |
|
869 | 873 | |
|
870 | 874 | self.save(figpath=figpath, |
|
871 | 875 | figfile=figfile, |
|
872 | 876 | save=save, |
|
873 | 877 | ftp=ftp, |
|
874 | 878 | wr_period=wr_period, |
|
875 | 879 | thisDatetime=thisDatetime, |
|
876 | 880 | update_figfile=update_figfile) |
|
877 | 881 | |
|
878 | 882 | return dataOut |
|
879 | 883 | |
|
880 | 884 | @MPDecorator |
|
881 | class PowerProfilePlot(Figure): | |
|
885 | class PowerProfilePlot_(Figure): | |
|
882 | 886 | |
|
883 | 887 | isConfig = None |
|
884 | 888 | __nsubplots = None |
|
885 | 889 | |
|
886 | 890 | WIDTHPROF = None |
|
887 | 891 | HEIGHTPROF = None |
|
888 | 892 | PREFIX = 'spcprofile' |
|
889 | 893 | |
|
890 | 894 | def __init__(self): |
|
891 | 895 | Figure.__init__(self) |
|
892 | 896 | self.isConfig = False |
|
893 | 897 | self.__nsubplots = 1 |
|
894 | 898 | |
|
895 | 899 | self.PLOT_CODE = POWER_CODE |
|
896 | 900 | |
|
897 | 901 | self.WIDTH = 300 |
|
898 | 902 | self.HEIGHT = 500 |
|
899 | 903 | self.counter_imagwr = 0 |
|
900 | 904 | |
|
901 | 905 | def getSubplots(self): |
|
902 | 906 | ncol = 1 |
|
903 | 907 | nrow = 1 |
|
904 | 908 | |
|
905 | 909 | return nrow, ncol |
|
906 | 910 | |
|
907 | 911 | def setup(self, id, nplots, wintitle, show): |
|
908 | 912 | |
|
909 | 913 | self.nplots = nplots |
|
910 | 914 | |
|
911 | 915 | ncolspan = 1 |
|
912 | 916 | colspan = 1 |
|
913 | 917 | |
|
914 | 918 | self.createFigure(id = id, |
|
915 | 919 | wintitle = wintitle, |
|
916 | 920 | widthplot = self.WIDTH, |
|
917 | 921 | heightplot = self.HEIGHT, |
|
918 | 922 | show=show) |
|
919 | 923 | |
|
920 | 924 | nrow, ncol = self.getSubplots() |
|
921 | 925 | |
|
922 | 926 | counter = 0 |
|
923 | 927 | for y in range(nrow): |
|
924 | 928 | for x in range(ncol): |
|
925 | 929 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
926 | 930 | |
|
927 | 931 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
928 | 932 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
929 | 933 | save=False, figpath='./', figfile=None, show=True, |
|
930 | 934 | ftp=False, wr_period=1, server=None, |
|
931 | 935 | folder=None, username=None, password=None): |
|
932 | 936 | |
|
933 | 937 | if dataOut.flagNoData: |
|
934 | 938 | return dataOut |
|
935 | 939 | |
|
936 | 940 | |
|
937 | 941 | if channelList == None: |
|
938 | 942 | channelIndexList = dataOut.channelIndexList |
|
939 | 943 | channelList = dataOut.channelList |
|
940 | 944 | else: |
|
941 | 945 | channelIndexList = [] |
|
942 | 946 | for channel in channelList: |
|
943 | 947 | if channel not in dataOut.channelList: |
|
944 | 948 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
945 | 949 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
946 | 950 | |
|
947 | 951 | factor = dataOut.normFactor |
|
948 | 952 | |
|
949 | 953 | y = dataOut.getHeiRange() |
|
950 | 954 | |
|
951 | 955 | #for voltage |
|
952 | 956 | if dataOut.type == 'Voltage': |
|
953 | 957 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
954 | 958 | x = x.real |
|
955 | 959 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
956 | 960 | |
|
957 | 961 | #for spectra |
|
958 | 962 | if dataOut.type == 'Spectra': |
|
959 | 963 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
960 | 964 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
961 | 965 | x = numpy.average(x, axis=1) |
|
962 | 966 | |
|
963 | 967 | |
|
964 | 968 | xdB = 10*numpy.log10(x) |
|
965 | 969 | |
|
966 | 970 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
967 | 971 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
968 | 972 | xlabel = "dB" |
|
969 | 973 | ylabel = "Range (Km)" |
|
970 | 974 | |
|
971 | 975 | if not self.isConfig: |
|
972 | 976 | |
|
973 | 977 | nplots = 1 |
|
974 | 978 | |
|
975 | 979 | self.setup(id=id, |
|
976 | 980 | nplots=nplots, |
|
977 | 981 | wintitle=wintitle, |
|
978 | 982 | show=show) |
|
979 | 983 | |
|
980 | 984 | if ymin == None: ymin = numpy.nanmin(y) |
|
981 | 985 | if ymax == None: ymax = numpy.nanmax(y) |
|
982 | 986 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
983 | 987 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 |
|
984 | 988 | |
|
985 | 989 | self.isConfig = True |
|
986 | 990 | |
|
987 | 991 | self.setWinTitle(title) |
|
988 | 992 | |
|
989 | 993 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
990 | 994 | axes = self.axesList[0] |
|
991 | 995 | |
|
992 | 996 | legendlabels = ["channel %d"%x for x in channelList] |
|
993 | 997 | axes.pmultiline(xdB, y, |
|
994 | 998 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
995 | 999 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
996 | 1000 | ytick_visible=True, nxticks=5, |
|
997 | 1001 | grid='x') |
|
998 | 1002 | |
|
999 | 1003 | self.draw() |
|
1000 | 1004 | |
|
1001 | 1005 | self.save(figpath=figpath, |
|
1002 | 1006 | figfile=figfile, |
|
1003 | 1007 | save=save, |
|
1004 | 1008 | ftp=ftp, |
|
1005 | 1009 | wr_period=wr_period, |
|
1006 | 1010 | thisDatetime=thisDatetime) |
|
1007 | 1011 | |
|
1008 | 1012 | return dataOut |
|
1009 | 1013 | |
|
1010 | 1014 | @MPDecorator |
|
1011 | class SpectraCutPlot(Figure): | |
|
1015 | class SpectraCutPlot_(Figure): | |
|
1012 | 1016 | |
|
1013 | 1017 | isConfig = None |
|
1014 | 1018 | __nsubplots = None |
|
1015 | 1019 | |
|
1016 | 1020 | WIDTHPROF = None |
|
1017 | 1021 | HEIGHTPROF = None |
|
1018 | 1022 | PREFIX = 'spc_cut' |
|
1019 | 1023 | |
|
1020 | 1024 | def __init__(self): |
|
1021 | 1025 | Figure.__init__(self) |
|
1022 | 1026 | self.isConfig = False |
|
1023 | 1027 | self.__nsubplots = 1 |
|
1024 | 1028 | |
|
1025 | 1029 | self.PLOT_CODE = POWER_CODE |
|
1026 | 1030 | |
|
1027 | 1031 | self.WIDTH = 700 |
|
1028 | 1032 | self.HEIGHT = 500 |
|
1029 | 1033 | self.counter_imagwr = 0 |
|
1030 | 1034 | |
|
1031 | 1035 | def getSubplots(self): |
|
1032 | 1036 | ncol = 1 |
|
1033 | 1037 | nrow = 1 |
|
1034 | 1038 | |
|
1035 | 1039 | return nrow, ncol |
|
1036 | 1040 | |
|
1037 | 1041 | def setup(self, id, nplots, wintitle, show): |
|
1038 | 1042 | |
|
1039 | 1043 | self.nplots = nplots |
|
1040 | 1044 | |
|
1041 | 1045 | ncolspan = 1 |
|
1042 | 1046 | colspan = 1 |
|
1043 | 1047 | |
|
1044 | 1048 | self.createFigure(id = id, |
|
1045 | 1049 | wintitle = wintitle, |
|
1046 | 1050 | widthplot = self.WIDTH, |
|
1047 | 1051 | heightplot = self.HEIGHT, |
|
1048 | 1052 | show=show) |
|
1049 | 1053 | |
|
1050 | 1054 | nrow, ncol = self.getSubplots() |
|
1051 | 1055 | |
|
1052 | 1056 | counter = 0 |
|
1053 | 1057 | for y in range(nrow): |
|
1054 | 1058 | for x in range(ncol): |
|
1055 | 1059 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1056 | 1060 | |
|
1057 | 1061 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1058 | 1062 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1059 | 1063 | save=False, figpath='./', figfile=None, show=True, |
|
1060 | 1064 | ftp=False, wr_period=1, server=None, |
|
1061 | 1065 | folder=None, username=None, password=None, |
|
1062 | 1066 | xaxis="frequency"): |
|
1063 | 1067 | |
|
1064 | 1068 | if dataOut.flagNoData: |
|
1065 | 1069 | return dataOut |
|
1066 | 1070 | |
|
1067 | 1071 | if channelList == None: |
|
1068 | 1072 | channelIndexList = dataOut.channelIndexList |
|
1069 | 1073 | channelList = dataOut.channelList |
|
1070 | 1074 | else: |
|
1071 | 1075 | channelIndexList = [] |
|
1072 | 1076 | for channel in channelList: |
|
1073 | 1077 | if channel not in dataOut.channelList: |
|
1074 | 1078 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
1075 | 1079 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1076 | 1080 | |
|
1077 | 1081 | factor = dataOut.normFactor |
|
1078 | 1082 | |
|
1079 | 1083 | y = dataOut.getHeiRange() |
|
1080 | 1084 | |
|
1081 | 1085 | z = dataOut.data_spc/factor |
|
1082 | 1086 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
1083 | 1087 | |
|
1084 | 1088 | hei_index = numpy.arange(25)*3 + 20 |
|
1085 | 1089 | |
|
1086 | 1090 | if xaxis == "frequency": |
|
1087 | 1091 | x = dataOut.getFreqRange()/1000. |
|
1088 | 1092 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1089 | 1093 | xlabel = "Frequency (kHz)" |
|
1090 | 1094 | ylabel = "Power (dB)" |
|
1091 | 1095 | |
|
1092 | 1096 | elif xaxis == "time": |
|
1093 | 1097 | x = dataOut.getAcfRange() |
|
1094 | 1098 | zdB = z[0,:,hei_index] |
|
1095 | 1099 | xlabel = "Time (ms)" |
|
1096 | 1100 | ylabel = "ACF" |
|
1097 | 1101 | |
|
1098 | 1102 | else: |
|
1099 | 1103 | x = dataOut.getVelRange() |
|
1100 | 1104 | zdB = 10*numpy.log10(z[0,:,hei_index]) |
|
1101 | 1105 | xlabel = "Velocity (m/s)" |
|
1102 | 1106 | ylabel = "Power (dB)" |
|
1103 | 1107 | |
|
1104 | 1108 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
1105 | 1109 | title = wintitle + " Range Cuts %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1106 | 1110 | |
|
1107 | 1111 | if not self.isConfig: |
|
1108 | 1112 | |
|
1109 | 1113 | nplots = 1 |
|
1110 | 1114 | |
|
1111 | 1115 | self.setup(id=id, |
|
1112 | 1116 | nplots=nplots, |
|
1113 | 1117 | wintitle=wintitle, |
|
1114 | 1118 | show=show) |
|
1115 | 1119 | |
|
1116 | 1120 | if xmin == None: xmin = numpy.nanmin(x)*0.9 |
|
1117 | 1121 | if xmax == None: xmax = numpy.nanmax(x)*1.1 |
|
1118 | 1122 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
1119 | 1123 | if ymax == None: ymax = numpy.nanmax(zdB) |
|
1120 | 1124 | |
|
1121 | 1125 | self.isConfig = True |
|
1122 | 1126 | |
|
1123 | 1127 | self.setWinTitle(title) |
|
1124 | 1128 | |
|
1125 | 1129 | title = "Spectra Cuts: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1126 | 1130 | axes = self.axesList[0] |
|
1127 | 1131 | |
|
1128 | 1132 | legendlabels = ["Range = %dKm" %y[i] for i in hei_index] |
|
1129 | 1133 | |
|
1130 | 1134 | axes.pmultilineyaxis( x, zdB, |
|
1131 | 1135 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1132 | 1136 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1133 | 1137 | ytick_visible=True, nxticks=5, |
|
1134 | 1138 | grid='x') |
|
1135 | 1139 | |
|
1136 | 1140 | self.draw() |
|
1137 | 1141 | |
|
1138 | 1142 | self.save(figpath=figpath, |
|
1139 | 1143 | figfile=figfile, |
|
1140 | 1144 | save=save, |
|
1141 | 1145 | ftp=ftp, |
|
1142 | 1146 | wr_period=wr_period, |
|
1143 | 1147 | thisDatetime=thisDatetime) |
|
1144 | 1148 | |
|
1145 | 1149 | return dataOut |
|
1146 | 1150 | |
|
1147 | 1151 | @MPDecorator |
|
1148 | class Noise(Figure): | |
|
1152 | class Noise_(Figure): | |
|
1149 | 1153 | |
|
1150 | 1154 | isConfig = None |
|
1151 | 1155 | __nsubplots = None |
|
1152 | 1156 | |
|
1153 | 1157 | PREFIX = 'noise' |
|
1154 | 1158 | |
|
1155 | 1159 | |
|
1156 | 1160 | def __init__(self): |
|
1157 | 1161 | Figure.__init__(self) |
|
1158 | 1162 | self.timerange = 24*60*60 |
|
1159 | 1163 | self.isConfig = False |
|
1160 | 1164 | self.__nsubplots = 1 |
|
1161 | 1165 | self.counter_imagwr = 0 |
|
1162 | 1166 | self.WIDTH = 800 |
|
1163 | 1167 | self.HEIGHT = 400 |
|
1164 | 1168 | self.WIDTHPROF = 120 |
|
1165 | 1169 | self.HEIGHTPROF = 0 |
|
1166 | 1170 | self.xdata = None |
|
1167 | 1171 | self.ydata = None |
|
1168 | 1172 | |
|
1169 | 1173 | self.PLOT_CODE = NOISE_CODE |
|
1170 | 1174 | |
|
1171 | 1175 | self.FTP_WEI = None |
|
1172 | 1176 | self.EXP_CODE = None |
|
1173 | 1177 | self.SUB_EXP_CODE = None |
|
1174 | 1178 | self.PLOT_POS = None |
|
1175 | 1179 | self.figfile = None |
|
1176 | 1180 | |
|
1177 | 1181 | self.xmin = None |
|
1178 | 1182 | self.xmax = None |
|
1179 | 1183 | |
|
1180 | 1184 | def getSubplots(self): |
|
1181 | 1185 | |
|
1182 | 1186 | ncol = 1 |
|
1183 | 1187 | nrow = 1 |
|
1184 | 1188 | |
|
1185 | 1189 | return nrow, ncol |
|
1186 | 1190 | |
|
1187 | 1191 | def openfile(self, filename): |
|
1188 | 1192 | dirname = os.path.dirname(filename) |
|
1189 | 1193 | |
|
1190 | 1194 | if not os.path.exists(dirname): |
|
1191 | 1195 | os.mkdir(dirname) |
|
1192 | 1196 | |
|
1193 | 1197 | f = open(filename,'w+') |
|
1194 | 1198 | f.write('\n\n') |
|
1195 | 1199 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1196 | 1200 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1197 | 1201 | f.close() |
|
1198 | 1202 | |
|
1199 | 1203 | def save_data(self, filename_phase, data, data_datetime): |
|
1200 | 1204 | |
|
1201 | 1205 | f=open(filename_phase,'a') |
|
1202 | 1206 | |
|
1203 | 1207 | timetuple_data = data_datetime.timetuple() |
|
1204 | 1208 | day = str(timetuple_data.tm_mday) |
|
1205 | 1209 | month = str(timetuple_data.tm_mon) |
|
1206 | 1210 | year = str(timetuple_data.tm_year) |
|
1207 | 1211 | hour = str(timetuple_data.tm_hour) |
|
1208 | 1212 | minute = str(timetuple_data.tm_min) |
|
1209 | 1213 | second = str(timetuple_data.tm_sec) |
|
1210 | 1214 | |
|
1211 | 1215 | data_msg = '' |
|
1212 | 1216 | for i in range(len(data)): |
|
1213 | 1217 | data_msg += str(data[i]) + ' ' |
|
1214 | 1218 | |
|
1215 | 1219 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' ' + data_msg + '\n') |
|
1216 | 1220 | f.close() |
|
1217 | 1221 | |
|
1218 | 1222 | |
|
1219 | 1223 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1220 | 1224 | |
|
1221 | 1225 | self.__showprofile = showprofile |
|
1222 | 1226 | self.nplots = nplots |
|
1223 | 1227 | |
|
1224 | 1228 | ncolspan = 7 |
|
1225 | 1229 | colspan = 6 |
|
1226 | 1230 | self.__nsubplots = 2 |
|
1227 | 1231 | |
|
1228 | 1232 | self.createFigure(id = id, |
|
1229 | 1233 | wintitle = wintitle, |
|
1230 | 1234 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1231 | 1235 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1232 | 1236 | show=show) |
|
1233 | 1237 | |
|
1234 | 1238 | nrow, ncol = self.getSubplots() |
|
1235 | 1239 | |
|
1236 | 1240 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1237 | 1241 | |
|
1238 | 1242 | |
|
1239 | 1243 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1240 | 1244 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1241 | 1245 | timerange=None, |
|
1242 | 1246 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1243 | 1247 | server=None, folder=None, username=None, password=None, |
|
1244 | 1248 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1245 | 1249 | |
|
1246 | 1250 | if dataOut.flagNoData: |
|
1247 | 1251 | return dataOut |
|
1248 | 1252 | |
|
1249 | 1253 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1250 | 1254 | return |
|
1251 | 1255 | |
|
1252 | 1256 | if channelList == None: |
|
1253 | 1257 | channelIndexList = dataOut.channelIndexList |
|
1254 | 1258 | channelList = dataOut.channelList |
|
1255 | 1259 | else: |
|
1256 | 1260 | channelIndexList = [] |
|
1257 | 1261 | for channel in channelList: |
|
1258 | 1262 | if channel not in dataOut.channelList: |
|
1259 | 1263 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
1260 | 1264 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1261 | 1265 | |
|
1262 | 1266 | x = dataOut.getTimeRange() |
|
1263 | 1267 | #y = dataOut.getHeiRange() |
|
1264 | 1268 | factor = dataOut.normFactor |
|
1265 | 1269 | noise = dataOut.noise[channelIndexList]/factor |
|
1266 | 1270 | noisedB = 10*numpy.log10(noise) |
|
1267 | 1271 | |
|
1268 | 1272 | thisDatetime = dataOut.datatime |
|
1269 | 1273 | |
|
1270 | 1274 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1271 | 1275 | xlabel = "" |
|
1272 | 1276 | ylabel = "Intensity (dB)" |
|
1273 | 1277 | update_figfile = False |
|
1274 | 1278 | |
|
1275 | 1279 | if not self.isConfig: |
|
1276 | 1280 | |
|
1277 | 1281 | nplots = 1 |
|
1278 | 1282 | |
|
1279 | 1283 | self.setup(id=id, |
|
1280 | 1284 | nplots=nplots, |
|
1281 | 1285 | wintitle=wintitle, |
|
1282 | 1286 | showprofile=showprofile, |
|
1283 | 1287 | show=show) |
|
1284 | 1288 | |
|
1285 | 1289 | if timerange != None: |
|
1286 | 1290 | self.timerange = timerange |
|
1287 | 1291 | |
|
1288 | 1292 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1289 | 1293 | |
|
1290 | 1294 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 |
|
1291 | 1295 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1292 | 1296 | |
|
1293 | 1297 | self.FTP_WEI = ftp_wei |
|
1294 | 1298 | self.EXP_CODE = exp_code |
|
1295 | 1299 | self.SUB_EXP_CODE = sub_exp_code |
|
1296 | 1300 | self.PLOT_POS = plot_pos |
|
1297 | 1301 | |
|
1298 | 1302 | |
|
1299 | 1303 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1300 | 1304 | self.isConfig = True |
|
1301 | 1305 | self.figfile = figfile |
|
1302 | 1306 | self.xdata = numpy.array([]) |
|
1303 | 1307 | self.ydata = numpy.array([]) |
|
1304 | 1308 | |
|
1305 | 1309 | update_figfile = True |
|
1306 | 1310 | |
|
1307 | 1311 | #open file beacon phase |
|
1308 | 1312 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1309 | 1313 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1310 | 1314 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1311 | 1315 | |
|
1312 | 1316 | self.setWinTitle(title) |
|
1313 | 1317 | |
|
1314 | 1318 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1315 | 1319 | |
|
1316 | 1320 | legendlabels = ["channel %d"%(idchannel) for idchannel in channelList] |
|
1317 | 1321 | axes = self.axesList[0] |
|
1318 | 1322 | |
|
1319 | 1323 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1320 | 1324 | |
|
1321 | 1325 | if len(self.ydata)==0: |
|
1322 | 1326 | self.ydata = noisedB.reshape(-1,1) |
|
1323 | 1327 | else: |
|
1324 | 1328 | self.ydata = numpy.hstack((self.ydata, noisedB.reshape(-1,1))) |
|
1325 | 1329 | |
|
1326 | 1330 | |
|
1327 | 1331 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1328 | 1332 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1329 | 1333 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1330 | 1334 | XAxisAsTime=True, grid='both' |
|
1331 | 1335 | ) |
|
1332 | 1336 | |
|
1333 | 1337 | self.draw() |
|
1334 | 1338 | |
|
1335 | 1339 | if dataOut.ltctime >= self.xmax: |
|
1336 | 1340 | self.counter_imagwr = wr_period |
|
1337 | 1341 | self.isConfig = False |
|
1338 | 1342 | update_figfile = True |
|
1339 | 1343 | |
|
1340 | 1344 | self.save(figpath=figpath, |
|
1341 | 1345 | figfile=figfile, |
|
1342 | 1346 | save=save, |
|
1343 | 1347 | ftp=ftp, |
|
1344 | 1348 | wr_period=wr_period, |
|
1345 | 1349 | thisDatetime=thisDatetime, |
|
1346 | 1350 | update_figfile=update_figfile) |
|
1347 | 1351 | |
|
1348 | 1352 | #store data beacon phase |
|
1349 | 1353 | if save: |
|
1350 | 1354 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1351 | 1355 | |
|
1352 | 1356 | return dataOut |
|
1353 | 1357 | |
|
1354 | 1358 | @MPDecorator |
|
1355 | class BeaconPhase(Figure): | |
|
1359 | class BeaconPhase_(Figure): | |
|
1356 | 1360 | |
|
1357 | 1361 | __isConfig = None |
|
1358 | 1362 | __nsubplots = None |
|
1359 | 1363 | |
|
1360 | 1364 | PREFIX = 'beacon_phase' |
|
1361 | 1365 | |
|
1362 | 1366 | def __init__(self): |
|
1363 | 1367 | Figure.__init__(self) |
|
1364 | 1368 | self.timerange = 24*60*60 |
|
1365 | 1369 | self.isConfig = False |
|
1366 | 1370 | self.__nsubplots = 1 |
|
1367 | 1371 | self.counter_imagwr = 0 |
|
1368 | 1372 | self.WIDTH = 800 |
|
1369 | 1373 | self.HEIGHT = 400 |
|
1370 | 1374 | self.WIDTHPROF = 120 |
|
1371 | 1375 | self.HEIGHTPROF = 0 |
|
1372 | 1376 | self.xdata = None |
|
1373 | 1377 | self.ydata = None |
|
1374 | 1378 | |
|
1375 | 1379 | self.PLOT_CODE = BEACON_CODE |
|
1376 | 1380 | |
|
1377 | 1381 | self.FTP_WEI = None |
|
1378 | 1382 | self.EXP_CODE = None |
|
1379 | 1383 | self.SUB_EXP_CODE = None |
|
1380 | 1384 | self.PLOT_POS = None |
|
1381 | 1385 | |
|
1382 | 1386 | self.filename_phase = None |
|
1383 | 1387 | |
|
1384 | 1388 | self.figfile = None |
|
1385 | 1389 | |
|
1386 | 1390 | self.xmin = None |
|
1387 | 1391 | self.xmax = None |
|
1388 | 1392 | |
|
1389 | 1393 | def getSubplots(self): |
|
1390 | 1394 | |
|
1391 | 1395 | ncol = 1 |
|
1392 | 1396 | nrow = 1 |
|
1393 | 1397 | |
|
1394 | 1398 | return nrow, ncol |
|
1395 | 1399 | |
|
1396 | 1400 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1397 | 1401 | |
|
1398 | 1402 | self.__showprofile = showprofile |
|
1399 | 1403 | self.nplots = nplots |
|
1400 | 1404 | |
|
1401 | 1405 | ncolspan = 7 |
|
1402 | 1406 | colspan = 6 |
|
1403 | 1407 | self.__nsubplots = 2 |
|
1404 | 1408 | |
|
1405 | 1409 | self.createFigure(id = id, |
|
1406 | 1410 | wintitle = wintitle, |
|
1407 | 1411 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1408 | 1412 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1409 | 1413 | show=show) |
|
1410 | 1414 | |
|
1411 | 1415 | nrow, ncol = self.getSubplots() |
|
1412 | 1416 | |
|
1413 | 1417 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1414 | 1418 | |
|
1415 | 1419 | def save_phase(self, filename_phase): |
|
1416 | 1420 | f = open(filename_phase,'w+') |
|
1417 | 1421 | f.write('\n\n') |
|
1418 | 1422 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1419 | 1423 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1420 | 1424 | f.close() |
|
1421 | 1425 | |
|
1422 | 1426 | def save_data(self, filename_phase, data, data_datetime): |
|
1423 | 1427 | f=open(filename_phase,'a') |
|
1424 | 1428 | timetuple_data = data_datetime.timetuple() |
|
1425 | 1429 | day = str(timetuple_data.tm_mday) |
|
1426 | 1430 | month = str(timetuple_data.tm_mon) |
|
1427 | 1431 | year = str(timetuple_data.tm_year) |
|
1428 | 1432 | hour = str(timetuple_data.tm_hour) |
|
1429 | 1433 | minute = str(timetuple_data.tm_min) |
|
1430 | 1434 | second = str(timetuple_data.tm_sec) |
|
1431 | 1435 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1432 | 1436 | f.close() |
|
1433 | 1437 | |
|
1434 | 1438 | |
|
1435 | 1439 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1436 | 1440 | xmin=None, xmax=None, ymin=None, ymax=None, hmin=None, hmax=None, |
|
1437 | 1441 | timerange=None, |
|
1438 | 1442 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1439 | 1443 | server=None, folder=None, username=None, password=None, |
|
1440 | 1444 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1441 | 1445 | |
|
1442 | 1446 | if dataOut.flagNoData: |
|
1443 | 1447 | return dataOut |
|
1444 | 1448 | |
|
1445 | 1449 | if not isTimeInHourRange(dataOut.datatime, xmin, xmax): |
|
1446 | 1450 | return |
|
1447 | 1451 | |
|
1448 | 1452 | if pairsList == None: |
|
1449 | 1453 | pairsIndexList = dataOut.pairsIndexList[:10] |
|
1450 | 1454 | else: |
|
1451 | 1455 | pairsIndexList = [] |
|
1452 | 1456 | for pair in pairsList: |
|
1453 | 1457 | if pair not in dataOut.pairsList: |
|
1454 | 1458 | raise ValueError("Pair %s is not in dataOut.pairsList" %(pair)) |
|
1455 | 1459 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1456 | 1460 | |
|
1457 | 1461 | if pairsIndexList == []: |
|
1458 | 1462 | return |
|
1459 | 1463 | |
|
1460 | 1464 | # if len(pairsIndexList) > 4: |
|
1461 | 1465 | # pairsIndexList = pairsIndexList[0:4] |
|
1462 | 1466 | |
|
1463 | 1467 | hmin_index = None |
|
1464 | 1468 | hmax_index = None |
|
1465 | 1469 | |
|
1466 | 1470 | if hmin != None and hmax != None: |
|
1467 | 1471 | indexes = numpy.arange(dataOut.nHeights) |
|
1468 | 1472 | hmin_list = indexes[dataOut.heightList >= hmin] |
|
1469 | 1473 | hmax_list = indexes[dataOut.heightList <= hmax] |
|
1470 | 1474 | |
|
1471 | 1475 | if hmin_list.any(): |
|
1472 | 1476 | hmin_index = hmin_list[0] |
|
1473 | 1477 | |
|
1474 | 1478 | if hmax_list.any(): |
|
1475 | 1479 | hmax_index = hmax_list[-1]+1 |
|
1476 | 1480 | |
|
1477 | 1481 | x = dataOut.getTimeRange() |
|
1478 | 1482 | #y = dataOut.getHeiRange() |
|
1479 | 1483 | |
|
1480 | 1484 | |
|
1481 | 1485 | thisDatetime = dataOut.datatime |
|
1482 | 1486 | |
|
1483 | 1487 | title = wintitle + " Signal Phase" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1484 | 1488 | xlabel = "Local Time" |
|
1485 | 1489 | ylabel = "Phase (degrees)" |
|
1486 | 1490 | |
|
1487 | 1491 | update_figfile = False |
|
1488 | 1492 | |
|
1489 | 1493 | nplots = len(pairsIndexList) |
|
1490 | 1494 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1491 | 1495 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1492 | 1496 | for i in range(nplots): |
|
1493 | 1497 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1494 | 1498 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i], :, hmin_index:hmax_index], axis=0) |
|
1495 | 1499 | powa = numpy.average(dataOut.data_spc[pair[0], :, hmin_index:hmax_index], axis=0) |
|
1496 | 1500 | powb = numpy.average(dataOut.data_spc[pair[1], :, hmin_index:hmax_index], axis=0) |
|
1497 | 1501 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1498 | 1502 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1499 | 1503 | |
|
1500 | #print "Phase %d%d" %(pair[0], pair[1]) | |
|
1501 | #print phase[dataOut.beacon_heiIndexList] | |
|
1502 | ||
|
1503 | 1504 | if dataOut.beacon_heiIndexList: |
|
1504 | 1505 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1505 | 1506 | else: |
|
1506 | 1507 | phase_beacon[i] = numpy.average(phase) |
|
1507 | 1508 | |
|
1508 | 1509 | if not self.isConfig: |
|
1509 | 1510 | |
|
1510 | 1511 | nplots = len(pairsIndexList) |
|
1511 | 1512 | |
|
1512 | 1513 | self.setup(id=id, |
|
1513 | 1514 | nplots=nplots, |
|
1514 | 1515 | wintitle=wintitle, |
|
1515 | 1516 | showprofile=showprofile, |
|
1516 | 1517 | show=show) |
|
1517 | 1518 | |
|
1518 | 1519 | if timerange != None: |
|
1519 | 1520 | self.timerange = timerange |
|
1520 | 1521 | |
|
1521 | 1522 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1522 | 1523 | |
|
1523 | 1524 | if ymin == None: ymin = 0 |
|
1524 | 1525 | if ymax == None: ymax = 360 |
|
1525 | 1526 | |
|
1526 | 1527 | self.FTP_WEI = ftp_wei |
|
1527 | 1528 | self.EXP_CODE = exp_code |
|
1528 | 1529 | self.SUB_EXP_CODE = sub_exp_code |
|
1529 | 1530 | self.PLOT_POS = plot_pos |
|
1530 | 1531 | |
|
1531 | 1532 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1532 | 1533 | self.isConfig = True |
|
1533 | 1534 | self.figfile = figfile |
|
1534 | 1535 | self.xdata = numpy.array([]) |
|
1535 | 1536 | self.ydata = numpy.array([]) |
|
1536 | 1537 | |
|
1537 | 1538 | update_figfile = True |
|
1538 | 1539 | |
|
1539 | 1540 | #open file beacon phase |
|
1540 | 1541 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1541 | 1542 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1542 | 1543 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1543 | 1544 | #self.save_phase(self.filename_phase) |
|
1544 | 1545 | |
|
1545 | 1546 | |
|
1546 | 1547 | #store data beacon phase |
|
1547 | 1548 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1548 | 1549 | |
|
1549 | 1550 | self.setWinTitle(title) |
|
1550 | 1551 | |
|
1551 | 1552 | |
|
1552 | 1553 | title = "Phase Plot %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1553 | 1554 | |
|
1554 | 1555 | legendlabels = ["Pair (%d,%d)"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1555 | 1556 | |
|
1556 | 1557 | axes = self.axesList[0] |
|
1557 | 1558 | |
|
1558 | 1559 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1559 | 1560 | |
|
1560 | 1561 | if len(self.ydata)==0: |
|
1561 | 1562 | self.ydata = phase_beacon.reshape(-1,1) |
|
1562 | 1563 | else: |
|
1563 | 1564 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1564 | 1565 | |
|
1565 | 1566 | |
|
1566 | 1567 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1567 | 1568 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, |
|
1568 | 1569 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1569 | 1570 | XAxisAsTime=True, grid='both' |
|
1570 | 1571 | ) |
|
1571 | 1572 | |
|
1572 | 1573 | self.draw() |
|
1573 | 1574 | |
|
1574 | 1575 | if dataOut.ltctime >= self.xmax: |
|
1575 | 1576 | self.counter_imagwr = wr_period |
|
1576 | 1577 | self.isConfig = False |
|
1577 | 1578 | update_figfile = True |
|
1578 | 1579 | |
|
1579 | 1580 | self.save(figpath=figpath, |
|
1580 | 1581 | figfile=figfile, |
|
1581 | 1582 | save=save, |
|
1582 | 1583 | ftp=ftp, |
|
1583 | 1584 | wr_period=wr_period, |
|
1584 | 1585 | thisDatetime=thisDatetime, |
|
1585 | 1586 | update_figfile=update_figfile) |
|
1586 | 1587 | |
|
1587 | 1588 | return dataOut No newline at end of file |
@@ -1,232 +1,232 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 9, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator #YONG |
|
10 | 10 | from schainpy.utils import log |
|
11 | 11 | from .figure import Figure |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | @MPDecorator |
|
15 | class Scope(Figure): | |
|
15 | class Scope_(Figure): | |
|
16 | 16 | |
|
17 | 17 | isConfig = None |
|
18 | 18 | |
|
19 | 19 | def __init__(self):#, **kwargs): #YONG |
|
20 | 20 | Figure.__init__(self)#, **kwargs) |
|
21 | 21 | self.isConfig = False |
|
22 | 22 | self.WIDTH = 300 |
|
23 | 23 | self.HEIGHT = 200 |
|
24 | 24 | self.counter_imagwr = 0 |
|
25 | 25 | |
|
26 | 26 | def getSubplots(self): |
|
27 | 27 | |
|
28 | 28 | nrow = self.nplots |
|
29 | 29 | ncol = 3 |
|
30 | 30 | return nrow, ncol |
|
31 | 31 | |
|
32 | 32 | def setup(self, id, nplots, wintitle, show): |
|
33 | 33 | |
|
34 | 34 | self.nplots = nplots |
|
35 | 35 | |
|
36 | 36 | self.createFigure(id=id, |
|
37 | 37 | wintitle=wintitle, |
|
38 | 38 | show=show) |
|
39 | 39 | |
|
40 | 40 | nrow,ncol = self.getSubplots() |
|
41 | 41 | colspan = 3 |
|
42 | 42 | rowspan = 1 |
|
43 | 43 | |
|
44 | 44 | for i in range(nplots): |
|
45 | 45 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
46 | 46 | |
|
47 | 47 | def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): |
|
48 | 48 | yreal = y[channelIndexList,:].real |
|
49 | 49 | yimag = y[channelIndexList,:].imag |
|
50 | 50 | |
|
51 | 51 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
52 | 52 | xlabel = "Range (Km)" |
|
53 | 53 | ylabel = "Intensity - IQ" |
|
54 | 54 | |
|
55 | 55 | if not self.isConfig: |
|
56 | 56 | nplots = len(channelIndexList) |
|
57 | 57 | |
|
58 | 58 | self.setup(id=id, |
|
59 | 59 | nplots=nplots, |
|
60 | 60 | wintitle='', |
|
61 | 61 | show=show) |
|
62 | 62 | |
|
63 | 63 | if xmin == None: xmin = numpy.nanmin(x) |
|
64 | 64 | if xmax == None: xmax = numpy.nanmax(x) |
|
65 | 65 | if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag)) |
|
66 | 66 | if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag)) |
|
67 | 67 | |
|
68 | 68 | self.isConfig = True |
|
69 | 69 | |
|
70 | 70 | self.setWinTitle(title) |
|
71 | 71 | |
|
72 | 72 | for i in range(len(self.axesList)): |
|
73 | 73 | title = "Channel %d" %(i) |
|
74 | 74 | axes = self.axesList[i] |
|
75 | 75 | |
|
76 | 76 | axes.pline(x, yreal[i,:], |
|
77 | 77 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
78 | 78 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
79 | 79 | |
|
80 | 80 | axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2) |
|
81 | 81 | |
|
82 | 82 | def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): |
|
83 | 83 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) |
|
84 | 84 | yreal = y.real |
|
85 | 85 | |
|
86 | 86 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
87 | 87 | xlabel = "Range (Km)" |
|
88 | 88 | ylabel = "Intensity" |
|
89 | 89 | |
|
90 | 90 | if not self.isConfig: |
|
91 | 91 | nplots = len(channelIndexList) |
|
92 | 92 | |
|
93 | 93 | self.setup(id=id, |
|
94 | 94 | nplots=nplots, |
|
95 | 95 | wintitle='', |
|
96 | 96 | show=show) |
|
97 | 97 | |
|
98 | 98 | if xmin == None: xmin = numpy.nanmin(x) |
|
99 | 99 | if xmax == None: xmax = numpy.nanmax(x) |
|
100 | 100 | if ymin == None: ymin = numpy.nanmin(yreal) |
|
101 | 101 | if ymax == None: ymax = numpy.nanmax(yreal) |
|
102 | 102 | |
|
103 | 103 | self.isConfig = True |
|
104 | 104 | |
|
105 | 105 | self.setWinTitle(title) |
|
106 | 106 | |
|
107 | 107 | for i in range(len(self.axesList)): |
|
108 | 108 | title = "Channel %d" %(i) |
|
109 | 109 | axes = self.axesList[i] |
|
110 | 110 | ychannel = yreal[i,:] |
|
111 | 111 | axes.pline(x, ychannel, |
|
112 | 112 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
113 | 113 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
114 | 114 | |
|
115 | 115 | |
|
116 | 116 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
117 | 117 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
118 | 118 | figpath='./', figfile=None, show=True, wr_period=1, |
|
119 | 119 | ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs): |
|
120 | 120 | |
|
121 | 121 | """ |
|
122 | 122 | |
|
123 | 123 | Input: |
|
124 | 124 | dataOut : |
|
125 | 125 | id : |
|
126 | 126 | wintitle : |
|
127 | 127 | channelList : |
|
128 | 128 | xmin : None, |
|
129 | 129 | xmax : None, |
|
130 | 130 | ymin : None, |
|
131 | 131 | ymax : None, |
|
132 | 132 | """ |
|
133 | 133 | if dataOut.flagNoData: |
|
134 | 134 | return dataOut |
|
135 | 135 | |
|
136 | 136 | if channelList == None: |
|
137 | 137 | channelIndexList = dataOut.channelIndexList |
|
138 | 138 | else: |
|
139 | 139 | channelIndexList = [] |
|
140 | 140 | for channel in channelList: |
|
141 | 141 | if channel not in dataOut.channelList: |
|
142 | 142 | raise ValueError("Channel %d is not in dataOut.channelList") |
|
143 | 143 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
144 | 144 | |
|
145 | 145 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
146 | 146 | |
|
147 | 147 | if dataOut.flagDataAsBlock: |
|
148 | 148 | |
|
149 | 149 | for i in range(dataOut.nProfiles): |
|
150 | 150 | |
|
151 | 151 | wintitle1 = wintitle + " [Profile = %d] " %i |
|
152 | 152 | |
|
153 | 153 | if type == "power": |
|
154 | 154 | self.plot_power(dataOut.heightList, |
|
155 | 155 | dataOut.data[:,i,:], |
|
156 | 156 | id, |
|
157 | 157 | channelIndexList, |
|
158 | 158 | thisDatetime, |
|
159 | 159 | wintitle1, |
|
160 | 160 | show, |
|
161 | 161 | xmin, |
|
162 | 162 | xmax, |
|
163 | 163 | ymin, |
|
164 | 164 | ymax) |
|
165 | 165 | |
|
166 | 166 | if type == "iq": |
|
167 | 167 | self.plot_iq(dataOut.heightList, |
|
168 | 168 | dataOut.data[:,i,:], |
|
169 | 169 | id, |
|
170 | 170 | channelIndexList, |
|
171 | 171 | thisDatetime, |
|
172 | 172 | wintitle1, |
|
173 | 173 | show, |
|
174 | 174 | xmin, |
|
175 | 175 | xmax, |
|
176 | 176 | ymin, |
|
177 | 177 | ymax) |
|
178 | 178 | |
|
179 | 179 | self.draw() |
|
180 | 180 | |
|
181 | 181 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
182 | 182 | figfile = self.getFilename(name = str_datetime) + "_" + str(i) |
|
183 | 183 | |
|
184 | 184 | self.save(figpath=figpath, |
|
185 | 185 | figfile=figfile, |
|
186 | 186 | save=save, |
|
187 | 187 | ftp=ftp, |
|
188 | 188 | wr_period=wr_period, |
|
189 | 189 | thisDatetime=thisDatetime) |
|
190 | 190 | |
|
191 | 191 | else: |
|
192 | 192 | wintitle += " [Profile = %d] " %dataOut.profileIndex |
|
193 | 193 | |
|
194 | 194 | if type == "power": |
|
195 | 195 | self.plot_power(dataOut.heightList, |
|
196 | 196 | dataOut.data, |
|
197 | 197 | id, |
|
198 | 198 | channelIndexList, |
|
199 | 199 | thisDatetime, |
|
200 | 200 | wintitle, |
|
201 | 201 | show, |
|
202 | 202 | xmin, |
|
203 | 203 | xmax, |
|
204 | 204 | ymin, |
|
205 | 205 | ymax) |
|
206 | 206 | |
|
207 | 207 | if type == "iq": |
|
208 | 208 | self.plot_iq(dataOut.heightList, |
|
209 | 209 | dataOut.data, |
|
210 | 210 | id, |
|
211 | 211 | channelIndexList, |
|
212 | 212 | thisDatetime, |
|
213 | 213 | wintitle, |
|
214 | 214 | show, |
|
215 | 215 | xmin, |
|
216 | 216 | xmax, |
|
217 | 217 | ymin, |
|
218 | 218 | ymax) |
|
219 | 219 | |
|
220 | 220 | self.draw() |
|
221 | 221 | |
|
222 | 222 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") + "_" + str(dataOut.profileIndex) |
|
223 | 223 | figfile = self.getFilename(name = str_datetime) |
|
224 | 224 | |
|
225 | 225 | self.save(figpath=figpath, |
|
226 | 226 | figfile=figfile, |
|
227 | 227 | save=save, |
|
228 | 228 | ftp=ftp, |
|
229 | 229 | wr_period=wr_period, |
|
230 | 230 | thisDatetime=thisDatetime) |
|
231 | 231 | |
|
232 | 232 | return dataOut No newline at end of file |
@@ -1,501 +1,500 | |||
|
1 | 1 | import os |
|
2 | 2 | import sys |
|
3 | 3 | import datetime |
|
4 | 4 | import numpy |
|
5 | 5 | import matplotlib |
|
6 | 6 | |
|
7 | 7 | if 'BACKEND' in os.environ: |
|
8 | 8 | matplotlib.use(os.environ['BACKEND']) |
|
9 | 9 | elif 'linux' in sys.platform: |
|
10 | 10 | matplotlib.use("TkAgg") |
|
11 | 11 | elif 'darwin' in sys.platform: |
|
12 | 12 | matplotlib.use('TkAgg') |
|
13 | 13 | else: |
|
14 | 14 | from schainpy.utils import log |
|
15 | 15 | log.warning('Using default Backend="Agg"', 'INFO') |
|
16 | 16 | matplotlib.use('Agg') |
|
17 | 17 | # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' |
|
18 | 18 | import matplotlib.pyplot |
|
19 | 19 | |
|
20 | 20 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
21 | 21 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
22 | 22 | |
|
23 | 23 | ########################################### |
|
24 | 24 | # Actualizacion de las funciones del driver |
|
25 | 25 | ########################################### |
|
26 | 26 | |
|
27 | 27 | # create jro colormap |
|
28 | 28 | |
|
29 | 29 | jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90] |
|
30 | 30 | blu_values = matplotlib.pyplot.get_cmap( |
|
31 | 31 | "seismic_r", 20)(numpy.arange(20))[10:15] |
|
32 | 32 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( |
|
33 | 33 | "jro", numpy.vstack((blu_values, jet_values))) |
|
34 | 34 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
35 | 35 | |
|
36 | 36 | |
|
37 | 37 | def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80): |
|
38 | 38 | |
|
39 | 39 | matplotlib.pyplot.ioff() |
|
40 | 40 | |
|
41 | 41 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=( |
|
42 | 42 | 1.0 * width / dpi, 1.0 * height / dpi)) |
|
43 | 43 | fig.canvas.manager.set_window_title(wintitle) |
|
44 | 44 | # fig.canvas.manager.resize(width, height) |
|
45 | 45 | matplotlib.pyplot.ion() |
|
46 | 46 | |
|
47 | 47 | if show: |
|
48 | 48 | matplotlib.pyplot.show() |
|
49 | 49 | |
|
50 | 50 | return fig |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | def closeFigure(show=False, fig=None): |
|
54 | 54 | |
|
55 | 55 | # matplotlib.pyplot.ioff() |
|
56 | 56 | # matplotlib.pyplot.pause(0) |
|
57 | 57 | |
|
58 | 58 | if show: |
|
59 | 59 | matplotlib.pyplot.show() |
|
60 | 60 | |
|
61 | 61 | if fig != None: |
|
62 | 62 | matplotlib.pyplot.close(fig) |
|
63 | 63 | # matplotlib.pyplot.pause(0) |
|
64 | 64 | # matplotlib.pyplot.ion() |
|
65 | 65 | |
|
66 | 66 | return |
|
67 | 67 | |
|
68 | 68 | matplotlib.pyplot.close("all") |
|
69 | 69 | # matplotlib.pyplot.pause(0) |
|
70 | 70 | # matplotlib.pyplot.ion() |
|
71 | 71 | |
|
72 | 72 | return |
|
73 | 73 | |
|
74 | 74 | |
|
75 | 75 | def saveFigure(fig, filename): |
|
76 | 76 | |
|
77 | 77 | # matplotlib.pyplot.ioff() |
|
78 | 78 | fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi) |
|
79 | 79 | # matplotlib.pyplot.ion() |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | def clearFigure(fig): |
|
83 | 83 | |
|
84 | 84 | fig.clf() |
|
85 | 85 | |
|
86 | 86 | |
|
87 | 87 | def setWinTitle(fig, title): |
|
88 | 88 | |
|
89 | 89 | fig.canvas.manager.set_window_title(title) |
|
90 | 90 | |
|
91 | 91 | |
|
92 | 92 | def setTitle(fig, title): |
|
93 | 93 | |
|
94 | 94 | fig.suptitle(title) |
|
95 | 95 | |
|
96 | 96 | |
|
97 | 97 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): |
|
98 | 98 | |
|
99 | 99 | matplotlib.pyplot.ioff() |
|
100 | 100 | matplotlib.pyplot.figure(fig.number) |
|
101 | 101 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
102 | 102 | (xpos, ypos), |
|
103 | 103 | colspan=colspan, |
|
104 | 104 | rowspan=rowspan, |
|
105 | 105 | polar=polar) |
|
106 | 106 | |
|
107 | 107 | matplotlib.pyplot.ion() |
|
108 | 108 | return axes |
|
109 | 109 | |
|
110 | 110 | |
|
111 | 111 | def setAxesText(ax, text): |
|
112 | 112 | |
|
113 | 113 | ax.annotate(text, |
|
114 | 114 | xy=(.1, .99), |
|
115 | 115 | xycoords='figure fraction', |
|
116 | 116 | horizontalalignment='left', |
|
117 | 117 | verticalalignment='top', |
|
118 | 118 | fontsize=10) |
|
119 | 119 | |
|
120 | 120 | |
|
121 | 121 | def printLabels(ax, xlabel, ylabel, title): |
|
122 | 122 | |
|
123 | 123 | ax.set_xlabel(xlabel, size=11) |
|
124 | 124 | ax.set_ylabel(ylabel, size=11) |
|
125 | 125 | ax.set_title(title, size=8) |
|
126 | 126 | |
|
127 | 127 | |
|
128 | 128 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
129 | 129 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
130 | 130 | nxticks=4, nyticks=10, |
|
131 | 131 | grid=None, color='blue'): |
|
132 | 132 | """ |
|
133 | 133 | |
|
134 | 134 | Input: |
|
135 | 135 | grid : None, 'both', 'x', 'y' |
|
136 | 136 | """ |
|
137 | 137 | |
|
138 | 138 | matplotlib.pyplot.ioff() |
|
139 | 139 | |
|
140 | 140 | ax.set_xlim([xmin, xmax]) |
|
141 | 141 | ax.set_ylim([ymin, ymax]) |
|
142 | 142 | |
|
143 | 143 | printLabels(ax, xlabel, ylabel, title) |
|
144 | 144 | |
|
145 | 145 | ###################################################### |
|
146 | 146 | if (xmax - xmin) <= 1: |
|
147 | 147 | xtickspos = numpy.linspace(xmin, xmax, nxticks) |
|
148 | 148 | xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos]) |
|
149 | 149 | ax.set_xticks(xtickspos) |
|
150 | 150 | else: |
|
151 | 151 | xtickspos = numpy.arange(nxticks) * \ |
|
152 | 152 | int((xmax - xmin) / (nxticks)) + int(xmin) |
|
153 | 153 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
154 | 154 | ax.set_xticks(xtickspos) |
|
155 | 155 | |
|
156 | 156 | for tick in ax.get_xticklabels(): |
|
157 | 157 | tick.set_visible(xtick_visible) |
|
158 | 158 | |
|
159 | 159 | for tick in ax.xaxis.get_major_ticks(): |
|
160 | 160 | tick.label.set_fontsize(ticksize) |
|
161 | 161 | |
|
162 | 162 | ###################################################### |
|
163 | 163 | for tick in ax.get_yticklabels(): |
|
164 | 164 | tick.set_visible(ytick_visible) |
|
165 | 165 | |
|
166 | 166 | for tick in ax.yaxis.get_major_ticks(): |
|
167 | 167 | tick.label.set_fontsize(ticksize) |
|
168 | 168 | |
|
169 | 169 | ax.plot(x, y, color=color) |
|
170 | 170 | iplot = ax.lines[-1] |
|
171 | 171 | |
|
172 | 172 | ###################################################### |
|
173 | 173 | if '0.' in matplotlib.__version__[0:2]: |
|
174 | 174 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
175 | 175 | return iplot |
|
176 | 176 | |
|
177 | 177 | if '1.0.' in matplotlib.__version__[0:4]: |
|
178 | 178 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
179 | 179 | return iplot |
|
180 | 180 | |
|
181 | 181 | if grid != None: |
|
182 | 182 | ax.grid(b=True, which='major', axis=grid) |
|
183 | 183 | |
|
184 | 184 | matplotlib.pyplot.tight_layout() |
|
185 | 185 | |
|
186 | 186 | matplotlib.pyplot.ion() |
|
187 | 187 | |
|
188 | 188 | return iplot |
|
189 | 189 | |
|
190 | 190 | |
|
191 | 191 | def set_linedata(ax, x, y, idline): |
|
192 | 192 | |
|
193 | 193 | ax.lines[idline].set_data(x, y) |
|
194 | 194 | |
|
195 | 195 | |
|
196 | 196 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
197 | 197 | |
|
198 | 198 | ax = iplot.axes |
|
199 | 199 | |
|
200 | 200 | printLabels(ax, xlabel, ylabel, title) |
|
201 | 201 | |
|
202 | 202 | set_linedata(ax, x, y, idline=0) |
|
203 | 203 | |
|
204 | 204 | |
|
205 | 205 | def addpline(ax, x, y, color, linestyle, lw): |
|
206 | 206 | |
|
207 | 207 | ax.plot(x, y, color=color, linestyle=linestyle, lw=lw) |
|
208 | 208 | |
|
209 | 209 | |
|
210 | 210 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
211 | 211 | xlabel='', ylabel='', title='', ticksize=9, |
|
212 | 212 | colormap='jet', cblabel='', cbsize="5%", |
|
213 | 213 | XAxisAsTime=False): |
|
214 | 214 | |
|
215 | 215 | matplotlib.pyplot.ioff() |
|
216 | 216 | |
|
217 | 217 | divider = make_axes_locatable(ax) |
|
218 | 218 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
219 | 219 | fig = ax.get_figure() |
|
220 | 220 | fig.add_axes(ax_cb) |
|
221 | 221 | |
|
222 | 222 | ax.set_xlim([xmin, xmax]) |
|
223 | 223 | ax.set_ylim([ymin, ymax]) |
|
224 | 224 | |
|
225 | 225 | printLabels(ax, xlabel, ylabel, title) |
|
226 | 226 | |
|
227 | 227 | z = numpy.ma.masked_invalid(z) |
|
228 | 228 | cmap = matplotlib.pyplot.get_cmap(colormap) |
|
229 | 229 | cmap.set_bad('black', 1.) |
|
230 | 230 | imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap) |
|
231 | 231 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
232 | 232 | cb.set_label(cblabel) |
|
233 | 233 | |
|
234 | 234 | # for tl in ax_cb.get_yticklabels(): |
|
235 | 235 | # tl.set_visible(True) |
|
236 | 236 | |
|
237 | 237 | for tick in ax.yaxis.get_major_ticks(): |
|
238 | 238 | tick.label.set_fontsize(ticksize) |
|
239 | 239 | |
|
240 | 240 | for tick in ax.xaxis.get_major_ticks(): |
|
241 | 241 | tick.label.set_fontsize(ticksize) |
|
242 | 242 | |
|
243 | 243 | for tick in cb.ax.get_yticklabels(): |
|
244 | 244 | tick.set_fontsize(ticksize) |
|
245 | 245 | |
|
246 | 246 | ax_cb.yaxis.tick_right() |
|
247 | 247 | |
|
248 | 248 | if '0.' in matplotlib.__version__[0:2]: |
|
249 | 249 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
250 | 250 | return imesh |
|
251 | 251 | |
|
252 | 252 | if '1.0.' in matplotlib.__version__[0:4]: |
|
253 | 253 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
254 | 254 | return imesh |
|
255 | 255 | |
|
256 | 256 | matplotlib.pyplot.tight_layout() |
|
257 | 257 | |
|
258 | 258 | if XAxisAsTime: |
|
259 | 259 | |
|
260 | 260 | def func(x, pos): return ('%s') % ( |
|
261 | 261 | datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
262 | 262 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
263 | 263 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
264 | 264 | |
|
265 | 265 | matplotlib.pyplot.ion() |
|
266 | 266 | return imesh |
|
267 | 267 | |
|
268 | 268 | |
|
269 | 269 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
270 | 270 | |
|
271 | 271 | z = z.T |
|
272 | 272 | ax = imesh.axes |
|
273 | 273 | printLabels(ax, xlabel, ylabel, title) |
|
274 | 274 | imesh.set_array(z.ravel()) |
|
275 | 275 | |
|
276 | 276 | |
|
277 | 277 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
278 | 278 | |
|
279 | 279 | printLabels(ax, xlabel, ylabel, title) |
|
280 | 280 | |
|
281 | 281 | ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, |
|
282 | 282 | cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
283 | 283 | |
|
284 | 284 | |
|
285 | 285 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
286 | 286 | |
|
287 | 287 | printLabels(ax, xlabel, ylabel, title) |
|
288 | 288 | |
|
289 | 289 | ax.collections.remove(ax.collections[0]) |
|
290 | 290 | |
|
291 | 291 | z = numpy.ma.masked_invalid(z) |
|
292 | 292 | |
|
293 | 293 | cmap = matplotlib.pyplot.get_cmap(colormap) |
|
294 | 294 | cmap.set_bad('black', 1.) |
|
295 | 295 | |
|
296 | 296 | ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap) |
|
297 | 297 | |
|
298 | 298 | |
|
299 | 299 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
300 | 300 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
301 | 301 | nxticks=4, nyticks=10, |
|
302 | 302 | grid=None): |
|
303 | 303 | """ |
|
304 | 304 | |
|
305 | 305 | Input: |
|
306 | 306 | grid : None, 'both', 'x', 'y' |
|
307 | 307 | """ |
|
308 | 308 | |
|
309 | 309 | matplotlib.pyplot.ioff() |
|
310 | 310 | |
|
311 | 311 | lines = ax.plot(x.T, y) |
|
312 | 312 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
313 | 313 | leg.get_frame().set_alpha(0.5) |
|
314 | 314 | ax.set_xlim([xmin, xmax]) |
|
315 | 315 | ax.set_ylim([ymin, ymax]) |
|
316 | 316 | printLabels(ax, xlabel, ylabel, title) |
|
317 | 317 | |
|
318 | 318 | xtickspos = numpy.arange(nxticks) * \ |
|
319 | 319 | int((xmax - xmin) / (nxticks)) + int(xmin) |
|
320 | 320 | ax.set_xticks(xtickspos) |
|
321 | 321 | |
|
322 | 322 | for tick in ax.get_xticklabels(): |
|
323 | 323 | tick.set_visible(xtick_visible) |
|
324 | 324 | |
|
325 | 325 | for tick in ax.xaxis.get_major_ticks(): |
|
326 | 326 | tick.label.set_fontsize(ticksize) |
|
327 | 327 | |
|
328 | 328 | for tick in ax.get_yticklabels(): |
|
329 | 329 | tick.set_visible(ytick_visible) |
|
330 | 330 | |
|
331 | 331 | for tick in ax.yaxis.get_major_ticks(): |
|
332 | 332 | tick.label.set_fontsize(ticksize) |
|
333 | 333 | |
|
334 | 334 | iplot = ax.lines[-1] |
|
335 | 335 | |
|
336 | 336 | if '0.' in matplotlib.__version__[0:2]: |
|
337 | 337 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
338 | 338 | return iplot |
|
339 | 339 | |
|
340 | 340 | if '1.0.' in matplotlib.__version__[0:4]: |
|
341 | 341 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
342 | 342 | return iplot |
|
343 | 343 | |
|
344 | 344 | if grid != None: |
|
345 | 345 | ax.grid(b=True, which='major', axis=grid) |
|
346 | 346 | |
|
347 | 347 | matplotlib.pyplot.tight_layout() |
|
348 | 348 | |
|
349 | 349 | matplotlib.pyplot.ion() |
|
350 | 350 | |
|
351 | 351 | return iplot |
|
352 | 352 | |
|
353 | 353 | |
|
354 | 354 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
355 | 355 | |
|
356 | 356 | ax = iplot.axes |
|
357 | 357 | |
|
358 | 358 | printLabels(ax, xlabel, ylabel, title) |
|
359 | 359 | |
|
360 | 360 | for i in range(len(ax.lines)): |
|
361 | 361 | line = ax.lines[i] |
|
362 | 362 | line.set_data(x[i, :], y) |
|
363 | 363 | |
|
364 | 364 | |
|
365 | 365 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
366 | 366 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
367 | 367 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
368 | 368 | grid=None, XAxisAsTime=False): |
|
369 | 369 | """ |
|
370 | 370 | |
|
371 | 371 | Input: |
|
372 | 372 | grid : None, 'both', 'x', 'y' |
|
373 | 373 | """ |
|
374 | 374 | |
|
375 | 375 | matplotlib.pyplot.ioff() |
|
376 | 376 | |
|
377 | 377 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
378 | 378 | lines = ax.plot(x, y.T) |
|
379 | 379 | # leg = ax.legend(lines, legendlabels, loc=2, bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
380 | 380 | # handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
381 | 381 | |
|
382 | 382 | leg = ax.legend(lines, legendlabels, |
|
383 | 383 | loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0) |
|
384 | 384 | |
|
385 | 385 | for label in leg.get_texts(): |
|
386 | 386 | label.set_fontsize(9) |
|
387 | 387 | |
|
388 | 388 | ax.set_xlim([xmin, xmax]) |
|
389 | 389 | ax.set_ylim([ymin, ymax]) |
|
390 | 390 | printLabels(ax, xlabel, ylabel, title) |
|
391 | 391 | |
|
392 | 392 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
393 | 393 | # ax.set_xticks(xtickspos) |
|
394 | 394 | |
|
395 | 395 | for tick in ax.get_xticklabels(): |
|
396 | 396 | tick.set_visible(xtick_visible) |
|
397 | 397 | |
|
398 | 398 | for tick in ax.xaxis.get_major_ticks(): |
|
399 | 399 | tick.label.set_fontsize(ticksize) |
|
400 | 400 | |
|
401 | 401 | for tick in ax.get_yticklabels(): |
|
402 | 402 | tick.set_visible(ytick_visible) |
|
403 | 403 | |
|
404 | 404 | for tick in ax.yaxis.get_major_ticks(): |
|
405 | 405 | tick.label.set_fontsize(ticksize) |
|
406 | 406 | |
|
407 | 407 | iplot = ax.lines[-1] |
|
408 | 408 | |
|
409 | 409 | if '0.' in matplotlib.__version__[0:2]: |
|
410 | 410 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
411 | 411 | return iplot |
|
412 | 412 | |
|
413 | 413 | if '1.0.' in matplotlib.__version__[0:4]: |
|
414 | 414 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
415 | 415 | return iplot |
|
416 | 416 | |
|
417 | 417 | if grid != None: |
|
418 | 418 | ax.grid(b=True, which='major', axis=grid) |
|
419 | 419 | |
|
420 | 420 | matplotlib.pyplot.tight_layout() |
|
421 | 421 | |
|
422 | 422 | if XAxisAsTime: |
|
423 | 423 | |
|
424 | 424 | def func(x, pos): return ('%s') % ( |
|
425 | 425 | datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
426 | 426 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
427 | 427 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
428 | 428 | |
|
429 | 429 | matplotlib.pyplot.ion() |
|
430 | 430 | |
|
431 | 431 | return iplot |
|
432 | 432 | |
|
433 | 433 | |
|
434 | 434 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
435 | 435 | |
|
436 | 436 | ax = iplot.axes |
|
437 | ||
|
438 | 437 | printLabels(ax, xlabel, ylabel, title) |
|
439 | 438 | |
|
440 | 439 | for i in range(len(ax.lines)): |
|
441 | 440 | line = ax.lines[i] |
|
442 | 441 | line.set_data(x, y[i, :]) |
|
443 | 442 | |
|
444 | 443 | |
|
445 | 444 | def createPolar(ax, x, y, |
|
446 | 445 | xlabel='', ylabel='', title='', ticksize=9, |
|
447 | 446 | colormap='jet', cblabel='', cbsize="5%", |
|
448 | 447 | XAxisAsTime=False): |
|
449 | 448 | |
|
450 | 449 | matplotlib.pyplot.ioff() |
|
451 | 450 | |
|
452 | 451 | ax.plot(x, y, 'bo', markersize=5) |
|
453 | 452 | # ax.set_rmax(90) |
|
454 | 453 | ax.set_ylim(0, 90) |
|
455 | 454 | ax.set_yticks(numpy.arange(0, 90, 20)) |
|
456 | 455 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') |
|
457 | 456 | # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11') |
|
458 | 457 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') |
|
459 | 458 | ax.yaxis.labelpad = 40 |
|
460 | 459 | printLabels(ax, xlabel, ylabel, title) |
|
461 | 460 | iplot = ax.lines[-1] |
|
462 | 461 | |
|
463 | 462 | if '0.' in matplotlib.__version__[0:2]: |
|
464 | 463 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
465 | 464 | return iplot |
|
466 | 465 | |
|
467 | 466 | if '1.0.' in matplotlib.__version__[0:4]: |
|
468 | 467 | print("The matplotlib version has to be updated to 1.1 or newer") |
|
469 | 468 | return iplot |
|
470 | 469 | |
|
471 | 470 | # if grid != None: |
|
472 | 471 | # ax.grid(b=True, which='major', axis=grid) |
|
473 | 472 | |
|
474 | 473 | matplotlib.pyplot.tight_layout() |
|
475 | 474 | |
|
476 | 475 | matplotlib.pyplot.ion() |
|
477 | 476 | |
|
478 | 477 | return iplot |
|
479 | 478 | |
|
480 | 479 | |
|
481 | 480 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): |
|
482 | 481 | |
|
483 | 482 | ax = iplot.axes |
|
484 | 483 | |
|
485 | 484 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') |
|
486 | 485 | printLabels(ax, xlabel, ylabel, title) |
|
487 | 486 | |
|
488 | 487 | set_linedata(ax, x, y, idline=0) |
|
489 | 488 | |
|
490 | 489 | |
|
491 | 490 | def draw(fig): |
|
492 | 491 | |
|
493 | 492 | if type(fig) == 'int': |
|
494 | 493 | raise ValueError("Error drawing: Fig parameter should be a matplotlib figure object figure") |
|
495 | 494 | |
|
496 | 495 | fig.canvas.draw() |
|
497 | 496 | |
|
498 | 497 | |
|
499 | 498 | def pause(interval=0.000001): |
|
500 | 499 | |
|
501 | 500 | matplotlib.pyplot.pause(interval) No newline at end of file |
@@ -1,371 +1,368 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Nov 9, 2016 |
|
3 | 3 | |
|
4 | 4 | @author: roj- LouVD |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | import os |
|
9 | 9 | import sys |
|
10 | 10 | import time |
|
11 | 11 | import glob |
|
12 | 12 | import datetime |
|
13 | 13 | |
|
14 | 14 | import numpy |
|
15 | 15 | |
|
16 |
from schainpy.model.proc.jroproc_base import ProcessingUnit, |
|
|
16 | from schainpy.model.proc.jroproc_base import ProcessingUnit, MPDecorator | |
|
17 | 17 | from schainpy.model.data.jrodata import Parameters |
|
18 | 18 | from schainpy.model.io.jroIO_base import JRODataReader, isNumber |
|
19 | 19 | from schainpy.utils import log |
|
20 | 20 | |
|
21 | 21 | FILE_HEADER_STRUCTURE = numpy.dtype([ |
|
22 | 22 | ('FMN', '<u4'), |
|
23 | 23 | ('nrec', '<u4'), |
|
24 | 24 | ('fr_offset', '<u4'), |
|
25 | 25 | ('id', '<u4'), |
|
26 | 26 | ('site', 'u1', (32,)) |
|
27 | 27 | ]) |
|
28 | 28 | |
|
29 | 29 | REC_HEADER_STRUCTURE = numpy.dtype([ |
|
30 | 30 | ('rmn', '<u4'), |
|
31 | 31 | ('rcounter', '<u4'), |
|
32 | 32 | ('nr_offset', '<u4'), |
|
33 | 33 | ('tr_offset', '<u4'), |
|
34 | 34 | ('time', '<u4'), |
|
35 | 35 | ('time_msec', '<u4'), |
|
36 | 36 | ('tag', 'u1', (32,)), |
|
37 | 37 | ('comments', 'u1', (32,)), |
|
38 | 38 | ('lat', '<f4'), |
|
39 | 39 | ('lon', '<f4'), |
|
40 | 40 | ('gps_status', '<u4'), |
|
41 | 41 | ('freq', '<u4'), |
|
42 | 42 | ('freq0', '<u4'), |
|
43 | 43 | ('nchan', '<u4'), |
|
44 | 44 | ('delta_r', '<u4'), |
|
45 | 45 | ('nranges', '<u4'), |
|
46 | 46 | ('r0', '<u4'), |
|
47 | 47 | ('prf', '<u4'), |
|
48 | 48 | ('ncoh', '<u4'), |
|
49 | 49 | ('npoints', '<u4'), |
|
50 | 50 | ('polarization', '<i4'), |
|
51 | 51 | ('rx_filter', '<u4'), |
|
52 | 52 | ('nmodes', '<u4'), |
|
53 | 53 | ('dmode_index', '<u4'), |
|
54 | 54 | ('dmode_rngcorr', '<u4'), |
|
55 | 55 | ('nrxs', '<u4'), |
|
56 | 56 | ('acf_length', '<u4'), |
|
57 | 57 | ('acf_lags', '<u4'), |
|
58 | 58 | ('sea_to_atmos', '<f4'), |
|
59 | 59 | ('sea_notch', '<u4'), |
|
60 | 60 | ('lh_sea', '<u4'), |
|
61 | 61 | ('hh_sea', '<u4'), |
|
62 | 62 | ('nbins_sea', '<u4'), |
|
63 | 63 | ('min_snr', '<f4'), |
|
64 | 64 | ('min_cc', '<f4'), |
|
65 | 65 | ('max_time_diff', '<f4') |
|
66 | 66 | ]) |
|
67 | 67 | |
|
68 | 68 | DATA_STRUCTURE = numpy.dtype([ |
|
69 | 69 | ('range', '<u4'), |
|
70 | 70 | ('status', '<u4'), |
|
71 | 71 | ('zonal', '<f4'), |
|
72 | 72 | ('meridional', '<f4'), |
|
73 | 73 | ('vertical', '<f4'), |
|
74 | 74 | ('zonal_a', '<f4'), |
|
75 | 75 | ('meridional_a', '<f4'), |
|
76 | 76 | ('corrected_fading', '<f4'), # seconds |
|
77 | 77 | ('uncorrected_fading', '<f4'), # seconds |
|
78 | 78 | ('time_diff', '<f4'), |
|
79 | 79 | ('major_axis', '<f4'), |
|
80 | 80 | ('axial_ratio', '<f4'), |
|
81 | 81 | ('orientation', '<f4'), |
|
82 | 82 | ('sea_power', '<u4'), |
|
83 | 83 | ('sea_algorithm', '<u4') |
|
84 | 84 | ]) |
|
85 | 85 | |
|
86 | 86 | @MPDecorator |
|
87 | 87 | class BLTRParamReader(JRODataReader, ProcessingUnit): |
|
88 | 88 | ''' |
|
89 | 89 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files |
|
90 | 90 | ''' |
|
91 | 91 | |
|
92 | 92 | ext = '.sswma' |
|
93 | 93 | |
|
94 | 94 | def __init__(self): |
|
95 | 95 | |
|
96 | 96 | ProcessingUnit.__init__(self) |
|
97 | 97 | |
|
98 | 98 | self.dataOut = Parameters() |
|
99 | 99 | self.counter_records = 0 |
|
100 | 100 | self.flagNoMoreFiles = 0 |
|
101 | 101 | self.isConfig = False |
|
102 | 102 | self.filename = None |
|
103 | 103 | |
|
104 | 104 | def setup(self, |
|
105 | 105 | path=None, |
|
106 | 106 | startDate=None, |
|
107 | 107 | endDate=None, |
|
108 | 108 | ext=None, |
|
109 | 109 | startTime=datetime.time(0, 0, 0), |
|
110 | 110 | endTime=datetime.time(23, 59, 59), |
|
111 | 111 | timezone=0, |
|
112 | 112 | status_value=0, |
|
113 | 113 | **kwargs): |
|
114 | ||
|
115 | 114 | self.path = path |
|
116 | 115 | self.startDate = startDate |
|
117 | 116 | self.endDate = endDate |
|
118 | 117 | self.startTime = startTime |
|
119 | 118 | self.endTime = endTime |
|
120 | 119 | self.status_value = status_value |
|
121 | 120 | self.datatime = datetime.datetime(1900,1,1) |
|
122 | 121 | |
|
123 | 122 | if self.path is None: |
|
124 | 123 | raise ValueError("The path is not valid") |
|
125 | 124 | |
|
126 | 125 | if ext is None: |
|
127 | 126 | ext = self.ext |
|
128 | 127 | |
|
129 | 128 | self.search_files(self.path, startDate, endDate, ext) |
|
130 | 129 | self.timezone = timezone |
|
131 | 130 | self.fileIndex = 0 |
|
132 | 131 | |
|
133 | 132 | if not self.fileList: |
|
134 | 133 | raise Warning("There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % ( |
|
135 | 134 | path)) |
|
136 | 135 | |
|
137 | 136 | self.setNextFile() |
|
138 | 137 | |
|
139 | 138 | def search_files(self, path, startDate, endDate, ext): |
|
140 | 139 | ''' |
|
141 | 140 | Searching for BLTR rawdata file in path |
|
142 | 141 | Creating a list of file to proces included in [startDate,endDate] |
|
143 | 142 | |
|
144 | 143 | Input: |
|
145 | 144 | path - Path to find BLTR rawdata files |
|
146 | 145 | startDate - Select file from this date |
|
147 | 146 | enDate - Select file until this date |
|
148 | 147 | ext - Extension of the file to read |
|
149 | 148 | ''' |
|
150 | 149 | |
|
151 | 150 | log.success('Searching files in {} '.format(path), 'BLTRParamReader') |
|
152 | 151 | foldercounter = 0 |
|
153 | 152 | fileList0 = glob.glob1(path, "*%s" % ext) |
|
154 | 153 | fileList0.sort() |
|
155 | 154 | |
|
156 | 155 | self.fileList = [] |
|
157 | 156 | self.dateFileList = [] |
|
158 | 157 | |
|
159 | 158 | for thisFile in fileList0: |
|
160 | 159 | year = thisFile[-14:-10] |
|
161 | 160 | if not isNumber(year): |
|
162 | 161 | continue |
|
163 | 162 | |
|
164 | 163 | month = thisFile[-10:-8] |
|
165 | 164 | if not isNumber(month): |
|
166 | 165 | continue |
|
167 | 166 | |
|
168 | 167 | day = thisFile[-8:-6] |
|
169 | 168 | if not isNumber(day): |
|
170 | 169 | continue |
|
171 | 170 | |
|
172 | 171 | year, month, day = int(year), int(month), int(day) |
|
173 | 172 | dateFile = datetime.date(year, month, day) |
|
174 | 173 | |
|
175 | 174 | if (startDate > dateFile) or (endDate < dateFile): |
|
176 | 175 | continue |
|
177 | 176 | |
|
178 | 177 | self.fileList.append(thisFile) |
|
179 | 178 | self.dateFileList.append(dateFile) |
|
180 | 179 | |
|
181 | 180 | return |
|
182 | 181 | |
|
183 | 182 | def setNextFile(self): |
|
184 | 183 | |
|
185 | 184 | file_id = self.fileIndex |
|
186 | 185 | |
|
187 | 186 | if file_id == len(self.fileList): |
|
188 | log.success('No more files in the folder', 'BLTRParamReader') | |
|
189 | 187 | self.flagNoMoreFiles = 1 |
|
190 | 188 | return 0 |
|
191 | 189 | |
|
192 | 190 | log.success('Opening {}'.format(self.fileList[file_id]), 'BLTRParamReader') |
|
193 | 191 | filename = os.path.join(self.path, self.fileList[file_id]) |
|
194 | 192 | |
|
195 | 193 | dirname, name = os.path.split(filename) |
|
196 | 194 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya |
|
197 | 195 | self.siteFile = name.split('.')[0] |
|
198 | 196 | if self.filename is not None: |
|
199 | 197 | self.fp.close() |
|
200 | 198 | self.filename = filename |
|
201 | 199 | self.fp = open(self.filename, 'rb') |
|
202 | 200 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) |
|
203 | 201 | self.nrecords = self.header_file['nrec'][0] |
|
204 | 202 | self.sizeOfFile = os.path.getsize(self.filename) |
|
205 | 203 | self.counter_records = 0 |
|
206 | 204 | self.flagIsNewFile = 0 |
|
207 | 205 | self.fileIndex += 1 |
|
208 | 206 | |
|
209 | 207 | return 1 |
|
210 | 208 | |
|
211 | 209 | def readNextBlock(self): |
|
212 | 210 | |
|
213 | 211 | while True: |
|
214 | 212 | if self.counter_records == self.nrecords: |
|
215 | 213 | self.flagIsNewFile = 1 |
|
216 | 214 | if not self.setNextFile(): |
|
217 | 215 | return 0 |
|
218 | 216 | |
|
219 | 217 | self.readBlock() |
|
220 | 218 | |
|
221 | 219 | if (self.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or \ |
|
222 | 220 | (self.datatime > datetime.datetime.combine(self.endDate, self.endTime)): |
|
223 | 221 | log.warning( |
|
224 | 222 | 'Reading Record No. {}/{} -> {} [Skipping]'.format( |
|
225 | 223 | self.counter_records, |
|
226 | 224 | self.nrecords, |
|
227 | 225 | self.datatime.ctime()), |
|
228 | 226 | 'BLTRParamReader') |
|
229 | 227 | continue |
|
230 | 228 | break |
|
231 | 229 | |
|
232 | 230 | log.log('Reading Record No. {}/{} -> {}'.format( |
|
233 | 231 | self.counter_records, |
|
234 | 232 | self.nrecords, |
|
235 | 233 | self.datatime.ctime()), 'BLTRParamReader') |
|
236 | 234 | |
|
237 | 235 | return 1 |
|
238 | 236 | |
|
239 | 237 | def readBlock(self): |
|
240 | 238 | |
|
241 | 239 | pointer = self.fp.tell() |
|
242 | 240 | header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) |
|
243 | self.nchannels = header_rec['nchan'][0] / 2 | |
|
241 | self.nchannels = int(header_rec['nchan'][0] / 2) | |
|
244 | 242 | self.kchan = header_rec['nrxs'][0] |
|
245 | 243 | self.nmodes = header_rec['nmodes'][0] |
|
246 | 244 | self.nranges = header_rec['nranges'][0] |
|
247 | 245 | self.fp.seek(pointer) |
|
248 | 246 | self.height = numpy.empty((self.nmodes, self.nranges)) |
|
249 | 247 | self.snr = numpy.empty((self.nmodes, int(self.nchannels), self.nranges)) |
|
250 | 248 | self.buffer = numpy.empty((self.nmodes, 3, self.nranges)) |
|
251 | 249 | self.flagDiscontinuousBlock = 0 |
|
252 | 250 | |
|
253 | 251 | for mode in range(self.nmodes): |
|
254 | 252 | self.readHeader() |
|
255 | 253 | data = self.readData() |
|
256 | 254 | self.height[mode] = (data[0] - self.correction) / 1000. |
|
257 | 255 | self.buffer[mode] = data[1] |
|
258 | 256 | self.snr[mode] = data[2] |
|
259 | 257 | |
|
260 | 258 | self.counter_records = self.counter_records + self.nmodes |
|
261 | 259 | |
|
262 | 260 | return |
|
263 | 261 | |
|
264 | 262 | def readHeader(self): |
|
265 | 263 | ''' |
|
266 | 264 | RecordHeader of BLTR rawdata file |
|
267 | 265 | ''' |
|
268 | 266 | |
|
269 | 267 | header_structure = numpy.dtype( |
|
270 | 268 | REC_HEADER_STRUCTURE.descr + [ |
|
271 | 269 | ('antenna_coord', 'f4', (2, int(self.nchannels))), |
|
272 | 270 | ('rx_gains', 'u4', (int(self.nchannels),)), |
|
273 | 271 | ('rx_analysis', 'u4', (int(self.nchannels),)) |
|
274 | 272 | ] |
|
275 | 273 | ) |
|
276 | 274 | |
|
277 | 275 | self.header_rec = numpy.fromfile(self.fp, header_structure, 1) |
|
278 | 276 | self.lat = self.header_rec['lat'][0] |
|
279 | 277 | self.lon = self.header_rec['lon'][0] |
|
280 | 278 | self.delta = self.header_rec['delta_r'][0] |
|
281 | 279 | self.correction = self.header_rec['dmode_rngcorr'][0] |
|
282 | 280 | self.imode = self.header_rec['dmode_index'][0] |
|
283 | 281 | self.antenna = self.header_rec['antenna_coord'] |
|
284 | 282 | self.rx_gains = self.header_rec['rx_gains'] |
|
285 | 283 | self.time = self.header_rec['time'][0] |
|
286 | 284 | dt = datetime.datetime.utcfromtimestamp(self.time) |
|
287 | 285 | if dt.date()>self.datatime.date(): |
|
288 | 286 | self.flagDiscontinuousBlock = 1 |
|
289 | 287 | self.datatime = dt |
|
290 | 288 | |
|
291 | 289 | def readData(self): |
|
292 | 290 | ''' |
|
293 | 291 | Reading and filtering data block record of BLTR rawdata file, filtering is according to status_value. |
|
294 | 292 | |
|
295 | 293 | Input: |
|
296 | 294 | status_value - Array data is set to NAN for values that are not equal to status_value |
|
297 | 295 | |
|
298 | 296 | ''' |
|
299 | 297 | self.nchannels = int(self.nchannels) |
|
300 | 298 | |
|
301 | 299 | data_structure = numpy.dtype( |
|
302 | 300 | DATA_STRUCTURE.descr + [ |
|
303 | 301 | ('rx_saturation', 'u4', (self.nchannels,)), |
|
304 | 302 | ('chan_offset', 'u4', (2 * self.nchannels,)), |
|
305 | 303 | ('rx_amp', 'u4', (self.nchannels,)), |
|
306 | 304 | ('rx_snr', 'f4', (self.nchannels,)), |
|
307 | 305 | ('cross_snr', 'f4', (self.kchan,)), |
|
308 | 306 | ('sea_power_relative', 'f4', (self.kchan,))] |
|
309 | 307 | ) |
|
310 | 308 | |
|
311 | 309 | data = numpy.fromfile(self.fp, data_structure, self.nranges) |
|
312 | 310 | |
|
313 | 311 | height = data['range'] |
|
314 | 312 | winds = numpy.array( |
|
315 | 313 | (data['zonal'], data['meridional'], data['vertical'])) |
|
316 | 314 | snr = data['rx_snr'].T |
|
317 | 315 | |
|
318 | 316 | winds[numpy.where(winds == -9999.)] = numpy.nan |
|
319 | 317 | winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
320 | 318 | snr[numpy.where(snr == -9999.)] = numpy.nan |
|
321 | 319 | snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
322 | 320 | snr = numpy.power(10, snr / 10) |
|
323 | 321 | |
|
324 | 322 | return height, winds, snr |
|
325 | 323 | |
|
326 | 324 | def set_output(self): |
|
327 | 325 | ''' |
|
328 | 326 | Storing data from databuffer to dataOut object |
|
329 | 327 | ''' |
|
330 | 328 | |
|
331 | 329 | self.dataOut.data_SNR = self.snr |
|
332 | 330 | self.dataOut.height = self.height |
|
333 | 331 | self.dataOut.data = self.buffer |
|
334 | 332 | self.dataOut.utctimeInit = self.time |
|
335 | 333 | self.dataOut.utctime = self.dataOut.utctimeInit |
|
336 | 334 | self.dataOut.useLocalTime = False |
|
337 | 335 | self.dataOut.paramInterval = 157 |
|
338 | 336 | self.dataOut.timezone = self.timezone |
|
339 | 337 | self.dataOut.site = self.siteFile |
|
340 | 338 | self.dataOut.nrecords = self.nrecords / self.nmodes |
|
341 | 339 | self.dataOut.sizeOfFile = self.sizeOfFile |
|
342 | 340 | self.dataOut.lat = self.lat |
|
343 | 341 | self.dataOut.lon = self.lon |
|
344 | 342 | self.dataOut.channelList = list(range(self.nchannels)) |
|
345 | 343 | self.dataOut.kchan = self.kchan |
|
346 | 344 | self.dataOut.delta = self.delta |
|
347 | 345 | self.dataOut.correction = self.correction |
|
348 | 346 | self.dataOut.nmodes = self.nmodes |
|
349 | 347 | self.dataOut.imode = self.imode |
|
350 | 348 | self.dataOut.antenna = self.antenna |
|
351 | 349 | self.dataOut.rx_gains = self.rx_gains |
|
352 | 350 | self.dataOut.flagNoData = False |
|
353 | 351 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
354 | 352 | |
|
355 | 353 | def getData(self): |
|
356 | 354 | ''' |
|
357 | 355 | Storing data from databuffer to dataOut object |
|
358 | 356 | ''' |
|
359 | 357 | if self.flagNoMoreFiles: |
|
360 | 358 | self.dataOut.flagNoData = True |
|
361 | log.success('No file left to process', 'BLTRParamReader') | |
|
362 | return 0 | |
|
359 | self.dataOut.error = (1, 'No More files to read') | |
|
363 | 360 | |
|
364 | 361 | if not self.readNextBlock(): |
|
365 | 362 | self.dataOut.flagNoData = True |
|
366 | 363 | return 0 |
|
367 | 364 | |
|
368 | 365 | self.set_output() |
|
369 | 366 | |
|
370 | 367 | return 1 |
|
371 | 368 | No newline at end of file |
@@ -1,1828 +1,1828 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 2, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import sys |
|
8 | 8 | import glob |
|
9 | 9 | import time |
|
10 | 10 | import numpy |
|
11 | 11 | import fnmatch |
|
12 | 12 | import inspect |
|
13 | 13 | import time |
|
14 | 14 | import datetime |
|
15 | 15 | import traceback |
|
16 | 16 | import zmq |
|
17 | 17 | |
|
18 | 18 | try: |
|
19 | 19 | from gevent import sleep |
|
20 | 20 | except: |
|
21 | 21 | from time import sleep |
|
22 | 22 | |
|
23 | 23 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
24 | 24 | from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width |
|
25 | 25 | from schainpy.utils import log |
|
26 | 26 | import schainpy.admin |
|
27 | 27 | |
|
28 | 28 | LOCALTIME = True |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | def isNumber(cad): |
|
32 | 32 | """ |
|
33 | 33 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
34 | 34 | |
|
35 | 35 | Excepciones: |
|
36 | 36 | Si un determinado string no puede ser convertido a numero |
|
37 | 37 | Input: |
|
38 | 38 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
39 | 39 | |
|
40 | 40 | Return: |
|
41 | 41 | True : si el string es uno numerico |
|
42 | 42 | False : no es un string numerico |
|
43 | 43 | """ |
|
44 | 44 | try: |
|
45 | 45 | float(cad) |
|
46 | 46 | return True |
|
47 | 47 | except: |
|
48 | 48 | return False |
|
49 | 49 | |
|
50 | 50 | |
|
51 | 51 | def isFileInEpoch(filename, startUTSeconds, endUTSeconds): |
|
52 | 52 | """ |
|
53 | 53 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
54 | 54 | |
|
55 | 55 | Inputs: |
|
56 | 56 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
57 | 57 | |
|
58 | 58 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
59 | 59 | segundos contados desde 01/01/1970. |
|
60 | 60 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
61 | 61 | segundos contados desde 01/01/1970. |
|
62 | 62 | |
|
63 | 63 | Return: |
|
64 | 64 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
65 | 65 | fecha especificado, de lo contrario retorna False. |
|
66 | 66 | |
|
67 | 67 | Excepciones: |
|
68 | 68 | Si el archivo no existe o no puede ser abierto |
|
69 | 69 | Si la cabecera no puede ser leida. |
|
70 | 70 | |
|
71 | 71 | """ |
|
72 | 72 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
73 | 73 | |
|
74 | 74 | try: |
|
75 | 75 | fp = open(filename, 'rb') |
|
76 | 76 | except IOError: |
|
77 | 77 | print("The file %s can't be opened" % (filename)) |
|
78 | 78 | return 0 |
|
79 | 79 | |
|
80 | 80 | sts = basicHeaderObj.read(fp) |
|
81 | 81 | fp.close() |
|
82 | 82 | |
|
83 | 83 | if not(sts): |
|
84 | 84 | print("Skipping the file %s because it has not a valid header" % (filename)) |
|
85 | 85 | return 0 |
|
86 | 86 | |
|
87 | 87 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
88 | 88 | return 0 |
|
89 | 89 | |
|
90 | 90 | return 1 |
|
91 | 91 | |
|
92 | 92 | |
|
93 | 93 | def isTimeInRange(thisTime, startTime, endTime): |
|
94 | 94 | if endTime >= startTime: |
|
95 | 95 | if (thisTime < startTime) or (thisTime > endTime): |
|
96 | 96 | return 0 |
|
97 | 97 | return 1 |
|
98 | 98 | else: |
|
99 | 99 | if (thisTime < startTime) and (thisTime > endTime): |
|
100 | 100 | return 0 |
|
101 | 101 | return 1 |
|
102 | 102 | |
|
103 | 103 | |
|
104 | 104 | def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): |
|
105 | 105 | """ |
|
106 | 106 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
107 | 107 | |
|
108 | 108 | Inputs: |
|
109 | 109 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
110 | 110 | |
|
111 | 111 | startDate : fecha inicial del rango seleccionado en formato datetime.date |
|
112 | 112 | |
|
113 | 113 | endDate : fecha final del rango seleccionado en formato datetime.date |
|
114 | 114 | |
|
115 | 115 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
116 | 116 | |
|
117 | 117 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
118 | 118 | |
|
119 | 119 | Return: |
|
120 | 120 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
121 | 121 | fecha especificado, de lo contrario retorna False. |
|
122 | 122 | |
|
123 | 123 | Excepciones: |
|
124 | 124 | Si el archivo no existe o no puede ser abierto |
|
125 | 125 | Si la cabecera no puede ser leida. |
|
126 | 126 | |
|
127 | 127 | """ |
|
128 | 128 | |
|
129 | 129 | try: |
|
130 | 130 | fp = open(filename, 'rb') |
|
131 | 131 | except IOError: |
|
132 | 132 | print("The file %s can't be opened" % (filename)) |
|
133 | 133 | return None |
|
134 | 134 | |
|
135 | 135 | firstBasicHeaderObj = BasicHeader(LOCALTIME) |
|
136 | 136 | systemHeaderObj = SystemHeader() |
|
137 | 137 | radarControllerHeaderObj = RadarControllerHeader() |
|
138 | 138 | processingHeaderObj = ProcessingHeader() |
|
139 | 139 | |
|
140 | 140 | lastBasicHeaderObj = BasicHeader(LOCALTIME) |
|
141 | 141 | |
|
142 | 142 | sts = firstBasicHeaderObj.read(fp) |
|
143 | 143 | |
|
144 | 144 | if not(sts): |
|
145 | 145 | print("[Reading] Skipping the file %s because it has not a valid header" % (filename)) |
|
146 | 146 | return None |
|
147 | 147 | |
|
148 | 148 | if not systemHeaderObj.read(fp): |
|
149 | 149 | return None |
|
150 | 150 | |
|
151 | 151 | if not radarControllerHeaderObj.read(fp): |
|
152 | 152 | return None |
|
153 | 153 | |
|
154 | 154 | if not processingHeaderObj.read(fp): |
|
155 | 155 | return None |
|
156 | 156 | |
|
157 | 157 | filesize = os.path.getsize(filename) |
|
158 | 158 | |
|
159 | 159 | offset = processingHeaderObj.blockSize + 24 # header size |
|
160 | 160 | |
|
161 | 161 | if filesize <= offset: |
|
162 | 162 | print("[Reading] %s: This file has not enough data" % filename) |
|
163 | 163 | return None |
|
164 | 164 | |
|
165 | 165 | fp.seek(-offset, 2) |
|
166 | 166 | |
|
167 | 167 | sts = lastBasicHeaderObj.read(fp) |
|
168 | 168 | |
|
169 | 169 | fp.close() |
|
170 | 170 | |
|
171 | 171 | thisDatetime = lastBasicHeaderObj.datatime |
|
172 | 172 | thisTime_last_block = thisDatetime.time() |
|
173 | 173 | |
|
174 | 174 | thisDatetime = firstBasicHeaderObj.datatime |
|
175 | 175 | thisDate = thisDatetime.date() |
|
176 | 176 | thisTime_first_block = thisDatetime.time() |
|
177 | 177 | |
|
178 | 178 | # General case |
|
179 | 179 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o |
|
180 | 180 | #-----------o----------------------------o----------- |
|
181 | 181 | # startTime endTime |
|
182 | 182 | |
|
183 | 183 | if endTime >= startTime: |
|
184 | 184 | if (thisTime_last_block < startTime) or (thisTime_first_block > endTime): |
|
185 | 185 | return None |
|
186 | 186 | |
|
187 | 187 | return thisDatetime |
|
188 | 188 | |
|
189 | 189 | # If endTime < startTime then endTime belongs to the next day |
|
190 | 190 | |
|
191 | 191 | #<<<<<<<<<<<o o>>>>>>>>>>> |
|
192 | 192 | #-----------o----------------------------o----------- |
|
193 | 193 | # endTime startTime |
|
194 | 194 | |
|
195 | 195 | if (thisDate == startDate) and (thisTime_last_block < startTime): |
|
196 | 196 | return None |
|
197 | 197 | |
|
198 | 198 | if (thisDate == endDate) and (thisTime_first_block > endTime): |
|
199 | 199 | return None |
|
200 | 200 | |
|
201 | 201 | if (thisTime_last_block < startTime) and (thisTime_first_block > endTime): |
|
202 | 202 | return None |
|
203 | 203 | |
|
204 | 204 | return thisDatetime |
|
205 | 205 | |
|
206 | 206 | |
|
207 | 207 | def isFolderInDateRange(folder, startDate=None, endDate=None): |
|
208 | 208 | """ |
|
209 | 209 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
210 | 210 | |
|
211 | 211 | Inputs: |
|
212 | 212 | folder : nombre completo del directorio. |
|
213 | 213 | Su formato deberia ser "/path_root/?YYYYDDD" |
|
214 | 214 | |
|
215 | 215 | siendo: |
|
216 | 216 | YYYY : Anio (ejemplo 2015) |
|
217 | 217 | DDD : Dia del anio (ejemplo 305) |
|
218 | 218 | |
|
219 | 219 | startDate : fecha inicial del rango seleccionado en formato datetime.date |
|
220 | 220 | |
|
221 | 221 | endDate : fecha final del rango seleccionado en formato datetime.date |
|
222 | 222 | |
|
223 | 223 | Return: |
|
224 | 224 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
225 | 225 | fecha especificado, de lo contrario retorna False. |
|
226 | 226 | Excepciones: |
|
227 | 227 | Si el directorio no tiene el formato adecuado |
|
228 | 228 | """ |
|
229 | 229 | |
|
230 | 230 | basename = os.path.basename(folder) |
|
231 | 231 | |
|
232 | 232 | if not isRadarFolder(basename): |
|
233 | 233 | print("The folder %s has not the rigth format" % folder) |
|
234 | 234 | return 0 |
|
235 | 235 | |
|
236 | 236 | if startDate and endDate: |
|
237 | 237 | thisDate = getDateFromRadarFolder(basename) |
|
238 | 238 | |
|
239 | 239 | if thisDate < startDate: |
|
240 | 240 | return 0 |
|
241 | 241 | |
|
242 | 242 | if thisDate > endDate: |
|
243 | 243 | return 0 |
|
244 | 244 | |
|
245 | 245 | return 1 |
|
246 | 246 | |
|
247 | 247 | |
|
248 | 248 | def isFileInDateRange(filename, startDate=None, endDate=None): |
|
249 | 249 | """ |
|
250 | 250 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
251 | 251 | |
|
252 | 252 | Inputs: |
|
253 | 253 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
254 | 254 | |
|
255 | 255 | Su formato deberia ser "?YYYYDDDsss" |
|
256 | 256 | |
|
257 | 257 | siendo: |
|
258 | 258 | YYYY : Anio (ejemplo 2015) |
|
259 | 259 | DDD : Dia del anio (ejemplo 305) |
|
260 | 260 | sss : set |
|
261 | 261 | |
|
262 | 262 | startDate : fecha inicial del rango seleccionado en formato datetime.date |
|
263 | 263 | |
|
264 | 264 | endDate : fecha final del rango seleccionado en formato datetime.date |
|
265 | 265 | |
|
266 | 266 | Return: |
|
267 | 267 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
268 | 268 | fecha especificado, de lo contrario retorna False. |
|
269 | 269 | Excepciones: |
|
270 | 270 | Si el archivo no tiene el formato adecuado |
|
271 | 271 | """ |
|
272 | 272 | |
|
273 | 273 | basename = os.path.basename(filename) |
|
274 | 274 | |
|
275 | 275 | if not isRadarFile(basename): |
|
276 | 276 | print("The filename %s has not the rigth format" % filename) |
|
277 | 277 | return 0 |
|
278 | 278 | |
|
279 | 279 | if startDate and endDate: |
|
280 | 280 | thisDate = getDateFromRadarFile(basename) |
|
281 | 281 | |
|
282 | 282 | if thisDate < startDate: |
|
283 | 283 | return 0 |
|
284 | 284 | |
|
285 | 285 | if thisDate > endDate: |
|
286 | 286 | return 0 |
|
287 | 287 | |
|
288 | 288 | return 1 |
|
289 | 289 | |
|
290 | 290 | |
|
291 | 291 | def getFileFromSet(path, ext, set): |
|
292 | 292 | validFilelist = [] |
|
293 | 293 | fileList = os.listdir(path) |
|
294 | 294 | |
|
295 | 295 | # 0 1234 567 89A BCDE |
|
296 | 296 | # H YYYY DDD SSS .ext |
|
297 | 297 | |
|
298 | 298 | for thisFile in fileList: |
|
299 | 299 | try: |
|
300 | 300 | year = int(thisFile[1:5]) |
|
301 | 301 | doy = int(thisFile[5:8]) |
|
302 | 302 | except: |
|
303 | 303 | continue |
|
304 | 304 | |
|
305 | 305 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
306 | 306 | continue |
|
307 | 307 | |
|
308 | 308 | validFilelist.append(thisFile) |
|
309 | 309 | |
|
310 | 310 | myfile = fnmatch.filter( |
|
311 | 311 | validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set)) |
|
312 | 312 | |
|
313 | 313 | if len(myfile) != 0: |
|
314 | 314 | return myfile[0] |
|
315 | 315 | else: |
|
316 | 316 | filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower()) |
|
317 | 317 | print('the filename %s does not exist' % filename) |
|
318 | 318 | print('...going to the last file: ') |
|
319 | 319 | |
|
320 | 320 | if validFilelist: |
|
321 | 321 | validFilelist = sorted(validFilelist, key=str.lower) |
|
322 | 322 | return validFilelist[-1] |
|
323 | 323 | |
|
324 | 324 | return None |
|
325 | 325 | |
|
326 | 326 | |
|
327 | 327 | def getlastFileFromPath(path, ext): |
|
328 | 328 | """ |
|
329 | 329 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
330 | 330 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
331 | 331 | |
|
332 | 332 | Input: |
|
333 | 333 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
334 | 334 | ext : extension de los files contenidos en una carpeta |
|
335 | 335 | |
|
336 | 336 | Return: |
|
337 | 337 | El ultimo file de una determinada carpeta, no se considera el path. |
|
338 | 338 | """ |
|
339 | 339 | validFilelist = [] |
|
340 | 340 | fileList = os.listdir(path) |
|
341 | 341 | |
|
342 | 342 | # 0 1234 567 89A BCDE |
|
343 | 343 | # H YYYY DDD SSS .ext |
|
344 | 344 | |
|
345 | 345 | for thisFile in fileList: |
|
346 | 346 | |
|
347 | 347 | year = thisFile[1:5] |
|
348 | 348 | if not isNumber(year): |
|
349 | 349 | continue |
|
350 | 350 | |
|
351 | 351 | doy = thisFile[5:8] |
|
352 | 352 | if not isNumber(doy): |
|
353 | 353 | continue |
|
354 | 354 | |
|
355 | 355 | year = int(year) |
|
356 | 356 | doy = int(doy) |
|
357 | 357 | |
|
358 | 358 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
359 | 359 | continue |
|
360 | 360 | |
|
361 | 361 | validFilelist.append(thisFile) |
|
362 | 362 | |
|
363 | 363 | if validFilelist: |
|
364 | 364 | validFilelist = sorted(validFilelist, key=str.lower) |
|
365 | 365 | return validFilelist[-1] |
|
366 | 366 | |
|
367 | 367 | return None |
|
368 | 368 | |
|
369 | 369 | |
|
370 | 370 | def checkForRealPath(path, foldercounter, year, doy, set, ext): |
|
371 | 371 | """ |
|
372 | 372 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
373 | 373 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
374 | 374 | el path exacto de un determinado file. |
|
375 | 375 | |
|
376 | 376 | Example : |
|
377 | 377 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
378 | 378 | |
|
379 | 379 | Entonces la funcion prueba con las siguientes combinaciones |
|
380 | 380 | .../.../y2009307367.ext |
|
381 | 381 | .../.../Y2009307367.ext |
|
382 | 382 | .../.../x2009307/y2009307367.ext |
|
383 | 383 | .../.../x2009307/Y2009307367.ext |
|
384 | 384 | .../.../X2009307/y2009307367.ext |
|
385 | 385 | .../.../X2009307/Y2009307367.ext |
|
386 | 386 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
387 | 387 | |
|
388 | 388 | Return: |
|
389 | 389 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
390 | 390 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
391 | 391 | para el filename |
|
392 | 392 | """ |
|
393 | 393 | fullfilename = None |
|
394 | 394 | find_flag = False |
|
395 | 395 | filename = None |
|
396 | 396 | |
|
397 | 397 | prefixDirList = [None, 'd', 'D'] |
|
398 | 398 | if ext.lower() == ".r": # voltage |
|
399 | 399 | prefixFileList = ['d', 'D'] |
|
400 | 400 | elif ext.lower() == ".pdata": # spectra |
|
401 | 401 | prefixFileList = ['p', 'P'] |
|
402 | 402 | else: |
|
403 | 403 | return None, filename |
|
404 | 404 | |
|
405 | 405 | # barrido por las combinaciones posibles |
|
406 | 406 | for prefixDir in prefixDirList: |
|
407 | 407 | thispath = path |
|
408 | 408 | if prefixDir != None: |
|
409 | 409 | # formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
410 | 410 | if foldercounter == 0: |
|
411 | 411 | thispath = os.path.join(path, "%s%04d%03d" % |
|
412 | 412 | (prefixDir, year, doy)) |
|
413 | 413 | else: |
|
414 | 414 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( |
|
415 | 415 | prefixDir, year, doy, foldercounter)) |
|
416 | 416 | for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D" |
|
417 | 417 | # formo el nombre del file xYYYYDDDSSS.ext |
|
418 | 418 | filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext) |
|
419 | 419 | fullfilename = os.path.join( |
|
420 | 420 | thispath, filename) # formo el path completo |
|
421 | 421 | |
|
422 | 422 | if os.path.exists(fullfilename): # verifico que exista |
|
423 | 423 | find_flag = True |
|
424 | 424 | break |
|
425 | 425 | if find_flag: |
|
426 | 426 | break |
|
427 | 427 | |
|
428 | 428 | if not(find_flag): |
|
429 | 429 | return None, filename |
|
430 | 430 | |
|
431 | 431 | return fullfilename, filename |
|
432 | 432 | |
|
433 | 433 | |
|
434 | 434 | def isRadarFolder(folder): |
|
435 | 435 | try: |
|
436 | 436 | year = int(folder[1:5]) |
|
437 | 437 | doy = int(folder[5:8]) |
|
438 | 438 | except: |
|
439 | 439 | return 0 |
|
440 | 440 | |
|
441 | 441 | return 1 |
|
442 | 442 | |
|
443 | 443 | |
|
444 | 444 | def isRadarFile(file): |
|
445 | 445 | try: |
|
446 | 446 | year = int(file[1:5]) |
|
447 | 447 | doy = int(file[5:8]) |
|
448 | 448 | set = int(file[8:11]) |
|
449 | 449 | except: |
|
450 | 450 | return 0 |
|
451 | 451 | |
|
452 | 452 | return 1 |
|
453 | 453 | |
|
454 | 454 | |
|
455 | 455 | def getDateFromRadarFile(file): |
|
456 | 456 | try: |
|
457 | 457 | year = int(file[1:5]) |
|
458 | 458 | doy = int(file[5:8]) |
|
459 | 459 | set = int(file[8:11]) |
|
460 | 460 | except: |
|
461 | 461 | return None |
|
462 | 462 | |
|
463 | 463 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1) |
|
464 | 464 | return thisDate |
|
465 | 465 | |
|
466 | 466 | |
|
467 | 467 | def getDateFromRadarFolder(folder): |
|
468 | 468 | try: |
|
469 | 469 | year = int(folder[1:5]) |
|
470 | 470 | doy = int(folder[5:8]) |
|
471 | 471 | except: |
|
472 | 472 | return None |
|
473 | 473 | |
|
474 | 474 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1) |
|
475 | 475 | return thisDate |
|
476 | 476 | |
|
477 | 477 | |
|
478 | 478 | class JRODataIO: |
|
479 | 479 | |
|
480 | 480 | c = 3E8 |
|
481 | 481 | |
|
482 | 482 | isConfig = False |
|
483 | 483 | |
|
484 | 484 | basicHeaderObj = None |
|
485 | 485 | |
|
486 | 486 | systemHeaderObj = None |
|
487 | 487 | |
|
488 | 488 | radarControllerHeaderObj = None |
|
489 | 489 | |
|
490 | 490 | processingHeaderObj = None |
|
491 | 491 | |
|
492 | 492 | dtype = None |
|
493 | 493 | |
|
494 | 494 | pathList = [] |
|
495 | 495 | |
|
496 | 496 | filenameList = [] |
|
497 | 497 | |
|
498 | 498 | filename = None |
|
499 | 499 | |
|
500 | 500 | ext = None |
|
501 | 501 | |
|
502 | 502 | flagIsNewFile = 1 |
|
503 | 503 | |
|
504 | 504 | flagDiscontinuousBlock = 0 |
|
505 | 505 | |
|
506 | 506 | flagIsNewBlock = 0 |
|
507 | 507 | |
|
508 | 508 | fp = None |
|
509 | 509 | |
|
510 | 510 | firstHeaderSize = 0 |
|
511 | 511 | |
|
512 | 512 | basicHeaderSize = 24 |
|
513 | 513 | |
|
514 | 514 | versionFile = 1103 |
|
515 | 515 | |
|
516 | 516 | fileSize = None |
|
517 | 517 | |
|
518 | 518 | # ippSeconds = None |
|
519 | 519 | |
|
520 | 520 | fileSizeByHeader = None |
|
521 | 521 | |
|
522 | 522 | fileIndex = None |
|
523 | 523 | |
|
524 | 524 | profileIndex = None |
|
525 | 525 | |
|
526 | 526 | blockIndex = None |
|
527 | 527 | |
|
528 | 528 | nTotalBlocks = None |
|
529 | 529 | |
|
530 | 530 | maxTimeStep = 30 |
|
531 | 531 | |
|
532 | 532 | lastUTTime = None |
|
533 | 533 | |
|
534 | 534 | datablock = None |
|
535 | 535 | |
|
536 | 536 | dataOut = None |
|
537 | 537 | |
|
538 | 538 | blocksize = None |
|
539 | 539 | |
|
540 | 540 | getByBlock = False |
|
541 | 541 | |
|
542 | 542 | def __init__(self): |
|
543 | 543 | |
|
544 | 544 | raise NotImplementedError |
|
545 | 545 | |
|
546 | 546 | def run(self): |
|
547 | 547 | |
|
548 | 548 | raise NotImplementedError |
|
549 | 549 | |
|
550 | 550 | def getDtypeWidth(self): |
|
551 | 551 | |
|
552 | 552 | dtype_index = get_dtype_index(self.dtype) |
|
553 | 553 | dtype_width = get_dtype_width(dtype_index) |
|
554 | 554 | |
|
555 | 555 | return dtype_width |
|
556 | 556 | |
|
557 | 557 | def getAllowedArgs(self): |
|
558 | 558 | if hasattr(self, '__attrs__'): |
|
559 | 559 | return self.__attrs__ |
|
560 | 560 | else: |
|
561 | 561 | return inspect.getargspec(self.run).args |
|
562 | 562 | |
|
563 | 563 | |
|
564 | 564 | class JRODataReader(JRODataIO): |
|
565 | 565 | |
|
566 | 566 | online = 0 |
|
567 | 567 | |
|
568 | 568 | realtime = 0 |
|
569 | 569 | |
|
570 | 570 | nReadBlocks = 0 |
|
571 | 571 | |
|
572 | 572 | delay = 10 # number of seconds waiting a new file |
|
573 | 573 | |
|
574 | 574 | nTries = 3 # quantity tries |
|
575 | 575 | |
|
576 | 576 | nFiles = 3 # number of files for searching |
|
577 | 577 | |
|
578 | 578 | path = None |
|
579 | 579 | |
|
580 | 580 | foldercounter = 0 |
|
581 | 581 | |
|
582 | 582 | flagNoMoreFiles = 0 |
|
583 | 583 | |
|
584 | 584 | datetimeList = [] |
|
585 | 585 | |
|
586 | 586 | __isFirstTimeOnline = 1 |
|
587 | 587 | |
|
588 | 588 | __printInfo = True |
|
589 | 589 | |
|
590 | 590 | profileIndex = None |
|
591 | 591 | |
|
592 | 592 | nTxs = 1 |
|
593 | 593 | |
|
594 | 594 | txIndex = None |
|
595 | 595 | |
|
596 | 596 | # Added-------------------- |
|
597 | 597 | |
|
598 | 598 | selBlocksize = None |
|
599 | 599 | |
|
600 | 600 | selBlocktime = None |
|
601 | 601 | |
|
602 | 602 | def __init__(self): |
|
603 | 603 | """ |
|
604 | 604 | This class is used to find data files |
|
605 | 605 | |
|
606 | 606 | Example: |
|
607 | 607 | reader = JRODataReader() |
|
608 | 608 | fileList = reader.findDataFiles() |
|
609 | 609 | |
|
610 | 610 | """ |
|
611 | 611 | pass |
|
612 | 612 | |
|
613 | 613 | def createObjByDefault(self): |
|
614 | 614 | """ |
|
615 | 615 | |
|
616 | 616 | """ |
|
617 | 617 | raise NotImplementedError |
|
618 | 618 | |
|
619 | 619 | def getBlockDimension(self): |
|
620 | 620 | |
|
621 | 621 | raise NotImplementedError |
|
622 | 622 | |
|
623 | 623 | def searchFilesOffLine(self, |
|
624 | 624 | path, |
|
625 | 625 | startDate=None, |
|
626 | 626 | endDate=None, |
|
627 | 627 | startTime=datetime.time(0, 0, 0), |
|
628 | 628 | endTime=datetime.time(23, 59, 59), |
|
629 | 629 | set=None, |
|
630 | 630 | expLabel='', |
|
631 | 631 | ext='.r', |
|
632 | 632 | cursor=None, |
|
633 | 633 | skip=None, |
|
634 | 634 | walk=True): |
|
635 | 635 | |
|
636 | 636 | self.filenameList = [] |
|
637 | 637 | self.datetimeList = [] |
|
638 | 638 | |
|
639 | 639 | pathList = [] |
|
640 | 640 | |
|
641 | 641 | dateList, pathList = self.findDatafiles( |
|
642 | 642 | path, startDate, endDate, expLabel, ext, walk, include_path=True) |
|
643 | 643 | |
|
644 | 644 | if dateList == []: |
|
645 | 645 | return [], [] |
|
646 | 646 | |
|
647 | 647 | if len(dateList) > 1: |
|
648 | 648 | print("[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList))) |
|
649 | 649 | else: |
|
650 | 650 | print("[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0])) |
|
651 | 651 | |
|
652 | 652 | filenameList = [] |
|
653 | 653 | datetimeList = [] |
|
654 | 654 | |
|
655 | 655 | for thisPath in pathList: |
|
656 | 656 | |
|
657 | 657 | fileList = glob.glob1(thisPath, "*%s" % ext) |
|
658 | 658 | fileList.sort() |
|
659 | 659 | |
|
660 | 660 | for file in fileList: |
|
661 | 661 | |
|
662 | 662 | filename = os.path.join(thisPath, file) |
|
663 | 663 | |
|
664 | 664 | if not isFileInDateRange(filename, startDate, endDate): |
|
665 | 665 | continue |
|
666 | 666 | |
|
667 | 667 | thisDatetime = isFileInTimeRange( |
|
668 | 668 | filename, startDate, endDate, startTime, endTime) |
|
669 | 669 | |
|
670 | 670 | if not(thisDatetime): |
|
671 | 671 | continue |
|
672 | 672 | |
|
673 | 673 | filenameList.append(filename) |
|
674 | 674 | datetimeList.append(thisDatetime) |
|
675 | 675 | |
|
676 | 676 | if cursor is not None and skip is not None: |
|
677 | 677 | filenameList = filenameList[cursor * skip:cursor * skip + skip] |
|
678 | 678 | datetimeList = datetimeList[cursor * skip:cursor * skip + skip] |
|
679 | 679 | |
|
680 | 680 | if not(filenameList): |
|
681 | 681 | print("[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path)) |
|
682 | 682 | return [], [] |
|
683 | 683 | |
|
684 | 684 | print("[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime)) |
|
685 | 685 | |
|
686 | 686 | # for i in range(len(filenameList)): |
|
687 | 687 | # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
688 | 688 | |
|
689 | 689 | self.filenameList = filenameList |
|
690 | 690 | self.datetimeList = datetimeList |
|
691 | 691 | |
|
692 | 692 | return pathList, filenameList |
|
693 | 693 | |
|
694 | 694 | def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None): |
|
695 | 695 | """ |
|
696 | 696 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
697 | 697 | devuelve el archivo encontrado ademas de otros datos. |
|
698 | 698 | |
|
699 | 699 | Input: |
|
700 | 700 | path : carpeta donde estan contenidos los files que contiene data |
|
701 | 701 | |
|
702 | 702 | expLabel : Nombre del subexperimento (subfolder) |
|
703 | 703 | |
|
704 | 704 | ext : extension de los files |
|
705 | 705 | |
|
706 | 706 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
707 | 707 | |
|
708 | 708 | Return: |
|
709 | 709 | directory : eL directorio donde esta el file encontrado |
|
710 | 710 | filename : el ultimo file de una determinada carpeta |
|
711 | 711 | year : el anho |
|
712 | 712 | doy : el numero de dia del anho |
|
713 | 713 | set : el set del archivo |
|
714 | 714 | |
|
715 | 715 | |
|
716 | 716 | """ |
|
717 | 717 | if not os.path.isdir(path): |
|
718 | 718 | return None, None, None, None, None, None |
|
719 | 719 | |
|
720 | 720 | dirList = [] |
|
721 | 721 | |
|
722 | 722 | if not walk: |
|
723 | 723 | fullpath = path |
|
724 | 724 | foldercounter = 0 |
|
725 | 725 | else: |
|
726 | 726 | # Filtra solo los directorios |
|
727 | 727 | for thisPath in os.listdir(path): |
|
728 | 728 | if not os.path.isdir(os.path.join(path, thisPath)): |
|
729 | 729 | continue |
|
730 | 730 | if not isRadarFolder(thisPath): |
|
731 | 731 | continue |
|
732 | 732 | |
|
733 | 733 | dirList.append(thisPath) |
|
734 | 734 | |
|
735 | 735 | if not(dirList): |
|
736 | 736 | return None, None, None, None, None, None |
|
737 | 737 | |
|
738 | 738 | dirList = sorted(dirList, key=str.lower) |
|
739 | 739 | |
|
740 | 740 | doypath = dirList[-1] |
|
741 | 741 | foldercounter = int(doypath.split('_')[1]) if len( |
|
742 | 742 | doypath.split('_')) > 1 else 0 |
|
743 | 743 | fullpath = os.path.join(path, doypath, expLabel) |
|
744 | 744 | |
|
745 | 745 | print("[Reading] %s folder was found: " % (fullpath)) |
|
746 | 746 | |
|
747 | 747 | if set == None: |
|
748 | 748 | filename = getlastFileFromPath(fullpath, ext) |
|
749 | 749 | else: |
|
750 | 750 | filename = getFileFromSet(fullpath, ext, set) |
|
751 | 751 | |
|
752 | 752 | if not(filename): |
|
753 | 753 | return None, None, None, None, None, None |
|
754 | 754 | |
|
755 | 755 | print("[Reading] %s file was found" % (filename)) |
|
756 | 756 | |
|
757 | 757 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
758 | 758 | return None, None, None, None, None, None |
|
759 | 759 | |
|
760 | 760 | year = int(filename[1:5]) |
|
761 | 761 | doy = int(filename[5:8]) |
|
762 | 762 | set = int(filename[8:11]) |
|
763 | 763 | |
|
764 | 764 | return fullpath, foldercounter, filename, year, doy, set |
|
765 | 765 | |
|
766 | 766 | def __setNextFileOffline(self): |
|
767 | 767 | |
|
768 | 768 | idFile = self.fileIndex |
|
769 | 769 | |
|
770 | 770 | while (True): |
|
771 | 771 | idFile += 1 |
|
772 | 772 | if not(idFile < len(self.filenameList)): |
|
773 | 773 | self.flagNoMoreFiles = 1 |
|
774 | 774 | # print "[Reading] No more Files" |
|
775 | 775 | return 0 |
|
776 | 776 | |
|
777 | 777 | filename = self.filenameList[idFile] |
|
778 | 778 | |
|
779 | 779 | if not(self.__verifyFile(filename)): |
|
780 | 780 | continue |
|
781 | 781 | |
|
782 | 782 | fileSize = os.path.getsize(filename) |
|
783 | 783 | fp = open(filename, 'rb') |
|
784 | 784 | break |
|
785 | 785 | |
|
786 | 786 | self.flagIsNewFile = 1 |
|
787 | 787 | self.fileIndex = idFile |
|
788 | 788 | self.filename = filename |
|
789 | 789 | self.fileSize = fileSize |
|
790 | 790 | self.fp = fp |
|
791 | 791 | |
|
792 | 792 | # print "[Reading] Setting the file: %s"%self.filename |
|
793 | 793 | |
|
794 | 794 | return 1 |
|
795 | 795 | |
|
796 | 796 | def __setNextFileOnline(self): |
|
797 | 797 | """ |
|
798 | 798 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
799 | 799 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
800 | 800 | siguientes. |
|
801 | 801 | |
|
802 | 802 | Affected: |
|
803 | 803 | self.flagIsNewFile |
|
804 | 804 | self.filename |
|
805 | 805 | self.fileSize |
|
806 | 806 | self.fp |
|
807 | 807 | self.set |
|
808 | 808 | self.flagNoMoreFiles |
|
809 | 809 | |
|
810 | 810 | Return: |
|
811 | 811 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
812 | 812 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
813 | 813 | |
|
814 | 814 | Excepciones: |
|
815 | 815 | Si un determinado file no puede ser abierto |
|
816 | 816 | """ |
|
817 | 817 | nFiles = 0 |
|
818 | 818 | fileOk_flag = False |
|
819 | 819 | firstTime_flag = True |
|
820 | 820 | |
|
821 | 821 | self.set += 1 |
|
822 | 822 | |
|
823 | 823 | if self.set > 999: |
|
824 | 824 | self.set = 0 |
|
825 | 825 | self.foldercounter += 1 |
|
826 | 826 | |
|
827 | 827 | # busca el 1er file disponible |
|
828 | 828 | fullfilename, filename = checkForRealPath( |
|
829 | 829 | self.path, self.foldercounter, self.year, self.doy, self.set, self.ext) |
|
830 | 830 | if fullfilename: |
|
831 | 831 | if self.__verifyFile(fullfilename, False): |
|
832 | 832 | fileOk_flag = True |
|
833 | 833 | |
|
834 | 834 | # si no encuentra un file entonces espera y vuelve a buscar |
|
835 | 835 | if not(fileOk_flag): |
|
836 | 836 | # busco en los siguientes self.nFiles+1 files posibles |
|
837 | 837 | for nFiles in range(self.nFiles + 1): |
|
838 | 838 | |
|
839 | 839 | if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces |
|
840 | 840 | tries = self.nTries |
|
841 | 841 | else: |
|
842 | 842 | tries = 1 # si no es la 1era vez entonces solo lo hace una vez |
|
843 | 843 | |
|
844 | 844 | for nTries in range(tries): |
|
845 | 845 | if firstTime_flag: |
|
846 | 846 | print("\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1)) |
|
847 | 847 | sleep(self.delay) |
|
848 | 848 | else: |
|
849 | 849 | print("\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)) |
|
850 | 850 | |
|
851 | 851 | fullfilename, filename = checkForRealPath( |
|
852 | 852 | self.path, self.foldercounter, self.year, self.doy, self.set, self.ext) |
|
853 | 853 | if fullfilename: |
|
854 | 854 | if self.__verifyFile(fullfilename): |
|
855 | 855 | fileOk_flag = True |
|
856 | 856 | break |
|
857 | 857 | |
|
858 | 858 | if fileOk_flag: |
|
859 | 859 | break |
|
860 | 860 | |
|
861 | 861 | firstTime_flag = False |
|
862 | 862 | |
|
863 | 863 | log.warning('Skipping the file {} due to this file doesn\'t exist'.format(filename)) |
|
864 | 864 | self.set += 1 |
|
865 | 865 | |
|
866 | 866 | # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
867 | 867 | if nFiles == (self.nFiles - 1): |
|
868 | 868 | self.set = 0 |
|
869 | 869 | self.doy += 1 |
|
870 | 870 | self.foldercounter = 0 |
|
871 | 871 | |
|
872 | 872 | if fileOk_flag: |
|
873 | 873 | self.fileSize = os.path.getsize(fullfilename) |
|
874 | 874 | self.filename = fullfilename |
|
875 | 875 | self.flagIsNewFile = 1 |
|
876 | 876 | if self.fp != None: |
|
877 | 877 | self.fp.close() |
|
878 | 878 | self.fp = open(fullfilename, 'rb') |
|
879 | 879 | self.flagNoMoreFiles = 0 |
|
880 | 880 | # print '[Reading] Setting the file: %s' % fullfilename |
|
881 | 881 | else: |
|
882 | 882 | self.fileSize = 0 |
|
883 | 883 | self.filename = None |
|
884 | 884 | self.flagIsNewFile = 0 |
|
885 | 885 | self.fp = None |
|
886 | 886 | self.flagNoMoreFiles = 1 |
|
887 | 887 | # print '[Reading] No more files to read' |
|
888 | 888 | |
|
889 | 889 | return fileOk_flag |
|
890 | 890 | |
|
891 | 891 | def setNextFile(self): |
|
892 | 892 | if self.fp != None: |
|
893 | 893 | self.fp.close() |
|
894 | 894 | |
|
895 | 895 | if self.online: |
|
896 | 896 | newFile = self.__setNextFileOnline() |
|
897 | 897 | else: |
|
898 | 898 | newFile = self.__setNextFileOffline() |
|
899 | 899 | |
|
900 | 900 | if not(newFile): |
|
901 | 901 | self.dataOut.error = (-1, 'No more files to read') |
|
902 | 902 | return 0 |
|
903 | 903 | |
|
904 | 904 | if self.verbose: |
|
905 | 905 | print('[Reading] Setting the file: %s' % self.filename) |
|
906 | 906 | |
|
907 | 907 | self.__readFirstHeader() |
|
908 | 908 | self.nReadBlocks = 0 |
|
909 | 909 | return 1 |
|
910 | 910 | |
|
911 | 911 | def __waitNewBlock(self): |
|
912 | 912 | """ |
|
913 | 913 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
914 | 914 | |
|
915 | 915 | Si el modo de lectura es OffLine siempre retorn 0 |
|
916 | 916 | """ |
|
917 | 917 | if not self.online: |
|
918 | 918 | return 0 |
|
919 | 919 | |
|
920 | 920 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
921 | 921 | return 0 |
|
922 | 922 | |
|
923 | 923 | currentPointer = self.fp.tell() |
|
924 | 924 | |
|
925 | 925 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
926 | 926 | |
|
927 | 927 | for nTries in range(self.nTries): |
|
928 | 928 | |
|
929 | 929 | self.fp.close() |
|
930 | 930 | self.fp = open(self.filename, 'rb') |
|
931 | 931 | self.fp.seek(currentPointer) |
|
932 | 932 | |
|
933 | 933 | self.fileSize = os.path.getsize(self.filename) |
|
934 | 934 | currentSize = self.fileSize - currentPointer |
|
935 | 935 | |
|
936 | 936 | if (currentSize >= neededSize): |
|
937 | 937 | self.basicHeaderObj.read(self.fp) |
|
938 | 938 | return 1 |
|
939 | 939 | |
|
940 | 940 | if self.fileSize == self.fileSizeByHeader: |
|
941 | 941 | # self.flagEoF = True |
|
942 | 942 | return 0 |
|
943 | 943 | |
|
944 | 944 | print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)) |
|
945 | 945 | sleep(self.delay) |
|
946 | 946 | |
|
947 | 947 | return 0 |
|
948 | 948 | |
|
949 | 949 | def waitDataBlock(self, pointer_location): |
|
950 | 950 | |
|
951 | 951 | currentPointer = pointer_location |
|
952 | 952 | |
|
953 | 953 | neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize |
|
954 | 954 | |
|
955 | 955 | for nTries in range(self.nTries): |
|
956 | 956 | self.fp.close() |
|
957 | 957 | self.fp = open(self.filename, 'rb') |
|
958 | 958 | self.fp.seek(currentPointer) |
|
959 | 959 | |
|
960 | 960 | self.fileSize = os.path.getsize(self.filename) |
|
961 | 961 | currentSize = self.fileSize - currentPointer |
|
962 | 962 | |
|
963 | 963 | if (currentSize >= neededSize): |
|
964 | 964 | return 1 |
|
965 | 965 | |
|
966 | 966 | print("[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1)) |
|
967 | 967 | sleep(self.delay) |
|
968 | 968 | |
|
969 | 969 | return 0 |
|
970 | 970 | |
|
971 | 971 | def __jumpToLastBlock(self): |
|
972 | 972 | |
|
973 | 973 | if not(self.__isFirstTimeOnline): |
|
974 | 974 | return |
|
975 | 975 | |
|
976 | 976 | csize = self.fileSize - self.fp.tell() |
|
977 | 977 | blocksize = self.processingHeaderObj.blockSize |
|
978 | 978 | |
|
979 | 979 | # salta el primer bloque de datos |
|
980 | 980 | if csize > self.processingHeaderObj.blockSize: |
|
981 | 981 | self.fp.seek(self.fp.tell() + blocksize) |
|
982 | 982 | else: |
|
983 | 983 | return |
|
984 | 984 | |
|
985 | 985 | csize = self.fileSize - self.fp.tell() |
|
986 | 986 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
987 | 987 | while True: |
|
988 | 988 | |
|
989 | 989 | if self.fp.tell() < self.fileSize: |
|
990 | 990 | self.fp.seek(self.fp.tell() + neededsize) |
|
991 | 991 | else: |
|
992 | 992 | self.fp.seek(self.fp.tell() - neededsize) |
|
993 | 993 | break |
|
994 | 994 | |
|
995 | 995 | # csize = self.fileSize - self.fp.tell() |
|
996 | 996 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
997 | 997 | # factor = int(csize/neededsize) |
|
998 | 998 | # if factor > 0: |
|
999 | 999 | # self.fp.seek(self.fp.tell() + factor*neededsize) |
|
1000 | 1000 | |
|
1001 | 1001 | self.flagIsNewFile = 0 |
|
1002 | 1002 | self.__isFirstTimeOnline = 0 |
|
1003 | 1003 | |
|
1004 | 1004 | def __setNewBlock(self): |
|
1005 | 1005 | # if self.server is None: |
|
1006 | 1006 | if self.fp == None: |
|
1007 | 1007 | return 0 |
|
1008 | 1008 | |
|
1009 | 1009 | # if self.online: |
|
1010 | 1010 | # self.__jumpToLastBlock() |
|
1011 | 1011 | |
|
1012 | 1012 | if self.flagIsNewFile: |
|
1013 | 1013 | self.lastUTTime = self.basicHeaderObj.utc |
|
1014 | 1014 | return 1 |
|
1015 | 1015 | |
|
1016 | 1016 | if self.realtime: |
|
1017 | 1017 | self.flagDiscontinuousBlock = 1 |
|
1018 | 1018 | if not(self.setNextFile()): |
|
1019 | 1019 | return 0 |
|
1020 | 1020 | else: |
|
1021 | 1021 | return 1 |
|
1022 | 1022 | # if self.server is None: |
|
1023 | 1023 | currentSize = self.fileSize - self.fp.tell() |
|
1024 | 1024 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
1025 | 1025 | if (currentSize >= neededSize): |
|
1026 | 1026 | self.basicHeaderObj.read(self.fp) |
|
1027 | 1027 | self.lastUTTime = self.basicHeaderObj.utc |
|
1028 | 1028 | return 1 |
|
1029 | 1029 | # else: |
|
1030 | 1030 | # self.basicHeaderObj.read(self.zHeader) |
|
1031 | 1031 | # self.lastUTTime = self.basicHeaderObj.utc |
|
1032 | 1032 | # return 1 |
|
1033 | 1033 | if self.__waitNewBlock(): |
|
1034 | 1034 | self.lastUTTime = self.basicHeaderObj.utc |
|
1035 | 1035 | return 1 |
|
1036 | 1036 | # if self.server is None: |
|
1037 | 1037 | if not(self.setNextFile()): |
|
1038 | 1038 | return 0 |
|
1039 | 1039 | |
|
1040 | 1040 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime |
|
1041 | 1041 | self.lastUTTime = self.basicHeaderObj.utc |
|
1042 | 1042 | |
|
1043 | 1043 | self.flagDiscontinuousBlock = 0 |
|
1044 | 1044 | |
|
1045 | 1045 | if deltaTime > self.maxTimeStep: |
|
1046 | 1046 | self.flagDiscontinuousBlock = 1 |
|
1047 | 1047 | |
|
1048 | 1048 | return 1 |
|
1049 | 1049 | |
|
1050 | 1050 | def readNextBlock(self): |
|
1051 | 1051 | |
|
1052 | 1052 | # Skip block out of startTime and endTime |
|
1053 | 1053 | while True: |
|
1054 | 1054 | if not(self.__setNewBlock()): |
|
1055 | 1055 | self.dataOut.error = (-1, 'No more files to read') |
|
1056 | 1056 | return 0 |
|
1057 | 1057 | |
|
1058 | 1058 | if not(self.readBlock()): |
|
1059 | 1059 | return 0 |
|
1060 | 1060 | |
|
1061 | 1061 | self.getBasicHeader() |
|
1062 | 1062 | if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)): |
|
1063 | 1063 | print("[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks, |
|
1064 | 1064 | self.processingHeaderObj.dataBlocksPerFile, |
|
1065 | 1065 | self.dataOut.datatime.ctime())) |
|
1066 | 1066 | continue |
|
1067 | 1067 | |
|
1068 | 1068 | break |
|
1069 | 1069 | |
|
1070 | 1070 | if self.verbose: |
|
1071 | 1071 | print("[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks, |
|
1072 | 1072 | self.processingHeaderObj.dataBlocksPerFile, |
|
1073 | 1073 | self.dataOut.datatime.ctime())) |
|
1074 | 1074 | return 1 |
|
1075 | 1075 | |
|
1076 | 1076 | def __readFirstHeader(self): |
|
1077 | 1077 | |
|
1078 | 1078 | self.basicHeaderObj.read(self.fp) |
|
1079 | 1079 | self.systemHeaderObj.read(self.fp) |
|
1080 | 1080 | self.radarControllerHeaderObj.read(self.fp) |
|
1081 | 1081 | self.processingHeaderObj.read(self.fp) |
|
1082 | 1082 | |
|
1083 | 1083 | self.firstHeaderSize = self.basicHeaderObj.size |
|
1084 | 1084 | |
|
1085 | 1085 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & |
|
1086 | 1086 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
1087 | 1087 | if datatype == 0: |
|
1088 | 1088 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
1089 | 1089 | elif datatype == 1: |
|
1090 | 1090 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
1091 | 1091 | elif datatype == 2: |
|
1092 | 1092 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
1093 | 1093 | elif datatype == 3: |
|
1094 | 1094 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
1095 | 1095 | elif datatype == 4: |
|
1096 | 1096 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
1097 | 1097 | elif datatype == 5: |
|
1098 | 1098 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
1099 | 1099 | else: |
|
1100 | 1100 | raise ValueError('Data type was not defined') |
|
1101 | 1101 | |
|
1102 | 1102 | self.dtype = datatype_str |
|
1103 | 1103 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
1104 | 1104 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \ |
|
1105 | 1105 | self.firstHeaderSize + self.basicHeaderSize * \ |
|
1106 | 1106 | (self.processingHeaderObj.dataBlocksPerFile - 1) |
|
1107 | 1107 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
1108 | 1108 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
1109 | 1109 | self.getBlockDimension() |
|
1110 | 1110 | |
|
1111 | 1111 | def __verifyFile(self, filename, msgFlag=True): |
|
1112 | 1112 | |
|
1113 | 1113 | msg = None |
|
1114 | 1114 | |
|
1115 | 1115 | try: |
|
1116 | 1116 | fp = open(filename, 'rb') |
|
1117 | 1117 | except IOError: |
|
1118 | 1118 | |
|
1119 | 1119 | if msgFlag: |
|
1120 | 1120 | print("[Reading] File %s can't be opened" % (filename)) |
|
1121 | 1121 | |
|
1122 | 1122 | return False |
|
1123 | 1123 | |
|
1124 | 1124 | currentPosition = fp.tell() |
|
1125 | 1125 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
1126 | 1126 | |
|
1127 | 1127 | if neededSize == 0: |
|
1128 | 1128 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
1129 | 1129 | systemHeaderObj = SystemHeader() |
|
1130 | 1130 | radarControllerHeaderObj = RadarControllerHeader() |
|
1131 | 1131 | processingHeaderObj = ProcessingHeader() |
|
1132 | 1132 | |
|
1133 | 1133 | if not(basicHeaderObj.read(fp)): |
|
1134 | 1134 | fp.close() |
|
1135 | 1135 | return False |
|
1136 | 1136 | |
|
1137 | 1137 | if not(systemHeaderObj.read(fp)): |
|
1138 | 1138 | fp.close() |
|
1139 | 1139 | return False |
|
1140 | 1140 | |
|
1141 | 1141 | if not(radarControllerHeaderObj.read(fp)): |
|
1142 | 1142 | fp.close() |
|
1143 | 1143 | return False |
|
1144 | 1144 | |
|
1145 | 1145 | if not(processingHeaderObj.read(fp)): |
|
1146 | 1146 | fp.close() |
|
1147 | 1147 | return False |
|
1148 | 1148 | |
|
1149 | 1149 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
1150 | 1150 | else: |
|
1151 | 1151 | msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename |
|
1152 | 1152 | |
|
1153 | 1153 | fp.close() |
|
1154 | 1154 | |
|
1155 | 1155 | fileSize = os.path.getsize(filename) |
|
1156 | 1156 | currentSize = fileSize - currentPosition |
|
1157 | 1157 | |
|
1158 | 1158 | if currentSize < neededSize: |
|
1159 | 1159 | if msgFlag and (msg != None): |
|
1160 | 1160 | print(msg) |
|
1161 | 1161 | return False |
|
1162 | 1162 | |
|
1163 | 1163 | return True |
|
1164 | 1164 | |
|
1165 | 1165 | def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False): |
|
1166 | 1166 | |
|
1167 | 1167 | path_empty = True |
|
1168 | 1168 | |
|
1169 | 1169 | dateList = [] |
|
1170 | 1170 | pathList = [] |
|
1171 | 1171 | |
|
1172 | 1172 | multi_path = path.split(',') |
|
1173 | 1173 | |
|
1174 | 1174 | if not walk: |
|
1175 | 1175 | |
|
1176 | 1176 | for single_path in multi_path: |
|
1177 | 1177 | |
|
1178 | 1178 | if not os.path.isdir(single_path): |
|
1179 | 1179 | continue |
|
1180 | 1180 | |
|
1181 | 1181 | fileList = glob.glob1(single_path, "*" + ext) |
|
1182 | 1182 | |
|
1183 | 1183 | if not fileList: |
|
1184 | 1184 | continue |
|
1185 | 1185 | |
|
1186 | 1186 | path_empty = False |
|
1187 | 1187 | |
|
1188 | 1188 | fileList.sort() |
|
1189 | 1189 | |
|
1190 | 1190 | for thisFile in fileList: |
|
1191 | 1191 | |
|
1192 | 1192 | if not os.path.isfile(os.path.join(single_path, thisFile)): |
|
1193 | 1193 | continue |
|
1194 | 1194 | |
|
1195 | 1195 | if not isRadarFile(thisFile): |
|
1196 | 1196 | continue |
|
1197 | 1197 | |
|
1198 | 1198 | if not isFileInDateRange(thisFile, startDate, endDate): |
|
1199 | 1199 | continue |
|
1200 | 1200 | |
|
1201 | 1201 | thisDate = getDateFromRadarFile(thisFile) |
|
1202 | 1202 | |
|
1203 | 1203 | if thisDate in dateList: |
|
1204 | 1204 | continue |
|
1205 | 1205 | |
|
1206 | 1206 | dateList.append(thisDate) |
|
1207 | 1207 | pathList.append(single_path) |
|
1208 | 1208 | |
|
1209 | 1209 | else: |
|
1210 | 1210 | for single_path in multi_path: |
|
1211 | 1211 | |
|
1212 | 1212 | if not os.path.isdir(single_path): |
|
1213 | 1213 | continue |
|
1214 | 1214 | |
|
1215 | 1215 | dirList = [] |
|
1216 | 1216 | |
|
1217 | 1217 | for thisPath in os.listdir(single_path): |
|
1218 | 1218 | |
|
1219 | 1219 | if not os.path.isdir(os.path.join(single_path, thisPath)): |
|
1220 | 1220 | continue |
|
1221 | 1221 | |
|
1222 | 1222 | if not isRadarFolder(thisPath): |
|
1223 | 1223 | continue |
|
1224 | 1224 | |
|
1225 | 1225 | if not isFolderInDateRange(thisPath, startDate, endDate): |
|
1226 | 1226 | continue |
|
1227 | 1227 | |
|
1228 | 1228 | dirList.append(thisPath) |
|
1229 | 1229 | |
|
1230 | 1230 | if not dirList: |
|
1231 | 1231 | continue |
|
1232 | 1232 | |
|
1233 | 1233 | dirList.sort() |
|
1234 | 1234 | |
|
1235 | 1235 | for thisDir in dirList: |
|
1236 | 1236 | |
|
1237 | 1237 | datapath = os.path.join(single_path, thisDir, expLabel) |
|
1238 | 1238 | fileList = glob.glob1(datapath, "*" + ext) |
|
1239 | 1239 | |
|
1240 | 1240 | if not fileList: |
|
1241 | 1241 | continue |
|
1242 | 1242 | |
|
1243 | 1243 | path_empty = False |
|
1244 | 1244 | |
|
1245 | 1245 | thisDate = getDateFromRadarFolder(thisDir) |
|
1246 | 1246 | |
|
1247 | 1247 | pathList.append(datapath) |
|
1248 | 1248 | dateList.append(thisDate) |
|
1249 | 1249 | |
|
1250 | 1250 | dateList.sort() |
|
1251 | 1251 | |
|
1252 | 1252 | if walk: |
|
1253 | 1253 | pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel) |
|
1254 | 1254 | else: |
|
1255 | 1255 | pattern_path = multi_path[0] |
|
1256 | 1256 | |
|
1257 | 1257 | if path_empty: |
|
1258 | 1258 | print("[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate)) |
|
1259 | 1259 | else: |
|
1260 | 1260 | if not dateList: |
|
1261 | 1261 | print("[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path)) |
|
1262 | 1262 | |
|
1263 | 1263 | if include_path: |
|
1264 | 1264 | return dateList, pathList |
|
1265 | 1265 | |
|
1266 | 1266 | return dateList |
|
1267 | 1267 | |
|
1268 | 1268 | def setup(self, |
|
1269 | 1269 | path=None, |
|
1270 | 1270 | startDate=None, |
|
1271 | 1271 | endDate=None, |
|
1272 | 1272 | startTime=datetime.time(0, 0, 0), |
|
1273 | 1273 | endTime=datetime.time(23, 59, 59), |
|
1274 | 1274 | set=None, |
|
1275 | 1275 | expLabel="", |
|
1276 | 1276 | ext=None, |
|
1277 | 1277 | online=False, |
|
1278 | 1278 | delay=60, |
|
1279 | 1279 | walk=True, |
|
1280 | 1280 | getblock=False, |
|
1281 | 1281 | nTxs=1, |
|
1282 | 1282 | realtime=False, |
|
1283 | 1283 | blocksize=None, |
|
1284 | 1284 | blocktime=None, |
|
1285 | 1285 | skip=None, |
|
1286 | 1286 | cursor=None, |
|
1287 | 1287 | warnings=True, |
|
1288 | 1288 | verbose=True, |
|
1289 | 1289 | server=None, |
|
1290 | 1290 | format=None, |
|
1291 | 1291 | oneDDict=None, |
|
1292 | 1292 | twoDDict=None, |
|
1293 | 1293 | ind2DList=None): |
|
1294 | 1294 | if server is not None: |
|
1295 | 1295 | if 'tcp://' in server: |
|
1296 | 1296 | address = server |
|
1297 | 1297 | else: |
|
1298 | 1298 | address = 'ipc:///tmp/%s' % server |
|
1299 | 1299 | self.server = address |
|
1300 | 1300 | self.context = zmq.Context() |
|
1301 | 1301 | self.receiver = self.context.socket(zmq.PULL) |
|
1302 | 1302 | self.receiver.connect(self.server) |
|
1303 | 1303 | time.sleep(0.5) |
|
1304 | 1304 | print('[Starting] ReceiverData from {}'.format(self.server)) |
|
1305 | 1305 | else: |
|
1306 | 1306 | self.server = None |
|
1307 | 1307 | if path == None: |
|
1308 | 1308 | raise ValueError("[Reading] The path is not valid") |
|
1309 | 1309 | |
|
1310 | 1310 | if ext == None: |
|
1311 | 1311 | ext = self.ext |
|
1312 | 1312 | |
|
1313 | 1313 | if online: |
|
1314 | 1314 | print("[Reading] Searching files in online mode...") |
|
1315 | 1315 | |
|
1316 | 1316 | for nTries in range(self.nTries): |
|
1317 | 1317 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine( |
|
1318 | 1318 | path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) |
|
1319 | 1319 | |
|
1320 | 1320 | if fullpath: |
|
1321 | 1321 | break |
|
1322 | 1322 | |
|
1323 | 1323 | print('[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1)) |
|
1324 | 1324 | sleep(self.delay) |
|
1325 | 1325 | |
|
1326 | 1326 | if not(fullpath): |
|
1327 | 1327 | self.dataOut.error = (-1, 'There isn\'t any valid file in {}'.format(path)) |
|
1328 | 1328 | return |
|
1329 | 1329 | |
|
1330 | 1330 | self.year = year |
|
1331 | 1331 | self.doy = doy |
|
1332 | 1332 | self.set = set - 1 |
|
1333 | 1333 | self.path = path |
|
1334 | 1334 | self.foldercounter = foldercounter |
|
1335 | 1335 | last_set = None |
|
1336 | 1336 | else: |
|
1337 | 1337 | print("[Reading] Searching files in offline mode ...") |
|
1338 | 1338 | pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
1339 | 1339 | startTime=startTime, endTime=endTime, |
|
1340 | 1340 | set=set, expLabel=expLabel, ext=ext, |
|
1341 | 1341 | walk=walk, cursor=cursor, |
|
1342 | 1342 | skip=skip) |
|
1343 | 1343 | |
|
1344 | 1344 | if not(pathList): |
|
1345 | 1345 | self.fileIndex = -1 |
|
1346 | 1346 | self.pathList = [] |
|
1347 | 1347 | self.filenameList = [] |
|
1348 | 1348 | return |
|
1349 | 1349 | |
|
1350 | 1350 | self.fileIndex = -1 |
|
1351 | 1351 | self.pathList = pathList |
|
1352 | 1352 | self.filenameList = filenameList |
|
1353 | 1353 | file_name = os.path.basename(filenameList[-1]) |
|
1354 | 1354 | basename, ext = os.path.splitext(file_name) |
|
1355 | 1355 | last_set = int(basename[-3:]) |
|
1356 | 1356 | |
|
1357 | 1357 | self.online = online |
|
1358 | 1358 | self.realtime = realtime |
|
1359 | 1359 | self.delay = delay |
|
1360 | 1360 | ext = ext.lower() |
|
1361 | 1361 | self.ext = ext |
|
1362 | 1362 | self.getByBlock = getblock |
|
1363 | 1363 | self.nTxs = nTxs |
|
1364 | 1364 | self.startTime = startTime |
|
1365 | 1365 | self.endTime = endTime |
|
1366 | 1366 | self.endDate = endDate |
|
1367 | 1367 | self.startDate = startDate |
|
1368 | 1368 | # Added----------------- |
|
1369 | 1369 | self.selBlocksize = blocksize |
|
1370 | 1370 | self.selBlocktime = blocktime |
|
1371 | 1371 | |
|
1372 | 1372 | # Verbose----------- |
|
1373 | 1373 | self.verbose = verbose |
|
1374 | 1374 | self.warnings = warnings |
|
1375 | 1375 | |
|
1376 | 1376 | if not(self.setNextFile()): |
|
1377 | 1377 | if (startDate != None) and (endDate != None): |
|
1378 | 1378 | print("[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime())) |
|
1379 | 1379 | elif startDate != None: |
|
1380 | 1380 | print("[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime())) |
|
1381 | 1381 | else: |
|
1382 | 1382 | print("[Reading] No files") |
|
1383 | 1383 | |
|
1384 | 1384 | self.fileIndex = -1 |
|
1385 | 1385 | self.pathList = [] |
|
1386 | 1386 | self.filenameList = [] |
|
1387 | 1387 | return |
|
1388 | 1388 | |
|
1389 | 1389 | # self.getBasicHeader() |
|
1390 | 1390 | |
|
1391 | 1391 | if last_set != None: |
|
1392 | 1392 | self.dataOut.last_block = last_set * \ |
|
1393 | 1393 | self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock |
|
1394 | 1394 | return |
|
1395 | 1395 | |
|
1396 | 1396 | def getBasicHeader(self): |
|
1397 | 1397 | |
|
1398 | 1398 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ |
|
1399 | 1399 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds |
|
1400 | 1400 | |
|
1401 | 1401 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
1402 | 1402 | |
|
1403 | 1403 | self.dataOut.timeZone = self.basicHeaderObj.timeZone |
|
1404 | 1404 | |
|
1405 | 1405 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag |
|
1406 | 1406 | |
|
1407 | 1407 | self.dataOut.errorCount = self.basicHeaderObj.errorCount |
|
1408 | 1408 | |
|
1409 | 1409 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime |
|
1410 | 1410 | |
|
1411 | 1411 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs |
|
1412 | 1412 | |
|
1413 | 1413 | # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
1414 | 1414 | |
|
1415 | 1415 | def getFirstHeader(self): |
|
1416 | 1416 | |
|
1417 | 1417 | raise NotImplementedError |
|
1418 | 1418 | |
|
1419 | 1419 | def getData(self): |
|
1420 | 1420 | |
|
1421 | 1421 | raise NotImplementedError |
|
1422 | 1422 | |
|
1423 | 1423 | def hasNotDataInBuffer(self): |
|
1424 | 1424 | |
|
1425 | 1425 | raise NotImplementedError |
|
1426 | 1426 | |
|
1427 | 1427 | def readBlock(self): |
|
1428 | 1428 | |
|
1429 | 1429 | raise NotImplementedError |
|
1430 | 1430 | |
|
1431 | 1431 | def isEndProcess(self): |
|
1432 | 1432 | |
|
1433 | 1433 | return self.flagNoMoreFiles |
|
1434 | 1434 | |
|
1435 | 1435 | def printReadBlocks(self): |
|
1436 | 1436 | |
|
1437 | 1437 | print("[Reading] Number of read blocks per file %04d" % self.nReadBlocks) |
|
1438 | 1438 | |
|
1439 | 1439 | def printTotalBlocks(self): |
|
1440 | 1440 | |
|
1441 | 1441 | print("[Reading] Number of read blocks %04d" % self.nTotalBlocks) |
|
1442 | 1442 | |
|
1443 | 1443 | def printNumberOfBlock(self): |
|
1444 | 1444 | 'SPAM!' |
|
1445 | 1445 | |
|
1446 | 1446 | # if self.flagIsNewBlock: |
|
1447 | 1447 | # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks, |
|
1448 | 1448 | # self.processingHeaderObj.dataBlocksPerFile, |
|
1449 | 1449 | # self.dataOut.datatime.ctime()) |
|
1450 | 1450 | |
|
1451 | 1451 | def printInfo(self): |
|
1452 | 1452 | |
|
1453 | 1453 | if self.__printInfo == False: |
|
1454 | 1454 | return |
|
1455 | 1455 | |
|
1456 | 1456 | self.basicHeaderObj.printInfo() |
|
1457 | 1457 | self.systemHeaderObj.printInfo() |
|
1458 | 1458 | self.radarControllerHeaderObj.printInfo() |
|
1459 | 1459 | self.processingHeaderObj.printInfo() |
|
1460 | 1460 | |
|
1461 | 1461 | self.__printInfo = False |
|
1462 | 1462 | |
|
1463 | 1463 | def run(self, |
|
1464 | 1464 | path=None, |
|
1465 | 1465 | startDate=None, |
|
1466 | 1466 | endDate=None, |
|
1467 | 1467 | startTime=datetime.time(0, 0, 0), |
|
1468 | 1468 | endTime=datetime.time(23, 59, 59), |
|
1469 | 1469 | set=None, |
|
1470 | 1470 | expLabel="", |
|
1471 | 1471 | ext=None, |
|
1472 | 1472 | online=False, |
|
1473 | 1473 | delay=60, |
|
1474 | 1474 | walk=True, |
|
1475 | 1475 | getblock=False, |
|
1476 | 1476 | nTxs=1, |
|
1477 | 1477 | realtime=False, |
|
1478 | 1478 | blocksize=None, |
|
1479 | 1479 | blocktime=None, |
|
1480 | 1480 | skip=None, |
|
1481 | 1481 | cursor=None, |
|
1482 | 1482 | warnings=True, |
|
1483 | 1483 | server=None, |
|
1484 | 1484 | verbose=True, |
|
1485 | 1485 | format=None, |
|
1486 | 1486 | oneDDict=None, |
|
1487 | 1487 | twoDDict=None, |
|
1488 | 1488 | ind2DList=None, **kwargs): |
|
1489 | 1489 | |
|
1490 | 1490 | if not(self.isConfig): |
|
1491 | 1491 | self.setup(path=path, |
|
1492 | 1492 | startDate=startDate, |
|
1493 | 1493 | endDate=endDate, |
|
1494 | 1494 | startTime=startTime, |
|
1495 | 1495 | endTime=endTime, |
|
1496 | 1496 | set=set, |
|
1497 | 1497 | expLabel=expLabel, |
|
1498 | 1498 | ext=ext, |
|
1499 | 1499 | online=online, |
|
1500 | 1500 | delay=delay, |
|
1501 | 1501 | walk=walk, |
|
1502 | 1502 | getblock=getblock, |
|
1503 | 1503 | nTxs=nTxs, |
|
1504 | 1504 | realtime=realtime, |
|
1505 | 1505 | blocksize=blocksize, |
|
1506 | 1506 | blocktime=blocktime, |
|
1507 | 1507 | skip=skip, |
|
1508 | 1508 | cursor=cursor, |
|
1509 | 1509 | warnings=warnings, |
|
1510 | 1510 | server=server, |
|
1511 | 1511 | verbose=verbose, |
|
1512 | 1512 | format=format, |
|
1513 | 1513 | oneDDict=oneDDict, |
|
1514 | 1514 | twoDDict=twoDDict, |
|
1515 | 1515 | ind2DList=ind2DList) |
|
1516 | 1516 | self.isConfig = True |
|
1517 | 1517 | if server is None: |
|
1518 | 1518 | self.getData() |
|
1519 | 1519 | else: |
|
1520 | 1520 | self.getFromServer() |
|
1521 | 1521 | |
|
1522 | 1522 | |
|
1523 | 1523 | class JRODataWriter(JRODataIO): |
|
1524 | 1524 | |
|
1525 | 1525 | """ |
|
1526 | 1526 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
1527 | 1527 | de los datos siempre se realiza por bloques. |
|
1528 | 1528 | """ |
|
1529 | 1529 | |
|
1530 | 1530 | blockIndex = 0 |
|
1531 | 1531 | |
|
1532 | 1532 | path = None |
|
1533 | 1533 | |
|
1534 | 1534 | setFile = None |
|
1535 | 1535 | |
|
1536 | 1536 | profilesPerBlock = None |
|
1537 | 1537 | |
|
1538 | 1538 | blocksPerFile = None |
|
1539 | 1539 | |
|
1540 | 1540 | nWriteBlocks = 0 |
|
1541 | 1541 | |
|
1542 | 1542 | fileDate = None |
|
1543 | 1543 | |
|
1544 | 1544 | def __init__(self, dataOut=None): |
|
1545 | 1545 | raise NotImplementedError |
|
1546 | 1546 | |
|
1547 | 1547 | def hasAllDataInBuffer(self): |
|
1548 | 1548 | raise NotImplementedError |
|
1549 | 1549 | |
|
1550 | 1550 | def setBlockDimension(self): |
|
1551 | 1551 | raise NotImplementedError |
|
1552 | 1552 | |
|
1553 | 1553 | def writeBlock(self): |
|
1554 | 1554 | raise NotImplementedError |
|
1555 | 1555 | |
|
1556 | 1556 | def putData(self): |
|
1557 | 1557 | raise NotImplementedError |
|
1558 | 1558 | |
|
1559 | 1559 | def getProcessFlags(self): |
|
1560 | 1560 | |
|
1561 | 1561 | processFlags = 0 |
|
1562 | 1562 | |
|
1563 | 1563 | dtype_index = get_dtype_index(self.dtype) |
|
1564 | 1564 | procflag_dtype = get_procflag_dtype(dtype_index) |
|
1565 | 1565 | |
|
1566 | 1566 | processFlags += procflag_dtype |
|
1567 | 1567 | |
|
1568 | 1568 | if self.dataOut.flagDecodeData: |
|
1569 | 1569 | processFlags += PROCFLAG.DECODE_DATA |
|
1570 | 1570 | |
|
1571 | 1571 | if self.dataOut.flagDeflipData: |
|
1572 | 1572 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1573 | 1573 | |
|
1574 | 1574 | if self.dataOut.code is not None: |
|
1575 | 1575 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1576 | 1576 | |
|
1577 | 1577 | if self.dataOut.nCohInt > 1: |
|
1578 | 1578 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1579 | 1579 | |
|
1580 | 1580 | if self.dataOut.type == "Spectra": |
|
1581 | 1581 | if self.dataOut.nIncohInt > 1: |
|
1582 | 1582 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
1583 | 1583 | |
|
1584 | 1584 | if self.dataOut.data_dc is not None: |
|
1585 | 1585 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
1586 | 1586 | |
|
1587 | 1587 | if self.dataOut.flagShiftFFT: |
|
1588 | 1588 | processFlags += PROCFLAG.SHIFT_FFT_DATA |
|
1589 | 1589 | |
|
1590 | 1590 | return processFlags |
|
1591 | 1591 | |
|
1592 | 1592 | def setBasicHeader(self): |
|
1593 | 1593 | |
|
1594 | 1594 | self.basicHeaderObj.size = self.basicHeaderSize # bytes |
|
1595 | 1595 | self.basicHeaderObj.version = self.versionFile |
|
1596 | 1596 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
1597 | 1597 | |
|
1598 | 1598 | utc = numpy.floor(self.dataOut.utctime) |
|
1599 | 1599 | milisecond = (self.dataOut.utctime - utc) * 1000.0 |
|
1600 | 1600 | |
|
1601 | 1601 | self.basicHeaderObj.utc = utc |
|
1602 | 1602 | self.basicHeaderObj.miliSecond = milisecond |
|
1603 | 1603 | self.basicHeaderObj.timeZone = self.dataOut.timeZone |
|
1604 | 1604 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag |
|
1605 | 1605 | self.basicHeaderObj.errorCount = self.dataOut.errorCount |
|
1606 | 1606 | |
|
1607 | 1607 | def setFirstHeader(self): |
|
1608 | 1608 | """ |
|
1609 | 1609 | Obtiene una copia del First Header |
|
1610 | 1610 | |
|
1611 | 1611 | Affected: |
|
1612 | 1612 | |
|
1613 | 1613 | self.basicHeaderObj |
|
1614 | 1614 | self.systemHeaderObj |
|
1615 | 1615 | self.radarControllerHeaderObj |
|
1616 | 1616 | self.processingHeaderObj self. |
|
1617 | 1617 | |
|
1618 | 1618 | Return: |
|
1619 | 1619 | None |
|
1620 | 1620 | """ |
|
1621 | 1621 | |
|
1622 | 1622 | raise NotImplementedError |
|
1623 | 1623 | |
|
1624 | 1624 | def __writeFirstHeader(self): |
|
1625 | 1625 | """ |
|
1626 | 1626 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
1627 | 1627 | |
|
1628 | 1628 | Affected: |
|
1629 | 1629 | __dataType |
|
1630 | 1630 | |
|
1631 | 1631 | Return: |
|
1632 | 1632 | None |
|
1633 | 1633 | """ |
|
1634 | 1634 | |
|
1635 | 1635 | # CALCULAR PARAMETROS |
|
1636 | 1636 | |
|
1637 | 1637 | sizeLongHeader = self.systemHeaderObj.size + \ |
|
1638 | 1638 | self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
1639 | 1639 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
1640 | 1640 | |
|
1641 | 1641 | self.basicHeaderObj.write(self.fp) |
|
1642 | 1642 | self.systemHeaderObj.write(self.fp) |
|
1643 | 1643 | self.radarControllerHeaderObj.write(self.fp) |
|
1644 | 1644 | self.processingHeaderObj.write(self.fp) |
|
1645 | 1645 | |
|
1646 | 1646 | def __setNewBlock(self): |
|
1647 | 1647 | """ |
|
1648 | 1648 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
1649 | 1649 | |
|
1650 | 1650 | Return: |
|
1651 | 1651 | 0 : si no pudo escribir nada |
|
1652 | 1652 | 1 : Si escribio el Basic el First Header |
|
1653 | 1653 | """ |
|
1654 | 1654 | if self.fp == None: |
|
1655 | 1655 | self.setNextFile() |
|
1656 | 1656 | |
|
1657 | 1657 | if self.flagIsNewFile: |
|
1658 | 1658 | return 1 |
|
1659 | 1659 | |
|
1660 | 1660 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
1661 | 1661 | self.basicHeaderObj.write(self.fp) |
|
1662 | 1662 | return 1 |
|
1663 | 1663 | |
|
1664 | 1664 | if not(self.setNextFile()): |
|
1665 | 1665 | return 0 |
|
1666 | 1666 | |
|
1667 | 1667 | return 1 |
|
1668 | 1668 | |
|
1669 | 1669 | def writeNextBlock(self): |
|
1670 | 1670 | """ |
|
1671 | 1671 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1672 | 1672 | |
|
1673 | 1673 | Return: |
|
1674 | 1674 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1675 | 1675 | 1 : Si no pudo escribir el bloque de datos |
|
1676 | 1676 | """ |
|
1677 | 1677 | if not(self.__setNewBlock()): |
|
1678 | 1678 | return 0 |
|
1679 | 1679 | |
|
1680 | 1680 | self.writeBlock() |
|
1681 | 1681 | |
|
1682 | 1682 | print("[Writing] Block No. %d/%d" % (self.blockIndex, |
|
1683 | 1683 | self.processingHeaderObj.dataBlocksPerFile)) |
|
1684 | 1684 | |
|
1685 | 1685 | return 1 |
|
1686 | 1686 | |
|
1687 | 1687 | def setNextFile(self): |
|
1688 | 1688 | """ |
|
1689 | 1689 | Determina el siguiente file que sera escrito |
|
1690 | 1690 | |
|
1691 | 1691 | Affected: |
|
1692 | 1692 | self.filename |
|
1693 | 1693 | self.subfolder |
|
1694 | 1694 | self.fp |
|
1695 | 1695 | self.setFile |
|
1696 | 1696 | self.flagIsNewFile |
|
1697 | 1697 | |
|
1698 | 1698 | Return: |
|
1699 | 1699 | 0 : Si el archivo no puede ser escrito |
|
1700 | 1700 | 1 : Si el archivo esta listo para ser escrito |
|
1701 | 1701 | """ |
|
1702 | 1702 | ext = self.ext |
|
1703 | 1703 | path = self.path |
|
1704 | 1704 | |
|
1705 | 1705 | if self.fp != None: |
|
1706 | 1706 | self.fp.close() |
|
1707 | 1707 | |
|
1708 | 1708 | timeTuple = time.localtime(self.dataOut.utctime) |
|
1709 | 1709 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday) |
|
1710 | 1710 | |
|
1711 | 1711 | fullpath = os.path.join(path, subfolder) |
|
1712 | 1712 | setFile = self.setFile |
|
1713 | 1713 | |
|
1714 | 1714 | if not(os.path.exists(fullpath)): |
|
1715 | 1715 | os.mkdir(fullpath) |
|
1716 | 1716 | setFile = -1 # inicializo mi contador de seteo |
|
1717 | 1717 | else: |
|
1718 | 1718 | filesList = os.listdir(fullpath) |
|
1719 | 1719 | if len(filesList) > 0: |
|
1720 | 1720 | filesList = sorted(filesList, key=str.lower) |
|
1721 | 1721 | filen = filesList[-1] |
|
1722 | 1722 | # el filename debera tener el siguiente formato |
|
1723 | 1723 | # 0 1234 567 89A BCDE (hex) |
|
1724 | 1724 | # x YYYY DDD SSS .ext |
|
1725 | 1725 | if isNumber(filen[8:11]): |
|
1726 | 1726 | # inicializo mi contador de seteo al seteo del ultimo file |
|
1727 | 1727 | setFile = int(filen[8:11]) |
|
1728 | 1728 | else: |
|
1729 | 1729 | setFile = -1 |
|
1730 | 1730 | else: |
|
1731 | 1731 | setFile = -1 # inicializo mi contador de seteo |
|
1732 | 1732 | |
|
1733 | 1733 | setFile += 1 |
|
1734 | 1734 | |
|
1735 | 1735 | # If this is a new day it resets some values |
|
1736 | 1736 | if self.dataOut.datatime.date() > self.fileDate: |
|
1737 | 1737 | setFile = 0 |
|
1738 | 1738 | self.nTotalBlocks = 0 |
|
1739 | 1739 | |
|
1740 | 1740 | filen = '{}{:04d}{:03d}{:03d}{}'.format( |
|
1741 | 1741 | self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext) |
|
1742 | 1742 | |
|
1743 | 1743 | filename = os.path.join(path, subfolder, filen) |
|
1744 | 1744 | |
|
1745 | 1745 | fp = open(filename, 'wb') |
|
1746 | 1746 | |
|
1747 | 1747 | self.blockIndex = 0 |
|
1748 | 1748 | |
|
1749 | 1749 | # guardando atributos |
|
1750 | 1750 | self.filename = filename |
|
1751 | 1751 | self.subfolder = subfolder |
|
1752 | 1752 | self.fp = fp |
|
1753 | 1753 | self.setFile = setFile |
|
1754 | 1754 | self.flagIsNewFile = 1 |
|
1755 | 1755 | self.fileDate = self.dataOut.datatime.date() |
|
1756 | 1756 | |
|
1757 | 1757 | self.setFirstHeader() |
|
1758 | 1758 | |
|
1759 | 1759 | print('[Writing] Opening file: %s' % self.filename) |
|
1760 | 1760 | |
|
1761 | 1761 | self.__writeFirstHeader() |
|
1762 | 1762 | |
|
1763 | 1763 | return 1 |
|
1764 | 1764 | |
|
1765 | 1765 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4): |
|
1766 | 1766 | """ |
|
1767 | 1767 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1768 | 1768 | |
|
1769 | 1769 | Inputs: |
|
1770 | 1770 | path : directory where data will be saved |
|
1771 | 1771 | profilesPerBlock : number of profiles per block |
|
1772 | 1772 | set : initial file set |
|
1773 | 1773 | datatype : An integer number that defines data type: |
|
1774 | 1774 | 0 : int8 (1 byte) |
|
1775 | 1775 | 1 : int16 (2 bytes) |
|
1776 | 1776 | 2 : int32 (4 bytes) |
|
1777 | 1777 | 3 : int64 (8 bytes) |
|
1778 | 1778 | 4 : float32 (4 bytes) |
|
1779 | 1779 | 5 : double64 (8 bytes) |
|
1780 | 1780 | |
|
1781 | 1781 | Return: |
|
1782 | 1782 | 0 : Si no realizo un buen seteo |
|
1783 | 1783 | 1 : Si realizo un buen seteo |
|
1784 | 1784 | """ |
|
1785 | 1785 | |
|
1786 | 1786 | if ext == None: |
|
1787 | 1787 | ext = self.ext |
|
1788 | 1788 | |
|
1789 | 1789 | self.ext = ext.lower() |
|
1790 | 1790 | |
|
1791 | 1791 | self.path = path |
|
1792 | 1792 | |
|
1793 | 1793 | if set is None: |
|
1794 | 1794 | self.setFile = -1 |
|
1795 | 1795 | else: |
|
1796 | 1796 | self.setFile = set - 1 |
|
1797 | 1797 | |
|
1798 | 1798 | self.blocksPerFile = blocksPerFile |
|
1799 | 1799 | |
|
1800 | 1800 | self.profilesPerBlock = profilesPerBlock |
|
1801 | 1801 | |
|
1802 | 1802 | self.dataOut = dataOut |
|
1803 | 1803 | self.fileDate = self.dataOut.datatime.date() |
|
1804 | 1804 | # By default |
|
1805 | 1805 | self.dtype = self.dataOut.dtype |
|
1806 | 1806 | |
|
1807 | 1807 | if datatype is not None: |
|
1808 | 1808 | self.dtype = get_numpy_dtype(datatype) |
|
1809 | 1809 | |
|
1810 | 1810 | if not(self.setNextFile()): |
|
1811 | 1811 | print("[Writing] There isn't a next file") |
|
1812 | 1812 | return 0 |
|
1813 | 1813 | |
|
1814 | 1814 | self.setBlockDimension() |
|
1815 | 1815 | |
|
1816 | 1816 | return 1 |
|
1817 | 1817 | |
|
1818 | def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs): | |
|
1818 | def run(self, dataOut, path, blocksPerFile=100, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs): | |
|
1819 | 1819 | |
|
1820 | 1820 | if not(self.isConfig): |
|
1821 | 1821 | |
|
1822 | 1822 | self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, |
|
1823 | 1823 | set=set, ext=ext, datatype=datatype, **kwargs) |
|
1824 | 1824 | self.isConfig = True |
|
1825 | 1825 | |
|
1826 | 1826 | self.dataOut = dataOut |
|
1827 | 1827 | self.putData() |
|
1828 | 1828 | return self.dataOut No newline at end of file |
This diff has been collapsed as it changes many lines, (607 lines changed) Show them Hide them | |||
@@ -1,1180 +1,697 | |||
|
1 | 1 | import os |
|
2 | 2 | import sys |
|
3 | 3 | import glob |
|
4 | 4 | import fnmatch |
|
5 | 5 | import datetime |
|
6 | 6 | import time |
|
7 | 7 | import re |
|
8 | 8 | import h5py |
|
9 | 9 | import numpy |
|
10 | 10 | |
|
11 | 11 | import pylab as plb |
|
12 | 12 | from scipy.optimize import curve_fit |
|
13 | 13 | from scipy import asarray as ar, exp |
|
14 | 14 | from scipy import stats |
|
15 | 15 | |
|
16 | 16 | from numpy.ma.core import getdata |
|
17 | 17 | |
|
18 | 18 | SPEED_OF_LIGHT = 299792458 |
|
19 | 19 | SPEED_OF_LIGHT = 3e8 |
|
20 | 20 | |
|
21 | 21 | try: |
|
22 | 22 | from gevent import sleep |
|
23 | 23 | except: |
|
24 | 24 | from time import sleep |
|
25 | 25 | |
|
26 | 26 | from schainpy.model.data.jrodata import Spectra |
|
27 | 27 | #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader |
|
28 | 28 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
29 | 29 | #from schainpy.model.io.jroIO_bltr import BLTRReader |
|
30 | 30 | from numpy import imag, shape, NaN |
|
31 | 31 | |
|
32 | 32 | from .jroIO_base import JRODataReader |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | class Header(object): |
|
36 | 36 | |
|
37 | 37 | def __init__(self): |
|
38 | 38 | raise NotImplementedError |
|
39 | 39 | |
|
40 | 40 | def read(self): |
|
41 | 41 | |
|
42 | 42 | raise NotImplementedError |
|
43 | 43 | |
|
44 | 44 | def write(self): |
|
45 | 45 | |
|
46 | 46 | raise NotImplementedError |
|
47 | 47 | |
|
48 | 48 | def printInfo(self): |
|
49 | 49 | |
|
50 | 50 | message = "#" * 50 + "\n" |
|
51 | 51 | message += self.__class__.__name__.upper() + "\n" |
|
52 | 52 | message += "#" * 50 + "\n" |
|
53 | 53 | |
|
54 | 54 | keyList = list(self.__dict__.keys()) |
|
55 | 55 | keyList.sort() |
|
56 | 56 | |
|
57 | 57 | for key in keyList: |
|
58 | 58 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" |
|
59 | 59 | |
|
60 | 60 | if "size" not in keyList: |
|
61 | 61 | attr = getattr(self, "size") |
|
62 | 62 | |
|
63 | 63 | if attr: |
|
64 | 64 | message += "%s = %s" % ("size", attr) + "\n" |
|
65 | 65 | |
|
66 | # print message | |
|
67 | ||
|
68 | ||
|
69 | 66 | FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes |
|
70 | 67 | ('FileMgcNumber', '<u4'), # 0x23020100 |
|
71 | 68 | # No Of FDT data records in this file (0 or more) |
|
72 | 69 | ('nFDTdataRecors', '<u4'), |
|
73 | 70 | ('OffsetStartHeader', '<u4'), |
|
74 | 71 | ('RadarUnitId', '<u4'), |
|
75 | 72 | ('SiteName', numpy.str_, 32), # Null terminated |
|
76 | 73 | ]) |
|
77 | 74 | |
|
78 | 75 | |
|
79 | 76 | class FileHeaderBLTR(Header): |
|
80 | 77 | |
|
81 | 78 | def __init__(self): |
|
82 | 79 | |
|
83 | 80 | self.FileMgcNumber = 0 # 0x23020100 |
|
84 | 81 | # No Of FDT data records in this file (0 or more) |
|
85 | 82 | self.nFDTdataRecors = 0 |
|
86 | 83 | self.RadarUnitId = 0 |
|
87 | 84 | self.OffsetStartHeader = 0 |
|
88 | 85 | self.SiteName = "" |
|
89 | 86 | self.size = 48 |
|
90 | 87 | |
|
91 | 88 | def FHread(self, fp): |
|
92 | 89 | # try: |
|
93 | 90 | startFp = open(fp, "rb") |
|
94 | 91 | |
|
95 | 92 | header = numpy.fromfile(startFp, FILE_STRUCTURE, 1) |
|
96 | 93 | |
|
97 | print(' ') | |
|
98 | print('puntero file header', startFp.tell()) | |
|
99 | print(' ') | |
|
100 | ||
|
101 | ''' numpy.fromfile(file, dtype, count, sep='') | |
|
102 | file : file or str | |
|
103 | Open file object or filename. | |
|
104 | ||
|
105 | dtype : data-type | |
|
106 | Data type of the returned array. For binary files, it is used to determine | |
|
107 | the size and byte-order of the items in the file. | |
|
108 | ||
|
109 | count : int | |
|
110 | Number of items to read. -1 means all items (i.e., the complete file). | |
|
111 | ||
|
112 | sep : str | |
|
113 | Separator between items if file is a text file. Empty ("") separator means | |
|
114 | the file should be treated as binary. Spaces (" ") in the separator match zero | |
|
115 | or more whitespace characters. A separator consisting only of spaces must match | |
|
116 | at least one whitespace. | |
|
117 | ||
|
118 | ''' | |
|
119 | ||
|
120 | 94 | self.FileMgcNumber = hex(header['FileMgcNumber'][0]) |
|
121 | 95 | # No Of FDT data records in this file (0 or more) |
|
122 | 96 | self.nFDTdataRecors = int(header['nFDTdataRecors'][0]) |
|
123 | 97 | self.RadarUnitId = int(header['RadarUnitId'][0]) |
|
124 | 98 | self.OffsetStartHeader = int(header['OffsetStartHeader'][0]) |
|
125 | 99 | self.SiteName = str(header['SiteName'][0]) |
|
126 | 100 | |
|
127 | # print 'Numero de bloques', self.nFDTdataRecors | |
|
128 | ||
|
129 | 101 | if self.size < 48: |
|
130 | 102 | return 0 |
|
131 | 103 | |
|
132 | 104 | return 1 |
|
133 | 105 | |
|
134 | 106 | def write(self, fp): |
|
135 | 107 | |
|
136 | 108 | headerTuple = (self.FileMgcNumber, |
|
137 | 109 | self.nFDTdataRecors, |
|
138 | 110 | self.RadarUnitId, |
|
139 | 111 | self.SiteName, |
|
140 | 112 | self.size) |
|
141 | 113 | |
|
142 | 114 | header = numpy.array(headerTuple, FILE_STRUCTURE) |
|
143 | 115 | # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) |
|
144 | 116 | header.tofile(fp) |
|
145 | 117 | ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default). |
|
146 | 118 | |
|
147 | 119 | fid : file or str |
|
148 | 120 | An open file object, or a string containing a filename. |
|
149 | 121 | |
|
150 | 122 | sep : str |
|
151 | 123 | Separator between array items for text output. If "" (empty), a binary file is written, |
|
152 | 124 | equivalent to file.write(a.tobytes()). |
|
153 | 125 | |
|
154 | 126 | format : str |
|
155 | 127 | Format string for text file output. Each entry in the array is formatted to text by |
|
156 | 128 | first converting it to the closest Python type, and then using "format" % item. |
|
157 | 129 | |
|
158 | 130 | ''' |
|
159 | 131 | |
|
160 | 132 | return 1 |
|
161 | 133 | |
|
162 | 134 | |
|
163 | 135 | RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes |
|
164 | 136 | ('RecMgcNumber', '<u4'), # 0x23030001 |
|
165 | 137 | ('RecCounter', '<u4'), # Record counter(0,1, ...) |
|
166 | 138 | # Offset to start of next record form start of this record |
|
167 | 139 | ('Off2StartNxtRec', '<u4'), |
|
168 | 140 | # Offset to start of data from start of this record |
|
169 | 141 | ('Off2StartData', '<u4'), |
|
170 | 142 | # Epoch time stamp of start of acquisition (seconds) |
|
171 | 143 | ('nUtime', '<i4'), |
|
172 | 144 | # Millisecond component of time stamp (0,...,999) |
|
173 | 145 | ('nMilisec', '<u4'), |
|
174 | 146 | # Experiment tag name (null terminated) |
|
175 | 147 | ('ExpTagName', numpy.str_, 32), |
|
176 | 148 | # Experiment comment (null terminated) |
|
177 | 149 | ('ExpComment', numpy.str_, 32), |
|
178 | 150 | # Site latitude (from GPS) in degrees (positive implies North) |
|
179 | 151 | ('SiteLatDegrees', '<f4'), |
|
180 | 152 | # Site longitude (from GPS) in degrees (positive implies East) |
|
181 | 153 | ('SiteLongDegrees', '<f4'), |
|
182 | 154 | # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE) |
|
183 | 155 | ('RTCgpsStatus', '<u4'), |
|
184 | 156 | ('TransmitFrec', '<u4'), # Transmit frequency (Hz) |
|
185 | 157 | ('ReceiveFrec', '<u4'), # Receive frequency |
|
186 | 158 | # First local oscillator frequency (Hz) |
|
187 | 159 | ('FirstOsciFrec', '<u4'), |
|
188 | 160 | # (0="O", 1="E", 2="linear 1", 3="linear2") |
|
189 | 161 | ('Polarisation', '<u4'), |
|
190 | 162 | # Receiver filter settings (0,1,2,3) |
|
191 | 163 | ('ReceiverFiltSett', '<u4'), |
|
192 | 164 | # Number of modes in use (1 or 2) |
|
193 | 165 | ('nModesInUse', '<u4'), |
|
194 | 166 | # Dual Mode index number for these data (0 or 1) |
|
195 | 167 | ('DualModeIndex', '<u4'), |
|
196 | 168 | # Dual Mode range correction for these data (m) |
|
197 | 169 | ('DualModeRange', '<u4'), |
|
198 | 170 | # Number of digital channels acquired (2*N) |
|
199 | 171 | ('nDigChannels', '<u4'), |
|
200 | 172 | # Sampling resolution (meters) |
|
201 | 173 | ('SampResolution', '<u4'), |
|
202 | 174 | # Number of range gates sampled |
|
203 | 175 | ('nHeights', '<u4'), |
|
204 | 176 | # Start range of sampling (meters) |
|
205 | 177 | ('StartRangeSamp', '<u4'), |
|
206 | 178 | ('PRFhz', '<u4'), # PRF (Hz) |
|
207 | 179 | ('nCohInt', '<u4'), # Integrations |
|
208 | 180 | # Number of data points transformed |
|
209 | 181 | ('nProfiles', '<u4'), |
|
210 | 182 | # Number of receive beams stored in file (1 or N) |
|
211 | 183 | ('nChannels', '<u4'), |
|
212 | 184 | ('nIncohInt', '<u4'), # Number of spectral averages |
|
213 | 185 | # FFT windowing index (0 = no window) |
|
214 | 186 | ('FFTwindowingInd', '<u4'), |
|
215 | 187 | # Beam steer angle (azimuth) in degrees (clockwise from true North) |
|
216 | 188 | ('BeamAngleAzim', '<f4'), |
|
217 | 189 | # Beam steer angle (zenith) in degrees (0=> vertical) |
|
218 | 190 | ('BeamAngleZen', '<f4'), |
|
219 | 191 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
220 | 192 | ('AntennaCoord0', '<f4'), |
|
221 | 193 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
222 | 194 | ('AntennaAngl0', '<f4'), |
|
223 | 195 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
224 | 196 | ('AntennaCoord1', '<f4'), |
|
225 | 197 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
226 | 198 | ('AntennaAngl1', '<f4'), |
|
227 | 199 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
228 | 200 | ('AntennaCoord2', '<f4'), |
|
229 | 201 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
230 | 202 | ('AntennaAngl2', '<f4'), |
|
231 | 203 | # Receiver phase calibration (degrees) - N values |
|
232 | 204 | ('RecPhaseCalibr0', '<f4'), |
|
233 | 205 | # Receiver phase calibration (degrees) - N values |
|
234 | 206 | ('RecPhaseCalibr1', '<f4'), |
|
235 | 207 | # Receiver phase calibration (degrees) - N values |
|
236 | 208 | ('RecPhaseCalibr2', '<f4'), |
|
237 | 209 | # Receiver amplitude calibration (ratio relative to receiver one) - N values |
|
238 | 210 | ('RecAmpCalibr0', '<f4'), |
|
239 | 211 | # Receiver amplitude calibration (ratio relative to receiver one) - N values |
|
240 | 212 | ('RecAmpCalibr1', '<f4'), |
|
241 | 213 | # Receiver amplitude calibration (ratio relative to receiver one) - N values |
|
242 | 214 | ('RecAmpCalibr2', '<f4'), |
|
243 | 215 | # Receiver gains in dB - N values |
|
244 | 216 | ('ReceiverGaindB0', '<i4'), |
|
245 | 217 | # Receiver gains in dB - N values |
|
246 | 218 | ('ReceiverGaindB1', '<i4'), |
|
247 | 219 | # Receiver gains in dB - N values |
|
248 | 220 | ('ReceiverGaindB2', '<i4'), |
|
249 | 221 | ]) |
|
250 | 222 | |
|
251 | 223 | |
|
252 | 224 | class RecordHeaderBLTR(Header): |
|
253 | 225 | |
|
254 | 226 | def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248, |
|
255 | 227 | nUtime=0, nMilisec=0, ExpTagName=None, |
|
256 | 228 | ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0, |
|
257 | 229 | RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0, |
|
258 | 230 | FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0, |
|
259 | 231 | nModesInUse=0, DualModeIndex=0, DualModeRange=0, |
|
260 | 232 | nDigChannels=0, SampResolution=0, nHeights=0, |
|
261 | 233 | StartRangeSamp=0, PRFhz=0, nCohInt=0, |
|
262 | 234 | nProfiles=0, nChannels=0, nIncohInt=0, |
|
263 | 235 | FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0, |
|
264 | 236 | AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0, |
|
265 | 237 | RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0, |
|
266 | 238 | RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0, |
|
267 | 239 | AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0, |
|
268 | 240 | ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0): |
|
269 | 241 | |
|
270 | 242 | self.RecMgcNumber = RecMgcNumber # 0x23030001 |
|
271 | 243 | self.RecCounter = RecCounter |
|
272 | 244 | self.Off2StartNxtRec = Off2StartNxtRec |
|
273 | 245 | self.Off2StartData = Off2StartData |
|
274 | 246 | self.nUtime = nUtime |
|
275 | 247 | self.nMilisec = nMilisec |
|
276 | 248 | self.ExpTagName = ExpTagName |
|
277 | 249 | self.ExpComment = ExpComment |
|
278 | 250 | self.SiteLatDegrees = SiteLatDegrees |
|
279 | 251 | self.SiteLongDegrees = SiteLongDegrees |
|
280 | 252 | self.RTCgpsStatus = RTCgpsStatus |
|
281 | 253 | self.TransmitFrec = TransmitFrec |
|
282 | 254 | self.ReceiveFrec = ReceiveFrec |
|
283 | 255 | self.FirstOsciFrec = FirstOsciFrec |
|
284 | 256 | self.Polarisation = Polarisation |
|
285 | 257 | self.ReceiverFiltSett = ReceiverFiltSett |
|
286 | 258 | self.nModesInUse = nModesInUse |
|
287 | 259 | self.DualModeIndex = DualModeIndex |
|
288 | 260 | self.DualModeRange = DualModeRange |
|
289 | 261 | self.nDigChannels = nDigChannels |
|
290 | 262 | self.SampResolution = SampResolution |
|
291 | 263 | self.nHeights = nHeights |
|
292 | 264 | self.StartRangeSamp = StartRangeSamp |
|
293 | 265 | self.PRFhz = PRFhz |
|
294 | 266 | self.nCohInt = nCohInt |
|
295 | 267 | self.nProfiles = nProfiles |
|
296 | 268 | self.nChannels = nChannels |
|
297 | 269 | self.nIncohInt = nIncohInt |
|
298 | 270 | self.FFTwindowingInd = FFTwindowingInd |
|
299 | 271 | self.BeamAngleAzim = BeamAngleAzim |
|
300 | 272 | self.BeamAngleZen = BeamAngleZen |
|
301 | 273 | self.AntennaCoord0 = AntennaCoord0 |
|
302 | 274 | self.AntennaAngl0 = AntennaAngl0 |
|
303 | 275 | self.AntennaAngl1 = AntennaAngl1 |
|
304 | 276 | self.AntennaAngl2 = AntennaAngl2 |
|
305 | 277 | self.AntennaCoord1 = AntennaCoord1 |
|
306 | 278 | self.AntennaCoord2 = AntennaCoord2 |
|
307 | 279 | self.RecPhaseCalibr0 = RecPhaseCalibr0 |
|
308 | 280 | self.RecPhaseCalibr1 = RecPhaseCalibr1 |
|
309 | 281 | self.RecPhaseCalibr2 = RecPhaseCalibr2 |
|
310 | 282 | self.RecAmpCalibr0 = RecAmpCalibr0 |
|
311 | 283 | self.RecAmpCalibr1 = RecAmpCalibr1 |
|
312 | 284 | self.RecAmpCalibr2 = RecAmpCalibr2 |
|
313 | 285 | self.ReceiverGaindB0 = ReceiverGaindB0 |
|
314 | 286 | self.ReceiverGaindB1 = ReceiverGaindB1 |
|
315 | 287 | self.ReceiverGaindB2 = ReceiverGaindB2 |
|
316 | 288 | self.OffsetStartHeader = 48 |
|
317 | 289 | |
|
318 | 290 | def RHread(self, fp): |
|
319 | # print fp | |
|
320 | # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
321 | # The method tell() returns the current position of the file read/write pointer within the file. | |
|
322 | 291 | startFp = open(fp, "rb") |
|
323 | # RecCounter=0 | |
|
324 | # Off2StartNxtRec=811248 | |
|
325 | 292 | OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec |
|
326 | print(' ') | |
|
327 | print('puntero Record Header', startFp.tell()) | |
|
328 | print(' ') | |
|
329 | ||
|
330 | 293 | startFp.seek(OffRHeader, os.SEEK_SET) |
|
331 | ||
|
332 | print(' ') | |
|
333 | print('puntero Record Header con seek', startFp.tell()) | |
|
334 | print(' ') | |
|
335 | ||
|
336 | # print 'Posicion del bloque: ',OffRHeader | |
|
337 | ||
|
338 | 294 | header = numpy.fromfile(startFp, RECORD_STRUCTURE, 1) |
|
339 | ||
|
340 | print(' ') | |
|
341 | print('puntero Record Header con seek', startFp.tell()) | |
|
342 | print(' ') | |
|
343 | ||
|
344 | print(' ') | |
|
345 | # | |
|
346 | # print 'puntero Record Header despues de seek', header.tell() | |
|
347 | print(' ') | |
|
348 | ||
|
349 | 295 | self.RecMgcNumber = hex(header['RecMgcNumber'][0]) # 0x23030001 |
|
350 | 296 | self.RecCounter = int(header['RecCounter'][0]) |
|
351 | 297 | self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0]) |
|
352 | 298 | self.Off2StartData = int(header['Off2StartData'][0]) |
|
353 | 299 | self.nUtime = header['nUtime'][0] |
|
354 | 300 | self.nMilisec = header['nMilisec'][0] |
|
355 | 301 | self.ExpTagName = str(header['ExpTagName'][0]) |
|
356 | 302 | self.ExpComment = str(header['ExpComment'][0]) |
|
357 | 303 | self.SiteLatDegrees = header['SiteLatDegrees'][0] |
|
358 | 304 | self.SiteLongDegrees = header['SiteLongDegrees'][0] |
|
359 | 305 | self.RTCgpsStatus = header['RTCgpsStatus'][0] |
|
360 | 306 | self.TransmitFrec = header['TransmitFrec'][0] |
|
361 | 307 | self.ReceiveFrec = header['ReceiveFrec'][0] |
|
362 | 308 | self.FirstOsciFrec = header['FirstOsciFrec'][0] |
|
363 | 309 | self.Polarisation = header['Polarisation'][0] |
|
364 | 310 | self.ReceiverFiltSett = header['ReceiverFiltSett'][0] |
|
365 | 311 | self.nModesInUse = header['nModesInUse'][0] |
|
366 | 312 | self.DualModeIndex = header['DualModeIndex'][0] |
|
367 | 313 | self.DualModeRange = header['DualModeRange'][0] |
|
368 | 314 | self.nDigChannels = header['nDigChannels'][0] |
|
369 | 315 | self.SampResolution = header['SampResolution'][0] |
|
370 | 316 | self.nHeights = header['nHeights'][0] |
|
371 | 317 | self.StartRangeSamp = header['StartRangeSamp'][0] |
|
372 | 318 | self.PRFhz = header['PRFhz'][0] |
|
373 | 319 | self.nCohInt = header['nCohInt'][0] |
|
374 | 320 | self.nProfiles = header['nProfiles'][0] |
|
375 | 321 | self.nChannels = header['nChannels'][0] |
|
376 | 322 | self.nIncohInt = header['nIncohInt'][0] |
|
377 | 323 | self.FFTwindowingInd = header['FFTwindowingInd'][0] |
|
378 | 324 | self.BeamAngleAzim = header['BeamAngleAzim'][0] |
|
379 | 325 | self.BeamAngleZen = header['BeamAngleZen'][0] |
|
380 | 326 | self.AntennaCoord0 = header['AntennaCoord0'][0] |
|
381 | 327 | self.AntennaAngl0 = header['AntennaAngl0'][0] |
|
382 | 328 | self.AntennaCoord1 = header['AntennaCoord1'][0] |
|
383 | 329 | self.AntennaAngl1 = header['AntennaAngl1'][0] |
|
384 | 330 | self.AntennaCoord2 = header['AntennaCoord2'][0] |
|
385 | 331 | self.AntennaAngl2 = header['AntennaAngl2'][0] |
|
386 | 332 | self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0] |
|
387 | 333 | self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0] |
|
388 | 334 | self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0] |
|
389 | 335 | self.RecAmpCalibr0 = header['RecAmpCalibr0'][0] |
|
390 | 336 | self.RecAmpCalibr1 = header['RecAmpCalibr1'][0] |
|
391 | 337 | self.RecAmpCalibr2 = header['RecAmpCalibr2'][0] |
|
392 | 338 | self.ReceiverGaindB0 = header['ReceiverGaindB0'][0] |
|
393 | 339 | self.ReceiverGaindB1 = header['ReceiverGaindB1'][0] |
|
394 | 340 | self.ReceiverGaindB2 = header['ReceiverGaindB2'][0] |
|
395 | 341 | |
|
396 | 342 | self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz) |
|
397 | 343 | |
|
398 | 344 | self.RHsize = 180 + 20 * self.nChannels |
|
399 | 345 | self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4 |
|
400 | # print 'Datasize',self.Datasize | |
|
401 | 346 | endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec |
|
402 | 347 | |
|
403 | print('==============================================') | |
|
404 | print('RecMgcNumber ', self.RecMgcNumber) | |
|
405 | print('RecCounter ', self.RecCounter) | |
|
406 | print('Off2StartNxtRec ', self.Off2StartNxtRec) | |
|
407 | print('Off2StartData ', self.Off2StartData) | |
|
408 | print('Range Resolution ', self.SampResolution) | |
|
409 | print('First Height ', self.StartRangeSamp) | |
|
410 | print('PRF (Hz) ', self.PRFhz) | |
|
411 | print('Heights (K) ', self.nHeights) | |
|
412 | print('Channels (N) ', self.nChannels) | |
|
413 | print('Profiles (J) ', self.nProfiles) | |
|
414 | print('iCoh ', self.nCohInt) | |
|
415 | print('iInCoh ', self.nIncohInt) | |
|
416 | print('BeamAngleAzim ', self.BeamAngleAzim) | |
|
417 | print('BeamAngleZen ', self.BeamAngleZen) | |
|
418 | ||
|
419 | # print 'ModoEnUso ',self.DualModeIndex | |
|
420 | # print 'UtcTime ',self.nUtime | |
|
421 | # print 'MiliSec ',self.nMilisec | |
|
422 | # print 'Exp TagName ',self.ExpTagName | |
|
423 | # print 'Exp Comment ',self.ExpComment | |
|
424 | # print 'FFT Window Index ',self.FFTwindowingInd | |
|
425 | # print 'N Dig. Channels ',self.nDigChannels | |
|
426 | print('Size de bloque ', self.RHsize) | |
|
427 | print('DataSize ', self.Datasize) | |
|
428 | print('BeamAngleAzim ', self.BeamAngleAzim) | |
|
429 | # print 'AntennaCoord0 ',self.AntennaCoord0 | |
|
430 | # print 'AntennaAngl0 ',self.AntennaAngl0 | |
|
431 | # print 'AntennaCoord1 ',self.AntennaCoord1 | |
|
432 | # print 'AntennaAngl1 ',self.AntennaAngl1 | |
|
433 | # print 'AntennaCoord2 ',self.AntennaCoord2 | |
|
434 | # print 'AntennaAngl2 ',self.AntennaAngl2 | |
|
435 | print('RecPhaseCalibr0 ', self.RecPhaseCalibr0) | |
|
436 | print('RecPhaseCalibr1 ', self.RecPhaseCalibr1) | |
|
437 | print('RecPhaseCalibr2 ', self.RecPhaseCalibr2) | |
|
438 | print('RecAmpCalibr0 ', self.RecAmpCalibr0) | |
|
439 | print('RecAmpCalibr1 ', self.RecAmpCalibr1) | |
|
440 | print('RecAmpCalibr2 ', self.RecAmpCalibr2) | |
|
441 | print('ReceiverGaindB0 ', self.ReceiverGaindB0) | |
|
442 | print('ReceiverGaindB1 ', self.ReceiverGaindB1) | |
|
443 | print('ReceiverGaindB2 ', self.ReceiverGaindB2) | |
|
444 | print('==============================================') | |
|
445 | ||
|
348 | ||
|
446 | 349 | if OffRHeader > endFp: |
|
447 | 350 | sys.stderr.write( |
|
448 | 351 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp) |
|
449 | 352 | return 0 |
|
450 | 353 | |
|
451 | 354 | if OffRHeader < endFp: |
|
452 | 355 | sys.stderr.write( |
|
453 | 356 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp) |
|
454 | 357 | return 0 |
|
455 | 358 | |
|
456 | 359 | return 1 |
|
457 | 360 | |
|
458 | 361 | |
|
459 | 362 | class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader): |
|
460 | 363 | |
|
461 | 364 | path = None |
|
462 | 365 | startDate = None |
|
463 | 366 | endDate = None |
|
464 | 367 | startTime = None |
|
465 | 368 | endTime = None |
|
466 | 369 | walk = None |
|
467 | 370 | isConfig = False |
|
468 | 371 | |
|
469 | 372 | fileList = None |
|
470 | 373 | |
|
471 | 374 | # metadata |
|
472 | 375 | TimeZone = None |
|
473 | 376 | Interval = None |
|
474 | 377 | heightList = None |
|
475 | 378 | |
|
476 | 379 | # data |
|
477 | 380 | data = None |
|
478 | 381 | utctime = None |
|
479 | 382 | |
|
480 | 383 | def __init__(self, **kwargs): |
|
481 | 384 | |
|
482 | 385 | # Eliminar de la base la herencia |
|
483 | 386 | ProcessingUnit.__init__(self, **kwargs) |
|
484 | 387 | |
|
485 | 388 | #self.isConfig = False |
|
486 | 389 | |
|
487 | 390 | #self.pts2read_SelfSpectra = 0 |
|
488 | 391 | #self.pts2read_CrossSpectra = 0 |
|
489 | 392 | #self.pts2read_DCchannels = 0 |
|
490 | 393 | #self.datablock = None |
|
491 | 394 | self.utc = None |
|
492 | 395 | self.ext = ".fdt" |
|
493 | 396 | self.optchar = "P" |
|
494 | 397 | self.fpFile = None |
|
495 | 398 | self.fp = None |
|
496 | 399 | self.BlockCounter = 0 |
|
497 | 400 | self.dtype = None |
|
498 | 401 | self.fileSizeByHeader = None |
|
499 | 402 | self.filenameList = [] |
|
500 | 403 | self.fileSelector = 0 |
|
501 | 404 | self.Off2StartNxtRec = 0 |
|
502 | 405 | self.RecCounter = 0 |
|
503 | 406 | self.flagNoMoreFiles = 0 |
|
504 | 407 | self.data_spc = None |
|
505 | 408 | self.data_cspc = None |
|
506 | 409 | self.data_output = None |
|
507 | 410 | self.path = None |
|
508 | 411 | self.OffsetStartHeader = 0 |
|
509 | 412 | self.Off2StartData = 0 |
|
510 | 413 | self.ipp = 0 |
|
511 | 414 | self.nFDTdataRecors = 0 |
|
512 | 415 | self.blocksize = 0 |
|
513 | 416 | self.dataOut = Spectra() |
|
514 | 417 | self.profileIndex = 1 # Always |
|
515 | 418 | self.dataOut.flagNoData = False |
|
516 | 419 | self.dataOut.nRdPairs = 0 |
|
517 | 420 | self.dataOut.data_spc = None |
|
518 | 421 | self.dataOut.velocityX = [] |
|
519 | 422 | self.dataOut.velocityY = [] |
|
520 | 423 | self.dataOut.velocityV = [] |
|
521 | 424 | |
|
522 | 425 | def Files2Read(self, fp): |
|
523 | 426 | ''' |
|
524 | 427 | Function that indicates the number of .fdt files that exist in the folder to be read. |
|
525 | 428 | It also creates an organized list with the names of the files to read. |
|
526 | 429 | ''' |
|
527 | 430 | # self.__checkPath() |
|
528 | 431 | |
|
529 | 432 | # Gets the list of files within the fp address |
|
530 | 433 | ListaData = os.listdir(fp) |
|
531 | 434 | # Sort the list of files from least to largest by names |
|
532 | 435 | ListaData = sorted(ListaData) |
|
533 | 436 | nFiles = 0 # File Counter |
|
534 | 437 | FileList = [] # A list is created that will contain the .fdt files |
|
535 | 438 | for IndexFile in ListaData: |
|
536 | 439 | if '.fdt' in IndexFile: |
|
537 | 440 | FileList.append(IndexFile) |
|
538 | 441 | nFiles += 1 |
|
539 | 442 | |
|
540 | # print 'Files2Read' | |
|
541 | # print 'Existen '+str(nFiles)+' archivos .fdt' | |
|
542 | ||
|
543 | 443 | self.filenameList = FileList # List of files from least to largest by names |
|
544 | 444 | |
|
545 | 445 | def run(self, **kwargs): |
|
546 | 446 | ''' |
|
547 | 447 | This method will be the one that will initiate the data entry, will be called constantly. |
|
548 | 448 | You should first verify that your Setup () is set up and then continue to acquire |
|
549 | 449 | the data to be processed with getData (). |
|
550 | 450 | ''' |
|
551 | 451 | if not self.isConfig: |
|
552 | 452 | self.setup(**kwargs) |
|
553 | 453 | self.isConfig = True |
|
554 | 454 | |
|
555 | 455 | self.getData() |
|
556 | # print 'running' | |
|
557 | 456 | |
|
558 | 457 | def setup(self, path=None, |
|
559 | 458 | startDate=None, |
|
560 | 459 | endDate=None, |
|
561 | 460 | startTime=None, |
|
562 | 461 | endTime=None, |
|
563 | 462 | walk=True, |
|
564 | 463 | timezone='utc', |
|
565 | 464 | code=None, |
|
566 | 465 | online=False, |
|
567 | 466 | ReadMode=None, |
|
568 | 467 | **kwargs): |
|
569 | 468 | |
|
570 | 469 | self.isConfig = True |
|
571 | 470 | |
|
572 | 471 | self.path = path |
|
573 | 472 | self.startDate = startDate |
|
574 | 473 | self.endDate = endDate |
|
575 | 474 | self.startTime = startTime |
|
576 | 475 | self.endTime = endTime |
|
577 | 476 | self.walk = walk |
|
578 | 477 | self.ReadMode = int(ReadMode) |
|
579 | 478 | |
|
580 | 479 | pass |
|
581 | 480 | |
|
582 | 481 | def getData(self): |
|
583 | 482 | ''' |
|
584 | 483 | Before starting this function, you should check that there is still an unread file, |
|
585 | 484 | If there are still blocks to read or if the data block is empty. |
|
586 | 485 | |
|
587 | 486 | You should call the file "read". |
|
588 | 487 | |
|
589 | 488 | ''' |
|
590 | 489 | |
|
591 | 490 | if self.flagNoMoreFiles: |
|
592 | 491 | self.dataOut.flagNoData = True |
|
593 | print('NoData se vuelve true') | |
|
594 | 492 | return 0 |
|
595 | 493 | |
|
596 | 494 | self.fp = self.path |
|
597 | 495 | self.Files2Read(self.fp) |
|
598 | 496 | self.readFile(self.fp) |
|
599 | 497 | self.dataOut.data_spc = self.data_spc |
|
600 |
self.dataOut.data_cspc = |
|
|
601 |
self.dataOut.data_output |
|
|
602 | ||
|
603 | print('self.dataOut.data_output', shape(self.dataOut.data_output)) | |
|
604 | ||
|
605 | # self.removeDC() | |
|
606 | return self.dataOut.data_spc | |
|
607 | ||
|
608 | def readFile(self, fp): | |
|
498 | self.dataOut.data_cspc =self.data_cspc | |
|
499 | self.dataOut.data_output=self.data_output | |
|
500 | ||
|
501 | return self.dataOut.data_spc | |
|
502 | ||
|
503 | ||
|
504 | def readFile(self,fp): | |
|
609 | 505 | ''' |
|
610 | 506 | You must indicate if you are reading in Online or Offline mode and load the |
|
611 | 507 | The parameters for this file reading mode. |
|
612 | 508 | |
|
613 | 509 | Then you must do 2 actions: |
|
614 | 510 | |
|
615 | 511 | 1. Get the BLTR FileHeader. |
|
616 | 512 | 2. Start reading the first block. |
|
617 | 513 | ''' |
|
618 | ||
|
619 | # The address of the folder is generated the name of the .fdt file that will be read | |
|
620 | print("File: ", self.fileSelector + 1) | |
|
621 | ||
|
514 | ||
|
622 | 515 | if self.fileSelector < len(self.filenameList): |
|
623 | 516 | |
|
624 | 517 | self.fpFile = str(fp) + '/' + \ |
|
625 | 518 | str(self.filenameList[self.fileSelector]) |
|
626 | # print self.fpFile | |
|
627 | 519 | fheader = FileHeaderBLTR() |
|
628 | 520 | fheader.FHread(self.fpFile) # Bltr FileHeader Reading |
|
629 | 521 | self.nFDTdataRecors = fheader.nFDTdataRecors |
|
630 | 522 | |
|
631 | 523 | self.readBlock() # Block reading |
|
632 | 524 | else: |
|
633 | print('readFile FlagNoData becomes true') | |
|
634 | self.flagNoMoreFiles = True | |
|
525 | self.flagNoMoreFiles=True | |
|
635 | 526 | self.dataOut.flagNoData = True |
|
636 | 527 | return 0 |
|
637 | 528 | |
|
638 | 529 | def getVelRange(self, extrapoints=0): |
|
639 | 530 | Lambda = SPEED_OF_LIGHT / 50000000 |
|
640 | 531 | # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt) |
|
641 | 532 | PRF = self.dataOut.PRF |
|
642 | 533 | Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.) |
|
643 | 534 | deltafreq = PRF / (self.nProfiles) |
|
644 | 535 | deltavel = (Vmax * 2) / (self.nProfiles) |
|
645 | 536 | freqrange = deltafreq * \ |
|
646 | 537 | (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2 |
|
647 | 538 | velrange = deltavel * \ |
|
648 | 539 | (numpy.arange(self.nProfiles) - self.nProfiles / 2.) |
|
649 | 540 | return velrange |
|
650 | 541 | |
|
651 | 542 | def readBlock(self): |
|
652 | 543 | ''' |
|
653 | 544 | It should be checked if the block has data, if it is not passed to the next file. |
|
654 | 545 | |
|
655 | 546 | Then the following is done: |
|
656 | 547 | |
|
657 | 548 | 1. Read the RecordHeader |
|
658 | 549 | 2. Fill the buffer with the current block number. |
|
659 | 550 | |
|
660 | 551 | ''' |
|
661 | ||
|
662 |
if self.BlockCounter < self.nFDTdataRecors |
|
|
663 | print(self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!') | |
|
664 | if self.ReadMode == 1: | |
|
665 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter + 1) | |
|
666 | elif self.ReadMode == 0: | |
|
552 | ||
|
553 | if self.BlockCounter < self.nFDTdataRecors-1: | |
|
554 | if self.ReadMode==1: | |
|
555 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter+1) | |
|
556 | elif self.ReadMode==0: | |
|
667 | 557 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter) |
|
668 | 558 | |
|
669 | 559 | rheader.RHread(self.fpFile) # Bltr FileHeader Reading |
|
670 | 560 | |
|
671 | 561 | self.OffsetStartHeader = rheader.OffsetStartHeader |
|
672 | 562 | self.RecCounter = rheader.RecCounter |
|
673 | 563 | self.Off2StartNxtRec = rheader.Off2StartNxtRec |
|
674 | 564 | self.Off2StartData = rheader.Off2StartData |
|
675 | 565 | self.nProfiles = rheader.nProfiles |
|
676 | 566 | self.nChannels = rheader.nChannels |
|
677 | 567 | self.nHeights = rheader.nHeights |
|
678 | 568 | self.frequency = rheader.TransmitFrec |
|
679 | 569 | self.DualModeIndex = rheader.DualModeIndex |
|
680 | 570 | |
|
681 | 571 | self.pairsList = [(0, 1), (0, 2), (1, 2)] |
|
682 | 572 | self.dataOut.pairsList = self.pairsList |
|
683 | 573 | |
|
684 | 574 | self.nRdPairs = len(self.dataOut.pairsList) |
|
685 | 575 | self.dataOut.nRdPairs = self.nRdPairs |
|
686 | ||
|
687 |
self.__ |
|
|
688 | self.__deltaHeigth = rheader.SampResolution | |
|
689 |
self.dataOut. |
|
|
690 | numpy.array(list(range(self.nHeights))) * self.__deltaHeigth | |
|
691 | self.dataOut.channelList = list(range(self.nChannels)) | |
|
692 |
self.dataOut.n |
|
|
693 |
self.dataOut. |
|
|
694 |
self.dataOut. |
|
|
695 |
self.dataOut. |
|
|
696 |
self.dataOut. |
|
|
697 |
self.dataOut. |
|
|
698 | self.dataOut.utctime = rheader.nUtime | |
|
699 | self.dataOut.timeZone = 0 | |
|
700 | self.dataOut.normFactor = self.dataOut.nProfiles * \ | |
|
701 | self.dataOut.nIncohInt * self.dataOut.nCohInt | |
|
702 | self.dataOut.outputInterval = self.dataOut.ippSeconds * \ | |
|
703 | self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles | |
|
704 | ||
|
705 | self.data_output = numpy.ones([3, rheader.nHeights]) * numpy.NaN | |
|
706 | print('self.data_output', shape(self.data_output)) | |
|
707 | self.dataOut.velocityX = [] | |
|
708 | self.dataOut.velocityY = [] | |
|
709 | self.dataOut.velocityV = [] | |
|
710 | ||
|
576 | self.__firstHeigth=rheader.StartRangeSamp | |
|
577 | self.__deltaHeigth=rheader.SampResolution | |
|
578 | self.dataOut.heightList= self.__firstHeigth + numpy.array(range(self.nHeights))*self.__deltaHeigth | |
|
579 | self.dataOut.channelList = range(self.nChannels) | |
|
580 | self.dataOut.nProfiles=rheader.nProfiles | |
|
581 | self.dataOut.nIncohInt=rheader.nIncohInt | |
|
582 | self.dataOut.nCohInt=rheader.nCohInt | |
|
583 | self.dataOut.ippSeconds= 1/float(rheader.PRFhz) | |
|
584 | self.dataOut.PRF=rheader.PRFhz | |
|
585 | self.dataOut.nFFTPoints=rheader.nProfiles | |
|
586 | self.dataOut.utctime=rheader.nUtime | |
|
587 | self.dataOut.timeZone=0 | |
|
588 | self.dataOut.normFactor= self.dataOut.nProfiles*self.dataOut.nIncohInt*self.dataOut.nCohInt | |
|
589 | self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles | |
|
590 | ||
|
591 | self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN | |
|
592 | self.dataOut.velocityX=[] | |
|
593 | self.dataOut.velocityY=[] | |
|
594 | self.dataOut.velocityV=[] | |
|
595 | ||
|
711 | 596 |
|
|
712 | 597 | shape. |
|
713 | 598 | ''' |
|
714 | 599 | |
|
715 | 600 | # Procedure to take the pointer to where the date block starts |
|
716 | 601 | startDATA = open(self.fpFile, "rb") |
|
717 | 602 | OffDATA = self.OffsetStartHeader + self.RecCounter * \ |
|
718 | 603 | self.Off2StartNxtRec + self.Off2StartData |
|
719 | 604 | startDATA.seek(OffDATA, os.SEEK_SET) |
|
720 | 605 | |
|
721 | 606 | def moving_average(x, N=2): |
|
722 | 607 | return numpy.convolve(x, numpy.ones((N,)) / N)[(N - 1):] |
|
723 | 608 | |
|
724 | 609 | def gaus(xSamples, a, x0, sigma): |
|
725 | 610 | return a * exp(-(xSamples - x0)**2 / (2 * sigma**2)) |
|
726 | 611 | |
|
727 | 612 | def Find(x, value): |
|
728 | 613 | for index in range(len(x)): |
|
729 | 614 | if x[index] == value: |
|
730 | 615 | return index |
|
731 | 616 | |
|
732 | 617 | def pol2cart(rho, phi): |
|
733 | 618 | x = rho * numpy.cos(phi) |
|
734 | 619 | y = rho * numpy.sin(phi) |
|
735 | 620 | return(x, y) |
|
736 | 621 | |
|
737 |
if self.DualModeIndex |
|
|
738 | ||
|
739 | self.data_fft = numpy.fromfile( | |
|
740 | startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights) | |
|
741 | ||
|
742 |
self.data_fft |
|
|
743 | ||
|
744 | self.data_block = numpy.reshape( | |
|
745 | self.data_fft, (self.nHeights, self.nChannels, self.nProfiles)) | |
|
746 | ||
|
747 | self.data_block = numpy.transpose(self.data_block, (1, 2, 0)) | |
|
748 | ||
|
622 | if self.DualModeIndex==self.ReadMode: | |
|
623 | ||
|
624 | self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights ) | |
|
625 | self.data_fft = numpy.empty(101376) | |
|
626 | ||
|
627 | self.data_fft=self.data_fft.astype(numpy.dtype('complex')) | |
|
628 | ||
|
629 | self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles )) | |
|
630 | ||
|
631 | self.data_block = numpy.transpose(self.data_block, (1,2,0)) | |
|
632 | ||
|
749 | 633 | copy = self.data_block.copy() |
|
750 | 634 | spc = copy * numpy.conjugate(copy) |
|
751 | 635 | |
|
752 | 636 | self.data_spc = numpy.absolute( |
|
753 | 637 | spc) # valor absoluto o magnitud |
|
754 | 638 | |
|
755 | 639 | factor = self.dataOut.normFactor |
|
756 | 640 | |
|
757 | 641 | z = self.data_spc.copy() # /factor |
|
758 | 642 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
759 | #zdB = 10*numpy.log10(z) | |
|
760 | print(' ') | |
|
761 | print('Z: ') | |
|
762 | print(shape(z)) | |
|
763 | print(' ') | |
|
764 | print(' ') | |
|
765 | ||
|
766 | self.dataOut.data_spc = self.data_spc | |
|
767 | ||
|
768 | self.noise = self.dataOut.getNoise( | |
|
769 | ymin_index=80, ymax_index=132) # /factor | |
|
770 | #noisedB = 10*numpy.log10(self.noise) | |
|
643 | self.dataOut.data_spc=self.data_spc | |
|
644 | self.noise = self.dataOut.getNoise(ymin_index=80, ymax_index=132)#/factor | |
|
771 | 645 | |
|
772 | 646 | ySamples = numpy.ones([3, self.nProfiles]) |
|
773 | 647 | phase = numpy.ones([3, self.nProfiles]) |
|
774 | 648 | CSPCSamples = numpy.ones( |
|
775 | 649 | [3, self.nProfiles], dtype=numpy.complex_) |
|
776 | 650 | coherence = numpy.ones([3, self.nProfiles]) |
|
777 | 651 | PhaseSlope = numpy.ones(3) |
|
778 | 652 | PhaseInter = numpy.ones(3) |
|
779 | 653 | |
|
780 | 654 | '''****** Getting CrossSpectra ******''' |
|
781 |
cspc |
|
|
782 |
self.data_cspc |
|
|
783 | ||
|
784 |
xFrec |
|
|
785 |
VelRange |
|
|
786 |
self.dataOut.VelRange |
|
|
787 |
|
|
|
788 |
|
|
|
789 | # print 'xFrec',xFrec | |
|
790 |
|
|
|
791 | # print ' ' | |
|
792 | # Height=35 | |
|
793 | for i in range(self.nRdPairs): | |
|
794 | ||
|
655 | cspc=self.data_block.copy() | |
|
656 | self.data_cspc=self.data_block.copy() | |
|
657 | ||
|
658 | xFrec=self.getVelRange(1) | |
|
659 | VelRange=self.getVelRange(1) | |
|
660 | self.dataOut.VelRange=VelRange | |
|
661 | ||
|
662 | ||
|
663 | for i in range(self.nRdPairs): | |
|
664 | ||
|
795 | 665 | chan_index0 = self.dataOut.pairsList[i][0] |
|
796 | 666 | chan_index1 = self.dataOut.pairsList[i][1] |
|
797 | 667 | |
|
798 | 668 | self.data_cspc[i, :, :] = cspc[chan_index0, :, |
|
799 | 669 | :] * numpy.conjugate(cspc[chan_index1, :, :]) |
|
800 | 670 | |
|
801 | 671 | '''Getting Eij and Nij''' |
|
802 | 672 | (AntennaX0, AntennaY0) = pol2cart( |
|
803 | 673 | rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180) |
|
804 | 674 | (AntennaX1, AntennaY1) = pol2cart( |
|
805 | 675 | rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180) |
|
806 | 676 | (AntennaX2, AntennaY2) = pol2cart( |
|
807 | 677 | rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180) |
|
808 | 678 | |
|
809 | 679 | E01 = AntennaX0 - AntennaX1 |
|
810 | 680 | N01 = AntennaY0 - AntennaY1 |
|
811 | 681 | |
|
812 | 682 | E02 = AntennaX0 - AntennaX2 |
|
813 | 683 | N02 = AntennaY0 - AntennaY2 |
|
814 | 684 | |
|
815 | 685 | E12 = AntennaX1 - AntennaX2 |
|
816 | 686 | N12 = AntennaY1 - AntennaY2 |
|
817 | 687 | |
|
818 | 688 | self.ChanDist = numpy.array( |
|
819 | 689 | [[E01, N01], [E02, N02], [E12, N12]]) |
|
820 | 690 | |
|
821 | 691 | self.dataOut.ChanDist = self.ChanDist |
|
822 | 692 | |
|
823 | ||
|
824 | # for Height in range(self.nHeights): | |
|
825 | # | |
|
826 | # for i in range(self.nRdPairs): | |
|
827 | # | |
|
828 | # '''****** Line of Data SPC ******''' | |
|
829 | # zline=z[i,:,Height] | |
|
830 | # | |
|
831 | # '''****** DC is removed ******''' | |
|
832 | # DC=Find(zline,numpy.amax(zline)) | |
|
833 | # zline[DC]=(zline[DC-1]+zline[DC+1])/2 | |
|
834 | # | |
|
835 | # | |
|
836 | # '''****** SPC is normalized ******''' | |
|
837 | # FactNorm= zline.copy() / numpy.sum(zline.copy()) | |
|
838 | # FactNorm= FactNorm/numpy.sum(FactNorm) | |
|
839 | # | |
|
840 | # SmoothSPC=moving_average(FactNorm,N=3) | |
|
841 | # | |
|
842 | # xSamples = ar(range(len(SmoothSPC))) | |
|
843 | # ySamples[i] = SmoothSPC-self.noise[i] | |
|
844 | # | |
|
845 | # for i in range(self.nRdPairs): | |
|
846 | # | |
|
847 | # '''****** Line of Data CSPC ******''' | |
|
848 | # cspcLine=self.data_cspc[i,:,Height].copy() | |
|
849 | # | |
|
850 | # | |
|
851 | # | |
|
852 | # '''****** CSPC is normalized ******''' | |
|
853 | # chan_index0 = self.dataOut.pairsList[i][0] | |
|
854 | # chan_index1 = self.dataOut.pairsList[i][1] | |
|
855 | # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1]) | |
|
856 | # | |
|
857 | # | |
|
858 | # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor) | |
|
859 | # | |
|
860 | # | |
|
861 | # CSPCSamples[i] = CSPCNorm-self.noise[i] | |
|
862 | # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor) | |
|
863 | # | |
|
864 | # '''****** DC is removed ******''' | |
|
865 | # DC=Find(coherence[i],numpy.amax(coherence[i])) | |
|
866 | # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2 | |
|
867 | # coherence[i]= moving_average(coherence[i],N=2) | |
|
868 | # | |
|
869 | # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi | |
|
870 | # | |
|
871 | # | |
|
872 | # '''****** Getting fij width ******''' | |
|
873 | # | |
|
874 | # yMean=[] | |
|
875 | # yMean2=[] | |
|
876 | # | |
|
877 | # for j in range(len(ySamples[1])): | |
|
878 | # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]])) | |
|
879 | # | |
|
880 | # '''******* Getting fitting Gaussian ******''' | |
|
881 | # meanGauss=sum(xSamples*yMean) / len(xSamples) | |
|
882 | # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) | |
|
883 | # #print 'Height',Height,'SNR', meanGauss/sigma**2 | |
|
884 | # | |
|
885 | # if (abs(meanGauss/sigma**2) > 0.0001) : | |
|
886 | # | |
|
887 | # try: | |
|
888 | # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma]) | |
|
889 | # | |
|
890 | # if numpy.amax(popt)>numpy.amax(yMean)*0.3: | |
|
891 | # FitGauss=gaus(xSamples,*popt) | |
|
892 | # | |
|
893 | # else: | |
|
894 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
|
895 | # print 'Verificador: Dentro', Height | |
|
896 | # except RuntimeError: | |
|
897 | # | |
|
898 | # try: | |
|
899 | # for j in range(len(ySamples[1])): | |
|
900 | # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]])) | |
|
901 | # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma]) | |
|
902 | # FitGauss=gaus(xSamples,*popt) | |
|
903 | # print 'Verificador: Exepcion1', Height | |
|
904 | # except RuntimeError: | |
|
905 | # | |
|
906 | # try: | |
|
907 | # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma]) | |
|
908 | # FitGauss=gaus(xSamples,*popt) | |
|
909 | # print 'Verificador: Exepcion2', Height | |
|
910 | # except RuntimeError: | |
|
911 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
|
912 | # print 'Verificador: Exepcion3', Height | |
|
913 | # else: | |
|
914 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
|
915 | # #print 'Verificador: Fuera', Height | |
|
916 | # | |
|
917 | # | |
|
918 | # | |
|
919 | # Maximun=numpy.amax(yMean) | |
|
920 | # eMinus1=Maximun*numpy.exp(-1) | |
|
921 | # | |
|
922 | # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1))) | |
|
923 | # HalfWidth= xFrec[HWpos] | |
|
924 | # GCpos=Find(FitGauss, numpy.amax(FitGauss)) | |
|
925 | # Vpos=Find(FactNorm, numpy.amax(FactNorm)) | |
|
926 | # #Vpos=numpy.sum(FactNorm)/len(FactNorm) | |
|
927 | # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) ))) | |
|
928 | # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos | |
|
929 | # '''****** Getting Fij ******''' | |
|
930 | # | |
|
931 | # GaussCenter=xFrec[GCpos] | |
|
932 | # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0): | |
|
933 | # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001 | |
|
934 | # else: | |
|
935 | # Fij=abs(GaussCenter-HalfWidth)+0.0000001 | |
|
936 | # | |
|
937 | # '''****** Getting Frecuency range of significant data ******''' | |
|
938 | # | |
|
939 | # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10))) | |
|
940 | # | |
|
941 | # if Rangpos<GCpos: | |
|
942 | # Range=numpy.array([Rangpos,2*GCpos-Rangpos]) | |
|
943 | # else: | |
|
944 | # Range=numpy.array([2*GCpos-Rangpos,Rangpos]) | |
|
945 | # | |
|
946 | # FrecRange=xFrec[Range[0]:Range[1]] | |
|
947 | # | |
|
948 | # #print 'FrecRange', FrecRange | |
|
949 | # '''****** Getting SCPC Slope ******''' | |
|
950 | # | |
|
951 | # for i in range(self.nRdPairs): | |
|
952 | # | |
|
953 | # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5: | |
|
954 | # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3) | |
|
955 | # | |
|
956 | # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange) | |
|
957 | # PhaseSlope[i]=slope | |
|
958 | # PhaseInter[i]=intercept | |
|
959 | # else: | |
|
960 | # PhaseSlope[i]=0 | |
|
961 | # PhaseInter[i]=0 | |
|
962 | # | |
|
963 | # # plt.figure(i+15) | |
|
964 | # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1])) | |
|
965 | # # plt.xlabel('Frecuencia (KHz)') | |
|
966 | # # plt.ylabel('Magnitud') | |
|
967 | # # #plt.subplot(311+i) | |
|
968 | # # plt.plot(FrecRange,PhaseRange,'b') | |
|
969 | # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r') | |
|
970 | # | |
|
971 | # #plt.axis([-0.6, 0.2, -3.2, 3.2]) | |
|
972 | # | |
|
973 | # | |
|
974 | # '''Getting constant C''' | |
|
975 | # cC=(Fij*numpy.pi)**2 | |
|
976 | # | |
|
977 | # # '''Getting Eij and Nij''' | |
|
978 | # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180) | |
|
979 | # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180) | |
|
980 | # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180) | |
|
981 | # # | |
|
982 | # # E01=AntennaX0-AntennaX1 | |
|
983 | # # N01=AntennaY0-AntennaY1 | |
|
984 | # # | |
|
985 | # # E02=AntennaX0-AntennaX2 | |
|
986 | # # N02=AntennaY0-AntennaY2 | |
|
987 | # # | |
|
988 | # # E12=AntennaX1-AntennaX2 | |
|
989 | # # N12=AntennaY1-AntennaY2 | |
|
990 | # | |
|
991 | # '''****** Getting constants F and G ******''' | |
|
992 | # MijEijNij=numpy.array([[E02,N02], [E12,N12]]) | |
|
993 | # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi) | |
|
994 | # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi) | |
|
995 | # MijResults=numpy.array([MijResult0,MijResult1]) | |
|
996 | # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) | |
|
997 | # | |
|
998 | # '''****** Getting constants A, B and H ******''' | |
|
999 | # W01=numpy.amax(coherence[0]) | |
|
1000 | # W02=numpy.amax(coherence[1]) | |
|
1001 | # W12=numpy.amax(coherence[2]) | |
|
1002 | # | |
|
1003 | # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC)) | |
|
1004 | # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC)) | |
|
1005 | # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC)) | |
|
1006 | # | |
|
1007 | # WijResults=numpy.array([WijResult0, WijResult1, WijResult2]) | |
|
1008 | # | |
|
1009 | # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ]) | |
|
1010 | # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) | |
|
1011 | # | |
|
1012 | # VxVy=numpy.array([[cA,cH],[cH,cB]]) | |
|
1013 | # | |
|
1014 | # VxVyResults=numpy.array([-cF,-cG]) | |
|
1015 | # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults) | |
|
1016 | # Vzon = Vy | |
|
1017 | # Vmer = Vx | |
|
1018 | # Vmag=numpy.sqrt(Vzon**2+Vmer**2) | |
|
1019 | # Vang=numpy.arctan2(Vmer,Vzon) | |
|
1020 | # | |
|
1021 | # if abs(Vy)<100 and abs(Vy)> 0.: | |
|
1022 | # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag | |
|
1023 | # #print 'Vmag',Vmag | |
|
1024 | # else: | |
|
1025 | # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN) | |
|
1026 | # | |
|
1027 | # if abs(Vx)<100 and abs(Vx) > 0.: | |
|
1028 | # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang | |
|
1029 | # #print 'Vang',Vang | |
|
1030 | # else: | |
|
1031 | # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN) | |
|
1032 | # | |
|
1033 | # if abs(GaussCenter)<2: | |
|
1034 | # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos]) | |
|
1035 | # | |
|
1036 | # else: | |
|
1037 | # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN) | |
|
1038 | # | |
|
1039 | # | |
|
1040 | # # print '********************************************' | |
|
1041 | # # print 'HalfWidth ', HalfWidth | |
|
1042 | # # print 'Maximun ', Maximun | |
|
1043 | # # print 'eMinus1 ', eMinus1 | |
|
1044 | # # print 'Rangpos ', Rangpos | |
|
1045 | # # print 'GaussCenter ',GaussCenter | |
|
1046 | # # print 'E01 ',E01 | |
|
1047 | # # print 'N01 ',N01 | |
|
1048 | # # print 'E02 ',E02 | |
|
1049 | # # print 'N02 ',N02 | |
|
1050 | # # print 'E12 ',E12 | |
|
1051 | # # print 'N12 ',N12 | |
|
1052 | # #print 'self.dataOut.velocityX ', self.dataOut.velocityX | |
|
1053 | # # print 'Fij ', Fij | |
|
1054 | # # print 'cC ', cC | |
|
1055 | # # print 'cF ', cF | |
|
1056 | # # print 'cG ', cG | |
|
1057 | # # print 'cA ', cA | |
|
1058 | # # print 'cB ', cB | |
|
1059 | # # print 'cH ', cH | |
|
1060 | # # print 'Vx ', Vx | |
|
1061 | # # print 'Vy ', Vy | |
|
1062 | # # print 'Vmag ', Vmag | |
|
1063 | # # print 'Vang ', Vang*180/numpy.pi | |
|
1064 | # # print 'PhaseSlope ',PhaseSlope[0] | |
|
1065 | # # print 'PhaseSlope ',PhaseSlope[1] | |
|
1066 | # # print 'PhaseSlope ',PhaseSlope[2] | |
|
1067 | # # print '********************************************' | |
|
1068 | # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY) | |
|
1069 | # | |
|
1070 | # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX) | |
|
1071 | # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY) | |
|
1072 | # #print 'self.dataOut.velocityV', self.dataOut.velocityV | |
|
1073 | # | |
|
1074 | # self.data_output[0]=numpy.array(self.dataOut.velocityX) | |
|
1075 | # self.data_output[1]=numpy.array(self.dataOut.velocityY) | |
|
1076 | # self.data_output[2]=numpy.array(self.dataOut.velocityV) | |
|
1077 | # | |
|
1078 | # prin= self.data_output[0][~numpy.isnan(self.data_output[0])] | |
|
1079 | # print ' ' | |
|
1080 | # print 'VmagAverage',numpy.mean(prin) | |
|
1081 | # print ' ' | |
|
1082 | # # plt.figure(5) | |
|
1083 | # # plt.subplot(211) | |
|
1084 | # # plt.plot(self.dataOut.velocityX,'yo:') | |
|
1085 | # # plt.subplot(212) | |
|
1086 | # # plt.plot(self.dataOut.velocityY,'yo:') | |
|
1087 | # | |
|
1088 | # # plt.figure(1) | |
|
1089 | # # # plt.subplot(121) | |
|
1090 | # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0') | |
|
1091 | # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1') | |
|
1092 | # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2') | |
|
1093 | # # # plt.plot(xFrec,FitGauss,'yo:',label='fit') | |
|
1094 | # # # plt.legend() | |
|
1095 | # # plt.title('DATOS A ALTURA DE 2850 METROS') | |
|
1096 | # # | |
|
1097 | # # plt.xlabel('Frecuencia (KHz)') | |
|
1098 | # # plt.ylabel('Magnitud') | |
|
1099 | # # # plt.subplot(122) | |
|
1100 | # # # plt.title('Fit for Time Constant') | |
|
1101 | # # #plt.plot(xFrec,zline) | |
|
1102 | # # #plt.plot(xFrec,SmoothSPC,'g') | |
|
1103 | # # plt.plot(xFrec,FactNorm) | |
|
1104 | # # plt.axis([-4, 4, 0, 0.15]) | |
|
1105 | # # # plt.xlabel('SelfSpectra KHz') | |
|
1106 | # # | |
|
1107 | # # plt.figure(10) | |
|
1108 | # # # plt.subplot(121) | |
|
1109 | # # plt.plot(xFrec,ySamples[0],'b',label='Ch0') | |
|
1110 | # # plt.plot(xFrec,ySamples[1],'y',label='Ch1') | |
|
1111 | # # plt.plot(xFrec,ySamples[2],'r',label='Ch2') | |
|
1112 | # # # plt.plot(xFrec,FitGauss,'yo:',label='fit') | |
|
1113 | # # plt.legend() | |
|
1114 | # # plt.title('SELFSPECTRA EN CANALES') | |
|
1115 | # # | |
|
1116 | # # plt.xlabel('Frecuencia (KHz)') | |
|
1117 | # # plt.ylabel('Magnitud') | |
|
1118 | # # # plt.subplot(122) | |
|
1119 | # # # plt.title('Fit for Time Constant') | |
|
1120 | # # #plt.plot(xFrec,zline) | |
|
1121 | # # #plt.plot(xFrec,SmoothSPC,'g') | |
|
1122 | # # # plt.plot(xFrec,FactNorm) | |
|
1123 | # # # plt.axis([-4, 4, 0, 0.15]) | |
|
1124 | # # # plt.xlabel('SelfSpectra KHz') | |
|
1125 | # # | |
|
1126 | # # plt.figure(9) | |
|
1127 | # # | |
|
1128 | # # | |
|
1129 | # # plt.title('DATOS SUAVIZADOS') | |
|
1130 | # # plt.xlabel('Frecuencia (KHz)') | |
|
1131 | # # plt.ylabel('Magnitud') | |
|
1132 | # # plt.plot(xFrec,SmoothSPC,'g') | |
|
1133 | # # | |
|
1134 | # # #plt.plot(xFrec,FactNorm) | |
|
1135 | # # plt.axis([-4, 4, 0, 0.15]) | |
|
1136 | # # # plt.xlabel('SelfSpectra KHz') | |
|
1137 | # # # | |
|
1138 | # # plt.figure(2) | |
|
1139 | # # # #plt.subplot(121) | |
|
1140 | # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra') | |
|
1141 | # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano') | |
|
1142 | # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo') | |
|
1143 | # # # #plt.plot(xFrec,phase) | |
|
1144 | # # # plt.xlabel('Suavizado, promediado KHz') | |
|
1145 | # # plt.title('SELFSPECTRA PROMEDIADO') | |
|
1146 | # # # #plt.subplot(122) | |
|
1147 | # # # #plt.plot(xSamples,zline) | |
|
1148 | # # plt.xlabel('Frecuencia (KHz)') | |
|
1149 | # # plt.ylabel('Magnitud') | |
|
1150 | # # plt.legend() | |
|
1151 | # # # | |
|
1152 | # # # plt.figure(3) | |
|
1153 | # # # plt.subplot(311) | |
|
1154 | # # # #plt.plot(xFrec,phase[0]) | |
|
1155 | # # # plt.plot(xFrec,phase[0],'g') | |
|
1156 | # # # plt.subplot(312) | |
|
1157 | # # # plt.plot(xFrec,phase[1],'g') | |
|
1158 | # # # plt.subplot(313) | |
|
1159 | # # # plt.plot(xFrec,phase[2],'g') | |
|
1160 | # # # #plt.plot(xFrec,phase[2]) | |
|
1161 | # # # | |
|
1162 | # # # plt.figure(4) | |
|
1163 | # # # | |
|
1164 | # # # plt.plot(xSamples,coherence[0],'b') | |
|
1165 | # # # plt.plot(xSamples,coherence[1],'r') | |
|
1166 | # # # plt.plot(xSamples,coherence[2],'g') | |
|
1167 | # # plt.show() | |
|
1168 | # # # | |
|
1169 | # # # plt.clf() | |
|
1170 | # # # plt.cla() | |
|
1171 | # # # plt.close() | |
|
1172 | # | |
|
1173 | # print ' ' | |
|
1174 | ||
|
1175 | self.BlockCounter += 2 | |
|
1176 | ||
|
693 | self.BlockCounter+=2 | |
|
694 | ||
|
1177 | 695 | else: |
|
1178 |
self.fileSelector |
|
|
1179 |
self.BlockCounter |
|
|
1180 | print("Next File") No newline at end of file | |
|
696 | self.fileSelector+=1 | |
|
697 | self.BlockCounter=0 |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file chmod 100644 => 100755 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now