@@ -1,936 +1,940 | |||||
1 |
|
1 | |||
2 | import os |
|
2 | import os | |
3 | import time |
|
3 | import time | |
4 | import glob |
|
4 | import glob | |
5 | import datetime |
|
5 | import datetime | |
6 | from multiprocessing import Process |
|
6 | from multiprocessing import Process | |
7 |
|
7 | |||
8 | import zmq |
|
8 | import zmq | |
9 | import numpy |
|
9 | import numpy | |
10 | import matplotlib |
|
10 | import matplotlib | |
11 | import matplotlib.pyplot as plt |
|
11 | import matplotlib.pyplot as plt | |
12 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
12 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
13 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator |
|
13 | from matplotlib.ticker import FuncFormatter, LinearLocator, MultipleLocator | |
14 |
|
14 | |||
15 | from schainpy.model.proc.jroproc_base import Operation |
|
15 | from schainpy.model.proc.jroproc_base import Operation | |
16 | from schainpy.utils import log |
|
16 | from schainpy.utils import log | |
17 |
|
17 | |||
18 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] |
|
18 | jet_values = matplotlib.pyplot.get_cmap('jet', 100)(numpy.arange(100))[10:90] | |
19 | blu_values = matplotlib.pyplot.get_cmap( |
|
19 | blu_values = matplotlib.pyplot.get_cmap( | |
20 | 'seismic_r', 20)(numpy.arange(20))[10:15] |
|
20 | 'seismic_r', 20)(numpy.arange(20))[10:15] | |
21 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( |
|
21 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
22 | 'jro', numpy.vstack((blu_values, jet_values))) |
|
22 | 'jro', numpy.vstack((blu_values, jet_values))) | |
23 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
23 | matplotlib.pyplot.register_cmap(cmap=ncmap) | |
24 |
|
24 | |||
25 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')] |
|
25 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')] | |
26 |
|
26 | |||
27 | def figpause(interval): |
|
27 | def figpause(interval): | |
28 | backend = plt.rcParams['backend'] |
|
28 | backend = plt.rcParams['backend'] | |
29 | if backend in matplotlib.rcsetup.interactive_bk: |
|
29 | if backend in matplotlib.rcsetup.interactive_bk: | |
30 | figManager = matplotlib._pylab_helpers.Gcf.get_active() |
|
30 | figManager = matplotlib._pylab_helpers.Gcf.get_active() | |
31 | if figManager is not None: |
|
31 | if figManager is not None: | |
32 | canvas = figManager.canvas |
|
32 | canvas = figManager.canvas | |
33 | if canvas.figure.stale: |
|
33 | if canvas.figure.stale: | |
34 | canvas.draw() |
|
34 | canvas.draw() | |
35 | canvas.start_event_loop(interval) |
|
35 | canvas.start_event_loop(interval) | |
36 | return |
|
36 | return | |
37 |
|
37 | |||
38 | class PlotData(Operation, Process): |
|
38 | class PlotData(Operation, Process): | |
39 | ''' |
|
39 | ''' | |
40 | Base class for Schain plotting operations |
|
40 | Base class for Schain plotting operations | |
41 | ''' |
|
41 | ''' | |
42 |
|
42 | |||
43 | CODE = 'Figure' |
|
43 | CODE = 'Figure' | |
44 | colormap = 'jro' |
|
44 | colormap = 'jro' | |
45 | bgcolor = 'white' |
|
45 | bgcolor = 'white' | |
46 | CONFLATE = False |
|
46 | CONFLATE = False | |
47 | __MAXNUMX = 80 |
|
47 | __MAXNUMX = 80 | |
48 | __missing = 1E30 |
|
48 | __missing = 1E30 | |
49 |
|
49 | |||
|
50 | __attrs__ = ['show', 'save', 'xmin', 'xmax', 'ymin', 'ymax', 'zmin', 'zmax', | |||
|
51 | 'zlimits', 'xlabel', 'ylabel', 'cb_label', 'title', 'titles', 'colorbar', | |||
|
52 | 'bgcolor', 'width', 'height', 'localtime', 'oneFigure', 'showprofile'] | |||
|
53 | ||||
50 | def __init__(self, **kwargs): |
|
54 | def __init__(self, **kwargs): | |
51 |
|
55 | |||
52 | Operation.__init__(self, plot=True, **kwargs) |
|
56 | Operation.__init__(self, plot=True, **kwargs) | |
53 | Process.__init__(self) |
|
57 | Process.__init__(self) | |
54 | self.kwargs['code'] = self.CODE |
|
58 | self.kwargs['code'] = self.CODE | |
55 | self.mp = False |
|
59 | self.mp = False | |
56 | self.data = None |
|
60 | self.data = None | |
57 | self.isConfig = False |
|
61 | self.isConfig = False | |
58 | self.figures = [] |
|
62 | self.figures = [] | |
59 | self.axes = [] |
|
63 | self.axes = [] | |
60 | self.cb_axes = [] |
|
64 | self.cb_axes = [] | |
61 | self.localtime = kwargs.pop('localtime', True) |
|
65 | self.localtime = kwargs.pop('localtime', True) | |
62 | self.show = kwargs.get('show', True) |
|
66 | self.show = kwargs.get('show', True) | |
63 | self.save = kwargs.get('save', False) |
|
67 | self.save = kwargs.get('save', False) | |
64 | self.colormap = kwargs.get('colormap', self.colormap) |
|
68 | self.colormap = kwargs.get('colormap', self.colormap) | |
65 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') |
|
69 | self.colormap_coh = kwargs.get('colormap_coh', 'jet') | |
66 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') |
|
70 | self.colormap_phase = kwargs.get('colormap_phase', 'RdBu_r') | |
67 | self.colormaps = kwargs.get('colormaps', None) |
|
71 | self.colormaps = kwargs.get('colormaps', None) | |
68 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) |
|
72 | self.bgcolor = kwargs.get('bgcolor', self.bgcolor) | |
69 | self.showprofile = kwargs.get('showprofile', False) |
|
73 | self.showprofile = kwargs.get('showprofile', False) | |
70 | self.title = kwargs.get('wintitle', self.CODE.upper()) |
|
74 | self.title = kwargs.get('wintitle', self.CODE.upper()) | |
71 | self.cb_label = kwargs.get('cb_label', None) |
|
75 | self.cb_label = kwargs.get('cb_label', None) | |
72 | self.cb_labels = kwargs.get('cb_labels', None) |
|
76 | self.cb_labels = kwargs.get('cb_labels', None) | |
73 | self.xaxis = kwargs.get('xaxis', 'frequency') |
|
77 | self.xaxis = kwargs.get('xaxis', 'frequency') | |
74 | self.zmin = kwargs.get('zmin', None) |
|
78 | self.zmin = kwargs.get('zmin', None) | |
75 | self.zmax = kwargs.get('zmax', None) |
|
79 | self.zmax = kwargs.get('zmax', None) | |
76 | self.zlimits = kwargs.get('zlimits', None) |
|
80 | self.zlimits = kwargs.get('zlimits', None) | |
77 | self.xmin = kwargs.get('xmin', None) |
|
81 | self.xmin = kwargs.get('xmin', None) | |
78 | self.xmax = kwargs.get('xmax', None) |
|
82 | self.xmax = kwargs.get('xmax', None) | |
79 | self.xrange = kwargs.get('xrange', 24) |
|
83 | self.xrange = kwargs.get('xrange', 24) | |
80 | self.ymin = kwargs.get('ymin', None) |
|
84 | self.ymin = kwargs.get('ymin', None) | |
81 | self.ymax = kwargs.get('ymax', None) |
|
85 | self.ymax = kwargs.get('ymax', None) | |
82 | self.xlabel = kwargs.get('xlabel', None) |
|
86 | self.xlabel = kwargs.get('xlabel', None) | |
83 | self.__MAXNUMY = kwargs.get('decimation', 100) |
|
87 | self.__MAXNUMY = kwargs.get('decimation', 100) | |
84 | self.showSNR = kwargs.get('showSNR', False) |
|
88 | self.showSNR = kwargs.get('showSNR', False) | |
85 | self.oneFigure = kwargs.get('oneFigure', True) |
|
89 | self.oneFigure = kwargs.get('oneFigure', True) | |
86 | self.width = kwargs.get('width', None) |
|
90 | self.width = kwargs.get('width', None) | |
87 | self.height = kwargs.get('height', None) |
|
91 | self.height = kwargs.get('height', None) | |
88 | self.colorbar = kwargs.get('colorbar', True) |
|
92 | self.colorbar = kwargs.get('colorbar', True) | |
89 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) |
|
93 | self.factors = kwargs.get('factors', [1, 1, 1, 1, 1, 1, 1, 1]) | |
90 | self.titles = ['' for __ in range(16)] |
|
94 | self.titles = ['' for __ in range(16)] | |
91 | self.polar = False |
|
95 | self.polar = False | |
92 |
|
96 | |||
93 | def __fmtTime(self, x, pos): |
|
97 | def __fmtTime(self, x, pos): | |
94 | ''' |
|
98 | ''' | |
95 | ''' |
|
99 | ''' | |
96 |
|
100 | |||
97 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) |
|
101 | return '{}'.format(self.getDateTime(x).strftime('%H:%M')) | |
98 |
|
102 | |||
99 | def __setup(self): |
|
103 | def __setup(self): | |
100 | ''' |
|
104 | ''' | |
101 | Common setup for all figures, here figures and axes are created |
|
105 | Common setup for all figures, here figures and axes are created | |
102 | ''' |
|
106 | ''' | |
103 |
|
107 | |||
104 | if self.CODE not in self.data: |
|
108 | if self.CODE not in self.data: | |
105 | raise ValueError(log.error('Missing data for {}'.format(self.CODE), |
|
109 | raise ValueError(log.error('Missing data for {}'.format(self.CODE), | |
106 | self.name)) |
|
110 | self.name)) | |
107 |
|
111 | |||
108 | self.setup() |
|
112 | self.setup() | |
109 |
|
113 | |||
110 | self.time_label = 'LT' if self.localtime else 'UTC' |
|
114 | self.time_label = 'LT' if self.localtime else 'UTC' | |
111 | if self.data.localtime: |
|
115 | if self.data.localtime: | |
112 | self.getDateTime = datetime.datetime.fromtimestamp |
|
116 | self.getDateTime = datetime.datetime.fromtimestamp | |
113 | else: |
|
117 | else: | |
114 | self.getDateTime = datetime.datetime.utcfromtimestamp |
|
118 | self.getDateTime = datetime.datetime.utcfromtimestamp | |
115 |
|
119 | |||
116 | if self.width is None: |
|
120 | if self.width is None: | |
117 | self.width = 8 |
|
121 | self.width = 8 | |
118 |
|
122 | |||
119 | self.figures = [] |
|
123 | self.figures = [] | |
120 | self.axes = [] |
|
124 | self.axes = [] | |
121 | self.cb_axes = [] |
|
125 | self.cb_axes = [] | |
122 | self.pf_axes = [] |
|
126 | self.pf_axes = [] | |
123 | self.cmaps = [] |
|
127 | self.cmaps = [] | |
124 |
|
128 | |||
125 | size = '15%' if self.ncols == 1 else '30%' |
|
129 | size = '15%' if self.ncols == 1 else '30%' | |
126 | pad = '4%' if self.ncols == 1 else '8%' |
|
130 | pad = '4%' if self.ncols == 1 else '8%' | |
127 |
|
131 | |||
128 | if self.oneFigure: |
|
132 | if self.oneFigure: | |
129 | if self.height is None: |
|
133 | if self.height is None: | |
130 | self.height = 1.4 * self.nrows + 1 |
|
134 | self.height = 1.4 * self.nrows + 1 | |
131 | fig = plt.figure(figsize=(self.width, self.height), |
|
135 | fig = plt.figure(figsize=(self.width, self.height), | |
132 | edgecolor='k', |
|
136 | edgecolor='k', | |
133 | facecolor='w') |
|
137 | facecolor='w') | |
134 | self.figures.append(fig) |
|
138 | self.figures.append(fig) | |
135 | for n in range(self.nplots): |
|
139 | for n in range(self.nplots): | |
136 | ax = fig.add_subplot(self.nrows, self.ncols, n + 1, polar=self.polar) |
|
140 | ax = fig.add_subplot(self.nrows, self.ncols, n + 1, polar=self.polar) | |
137 | ax.tick_params(labelsize=8) |
|
141 | ax.tick_params(labelsize=8) | |
138 | ax.firsttime = True |
|
142 | ax.firsttime = True | |
139 | ax.index = 0 |
|
143 | ax.index = 0 | |
140 | ax.press = None |
|
144 | ax.press = None | |
141 | self.axes.append(ax) |
|
145 | self.axes.append(ax) | |
142 | if self.showprofile: |
|
146 | if self.showprofile: | |
143 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
147 | cax = self.__add_axes(ax, size=size, pad=pad) | |
144 | cax.tick_params(labelsize=8) |
|
148 | cax.tick_params(labelsize=8) | |
145 | self.pf_axes.append(cax) |
|
149 | self.pf_axes.append(cax) | |
146 | else: |
|
150 | else: | |
147 | if self.height is None: |
|
151 | if self.height is None: | |
148 | self.height = 3 |
|
152 | self.height = 3 | |
149 | for n in range(self.nplots): |
|
153 | for n in range(self.nplots): | |
150 | fig = plt.figure(figsize=(self.width, self.height), |
|
154 | fig = plt.figure(figsize=(self.width, self.height), | |
151 | edgecolor='k', |
|
155 | edgecolor='k', | |
152 | facecolor='w') |
|
156 | facecolor='w') | |
153 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) |
|
157 | ax = fig.add_subplot(1, 1, 1, polar=self.polar) | |
154 | ax.tick_params(labelsize=8) |
|
158 | ax.tick_params(labelsize=8) | |
155 | ax.firsttime = True |
|
159 | ax.firsttime = True | |
156 | ax.index = 0 |
|
160 | ax.index = 0 | |
157 | ax.press = None |
|
161 | ax.press = None | |
158 | self.figures.append(fig) |
|
162 | self.figures.append(fig) | |
159 | self.axes.append(ax) |
|
163 | self.axes.append(ax) | |
160 | if self.showprofile: |
|
164 | if self.showprofile: | |
161 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
165 | cax = self.__add_axes(ax, size=size, pad=pad) | |
162 | cax.tick_params(labelsize=8) |
|
166 | cax.tick_params(labelsize=8) | |
163 | self.pf_axes.append(cax) |
|
167 | self.pf_axes.append(cax) | |
164 |
|
168 | |||
165 | for n in range(self.nrows): |
|
169 | for n in range(self.nrows): | |
166 | if self.colormaps is not None: |
|
170 | if self.colormaps is not None: | |
167 | cmap = plt.get_cmap(self.colormaps[n]) |
|
171 | cmap = plt.get_cmap(self.colormaps[n]) | |
168 | else: |
|
172 | else: | |
169 | cmap = plt.get_cmap(self.colormap) |
|
173 | cmap = plt.get_cmap(self.colormap) | |
170 | cmap.set_bad(self.bgcolor, 1.) |
|
174 | cmap.set_bad(self.bgcolor, 1.) | |
171 | self.cmaps.append(cmap) |
|
175 | self.cmaps.append(cmap) | |
172 |
|
176 | |||
173 | for fig in self.figures: |
|
177 | for fig in self.figures: | |
174 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) |
|
178 | fig.canvas.mpl_connect('key_press_event', self.OnKeyPress) | |
175 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) |
|
179 | fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll) | |
176 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) |
|
180 | fig.canvas.mpl_connect('button_press_event', self.onBtnPress) | |
177 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) |
|
181 | fig.canvas.mpl_connect('motion_notify_event', self.onMotion) | |
178 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) |
|
182 | fig.canvas.mpl_connect('button_release_event', self.onBtnRelease) | |
179 | if self.show: |
|
183 | if self.show: | |
180 | fig.show() |
|
184 | fig.show() | |
181 |
|
185 | |||
182 | def OnKeyPress(self, event): |
|
186 | def OnKeyPress(self, event): | |
183 | ''' |
|
187 | ''' | |
184 | Event for pressing keys (up, down) change colormap |
|
188 | Event for pressing keys (up, down) change colormap | |
185 | ''' |
|
189 | ''' | |
186 | ax = event.inaxes |
|
190 | ax = event.inaxes | |
187 | if ax in self.axes: |
|
191 | if ax in self.axes: | |
188 | if event.key == 'down': |
|
192 | if event.key == 'down': | |
189 | ax.index += 1 |
|
193 | ax.index += 1 | |
190 | elif event.key == 'up': |
|
194 | elif event.key == 'up': | |
191 | ax.index -= 1 |
|
195 | ax.index -= 1 | |
192 | if ax.index < 0: |
|
196 | if ax.index < 0: | |
193 | ax.index = len(CMAPS) - 1 |
|
197 | ax.index = len(CMAPS) - 1 | |
194 | elif ax.index == len(CMAPS): |
|
198 | elif ax.index == len(CMAPS): | |
195 | ax.index = 0 |
|
199 | ax.index = 0 | |
196 | cmap = CMAPS[ax.index] |
|
200 | cmap = CMAPS[ax.index] | |
197 | ax.cbar.set_cmap(cmap) |
|
201 | ax.cbar.set_cmap(cmap) | |
198 | ax.cbar.draw_all() |
|
202 | ax.cbar.draw_all() | |
199 | ax.plt.set_cmap(cmap) |
|
203 | ax.plt.set_cmap(cmap) | |
200 | ax.cbar.patch.figure.canvas.draw() |
|
204 | ax.cbar.patch.figure.canvas.draw() | |
201 | self.colormap = cmap.name |
|
205 | self.colormap = cmap.name | |
202 |
|
206 | |||
203 | def OnBtnScroll(self, event): |
|
207 | def OnBtnScroll(self, event): | |
204 | ''' |
|
208 | ''' | |
205 | Event for scrolling, scale figure |
|
209 | Event for scrolling, scale figure | |
206 | ''' |
|
210 | ''' | |
207 | cb_ax = event.inaxes |
|
211 | cb_ax = event.inaxes | |
208 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: |
|
212 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
209 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] |
|
213 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
210 | pt = ax.cbar.ax.bbox.get_points()[:,1] |
|
214 | pt = ax.cbar.ax.bbox.get_points()[:,1] | |
211 | nrm = ax.cbar.norm |
|
215 | nrm = ax.cbar.norm | |
212 | vmin, vmax, p0, p1, pS = (nrm.vmin, nrm.vmax, pt[0], pt[1], event.y) |
|
216 | vmin, vmax, p0, p1, pS = (nrm.vmin, nrm.vmax, pt[0], pt[1], event.y) | |
213 | scale = 2 if event.step == 1 else 0.5 |
|
217 | scale = 2 if event.step == 1 else 0.5 | |
214 | point = vmin + (vmax - vmin) / (p1 - p0)*(pS - p0) |
|
218 | point = vmin + (vmax - vmin) / (p1 - p0)*(pS - p0) | |
215 | ax.cbar.norm.vmin = point - scale*(point - vmin) |
|
219 | ax.cbar.norm.vmin = point - scale*(point - vmin) | |
216 | ax.cbar.norm.vmax = point - scale*(point - vmax) |
|
220 | ax.cbar.norm.vmax = point - scale*(point - vmax) | |
217 | ax.plt.set_norm(ax.cbar.norm) |
|
221 | ax.plt.set_norm(ax.cbar.norm) | |
218 | ax.cbar.draw_all() |
|
222 | ax.cbar.draw_all() | |
219 | ax.cbar.patch.figure.canvas.draw() |
|
223 | ax.cbar.patch.figure.canvas.draw() | |
220 |
|
224 | |||
221 | def onBtnPress(self, event): |
|
225 | def onBtnPress(self, event): | |
222 | ''' |
|
226 | ''' | |
223 | Event for mouse button press |
|
227 | Event for mouse button press | |
224 | ''' |
|
228 | ''' | |
225 | cb_ax = event.inaxes |
|
229 | cb_ax = event.inaxes | |
226 | if cb_ax is None: |
|
230 | if cb_ax is None: | |
227 | return |
|
231 | return | |
228 |
|
232 | |||
229 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: |
|
233 | if cb_ax in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
230 | cb_ax.press = event.x, event.y |
|
234 | cb_ax.press = event.x, event.y | |
231 | else: |
|
235 | else: | |
232 | cb_ax.press = None |
|
236 | cb_ax.press = None | |
233 |
|
237 | |||
234 | def onMotion(self, event): |
|
238 | def onMotion(self, event): | |
235 | ''' |
|
239 | ''' | |
236 | Event for move inside colorbar |
|
240 | Event for move inside colorbar | |
237 | ''' |
|
241 | ''' | |
238 | cb_ax = event.inaxes |
|
242 | cb_ax = event.inaxes | |
239 | if cb_ax is None: |
|
243 | if cb_ax is None: | |
240 | return |
|
244 | return | |
241 | if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]: |
|
245 | if cb_ax not in [ax.cbar.ax for ax in self.axes if ax.cbar]: | |
242 | return |
|
246 | return | |
243 | if cb_ax.press is None: |
|
247 | if cb_ax.press is None: | |
244 | return |
|
248 | return | |
245 |
|
249 | |||
246 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] |
|
250 | ax = [ax for ax in self.axes if cb_ax == ax.cbar.ax][0] | |
247 | xprev, yprev = cb_ax.press |
|
251 | xprev, yprev = cb_ax.press | |
248 | dx = event.x - xprev |
|
252 | dx = event.x - xprev | |
249 | dy = event.y - yprev |
|
253 | dy = event.y - yprev | |
250 | cb_ax.press = event.x, event.y |
|
254 | cb_ax.press = event.x, event.y | |
251 | scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin |
|
255 | scale = ax.cbar.norm.vmax - ax.cbar.norm.vmin | |
252 | perc = 0.03 |
|
256 | perc = 0.03 | |
253 |
|
257 | |||
254 | if event.button == 1: |
|
258 | if event.button == 1: | |
255 | ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy) |
|
259 | ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy) | |
256 | ax.cbar.norm.vmax -= (perc*scale)*numpy.sign(dy) |
|
260 | ax.cbar.norm.vmax -= (perc*scale)*numpy.sign(dy) | |
257 | elif event.button == 3: |
|
261 | elif event.button == 3: | |
258 | ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy) |
|
262 | ax.cbar.norm.vmin -= (perc*scale)*numpy.sign(dy) | |
259 | ax.cbar.norm.vmax += (perc*scale)*numpy.sign(dy) |
|
263 | ax.cbar.norm.vmax += (perc*scale)*numpy.sign(dy) | |
260 |
|
264 | |||
261 | ax.cbar.draw_all() |
|
265 | ax.cbar.draw_all() | |
262 | ax.plt.set_norm(ax.cbar.norm) |
|
266 | ax.plt.set_norm(ax.cbar.norm) | |
263 | ax.cbar.patch.figure.canvas.draw() |
|
267 | ax.cbar.patch.figure.canvas.draw() | |
264 |
|
268 | |||
265 | def onBtnRelease(self, event): |
|
269 | def onBtnRelease(self, event): | |
266 | ''' |
|
270 | ''' | |
267 | Event for mouse button release |
|
271 | Event for mouse button release | |
268 | ''' |
|
272 | ''' | |
269 | cb_ax = event.inaxes |
|
273 | cb_ax = event.inaxes | |
270 | if cb_ax is not None: |
|
274 | if cb_ax is not None: | |
271 | cb_ax.press = None |
|
275 | cb_ax.press = None | |
272 |
|
276 | |||
273 | def __add_axes(self, ax, size='30%', pad='8%'): |
|
277 | def __add_axes(self, ax, size='30%', pad='8%'): | |
274 | ''' |
|
278 | ''' | |
275 | Add new axes to the given figure |
|
279 | Add new axes to the given figure | |
276 | ''' |
|
280 | ''' | |
277 | divider = make_axes_locatable(ax) |
|
281 | divider = make_axes_locatable(ax) | |
278 | nax = divider.new_horizontal(size=size, pad=pad) |
|
282 | nax = divider.new_horizontal(size=size, pad=pad) | |
279 | ax.figure.add_axes(nax) |
|
283 | ax.figure.add_axes(nax) | |
280 | return nax |
|
284 | return nax | |
281 |
|
285 | |||
282 | self.setup() |
|
286 | self.setup() | |
283 |
|
287 | |||
284 | def setup(self): |
|
288 | def setup(self): | |
285 | ''' |
|
289 | ''' | |
286 | This method should be implemented in the child class, the following |
|
290 | This method should be implemented in the child class, the following | |
287 | attributes should be set: |
|
291 | attributes should be set: | |
288 |
|
292 | |||
289 | self.nrows: number of rows |
|
293 | self.nrows: number of rows | |
290 | self.ncols: number of cols |
|
294 | self.ncols: number of cols | |
291 | self.nplots: number of plots (channels or pairs) |
|
295 | self.nplots: number of plots (channels or pairs) | |
292 | self.ylabel: label for Y axes |
|
296 | self.ylabel: label for Y axes | |
293 | self.titles: list of axes title |
|
297 | self.titles: list of axes title | |
294 |
|
298 | |||
295 | ''' |
|
299 | ''' | |
296 | raise(NotImplementedError, 'Implement this method in child class') |
|
300 | raise(NotImplementedError, 'Implement this method in child class') | |
297 |
|
301 | |||
298 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): |
|
302 | def fill_gaps(self, x_buffer, y_buffer, z_buffer): | |
299 | ''' |
|
303 | ''' | |
300 | Create a masked array for missing data |
|
304 | Create a masked array for missing data | |
301 | ''' |
|
305 | ''' | |
302 | if x_buffer.shape[0] < 2: |
|
306 | if x_buffer.shape[0] < 2: | |
303 | return x_buffer, y_buffer, z_buffer |
|
307 | return x_buffer, y_buffer, z_buffer | |
304 |
|
308 | |||
305 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
309 | deltas = x_buffer[1:] - x_buffer[0:-1] | |
306 | x_median = numpy.median(deltas) |
|
310 | x_median = numpy.median(deltas) | |
307 |
|
311 | |||
308 | index = numpy.where(deltas > 5 * x_median) |
|
312 | index = numpy.where(deltas > 5 * x_median) | |
309 |
|
313 | |||
310 | if len(index[0]) != 0: |
|
314 | if len(index[0]) != 0: | |
311 | z_buffer[::, index[0], ::] = self.__missing |
|
315 | z_buffer[::, index[0], ::] = self.__missing | |
312 | z_buffer = numpy.ma.masked_inside(z_buffer, |
|
316 | z_buffer = numpy.ma.masked_inside(z_buffer, | |
313 | 0.99 * self.__missing, |
|
317 | 0.99 * self.__missing, | |
314 | 1.01 * self.__missing) |
|
318 | 1.01 * self.__missing) | |
315 |
|
319 | |||
316 | return x_buffer, y_buffer, z_buffer |
|
320 | return x_buffer, y_buffer, z_buffer | |
317 |
|
321 | |||
318 | def decimate(self): |
|
322 | def decimate(self): | |
319 |
|
323 | |||
320 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
324 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 | |
321 | dy = int(len(self.y) / self.__MAXNUMY) + 1 |
|
325 | dy = int(len(self.y) / self.__MAXNUMY) + 1 | |
322 |
|
326 | |||
323 | # x = self.x[::dx] |
|
327 | # x = self.x[::dx] | |
324 | x = self.x |
|
328 | x = self.x | |
325 | y = self.y[::dy] |
|
329 | y = self.y[::dy] | |
326 | z = self.z[::, ::, ::dy] |
|
330 | z = self.z[::, ::, ::dy] | |
327 |
|
331 | |||
328 | return x, y, z |
|
332 | return x, y, z | |
329 |
|
333 | |||
330 | def format(self): |
|
334 | def format(self): | |
331 | ''' |
|
335 | ''' | |
332 | Set min and max values, labels, ticks and titles |
|
336 | Set min and max values, labels, ticks and titles | |
333 | ''' |
|
337 | ''' | |
334 |
|
338 | |||
335 | if self.xmin is None: |
|
339 | if self.xmin is None: | |
336 | xmin = self.min_time |
|
340 | xmin = self.min_time | |
337 | else: |
|
341 | else: | |
338 | if self.xaxis is 'time': |
|
342 | if self.xaxis is 'time': | |
339 | dt = self.getDateTime(self.min_time) |
|
343 | dt = self.getDateTime(self.min_time) | |
340 | xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
344 | xmin = (dt.replace(hour=int(self.xmin), minute=0, second=0) - datetime.datetime(1970, 1, 1)).total_seconds() | |
341 | if self.data.localtime: |
|
345 | if self.data.localtime: | |
342 | xmin += time.timezone |
|
346 | xmin += time.timezone | |
343 | else: |
|
347 | else: | |
344 | xmin = self.xmin |
|
348 | xmin = self.xmin | |
345 |
|
349 | |||
346 | if self.xmax is None: |
|
350 | if self.xmax is None: | |
347 | xmax = xmin + self.xrange * 60 * 60 |
|
351 | xmax = xmin + self.xrange * 60 * 60 | |
348 | else: |
|
352 | else: | |
349 | if self.xaxis is 'time': |
|
353 | if self.xaxis is 'time': | |
350 | dt = self.getDateTime(self.max_time) |
|
354 | dt = self.getDateTime(self.max_time) | |
351 | xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) - datetime.datetime(1970, 1, 1)).total_seconds() |
|
355 | xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) - datetime.datetime(1970, 1, 1)).total_seconds() | |
352 | if self.data.localtime: |
|
356 | if self.data.localtime: | |
353 | xmax += time.timezone |
|
357 | xmax += time.timezone | |
354 | else: |
|
358 | else: | |
355 | xmax = self.xmax |
|
359 | xmax = self.xmax | |
356 |
|
360 | |||
357 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) |
|
361 | ymin = self.ymin if self.ymin else numpy.nanmin(self.y) | |
358 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) |
|
362 | ymax = self.ymax if self.ymax else numpy.nanmax(self.y) | |
359 |
|
363 | |||
360 | Y = numpy.array([10, 20, 50, 100, 200, 500, 1000, 2000]) |
|
364 | Y = numpy.array([10, 20, 50, 100, 200, 500, 1000, 2000]) | |
361 | i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0] |
|
365 | i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0] | |
362 | ystep = Y[i-1]/5 |
|
366 | ystep = Y[i-1]/5 | |
363 |
|
367 | |||
364 | for n, ax in enumerate(self.axes): |
|
368 | for n, ax in enumerate(self.axes): | |
365 | if ax.firsttime: |
|
369 | if ax.firsttime: | |
366 | ax.set_facecolor(self.bgcolor) |
|
370 | ax.set_facecolor(self.bgcolor) | |
367 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) |
|
371 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) | |
368 | if self.xaxis is 'time': |
|
372 | if self.xaxis is 'time': | |
369 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) |
|
373 | ax.xaxis.set_major_formatter(FuncFormatter(self.__fmtTime)) | |
370 | ax.xaxis.set_major_locator(LinearLocator(9)) |
|
374 | ax.xaxis.set_major_locator(LinearLocator(9)) | |
371 | if self.xlabel is not None: |
|
375 | if self.xlabel is not None: | |
372 | ax.set_xlabel(self.xlabel) |
|
376 | ax.set_xlabel(self.xlabel) | |
373 | ax.set_ylabel(self.ylabel) |
|
377 | ax.set_ylabel(self.ylabel) | |
374 | ax.firsttime = False |
|
378 | ax.firsttime = False | |
375 | if self.showprofile: |
|
379 | if self.showprofile: | |
376 | self.pf_axes[n].set_ylim(ymin, ymax) |
|
380 | self.pf_axes[n].set_ylim(ymin, ymax) | |
377 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) |
|
381 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
378 | self.pf_axes[n].set_xlabel('dB') |
|
382 | self.pf_axes[n].set_xlabel('dB') | |
379 | self.pf_axes[n].grid(b=True, axis='x') |
|
383 | self.pf_axes[n].grid(b=True, axis='x') | |
380 | [tick.set_visible(False) |
|
384 | [tick.set_visible(False) | |
381 | for tick in self.pf_axes[n].get_yticklabels()] |
|
385 | for tick in self.pf_axes[n].get_yticklabels()] | |
382 | if self.colorbar: |
|
386 | if self.colorbar: | |
383 |
ax.cbar = plt.colorbar(ax.plt, ax=ax, fraction=0. |
|
387 | ax.cbar = plt.colorbar(ax.plt, ax=ax, fraction=0.05, pad=0.02, aspect=10) | |
384 | ax.cbar.ax.tick_params(labelsize=8) |
|
388 | ax.cbar.ax.tick_params(labelsize=8) | |
385 | ax.cbar.ax.press = None |
|
389 | ax.cbar.ax.press = None | |
386 | if self.cb_label: |
|
390 | if self.cb_label: | |
387 | ax.cbar.set_label(self.cb_label, size=8) |
|
391 | ax.cbar.set_label(self.cb_label, size=8) | |
388 | elif self.cb_labels: |
|
392 | elif self.cb_labels: | |
389 | ax.cbar.set_label(self.cb_labels[n], size=8) |
|
393 | ax.cbar.set_label(self.cb_labels[n], size=8) | |
390 | else: |
|
394 | else: | |
391 | ax.cbar = None |
|
395 | ax.cbar = None | |
392 |
|
396 | |||
393 | if not self.polar: |
|
397 | if not self.polar: | |
394 | ax.set_xlim(xmin, xmax) |
|
398 | ax.set_xlim(xmin, xmax) | |
395 | ax.set_ylim(ymin, ymax) |
|
399 | ax.set_ylim(ymin, ymax) | |
396 | ax.set_title('{} - {} {}'.format( |
|
400 | ax.set_title('{} - {} {}'.format( | |
397 | self.titles[n], |
|
401 | self.titles[n], | |
398 | self.getDateTime(self.max_time).strftime('%H:%M:%S'), |
|
402 | self.getDateTime(self.max_time).strftime('%H:%M:%S'), | |
399 | self.time_label), |
|
403 | self.time_label), | |
400 | size=8) |
|
404 | size=8) | |
401 | else: |
|
405 | else: | |
402 | ax.set_title('{}'.format(self.titles[n]), size=8) |
|
406 | ax.set_title('{}'.format(self.titles[n]), size=8) | |
403 | ax.set_ylim(0, 90) |
|
407 | ax.set_ylim(0, 90) | |
404 | ax.set_yticks(numpy.arange(0, 90, 20)) |
|
408 | ax.set_yticks(numpy.arange(0, 90, 20)) | |
405 | ax.yaxis.labelpad = 40 |
|
409 | ax.yaxis.labelpad = 40 | |
406 |
|
410 | |||
407 |
|
411 | |||
408 | def __plot(self): |
|
412 | def __plot(self): | |
409 | ''' |
|
413 | ''' | |
410 | ''' |
|
414 | ''' | |
411 | log.success('Plotting', self.name) |
|
415 | log.success('Plotting', self.name) | |
412 |
|
416 | |||
413 | self.plot() |
|
417 | self.plot() | |
414 | self.format() |
|
418 | self.format() | |
415 |
|
419 | |||
416 | for n, fig in enumerate(self.figures): |
|
420 | for n, fig in enumerate(self.figures): | |
417 | if self.nrows == 0 or self.nplots == 0: |
|
421 | if self.nrows == 0 or self.nplots == 0: | |
418 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') |
|
422 | fig.text(0.5, 0.5, 'No Data', fontsize='large', ha='center') | |
419 | continue |
|
423 | continue | |
420 |
|
424 | |||
421 | fig.tight_layout() |
|
425 | fig.tight_layout() | |
422 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, |
|
426 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, | |
423 | self.getDateTime(self.max_time).strftime('%Y/%m/%d'))) |
|
427 | self.getDateTime(self.max_time).strftime('%Y/%m/%d'))) | |
424 | # fig.canvas.draw() |
|
428 | # fig.canvas.draw() | |
425 |
|
429 | |||
426 | if self.save and self.data.ended: |
|
430 | if self.save and self.data.ended: | |
427 | channels = range(self.nrows) |
|
431 | channels = range(self.nrows) | |
428 | if self.oneFigure: |
|
432 | if self.oneFigure: | |
429 | label = '' |
|
433 | label = '' | |
430 | else: |
|
434 | else: | |
431 | label = '_{}'.format(channels[n]) |
|
435 | label = '_{}'.format(channels[n]) | |
432 | figname = os.path.join( |
|
436 | figname = os.path.join( | |
433 | self.save, |
|
437 | self.save, | |
434 | '{}{}_{}.png'.format( |
|
438 | '{}{}_{}.png'.format( | |
435 | self.CODE, |
|
439 | self.CODE, | |
436 | label, |
|
440 | label, | |
437 | self.getDateTime(self.saveTime).strftime('%y%m%d_%H%M%S') |
|
441 | self.getDateTime(self.saveTime).strftime('%y%m%d_%H%M%S') | |
438 | ) |
|
442 | ) | |
439 | ) |
|
443 | ) | |
440 | log.log('Saving figure: {}'.format(figname), self.name) |
|
444 | log.log('Saving figure: {}'.format(figname), self.name) | |
441 | fig.savefig(figname) |
|
445 | fig.savefig(figname) | |
442 |
|
446 | |||
443 | def plot(self): |
|
447 | def plot(self): | |
444 | ''' |
|
448 | ''' | |
445 | ''' |
|
449 | ''' | |
446 | raise(NotImplementedError, 'Implement this method in child class') |
|
450 | raise(NotImplementedError, 'Implement this method in child class') | |
447 |
|
451 | |||
448 | def run(self): |
|
452 | def run(self): | |
449 |
|
453 | |||
450 | log.success('Starting', self.name) |
|
454 | log.success('Starting', self.name) | |
451 |
|
455 | |||
452 | context = zmq.Context() |
|
456 | context = zmq.Context() | |
453 | receiver = context.socket(zmq.SUB) |
|
457 | receiver = context.socket(zmq.SUB) | |
454 | receiver.setsockopt(zmq.SUBSCRIBE, '') |
|
458 | receiver.setsockopt(zmq.SUBSCRIBE, '') | |
455 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
459 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) | |
456 |
|
460 | |||
457 | if 'server' in self.kwargs['parent']: |
|
461 | if 'server' in self.kwargs['parent']: | |
458 | receiver.connect( |
|
462 | receiver.connect( | |
459 | 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) |
|
463 | 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |
460 | else: |
|
464 | else: | |
461 | receiver.connect("ipc:///tmp/zmq.plots") |
|
465 | receiver.connect("ipc:///tmp/zmq.plots") | |
462 |
|
466 | |||
463 | while True: |
|
467 | while True: | |
464 | try: |
|
468 | try: | |
465 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) |
|
469 | self.data = receiver.recv_pyobj(flags=zmq.NOBLOCK) | |
466 | if self.data.localtime and self.localtime: |
|
470 | if self.data.localtime and self.localtime: | |
467 | self.times = self.data.times |
|
471 | self.times = self.data.times | |
468 | elif self.data.localtime and not self.localtime: |
|
472 | elif self.data.localtime and not self.localtime: | |
469 | self.times = self.data.times + time.timezone |
|
473 | self.times = self.data.times + time.timezone | |
470 | elif not self.data.localtime and self.localtime: |
|
474 | elif not self.data.localtime and self.localtime: | |
471 | self.times = self.data.times - time.timezone |
|
475 | self.times = self.data.times - time.timezone | |
472 | else: |
|
476 | else: | |
473 | self.times = self.data.times |
|
477 | self.times = self.data.times | |
474 |
|
478 | |||
475 | self.min_time = self.times[0] |
|
479 | self.min_time = self.times[0] | |
476 | self.max_time = self.times[-1] |
|
480 | self.max_time = self.times[-1] | |
477 |
|
481 | |||
478 | if self.isConfig is False: |
|
482 | if self.isConfig is False: | |
479 | self.__setup() |
|
483 | self.__setup() | |
480 | self.isConfig = True |
|
484 | self.isConfig = True | |
481 |
|
485 | |||
482 | self.__plot() |
|
486 | self.__plot() | |
483 |
|
487 | |||
484 | except zmq.Again as e: |
|
488 | except zmq.Again as e: | |
485 | log.log('Waiting for data...') |
|
489 | log.log('Waiting for data...') | |
486 | if self.data: |
|
490 | if self.data: | |
487 | figpause(self.data.throttle) |
|
491 | figpause(self.data.throttle) | |
488 | else: |
|
492 | else: | |
489 | time.sleep(2) |
|
493 | time.sleep(2) | |
490 |
|
494 | |||
491 | def close(self): |
|
495 | def close(self): | |
492 | if self.data: |
|
496 | if self.data: | |
493 | self.__plot() |
|
497 | self.__plot() | |
494 |
|
498 | |||
495 |
|
499 | |||
496 | class PlotSpectraData(PlotData): |
|
500 | class PlotSpectraData(PlotData): | |
497 | ''' |
|
501 | ''' | |
498 | Plot for Spectra data |
|
502 | Plot for Spectra data | |
499 | ''' |
|
503 | ''' | |
500 |
|
504 | |||
501 | CODE = 'spc' |
|
505 | CODE = 'spc' | |
502 | colormap = 'jro' |
|
506 | colormap = 'jro' | |
503 |
|
507 | |||
504 | def setup(self): |
|
508 | def setup(self): | |
505 | self.nplots = len(self.data.channels) |
|
509 | self.nplots = len(self.data.channels) | |
506 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) |
|
510 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) | |
507 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) |
|
511 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) | |
508 | self.width = 3.4 * self.ncols |
|
512 | self.width = 3.4 * self.ncols | |
509 | self.height = 3 * self.nrows |
|
513 | self.height = 3 * self.nrows | |
510 | self.cb_label = 'dB' |
|
514 | self.cb_label = 'dB' | |
511 | if self.showprofile: |
|
515 | if self.showprofile: | |
512 | self.width += 0.8 * self.ncols |
|
516 | self.width += 0.8 * self.ncols | |
513 |
|
517 | |||
514 | self.ylabel = 'Range [Km]' |
|
518 | self.ylabel = 'Range [Km]' | |
515 |
|
519 | |||
516 | def plot(self): |
|
520 | def plot(self): | |
517 | if self.xaxis == "frequency": |
|
521 | if self.xaxis == "frequency": | |
518 | x = self.data.xrange[0] |
|
522 | x = self.data.xrange[0] | |
519 | self.xlabel = "Frequency (kHz)" |
|
523 | self.xlabel = "Frequency (kHz)" | |
520 | elif self.xaxis == "time": |
|
524 | elif self.xaxis == "time": | |
521 | x = self.data.xrange[1] |
|
525 | x = self.data.xrange[1] | |
522 | self.xlabel = "Time (ms)" |
|
526 | self.xlabel = "Time (ms)" | |
523 | else: |
|
527 | else: | |
524 | x = self.data.xrange[2] |
|
528 | x = self.data.xrange[2] | |
525 | self.xlabel = "Velocity (m/s)" |
|
529 | self.xlabel = "Velocity (m/s)" | |
526 |
|
530 | |||
527 | if self.CODE == 'spc_mean': |
|
531 | if self.CODE == 'spc_mean': | |
528 | x = self.data.xrange[2] |
|
532 | x = self.data.xrange[2] | |
529 | self.xlabel = "Velocity (m/s)" |
|
533 | self.xlabel = "Velocity (m/s)" | |
530 |
|
534 | |||
531 | self.titles = [] |
|
535 | self.titles = [] | |
532 |
|
536 | |||
533 | y = self.data.heights |
|
537 | y = self.data.heights | |
534 | self.y = y |
|
538 | self.y = y | |
535 | z = self.data['spc'] |
|
539 | z = self.data['spc'] | |
536 |
|
540 | |||
537 | for n, ax in enumerate(self.axes): |
|
541 | for n, ax in enumerate(self.axes): | |
538 | noise = self.data['noise'][n][-1] |
|
542 | noise = self.data['noise'][n][-1] | |
539 | if self.CODE == 'spc_mean': |
|
543 | if self.CODE == 'spc_mean': | |
540 | mean = self.data['mean'][n][-1] |
|
544 | mean = self.data['mean'][n][-1] | |
541 | if ax.firsttime: |
|
545 | if ax.firsttime: | |
542 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
546 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
543 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
547 | self.xmin = self.xmin if self.xmin else -self.xmax | |
544 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) |
|
548 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) | |
545 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) |
|
549 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) | |
546 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
550 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
547 | vmin=self.zmin, |
|
551 | vmin=self.zmin, | |
548 | vmax=self.zmax, |
|
552 | vmax=self.zmax, | |
549 | cmap=plt.get_cmap(self.colormap) |
|
553 | cmap=plt.get_cmap(self.colormap) | |
550 | ) |
|
554 | ) | |
551 |
|
555 | |||
552 | if self.showprofile: |
|
556 | if self.showprofile: | |
553 | ax.plt_profile = self.pf_axes[n].plot( |
|
557 | ax.plt_profile = self.pf_axes[n].plot( | |
554 | self.data['rti'][n][-1], y)[0] |
|
558 | self.data['rti'][n][-1], y)[0] | |
555 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, |
|
559 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, | |
556 | color="k", linestyle="dashed", lw=1)[0] |
|
560 | color="k", linestyle="dashed", lw=1)[0] | |
557 | if self.CODE == 'spc_mean': |
|
561 | if self.CODE == 'spc_mean': | |
558 | ax.plt_mean = ax.plot(mean, y, color='k')[0] |
|
562 | ax.plt_mean = ax.plot(mean, y, color='k')[0] | |
559 | else: |
|
563 | else: | |
560 | ax.plt.set_array(z[n].T.ravel()) |
|
564 | ax.plt.set_array(z[n].T.ravel()) | |
561 | if self.showprofile: |
|
565 | if self.showprofile: | |
562 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) |
|
566 | ax.plt_profile.set_data(self.data['rti'][n][-1], y) | |
563 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) |
|
567 | ax.plt_noise.set_data(numpy.repeat(noise, len(y)), y) | |
564 | if self.CODE == 'spc_mean': |
|
568 | if self.CODE == 'spc_mean': | |
565 | ax.plt_mean.set_data(mean, y) |
|
569 | ax.plt_mean.set_data(mean, y) | |
566 |
|
570 | |||
567 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
571 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
568 | self.saveTime = self.max_time |
|
572 | self.saveTime = self.max_time | |
569 |
|
573 | |||
570 |
|
574 | |||
571 | class PlotCrossSpectraData(PlotData): |
|
575 | class PlotCrossSpectraData(PlotData): | |
572 |
|
576 | |||
573 | CODE = 'cspc' |
|
577 | CODE = 'cspc' | |
574 | zmin_coh = None |
|
578 | zmin_coh = None | |
575 | zmax_coh = None |
|
579 | zmax_coh = None | |
576 | zmin_phase = None |
|
580 | zmin_phase = None | |
577 | zmax_phase = None |
|
581 | zmax_phase = None | |
578 |
|
582 | |||
579 | def setup(self): |
|
583 | def setup(self): | |
580 |
|
584 | |||
581 | self.ncols = 4 |
|
585 | self.ncols = 4 | |
582 | self.nrows = len(self.data.pairs) |
|
586 | self.nrows = len(self.data.pairs) | |
583 | self.nplots = self.nrows * 4 |
|
587 | self.nplots = self.nrows * 4 | |
584 | self.width = 3.4 * self.ncols |
|
588 | self.width = 3.4 * self.ncols | |
585 | self.height = 3 * self.nrows |
|
589 | self.height = 3 * self.nrows | |
586 | self.ylabel = 'Range [Km]' |
|
590 | self.ylabel = 'Range [Km]' | |
587 | self.showprofile = False |
|
591 | self.showprofile = False | |
588 |
|
592 | |||
589 | def plot(self): |
|
593 | def plot(self): | |
590 |
|
594 | |||
591 | if self.xaxis == "frequency": |
|
595 | if self.xaxis == "frequency": | |
592 | x = self.data.xrange[0] |
|
596 | x = self.data.xrange[0] | |
593 | self.xlabel = "Frequency (kHz)" |
|
597 | self.xlabel = "Frequency (kHz)" | |
594 | elif self.xaxis == "time": |
|
598 | elif self.xaxis == "time": | |
595 | x = self.data.xrange[1] |
|
599 | x = self.data.xrange[1] | |
596 | self.xlabel = "Time (ms)" |
|
600 | self.xlabel = "Time (ms)" | |
597 | else: |
|
601 | else: | |
598 | x = self.data.xrange[2] |
|
602 | x = self.data.xrange[2] | |
599 | self.xlabel = "Velocity (m/s)" |
|
603 | self.xlabel = "Velocity (m/s)" | |
600 |
|
604 | |||
601 | self.titles = [] |
|
605 | self.titles = [] | |
602 |
|
606 | |||
603 | y = self.data.heights |
|
607 | y = self.data.heights | |
604 | self.y = y |
|
608 | self.y = y | |
605 | spc = self.data['spc'] |
|
609 | spc = self.data['spc'] | |
606 | cspc = self.data['cspc'] |
|
610 | cspc = self.data['cspc'] | |
607 |
|
611 | |||
608 | for n in range(self.nrows): |
|
612 | for n in range(self.nrows): | |
609 | noise = self.data['noise'][n][-1] |
|
613 | noise = self.data['noise'][n][-1] | |
610 | pair = self.data.pairs[n] |
|
614 | pair = self.data.pairs[n] | |
611 | ax = self.axes[4 * n] |
|
615 | ax = self.axes[4 * n] | |
612 | ax3 = self.axes[4 * n + 3] |
|
616 | ax3 = self.axes[4 * n + 3] | |
613 | if ax.firsttime: |
|
617 | if ax.firsttime: | |
614 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
618 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) | |
615 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
619 | self.xmin = self.xmin if self.xmin else -self.xmax | |
616 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) |
|
620 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) | |
617 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) |
|
621 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) | |
618 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, |
|
622 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, | |
619 | vmin=self.zmin, |
|
623 | vmin=self.zmin, | |
620 | vmax=self.zmax, |
|
624 | vmax=self.zmax, | |
621 | cmap=plt.get_cmap(self.colormap) |
|
625 | cmap=plt.get_cmap(self.colormap) | |
622 | ) |
|
626 | ) | |
623 | else: |
|
627 | else: | |
624 | ax.plt.set_array(spc[pair[0]].T.ravel()) |
|
628 | ax.plt.set_array(spc[pair[0]].T.ravel()) | |
625 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
629 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
626 |
|
630 | |||
627 | ax = self.axes[4 * n + 1] |
|
631 | ax = self.axes[4 * n + 1] | |
628 | if ax.firsttime: |
|
632 | if ax.firsttime: | |
629 | ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, |
|
633 | ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, | |
630 | vmin=self.zmin, |
|
634 | vmin=self.zmin, | |
631 | vmax=self.zmax, |
|
635 | vmax=self.zmax, | |
632 | cmap=plt.get_cmap(self.colormap) |
|
636 | cmap=plt.get_cmap(self.colormap) | |
633 | ) |
|
637 | ) | |
634 | else: |
|
638 | else: | |
635 | ax.plt.set_array(spc[pair[1]].T.ravel()) |
|
639 | ax.plt.set_array(spc[pair[1]].T.ravel()) | |
636 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
640 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) | |
637 |
|
641 | |||
638 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) |
|
642 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) | |
639 | coh = numpy.abs(out) |
|
643 | coh = numpy.abs(out) | |
640 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi |
|
644 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi | |
641 |
|
645 | |||
642 | ax = self.axes[4 * n + 2] |
|
646 | ax = self.axes[4 * n + 2] | |
643 | if ax.firsttime: |
|
647 | if ax.firsttime: | |
644 | ax.plt = ax.pcolormesh(x, y, coh.T, |
|
648 | ax.plt = ax.pcolormesh(x, y, coh.T, | |
645 | vmin=0, |
|
649 | vmin=0, | |
646 | vmax=1, |
|
650 | vmax=1, | |
647 | cmap=plt.get_cmap(self.colormap_coh) |
|
651 | cmap=plt.get_cmap(self.colormap_coh) | |
648 | ) |
|
652 | ) | |
649 | else: |
|
653 | else: | |
650 | ax.plt.set_array(coh.T.ravel()) |
|
654 | ax.plt.set_array(coh.T.ravel()) | |
651 | self.titles.append( |
|
655 | self.titles.append( | |
652 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) |
|
656 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |
653 |
|
657 | |||
654 | ax = self.axes[4 * n + 3] |
|
658 | ax = self.axes[4 * n + 3] | |
655 | if ax.firsttime: |
|
659 | if ax.firsttime: | |
656 | ax.plt = ax.pcolormesh(x, y, phase.T, |
|
660 | ax.plt = ax.pcolormesh(x, y, phase.T, | |
657 | vmin=-180, |
|
661 | vmin=-180, | |
658 | vmax=180, |
|
662 | vmax=180, | |
659 | cmap=plt.get_cmap(self.colormap_phase) |
|
663 | cmap=plt.get_cmap(self.colormap_phase) | |
660 | ) |
|
664 | ) | |
661 | else: |
|
665 | else: | |
662 | ax.plt.set_array(phase.T.ravel()) |
|
666 | ax.plt.set_array(phase.T.ravel()) | |
663 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) |
|
667 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) | |
664 |
|
668 | |||
665 | self.saveTime = self.max_time |
|
669 | self.saveTime = self.max_time | |
666 |
|
670 | |||
667 |
|
671 | |||
668 | class PlotSpectraMeanData(PlotSpectraData): |
|
672 | class PlotSpectraMeanData(PlotSpectraData): | |
669 | ''' |
|
673 | ''' | |
670 | Plot for Spectra and Mean |
|
674 | Plot for Spectra and Mean | |
671 | ''' |
|
675 | ''' | |
672 | CODE = 'spc_mean' |
|
676 | CODE = 'spc_mean' | |
673 | colormap = 'jro' |
|
677 | colormap = 'jro' | |
674 |
|
678 | |||
675 |
|
679 | |||
676 | class PlotRTIData(PlotData): |
|
680 | class PlotRTIData(PlotData): | |
677 | ''' |
|
681 | ''' | |
678 | Plot for RTI data |
|
682 | Plot for RTI data | |
679 | ''' |
|
683 | ''' | |
680 |
|
684 | |||
681 | CODE = 'rti' |
|
685 | CODE = 'rti' | |
682 | colormap = 'jro' |
|
686 | colormap = 'jro' | |
683 |
|
687 | |||
684 | def setup(self): |
|
688 | def setup(self): | |
685 | self.xaxis = 'time' |
|
689 | self.xaxis = 'time' | |
686 | self.ncols = 1 |
|
690 | self.ncols = 1 | |
687 | self.nrows = len(self.data.channels) |
|
691 | self.nrows = len(self.data.channels) | |
688 | self.nplots = len(self.data.channels) |
|
692 | self.nplots = len(self.data.channels) | |
689 | self.ylabel = 'Range [Km]' |
|
693 | self.ylabel = 'Range [Km]' | |
690 | self.cb_label = 'dB' |
|
694 | self.cb_label = 'dB' | |
691 | self.titles = ['{} Channel {}'.format( |
|
695 | self.titles = ['{} Channel {}'.format( | |
692 | self.CODE.upper(), x) for x in range(self.nrows)] |
|
696 | self.CODE.upper(), x) for x in range(self.nrows)] | |
693 |
|
697 | |||
694 | def plot(self): |
|
698 | def plot(self): | |
695 | self.x = self.times |
|
699 | self.x = self.times | |
696 | self.y = self.data.heights |
|
700 | self.y = self.data.heights | |
697 | self.z = self.data[self.CODE] |
|
701 | self.z = self.data[self.CODE] | |
698 | self.z = numpy.ma.masked_invalid(self.z) |
|
702 | self.z = numpy.ma.masked_invalid(self.z) | |
699 |
|
703 | |||
700 | for n, ax in enumerate(self.axes): |
|
704 | for n, ax in enumerate(self.axes): | |
701 | x, y, z = self.fill_gaps(*self.decimate()) |
|
705 | x, y, z = self.fill_gaps(*self.decimate()) | |
702 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) |
|
706 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) | |
703 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) |
|
707 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) | |
704 | if ax.firsttime: |
|
708 | if ax.firsttime: | |
705 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
709 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
706 | vmin=self.zmin, |
|
710 | vmin=self.zmin, | |
707 | vmax=self.zmax, |
|
711 | vmax=self.zmax, | |
708 | cmap=plt.get_cmap(self.colormap) |
|
712 | cmap=plt.get_cmap(self.colormap) | |
709 | ) |
|
713 | ) | |
710 | if self.showprofile: |
|
714 | if self.showprofile: | |
711 | ax.plot_profile = self.pf_axes[n].plot( |
|
715 | ax.plot_profile = self.pf_axes[n].plot( | |
712 | self.data['rti'][n][-1], self.y)[0] |
|
716 | self.data['rti'][n][-1], self.y)[0] | |
713 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, |
|
717 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, | |
714 | color="k", linestyle="dashed", lw=1)[0] |
|
718 | color="k", linestyle="dashed", lw=1)[0] | |
715 | else: |
|
719 | else: | |
716 | ax.collections.remove(ax.collections[0]) |
|
720 | ax.collections.remove(ax.collections[0]) | |
717 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
721 | ax.plt = ax.pcolormesh(x, y, z[n].T, | |
718 | vmin=self.zmin, |
|
722 | vmin=self.zmin, | |
719 | vmax=self.zmax, |
|
723 | vmax=self.zmax, | |
720 | cmap=plt.get_cmap(self.colormap) |
|
724 | cmap=plt.get_cmap(self.colormap) | |
721 | ) |
|
725 | ) | |
722 | if self.showprofile: |
|
726 | if self.showprofile: | |
723 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) |
|
727 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) | |
724 | ax.plot_noise.set_data(numpy.repeat( |
|
728 | ax.plot_noise.set_data(numpy.repeat( | |
725 | self.data['noise'][n][-1], len(self.y)), self.y) |
|
729 | self.data['noise'][n][-1], len(self.y)), self.y) | |
726 |
|
730 | |||
727 | self.saveTime = self.min_time |
|
731 | self.saveTime = self.min_time | |
728 |
|
732 | |||
729 |
|
733 | |||
730 | class PlotCOHData(PlotRTIData): |
|
734 | class PlotCOHData(PlotRTIData): | |
731 | ''' |
|
735 | ''' | |
732 | Plot for Coherence data |
|
736 | Plot for Coherence data | |
733 | ''' |
|
737 | ''' | |
734 |
|
738 | |||
735 | CODE = 'coh' |
|
739 | CODE = 'coh' | |
736 |
|
740 | |||
737 | def setup(self): |
|
741 | def setup(self): | |
738 | self.xaxis = 'time' |
|
742 | self.xaxis = 'time' | |
739 | self.ncols = 1 |
|
743 | self.ncols = 1 | |
740 | self.nrows = len(self.data.pairs) |
|
744 | self.nrows = len(self.data.pairs) | |
741 | self.nplots = len(self.data.pairs) |
|
745 | self.nplots = len(self.data.pairs) | |
742 | self.ylabel = 'Range [Km]' |
|
746 | self.ylabel = 'Range [Km]' | |
743 | if self.CODE == 'coh': |
|
747 | if self.CODE == 'coh': | |
744 | self.cb_label = '' |
|
748 | self.cb_label = '' | |
745 | self.titles = [ |
|
749 | self.titles = [ | |
746 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
750 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
747 | else: |
|
751 | else: | |
748 | self.cb_label = 'Degrees' |
|
752 | self.cb_label = 'Degrees' | |
749 | self.titles = [ |
|
753 | self.titles = [ | |
750 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] |
|
754 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
751 |
|
755 | |||
752 |
|
756 | |||
753 | class PlotPHASEData(PlotCOHData): |
|
757 | class PlotPHASEData(PlotCOHData): | |
754 | ''' |
|
758 | ''' | |
755 | Plot for Phase map data |
|
759 | Plot for Phase map data | |
756 | ''' |
|
760 | ''' | |
757 |
|
761 | |||
758 | CODE = 'phase' |
|
762 | CODE = 'phase' | |
759 | colormap = 'seismic' |
|
763 | colormap = 'seismic' | |
760 |
|
764 | |||
761 |
|
765 | |||
762 | class PlotNoiseData(PlotData): |
|
766 | class PlotNoiseData(PlotData): | |
763 | ''' |
|
767 | ''' | |
764 | Plot for noise |
|
768 | Plot for noise | |
765 | ''' |
|
769 | ''' | |
766 |
|
770 | |||
767 | CODE = 'noise' |
|
771 | CODE = 'noise' | |
768 |
|
772 | |||
769 | def setup(self): |
|
773 | def setup(self): | |
770 | self.xaxis = 'time' |
|
774 | self.xaxis = 'time' | |
771 | self.ncols = 1 |
|
775 | self.ncols = 1 | |
772 | self.nrows = 1 |
|
776 | self.nrows = 1 | |
773 | self.nplots = 1 |
|
777 | self.nplots = 1 | |
774 | self.ylabel = 'Intensity [dB]' |
|
778 | self.ylabel = 'Intensity [dB]' | |
775 | self.titles = ['Noise'] |
|
779 | self.titles = ['Noise'] | |
776 | self.colorbar = False |
|
780 | self.colorbar = False | |
777 |
|
781 | |||
778 | def plot(self): |
|
782 | def plot(self): | |
779 |
|
783 | |||
780 | x = self.times |
|
784 | x = self.times | |
781 | xmin = self.min_time |
|
785 | xmin = self.min_time | |
782 | xmax = xmin + self.xrange * 60 * 60 |
|
786 | xmax = xmin + self.xrange * 60 * 60 | |
783 | Y = self.data[self.CODE] |
|
787 | Y = self.data[self.CODE] | |
784 |
|
788 | |||
785 | if self.axes[0].firsttime: |
|
789 | if self.axes[0].firsttime: | |
786 | for ch in self.data.channels: |
|
790 | for ch in self.data.channels: | |
787 | y = Y[ch] |
|
791 | y = Y[ch] | |
788 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) |
|
792 | self.axes[0].plot(x, y, lw=1, label='Ch{}'.format(ch)) | |
789 | plt.legend() |
|
793 | plt.legend() | |
790 | else: |
|
794 | else: | |
791 | for ch in self.data.channels: |
|
795 | for ch in self.data.channels: | |
792 | y = Y[ch] |
|
796 | y = Y[ch] | |
793 | self.axes[0].lines[ch].set_data(x, y) |
|
797 | self.axes[0].lines[ch].set_data(x, y) | |
794 |
|
798 | |||
795 | self.ymin = numpy.nanmin(Y) - 5 |
|
799 | self.ymin = numpy.nanmin(Y) - 5 | |
796 | self.ymax = numpy.nanmax(Y) + 5 |
|
800 | self.ymax = numpy.nanmax(Y) + 5 | |
797 | self.saveTime = self.min_time |
|
801 | self.saveTime = self.min_time | |
798 |
|
802 | |||
799 |
|
803 | |||
800 | class PlotSNRData(PlotRTIData): |
|
804 | class PlotSNRData(PlotRTIData): | |
801 | ''' |
|
805 | ''' | |
802 | Plot for SNR Data |
|
806 | Plot for SNR Data | |
803 | ''' |
|
807 | ''' | |
804 |
|
808 | |||
805 | CODE = 'snr' |
|
809 | CODE = 'snr' | |
806 | colormap = 'jet' |
|
810 | colormap = 'jet' | |
807 |
|
811 | |||
808 |
|
812 | |||
809 | class PlotDOPData(PlotRTIData): |
|
813 | class PlotDOPData(PlotRTIData): | |
810 | ''' |
|
814 | ''' | |
811 | Plot for DOPPLER Data |
|
815 | Plot for DOPPLER Data | |
812 | ''' |
|
816 | ''' | |
813 |
|
817 | |||
814 | CODE = 'dop' |
|
818 | CODE = 'dop' | |
815 | colormap = 'jet' |
|
819 | colormap = 'jet' | |
816 |
|
820 | |||
817 |
|
821 | |||
818 | class PlotSkyMapData(PlotData): |
|
822 | class PlotSkyMapData(PlotData): | |
819 | ''' |
|
823 | ''' | |
820 | Plot for meteors detection data |
|
824 | Plot for meteors detection data | |
821 | ''' |
|
825 | ''' | |
822 |
|
826 | |||
823 | CODE = 'param' |
|
827 | CODE = 'param' | |
824 |
|
828 | |||
825 | def setup(self): |
|
829 | def setup(self): | |
826 |
|
830 | |||
827 | self.ncols = 1 |
|
831 | self.ncols = 1 | |
828 | self.nrows = 1 |
|
832 | self.nrows = 1 | |
829 | self.width = 7.2 |
|
833 | self.width = 7.2 | |
830 | self.height = 7.2 |
|
834 | self.height = 7.2 | |
831 | self.nplots = 1 |
|
835 | self.nplots = 1 | |
832 | self.xlabel = 'Zonal Zenith Angle (deg)' |
|
836 | self.xlabel = 'Zonal Zenith Angle (deg)' | |
833 | self.ylabel = 'Meridional Zenith Angle (deg)' |
|
837 | self.ylabel = 'Meridional Zenith Angle (deg)' | |
834 | self.polar = True |
|
838 | self.polar = True | |
835 | self.ymin = -180 |
|
839 | self.ymin = -180 | |
836 | self.ymax = 180 |
|
840 | self.ymax = 180 | |
837 | self.colorbar = False |
|
841 | self.colorbar = False | |
838 |
|
842 | |||
839 | def plot(self): |
|
843 | def plot(self): | |
840 |
|
844 | |||
841 | arrayParameters = numpy.concatenate(self.data['param']) |
|
845 | arrayParameters = numpy.concatenate(self.data['param']) | |
842 | error = arrayParameters[:, -1] |
|
846 | error = arrayParameters[:, -1] | |
843 | indValid = numpy.where(error == 0)[0] |
|
847 | indValid = numpy.where(error == 0)[0] | |
844 | finalMeteor = arrayParameters[indValid, :] |
|
848 | finalMeteor = arrayParameters[indValid, :] | |
845 | finalAzimuth = finalMeteor[:, 3] |
|
849 | finalAzimuth = finalMeteor[:, 3] | |
846 | finalZenith = finalMeteor[:, 4] |
|
850 | finalZenith = finalMeteor[:, 4] | |
847 |
|
851 | |||
848 | x = finalAzimuth * numpy.pi / 180 |
|
852 | x = finalAzimuth * numpy.pi / 180 | |
849 | y = finalZenith |
|
853 | y = finalZenith | |
850 |
|
854 | |||
851 | ax = self.axes[0] |
|
855 | ax = self.axes[0] | |
852 |
|
856 | |||
853 | if ax.firsttime: |
|
857 | if ax.firsttime: | |
854 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] |
|
858 | ax.plot = ax.plot(x, y, 'bo', markersize=5)[0] | |
855 | else: |
|
859 | else: | |
856 | ax.plot.set_data(x, y) |
|
860 | ax.plot.set_data(x, y) | |
857 |
|
861 | |||
858 | dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S') |
|
862 | dt1 = self.getDateTime(self.min_time).strftime('%y/%m/%d %H:%M:%S') | |
859 | dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S') |
|
863 | dt2 = self.getDateTime(self.max_time).strftime('%y/%m/%d %H:%M:%S') | |
860 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, |
|
864 | title = 'Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n' % (dt1, | |
861 | dt2, |
|
865 | dt2, | |
862 | len(x)) |
|
866 | len(x)) | |
863 | self.titles[0] = title |
|
867 | self.titles[0] = title | |
864 | self.saveTime = self.max_time |
|
868 | self.saveTime = self.max_time | |
865 |
|
869 | |||
866 |
|
870 | |||
867 | class PlotParamData(PlotRTIData): |
|
871 | class PlotParamData(PlotRTIData): | |
868 | ''' |
|
872 | ''' | |
869 | Plot for data_param object |
|
873 | Plot for data_param object | |
870 | ''' |
|
874 | ''' | |
871 |
|
875 | |||
872 | CODE = 'param' |
|
876 | CODE = 'param' | |
873 | colormap = 'seismic' |
|
877 | colormap = 'seismic' | |
874 |
|
878 | |||
875 | def setup(self): |
|
879 | def setup(self): | |
876 | self.xaxis = 'time' |
|
880 | self.xaxis = 'time' | |
877 | self.ncols = 1 |
|
881 | self.ncols = 1 | |
878 | self.nrows = self.data.shape(self.CODE)[0] |
|
882 | self.nrows = self.data.shape(self.CODE)[0] | |
879 | self.nplots = self.nrows |
|
883 | self.nplots = self.nrows | |
880 | if self.showSNR: |
|
884 | if self.showSNR: | |
881 | self.nrows += 1 |
|
885 | self.nrows += 1 | |
882 | self.nplots += 1 |
|
886 | self.nplots += 1 | |
883 |
|
887 | |||
884 | self.ylabel = 'Height [Km]' |
|
888 | self.ylabel = 'Height [Km]' | |
885 | self.titles = self.data.parameters \ |
|
889 | self.titles = self.data.parameters \ | |
886 | if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)] |
|
890 | if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)] | |
887 | if self.showSNR: |
|
891 | if self.showSNR: | |
888 | self.titles.append('SNR') |
|
892 | self.titles.append('SNR') | |
889 |
|
893 | |||
890 | def plot(self): |
|
894 | def plot(self): | |
891 | self.data.normalize_heights() |
|
895 | self.data.normalize_heights() | |
892 | self.x = self.times |
|
896 | self.x = self.times | |
893 | self.y = self.data.heights |
|
897 | self.y = self.data.heights | |
894 | if self.showSNR: |
|
898 | if self.showSNR: | |
895 | self.z = numpy.concatenate( |
|
899 | self.z = numpy.concatenate( | |
896 | (self.data[self.CODE], self.data['snr']) |
|
900 | (self.data[self.CODE], self.data['snr']) | |
897 | ) |
|
901 | ) | |
898 | else: |
|
902 | else: | |
899 | self.z = self.data[self.CODE] |
|
903 | self.z = self.data[self.CODE] | |
900 |
|
904 | |||
901 | self.z = numpy.ma.masked_invalid(self.z) |
|
905 | self.z = numpy.ma.masked_invalid(self.z) | |
902 |
|
906 | |||
903 | for n, ax in enumerate(self.axes): |
|
907 | for n, ax in enumerate(self.axes): | |
904 |
|
908 | |||
905 | x, y, z = self.fill_gaps(*self.decimate()) |
|
909 | x, y, z = self.fill_gaps(*self.decimate()) | |
906 | self.zmax = self.zmax if self.zmax is not None else numpy.max(self.z[n]) |
|
910 | self.zmax = self.zmax if self.zmax is not None else numpy.max(self.z[n]) | |
907 | self.zmin = self.zmin if self.zmin is not None else numpy.min(self.z[n]) |
|
911 | self.zmin = self.zmin if self.zmin is not None else numpy.min(self.z[n]) | |
908 |
|
912 | |||
909 | if ax.firsttime: |
|
913 | if ax.firsttime: | |
910 | if self.zlimits is not None: |
|
914 | if self.zlimits is not None: | |
911 | self.zmin, self.zmax = self.zlimits[n] |
|
915 | self.zmin, self.zmax = self.zlimits[n] | |
912 |
|
916 | |||
913 | ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n], |
|
917 | ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n], | |
914 | vmin=self.zmin, |
|
918 | vmin=self.zmin, | |
915 | vmax=self.zmax, |
|
919 | vmax=self.zmax, | |
916 | cmap=self.cmaps[n] |
|
920 | cmap=self.cmaps[n] | |
917 | ) |
|
921 | ) | |
918 | else: |
|
922 | else: | |
919 | if self.zlimits is not None: |
|
923 | if self.zlimits is not None: | |
920 | self.zmin, self.zmax = self.zlimits[n] |
|
924 | self.zmin, self.zmax = self.zlimits[n] | |
921 | ax.collections.remove(ax.collections[0]) |
|
925 | ax.collections.remove(ax.collections[0]) | |
922 | ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n], |
|
926 | ax.plt = ax.pcolormesh(x, y, z[n].T*self.factors[n], | |
923 | vmin=self.zmin, |
|
927 | vmin=self.zmin, | |
924 | vmax=self.zmax, |
|
928 | vmax=self.zmax, | |
925 | cmap=self.cmaps[n] |
|
929 | cmap=self.cmaps[n] | |
926 | ) |
|
930 | ) | |
927 |
|
931 | |||
928 | self.saveTime = self.min_time |
|
932 | self.saveTime = self.min_time | |
929 |
|
933 | |||
930 | class PlotOutputData(PlotParamData): |
|
934 | class PlotOutputData(PlotParamData): | |
931 | ''' |
|
935 | ''' | |
932 | Plot data_output object |
|
936 | Plot data_output object | |
933 | ''' |
|
937 | ''' | |
934 |
|
938 | |||
935 | CODE = 'output' |
|
939 | CODE = 'output' | |
936 | colormap = 'seismic' |
|
940 | colormap = 'seismic' |
@@ -1,1830 +1,1833 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 2, 2014 |
|
2 | Created on Jul 2, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import sys |
|
7 | import sys | |
8 | import glob |
|
8 | import glob | |
9 | import time |
|
9 | import time | |
10 | import numpy |
|
10 | import numpy | |
11 | import fnmatch |
|
11 | import fnmatch | |
12 | import inspect |
|
12 | import inspect | |
13 | import time |
|
13 | import time | |
14 | import datetime |
|
14 | import datetime | |
15 | import traceback |
|
15 | import traceback | |
16 | import zmq |
|
16 | import zmq | |
17 |
|
17 | |||
18 | try: |
|
18 | try: | |
19 | from gevent import sleep |
|
19 | from gevent import sleep | |
20 | except: |
|
20 | except: | |
21 | from time import sleep |
|
21 | from time import sleep | |
22 |
|
22 | |||
23 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader |
|
23 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
24 | from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width |
|
24 | from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, get_procflag_dtype, get_dtype_width | |
25 |
|
25 | |||
26 | LOCALTIME = True |
|
26 | LOCALTIME = True | |
27 |
|
27 | |||
28 |
|
28 | |||
29 | def isNumber(cad): |
|
29 | def isNumber(cad): | |
30 | """ |
|
30 | """ | |
31 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
31 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
32 |
|
32 | |||
33 | Excepciones: |
|
33 | Excepciones: | |
34 | Si un determinado string no puede ser convertido a numero |
|
34 | Si un determinado string no puede ser convertido a numero | |
35 | Input: |
|
35 | Input: | |
36 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
36 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
37 |
|
37 | |||
38 | Return: |
|
38 | Return: | |
39 | True : si el string es uno numerico |
|
39 | True : si el string es uno numerico | |
40 | False : no es un string numerico |
|
40 | False : no es un string numerico | |
41 | """ |
|
41 | """ | |
42 | try: |
|
42 | try: | |
43 | float(cad) |
|
43 | float(cad) | |
44 | return True |
|
44 | return True | |
45 | except: |
|
45 | except: | |
46 | return False |
|
46 | return False | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | def isFileInEpoch(filename, startUTSeconds, endUTSeconds): |
|
49 | def isFileInEpoch(filename, startUTSeconds, endUTSeconds): | |
50 | """ |
|
50 | """ | |
51 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
51 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
52 |
|
52 | |||
53 | Inputs: |
|
53 | Inputs: | |
54 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
54 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
55 |
|
55 | |||
56 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
56 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
57 | segundos contados desde 01/01/1970. |
|
57 | segundos contados desde 01/01/1970. | |
58 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
58 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
59 | segundos contados desde 01/01/1970. |
|
59 | segundos contados desde 01/01/1970. | |
60 |
|
60 | |||
61 | Return: |
|
61 | Return: | |
62 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
62 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
63 | fecha especificado, de lo contrario retorna False. |
|
63 | fecha especificado, de lo contrario retorna False. | |
64 |
|
64 | |||
65 | Excepciones: |
|
65 | Excepciones: | |
66 | Si el archivo no existe o no puede ser abierto |
|
66 | Si el archivo no existe o no puede ser abierto | |
67 | Si la cabecera no puede ser leida. |
|
67 | Si la cabecera no puede ser leida. | |
68 |
|
68 | |||
69 | """ |
|
69 | """ | |
70 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
70 | basicHeaderObj = BasicHeader(LOCALTIME) | |
71 |
|
71 | |||
72 | try: |
|
72 | try: | |
73 | fp = open(filename, 'rb') |
|
73 | fp = open(filename, 'rb') | |
74 | except IOError: |
|
74 | except IOError: | |
75 | print "The file %s can't be opened" % (filename) |
|
75 | print "The file %s can't be opened" % (filename) | |
76 | return 0 |
|
76 | return 0 | |
77 |
|
77 | |||
78 | sts = basicHeaderObj.read(fp) |
|
78 | sts = basicHeaderObj.read(fp) | |
79 | fp.close() |
|
79 | fp.close() | |
80 |
|
80 | |||
81 | if not(sts): |
|
81 | if not(sts): | |
82 | print "Skipping the file %s because it has not a valid header" % (filename) |
|
82 | print "Skipping the file %s because it has not a valid header" % (filename) | |
83 | return 0 |
|
83 | return 0 | |
84 |
|
84 | |||
85 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
85 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
86 | return 0 |
|
86 | return 0 | |
87 |
|
87 | |||
88 | return 1 |
|
88 | return 1 | |
89 |
|
89 | |||
90 |
|
90 | |||
91 | def isTimeInRange(thisTime, startTime, endTime): |
|
91 | def isTimeInRange(thisTime, startTime, endTime): | |
92 | if endTime >= startTime: |
|
92 | if endTime >= startTime: | |
93 | if (thisTime < startTime) or (thisTime > endTime): |
|
93 | if (thisTime < startTime) or (thisTime > endTime): | |
94 | return 0 |
|
94 | return 0 | |
95 | return 1 |
|
95 | return 1 | |
96 | else: |
|
96 | else: | |
97 | if (thisTime < startTime) and (thisTime > endTime): |
|
97 | if (thisTime < startTime) and (thisTime > endTime): | |
98 | return 0 |
|
98 | return 0 | |
99 | return 1 |
|
99 | return 1 | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): |
|
102 | def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |
103 | """ |
|
103 | """ | |
104 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
104 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
105 |
|
105 | |||
106 | Inputs: |
|
106 | Inputs: | |
107 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
107 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
108 |
|
108 | |||
109 | startDate : fecha inicial del rango seleccionado en formato datetime.date |
|
109 | startDate : fecha inicial del rango seleccionado en formato datetime.date | |
110 |
|
110 | |||
111 | endDate : fecha final del rango seleccionado en formato datetime.date |
|
111 | endDate : fecha final del rango seleccionado en formato datetime.date | |
112 |
|
112 | |||
113 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
113 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
114 |
|
114 | |||
115 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
115 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
116 |
|
116 | |||
117 | Return: |
|
117 | Return: | |
118 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
118 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
119 | fecha especificado, de lo contrario retorna False. |
|
119 | fecha especificado, de lo contrario retorna False. | |
120 |
|
120 | |||
121 | Excepciones: |
|
121 | Excepciones: | |
122 | Si el archivo no existe o no puede ser abierto |
|
122 | Si el archivo no existe o no puede ser abierto | |
123 | Si la cabecera no puede ser leida. |
|
123 | Si la cabecera no puede ser leida. | |
124 |
|
124 | |||
125 | """ |
|
125 | """ | |
126 |
|
126 | |||
127 | try: |
|
127 | try: | |
128 | fp = open(filename, 'rb') |
|
128 | fp = open(filename, 'rb') | |
129 | except IOError: |
|
129 | except IOError: | |
130 | print "The file %s can't be opened" % (filename) |
|
130 | print "The file %s can't be opened" % (filename) | |
131 | return None |
|
131 | return None | |
132 |
|
132 | |||
133 | firstBasicHeaderObj = BasicHeader(LOCALTIME) |
|
133 | firstBasicHeaderObj = BasicHeader(LOCALTIME) | |
134 | systemHeaderObj = SystemHeader() |
|
134 | systemHeaderObj = SystemHeader() | |
135 | radarControllerHeaderObj = RadarControllerHeader() |
|
135 | radarControllerHeaderObj = RadarControllerHeader() | |
136 | processingHeaderObj = ProcessingHeader() |
|
136 | processingHeaderObj = ProcessingHeader() | |
137 |
|
137 | |||
138 | lastBasicHeaderObj = BasicHeader(LOCALTIME) |
|
138 | lastBasicHeaderObj = BasicHeader(LOCALTIME) | |
139 |
|
139 | |||
140 | sts = firstBasicHeaderObj.read(fp) |
|
140 | sts = firstBasicHeaderObj.read(fp) | |
141 |
|
141 | |||
142 | if not(sts): |
|
142 | if not(sts): | |
143 | print "[Reading] Skipping the file %s because it has not a valid header" % (filename) |
|
143 | print "[Reading] Skipping the file %s because it has not a valid header" % (filename) | |
144 | return None |
|
144 | return None | |
145 |
|
145 | |||
146 | if not systemHeaderObj.read(fp): |
|
146 | if not systemHeaderObj.read(fp): | |
147 | return None |
|
147 | return None | |
148 |
|
148 | |||
149 | if not radarControllerHeaderObj.read(fp): |
|
149 | if not radarControllerHeaderObj.read(fp): | |
150 | return None |
|
150 | return None | |
151 |
|
151 | |||
152 | if not processingHeaderObj.read(fp): |
|
152 | if not processingHeaderObj.read(fp): | |
153 | return None |
|
153 | return None | |
154 |
|
154 | |||
155 | filesize = os.path.getsize(filename) |
|
155 | filesize = os.path.getsize(filename) | |
156 |
|
156 | |||
157 | offset = processingHeaderObj.blockSize + 24 # header size |
|
157 | offset = processingHeaderObj.blockSize + 24 # header size | |
158 |
|
158 | |||
159 | if filesize <= offset: |
|
159 | if filesize <= offset: | |
160 | print "[Reading] %s: This file has not enough data" % filename |
|
160 | print "[Reading] %s: This file has not enough data" % filename | |
161 | return None |
|
161 | return None | |
162 |
|
162 | |||
163 | fp.seek(-offset, 2) |
|
163 | fp.seek(-offset, 2) | |
164 |
|
164 | |||
165 | sts = lastBasicHeaderObj.read(fp) |
|
165 | sts = lastBasicHeaderObj.read(fp) | |
166 |
|
166 | |||
167 | fp.close() |
|
167 | fp.close() | |
168 |
|
168 | |||
169 | thisDatetime = lastBasicHeaderObj.datatime |
|
169 | thisDatetime = lastBasicHeaderObj.datatime | |
170 | thisTime_last_block = thisDatetime.time() |
|
170 | thisTime_last_block = thisDatetime.time() | |
171 |
|
171 | |||
172 | thisDatetime = firstBasicHeaderObj.datatime |
|
172 | thisDatetime = firstBasicHeaderObj.datatime | |
173 | thisDate = thisDatetime.date() |
|
173 | thisDate = thisDatetime.date() | |
174 | thisTime_first_block = thisDatetime.time() |
|
174 | thisTime_first_block = thisDatetime.time() | |
175 |
|
175 | |||
176 | # General case |
|
176 | # General case | |
177 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o |
|
177 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o | |
178 | #-----------o----------------------------o----------- |
|
178 | #-----------o----------------------------o----------- | |
179 | # startTime endTime |
|
179 | # startTime endTime | |
180 |
|
180 | |||
181 | if endTime >= startTime: |
|
181 | if endTime >= startTime: | |
182 | if (thisTime_last_block < startTime) or (thisTime_first_block > endTime): |
|
182 | if (thisTime_last_block < startTime) or (thisTime_first_block > endTime): | |
183 | return None |
|
183 | return None | |
184 |
|
184 | |||
185 | return thisDatetime |
|
185 | return thisDatetime | |
186 |
|
186 | |||
187 | # If endTime < startTime then endTime belongs to the next day |
|
187 | # If endTime < startTime then endTime belongs to the next day | |
188 |
|
188 | |||
189 | #<<<<<<<<<<<o o>>>>>>>>>>> |
|
189 | #<<<<<<<<<<<o o>>>>>>>>>>> | |
190 | #-----------o----------------------------o----------- |
|
190 | #-----------o----------------------------o----------- | |
191 | # endTime startTime |
|
191 | # endTime startTime | |
192 |
|
192 | |||
193 | if (thisDate == startDate) and (thisTime_last_block < startTime): |
|
193 | if (thisDate == startDate) and (thisTime_last_block < startTime): | |
194 | return None |
|
194 | return None | |
195 |
|
195 | |||
196 | if (thisDate == endDate) and (thisTime_first_block > endTime): |
|
196 | if (thisDate == endDate) and (thisTime_first_block > endTime): | |
197 | return None |
|
197 | return None | |
198 |
|
198 | |||
199 | if (thisTime_last_block < startTime) and (thisTime_first_block > endTime): |
|
199 | if (thisTime_last_block < startTime) and (thisTime_first_block > endTime): | |
200 | return None |
|
200 | return None | |
201 |
|
201 | |||
202 | return thisDatetime |
|
202 | return thisDatetime | |
203 |
|
203 | |||
204 |
|
204 | |||
205 | def isFolderInDateRange(folder, startDate=None, endDate=None): |
|
205 | def isFolderInDateRange(folder, startDate=None, endDate=None): | |
206 | """ |
|
206 | """ | |
207 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
207 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
208 |
|
208 | |||
209 | Inputs: |
|
209 | Inputs: | |
210 | folder : nombre completo del directorio. |
|
210 | folder : nombre completo del directorio. | |
211 | Su formato deberia ser "/path_root/?YYYYDDD" |
|
211 | Su formato deberia ser "/path_root/?YYYYDDD" | |
212 |
|
212 | |||
213 | siendo: |
|
213 | siendo: | |
214 | YYYY : Anio (ejemplo 2015) |
|
214 | YYYY : Anio (ejemplo 2015) | |
215 | DDD : Dia del anio (ejemplo 305) |
|
215 | DDD : Dia del anio (ejemplo 305) | |
216 |
|
216 | |||
217 | startDate : fecha inicial del rango seleccionado en formato datetime.date |
|
217 | startDate : fecha inicial del rango seleccionado en formato datetime.date | |
218 |
|
218 | |||
219 | endDate : fecha final del rango seleccionado en formato datetime.date |
|
219 | endDate : fecha final del rango seleccionado en formato datetime.date | |
220 |
|
220 | |||
221 | Return: |
|
221 | Return: | |
222 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
222 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
223 | fecha especificado, de lo contrario retorna False. |
|
223 | fecha especificado, de lo contrario retorna False. | |
224 | Excepciones: |
|
224 | Excepciones: | |
225 | Si el directorio no tiene el formato adecuado |
|
225 | Si el directorio no tiene el formato adecuado | |
226 | """ |
|
226 | """ | |
227 |
|
227 | |||
228 | basename = os.path.basename(folder) |
|
228 | basename = os.path.basename(folder) | |
229 |
|
229 | |||
230 | if not isRadarFolder(basename): |
|
230 | if not isRadarFolder(basename): | |
231 | print "The folder %s has not the rigth format" % folder |
|
231 | print "The folder %s has not the rigth format" % folder | |
232 | return 0 |
|
232 | return 0 | |
233 |
|
233 | |||
234 | if startDate and endDate: |
|
234 | if startDate and endDate: | |
235 | thisDate = getDateFromRadarFolder(basename) |
|
235 | thisDate = getDateFromRadarFolder(basename) | |
236 |
|
236 | |||
237 | if thisDate < startDate: |
|
237 | if thisDate < startDate: | |
238 | return 0 |
|
238 | return 0 | |
239 |
|
239 | |||
240 | if thisDate > endDate: |
|
240 | if thisDate > endDate: | |
241 | return 0 |
|
241 | return 0 | |
242 |
|
242 | |||
243 | return 1 |
|
243 | return 1 | |
244 |
|
244 | |||
245 |
|
245 | |||
246 | def isFileInDateRange(filename, startDate=None, endDate=None): |
|
246 | def isFileInDateRange(filename, startDate=None, endDate=None): | |
247 | """ |
|
247 | """ | |
248 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
248 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
249 |
|
249 | |||
250 | Inputs: |
|
250 | Inputs: | |
251 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
251 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
252 |
|
252 | |||
253 | Su formato deberia ser "?YYYYDDDsss" |
|
253 | Su formato deberia ser "?YYYYDDDsss" | |
254 |
|
254 | |||
255 | siendo: |
|
255 | siendo: | |
256 | YYYY : Anio (ejemplo 2015) |
|
256 | YYYY : Anio (ejemplo 2015) | |
257 | DDD : Dia del anio (ejemplo 305) |
|
257 | DDD : Dia del anio (ejemplo 305) | |
258 | sss : set |
|
258 | sss : set | |
259 |
|
259 | |||
260 | startDate : fecha inicial del rango seleccionado en formato datetime.date |
|
260 | startDate : fecha inicial del rango seleccionado en formato datetime.date | |
261 |
|
261 | |||
262 | endDate : fecha final del rango seleccionado en formato datetime.date |
|
262 | endDate : fecha final del rango seleccionado en formato datetime.date | |
263 |
|
263 | |||
264 | Return: |
|
264 | Return: | |
265 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
265 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
266 | fecha especificado, de lo contrario retorna False. |
|
266 | fecha especificado, de lo contrario retorna False. | |
267 | Excepciones: |
|
267 | Excepciones: | |
268 | Si el archivo no tiene el formato adecuado |
|
268 | Si el archivo no tiene el formato adecuado | |
269 | """ |
|
269 | """ | |
270 |
|
270 | |||
271 | basename = os.path.basename(filename) |
|
271 | basename = os.path.basename(filename) | |
272 |
|
272 | |||
273 | if not isRadarFile(basename): |
|
273 | if not isRadarFile(basename): | |
274 | print "The filename %s has not the rigth format" % filename |
|
274 | print "The filename %s has not the rigth format" % filename | |
275 | return 0 |
|
275 | return 0 | |
276 |
|
276 | |||
277 | if startDate and endDate: |
|
277 | if startDate and endDate: | |
278 | thisDate = getDateFromRadarFile(basename) |
|
278 | thisDate = getDateFromRadarFile(basename) | |
279 |
|
279 | |||
280 | if thisDate < startDate: |
|
280 | if thisDate < startDate: | |
281 | return 0 |
|
281 | return 0 | |
282 |
|
282 | |||
283 | if thisDate > endDate: |
|
283 | if thisDate > endDate: | |
284 | return 0 |
|
284 | return 0 | |
285 |
|
285 | |||
286 | return 1 |
|
286 | return 1 | |
287 |
|
287 | |||
288 |
|
288 | |||
289 | def getFileFromSet(path, ext, set): |
|
289 | def getFileFromSet(path, ext, set): | |
290 | validFilelist = [] |
|
290 | validFilelist = [] | |
291 | fileList = os.listdir(path) |
|
291 | fileList = os.listdir(path) | |
292 |
|
292 | |||
293 | # 0 1234 567 89A BCDE |
|
293 | # 0 1234 567 89A BCDE | |
294 | # H YYYY DDD SSS .ext |
|
294 | # H YYYY DDD SSS .ext | |
295 |
|
295 | |||
296 | for thisFile in fileList: |
|
296 | for thisFile in fileList: | |
297 | try: |
|
297 | try: | |
298 | year = int(thisFile[1:5]) |
|
298 | year = int(thisFile[1:5]) | |
299 | doy = int(thisFile[5:8]) |
|
299 | doy = int(thisFile[5:8]) | |
300 | except: |
|
300 | except: | |
301 | continue |
|
301 | continue | |
302 |
|
302 | |||
303 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
303 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): | |
304 | continue |
|
304 | continue | |
305 |
|
305 | |||
306 | validFilelist.append(thisFile) |
|
306 | validFilelist.append(thisFile) | |
307 |
|
307 | |||
308 | myfile = fnmatch.filter( |
|
308 | myfile = fnmatch.filter( | |
309 | validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set)) |
|
309 | validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set)) | |
310 |
|
310 | |||
311 | if len(myfile) != 0: |
|
311 | if len(myfile) != 0: | |
312 | return myfile[0] |
|
312 | return myfile[0] | |
313 | else: |
|
313 | else: | |
314 | filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower()) |
|
314 | filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower()) | |
315 | print 'the filename %s does not exist' % filename |
|
315 | print 'the filename %s does not exist' % filename | |
316 | print '...going to the last file: ' |
|
316 | print '...going to the last file: ' | |
317 |
|
317 | |||
318 | if validFilelist: |
|
318 | if validFilelist: | |
319 | validFilelist = sorted(validFilelist, key=str.lower) |
|
319 | validFilelist = sorted(validFilelist, key=str.lower) | |
320 | return validFilelist[-1] |
|
320 | return validFilelist[-1] | |
321 |
|
321 | |||
322 | return None |
|
322 | return None | |
323 |
|
323 | |||
324 |
|
324 | |||
325 | def getlastFileFromPath(path, ext): |
|
325 | def getlastFileFromPath(path, ext): | |
326 | """ |
|
326 | """ | |
327 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
327 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
328 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
328 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
329 |
|
329 | |||
330 | Input: |
|
330 | Input: | |
331 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
331 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
332 | ext : extension de los files contenidos en una carpeta |
|
332 | ext : extension de los files contenidos en una carpeta | |
333 |
|
333 | |||
334 | Return: |
|
334 | Return: | |
335 | El ultimo file de una determinada carpeta, no se considera el path. |
|
335 | El ultimo file de una determinada carpeta, no se considera el path. | |
336 | """ |
|
336 | """ | |
337 | validFilelist = [] |
|
337 | validFilelist = [] | |
338 | fileList = os.listdir(path) |
|
338 | fileList = os.listdir(path) | |
339 |
|
339 | |||
340 | # 0 1234 567 89A BCDE |
|
340 | # 0 1234 567 89A BCDE | |
341 | # H YYYY DDD SSS .ext |
|
341 | # H YYYY DDD SSS .ext | |
342 |
|
342 | |||
343 | for thisFile in fileList: |
|
343 | for thisFile in fileList: | |
344 |
|
344 | |||
345 | year = thisFile[1:5] |
|
345 | year = thisFile[1:5] | |
346 | if not isNumber(year): |
|
346 | if not isNumber(year): | |
347 | continue |
|
347 | continue | |
348 |
|
348 | |||
349 | doy = thisFile[5:8] |
|
349 | doy = thisFile[5:8] | |
350 | if not isNumber(doy): |
|
350 | if not isNumber(doy): | |
351 | continue |
|
351 | continue | |
352 |
|
352 | |||
353 | year = int(year) |
|
353 | year = int(year) | |
354 | doy = int(doy) |
|
354 | doy = int(doy) | |
355 |
|
355 | |||
356 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
356 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): | |
357 | continue |
|
357 | continue | |
358 |
|
358 | |||
359 | validFilelist.append(thisFile) |
|
359 | validFilelist.append(thisFile) | |
360 |
|
360 | |||
361 | if validFilelist: |
|
361 | if validFilelist: | |
362 | validFilelist = sorted(validFilelist, key=str.lower) |
|
362 | validFilelist = sorted(validFilelist, key=str.lower) | |
363 | return validFilelist[-1] |
|
363 | return validFilelist[-1] | |
364 |
|
364 | |||
365 | return None |
|
365 | return None | |
366 |
|
366 | |||
367 |
|
367 | |||
368 | def checkForRealPath(path, foldercounter, year, doy, set, ext): |
|
368 | def checkForRealPath(path, foldercounter, year, doy, set, ext): | |
369 | """ |
|
369 | """ | |
370 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
370 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
371 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
371 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
372 | el path exacto de un determinado file. |
|
372 | el path exacto de un determinado file. | |
373 |
|
373 | |||
374 | Example : |
|
374 | Example : | |
375 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
375 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
376 |
|
376 | |||
377 | Entonces la funcion prueba con las siguientes combinaciones |
|
377 | Entonces la funcion prueba con las siguientes combinaciones | |
378 | .../.../y2009307367.ext |
|
378 | .../.../y2009307367.ext | |
379 | .../.../Y2009307367.ext |
|
379 | .../.../Y2009307367.ext | |
380 | .../.../x2009307/y2009307367.ext |
|
380 | .../.../x2009307/y2009307367.ext | |
381 | .../.../x2009307/Y2009307367.ext |
|
381 | .../.../x2009307/Y2009307367.ext | |
382 | .../.../X2009307/y2009307367.ext |
|
382 | .../.../X2009307/y2009307367.ext | |
383 | .../.../X2009307/Y2009307367.ext |
|
383 | .../.../X2009307/Y2009307367.ext | |
384 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
384 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
385 |
|
385 | |||
386 | Return: |
|
386 | Return: | |
387 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
387 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
388 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
388 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
389 | para el filename |
|
389 | para el filename | |
390 | """ |
|
390 | """ | |
391 | fullfilename = None |
|
391 | fullfilename = None | |
392 | find_flag = False |
|
392 | find_flag = False | |
393 | filename = None |
|
393 | filename = None | |
394 |
|
394 | |||
395 | prefixDirList = [None, 'd', 'D'] |
|
395 | prefixDirList = [None, 'd', 'D'] | |
396 | if ext.lower() == ".r": # voltage |
|
396 | if ext.lower() == ".r": # voltage | |
397 | prefixFileList = ['d', 'D'] |
|
397 | prefixFileList = ['d', 'D'] | |
398 | elif ext.lower() == ".pdata": # spectra |
|
398 | elif ext.lower() == ".pdata": # spectra | |
399 | prefixFileList = ['p', 'P'] |
|
399 | prefixFileList = ['p', 'P'] | |
400 | else: |
|
400 | else: | |
401 | return None, filename |
|
401 | return None, filename | |
402 |
|
402 | |||
403 | # barrido por las combinaciones posibles |
|
403 | # barrido por las combinaciones posibles | |
404 | for prefixDir in prefixDirList: |
|
404 | for prefixDir in prefixDirList: | |
405 | thispath = path |
|
405 | thispath = path | |
406 | if prefixDir != None: |
|
406 | if prefixDir != None: | |
407 | # formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
407 | # formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
408 | if foldercounter == 0: |
|
408 | if foldercounter == 0: | |
409 | thispath = os.path.join(path, "%s%04d%03d" % |
|
409 | thispath = os.path.join(path, "%s%04d%03d" % | |
410 | (prefixDir, year, doy)) |
|
410 | (prefixDir, year, doy)) | |
411 | else: |
|
411 | else: | |
412 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( |
|
412 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( | |
413 | prefixDir, year, doy, foldercounter)) |
|
413 | prefixDir, year, doy, foldercounter)) | |
414 | for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D" |
|
414 | for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D" | |
415 | # formo el nombre del file xYYYYDDDSSS.ext |
|
415 | # formo el nombre del file xYYYYDDDSSS.ext | |
416 | filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext) |
|
416 | filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext) | |
417 | fullfilename = os.path.join( |
|
417 | fullfilename = os.path.join( | |
418 | thispath, filename) # formo el path completo |
|
418 | thispath, filename) # formo el path completo | |
419 |
|
419 | |||
420 | if os.path.exists(fullfilename): # verifico que exista |
|
420 | if os.path.exists(fullfilename): # verifico que exista | |
421 | find_flag = True |
|
421 | find_flag = True | |
422 | break |
|
422 | break | |
423 | if find_flag: |
|
423 | if find_flag: | |
424 | break |
|
424 | break | |
425 |
|
425 | |||
426 | if not(find_flag): |
|
426 | if not(find_flag): | |
427 | return None, filename |
|
427 | return None, filename | |
428 |
|
428 | |||
429 | return fullfilename, filename |
|
429 | return fullfilename, filename | |
430 |
|
430 | |||
431 |
|
431 | |||
432 | def isRadarFolder(folder): |
|
432 | def isRadarFolder(folder): | |
433 | try: |
|
433 | try: | |
434 | year = int(folder[1:5]) |
|
434 | year = int(folder[1:5]) | |
435 | doy = int(folder[5:8]) |
|
435 | doy = int(folder[5:8]) | |
436 | except: |
|
436 | except: | |
437 | return 0 |
|
437 | return 0 | |
438 |
|
438 | |||
439 | return 1 |
|
439 | return 1 | |
440 |
|
440 | |||
441 |
|
441 | |||
442 | def isRadarFile(file): |
|
442 | def isRadarFile(file): | |
443 | try: |
|
443 | try: | |
444 | year = int(file[1:5]) |
|
444 | year = int(file[1:5]) | |
445 | doy = int(file[5:8]) |
|
445 | doy = int(file[5:8]) | |
446 | set = int(file[8:11]) |
|
446 | set = int(file[8:11]) | |
447 | except: |
|
447 | except: | |
448 | return 0 |
|
448 | return 0 | |
449 |
|
449 | |||
450 | return 1 |
|
450 | return 1 | |
451 |
|
451 | |||
452 |
|
452 | |||
453 | def getDateFromRadarFile(file): |
|
453 | def getDateFromRadarFile(file): | |
454 | try: |
|
454 | try: | |
455 | year = int(file[1:5]) |
|
455 | year = int(file[1:5]) | |
456 | doy = int(file[5:8]) |
|
456 | doy = int(file[5:8]) | |
457 | set = int(file[8:11]) |
|
457 | set = int(file[8:11]) | |
458 | except: |
|
458 | except: | |
459 | return None |
|
459 | return None | |
460 |
|
460 | |||
461 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1) |
|
461 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1) | |
462 | return thisDate |
|
462 | return thisDate | |
463 |
|
463 | |||
464 |
|
464 | |||
465 | def getDateFromRadarFolder(folder): |
|
465 | def getDateFromRadarFolder(folder): | |
466 | try: |
|
466 | try: | |
467 | year = int(folder[1:5]) |
|
467 | year = int(folder[1:5]) | |
468 | doy = int(folder[5:8]) |
|
468 | doy = int(folder[5:8]) | |
469 | except: |
|
469 | except: | |
470 | return None |
|
470 | return None | |
471 |
|
471 | |||
472 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1) |
|
472 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1) | |
473 | return thisDate |
|
473 | return thisDate | |
474 |
|
474 | |||
475 |
|
475 | |||
476 | class JRODataIO: |
|
476 | class JRODataIO: | |
477 |
|
477 | |||
478 | c = 3E8 |
|
478 | c = 3E8 | |
479 |
|
479 | |||
480 | isConfig = False |
|
480 | isConfig = False | |
481 |
|
481 | |||
482 | basicHeaderObj = None |
|
482 | basicHeaderObj = None | |
483 |
|
483 | |||
484 | systemHeaderObj = None |
|
484 | systemHeaderObj = None | |
485 |
|
485 | |||
486 | radarControllerHeaderObj = None |
|
486 | radarControllerHeaderObj = None | |
487 |
|
487 | |||
488 | processingHeaderObj = None |
|
488 | processingHeaderObj = None | |
489 |
|
489 | |||
490 | dtype = None |
|
490 | dtype = None | |
491 |
|
491 | |||
492 | pathList = [] |
|
492 | pathList = [] | |
493 |
|
493 | |||
494 | filenameList = [] |
|
494 | filenameList = [] | |
495 |
|
495 | |||
496 | filename = None |
|
496 | filename = None | |
497 |
|
497 | |||
498 | ext = None |
|
498 | ext = None | |
499 |
|
499 | |||
500 | flagIsNewFile = 1 |
|
500 | flagIsNewFile = 1 | |
501 |
|
501 | |||
502 | flagDiscontinuousBlock = 0 |
|
502 | flagDiscontinuousBlock = 0 | |
503 |
|
503 | |||
504 | flagIsNewBlock = 0 |
|
504 | flagIsNewBlock = 0 | |
505 |
|
505 | |||
506 | fp = None |
|
506 | fp = None | |
507 |
|
507 | |||
508 | firstHeaderSize = 0 |
|
508 | firstHeaderSize = 0 | |
509 |
|
509 | |||
510 | basicHeaderSize = 24 |
|
510 | basicHeaderSize = 24 | |
511 |
|
511 | |||
512 | versionFile = 1103 |
|
512 | versionFile = 1103 | |
513 |
|
513 | |||
514 | fileSize = None |
|
514 | fileSize = None | |
515 |
|
515 | |||
516 | # ippSeconds = None |
|
516 | # ippSeconds = None | |
517 |
|
517 | |||
518 | fileSizeByHeader = None |
|
518 | fileSizeByHeader = None | |
519 |
|
519 | |||
520 | fileIndex = None |
|
520 | fileIndex = None | |
521 |
|
521 | |||
522 | profileIndex = None |
|
522 | profileIndex = None | |
523 |
|
523 | |||
524 | blockIndex = None |
|
524 | blockIndex = None | |
525 |
|
525 | |||
526 | nTotalBlocks = None |
|
526 | nTotalBlocks = None | |
527 |
|
527 | |||
528 | maxTimeStep = 30 |
|
528 | maxTimeStep = 30 | |
529 |
|
529 | |||
530 | lastUTTime = None |
|
530 | lastUTTime = None | |
531 |
|
531 | |||
532 | datablock = None |
|
532 | datablock = None | |
533 |
|
533 | |||
534 | dataOut = None |
|
534 | dataOut = None | |
535 |
|
535 | |||
536 | blocksize = None |
|
536 | blocksize = None | |
537 |
|
537 | |||
538 | getByBlock = False |
|
538 | getByBlock = False | |
539 |
|
539 | |||
540 | def __init__(self): |
|
540 | def __init__(self): | |
541 |
|
541 | |||
542 | raise NotImplementedError |
|
542 | raise NotImplementedError | |
543 |
|
543 | |||
544 | def run(self): |
|
544 | def run(self): | |
545 |
|
545 | |||
546 | raise NotImplementedError |
|
546 | raise NotImplementedError | |
547 |
|
547 | |||
548 | def getDtypeWidth(self): |
|
548 | def getDtypeWidth(self): | |
549 |
|
549 | |||
550 | dtype_index = get_dtype_index(self.dtype) |
|
550 | dtype_index = get_dtype_index(self.dtype) | |
551 | dtype_width = get_dtype_width(dtype_index) |
|
551 | dtype_width = get_dtype_width(dtype_index) | |
552 |
|
552 | |||
553 | return dtype_width |
|
553 | return dtype_width | |
554 |
|
554 | |||
555 | def getAllowedArgs(self): |
|
555 | def getAllowedArgs(self): | |
556 | return inspect.getargspec(self.run).args |
|
556 | if hasattr(self, '__attrs__'): | |
|
557 | return self.__attrs__ | |||
|
558 | else: | |||
|
559 | return inspect.getargspec(self.run).args | |||
557 |
|
560 | |||
558 |
|
561 | |||
559 | class JRODataReader(JRODataIO): |
|
562 | class JRODataReader(JRODataIO): | |
560 |
|
563 | |||
561 | online = 0 |
|
564 | online = 0 | |
562 |
|
565 | |||
563 | realtime = 0 |
|
566 | realtime = 0 | |
564 |
|
567 | |||
565 | nReadBlocks = 0 |
|
568 | nReadBlocks = 0 | |
566 |
|
569 | |||
567 | delay = 10 # number of seconds waiting a new file |
|
570 | delay = 10 # number of seconds waiting a new file | |
568 |
|
571 | |||
569 | nTries = 3 # quantity tries |
|
572 | nTries = 3 # quantity tries | |
570 |
|
573 | |||
571 | nFiles = 3 # number of files for searching |
|
574 | nFiles = 3 # number of files for searching | |
572 |
|
575 | |||
573 | path = None |
|
576 | path = None | |
574 |
|
577 | |||
575 | foldercounter = 0 |
|
578 | foldercounter = 0 | |
576 |
|
579 | |||
577 | flagNoMoreFiles = 0 |
|
580 | flagNoMoreFiles = 0 | |
578 |
|
581 | |||
579 | datetimeList = [] |
|
582 | datetimeList = [] | |
580 |
|
583 | |||
581 | __isFirstTimeOnline = 1 |
|
584 | __isFirstTimeOnline = 1 | |
582 |
|
585 | |||
583 | __printInfo = True |
|
586 | __printInfo = True | |
584 |
|
587 | |||
585 | profileIndex = None |
|
588 | profileIndex = None | |
586 |
|
589 | |||
587 | nTxs = 1 |
|
590 | nTxs = 1 | |
588 |
|
591 | |||
589 | txIndex = None |
|
592 | txIndex = None | |
590 |
|
593 | |||
591 | # Added-------------------- |
|
594 | # Added-------------------- | |
592 |
|
595 | |||
593 | selBlocksize = None |
|
596 | selBlocksize = None | |
594 |
|
597 | |||
595 | selBlocktime = None |
|
598 | selBlocktime = None | |
596 |
|
599 | |||
597 | def __init__(self): |
|
600 | def __init__(self): | |
598 | """ |
|
601 | """ | |
599 | This class is used to find data files |
|
602 | This class is used to find data files | |
600 |
|
603 | |||
601 | Example: |
|
604 | Example: | |
602 | reader = JRODataReader() |
|
605 | reader = JRODataReader() | |
603 | fileList = reader.findDataFiles() |
|
606 | fileList = reader.findDataFiles() | |
604 |
|
607 | |||
605 | """ |
|
608 | """ | |
606 | pass |
|
609 | pass | |
607 |
|
610 | |||
608 | def createObjByDefault(self): |
|
611 | def createObjByDefault(self): | |
609 | """ |
|
612 | """ | |
610 |
|
613 | |||
611 | """ |
|
614 | """ | |
612 | raise NotImplementedError |
|
615 | raise NotImplementedError | |
613 |
|
616 | |||
614 | def getBlockDimension(self): |
|
617 | def getBlockDimension(self): | |
615 |
|
618 | |||
616 | raise NotImplementedError |
|
619 | raise NotImplementedError | |
617 |
|
620 | |||
618 | def searchFilesOffLine(self, |
|
621 | def searchFilesOffLine(self, | |
619 | path, |
|
622 | path, | |
620 | startDate=None, |
|
623 | startDate=None, | |
621 | endDate=None, |
|
624 | endDate=None, | |
622 | startTime=datetime.time(0, 0, 0), |
|
625 | startTime=datetime.time(0, 0, 0), | |
623 | endTime=datetime.time(23, 59, 59), |
|
626 | endTime=datetime.time(23, 59, 59), | |
624 | set=None, |
|
627 | set=None, | |
625 | expLabel='', |
|
628 | expLabel='', | |
626 | ext='.r', |
|
629 | ext='.r', | |
627 | cursor=None, |
|
630 | cursor=None, | |
628 | skip=None, |
|
631 | skip=None, | |
629 | walk=True): |
|
632 | walk=True): | |
630 |
|
633 | |||
631 | self.filenameList = [] |
|
634 | self.filenameList = [] | |
632 | self.datetimeList = [] |
|
635 | self.datetimeList = [] | |
633 |
|
636 | |||
634 | pathList = [] |
|
637 | pathList = [] | |
635 |
|
638 | |||
636 | dateList, pathList = self.findDatafiles( |
|
639 | dateList, pathList = self.findDatafiles( | |
637 | path, startDate, endDate, expLabel, ext, walk, include_path=True) |
|
640 | path, startDate, endDate, expLabel, ext, walk, include_path=True) | |
638 |
|
641 | |||
639 | if dateList == []: |
|
642 | if dateList == []: | |
640 | return [], [] |
|
643 | return [], [] | |
641 |
|
644 | |||
642 | if len(dateList) > 1: |
|
645 | if len(dateList) > 1: | |
643 | print "[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList)) |
|
646 | print "[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList)) | |
644 | else: |
|
647 | else: | |
645 | print "[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0]) |
|
648 | print "[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0]) | |
646 |
|
649 | |||
647 | filenameList = [] |
|
650 | filenameList = [] | |
648 | datetimeList = [] |
|
651 | datetimeList = [] | |
649 |
|
652 | |||
650 | for thisPath in pathList: |
|
653 | for thisPath in pathList: | |
651 |
|
654 | |||
652 | fileList = glob.glob1(thisPath, "*%s" % ext) |
|
655 | fileList = glob.glob1(thisPath, "*%s" % ext) | |
653 | fileList.sort() |
|
656 | fileList.sort() | |
654 |
|
657 | |||
655 | skippedFileList = [] |
|
658 | skippedFileList = [] | |
656 |
|
659 | |||
657 | if cursor is not None and skip is not None: |
|
660 | if cursor is not None and skip is not None: | |
658 |
|
661 | |||
659 | if skip == 0: |
|
662 | if skip == 0: | |
660 | skippedFileList = [] |
|
663 | skippedFileList = [] | |
661 | else: |
|
664 | else: | |
662 | skippedFileList = fileList[cursor * |
|
665 | skippedFileList = fileList[cursor * | |
663 | skip: cursor * skip + skip] |
|
666 | skip: cursor * skip + skip] | |
664 |
|
667 | |||
665 | else: |
|
668 | else: | |
666 | skippedFileList = fileList |
|
669 | skippedFileList = fileList | |
667 |
|
670 | |||
668 | for file in skippedFileList: |
|
671 | for file in skippedFileList: | |
669 |
|
672 | |||
670 | filename = os.path.join(thisPath, file) |
|
673 | filename = os.path.join(thisPath, file) | |
671 |
|
674 | |||
672 | if not isFileInDateRange(filename, startDate, endDate): |
|
675 | if not isFileInDateRange(filename, startDate, endDate): | |
673 | continue |
|
676 | continue | |
674 |
|
677 | |||
675 | thisDatetime = isFileInTimeRange( |
|
678 | thisDatetime = isFileInTimeRange( | |
676 | filename, startDate, endDate, startTime, endTime) |
|
679 | filename, startDate, endDate, startTime, endTime) | |
677 |
|
680 | |||
678 | if not(thisDatetime): |
|
681 | if not(thisDatetime): | |
679 | continue |
|
682 | continue | |
680 |
|
683 | |||
681 | filenameList.append(filename) |
|
684 | filenameList.append(filename) | |
682 | datetimeList.append(thisDatetime) |
|
685 | datetimeList.append(thisDatetime) | |
683 |
|
686 | |||
684 | if not(filenameList): |
|
687 | if not(filenameList): | |
685 | print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path) |
|
688 | print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path) | |
686 | return [], [] |
|
689 | return [], [] | |
687 |
|
690 | |||
688 | print "[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime) |
|
691 | print "[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime) | |
689 |
|
692 | |||
690 |
|
693 | |||
691 | # for i in range(len(filenameList)): |
|
694 | # for i in range(len(filenameList)): | |
692 | # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
695 | # print "[Reading] %s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) | |
693 |
|
696 | |||
694 | self.filenameList = filenameList |
|
697 | self.filenameList = filenameList | |
695 | self.datetimeList = datetimeList |
|
698 | self.datetimeList = datetimeList | |
696 |
|
699 | |||
697 | return pathList, filenameList |
|
700 | return pathList, filenameList | |
698 |
|
701 | |||
699 | def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None): |
|
702 | def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None): | |
700 | """ |
|
703 | """ | |
701 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
704 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
702 | devuelve el archivo encontrado ademas de otros datos. |
|
705 | devuelve el archivo encontrado ademas de otros datos. | |
703 |
|
706 | |||
704 | Input: |
|
707 | Input: | |
705 | path : carpeta donde estan contenidos los files que contiene data |
|
708 | path : carpeta donde estan contenidos los files que contiene data | |
706 |
|
709 | |||
707 | expLabel : Nombre del subexperimento (subfolder) |
|
710 | expLabel : Nombre del subexperimento (subfolder) | |
708 |
|
711 | |||
709 | ext : extension de los files |
|
712 | ext : extension de los files | |
710 |
|
713 | |||
711 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
714 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) | |
712 |
|
715 | |||
713 | Return: |
|
716 | Return: | |
714 | directory : eL directorio donde esta el file encontrado |
|
717 | directory : eL directorio donde esta el file encontrado | |
715 | filename : el ultimo file de una determinada carpeta |
|
718 | filename : el ultimo file de una determinada carpeta | |
716 | year : el anho |
|
719 | year : el anho | |
717 | doy : el numero de dia del anho |
|
720 | doy : el numero de dia del anho | |
718 | set : el set del archivo |
|
721 | set : el set del archivo | |
719 |
|
722 | |||
720 |
|
723 | |||
721 | """ |
|
724 | """ | |
722 | if not os.path.isdir(path): |
|
725 | if not os.path.isdir(path): | |
723 | return None, None, None, None, None, None |
|
726 | return None, None, None, None, None, None | |
724 |
|
727 | |||
725 | dirList = [] |
|
728 | dirList = [] | |
726 |
|
729 | |||
727 | if not walk: |
|
730 | if not walk: | |
728 | fullpath = path |
|
731 | fullpath = path | |
729 | foldercounter = 0 |
|
732 | foldercounter = 0 | |
730 | else: |
|
733 | else: | |
731 | # Filtra solo los directorios |
|
734 | # Filtra solo los directorios | |
732 | for thisPath in os.listdir(path): |
|
735 | for thisPath in os.listdir(path): | |
733 | if not os.path.isdir(os.path.join(path, thisPath)): |
|
736 | if not os.path.isdir(os.path.join(path, thisPath)): | |
734 | continue |
|
737 | continue | |
735 | if not isRadarFolder(thisPath): |
|
738 | if not isRadarFolder(thisPath): | |
736 | continue |
|
739 | continue | |
737 |
|
740 | |||
738 | dirList.append(thisPath) |
|
741 | dirList.append(thisPath) | |
739 |
|
742 | |||
740 | if not(dirList): |
|
743 | if not(dirList): | |
741 | return None, None, None, None, None, None |
|
744 | return None, None, None, None, None, None | |
742 |
|
745 | |||
743 | dirList = sorted(dirList, key=str.lower) |
|
746 | dirList = sorted(dirList, key=str.lower) | |
744 |
|
747 | |||
745 | doypath = dirList[-1] |
|
748 | doypath = dirList[-1] | |
746 | foldercounter = int(doypath.split('_')[1]) if len( |
|
749 | foldercounter = int(doypath.split('_')[1]) if len( | |
747 | doypath.split('_')) > 1 else 0 |
|
750 | doypath.split('_')) > 1 else 0 | |
748 | fullpath = os.path.join(path, doypath, expLabel) |
|
751 | fullpath = os.path.join(path, doypath, expLabel) | |
749 |
|
752 | |||
750 | print "[Reading] %s folder was found: " % (fullpath) |
|
753 | print "[Reading] %s folder was found: " % (fullpath) | |
751 |
|
754 | |||
752 | if set == None: |
|
755 | if set == None: | |
753 | filename = getlastFileFromPath(fullpath, ext) |
|
756 | filename = getlastFileFromPath(fullpath, ext) | |
754 | else: |
|
757 | else: | |
755 | filename = getFileFromSet(fullpath, ext, set) |
|
758 | filename = getFileFromSet(fullpath, ext, set) | |
756 |
|
759 | |||
757 | if not(filename): |
|
760 | if not(filename): | |
758 | return None, None, None, None, None, None |
|
761 | return None, None, None, None, None, None | |
759 |
|
762 | |||
760 | print "[Reading] %s file was found" % (filename) |
|
763 | print "[Reading] %s file was found" % (filename) | |
761 |
|
764 | |||
762 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
765 | if not(self.__verifyFile(os.path.join(fullpath, filename))): | |
763 | return None, None, None, None, None, None |
|
766 | return None, None, None, None, None, None | |
764 |
|
767 | |||
765 | year = int(filename[1:5]) |
|
768 | year = int(filename[1:5]) | |
766 | doy = int(filename[5:8]) |
|
769 | doy = int(filename[5:8]) | |
767 | set = int(filename[8:11]) |
|
770 | set = int(filename[8:11]) | |
768 |
|
771 | |||
769 | return fullpath, foldercounter, filename, year, doy, set |
|
772 | return fullpath, foldercounter, filename, year, doy, set | |
770 |
|
773 | |||
771 | def __setNextFileOffline(self): |
|
774 | def __setNextFileOffline(self): | |
772 |
|
775 | |||
773 | idFile = self.fileIndex |
|
776 | idFile = self.fileIndex | |
774 |
|
777 | |||
775 | while (True): |
|
778 | while (True): | |
776 | idFile += 1 |
|
779 | idFile += 1 | |
777 | if not(idFile < len(self.filenameList)): |
|
780 | if not(idFile < len(self.filenameList)): | |
778 | self.flagNoMoreFiles = 1 |
|
781 | self.flagNoMoreFiles = 1 | |
779 | # print "[Reading] No more Files" |
|
782 | # print "[Reading] No more Files" | |
780 | return 0 |
|
783 | return 0 | |
781 |
|
784 | |||
782 | filename = self.filenameList[idFile] |
|
785 | filename = self.filenameList[idFile] | |
783 |
|
786 | |||
784 | if not(self.__verifyFile(filename)): |
|
787 | if not(self.__verifyFile(filename)): | |
785 | continue |
|
788 | continue | |
786 |
|
789 | |||
787 | fileSize = os.path.getsize(filename) |
|
790 | fileSize = os.path.getsize(filename) | |
788 | fp = open(filename, 'rb') |
|
791 | fp = open(filename, 'rb') | |
789 | break |
|
792 | break | |
790 |
|
793 | |||
791 | self.flagIsNewFile = 1 |
|
794 | self.flagIsNewFile = 1 | |
792 | self.fileIndex = idFile |
|
795 | self.fileIndex = idFile | |
793 | self.filename = filename |
|
796 | self.filename = filename | |
794 | self.fileSize = fileSize |
|
797 | self.fileSize = fileSize | |
795 | self.fp = fp |
|
798 | self.fp = fp | |
796 |
|
799 | |||
797 | # print "[Reading] Setting the file: %s"%self.filename |
|
800 | # print "[Reading] Setting the file: %s"%self.filename | |
798 |
|
801 | |||
799 | return 1 |
|
802 | return 1 | |
800 |
|
803 | |||
801 | def __setNextFileOnline(self): |
|
804 | def __setNextFileOnline(self): | |
802 | """ |
|
805 | """ | |
803 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
806 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
804 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
807 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
805 | siguientes. |
|
808 | siguientes. | |
806 |
|
809 | |||
807 | Affected: |
|
810 | Affected: | |
808 | self.flagIsNewFile |
|
811 | self.flagIsNewFile | |
809 | self.filename |
|
812 | self.filename | |
810 | self.fileSize |
|
813 | self.fileSize | |
811 | self.fp |
|
814 | self.fp | |
812 | self.set |
|
815 | self.set | |
813 | self.flagNoMoreFiles |
|
816 | self.flagNoMoreFiles | |
814 |
|
817 | |||
815 | Return: |
|
818 | Return: | |
816 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
819 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
817 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
820 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
818 |
|
821 | |||
819 | Excepciones: |
|
822 | Excepciones: | |
820 | Si un determinado file no puede ser abierto |
|
823 | Si un determinado file no puede ser abierto | |
821 | """ |
|
824 | """ | |
822 | nFiles = 0 |
|
825 | nFiles = 0 | |
823 | fileOk_flag = False |
|
826 | fileOk_flag = False | |
824 | firstTime_flag = True |
|
827 | firstTime_flag = True | |
825 |
|
828 | |||
826 | self.set += 1 |
|
829 | self.set += 1 | |
827 |
|
830 | |||
828 | if self.set > 999: |
|
831 | if self.set > 999: | |
829 | self.set = 0 |
|
832 | self.set = 0 | |
830 | self.foldercounter += 1 |
|
833 | self.foldercounter += 1 | |
831 |
|
834 | |||
832 | # busca el 1er file disponible |
|
835 | # busca el 1er file disponible | |
833 | fullfilename, filename = checkForRealPath( |
|
836 | fullfilename, filename = checkForRealPath( | |
834 | self.path, self.foldercounter, self.year, self.doy, self.set, self.ext) |
|
837 | self.path, self.foldercounter, self.year, self.doy, self.set, self.ext) | |
835 | if fullfilename: |
|
838 | if fullfilename: | |
836 | if self.__verifyFile(fullfilename, False): |
|
839 | if self.__verifyFile(fullfilename, False): | |
837 | fileOk_flag = True |
|
840 | fileOk_flag = True | |
838 |
|
841 | |||
839 | # si no encuentra un file entonces espera y vuelve a buscar |
|
842 | # si no encuentra un file entonces espera y vuelve a buscar | |
840 | if not(fileOk_flag): |
|
843 | if not(fileOk_flag): | |
841 | # busco en los siguientes self.nFiles+1 files posibles |
|
844 | # busco en los siguientes self.nFiles+1 files posibles | |
842 | for nFiles in range(self.nFiles + 1): |
|
845 | for nFiles in range(self.nFiles + 1): | |
843 |
|
846 | |||
844 | if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces |
|
847 | if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces | |
845 | tries = self.nTries |
|
848 | tries = self.nTries | |
846 | else: |
|
849 | else: | |
847 | tries = 1 # si no es la 1era vez entonces solo lo hace una vez |
|
850 | tries = 1 # si no es la 1era vez entonces solo lo hace una vez | |
848 |
|
851 | |||
849 | for nTries in range(tries): |
|
852 | for nTries in range(tries): | |
850 | if firstTime_flag: |
|
853 | if firstTime_flag: | |
851 | print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1) |
|
854 | print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1) | |
852 | sleep(self.delay) |
|
855 | sleep(self.delay) | |
853 | else: |
|
856 | else: | |
854 | print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
857 | print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
855 |
|
858 | |||
856 | fullfilename, filename = checkForRealPath( |
|
859 | fullfilename, filename = checkForRealPath( | |
857 | self.path, self.foldercounter, self.year, self.doy, self.set, self.ext) |
|
860 | self.path, self.foldercounter, self.year, self.doy, self.set, self.ext) | |
858 | if fullfilename: |
|
861 | if fullfilename: | |
859 | if self.__verifyFile(fullfilename): |
|
862 | if self.__verifyFile(fullfilename): | |
860 | fileOk_flag = True |
|
863 | fileOk_flag = True | |
861 | break |
|
864 | break | |
862 |
|
865 | |||
863 | if fileOk_flag: |
|
866 | if fileOk_flag: | |
864 | break |
|
867 | break | |
865 |
|
868 | |||
866 | firstTime_flag = False |
|
869 | firstTime_flag = False | |
867 |
|
870 | |||
868 | print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename |
|
871 | print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename | |
869 | self.set += 1 |
|
872 | self.set += 1 | |
870 |
|
873 | |||
871 | # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
874 | # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
872 | if nFiles == (self.nFiles - 1): |
|
875 | if nFiles == (self.nFiles - 1): | |
873 | self.set = 0 |
|
876 | self.set = 0 | |
874 | self.doy += 1 |
|
877 | self.doy += 1 | |
875 | self.foldercounter = 0 |
|
878 | self.foldercounter = 0 | |
876 |
|
879 | |||
877 | if fileOk_flag: |
|
880 | if fileOk_flag: | |
878 | self.fileSize = os.path.getsize(fullfilename) |
|
881 | self.fileSize = os.path.getsize(fullfilename) | |
879 | self.filename = fullfilename |
|
882 | self.filename = fullfilename | |
880 | self.flagIsNewFile = 1 |
|
883 | self.flagIsNewFile = 1 | |
881 | if self.fp != None: |
|
884 | if self.fp != None: | |
882 | self.fp.close() |
|
885 | self.fp.close() | |
883 | self.fp = open(fullfilename, 'rb') |
|
886 | self.fp = open(fullfilename, 'rb') | |
884 | self.flagNoMoreFiles = 0 |
|
887 | self.flagNoMoreFiles = 0 | |
885 | # print '[Reading] Setting the file: %s' % fullfilename |
|
888 | # print '[Reading] Setting the file: %s' % fullfilename | |
886 | else: |
|
889 | else: | |
887 | self.fileSize = 0 |
|
890 | self.fileSize = 0 | |
888 | self.filename = None |
|
891 | self.filename = None | |
889 | self.flagIsNewFile = 0 |
|
892 | self.flagIsNewFile = 0 | |
890 | self.fp = None |
|
893 | self.fp = None | |
891 | self.flagNoMoreFiles = 1 |
|
894 | self.flagNoMoreFiles = 1 | |
892 | # print '[Reading] No more files to read' |
|
895 | # print '[Reading] No more files to read' | |
893 |
|
896 | |||
894 | return fileOk_flag |
|
897 | return fileOk_flag | |
895 |
|
898 | |||
896 | def setNextFile(self): |
|
899 | def setNextFile(self): | |
897 | if self.fp != None: |
|
900 | if self.fp != None: | |
898 | self.fp.close() |
|
901 | self.fp.close() | |
899 |
|
902 | |||
900 | if self.online: |
|
903 | if self.online: | |
901 | newFile = self.__setNextFileOnline() |
|
904 | newFile = self.__setNextFileOnline() | |
902 | else: |
|
905 | else: | |
903 | newFile = self.__setNextFileOffline() |
|
906 | newFile = self.__setNextFileOffline() | |
904 |
|
907 | |||
905 | if not(newFile): |
|
908 | if not(newFile): | |
906 | print '[Reading] No more files to read' |
|
909 | print '[Reading] No more files to read' | |
907 | return 0 |
|
910 | return 0 | |
908 |
|
911 | |||
909 | if self.verbose: |
|
912 | if self.verbose: | |
910 | print '[Reading] Setting the file: %s' % self.filename |
|
913 | print '[Reading] Setting the file: %s' % self.filename | |
911 |
|
914 | |||
912 | self.__readFirstHeader() |
|
915 | self.__readFirstHeader() | |
913 | self.nReadBlocks = 0 |
|
916 | self.nReadBlocks = 0 | |
914 | return 1 |
|
917 | return 1 | |
915 |
|
918 | |||
916 | def __waitNewBlock(self): |
|
919 | def __waitNewBlock(self): | |
917 | """ |
|
920 | """ | |
918 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
921 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
919 |
|
922 | |||
920 | Si el modo de lectura es OffLine siempre retorn 0 |
|
923 | Si el modo de lectura es OffLine siempre retorn 0 | |
921 | """ |
|
924 | """ | |
922 | if not self.online: |
|
925 | if not self.online: | |
923 | return 0 |
|
926 | return 0 | |
924 |
|
927 | |||
925 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
928 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |
926 | return 0 |
|
929 | return 0 | |
927 |
|
930 | |||
928 | currentPointer = self.fp.tell() |
|
931 | currentPointer = self.fp.tell() | |
929 |
|
932 | |||
930 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
933 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
931 |
|
934 | |||
932 | for nTries in range(self.nTries): |
|
935 | for nTries in range(self.nTries): | |
933 |
|
936 | |||
934 | self.fp.close() |
|
937 | self.fp.close() | |
935 | self.fp = open(self.filename, 'rb') |
|
938 | self.fp = open(self.filename, 'rb') | |
936 | self.fp.seek(currentPointer) |
|
939 | self.fp.seek(currentPointer) | |
937 |
|
940 | |||
938 | self.fileSize = os.path.getsize(self.filename) |
|
941 | self.fileSize = os.path.getsize(self.filename) | |
939 | currentSize = self.fileSize - currentPointer |
|
942 | currentSize = self.fileSize - currentPointer | |
940 |
|
943 | |||
941 | if (currentSize >= neededSize): |
|
944 | if (currentSize >= neededSize): | |
942 | self.basicHeaderObj.read(self.fp) |
|
945 | self.basicHeaderObj.read(self.fp) | |
943 | return 1 |
|
946 | return 1 | |
944 |
|
947 | |||
945 | if self.fileSize == self.fileSizeByHeader: |
|
948 | if self.fileSize == self.fileSizeByHeader: | |
946 | # self.flagEoF = True |
|
949 | # self.flagEoF = True | |
947 | return 0 |
|
950 | return 0 | |
948 |
|
951 | |||
949 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1) |
|
952 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1) | |
950 | sleep(self.delay) |
|
953 | sleep(self.delay) | |
951 |
|
954 | |||
952 | return 0 |
|
955 | return 0 | |
953 |
|
956 | |||
954 | def waitDataBlock(self, pointer_location): |
|
957 | def waitDataBlock(self, pointer_location): | |
955 |
|
958 | |||
956 | currentPointer = pointer_location |
|
959 | currentPointer = pointer_location | |
957 |
|
960 | |||
958 | neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize |
|
961 | neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize | |
959 |
|
962 | |||
960 | for nTries in range(self.nTries): |
|
963 | for nTries in range(self.nTries): | |
961 | self.fp.close() |
|
964 | self.fp.close() | |
962 | self.fp = open(self.filename, 'rb') |
|
965 | self.fp = open(self.filename, 'rb') | |
963 | self.fp.seek(currentPointer) |
|
966 | self.fp.seek(currentPointer) | |
964 |
|
967 | |||
965 | self.fileSize = os.path.getsize(self.filename) |
|
968 | self.fileSize = os.path.getsize(self.filename) | |
966 | currentSize = self.fileSize - currentPointer |
|
969 | currentSize = self.fileSize - currentPointer | |
967 |
|
970 | |||
968 | if (currentSize >= neededSize): |
|
971 | if (currentSize >= neededSize): | |
969 | return 1 |
|
972 | return 1 | |
970 |
|
973 | |||
971 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1) |
|
974 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1) | |
972 | sleep(self.delay) |
|
975 | sleep(self.delay) | |
973 |
|
976 | |||
974 | return 0 |
|
977 | return 0 | |
975 |
|
978 | |||
976 | def __jumpToLastBlock(self): |
|
979 | def __jumpToLastBlock(self): | |
977 |
|
980 | |||
978 | if not(self.__isFirstTimeOnline): |
|
981 | if not(self.__isFirstTimeOnline): | |
979 | return |
|
982 | return | |
980 |
|
983 | |||
981 | csize = self.fileSize - self.fp.tell() |
|
984 | csize = self.fileSize - self.fp.tell() | |
982 | blocksize = self.processingHeaderObj.blockSize |
|
985 | blocksize = self.processingHeaderObj.blockSize | |
983 |
|
986 | |||
984 | # salta el primer bloque de datos |
|
987 | # salta el primer bloque de datos | |
985 | if csize > self.processingHeaderObj.blockSize: |
|
988 | if csize > self.processingHeaderObj.blockSize: | |
986 | self.fp.seek(self.fp.tell() + blocksize) |
|
989 | self.fp.seek(self.fp.tell() + blocksize) | |
987 | else: |
|
990 | else: | |
988 | return |
|
991 | return | |
989 |
|
992 | |||
990 | csize = self.fileSize - self.fp.tell() |
|
993 | csize = self.fileSize - self.fp.tell() | |
991 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
994 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
992 | while True: |
|
995 | while True: | |
993 |
|
996 | |||
994 | if self.fp.tell() < self.fileSize: |
|
997 | if self.fp.tell() < self.fileSize: | |
995 | self.fp.seek(self.fp.tell() + neededsize) |
|
998 | self.fp.seek(self.fp.tell() + neededsize) | |
996 | else: |
|
999 | else: | |
997 | self.fp.seek(self.fp.tell() - neededsize) |
|
1000 | self.fp.seek(self.fp.tell() - neededsize) | |
998 | break |
|
1001 | break | |
999 |
|
1002 | |||
1000 | # csize = self.fileSize - self.fp.tell() |
|
1003 | # csize = self.fileSize - self.fp.tell() | |
1001 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
1004 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
1002 | # factor = int(csize/neededsize) |
|
1005 | # factor = int(csize/neededsize) | |
1003 | # if factor > 0: |
|
1006 | # if factor > 0: | |
1004 | # self.fp.seek(self.fp.tell() + factor*neededsize) |
|
1007 | # self.fp.seek(self.fp.tell() + factor*neededsize) | |
1005 |
|
1008 | |||
1006 | self.flagIsNewFile = 0 |
|
1009 | self.flagIsNewFile = 0 | |
1007 | self.__isFirstTimeOnline = 0 |
|
1010 | self.__isFirstTimeOnline = 0 | |
1008 |
|
1011 | |||
1009 | def __setNewBlock(self): |
|
1012 | def __setNewBlock(self): | |
1010 | # if self.server is None: |
|
1013 | # if self.server is None: | |
1011 | if self.fp == None: |
|
1014 | if self.fp == None: | |
1012 | return 0 |
|
1015 | return 0 | |
1013 |
|
1016 | |||
1014 | # if self.online: |
|
1017 | # if self.online: | |
1015 | # self.__jumpToLastBlock() |
|
1018 | # self.__jumpToLastBlock() | |
1016 |
|
1019 | |||
1017 | if self.flagIsNewFile: |
|
1020 | if self.flagIsNewFile: | |
1018 | self.lastUTTime = self.basicHeaderObj.utc |
|
1021 | self.lastUTTime = self.basicHeaderObj.utc | |
1019 | return 1 |
|
1022 | return 1 | |
1020 |
|
1023 | |||
1021 | if self.realtime: |
|
1024 | if self.realtime: | |
1022 | self.flagDiscontinuousBlock = 1 |
|
1025 | self.flagDiscontinuousBlock = 1 | |
1023 | if not(self.setNextFile()): |
|
1026 | if not(self.setNextFile()): | |
1024 | return 0 |
|
1027 | return 0 | |
1025 | else: |
|
1028 | else: | |
1026 | return 1 |
|
1029 | return 1 | |
1027 | # if self.server is None: |
|
1030 | # if self.server is None: | |
1028 | currentSize = self.fileSize - self.fp.tell() |
|
1031 | currentSize = self.fileSize - self.fp.tell() | |
1029 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
1032 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
1030 | if (currentSize >= neededSize): |
|
1033 | if (currentSize >= neededSize): | |
1031 | self.basicHeaderObj.read(self.fp) |
|
1034 | self.basicHeaderObj.read(self.fp) | |
1032 | self.lastUTTime = self.basicHeaderObj.utc |
|
1035 | self.lastUTTime = self.basicHeaderObj.utc | |
1033 | return 1 |
|
1036 | return 1 | |
1034 | # else: |
|
1037 | # else: | |
1035 | # self.basicHeaderObj.read(self.zHeader) |
|
1038 | # self.basicHeaderObj.read(self.zHeader) | |
1036 | # self.lastUTTime = self.basicHeaderObj.utc |
|
1039 | # self.lastUTTime = self.basicHeaderObj.utc | |
1037 | # return 1 |
|
1040 | # return 1 | |
1038 | if self.__waitNewBlock(): |
|
1041 | if self.__waitNewBlock(): | |
1039 | self.lastUTTime = self.basicHeaderObj.utc |
|
1042 | self.lastUTTime = self.basicHeaderObj.utc | |
1040 | return 1 |
|
1043 | return 1 | |
1041 | # if self.server is None: |
|
1044 | # if self.server is None: | |
1042 | if not(self.setNextFile()): |
|
1045 | if not(self.setNextFile()): | |
1043 | return 0 |
|
1046 | return 0 | |
1044 |
|
1047 | |||
1045 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime |
|
1048 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime | |
1046 | self.lastUTTime = self.basicHeaderObj.utc |
|
1049 | self.lastUTTime = self.basicHeaderObj.utc | |
1047 |
|
1050 | |||
1048 | self.flagDiscontinuousBlock = 0 |
|
1051 | self.flagDiscontinuousBlock = 0 | |
1049 |
|
1052 | |||
1050 | if deltaTime > self.maxTimeStep: |
|
1053 | if deltaTime > self.maxTimeStep: | |
1051 | self.flagDiscontinuousBlock = 1 |
|
1054 | self.flagDiscontinuousBlock = 1 | |
1052 |
|
1055 | |||
1053 | return 1 |
|
1056 | return 1 | |
1054 |
|
1057 | |||
1055 | def readNextBlock(self): |
|
1058 | def readNextBlock(self): | |
1056 |
|
1059 | |||
1057 | # Skip block out of startTime and endTime |
|
1060 | # Skip block out of startTime and endTime | |
1058 | while True: |
|
1061 | while True: | |
1059 | if not(self.__setNewBlock()): |
|
1062 | if not(self.__setNewBlock()): | |
1060 | return 0 |
|
1063 | return 0 | |
1061 |
|
1064 | |||
1062 | if not(self.readBlock()): |
|
1065 | if not(self.readBlock()): | |
1063 | return 0 |
|
1066 | return 0 | |
1064 |
|
1067 | |||
1065 | self.getBasicHeader() |
|
1068 | self.getBasicHeader() | |
1066 | if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)): |
|
1069 | if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)): | |
1067 | print "[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks, |
|
1070 | print "[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks, | |
1068 | self.processingHeaderObj.dataBlocksPerFile, |
|
1071 | self.processingHeaderObj.dataBlocksPerFile, | |
1069 | self.dataOut.datatime.ctime()) |
|
1072 | self.dataOut.datatime.ctime()) | |
1070 | continue |
|
1073 | continue | |
1071 |
|
1074 | |||
1072 | break |
|
1075 | break | |
1073 |
|
1076 | |||
1074 | if self.verbose: |
|
1077 | if self.verbose: | |
1075 | print "[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks, |
|
1078 | print "[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks, | |
1076 | self.processingHeaderObj.dataBlocksPerFile, |
|
1079 | self.processingHeaderObj.dataBlocksPerFile, | |
1077 | self.dataOut.datatime.ctime()) |
|
1080 | self.dataOut.datatime.ctime()) | |
1078 | return 1 |
|
1081 | return 1 | |
1079 |
|
1082 | |||
1080 | def __readFirstHeader(self): |
|
1083 | def __readFirstHeader(self): | |
1081 |
|
1084 | |||
1082 | self.basicHeaderObj.read(self.fp) |
|
1085 | self.basicHeaderObj.read(self.fp) | |
1083 | self.systemHeaderObj.read(self.fp) |
|
1086 | self.systemHeaderObj.read(self.fp) | |
1084 | self.radarControllerHeaderObj.read(self.fp) |
|
1087 | self.radarControllerHeaderObj.read(self.fp) | |
1085 | self.processingHeaderObj.read(self.fp) |
|
1088 | self.processingHeaderObj.read(self.fp) | |
1086 |
|
1089 | |||
1087 | self.firstHeaderSize = self.basicHeaderObj.size |
|
1090 | self.firstHeaderSize = self.basicHeaderObj.size | |
1088 |
|
1091 | |||
1089 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & |
|
1092 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & | |
1090 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
1093 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
1091 | if datatype == 0: |
|
1094 | if datatype == 0: | |
1092 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) |
|
1095 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
1093 | elif datatype == 1: |
|
1096 | elif datatype == 1: | |
1094 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) |
|
1097 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
1095 | elif datatype == 2: |
|
1098 | elif datatype == 2: | |
1096 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) |
|
1099 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
1097 | elif datatype == 3: |
|
1100 | elif datatype == 3: | |
1098 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) |
|
1101 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
1099 | elif datatype == 4: |
|
1102 | elif datatype == 4: | |
1100 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) |
|
1103 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
1101 | elif datatype == 5: |
|
1104 | elif datatype == 5: | |
1102 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) |
|
1105 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
1103 | else: |
|
1106 | else: | |
1104 | raise ValueError, 'Data type was not defined' |
|
1107 | raise ValueError, 'Data type was not defined' | |
1105 |
|
1108 | |||
1106 | self.dtype = datatype_str |
|
1109 | self.dtype = datatype_str | |
1107 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
1110 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
1108 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \ |
|
1111 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \ | |
1109 | self.firstHeaderSize + self.basicHeaderSize * \ |
|
1112 | self.firstHeaderSize + self.basicHeaderSize * \ | |
1110 | (self.processingHeaderObj.dataBlocksPerFile - 1) |
|
1113 | (self.processingHeaderObj.dataBlocksPerFile - 1) | |
1111 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
1114 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
1112 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
1115 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
1113 | self.getBlockDimension() |
|
1116 | self.getBlockDimension() | |
1114 |
|
1117 | |||
1115 | def __verifyFile(self, filename, msgFlag=True): |
|
1118 | def __verifyFile(self, filename, msgFlag=True): | |
1116 |
|
1119 | |||
1117 | msg = None |
|
1120 | msg = None | |
1118 |
|
1121 | |||
1119 | try: |
|
1122 | try: | |
1120 | fp = open(filename, 'rb') |
|
1123 | fp = open(filename, 'rb') | |
1121 | except IOError: |
|
1124 | except IOError: | |
1122 |
|
1125 | |||
1123 | if msgFlag: |
|
1126 | if msgFlag: | |
1124 | print "[Reading] File %s can't be opened" % (filename) |
|
1127 | print "[Reading] File %s can't be opened" % (filename) | |
1125 |
|
1128 | |||
1126 | return False |
|
1129 | return False | |
1127 |
|
1130 | |||
1128 | currentPosition = fp.tell() |
|
1131 | currentPosition = fp.tell() | |
1129 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
1132 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
1130 |
|
1133 | |||
1131 | if neededSize == 0: |
|
1134 | if neededSize == 0: | |
1132 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
1135 | basicHeaderObj = BasicHeader(LOCALTIME) | |
1133 | systemHeaderObj = SystemHeader() |
|
1136 | systemHeaderObj = SystemHeader() | |
1134 | radarControllerHeaderObj = RadarControllerHeader() |
|
1137 | radarControllerHeaderObj = RadarControllerHeader() | |
1135 | processingHeaderObj = ProcessingHeader() |
|
1138 | processingHeaderObj = ProcessingHeader() | |
1136 |
|
1139 | |||
1137 | if not(basicHeaderObj.read(fp)): |
|
1140 | if not(basicHeaderObj.read(fp)): | |
1138 | fp.close() |
|
1141 | fp.close() | |
1139 | return False |
|
1142 | return False | |
1140 |
|
1143 | |||
1141 | if not(systemHeaderObj.read(fp)): |
|
1144 | if not(systemHeaderObj.read(fp)): | |
1142 | fp.close() |
|
1145 | fp.close() | |
1143 | return False |
|
1146 | return False | |
1144 |
|
1147 | |||
1145 | if not(radarControllerHeaderObj.read(fp)): |
|
1148 | if not(radarControllerHeaderObj.read(fp)): | |
1146 | fp.close() |
|
1149 | fp.close() | |
1147 | return False |
|
1150 | return False | |
1148 |
|
1151 | |||
1149 | if not(processingHeaderObj.read(fp)): |
|
1152 | if not(processingHeaderObj.read(fp)): | |
1150 | fp.close() |
|
1153 | fp.close() | |
1151 | return False |
|
1154 | return False | |
1152 |
|
1155 | |||
1153 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
1156 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
1154 | else: |
|
1157 | else: | |
1155 | msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename |
|
1158 | msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename | |
1156 |
|
1159 | |||
1157 | fp.close() |
|
1160 | fp.close() | |
1158 |
|
1161 | |||
1159 | fileSize = os.path.getsize(filename) |
|
1162 | fileSize = os.path.getsize(filename) | |
1160 | currentSize = fileSize - currentPosition |
|
1163 | currentSize = fileSize - currentPosition | |
1161 |
|
1164 | |||
1162 | if currentSize < neededSize: |
|
1165 | if currentSize < neededSize: | |
1163 | if msgFlag and (msg != None): |
|
1166 | if msgFlag and (msg != None): | |
1164 | print msg |
|
1167 | print msg | |
1165 | return False |
|
1168 | return False | |
1166 |
|
1169 | |||
1167 | return True |
|
1170 | return True | |
1168 |
|
1171 | |||
1169 | def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False): |
|
1172 | def findDatafiles(self, path, startDate=None, endDate=None, expLabel='', ext='.r', walk=True, include_path=False): | |
1170 |
|
1173 | |||
1171 | path_empty = True |
|
1174 | path_empty = True | |
1172 |
|
1175 | |||
1173 | dateList = [] |
|
1176 | dateList = [] | |
1174 | pathList = [] |
|
1177 | pathList = [] | |
1175 |
|
1178 | |||
1176 | multi_path = path.split(',') |
|
1179 | multi_path = path.split(',') | |
1177 |
|
1180 | |||
1178 | if not walk: |
|
1181 | if not walk: | |
1179 |
|
1182 | |||
1180 | for single_path in multi_path: |
|
1183 | for single_path in multi_path: | |
1181 |
|
1184 | |||
1182 | if not os.path.isdir(single_path): |
|
1185 | if not os.path.isdir(single_path): | |
1183 | continue |
|
1186 | continue | |
1184 |
|
1187 | |||
1185 | fileList = glob.glob1(single_path, "*" + ext) |
|
1188 | fileList = glob.glob1(single_path, "*" + ext) | |
1186 |
|
1189 | |||
1187 | if not fileList: |
|
1190 | if not fileList: | |
1188 | continue |
|
1191 | continue | |
1189 |
|
1192 | |||
1190 | path_empty = False |
|
1193 | path_empty = False | |
1191 |
|
1194 | |||
1192 | fileList.sort() |
|
1195 | fileList.sort() | |
1193 |
|
1196 | |||
1194 | for thisFile in fileList: |
|
1197 | for thisFile in fileList: | |
1195 |
|
1198 | |||
1196 | if not os.path.isfile(os.path.join(single_path, thisFile)): |
|
1199 | if not os.path.isfile(os.path.join(single_path, thisFile)): | |
1197 | continue |
|
1200 | continue | |
1198 |
|
1201 | |||
1199 | if not isRadarFile(thisFile): |
|
1202 | if not isRadarFile(thisFile): | |
1200 | continue |
|
1203 | continue | |
1201 |
|
1204 | |||
1202 | if not isFileInDateRange(thisFile, startDate, endDate): |
|
1205 | if not isFileInDateRange(thisFile, startDate, endDate): | |
1203 | continue |
|
1206 | continue | |
1204 |
|
1207 | |||
1205 | thisDate = getDateFromRadarFile(thisFile) |
|
1208 | thisDate = getDateFromRadarFile(thisFile) | |
1206 |
|
1209 | |||
1207 | if thisDate in dateList: |
|
1210 | if thisDate in dateList: | |
1208 | continue |
|
1211 | continue | |
1209 |
|
1212 | |||
1210 | dateList.append(thisDate) |
|
1213 | dateList.append(thisDate) | |
1211 | pathList.append(single_path) |
|
1214 | pathList.append(single_path) | |
1212 |
|
1215 | |||
1213 | else: |
|
1216 | else: | |
1214 | for single_path in multi_path: |
|
1217 | for single_path in multi_path: | |
1215 |
|
1218 | |||
1216 | if not os.path.isdir(single_path): |
|
1219 | if not os.path.isdir(single_path): | |
1217 | continue |
|
1220 | continue | |
1218 |
|
1221 | |||
1219 | dirList = [] |
|
1222 | dirList = [] | |
1220 |
|
1223 | |||
1221 | for thisPath in os.listdir(single_path): |
|
1224 | for thisPath in os.listdir(single_path): | |
1222 |
|
1225 | |||
1223 | if not os.path.isdir(os.path.join(single_path, thisPath)): |
|
1226 | if not os.path.isdir(os.path.join(single_path, thisPath)): | |
1224 | continue |
|
1227 | continue | |
1225 |
|
1228 | |||
1226 | if not isRadarFolder(thisPath): |
|
1229 | if not isRadarFolder(thisPath): | |
1227 | continue |
|
1230 | continue | |
1228 |
|
1231 | |||
1229 | if not isFolderInDateRange(thisPath, startDate, endDate): |
|
1232 | if not isFolderInDateRange(thisPath, startDate, endDate): | |
1230 | continue |
|
1233 | continue | |
1231 |
|
1234 | |||
1232 | dirList.append(thisPath) |
|
1235 | dirList.append(thisPath) | |
1233 |
|
1236 | |||
1234 | if not dirList: |
|
1237 | if not dirList: | |
1235 | continue |
|
1238 | continue | |
1236 |
|
1239 | |||
1237 | dirList.sort() |
|
1240 | dirList.sort() | |
1238 |
|
1241 | |||
1239 | for thisDir in dirList: |
|
1242 | for thisDir in dirList: | |
1240 |
|
1243 | |||
1241 | datapath = os.path.join(single_path, thisDir, expLabel) |
|
1244 | datapath = os.path.join(single_path, thisDir, expLabel) | |
1242 | fileList = glob.glob1(datapath, "*" + ext) |
|
1245 | fileList = glob.glob1(datapath, "*" + ext) | |
1243 |
|
1246 | |||
1244 | if not fileList: |
|
1247 | if not fileList: | |
1245 | continue |
|
1248 | continue | |
1246 |
|
1249 | |||
1247 | path_empty = False |
|
1250 | path_empty = False | |
1248 |
|
1251 | |||
1249 | thisDate = getDateFromRadarFolder(thisDir) |
|
1252 | thisDate = getDateFromRadarFolder(thisDir) | |
1250 |
|
1253 | |||
1251 | pathList.append(datapath) |
|
1254 | pathList.append(datapath) | |
1252 | dateList.append(thisDate) |
|
1255 | dateList.append(thisDate) | |
1253 |
|
1256 | |||
1254 | dateList.sort() |
|
1257 | dateList.sort() | |
1255 |
|
1258 | |||
1256 | if walk: |
|
1259 | if walk: | |
1257 | pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel) |
|
1260 | pattern_path = os.path.join(multi_path[0], "[dYYYYDDD]", expLabel) | |
1258 | else: |
|
1261 | else: | |
1259 | pattern_path = multi_path[0] |
|
1262 | pattern_path = multi_path[0] | |
1260 |
|
1263 | |||
1261 | if path_empty: |
|
1264 | if path_empty: | |
1262 | print "[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate) |
|
1265 | print "[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate) | |
1263 | else: |
|
1266 | else: | |
1264 | if not dateList: |
|
1267 | if not dateList: | |
1265 | print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path) |
|
1268 | print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path) | |
1266 |
|
1269 | |||
1267 | if include_path: |
|
1270 | if include_path: | |
1268 | return dateList, pathList |
|
1271 | return dateList, pathList | |
1269 |
|
1272 | |||
1270 | return dateList |
|
1273 | return dateList | |
1271 |
|
1274 | |||
1272 | def setup(self, |
|
1275 | def setup(self, | |
1273 | path=None, |
|
1276 | path=None, | |
1274 | startDate=None, |
|
1277 | startDate=None, | |
1275 | endDate=None, |
|
1278 | endDate=None, | |
1276 | startTime=datetime.time(0, 0, 0), |
|
1279 | startTime=datetime.time(0, 0, 0), | |
1277 | endTime=datetime.time(23, 59, 59), |
|
1280 | endTime=datetime.time(23, 59, 59), | |
1278 | set=None, |
|
1281 | set=None, | |
1279 | expLabel="", |
|
1282 | expLabel="", | |
1280 | ext=None, |
|
1283 | ext=None, | |
1281 | online=False, |
|
1284 | online=False, | |
1282 | delay=60, |
|
1285 | delay=60, | |
1283 | walk=True, |
|
1286 | walk=True, | |
1284 | getblock=False, |
|
1287 | getblock=False, | |
1285 | nTxs=1, |
|
1288 | nTxs=1, | |
1286 | realtime=False, |
|
1289 | realtime=False, | |
1287 | blocksize=None, |
|
1290 | blocksize=None, | |
1288 | blocktime=None, |
|
1291 | blocktime=None, | |
1289 | skip=None, |
|
1292 | skip=None, | |
1290 | cursor=None, |
|
1293 | cursor=None, | |
1291 | warnings=True, |
|
1294 | warnings=True, | |
1292 | verbose=True, |
|
1295 | verbose=True, | |
1293 | server=None, |
|
1296 | server=None, | |
1294 | format=None, |
|
1297 | format=None, | |
1295 | oneDDict=None, |
|
1298 | oneDDict=None, | |
1296 | twoDDict=None, |
|
1299 | twoDDict=None, | |
1297 | ind2DList=None): |
|
1300 | ind2DList=None): | |
1298 | if server is not None: |
|
1301 | if server is not None: | |
1299 | if 'tcp://' in server: |
|
1302 | if 'tcp://' in server: | |
1300 | address = server |
|
1303 | address = server | |
1301 | else: |
|
1304 | else: | |
1302 | address = 'ipc:///tmp/%s' % server |
|
1305 | address = 'ipc:///tmp/%s' % server | |
1303 | self.server = address |
|
1306 | self.server = address | |
1304 | self.context = zmq.Context() |
|
1307 | self.context = zmq.Context() | |
1305 | self.receiver = self.context.socket(zmq.PULL) |
|
1308 | self.receiver = self.context.socket(zmq.PULL) | |
1306 | self.receiver.connect(self.server) |
|
1309 | self.receiver.connect(self.server) | |
1307 | time.sleep(0.5) |
|
1310 | time.sleep(0.5) | |
1308 | print '[Starting] ReceiverData from {}'.format(self.server) |
|
1311 | print '[Starting] ReceiverData from {}'.format(self.server) | |
1309 | else: |
|
1312 | else: | |
1310 | self.server = None |
|
1313 | self.server = None | |
1311 | if path == None: |
|
1314 | if path == None: | |
1312 | raise ValueError, "[Reading] The path is not valid" |
|
1315 | raise ValueError, "[Reading] The path is not valid" | |
1313 |
|
1316 | |||
1314 | if ext == None: |
|
1317 | if ext == None: | |
1315 | ext = self.ext |
|
1318 | ext = self.ext | |
1316 |
|
1319 | |||
1317 | if online: |
|
1320 | if online: | |
1318 | print "[Reading] Searching files in online mode..." |
|
1321 | print "[Reading] Searching files in online mode..." | |
1319 |
|
1322 | |||
1320 | for nTries in range(self.nTries): |
|
1323 | for nTries in range(self.nTries): | |
1321 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine( |
|
1324 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine( | |
1322 | path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) |
|
1325 | path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) | |
1323 |
|
1326 | |||
1324 | if fullpath: |
|
1327 | if fullpath: | |
1325 | break |
|
1328 | break | |
1326 |
|
1329 | |||
1327 | print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1) |
|
1330 | print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1) | |
1328 | sleep(self.delay) |
|
1331 | sleep(self.delay) | |
1329 |
|
1332 | |||
1330 | if not(fullpath): |
|
1333 | if not(fullpath): | |
1331 | print "[Reading] There 'isn't any valid file in %s" % path |
|
1334 | print "[Reading] There 'isn't any valid file in %s" % path | |
1332 | return |
|
1335 | return | |
1333 |
|
1336 | |||
1334 | self.year = year |
|
1337 | self.year = year | |
1335 | self.doy = doy |
|
1338 | self.doy = doy | |
1336 | self.set = set - 1 |
|
1339 | self.set = set - 1 | |
1337 | self.path = path |
|
1340 | self.path = path | |
1338 | self.foldercounter = foldercounter |
|
1341 | self.foldercounter = foldercounter | |
1339 | last_set = None |
|
1342 | last_set = None | |
1340 | else: |
|
1343 | else: | |
1341 | print "[Reading] Searching files in offline mode ..." |
|
1344 | print "[Reading] Searching files in offline mode ..." | |
1342 | pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
1345 | pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
1343 | startTime=startTime, endTime=endTime, |
|
1346 | startTime=startTime, endTime=endTime, | |
1344 | set=set, expLabel=expLabel, ext=ext, |
|
1347 | set=set, expLabel=expLabel, ext=ext, | |
1345 | walk=walk, cursor=cursor, |
|
1348 | walk=walk, cursor=cursor, | |
1346 | skip=skip) |
|
1349 | skip=skip) | |
1347 |
|
1350 | |||
1348 | if not(pathList): |
|
1351 | if not(pathList): | |
1349 | self.fileIndex = -1 |
|
1352 | self.fileIndex = -1 | |
1350 | self.pathList = [] |
|
1353 | self.pathList = [] | |
1351 | self.filenameList = [] |
|
1354 | self.filenameList = [] | |
1352 | return |
|
1355 | return | |
1353 |
|
1356 | |||
1354 | self.fileIndex = -1 |
|
1357 | self.fileIndex = -1 | |
1355 | self.pathList = pathList |
|
1358 | self.pathList = pathList | |
1356 | self.filenameList = filenameList |
|
1359 | self.filenameList = filenameList | |
1357 | file_name = os.path.basename(filenameList[-1]) |
|
1360 | file_name = os.path.basename(filenameList[-1]) | |
1358 | basename, ext = os.path.splitext(file_name) |
|
1361 | basename, ext = os.path.splitext(file_name) | |
1359 | last_set = int(basename[-3:]) |
|
1362 | last_set = int(basename[-3:]) | |
1360 |
|
1363 | |||
1361 | self.online = online |
|
1364 | self.online = online | |
1362 | self.realtime = realtime |
|
1365 | self.realtime = realtime | |
1363 | self.delay = delay |
|
1366 | self.delay = delay | |
1364 | ext = ext.lower() |
|
1367 | ext = ext.lower() | |
1365 | self.ext = ext |
|
1368 | self.ext = ext | |
1366 | self.getByBlock = getblock |
|
1369 | self.getByBlock = getblock | |
1367 | self.nTxs = nTxs |
|
1370 | self.nTxs = nTxs | |
1368 | self.startTime = startTime |
|
1371 | self.startTime = startTime | |
1369 | self.endTime = endTime |
|
1372 | self.endTime = endTime | |
1370 | self.endDate = endDate |
|
1373 | self.endDate = endDate | |
1371 | self.startDate = startDate |
|
1374 | self.startDate = startDate | |
1372 | # Added----------------- |
|
1375 | # Added----------------- | |
1373 | self.selBlocksize = blocksize |
|
1376 | self.selBlocksize = blocksize | |
1374 | self.selBlocktime = blocktime |
|
1377 | self.selBlocktime = blocktime | |
1375 |
|
1378 | |||
1376 | # Verbose----------- |
|
1379 | # Verbose----------- | |
1377 | self.verbose = verbose |
|
1380 | self.verbose = verbose | |
1378 | self.warnings = warnings |
|
1381 | self.warnings = warnings | |
1379 |
|
1382 | |||
1380 | if not(self.setNextFile()): |
|
1383 | if not(self.setNextFile()): | |
1381 | if (startDate != None) and (endDate != None): |
|
1384 | if (startDate != None) and (endDate != None): | |
1382 | print "[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime()) |
|
1385 | print "[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime()) | |
1383 | elif startDate != None: |
|
1386 | elif startDate != None: | |
1384 | print "[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime()) |
|
1387 | print "[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime()) | |
1385 | else: |
|
1388 | else: | |
1386 | print "[Reading] No files" |
|
1389 | print "[Reading] No files" | |
1387 |
|
1390 | |||
1388 | self.fileIndex = -1 |
|
1391 | self.fileIndex = -1 | |
1389 | self.pathList = [] |
|
1392 | self.pathList = [] | |
1390 | self.filenameList = [] |
|
1393 | self.filenameList = [] | |
1391 | return |
|
1394 | return | |
1392 |
|
1395 | |||
1393 | # self.getBasicHeader() |
|
1396 | # self.getBasicHeader() | |
1394 |
|
1397 | |||
1395 | if last_set != None: |
|
1398 | if last_set != None: | |
1396 | self.dataOut.last_block = last_set * \ |
|
1399 | self.dataOut.last_block = last_set * \ | |
1397 | self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock |
|
1400 | self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock | |
1398 | return |
|
1401 | return | |
1399 |
|
1402 | |||
1400 | def getBasicHeader(self): |
|
1403 | def getBasicHeader(self): | |
1401 |
|
1404 | |||
1402 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ |
|
1405 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ | |
1403 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds |
|
1406 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds | |
1404 |
|
1407 | |||
1405 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
1408 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |
1406 |
|
1409 | |||
1407 | self.dataOut.timeZone = self.basicHeaderObj.timeZone |
|
1410 | self.dataOut.timeZone = self.basicHeaderObj.timeZone | |
1408 |
|
1411 | |||
1409 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag |
|
1412 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag | |
1410 |
|
1413 | |||
1411 | self.dataOut.errorCount = self.basicHeaderObj.errorCount |
|
1414 | self.dataOut.errorCount = self.basicHeaderObj.errorCount | |
1412 |
|
1415 | |||
1413 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime |
|
1416 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime | |
1414 |
|
1417 | |||
1415 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs |
|
1418 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |
1416 |
|
1419 | |||
1417 | # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
1420 | # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs | |
1418 |
|
1421 | |||
1419 | def getFirstHeader(self): |
|
1422 | def getFirstHeader(self): | |
1420 |
|
1423 | |||
1421 | raise NotImplementedError |
|
1424 | raise NotImplementedError | |
1422 |
|
1425 | |||
1423 | def getData(self): |
|
1426 | def getData(self): | |
1424 |
|
1427 | |||
1425 | raise NotImplementedError |
|
1428 | raise NotImplementedError | |
1426 |
|
1429 | |||
1427 | def hasNotDataInBuffer(self): |
|
1430 | def hasNotDataInBuffer(self): | |
1428 |
|
1431 | |||
1429 | raise NotImplementedError |
|
1432 | raise NotImplementedError | |
1430 |
|
1433 | |||
1431 | def readBlock(self): |
|
1434 | def readBlock(self): | |
1432 |
|
1435 | |||
1433 | raise NotImplementedError |
|
1436 | raise NotImplementedError | |
1434 |
|
1437 | |||
1435 | def isEndProcess(self): |
|
1438 | def isEndProcess(self): | |
1436 |
|
1439 | |||
1437 | return self.flagNoMoreFiles |
|
1440 | return self.flagNoMoreFiles | |
1438 |
|
1441 | |||
1439 | def printReadBlocks(self): |
|
1442 | def printReadBlocks(self): | |
1440 |
|
1443 | |||
1441 | print "[Reading] Number of read blocks per file %04d" % self.nReadBlocks |
|
1444 | print "[Reading] Number of read blocks per file %04d" % self.nReadBlocks | |
1442 |
|
1445 | |||
1443 | def printTotalBlocks(self): |
|
1446 | def printTotalBlocks(self): | |
1444 |
|
1447 | |||
1445 | print "[Reading] Number of read blocks %04d" % self.nTotalBlocks |
|
1448 | print "[Reading] Number of read blocks %04d" % self.nTotalBlocks | |
1446 |
|
1449 | |||
1447 | def printNumberOfBlock(self): |
|
1450 | def printNumberOfBlock(self): | |
1448 | 'SPAM!' |
|
1451 | 'SPAM!' | |
1449 |
|
1452 | |||
1450 | # if self.flagIsNewBlock: |
|
1453 | # if self.flagIsNewBlock: | |
1451 | # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks, |
|
1454 | # print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks, | |
1452 | # self.processingHeaderObj.dataBlocksPerFile, |
|
1455 | # self.processingHeaderObj.dataBlocksPerFile, | |
1453 | # self.dataOut.datatime.ctime()) |
|
1456 | # self.dataOut.datatime.ctime()) | |
1454 |
|
1457 | |||
1455 | def printInfo(self): |
|
1458 | def printInfo(self): | |
1456 |
|
1459 | |||
1457 | if self.__printInfo == False: |
|
1460 | if self.__printInfo == False: | |
1458 | return |
|
1461 | return | |
1459 |
|
1462 | |||
1460 | self.basicHeaderObj.printInfo() |
|
1463 | self.basicHeaderObj.printInfo() | |
1461 | self.systemHeaderObj.printInfo() |
|
1464 | self.systemHeaderObj.printInfo() | |
1462 | self.radarControllerHeaderObj.printInfo() |
|
1465 | self.radarControllerHeaderObj.printInfo() | |
1463 | self.processingHeaderObj.printInfo() |
|
1466 | self.processingHeaderObj.printInfo() | |
1464 |
|
1467 | |||
1465 | self.__printInfo = False |
|
1468 | self.__printInfo = False | |
1466 |
|
1469 | |||
1467 | def run(self, |
|
1470 | def run(self, | |
1468 | path=None, |
|
1471 | path=None, | |
1469 | startDate=None, |
|
1472 | startDate=None, | |
1470 | endDate=None, |
|
1473 | endDate=None, | |
1471 | startTime=datetime.time(0, 0, 0), |
|
1474 | startTime=datetime.time(0, 0, 0), | |
1472 | endTime=datetime.time(23, 59, 59), |
|
1475 | endTime=datetime.time(23, 59, 59), | |
1473 | set=None, |
|
1476 | set=None, | |
1474 | expLabel="", |
|
1477 | expLabel="", | |
1475 | ext=None, |
|
1478 | ext=None, | |
1476 | online=False, |
|
1479 | online=False, | |
1477 | delay=60, |
|
1480 | delay=60, | |
1478 | walk=True, |
|
1481 | walk=True, | |
1479 | getblock=False, |
|
1482 | getblock=False, | |
1480 | nTxs=1, |
|
1483 | nTxs=1, | |
1481 | realtime=False, |
|
1484 | realtime=False, | |
1482 | blocksize=None, |
|
1485 | blocksize=None, | |
1483 | blocktime=None, |
|
1486 | blocktime=None, | |
1484 | skip=None, |
|
1487 | skip=None, | |
1485 | cursor=None, |
|
1488 | cursor=None, | |
1486 | warnings=True, |
|
1489 | warnings=True, | |
1487 | server=None, |
|
1490 | server=None, | |
1488 | verbose=True, |
|
1491 | verbose=True, | |
1489 | format=None, |
|
1492 | format=None, | |
1490 | oneDDict=None, |
|
1493 | oneDDict=None, | |
1491 | twoDDict=None, |
|
1494 | twoDDict=None, | |
1492 | ind2DList=None, **kwargs): |
|
1495 | ind2DList=None, **kwargs): | |
1493 |
|
1496 | |||
1494 | if not(self.isConfig): |
|
1497 | if not(self.isConfig): | |
1495 | self.setup(path=path, |
|
1498 | self.setup(path=path, | |
1496 | startDate=startDate, |
|
1499 | startDate=startDate, | |
1497 | endDate=endDate, |
|
1500 | endDate=endDate, | |
1498 | startTime=startTime, |
|
1501 | startTime=startTime, | |
1499 | endTime=endTime, |
|
1502 | endTime=endTime, | |
1500 | set=set, |
|
1503 | set=set, | |
1501 | expLabel=expLabel, |
|
1504 | expLabel=expLabel, | |
1502 | ext=ext, |
|
1505 | ext=ext, | |
1503 | online=online, |
|
1506 | online=online, | |
1504 | delay=delay, |
|
1507 | delay=delay, | |
1505 | walk=walk, |
|
1508 | walk=walk, | |
1506 | getblock=getblock, |
|
1509 | getblock=getblock, | |
1507 | nTxs=nTxs, |
|
1510 | nTxs=nTxs, | |
1508 | realtime=realtime, |
|
1511 | realtime=realtime, | |
1509 | blocksize=blocksize, |
|
1512 | blocksize=blocksize, | |
1510 | blocktime=blocktime, |
|
1513 | blocktime=blocktime, | |
1511 | skip=skip, |
|
1514 | skip=skip, | |
1512 | cursor=cursor, |
|
1515 | cursor=cursor, | |
1513 | warnings=warnings, |
|
1516 | warnings=warnings, | |
1514 | server=server, |
|
1517 | server=server, | |
1515 | verbose=verbose, |
|
1518 | verbose=verbose, | |
1516 | format=format, |
|
1519 | format=format, | |
1517 | oneDDict=oneDDict, |
|
1520 | oneDDict=oneDDict, | |
1518 | twoDDict=twoDDict, |
|
1521 | twoDDict=twoDDict, | |
1519 | ind2DList=ind2DList) |
|
1522 | ind2DList=ind2DList) | |
1520 | self.isConfig = True |
|
1523 | self.isConfig = True | |
1521 | if server is None: |
|
1524 | if server is None: | |
1522 | self.getData() |
|
1525 | self.getData() | |
1523 | else: |
|
1526 | else: | |
1524 | self.getFromServer() |
|
1527 | self.getFromServer() | |
1525 |
|
1528 | |||
1526 |
|
1529 | |||
1527 | class JRODataWriter(JRODataIO): |
|
1530 | class JRODataWriter(JRODataIO): | |
1528 |
|
1531 | |||
1529 | """ |
|
1532 | """ | |
1530 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
1533 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
1531 | de los datos siempre se realiza por bloques. |
|
1534 | de los datos siempre se realiza por bloques. | |
1532 | """ |
|
1535 | """ | |
1533 |
|
1536 | |||
1534 | blockIndex = 0 |
|
1537 | blockIndex = 0 | |
1535 |
|
1538 | |||
1536 | path = None |
|
1539 | path = None | |
1537 |
|
1540 | |||
1538 | setFile = None |
|
1541 | setFile = None | |
1539 |
|
1542 | |||
1540 | profilesPerBlock = None |
|
1543 | profilesPerBlock = None | |
1541 |
|
1544 | |||
1542 | blocksPerFile = None |
|
1545 | blocksPerFile = None | |
1543 |
|
1546 | |||
1544 | nWriteBlocks = 0 |
|
1547 | nWriteBlocks = 0 | |
1545 |
|
1548 | |||
1546 | fileDate = None |
|
1549 | fileDate = None | |
1547 |
|
1550 | |||
1548 | def __init__(self, dataOut=None): |
|
1551 | def __init__(self, dataOut=None): | |
1549 | raise NotImplementedError |
|
1552 | raise NotImplementedError | |
1550 |
|
1553 | |||
1551 | def hasAllDataInBuffer(self): |
|
1554 | def hasAllDataInBuffer(self): | |
1552 | raise NotImplementedError |
|
1555 | raise NotImplementedError | |
1553 |
|
1556 | |||
1554 | def setBlockDimension(self): |
|
1557 | def setBlockDimension(self): | |
1555 | raise NotImplementedError |
|
1558 | raise NotImplementedError | |
1556 |
|
1559 | |||
1557 | def writeBlock(self): |
|
1560 | def writeBlock(self): | |
1558 | raise NotImplementedError |
|
1561 | raise NotImplementedError | |
1559 |
|
1562 | |||
1560 | def putData(self): |
|
1563 | def putData(self): | |
1561 | raise NotImplementedError |
|
1564 | raise NotImplementedError | |
1562 |
|
1565 | |||
1563 | def getProcessFlags(self): |
|
1566 | def getProcessFlags(self): | |
1564 |
|
1567 | |||
1565 | processFlags = 0 |
|
1568 | processFlags = 0 | |
1566 |
|
1569 | |||
1567 | dtype_index = get_dtype_index(self.dtype) |
|
1570 | dtype_index = get_dtype_index(self.dtype) | |
1568 | procflag_dtype = get_procflag_dtype(dtype_index) |
|
1571 | procflag_dtype = get_procflag_dtype(dtype_index) | |
1569 |
|
1572 | |||
1570 | processFlags += procflag_dtype |
|
1573 | processFlags += procflag_dtype | |
1571 |
|
1574 | |||
1572 | if self.dataOut.flagDecodeData: |
|
1575 | if self.dataOut.flagDecodeData: | |
1573 | processFlags += PROCFLAG.DECODE_DATA |
|
1576 | processFlags += PROCFLAG.DECODE_DATA | |
1574 |
|
1577 | |||
1575 | if self.dataOut.flagDeflipData: |
|
1578 | if self.dataOut.flagDeflipData: | |
1576 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1579 | processFlags += PROCFLAG.DEFLIP_DATA | |
1577 |
|
1580 | |||
1578 | if self.dataOut.code is not None: |
|
1581 | if self.dataOut.code is not None: | |
1579 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1582 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
1580 |
|
1583 | |||
1581 | if self.dataOut.nCohInt > 1: |
|
1584 | if self.dataOut.nCohInt > 1: | |
1582 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1585 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
1583 |
|
1586 | |||
1584 | if self.dataOut.type == "Spectra": |
|
1587 | if self.dataOut.type == "Spectra": | |
1585 | if self.dataOut.nIncohInt > 1: |
|
1588 | if self.dataOut.nIncohInt > 1: | |
1586 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
1589 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
1587 |
|
1590 | |||
1588 | if self.dataOut.data_dc is not None: |
|
1591 | if self.dataOut.data_dc is not None: | |
1589 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
1592 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
1590 |
|
1593 | |||
1591 | if self.dataOut.flagShiftFFT: |
|
1594 | if self.dataOut.flagShiftFFT: | |
1592 | processFlags += PROCFLAG.SHIFT_FFT_DATA |
|
1595 | processFlags += PROCFLAG.SHIFT_FFT_DATA | |
1593 |
|
1596 | |||
1594 | return processFlags |
|
1597 | return processFlags | |
1595 |
|
1598 | |||
1596 | def setBasicHeader(self): |
|
1599 | def setBasicHeader(self): | |
1597 |
|
1600 | |||
1598 | self.basicHeaderObj.size = self.basicHeaderSize # bytes |
|
1601 | self.basicHeaderObj.size = self.basicHeaderSize # bytes | |
1599 | self.basicHeaderObj.version = self.versionFile |
|
1602 | self.basicHeaderObj.version = self.versionFile | |
1600 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
1603 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
1601 |
|
1604 | |||
1602 | utc = numpy.floor(self.dataOut.utctime) |
|
1605 | utc = numpy.floor(self.dataOut.utctime) | |
1603 | milisecond = (self.dataOut.utctime - utc) * 1000.0 |
|
1606 | milisecond = (self.dataOut.utctime - utc) * 1000.0 | |
1604 |
|
1607 | |||
1605 | self.basicHeaderObj.utc = utc |
|
1608 | self.basicHeaderObj.utc = utc | |
1606 | self.basicHeaderObj.miliSecond = milisecond |
|
1609 | self.basicHeaderObj.miliSecond = milisecond | |
1607 | self.basicHeaderObj.timeZone = self.dataOut.timeZone |
|
1610 | self.basicHeaderObj.timeZone = self.dataOut.timeZone | |
1608 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag |
|
1611 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag | |
1609 | self.basicHeaderObj.errorCount = self.dataOut.errorCount |
|
1612 | self.basicHeaderObj.errorCount = self.dataOut.errorCount | |
1610 |
|
1613 | |||
1611 | def setFirstHeader(self): |
|
1614 | def setFirstHeader(self): | |
1612 | """ |
|
1615 | """ | |
1613 | Obtiene una copia del First Header |
|
1616 | Obtiene una copia del First Header | |
1614 |
|
1617 | |||
1615 | Affected: |
|
1618 | Affected: | |
1616 |
|
1619 | |||
1617 | self.basicHeaderObj |
|
1620 | self.basicHeaderObj | |
1618 | self.systemHeaderObj |
|
1621 | self.systemHeaderObj | |
1619 | self.radarControllerHeaderObj |
|
1622 | self.radarControllerHeaderObj | |
1620 | self.processingHeaderObj self. |
|
1623 | self.processingHeaderObj self. | |
1621 |
|
1624 | |||
1622 | Return: |
|
1625 | Return: | |
1623 | None |
|
1626 | None | |
1624 | """ |
|
1627 | """ | |
1625 |
|
1628 | |||
1626 | raise NotImplementedError |
|
1629 | raise NotImplementedError | |
1627 |
|
1630 | |||
1628 | def __writeFirstHeader(self): |
|
1631 | def __writeFirstHeader(self): | |
1629 | """ |
|
1632 | """ | |
1630 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
1633 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
1631 |
|
1634 | |||
1632 | Affected: |
|
1635 | Affected: | |
1633 | __dataType |
|
1636 | __dataType | |
1634 |
|
1637 | |||
1635 | Return: |
|
1638 | Return: | |
1636 | None |
|
1639 | None | |
1637 | """ |
|
1640 | """ | |
1638 |
|
1641 | |||
1639 | # CALCULAR PARAMETROS |
|
1642 | # CALCULAR PARAMETROS | |
1640 |
|
1643 | |||
1641 | sizeLongHeader = self.systemHeaderObj.size + \ |
|
1644 | sizeLongHeader = self.systemHeaderObj.size + \ | |
1642 | self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
1645 | self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
1643 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
1646 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
1644 |
|
1647 | |||
1645 | self.basicHeaderObj.write(self.fp) |
|
1648 | self.basicHeaderObj.write(self.fp) | |
1646 | self.systemHeaderObj.write(self.fp) |
|
1649 | self.systemHeaderObj.write(self.fp) | |
1647 | self.radarControllerHeaderObj.write(self.fp) |
|
1650 | self.radarControllerHeaderObj.write(self.fp) | |
1648 | self.processingHeaderObj.write(self.fp) |
|
1651 | self.processingHeaderObj.write(self.fp) | |
1649 |
|
1652 | |||
1650 | def __setNewBlock(self): |
|
1653 | def __setNewBlock(self): | |
1651 | """ |
|
1654 | """ | |
1652 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
1655 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
1653 |
|
1656 | |||
1654 | Return: |
|
1657 | Return: | |
1655 | 0 : si no pudo escribir nada |
|
1658 | 0 : si no pudo escribir nada | |
1656 | 1 : Si escribio el Basic el First Header |
|
1659 | 1 : Si escribio el Basic el First Header | |
1657 | """ |
|
1660 | """ | |
1658 | if self.fp == None: |
|
1661 | if self.fp == None: | |
1659 | self.setNextFile() |
|
1662 | self.setNextFile() | |
1660 |
|
1663 | |||
1661 | if self.flagIsNewFile: |
|
1664 | if self.flagIsNewFile: | |
1662 | return 1 |
|
1665 | return 1 | |
1663 |
|
1666 | |||
1664 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
1667 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
1665 | self.basicHeaderObj.write(self.fp) |
|
1668 | self.basicHeaderObj.write(self.fp) | |
1666 | return 1 |
|
1669 | return 1 | |
1667 |
|
1670 | |||
1668 | if not(self.setNextFile()): |
|
1671 | if not(self.setNextFile()): | |
1669 | return 0 |
|
1672 | return 0 | |
1670 |
|
1673 | |||
1671 | return 1 |
|
1674 | return 1 | |
1672 |
|
1675 | |||
1673 | def writeNextBlock(self): |
|
1676 | def writeNextBlock(self): | |
1674 | """ |
|
1677 | """ | |
1675 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1678 | Selecciona el bloque siguiente de datos y los escribe en un file | |
1676 |
|
1679 | |||
1677 | Return: |
|
1680 | Return: | |
1678 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1681 | 0 : Si no hizo pudo escribir el bloque de datos | |
1679 | 1 : Si no pudo escribir el bloque de datos |
|
1682 | 1 : Si no pudo escribir el bloque de datos | |
1680 | """ |
|
1683 | """ | |
1681 | if not(self.__setNewBlock()): |
|
1684 | if not(self.__setNewBlock()): | |
1682 | return 0 |
|
1685 | return 0 | |
1683 |
|
1686 | |||
1684 | self.writeBlock() |
|
1687 | self.writeBlock() | |
1685 |
|
1688 | |||
1686 | print "[Writing] Block No. %d/%d" % (self.blockIndex, |
|
1689 | print "[Writing] Block No. %d/%d" % (self.blockIndex, | |
1687 | self.processingHeaderObj.dataBlocksPerFile) |
|
1690 | self.processingHeaderObj.dataBlocksPerFile) | |
1688 |
|
1691 | |||
1689 | return 1 |
|
1692 | return 1 | |
1690 |
|
1693 | |||
1691 | def setNextFile(self): |
|
1694 | def setNextFile(self): | |
1692 | """ |
|
1695 | """ | |
1693 | Determina el siguiente file que sera escrito |
|
1696 | Determina el siguiente file que sera escrito | |
1694 |
|
1697 | |||
1695 | Affected: |
|
1698 | Affected: | |
1696 | self.filename |
|
1699 | self.filename | |
1697 | self.subfolder |
|
1700 | self.subfolder | |
1698 | self.fp |
|
1701 | self.fp | |
1699 | self.setFile |
|
1702 | self.setFile | |
1700 | self.flagIsNewFile |
|
1703 | self.flagIsNewFile | |
1701 |
|
1704 | |||
1702 | Return: |
|
1705 | Return: | |
1703 | 0 : Si el archivo no puede ser escrito |
|
1706 | 0 : Si el archivo no puede ser escrito | |
1704 | 1 : Si el archivo esta listo para ser escrito |
|
1707 | 1 : Si el archivo esta listo para ser escrito | |
1705 | """ |
|
1708 | """ | |
1706 | ext = self.ext |
|
1709 | ext = self.ext | |
1707 | path = self.path |
|
1710 | path = self.path | |
1708 |
|
1711 | |||
1709 | if self.fp != None: |
|
1712 | if self.fp != None: | |
1710 | self.fp.close() |
|
1713 | self.fp.close() | |
1711 |
|
1714 | |||
1712 | timeTuple = time.localtime(self.dataOut.utctime) |
|
1715 | timeTuple = time.localtime(self.dataOut.utctime) | |
1713 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday) |
|
1716 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday) | |
1714 |
|
1717 | |||
1715 | fullpath = os.path.join(path, subfolder) |
|
1718 | fullpath = os.path.join(path, subfolder) | |
1716 | setFile = self.setFile |
|
1719 | setFile = self.setFile | |
1717 |
|
1720 | |||
1718 | if not(os.path.exists(fullpath)): |
|
1721 | if not(os.path.exists(fullpath)): | |
1719 | os.mkdir(fullpath) |
|
1722 | os.mkdir(fullpath) | |
1720 | setFile = -1 # inicializo mi contador de seteo |
|
1723 | setFile = -1 # inicializo mi contador de seteo | |
1721 | else: |
|
1724 | else: | |
1722 | filesList = os.listdir(fullpath) |
|
1725 | filesList = os.listdir(fullpath) | |
1723 | if len(filesList) > 0: |
|
1726 | if len(filesList) > 0: | |
1724 | filesList = sorted(filesList, key=str.lower) |
|
1727 | filesList = sorted(filesList, key=str.lower) | |
1725 | filen = filesList[-1] |
|
1728 | filen = filesList[-1] | |
1726 | # el filename debera tener el siguiente formato |
|
1729 | # el filename debera tener el siguiente formato | |
1727 | # 0 1234 567 89A BCDE (hex) |
|
1730 | # 0 1234 567 89A BCDE (hex) | |
1728 | # x YYYY DDD SSS .ext |
|
1731 | # x YYYY DDD SSS .ext | |
1729 | if isNumber(filen[8:11]): |
|
1732 | if isNumber(filen[8:11]): | |
1730 | # inicializo mi contador de seteo al seteo del ultimo file |
|
1733 | # inicializo mi contador de seteo al seteo del ultimo file | |
1731 | setFile = int(filen[8:11]) |
|
1734 | setFile = int(filen[8:11]) | |
1732 | else: |
|
1735 | else: | |
1733 | setFile = -1 |
|
1736 | setFile = -1 | |
1734 | else: |
|
1737 | else: | |
1735 | setFile = -1 # inicializo mi contador de seteo |
|
1738 | setFile = -1 # inicializo mi contador de seteo | |
1736 |
|
1739 | |||
1737 | setFile += 1 |
|
1740 | setFile += 1 | |
1738 |
|
1741 | |||
1739 | # If this is a new day it resets some values |
|
1742 | # If this is a new day it resets some values | |
1740 | if self.dataOut.datatime.date() > self.fileDate: |
|
1743 | if self.dataOut.datatime.date() > self.fileDate: | |
1741 | setFile = 0 |
|
1744 | setFile = 0 | |
1742 | self.nTotalBlocks = 0 |
|
1745 | self.nTotalBlocks = 0 | |
1743 |
|
1746 | |||
1744 | filen = '%s%4.4d%3.3d%3.3d%s' % ( |
|
1747 | filen = '%s%4.4d%3.3d%3.3d%s' % ( | |
1745 | self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext) |
|
1748 | self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext) | |
1746 |
|
1749 | |||
1747 | filename = os.path.join(path, subfolder, filen) |
|
1750 | filename = os.path.join(path, subfolder, filen) | |
1748 |
|
1751 | |||
1749 | fp = open(filename, 'wb') |
|
1752 | fp = open(filename, 'wb') | |
1750 |
|
1753 | |||
1751 | self.blockIndex = 0 |
|
1754 | self.blockIndex = 0 | |
1752 |
|
1755 | |||
1753 | # guardando atributos |
|
1756 | # guardando atributos | |
1754 | self.filename = filename |
|
1757 | self.filename = filename | |
1755 | self.subfolder = subfolder |
|
1758 | self.subfolder = subfolder | |
1756 | self.fp = fp |
|
1759 | self.fp = fp | |
1757 | self.setFile = setFile |
|
1760 | self.setFile = setFile | |
1758 | self.flagIsNewFile = 1 |
|
1761 | self.flagIsNewFile = 1 | |
1759 | self.fileDate = self.dataOut.datatime.date() |
|
1762 | self.fileDate = self.dataOut.datatime.date() | |
1760 |
|
1763 | |||
1761 | self.setFirstHeader() |
|
1764 | self.setFirstHeader() | |
1762 |
|
1765 | |||
1763 | print '[Writing] Opening file: %s' % self.filename |
|
1766 | print '[Writing] Opening file: %s' % self.filename | |
1764 |
|
1767 | |||
1765 | self.__writeFirstHeader() |
|
1768 | self.__writeFirstHeader() | |
1766 |
|
1769 | |||
1767 | return 1 |
|
1770 | return 1 | |
1768 |
|
1771 | |||
1769 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4): |
|
1772 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4): | |
1770 | """ |
|
1773 | """ | |
1771 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1774 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1772 |
|
1775 | |||
1773 | Inputs: |
|
1776 | Inputs: | |
1774 | path : directory where data will be saved |
|
1777 | path : directory where data will be saved | |
1775 | profilesPerBlock : number of profiles per block |
|
1778 | profilesPerBlock : number of profiles per block | |
1776 | set : initial file set |
|
1779 | set : initial file set | |
1777 | datatype : An integer number that defines data type: |
|
1780 | datatype : An integer number that defines data type: | |
1778 | 0 : int8 (1 byte) |
|
1781 | 0 : int8 (1 byte) | |
1779 | 1 : int16 (2 bytes) |
|
1782 | 1 : int16 (2 bytes) | |
1780 | 2 : int32 (4 bytes) |
|
1783 | 2 : int32 (4 bytes) | |
1781 | 3 : int64 (8 bytes) |
|
1784 | 3 : int64 (8 bytes) | |
1782 | 4 : float32 (4 bytes) |
|
1785 | 4 : float32 (4 bytes) | |
1783 | 5 : double64 (8 bytes) |
|
1786 | 5 : double64 (8 bytes) | |
1784 |
|
1787 | |||
1785 | Return: |
|
1788 | Return: | |
1786 | 0 : Si no realizo un buen seteo |
|
1789 | 0 : Si no realizo un buen seteo | |
1787 | 1 : Si realizo un buen seteo |
|
1790 | 1 : Si realizo un buen seteo | |
1788 | """ |
|
1791 | """ | |
1789 |
|
1792 | |||
1790 | if ext == None: |
|
1793 | if ext == None: | |
1791 | ext = self.ext |
|
1794 | ext = self.ext | |
1792 |
|
1795 | |||
1793 | self.ext = ext.lower() |
|
1796 | self.ext = ext.lower() | |
1794 |
|
1797 | |||
1795 | self.path = path |
|
1798 | self.path = path | |
1796 |
|
1799 | |||
1797 | if set is None: |
|
1800 | if set is None: | |
1798 | self.setFile = -1 |
|
1801 | self.setFile = -1 | |
1799 | else: |
|
1802 | else: | |
1800 | self.setFile = set - 1 |
|
1803 | self.setFile = set - 1 | |
1801 |
|
1804 | |||
1802 | self.blocksPerFile = blocksPerFile |
|
1805 | self.blocksPerFile = blocksPerFile | |
1803 |
|
1806 | |||
1804 | self.profilesPerBlock = profilesPerBlock |
|
1807 | self.profilesPerBlock = profilesPerBlock | |
1805 |
|
1808 | |||
1806 | self.dataOut = dataOut |
|
1809 | self.dataOut = dataOut | |
1807 | self.fileDate = self.dataOut.datatime.date() |
|
1810 | self.fileDate = self.dataOut.datatime.date() | |
1808 | # By default |
|
1811 | # By default | |
1809 | self.dtype = self.dataOut.dtype |
|
1812 | self.dtype = self.dataOut.dtype | |
1810 |
|
1813 | |||
1811 | if datatype is not None: |
|
1814 | if datatype is not None: | |
1812 | self.dtype = get_numpy_dtype(datatype) |
|
1815 | self.dtype = get_numpy_dtype(datatype) | |
1813 |
|
1816 | |||
1814 | if not(self.setNextFile()): |
|
1817 | if not(self.setNextFile()): | |
1815 | print "[Writing] There isn't a next file" |
|
1818 | print "[Writing] There isn't a next file" | |
1816 | return 0 |
|
1819 | return 0 | |
1817 |
|
1820 | |||
1818 | self.setBlockDimension() |
|
1821 | self.setBlockDimension() | |
1819 |
|
1822 | |||
1820 | return 1 |
|
1823 | return 1 | |
1821 |
|
1824 | |||
1822 | def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs): |
|
1825 | def run(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=None, ext=None, datatype=4, **kwargs): | |
1823 |
|
1826 | |||
1824 | if not(self.isConfig): |
|
1827 | if not(self.isConfig): | |
1825 |
|
1828 | |||
1826 | self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, |
|
1829 | self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, | |
1827 | set=set, ext=ext, datatype=datatype, **kwargs) |
|
1830 | set=set, ext=ext, datatype=datatype, **kwargs) | |
1828 | self.isConfig = True |
|
1831 | self.isConfig = True | |
1829 |
|
1832 | |||
1830 | self.putData() |
|
1833 | self.putData() |
@@ -1,1182 +1,1180 | |||||
1 | import os |
|
1 | import os | |
2 | import sys |
|
2 | import sys | |
3 | import glob |
|
3 | import glob | |
4 | import fnmatch |
|
4 | import fnmatch | |
5 | import datetime |
|
5 | import datetime | |
6 | import time |
|
6 | import time | |
7 | import re |
|
7 | import re | |
8 | import h5py |
|
8 | import h5py | |
9 | import numpy |
|
9 | import numpy | |
10 |
|
10 | |||
11 | import pylab as plb |
|
11 | import pylab as plb | |
12 | from scipy.optimize import curve_fit |
|
12 | from scipy.optimize import curve_fit | |
13 | from scipy import asarray as ar, exp |
|
13 | from scipy import asarray as ar, exp | |
14 | from scipy import stats |
|
14 | from scipy import stats | |
15 |
|
15 | |||
16 | from numpy.ma.core import getdata |
|
16 | from numpy.ma.core import getdata | |
17 |
|
17 | |||
18 | SPEED_OF_LIGHT = 299792458 |
|
18 | SPEED_OF_LIGHT = 299792458 | |
19 | SPEED_OF_LIGHT = 3e8 |
|
19 | SPEED_OF_LIGHT = 3e8 | |
20 |
|
20 | |||
21 | try: |
|
21 | try: | |
22 | from gevent import sleep |
|
22 | from gevent import sleep | |
23 | except: |
|
23 | except: | |
24 | from time import sleep |
|
24 | from time import sleep | |
25 |
|
25 | |||
26 | from schainpy.model.data.jrodata import Spectra |
|
26 | from schainpy.model.data.jrodata import Spectra | |
27 | #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader |
|
27 | #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader | |
28 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
28 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
29 | #from schainpy.model.io.jroIO_bltr import BLTRReader |
|
29 | #from schainpy.model.io.jroIO_bltr import BLTRReader | |
30 | from numpy import imag, shape, NaN |
|
30 | from numpy import imag, shape, NaN | |
31 |
|
31 | |||
32 | from jroIO_base import JRODataReader |
|
32 | from jroIO_base import JRODataReader | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | class Header(object): |
|
35 | class Header(object): | |
36 |
|
36 | |||
37 | def __init__(self): |
|
37 | def __init__(self): | |
38 | raise NotImplementedError |
|
38 | raise NotImplementedError | |
39 |
|
39 | |||
40 | def read(self): |
|
40 | def read(self): | |
41 |
|
41 | |||
42 | raise NotImplementedError |
|
42 | raise NotImplementedError | |
43 |
|
43 | |||
44 | def write(self): |
|
44 | def write(self): | |
45 |
|
45 | |||
46 | raise NotImplementedError |
|
46 | raise NotImplementedError | |
47 |
|
47 | |||
48 | def printInfo(self): |
|
48 | def printInfo(self): | |
49 |
|
49 | |||
50 | message = "#" * 50 + "\n" |
|
50 | message = "#" * 50 + "\n" | |
51 | message += self.__class__.__name__.upper() + "\n" |
|
51 | message += self.__class__.__name__.upper() + "\n" | |
52 | message += "#" * 50 + "\n" |
|
52 | message += "#" * 50 + "\n" | |
53 |
|
53 | |||
54 | keyList = self.__dict__.keys() |
|
54 | keyList = self.__dict__.keys() | |
55 | keyList.sort() |
|
55 | keyList.sort() | |
56 |
|
56 | |||
57 | for key in keyList: |
|
57 | for key in keyList: | |
58 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" |
|
58 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" | |
59 |
|
59 | |||
60 | if "size" not in keyList: |
|
60 | if "size" not in keyList: | |
61 | attr = getattr(self, "size") |
|
61 | attr = getattr(self, "size") | |
62 |
|
62 | |||
63 | if attr: |
|
63 | if attr: | |
64 | message += "%s = %s" % ("size", attr) + "\n" |
|
64 | message += "%s = %s" % ("size", attr) + "\n" | |
65 |
|
65 | |||
66 | # print message |
|
66 | # print message | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes |
|
69 | FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes | |
70 | ('FileMgcNumber', '<u4'), # 0x23020100 |
|
70 | ('FileMgcNumber', '<u4'), # 0x23020100 | |
71 | # No Of FDT data records in this file (0 or more) |
|
71 | # No Of FDT data records in this file (0 or more) | |
72 | ('nFDTdataRecors', '<u4'), |
|
72 | ('nFDTdataRecors', '<u4'), | |
73 | ('OffsetStartHeader', '<u4'), |
|
73 | ('OffsetStartHeader', '<u4'), | |
74 | ('RadarUnitId', '<u4'), |
|
74 | ('RadarUnitId', '<u4'), | |
75 | ('SiteName', numpy.str_, 32), # Null terminated |
|
75 | ('SiteName', numpy.str_, 32), # Null terminated | |
76 | ]) |
|
76 | ]) | |
77 |
|
77 | |||
78 |
|
78 | |||
79 | class FileHeaderBLTR(Header): |
|
79 | class FileHeaderBLTR(Header): | |
80 |
|
80 | |||
81 | def __init__(self): |
|
81 | def __init__(self): | |
82 |
|
82 | |||
83 | self.FileMgcNumber = 0 # 0x23020100 |
|
83 | self.FileMgcNumber = 0 # 0x23020100 | |
84 | # No Of FDT data records in this file (0 or more) |
|
84 | # No Of FDT data records in this file (0 or more) | |
85 | self.nFDTdataRecors = 0 |
|
85 | self.nFDTdataRecors = 0 | |
86 | self.RadarUnitId = 0 |
|
86 | self.RadarUnitId = 0 | |
87 | self.OffsetStartHeader = 0 |
|
87 | self.OffsetStartHeader = 0 | |
88 | self.SiteName = "" |
|
88 | self.SiteName = "" | |
89 | self.size = 48 |
|
89 | self.size = 48 | |
90 |
|
90 | |||
91 | def FHread(self, fp): |
|
91 | def FHread(self, fp): | |
92 | # try: |
|
92 | # try: | |
93 | startFp = open(fp, "rb") |
|
93 | startFp = open(fp, "rb") | |
94 |
|
94 | |||
95 | header = numpy.fromfile(startFp, FILE_STRUCTURE, 1) |
|
95 | header = numpy.fromfile(startFp, FILE_STRUCTURE, 1) | |
96 |
|
96 | |||
97 | print ' ' |
|
97 | print ' ' | |
98 | print 'puntero file header', startFp.tell() |
|
98 | print 'puntero file header', startFp.tell() | |
99 | print ' ' |
|
99 | print ' ' | |
100 |
|
100 | |||
101 | ''' numpy.fromfile(file, dtype, count, sep='') |
|
101 | ''' numpy.fromfile(file, dtype, count, sep='') | |
102 | file : file or str |
|
102 | file : file or str | |
103 | Open file object or filename. |
|
103 | Open file object or filename. | |
104 |
|
104 | |||
105 | dtype : data-type |
|
105 | dtype : data-type | |
106 | Data type of the returned array. For binary files, it is used to determine |
|
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. |
|
107 | the size and byte-order of the items in the file. | |
108 |
|
108 | |||
109 | count : int |
|
109 | count : int | |
110 | Number of items to read. -1 means all items (i.e., the complete file). |
|
110 | Number of items to read. -1 means all items (i.e., the complete file). | |
111 |
|
111 | |||
112 | sep : str |
|
112 | sep : str | |
113 | Separator between items if file is a text file. Empty ("") separator means |
|
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 |
|
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 |
|
115 | or more whitespace characters. A separator consisting only of spaces must match | |
116 | at least one whitespace. |
|
116 | at least one whitespace. | |
117 |
|
117 | |||
118 | ''' |
|
118 | ''' | |
119 |
|
119 | |||
120 | self.FileMgcNumber = hex(header['FileMgcNumber'][0]) |
|
120 | self.FileMgcNumber = hex(header['FileMgcNumber'][0]) | |
121 | # No Of FDT data records in this file (0 or more) |
|
121 | # No Of FDT data records in this file (0 or more) | |
122 | self.nFDTdataRecors = int(header['nFDTdataRecors'][0]) |
|
122 | self.nFDTdataRecors = int(header['nFDTdataRecors'][0]) | |
123 | self.RadarUnitId = int(header['RadarUnitId'][0]) |
|
123 | self.RadarUnitId = int(header['RadarUnitId'][0]) | |
124 | self.OffsetStartHeader = int(header['OffsetStartHeader'][0]) |
|
124 | self.OffsetStartHeader = int(header['OffsetStartHeader'][0]) | |
125 | self.SiteName = str(header['SiteName'][0]) |
|
125 | self.SiteName = str(header['SiteName'][0]) | |
126 |
|
126 | |||
127 | # print 'Numero de bloques', self.nFDTdataRecors |
|
127 | # print 'Numero de bloques', self.nFDTdataRecors | |
128 |
|
128 | |||
129 | if self.size < 48: |
|
129 | if self.size < 48: | |
130 | return 0 |
|
130 | return 0 | |
131 |
|
131 | |||
132 | return 1 |
|
132 | return 1 | |
133 |
|
133 | |||
134 | def write(self, fp): |
|
134 | def write(self, fp): | |
135 |
|
135 | |||
136 | headerTuple = (self.FileMgcNumber, |
|
136 | headerTuple = (self.FileMgcNumber, | |
137 | self.nFDTdataRecors, |
|
137 | self.nFDTdataRecors, | |
138 | self.RadarUnitId, |
|
138 | self.RadarUnitId, | |
139 | self.SiteName, |
|
139 | self.SiteName, | |
140 | self.size) |
|
140 | self.size) | |
141 |
|
141 | |||
142 | header = numpy.array(headerTuple, FILE_STRUCTURE) |
|
142 | header = numpy.array(headerTuple, FILE_STRUCTURE) | |
143 | # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) |
|
143 | # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) | |
144 | header.tofile(fp) |
|
144 | header.tofile(fp) | |
145 | ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default). |
|
145 | ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default). | |
146 |
|
146 | |||
147 | fid : file or str |
|
147 | fid : file or str | |
148 | An open file object, or a string containing a filename. |
|
148 | An open file object, or a string containing a filename. | |
149 |
|
149 | |||
150 | sep : str |
|
150 | sep : str | |
151 | Separator between array items for text output. If "" (empty), a binary file is written, |
|
151 | Separator between array items for text output. If "" (empty), a binary file is written, | |
152 | equivalent to file.write(a.tobytes()). |
|
152 | equivalent to file.write(a.tobytes()). | |
153 |
|
153 | |||
154 | format : str |
|
154 | format : str | |
155 | Format string for text file output. Each entry in the array is formatted to text by |
|
155 | Format string for text file output. Each entry in the array is formatted to text by | |
156 | first converting it to the closest Python type, and then using "format" % item. |
|
156 | first converting it to the closest Python type, and then using "format" % item. | |
157 |
|
157 | |||
158 | ''' |
|
158 | ''' | |
159 |
|
159 | |||
160 | return 1 |
|
160 | return 1 | |
161 |
|
161 | |||
162 |
|
162 | |||
163 | RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes |
|
163 | RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes | |
164 | ('RecMgcNumber', '<u4'), # 0x23030001 |
|
164 | ('RecMgcNumber', '<u4'), # 0x23030001 | |
165 | ('RecCounter', '<u4'), # Record counter(0,1, ...) |
|
165 | ('RecCounter', '<u4'), # Record counter(0,1, ...) | |
166 | # Offset to start of next record form start of this record |
|
166 | # Offset to start of next record form start of this record | |
167 | ('Off2StartNxtRec', '<u4'), |
|
167 | ('Off2StartNxtRec', '<u4'), | |
168 | # Offset to start of data from start of this record |
|
168 | # Offset to start of data from start of this record | |
169 | ('Off2StartData', '<u4'), |
|
169 | ('Off2StartData', '<u4'), | |
170 | # Epoch time stamp of start of acquisition (seconds) |
|
170 | # Epoch time stamp of start of acquisition (seconds) | |
171 | ('nUtime', '<i4'), |
|
171 | ('nUtime', '<i4'), | |
172 | # Millisecond component of time stamp (0,...,999) |
|
172 | # Millisecond component of time stamp (0,...,999) | |
173 | ('nMilisec', '<u4'), |
|
173 | ('nMilisec', '<u4'), | |
174 | # Experiment tag name (null terminated) |
|
174 | # Experiment tag name (null terminated) | |
175 | ('ExpTagName', numpy.str_, 32), |
|
175 | ('ExpTagName', numpy.str_, 32), | |
176 | # Experiment comment (null terminated) |
|
176 | # Experiment comment (null terminated) | |
177 | ('ExpComment', numpy.str_, 32), |
|
177 | ('ExpComment', numpy.str_, 32), | |
178 | # Site latitude (from GPS) in degrees (positive implies North) |
|
178 | # Site latitude (from GPS) in degrees (positive implies North) | |
179 | ('SiteLatDegrees', '<f4'), |
|
179 | ('SiteLatDegrees', '<f4'), | |
180 | # Site longitude (from GPS) in degrees (positive implies East) |
|
180 | # Site longitude (from GPS) in degrees (positive implies East) | |
181 | ('SiteLongDegrees', '<f4'), |
|
181 | ('SiteLongDegrees', '<f4'), | |
182 | # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE) |
|
182 | # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE) | |
183 | ('RTCgpsStatus', '<u4'), |
|
183 | ('RTCgpsStatus', '<u4'), | |
184 | ('TransmitFrec', '<u4'), # Transmit frequency (Hz) |
|
184 | ('TransmitFrec', '<u4'), # Transmit frequency (Hz) | |
185 | ('ReceiveFrec', '<u4'), # Receive frequency |
|
185 | ('ReceiveFrec', '<u4'), # Receive frequency | |
186 | # First local oscillator frequency (Hz) |
|
186 | # First local oscillator frequency (Hz) | |
187 | ('FirstOsciFrec', '<u4'), |
|
187 | ('FirstOsciFrec', '<u4'), | |
188 | # (0="O", 1="E", 2="linear 1", 3="linear2") |
|
188 | # (0="O", 1="E", 2="linear 1", 3="linear2") | |
189 | ('Polarisation', '<u4'), |
|
189 | ('Polarisation', '<u4'), | |
190 | # Receiver filter settings (0,1,2,3) |
|
190 | # Receiver filter settings (0,1,2,3) | |
191 | ('ReceiverFiltSett', '<u4'), |
|
191 | ('ReceiverFiltSett', '<u4'), | |
192 | # Number of modes in use (1 or 2) |
|
192 | # Number of modes in use (1 or 2) | |
193 | ('nModesInUse', '<u4'), |
|
193 | ('nModesInUse', '<u4'), | |
194 | # Dual Mode index number for these data (0 or 1) |
|
194 | # Dual Mode index number for these data (0 or 1) | |
195 | ('DualModeIndex', '<u4'), |
|
195 | ('DualModeIndex', '<u4'), | |
196 | # Dual Mode range correction for these data (m) |
|
196 | # Dual Mode range correction for these data (m) | |
197 | ('DualModeRange', '<u4'), |
|
197 | ('DualModeRange', '<u4'), | |
198 | # Number of digital channels acquired (2*N) |
|
198 | # Number of digital channels acquired (2*N) | |
199 | ('nDigChannels', '<u4'), |
|
199 | ('nDigChannels', '<u4'), | |
200 | # Sampling resolution (meters) |
|
200 | # Sampling resolution (meters) | |
201 | ('SampResolution', '<u4'), |
|
201 | ('SampResolution', '<u4'), | |
202 | # Number of range gates sampled |
|
202 | # Number of range gates sampled | |
203 | ('nHeights', '<u4'), |
|
203 | ('nHeights', '<u4'), | |
204 | # Start range of sampling (meters) |
|
204 | # Start range of sampling (meters) | |
205 | ('StartRangeSamp', '<u4'), |
|
205 | ('StartRangeSamp', '<u4'), | |
206 | ('PRFhz', '<u4'), # PRF (Hz) |
|
206 | ('PRFhz', '<u4'), # PRF (Hz) | |
207 | ('nCohInt', '<u4'), # Integrations |
|
207 | ('nCohInt', '<u4'), # Integrations | |
208 | # Number of data points transformed |
|
208 | # Number of data points transformed | |
209 | ('nProfiles', '<u4'), |
|
209 | ('nProfiles', '<u4'), | |
210 | # Number of receive beams stored in file (1 or N) |
|
210 | # Number of receive beams stored in file (1 or N) | |
211 | ('nChannels', '<u4'), |
|
211 | ('nChannels', '<u4'), | |
212 | ('nIncohInt', '<u4'), # Number of spectral averages |
|
212 | ('nIncohInt', '<u4'), # Number of spectral averages | |
213 | # FFT windowing index (0 = no window) |
|
213 | # FFT windowing index (0 = no window) | |
214 | ('FFTwindowingInd', '<u4'), |
|
214 | ('FFTwindowingInd', '<u4'), | |
215 | # Beam steer angle (azimuth) in degrees (clockwise from true North) |
|
215 | # Beam steer angle (azimuth) in degrees (clockwise from true North) | |
216 | ('BeamAngleAzim', '<f4'), |
|
216 | ('BeamAngleAzim', '<f4'), | |
217 | # Beam steer angle (zenith) in degrees (0=> vertical) |
|
217 | # Beam steer angle (zenith) in degrees (0=> vertical) | |
218 | ('BeamAngleZen', '<f4'), |
|
218 | ('BeamAngleZen', '<f4'), | |
219 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
219 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
220 | ('AntennaCoord0', '<f4'), |
|
220 | ('AntennaCoord0', '<f4'), | |
221 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
221 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
222 | ('AntennaAngl0', '<f4'), |
|
222 | ('AntennaAngl0', '<f4'), | |
223 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
223 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
224 | ('AntennaCoord1', '<f4'), |
|
224 | ('AntennaCoord1', '<f4'), | |
225 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
225 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
226 | ('AntennaAngl1', '<f4'), |
|
226 | ('AntennaAngl1', '<f4'), | |
227 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
227 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
228 | ('AntennaCoord2', '<f4'), |
|
228 | ('AntennaCoord2', '<f4'), | |
229 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs |
|
229 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
230 | ('AntennaAngl2', '<f4'), |
|
230 | ('AntennaAngl2', '<f4'), | |
231 | # Receiver phase calibration (degrees) - N values |
|
231 | # Receiver phase calibration (degrees) - N values | |
232 | ('RecPhaseCalibr0', '<f4'), |
|
232 | ('RecPhaseCalibr0', '<f4'), | |
233 | # Receiver phase calibration (degrees) - N values |
|
233 | # Receiver phase calibration (degrees) - N values | |
234 | ('RecPhaseCalibr1', '<f4'), |
|
234 | ('RecPhaseCalibr1', '<f4'), | |
235 | # Receiver phase calibration (degrees) - N values |
|
235 | # Receiver phase calibration (degrees) - N values | |
236 | ('RecPhaseCalibr2', '<f4'), |
|
236 | ('RecPhaseCalibr2', '<f4'), | |
237 | # Receiver amplitude calibration (ratio relative to receiver one) - N values |
|
237 | # Receiver amplitude calibration (ratio relative to receiver one) - N values | |
238 | ('RecAmpCalibr0', '<f4'), |
|
238 | ('RecAmpCalibr0', '<f4'), | |
239 | # Receiver amplitude calibration (ratio relative to receiver one) - N values |
|
239 | # Receiver amplitude calibration (ratio relative to receiver one) - N values | |
240 | ('RecAmpCalibr1', '<f4'), |
|
240 | ('RecAmpCalibr1', '<f4'), | |
241 | # Receiver amplitude calibration (ratio relative to receiver one) - N values |
|
241 | # Receiver amplitude calibration (ratio relative to receiver one) - N values | |
242 | ('RecAmpCalibr2', '<f4'), |
|
242 | ('RecAmpCalibr2', '<f4'), | |
243 | # Receiver gains in dB - N values |
|
243 | # Receiver gains in dB - N values | |
244 | ('ReceiverGaindB0', '<i4'), |
|
244 | ('ReceiverGaindB0', '<i4'), | |
245 | # Receiver gains in dB - N values |
|
245 | # Receiver gains in dB - N values | |
246 | ('ReceiverGaindB1', '<i4'), |
|
246 | ('ReceiverGaindB1', '<i4'), | |
247 | # Receiver gains in dB - N values |
|
247 | # Receiver gains in dB - N values | |
248 | ('ReceiverGaindB2', '<i4'), |
|
248 | ('ReceiverGaindB2', '<i4'), | |
249 | ]) |
|
249 | ]) | |
250 |
|
250 | |||
251 |
|
251 | |||
252 | class RecordHeaderBLTR(Header): |
|
252 | class RecordHeaderBLTR(Header): | |
253 |
|
253 | |||
254 | def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248, |
|
254 | def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248, | |
255 | nUtime=0, nMilisec=0, ExpTagName=None, |
|
255 | nUtime=0, nMilisec=0, ExpTagName=None, | |
256 | ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0, |
|
256 | ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0, | |
257 | RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0, |
|
257 | RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0, | |
258 | FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0, |
|
258 | FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0, | |
259 | nModesInUse=0, DualModeIndex=0, DualModeRange=0, |
|
259 | nModesInUse=0, DualModeIndex=0, DualModeRange=0, | |
260 | nDigChannels=0, SampResolution=0, nHeights=0, |
|
260 | nDigChannels=0, SampResolution=0, nHeights=0, | |
261 | StartRangeSamp=0, PRFhz=0, nCohInt=0, |
|
261 | StartRangeSamp=0, PRFhz=0, nCohInt=0, | |
262 | nProfiles=0, nChannels=0, nIncohInt=0, |
|
262 | nProfiles=0, nChannels=0, nIncohInt=0, | |
263 | FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0, |
|
263 | FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0, | |
264 | AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0, |
|
264 | AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0, | |
265 | RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0, |
|
265 | RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0, | |
266 | RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0, |
|
266 | RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0, | |
267 | AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0, |
|
267 | AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0, | |
268 | ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0): |
|
268 | ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0): | |
269 |
|
269 | |||
270 | self.RecMgcNumber = RecMgcNumber # 0x23030001 |
|
270 | self.RecMgcNumber = RecMgcNumber # 0x23030001 | |
271 | self.RecCounter = RecCounter |
|
271 | self.RecCounter = RecCounter | |
272 | self.Off2StartNxtRec = Off2StartNxtRec |
|
272 | self.Off2StartNxtRec = Off2StartNxtRec | |
273 | self.Off2StartData = Off2StartData |
|
273 | self.Off2StartData = Off2StartData | |
274 | self.nUtime = nUtime |
|
274 | self.nUtime = nUtime | |
275 | self.nMilisec = nMilisec |
|
275 | self.nMilisec = nMilisec | |
276 | self.ExpTagName = ExpTagName |
|
276 | self.ExpTagName = ExpTagName | |
277 | self.ExpComment = ExpComment |
|
277 | self.ExpComment = ExpComment | |
278 | self.SiteLatDegrees = SiteLatDegrees |
|
278 | self.SiteLatDegrees = SiteLatDegrees | |
279 | self.SiteLongDegrees = SiteLongDegrees |
|
279 | self.SiteLongDegrees = SiteLongDegrees | |
280 | self.RTCgpsStatus = RTCgpsStatus |
|
280 | self.RTCgpsStatus = RTCgpsStatus | |
281 | self.TransmitFrec = TransmitFrec |
|
281 | self.TransmitFrec = TransmitFrec | |
282 | self.ReceiveFrec = ReceiveFrec |
|
282 | self.ReceiveFrec = ReceiveFrec | |
283 | self.FirstOsciFrec = FirstOsciFrec |
|
283 | self.FirstOsciFrec = FirstOsciFrec | |
284 | self.Polarisation = Polarisation |
|
284 | self.Polarisation = Polarisation | |
285 | self.ReceiverFiltSett = ReceiverFiltSett |
|
285 | self.ReceiverFiltSett = ReceiverFiltSett | |
286 | self.nModesInUse = nModesInUse |
|
286 | self.nModesInUse = nModesInUse | |
287 | self.DualModeIndex = DualModeIndex |
|
287 | self.DualModeIndex = DualModeIndex | |
288 | self.DualModeRange = DualModeRange |
|
288 | self.DualModeRange = DualModeRange | |
289 | self.nDigChannels = nDigChannels |
|
289 | self.nDigChannels = nDigChannels | |
290 | self.SampResolution = SampResolution |
|
290 | self.SampResolution = SampResolution | |
291 | self.nHeights = nHeights |
|
291 | self.nHeights = nHeights | |
292 | self.StartRangeSamp = StartRangeSamp |
|
292 | self.StartRangeSamp = StartRangeSamp | |
293 | self.PRFhz = PRFhz |
|
293 | self.PRFhz = PRFhz | |
294 | self.nCohInt = nCohInt |
|
294 | self.nCohInt = nCohInt | |
295 | self.nProfiles = nProfiles |
|
295 | self.nProfiles = nProfiles | |
296 | self.nChannels = nChannels |
|
296 | self.nChannels = nChannels | |
297 | self.nIncohInt = nIncohInt |
|
297 | self.nIncohInt = nIncohInt | |
298 | self.FFTwindowingInd = FFTwindowingInd |
|
298 | self.FFTwindowingInd = FFTwindowingInd | |
299 | self.BeamAngleAzim = BeamAngleAzim |
|
299 | self.BeamAngleAzim = BeamAngleAzim | |
300 | self.BeamAngleZen = BeamAngleZen |
|
300 | self.BeamAngleZen = BeamAngleZen | |
301 | self.AntennaCoord0 = AntennaCoord0 |
|
301 | self.AntennaCoord0 = AntennaCoord0 | |
302 | self.AntennaAngl0 = AntennaAngl0 |
|
302 | self.AntennaAngl0 = AntennaAngl0 | |
303 | self.AntennaAngl1 = AntennaAngl1 |
|
303 | self.AntennaAngl1 = AntennaAngl1 | |
304 | self.AntennaAngl2 = AntennaAngl2 |
|
304 | self.AntennaAngl2 = AntennaAngl2 | |
305 | self.AntennaCoord1 = AntennaCoord1 |
|
305 | self.AntennaCoord1 = AntennaCoord1 | |
306 | self.AntennaCoord2 = AntennaCoord2 |
|
306 | self.AntennaCoord2 = AntennaCoord2 | |
307 | self.RecPhaseCalibr0 = RecPhaseCalibr0 |
|
307 | self.RecPhaseCalibr0 = RecPhaseCalibr0 | |
308 | self.RecPhaseCalibr1 = RecPhaseCalibr1 |
|
308 | self.RecPhaseCalibr1 = RecPhaseCalibr1 | |
309 | self.RecPhaseCalibr2 = RecPhaseCalibr2 |
|
309 | self.RecPhaseCalibr2 = RecPhaseCalibr2 | |
310 | self.RecAmpCalibr0 = RecAmpCalibr0 |
|
310 | self.RecAmpCalibr0 = RecAmpCalibr0 | |
311 | self.RecAmpCalibr1 = RecAmpCalibr1 |
|
311 | self.RecAmpCalibr1 = RecAmpCalibr1 | |
312 | self.RecAmpCalibr2 = RecAmpCalibr2 |
|
312 | self.RecAmpCalibr2 = RecAmpCalibr2 | |
313 | self.ReceiverGaindB0 = ReceiverGaindB0 |
|
313 | self.ReceiverGaindB0 = ReceiverGaindB0 | |
314 | self.ReceiverGaindB1 = ReceiverGaindB1 |
|
314 | self.ReceiverGaindB1 = ReceiverGaindB1 | |
315 | self.ReceiverGaindB2 = ReceiverGaindB2 |
|
315 | self.ReceiverGaindB2 = ReceiverGaindB2 | |
316 | self.OffsetStartHeader = 48 |
|
316 | self.OffsetStartHeader = 48 | |
317 |
|
317 | |||
318 | def RHread(self, fp): |
|
318 | def RHread(self, fp): | |
319 | # print 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. |
|
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. |
|
321 | # The method tell() returns the current position of the file read/write pointer within the file. | |
322 | startFp = open(fp, "rb") |
|
322 | startFp = open(fp, "rb") | |
323 | # RecCounter=0 |
|
323 | # RecCounter=0 | |
324 | # Off2StartNxtRec=811248 |
|
324 | # Off2StartNxtRec=811248 | |
325 | OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec |
|
325 | OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec | |
326 | print ' ' |
|
326 | print ' ' | |
327 | print 'puntero Record Header', startFp.tell() |
|
327 | print 'puntero Record Header', startFp.tell() | |
328 | print ' ' |
|
328 | print ' ' | |
329 |
|
329 | |||
330 | startFp.seek(OffRHeader, os.SEEK_SET) |
|
330 | startFp.seek(OffRHeader, os.SEEK_SET) | |
331 |
|
331 | |||
332 | print ' ' |
|
332 | print ' ' | |
333 | print 'puntero Record Header con seek', startFp.tell() |
|
333 | print 'puntero Record Header con seek', startFp.tell() | |
334 | print ' ' |
|
334 | print ' ' | |
335 |
|
335 | |||
336 | # print 'Posicion del bloque: ',OffRHeader |
|
336 | # print 'Posicion del bloque: ',OffRHeader | |
337 |
|
337 | |||
338 | header = numpy.fromfile(startFp, RECORD_STRUCTURE, 1) |
|
338 | header = numpy.fromfile(startFp, RECORD_STRUCTURE, 1) | |
339 |
|
339 | |||
340 | print ' ' |
|
340 | print ' ' | |
341 | print 'puntero Record Header con seek', startFp.tell() |
|
341 | print 'puntero Record Header con seek', startFp.tell() | |
342 | print ' ' |
|
342 | print ' ' | |
343 |
|
343 | |||
344 | print ' ' |
|
344 | print ' ' | |
345 | # |
|
345 | # | |
346 | # print 'puntero Record Header despues de seek', header.tell() |
|
346 | # print 'puntero Record Header despues de seek', header.tell() | |
347 | print ' ' |
|
347 | print ' ' | |
348 |
|
348 | |||
349 | self.RecMgcNumber = hex(header['RecMgcNumber'][0]) # 0x23030001 |
|
349 | self.RecMgcNumber = hex(header['RecMgcNumber'][0]) # 0x23030001 | |
350 | self.RecCounter = int(header['RecCounter'][0]) |
|
350 | self.RecCounter = int(header['RecCounter'][0]) | |
351 | self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0]) |
|
351 | self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0]) | |
352 | self.Off2StartData = int(header['Off2StartData'][0]) |
|
352 | self.Off2StartData = int(header['Off2StartData'][0]) | |
353 | self.nUtime = header['nUtime'][0] |
|
353 | self.nUtime = header['nUtime'][0] | |
354 | self.nMilisec = header['nMilisec'][0] |
|
354 | self.nMilisec = header['nMilisec'][0] | |
355 | self.ExpTagName = str(header['ExpTagName'][0]) |
|
355 | self.ExpTagName = str(header['ExpTagName'][0]) | |
356 | self.ExpComment = str(header['ExpComment'][0]) |
|
356 | self.ExpComment = str(header['ExpComment'][0]) | |
357 | self.SiteLatDegrees = header['SiteLatDegrees'][0] |
|
357 | self.SiteLatDegrees = header['SiteLatDegrees'][0] | |
358 | self.SiteLongDegrees = header['SiteLongDegrees'][0] |
|
358 | self.SiteLongDegrees = header['SiteLongDegrees'][0] | |
359 | self.RTCgpsStatus = header['RTCgpsStatus'][0] |
|
359 | self.RTCgpsStatus = header['RTCgpsStatus'][0] | |
360 | self.TransmitFrec = header['TransmitFrec'][0] |
|
360 | self.TransmitFrec = header['TransmitFrec'][0] | |
361 | self.ReceiveFrec = header['ReceiveFrec'][0] |
|
361 | self.ReceiveFrec = header['ReceiveFrec'][0] | |
362 | self.FirstOsciFrec = header['FirstOsciFrec'][0] |
|
362 | self.FirstOsciFrec = header['FirstOsciFrec'][0] | |
363 | self.Polarisation = header['Polarisation'][0] |
|
363 | self.Polarisation = header['Polarisation'][0] | |
364 | self.ReceiverFiltSett = header['ReceiverFiltSett'][0] |
|
364 | self.ReceiverFiltSett = header['ReceiverFiltSett'][0] | |
365 | self.nModesInUse = header['nModesInUse'][0] |
|
365 | self.nModesInUse = header['nModesInUse'][0] | |
366 | self.DualModeIndex = header['DualModeIndex'][0] |
|
366 | self.DualModeIndex = header['DualModeIndex'][0] | |
367 | self.DualModeRange = header['DualModeRange'][0] |
|
367 | self.DualModeRange = header['DualModeRange'][0] | |
368 | self.nDigChannels = header['nDigChannels'][0] |
|
368 | self.nDigChannels = header['nDigChannels'][0] | |
369 | self.SampResolution = header['SampResolution'][0] |
|
369 | self.SampResolution = header['SampResolution'][0] | |
370 | self.nHeights = header['nHeights'][0] |
|
370 | self.nHeights = header['nHeights'][0] | |
371 | self.StartRangeSamp = header['StartRangeSamp'][0] |
|
371 | self.StartRangeSamp = header['StartRangeSamp'][0] | |
372 | self.PRFhz = header['PRFhz'][0] |
|
372 | self.PRFhz = header['PRFhz'][0] | |
373 | self.nCohInt = header['nCohInt'][0] |
|
373 | self.nCohInt = header['nCohInt'][0] | |
374 | self.nProfiles = header['nProfiles'][0] |
|
374 | self.nProfiles = header['nProfiles'][0] | |
375 | self.nChannels = header['nChannels'][0] |
|
375 | self.nChannels = header['nChannels'][0] | |
376 | self.nIncohInt = header['nIncohInt'][0] |
|
376 | self.nIncohInt = header['nIncohInt'][0] | |
377 | self.FFTwindowingInd = header['FFTwindowingInd'][0] |
|
377 | self.FFTwindowingInd = header['FFTwindowingInd'][0] | |
378 | self.BeamAngleAzim = header['BeamAngleAzim'][0] |
|
378 | self.BeamAngleAzim = header['BeamAngleAzim'][0] | |
379 | self.BeamAngleZen = header['BeamAngleZen'][0] |
|
379 | self.BeamAngleZen = header['BeamAngleZen'][0] | |
380 | self.AntennaCoord0 = header['AntennaCoord0'][0] |
|
380 | self.AntennaCoord0 = header['AntennaCoord0'][0] | |
381 | self.AntennaAngl0 = header['AntennaAngl0'][0] |
|
381 | self.AntennaAngl0 = header['AntennaAngl0'][0] | |
382 | self.AntennaCoord1 = header['AntennaCoord1'][0] |
|
382 | self.AntennaCoord1 = header['AntennaCoord1'][0] | |
383 | self.AntennaAngl1 = header['AntennaAngl1'][0] |
|
383 | self.AntennaAngl1 = header['AntennaAngl1'][0] | |
384 | self.AntennaCoord2 = header['AntennaCoord2'][0] |
|
384 | self.AntennaCoord2 = header['AntennaCoord2'][0] | |
385 | self.AntennaAngl2 = header['AntennaAngl2'][0] |
|
385 | self.AntennaAngl2 = header['AntennaAngl2'][0] | |
386 | self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0] |
|
386 | self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0] | |
387 | self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0] |
|
387 | self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0] | |
388 | self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0] |
|
388 | self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0] | |
389 | self.RecAmpCalibr0 = header['RecAmpCalibr0'][0] |
|
389 | self.RecAmpCalibr0 = header['RecAmpCalibr0'][0] | |
390 | self.RecAmpCalibr1 = header['RecAmpCalibr1'][0] |
|
390 | self.RecAmpCalibr1 = header['RecAmpCalibr1'][0] | |
391 | self.RecAmpCalibr2 = header['RecAmpCalibr2'][0] |
|
391 | self.RecAmpCalibr2 = header['RecAmpCalibr2'][0] | |
392 | self.ReceiverGaindB0 = header['ReceiverGaindB0'][0] |
|
392 | self.ReceiverGaindB0 = header['ReceiverGaindB0'][0] | |
393 | self.ReceiverGaindB1 = header['ReceiverGaindB1'][0] |
|
393 | self.ReceiverGaindB1 = header['ReceiverGaindB1'][0] | |
394 | self.ReceiverGaindB2 = header['ReceiverGaindB2'][0] |
|
394 | self.ReceiverGaindB2 = header['ReceiverGaindB2'][0] | |
395 |
|
395 | |||
396 | self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz) |
|
396 | self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz) | |
397 |
|
397 | |||
398 | self.RHsize = 180 + 20 * self.nChannels |
|
398 | self.RHsize = 180 + 20 * self.nChannels | |
399 | self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4 |
|
399 | self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4 | |
400 | # print 'Datasize',self.Datasize |
|
400 | # print 'Datasize',self.Datasize | |
401 | endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec |
|
401 | endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec | |
402 |
|
402 | |||
403 | print '==============================================' |
|
403 | print '==============================================' | |
404 | print 'RecMgcNumber ', self.RecMgcNumber |
|
404 | print 'RecMgcNumber ', self.RecMgcNumber | |
405 | print 'RecCounter ', self.RecCounter |
|
405 | print 'RecCounter ', self.RecCounter | |
406 | print 'Off2StartNxtRec ', self.Off2StartNxtRec |
|
406 | print 'Off2StartNxtRec ', self.Off2StartNxtRec | |
407 | print 'Off2StartData ', self.Off2StartData |
|
407 | print 'Off2StartData ', self.Off2StartData | |
408 | print 'Range Resolution ', self.SampResolution |
|
408 | print 'Range Resolution ', self.SampResolution | |
409 | print 'First Height ', self.StartRangeSamp |
|
409 | print 'First Height ', self.StartRangeSamp | |
410 | print 'PRF (Hz) ', self.PRFhz |
|
410 | print 'PRF (Hz) ', self.PRFhz | |
411 | print 'Heights (K) ', self.nHeights |
|
411 | print 'Heights (K) ', self.nHeights | |
412 | print 'Channels (N) ', self.nChannels |
|
412 | print 'Channels (N) ', self.nChannels | |
413 | print 'Profiles (J) ', self.nProfiles |
|
413 | print 'Profiles (J) ', self.nProfiles | |
414 | print 'iCoh ', self.nCohInt |
|
414 | print 'iCoh ', self.nCohInt | |
415 | print 'iInCoh ', self.nIncohInt |
|
415 | print 'iInCoh ', self.nIncohInt | |
416 | print 'BeamAngleAzim ', self.BeamAngleAzim |
|
416 | print 'BeamAngleAzim ', self.BeamAngleAzim | |
417 | print 'BeamAngleZen ', self.BeamAngleZen |
|
417 | print 'BeamAngleZen ', self.BeamAngleZen | |
418 |
|
418 | |||
419 | # print 'ModoEnUso ',self.DualModeIndex |
|
419 | # print 'ModoEnUso ',self.DualModeIndex | |
420 | # print 'UtcTime ',self.nUtime |
|
420 | # print 'UtcTime ',self.nUtime | |
421 | # print 'MiliSec ',self.nMilisec |
|
421 | # print 'MiliSec ',self.nMilisec | |
422 | # print 'Exp TagName ',self.ExpTagName |
|
422 | # print 'Exp TagName ',self.ExpTagName | |
423 | # print 'Exp Comment ',self.ExpComment |
|
423 | # print 'Exp Comment ',self.ExpComment | |
424 | # print 'FFT Window Index ',self.FFTwindowingInd |
|
424 | # print 'FFT Window Index ',self.FFTwindowingInd | |
425 | # print 'N Dig. Channels ',self.nDigChannels |
|
425 | # print 'N Dig. Channels ',self.nDigChannels | |
426 | print 'Size de bloque ', self.RHsize |
|
426 | print 'Size de bloque ', self.RHsize | |
427 | print 'DataSize ', self.Datasize |
|
427 | print 'DataSize ', self.Datasize | |
428 | print 'BeamAngleAzim ', self.BeamAngleAzim |
|
428 | print 'BeamAngleAzim ', self.BeamAngleAzim | |
429 | # print 'AntennaCoord0 ',self.AntennaCoord0 |
|
429 | # print 'AntennaCoord0 ',self.AntennaCoord0 | |
430 | # print 'AntennaAngl0 ',self.AntennaAngl0 |
|
430 | # print 'AntennaAngl0 ',self.AntennaAngl0 | |
431 | # print 'AntennaCoord1 ',self.AntennaCoord1 |
|
431 | # print 'AntennaCoord1 ',self.AntennaCoord1 | |
432 | # print 'AntennaAngl1 ',self.AntennaAngl1 |
|
432 | # print 'AntennaAngl1 ',self.AntennaAngl1 | |
433 | # print 'AntennaCoord2 ',self.AntennaCoord2 |
|
433 | # print 'AntennaCoord2 ',self.AntennaCoord2 | |
434 | # print 'AntennaAngl2 ',self.AntennaAngl2 |
|
434 | # print 'AntennaAngl2 ',self.AntennaAngl2 | |
435 | print 'RecPhaseCalibr0 ', self.RecPhaseCalibr0 |
|
435 | print 'RecPhaseCalibr0 ', self.RecPhaseCalibr0 | |
436 | print 'RecPhaseCalibr1 ', self.RecPhaseCalibr1 |
|
436 | print 'RecPhaseCalibr1 ', self.RecPhaseCalibr1 | |
437 | print 'RecPhaseCalibr2 ', self.RecPhaseCalibr2 |
|
437 | print 'RecPhaseCalibr2 ', self.RecPhaseCalibr2 | |
438 | print 'RecAmpCalibr0 ', self.RecAmpCalibr0 |
|
438 | print 'RecAmpCalibr0 ', self.RecAmpCalibr0 | |
439 | print 'RecAmpCalibr1 ', self.RecAmpCalibr1 |
|
439 | print 'RecAmpCalibr1 ', self.RecAmpCalibr1 | |
440 | print 'RecAmpCalibr2 ', self.RecAmpCalibr2 |
|
440 | print 'RecAmpCalibr2 ', self.RecAmpCalibr2 | |
441 | print 'ReceiverGaindB0 ', self.ReceiverGaindB0 |
|
441 | print 'ReceiverGaindB0 ', self.ReceiverGaindB0 | |
442 | print 'ReceiverGaindB1 ', self.ReceiverGaindB1 |
|
442 | print 'ReceiverGaindB1 ', self.ReceiverGaindB1 | |
443 | print 'ReceiverGaindB2 ', self.ReceiverGaindB2 |
|
443 | print 'ReceiverGaindB2 ', self.ReceiverGaindB2 | |
444 | print '==============================================' |
|
444 | print '==============================================' | |
445 |
|
445 | |||
446 | if OffRHeader > endFp: |
|
446 | if OffRHeader > endFp: | |
447 | sys.stderr.write( |
|
447 | sys.stderr.write( | |
448 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp) |
|
448 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp) | |
449 | return 0 |
|
449 | return 0 | |
450 |
|
450 | |||
451 | if OffRHeader < endFp: |
|
451 | if OffRHeader < endFp: | |
452 | sys.stderr.write( |
|
452 | sys.stderr.write( | |
453 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp) |
|
453 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp) | |
454 | return 0 |
|
454 | return 0 | |
455 |
|
455 | |||
456 | return 1 |
|
456 | return 1 | |
457 |
|
457 | |||
458 |
|
458 | |||
459 | class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader): |
|
459 | class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader): | |
460 |
|
460 | |||
461 | path = None |
|
461 | path = None | |
462 | startDate = None |
|
462 | startDate = None | |
463 | endDate = None |
|
463 | endDate = None | |
464 | startTime = None |
|
464 | startTime = None | |
465 | endTime = None |
|
465 | endTime = None | |
466 | walk = None |
|
466 | walk = None | |
467 | isConfig = False |
|
467 | isConfig = False | |
468 |
|
468 | |||
469 | fileList = None |
|
469 | fileList = None | |
470 |
|
470 | |||
471 | # metadata |
|
471 | # metadata | |
472 | TimeZone = None |
|
472 | TimeZone = None | |
473 | Interval = None |
|
473 | Interval = None | |
474 | heightList = None |
|
474 | heightList = None | |
475 |
|
475 | |||
476 | # data |
|
476 | # data | |
477 | data = None |
|
477 | data = None | |
478 | utctime = None |
|
478 | utctime = None | |
479 |
|
479 | |||
480 | def __init__(self, **kwargs): |
|
480 | def __init__(self, **kwargs): | |
481 |
|
481 | |||
482 | # Eliminar de la base la herencia |
|
482 | # Eliminar de la base la herencia | |
483 | ProcessingUnit.__init__(self, **kwargs) |
|
483 | ProcessingUnit.__init__(self, **kwargs) | |
484 |
|
484 | |||
485 | #self.isConfig = False |
|
485 | #self.isConfig = False | |
486 |
|
486 | |||
487 | #self.pts2read_SelfSpectra = 0 |
|
487 | #self.pts2read_SelfSpectra = 0 | |
488 | #self.pts2read_CrossSpectra = 0 |
|
488 | #self.pts2read_CrossSpectra = 0 | |
489 | #self.pts2read_DCchannels = 0 |
|
489 | #self.pts2read_DCchannels = 0 | |
490 | #self.datablock = None |
|
490 | #self.datablock = None | |
491 | self.utc = None |
|
491 | self.utc = None | |
492 | self.ext = ".fdt" |
|
492 | self.ext = ".fdt" | |
493 | self.optchar = "P" |
|
493 | self.optchar = "P" | |
494 | self.fpFile = None |
|
494 | self.fpFile = None | |
495 | self.fp = None |
|
495 | self.fp = None | |
496 | self.BlockCounter = 0 |
|
496 | self.BlockCounter = 0 | |
497 | self.dtype = None |
|
497 | self.dtype = None | |
498 | self.fileSizeByHeader = None |
|
498 | self.fileSizeByHeader = None | |
499 | self.filenameList = [] |
|
499 | self.filenameList = [] | |
500 | self.fileSelector = 0 |
|
500 | self.fileSelector = 0 | |
501 | self.Off2StartNxtRec = 0 |
|
501 | self.Off2StartNxtRec = 0 | |
502 | self.RecCounter = 0 |
|
502 | self.RecCounter = 0 | |
503 | self.flagNoMoreFiles = 0 |
|
503 | self.flagNoMoreFiles = 0 | |
504 | self.data_spc = None |
|
504 | self.data_spc = None | |
505 | self.data_cspc = None |
|
505 | self.data_cspc = None | |
506 | self.data_output = None |
|
506 | self.data_output = None | |
507 | self.path = None |
|
507 | self.path = None | |
508 | self.OffsetStartHeader = 0 |
|
508 | self.OffsetStartHeader = 0 | |
509 | self.Off2StartData = 0 |
|
509 | self.Off2StartData = 0 | |
510 | self.ipp = 0 |
|
510 | self.ipp = 0 | |
511 | self.nFDTdataRecors = 0 |
|
511 | self.nFDTdataRecors = 0 | |
512 | self.blocksize = 0 |
|
512 | self.blocksize = 0 | |
513 | self.dataOut = Spectra() |
|
513 | self.dataOut = Spectra() | |
514 | self.profileIndex = 1 # Always |
|
514 | self.profileIndex = 1 # Always | |
515 | self.dataOut.flagNoData = False |
|
515 | self.dataOut.flagNoData = False | |
516 | self.dataOut.nRdPairs = 0 |
|
516 | self.dataOut.nRdPairs = 0 | |
517 |
self.dataOut. |
|
517 | self.dataOut.data_spc = None | |
518 | self.dataOut.data_spc = None |
|
|||
519 | self.dataOut.noise = [] |
|
|||
520 | self.dataOut.velocityX = [] |
|
518 | self.dataOut.velocityX = [] | |
521 | self.dataOut.velocityY = [] |
|
519 | self.dataOut.velocityY = [] | |
522 | self.dataOut.velocityV = [] |
|
520 | self.dataOut.velocityV = [] | |
523 |
|
521 | |||
524 | def Files2Read(self, fp): |
|
522 | def Files2Read(self, fp): | |
525 | ''' |
|
523 | ''' | |
526 | Function that indicates the number of .fdt files that exist in the folder to be read. |
|
524 | Function that indicates the number of .fdt files that exist in the folder to be read. | |
527 | It also creates an organized list with the names of the files to read. |
|
525 | It also creates an organized list with the names of the files to read. | |
528 | ''' |
|
526 | ''' | |
529 | # self.__checkPath() |
|
527 | # self.__checkPath() | |
530 |
|
528 | |||
531 | # Gets the list of files within the fp address |
|
529 | # Gets the list of files within the fp address | |
532 | ListaData = os.listdir(fp) |
|
530 | ListaData = os.listdir(fp) | |
533 | # Sort the list of files from least to largest by names |
|
531 | # Sort the list of files from least to largest by names | |
534 | ListaData = sorted(ListaData) |
|
532 | ListaData = sorted(ListaData) | |
535 | nFiles = 0 # File Counter |
|
533 | nFiles = 0 # File Counter | |
536 | FileList = [] # A list is created that will contain the .fdt files |
|
534 | FileList = [] # A list is created that will contain the .fdt files | |
537 | for IndexFile in ListaData: |
|
535 | for IndexFile in ListaData: | |
538 | if '.fdt' in IndexFile: |
|
536 | if '.fdt' in IndexFile: | |
539 | FileList.append(IndexFile) |
|
537 | FileList.append(IndexFile) | |
540 | nFiles += 1 |
|
538 | nFiles += 1 | |
541 |
|
539 | |||
542 | # print 'Files2Read' |
|
540 | # print 'Files2Read' | |
543 | # print 'Existen '+str(nFiles)+' archivos .fdt' |
|
541 | # print 'Existen '+str(nFiles)+' archivos .fdt' | |
544 |
|
542 | |||
545 | self.filenameList = FileList # List of files from least to largest by names |
|
543 | self.filenameList = FileList # List of files from least to largest by names | |
546 |
|
544 | |||
547 | def run(self, **kwargs): |
|
545 | def run(self, **kwargs): | |
548 | ''' |
|
546 | ''' | |
549 | This method will be the one that will initiate the data entry, will be called constantly. |
|
547 | This method will be the one that will initiate the data entry, will be called constantly. | |
550 | You should first verify that your Setup () is set up and then continue to acquire |
|
548 | You should first verify that your Setup () is set up and then continue to acquire | |
551 | the data to be processed with getData (). |
|
549 | the data to be processed with getData (). | |
552 | ''' |
|
550 | ''' | |
553 | if not self.isConfig: |
|
551 | if not self.isConfig: | |
554 | self.setup(**kwargs) |
|
552 | self.setup(**kwargs) | |
555 | self.isConfig = True |
|
553 | self.isConfig = True | |
556 |
|
554 | |||
557 | self.getData() |
|
555 | self.getData() | |
558 | # print 'running' |
|
556 | # print 'running' | |
559 |
|
557 | |||
560 | def setup(self, path=None, |
|
558 | def setup(self, path=None, | |
561 | startDate=None, |
|
559 | startDate=None, | |
562 | endDate=None, |
|
560 | endDate=None, | |
563 | startTime=None, |
|
561 | startTime=None, | |
564 | endTime=None, |
|
562 | endTime=None, | |
565 | walk=True, |
|
563 | walk=True, | |
566 | timezone='utc', |
|
564 | timezone='utc', | |
567 | code=None, |
|
565 | code=None, | |
568 | online=False, |
|
566 | online=False, | |
569 | ReadMode=None, |
|
567 | ReadMode=None, | |
570 | **kwargs): |
|
568 | **kwargs): | |
571 |
|
569 | |||
572 | self.isConfig = True |
|
570 | self.isConfig = True | |
573 |
|
571 | |||
574 | self.path = path |
|
572 | self.path = path | |
575 | self.startDate = startDate |
|
573 | self.startDate = startDate | |
576 | self.endDate = endDate |
|
574 | self.endDate = endDate | |
577 | self.startTime = startTime |
|
575 | self.startTime = startTime | |
578 | self.endTime = endTime |
|
576 | self.endTime = endTime | |
579 | self.walk = walk |
|
577 | self.walk = walk | |
580 | self.ReadMode = int(ReadMode) |
|
578 | self.ReadMode = int(ReadMode) | |
581 |
|
579 | |||
582 | pass |
|
580 | pass | |
583 |
|
581 | |||
584 | def getData(self): |
|
582 | def getData(self): | |
585 | ''' |
|
583 | ''' | |
586 | Before starting this function, you should check that there is still an unread file, |
|
584 | Before starting this function, you should check that there is still an unread file, | |
587 | If there are still blocks to read or if the data block is empty. |
|
585 | If there are still blocks to read or if the data block is empty. | |
588 |
|
586 | |||
589 | You should call the file "read". |
|
587 | You should call the file "read". | |
590 |
|
588 | |||
591 | ''' |
|
589 | ''' | |
592 |
|
590 | |||
593 | if self.flagNoMoreFiles: |
|
591 | if self.flagNoMoreFiles: | |
594 | self.dataOut.flagNoData = True |
|
592 | self.dataOut.flagNoData = True | |
595 | print 'NoData se vuelve true' |
|
593 | print 'NoData se vuelve true' | |
596 | return 0 |
|
594 | return 0 | |
597 |
|
595 | |||
598 | self.fp = self.path |
|
596 | self.fp = self.path | |
599 | self.Files2Read(self.fp) |
|
597 | self.Files2Read(self.fp) | |
600 | self.readFile(self.fp) |
|
598 | self.readFile(self.fp) | |
601 | self.dataOut.data_spc = self.data_spc |
|
599 | self.dataOut.data_spc = self.data_spc | |
602 | self.dataOut.data_cspc = self.data_cspc |
|
600 | self.dataOut.data_cspc = self.data_cspc | |
603 | self.dataOut.data_output = self.data_output |
|
601 | self.dataOut.data_output = self.data_output | |
604 |
|
602 | |||
605 | print 'self.dataOut.data_output', shape(self.dataOut.data_output) |
|
603 | print 'self.dataOut.data_output', shape(self.dataOut.data_output) | |
606 |
|
604 | |||
607 | # self.removeDC() |
|
605 | # self.removeDC() | |
608 | return self.dataOut.data_spc |
|
606 | return self.dataOut.data_spc | |
609 |
|
607 | |||
610 | def readFile(self, fp): |
|
608 | def readFile(self, fp): | |
611 | ''' |
|
609 | ''' | |
612 | You must indicate if you are reading in Online or Offline mode and load the |
|
610 | You must indicate if you are reading in Online or Offline mode and load the | |
613 | The parameters for this file reading mode. |
|
611 | The parameters for this file reading mode. | |
614 |
|
612 | |||
615 | Then you must do 2 actions: |
|
613 | Then you must do 2 actions: | |
616 |
|
614 | |||
617 | 1. Get the BLTR FileHeader. |
|
615 | 1. Get the BLTR FileHeader. | |
618 | 2. Start reading the first block. |
|
616 | 2. Start reading the first block. | |
619 | ''' |
|
617 | ''' | |
620 |
|
618 | |||
621 | # The address of the folder is generated the name of the .fdt file that will be read |
|
619 | # The address of the folder is generated the name of the .fdt file that will be read | |
622 | print "File: ", self.fileSelector + 1 |
|
620 | print "File: ", self.fileSelector + 1 | |
623 |
|
621 | |||
624 | if self.fileSelector < len(self.filenameList): |
|
622 | if self.fileSelector < len(self.filenameList): | |
625 |
|
623 | |||
626 | self.fpFile = str(fp) + '/' + \ |
|
624 | self.fpFile = str(fp) + '/' + \ | |
627 | str(self.filenameList[self.fileSelector]) |
|
625 | str(self.filenameList[self.fileSelector]) | |
628 | # print self.fpFile |
|
626 | # print self.fpFile | |
629 | fheader = FileHeaderBLTR() |
|
627 | fheader = FileHeaderBLTR() | |
630 | fheader.FHread(self.fpFile) # Bltr FileHeader Reading |
|
628 | fheader.FHread(self.fpFile) # Bltr FileHeader Reading | |
631 | self.nFDTdataRecors = fheader.nFDTdataRecors |
|
629 | self.nFDTdataRecors = fheader.nFDTdataRecors | |
632 |
|
630 | |||
633 | self.readBlock() # Block reading |
|
631 | self.readBlock() # Block reading | |
634 | else: |
|
632 | else: | |
635 | print 'readFile FlagNoData becomes true' |
|
633 | print 'readFile FlagNoData becomes true' | |
636 | self.flagNoMoreFiles = True |
|
634 | self.flagNoMoreFiles = True | |
637 | self.dataOut.flagNoData = True |
|
635 | self.dataOut.flagNoData = True | |
638 | return 0 |
|
636 | return 0 | |
639 |
|
637 | |||
640 | def getVelRange(self, extrapoints=0): |
|
638 | def getVelRange(self, extrapoints=0): | |
641 | Lambda = SPEED_OF_LIGHT / 50000000 |
|
639 | Lambda = SPEED_OF_LIGHT / 50000000 | |
642 | # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt) |
|
640 | # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt) | |
643 | PRF = self.dataOut.PRF |
|
641 | PRF = self.dataOut.PRF | |
644 | Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.) |
|
642 | Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.) | |
645 | deltafreq = PRF / (self.nProfiles) |
|
643 | deltafreq = PRF / (self.nProfiles) | |
646 | deltavel = (Vmax * 2) / (self.nProfiles) |
|
644 | deltavel = (Vmax * 2) / (self.nProfiles) | |
647 | freqrange = deltafreq * \ |
|
645 | freqrange = deltafreq * \ | |
648 | (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2 |
|
646 | (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2 | |
649 | velrange = deltavel * \ |
|
647 | velrange = deltavel * \ | |
650 | (numpy.arange(self.nProfiles) - self.nProfiles / 2.) |
|
648 | (numpy.arange(self.nProfiles) - self.nProfiles / 2.) | |
651 | return velrange |
|
649 | return velrange | |
652 |
|
650 | |||
653 | def readBlock(self): |
|
651 | def readBlock(self): | |
654 | ''' |
|
652 | ''' | |
655 | It should be checked if the block has data, if it is not passed to the next file. |
|
653 | It should be checked if the block has data, if it is not passed to the next file. | |
656 |
|
654 | |||
657 | Then the following is done: |
|
655 | Then the following is done: | |
658 |
|
656 | |||
659 | 1. Read the RecordHeader |
|
657 | 1. Read the RecordHeader | |
660 | 2. Fill the buffer with the current block number. |
|
658 | 2. Fill the buffer with the current block number. | |
661 |
|
659 | |||
662 | ''' |
|
660 | ''' | |
663 |
|
661 | |||
664 | if self.BlockCounter < self.nFDTdataRecors - 2: |
|
662 | if self.BlockCounter < self.nFDTdataRecors - 2: | |
665 | print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' |
|
663 | print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' | |
666 | if self.ReadMode == 1: |
|
664 | if self.ReadMode == 1: | |
667 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter + 1) |
|
665 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter + 1) | |
668 | elif self.ReadMode == 0: |
|
666 | elif self.ReadMode == 0: | |
669 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter) |
|
667 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter) | |
670 |
|
668 | |||
671 | rheader.RHread(self.fpFile) # Bltr FileHeader Reading |
|
669 | rheader.RHread(self.fpFile) # Bltr FileHeader Reading | |
672 |
|
670 | |||
673 | self.OffsetStartHeader = rheader.OffsetStartHeader |
|
671 | self.OffsetStartHeader = rheader.OffsetStartHeader | |
674 | self.RecCounter = rheader.RecCounter |
|
672 | self.RecCounter = rheader.RecCounter | |
675 | self.Off2StartNxtRec = rheader.Off2StartNxtRec |
|
673 | self.Off2StartNxtRec = rheader.Off2StartNxtRec | |
676 | self.Off2StartData = rheader.Off2StartData |
|
674 | self.Off2StartData = rheader.Off2StartData | |
677 | self.nProfiles = rheader.nProfiles |
|
675 | self.nProfiles = rheader.nProfiles | |
678 | self.nChannels = rheader.nChannels |
|
676 | self.nChannels = rheader.nChannels | |
679 | self.nHeights = rheader.nHeights |
|
677 | self.nHeights = rheader.nHeights | |
680 | self.frequency = rheader.TransmitFrec |
|
678 | self.frequency = rheader.TransmitFrec | |
681 | self.DualModeIndex = rheader.DualModeIndex |
|
679 | self.DualModeIndex = rheader.DualModeIndex | |
682 |
|
680 | |||
683 | self.pairsList = [(0, 1), (0, 2), (1, 2)] |
|
681 | self.pairsList = [(0, 1), (0, 2), (1, 2)] | |
684 | self.dataOut.pairsList = self.pairsList |
|
682 | self.dataOut.pairsList = self.pairsList | |
685 |
|
683 | |||
686 | self.nRdPairs = len(self.dataOut.pairsList) |
|
684 | self.nRdPairs = len(self.dataOut.pairsList) | |
687 | self.dataOut.nRdPairs = self.nRdPairs |
|
685 | self.dataOut.nRdPairs = self.nRdPairs | |
688 |
|
686 | |||
689 | self.__firstHeigth = rheader.StartRangeSamp |
|
687 | self.__firstHeigth = rheader.StartRangeSamp | |
690 | self.__deltaHeigth = rheader.SampResolution |
|
688 | self.__deltaHeigth = rheader.SampResolution | |
691 | self.dataOut.heightList = self.__firstHeigth + \ |
|
689 | self.dataOut.heightList = self.__firstHeigth + \ | |
692 | numpy.array(range(self.nHeights)) * self.__deltaHeigth |
|
690 | numpy.array(range(self.nHeights)) * self.__deltaHeigth | |
693 | self.dataOut.channelList = range(self.nChannels) |
|
691 | self.dataOut.channelList = range(self.nChannels) | |
694 | self.dataOut.nProfiles = rheader.nProfiles |
|
692 | self.dataOut.nProfiles = rheader.nProfiles | |
695 | self.dataOut.nIncohInt = rheader.nIncohInt |
|
693 | self.dataOut.nIncohInt = rheader.nIncohInt | |
696 | self.dataOut.nCohInt = rheader.nCohInt |
|
694 | self.dataOut.nCohInt = rheader.nCohInt | |
697 | self.dataOut.ippSeconds = 1 / float(rheader.PRFhz) |
|
695 | self.dataOut.ippSeconds = 1 / float(rheader.PRFhz) | |
698 | self.dataOut.PRF = rheader.PRFhz |
|
696 | self.dataOut.PRF = rheader.PRFhz | |
699 | self.dataOut.nFFTPoints = rheader.nProfiles |
|
697 | self.dataOut.nFFTPoints = rheader.nProfiles | |
700 | self.dataOut.utctime = rheader.nUtime |
|
698 | self.dataOut.utctime = rheader.nUtime | |
701 | self.dataOut.timeZone = 0 |
|
699 | self.dataOut.timeZone = 0 | |
702 | self.dataOut.normFactor = self.dataOut.nProfiles * \ |
|
700 | self.dataOut.normFactor = self.dataOut.nProfiles * \ | |
703 | self.dataOut.nIncohInt * self.dataOut.nCohInt |
|
701 | self.dataOut.nIncohInt * self.dataOut.nCohInt | |
704 | self.dataOut.outputInterval = self.dataOut.ippSeconds * \ |
|
702 | self.dataOut.outputInterval = self.dataOut.ippSeconds * \ | |
705 | self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles |
|
703 | self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles | |
706 |
|
704 | |||
707 | self.data_output = numpy.ones([3, rheader.nHeights]) * numpy.NaN |
|
705 | self.data_output = numpy.ones([3, rheader.nHeights]) * numpy.NaN | |
708 | print 'self.data_output', shape(self.data_output) |
|
706 | print 'self.data_output', shape(self.data_output) | |
709 | self.dataOut.velocityX = [] |
|
707 | self.dataOut.velocityX = [] | |
710 | self.dataOut.velocityY = [] |
|
708 | self.dataOut.velocityY = [] | |
711 | self.dataOut.velocityV = [] |
|
709 | self.dataOut.velocityV = [] | |
712 |
|
710 | |||
713 | '''Block Reading, the Block Data is received and Reshape is used to give it |
|
711 | '''Block Reading, the Block Data is received and Reshape is used to give it | |
714 | shape. |
|
712 | shape. | |
715 | ''' |
|
713 | ''' | |
716 |
|
714 | |||
717 | # Procedure to take the pointer to where the date block starts |
|
715 | # Procedure to take the pointer to where the date block starts | |
718 | startDATA = open(self.fpFile, "rb") |
|
716 | startDATA = open(self.fpFile, "rb") | |
719 | OffDATA = self.OffsetStartHeader + self.RecCounter * \ |
|
717 | OffDATA = self.OffsetStartHeader + self.RecCounter * \ | |
720 | self.Off2StartNxtRec + self.Off2StartData |
|
718 | self.Off2StartNxtRec + self.Off2StartData | |
721 | startDATA.seek(OffDATA, os.SEEK_SET) |
|
719 | startDATA.seek(OffDATA, os.SEEK_SET) | |
722 |
|
720 | |||
723 | def moving_average(x, N=2): |
|
721 | def moving_average(x, N=2): | |
724 | return numpy.convolve(x, numpy.ones((N,)) / N)[(N - 1):] |
|
722 | return numpy.convolve(x, numpy.ones((N,)) / N)[(N - 1):] | |
725 |
|
723 | |||
726 | def gaus(xSamples, a, x0, sigma): |
|
724 | def gaus(xSamples, a, x0, sigma): | |
727 | return a * exp(-(xSamples - x0)**2 / (2 * sigma**2)) |
|
725 | return a * exp(-(xSamples - x0)**2 / (2 * sigma**2)) | |
728 |
|
726 | |||
729 | def Find(x, value): |
|
727 | def Find(x, value): | |
730 | for index in range(len(x)): |
|
728 | for index in range(len(x)): | |
731 | if x[index] == value: |
|
729 | if x[index] == value: | |
732 | return index |
|
730 | return index | |
733 |
|
731 | |||
734 | def pol2cart(rho, phi): |
|
732 | def pol2cart(rho, phi): | |
735 | x = rho * numpy.cos(phi) |
|
733 | x = rho * numpy.cos(phi) | |
736 | y = rho * numpy.sin(phi) |
|
734 | y = rho * numpy.sin(phi) | |
737 | return(x, y) |
|
735 | return(x, y) | |
738 |
|
736 | |||
739 | if self.DualModeIndex == self.ReadMode: |
|
737 | if self.DualModeIndex == self.ReadMode: | |
740 |
|
738 | |||
741 | self.data_fft = numpy.fromfile( |
|
739 | self.data_fft = numpy.fromfile( | |
742 | startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights) |
|
740 | startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights) | |
743 |
|
741 | |||
744 | self.data_fft = self.data_fft.astype(numpy.dtype('complex')) |
|
742 | self.data_fft = self.data_fft.astype(numpy.dtype('complex')) | |
745 |
|
743 | |||
746 | self.data_block = numpy.reshape( |
|
744 | self.data_block = numpy.reshape( | |
747 | self.data_fft, (self.nHeights, self.nChannels, self.nProfiles)) |
|
745 | self.data_fft, (self.nHeights, self.nChannels, self.nProfiles)) | |
748 |
|
746 | |||
749 | self.data_block = numpy.transpose(self.data_block, (1, 2, 0)) |
|
747 | self.data_block = numpy.transpose(self.data_block, (1, 2, 0)) | |
750 |
|
748 | |||
751 | copy = self.data_block.copy() |
|
749 | copy = self.data_block.copy() | |
752 | spc = copy * numpy.conjugate(copy) |
|
750 | spc = copy * numpy.conjugate(copy) | |
753 |
|
751 | |||
754 | self.data_spc = numpy.absolute( |
|
752 | self.data_spc = numpy.absolute( | |
755 | spc) # valor absoluto o magnitud |
|
753 | spc) # valor absoluto o magnitud | |
756 |
|
754 | |||
757 | factor = self.dataOut.normFactor |
|
755 | factor = self.dataOut.normFactor | |
758 |
|
756 | |||
759 | z = self.data_spc.copy() # /factor |
|
757 | z = self.data_spc.copy() # /factor | |
760 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
758 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
761 | #zdB = 10*numpy.log10(z) |
|
759 | #zdB = 10*numpy.log10(z) | |
762 | print ' ' |
|
760 | print ' ' | |
763 | print 'Z: ' |
|
761 | print 'Z: ' | |
764 | print shape(z) |
|
762 | print shape(z) | |
765 | print ' ' |
|
763 | print ' ' | |
766 | print ' ' |
|
764 | print ' ' | |
767 |
|
765 | |||
768 | self.dataOut.data_spc = self.data_spc |
|
766 | self.dataOut.data_spc = self.data_spc | |
769 |
|
767 | |||
770 | self.noise = self.dataOut.getNoise( |
|
768 | self.noise = self.dataOut.getNoise( | |
771 | ymin_index=80, ymax_index=132) # /factor |
|
769 | ymin_index=80, ymax_index=132) # /factor | |
772 | #noisedB = 10*numpy.log10(self.noise) |
|
770 | #noisedB = 10*numpy.log10(self.noise) | |
773 |
|
771 | |||
774 | ySamples = numpy.ones([3, self.nProfiles]) |
|
772 | ySamples = numpy.ones([3, self.nProfiles]) | |
775 | phase = numpy.ones([3, self.nProfiles]) |
|
773 | phase = numpy.ones([3, self.nProfiles]) | |
776 | CSPCSamples = numpy.ones( |
|
774 | CSPCSamples = numpy.ones( | |
777 | [3, self.nProfiles], dtype=numpy.complex_) |
|
775 | [3, self.nProfiles], dtype=numpy.complex_) | |
778 | coherence = numpy.ones([3, self.nProfiles]) |
|
776 | coherence = numpy.ones([3, self.nProfiles]) | |
779 | PhaseSlope = numpy.ones(3) |
|
777 | PhaseSlope = numpy.ones(3) | |
780 | PhaseInter = numpy.ones(3) |
|
778 | PhaseInter = numpy.ones(3) | |
781 |
|
779 | |||
782 | '''****** Getting CrossSpectra ******''' |
|
780 | '''****** Getting CrossSpectra ******''' | |
783 | cspc = self.data_block.copy() |
|
781 | cspc = self.data_block.copy() | |
784 | self.data_cspc = self.data_block.copy() |
|
782 | self.data_cspc = self.data_block.copy() | |
785 |
|
783 | |||
786 | xFrec = self.getVelRange(1) |
|
784 | xFrec = self.getVelRange(1) | |
787 | VelRange = self.getVelRange(1) |
|
785 | VelRange = self.getVelRange(1) | |
788 | self.dataOut.VelRange = VelRange |
|
786 | self.dataOut.VelRange = VelRange | |
789 | # print ' ' |
|
787 | # print ' ' | |
790 | # print ' ' |
|
788 | # print ' ' | |
791 | # print 'xFrec',xFrec |
|
789 | # print 'xFrec',xFrec | |
792 | # print ' ' |
|
790 | # print ' ' | |
793 | # print ' ' |
|
791 | # print ' ' | |
794 | # Height=35 |
|
792 | # Height=35 | |
795 | for i in range(self.nRdPairs): |
|
793 | for i in range(self.nRdPairs): | |
796 |
|
794 | |||
797 | chan_index0 = self.dataOut.pairsList[i][0] |
|
795 | chan_index0 = self.dataOut.pairsList[i][0] | |
798 | chan_index1 = self.dataOut.pairsList[i][1] |
|
796 | chan_index1 = self.dataOut.pairsList[i][1] | |
799 |
|
797 | |||
800 | self.data_cspc[i, :, :] = cspc[chan_index0, :, |
|
798 | self.data_cspc[i, :, :] = cspc[chan_index0, :, | |
801 | :] * numpy.conjugate(cspc[chan_index1, :, :]) |
|
799 | :] * numpy.conjugate(cspc[chan_index1, :, :]) | |
802 |
|
800 | |||
803 | '''Getting Eij and Nij''' |
|
801 | '''Getting Eij and Nij''' | |
804 | (AntennaX0, AntennaY0) = pol2cart( |
|
802 | (AntennaX0, AntennaY0) = pol2cart( | |
805 | rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180) |
|
803 | rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180) | |
806 | (AntennaX1, AntennaY1) = pol2cart( |
|
804 | (AntennaX1, AntennaY1) = pol2cart( | |
807 | rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180) |
|
805 | rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180) | |
808 | (AntennaX2, AntennaY2) = pol2cart( |
|
806 | (AntennaX2, AntennaY2) = pol2cart( | |
809 | rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180) |
|
807 | rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180) | |
810 |
|
808 | |||
811 | E01 = AntennaX0 - AntennaX1 |
|
809 | E01 = AntennaX0 - AntennaX1 | |
812 | N01 = AntennaY0 - AntennaY1 |
|
810 | N01 = AntennaY0 - AntennaY1 | |
813 |
|
811 | |||
814 | E02 = AntennaX0 - AntennaX2 |
|
812 | E02 = AntennaX0 - AntennaX2 | |
815 | N02 = AntennaY0 - AntennaY2 |
|
813 | N02 = AntennaY0 - AntennaY2 | |
816 |
|
814 | |||
817 | E12 = AntennaX1 - AntennaX2 |
|
815 | E12 = AntennaX1 - AntennaX2 | |
818 | N12 = AntennaY1 - AntennaY2 |
|
816 | N12 = AntennaY1 - AntennaY2 | |
819 |
|
817 | |||
820 | self.ChanDist = numpy.array( |
|
818 | self.ChanDist = numpy.array( | |
821 | [[E01, N01], [E02, N02], [E12, N12]]) |
|
819 | [[E01, N01], [E02, N02], [E12, N12]]) | |
822 |
|
820 | |||
823 | self.dataOut.ChanDist = self.ChanDist |
|
821 | self.dataOut.ChanDist = self.ChanDist | |
824 |
|
822 | |||
825 |
|
823 | |||
826 | # for Height in range(self.nHeights): |
|
824 | # for Height in range(self.nHeights): | |
827 | # |
|
825 | # | |
828 | # for i in range(self.nRdPairs): |
|
826 | # for i in range(self.nRdPairs): | |
829 | # |
|
827 | # | |
830 | # '''****** Line of Data SPC ******''' |
|
828 | # '''****** Line of Data SPC ******''' | |
831 | # zline=z[i,:,Height] |
|
829 | # zline=z[i,:,Height] | |
832 | # |
|
830 | # | |
833 | # '''****** DC is removed ******''' |
|
831 | # '''****** DC is removed ******''' | |
834 | # DC=Find(zline,numpy.amax(zline)) |
|
832 | # DC=Find(zline,numpy.amax(zline)) | |
835 | # zline[DC]=(zline[DC-1]+zline[DC+1])/2 |
|
833 | # zline[DC]=(zline[DC-1]+zline[DC+1])/2 | |
836 | # |
|
834 | # | |
837 | # |
|
835 | # | |
838 | # '''****** SPC is normalized ******''' |
|
836 | # '''****** SPC is normalized ******''' | |
839 | # FactNorm= zline.copy() / numpy.sum(zline.copy()) |
|
837 | # FactNorm= zline.copy() / numpy.sum(zline.copy()) | |
840 | # FactNorm= FactNorm/numpy.sum(FactNorm) |
|
838 | # FactNorm= FactNorm/numpy.sum(FactNorm) | |
841 | # |
|
839 | # | |
842 | # SmoothSPC=moving_average(FactNorm,N=3) |
|
840 | # SmoothSPC=moving_average(FactNorm,N=3) | |
843 | # |
|
841 | # | |
844 | # xSamples = ar(range(len(SmoothSPC))) |
|
842 | # xSamples = ar(range(len(SmoothSPC))) | |
845 | # ySamples[i] = SmoothSPC-self.noise[i] |
|
843 | # ySamples[i] = SmoothSPC-self.noise[i] | |
846 | # |
|
844 | # | |
847 | # for i in range(self.nRdPairs): |
|
845 | # for i in range(self.nRdPairs): | |
848 | # |
|
846 | # | |
849 | # '''****** Line of Data CSPC ******''' |
|
847 | # '''****** Line of Data CSPC ******''' | |
850 | # cspcLine=self.data_cspc[i,:,Height].copy() |
|
848 | # cspcLine=self.data_cspc[i,:,Height].copy() | |
851 | # |
|
849 | # | |
852 | # |
|
850 | # | |
853 | # |
|
851 | # | |
854 | # '''****** CSPC is normalized ******''' |
|
852 | # '''****** CSPC is normalized ******''' | |
855 | # chan_index0 = self.dataOut.pairsList[i][0] |
|
853 | # chan_index0 = self.dataOut.pairsList[i][0] | |
856 | # chan_index1 = self.dataOut.pairsList[i][1] |
|
854 | # chan_index1 = self.dataOut.pairsList[i][1] | |
857 | # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1]) |
|
855 | # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1]) | |
858 | # |
|
856 | # | |
859 | # |
|
857 | # | |
860 | # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor) |
|
858 | # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor) | |
861 | # |
|
859 | # | |
862 | # |
|
860 | # | |
863 | # CSPCSamples[i] = CSPCNorm-self.noise[i] |
|
861 | # CSPCSamples[i] = CSPCNorm-self.noise[i] | |
864 | # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor) |
|
862 | # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor) | |
865 | # |
|
863 | # | |
866 | # '''****** DC is removed ******''' |
|
864 | # '''****** DC is removed ******''' | |
867 | # DC=Find(coherence[i],numpy.amax(coherence[i])) |
|
865 | # DC=Find(coherence[i],numpy.amax(coherence[i])) | |
868 | # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2 |
|
866 | # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2 | |
869 | # coherence[i]= moving_average(coherence[i],N=2) |
|
867 | # coherence[i]= moving_average(coherence[i],N=2) | |
870 | # |
|
868 | # | |
871 | # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi |
|
869 | # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi | |
872 | # |
|
870 | # | |
873 | # |
|
871 | # | |
874 | # '''****** Getting fij width ******''' |
|
872 | # '''****** Getting fij width ******''' | |
875 | # |
|
873 | # | |
876 | # yMean=[] |
|
874 | # yMean=[] | |
877 | # yMean2=[] |
|
875 | # yMean2=[] | |
878 | # |
|
876 | # | |
879 | # for j in range(len(ySamples[1])): |
|
877 | # for j in range(len(ySamples[1])): | |
880 | # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]])) |
|
878 | # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]])) | |
881 | # |
|
879 | # | |
882 | # '''******* Getting fitting Gaussian ******''' |
|
880 | # '''******* Getting fitting Gaussian ******''' | |
883 | # meanGauss=sum(xSamples*yMean) / len(xSamples) |
|
881 | # meanGauss=sum(xSamples*yMean) / len(xSamples) | |
884 | # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) |
|
882 | # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) | |
885 | # #print 'Height',Height,'SNR', meanGauss/sigma**2 |
|
883 | # #print 'Height',Height,'SNR', meanGauss/sigma**2 | |
886 | # |
|
884 | # | |
887 | # if (abs(meanGauss/sigma**2) > 0.0001) : |
|
885 | # if (abs(meanGauss/sigma**2) > 0.0001) : | |
888 | # |
|
886 | # | |
889 | # try: |
|
887 | # try: | |
890 | # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma]) |
|
888 | # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma]) | |
891 | # |
|
889 | # | |
892 | # if numpy.amax(popt)>numpy.amax(yMean)*0.3: |
|
890 | # if numpy.amax(popt)>numpy.amax(yMean)*0.3: | |
893 | # FitGauss=gaus(xSamples,*popt) |
|
891 | # FitGauss=gaus(xSamples,*popt) | |
894 | # |
|
892 | # | |
895 | # else: |
|
893 | # else: | |
896 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) |
|
894 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
897 | # print 'Verificador: Dentro', Height |
|
895 | # print 'Verificador: Dentro', Height | |
898 | # except RuntimeError: |
|
896 | # except RuntimeError: | |
899 | # |
|
897 | # | |
900 | # try: |
|
898 | # try: | |
901 | # for j in range(len(ySamples[1])): |
|
899 | # for j in range(len(ySamples[1])): | |
902 | # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]])) |
|
900 | # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]])) | |
903 | # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma]) |
|
901 | # popt,pcov = curve_fit(gaus,xSamples,yMean2,p0=[1,meanGauss,sigma]) | |
904 | # FitGauss=gaus(xSamples,*popt) |
|
902 | # FitGauss=gaus(xSamples,*popt) | |
905 | # print 'Verificador: Exepcion1', Height |
|
903 | # print 'Verificador: Exepcion1', Height | |
906 | # except RuntimeError: |
|
904 | # except RuntimeError: | |
907 | # |
|
905 | # | |
908 | # try: |
|
906 | # try: | |
909 | # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma]) |
|
907 | # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma]) | |
910 | # FitGauss=gaus(xSamples,*popt) |
|
908 | # FitGauss=gaus(xSamples,*popt) | |
911 | # print 'Verificador: Exepcion2', Height |
|
909 | # print 'Verificador: Exepcion2', Height | |
912 | # except RuntimeError: |
|
910 | # except RuntimeError: | |
913 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) |
|
911 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
914 | # print 'Verificador: Exepcion3', Height |
|
912 | # print 'Verificador: Exepcion3', Height | |
915 | # else: |
|
913 | # else: | |
916 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) |
|
914 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) | |
917 | # #print 'Verificador: Fuera', Height |
|
915 | # #print 'Verificador: Fuera', Height | |
918 | # |
|
916 | # | |
919 | # |
|
917 | # | |
920 | # |
|
918 | # | |
921 | # Maximun=numpy.amax(yMean) |
|
919 | # Maximun=numpy.amax(yMean) | |
922 | # eMinus1=Maximun*numpy.exp(-1) |
|
920 | # eMinus1=Maximun*numpy.exp(-1) | |
923 | # |
|
921 | # | |
924 | # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1))) |
|
922 | # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1))) | |
925 | # HalfWidth= xFrec[HWpos] |
|
923 | # HalfWidth= xFrec[HWpos] | |
926 | # GCpos=Find(FitGauss, numpy.amax(FitGauss)) |
|
924 | # GCpos=Find(FitGauss, numpy.amax(FitGauss)) | |
927 | # Vpos=Find(FactNorm, numpy.amax(FactNorm)) |
|
925 | # Vpos=Find(FactNorm, numpy.amax(FactNorm)) | |
928 | # #Vpos=numpy.sum(FactNorm)/len(FactNorm) |
|
926 | # #Vpos=numpy.sum(FactNorm)/len(FactNorm) | |
929 | # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) ))) |
|
927 | # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) ))) | |
930 | # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos |
|
928 | # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos | |
931 | # '''****** Getting Fij ******''' |
|
929 | # '''****** Getting Fij ******''' | |
932 | # |
|
930 | # | |
933 | # GaussCenter=xFrec[GCpos] |
|
931 | # GaussCenter=xFrec[GCpos] | |
934 | # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0): |
|
932 | # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0): | |
935 | # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001 |
|
933 | # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001 | |
936 | # else: |
|
934 | # else: | |
937 | # Fij=abs(GaussCenter-HalfWidth)+0.0000001 |
|
935 | # Fij=abs(GaussCenter-HalfWidth)+0.0000001 | |
938 | # |
|
936 | # | |
939 | # '''****** Getting Frecuency range of significant data ******''' |
|
937 | # '''****** Getting Frecuency range of significant data ******''' | |
940 | # |
|
938 | # | |
941 | # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10))) |
|
939 | # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10))) | |
942 | # |
|
940 | # | |
943 | # if Rangpos<GCpos: |
|
941 | # if Rangpos<GCpos: | |
944 | # Range=numpy.array([Rangpos,2*GCpos-Rangpos]) |
|
942 | # Range=numpy.array([Rangpos,2*GCpos-Rangpos]) | |
945 | # else: |
|
943 | # else: | |
946 | # Range=numpy.array([2*GCpos-Rangpos,Rangpos]) |
|
944 | # Range=numpy.array([2*GCpos-Rangpos,Rangpos]) | |
947 | # |
|
945 | # | |
948 | # FrecRange=xFrec[Range[0]:Range[1]] |
|
946 | # FrecRange=xFrec[Range[0]:Range[1]] | |
949 | # |
|
947 | # | |
950 | # #print 'FrecRange', FrecRange |
|
948 | # #print 'FrecRange', FrecRange | |
951 | # '''****** Getting SCPC Slope ******''' |
|
949 | # '''****** Getting SCPC Slope ******''' | |
952 | # |
|
950 | # | |
953 | # for i in range(self.nRdPairs): |
|
951 | # for i in range(self.nRdPairs): | |
954 | # |
|
952 | # | |
955 | # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5: |
|
953 | # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5: | |
956 | # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3) |
|
954 | # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3) | |
957 | # |
|
955 | # | |
958 | # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange) |
|
956 | # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange) | |
959 | # PhaseSlope[i]=slope |
|
957 | # PhaseSlope[i]=slope | |
960 | # PhaseInter[i]=intercept |
|
958 | # PhaseInter[i]=intercept | |
961 | # else: |
|
959 | # else: | |
962 | # PhaseSlope[i]=0 |
|
960 | # PhaseSlope[i]=0 | |
963 | # PhaseInter[i]=0 |
|
961 | # PhaseInter[i]=0 | |
964 | # |
|
962 | # | |
965 | # # plt.figure(i+15) |
|
963 | # # plt.figure(i+15) | |
966 | # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1])) |
|
964 | # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1])) | |
967 | # # plt.xlabel('Frecuencia (KHz)') |
|
965 | # # plt.xlabel('Frecuencia (KHz)') | |
968 | # # plt.ylabel('Magnitud') |
|
966 | # # plt.ylabel('Magnitud') | |
969 | # # #plt.subplot(311+i) |
|
967 | # # #plt.subplot(311+i) | |
970 | # # plt.plot(FrecRange,PhaseRange,'b') |
|
968 | # # plt.plot(FrecRange,PhaseRange,'b') | |
971 | # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r') |
|
969 | # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r') | |
972 | # |
|
970 | # | |
973 | # #plt.axis([-0.6, 0.2, -3.2, 3.2]) |
|
971 | # #plt.axis([-0.6, 0.2, -3.2, 3.2]) | |
974 | # |
|
972 | # | |
975 | # |
|
973 | # | |
976 | # '''Getting constant C''' |
|
974 | # '''Getting constant C''' | |
977 | # cC=(Fij*numpy.pi)**2 |
|
975 | # cC=(Fij*numpy.pi)**2 | |
978 | # |
|
976 | # | |
979 | # # '''Getting Eij and Nij''' |
|
977 | # # '''Getting Eij and Nij''' | |
980 | # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180) |
|
978 | # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180) | |
981 | # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180) |
|
979 | # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180) | |
982 | # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180) |
|
980 | # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180) | |
983 | # # |
|
981 | # # | |
984 | # # E01=AntennaX0-AntennaX1 |
|
982 | # # E01=AntennaX0-AntennaX1 | |
985 | # # N01=AntennaY0-AntennaY1 |
|
983 | # # N01=AntennaY0-AntennaY1 | |
986 | # # |
|
984 | # # | |
987 | # # E02=AntennaX0-AntennaX2 |
|
985 | # # E02=AntennaX0-AntennaX2 | |
988 | # # N02=AntennaY0-AntennaY2 |
|
986 | # # N02=AntennaY0-AntennaY2 | |
989 | # # |
|
987 | # # | |
990 | # # E12=AntennaX1-AntennaX2 |
|
988 | # # E12=AntennaX1-AntennaX2 | |
991 | # # N12=AntennaY1-AntennaY2 |
|
989 | # # N12=AntennaY1-AntennaY2 | |
992 | # |
|
990 | # | |
993 | # '''****** Getting constants F and G ******''' |
|
991 | # '''****** Getting constants F and G ******''' | |
994 | # MijEijNij=numpy.array([[E02,N02], [E12,N12]]) |
|
992 | # MijEijNij=numpy.array([[E02,N02], [E12,N12]]) | |
995 | # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi) |
|
993 | # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi) | |
996 | # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi) |
|
994 | # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi) | |
997 | # MijResults=numpy.array([MijResult0,MijResult1]) |
|
995 | # MijResults=numpy.array([MijResult0,MijResult1]) | |
998 | # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) |
|
996 | # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) | |
999 | # |
|
997 | # | |
1000 | # '''****** Getting constants A, B and H ******''' |
|
998 | # '''****** Getting constants A, B and H ******''' | |
1001 | # W01=numpy.amax(coherence[0]) |
|
999 | # W01=numpy.amax(coherence[0]) | |
1002 | # W02=numpy.amax(coherence[1]) |
|
1000 | # W02=numpy.amax(coherence[1]) | |
1003 | # W12=numpy.amax(coherence[2]) |
|
1001 | # W12=numpy.amax(coherence[2]) | |
1004 | # |
|
1002 | # | |
1005 | # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC)) |
|
1003 | # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC)) | |
1006 | # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC)) |
|
1004 | # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC)) | |
1007 | # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC)) |
|
1005 | # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC)) | |
1008 | # |
|
1006 | # | |
1009 | # WijResults=numpy.array([WijResult0, WijResult1, WijResult2]) |
|
1007 | # WijResults=numpy.array([WijResult0, WijResult1, WijResult2]) | |
1010 | # |
|
1008 | # | |
1011 | # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ]) |
|
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] ]) | |
1012 | # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) |
|
1010 | # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) | |
1013 | # |
|
1011 | # | |
1014 | # VxVy=numpy.array([[cA,cH],[cH,cB]]) |
|
1012 | # VxVy=numpy.array([[cA,cH],[cH,cB]]) | |
1015 | # |
|
1013 | # | |
1016 | # VxVyResults=numpy.array([-cF,-cG]) |
|
1014 | # VxVyResults=numpy.array([-cF,-cG]) | |
1017 | # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults) |
|
1015 | # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults) | |
1018 | # Vzon = Vy |
|
1016 | # Vzon = Vy | |
1019 | # Vmer = Vx |
|
1017 | # Vmer = Vx | |
1020 | # Vmag=numpy.sqrt(Vzon**2+Vmer**2) |
|
1018 | # Vmag=numpy.sqrt(Vzon**2+Vmer**2) | |
1021 | # Vang=numpy.arctan2(Vmer,Vzon) |
|
1019 | # Vang=numpy.arctan2(Vmer,Vzon) | |
1022 | # |
|
1020 | # | |
1023 | # if abs(Vy)<100 and abs(Vy)> 0.: |
|
1021 | # if abs(Vy)<100 and abs(Vy)> 0.: | |
1024 | # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag |
|
1022 | # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag | |
1025 | # #print 'Vmag',Vmag |
|
1023 | # #print 'Vmag',Vmag | |
1026 | # else: |
|
1024 | # else: | |
1027 | # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN) |
|
1025 | # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN) | |
1028 | # |
|
1026 | # | |
1029 | # if abs(Vx)<100 and abs(Vx) > 0.: |
|
1027 | # if abs(Vx)<100 and abs(Vx) > 0.: | |
1030 | # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang |
|
1028 | # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang | |
1031 | # #print 'Vang',Vang |
|
1029 | # #print 'Vang',Vang | |
1032 | # else: |
|
1030 | # else: | |
1033 | # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN) |
|
1031 | # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN) | |
1034 | # |
|
1032 | # | |
1035 | # if abs(GaussCenter)<2: |
|
1033 | # if abs(GaussCenter)<2: | |
1036 | # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos]) |
|
1034 | # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos]) | |
1037 | # |
|
1035 | # | |
1038 | # else: |
|
1036 | # else: | |
1039 | # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN) |
|
1037 | # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN) | |
1040 | # |
|
1038 | # | |
1041 | # |
|
1039 | # | |
1042 | # # print '********************************************' |
|
1040 | # # print '********************************************' | |
1043 | # # print 'HalfWidth ', HalfWidth |
|
1041 | # # print 'HalfWidth ', HalfWidth | |
1044 | # # print 'Maximun ', Maximun |
|
1042 | # # print 'Maximun ', Maximun | |
1045 | # # print 'eMinus1 ', eMinus1 |
|
1043 | # # print 'eMinus1 ', eMinus1 | |
1046 | # # print 'Rangpos ', Rangpos |
|
1044 | # # print 'Rangpos ', Rangpos | |
1047 | # # print 'GaussCenter ',GaussCenter |
|
1045 | # # print 'GaussCenter ',GaussCenter | |
1048 | # # print 'E01 ',E01 |
|
1046 | # # print 'E01 ',E01 | |
1049 | # # print 'N01 ',N01 |
|
1047 | # # print 'N01 ',N01 | |
1050 | # # print 'E02 ',E02 |
|
1048 | # # print 'E02 ',E02 | |
1051 | # # print 'N02 ',N02 |
|
1049 | # # print 'N02 ',N02 | |
1052 | # # print 'E12 ',E12 |
|
1050 | # # print 'E12 ',E12 | |
1053 | # # print 'N12 ',N12 |
|
1051 | # # print 'N12 ',N12 | |
1054 | # #print 'self.dataOut.velocityX ', self.dataOut.velocityX |
|
1052 | # #print 'self.dataOut.velocityX ', self.dataOut.velocityX | |
1055 | # # print 'Fij ', Fij |
|
1053 | # # print 'Fij ', Fij | |
1056 | # # print 'cC ', cC |
|
1054 | # # print 'cC ', cC | |
1057 | # # print 'cF ', cF |
|
1055 | # # print 'cF ', cF | |
1058 | # # print 'cG ', cG |
|
1056 | # # print 'cG ', cG | |
1059 | # # print 'cA ', cA |
|
1057 | # # print 'cA ', cA | |
1060 | # # print 'cB ', cB |
|
1058 | # # print 'cB ', cB | |
1061 | # # print 'cH ', cH |
|
1059 | # # print 'cH ', cH | |
1062 | # # print 'Vx ', Vx |
|
1060 | # # print 'Vx ', Vx | |
1063 | # # print 'Vy ', Vy |
|
1061 | # # print 'Vy ', Vy | |
1064 | # # print 'Vmag ', Vmag |
|
1062 | # # print 'Vmag ', Vmag | |
1065 | # # print 'Vang ', Vang*180/numpy.pi |
|
1063 | # # print 'Vang ', Vang*180/numpy.pi | |
1066 | # # print 'PhaseSlope ',PhaseSlope[0] |
|
1064 | # # print 'PhaseSlope ',PhaseSlope[0] | |
1067 | # # print 'PhaseSlope ',PhaseSlope[1] |
|
1065 | # # print 'PhaseSlope ',PhaseSlope[1] | |
1068 | # # print 'PhaseSlope ',PhaseSlope[2] |
|
1066 | # # print 'PhaseSlope ',PhaseSlope[2] | |
1069 | # # print '********************************************' |
|
1067 | # # print '********************************************' | |
1070 | # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY) |
|
1068 | # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY) | |
1071 | # |
|
1069 | # | |
1072 | # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX) |
|
1070 | # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX) | |
1073 | # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY) |
|
1071 | # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY) | |
1074 | # #print 'self.dataOut.velocityV', self.dataOut.velocityV |
|
1072 | # #print 'self.dataOut.velocityV', self.dataOut.velocityV | |
1075 | # |
|
1073 | # | |
1076 | # self.data_output[0]=numpy.array(self.dataOut.velocityX) |
|
1074 | # self.data_output[0]=numpy.array(self.dataOut.velocityX) | |
1077 | # self.data_output[1]=numpy.array(self.dataOut.velocityY) |
|
1075 | # self.data_output[1]=numpy.array(self.dataOut.velocityY) | |
1078 | # self.data_output[2]=numpy.array(self.dataOut.velocityV) |
|
1076 | # self.data_output[2]=numpy.array(self.dataOut.velocityV) | |
1079 | # |
|
1077 | # | |
1080 | # prin= self.data_output[0][~numpy.isnan(self.data_output[0])] |
|
1078 | # prin= self.data_output[0][~numpy.isnan(self.data_output[0])] | |
1081 | # print ' ' |
|
1079 | # print ' ' | |
1082 | # print 'VmagAverage',numpy.mean(prin) |
|
1080 | # print 'VmagAverage',numpy.mean(prin) | |
1083 | # print ' ' |
|
1081 | # print ' ' | |
1084 | # # plt.figure(5) |
|
1082 | # # plt.figure(5) | |
1085 | # # plt.subplot(211) |
|
1083 | # # plt.subplot(211) | |
1086 | # # plt.plot(self.dataOut.velocityX,'yo:') |
|
1084 | # # plt.plot(self.dataOut.velocityX,'yo:') | |
1087 | # # plt.subplot(212) |
|
1085 | # # plt.subplot(212) | |
1088 | # # plt.plot(self.dataOut.velocityY,'yo:') |
|
1086 | # # plt.plot(self.dataOut.velocityY,'yo:') | |
1089 | # |
|
1087 | # | |
1090 | # # plt.figure(1) |
|
1088 | # # plt.figure(1) | |
1091 | # # # plt.subplot(121) |
|
1089 | # # # plt.subplot(121) | |
1092 | # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0') |
|
1090 | # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0') | |
1093 | # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1') |
|
1091 | # # # plt.plot(xFrec,ySamples[1],'g',label='Ch1') | |
1094 | # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2') |
|
1092 | # # # plt.plot(xFrec,ySamples[2],'r',label='Ch2') | |
1095 | # # # plt.plot(xFrec,FitGauss,'yo:',label='fit') |
|
1093 | # # # plt.plot(xFrec,FitGauss,'yo:',label='fit') | |
1096 | # # # plt.legend() |
|
1094 | # # # plt.legend() | |
1097 | # # plt.title('DATOS A ALTURA DE 2850 METROS') |
|
1095 | # # plt.title('DATOS A ALTURA DE 2850 METROS') | |
1098 | # # |
|
1096 | # # | |
1099 | # # plt.xlabel('Frecuencia (KHz)') |
|
1097 | # # plt.xlabel('Frecuencia (KHz)') | |
1100 | # # plt.ylabel('Magnitud') |
|
1098 | # # plt.ylabel('Magnitud') | |
1101 | # # # plt.subplot(122) |
|
1099 | # # # plt.subplot(122) | |
1102 | # # # plt.title('Fit for Time Constant') |
|
1100 | # # # plt.title('Fit for Time Constant') | |
1103 | # # #plt.plot(xFrec,zline) |
|
1101 | # # #plt.plot(xFrec,zline) | |
1104 | # # #plt.plot(xFrec,SmoothSPC,'g') |
|
1102 | # # #plt.plot(xFrec,SmoothSPC,'g') | |
1105 | # # plt.plot(xFrec,FactNorm) |
|
1103 | # # plt.plot(xFrec,FactNorm) | |
1106 | # # plt.axis([-4, 4, 0, 0.15]) |
|
1104 | # # plt.axis([-4, 4, 0, 0.15]) | |
1107 | # # # plt.xlabel('SelfSpectra KHz') |
|
1105 | # # # plt.xlabel('SelfSpectra KHz') | |
1108 | # # |
|
1106 | # # | |
1109 | # # plt.figure(10) |
|
1107 | # # plt.figure(10) | |
1110 | # # # plt.subplot(121) |
|
1108 | # # # plt.subplot(121) | |
1111 | # # plt.plot(xFrec,ySamples[0],'b',label='Ch0') |
|
1109 | # # plt.plot(xFrec,ySamples[0],'b',label='Ch0') | |
1112 | # # plt.plot(xFrec,ySamples[1],'y',label='Ch1') |
|
1110 | # # plt.plot(xFrec,ySamples[1],'y',label='Ch1') | |
1113 | # # plt.plot(xFrec,ySamples[2],'r',label='Ch2') |
|
1111 | # # plt.plot(xFrec,ySamples[2],'r',label='Ch2') | |
1114 | # # # plt.plot(xFrec,FitGauss,'yo:',label='fit') |
|
1112 | # # # plt.plot(xFrec,FitGauss,'yo:',label='fit') | |
1115 | # # plt.legend() |
|
1113 | # # plt.legend() | |
1116 | # # plt.title('SELFSPECTRA EN CANALES') |
|
1114 | # # plt.title('SELFSPECTRA EN CANALES') | |
1117 | # # |
|
1115 | # # | |
1118 | # # plt.xlabel('Frecuencia (KHz)') |
|
1116 | # # plt.xlabel('Frecuencia (KHz)') | |
1119 | # # plt.ylabel('Magnitud') |
|
1117 | # # plt.ylabel('Magnitud') | |
1120 | # # # plt.subplot(122) |
|
1118 | # # # plt.subplot(122) | |
1121 | # # # plt.title('Fit for Time Constant') |
|
1119 | # # # plt.title('Fit for Time Constant') | |
1122 | # # #plt.plot(xFrec,zline) |
|
1120 | # # #plt.plot(xFrec,zline) | |
1123 | # # #plt.plot(xFrec,SmoothSPC,'g') |
|
1121 | # # #plt.plot(xFrec,SmoothSPC,'g') | |
1124 | # # # plt.plot(xFrec,FactNorm) |
|
1122 | # # # plt.plot(xFrec,FactNorm) | |
1125 | # # # plt.axis([-4, 4, 0, 0.15]) |
|
1123 | # # # plt.axis([-4, 4, 0, 0.15]) | |
1126 | # # # plt.xlabel('SelfSpectra KHz') |
|
1124 | # # # plt.xlabel('SelfSpectra KHz') | |
1127 | # # |
|
1125 | # # | |
1128 | # # plt.figure(9) |
|
1126 | # # plt.figure(9) | |
1129 | # # |
|
1127 | # # | |
1130 | # # |
|
1128 | # # | |
1131 | # # plt.title('DATOS SUAVIZADOS') |
|
1129 | # # plt.title('DATOS SUAVIZADOS') | |
1132 | # # plt.xlabel('Frecuencia (KHz)') |
|
1130 | # # plt.xlabel('Frecuencia (KHz)') | |
1133 | # # plt.ylabel('Magnitud') |
|
1131 | # # plt.ylabel('Magnitud') | |
1134 | # # plt.plot(xFrec,SmoothSPC,'g') |
|
1132 | # # plt.plot(xFrec,SmoothSPC,'g') | |
1135 | # # |
|
1133 | # # | |
1136 | # # #plt.plot(xFrec,FactNorm) |
|
1134 | # # #plt.plot(xFrec,FactNorm) | |
1137 | # # plt.axis([-4, 4, 0, 0.15]) |
|
1135 | # # plt.axis([-4, 4, 0, 0.15]) | |
1138 | # # # plt.xlabel('SelfSpectra KHz') |
|
1136 | # # # plt.xlabel('SelfSpectra KHz') | |
1139 | # # # |
|
1137 | # # # | |
1140 | # # plt.figure(2) |
|
1138 | # # plt.figure(2) | |
1141 | # # # #plt.subplot(121) |
|
1139 | # # # #plt.subplot(121) | |
1142 | # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra') |
|
1140 | # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra') | |
1143 | # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano') |
|
1141 | # # plt.plot(xFrec,FitGauss,'yo:',label='Ajuste Gaussiano') | |
1144 | # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo') |
|
1142 | # # # plt.plot(xFrec[Rangpos],FitGauss[Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.1)))],'bo') | |
1145 | # # # #plt.plot(xFrec,phase) |
|
1143 | # # # #plt.plot(xFrec,phase) | |
1146 | # # # plt.xlabel('Suavizado, promediado KHz') |
|
1144 | # # # plt.xlabel('Suavizado, promediado KHz') | |
1147 | # # plt.title('SELFSPECTRA PROMEDIADO') |
|
1145 | # # plt.title('SELFSPECTRA PROMEDIADO') | |
1148 | # # # #plt.subplot(122) |
|
1146 | # # # #plt.subplot(122) | |
1149 | # # # #plt.plot(xSamples,zline) |
|
1147 | # # # #plt.plot(xSamples,zline) | |
1150 | # # plt.xlabel('Frecuencia (KHz)') |
|
1148 | # # plt.xlabel('Frecuencia (KHz)') | |
1151 | # # plt.ylabel('Magnitud') |
|
1149 | # # plt.ylabel('Magnitud') | |
1152 | # # plt.legend() |
|
1150 | # # plt.legend() | |
1153 | # # # |
|
1151 | # # # | |
1154 | # # # plt.figure(3) |
|
1152 | # # # plt.figure(3) | |
1155 | # # # plt.subplot(311) |
|
1153 | # # # plt.subplot(311) | |
1156 | # # # #plt.plot(xFrec,phase[0]) |
|
1154 | # # # #plt.plot(xFrec,phase[0]) | |
1157 | # # # plt.plot(xFrec,phase[0],'g') |
|
1155 | # # # plt.plot(xFrec,phase[0],'g') | |
1158 | # # # plt.subplot(312) |
|
1156 | # # # plt.subplot(312) | |
1159 | # # # plt.plot(xFrec,phase[1],'g') |
|
1157 | # # # plt.plot(xFrec,phase[1],'g') | |
1160 | # # # plt.subplot(313) |
|
1158 | # # # plt.subplot(313) | |
1161 | # # # plt.plot(xFrec,phase[2],'g') |
|
1159 | # # # plt.plot(xFrec,phase[2],'g') | |
1162 | # # # #plt.plot(xFrec,phase[2]) |
|
1160 | # # # #plt.plot(xFrec,phase[2]) | |
1163 | # # # |
|
1161 | # # # | |
1164 | # # # plt.figure(4) |
|
1162 | # # # plt.figure(4) | |
1165 | # # # |
|
1163 | # # # | |
1166 | # # # plt.plot(xSamples,coherence[0],'b') |
|
1164 | # # # plt.plot(xSamples,coherence[0],'b') | |
1167 | # # # plt.plot(xSamples,coherence[1],'r') |
|
1165 | # # # plt.plot(xSamples,coherence[1],'r') | |
1168 | # # # plt.plot(xSamples,coherence[2],'g') |
|
1166 | # # # plt.plot(xSamples,coherence[2],'g') | |
1169 | # # plt.show() |
|
1167 | # # plt.show() | |
1170 | # # # |
|
1168 | # # # | |
1171 | # # # plt.clf() |
|
1169 | # # # plt.clf() | |
1172 | # # # plt.cla() |
|
1170 | # # # plt.cla() | |
1173 | # # # plt.close() |
|
1171 | # # # plt.close() | |
1174 | # |
|
1172 | # | |
1175 | # print ' ' |
|
1173 | # print ' ' | |
1176 |
|
1174 | |||
1177 | self.BlockCounter += 2 |
|
1175 | self.BlockCounter += 2 | |
1178 |
|
1176 | |||
1179 | else: |
|
1177 | else: | |
1180 | self.fileSelector += 1 |
|
1178 | self.fileSelector += 1 | |
1181 | self.BlockCounter = 0 |
|
1179 | self.BlockCounter = 0 | |
1182 | print "Next File" |
|
1180 | print "Next File" |
@@ -1,802 +1,800 | |||||
1 | import os |
|
1 | import os | |
2 | import sys |
|
2 | import sys | |
3 | import glob |
|
3 | import glob | |
4 | import fnmatch |
|
4 | import fnmatch | |
5 | import datetime |
|
5 | import datetime | |
6 | import time |
|
6 | import time | |
7 | import re |
|
7 | import re | |
8 | import h5py |
|
8 | import h5py | |
9 | import numpy |
|
9 | import numpy | |
10 |
|
10 | |||
11 | from scipy.optimize import curve_fit |
|
11 | from scipy.optimize import curve_fit | |
12 | from scipy import asarray as ar, exp |
|
12 | from scipy import asarray as ar, exp | |
13 | from scipy import stats |
|
13 | from scipy import stats | |
14 |
|
14 | |||
15 | from numpy.ma.core import getdata |
|
15 | from numpy.ma.core import getdata | |
16 |
|
16 | |||
17 | SPEED_OF_LIGHT = 299792458 |
|
17 | SPEED_OF_LIGHT = 299792458 | |
18 | SPEED_OF_LIGHT = 3e8 |
|
18 | SPEED_OF_LIGHT = 3e8 | |
19 |
|
19 | |||
20 | try: |
|
20 | try: | |
21 | from gevent import sleep |
|
21 | from gevent import sleep | |
22 | except: |
|
22 | except: | |
23 | from time import sleep |
|
23 | from time import sleep | |
24 |
|
24 | |||
25 | from schainpy.model.data.jrodata import Spectra |
|
25 | from schainpy.model.data.jrodata import Spectra | |
26 | #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader |
|
26 | #from schainpy.model.data.BLTRheaderIO import FileHeader, RecordHeader | |
27 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
27 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
28 | #from schainpy.model.io.jroIO_bltr import BLTRReader |
|
28 | #from schainpy.model.io.jroIO_bltr import BLTRReader | |
29 | from numpy import imag, shape, NaN, empty |
|
29 | from numpy import imag, shape, NaN, empty | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | class Header(object): |
|
32 | class Header(object): | |
33 |
|
33 | |||
34 | def __init__(self): |
|
34 | def __init__(self): | |
35 | raise NotImplementedError |
|
35 | raise NotImplementedError | |
36 |
|
36 | |||
37 | def read(self): |
|
37 | def read(self): | |
38 |
|
38 | |||
39 | raise NotImplementedError |
|
39 | raise NotImplementedError | |
40 |
|
40 | |||
41 | def write(self): |
|
41 | def write(self): | |
42 |
|
42 | |||
43 | raise NotImplementedError |
|
43 | raise NotImplementedError | |
44 |
|
44 | |||
45 | def printInfo(self): |
|
45 | def printInfo(self): | |
46 |
|
46 | |||
47 | message = "#" * 50 + "\n" |
|
47 | message = "#" * 50 + "\n" | |
48 | message += self.__class__.__name__.upper() + "\n" |
|
48 | message += self.__class__.__name__.upper() + "\n" | |
49 | message += "#" * 50 + "\n" |
|
49 | message += "#" * 50 + "\n" | |
50 |
|
50 | |||
51 | keyList = self.__dict__.keys() |
|
51 | keyList = self.__dict__.keys() | |
52 | keyList.sort() |
|
52 | keyList.sort() | |
53 |
|
53 | |||
54 | for key in keyList: |
|
54 | for key in keyList: | |
55 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" |
|
55 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" | |
56 |
|
56 | |||
57 | if "size" not in keyList: |
|
57 | if "size" not in keyList: | |
58 | attr = getattr(self, "size") |
|
58 | attr = getattr(self, "size") | |
59 |
|
59 | |||
60 | if attr: |
|
60 | if attr: | |
61 | message += "%s = %s" % ("size", attr) + "\n" |
|
61 | message += "%s = %s" % ("size", attr) + "\n" | |
62 |
|
62 | |||
63 | # print message |
|
63 | # print message | |
64 |
|
64 | |||
65 |
|
65 | |||
66 | FILE_HEADER = numpy.dtype([ # HEADER 1024bytes |
|
66 | FILE_HEADER = numpy.dtype([ # HEADER 1024bytes | |
67 | ('Hname', 'a32'), # Original file name |
|
67 | ('Hname', 'a32'), # Original file name | |
68 | # Date and time when the file was created |
|
68 | # Date and time when the file was created | |
69 | ('Htime', numpy.str_, 32), |
|
69 | ('Htime', numpy.str_, 32), | |
70 | # Name of operator who created the file |
|
70 | # Name of operator who created the file | |
71 | ('Hoper', numpy.str_, 64), |
|
71 | ('Hoper', numpy.str_, 64), | |
72 | # Place where the measurements was carried out |
|
72 | # Place where the measurements was carried out | |
73 | ('Hplace', numpy.str_, 128), |
|
73 | ('Hplace', numpy.str_, 128), | |
74 | # Description of measurements |
|
74 | # Description of measurements | |
75 | ('Hdescr', numpy.str_, 256), |
|
75 | ('Hdescr', numpy.str_, 256), | |
76 | ('Hdummy', numpy.str_, 512), # Reserved space |
|
76 | ('Hdummy', numpy.str_, 512), # Reserved space | |
77 | # Main chunk 8bytes |
|
77 | # Main chunk 8bytes | |
78 | # Main chunk signature FZKF or NUIG |
|
78 | # Main chunk signature FZKF or NUIG | |
79 | ('Msign', numpy.str_, 4), |
|
79 | ('Msign', numpy.str_, 4), | |
80 | ('MsizeData', '<i4'), # Size of data block main chunk |
|
80 | ('MsizeData', '<i4'), # Size of data block main chunk | |
81 | # Processing DSP parameters 36bytes |
|
81 | # Processing DSP parameters 36bytes | |
82 | ('PPARsign', numpy.str_, 4), # PPAR signature |
|
82 | ('PPARsign', numpy.str_, 4), # PPAR signature | |
83 | ('PPARsize', '<i4'), # PPAR size of block |
|
83 | ('PPARsize', '<i4'), # PPAR size of block | |
84 | ('PPARprf', '<i4'), # Pulse repetition frequency |
|
84 | ('PPARprf', '<i4'), # Pulse repetition frequency | |
85 | ('PPARpdr', '<i4'), # Pulse duration |
|
85 | ('PPARpdr', '<i4'), # Pulse duration | |
86 | ('PPARsft', '<i4'), # FFT length |
|
86 | ('PPARsft', '<i4'), # FFT length | |
87 | # Number of spectral (in-coherent) averages |
|
87 | # Number of spectral (in-coherent) averages | |
88 | ('PPARavc', '<i4'), |
|
88 | ('PPARavc', '<i4'), | |
89 | # Number of lowest range gate for moment estimation |
|
89 | # Number of lowest range gate for moment estimation | |
90 | ('PPARihp', '<i4'), |
|
90 | ('PPARihp', '<i4'), | |
91 | # Count for gates for moment estimation |
|
91 | # Count for gates for moment estimation | |
92 | ('PPARchg', '<i4'), |
|
92 | ('PPARchg', '<i4'), | |
93 | # switch on/off polarimetric measurements. Should be 1. |
|
93 | # switch on/off polarimetric measurements. Should be 1. | |
94 | ('PPARpol', '<i4'), |
|
94 | ('PPARpol', '<i4'), | |
95 | # Service DSP parameters 112bytes |
|
95 | # Service DSP parameters 112bytes | |
96 | # STC attenuation on the lowest ranges on/off |
|
96 | # STC attenuation on the lowest ranges on/off | |
97 | ('SPARatt', '<i4'), |
|
97 | ('SPARatt', '<i4'), | |
98 | ('SPARtx', '<i4'), # OBSOLETE |
|
98 | ('SPARtx', '<i4'), # OBSOLETE | |
99 | ('SPARaddGain0', '<f4'), # OBSOLETE |
|
99 | ('SPARaddGain0', '<f4'), # OBSOLETE | |
100 | ('SPARaddGain1', '<f4'), # OBSOLETE |
|
100 | ('SPARaddGain1', '<f4'), # OBSOLETE | |
101 | # Debug only. It normal mode it is 0. |
|
101 | # Debug only. It normal mode it is 0. | |
102 | ('SPARwnd', '<i4'), |
|
102 | ('SPARwnd', '<i4'), | |
103 | # Delay between sync pulse and tx pulse for phase corr, ns |
|
103 | # Delay between sync pulse and tx pulse for phase corr, ns | |
104 | ('SPARpos', '<i4'), |
|
104 | ('SPARpos', '<i4'), | |
105 | # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal. |
|
105 | # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal. | |
106 | ('SPARadd', '<i4'), |
|
106 | ('SPARadd', '<i4'), | |
107 | # Time for measuring txn pulse phase. OBSOLETE |
|
107 | # Time for measuring txn pulse phase. OBSOLETE | |
108 | ('SPARlen', '<i4'), |
|
108 | ('SPARlen', '<i4'), | |
109 | ('SPARcal', '<i4'), # OBSOLETE |
|
109 | ('SPARcal', '<i4'), # OBSOLETE | |
110 | ('SPARnos', '<i4'), # OBSOLETE |
|
110 | ('SPARnos', '<i4'), # OBSOLETE | |
111 | ('SPARof0', '<i4'), # detection threshold |
|
111 | ('SPARof0', '<i4'), # detection threshold | |
112 | ('SPARof1', '<i4'), # OBSOLETE |
|
112 | ('SPARof1', '<i4'), # OBSOLETE | |
113 | ('SPARswt', '<i4'), # 2nd moment estimation threshold |
|
113 | ('SPARswt', '<i4'), # 2nd moment estimation threshold | |
114 | ('SPARsum', '<i4'), # OBSOLETE |
|
114 | ('SPARsum', '<i4'), # OBSOLETE | |
115 | ('SPARosc', '<i4'), # flag Oscillosgram mode |
|
115 | ('SPARosc', '<i4'), # flag Oscillosgram mode | |
116 | ('SPARtst', '<i4'), # OBSOLETE |
|
116 | ('SPARtst', '<i4'), # OBSOLETE | |
117 | ('SPARcor', '<i4'), # OBSOLETE |
|
117 | ('SPARcor', '<i4'), # OBSOLETE | |
118 | ('SPARofs', '<i4'), # OBSOLETE |
|
118 | ('SPARofs', '<i4'), # OBSOLETE | |
119 | # Hildebrand div noise detection on noise gate |
|
119 | # Hildebrand div noise detection on noise gate | |
120 | ('SPARhsn', '<i4'), |
|
120 | ('SPARhsn', '<i4'), | |
121 | # Hildebrand div noise detection on all gates |
|
121 | # Hildebrand div noise detection on all gates | |
122 | ('SPARhsa', '<f4'), |
|
122 | ('SPARhsa', '<f4'), | |
123 | ('SPARcalibPow_M', '<f4'), # OBSOLETE |
|
123 | ('SPARcalibPow_M', '<f4'), # OBSOLETE | |
124 | ('SPARcalibSNR_M', '<f4'), # OBSOLETE |
|
124 | ('SPARcalibSNR_M', '<f4'), # OBSOLETE | |
125 | ('SPARcalibPow_S', '<f4'), # OBSOLETE |
|
125 | ('SPARcalibPow_S', '<f4'), # OBSOLETE | |
126 | ('SPARcalibSNR_S', '<f4'), # OBSOLETE |
|
126 | ('SPARcalibSNR_S', '<f4'), # OBSOLETE | |
127 | # Lowest range gate for spectra saving Raw_Gate1 >=5 |
|
127 | # Lowest range gate for spectra saving Raw_Gate1 >=5 | |
128 | ('SPARrawGate1', '<i4'), |
|
128 | ('SPARrawGate1', '<i4'), | |
129 | # Number of range gates with atmospheric signal |
|
129 | # Number of range gates with atmospheric signal | |
130 | ('SPARrawGate2', '<i4'), |
|
130 | ('SPARrawGate2', '<i4'), | |
131 | # flag - IQ or spectra saving on/off |
|
131 | # flag - IQ or spectra saving on/off | |
132 | ('SPARraw', '<i4'), |
|
132 | ('SPARraw', '<i4'), | |
133 | ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off |
|
133 | ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off | |
134 |
|
134 | |||
135 |
|
135 | |||
136 | class FileHeaderMIRA35c(Header): |
|
136 | class FileHeaderMIRA35c(Header): | |
137 |
|
137 | |||
138 | def __init__(self): |
|
138 | def __init__(self): | |
139 |
|
139 | |||
140 | self.Hname = None |
|
140 | self.Hname = None | |
141 | self.Htime = None |
|
141 | self.Htime = None | |
142 | self.Hoper = None |
|
142 | self.Hoper = None | |
143 | self.Hplace = None |
|
143 | self.Hplace = None | |
144 | self.Hdescr = None |
|
144 | self.Hdescr = None | |
145 | self.Hdummy = None |
|
145 | self.Hdummy = None | |
146 |
|
146 | |||
147 | self.Msign = None |
|
147 | self.Msign = None | |
148 | self.MsizeData = None |
|
148 | self.MsizeData = None | |
149 |
|
149 | |||
150 | self.PPARsign = None |
|
150 | self.PPARsign = None | |
151 | self.PPARsize = None |
|
151 | self.PPARsize = None | |
152 | self.PPARprf = None |
|
152 | self.PPARprf = None | |
153 | self.PPARpdr = None |
|
153 | self.PPARpdr = None | |
154 | self.PPARsft = None |
|
154 | self.PPARsft = None | |
155 | self.PPARavc = None |
|
155 | self.PPARavc = None | |
156 | self.PPARihp = None |
|
156 | self.PPARihp = None | |
157 | self.PPARchg = None |
|
157 | self.PPARchg = None | |
158 | self.PPARpol = None |
|
158 | self.PPARpol = None | |
159 | # Service DSP parameters |
|
159 | # Service DSP parameters | |
160 | self.SPARatt = None |
|
160 | self.SPARatt = None | |
161 | self.SPARtx = None |
|
161 | self.SPARtx = None | |
162 | self.SPARaddGain0 = None |
|
162 | self.SPARaddGain0 = None | |
163 | self.SPARaddGain1 = None |
|
163 | self.SPARaddGain1 = None | |
164 | self.SPARwnd = None |
|
164 | self.SPARwnd = None | |
165 | self.SPARpos = None |
|
165 | self.SPARpos = None | |
166 | self.SPARadd = None |
|
166 | self.SPARadd = None | |
167 | self.SPARlen = None |
|
167 | self.SPARlen = None | |
168 | self.SPARcal = None |
|
168 | self.SPARcal = None | |
169 | self.SPARnos = None |
|
169 | self.SPARnos = None | |
170 | self.SPARof0 = None |
|
170 | self.SPARof0 = None | |
171 | self.SPARof1 = None |
|
171 | self.SPARof1 = None | |
172 | self.SPARswt = None |
|
172 | self.SPARswt = None | |
173 | self.SPARsum = None |
|
173 | self.SPARsum = None | |
174 | self.SPARosc = None |
|
174 | self.SPARosc = None | |
175 | self.SPARtst = None |
|
175 | self.SPARtst = None | |
176 | self.SPARcor = None |
|
176 | self.SPARcor = None | |
177 | self.SPARofs = None |
|
177 | self.SPARofs = None | |
178 | self.SPARhsn = None |
|
178 | self.SPARhsn = None | |
179 | self.SPARhsa = None |
|
179 | self.SPARhsa = None | |
180 | self.SPARcalibPow_M = None |
|
180 | self.SPARcalibPow_M = None | |
181 | self.SPARcalibSNR_M = None |
|
181 | self.SPARcalibSNR_M = None | |
182 | self.SPARcalibPow_S = None |
|
182 | self.SPARcalibPow_S = None | |
183 | self.SPARcalibSNR_S = None |
|
183 | self.SPARcalibSNR_S = None | |
184 | self.SPARrawGate1 = None |
|
184 | self.SPARrawGate1 = None | |
185 | self.SPARrawGate2 = None |
|
185 | self.SPARrawGate2 = None | |
186 | self.SPARraw = None |
|
186 | self.SPARraw = None | |
187 | self.SPARprc = None |
|
187 | self.SPARprc = None | |
188 |
|
188 | |||
189 | self.FHsize = 1180 |
|
189 | self.FHsize = 1180 | |
190 |
|
190 | |||
191 | def FHread(self, fp): |
|
191 | def FHread(self, fp): | |
192 |
|
192 | |||
193 | header = numpy.fromfile(fp, FILE_HEADER, 1) |
|
193 | header = numpy.fromfile(fp, FILE_HEADER, 1) | |
194 | ''' numpy.fromfile(file, dtype, count, sep='') |
|
194 | ''' numpy.fromfile(file, dtype, count, sep='') | |
195 | file : file or str |
|
195 | file : file or str | |
196 | Open file object or filename. |
|
196 | Open file object or filename. | |
197 |
|
197 | |||
198 | dtype : data-type |
|
198 | dtype : data-type | |
199 | Data type of the returned array. For binary files, it is used to determine |
|
199 | Data type of the returned array. For binary files, it is used to determine | |
200 | the size and byte-order of the items in the file. |
|
200 | the size and byte-order of the items in the file. | |
201 |
|
201 | |||
202 | count : int |
|
202 | count : int | |
203 | Number of items to read. -1 means all items (i.e., the complete file). |
|
203 | Number of items to read. -1 means all items (i.e., the complete file). | |
204 |
|
204 | |||
205 | sep : str |
|
205 | sep : str | |
206 | Separator between items if file is a text file. Empty ("") separator means |
|
206 | Separator between items if file is a text file. Empty ("") separator means | |
207 | the file should be treated as binary. Spaces (" ") in the separator match zero |
|
207 | the file should be treated as binary. Spaces (" ") in the separator match zero | |
208 | or more whitespace characters. A separator consisting only of spaces must match |
|
208 | or more whitespace characters. A separator consisting only of spaces must match | |
209 | at least one whitespace. |
|
209 | at least one whitespace. | |
210 |
|
210 | |||
211 | ''' |
|
211 | ''' | |
212 |
|
212 | |||
213 | self.Hname = str(header['Hname'][0]) |
|
213 | self.Hname = str(header['Hname'][0]) | |
214 | self.Htime = str(header['Htime'][0]) |
|
214 | self.Htime = str(header['Htime'][0]) | |
215 | self.Hoper = str(header['Hoper'][0]) |
|
215 | self.Hoper = str(header['Hoper'][0]) | |
216 | self.Hplace = str(header['Hplace'][0]) |
|
216 | self.Hplace = str(header['Hplace'][0]) | |
217 | self.Hdescr = str(header['Hdescr'][0]) |
|
217 | self.Hdescr = str(header['Hdescr'][0]) | |
218 | self.Hdummy = str(header['Hdummy'][0]) |
|
218 | self.Hdummy = str(header['Hdummy'][0]) | |
219 | # 1024 |
|
219 | # 1024 | |
220 |
|
220 | |||
221 | self.Msign = str(header['Msign'][0]) |
|
221 | self.Msign = str(header['Msign'][0]) | |
222 | self.MsizeData = header['MsizeData'][0] |
|
222 | self.MsizeData = header['MsizeData'][0] | |
223 | # 8 |
|
223 | # 8 | |
224 |
|
224 | |||
225 | self.PPARsign = str(header['PPARsign'][0]) |
|
225 | self.PPARsign = str(header['PPARsign'][0]) | |
226 | self.PPARsize = header['PPARsize'][0] |
|
226 | self.PPARsize = header['PPARsize'][0] | |
227 | self.PPARprf = header['PPARprf'][0] |
|
227 | self.PPARprf = header['PPARprf'][0] | |
228 | self.PPARpdr = header['PPARpdr'][0] |
|
228 | self.PPARpdr = header['PPARpdr'][0] | |
229 | self.PPARsft = header['PPARsft'][0] |
|
229 | self.PPARsft = header['PPARsft'][0] | |
230 | self.PPARavc = header['PPARavc'][0] |
|
230 | self.PPARavc = header['PPARavc'][0] | |
231 | self.PPARihp = header['PPARihp'][0] |
|
231 | self.PPARihp = header['PPARihp'][0] | |
232 | self.PPARchg = header['PPARchg'][0] |
|
232 | self.PPARchg = header['PPARchg'][0] | |
233 | self.PPARpol = header['PPARpol'][0] |
|
233 | self.PPARpol = header['PPARpol'][0] | |
234 | # Service DSP parameters |
|
234 | # Service DSP parameters | |
235 | # 36 |
|
235 | # 36 | |
236 |
|
236 | |||
237 | self.SPARatt = header['SPARatt'][0] |
|
237 | self.SPARatt = header['SPARatt'][0] | |
238 | self.SPARtx = header['SPARtx'][0] |
|
238 | self.SPARtx = header['SPARtx'][0] | |
239 | self.SPARaddGain0 = header['SPARaddGain0'][0] |
|
239 | self.SPARaddGain0 = header['SPARaddGain0'][0] | |
240 | self.SPARaddGain1 = header['SPARaddGain1'][0] |
|
240 | self.SPARaddGain1 = header['SPARaddGain1'][0] | |
241 | self.SPARwnd = header['SPARwnd'][0] |
|
241 | self.SPARwnd = header['SPARwnd'][0] | |
242 | self.SPARpos = header['SPARpos'][0] |
|
242 | self.SPARpos = header['SPARpos'][0] | |
243 | self.SPARadd = header['SPARadd'][0] |
|
243 | self.SPARadd = header['SPARadd'][0] | |
244 | self.SPARlen = header['SPARlen'][0] |
|
244 | self.SPARlen = header['SPARlen'][0] | |
245 | self.SPARcal = header['SPARcal'][0] |
|
245 | self.SPARcal = header['SPARcal'][0] | |
246 | self.SPARnos = header['SPARnos'][0] |
|
246 | self.SPARnos = header['SPARnos'][0] | |
247 | self.SPARof0 = header['SPARof0'][0] |
|
247 | self.SPARof0 = header['SPARof0'][0] | |
248 | self.SPARof1 = header['SPARof1'][0] |
|
248 | self.SPARof1 = header['SPARof1'][0] | |
249 | self.SPARswt = header['SPARswt'][0] |
|
249 | self.SPARswt = header['SPARswt'][0] | |
250 | self.SPARsum = header['SPARsum'][0] |
|
250 | self.SPARsum = header['SPARsum'][0] | |
251 | self.SPARosc = header['SPARosc'][0] |
|
251 | self.SPARosc = header['SPARosc'][0] | |
252 | self.SPARtst = header['SPARtst'][0] |
|
252 | self.SPARtst = header['SPARtst'][0] | |
253 | self.SPARcor = header['SPARcor'][0] |
|
253 | self.SPARcor = header['SPARcor'][0] | |
254 | self.SPARofs = header['SPARofs'][0] |
|
254 | self.SPARofs = header['SPARofs'][0] | |
255 | self.SPARhsn = header['SPARhsn'][0] |
|
255 | self.SPARhsn = header['SPARhsn'][0] | |
256 | self.SPARhsa = header['SPARhsa'][0] |
|
256 | self.SPARhsa = header['SPARhsa'][0] | |
257 | self.SPARcalibPow_M = header['SPARcalibPow_M'][0] |
|
257 | self.SPARcalibPow_M = header['SPARcalibPow_M'][0] | |
258 | self.SPARcalibSNR_M = header['SPARcalibSNR_M'][0] |
|
258 | self.SPARcalibSNR_M = header['SPARcalibSNR_M'][0] | |
259 | self.SPARcalibPow_S = header['SPARcalibPow_S'][0] |
|
259 | self.SPARcalibPow_S = header['SPARcalibPow_S'][0] | |
260 | self.SPARcalibSNR_S = header['SPARcalibSNR_S'][0] |
|
260 | self.SPARcalibSNR_S = header['SPARcalibSNR_S'][0] | |
261 | self.SPARrawGate1 = header['SPARrawGate1'][0] |
|
261 | self.SPARrawGate1 = header['SPARrawGate1'][0] | |
262 | self.SPARrawGate2 = header['SPARrawGate2'][0] |
|
262 | self.SPARrawGate2 = header['SPARrawGate2'][0] | |
263 | self.SPARraw = header['SPARraw'][0] |
|
263 | self.SPARraw = header['SPARraw'][0] | |
264 | self.SPARprc = header['SPARprc'][0] |
|
264 | self.SPARprc = header['SPARprc'][0] | |
265 | # 112 |
|
265 | # 112 | |
266 | # 1180 |
|
266 | # 1180 | |
267 | # print 'Pointer fp header', fp.tell() |
|
267 | # print 'Pointer fp header', fp.tell() | |
268 | # print ' ' |
|
268 | # print ' ' | |
269 | # print 'SPARrawGate' |
|
269 | # print 'SPARrawGate' | |
270 | # print self.SPARrawGate2 - self.SPARrawGate1 |
|
270 | # print self.SPARrawGate2 - self.SPARrawGate1 | |
271 |
|
271 | |||
272 | # print ' ' |
|
272 | # print ' ' | |
273 | # print 'Hname' |
|
273 | # print 'Hname' | |
274 | # print self.Hname |
|
274 | # print self.Hname | |
275 |
|
275 | |||
276 | # print ' ' |
|
276 | # print ' ' | |
277 | # print 'Msign' |
|
277 | # print 'Msign' | |
278 | # print self.Msign |
|
278 | # print self.Msign | |
279 |
|
279 | |||
280 | def write(self, fp): |
|
280 | def write(self, fp): | |
281 |
|
281 | |||
282 | headerTuple = (self.Hname, |
|
282 | headerTuple = (self.Hname, | |
283 | self.Htime, |
|
283 | self.Htime, | |
284 | self.Hoper, |
|
284 | self.Hoper, | |
285 | self.Hplace, |
|
285 | self.Hplace, | |
286 | self.Hdescr, |
|
286 | self.Hdescr, | |
287 | self.Hdummy) |
|
287 | self.Hdummy) | |
288 |
|
288 | |||
289 | header = numpy.array(headerTuple, FILE_HEADER) |
|
289 | header = numpy.array(headerTuple, FILE_HEADER) | |
290 | # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) |
|
290 | # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) | |
291 | header.tofile(fp) |
|
291 | header.tofile(fp) | |
292 | ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default). |
|
292 | ''' ndarray.tofile(fid, sep, format) Write array to a file as text or binary (default). | |
293 |
|
293 | |||
294 | fid : file or str |
|
294 | fid : file or str | |
295 | An open file object, or a string containing a filename. |
|
295 | An open file object, or a string containing a filename. | |
296 |
|
296 | |||
297 | sep : str |
|
297 | sep : str | |
298 | Separator between array items for text output. If "" (empty), a binary file is written, |
|
298 | Separator between array items for text output. If "" (empty), a binary file is written, | |
299 | equivalent to file.write(a.tobytes()). |
|
299 | equivalent to file.write(a.tobytes()). | |
300 |
|
300 | |||
301 | format : str |
|
301 | format : str | |
302 | Format string for text file output. Each entry in the array is formatted to text by |
|
302 | Format string for text file output. Each entry in the array is formatted to text by | |
303 | first converting it to the closest Python type, and then using "format" % item. |
|
303 | first converting it to the closest Python type, and then using "format" % item. | |
304 |
|
304 | |||
305 | ''' |
|
305 | ''' | |
306 |
|
306 | |||
307 | return 1 |
|
307 | return 1 | |
308 |
|
308 | |||
309 |
|
309 | |||
310 | SRVI_HEADER = numpy.dtype([ |
|
310 | SRVI_HEADER = numpy.dtype([ | |
311 | ('SignatureSRVI1', numpy.str_, 4), |
|
311 | ('SignatureSRVI1', numpy.str_, 4), | |
312 | ('SizeOfDataBlock1', '<i4'), |
|
312 | ('SizeOfDataBlock1', '<i4'), | |
313 | ('DataBlockTitleSRVI1', numpy.str_, 4), |
|
313 | ('DataBlockTitleSRVI1', numpy.str_, 4), | |
314 | ('SizeOfSRVI1', '<i4'), ]) |
|
314 | ('SizeOfSRVI1', '<i4'), ]) | |
315 |
|
315 | |||
316 |
|
316 | |||
317 | class SRVIHeader(Header): |
|
317 | class SRVIHeader(Header): | |
318 | def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0): |
|
318 | def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0): | |
319 |
|
319 | |||
320 | self.SignatureSRVI1 = SignatureSRVI1 |
|
320 | self.SignatureSRVI1 = SignatureSRVI1 | |
321 | self.SizeOfDataBlock1 = SizeOfDataBlock1 |
|
321 | self.SizeOfDataBlock1 = SizeOfDataBlock1 | |
322 | self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1 |
|
322 | self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1 | |
323 | self.SizeOfSRVI1 = SizeOfSRVI1 |
|
323 | self.SizeOfSRVI1 = SizeOfSRVI1 | |
324 |
|
324 | |||
325 | self.SRVIHsize = 16 |
|
325 | self.SRVIHsize = 16 | |
326 |
|
326 | |||
327 | def SRVIread(self, fp): |
|
327 | def SRVIread(self, fp): | |
328 |
|
328 | |||
329 | header = numpy.fromfile(fp, SRVI_HEADER, 1) |
|
329 | header = numpy.fromfile(fp, SRVI_HEADER, 1) | |
330 |
|
330 | |||
331 | self.SignatureSRVI1 = str(header['SignatureSRVI1'][0]) |
|
331 | self.SignatureSRVI1 = str(header['SignatureSRVI1'][0]) | |
332 | self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0] |
|
332 | self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0] | |
333 | self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0]) |
|
333 | self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0]) | |
334 | self.SizeOfSRVI1 = header['SizeOfSRVI1'][0] |
|
334 | self.SizeOfSRVI1 = header['SizeOfSRVI1'][0] | |
335 | # 16 |
|
335 | # 16 | |
336 | print 'Pointer fp SRVIheader', fp.tell() |
|
336 | print 'Pointer fp SRVIheader', fp.tell() | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | SRVI_STRUCTURE = numpy.dtype([ |
|
339 | SRVI_STRUCTURE = numpy.dtype([ | |
340 | ('frame_cnt', '<u4'), |
|
340 | ('frame_cnt', '<u4'), | |
341 | ('time_t', '<u4'), # |
|
341 | ('time_t', '<u4'), # | |
342 | ('tpow', '<f4'), # |
|
342 | ('tpow', '<f4'), # | |
343 | ('npw1', '<f4'), # |
|
343 | ('npw1', '<f4'), # | |
344 | ('npw2', '<f4'), # |
|
344 | ('npw2', '<f4'), # | |
345 | ('cpw1', '<f4'), # |
|
345 | ('cpw1', '<f4'), # | |
346 | ('pcw2', '<f4'), # |
|
346 | ('pcw2', '<f4'), # | |
347 | ('ps_err', '<u4'), # |
|
347 | ('ps_err', '<u4'), # | |
348 | ('te_err', '<u4'), # |
|
348 | ('te_err', '<u4'), # | |
349 | ('rc_err', '<u4'), # |
|
349 | ('rc_err', '<u4'), # | |
350 | ('grs1', '<u4'), # |
|
350 | ('grs1', '<u4'), # | |
351 | ('grs2', '<u4'), # |
|
351 | ('grs2', '<u4'), # | |
352 | ('azipos', '<f4'), # |
|
352 | ('azipos', '<f4'), # | |
353 | ('azivel', '<f4'), # |
|
353 | ('azivel', '<f4'), # | |
354 | ('elvpos', '<f4'), # |
|
354 | ('elvpos', '<f4'), # | |
355 | ('elvvel', '<f4'), # |
|
355 | ('elvvel', '<f4'), # | |
356 | ('northAngle', '<f4'), |
|
356 | ('northAngle', '<f4'), | |
357 | ('microsec', '<u4'), # |
|
357 | ('microsec', '<u4'), # | |
358 | ('azisetvel', '<f4'), # |
|
358 | ('azisetvel', '<f4'), # | |
359 | ('elvsetpos', '<f4'), # |
|
359 | ('elvsetpos', '<f4'), # | |
360 | ('RadarConst', '<f4'), ]) # |
|
360 | ('RadarConst', '<f4'), ]) # | |
361 |
|
361 | |||
362 |
|
362 | |||
363 | class RecordHeader(Header): |
|
363 | class RecordHeader(Header): | |
364 |
|
364 | |||
365 | def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0, |
|
365 | def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0, | |
366 | cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0, |
|
366 | cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0, | |
367 | grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0, |
|
367 | grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0, | |
368 | microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0): |
|
368 | microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0): | |
369 |
|
369 | |||
370 | self.frame_cnt = frame_cnt |
|
370 | self.frame_cnt = frame_cnt | |
371 | self.dwell = time_t |
|
371 | self.dwell = time_t | |
372 | self.tpow = tpow |
|
372 | self.tpow = tpow | |
373 | self.npw1 = npw1 |
|
373 | self.npw1 = npw1 | |
374 | self.npw2 = npw2 |
|
374 | self.npw2 = npw2 | |
375 | self.cpw1 = cpw1 |
|
375 | self.cpw1 = cpw1 | |
376 | self.pcw2 = pcw2 |
|
376 | self.pcw2 = pcw2 | |
377 | self.ps_err = ps_err |
|
377 | self.ps_err = ps_err | |
378 | self.te_err = te_err |
|
378 | self.te_err = te_err | |
379 | self.rc_err = rc_err |
|
379 | self.rc_err = rc_err | |
380 | self.grs1 = grs1 |
|
380 | self.grs1 = grs1 | |
381 | self.grs2 = grs2 |
|
381 | self.grs2 = grs2 | |
382 | self.azipos = azipos |
|
382 | self.azipos = azipos | |
383 | self.azivel = azivel |
|
383 | self.azivel = azivel | |
384 | self.elvpos = elvpos |
|
384 | self.elvpos = elvpos | |
385 | self.elvvel = elvvel |
|
385 | self.elvvel = elvvel | |
386 | self.northAngle = northangle |
|
386 | self.northAngle = northangle | |
387 | self.microsec = microsec |
|
387 | self.microsec = microsec | |
388 | self.azisetvel = azisetvel |
|
388 | self.azisetvel = azisetvel | |
389 | self.elvsetpos = elvsetpos |
|
389 | self.elvsetpos = elvsetpos | |
390 | self.RadarConst = RadarConst |
|
390 | self.RadarConst = RadarConst | |
391 | self.RHsize = 84 |
|
391 | self.RHsize = 84 | |
392 | self.RecCounter = RecCounter |
|
392 | self.RecCounter = RecCounter | |
393 | self.Off2StartNxtRec = Off2StartNxtRec |
|
393 | self.Off2StartNxtRec = Off2StartNxtRec | |
394 |
|
394 | |||
395 | def RHread(self, fp): |
|
395 | def RHread(self, fp): | |
396 |
|
396 | |||
397 | # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file. |
|
397 | # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
398 |
|
398 | |||
399 | #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec) |
|
399 | #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec) | |
400 | #startFp.seek(OffRHeader, os.SEEK_SET) |
|
400 | #startFp.seek(OffRHeader, os.SEEK_SET) | |
401 |
|
401 | |||
402 | # print 'Posicion del bloque: ',OffRHeader |
|
402 | # print 'Posicion del bloque: ',OffRHeader | |
403 |
|
403 | |||
404 | header = numpy.fromfile(fp, SRVI_STRUCTURE, 1) |
|
404 | header = numpy.fromfile(fp, SRVI_STRUCTURE, 1) | |
405 |
|
405 | |||
406 | self.frame_cnt = header['frame_cnt'][0] |
|
406 | self.frame_cnt = header['frame_cnt'][0] | |
407 | self.time_t = header['time_t'][0] # |
|
407 | self.time_t = header['time_t'][0] # | |
408 | self.tpow = header['tpow'][0] # |
|
408 | self.tpow = header['tpow'][0] # | |
409 | self.npw1 = header['npw1'][0] # |
|
409 | self.npw1 = header['npw1'][0] # | |
410 | self.npw2 = header['npw2'][0] # |
|
410 | self.npw2 = header['npw2'][0] # | |
411 | self.cpw1 = header['cpw1'][0] # |
|
411 | self.cpw1 = header['cpw1'][0] # | |
412 | self.pcw2 = header['pcw2'][0] # |
|
412 | self.pcw2 = header['pcw2'][0] # | |
413 | self.ps_err = header['ps_err'][0] # |
|
413 | self.ps_err = header['ps_err'][0] # | |
414 | self.te_err = header['te_err'][0] # |
|
414 | self.te_err = header['te_err'][0] # | |
415 | self.rc_err = header['rc_err'][0] # |
|
415 | self.rc_err = header['rc_err'][0] # | |
416 | self.grs1 = header['grs1'][0] # |
|
416 | self.grs1 = header['grs1'][0] # | |
417 | self.grs2 = header['grs2'][0] # |
|
417 | self.grs2 = header['grs2'][0] # | |
418 | self.azipos = header['azipos'][0] # |
|
418 | self.azipos = header['azipos'][0] # | |
419 | self.azivel = header['azivel'][0] # |
|
419 | self.azivel = header['azivel'][0] # | |
420 | self.elvpos = header['elvpos'][0] # |
|
420 | self.elvpos = header['elvpos'][0] # | |
421 | self.elvvel = header['elvvel'][0] # |
|
421 | self.elvvel = header['elvvel'][0] # | |
422 | self.northAngle = header['northAngle'][0] # |
|
422 | self.northAngle = header['northAngle'][0] # | |
423 | self.microsec = header['microsec'][0] # |
|
423 | self.microsec = header['microsec'][0] # | |
424 | self.azisetvel = header['azisetvel'][0] # |
|
424 | self.azisetvel = header['azisetvel'][0] # | |
425 | self.elvsetpos = header['elvsetpos'][0] # |
|
425 | self.elvsetpos = header['elvsetpos'][0] # | |
426 | self.RadarConst = header['RadarConst'][0] # |
|
426 | self.RadarConst = header['RadarConst'][0] # | |
427 | # 84 |
|
427 | # 84 | |
428 |
|
428 | |||
429 | # print 'Pointer fp RECheader', fp.tell() |
|
429 | # print 'Pointer fp RECheader', fp.tell() | |
430 |
|
430 | |||
431 | #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz) |
|
431 | #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz) | |
432 |
|
432 | |||
433 | #self.RHsize = 180+20*self.nChannels |
|
433 | #self.RHsize = 180+20*self.nChannels | |
434 | #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4 |
|
434 | #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4 | |
435 | # print 'Datasize',self.Datasize |
|
435 | # print 'Datasize',self.Datasize | |
436 | #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec |
|
436 | #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec | |
437 |
|
437 | |||
438 | print '==============================================' |
|
438 | print '==============================================' | |
439 |
|
439 | |||
440 | print '==============================================' |
|
440 | print '==============================================' | |
441 |
|
441 | |||
442 | return 1 |
|
442 | return 1 | |
443 |
|
443 | |||
444 |
|
444 | |||
445 | class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader): |
|
445 | class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader): | |
446 |
|
446 | |||
447 | path = None |
|
447 | path = None | |
448 | startDate = None |
|
448 | startDate = None | |
449 | endDate = None |
|
449 | endDate = None | |
450 | startTime = None |
|
450 | startTime = None | |
451 | endTime = None |
|
451 | endTime = None | |
452 | walk = None |
|
452 | walk = None | |
453 | isConfig = False |
|
453 | isConfig = False | |
454 |
|
454 | |||
455 | fileList = None |
|
455 | fileList = None | |
456 |
|
456 | |||
457 | # metadata |
|
457 | # metadata | |
458 | TimeZone = None |
|
458 | TimeZone = None | |
459 | Interval = None |
|
459 | Interval = None | |
460 | heightList = None |
|
460 | heightList = None | |
461 |
|
461 | |||
462 | # data |
|
462 | # data | |
463 | data = None |
|
463 | data = None | |
464 | utctime = None |
|
464 | utctime = None | |
465 |
|
465 | |||
466 | def __init__(self, **kwargs): |
|
466 | def __init__(self, **kwargs): | |
467 |
|
467 | |||
468 | # Eliminar de la base la herencia |
|
468 | # Eliminar de la base la herencia | |
469 | ProcessingUnit.__init__(self, **kwargs) |
|
469 | ProcessingUnit.__init__(self, **kwargs) | |
470 | self.PointerReader = 0 |
|
470 | self.PointerReader = 0 | |
471 | self.FileHeaderFlag = False |
|
471 | self.FileHeaderFlag = False | |
472 | self.utc = None |
|
472 | self.utc = None | |
473 | self.ext = ".zspca" |
|
473 | self.ext = ".zspca" | |
474 | self.optchar = "P" |
|
474 | self.optchar = "P" | |
475 | self.fpFile = None |
|
475 | self.fpFile = None | |
476 | self.fp = None |
|
476 | self.fp = None | |
477 | self.BlockCounter = 0 |
|
477 | self.BlockCounter = 0 | |
478 | self.dtype = None |
|
478 | self.dtype = None | |
479 | self.fileSizeByHeader = None |
|
479 | self.fileSizeByHeader = None | |
480 | self.filenameList = [] |
|
480 | self.filenameList = [] | |
481 | self.fileSelector = 0 |
|
481 | self.fileSelector = 0 | |
482 | self.Off2StartNxtRec = 0 |
|
482 | self.Off2StartNxtRec = 0 | |
483 | self.RecCounter = 0 |
|
483 | self.RecCounter = 0 | |
484 | self.flagNoMoreFiles = 0 |
|
484 | self.flagNoMoreFiles = 0 | |
485 | self.data_spc = None |
|
485 | self.data_spc = None | |
486 | # self.data_cspc=None |
|
486 | # self.data_cspc=None | |
487 | self.data_output = None |
|
487 | self.data_output = None | |
488 | self.path = None |
|
488 | self.path = None | |
489 | self.OffsetStartHeader = 0 |
|
489 | self.OffsetStartHeader = 0 | |
490 | self.Off2StartData = 0 |
|
490 | self.Off2StartData = 0 | |
491 | self.ipp = 0 |
|
491 | self.ipp = 0 | |
492 | self.nFDTdataRecors = 0 |
|
492 | self.nFDTdataRecors = 0 | |
493 | self.blocksize = 0 |
|
493 | self.blocksize = 0 | |
494 | self.dataOut = Spectra() |
|
494 | self.dataOut = Spectra() | |
495 | self.profileIndex = 1 # Always |
|
495 | self.profileIndex = 1 # Always | |
496 | self.dataOut.flagNoData = False |
|
496 | self.dataOut.flagNoData = False | |
497 | self.dataOut.nRdPairs = 0 |
|
497 | self.dataOut.nRdPairs = 0 | |
498 |
self.dataOut. |
|
498 | self.dataOut.data_spc = None | |
499 | self.dataOut.data_spc = None |
|
|||
500 |
|
||||
501 | self.dataOut.normFactor = 1 |
|
|||
502 | self.nextfileflag = True |
|
499 | self.nextfileflag = True | |
503 | self.dataOut.RadarConst = 0 |
|
500 | self.dataOut.RadarConst = 0 | |
504 | self.dataOut.HSDV = [] |
|
501 | self.dataOut.HSDV = [] | |
505 | self.dataOut.NPW = [] |
|
502 | self.dataOut.NPW = [] | |
506 | self.dataOut.COFA = [] |
|
503 | self.dataOut.COFA = [] | |
507 | self.dataOut.noise = 0 |
|
504 | # self.dataOut.noise = 0 | |
508 |
|
505 | |||
509 | def Files2Read(self, fp): |
|
506 | def Files2Read(self, fp): | |
510 | ''' |
|
507 | ''' | |
511 | Function that indicates the number of .fdt files that exist in the folder to be read. |
|
508 | Function that indicates the number of .fdt files that exist in the folder to be read. | |
512 | It also creates an organized list with the names of the files to read. |
|
509 | It also creates an organized list with the names of the files to read. | |
513 | ''' |
|
510 | ''' | |
514 | # self.__checkPath() |
|
511 | # self.__checkPath() | |
515 |
|
512 | |||
516 | # Gets the list of files within the fp address |
|
513 | # Gets the list of files within the fp address | |
517 | ListaData = os.listdir(fp) |
|
514 | ListaData = os.listdir(fp) | |
518 | # Sort the list of files from least to largest by names |
|
515 | # Sort the list of files from least to largest by names | |
519 | ListaData = sorted(ListaData) |
|
516 | ListaData = sorted(ListaData) | |
520 | nFiles = 0 # File Counter |
|
517 | nFiles = 0 # File Counter | |
521 | FileList = [] # A list is created that will contain the .fdt files |
|
518 | FileList = [] # A list is created that will contain the .fdt files | |
522 | for IndexFile in ListaData: |
|
519 | for IndexFile in ListaData: | |
523 | if '.zspca' in IndexFile and '.gz' not in IndexFile: |
|
520 | if '.zspca' in IndexFile and '.gz' not in IndexFile: | |
524 | FileList.append(IndexFile) |
|
521 | FileList.append(IndexFile) | |
525 | nFiles += 1 |
|
522 | nFiles += 1 | |
526 |
|
523 | |||
527 | # print 'Files2Read' |
|
524 | # print 'Files2Read' | |
528 | # print 'Existen '+str(nFiles)+' archivos .fdt' |
|
525 | # print 'Existen '+str(nFiles)+' archivos .fdt' | |
529 |
|
526 | |||
530 | self.filenameList = FileList # List of files from least to largest by names |
|
527 | self.filenameList = FileList # List of files from least to largest by names | |
531 |
|
528 | |||
532 | def run(self, **kwargs): |
|
529 | def run(self, **kwargs): | |
533 | ''' |
|
530 | ''' | |
534 | This method will be the one that will initiate the data entry, will be called constantly. |
|
531 | This method will be the one that will initiate the data entry, will be called constantly. | |
535 | You should first verify that your Setup () is set up and then continue to acquire |
|
532 | You should first verify that your Setup () is set up and then continue to acquire | |
536 | the data to be processed with getData (). |
|
533 | the data to be processed with getData (). | |
537 | ''' |
|
534 | ''' | |
538 | if not self.isConfig: |
|
535 | if not self.isConfig: | |
539 | self.setup(**kwargs) |
|
536 | self.setup(**kwargs) | |
540 | self.isConfig = True |
|
537 | self.isConfig = True | |
541 |
|
538 | |||
542 | self.getData() |
|
539 | self.getData() | |
543 |
|
540 | |||
544 | def setup(self, path=None, |
|
541 | def setup(self, path=None, | |
545 | startDate=None, |
|
542 | startDate=None, | |
546 | endDate=None, |
|
543 | endDate=None, | |
547 | startTime=None, |
|
544 | startTime=None, | |
548 | endTime=None, |
|
545 | endTime=None, | |
549 | walk=True, |
|
546 | walk=True, | |
550 | timezone='utc', |
|
547 | timezone='utc', | |
551 | code=None, |
|
548 | code=None, | |
552 | online=False, |
|
549 | online=False, | |
553 | ReadMode=None, **kwargs): |
|
550 | ReadMode=None, **kwargs): | |
554 |
|
551 | |||
555 | self.isConfig = True |
|
552 | self.isConfig = True | |
556 |
|
553 | |||
557 | self.path = path |
|
554 | self.path = path | |
558 | self.startDate = startDate |
|
555 | self.startDate = startDate | |
559 | self.endDate = endDate |
|
556 | self.endDate = endDate | |
560 | self.startTime = startTime |
|
557 | self.startTime = startTime | |
561 | self.endTime = endTime |
|
558 | self.endTime = endTime | |
562 | self.walk = walk |
|
559 | self.walk = walk | |
563 | # self.ReadMode=int(ReadMode) |
|
560 | # self.ReadMode=int(ReadMode) | |
564 |
|
561 | |||
565 | pass |
|
562 | pass | |
566 |
|
563 | |||
567 | def getData(self): |
|
564 | def getData(self): | |
568 | ''' |
|
565 | ''' | |
569 | Before starting this function, you should check that there is still an unread file, |
|
566 | Before starting this function, you should check that there is still an unread file, | |
570 | If there are still blocks to read or if the data block is empty. |
|
567 | If there are still blocks to read or if the data block is empty. | |
571 |
|
568 | |||
572 | You should call the file "read". |
|
569 | You should call the file "read". | |
573 |
|
570 | |||
574 | ''' |
|
571 | ''' | |
575 |
|
572 | |||
576 | if self.flagNoMoreFiles: |
|
573 | if self.flagNoMoreFiles: | |
577 | self.dataOut.flagNoData = True |
|
574 | self.dataOut.flagNoData = True | |
578 | print 'NoData se vuelve true' |
|
575 | print 'NoData se vuelve true' | |
579 | return 0 |
|
576 | return 0 | |
580 |
|
577 | |||
581 | self.fp = self.path |
|
578 | self.fp = self.path | |
582 | self.Files2Read(self.fp) |
|
579 | self.Files2Read(self.fp) | |
583 | self.readFile(self.fp) |
|
580 | self.readFile(self.fp) | |
584 |
|
581 | |||
585 | self.dataOut.data_spc = self.dataOut_spc # self.data_spc.copy() |
|
582 | self.dataOut.data_spc = self.dataOut_spc # self.data_spc.copy() | |
586 | self.dataOut.RadarConst = self.RadarConst |
|
583 | self.dataOut.RadarConst = self.RadarConst | |
587 | self.dataOut.data_output = self.data_output |
|
584 | self.dataOut.data_output = self.data_output | |
588 | self.dataOut.noise = self.dataOut.getNoise() |
|
585 | self.dataOut.noise = self.dataOut.getNoise() | |
589 | # print 'ACAAAAAA', self.dataOut.noise |
|
586 | # print 'ACAAAAAA', self.dataOut.noise | |
590 | self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise |
|
587 | self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise | |
|
588 | self.dataOut.normFactor = 1 | |||
591 | # print 'self.dataOut.noise',self.dataOut.noise |
|
589 | # print 'self.dataOut.noise',self.dataOut.noise | |
592 |
|
590 | |||
593 | return self.dataOut.data_spc |
|
591 | return self.dataOut.data_spc | |
594 |
|
592 | |||
595 | def readFile(self, fp): |
|
593 | def readFile(self, fp): | |
596 | ''' |
|
594 | ''' | |
597 | You must indicate if you are reading in Online or Offline mode and load the |
|
595 | You must indicate if you are reading in Online or Offline mode and load the | |
598 | The parameters for this file reading mode. |
|
596 | The parameters for this file reading mode. | |
599 |
|
597 | |||
600 | Then you must do 2 actions: |
|
598 | Then you must do 2 actions: | |
601 |
|
599 | |||
602 | 1. Get the BLTR FileHeader. |
|
600 | 1. Get the BLTR FileHeader. | |
603 | 2. Start reading the first block. |
|
601 | 2. Start reading the first block. | |
604 | ''' |
|
602 | ''' | |
605 |
|
603 | |||
606 | # The address of the folder is generated the name of the .fdt file that will be read |
|
604 | # The address of the folder is generated the name of the .fdt file that will be read | |
607 | print "File: ", self.fileSelector + 1 |
|
605 | print "File: ", self.fileSelector + 1 | |
608 |
|
606 | |||
609 | if self.fileSelector < len(self.filenameList): |
|
607 | if self.fileSelector < len(self.filenameList): | |
610 |
|
608 | |||
611 | self.fpFile = str(fp) + '/' + \ |
|
609 | self.fpFile = str(fp) + '/' + \ | |
612 | str(self.filenameList[self.fileSelector]) |
|
610 | str(self.filenameList[self.fileSelector]) | |
613 |
|
611 | |||
614 | if self.nextfileflag == True: |
|
612 | if self.nextfileflag == True: | |
615 | self.fp = open(self.fpFile, "rb") |
|
613 | self.fp = open(self.fpFile, "rb") | |
616 | self.nextfileflag == False |
|
614 | self.nextfileflag == False | |
617 |
|
615 | |||
618 | '''HERE STARTING THE FILE READING''' |
|
616 | '''HERE STARTING THE FILE READING''' | |
619 |
|
617 | |||
620 | self.fheader = FileHeaderMIRA35c() |
|
618 | self.fheader = FileHeaderMIRA35c() | |
621 | self.fheader.FHread(self.fp) # Bltr FileHeader Reading |
|
619 | self.fheader.FHread(self.fp) # Bltr FileHeader Reading | |
622 |
|
620 | |||
623 | self.SPARrawGate1 = self.fheader.SPARrawGate1 |
|
621 | self.SPARrawGate1 = self.fheader.SPARrawGate1 | |
624 | self.SPARrawGate2 = self.fheader.SPARrawGate2 |
|
622 | self.SPARrawGate2 = self.fheader.SPARrawGate2 | |
625 | self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1 |
|
623 | self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1 | |
626 | self.Num_Bins = self.fheader.PPARsft |
|
624 | self.Num_Bins = self.fheader.PPARsft | |
627 | self.dataOut.nFFTPoints = self.fheader.PPARsft |
|
625 | self.dataOut.nFFTPoints = self.fheader.PPARsft | |
628 |
|
626 | |||
629 | self.Num_inCoh = self.fheader.PPARavc |
|
627 | self.Num_inCoh = self.fheader.PPARavc | |
630 | self.dataOut.PRF = self.fheader.PPARprf |
|
628 | self.dataOut.PRF = self.fheader.PPARprf | |
631 | self.dataOut.frequency = 34.85 * 10**9 |
|
629 | self.dataOut.frequency = 34.85 * 10**9 | |
632 | self.Lambda = SPEED_OF_LIGHT / self.dataOut.frequency |
|
630 | self.Lambda = SPEED_OF_LIGHT / self.dataOut.frequency | |
633 | self.dataOut.ippSeconds = 1. / float(self.dataOut.PRF) |
|
631 | self.dataOut.ippSeconds = 1. / float(self.dataOut.PRF) | |
634 |
|
632 | |||
635 | pulse_width = self.fheader.PPARpdr * 10**-9 |
|
633 | pulse_width = self.fheader.PPARpdr * 10**-9 | |
636 | self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width |
|
634 | self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width | |
637 |
|
635 | |||
638 | self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins, 2)) |
|
636 | self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins, 2)) | |
639 | self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2)) |
|
637 | self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2)) | |
640 |
|
638 | |||
641 | self.Ze = numpy.zeros(self.Num_Hei) |
|
639 | self.Ze = numpy.zeros(self.Num_Hei) | |
642 | self.ETA = numpy.zeros(([2, self.Num_Hei])) |
|
640 | self.ETA = numpy.zeros(([2, self.Num_Hei])) | |
643 |
|
641 | |||
644 | self.readBlock() # Block reading |
|
642 | self.readBlock() # Block reading | |
645 |
|
643 | |||
646 | else: |
|
644 | else: | |
647 | print 'readFile FlagNoData becomes true' |
|
645 | print 'readFile FlagNoData becomes true' | |
648 | self.flagNoMoreFiles = True |
|
646 | self.flagNoMoreFiles = True | |
649 | self.dataOut.flagNoData = True |
|
647 | self.dataOut.flagNoData = True | |
650 | self.FileHeaderFlag == True |
|
648 | self.FileHeaderFlag == True | |
651 | return 0 |
|
649 | return 0 | |
652 |
|
650 | |||
653 | def readBlock(self): |
|
651 | def readBlock(self): | |
654 | ''' |
|
652 | ''' | |
655 | It should be checked if the block has data, if it is not passed to the next file. |
|
653 | It should be checked if the block has data, if it is not passed to the next file. | |
656 |
|
654 | |||
657 | Then the following is done: |
|
655 | Then the following is done: | |
658 |
|
656 | |||
659 | 1. Read the RecordHeader |
|
657 | 1. Read the RecordHeader | |
660 | 2. Fill the buffer with the current block number. |
|
658 | 2. Fill the buffer with the current block number. | |
661 |
|
659 | |||
662 | ''' |
|
660 | ''' | |
663 |
|
661 | |||
664 | if self.PointerReader > 1180: |
|
662 | if self.PointerReader > 1180: | |
665 | self.fp.seek(self.PointerReader, os.SEEK_SET) |
|
663 | self.fp.seek(self.PointerReader, os.SEEK_SET) | |
666 | self.FirstPoint = self.PointerReader |
|
664 | self.FirstPoint = self.PointerReader | |
667 |
|
665 | |||
668 | else: |
|
666 | else: | |
669 | self.FirstPoint = 1180 |
|
667 | self.FirstPoint = 1180 | |
670 |
|
668 | |||
671 | self.srviHeader = SRVIHeader() |
|
669 | self.srviHeader = SRVIHeader() | |
672 |
|
670 | |||
673 | self.srviHeader.SRVIread(self.fp) # Se obtiene la cabecera del SRVI |
|
671 | self.srviHeader.SRVIread(self.fp) # Se obtiene la cabecera del SRVI | |
674 |
|
672 | |||
675 | self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque |
|
673 | self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque | |
676 |
|
674 | |||
677 | if self.blocksize == 148: |
|
675 | if self.blocksize == 148: | |
678 | print 'blocksize == 148 bug' |
|
676 | print 'blocksize == 148 bug' | |
679 | jump = numpy.fromfile(self.fp, [('jump', numpy.str_, 140)], 1) |
|
677 | jump = numpy.fromfile(self.fp, [('jump', numpy.str_, 140)], 1) | |
680 |
|
678 | |||
681 | # Se obtiene la cabecera del SRVI |
|
679 | # Se obtiene la cabecera del SRVI | |
682 | self.srviHeader.SRVIread(self.fp) |
|
680 | self.srviHeader.SRVIread(self.fp) | |
683 |
|
681 | |||
684 | if not self.srviHeader.SizeOfSRVI1: |
|
682 | if not self.srviHeader.SizeOfSRVI1: | |
685 | self.fileSelector += 1 |
|
683 | self.fileSelector += 1 | |
686 | self.nextfileflag == True |
|
684 | self.nextfileflag == True | |
687 | self.FileHeaderFlag == True |
|
685 | self.FileHeaderFlag == True | |
688 |
|
686 | |||
689 | self.recordheader = RecordHeader() |
|
687 | self.recordheader = RecordHeader() | |
690 | self.recordheader.RHread(self.fp) |
|
688 | self.recordheader.RHread(self.fp) | |
691 | self.RadarConst = self.recordheader.RadarConst |
|
689 | self.RadarConst = self.recordheader.RadarConst | |
692 | dwell = self.recordheader.time_t |
|
690 | dwell = self.recordheader.time_t | |
693 | npw1 = self.recordheader.npw1 |
|
691 | npw1 = self.recordheader.npw1 | |
694 | npw2 = self.recordheader.npw2 |
|
692 | npw2 = self.recordheader.npw2 | |
695 |
|
693 | |||
696 | self.dataOut.channelList = range(1) |
|
694 | self.dataOut.channelList = range(1) | |
697 | self.dataOut.nIncohInt = self.Num_inCoh |
|
695 | self.dataOut.nIncohInt = self.Num_inCoh | |
698 | self.dataOut.nProfiles = self.Num_Bins |
|
696 | self.dataOut.nProfiles = self.Num_Bins | |
699 | self.dataOut.nCohInt = 1 |
|
697 | self.dataOut.nCohInt = 1 | |
700 | self.dataOut.windowOfFilter = 1 |
|
698 | self.dataOut.windowOfFilter = 1 | |
701 | self.dataOut.utctime = dwell |
|
699 | self.dataOut.utctime = dwell | |
702 | self.dataOut.timeZone = 0 |
|
700 | self.dataOut.timeZone = 0 | |
703 |
|
701 | |||
704 | self.dataOut.outputInterval = self.dataOut.getTimeInterval() |
|
702 | self.dataOut.outputInterval = self.dataOut.getTimeInterval() | |
705 | self.dataOut.heightList = self.SPARrawGate1 * self.__deltaHeigth + \ |
|
703 | self.dataOut.heightList = self.SPARrawGate1 * self.__deltaHeigth + \ | |
706 | numpy.array(range(self.Num_Hei)) * self.__deltaHeigth |
|
704 | numpy.array(range(self.Num_Hei)) * self.__deltaHeigth | |
707 |
|
705 | |||
708 | self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1) |
|
706 | self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1) | |
709 | self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1) |
|
707 | self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1) | |
710 | self.HSDV_Co = numpy.fromfile( |
|
708 | self.HSDV_Co = numpy.fromfile( | |
711 | self.fp, [('HSDV_Co', '<f4')], self.Num_Hei) |
|
709 | self.fp, [('HSDV_Co', '<f4')], self.Num_Hei) | |
712 | self.HSDV_Cx = numpy.fromfile( |
|
710 | self.HSDV_Cx = numpy.fromfile( | |
713 | self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei) |
|
711 | self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei) | |
714 |
|
712 | |||
715 | self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1) |
|
713 | self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1) | |
716 | self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1) |
|
714 | self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1) | |
717 | self.COFA_Co = numpy.fromfile( |
|
715 | self.COFA_Co = numpy.fromfile( | |
718 | self.fp, [('COFA_Co', '<f4')], self.Num_Hei) |
|
716 | self.fp, [('COFA_Co', '<f4')], self.Num_Hei) | |
719 | self.COFA_Cx = numpy.fromfile( |
|
717 | self.COFA_Cx = numpy.fromfile( | |
720 | self.fp, [('COFA_Cx', '<f4')], self.Num_Hei) |
|
718 | self.fp, [('COFA_Cx', '<f4')], self.Num_Hei) | |
721 |
|
719 | |||
722 | self.ZSPCsign = numpy.fromfile( |
|
720 | self.ZSPCsign = numpy.fromfile( | |
723 | self.fp, [('ZSPCsign', numpy.str_, 4)], 1) |
|
721 | self.fp, [('ZSPCsign', numpy.str_, 4)], 1) | |
724 | self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1) |
|
722 | self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1) | |
725 |
|
723 | |||
726 | self.dataOut.HSDV[0] = self.HSDV_Co[:][0] |
|
724 | self.dataOut.HSDV[0] = self.HSDV_Co[:][0] | |
727 | self.dataOut.HSDV[1] = self.HSDV_Cx[:][0] |
|
725 | self.dataOut.HSDV[1] = self.HSDV_Cx[:][0] | |
728 |
|
726 | |||
729 | for irg in range(self.Num_Hei): |
|
727 | for irg in range(self.Num_Hei): | |
730 | # Number of spectral sub pieces containing significant power |
|
728 | # Number of spectral sub pieces containing significant power | |
731 | nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0] |
|
729 | nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0] | |
732 |
|
730 | |||
733 | for k in range(nspc): |
|
731 | for k in range(nspc): | |
734 | # Index of the spectral bin where the piece is beginning |
|
732 | # Index of the spectral bin where the piece is beginning | |
735 | binIndex = numpy.fromfile( |
|
733 | binIndex = numpy.fromfile( | |
736 | self.fp, [('binIndex', 'int16')], 1)[0][0] |
|
734 | self.fp, [('binIndex', 'int16')], 1)[0][0] | |
737 | nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[ |
|
735 | nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[ | |
738 | 0][0] # Number of bins of the piece |
|
736 | 0][0] # Number of bins of the piece | |
739 |
|
737 | |||
740 | # Co_Channel |
|
738 | # Co_Channel | |
741 | jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[ |
|
739 | jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[ | |
742 | 0][0] # Spectrum piece to be normaliced |
|
740 | 0][0] # Spectrum piece to be normaliced | |
743 | jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[ |
|
741 | jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[ | |
744 | 0][0] # Maximun piece to be normaliced |
|
742 | 0][0] # Maximun piece to be normaliced | |
745 |
|
743 | |||
746 | self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg, |
|
744 | self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg, | |
747 | binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax |
|
745 | binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax | |
748 |
|
746 | |||
749 | # Cx_Channel |
|
747 | # Cx_Channel | |
750 | jbin = numpy.fromfile( |
|
748 | jbin = numpy.fromfile( | |
751 | self.fp, [('jbin', 'uint16')], nbins)[0][0] |
|
749 | self.fp, [('jbin', 'uint16')], nbins)[0][0] | |
752 | jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0] |
|
750 | jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0] | |
753 |
|
751 | |||
754 | self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg, |
|
752 | self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg, | |
755 | binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax |
|
753 | binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax | |
756 |
|
754 | |||
757 | for bin in range(self.Num_Bins): |
|
755 | for bin in range(self.Num_Bins): | |
758 |
|
756 | |||
759 | self.data_spc[:, bin, 0] = self.data_spc[:, |
|
757 | self.data_spc[:, bin, 0] = self.data_spc[:, | |
760 | bin, 0] - self.dataOut.HSDV[:, 0] |
|
758 | bin, 0] - self.dataOut.HSDV[:, 0] | |
761 |
|
759 | |||
762 | self.data_spc[:, bin, 1] = self.data_spc[:, |
|
760 | self.data_spc[:, bin, 1] = self.data_spc[:, | |
763 | bin, 1] - self.dataOut.HSDV[:, 1] |
|
761 | bin, 1] - self.dataOut.HSDV[:, 1] | |
764 |
|
762 | |||
765 | numpy.set_printoptions(threshold='nan') |
|
763 | numpy.set_printoptions(threshold='nan') | |
766 |
|
764 | |||
767 | self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0) |
|
765 | self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0) | |
768 |
|
766 | |||
769 | self.dataOut.COFA = numpy.array([self.COFA_Co, self.COFA_Cx]) |
|
767 | self.dataOut.COFA = numpy.array([self.COFA_Co, self.COFA_Cx]) | |
770 |
|
768 | |||
771 | print ' ' |
|
769 | print ' ' | |
772 | print 'SPC', numpy.shape(self.dataOut.data_spc) |
|
770 | print 'SPC', numpy.shape(self.dataOut.data_spc) | |
773 | # print 'SPC',self.dataOut.data_spc |
|
771 | # print 'SPC',self.dataOut.data_spc | |
774 |
|
772 | |||
775 | noinor1 = 713031680 |
|
773 | noinor1 = 713031680 | |
776 | noinor2 = 30 |
|
774 | noinor2 = 30 | |
777 |
|
775 | |||
778 | npw1 = 1 # 0**(npw1/10) * noinor1 * noinor2 |
|
776 | npw1 = 1 # 0**(npw1/10) * noinor1 * noinor2 | |
779 | npw2 = 1 # 0**(npw2/10) * noinor1 * noinor2 |
|
777 | npw2 = 1 # 0**(npw2/10) * noinor1 * noinor2 | |
780 | self.dataOut.NPW = numpy.array([npw1, npw2]) |
|
778 | self.dataOut.NPW = numpy.array([npw1, npw2]) | |
781 |
|
779 | |||
782 | print ' ' |
|
780 | print ' ' | |
783 |
|
781 | |||
784 | self.data_spc = numpy.transpose(self.data_spc, (2, 1, 0)) |
|
782 | self.data_spc = numpy.transpose(self.data_spc, (2, 1, 0)) | |
785 | self.data_spc = numpy.fft.fftshift(self.data_spc, axes=1) |
|
783 | self.data_spc = numpy.fft.fftshift(self.data_spc, axes=1) | |
786 |
|
784 | |||
787 | self.data_spc = numpy.fliplr(self.data_spc) |
|
785 | self.data_spc = numpy.fliplr(self.data_spc) | |
788 |
|
786 | |||
789 | self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0) |
|
787 | self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0) | |
790 | self.dataOut_spc = numpy.ones([1, self.Num_Bins, self.Num_Hei]) |
|
788 | self.dataOut_spc = numpy.ones([1, self.Num_Bins, self.Num_Hei]) | |
791 | self.dataOut_spc[0, :, :] = self.data_spc[0, :, :] |
|
789 | self.dataOut_spc[0, :, :] = self.data_spc[0, :, :] | |
792 | # print 'SHAPE', self.dataOut_spc.shape |
|
790 | # print 'SHAPE', self.dataOut_spc.shape | |
793 | # For nyquist correction: |
|
791 | # For nyquist correction: | |
794 | # fix = 20 # ~3m/s |
|
792 | # fix = 20 # ~3m/s | |
795 | #shift = self.Num_Bins/2 + fix |
|
793 | #shift = self.Num_Bins/2 + fix | |
796 | #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]]) |
|
794 | #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]]) | |
797 |
|
795 | |||
798 | '''Block Reading, the Block Data is received and Reshape is used to give it |
|
796 | '''Block Reading, the Block Data is received and Reshape is used to give it | |
799 | shape. |
|
797 | shape. | |
800 | ''' |
|
798 | ''' | |
801 |
|
799 | |||
802 | self.PointerReader = self.fp.tell() |
|
800 | self.PointerReader = self.fp.tell() |
@@ -1,354 +1,360 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $ |
|
4 | $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 | import inspect |
|
6 | import inspect | |
7 | from fuzzywuzzy import process |
|
7 | from fuzzywuzzy import process | |
8 |
|
8 | |||
9 | def checkKwargs(method, kwargs): |
|
9 | def checkKwargs(method, kwargs): | |
10 | currentKwargs = kwargs |
|
10 | currentKwargs = kwargs | |
11 | choices = inspect.getargspec(method).args |
|
11 | choices = inspect.getargspec(method).args | |
12 | try: |
|
12 | try: | |
13 | choices.remove('self') |
|
13 | choices.remove('self') | |
14 | except Exception as e: |
|
14 | except Exception as e: | |
15 | pass |
|
15 | pass | |
16 |
|
16 | |||
17 | try: |
|
17 | try: | |
18 | choices.remove('dataOut') |
|
18 | choices.remove('dataOut') | |
19 | except Exception as e: |
|
19 | except Exception as e: | |
20 | pass |
|
20 | pass | |
21 |
|
21 | |||
22 | for kwarg in kwargs: |
|
22 | for kwarg in kwargs: | |
23 | fuzz = process.extractOne(kwarg, choices) |
|
23 | fuzz = process.extractOne(kwarg, choices) | |
24 | if fuzz is None: |
|
24 | if fuzz is None: | |
25 | continue |
|
25 | continue | |
26 | if fuzz[1] < 100: |
|
26 | if fuzz[1] < 100: | |
27 | raise Exception('\x1b[0;32;40mDid you mean {} instead of {} in {}? \x1b[0m'. |
|
27 | raise Exception('\x1b[0;32;40mDid you mean {} instead of {} in {}? \x1b[0m'. | |
28 | format(fuzz[0], kwarg, method.__self__.__class__.__name__)) |
|
28 | format(fuzz[0], kwarg, method.__self__.__class__.__name__)) | |
29 |
|
29 | |||
30 | class ProcessingUnit(object): |
|
30 | class ProcessingUnit(object): | |
31 |
|
31 | |||
32 | """ |
|
32 | """ | |
33 | Esta es la clase base para el procesamiento de datos. |
|
33 | Esta es la clase base para el procesamiento de datos. | |
34 |
|
34 | |||
35 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
35 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
36 | - Metodos internos (callMethod) |
|
36 | - Metodos internos (callMethod) | |
37 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
37 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
38 | tienen que ser agreagados con el metodo "add". |
|
38 | tienen que ser agreagados con el metodo "add". | |
39 |
|
39 | |||
40 | """ |
|
40 | """ | |
41 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
41 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
42 | dataIn = None |
|
42 | dataIn = None | |
43 | dataInList = [] |
|
43 | dataInList = [] | |
44 |
|
44 | |||
45 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
45 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
46 | dataOut = None |
|
46 | dataOut = None | |
47 |
|
47 | |||
48 | operations2RunDict = None |
|
48 | operations2RunDict = None | |
49 |
|
49 | |||
50 | isConfig = False |
|
50 | isConfig = False | |
51 |
|
51 | |||
52 |
|
52 | |||
53 | def __init__(self, *args, **kwargs): |
|
53 | def __init__(self, *args, **kwargs): | |
54 |
|
54 | |||
55 | self.dataIn = None |
|
55 | self.dataIn = None | |
56 | self.dataInList = [] |
|
56 | self.dataInList = [] | |
57 |
|
57 | |||
58 | self.dataOut = None |
|
58 | self.dataOut = None | |
59 |
|
59 | |||
60 | self.operations2RunDict = {} |
|
60 | self.operations2RunDict = {} | |
61 | self.operationKwargs = {} |
|
61 | self.operationKwargs = {} | |
62 |
|
62 | |||
63 | self.isConfig = False |
|
63 | self.isConfig = False | |
64 |
|
64 | |||
65 | self.args = args |
|
65 | self.args = args | |
66 | self.kwargs = kwargs |
|
66 | self.kwargs = kwargs | |
67 |
|
67 | |||
68 | if not hasattr(self, 'name'): |
|
68 | if not hasattr(self, 'name'): | |
69 | self.name = self.__class__.__name__ |
|
69 | self.name = self.__class__.__name__ | |
70 |
|
70 | |||
71 | checkKwargs(self.run, kwargs) |
|
71 | checkKwargs(self.run, kwargs) | |
72 |
|
72 | |||
73 | def getAllowedArgs(self): |
|
73 | def getAllowedArgs(self): | |
74 | return inspect.getargspec(self.run).args |
|
74 | if hasattr(self, '__attrs__'): | |
|
75 | return self.__attrs__ | |||
|
76 | else: | |||
|
77 | return inspect.getargspec(self.run).args | |||
75 |
|
78 | |||
76 | def addOperationKwargs(self, objId, **kwargs): |
|
79 | def addOperationKwargs(self, objId, **kwargs): | |
77 | ''' |
|
80 | ''' | |
78 | ''' |
|
81 | ''' | |
79 |
|
82 | |||
80 | self.operationKwargs[objId] = kwargs |
|
83 | self.operationKwargs[objId] = kwargs | |
81 |
|
84 | |||
82 |
|
85 | |||
83 | def addOperation(self, opObj, objId): |
|
86 | def addOperation(self, opObj, objId): | |
84 |
|
87 | |||
85 | """ |
|
88 | """ | |
86 | Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el |
|
89 | Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el | |
87 | identificador asociado a este objeto. |
|
90 | identificador asociado a este objeto. | |
88 |
|
91 | |||
89 | Input: |
|
92 | Input: | |
90 |
|
93 | |||
91 | object : objeto de la clase "Operation" |
|
94 | object : objeto de la clase "Operation" | |
92 |
|
95 | |||
93 | Return: |
|
96 | Return: | |
94 |
|
97 | |||
95 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
98 | objId : identificador del objeto, necesario para ejecutar la operacion | |
96 | """ |
|
99 | """ | |
97 |
|
100 | |||
98 | self.operations2RunDict[objId] = opObj |
|
101 | self.operations2RunDict[objId] = opObj | |
99 |
|
102 | |||
100 | return objId |
|
103 | return objId | |
101 |
|
104 | |||
102 | def getOperationObj(self, objId): |
|
105 | def getOperationObj(self, objId): | |
103 |
|
106 | |||
104 | if objId not in self.operations2RunDict.keys(): |
|
107 | if objId not in self.operations2RunDict.keys(): | |
105 | return None |
|
108 | return None | |
106 |
|
109 | |||
107 | return self.operations2RunDict[objId] |
|
110 | return self.operations2RunDict[objId] | |
108 |
|
111 | |||
109 | def operation(self, **kwargs): |
|
112 | def operation(self, **kwargs): | |
110 |
|
113 | |||
111 | """ |
|
114 | """ | |
112 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
115 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los | |
113 | atributos del objeto dataOut |
|
116 | atributos del objeto dataOut | |
114 |
|
117 | |||
115 | Input: |
|
118 | Input: | |
116 |
|
119 | |||
117 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
120 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
118 | """ |
|
121 | """ | |
119 |
|
122 | |||
120 | raise NotImplementedError |
|
123 | raise NotImplementedError | |
121 |
|
124 | |||
122 | def callMethod(self, name, opId): |
|
125 | def callMethod(self, name, opId): | |
123 |
|
126 | |||
124 | """ |
|
127 | """ | |
125 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
128 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
126 |
|
129 | |||
127 | Input: |
|
130 | Input: | |
128 | name : nombre del metodo a ejecutar |
|
131 | name : nombre del metodo a ejecutar | |
129 |
|
132 | |||
130 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
133 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
131 |
|
134 | |||
132 | """ |
|
135 | """ | |
133 |
|
136 | |||
134 | #Checking the inputs |
|
137 | #Checking the inputs | |
135 | if name == 'run': |
|
138 | if name == 'run': | |
136 |
|
139 | |||
137 | if not self.checkInputs(): |
|
140 | if not self.checkInputs(): | |
138 | self.dataOut.flagNoData = True |
|
141 | self.dataOut.flagNoData = True | |
139 | return False |
|
142 | return False | |
140 | else: |
|
143 | else: | |
141 | #Si no es un metodo RUN la entrada es la misma dataOut (interna) |
|
144 | #Si no es un metodo RUN la entrada es la misma dataOut (interna) | |
142 | if self.dataOut is not None and self.dataOut.isEmpty(): |
|
145 | if self.dataOut is not None and self.dataOut.isEmpty(): | |
143 | return False |
|
146 | return False | |
144 |
|
147 | |||
145 | #Getting the pointer to method |
|
148 | #Getting the pointer to method | |
146 | methodToCall = getattr(self, name) |
|
149 | methodToCall = getattr(self, name) | |
147 |
|
150 | |||
148 | #Executing the self method |
|
151 | #Executing the self method | |
149 |
|
152 | |||
150 | if hasattr(self, 'mp'): |
|
153 | if hasattr(self, 'mp'): | |
151 | if name=='run': |
|
154 | if name=='run': | |
152 | if self.mp is False: |
|
155 | if self.mp is False: | |
153 | self.mp = True |
|
156 | self.mp = True | |
154 | self.start() |
|
157 | self.start() | |
155 | else: |
|
158 | else: | |
156 | self.operationKwargs[opId]['parent'] = self.kwargs |
|
159 | self.operationKwargs[opId]['parent'] = self.kwargs | |
157 | methodToCall(**self.operationKwargs[opId]) |
|
160 | methodToCall(**self.operationKwargs[opId]) | |
158 | else: |
|
161 | else: | |
159 | if name=='run': |
|
162 | if name=='run': | |
160 | methodToCall(**self.kwargs) |
|
163 | methodToCall(**self.kwargs) | |
161 | else: |
|
164 | else: | |
162 | methodToCall(**self.operationKwargs[opId]) |
|
165 | methodToCall(**self.operationKwargs[opId]) | |
163 |
|
166 | |||
164 | if self.dataOut is None: |
|
167 | if self.dataOut is None: | |
165 | return False |
|
168 | return False | |
166 |
|
169 | |||
167 | if self.dataOut.isEmpty(): |
|
170 | if self.dataOut.isEmpty(): | |
168 | return False |
|
171 | return False | |
169 |
|
172 | |||
170 | return True |
|
173 | return True | |
171 |
|
174 | |||
172 | def callObject(self, objId): |
|
175 | def callObject(self, objId): | |
173 |
|
176 | |||
174 | """ |
|
177 | """ | |
175 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
178 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
176 |
|
179 | |||
177 | Input: |
|
180 | Input: | |
178 |
|
181 | |||
179 | objId : identificador del objeto a ejecutar |
|
182 | objId : identificador del objeto a ejecutar | |
180 |
|
183 | |||
181 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
184 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
182 |
|
185 | |||
183 | Return: |
|
186 | Return: | |
184 |
|
187 | |||
185 | None |
|
188 | None | |
186 | """ |
|
189 | """ | |
187 |
|
190 | |||
188 | if self.dataOut is not None and self.dataOut.isEmpty(): |
|
191 | if self.dataOut is not None and self.dataOut.isEmpty(): | |
189 | return False |
|
192 | return False | |
190 |
|
193 | |||
191 | externalProcObj = self.operations2RunDict[objId] |
|
194 | externalProcObj = self.operations2RunDict[objId] | |
192 |
|
195 | |||
193 | if hasattr(externalProcObj, 'mp'): |
|
196 | if hasattr(externalProcObj, 'mp'): | |
194 | if externalProcObj.mp is False: |
|
197 | if externalProcObj.mp is False: | |
195 | externalProcObj.kwargs['parent'] = self.kwargs |
|
198 | externalProcObj.kwargs['parent'] = self.kwargs | |
196 | self.operationKwargs[objId] = externalProcObj.kwargs |
|
199 | self.operationKwargs[objId] = externalProcObj.kwargs | |
197 | externalProcObj.mp = True |
|
200 | externalProcObj.mp = True | |
198 | externalProcObj.start() |
|
201 | externalProcObj.start() | |
199 | else: |
|
202 | else: | |
200 | externalProcObj.run(self.dataOut, **externalProcObj.kwargs) |
|
203 | externalProcObj.run(self.dataOut, **externalProcObj.kwargs) | |
201 | self.operationKwargs[objId] = externalProcObj.kwargs |
|
204 | self.operationKwargs[objId] = externalProcObj.kwargs | |
202 |
|
205 | |||
203 |
|
206 | |||
204 | return True |
|
207 | return True | |
205 |
|
208 | |||
206 | def call(self, opType, opName=None, opId=None): |
|
209 | def call(self, opType, opName=None, opId=None): | |
207 | """ |
|
210 | """ | |
208 | Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa |
|
211 | Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa | |
209 | identificada con el id "opId"; con los argumentos "**kwargs". |
|
212 | identificada con el id "opId"; con los argumentos "**kwargs". | |
210 |
|
213 | |||
211 | False si la operacion no se ha ejecutado. |
|
214 | False si la operacion no se ha ejecutado. | |
212 |
|
215 | |||
213 | Input: |
|
216 | Input: | |
214 |
|
217 | |||
215 | opType : Puede ser "self" o "external" |
|
218 | opType : Puede ser "self" o "external" | |
216 |
|
219 | |||
217 | Depende del tipo de operacion para llamar a:callMethod or callObject: |
|
220 | Depende del tipo de operacion para llamar a:callMethod or callObject: | |
218 |
|
221 | |||
219 | 1. If opType = "self": Llama a un metodo propio de esta clase: |
|
222 | 1. If opType = "self": Llama a un metodo propio de esta clase: | |
220 |
|
223 | |||
221 | name_method = getattr(self, name) |
|
224 | name_method = getattr(self, name) | |
222 | name_method(**kwargs) |
|
225 | name_method(**kwargs) | |
223 |
|
226 | |||
224 |
|
227 | |||
225 | 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la |
|
228 | 2. If opType = "other" o"external": Llama al metodo "run()" de una instancia de la | |
226 | clase "Operation" o de un derivado de ella: |
|
229 | clase "Operation" o de un derivado de ella: | |
227 |
|
230 | |||
228 | instanceName = self.operationList[opId] |
|
231 | instanceName = self.operationList[opId] | |
229 | instanceName.run(**kwargs) |
|
232 | instanceName.run(**kwargs) | |
230 |
|
233 | |||
231 | opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera |
|
234 | opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera | |
232 | usada para llamar a un metodo interno de la clase Processing |
|
235 | usada para llamar a un metodo interno de la clase Processing | |
233 |
|
236 | |||
234 | opId : Si la operacion es externa (opType = 'other' o 'external), entonces el |
|
237 | opId : Si la operacion es externa (opType = 'other' o 'external), entonces el | |
235 | "opId" sera usada para llamar al metodo "run" de la clase Operation |
|
238 | "opId" sera usada para llamar al metodo "run" de la clase Operation | |
236 | registrada anteriormente con ese Id |
|
239 | registrada anteriormente con ese Id | |
237 |
|
240 | |||
238 | Exception: |
|
241 | Exception: | |
239 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
242 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
240 | "addOperation" e identificado con el valor "opId" = el id de la operacion. |
|
243 | "addOperation" e identificado con el valor "opId" = el id de la operacion. | |
241 | De lo contrario retornara un error del tipo ValueError |
|
244 | De lo contrario retornara un error del tipo ValueError | |
242 |
|
245 | |||
243 | """ |
|
246 | """ | |
244 |
|
247 | |||
245 | if opType == 'self': |
|
248 | if opType == 'self': | |
246 |
|
249 | |||
247 | if not opName: |
|
250 | if not opName: | |
248 | raise ValueError, "opName parameter should be defined" |
|
251 | raise ValueError, "opName parameter should be defined" | |
249 |
|
252 | |||
250 | sts = self.callMethod(opName, opId) |
|
253 | sts = self.callMethod(opName, opId) | |
251 |
|
254 | |||
252 | elif opType == 'other' or opType == 'external' or opType == 'plotter': |
|
255 | elif opType == 'other' or opType == 'external' or opType == 'plotter': | |
253 |
|
256 | |||
254 | if not opId: |
|
257 | if not opId: | |
255 | raise ValueError, "opId parameter should be defined" |
|
258 | raise ValueError, "opId parameter should be defined" | |
256 |
|
259 | |||
257 | if opId not in self.operations2RunDict.keys(): |
|
260 | if opId not in self.operations2RunDict.keys(): | |
258 | raise ValueError, "Any operation with id=%s has been added" %str(opId) |
|
261 | raise ValueError, "Any operation with id=%s has been added" %str(opId) | |
259 |
|
262 | |||
260 | sts = self.callObject(opId) |
|
263 | sts = self.callObject(opId) | |
261 |
|
264 | |||
262 | else: |
|
265 | else: | |
263 | raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType |
|
266 | raise ValueError, "opType should be 'self', 'external' or 'plotter'; and not '%s'" %opType | |
264 |
|
267 | |||
265 | return sts |
|
268 | return sts | |
266 |
|
269 | |||
267 | def setInput(self, dataIn): |
|
270 | def setInput(self, dataIn): | |
268 |
|
271 | |||
269 | self.dataIn = dataIn |
|
272 | self.dataIn = dataIn | |
270 | self.dataInList.append(dataIn) |
|
273 | self.dataInList.append(dataIn) | |
271 |
|
274 | |||
272 | def getOutputObj(self): |
|
275 | def getOutputObj(self): | |
273 |
|
276 | |||
274 | return self.dataOut |
|
277 | return self.dataOut | |
275 |
|
278 | |||
276 | def checkInputs(self): |
|
279 | def checkInputs(self): | |
277 |
|
280 | |||
278 | for thisDataIn in self.dataInList: |
|
281 | for thisDataIn in self.dataInList: | |
279 |
|
282 | |||
280 | if thisDataIn.isEmpty(): |
|
283 | if thisDataIn.isEmpty(): | |
281 | return False |
|
284 | return False | |
282 |
|
285 | |||
283 | return True |
|
286 | return True | |
284 |
|
287 | |||
285 | def setup(self): |
|
288 | def setup(self): | |
286 |
|
289 | |||
287 | raise NotImplementedError |
|
290 | raise NotImplementedError | |
288 |
|
291 | |||
289 | def run(self): |
|
292 | def run(self): | |
290 |
|
293 | |||
291 | raise NotImplementedError |
|
294 | raise NotImplementedError | |
292 |
|
295 | |||
293 | def close(self): |
|
296 | def close(self): | |
294 | #Close every thread, queue or any other object here is it is neccesary. |
|
297 | #Close every thread, queue or any other object here is it is neccesary. | |
295 | return |
|
298 | return | |
296 |
|
299 | |||
297 | class Operation(object): |
|
300 | class Operation(object): | |
298 |
|
301 | |||
299 | """ |
|
302 | """ | |
300 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
303 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
301 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
304 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
302 | acumulacion dentro de esta clase |
|
305 | acumulacion dentro de esta clase | |
303 |
|
306 | |||
304 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
307 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
305 |
|
308 | |||
306 | """ |
|
309 | """ | |
307 |
|
310 | |||
308 | __buffer = None |
|
311 | __buffer = None | |
309 | isConfig = False |
|
312 | isConfig = False | |
310 |
|
313 | |||
311 | def __init__(self, **kwargs): |
|
314 | def __init__(self, **kwargs): | |
312 |
|
315 | |||
313 | self.__buffer = None |
|
316 | self.__buffer = None | |
314 | self.isConfig = False |
|
317 | self.isConfig = False | |
315 | self.kwargs = kwargs |
|
318 | self.kwargs = kwargs | |
316 | if not hasattr(self, 'name'): |
|
319 | if not hasattr(self, 'name'): | |
317 | self.name = self.__class__.__name__ |
|
320 | self.name = self.__class__.__name__ | |
318 | checkKwargs(self.run, kwargs) |
|
321 | checkKwargs(self.run, kwargs) | |
319 |
|
322 | |||
320 | def getAllowedArgs(self): |
|
323 | def getAllowedArgs(self): | |
321 | return inspect.getargspec(self.run).args |
|
324 | if hasattr(self, '__attrs__'): | |
|
325 | return self.__attrs__ | |||
|
326 | else: | |||
|
327 | return inspect.getargspec(self.run).args | |||
322 |
|
328 | |||
323 | def setup(self): |
|
329 | def setup(self): | |
324 |
|
330 | |||
325 | self.isConfig = True |
|
331 | self.isConfig = True | |
326 |
|
332 | |||
327 | raise NotImplementedError |
|
333 | raise NotImplementedError | |
328 |
|
334 | |||
329 | def run(self, dataIn, **kwargs): |
|
335 | def run(self, dataIn, **kwargs): | |
330 |
|
336 | |||
331 | """ |
|
337 | """ | |
332 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los |
|
338 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los | |
333 | atributos del objeto dataIn. |
|
339 | atributos del objeto dataIn. | |
334 |
|
340 | |||
335 | Input: |
|
341 | Input: | |
336 |
|
342 | |||
337 | dataIn : objeto del tipo JROData |
|
343 | dataIn : objeto del tipo JROData | |
338 |
|
344 | |||
339 | Return: |
|
345 | Return: | |
340 |
|
346 | |||
341 | None |
|
347 | None | |
342 |
|
348 | |||
343 | Affected: |
|
349 | Affected: | |
344 | __buffer : buffer de recepcion de datos. |
|
350 | __buffer : buffer de recepcion de datos. | |
345 |
|
351 | |||
346 | """ |
|
352 | """ | |
347 | if not self.isConfig: |
|
353 | if not self.isConfig: | |
348 | self.setup(**kwargs) |
|
354 | self.setup(**kwargs) | |
349 |
|
355 | |||
350 | raise NotImplementedError |
|
356 | raise NotImplementedError | |
351 |
|
357 | |||
352 | def close(self): |
|
358 | def close(self): | |
353 |
|
359 | |||
354 | pass |
|
360 | pass |
@@ -1,631 +1,636 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Juan C. Espinoza |
|
2 | @author: Juan C. Espinoza | |
3 | ''' |
|
3 | ''' | |
4 |
|
4 | |||
5 | import time |
|
5 | import time | |
6 | import json |
|
6 | import json | |
7 | import numpy |
|
7 | import numpy | |
8 | import paho.mqtt.client as mqtt |
|
8 | import paho.mqtt.client as mqtt | |
9 | import zmq |
|
9 | import zmq | |
10 | import datetime |
|
10 | import datetime | |
11 | from zmq.utils.monitor import recv_monitor_message |
|
11 | from zmq.utils.monitor import recv_monitor_message | |
12 | from functools import wraps |
|
12 | from functools import wraps | |
13 | from threading import Thread |
|
13 | from threading import Thread | |
14 | from multiprocessing import Process |
|
14 | from multiprocessing import Process | |
15 |
|
15 | |||
16 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit |
|
16 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit | |
17 | from schainpy.model.data.jrodata import JROData |
|
17 | from schainpy.model.data.jrodata import JROData | |
18 | from schainpy.utils import log |
|
18 | from schainpy.utils import log | |
19 |
|
19 | |||
20 | MAXNUMX = 100 |
|
20 | MAXNUMX = 100 | |
21 | MAXNUMY = 100 |
|
21 | MAXNUMY = 100 | |
22 |
|
22 | |||
23 | class PrettyFloat(float): |
|
23 | class PrettyFloat(float): | |
24 | def __repr__(self): |
|
24 | def __repr__(self): | |
25 | return '%.2f' % self |
|
25 | return '%.2f' % self | |
26 |
|
26 | |||
27 | def roundFloats(obj): |
|
27 | def roundFloats(obj): | |
28 | if isinstance(obj, list): |
|
28 | if isinstance(obj, list): | |
29 | return map(roundFloats, obj) |
|
29 | return map(roundFloats, obj) | |
30 | elif isinstance(obj, float): |
|
30 | elif isinstance(obj, float): | |
31 | return round(obj, 2) |
|
31 | return round(obj, 2) | |
32 |
|
32 | |||
33 | def decimate(z, MAXNUMY): |
|
33 | def decimate(z, MAXNUMY): | |
34 | dy = int(len(z[0])/MAXNUMY) + 1 |
|
34 | dy = int(len(z[0])/MAXNUMY) + 1 | |
35 |
|
35 | |||
36 | return z[::, ::dy] |
|
36 | return z[::, ::dy] | |
37 |
|
37 | |||
38 | class throttle(object): |
|
38 | class throttle(object): | |
39 | ''' |
|
39 | ''' | |
40 | Decorator that prevents a function from being called more than once every |
|
40 | Decorator that prevents a function from being called more than once every | |
41 | time period. |
|
41 | time period. | |
42 | To create a function that cannot be called more than once a minute, but |
|
42 | To create a function that cannot be called more than once a minute, but | |
43 | will sleep until it can be called: |
|
43 | will sleep until it can be called: | |
44 | @throttle(minutes=1) |
|
44 | @throttle(minutes=1) | |
45 | def foo(): |
|
45 | def foo(): | |
46 | pass |
|
46 | pass | |
47 |
|
47 | |||
48 | for i in range(10): |
|
48 | for i in range(10): | |
49 | foo() |
|
49 | foo() | |
50 | print "This function has run %s times." % i |
|
50 | print "This function has run %s times." % i | |
51 | ''' |
|
51 | ''' | |
52 |
|
52 | |||
53 | def __init__(self, seconds=0, minutes=0, hours=0): |
|
53 | def __init__(self, seconds=0, minutes=0, hours=0): | |
54 | self.throttle_period = datetime.timedelta( |
|
54 | self.throttle_period = datetime.timedelta( | |
55 | seconds=seconds, minutes=minutes, hours=hours |
|
55 | seconds=seconds, minutes=minutes, hours=hours | |
56 | ) |
|
56 | ) | |
57 |
|
57 | |||
58 | self.time_of_last_call = datetime.datetime.min |
|
58 | self.time_of_last_call = datetime.datetime.min | |
59 |
|
59 | |||
60 | def __call__(self, fn): |
|
60 | def __call__(self, fn): | |
61 | @wraps(fn) |
|
61 | @wraps(fn) | |
62 | def wrapper(*args, **kwargs): |
|
62 | def wrapper(*args, **kwargs): | |
63 | coerce = kwargs.pop('coerce', None) |
|
63 | coerce = kwargs.pop('coerce', None) | |
64 | if coerce: |
|
64 | if coerce: | |
65 | self.time_of_last_call = datetime.datetime.now() |
|
65 | self.time_of_last_call = datetime.datetime.now() | |
66 | return fn(*args, **kwargs) |
|
66 | return fn(*args, **kwargs) | |
67 | else: |
|
67 | else: | |
68 | now = datetime.datetime.now() |
|
68 | now = datetime.datetime.now() | |
69 | time_since_last_call = now - self.time_of_last_call |
|
69 | time_since_last_call = now - self.time_of_last_call | |
70 | time_left = self.throttle_period - time_since_last_call |
|
70 | time_left = self.throttle_period - time_since_last_call | |
71 |
|
71 | |||
72 | if time_left > datetime.timedelta(seconds=0): |
|
72 | if time_left > datetime.timedelta(seconds=0): | |
73 | return |
|
73 | return | |
74 |
|
74 | |||
75 | self.time_of_last_call = datetime.datetime.now() |
|
75 | self.time_of_last_call = datetime.datetime.now() | |
76 | return fn(*args, **kwargs) |
|
76 | return fn(*args, **kwargs) | |
77 |
|
77 | |||
78 | return wrapper |
|
78 | return wrapper | |
79 |
|
79 | |||
80 | class Data(object): |
|
80 | class Data(object): | |
81 | ''' |
|
81 | ''' | |
82 | Object to hold data to be plotted |
|
82 | Object to hold data to be plotted | |
83 | ''' |
|
83 | ''' | |
84 |
|
84 | |||
85 | def __init__(self, plottypes, throttle_value): |
|
85 | def __init__(self, plottypes, throttle_value): | |
86 | self.plottypes = plottypes |
|
86 | self.plottypes = plottypes | |
87 | self.throttle = throttle_value |
|
87 | self.throttle = throttle_value | |
88 | self.ended = False |
|
88 | self.ended = False | |
89 | self.localtime = False |
|
89 | self.localtime = False | |
90 | self.__times = [] |
|
90 | self.__times = [] | |
91 | self.__heights = [] |
|
91 | self.__heights = [] | |
92 |
|
92 | |||
93 | def __str__(self): |
|
93 | def __str__(self): | |
94 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] |
|
94 | dum = ['{}{}'.format(key, self.shape(key)) for key in self.data] | |
95 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) |
|
95 | return 'Data[{}][{}]'.format(';'.join(dum), len(self.__times)) | |
96 |
|
96 | |||
97 | def __len__(self): |
|
97 | def __len__(self): | |
98 | return len(self.__times) |
|
98 | return len(self.__times) | |
99 |
|
99 | |||
100 | def __getitem__(self, key): |
|
100 | def __getitem__(self, key): | |
101 | if key not in self.data: |
|
101 | if key not in self.data: | |
102 | raise KeyError(log.error('Missing key: {}'.format(key))) |
|
102 | raise KeyError(log.error('Missing key: {}'.format(key))) | |
103 |
|
103 | |||
104 | if 'spc' in key: |
|
104 | if 'spc' in key: | |
105 | ret = self.data[key] |
|
105 | ret = self.data[key] | |
106 | else: |
|
106 | else: | |
107 | ret = numpy.array([self.data[key][x] for x in self.times]) |
|
107 | ret = numpy.array([self.data[key][x] for x in self.times]) | |
108 | if ret.ndim > 1: |
|
108 | if ret.ndim > 1: | |
109 | ret = numpy.swapaxes(ret, 0, 1) |
|
109 | ret = numpy.swapaxes(ret, 0, 1) | |
110 | return ret |
|
110 | return ret | |
111 |
|
111 | |||
112 | def __contains__(self, key): |
|
112 | def __contains__(self, key): | |
113 | return key in self.data |
|
113 | return key in self.data | |
114 |
|
114 | |||
115 | def setup(self): |
|
115 | def setup(self): | |
116 | ''' |
|
116 | ''' | |
117 | Configure object |
|
117 | Configure object | |
118 | ''' |
|
118 | ''' | |
119 |
|
119 | |||
120 | self.ended = False |
|
120 | self.ended = False | |
121 | self.data = {} |
|
121 | self.data = {} | |
122 | self.__times = [] |
|
122 | self.__times = [] | |
123 | self.__heights = [] |
|
123 | self.__heights = [] | |
124 | self.__all_heights = set() |
|
124 | self.__all_heights = set() | |
125 | for plot in self.plottypes: |
|
125 | for plot in self.plottypes: | |
126 | if 'snr' in plot: |
|
126 | if 'snr' in plot: | |
127 | plot = 'snr' |
|
127 | plot = 'snr' | |
128 | self.data[plot] = {} |
|
128 | self.data[plot] = {} | |
129 |
|
129 | |||
130 | def shape(self, key): |
|
130 | def shape(self, key): | |
131 | ''' |
|
131 | ''' | |
132 | Get the shape of the one-element data for the given key |
|
132 | Get the shape of the one-element data for the given key | |
133 | ''' |
|
133 | ''' | |
134 |
|
134 | |||
135 | if len(self.data[key]): |
|
135 | if len(self.data[key]): | |
136 | if 'spc' in key: |
|
136 | if 'spc' in key: | |
137 | return self.data[key].shape |
|
137 | return self.data[key].shape | |
138 | return self.data[key][self.__times[0]].shape |
|
138 | return self.data[key][self.__times[0]].shape | |
139 | return (0,) |
|
139 | return (0,) | |
140 |
|
140 | |||
141 | def update(self, dataOut): |
|
141 | def update(self, dataOut): | |
142 | ''' |
|
142 | ''' | |
143 | Update data object with new dataOut |
|
143 | Update data object with new dataOut | |
144 | ''' |
|
144 | ''' | |
145 |
|
145 | |||
146 | tm = dataOut.utctime |
|
146 | tm = dataOut.utctime | |
147 | if tm in self.__times: |
|
147 | if tm in self.__times: | |
148 | return |
|
148 | return | |
149 |
|
149 | |||
150 | self.parameters = getattr(dataOut, 'parameters', []) |
|
150 | self.parameters = getattr(dataOut, 'parameters', []) | |
151 | self.pairs = dataOut.pairsList |
|
151 | self.pairs = dataOut.pairsList | |
152 | self.channels = dataOut.channelList |
|
152 | self.channels = dataOut.channelList | |
153 | self.interval = dataOut.getTimeInterval() |
|
153 | self.interval = dataOut.getTimeInterval() | |
154 | self.localtime = dataOut.useLocalTime |
|
154 | self.localtime = dataOut.useLocalTime | |
155 | if 'spc' in self.plottypes or 'cspc' in self.plottypes: |
|
155 | if 'spc' in self.plottypes or 'cspc' in self.plottypes: | |
156 | self.xrange = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) |
|
156 | self.xrange = (dataOut.getFreqRange(1)/1000., dataOut.getAcfRange(1), dataOut.getVelRange(1)) | |
157 | self.__heights.append(dataOut.heightList) |
|
157 | self.__heights.append(dataOut.heightList) | |
158 | self.__all_heights.update(dataOut.heightList) |
|
158 | self.__all_heights.update(dataOut.heightList) | |
159 | self.__times.append(tm) |
|
159 | self.__times.append(tm) | |
160 |
|
160 | |||
161 | for plot in self.plottypes: |
|
161 | for plot in self.plottypes: | |
162 | if plot == 'spc': |
|
162 | if plot == 'spc': | |
163 | z = dataOut.data_spc/dataOut.normFactor |
|
163 | z = dataOut.data_spc/dataOut.normFactor | |
164 | self.data[plot] = 10*numpy.log10(z) |
|
164 | self.data[plot] = 10*numpy.log10(z) | |
165 | if plot == 'cspc': |
|
165 | if plot == 'cspc': | |
166 | self.data[plot] = dataOut.data_cspc |
|
166 | self.data[plot] = dataOut.data_cspc | |
167 | if plot == 'noise': |
|
167 | if plot == 'noise': | |
168 | self.data[plot][tm] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) |
|
168 | self.data[plot][tm] = 10*numpy.log10(dataOut.getNoise()/dataOut.normFactor) | |
169 | if plot == 'rti': |
|
169 | if plot == 'rti': | |
170 | self.data[plot][tm] = dataOut.getPower() |
|
170 | self.data[plot][tm] = dataOut.getPower() | |
171 | if plot == 'snr_db': |
|
171 | if plot == 'snr_db': | |
172 | self.data['snr'][tm] = dataOut.data_SNR |
|
172 | self.data['snr'][tm] = dataOut.data_SNR | |
173 | if plot == 'snr': |
|
173 | if plot == 'snr': | |
174 | self.data[plot][tm] = 10*numpy.log10(dataOut.data_SNR) |
|
174 | self.data[plot][tm] = 10*numpy.log10(dataOut.data_SNR) | |
175 | if plot == 'dop': |
|
175 | if plot == 'dop': | |
176 | self.data[plot][tm] = 10*numpy.log10(dataOut.data_DOP) |
|
176 | self.data[plot][tm] = 10*numpy.log10(dataOut.data_DOP) | |
177 | if plot == 'mean': |
|
177 | if plot == 'mean': | |
178 | self.data[plot][tm] = dataOut.data_MEAN |
|
178 | self.data[plot][tm] = dataOut.data_MEAN | |
179 | if plot == 'std': |
|
179 | if plot == 'std': | |
180 | self.data[plot][tm] = dataOut.data_STD |
|
180 | self.data[plot][tm] = dataOut.data_STD | |
181 | if plot == 'coh': |
|
181 | if plot == 'coh': | |
182 | self.data[plot][tm] = dataOut.getCoherence() |
|
182 | self.data[plot][tm] = dataOut.getCoherence() | |
183 | if plot == 'phase': |
|
183 | if plot == 'phase': | |
184 | self.data[plot][tm] = dataOut.getCoherence(phase=True) |
|
184 | self.data[plot][tm] = dataOut.getCoherence(phase=True) | |
185 | if plot == 'output': |
|
185 | if plot == 'output': | |
186 | self.data[plot][tm] = dataOut.data_output |
|
186 | self.data[plot][tm] = dataOut.data_output | |
187 | if plot == 'param': |
|
187 | if plot == 'param': | |
188 | self.data[plot][tm] = dataOut.data_param |
|
188 | self.data[plot][tm] = dataOut.data_param | |
189 |
|
189 | |||
190 | def normalize_heights(self): |
|
190 | def normalize_heights(self): | |
191 | ''' |
|
191 | ''' | |
192 | Ensure same-dimension of the data for different heighList |
|
192 | Ensure same-dimension of the data for different heighList | |
193 | ''' |
|
193 | ''' | |
194 |
|
194 | |||
195 | H = numpy.array(list(self.__all_heights)) |
|
195 | H = numpy.array(list(self.__all_heights)) | |
196 | H.sort() |
|
196 | H.sort() | |
197 | for key in self.data: |
|
197 | for key in self.data: | |
198 | shape = self.shape(key)[:-1] + H.shape |
|
198 | shape = self.shape(key)[:-1] + H.shape | |
199 | for tm, obj in self.data[key].items(): |
|
199 | for tm, obj in self.data[key].items(): | |
200 | h = self.__heights[self.__times.index(tm)] |
|
200 | h = self.__heights[self.__times.index(tm)] | |
201 | if H.size == h.size: |
|
201 | if H.size == h.size: | |
202 | continue |
|
202 | continue | |
203 | index = numpy.where(numpy.in1d(H, h))[0] |
|
203 | index = numpy.where(numpy.in1d(H, h))[0] | |
204 | dummy = numpy.zeros(shape) + numpy.nan |
|
204 | dummy = numpy.zeros(shape) + numpy.nan | |
205 | if len(shape) == 2: |
|
205 | if len(shape) == 2: | |
206 | dummy[:, index] = obj |
|
206 | dummy[:, index] = obj | |
207 | else: |
|
207 | else: | |
208 | dummy[index] = obj |
|
208 | dummy[index] = obj | |
209 | self.data[key][tm] = dummy |
|
209 | self.data[key][tm] = dummy | |
210 |
|
210 | |||
211 | self.__heights = [H for tm in self.__times] |
|
211 | self.__heights = [H for tm in self.__times] | |
212 |
|
212 | |||
213 | def jsonify(self, decimate=False): |
|
213 | def jsonify(self, decimate=False): | |
214 | ''' |
|
214 | ''' | |
215 | Convert data to json |
|
215 | Convert data to json | |
216 | ''' |
|
216 | ''' | |
217 |
|
217 | |||
218 | ret = {} |
|
218 | ret = {} | |
219 | tm = self.times[-1] |
|
219 | tm = self.times[-1] | |
220 |
|
220 | |||
221 | for key, value in self.data: |
|
221 | for key, value in self.data: | |
222 | if key in ('spc', 'cspc'): |
|
222 | if key in ('spc', 'cspc'): | |
223 | ret[key] = roundFloats(self.data[key].to_list()) |
|
223 | ret[key] = roundFloats(self.data[key].to_list()) | |
224 | else: |
|
224 | else: | |
225 | ret[key] = roundFloats(self.data[key][tm].to_list()) |
|
225 | ret[key] = roundFloats(self.data[key][tm].to_list()) | |
226 |
|
226 | |||
227 | ret['timestamp'] = tm |
|
227 | ret['timestamp'] = tm | |
228 | ret['interval'] = self.interval |
|
228 | ret['interval'] = self.interval | |
229 |
|
229 | |||
230 | @property |
|
230 | @property | |
231 | def times(self): |
|
231 | def times(self): | |
232 | ''' |
|
232 | ''' | |
233 | Return the list of times of the current data |
|
233 | Return the list of times of the current data | |
234 | ''' |
|
234 | ''' | |
235 |
|
235 | |||
236 | ret = numpy.array(self.__times) |
|
236 | ret = numpy.array(self.__times) | |
237 | ret.sort() |
|
237 | ret.sort() | |
238 | return ret |
|
238 | return ret | |
239 |
|
239 | |||
240 | @property |
|
240 | @property | |
241 | def heights(self): |
|
241 | def heights(self): | |
242 | ''' |
|
242 | ''' | |
243 | Return the list of heights of the current data |
|
243 | Return the list of heights of the current data | |
244 | ''' |
|
244 | ''' | |
245 |
|
245 | |||
246 | return numpy.array(self.__heights[-1]) |
|
246 | return numpy.array(self.__heights[-1]) | |
247 |
|
247 | |||
248 | class PublishData(Operation): |
|
248 | class PublishData(Operation): | |
249 | ''' |
|
249 | ''' | |
250 | Operation to send data over zmq. |
|
250 | Operation to send data over zmq. | |
251 | ''' |
|
251 | ''' | |
252 |
|
252 | |||
|
253 | __attrs__ = ['host', 'port', 'delay', 'zeromq', 'mqtt', 'verbose'] | |||
|
254 | ||||
253 | def __init__(self, **kwargs): |
|
255 | def __init__(self, **kwargs): | |
254 | """Inicio.""" |
|
256 | """Inicio.""" | |
255 | Operation.__init__(self, **kwargs) |
|
257 | Operation.__init__(self, **kwargs) | |
256 | self.isConfig = False |
|
258 | self.isConfig = False | |
257 | self.client = None |
|
259 | self.client = None | |
258 | self.zeromq = None |
|
260 | self.zeromq = None | |
259 | self.mqtt = None |
|
261 | self.mqtt = None | |
260 |
|
262 | |||
261 | def on_disconnect(self, client, userdata, rc): |
|
263 | def on_disconnect(self, client, userdata, rc): | |
262 | if rc != 0: |
|
264 | if rc != 0: | |
263 | log.warning('Unexpected disconnection.') |
|
265 | log.warning('Unexpected disconnection.') | |
264 | self.connect() |
|
266 | self.connect() | |
265 |
|
267 | |||
266 | def connect(self): |
|
268 | def connect(self): | |
267 | log.warning('trying to connect') |
|
269 | log.warning('trying to connect') | |
268 | try: |
|
270 | try: | |
269 | self.client.connect( |
|
271 | self.client.connect( | |
270 | host=self.host, |
|
272 | host=self.host, | |
271 | port=self.port, |
|
273 | port=self.port, | |
272 | keepalive=60*10, |
|
274 | keepalive=60*10, | |
273 | bind_address='') |
|
275 | bind_address='') | |
274 | self.client.loop_start() |
|
276 | self.client.loop_start() | |
275 | # self.client.publish( |
|
277 | # self.client.publish( | |
276 | # self.topic + 'SETUP', |
|
278 | # self.topic + 'SETUP', | |
277 | # json.dumps(setup), |
|
279 | # json.dumps(setup), | |
278 | # retain=True |
|
280 | # retain=True | |
279 | # ) |
|
281 | # ) | |
280 | except: |
|
282 | except: | |
281 | log.error('MQTT Conection error.') |
|
283 | log.error('MQTT Conection error.') | |
282 | self.client = False |
|
284 | self.client = False | |
283 |
|
285 | |||
284 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): |
|
286 | def setup(self, port=1883, username=None, password=None, clientId="user", zeromq=1, verbose=True, **kwargs): | |
285 | self.counter = 0 |
|
287 | self.counter = 0 | |
286 | self.topic = kwargs.get('topic', 'schain') |
|
288 | self.topic = kwargs.get('topic', 'schain') | |
287 | self.delay = kwargs.get('delay', 0) |
|
289 | self.delay = kwargs.get('delay', 0) | |
288 | self.plottype = kwargs.get('plottype', 'spectra') |
|
290 | self.plottype = kwargs.get('plottype', 'spectra') | |
289 | self.host = kwargs.get('host', "10.10.10.82") |
|
291 | self.host = kwargs.get('host', "10.10.10.82") | |
290 | self.port = kwargs.get('port', 3000) |
|
292 | self.port = kwargs.get('port', 3000) | |
291 | self.clientId = clientId |
|
293 | self.clientId = clientId | |
292 | self.cnt = 0 |
|
294 | self.cnt = 0 | |
293 | self.zeromq = zeromq |
|
295 | self.zeromq = zeromq | |
294 | self.mqtt = kwargs.get('plottype', 0) |
|
296 | self.mqtt = kwargs.get('plottype', 0) | |
295 | self.client = None |
|
297 | self.client = None | |
296 | self.verbose = verbose |
|
298 | self.verbose = verbose | |
297 | setup = [] |
|
299 | setup = [] | |
298 | if mqtt is 1: |
|
300 | if mqtt is 1: | |
299 | self.client = mqtt.Client( |
|
301 | self.client = mqtt.Client( | |
300 | client_id=self.clientId + self.topic + 'SCHAIN', |
|
302 | client_id=self.clientId + self.topic + 'SCHAIN', | |
301 | clean_session=True) |
|
303 | clean_session=True) | |
302 | self.client.on_disconnect = self.on_disconnect |
|
304 | self.client.on_disconnect = self.on_disconnect | |
303 | self.connect() |
|
305 | self.connect() | |
304 | for plot in self.plottype: |
|
306 | for plot in self.plottype: | |
305 | setup.append({ |
|
307 | setup.append({ | |
306 | 'plot': plot, |
|
308 | 'plot': plot, | |
307 | 'topic': self.topic + plot, |
|
309 | 'topic': self.topic + plot, | |
308 | 'title': getattr(self, plot + '_' + 'title', False), |
|
310 | 'title': getattr(self, plot + '_' + 'title', False), | |
309 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), |
|
311 | 'xlabel': getattr(self, plot + '_' + 'xlabel', False), | |
310 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), |
|
312 | 'ylabel': getattr(self, plot + '_' + 'ylabel', False), | |
311 | 'xrange': getattr(self, plot + '_' + 'xrange', False), |
|
313 | 'xrange': getattr(self, plot + '_' + 'xrange', False), | |
312 | 'yrange': getattr(self, plot + '_' + 'yrange', False), |
|
314 | 'yrange': getattr(self, plot + '_' + 'yrange', False), | |
313 | 'zrange': getattr(self, plot + '_' + 'zrange', False), |
|
315 | 'zrange': getattr(self, plot + '_' + 'zrange', False), | |
314 | }) |
|
316 | }) | |
315 | if zeromq is 1: |
|
317 | if zeromq is 1: | |
316 | context = zmq.Context() |
|
318 | context = zmq.Context() | |
317 | self.zmq_socket = context.socket(zmq.PUSH) |
|
319 | self.zmq_socket = context.socket(zmq.PUSH) | |
318 | server = kwargs.get('server', 'zmq.pipe') |
|
320 | server = kwargs.get('server', 'zmq.pipe') | |
319 |
|
321 | |||
320 | if 'tcp://' in server: |
|
322 | if 'tcp://' in server: | |
321 | address = server |
|
323 | address = server | |
322 | else: |
|
324 | else: | |
323 | address = 'ipc:///tmp/%s' % server |
|
325 | address = 'ipc:///tmp/%s' % server | |
324 |
|
326 | |||
325 | self.zmq_socket.connect(address) |
|
327 | self.zmq_socket.connect(address) | |
326 | time.sleep(1) |
|
328 | time.sleep(1) | |
327 |
|
329 | |||
328 |
|
330 | |||
329 | def publish_data(self): |
|
331 | def publish_data(self): | |
330 | self.dataOut.finished = False |
|
332 | self.dataOut.finished = False | |
331 | if self.mqtt is 1: |
|
333 | if self.mqtt is 1: | |
332 | yData = self.dataOut.heightList[:2].tolist() |
|
334 | yData = self.dataOut.heightList[:2].tolist() | |
333 | if self.plottype == 'spectra': |
|
335 | if self.plottype == 'spectra': | |
334 | data = getattr(self.dataOut, 'data_spc') |
|
336 | data = getattr(self.dataOut, 'data_spc') | |
335 | z = data/self.dataOut.normFactor |
|
337 | z = data/self.dataOut.normFactor | |
336 | zdB = 10*numpy.log10(z) |
|
338 | zdB = 10*numpy.log10(z) | |
337 | xlen, ylen = zdB[0].shape |
|
339 | xlen, ylen = zdB[0].shape | |
338 | dx = int(xlen/MAXNUMX) + 1 |
|
340 | dx = int(xlen/MAXNUMX) + 1 | |
339 | dy = int(ylen/MAXNUMY) + 1 |
|
341 | dy = int(ylen/MAXNUMY) + 1 | |
340 | Z = [0 for i in self.dataOut.channelList] |
|
342 | Z = [0 for i in self.dataOut.channelList] | |
341 | for i in self.dataOut.channelList: |
|
343 | for i in self.dataOut.channelList: | |
342 | Z[i] = zdB[i][::dx, ::dy].tolist() |
|
344 | Z[i] = zdB[i][::dx, ::dy].tolist() | |
343 | payload = { |
|
345 | payload = { | |
344 | 'timestamp': self.dataOut.utctime, |
|
346 | 'timestamp': self.dataOut.utctime, | |
345 | 'data': roundFloats(Z), |
|
347 | 'data': roundFloats(Z), | |
346 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
348 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
347 | 'interval': self.dataOut.getTimeInterval(), |
|
349 | 'interval': self.dataOut.getTimeInterval(), | |
348 | 'type': self.plottype, |
|
350 | 'type': self.plottype, | |
349 | 'yData': yData |
|
351 | 'yData': yData | |
350 | } |
|
352 | } | |
351 |
|
353 | |||
352 | elif self.plottype in ('rti', 'power'): |
|
354 | elif self.plottype in ('rti', 'power'): | |
353 | data = getattr(self.dataOut, 'data_spc') |
|
355 | data = getattr(self.dataOut, 'data_spc') | |
354 | z = data/self.dataOut.normFactor |
|
356 | z = data/self.dataOut.normFactor | |
355 | avg = numpy.average(z, axis=1) |
|
357 | avg = numpy.average(z, axis=1) | |
356 | avgdB = 10*numpy.log10(avg) |
|
358 | avgdB = 10*numpy.log10(avg) | |
357 | xlen, ylen = z[0].shape |
|
359 | xlen, ylen = z[0].shape | |
358 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
360 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
359 | AVG = [0 for i in self.dataOut.channelList] |
|
361 | AVG = [0 for i in self.dataOut.channelList] | |
360 | for i in self.dataOut.channelList: |
|
362 | for i in self.dataOut.channelList: | |
361 | AVG[i] = avgdB[i][::dy].tolist() |
|
363 | AVG[i] = avgdB[i][::dy].tolist() | |
362 | payload = { |
|
364 | payload = { | |
363 | 'timestamp': self.dataOut.utctime, |
|
365 | 'timestamp': self.dataOut.utctime, | |
364 | 'data': roundFloats(AVG), |
|
366 | 'data': roundFloats(AVG), | |
365 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
367 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
366 | 'interval': self.dataOut.getTimeInterval(), |
|
368 | 'interval': self.dataOut.getTimeInterval(), | |
367 | 'type': self.plottype, |
|
369 | 'type': self.plottype, | |
368 | 'yData': yData |
|
370 | 'yData': yData | |
369 | } |
|
371 | } | |
370 | elif self.plottype == 'noise': |
|
372 | elif self.plottype == 'noise': | |
371 | noise = self.dataOut.getNoise()/self.dataOut.normFactor |
|
373 | noise = self.dataOut.getNoise()/self.dataOut.normFactor | |
372 | noisedB = 10*numpy.log10(noise) |
|
374 | noisedB = 10*numpy.log10(noise) | |
373 | payload = { |
|
375 | payload = { | |
374 | 'timestamp': self.dataOut.utctime, |
|
376 | 'timestamp': self.dataOut.utctime, | |
375 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), |
|
377 | 'data': roundFloats(noisedB.reshape(-1, 1).tolist()), | |
376 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
378 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
377 | 'interval': self.dataOut.getTimeInterval(), |
|
379 | 'interval': self.dataOut.getTimeInterval(), | |
378 | 'type': self.plottype, |
|
380 | 'type': self.plottype, | |
379 | 'yData': yData |
|
381 | 'yData': yData | |
380 | } |
|
382 | } | |
381 | elif self.plottype == 'snr': |
|
383 | elif self.plottype == 'snr': | |
382 | data = getattr(self.dataOut, 'data_SNR') |
|
384 | data = getattr(self.dataOut, 'data_SNR') | |
383 | avgdB = 10*numpy.log10(data) |
|
385 | avgdB = 10*numpy.log10(data) | |
384 |
|
386 | |||
385 | ylen = data[0].size |
|
387 | ylen = data[0].size | |
386 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 |
|
388 | dy = numpy.floor(ylen/self.__MAXNUMY) + 1 | |
387 | AVG = [0 for i in self.dataOut.channelList] |
|
389 | AVG = [0 for i in self.dataOut.channelList] | |
388 | for i in self.dataOut.channelList: |
|
390 | for i in self.dataOut.channelList: | |
389 | AVG[i] = avgdB[i][::dy].tolist() |
|
391 | AVG[i] = avgdB[i][::dy].tolist() | |
390 | payload = { |
|
392 | payload = { | |
391 | 'timestamp': self.dataOut.utctime, |
|
393 | 'timestamp': self.dataOut.utctime, | |
392 | 'data': roundFloats(AVG), |
|
394 | 'data': roundFloats(AVG), | |
393 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], |
|
395 | 'channels': ['Ch %s' % ch for ch in self.dataOut.channelList], | |
394 | 'type': self.plottype, |
|
396 | 'type': self.plottype, | |
395 | 'yData': yData |
|
397 | 'yData': yData | |
396 | } |
|
398 | } | |
397 | else: |
|
399 | else: | |
398 | print "Tipo de grafico invalido" |
|
400 | print "Tipo de grafico invalido" | |
399 | payload = { |
|
401 | payload = { | |
400 | 'data': 'None', |
|
402 | 'data': 'None', | |
401 | 'timestamp': 'None', |
|
403 | 'timestamp': 'None', | |
402 | 'type': None |
|
404 | 'type': None | |
403 | } |
|
405 | } | |
404 |
|
406 | |||
405 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) |
|
407 | self.client.publish(self.topic + self.plottype, json.dumps(payload), qos=0) | |
406 |
|
408 | |||
407 | if self.zeromq is 1: |
|
409 | if self.zeromq is 1: | |
408 | if self.verbose: |
|
410 | if self.verbose: | |
409 | log.log( |
|
411 | log.log( | |
410 | 'Sending {} - {}'.format(self.dataOut.type, self.dataOut.datatime), |
|
412 | 'Sending {} - {}'.format(self.dataOut.type, self.dataOut.datatime), | |
411 | self.name |
|
413 | self.name | |
412 | ) |
|
414 | ) | |
413 | self.zmq_socket.send_pyobj(self.dataOut) |
|
415 | self.zmq_socket.send_pyobj(self.dataOut) | |
414 |
|
416 | |||
415 | def run(self, dataOut, **kwargs): |
|
417 | def run(self, dataOut, **kwargs): | |
416 | self.dataOut = dataOut |
|
418 | self.dataOut = dataOut | |
417 | if not self.isConfig: |
|
419 | if not self.isConfig: | |
418 | self.setup(**kwargs) |
|
420 | self.setup(**kwargs) | |
419 | self.isConfig = True |
|
421 | self.isConfig = True | |
420 |
|
422 | |||
421 | self.publish_data() |
|
423 | self.publish_data() | |
422 | time.sleep(self.delay) |
|
424 | time.sleep(self.delay) | |
423 |
|
425 | |||
424 | def close(self): |
|
426 | def close(self): | |
425 | if self.zeromq is 1: |
|
427 | if self.zeromq is 1: | |
426 | self.dataOut.finished = True |
|
428 | self.dataOut.finished = True | |
427 | self.zmq_socket.send_pyobj(self.dataOut) |
|
429 | self.zmq_socket.send_pyobj(self.dataOut) | |
428 | time.sleep(0.1) |
|
430 | time.sleep(0.1) | |
429 | self.zmq_socket.close() |
|
431 | self.zmq_socket.close() | |
430 | if self.client: |
|
432 | if self.client: | |
431 | self.client.loop_stop() |
|
433 | self.client.loop_stop() | |
432 | self.client.disconnect() |
|
434 | self.client.disconnect() | |
433 |
|
435 | |||
434 |
|
436 | |||
435 | class ReceiverData(ProcessingUnit): |
|
437 | class ReceiverData(ProcessingUnit): | |
436 |
|
438 | |||
|
439 | __attrs__ = ['server'] | |||
|
440 | ||||
437 | def __init__(self, **kwargs): |
|
441 | def __init__(self, **kwargs): | |
438 |
|
442 | |||
439 | ProcessingUnit.__init__(self, **kwargs) |
|
443 | ProcessingUnit.__init__(self, **kwargs) | |
440 |
|
444 | |||
441 | self.isConfig = False |
|
445 | self.isConfig = False | |
442 | server = kwargs.get('server', 'zmq.pipe') |
|
446 | server = kwargs.get('server', 'zmq.pipe') | |
443 | if 'tcp://' in server: |
|
447 | if 'tcp://' in server: | |
444 | address = server |
|
448 | address = server | |
445 | else: |
|
449 | else: | |
446 | address = 'ipc:///tmp/%s' % server |
|
450 | address = 'ipc:///tmp/%s' % server | |
447 |
|
451 | |||
448 | self.address = address |
|
452 | self.address = address | |
449 | self.dataOut = JROData() |
|
453 | self.dataOut = JROData() | |
450 |
|
454 | |||
451 | def setup(self): |
|
455 | def setup(self): | |
452 |
|
456 | |||
453 | self.context = zmq.Context() |
|
457 | self.context = zmq.Context() | |
454 | self.receiver = self.context.socket(zmq.PULL) |
|
458 | self.receiver = self.context.socket(zmq.PULL) | |
455 | self.receiver.bind(self.address) |
|
459 | self.receiver.bind(self.address) | |
456 | time.sleep(0.5) |
|
460 | time.sleep(0.5) | |
457 | log.success('ReceiverData from {}'.format(self.address)) |
|
461 | log.success('ReceiverData from {}'.format(self.address)) | |
458 |
|
462 | |||
459 |
|
463 | |||
460 | def run(self): |
|
464 | def run(self): | |
461 |
|
465 | |||
462 | if not self.isConfig: |
|
466 | if not self.isConfig: | |
463 | self.setup() |
|
467 | self.setup() | |
464 | self.isConfig = True |
|
468 | self.isConfig = True | |
465 |
|
469 | |||
466 | self.dataOut = self.receiver.recv_pyobj() |
|
470 | self.dataOut = self.receiver.recv_pyobj() | |
467 | log.log('{} - {}'.format(self.dataOut.type, |
|
471 | log.log('{} - {}'.format(self.dataOut.type, | |
468 | self.dataOut.datatime.ctime(),), |
|
472 | self.dataOut.datatime.ctime(),), | |
469 | 'Receiving') |
|
473 | 'Receiving') | |
470 |
|
474 | |||
471 |
|
475 | |||
472 | class PlotterReceiver(ProcessingUnit, Process): |
|
476 | class PlotterReceiver(ProcessingUnit, Process): | |
473 |
|
477 | |||
474 | throttle_value = 5 |
|
478 | throttle_value = 5 | |
|
479 | __attrs__ = ['server', 'plottypes', 'realtime', 'localtime', 'throttle'] | |||
475 |
|
480 | |||
476 | def __init__(self, **kwargs): |
|
481 | def __init__(self, **kwargs): | |
477 |
|
482 | |||
478 | ProcessingUnit.__init__(self, **kwargs) |
|
483 | ProcessingUnit.__init__(self, **kwargs) | |
479 | Process.__init__(self) |
|
484 | Process.__init__(self) | |
480 | self.mp = False |
|
485 | self.mp = False | |
481 | self.isConfig = False |
|
486 | self.isConfig = False | |
482 | self.isWebConfig = False |
|
487 | self.isWebConfig = False | |
483 | self.connections = 0 |
|
488 | self.connections = 0 | |
484 | server = kwargs.get('server', 'zmq.pipe') |
|
489 | server = kwargs.get('server', 'zmq.pipe') | |
485 | plot_server = kwargs.get('plot_server', 'zmq.web') |
|
490 | plot_server = kwargs.get('plot_server', 'zmq.web') | |
486 | if 'tcp://' in server: |
|
491 | if 'tcp://' in server: | |
487 | address = server |
|
492 | address = server | |
488 | else: |
|
493 | else: | |
489 | address = 'ipc:///tmp/%s' % server |
|
494 | address = 'ipc:///tmp/%s' % server | |
490 |
|
495 | |||
491 | if 'tcp://' in plot_server: |
|
496 | if 'tcp://' in plot_server: | |
492 | plot_address = plot_server |
|
497 | plot_address = plot_server | |
493 | else: |
|
498 | else: | |
494 | plot_address = 'ipc:///tmp/%s' % plot_server |
|
499 | plot_address = 'ipc:///tmp/%s' % plot_server | |
495 |
|
500 | |||
496 | self.address = address |
|
501 | self.address = address | |
497 | self.plot_address = plot_address |
|
502 | self.plot_address = plot_address | |
498 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] |
|
503 | self.plottypes = [s.strip() for s in kwargs.get('plottypes', 'rti').split(',')] | |
499 | self.realtime = kwargs.get('realtime', False) |
|
504 | self.realtime = kwargs.get('realtime', False) | |
500 | self.localtime = kwargs.get('localtime', True) |
|
505 | self.localtime = kwargs.get('localtime', True) | |
501 | self.throttle_value = kwargs.get('throttle', 5) |
|
506 | self.throttle_value = kwargs.get('throttle', 5) | |
502 | self.sendData = self.initThrottle(self.throttle_value) |
|
507 | self.sendData = self.initThrottle(self.throttle_value) | |
503 | self.dates = [] |
|
508 | self.dates = [] | |
504 | self.setup() |
|
509 | self.setup() | |
505 |
|
510 | |||
506 | def setup(self): |
|
511 | def setup(self): | |
507 |
|
512 | |||
508 | self.data = Data(self.plottypes, self.throttle_value) |
|
513 | self.data = Data(self.plottypes, self.throttle_value) | |
509 | self.isConfig = True |
|
514 | self.isConfig = True | |
510 |
|
515 | |||
511 | def event_monitor(self, monitor): |
|
516 | def event_monitor(self, monitor): | |
512 |
|
517 | |||
513 | events = {} |
|
518 | events = {} | |
514 |
|
519 | |||
515 | for name in dir(zmq): |
|
520 | for name in dir(zmq): | |
516 | if name.startswith('EVENT_'): |
|
521 | if name.startswith('EVENT_'): | |
517 | value = getattr(zmq, name) |
|
522 | value = getattr(zmq, name) | |
518 | events[value] = name |
|
523 | events[value] = name | |
519 |
|
524 | |||
520 | while monitor.poll(): |
|
525 | while monitor.poll(): | |
521 | evt = recv_monitor_message(monitor) |
|
526 | evt = recv_monitor_message(monitor) | |
522 | if evt['event'] == 32: |
|
527 | if evt['event'] == 32: | |
523 | self.connections += 1 |
|
528 | self.connections += 1 | |
524 | if evt['event'] == 512: |
|
529 | if evt['event'] == 512: | |
525 | pass |
|
530 | pass | |
526 |
|
531 | |||
527 | evt.update({'description': events[evt['event']]}) |
|
532 | evt.update({'description': events[evt['event']]}) | |
528 |
|
533 | |||
529 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: |
|
534 | if evt['event'] == zmq.EVENT_MONITOR_STOPPED: | |
530 | break |
|
535 | break | |
531 | monitor.close() |
|
536 | monitor.close() | |
532 | print('event monitor thread done!') |
|
537 | print('event monitor thread done!') | |
533 |
|
538 | |||
534 | def initThrottle(self, throttle_value): |
|
539 | def initThrottle(self, throttle_value): | |
535 |
|
540 | |||
536 | @throttle(seconds=throttle_value) |
|
541 | @throttle(seconds=throttle_value) | |
537 | def sendDataThrottled(fn_sender, data): |
|
542 | def sendDataThrottled(fn_sender, data): | |
538 | fn_sender(data) |
|
543 | fn_sender(data) | |
539 |
|
544 | |||
540 | return sendDataThrottled |
|
545 | return sendDataThrottled | |
541 |
|
546 | |||
542 | def send(self, data): |
|
547 | def send(self, data): | |
543 | log.success('Sending {}'.format(data), self.name) |
|
548 | log.success('Sending {}'.format(data), self.name) | |
544 | self.sender.send_pyobj(data) |
|
549 | self.sender.send_pyobj(data) | |
545 |
|
550 | |||
546 | def run(self): |
|
551 | def run(self): | |
547 |
|
552 | |||
548 | log.success( |
|
553 | log.success( | |
549 | 'Starting from {}'.format(self.address), |
|
554 | 'Starting from {}'.format(self.address), | |
550 | self.name |
|
555 | self.name | |
551 | ) |
|
556 | ) | |
552 |
|
557 | |||
553 | self.context = zmq.Context() |
|
558 | self.context = zmq.Context() | |
554 | self.receiver = self.context.socket(zmq.PULL) |
|
559 | self.receiver = self.context.socket(zmq.PULL) | |
555 | self.receiver.bind(self.address) |
|
560 | self.receiver.bind(self.address) | |
556 | monitor = self.receiver.get_monitor_socket() |
|
561 | monitor = self.receiver.get_monitor_socket() | |
557 | self.sender = self.context.socket(zmq.PUB) |
|
562 | self.sender = self.context.socket(zmq.PUB) | |
558 | if self.realtime: |
|
563 | if self.realtime: | |
559 | self.sender_web = self.context.socket(zmq.PUB) |
|
564 | self.sender_web = self.context.socket(zmq.PUB) | |
560 | self.sender_web.connect(self.plot_address) |
|
565 | self.sender_web.connect(self.plot_address) | |
561 | time.sleep(1) |
|
566 | time.sleep(1) | |
562 |
|
567 | |||
563 | if 'server' in self.kwargs: |
|
568 | if 'server' in self.kwargs: | |
564 | self.sender.bind("ipc:///tmp/{}.plots".format(self.kwargs['server'])) |
|
569 | self.sender.bind("ipc:///tmp/{}.plots".format(self.kwargs['server'])) | |
565 | else: |
|
570 | else: | |
566 | self.sender.bind("ipc:///tmp/zmq.plots") |
|
571 | self.sender.bind("ipc:///tmp/zmq.plots") | |
567 |
|
572 | |||
568 | time.sleep(2) |
|
573 | time.sleep(2) | |
569 |
|
574 | |||
570 | t = Thread(target=self.event_monitor, args=(monitor,)) |
|
575 | t = Thread(target=self.event_monitor, args=(monitor,)) | |
571 | t.start() |
|
576 | t.start() | |
572 |
|
577 | |||
573 | while True: |
|
578 | while True: | |
574 | dataOut = self.receiver.recv_pyobj() |
|
579 | dataOut = self.receiver.recv_pyobj() | |
575 | if not dataOut.flagNoData: |
|
580 | if not dataOut.flagNoData: | |
576 | if dataOut.type == 'Parameters': |
|
581 | if dataOut.type == 'Parameters': | |
577 | tm = dataOut.utctimeInit |
|
582 | tm = dataOut.utctimeInit | |
578 | else: |
|
583 | else: | |
579 | tm = dataOut.utctime |
|
584 | tm = dataOut.utctime | |
580 | if dataOut.useLocalTime: |
|
585 | if dataOut.useLocalTime: | |
581 | if not self.localtime: |
|
586 | if not self.localtime: | |
582 | tm += time.timezone |
|
587 | tm += time.timezone | |
583 | dt = datetime.datetime.fromtimestamp(tm).date() |
|
588 | dt = datetime.datetime.fromtimestamp(tm).date() | |
584 | else: |
|
589 | else: | |
585 | if self.localtime: |
|
590 | if self.localtime: | |
586 | tm -= time.timezone |
|
591 | tm -= time.timezone | |
587 | dt = datetime.datetime.utcfromtimestamp(tm).date() |
|
592 | dt = datetime.datetime.utcfromtimestamp(tm).date() | |
588 | coerce = False |
|
593 | coerce = False | |
589 | if dt not in self.dates: |
|
594 | if dt not in self.dates: | |
590 | if self.data: |
|
595 | if self.data: | |
591 | self.data.ended = True |
|
596 | self.data.ended = True | |
592 | self.send(self.data) |
|
597 | self.send(self.data) | |
593 | coerce = True |
|
598 | coerce = True | |
594 | self.data.setup() |
|
599 | self.data.setup() | |
595 | self.dates.append(dt) |
|
600 | self.dates.append(dt) | |
596 |
|
601 | |||
597 | self.data.update(dataOut) |
|
602 | self.data.update(dataOut) | |
598 |
|
603 | |||
599 | if dataOut.finished is True: |
|
604 | if dataOut.finished is True: | |
600 | self.connections -= 1 |
|
605 | self.connections -= 1 | |
601 | if self.connections == 0 and dt in self.dates: |
|
606 | if self.connections == 0 and dt in self.dates: | |
602 | self.data.ended = True |
|
607 | self.data.ended = True | |
603 | self.send(self.data) |
|
608 | self.send(self.data) | |
604 | self.data.setup() |
|
609 | self.data.setup() | |
605 | else: |
|
610 | else: | |
606 | if self.realtime: |
|
611 | if self.realtime: | |
607 | self.send(self.data) |
|
612 | self.send(self.data) | |
608 | # self.sender_web.send_string(self.data.jsonify()) |
|
613 | # self.sender_web.send_string(self.data.jsonify()) | |
609 | else: |
|
614 | else: | |
610 | self.sendData(self.send, self.data, coerce=coerce) |
|
615 | self.sendData(self.send, self.data, coerce=coerce) | |
611 | coerce = False |
|
616 | coerce = False | |
612 |
|
617 | |||
613 | return |
|
618 | return | |
614 |
|
619 | |||
615 | def sendToWeb(self): |
|
620 | def sendToWeb(self): | |
616 |
|
621 | |||
617 | if not self.isWebConfig: |
|
622 | if not self.isWebConfig: | |
618 | context = zmq.Context() |
|
623 | context = zmq.Context() | |
619 | sender_web_config = context.socket(zmq.PUB) |
|
624 | sender_web_config = context.socket(zmq.PUB) | |
620 | if 'tcp://' in self.plot_address: |
|
625 | if 'tcp://' in self.plot_address: | |
621 | dum, address, port = self.plot_address.split(':') |
|
626 | dum, address, port = self.plot_address.split(':') | |
622 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) |
|
627 | conf_address = '{}:{}:{}'.format(dum, address, int(port)+1) | |
623 | else: |
|
628 | else: | |
624 | conf_address = self.plot_address + '.config' |
|
629 | conf_address = self.plot_address + '.config' | |
625 | sender_web_config.bind(conf_address) |
|
630 | sender_web_config.bind(conf_address) | |
626 | time.sleep(1) |
|
631 | time.sleep(1) | |
627 | for kwargs in self.operationKwargs.values(): |
|
632 | for kwargs in self.operationKwargs.values(): | |
628 | if 'plot' in kwargs: |
|
633 | if 'plot' in kwargs: | |
629 | log.success('[Sending] Config data to web for {}'.format(kwargs['code'].upper())) |
|
634 | log.success('[Sending] Config data to web for {}'.format(kwargs['code'].upper())) | |
630 | sender_web_config.send_string(json.dumps(kwargs)) |
|
635 | sender_web_config.send_string(json.dumps(kwargs)) | |
631 | self.isWebConfig = True |
|
636 | self.isWebConfig = True |
@@ -1,81 +1,80 | |||||
1 | import schainpy |
|
1 | import schainpy | |
2 | from schainpy.model import Operation, ProcessingUnit |
|
2 | from schainpy.model import Operation, ProcessingUnit | |
3 | from importlib import import_module |
|
|||
4 | from pydoc import locate |
|
3 | from pydoc import locate | |
5 |
|
4 | |||
6 | def clean_modules(module): |
|
5 | def clean_modules(module): | |
7 | noEndsUnder = [x for x in module if not x.endswith('__')] |
|
6 | noEndsUnder = [x for x in module if not x.endswith('__')] | |
8 | noStartUnder = [x for x in noEndsUnder if not x.startswith('__')] |
|
7 | noStartUnder = [x for x in noEndsUnder if not x.startswith('__')] | |
9 | noFullUpper = [x for x in noStartUnder if not x.isupper()] |
|
8 | noFullUpper = [x for x in noStartUnder if not x.isupper()] | |
10 | return noFullUpper |
|
9 | return noFullUpper | |
11 |
|
10 | |||
12 | def check_module(possible, instance): |
|
11 | def check_module(possible, instance): | |
13 | def check(x): |
|
12 | def check(x): | |
14 | try: |
|
13 | try: | |
15 | instancia = locate('schainpy.model.{}'.format(x)) |
|
14 | instancia = locate('schainpy.model.{}'.format(x)) | |
16 | return isinstance(instancia(), instance) |
|
15 | return isinstance(instancia(), instance) | |
17 | except Exception as e: |
|
16 | except Exception as e: | |
18 | return False |
|
17 | return False | |
19 | clean = clean_modules(possible) |
|
18 | clean = clean_modules(possible) | |
20 | return [x for x in clean if check(x)] |
|
19 | return [x for x in clean if check(x)] | |
21 |
|
20 | |||
22 |
|
21 | |||
23 | def getProcs(): |
|
22 | def getProcs(): | |
24 |
module = dir( |
|
23 | module = dir(schainpy.model) | |
25 | procs = check_module(module, ProcessingUnit) |
|
24 | procs = check_module(module, ProcessingUnit) | |
26 | try: |
|
25 | try: | |
27 | procs.remove('ProcessingUnit') |
|
26 | procs.remove('ProcessingUnit') | |
28 | except Exception as e: |
|
27 | except Exception as e: | |
29 | pass |
|
28 | pass | |
30 | return procs |
|
29 | return procs | |
31 |
|
30 | |||
32 | def getOperations(): |
|
31 | def getOperations(): | |
33 |
module = dir( |
|
32 | module = dir(schainpy.model) | |
34 | noProcs = [x for x in module if not x.endswith('Proc')] |
|
33 | noProcs = [x for x in module if not x.endswith('Proc')] | |
35 | operations = check_module(noProcs, Operation) |
|
34 | operations = check_module(noProcs, Operation) | |
36 | try: |
|
35 | try: | |
37 | operations.remove('Operation') |
|
36 | operations.remove('Operation') | |
38 | except Exception as e: |
|
37 | except Exception as e: | |
39 | pass |
|
38 | pass | |
40 | return operations |
|
39 | return operations | |
41 |
|
40 | |||
42 | def getArgs(op): |
|
41 | def getArgs(op): | |
43 | module = locate('schainpy.model.{}'.format(op)) |
|
42 | module = locate('schainpy.model.{}'.format(op)) | |
44 | args = module().getAllowedArgs() |
|
43 | args = module().getAllowedArgs() | |
45 | try: |
|
44 | try: | |
46 | args.remove('self') |
|
45 | args.remove('self') | |
47 | except Exception as e: |
|
46 | except Exception as e: | |
48 | pass |
|
47 | pass | |
49 | try: |
|
48 | try: | |
50 | args.remove('dataOut') |
|
49 | args.remove('dataOut') | |
51 | except Exception as e: |
|
50 | except Exception as e: | |
52 | pass |
|
51 | pass | |
53 | return args |
|
52 | return args | |
54 |
|
53 | |||
55 | def getAll(): |
|
54 | def getAll(): | |
56 |
allModules = dir( |
|
55 | allModules = dir(schainpy.model) | |
57 | modules = check_module(allModules, Operation) |
|
56 | modules = check_module(allModules, Operation) | |
58 | modules.extend(check_module(allModules, ProcessingUnit)) |
|
57 | modules.extend(check_module(allModules, ProcessingUnit)) | |
59 | return modules |
|
58 | return modules | |
60 |
|
59 | |||
61 | def formatArgs(op): |
|
60 | def formatArgs(op): | |
62 | args = getArgs(op) |
|
61 | args = getArgs(op) | |
63 |
|
62 | |||
64 | argsAsKey = ["\t'{}'".format(x) for x in args] |
|
63 | argsAsKey = ["\t'{}'".format(x) for x in args] | |
65 | argsFormatted = ": 'string',\n".join(argsAsKey) |
|
64 | argsFormatted = ": 'string',\n".join(argsAsKey) | |
66 |
|
65 | |||
67 | print op |
|
66 | print op | |
68 | print "parameters = { \n" + argsFormatted + ": 'string',\n }" |
|
67 | print "parameters = { \n" + argsFormatted + ": 'string',\n }" | |
69 | print '\n' |
|
68 | print '\n' | |
70 |
|
69 | |||
71 |
|
70 | |||
72 | if __name__ == "__main__": |
|
71 | if __name__ == "__main__": | |
73 | getAll() |
|
72 | getAll() | |
74 | [formatArgs(x) for x in getAll()] |
|
73 | [formatArgs(x) for x in getAll()] | |
75 |
|
74 | |||
76 | ''' |
|
75 | ''' | |
77 | parameters = { |
|
76 | parameters = { | |
78 | 'id': , |
|
77 | 'id': , | |
79 | 'wintitle': , |
|
78 | 'wintitle': , | |
80 | } |
|
79 | } | |
81 | ''' No newline at end of file |
|
80 | ''' |
General Comments 0
You need to be logged in to leave comments.
Login now