@@ -1,374 +1,373 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import sys |
|
3 | import sys | |
4 | import matplotlib |
|
4 | import matplotlib | |
5 | if sys.platform == 'linux': |
|
5 | ||
6 | matplotlib.use("GTKAgg") |
|
6 | if 'linux' in sys.platform: | |
7 | if sys.platform == 'darwin': |
|
7 | matplotlib.use("TKAgg") | |
|
8 | ||||
|
9 | if 'darwin' in sys.platform: | |||
8 | matplotlib.use("TKAgg") |
|
10 | matplotlib.use("TKAgg") | |
|
11 | ||||
9 | import matplotlib.pyplot |
|
12 | import matplotlib.pyplot | |
10 | import matplotlib.dates |
|
|||
11 | #import scitools.numpyutils |
|
|||
12 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
|||
13 |
|
13 | |||
14 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter |
|
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
15 | from matplotlib.ticker import FuncFormatter |
|
|||
16 | from matplotlib.ticker import * |
|
15 | from matplotlib.ticker import * | |
17 |
|
16 | |||
18 | ########################################### |
|
17 | ########################################### | |
19 | #Actualizacion de las funciones del driver |
|
18 | #Actualizacion de las funciones del driver | |
20 | ########################################### |
|
19 | ########################################### | |
21 |
|
20 | |||
22 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
21 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
23 |
|
22 | |||
24 | matplotlib.pyplot.ioff() |
|
23 | matplotlib.pyplot.ioff() | |
25 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
24 | fig = matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
26 | fig.canvas.manager.set_window_title(wintitle) |
|
25 | fig.canvas.manager.set_window_title(wintitle) | |
27 | fig.canvas.manager.resize(width, height) |
|
26 | fig.canvas.manager.resize(width, height) | |
28 | matplotlib.pyplot.ion() |
|
27 | matplotlib.pyplot.ion() | |
29 | matplotlib.pyplot.show() |
|
28 | matplotlib.pyplot.show() | |
30 |
|
29 | |||
31 | return fig |
|
30 | return fig | |
32 |
|
31 | |||
33 | def closeFigure(): |
|
32 | def closeFigure(): | |
34 |
|
33 | |||
35 | matplotlib.pyplot.ioff() |
|
34 | matplotlib.pyplot.ioff() | |
36 | matplotlib.pyplot.show() |
|
35 | matplotlib.pyplot.show() | |
37 |
|
36 | |||
38 | return |
|
37 | return | |
39 |
|
38 | |||
40 | def saveFigure(fig, filename): |
|
39 | def saveFigure(fig, filename): | |
41 |
|
40 | |||
42 | matplotlib.pyplot.ioff() |
|
41 | matplotlib.pyplot.ioff() | |
43 | fig.savefig(filename) |
|
42 | fig.savefig(filename) | |
44 | matplotlib.pyplot.ion() |
|
43 | matplotlib.pyplot.ion() | |
45 |
|
44 | |||
46 | def setWinTitle(fig, title): |
|
45 | def setWinTitle(fig, title): | |
47 |
|
46 | |||
48 | fig.canvas.manager.set_window_title(title) |
|
47 | fig.canvas.manager.set_window_title(title) | |
49 |
|
48 | |||
50 | def setTitle(fig, title): |
|
49 | def setTitle(fig, title): | |
51 |
|
50 | |||
52 | fig.suptitle(title) |
|
51 | fig.suptitle(title) | |
53 |
|
52 | |||
54 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
53 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
55 |
|
54 | |||
56 | matplotlib.pyplot.ioff() |
|
55 | matplotlib.pyplot.ioff() | |
57 | matplotlib.pyplot.figure(fig.number) |
|
56 | matplotlib.pyplot.figure(fig.number) | |
58 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
57 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
59 | (xpos, ypos), |
|
58 | (xpos, ypos), | |
60 | colspan=colspan, |
|
59 | colspan=colspan, | |
61 | rowspan=rowspan) |
|
60 | rowspan=rowspan) | |
62 |
|
61 | |||
63 | matplotlib.pyplot.ion() |
|
62 | matplotlib.pyplot.ion() | |
64 | return axes |
|
63 | return axes | |
65 |
|
64 | |||
66 | def setAxesText(ax, text): |
|
65 | def setAxesText(ax, text): | |
67 |
|
66 | |||
68 | ax.annotate(text, |
|
67 | ax.annotate(text, | |
69 | xy = (.1, .99), |
|
68 | xy = (.1, .99), | |
70 | xycoords = 'figure fraction', |
|
69 | xycoords = 'figure fraction', | |
71 | horizontalalignment = 'left', |
|
70 | horizontalalignment = 'left', | |
72 | verticalalignment = 'top', |
|
71 | verticalalignment = 'top', | |
73 | fontsize = 10) |
|
72 | fontsize = 10) | |
74 |
|
73 | |||
75 | def printLabels(ax, xlabel, ylabel, title): |
|
74 | def printLabels(ax, xlabel, ylabel, title): | |
76 |
|
75 | |||
77 | ax.set_xlabel(xlabel, size=11) |
|
76 | ax.set_xlabel(xlabel, size=11) | |
78 | ax.set_ylabel(ylabel, size=11) |
|
77 | ax.set_ylabel(ylabel, size=11) | |
79 | ax.set_title(title, size=12) |
|
78 | ax.set_title(title, size=12) | |
80 |
|
79 | |||
81 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
80 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
82 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
81 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
83 | nxticks=4, nyticks=10, |
|
82 | nxticks=4, nyticks=10, | |
84 | grid=None): |
|
83 | grid=None): | |
85 |
|
84 | |||
86 | """ |
|
85 | """ | |
87 |
|
86 | |||
88 | Input: |
|
87 | Input: | |
89 | grid : None, 'both', 'x', 'y' |
|
88 | grid : None, 'both', 'x', 'y' | |
90 | """ |
|
89 | """ | |
91 |
|
90 | |||
92 | matplotlib.pyplot.ioff() |
|
91 | matplotlib.pyplot.ioff() | |
93 |
|
92 | |||
94 | ax.set_xlim([xmin,xmax]) |
|
93 | ax.set_xlim([xmin,xmax]) | |
95 | ax.set_ylim([ymin,ymax]) |
|
94 | ax.set_ylim([ymin,ymax]) | |
96 |
|
95 | |||
97 | printLabels(ax, xlabel, ylabel, title) |
|
96 | printLabels(ax, xlabel, ylabel, title) | |
98 |
|
97 | |||
99 | ###################################################### |
|
98 | ###################################################### | |
100 | if (xmax-xmin)<=1: |
|
99 | if (xmax-xmin)<=1: | |
101 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
100 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
102 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
101 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
103 | ax.set_xticks(xtickspos) |
|
102 | ax.set_xticks(xtickspos) | |
104 | else: |
|
103 | else: | |
105 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
104 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
106 | ax.set_xticks(xtickspos) |
|
105 | ax.set_xticks(xtickspos) | |
107 |
|
106 | |||
108 | for tick in ax.get_xticklabels(): |
|
107 | for tick in ax.get_xticklabels(): | |
109 | tick.set_visible(xtick_visible) |
|
108 | tick.set_visible(xtick_visible) | |
110 |
|
109 | |||
111 | for tick in ax.xaxis.get_major_ticks(): |
|
110 | for tick in ax.xaxis.get_major_ticks(): | |
112 | tick.label.set_fontsize(ticksize) |
|
111 | tick.label.set_fontsize(ticksize) | |
113 |
|
112 | |||
114 | ###################################################### |
|
113 | ###################################################### | |
115 | for tick in ax.get_yticklabels(): |
|
114 | for tick in ax.get_yticklabels(): | |
116 | tick.set_visible(ytick_visible) |
|
115 | tick.set_visible(ytick_visible) | |
117 |
|
116 | |||
118 | for tick in ax.yaxis.get_major_ticks(): |
|
117 | for tick in ax.yaxis.get_major_ticks(): | |
119 | tick.label.set_fontsize(ticksize) |
|
118 | tick.label.set_fontsize(ticksize) | |
120 |
|
119 | |||
121 | ax.plot(x, y) |
|
120 | ax.plot(x, y) | |
122 | iplot = ax.lines[-1] |
|
121 | iplot = ax.lines[-1] | |
123 |
|
122 | |||
124 | ###################################################### |
|
123 | ###################################################### | |
125 | if '0.' in matplotlib.__version__[0:2]: |
|
124 | if '0.' in matplotlib.__version__[0:2]: | |
126 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
125 | print "The matplotlib version has to be updated to 1.1 or newer" | |
127 | return iplot |
|
126 | return iplot | |
128 |
|
127 | |||
129 | if '1.0.' in matplotlib.__version__[0:4]: |
|
128 | if '1.0.' in matplotlib.__version__[0:4]: | |
130 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
129 | print "The matplotlib version has to be updated to 1.1 or newer" | |
131 | return iplot |
|
130 | return iplot | |
132 |
|
131 | |||
133 | if grid != None: |
|
132 | if grid != None: | |
134 | ax.grid(b=True, which='major', axis=grid) |
|
133 | ax.grid(b=True, which='major', axis=grid) | |
135 |
|
134 | |||
136 | matplotlib.pyplot.tight_layout() |
|
135 | matplotlib.pyplot.tight_layout() | |
137 |
|
136 | |||
138 | matplotlib.pyplot.ion() |
|
137 | matplotlib.pyplot.ion() | |
139 |
|
138 | |||
140 | return iplot |
|
139 | return iplot | |
141 |
|
140 | |||
142 | def set_linedata(ax, x, y, idline): |
|
141 | def set_linedata(ax, x, y, idline): | |
143 |
|
142 | |||
144 | ax.lines[idline].set_data(x,y) |
|
143 | ax.lines[idline].set_data(x,y) | |
145 |
|
144 | |||
146 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
145 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
147 |
|
146 | |||
148 | ax = iplot.get_axes() |
|
147 | ax = iplot.get_axes() | |
149 |
|
148 | |||
150 | printLabels(ax, xlabel, ylabel, title) |
|
149 | printLabels(ax, xlabel, ylabel, title) | |
151 |
|
150 | |||
152 | set_linedata(ax, x, y, idline=0) |
|
151 | set_linedata(ax, x, y, idline=0) | |
153 |
|
152 | |||
154 | def addpline(ax, x, y, color, linestyle, lw): |
|
153 | def addpline(ax, x, y, color, linestyle, lw): | |
155 |
|
154 | |||
156 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
155 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) | |
157 |
|
156 | |||
158 |
|
157 | |||
159 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
158 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
160 | xlabel='', ylabel='', title='', ticksize = 9, |
|
159 | xlabel='', ylabel='', title='', ticksize = 9, | |
161 | colormap='jet',cblabel='', cbsize="5%", |
|
160 | colormap='jet',cblabel='', cbsize="5%", | |
162 | XAxisAsTime=False): |
|
161 | XAxisAsTime=False): | |
163 |
|
162 | |||
164 | matplotlib.pyplot.ioff() |
|
163 | matplotlib.pyplot.ioff() | |
165 |
|
164 | |||
166 | divider = make_axes_locatable(ax) |
|
165 | divider = make_axes_locatable(ax) | |
167 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
166 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
168 | fig = ax.get_figure() |
|
167 | fig = ax.get_figure() | |
169 | fig.add_axes(ax_cb) |
|
168 | fig.add_axes(ax_cb) | |
170 |
|
169 | |||
171 | ax.set_xlim([xmin,xmax]) |
|
170 | ax.set_xlim([xmin,xmax]) | |
172 | ax.set_ylim([ymin,ymax]) |
|
171 | ax.set_ylim([ymin,ymax]) | |
173 |
|
172 | |||
174 | printLabels(ax, xlabel, ylabel, title) |
|
173 | printLabels(ax, xlabel, ylabel, title) | |
175 |
|
174 | |||
176 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
175 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
177 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
176 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
178 | cb.set_label(cblabel) |
|
177 | cb.set_label(cblabel) | |
179 |
|
178 | |||
180 | # for tl in ax_cb.get_yticklabels(): |
|
179 | # for tl in ax_cb.get_yticklabels(): | |
181 | # tl.set_visible(True) |
|
180 | # tl.set_visible(True) | |
182 |
|
181 | |||
183 | for tick in ax.yaxis.get_major_ticks(): |
|
182 | for tick in ax.yaxis.get_major_ticks(): | |
184 | tick.label.set_fontsize(ticksize) |
|
183 | tick.label.set_fontsize(ticksize) | |
185 |
|
184 | |||
186 | for tick in ax.xaxis.get_major_ticks(): |
|
185 | for tick in ax.xaxis.get_major_ticks(): | |
187 | tick.label.set_fontsize(ticksize) |
|
186 | tick.label.set_fontsize(ticksize) | |
188 |
|
187 | |||
189 | for tick in cb.ax.get_yticklabels(): |
|
188 | for tick in cb.ax.get_yticklabels(): | |
190 | tick.set_fontsize(ticksize) |
|
189 | tick.set_fontsize(ticksize) | |
191 |
|
190 | |||
192 | ax_cb.yaxis.tick_right() |
|
191 | ax_cb.yaxis.tick_right() | |
193 |
|
192 | |||
194 | if '0.' in matplotlib.__version__[0:2]: |
|
193 | if '0.' in matplotlib.__version__[0:2]: | |
195 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
194 | print "The matplotlib version has to be updated to 1.1 or newer" | |
196 | return imesh |
|
195 | return imesh | |
197 |
|
196 | |||
198 | if '1.0.' in matplotlib.__version__[0:4]: |
|
197 | if '1.0.' in matplotlib.__version__[0:4]: | |
199 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
198 | print "The matplotlib version has to be updated to 1.1 or newer" | |
200 | return imesh |
|
199 | return imesh | |
201 |
|
200 | |||
202 | matplotlib.pyplot.tight_layout() |
|
201 | matplotlib.pyplot.tight_layout() | |
203 |
|
202 | |||
204 | if XAxisAsTime: |
|
203 | if XAxisAsTime: | |
205 |
|
204 | |||
206 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
205 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
207 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
206 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
208 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
207 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
209 |
|
208 | |||
210 | matplotlib.pyplot.ion() |
|
209 | matplotlib.pyplot.ion() | |
211 | return imesh |
|
210 | return imesh | |
212 |
|
211 | |||
213 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
212 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
214 |
|
213 | |||
215 | z = z.T |
|
214 | z = z.T | |
216 |
|
215 | |||
217 | ax = imesh.get_axes() |
|
216 | ax = imesh.get_axes() | |
218 |
|
217 | |||
219 | printLabels(ax, xlabel, ylabel, title) |
|
218 | printLabels(ax, xlabel, ylabel, title) | |
220 |
|
219 | |||
221 | imesh.set_array(z.ravel()) |
|
220 | imesh.set_array(z.ravel()) | |
222 |
|
221 | |||
223 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
222 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
224 |
|
223 | |||
225 | printLabels(ax, xlabel, ylabel, title) |
|
224 | printLabels(ax, xlabel, ylabel, title) | |
226 |
|
225 | |||
227 | ax.collections.remove(ax.collections[0]) |
|
226 | ax.collections.remove(ax.collections[0]) | |
228 |
|
227 | |||
229 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
228 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
230 |
|
229 | |||
231 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
230 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
232 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
231 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
233 | nxticks=4, nyticks=10, |
|
232 | nxticks=4, nyticks=10, | |
234 | grid=None): |
|
233 | grid=None): | |
235 |
|
234 | |||
236 | """ |
|
235 | """ | |
237 |
|
236 | |||
238 | Input: |
|
237 | Input: | |
239 | grid : None, 'both', 'x', 'y' |
|
238 | grid : None, 'both', 'x', 'y' | |
240 | """ |
|
239 | """ | |
241 |
|
240 | |||
242 | matplotlib.pyplot.ioff() |
|
241 | matplotlib.pyplot.ioff() | |
243 |
|
242 | |||
244 | lines = ax.plot(x.T, y) |
|
243 | lines = ax.plot(x.T, y) | |
245 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
244 | leg = ax.legend(lines, legendlabels, loc='upper right') | |
246 | leg.get_frame().set_alpha(0.5) |
|
245 | leg.get_frame().set_alpha(0.5) | |
247 | ax.set_xlim([xmin,xmax]) |
|
246 | ax.set_xlim([xmin,xmax]) | |
248 | ax.set_ylim([ymin,ymax]) |
|
247 | ax.set_ylim([ymin,ymax]) | |
249 | printLabels(ax, xlabel, ylabel, title) |
|
248 | printLabels(ax, xlabel, ylabel, title) | |
250 |
|
249 | |||
251 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
250 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
252 | ax.set_xticks(xtickspos) |
|
251 | ax.set_xticks(xtickspos) | |
253 |
|
252 | |||
254 | for tick in ax.get_xticklabels(): |
|
253 | for tick in ax.get_xticklabels(): | |
255 | tick.set_visible(xtick_visible) |
|
254 | tick.set_visible(xtick_visible) | |
256 |
|
255 | |||
257 | for tick in ax.xaxis.get_major_ticks(): |
|
256 | for tick in ax.xaxis.get_major_ticks(): | |
258 | tick.label.set_fontsize(ticksize) |
|
257 | tick.label.set_fontsize(ticksize) | |
259 |
|
258 | |||
260 | for tick in ax.get_yticklabels(): |
|
259 | for tick in ax.get_yticklabels(): | |
261 | tick.set_visible(ytick_visible) |
|
260 | tick.set_visible(ytick_visible) | |
262 |
|
261 | |||
263 | for tick in ax.yaxis.get_major_ticks(): |
|
262 | for tick in ax.yaxis.get_major_ticks(): | |
264 | tick.label.set_fontsize(ticksize) |
|
263 | tick.label.set_fontsize(ticksize) | |
265 |
|
264 | |||
266 | iplot = ax.lines[-1] |
|
265 | iplot = ax.lines[-1] | |
267 |
|
266 | |||
268 | if '0.' in matplotlib.__version__[0:2]: |
|
267 | if '0.' in matplotlib.__version__[0:2]: | |
269 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
268 | print "The matplotlib version has to be updated to 1.1 or newer" | |
270 | return iplot |
|
269 | return iplot | |
271 |
|
270 | |||
272 | if '1.0.' in matplotlib.__version__[0:4]: |
|
271 | if '1.0.' in matplotlib.__version__[0:4]: | |
273 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
272 | print "The matplotlib version has to be updated to 1.1 or newer" | |
274 | return iplot |
|
273 | return iplot | |
275 |
|
274 | |||
276 | if grid != None: |
|
275 | if grid != None: | |
277 | ax.grid(b=True, which='major', axis=grid) |
|
276 | ax.grid(b=True, which='major', axis=grid) | |
278 |
|
277 | |||
279 | matplotlib.pyplot.tight_layout() |
|
278 | matplotlib.pyplot.tight_layout() | |
280 |
|
279 | |||
281 | matplotlib.pyplot.ion() |
|
280 | matplotlib.pyplot.ion() | |
282 |
|
281 | |||
283 | return iplot |
|
282 | return iplot | |
284 |
|
283 | |||
285 |
|
284 | |||
286 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
285 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): | |
287 |
|
286 | |||
288 | ax = iplot.get_axes() |
|
287 | ax = iplot.get_axes() | |
289 |
|
288 | |||
290 | printLabels(ax, xlabel, ylabel, title) |
|
289 | printLabels(ax, xlabel, ylabel, title) | |
291 |
|
290 | |||
292 | for i in range(len(ax.lines)): |
|
291 | for i in range(len(ax.lines)): | |
293 | line = ax.lines[i] |
|
292 | line = ax.lines[i] | |
294 | line.set_data(x[i,:],y) |
|
293 | line.set_data(x[i,:],y) | |
295 |
|
294 | |||
296 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
295 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
297 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
296 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
298 | nxticks=4, nyticks=10, marker='^', markersize=8, linestyle="solid", |
|
297 | nxticks=4, nyticks=10, marker='^', markersize=8, linestyle="solid", | |
299 | grid=None, XAxisAsTime=False): |
|
298 | grid=None, XAxisAsTime=False): | |
300 |
|
299 | |||
301 | """ |
|
300 | """ | |
302 |
|
301 | |||
303 | Input: |
|
302 | Input: | |
304 | grid : None, 'both', 'x', 'y' |
|
303 | grid : None, 'both', 'x', 'y' | |
305 | """ |
|
304 | """ | |
306 |
|
305 | |||
307 | matplotlib.pyplot.ioff() |
|
306 | matplotlib.pyplot.ioff() | |
308 |
|
307 | |||
309 | lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
308 | lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) | |
310 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
309 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ | |
311 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
310 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) | |
312 |
|
311 | |||
313 | for label in leg.get_texts(): label.set_fontsize(9) |
|
312 | for label in leg.get_texts(): label.set_fontsize(9) | |
314 |
|
313 | |||
315 | ax.set_xlim([xmin,xmax]) |
|
314 | ax.set_xlim([xmin,xmax]) | |
316 | ax.set_ylim([ymin,ymax]) |
|
315 | ax.set_ylim([ymin,ymax]) | |
317 | printLabels(ax, xlabel, ylabel, title) |
|
316 | printLabels(ax, xlabel, ylabel, title) | |
318 |
|
317 | |||
319 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
318 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
320 | # ax.set_xticks(xtickspos) |
|
319 | # ax.set_xticks(xtickspos) | |
321 |
|
320 | |||
322 | for tick in ax.get_xticklabels(): |
|
321 | for tick in ax.get_xticklabels(): | |
323 | tick.set_visible(xtick_visible) |
|
322 | tick.set_visible(xtick_visible) | |
324 |
|
323 | |||
325 | for tick in ax.xaxis.get_major_ticks(): |
|
324 | for tick in ax.xaxis.get_major_ticks(): | |
326 | tick.label.set_fontsize(ticksize) |
|
325 | tick.label.set_fontsize(ticksize) | |
327 |
|
326 | |||
328 | for tick in ax.get_yticklabels(): |
|
327 | for tick in ax.get_yticklabels(): | |
329 | tick.set_visible(ytick_visible) |
|
328 | tick.set_visible(ytick_visible) | |
330 |
|
329 | |||
331 | for tick in ax.yaxis.get_major_ticks(): |
|
330 | for tick in ax.yaxis.get_major_ticks(): | |
332 | tick.label.set_fontsize(ticksize) |
|
331 | tick.label.set_fontsize(ticksize) | |
333 |
|
332 | |||
334 | iplot = ax.lines[-1] |
|
333 | iplot = ax.lines[-1] | |
335 |
|
334 | |||
336 | if '0.' in matplotlib.__version__[0:2]: |
|
335 | if '0.' in matplotlib.__version__[0:2]: | |
337 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
336 | print "The matplotlib version has to be updated to 1.1 or newer" | |
338 | return iplot |
|
337 | return iplot | |
339 |
|
338 | |||
340 | if '1.0.' in matplotlib.__version__[0:4]: |
|
339 | if '1.0.' in matplotlib.__version__[0:4]: | |
341 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
340 | print "The matplotlib version has to be updated to 1.1 or newer" | |
342 | return iplot |
|
341 | return iplot | |
343 |
|
342 | |||
344 | if grid != None: |
|
343 | if grid != None: | |
345 | ax.grid(b=True, which='major', axis=grid) |
|
344 | ax.grid(b=True, which='major', axis=grid) | |
346 |
|
345 | |||
347 | matplotlib.pyplot.tight_layout() |
|
346 | matplotlib.pyplot.tight_layout() | |
348 |
|
347 | |||
349 | if XAxisAsTime: |
|
348 | if XAxisAsTime: | |
350 |
|
349 | |||
351 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
350 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
352 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
351 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
353 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
352 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
354 |
|
353 | |||
355 | matplotlib.pyplot.ion() |
|
354 | matplotlib.pyplot.ion() | |
356 |
|
355 | |||
357 | return iplot |
|
356 | return iplot | |
358 |
|
357 | |||
359 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
358 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): | |
360 |
|
359 | |||
361 | ax = iplot.get_axes() |
|
360 | ax = iplot.get_axes() | |
362 |
|
361 | |||
363 | printLabels(ax, xlabel, ylabel, title) |
|
362 | printLabels(ax, xlabel, ylabel, title) | |
364 |
|
363 | |||
365 | for i in range(len(ax.lines)): |
|
364 | for i in range(len(ax.lines)): | |
366 | line = ax.lines[i] |
|
365 | line = ax.lines[i] | |
367 | line.set_data(x,y[i,:]) |
|
366 | line.set_data(x,y[i,:]) | |
368 |
|
367 | |||
369 | def draw(fig): |
|
368 | def draw(fig): | |
370 |
|
369 | |||
371 | if type(fig) == 'int': |
|
370 | if type(fig) == 'int': | |
372 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
371 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
373 |
|
372 | |||
374 | fig.canvas.draw() No newline at end of file |
|
373 | fig.canvas.draw() |
@@ -1,2562 +1,2573 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ |
|
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, 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 time, datetime |
|
12 | import time, datetime | |
13 |
|
13 | |||
14 | from jrodata import * |
|
14 | from jrodata import * | |
15 | from jroheaderIO import * |
|
15 | from jroheaderIO import * | |
16 | from jroprocessing import * |
|
16 | from jroprocessing import * | |
17 |
|
17 | |||
18 | LOCALTIME = -18000 |
|
18 | LOCALTIME = -18000 | |
19 |
|
19 | |||
20 | def isNumber(str): |
|
20 | def isNumber(str): | |
21 | """ |
|
21 | """ | |
22 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
22 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
23 |
|
23 | |||
24 | Excepciones: |
|
24 | Excepciones: | |
25 | Si un determinado string no puede ser convertido a numero |
|
25 | Si un determinado string no puede ser convertido a numero | |
26 | Input: |
|
26 | Input: | |
27 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
27 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
28 |
|
28 | |||
29 | Return: |
|
29 | Return: | |
30 | True : si el string es uno numerico |
|
30 | True : si el string es uno numerico | |
31 | False : no es un string numerico |
|
31 | False : no es un string numerico | |
32 | """ |
|
32 | """ | |
33 | try: |
|
33 | try: | |
34 | float( str ) |
|
34 | float( str ) | |
35 | return True |
|
35 | return True | |
36 | except: |
|
36 | except: | |
37 | return False |
|
37 | return False | |
38 |
|
38 | |||
39 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
39 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
40 | """ |
|
40 | """ | |
41 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
41 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
42 |
|
42 | |||
43 | Inputs: |
|
43 | Inputs: | |
44 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
44 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
45 |
|
45 | |||
46 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
46 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
47 | segundos contados desde 01/01/1970. |
|
47 | segundos contados desde 01/01/1970. | |
48 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
48 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
49 | segundos contados desde 01/01/1970. |
|
49 | segundos contados desde 01/01/1970. | |
50 |
|
50 | |||
51 | Return: |
|
51 | Return: | |
52 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
52 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
53 | fecha especificado, de lo contrario retorna False. |
|
53 | fecha especificado, de lo contrario retorna False. | |
54 |
|
54 | |||
55 | Excepciones: |
|
55 | Excepciones: | |
56 | Si el archivo no existe o no puede ser abierto |
|
56 | Si el archivo no existe o no puede ser abierto | |
57 | Si la cabecera no puede ser leida. |
|
57 | Si la cabecera no puede ser leida. | |
58 |
|
58 | |||
59 | """ |
|
59 | """ | |
60 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
60 | basicHeaderObj = BasicHeader(LOCALTIME) | |
61 |
|
61 | |||
62 | try: |
|
62 | try: | |
63 | fp = open(filename,'rb') |
|
63 | fp = open(filename,'rb') | |
64 | except: |
|
64 | except: | |
65 | raise IOError, "The file %s can't be opened" %(filename) |
|
65 | raise IOError, "The file %s can't be opened" %(filename) | |
66 |
|
66 | |||
67 | sts = basicHeaderObj.read(fp) |
|
67 | sts = basicHeaderObj.read(fp) | |
68 | fp.close() |
|
68 | fp.close() | |
69 |
|
69 | |||
70 | if not(sts): |
|
70 | if not(sts): | |
71 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
71 | print "Skipping the file %s because it has not a valid header" %(filename) | |
72 | return 0 |
|
72 | return 0 | |
73 |
|
73 | |||
74 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
74 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
75 | return 0 |
|
75 | return 0 | |
76 |
|
76 | |||
77 | return 1 |
|
77 | return 1 | |
78 |
|
78 | |||
79 | def isFileinThisTime(filename, startTime, endTime): |
|
79 | def isFileinThisTime(filename, startTime, endTime): | |
80 | """ |
|
80 | """ | |
81 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
81 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
82 |
|
82 | |||
83 | Inputs: |
|
83 | Inputs: | |
84 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
84 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
85 |
|
85 | |||
86 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
86 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
87 |
|
87 | |||
88 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
88 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
89 |
|
89 | |||
90 | Return: |
|
90 | Return: | |
91 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
91 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
92 | fecha especificado, de lo contrario retorna False. |
|
92 | fecha especificado, de lo contrario retorna False. | |
93 |
|
93 | |||
94 | Excepciones: |
|
94 | Excepciones: | |
95 | Si el archivo no existe o no puede ser abierto |
|
95 | Si el archivo no existe o no puede ser abierto | |
96 | Si la cabecera no puede ser leida. |
|
96 | Si la cabecera no puede ser leida. | |
97 |
|
97 | |||
98 | """ |
|
98 | """ | |
99 |
|
99 | |||
100 |
|
100 | |||
101 | try: |
|
101 | try: | |
102 | fp = open(filename,'rb') |
|
102 | fp = open(filename,'rb') | |
103 | except: |
|
103 | except: | |
104 | raise IOError, "The file %s can't be opened" %(filename) |
|
104 | raise IOError, "The file %s can't be opened" %(filename) | |
105 |
|
105 | |||
106 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
106 | basicHeaderObj = BasicHeader(LOCALTIME) | |
107 | sts = basicHeaderObj.read(fp) |
|
107 | sts = basicHeaderObj.read(fp) | |
108 | fp.close() |
|
108 | fp.close() | |
109 |
|
109 | |||
110 | thisTime = basicHeaderObj.datatime.time() |
|
110 | thisTime = basicHeaderObj.datatime.time() | |
111 |
|
111 | |||
112 | if not(sts): |
|
112 | if not(sts): | |
113 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
113 | print "Skipping the file %s because it has not a valid header" %(filename) | |
114 | return 0 |
|
114 | return 0 | |
115 |
|
115 | |||
116 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
116 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |
117 | return 0 |
|
117 | return 0 | |
118 |
|
118 | |||
119 | return 1 |
|
119 | return 1 | |
120 |
|
120 | |||
121 | def getlastFileFromPath(path, ext): |
|
121 | def getlastFileFromPath(path, ext): | |
122 | """ |
|
122 | """ | |
123 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
123 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
124 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
124 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
125 |
|
125 | |||
126 | Input: |
|
126 | Input: | |
127 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
127 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
128 | ext : extension de los files contenidos en una carpeta |
|
128 | ext : extension de los files contenidos en una carpeta | |
129 |
|
129 | |||
130 | Return: |
|
130 | Return: | |
131 | El ultimo file de una determinada carpeta, no se considera el path. |
|
131 | El ultimo file de una determinada carpeta, no se considera el path. | |
132 | """ |
|
132 | """ | |
133 | validFilelist = [] |
|
133 | validFilelist = [] | |
134 | fileList = os.listdir(path) |
|
134 | fileList = os.listdir(path) | |
135 |
|
135 | |||
136 | # 0 1234 567 89A BCDE |
|
136 | # 0 1234 567 89A BCDE | |
137 | # H YYYY DDD SSS .ext |
|
137 | # H YYYY DDD SSS .ext | |
138 |
|
138 | |||
139 | for file in fileList: |
|
139 | for file in fileList: | |
140 | try: |
|
140 | try: | |
141 | year = int(file[1:5]) |
|
141 | year = int(file[1:5]) | |
142 | doy = int(file[5:8]) |
|
142 | doy = int(file[5:8]) | |
143 |
|
143 | |||
144 |
|
144 | |||
145 | except: |
|
145 | except: | |
146 | continue |
|
146 | continue | |
147 |
|
147 | |||
148 | if (os.path.splitext(file)[-1].lower() != ext.lower()): |
|
148 | if (os.path.splitext(file)[-1].lower() != ext.lower()): | |
149 | continue |
|
149 | continue | |
150 |
|
150 | |||
151 | validFilelist.append(file) |
|
151 | validFilelist.append(file) | |
152 |
|
152 | |||
153 | if validFilelist: |
|
153 | if validFilelist: | |
154 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
154 | validFilelist = sorted( validFilelist, key=str.lower ) | |
155 | return validFilelist[-1] |
|
155 | return validFilelist[-1] | |
156 |
|
156 | |||
157 | return None |
|
157 | return None | |
158 |
|
158 | |||
159 | def checkForRealPath(path, year, doy, set, ext): |
|
159 | def checkForRealPath(path, year, doy, set, ext): | |
160 | """ |
|
160 | """ | |
161 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
161 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
162 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
162 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
163 | el path exacto de un determinado file. |
|
163 | el path exacto de un determinado file. | |
164 |
|
164 | |||
165 | Example : |
|
165 | Example : | |
166 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
166 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
167 |
|
167 | |||
168 | Entonces la funcion prueba con las siguientes combinaciones |
|
168 | Entonces la funcion prueba con las siguientes combinaciones | |
169 | .../.../y2009307367.ext |
|
169 | .../.../y2009307367.ext | |
170 | .../.../Y2009307367.ext |
|
170 | .../.../Y2009307367.ext | |
171 | .../.../x2009307/y2009307367.ext |
|
171 | .../.../x2009307/y2009307367.ext | |
172 | .../.../x2009307/Y2009307367.ext |
|
172 | .../.../x2009307/Y2009307367.ext | |
173 | .../.../X2009307/y2009307367.ext |
|
173 | .../.../X2009307/y2009307367.ext | |
174 | .../.../X2009307/Y2009307367.ext |
|
174 | .../.../X2009307/Y2009307367.ext | |
175 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
175 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
176 |
|
176 | |||
177 | Return: |
|
177 | Return: | |
178 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
178 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
179 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
179 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
180 | para el filename |
|
180 | para el filename | |
181 | """ |
|
181 | """ | |
182 | fullfilename = None |
|
182 | fullfilename = None | |
183 | find_flag = False |
|
183 | find_flag = False | |
184 | filename = None |
|
184 | filename = None | |
185 |
|
185 | |||
186 | prefixDirList = [None,'d','D'] |
|
186 | prefixDirList = [None,'d','D'] | |
187 | if ext.lower() == ".r": #voltage |
|
187 | if ext.lower() == ".r": #voltage | |
188 | prefixFileList = ['d','D'] |
|
188 | prefixFileList = ['d','D'] | |
189 | elif ext.lower() == ".pdata": #spectra |
|
189 | elif ext.lower() == ".pdata": #spectra | |
190 | prefixFileList = ['p','P'] |
|
190 | prefixFileList = ['p','P'] | |
191 | else: |
|
191 | else: | |
192 | return None, filename |
|
192 | return None, filename | |
193 |
|
193 | |||
194 | #barrido por las combinaciones posibles |
|
194 | #barrido por las combinaciones posibles | |
195 | for prefixDir in prefixDirList: |
|
195 | for prefixDir in prefixDirList: | |
196 | thispath = path |
|
196 | thispath = path | |
197 | if prefixDir != None: |
|
197 | if prefixDir != None: | |
198 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
198 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
199 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) |
|
199 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) | |
200 |
|
200 | |||
201 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" |
|
201 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" | |
202 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
202 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
203 | fullfilename = os.path.join( thispath, filename ) #formo el path completo |
|
203 | fullfilename = os.path.join( thispath, filename ) #formo el path completo | |
204 |
|
204 | |||
205 | if os.path.exists( fullfilename ): #verifico que exista |
|
205 | if os.path.exists( fullfilename ): #verifico que exista | |
206 | find_flag = True |
|
206 | find_flag = True | |
207 | break |
|
207 | break | |
208 | if find_flag: |
|
208 | if find_flag: | |
209 | break |
|
209 | break | |
210 |
|
210 | |||
211 | if not(find_flag): |
|
211 | if not(find_flag): | |
212 | return None, filename |
|
212 | return None, filename | |
213 |
|
213 | |||
214 | return fullfilename, filename |
|
214 | return fullfilename, filename | |
215 |
|
215 | |||
216 | class JRODataIO: |
|
216 | class JRODataIO: | |
217 |
|
217 | |||
218 | c = 3E8 |
|
218 | c = 3E8 | |
219 |
|
219 | |||
220 | isConfig = False |
|
220 | isConfig = False | |
221 |
|
221 | |||
222 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
222 | basicHeaderObj = BasicHeader(LOCALTIME) | |
223 |
|
223 | |||
224 | systemHeaderObj = SystemHeader() |
|
224 | systemHeaderObj = SystemHeader() | |
225 |
|
225 | |||
226 | radarControllerHeaderObj = RadarControllerHeader() |
|
226 | radarControllerHeaderObj = RadarControllerHeader() | |
227 |
|
227 | |||
228 | processingHeaderObj = ProcessingHeader() |
|
228 | processingHeaderObj = ProcessingHeader() | |
229 |
|
229 | |||
230 | online = 0 |
|
230 | online = 0 | |
231 |
|
231 | |||
232 | dtype = None |
|
232 | dtype = None | |
233 |
|
233 | |||
234 | pathList = [] |
|
234 | pathList = [] | |
235 |
|
235 | |||
236 | filenameList = [] |
|
236 | filenameList = [] | |
237 |
|
237 | |||
238 | filename = None |
|
238 | filename = None | |
239 |
|
239 | |||
240 | ext = None |
|
240 | ext = None | |
241 |
|
241 | |||
242 | flagIsNewFile = 1 |
|
242 | flagIsNewFile = 1 | |
243 |
|
243 | |||
244 | flagTimeBlock = 0 |
|
244 | flagTimeBlock = 0 | |
245 |
|
245 | |||
246 | flagIsNewBlock = 0 |
|
246 | flagIsNewBlock = 0 | |
247 |
|
247 | |||
248 | fp = None |
|
248 | fp = None | |
249 |
|
249 | |||
250 | firstHeaderSize = 0 |
|
250 | firstHeaderSize = 0 | |
251 |
|
251 | |||
252 | basicHeaderSize = 24 |
|
252 | basicHeaderSize = 24 | |
253 |
|
253 | |||
254 | versionFile = 1103 |
|
254 | versionFile = 1103 | |
255 |
|
255 | |||
256 | fileSize = None |
|
256 | fileSize = None | |
257 |
|
257 | |||
258 | ippSeconds = None |
|
258 | ippSeconds = None | |
259 |
|
259 | |||
260 | fileSizeByHeader = None |
|
260 | fileSizeByHeader = None | |
261 |
|
261 | |||
262 | fileIndex = None |
|
262 | fileIndex = None | |
263 |
|
263 | |||
264 | profileIndex = None |
|
264 | profileIndex = None | |
265 |
|
265 | |||
266 | blockIndex = None |
|
266 | blockIndex = None | |
267 |
|
267 | |||
268 | nTotalBlocks = None |
|
268 | nTotalBlocks = None | |
269 |
|
269 | |||
270 | maxTimeStep = 30 |
|
270 | maxTimeStep = 30 | |
271 |
|
271 | |||
272 | lastUTTime = None |
|
272 | lastUTTime = None | |
273 |
|
273 | |||
274 | datablock = None |
|
274 | datablock = None | |
275 |
|
275 | |||
276 | dataOut = None |
|
276 | dataOut = None | |
277 |
|
277 | |||
278 | blocksize = None |
|
278 | blocksize = None | |
279 |
|
279 | |||
280 | def __init__(self): |
|
280 | def __init__(self): | |
281 |
|
281 | |||
282 | raise ValueError, "Not implemented" |
|
282 | raise ValueError, "Not implemented" | |
283 |
|
283 | |||
284 | def run(self): |
|
284 | def run(self): | |
285 |
|
285 | |||
286 | raise ValueError, "Not implemented" |
|
286 | raise ValueError, "Not implemented" | |
287 |
|
287 | |||
288 | def getOutput(self): |
|
288 | def getOutput(self): | |
289 |
|
289 | |||
290 | return self.dataOut |
|
290 | return self.dataOut | |
291 |
|
291 | |||
292 | class JRODataReader(JRODataIO, ProcessingUnit): |
|
292 | class JRODataReader(JRODataIO, ProcessingUnit): | |
293 |
|
293 | |||
294 | nReadBlocks = 0 |
|
294 | nReadBlocks = 0 | |
295 |
|
295 | |||
296 | delay = 10 #number of seconds waiting a new file |
|
296 | delay = 10 #number of seconds waiting a new file | |
297 |
|
297 | |||
298 | nTries = 3 #quantity tries |
|
298 | nTries = 3 #quantity tries | |
299 |
|
299 | |||
300 | nFiles = 3 #number of files for searching |
|
300 | nFiles = 3 #number of files for searching | |
301 |
|
301 | |||
302 | flagNoMoreFiles = 0 |
|
302 | flagNoMoreFiles = 0 | |
303 |
|
303 | |||
304 | def __init__(self): |
|
304 | def __init__(self): | |
305 |
|
305 | |||
306 | """ |
|
306 | """ | |
307 |
|
307 | |||
308 | """ |
|
308 | """ | |
309 |
|
309 | |||
310 | raise ValueError, "This method has not been implemented" |
|
310 | raise ValueError, "This method has not been implemented" | |
311 |
|
311 | |||
312 |
|
312 | |||
313 | def createObjByDefault(self): |
|
313 | def createObjByDefault(self): | |
314 | """ |
|
314 | """ | |
315 |
|
315 | |||
316 | """ |
|
316 | """ | |
317 | raise ValueError, "This method has not been implemented" |
|
317 | raise ValueError, "This method has not been implemented" | |
318 |
|
318 | |||
319 | def getBlockDimension(self): |
|
319 | def getBlockDimension(self): | |
320 |
|
320 | |||
321 | raise ValueError, "No implemented" |
|
321 | raise ValueError, "No implemented" | |
322 |
|
322 | |||
323 | def __searchFilesOffLine(self, |
|
323 | def __searchFilesOffLine(self, | |
324 | path, |
|
324 | path, | |
325 | startDate, |
|
325 | startDate, | |
326 | endDate, |
|
326 | endDate, | |
327 | startTime=datetime.time(0,0,0), |
|
327 | startTime=datetime.time(0,0,0), | |
328 | endTime=datetime.time(23,59,59), |
|
328 | endTime=datetime.time(23,59,59), | |
329 | set=None, |
|
329 | set=None, | |
330 | expLabel='', |
|
330 | expLabel='', | |
331 | ext='.r', |
|
331 | ext='.r', | |
332 | walk=True): |
|
332 | walk=True): | |
333 |
|
333 | |||
334 | pathList = [] |
|
334 | pathList = [] | |
335 |
|
335 | |||
336 | if not walk: |
|
336 | if not walk: | |
337 | pathList.append(path) |
|
337 | pathList.append(path) | |
338 |
|
338 | |||
339 | else: |
|
339 | else: | |
340 | dirList = [] |
|
340 | dirList = [] | |
341 | for thisPath in os.listdir(path): |
|
341 | for thisPath in os.listdir(path): | |
342 | if os.path.isdir(os.path.join(path,thisPath)): |
|
342 | if os.path.isdir(os.path.join(path,thisPath)): | |
343 | dirList.append(thisPath) |
|
343 | dirList.append(thisPath) | |
344 |
|
344 | |||
345 | if not(dirList): |
|
345 | if not(dirList): | |
346 | return None, None |
|
346 | return None, None | |
347 |
|
347 | |||
348 | thisDate = startDate |
|
348 | thisDate = startDate | |
349 |
|
349 | |||
350 | while(thisDate <= endDate): |
|
350 | while(thisDate <= endDate): | |
351 | year = thisDate.timetuple().tm_year |
|
351 | year = thisDate.timetuple().tm_year | |
352 | doy = thisDate.timetuple().tm_yday |
|
352 | doy = thisDate.timetuple().tm_yday | |
353 |
|
353 | |||
354 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
354 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
355 | if len(match) == 0: |
|
355 | if len(match) == 0: | |
356 | thisDate += datetime.timedelta(1) |
|
356 | thisDate += datetime.timedelta(1) | |
357 | continue |
|
357 | continue | |
358 |
|
358 | |||
359 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
359 | pathList.append(os.path.join(path,match[0],expLabel)) | |
360 | thisDate += datetime.timedelta(1) |
|
360 | thisDate += datetime.timedelta(1) | |
361 |
|
361 | |||
362 | if pathList == []: |
|
362 | if pathList == []: | |
363 |
print "Any folder found |
|
363 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) | |
364 | return None, None |
|
364 | return None, None | |
365 |
|
365 | |||
366 |
print "%d folder(s) found |
|
366 | print "%d folder(s) was(were) found for the date range: %s-%s" %(len(pathList), startDate, endDate) | |
367 |
|
367 | |||
368 | filenameList = [] |
|
368 | filenameList = [] | |
369 | for thisPath in pathList: |
|
369 | for thisPath in pathList: | |
370 |
|
370 | |||
371 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
371 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
372 | fileList.sort() |
|
372 | fileList.sort() | |
373 |
|
373 | |||
374 | for file in fileList: |
|
374 | for file in fileList: | |
375 |
|
375 | |||
376 | filename = os.path.join(thisPath,file) |
|
376 | filename = os.path.join(thisPath,file) | |
377 |
|
377 | |||
378 | if isFileinThisTime(filename, startTime, endTime): |
|
378 | if isFileinThisTime(filename, startTime, endTime): | |
379 | filenameList.append(filename) |
|
379 | filenameList.append(filename) | |
380 |
|
380 | |||
381 | if not(filenameList): |
|
381 | if not(filenameList): | |
382 |
print "Any file found |
|
382 | print "Any file was found for the time range %s - %s" %(startTime, endTime) | |
383 | return None, None |
|
383 | return None, None | |
|
384 | ||||
|
385 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) | |||
384 |
|
386 | |||
385 | self.filenameList = filenameList |
|
387 | self.filenameList = filenameList | |
386 |
|
388 | |||
387 | return pathList, filenameList |
|
389 | return pathList, filenameList | |
388 |
|
390 | |||
389 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True): |
|
391 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True): | |
390 |
|
392 | |||
391 | """ |
|
393 | """ | |
392 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
394 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
393 | devuelve el archivo encontrado ademas de otros datos. |
|
395 | devuelve el archivo encontrado ademas de otros datos. | |
394 |
|
396 | |||
395 | Input: |
|
397 | Input: | |
396 | path : carpeta donde estan contenidos los files que contiene data |
|
398 | path : carpeta donde estan contenidos los files que contiene data | |
397 |
|
399 | |||
398 | expLabel : Nombre del subexperimento (subfolder) |
|
400 | expLabel : Nombre del subexperimento (subfolder) | |
399 |
|
401 | |||
400 | ext : extension de los files |
|
402 | ext : extension de los files | |
401 |
|
403 | |||
402 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
404 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) | |
403 |
|
405 | |||
404 | Return: |
|
406 | Return: | |
405 | directory : eL directorio donde esta el file encontrado |
|
407 | directory : eL directorio donde esta el file encontrado | |
406 | filename : el ultimo file de una determinada carpeta |
|
408 | filename : el ultimo file de una determinada carpeta | |
407 | year : el anho |
|
409 | year : el anho | |
408 | doy : el numero de dia del anho |
|
410 | doy : el numero de dia del anho | |
409 | set : el set del archivo |
|
411 | set : el set del archivo | |
410 |
|
412 | |||
411 |
|
413 | |||
412 | """ |
|
414 | """ | |
413 | dirList = [] |
|
415 | dirList = [] | |
414 |
|
416 | |||
415 | if walk: |
|
417 | if walk: | |
416 |
|
418 | |||
417 | #Filtra solo los directorios |
|
419 | #Filtra solo los directorios | |
418 | for thisPath in os.listdir(path): |
|
420 | for thisPath in os.listdir(path): | |
419 | if os.path.isdir(os.path.join(path, thisPath)): |
|
421 | if os.path.isdir(os.path.join(path, thisPath)): | |
420 | dirList.append(thisPath) |
|
422 | dirList.append(thisPath) | |
421 |
|
423 | |||
422 | if not(dirList): |
|
424 | if not(dirList): | |
423 | return None, None, None, None, None |
|
425 | return None, None, None, None, None | |
424 |
|
426 | |||
425 | dirList = sorted( dirList, key=str.lower ) |
|
427 | dirList = sorted( dirList, key=str.lower ) | |
426 |
|
428 | |||
427 | doypath = dirList[-1] |
|
429 | doypath = dirList[-1] | |
428 | fullpath = os.path.join(path, doypath, expLabel) |
|
430 | fullpath = os.path.join(path, doypath, expLabel) | |
429 |
|
431 | |||
430 | else: |
|
432 | else: | |
431 | fullpath = path |
|
433 | fullpath = path | |
432 |
|
434 | |||
433 | filename = getlastFileFromPath(fullpath, ext) |
|
435 | filename = getlastFileFromPath(fullpath, ext) | |
434 |
|
436 | |||
435 | if not(filename): |
|
437 | if not(filename): | |
436 | return None, None, None, None, None |
|
438 | return None, None, None, None, None | |
437 |
|
439 | |||
438 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
440 | if not(self.__verifyFile(os.path.join(fullpath, filename))): | |
439 | return None, None, None, None, None |
|
441 | return None, None, None, None, None | |
440 |
|
442 | |||
441 | year = int( filename[1:5] ) |
|
443 | year = int( filename[1:5] ) | |
442 | doy = int( filename[5:8] ) |
|
444 | doy = int( filename[5:8] ) | |
443 | set = int( filename[8:11] ) |
|
445 | set = int( filename[8:11] ) | |
444 |
|
446 | |||
445 | return fullpath, filename, year, doy, set |
|
447 | return fullpath, filename, year, doy, set | |
446 |
|
448 | |||
447 |
|
449 | |||
448 |
|
450 | |||
449 | def __setNextFileOffline(self): |
|
451 | def __setNextFileOffline(self): | |
450 |
|
452 | |||
451 | idFile = self.fileIndex |
|
453 | idFile = self.fileIndex | |
452 |
|
454 | |||
453 | while (True): |
|
455 | while (True): | |
454 | idFile += 1 |
|
456 | idFile += 1 | |
455 | if not(idFile < len(self.filenameList)): |
|
457 | if not(idFile < len(self.filenameList)): | |
456 | self.flagNoMoreFiles = 1 |
|
458 | self.flagNoMoreFiles = 1 | |
457 | print "No more Files" |
|
459 | print "No more Files" | |
458 | return 0 |
|
460 | return 0 | |
459 |
|
461 | |||
460 | filename = self.filenameList[idFile] |
|
462 | filename = self.filenameList[idFile] | |
461 |
|
463 | |||
462 | if not(self.__verifyFile(filename)): |
|
464 | if not(self.__verifyFile(filename)): | |
463 | continue |
|
465 | continue | |
464 |
|
466 | |||
465 | fileSize = os.path.getsize(filename) |
|
467 | fileSize = os.path.getsize(filename) | |
466 | fp = open(filename,'rb') |
|
468 | fp = open(filename,'rb') | |
467 | break |
|
469 | break | |
468 |
|
470 | |||
469 | self.flagIsNewFile = 1 |
|
471 | self.flagIsNewFile = 1 | |
470 | self.fileIndex = idFile |
|
472 | self.fileIndex = idFile | |
471 | self.filename = filename |
|
473 | self.filename = filename | |
472 | self.fileSize = fileSize |
|
474 | self.fileSize = fileSize | |
473 | self.fp = fp |
|
475 | self.fp = fp | |
474 |
|
476 | |||
475 | print "Setting the file: %s"%self.filename |
|
477 | print "Setting the file: %s"%self.filename | |
476 |
|
478 | |||
477 | return 1 |
|
479 | return 1 | |
478 |
|
480 | |||
479 | def __setNextFileOnline(self): |
|
481 | def __setNextFileOnline(self): | |
480 | """ |
|
482 | """ | |
481 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
483 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
482 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
484 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
483 | siguientes. |
|
485 | siguientes. | |
484 |
|
486 | |||
485 | Affected: |
|
487 | Affected: | |
486 | self.flagIsNewFile |
|
488 | self.flagIsNewFile | |
487 | self.filename |
|
489 | self.filename | |
488 | self.fileSize |
|
490 | self.fileSize | |
489 | self.fp |
|
491 | self.fp | |
490 | self.set |
|
492 | self.set | |
491 | self.flagNoMoreFiles |
|
493 | self.flagNoMoreFiles | |
492 |
|
494 | |||
493 | Return: |
|
495 | Return: | |
494 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
496 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
495 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
497 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
496 |
|
498 | |||
497 | Excepciones: |
|
499 | Excepciones: | |
498 | Si un determinado file no puede ser abierto |
|
500 | Si un determinado file no puede ser abierto | |
499 | """ |
|
501 | """ | |
500 | nFiles = 0 |
|
502 | nFiles = 0 | |
501 | fileOk_flag = False |
|
503 | fileOk_flag = False | |
502 | firstTime_flag = True |
|
504 | firstTime_flag = True | |
503 |
|
505 | |||
504 | self.set += 1 |
|
506 | self.set += 1 | |
505 |
|
507 | |||
506 | #busca el 1er file disponible |
|
508 | #busca el 1er file disponible | |
507 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
509 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
508 | if fullfilename: |
|
510 | if fullfilename: | |
509 | if self.__verifyFile(fullfilename, False): |
|
511 | if self.__verifyFile(fullfilename, False): | |
510 | fileOk_flag = True |
|
512 | fileOk_flag = True | |
511 |
|
513 | |||
512 | #si no encuentra un file entonces espera y vuelve a buscar |
|
514 | #si no encuentra un file entonces espera y vuelve a buscar | |
513 | if not(fileOk_flag): |
|
515 | if not(fileOk_flag): | |
514 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
516 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles | |
515 |
|
517 | |||
516 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
518 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
517 | tries = self.nTries |
|
519 | tries = self.nTries | |
518 | else: |
|
520 | else: | |
519 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
521 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
520 |
|
522 | |||
521 | for nTries in range( tries ): |
|
523 | for nTries in range( tries ): | |
522 | if firstTime_flag: |
|
524 | if firstTime_flag: | |
523 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
525 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) | |
524 | time.sleep( self.delay ) |
|
526 | time.sleep( self.delay ) | |
525 | else: |
|
527 | else: | |
526 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
528 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
527 |
|
529 | |||
528 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
530 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
529 | if fullfilename: |
|
531 | if fullfilename: | |
530 | if self.__verifyFile(fullfilename): |
|
532 | if self.__verifyFile(fullfilename): | |
531 | fileOk_flag = True |
|
533 | fileOk_flag = True | |
532 | break |
|
534 | break | |
533 |
|
535 | |||
534 | if fileOk_flag: |
|
536 | if fileOk_flag: | |
535 | break |
|
537 | break | |
536 |
|
538 | |||
537 | firstTime_flag = False |
|
539 | firstTime_flag = False | |
538 |
|
540 | |||
539 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
541 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename | |
540 | self.set += 1 |
|
542 | self.set += 1 | |
541 |
|
543 | |||
542 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
544 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
543 | self.set = 0 |
|
545 | self.set = 0 | |
544 | self.doy += 1 |
|
546 | self.doy += 1 | |
545 |
|
547 | |||
546 | if fileOk_flag: |
|
548 | if fileOk_flag: | |
547 | self.fileSize = os.path.getsize( fullfilename ) |
|
549 | self.fileSize = os.path.getsize( fullfilename ) | |
548 | self.filename = fullfilename |
|
550 | self.filename = fullfilename | |
549 | self.flagIsNewFile = 1 |
|
551 | self.flagIsNewFile = 1 | |
550 | if self.fp != None: self.fp.close() |
|
552 | if self.fp != None: self.fp.close() | |
551 | self.fp = open(fullfilename, 'rb') |
|
553 | self.fp = open(fullfilename, 'rb') | |
552 | self.flagNoMoreFiles = 0 |
|
554 | self.flagNoMoreFiles = 0 | |
553 | print 'Setting the file: %s' % fullfilename |
|
555 | print 'Setting the file: %s' % fullfilename | |
554 | else: |
|
556 | else: | |
555 | self.fileSize = 0 |
|
557 | self.fileSize = 0 | |
556 | self.filename = None |
|
558 | self.filename = None | |
557 | self.flagIsNewFile = 0 |
|
559 | self.flagIsNewFile = 0 | |
558 | self.fp = None |
|
560 | self.fp = None | |
559 | self.flagNoMoreFiles = 1 |
|
561 | self.flagNoMoreFiles = 1 | |
560 | print 'No more Files' |
|
562 | print 'No more Files' | |
561 |
|
563 | |||
562 | return fileOk_flag |
|
564 | return fileOk_flag | |
563 |
|
565 | |||
564 |
|
566 | |||
565 | def setNextFile(self): |
|
567 | def setNextFile(self): | |
566 | if self.fp != None: |
|
568 | if self.fp != None: | |
567 | self.fp.close() |
|
569 | self.fp.close() | |
568 |
|
570 | |||
569 | if self.online: |
|
571 | if self.online: | |
570 | newFile = self.__setNextFileOnline() |
|
572 | newFile = self.__setNextFileOnline() | |
571 | else: |
|
573 | else: | |
572 | newFile = self.__setNextFileOffline() |
|
574 | newFile = self.__setNextFileOffline() | |
573 |
|
575 | |||
574 | if not(newFile): |
|
576 | if not(newFile): | |
575 | return 0 |
|
577 | return 0 | |
576 |
|
578 | |||
577 | self.__readFirstHeader() |
|
579 | self.__readFirstHeader() | |
578 | self.nReadBlocks = 0 |
|
580 | self.nReadBlocks = 0 | |
579 | return 1 |
|
581 | return 1 | |
580 |
|
582 | |||
581 | def __waitNewBlock(self): |
|
583 | def __waitNewBlock(self): | |
582 | """ |
|
584 | """ | |
583 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
585 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
584 |
|
586 | |||
585 | Si el modo de lectura es OffLine siempre retorn 0 |
|
587 | Si el modo de lectura es OffLine siempre retorn 0 | |
586 | """ |
|
588 | """ | |
587 | if not self.online: |
|
589 | if not self.online: | |
588 | return 0 |
|
590 | return 0 | |
589 |
|
591 | |||
590 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
592 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |
591 | return 0 |
|
593 | return 0 | |
592 |
|
594 | |||
593 | currentPointer = self.fp.tell() |
|
595 | currentPointer = self.fp.tell() | |
594 |
|
596 | |||
595 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
597 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
596 |
|
598 | |||
597 | for nTries in range( self.nTries ): |
|
599 | for nTries in range( self.nTries ): | |
598 |
|
600 | |||
599 | self.fp.close() |
|
601 | self.fp.close() | |
600 | self.fp = open( self.filename, 'rb' ) |
|
602 | self.fp = open( self.filename, 'rb' ) | |
601 | self.fp.seek( currentPointer ) |
|
603 | self.fp.seek( currentPointer ) | |
602 |
|
604 | |||
603 | self.fileSize = os.path.getsize( self.filename ) |
|
605 | self.fileSize = os.path.getsize( self.filename ) | |
604 | currentSize = self.fileSize - currentPointer |
|
606 | currentSize = self.fileSize - currentPointer | |
605 |
|
607 | |||
606 | if ( currentSize >= neededSize ): |
|
608 | if ( currentSize >= neededSize ): | |
607 | self.__rdBasicHeader() |
|
609 | self.__rdBasicHeader() | |
608 | return 1 |
|
610 | return 1 | |
609 |
|
611 | |||
610 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
612 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
611 | time.sleep( self.delay ) |
|
613 | time.sleep( self.delay ) | |
612 |
|
614 | |||
613 |
|
615 | |||
614 | return 0 |
|
616 | return 0 | |
615 |
|
617 | |||
616 | def __setNewBlock(self): |
|
618 | def __setNewBlock(self): | |
617 |
|
619 | |||
618 | if self.fp == None: |
|
620 | if self.fp == None: | |
619 | return 0 |
|
621 | return 0 | |
620 |
|
622 | |||
621 | if self.flagIsNewFile: |
|
623 | if self.flagIsNewFile: | |
622 | return 1 |
|
624 | return 1 | |
623 |
|
625 | |||
624 | self.lastUTTime = self.basicHeaderObj.utc |
|
626 | self.lastUTTime = self.basicHeaderObj.utc | |
625 | currentSize = self.fileSize - self.fp.tell() |
|
627 | currentSize = self.fileSize - self.fp.tell() | |
626 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
628 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
627 |
|
629 | |||
628 | if (currentSize >= neededSize): |
|
630 | if (currentSize >= neededSize): | |
629 | self.__rdBasicHeader() |
|
631 | self.__rdBasicHeader() | |
630 | return 1 |
|
632 | return 1 | |
631 |
|
633 | |||
632 | if self.__waitNewBlock(): |
|
634 | if self.__waitNewBlock(): | |
633 | return 1 |
|
635 | return 1 | |
634 |
|
636 | |||
635 | if not(self.setNextFile()): |
|
637 | if not(self.setNextFile()): | |
636 | return 0 |
|
638 | return 0 | |
637 |
|
639 | |||
638 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
640 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
639 |
|
641 | |||
640 | self.flagTimeBlock = 0 |
|
642 | self.flagTimeBlock = 0 | |
641 |
|
643 | |||
642 | if deltaTime > self.maxTimeStep: |
|
644 | if deltaTime > self.maxTimeStep: | |
643 | self.flagTimeBlock = 1 |
|
645 | self.flagTimeBlock = 1 | |
644 |
|
646 | |||
645 | return 1 |
|
647 | return 1 | |
646 |
|
648 | |||
647 |
|
649 | |||
648 | def readNextBlock(self): |
|
650 | def readNextBlock(self): | |
649 | if not(self.__setNewBlock()): |
|
651 | if not(self.__setNewBlock()): | |
650 | return 0 |
|
652 | return 0 | |
651 |
|
653 | |||
652 | if not(self.readBlock()): |
|
654 | if not(self.readBlock()): | |
653 | return 0 |
|
655 | return 0 | |
654 |
|
656 | |||
655 | return 1 |
|
657 | return 1 | |
656 |
|
658 | |||
657 | def __rdProcessingHeader(self, fp=None): |
|
659 | def __rdProcessingHeader(self, fp=None): | |
658 | if fp == None: |
|
660 | if fp == None: | |
659 | fp = self.fp |
|
661 | fp = self.fp | |
660 |
|
662 | |||
661 | self.processingHeaderObj.read(fp) |
|
663 | self.processingHeaderObj.read(fp) | |
662 |
|
664 | |||
663 | def __rdRadarControllerHeader(self, fp=None): |
|
665 | def __rdRadarControllerHeader(self, fp=None): | |
664 | if fp == None: |
|
666 | if fp == None: | |
665 | fp = self.fp |
|
667 | fp = self.fp | |
666 |
|
668 | |||
667 | self.radarControllerHeaderObj.read(fp) |
|
669 | self.radarControllerHeaderObj.read(fp) | |
668 |
|
670 | |||
669 | def __rdSystemHeader(self, fp=None): |
|
671 | def __rdSystemHeader(self, fp=None): | |
670 | if fp == None: |
|
672 | if fp == None: | |
671 | fp = self.fp |
|
673 | fp = self.fp | |
672 |
|
674 | |||
673 | self.systemHeaderObj.read(fp) |
|
675 | self.systemHeaderObj.read(fp) | |
674 |
|
676 | |||
675 | def __rdBasicHeader(self, fp=None): |
|
677 | def __rdBasicHeader(self, fp=None): | |
676 | if fp == None: |
|
678 | if fp == None: | |
677 | fp = self.fp |
|
679 | fp = self.fp | |
678 |
|
680 | |||
679 | self.basicHeaderObj.read(fp) |
|
681 | self.basicHeaderObj.read(fp) | |
680 |
|
682 | |||
681 |
|
683 | |||
682 | def __readFirstHeader(self): |
|
684 | def __readFirstHeader(self): | |
683 | self.__rdBasicHeader() |
|
685 | self.__rdBasicHeader() | |
684 | self.__rdSystemHeader() |
|
686 | self.__rdSystemHeader() | |
685 | self.__rdRadarControllerHeader() |
|
687 | self.__rdRadarControllerHeader() | |
686 | self.__rdProcessingHeader() |
|
688 | self.__rdProcessingHeader() | |
687 |
|
689 | |||
688 | self.firstHeaderSize = self.basicHeaderObj.size |
|
690 | self.firstHeaderSize = self.basicHeaderObj.size | |
689 |
|
691 | |||
690 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
692 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
691 | if datatype == 0: |
|
693 | if datatype == 0: | |
692 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
694 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
693 | elif datatype == 1: |
|
695 | elif datatype == 1: | |
694 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
696 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
695 | elif datatype == 2: |
|
697 | elif datatype == 2: | |
696 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
698 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
697 | elif datatype == 3: |
|
699 | elif datatype == 3: | |
698 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
700 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
699 | elif datatype == 4: |
|
701 | elif datatype == 4: | |
700 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
702 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
701 | elif datatype == 5: |
|
703 | elif datatype == 5: | |
702 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
704 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
703 | else: |
|
705 | else: | |
704 | raise ValueError, 'Data type was not defined' |
|
706 | raise ValueError, 'Data type was not defined' | |
705 |
|
707 | |||
706 | self.dtype = datatype_str |
|
708 | self.dtype = datatype_str | |
707 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
709 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
708 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
710 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
709 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
711 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
710 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
712 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
711 | self.getBlockDimension() |
|
713 | self.getBlockDimension() | |
712 |
|
714 | |||
713 |
|
715 | |||
714 | def __verifyFile(self, filename, msgFlag=True): |
|
716 | def __verifyFile(self, filename, msgFlag=True): | |
715 | msg = None |
|
717 | msg = None | |
716 | try: |
|
718 | try: | |
717 | fp = open(filename, 'rb') |
|
719 | fp = open(filename, 'rb') | |
718 | currentPosition = fp.tell() |
|
720 | currentPosition = fp.tell() | |
719 | except: |
|
721 | except: | |
720 | if msgFlag: |
|
722 | if msgFlag: | |
721 | print "The file %s can't be opened" % (filename) |
|
723 | print "The file %s can't be opened" % (filename) | |
722 | return False |
|
724 | return False | |
723 |
|
725 | |||
724 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
726 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
725 |
|
727 | |||
726 | if neededSize == 0: |
|
728 | if neededSize == 0: | |
727 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
729 | basicHeaderObj = BasicHeader(LOCALTIME) | |
728 | systemHeaderObj = SystemHeader() |
|
730 | systemHeaderObj = SystemHeader() | |
729 | radarControllerHeaderObj = RadarControllerHeader() |
|
731 | radarControllerHeaderObj = RadarControllerHeader() | |
730 | processingHeaderObj = ProcessingHeader() |
|
732 | processingHeaderObj = ProcessingHeader() | |
731 |
|
733 | |||
732 | try: |
|
734 | try: | |
733 | if not( basicHeaderObj.read(fp) ): raise IOError |
|
735 | if not( basicHeaderObj.read(fp) ): raise IOError | |
734 | if not( systemHeaderObj.read(fp) ): raise IOError |
|
736 | if not( systemHeaderObj.read(fp) ): raise IOError | |
735 | if not( radarControllerHeaderObj.read(fp) ): raise IOError |
|
737 | if not( radarControllerHeaderObj.read(fp) ): raise IOError | |
736 | if not( processingHeaderObj.read(fp) ): raise IOError |
|
738 | if not( processingHeaderObj.read(fp) ): raise IOError | |
737 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
739 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
738 |
|
740 | |||
739 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
741 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
740 |
|
742 | |||
741 | except: |
|
743 | except: | |
742 | if msgFlag: |
|
744 | if msgFlag: | |
743 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
745 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
744 |
|
746 | |||
745 | fp.close() |
|
747 | fp.close() | |
746 | return False |
|
748 | return False | |
747 | else: |
|
749 | else: | |
748 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
750 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
749 |
|
751 | |||
750 | fp.close() |
|
752 | fp.close() | |
751 | fileSize = os.path.getsize(filename) |
|
753 | fileSize = os.path.getsize(filename) | |
752 | currentSize = fileSize - currentPosition |
|
754 | currentSize = fileSize - currentPosition | |
753 | if currentSize < neededSize: |
|
755 | if currentSize < neededSize: | |
754 | if msgFlag and (msg != None): |
|
756 | if msgFlag and (msg != None): | |
755 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
757 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
756 | return False |
|
758 | return False | |
757 |
|
759 | |||
758 | return True |
|
760 | return True | |
759 |
|
761 | |||
760 | def setup(self, |
|
762 | def setup(self, | |
761 | path=None, |
|
763 | path=None, | |
762 | startDate=None, |
|
764 | startDate=None, | |
763 | endDate=None, |
|
765 | endDate=None, | |
764 | startTime=datetime.time(0,0,0), |
|
766 | startTime=datetime.time(0,0,0), | |
765 | endTime=datetime.time(23,59,59), |
|
767 | endTime=datetime.time(23,59,59), | |
766 | set=0, |
|
768 | set=0, | |
767 | expLabel = "", |
|
769 | expLabel = "", | |
768 | ext = None, |
|
770 | ext = None, | |
769 | online = False, |
|
771 | online = False, | |
770 | delay = 60, |
|
772 | delay = 60, | |
771 | walk = True): |
|
773 | walk = True): | |
772 |
|
774 | |||
773 | if path == None: |
|
775 | if path == None: | |
774 | raise ValueError, "The path is not valid" |
|
776 | raise ValueError, "The path is not valid" | |
775 |
|
777 | |||
776 | if ext == None: |
|
778 | if ext == None: | |
777 | ext = self.ext |
|
779 | ext = self.ext | |
778 |
|
780 | |||
779 | if online: |
|
781 | if online: | |
780 | print "Searching files in online mode..." |
|
782 | print "Searching files in online mode..." | |
781 |
|
783 | |||
782 | for nTries in range( self.nTries ): |
|
784 | for nTries in range( self.nTries ): | |
783 | fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk) |
|
785 | fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk) | |
784 |
|
786 | |||
785 | if fullpath: |
|
787 | if fullpath: | |
786 | break |
|
788 | break | |
787 |
|
789 | |||
788 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
790 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
789 | time.sleep( self.delay ) |
|
791 | time.sleep( self.delay ) | |
790 |
|
792 | |||
791 | if not(fullpath): |
|
793 | if not(fullpath): | |
792 | print "There 'isn't valied files in %s" % path |
|
794 | print "There 'isn't valied files in %s" % path | |
793 | return None |
|
795 | return None | |
794 |
|
796 | |||
795 | self.year = year |
|
797 | self.year = year | |
796 | self.doy = doy |
|
798 | self.doy = doy | |
797 | self.set = set - 1 |
|
799 | self.set = set - 1 | |
798 | self.path = path |
|
800 | self.path = path | |
799 |
|
801 | |||
800 | else: |
|
802 | else: | |
801 | print "Searching files in offline mode ..." |
|
803 | print "Searching files in offline mode ..." | |
802 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
804 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
803 | startTime=startTime, endTime=endTime, |
|
805 | startTime=startTime, endTime=endTime, | |
804 | set=set, expLabel=expLabel, ext=ext, |
|
806 | set=set, expLabel=expLabel, ext=ext, | |
805 | walk=walk) |
|
807 | walk=walk) | |
806 |
|
808 | |||
807 | if not(pathList): |
|
809 | if not(pathList): | |
808 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
810 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
809 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
811 | datetime.datetime.combine(startDate,startTime).ctime(), | |
810 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
812 | datetime.datetime.combine(endDate,endTime).ctime()) | |
811 |
|
813 | |||
812 | sys.exit(-1) |
|
814 | sys.exit(-1) | |
813 |
|
815 | |||
814 |
|
816 | |||
815 | self.fileIndex = -1 |
|
817 | self.fileIndex = -1 | |
816 | self.pathList = pathList |
|
818 | self.pathList = pathList | |
817 | self.filenameList = filenameList |
|
819 | self.filenameList = filenameList | |
818 |
|
820 | |||
819 | self.online = online |
|
821 | self.online = online | |
820 | self.delay = delay |
|
822 | self.delay = delay | |
821 | ext = ext.lower() |
|
823 | ext = ext.lower() | |
822 | self.ext = ext |
|
824 | self.ext = ext | |
823 |
|
825 | |||
824 | if not(self.setNextFile()): |
|
826 | if not(self.setNextFile()): | |
825 | if (startDate!=None) and (endDate!=None): |
|
827 | if (startDate!=None) and (endDate!=None): | |
826 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
828 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
827 | elif startDate != None: |
|
829 | elif startDate != None: | |
828 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
830 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
829 | else: |
|
831 | else: | |
830 | print "No files" |
|
832 | print "No files" | |
831 |
|
833 | |||
832 | sys.exit(-1) |
|
834 | sys.exit(-1) | |
833 |
|
835 | |||
834 | # self.updateDataHeader() |
|
836 | # self.updateDataHeader() | |
835 |
|
837 | |||
836 | return self.dataOut |
|
838 | return self.dataOut | |
837 |
|
839 | |||
838 | def getData(): |
|
840 | def getData(): | |
839 |
|
841 | |||
840 | raise ValueError, "This method has not been implemented" |
|
842 | raise ValueError, "This method has not been implemented" | |
841 |
|
843 | |||
842 | def hasNotDataInBuffer(): |
|
844 | def hasNotDataInBuffer(): | |
843 |
|
845 | |||
844 | raise ValueError, "This method has not been implemented" |
|
846 | raise ValueError, "This method has not been implemented" | |
845 |
|
847 | |||
846 | def readBlock(): |
|
848 | def readBlock(): | |
847 |
|
849 | |||
848 | raise ValueError, "This method has not been implemented" |
|
850 | raise ValueError, "This method has not been implemented" | |
849 |
|
851 | |||
850 | def isEndProcess(self): |
|
852 | def isEndProcess(self): | |
851 |
|
853 | |||
852 | return self.flagNoMoreFiles |
|
854 | return self.flagNoMoreFiles | |
853 |
|
855 | |||
854 | def printReadBlocks(self): |
|
856 | def printReadBlocks(self): | |
855 |
|
857 | |||
856 | print "Number of read blocks per file %04d" %self.nReadBlocks |
|
858 | print "Number of read blocks per file %04d" %self.nReadBlocks | |
857 |
|
859 | |||
858 | def printTotalBlocks(self): |
|
860 | def printTotalBlocks(self): | |
859 |
|
861 | |||
860 | print "Number of read blocks %04d" %self.nTotalBlocks |
|
862 | print "Number of read blocks %04d" %self.nTotalBlocks | |
861 |
|
863 | |||
862 | def printInfo(self): |
|
864 | def printInfo(self): | |
863 |
|
865 | |||
864 | print self.basicHeaderObj.printInfo() |
|
866 | print self.basicHeaderObj.printInfo() | |
865 | print self.systemHeaderObj.printInfo() |
|
867 | print self.systemHeaderObj.printInfo() | |
866 | print self.radarControllerHeaderObj.printInfo() |
|
868 | print self.radarControllerHeaderObj.printInfo() | |
867 | print self.processingHeaderObj.printInfo() |
|
869 | print self.processingHeaderObj.printInfo() | |
868 |
|
870 | |||
869 |
|
871 | |||
870 | def run(self, **kwargs): |
|
872 | def run(self, **kwargs): | |
871 |
|
873 | |||
872 | if not(self.isConfig): |
|
874 | if not(self.isConfig): | |
873 |
|
875 | |||
874 | # self.dataOut = dataOut |
|
876 | # self.dataOut = dataOut | |
875 | self.setup(**kwargs) |
|
877 | self.setup(**kwargs) | |
876 | self.isConfig = True |
|
878 | self.isConfig = True | |
877 |
|
879 | |||
878 | self.getData() |
|
880 | self.getData() | |
879 |
|
881 | |||
880 | class JRODataWriter(JRODataIO, Operation): |
|
882 | class JRODataWriter(JRODataIO, Operation): | |
881 |
|
883 | |||
882 | """ |
|
884 | """ | |
883 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
885 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
884 | de los datos siempre se realiza por bloques. |
|
886 | de los datos siempre se realiza por bloques. | |
885 | """ |
|
887 | """ | |
886 |
|
888 | |||
887 | blockIndex = 0 |
|
889 | blockIndex = 0 | |
888 |
|
890 | |||
889 | path = None |
|
891 | path = None | |
890 |
|
892 | |||
891 | setFile = None |
|
893 | setFile = None | |
892 |
|
894 | |||
893 | profilesPerBlock = None |
|
895 | profilesPerBlock = None | |
894 |
|
896 | |||
895 | blocksPerFile = None |
|
897 | blocksPerFile = None | |
896 |
|
898 | |||
897 | nWriteBlocks = 0 |
|
899 | nWriteBlocks = 0 | |
898 |
|
900 | |||
899 | def __init__(self, dataOut=None): |
|
901 | def __init__(self, dataOut=None): | |
900 | raise ValueError, "Not implemented" |
|
902 | raise ValueError, "Not implemented" | |
901 |
|
903 | |||
902 |
|
904 | |||
903 | def hasAllDataInBuffer(self): |
|
905 | def hasAllDataInBuffer(self): | |
904 | raise ValueError, "Not implemented" |
|
906 | raise ValueError, "Not implemented" | |
905 |
|
907 | |||
906 |
|
908 | |||
907 | def setBlockDimension(self): |
|
909 | def setBlockDimension(self): | |
908 | raise ValueError, "Not implemented" |
|
910 | raise ValueError, "Not implemented" | |
909 |
|
911 | |||
910 |
|
912 | |||
911 | def writeBlock(self): |
|
913 | def writeBlock(self): | |
912 | raise ValueError, "No implemented" |
|
914 | raise ValueError, "No implemented" | |
913 |
|
915 | |||
914 |
|
916 | |||
915 | def putData(self): |
|
917 | def putData(self): | |
916 | raise ValueError, "No implemented" |
|
918 | raise ValueError, "No implemented" | |
917 |
|
919 | |||
918 | def getDataHeader(self): |
|
920 | def getDataHeader(self): | |
919 | """ |
|
921 | """ | |
920 | Obtiene una copia del First Header |
|
922 | Obtiene una copia del First Header | |
921 |
|
923 | |||
922 | Affected: |
|
924 | Affected: | |
923 |
|
925 | |||
924 | self.basicHeaderObj |
|
926 | self.basicHeaderObj | |
925 | self.systemHeaderObj |
|
927 | self.systemHeaderObj | |
926 | self.radarControllerHeaderObj |
|
928 | self.radarControllerHeaderObj | |
927 | self.processingHeaderObj self. |
|
929 | self.processingHeaderObj self. | |
928 |
|
930 | |||
929 | Return: |
|
931 | Return: | |
930 | None |
|
932 | None | |
931 | """ |
|
933 | """ | |
932 |
|
934 | |||
933 | raise ValueError, "No implemented" |
|
935 | raise ValueError, "No implemented" | |
934 |
|
936 | |||
935 | def getBasicHeader(self): |
|
937 | def getBasicHeader(self): | |
936 |
|
938 | |||
937 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
939 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
938 | self.basicHeaderObj.version = self.versionFile |
|
940 | self.basicHeaderObj.version = self.versionFile | |
939 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
941 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
940 |
|
942 | |||
941 | utc = numpy.floor(self.dataOut.utctime) |
|
943 | utc = numpy.floor(self.dataOut.utctime) | |
942 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
944 | milisecond = (self.dataOut.utctime - utc)* 1000.0 | |
943 |
|
945 | |||
944 | self.basicHeaderObj.utc = utc |
|
946 | self.basicHeaderObj.utc = utc | |
945 | self.basicHeaderObj.miliSecond = milisecond |
|
947 | self.basicHeaderObj.miliSecond = milisecond | |
946 | self.basicHeaderObj.timeZone = 0 |
|
948 | self.basicHeaderObj.timeZone = 0 | |
947 | self.basicHeaderObj.dstFlag = 0 |
|
949 | self.basicHeaderObj.dstFlag = 0 | |
948 | self.basicHeaderObj.errorCount = 0 |
|
950 | self.basicHeaderObj.errorCount = 0 | |
949 |
|
951 | |||
950 | def __writeFirstHeader(self): |
|
952 | def __writeFirstHeader(self): | |
951 | """ |
|
953 | """ | |
952 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
954 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
953 |
|
955 | |||
954 | Affected: |
|
956 | Affected: | |
955 | __dataType |
|
957 | __dataType | |
956 |
|
958 | |||
957 | Return: |
|
959 | Return: | |
958 | None |
|
960 | None | |
959 | """ |
|
961 | """ | |
960 |
|
962 | |||
961 | # CALCULAR PARAMETROS |
|
963 | # CALCULAR PARAMETROS | |
962 |
|
964 | |||
963 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
965 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
964 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
966 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
965 |
|
967 | |||
966 | self.basicHeaderObj.write(self.fp) |
|
968 | self.basicHeaderObj.write(self.fp) | |
967 | self.systemHeaderObj.write(self.fp) |
|
969 | self.systemHeaderObj.write(self.fp) | |
968 | self.radarControllerHeaderObj.write(self.fp) |
|
970 | self.radarControllerHeaderObj.write(self.fp) | |
969 | self.processingHeaderObj.write(self.fp) |
|
971 | self.processingHeaderObj.write(self.fp) | |
970 |
|
972 | |||
971 | self.dtype = self.dataOut.dtype |
|
973 | self.dtype = self.dataOut.dtype | |
972 |
|
974 | |||
973 | def __setNewBlock(self): |
|
975 | def __setNewBlock(self): | |
974 | """ |
|
976 | """ | |
975 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
977 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
976 |
|
978 | |||
977 | Return: |
|
979 | Return: | |
978 | 0 : si no pudo escribir nada |
|
980 | 0 : si no pudo escribir nada | |
979 | 1 : Si escribio el Basic el First Header |
|
981 | 1 : Si escribio el Basic el First Header | |
980 | """ |
|
982 | """ | |
981 | if self.fp == None: |
|
983 | if self.fp == None: | |
982 | self.setNextFile() |
|
984 | self.setNextFile() | |
983 |
|
985 | |||
984 | if self.flagIsNewFile: |
|
986 | if self.flagIsNewFile: | |
985 | return 1 |
|
987 | return 1 | |
986 |
|
988 | |||
987 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
989 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
988 | self.basicHeaderObj.write(self.fp) |
|
990 | self.basicHeaderObj.write(self.fp) | |
989 | return 1 |
|
991 | return 1 | |
990 |
|
992 | |||
991 | if not( self.setNextFile() ): |
|
993 | if not( self.setNextFile() ): | |
992 | return 0 |
|
994 | return 0 | |
993 |
|
995 | |||
994 | return 1 |
|
996 | return 1 | |
995 |
|
997 | |||
996 |
|
998 | |||
997 | def writeNextBlock(self): |
|
999 | def writeNextBlock(self): | |
998 | """ |
|
1000 | """ | |
999 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1001 | Selecciona el bloque siguiente de datos y los escribe en un file | |
1000 |
|
1002 | |||
1001 | Return: |
|
1003 | Return: | |
1002 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1004 | 0 : Si no hizo pudo escribir el bloque de datos | |
1003 | 1 : Si no pudo escribir el bloque de datos |
|
1005 | 1 : Si no pudo escribir el bloque de datos | |
1004 | """ |
|
1006 | """ | |
1005 | if not( self.__setNewBlock() ): |
|
1007 | if not( self.__setNewBlock() ): | |
1006 | return 0 |
|
1008 | return 0 | |
1007 |
|
1009 | |||
1008 | self.writeBlock() |
|
1010 | self.writeBlock() | |
1009 |
|
1011 | |||
1010 | return 1 |
|
1012 | return 1 | |
1011 |
|
1013 | |||
1012 | def setNextFile(self): |
|
1014 | def setNextFile(self): | |
1013 | """ |
|
1015 | """ | |
1014 | Determina el siguiente file que sera escrito |
|
1016 | Determina el siguiente file que sera escrito | |
1015 |
|
1017 | |||
1016 | Affected: |
|
1018 | Affected: | |
1017 | self.filename |
|
1019 | self.filename | |
1018 | self.subfolder |
|
1020 | self.subfolder | |
1019 | self.fp |
|
1021 | self.fp | |
1020 | self.setFile |
|
1022 | self.setFile | |
1021 | self.flagIsNewFile |
|
1023 | self.flagIsNewFile | |
1022 |
|
1024 | |||
1023 | Return: |
|
1025 | Return: | |
1024 | 0 : Si el archivo no puede ser escrito |
|
1026 | 0 : Si el archivo no puede ser escrito | |
1025 | 1 : Si el archivo esta listo para ser escrito |
|
1027 | 1 : Si el archivo esta listo para ser escrito | |
1026 | """ |
|
1028 | """ | |
1027 | ext = self.ext |
|
1029 | ext = self.ext | |
1028 | path = self.path |
|
1030 | path = self.path | |
1029 |
|
1031 | |||
1030 | if self.fp != None: |
|
1032 | if self.fp != None: | |
1031 | self.fp.close() |
|
1033 | self.fp.close() | |
1032 |
|
1034 | |||
1033 | timeTuple = time.localtime( self.dataOut.dataUtcTime) |
|
1035 | timeTuple = time.localtime( self.dataOut.dataUtcTime) | |
1034 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1036 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
1035 |
|
1037 | |||
1036 | fullpath = os.path.join( path, subfolder ) |
|
1038 | fullpath = os.path.join( path, subfolder ) | |
1037 | if not( os.path.exists(fullpath) ): |
|
1039 | if not( os.path.exists(fullpath) ): | |
1038 | os.mkdir(fullpath) |
|
1040 | os.mkdir(fullpath) | |
1039 | self.setFile = -1 #inicializo mi contador de seteo |
|
1041 | self.setFile = -1 #inicializo mi contador de seteo | |
1040 | else: |
|
1042 | else: | |
1041 | filesList = os.listdir( fullpath ) |
|
1043 | filesList = os.listdir( fullpath ) | |
1042 | if len( filesList ) > 0: |
|
1044 | if len( filesList ) > 0: | |
1043 | filesList = sorted( filesList, key=str.lower ) |
|
1045 | filesList = sorted( filesList, key=str.lower ) | |
1044 | filen = filesList[-1] |
|
1046 | filen = filesList[-1] | |
1045 | # el filename debera tener el siguiente formato |
|
1047 | # el filename debera tener el siguiente formato | |
1046 | # 0 1234 567 89A BCDE (hex) |
|
1048 | # 0 1234 567 89A BCDE (hex) | |
1047 | # x YYYY DDD SSS .ext |
|
1049 | # x YYYY DDD SSS .ext | |
1048 | if isNumber( filen[8:11] ): |
|
1050 | if isNumber( filen[8:11] ): | |
1049 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
1051 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
1050 | else: |
|
1052 | else: | |
1051 | self.setFile = -1 |
|
1053 | self.setFile = -1 | |
1052 | else: |
|
1054 | else: | |
1053 | self.setFile = -1 #inicializo mi contador de seteo |
|
1055 | self.setFile = -1 #inicializo mi contador de seteo | |
1054 |
|
1056 | |||
1055 | setFile = self.setFile |
|
1057 | setFile = self.setFile | |
1056 | setFile += 1 |
|
1058 | setFile += 1 | |
1057 |
|
1059 | |||
1058 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
1060 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
1059 | timeTuple.tm_year, |
|
1061 | timeTuple.tm_year, | |
1060 | timeTuple.tm_yday, |
|
1062 | timeTuple.tm_yday, | |
1061 | setFile, |
|
1063 | setFile, | |
1062 | ext ) |
|
1064 | ext ) | |
1063 |
|
1065 | |||
1064 | filename = os.path.join( path, subfolder, file ) |
|
1066 | filename = os.path.join( path, subfolder, file ) | |
1065 |
|
1067 | |||
1066 | fp = open( filename,'wb' ) |
|
1068 | fp = open( filename,'wb' ) | |
1067 |
|
1069 | |||
1068 | self.blockIndex = 0 |
|
1070 | self.blockIndex = 0 | |
1069 |
|
1071 | |||
1070 | #guardando atributos |
|
1072 | #guardando atributos | |
1071 | self.filename = filename |
|
1073 | self.filename = filename | |
1072 | self.subfolder = subfolder |
|
1074 | self.subfolder = subfolder | |
1073 | self.fp = fp |
|
1075 | self.fp = fp | |
1074 | self.setFile = setFile |
|
1076 | self.setFile = setFile | |
1075 | self.flagIsNewFile = 1 |
|
1077 | self.flagIsNewFile = 1 | |
1076 |
|
1078 | |||
1077 | self.getDataHeader() |
|
1079 | self.getDataHeader() | |
1078 |
|
1080 | |||
1079 | print 'Writing the file: %s'%self.filename |
|
1081 | print 'Writing the file: %s'%self.filename | |
1080 |
|
1082 | |||
1081 | self.__writeFirstHeader() |
|
1083 | self.__writeFirstHeader() | |
1082 |
|
1084 | |||
1083 | return 1 |
|
1085 | return 1 | |
1084 |
|
1086 | |||
1085 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): |
|
1087 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): | |
1086 | """ |
|
1088 | """ | |
1087 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1089 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1088 |
|
1090 | |||
1089 | Inputs: |
|
1091 | Inputs: | |
1090 | path : el path destino en el cual se escribiran los files a crear |
|
1092 | path : el path destino en el cual se escribiran los files a crear | |
1091 | format : formato en el cual sera salvado un file |
|
1093 | format : formato en el cual sera salvado un file | |
1092 | set : el setebo del file |
|
1094 | set : el setebo del file | |
1093 |
|
1095 | |||
1094 | Return: |
|
1096 | Return: | |
1095 | 0 : Si no realizo un buen seteo |
|
1097 | 0 : Si no realizo un buen seteo | |
1096 | 1 : Si realizo un buen seteo |
|
1098 | 1 : Si realizo un buen seteo | |
1097 | """ |
|
1099 | """ | |
1098 |
|
1100 | |||
1099 | if ext == None: |
|
1101 | if ext == None: | |
1100 | ext = self.ext |
|
1102 | ext = self.ext | |
1101 |
|
1103 | |||
1102 | ext = ext.lower() |
|
1104 | ext = ext.lower() | |
1103 |
|
1105 | |||
1104 | self.ext = ext |
|
1106 | self.ext = ext | |
1105 |
|
1107 | |||
1106 | self.path = path |
|
1108 | self.path = path | |
1107 |
|
1109 | |||
1108 | self.setFile = set - 1 |
|
1110 | self.setFile = set - 1 | |
1109 |
|
1111 | |||
1110 | self.blocksPerFile = blocksPerFile |
|
1112 | self.blocksPerFile = blocksPerFile | |
1111 |
|
1113 | |||
1112 | self.profilesPerBlock = profilesPerBlock |
|
1114 | self.profilesPerBlock = profilesPerBlock | |
1113 |
|
1115 | |||
1114 | self.dataOut = dataOut |
|
1116 | self.dataOut = dataOut | |
1115 |
|
1117 | |||
1116 | if not(self.setNextFile()): |
|
1118 | if not(self.setNextFile()): | |
1117 | print "There isn't a next file" |
|
1119 | print "There isn't a next file" | |
1118 | return 0 |
|
1120 | return 0 | |
1119 |
|
1121 | |||
1120 | self.setBlockDimension() |
|
1122 | self.setBlockDimension() | |
1121 |
|
1123 | |||
1122 | return 1 |
|
1124 | return 1 | |
1123 |
|
1125 | |||
1124 | def run(self, dataOut, **kwargs): |
|
1126 | def run(self, dataOut, **kwargs): | |
1125 |
|
1127 | |||
1126 | if not(self.isConfig): |
|
1128 | if not(self.isConfig): | |
1127 |
|
1129 | |||
1128 | self.setup(dataOut, **kwargs) |
|
1130 | self.setup(dataOut, **kwargs) | |
1129 | self.isConfig = True |
|
1131 | self.isConfig = True | |
1130 |
|
1132 | |||
1131 | self.putData() |
|
1133 | self.putData() | |
1132 |
|
1134 | |||
1133 | class VoltageReader(JRODataReader): |
|
1135 | class VoltageReader(JRODataReader): | |
1134 | """ |
|
1136 | """ | |
1135 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
1137 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
1136 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
1138 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
1137 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
1139 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
1138 |
|
1140 | |||
1139 | perfiles * alturas * canales |
|
1141 | perfiles * alturas * canales | |
1140 |
|
1142 | |||
1141 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1143 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1142 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
1144 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
1143 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
1145 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
1144 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1146 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1145 |
|
1147 | |||
1146 | Example: |
|
1148 | Example: | |
1147 |
|
1149 | |||
1148 | dpath = "/home/myuser/data" |
|
1150 | dpath = "/home/myuser/data" | |
1149 |
|
1151 | |||
1150 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1152 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1151 |
|
1153 | |||
1152 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1154 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1153 |
|
1155 | |||
1154 | readerObj = VoltageReader() |
|
1156 | readerObj = VoltageReader() | |
1155 |
|
1157 | |||
1156 | readerObj.setup(dpath, startTime, endTime) |
|
1158 | readerObj.setup(dpath, startTime, endTime) | |
1157 |
|
1159 | |||
1158 | while(True): |
|
1160 | while(True): | |
1159 |
|
1161 | |||
1160 | #to get one profile |
|
1162 | #to get one profile | |
1161 | profile = readerObj.getData() |
|
1163 | profile = readerObj.getData() | |
1162 |
|
1164 | |||
1163 | #print the profile |
|
1165 | #print the profile | |
1164 | print profile |
|
1166 | print profile | |
1165 |
|
1167 | |||
1166 | #If you want to see all datablock |
|
1168 | #If you want to see all datablock | |
1167 | print readerObj.datablock |
|
1169 | print readerObj.datablock | |
1168 |
|
1170 | |||
1169 | if readerObj.flagNoMoreFiles: |
|
1171 | if readerObj.flagNoMoreFiles: | |
1170 | break |
|
1172 | break | |
1171 |
|
1173 | |||
1172 | """ |
|
1174 | """ | |
1173 |
|
1175 | |||
1174 | ext = ".r" |
|
1176 | ext = ".r" | |
1175 |
|
1177 | |||
1176 | optchar = "D" |
|
1178 | optchar = "D" | |
1177 | dataOut = None |
|
1179 | dataOut = None | |
1178 |
|
1180 | |||
1179 |
|
1181 | |||
1180 | def __init__(self): |
|
1182 | def __init__(self): | |
1181 | """ |
|
1183 | """ | |
1182 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
1184 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
1183 |
|
1185 | |||
1184 | Input: |
|
1186 | Input: | |
1185 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
1187 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
1186 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1188 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1187 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1189 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1188 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1190 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1189 | bloque de datos. |
|
1191 | bloque de datos. | |
1190 | Si este parametro no es pasado se creara uno internamente. |
|
1192 | Si este parametro no es pasado se creara uno internamente. | |
1191 |
|
1193 | |||
1192 | Variables afectadas: |
|
1194 | Variables afectadas: | |
1193 | self.dataOut |
|
1195 | self.dataOut | |
1194 |
|
1196 | |||
1195 | Return: |
|
1197 | Return: | |
1196 | None |
|
1198 | None | |
1197 | """ |
|
1199 | """ | |
1198 |
|
1200 | |||
1199 | self.isConfig = False |
|
1201 | self.isConfig = False | |
1200 |
|
1202 | |||
1201 | self.datablock = None |
|
1203 | self.datablock = None | |
1202 |
|
1204 | |||
1203 | self.utc = 0 |
|
1205 | self.utc = 0 | |
1204 |
|
1206 | |||
1205 | self.ext = ".r" |
|
1207 | self.ext = ".r" | |
1206 |
|
1208 | |||
1207 | self.optchar = "D" |
|
1209 | self.optchar = "D" | |
1208 |
|
1210 | |||
1209 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1211 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1210 |
|
1212 | |||
1211 | self.systemHeaderObj = SystemHeader() |
|
1213 | self.systemHeaderObj = SystemHeader() | |
1212 |
|
1214 | |||
1213 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1215 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1214 |
|
1216 | |||
1215 | self.processingHeaderObj = ProcessingHeader() |
|
1217 | self.processingHeaderObj = ProcessingHeader() | |
1216 |
|
1218 | |||
1217 | self.online = 0 |
|
1219 | self.online = 0 | |
1218 |
|
1220 | |||
1219 | self.fp = None |
|
1221 | self.fp = None | |
1220 |
|
1222 | |||
1221 | self.idFile = None |
|
1223 | self.idFile = None | |
1222 |
|
1224 | |||
1223 | self.dtype = None |
|
1225 | self.dtype = None | |
1224 |
|
1226 | |||
1225 | self.fileSizeByHeader = None |
|
1227 | self.fileSizeByHeader = None | |
1226 |
|
1228 | |||
1227 | self.filenameList = [] |
|
1229 | self.filenameList = [] | |
1228 |
|
1230 | |||
1229 | self.filename = None |
|
1231 | self.filename = None | |
1230 |
|
1232 | |||
1231 | self.fileSize = None |
|
1233 | self.fileSize = None | |
1232 |
|
1234 | |||
1233 | self.firstHeaderSize = 0 |
|
1235 | self.firstHeaderSize = 0 | |
1234 |
|
1236 | |||
1235 | self.basicHeaderSize = 24 |
|
1237 | self.basicHeaderSize = 24 | |
1236 |
|
1238 | |||
1237 | self.pathList = [] |
|
1239 | self.pathList = [] | |
1238 |
|
1240 | |||
1239 | self.filenameList = [] |
|
1241 | self.filenameList = [] | |
1240 |
|
1242 | |||
1241 | self.lastUTTime = 0 |
|
1243 | self.lastUTTime = 0 | |
1242 |
|
1244 | |||
1243 | self.maxTimeStep = 30 |
|
1245 | self.maxTimeStep = 30 | |
1244 |
|
1246 | |||
1245 | self.flagNoMoreFiles = 0 |
|
1247 | self.flagNoMoreFiles = 0 | |
1246 |
|
1248 | |||
1247 | self.set = 0 |
|
1249 | self.set = 0 | |
1248 |
|
1250 | |||
1249 | self.path = None |
|
1251 | self.path = None | |
1250 |
|
1252 | |||
1251 | self.profileIndex = 9999 |
|
1253 | self.profileIndex = 9999 | |
1252 |
|
1254 | |||
1253 | self.delay = 3 #seconds |
|
1255 | self.delay = 3 #seconds | |
1254 |
|
1256 | |||
1255 | self.nTries = 3 #quantity tries |
|
1257 | self.nTries = 3 #quantity tries | |
1256 |
|
1258 | |||
1257 | self.nFiles = 3 #number of files for searching |
|
1259 | self.nFiles = 3 #number of files for searching | |
1258 |
|
1260 | |||
1259 | self.nReadBlocks = 0 |
|
1261 | self.nReadBlocks = 0 | |
1260 |
|
1262 | |||
1261 | self.flagIsNewFile = 1 |
|
1263 | self.flagIsNewFile = 1 | |
1262 |
|
1264 | |||
1263 | self.ippSeconds = 0 |
|
1265 | self.ippSeconds = 0 | |
1264 |
|
1266 | |||
1265 | self.flagTimeBlock = 0 |
|
1267 | self.flagTimeBlock = 0 | |
1266 |
|
1268 | |||
1267 | self.flagIsNewBlock = 0 |
|
1269 | self.flagIsNewBlock = 0 | |
1268 |
|
1270 | |||
1269 | self.nTotalBlocks = 0 |
|
1271 | self.nTotalBlocks = 0 | |
1270 |
|
1272 | |||
1271 | self.blocksize = 0 |
|
1273 | self.blocksize = 0 | |
1272 |
|
1274 | |||
1273 | self.dataOut = self.createObjByDefault() |
|
1275 | self.dataOut = self.createObjByDefault() | |
1274 |
|
1276 | |||
1275 | def createObjByDefault(self): |
|
1277 | def createObjByDefault(self): | |
1276 |
|
1278 | |||
1277 | dataObj = Voltage() |
|
1279 | dataObj = Voltage() | |
1278 |
|
1280 | |||
1279 | return dataObj |
|
1281 | return dataObj | |
1280 |
|
1282 | |||
1281 | def __hasNotDataInBuffer(self): |
|
1283 | def __hasNotDataInBuffer(self): | |
1282 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1284 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1283 | return 1 |
|
1285 | return 1 | |
1284 | return 0 |
|
1286 | return 0 | |
1285 |
|
1287 | |||
1286 |
|
1288 | |||
1287 | def getBlockDimension(self): |
|
1289 | def getBlockDimension(self): | |
1288 | """ |
|
1290 | """ | |
1289 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1291 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1290 |
|
1292 | |||
1291 | Affected: |
|
1293 | Affected: | |
1292 | self.blocksize |
|
1294 | self.blocksize | |
1293 |
|
1295 | |||
1294 | Return: |
|
1296 | Return: | |
1295 | None |
|
1297 | None | |
1296 | """ |
|
1298 | """ | |
1297 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
1299 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
1298 | self.blocksize = pts2read |
|
1300 | self.blocksize = pts2read | |
1299 |
|
1301 | |||
1300 |
|
1302 | |||
1301 | def readBlock(self): |
|
1303 | def readBlock(self): | |
1302 | """ |
|
1304 | """ | |
1303 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1305 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
1304 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1306 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1305 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1307 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1306 | es seteado a 0 |
|
1308 | es seteado a 0 | |
1307 |
|
1309 | |||
1308 | Inputs: |
|
1310 | Inputs: | |
1309 | None |
|
1311 | None | |
1310 |
|
1312 | |||
1311 | Return: |
|
1313 | Return: | |
1312 | None |
|
1314 | None | |
1313 |
|
1315 | |||
1314 | Affected: |
|
1316 | Affected: | |
1315 | self.profileIndex |
|
1317 | self.profileIndex | |
1316 | self.datablock |
|
1318 | self.datablock | |
1317 | self.flagIsNewFile |
|
1319 | self.flagIsNewFile | |
1318 | self.flagIsNewBlock |
|
1320 | self.flagIsNewBlock | |
1319 | self.nTotalBlocks |
|
1321 | self.nTotalBlocks | |
1320 |
|
1322 | |||
1321 | Exceptions: |
|
1323 | Exceptions: | |
1322 | Si un bloque leido no es un bloque valido |
|
1324 | Si un bloque leido no es un bloque valido | |
1323 | """ |
|
1325 | """ | |
1324 |
|
1326 | |||
1325 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1327 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
1326 |
|
1328 | |||
1327 | try: |
|
1329 | try: | |
1328 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1330 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
1329 | except: |
|
1331 | except: | |
1330 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
1332 | print "The read block (%3d) has not enough data" %self.nReadBlocks | |
1331 | return 0 |
|
1333 | return 0 | |
1332 |
|
1334 | |||
1333 | junk = numpy.transpose(junk, (2,0,1)) |
|
1335 | junk = numpy.transpose(junk, (2,0,1)) | |
1334 | self.datablock = junk['real'] + junk['imag']*1j |
|
1336 | self.datablock = junk['real'] + junk['imag']*1j | |
1335 |
|
1337 | |||
1336 | self.profileIndex = 0 |
|
1338 | self.profileIndex = 0 | |
1337 |
|
1339 | |||
1338 | self.flagIsNewFile = 0 |
|
1340 | self.flagIsNewFile = 0 | |
1339 | self.flagIsNewBlock = 1 |
|
1341 | self.flagIsNewBlock = 1 | |
1340 |
|
1342 | |||
1341 | self.nTotalBlocks += 1 |
|
1343 | self.nTotalBlocks += 1 | |
1342 | self.nReadBlocks += 1 |
|
1344 | self.nReadBlocks += 1 | |
1343 |
|
1345 | |||
1344 | return 1 |
|
1346 | return 1 | |
1345 |
|
1347 | |||
1346 |
|
1348 | |||
1347 | def getData(self): |
|
1349 | def getData(self): | |
1348 | """ |
|
1350 | """ | |
1349 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
1351 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
1350 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1352 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1351 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1353 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1352 |
|
1354 | |||
1353 | Ademas incrementa el contador del buffer en 1. |
|
1355 | Ademas incrementa el contador del buffer en 1. | |
1354 |
|
1356 | |||
1355 | Return: |
|
1357 | Return: | |
1356 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
1358 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
1357 | buffer. Si no hay mas archivos a leer retorna None. |
|
1359 | buffer. Si no hay mas archivos a leer retorna None. | |
1358 |
|
1360 | |||
1359 | Variables afectadas: |
|
1361 | Variables afectadas: | |
1360 | self.dataOut |
|
1362 | self.dataOut | |
1361 | self.profileIndex |
|
1363 | self.profileIndex | |
1362 |
|
1364 | |||
1363 | Affected: |
|
1365 | Affected: | |
1364 | self.dataOut |
|
1366 | self.dataOut | |
1365 | self.profileIndex |
|
1367 | self.profileIndex | |
1366 | self.flagTimeBlock |
|
1368 | self.flagTimeBlock | |
1367 | self.flagIsNewBlock |
|
1369 | self.flagIsNewBlock | |
1368 | """ |
|
1370 | """ | |
1369 |
|
1371 | |||
1370 | if self.flagNoMoreFiles: |
|
1372 | if self.flagNoMoreFiles: | |
1371 | self.dataOut.flagNoData = True |
|
1373 | self.dataOut.flagNoData = True | |
1372 | print 'Process finished' |
|
1374 | print 'Process finished' | |
1373 | return 0 |
|
1375 | return 0 | |
1374 |
|
1376 | |||
1375 | self.flagTimeBlock = 0 |
|
1377 | self.flagTimeBlock = 0 | |
1376 | self.flagIsNewBlock = 0 |
|
1378 | self.flagIsNewBlock = 0 | |
1377 |
|
1379 | |||
1378 | if self.__hasNotDataInBuffer(): |
|
1380 | if self.__hasNotDataInBuffer(): | |
1379 |
|
1381 | |||
1380 | if not( self.readNextBlock() ): |
|
1382 | if not( self.readNextBlock() ): | |
1381 | return 0 |
|
1383 | return 0 | |
1382 |
|
1384 | |||
1383 | self.dataOut.dtype = self.dtype |
|
1385 | self.dataOut.dtype = self.dtype | |
1384 |
|
1386 | |||
1385 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
1387 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
1386 |
|
1388 | |||
1387 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1389 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
1388 |
|
1390 | |||
1389 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
1391 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
1390 |
|
1392 | |||
1391 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
1393 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
1392 |
|
1394 | |||
1393 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
1395 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
1394 |
|
1396 | |||
1395 | self.dataOut.ippSeconds = self.ippSeconds |
|
1397 | self.dataOut.ippSeconds = self.ippSeconds | |
1396 |
|
1398 | |||
1397 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt |
|
1399 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |
1398 |
|
1400 | |||
1399 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
1401 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
1400 |
|
1402 | |||
1401 | self.dataOut.flagShiftFFT = False |
|
1403 | self.dataOut.flagShiftFFT = False | |
1402 |
|
1404 | |||
1403 | if self.radarControllerHeaderObj.code != None: |
|
1405 | if self.radarControllerHeaderObj.code != None: | |
1404 |
|
1406 | |||
1405 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
1407 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
1406 |
|
1408 | |||
1407 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
1409 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
1408 |
|
1410 | |||
1409 | self.dataOut.code = self.radarControllerHeaderObj.code |
|
1411 | self.dataOut.code = self.radarControllerHeaderObj.code | |
1410 |
|
1412 | |||
1411 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
1413 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
1412 |
|
1414 | |||
1413 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
1415 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
1414 |
|
1416 | |||
1415 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
1417 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |
1416 |
|
1418 | |||
1417 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip |
|
1419 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip | |
1418 |
|
1420 | |||
1419 | self.dataOut.flagShiftFFT = False |
|
1421 | self.dataOut.flagShiftFFT = False | |
1420 |
|
1422 | |||
1421 |
|
1423 | |||
1422 | # self.updateDataHeader() |
|
1424 | # self.updateDataHeader() | |
1423 |
|
1425 | |||
1424 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
1426 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
1425 |
|
1427 | |||
1426 | if self.datablock == None: |
|
1428 | if self.datablock == None: | |
1427 | self.dataOut.flagNoData = True |
|
1429 | self.dataOut.flagNoData = True | |
1428 | return 0 |
|
1430 | return 0 | |
1429 |
|
1431 | |||
1430 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
1432 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
1431 |
|
1433 | |||
1432 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
1434 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
1433 |
|
1435 | |||
1434 | self.profileIndex += 1 |
|
1436 | self.profileIndex += 1 | |
1435 |
|
1437 | |||
1436 | self.dataOut.flagNoData = False |
|
1438 | self.dataOut.flagNoData = False | |
1437 |
|
1439 | |||
1438 | # print self.profileIndex, self.dataOut.utctime |
|
1440 | # print self.profileIndex, self.dataOut.utctime | |
1439 | # if self.profileIndex == 800: |
|
1441 | # if self.profileIndex == 800: | |
1440 | # a=1 |
|
1442 | # a=1 | |
1441 |
|
1443 | |||
1442 |
|
1444 | |||
1443 | return self.dataOut.data |
|
1445 | return self.dataOut.data | |
1444 |
|
1446 | |||
1445 |
|
1447 | |||
1446 | class VoltageWriter(JRODataWriter): |
|
1448 | class VoltageWriter(JRODataWriter): | |
1447 | """ |
|
1449 | """ | |
1448 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
1450 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
1449 | de los datos siempre se realiza por bloques. |
|
1451 | de los datos siempre se realiza por bloques. | |
1450 | """ |
|
1452 | """ | |
1451 |
|
1453 | |||
1452 | ext = ".r" |
|
1454 | ext = ".r" | |
1453 |
|
1455 | |||
1454 | optchar = "D" |
|
1456 | optchar = "D" | |
1455 |
|
1457 | |||
1456 | shapeBuffer = None |
|
1458 | shapeBuffer = None | |
1457 |
|
1459 | |||
1458 |
|
1460 | |||
1459 | def __init__(self): |
|
1461 | def __init__(self): | |
1460 | """ |
|
1462 | """ | |
1461 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
1463 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
1462 |
|
1464 | |||
1463 | Affected: |
|
1465 | Affected: | |
1464 | self.dataOut |
|
1466 | self.dataOut | |
1465 |
|
1467 | |||
1466 | Return: None |
|
1468 | Return: None | |
1467 | """ |
|
1469 | """ | |
1468 |
|
1470 | |||
1469 | self.nTotalBlocks = 0 |
|
1471 | self.nTotalBlocks = 0 | |
1470 |
|
1472 | |||
1471 | self.profileIndex = 0 |
|
1473 | self.profileIndex = 0 | |
1472 |
|
1474 | |||
1473 | self.isConfig = False |
|
1475 | self.isConfig = False | |
1474 |
|
1476 | |||
1475 | self.fp = None |
|
1477 | self.fp = None | |
1476 |
|
1478 | |||
1477 | self.flagIsNewFile = 1 |
|
1479 | self.flagIsNewFile = 1 | |
1478 |
|
1480 | |||
1479 | self.nTotalBlocks = 0 |
|
1481 | self.nTotalBlocks = 0 | |
1480 |
|
1482 | |||
1481 | self.flagIsNewBlock = 0 |
|
1483 | self.flagIsNewBlock = 0 | |
1482 |
|
1484 | |||
1483 | self.setFile = None |
|
1485 | self.setFile = None | |
1484 |
|
1486 | |||
1485 | self.dtype = None |
|
1487 | self.dtype = None | |
1486 |
|
1488 | |||
1487 | self.path = None |
|
1489 | self.path = None | |
1488 |
|
1490 | |||
1489 | self.filename = None |
|
1491 | self.filename = None | |
1490 |
|
1492 | |||
1491 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1493 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1492 |
|
1494 | |||
1493 | self.systemHeaderObj = SystemHeader() |
|
1495 | self.systemHeaderObj = SystemHeader() | |
1494 |
|
1496 | |||
1495 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1497 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1496 |
|
1498 | |||
1497 | self.processingHeaderObj = ProcessingHeader() |
|
1499 | self.processingHeaderObj = ProcessingHeader() | |
1498 |
|
1500 | |||
1499 | def hasAllDataInBuffer(self): |
|
1501 | def hasAllDataInBuffer(self): | |
1500 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1502 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1501 | return 1 |
|
1503 | return 1 | |
1502 | return 0 |
|
1504 | return 0 | |
1503 |
|
1505 | |||
1504 |
|
1506 | |||
1505 | def setBlockDimension(self): |
|
1507 | def setBlockDimension(self): | |
1506 | """ |
|
1508 | """ | |
1507 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
1509 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
1508 |
|
1510 | |||
1509 | Affected: |
|
1511 | Affected: | |
1510 | self.shape_spc_Buffer |
|
1512 | self.shape_spc_Buffer | |
1511 | self.shape_cspc_Buffer |
|
1513 | self.shape_cspc_Buffer | |
1512 | self.shape_dc_Buffer |
|
1514 | self.shape_dc_Buffer | |
1513 |
|
1515 | |||
1514 | Return: None |
|
1516 | Return: None | |
1515 | """ |
|
1517 | """ | |
1516 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
1518 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
1517 | self.processingHeaderObj.nHeights, |
|
1519 | self.processingHeaderObj.nHeights, | |
1518 | self.systemHeaderObj.nChannels) |
|
1520 | self.systemHeaderObj.nChannels) | |
1519 |
|
1521 | |||
1520 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
1522 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
1521 | self.processingHeaderObj.profilesPerBlock, |
|
1523 | self.processingHeaderObj.profilesPerBlock, | |
1522 | self.processingHeaderObj.nHeights), |
|
1524 | self.processingHeaderObj.nHeights), | |
1523 | dtype=numpy.dtype('complex')) |
|
1525 | dtype=numpy.dtype('complex')) | |
1524 |
|
1526 | |||
1525 |
|
1527 | |||
1526 | def writeBlock(self): |
|
1528 | def writeBlock(self): | |
1527 | """ |
|
1529 | """ | |
1528 | Escribe el buffer en el file designado |
|
1530 | Escribe el buffer en el file designado | |
1529 |
|
1531 | |||
1530 | Affected: |
|
1532 | Affected: | |
1531 | self.profileIndex |
|
1533 | self.profileIndex | |
1532 | self.flagIsNewFile |
|
1534 | self.flagIsNewFile | |
1533 | self.flagIsNewBlock |
|
1535 | self.flagIsNewBlock | |
1534 | self.nTotalBlocks |
|
1536 | self.nTotalBlocks | |
1535 | self.blockIndex |
|
1537 | self.blockIndex | |
1536 |
|
1538 | |||
1537 | Return: None |
|
1539 | Return: None | |
1538 | """ |
|
1540 | """ | |
1539 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
1541 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
1540 |
|
1542 | |||
1541 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
1543 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
1542 |
|
1544 | |||
1543 | data['real'] = junk.real |
|
1545 | data['real'] = junk.real | |
1544 | data['imag'] = junk.imag |
|
1546 | data['imag'] = junk.imag | |
1545 |
|
1547 | |||
1546 | data = data.reshape( (-1) ) |
|
1548 | data = data.reshape( (-1) ) | |
1547 |
|
1549 | |||
1548 | data.tofile( self.fp ) |
|
1550 | data.tofile( self.fp ) | |
1549 |
|
1551 | |||
1550 | self.datablock.fill(0) |
|
1552 | self.datablock.fill(0) | |
1551 |
|
1553 | |||
1552 | self.profileIndex = 0 |
|
1554 | self.profileIndex = 0 | |
1553 | self.flagIsNewFile = 0 |
|
1555 | self.flagIsNewFile = 0 | |
1554 | self.flagIsNewBlock = 1 |
|
1556 | self.flagIsNewBlock = 1 | |
1555 |
|
1557 | |||
1556 | self.blockIndex += 1 |
|
1558 | self.blockIndex += 1 | |
1557 | self.nTotalBlocks += 1 |
|
1559 | self.nTotalBlocks += 1 | |
1558 |
|
1560 | |||
1559 | def putData(self): |
|
1561 | def putData(self): | |
1560 | """ |
|
1562 | """ | |
1561 | Setea un bloque de datos y luego los escribe en un file |
|
1563 | Setea un bloque de datos y luego los escribe en un file | |
1562 |
|
1564 | |||
1563 | Affected: |
|
1565 | Affected: | |
1564 | self.flagIsNewBlock |
|
1566 | self.flagIsNewBlock | |
1565 | self.profileIndex |
|
1567 | self.profileIndex | |
1566 |
|
1568 | |||
1567 | Return: |
|
1569 | Return: | |
1568 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
1570 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
1569 | 1 : Si se escribio la data de un bloque en un file |
|
1571 | 1 : Si se escribio la data de un bloque en un file | |
1570 | """ |
|
1572 | """ | |
1571 | if self.dataOut.flagNoData: |
|
1573 | if self.dataOut.flagNoData: | |
1572 | return 0 |
|
1574 | return 0 | |
1573 |
|
1575 | |||
1574 | self.flagIsNewBlock = 0 |
|
1576 | self.flagIsNewBlock = 0 | |
1575 |
|
1577 | |||
1576 | if self.dataOut.flagTimeBlock: |
|
1578 | if self.dataOut.flagTimeBlock: | |
1577 |
|
1579 | |||
1578 | self.datablock.fill(0) |
|
1580 | self.datablock.fill(0) | |
1579 | self.profileIndex = 0 |
|
1581 | self.profileIndex = 0 | |
1580 | self.setNextFile() |
|
1582 | self.setNextFile() | |
1581 |
|
1583 | |||
1582 | if self.profileIndex == 0: |
|
1584 | if self.profileIndex == 0: | |
1583 | self.getBasicHeader() |
|
1585 | self.getBasicHeader() | |
1584 |
|
1586 | |||
1585 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
1587 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
1586 |
|
1588 | |||
1587 | self.profileIndex += 1 |
|
1589 | self.profileIndex += 1 | |
1588 |
|
1590 | |||
1589 | if self.hasAllDataInBuffer(): |
|
1591 | if self.hasAllDataInBuffer(): | |
1590 | #if self.flagIsNewFile: |
|
1592 | #if self.flagIsNewFile: | |
1591 | self.writeNextBlock() |
|
1593 | self.writeNextBlock() | |
1592 | # self.getDataHeader() |
|
1594 | # self.getDataHeader() | |
1593 |
|
1595 | |||
1594 | return 1 |
|
1596 | return 1 | |
1595 |
|
1597 | |||
1596 | def __getProcessFlags(self): |
|
1598 | def __getProcessFlags(self): | |
1597 |
|
1599 | |||
1598 | processFlags = 0 |
|
1600 | processFlags = 0 | |
1599 |
|
1601 | |||
1600 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1602 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1601 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1603 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1602 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1604 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1603 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1605 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1604 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1606 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1605 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1607 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1606 |
|
1608 | |||
1607 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1609 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1608 |
|
1610 | |||
1609 |
|
1611 | |||
1610 |
|
1612 | |||
1611 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
1613 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
1612 | PROCFLAG.DATATYPE_SHORT, |
|
1614 | PROCFLAG.DATATYPE_SHORT, | |
1613 | PROCFLAG.DATATYPE_LONG, |
|
1615 | PROCFLAG.DATATYPE_LONG, | |
1614 | PROCFLAG.DATATYPE_INT64, |
|
1616 | PROCFLAG.DATATYPE_INT64, | |
1615 | PROCFLAG.DATATYPE_FLOAT, |
|
1617 | PROCFLAG.DATATYPE_FLOAT, | |
1616 | PROCFLAG.DATATYPE_DOUBLE] |
|
1618 | PROCFLAG.DATATYPE_DOUBLE] | |
1617 |
|
1619 | |||
1618 |
|
1620 | |||
1619 | for index in range(len(dtypeList)): |
|
1621 | for index in range(len(dtypeList)): | |
1620 | if self.dataOut.dtype == dtypeList[index]: |
|
1622 | if self.dataOut.dtype == dtypeList[index]: | |
1621 | dtypeValue = datatypeValueList[index] |
|
1623 | dtypeValue = datatypeValueList[index] | |
1622 | break |
|
1624 | break | |
1623 |
|
1625 | |||
1624 | processFlags += dtypeValue |
|
1626 | processFlags += dtypeValue | |
1625 |
|
1627 | |||
1626 | if self.dataOut.flagDecodeData: |
|
1628 | if self.dataOut.flagDecodeData: | |
1627 | processFlags += PROCFLAG.DECODE_DATA |
|
1629 | processFlags += PROCFLAG.DECODE_DATA | |
1628 |
|
1630 | |||
1629 | if self.dataOut.flagDeflipData: |
|
1631 | if self.dataOut.flagDeflipData: | |
1630 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1632 | processFlags += PROCFLAG.DEFLIP_DATA | |
1631 |
|
1633 | |||
1632 | if self.dataOut.code != None: |
|
1634 | if self.dataOut.code != None: | |
1633 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1635 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
1634 |
|
1636 | |||
1635 | if self.dataOut.nCohInt > 1: |
|
1637 | if self.dataOut.nCohInt > 1: | |
1636 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1638 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
1637 |
|
1639 | |||
1638 | return processFlags |
|
1640 | return processFlags | |
1639 |
|
1641 | |||
1640 |
|
1642 | |||
1641 | def __getBlockSize(self): |
|
1643 | def __getBlockSize(self): | |
1642 | ''' |
|
1644 | ''' | |
1643 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
1645 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
1644 | ''' |
|
1646 | ''' | |
1645 |
|
1647 | |||
1646 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1648 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1647 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1649 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1648 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1650 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1649 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1651 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1650 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1652 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1651 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1653 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1652 |
|
1654 | |||
1653 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1655 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1654 | datatypeValueList = [1,2,4,8,4,8] |
|
1656 | datatypeValueList = [1,2,4,8,4,8] | |
1655 | for index in range(len(dtypeList)): |
|
1657 | for index in range(len(dtypeList)): | |
1656 | if self.dataOut.dtype == dtypeList[index]: |
|
1658 | if self.dataOut.dtype == dtypeList[index]: | |
1657 | datatypeValue = datatypeValueList[index] |
|
1659 | datatypeValue = datatypeValueList[index] | |
1658 | break |
|
1660 | break | |
1659 |
|
1661 | |||
1660 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) |
|
1662 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) | |
1661 |
|
1663 | |||
1662 | return blocksize |
|
1664 | return blocksize | |
1663 |
|
1665 | |||
1664 | def getDataHeader(self): |
|
1666 | def getDataHeader(self): | |
1665 |
|
1667 | |||
1666 | """ |
|
1668 | """ | |
1667 | Obtiene una copia del First Header |
|
1669 | Obtiene una copia del First Header | |
1668 |
|
1670 | |||
1669 | Affected: |
|
1671 | Affected: | |
1670 | self.systemHeaderObj |
|
1672 | self.systemHeaderObj | |
1671 | self.radarControllerHeaderObj |
|
1673 | self.radarControllerHeaderObj | |
1672 | self.dtype |
|
1674 | self.dtype | |
1673 |
|
1675 | |||
1674 | Return: |
|
1676 | Return: | |
1675 | None |
|
1677 | None | |
1676 | """ |
|
1678 | """ | |
1677 |
|
1679 | |||
1678 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
1680 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
1679 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
1681 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
1680 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
1682 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
1681 |
|
1683 | |||
1682 | self.getBasicHeader() |
|
1684 | self.getBasicHeader() | |
1683 |
|
1685 | |||
1684 | processingHeaderSize = 40 # bytes |
|
1686 | processingHeaderSize = 40 # bytes | |
1685 | self.processingHeaderObj.dtype = 0 # Voltage |
|
1687 | self.processingHeaderObj.dtype = 0 # Voltage | |
1686 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
1688 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
1687 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
1689 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
1688 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
1690 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
1689 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
1691 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
1690 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
1692 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
1691 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
1693 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
1692 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
1694 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
1693 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
1695 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
1694 |
|
1696 | |||
1695 | if self.dataOut.code != None: |
|
1697 | if self.dataOut.code != None: | |
1696 | self.processingHeaderObj.code = self.dataOut.code |
|
1698 | self.processingHeaderObj.code = self.dataOut.code | |
1697 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
1699 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
1698 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
1700 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
1699 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
1701 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) | |
1700 | processingHeaderSize += codesize |
|
1702 | processingHeaderSize += codesize | |
1701 |
|
1703 | |||
1702 | if self.processingHeaderObj.nWindows != 0: |
|
1704 | if self.processingHeaderObj.nWindows != 0: | |
1703 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
1705 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
1704 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
1706 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
1705 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
1707 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
1706 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
1708 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
1707 | processingHeaderSize += 12 |
|
1709 | processingHeaderSize += 12 | |
1708 |
|
1710 | |||
1709 | self.processingHeaderObj.size = processingHeaderSize |
|
1711 | self.processingHeaderObj.size = processingHeaderSize | |
1710 |
|
1712 | |||
1711 | class SpectraReader(JRODataReader): |
|
1713 | class SpectraReader(JRODataReader): | |
1712 | """ |
|
1714 | """ | |
1713 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
1715 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
1714 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
1716 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
1715 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
1717 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
1716 |
|
1718 | |||
1717 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
1719 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
1718 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
1720 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
1719 | canales * alturas (DC Channels) |
|
1721 | canales * alturas (DC Channels) | |
1720 |
|
1722 | |||
1721 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1723 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1722 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
1724 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
1723 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
1725 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
1724 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1726 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1725 |
|
1727 | |||
1726 | Example: |
|
1728 | Example: | |
1727 | dpath = "/home/myuser/data" |
|
1729 | dpath = "/home/myuser/data" | |
1728 |
|
1730 | |||
1729 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1731 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1730 |
|
1732 | |||
1731 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1733 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1732 |
|
1734 | |||
1733 | readerObj = SpectraReader() |
|
1735 | readerObj = SpectraReader() | |
1734 |
|
1736 | |||
1735 | readerObj.setup(dpath, startTime, endTime) |
|
1737 | readerObj.setup(dpath, startTime, endTime) | |
1736 |
|
1738 | |||
1737 | while(True): |
|
1739 | while(True): | |
1738 |
|
1740 | |||
1739 | readerObj.getData() |
|
1741 | readerObj.getData() | |
1740 |
|
1742 | |||
1741 | print readerObj.data_spc |
|
1743 | print readerObj.data_spc | |
1742 |
|
1744 | |||
1743 | print readerObj.data_cspc |
|
1745 | print readerObj.data_cspc | |
1744 |
|
1746 | |||
1745 | print readerObj.data_dc |
|
1747 | print readerObj.data_dc | |
1746 |
|
1748 | |||
1747 | if readerObj.flagNoMoreFiles: |
|
1749 | if readerObj.flagNoMoreFiles: | |
1748 | break |
|
1750 | break | |
1749 |
|
1751 | |||
1750 | """ |
|
1752 | """ | |
1751 |
|
1753 | |||
1752 | pts2read_SelfSpectra = 0 |
|
1754 | pts2read_SelfSpectra = 0 | |
1753 |
|
1755 | |||
1754 | pts2read_CrossSpectra = 0 |
|
1756 | pts2read_CrossSpectra = 0 | |
1755 |
|
1757 | |||
1756 | pts2read_DCchannels = 0 |
|
1758 | pts2read_DCchannels = 0 | |
1757 |
|
1759 | |||
1758 | ext = ".pdata" |
|
1760 | ext = ".pdata" | |
1759 |
|
1761 | |||
1760 | optchar = "P" |
|
1762 | optchar = "P" | |
1761 |
|
1763 | |||
1762 | dataOut = None |
|
1764 | dataOut = None | |
1763 |
|
1765 | |||
1764 | nRdChannels = None |
|
1766 | nRdChannels = None | |
1765 |
|
1767 | |||
1766 | nRdPairs = None |
|
1768 | nRdPairs = None | |
1767 |
|
1769 | |||
1768 | rdPairList = [] |
|
1770 | rdPairList = [] | |
1769 |
|
1771 | |||
1770 |
|
1772 | |||
1771 | def __init__(self): |
|
1773 | def __init__(self): | |
1772 | """ |
|
1774 | """ | |
1773 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
1775 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
1774 |
|
1776 | |||
1775 | Inputs: |
|
1777 | Inputs: | |
1776 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
1778 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para | |
1777 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1779 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1778 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1780 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1779 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1781 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1780 | bloque de datos. |
|
1782 | bloque de datos. | |
1781 | Si este parametro no es pasado se creara uno internamente. |
|
1783 | Si este parametro no es pasado se creara uno internamente. | |
1782 |
|
1784 | |||
1783 | Affected: |
|
1785 | Affected: | |
1784 | self.dataOut |
|
1786 | self.dataOut | |
1785 |
|
1787 | |||
1786 | Return : None |
|
1788 | Return : None | |
1787 | """ |
|
1789 | """ | |
1788 |
|
1790 | |||
1789 | self.isConfig = False |
|
1791 | self.isConfig = False | |
1790 |
|
1792 | |||
1791 | self.pts2read_SelfSpectra = 0 |
|
1793 | self.pts2read_SelfSpectra = 0 | |
1792 |
|
1794 | |||
1793 | self.pts2read_CrossSpectra = 0 |
|
1795 | self.pts2read_CrossSpectra = 0 | |
1794 |
|
1796 | |||
1795 | self.pts2read_DCchannels = 0 |
|
1797 | self.pts2read_DCchannels = 0 | |
1796 |
|
1798 | |||
1797 | self.datablock = None |
|
1799 | self.datablock = None | |
1798 |
|
1800 | |||
1799 | self.utc = None |
|
1801 | self.utc = None | |
1800 |
|
1802 | |||
1801 | self.ext = ".pdata" |
|
1803 | self.ext = ".pdata" | |
1802 |
|
1804 | |||
1803 | self.optchar = "P" |
|
1805 | self.optchar = "P" | |
1804 |
|
1806 | |||
1805 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1807 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1806 |
|
1808 | |||
1807 | self.systemHeaderObj = SystemHeader() |
|
1809 | self.systemHeaderObj = SystemHeader() | |
1808 |
|
1810 | |||
1809 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1811 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1810 |
|
1812 | |||
1811 | self.processingHeaderObj = ProcessingHeader() |
|
1813 | self.processingHeaderObj = ProcessingHeader() | |
1812 |
|
1814 | |||
1813 | self.online = 0 |
|
1815 | self.online = 0 | |
1814 |
|
1816 | |||
1815 | self.fp = None |
|
1817 | self.fp = None | |
1816 |
|
1818 | |||
1817 | self.idFile = None |
|
1819 | self.idFile = None | |
1818 |
|
1820 | |||
1819 | self.dtype = None |
|
1821 | self.dtype = None | |
1820 |
|
1822 | |||
1821 | self.fileSizeByHeader = None |
|
1823 | self.fileSizeByHeader = None | |
1822 |
|
1824 | |||
1823 | self.filenameList = [] |
|
1825 | self.filenameList = [] | |
1824 |
|
1826 | |||
1825 | self.filename = None |
|
1827 | self.filename = None | |
1826 |
|
1828 | |||
1827 | self.fileSize = None |
|
1829 | self.fileSize = None | |
1828 |
|
1830 | |||
1829 | self.firstHeaderSize = 0 |
|
1831 | self.firstHeaderSize = 0 | |
1830 |
|
1832 | |||
1831 | self.basicHeaderSize = 24 |
|
1833 | self.basicHeaderSize = 24 | |
1832 |
|
1834 | |||
1833 | self.pathList = [] |
|
1835 | self.pathList = [] | |
1834 |
|
1836 | |||
1835 | self.lastUTTime = 0 |
|
1837 | self.lastUTTime = 0 | |
1836 |
|
1838 | |||
1837 | self.maxTimeStep = 30 |
|
1839 | self.maxTimeStep = 30 | |
1838 |
|
1840 | |||
1839 | self.flagNoMoreFiles = 0 |
|
1841 | self.flagNoMoreFiles = 0 | |
1840 |
|
1842 | |||
1841 | self.set = 0 |
|
1843 | self.set = 0 | |
1842 |
|
1844 | |||
1843 | self.path = None |
|
1845 | self.path = None | |
1844 |
|
1846 | |||
1845 | self.delay = 3 #seconds |
|
1847 | self.delay = 3 #seconds | |
1846 |
|
1848 | |||
1847 | self.nTries = 3 #quantity tries |
|
1849 | self.nTries = 3 #quantity tries | |
1848 |
|
1850 | |||
1849 | self.nFiles = 3 #number of files for searching |
|
1851 | self.nFiles = 3 #number of files for searching | |
1850 |
|
1852 | |||
1851 | self.nReadBlocks = 0 |
|
1853 | self.nReadBlocks = 0 | |
1852 |
|
1854 | |||
1853 | self.flagIsNewFile = 1 |
|
1855 | self.flagIsNewFile = 1 | |
1854 |
|
1856 | |||
1855 | self.ippSeconds = 0 |
|
1857 | self.ippSeconds = 0 | |
1856 |
|
1858 | |||
1857 | self.flagTimeBlock = 0 |
|
1859 | self.flagTimeBlock = 0 | |
1858 |
|
1860 | |||
1859 | self.flagIsNewBlock = 0 |
|
1861 | self.flagIsNewBlock = 0 | |
1860 |
|
1862 | |||
1861 | self.nTotalBlocks = 0 |
|
1863 | self.nTotalBlocks = 0 | |
1862 |
|
1864 | |||
1863 | self.blocksize = 0 |
|
1865 | self.blocksize = 0 | |
1864 |
|
1866 | |||
1865 | self.dataOut = self.createObjByDefault() |
|
1867 | self.dataOut = self.createObjByDefault() | |
1866 |
|
1868 | |||
1867 |
|
1869 | |||
1868 | def createObjByDefault(self): |
|
1870 | def createObjByDefault(self): | |
1869 |
|
1871 | |||
1870 | dataObj = Spectra() |
|
1872 | dataObj = Spectra() | |
1871 |
|
1873 | |||
1872 | return dataObj |
|
1874 | return dataObj | |
1873 |
|
1875 | |||
1874 | def __hasNotDataInBuffer(self): |
|
1876 | def __hasNotDataInBuffer(self): | |
1875 | return 1 |
|
1877 | return 1 | |
1876 |
|
1878 | |||
1877 |
|
1879 | |||
1878 | def getBlockDimension(self): |
|
1880 | def getBlockDimension(self): | |
1879 | """ |
|
1881 | """ | |
1880 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1882 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1881 |
|
1883 | |||
1882 | Affected: |
|
1884 | Affected: | |
1883 | self.nRdChannels |
|
1885 | self.nRdChannels | |
1884 | self.nRdPairs |
|
1886 | self.nRdPairs | |
1885 | self.pts2read_SelfSpectra |
|
1887 | self.pts2read_SelfSpectra | |
1886 | self.pts2read_CrossSpectra |
|
1888 | self.pts2read_CrossSpectra | |
1887 | self.pts2read_DCchannels |
|
1889 | self.pts2read_DCchannels | |
1888 | self.blocksize |
|
1890 | self.blocksize | |
1889 | self.dataOut.nChannels |
|
1891 | self.dataOut.nChannels | |
1890 | self.dataOut.nPairs |
|
1892 | self.dataOut.nPairs | |
1891 |
|
1893 | |||
1892 | Return: |
|
1894 | Return: | |
1893 | None |
|
1895 | None | |
1894 | """ |
|
1896 | """ | |
1895 | self.nRdChannels = 0 |
|
1897 | self.nRdChannels = 0 | |
1896 | self.nRdPairs = 0 |
|
1898 | self.nRdPairs = 0 | |
1897 | self.rdPairList = [] |
|
1899 | self.rdPairList = [] | |
1898 |
|
1900 | |||
1899 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
1901 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
1900 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
1902 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
1901 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
1903 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
1902 | else: |
|
1904 | else: | |
1903 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
1905 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
1904 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
1906 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
1905 |
|
1907 | |||
1906 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
1908 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
1907 |
|
1909 | |||
1908 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
1910 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
1909 | self.blocksize = self.pts2read_SelfSpectra |
|
1911 | self.blocksize = self.pts2read_SelfSpectra | |
1910 |
|
1912 | |||
1911 | if self.processingHeaderObj.flag_cspc: |
|
1913 | if self.processingHeaderObj.flag_cspc: | |
1912 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
1914 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
1913 | self.blocksize += self.pts2read_CrossSpectra |
|
1915 | self.blocksize += self.pts2read_CrossSpectra | |
1914 |
|
1916 | |||
1915 | if self.processingHeaderObj.flag_dc: |
|
1917 | if self.processingHeaderObj.flag_dc: | |
1916 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
1918 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
1917 | self.blocksize += self.pts2read_DCchannels |
|
1919 | self.blocksize += self.pts2read_DCchannels | |
1918 |
|
1920 | |||
1919 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
1921 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
1920 |
|
1922 | |||
1921 |
|
1923 | |||
1922 | def readBlock(self): |
|
1924 | def readBlock(self): | |
1923 | """ |
|
1925 | """ | |
1924 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1926 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
1925 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1927 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1926 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1928 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1927 | es seteado a 0 |
|
1929 | es seteado a 0 | |
1928 |
|
1930 | |||
1929 | Return: None |
|
1931 | Return: None | |
1930 |
|
1932 | |||
1931 | Variables afectadas: |
|
1933 | Variables afectadas: | |
1932 |
|
1934 | |||
1933 | self.flagIsNewFile |
|
1935 | self.flagIsNewFile | |
1934 | self.flagIsNewBlock |
|
1936 | self.flagIsNewBlock | |
1935 | self.nTotalBlocks |
|
1937 | self.nTotalBlocks | |
1936 | self.data_spc |
|
1938 | self.data_spc | |
1937 | self.data_cspc |
|
1939 | self.data_cspc | |
1938 | self.data_dc |
|
1940 | self.data_dc | |
1939 |
|
1941 | |||
1940 | Exceptions: |
|
1942 | Exceptions: | |
1941 | Si un bloque leido no es un bloque valido |
|
1943 | Si un bloque leido no es un bloque valido | |
1942 | """ |
|
1944 | """ | |
1943 | blockOk_flag = False |
|
1945 | blockOk_flag = False | |
1944 | fpointer = self.fp.tell() |
|
1946 | fpointer = self.fp.tell() | |
1945 |
|
1947 | |||
1946 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
1948 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
1947 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
1949 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
1948 |
|
1950 | |||
1949 | if self.processingHeaderObj.flag_cspc: |
|
1951 | if self.processingHeaderObj.flag_cspc: | |
1950 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
1952 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
1951 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
1953 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
1952 |
|
1954 | |||
1953 | if self.processingHeaderObj.flag_dc: |
|
1955 | if self.processingHeaderObj.flag_dc: | |
1954 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
1956 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
1955 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
1957 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
1956 |
|
1958 | |||
1957 |
|
1959 | |||
1958 | if not(self.processingHeaderObj.shif_fft): |
|
1960 | if not(self.processingHeaderObj.shif_fft): | |
1959 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
1961 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
1960 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
1962 | shift = int(self.processingHeaderObj.profilesPerBlock/2) | |
1961 | spc = numpy.roll( spc, shift , axis=2 ) |
|
1963 | spc = numpy.roll( spc, shift , axis=2 ) | |
1962 |
|
1964 | |||
1963 | if self.processingHeaderObj.flag_cspc: |
|
1965 | if self.processingHeaderObj.flag_cspc: | |
1964 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
1966 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
1965 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
1967 | cspc = numpy.roll( cspc, shift, axis=2 ) | |
1966 |
|
1968 | |||
1967 |
|
1969 | |||
1968 | spc = numpy.transpose( spc, (0,2,1) ) |
|
1970 | spc = numpy.transpose( spc, (0,2,1) ) | |
1969 | self.data_spc = spc |
|
1971 | self.data_spc = spc | |
1970 |
|
1972 | |||
1971 | if self.processingHeaderObj.flag_cspc: |
|
1973 | if self.processingHeaderObj.flag_cspc: | |
1972 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
1974 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
1973 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
1975 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
1974 | else: |
|
1976 | else: | |
1975 | self.data_cspc = None |
|
1977 | self.data_cspc = None | |
1976 |
|
1978 | |||
1977 | if self.processingHeaderObj.flag_dc: |
|
1979 | if self.processingHeaderObj.flag_dc: | |
1978 | self.data_dc = dc['real'] + dc['imag']*1j |
|
1980 | self.data_dc = dc['real'] + dc['imag']*1j | |
1979 | else: |
|
1981 | else: | |
1980 | self.data_dc = None |
|
1982 | self.data_dc = None | |
1981 |
|
1983 | |||
1982 | self.flagIsNewFile = 0 |
|
1984 | self.flagIsNewFile = 0 | |
1983 | self.flagIsNewBlock = 1 |
|
1985 | self.flagIsNewBlock = 1 | |
1984 |
|
1986 | |||
1985 | self.nTotalBlocks += 1 |
|
1987 | self.nTotalBlocks += 1 | |
1986 | self.nReadBlocks += 1 |
|
1988 | self.nReadBlocks += 1 | |
1987 |
|
1989 | |||
1988 | return 1 |
|
1990 | return 1 | |
1989 |
|
1991 | |||
1990 |
|
1992 | |||
1991 | def getData(self): |
|
1993 | def getData(self): | |
1992 | """ |
|
1994 | """ | |
1993 | Copia el buffer de lectura a la clase "Spectra", |
|
1995 | Copia el buffer de lectura a la clase "Spectra", | |
1994 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1996 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1995 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1997 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1996 |
|
1998 | |||
1997 | Return: |
|
1999 | Return: | |
1998 | 0 : Si no hay mas archivos disponibles |
|
2000 | 0 : Si no hay mas archivos disponibles | |
1999 | 1 : Si hizo una buena copia del buffer |
|
2001 | 1 : Si hizo una buena copia del buffer | |
2000 |
|
2002 | |||
2001 | Affected: |
|
2003 | Affected: | |
2002 | self.dataOut |
|
2004 | self.dataOut | |
2003 |
|
2005 | |||
2004 | self.flagTimeBlock |
|
2006 | self.flagTimeBlock | |
2005 | self.flagIsNewBlock |
|
2007 | self.flagIsNewBlock | |
2006 | """ |
|
2008 | """ | |
2007 |
|
2009 | |||
2008 | if self.flagNoMoreFiles: |
|
2010 | if self.flagNoMoreFiles: | |
2009 | self.dataOut.flagNoData = True |
|
2011 | self.dataOut.flagNoData = True | |
2010 | print 'Process finished' |
|
2012 | print 'Process finished' | |
2011 | return 0 |
|
2013 | return 0 | |
2012 |
|
2014 | |||
2013 | self.flagTimeBlock = 0 |
|
2015 | self.flagTimeBlock = 0 | |
2014 | self.flagIsNewBlock = 0 |
|
2016 | self.flagIsNewBlock = 0 | |
2015 |
|
2017 | |||
2016 | if self.__hasNotDataInBuffer(): |
|
2018 | if self.__hasNotDataInBuffer(): | |
2017 |
|
2019 | |||
2018 | if not( self.readNextBlock() ): |
|
2020 | if not( self.readNextBlock() ): | |
2019 | self.dataOut.flagNoData = True |
|
2021 | self.dataOut.flagNoData = True | |
2020 | return 0 |
|
2022 | return 0 | |
2021 |
|
2023 | |||
2022 | # self.updateDataHeader() |
|
2024 | # self.updateDataHeader() | |
2023 |
|
2025 | |||
2024 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
2026 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
2025 |
|
2027 | |||
2026 | if self.data_dc == None: |
|
2028 | if self.data_dc == None: | |
2027 | self.dataOut.flagNoData = True |
|
2029 | self.dataOut.flagNoData = True | |
2028 | return 0 |
|
2030 | return 0 | |
2029 |
|
2031 | |||
2030 | self.dataOut.data_spc = self.data_spc |
|
2032 | self.dataOut.data_spc = self.data_spc | |
2031 |
|
2033 | |||
2032 | self.dataOut.data_cspc = self.data_cspc |
|
2034 | self.dataOut.data_cspc = self.data_cspc | |
2033 |
|
2035 | |||
2034 | self.dataOut.data_dc = self.data_dc |
|
2036 | self.dataOut.data_dc = self.data_dc | |
2035 |
|
2037 | |||
2036 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
2038 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
2037 |
|
2039 | |||
2038 | self.dataOut.flagNoData = False |
|
2040 | self.dataOut.flagNoData = False | |
2039 |
|
2041 | |||
2040 | self.dataOut.dtype = self.dtype |
|
2042 | self.dataOut.dtype = self.dtype | |
2041 |
|
2043 | |||
2042 | # self.dataOut.nChannels = self.nRdChannels |
|
2044 | # self.dataOut.nChannels = self.nRdChannels | |
2043 |
|
2045 | |||
2044 | self.dataOut.nPairs = self.nRdPairs |
|
2046 | self.dataOut.nPairs = self.nRdPairs | |
2045 |
|
2047 | |||
2046 | self.dataOut.pairsList = self.rdPairList |
|
2048 | self.dataOut.pairsList = self.rdPairList | |
2047 |
|
2049 | |||
2048 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights |
|
2050 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights | |
2049 |
|
2051 | |||
2050 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
2052 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
2051 |
|
2053 | |||
2052 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
2054 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
2053 |
|
2055 | |||
2054 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
2056 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
2055 |
|
2057 | |||
2056 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
2058 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |
2057 |
|
2059 | |||
2058 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
2060 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
2059 |
|
2061 | |||
2060 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
2062 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
2061 |
|
2063 | |||
2062 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
2064 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
2063 |
|
2065 | |||
2064 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
2066 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) | |
2065 |
|
2067 | |||
2066 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds |
|
2068 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds | |
2067 |
|
2069 | |||
2068 | self.dataOut.ippSeconds = self.ippSeconds |
|
2070 | self.dataOut.ippSeconds = self.ippSeconds | |
2069 |
|
2071 | |||
2070 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints |
|
2072 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints | |
2071 |
|
2073 | |||
2072 | # self.profileIndex += 1 |
|
2074 | # self.profileIndex += 1 | |
2073 |
|
2075 | |||
2074 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
2076 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
2075 |
|
2077 | |||
2076 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
2078 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
2077 |
|
2079 | |||
2078 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
2080 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
2079 |
|
2081 | |||
2080 |
self.dataOut.flagDecodeData = |
|
2082 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |
2081 |
|
2083 | |||
2082 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
2084 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
2083 |
|
|
2085 | ||
|
2086 | if self.processingHeaderObj.code != None: | |||
|
2087 | ||||
|
2088 | self.dataOut.nCode = self.processingHeaderObj.nCode | |||
|
2089 | ||||
|
2090 | self.dataOut.nBaud = self.processingHeaderObj.nBaud | |||
|
2091 | ||||
|
2092 | self.dataOut.code = self.processingHeaderObj.code | |||
|
2093 | ||||
|
2094 | self.dataOut.flagDecodeData = True | |||
2084 |
|
2095 | |||
2085 | return self.dataOut.data_spc |
|
2096 | return self.dataOut.data_spc | |
2086 |
|
2097 | |||
2087 |
|
2098 | |||
2088 | class SpectraWriter(JRODataWriter): |
|
2099 | class SpectraWriter(JRODataWriter): | |
2089 |
|
2100 | |||
2090 | """ |
|
2101 | """ | |
2091 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
2102 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
2092 | de los datos siempre se realiza por bloques. |
|
2103 | de los datos siempre se realiza por bloques. | |
2093 | """ |
|
2104 | """ | |
2094 |
|
2105 | |||
2095 | ext = ".pdata" |
|
2106 | ext = ".pdata" | |
2096 |
|
2107 | |||
2097 | optchar = "P" |
|
2108 | optchar = "P" | |
2098 |
|
2109 | |||
2099 | shape_spc_Buffer = None |
|
2110 | shape_spc_Buffer = None | |
2100 |
|
2111 | |||
2101 | shape_cspc_Buffer = None |
|
2112 | shape_cspc_Buffer = None | |
2102 |
|
2113 | |||
2103 | shape_dc_Buffer = None |
|
2114 | shape_dc_Buffer = None | |
2104 |
|
2115 | |||
2105 | data_spc = None |
|
2116 | data_spc = None | |
2106 |
|
2117 | |||
2107 | data_cspc = None |
|
2118 | data_cspc = None | |
2108 |
|
2119 | |||
2109 | data_dc = None |
|
2120 | data_dc = None | |
2110 |
|
2121 | |||
2111 | # dataOut = None |
|
2122 | # dataOut = None | |
2112 |
|
2123 | |||
2113 | def __init__(self): |
|
2124 | def __init__(self): | |
2114 | """ |
|
2125 | """ | |
2115 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
2126 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
2116 |
|
2127 | |||
2117 | Affected: |
|
2128 | Affected: | |
2118 | self.dataOut |
|
2129 | self.dataOut | |
2119 | self.basicHeaderObj |
|
2130 | self.basicHeaderObj | |
2120 | self.systemHeaderObj |
|
2131 | self.systemHeaderObj | |
2121 | self.radarControllerHeaderObj |
|
2132 | self.radarControllerHeaderObj | |
2122 | self.processingHeaderObj |
|
2133 | self.processingHeaderObj | |
2123 |
|
2134 | |||
2124 | Return: None |
|
2135 | Return: None | |
2125 | """ |
|
2136 | """ | |
2126 |
|
2137 | |||
2127 | self.isConfig = False |
|
2138 | self.isConfig = False | |
2128 |
|
2139 | |||
2129 | self.nTotalBlocks = 0 |
|
2140 | self.nTotalBlocks = 0 | |
2130 |
|
2141 | |||
2131 | self.data_spc = None |
|
2142 | self.data_spc = None | |
2132 |
|
2143 | |||
2133 | self.data_cspc = None |
|
2144 | self.data_cspc = None | |
2134 |
|
2145 | |||
2135 | self.data_dc = None |
|
2146 | self.data_dc = None | |
2136 |
|
2147 | |||
2137 | self.fp = None |
|
2148 | self.fp = None | |
2138 |
|
2149 | |||
2139 | self.flagIsNewFile = 1 |
|
2150 | self.flagIsNewFile = 1 | |
2140 |
|
2151 | |||
2141 | self.nTotalBlocks = 0 |
|
2152 | self.nTotalBlocks = 0 | |
2142 |
|
2153 | |||
2143 | self.flagIsNewBlock = 0 |
|
2154 | self.flagIsNewBlock = 0 | |
2144 |
|
2155 | |||
2145 | self.setFile = None |
|
2156 | self.setFile = None | |
2146 |
|
2157 | |||
2147 | self.dtype = None |
|
2158 | self.dtype = None | |
2148 |
|
2159 | |||
2149 | self.path = None |
|
2160 | self.path = None | |
2150 |
|
2161 | |||
2151 | self.noMoreFiles = 0 |
|
2162 | self.noMoreFiles = 0 | |
2152 |
|
2163 | |||
2153 | self.filename = None |
|
2164 | self.filename = None | |
2154 |
|
2165 | |||
2155 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
2166 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
2156 |
|
2167 | |||
2157 | self.systemHeaderObj = SystemHeader() |
|
2168 | self.systemHeaderObj = SystemHeader() | |
2158 |
|
2169 | |||
2159 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2170 | self.radarControllerHeaderObj = RadarControllerHeader() | |
2160 |
|
2171 | |||
2161 | self.processingHeaderObj = ProcessingHeader() |
|
2172 | self.processingHeaderObj = ProcessingHeader() | |
2162 |
|
2173 | |||
2163 |
|
2174 | |||
2164 | def hasAllDataInBuffer(self): |
|
2175 | def hasAllDataInBuffer(self): | |
2165 | return 1 |
|
2176 | return 1 | |
2166 |
|
2177 | |||
2167 |
|
2178 | |||
2168 | def setBlockDimension(self): |
|
2179 | def setBlockDimension(self): | |
2169 | """ |
|
2180 | """ | |
2170 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
2181 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
2171 |
|
2182 | |||
2172 | Affected: |
|
2183 | Affected: | |
2173 | self.shape_spc_Buffer |
|
2184 | self.shape_spc_Buffer | |
2174 | self.shape_cspc_Buffer |
|
2185 | self.shape_cspc_Buffer | |
2175 | self.shape_dc_Buffer |
|
2186 | self.shape_dc_Buffer | |
2176 |
|
2187 | |||
2177 | Return: None |
|
2188 | Return: None | |
2178 | """ |
|
2189 | """ | |
2179 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
2190 | self.shape_spc_Buffer = (self.dataOut.nChannels, | |
2180 | self.processingHeaderObj.nHeights, |
|
2191 | self.processingHeaderObj.nHeights, | |
2181 | self.processingHeaderObj.profilesPerBlock) |
|
2192 | self.processingHeaderObj.profilesPerBlock) | |
2182 |
|
2193 | |||
2183 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
2194 | self.shape_cspc_Buffer = (self.dataOut.nPairs, | |
2184 | self.processingHeaderObj.nHeights, |
|
2195 | self.processingHeaderObj.nHeights, | |
2185 | self.processingHeaderObj.profilesPerBlock) |
|
2196 | self.processingHeaderObj.profilesPerBlock) | |
2186 |
|
2197 | |||
2187 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
2198 | self.shape_dc_Buffer = (self.dataOut.nChannels, | |
2188 | self.processingHeaderObj.nHeights) |
|
2199 | self.processingHeaderObj.nHeights) | |
2189 |
|
2200 | |||
2190 |
|
2201 | |||
2191 | def writeBlock(self): |
|
2202 | def writeBlock(self): | |
2192 | """ |
|
2203 | """ | |
2193 | Escribe el buffer en el file designado |
|
2204 | Escribe el buffer en el file designado | |
2194 |
|
2205 | |||
2195 | Affected: |
|
2206 | Affected: | |
2196 | self.data_spc |
|
2207 | self.data_spc | |
2197 | self.data_cspc |
|
2208 | self.data_cspc | |
2198 | self.data_dc |
|
2209 | self.data_dc | |
2199 | self.flagIsNewFile |
|
2210 | self.flagIsNewFile | |
2200 | self.flagIsNewBlock |
|
2211 | self.flagIsNewBlock | |
2201 | self.nTotalBlocks |
|
2212 | self.nTotalBlocks | |
2202 | self.nWriteBlocks |
|
2213 | self.nWriteBlocks | |
2203 |
|
2214 | |||
2204 | Return: None |
|
2215 | Return: None | |
2205 | """ |
|
2216 | """ | |
2206 |
|
2217 | |||
2207 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
2218 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
2208 | if not( self.processingHeaderObj.shif_fft ): |
|
2219 | if not( self.processingHeaderObj.shif_fft ): | |
2209 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2220 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2210 | data = spc.reshape((-1)) |
|
2221 | data = spc.reshape((-1)) | |
2211 | data.tofile(self.fp) |
|
2222 | data.tofile(self.fp) | |
2212 |
|
2223 | |||
2213 | if self.data_cspc != None: |
|
2224 | if self.data_cspc != None: | |
2214 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
2225 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
2215 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
2226 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
2216 | if not( self.processingHeaderObj.shif_fft ): |
|
2227 | if not( self.processingHeaderObj.shif_fft ): | |
2217 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2228 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2218 | data['real'] = cspc.real |
|
2229 | data['real'] = cspc.real | |
2219 | data['imag'] = cspc.imag |
|
2230 | data['imag'] = cspc.imag | |
2220 | data = data.reshape((-1)) |
|
2231 | data = data.reshape((-1)) | |
2221 | data.tofile(self.fp) |
|
2232 | data.tofile(self.fp) | |
2222 |
|
2233 | |||
2223 | if self.data_dc != None: |
|
2234 | if self.data_dc != None: | |
2224 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
2235 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
2225 | dc = self.data_dc |
|
2236 | dc = self.data_dc | |
2226 | data['real'] = dc.real |
|
2237 | data['real'] = dc.real | |
2227 | data['imag'] = dc.imag |
|
2238 | data['imag'] = dc.imag | |
2228 | data = data.reshape((-1)) |
|
2239 | data = data.reshape((-1)) | |
2229 | data.tofile(self.fp) |
|
2240 | data.tofile(self.fp) | |
2230 |
|
2241 | |||
2231 | self.data_spc.fill(0) |
|
2242 | self.data_spc.fill(0) | |
2232 | self.data_dc.fill(0) |
|
2243 | self.data_dc.fill(0) | |
2233 | if self.data_cspc != None: |
|
2244 | if self.data_cspc != None: | |
2234 | self.data_cspc.fill(0) |
|
2245 | self.data_cspc.fill(0) | |
2235 |
|
2246 | |||
2236 | self.flagIsNewFile = 0 |
|
2247 | self.flagIsNewFile = 0 | |
2237 | self.flagIsNewBlock = 1 |
|
2248 | self.flagIsNewBlock = 1 | |
2238 | self.nTotalBlocks += 1 |
|
2249 | self.nTotalBlocks += 1 | |
2239 | self.nWriteBlocks += 1 |
|
2250 | self.nWriteBlocks += 1 | |
2240 | self.blockIndex += 1 |
|
2251 | self.blockIndex += 1 | |
2241 |
|
2252 | |||
2242 |
|
2253 | |||
2243 | def putData(self): |
|
2254 | def putData(self): | |
2244 | """ |
|
2255 | """ | |
2245 | Setea un bloque de datos y luego los escribe en un file |
|
2256 | Setea un bloque de datos y luego los escribe en un file | |
2246 |
|
2257 | |||
2247 | Affected: |
|
2258 | Affected: | |
2248 | self.data_spc |
|
2259 | self.data_spc | |
2249 | self.data_cspc |
|
2260 | self.data_cspc | |
2250 | self.data_dc |
|
2261 | self.data_dc | |
2251 |
|
2262 | |||
2252 | Return: |
|
2263 | Return: | |
2253 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
2264 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
2254 | 1 : Si se escribio la data de un bloque en un file |
|
2265 | 1 : Si se escribio la data de un bloque en un file | |
2255 | """ |
|
2266 | """ | |
2256 |
|
2267 | |||
2257 | if self.dataOut.flagNoData: |
|
2268 | if self.dataOut.flagNoData: | |
2258 | return 0 |
|
2269 | return 0 | |
2259 |
|
2270 | |||
2260 | self.flagIsNewBlock = 0 |
|
2271 | self.flagIsNewBlock = 0 | |
2261 |
|
2272 | |||
2262 | if self.dataOut.flagTimeBlock: |
|
2273 | if self.dataOut.flagTimeBlock: | |
2263 | self.data_spc.fill(0) |
|
2274 | self.data_spc.fill(0) | |
2264 | self.data_cspc.fill(0) |
|
2275 | self.data_cspc.fill(0) | |
2265 | self.data_dc.fill(0) |
|
2276 | self.data_dc.fill(0) | |
2266 | self.setNextFile() |
|
2277 | self.setNextFile() | |
2267 |
|
2278 | |||
2268 | if self.flagIsNewFile == 0: |
|
2279 | if self.flagIsNewFile == 0: | |
2269 | self.getBasicHeader() |
|
2280 | self.getBasicHeader() | |
2270 |
|
2281 | |||
2271 | self.data_spc = self.dataOut.data_spc |
|
2282 | self.data_spc = self.dataOut.data_spc | |
2272 | self.data_cspc = self.dataOut.data_cspc |
|
2283 | self.data_cspc = self.dataOut.data_cspc | |
2273 | self.data_dc = self.dataOut.data_dc |
|
2284 | self.data_dc = self.dataOut.data_dc | |
2274 |
|
2285 | |||
2275 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
2286 | # #self.processingHeaderObj.dataBlocksPerFile) | |
2276 | if self.hasAllDataInBuffer(): |
|
2287 | if self.hasAllDataInBuffer(): | |
2277 | # self.getDataHeader() |
|
2288 | # self.getDataHeader() | |
2278 | self.writeNextBlock() |
|
2289 | self.writeNextBlock() | |
2279 |
|
2290 | |||
2280 | return 1 |
|
2291 | return 1 | |
2281 |
|
2292 | |||
2282 |
|
2293 | |||
2283 | def __getProcessFlags(self): |
|
2294 | def __getProcessFlags(self): | |
2284 |
|
2295 | |||
2285 | processFlags = 0 |
|
2296 | processFlags = 0 | |
2286 |
|
2297 | |||
2287 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2298 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2288 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2299 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2289 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2300 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2290 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2301 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2291 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2302 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2292 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2303 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2293 |
|
2304 | |||
2294 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2305 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2295 |
|
2306 | |||
2296 |
|
2307 | |||
2297 |
|
2308 | |||
2298 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
2309 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
2299 | PROCFLAG.DATATYPE_SHORT, |
|
2310 | PROCFLAG.DATATYPE_SHORT, | |
2300 | PROCFLAG.DATATYPE_LONG, |
|
2311 | PROCFLAG.DATATYPE_LONG, | |
2301 | PROCFLAG.DATATYPE_INT64, |
|
2312 | PROCFLAG.DATATYPE_INT64, | |
2302 | PROCFLAG.DATATYPE_FLOAT, |
|
2313 | PROCFLAG.DATATYPE_FLOAT, | |
2303 | PROCFLAG.DATATYPE_DOUBLE] |
|
2314 | PROCFLAG.DATATYPE_DOUBLE] | |
2304 |
|
2315 | |||
2305 |
|
2316 | |||
2306 | for index in range(len(dtypeList)): |
|
2317 | for index in range(len(dtypeList)): | |
2307 | if self.dataOut.dtype == dtypeList[index]: |
|
2318 | if self.dataOut.dtype == dtypeList[index]: | |
2308 | dtypeValue = datatypeValueList[index] |
|
2319 | dtypeValue = datatypeValueList[index] | |
2309 | break |
|
2320 | break | |
2310 |
|
2321 | |||
2311 | processFlags += dtypeValue |
|
2322 | processFlags += dtypeValue | |
2312 |
|
2323 | |||
2313 | if self.dataOut.flagDecodeData: |
|
2324 | if self.dataOut.flagDecodeData: | |
2314 | processFlags += PROCFLAG.DECODE_DATA |
|
2325 | processFlags += PROCFLAG.DECODE_DATA | |
2315 |
|
2326 | |||
2316 | if self.dataOut.flagDeflipData: |
|
2327 | if self.dataOut.flagDeflipData: | |
2317 | processFlags += PROCFLAG.DEFLIP_DATA |
|
2328 | processFlags += PROCFLAG.DEFLIP_DATA | |
2318 |
|
2329 | |||
2319 | if self.dataOut.code != None: |
|
2330 | if self.dataOut.code != None: | |
2320 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
2331 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
2321 |
|
2332 | |||
2322 | if self.dataOut.nIncohInt > 1: |
|
2333 | if self.dataOut.nIncohInt > 1: | |
2323 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
2334 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
2324 |
|
2335 | |||
2325 | if self.dataOut.data_dc != None: |
|
2336 | if self.dataOut.data_dc != None: | |
2326 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
2337 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
2327 |
|
2338 | |||
2328 | return processFlags |
|
2339 | return processFlags | |
2329 |
|
2340 | |||
2330 |
|
2341 | |||
2331 | def __getBlockSize(self): |
|
2342 | def __getBlockSize(self): | |
2332 | ''' |
|
2343 | ''' | |
2333 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
2344 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
2334 | ''' |
|
2345 | ''' | |
2335 |
|
2346 | |||
2336 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2347 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2337 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2348 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2338 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2349 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2339 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2350 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2340 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2351 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2341 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2352 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2342 |
|
2353 | |||
2343 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2354 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2344 | datatypeValueList = [1,2,4,8,4,8] |
|
2355 | datatypeValueList = [1,2,4,8,4,8] | |
2345 | for index in range(len(dtypeList)): |
|
2356 | for index in range(len(dtypeList)): | |
2346 | if self.dataOut.dtype == dtypeList[index]: |
|
2357 | if self.dataOut.dtype == dtypeList[index]: | |
2347 | datatypeValue = datatypeValueList[index] |
|
2358 | datatypeValue = datatypeValueList[index] | |
2348 | break |
|
2359 | break | |
2349 |
|
2360 | |||
2350 |
|
2361 | |||
2351 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
2362 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints | |
2352 |
|
2363 | |||
2353 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
2364 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) | |
2354 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
2365 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
2355 |
|
2366 | |||
2356 | if self.dataOut.data_cspc != None: |
|
2367 | if self.dataOut.data_cspc != None: | |
2357 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
2368 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) | |
2358 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
2369 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
2359 |
|
2370 | |||
2360 | if self.dataOut.data_dc != None: |
|
2371 | if self.dataOut.data_dc != None: | |
2361 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
2372 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) | |
2362 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
2373 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
2363 |
|
2374 | |||
2364 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
2375 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
2365 |
|
2376 | |||
2366 | return blocksize |
|
2377 | return blocksize | |
2367 |
|
2378 | |||
2368 | def getDataHeader(self): |
|
2379 | def getDataHeader(self): | |
2369 |
|
2380 | |||
2370 | """ |
|
2381 | """ | |
2371 | Obtiene una copia del First Header |
|
2382 | Obtiene una copia del First Header | |
2372 |
|
2383 | |||
2373 | Affected: |
|
2384 | Affected: | |
2374 | self.systemHeaderObj |
|
2385 | self.systemHeaderObj | |
2375 | self.radarControllerHeaderObj |
|
2386 | self.radarControllerHeaderObj | |
2376 | self.dtype |
|
2387 | self.dtype | |
2377 |
|
2388 | |||
2378 | Return: |
|
2389 | Return: | |
2379 | None |
|
2390 | None | |
2380 | """ |
|
2391 | """ | |
2381 |
|
2392 | |||
2382 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
2393 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
2383 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
2394 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
2384 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
2395 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
2385 |
|
2396 | |||
2386 | self.getBasicHeader() |
|
2397 | self.getBasicHeader() | |
2387 |
|
2398 | |||
2388 | processingHeaderSize = 40 # bytes |
|
2399 | processingHeaderSize = 40 # bytes | |
2389 | self.processingHeaderObj.dtype = 0 # Voltage |
|
2400 | self.processingHeaderObj.dtype = 0 # Voltage | |
2390 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
2401 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
2391 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
2402 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints | |
2392 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
2403 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
2393 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
2404 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
2394 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
2405 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
2395 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
2406 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval | |
2396 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
2407 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
2397 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
2408 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels | |
2398 |
|
2409 | |||
2399 | if self.processingHeaderObj.totalSpectra > 0: |
|
2410 | if self.processingHeaderObj.totalSpectra > 0: | |
2400 | channelList = [] |
|
2411 | channelList = [] | |
2401 | for channel in range(self.dataOut.nChannels): |
|
2412 | for channel in range(self.dataOut.nChannels): | |
2402 | channelList.append(channel) |
|
2413 | channelList.append(channel) | |
2403 | channelList.append(channel) |
|
2414 | channelList.append(channel) | |
2404 |
|
2415 | |||
2405 | pairsList = [] |
|
2416 | pairsList = [] | |
2406 | for pair in self.dataOut.pairsList: |
|
2417 | for pair in self.dataOut.pairsList: | |
2407 | pairsList.append(pair[0]) |
|
2418 | pairsList.append(pair[0]) | |
2408 | pairsList.append(pair[1]) |
|
2419 | pairsList.append(pair[1]) | |
2409 | spectraComb = channelList + pairsList |
|
2420 | spectraComb = channelList + pairsList | |
2410 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
2421 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
2411 | self.processingHeaderObj.spectraComb = spectraComb |
|
2422 | self.processingHeaderObj.spectraComb = spectraComb | |
2412 | sizeOfSpcComb = len(spectraComb) |
|
2423 | sizeOfSpcComb = len(spectraComb) | |
2413 | processingHeaderSize += sizeOfSpcComb |
|
2424 | processingHeaderSize += sizeOfSpcComb | |
2414 |
|
2425 | |||
2415 | if self.dataOut.code != None: |
|
2426 | if self.dataOut.code != None: | |
2416 | self.processingHeaderObj.code = self.dataOut.code |
|
2427 | self.processingHeaderObj.code = self.dataOut.code | |
2417 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
2428 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
2418 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
2429 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
2419 | nCodeSize = 4 # bytes |
|
2430 | nCodeSize = 4 # bytes | |
2420 | nBaudSize = 4 # bytes |
|
2431 | nBaudSize = 4 # bytes | |
2421 | codeSize = 4 # bytes |
|
2432 | codeSize = 4 # bytes | |
2422 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
2433 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) | |
2423 | processingHeaderSize += sizeOfCode |
|
2434 | processingHeaderSize += sizeOfCode | |
2424 |
|
2435 | |||
2425 | if self.processingHeaderObj.nWindows != 0: |
|
2436 | if self.processingHeaderObj.nWindows != 0: | |
2426 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
2437 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
2427 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2438 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
2428 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
2439 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
2429 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
2440 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
2430 | sizeOfFirstHeight = 4 |
|
2441 | sizeOfFirstHeight = 4 | |
2431 | sizeOfdeltaHeight = 4 |
|
2442 | sizeOfdeltaHeight = 4 | |
2432 | sizeOfnHeights = 4 |
|
2443 | sizeOfnHeights = 4 | |
2433 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
2444 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
2434 | processingHeaderSize += sizeOfWindows |
|
2445 | processingHeaderSize += sizeOfWindows | |
2435 |
|
2446 | |||
2436 | self.processingHeaderObj.size = processingHeaderSize |
|
2447 | self.processingHeaderObj.size = processingHeaderSize | |
2437 |
|
2448 | |||
2438 | class SpectraHeisWriter(): |
|
2449 | class SpectraHeisWriter(): | |
2439 |
|
2450 | |||
2440 | i=0 |
|
2451 | i=0 | |
2441 |
|
2452 | |||
2442 | def __init__(self, dataOut): |
|
2453 | def __init__(self, dataOut): | |
2443 |
|
2454 | |||
2444 | self.wrObj = FITS() |
|
2455 | self.wrObj = FITS() | |
2445 | self.dataOut = dataOut |
|
2456 | self.dataOut = dataOut | |
2446 |
|
2457 | |||
2447 | def isNumber(str): |
|
2458 | def isNumber(str): | |
2448 | """ |
|
2459 | """ | |
2449 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
2460 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
2450 |
|
2461 | |||
2451 | Excepciones: |
|
2462 | Excepciones: | |
2452 | Si un determinado string no puede ser convertido a numero |
|
2463 | Si un determinado string no puede ser convertido a numero | |
2453 | Input: |
|
2464 | Input: | |
2454 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
2465 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
2455 |
|
2466 | |||
2456 | Return: |
|
2467 | Return: | |
2457 | True : si el string es uno numerico |
|
2468 | True : si el string es uno numerico | |
2458 | False : no es un string numerico |
|
2469 | False : no es un string numerico | |
2459 | """ |
|
2470 | """ | |
2460 | try: |
|
2471 | try: | |
2461 | float( str ) |
|
2472 | float( str ) | |
2462 | return True |
|
2473 | return True | |
2463 | except: |
|
2474 | except: | |
2464 | return False |
|
2475 | return False | |
2465 |
|
2476 | |||
2466 | def setup(self, wrpath,): |
|
2477 | def setup(self, wrpath,): | |
2467 |
|
2478 | |||
2468 | if not(os.path.exists(wrpath)): |
|
2479 | if not(os.path.exists(wrpath)): | |
2469 | os.mkdir(wrpath) |
|
2480 | os.mkdir(wrpath) | |
2470 |
|
2481 | |||
2471 | self.wrpath = wrpath |
|
2482 | self.wrpath = wrpath | |
2472 | self.setFile = 0 |
|
2483 | self.setFile = 0 | |
2473 |
|
2484 | |||
2474 | def putData(self): |
|
2485 | def putData(self): | |
2475 | # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints) |
|
2486 | # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints) | |
2476 | #name = self.dataOut.utctime |
|
2487 | #name = self.dataOut.utctime | |
2477 | name= time.localtime( self.dataOut.utctime) |
|
2488 | name= time.localtime( self.dataOut.utctime) | |
2478 | ext=".fits" |
|
2489 | ext=".fits" | |
2479 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) |
|
2490 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) | |
2480 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) |
|
2491 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) | |
2481 |
|
2492 | |||
2482 | fullpath = os.path.join( self.wrpath, subfolder ) |
|
2493 | fullpath = os.path.join( self.wrpath, subfolder ) | |
2483 | if not( os.path.exists(fullpath) ): |
|
2494 | if not( os.path.exists(fullpath) ): | |
2484 | os.mkdir(fullpath) |
|
2495 | os.mkdir(fullpath) | |
2485 | self.setFile += 1 |
|
2496 | self.setFile += 1 | |
2486 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
2497 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) | |
2487 |
|
2498 | |||
2488 | filename = os.path.join(self.wrpath,subfolder, file) |
|
2499 | filename = os.path.join(self.wrpath,subfolder, file) | |
2489 |
|
2500 | |||
2490 | # print self.dataOut.ippSeconds |
|
2501 | # print self.dataOut.ippSeconds | |
2491 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds) |
|
2502 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds) | |
2492 |
|
2503 | |||
2493 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
2504 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) | |
2494 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:])) |
|
2505 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:])) | |
2495 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:])) |
|
2506 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:])) | |
2496 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:])) |
|
2507 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:])) | |
2497 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:])) |
|
2508 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:])) | |
2498 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:])) |
|
2509 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:])) | |
2499 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:])) |
|
2510 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:])) | |
2500 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:])) |
|
2511 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:])) | |
2501 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:])) |
|
2512 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:])) | |
2502 | #n=numpy.arange((100)) |
|
2513 | #n=numpy.arange((100)) | |
2503 | n=self.dataOut.data_spc[6,:] |
|
2514 | n=self.dataOut.data_spc[6,:] | |
2504 | a=self.wrObj.cFImage(n) |
|
2515 | a=self.wrObj.cFImage(n) | |
2505 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) |
|
2516 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) | |
2506 | self.wrObj.CFile(a,b) |
|
2517 | self.wrObj.CFile(a,b) | |
2507 | self.wrObj.wFile(filename) |
|
2518 | self.wrObj.wFile(filename) | |
2508 | return 1 |
|
2519 | return 1 | |
2509 |
|
2520 | |||
2510 | class FITS: |
|
2521 | class FITS: | |
2511 |
|
2522 | |||
2512 | name=None |
|
2523 | name=None | |
2513 | format=None |
|
2524 | format=None | |
2514 | array =None |
|
2525 | array =None | |
2515 | data =None |
|
2526 | data =None | |
2516 | thdulist=None |
|
2527 | thdulist=None | |
2517 |
|
2528 | |||
2518 | def __init__(self): |
|
2529 | def __init__(self): | |
2519 |
|
2530 | |||
2520 | pass |
|
2531 | pass | |
2521 |
|
2532 | |||
2522 | def setColF(self,name,format,array): |
|
2533 | def setColF(self,name,format,array): | |
2523 | self.name=name |
|
2534 | self.name=name | |
2524 | self.format=format |
|
2535 | self.format=format | |
2525 | self.array=array |
|
2536 | self.array=array | |
2526 | a1=numpy.array([self.array],dtype=numpy.float32) |
|
2537 | a1=numpy.array([self.array],dtype=numpy.float32) | |
2527 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) |
|
2538 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
2528 | return self.col1 |
|
2539 | return self.col1 | |
2529 |
|
2540 | |||
2530 | # def setColP(self,name,format,data): |
|
2541 | # def setColP(self,name,format,data): | |
2531 | # self.name=name |
|
2542 | # self.name=name | |
2532 | # self.format=format |
|
2543 | # self.format=format | |
2533 | # self.data=data |
|
2544 | # self.data=data | |
2534 | # a2=numpy.array([self.data],dtype=numpy.float32) |
|
2545 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
2535 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2546 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2536 | # return self.col2 |
|
2547 | # return self.col2 | |
2537 |
|
2548 | |||
2538 | def writeHeader(self,): |
|
2549 | def writeHeader(self,): | |
2539 | pass |
|
2550 | pass | |
2540 |
|
2551 | |||
2541 | def writeData(self,name,format,data): |
|
2552 | def writeData(self,name,format,data): | |
2542 | self.name=name |
|
2553 | self.name=name | |
2543 | self.format=format |
|
2554 | self.format=format | |
2544 | self.data=data |
|
2555 | self.data=data | |
2545 | a2=numpy.array([self.data],dtype=numpy.float32) |
|
2556 | a2=numpy.array([self.data],dtype=numpy.float32) | |
2546 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2557 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2547 | return self.col2 |
|
2558 | return self.col2 | |
2548 |
|
2559 | |||
2549 | def cFImage(self,n): |
|
2560 | def cFImage(self,n): | |
2550 | self.hdu= pyfits.PrimaryHDU(n) |
|
2561 | self.hdu= pyfits.PrimaryHDU(n) | |
2551 | return self.hdu |
|
2562 | return self.hdu | |
2552 |
|
2563 | |||
2553 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): |
|
2564 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): | |
2554 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) |
|
2565 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) | |
2555 | self.tbhdu = pyfits.new_table(self.cols) |
|
2566 | self.tbhdu = pyfits.new_table(self.cols) | |
2556 | return self.tbhdu |
|
2567 | return self.tbhdu | |
2557 |
|
2568 | |||
2558 | def CFile(self,hdu,tbhdu): |
|
2569 | def CFile(self,hdu,tbhdu): | |
2559 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) |
|
2570 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
2560 |
|
2571 | |||
2561 | def wFile(self,filename): |
|
2572 | def wFile(self,filename): | |
2562 | self.thdulist.writeto(filename) No newline at end of file |
|
2573 | self.thdulist.writeto(filename) |
@@ -1,1006 +1,1012 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time, datetime |
|
2 | import time, datetime | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 |
|
4 | |||
5 | class CrossSpectraPlot(Figure): |
|
5 | class CrossSpectraPlot(Figure): | |
6 |
|
6 | |||
7 | __isConfig = None |
|
7 | __isConfig = None | |
8 | __nsubplots = None |
|
8 | __nsubplots = None | |
9 |
|
9 | |||
10 | WIDTH = None |
|
10 | WIDTH = None | |
11 | HEIGHT = None |
|
11 | HEIGHT = None | |
12 | WIDTHPROF = None |
|
12 | WIDTHPROF = None | |
13 | HEIGHTPROF = None |
|
13 | HEIGHTPROF = None | |
14 | PREFIX = 'cspc' |
|
14 | PREFIX = 'cspc' | |
15 |
|
15 | |||
16 | def __init__(self): |
|
16 | def __init__(self): | |
17 |
|
17 | |||
18 | self.__isConfig = False |
|
18 | self.__isConfig = False | |
19 | self.__nsubplots = 4 |
|
19 | self.__nsubplots = 4 | |
20 |
|
20 | |||
21 | self.WIDTH = 250 |
|
21 | self.WIDTH = 250 | |
22 | self.HEIGHT = 250 |
|
22 | self.HEIGHT = 250 | |
23 | self.WIDTHPROF = 0 |
|
23 | self.WIDTHPROF = 0 | |
24 | self.HEIGHTPROF = 0 |
|
24 | self.HEIGHTPROF = 0 | |
25 |
|
25 | |||
26 | def getSubplots(self): |
|
26 | def getSubplots(self): | |
27 |
|
27 | |||
28 | ncol = 4 |
|
28 | ncol = 4 | |
29 | nrow = self.nplots |
|
29 | nrow = self.nplots | |
30 |
|
30 | |||
31 | return nrow, ncol |
|
31 | return nrow, ncol | |
32 |
|
32 | |||
33 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
33 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
34 |
|
34 | |||
35 | self.__showprofile = showprofile |
|
35 | self.__showprofile = showprofile | |
36 | self.nplots = nplots |
|
36 | self.nplots = nplots | |
37 |
|
37 | |||
38 | ncolspan = 1 |
|
38 | ncolspan = 1 | |
39 | colspan = 1 |
|
39 | colspan = 1 | |
40 |
|
40 | |||
41 | self.createFigure(idfigure = idfigure, |
|
41 | self.createFigure(idfigure = idfigure, | |
42 | wintitle = wintitle, |
|
42 | wintitle = wintitle, | |
43 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
43 | widthplot = self.WIDTH + self.WIDTHPROF, | |
44 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
44 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
45 |
|
45 | |||
46 | nrow, ncol = self.getSubplots() |
|
46 | nrow, ncol = self.getSubplots() | |
47 |
|
47 | |||
48 | counter = 0 |
|
48 | counter = 0 | |
49 | for y in range(nrow): |
|
49 | for y in range(nrow): | |
50 | for x in range(ncol): |
|
50 | for x in range(ncol): | |
51 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
51 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
52 |
|
52 | |||
53 | counter += 1 |
|
53 | counter += 1 | |
54 |
|
54 | |||
55 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
55 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', | |
56 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
56 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
57 |
save=False, figpath='./', figfile=None |
|
57 | save=False, figpath='./', figfile=None, | |
|
58 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r'): | |||
58 |
|
59 | |||
59 | """ |
|
60 | """ | |
60 |
|
61 | |||
61 | Input: |
|
62 | Input: | |
62 | dataOut : |
|
63 | dataOut : | |
63 | idfigure : |
|
64 | idfigure : | |
64 | wintitle : |
|
65 | wintitle : | |
65 | channelList : |
|
66 | channelList : | |
66 | showProfile : |
|
67 | showProfile : | |
67 | xmin : None, |
|
68 | xmin : None, | |
68 | xmax : None, |
|
69 | xmax : None, | |
69 | ymin : None, |
|
70 | ymin : None, | |
70 | ymax : None, |
|
71 | ymax : None, | |
71 | zmin : None, |
|
72 | zmin : None, | |
72 | zmax : None |
|
73 | zmax : None | |
73 | """ |
|
74 | """ | |
74 |
|
75 | |||
75 | if pairsList == None: |
|
76 | if pairsList == None: | |
76 | pairsIndexList = dataOut.pairsIndexList |
|
77 | pairsIndexList = dataOut.pairsIndexList | |
77 | else: |
|
78 | else: | |
78 | pairsIndexList = [] |
|
79 | pairsIndexList = [] | |
79 | for pair in pairsList: |
|
80 | for pair in pairsList: | |
80 | if pair not in dataOut.pairsList: |
|
81 | if pair not in dataOut.pairsList: | |
81 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
82 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
82 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
83 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
83 |
|
84 | |||
84 | if pairsIndexList == []: |
|
85 | if pairsIndexList == []: | |
85 | return |
|
86 | return | |
86 |
|
87 | |||
87 | if len(pairsIndexList) > 4: |
|
88 | if len(pairsIndexList) > 4: | |
88 | pairsIndexList = pairsIndexList[0:4] |
|
89 | pairsIndexList = pairsIndexList[0:4] | |
89 | factor = dataOut.normFactor |
|
90 | factor = dataOut.normFactor | |
90 | x = dataOut.getVelRange(1) |
|
91 | x = dataOut.getVelRange(1) | |
91 | y = dataOut.getHeiRange() |
|
92 | y = dataOut.getHeiRange() | |
92 | z = dataOut.data_spc[:,:,:]/factor |
|
93 | z = dataOut.data_spc[:,:,:]/factor | |
93 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
94 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
94 |
avg = numpy.a |
|
95 | avg = numpy.abs(numpy.average(z, axis=1)) | |
95 | noise = dataOut.getNoise()/factor |
|
96 | noise = dataOut.getNoise()/factor | |
96 |
|
97 | |||
97 | zdB = 10*numpy.log10(z) |
|
98 | zdB = 10*numpy.log10(z) | |
98 | avgdB = 10*numpy.log10(avg) |
|
99 | avgdB = 10*numpy.log10(avg) | |
99 | noisedB = 10*numpy.log10(noise) |
|
100 | noisedB = 10*numpy.log10(noise) | |
100 |
|
101 | |||
101 |
|
102 | |||
102 | thisDatetime = dataOut.datatime |
|
103 | thisDatetime = dataOut.datatime | |
103 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
104 | title = "Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
104 | xlabel = "Velocity (m/s)" |
|
105 | xlabel = "Velocity (m/s)" | |
105 | ylabel = "Range (Km)" |
|
106 | ylabel = "Range (Km)" | |
106 |
|
107 | |||
107 | if not self.__isConfig: |
|
108 | if not self.__isConfig: | |
108 |
|
109 | |||
109 | nplots = len(pairsIndexList) |
|
110 | nplots = len(pairsIndexList) | |
110 |
|
111 | |||
111 | self.setup(idfigure=idfigure, |
|
112 | self.setup(idfigure=idfigure, | |
112 | nplots=nplots, |
|
113 | nplots=nplots, | |
113 | wintitle=wintitle, |
|
114 | wintitle=wintitle, | |
114 | showprofile=showprofile) |
|
115 | showprofile=showprofile) | |
115 |
|
116 | |||
116 | if xmin == None: xmin = numpy.nanmin(x) |
|
117 | if xmin == None: xmin = numpy.nanmin(x) | |
117 | if xmax == None: xmax = numpy.nanmax(x) |
|
118 | if xmax == None: xmax = numpy.nanmax(x) | |
118 | if ymin == None: ymin = numpy.nanmin(y) |
|
119 | if ymin == None: ymin = numpy.nanmin(y) | |
119 | if ymax == None: ymax = numpy.nanmax(y) |
|
120 | if ymax == None: ymax = numpy.nanmax(y) | |
120 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
121 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
121 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
122 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
122 |
|
123 | |||
123 | self.__isConfig = True |
|
124 | self.__isConfig = True | |
124 |
|
125 | |||
125 | self.setWinTitle(title) |
|
126 | self.setWinTitle(title) | |
126 |
|
127 | |||
127 | for i in range(self.nplots): |
|
128 | for i in range(self.nplots): | |
128 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
129 | pair = dataOut.pairsList[pairsIndexList[i]] | |
129 |
|
130 | |||
130 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) |
|
131 | title = "Channel %d: %4.2fdB" %(pair[0], noisedB[pair[0]]) | |
131 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
132 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) | |
132 | axes0 = self.axesList[i*self.__nsubplots] |
|
133 | axes0 = self.axesList[i*self.__nsubplots] | |
133 | axes0.pcolor(x, y, zdB, |
|
134 | axes0.pcolor(x, y, zdB, | |
134 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
135 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
135 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
136 | xlabel=xlabel, ylabel=ylabel, title=title, | |
136 | ticksize=9, cblabel='') |
|
137 | ticksize=9, colormap=power_cmap, cblabel='') | |
137 |
|
138 | |||
138 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) |
|
139 | title = "Channel %d: %4.2fdB" %(pair[1], noisedB[pair[1]]) | |
139 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
140 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) | |
140 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
141 | axes0 = self.axesList[i*self.__nsubplots+1] | |
141 | axes0.pcolor(x, y, zdB, |
|
142 | axes0.pcolor(x, y, zdB, | |
142 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
143 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
143 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
144 | xlabel=xlabel, ylabel=ylabel, title=title, | |
144 | ticksize=9, cblabel='') |
|
145 | ticksize=9, colormap=power_cmap, cblabel='') | |
145 |
|
146 | |||
146 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
147 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
147 | coherence = numpy.abs(coherenceComplex) |
|
148 | coherence = numpy.abs(coherenceComplex) | |
148 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
149 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
149 |
|
150 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | ||
150 |
|
151 | |||
151 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
152 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
152 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
153 | axes0 = self.axesList[i*self.__nsubplots+2] | |
153 | axes0.pcolor(x, y, coherence, |
|
154 | axes0.pcolor(x, y, coherence, | |
154 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
155 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
155 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
156 | xlabel=xlabel, ylabel=ylabel, title=title, | |
156 | ticksize=9, cblabel='') |
|
157 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
157 |
|
158 | |||
158 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
159 | title = "Phase %d%d" %(pair[0], pair[1]) | |
159 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
160 | axes0 = self.axesList[i*self.__nsubplots+3] | |
160 | axes0.pcolor(x, y, phase, |
|
161 | axes0.pcolor(x, y, phase, | |
161 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
162 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
162 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
163 | xlabel=xlabel, ylabel=ylabel, title=title, | |
163 |
ticksize=9, cblabel='' |
|
164 | ticksize=9, colormap=phase_cmap, cblabel='') | |
164 |
|
165 | |||
165 |
|
166 | |||
166 |
|
167 | |||
167 | self.draw() |
|
168 | self.draw() | |
168 |
|
169 | |||
169 | if save: |
|
170 | if save: | |
170 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
171 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
171 | if figfile == None: |
|
172 | if figfile == None: | |
172 | figfile = self.getFilename(name = date) |
|
173 | figfile = self.getFilename(name = date) | |
173 |
|
174 | |||
174 | self.saveFigure(figpath, figfile) |
|
175 | self.saveFigure(figpath, figfile) | |
175 |
|
176 | |||
176 |
|
177 | |||
177 | class RTIPlot(Figure): |
|
178 | class RTIPlot(Figure): | |
178 |
|
179 | |||
179 | __isConfig = None |
|
180 | __isConfig = None | |
180 | __nsubplots = None |
|
181 | __nsubplots = None | |
181 | __missing = 1E30 |
|
182 | __missing = 1E30 | |
182 | WIDTHPROF = None |
|
183 | WIDTHPROF = None | |
183 | HEIGHTPROF = None |
|
184 | HEIGHTPROF = None | |
184 | PREFIX = 'rti' |
|
185 | PREFIX = 'rti' | |
185 |
|
186 | |||
186 | def __init__(self): |
|
187 | def __init__(self): | |
187 |
|
188 | |||
188 | self.timerange = 2*60*60 |
|
189 | self.timerange = 2*60*60 | |
189 | self.__isConfig = False |
|
190 | self.__isConfig = False | |
190 | self.__nsubplots = 1 |
|
191 | self.__nsubplots = 1 | |
191 |
|
192 | |||
192 | self.WIDTH = 800 |
|
193 | self.WIDTH = 800 | |
193 | self.HEIGHT = 200 |
|
194 | self.HEIGHT = 200 | |
194 | self.WIDTHPROF = 120 |
|
195 | self.WIDTHPROF = 120 | |
195 | self.HEIGHTPROF = 0 |
|
196 | self.HEIGHTPROF = 0 | |
196 | self.x_buffer = None |
|
197 | self.x_buffer = None | |
197 | self.avgdB_buffer = None |
|
198 | self.avgdB_buffer = None | |
198 |
|
199 | |||
199 | def getSubplots(self): |
|
200 | def getSubplots(self): | |
200 |
|
201 | |||
201 | ncol = 1 |
|
202 | ncol = 1 | |
202 | nrow = self.nplots |
|
203 | nrow = self.nplots | |
203 |
|
204 | |||
204 | return nrow, ncol |
|
205 | return nrow, ncol | |
205 |
|
206 | |||
206 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
207 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
207 |
|
208 | |||
208 | self.__showprofile = showprofile |
|
209 | self.__showprofile = showprofile | |
209 | self.nplots = nplots |
|
210 | self.nplots = nplots | |
210 |
|
211 | |||
211 | ncolspan = 1 |
|
212 | ncolspan = 1 | |
212 | colspan = 1 |
|
213 | colspan = 1 | |
213 | if showprofile: |
|
214 | if showprofile: | |
214 | ncolspan = 7 |
|
215 | ncolspan = 7 | |
215 | colspan = 6 |
|
216 | colspan = 6 | |
216 | self.__nsubplots = 2 |
|
217 | self.__nsubplots = 2 | |
217 |
|
218 | |||
218 | self.createFigure(idfigure = idfigure, |
|
219 | self.createFigure(idfigure = idfigure, | |
219 | wintitle = wintitle, |
|
220 | wintitle = wintitle, | |
220 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
221 | widthplot = self.WIDTH + self.WIDTHPROF, | |
221 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
222 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
222 |
|
223 | |||
223 | nrow, ncol = self.getSubplots() |
|
224 | nrow, ncol = self.getSubplots() | |
224 |
|
225 | |||
225 | counter = 0 |
|
226 | counter = 0 | |
226 | for y in range(nrow): |
|
227 | for y in range(nrow): | |
227 | for x in range(ncol): |
|
228 | for x in range(ncol): | |
228 |
|
229 | |||
229 | if counter >= self.nplots: |
|
230 | if counter >= self.nplots: | |
230 | break |
|
231 | break | |
231 |
|
232 | |||
232 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
233 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
233 |
|
234 | |||
234 | if showprofile: |
|
235 | if showprofile: | |
235 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
236 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
236 |
|
237 | |||
237 | counter += 1 |
|
238 | counter += 1 | |
238 |
|
239 | |||
239 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
240 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
240 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
241 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
241 | timerange=None, |
|
242 | timerange=None, | |
242 | save=False, figpath='./', figfile=None): |
|
243 | save=False, figpath='./', figfile=None): | |
243 |
|
244 | |||
244 | """ |
|
245 | """ | |
245 |
|
246 | |||
246 | Input: |
|
247 | Input: | |
247 | dataOut : |
|
248 | dataOut : | |
248 | idfigure : |
|
249 | idfigure : | |
249 | wintitle : |
|
250 | wintitle : | |
250 | channelList : |
|
251 | channelList : | |
251 | showProfile : |
|
252 | showProfile : | |
252 | xmin : None, |
|
253 | xmin : None, | |
253 | xmax : None, |
|
254 | xmax : None, | |
254 | ymin : None, |
|
255 | ymin : None, | |
255 | ymax : None, |
|
256 | ymax : None, | |
256 | zmin : None, |
|
257 | zmin : None, | |
257 | zmax : None |
|
258 | zmax : None | |
258 | """ |
|
259 | """ | |
259 |
|
260 | |||
260 | if channelList == None: |
|
261 | if channelList == None: | |
261 | channelIndexList = dataOut.channelIndexList |
|
262 | channelIndexList = dataOut.channelIndexList | |
262 | else: |
|
263 | else: | |
263 | channelIndexList = [] |
|
264 | channelIndexList = [] | |
264 | for channel in channelList: |
|
265 | for channel in channelList: | |
265 | if channel not in dataOut.channelList: |
|
266 | if channel not in dataOut.channelList: | |
266 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
267 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
267 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
268 | channelIndexList.append(dataOut.channelList.index(channel)) | |
268 |
|
269 | |||
269 | if timerange != None: |
|
270 | if timerange != None: | |
270 | self.timerange = timerange |
|
271 | self.timerange = timerange | |
271 |
|
272 | |||
272 | tmin = None |
|
273 | tmin = None | |
273 | tmax = None |
|
274 | tmax = None | |
274 | factor = dataOut.normFactor |
|
275 | factor = dataOut.normFactor | |
275 | x = dataOut.getTimeRange() |
|
276 | x = dataOut.getTimeRange() | |
276 | y = dataOut.getHeiRange() |
|
277 | y = dataOut.getHeiRange() | |
277 |
|
278 | |||
278 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
279 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
279 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
280 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
280 | avg = numpy.average(z, axis=1) |
|
281 | avg = numpy.average(z, axis=1) | |
281 |
|
282 | |||
282 | avgdB = 10.*numpy.log10(avg) |
|
283 | avgdB = 10.*numpy.log10(avg) | |
283 |
|
284 | |||
284 |
|
285 | |||
285 | thisDatetime = dataOut.datatime |
|
286 | thisDatetime = dataOut.datatime | |
286 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
287 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
287 | xlabel = "Velocity (m/s)" |
|
288 | xlabel = "Velocity (m/s)" | |
288 | ylabel = "Range (Km)" |
|
289 | ylabel = "Range (Km)" | |
289 |
|
290 | |||
290 | if not self.__isConfig: |
|
291 | if not self.__isConfig: | |
291 |
|
292 | |||
292 | nplots = len(channelIndexList) |
|
293 | nplots = len(channelIndexList) | |
293 |
|
294 | |||
294 | self.setup(idfigure=idfigure, |
|
295 | self.setup(idfigure=idfigure, | |
295 | nplots=nplots, |
|
296 | nplots=nplots, | |
296 | wintitle=wintitle, |
|
297 | wintitle=wintitle, | |
297 | showprofile=showprofile) |
|
298 | showprofile=showprofile) | |
298 |
|
299 | |||
299 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
300 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
300 | if ymin == None: ymin = numpy.nanmin(y) |
|
301 | if ymin == None: ymin = numpy.nanmin(y) | |
301 | if ymax == None: ymax = numpy.nanmax(y) |
|
302 | if ymax == None: ymax = numpy.nanmax(y) | |
302 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
303 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
303 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
304 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
304 |
|
305 | |||
305 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
306 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
306 | self.x_buffer = numpy.array([]) |
|
307 | self.x_buffer = numpy.array([]) | |
307 | self.avgdB_buffer = numpy.array([]) |
|
308 | self.avgdB_buffer = numpy.array([]) | |
308 | self.__isConfig = True |
|
309 | self.__isConfig = True | |
309 |
|
310 | |||
310 |
|
311 | |||
311 | self.setWinTitle(title) |
|
312 | self.setWinTitle(title) | |
312 |
|
313 | |||
313 | if len(self.avgdB_buffer)==0: |
|
314 | if len(self.avgdB_buffer)==0: | |
314 | self.avgdB_buffer = avgdB |
|
315 | self.avgdB_buffer = avgdB | |
315 | newxdim = 1 |
|
316 | newxdim = 1 | |
316 | newydim = -1 |
|
317 | newydim = -1 | |
317 | else: |
|
318 | else: | |
318 | if x[0]>self.x_buffer[-1]: |
|
319 | if x[0]>self.x_buffer[-1]: | |
319 | gap = avgdB.copy() |
|
320 | gap = avgdB.copy() | |
320 | gap[:] = self.__missing |
|
321 | gap[:] = self.__missing | |
321 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, gap)) |
|
322 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, gap)) | |
322 |
|
323 | |||
323 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, avgdB)) |
|
324 | self.avgdB_buffer = numpy.hstack((self.avgdB_buffer, avgdB)) | |
324 | newxdim = -1 |
|
325 | newxdim = -1 | |
325 | newydim = len(y) |
|
326 | newydim = len(y) | |
326 |
|
327 | |||
327 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
328 | self.x_buffer = numpy.hstack((self.x_buffer, x)) | |
328 |
|
329 | |||
329 | self.avgdB_buffer = numpy.ma.masked_inside(self.avgdB_buffer,0.99*self.__missing,1.01*self.__missing) |
|
330 | self.avgdB_buffer = numpy.ma.masked_inside(self.avgdB_buffer,0.99*self.__missing,1.01*self.__missing) | |
330 |
|
331 | |||
331 | for i in range(self.nplots): |
|
332 | for i in range(self.nplots): | |
332 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
333 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
333 | axes = self.axesList[i*self.__nsubplots] |
|
334 | axes = self.axesList[i*self.__nsubplots] | |
334 | zdB = self.avgdB_buffer[i].reshape(newxdim,newydim) |
|
335 | zdB = self.avgdB_buffer[i].reshape(newxdim,newydim) | |
335 | axes.pcolor(self.x_buffer, y, zdB, |
|
336 | axes.pcolor(self.x_buffer, y, zdB, | |
336 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
337 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
337 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
338 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
338 | ticksize=9, cblabel='', cbsize="1%") |
|
339 | ticksize=9, cblabel='', cbsize="1%") | |
339 |
|
340 | |||
340 | if self.__showprofile: |
|
341 | if self.__showprofile: | |
341 | axes = self.axesList[i*self.__nsubplots +1] |
|
342 | axes = self.axesList[i*self.__nsubplots +1] | |
342 | axes.pline(avgdB[i], y, |
|
343 | axes.pline(avgdB[i], y, | |
343 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
344 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
344 | xlabel='dB', ylabel='', title='', |
|
345 | xlabel='dB', ylabel='', title='', | |
345 | ytick_visible=False, |
|
346 | ytick_visible=False, | |
346 | grid='x') |
|
347 | grid='x') | |
347 |
|
348 | |||
348 | self.draw() |
|
349 | self.draw() | |
349 |
|
350 | |||
350 | if save: |
|
351 | if save: | |
351 |
|
352 | |||
352 | if figfile == None: |
|
353 | if figfile == None: | |
353 | figfile = self.getFilename(name = self.name) |
|
354 | figfile = self.getFilename(name = self.name) | |
354 |
|
355 | |||
355 | self.saveFigure(figpath, figfile) |
|
356 | self.saveFigure(figpath, figfile) | |
356 |
|
357 | |||
357 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
358 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
358 | self.__isConfig = False |
|
359 | self.__isConfig = False | |
359 |
|
360 | |||
360 | class SpectraPlot(Figure): |
|
361 | class SpectraPlot(Figure): | |
361 |
|
362 | |||
362 | __isConfig = None |
|
363 | __isConfig = None | |
363 | __nsubplots = None |
|
364 | __nsubplots = None | |
364 |
|
365 | |||
365 | WIDTHPROF = None |
|
366 | WIDTHPROF = None | |
366 | HEIGHTPROF = None |
|
367 | HEIGHTPROF = None | |
367 | PREFIX = 'spc' |
|
368 | PREFIX = 'spc' | |
368 |
|
369 | |||
369 | def __init__(self): |
|
370 | def __init__(self): | |
370 |
|
371 | |||
371 | self.__isConfig = False |
|
372 | self.__isConfig = False | |
372 | self.__nsubplots = 1 |
|
373 | self.__nsubplots = 1 | |
373 |
|
374 | |||
374 | self.WIDTH = 230 |
|
375 | self.WIDTH = 230 | |
375 | self.HEIGHT = 250 |
|
376 | self.HEIGHT = 250 | |
376 | self.WIDTHPROF = 120 |
|
377 | self.WIDTHPROF = 120 | |
377 | self.HEIGHTPROF = 0 |
|
378 | self.HEIGHTPROF = 0 | |
378 |
|
379 | |||
379 | def getSubplots(self): |
|
380 | def getSubplots(self): | |
380 |
|
381 | |||
381 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
382 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
382 | nrow = int(self.nplots*1./ncol + 0.9) |
|
383 | nrow = int(self.nplots*1./ncol + 0.9) | |
383 |
|
384 | |||
384 | return nrow, ncol |
|
385 | return nrow, ncol | |
385 |
|
386 | |||
386 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
387 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
387 |
|
388 | |||
388 | self.__showprofile = showprofile |
|
389 | self.__showprofile = showprofile | |
389 | self.nplots = nplots |
|
390 | self.nplots = nplots | |
390 |
|
391 | |||
391 | ncolspan = 1 |
|
392 | ncolspan = 1 | |
392 | colspan = 1 |
|
393 | colspan = 1 | |
393 | if showprofile: |
|
394 | if showprofile: | |
394 | ncolspan = 3 |
|
395 | ncolspan = 3 | |
395 | colspan = 2 |
|
396 | colspan = 2 | |
396 | self.__nsubplots = 2 |
|
397 | self.__nsubplots = 2 | |
397 |
|
398 | |||
398 | self.createFigure(idfigure = idfigure, |
|
399 | self.createFigure(idfigure = idfigure, | |
399 | wintitle = wintitle, |
|
400 | wintitle = wintitle, | |
400 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
401 | widthplot = self.WIDTH + self.WIDTHPROF, | |
401 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
402 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
402 |
|
403 | |||
403 | nrow, ncol = self.getSubplots() |
|
404 | nrow, ncol = self.getSubplots() | |
404 |
|
405 | |||
405 | counter = 0 |
|
406 | counter = 0 | |
406 | for y in range(nrow): |
|
407 | for y in range(nrow): | |
407 | for x in range(ncol): |
|
408 | for x in range(ncol): | |
408 |
|
409 | |||
409 | if counter >= self.nplots: |
|
410 | if counter >= self.nplots: | |
410 | break |
|
411 | break | |
411 |
|
412 | |||
412 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
413 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
413 |
|
414 | |||
414 | if showprofile: |
|
415 | if showprofile: | |
415 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
416 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
416 |
|
417 | |||
417 | counter += 1 |
|
418 | counter += 1 | |
418 |
|
419 | |||
419 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
420 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
420 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
421 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
421 | save=False, figpath='./', figfile=None): |
|
422 | save=False, figpath='./', figfile=None): | |
422 |
|
423 | |||
423 | """ |
|
424 | """ | |
424 |
|
425 | |||
425 | Input: |
|
426 | Input: | |
426 | dataOut : |
|
427 | dataOut : | |
427 | idfigure : |
|
428 | idfigure : | |
428 | wintitle : |
|
429 | wintitle : | |
429 | channelList : |
|
430 | channelList : | |
430 | showProfile : |
|
431 | showProfile : | |
431 | xmin : None, |
|
432 | xmin : None, | |
432 | xmax : None, |
|
433 | xmax : None, | |
433 | ymin : None, |
|
434 | ymin : None, | |
434 | ymax : None, |
|
435 | ymax : None, | |
435 | zmin : None, |
|
436 | zmin : None, | |
436 | zmax : None |
|
437 | zmax : None | |
437 | """ |
|
438 | """ | |
438 |
|
439 | |||
439 | if channelList == None: |
|
440 | if channelList == None: | |
440 | channelIndexList = dataOut.channelIndexList |
|
441 | channelIndexList = dataOut.channelIndexList | |
441 | else: |
|
442 | else: | |
442 | channelIndexList = [] |
|
443 | channelIndexList = [] | |
443 | for channel in channelList: |
|
444 | for channel in channelList: | |
444 | if channel not in dataOut.channelList: |
|
445 | if channel not in dataOut.channelList: | |
445 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
446 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
446 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
447 | channelIndexList.append(dataOut.channelList.index(channel)) | |
447 | factor = dataOut.normFactor |
|
448 | factor = dataOut.normFactor | |
448 | x = dataOut.getVelRange(1) |
|
449 | x = dataOut.getVelRange(1) | |
449 | y = dataOut.getHeiRange() |
|
450 | y = dataOut.getHeiRange() | |
450 |
|
451 | |||
451 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
452 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
452 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
453 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
453 | avg = numpy.average(z, axis=1) |
|
454 | avg = numpy.average(z, axis=1) | |
454 | noise = dataOut.getNoise()/factor |
|
455 | noise = dataOut.getNoise()/factor | |
455 |
|
456 | |||
456 | zdB = 10*numpy.log10(z) |
|
457 | zdB = 10*numpy.log10(z) | |
457 | avgdB = 10*numpy.log10(avg) |
|
458 | avgdB = 10*numpy.log10(avg) | |
458 | noisedB = 10*numpy.log10(noise) |
|
459 | noisedB = 10*numpy.log10(noise) | |
459 |
|
460 | |||
460 | thisDatetime = dataOut.datatime |
|
461 | thisDatetime = dataOut.datatime | |
461 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
462 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
462 | xlabel = "Velocity (m/s)" |
|
463 | xlabel = "Velocity (m/s)" | |
463 | ylabel = "Range (Km)" |
|
464 | ylabel = "Range (Km)" | |
464 |
|
465 | |||
465 | if not self.__isConfig: |
|
466 | if not self.__isConfig: | |
466 |
|
467 | |||
467 | nplots = len(channelIndexList) |
|
468 | nplots = len(channelIndexList) | |
468 |
|
469 | |||
469 | self.setup(idfigure=idfigure, |
|
470 | self.setup(idfigure=idfigure, | |
470 | nplots=nplots, |
|
471 | nplots=nplots, | |
471 | wintitle=wintitle, |
|
472 | wintitle=wintitle, | |
472 | showprofile=showprofile) |
|
473 | showprofile=showprofile) | |
473 |
|
474 | |||
474 | if xmin == None: xmin = numpy.nanmin(x) |
|
475 | if xmin == None: xmin = numpy.nanmin(x) | |
475 | if xmax == None: xmax = numpy.nanmax(x) |
|
476 | if xmax == None: xmax = numpy.nanmax(x) | |
476 | if ymin == None: ymin = numpy.nanmin(y) |
|
477 | if ymin == None: ymin = numpy.nanmin(y) | |
477 | if ymax == None: ymax = numpy.nanmax(y) |
|
478 | if ymax == None: ymax = numpy.nanmax(y) | |
478 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
479 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
479 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
480 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
480 |
|
481 | |||
481 | self.__isConfig = True |
|
482 | self.__isConfig = True | |
482 |
|
483 | |||
483 | self.setWinTitle(title) |
|
484 | self.setWinTitle(title) | |
484 |
|
485 | |||
485 | for i in range(self.nplots): |
|
486 | for i in range(self.nplots): | |
486 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) |
|
487 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noisedB[i]) | |
487 | axes = self.axesList[i*self.__nsubplots] |
|
488 | axes = self.axesList[i*self.__nsubplots] | |
488 | axes.pcolor(x, y, zdB[i,:,:], |
|
489 | axes.pcolor(x, y, zdB[i,:,:], | |
489 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
490 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
490 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
491 | xlabel=xlabel, ylabel=ylabel, title=title, | |
491 | ticksize=9, cblabel='') |
|
492 | ticksize=9, cblabel='') | |
492 |
|
493 | |||
493 | if self.__showprofile: |
|
494 | if self.__showprofile: | |
494 | axes = self.axesList[i*self.__nsubplots +1] |
|
495 | axes = self.axesList[i*self.__nsubplots +1] | |
495 | axes.pline(avgdB[i], y, |
|
496 | axes.pline(avgdB[i], y, | |
496 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
497 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
497 | xlabel='dB', ylabel='', title='', |
|
498 | xlabel='dB', ylabel='', title='', | |
498 | ytick_visible=False, |
|
499 | ytick_visible=False, | |
499 | grid='x') |
|
500 | grid='x') | |
500 |
|
501 | |||
501 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
502 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
502 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
503 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
503 |
|
504 | |||
504 | self.draw() |
|
505 | self.draw() | |
505 |
|
506 | |||
506 | if save: |
|
507 | if save: | |
507 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
508 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
508 | if figfile == None: |
|
509 | if figfile == None: | |
509 | figfile = self.getFilename(name = date) |
|
510 | figfile = self.getFilename(name = date) | |
510 |
|
511 | |||
511 | self.saveFigure(figpath, figfile) |
|
512 | self.saveFigure(figpath, figfile) | |
512 |
|
513 | |||
513 | class Scope(Figure): |
|
514 | class Scope(Figure): | |
514 |
|
515 | |||
515 | __isConfig = None |
|
516 | __isConfig = None | |
516 |
|
517 | |||
517 | def __init__(self): |
|
518 | def __init__(self): | |
518 |
|
519 | |||
519 | self.__isConfig = False |
|
520 | self.__isConfig = False | |
520 | self.WIDTH = 600 |
|
521 | self.WIDTH = 600 | |
521 | self.HEIGHT = 200 |
|
522 | self.HEIGHT = 200 | |
522 |
|
523 | |||
523 | def getSubplots(self): |
|
524 | def getSubplots(self): | |
524 |
|
525 | |||
525 | nrow = self.nplots |
|
526 | nrow = self.nplots | |
526 | ncol = 3 |
|
527 | ncol = 3 | |
527 | return nrow, ncol |
|
528 | return nrow, ncol | |
528 |
|
529 | |||
529 | def setup(self, idfigure, nplots, wintitle): |
|
530 | def setup(self, idfigure, nplots, wintitle): | |
530 |
|
531 | |||
531 | self.nplots = nplots |
|
532 | self.nplots = nplots | |
532 |
|
533 | |||
533 | self.createFigure(idfigure, wintitle) |
|
534 | self.createFigure(idfigure, wintitle) | |
534 |
|
535 | |||
535 | nrow,ncol = self.getSubplots() |
|
536 | nrow,ncol = self.getSubplots() | |
536 | colspan = 3 |
|
537 | colspan = 3 | |
537 | rowspan = 1 |
|
538 | rowspan = 1 | |
538 |
|
539 | |||
539 | for i in range(nplots): |
|
540 | for i in range(nplots): | |
540 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
541 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
541 |
|
542 | |||
542 |
|
543 | |||
543 |
|
544 | |||
544 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
545 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
545 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
546 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
546 | figpath='./', figfile=None): |
|
547 | figpath='./', figfile=None): | |
547 |
|
548 | |||
548 | """ |
|
549 | """ | |
549 |
|
550 | |||
550 | Input: |
|
551 | Input: | |
551 | dataOut : |
|
552 | dataOut : | |
552 | idfigure : |
|
553 | idfigure : | |
553 | wintitle : |
|
554 | wintitle : | |
554 | channelList : |
|
555 | channelList : | |
555 | xmin : None, |
|
556 | xmin : None, | |
556 | xmax : None, |
|
557 | xmax : None, | |
557 | ymin : None, |
|
558 | ymin : None, | |
558 | ymax : None, |
|
559 | ymax : None, | |
559 | """ |
|
560 | """ | |
560 |
|
561 | |||
561 | if channelList == None: |
|
562 | if channelList == None: | |
562 | channelIndexList = dataOut.channelIndexList |
|
563 | channelIndexList = dataOut.channelIndexList | |
563 | else: |
|
564 | else: | |
564 | channelIndexList = [] |
|
565 | channelIndexList = [] | |
565 | for channel in channelList: |
|
566 | for channel in channelList: | |
566 | if channel not in dataOut.channelList: |
|
567 | if channel not in dataOut.channelList: | |
567 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
568 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
568 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
569 | channelIndexList.append(dataOut.channelList.index(channel)) | |
569 |
|
570 | |||
570 | x = dataOut.heightList |
|
571 | x = dataOut.heightList | |
571 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
572 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
572 | y = y.real |
|
573 | y = y.real | |
573 |
|
574 | |||
574 | thisDatetime = dataOut.datatime |
|
575 | thisDatetime = dataOut.datatime | |
575 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
576 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
576 | xlabel = "Range (Km)" |
|
577 | xlabel = "Range (Km)" | |
577 | ylabel = "Intensity" |
|
578 | ylabel = "Intensity" | |
578 |
|
579 | |||
579 | if not self.__isConfig: |
|
580 | if not self.__isConfig: | |
580 | nplots = len(channelIndexList) |
|
581 | nplots = len(channelIndexList) | |
581 |
|
582 | |||
582 | self.setup(idfigure=idfigure, |
|
583 | self.setup(idfigure=idfigure, | |
583 | nplots=nplots, |
|
584 | nplots=nplots, | |
584 | wintitle=wintitle) |
|
585 | wintitle=wintitle) | |
585 |
|
586 | |||
586 | if xmin == None: xmin = numpy.nanmin(x) |
|
587 | if xmin == None: xmin = numpy.nanmin(x) | |
587 | if xmax == None: xmax = numpy.nanmax(x) |
|
588 | if xmax == None: xmax = numpy.nanmax(x) | |
588 | if ymin == None: ymin = numpy.nanmin(y) |
|
589 | if ymin == None: ymin = numpy.nanmin(y) | |
589 | if ymax == None: ymax = numpy.nanmax(y) |
|
590 | if ymax == None: ymax = numpy.nanmax(y) | |
590 |
|
591 | |||
591 | self.__isConfig = True |
|
592 | self.__isConfig = True | |
592 |
|
593 | |||
593 | self.setWinTitle(title) |
|
594 | self.setWinTitle(title) | |
594 |
|
595 | |||
595 | for i in range(len(self.axesList)): |
|
596 | for i in range(len(self.axesList)): | |
596 | title = "Channel %d" %(i) |
|
597 | title = "Channel %d" %(i) | |
597 | axes = self.axesList[i] |
|
598 | axes = self.axesList[i] | |
598 | ychannel = y[i,:] |
|
599 | ychannel = y[i,:] | |
599 | axes.pline(x, ychannel, |
|
600 | axes.pline(x, ychannel, | |
600 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
601 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
601 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
602 | xlabel=xlabel, ylabel=ylabel, title=title) | |
602 |
|
603 | |||
603 | self.draw() |
|
604 | self.draw() | |
604 |
|
605 | |||
605 | if save: |
|
606 | if save: | |
606 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
607 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
607 | if figfile == None: |
|
608 | if figfile == None: | |
608 | figfile = self.getFilename(name = date) |
|
609 | figfile = self.getFilename(name = date) | |
609 |
|
610 | |||
610 | self.saveFigure(figpath, figfile) |
|
611 | self.saveFigure(figpath, figfile) | |
611 |
|
612 | |||
612 | class ProfilePlot(Figure): |
|
613 | class ProfilePlot(Figure): | |
613 | __isConfig = None |
|
614 | __isConfig = None | |
614 | __nsubplots = None |
|
615 | __nsubplots = None | |
615 |
|
616 | |||
616 | WIDTHPROF = None |
|
617 | WIDTHPROF = None | |
617 | HEIGHTPROF = None |
|
618 | HEIGHTPROF = None | |
618 | PREFIX = 'spcprofile' |
|
619 | PREFIX = 'spcprofile' | |
619 |
|
620 | |||
620 | def __init__(self): |
|
621 | def __init__(self): | |
621 | self.__isConfig = False |
|
622 | self.__isConfig = False | |
622 | self.__nsubplots = 1 |
|
623 | self.__nsubplots = 1 | |
623 |
|
624 | |||
624 | self.WIDTH = 300 |
|
625 | self.WIDTH = 300 | |
625 | self.HEIGHT = 500 |
|
626 | self.HEIGHT = 500 | |
626 |
|
627 | |||
627 | def getSubplots(self): |
|
628 | def getSubplots(self): | |
628 | ncol = 1 |
|
629 | ncol = 1 | |
629 | nrow = 1 |
|
630 | nrow = 1 | |
630 |
|
631 | |||
631 | return nrow, ncol |
|
632 | return nrow, ncol | |
632 |
|
633 | |||
633 | def setup(self, idfigure, nplots, wintitle): |
|
634 | def setup(self, idfigure, nplots, wintitle): | |
634 |
|
635 | |||
635 | self.nplots = nplots |
|
636 | self.nplots = nplots | |
636 |
|
637 | |||
637 | ncolspan = 1 |
|
638 | ncolspan = 1 | |
638 | colspan = 1 |
|
639 | colspan = 1 | |
639 |
|
640 | |||
640 | self.createFigure(idfigure = idfigure, |
|
641 | self.createFigure(idfigure = idfigure, | |
641 | wintitle = wintitle, |
|
642 | wintitle = wintitle, | |
642 | widthplot = self.WIDTH, |
|
643 | widthplot = self.WIDTH, | |
643 | heightplot = self.HEIGHT) |
|
644 | heightplot = self.HEIGHT) | |
644 |
|
645 | |||
645 | nrow, ncol = self.getSubplots() |
|
646 | nrow, ncol = self.getSubplots() | |
646 |
|
647 | |||
647 | counter = 0 |
|
648 | counter = 0 | |
648 | for y in range(nrow): |
|
649 | for y in range(nrow): | |
649 | for x in range(ncol): |
|
650 | for x in range(ncol): | |
650 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
651 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
651 |
|
652 | |||
652 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
653 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
653 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
654 | xmin=None, xmax=None, ymin=None, ymax=None, | |
654 | save=False, figpath='./', figfile=None): |
|
655 | save=False, figpath='./', figfile=None): | |
655 |
|
656 | |||
656 | if channelList == None: |
|
657 | if channelList == None: | |
657 | channelIndexList = dataOut.channelIndexList |
|
658 | channelIndexList = dataOut.channelIndexList | |
658 | channelList = dataOut.channelList |
|
659 | channelList = dataOut.channelList | |
659 | else: |
|
660 | else: | |
660 | channelIndexList = [] |
|
661 | channelIndexList = [] | |
661 | for channel in channelList: |
|
662 | for channel in channelList: | |
662 | if channel not in dataOut.channelList: |
|
663 | if channel not in dataOut.channelList: | |
663 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
664 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
664 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
665 | channelIndexList.append(dataOut.channelList.index(channel)) | |
665 |
|
666 | |||
666 | factor = dataOut.normFactor |
|
667 | factor = dataOut.normFactor | |
667 | y = dataOut.getHeiRange() |
|
668 | y = dataOut.getHeiRange() | |
668 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
669 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
669 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
670 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
670 | avg = numpy.average(x, axis=1) |
|
671 | avg = numpy.average(x, axis=1) | |
671 |
|
672 | |||
672 | avgdB = 10*numpy.log10(avg) |
|
673 | avgdB = 10*numpy.log10(avg) | |
673 |
|
674 | |||
674 | thisDatetime = dataOut.datatime |
|
675 | thisDatetime = dataOut.datatime | |
675 | title = "Power Profile" |
|
676 | title = "Power Profile" | |
676 | xlabel = "dB" |
|
677 | xlabel = "dB" | |
677 | ylabel = "Range (Km)" |
|
678 | ylabel = "Range (Km)" | |
678 |
|
679 | |||
679 | if not self.__isConfig: |
|
680 | if not self.__isConfig: | |
680 |
|
681 | |||
681 | nplots = 1 |
|
682 | nplots = 1 | |
682 |
|
683 | |||
683 | self.setup(idfigure=idfigure, |
|
684 | self.setup(idfigure=idfigure, | |
684 | nplots=nplots, |
|
685 | nplots=nplots, | |
685 | wintitle=wintitle) |
|
686 | wintitle=wintitle) | |
686 |
|
687 | |||
687 | if ymin == None: ymin = numpy.nanmin(y) |
|
688 | if ymin == None: ymin = numpy.nanmin(y) | |
688 | if ymax == None: ymax = numpy.nanmax(y) |
|
689 | if ymax == None: ymax = numpy.nanmax(y) | |
689 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 |
|
690 | if xmin == None: xmin = numpy.nanmin(avgdB)*0.9 | |
690 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 |
|
691 | if xmax == None: xmax = numpy.nanmax(avgdB)*0.9 | |
691 |
|
692 | |||
692 | self.__isConfig = True |
|
693 | self.__isConfig = True | |
693 |
|
694 | |||
694 | self.setWinTitle(title) |
|
695 | self.setWinTitle(title) | |
695 |
|
696 | |||
696 |
|
697 | |||
697 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
698 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
698 | axes = self.axesList[0] |
|
699 | axes = self.axesList[0] | |
699 |
|
700 | |||
700 | legendlabels = ["channel %d"%x for x in channelList] |
|
701 | legendlabels = ["channel %d"%x for x in channelList] | |
701 | axes.pmultiline(avgdB, y, |
|
702 | axes.pmultiline(avgdB, y, | |
702 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
703 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
703 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
704 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
704 | ytick_visible=True, nxticks=5, |
|
705 | ytick_visible=True, nxticks=5, | |
705 | grid='x') |
|
706 | grid='x') | |
706 |
|
707 | |||
707 | self.draw() |
|
708 | self.draw() | |
708 |
|
709 | |||
709 | if save: |
|
710 | if save: | |
710 | date = thisDatetime.strftime("%Y%m%d") |
|
711 | date = thisDatetime.strftime("%Y%m%d") | |
711 | if figfile == None: |
|
712 | if figfile == None: | |
712 | figfile = self.getFilename(name = date) |
|
713 | figfile = self.getFilename(name = date) | |
713 |
|
714 | |||
714 | self.saveFigure(figpath, figfile) |
|
715 | self.saveFigure(figpath, figfile) | |
715 |
|
716 | |||
716 | class CoherenceMap(Figure): |
|
717 | class CoherenceMap(Figure): | |
717 | __isConfig = None |
|
718 | __isConfig = None | |
718 | __nsubplots = None |
|
719 | __nsubplots = None | |
719 |
|
720 | |||
720 | WIDTHPROF = None |
|
721 | WIDTHPROF = None | |
721 | HEIGHTPROF = None |
|
722 | HEIGHTPROF = None | |
722 |
PREFIX = 'c |
|
723 | PREFIX = 'cmap' | |
723 |
|
724 | |||
724 | def __init__(self): |
|
725 | def __init__(self): | |
725 | self.timerange = 2*60*60 |
|
726 | self.timerange = 2*60*60 | |
726 | self.__isConfig = False |
|
727 | self.__isConfig = False | |
727 | self.__nsubplots = 1 |
|
728 | self.__nsubplots = 1 | |
728 |
|
729 | |||
729 | self.WIDTH = 800 |
|
730 | self.WIDTH = 800 | |
730 | self.HEIGHT = 200 |
|
731 | self.HEIGHT = 200 | |
731 | self.WIDTHPROF = 120 |
|
732 | self.WIDTHPROF = 120 | |
732 | self.HEIGHTPROF = 0 |
|
733 | self.HEIGHTPROF = 0 | |
733 |
|
734 | |||
734 | def getSubplots(self): |
|
735 | def getSubplots(self): | |
735 | ncol = 1 |
|
736 | ncol = 1 | |
736 | nrow = self.nplots*2 |
|
737 | nrow = self.nplots*2 | |
737 |
|
738 | |||
738 | return nrow, ncol |
|
739 | return nrow, ncol | |
739 |
|
740 | |||
740 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
741 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
741 | self.__showprofile = showprofile |
|
742 | self.__showprofile = showprofile | |
742 | self.nplots = nplots |
|
743 | self.nplots = nplots | |
743 |
|
744 | |||
744 | ncolspan = 1 |
|
745 | ncolspan = 1 | |
745 | colspan = 1 |
|
746 | colspan = 1 | |
746 | if showprofile: |
|
747 | if showprofile: | |
747 | ncolspan = 7 |
|
748 | ncolspan = 7 | |
748 | colspan = 6 |
|
749 | colspan = 6 | |
749 | self.__nsubplots = 2 |
|
750 | self.__nsubplots = 2 | |
750 |
|
751 | |||
751 | self.createFigure(idfigure = idfigure, |
|
752 | self.createFigure(idfigure = idfigure, | |
752 | wintitle = wintitle, |
|
753 | wintitle = wintitle, | |
753 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
754 | widthplot = self.WIDTH + self.WIDTHPROF, | |
754 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
755 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
755 |
|
756 | |||
756 | nrow, ncol = self.getSubplots() |
|
757 | nrow, ncol = self.getSubplots() | |
757 |
|
758 | |||
758 | for y in range(nrow): |
|
759 | for y in range(nrow): | |
759 | for x in range(ncol): |
|
760 | for x in range(ncol): | |
760 |
|
761 | |||
761 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
762 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
762 |
|
763 | |||
763 | if showprofile: |
|
764 | if showprofile: | |
764 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
765 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
765 |
|
766 | |||
766 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', |
|
767 | def run(self, dataOut, idfigure, wintitle="", pairsList=None, showprofile='True', | |
767 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
768 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
768 | timerange=None, |
|
769 | timerange=None, | |
769 |
save=False, figpath='./', figfile=None |
|
770 | save=False, figpath='./', figfile=None, | |
|
771 | coherence_cmap='jet', phase_cmap='RdBu_r'): | |||
770 |
|
772 | |||
771 | if pairsList == None: |
|
773 | if pairsList == None: | |
772 | pairsIndexList = dataOut.pairsIndexList |
|
774 | pairsIndexList = dataOut.pairsIndexList | |
773 | else: |
|
775 | else: | |
774 | pairsIndexList = [] |
|
776 | pairsIndexList = [] | |
775 | for pair in pairsList: |
|
777 | for pair in pairsList: | |
776 | if pair not in dataOut.pairsList: |
|
778 | if pair not in dataOut.pairsList: | |
777 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
779 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
778 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
780 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
779 |
|
781 | |||
780 | if timerange != None: |
|
782 | if timerange != None: | |
781 | self.timerange = timerange |
|
783 | self.timerange = timerange | |
782 |
|
784 | |||
783 | if pairsIndexList == []: |
|
785 | if pairsIndexList == []: | |
784 | return |
|
786 | return | |
785 |
|
787 | |||
786 | if len(pairsIndexList) > 4: |
|
788 | if len(pairsIndexList) > 4: | |
787 | pairsIndexList = pairsIndexList[0:4] |
|
789 | pairsIndexList = pairsIndexList[0:4] | |
788 |
|
790 | |||
789 | tmin = None |
|
791 | tmin = None | |
790 | tmax = None |
|
792 | tmax = None | |
791 | x = dataOut.getTimeRange() |
|
793 | x = dataOut.getTimeRange() | |
792 | y = dataOut.getHeiRange() |
|
794 | y = dataOut.getHeiRange() | |
793 |
|
795 | |||
794 | thisDatetime = dataOut.datatime |
|
796 | thisDatetime = dataOut.datatime | |
795 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
797 | title = "CoherenceMap: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
796 | xlabel = "" |
|
798 | xlabel = "" | |
797 | ylabel = "Range (Km)" |
|
799 | ylabel = "Range (Km)" | |
798 |
|
800 | |||
799 | if not self.__isConfig: |
|
801 | if not self.__isConfig: | |
800 | nplots = len(pairsIndexList) |
|
802 | nplots = len(pairsIndexList) | |
801 | self.setup(idfigure=idfigure, |
|
803 | self.setup(idfigure=idfigure, | |
802 | nplots=nplots, |
|
804 | nplots=nplots, | |
803 | wintitle=wintitle, |
|
805 | wintitle=wintitle, | |
804 | showprofile=showprofile) |
|
806 | showprofile=showprofile) | |
805 |
|
807 | |||
806 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
808 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
807 | if ymin == None: ymin = numpy.nanmin(y) |
|
809 | if ymin == None: ymin = numpy.nanmin(y) | |
808 | if ymax == None: ymax = numpy.nanmax(y) |
|
810 | if ymax == None: ymax = numpy.nanmax(y) | |
809 |
|
811 | |||
810 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
812 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
811 |
|
813 | |||
812 | self.__isConfig = True |
|
814 | self.__isConfig = True | |
813 |
|
815 | |||
814 | self.setWinTitle(title) |
|
816 | self.setWinTitle(title) | |
815 |
|
817 | |||
816 | for i in range(self.nplots): |
|
818 | for i in range(self.nplots): | |
817 |
|
819 | |||
818 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
820 | pair = dataOut.pairsList[pairsIndexList[i]] | |
819 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
821 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
820 |
coherence = numpy.a |
|
822 | avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) | |
821 |
|
|
823 | coherence = numpy.abs(avgcoherenceComplex) | |
822 | z = avg.reshape((1,-1)) |
|
824 | # coherence = numpy.abs(coherenceComplex) | |
|
825 | # avg = numpy.average(coherence, axis=0) | |||
|
826 | ||||
|
827 | z = coherence.reshape((1,-1)) | |||
823 |
|
828 | |||
824 | counter = 0 |
|
829 | counter = 0 | |
825 |
|
830 | |||
826 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
831 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
827 | axes = self.axesList[i*self.__nsubplots*2] |
|
832 | axes = self.axesList[i*self.__nsubplots*2] | |
828 | axes.pcolor(x, y, z, |
|
833 | axes.pcolor(x, y, z, | |
829 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
834 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
830 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
835 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
831 | ticksize=9, cblabel='', cbsize="1%") |
|
836 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
832 |
|
837 | |||
833 | if self.__showprofile: |
|
838 | if self.__showprofile: | |
834 | counter += 1 |
|
839 | counter += 1 | |
835 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
840 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
836 |
axes.pline( |
|
841 | axes.pline(coherence, y, | |
837 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, |
|
842 | xmin=0, xmax=1, ymin=ymin, ymax=ymax, | |
838 | xlabel='', ylabel='', title='', ticksize=7, |
|
843 | xlabel='', ylabel='', title='', ticksize=7, | |
839 | ytick_visible=False, nxticks=5, |
|
844 | ytick_visible=False, nxticks=5, | |
840 | grid='x') |
|
845 | grid='x') | |
841 |
|
846 | |||
842 | counter += 1 |
|
847 | counter += 1 | |
843 | phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
848 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
844 | avg = numpy.average(phase, axis=0) |
|
849 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
845 | z = avg.reshape((1,-1)) |
|
850 | # avg = numpy.average(phase, axis=0) | |
|
851 | z = phase.reshape((1,-1)) | |||
846 |
|
852 | |||
847 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
853 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
848 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
854 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
849 | axes.pcolor(x, y, z, |
|
855 | axes.pcolor(x, y, z, | |
850 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
856 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
851 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
857 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
852 |
ticksize=9, cblabel='', colormap= |
|
858 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
853 |
|
859 | |||
854 | if self.__showprofile: |
|
860 | if self.__showprofile: | |
855 | counter += 1 |
|
861 | counter += 1 | |
856 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
862 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
857 |
axes.pline( |
|
863 | axes.pline(phase, y, | |
858 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
864 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
859 | xlabel='', ylabel='', title='', ticksize=7, |
|
865 | xlabel='', ylabel='', title='', ticksize=7, | |
860 | ytick_visible=False, nxticks=4, |
|
866 | ytick_visible=False, nxticks=4, | |
861 | grid='x') |
|
867 | grid='x') | |
862 |
|
868 | |||
863 | self.draw() |
|
869 | self.draw() | |
864 |
|
870 | |||
865 | if save: |
|
871 | if save: | |
866 |
|
872 | |||
867 | if figfile == None: |
|
873 | if figfile == None: | |
868 | figfile = self.getFilename(name = self.name) |
|
874 | figfile = self.getFilename(name = self.name) | |
869 |
|
875 | |||
870 | self.saveFigure(figpath, figfile) |
|
876 | self.saveFigure(figpath, figfile) | |
871 |
|
877 | |||
872 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
878 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
873 | self.__isConfig = False |
|
879 | self.__isConfig = False | |
874 |
|
880 | |||
875 | class RTIfromNoise(Figure): |
|
881 | class RTIfromNoise(Figure): | |
876 |
|
882 | |||
877 | __isConfig = None |
|
883 | __isConfig = None | |
878 | __nsubplots = None |
|
884 | __nsubplots = None | |
879 |
|
885 | |||
880 | PREFIX = 'rtinoise' |
|
886 | PREFIX = 'rtinoise' | |
881 |
|
887 | |||
882 | def __init__(self): |
|
888 | def __init__(self): | |
883 |
|
889 | |||
884 | self.timerange = 24*60*60 |
|
890 | self.timerange = 24*60*60 | |
885 | self.__isConfig = False |
|
891 | self.__isConfig = False | |
886 | self.__nsubplots = 1 |
|
892 | self.__nsubplots = 1 | |
887 |
|
893 | |||
888 | self.WIDTH = 820 |
|
894 | self.WIDTH = 820 | |
889 | self.HEIGHT = 200 |
|
895 | self.HEIGHT = 200 | |
890 | self.WIDTHPROF = 120 |
|
896 | self.WIDTHPROF = 120 | |
891 | self.HEIGHTPROF = 0 |
|
897 | self.HEIGHTPROF = 0 | |
892 | self.xdata = None |
|
898 | self.xdata = None | |
893 | self.ydata = None |
|
899 | self.ydata = None | |
894 |
|
900 | |||
895 | def getSubplots(self): |
|
901 | def getSubplots(self): | |
896 |
|
902 | |||
897 | ncol = 1 |
|
903 | ncol = 1 | |
898 | nrow = 1 |
|
904 | nrow = 1 | |
899 |
|
905 | |||
900 | return nrow, ncol |
|
906 | return nrow, ncol | |
901 |
|
907 | |||
902 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
908 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
903 |
|
909 | |||
904 | self.__showprofile = showprofile |
|
910 | self.__showprofile = showprofile | |
905 | self.nplots = nplots |
|
911 | self.nplots = nplots | |
906 |
|
912 | |||
907 | ncolspan = 7 |
|
913 | ncolspan = 7 | |
908 | colspan = 6 |
|
914 | colspan = 6 | |
909 | self.__nsubplots = 2 |
|
915 | self.__nsubplots = 2 | |
910 |
|
916 | |||
911 | self.createFigure(idfigure = idfigure, |
|
917 | self.createFigure(idfigure = idfigure, | |
912 | wintitle = wintitle, |
|
918 | wintitle = wintitle, | |
913 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
919 | widthplot = self.WIDTH+self.WIDTHPROF, | |
914 | heightplot = self.HEIGHT+self.HEIGHTPROF) |
|
920 | heightplot = self.HEIGHT+self.HEIGHTPROF) | |
915 |
|
921 | |||
916 | nrow, ncol = self.getSubplots() |
|
922 | nrow, ncol = self.getSubplots() | |
917 |
|
923 | |||
918 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
924 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
919 |
|
925 | |||
920 |
|
926 | |||
921 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
927 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', | |
922 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
928 | xmin=None, xmax=None, ymin=None, ymax=None, | |
923 | timerange=None, |
|
929 | timerange=None, | |
924 | save=False, figpath='./', figfile=None): |
|
930 | save=False, figpath='./', figfile=None): | |
925 |
|
931 | |||
926 | if channelList == None: |
|
932 | if channelList == None: | |
927 | channelIndexList = dataOut.channelIndexList |
|
933 | channelIndexList = dataOut.channelIndexList | |
928 | channelList = dataOut.channelList |
|
934 | channelList = dataOut.channelList | |
929 | else: |
|
935 | else: | |
930 | channelIndexList = [] |
|
936 | channelIndexList = [] | |
931 | for channel in channelList: |
|
937 | for channel in channelList: | |
932 | if channel not in dataOut.channelList: |
|
938 | if channel not in dataOut.channelList: | |
933 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
939 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
934 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
940 | channelIndexList.append(dataOut.channelList.index(channel)) | |
935 |
|
941 | |||
936 | if timerange != None: |
|
942 | if timerange != None: | |
937 | self.timerange = timerange |
|
943 | self.timerange = timerange | |
938 |
|
944 | |||
939 | tmin = None |
|
945 | tmin = None | |
940 | tmax = None |
|
946 | tmax = None | |
941 | x = dataOut.getTimeRange() |
|
947 | x = dataOut.getTimeRange() | |
942 | y = dataOut.getHeiRange() |
|
948 | y = dataOut.getHeiRange() | |
943 | factor = dataOut.normFactor |
|
949 | factor = dataOut.normFactor | |
944 | noise = dataOut.getNoise()/factor |
|
950 | noise = dataOut.getNoise()/factor | |
945 | noisedB = 10*numpy.log10(noise) |
|
951 | noisedB = 10*numpy.log10(noise) | |
946 |
|
952 | |||
947 | thisDatetime = dataOut.datatime |
|
953 | thisDatetime = dataOut.datatime | |
948 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
954 | title = "RTI Noise: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
949 | xlabel = "" |
|
955 | xlabel = "" | |
950 | ylabel = "Range (Km)" |
|
956 | ylabel = "Range (Km)" | |
951 |
|
957 | |||
952 | if not self.__isConfig: |
|
958 | if not self.__isConfig: | |
953 |
|
959 | |||
954 | nplots = 1 |
|
960 | nplots = 1 | |
955 |
|
961 | |||
956 | self.setup(idfigure=idfigure, |
|
962 | self.setup(idfigure=idfigure, | |
957 | nplots=nplots, |
|
963 | nplots=nplots, | |
958 | wintitle=wintitle, |
|
964 | wintitle=wintitle, | |
959 | showprofile=showprofile) |
|
965 | showprofile=showprofile) | |
960 |
|
966 | |||
961 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
967 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
962 | if ymin == None: ymin = numpy.nanmin(noisedB) |
|
968 | if ymin == None: ymin = numpy.nanmin(noisedB) | |
963 | if ymax == None: ymax = numpy.nanmax(noisedB) |
|
969 | if ymax == None: ymax = numpy.nanmax(noisedB) | |
964 |
|
970 | |||
965 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
971 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
966 | self.__isConfig = True |
|
972 | self.__isConfig = True | |
967 |
|
973 | |||
968 | self.xdata = numpy.array([]) |
|
974 | self.xdata = numpy.array([]) | |
969 | self.ydata = numpy.array([]) |
|
975 | self.ydata = numpy.array([]) | |
970 |
|
976 | |||
971 | self.setWinTitle(title) |
|
977 | self.setWinTitle(title) | |
972 |
|
978 | |||
973 |
|
979 | |||
974 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
980 | title = "RTI Noise %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
975 |
|
981 | |||
976 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
982 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
977 | axes = self.axesList[0] |
|
983 | axes = self.axesList[0] | |
978 |
|
984 | |||
979 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
985 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
980 |
|
986 | |||
981 | if len(self.ydata)==0: |
|
987 | if len(self.ydata)==0: | |
982 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
988 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
983 | else: |
|
989 | else: | |
984 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
990 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
985 |
|
991 | |||
986 |
|
992 | |||
987 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
993 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
988 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
994 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
989 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
995 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
990 | XAxisAsTime=True |
|
996 | XAxisAsTime=True | |
991 | ) |
|
997 | ) | |
992 |
|
998 | |||
993 | self.draw() |
|
999 | self.draw() | |
994 |
|
1000 | |||
995 | if save: |
|
1001 | if save: | |
996 |
|
1002 | |||
997 | if figfile == None: |
|
1003 | if figfile == None: | |
998 | figfile = self.getFilename(name = self.name) |
|
1004 | figfile = self.getFilename(name = self.name) | |
999 |
|
1005 | |||
1000 | self.saveFigure(figpath, figfile) |
|
1006 | self.saveFigure(figpath, figfile) | |
1001 |
|
1007 | |||
1002 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1008 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1003 | self.__isConfig = False |
|
1009 | self.__isConfig = False | |
1004 | del self.xdata |
|
1010 | del self.xdata | |
1005 | del self.ydata |
|
1011 | del self.ydata | |
1006 | No newline at end of file |
|
1012 |
General Comments 0
You need to be logged in to leave comments.
Login now