@@ -0,0 +1,47 | |||
|
1 | import os, sys | |
|
2 | ||
|
3 | path = os.path.split(os.getcwd())[0] | |
|
4 | sys.path.append(path) | |
|
5 | ||
|
6 | from controller import * | |
|
7 | ||
|
8 | desc = "AMISR Experiment Test" | |
|
9 | filename = "amisr.xml" | |
|
10 | ||
|
11 | controllerObj = Project() | |
|
12 | ||
|
13 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
14 | ||
|
15 | path = '/home/administrator/Documents/amisr' | |
|
16 | ||
|
17 | readUnitConfObj = controllerObj.addReadUnit(datatype='AMISR', | |
|
18 | path=path, | |
|
19 | startDate='2014/08/18', | |
|
20 | endDate='2014/08/18', | |
|
21 | startTime='00:00:00', | |
|
22 | endTime='23:59:59', | |
|
23 | walk=1) | |
|
24 | ||
|
25 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
26 | ||
|
27 | opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='other') | |
|
28 | opObj11.addParameter(name='id', value='101', format='int') | |
|
29 | opObj11.addParameter(name='wintitle', value='AMISR', format='str') | |
|
30 | opObj11.addParameter(name='type', value='iq', format='str') | |
|
31 | ||
|
32 | opObj11 = procUnitConfObjBeam1.addOperation(name='ProfileSelector', optype='other') | |
|
33 | opObj11.addParameter(name='profileRangeList', value='0,81', format='intlist') | |
|
34 | ||
|
35 | opObj11 = procUnitConfObj0.addOperation(name='PowerProfile', optype='other') | |
|
36 | opObj11.addParameter(name='id', value='102', format='int') | |
|
37 | opObj11.addParameter(name='wintitle', value='AMISR Power Profile', format='str') | |
|
38 | ||
|
39 | ||
|
40 | print "Escribiendo el archivo XML" | |
|
41 | controllerObj.writeXml(filename) | |
|
42 | print "Leyendo el archivo XML" | |
|
43 | controllerObj.readXml(filename) | |
|
44 | ||
|
45 | controllerObj.createObjects() | |
|
46 | controllerObj.connectObjects() | |
|
47 | controllerObj.run() |
@@ -0,0 +1,93 | |||
|
1 | import os, sys | |
|
2 | ||
|
3 | path = os.path.split(os.getcwd())[0] | |
|
4 | sys.path.append(path) | |
|
5 | ||
|
6 | from controller import * | |
|
7 | ||
|
8 | desc = "AMISR Experiment Test" | |
|
9 | filename = "amisr.xml" | |
|
10 | ||
|
11 | controllerObj = Project() | |
|
12 | ||
|
13 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
14 | ||
|
15 | path = '/home/administrator/Documents/amisr' | |
|
16 | ||
|
17 | readUnitConfObj = controllerObj.addReadUnit(datatype='AMISR', | |
|
18 | path=path, | |
|
19 | startDate='2014/08/18', | |
|
20 | endDate='2014/08/18', | |
|
21 | startTime='00:00:00', | |
|
22 | endTime='23:59:59', | |
|
23 | walk=1) | |
|
24 | ||
|
25 | procUnitConfObjBeam0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
26 | procUnitConfObjBeam1 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
27 | procUnitConfObjBeam2 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
28 | procUnitConfObjBeam3 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
29 | procUnitConfObjBeam4 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
30 | procUnitConfObjBeam5 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
31 | procUnitConfObjBeam6 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
|
32 | ||
|
33 | # Beam0 | |
|
34 | opObj11 = procUnitConfObjBeam0.addOperation(name='ProfileSelector', optype='other') | |
|
35 | opObj11.addParameter(name='profileRangeList', value='0,81', format='intlist') | |
|
36 | ||
|
37 | opObj11 = procUnitConfObjBeam0.addOperation(name='PowerProfile', optype='other') | |
|
38 | opObj11.addParameter(name='id', value='10', format='int') | |
|
39 | opObj11.addParameter(name='wintitle', value='AMISR Beam0 - Power Profile', format='str') | |
|
40 | ||
|
41 | # Beam1 | |
|
42 | opObj11 = procUnitConfObjBeam1.addOperation(name='ProfileSelector', optype='other') | |
|
43 | opObj11.addParameter(name='profileRangeList', value='82,209', format='intlist') | |
|
44 | opObj11 = procUnitConfObjBeam1.addOperation(name='PowerProfile', optype='other') | |
|
45 | opObj11.addParameter(name='id', value='11', format='int') | |
|
46 | opObj11.addParameter(name='wintitle', value='AMISR Beam1 - Power Profile', format='str') | |
|
47 | ||
|
48 | # # Beam2 | |
|
49 | opObj11 = procUnitConfObjBeam2.addOperation(name='ProfileSelector', optype='other') | |
|
50 | opObj11.addParameter(name='profileRangeList', value='210,337', format='intlist') | |
|
51 | opObj11 = procUnitConfObjBeam2.addOperation(name='PowerProfile', optype='other') | |
|
52 | opObj11.addParameter(name='id', value='12', format='int') | |
|
53 | opObj11.addParameter(name='wintitle', value='AMISR Beam2 - Power Profile', format='str') | |
|
54 | # | |
|
55 | # # Beam3 | |
|
56 | opObj11 = procUnitConfObjBeam3.addOperation(name='ProfileSelector', optype='other') | |
|
57 | opObj11.addParameter(name='profileRangeList', value='338,465', format='intlist') | |
|
58 | opObj11 = procUnitConfObjBeam3.addOperation(name='PowerProfile', optype='other') | |
|
59 | opObj11.addParameter(name='id', value='13', format='int') | |
|
60 | opObj11.addParameter(name='wintitle', value='AMISR Beam3 - Power Profile', format='str') | |
|
61 | ||
|
62 | # # Beam4 | |
|
63 | opObj11 = procUnitConfObjBeam4.addOperation(name='ProfileSelector', optype='other') | |
|
64 | opObj11.addParameter(name='profileRangeList', value='466,593', format='intlist') | |
|
65 | opObj11 = procUnitConfObjBeam4.addOperation(name='PowerProfile', optype='other') | |
|
66 | opObj11.addParameter(name='id', value='14', format='int') | |
|
67 | opObj11.addParameter(name='wintitle', value='AMISR Beam4 - Power Profile', format='str') | |
|
68 | # | |
|
69 | # # Beam5 | |
|
70 | # opObj11 = procUnitConfObjBeam5.addOperation(name='ProfileSelector', optype='other') | |
|
71 | # opObj11.addParameter(name='profileRangeList', value='594,721', format='intlist') | |
|
72 | # opObj11 = procUnitConfObjBeam5.addOperation(name='PowerProfile', optype='other') | |
|
73 | # opObj11.addParameter(name='id', value='15', format='int') | |
|
74 | # opObj11.addParameter(name='wintitle', value='AMISR Beam5 - Power Profile', format='str') | |
|
75 | # | |
|
76 | # # Beam6 | |
|
77 | # opObj11 = procUnitConfObjBeam6.addOperation(name='ProfileSelector', optype='other') | |
|
78 | # opObj11.addParameter(name='profileRangeList', value='722,849', format='intlist') | |
|
79 | # opObj11 = procUnitConfObjBeam6.addOperation(name='PowerProfile', optype='other') | |
|
80 | # opObj11.addParameter(name='id', value='16', format='int') | |
|
81 | # opObj11.addParameter(name='wintitle', value='AMISR Beam6 - Power Profile', format='str') | |
|
82 | ||
|
83 | ||
|
84 | ||
|
85 | ||
|
86 | print "Escribiendo el archivo XML" | |
|
87 | controllerObj.writeXml(filename) | |
|
88 | print "Leyendo el archivo XML" | |
|
89 | controllerObj.readXml(filename) | |
|
90 | ||
|
91 | controllerObj.createObjects() | |
|
92 | controllerObj.connectObjects() | |
|
93 | controllerObj.run() |
@@ -1,383 +1,383 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import sys |
|
4 | 4 | import matplotlib |
|
5 | 5 | |
|
6 | 6 | if 'linux' in sys.platform: |
|
7 | 7 | matplotlib.use("TKAgg") |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 | 10 | matplotlib.use("GTKAgg") |
|
11 | 11 | |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
|
14 | 14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
15 | 15 | from matplotlib.ticker import * |
|
16 | 16 | |
|
17 | 17 | ########################################### |
|
18 | 18 | #Actualizacion de las funciones del driver |
|
19 | 19 | ########################################### |
|
20 | 20 | |
|
21 | 21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): |
|
22 | 22 | |
|
23 | 23 | matplotlib.pyplot.ioff() |
|
24 | 24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) |
|
25 | 25 | fig.canvas.manager.set_window_title(wintitle) |
|
26 | 26 | fig.canvas.manager.resize(width, height) |
|
27 | 27 | matplotlib.pyplot.ion() |
|
28 | 28 | if show: |
|
29 | 29 | matplotlib.pyplot.show() |
|
30 | 30 | |
|
31 | 31 | return fig |
|
32 | 32 | |
|
33 | 33 | def closeFigure(show=True): |
|
34 | 34 | |
|
35 | 35 | matplotlib.pyplot.ioff() |
|
36 | 36 | if show: |
|
37 | 37 | matplotlib.pyplot.show() |
|
38 | 38 | |
|
39 | 39 | return |
|
40 | 40 | |
|
41 | 41 | def saveFigure(fig, filename): |
|
42 | 42 | |
|
43 | 43 | matplotlib.pyplot.ioff() |
|
44 | 44 | fig.savefig(filename) |
|
45 | 45 | matplotlib.pyplot.ion() |
|
46 | 46 | |
|
47 | 47 | def setWinTitle(fig, title): |
|
48 | 48 | |
|
49 | 49 | fig.canvas.manager.set_window_title(title) |
|
50 | 50 | |
|
51 | 51 | def setTitle(fig, title): |
|
52 | 52 | |
|
53 | 53 | fig.suptitle(title) |
|
54 | 54 | |
|
55 | 55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
56 | 56 | |
|
57 | 57 | matplotlib.pyplot.ioff() |
|
58 | 58 | matplotlib.pyplot.figure(fig.number) |
|
59 | 59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
60 | 60 | (xpos, ypos), |
|
61 | 61 | colspan=colspan, |
|
62 | 62 | rowspan=rowspan) |
|
63 | 63 | |
|
64 | 64 | matplotlib.pyplot.ion() |
|
65 | 65 | return axes |
|
66 | 66 | |
|
67 | 67 | def setAxesText(ax, text): |
|
68 | 68 | |
|
69 | 69 | ax.annotate(text, |
|
70 | 70 | xy = (.1, .99), |
|
71 | 71 | xycoords = 'figure fraction', |
|
72 | 72 | horizontalalignment = 'left', |
|
73 | 73 | verticalalignment = 'top', |
|
74 | 74 | fontsize = 10) |
|
75 | 75 | |
|
76 | 76 | def printLabels(ax, xlabel, ylabel, title): |
|
77 | 77 | |
|
78 | 78 | ax.set_xlabel(xlabel, size=11) |
|
79 | 79 | ax.set_ylabel(ylabel, size=11) |
|
80 | 80 | ax.set_title(title, size=12) |
|
81 | 81 | |
|
82 | 82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
83 | 83 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
84 | 84 | nxticks=4, nyticks=10, |
|
85 | grid=None): | |
|
85 | grid=None,color='blue'): | |
|
86 | 86 | |
|
87 | 87 | """ |
|
88 | 88 | |
|
89 | 89 | Input: |
|
90 | 90 | grid : None, 'both', 'x', 'y' |
|
91 | 91 | """ |
|
92 | 92 | |
|
93 | 93 | matplotlib.pyplot.ioff() |
|
94 | 94 | |
|
95 | 95 | ax.set_xlim([xmin,xmax]) |
|
96 | 96 | ax.set_ylim([ymin,ymax]) |
|
97 | 97 | |
|
98 | 98 | printLabels(ax, xlabel, ylabel, title) |
|
99 | 99 | |
|
100 | 100 | ###################################################### |
|
101 | 101 | if (xmax-xmin)<=1: |
|
102 | 102 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
103 | 103 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
104 | 104 | ax.set_xticks(xtickspos) |
|
105 | 105 | else: |
|
106 | 106 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
107 | 107 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
108 | 108 | ax.set_xticks(xtickspos) |
|
109 | 109 | |
|
110 | 110 | for tick in ax.get_xticklabels(): |
|
111 | 111 | tick.set_visible(xtick_visible) |
|
112 | 112 | |
|
113 | 113 | for tick in ax.xaxis.get_major_ticks(): |
|
114 | 114 | tick.label.set_fontsize(ticksize) |
|
115 | 115 | |
|
116 | 116 | ###################################################### |
|
117 | 117 | for tick in ax.get_yticklabels(): |
|
118 | 118 | tick.set_visible(ytick_visible) |
|
119 | 119 | |
|
120 | 120 | for tick in ax.yaxis.get_major_ticks(): |
|
121 | 121 | tick.label.set_fontsize(ticksize) |
|
122 | 122 | |
|
123 | ax.plot(x, y) | |
|
123 | ax.plot(x, y, color=color) | |
|
124 | 124 | iplot = ax.lines[-1] |
|
125 | 125 | |
|
126 | 126 | ###################################################### |
|
127 | 127 | if '0.' in matplotlib.__version__[0:2]: |
|
128 | 128 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
129 | 129 | return iplot |
|
130 | 130 | |
|
131 | 131 | if '1.0.' in matplotlib.__version__[0:4]: |
|
132 | 132 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
133 | 133 | return iplot |
|
134 | 134 | |
|
135 | 135 | if grid != None: |
|
136 | 136 | ax.grid(b=True, which='major', axis=grid) |
|
137 | 137 | |
|
138 | 138 | matplotlib.pyplot.tight_layout() |
|
139 | 139 | |
|
140 | 140 | matplotlib.pyplot.ion() |
|
141 | 141 | |
|
142 | 142 | return iplot |
|
143 | 143 | |
|
144 | 144 | def set_linedata(ax, x, y, idline): |
|
145 | 145 | |
|
146 | 146 | ax.lines[idline].set_data(x,y) |
|
147 | 147 | |
|
148 | 148 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
149 | 149 | |
|
150 | 150 | ax = iplot.get_axes() |
|
151 | 151 | |
|
152 | 152 | printLabels(ax, xlabel, ylabel, title) |
|
153 | 153 | |
|
154 | 154 | set_linedata(ax, x, y, idline=0) |
|
155 | 155 | |
|
156 | 156 | def addpline(ax, x, y, color, linestyle, lw): |
|
157 | 157 | |
|
158 | 158 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
159 | 159 | |
|
160 | 160 | |
|
161 | 161 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
162 | 162 | xlabel='', ylabel='', title='', ticksize = 9, |
|
163 | 163 | colormap='jet',cblabel='', cbsize="5%", |
|
164 | 164 | XAxisAsTime=False): |
|
165 | 165 | |
|
166 | 166 | matplotlib.pyplot.ioff() |
|
167 | 167 | |
|
168 | 168 | divider = make_axes_locatable(ax) |
|
169 | 169 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
170 | 170 | fig = ax.get_figure() |
|
171 | 171 | fig.add_axes(ax_cb) |
|
172 | 172 | |
|
173 | 173 | ax.set_xlim([xmin,xmax]) |
|
174 | 174 | ax.set_ylim([ymin,ymax]) |
|
175 | 175 | |
|
176 | 176 | printLabels(ax, xlabel, ylabel, title) |
|
177 | 177 | |
|
178 | 178 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
179 | 179 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
180 | 180 | cb.set_label(cblabel) |
|
181 | 181 | |
|
182 | 182 | # for tl in ax_cb.get_yticklabels(): |
|
183 | 183 | # tl.set_visible(True) |
|
184 | 184 | |
|
185 | 185 | for tick in ax.yaxis.get_major_ticks(): |
|
186 | 186 | tick.label.set_fontsize(ticksize) |
|
187 | 187 | |
|
188 | 188 | for tick in ax.xaxis.get_major_ticks(): |
|
189 | 189 | tick.label.set_fontsize(ticksize) |
|
190 | 190 | |
|
191 | 191 | for tick in cb.ax.get_yticklabels(): |
|
192 | 192 | tick.set_fontsize(ticksize) |
|
193 | 193 | |
|
194 | 194 | ax_cb.yaxis.tick_right() |
|
195 | 195 | |
|
196 | 196 | if '0.' in matplotlib.__version__[0:2]: |
|
197 | 197 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
198 | 198 | return imesh |
|
199 | 199 | |
|
200 | 200 | if '1.0.' in matplotlib.__version__[0:4]: |
|
201 | 201 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
202 | 202 | return imesh |
|
203 | 203 | |
|
204 | 204 | matplotlib.pyplot.tight_layout() |
|
205 | 205 | |
|
206 | 206 | if XAxisAsTime: |
|
207 | 207 | |
|
208 | 208 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
209 | 209 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
210 | 210 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
211 | 211 | |
|
212 | 212 | matplotlib.pyplot.ion() |
|
213 | 213 | return imesh |
|
214 | 214 | |
|
215 | 215 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
216 | 216 | |
|
217 | 217 | z = z.T |
|
218 | 218 | |
|
219 | 219 | ax = imesh.get_axes() |
|
220 | 220 | |
|
221 | 221 | printLabels(ax, xlabel, ylabel, title) |
|
222 | 222 | |
|
223 | 223 | imesh.set_array(z.ravel()) |
|
224 | 224 | |
|
225 | 225 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
226 | 226 | |
|
227 | 227 | printLabels(ax, xlabel, ylabel, title) |
|
228 | 228 | |
|
229 | 229 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
230 | 230 | |
|
231 | 231 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
232 | 232 | |
|
233 | 233 | printLabels(ax, xlabel, ylabel, title) |
|
234 | 234 | |
|
235 | 235 | ax.collections.remove(ax.collections[0]) |
|
236 | 236 | |
|
237 | 237 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
238 | 238 | |
|
239 | 239 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
240 | 240 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
241 | 241 | nxticks=4, nyticks=10, |
|
242 | 242 | grid=None): |
|
243 | 243 | |
|
244 | 244 | """ |
|
245 | 245 | |
|
246 | 246 | Input: |
|
247 | 247 | grid : None, 'both', 'x', 'y' |
|
248 | 248 | """ |
|
249 | 249 | |
|
250 | 250 | matplotlib.pyplot.ioff() |
|
251 | 251 | |
|
252 | 252 | lines = ax.plot(x.T, y) |
|
253 | 253 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
254 | 254 | leg.get_frame().set_alpha(0.5) |
|
255 | 255 | ax.set_xlim([xmin,xmax]) |
|
256 | 256 | ax.set_ylim([ymin,ymax]) |
|
257 | 257 | printLabels(ax, xlabel, ylabel, title) |
|
258 | 258 | |
|
259 | 259 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
260 | 260 | ax.set_xticks(xtickspos) |
|
261 | 261 | |
|
262 | 262 | for tick in ax.get_xticklabels(): |
|
263 | 263 | tick.set_visible(xtick_visible) |
|
264 | 264 | |
|
265 | 265 | for tick in ax.xaxis.get_major_ticks(): |
|
266 | 266 | tick.label.set_fontsize(ticksize) |
|
267 | 267 | |
|
268 | 268 | for tick in ax.get_yticklabels(): |
|
269 | 269 | tick.set_visible(ytick_visible) |
|
270 | 270 | |
|
271 | 271 | for tick in ax.yaxis.get_major_ticks(): |
|
272 | 272 | tick.label.set_fontsize(ticksize) |
|
273 | 273 | |
|
274 | 274 | iplot = ax.lines[-1] |
|
275 | 275 | |
|
276 | 276 | if '0.' in matplotlib.__version__[0:2]: |
|
277 | 277 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
278 | 278 | return iplot |
|
279 | 279 | |
|
280 | 280 | if '1.0.' in matplotlib.__version__[0:4]: |
|
281 | 281 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
282 | 282 | return iplot |
|
283 | 283 | |
|
284 | 284 | if grid != None: |
|
285 | 285 | ax.grid(b=True, which='major', axis=grid) |
|
286 | 286 | |
|
287 | 287 | matplotlib.pyplot.tight_layout() |
|
288 | 288 | |
|
289 | 289 | matplotlib.pyplot.ion() |
|
290 | 290 | |
|
291 | 291 | return iplot |
|
292 | 292 | |
|
293 | 293 | |
|
294 | 294 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
295 | 295 | |
|
296 | 296 | ax = iplot.get_axes() |
|
297 | 297 | |
|
298 | 298 | printLabels(ax, xlabel, ylabel, title) |
|
299 | 299 | |
|
300 | 300 | for i in range(len(ax.lines)): |
|
301 | 301 | line = ax.lines[i] |
|
302 | 302 | line.set_data(x[i,:],y) |
|
303 | 303 | |
|
304 | 304 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
305 | 305 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
306 | 306 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
307 | 307 | grid=None, XAxisAsTime=False): |
|
308 | 308 | |
|
309 | 309 | """ |
|
310 | 310 | |
|
311 | 311 | Input: |
|
312 | 312 | grid : None, 'both', 'x', 'y' |
|
313 | 313 | """ |
|
314 | 314 | |
|
315 | 315 | matplotlib.pyplot.ioff() |
|
316 | 316 | |
|
317 | 317 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
318 | 318 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) |
|
319 | 319 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
320 | 320 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
321 | 321 | |
|
322 | 322 | for label in leg.get_texts(): label.set_fontsize(9) |
|
323 | 323 | |
|
324 | 324 | ax.set_xlim([xmin,xmax]) |
|
325 | 325 | ax.set_ylim([ymin,ymax]) |
|
326 | 326 | printLabels(ax, xlabel, ylabel, title) |
|
327 | 327 | |
|
328 | 328 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
329 | 329 | # ax.set_xticks(xtickspos) |
|
330 | 330 | |
|
331 | 331 | for tick in ax.get_xticklabels(): |
|
332 | 332 | tick.set_visible(xtick_visible) |
|
333 | 333 | |
|
334 | 334 | for tick in ax.xaxis.get_major_ticks(): |
|
335 | 335 | tick.label.set_fontsize(ticksize) |
|
336 | 336 | |
|
337 | 337 | for tick in ax.get_yticklabels(): |
|
338 | 338 | tick.set_visible(ytick_visible) |
|
339 | 339 | |
|
340 | 340 | for tick in ax.yaxis.get_major_ticks(): |
|
341 | 341 | tick.label.set_fontsize(ticksize) |
|
342 | 342 | |
|
343 | 343 | iplot = ax.lines[-1] |
|
344 | 344 | |
|
345 | 345 | if '0.' in matplotlib.__version__[0:2]: |
|
346 | 346 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
347 | 347 | return iplot |
|
348 | 348 | |
|
349 | 349 | if '1.0.' in matplotlib.__version__[0:4]: |
|
350 | 350 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
351 | 351 | return iplot |
|
352 | 352 | |
|
353 | 353 | if grid != None: |
|
354 | 354 | ax.grid(b=True, which='major', axis=grid) |
|
355 | 355 | |
|
356 | 356 | matplotlib.pyplot.tight_layout() |
|
357 | 357 | |
|
358 | 358 | if XAxisAsTime: |
|
359 | 359 | |
|
360 | 360 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
361 | 361 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
362 | 362 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
363 | 363 | |
|
364 | 364 | matplotlib.pyplot.ion() |
|
365 | 365 | |
|
366 | 366 | return iplot |
|
367 | 367 | |
|
368 | 368 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
369 | 369 | |
|
370 | 370 | ax = iplot.get_axes() |
|
371 | 371 | |
|
372 | 372 | printLabels(ax, xlabel, ylabel, title) |
|
373 | 373 | |
|
374 | 374 | for i in range(len(ax.lines)): |
|
375 | 375 | line = ax.lines[i] |
|
376 | 376 | line.set_data(x,y[i,:]) |
|
377 | 377 | |
|
378 | 378 | def draw(fig): |
|
379 | 379 | |
|
380 | 380 | if type(fig) == 'int': |
|
381 | 381 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
382 | 382 | |
|
383 | 383 | fig.canvas.draw() |
@@ -1,657 +1,690 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os, sys |
|
8 | 8 | import copy |
|
9 | 9 | import numpy |
|
10 | 10 | import datetime |
|
11 | 11 | |
|
12 | 12 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | def hildebrand_sekhon(data, navg): |
|
16 | 16 | |
|
17 | 17 | data = data.copy() |
|
18 | 18 | |
|
19 | 19 | sortdata = numpy.sort(data,axis=None) |
|
20 | 20 | lenOfData = len(sortdata) |
|
21 | 21 | nums_min = lenOfData/10 |
|
22 | 22 | |
|
23 | 23 | if (lenOfData/10) > 2: |
|
24 | 24 | nums_min = lenOfData/10 |
|
25 | 25 | else: |
|
26 | 26 | nums_min = 2 |
|
27 | 27 | |
|
28 | 28 | sump = 0. |
|
29 | 29 | |
|
30 | 30 | sumq = 0. |
|
31 | 31 | |
|
32 | 32 | j = 0 |
|
33 | 33 | |
|
34 | 34 | cont = 1 |
|
35 | 35 | |
|
36 | 36 | while((cont==1)and(j<lenOfData)): |
|
37 | 37 | |
|
38 | 38 | sump += sortdata[j] |
|
39 | 39 | |
|
40 | 40 | sumq += sortdata[j]**2 |
|
41 | 41 | |
|
42 | 42 | j += 1 |
|
43 | 43 | |
|
44 | 44 | if j > nums_min: |
|
45 | 45 | rtest = float(j)/(j-1) + 1.0/navg |
|
46 | 46 | if ((sumq*j) > (rtest*sump**2)): |
|
47 | 47 | j = j - 1 |
|
48 | 48 | sump = sump - sortdata[j] |
|
49 | 49 | sumq = sumq - sortdata[j]**2 |
|
50 | 50 | cont = 0 |
|
51 | 51 | |
|
52 | 52 | lnoise = sump /j |
|
53 | 53 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) |
|
54 | 54 | return lnoise |
|
55 | 55 | |
|
56 | 56 | class JROData: |
|
57 | 57 | |
|
58 | 58 | # m_BasicHeader = BasicHeader() |
|
59 | 59 | # m_ProcessingHeader = ProcessingHeader() |
|
60 | 60 | |
|
61 | 61 | systemHeaderObj = SystemHeader() |
|
62 | 62 | |
|
63 | 63 | radarControllerHeaderObj = RadarControllerHeader() |
|
64 | 64 | |
|
65 | 65 | # data = None |
|
66 | 66 | |
|
67 | 67 | type = None |
|
68 | 68 | |
|
69 | 69 | dtype = None |
|
70 | 70 | |
|
71 | 71 | # nChannels = None |
|
72 | 72 | |
|
73 | 73 | # nHeights = None |
|
74 | 74 | |
|
75 | 75 | nProfiles = None |
|
76 | 76 | |
|
77 | 77 | heightList = None |
|
78 | 78 | |
|
79 | 79 | channelList = None |
|
80 | 80 | |
|
81 | 81 | flagNoData = True |
|
82 | 82 | |
|
83 | 83 | flagTimeBlock = False |
|
84 | 84 | |
|
85 | 85 | useLocalTime = False |
|
86 | 86 | |
|
87 | 87 | utctime = None |
|
88 | 88 | |
|
89 | 89 | timeZone = None |
|
90 | 90 | |
|
91 | 91 | dstFlag = None |
|
92 | 92 | |
|
93 | 93 | errorCount = None |
|
94 | 94 | |
|
95 | 95 | blocksize = None |
|
96 | 96 | |
|
97 | 97 | nCode = None |
|
98 | 98 | |
|
99 | 99 | nBaud = None |
|
100 | 100 | |
|
101 | 101 | code = None |
|
102 | 102 | |
|
103 | 103 | flagDecodeData = False #asumo q la data no esta decodificada |
|
104 | 104 | |
|
105 | 105 | flagDeflipData = False #asumo q la data no esta sin flip |
|
106 | 106 | |
|
107 | 107 | flagShiftFFT = False |
|
108 | 108 | |
|
109 | 109 | ippSeconds = None |
|
110 | 110 | |
|
111 | 111 | timeInterval = None |
|
112 | 112 | |
|
113 | 113 | nCohInt = None |
|
114 | 114 | |
|
115 | 115 | noise = None |
|
116 | 116 | |
|
117 | 117 | windowOfFilter = 1 |
|
118 | 118 | |
|
119 | 119 | #Speed of ligth |
|
120 | 120 | C = 3e8 |
|
121 | 121 | |
|
122 | 122 | frequency = 49.92e6 |
|
123 | 123 | |
|
124 | 124 | realtime = False |
|
125 | 125 | |
|
126 | 126 | beacon_heiIndexList = None |
|
127 | 127 | |
|
128 | 128 | last_block = None |
|
129 | 129 | |
|
130 | 130 | blocknow = None |
|
131 | 131 | |
|
132 | 132 | def __init__(self): |
|
133 | 133 | |
|
134 | 134 | raise ValueError, "This class has not been implemented" |
|
135 | 135 | |
|
136 | 136 | def copy(self, inputObj=None): |
|
137 | 137 | |
|
138 | 138 | if inputObj == None: |
|
139 | 139 | return copy.deepcopy(self) |
|
140 | 140 | |
|
141 | 141 | for key in inputObj.__dict__.keys(): |
|
142 | 142 | self.__dict__[key] = inputObj.__dict__[key] |
|
143 | 143 | |
|
144 | 144 | def deepcopy(self): |
|
145 | 145 | |
|
146 | 146 | return copy.deepcopy(self) |
|
147 | 147 | |
|
148 | 148 | def isEmpty(self): |
|
149 | 149 | |
|
150 | 150 | return self.flagNoData |
|
151 | 151 | |
|
152 | 152 | def getNoise(self): |
|
153 | 153 | |
|
154 | 154 | raise ValueError, "Not implemented" |
|
155 | 155 | |
|
156 | 156 | def getNChannels(self): |
|
157 | 157 | |
|
158 | 158 | return len(self.channelList) |
|
159 | 159 | |
|
160 | 160 | def getChannelIndexList(self): |
|
161 | 161 | |
|
162 | 162 | return range(self.nChannels) |
|
163 | 163 | |
|
164 | 164 | def getNHeights(self): |
|
165 | 165 | |
|
166 | 166 | return len(self.heightList) |
|
167 | 167 | |
|
168 | 168 | def getHeiRange(self, extrapoints=0): |
|
169 | 169 | |
|
170 | 170 | heis = self.heightList |
|
171 | 171 | # deltah = self.heightList[1] - self.heightList[0] |
|
172 | 172 | # |
|
173 | 173 | # heis.append(self.heightList[-1]) |
|
174 | 174 | |
|
175 | 175 | return heis |
|
176 | 176 | |
|
177 | 177 | def getltctime(self): |
|
178 | 178 | |
|
179 | 179 | if self.useLocalTime: |
|
180 | 180 | return self.utctime - self.timeZone*60 |
|
181 | 181 | |
|
182 | 182 | return self.utctime |
|
183 | 183 | |
|
184 | 184 | def getDatatime(self): |
|
185 | 185 | |
|
186 | 186 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
187 | 187 | return datatime |
|
188 | 188 | |
|
189 | 189 | def getTimeRange(self): |
|
190 | 190 | |
|
191 | 191 | datatime = [] |
|
192 | 192 | |
|
193 | 193 | datatime.append(self.ltctime) |
|
194 | 194 | datatime.append(self.ltctime + self.timeInterval) |
|
195 | 195 | |
|
196 | 196 | datatime = numpy.array(datatime) |
|
197 | 197 | |
|
198 | 198 | return datatime |
|
199 | 199 | |
|
200 | 200 | def getFmax(self): |
|
201 | 201 | |
|
202 | 202 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
203 | 203 | |
|
204 | 204 | fmax = PRF/2. |
|
205 | 205 | |
|
206 | 206 | return fmax |
|
207 | 207 | |
|
208 | 208 | def getVmax(self): |
|
209 | 209 | |
|
210 | 210 | _lambda = self.C/self.frequency |
|
211 | 211 | |
|
212 | 212 | vmax = self.getFmax() * _lambda |
|
213 | 213 | |
|
214 | 214 | return vmax |
|
215 | 215 | |
|
216 | 216 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
217 | 217 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
218 | 218 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
219 | 219 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
220 | 220 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
221 | 221 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
222 | 222 | |
|
223 | 223 | class Voltage(JROData): |
|
224 | 224 | |
|
225 | 225 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
226 | 226 | data = None |
|
227 | 227 | |
|
228 | 228 | def __init__(self): |
|
229 | 229 | ''' |
|
230 | 230 | Constructor |
|
231 | 231 | ''' |
|
232 | 232 | |
|
233 | 233 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
234 | 234 | |
|
235 | 235 | self.systemHeaderObj = SystemHeader() |
|
236 | 236 | |
|
237 | 237 | self.type = "Voltage" |
|
238 | 238 | |
|
239 | 239 | self.data = None |
|
240 | 240 | |
|
241 | 241 | self.dtype = None |
|
242 | 242 | |
|
243 | 243 | # self.nChannels = 0 |
|
244 | 244 | |
|
245 | 245 | # self.nHeights = 0 |
|
246 | 246 | |
|
247 | 247 | self.nProfiles = None |
|
248 | 248 | |
|
249 | 249 | self.heightList = None |
|
250 | 250 | |
|
251 | 251 | self.channelList = None |
|
252 | 252 | |
|
253 | 253 | # self.channelIndexList = None |
|
254 | 254 | |
|
255 | 255 | self.flagNoData = True |
|
256 | 256 | |
|
257 | 257 | self.flagTimeBlock = False |
|
258 | 258 | |
|
259 | 259 | self.utctime = None |
|
260 | 260 | |
|
261 | 261 | self.timeZone = None |
|
262 | 262 | |
|
263 | 263 | self.dstFlag = None |
|
264 | 264 | |
|
265 | 265 | self.errorCount = None |
|
266 | 266 | |
|
267 | 267 | self.nCohInt = None |
|
268 | 268 | |
|
269 | 269 | self.blocksize = None |
|
270 | 270 | |
|
271 | 271 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
272 | 272 | |
|
273 | 273 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
274 | 274 | |
|
275 | 275 | self.flagShiftFFT = False |
|
276 | 276 | |
|
277 | 277 | |
|
278 | 278 | def getNoisebyHildebrand(self): |
|
279 | 279 | """ |
|
280 | 280 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
281 | 281 | |
|
282 | 282 | Return: |
|
283 | 283 | noiselevel |
|
284 | 284 | """ |
|
285 | 285 | |
|
286 | 286 | for channel in range(self.nChannels): |
|
287 | 287 | daux = self.data_spc[channel,:,:] |
|
288 | 288 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
289 | 289 | |
|
290 | 290 | return self.noise |
|
291 | 291 | |
|
292 | 292 | def getNoise(self, type = 1): |
|
293 | 293 | |
|
294 | 294 | self.noise = numpy.zeros(self.nChannels) |
|
295 | 295 | |
|
296 | 296 | if type == 1: |
|
297 | 297 | noise = self.getNoisebyHildebrand() |
|
298 | 298 | |
|
299 | 299 | return 10*numpy.log10(noise) |
|
300 | 300 | |
|
301 | 301 | class Spectra(JROData): |
|
302 | 302 | |
|
303 | 303 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
304 | 304 | data_spc = None |
|
305 | 305 | |
|
306 | 306 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
307 | 307 | data_cspc = None |
|
308 | 308 | |
|
309 | 309 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
310 | 310 | data_dc = None |
|
311 | 311 | |
|
312 | 312 | nFFTPoints = None |
|
313 | 313 | |
|
314 | 314 | nPairs = None |
|
315 | 315 | |
|
316 | 316 | pairsList = None |
|
317 | 317 | |
|
318 | 318 | nIncohInt = None |
|
319 | 319 | |
|
320 | 320 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
321 | 321 | |
|
322 | 322 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
323 | 323 | |
|
324 | 324 | ippFactor = None |
|
325 | 325 | |
|
326 | 326 | def __init__(self): |
|
327 | 327 | ''' |
|
328 | 328 | Constructor |
|
329 | 329 | ''' |
|
330 | 330 | |
|
331 | 331 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
332 | 332 | |
|
333 | 333 | self.systemHeaderObj = SystemHeader() |
|
334 | 334 | |
|
335 | 335 | self.type = "Spectra" |
|
336 | 336 | |
|
337 | 337 | # self.data = None |
|
338 | 338 | |
|
339 | 339 | self.dtype = None |
|
340 | 340 | |
|
341 | 341 | # self.nChannels = 0 |
|
342 | 342 | |
|
343 | 343 | # self.nHeights = 0 |
|
344 | 344 | |
|
345 | 345 | self.nProfiles = None |
|
346 | 346 | |
|
347 | 347 | self.heightList = None |
|
348 | 348 | |
|
349 | 349 | self.channelList = None |
|
350 | 350 | |
|
351 | 351 | # self.channelIndexList = None |
|
352 | 352 | |
|
353 | 353 | self.flagNoData = True |
|
354 | 354 | |
|
355 | 355 | self.flagTimeBlock = False |
|
356 | 356 | |
|
357 | 357 | self.utctime = None |
|
358 | 358 | |
|
359 | 359 | self.nCohInt = None |
|
360 | 360 | |
|
361 | 361 | self.nIncohInt = None |
|
362 | 362 | |
|
363 | 363 | self.blocksize = None |
|
364 | 364 | |
|
365 | 365 | self.nFFTPoints = None |
|
366 | 366 | |
|
367 | 367 | self.wavelength = None |
|
368 | 368 | |
|
369 | 369 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
370 | 370 | |
|
371 | 371 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
372 | 372 | |
|
373 | 373 | self.flagShiftFFT = False |
|
374 | 374 | |
|
375 | 375 | self.ippFactor = 1 |
|
376 | 376 | |
|
377 | 377 | self.noise = None |
|
378 | 378 | |
|
379 | 379 | self.beacon_heiIndexList = [] |
|
380 | 380 | |
|
381 | 381 | |
|
382 | 382 | def getNoisebyHildebrand(self): |
|
383 | 383 | """ |
|
384 | 384 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
385 | 385 | |
|
386 | 386 | Return: |
|
387 | 387 | noiselevel |
|
388 | 388 | """ |
|
389 | 389 | noise = numpy.zeros(self.nChannels) |
|
390 | 390 | for channel in range(self.nChannels): |
|
391 | 391 | daux = self.data_spc[channel,:,:] |
|
392 | 392 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
393 | 393 | |
|
394 | 394 | return noise |
|
395 | 395 | |
|
396 | 396 | def getNoise(self): |
|
397 | 397 | if self.noise != None: |
|
398 | 398 | return self.noise |
|
399 | 399 | else: |
|
400 | 400 | noise = self.getNoisebyHildebrand() |
|
401 | 401 | return noise |
|
402 | 402 | |
|
403 | 403 | |
|
404 | 404 | def getFreqRange(self, extrapoints=0): |
|
405 | 405 | |
|
406 | 406 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
407 | 407 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
408 | 408 | |
|
409 | 409 | return freqrange |
|
410 | 410 | |
|
411 | 411 | def getVelRange(self, extrapoints=0): |
|
412 | 412 | |
|
413 | 413 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
414 | 414 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
415 | 415 | |
|
416 | 416 | return velrange |
|
417 | 417 | |
|
418 | 418 | def getNPairs(self): |
|
419 | 419 | |
|
420 | 420 | return len(self.pairsList) |
|
421 | 421 | |
|
422 | 422 | def getPairsIndexList(self): |
|
423 | 423 | |
|
424 | 424 | return range(self.nPairs) |
|
425 | 425 | |
|
426 | 426 | def getNormFactor(self): |
|
427 | 427 | pwcode = 1 |
|
428 | 428 | if self.flagDecodeData: |
|
429 | 429 | pwcode = numpy.sum(self.code[0]**2) |
|
430 | 430 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
431 | 431 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
432 | 432 | |
|
433 | 433 | return normFactor |
|
434 | 434 | |
|
435 | 435 | def getFlagCspc(self): |
|
436 | 436 | |
|
437 | 437 | if self.data_cspc == None: |
|
438 | 438 | return True |
|
439 | 439 | |
|
440 | 440 | return False |
|
441 | 441 | |
|
442 | 442 | def getFlagDc(self): |
|
443 | 443 | |
|
444 | 444 | if self.data_dc == None: |
|
445 | 445 | return True |
|
446 | 446 | |
|
447 | 447 | return False |
|
448 | 448 | |
|
449 | 449 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
450 | 450 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
451 | 451 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
452 | 452 | flag_cspc = property(getFlagCspc) |
|
453 | 453 | flag_dc = property(getFlagDc) |
|
454 | 454 | |
|
455 | 455 | class SpectraHeis(JROData): |
|
456 | 456 | |
|
457 | 457 | data_spc = None |
|
458 | 458 | |
|
459 | 459 | data_cspc = None |
|
460 | 460 | |
|
461 | 461 | data_dc = None |
|
462 | 462 | |
|
463 | 463 | nFFTPoints = None |
|
464 | 464 | |
|
465 | 465 | nPairs = None |
|
466 | 466 | |
|
467 | 467 | pairsList = None |
|
468 | 468 | |
|
469 | 469 | nIncohInt = None |
|
470 | 470 | |
|
471 | 471 | def __init__(self): |
|
472 | 472 | |
|
473 | 473 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
474 | 474 | |
|
475 | 475 | self.systemHeaderObj = SystemHeader() |
|
476 | 476 | |
|
477 | 477 | self.type = "SpectraHeis" |
|
478 | 478 | |
|
479 | 479 | self.dtype = None |
|
480 | 480 | |
|
481 | 481 | # self.nChannels = 0 |
|
482 | 482 | |
|
483 | 483 | # self.nHeights = 0 |
|
484 | 484 | |
|
485 | 485 | self.nProfiles = None |
|
486 | 486 | |
|
487 | 487 | self.heightList = None |
|
488 | 488 | |
|
489 | 489 | self.channelList = None |
|
490 | 490 | |
|
491 | 491 | # self.channelIndexList = None |
|
492 | 492 | |
|
493 | 493 | self.flagNoData = True |
|
494 | 494 | |
|
495 | 495 | self.flagTimeBlock = False |
|
496 | 496 | |
|
497 | 497 | self.nPairs = 0 |
|
498 | 498 | |
|
499 | 499 | self.utctime = None |
|
500 | 500 | |
|
501 | 501 | self.blocksize = None |
|
502 | 502 | |
|
503 | 503 | class Fits: |
|
504 | 504 | |
|
505 | 505 | heightList = None |
|
506 | 506 | |
|
507 | 507 | channelList = None |
|
508 | 508 | |
|
509 | 509 | flagNoData = True |
|
510 | 510 | |
|
511 | 511 | flagTimeBlock = False |
|
512 | 512 | |
|
513 | 513 | useLocalTime = False |
|
514 | 514 | |
|
515 | 515 | utctime = None |
|
516 | 516 | |
|
517 | 517 | timeZone = None |
|
518 | 518 | |
|
519 | 519 | ippSeconds = None |
|
520 | 520 | |
|
521 | 521 | timeInterval = None |
|
522 | 522 | |
|
523 | 523 | nCohInt = None |
|
524 | 524 | |
|
525 | 525 | nIncohInt = None |
|
526 | 526 | |
|
527 | 527 | noise = None |
|
528 | 528 | |
|
529 | 529 | windowOfFilter = 1 |
|
530 | 530 | |
|
531 | 531 | #Speed of ligth |
|
532 | 532 | C = 3e8 |
|
533 | 533 | |
|
534 | 534 | frequency = 49.92e6 |
|
535 | 535 | |
|
536 | 536 | realtime = False |
|
537 | 537 | |
|
538 | 538 | |
|
539 | 539 | def __init__(self): |
|
540 | 540 | |
|
541 | 541 | self.type = "Fits" |
|
542 | 542 | |
|
543 | 543 | self.nProfiles = None |
|
544 | 544 | |
|
545 | 545 | self.heightList = None |
|
546 | 546 | |
|
547 | 547 | self.channelList = None |
|
548 | 548 | |
|
549 | 549 | # self.channelIndexList = None |
|
550 | 550 | |
|
551 | 551 | self.flagNoData = True |
|
552 | 552 | |
|
553 | 553 | self.utctime = None |
|
554 | 554 | |
|
555 | 555 | self.nCohInt = None |
|
556 | 556 | |
|
557 | 557 | self.nIncohInt = None |
|
558 | 558 | |
|
559 | 559 | self.useLocalTime = True |
|
560 | 560 | |
|
561 | 561 | # self.utctime = None |
|
562 | 562 | # self.timeZone = None |
|
563 | 563 | # self.ltctime = None |
|
564 | 564 | # self.timeInterval = None |
|
565 | 565 | # self.header = None |
|
566 | 566 | # self.data_header = None |
|
567 | 567 | # self.data = None |
|
568 | 568 | # self.datatime = None |
|
569 | 569 | # self.flagNoData = False |
|
570 | 570 | # self.expName = '' |
|
571 | 571 | # self.nChannels = None |
|
572 | 572 | # self.nSamples = None |
|
573 | 573 | # self.dataBlocksPerFile = None |
|
574 | 574 | # self.comments = '' |
|
575 | 575 | # |
|
576 | 576 | |
|
577 | 577 | |
|
578 | 578 | def getltctime(self): |
|
579 | 579 | |
|
580 | 580 | if self.useLocalTime: |
|
581 | 581 | return self.utctime - self.timeZone*60 |
|
582 | 582 | |
|
583 | 583 | return self.utctime |
|
584 | 584 | |
|
585 | 585 | def getDatatime(self): |
|
586 | 586 | |
|
587 | 587 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
588 | 588 | return datatime |
|
589 | 589 | |
|
590 | 590 | def getTimeRange(self): |
|
591 | 591 | |
|
592 | 592 | datatime = [] |
|
593 | 593 | |
|
594 | 594 | datatime.append(self.ltctime) |
|
595 | 595 | datatime.append(self.ltctime + self.timeInterval) |
|
596 | 596 | |
|
597 | 597 | datatime = numpy.array(datatime) |
|
598 | 598 | |
|
599 | 599 | return datatime |
|
600 | 600 | |
|
601 | 601 | def getHeiRange(self): |
|
602 | 602 | |
|
603 | 603 | heis = self.heightList |
|
604 | 604 | |
|
605 | 605 | return heis |
|
606 | 606 | |
|
607 | 607 | def isEmpty(self): |
|
608 | 608 | |
|
609 | 609 | return self.flagNoData |
|
610 | 610 | |
|
611 | 611 | def getNHeights(self): |
|
612 | 612 | |
|
613 | 613 | return len(self.heightList) |
|
614 | 614 | |
|
615 | 615 | def getNChannels(self): |
|
616 | 616 | |
|
617 | 617 | return len(self.channelList) |
|
618 | 618 | |
|
619 | 619 | def getChannelIndexList(self): |
|
620 | 620 | |
|
621 | 621 | return range(self.nChannels) |
|
622 | 622 | |
|
623 | 623 | def getNoise(self, type = 1): |
|
624 | 624 | |
|
625 | 625 | self.noise = numpy.zeros(self.nChannels) |
|
626 | 626 | |
|
627 | 627 | if type == 1: |
|
628 | 628 | noise = self.getNoisebyHildebrand() |
|
629 | 629 | |
|
630 | 630 | if type == 2: |
|
631 | 631 | noise = self.getNoisebySort() |
|
632 | 632 | |
|
633 | 633 | if type == 3: |
|
634 | 634 | noise = self.getNoisebyWindow() |
|
635 | 635 | |
|
636 | 636 | return noise |
|
637 | 637 | |
|
638 | 638 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
639 | 639 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
640 | 640 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
641 | 641 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
642 | 642 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
643 | 643 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
644 | 644 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
645 | 645 | |
|
646 | 646 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
647 | 647 | |
|
648 | 648 | class AMISR: |
|
649 | 649 | def __init__(self): |
|
650 | 650 | self.flagNoData = True |
|
651 | 651 | self.data = None |
|
652 | 652 | self.utctime = None |
|
653 | 653 | self.type = "AMISR" |
|
654 | 654 | |
|
655 | #propiedades para compatibilidad con Voltages | |
|
656 | self.timeZone = 0#self.dataIn.timeZone | |
|
657 | self.dstFlag = 0#self.dataIn.dstFlag | |
|
658 | self.errorCount = 0#self.dataIn.errorCount | |
|
659 | self.useLocalTime = True#self.dataIn.useLocalTime | |
|
660 | ||
|
661 | self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy() | |
|
662 | self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy() | |
|
663 | self.channelList = [1]#self.dataIn.channelList esto solo aplica para el caso de AMISR | |
|
664 | self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
|
665 | ||
|
666 | self.flagTimeBlock = None#self.dataIn.flagTimeBlock | |
|
667 | #self.utctime = #self.firstdatatime | |
|
668 | self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
|
669 | self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
|
670 | ||
|
671 | self.nCohInt = 1#self.dataIn.nCohInt | |
|
672 | self.nIncohInt = 1 | |
|
673 | self.ippSeconds = 0.004#self.dataIn.ippSeconds, segun el filename/Setup/Tufile | |
|
674 | self.windowOfFilter = None#self.dataIn.windowOfFilter | |
|
675 | ||
|
676 | self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
|
677 | self.frequency = 20000#self.dataIn.frequency | |
|
678 | self.realtime = 0#self.dataIn.realtime | |
|
679 | ||
|
680 | #actualizar en la lectura de datos | |
|
681 | self.heightList = None#self.dataIn.heightList | |
|
682 | self.nProfiles = None#self.dataOut.nFFTPoints | |
|
683 | self.nBaud = None#self.dataIn.nBaud | |
|
684 | self.nCode = None#self.dataIn.nCode | |
|
685 | self.code = None#self.dataIn.code | |
|
686 | ||
|
687 | ||
|
655 | 688 | def isEmpty(self): |
|
656 | 689 | |
|
657 | 690 | return self.flagNoData No newline at end of file |
@@ -1,3825 +1,3836 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os, sys |
|
8 | 8 | import glob |
|
9 | 9 | import time |
|
10 | 10 | import numpy |
|
11 | 11 | import fnmatch |
|
12 | 12 | import time, datetime |
|
13 | 13 | import h5py |
|
14 | 14 | from xml.etree.ElementTree import Element, SubElement, ElementTree |
|
15 | 15 | try: |
|
16 | 16 | import pyfits |
|
17 | 17 | except: |
|
18 | 18 | print "pyfits module has not been imported, it should be installed to save files in fits format" |
|
19 | 19 | |
|
20 | 20 | from jrodata import * |
|
21 | 21 | from jroheaderIO import * |
|
22 | 22 | from jroprocessing import * |
|
23 | 23 | |
|
24 | 24 | LOCALTIME = True #-18000 |
|
25 | 25 | |
|
26 | 26 | def isNumber(str): |
|
27 | 27 | """ |
|
28 | 28 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
29 | 29 | |
|
30 | 30 | Excepciones: |
|
31 | 31 | Si un determinado string no puede ser convertido a numero |
|
32 | 32 | Input: |
|
33 | 33 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
34 | 34 | |
|
35 | 35 | Return: |
|
36 | 36 | True : si el string es uno numerico |
|
37 | 37 | False : no es un string numerico |
|
38 | 38 | """ |
|
39 | 39 | try: |
|
40 | 40 | float( str ) |
|
41 | 41 | return True |
|
42 | 42 | except: |
|
43 | 43 | return False |
|
44 | 44 | |
|
45 | 45 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
46 | 46 | """ |
|
47 | 47 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
48 | 48 | |
|
49 | 49 | Inputs: |
|
50 | 50 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
51 | 51 | |
|
52 | 52 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
53 | 53 | segundos contados desde 01/01/1970. |
|
54 | 54 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
55 | 55 | segundos contados desde 01/01/1970. |
|
56 | 56 | |
|
57 | 57 | Return: |
|
58 | 58 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
59 | 59 | fecha especificado, de lo contrario retorna False. |
|
60 | 60 | |
|
61 | 61 | Excepciones: |
|
62 | 62 | Si el archivo no existe o no puede ser abierto |
|
63 | 63 | Si la cabecera no puede ser leida. |
|
64 | 64 | |
|
65 | 65 | """ |
|
66 | 66 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
67 | 67 | |
|
68 | 68 | try: |
|
69 | 69 | fp = open(filename,'rb') |
|
70 | 70 | except: |
|
71 | 71 | raise IOError, "The file %s can't be opened" %(filename) |
|
72 | 72 | |
|
73 | 73 | sts = basicHeaderObj.read(fp) |
|
74 | 74 | fp.close() |
|
75 | 75 | |
|
76 | 76 | if not(sts): |
|
77 | 77 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
78 | 78 | return 0 |
|
79 | 79 | |
|
80 | 80 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
81 | 81 | return 0 |
|
82 | 82 | |
|
83 | 83 | return 1 |
|
84 | 84 | |
|
85 | 85 | def isFileinThisTime(filename, startTime, endTime): |
|
86 | 86 | """ |
|
87 | 87 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
88 | 88 | |
|
89 | 89 | Inputs: |
|
90 | 90 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
91 | 91 | |
|
92 | 92 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
93 | 93 | |
|
94 | 94 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
95 | 95 | |
|
96 | 96 | Return: |
|
97 | 97 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
98 | 98 | fecha especificado, de lo contrario retorna False. |
|
99 | 99 | |
|
100 | 100 | Excepciones: |
|
101 | 101 | Si el archivo no existe o no puede ser abierto |
|
102 | 102 | Si la cabecera no puede ser leida. |
|
103 | 103 | |
|
104 | 104 | """ |
|
105 | 105 | |
|
106 | 106 | |
|
107 | 107 | try: |
|
108 | 108 | fp = open(filename,'rb') |
|
109 | 109 | except: |
|
110 | 110 | raise IOError, "The file %s can't be opened" %(filename) |
|
111 | 111 | |
|
112 | 112 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
113 | 113 | sts = basicHeaderObj.read(fp) |
|
114 | 114 | fp.close() |
|
115 | 115 | |
|
116 | 116 | thisDatetime = basicHeaderObj.datatime |
|
117 | 117 | thisTime = basicHeaderObj.datatime.time() |
|
118 | 118 | |
|
119 | 119 | if not(sts): |
|
120 | 120 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
121 | 121 | return None |
|
122 | 122 | |
|
123 | 123 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
124 | 124 | return None |
|
125 | 125 | |
|
126 | 126 | return thisDatetime |
|
127 | 127 | |
|
128 | 128 | def getFileFromSet(path,ext,set): |
|
129 | 129 | validFilelist = [] |
|
130 | 130 | fileList = os.listdir(path) |
|
131 | 131 | |
|
132 | 132 | # 0 1234 567 89A BCDE |
|
133 | 133 | # H YYYY DDD SSS .ext |
|
134 | 134 | |
|
135 | 135 | for file in fileList: |
|
136 | 136 | try: |
|
137 | 137 | year = int(file[1:5]) |
|
138 | 138 | doy = int(file[5:8]) |
|
139 | 139 | |
|
140 | 140 | |
|
141 | 141 | except: |
|
142 | 142 | continue |
|
143 | 143 | |
|
144 | 144 | if (os.path.splitext(file)[-1].lower() != ext.lower()): |
|
145 | 145 | continue |
|
146 | 146 | |
|
147 | 147 | validFilelist.append(file) |
|
148 | 148 | |
|
149 | 149 | myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set)) |
|
150 | 150 | |
|
151 | 151 | if len(myfile)!= 0: |
|
152 | 152 | return myfile[0] |
|
153 | 153 | else: |
|
154 | 154 | filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower()) |
|
155 | 155 | print 'the filename %s does not exist'%filename |
|
156 | 156 | print '...going to the last file: ' |
|
157 | 157 | |
|
158 | 158 | if validFilelist: |
|
159 | 159 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
160 | 160 | return validFilelist[-1] |
|
161 | 161 | |
|
162 | 162 | return None |
|
163 | 163 | |
|
164 | 164 | |
|
165 | 165 | def getlastFileFromPath(path, ext): |
|
166 | 166 | """ |
|
167 | 167 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
168 | 168 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
169 | 169 | |
|
170 | 170 | Input: |
|
171 | 171 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
172 | 172 | ext : extension de los files contenidos en una carpeta |
|
173 | 173 | |
|
174 | 174 | Return: |
|
175 | 175 | El ultimo file de una determinada carpeta, no se considera el path. |
|
176 | 176 | """ |
|
177 | 177 | validFilelist = [] |
|
178 | 178 | fileList = os.listdir(path) |
|
179 | 179 | |
|
180 | 180 | # 0 1234 567 89A BCDE |
|
181 | 181 | # H YYYY DDD SSS .ext |
|
182 | 182 | |
|
183 | 183 | for file in fileList: |
|
184 | 184 | try: |
|
185 | 185 | year = int(file[1:5]) |
|
186 | 186 | doy = int(file[5:8]) |
|
187 | 187 | |
|
188 | 188 | |
|
189 | 189 | except: |
|
190 | 190 | continue |
|
191 | 191 | |
|
192 | 192 | if (os.path.splitext(file)[-1].lower() != ext.lower()): |
|
193 | 193 | continue |
|
194 | 194 | |
|
195 | 195 | validFilelist.append(file) |
|
196 | 196 | |
|
197 | 197 | if validFilelist: |
|
198 | 198 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
199 | 199 | return validFilelist[-1] |
|
200 | 200 | |
|
201 | 201 | return None |
|
202 | 202 | |
|
203 | 203 | def checkForRealPath(path, foldercounter, year, doy, set, ext): |
|
204 | 204 | """ |
|
205 | 205 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
206 | 206 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
207 | 207 | el path exacto de un determinado file. |
|
208 | 208 | |
|
209 | 209 | Example : |
|
210 | 210 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
211 | 211 | |
|
212 | 212 | Entonces la funcion prueba con las siguientes combinaciones |
|
213 | 213 | .../.../y2009307367.ext |
|
214 | 214 | .../.../Y2009307367.ext |
|
215 | 215 | .../.../x2009307/y2009307367.ext |
|
216 | 216 | .../.../x2009307/Y2009307367.ext |
|
217 | 217 | .../.../X2009307/y2009307367.ext |
|
218 | 218 | .../.../X2009307/Y2009307367.ext |
|
219 | 219 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
220 | 220 | |
|
221 | 221 | Return: |
|
222 | 222 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
223 | 223 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
224 | 224 | para el filename |
|
225 | 225 | """ |
|
226 | 226 | fullfilename = None |
|
227 | 227 | find_flag = False |
|
228 | 228 | filename = None |
|
229 | 229 | |
|
230 | 230 | prefixDirList = [None,'d','D'] |
|
231 | 231 | if ext.lower() == ".r": #voltage |
|
232 | 232 | prefixFileList = ['d','D'] |
|
233 | 233 | elif ext.lower() == ".pdata": #spectra |
|
234 | 234 | prefixFileList = ['p','P'] |
|
235 | 235 | else: |
|
236 | 236 | return None, filename |
|
237 | 237 | |
|
238 | 238 | #barrido por las combinaciones posibles |
|
239 | 239 | for prefixDir in prefixDirList: |
|
240 | 240 | thispath = path |
|
241 | 241 | if prefixDir != None: |
|
242 | 242 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
243 | 243 | if foldercounter == 0: |
|
244 | 244 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) |
|
245 | 245 | else: |
|
246 | 246 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter)) |
|
247 | 247 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" |
|
248 | 248 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
249 | 249 | fullfilename = os.path.join( thispath, filename ) #formo el path completo |
|
250 | 250 | |
|
251 | 251 | if os.path.exists( fullfilename ): #verifico que exista |
|
252 | 252 | find_flag = True |
|
253 | 253 | break |
|
254 | 254 | if find_flag: |
|
255 | 255 | break |
|
256 | 256 | |
|
257 | 257 | if not(find_flag): |
|
258 | 258 | return None, filename |
|
259 | 259 | |
|
260 | 260 | return fullfilename, filename |
|
261 | 261 | |
|
262 | 262 | def isDoyFolder(folder): |
|
263 | 263 | try: |
|
264 | 264 | year = int(folder[1:5]) |
|
265 | 265 | except: |
|
266 | 266 | return 0 |
|
267 | 267 | |
|
268 | 268 | try: |
|
269 | 269 | doy = int(folder[5:8]) |
|
270 | 270 | except: |
|
271 | 271 | return 0 |
|
272 | 272 | |
|
273 | 273 | return 1 |
|
274 | 274 | |
|
275 | 275 | class JRODataIO: |
|
276 | 276 | |
|
277 | 277 | c = 3E8 |
|
278 | 278 | |
|
279 | 279 | isConfig = False |
|
280 | 280 | |
|
281 | 281 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
282 | 282 | |
|
283 | 283 | systemHeaderObj = SystemHeader() |
|
284 | 284 | |
|
285 | 285 | radarControllerHeaderObj = RadarControllerHeader() |
|
286 | 286 | |
|
287 | 287 | processingHeaderObj = ProcessingHeader() |
|
288 | 288 | |
|
289 | 289 | online = 0 |
|
290 | 290 | |
|
291 | 291 | dtype = None |
|
292 | 292 | |
|
293 | 293 | pathList = [] |
|
294 | 294 | |
|
295 | 295 | filenameList = [] |
|
296 | 296 | |
|
297 | 297 | filename = None |
|
298 | 298 | |
|
299 | 299 | ext = None |
|
300 | 300 | |
|
301 | 301 | flagIsNewFile = 1 |
|
302 | 302 | |
|
303 | 303 | flagTimeBlock = 0 |
|
304 | 304 | |
|
305 | 305 | flagIsNewBlock = 0 |
|
306 | 306 | |
|
307 | 307 | fp = None |
|
308 | 308 | |
|
309 | 309 | firstHeaderSize = 0 |
|
310 | 310 | |
|
311 | 311 | basicHeaderSize = 24 |
|
312 | 312 | |
|
313 | 313 | versionFile = 1103 |
|
314 | 314 | |
|
315 | 315 | fileSize = None |
|
316 | 316 | |
|
317 | 317 | ippSeconds = None |
|
318 | 318 | |
|
319 | 319 | fileSizeByHeader = None |
|
320 | 320 | |
|
321 | 321 | fileIndex = None |
|
322 | 322 | |
|
323 | 323 | profileIndex = None |
|
324 | 324 | |
|
325 | 325 | blockIndex = None |
|
326 | 326 | |
|
327 | 327 | nTotalBlocks = None |
|
328 | 328 | |
|
329 | 329 | maxTimeStep = 30 |
|
330 | 330 | |
|
331 | 331 | lastUTTime = None |
|
332 | 332 | |
|
333 | 333 | datablock = None |
|
334 | 334 | |
|
335 | 335 | dataOut = None |
|
336 | 336 | |
|
337 | 337 | blocksize = None |
|
338 | 338 | |
|
339 | 339 | def __init__(self): |
|
340 | 340 | |
|
341 | 341 | raise ValueError, "Not implemented" |
|
342 | 342 | |
|
343 | 343 | def run(self): |
|
344 | 344 | |
|
345 | 345 | raise ValueError, "Not implemented" |
|
346 | 346 | |
|
347 | 347 | def getOutput(self): |
|
348 | 348 | |
|
349 | 349 | return self.dataOut |
|
350 | 350 | |
|
351 | 351 | class JRODataReader(JRODataIO, ProcessingUnit): |
|
352 | 352 | |
|
353 | 353 | nReadBlocks = 0 |
|
354 | 354 | |
|
355 | 355 | delay = 10 #number of seconds waiting a new file |
|
356 | 356 | |
|
357 | 357 | nTries = 3 #quantity tries |
|
358 | 358 | |
|
359 | 359 | nFiles = 3 #number of files for searching |
|
360 | 360 | |
|
361 | 361 | path = None |
|
362 | 362 | |
|
363 | 363 | foldercounter = 0 |
|
364 | 364 | |
|
365 | 365 | flagNoMoreFiles = 0 |
|
366 | 366 | |
|
367 | 367 | datetimeList = [] |
|
368 | 368 | |
|
369 | 369 | __isFirstTimeOnline = 1 |
|
370 | 370 | |
|
371 | 371 | __printInfo = True |
|
372 | 372 | |
|
373 | 373 | profileIndex = None |
|
374 | 374 | |
|
375 | 375 | def __init__(self): |
|
376 | 376 | |
|
377 | 377 | """ |
|
378 | 378 | |
|
379 | 379 | """ |
|
380 | 380 | |
|
381 | 381 | raise ValueError, "This method has not been implemented" |
|
382 | 382 | |
|
383 | 383 | |
|
384 | 384 | def createObjByDefault(self): |
|
385 | 385 | """ |
|
386 | 386 | |
|
387 | 387 | """ |
|
388 | 388 | raise ValueError, "This method has not been implemented" |
|
389 | 389 | |
|
390 | 390 | def getBlockDimension(self): |
|
391 | 391 | |
|
392 | 392 | raise ValueError, "No implemented" |
|
393 | 393 | |
|
394 | 394 | def __searchFilesOffLine(self, |
|
395 | 395 | path, |
|
396 | 396 | startDate, |
|
397 | 397 | endDate, |
|
398 | 398 | startTime=datetime.time(0,0,0), |
|
399 | 399 | endTime=datetime.time(23,59,59), |
|
400 | 400 | set=None, |
|
401 | 401 | expLabel='', |
|
402 | 402 | ext='.r', |
|
403 | 403 | walk=True): |
|
404 | 404 | |
|
405 | 405 | pathList = [] |
|
406 | 406 | |
|
407 | 407 | if not walk: |
|
408 | 408 | #pathList.append(path) |
|
409 | 409 | multi_path = path.split(',') |
|
410 | 410 | for single_path in multi_path: |
|
411 | 411 | pathList.append(single_path) |
|
412 | 412 | |
|
413 | 413 | else: |
|
414 | 414 | #dirList = [] |
|
415 | 415 | multi_path = path.split(',') |
|
416 | 416 | for single_path in multi_path: |
|
417 | 417 | dirList = [] |
|
418 | 418 | for thisPath in os.listdir(single_path): |
|
419 | 419 | if not os.path.isdir(os.path.join(single_path,thisPath)): |
|
420 | 420 | continue |
|
421 | 421 | if not isDoyFolder(thisPath): |
|
422 | 422 | continue |
|
423 | 423 | |
|
424 | 424 | dirList.append(thisPath) |
|
425 | 425 | |
|
426 | 426 | if not(dirList): |
|
427 | 427 | return None, None |
|
428 | 428 | |
|
429 | 429 | thisDate = startDate |
|
430 | 430 | |
|
431 | 431 | while(thisDate <= endDate): |
|
432 | 432 | year = thisDate.timetuple().tm_year |
|
433 | 433 | doy = thisDate.timetuple().tm_yday |
|
434 | 434 | |
|
435 | 435 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
436 | 436 | if len(matchlist) == 0: |
|
437 | 437 | thisDate += datetime.timedelta(1) |
|
438 | 438 | continue |
|
439 | 439 | for match in matchlist: |
|
440 | 440 | pathList.append(os.path.join(single_path,match,expLabel)) |
|
441 | 441 | |
|
442 | 442 | thisDate += datetime.timedelta(1) |
|
443 | 443 | |
|
444 | 444 | if pathList == []: |
|
445 | 445 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
446 | 446 | return None, None |
|
447 | 447 | |
|
448 | 448 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
449 | 449 | |
|
450 | 450 | filenameList = [] |
|
451 | 451 | datetimeList = [] |
|
452 | 452 | pathDict = {} |
|
453 | 453 | filenameList_to_sort = [] |
|
454 | 454 | |
|
455 | 455 | for i in range(len(pathList)): |
|
456 | 456 | |
|
457 | 457 | thisPath = pathList[i] |
|
458 | 458 | |
|
459 | 459 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
460 | 460 | fileList.sort() |
|
461 | 461 | pathDict.setdefault(fileList[0]) |
|
462 | 462 | pathDict[fileList[0]] = i |
|
463 | 463 | filenameList_to_sort.append(fileList[0]) |
|
464 | 464 | |
|
465 | 465 | filenameList_to_sort.sort() |
|
466 | 466 | |
|
467 | 467 | for file in filenameList_to_sort: |
|
468 | 468 | thisPath = pathList[pathDict[file]] |
|
469 | 469 | |
|
470 | 470 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
471 | 471 | fileList.sort() |
|
472 | 472 | |
|
473 | 473 | for file in fileList: |
|
474 | 474 | |
|
475 | 475 | filename = os.path.join(thisPath,file) |
|
476 | 476 | thisDatetime = isFileinThisTime(filename, startTime, endTime) |
|
477 | 477 | |
|
478 | 478 | if not(thisDatetime): |
|
479 | 479 | continue |
|
480 | 480 | |
|
481 | 481 | filenameList.append(filename) |
|
482 | 482 | datetimeList.append(thisDatetime) |
|
483 | 483 | |
|
484 | 484 | if not(filenameList): |
|
485 | 485 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
486 | 486 | return None, None |
|
487 | 487 | |
|
488 | 488 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
489 | 489 | |
|
490 | 490 | |
|
491 | 491 | for i in range(len(filenameList)): |
|
492 | 492 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
493 | 493 | |
|
494 | 494 | self.filenameList = filenameList |
|
495 | 495 | self.datetimeList = datetimeList |
|
496 | 496 | |
|
497 | 497 | return pathList, filenameList |
|
498 | 498 | |
|
499 | 499 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None): |
|
500 | 500 | |
|
501 | 501 | """ |
|
502 | 502 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
503 | 503 | devuelve el archivo encontrado ademas de otros datos. |
|
504 | 504 | |
|
505 | 505 | Input: |
|
506 | 506 | path : carpeta donde estan contenidos los files que contiene data |
|
507 | 507 | |
|
508 | 508 | expLabel : Nombre del subexperimento (subfolder) |
|
509 | 509 | |
|
510 | 510 | ext : extension de los files |
|
511 | 511 | |
|
512 | 512 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
513 | 513 | |
|
514 | 514 | Return: |
|
515 | 515 | directory : eL directorio donde esta el file encontrado |
|
516 | 516 | filename : el ultimo file de una determinada carpeta |
|
517 | 517 | year : el anho |
|
518 | 518 | doy : el numero de dia del anho |
|
519 | 519 | set : el set del archivo |
|
520 | 520 | |
|
521 | 521 | |
|
522 | 522 | """ |
|
523 | 523 | dirList = [] |
|
524 | 524 | |
|
525 | 525 | if not walk: |
|
526 | 526 | fullpath = path |
|
527 | 527 | foldercounter = 0 |
|
528 | 528 | else: |
|
529 | 529 | #Filtra solo los directorios |
|
530 | 530 | for thisPath in os.listdir(path): |
|
531 | 531 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
532 | 532 | continue |
|
533 | 533 | if not isDoyFolder(thisPath): |
|
534 | 534 | continue |
|
535 | 535 | |
|
536 | 536 | dirList.append(thisPath) |
|
537 | 537 | |
|
538 | 538 | if not(dirList): |
|
539 | 539 | return None, None, None, None, None, None |
|
540 | 540 | |
|
541 | 541 | dirList = sorted( dirList, key=str.lower ) |
|
542 | 542 | |
|
543 | 543 | doypath = dirList[-1] |
|
544 | 544 | foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0 |
|
545 | 545 | fullpath = os.path.join(path, doypath, expLabel) |
|
546 | 546 | |
|
547 | 547 | |
|
548 | 548 | print "%s folder was found: " %(fullpath ) |
|
549 | 549 | |
|
550 | 550 | if set == None: |
|
551 | 551 | filename = getlastFileFromPath(fullpath, ext) |
|
552 | 552 | else: |
|
553 | 553 | filename = getFileFromSet(fullpath, ext, set) |
|
554 | 554 | |
|
555 | 555 | if not(filename): |
|
556 | 556 | return None, None, None, None, None, None |
|
557 | 557 | |
|
558 | 558 | print "%s file was found" %(filename) |
|
559 | 559 | |
|
560 | 560 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
561 | 561 | return None, None, None, None, None, None |
|
562 | 562 | |
|
563 | 563 | year = int( filename[1:5] ) |
|
564 | 564 | doy = int( filename[5:8] ) |
|
565 | 565 | set = int( filename[8:11] ) |
|
566 | 566 | |
|
567 | 567 | return fullpath, foldercounter, filename, year, doy, set |
|
568 | 568 | |
|
569 | 569 | def __setNextFileOffline(self): |
|
570 | 570 | |
|
571 | 571 | idFile = self.fileIndex |
|
572 | 572 | |
|
573 | 573 | while (True): |
|
574 | 574 | idFile += 1 |
|
575 | 575 | if not(idFile < len(self.filenameList)): |
|
576 | 576 | self.flagNoMoreFiles = 1 |
|
577 | 577 | print "No more Files" |
|
578 | 578 | return 0 |
|
579 | 579 | |
|
580 | 580 | filename = self.filenameList[idFile] |
|
581 | 581 | |
|
582 | 582 | if not(self.__verifyFile(filename)): |
|
583 | 583 | continue |
|
584 | 584 | |
|
585 | 585 | fileSize = os.path.getsize(filename) |
|
586 | 586 | fp = open(filename,'rb') |
|
587 | 587 | break |
|
588 | 588 | |
|
589 | 589 | self.flagIsNewFile = 1 |
|
590 | 590 | self.fileIndex = idFile |
|
591 | 591 | self.filename = filename |
|
592 | 592 | self.fileSize = fileSize |
|
593 | 593 | self.fp = fp |
|
594 | 594 | |
|
595 | 595 | print "Setting the file: %s"%self.filename |
|
596 | 596 | |
|
597 | 597 | return 1 |
|
598 | 598 | |
|
599 | 599 | def __setNextFileOnline(self): |
|
600 | 600 | """ |
|
601 | 601 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
602 | 602 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
603 | 603 | siguientes. |
|
604 | 604 | |
|
605 | 605 | Affected: |
|
606 | 606 | self.flagIsNewFile |
|
607 | 607 | self.filename |
|
608 | 608 | self.fileSize |
|
609 | 609 | self.fp |
|
610 | 610 | self.set |
|
611 | 611 | self.flagNoMoreFiles |
|
612 | 612 | |
|
613 | 613 | Return: |
|
614 | 614 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
615 | 615 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
616 | 616 | |
|
617 | 617 | Excepciones: |
|
618 | 618 | Si un determinado file no puede ser abierto |
|
619 | 619 | """ |
|
620 | 620 | nFiles = 0 |
|
621 | 621 | fileOk_flag = False |
|
622 | 622 | firstTime_flag = True |
|
623 | 623 | |
|
624 | 624 | self.set += 1 |
|
625 | 625 | |
|
626 | 626 | if self.set > 999: |
|
627 | 627 | self.set = 0 |
|
628 | 628 | self.foldercounter += 1 |
|
629 | 629 | |
|
630 | 630 | #busca el 1er file disponible |
|
631 | 631 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
632 | 632 | if fullfilename: |
|
633 | 633 | if self.__verifyFile(fullfilename, False): |
|
634 | 634 | fileOk_flag = True |
|
635 | 635 | |
|
636 | 636 | #si no encuentra un file entonces espera y vuelve a buscar |
|
637 | 637 | if not(fileOk_flag): |
|
638 | 638 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
639 | 639 | |
|
640 | 640 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
641 | 641 | tries = self.nTries |
|
642 | 642 | else: |
|
643 | 643 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
644 | 644 | |
|
645 | 645 | for nTries in range( tries ): |
|
646 | 646 | if firstTime_flag: |
|
647 | 647 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
648 | 648 | time.sleep( self.delay ) |
|
649 | 649 | else: |
|
650 | 650 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
651 | 651 | |
|
652 | 652 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
653 | 653 | if fullfilename: |
|
654 | 654 | if self.__verifyFile(fullfilename): |
|
655 | 655 | fileOk_flag = True |
|
656 | 656 | break |
|
657 | 657 | |
|
658 | 658 | if fileOk_flag: |
|
659 | 659 | break |
|
660 | 660 | |
|
661 | 661 | firstTime_flag = False |
|
662 | 662 | |
|
663 | 663 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
664 | 664 | self.set += 1 |
|
665 | 665 | |
|
666 | 666 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
667 | 667 | self.set = 0 |
|
668 | 668 | self.doy += 1 |
|
669 | 669 | self.foldercounter = 0 |
|
670 | 670 | |
|
671 | 671 | if fileOk_flag: |
|
672 | 672 | self.fileSize = os.path.getsize( fullfilename ) |
|
673 | 673 | self.filename = fullfilename |
|
674 | 674 | self.flagIsNewFile = 1 |
|
675 | 675 | if self.fp != None: self.fp.close() |
|
676 | 676 | self.fp = open(fullfilename, 'rb') |
|
677 | 677 | self.flagNoMoreFiles = 0 |
|
678 | 678 | print 'Setting the file: %s' % fullfilename |
|
679 | 679 | else: |
|
680 | 680 | self.fileSize = 0 |
|
681 | 681 | self.filename = None |
|
682 | 682 | self.flagIsNewFile = 0 |
|
683 | 683 | self.fp = None |
|
684 | 684 | self.flagNoMoreFiles = 1 |
|
685 | 685 | print 'No more Files' |
|
686 | 686 | |
|
687 | 687 | return fileOk_flag |
|
688 | 688 | |
|
689 | 689 | |
|
690 | 690 | def setNextFile(self): |
|
691 | 691 | if self.fp != None: |
|
692 | 692 | self.fp.close() |
|
693 | 693 | |
|
694 | 694 | if self.online: |
|
695 | 695 | newFile = self.__setNextFileOnline() |
|
696 | 696 | else: |
|
697 | 697 | newFile = self.__setNextFileOffline() |
|
698 | 698 | |
|
699 | 699 | if not(newFile): |
|
700 | 700 | return 0 |
|
701 | 701 | |
|
702 | 702 | self.__readFirstHeader() |
|
703 | 703 | self.nReadBlocks = 0 |
|
704 | 704 | return 1 |
|
705 | 705 | |
|
706 | 706 | def __waitNewBlock(self): |
|
707 | 707 | """ |
|
708 | 708 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
709 | 709 | |
|
710 | 710 | Si el modo de lectura es OffLine siempre retorn 0 |
|
711 | 711 | """ |
|
712 | 712 | if not self.online: |
|
713 | 713 | return 0 |
|
714 | 714 | |
|
715 | 715 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
716 | 716 | return 0 |
|
717 | 717 | |
|
718 | 718 | currentPointer = self.fp.tell() |
|
719 | 719 | |
|
720 | 720 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
721 | 721 | |
|
722 | 722 | for nTries in range( self.nTries ): |
|
723 | 723 | |
|
724 | 724 | self.fp.close() |
|
725 | 725 | self.fp = open( self.filename, 'rb' ) |
|
726 | 726 | self.fp.seek( currentPointer ) |
|
727 | 727 | |
|
728 | 728 | self.fileSize = os.path.getsize( self.filename ) |
|
729 | 729 | currentSize = self.fileSize - currentPointer |
|
730 | 730 | |
|
731 | 731 | if ( currentSize >= neededSize ): |
|
732 | 732 | self.__rdBasicHeader() |
|
733 | 733 | return 1 |
|
734 | 734 | |
|
735 | 735 | if self.fileSize == self.fileSizeByHeader: |
|
736 | 736 | # self.flagEoF = True |
|
737 | 737 | return 0 |
|
738 | 738 | |
|
739 | 739 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
740 | 740 | time.sleep( self.delay ) |
|
741 | 741 | |
|
742 | 742 | |
|
743 | 743 | return 0 |
|
744 | 744 | |
|
745 | 745 | def waitDataBlock(self,pointer_location): |
|
746 | 746 | |
|
747 | 747 | currentPointer = pointer_location |
|
748 | 748 | |
|
749 | 749 | neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize |
|
750 | 750 | |
|
751 | 751 | for nTries in range( self.nTries ): |
|
752 | 752 | self.fp.close() |
|
753 | 753 | self.fp = open( self.filename, 'rb' ) |
|
754 | 754 | self.fp.seek( currentPointer ) |
|
755 | 755 | |
|
756 | 756 | self.fileSize = os.path.getsize( self.filename ) |
|
757 | 757 | currentSize = self.fileSize - currentPointer |
|
758 | 758 | |
|
759 | 759 | if ( currentSize >= neededSize ): |
|
760 | 760 | return 1 |
|
761 | 761 | |
|
762 | 762 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
763 | 763 | time.sleep( self.delay ) |
|
764 | 764 | |
|
765 | 765 | return 0 |
|
766 | 766 | |
|
767 | 767 | |
|
768 | 768 | def __jumpToLastBlock(self): |
|
769 | 769 | |
|
770 | 770 | if not(self.__isFirstTimeOnline): |
|
771 | 771 | return |
|
772 | 772 | |
|
773 | 773 | csize = self.fileSize - self.fp.tell() |
|
774 | 774 | blocksize = self.processingHeaderObj.blockSize |
|
775 | 775 | |
|
776 | 776 | #salta el primer bloque de datos |
|
777 | 777 | if csize > self.processingHeaderObj.blockSize: |
|
778 | 778 | self.fp.seek(self.fp.tell() + blocksize) |
|
779 | 779 | else: |
|
780 | 780 | return |
|
781 | 781 | |
|
782 | 782 | csize = self.fileSize - self.fp.tell() |
|
783 | 783 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
784 | 784 | while True: |
|
785 | 785 | |
|
786 | 786 | if self.fp.tell()<self.fileSize: |
|
787 | 787 | self.fp.seek(self.fp.tell() + neededsize) |
|
788 | 788 | else: |
|
789 | 789 | self.fp.seek(self.fp.tell() - neededsize) |
|
790 | 790 | break |
|
791 | 791 | |
|
792 | 792 | # csize = self.fileSize - self.fp.tell() |
|
793 | 793 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
794 | 794 | # factor = int(csize/neededsize) |
|
795 | 795 | # if factor > 0: |
|
796 | 796 | # self.fp.seek(self.fp.tell() + factor*neededsize) |
|
797 | 797 | |
|
798 | 798 | self.flagIsNewFile = 0 |
|
799 | 799 | self.__isFirstTimeOnline = 0 |
|
800 | 800 | |
|
801 | 801 | |
|
802 | 802 | def __setNewBlock(self): |
|
803 | 803 | |
|
804 | 804 | if self.fp == None: |
|
805 | 805 | return 0 |
|
806 | 806 | |
|
807 | 807 | if self.online: |
|
808 | 808 | self.__jumpToLastBlock() |
|
809 | 809 | |
|
810 | 810 | if self.flagIsNewFile: |
|
811 | 811 | return 1 |
|
812 | 812 | |
|
813 | 813 | self.lastUTTime = self.basicHeaderObj.utc |
|
814 | 814 | currentSize = self.fileSize - self.fp.tell() |
|
815 | 815 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
816 | 816 | |
|
817 | 817 | if (currentSize >= neededSize): |
|
818 | 818 | self.__rdBasicHeader() |
|
819 | 819 | return 1 |
|
820 | 820 | |
|
821 | 821 | if self.__waitNewBlock(): |
|
822 | 822 | return 1 |
|
823 | 823 | |
|
824 | 824 | if not(self.setNextFile()): |
|
825 | 825 | return 0 |
|
826 | 826 | |
|
827 | 827 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
828 | 828 | |
|
829 | 829 | self.flagTimeBlock = 0 |
|
830 | 830 | |
|
831 | 831 | if deltaTime > self.maxTimeStep: |
|
832 | 832 | self.flagTimeBlock = 1 |
|
833 | 833 | |
|
834 | 834 | return 1 |
|
835 | 835 | |
|
836 | 836 | |
|
837 | 837 | def readNextBlock(self): |
|
838 | 838 | if not(self.__setNewBlock()): |
|
839 | 839 | return 0 |
|
840 | 840 | |
|
841 | 841 | if not(self.readBlock()): |
|
842 | 842 | return 0 |
|
843 | 843 | |
|
844 | 844 | return 1 |
|
845 | 845 | |
|
846 | 846 | def __rdProcessingHeader(self, fp=None): |
|
847 | 847 | if fp == None: |
|
848 | 848 | fp = self.fp |
|
849 | 849 | |
|
850 | 850 | self.processingHeaderObj.read(fp) |
|
851 | 851 | |
|
852 | 852 | def __rdRadarControllerHeader(self, fp=None): |
|
853 | 853 | if fp == None: |
|
854 | 854 | fp = self.fp |
|
855 | 855 | |
|
856 | 856 | self.radarControllerHeaderObj.read(fp) |
|
857 | 857 | |
|
858 | 858 | def __rdSystemHeader(self, fp=None): |
|
859 | 859 | if fp == None: |
|
860 | 860 | fp = self.fp |
|
861 | 861 | |
|
862 | 862 | self.systemHeaderObj.read(fp) |
|
863 | 863 | |
|
864 | 864 | def __rdBasicHeader(self, fp=None): |
|
865 | 865 | if fp == None: |
|
866 | 866 | fp = self.fp |
|
867 | 867 | |
|
868 | 868 | self.basicHeaderObj.read(fp) |
|
869 | 869 | |
|
870 | 870 | |
|
871 | 871 | def __readFirstHeader(self): |
|
872 | 872 | self.__rdBasicHeader() |
|
873 | 873 | self.__rdSystemHeader() |
|
874 | 874 | self.__rdRadarControllerHeader() |
|
875 | 875 | self.__rdProcessingHeader() |
|
876 | 876 | |
|
877 | 877 | self.firstHeaderSize = self.basicHeaderObj.size |
|
878 | 878 | |
|
879 | 879 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
880 | 880 | if datatype == 0: |
|
881 | 881 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
882 | 882 | elif datatype == 1: |
|
883 | 883 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
884 | 884 | elif datatype == 2: |
|
885 | 885 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
886 | 886 | elif datatype == 3: |
|
887 | 887 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
888 | 888 | elif datatype == 4: |
|
889 | 889 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
890 | 890 | elif datatype == 5: |
|
891 | 891 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
892 | 892 | else: |
|
893 | 893 | raise ValueError, 'Data type was not defined' |
|
894 | 894 | |
|
895 | 895 | self.dtype = datatype_str |
|
896 | 896 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
897 | 897 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
898 | 898 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
899 | 899 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
900 | 900 | self.getBlockDimension() |
|
901 | 901 | |
|
902 | 902 | |
|
903 | 903 | def __verifyFile(self, filename, msgFlag=True): |
|
904 | 904 | msg = None |
|
905 | 905 | try: |
|
906 | 906 | fp = open(filename, 'rb') |
|
907 | 907 | currentPosition = fp.tell() |
|
908 | 908 | except: |
|
909 | 909 | if msgFlag: |
|
910 | 910 | print "The file %s can't be opened" % (filename) |
|
911 | 911 | return False |
|
912 | 912 | |
|
913 | 913 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
914 | 914 | |
|
915 | 915 | if neededSize == 0: |
|
916 | 916 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
917 | 917 | systemHeaderObj = SystemHeader() |
|
918 | 918 | radarControllerHeaderObj = RadarControllerHeader() |
|
919 | 919 | processingHeaderObj = ProcessingHeader() |
|
920 | 920 | |
|
921 | 921 | try: |
|
922 | 922 | if not( basicHeaderObj.read(fp) ): raise IOError |
|
923 | 923 | if not( systemHeaderObj.read(fp) ): raise IOError |
|
924 | 924 | if not( radarControllerHeaderObj.read(fp) ): raise IOError |
|
925 | 925 | if not( processingHeaderObj.read(fp) ): raise IOError |
|
926 | 926 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
927 | 927 | |
|
928 | 928 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
929 | 929 | |
|
930 | 930 | except: |
|
931 | 931 | if msgFlag: |
|
932 | 932 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
933 | 933 | |
|
934 | 934 | fp.close() |
|
935 | 935 | return False |
|
936 | 936 | else: |
|
937 | 937 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
938 | 938 | |
|
939 | 939 | fp.close() |
|
940 | 940 | fileSize = os.path.getsize(filename) |
|
941 | 941 | currentSize = fileSize - currentPosition |
|
942 | 942 | if currentSize < neededSize: |
|
943 | 943 | if msgFlag and (msg != None): |
|
944 | 944 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
945 | 945 | return False |
|
946 | 946 | |
|
947 | 947 | return True |
|
948 | 948 | |
|
949 | 949 | def setup(self, |
|
950 | 950 | path=None, |
|
951 | 951 | startDate=None, |
|
952 | 952 | endDate=None, |
|
953 | 953 | startTime=datetime.time(0,0,0), |
|
954 | 954 | endTime=datetime.time(23,59,59), |
|
955 | 955 | set=None, |
|
956 | 956 | expLabel = "", |
|
957 | 957 | ext = None, |
|
958 | 958 | online = False, |
|
959 | 959 | delay = 60, |
|
960 | 960 | walk = True): |
|
961 | 961 | |
|
962 | 962 | if path == None: |
|
963 | 963 | raise ValueError, "The path is not valid" |
|
964 | 964 | |
|
965 | 965 | if ext == None: |
|
966 | 966 | ext = self.ext |
|
967 | 967 | |
|
968 | 968 | if online: |
|
969 | 969 | print "Searching files in online mode..." |
|
970 | 970 | |
|
971 | 971 | for nTries in range( self.nTries ): |
|
972 | 972 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) |
|
973 | 973 | |
|
974 | 974 | if fullpath: |
|
975 | 975 | break |
|
976 | 976 | |
|
977 | 977 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
978 | 978 | time.sleep( self.delay ) |
|
979 | 979 | |
|
980 | 980 | if not(fullpath): |
|
981 | 981 | print "There 'isn't valied files in %s" % path |
|
982 | 982 | return None |
|
983 | 983 | |
|
984 | 984 | self.year = year |
|
985 | 985 | self.doy = doy |
|
986 | 986 | self.set = set - 1 |
|
987 | 987 | self.path = path |
|
988 | 988 | self.foldercounter = foldercounter |
|
989 | 989 | last_set = None |
|
990 | 990 | |
|
991 | 991 | else: |
|
992 | 992 | print "Searching files in offline mode ..." |
|
993 | 993 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
994 | 994 | startTime=startTime, endTime=endTime, |
|
995 | 995 | set=set, expLabel=expLabel, ext=ext, |
|
996 | 996 | walk=walk) |
|
997 | 997 | |
|
998 | 998 | if not(pathList): |
|
999 | 999 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
1000 | 1000 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
1001 | 1001 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
1002 | 1002 | |
|
1003 | 1003 | sys.exit(-1) |
|
1004 | 1004 | |
|
1005 | 1005 | |
|
1006 | 1006 | self.fileIndex = -1 |
|
1007 | 1007 | self.pathList = pathList |
|
1008 | 1008 | self.filenameList = filenameList |
|
1009 | 1009 | file_name = os.path.basename(filenameList[-1]) |
|
1010 | 1010 | basename, ext = os.path.splitext(file_name) |
|
1011 | 1011 | last_set = int(basename[-3:]) |
|
1012 | 1012 | |
|
1013 | 1013 | self.online = online |
|
1014 | 1014 | self.delay = delay |
|
1015 | 1015 | ext = ext.lower() |
|
1016 | 1016 | self.ext = ext |
|
1017 | 1017 | |
|
1018 | 1018 | if not(self.setNextFile()): |
|
1019 | 1019 | if (startDate!=None) and (endDate!=None): |
|
1020 | 1020 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
1021 | 1021 | elif startDate != None: |
|
1022 | 1022 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
1023 | 1023 | else: |
|
1024 | 1024 | print "No files" |
|
1025 | 1025 | |
|
1026 | 1026 | sys.exit(-1) |
|
1027 | 1027 | |
|
1028 | 1028 | # self.updateDataHeader() |
|
1029 | 1029 | if last_set != None: |
|
1030 | 1030 | self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock |
|
1031 | 1031 | return self.dataOut |
|
1032 | 1032 | |
|
1033 | 1033 | def getBasicHeader(self): |
|
1034 | 1034 | |
|
1035 | 1035 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
1036 | 1036 | |
|
1037 | 1037 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
1038 | 1038 | |
|
1039 | 1039 | self.dataOut.timeZone = self.basicHeaderObj.timeZone |
|
1040 | 1040 | |
|
1041 | 1041 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag |
|
1042 | 1042 | |
|
1043 | 1043 | self.dataOut.errorCount = self.basicHeaderObj.errorCount |
|
1044 | 1044 | |
|
1045 | 1045 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime |
|
1046 | 1046 | |
|
1047 | 1047 | def getFirstHeader(self): |
|
1048 | 1048 | |
|
1049 | 1049 | raise ValueError, "This method has not been implemented" |
|
1050 | 1050 | |
|
1051 | 1051 | def getData(): |
|
1052 | 1052 | |
|
1053 | 1053 | raise ValueError, "This method has not been implemented" |
|
1054 | 1054 | |
|
1055 | 1055 | def hasNotDataInBuffer(): |
|
1056 | 1056 | |
|
1057 | 1057 | raise ValueError, "This method has not been implemented" |
|
1058 | 1058 | |
|
1059 | 1059 | def readBlock(): |
|
1060 | 1060 | |
|
1061 | 1061 | raise ValueError, "This method has not been implemented" |
|
1062 | 1062 | |
|
1063 | 1063 | def isEndProcess(self): |
|
1064 | 1064 | |
|
1065 | 1065 | return self.flagNoMoreFiles |
|
1066 | 1066 | |
|
1067 | 1067 | def printReadBlocks(self): |
|
1068 | 1068 | |
|
1069 | 1069 | print "Number of read blocks per file %04d" %self.nReadBlocks |
|
1070 | 1070 | |
|
1071 | 1071 | def printTotalBlocks(self): |
|
1072 | 1072 | |
|
1073 | 1073 | print "Number of read blocks %04d" %self.nTotalBlocks |
|
1074 | 1074 | |
|
1075 | 1075 | def printNumberOfBlock(self): |
|
1076 | 1076 | |
|
1077 | 1077 | if self.flagIsNewBlock: |
|
1078 | 1078 | print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) |
|
1079 | 1079 | self.dataOut.blocknow = self.basicHeaderObj.dataBlock |
|
1080 | 1080 | def printInfo(self): |
|
1081 | 1081 | |
|
1082 | 1082 | if self.__printInfo == False: |
|
1083 | 1083 | return |
|
1084 | 1084 | |
|
1085 | 1085 | self.basicHeaderObj.printInfo() |
|
1086 | 1086 | self.systemHeaderObj.printInfo() |
|
1087 | 1087 | self.radarControllerHeaderObj.printInfo() |
|
1088 | 1088 | self.processingHeaderObj.printInfo() |
|
1089 | 1089 | |
|
1090 | 1090 | self.__printInfo = False |
|
1091 | 1091 | |
|
1092 | 1092 | |
|
1093 | 1093 | def run(self, **kwargs): |
|
1094 | 1094 | |
|
1095 | 1095 | if not(self.isConfig): |
|
1096 | 1096 | |
|
1097 | 1097 | # self.dataOut = dataOut |
|
1098 | 1098 | self.setup(**kwargs) |
|
1099 | 1099 | self.isConfig = True |
|
1100 | 1100 | |
|
1101 | 1101 | self.getData() |
|
1102 | 1102 | |
|
1103 | 1103 | class JRODataWriter(JRODataIO, Operation): |
|
1104 | 1104 | |
|
1105 | 1105 | """ |
|
1106 | 1106 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
1107 | 1107 | de los datos siempre se realiza por bloques. |
|
1108 | 1108 | """ |
|
1109 | 1109 | |
|
1110 | 1110 | blockIndex = 0 |
|
1111 | 1111 | |
|
1112 | 1112 | path = None |
|
1113 | 1113 | |
|
1114 | 1114 | setFile = None |
|
1115 | 1115 | |
|
1116 | 1116 | profilesPerBlock = None |
|
1117 | 1117 | |
|
1118 | 1118 | blocksPerFile = None |
|
1119 | 1119 | |
|
1120 | 1120 | nWriteBlocks = 0 |
|
1121 | 1121 | |
|
1122 | 1122 | def __init__(self, dataOut=None): |
|
1123 | 1123 | raise ValueError, "Not implemented" |
|
1124 | 1124 | |
|
1125 | 1125 | |
|
1126 | 1126 | def hasAllDataInBuffer(self): |
|
1127 | 1127 | raise ValueError, "Not implemented" |
|
1128 | 1128 | |
|
1129 | 1129 | |
|
1130 | 1130 | def setBlockDimension(self): |
|
1131 | 1131 | raise ValueError, "Not implemented" |
|
1132 | 1132 | |
|
1133 | 1133 | |
|
1134 | 1134 | def writeBlock(self): |
|
1135 | 1135 | raise ValueError, "No implemented" |
|
1136 | 1136 | |
|
1137 | 1137 | |
|
1138 | 1138 | def putData(self): |
|
1139 | 1139 | raise ValueError, "No implemented" |
|
1140 | 1140 | |
|
1141 | 1141 | |
|
1142 | 1142 | def setBasicHeader(self): |
|
1143 | 1143 | |
|
1144 | 1144 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
1145 | 1145 | self.basicHeaderObj.version = self.versionFile |
|
1146 | 1146 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
1147 | 1147 | |
|
1148 | 1148 | utc = numpy.floor(self.dataOut.utctime) |
|
1149 | 1149 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
1150 | 1150 | |
|
1151 | 1151 | self.basicHeaderObj.utc = utc |
|
1152 | 1152 | self.basicHeaderObj.miliSecond = milisecond |
|
1153 | 1153 | self.basicHeaderObj.timeZone = self.dataOut.timeZone |
|
1154 | 1154 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag |
|
1155 | 1155 | self.basicHeaderObj.errorCount = self.dataOut.errorCount |
|
1156 | 1156 | |
|
1157 | 1157 | def setFirstHeader(self): |
|
1158 | 1158 | """ |
|
1159 | 1159 | Obtiene una copia del First Header |
|
1160 | 1160 | |
|
1161 | 1161 | Affected: |
|
1162 | 1162 | |
|
1163 | 1163 | self.basicHeaderObj |
|
1164 | 1164 | self.systemHeaderObj |
|
1165 | 1165 | self.radarControllerHeaderObj |
|
1166 | 1166 | self.processingHeaderObj self. |
|
1167 | 1167 | |
|
1168 | 1168 | Return: |
|
1169 | 1169 | None |
|
1170 | 1170 | """ |
|
1171 | 1171 | |
|
1172 | 1172 | raise ValueError, "No implemented" |
|
1173 | 1173 | |
|
1174 | 1174 | def __writeFirstHeader(self): |
|
1175 | 1175 | """ |
|
1176 | 1176 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
1177 | 1177 | |
|
1178 | 1178 | Affected: |
|
1179 | 1179 | __dataType |
|
1180 | 1180 | |
|
1181 | 1181 | Return: |
|
1182 | 1182 | None |
|
1183 | 1183 | """ |
|
1184 | 1184 | |
|
1185 | 1185 | # CALCULAR PARAMETROS |
|
1186 | 1186 | |
|
1187 | 1187 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
1188 | 1188 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
1189 | 1189 | |
|
1190 | 1190 | self.basicHeaderObj.write(self.fp) |
|
1191 | 1191 | self.systemHeaderObj.write(self.fp) |
|
1192 | 1192 | self.radarControllerHeaderObj.write(self.fp) |
|
1193 | 1193 | self.processingHeaderObj.write(self.fp) |
|
1194 | 1194 | |
|
1195 | 1195 | self.dtype = self.dataOut.dtype |
|
1196 | 1196 | |
|
1197 | 1197 | def __setNewBlock(self): |
|
1198 | 1198 | """ |
|
1199 | 1199 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
1200 | 1200 | |
|
1201 | 1201 | Return: |
|
1202 | 1202 | 0 : si no pudo escribir nada |
|
1203 | 1203 | 1 : Si escribio el Basic el First Header |
|
1204 | 1204 | """ |
|
1205 | 1205 | if self.fp == None: |
|
1206 | 1206 | self.setNextFile() |
|
1207 | 1207 | |
|
1208 | 1208 | if self.flagIsNewFile: |
|
1209 | 1209 | return 1 |
|
1210 | 1210 | |
|
1211 | 1211 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
1212 | 1212 | self.basicHeaderObj.write(self.fp) |
|
1213 | 1213 | return 1 |
|
1214 | 1214 | |
|
1215 | 1215 | if not( self.setNextFile() ): |
|
1216 | 1216 | return 0 |
|
1217 | 1217 | |
|
1218 | 1218 | return 1 |
|
1219 | 1219 | |
|
1220 | 1220 | |
|
1221 | 1221 | def writeNextBlock(self): |
|
1222 | 1222 | """ |
|
1223 | 1223 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1224 | 1224 | |
|
1225 | 1225 | Return: |
|
1226 | 1226 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1227 | 1227 | 1 : Si no pudo escribir el bloque de datos |
|
1228 | 1228 | """ |
|
1229 | 1229 | if not( self.__setNewBlock() ): |
|
1230 | 1230 | return 0 |
|
1231 | 1231 | |
|
1232 | 1232 | self.writeBlock() |
|
1233 | 1233 | |
|
1234 | 1234 | return 1 |
|
1235 | 1235 | |
|
1236 | 1236 | def setNextFile(self): |
|
1237 | 1237 | """ |
|
1238 | 1238 | Determina el siguiente file que sera escrito |
|
1239 | 1239 | |
|
1240 | 1240 | Affected: |
|
1241 | 1241 | self.filename |
|
1242 | 1242 | self.subfolder |
|
1243 | 1243 | self.fp |
|
1244 | 1244 | self.setFile |
|
1245 | 1245 | self.flagIsNewFile |
|
1246 | 1246 | |
|
1247 | 1247 | Return: |
|
1248 | 1248 | 0 : Si el archivo no puede ser escrito |
|
1249 | 1249 | 1 : Si el archivo esta listo para ser escrito |
|
1250 | 1250 | """ |
|
1251 | 1251 | ext = self.ext |
|
1252 | 1252 | path = self.path |
|
1253 | 1253 | |
|
1254 | 1254 | if self.fp != None: |
|
1255 | 1255 | self.fp.close() |
|
1256 | 1256 | |
|
1257 | 1257 | timeTuple = time.localtime( self.dataOut.utctime) |
|
1258 | 1258 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1259 | 1259 | |
|
1260 | 1260 | fullpath = os.path.join( path, subfolder ) |
|
1261 | 1261 | if not( os.path.exists(fullpath) ): |
|
1262 | 1262 | os.mkdir(fullpath) |
|
1263 | 1263 | self.setFile = -1 #inicializo mi contador de seteo |
|
1264 | 1264 | else: |
|
1265 | 1265 | filesList = os.listdir( fullpath ) |
|
1266 | 1266 | if len( filesList ) > 0: |
|
1267 | 1267 | filesList = sorted( filesList, key=str.lower ) |
|
1268 | 1268 | filen = filesList[-1] |
|
1269 | 1269 | # el filename debera tener el siguiente formato |
|
1270 | 1270 | # 0 1234 567 89A BCDE (hex) |
|
1271 | 1271 | # x YYYY DDD SSS .ext |
|
1272 | 1272 | if isNumber( filen[8:11] ): |
|
1273 | 1273 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
1274 | 1274 | else: |
|
1275 | 1275 | self.setFile = -1 |
|
1276 | 1276 | else: |
|
1277 | 1277 | self.setFile = -1 #inicializo mi contador de seteo |
|
1278 | 1278 | |
|
1279 | 1279 | setFile = self.setFile |
|
1280 | 1280 | setFile += 1 |
|
1281 | 1281 | |
|
1282 | 1282 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
1283 | 1283 | timeTuple.tm_year, |
|
1284 | 1284 | timeTuple.tm_yday, |
|
1285 | 1285 | setFile, |
|
1286 | 1286 | ext ) |
|
1287 | 1287 | |
|
1288 | 1288 | filename = os.path.join( path, subfolder, file ) |
|
1289 | 1289 | |
|
1290 | 1290 | fp = open( filename,'wb' ) |
|
1291 | 1291 | |
|
1292 | 1292 | self.blockIndex = 0 |
|
1293 | 1293 | |
|
1294 | 1294 | #guardando atributos |
|
1295 | 1295 | self.filename = filename |
|
1296 | 1296 | self.subfolder = subfolder |
|
1297 | 1297 | self.fp = fp |
|
1298 | 1298 | self.setFile = setFile |
|
1299 | 1299 | self.flagIsNewFile = 1 |
|
1300 | 1300 | |
|
1301 | 1301 | self.setFirstHeader() |
|
1302 | 1302 | |
|
1303 | 1303 | print 'Writing the file: %s'%self.filename |
|
1304 | 1304 | |
|
1305 | 1305 | self.__writeFirstHeader() |
|
1306 | 1306 | |
|
1307 | 1307 | return 1 |
|
1308 | 1308 | |
|
1309 | 1309 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=0, ext=None): |
|
1310 | 1310 | """ |
|
1311 | 1311 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1312 | 1312 | |
|
1313 | 1313 | Inputs: |
|
1314 | 1314 | path : el path destino en el cual se escribiran los files a crear |
|
1315 | 1315 | format : formato en el cual sera salvado un file |
|
1316 | 1316 | set : el setebo del file |
|
1317 | 1317 | |
|
1318 | 1318 | Return: |
|
1319 | 1319 | 0 : Si no realizo un buen seteo |
|
1320 | 1320 | 1 : Si realizo un buen seteo |
|
1321 | 1321 | """ |
|
1322 | 1322 | |
|
1323 | 1323 | if ext == None: |
|
1324 | 1324 | ext = self.ext |
|
1325 | 1325 | |
|
1326 | 1326 | ext = ext.lower() |
|
1327 | 1327 | |
|
1328 | 1328 | self.ext = ext |
|
1329 | 1329 | |
|
1330 | 1330 | self.path = path |
|
1331 | 1331 | |
|
1332 | 1332 | self.setFile = set - 1 |
|
1333 | 1333 | |
|
1334 | 1334 | self.blocksPerFile = blocksPerFile |
|
1335 | 1335 | |
|
1336 | 1336 | self.profilesPerBlock = profilesPerBlock |
|
1337 | 1337 | |
|
1338 | 1338 | self.dataOut = dataOut |
|
1339 | 1339 | |
|
1340 | 1340 | if not(self.setNextFile()): |
|
1341 | 1341 | print "There isn't a next file" |
|
1342 | 1342 | return 0 |
|
1343 | 1343 | |
|
1344 | 1344 | self.setBlockDimension() |
|
1345 | 1345 | |
|
1346 | 1346 | return 1 |
|
1347 | 1347 | |
|
1348 | 1348 | def run(self, dataOut, **kwargs): |
|
1349 | 1349 | |
|
1350 | 1350 | if not(self.isConfig): |
|
1351 | 1351 | |
|
1352 | 1352 | self.setup(dataOut, **kwargs) |
|
1353 | 1353 | self.isConfig = True |
|
1354 | 1354 | |
|
1355 | 1355 | self.putData() |
|
1356 | 1356 | |
|
1357 | 1357 | class VoltageReader(JRODataReader): |
|
1358 | 1358 | """ |
|
1359 | 1359 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
1360 | 1360 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
1361 | 1361 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
1362 | 1362 | |
|
1363 | 1363 | perfiles * alturas * canales |
|
1364 | 1364 | |
|
1365 | 1365 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1366 | 1366 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
1367 | 1367 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
1368 | 1368 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1369 | 1369 | |
|
1370 | 1370 | Example: |
|
1371 | 1371 | |
|
1372 | 1372 | dpath = "/home/myuser/data" |
|
1373 | 1373 | |
|
1374 | 1374 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1375 | 1375 | |
|
1376 | 1376 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1377 | 1377 | |
|
1378 | 1378 | readerObj = VoltageReader() |
|
1379 | 1379 | |
|
1380 | 1380 | readerObj.setup(dpath, startTime, endTime) |
|
1381 | 1381 | |
|
1382 | 1382 | while(True): |
|
1383 | 1383 | |
|
1384 | 1384 | #to get one profile |
|
1385 | 1385 | profile = readerObj.getData() |
|
1386 | 1386 | |
|
1387 | 1387 | #print the profile |
|
1388 | 1388 | print profile |
|
1389 | 1389 | |
|
1390 | 1390 | #If you want to see all datablock |
|
1391 | 1391 | print readerObj.datablock |
|
1392 | 1392 | |
|
1393 | 1393 | if readerObj.flagNoMoreFiles: |
|
1394 | 1394 | break |
|
1395 | 1395 | |
|
1396 | 1396 | """ |
|
1397 | 1397 | |
|
1398 | 1398 | ext = ".r" |
|
1399 | 1399 | |
|
1400 | 1400 | optchar = "D" |
|
1401 | 1401 | dataOut = None |
|
1402 | 1402 | |
|
1403 | 1403 | |
|
1404 | 1404 | def __init__(self): |
|
1405 | 1405 | """ |
|
1406 | 1406 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
1407 | 1407 | |
|
1408 | 1408 | Input: |
|
1409 | 1409 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
1410 | 1410 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1411 | 1411 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1412 | 1412 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1413 | 1413 | bloque de datos. |
|
1414 | 1414 | Si este parametro no es pasado se creara uno internamente. |
|
1415 | 1415 | |
|
1416 | 1416 | Variables afectadas: |
|
1417 | 1417 | self.dataOut |
|
1418 | 1418 | |
|
1419 | 1419 | Return: |
|
1420 | 1420 | None |
|
1421 | 1421 | """ |
|
1422 | 1422 | |
|
1423 | 1423 | self.isConfig = False |
|
1424 | 1424 | |
|
1425 | 1425 | self.datablock = None |
|
1426 | 1426 | |
|
1427 | 1427 | self.utc = 0 |
|
1428 | 1428 | |
|
1429 | 1429 | self.ext = ".r" |
|
1430 | 1430 | |
|
1431 | 1431 | self.optchar = "D" |
|
1432 | 1432 | |
|
1433 | 1433 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1434 | 1434 | |
|
1435 | 1435 | self.systemHeaderObj = SystemHeader() |
|
1436 | 1436 | |
|
1437 | 1437 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1438 | 1438 | |
|
1439 | 1439 | self.processingHeaderObj = ProcessingHeader() |
|
1440 | 1440 | |
|
1441 | 1441 | self.online = 0 |
|
1442 | 1442 | |
|
1443 | 1443 | self.fp = None |
|
1444 | 1444 | |
|
1445 | 1445 | self.idFile = None |
|
1446 | 1446 | |
|
1447 | 1447 | self.dtype = None |
|
1448 | 1448 | |
|
1449 | 1449 | self.fileSizeByHeader = None |
|
1450 | 1450 | |
|
1451 | 1451 | self.filenameList = [] |
|
1452 | 1452 | |
|
1453 | 1453 | self.filename = None |
|
1454 | 1454 | |
|
1455 | 1455 | self.fileSize = None |
|
1456 | 1456 | |
|
1457 | 1457 | self.firstHeaderSize = 0 |
|
1458 | 1458 | |
|
1459 | 1459 | self.basicHeaderSize = 24 |
|
1460 | 1460 | |
|
1461 | 1461 | self.pathList = [] |
|
1462 | 1462 | |
|
1463 | 1463 | self.filenameList = [] |
|
1464 | 1464 | |
|
1465 | 1465 | self.lastUTTime = 0 |
|
1466 | 1466 | |
|
1467 | 1467 | self.maxTimeStep = 30 |
|
1468 | 1468 | |
|
1469 | 1469 | self.flagNoMoreFiles = 0 |
|
1470 | 1470 | |
|
1471 | 1471 | self.set = 0 |
|
1472 | 1472 | |
|
1473 | 1473 | self.path = None |
|
1474 | 1474 | |
|
1475 | 1475 | self.profileIndex = 2**32-1 |
|
1476 | 1476 | |
|
1477 | 1477 | self.delay = 3 #seconds |
|
1478 | 1478 | |
|
1479 | 1479 | self.nTries = 3 #quantity tries |
|
1480 | 1480 | |
|
1481 | 1481 | self.nFiles = 3 #number of files for searching |
|
1482 | 1482 | |
|
1483 | 1483 | self.nReadBlocks = 0 |
|
1484 | 1484 | |
|
1485 | 1485 | self.flagIsNewFile = 1 |
|
1486 | 1486 | |
|
1487 | 1487 | self.__isFirstTimeOnline = 1 |
|
1488 | 1488 | |
|
1489 | 1489 | self.ippSeconds = 0 |
|
1490 | 1490 | |
|
1491 | 1491 | self.flagTimeBlock = 0 |
|
1492 | 1492 | |
|
1493 | 1493 | self.flagIsNewBlock = 0 |
|
1494 | 1494 | |
|
1495 | 1495 | self.nTotalBlocks = 0 |
|
1496 | 1496 | |
|
1497 | 1497 | self.blocksize = 0 |
|
1498 | 1498 | |
|
1499 | 1499 | self.dataOut = self.createObjByDefault() |
|
1500 | 1500 | |
|
1501 | 1501 | def createObjByDefault(self): |
|
1502 | 1502 | |
|
1503 | 1503 | dataObj = Voltage() |
|
1504 | 1504 | |
|
1505 | 1505 | return dataObj |
|
1506 | 1506 | |
|
1507 | 1507 | def __hasNotDataInBuffer(self): |
|
1508 | 1508 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1509 | 1509 | return 1 |
|
1510 | 1510 | return 0 |
|
1511 | 1511 | |
|
1512 | 1512 | |
|
1513 | 1513 | def getBlockDimension(self): |
|
1514 | 1514 | """ |
|
1515 | 1515 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1516 | 1516 | |
|
1517 | 1517 | Affected: |
|
1518 | 1518 | self.blocksize |
|
1519 | 1519 | |
|
1520 | 1520 | Return: |
|
1521 | 1521 | None |
|
1522 | 1522 | """ |
|
1523 | 1523 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
1524 | 1524 | self.blocksize = pts2read |
|
1525 | 1525 | |
|
1526 | 1526 | |
|
1527 | 1527 | def readBlock(self): |
|
1528 | 1528 | """ |
|
1529 | 1529 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1530 | 1530 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1531 | 1531 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1532 | 1532 | es seteado a 0 |
|
1533 | 1533 | |
|
1534 | 1534 | Inputs: |
|
1535 | 1535 | None |
|
1536 | 1536 | |
|
1537 | 1537 | Return: |
|
1538 | 1538 | None |
|
1539 | 1539 | |
|
1540 | 1540 | Affected: |
|
1541 | 1541 | self.profileIndex |
|
1542 | 1542 | self.datablock |
|
1543 | 1543 | self.flagIsNewFile |
|
1544 | 1544 | self.flagIsNewBlock |
|
1545 | 1545 | self.nTotalBlocks |
|
1546 | 1546 | |
|
1547 | 1547 | Exceptions: |
|
1548 | 1548 | Si un bloque leido no es un bloque valido |
|
1549 | 1549 | """ |
|
1550 | 1550 | current_pointer_location = self.fp.tell() |
|
1551 | 1551 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1552 | 1552 | |
|
1553 | 1553 | try: |
|
1554 | 1554 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1555 | 1555 | except: |
|
1556 | 1556 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
1557 | 1557 | |
|
1558 | 1558 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
1559 | 1559 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1560 | 1560 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1561 | 1561 | # return 0 |
|
1562 | 1562 | |
|
1563 | 1563 | junk = numpy.transpose(junk, (2,0,1)) |
|
1564 | 1564 | self.datablock = junk['real'] + junk['imag']*1j |
|
1565 | 1565 | |
|
1566 | 1566 | self.profileIndex = 0 |
|
1567 | 1567 | |
|
1568 | 1568 | self.flagIsNewFile = 0 |
|
1569 | 1569 | self.flagIsNewBlock = 1 |
|
1570 | 1570 | |
|
1571 | 1571 | self.nTotalBlocks += 1 |
|
1572 | 1572 | self.nReadBlocks += 1 |
|
1573 | 1573 | |
|
1574 | 1574 | return 1 |
|
1575 | 1575 | |
|
1576 | 1576 | def getFirstHeader(self): |
|
1577 | 1577 | |
|
1578 | 1578 | self.dataOut.dtype = self.dtype |
|
1579 | 1579 | |
|
1580 | 1580 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
1581 | 1581 | |
|
1582 | 1582 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1583 | 1583 | |
|
1584 | 1584 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
1585 | 1585 | |
|
1586 | 1586 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
1587 | 1587 | |
|
1588 | 1588 | self.dataOut.ippSeconds = self.ippSeconds |
|
1589 | 1589 | |
|
1590 | 1590 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt |
|
1591 | 1591 | |
|
1592 | 1592 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
1593 | 1593 | |
|
1594 | 1594 | self.dataOut.flagShiftFFT = False |
|
1595 | 1595 | |
|
1596 | 1596 | if self.radarControllerHeaderObj.code != None: |
|
1597 | 1597 | |
|
1598 | 1598 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
1599 | 1599 | |
|
1600 | 1600 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
1601 | 1601 | |
|
1602 | 1602 | self.dataOut.code = self.radarControllerHeaderObj.code |
|
1603 | 1603 | |
|
1604 | 1604 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
1605 | 1605 | |
|
1606 | 1606 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
1607 | 1607 | |
|
1608 | 1608 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
1609 | 1609 | |
|
1610 | 1610 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip |
|
1611 | 1611 | |
|
1612 | 1612 | self.dataOut.flagShiftFFT = False |
|
1613 | 1613 | |
|
1614 | 1614 | def getData(self): |
|
1615 | 1615 | """ |
|
1616 | 1616 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
1617 | 1617 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1618 | 1618 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1619 | 1619 | |
|
1620 | 1620 | Ademas incrementa el contador del buffer en 1. |
|
1621 | 1621 | |
|
1622 | 1622 | Return: |
|
1623 | 1623 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
1624 | 1624 | buffer. Si no hay mas archivos a leer retorna None. |
|
1625 | 1625 | |
|
1626 | 1626 | Variables afectadas: |
|
1627 | 1627 | self.dataOut |
|
1628 | 1628 | self.profileIndex |
|
1629 | 1629 | |
|
1630 | 1630 | Affected: |
|
1631 | 1631 | self.dataOut |
|
1632 | 1632 | self.profileIndex |
|
1633 | 1633 | self.flagTimeBlock |
|
1634 | 1634 | self.flagIsNewBlock |
|
1635 | 1635 | """ |
|
1636 | 1636 | |
|
1637 | 1637 | if self.flagNoMoreFiles: |
|
1638 | 1638 | self.dataOut.flagNoData = True |
|
1639 | 1639 | print 'Process finished' |
|
1640 | 1640 | return 0 |
|
1641 | 1641 | |
|
1642 | 1642 | self.flagTimeBlock = 0 |
|
1643 | 1643 | self.flagIsNewBlock = 0 |
|
1644 | 1644 | |
|
1645 | 1645 | if self.__hasNotDataInBuffer(): |
|
1646 | 1646 | |
|
1647 | 1647 | if not( self.readNextBlock() ): |
|
1648 | 1648 | return 0 |
|
1649 | 1649 | |
|
1650 | 1650 | self.getFirstHeader() |
|
1651 | 1651 | |
|
1652 | 1652 | if self.datablock == None: |
|
1653 | 1653 | self.dataOut.flagNoData = True |
|
1654 | 1654 | return 0 |
|
1655 | 1655 | |
|
1656 | 1656 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
1657 | 1657 | |
|
1658 | 1658 | self.dataOut.flagNoData = False |
|
1659 | 1659 | |
|
1660 | 1660 | self.getBasicHeader() |
|
1661 | 1661 | |
|
1662 | 1662 | self.profileIndex += 1 |
|
1663 | 1663 | |
|
1664 | 1664 | self.dataOut.realtime = self.online |
|
1665 | 1665 | |
|
1666 | 1666 | return self.dataOut.data |
|
1667 | 1667 | |
|
1668 | 1668 | |
|
1669 | 1669 | class VoltageWriter(JRODataWriter): |
|
1670 | 1670 | """ |
|
1671 | 1671 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
1672 | 1672 | de los datos siempre se realiza por bloques. |
|
1673 | 1673 | """ |
|
1674 | 1674 | |
|
1675 | 1675 | ext = ".r" |
|
1676 | 1676 | |
|
1677 | 1677 | optchar = "D" |
|
1678 | 1678 | |
|
1679 | 1679 | shapeBuffer = None |
|
1680 | 1680 | |
|
1681 | 1681 | |
|
1682 | 1682 | def __init__(self): |
|
1683 | 1683 | """ |
|
1684 | 1684 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
1685 | 1685 | |
|
1686 | 1686 | Affected: |
|
1687 | 1687 | self.dataOut |
|
1688 | 1688 | |
|
1689 | 1689 | Return: None |
|
1690 | 1690 | """ |
|
1691 | 1691 | |
|
1692 | 1692 | self.nTotalBlocks = 0 |
|
1693 | 1693 | |
|
1694 | 1694 | self.profileIndex = 0 |
|
1695 | 1695 | |
|
1696 | 1696 | self.isConfig = False |
|
1697 | 1697 | |
|
1698 | 1698 | self.fp = None |
|
1699 | 1699 | |
|
1700 | 1700 | self.flagIsNewFile = 1 |
|
1701 | 1701 | |
|
1702 | 1702 | self.nTotalBlocks = 0 |
|
1703 | 1703 | |
|
1704 | 1704 | self.flagIsNewBlock = 0 |
|
1705 | 1705 | |
|
1706 | 1706 | self.setFile = None |
|
1707 | 1707 | |
|
1708 | 1708 | self.dtype = None |
|
1709 | 1709 | |
|
1710 | 1710 | self.path = None |
|
1711 | 1711 | |
|
1712 | 1712 | self.filename = None |
|
1713 | 1713 | |
|
1714 | 1714 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1715 | 1715 | |
|
1716 | 1716 | self.systemHeaderObj = SystemHeader() |
|
1717 | 1717 | |
|
1718 | 1718 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1719 | 1719 | |
|
1720 | 1720 | self.processingHeaderObj = ProcessingHeader() |
|
1721 | 1721 | |
|
1722 | 1722 | def hasAllDataInBuffer(self): |
|
1723 | 1723 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1724 | 1724 | return 1 |
|
1725 | 1725 | return 0 |
|
1726 | 1726 | |
|
1727 | 1727 | |
|
1728 | 1728 | def setBlockDimension(self): |
|
1729 | 1729 | """ |
|
1730 | 1730 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
1731 | 1731 | |
|
1732 | 1732 | Affected: |
|
1733 | 1733 | self.shape_spc_Buffer |
|
1734 | 1734 | self.shape_cspc_Buffer |
|
1735 | 1735 | self.shape_dc_Buffer |
|
1736 | 1736 | |
|
1737 | 1737 | Return: None |
|
1738 | 1738 | """ |
|
1739 | 1739 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
1740 | 1740 | self.processingHeaderObj.nHeights, |
|
1741 | 1741 | self.systemHeaderObj.nChannels) |
|
1742 | 1742 | |
|
1743 | 1743 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
1744 | 1744 | self.processingHeaderObj.profilesPerBlock, |
|
1745 | 1745 | self.processingHeaderObj.nHeights), |
|
1746 | 1746 | dtype=numpy.dtype('complex64')) |
|
1747 | 1747 | |
|
1748 | 1748 | |
|
1749 | 1749 | def writeBlock(self): |
|
1750 | 1750 | """ |
|
1751 | 1751 | Escribe el buffer en el file designado |
|
1752 | 1752 | |
|
1753 | 1753 | Affected: |
|
1754 | 1754 | self.profileIndex |
|
1755 | 1755 | self.flagIsNewFile |
|
1756 | 1756 | self.flagIsNewBlock |
|
1757 | 1757 | self.nTotalBlocks |
|
1758 | 1758 | self.blockIndex |
|
1759 | 1759 | |
|
1760 | 1760 | Return: None |
|
1761 | 1761 | """ |
|
1762 | 1762 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
1763 | 1763 | |
|
1764 | 1764 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
1765 | 1765 | |
|
1766 | 1766 | data['real'] = junk.real |
|
1767 | 1767 | data['imag'] = junk.imag |
|
1768 | 1768 | |
|
1769 | 1769 | data = data.reshape( (-1) ) |
|
1770 | 1770 | |
|
1771 | 1771 | data.tofile( self.fp ) |
|
1772 | 1772 | |
|
1773 | 1773 | self.datablock.fill(0) |
|
1774 | 1774 | |
|
1775 | 1775 | self.profileIndex = 0 |
|
1776 | 1776 | self.flagIsNewFile = 0 |
|
1777 | 1777 | self.flagIsNewBlock = 1 |
|
1778 | 1778 | |
|
1779 | 1779 | self.blockIndex += 1 |
|
1780 | 1780 | self.nTotalBlocks += 1 |
|
1781 | 1781 | |
|
1782 | 1782 | def putData(self): |
|
1783 | 1783 | """ |
|
1784 | 1784 | Setea un bloque de datos y luego los escribe en un file |
|
1785 | 1785 | |
|
1786 | 1786 | Affected: |
|
1787 | 1787 | self.flagIsNewBlock |
|
1788 | 1788 | self.profileIndex |
|
1789 | 1789 | |
|
1790 | 1790 | Return: |
|
1791 | 1791 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
1792 | 1792 | 1 : Si se escribio la data de un bloque en un file |
|
1793 | 1793 | """ |
|
1794 | 1794 | if self.dataOut.flagNoData: |
|
1795 | 1795 | return 0 |
|
1796 | 1796 | |
|
1797 | 1797 | self.flagIsNewBlock = 0 |
|
1798 | 1798 | |
|
1799 | 1799 | if self.dataOut.flagTimeBlock: |
|
1800 | 1800 | |
|
1801 | 1801 | self.datablock.fill(0) |
|
1802 | 1802 | self.profileIndex = 0 |
|
1803 | 1803 | self.setNextFile() |
|
1804 | 1804 | |
|
1805 | 1805 | if self.profileIndex == 0: |
|
1806 | 1806 | self.setBasicHeader() |
|
1807 | 1807 | |
|
1808 | 1808 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
1809 | 1809 | |
|
1810 | 1810 | self.profileIndex += 1 |
|
1811 | 1811 | |
|
1812 | 1812 | if self.hasAllDataInBuffer(): |
|
1813 | 1813 | #if self.flagIsNewFile: |
|
1814 | 1814 | self.writeNextBlock() |
|
1815 | 1815 | # self.setFirstHeader() |
|
1816 | 1816 | |
|
1817 | 1817 | return 1 |
|
1818 | 1818 | |
|
1819 | 1819 | def __getProcessFlags(self): |
|
1820 | 1820 | |
|
1821 | 1821 | processFlags = 0 |
|
1822 | 1822 | |
|
1823 | 1823 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1824 | 1824 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1825 | 1825 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1826 | 1826 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1827 | 1827 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1828 | 1828 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1829 | 1829 | |
|
1830 | 1830 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1831 | 1831 | |
|
1832 | 1832 | |
|
1833 | 1833 | |
|
1834 | 1834 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
1835 | 1835 | PROCFLAG.DATATYPE_SHORT, |
|
1836 | 1836 | PROCFLAG.DATATYPE_LONG, |
|
1837 | 1837 | PROCFLAG.DATATYPE_INT64, |
|
1838 | 1838 | PROCFLAG.DATATYPE_FLOAT, |
|
1839 | 1839 | PROCFLAG.DATATYPE_DOUBLE] |
|
1840 | 1840 | |
|
1841 | 1841 | |
|
1842 | 1842 | for index in range(len(dtypeList)): |
|
1843 | 1843 | if self.dataOut.dtype == dtypeList[index]: |
|
1844 | 1844 | dtypeValue = datatypeValueList[index] |
|
1845 | 1845 | break |
|
1846 | 1846 | |
|
1847 | 1847 | processFlags += dtypeValue |
|
1848 | 1848 | |
|
1849 | 1849 | if self.dataOut.flagDecodeData: |
|
1850 | 1850 | processFlags += PROCFLAG.DECODE_DATA |
|
1851 | 1851 | |
|
1852 | 1852 | if self.dataOut.flagDeflipData: |
|
1853 | 1853 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1854 | 1854 | |
|
1855 | 1855 | if self.dataOut.code != None: |
|
1856 | 1856 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1857 | 1857 | |
|
1858 | 1858 | if self.dataOut.nCohInt > 1: |
|
1859 | 1859 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1860 | 1860 | |
|
1861 | 1861 | return processFlags |
|
1862 | 1862 | |
|
1863 | 1863 | |
|
1864 | 1864 | def __getBlockSize(self): |
|
1865 | 1865 | ''' |
|
1866 | 1866 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
1867 | 1867 | ''' |
|
1868 | 1868 | |
|
1869 | 1869 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1870 | 1870 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1871 | 1871 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1872 | 1872 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1873 | 1873 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1874 | 1874 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1875 | 1875 | |
|
1876 | 1876 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1877 | 1877 | datatypeValueList = [1,2,4,8,4,8] |
|
1878 | 1878 | for index in range(len(dtypeList)): |
|
1879 | 1879 | if self.dataOut.dtype == dtypeList[index]: |
|
1880 | 1880 | datatypeValue = datatypeValueList[index] |
|
1881 | 1881 | break |
|
1882 | 1882 | |
|
1883 | 1883 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * datatypeValue * 2) |
|
1884 | 1884 | |
|
1885 | 1885 | return blocksize |
|
1886 | 1886 | |
|
1887 | 1887 | def setFirstHeader(self): |
|
1888 | 1888 | |
|
1889 | 1889 | """ |
|
1890 | 1890 | Obtiene una copia del First Header |
|
1891 | 1891 | |
|
1892 | 1892 | Affected: |
|
1893 | 1893 | self.systemHeaderObj |
|
1894 | 1894 | self.radarControllerHeaderObj |
|
1895 | 1895 | self.dtype |
|
1896 | 1896 | |
|
1897 | 1897 | Return: |
|
1898 | 1898 | None |
|
1899 | 1899 | """ |
|
1900 | 1900 | |
|
1901 | 1901 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
1902 | 1902 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
1903 | 1903 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
1904 | 1904 | |
|
1905 | 1905 | self.setBasicHeader() |
|
1906 | 1906 | |
|
1907 | 1907 | processingHeaderSize = 40 # bytes |
|
1908 | 1908 | self.processingHeaderObj.dtype = 0 # Voltage |
|
1909 | 1909 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
1910 | 1910 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
1911 | 1911 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
1912 | 1912 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
1913 | 1913 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
1914 | 1914 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
1915 | 1915 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
1916 | 1916 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
1917 | 1917 | |
|
1918 | 1918 | # if self.dataOut.code != None: |
|
1919 | 1919 | # self.processingHeaderObj.code = self.dataOut.code |
|
1920 | 1920 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
1921 | 1921 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
1922 | 1922 | # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
1923 | 1923 | # processingHeaderSize += codesize |
|
1924 | 1924 | |
|
1925 | 1925 | if self.processingHeaderObj.nWindows != 0: |
|
1926 | 1926 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
1927 | 1927 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
1928 | 1928 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
1929 | 1929 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
1930 | 1930 | processingHeaderSize += 12 |
|
1931 | 1931 | |
|
1932 | 1932 | self.processingHeaderObj.size = processingHeaderSize |
|
1933 | 1933 | |
|
1934 | 1934 | class SpectraReader(JRODataReader): |
|
1935 | 1935 | """ |
|
1936 | 1936 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
1937 | 1937 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
1938 | 1938 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
1939 | 1939 | |
|
1940 | 1940 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
1941 | 1941 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
1942 | 1942 | canales * alturas (DC Channels) |
|
1943 | 1943 | |
|
1944 | 1944 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1945 | 1945 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
1946 | 1946 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
1947 | 1947 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1948 | 1948 | |
|
1949 | 1949 | Example: |
|
1950 | 1950 | dpath = "/home/myuser/data" |
|
1951 | 1951 | |
|
1952 | 1952 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1953 | 1953 | |
|
1954 | 1954 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1955 | 1955 | |
|
1956 | 1956 | readerObj = SpectraReader() |
|
1957 | 1957 | |
|
1958 | 1958 | readerObj.setup(dpath, startTime, endTime) |
|
1959 | 1959 | |
|
1960 | 1960 | while(True): |
|
1961 | 1961 | |
|
1962 | 1962 | readerObj.getData() |
|
1963 | 1963 | |
|
1964 | 1964 | print readerObj.data_spc |
|
1965 | 1965 | |
|
1966 | 1966 | print readerObj.data_cspc |
|
1967 | 1967 | |
|
1968 | 1968 | print readerObj.data_dc |
|
1969 | 1969 | |
|
1970 | 1970 | if readerObj.flagNoMoreFiles: |
|
1971 | 1971 | break |
|
1972 | 1972 | |
|
1973 | 1973 | """ |
|
1974 | 1974 | |
|
1975 | 1975 | pts2read_SelfSpectra = 0 |
|
1976 | 1976 | |
|
1977 | 1977 | pts2read_CrossSpectra = 0 |
|
1978 | 1978 | |
|
1979 | 1979 | pts2read_DCchannels = 0 |
|
1980 | 1980 | |
|
1981 | 1981 | ext = ".pdata" |
|
1982 | 1982 | |
|
1983 | 1983 | optchar = "P" |
|
1984 | 1984 | |
|
1985 | 1985 | dataOut = None |
|
1986 | 1986 | |
|
1987 | 1987 | nRdChannels = None |
|
1988 | 1988 | |
|
1989 | 1989 | nRdPairs = None |
|
1990 | 1990 | |
|
1991 | 1991 | rdPairList = [] |
|
1992 | 1992 | |
|
1993 | 1993 | def __init__(self): |
|
1994 | 1994 | """ |
|
1995 | 1995 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
1996 | 1996 | |
|
1997 | 1997 | Inputs: |
|
1998 | 1998 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
1999 | 1999 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
2000 | 2000 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
2001 | 2001 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
2002 | 2002 | bloque de datos. |
|
2003 | 2003 | Si este parametro no es pasado se creara uno internamente. |
|
2004 | 2004 | |
|
2005 | 2005 | Affected: |
|
2006 | 2006 | self.dataOut |
|
2007 | 2007 | |
|
2008 | 2008 | Return : None |
|
2009 | 2009 | """ |
|
2010 | 2010 | |
|
2011 | 2011 | self.isConfig = False |
|
2012 | 2012 | |
|
2013 | 2013 | self.pts2read_SelfSpectra = 0 |
|
2014 | 2014 | |
|
2015 | 2015 | self.pts2read_CrossSpectra = 0 |
|
2016 | 2016 | |
|
2017 | 2017 | self.pts2read_DCchannels = 0 |
|
2018 | 2018 | |
|
2019 | 2019 | self.datablock = None |
|
2020 | 2020 | |
|
2021 | 2021 | self.utc = None |
|
2022 | 2022 | |
|
2023 | 2023 | self.ext = ".pdata" |
|
2024 | 2024 | |
|
2025 | 2025 | self.optchar = "P" |
|
2026 | 2026 | |
|
2027 | 2027 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
2028 | 2028 | |
|
2029 | 2029 | self.systemHeaderObj = SystemHeader() |
|
2030 | 2030 | |
|
2031 | 2031 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2032 | 2032 | |
|
2033 | 2033 | self.processingHeaderObj = ProcessingHeader() |
|
2034 | 2034 | |
|
2035 | 2035 | self.online = 0 |
|
2036 | 2036 | |
|
2037 | 2037 | self.fp = None |
|
2038 | 2038 | |
|
2039 | 2039 | self.idFile = None |
|
2040 | 2040 | |
|
2041 | 2041 | self.dtype = None |
|
2042 | 2042 | |
|
2043 | 2043 | self.fileSizeByHeader = None |
|
2044 | 2044 | |
|
2045 | 2045 | self.filenameList = [] |
|
2046 | 2046 | |
|
2047 | 2047 | self.filename = None |
|
2048 | 2048 | |
|
2049 | 2049 | self.fileSize = None |
|
2050 | 2050 | |
|
2051 | 2051 | self.firstHeaderSize = 0 |
|
2052 | 2052 | |
|
2053 | 2053 | self.basicHeaderSize = 24 |
|
2054 | 2054 | |
|
2055 | 2055 | self.pathList = [] |
|
2056 | 2056 | |
|
2057 | 2057 | self.lastUTTime = 0 |
|
2058 | 2058 | |
|
2059 | 2059 | self.maxTimeStep = 30 |
|
2060 | 2060 | |
|
2061 | 2061 | self.flagNoMoreFiles = 0 |
|
2062 | 2062 | |
|
2063 | 2063 | self.set = 0 |
|
2064 | 2064 | |
|
2065 | 2065 | self.path = None |
|
2066 | 2066 | |
|
2067 | 2067 | self.delay = 60 #seconds |
|
2068 | 2068 | |
|
2069 | 2069 | self.nTries = 3 #quantity tries |
|
2070 | 2070 | |
|
2071 | 2071 | self.nFiles = 3 #number of files for searching |
|
2072 | 2072 | |
|
2073 | 2073 | self.nReadBlocks = 0 |
|
2074 | 2074 | |
|
2075 | 2075 | self.flagIsNewFile = 1 |
|
2076 | 2076 | |
|
2077 | 2077 | self.__isFirstTimeOnline = 1 |
|
2078 | 2078 | |
|
2079 | 2079 | self.ippSeconds = 0 |
|
2080 | 2080 | |
|
2081 | 2081 | self.flagTimeBlock = 0 |
|
2082 | 2082 | |
|
2083 | 2083 | self.flagIsNewBlock = 0 |
|
2084 | 2084 | |
|
2085 | 2085 | self.nTotalBlocks = 0 |
|
2086 | 2086 | |
|
2087 | 2087 | self.blocksize = 0 |
|
2088 | 2088 | |
|
2089 | 2089 | self.dataOut = self.createObjByDefault() |
|
2090 | 2090 | |
|
2091 | 2091 | self.profileIndex = 1 #Always |
|
2092 | 2092 | |
|
2093 | 2093 | |
|
2094 | 2094 | def createObjByDefault(self): |
|
2095 | 2095 | |
|
2096 | 2096 | dataObj = Spectra() |
|
2097 | 2097 | |
|
2098 | 2098 | return dataObj |
|
2099 | 2099 | |
|
2100 | 2100 | def __hasNotDataInBuffer(self): |
|
2101 | 2101 | return 1 |
|
2102 | 2102 | |
|
2103 | 2103 | |
|
2104 | 2104 | def getBlockDimension(self): |
|
2105 | 2105 | """ |
|
2106 | 2106 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
2107 | 2107 | |
|
2108 | 2108 | Affected: |
|
2109 | 2109 | self.nRdChannels |
|
2110 | 2110 | self.nRdPairs |
|
2111 | 2111 | self.pts2read_SelfSpectra |
|
2112 | 2112 | self.pts2read_CrossSpectra |
|
2113 | 2113 | self.pts2read_DCchannels |
|
2114 | 2114 | self.blocksize |
|
2115 | 2115 | self.dataOut.nChannels |
|
2116 | 2116 | self.dataOut.nPairs |
|
2117 | 2117 | |
|
2118 | 2118 | Return: |
|
2119 | 2119 | None |
|
2120 | 2120 | """ |
|
2121 | 2121 | self.nRdChannels = 0 |
|
2122 | 2122 | self.nRdPairs = 0 |
|
2123 | 2123 | self.rdPairList = [] |
|
2124 | 2124 | |
|
2125 | 2125 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
2126 | 2126 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
2127 | 2127 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
2128 | 2128 | else: |
|
2129 | 2129 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
2130 | 2130 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
2131 | 2131 | |
|
2132 | 2132 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
2133 | 2133 | |
|
2134 | 2134 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
2135 | 2135 | self.blocksize = self.pts2read_SelfSpectra |
|
2136 | 2136 | |
|
2137 | 2137 | if self.processingHeaderObj.flag_cspc: |
|
2138 | 2138 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
2139 | 2139 | self.blocksize += self.pts2read_CrossSpectra |
|
2140 | 2140 | |
|
2141 | 2141 | if self.processingHeaderObj.flag_dc: |
|
2142 | 2142 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
2143 | 2143 | self.blocksize += self.pts2read_DCchannels |
|
2144 | 2144 | |
|
2145 | 2145 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
2146 | 2146 | |
|
2147 | 2147 | |
|
2148 | 2148 | def readBlock(self): |
|
2149 | 2149 | """ |
|
2150 | 2150 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
2151 | 2151 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
2152 | 2152 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
2153 | 2153 | es seteado a 0 |
|
2154 | 2154 | |
|
2155 | 2155 | Return: None |
|
2156 | 2156 | |
|
2157 | 2157 | Variables afectadas: |
|
2158 | 2158 | |
|
2159 | 2159 | self.flagIsNewFile |
|
2160 | 2160 | self.flagIsNewBlock |
|
2161 | 2161 | self.nTotalBlocks |
|
2162 | 2162 | self.data_spc |
|
2163 | 2163 | self.data_cspc |
|
2164 | 2164 | self.data_dc |
|
2165 | 2165 | |
|
2166 | 2166 | Exceptions: |
|
2167 | 2167 | Si un bloque leido no es un bloque valido |
|
2168 | 2168 | """ |
|
2169 | 2169 | blockOk_flag = False |
|
2170 | 2170 | fpointer = self.fp.tell() |
|
2171 | 2171 | |
|
2172 | 2172 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
2173 | 2173 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
2174 | 2174 | |
|
2175 | 2175 | if self.processingHeaderObj.flag_cspc: |
|
2176 | 2176 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
2177 | 2177 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
2178 | 2178 | |
|
2179 | 2179 | if self.processingHeaderObj.flag_dc: |
|
2180 | 2180 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
2181 | 2181 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
2182 | 2182 | |
|
2183 | 2183 | |
|
2184 | 2184 | if not(self.processingHeaderObj.shif_fft): |
|
2185 | 2185 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2186 | 2186 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
2187 | 2187 | spc = numpy.roll( spc, shift , axis=2 ) |
|
2188 | 2188 | |
|
2189 | 2189 | if self.processingHeaderObj.flag_cspc: |
|
2190 | 2190 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2191 | 2191 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
2192 | 2192 | |
|
2193 | 2193 | # self.processingHeaderObj.shif_fft = True |
|
2194 | 2194 | |
|
2195 | 2195 | spc = numpy.transpose( spc, (0,2,1) ) |
|
2196 | 2196 | self.data_spc = spc |
|
2197 | 2197 | |
|
2198 | 2198 | if self.processingHeaderObj.flag_cspc: |
|
2199 | 2199 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
2200 | 2200 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
2201 | 2201 | else: |
|
2202 | 2202 | self.data_cspc = None |
|
2203 | 2203 | |
|
2204 | 2204 | if self.processingHeaderObj.flag_dc: |
|
2205 | 2205 | self.data_dc = dc['real'] + dc['imag']*1j |
|
2206 | 2206 | else: |
|
2207 | 2207 | self.data_dc = None |
|
2208 | 2208 | |
|
2209 | 2209 | self.flagIsNewFile = 0 |
|
2210 | 2210 | self.flagIsNewBlock = 1 |
|
2211 | 2211 | |
|
2212 | 2212 | self.nTotalBlocks += 1 |
|
2213 | 2213 | self.nReadBlocks += 1 |
|
2214 | 2214 | |
|
2215 | 2215 | return 1 |
|
2216 | 2216 | |
|
2217 | 2217 | def getFirstHeader(self): |
|
2218 | 2218 | |
|
2219 | 2219 | self.dataOut.dtype = self.dtype |
|
2220 | 2220 | |
|
2221 | 2221 | self.dataOut.nPairs = self.nRdPairs |
|
2222 | 2222 | |
|
2223 | 2223 | self.dataOut.pairsList = self.rdPairList |
|
2224 | 2224 | |
|
2225 | 2225 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
2226 | 2226 | |
|
2227 | 2227 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
2228 | 2228 | |
|
2229 | 2229 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
2230 | 2230 | |
|
2231 | 2231 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
2232 | 2232 | |
|
2233 | 2233 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
2234 | 2234 | |
|
2235 | 2235 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
2236 | 2236 | |
|
2237 | 2237 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
2238 | 2238 | |
|
2239 | 2239 | self.dataOut.ippSeconds = self.ippSeconds |
|
2240 | 2240 | |
|
2241 | 2241 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints |
|
2242 | 2242 | |
|
2243 | 2243 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
2244 | 2244 | |
|
2245 | 2245 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
2246 | 2246 | |
|
2247 | 2247 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
2248 | 2248 | |
|
2249 | 2249 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
2250 | 2250 | |
|
2251 | 2251 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
2252 | 2252 | |
|
2253 | 2253 | if self.radarControllerHeaderObj.code != None: |
|
2254 | 2254 | |
|
2255 | 2255 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
2256 | 2256 | |
|
2257 | 2257 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
2258 | 2258 | |
|
2259 | 2259 | self.dataOut.code = self.radarControllerHeaderObj.code |
|
2260 | 2260 | |
|
2261 | 2261 | self.dataOut.flagDecodeData = True |
|
2262 | 2262 | |
|
2263 | 2263 | def getData(self): |
|
2264 | 2264 | """ |
|
2265 | 2265 | Copia el buffer de lectura a la clase "Spectra", |
|
2266 | 2266 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
2267 | 2267 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
2268 | 2268 | |
|
2269 | 2269 | Return: |
|
2270 | 2270 | 0 : Si no hay mas archivos disponibles |
|
2271 | 2271 | 1 : Si hizo una buena copia del buffer |
|
2272 | 2272 | |
|
2273 | 2273 | Affected: |
|
2274 | 2274 | self.dataOut |
|
2275 | 2275 | |
|
2276 | 2276 | self.flagTimeBlock |
|
2277 | 2277 | self.flagIsNewBlock |
|
2278 | 2278 | """ |
|
2279 | 2279 | |
|
2280 | 2280 | if self.flagNoMoreFiles: |
|
2281 | 2281 | self.dataOut.flagNoData = True |
|
2282 | 2282 | print 'Process finished' |
|
2283 | 2283 | return 0 |
|
2284 | 2284 | |
|
2285 | 2285 | self.flagTimeBlock = 0 |
|
2286 | 2286 | self.flagIsNewBlock = 0 |
|
2287 | 2287 | |
|
2288 | 2288 | if self.__hasNotDataInBuffer(): |
|
2289 | 2289 | |
|
2290 | 2290 | if not( self.readNextBlock() ): |
|
2291 | 2291 | self.dataOut.flagNoData = True |
|
2292 | 2292 | return 0 |
|
2293 | 2293 | |
|
2294 | 2294 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
2295 | 2295 | |
|
2296 | 2296 | if self.data_dc == None: |
|
2297 | 2297 | self.dataOut.flagNoData = True |
|
2298 | 2298 | return 0 |
|
2299 | 2299 | |
|
2300 | 2300 | self.getBasicHeader() |
|
2301 | 2301 | |
|
2302 | 2302 | self.getFirstHeader() |
|
2303 | 2303 | |
|
2304 | 2304 | self.dataOut.data_spc = self.data_spc |
|
2305 | 2305 | |
|
2306 | 2306 | self.dataOut.data_cspc = self.data_cspc |
|
2307 | 2307 | |
|
2308 | 2308 | self.dataOut.data_dc = self.data_dc |
|
2309 | 2309 | |
|
2310 | 2310 | self.dataOut.flagNoData = False |
|
2311 | 2311 | |
|
2312 | 2312 | self.dataOut.realtime = self.online |
|
2313 | 2313 | |
|
2314 | 2314 | return self.dataOut.data_spc |
|
2315 | 2315 | |
|
2316 | 2316 | |
|
2317 | 2317 | class SpectraWriter(JRODataWriter): |
|
2318 | 2318 | |
|
2319 | 2319 | """ |
|
2320 | 2320 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
2321 | 2321 | de los datos siempre se realiza por bloques. |
|
2322 | 2322 | """ |
|
2323 | 2323 | |
|
2324 | 2324 | ext = ".pdata" |
|
2325 | 2325 | |
|
2326 | 2326 | optchar = "P" |
|
2327 | 2327 | |
|
2328 | 2328 | shape_spc_Buffer = None |
|
2329 | 2329 | |
|
2330 | 2330 | shape_cspc_Buffer = None |
|
2331 | 2331 | |
|
2332 | 2332 | shape_dc_Buffer = None |
|
2333 | 2333 | |
|
2334 | 2334 | data_spc = None |
|
2335 | 2335 | |
|
2336 | 2336 | data_cspc = None |
|
2337 | 2337 | |
|
2338 | 2338 | data_dc = None |
|
2339 | 2339 | |
|
2340 | 2340 | # dataOut = None |
|
2341 | 2341 | |
|
2342 | 2342 | def __init__(self): |
|
2343 | 2343 | """ |
|
2344 | 2344 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
2345 | 2345 | |
|
2346 | 2346 | Affected: |
|
2347 | 2347 | self.dataOut |
|
2348 | 2348 | self.basicHeaderObj |
|
2349 | 2349 | self.systemHeaderObj |
|
2350 | 2350 | self.radarControllerHeaderObj |
|
2351 | 2351 | self.processingHeaderObj |
|
2352 | 2352 | |
|
2353 | 2353 | Return: None |
|
2354 | 2354 | """ |
|
2355 | 2355 | |
|
2356 | 2356 | self.isConfig = False |
|
2357 | 2357 | |
|
2358 | 2358 | self.nTotalBlocks = 0 |
|
2359 | 2359 | |
|
2360 | 2360 | self.data_spc = None |
|
2361 | 2361 | |
|
2362 | 2362 | self.data_cspc = None |
|
2363 | 2363 | |
|
2364 | 2364 | self.data_dc = None |
|
2365 | 2365 | |
|
2366 | 2366 | self.fp = None |
|
2367 | 2367 | |
|
2368 | 2368 | self.flagIsNewFile = 1 |
|
2369 | 2369 | |
|
2370 | 2370 | self.nTotalBlocks = 0 |
|
2371 | 2371 | |
|
2372 | 2372 | self.flagIsNewBlock = 0 |
|
2373 | 2373 | |
|
2374 | 2374 | self.setFile = None |
|
2375 | 2375 | |
|
2376 | 2376 | self.dtype = None |
|
2377 | 2377 | |
|
2378 | 2378 | self.path = None |
|
2379 | 2379 | |
|
2380 | 2380 | self.noMoreFiles = 0 |
|
2381 | 2381 | |
|
2382 | 2382 | self.filename = None |
|
2383 | 2383 | |
|
2384 | 2384 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
2385 | 2385 | |
|
2386 | 2386 | self.systemHeaderObj = SystemHeader() |
|
2387 | 2387 | |
|
2388 | 2388 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2389 | 2389 | |
|
2390 | 2390 | self.processingHeaderObj = ProcessingHeader() |
|
2391 | 2391 | |
|
2392 | 2392 | |
|
2393 | 2393 | def hasAllDataInBuffer(self): |
|
2394 | 2394 | return 1 |
|
2395 | 2395 | |
|
2396 | 2396 | |
|
2397 | 2397 | def setBlockDimension(self): |
|
2398 | 2398 | """ |
|
2399 | 2399 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
2400 | 2400 | |
|
2401 | 2401 | Affected: |
|
2402 | 2402 | self.shape_spc_Buffer |
|
2403 | 2403 | self.shape_cspc_Buffer |
|
2404 | 2404 | self.shape_dc_Buffer |
|
2405 | 2405 | |
|
2406 | 2406 | Return: None |
|
2407 | 2407 | """ |
|
2408 | 2408 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
2409 | 2409 | self.processingHeaderObj.nHeights, |
|
2410 | 2410 | self.processingHeaderObj.profilesPerBlock) |
|
2411 | 2411 | |
|
2412 | 2412 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
2413 | 2413 | self.processingHeaderObj.nHeights, |
|
2414 | 2414 | self.processingHeaderObj.profilesPerBlock) |
|
2415 | 2415 | |
|
2416 | 2416 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
2417 | 2417 | self.processingHeaderObj.nHeights) |
|
2418 | 2418 | |
|
2419 | 2419 | |
|
2420 | 2420 | def writeBlock(self): |
|
2421 | 2421 | """ |
|
2422 | 2422 | Escribe el buffer en el file designado |
|
2423 | 2423 | |
|
2424 | 2424 | Affected: |
|
2425 | 2425 | self.data_spc |
|
2426 | 2426 | self.data_cspc |
|
2427 | 2427 | self.data_dc |
|
2428 | 2428 | self.flagIsNewFile |
|
2429 | 2429 | self.flagIsNewBlock |
|
2430 | 2430 | self.nTotalBlocks |
|
2431 | 2431 | self.nWriteBlocks |
|
2432 | 2432 | |
|
2433 | 2433 | Return: None |
|
2434 | 2434 | """ |
|
2435 | 2435 | |
|
2436 | 2436 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
2437 | 2437 | if not( self.processingHeaderObj.shif_fft ): |
|
2438 | 2438 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2439 | 2439 | data = spc.reshape((-1)) |
|
2440 | 2440 | data = data.astype(self.dtype[0]) |
|
2441 | 2441 | data.tofile(self.fp) |
|
2442 | 2442 | |
|
2443 | 2443 | if self.data_cspc != None: |
|
2444 | 2444 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
2445 | 2445 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
2446 | 2446 | if not( self.processingHeaderObj.shif_fft ): |
|
2447 | 2447 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2448 | 2448 | data['real'] = cspc.real |
|
2449 | 2449 | data['imag'] = cspc.imag |
|
2450 | 2450 | data = data.reshape((-1)) |
|
2451 | 2451 | data.tofile(self.fp) |
|
2452 | 2452 | |
|
2453 | 2453 | if self.data_dc != None: |
|
2454 | 2454 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
2455 | 2455 | dc = self.data_dc |
|
2456 | 2456 | data['real'] = dc.real |
|
2457 | 2457 | data['imag'] = dc.imag |
|
2458 | 2458 | data = data.reshape((-1)) |
|
2459 | 2459 | data.tofile(self.fp) |
|
2460 | 2460 | |
|
2461 | 2461 | self.data_spc.fill(0) |
|
2462 | 2462 | |
|
2463 | 2463 | if self.data_dc != None: |
|
2464 | 2464 | self.data_dc.fill(0) |
|
2465 | 2465 | |
|
2466 | 2466 | if self.data_cspc != None: |
|
2467 | 2467 | self.data_cspc.fill(0) |
|
2468 | 2468 | |
|
2469 | 2469 | self.flagIsNewFile = 0 |
|
2470 | 2470 | self.flagIsNewBlock = 1 |
|
2471 | 2471 | self.nTotalBlocks += 1 |
|
2472 | 2472 | self.nWriteBlocks += 1 |
|
2473 | 2473 | self.blockIndex += 1 |
|
2474 | 2474 | |
|
2475 | 2475 | |
|
2476 | 2476 | def putData(self): |
|
2477 | 2477 | """ |
|
2478 | 2478 | Setea un bloque de datos y luego los escribe en un file |
|
2479 | 2479 | |
|
2480 | 2480 | Affected: |
|
2481 | 2481 | self.data_spc |
|
2482 | 2482 | self.data_cspc |
|
2483 | 2483 | self.data_dc |
|
2484 | 2484 | |
|
2485 | 2485 | Return: |
|
2486 | 2486 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
2487 | 2487 | 1 : Si se escribio la data de un bloque en un file |
|
2488 | 2488 | """ |
|
2489 | 2489 | |
|
2490 | 2490 | if self.dataOut.flagNoData: |
|
2491 | 2491 | return 0 |
|
2492 | 2492 | |
|
2493 | 2493 | self.flagIsNewBlock = 0 |
|
2494 | 2494 | |
|
2495 | 2495 | if self.dataOut.flagTimeBlock: |
|
2496 | 2496 | self.data_spc.fill(0) |
|
2497 | 2497 | self.data_cspc.fill(0) |
|
2498 | 2498 | self.data_dc.fill(0) |
|
2499 | 2499 | self.setNextFile() |
|
2500 | 2500 | |
|
2501 | 2501 | if self.flagIsNewFile == 0: |
|
2502 | 2502 | self.setBasicHeader() |
|
2503 | 2503 | |
|
2504 | 2504 | self.data_spc = self.dataOut.data_spc.copy() |
|
2505 | 2505 | if self.dataOut.data_cspc != None: |
|
2506 | 2506 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
2507 | 2507 | self.data_dc = self.dataOut.data_dc.copy() |
|
2508 | 2508 | |
|
2509 | 2509 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
2510 | 2510 | if self.hasAllDataInBuffer(): |
|
2511 | 2511 | # self.setFirstHeader() |
|
2512 | 2512 | self.writeNextBlock() |
|
2513 | 2513 | |
|
2514 | 2514 | return 1 |
|
2515 | 2515 | |
|
2516 | 2516 | |
|
2517 | 2517 | def __getProcessFlags(self): |
|
2518 | 2518 | |
|
2519 | 2519 | processFlags = 0 |
|
2520 | 2520 | |
|
2521 | 2521 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2522 | 2522 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2523 | 2523 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2524 | 2524 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2525 | 2525 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2526 | 2526 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2527 | 2527 | |
|
2528 | 2528 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2529 | 2529 | |
|
2530 | 2530 | |
|
2531 | 2531 | |
|
2532 | 2532 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
2533 | 2533 | PROCFLAG.DATATYPE_SHORT, |
|
2534 | 2534 | PROCFLAG.DATATYPE_LONG, |
|
2535 | 2535 | PROCFLAG.DATATYPE_INT64, |
|
2536 | 2536 | PROCFLAG.DATATYPE_FLOAT, |
|
2537 | 2537 | PROCFLAG.DATATYPE_DOUBLE] |
|
2538 | 2538 | |
|
2539 | 2539 | |
|
2540 | 2540 | for index in range(len(dtypeList)): |
|
2541 | 2541 | if self.dataOut.dtype == dtypeList[index]: |
|
2542 | 2542 | dtypeValue = datatypeValueList[index] |
|
2543 | 2543 | break |
|
2544 | 2544 | |
|
2545 | 2545 | processFlags += dtypeValue |
|
2546 | 2546 | |
|
2547 | 2547 | if self.dataOut.flagDecodeData: |
|
2548 | 2548 | processFlags += PROCFLAG.DECODE_DATA |
|
2549 | 2549 | |
|
2550 | 2550 | if self.dataOut.flagDeflipData: |
|
2551 | 2551 | processFlags += PROCFLAG.DEFLIP_DATA |
|
2552 | 2552 | |
|
2553 | 2553 | if self.dataOut.code != None: |
|
2554 | 2554 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
2555 | 2555 | |
|
2556 | 2556 | if self.dataOut.nIncohInt > 1: |
|
2557 | 2557 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
2558 | 2558 | |
|
2559 | 2559 | if self.dataOut.data_dc != None: |
|
2560 | 2560 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
2561 | 2561 | |
|
2562 | 2562 | return processFlags |
|
2563 | 2563 | |
|
2564 | 2564 | |
|
2565 | 2565 | def __getBlockSize(self): |
|
2566 | 2566 | ''' |
|
2567 | 2567 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
2568 | 2568 | ''' |
|
2569 | 2569 | |
|
2570 | 2570 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2571 | 2571 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2572 | 2572 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2573 | 2573 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2574 | 2574 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2575 | 2575 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2576 | 2576 | |
|
2577 | 2577 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2578 | 2578 | datatypeValueList = [1,2,4,8,4,8] |
|
2579 | 2579 | for index in range(len(dtypeList)): |
|
2580 | 2580 | if self.dataOut.dtype == dtypeList[index]: |
|
2581 | 2581 | datatypeValue = datatypeValueList[index] |
|
2582 | 2582 | break |
|
2583 | 2583 | |
|
2584 | 2584 | |
|
2585 | 2585 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
2586 | 2586 | |
|
2587 | 2587 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
2588 | 2588 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
2589 | 2589 | |
|
2590 | 2590 | if self.dataOut.data_cspc != None: |
|
2591 | 2591 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
2592 | 2592 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
2593 | 2593 | |
|
2594 | 2594 | if self.dataOut.data_dc != None: |
|
2595 | 2595 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
2596 | 2596 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
2597 | 2597 | |
|
2598 | 2598 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
2599 | 2599 | |
|
2600 | 2600 | return blocksize |
|
2601 | 2601 | |
|
2602 | 2602 | def setFirstHeader(self): |
|
2603 | 2603 | |
|
2604 | 2604 | """ |
|
2605 | 2605 | Obtiene una copia del First Header |
|
2606 | 2606 | |
|
2607 | 2607 | Affected: |
|
2608 | 2608 | self.systemHeaderObj |
|
2609 | 2609 | self.radarControllerHeaderObj |
|
2610 | 2610 | self.dtype |
|
2611 | 2611 | |
|
2612 | 2612 | Return: |
|
2613 | 2613 | None |
|
2614 | 2614 | """ |
|
2615 | 2615 | |
|
2616 | 2616 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
2617 | 2617 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
2618 | 2618 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
2619 | 2619 | old_code_size = self.dataOut.radarControllerHeaderObj.code_size |
|
2620 | 2620 | new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4 |
|
2621 | 2621 | self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size |
|
2622 | 2622 | |
|
2623 | 2623 | self.setBasicHeader() |
|
2624 | 2624 | |
|
2625 | 2625 | processingHeaderSize = 40 # bytes |
|
2626 | 2626 | self.processingHeaderObj.dtype = 1 # Spectra |
|
2627 | 2627 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
2628 | 2628 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
2629 | 2629 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
2630 | 2630 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
2631 | 2631 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
2632 | 2632 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
2633 | 2633 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
2634 | 2634 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
2635 | 2635 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT |
|
2636 | 2636 | |
|
2637 | 2637 | if self.processingHeaderObj.totalSpectra > 0: |
|
2638 | 2638 | channelList = [] |
|
2639 | 2639 | for channel in range(self.dataOut.nChannels): |
|
2640 | 2640 | channelList.append(channel) |
|
2641 | 2641 | channelList.append(channel) |
|
2642 | 2642 | |
|
2643 | 2643 | pairsList = [] |
|
2644 | 2644 | if self.dataOut.nPairs > 0: |
|
2645 | 2645 | for pair in self.dataOut.pairsList: |
|
2646 | 2646 | pairsList.append(pair[0]) |
|
2647 | 2647 | pairsList.append(pair[1]) |
|
2648 | 2648 | |
|
2649 | 2649 | spectraComb = channelList + pairsList |
|
2650 | 2650 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
2651 | 2651 | self.processingHeaderObj.spectraComb = spectraComb |
|
2652 | 2652 | sizeOfSpcComb = len(spectraComb) |
|
2653 | 2653 | processingHeaderSize += sizeOfSpcComb |
|
2654 | 2654 | |
|
2655 | 2655 | # The processing header should not have information about code |
|
2656 | 2656 | # if self.dataOut.code != None: |
|
2657 | 2657 | # self.processingHeaderObj.code = self.dataOut.code |
|
2658 | 2658 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
2659 | 2659 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
2660 | 2660 | # nCodeSize = 4 # bytes |
|
2661 | 2661 | # nBaudSize = 4 # bytes |
|
2662 | 2662 | # codeSize = 4 # bytes |
|
2663 | 2663 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
2664 | 2664 | # processingHeaderSize += sizeOfCode |
|
2665 | 2665 | |
|
2666 | 2666 | if self.processingHeaderObj.nWindows != 0: |
|
2667 | 2667 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
2668 | 2668 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2669 | 2669 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
2670 | 2670 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
2671 | 2671 | sizeOfFirstHeight = 4 |
|
2672 | 2672 | sizeOfdeltaHeight = 4 |
|
2673 | 2673 | sizeOfnHeights = 4 |
|
2674 | 2674 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
2675 | 2675 | processingHeaderSize += sizeOfWindows |
|
2676 | 2676 | |
|
2677 | 2677 | self.processingHeaderObj.size = processingHeaderSize |
|
2678 | 2678 | |
|
2679 | 2679 | class SpectraHeisWriter(Operation): |
|
2680 | 2680 | # set = None |
|
2681 | 2681 | setFile = None |
|
2682 | 2682 | idblock = None |
|
2683 | 2683 | doypath = None |
|
2684 | 2684 | subfolder = None |
|
2685 | 2685 | |
|
2686 | 2686 | def __init__(self): |
|
2687 | 2687 | self.wrObj = FITS() |
|
2688 | 2688 | # self.dataOut = dataOut |
|
2689 | 2689 | self.nTotalBlocks=0 |
|
2690 | 2690 | # self.set = None |
|
2691 | 2691 | self.setFile = None |
|
2692 | 2692 | self.idblock = 0 |
|
2693 | 2693 | self.wrpath = None |
|
2694 | 2694 | self.doypath = None |
|
2695 | 2695 | self.subfolder = None |
|
2696 | 2696 | self.isConfig = False |
|
2697 | 2697 | |
|
2698 | 2698 | def isNumber(str): |
|
2699 | 2699 | """ |
|
2700 | 2700 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
2701 | 2701 | |
|
2702 | 2702 | Excepciones: |
|
2703 | 2703 | Si un determinado string no puede ser convertido a numero |
|
2704 | 2704 | Input: |
|
2705 | 2705 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
2706 | 2706 | |
|
2707 | 2707 | Return: |
|
2708 | 2708 | True : si el string es uno numerico |
|
2709 | 2709 | False : no es un string numerico |
|
2710 | 2710 | """ |
|
2711 | 2711 | try: |
|
2712 | 2712 | float( str ) |
|
2713 | 2713 | return True |
|
2714 | 2714 | except: |
|
2715 | 2715 | return False |
|
2716 | 2716 | |
|
2717 | 2717 | def setup(self, dataOut, wrpath): |
|
2718 | 2718 | |
|
2719 | 2719 | if not(os.path.exists(wrpath)): |
|
2720 | 2720 | os.mkdir(wrpath) |
|
2721 | 2721 | |
|
2722 | 2722 | self.wrpath = wrpath |
|
2723 | 2723 | # self.setFile = 0 |
|
2724 | 2724 | self.dataOut = dataOut |
|
2725 | 2725 | |
|
2726 | 2726 | def putData(self): |
|
2727 | 2727 | name= time.localtime( self.dataOut.utctime) |
|
2728 | 2728 | ext=".fits" |
|
2729 | 2729 | |
|
2730 | 2730 | if self.doypath == None: |
|
2731 | 2731 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) |
|
2732 | 2732 | self.doypath = os.path.join( self.wrpath, self.subfolder ) |
|
2733 | 2733 | os.mkdir(self.doypath) |
|
2734 | 2734 | |
|
2735 | 2735 | if self.setFile == None: |
|
2736 | 2736 | # self.set = self.dataOut.set |
|
2737 | 2737 | self.setFile = 0 |
|
2738 | 2738 | # if self.set != self.dataOut.set: |
|
2739 | 2739 | ## self.set = self.dataOut.set |
|
2740 | 2740 | # self.setFile = 0 |
|
2741 | 2741 | |
|
2742 | 2742 | #make the filename |
|
2743 | 2743 | file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
2744 | 2744 | |
|
2745 | 2745 | filename = os.path.join(self.wrpath,self.subfolder, file) |
|
2746 | 2746 | |
|
2747 | 2747 | idblock = numpy.array([self.idblock],dtype="int64") |
|
2748 | 2748 | header=self.wrObj.cFImage(idblock=idblock, |
|
2749 | 2749 | year=time.gmtime(self.dataOut.utctime).tm_year, |
|
2750 | 2750 | month=time.gmtime(self.dataOut.utctime).tm_mon, |
|
2751 | 2751 | day=time.gmtime(self.dataOut.utctime).tm_mday, |
|
2752 | 2752 | hour=time.gmtime(self.dataOut.utctime).tm_hour, |
|
2753 | 2753 | minute=time.gmtime(self.dataOut.utctime).tm_min, |
|
2754 | 2754 | second=time.gmtime(self.dataOut.utctime).tm_sec) |
|
2755 | 2755 | |
|
2756 | 2756 | c=3E8 |
|
2757 | 2757 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2758 | 2758 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000)) |
|
2759 | 2759 | |
|
2760 | 2760 | colList = [] |
|
2761 | 2761 | |
|
2762 | 2762 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
2763 | 2763 | |
|
2764 | 2764 | colList.append(colFreq) |
|
2765 | 2765 | |
|
2766 | 2766 | nchannel=self.dataOut.nChannels |
|
2767 | 2767 | |
|
2768 | 2768 | for i in range(nchannel): |
|
2769 | 2769 | col = self.wrObj.writeData(name="PCh"+str(i+1), |
|
2770 | 2770 | format=str(self.dataOut.nFFTPoints)+'E', |
|
2771 | 2771 | data=10*numpy.log10(self.dataOut.data_spc[i,:])) |
|
2772 | 2772 | |
|
2773 | 2773 | colList.append(col) |
|
2774 | 2774 | |
|
2775 | 2775 | data=self.wrObj.Ctable(colList=colList) |
|
2776 | 2776 | |
|
2777 | 2777 | self.wrObj.CFile(header,data) |
|
2778 | 2778 | |
|
2779 | 2779 | self.wrObj.wFile(filename) |
|
2780 | 2780 | |
|
2781 | 2781 | #update the setFile |
|
2782 | 2782 | self.setFile += 1 |
|
2783 | 2783 | self.idblock += 1 |
|
2784 | 2784 | |
|
2785 | 2785 | return 1 |
|
2786 | 2786 | |
|
2787 | 2787 | def run(self, dataOut, **kwargs): |
|
2788 | 2788 | |
|
2789 | 2789 | if not(self.isConfig): |
|
2790 | 2790 | |
|
2791 | 2791 | self.setup(dataOut, **kwargs) |
|
2792 | 2792 | self.isConfig = True |
|
2793 | 2793 | |
|
2794 | 2794 | self.putData() |
|
2795 | 2795 | |
|
2796 | 2796 | |
|
2797 | 2797 | |
|
2798 | 2798 | class ParameterConf: |
|
2799 | 2799 | ELEMENTNAME = 'Parameter' |
|
2800 | 2800 | def __init__(self): |
|
2801 | 2801 | self.name = '' |
|
2802 | 2802 | self.value = '' |
|
2803 | 2803 | |
|
2804 | 2804 | def readXml(self, parmElement): |
|
2805 | 2805 | self.name = parmElement.get('name') |
|
2806 | 2806 | self.value = parmElement.get('value') |
|
2807 | 2807 | |
|
2808 | 2808 | def getElementName(self): |
|
2809 | 2809 | return self.ELEMENTNAME |
|
2810 | 2810 | |
|
2811 | 2811 | class Metadata: |
|
2812 | 2812 | |
|
2813 | 2813 | def __init__(self, filename): |
|
2814 | 2814 | self.parmConfObjList = [] |
|
2815 | 2815 | self.readXml(filename) |
|
2816 | 2816 | |
|
2817 | 2817 | def readXml(self, filename): |
|
2818 | 2818 | self.projectElement = None |
|
2819 | 2819 | self.procUnitConfObjDict = {} |
|
2820 | 2820 | self.projectElement = ElementTree().parse(filename) |
|
2821 | 2821 | self.project = self.projectElement.tag |
|
2822 | 2822 | |
|
2823 | 2823 | parmElementList = self.projectElement.getiterator(ParameterConf().getElementName()) |
|
2824 | 2824 | |
|
2825 | 2825 | for parmElement in parmElementList: |
|
2826 | 2826 | parmConfObj = ParameterConf() |
|
2827 | 2827 | parmConfObj.readXml(parmElement) |
|
2828 | 2828 | self.parmConfObjList.append(parmConfObj) |
|
2829 | 2829 | |
|
2830 | 2830 | class FitsWriter(Operation): |
|
2831 | 2831 | |
|
2832 | 2832 | def __init__(self): |
|
2833 | 2833 | self.isConfig = False |
|
2834 | 2834 | self.dataBlocksPerFile = None |
|
2835 | 2835 | self.blockIndex = 0 |
|
2836 | 2836 | self.flagIsNewFile = 1 |
|
2837 | 2837 | self.fitsObj = None |
|
2838 | 2838 | self.optchar = 'P' |
|
2839 | 2839 | self.ext = '.fits' |
|
2840 | 2840 | self.setFile = 0 |
|
2841 | 2841 | |
|
2842 | 2842 | def setFitsHeader(self, dataOut, metadatafile): |
|
2843 | 2843 | |
|
2844 | 2844 | header_data = pyfits.PrimaryHDU() |
|
2845 | 2845 | |
|
2846 | 2846 | metadata4fits = Metadata(metadatafile) |
|
2847 | 2847 | for parameter in metadata4fits.parmConfObjList: |
|
2848 | 2848 | parm_name = parameter.name |
|
2849 | 2849 | parm_value = parameter.value |
|
2850 | 2850 | |
|
2851 | 2851 | # if parm_value == 'fromdatadatetime': |
|
2852 | 2852 | # value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) |
|
2853 | 2853 | # elif parm_value == 'fromdataheights': |
|
2854 | 2854 | # value = dataOut.nHeights |
|
2855 | 2855 | # elif parm_value == 'fromdatachannel': |
|
2856 | 2856 | # value = dataOut.nChannels |
|
2857 | 2857 | # elif parm_value == 'fromdatasamples': |
|
2858 | 2858 | # value = dataOut.nFFTPoints |
|
2859 | 2859 | # else: |
|
2860 | 2860 | # value = parm_value |
|
2861 | 2861 | |
|
2862 | 2862 | header_data.header[parm_name] = parm_value |
|
2863 | 2863 | |
|
2864 | 2864 | |
|
2865 | 2865 | header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) |
|
2866 | 2866 | header_data.header['CHANNELLIST'] = str(dataOut.channelList) |
|
2867 | 2867 | header_data.header['NCHANNELS'] = dataOut.nChannels |
|
2868 | 2868 | #header_data.header['HEIGHTS'] = dataOut.heightList |
|
2869 | 2869 | header_data.header['NHEIGHTS'] = dataOut.nHeights |
|
2870 | 2870 | |
|
2871 | 2871 | header_data.header['IPPSECONDS'] = dataOut.ippSeconds |
|
2872 | 2872 | header_data.header['NCOHINT'] = dataOut.nCohInt |
|
2873 | 2873 | header_data.header['NINCOHINT'] = dataOut.nIncohInt |
|
2874 | 2874 | header_data.header['TIMEZONE'] = dataOut.timeZone |
|
2875 | 2875 | header_data.header['NBLOCK'] = self.blockIndex |
|
2876 | 2876 | |
|
2877 | 2877 | header_data.writeto(self.filename) |
|
2878 | 2878 | |
|
2879 | 2879 | self.addExtension(dataOut.heightList,'HEIGHTLIST') |
|
2880 | 2880 | |
|
2881 | 2881 | |
|
2882 | 2882 | def setup(self, dataOut, path, dataBlocksPerFile, metadatafile): |
|
2883 | 2883 | |
|
2884 | 2884 | self.path = path |
|
2885 | 2885 | self.dataOut = dataOut |
|
2886 | 2886 | self.metadatafile = metadatafile |
|
2887 | 2887 | self.dataBlocksPerFile = dataBlocksPerFile |
|
2888 | 2888 | |
|
2889 | 2889 | def open(self): |
|
2890 | 2890 | self.fitsObj = pyfits.open(self.filename, mode='update') |
|
2891 | 2891 | |
|
2892 | 2892 | |
|
2893 | 2893 | def addExtension(self, data, tagname): |
|
2894 | 2894 | self.open() |
|
2895 | 2895 | extension = pyfits.ImageHDU(data=data, name=tagname) |
|
2896 | 2896 | #extension.header['TAG'] = tagname |
|
2897 | 2897 | self.fitsObj.append(extension) |
|
2898 | 2898 | self.write() |
|
2899 | 2899 | |
|
2900 | 2900 | def addData(self, data): |
|
2901 | 2901 | self.open() |
|
2902 | 2902 | extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE']) |
|
2903 | 2903 | extension.header['UTCTIME'] = self.dataOut.utctime |
|
2904 | 2904 | self.fitsObj.append(extension) |
|
2905 | 2905 | self.blockIndex += 1 |
|
2906 | 2906 | self.fitsObj[0].header['NBLOCK'] = self.blockIndex |
|
2907 | 2907 | |
|
2908 | 2908 | self.write() |
|
2909 | 2909 | |
|
2910 | 2910 | def write(self): |
|
2911 | 2911 | |
|
2912 | 2912 | self.fitsObj.flush(verbose=True) |
|
2913 | 2913 | self.fitsObj.close() |
|
2914 | 2914 | |
|
2915 | 2915 | |
|
2916 | 2916 | def setNextFile(self): |
|
2917 | 2917 | |
|
2918 | 2918 | ext = self.ext |
|
2919 | 2919 | path = self.path |
|
2920 | 2920 | |
|
2921 | 2921 | timeTuple = time.localtime( self.dataOut.utctime) |
|
2922 | 2922 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
2923 | 2923 | |
|
2924 | 2924 | fullpath = os.path.join( path, subfolder ) |
|
2925 | 2925 | if not( os.path.exists(fullpath) ): |
|
2926 | 2926 | os.mkdir(fullpath) |
|
2927 | 2927 | self.setFile = -1 #inicializo mi contador de seteo |
|
2928 | 2928 | else: |
|
2929 | 2929 | filesList = os.listdir( fullpath ) |
|
2930 | 2930 | if len( filesList ) > 0: |
|
2931 | 2931 | filesList = sorted( filesList, key=str.lower ) |
|
2932 | 2932 | filen = filesList[-1] |
|
2933 | 2933 | |
|
2934 | 2934 | if isNumber( filen[8:11] ): |
|
2935 | 2935 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
2936 | 2936 | else: |
|
2937 | 2937 | self.setFile = -1 |
|
2938 | 2938 | else: |
|
2939 | 2939 | self.setFile = -1 #inicializo mi contador de seteo |
|
2940 | 2940 | |
|
2941 | 2941 | setFile = self.setFile |
|
2942 | 2942 | setFile += 1 |
|
2943 | 2943 | |
|
2944 | 2944 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
2945 | 2945 | timeTuple.tm_year, |
|
2946 | 2946 | timeTuple.tm_yday, |
|
2947 | 2947 | setFile, |
|
2948 | 2948 | ext ) |
|
2949 | 2949 | |
|
2950 | 2950 | filename = os.path.join( path, subfolder, file ) |
|
2951 | 2951 | |
|
2952 | 2952 | self.blockIndex = 0 |
|
2953 | 2953 | self.filename = filename |
|
2954 | 2954 | self.setFile = setFile |
|
2955 | 2955 | self.flagIsNewFile = 1 |
|
2956 | 2956 | |
|
2957 | 2957 | print 'Writing the file: %s'%self.filename |
|
2958 | 2958 | |
|
2959 | 2959 | self.setFitsHeader(self.dataOut, self.metadatafile) |
|
2960 | 2960 | |
|
2961 | 2961 | return 1 |
|
2962 | 2962 | |
|
2963 | 2963 | def writeBlock(self): |
|
2964 | 2964 | self.addData(self.dataOut.data_spc) |
|
2965 | 2965 | self.flagIsNewFile = 0 |
|
2966 | 2966 | |
|
2967 | 2967 | |
|
2968 | 2968 | def __setNewBlock(self): |
|
2969 | 2969 | |
|
2970 | 2970 | if self.flagIsNewFile: |
|
2971 | 2971 | return 1 |
|
2972 | 2972 | |
|
2973 | 2973 | if self.blockIndex < self.dataBlocksPerFile: |
|
2974 | 2974 | return 1 |
|
2975 | 2975 | |
|
2976 | 2976 | if not( self.setNextFile() ): |
|
2977 | 2977 | return 0 |
|
2978 | 2978 | |
|
2979 | 2979 | return 1 |
|
2980 | 2980 | |
|
2981 | 2981 | def writeNextBlock(self): |
|
2982 | 2982 | if not( self.__setNewBlock() ): |
|
2983 | 2983 | return 0 |
|
2984 | 2984 | self.writeBlock() |
|
2985 | 2985 | return 1 |
|
2986 | 2986 | |
|
2987 | 2987 | def putData(self): |
|
2988 | 2988 | if self.flagIsNewFile: |
|
2989 | 2989 | self.setNextFile() |
|
2990 | 2990 | self.writeNextBlock() |
|
2991 | 2991 | |
|
2992 | 2992 | def run(self, dataOut, **kwargs): |
|
2993 | 2993 | if not(self.isConfig): |
|
2994 | 2994 | self.setup(dataOut, **kwargs) |
|
2995 | 2995 | self.isConfig = True |
|
2996 | 2996 | self.putData() |
|
2997 | 2997 | |
|
2998 | 2998 | |
|
2999 | 2999 | class FitsReader(ProcessingUnit): |
|
3000 | 3000 | |
|
3001 | 3001 | # __TIMEZONE = time.timezone |
|
3002 | 3002 | |
|
3003 | 3003 | expName = None |
|
3004 | 3004 | datetimestr = None |
|
3005 | 3005 | utc = None |
|
3006 | 3006 | nChannels = None |
|
3007 | 3007 | nSamples = None |
|
3008 | 3008 | dataBlocksPerFile = None |
|
3009 | 3009 | comments = None |
|
3010 | 3010 | lastUTTime = None |
|
3011 | 3011 | header_dict = None |
|
3012 | 3012 | data = None |
|
3013 | 3013 | data_header_dict = None |
|
3014 | 3014 | |
|
3015 | 3015 | def __init__(self): |
|
3016 | 3016 | self.isConfig = False |
|
3017 | 3017 | self.ext = '.fits' |
|
3018 | 3018 | self.setFile = 0 |
|
3019 | 3019 | self.flagNoMoreFiles = 0 |
|
3020 | 3020 | self.flagIsNewFile = 1 |
|
3021 | 3021 | self.flagTimeBlock = None |
|
3022 | 3022 | self.fileIndex = None |
|
3023 | 3023 | self.filename = None |
|
3024 | 3024 | self.fileSize = None |
|
3025 | 3025 | self.fitsObj = None |
|
3026 | 3026 | self.timeZone = None |
|
3027 | 3027 | self.nReadBlocks = 0 |
|
3028 | 3028 | self.nTotalBlocks = 0 |
|
3029 | 3029 | self.dataOut = self.createObjByDefault() |
|
3030 | 3030 | self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup() |
|
3031 | 3031 | self.blockIndex = 1 |
|
3032 | 3032 | |
|
3033 | 3033 | def createObjByDefault(self): |
|
3034 | 3034 | |
|
3035 | 3035 | dataObj = Fits() |
|
3036 | 3036 | |
|
3037 | 3037 | return dataObj |
|
3038 | 3038 | |
|
3039 | 3039 | def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False): |
|
3040 | 3040 | try: |
|
3041 | 3041 | fitsObj = pyfits.open(filename,'readonly') |
|
3042 | 3042 | except: |
|
3043 | 3043 | raise IOError, "The file %s can't be opened" %(filename) |
|
3044 | 3044 | |
|
3045 | 3045 | header = fitsObj[0].header |
|
3046 | 3046 | struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S") |
|
3047 | 3047 | utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS |
|
3048 | 3048 | |
|
3049 | 3049 | ltc = utc |
|
3050 | 3050 | if useLocalTime: |
|
3051 | 3051 | ltc -= time.timezone |
|
3052 | 3052 | thisDatetime = datetime.datetime.utcfromtimestamp(ltc) |
|
3053 | 3053 | thisTime = thisDatetime.time() |
|
3054 | 3054 | |
|
3055 | 3055 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
3056 | 3056 | return None |
|
3057 | 3057 | |
|
3058 | 3058 | return thisDatetime |
|
3059 | 3059 | |
|
3060 | 3060 | def __setNextFileOnline(self): |
|
3061 | 3061 | raise ValueError, "No implemented" |
|
3062 | 3062 | |
|
3063 | 3063 | def __setNextFileOffline(self): |
|
3064 | 3064 | idFile = self.fileIndex |
|
3065 | 3065 | |
|
3066 | 3066 | while (True): |
|
3067 | 3067 | idFile += 1 |
|
3068 | 3068 | if not(idFile < len(self.filenameList)): |
|
3069 | 3069 | self.flagNoMoreFiles = 1 |
|
3070 | 3070 | print "No more Files" |
|
3071 | 3071 | return 0 |
|
3072 | 3072 | |
|
3073 | 3073 | filename = self.filenameList[idFile] |
|
3074 | 3074 | |
|
3075 | 3075 | # if not(self.__verifyFile(filename)): |
|
3076 | 3076 | # continue |
|
3077 | 3077 | |
|
3078 | 3078 | fileSize = os.path.getsize(filename) |
|
3079 | 3079 | fitsObj = pyfits.open(filename,'readonly') |
|
3080 | 3080 | break |
|
3081 | 3081 | |
|
3082 | 3082 | self.flagIsNewFile = 1 |
|
3083 | 3083 | self.fileIndex = idFile |
|
3084 | 3084 | self.filename = filename |
|
3085 | 3085 | self.fileSize = fileSize |
|
3086 | 3086 | self.fitsObj = fitsObj |
|
3087 | 3087 | self.blockIndex = 0 |
|
3088 | 3088 | print "Setting the file: %s"%self.filename |
|
3089 | 3089 | |
|
3090 | 3090 | return 1 |
|
3091 | 3091 | |
|
3092 | 3092 | def readHeader(self): |
|
3093 | 3093 | headerObj = self.fitsObj[0] |
|
3094 | 3094 | |
|
3095 | 3095 | self.header_dict = headerObj.header |
|
3096 | 3096 | if 'EXPNAME' in headerObj.header.keys(): |
|
3097 | 3097 | self.expName = headerObj.header['EXPNAME'] |
|
3098 | 3098 | |
|
3099 | 3099 | if 'DATATYPE' in headerObj.header.keys(): |
|
3100 | 3100 | self.dataType = headerObj.header['DATATYPE'] |
|
3101 | 3101 | |
|
3102 | 3102 | self.datetimestr = headerObj.header['DATETIME'] |
|
3103 | 3103 | channelList = headerObj.header['CHANNELLIST'] |
|
3104 | 3104 | channelList = channelList.split('[') |
|
3105 | 3105 | channelList = channelList[1].split(']') |
|
3106 | 3106 | channelList = channelList[0].split(',') |
|
3107 | 3107 | channelList = [int(ch) for ch in channelList] |
|
3108 | 3108 | self.channelList = channelList |
|
3109 | 3109 | self.nChannels = headerObj.header['NCHANNELS'] |
|
3110 | 3110 | self.nHeights = headerObj.header['NHEIGHTS'] |
|
3111 | 3111 | self.ippSeconds = headerObj.header['IPPSECONDS'] |
|
3112 | 3112 | self.nCohInt = headerObj.header['NCOHINT'] |
|
3113 | 3113 | self.nIncohInt = headerObj.header['NINCOHINT'] |
|
3114 | 3114 | self.dataBlocksPerFile = headerObj.header['NBLOCK'] |
|
3115 | 3115 | self.timeZone = headerObj.header['TIMEZONE'] |
|
3116 | 3116 | |
|
3117 | 3117 | self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
3118 | 3118 | |
|
3119 | 3119 | if 'COMMENT' in headerObj.header.keys(): |
|
3120 | 3120 | self.comments = headerObj.header['COMMENT'] |
|
3121 | 3121 | |
|
3122 | 3122 | self.readHeightList() |
|
3123 | 3123 | |
|
3124 | 3124 | def readHeightList(self): |
|
3125 | 3125 | self.blockIndex = self.blockIndex + 1 |
|
3126 | 3126 | obj = self.fitsObj[self.blockIndex] |
|
3127 | 3127 | self.heightList = obj.data |
|
3128 | 3128 | self.blockIndex = self.blockIndex + 1 |
|
3129 | 3129 | |
|
3130 | 3130 | def readExtension(self): |
|
3131 | 3131 | obj = self.fitsObj[self.blockIndex] |
|
3132 | 3132 | self.heightList = obj.data |
|
3133 | 3133 | self.blockIndex = self.blockIndex + 1 |
|
3134 | 3134 | |
|
3135 | 3135 | def setNextFile(self): |
|
3136 | 3136 | |
|
3137 | 3137 | if self.online: |
|
3138 | 3138 | newFile = self.__setNextFileOnline() |
|
3139 | 3139 | else: |
|
3140 | 3140 | newFile = self.__setNextFileOffline() |
|
3141 | 3141 | |
|
3142 | 3142 | if not(newFile): |
|
3143 | 3143 | return 0 |
|
3144 | 3144 | |
|
3145 | 3145 | self.readHeader() |
|
3146 | 3146 | |
|
3147 | 3147 | self.nReadBlocks = 0 |
|
3148 | 3148 | # self.blockIndex = 1 |
|
3149 | 3149 | return 1 |
|
3150 | 3150 | |
|
3151 | 3151 | def __searchFilesOffLine(self, |
|
3152 | 3152 | path, |
|
3153 | 3153 | startDate, |
|
3154 | 3154 | endDate, |
|
3155 | 3155 | startTime=datetime.time(0,0,0), |
|
3156 | 3156 | endTime=datetime.time(23,59,59), |
|
3157 | 3157 | set=None, |
|
3158 | 3158 | expLabel='', |
|
3159 | 3159 | ext='.fits', |
|
3160 | 3160 | walk=True): |
|
3161 | 3161 | |
|
3162 | 3162 | pathList = [] |
|
3163 | 3163 | |
|
3164 | 3164 | if not walk: |
|
3165 | 3165 | pathList.append(path) |
|
3166 | 3166 | |
|
3167 | 3167 | else: |
|
3168 | 3168 | dirList = [] |
|
3169 | 3169 | for thisPath in os.listdir(path): |
|
3170 | 3170 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
3171 | 3171 | continue |
|
3172 | 3172 | if not isDoyFolder(thisPath): |
|
3173 | 3173 | continue |
|
3174 | 3174 | |
|
3175 | 3175 | dirList.append(thisPath) |
|
3176 | 3176 | |
|
3177 | 3177 | if not(dirList): |
|
3178 | 3178 | return None, None |
|
3179 | 3179 | |
|
3180 | 3180 | thisDate = startDate |
|
3181 | 3181 | |
|
3182 | 3182 | while(thisDate <= endDate): |
|
3183 | 3183 | year = thisDate.timetuple().tm_year |
|
3184 | 3184 | doy = thisDate.timetuple().tm_yday |
|
3185 | 3185 | |
|
3186 | 3186 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
3187 | 3187 | if len(matchlist) == 0: |
|
3188 | 3188 | thisDate += datetime.timedelta(1) |
|
3189 | 3189 | continue |
|
3190 | 3190 | for match in matchlist: |
|
3191 | 3191 | pathList.append(os.path.join(path,match,expLabel)) |
|
3192 | 3192 | |
|
3193 | 3193 | thisDate += datetime.timedelta(1) |
|
3194 | 3194 | |
|
3195 | 3195 | if pathList == []: |
|
3196 | 3196 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
3197 | 3197 | return None, None |
|
3198 | 3198 | |
|
3199 | 3199 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
3200 | 3200 | |
|
3201 | 3201 | filenameList = [] |
|
3202 | 3202 | datetimeList = [] |
|
3203 | 3203 | |
|
3204 | 3204 | for i in range(len(pathList)): |
|
3205 | 3205 | |
|
3206 | 3206 | thisPath = pathList[i] |
|
3207 | 3207 | |
|
3208 | 3208 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
3209 | 3209 | fileList.sort() |
|
3210 | 3210 | |
|
3211 | 3211 | for file in fileList: |
|
3212 | 3212 | |
|
3213 | 3213 | filename = os.path.join(thisPath,file) |
|
3214 | 3214 | thisDatetime = self.isFileinThisTime(filename, startTime, endTime) |
|
3215 | 3215 | |
|
3216 | 3216 | if not(thisDatetime): |
|
3217 | 3217 | continue |
|
3218 | 3218 | |
|
3219 | 3219 | filenameList.append(filename) |
|
3220 | 3220 | datetimeList.append(thisDatetime) |
|
3221 | 3221 | |
|
3222 | 3222 | if not(filenameList): |
|
3223 | 3223 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
3224 | 3224 | return None, None |
|
3225 | 3225 | |
|
3226 | 3226 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
3227 | 3227 | |
|
3228 | 3228 | |
|
3229 | 3229 | for i in range(len(filenameList)): |
|
3230 | 3230 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
3231 | 3231 | |
|
3232 | 3232 | self.filenameList = filenameList |
|
3233 | 3233 | self.datetimeList = datetimeList |
|
3234 | 3234 | |
|
3235 | 3235 | return pathList, filenameList |
|
3236 | 3236 | |
|
3237 | 3237 | def setup(self, path=None, |
|
3238 | 3238 | startDate=None, |
|
3239 | 3239 | endDate=None, |
|
3240 | 3240 | startTime=datetime.time(0,0,0), |
|
3241 | 3241 | endTime=datetime.time(23,59,59), |
|
3242 | 3242 | set=0, |
|
3243 | 3243 | expLabel = "", |
|
3244 | 3244 | ext = None, |
|
3245 | 3245 | online = False, |
|
3246 | 3246 | delay = 60, |
|
3247 | 3247 | walk = True): |
|
3248 | 3248 | |
|
3249 | 3249 | if path == None: |
|
3250 | 3250 | raise ValueError, "The path is not valid" |
|
3251 | 3251 | |
|
3252 | 3252 | if ext == None: |
|
3253 | 3253 | ext = self.ext |
|
3254 | 3254 | |
|
3255 | 3255 | if not(online): |
|
3256 | 3256 | print "Searching files in offline mode ..." |
|
3257 | 3257 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
3258 | 3258 | startTime=startTime, endTime=endTime, |
|
3259 | 3259 | set=set, expLabel=expLabel, ext=ext, |
|
3260 | 3260 | walk=walk) |
|
3261 | 3261 | |
|
3262 | 3262 | if not(pathList): |
|
3263 | 3263 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
3264 | 3264 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
3265 | 3265 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
3266 | 3266 | |
|
3267 | 3267 | sys.exit(-1) |
|
3268 | 3268 | |
|
3269 | 3269 | self.fileIndex = -1 |
|
3270 | 3270 | self.pathList = pathList |
|
3271 | 3271 | self.filenameList = filenameList |
|
3272 | 3272 | |
|
3273 | 3273 | self.online = online |
|
3274 | 3274 | self.delay = delay |
|
3275 | 3275 | ext = ext.lower() |
|
3276 | 3276 | self.ext = ext |
|
3277 | 3277 | |
|
3278 | 3278 | if not(self.setNextFile()): |
|
3279 | 3279 | if (startDate!=None) and (endDate!=None): |
|
3280 | 3280 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
3281 | 3281 | elif startDate != None: |
|
3282 | 3282 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
3283 | 3283 | else: |
|
3284 | 3284 | print "No files" |
|
3285 | 3285 | |
|
3286 | 3286 | sys.exit(-1) |
|
3287 | 3287 | |
|
3288 | 3288 | |
|
3289 | 3289 | |
|
3290 | 3290 | def readBlock(self): |
|
3291 | 3291 | dataObj = self.fitsObj[self.blockIndex] |
|
3292 | 3292 | |
|
3293 | 3293 | self.data = dataObj.data |
|
3294 | 3294 | self.data_header_dict = dataObj.header |
|
3295 | 3295 | self.utc = self.data_header_dict['UTCTIME'] |
|
3296 | 3296 | |
|
3297 | 3297 | self.flagIsNewFile = 0 |
|
3298 | 3298 | self.blockIndex += 1 |
|
3299 | 3299 | self.nTotalBlocks += 1 |
|
3300 | 3300 | self.nReadBlocks += 1 |
|
3301 | 3301 | |
|
3302 | 3302 | return 1 |
|
3303 | 3303 | |
|
3304 | 3304 | def __jumpToLastBlock(self): |
|
3305 | 3305 | raise ValueError, "No implemented" |
|
3306 | 3306 | |
|
3307 | 3307 | def __waitNewBlock(self): |
|
3308 | 3308 | """ |
|
3309 | 3309 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
3310 | 3310 | |
|
3311 | 3311 | Si el modo de lectura es OffLine siempre retorn 0 |
|
3312 | 3312 | """ |
|
3313 | 3313 | if not self.online: |
|
3314 | 3314 | return 0 |
|
3315 | 3315 | |
|
3316 | 3316 | if (self.nReadBlocks >= self.dataBlocksPerFile): |
|
3317 | 3317 | return 0 |
|
3318 | 3318 | |
|
3319 | 3319 | currentPointer = self.fp.tell() |
|
3320 | 3320 | |
|
3321 | 3321 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
3322 | 3322 | |
|
3323 | 3323 | for nTries in range( self.nTries ): |
|
3324 | 3324 | |
|
3325 | 3325 | self.fp.close() |
|
3326 | 3326 | self.fp = open( self.filename, 'rb' ) |
|
3327 | 3327 | self.fp.seek( currentPointer ) |
|
3328 | 3328 | |
|
3329 | 3329 | self.fileSize = os.path.getsize( self.filename ) |
|
3330 | 3330 | currentSize = self.fileSize - currentPointer |
|
3331 | 3331 | |
|
3332 | 3332 | if ( currentSize >= neededSize ): |
|
3333 | 3333 | self.__rdBasicHeader() |
|
3334 | 3334 | return 1 |
|
3335 | 3335 | |
|
3336 | 3336 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
3337 | 3337 | time.sleep( self.delay ) |
|
3338 | 3338 | |
|
3339 | 3339 | |
|
3340 | 3340 | return 0 |
|
3341 | 3341 | |
|
3342 | 3342 | def __setNewBlock(self): |
|
3343 | 3343 | |
|
3344 | 3344 | if self.online: |
|
3345 | 3345 | self.__jumpToLastBlock() |
|
3346 | 3346 | |
|
3347 | 3347 | if self.flagIsNewFile: |
|
3348 | 3348 | return 1 |
|
3349 | 3349 | |
|
3350 | 3350 | self.lastUTTime = self.utc |
|
3351 | 3351 | |
|
3352 | 3352 | if self.online: |
|
3353 | 3353 | if self.__waitNewBlock(): |
|
3354 | 3354 | return 1 |
|
3355 | 3355 | |
|
3356 | 3356 | if self.nReadBlocks < self.dataBlocksPerFile: |
|
3357 | 3357 | return 1 |
|
3358 | 3358 | |
|
3359 | 3359 | if not(self.setNextFile()): |
|
3360 | 3360 | return 0 |
|
3361 | 3361 | |
|
3362 | 3362 | deltaTime = self.utc - self.lastUTTime |
|
3363 | 3363 | |
|
3364 | 3364 | self.flagTimeBlock = 0 |
|
3365 | 3365 | |
|
3366 | 3366 | if deltaTime > self.maxTimeStep: |
|
3367 | 3367 | self.flagTimeBlock = 1 |
|
3368 | 3368 | |
|
3369 | 3369 | return 1 |
|
3370 | 3370 | |
|
3371 | 3371 | |
|
3372 | 3372 | def readNextBlock(self): |
|
3373 | 3373 | if not(self.__setNewBlock()): |
|
3374 | 3374 | return 0 |
|
3375 | 3375 | |
|
3376 | 3376 | if not(self.readBlock()): |
|
3377 | 3377 | return 0 |
|
3378 | 3378 | |
|
3379 | 3379 | return 1 |
|
3380 | 3380 | |
|
3381 | 3381 | |
|
3382 | 3382 | def getData(self): |
|
3383 | 3383 | |
|
3384 | 3384 | if self.flagNoMoreFiles: |
|
3385 | 3385 | self.dataOut.flagNoData = True |
|
3386 | 3386 | print 'Process finished' |
|
3387 | 3387 | return 0 |
|
3388 | 3388 | |
|
3389 | 3389 | self.flagTimeBlock = 0 |
|
3390 | 3390 | self.flagIsNewBlock = 0 |
|
3391 | 3391 | |
|
3392 | 3392 | if not(self.readNextBlock()): |
|
3393 | 3393 | return 0 |
|
3394 | 3394 | |
|
3395 | 3395 | if self.data == None: |
|
3396 | 3396 | self.dataOut.flagNoData = True |
|
3397 | 3397 | return 0 |
|
3398 | 3398 | |
|
3399 | 3399 | self.dataOut.data = self.data |
|
3400 | 3400 | self.dataOut.data_header = self.data_header_dict |
|
3401 | 3401 | self.dataOut.utctime = self.utc |
|
3402 | 3402 | |
|
3403 | 3403 | self.dataOut.header = self.header_dict |
|
3404 | 3404 | self.dataOut.expName = self.expName |
|
3405 | 3405 | self.dataOut.nChannels = self.nChannels |
|
3406 | 3406 | self.dataOut.timeZone = self.timeZone |
|
3407 | 3407 | self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile |
|
3408 | 3408 | self.dataOut.comments = self.comments |
|
3409 | 3409 | self.dataOut.timeInterval = self.timeInterval |
|
3410 | 3410 | self.dataOut.channelList = self.channelList |
|
3411 | 3411 | self.dataOut.heightList = self.heightList |
|
3412 | 3412 | self.dataOut.flagNoData = False |
|
3413 | 3413 | |
|
3414 | 3414 | return self.dataOut.data |
|
3415 | 3415 | |
|
3416 | 3416 | def run(self, **kwargs): |
|
3417 | 3417 | |
|
3418 | 3418 | if not(self.isConfig): |
|
3419 | 3419 | self.setup(**kwargs) |
|
3420 | 3420 | self.isConfig = True |
|
3421 | 3421 | |
|
3422 | 3422 | self.getData() |
|
3423 | 3423 | |
|
3424 | 3424 | |
|
3425 | 3425 | class RadacHeader(): |
|
3426 | 3426 | def __init__(self, fp): |
|
3427 | 3427 | header = 'Raw11/Data/RadacHeader' |
|
3428 | 3428 | self.beamCode = fp.get(header+'/BeamCode') |
|
3429 | 3429 | self.code = fp.get(header+'/Code') |
|
3430 | 3430 | self.frameCount = fp.get(header+'/FrameCount') |
|
3431 | 3431 | self.modeGroup = fp.get(header+'/ModeGroup') |
|
3432 | 3432 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') |
|
3433 | 3433 | self.pulseCount = fp.get(header+'/PulseCount') |
|
3434 | 3434 | self.radacTime = fp.get(header+'/RadacTime') |
|
3435 | 3435 | self.timeCount = fp.get(header+'/TimeCount') |
|
3436 | 3436 | self.timeStatus = fp.get(header+'/TimeStatus') |
|
3437 | 3437 | |
|
3438 | 3438 | self.nrecords = self.pulseCount.shape[0] #numero de bloques |
|
3439 | 3439 | self.npulses = self.pulseCount.shape[1] #numero de perfiles |
|
3440 | 3440 | self.nsamples = self.nsamplesPulse[0,0] #numero de alturas |
|
3441 | 3441 | |
|
3442 | 3442 | |
|
3443 | 3443 | def getIndexRangeToPulse(self, idrecord=0): |
|
3444 | 3444 | indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) |
|
3445 | 3445 | startPulseCountId = indexToZero[0][0] |
|
3446 | 3446 | endPulseCountId = startPulseCountId - 1 |
|
3447 | 3447 | range1 = numpy.arange(startPulseCountId,self.npulses,1) |
|
3448 | 3448 | range2 = numpy.arange(0,startPulseCountId,1) |
|
3449 | 3449 | return range1, range2 |
|
3450 | 3450 | |
|
3451 | 3451 | |
|
3452 | 3452 | class AMISRReader(ProcessingUnit): |
|
3453 | 3453 | |
|
3454 | 3454 | path = None |
|
3455 | 3455 | startDate = None |
|
3456 | 3456 | endDate = None |
|
3457 | 3457 | startTime = None |
|
3458 | 3458 | endTime = None |
|
3459 | 3459 | walk = None |
|
3460 | 3460 | isConfig = False |
|
3461 | 3461 | |
|
3462 | 3462 | def __init__(self): |
|
3463 | 3463 | self.set = None |
|
3464 | 3464 | self.subset = None |
|
3465 | 3465 | self.extension_file = '.h5' |
|
3466 | 3466 | self.dtc_str = 'dtc' |
|
3467 | 3467 | self.dtc_id = 0 |
|
3468 | 3468 | self.status = True |
|
3469 | 3469 | self.isConfig = False |
|
3470 | 3470 | self.dirnameList = [] |
|
3471 | 3471 | self.filenameList = [] |
|
3472 | 3472 | self.fileIndex = None |
|
3473 | 3473 | self.flagNoMoreFiles = False |
|
3474 | 3474 | self.flagIsNewFile = 0 |
|
3475 | 3475 | self.filename = '' |
|
3476 | 3476 | self.amisrFilePointer = None |
|
3477 | 3477 | self.radacHeaderObj = None |
|
3478 | 3478 | self.dataOut = self.__createObjByDefault() |
|
3479 | 3479 | self.datablock = None |
|
3480 | 3480 | self.rest_datablock = None |
|
3481 | 3481 | self.range = None |
|
3482 | 3482 | self.idrecord_count = 0 |
|
3483 | 3483 | self.profileIndex = 0 |
|
3484 | 3484 | self.idpulse_range1 = None |
|
3485 | 3485 | self.idpulse_range2 = None |
|
3486 | 3486 | self.beamCodeByFrame = None |
|
3487 | 3487 | self.radacTimeByFrame = None |
|
3488 | 3488 | #atributos originales tal y como esta en el archivo de datos |
|
3489 | 3489 | self.beamCodesFromFile = None |
|
3490 | 3490 | self.radacTimeFromFile = None |
|
3491 | 3491 | self.rangeFromFile = None |
|
3492 | 3492 | self.dataByFrame = None |
|
3493 | 3493 | self.dataset = None |
|
3494 | 3494 | |
|
3495 | 3495 | |
|
3496 | 3496 | def __createObjByDefault(self): |
|
3497 | 3497 | |
|
3498 | 3498 | dataObj = AMISR() |
|
3499 | 3499 | |
|
3500 | 3500 | return dataObj |
|
3501 | 3501 | |
|
3502 | 3502 | def __setParameters(self,path,startDate,endDate,startTime,endTime,walk): |
|
3503 | 3503 | self.path = path |
|
3504 | 3504 | self.startDate = startDate |
|
3505 | 3505 | self.endDate = endDate |
|
3506 | 3506 | self.startTime = startTime |
|
3507 | 3507 | self.endTime = endTime |
|
3508 | 3508 | self.walk = walk |
|
3509 | 3509 | |
|
3510 | 3510 | def __checkPath(self): |
|
3511 | 3511 | if os.path.exists(self.path): |
|
3512 | 3512 | self.status = 1 |
|
3513 | 3513 | else: |
|
3514 | 3514 | self.status = 0 |
|
3515 | 3515 | print 'Path:%s does not exists'%self.path |
|
3516 | 3516 | |
|
3517 | 3517 | return |
|
3518 | 3518 | |
|
3519 | 3519 | def __selDates(self, amisr_dirname_format): |
|
3520 | 3520 | year = int(amisr_dirname_format[0:4]) |
|
3521 | 3521 | month = int(amisr_dirname_format[4:6]) |
|
3522 | 3522 | dom = int(amisr_dirname_format[6:8]) |
|
3523 | 3523 | thisDate = datetime.date(year,month,dom) |
|
3524 | 3524 | |
|
3525 | 3525 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
3526 | 3526 | return amisr_dirname_format |
|
3527 | 3527 | |
|
3528 | 3528 | def __findDataForDates(self): |
|
3529 | 3529 | |
|
3530 | 3530 | import re |
|
3531 | 3531 | |
|
3532 | 3532 | if not(self.status): |
|
3533 | 3533 | return None |
|
3534 | 3534 | |
|
3535 | 3535 | pat = '\d+.\d+' |
|
3536 | 3536 | dirnameList = [re.search(pat,x).string for x in os.listdir(self.path)] |
|
3537 | 3537 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
3538 | 3538 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
3539 | 3539 | if len(dirnameList)>0: |
|
3540 | 3540 | self.status = 1 |
|
3541 | 3541 | self.dirnameList = dirnameList |
|
3542 | 3542 | self.dirnameList.sort() |
|
3543 | 3543 | else: |
|
3544 | 3544 | self.status = 0 |
|
3545 | 3545 | return None |
|
3546 | 3546 | |
|
3547 | 3547 | def __getTimeFromData(self): |
|
3548 | 3548 | pass |
|
3549 | 3549 | |
|
3550 | 3550 | def __filterByGlob1(self, dirName): |
|
3551 | 3551 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) |
|
3552 | 3552 | filterDict = {} |
|
3553 | 3553 | filterDict.setdefault(dirName) |
|
3554 | 3554 | filterDict[dirName] = filter_files |
|
3555 | 3555 | return filterDict |
|
3556 | 3556 | |
|
3557 | 3557 | def __getFilenameList(self, fileListInKeys, dirList): |
|
3558 | 3558 | for value in fileListInKeys: |
|
3559 | 3559 | dirName = value.keys()[0] |
|
3560 | 3560 | for file in value[dirName]: |
|
3561 | 3561 | filename = os.path.join(dirName, file) |
|
3562 | 3562 | self.filenameList.append(filename) |
|
3563 | 3563 | |
|
3564 | 3564 | |
|
3565 | 3565 | def __selectDataForTimes(self): |
|
3566 | 3566 | #aun no esta implementado el filtro for tiempo |
|
3567 | 3567 | if not(self.status): |
|
3568 | 3568 | return None |
|
3569 | 3569 | |
|
3570 | 3570 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
3571 | 3571 | |
|
3572 | 3572 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] |
|
3573 | 3573 | |
|
3574 | 3574 | self.__getFilenameList(fileListInKeys, dirList) |
|
3575 | 3575 | |
|
3576 | 3576 | if len(self.filenameList)>0: |
|
3577 | 3577 | self.status = 1 |
|
3578 | 3578 | self.filenameList.sort() |
|
3579 | 3579 | else: |
|
3580 | 3580 | self.status = 0 |
|
3581 | 3581 | return None |
|
3582 | 3582 | |
|
3583 | 3583 | |
|
3584 | 3584 | def __searchFilesOffline(self, |
|
3585 | 3585 | path, |
|
3586 | 3586 | startDate, |
|
3587 | 3587 | endDate, |
|
3588 | 3588 | startTime=datetime.time(0,0,0), |
|
3589 | 3589 | endTime=datetime.time(23,59,59), |
|
3590 | 3590 | walk=True): |
|
3591 | 3591 | |
|
3592 | 3592 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
3593 | 3593 | |
|
3594 | 3594 | self.__checkPath() |
|
3595 | 3595 | |
|
3596 | 3596 | self.__findDataForDates() |
|
3597 | 3597 | |
|
3598 | 3598 | self.__selectDataForTimes() |
|
3599 | 3599 | |
|
3600 | 3600 | for i in range(len(self.filenameList)): |
|
3601 | 3601 | print "%s" %(self.filenameList[i]) |
|
3602 | 3602 | |
|
3603 | 3603 | return |
|
3604 | 3604 | |
|
3605 | 3605 | def __setNextFileOffline(self): |
|
3606 | 3606 | idFile = self.fileIndex |
|
3607 | 3607 | |
|
3608 | 3608 | while (True): |
|
3609 | 3609 | idFile += 1 |
|
3610 | 3610 | if not(idFile < len(self.filenameList)): |
|
3611 | 3611 | self.flagNoMoreFiles = 1 |
|
3612 | 3612 | print "No more Files" |
|
3613 | 3613 | return 0 |
|
3614 | 3614 | |
|
3615 | 3615 | filename = self.filenameList[idFile] |
|
3616 | 3616 | |
|
3617 | 3617 | amisrFilePointer = h5py.File(filename,'r') |
|
3618 | 3618 | |
|
3619 | 3619 | break |
|
3620 | 3620 | |
|
3621 | 3621 | self.flagIsNewFile = 1 |
|
3622 | 3622 | self.fileIndex = idFile |
|
3623 | 3623 | self.filename = filename |
|
3624 | 3624 | |
|
3625 | 3625 | self.amisrFilePointer = amisrFilePointer |
|
3626 | 3626 | |
|
3627 | 3627 | print "Setting the file: %s"%self.filename |
|
3628 | 3628 | |
|
3629 | 3629 | return 1 |
|
3630 | 3630 | |
|
3631 | 3631 | def __readHeader(self): |
|
3632 | 3632 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) |
|
3633 | 3633 | self.flagIsNewFile = 1 |
|
3634 | 3634 | |
|
3635 | 3635 | |
|
3636 | 3636 | |
|
3637 | 3637 | def __setNextFile(self): |
|
3638 | 3638 | |
|
3639 | 3639 | newFile = self.__setNextFileOffline() |
|
3640 | 3640 | |
|
3641 | 3641 | if not(newFile): |
|
3642 | 3642 | return 0 |
|
3643 | 3643 | |
|
3644 | 3644 | self.__readHeader() |
|
3645 | 3645 | |
|
3646 | 3646 | self.readDataBlock() |
|
3647 | 3647 | |
|
3648 | 3648 | |
|
3649 | 3649 | def setup(self,path=None, |
|
3650 | 3650 | startDate=None, |
|
3651 | 3651 | endDate=None, |
|
3652 | 3652 | startTime=datetime.time(0,0,0), |
|
3653 | 3653 | endTime=datetime.time(23,59,59), |
|
3654 | 3654 | walk=True): |
|
3655 | 3655 | |
|
3656 | 3656 | #Busqueda de archivos offline |
|
3657 | 3657 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) |
|
3658 | 3658 | |
|
3659 | 3659 | if not(self.filenameList): |
|
3660 | 3660 | print "There is no files into the folder: %s"%(path) |
|
3661 | 3661 | |
|
3662 | 3662 | sys.exit(-1) |
|
3663 | 3663 | |
|
3664 | 3664 | self.fileIndex = -1 |
|
3665 | 3665 | |
|
3666 | 3666 | self.__setNextFile() |
|
3667 | 3667 | |
|
3668 | 3668 | def readRanges(self): |
|
3669 | 3669 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') |
|
3670 |
self.rangeFromFile = dataset.value |
|
|
3670 | #self.rangeFromFile = dataset.value | |
|
3671 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) | |
|
3671 | 3672 | return range |
|
3672 | 3673 | |
|
3673 | 3674 | |
|
3674 | 3675 | def readRadacTime(self,idrecord, range1, range2): |
|
3675 | 3676 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value |
|
3676 | 3677 | |
|
3677 | 3678 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
3678 | 3679 | #radacTimeByFrame = dataset[idrecord - 1,range1] |
|
3679 | 3680 | #radacTimeByFrame = dataset[idrecord,range2] |
|
3680 | 3681 | |
|
3681 | 3682 | return radacTimeByFrame |
|
3682 | 3683 | |
|
3683 | 3684 | def readBeamCode(self, idrecord, range1, range2): |
|
3684 | 3685 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') |
|
3685 | 3686 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
3686 | 3687 | self.beamCodesFromFile = dataset.value |
|
3687 | 3688 | |
|
3688 | 3689 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] |
|
3689 | 3690 | #beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
3690 | 3691 | beamcodeByFrame[range1] = dataset[idrecord, range1] |
|
3691 | 3692 | beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
3692 | 3693 | |
|
3693 | 3694 | return beamcodeByFrame |
|
3694 | 3695 | |
|
3695 | 3696 | |
|
3696 | 3697 | def __setDataByFrame(self): |
|
3697 | 3698 | ndata = 2 # porque es complejo |
|
3698 | 3699 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) |
|
3699 | 3700 | return dataByFrame |
|
3700 | 3701 | |
|
3701 | 3702 | def __readDataSet(self): |
|
3702 | 3703 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') |
|
3703 | 3704 | return dataset |
|
3704 | 3705 | |
|
3705 | 3706 | def __setDataBlock(self,): |
|
3706 | 3707 | real = self.dataByFrame[:,:,0] #asumo que 0 es real |
|
3707 | 3708 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario |
|
3708 | 3709 | datablock = real + imag*1j #armo el complejo |
|
3709 | 3710 | return datablock |
|
3710 | 3711 | |
|
3711 | 3712 | def readSamples_version1(self,idrecord): |
|
3712 | 3713 | #estas tres primeras lineas solo se deben ejecutar una vez |
|
3713 | 3714 | if self.flagIsNewFile: |
|
3714 | 3715 | self.idpulse_range1, self.idpulse_range2 = self.radacHeaderObj.getIndexRangeToPulse(0) |
|
3715 | 3716 | self.dataByFrame = self.__setDataByFrame() |
|
3716 | 3717 | self.beamCodeByFrame = self.readBeamCode(idrecord, self.idpulse_range1, self.idpulse_range2) |
|
3717 | 3718 | self.radacTimeByFrame = self.readRadacTime(idrecord, self.idpulse_range1, self.idpulse_range2) |
|
3718 | 3719 | #reading dataset |
|
3719 | 3720 | self.dataset = self.__readDataSet() |
|
3720 | 3721 | |
|
3721 | 3722 | if idrecord == 0: |
|
3722 | 3723 | |
|
3723 | 3724 | if len(numpy.where(self.dataByFrame!=0.0)[0]) or len(numpy.where(self.dataByFrame!=0.0)[1]) or len(numpy.where(self.dataByFrame!=0.0)[2]): |
|
3724 | 3725 | #falta agregar una condicion para datos discontinuos |
|
3725 | 3726 | #por defecto une los datos del record anterior |
|
3726 | 3727 | self.dataByFrame[self.idpulse_range2, :, :] = self.dataset[idrecord, self.idpulse_range2, :, :] |
|
3727 | 3728 | #timepulse |
|
3728 | 3729 | self.radacTimeByFrame[self.idpulse_range2] = self.radacHeaderObj.radacTime[idrecord, self.idpulse_range2] |
|
3729 | 3730 | else: |
|
3730 | 3731 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord, self.idpulse_range1, :, :] |
|
3731 | 3732 | |
|
3732 | 3733 | self.radacTimeByFrame[self.idpulse_range1] = self.radacHeaderObj.radacTime[idrecord, self.idpulse_range1] |
|
3733 | 3734 | |
|
3734 | 3735 | datablock = self.__setDataBlock() |
|
3735 | 3736 | |
|
3736 | 3737 | return datablock |
|
3737 | 3738 | |
|
3738 | 3739 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord - 1,self.idpulse_range1, :, :] |
|
3739 | 3740 | self.dataByFrame[self.idpulse_range2, :, :] = self.dataset[idrecord, self.idpulse_range2, :, :] |
|
3740 | 3741 | datablock = self.__setDataBlock() |
|
3741 | 3742 | self.flagIsNewFile = 0 |
|
3742 | 3743 | |
|
3743 | 3744 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord, self.idpulse_range1, :, :] |
|
3744 | 3745 | |
|
3745 | 3746 | |
|
3746 | 3747 | return datablock |
|
3747 | 3748 | |
|
3748 | 3749 | |
|
3749 | 3750 | def readSamples(self,idrecord): |
|
3750 | 3751 | if self.flagIsNewFile: |
|
3751 | 3752 | self.dataByFrame = self.__setDataByFrame() |
|
3752 | 3753 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] |
|
3753 | ||
|
3754 | ||
|
3755 | #reading ranges | |
|
3756 | self.readRanges() | |
|
3754 | 3757 | #reading dataset |
|
3755 | 3758 | self.dataset = self.__readDataSet() |
|
3756 | 3759 | |
|
3757 | 3760 | self.flagIsNewFile = 0 |
|
3758 | 3761 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] |
|
3759 | 3762 | self.dataByFrame = self.dataset[idrecord, :, :, :] |
|
3760 | 3763 | datablock = self.__setDataBlock() |
|
3761 | 3764 | return datablock |
|
3762 | 3765 | |
|
3763 | 3766 | |
|
3764 | 3767 | def readDataBlock(self): |
|
3765 | 3768 | |
|
3766 | 3769 | #self.datablock = self.readSamples(self.idrecord_count) |
|
3767 | 3770 | self.datablock = self.readSamples(self.idrecord_count) |
|
3768 | 3771 | #print 'record:', self.idrecord_count |
|
3769 | 3772 | |
|
3770 | 3773 | self.idrecord_count += 1 |
|
3771 | 3774 | self.profileIndex = 0 |
|
3772 | 3775 | |
|
3773 | 3776 | if self.idrecord_count >= self.radacHeaderObj.nrecords: |
|
3774 | 3777 | self.idrecord_count = 0 |
|
3775 | 3778 | self.flagIsNewFile = 1 |
|
3776 | 3779 | |
|
3777 | 3780 | def readNextBlock(self): |
|
3778 | 3781 | |
|
3779 | 3782 | self.readDataBlock() |
|
3780 | 3783 | |
|
3781 | 3784 | if self.flagIsNewFile: |
|
3782 | 3785 | self.__setNextFile() |
|
3783 | 3786 | pass |
|
3784 | 3787 | |
|
3785 | 3788 | def __hasNotDataInBuffer(self): |
|
3786 | 3789 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record |
|
3787 | 3790 | if self.profileIndex >= self.radacHeaderObj.npulses: |
|
3788 | 3791 | return 1 |
|
3789 | 3792 | return 0 |
|
3790 | 3793 | |
|
3794 | def setObjProperties(self): | |
|
3795 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km | |
|
3796 | self.dataOut.nProfiles = self.radacHeaderObj.npulses | |
|
3797 | self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
|
3798 | self.dataOut.nBaud = None | |
|
3799 | self.dataOut.nCode = None | |
|
3800 | self.dataOut.code = None | |
|
3791 | 3801 | |
|
3792 | 3802 | def getData(self): |
|
3793 | 3803 | |
|
3794 | 3804 | if self.flagNoMoreFiles: |
|
3795 | 3805 | self.dataOut.flagNoData = True |
|
3796 | 3806 | print 'Process finished' |
|
3797 | 3807 | return 0 |
|
3798 | 3808 | |
|
3799 | 3809 | if self.__hasNotDataInBuffer(): |
|
3800 | 3810 | self.readNextBlock() |
|
3801 | 3811 | # if not( self.readNextBlock() ): |
|
3802 | 3812 | # return 0 |
|
3803 | 3813 | # self.getFirstHeader() |
|
3804 | 3814 | |
|
3805 | 3815 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
3806 | 3816 | self.dataOut.flagNoData = True |
|
3807 | 3817 | return 0 |
|
3808 | 3818 | |
|
3809 | 3819 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) |
|
3810 | 3820 | |
|
3811 | 3821 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] |
|
3812 | 3822 | |
|
3813 | 3823 | self.dataOut.flagNoData = False |
|
3814 | 3824 | |
|
3815 | 3825 | self.profileIndex += 1 |
|
3816 | 3826 | |
|
3817 | 3827 | return self.dataOut.data |
|
3818 | 3828 | |
|
3819 | 3829 | |
|
3820 | 3830 | def run(self, **kwargs): |
|
3821 | 3831 | if not(self.isConfig): |
|
3822 | 3832 | self.setup(**kwargs) |
|
3833 | self.setObjProperties() | |
|
3823 | 3834 | self.isConfig = True |
|
3824 | 3835 | |
|
3825 | 3836 | self.getData() |
@@ -1,2033 +1,2110 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime, os |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | def isRealtime(utcdatatime): |
|
5 | 5 | utcnow = time.mktime(time.localtime()) |
|
6 | 6 | delta = abs(utcnow - utcdatatime) # abs |
|
7 | 7 | if delta >= 30.: |
|
8 | 8 | return False |
|
9 | 9 | return True |
|
10 | 10 | |
|
11 | 11 | class CrossSpectraPlot(Figure): |
|
12 | 12 | |
|
13 | 13 | __isConfig = None |
|
14 | 14 | __nsubplots = None |
|
15 | 15 | |
|
16 | 16 | WIDTH = None |
|
17 | 17 | HEIGHT = None |
|
18 | 18 | WIDTHPROF = None |
|
19 | 19 | HEIGHTPROF = None |
|
20 | 20 | PREFIX = 'cspc' |
|
21 | 21 | |
|
22 | 22 | def __init__(self): |
|
23 | 23 | |
|
24 | 24 | self.__isConfig = False |
|
25 | 25 | self.__nsubplots = 4 |
|
26 | 26 | self.counter_imagwr = 0 |
|
27 | 27 | self.WIDTH = 250 |
|
28 | 28 | self.HEIGHT = 250 |
|
29 | 29 | self.WIDTHPROF = 0 |
|
30 | 30 | self.HEIGHTPROF = 0 |
|
31 | 31 | |
|
32 | 32 | self.PLOT_CODE = 1 |
|
33 | 33 | self.FTP_WEI = None |
|
34 | 34 | self.EXP_CODE = None |
|
35 | 35 | self.SUB_EXP_CODE = None |
|
36 | 36 | self.PLOT_POS = None |
|
37 | 37 | |
|
38 | 38 | def getSubplots(self): |
|
39 | 39 | |
|
40 | 40 | ncol = 4 |
|
41 | 41 | nrow = self.nplots |
|
42 | 42 | |
|
43 | 43 | return nrow, ncol |
|
44 | 44 | |
|
45 | 45 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
46 | 46 | |
|
47 | 47 | self.__showprofile = showprofile |
|
48 | 48 | self.nplots = nplots |
|
49 | 49 | |
|
50 | 50 | ncolspan = 1 |
|
51 | 51 | colspan = 1 |
|
52 | 52 | |
|
53 | 53 | self.createFigure(id = id, |
|
54 | 54 | wintitle = wintitle, |
|
55 | 55 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
56 | 56 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
57 | 57 | show=True) |
|
58 | 58 | |
|
59 | 59 | nrow, ncol = self.getSubplots() |
|
60 | 60 | |
|
61 | 61 | counter = 0 |
|
62 | 62 | for y in range(nrow): |
|
63 | 63 | for x in range(ncol): |
|
64 | 64 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
65 | 65 | |
|
66 | 66 | counter += 1 |
|
67 | 67 | |
|
68 | 68 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
69 | 69 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
70 | 70 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
71 | 71 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
72 | 72 | server=None, folder=None, username=None, password=None, |
|
73 | 73 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
74 | 74 | |
|
75 | 75 | """ |
|
76 | 76 | |
|
77 | 77 | Input: |
|
78 | 78 | dataOut : |
|
79 | 79 | id : |
|
80 | 80 | wintitle : |
|
81 | 81 | channelList : |
|
82 | 82 | showProfile : |
|
83 | 83 | xmin : None, |
|
84 | 84 | xmax : None, |
|
85 | 85 | ymin : None, |
|
86 | 86 | ymax : None, |
|
87 | 87 | zmin : None, |
|
88 | 88 | zmax : None |
|
89 | 89 | """ |
|
90 | 90 | |
|
91 | 91 | if pairsList == None: |
|
92 | 92 | pairsIndexList = dataOut.pairsIndexList |
|
93 | 93 | else: |
|
94 | 94 | pairsIndexList = [] |
|
95 | 95 | for pair in pairsList: |
|
96 | 96 | if pair not in dataOut.pairsList: |
|
97 | 97 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
98 | 98 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
99 | 99 | |
|
100 | 100 | if pairsIndexList == []: |
|
101 | 101 | return |
|
102 | 102 | |
|
103 | 103 | if len(pairsIndexList) > 4: |
|
104 | 104 | pairsIndexList = pairsIndexList[0:4] |
|
105 | 105 | factor = dataOut.normFactor |
|
106 | 106 | x = dataOut.getVelRange(1) |
|
107 | 107 | y = dataOut.getHeiRange() |
|
108 | 108 | z = dataOut.data_spc[:,:,:]/factor |
|
109 | 109 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
110 | 110 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
111 | 111 | noise = dataOut.getNoise()/factor |
|
112 | 112 | |
|
113 | 113 | zdB = 10*numpy.log10(z) |
|
114 | 114 | avgdB = 10*numpy.log10(avg) |
|
115 | 115 | noisedB = 10*numpy.log10(noise) |
|
116 | 116 | |
|
117 | 117 | |
|
118 | 118 | #thisDatetime = dataOut.datatime |
|
119 | 119 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
120 | 120 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
121 | 121 | xlabel = "Velocity (m/s)" |
|
122 | 122 | ylabel = "Range (Km)" |
|
123 | 123 | |
|
124 | 124 | if not self.__isConfig: |
|
125 | 125 | |
|
126 | 126 | nplots = len(pairsIndexList) |
|
127 | 127 | |
|
128 | 128 | self.setup(id=id, |
|
129 | 129 | nplots=nplots, |
|
130 | 130 | wintitle=wintitle, |
|
131 | 131 | showprofile=False, |
|
132 | 132 | show=show) |
|
133 | 133 | |
|
134 | 134 | if xmin == None: xmin = numpy.nanmin(x) |
|
135 | 135 | if xmax == None: xmax = numpy.nanmax(x) |
|
136 | 136 | if ymin == None: ymin = numpy.nanmin(y) |
|
137 | 137 | if ymax == None: ymax = numpy.nanmax(y) |
|
138 | 138 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
139 | 139 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
140 | 140 | |
|
141 | 141 | self.FTP_WEI = ftp_wei |
|
142 | 142 | self.EXP_CODE = exp_code |
|
143 | 143 | self.SUB_EXP_CODE = sub_exp_code |
|
144 | 144 | self.PLOT_POS = plot_pos |
|
145 | 145 | |
|
146 | 146 | self.__isConfig = True |
|
147 | 147 | |
|
148 | 148 | self.setWinTitle(title) |
|
149 | 149 | |
|
150 | 150 | for i in range(self.nplots): |
|
151 | 151 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
152 | 152 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
153 | 153 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
154 | 154 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
155 | 155 | axes0 = self.axesList[i*self.__nsubplots] |
|
156 | 156 | axes0.pcolor(x, y, zdB, |
|
157 | 157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
158 | 158 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
159 | 159 | ticksize=9, colormap=power_cmap, cblabel='') |
|
160 | 160 | |
|
161 | 161 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
162 | 162 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
163 | 163 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
164 | 164 | axes0.pcolor(x, y, zdB, |
|
165 | 165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
166 | 166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
167 | 167 | ticksize=9, colormap=power_cmap, cblabel='') |
|
168 | 168 | |
|
169 | 169 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
170 | 170 | coherence = numpy.abs(coherenceComplex) |
|
171 | 171 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
172 | 172 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
173 | 173 | |
|
174 | 174 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
175 | 175 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
176 | 176 | axes0.pcolor(x, y, coherence, |
|
177 | 177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
178 | 178 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
179 | 179 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
180 | 180 | |
|
181 | 181 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
182 | 182 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
183 | 183 | axes0.pcolor(x, y, phase, |
|
184 | 184 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
185 | 185 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
186 | 186 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
187 | 187 | |
|
188 | 188 | |
|
189 | 189 | |
|
190 | 190 | self.draw() |
|
191 | 191 | |
|
192 | 192 | if save: |
|
193 | 193 | |
|
194 | 194 | self.counter_imagwr += 1 |
|
195 | 195 | if (self.counter_imagwr==wr_period): |
|
196 | 196 | if figfile == None: |
|
197 | 197 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
198 | 198 | figfile = self.getFilename(name = str_datetime) |
|
199 | 199 | |
|
200 | 200 | self.saveFigure(figpath, figfile) |
|
201 | 201 | |
|
202 | 202 | if ftp: |
|
203 | 203 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
204 | 204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
205 | 205 | path = '%s%03d' %(self.PREFIX, self.id) |
|
206 | 206 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
207 | 207 | self.saveFigure(figpath, ftp_file) |
|
208 | 208 | ftp_filename = os.path.join(figpath,ftp_file) |
|
209 | 209 | |
|
210 | 210 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
211 | 211 | self.counter_imagwr = 0 |
|
212 | 212 | |
|
213 | 213 | self.counter_imagwr = 0 |
|
214 | 214 | |
|
215 | 215 | class SNRPlot(Figure): |
|
216 | 216 | |
|
217 | 217 | __isConfig = None |
|
218 | 218 | __nsubplots = None |
|
219 | 219 | |
|
220 | 220 | WIDTHPROF = None |
|
221 | 221 | HEIGHTPROF = None |
|
222 | 222 | PREFIX = 'snr' |
|
223 | 223 | |
|
224 | 224 | def __init__(self): |
|
225 | 225 | |
|
226 | 226 | self.timerange = 2*60*60 |
|
227 | 227 | self.__isConfig = False |
|
228 | 228 | self.__nsubplots = 1 |
|
229 | 229 | |
|
230 | 230 | self.WIDTH = 800 |
|
231 | 231 | self.HEIGHT = 150 |
|
232 | 232 | self.WIDTHPROF = 120 |
|
233 | 233 | self.HEIGHTPROF = 0 |
|
234 | 234 | self.counter_imagwr = 0 |
|
235 | 235 | |
|
236 | 236 | self.PLOT_CODE = 0 |
|
237 | 237 | self.FTP_WEI = None |
|
238 | 238 | self.EXP_CODE = None |
|
239 | 239 | self.SUB_EXP_CODE = None |
|
240 | 240 | self.PLOT_POS = None |
|
241 | 241 | |
|
242 | 242 | def getSubplots(self): |
|
243 | 243 | |
|
244 | 244 | ncol = 1 |
|
245 | 245 | nrow = self.nplots |
|
246 | 246 | |
|
247 | 247 | return nrow, ncol |
|
248 | 248 | |
|
249 | 249 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
250 | 250 | |
|
251 | 251 | self.__showprofile = showprofile |
|
252 | 252 | self.nplots = nplots |
|
253 | 253 | |
|
254 | 254 | ncolspan = 1 |
|
255 | 255 | colspan = 1 |
|
256 | 256 | if showprofile: |
|
257 | 257 | ncolspan = 7 |
|
258 | 258 | colspan = 6 |
|
259 | 259 | self.__nsubplots = 2 |
|
260 | 260 | |
|
261 | 261 | self.createFigure(id = id, |
|
262 | 262 | wintitle = wintitle, |
|
263 | 263 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
264 | 264 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
265 | 265 | show=show) |
|
266 | 266 | |
|
267 | 267 | nrow, ncol = self.getSubplots() |
|
268 | 268 | |
|
269 | 269 | counter = 0 |
|
270 | 270 | for y in range(nrow): |
|
271 | 271 | for x in range(ncol): |
|
272 | 272 | |
|
273 | 273 | if counter >= self.nplots: |
|
274 | 274 | break |
|
275 | 275 | |
|
276 | 276 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
277 | 277 | |
|
278 | 278 | if showprofile: |
|
279 | 279 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
280 | 280 | |
|
281 | 281 | counter += 1 |
|
282 | 282 | |
|
283 | 283 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
284 | 284 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
285 | 285 | timerange=None, |
|
286 | 286 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
287 | 287 | server=None, folder=None, username=None, password=None, |
|
288 | 288 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
289 | 289 | |
|
290 | 290 | """ |
|
291 | 291 | |
|
292 | 292 | Input: |
|
293 | 293 | dataOut : |
|
294 | 294 | id : |
|
295 | 295 | wintitle : |
|
296 | 296 | channelList : |
|
297 | 297 | showProfile : |
|
298 | 298 | xmin : None, |
|
299 | 299 | xmax : None, |
|
300 | 300 | ymin : None, |
|
301 | 301 | ymax : None, |
|
302 | 302 | zmin : None, |
|
303 | 303 | zmax : None |
|
304 | 304 | """ |
|
305 | 305 | |
|
306 | 306 | if channelList == None: |
|
307 | 307 | channelIndexList = dataOut.channelIndexList |
|
308 | 308 | else: |
|
309 | 309 | channelIndexList = [] |
|
310 | 310 | for channel in channelList: |
|
311 | 311 | if channel not in dataOut.channelList: |
|
312 | 312 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
313 | 313 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
314 | 314 | |
|
315 | 315 | if timerange != None: |
|
316 | 316 | self.timerange = timerange |
|
317 | 317 | |
|
318 | 318 | tmin = None |
|
319 | 319 | tmax = None |
|
320 | 320 | factor = dataOut.normFactor |
|
321 | 321 | x = dataOut.getTimeRange() |
|
322 | 322 | y = dataOut.getHeiRange() |
|
323 | 323 | |
|
324 | 324 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
325 | 325 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
326 | 326 | avg = numpy.average(z, axis=1) |
|
327 | 327 | |
|
328 | 328 | avgdB = 10.*numpy.log10(avg) |
|
329 | 329 | |
|
330 | 330 | noise = dataOut.getNoise()/factor |
|
331 | 331 | noisedB = 10.*numpy.log10(noise) |
|
332 | 332 | |
|
333 | 333 | SNR = numpy.transpose(numpy.divide(avg.T,noise)) |
|
334 | 334 | |
|
335 | 335 | SNR_dB = 10.*numpy.log10(SNR) |
|
336 | 336 | |
|
337 | 337 | #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB)) |
|
338 | 338 | |
|
339 | 339 | # thisDatetime = dataOut.datatime |
|
340 | 340 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
341 | 341 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
342 | 342 | xlabel = "" |
|
343 | 343 | ylabel = "Range (Km)" |
|
344 | 344 | |
|
345 | 345 | if not self.__isConfig: |
|
346 | 346 | |
|
347 | 347 | nplots = len(channelIndexList) |
|
348 | 348 | |
|
349 | 349 | self.setup(id=id, |
|
350 | 350 | nplots=nplots, |
|
351 | 351 | wintitle=wintitle, |
|
352 | 352 | showprofile=showprofile, |
|
353 | 353 | show=show) |
|
354 | 354 | |
|
355 | 355 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
356 | 356 | if ymin == None: ymin = numpy.nanmin(y) |
|
357 | 357 | if ymax == None: ymax = numpy.nanmax(y) |
|
358 | 358 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
359 | 359 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
360 | 360 | |
|
361 | 361 | self.FTP_WEI = ftp_wei |
|
362 | 362 | self.EXP_CODE = exp_code |
|
363 | 363 | self.SUB_EXP_CODE = sub_exp_code |
|
364 | 364 | self.PLOT_POS = plot_pos |
|
365 | 365 | |
|
366 | 366 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
367 | 367 | self.__isConfig = True |
|
368 | 368 | |
|
369 | 369 | |
|
370 | 370 | self.setWinTitle(title) |
|
371 | 371 | |
|
372 | 372 | for i in range(self.nplots): |
|
373 | 373 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
374 | 374 | axes = self.axesList[i*self.__nsubplots] |
|
375 | 375 | zdB = SNR_dB[i].reshape((1,-1)) |
|
376 | 376 | axes.pcolorbuffer(x, y, zdB, |
|
377 | 377 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
378 | 378 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
379 | 379 | ticksize=9, cblabel='', cbsize="1%") |
|
380 | 380 | |
|
381 | 381 | # if self.__showprofile: |
|
382 | 382 | # axes = self.axesList[i*self.__nsubplots +1] |
|
383 | 383 | # axes.pline(avgdB[i], y, |
|
384 | 384 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
385 | 385 | # xlabel='dB', ylabel='', title='', |
|
386 | 386 | # ytick_visible=False, |
|
387 | 387 | # grid='x') |
|
388 | 388 | # |
|
389 | 389 | self.draw() |
|
390 | 390 | |
|
391 | 391 | if lastone: |
|
392 | 392 | if dataOut.blocknow >= dataOut.last_block: |
|
393 | 393 | if figfile == None: |
|
394 | 394 | figfile = self.getFilename(name = self.name) |
|
395 | 395 | self.saveFigure(figpath, figfile) |
|
396 | 396 | |
|
397 | 397 | if (save and not(lastone)): |
|
398 | 398 | |
|
399 | 399 | self.counter_imagwr += 1 |
|
400 | 400 | if (self.counter_imagwr==wr_period): |
|
401 | 401 | if figfile == None: |
|
402 | 402 | figfile = self.getFilename(name = self.name) |
|
403 | 403 | self.saveFigure(figpath, figfile) |
|
404 | 404 | |
|
405 | 405 | if ftp: |
|
406 | 406 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
407 | 407 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
408 | 408 | path = '%s%03d' %(self.PREFIX, self.id) |
|
409 | 409 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
410 | 410 | self.saveFigure(figpath, ftp_file) |
|
411 | 411 | ftp_filename = os.path.join(figpath,ftp_file) |
|
412 | 412 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
413 | 413 | self.counter_imagwr = 0 |
|
414 | 414 | |
|
415 | 415 | self.counter_imagwr = 0 |
|
416 | 416 | |
|
417 | 417 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
418 | 418 | |
|
419 | 419 | self.__isConfig = False |
|
420 | 420 | |
|
421 | 421 | if lastone: |
|
422 | 422 | if figfile == None: |
|
423 | 423 | figfile = self.getFilename(name = self.name) |
|
424 | 424 | self.saveFigure(figpath, figfile) |
|
425 | 425 | |
|
426 | 426 | if ftp: |
|
427 | 427 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
428 | 428 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
429 | 429 | path = '%s%03d' %(self.PREFIX, self.id) |
|
430 | 430 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
431 | 431 | self.saveFigure(figpath, ftp_file) |
|
432 | 432 | ftp_filename = os.path.join(figpath,ftp_file) |
|
433 | 433 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
434 | 434 | |
|
435 | 435 | |
|
436 | 436 | class RTIPlot(Figure): |
|
437 | 437 | |
|
438 | 438 | __isConfig = None |
|
439 | 439 | __nsubplots = None |
|
440 | 440 | |
|
441 | 441 | WIDTHPROF = None |
|
442 | 442 | HEIGHTPROF = None |
|
443 | 443 | PREFIX = 'rti' |
|
444 | 444 | |
|
445 | 445 | def __init__(self): |
|
446 | 446 | |
|
447 | 447 | self.timerange = 2*60*60 |
|
448 | 448 | self.__isConfig = False |
|
449 | 449 | self.__nsubplots = 1 |
|
450 | 450 | |
|
451 | 451 | self.WIDTH = 800 |
|
452 | 452 | self.HEIGHT = 150 |
|
453 | 453 | self.WIDTHPROF = 120 |
|
454 | 454 | self.HEIGHTPROF = 0 |
|
455 | 455 | self.counter_imagwr = 0 |
|
456 | 456 | |
|
457 | 457 | self.PLOT_CODE = 0 |
|
458 | 458 | self.FTP_WEI = None |
|
459 | 459 | self.EXP_CODE = None |
|
460 | 460 | self.SUB_EXP_CODE = None |
|
461 | 461 | self.PLOT_POS = None |
|
462 | 462 | self.tmin = None |
|
463 | 463 | self.tmax = None |
|
464 | 464 | |
|
465 | 465 | self.xmin = None |
|
466 | 466 | self.xmax = None |
|
467 | 467 | |
|
468 | 468 | def getSubplots(self): |
|
469 | 469 | |
|
470 | 470 | ncol = 1 |
|
471 | 471 | nrow = self.nplots |
|
472 | 472 | |
|
473 | 473 | return nrow, ncol |
|
474 | 474 | |
|
475 | 475 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
476 | 476 | |
|
477 | 477 | self.__showprofile = showprofile |
|
478 | 478 | self.nplots = nplots |
|
479 | 479 | |
|
480 | 480 | ncolspan = 1 |
|
481 | 481 | colspan = 1 |
|
482 | 482 | if showprofile: |
|
483 | 483 | ncolspan = 7 |
|
484 | 484 | colspan = 6 |
|
485 | 485 | self.__nsubplots = 2 |
|
486 | 486 | |
|
487 | 487 | self.createFigure(id = id, |
|
488 | 488 | wintitle = wintitle, |
|
489 | 489 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
490 | 490 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
491 | 491 | show=show) |
|
492 | 492 | |
|
493 | 493 | nrow, ncol = self.getSubplots() |
|
494 | 494 | |
|
495 | 495 | counter = 0 |
|
496 | 496 | for y in range(nrow): |
|
497 | 497 | for x in range(ncol): |
|
498 | 498 | |
|
499 | 499 | if counter >= self.nplots: |
|
500 | 500 | break |
|
501 | 501 | |
|
502 | 502 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
503 | 503 | |
|
504 | 504 | if showprofile: |
|
505 | 505 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
506 | 506 | |
|
507 | 507 | counter += 1 |
|
508 | 508 | |
|
509 | 509 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
510 | 510 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
511 | 511 | timerange=None, |
|
512 | 512 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
513 | 513 | server=None, folder=None, username=None, password=None, |
|
514 | 514 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
515 | 515 | |
|
516 | 516 | """ |
|
517 | 517 | |
|
518 | 518 | Input: |
|
519 | 519 | dataOut : |
|
520 | 520 | id : |
|
521 | 521 | wintitle : |
|
522 | 522 | channelList : |
|
523 | 523 | showProfile : |
|
524 | 524 | xmin : None, |
|
525 | 525 | xmax : None, |
|
526 | 526 | ymin : None, |
|
527 | 527 | ymax : None, |
|
528 | 528 | zmin : None, |
|
529 | 529 | zmax : None |
|
530 | 530 | """ |
|
531 | 531 | |
|
532 | 532 | if channelList == None: |
|
533 | 533 | channelIndexList = dataOut.channelIndexList |
|
534 | 534 | else: |
|
535 | 535 | channelIndexList = [] |
|
536 | 536 | for channel in channelList: |
|
537 | 537 | if channel not in dataOut.channelList: |
|
538 | 538 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
539 | 539 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
540 | 540 | |
|
541 | 541 | if timerange != None: |
|
542 | 542 | self.timerange = timerange |
|
543 | 543 | |
|
544 | 544 | #tmin = None |
|
545 | 545 | #tmax = None |
|
546 | 546 | factor = dataOut.normFactor |
|
547 | 547 | x = dataOut.getTimeRange() |
|
548 | 548 | y = dataOut.getHeiRange() |
|
549 | 549 | |
|
550 | 550 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
551 | 551 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
552 | 552 | avg = numpy.average(z, axis=1) |
|
553 | 553 | |
|
554 | 554 | avgdB = 10.*numpy.log10(avg) |
|
555 | 555 | |
|
556 | 556 | |
|
557 | 557 | # thisDatetime = dataOut.datatime |
|
558 | 558 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
559 | 559 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
560 | 560 | xlabel = "" |
|
561 | 561 | ylabel = "Range (Km)" |
|
562 | 562 | |
|
563 | 563 | if not self.__isConfig: |
|
564 | 564 | |
|
565 | 565 | nplots = len(channelIndexList) |
|
566 | 566 | |
|
567 | 567 | self.setup(id=id, |
|
568 | 568 | nplots=nplots, |
|
569 | 569 | wintitle=wintitle, |
|
570 | 570 | showprofile=showprofile, |
|
571 | 571 | show=show) |
|
572 | 572 | |
|
573 | 573 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
574 | 574 | |
|
575 | 575 | # if timerange != None: |
|
576 | 576 | # self.timerange = timerange |
|
577 | 577 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
578 | 578 | |
|
579 | 579 | |
|
580 | 580 | |
|
581 | 581 | if ymin == None: ymin = numpy.nanmin(y) |
|
582 | 582 | if ymax == None: ymax = numpy.nanmax(y) |
|
583 | 583 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
584 | 584 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
585 | 585 | |
|
586 | 586 | self.FTP_WEI = ftp_wei |
|
587 | 587 | self.EXP_CODE = exp_code |
|
588 | 588 | self.SUB_EXP_CODE = sub_exp_code |
|
589 | 589 | self.PLOT_POS = plot_pos |
|
590 | 590 | |
|
591 | 591 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
592 | 592 | self.__isConfig = True |
|
593 | 593 | |
|
594 | 594 | |
|
595 | 595 | self.setWinTitle(title) |
|
596 | 596 | |
|
597 | 597 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
598 | 598 | x[1] = self.xmax |
|
599 | 599 | |
|
600 | 600 | for i in range(self.nplots): |
|
601 | 601 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
602 | 602 | axes = self.axesList[i*self.__nsubplots] |
|
603 | 603 | zdB = avgdB[i].reshape((1,-1)) |
|
604 | 604 | axes.pcolorbuffer(x, y, zdB, |
|
605 | 605 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
606 | 606 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
607 | 607 | ticksize=9, cblabel='', cbsize="1%") |
|
608 | 608 | |
|
609 | 609 | if self.__showprofile: |
|
610 | 610 | axes = self.axesList[i*self.__nsubplots +1] |
|
611 | 611 | axes.pline(avgdB[i], y, |
|
612 | 612 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
613 | 613 | xlabel='dB', ylabel='', title='', |
|
614 | 614 | ytick_visible=False, |
|
615 | 615 | grid='x') |
|
616 | 616 | |
|
617 | 617 | self.draw() |
|
618 | 618 | |
|
619 | 619 | # if lastone: |
|
620 | 620 | # if dataOut.blocknow >= dataOut.last_block: |
|
621 | 621 | # if figfile == None: |
|
622 | 622 | # figfile = self.getFilename(name = self.name) |
|
623 | 623 | # self.saveFigure(figpath, figfile) |
|
624 | 624 | # |
|
625 | 625 | # if (save and not(lastone)): |
|
626 | 626 | # |
|
627 | 627 | # self.counter_imagwr += 1 |
|
628 | 628 | # if (self.counter_imagwr==wr_period): |
|
629 | 629 | # if figfile == None: |
|
630 | 630 | # figfile = self.getFilename(name = self.name) |
|
631 | 631 | # self.saveFigure(figpath, figfile) |
|
632 | 632 | # |
|
633 | 633 | # if ftp: |
|
634 | 634 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
635 | 635 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
636 | 636 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
637 | 637 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
638 | 638 | # self.saveFigure(figpath, ftp_file) |
|
639 | 639 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
640 | 640 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
641 | 641 | # self.counter_imagwr = 0 |
|
642 | 642 | # |
|
643 | 643 | # self.counter_imagwr = 0 |
|
644 | 644 | |
|
645 | 645 | #if ((dataOut.utctime-time.timezone) >= self.axesList[0].xmax): |
|
646 | 646 | if x[1] >= self.axesList[0].xmax: |
|
647 | 647 | self.saveFigure(figpath, figfile) |
|
648 | 648 | self.__isConfig = False |
|
649 | 649 | |
|
650 | 650 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
651 | 651 | # |
|
652 | 652 | # self.__isConfig = False |
|
653 | 653 | |
|
654 | 654 | # if lastone: |
|
655 | 655 | # if figfile == None: |
|
656 | 656 | # figfile = self.getFilename(name = self.name) |
|
657 | 657 | # self.saveFigure(figpath, figfile) |
|
658 | 658 | # |
|
659 | 659 | # if ftp: |
|
660 | 660 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
661 | 661 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
662 | 662 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
663 | 663 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
664 | 664 | # self.saveFigure(figpath, ftp_file) |
|
665 | 665 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
666 | 666 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
667 | 667 | |
|
668 | 668 | |
|
669 | 669 | class SpectraPlot(Figure): |
|
670 | 670 | |
|
671 | 671 | __isConfig = None |
|
672 | 672 | __nsubplots = None |
|
673 | 673 | |
|
674 | 674 | WIDTHPROF = None |
|
675 | 675 | HEIGHTPROF = None |
|
676 | 676 | PREFIX = 'spc' |
|
677 | 677 | |
|
678 | 678 | def __init__(self): |
|
679 | 679 | |
|
680 | 680 | self.__isConfig = False |
|
681 | 681 | self.__nsubplots = 1 |
|
682 | 682 | |
|
683 | 683 | self.WIDTH = 280 |
|
684 | 684 | self.HEIGHT = 250 |
|
685 | 685 | self.WIDTHPROF = 120 |
|
686 | 686 | self.HEIGHTPROF = 0 |
|
687 | 687 | self.counter_imagwr = 0 |
|
688 | 688 | |
|
689 | 689 | self.PLOT_CODE = 1 |
|
690 | 690 | self.FTP_WEI = None |
|
691 | 691 | self.EXP_CODE = None |
|
692 | 692 | self.SUB_EXP_CODE = None |
|
693 | 693 | self.PLOT_POS = None |
|
694 | 694 | |
|
695 | 695 | def getSubplots(self): |
|
696 | 696 | |
|
697 | 697 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
698 | 698 | nrow = int(self.nplots*1./ncol + 0.9) |
|
699 | 699 | |
|
700 | 700 | return nrow, ncol |
|
701 | 701 | |
|
702 | 702 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
703 | 703 | |
|
704 | 704 | self.__showprofile = showprofile |
|
705 | 705 | self.nplots = nplots |
|
706 | 706 | |
|
707 | 707 | ncolspan = 1 |
|
708 | 708 | colspan = 1 |
|
709 | 709 | if showprofile: |
|
710 | 710 | ncolspan = 3 |
|
711 | 711 | colspan = 2 |
|
712 | 712 | self.__nsubplots = 2 |
|
713 | 713 | |
|
714 | 714 | self.createFigure(id = id, |
|
715 | 715 | wintitle = wintitle, |
|
716 | 716 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
717 | 717 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
718 | 718 | show=show) |
|
719 | 719 | |
|
720 | 720 | nrow, ncol = self.getSubplots() |
|
721 | 721 | |
|
722 | 722 | counter = 0 |
|
723 | 723 | for y in range(nrow): |
|
724 | 724 | for x in range(ncol): |
|
725 | 725 | |
|
726 | 726 | if counter >= self.nplots: |
|
727 | 727 | break |
|
728 | 728 | |
|
729 | 729 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
730 | 730 | |
|
731 | 731 | if showprofile: |
|
732 | 732 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
733 | 733 | |
|
734 | 734 | counter += 1 |
|
735 | 735 | |
|
736 | 736 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
737 | 737 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
738 | 738 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
739 | 739 | server=None, folder=None, username=None, password=None, |
|
740 | 740 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
741 | 741 | |
|
742 | 742 | """ |
|
743 | 743 | |
|
744 | 744 | Input: |
|
745 | 745 | dataOut : |
|
746 | 746 | id : |
|
747 | 747 | wintitle : |
|
748 | 748 | channelList : |
|
749 | 749 | showProfile : |
|
750 | 750 | xmin : None, |
|
751 | 751 | xmax : None, |
|
752 | 752 | ymin : None, |
|
753 | 753 | ymax : None, |
|
754 | 754 | zmin : None, |
|
755 | 755 | zmax : None |
|
756 | 756 | """ |
|
757 | 757 | |
|
758 | 758 | if realtime: |
|
759 | 759 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
760 | 760 | print 'Skipping this plot function' |
|
761 | 761 | return |
|
762 | 762 | |
|
763 | 763 | if channelList == None: |
|
764 | 764 | channelIndexList = dataOut.channelIndexList |
|
765 | 765 | else: |
|
766 | 766 | channelIndexList = [] |
|
767 | 767 | for channel in channelList: |
|
768 | 768 | if channel not in dataOut.channelList: |
|
769 | 769 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
770 | 770 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
771 | 771 | factor = dataOut.normFactor |
|
772 | 772 | x = dataOut.getVelRange(1) |
|
773 | 773 | y = dataOut.getHeiRange() |
|
774 | 774 | |
|
775 | 775 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
776 | 776 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
777 | 777 | avg = numpy.average(z, axis=1) |
|
778 | 778 | noise = dataOut.getNoise()/factor |
|
779 | 779 | |
|
780 | 780 | zdB = 10*numpy.log10(z) |
|
781 | 781 | avgdB = 10*numpy.log10(avg) |
|
782 | 782 | noisedB = 10*numpy.log10(noise) |
|
783 | 783 | |
|
784 | 784 | #thisDatetime = dataOut.datatime |
|
785 | 785 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
786 | 786 | title = wintitle + " Spectra" |
|
787 | 787 | xlabel = "Velocity (m/s)" |
|
788 | 788 | ylabel = "Range (Km)" |
|
789 | 789 | |
|
790 | 790 | if not self.__isConfig: |
|
791 | 791 | |
|
792 | 792 | nplots = len(channelIndexList) |
|
793 | 793 | |
|
794 | 794 | self.setup(id=id, |
|
795 | 795 | nplots=nplots, |
|
796 | 796 | wintitle=wintitle, |
|
797 | 797 | showprofile=showprofile, |
|
798 | 798 | show=show) |
|
799 | 799 | |
|
800 | 800 | if xmin == None: xmin = numpy.nanmin(x) |
|
801 | 801 | if xmax == None: xmax = numpy.nanmax(x) |
|
802 | 802 | if ymin == None: ymin = numpy.nanmin(y) |
|
803 | 803 | if ymax == None: ymax = numpy.nanmax(y) |
|
804 | 804 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
805 | 805 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
806 | 806 | |
|
807 | 807 | self.FTP_WEI = ftp_wei |
|
808 | 808 | self.EXP_CODE = exp_code |
|
809 | 809 | self.SUB_EXP_CODE = sub_exp_code |
|
810 | 810 | self.PLOT_POS = plot_pos |
|
811 | 811 | |
|
812 | 812 | self.__isConfig = True |
|
813 | 813 | |
|
814 | 814 | self.setWinTitle(title) |
|
815 | 815 | |
|
816 | 816 | for i in range(self.nplots): |
|
817 | 817 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
818 | 818 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
819 | 819 | axes = self.axesList[i*self.__nsubplots] |
|
820 | 820 | axes.pcolor(x, y, zdB[i,:,:], |
|
821 | 821 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
822 | 822 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
823 | 823 | ticksize=9, cblabel='') |
|
824 | 824 | |
|
825 | 825 | if self.__showprofile: |
|
826 | 826 | axes = self.axesList[i*self.__nsubplots +1] |
|
827 | 827 | axes.pline(avgdB[i], y, |
|
828 | 828 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
829 | 829 | xlabel='dB', ylabel='', title='', |
|
830 | 830 | ytick_visible=False, |
|
831 | 831 | grid='x') |
|
832 | 832 | |
|
833 | 833 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
834 | 834 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
835 | 835 | |
|
836 | 836 | self.draw() |
|
837 | 837 | |
|
838 | 838 | if save: |
|
839 | 839 | |
|
840 | 840 | self.counter_imagwr += 1 |
|
841 | 841 | if (self.counter_imagwr==wr_period): |
|
842 | 842 | if figfile == None: |
|
843 | 843 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
844 | 844 | figfile = self.getFilename(name = str_datetime) |
|
845 | 845 | |
|
846 | 846 | self.saveFigure(figpath, figfile) |
|
847 | 847 | |
|
848 | 848 | if ftp: |
|
849 | 849 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
850 | 850 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
851 | 851 | path = '%s%03d' %(self.PREFIX, self.id) |
|
852 | 852 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
853 | 853 | self.saveFigure(figpath, ftp_file) |
|
854 | 854 | ftp_filename = os.path.join(figpath,ftp_file) |
|
855 | 855 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
856 | 856 | self.counter_imagwr = 0 |
|
857 | 857 | |
|
858 | 858 | |
|
859 | 859 | self.counter_imagwr = 0 |
|
860 | 860 | |
|
861 | 861 | |
|
862 | 862 | class Scope(Figure): |
|
863 | 863 | |
|
864 | 864 | __isConfig = None |
|
865 | 865 | |
|
866 | 866 | def __init__(self): |
|
867 | 867 | |
|
868 | 868 | self.__isConfig = False |
|
869 |
self.WIDTH = |
|
|
869 | self.WIDTH = 300 | |
|
870 | 870 | self.HEIGHT = 200 |
|
871 | 871 | self.counter_imagwr = 0 |
|
872 | 872 | |
|
873 | 873 | def getSubplots(self): |
|
874 | 874 | |
|
875 | 875 | nrow = self.nplots |
|
876 | 876 | ncol = 3 |
|
877 | 877 | return nrow, ncol |
|
878 | 878 | |
|
879 | 879 | def setup(self, id, nplots, wintitle, show): |
|
880 | 880 | |
|
881 | 881 | self.nplots = nplots |
|
882 | 882 | |
|
883 | 883 | self.createFigure(id=id, |
|
884 | 884 | wintitle=wintitle, |
|
885 | 885 | show=show) |
|
886 | 886 | |
|
887 | 887 | nrow,ncol = self.getSubplots() |
|
888 | 888 | colspan = 3 |
|
889 | 889 | rowspan = 1 |
|
890 | 890 | |
|
891 | 891 | for i in range(nplots): |
|
892 | 892 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
893 | ||
|
894 | def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): | |
|
895 | yreal = y[channelIndexList,:].real | |
|
896 | yimag = y[channelIndexList,:].imag | |
|
897 | ||
|
898 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
899 | xlabel = "Range (Km)" | |
|
900 | ylabel = "Intensity - IQ" | |
|
901 | ||
|
902 | if not self.__isConfig: | |
|
903 | nplots = len(channelIndexList) | |
|
893 | 904 | |
|
905 | self.setup(id=id, | |
|
906 | nplots=nplots, | |
|
907 | wintitle='', | |
|
908 | show=show) | |
|
909 | ||
|
910 | if xmin == None: xmin = numpy.nanmin(x) | |
|
911 | if xmax == None: xmax = numpy.nanmax(x) | |
|
912 | if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag)) | |
|
913 | if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag)) | |
|
914 | ||
|
915 | self.__isConfig = True | |
|
916 | ||
|
917 | self.setWinTitle(title) | |
|
918 | ||
|
919 | for i in range(len(self.axesList)): | |
|
920 | title = "Channel %d" %(i) | |
|
921 | axes = self.axesList[i] | |
|
922 | ||
|
923 | axes.pline(x, yreal[i,:], | |
|
924 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
|
925 | xlabel=xlabel, ylabel=ylabel, title=title) | |
|
926 | ||
|
927 | axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2) | |
|
928 | ||
|
929 | def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): | |
|
930 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) | |
|
931 | yreal = y.real | |
|
932 | ||
|
933 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
934 | xlabel = "Range (Km)" | |
|
935 | ylabel = "Intensity" | |
|
936 | ||
|
937 | if not self.__isConfig: | |
|
938 | nplots = len(channelIndexList) | |
|
939 | ||
|
940 | self.setup(id=id, | |
|
941 | nplots=nplots, | |
|
942 | wintitle='', | |
|
943 | show=show) | |
|
944 | ||
|
945 | if xmin == None: xmin = numpy.nanmin(x) | |
|
946 | if xmax == None: xmax = numpy.nanmax(x) | |
|
947 | if ymin == None: ymin = numpy.nanmin(yreal) | |
|
948 | if ymax == None: ymax = numpy.nanmax(yreal) | |
|
949 | ||
|
950 | self.__isConfig = True | |
|
951 | ||
|
952 | self.setWinTitle(title) | |
|
894 | 953 | |
|
954 | for i in range(len(self.axesList)): | |
|
955 | title = "Channel %d" %(i) | |
|
956 | axes = self.axesList[i] | |
|
957 | ychannel = yreal[i,:] | |
|
958 | axes.pline(x, ychannel, | |
|
959 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
|
960 | xlabel=xlabel, ylabel=ylabel, title=title) | |
|
961 | ||
|
895 | 962 | |
|
896 | 963 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
897 | 964 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
898 | 965 | figpath='./', figfile=None, show=True, wr_period=1, |
|
899 | server=None, folder=None, username=None, password=None): | |
|
966 | server=None, folder=None, username=None, password=None, type='power'): | |
|
900 | 967 | |
|
901 | 968 | """ |
|
902 | 969 | |
|
903 | 970 | Input: |
|
904 | 971 | dataOut : |
|
905 | 972 | id : |
|
906 | 973 | wintitle : |
|
907 | 974 | channelList : |
|
908 | 975 | xmin : None, |
|
909 | 976 | xmax : None, |
|
910 | 977 | ymin : None, |
|
911 | 978 | ymax : None, |
|
912 | 979 | """ |
|
913 | 980 | |
|
914 | 981 | if channelList == None: |
|
915 | 982 | channelIndexList = dataOut.channelIndexList |
|
916 | 983 | else: |
|
917 | 984 | channelIndexList = [] |
|
918 | 985 | for channel in channelList: |
|
919 | 986 | if channel not in dataOut.channelList: |
|
920 | 987 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
921 | 988 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
922 | 989 | |
|
923 | 990 | x = dataOut.heightList |
|
924 | 991 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
925 | 992 | y = y.real |
|
926 | 993 | |
|
927 | #thisDatetime = dataOut.datatime | |
|
928 | 994 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
929 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
930 | xlabel = "Range (Km)" | |
|
931 | ylabel = "Intensity" | |
|
932 | 995 | |
|
933 | if not self.__isConfig: | |
|
934 | nplots = len(channelIndexList) | |
|
935 | ||
|
936 | self.setup(id=id, | |
|
937 |
|
|
|
938 |
|
|
|
939 |
|
|
|
940 | ||
|
941 | if xmin == None: xmin = numpy.nanmin(x) | |
|
942 | if xmax == None: xmax = numpy.nanmax(x) | |
|
943 | if ymin == None: ymin = numpy.nanmin(y) | |
|
944 | if ymax == None: ymax = numpy.nanmax(y) | |
|
945 |
|
|
|
946 | self.__isConfig = True | |
|
947 | ||
|
948 | self.setWinTitle(title) | |
|
996 | if type == "power": | |
|
997 | self.plot_power(dataOut.heightList, | |
|
998 | dataOut.data, | |
|
999 | id, | |
|
1000 | channelIndexList, | |
|
1001 | thisDatetime, | |
|
1002 | wintitle, | |
|
1003 | show, | |
|
1004 | xmin, | |
|
1005 | xmax, | |
|
1006 | ymin, | |
|
1007 | ymax) | |
|
1008 | ||
|
1009 | if type == "iq": | |
|
1010 | self.plot_iq(dataOut.heightList, | |
|
1011 | dataOut.data, | |
|
1012 | id, | |
|
1013 | channelIndexList, | |
|
1014 | thisDatetime, | |
|
1015 | wintitle, | |
|
1016 | show, | |
|
1017 | xmin, | |
|
1018 | xmax, | |
|
1019 | ymin, | |
|
1020 | ymax) | |
|
949 | 1021 | |
|
950 | for i in range(len(self.axesList)): | |
|
951 | title = "Channel %d" %(i) | |
|
952 | axes = self.axesList[i] | |
|
953 | ychannel = y[i,:] | |
|
954 | axes.pline(x, ychannel, | |
|
955 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
|
956 | xlabel=xlabel, ylabel=ylabel, title=title) | |
|
957 | 1022 | |
|
958 | 1023 | self.draw() |
|
959 | 1024 | |
|
960 | 1025 | if save: |
|
961 | 1026 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
962 | 1027 | if figfile == None: |
|
963 | 1028 | figfile = self.getFilename(name = date) |
|
964 | 1029 | |
|
965 | 1030 | self.saveFigure(figpath, figfile) |
|
966 | 1031 | |
|
967 | 1032 | self.counter_imagwr += 1 |
|
968 | 1033 | if (ftp and (self.counter_imagwr==wr_period)): |
|
969 | 1034 | ftp_filename = os.path.join(figpath,figfile) |
|
970 | 1035 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
971 | 1036 | self.counter_imagwr = 0 |
|
972 | 1037 | |
|
973 |
class PowerProfile |
|
|
1038 | class PowerProfile(Figure): | |
|
974 | 1039 | __isConfig = None |
|
975 | 1040 | __nsubplots = None |
|
976 | 1041 | |
|
977 | 1042 | WIDTHPROF = None |
|
978 | 1043 | HEIGHTPROF = None |
|
979 | 1044 | PREFIX = 'spcprofile' |
|
980 | 1045 | |
|
981 | 1046 | def __init__(self): |
|
982 | 1047 | self.__isConfig = False |
|
983 | 1048 | self.__nsubplots = 1 |
|
984 | 1049 | |
|
985 | 1050 | self.WIDTH = 300 |
|
986 | 1051 | self.HEIGHT = 500 |
|
987 | 1052 | self.counter_imagwr = 0 |
|
988 | 1053 | |
|
989 | 1054 | def getSubplots(self): |
|
990 | 1055 | ncol = 1 |
|
991 | 1056 | nrow = 1 |
|
992 | 1057 | |
|
993 | 1058 | return nrow, ncol |
|
994 | 1059 | |
|
995 | 1060 | def setup(self, id, nplots, wintitle, show): |
|
996 | 1061 | |
|
997 | 1062 | self.nplots = nplots |
|
998 | 1063 | |
|
999 | 1064 | ncolspan = 1 |
|
1000 | 1065 | colspan = 1 |
|
1001 | 1066 | |
|
1002 | 1067 | self.createFigure(id = id, |
|
1003 | 1068 | wintitle = wintitle, |
|
1004 | 1069 | widthplot = self.WIDTH, |
|
1005 | 1070 | heightplot = self.HEIGHT, |
|
1006 | 1071 | show=show) |
|
1007 | 1072 | |
|
1008 | 1073 | nrow, ncol = self.getSubplots() |
|
1009 | 1074 | |
|
1010 | 1075 | counter = 0 |
|
1011 | 1076 | for y in range(nrow): |
|
1012 | 1077 | for x in range(ncol): |
|
1013 | 1078 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1014 | 1079 | |
|
1015 | 1080 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1016 | 1081 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1017 | 1082 | save=False, figpath='./', figfile=None, show=True, wr_period=1, |
|
1018 | 1083 | server=None, folder=None, username=None, password=None,): |
|
1019 | 1084 | |
|
1020 | 1085 | if channelList == None: |
|
1021 | 1086 | channelIndexList = dataOut.channelIndexList |
|
1022 | 1087 | channelList = dataOut.channelList |
|
1023 | 1088 | else: |
|
1024 | 1089 | channelIndexList = [] |
|
1025 | 1090 | for channel in channelList: |
|
1026 | 1091 | if channel not in dataOut.channelList: |
|
1027 | 1092 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1028 | 1093 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1029 | 1094 | |
|
1030 | factor = dataOut.normFactor | |
|
1031 | y = dataOut.getHeiRange() | |
|
1032 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
|
1033 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
|
1034 | avg = numpy.average(x, axis=1) | |
|
1095 | try: | |
|
1096 | factor = dataOut.normFactor | |
|
1097 | except: | |
|
1098 | factor = 1 | |
|
1035 | 1099 | |
|
1036 | avgdB = 10*numpy.log10(avg) | |
|
1100 | y = dataOut.getHeiRange() | |
|
1101 | ||
|
1102 | #for voltage | |
|
1103 | if dataOut.type == 'Voltage': | |
|
1104 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
|
1105 | x = x.real | |
|
1106 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
|
1107 | ||
|
1108 | #for spectra | |
|
1109 | if dataOut.type == 'Spectra': | |
|
1110 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
|
1111 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
|
1112 | x = numpy.average(x, axis=1) | |
|
1113 | ||
|
1114 | ||
|
1115 | xdB = 10*numpy.log10(x) | |
|
1037 | 1116 | |
|
1038 | #thisDatetime = dataOut.datatime | |
|
1039 | 1117 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1040 | 1118 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1041 | 1119 | xlabel = "dB" |
|
1042 | 1120 | ylabel = "Range (Km)" |
|
1043 | 1121 | |
|
1044 | 1122 | if not self.__isConfig: |
|
1045 | 1123 | |
|
1046 | 1124 | nplots = 1 |
|
1047 | 1125 | |
|
1048 | 1126 | self.setup(id=id, |
|
1049 | 1127 | nplots=nplots, |
|
1050 | 1128 | wintitle=wintitle, |
|
1051 | 1129 | show=show) |
|
1052 | 1130 | |
|
1053 | 1131 | if ymin == None: ymin = numpy.nanmin(y) |
|
1054 | 1132 | if ymax == None: ymax = numpy.nanmax(y) |
|
1055 |
if xmin == None: xmin = numpy.nanmin( |
|
|
1056 |
if xmax == None: xmax = numpy.nanmax( |
|
|
1133 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 | |
|
1134 | if xmax == None: xmax = numpy.nanmax(xdB)*0.9 | |
|
1057 | 1135 | |
|
1058 | 1136 | self.__isConfig = True |
|
1059 | 1137 | |
|
1060 | 1138 | self.setWinTitle(title) |
|
1061 | 1139 | |
|
1062 | ||
|
1063 | 1140 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1064 | 1141 | axes = self.axesList[0] |
|
1065 | 1142 | |
|
1066 | 1143 | legendlabels = ["channel %d"%x for x in channelList] |
|
1067 |
axes.pmultiline( |
|
|
1144 | axes.pmultiline(xdB, y, | |
|
1068 | 1145 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1069 | 1146 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1070 | 1147 | ytick_visible=True, nxticks=5, |
|
1071 | 1148 | grid='x') |
|
1072 | 1149 | |
|
1073 | 1150 | self.draw() |
|
1074 | 1151 | |
|
1075 | 1152 | if save: |
|
1076 | 1153 | date = thisDatetime.strftime("%Y%m%d") |
|
1077 | 1154 | if figfile == None: |
|
1078 | 1155 | figfile = self.getFilename(name = date) |
|
1079 | 1156 | |
|
1080 | 1157 | self.saveFigure(figpath, figfile) |
|
1081 | 1158 | |
|
1082 | 1159 | self.counter_imagwr += 1 |
|
1083 | 1160 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1084 | 1161 | ftp_filename = os.path.join(figpath,figfile) |
|
1085 | 1162 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1086 | 1163 | self.counter_imagwr = 0 |
|
1087 | 1164 | |
|
1088 | 1165 | class CoherenceMap(Figure): |
|
1089 | 1166 | __isConfig = None |
|
1090 | 1167 | __nsubplots = None |
|
1091 | 1168 | |
|
1092 | 1169 | WIDTHPROF = None |
|
1093 | 1170 | HEIGHTPROF = None |
|
1094 | 1171 | PREFIX = 'cmap' |
|
1095 | 1172 | |
|
1096 | 1173 | def __init__(self): |
|
1097 | 1174 | self.timerange = 2*60*60 |
|
1098 | 1175 | self.__isConfig = False |
|
1099 | 1176 | self.__nsubplots = 1 |
|
1100 | 1177 | |
|
1101 | 1178 | self.WIDTH = 800 |
|
1102 | 1179 | self.HEIGHT = 150 |
|
1103 | 1180 | self.WIDTHPROF = 120 |
|
1104 | 1181 | self.HEIGHTPROF = 0 |
|
1105 | 1182 | self.counter_imagwr = 0 |
|
1106 | 1183 | |
|
1107 | 1184 | self.PLOT_CODE = 3 |
|
1108 | 1185 | self.FTP_WEI = None |
|
1109 | 1186 | self.EXP_CODE = None |
|
1110 | 1187 | self.SUB_EXP_CODE = None |
|
1111 | 1188 | self.PLOT_POS = None |
|
1112 | 1189 | self.counter_imagwr = 0 |
|
1113 | 1190 | |
|
1114 | 1191 | self.xmin = None |
|
1115 | 1192 | self.xmax = None |
|
1116 | 1193 | |
|
1117 | 1194 | def getSubplots(self): |
|
1118 | 1195 | ncol = 1 |
|
1119 | 1196 | nrow = self.nplots*2 |
|
1120 | 1197 | |
|
1121 | 1198 | return nrow, ncol |
|
1122 | 1199 | |
|
1123 | 1200 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1124 | 1201 | self.__showprofile = showprofile |
|
1125 | 1202 | self.nplots = nplots |
|
1126 | 1203 | |
|
1127 | 1204 | ncolspan = 1 |
|
1128 | 1205 | colspan = 1 |
|
1129 | 1206 | if showprofile: |
|
1130 | 1207 | ncolspan = 7 |
|
1131 | 1208 | colspan = 6 |
|
1132 | 1209 | self.__nsubplots = 2 |
|
1133 | 1210 | |
|
1134 | 1211 | self.createFigure(id = id, |
|
1135 | 1212 | wintitle = wintitle, |
|
1136 | 1213 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1137 | 1214 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1138 | 1215 | show=True) |
|
1139 | 1216 | |
|
1140 | 1217 | nrow, ncol = self.getSubplots() |
|
1141 | 1218 | |
|
1142 | 1219 | for y in range(nrow): |
|
1143 | 1220 | for x in range(ncol): |
|
1144 | 1221 | |
|
1145 | 1222 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1146 | 1223 | |
|
1147 | 1224 | if showprofile: |
|
1148 | 1225 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1149 | 1226 | |
|
1150 | 1227 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1151 | 1228 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1152 | 1229 | timerange=None, |
|
1153 | 1230 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
1154 | 1231 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
1155 | 1232 | server=None, folder=None, username=None, password=None, |
|
1156 | 1233 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1157 | 1234 | |
|
1158 | 1235 | if pairsList == None: |
|
1159 | 1236 | pairsIndexList = dataOut.pairsIndexList |
|
1160 | 1237 | else: |
|
1161 | 1238 | pairsIndexList = [] |
|
1162 | 1239 | for pair in pairsList: |
|
1163 | 1240 | if pair not in dataOut.pairsList: |
|
1164 | 1241 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1165 | 1242 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1166 | 1243 | |
|
1167 | 1244 | if timerange != None: |
|
1168 | 1245 | self.timerange = timerange |
|
1169 | 1246 | |
|
1170 | 1247 | if pairsIndexList == []: |
|
1171 | 1248 | return |
|
1172 | 1249 | |
|
1173 | 1250 | if len(pairsIndexList) > 4: |
|
1174 | 1251 | pairsIndexList = pairsIndexList[0:4] |
|
1175 | 1252 | |
|
1176 | 1253 | # tmin = None |
|
1177 | 1254 | # tmax = None |
|
1178 | 1255 | x = dataOut.getTimeRange() |
|
1179 | 1256 | y = dataOut.getHeiRange() |
|
1180 | 1257 | |
|
1181 | 1258 | #thisDatetime = dataOut.datatime |
|
1182 | 1259 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1183 | 1260 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1184 | 1261 | xlabel = "" |
|
1185 | 1262 | ylabel = "Range (Km)" |
|
1186 | 1263 | |
|
1187 | 1264 | if not self.__isConfig: |
|
1188 | 1265 | nplots = len(pairsIndexList) |
|
1189 | 1266 | self.setup(id=id, |
|
1190 | 1267 | nplots=nplots, |
|
1191 | 1268 | wintitle=wintitle, |
|
1192 | 1269 | showprofile=showprofile, |
|
1193 | 1270 | show=show) |
|
1194 | 1271 | |
|
1195 | 1272 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1196 | 1273 | |
|
1197 | 1274 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1198 | 1275 | |
|
1199 | 1276 | if ymin == None: ymin = numpy.nanmin(y) |
|
1200 | 1277 | if ymax == None: ymax = numpy.nanmax(y) |
|
1201 | 1278 | if zmin == None: zmin = 0. |
|
1202 | 1279 | if zmax == None: zmax = 1. |
|
1203 | 1280 | |
|
1204 | 1281 | self.FTP_WEI = ftp_wei |
|
1205 | 1282 | self.EXP_CODE = exp_code |
|
1206 | 1283 | self.SUB_EXP_CODE = sub_exp_code |
|
1207 | 1284 | self.PLOT_POS = plot_pos |
|
1208 | 1285 | |
|
1209 | 1286 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1210 | 1287 | |
|
1211 | 1288 | self.__isConfig = True |
|
1212 | 1289 | |
|
1213 | 1290 | self.setWinTitle(title) |
|
1214 | 1291 | |
|
1215 | 1292 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1216 | 1293 | x[1] = self.xmax |
|
1217 | 1294 | |
|
1218 | 1295 | for i in range(self.nplots): |
|
1219 | 1296 | |
|
1220 | 1297 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1221 | 1298 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
1222 | 1299 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
1223 | 1300 | # coherence = numpy.abs(avgcoherenceComplex) |
|
1224 | 1301 | |
|
1225 | 1302 | ## coherence = numpy.abs(coherenceComplex) |
|
1226 | 1303 | ## avg = numpy.average(coherence, axis=0) |
|
1227 | 1304 | |
|
1228 | 1305 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1229 | 1306 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1230 | 1307 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1231 | 1308 | |
|
1232 | 1309 | |
|
1233 | 1310 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1234 | 1311 | coherence = numpy.abs(avgcoherenceComplex) |
|
1235 | 1312 | |
|
1236 | 1313 | z = coherence.reshape((1,-1)) |
|
1237 | 1314 | |
|
1238 | 1315 | counter = 0 |
|
1239 | 1316 | |
|
1240 | 1317 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1241 | 1318 | axes = self.axesList[i*self.__nsubplots*2] |
|
1242 | 1319 | axes.pcolorbuffer(x, y, z, |
|
1243 | 1320 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1244 | 1321 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1245 | 1322 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
1246 | 1323 | |
|
1247 | 1324 | if self.__showprofile: |
|
1248 | 1325 | counter += 1 |
|
1249 | 1326 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1250 | 1327 | axes.pline(coherence, y, |
|
1251 | 1328 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
1252 | 1329 | xlabel='', ylabel='', title='', ticksize=7, |
|
1253 | 1330 | ytick_visible=False, nxticks=5, |
|
1254 | 1331 | grid='x') |
|
1255 | 1332 | |
|
1256 | 1333 | counter += 1 |
|
1257 | 1334 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
1258 | 1335 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1259 | 1336 | # avg = numpy.average(phase, axis=0) |
|
1260 | 1337 | z = phase.reshape((1,-1)) |
|
1261 | 1338 | |
|
1262 | 1339 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1263 | 1340 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1264 | 1341 | axes.pcolorbuffer(x, y, z, |
|
1265 | 1342 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
1266 | 1343 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1267 | 1344 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
1268 | 1345 | |
|
1269 | 1346 | if self.__showprofile: |
|
1270 | 1347 | counter += 1 |
|
1271 | 1348 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1272 | 1349 | axes.pline(phase, y, |
|
1273 | 1350 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
1274 | 1351 | xlabel='', ylabel='', title='', ticksize=7, |
|
1275 | 1352 | ytick_visible=False, nxticks=4, |
|
1276 | 1353 | grid='x') |
|
1277 | 1354 | |
|
1278 | 1355 | self.draw() |
|
1279 | 1356 | |
|
1280 | 1357 | if x[1] >= self.axesList[0].xmax: |
|
1281 | 1358 | self.saveFigure(figpath, figfile) |
|
1282 | 1359 | self.__isConfig = False |
|
1283 | 1360 | |
|
1284 | 1361 | # if save: |
|
1285 | 1362 | # |
|
1286 | 1363 | # self.counter_imagwr += 1 |
|
1287 | 1364 | # if (self.counter_imagwr==wr_period): |
|
1288 | 1365 | # if figfile == None: |
|
1289 | 1366 | # figfile = self.getFilename(name = self.name) |
|
1290 | 1367 | # self.saveFigure(figpath, figfile) |
|
1291 | 1368 | # |
|
1292 | 1369 | # if ftp: |
|
1293 | 1370 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1294 | 1371 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1295 | 1372 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
1296 | 1373 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1297 | 1374 | # self.saveFigure(figpath, ftp_file) |
|
1298 | 1375 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
1299 | 1376 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1300 | 1377 | # self.counter_imagwr = 0 |
|
1301 | 1378 | # |
|
1302 | 1379 | # self.counter_imagwr = 0 |
|
1303 | 1380 | # |
|
1304 | 1381 | # |
|
1305 | 1382 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1306 | 1383 | # self.__isConfig = False |
|
1307 | 1384 | |
|
1308 | 1385 | class BeaconPhase(Figure): |
|
1309 | 1386 | |
|
1310 | 1387 | __isConfig = None |
|
1311 | 1388 | __nsubplots = None |
|
1312 | 1389 | |
|
1313 | 1390 | PREFIX = 'beacon_phase' |
|
1314 | 1391 | |
|
1315 | 1392 | def __init__(self): |
|
1316 | 1393 | |
|
1317 | 1394 | self.timerange = 24*60*60 |
|
1318 | 1395 | self.__isConfig = False |
|
1319 | 1396 | self.__nsubplots = 1 |
|
1320 | 1397 | self.counter_imagwr = 0 |
|
1321 | 1398 | self.WIDTH = 600 |
|
1322 | 1399 | self.HEIGHT = 300 |
|
1323 | 1400 | self.WIDTHPROF = 120 |
|
1324 | 1401 | self.HEIGHTPROF = 0 |
|
1325 | 1402 | self.xdata = None |
|
1326 | 1403 | self.ydata = None |
|
1327 | 1404 | |
|
1328 | 1405 | self.PLOT_CODE = 18 |
|
1329 | 1406 | self.FTP_WEI = None |
|
1330 | 1407 | self.EXP_CODE = None |
|
1331 | 1408 | self.SUB_EXP_CODE = None |
|
1332 | 1409 | self.PLOT_POS = None |
|
1333 | 1410 | |
|
1334 | 1411 | self.filename_phase = None |
|
1335 | 1412 | |
|
1336 | 1413 | def getSubplots(self): |
|
1337 | 1414 | |
|
1338 | 1415 | ncol = 1 |
|
1339 | 1416 | nrow = 1 |
|
1340 | 1417 | |
|
1341 | 1418 | return nrow, ncol |
|
1342 | 1419 | |
|
1343 | 1420 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1344 | 1421 | |
|
1345 | 1422 | self.__showprofile = showprofile |
|
1346 | 1423 | self.nplots = nplots |
|
1347 | 1424 | |
|
1348 | 1425 | ncolspan = 7 |
|
1349 | 1426 | colspan = 6 |
|
1350 | 1427 | self.__nsubplots = 2 |
|
1351 | 1428 | |
|
1352 | 1429 | self.createFigure(id = id, |
|
1353 | 1430 | wintitle = wintitle, |
|
1354 | 1431 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1355 | 1432 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1356 | 1433 | show=show) |
|
1357 | 1434 | |
|
1358 | 1435 | nrow, ncol = self.getSubplots() |
|
1359 | 1436 | |
|
1360 | 1437 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1361 | 1438 | |
|
1362 | 1439 | def save_phase(self, filename_phase): |
|
1363 | 1440 | f = open(filename_phase,'w+') |
|
1364 | 1441 | f.write('\n\n') |
|
1365 | 1442 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1366 | 1443 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1367 | 1444 | f.close() |
|
1368 | 1445 | |
|
1369 | 1446 | def save_data(self, filename_phase, data, data_datetime): |
|
1370 | 1447 | f=open(filename_phase,'a') |
|
1371 | 1448 | timetuple_data = data_datetime.timetuple() |
|
1372 | 1449 | day = str(timetuple_data.tm_mday) |
|
1373 | 1450 | month = str(timetuple_data.tm_mon) |
|
1374 | 1451 | year = str(timetuple_data.tm_year) |
|
1375 | 1452 | hour = str(timetuple_data.tm_hour) |
|
1376 | 1453 | minute = str(timetuple_data.tm_min) |
|
1377 | 1454 | second = str(timetuple_data.tm_sec) |
|
1378 | 1455 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1379 | 1456 | f.close() |
|
1380 | 1457 | |
|
1381 | 1458 | |
|
1382 | 1459 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1383 | 1460 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1384 | 1461 | timerange=None, |
|
1385 | 1462 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1386 | 1463 | server=None, folder=None, username=None, password=None, |
|
1387 | 1464 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1388 | 1465 | |
|
1389 | 1466 | if pairsList == None: |
|
1390 | 1467 | pairsIndexList = dataOut.pairsIndexList |
|
1391 | 1468 | else: |
|
1392 | 1469 | pairsIndexList = [] |
|
1393 | 1470 | for pair in pairsList: |
|
1394 | 1471 | if pair not in dataOut.pairsList: |
|
1395 | 1472 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1396 | 1473 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1397 | 1474 | |
|
1398 | 1475 | if pairsIndexList == []: |
|
1399 | 1476 | return |
|
1400 | 1477 | |
|
1401 | 1478 | # if len(pairsIndexList) > 4: |
|
1402 | 1479 | # pairsIndexList = pairsIndexList[0:4] |
|
1403 | 1480 | |
|
1404 | 1481 | if timerange != None: |
|
1405 | 1482 | self.timerange = timerange |
|
1406 | 1483 | |
|
1407 | 1484 | tmin = None |
|
1408 | 1485 | tmax = None |
|
1409 | 1486 | x = dataOut.getTimeRange() |
|
1410 | 1487 | y = dataOut.getHeiRange() |
|
1411 | 1488 | |
|
1412 | 1489 | |
|
1413 | 1490 | #thisDatetime = dataOut.datatime |
|
1414 | 1491 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1415 | 1492 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1416 | 1493 | xlabel = "Local Time" |
|
1417 | 1494 | ylabel = "Phase" |
|
1418 | 1495 | |
|
1419 | 1496 | nplots = len(pairsIndexList) |
|
1420 | 1497 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1421 | 1498 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1422 | 1499 | for i in range(nplots): |
|
1423 | 1500 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1424 | 1501 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1425 | 1502 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1426 | 1503 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1427 | 1504 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1428 | 1505 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1429 | 1506 | |
|
1430 | 1507 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1431 | 1508 | #print phase[dataOut.beacon_heiIndexList] |
|
1432 | 1509 | |
|
1433 | 1510 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1434 | 1511 | |
|
1435 | 1512 | if not self.__isConfig: |
|
1436 | 1513 | |
|
1437 | 1514 | nplots = len(pairsIndexList) |
|
1438 | 1515 | |
|
1439 | 1516 | self.setup(id=id, |
|
1440 | 1517 | nplots=nplots, |
|
1441 | 1518 | wintitle=wintitle, |
|
1442 | 1519 | showprofile=showprofile, |
|
1443 | 1520 | show=show) |
|
1444 | 1521 | |
|
1445 | 1522 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1446 | 1523 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1447 | 1524 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1448 | 1525 | |
|
1449 | 1526 | self.FTP_WEI = ftp_wei |
|
1450 | 1527 | self.EXP_CODE = exp_code |
|
1451 | 1528 | self.SUB_EXP_CODE = sub_exp_code |
|
1452 | 1529 | self.PLOT_POS = plot_pos |
|
1453 | 1530 | |
|
1454 | 1531 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1455 | 1532 | self.__isConfig = True |
|
1456 | 1533 | |
|
1457 | 1534 | self.xdata = numpy.array([]) |
|
1458 | 1535 | self.ydata = numpy.array([]) |
|
1459 | 1536 | |
|
1460 | 1537 | #open file beacon phase |
|
1461 | 1538 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1462 | 1539 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1463 | 1540 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1464 | 1541 | #self.save_phase(self.filename_phase) |
|
1465 | 1542 | |
|
1466 | 1543 | |
|
1467 | 1544 | #store data beacon phase |
|
1468 | 1545 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1469 | 1546 | |
|
1470 | 1547 | self.setWinTitle(title) |
|
1471 | 1548 | |
|
1472 | 1549 | |
|
1473 | 1550 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1474 | 1551 | |
|
1475 | 1552 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1476 | 1553 | |
|
1477 | 1554 | axes = self.axesList[0] |
|
1478 | 1555 | |
|
1479 | 1556 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1480 | 1557 | |
|
1481 | 1558 | if len(self.ydata)==0: |
|
1482 | 1559 | self.ydata = phase_beacon.reshape(-1,1) |
|
1483 | 1560 | else: |
|
1484 | 1561 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1485 | 1562 | |
|
1486 | 1563 | |
|
1487 | 1564 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1488 | 1565 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1489 | 1566 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1490 | 1567 | XAxisAsTime=True, grid='both' |
|
1491 | 1568 | ) |
|
1492 | 1569 | |
|
1493 | 1570 | self.draw() |
|
1494 | 1571 | |
|
1495 | 1572 | if save: |
|
1496 | 1573 | |
|
1497 | 1574 | self.counter_imagwr += 1 |
|
1498 | 1575 | if (self.counter_imagwr==wr_period): |
|
1499 | 1576 | if figfile == None: |
|
1500 | 1577 | figfile = self.getFilename(name = self.name) |
|
1501 | 1578 | self.saveFigure(figpath, figfile) |
|
1502 | 1579 | |
|
1503 | 1580 | if ftp: |
|
1504 | 1581 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1505 | 1582 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1506 | 1583 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1507 | 1584 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1508 | 1585 | self.saveFigure(figpath, ftp_file) |
|
1509 | 1586 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1510 | 1587 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1511 | 1588 | |
|
1512 | 1589 | self.counter_imagwr = 0 |
|
1513 | 1590 | |
|
1514 | 1591 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1515 | 1592 | self.__isConfig = False |
|
1516 | 1593 | del self.xdata |
|
1517 | 1594 | del self.ydata |
|
1518 | 1595 | |
|
1519 | 1596 | |
|
1520 | 1597 | |
|
1521 | 1598 | |
|
1522 | 1599 | class Noise(Figure): |
|
1523 | 1600 | |
|
1524 | 1601 | __isConfig = None |
|
1525 | 1602 | __nsubplots = None |
|
1526 | 1603 | |
|
1527 | 1604 | PREFIX = 'noise' |
|
1528 | 1605 | |
|
1529 | 1606 | def __init__(self): |
|
1530 | 1607 | |
|
1531 | 1608 | self.timerange = 24*60*60 |
|
1532 | 1609 | self.__isConfig = False |
|
1533 | 1610 | self.__nsubplots = 1 |
|
1534 | 1611 | self.counter_imagwr = 0 |
|
1535 | 1612 | self.WIDTH = 600 |
|
1536 | 1613 | self.HEIGHT = 300 |
|
1537 | 1614 | self.WIDTHPROF = 120 |
|
1538 | 1615 | self.HEIGHTPROF = 0 |
|
1539 | 1616 | self.xdata = None |
|
1540 | 1617 | self.ydata = None |
|
1541 | 1618 | |
|
1542 | 1619 | self.PLOT_CODE = 77 |
|
1543 | 1620 | self.FTP_WEI = None |
|
1544 | 1621 | self.EXP_CODE = None |
|
1545 | 1622 | self.SUB_EXP_CODE = None |
|
1546 | 1623 | self.PLOT_POS = None |
|
1547 | 1624 | |
|
1548 | 1625 | def getSubplots(self): |
|
1549 | 1626 | |
|
1550 | 1627 | ncol = 1 |
|
1551 | 1628 | nrow = 1 |
|
1552 | 1629 | |
|
1553 | 1630 | return nrow, ncol |
|
1554 | 1631 | |
|
1555 | 1632 | def openfile(self, filename): |
|
1556 | 1633 | f = open(filename,'w+') |
|
1557 | 1634 | f.write('\n\n') |
|
1558 | 1635 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1559 | 1636 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1560 | 1637 | f.close() |
|
1561 | 1638 | |
|
1562 | 1639 | def save_data(self, filename_phase, data, data_datetime): |
|
1563 | 1640 | f=open(filename_phase,'a') |
|
1564 | 1641 | timetuple_data = data_datetime.timetuple() |
|
1565 | 1642 | day = str(timetuple_data.tm_mday) |
|
1566 | 1643 | month = str(timetuple_data.tm_mon) |
|
1567 | 1644 | year = str(timetuple_data.tm_year) |
|
1568 | 1645 | hour = str(timetuple_data.tm_hour) |
|
1569 | 1646 | minute = str(timetuple_data.tm_min) |
|
1570 | 1647 | second = str(timetuple_data.tm_sec) |
|
1571 | 1648 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1572 | 1649 | f.close() |
|
1573 | 1650 | |
|
1574 | 1651 | |
|
1575 | 1652 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1576 | 1653 | |
|
1577 | 1654 | self.__showprofile = showprofile |
|
1578 | 1655 | self.nplots = nplots |
|
1579 | 1656 | |
|
1580 | 1657 | ncolspan = 7 |
|
1581 | 1658 | colspan = 6 |
|
1582 | 1659 | self.__nsubplots = 2 |
|
1583 | 1660 | |
|
1584 | 1661 | self.createFigure(id = id, |
|
1585 | 1662 | wintitle = wintitle, |
|
1586 | 1663 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1587 | 1664 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1588 | 1665 | show=show) |
|
1589 | 1666 | |
|
1590 | 1667 | nrow, ncol = self.getSubplots() |
|
1591 | 1668 | |
|
1592 | 1669 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1593 | 1670 | |
|
1594 | 1671 | |
|
1595 | 1672 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1596 | 1673 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1597 | 1674 | timerange=None, |
|
1598 | 1675 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1599 | 1676 | server=None, folder=None, username=None, password=None, |
|
1600 | 1677 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1601 | 1678 | |
|
1602 | 1679 | if channelList == None: |
|
1603 | 1680 | channelIndexList = dataOut.channelIndexList |
|
1604 | 1681 | channelList = dataOut.channelList |
|
1605 | 1682 | else: |
|
1606 | 1683 | channelIndexList = [] |
|
1607 | 1684 | for channel in channelList: |
|
1608 | 1685 | if channel not in dataOut.channelList: |
|
1609 | 1686 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1610 | 1687 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1611 | 1688 | |
|
1612 | 1689 | if timerange != None: |
|
1613 | 1690 | self.timerange = timerange |
|
1614 | 1691 | |
|
1615 | 1692 | tmin = None |
|
1616 | 1693 | tmax = None |
|
1617 | 1694 | x = dataOut.getTimeRange() |
|
1618 | 1695 | y = dataOut.getHeiRange() |
|
1619 | 1696 | factor = dataOut.normFactor |
|
1620 | 1697 | noise = dataOut.getNoise()/factor |
|
1621 | 1698 | noisedB = 10*numpy.log10(noise) |
|
1622 | 1699 | |
|
1623 | 1700 | #thisDatetime = dataOut.datatime |
|
1624 | 1701 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1625 | 1702 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1626 | 1703 | xlabel = "" |
|
1627 | 1704 | ylabel = "Intensity (dB)" |
|
1628 | 1705 | |
|
1629 | 1706 | if not self.__isConfig: |
|
1630 | 1707 | |
|
1631 | 1708 | nplots = 1 |
|
1632 | 1709 | |
|
1633 | 1710 | self.setup(id=id, |
|
1634 | 1711 | nplots=nplots, |
|
1635 | 1712 | wintitle=wintitle, |
|
1636 | 1713 | showprofile=showprofile, |
|
1637 | 1714 | show=show) |
|
1638 | 1715 | |
|
1639 | 1716 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1640 | 1717 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 |
|
1641 | 1718 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1642 | 1719 | |
|
1643 | 1720 | self.FTP_WEI = ftp_wei |
|
1644 | 1721 | self.EXP_CODE = exp_code |
|
1645 | 1722 | self.SUB_EXP_CODE = sub_exp_code |
|
1646 | 1723 | self.PLOT_POS = plot_pos |
|
1647 | 1724 | |
|
1648 | 1725 | |
|
1649 | 1726 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1650 | 1727 | self.__isConfig = True |
|
1651 | 1728 | |
|
1652 | 1729 | self.xdata = numpy.array([]) |
|
1653 | 1730 | self.ydata = numpy.array([]) |
|
1654 | 1731 | |
|
1655 | 1732 | #open file beacon phase |
|
1656 | 1733 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1657 | 1734 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1658 | 1735 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1659 | 1736 | self.openfile(self.filename_noise) |
|
1660 | 1737 | |
|
1661 | 1738 | |
|
1662 | 1739 | #store data beacon phase |
|
1663 | 1740 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1664 | 1741 | |
|
1665 | 1742 | |
|
1666 | 1743 | self.setWinTitle(title) |
|
1667 | 1744 | |
|
1668 | 1745 | |
|
1669 | 1746 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1670 | 1747 | |
|
1671 | 1748 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1672 | 1749 | axes = self.axesList[0] |
|
1673 | 1750 | |
|
1674 | 1751 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1675 | 1752 | |
|
1676 | 1753 | if len(self.ydata)==0: |
|
1677 | 1754 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1678 | 1755 | else: |
|
1679 | 1756 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1680 | 1757 | |
|
1681 | 1758 | |
|
1682 | 1759 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1683 | 1760 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1684 | 1761 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1685 | 1762 | XAxisAsTime=True, grid='both' |
|
1686 | 1763 | ) |
|
1687 | 1764 | |
|
1688 | 1765 | self.draw() |
|
1689 | 1766 | |
|
1690 | 1767 | # if save: |
|
1691 | 1768 | # |
|
1692 | 1769 | # if figfile == None: |
|
1693 | 1770 | # figfile = self.getFilename(name = self.name) |
|
1694 | 1771 | # |
|
1695 | 1772 | # self.saveFigure(figpath, figfile) |
|
1696 | 1773 | |
|
1697 | 1774 | if save: |
|
1698 | 1775 | |
|
1699 | 1776 | self.counter_imagwr += 1 |
|
1700 | 1777 | if (self.counter_imagwr==wr_period): |
|
1701 | 1778 | if figfile == None: |
|
1702 | 1779 | figfile = self.getFilename(name = self.name) |
|
1703 | 1780 | self.saveFigure(figpath, figfile) |
|
1704 | 1781 | |
|
1705 | 1782 | if ftp: |
|
1706 | 1783 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1707 | 1784 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1708 | 1785 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1709 | 1786 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1710 | 1787 | self.saveFigure(figpath, ftp_file) |
|
1711 | 1788 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1712 | 1789 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1713 | 1790 | self.counter_imagwr = 0 |
|
1714 | 1791 | |
|
1715 | 1792 | self.counter_imagwr = 0 |
|
1716 | 1793 | |
|
1717 | 1794 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1718 | 1795 | self.__isConfig = False |
|
1719 | 1796 | del self.xdata |
|
1720 | 1797 | del self.ydata |
|
1721 | 1798 | |
|
1722 | 1799 | |
|
1723 | 1800 | class SpectraHeisScope(Figure): |
|
1724 | 1801 | |
|
1725 | 1802 | |
|
1726 | 1803 | __isConfig = None |
|
1727 | 1804 | __nsubplots = None |
|
1728 | 1805 | |
|
1729 | 1806 | WIDTHPROF = None |
|
1730 | 1807 | HEIGHTPROF = None |
|
1731 | 1808 | PREFIX = 'spc' |
|
1732 | 1809 | |
|
1733 | 1810 | def __init__(self): |
|
1734 | 1811 | |
|
1735 | 1812 | self.__isConfig = False |
|
1736 | 1813 | self.__nsubplots = 1 |
|
1737 | 1814 | |
|
1738 | 1815 | self.WIDTH = 230 |
|
1739 | 1816 | self.HEIGHT = 250 |
|
1740 | 1817 | self.WIDTHPROF = 120 |
|
1741 | 1818 | self.HEIGHTPROF = 0 |
|
1742 | 1819 | self.counter_imagwr = 0 |
|
1743 | 1820 | |
|
1744 | 1821 | def getSubplots(self): |
|
1745 | 1822 | |
|
1746 | 1823 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1747 | 1824 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1748 | 1825 | |
|
1749 | 1826 | return nrow, ncol |
|
1750 | 1827 | |
|
1751 | 1828 | def setup(self, id, nplots, wintitle, show): |
|
1752 | 1829 | |
|
1753 | 1830 | showprofile = False |
|
1754 | 1831 | self.__showprofile = showprofile |
|
1755 | 1832 | self.nplots = nplots |
|
1756 | 1833 | |
|
1757 | 1834 | ncolspan = 1 |
|
1758 | 1835 | colspan = 1 |
|
1759 | 1836 | if showprofile: |
|
1760 | 1837 | ncolspan = 3 |
|
1761 | 1838 | colspan = 2 |
|
1762 | 1839 | self.__nsubplots = 2 |
|
1763 | 1840 | |
|
1764 | 1841 | self.createFigure(id = id, |
|
1765 | 1842 | wintitle = wintitle, |
|
1766 | 1843 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1767 | 1844 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1768 | 1845 | show = show) |
|
1769 | 1846 | |
|
1770 | 1847 | nrow, ncol = self.getSubplots() |
|
1771 | 1848 | |
|
1772 | 1849 | counter = 0 |
|
1773 | 1850 | for y in range(nrow): |
|
1774 | 1851 | for x in range(ncol): |
|
1775 | 1852 | |
|
1776 | 1853 | if counter >= self.nplots: |
|
1777 | 1854 | break |
|
1778 | 1855 | |
|
1779 | 1856 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1780 | 1857 | |
|
1781 | 1858 | if showprofile: |
|
1782 | 1859 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1783 | 1860 | |
|
1784 | 1861 | counter += 1 |
|
1785 | 1862 | |
|
1786 | 1863 | |
|
1787 | 1864 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1788 | 1865 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1789 | 1866 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
1790 | 1867 | server=None, folder=None, username=None, password=None): |
|
1791 | 1868 | |
|
1792 | 1869 | """ |
|
1793 | 1870 | |
|
1794 | 1871 | Input: |
|
1795 | 1872 | dataOut : |
|
1796 | 1873 | id : |
|
1797 | 1874 | wintitle : |
|
1798 | 1875 | channelList : |
|
1799 | 1876 | xmin : None, |
|
1800 | 1877 | xmax : None, |
|
1801 | 1878 | ymin : None, |
|
1802 | 1879 | ymax : None, |
|
1803 | 1880 | """ |
|
1804 | 1881 | |
|
1805 | 1882 | if dataOut.realtime: |
|
1806 | 1883 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
1807 | 1884 | print 'Skipping this plot function' |
|
1808 | 1885 | return |
|
1809 | 1886 | |
|
1810 | 1887 | if channelList == None: |
|
1811 | 1888 | channelIndexList = dataOut.channelIndexList |
|
1812 | 1889 | else: |
|
1813 | 1890 | channelIndexList = [] |
|
1814 | 1891 | for channel in channelList: |
|
1815 | 1892 | if channel not in dataOut.channelList: |
|
1816 | 1893 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1817 | 1894 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1818 | 1895 | |
|
1819 | 1896 | # x = dataOut.heightList |
|
1820 | 1897 | c = 3E8 |
|
1821 | 1898 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1822 | 1899 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1823 | 1900 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1824 | 1901 | #para 1Mhz descomentar la siguiente linea |
|
1825 | 1902 | #x= x/(10000.0) |
|
1826 | 1903 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1827 | 1904 | # y = y.real |
|
1828 | 1905 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1829 | 1906 | y = datadB |
|
1830 | 1907 | |
|
1831 | 1908 | #thisDatetime = dataOut.datatime |
|
1832 | 1909 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1833 | 1910 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1834 | 1911 | xlabel = "" |
|
1835 | 1912 | #para 1Mhz descomentar la siguiente linea |
|
1836 | 1913 | #xlabel = "Frequency x 10000" |
|
1837 | 1914 | ylabel = "Intensity (dB)" |
|
1838 | 1915 | |
|
1839 | 1916 | if not self.__isConfig: |
|
1840 | 1917 | nplots = len(channelIndexList) |
|
1841 | 1918 | |
|
1842 | 1919 | self.setup(id=id, |
|
1843 | 1920 | nplots=nplots, |
|
1844 | 1921 | wintitle=wintitle, |
|
1845 | 1922 | show=show) |
|
1846 | 1923 | |
|
1847 | 1924 | if xmin == None: xmin = numpy.nanmin(x) |
|
1848 | 1925 | if xmax == None: xmax = numpy.nanmax(x) |
|
1849 | 1926 | if ymin == None: ymin = numpy.nanmin(y) |
|
1850 | 1927 | if ymax == None: ymax = numpy.nanmax(y) |
|
1851 | 1928 | |
|
1852 | 1929 | self.__isConfig = True |
|
1853 | 1930 | |
|
1854 | 1931 | self.setWinTitle(title) |
|
1855 | 1932 | |
|
1856 | 1933 | for i in range(len(self.axesList)): |
|
1857 | 1934 | ychannel = y[i,:] |
|
1858 | 1935 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
1859 | 1936 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) |
|
1860 | 1937 | axes = self.axesList[i] |
|
1861 | 1938 | axes.pline(x, ychannel, |
|
1862 | 1939 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1863 | 1940 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1864 | 1941 | |
|
1865 | 1942 | |
|
1866 | 1943 | self.draw() |
|
1867 | 1944 | |
|
1868 | 1945 | if save: |
|
1869 | 1946 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1870 | 1947 | if figfile == None: |
|
1871 | 1948 | figfile = self.getFilename(name = date) |
|
1872 | 1949 | |
|
1873 | 1950 | self.saveFigure(figpath, figfile) |
|
1874 | 1951 | |
|
1875 | 1952 | self.counter_imagwr += 1 |
|
1876 | 1953 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1877 | 1954 | ftp_filename = os.path.join(figpath,figfile) |
|
1878 | 1955 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1879 | 1956 | self.counter_imagwr = 0 |
|
1880 | 1957 | |
|
1881 | 1958 | |
|
1882 | 1959 | class RTIfromSpectraHeis(Figure): |
|
1883 | 1960 | |
|
1884 | 1961 | __isConfig = None |
|
1885 | 1962 | __nsubplots = None |
|
1886 | 1963 | |
|
1887 | 1964 | PREFIX = 'rtinoise' |
|
1888 | 1965 | |
|
1889 | 1966 | def __init__(self): |
|
1890 | 1967 | |
|
1891 | 1968 | self.timerange = 24*60*60 |
|
1892 | 1969 | self.__isConfig = False |
|
1893 | 1970 | self.__nsubplots = 1 |
|
1894 | 1971 | |
|
1895 | 1972 | self.WIDTH = 820 |
|
1896 | 1973 | self.HEIGHT = 200 |
|
1897 | 1974 | self.WIDTHPROF = 120 |
|
1898 | 1975 | self.HEIGHTPROF = 0 |
|
1899 | 1976 | self.counter_imagwr = 0 |
|
1900 | 1977 | self.xdata = None |
|
1901 | 1978 | self.ydata = None |
|
1902 | 1979 | |
|
1903 | 1980 | def getSubplots(self): |
|
1904 | 1981 | |
|
1905 | 1982 | ncol = 1 |
|
1906 | 1983 | nrow = 1 |
|
1907 | 1984 | |
|
1908 | 1985 | return nrow, ncol |
|
1909 | 1986 | |
|
1910 | 1987 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1911 | 1988 | |
|
1912 | 1989 | self.__showprofile = showprofile |
|
1913 | 1990 | self.nplots = nplots |
|
1914 | 1991 | |
|
1915 | 1992 | ncolspan = 7 |
|
1916 | 1993 | colspan = 6 |
|
1917 | 1994 | self.__nsubplots = 2 |
|
1918 | 1995 | |
|
1919 | 1996 | self.createFigure(id = id, |
|
1920 | 1997 | wintitle = wintitle, |
|
1921 | 1998 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1922 | 1999 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1923 | 2000 | show = show) |
|
1924 | 2001 | |
|
1925 | 2002 | nrow, ncol = self.getSubplots() |
|
1926 | 2003 | |
|
1927 | 2004 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1928 | 2005 | |
|
1929 | 2006 | |
|
1930 | 2007 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1931 | 2008 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1932 | 2009 | timerange=None, |
|
1933 | 2010 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
1934 | 2011 | server=None, folder=None, username=None, password=None): |
|
1935 | 2012 | |
|
1936 | 2013 | if channelList == None: |
|
1937 | 2014 | channelIndexList = dataOut.channelIndexList |
|
1938 | 2015 | channelList = dataOut.channelList |
|
1939 | 2016 | else: |
|
1940 | 2017 | channelIndexList = [] |
|
1941 | 2018 | for channel in channelList: |
|
1942 | 2019 | if channel not in dataOut.channelList: |
|
1943 | 2020 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1944 | 2021 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1945 | 2022 | |
|
1946 | 2023 | if timerange != None: |
|
1947 | 2024 | self.timerange = timerange |
|
1948 | 2025 | |
|
1949 | 2026 | tmin = None |
|
1950 | 2027 | tmax = None |
|
1951 | 2028 | x = dataOut.getTimeRange() |
|
1952 | 2029 | y = dataOut.getHeiRange() |
|
1953 | 2030 | |
|
1954 | 2031 | #factor = 1 |
|
1955 | 2032 | data = dataOut.data_spc#/factor |
|
1956 | 2033 | data = numpy.average(data,axis=1) |
|
1957 | 2034 | datadB = 10*numpy.log10(data) |
|
1958 | 2035 | |
|
1959 | 2036 | # factor = dataOut.normFactor |
|
1960 | 2037 | # noise = dataOut.getNoise()/factor |
|
1961 | 2038 | # noisedB = 10*numpy.log10(noise) |
|
1962 | 2039 | |
|
1963 | 2040 | #thisDatetime = dataOut.datatime |
|
1964 | 2041 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1965 | 2042 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1966 | 2043 | xlabel = "Local Time" |
|
1967 | 2044 | ylabel = "Intensity (dB)" |
|
1968 | 2045 | |
|
1969 | 2046 | if not self.__isConfig: |
|
1970 | 2047 | |
|
1971 | 2048 | nplots = 1 |
|
1972 | 2049 | |
|
1973 | 2050 | self.setup(id=id, |
|
1974 | 2051 | nplots=nplots, |
|
1975 | 2052 | wintitle=wintitle, |
|
1976 | 2053 | showprofile=showprofile, |
|
1977 | 2054 | show=show) |
|
1978 | 2055 | |
|
1979 | 2056 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1980 | 2057 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
1981 | 2058 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
1982 | 2059 | |
|
1983 | 2060 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1984 | 2061 | self.__isConfig = True |
|
1985 | 2062 | |
|
1986 | 2063 | self.xdata = numpy.array([]) |
|
1987 | 2064 | self.ydata = numpy.array([]) |
|
1988 | 2065 | |
|
1989 | 2066 | self.setWinTitle(title) |
|
1990 | 2067 | |
|
1991 | 2068 | |
|
1992 | 2069 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1993 | 2070 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1994 | 2071 | |
|
1995 | 2072 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
1996 | 2073 | axes = self.axesList[0] |
|
1997 | 2074 | |
|
1998 | 2075 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1999 | 2076 | |
|
2000 | 2077 | if len(self.ydata)==0: |
|
2001 | 2078 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
2002 | 2079 | else: |
|
2003 | 2080 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
2004 | 2081 | |
|
2005 | 2082 | |
|
2006 | 2083 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
2007 | 2084 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
2008 | 2085 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
2009 | 2086 | XAxisAsTime=True |
|
2010 | 2087 | ) |
|
2011 | 2088 | |
|
2012 | 2089 | self.draw() |
|
2013 | 2090 | |
|
2014 | 2091 | if save: |
|
2015 | 2092 | |
|
2016 | 2093 | if figfile == None: |
|
2017 | 2094 | figfile = self.getFilename(name = self.name) |
|
2018 | 2095 | |
|
2019 | 2096 | self.saveFigure(figpath, figfile) |
|
2020 | 2097 | |
|
2021 | 2098 | self.counter_imagwr += 1 |
|
2022 | 2099 | if (ftp and (self.counter_imagwr==wr_period)): |
|
2023 | 2100 | ftp_filename = os.path.join(figpath,figfile) |
|
2024 | 2101 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
2025 | 2102 | self.counter_imagwr = 0 |
|
2026 | 2103 | |
|
2027 | 2104 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
2028 | 2105 | self.__isConfig = False |
|
2029 | 2106 | del self.xdata |
|
2030 | 2107 | del self.ydata |
|
2031 | 2108 | |
|
2032 | 2109 | |
|
2033 | 2110 | No newline at end of file |
@@ -1,2044 +1,2066 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: dsuarez $ |
|
4 | 4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
5 | 5 | ''' |
|
6 | 6 | import os |
|
7 | 7 | import numpy |
|
8 | 8 | import datetime |
|
9 | 9 | import time |
|
10 | 10 | import math |
|
11 | 11 | from jrodata import * |
|
12 | 12 | from jrodataIO import * |
|
13 | 13 | from jroplot import * |
|
14 | 14 | |
|
15 | 15 | try: |
|
16 | 16 | import cfunctions |
|
17 | 17 | except: |
|
18 | 18 | pass |
|
19 | 19 | |
|
20 | 20 | class ProcessingUnit: |
|
21 | 21 | |
|
22 | 22 | """ |
|
23 | 23 | Esta es la clase base para el procesamiento de datos. |
|
24 | 24 | |
|
25 | 25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
26 | 26 | - Metodos internos (callMethod) |
|
27 | 27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
28 | 28 | tienen que ser agreagados con el metodo "add". |
|
29 | 29 | |
|
30 | 30 | """ |
|
31 | 31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
32 | 32 | dataIn = None |
|
33 | 33 | |
|
34 | 34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
35 | 35 | dataOut = None |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | objectDict = None |
|
39 | 39 | |
|
40 | 40 | def __init__(self): |
|
41 | 41 | |
|
42 | 42 | self.objectDict = {} |
|
43 | 43 | |
|
44 | 44 | def init(self): |
|
45 | 45 | |
|
46 | 46 | raise ValueError, "Not implemented" |
|
47 | 47 | |
|
48 | 48 | def addOperation(self, object, objId): |
|
49 | 49 | |
|
50 | 50 | """ |
|
51 | 51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
52 | 52 | identificador asociado a este objeto. |
|
53 | 53 | |
|
54 | 54 | Input: |
|
55 | 55 | |
|
56 | 56 | object : objeto de la clase "Operation" |
|
57 | 57 | |
|
58 | 58 | Return: |
|
59 | 59 | |
|
60 | 60 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
61 | 61 | """ |
|
62 | 62 | |
|
63 | 63 | self.objectDict[objId] = object |
|
64 | 64 | |
|
65 | 65 | return objId |
|
66 | 66 | |
|
67 | 67 | def operation(self, **kwargs): |
|
68 | 68 | |
|
69 | 69 | """ |
|
70 | 70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
71 | 71 | atributos del objeto dataOut |
|
72 | 72 | |
|
73 | 73 | Input: |
|
74 | 74 | |
|
75 | 75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
76 | 76 | """ |
|
77 | 77 | |
|
78 | 78 | raise ValueError, "ImplementedError" |
|
79 | 79 | |
|
80 | 80 | def callMethod(self, name, **kwargs): |
|
81 | 81 | |
|
82 | 82 | """ |
|
83 | 83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
84 | 84 | |
|
85 | 85 | Input: |
|
86 | 86 | name : nombre del metodo a ejecutar |
|
87 | 87 | |
|
88 | 88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
89 | 89 | |
|
90 | 90 | """ |
|
91 | 91 | if name != 'run': |
|
92 | 92 | |
|
93 | 93 | if name == 'init' and self.dataIn.isEmpty(): |
|
94 | 94 | self.dataOut.flagNoData = True |
|
95 | 95 | return False |
|
96 | 96 | |
|
97 | 97 | if name != 'init' and self.dataOut.isEmpty(): |
|
98 | 98 | return False |
|
99 | 99 | |
|
100 | 100 | methodToCall = getattr(self, name) |
|
101 | 101 | |
|
102 | 102 | methodToCall(**kwargs) |
|
103 | 103 | |
|
104 | 104 | if name != 'run': |
|
105 | 105 | return True |
|
106 | 106 | |
|
107 | 107 | if self.dataOut.isEmpty(): |
|
108 | 108 | return False |
|
109 | 109 | |
|
110 | 110 | return True |
|
111 | 111 | |
|
112 | 112 | def callObject(self, objId, **kwargs): |
|
113 | 113 | |
|
114 | 114 | """ |
|
115 | 115 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
116 | 116 | |
|
117 | 117 | Input: |
|
118 | 118 | |
|
119 | 119 | objId : identificador del objeto a ejecutar |
|
120 | 120 | |
|
121 | 121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
122 | 122 | |
|
123 | 123 | Return: |
|
124 | 124 | |
|
125 | 125 | None |
|
126 | 126 | """ |
|
127 | 127 | |
|
128 | 128 | if self.dataOut.isEmpty(): |
|
129 | 129 | return False |
|
130 | 130 | |
|
131 | 131 | object = self.objectDict[objId] |
|
132 | 132 | |
|
133 | 133 | object.run(self.dataOut, **kwargs) |
|
134 | 134 | |
|
135 | 135 | return True |
|
136 | 136 | |
|
137 | 137 | def call(self, operationConf, **kwargs): |
|
138 | 138 | |
|
139 | 139 | """ |
|
140 | 140 | Return True si ejecuta la operacion "operationConf.name" con los |
|
141 | 141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
142 | 142 | La operacion puede ser de dos tipos: |
|
143 | 143 | |
|
144 | 144 | 1. Un metodo propio de esta clase: |
|
145 | 145 | |
|
146 | 146 | operation.type = "self" |
|
147 | 147 | |
|
148 | 148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
149 | 149 | operation.type = "other". |
|
150 | 150 | |
|
151 | 151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
152 | 152 | "addOperation" e identificado con el operation.id |
|
153 | 153 | |
|
154 | 154 | |
|
155 | 155 | con el id de la operacion. |
|
156 | 156 | |
|
157 | 157 | Input: |
|
158 | 158 | |
|
159 | 159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
160 | 160 | |
|
161 | 161 | """ |
|
162 | 162 | |
|
163 | 163 | if operationConf.type == 'self': |
|
164 | 164 | sts = self.callMethod(operationConf.name, **kwargs) |
|
165 | 165 | |
|
166 | 166 | if operationConf.type == 'other': |
|
167 | 167 | sts = self.callObject(operationConf.id, **kwargs) |
|
168 | 168 | |
|
169 | 169 | return sts |
|
170 | 170 | |
|
171 | 171 | def setInput(self, dataIn): |
|
172 | 172 | |
|
173 | 173 | self.dataIn = dataIn |
|
174 | 174 | |
|
175 | 175 | def getOutput(self): |
|
176 | 176 | |
|
177 | 177 | return self.dataOut |
|
178 | 178 | |
|
179 | 179 | class Operation(): |
|
180 | 180 | |
|
181 | 181 | """ |
|
182 | 182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
183 | 183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
184 | 184 | acumulacion dentro de esta clase |
|
185 | 185 | |
|
186 | 186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
187 | 187 | |
|
188 | 188 | """ |
|
189 | 189 | |
|
190 | 190 | __buffer = None |
|
191 | 191 | __isConfig = False |
|
192 | 192 | |
|
193 | 193 | def __init__(self): |
|
194 | 194 | |
|
195 | 195 | pass |
|
196 | 196 | |
|
197 | 197 | def run(self, dataIn, **kwargs): |
|
198 | 198 | |
|
199 | 199 | """ |
|
200 | 200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
201 | 201 | |
|
202 | 202 | Input: |
|
203 | 203 | |
|
204 | 204 | dataIn : objeto del tipo JROData |
|
205 | 205 | |
|
206 | 206 | Return: |
|
207 | 207 | |
|
208 | 208 | None |
|
209 | 209 | |
|
210 | 210 | Affected: |
|
211 | 211 | __buffer : buffer de recepcion de datos. |
|
212 | 212 | |
|
213 | 213 | """ |
|
214 | 214 | |
|
215 | 215 | raise ValueError, "ImplementedError" |
|
216 | 216 | |
|
217 | 217 | class VoltageProc(ProcessingUnit): |
|
218 | 218 | |
|
219 | 219 | |
|
220 | 220 | def __init__(self): |
|
221 | 221 | |
|
222 | 222 | self.objectDict = {} |
|
223 | 223 | self.dataOut = Voltage() |
|
224 | 224 | self.flip = 1 |
|
225 | 225 | |
|
226 | def __updateObjFromAmisrInput(self): | |
|
227 | ||
|
228 | self.dataOut.timeZone = self.dataIn.timeZone | |
|
229 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
|
230 | self.dataOut.errorCount = self.dataIn.errorCount | |
|
231 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
|
232 | ||
|
233 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
|
234 | self.dataOut.data = self.dataIn.data | |
|
235 | self.dataOut.utctime = self.dataIn.utctime | |
|
236 | self.dataOut.channelList = self.dataIn.channelList | |
|
237 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
|
238 | self.dataOut.heightList = self.dataIn.heightList | |
|
239 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
|
240 | ||
|
241 | pass | |
|
242 | ||
|
226 | 243 | def init(self): |
|
227 | 244 | |
|
228 | self.dataOut.copy(self.dataIn) | |
|
245 | ||
|
246 | if self.dataIn.type == 'AMISR': | |
|
247 | self.__updateObjFromAmisrInput() | |
|
248 | ||
|
249 | if self.dataIn.type == 'Voltage': | |
|
250 | self.dataOut.copy(self.dataIn) | |
|
229 | 251 | # No necesita copiar en cada init() los atributos de dataIn |
|
230 | 252 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
231 | 253 | |
|
232 | 254 | def selectChannels(self, channelList): |
|
233 | 255 | |
|
234 | 256 | channelIndexList = [] |
|
235 | 257 | |
|
236 | 258 | for channel in channelList: |
|
237 | 259 | index = self.dataOut.channelList.index(channel) |
|
238 | 260 | channelIndexList.append(index) |
|
239 | 261 | |
|
240 | 262 | self.selectChannelsByIndex(channelIndexList) |
|
241 | 263 | |
|
242 | 264 | def selectChannelsByIndex(self, channelIndexList): |
|
243 | 265 | """ |
|
244 | 266 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
245 | 267 | |
|
246 | 268 | Input: |
|
247 | 269 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
248 | 270 | |
|
249 | 271 | Affected: |
|
250 | 272 | self.dataOut.data |
|
251 | 273 | self.dataOut.channelIndexList |
|
252 | 274 | self.dataOut.nChannels |
|
253 | 275 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
254 | 276 | self.dataOut.systemHeaderObj.numChannels |
|
255 | 277 | self.dataOut.m_ProcessingHeader.blockSize |
|
256 | 278 | |
|
257 | 279 | Return: |
|
258 | 280 | None |
|
259 | 281 | """ |
|
260 | 282 | |
|
261 | 283 | for channelIndex in channelIndexList: |
|
262 | 284 | if channelIndex not in self.dataOut.channelIndexList: |
|
263 | 285 | print channelIndexList |
|
264 | 286 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
265 | 287 | |
|
266 | 288 | nChannels = len(channelIndexList) |
|
267 | 289 | |
|
268 | 290 | data = self.dataOut.data[channelIndexList,:] |
|
269 | 291 | |
|
270 | 292 | self.dataOut.data = data |
|
271 | 293 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
272 | 294 | # self.dataOut.nChannels = nChannels |
|
273 | 295 | |
|
274 | 296 | return 1 |
|
275 | 297 | |
|
276 | 298 | def selectHeights(self, minHei=None, maxHei=None): |
|
277 | 299 | """ |
|
278 | 300 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
279 | 301 | minHei <= height <= maxHei |
|
280 | 302 | |
|
281 | 303 | Input: |
|
282 | 304 | minHei : valor minimo de altura a considerar |
|
283 | 305 | maxHei : valor maximo de altura a considerar |
|
284 | 306 | |
|
285 | 307 | Affected: |
|
286 | 308 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
287 | 309 | |
|
288 | 310 | Return: |
|
289 | 311 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
290 | 312 | """ |
|
291 | 313 | |
|
292 | 314 | if minHei == None: |
|
293 | 315 | minHei = self.dataOut.heightList[0] |
|
294 | 316 | |
|
295 | 317 | if maxHei == None: |
|
296 | 318 | maxHei = self.dataOut.heightList[-1] |
|
297 | 319 | |
|
298 | 320 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
299 | 321 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
300 | 322 | |
|
301 | 323 | |
|
302 | 324 | if (maxHei > self.dataOut.heightList[-1]): |
|
303 | 325 | maxHei = self.dataOut.heightList[-1] |
|
304 | 326 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
305 | 327 | |
|
306 | 328 | minIndex = 0 |
|
307 | 329 | maxIndex = 0 |
|
308 | 330 | heights = self.dataOut.heightList |
|
309 | 331 | |
|
310 | 332 | inda = numpy.where(heights >= minHei) |
|
311 | 333 | indb = numpy.where(heights <= maxHei) |
|
312 | 334 | |
|
313 | 335 | try: |
|
314 | 336 | minIndex = inda[0][0] |
|
315 | 337 | except: |
|
316 | 338 | minIndex = 0 |
|
317 | 339 | |
|
318 | 340 | try: |
|
319 | 341 | maxIndex = indb[0][-1] |
|
320 | 342 | except: |
|
321 | 343 | maxIndex = len(heights) |
|
322 | 344 | |
|
323 | 345 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
324 | 346 | |
|
325 | 347 | return 1 |
|
326 | 348 | |
|
327 | 349 | |
|
328 | 350 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
329 | 351 | """ |
|
330 | 352 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
331 | 353 | minIndex <= index <= maxIndex |
|
332 | 354 | |
|
333 | 355 | Input: |
|
334 | 356 | minIndex : valor de indice minimo de altura a considerar |
|
335 | 357 | maxIndex : valor de indice maximo de altura a considerar |
|
336 | 358 | |
|
337 | 359 | Affected: |
|
338 | 360 | self.dataOut.data |
|
339 | 361 | self.dataOut.heightList |
|
340 | 362 | |
|
341 | 363 | Return: |
|
342 | 364 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
343 | 365 | """ |
|
344 | 366 | |
|
345 | 367 | if (minIndex < 0) or (minIndex > maxIndex): |
|
346 | 368 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
347 | 369 | |
|
348 | 370 | if (maxIndex >= self.dataOut.nHeights): |
|
349 | 371 | maxIndex = self.dataOut.nHeights-1 |
|
350 | 372 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
351 | 373 | |
|
352 | 374 | nHeights = maxIndex - minIndex + 1 |
|
353 | 375 | |
|
354 | 376 | #voltage |
|
355 | 377 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
356 | 378 | |
|
357 | 379 | firstHeight = self.dataOut.heightList[minIndex] |
|
358 | 380 | |
|
359 | 381 | self.dataOut.data = data |
|
360 | 382 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
361 | 383 | |
|
362 | 384 | return 1 |
|
363 | 385 | |
|
364 | 386 | |
|
365 | 387 | def filterByHeights(self, window): |
|
366 | 388 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
367 | 389 | |
|
368 | 390 | if window == None: |
|
369 | 391 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
370 | 392 | |
|
371 | 393 | newdelta = deltaHeight * window |
|
372 | 394 | r = self.dataOut.data.shape[1] % window |
|
373 | 395 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] |
|
374 | 396 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) |
|
375 | 397 | buffer = numpy.sum(buffer,2) |
|
376 | 398 | self.dataOut.data = buffer |
|
377 | 399 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) |
|
378 | 400 | self.dataOut.windowOfFilter = window |
|
379 | 401 | |
|
380 | 402 | def deFlip(self): |
|
381 | 403 | self.dataOut.data *= self.flip |
|
382 | 404 | self.flip *= -1. |
|
383 | 405 | |
|
384 | 406 | def setRadarFrequency(self, frequency=None): |
|
385 | 407 | if frequency != None: |
|
386 | 408 | self.dataOut.frequency = frequency |
|
387 | 409 | |
|
388 | 410 | return 1 |
|
389 | 411 | |
|
390 | 412 | class CohInt(Operation): |
|
391 | 413 | |
|
392 | 414 | __isConfig = False |
|
393 | 415 | |
|
394 | 416 | __profIndex = 0 |
|
395 | 417 | __withOverapping = False |
|
396 | 418 | |
|
397 | 419 | __byTime = False |
|
398 | 420 | __initime = None |
|
399 | 421 | __lastdatatime = None |
|
400 | 422 | __integrationtime = None |
|
401 | 423 | |
|
402 | 424 | __buffer = None |
|
403 | 425 | |
|
404 | 426 | __dataReady = False |
|
405 | 427 | |
|
406 | 428 | n = None |
|
407 | 429 | |
|
408 | 430 | |
|
409 | 431 | def __init__(self): |
|
410 | 432 | |
|
411 | 433 | self.__isConfig = False |
|
412 | 434 | |
|
413 | 435 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
414 | 436 | """ |
|
415 | 437 | Set the parameters of the integration class. |
|
416 | 438 | |
|
417 | 439 | Inputs: |
|
418 | 440 | |
|
419 | 441 | n : Number of coherent integrations |
|
420 | 442 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
421 | 443 | overlapping : |
|
422 | 444 | |
|
423 | 445 | """ |
|
424 | 446 | |
|
425 | 447 | self.__initime = None |
|
426 | 448 | self.__lastdatatime = 0 |
|
427 | 449 | self.__buffer = None |
|
428 | 450 | self.__dataReady = False |
|
429 | 451 | |
|
430 | 452 | |
|
431 | 453 | if n == None and timeInterval == None: |
|
432 | 454 | raise ValueError, "n or timeInterval should be specified ..." |
|
433 | 455 | |
|
434 | 456 | if n != None: |
|
435 | 457 | self.n = n |
|
436 | 458 | self.__byTime = False |
|
437 | 459 | else: |
|
438 | 460 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
439 | 461 | self.n = 9999 |
|
440 | 462 | self.__byTime = True |
|
441 | 463 | |
|
442 | 464 | if overlapping: |
|
443 | 465 | self.__withOverapping = True |
|
444 | 466 | self.__buffer = None |
|
445 | 467 | else: |
|
446 | 468 | self.__withOverapping = False |
|
447 | 469 | self.__buffer = 0 |
|
448 | 470 | |
|
449 | 471 | self.__profIndex = 0 |
|
450 | 472 | |
|
451 | 473 | def putData(self, data): |
|
452 | 474 | |
|
453 | 475 | """ |
|
454 | 476 | Add a profile to the __buffer and increase in one the __profileIndex |
|
455 | 477 | |
|
456 | 478 | """ |
|
457 | 479 | |
|
458 | 480 | if not self.__withOverapping: |
|
459 | 481 | self.__buffer += data.copy() |
|
460 | 482 | self.__profIndex += 1 |
|
461 | 483 | return |
|
462 | 484 | |
|
463 | 485 | #Overlapping data |
|
464 | 486 | nChannels, nHeis = data.shape |
|
465 | 487 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
466 | 488 | |
|
467 | 489 | #If the buffer is empty then it takes the data value |
|
468 | 490 | if self.__buffer == None: |
|
469 | 491 | self.__buffer = data |
|
470 | 492 | self.__profIndex += 1 |
|
471 | 493 | return |
|
472 | 494 | |
|
473 | 495 | #If the buffer length is lower than n then stakcing the data value |
|
474 | 496 | if self.__profIndex < self.n: |
|
475 | 497 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
476 | 498 | self.__profIndex += 1 |
|
477 | 499 | return |
|
478 | 500 | |
|
479 | 501 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
480 | 502 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
481 | 503 | self.__buffer[self.n-1] = data |
|
482 | 504 | self.__profIndex = self.n |
|
483 | 505 | return |
|
484 | 506 | |
|
485 | 507 | |
|
486 | 508 | def pushData(self): |
|
487 | 509 | """ |
|
488 | 510 | Return the sum of the last profiles and the profiles used in the sum. |
|
489 | 511 | |
|
490 | 512 | Affected: |
|
491 | 513 | |
|
492 | 514 | self.__profileIndex |
|
493 | 515 | |
|
494 | 516 | """ |
|
495 | 517 | |
|
496 | 518 | if not self.__withOverapping: |
|
497 | 519 | data = self.__buffer |
|
498 | 520 | n = self.__profIndex |
|
499 | 521 | |
|
500 | 522 | self.__buffer = 0 |
|
501 | 523 | self.__profIndex = 0 |
|
502 | 524 | |
|
503 | 525 | return data, n |
|
504 | 526 | |
|
505 | 527 | #Integration with Overlapping |
|
506 | 528 | data = numpy.sum(self.__buffer, axis=0) |
|
507 | 529 | n = self.__profIndex |
|
508 | 530 | |
|
509 | 531 | return data, n |
|
510 | 532 | |
|
511 | 533 | def byProfiles(self, data): |
|
512 | 534 | |
|
513 | 535 | self.__dataReady = False |
|
514 | 536 | avgdata = None |
|
515 | 537 | n = None |
|
516 | 538 | |
|
517 | 539 | self.putData(data) |
|
518 | 540 | |
|
519 | 541 | if self.__profIndex == self.n: |
|
520 | 542 | |
|
521 | 543 | avgdata, n = self.pushData() |
|
522 | 544 | self.__dataReady = True |
|
523 | 545 | |
|
524 | 546 | return avgdata |
|
525 | 547 | |
|
526 | 548 | def byTime(self, data, datatime): |
|
527 | 549 | |
|
528 | 550 | self.__dataReady = False |
|
529 | 551 | avgdata = None |
|
530 | 552 | n = None |
|
531 | 553 | |
|
532 | 554 | self.putData(data) |
|
533 | 555 | |
|
534 | 556 | if (datatime - self.__initime) >= self.__integrationtime: |
|
535 | 557 | avgdata, n = self.pushData() |
|
536 | 558 | self.n = n |
|
537 | 559 | self.__dataReady = True |
|
538 | 560 | |
|
539 | 561 | return avgdata |
|
540 | 562 | |
|
541 | 563 | def integrate(self, data, datatime=None): |
|
542 | 564 | |
|
543 | 565 | if self.__initime == None: |
|
544 | 566 | self.__initime = datatime |
|
545 | 567 | |
|
546 | 568 | if self.__byTime: |
|
547 | 569 | avgdata = self.byTime(data, datatime) |
|
548 | 570 | else: |
|
549 | 571 | avgdata = self.byProfiles(data) |
|
550 | 572 | |
|
551 | 573 | |
|
552 | 574 | self.__lastdatatime = datatime |
|
553 | 575 | |
|
554 | 576 | if avgdata == None: |
|
555 | 577 | return None, None |
|
556 | 578 | |
|
557 | 579 | avgdatatime = self.__initime |
|
558 | 580 | |
|
559 | 581 | deltatime = datatime -self.__lastdatatime |
|
560 | 582 | |
|
561 | 583 | if not self.__withOverapping: |
|
562 | 584 | self.__initime = datatime |
|
563 | 585 | else: |
|
564 | 586 | self.__initime += deltatime |
|
565 | 587 | |
|
566 | 588 | return avgdata, avgdatatime |
|
567 | 589 | |
|
568 | 590 | def run(self, dataOut, **kwargs): |
|
569 | 591 | |
|
570 | 592 | if not self.__isConfig: |
|
571 | 593 | self.setup(**kwargs) |
|
572 | 594 | self.__isConfig = True |
|
573 | 595 | |
|
574 | 596 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
575 | 597 | |
|
576 | 598 | # dataOut.timeInterval *= n |
|
577 | 599 | dataOut.flagNoData = True |
|
578 | 600 | |
|
579 | 601 | if self.__dataReady: |
|
580 | 602 | dataOut.data = avgdata |
|
581 | 603 | dataOut.nCohInt *= self.n |
|
582 | 604 | dataOut.utctime = avgdatatime |
|
583 | 605 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
584 | 606 | dataOut.flagNoData = False |
|
585 | 607 | |
|
586 | 608 | |
|
587 | 609 | class Decoder(Operation): |
|
588 | 610 | |
|
589 | 611 | __isConfig = False |
|
590 | 612 | __profIndex = 0 |
|
591 | 613 | |
|
592 | 614 | code = None |
|
593 | 615 | |
|
594 | 616 | nCode = None |
|
595 | 617 | nBaud = None |
|
596 | 618 | |
|
597 | 619 | def __init__(self): |
|
598 | 620 | |
|
599 | 621 | self.__isConfig = False |
|
600 | 622 | |
|
601 | 623 | def setup(self, code, shape): |
|
602 | 624 | |
|
603 | 625 | self.__profIndex = 0 |
|
604 | 626 | |
|
605 | 627 | self.code = code |
|
606 | 628 | |
|
607 | 629 | self.nCode = len(code) |
|
608 | 630 | self.nBaud = len(code[0]) |
|
609 | 631 | |
|
610 | 632 | self.__nChannels, self.__nHeis = shape |
|
611 | 633 | |
|
612 | 634 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
613 | 635 | |
|
614 | 636 | __codeBuffer[:,0:self.nBaud] = self.code |
|
615 | 637 | |
|
616 | 638 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
617 | 639 | |
|
618 | 640 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
619 | 641 | |
|
620 | 642 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
621 | 643 | |
|
622 | 644 | def convolutionInFreq(self, data): |
|
623 | 645 | |
|
624 | 646 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
625 | 647 | |
|
626 | 648 | fft_data = numpy.fft.fft(data, axis=1) |
|
627 | 649 | |
|
628 | 650 | conv = fft_data*fft_code |
|
629 | 651 | |
|
630 | 652 | data = numpy.fft.ifft(conv,axis=1) |
|
631 | 653 | |
|
632 | 654 | datadec = data[:,:-self.nBaud+1] |
|
633 | 655 | |
|
634 | 656 | return datadec |
|
635 | 657 | |
|
636 | 658 | def convolutionInFreqOpt(self, data): |
|
637 | 659 | |
|
638 | 660 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
639 | 661 | |
|
640 | 662 | data = cfunctions.decoder(fft_code, data) |
|
641 | 663 | |
|
642 | 664 | datadec = data[:,:-self.nBaud+1] |
|
643 | 665 | |
|
644 | 666 | return datadec |
|
645 | 667 | |
|
646 | 668 | def convolutionInTime(self, data): |
|
647 | 669 | |
|
648 | 670 | code = self.code[self.__profIndex] |
|
649 | 671 | |
|
650 | 672 | for i in range(self.__nChannels): |
|
651 | 673 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') |
|
652 | 674 | |
|
653 | 675 | return self.datadecTime |
|
654 | 676 | |
|
655 | 677 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): |
|
656 | 678 | |
|
657 | 679 | if code == None: |
|
658 | 680 | code = dataOut.code |
|
659 | 681 | else: |
|
660 | 682 | code = numpy.array(code).reshape(nCode,nBaud) |
|
661 | 683 | dataOut.code = code |
|
662 | 684 | dataOut.nCode = nCode |
|
663 | 685 | dataOut.nBaud = nBaud |
|
664 | 686 | dataOut.radarControllerHeaderObj.code = code |
|
665 | 687 | dataOut.radarControllerHeaderObj.nCode = nCode |
|
666 | 688 | dataOut.radarControllerHeaderObj.nBaud = nBaud |
|
667 | 689 | |
|
668 | 690 | |
|
669 | 691 | if not self.__isConfig: |
|
670 | 692 | |
|
671 | 693 | self.setup(code, dataOut.data.shape) |
|
672 | 694 | self.__isConfig = True |
|
673 | 695 | |
|
674 | 696 | if mode == 0: |
|
675 | 697 | datadec = self.convolutionInTime(dataOut.data) |
|
676 | 698 | |
|
677 | 699 | if mode == 1: |
|
678 | 700 | datadec = self.convolutionInFreq(dataOut.data) |
|
679 | 701 | |
|
680 | 702 | if mode == 2: |
|
681 | 703 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
682 | 704 | |
|
683 | 705 | dataOut.data = datadec |
|
684 | 706 | |
|
685 | 707 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
686 | 708 | |
|
687 | 709 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
688 | 710 | |
|
689 | 711 | if self.__profIndex == self.nCode-1: |
|
690 | 712 | self.__profIndex = 0 |
|
691 | 713 | return 1 |
|
692 | 714 | |
|
693 | 715 | self.__profIndex += 1 |
|
694 | 716 | |
|
695 | 717 | return 1 |
|
696 | 718 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
697 | 719 | |
|
698 | 720 | |
|
699 | 721 | |
|
700 | 722 | class SpectraProc(ProcessingUnit): |
|
701 | 723 | |
|
702 | 724 | def __init__(self): |
|
703 | 725 | |
|
704 | 726 | self.objectDict = {} |
|
705 | 727 | self.buffer = None |
|
706 | 728 | self.firstdatatime = None |
|
707 | 729 | self.profIndex = 0 |
|
708 | 730 | self.dataOut = Spectra() |
|
709 | 731 | |
|
710 | 732 | def __updateObjFromInput(self): |
|
711 | 733 | |
|
712 | 734 | self.dataOut.timeZone = self.dataIn.timeZone |
|
713 | 735 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
714 | 736 | self.dataOut.errorCount = self.dataIn.errorCount |
|
715 | 737 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
716 | 738 | |
|
717 | 739 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
718 | 740 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
719 | 741 | self.dataOut.channelList = self.dataIn.channelList |
|
720 | 742 | self.dataOut.heightList = self.dataIn.heightList |
|
721 | 743 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
722 | 744 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
723 | 745 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
724 | 746 | self.dataOut.nBaud = self.dataIn.nBaud |
|
725 | 747 | self.dataOut.nCode = self.dataIn.nCode |
|
726 | 748 | self.dataOut.code = self.dataIn.code |
|
727 | 749 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
728 | 750 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
729 | 751 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
730 | 752 | self.dataOut.utctime = self.firstdatatime |
|
731 | 753 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
732 | 754 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
733 | 755 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
734 | 756 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
735 | 757 | self.dataOut.nIncohInt = 1 |
|
736 | 758 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
737 | 759 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
738 | 760 | |
|
739 | 761 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
740 | 762 | self.dataOut.frequency = self.dataIn.frequency |
|
741 | 763 | self.dataOut.realtime = self.dataIn.realtime |
|
742 | 764 | |
|
743 | 765 | def __getFft(self): |
|
744 | 766 | """ |
|
745 | 767 | Convierte valores de Voltaje a Spectra |
|
746 | 768 | |
|
747 | 769 | Affected: |
|
748 | 770 | self.dataOut.data_spc |
|
749 | 771 | self.dataOut.data_cspc |
|
750 | 772 | self.dataOut.data_dc |
|
751 | 773 | self.dataOut.heightList |
|
752 | 774 | self.profIndex |
|
753 | 775 | self.buffer |
|
754 | 776 | self.dataOut.flagNoData |
|
755 | 777 | """ |
|
756 | 778 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
757 | 779 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
758 | 780 | dc = fft_volt[:,0,:] |
|
759 | 781 | |
|
760 | 782 | #calculo de self-spectra |
|
761 | 783 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
762 | 784 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
763 | 785 | spc = spc.real |
|
764 | 786 | |
|
765 | 787 | blocksize = 0 |
|
766 | 788 | blocksize += dc.size |
|
767 | 789 | blocksize += spc.size |
|
768 | 790 | |
|
769 | 791 | cspc = None |
|
770 | 792 | pairIndex = 0 |
|
771 | 793 | if self.dataOut.pairsList != None: |
|
772 | 794 | #calculo de cross-spectra |
|
773 | 795 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
774 | 796 | for pair in self.dataOut.pairsList: |
|
775 | 797 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
776 | 798 | pairIndex += 1 |
|
777 | 799 | blocksize += cspc.size |
|
778 | 800 | |
|
779 | 801 | self.dataOut.data_spc = spc |
|
780 | 802 | self.dataOut.data_cspc = cspc |
|
781 | 803 | self.dataOut.data_dc = dc |
|
782 | 804 | self.dataOut.blockSize = blocksize |
|
783 | 805 | self.dataOut.flagShiftFFT = False |
|
784 | 806 | |
|
785 | 807 | def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None): |
|
786 | 808 | |
|
787 | 809 | self.dataOut.flagNoData = True |
|
788 | 810 | |
|
789 | 811 | if self.dataIn.type == "Spectra": |
|
790 | 812 | self.dataOut.copy(self.dataIn) |
|
791 | 813 | return |
|
792 | 814 | |
|
793 | 815 | if self.dataIn.type == "Voltage": |
|
794 | 816 | |
|
795 | 817 | if nFFTPoints == None: |
|
796 | 818 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" |
|
797 | 819 | |
|
798 | 820 | if pairsList == None: |
|
799 | 821 | nPairs = 0 |
|
800 | 822 | else: |
|
801 | 823 | nPairs = len(pairsList) |
|
802 | 824 | |
|
803 | 825 | if ippFactor == None: |
|
804 | 826 | ippFactor = 1 |
|
805 | 827 | self.dataOut.ippFactor = ippFactor |
|
806 | 828 | |
|
807 | 829 | self.dataOut.nFFTPoints = nFFTPoints |
|
808 | 830 | self.dataOut.pairsList = pairsList |
|
809 | 831 | self.dataOut.nPairs = nPairs |
|
810 | 832 | |
|
811 | 833 | if self.buffer == None: |
|
812 | 834 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
813 | 835 | nProfiles, |
|
814 | 836 | self.dataIn.nHeights), |
|
815 | 837 | dtype='complex') |
|
816 | 838 | |
|
817 | 839 | |
|
818 | 840 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
819 | 841 | self.profIndex += 1 |
|
820 | 842 | |
|
821 | 843 | if self.firstdatatime == None: |
|
822 | 844 | self.firstdatatime = self.dataIn.utctime |
|
823 | 845 | |
|
824 | 846 | if self.profIndex == nProfiles: |
|
825 | 847 | self.__updateObjFromInput() |
|
826 | 848 | self.__getFft() |
|
827 | 849 | |
|
828 | 850 | self.dataOut.flagNoData = False |
|
829 | 851 | |
|
830 | 852 | self.buffer = None |
|
831 | 853 | self.firstdatatime = None |
|
832 | 854 | self.profIndex = 0 |
|
833 | 855 | |
|
834 | 856 | return |
|
835 | 857 | |
|
836 | 858 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
837 | 859 | |
|
838 | 860 | def selectChannels(self, channelList): |
|
839 | 861 | |
|
840 | 862 | channelIndexList = [] |
|
841 | 863 | |
|
842 | 864 | for channel in channelList: |
|
843 | 865 | index = self.dataOut.channelList.index(channel) |
|
844 | 866 | channelIndexList.append(index) |
|
845 | 867 | |
|
846 | 868 | self.selectChannelsByIndex(channelIndexList) |
|
847 | 869 | |
|
848 | 870 | def selectChannelsByIndex(self, channelIndexList): |
|
849 | 871 | """ |
|
850 | 872 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
851 | 873 | |
|
852 | 874 | Input: |
|
853 | 875 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
854 | 876 | |
|
855 | 877 | Affected: |
|
856 | 878 | self.dataOut.data_spc |
|
857 | 879 | self.dataOut.channelIndexList |
|
858 | 880 | self.dataOut.nChannels |
|
859 | 881 | |
|
860 | 882 | Return: |
|
861 | 883 | None |
|
862 | 884 | """ |
|
863 | 885 | |
|
864 | 886 | for channelIndex in channelIndexList: |
|
865 | 887 | if channelIndex not in self.dataOut.channelIndexList: |
|
866 | 888 | print channelIndexList |
|
867 | 889 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
868 | 890 | |
|
869 | 891 | nChannels = len(channelIndexList) |
|
870 | 892 | |
|
871 | 893 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
872 | 894 | |
|
873 | 895 | self.dataOut.data_spc = data_spc |
|
874 | 896 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
875 | 897 | # self.dataOut.nChannels = nChannels |
|
876 | 898 | |
|
877 | 899 | return 1 |
|
878 | 900 | |
|
879 | 901 | def selectHeights(self, minHei, maxHei): |
|
880 | 902 | """ |
|
881 | 903 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
882 | 904 | minHei <= height <= maxHei |
|
883 | 905 | |
|
884 | 906 | Input: |
|
885 | 907 | minHei : valor minimo de altura a considerar |
|
886 | 908 | maxHei : valor maximo de altura a considerar |
|
887 | 909 | |
|
888 | 910 | Affected: |
|
889 | 911 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
890 | 912 | |
|
891 | 913 | Return: |
|
892 | 914 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
893 | 915 | """ |
|
894 | 916 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
895 | 917 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
896 | 918 | |
|
897 | 919 | if (maxHei > self.dataOut.heightList[-1]): |
|
898 | 920 | maxHei = self.dataOut.heightList[-1] |
|
899 | 921 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
900 | 922 | |
|
901 | 923 | minIndex = 0 |
|
902 | 924 | maxIndex = 0 |
|
903 | 925 | heights = self.dataOut.heightList |
|
904 | 926 | |
|
905 | 927 | inda = numpy.where(heights >= minHei) |
|
906 | 928 | indb = numpy.where(heights <= maxHei) |
|
907 | 929 | |
|
908 | 930 | try: |
|
909 | 931 | minIndex = inda[0][0] |
|
910 | 932 | except: |
|
911 | 933 | minIndex = 0 |
|
912 | 934 | |
|
913 | 935 | try: |
|
914 | 936 | maxIndex = indb[0][-1] |
|
915 | 937 | except: |
|
916 | 938 | maxIndex = len(heights) |
|
917 | 939 | |
|
918 | 940 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
919 | 941 | |
|
920 | 942 | return 1 |
|
921 | 943 | |
|
922 | 944 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
923 | 945 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
924 | 946 | |
|
925 | 947 | if hei_ref != None: |
|
926 | 948 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
927 | 949 | |
|
928 | 950 | minIndex = min(newheis[0]) |
|
929 | 951 | maxIndex = max(newheis[0]) |
|
930 | 952 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
931 | 953 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
932 | 954 | |
|
933 | 955 | # determina indices |
|
934 | 956 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
935 | 957 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
936 | 958 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
937 | 959 | beacon_heiIndexList = [] |
|
938 | 960 | for val in avg_dB.tolist(): |
|
939 | 961 | if val >= beacon_dB[0]: |
|
940 | 962 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
941 | 963 | |
|
942 | 964 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
943 | 965 | data_cspc = None |
|
944 | 966 | if self.dataOut.data_cspc != None: |
|
945 | 967 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
946 | 968 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
947 | 969 | |
|
948 | 970 | data_dc = None |
|
949 | 971 | if self.dataOut.data_dc != None: |
|
950 | 972 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
951 | 973 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
952 | 974 | |
|
953 | 975 | self.dataOut.data_spc = data_spc |
|
954 | 976 | self.dataOut.data_cspc = data_cspc |
|
955 | 977 | self.dataOut.data_dc = data_dc |
|
956 | 978 | self.dataOut.heightList = heightList |
|
957 | 979 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
958 | 980 | |
|
959 | 981 | return 1 |
|
960 | 982 | |
|
961 | 983 | |
|
962 | 984 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
963 | 985 | """ |
|
964 | 986 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
965 | 987 | minIndex <= index <= maxIndex |
|
966 | 988 | |
|
967 | 989 | Input: |
|
968 | 990 | minIndex : valor de indice minimo de altura a considerar |
|
969 | 991 | maxIndex : valor de indice maximo de altura a considerar |
|
970 | 992 | |
|
971 | 993 | Affected: |
|
972 | 994 | self.dataOut.data_spc |
|
973 | 995 | self.dataOut.data_cspc |
|
974 | 996 | self.dataOut.data_dc |
|
975 | 997 | self.dataOut.heightList |
|
976 | 998 | |
|
977 | 999 | Return: |
|
978 | 1000 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
979 | 1001 | """ |
|
980 | 1002 | |
|
981 | 1003 | if (minIndex < 0) or (minIndex > maxIndex): |
|
982 | 1004 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
983 | 1005 | |
|
984 | 1006 | if (maxIndex >= self.dataOut.nHeights): |
|
985 | 1007 | maxIndex = self.dataOut.nHeights-1 |
|
986 | 1008 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
987 | 1009 | |
|
988 | 1010 | nHeights = maxIndex - minIndex + 1 |
|
989 | 1011 | |
|
990 | 1012 | #Spectra |
|
991 | 1013 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
992 | 1014 | |
|
993 | 1015 | data_cspc = None |
|
994 | 1016 | if self.dataOut.data_cspc != None: |
|
995 | 1017 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
996 | 1018 | |
|
997 | 1019 | data_dc = None |
|
998 | 1020 | if self.dataOut.data_dc != None: |
|
999 | 1021 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
1000 | 1022 | |
|
1001 | 1023 | self.dataOut.data_spc = data_spc |
|
1002 | 1024 | self.dataOut.data_cspc = data_cspc |
|
1003 | 1025 | self.dataOut.data_dc = data_dc |
|
1004 | 1026 | |
|
1005 | 1027 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
1006 | 1028 | |
|
1007 | 1029 | return 1 |
|
1008 | 1030 | |
|
1009 | 1031 | def removeDC(self, mode = 2): |
|
1010 | 1032 | jspectra = self.dataOut.data_spc |
|
1011 | 1033 | jcspectra = self.dataOut.data_cspc |
|
1012 | 1034 | |
|
1013 | 1035 | |
|
1014 | 1036 | num_chan = jspectra.shape[0] |
|
1015 | 1037 | num_hei = jspectra.shape[2] |
|
1016 | 1038 | |
|
1017 | 1039 | if jcspectra != None: |
|
1018 | 1040 | jcspectraExist = True |
|
1019 | 1041 | num_pairs = jcspectra.shape[0] |
|
1020 | 1042 | else: jcspectraExist = False |
|
1021 | 1043 | |
|
1022 | 1044 | freq_dc = jspectra.shape[1]/2 |
|
1023 | 1045 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1024 | 1046 | |
|
1025 | 1047 | if ind_vel[0]<0: |
|
1026 | 1048 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1027 | 1049 | |
|
1028 | 1050 | if mode == 1: |
|
1029 | 1051 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1030 | 1052 | |
|
1031 | 1053 | if jcspectraExist: |
|
1032 | 1054 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
1033 | 1055 | |
|
1034 | 1056 | if mode == 2: |
|
1035 | 1057 | |
|
1036 | 1058 | vel = numpy.array([-2,-1,1,2]) |
|
1037 | 1059 | xx = numpy.zeros([4,4]) |
|
1038 | 1060 | |
|
1039 | 1061 | for fil in range(4): |
|
1040 | 1062 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1041 | 1063 | |
|
1042 | 1064 | xx_inv = numpy.linalg.inv(xx) |
|
1043 | 1065 | xx_aux = xx_inv[0,:] |
|
1044 | 1066 | |
|
1045 | 1067 | for ich in range(num_chan): |
|
1046 | 1068 | yy = jspectra[ich,ind_vel,:] |
|
1047 | 1069 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1048 | 1070 | |
|
1049 | 1071 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1050 | 1072 | cjunkid = sum(junkid) |
|
1051 | 1073 | |
|
1052 | 1074 | if cjunkid.any(): |
|
1053 | 1075 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1054 | 1076 | |
|
1055 | 1077 | if jcspectraExist: |
|
1056 | 1078 | for ip in range(num_pairs): |
|
1057 | 1079 | yy = jcspectra[ip,ind_vel,:] |
|
1058 | 1080 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1059 | 1081 | |
|
1060 | 1082 | |
|
1061 | 1083 | self.dataOut.data_spc = jspectra |
|
1062 | 1084 | self.dataOut.data_cspc = jcspectra |
|
1063 | 1085 | |
|
1064 | 1086 | return 1 |
|
1065 | 1087 | |
|
1066 | 1088 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
1067 | 1089 | |
|
1068 | 1090 | jspectra = self.dataOut.data_spc |
|
1069 | 1091 | jcspectra = self.dataOut.data_cspc |
|
1070 | 1092 | jnoise = self.dataOut.getNoise() |
|
1071 | 1093 | num_incoh = self.dataOut.nIncohInt |
|
1072 | 1094 | |
|
1073 | 1095 | num_channel = jspectra.shape[0] |
|
1074 | 1096 | num_prof = jspectra.shape[1] |
|
1075 | 1097 | num_hei = jspectra.shape[2] |
|
1076 | 1098 | |
|
1077 | 1099 | #hei_interf |
|
1078 | 1100 | if hei_interf == None: |
|
1079 | 1101 | count_hei = num_hei/2 #Como es entero no importa |
|
1080 | 1102 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
1081 | 1103 | hei_interf = numpy.asarray(hei_interf)[0] |
|
1082 | 1104 | #nhei_interf |
|
1083 | 1105 | if (nhei_interf == None): |
|
1084 | 1106 | nhei_interf = 5 |
|
1085 | 1107 | if (nhei_interf < 1): |
|
1086 | 1108 | nhei_interf = 1 |
|
1087 | 1109 | if (nhei_interf > count_hei): |
|
1088 | 1110 | nhei_interf = count_hei |
|
1089 | 1111 | if (offhei_interf == None): |
|
1090 | 1112 | offhei_interf = 0 |
|
1091 | 1113 | |
|
1092 | 1114 | ind_hei = range(num_hei) |
|
1093 | 1115 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
1094 | 1116 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
1095 | 1117 | mask_prof = numpy.asarray(range(num_prof)) |
|
1096 | 1118 | num_mask_prof = mask_prof.size |
|
1097 | 1119 | comp_mask_prof = [0, num_prof/2] |
|
1098 | 1120 | |
|
1099 | 1121 | |
|
1100 | 1122 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
1101 | 1123 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
1102 | 1124 | jnoise = numpy.nan |
|
1103 | 1125 | noise_exist = jnoise[0] < numpy.Inf |
|
1104 | 1126 | |
|
1105 | 1127 | #Subrutina de Remocion de la Interferencia |
|
1106 | 1128 | for ich in range(num_channel): |
|
1107 | 1129 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
1108 | 1130 | power = jspectra[ich,mask_prof,:] |
|
1109 | 1131 | power = power[:,hei_interf] |
|
1110 | 1132 | power = power.sum(axis = 0) |
|
1111 | 1133 | psort = power.ravel().argsort() |
|
1112 | 1134 | |
|
1113 | 1135 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
1114 | 1136 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
1115 | 1137 | |
|
1116 | 1138 | if noise_exist: |
|
1117 | 1139 | # tmp_noise = jnoise[ich] / num_prof |
|
1118 | 1140 | tmp_noise = jnoise[ich] |
|
1119 | 1141 | junkspc_interf = junkspc_interf - tmp_noise |
|
1120 | 1142 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
1121 | 1143 | |
|
1122 | 1144 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
1123 | 1145 | jspc_interf = jspc_interf.transpose() |
|
1124 | 1146 | #Calculando el espectro de interferencia promedio |
|
1125 | 1147 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) |
|
1126 | 1148 | noiseid = noiseid[0] |
|
1127 | 1149 | cnoiseid = noiseid.size |
|
1128 | 1150 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) |
|
1129 | 1151 | interfid = interfid[0] |
|
1130 | 1152 | cinterfid = interfid.size |
|
1131 | 1153 | |
|
1132 | 1154 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
1133 | 1155 | |
|
1134 | 1156 | #Expandiendo los perfiles a limpiar |
|
1135 | 1157 | if (cinterfid > 0): |
|
1136 | 1158 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
1137 | 1159 | new_interfid = numpy.asarray(new_interfid) |
|
1138 | 1160 | new_interfid = {x for x in new_interfid} |
|
1139 | 1161 | new_interfid = numpy.array(list(new_interfid)) |
|
1140 | 1162 | new_cinterfid = new_interfid.size |
|
1141 | 1163 | else: new_cinterfid = 0 |
|
1142 | 1164 | |
|
1143 | 1165 | for ip in range(new_cinterfid): |
|
1144 | 1166 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
1145 | 1167 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
1146 | 1168 | |
|
1147 | 1169 | |
|
1148 | 1170 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
1149 | 1171 | |
|
1150 | 1172 | #Removiendo la interferencia del punto de mayor interferencia |
|
1151 | 1173 | ListAux = jspc_interf[mask_prof].tolist() |
|
1152 | 1174 | maxid = ListAux.index(max(ListAux)) |
|
1153 | 1175 | |
|
1154 | 1176 | |
|
1155 | 1177 | if cinterfid > 0: |
|
1156 | 1178 | for ip in range(cinterfid*(interf == 2) - 1): |
|
1157 | 1179 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() |
|
1158 | 1180 | cind = len(ind) |
|
1159 | 1181 | |
|
1160 | 1182 | if (cind > 0): |
|
1161 | 1183 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) |
|
1162 | 1184 | |
|
1163 | 1185 | ind = numpy.array([-2,-1,1,2]) |
|
1164 | 1186 | xx = numpy.zeros([4,4]) |
|
1165 | 1187 | |
|
1166 | 1188 | for id1 in range(4): |
|
1167 | 1189 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
1168 | 1190 | |
|
1169 | 1191 | xx_inv = numpy.linalg.inv(xx) |
|
1170 | 1192 | xx = xx_inv[:,0] |
|
1171 | 1193 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
1172 | 1194 | yy = jspectra[ich,mask_prof[ind],:] |
|
1173 | 1195 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
1174 | 1196 | |
|
1175 | 1197 | |
|
1176 | 1198 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() |
|
1177 | 1199 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) |
|
1178 | 1200 | |
|
1179 | 1201 | #Remocion de Interferencia en el Cross Spectra |
|
1180 | 1202 | if jcspectra == None: return jspectra, jcspectra |
|
1181 | 1203 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
1182 | 1204 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
1183 | 1205 | |
|
1184 | 1206 | for ip in range(num_pairs): |
|
1185 | 1207 | |
|
1186 | 1208 | #------------------------------------------- |
|
1187 | 1209 | |
|
1188 | 1210 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
1189 | 1211 | cspower = cspower[:,hei_interf] |
|
1190 | 1212 | cspower = cspower.sum(axis = 0) |
|
1191 | 1213 | |
|
1192 | 1214 | cspsort = cspower.ravel().argsort() |
|
1193 | 1215 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
1194 | 1216 | junkcspc_interf = junkcspc_interf.transpose() |
|
1195 | 1217 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
1196 | 1218 | |
|
1197 | 1219 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
1198 | 1220 | |
|
1199 | 1221 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
1200 | 1222 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
1201 | 1223 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
1202 | 1224 | |
|
1203 | 1225 | for iprof in range(num_prof): |
|
1204 | 1226 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
1205 | 1227 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
1206 | 1228 | |
|
1207 | 1229 | #Removiendo la Interferencia |
|
1208 | 1230 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
1209 | 1231 | |
|
1210 | 1232 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
1211 | 1233 | maxid = ListAux.index(max(ListAux)) |
|
1212 | 1234 | |
|
1213 | 1235 | ind = numpy.array([-2,-1,1,2]) |
|
1214 | 1236 | xx = numpy.zeros([4,4]) |
|
1215 | 1237 | |
|
1216 | 1238 | for id1 in range(4): |
|
1217 | 1239 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
1218 | 1240 | |
|
1219 | 1241 | xx_inv = numpy.linalg.inv(xx) |
|
1220 | 1242 | xx = xx_inv[:,0] |
|
1221 | 1243 | |
|
1222 | 1244 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
1223 | 1245 | yy = jcspectra[ip,mask_prof[ind],:] |
|
1224 | 1246 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
1225 | 1247 | |
|
1226 | 1248 | #Guardar Resultados |
|
1227 | 1249 | self.dataOut.data_spc = jspectra |
|
1228 | 1250 | self.dataOut.data_cspc = jcspectra |
|
1229 | 1251 | |
|
1230 | 1252 | return 1 |
|
1231 | 1253 | |
|
1232 | 1254 | def setRadarFrequency(self, frequency=None): |
|
1233 | 1255 | if frequency != None: |
|
1234 | 1256 | self.dataOut.frequency = frequency |
|
1235 | 1257 | |
|
1236 | 1258 | return 1 |
|
1237 | 1259 | |
|
1238 | 1260 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
1239 | 1261 | #validacion de rango |
|
1240 | 1262 | if minHei == None: |
|
1241 | 1263 | minHei = self.dataOut.heightList[0] |
|
1242 | 1264 | |
|
1243 | 1265 | if maxHei == None: |
|
1244 | 1266 | maxHei = self.dataOut.heightList[-1] |
|
1245 | 1267 | |
|
1246 | 1268 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
1247 | 1269 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
1248 | 1270 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
1249 | 1271 | minHei = self.dataOut.heightList[0] |
|
1250 | 1272 | |
|
1251 | 1273 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
1252 | 1274 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
1253 | 1275 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
1254 | 1276 | maxHei = self.dataOut.heightList[-1] |
|
1255 | 1277 | |
|
1256 | 1278 | # validacion de velocidades |
|
1257 | 1279 | velrange = self.dataOut.getVelRange(1) |
|
1258 | 1280 | |
|
1259 | 1281 | if minVel == None: |
|
1260 | 1282 | minVel = velrange[0] |
|
1261 | 1283 | |
|
1262 | 1284 | if maxVel == None: |
|
1263 | 1285 | maxVel = velrange[-1] |
|
1264 | 1286 | |
|
1265 | 1287 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
1266 | 1288 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
1267 | 1289 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
1268 | 1290 | minVel = velrange[0] |
|
1269 | 1291 | |
|
1270 | 1292 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
1271 | 1293 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
1272 | 1294 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
1273 | 1295 | maxVel = velrange[-1] |
|
1274 | 1296 | |
|
1275 | 1297 | # seleccion de indices para rango |
|
1276 | 1298 | minIndex = 0 |
|
1277 | 1299 | maxIndex = 0 |
|
1278 | 1300 | heights = self.dataOut.heightList |
|
1279 | 1301 | |
|
1280 | 1302 | inda = numpy.where(heights >= minHei) |
|
1281 | 1303 | indb = numpy.where(heights <= maxHei) |
|
1282 | 1304 | |
|
1283 | 1305 | try: |
|
1284 | 1306 | minIndex = inda[0][0] |
|
1285 | 1307 | except: |
|
1286 | 1308 | minIndex = 0 |
|
1287 | 1309 | |
|
1288 | 1310 | try: |
|
1289 | 1311 | maxIndex = indb[0][-1] |
|
1290 | 1312 | except: |
|
1291 | 1313 | maxIndex = len(heights) |
|
1292 | 1314 | |
|
1293 | 1315 | if (minIndex < 0) or (minIndex > maxIndex): |
|
1294 | 1316 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
1295 | 1317 | |
|
1296 | 1318 | if (maxIndex >= self.dataOut.nHeights): |
|
1297 | 1319 | maxIndex = self.dataOut.nHeights-1 |
|
1298 | 1320 | |
|
1299 | 1321 | # seleccion de indices para velocidades |
|
1300 | 1322 | indminvel = numpy.where(velrange >= minVel) |
|
1301 | 1323 | indmaxvel = numpy.where(velrange <= maxVel) |
|
1302 | 1324 | try: |
|
1303 | 1325 | minIndexVel = indminvel[0][0] |
|
1304 | 1326 | except: |
|
1305 | 1327 | minIndexVel = 0 |
|
1306 | 1328 | |
|
1307 | 1329 | try: |
|
1308 | 1330 | maxIndexVel = indmaxvel[0][-1] |
|
1309 | 1331 | except: |
|
1310 | 1332 | maxIndexVel = len(velrange) |
|
1311 | 1333 | |
|
1312 | 1334 | #seleccion del espectro |
|
1313 | 1335 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
1314 | 1336 | #estimacion de ruido |
|
1315 | 1337 | noise = numpy.zeros(self.dataOut.nChannels) |
|
1316 | 1338 | |
|
1317 | 1339 | for channel in range(self.dataOut.nChannels): |
|
1318 | 1340 | daux = data_spc[channel,:,:] |
|
1319 | 1341 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
1320 | 1342 | |
|
1321 | 1343 | self.dataOut.noise = noise.copy() |
|
1322 | 1344 | |
|
1323 | 1345 | return 1 |
|
1324 | 1346 | |
|
1325 | 1347 | |
|
1326 | 1348 | class IncohInt(Operation): |
|
1327 | 1349 | |
|
1328 | 1350 | |
|
1329 | 1351 | __profIndex = 0 |
|
1330 | 1352 | __withOverapping = False |
|
1331 | 1353 | |
|
1332 | 1354 | __byTime = False |
|
1333 | 1355 | __initime = None |
|
1334 | 1356 | __lastdatatime = None |
|
1335 | 1357 | __integrationtime = None |
|
1336 | 1358 | |
|
1337 | 1359 | __buffer_spc = None |
|
1338 | 1360 | __buffer_cspc = None |
|
1339 | 1361 | __buffer_dc = None |
|
1340 | 1362 | |
|
1341 | 1363 | __dataReady = False |
|
1342 | 1364 | |
|
1343 | 1365 | __timeInterval = None |
|
1344 | 1366 | |
|
1345 | 1367 | n = None |
|
1346 | 1368 | |
|
1347 | 1369 | |
|
1348 | 1370 | |
|
1349 | 1371 | def __init__(self): |
|
1350 | 1372 | |
|
1351 | 1373 | self.__isConfig = False |
|
1352 | 1374 | |
|
1353 | 1375 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1354 | 1376 | """ |
|
1355 | 1377 | Set the parameters of the integration class. |
|
1356 | 1378 | |
|
1357 | 1379 | Inputs: |
|
1358 | 1380 | |
|
1359 | 1381 | n : Number of coherent integrations |
|
1360 | 1382 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1361 | 1383 | overlapping : |
|
1362 | 1384 | |
|
1363 | 1385 | """ |
|
1364 | 1386 | |
|
1365 | 1387 | self.__initime = None |
|
1366 | 1388 | self.__lastdatatime = 0 |
|
1367 | 1389 | self.__buffer_spc = None |
|
1368 | 1390 | self.__buffer_cspc = None |
|
1369 | 1391 | self.__buffer_dc = None |
|
1370 | 1392 | self.__dataReady = False |
|
1371 | 1393 | |
|
1372 | 1394 | |
|
1373 | 1395 | if n == None and timeInterval == None: |
|
1374 | 1396 | raise ValueError, "n or timeInterval should be specified ..." |
|
1375 | 1397 | |
|
1376 | 1398 | if n != None: |
|
1377 | 1399 | self.n = n |
|
1378 | 1400 | self.__byTime = False |
|
1379 | 1401 | else: |
|
1380 | 1402 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line |
|
1381 | 1403 | self.n = 9999 |
|
1382 | 1404 | self.__byTime = True |
|
1383 | 1405 | |
|
1384 | 1406 | if overlapping: |
|
1385 | 1407 | self.__withOverapping = True |
|
1386 | 1408 | else: |
|
1387 | 1409 | self.__withOverapping = False |
|
1388 | 1410 | self.__buffer_spc = 0 |
|
1389 | 1411 | self.__buffer_cspc = 0 |
|
1390 | 1412 | self.__buffer_dc = 0 |
|
1391 | 1413 | |
|
1392 | 1414 | self.__profIndex = 0 |
|
1393 | 1415 | |
|
1394 | 1416 | def putData(self, data_spc, data_cspc, data_dc): |
|
1395 | 1417 | |
|
1396 | 1418 | """ |
|
1397 | 1419 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
1398 | 1420 | |
|
1399 | 1421 | """ |
|
1400 | 1422 | |
|
1401 | 1423 | if not self.__withOverapping: |
|
1402 | 1424 | self.__buffer_spc += data_spc |
|
1403 | 1425 | |
|
1404 | 1426 | if data_cspc == None: |
|
1405 | 1427 | self.__buffer_cspc = None |
|
1406 | 1428 | else: |
|
1407 | 1429 | self.__buffer_cspc += data_cspc |
|
1408 | 1430 | |
|
1409 | 1431 | if data_dc == None: |
|
1410 | 1432 | self.__buffer_dc = None |
|
1411 | 1433 | else: |
|
1412 | 1434 | self.__buffer_dc += data_dc |
|
1413 | 1435 | |
|
1414 | 1436 | self.__profIndex += 1 |
|
1415 | 1437 | return |
|
1416 | 1438 | |
|
1417 | 1439 | #Overlapping data |
|
1418 | 1440 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
1419 | 1441 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
1420 | 1442 | if data_cspc != None: |
|
1421 | 1443 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
1422 | 1444 | if data_dc != None: |
|
1423 | 1445 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
1424 | 1446 | |
|
1425 | 1447 | #If the buffer is empty then it takes the data value |
|
1426 | 1448 | if self.__buffer_spc == None: |
|
1427 | 1449 | self.__buffer_spc = data_spc |
|
1428 | 1450 | |
|
1429 | 1451 | if data_cspc == None: |
|
1430 | 1452 | self.__buffer_cspc = None |
|
1431 | 1453 | else: |
|
1432 | 1454 | self.__buffer_cspc += data_cspc |
|
1433 | 1455 | |
|
1434 | 1456 | if data_dc == None: |
|
1435 | 1457 | self.__buffer_dc = None |
|
1436 | 1458 | else: |
|
1437 | 1459 | self.__buffer_dc += data_dc |
|
1438 | 1460 | |
|
1439 | 1461 | self.__profIndex += 1 |
|
1440 | 1462 | return |
|
1441 | 1463 | |
|
1442 | 1464 | #If the buffer length is lower than n then stakcing the data value |
|
1443 | 1465 | if self.__profIndex < self.n: |
|
1444 | 1466 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
1445 | 1467 | |
|
1446 | 1468 | if data_cspc != None: |
|
1447 | 1469 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
1448 | 1470 | |
|
1449 | 1471 | if data_dc != None: |
|
1450 | 1472 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
1451 | 1473 | |
|
1452 | 1474 | self.__profIndex += 1 |
|
1453 | 1475 | return |
|
1454 | 1476 | |
|
1455 | 1477 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1456 | 1478 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
1457 | 1479 | self.__buffer_spc[self.n-1] = data_spc |
|
1458 | 1480 | |
|
1459 | 1481 | if data_cspc != None: |
|
1460 | 1482 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
1461 | 1483 | self.__buffer_cspc[self.n-1] = data_cspc |
|
1462 | 1484 | |
|
1463 | 1485 | if data_dc != None: |
|
1464 | 1486 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
1465 | 1487 | self.__buffer_dc[self.n-1] = data_dc |
|
1466 | 1488 | |
|
1467 | 1489 | self.__profIndex = self.n |
|
1468 | 1490 | return |
|
1469 | 1491 | |
|
1470 | 1492 | |
|
1471 | 1493 | def pushData(self): |
|
1472 | 1494 | """ |
|
1473 | 1495 | Return the sum of the last profiles and the profiles used in the sum. |
|
1474 | 1496 | |
|
1475 | 1497 | Affected: |
|
1476 | 1498 | |
|
1477 | 1499 | self.__profileIndex |
|
1478 | 1500 | |
|
1479 | 1501 | """ |
|
1480 | 1502 | data_spc = None |
|
1481 | 1503 | data_cspc = None |
|
1482 | 1504 | data_dc = None |
|
1483 | 1505 | |
|
1484 | 1506 | if not self.__withOverapping: |
|
1485 | 1507 | data_spc = self.__buffer_spc |
|
1486 | 1508 | data_cspc = self.__buffer_cspc |
|
1487 | 1509 | data_dc = self.__buffer_dc |
|
1488 | 1510 | |
|
1489 | 1511 | n = self.__profIndex |
|
1490 | 1512 | |
|
1491 | 1513 | self.__buffer_spc = 0 |
|
1492 | 1514 | self.__buffer_cspc = 0 |
|
1493 | 1515 | self.__buffer_dc = 0 |
|
1494 | 1516 | self.__profIndex = 0 |
|
1495 | 1517 | |
|
1496 | 1518 | return data_spc, data_cspc, data_dc, n |
|
1497 | 1519 | |
|
1498 | 1520 | #Integration with Overlapping |
|
1499 | 1521 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
1500 | 1522 | |
|
1501 | 1523 | if self.__buffer_cspc != None: |
|
1502 | 1524 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
1503 | 1525 | |
|
1504 | 1526 | if self.__buffer_dc != None: |
|
1505 | 1527 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
1506 | 1528 | |
|
1507 | 1529 | n = self.__profIndex |
|
1508 | 1530 | |
|
1509 | 1531 | return data_spc, data_cspc, data_dc, n |
|
1510 | 1532 | |
|
1511 | 1533 | def byProfiles(self, *args): |
|
1512 | 1534 | |
|
1513 | 1535 | self.__dataReady = False |
|
1514 | 1536 | avgdata_spc = None |
|
1515 | 1537 | avgdata_cspc = None |
|
1516 | 1538 | avgdata_dc = None |
|
1517 | 1539 | n = None |
|
1518 | 1540 | |
|
1519 | 1541 | self.putData(*args) |
|
1520 | 1542 | |
|
1521 | 1543 | if self.__profIndex == self.n: |
|
1522 | 1544 | |
|
1523 | 1545 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1524 | 1546 | self.__dataReady = True |
|
1525 | 1547 | |
|
1526 | 1548 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1527 | 1549 | |
|
1528 | 1550 | def byTime(self, datatime, *args): |
|
1529 | 1551 | |
|
1530 | 1552 | self.__dataReady = False |
|
1531 | 1553 | avgdata_spc = None |
|
1532 | 1554 | avgdata_cspc = None |
|
1533 | 1555 | avgdata_dc = None |
|
1534 | 1556 | n = None |
|
1535 | 1557 | |
|
1536 | 1558 | self.putData(*args) |
|
1537 | 1559 | |
|
1538 | 1560 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1539 | 1561 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1540 | 1562 | self.n = n |
|
1541 | 1563 | self.__dataReady = True |
|
1542 | 1564 | |
|
1543 | 1565 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1544 | 1566 | |
|
1545 | 1567 | def integrate(self, datatime, *args): |
|
1546 | 1568 | |
|
1547 | 1569 | if self.__initime == None: |
|
1548 | 1570 | self.__initime = datatime |
|
1549 | 1571 | |
|
1550 | 1572 | if self.__byTime: |
|
1551 | 1573 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
1552 | 1574 | else: |
|
1553 | 1575 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1554 | 1576 | |
|
1555 | 1577 | self.__lastdatatime = datatime |
|
1556 | 1578 | |
|
1557 | 1579 | if avgdata_spc == None: |
|
1558 | 1580 | return None, None, None, None |
|
1559 | 1581 | |
|
1560 | 1582 | avgdatatime = self.__initime |
|
1561 | 1583 | try: |
|
1562 | 1584 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
1563 | 1585 | except: |
|
1564 | 1586 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
1565 | 1587 | |
|
1566 | 1588 | deltatime = datatime -self.__lastdatatime |
|
1567 | 1589 | |
|
1568 | 1590 | if not self.__withOverapping: |
|
1569 | 1591 | self.__initime = datatime |
|
1570 | 1592 | else: |
|
1571 | 1593 | self.__initime += deltatime |
|
1572 | 1594 | |
|
1573 | 1595 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1574 | 1596 | |
|
1575 | 1597 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1576 | 1598 | |
|
1577 | 1599 | if n==1: |
|
1578 | 1600 | dataOut.flagNoData = False |
|
1579 | 1601 | return |
|
1580 | 1602 | |
|
1581 | 1603 | if not self.__isConfig: |
|
1582 | 1604 | self.setup(n, timeInterval, overlapping) |
|
1583 | 1605 | self.__isConfig = True |
|
1584 | 1606 | |
|
1585 | 1607 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1586 | 1608 | dataOut.data_spc, |
|
1587 | 1609 | dataOut.data_cspc, |
|
1588 | 1610 | dataOut.data_dc) |
|
1589 | 1611 | |
|
1590 | 1612 | # dataOut.timeInterval *= n |
|
1591 | 1613 | dataOut.flagNoData = True |
|
1592 | 1614 | |
|
1593 | 1615 | if self.__dataReady: |
|
1594 | 1616 | |
|
1595 | 1617 | dataOut.data_spc = avgdata_spc |
|
1596 | 1618 | dataOut.data_cspc = avgdata_cspc |
|
1597 | 1619 | dataOut.data_dc = avgdata_dc |
|
1598 | 1620 | |
|
1599 | 1621 | dataOut.nIncohInt *= self.n |
|
1600 | 1622 | dataOut.utctime = avgdatatime |
|
1601 | 1623 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
1602 | 1624 | dataOut.timeInterval = self.__timeInterval*self.n |
|
1603 | 1625 | dataOut.flagNoData = False |
|
1604 | 1626 | |
|
1605 | 1627 | class ProfileConcat(Operation): |
|
1606 | 1628 | |
|
1607 | 1629 | __isConfig = False |
|
1608 | 1630 | buffer = None |
|
1609 | 1631 | |
|
1610 | 1632 | def __init__(self): |
|
1611 | 1633 | |
|
1612 | 1634 | self.profileIndex = 0 |
|
1613 | 1635 | |
|
1614 | 1636 | def reset(self): |
|
1615 | 1637 | self.buffer = numpy.zeros_like(self.buffer) |
|
1616 | 1638 | self.start_index = 0 |
|
1617 | 1639 | self.times = 1 |
|
1618 | 1640 | |
|
1619 | 1641 | def setup(self, data, m, n=1): |
|
1620 | 1642 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
1621 | 1643 | self.profiles = data.shape[1] |
|
1622 | 1644 | self.start_index = 0 |
|
1623 | 1645 | self.times = 1 |
|
1624 | 1646 | |
|
1625 | 1647 | def concat(self, data): |
|
1626 | 1648 | |
|
1627 | 1649 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() |
|
1628 | 1650 | self.start_index = self.start_index + self.profiles |
|
1629 | 1651 | |
|
1630 | 1652 | def run(self, dataOut, m): |
|
1631 | 1653 | |
|
1632 | 1654 | dataOut.flagNoData = True |
|
1633 | 1655 | |
|
1634 | 1656 | if not self.__isConfig: |
|
1635 | 1657 | self.setup(dataOut.data, m, 1) |
|
1636 | 1658 | self.__isConfig = True |
|
1637 | 1659 | |
|
1638 | 1660 | self.concat(dataOut.data) |
|
1639 | 1661 | self.times += 1 |
|
1640 | 1662 | if self.times > m: |
|
1641 | 1663 | dataOut.data = self.buffer |
|
1642 | 1664 | self.reset() |
|
1643 | 1665 | dataOut.flagNoData = False |
|
1644 | 1666 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
1645 | 1667 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1646 | 1668 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 |
|
1647 | 1669 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
1648 | 1670 | |
|
1649 | 1671 | |
|
1650 | 1672 | |
|
1651 | 1673 | class ProfileSelector(Operation): |
|
1652 | 1674 | |
|
1653 | 1675 | profileIndex = None |
|
1654 | 1676 | # Tamanho total de los perfiles |
|
1655 | 1677 | nProfiles = None |
|
1656 | 1678 | |
|
1657 | 1679 | def __init__(self): |
|
1658 | 1680 | |
|
1659 | 1681 | self.profileIndex = 0 |
|
1660 | 1682 | |
|
1661 | 1683 | def incIndex(self): |
|
1662 | 1684 | self.profileIndex += 1 |
|
1663 | 1685 | |
|
1664 | 1686 | if self.profileIndex >= self.nProfiles: |
|
1665 | 1687 | self.profileIndex = 0 |
|
1666 | 1688 | |
|
1667 | 1689 | def isProfileInRange(self, minIndex, maxIndex): |
|
1668 | 1690 | |
|
1669 | 1691 | if self.profileIndex < minIndex: |
|
1670 | 1692 | return False |
|
1671 | 1693 | |
|
1672 | 1694 | if self.profileIndex > maxIndex: |
|
1673 | 1695 | return False |
|
1674 | 1696 | |
|
1675 | 1697 | return True |
|
1676 | 1698 | |
|
1677 | 1699 | def isProfileInList(self, profileList): |
|
1678 | 1700 | |
|
1679 | 1701 | if self.profileIndex not in profileList: |
|
1680 | 1702 | return False |
|
1681 | 1703 | |
|
1682 | 1704 | return True |
|
1683 | 1705 | |
|
1684 | 1706 | def run(self, dataOut, profileList=None, profileRangeList=None): |
|
1685 | 1707 | |
|
1686 | 1708 | dataOut.flagNoData = True |
|
1687 | 1709 | self.nProfiles = dataOut.nProfiles |
|
1688 | 1710 | |
|
1689 | 1711 | if profileList != None: |
|
1690 | 1712 | if self.isProfileInList(profileList): |
|
1691 | 1713 | dataOut.flagNoData = False |
|
1692 | 1714 | |
|
1693 | 1715 | self.incIndex() |
|
1694 | 1716 | return 1 |
|
1695 | 1717 | |
|
1696 | 1718 | |
|
1697 | 1719 | elif profileRangeList != None: |
|
1698 | 1720 | minIndex = profileRangeList[0] |
|
1699 | 1721 | maxIndex = profileRangeList[1] |
|
1700 | 1722 | if self.isProfileInRange(minIndex, maxIndex): |
|
1701 | 1723 | dataOut.flagNoData = False |
|
1702 | 1724 | |
|
1703 | 1725 | self.incIndex() |
|
1704 | 1726 | return 1 |
|
1705 | 1727 | |
|
1706 | 1728 | else: |
|
1707 | 1729 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
1708 | 1730 | |
|
1709 | 1731 | return 0 |
|
1710 | 1732 | |
|
1711 | 1733 | class SpectraHeisProc(ProcessingUnit): |
|
1712 | 1734 | def __init__(self): |
|
1713 | 1735 | self.objectDict = {} |
|
1714 | 1736 | # self.buffer = None |
|
1715 | 1737 | # self.firstdatatime = None |
|
1716 | 1738 | # self.profIndex = 0 |
|
1717 | 1739 | self.dataOut = SpectraHeis() |
|
1718 | 1740 | |
|
1719 | 1741 | def __updateObjFromInput(self): |
|
1720 | 1742 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1721 | 1743 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
1722 | 1744 | self.dataOut.errorCount = self.dataIn.errorCount |
|
1723 | 1745 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
1724 | 1746 | |
|
1725 | 1747 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# |
|
1726 | 1748 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# |
|
1727 | 1749 | self.dataOut.channelList = self.dataIn.channelList |
|
1728 | 1750 | self.dataOut.heightList = self.dataIn.heightList |
|
1729 | 1751 | # self.dataOut.dtype = self.dataIn.dtype |
|
1730 | 1752 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1731 | 1753 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
1732 | 1754 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
1733 | 1755 | self.dataOut.nBaud = self.dataIn.nBaud |
|
1734 | 1756 | self.dataOut.nCode = self.dataIn.nCode |
|
1735 | 1757 | self.dataOut.code = self.dataIn.code |
|
1736 | 1758 | # self.dataOut.nProfiles = 1 |
|
1737 | 1759 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
1738 | 1760 | self.dataOut.nFFTPoints = self.dataIn.nHeights |
|
1739 | 1761 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1740 | 1762 | # self.dataOut.flagNoData = self.dataIn.flagNoData |
|
1741 | 1763 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
1742 | 1764 | self.dataOut.utctime = self.dataIn.utctime |
|
1743 | 1765 | # self.dataOut.utctime = self.firstdatatime |
|
1744 | 1766 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
1745 | 1767 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
1746 | 1768 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
1747 | 1769 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
1748 | 1770 | self.dataOut.nIncohInt = 1 |
|
1749 | 1771 | self.dataOut.ippSeconds= self.dataIn.ippSeconds |
|
1750 | 1772 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
1751 | 1773 | |
|
1752 | 1774 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt |
|
1753 | 1775 | # self.dataOut.set=self.dataIn.set |
|
1754 | 1776 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight |
|
1755 | 1777 | |
|
1756 | 1778 | |
|
1757 | 1779 | def __updateObjFromFits(self): |
|
1758 | 1780 | self.dataOut.utctime = self.dataIn.utctime |
|
1759 | 1781 | self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1760 | 1782 | |
|
1761 | 1783 | self.dataOut.channelList = self.dataIn.channelList |
|
1762 | 1784 | self.dataOut.heightList = self.dataIn.heightList |
|
1763 | 1785 | self.dataOut.data_spc = self.dataIn.data |
|
1764 | 1786 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
1765 | 1787 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1766 | 1788 | self.dataOut.useLocalTime = True |
|
1767 | 1789 | # self.dataOut. |
|
1768 | 1790 | # self.dataOut. |
|
1769 | 1791 | |
|
1770 | 1792 | def __getFft(self): |
|
1771 | 1793 | |
|
1772 | 1794 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) |
|
1773 | 1795 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
1774 | 1796 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) |
|
1775 | 1797 | self.dataOut.data_spc = spc |
|
1776 | 1798 | |
|
1777 | 1799 | def init(self): |
|
1778 | 1800 | |
|
1779 | 1801 | self.dataOut.flagNoData = True |
|
1780 | 1802 | |
|
1781 | 1803 | if self.dataIn.type == "Fits": |
|
1782 | 1804 | self.__updateObjFromFits() |
|
1783 | 1805 | self.dataOut.flagNoData = False |
|
1784 | 1806 | return |
|
1785 | 1807 | |
|
1786 | 1808 | if self.dataIn.type == "SpectraHeis": |
|
1787 | 1809 | self.dataOut.copy(self.dataIn) |
|
1788 | 1810 | return |
|
1789 | 1811 | |
|
1790 | 1812 | if self.dataIn.type == "Voltage": |
|
1791 | 1813 | self.__updateObjFromInput() |
|
1792 | 1814 | self.__getFft() |
|
1793 | 1815 | self.dataOut.flagNoData = False |
|
1794 | 1816 | |
|
1795 | 1817 | return |
|
1796 | 1818 | |
|
1797 | 1819 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
1798 | 1820 | |
|
1799 | 1821 | |
|
1800 | 1822 | def selectChannels(self, channelList): |
|
1801 | 1823 | |
|
1802 | 1824 | channelIndexList = [] |
|
1803 | 1825 | |
|
1804 | 1826 | for channel in channelList: |
|
1805 | 1827 | index = self.dataOut.channelList.index(channel) |
|
1806 | 1828 | channelIndexList.append(index) |
|
1807 | 1829 | |
|
1808 | 1830 | self.selectChannelsByIndex(channelIndexList) |
|
1809 | 1831 | |
|
1810 | 1832 | def selectChannelsByIndex(self, channelIndexList): |
|
1811 | 1833 | """ |
|
1812 | 1834 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
1813 | 1835 | |
|
1814 | 1836 | Input: |
|
1815 | 1837 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
1816 | 1838 | |
|
1817 | 1839 | Affected: |
|
1818 | 1840 | self.dataOut.data |
|
1819 | 1841 | self.dataOut.channelIndexList |
|
1820 | 1842 | self.dataOut.nChannels |
|
1821 | 1843 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
1822 | 1844 | self.dataOut.systemHeaderObj.numChannels |
|
1823 | 1845 | self.dataOut.m_ProcessingHeader.blockSize |
|
1824 | 1846 | |
|
1825 | 1847 | Return: |
|
1826 | 1848 | None |
|
1827 | 1849 | """ |
|
1828 | 1850 | |
|
1829 | 1851 | for channelIndex in channelIndexList: |
|
1830 | 1852 | if channelIndex not in self.dataOut.channelIndexList: |
|
1831 | 1853 | print channelIndexList |
|
1832 | 1854 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
1833 | 1855 | |
|
1834 | 1856 | nChannels = len(channelIndexList) |
|
1835 | 1857 | |
|
1836 | 1858 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
1837 | 1859 | |
|
1838 | 1860 | self.dataOut.data_spc = data_spc |
|
1839 | 1861 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
1840 | 1862 | |
|
1841 | 1863 | return 1 |
|
1842 | 1864 | |
|
1843 | 1865 | class IncohInt4SpectraHeis(Operation): |
|
1844 | 1866 | |
|
1845 | 1867 | __isConfig = False |
|
1846 | 1868 | |
|
1847 | 1869 | __profIndex = 0 |
|
1848 | 1870 | __withOverapping = False |
|
1849 | 1871 | |
|
1850 | 1872 | __byTime = False |
|
1851 | 1873 | __initime = None |
|
1852 | 1874 | __lastdatatime = None |
|
1853 | 1875 | __integrationtime = None |
|
1854 | 1876 | |
|
1855 | 1877 | __buffer = None |
|
1856 | 1878 | |
|
1857 | 1879 | __dataReady = False |
|
1858 | 1880 | |
|
1859 | 1881 | n = None |
|
1860 | 1882 | |
|
1861 | 1883 | |
|
1862 | 1884 | def __init__(self): |
|
1863 | 1885 | |
|
1864 | 1886 | self.__isConfig = False |
|
1865 | 1887 | |
|
1866 | 1888 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1867 | 1889 | """ |
|
1868 | 1890 | Set the parameters of the integration class. |
|
1869 | 1891 | |
|
1870 | 1892 | Inputs: |
|
1871 | 1893 | |
|
1872 | 1894 | n : Number of coherent integrations |
|
1873 | 1895 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1874 | 1896 | overlapping : |
|
1875 | 1897 | |
|
1876 | 1898 | """ |
|
1877 | 1899 | |
|
1878 | 1900 | self.__initime = None |
|
1879 | 1901 | self.__lastdatatime = 0 |
|
1880 | 1902 | self.__buffer = None |
|
1881 | 1903 | self.__dataReady = False |
|
1882 | 1904 | |
|
1883 | 1905 | |
|
1884 | 1906 | if n == None and timeInterval == None: |
|
1885 | 1907 | raise ValueError, "n or timeInterval should be specified ..." |
|
1886 | 1908 | |
|
1887 | 1909 | if n != None: |
|
1888 | 1910 | self.n = n |
|
1889 | 1911 | self.__byTime = False |
|
1890 | 1912 | else: |
|
1891 | 1913 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
1892 | 1914 | self.n = 9999 |
|
1893 | 1915 | self.__byTime = True |
|
1894 | 1916 | |
|
1895 | 1917 | if overlapping: |
|
1896 | 1918 | self.__withOverapping = True |
|
1897 | 1919 | self.__buffer = None |
|
1898 | 1920 | else: |
|
1899 | 1921 | self.__withOverapping = False |
|
1900 | 1922 | self.__buffer = 0 |
|
1901 | 1923 | |
|
1902 | 1924 | self.__profIndex = 0 |
|
1903 | 1925 | |
|
1904 | 1926 | def putData(self, data): |
|
1905 | 1927 | |
|
1906 | 1928 | """ |
|
1907 | 1929 | Add a profile to the __buffer and increase in one the __profileIndex |
|
1908 | 1930 | |
|
1909 | 1931 | """ |
|
1910 | 1932 | |
|
1911 | 1933 | if not self.__withOverapping: |
|
1912 | 1934 | self.__buffer += data.copy() |
|
1913 | 1935 | self.__profIndex += 1 |
|
1914 | 1936 | return |
|
1915 | 1937 | |
|
1916 | 1938 | #Overlapping data |
|
1917 | 1939 | nChannels, nHeis = data.shape |
|
1918 | 1940 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
1919 | 1941 | |
|
1920 | 1942 | #If the buffer is empty then it takes the data value |
|
1921 | 1943 | if self.__buffer == None: |
|
1922 | 1944 | self.__buffer = data |
|
1923 | 1945 | self.__profIndex += 1 |
|
1924 | 1946 | return |
|
1925 | 1947 | |
|
1926 | 1948 | #If the buffer length is lower than n then stakcing the data value |
|
1927 | 1949 | if self.__profIndex < self.n: |
|
1928 | 1950 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
1929 | 1951 | self.__profIndex += 1 |
|
1930 | 1952 | return |
|
1931 | 1953 | |
|
1932 | 1954 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1933 | 1955 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
1934 | 1956 | self.__buffer[self.n-1] = data |
|
1935 | 1957 | self.__profIndex = self.n |
|
1936 | 1958 | return |
|
1937 | 1959 | |
|
1938 | 1960 | |
|
1939 | 1961 | def pushData(self): |
|
1940 | 1962 | """ |
|
1941 | 1963 | Return the sum of the last profiles and the profiles used in the sum. |
|
1942 | 1964 | |
|
1943 | 1965 | Affected: |
|
1944 | 1966 | |
|
1945 | 1967 | self.__profileIndex |
|
1946 | 1968 | |
|
1947 | 1969 | """ |
|
1948 | 1970 | |
|
1949 | 1971 | if not self.__withOverapping: |
|
1950 | 1972 | data = self.__buffer |
|
1951 | 1973 | n = self.__profIndex |
|
1952 | 1974 | |
|
1953 | 1975 | self.__buffer = 0 |
|
1954 | 1976 | self.__profIndex = 0 |
|
1955 | 1977 | |
|
1956 | 1978 | return data, n |
|
1957 | 1979 | |
|
1958 | 1980 | #Integration with Overlapping |
|
1959 | 1981 | data = numpy.sum(self.__buffer, axis=0) |
|
1960 | 1982 | n = self.__profIndex |
|
1961 | 1983 | |
|
1962 | 1984 | return data, n |
|
1963 | 1985 | |
|
1964 | 1986 | def byProfiles(self, data): |
|
1965 | 1987 | |
|
1966 | 1988 | self.__dataReady = False |
|
1967 | 1989 | avgdata = None |
|
1968 | 1990 | n = None |
|
1969 | 1991 | |
|
1970 | 1992 | self.putData(data) |
|
1971 | 1993 | |
|
1972 | 1994 | if self.__profIndex == self.n: |
|
1973 | 1995 | |
|
1974 | 1996 | avgdata, n = self.pushData() |
|
1975 | 1997 | self.__dataReady = True |
|
1976 | 1998 | |
|
1977 | 1999 | return avgdata |
|
1978 | 2000 | |
|
1979 | 2001 | def byTime(self, data, datatime): |
|
1980 | 2002 | |
|
1981 | 2003 | self.__dataReady = False |
|
1982 | 2004 | avgdata = None |
|
1983 | 2005 | n = None |
|
1984 | 2006 | |
|
1985 | 2007 | self.putData(data) |
|
1986 | 2008 | |
|
1987 | 2009 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1988 | 2010 | avgdata, n = self.pushData() |
|
1989 | 2011 | self.n = n |
|
1990 | 2012 | self.__dataReady = True |
|
1991 | 2013 | |
|
1992 | 2014 | return avgdata |
|
1993 | 2015 | |
|
1994 | 2016 | def integrate(self, data, datatime=None): |
|
1995 | 2017 | |
|
1996 | 2018 | if self.__initime == None: |
|
1997 | 2019 | self.__initime = datatime |
|
1998 | 2020 | |
|
1999 | 2021 | if self.__byTime: |
|
2000 | 2022 | avgdata = self.byTime(data, datatime) |
|
2001 | 2023 | else: |
|
2002 | 2024 | avgdata = self.byProfiles(data) |
|
2003 | 2025 | |
|
2004 | 2026 | |
|
2005 | 2027 | self.__lastdatatime = datatime |
|
2006 | 2028 | |
|
2007 | 2029 | if avgdata == None: |
|
2008 | 2030 | return None, None |
|
2009 | 2031 | |
|
2010 | 2032 | avgdatatime = self.__initime |
|
2011 | 2033 | |
|
2012 | 2034 | deltatime = datatime -self.__lastdatatime |
|
2013 | 2035 | |
|
2014 | 2036 | if not self.__withOverapping: |
|
2015 | 2037 | self.__initime = datatime |
|
2016 | 2038 | else: |
|
2017 | 2039 | self.__initime += deltatime |
|
2018 | 2040 | |
|
2019 | 2041 | return avgdata, avgdatatime |
|
2020 | 2042 | |
|
2021 | 2043 | def run(self, dataOut, **kwargs): |
|
2022 | 2044 | |
|
2023 | 2045 | if not self.__isConfig: |
|
2024 | 2046 | self.setup(**kwargs) |
|
2025 | 2047 | self.__isConfig = True |
|
2026 | 2048 | |
|
2027 | 2049 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
2028 | 2050 | |
|
2029 | 2051 | # dataOut.timeInterval *= n |
|
2030 | 2052 | dataOut.flagNoData = True |
|
2031 | 2053 | |
|
2032 | 2054 | if self.__dataReady: |
|
2033 | 2055 | dataOut.data_spc = avgdata |
|
2034 | 2056 | dataOut.nIncohInt *= self.n |
|
2035 | 2057 | # dataOut.nCohInt *= self.n |
|
2036 | 2058 | dataOut.utctime = avgdatatime |
|
2037 | 2059 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt |
|
2038 | 2060 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
2039 | 2061 | dataOut.flagNoData = False |
|
2040 | 2062 | |
|
2041 | 2063 | |
|
2042 | 2064 | |
|
2043 | 2065 | |
|
2044 | 2066 | No newline at end of file |
@@ -1,118 +1,121 | |||
|
1 | 1 | import os, sys |
|
2 | 2 | |
|
3 | 3 | path = os.path.split(os.getcwd())[0] |
|
4 | 4 | sys.path.append(path) |
|
5 | 5 | |
|
6 | 6 | from controller import * |
|
7 | 7 | |
|
8 | 8 | desc = "EWDrifts Experiment Test" |
|
9 | 9 | filename = "ewdrifts2.xml" |
|
10 | 10 | |
|
11 | 11 | controllerObj = Project() |
|
12 | 12 | |
|
13 | 13 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
14 | 14 | |
|
15 | 15 | path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift' |
|
16 | 16 | |
|
17 | 17 | path = '/Users/dsuarez/Documents/Radar/drifts' |
|
18 | 18 | path = '/Users/dsuarez/Documents/EW_DRIFT_WITH_TR' |
|
19 | path = '/home/administrator/Radar/drifts/2014' | |
|
19 | 20 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
20 | 21 | path=path, |
|
21 |
startDate='201 |
|
|
22 |
endDate='201 |
|
|
23 |
startTime=' |
|
|
22 | startDate='2014/01/11', | |
|
23 | endDate='2014/12/12', | |
|
24 | startTime='00:00:00', | |
|
24 | 25 | endTime='23:59:59', |
|
25 | 26 | online=0, |
|
26 | 27 | delay=5, |
|
27 | 28 | walk=0) |
|
28 | 29 | |
|
29 | 30 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
30 | 31 | |
|
31 |
opObj11 = procUnitConfObj0.addOperation(name=' |
|
|
32 | opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist') | |
|
33 | ||
|
34 | opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') | |
|
35 | opObj11.addParameter(name='window', value='3', format='int') | |
|
36 | ||
|
37 | opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
38 | ||
|
39 | ||
|
40 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
|
41 | procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int') | |
|
42 | procUnitConfObj1.addParameter(name='nProfiles', value='128', format='int') | |
|
43 | ||
|
44 | ||
|
45 | opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
46 | opObj11.addParameter(name='timeInterval', value='60', format='float') | |
|
47 | ||
|
48 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
|
49 | opObj11.addParameter(name='id', value='100', format='int') | |
|
50 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
|
51 | #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') | |
|
52 | # opObj11.addParameter(name='zmin', value='0', format='int') | |
|
53 | # opObj11.addParameter(name='zmax', value='100', format='int') | |
|
54 | opObj11.addParameter(name='showprofile', value='0', format='int') | |
|
55 | opObj11.addParameter(name='save', value='1', format='bool') | |
|
56 | opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') | |
|
57 | ||
|
58 | ||
|
59 | opObj11 = procUnitConfObj1.addOperation(name='Noise', optype='other') | |
|
32 | opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='other') | |
|
60 | 33 | opObj11.addParameter(name='id', value='101', format='int') |
|
61 |
opObj11.addParameter(name='wintitle', value=' |
|
|
62 | opObj11.addParameter(name='xmin', value='10', format='float') | |
|
63 | opObj11.addParameter(name='xmax', value='11.5', format='float') | |
|
64 | opObj11.addParameter(name='ymin', value='55', format='float') | |
|
65 | opObj11.addParameter(name='ymax', value='65', format='float') | |
|
66 | opObj11.addParameter(name='save', value='1', format='bool') | |
|
67 | opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') | |
|
68 | ||
|
69 | ||
|
34 | opObj11.addParameter(name='wintitle', value='AMISR', format='str') | |
|
70 | 35 | |
|
36 | # | |
|
37 | # opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other') | |
|
38 | # opObj11.addParameter(name='profileRangeList', value='0,127', format='intlist') | |
|
39 | # | |
|
40 | # opObj11 = procUnitConfObj0.addOperation(name='filterByHeights') | |
|
41 | # opObj11.addParameter(name='window', value='3', format='int') | |
|
42 | # | |
|
43 | # opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other') | |
|
44 | # | |
|
45 | # | |
|
46 | # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) | |
|
47 | # procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int') | |
|
48 | # procUnitConfObj1.addParameter(name='nProfiles', value='128', format='int') | |
|
49 | # | |
|
50 | # | |
|
51 | # opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
52 | # opObj11.addParameter(name='timeInterval', value='60', format='float') | |
|
53 | # | |
|
54 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
|
55 | # opObj11.addParameter(name='id', value='100', format='int') | |
|
56 | # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
|
57 | # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') | |
|
58 | # # opObj11.addParameter(name='zmin', value='0', format='int') | |
|
59 | # # opObj11.addParameter(name='zmax', value='100', format='int') | |
|
60 | # opObj11.addParameter(name='showprofile', value='0', format='int') | |
|
61 | # opObj11.addParameter(name='save', value='1', format='bool') | |
|
62 | # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') | |
|
63 | # | |
|
64 | # | |
|
65 | # opObj11 = procUnitConfObj1.addOperation(name='Noise', optype='other') | |
|
66 | # opObj11.addParameter(name='id', value='101', format='int') | |
|
67 | # opObj11.addParameter(name='wintitle', value='TR800KW', format='str') | |
|
68 | # opObj11.addParameter(name='xmin', value='10', format='float') | |
|
69 | # opObj11.addParameter(name='xmax', value='11.5', format='float') | |
|
70 | # opObj11.addParameter(name='ymin', value='55', format='float') | |
|
71 | # opObj11.addParameter(name='ymax', value='65', format='float') | |
|
72 | # opObj11.addParameter(name='save', value='1', format='bool') | |
|
73 | # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') | |
|
71 | 74 | |
|
72 | 75 | # |
|
73 | 76 | #opObj11 = procUnitConfObj1.addOperation(name='PowerProfilePlot', optype='other') |
|
74 | 77 | #opObj11.addParameter(name='idfigure', value='2', format='int') |
|
75 | 78 | #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') |
|
76 | 79 | #opObj11.addParameter(name='save', value='1', format='bool') |
|
77 | 80 | #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str') |
|
78 | 81 | ##opObj11.addParameter(name='xmin', value='10', format='int') |
|
79 | 82 | ##opObj11.addParameter(name='xmax', value='40', format='int') |
|
80 | 83 | # |
|
81 | 84 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') |
|
82 | 85 | # opObj11.addParameter(name='idfigure', value='3', format='int') |
|
83 | 86 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') |
|
84 | 87 | # #opObj11.addParameter(name='save', value='1', format='bool') |
|
85 | 88 | # #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str') |
|
86 | 89 | # ##opObj11.addParameter(name='zmin', value='10', format='int') |
|
87 | 90 | # ##opObj11.addParameter(name='zmax', value='40', format='int') |
|
88 | 91 | # ##opObj11.addParameter(name='save', value='1', format='bool') |
|
89 | 92 | # ##opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/cross_spc', format='str') |
|
90 | 93 | # opObj11.addParameter(name='zmin', value='20', format='int') |
|
91 | 94 | # opObj11.addParameter(name='zmax', value='40', format='int') |
|
92 | 95 | # opObj11.addParameter(name='save', value='1', format='bool') |
|
93 | 96 | # opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/ew_drifts_mz', format='str') |
|
94 | 97 | # |
|
95 | # | |
|
96 | opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
|
97 | opObj11.addParameter(name='id', value='102', format='int') | |
|
98 | opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') | |
|
99 | opObj11.addParameter(name='xmin', value='10', format='float') | |
|
100 | opObj11.addParameter(name='xmax', value='11.5', format='float') | |
|
101 | # opObj11.addParameter(name='zmin', value='20', format='int') | |
|
102 | # opObj11.addParameter(name='zmax', value='40', format='int') | |
|
103 | # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') | |
|
104 | # #opObj11.addParameter(name='timerange', value='86400', format='int') | |
|
105 | opObj11.addParameter(name='showprofile', value='0', format='int') | |
|
106 | opObj11.addParameter(name='save', value='1', format='bool') | |
|
107 | opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') | |
|
98 | # # | |
|
99 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
|
100 | # opObj11.addParameter(name='id', value='102', format='int') | |
|
101 | # opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') | |
|
102 | # opObj11.addParameter(name='xmin', value='10', format='float') | |
|
103 | # opObj11.addParameter(name='xmax', value='11.5', format='float') | |
|
104 | # # opObj11.addParameter(name='zmin', value='20', format='int') | |
|
105 | # # opObj11.addParameter(name='zmax', value='40', format='int') | |
|
106 | # # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') | |
|
107 | # # #opObj11.addParameter(name='timerange', value='86400', format='int') | |
|
108 | # opObj11.addParameter(name='showprofile', value='0', format='int') | |
|
109 | # opObj11.addParameter(name='save', value='1', format='bool') | |
|
110 | # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') | |
|
108 | 111 | |
|
109 | 112 | print "Escribiendo el archivo XML" |
|
110 | 113 | controllerObj.writeXml(filename) |
|
111 | 114 | print "Leyendo el archivo XML" |
|
112 | 115 | controllerObj.readXml(filename) |
|
113 | 116 | |
|
114 | 117 | controllerObj.createObjects() |
|
115 | 118 | controllerObj.connectObjects() |
|
116 | 119 | controllerObj.run() |
|
117 | 120 | |
|
118 | 121 |
General Comments 0
You need to be logged in to leave comments.
Login now