The requested changes are too big and content was truncated. Show full diff
@@ -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 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -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