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 | import numpy |
|
1 | import numpy | |
2 | import datetime |
|
2 | import datetime | |
3 | import sys |
|
3 | import sys | |
4 | import matplotlib |
|
4 | import matplotlib | |
5 |
|
5 | |||
6 | if 'linux' in sys.platform: |
|
6 | if 'linux' in sys.platform: | |
7 | matplotlib.use("TKAgg") |
|
7 | matplotlib.use("TKAgg") | |
8 |
|
8 | |||
9 | if 'darwin' in sys.platform: |
|
9 | if 'darwin' in sys.platform: | |
10 | matplotlib.use("GTKAgg") |
|
10 | matplotlib.use("GTKAgg") | |
11 |
|
11 | |||
12 | import matplotlib.pyplot |
|
12 | import matplotlib.pyplot | |
13 |
|
13 | |||
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
14 | from mpl_toolkits.axes_grid1 import make_axes_locatable | |
15 | from matplotlib.ticker import * |
|
15 | from matplotlib.ticker import * | |
16 |
|
16 | |||
17 | ########################################### |
|
17 | ########################################### | |
18 | #Actualizacion de las funciones del driver |
|
18 | #Actualizacion de las funciones del driver | |
19 | ########################################### |
|
19 | ########################################### | |
20 |
|
20 | |||
21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): |
|
21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): | |
22 |
|
22 | |||
23 | matplotlib.pyplot.ioff() |
|
23 | matplotlib.pyplot.ioff() | |
24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) |
|
24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) | |
25 | fig.canvas.manager.set_window_title(wintitle) |
|
25 | fig.canvas.manager.set_window_title(wintitle) | |
26 | fig.canvas.manager.resize(width, height) |
|
26 | fig.canvas.manager.resize(width, height) | |
27 | matplotlib.pyplot.ion() |
|
27 | matplotlib.pyplot.ion() | |
28 | if show: |
|
28 | if show: | |
29 | matplotlib.pyplot.show() |
|
29 | matplotlib.pyplot.show() | |
30 |
|
30 | |||
31 | return fig |
|
31 | return fig | |
32 |
|
32 | |||
33 | def closeFigure(show=True): |
|
33 | def closeFigure(show=True): | |
34 |
|
34 | |||
35 | matplotlib.pyplot.ioff() |
|
35 | matplotlib.pyplot.ioff() | |
36 | if show: |
|
36 | if show: | |
37 | matplotlib.pyplot.show() |
|
37 | matplotlib.pyplot.show() | |
38 |
|
38 | |||
39 | return |
|
39 | return | |
40 |
|
40 | |||
41 | def saveFigure(fig, filename): |
|
41 | def saveFigure(fig, filename): | |
42 |
|
42 | |||
43 | matplotlib.pyplot.ioff() |
|
43 | matplotlib.pyplot.ioff() | |
44 | fig.savefig(filename) |
|
44 | fig.savefig(filename) | |
45 | matplotlib.pyplot.ion() |
|
45 | matplotlib.pyplot.ion() | |
46 |
|
46 | |||
47 | def setWinTitle(fig, title): |
|
47 | def setWinTitle(fig, title): | |
48 |
|
48 | |||
49 | fig.canvas.manager.set_window_title(title) |
|
49 | fig.canvas.manager.set_window_title(title) | |
50 |
|
50 | |||
51 | def setTitle(fig, title): |
|
51 | def setTitle(fig, title): | |
52 |
|
52 | |||
53 | fig.suptitle(title) |
|
53 | fig.suptitle(title) | |
54 |
|
54 | |||
55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
56 |
|
56 | |||
57 | matplotlib.pyplot.ioff() |
|
57 | matplotlib.pyplot.ioff() | |
58 | matplotlib.pyplot.figure(fig.number) |
|
58 | matplotlib.pyplot.figure(fig.number) | |
59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
60 | (xpos, ypos), |
|
60 | (xpos, ypos), | |
61 | colspan=colspan, |
|
61 | colspan=colspan, | |
62 | rowspan=rowspan) |
|
62 | rowspan=rowspan) | |
63 |
|
63 | |||
64 | matplotlib.pyplot.ion() |
|
64 | matplotlib.pyplot.ion() | |
65 | return axes |
|
65 | return axes | |
66 |
|
66 | |||
67 | def setAxesText(ax, text): |
|
67 | def setAxesText(ax, text): | |
68 |
|
68 | |||
69 | ax.annotate(text, |
|
69 | ax.annotate(text, | |
70 | xy = (.1, .99), |
|
70 | xy = (.1, .99), | |
71 | xycoords = 'figure fraction', |
|
71 | xycoords = 'figure fraction', | |
72 | horizontalalignment = 'left', |
|
72 | horizontalalignment = 'left', | |
73 | verticalalignment = 'top', |
|
73 | verticalalignment = 'top', | |
74 | fontsize = 10) |
|
74 | fontsize = 10) | |
75 |
|
75 | |||
76 | def printLabels(ax, xlabel, ylabel, title): |
|
76 | def printLabels(ax, xlabel, ylabel, title): | |
77 |
|
77 | |||
78 | ax.set_xlabel(xlabel, size=11) |
|
78 | ax.set_xlabel(xlabel, size=11) | |
79 | ax.set_ylabel(ylabel, size=11) |
|
79 | ax.set_ylabel(ylabel, size=11) | |
80 | ax.set_title(title, size=12) |
|
80 | ax.set_title(title, size=12) | |
81 |
|
81 | |||
82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
82 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', | |
83 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
83 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
84 | nxticks=4, nyticks=10, |
|
84 | nxticks=4, nyticks=10, | |
85 | grid=None): |
|
85 | grid=None,color='blue'): | |
86 |
|
86 | |||
87 | """ |
|
87 | """ | |
88 |
|
88 | |||
89 | Input: |
|
89 | Input: | |
90 | grid : None, 'both', 'x', 'y' |
|
90 | grid : None, 'both', 'x', 'y' | |
91 | """ |
|
91 | """ | |
92 |
|
92 | |||
93 | matplotlib.pyplot.ioff() |
|
93 | matplotlib.pyplot.ioff() | |
94 |
|
94 | |||
95 | ax.set_xlim([xmin,xmax]) |
|
95 | ax.set_xlim([xmin,xmax]) | |
96 | ax.set_ylim([ymin,ymax]) |
|
96 | ax.set_ylim([ymin,ymax]) | |
97 |
|
97 | |||
98 | printLabels(ax, xlabel, ylabel, title) |
|
98 | printLabels(ax, xlabel, ylabel, title) | |
99 |
|
99 | |||
100 | ###################################################### |
|
100 | ###################################################### | |
101 | if (xmax-xmin)<=1: |
|
101 | if (xmax-xmin)<=1: | |
102 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
102 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
103 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
103 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
104 | ax.set_xticks(xtickspos) |
|
104 | ax.set_xticks(xtickspos) | |
105 | else: |
|
105 | else: | |
106 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
106 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
107 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
107 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) | |
108 | ax.set_xticks(xtickspos) |
|
108 | ax.set_xticks(xtickspos) | |
109 |
|
109 | |||
110 | for tick in ax.get_xticklabels(): |
|
110 | for tick in ax.get_xticklabels(): | |
111 | tick.set_visible(xtick_visible) |
|
111 | tick.set_visible(xtick_visible) | |
112 |
|
112 | |||
113 | for tick in ax.xaxis.get_major_ticks(): |
|
113 | for tick in ax.xaxis.get_major_ticks(): | |
114 | tick.label.set_fontsize(ticksize) |
|
114 | tick.label.set_fontsize(ticksize) | |
115 |
|
115 | |||
116 | ###################################################### |
|
116 | ###################################################### | |
117 | for tick in ax.get_yticklabels(): |
|
117 | for tick in ax.get_yticklabels(): | |
118 | tick.set_visible(ytick_visible) |
|
118 | tick.set_visible(ytick_visible) | |
119 |
|
119 | |||
120 | for tick in ax.yaxis.get_major_ticks(): |
|
120 | for tick in ax.yaxis.get_major_ticks(): | |
121 | tick.label.set_fontsize(ticksize) |
|
121 | tick.label.set_fontsize(ticksize) | |
122 |
|
122 | |||
123 | ax.plot(x, y) |
|
123 | ax.plot(x, y, color=color) | |
124 | iplot = ax.lines[-1] |
|
124 | iplot = ax.lines[-1] | |
125 |
|
125 | |||
126 | ###################################################### |
|
126 | ###################################################### | |
127 | if '0.' in matplotlib.__version__[0:2]: |
|
127 | if '0.' in matplotlib.__version__[0:2]: | |
128 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
128 | print "The matplotlib version has to be updated to 1.1 or newer" | |
129 | return iplot |
|
129 | return iplot | |
130 |
|
130 | |||
131 | if '1.0.' in matplotlib.__version__[0:4]: |
|
131 | if '1.0.' in matplotlib.__version__[0:4]: | |
132 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
132 | print "The matplotlib version has to be updated to 1.1 or newer" | |
133 | return iplot |
|
133 | return iplot | |
134 |
|
134 | |||
135 | if grid != None: |
|
135 | if grid != None: | |
136 | ax.grid(b=True, which='major', axis=grid) |
|
136 | ax.grid(b=True, which='major', axis=grid) | |
137 |
|
137 | |||
138 | matplotlib.pyplot.tight_layout() |
|
138 | matplotlib.pyplot.tight_layout() | |
139 |
|
139 | |||
140 | matplotlib.pyplot.ion() |
|
140 | matplotlib.pyplot.ion() | |
141 |
|
141 | |||
142 | return iplot |
|
142 | return iplot | |
143 |
|
143 | |||
144 | def set_linedata(ax, x, y, idline): |
|
144 | def set_linedata(ax, x, y, idline): | |
145 |
|
145 | |||
146 | ax.lines[idline].set_data(x,y) |
|
146 | ax.lines[idline].set_data(x,y) | |
147 |
|
147 | |||
148 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
148 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
149 |
|
149 | |||
150 | ax = iplot.get_axes() |
|
150 | ax = iplot.get_axes() | |
151 |
|
151 | |||
152 | printLabels(ax, xlabel, ylabel, title) |
|
152 | printLabels(ax, xlabel, ylabel, title) | |
153 |
|
153 | |||
154 | set_linedata(ax, x, y, idline=0) |
|
154 | set_linedata(ax, x, y, idline=0) | |
155 |
|
155 | |||
156 | def addpline(ax, x, y, color, linestyle, lw): |
|
156 | def addpline(ax, x, y, color, linestyle, lw): | |
157 |
|
157 | |||
158 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
158 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) | |
159 |
|
159 | |||
160 |
|
160 | |||
161 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
161 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
162 | xlabel='', ylabel='', title='', ticksize = 9, |
|
162 | xlabel='', ylabel='', title='', ticksize = 9, | |
163 | colormap='jet',cblabel='', cbsize="5%", |
|
163 | colormap='jet',cblabel='', cbsize="5%", | |
164 | XAxisAsTime=False): |
|
164 | XAxisAsTime=False): | |
165 |
|
165 | |||
166 | matplotlib.pyplot.ioff() |
|
166 | matplotlib.pyplot.ioff() | |
167 |
|
167 | |||
168 | divider = make_axes_locatable(ax) |
|
168 | divider = make_axes_locatable(ax) | |
169 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
169 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
170 | fig = ax.get_figure() |
|
170 | fig = ax.get_figure() | |
171 | fig.add_axes(ax_cb) |
|
171 | fig.add_axes(ax_cb) | |
172 |
|
172 | |||
173 | ax.set_xlim([xmin,xmax]) |
|
173 | ax.set_xlim([xmin,xmax]) | |
174 | ax.set_ylim([ymin,ymax]) |
|
174 | ax.set_ylim([ymin,ymax]) | |
175 |
|
175 | |||
176 | printLabels(ax, xlabel, ylabel, title) |
|
176 | printLabels(ax, xlabel, ylabel, title) | |
177 |
|
177 | |||
178 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
178 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
179 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
179 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
180 | cb.set_label(cblabel) |
|
180 | cb.set_label(cblabel) | |
181 |
|
181 | |||
182 | # for tl in ax_cb.get_yticklabels(): |
|
182 | # for tl in ax_cb.get_yticklabels(): | |
183 | # tl.set_visible(True) |
|
183 | # tl.set_visible(True) | |
184 |
|
184 | |||
185 | for tick in ax.yaxis.get_major_ticks(): |
|
185 | for tick in ax.yaxis.get_major_ticks(): | |
186 | tick.label.set_fontsize(ticksize) |
|
186 | tick.label.set_fontsize(ticksize) | |
187 |
|
187 | |||
188 | for tick in ax.xaxis.get_major_ticks(): |
|
188 | for tick in ax.xaxis.get_major_ticks(): | |
189 | tick.label.set_fontsize(ticksize) |
|
189 | tick.label.set_fontsize(ticksize) | |
190 |
|
190 | |||
191 | for tick in cb.ax.get_yticklabels(): |
|
191 | for tick in cb.ax.get_yticklabels(): | |
192 | tick.set_fontsize(ticksize) |
|
192 | tick.set_fontsize(ticksize) | |
193 |
|
193 | |||
194 | ax_cb.yaxis.tick_right() |
|
194 | ax_cb.yaxis.tick_right() | |
195 |
|
195 | |||
196 | if '0.' in matplotlib.__version__[0:2]: |
|
196 | if '0.' in matplotlib.__version__[0:2]: | |
197 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
197 | print "The matplotlib version has to be updated to 1.1 or newer" | |
198 | return imesh |
|
198 | return imesh | |
199 |
|
199 | |||
200 | if '1.0.' in matplotlib.__version__[0:4]: |
|
200 | if '1.0.' in matplotlib.__version__[0:4]: | |
201 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
201 | print "The matplotlib version has to be updated to 1.1 or newer" | |
202 | return imesh |
|
202 | return imesh | |
203 |
|
203 | |||
204 | matplotlib.pyplot.tight_layout() |
|
204 | matplotlib.pyplot.tight_layout() | |
205 |
|
205 | |||
206 | if XAxisAsTime: |
|
206 | if XAxisAsTime: | |
207 |
|
207 | |||
208 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
208 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
209 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
209 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
210 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
210 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
211 |
|
211 | |||
212 | matplotlib.pyplot.ion() |
|
212 | matplotlib.pyplot.ion() | |
213 | return imesh |
|
213 | return imesh | |
214 |
|
214 | |||
215 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
215 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
216 |
|
216 | |||
217 | z = z.T |
|
217 | z = z.T | |
218 |
|
218 | |||
219 | ax = imesh.get_axes() |
|
219 | ax = imesh.get_axes() | |
220 |
|
220 | |||
221 | printLabels(ax, xlabel, ylabel, title) |
|
221 | printLabels(ax, xlabel, ylabel, title) | |
222 |
|
222 | |||
223 | imesh.set_array(z.ravel()) |
|
223 | imesh.set_array(z.ravel()) | |
224 |
|
224 | |||
225 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
225 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
226 |
|
226 | |||
227 | printLabels(ax, xlabel, ylabel, title) |
|
227 | printLabels(ax, xlabel, ylabel, title) | |
228 |
|
228 | |||
229 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
229 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
230 |
|
230 | |||
231 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
231 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): | |
232 |
|
232 | |||
233 | printLabels(ax, xlabel, ylabel, title) |
|
233 | printLabels(ax, xlabel, ylabel, title) | |
234 |
|
234 | |||
235 | ax.collections.remove(ax.collections[0]) |
|
235 | ax.collections.remove(ax.collections[0]) | |
236 |
|
236 | |||
237 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
237 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
238 |
|
238 | |||
239 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
239 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
240 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
240 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
241 | nxticks=4, nyticks=10, |
|
241 | nxticks=4, nyticks=10, | |
242 | grid=None): |
|
242 | grid=None): | |
243 |
|
243 | |||
244 | """ |
|
244 | """ | |
245 |
|
245 | |||
246 | Input: |
|
246 | Input: | |
247 | grid : None, 'both', 'x', 'y' |
|
247 | grid : None, 'both', 'x', 'y' | |
248 | """ |
|
248 | """ | |
249 |
|
249 | |||
250 | matplotlib.pyplot.ioff() |
|
250 | matplotlib.pyplot.ioff() | |
251 |
|
251 | |||
252 | lines = ax.plot(x.T, y) |
|
252 | lines = ax.plot(x.T, y) | |
253 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
253 | leg = ax.legend(lines, legendlabels, loc='upper right') | |
254 | leg.get_frame().set_alpha(0.5) |
|
254 | leg.get_frame().set_alpha(0.5) | |
255 | ax.set_xlim([xmin,xmax]) |
|
255 | ax.set_xlim([xmin,xmax]) | |
256 | ax.set_ylim([ymin,ymax]) |
|
256 | ax.set_ylim([ymin,ymax]) | |
257 | printLabels(ax, xlabel, ylabel, title) |
|
257 | printLabels(ax, xlabel, ylabel, title) | |
258 |
|
258 | |||
259 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
259 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
260 | ax.set_xticks(xtickspos) |
|
260 | ax.set_xticks(xtickspos) | |
261 |
|
261 | |||
262 | for tick in ax.get_xticklabels(): |
|
262 | for tick in ax.get_xticklabels(): | |
263 | tick.set_visible(xtick_visible) |
|
263 | tick.set_visible(xtick_visible) | |
264 |
|
264 | |||
265 | for tick in ax.xaxis.get_major_ticks(): |
|
265 | for tick in ax.xaxis.get_major_ticks(): | |
266 | tick.label.set_fontsize(ticksize) |
|
266 | tick.label.set_fontsize(ticksize) | |
267 |
|
267 | |||
268 | for tick in ax.get_yticklabels(): |
|
268 | for tick in ax.get_yticklabels(): | |
269 | tick.set_visible(ytick_visible) |
|
269 | tick.set_visible(ytick_visible) | |
270 |
|
270 | |||
271 | for tick in ax.yaxis.get_major_ticks(): |
|
271 | for tick in ax.yaxis.get_major_ticks(): | |
272 | tick.label.set_fontsize(ticksize) |
|
272 | tick.label.set_fontsize(ticksize) | |
273 |
|
273 | |||
274 | iplot = ax.lines[-1] |
|
274 | iplot = ax.lines[-1] | |
275 |
|
275 | |||
276 | if '0.' in matplotlib.__version__[0:2]: |
|
276 | if '0.' in matplotlib.__version__[0:2]: | |
277 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
277 | print "The matplotlib version has to be updated to 1.1 or newer" | |
278 | return iplot |
|
278 | return iplot | |
279 |
|
279 | |||
280 | if '1.0.' in matplotlib.__version__[0:4]: |
|
280 | if '1.0.' in matplotlib.__version__[0:4]: | |
281 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
281 | print "The matplotlib version has to be updated to 1.1 or newer" | |
282 | return iplot |
|
282 | return iplot | |
283 |
|
283 | |||
284 | if grid != None: |
|
284 | if grid != None: | |
285 | ax.grid(b=True, which='major', axis=grid) |
|
285 | ax.grid(b=True, which='major', axis=grid) | |
286 |
|
286 | |||
287 | matplotlib.pyplot.tight_layout() |
|
287 | matplotlib.pyplot.tight_layout() | |
288 |
|
288 | |||
289 | matplotlib.pyplot.ion() |
|
289 | matplotlib.pyplot.ion() | |
290 |
|
290 | |||
291 | return iplot |
|
291 | return iplot | |
292 |
|
292 | |||
293 |
|
293 | |||
294 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
294 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): | |
295 |
|
295 | |||
296 | ax = iplot.get_axes() |
|
296 | ax = iplot.get_axes() | |
297 |
|
297 | |||
298 | printLabels(ax, xlabel, ylabel, title) |
|
298 | printLabels(ax, xlabel, ylabel, title) | |
299 |
|
299 | |||
300 | for i in range(len(ax.lines)): |
|
300 | for i in range(len(ax.lines)): | |
301 | line = ax.lines[i] |
|
301 | line = ax.lines[i] | |
302 | line.set_data(x[i,:],y) |
|
302 | line.set_data(x[i,:],y) | |
303 |
|
303 | |||
304 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
304 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
305 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
305 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
306 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
306 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", | |
307 | grid=None, XAxisAsTime=False): |
|
307 | grid=None, XAxisAsTime=False): | |
308 |
|
308 | |||
309 | """ |
|
309 | """ | |
310 |
|
310 | |||
311 | Input: |
|
311 | Input: | |
312 | grid : None, 'both', 'x', 'y' |
|
312 | grid : None, 'both', 'x', 'y' | |
313 | """ |
|
313 | """ | |
314 |
|
314 | |||
315 | matplotlib.pyplot.ioff() |
|
315 | matplotlib.pyplot.ioff() | |
316 |
|
316 | |||
317 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
317 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) | |
318 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) |
|
318 | lines = ax.plot(x, y.T, linestyle='None', marker='.', markersize=markersize) | |
319 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
319 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ | |
320 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
320 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) | |
321 |
|
321 | |||
322 | for label in leg.get_texts(): label.set_fontsize(9) |
|
322 | for label in leg.get_texts(): label.set_fontsize(9) | |
323 |
|
323 | |||
324 | ax.set_xlim([xmin,xmax]) |
|
324 | ax.set_xlim([xmin,xmax]) | |
325 | ax.set_ylim([ymin,ymax]) |
|
325 | ax.set_ylim([ymin,ymax]) | |
326 | printLabels(ax, xlabel, ylabel, title) |
|
326 | printLabels(ax, xlabel, ylabel, title) | |
327 |
|
327 | |||
328 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
328 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) | |
329 | # ax.set_xticks(xtickspos) |
|
329 | # ax.set_xticks(xtickspos) | |
330 |
|
330 | |||
331 | for tick in ax.get_xticklabels(): |
|
331 | for tick in ax.get_xticklabels(): | |
332 | tick.set_visible(xtick_visible) |
|
332 | tick.set_visible(xtick_visible) | |
333 |
|
333 | |||
334 | for tick in ax.xaxis.get_major_ticks(): |
|
334 | for tick in ax.xaxis.get_major_ticks(): | |
335 | tick.label.set_fontsize(ticksize) |
|
335 | tick.label.set_fontsize(ticksize) | |
336 |
|
336 | |||
337 | for tick in ax.get_yticklabels(): |
|
337 | for tick in ax.get_yticklabels(): | |
338 | tick.set_visible(ytick_visible) |
|
338 | tick.set_visible(ytick_visible) | |
339 |
|
339 | |||
340 | for tick in ax.yaxis.get_major_ticks(): |
|
340 | for tick in ax.yaxis.get_major_ticks(): | |
341 | tick.label.set_fontsize(ticksize) |
|
341 | tick.label.set_fontsize(ticksize) | |
342 |
|
342 | |||
343 | iplot = ax.lines[-1] |
|
343 | iplot = ax.lines[-1] | |
344 |
|
344 | |||
345 | if '0.' in matplotlib.__version__[0:2]: |
|
345 | if '0.' in matplotlib.__version__[0:2]: | |
346 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
346 | print "The matplotlib version has to be updated to 1.1 or newer" | |
347 | return iplot |
|
347 | return iplot | |
348 |
|
348 | |||
349 | if '1.0.' in matplotlib.__version__[0:4]: |
|
349 | if '1.0.' in matplotlib.__version__[0:4]: | |
350 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
350 | print "The matplotlib version has to be updated to 1.1 or newer" | |
351 | return iplot |
|
351 | return iplot | |
352 |
|
352 | |||
353 | if grid != None: |
|
353 | if grid != None: | |
354 | ax.grid(b=True, which='major', axis=grid) |
|
354 | ax.grid(b=True, which='major', axis=grid) | |
355 |
|
355 | |||
356 | matplotlib.pyplot.tight_layout() |
|
356 | matplotlib.pyplot.tight_layout() | |
357 |
|
357 | |||
358 | if XAxisAsTime: |
|
358 | if XAxisAsTime: | |
359 |
|
359 | |||
360 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
360 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
361 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
361 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
362 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
362 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
363 |
|
363 | |||
364 | matplotlib.pyplot.ion() |
|
364 | matplotlib.pyplot.ion() | |
365 |
|
365 | |||
366 | return iplot |
|
366 | return iplot | |
367 |
|
367 | |||
368 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
368 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): | |
369 |
|
369 | |||
370 | ax = iplot.get_axes() |
|
370 | ax = iplot.get_axes() | |
371 |
|
371 | |||
372 | printLabels(ax, xlabel, ylabel, title) |
|
372 | printLabels(ax, xlabel, ylabel, title) | |
373 |
|
373 | |||
374 | for i in range(len(ax.lines)): |
|
374 | for i in range(len(ax.lines)): | |
375 | line = ax.lines[i] |
|
375 | line = ax.lines[i] | |
376 | line.set_data(x,y[i,:]) |
|
376 | line.set_data(x,y[i,:]) | |
377 |
|
377 | |||
378 | def draw(fig): |
|
378 | def draw(fig): | |
379 |
|
379 | |||
380 | if type(fig) == 'int': |
|
380 | if type(fig) == 'int': | |
381 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
381 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
382 |
|
382 | |||
383 | fig.canvas.draw() |
|
383 | fig.canvas.draw() |
@@ -1,657 +1,690 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import copy |
|
8 | import copy | |
9 | import numpy |
|
9 | import numpy | |
10 | import datetime |
|
10 | import datetime | |
11 |
|
11 | |||
12 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
12 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
13 |
|
13 | |||
14 |
|
14 | |||
15 | def hildebrand_sekhon(data, navg): |
|
15 | def hildebrand_sekhon(data, navg): | |
16 |
|
16 | |||
17 | data = data.copy() |
|
17 | data = data.copy() | |
18 |
|
18 | |||
19 | sortdata = numpy.sort(data,axis=None) |
|
19 | sortdata = numpy.sort(data,axis=None) | |
20 | lenOfData = len(sortdata) |
|
20 | lenOfData = len(sortdata) | |
21 | nums_min = lenOfData/10 |
|
21 | nums_min = lenOfData/10 | |
22 |
|
22 | |||
23 | if (lenOfData/10) > 2: |
|
23 | if (lenOfData/10) > 2: | |
24 | nums_min = lenOfData/10 |
|
24 | nums_min = lenOfData/10 | |
25 | else: |
|
25 | else: | |
26 | nums_min = 2 |
|
26 | nums_min = 2 | |
27 |
|
27 | |||
28 | sump = 0. |
|
28 | sump = 0. | |
29 |
|
29 | |||
30 | sumq = 0. |
|
30 | sumq = 0. | |
31 |
|
31 | |||
32 | j = 0 |
|
32 | j = 0 | |
33 |
|
33 | |||
34 | cont = 1 |
|
34 | cont = 1 | |
35 |
|
35 | |||
36 | while((cont==1)and(j<lenOfData)): |
|
36 | while((cont==1)and(j<lenOfData)): | |
37 |
|
37 | |||
38 | sump += sortdata[j] |
|
38 | sump += sortdata[j] | |
39 |
|
39 | |||
40 | sumq += sortdata[j]**2 |
|
40 | sumq += sortdata[j]**2 | |
41 |
|
41 | |||
42 | j += 1 |
|
42 | j += 1 | |
43 |
|
43 | |||
44 | if j > nums_min: |
|
44 | if j > nums_min: | |
45 | rtest = float(j)/(j-1) + 1.0/navg |
|
45 | rtest = float(j)/(j-1) + 1.0/navg | |
46 | if ((sumq*j) > (rtest*sump**2)): |
|
46 | if ((sumq*j) > (rtest*sump**2)): | |
47 | j = j - 1 |
|
47 | j = j - 1 | |
48 | sump = sump - sortdata[j] |
|
48 | sump = sump - sortdata[j] | |
49 | sumq = sumq - sortdata[j]**2 |
|
49 | sumq = sumq - sortdata[j]**2 | |
50 | cont = 0 |
|
50 | cont = 0 | |
51 |
|
51 | |||
52 | lnoise = sump /j |
|
52 | lnoise = sump /j | |
53 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) |
|
53 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) | |
54 | return lnoise |
|
54 | return lnoise | |
55 |
|
55 | |||
56 | class JROData: |
|
56 | class JROData: | |
57 |
|
57 | |||
58 | # m_BasicHeader = BasicHeader() |
|
58 | # m_BasicHeader = BasicHeader() | |
59 | # m_ProcessingHeader = ProcessingHeader() |
|
59 | # m_ProcessingHeader = ProcessingHeader() | |
60 |
|
60 | |||
61 | systemHeaderObj = SystemHeader() |
|
61 | systemHeaderObj = SystemHeader() | |
62 |
|
62 | |||
63 | radarControllerHeaderObj = RadarControllerHeader() |
|
63 | radarControllerHeaderObj = RadarControllerHeader() | |
64 |
|
64 | |||
65 | # data = None |
|
65 | # data = None | |
66 |
|
66 | |||
67 | type = None |
|
67 | type = None | |
68 |
|
68 | |||
69 | dtype = None |
|
69 | dtype = None | |
70 |
|
70 | |||
71 | # nChannels = None |
|
71 | # nChannels = None | |
72 |
|
72 | |||
73 | # nHeights = None |
|
73 | # nHeights = None | |
74 |
|
74 | |||
75 | nProfiles = None |
|
75 | nProfiles = None | |
76 |
|
76 | |||
77 | heightList = None |
|
77 | heightList = None | |
78 |
|
78 | |||
79 | channelList = None |
|
79 | channelList = None | |
80 |
|
80 | |||
81 | flagNoData = True |
|
81 | flagNoData = True | |
82 |
|
82 | |||
83 | flagTimeBlock = False |
|
83 | flagTimeBlock = False | |
84 |
|
84 | |||
85 | useLocalTime = False |
|
85 | useLocalTime = False | |
86 |
|
86 | |||
87 | utctime = None |
|
87 | utctime = None | |
88 |
|
88 | |||
89 | timeZone = None |
|
89 | timeZone = None | |
90 |
|
90 | |||
91 | dstFlag = None |
|
91 | dstFlag = None | |
92 |
|
92 | |||
93 | errorCount = None |
|
93 | errorCount = None | |
94 |
|
94 | |||
95 | blocksize = None |
|
95 | blocksize = None | |
96 |
|
96 | |||
97 | nCode = None |
|
97 | nCode = None | |
98 |
|
98 | |||
99 | nBaud = None |
|
99 | nBaud = None | |
100 |
|
100 | |||
101 | code = None |
|
101 | code = None | |
102 |
|
102 | |||
103 | flagDecodeData = False #asumo q la data no esta decodificada |
|
103 | flagDecodeData = False #asumo q la data no esta decodificada | |
104 |
|
104 | |||
105 | flagDeflipData = False #asumo q la data no esta sin flip |
|
105 | flagDeflipData = False #asumo q la data no esta sin flip | |
106 |
|
106 | |||
107 | flagShiftFFT = False |
|
107 | flagShiftFFT = False | |
108 |
|
108 | |||
109 | ippSeconds = None |
|
109 | ippSeconds = None | |
110 |
|
110 | |||
111 | timeInterval = None |
|
111 | timeInterval = None | |
112 |
|
112 | |||
113 | nCohInt = None |
|
113 | nCohInt = None | |
114 |
|
114 | |||
115 | noise = None |
|
115 | noise = None | |
116 |
|
116 | |||
117 | windowOfFilter = 1 |
|
117 | windowOfFilter = 1 | |
118 |
|
118 | |||
119 | #Speed of ligth |
|
119 | #Speed of ligth | |
120 | C = 3e8 |
|
120 | C = 3e8 | |
121 |
|
121 | |||
122 | frequency = 49.92e6 |
|
122 | frequency = 49.92e6 | |
123 |
|
123 | |||
124 | realtime = False |
|
124 | realtime = False | |
125 |
|
125 | |||
126 | beacon_heiIndexList = None |
|
126 | beacon_heiIndexList = None | |
127 |
|
127 | |||
128 | last_block = None |
|
128 | last_block = None | |
129 |
|
129 | |||
130 | blocknow = None |
|
130 | blocknow = None | |
131 |
|
131 | |||
132 | def __init__(self): |
|
132 | def __init__(self): | |
133 |
|
133 | |||
134 | raise ValueError, "This class has not been implemented" |
|
134 | raise ValueError, "This class has not been implemented" | |
135 |
|
135 | |||
136 | def copy(self, inputObj=None): |
|
136 | def copy(self, inputObj=None): | |
137 |
|
137 | |||
138 | if inputObj == None: |
|
138 | if inputObj == None: | |
139 | return copy.deepcopy(self) |
|
139 | return copy.deepcopy(self) | |
140 |
|
140 | |||
141 | for key in inputObj.__dict__.keys(): |
|
141 | for key in inputObj.__dict__.keys(): | |
142 | self.__dict__[key] = inputObj.__dict__[key] |
|
142 | self.__dict__[key] = inputObj.__dict__[key] | |
143 |
|
143 | |||
144 | def deepcopy(self): |
|
144 | def deepcopy(self): | |
145 |
|
145 | |||
146 | return copy.deepcopy(self) |
|
146 | return copy.deepcopy(self) | |
147 |
|
147 | |||
148 | def isEmpty(self): |
|
148 | def isEmpty(self): | |
149 |
|
149 | |||
150 | return self.flagNoData |
|
150 | return self.flagNoData | |
151 |
|
151 | |||
152 | def getNoise(self): |
|
152 | def getNoise(self): | |
153 |
|
153 | |||
154 | raise ValueError, "Not implemented" |
|
154 | raise ValueError, "Not implemented" | |
155 |
|
155 | |||
156 | def getNChannels(self): |
|
156 | def getNChannels(self): | |
157 |
|
157 | |||
158 | return len(self.channelList) |
|
158 | return len(self.channelList) | |
159 |
|
159 | |||
160 | def getChannelIndexList(self): |
|
160 | def getChannelIndexList(self): | |
161 |
|
161 | |||
162 | return range(self.nChannels) |
|
162 | return range(self.nChannels) | |
163 |
|
163 | |||
164 | def getNHeights(self): |
|
164 | def getNHeights(self): | |
165 |
|
165 | |||
166 | return len(self.heightList) |
|
166 | return len(self.heightList) | |
167 |
|
167 | |||
168 | def getHeiRange(self, extrapoints=0): |
|
168 | def getHeiRange(self, extrapoints=0): | |
169 |
|
169 | |||
170 | heis = self.heightList |
|
170 | heis = self.heightList | |
171 | # deltah = self.heightList[1] - self.heightList[0] |
|
171 | # deltah = self.heightList[1] - self.heightList[0] | |
172 | # |
|
172 | # | |
173 | # heis.append(self.heightList[-1]) |
|
173 | # heis.append(self.heightList[-1]) | |
174 |
|
174 | |||
175 | return heis |
|
175 | return heis | |
176 |
|
176 | |||
177 | def getltctime(self): |
|
177 | def getltctime(self): | |
178 |
|
178 | |||
179 | if self.useLocalTime: |
|
179 | if self.useLocalTime: | |
180 | return self.utctime - self.timeZone*60 |
|
180 | return self.utctime - self.timeZone*60 | |
181 |
|
181 | |||
182 | return self.utctime |
|
182 | return self.utctime | |
183 |
|
183 | |||
184 | def getDatatime(self): |
|
184 | def getDatatime(self): | |
185 |
|
185 | |||
186 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
186 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
187 | return datatime |
|
187 | return datatime | |
188 |
|
188 | |||
189 | def getTimeRange(self): |
|
189 | def getTimeRange(self): | |
190 |
|
190 | |||
191 | datatime = [] |
|
191 | datatime = [] | |
192 |
|
192 | |||
193 | datatime.append(self.ltctime) |
|
193 | datatime.append(self.ltctime) | |
194 | datatime.append(self.ltctime + self.timeInterval) |
|
194 | datatime.append(self.ltctime + self.timeInterval) | |
195 |
|
195 | |||
196 | datatime = numpy.array(datatime) |
|
196 | datatime = numpy.array(datatime) | |
197 |
|
197 | |||
198 | return datatime |
|
198 | return datatime | |
199 |
|
199 | |||
200 | def getFmax(self): |
|
200 | def getFmax(self): | |
201 |
|
201 | |||
202 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
202 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
203 |
|
203 | |||
204 | fmax = PRF/2. |
|
204 | fmax = PRF/2. | |
205 |
|
205 | |||
206 | return fmax |
|
206 | return fmax | |
207 |
|
207 | |||
208 | def getVmax(self): |
|
208 | def getVmax(self): | |
209 |
|
209 | |||
210 | _lambda = self.C/self.frequency |
|
210 | _lambda = self.C/self.frequency | |
211 |
|
211 | |||
212 | vmax = self.getFmax() * _lambda |
|
212 | vmax = self.getFmax() * _lambda | |
213 |
|
213 | |||
214 | return vmax |
|
214 | return vmax | |
215 |
|
215 | |||
216 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
216 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
217 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
217 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
218 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
218 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
219 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
219 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
220 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
220 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
221 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
221 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
222 |
|
222 | |||
223 | class Voltage(JROData): |
|
223 | class Voltage(JROData): | |
224 |
|
224 | |||
225 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
225 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
226 | data = None |
|
226 | data = None | |
227 |
|
227 | |||
228 | def __init__(self): |
|
228 | def __init__(self): | |
229 | ''' |
|
229 | ''' | |
230 | Constructor |
|
230 | Constructor | |
231 | ''' |
|
231 | ''' | |
232 |
|
232 | |||
233 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
233 | self.radarControllerHeaderObj = RadarControllerHeader() | |
234 |
|
234 | |||
235 | self.systemHeaderObj = SystemHeader() |
|
235 | self.systemHeaderObj = SystemHeader() | |
236 |
|
236 | |||
237 | self.type = "Voltage" |
|
237 | self.type = "Voltage" | |
238 |
|
238 | |||
239 | self.data = None |
|
239 | self.data = None | |
240 |
|
240 | |||
241 | self.dtype = None |
|
241 | self.dtype = None | |
242 |
|
242 | |||
243 | # self.nChannels = 0 |
|
243 | # self.nChannels = 0 | |
244 |
|
244 | |||
245 | # self.nHeights = 0 |
|
245 | # self.nHeights = 0 | |
246 |
|
246 | |||
247 | self.nProfiles = None |
|
247 | self.nProfiles = None | |
248 |
|
248 | |||
249 | self.heightList = None |
|
249 | self.heightList = None | |
250 |
|
250 | |||
251 | self.channelList = None |
|
251 | self.channelList = None | |
252 |
|
252 | |||
253 | # self.channelIndexList = None |
|
253 | # self.channelIndexList = None | |
254 |
|
254 | |||
255 | self.flagNoData = True |
|
255 | self.flagNoData = True | |
256 |
|
256 | |||
257 | self.flagTimeBlock = False |
|
257 | self.flagTimeBlock = False | |
258 |
|
258 | |||
259 | self.utctime = None |
|
259 | self.utctime = None | |
260 |
|
260 | |||
261 | self.timeZone = None |
|
261 | self.timeZone = None | |
262 |
|
262 | |||
263 | self.dstFlag = None |
|
263 | self.dstFlag = None | |
264 |
|
264 | |||
265 | self.errorCount = None |
|
265 | self.errorCount = None | |
266 |
|
266 | |||
267 | self.nCohInt = None |
|
267 | self.nCohInt = None | |
268 |
|
268 | |||
269 | self.blocksize = None |
|
269 | self.blocksize = None | |
270 |
|
270 | |||
271 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
271 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
272 |
|
272 | |||
273 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
273 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
274 |
|
274 | |||
275 | self.flagShiftFFT = False |
|
275 | self.flagShiftFFT = False | |
276 |
|
276 | |||
277 |
|
277 | |||
278 | def getNoisebyHildebrand(self): |
|
278 | def getNoisebyHildebrand(self): | |
279 | """ |
|
279 | """ | |
280 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
280 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
281 |
|
281 | |||
282 | Return: |
|
282 | Return: | |
283 | noiselevel |
|
283 | noiselevel | |
284 | """ |
|
284 | """ | |
285 |
|
285 | |||
286 | for channel in range(self.nChannels): |
|
286 | for channel in range(self.nChannels): | |
287 | daux = self.data_spc[channel,:,:] |
|
287 | daux = self.data_spc[channel,:,:] | |
288 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
288 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) | |
289 |
|
289 | |||
290 | return self.noise |
|
290 | return self.noise | |
291 |
|
291 | |||
292 | def getNoise(self, type = 1): |
|
292 | def getNoise(self, type = 1): | |
293 |
|
293 | |||
294 | self.noise = numpy.zeros(self.nChannels) |
|
294 | self.noise = numpy.zeros(self.nChannels) | |
295 |
|
295 | |||
296 | if type == 1: |
|
296 | if type == 1: | |
297 | noise = self.getNoisebyHildebrand() |
|
297 | noise = self.getNoisebyHildebrand() | |
298 |
|
298 | |||
299 | return 10*numpy.log10(noise) |
|
299 | return 10*numpy.log10(noise) | |
300 |
|
300 | |||
301 | class Spectra(JROData): |
|
301 | class Spectra(JROData): | |
302 |
|
302 | |||
303 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
303 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
304 | data_spc = None |
|
304 | data_spc = None | |
305 |
|
305 | |||
306 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
306 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
307 | data_cspc = None |
|
307 | data_cspc = None | |
308 |
|
308 | |||
309 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
309 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
310 | data_dc = None |
|
310 | data_dc = None | |
311 |
|
311 | |||
312 | nFFTPoints = None |
|
312 | nFFTPoints = None | |
313 |
|
313 | |||
314 | nPairs = None |
|
314 | nPairs = None | |
315 |
|
315 | |||
316 | pairsList = None |
|
316 | pairsList = None | |
317 |
|
317 | |||
318 | nIncohInt = None |
|
318 | nIncohInt = None | |
319 |
|
319 | |||
320 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
320 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
321 |
|
321 | |||
322 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
322 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
323 |
|
323 | |||
324 | ippFactor = None |
|
324 | ippFactor = None | |
325 |
|
325 | |||
326 | def __init__(self): |
|
326 | def __init__(self): | |
327 | ''' |
|
327 | ''' | |
328 | Constructor |
|
328 | Constructor | |
329 | ''' |
|
329 | ''' | |
330 |
|
330 | |||
331 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
331 | self.radarControllerHeaderObj = RadarControllerHeader() | |
332 |
|
332 | |||
333 | self.systemHeaderObj = SystemHeader() |
|
333 | self.systemHeaderObj = SystemHeader() | |
334 |
|
334 | |||
335 | self.type = "Spectra" |
|
335 | self.type = "Spectra" | |
336 |
|
336 | |||
337 | # self.data = None |
|
337 | # self.data = None | |
338 |
|
338 | |||
339 | self.dtype = None |
|
339 | self.dtype = None | |
340 |
|
340 | |||
341 | # self.nChannels = 0 |
|
341 | # self.nChannels = 0 | |
342 |
|
342 | |||
343 | # self.nHeights = 0 |
|
343 | # self.nHeights = 0 | |
344 |
|
344 | |||
345 | self.nProfiles = None |
|
345 | self.nProfiles = None | |
346 |
|
346 | |||
347 | self.heightList = None |
|
347 | self.heightList = None | |
348 |
|
348 | |||
349 | self.channelList = None |
|
349 | self.channelList = None | |
350 |
|
350 | |||
351 | # self.channelIndexList = None |
|
351 | # self.channelIndexList = None | |
352 |
|
352 | |||
353 | self.flagNoData = True |
|
353 | self.flagNoData = True | |
354 |
|
354 | |||
355 | self.flagTimeBlock = False |
|
355 | self.flagTimeBlock = False | |
356 |
|
356 | |||
357 | self.utctime = None |
|
357 | self.utctime = None | |
358 |
|
358 | |||
359 | self.nCohInt = None |
|
359 | self.nCohInt = None | |
360 |
|
360 | |||
361 | self.nIncohInt = None |
|
361 | self.nIncohInt = None | |
362 |
|
362 | |||
363 | self.blocksize = None |
|
363 | self.blocksize = None | |
364 |
|
364 | |||
365 | self.nFFTPoints = None |
|
365 | self.nFFTPoints = None | |
366 |
|
366 | |||
367 | self.wavelength = None |
|
367 | self.wavelength = None | |
368 |
|
368 | |||
369 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
369 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
370 |
|
370 | |||
371 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
371 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
372 |
|
372 | |||
373 | self.flagShiftFFT = False |
|
373 | self.flagShiftFFT = False | |
374 |
|
374 | |||
375 | self.ippFactor = 1 |
|
375 | self.ippFactor = 1 | |
376 |
|
376 | |||
377 | self.noise = None |
|
377 | self.noise = None | |
378 |
|
378 | |||
379 | self.beacon_heiIndexList = [] |
|
379 | self.beacon_heiIndexList = [] | |
380 |
|
380 | |||
381 |
|
381 | |||
382 | def getNoisebyHildebrand(self): |
|
382 | def getNoisebyHildebrand(self): | |
383 | """ |
|
383 | """ | |
384 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
384 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
385 |
|
385 | |||
386 | Return: |
|
386 | Return: | |
387 | noiselevel |
|
387 | noiselevel | |
388 | """ |
|
388 | """ | |
389 | noise = numpy.zeros(self.nChannels) |
|
389 | noise = numpy.zeros(self.nChannels) | |
390 | for channel in range(self.nChannels): |
|
390 | for channel in range(self.nChannels): | |
391 | daux = self.data_spc[channel,:,:] |
|
391 | daux = self.data_spc[channel,:,:] | |
392 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
392 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
393 |
|
393 | |||
394 | return noise |
|
394 | return noise | |
395 |
|
395 | |||
396 | def getNoise(self): |
|
396 | def getNoise(self): | |
397 | if self.noise != None: |
|
397 | if self.noise != None: | |
398 | return self.noise |
|
398 | return self.noise | |
399 | else: |
|
399 | else: | |
400 | noise = self.getNoisebyHildebrand() |
|
400 | noise = self.getNoisebyHildebrand() | |
401 | return noise |
|
401 | return noise | |
402 |
|
402 | |||
403 |
|
403 | |||
404 | def getFreqRange(self, extrapoints=0): |
|
404 | def getFreqRange(self, extrapoints=0): | |
405 |
|
405 | |||
406 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
406 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) | |
407 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
407 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
408 |
|
408 | |||
409 | return freqrange |
|
409 | return freqrange | |
410 |
|
410 | |||
411 | def getVelRange(self, extrapoints=0): |
|
411 | def getVelRange(self, extrapoints=0): | |
412 |
|
412 | |||
413 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
413 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) | |
414 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
414 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |
415 |
|
415 | |||
416 | return velrange |
|
416 | return velrange | |
417 |
|
417 | |||
418 | def getNPairs(self): |
|
418 | def getNPairs(self): | |
419 |
|
419 | |||
420 | return len(self.pairsList) |
|
420 | return len(self.pairsList) | |
421 |
|
421 | |||
422 | def getPairsIndexList(self): |
|
422 | def getPairsIndexList(self): | |
423 |
|
423 | |||
424 | return range(self.nPairs) |
|
424 | return range(self.nPairs) | |
425 |
|
425 | |||
426 | def getNormFactor(self): |
|
426 | def getNormFactor(self): | |
427 | pwcode = 1 |
|
427 | pwcode = 1 | |
428 | if self.flagDecodeData: |
|
428 | if self.flagDecodeData: | |
429 | pwcode = numpy.sum(self.code[0]**2) |
|
429 | pwcode = numpy.sum(self.code[0]**2) | |
430 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
430 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
431 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
431 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
432 |
|
432 | |||
433 | return normFactor |
|
433 | return normFactor | |
434 |
|
434 | |||
435 | def getFlagCspc(self): |
|
435 | def getFlagCspc(self): | |
436 |
|
436 | |||
437 | if self.data_cspc == None: |
|
437 | if self.data_cspc == None: | |
438 | return True |
|
438 | return True | |
439 |
|
439 | |||
440 | return False |
|
440 | return False | |
441 |
|
441 | |||
442 | def getFlagDc(self): |
|
442 | def getFlagDc(self): | |
443 |
|
443 | |||
444 | if self.data_dc == None: |
|
444 | if self.data_dc == None: | |
445 | return True |
|
445 | return True | |
446 |
|
446 | |||
447 | return False |
|
447 | return False | |
448 |
|
448 | |||
449 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
449 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") | |
450 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
450 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") | |
451 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
451 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
452 | flag_cspc = property(getFlagCspc) |
|
452 | flag_cspc = property(getFlagCspc) | |
453 | flag_dc = property(getFlagDc) |
|
453 | flag_dc = property(getFlagDc) | |
454 |
|
454 | |||
455 | class SpectraHeis(JROData): |
|
455 | class SpectraHeis(JROData): | |
456 |
|
456 | |||
457 | data_spc = None |
|
457 | data_spc = None | |
458 |
|
458 | |||
459 | data_cspc = None |
|
459 | data_cspc = None | |
460 |
|
460 | |||
461 | data_dc = None |
|
461 | data_dc = None | |
462 |
|
462 | |||
463 | nFFTPoints = None |
|
463 | nFFTPoints = None | |
464 |
|
464 | |||
465 | nPairs = None |
|
465 | nPairs = None | |
466 |
|
466 | |||
467 | pairsList = None |
|
467 | pairsList = None | |
468 |
|
468 | |||
469 | nIncohInt = None |
|
469 | nIncohInt = None | |
470 |
|
470 | |||
471 | def __init__(self): |
|
471 | def __init__(self): | |
472 |
|
472 | |||
473 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
473 | self.radarControllerHeaderObj = RadarControllerHeader() | |
474 |
|
474 | |||
475 | self.systemHeaderObj = SystemHeader() |
|
475 | self.systemHeaderObj = SystemHeader() | |
476 |
|
476 | |||
477 | self.type = "SpectraHeis" |
|
477 | self.type = "SpectraHeis" | |
478 |
|
478 | |||
479 | self.dtype = None |
|
479 | self.dtype = None | |
480 |
|
480 | |||
481 | # self.nChannels = 0 |
|
481 | # self.nChannels = 0 | |
482 |
|
482 | |||
483 | # self.nHeights = 0 |
|
483 | # self.nHeights = 0 | |
484 |
|
484 | |||
485 | self.nProfiles = None |
|
485 | self.nProfiles = None | |
486 |
|
486 | |||
487 | self.heightList = None |
|
487 | self.heightList = None | |
488 |
|
488 | |||
489 | self.channelList = None |
|
489 | self.channelList = None | |
490 |
|
490 | |||
491 | # self.channelIndexList = None |
|
491 | # self.channelIndexList = None | |
492 |
|
492 | |||
493 | self.flagNoData = True |
|
493 | self.flagNoData = True | |
494 |
|
494 | |||
495 | self.flagTimeBlock = False |
|
495 | self.flagTimeBlock = False | |
496 |
|
496 | |||
497 | self.nPairs = 0 |
|
497 | self.nPairs = 0 | |
498 |
|
498 | |||
499 | self.utctime = None |
|
499 | self.utctime = None | |
500 |
|
500 | |||
501 | self.blocksize = None |
|
501 | self.blocksize = None | |
502 |
|
502 | |||
503 | class Fits: |
|
503 | class Fits: | |
504 |
|
504 | |||
505 | heightList = None |
|
505 | heightList = None | |
506 |
|
506 | |||
507 | channelList = None |
|
507 | channelList = None | |
508 |
|
508 | |||
509 | flagNoData = True |
|
509 | flagNoData = True | |
510 |
|
510 | |||
511 | flagTimeBlock = False |
|
511 | flagTimeBlock = False | |
512 |
|
512 | |||
513 | useLocalTime = False |
|
513 | useLocalTime = False | |
514 |
|
514 | |||
515 | utctime = None |
|
515 | utctime = None | |
516 |
|
516 | |||
517 | timeZone = None |
|
517 | timeZone = None | |
518 |
|
518 | |||
519 | ippSeconds = None |
|
519 | ippSeconds = None | |
520 |
|
520 | |||
521 | timeInterval = None |
|
521 | timeInterval = None | |
522 |
|
522 | |||
523 | nCohInt = None |
|
523 | nCohInt = None | |
524 |
|
524 | |||
525 | nIncohInt = None |
|
525 | nIncohInt = None | |
526 |
|
526 | |||
527 | noise = None |
|
527 | noise = None | |
528 |
|
528 | |||
529 | windowOfFilter = 1 |
|
529 | windowOfFilter = 1 | |
530 |
|
530 | |||
531 | #Speed of ligth |
|
531 | #Speed of ligth | |
532 | C = 3e8 |
|
532 | C = 3e8 | |
533 |
|
533 | |||
534 | frequency = 49.92e6 |
|
534 | frequency = 49.92e6 | |
535 |
|
535 | |||
536 | realtime = False |
|
536 | realtime = False | |
537 |
|
537 | |||
538 |
|
538 | |||
539 | def __init__(self): |
|
539 | def __init__(self): | |
540 |
|
540 | |||
541 | self.type = "Fits" |
|
541 | self.type = "Fits" | |
542 |
|
542 | |||
543 | self.nProfiles = None |
|
543 | self.nProfiles = None | |
544 |
|
544 | |||
545 | self.heightList = None |
|
545 | self.heightList = None | |
546 |
|
546 | |||
547 | self.channelList = None |
|
547 | self.channelList = None | |
548 |
|
548 | |||
549 | # self.channelIndexList = None |
|
549 | # self.channelIndexList = None | |
550 |
|
550 | |||
551 | self.flagNoData = True |
|
551 | self.flagNoData = True | |
552 |
|
552 | |||
553 | self.utctime = None |
|
553 | self.utctime = None | |
554 |
|
554 | |||
555 | self.nCohInt = None |
|
555 | self.nCohInt = None | |
556 |
|
556 | |||
557 | self.nIncohInt = None |
|
557 | self.nIncohInt = None | |
558 |
|
558 | |||
559 | self.useLocalTime = True |
|
559 | self.useLocalTime = True | |
560 |
|
560 | |||
561 | # self.utctime = None |
|
561 | # self.utctime = None | |
562 | # self.timeZone = None |
|
562 | # self.timeZone = None | |
563 | # self.ltctime = None |
|
563 | # self.ltctime = None | |
564 | # self.timeInterval = None |
|
564 | # self.timeInterval = None | |
565 | # self.header = None |
|
565 | # self.header = None | |
566 | # self.data_header = None |
|
566 | # self.data_header = None | |
567 | # self.data = None |
|
567 | # self.data = None | |
568 | # self.datatime = None |
|
568 | # self.datatime = None | |
569 | # self.flagNoData = False |
|
569 | # self.flagNoData = False | |
570 | # self.expName = '' |
|
570 | # self.expName = '' | |
571 | # self.nChannels = None |
|
571 | # self.nChannels = None | |
572 | # self.nSamples = None |
|
572 | # self.nSamples = None | |
573 | # self.dataBlocksPerFile = None |
|
573 | # self.dataBlocksPerFile = None | |
574 | # self.comments = '' |
|
574 | # self.comments = '' | |
575 | # |
|
575 | # | |
576 |
|
576 | |||
577 |
|
577 | |||
578 | def getltctime(self): |
|
578 | def getltctime(self): | |
579 |
|
579 | |||
580 | if self.useLocalTime: |
|
580 | if self.useLocalTime: | |
581 | return self.utctime - self.timeZone*60 |
|
581 | return self.utctime - self.timeZone*60 | |
582 |
|
582 | |||
583 | return self.utctime |
|
583 | return self.utctime | |
584 |
|
584 | |||
585 | def getDatatime(self): |
|
585 | def getDatatime(self): | |
586 |
|
586 | |||
587 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
587 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
588 | return datatime |
|
588 | return datatime | |
589 |
|
589 | |||
590 | def getTimeRange(self): |
|
590 | def getTimeRange(self): | |
591 |
|
591 | |||
592 | datatime = [] |
|
592 | datatime = [] | |
593 |
|
593 | |||
594 | datatime.append(self.ltctime) |
|
594 | datatime.append(self.ltctime) | |
595 | datatime.append(self.ltctime + self.timeInterval) |
|
595 | datatime.append(self.ltctime + self.timeInterval) | |
596 |
|
596 | |||
597 | datatime = numpy.array(datatime) |
|
597 | datatime = numpy.array(datatime) | |
598 |
|
598 | |||
599 | return datatime |
|
599 | return datatime | |
600 |
|
600 | |||
601 | def getHeiRange(self): |
|
601 | def getHeiRange(self): | |
602 |
|
602 | |||
603 | heis = self.heightList |
|
603 | heis = self.heightList | |
604 |
|
604 | |||
605 | return heis |
|
605 | return heis | |
606 |
|
606 | |||
607 | def isEmpty(self): |
|
607 | def isEmpty(self): | |
608 |
|
608 | |||
609 | return self.flagNoData |
|
609 | return self.flagNoData | |
610 |
|
610 | |||
611 | def getNHeights(self): |
|
611 | def getNHeights(self): | |
612 |
|
612 | |||
613 | return len(self.heightList) |
|
613 | return len(self.heightList) | |
614 |
|
614 | |||
615 | def getNChannels(self): |
|
615 | def getNChannels(self): | |
616 |
|
616 | |||
617 | return len(self.channelList) |
|
617 | return len(self.channelList) | |
618 |
|
618 | |||
619 | def getChannelIndexList(self): |
|
619 | def getChannelIndexList(self): | |
620 |
|
620 | |||
621 | return range(self.nChannels) |
|
621 | return range(self.nChannels) | |
622 |
|
622 | |||
623 | def getNoise(self, type = 1): |
|
623 | def getNoise(self, type = 1): | |
624 |
|
624 | |||
625 | self.noise = numpy.zeros(self.nChannels) |
|
625 | self.noise = numpy.zeros(self.nChannels) | |
626 |
|
626 | |||
627 | if type == 1: |
|
627 | if type == 1: | |
628 | noise = self.getNoisebyHildebrand() |
|
628 | noise = self.getNoisebyHildebrand() | |
629 |
|
629 | |||
630 | if type == 2: |
|
630 | if type == 2: | |
631 | noise = self.getNoisebySort() |
|
631 | noise = self.getNoisebySort() | |
632 |
|
632 | |||
633 | if type == 3: |
|
633 | if type == 3: | |
634 | noise = self.getNoisebyWindow() |
|
634 | noise = self.getNoisebyWindow() | |
635 |
|
635 | |||
636 | return noise |
|
636 | return noise | |
637 |
|
637 | |||
638 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
638 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
639 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
639 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
640 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
640 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
641 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
641 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
642 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
642 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
643 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
643 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
644 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
644 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
645 |
|
645 | |||
646 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
646 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
647 |
|
647 | |||
648 | class AMISR: |
|
648 | class AMISR: | |
649 | def __init__(self): |
|
649 | def __init__(self): | |
650 | self.flagNoData = True |
|
650 | self.flagNoData = True | |
651 | self.data = None |
|
651 | self.data = None | |
652 | self.utctime = None |
|
652 | self.utctime = None | |
653 | self.type = "AMISR" |
|
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 | def isEmpty(self): |
|
688 | def isEmpty(self): | |
656 |
|
689 | |||
657 | return self.flagNoData No newline at end of file |
|
690 | return self.flagNoData |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file | ||
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,2033 +1,2110 | |||||
1 | import numpy |
|
1 | import numpy | |
2 | import time, datetime, os |
|
2 | import time, datetime, os | |
3 | from graphics.figure import * |
|
3 | from graphics.figure import * | |
4 | def isRealtime(utcdatatime): |
|
4 | def isRealtime(utcdatatime): | |
5 | utcnow = time.mktime(time.localtime()) |
|
5 | utcnow = time.mktime(time.localtime()) | |
6 | delta = abs(utcnow - utcdatatime) # abs |
|
6 | delta = abs(utcnow - utcdatatime) # abs | |
7 | if delta >= 30.: |
|
7 | if delta >= 30.: | |
8 | return False |
|
8 | return False | |
9 | return True |
|
9 | return True | |
10 |
|
10 | |||
11 | class CrossSpectraPlot(Figure): |
|
11 | class CrossSpectraPlot(Figure): | |
12 |
|
12 | |||
13 | __isConfig = None |
|
13 | __isConfig = None | |
14 | __nsubplots = None |
|
14 | __nsubplots = None | |
15 |
|
15 | |||
16 | WIDTH = None |
|
16 | WIDTH = None | |
17 | HEIGHT = None |
|
17 | HEIGHT = None | |
18 | WIDTHPROF = None |
|
18 | WIDTHPROF = None | |
19 | HEIGHTPROF = None |
|
19 | HEIGHTPROF = None | |
20 | PREFIX = 'cspc' |
|
20 | PREFIX = 'cspc' | |
21 |
|
21 | |||
22 | def __init__(self): |
|
22 | def __init__(self): | |
23 |
|
23 | |||
24 | self.__isConfig = False |
|
24 | self.__isConfig = False | |
25 | self.__nsubplots = 4 |
|
25 | self.__nsubplots = 4 | |
26 | self.counter_imagwr = 0 |
|
26 | self.counter_imagwr = 0 | |
27 | self.WIDTH = 250 |
|
27 | self.WIDTH = 250 | |
28 | self.HEIGHT = 250 |
|
28 | self.HEIGHT = 250 | |
29 | self.WIDTHPROF = 0 |
|
29 | self.WIDTHPROF = 0 | |
30 | self.HEIGHTPROF = 0 |
|
30 | self.HEIGHTPROF = 0 | |
31 |
|
31 | |||
32 | self.PLOT_CODE = 1 |
|
32 | self.PLOT_CODE = 1 | |
33 | self.FTP_WEI = None |
|
33 | self.FTP_WEI = None | |
34 | self.EXP_CODE = None |
|
34 | self.EXP_CODE = None | |
35 | self.SUB_EXP_CODE = None |
|
35 | self.SUB_EXP_CODE = None | |
36 | self.PLOT_POS = None |
|
36 | self.PLOT_POS = None | |
37 |
|
37 | |||
38 | def getSubplots(self): |
|
38 | def getSubplots(self): | |
39 |
|
39 | |||
40 | ncol = 4 |
|
40 | ncol = 4 | |
41 | nrow = self.nplots |
|
41 | nrow = self.nplots | |
42 |
|
42 | |||
43 | return nrow, ncol |
|
43 | return nrow, ncol | |
44 |
|
44 | |||
45 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
45 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
46 |
|
46 | |||
47 | self.__showprofile = showprofile |
|
47 | self.__showprofile = showprofile | |
48 | self.nplots = nplots |
|
48 | self.nplots = nplots | |
49 |
|
49 | |||
50 | ncolspan = 1 |
|
50 | ncolspan = 1 | |
51 | colspan = 1 |
|
51 | colspan = 1 | |
52 |
|
52 | |||
53 | self.createFigure(id = id, |
|
53 | self.createFigure(id = id, | |
54 | wintitle = wintitle, |
|
54 | wintitle = wintitle, | |
55 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
55 | widthplot = self.WIDTH + self.WIDTHPROF, | |
56 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
56 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
57 | show=True) |
|
57 | show=True) | |
58 |
|
58 | |||
59 | nrow, ncol = self.getSubplots() |
|
59 | nrow, ncol = self.getSubplots() | |
60 |
|
60 | |||
61 | counter = 0 |
|
61 | counter = 0 | |
62 | for y in range(nrow): |
|
62 | for y in range(nrow): | |
63 | for x in range(ncol): |
|
63 | for x in range(ncol): | |
64 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
64 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
65 |
|
65 | |||
66 | counter += 1 |
|
66 | counter += 1 | |
67 |
|
67 | |||
68 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
68 | def run(self, dataOut, id, wintitle="", pairsList=None, | |
69 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
69 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
70 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
70 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
71 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
71 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
72 | server=None, folder=None, username=None, password=None, |
|
72 | server=None, folder=None, username=None, password=None, | |
73 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
73 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
74 |
|
74 | |||
75 | """ |
|
75 | """ | |
76 |
|
76 | |||
77 | Input: |
|
77 | Input: | |
78 | dataOut : |
|
78 | dataOut : | |
79 | id : |
|
79 | id : | |
80 | wintitle : |
|
80 | wintitle : | |
81 | channelList : |
|
81 | channelList : | |
82 | showProfile : |
|
82 | showProfile : | |
83 | xmin : None, |
|
83 | xmin : None, | |
84 | xmax : None, |
|
84 | xmax : None, | |
85 | ymin : None, |
|
85 | ymin : None, | |
86 | ymax : None, |
|
86 | ymax : None, | |
87 | zmin : None, |
|
87 | zmin : None, | |
88 | zmax : None |
|
88 | zmax : None | |
89 | """ |
|
89 | """ | |
90 |
|
90 | |||
91 | if pairsList == None: |
|
91 | if pairsList == None: | |
92 | pairsIndexList = dataOut.pairsIndexList |
|
92 | pairsIndexList = dataOut.pairsIndexList | |
93 | else: |
|
93 | else: | |
94 | pairsIndexList = [] |
|
94 | pairsIndexList = [] | |
95 | for pair in pairsList: |
|
95 | for pair in pairsList: | |
96 | if pair not in dataOut.pairsList: |
|
96 | if pair not in dataOut.pairsList: | |
97 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
97 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
98 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
98 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
99 |
|
99 | |||
100 | if pairsIndexList == []: |
|
100 | if pairsIndexList == []: | |
101 | return |
|
101 | return | |
102 |
|
102 | |||
103 | if len(pairsIndexList) > 4: |
|
103 | if len(pairsIndexList) > 4: | |
104 | pairsIndexList = pairsIndexList[0:4] |
|
104 | pairsIndexList = pairsIndexList[0:4] | |
105 | factor = dataOut.normFactor |
|
105 | factor = dataOut.normFactor | |
106 | x = dataOut.getVelRange(1) |
|
106 | x = dataOut.getVelRange(1) | |
107 | y = dataOut.getHeiRange() |
|
107 | y = dataOut.getHeiRange() | |
108 | z = dataOut.data_spc[:,:,:]/factor |
|
108 | z = dataOut.data_spc[:,:,:]/factor | |
109 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
109 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
110 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
110 | avg = numpy.abs(numpy.average(z, axis=1)) | |
111 | noise = dataOut.getNoise()/factor |
|
111 | noise = dataOut.getNoise()/factor | |
112 |
|
112 | |||
113 | zdB = 10*numpy.log10(z) |
|
113 | zdB = 10*numpy.log10(z) | |
114 | avgdB = 10*numpy.log10(avg) |
|
114 | avgdB = 10*numpy.log10(avg) | |
115 | noisedB = 10*numpy.log10(noise) |
|
115 | noisedB = 10*numpy.log10(noise) | |
116 |
|
116 | |||
117 |
|
117 | |||
118 | #thisDatetime = dataOut.datatime |
|
118 | #thisDatetime = dataOut.datatime | |
119 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
119 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
120 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
120 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
121 | xlabel = "Velocity (m/s)" |
|
121 | xlabel = "Velocity (m/s)" | |
122 | ylabel = "Range (Km)" |
|
122 | ylabel = "Range (Km)" | |
123 |
|
123 | |||
124 | if not self.__isConfig: |
|
124 | if not self.__isConfig: | |
125 |
|
125 | |||
126 | nplots = len(pairsIndexList) |
|
126 | nplots = len(pairsIndexList) | |
127 |
|
127 | |||
128 | self.setup(id=id, |
|
128 | self.setup(id=id, | |
129 | nplots=nplots, |
|
129 | nplots=nplots, | |
130 | wintitle=wintitle, |
|
130 | wintitle=wintitle, | |
131 | showprofile=False, |
|
131 | showprofile=False, | |
132 | show=show) |
|
132 | show=show) | |
133 |
|
133 | |||
134 | if xmin == None: xmin = numpy.nanmin(x) |
|
134 | if xmin == None: xmin = numpy.nanmin(x) | |
135 | if xmax == None: xmax = numpy.nanmax(x) |
|
135 | if xmax == None: xmax = numpy.nanmax(x) | |
136 | if ymin == None: ymin = numpy.nanmin(y) |
|
136 | if ymin == None: ymin = numpy.nanmin(y) | |
137 | if ymax == None: ymax = numpy.nanmax(y) |
|
137 | if ymax == None: ymax = numpy.nanmax(y) | |
138 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
138 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
139 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
139 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
140 |
|
140 | |||
141 | self.FTP_WEI = ftp_wei |
|
141 | self.FTP_WEI = ftp_wei | |
142 | self.EXP_CODE = exp_code |
|
142 | self.EXP_CODE = exp_code | |
143 | self.SUB_EXP_CODE = sub_exp_code |
|
143 | self.SUB_EXP_CODE = sub_exp_code | |
144 | self.PLOT_POS = plot_pos |
|
144 | self.PLOT_POS = plot_pos | |
145 |
|
145 | |||
146 | self.__isConfig = True |
|
146 | self.__isConfig = True | |
147 |
|
147 | |||
148 | self.setWinTitle(title) |
|
148 | self.setWinTitle(title) | |
149 |
|
149 | |||
150 | for i in range(self.nplots): |
|
150 | for i in range(self.nplots): | |
151 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
151 | pair = dataOut.pairsList[pairsIndexList[i]] | |
152 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
152 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
153 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
153 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) | |
154 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) |
|
154 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]) | |
155 | axes0 = self.axesList[i*self.__nsubplots] |
|
155 | axes0 = self.axesList[i*self.__nsubplots] | |
156 | axes0.pcolor(x, y, zdB, |
|
156 | axes0.pcolor(x, y, zdB, | |
157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
157 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
158 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
158 | xlabel=xlabel, ylabel=ylabel, title=title, | |
159 | ticksize=9, colormap=power_cmap, cblabel='') |
|
159 | ticksize=9, colormap=power_cmap, cblabel='') | |
160 |
|
160 | |||
161 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
161 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) | |
162 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) |
|
162 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]) | |
163 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
163 | axes0 = self.axesList[i*self.__nsubplots+1] | |
164 | axes0.pcolor(x, y, zdB, |
|
164 | axes0.pcolor(x, y, zdB, | |
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
166 | xlabel=xlabel, ylabel=ylabel, title=title, | |
167 | ticksize=9, colormap=power_cmap, cblabel='') |
|
167 | ticksize=9, colormap=power_cmap, cblabel='') | |
168 |
|
168 | |||
169 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
169 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
170 | coherence = numpy.abs(coherenceComplex) |
|
170 | coherence = numpy.abs(coherenceComplex) | |
171 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
171 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
172 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
172 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | |
173 |
|
173 | |||
174 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
174 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
175 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
175 | axes0 = self.axesList[i*self.__nsubplots+2] | |
176 | axes0.pcolor(x, y, coherence, |
|
176 | axes0.pcolor(x, y, coherence, | |
177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
177 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
178 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
178 | xlabel=xlabel, ylabel=ylabel, title=title, | |
179 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
179 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
180 |
|
180 | |||
181 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
181 | title = "Phase %d%d" %(pair[0], pair[1]) | |
182 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
182 | axes0 = self.axesList[i*self.__nsubplots+3] | |
183 | axes0.pcolor(x, y, phase, |
|
183 | axes0.pcolor(x, y, phase, | |
184 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
184 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
185 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
185 | xlabel=xlabel, ylabel=ylabel, title=title, | |
186 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
186 | ticksize=9, colormap=phase_cmap, cblabel='') | |
187 |
|
187 | |||
188 |
|
188 | |||
189 |
|
189 | |||
190 | self.draw() |
|
190 | self.draw() | |
191 |
|
191 | |||
192 | if save: |
|
192 | if save: | |
193 |
|
193 | |||
194 | self.counter_imagwr += 1 |
|
194 | self.counter_imagwr += 1 | |
195 | if (self.counter_imagwr==wr_period): |
|
195 | if (self.counter_imagwr==wr_period): | |
196 | if figfile == None: |
|
196 | if figfile == None: | |
197 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
197 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
198 | figfile = self.getFilename(name = str_datetime) |
|
198 | figfile = self.getFilename(name = str_datetime) | |
199 |
|
199 | |||
200 | self.saveFigure(figpath, figfile) |
|
200 | self.saveFigure(figpath, figfile) | |
201 |
|
201 | |||
202 | if ftp: |
|
202 | if ftp: | |
203 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
203 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
205 | path = '%s%03d' %(self.PREFIX, self.id) |
|
205 | path = '%s%03d' %(self.PREFIX, self.id) | |
206 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
206 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
207 | self.saveFigure(figpath, ftp_file) |
|
207 | self.saveFigure(figpath, ftp_file) | |
208 | ftp_filename = os.path.join(figpath,ftp_file) |
|
208 | ftp_filename = os.path.join(figpath,ftp_file) | |
209 |
|
209 | |||
210 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
210 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
211 | self.counter_imagwr = 0 |
|
211 | self.counter_imagwr = 0 | |
212 |
|
212 | |||
213 | self.counter_imagwr = 0 |
|
213 | self.counter_imagwr = 0 | |
214 |
|
214 | |||
215 | class SNRPlot(Figure): |
|
215 | class SNRPlot(Figure): | |
216 |
|
216 | |||
217 | __isConfig = None |
|
217 | __isConfig = None | |
218 | __nsubplots = None |
|
218 | __nsubplots = None | |
219 |
|
219 | |||
220 | WIDTHPROF = None |
|
220 | WIDTHPROF = None | |
221 | HEIGHTPROF = None |
|
221 | HEIGHTPROF = None | |
222 | PREFIX = 'snr' |
|
222 | PREFIX = 'snr' | |
223 |
|
223 | |||
224 | def __init__(self): |
|
224 | def __init__(self): | |
225 |
|
225 | |||
226 | self.timerange = 2*60*60 |
|
226 | self.timerange = 2*60*60 | |
227 | self.__isConfig = False |
|
227 | self.__isConfig = False | |
228 | self.__nsubplots = 1 |
|
228 | self.__nsubplots = 1 | |
229 |
|
229 | |||
230 | self.WIDTH = 800 |
|
230 | self.WIDTH = 800 | |
231 | self.HEIGHT = 150 |
|
231 | self.HEIGHT = 150 | |
232 | self.WIDTHPROF = 120 |
|
232 | self.WIDTHPROF = 120 | |
233 | self.HEIGHTPROF = 0 |
|
233 | self.HEIGHTPROF = 0 | |
234 | self.counter_imagwr = 0 |
|
234 | self.counter_imagwr = 0 | |
235 |
|
235 | |||
236 | self.PLOT_CODE = 0 |
|
236 | self.PLOT_CODE = 0 | |
237 | self.FTP_WEI = None |
|
237 | self.FTP_WEI = None | |
238 | self.EXP_CODE = None |
|
238 | self.EXP_CODE = None | |
239 | self.SUB_EXP_CODE = None |
|
239 | self.SUB_EXP_CODE = None | |
240 | self.PLOT_POS = None |
|
240 | self.PLOT_POS = None | |
241 |
|
241 | |||
242 | def getSubplots(self): |
|
242 | def getSubplots(self): | |
243 |
|
243 | |||
244 | ncol = 1 |
|
244 | ncol = 1 | |
245 | nrow = self.nplots |
|
245 | nrow = self.nplots | |
246 |
|
246 | |||
247 | return nrow, ncol |
|
247 | return nrow, ncol | |
248 |
|
248 | |||
249 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
249 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
250 |
|
250 | |||
251 | self.__showprofile = showprofile |
|
251 | self.__showprofile = showprofile | |
252 | self.nplots = nplots |
|
252 | self.nplots = nplots | |
253 |
|
253 | |||
254 | ncolspan = 1 |
|
254 | ncolspan = 1 | |
255 | colspan = 1 |
|
255 | colspan = 1 | |
256 | if showprofile: |
|
256 | if showprofile: | |
257 | ncolspan = 7 |
|
257 | ncolspan = 7 | |
258 | colspan = 6 |
|
258 | colspan = 6 | |
259 | self.__nsubplots = 2 |
|
259 | self.__nsubplots = 2 | |
260 |
|
260 | |||
261 | self.createFigure(id = id, |
|
261 | self.createFigure(id = id, | |
262 | wintitle = wintitle, |
|
262 | wintitle = wintitle, | |
263 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
263 | widthplot = self.WIDTH + self.WIDTHPROF, | |
264 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
264 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
265 | show=show) |
|
265 | show=show) | |
266 |
|
266 | |||
267 | nrow, ncol = self.getSubplots() |
|
267 | nrow, ncol = self.getSubplots() | |
268 |
|
268 | |||
269 | counter = 0 |
|
269 | counter = 0 | |
270 | for y in range(nrow): |
|
270 | for y in range(nrow): | |
271 | for x in range(ncol): |
|
271 | for x in range(ncol): | |
272 |
|
272 | |||
273 | if counter >= self.nplots: |
|
273 | if counter >= self.nplots: | |
274 | break |
|
274 | break | |
275 |
|
275 | |||
276 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
276 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
277 |
|
277 | |||
278 | if showprofile: |
|
278 | if showprofile: | |
279 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
279 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
280 |
|
280 | |||
281 | counter += 1 |
|
281 | counter += 1 | |
282 |
|
282 | |||
283 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
283 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, | |
284 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
284 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
285 | timerange=None, |
|
285 | timerange=None, | |
286 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
286 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
287 | server=None, folder=None, username=None, password=None, |
|
287 | server=None, folder=None, username=None, password=None, | |
288 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
288 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
289 |
|
289 | |||
290 | """ |
|
290 | """ | |
291 |
|
291 | |||
292 | Input: |
|
292 | Input: | |
293 | dataOut : |
|
293 | dataOut : | |
294 | id : |
|
294 | id : | |
295 | wintitle : |
|
295 | wintitle : | |
296 | channelList : |
|
296 | channelList : | |
297 | showProfile : |
|
297 | showProfile : | |
298 | xmin : None, |
|
298 | xmin : None, | |
299 | xmax : None, |
|
299 | xmax : None, | |
300 | ymin : None, |
|
300 | ymin : None, | |
301 | ymax : None, |
|
301 | ymax : None, | |
302 | zmin : None, |
|
302 | zmin : None, | |
303 | zmax : None |
|
303 | zmax : None | |
304 | """ |
|
304 | """ | |
305 |
|
305 | |||
306 | if channelList == None: |
|
306 | if channelList == None: | |
307 | channelIndexList = dataOut.channelIndexList |
|
307 | channelIndexList = dataOut.channelIndexList | |
308 | else: |
|
308 | else: | |
309 | channelIndexList = [] |
|
309 | channelIndexList = [] | |
310 | for channel in channelList: |
|
310 | for channel in channelList: | |
311 | if channel not in dataOut.channelList: |
|
311 | if channel not in dataOut.channelList: | |
312 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
312 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
313 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
313 | channelIndexList.append(dataOut.channelList.index(channel)) | |
314 |
|
314 | |||
315 | if timerange != None: |
|
315 | if timerange != None: | |
316 | self.timerange = timerange |
|
316 | self.timerange = timerange | |
317 |
|
317 | |||
318 | tmin = None |
|
318 | tmin = None | |
319 | tmax = None |
|
319 | tmax = None | |
320 | factor = dataOut.normFactor |
|
320 | factor = dataOut.normFactor | |
321 | x = dataOut.getTimeRange() |
|
321 | x = dataOut.getTimeRange() | |
322 | y = dataOut.getHeiRange() |
|
322 | y = dataOut.getHeiRange() | |
323 |
|
323 | |||
324 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
324 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
325 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
325 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
326 | avg = numpy.average(z, axis=1) |
|
326 | avg = numpy.average(z, axis=1) | |
327 |
|
327 | |||
328 | avgdB = 10.*numpy.log10(avg) |
|
328 | avgdB = 10.*numpy.log10(avg) | |
329 |
|
329 | |||
330 | noise = dataOut.getNoise()/factor |
|
330 | noise = dataOut.getNoise()/factor | |
331 | noisedB = 10.*numpy.log10(noise) |
|
331 | noisedB = 10.*numpy.log10(noise) | |
332 |
|
332 | |||
333 | SNR = numpy.transpose(numpy.divide(avg.T,noise)) |
|
333 | SNR = numpy.transpose(numpy.divide(avg.T,noise)) | |
334 |
|
334 | |||
335 | SNR_dB = 10.*numpy.log10(SNR) |
|
335 | SNR_dB = 10.*numpy.log10(SNR) | |
336 |
|
336 | |||
337 | #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB)) |
|
337 | #SNR_dB = numpy.transpose(numpy.subtract(avgdB.T, noisedB)) | |
338 |
|
338 | |||
339 | # thisDatetime = dataOut.datatime |
|
339 | # thisDatetime = dataOut.datatime | |
340 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
340 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
341 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
341 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
342 | xlabel = "" |
|
342 | xlabel = "" | |
343 | ylabel = "Range (Km)" |
|
343 | ylabel = "Range (Km)" | |
344 |
|
344 | |||
345 | if not self.__isConfig: |
|
345 | if not self.__isConfig: | |
346 |
|
346 | |||
347 | nplots = len(channelIndexList) |
|
347 | nplots = len(channelIndexList) | |
348 |
|
348 | |||
349 | self.setup(id=id, |
|
349 | self.setup(id=id, | |
350 | nplots=nplots, |
|
350 | nplots=nplots, | |
351 | wintitle=wintitle, |
|
351 | wintitle=wintitle, | |
352 | showprofile=showprofile, |
|
352 | showprofile=showprofile, | |
353 | show=show) |
|
353 | show=show) | |
354 |
|
354 | |||
355 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
355 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
356 | if ymin == None: ymin = numpy.nanmin(y) |
|
356 | if ymin == None: ymin = numpy.nanmin(y) | |
357 | if ymax == None: ymax = numpy.nanmax(y) |
|
357 | if ymax == None: ymax = numpy.nanmax(y) | |
358 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
358 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
359 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
359 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
360 |
|
360 | |||
361 | self.FTP_WEI = ftp_wei |
|
361 | self.FTP_WEI = ftp_wei | |
362 | self.EXP_CODE = exp_code |
|
362 | self.EXP_CODE = exp_code | |
363 | self.SUB_EXP_CODE = sub_exp_code |
|
363 | self.SUB_EXP_CODE = sub_exp_code | |
364 | self.PLOT_POS = plot_pos |
|
364 | self.PLOT_POS = plot_pos | |
365 |
|
365 | |||
366 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
366 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
367 | self.__isConfig = True |
|
367 | self.__isConfig = True | |
368 |
|
368 | |||
369 |
|
369 | |||
370 | self.setWinTitle(title) |
|
370 | self.setWinTitle(title) | |
371 |
|
371 | |||
372 | for i in range(self.nplots): |
|
372 | for i in range(self.nplots): | |
373 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
373 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
374 | axes = self.axesList[i*self.__nsubplots] |
|
374 | axes = self.axesList[i*self.__nsubplots] | |
375 | zdB = SNR_dB[i].reshape((1,-1)) |
|
375 | zdB = SNR_dB[i].reshape((1,-1)) | |
376 | axes.pcolorbuffer(x, y, zdB, |
|
376 | axes.pcolorbuffer(x, y, zdB, | |
377 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
377 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
378 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
378 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
379 | ticksize=9, cblabel='', cbsize="1%") |
|
379 | ticksize=9, cblabel='', cbsize="1%") | |
380 |
|
380 | |||
381 | # if self.__showprofile: |
|
381 | # if self.__showprofile: | |
382 | # axes = self.axesList[i*self.__nsubplots +1] |
|
382 | # axes = self.axesList[i*self.__nsubplots +1] | |
383 | # axes.pline(avgdB[i], y, |
|
383 | # axes.pline(avgdB[i], y, | |
384 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
384 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
385 | # xlabel='dB', ylabel='', title='', |
|
385 | # xlabel='dB', ylabel='', title='', | |
386 | # ytick_visible=False, |
|
386 | # ytick_visible=False, | |
387 | # grid='x') |
|
387 | # grid='x') | |
388 | # |
|
388 | # | |
389 | self.draw() |
|
389 | self.draw() | |
390 |
|
390 | |||
391 | if lastone: |
|
391 | if lastone: | |
392 | if dataOut.blocknow >= dataOut.last_block: |
|
392 | if dataOut.blocknow >= dataOut.last_block: | |
393 | if figfile == None: |
|
393 | if figfile == None: | |
394 | figfile = self.getFilename(name = self.name) |
|
394 | figfile = self.getFilename(name = self.name) | |
395 | self.saveFigure(figpath, figfile) |
|
395 | self.saveFigure(figpath, figfile) | |
396 |
|
396 | |||
397 | if (save and not(lastone)): |
|
397 | if (save and not(lastone)): | |
398 |
|
398 | |||
399 | self.counter_imagwr += 1 |
|
399 | self.counter_imagwr += 1 | |
400 | if (self.counter_imagwr==wr_period): |
|
400 | if (self.counter_imagwr==wr_period): | |
401 | if figfile == None: |
|
401 | if figfile == None: | |
402 | figfile = self.getFilename(name = self.name) |
|
402 | figfile = self.getFilename(name = self.name) | |
403 | self.saveFigure(figpath, figfile) |
|
403 | self.saveFigure(figpath, figfile) | |
404 |
|
404 | |||
405 | if ftp: |
|
405 | if ftp: | |
406 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
406 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
407 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
407 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
408 | path = '%s%03d' %(self.PREFIX, self.id) |
|
408 | path = '%s%03d' %(self.PREFIX, self.id) | |
409 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
409 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
410 | self.saveFigure(figpath, ftp_file) |
|
410 | self.saveFigure(figpath, ftp_file) | |
411 | ftp_filename = os.path.join(figpath,ftp_file) |
|
411 | ftp_filename = os.path.join(figpath,ftp_file) | |
412 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
412 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
413 | self.counter_imagwr = 0 |
|
413 | self.counter_imagwr = 0 | |
414 |
|
414 | |||
415 | self.counter_imagwr = 0 |
|
415 | self.counter_imagwr = 0 | |
416 |
|
416 | |||
417 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
417 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
418 |
|
418 | |||
419 | self.__isConfig = False |
|
419 | self.__isConfig = False | |
420 |
|
420 | |||
421 | if lastone: |
|
421 | if lastone: | |
422 | if figfile == None: |
|
422 | if figfile == None: | |
423 | figfile = self.getFilename(name = self.name) |
|
423 | figfile = self.getFilename(name = self.name) | |
424 | self.saveFigure(figpath, figfile) |
|
424 | self.saveFigure(figpath, figfile) | |
425 |
|
425 | |||
426 | if ftp: |
|
426 | if ftp: | |
427 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
427 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
428 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
428 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
429 | path = '%s%03d' %(self.PREFIX, self.id) |
|
429 | path = '%s%03d' %(self.PREFIX, self.id) | |
430 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
430 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
431 | self.saveFigure(figpath, ftp_file) |
|
431 | self.saveFigure(figpath, ftp_file) | |
432 | ftp_filename = os.path.join(figpath,ftp_file) |
|
432 | ftp_filename = os.path.join(figpath,ftp_file) | |
433 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
433 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
434 |
|
434 | |||
435 |
|
435 | |||
436 | class RTIPlot(Figure): |
|
436 | class RTIPlot(Figure): | |
437 |
|
437 | |||
438 | __isConfig = None |
|
438 | __isConfig = None | |
439 | __nsubplots = None |
|
439 | __nsubplots = None | |
440 |
|
440 | |||
441 | WIDTHPROF = None |
|
441 | WIDTHPROF = None | |
442 | HEIGHTPROF = None |
|
442 | HEIGHTPROF = None | |
443 | PREFIX = 'rti' |
|
443 | PREFIX = 'rti' | |
444 |
|
444 | |||
445 | def __init__(self): |
|
445 | def __init__(self): | |
446 |
|
446 | |||
447 | self.timerange = 2*60*60 |
|
447 | self.timerange = 2*60*60 | |
448 | self.__isConfig = False |
|
448 | self.__isConfig = False | |
449 | self.__nsubplots = 1 |
|
449 | self.__nsubplots = 1 | |
450 |
|
450 | |||
451 | self.WIDTH = 800 |
|
451 | self.WIDTH = 800 | |
452 | self.HEIGHT = 150 |
|
452 | self.HEIGHT = 150 | |
453 | self.WIDTHPROF = 120 |
|
453 | self.WIDTHPROF = 120 | |
454 | self.HEIGHTPROF = 0 |
|
454 | self.HEIGHTPROF = 0 | |
455 | self.counter_imagwr = 0 |
|
455 | self.counter_imagwr = 0 | |
456 |
|
456 | |||
457 | self.PLOT_CODE = 0 |
|
457 | self.PLOT_CODE = 0 | |
458 | self.FTP_WEI = None |
|
458 | self.FTP_WEI = None | |
459 | self.EXP_CODE = None |
|
459 | self.EXP_CODE = None | |
460 | self.SUB_EXP_CODE = None |
|
460 | self.SUB_EXP_CODE = None | |
461 | self.PLOT_POS = None |
|
461 | self.PLOT_POS = None | |
462 | self.tmin = None |
|
462 | self.tmin = None | |
463 | self.tmax = None |
|
463 | self.tmax = None | |
464 |
|
464 | |||
465 | self.xmin = None |
|
465 | self.xmin = None | |
466 | self.xmax = None |
|
466 | self.xmax = None | |
467 |
|
467 | |||
468 | def getSubplots(self): |
|
468 | def getSubplots(self): | |
469 |
|
469 | |||
470 | ncol = 1 |
|
470 | ncol = 1 | |
471 | nrow = self.nplots |
|
471 | nrow = self.nplots | |
472 |
|
472 | |||
473 | return nrow, ncol |
|
473 | return nrow, ncol | |
474 |
|
474 | |||
475 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
475 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
476 |
|
476 | |||
477 | self.__showprofile = showprofile |
|
477 | self.__showprofile = showprofile | |
478 | self.nplots = nplots |
|
478 | self.nplots = nplots | |
479 |
|
479 | |||
480 | ncolspan = 1 |
|
480 | ncolspan = 1 | |
481 | colspan = 1 |
|
481 | colspan = 1 | |
482 | if showprofile: |
|
482 | if showprofile: | |
483 | ncolspan = 7 |
|
483 | ncolspan = 7 | |
484 | colspan = 6 |
|
484 | colspan = 6 | |
485 | self.__nsubplots = 2 |
|
485 | self.__nsubplots = 2 | |
486 |
|
486 | |||
487 | self.createFigure(id = id, |
|
487 | self.createFigure(id = id, | |
488 | wintitle = wintitle, |
|
488 | wintitle = wintitle, | |
489 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
489 | widthplot = self.WIDTH + self.WIDTHPROF, | |
490 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
490 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
491 | show=show) |
|
491 | show=show) | |
492 |
|
492 | |||
493 | nrow, ncol = self.getSubplots() |
|
493 | nrow, ncol = self.getSubplots() | |
494 |
|
494 | |||
495 | counter = 0 |
|
495 | counter = 0 | |
496 | for y in range(nrow): |
|
496 | for y in range(nrow): | |
497 | for x in range(ncol): |
|
497 | for x in range(ncol): | |
498 |
|
498 | |||
499 | if counter >= self.nplots: |
|
499 | if counter >= self.nplots: | |
500 | break |
|
500 | break | |
501 |
|
501 | |||
502 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
502 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
503 |
|
503 | |||
504 | if showprofile: |
|
504 | if showprofile: | |
505 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
505 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
506 |
|
506 | |||
507 | counter += 1 |
|
507 | counter += 1 | |
508 |
|
508 | |||
509 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
509 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
510 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
510 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
511 | timerange=None, |
|
511 | timerange=None, | |
512 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
512 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
513 | server=None, folder=None, username=None, password=None, |
|
513 | server=None, folder=None, username=None, password=None, | |
514 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
514 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
515 |
|
515 | |||
516 | """ |
|
516 | """ | |
517 |
|
517 | |||
518 | Input: |
|
518 | Input: | |
519 | dataOut : |
|
519 | dataOut : | |
520 | id : |
|
520 | id : | |
521 | wintitle : |
|
521 | wintitle : | |
522 | channelList : |
|
522 | channelList : | |
523 | showProfile : |
|
523 | showProfile : | |
524 | xmin : None, |
|
524 | xmin : None, | |
525 | xmax : None, |
|
525 | xmax : None, | |
526 | ymin : None, |
|
526 | ymin : None, | |
527 | ymax : None, |
|
527 | ymax : None, | |
528 | zmin : None, |
|
528 | zmin : None, | |
529 | zmax : None |
|
529 | zmax : None | |
530 | """ |
|
530 | """ | |
531 |
|
531 | |||
532 | if channelList == None: |
|
532 | if channelList == None: | |
533 | channelIndexList = dataOut.channelIndexList |
|
533 | channelIndexList = dataOut.channelIndexList | |
534 | else: |
|
534 | else: | |
535 | channelIndexList = [] |
|
535 | channelIndexList = [] | |
536 | for channel in channelList: |
|
536 | for channel in channelList: | |
537 | if channel not in dataOut.channelList: |
|
537 | if channel not in dataOut.channelList: | |
538 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
538 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
539 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
539 | channelIndexList.append(dataOut.channelList.index(channel)) | |
540 |
|
540 | |||
541 | if timerange != None: |
|
541 | if timerange != None: | |
542 | self.timerange = timerange |
|
542 | self.timerange = timerange | |
543 |
|
543 | |||
544 | #tmin = None |
|
544 | #tmin = None | |
545 | #tmax = None |
|
545 | #tmax = None | |
546 | factor = dataOut.normFactor |
|
546 | factor = dataOut.normFactor | |
547 | x = dataOut.getTimeRange() |
|
547 | x = dataOut.getTimeRange() | |
548 | y = dataOut.getHeiRange() |
|
548 | y = dataOut.getHeiRange() | |
549 |
|
549 | |||
550 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
550 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
551 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
551 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
552 | avg = numpy.average(z, axis=1) |
|
552 | avg = numpy.average(z, axis=1) | |
553 |
|
553 | |||
554 | avgdB = 10.*numpy.log10(avg) |
|
554 | avgdB = 10.*numpy.log10(avg) | |
555 |
|
555 | |||
556 |
|
556 | |||
557 | # thisDatetime = dataOut.datatime |
|
557 | # thisDatetime = dataOut.datatime | |
558 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
558 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
559 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
559 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
560 | xlabel = "" |
|
560 | xlabel = "" | |
561 | ylabel = "Range (Km)" |
|
561 | ylabel = "Range (Km)" | |
562 |
|
562 | |||
563 | if not self.__isConfig: |
|
563 | if not self.__isConfig: | |
564 |
|
564 | |||
565 | nplots = len(channelIndexList) |
|
565 | nplots = len(channelIndexList) | |
566 |
|
566 | |||
567 | self.setup(id=id, |
|
567 | self.setup(id=id, | |
568 | nplots=nplots, |
|
568 | nplots=nplots, | |
569 | wintitle=wintitle, |
|
569 | wintitle=wintitle, | |
570 | showprofile=showprofile, |
|
570 | showprofile=showprofile, | |
571 | show=show) |
|
571 | show=show) | |
572 |
|
572 | |||
573 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
573 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
574 |
|
574 | |||
575 | # if timerange != None: |
|
575 | # if timerange != None: | |
576 | # self.timerange = timerange |
|
576 | # self.timerange = timerange | |
577 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
577 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) | |
578 |
|
578 | |||
579 |
|
579 | |||
580 |
|
580 | |||
581 | if ymin == None: ymin = numpy.nanmin(y) |
|
581 | if ymin == None: ymin = numpy.nanmin(y) | |
582 | if ymax == None: ymax = numpy.nanmax(y) |
|
582 | if ymax == None: ymax = numpy.nanmax(y) | |
583 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
583 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
584 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
584 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
585 |
|
585 | |||
586 | self.FTP_WEI = ftp_wei |
|
586 | self.FTP_WEI = ftp_wei | |
587 | self.EXP_CODE = exp_code |
|
587 | self.EXP_CODE = exp_code | |
588 | self.SUB_EXP_CODE = sub_exp_code |
|
588 | self.SUB_EXP_CODE = sub_exp_code | |
589 | self.PLOT_POS = plot_pos |
|
589 | self.PLOT_POS = plot_pos | |
590 |
|
590 | |||
591 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
591 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
592 | self.__isConfig = True |
|
592 | self.__isConfig = True | |
593 |
|
593 | |||
594 |
|
594 | |||
595 | self.setWinTitle(title) |
|
595 | self.setWinTitle(title) | |
596 |
|
596 | |||
597 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
597 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
598 | x[1] = self.xmax |
|
598 | x[1] = self.xmax | |
599 |
|
599 | |||
600 | for i in range(self.nplots): |
|
600 | for i in range(self.nplots): | |
601 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
601 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
602 | axes = self.axesList[i*self.__nsubplots] |
|
602 | axes = self.axesList[i*self.__nsubplots] | |
603 | zdB = avgdB[i].reshape((1,-1)) |
|
603 | zdB = avgdB[i].reshape((1,-1)) | |
604 | axes.pcolorbuffer(x, y, zdB, |
|
604 | axes.pcolorbuffer(x, y, zdB, | |
605 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
605 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
606 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
606 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
607 | ticksize=9, cblabel='', cbsize="1%") |
|
607 | ticksize=9, cblabel='', cbsize="1%") | |
608 |
|
608 | |||
609 | if self.__showprofile: |
|
609 | if self.__showprofile: | |
610 | axes = self.axesList[i*self.__nsubplots +1] |
|
610 | axes = self.axesList[i*self.__nsubplots +1] | |
611 | axes.pline(avgdB[i], y, |
|
611 | axes.pline(avgdB[i], y, | |
612 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
612 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
613 | xlabel='dB', ylabel='', title='', |
|
613 | xlabel='dB', ylabel='', title='', | |
614 | ytick_visible=False, |
|
614 | ytick_visible=False, | |
615 | grid='x') |
|
615 | grid='x') | |
616 |
|
616 | |||
617 | self.draw() |
|
617 | self.draw() | |
618 |
|
618 | |||
619 | # if lastone: |
|
619 | # if lastone: | |
620 | # if dataOut.blocknow >= dataOut.last_block: |
|
620 | # if dataOut.blocknow >= dataOut.last_block: | |
621 | # if figfile == None: |
|
621 | # if figfile == None: | |
622 | # figfile = self.getFilename(name = self.name) |
|
622 | # figfile = self.getFilename(name = self.name) | |
623 | # self.saveFigure(figpath, figfile) |
|
623 | # self.saveFigure(figpath, figfile) | |
624 | # |
|
624 | # | |
625 | # if (save and not(lastone)): |
|
625 | # if (save and not(lastone)): | |
626 | # |
|
626 | # | |
627 | # self.counter_imagwr += 1 |
|
627 | # self.counter_imagwr += 1 | |
628 | # if (self.counter_imagwr==wr_period): |
|
628 | # if (self.counter_imagwr==wr_period): | |
629 | # if figfile == None: |
|
629 | # if figfile == None: | |
630 | # figfile = self.getFilename(name = self.name) |
|
630 | # figfile = self.getFilename(name = self.name) | |
631 | # self.saveFigure(figpath, figfile) |
|
631 | # self.saveFigure(figpath, figfile) | |
632 | # |
|
632 | # | |
633 | # if ftp: |
|
633 | # if ftp: | |
634 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
634 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |
635 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
635 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
636 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
636 | # path = '%s%03d' %(self.PREFIX, self.id) | |
637 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
637 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
638 | # self.saveFigure(figpath, ftp_file) |
|
638 | # self.saveFigure(figpath, ftp_file) | |
639 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
639 | # ftp_filename = os.path.join(figpath,ftp_file) | |
640 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
640 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
641 | # self.counter_imagwr = 0 |
|
641 | # self.counter_imagwr = 0 | |
642 | # |
|
642 | # | |
643 | # self.counter_imagwr = 0 |
|
643 | # self.counter_imagwr = 0 | |
644 |
|
644 | |||
645 | #if ((dataOut.utctime-time.timezone) >= self.axesList[0].xmax): |
|
645 | #if ((dataOut.utctime-time.timezone) >= self.axesList[0].xmax): | |
646 | if x[1] >= self.axesList[0].xmax: |
|
646 | if x[1] >= self.axesList[0].xmax: | |
647 | self.saveFigure(figpath, figfile) |
|
647 | self.saveFigure(figpath, figfile) | |
648 | self.__isConfig = False |
|
648 | self.__isConfig = False | |
649 |
|
649 | |||
650 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
650 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
651 | # |
|
651 | # | |
652 | # self.__isConfig = False |
|
652 | # self.__isConfig = False | |
653 |
|
653 | |||
654 | # if lastone: |
|
654 | # if lastone: | |
655 | # if figfile == None: |
|
655 | # if figfile == None: | |
656 | # figfile = self.getFilename(name = self.name) |
|
656 | # figfile = self.getFilename(name = self.name) | |
657 | # self.saveFigure(figpath, figfile) |
|
657 | # self.saveFigure(figpath, figfile) | |
658 | # |
|
658 | # | |
659 | # if ftp: |
|
659 | # if ftp: | |
660 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
660 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |
661 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
661 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
662 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
662 | # path = '%s%03d' %(self.PREFIX, self.id) | |
663 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
663 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
664 | # self.saveFigure(figpath, ftp_file) |
|
664 | # self.saveFigure(figpath, ftp_file) | |
665 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
665 | # ftp_filename = os.path.join(figpath,ftp_file) | |
666 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
666 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
667 |
|
667 | |||
668 |
|
668 | |||
669 | class SpectraPlot(Figure): |
|
669 | class SpectraPlot(Figure): | |
670 |
|
670 | |||
671 | __isConfig = None |
|
671 | __isConfig = None | |
672 | __nsubplots = None |
|
672 | __nsubplots = None | |
673 |
|
673 | |||
674 | WIDTHPROF = None |
|
674 | WIDTHPROF = None | |
675 | HEIGHTPROF = None |
|
675 | HEIGHTPROF = None | |
676 | PREFIX = 'spc' |
|
676 | PREFIX = 'spc' | |
677 |
|
677 | |||
678 | def __init__(self): |
|
678 | def __init__(self): | |
679 |
|
679 | |||
680 | self.__isConfig = False |
|
680 | self.__isConfig = False | |
681 | self.__nsubplots = 1 |
|
681 | self.__nsubplots = 1 | |
682 |
|
682 | |||
683 | self.WIDTH = 280 |
|
683 | self.WIDTH = 280 | |
684 | self.HEIGHT = 250 |
|
684 | self.HEIGHT = 250 | |
685 | self.WIDTHPROF = 120 |
|
685 | self.WIDTHPROF = 120 | |
686 | self.HEIGHTPROF = 0 |
|
686 | self.HEIGHTPROF = 0 | |
687 | self.counter_imagwr = 0 |
|
687 | self.counter_imagwr = 0 | |
688 |
|
688 | |||
689 | self.PLOT_CODE = 1 |
|
689 | self.PLOT_CODE = 1 | |
690 | self.FTP_WEI = None |
|
690 | self.FTP_WEI = None | |
691 | self.EXP_CODE = None |
|
691 | self.EXP_CODE = None | |
692 | self.SUB_EXP_CODE = None |
|
692 | self.SUB_EXP_CODE = None | |
693 | self.PLOT_POS = None |
|
693 | self.PLOT_POS = None | |
694 |
|
694 | |||
695 | def getSubplots(self): |
|
695 | def getSubplots(self): | |
696 |
|
696 | |||
697 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
697 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
698 | nrow = int(self.nplots*1./ncol + 0.9) |
|
698 | nrow = int(self.nplots*1./ncol + 0.9) | |
699 |
|
699 | |||
700 | return nrow, ncol |
|
700 | return nrow, ncol | |
701 |
|
701 | |||
702 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
702 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
703 |
|
703 | |||
704 | self.__showprofile = showprofile |
|
704 | self.__showprofile = showprofile | |
705 | self.nplots = nplots |
|
705 | self.nplots = nplots | |
706 |
|
706 | |||
707 | ncolspan = 1 |
|
707 | ncolspan = 1 | |
708 | colspan = 1 |
|
708 | colspan = 1 | |
709 | if showprofile: |
|
709 | if showprofile: | |
710 | ncolspan = 3 |
|
710 | ncolspan = 3 | |
711 | colspan = 2 |
|
711 | colspan = 2 | |
712 | self.__nsubplots = 2 |
|
712 | self.__nsubplots = 2 | |
713 |
|
713 | |||
714 | self.createFigure(id = id, |
|
714 | self.createFigure(id = id, | |
715 | wintitle = wintitle, |
|
715 | wintitle = wintitle, | |
716 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
716 | widthplot = self.WIDTH + self.WIDTHPROF, | |
717 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
717 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
718 | show=show) |
|
718 | show=show) | |
719 |
|
719 | |||
720 | nrow, ncol = self.getSubplots() |
|
720 | nrow, ncol = self.getSubplots() | |
721 |
|
721 | |||
722 | counter = 0 |
|
722 | counter = 0 | |
723 | for y in range(nrow): |
|
723 | for y in range(nrow): | |
724 | for x in range(ncol): |
|
724 | for x in range(ncol): | |
725 |
|
725 | |||
726 | if counter >= self.nplots: |
|
726 | if counter >= self.nplots: | |
727 | break |
|
727 | break | |
728 |
|
728 | |||
729 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
729 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
730 |
|
730 | |||
731 | if showprofile: |
|
731 | if showprofile: | |
732 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
732 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
733 |
|
733 | |||
734 | counter += 1 |
|
734 | counter += 1 | |
735 |
|
735 | |||
736 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
736 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | |
737 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
737 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
738 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
738 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
739 | server=None, folder=None, username=None, password=None, |
|
739 | server=None, folder=None, username=None, password=None, | |
740 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
740 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
741 |
|
741 | |||
742 | """ |
|
742 | """ | |
743 |
|
743 | |||
744 | Input: |
|
744 | Input: | |
745 | dataOut : |
|
745 | dataOut : | |
746 | id : |
|
746 | id : | |
747 | wintitle : |
|
747 | wintitle : | |
748 | channelList : |
|
748 | channelList : | |
749 | showProfile : |
|
749 | showProfile : | |
750 | xmin : None, |
|
750 | xmin : None, | |
751 | xmax : None, |
|
751 | xmax : None, | |
752 | ymin : None, |
|
752 | ymin : None, | |
753 | ymax : None, |
|
753 | ymax : None, | |
754 | zmin : None, |
|
754 | zmin : None, | |
755 | zmax : None |
|
755 | zmax : None | |
756 | """ |
|
756 | """ | |
757 |
|
757 | |||
758 | if realtime: |
|
758 | if realtime: | |
759 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
759 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
760 | print 'Skipping this plot function' |
|
760 | print 'Skipping this plot function' | |
761 | return |
|
761 | return | |
762 |
|
762 | |||
763 | if channelList == None: |
|
763 | if channelList == None: | |
764 | channelIndexList = dataOut.channelIndexList |
|
764 | channelIndexList = dataOut.channelIndexList | |
765 | else: |
|
765 | else: | |
766 | channelIndexList = [] |
|
766 | channelIndexList = [] | |
767 | for channel in channelList: |
|
767 | for channel in channelList: | |
768 | if channel not in dataOut.channelList: |
|
768 | if channel not in dataOut.channelList: | |
769 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
769 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
770 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
770 | channelIndexList.append(dataOut.channelList.index(channel)) | |
771 | factor = dataOut.normFactor |
|
771 | factor = dataOut.normFactor | |
772 | x = dataOut.getVelRange(1) |
|
772 | x = dataOut.getVelRange(1) | |
773 | y = dataOut.getHeiRange() |
|
773 | y = dataOut.getHeiRange() | |
774 |
|
774 | |||
775 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
775 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
776 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
776 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
777 | avg = numpy.average(z, axis=1) |
|
777 | avg = numpy.average(z, axis=1) | |
778 | noise = dataOut.getNoise()/factor |
|
778 | noise = dataOut.getNoise()/factor | |
779 |
|
779 | |||
780 | zdB = 10*numpy.log10(z) |
|
780 | zdB = 10*numpy.log10(z) | |
781 | avgdB = 10*numpy.log10(avg) |
|
781 | avgdB = 10*numpy.log10(avg) | |
782 | noisedB = 10*numpy.log10(noise) |
|
782 | noisedB = 10*numpy.log10(noise) | |
783 |
|
783 | |||
784 | #thisDatetime = dataOut.datatime |
|
784 | #thisDatetime = dataOut.datatime | |
785 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
785 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
786 | title = wintitle + " Spectra" |
|
786 | title = wintitle + " Spectra" | |
787 | xlabel = "Velocity (m/s)" |
|
787 | xlabel = "Velocity (m/s)" | |
788 | ylabel = "Range (Km)" |
|
788 | ylabel = "Range (Km)" | |
789 |
|
789 | |||
790 | if not self.__isConfig: |
|
790 | if not self.__isConfig: | |
791 |
|
791 | |||
792 | nplots = len(channelIndexList) |
|
792 | nplots = len(channelIndexList) | |
793 |
|
793 | |||
794 | self.setup(id=id, |
|
794 | self.setup(id=id, | |
795 | nplots=nplots, |
|
795 | nplots=nplots, | |
796 | wintitle=wintitle, |
|
796 | wintitle=wintitle, | |
797 | showprofile=showprofile, |
|
797 | showprofile=showprofile, | |
798 | show=show) |
|
798 | show=show) | |
799 |
|
799 | |||
800 | if xmin == None: xmin = numpy.nanmin(x) |
|
800 | if xmin == None: xmin = numpy.nanmin(x) | |
801 | if xmax == None: xmax = numpy.nanmax(x) |
|
801 | if xmax == None: xmax = numpy.nanmax(x) | |
802 | if ymin == None: ymin = numpy.nanmin(y) |
|
802 | if ymin == None: ymin = numpy.nanmin(y) | |
803 | if ymax == None: ymax = numpy.nanmax(y) |
|
803 | if ymax == None: ymax = numpy.nanmax(y) | |
804 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
804 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
805 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
805 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
806 |
|
806 | |||
807 | self.FTP_WEI = ftp_wei |
|
807 | self.FTP_WEI = ftp_wei | |
808 | self.EXP_CODE = exp_code |
|
808 | self.EXP_CODE = exp_code | |
809 | self.SUB_EXP_CODE = sub_exp_code |
|
809 | self.SUB_EXP_CODE = sub_exp_code | |
810 | self.PLOT_POS = plot_pos |
|
810 | self.PLOT_POS = plot_pos | |
811 |
|
811 | |||
812 | self.__isConfig = True |
|
812 | self.__isConfig = True | |
813 |
|
813 | |||
814 | self.setWinTitle(title) |
|
814 | self.setWinTitle(title) | |
815 |
|
815 | |||
816 | for i in range(self.nplots): |
|
816 | for i in range(self.nplots): | |
817 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
817 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
818 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
818 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) | |
819 | axes = self.axesList[i*self.__nsubplots] |
|
819 | axes = self.axesList[i*self.__nsubplots] | |
820 | axes.pcolor(x, y, zdB[i,:,:], |
|
820 | axes.pcolor(x, y, zdB[i,:,:], | |
821 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
821 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
822 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
822 | xlabel=xlabel, ylabel=ylabel, title=title, | |
823 | ticksize=9, cblabel='') |
|
823 | ticksize=9, cblabel='') | |
824 |
|
824 | |||
825 | if self.__showprofile: |
|
825 | if self.__showprofile: | |
826 | axes = self.axesList[i*self.__nsubplots +1] |
|
826 | axes = self.axesList[i*self.__nsubplots +1] | |
827 | axes.pline(avgdB[i], y, |
|
827 | axes.pline(avgdB[i], y, | |
828 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
828 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
829 | xlabel='dB', ylabel='', title='', |
|
829 | xlabel='dB', ylabel='', title='', | |
830 | ytick_visible=False, |
|
830 | ytick_visible=False, | |
831 | grid='x') |
|
831 | grid='x') | |
832 |
|
832 | |||
833 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
833 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
834 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
834 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
835 |
|
835 | |||
836 | self.draw() |
|
836 | self.draw() | |
837 |
|
837 | |||
838 | if save: |
|
838 | if save: | |
839 |
|
839 | |||
840 | self.counter_imagwr += 1 |
|
840 | self.counter_imagwr += 1 | |
841 | if (self.counter_imagwr==wr_period): |
|
841 | if (self.counter_imagwr==wr_period): | |
842 | if figfile == None: |
|
842 | if figfile == None: | |
843 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
843 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
844 | figfile = self.getFilename(name = str_datetime) |
|
844 | figfile = self.getFilename(name = str_datetime) | |
845 |
|
845 | |||
846 | self.saveFigure(figpath, figfile) |
|
846 | self.saveFigure(figpath, figfile) | |
847 |
|
847 | |||
848 | if ftp: |
|
848 | if ftp: | |
849 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
849 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
850 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
850 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
851 | path = '%s%03d' %(self.PREFIX, self.id) |
|
851 | path = '%s%03d' %(self.PREFIX, self.id) | |
852 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
852 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
853 | self.saveFigure(figpath, ftp_file) |
|
853 | self.saveFigure(figpath, ftp_file) | |
854 | ftp_filename = os.path.join(figpath,ftp_file) |
|
854 | ftp_filename = os.path.join(figpath,ftp_file) | |
855 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
855 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
856 | self.counter_imagwr = 0 |
|
856 | self.counter_imagwr = 0 | |
857 |
|
857 | |||
858 |
|
858 | |||
859 | self.counter_imagwr = 0 |
|
859 | self.counter_imagwr = 0 | |
860 |
|
860 | |||
861 |
|
861 | |||
862 | class Scope(Figure): |
|
862 | class Scope(Figure): | |
863 |
|
863 | |||
864 | __isConfig = None |
|
864 | __isConfig = None | |
865 |
|
865 | |||
866 | def __init__(self): |
|
866 | def __init__(self): | |
867 |
|
867 | |||
868 | self.__isConfig = False |
|
868 | self.__isConfig = False | |
869 |
self.WIDTH = |
|
869 | self.WIDTH = 300 | |
870 | self.HEIGHT = 200 |
|
870 | self.HEIGHT = 200 | |
871 | self.counter_imagwr = 0 |
|
871 | self.counter_imagwr = 0 | |
872 |
|
872 | |||
873 | def getSubplots(self): |
|
873 | def getSubplots(self): | |
874 |
|
874 | |||
875 | nrow = self.nplots |
|
875 | nrow = self.nplots | |
876 | ncol = 3 |
|
876 | ncol = 3 | |
877 | return nrow, ncol |
|
877 | return nrow, ncol | |
878 |
|
878 | |||
879 | def setup(self, id, nplots, wintitle, show): |
|
879 | def setup(self, id, nplots, wintitle, show): | |
880 |
|
880 | |||
881 | self.nplots = nplots |
|
881 | self.nplots = nplots | |
882 |
|
882 | |||
883 | self.createFigure(id=id, |
|
883 | self.createFigure(id=id, | |
884 | wintitle=wintitle, |
|
884 | wintitle=wintitle, | |
885 | show=show) |
|
885 | show=show) | |
886 |
|
886 | |||
887 | nrow,ncol = self.getSubplots() |
|
887 | nrow,ncol = self.getSubplots() | |
888 | colspan = 3 |
|
888 | colspan = 3 | |
889 | rowspan = 1 |
|
889 | rowspan = 1 | |
890 |
|
890 | |||
891 | for i in range(nplots): |
|
891 | for i in range(nplots): | |
892 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
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 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
963 | def run(self, dataOut, id, wintitle="", channelList=None, | |
897 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
964 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
898 | figpath='./', figfile=None, show=True, wr_period=1, |
|
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 | Input: |
|
970 | Input: | |
904 | dataOut : |
|
971 | dataOut : | |
905 | id : |
|
972 | id : | |
906 | wintitle : |
|
973 | wintitle : | |
907 | channelList : |
|
974 | channelList : | |
908 | xmin : None, |
|
975 | xmin : None, | |
909 | xmax : None, |
|
976 | xmax : None, | |
910 | ymin : None, |
|
977 | ymin : None, | |
911 | ymax : None, |
|
978 | ymax : None, | |
912 | """ |
|
979 | """ | |
913 |
|
980 | |||
914 | if channelList == None: |
|
981 | if channelList == None: | |
915 | channelIndexList = dataOut.channelIndexList |
|
982 | channelIndexList = dataOut.channelIndexList | |
916 | else: |
|
983 | else: | |
917 | channelIndexList = [] |
|
984 | channelIndexList = [] | |
918 | for channel in channelList: |
|
985 | for channel in channelList: | |
919 | if channel not in dataOut.channelList: |
|
986 | if channel not in dataOut.channelList: | |
920 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
987 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
921 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
988 | channelIndexList.append(dataOut.channelList.index(channel)) | |
922 |
|
989 | |||
923 | x = dataOut.heightList |
|
990 | x = dataOut.heightList | |
924 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
991 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
925 | y = y.real |
|
992 | y = y.real | |
926 |
|
993 | |||
927 | #thisDatetime = dataOut.datatime |
|
|||
928 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
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: |
|
996 | if type == "power": | |
934 | nplots = len(channelIndexList) |
|
997 | self.plot_power(dataOut.heightList, | |
935 |
|
998 | dataOut.data, | ||
936 | self.setup(id=id, |
|
999 | id, | |
937 |
|
|
1000 | channelIndexList, | |
938 |
|
|
1001 | thisDatetime, | |
939 |
|
|
1002 | wintitle, | |
940 |
|
1003 | show, | ||
941 | if xmin == None: xmin = numpy.nanmin(x) |
|
1004 | xmin, | |
942 | if xmax == None: xmax = numpy.nanmax(x) |
|
1005 | xmax, | |
943 | if ymin == None: ymin = numpy.nanmin(y) |
|
1006 | ymin, | |
944 | if ymax == None: ymax = numpy.nanmax(y) |
|
1007 | ymax) | |
945 |
|
|
1008 | ||
946 | self.__isConfig = True |
|
1009 | if type == "iq": | |
947 |
|
1010 | self.plot_iq(dataOut.heightList, | ||
948 | self.setWinTitle(title) |
|
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 | self.draw() |
|
1023 | self.draw() | |
959 |
|
1024 | |||
960 | if save: |
|
1025 | if save: | |
961 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1026 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
962 | if figfile == None: |
|
1027 | if figfile == None: | |
963 | figfile = self.getFilename(name = date) |
|
1028 | figfile = self.getFilename(name = date) | |
964 |
|
1029 | |||
965 | self.saveFigure(figpath, figfile) |
|
1030 | self.saveFigure(figpath, figfile) | |
966 |
|
1031 | |||
967 | self.counter_imagwr += 1 |
|
1032 | self.counter_imagwr += 1 | |
968 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1033 | if (ftp and (self.counter_imagwr==wr_period)): | |
969 | ftp_filename = os.path.join(figpath,figfile) |
|
1034 | ftp_filename = os.path.join(figpath,figfile) | |
970 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1035 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
971 | self.counter_imagwr = 0 |
|
1036 | self.counter_imagwr = 0 | |
972 |
|
1037 | |||
973 |
class PowerProfile |
|
1038 | class PowerProfile(Figure): | |
974 | __isConfig = None |
|
1039 | __isConfig = None | |
975 | __nsubplots = None |
|
1040 | __nsubplots = None | |
976 |
|
1041 | |||
977 | WIDTHPROF = None |
|
1042 | WIDTHPROF = None | |
978 | HEIGHTPROF = None |
|
1043 | HEIGHTPROF = None | |
979 | PREFIX = 'spcprofile' |
|
1044 | PREFIX = 'spcprofile' | |
980 |
|
1045 | |||
981 | def __init__(self): |
|
1046 | def __init__(self): | |
982 | self.__isConfig = False |
|
1047 | self.__isConfig = False | |
983 | self.__nsubplots = 1 |
|
1048 | self.__nsubplots = 1 | |
984 |
|
1049 | |||
985 | self.WIDTH = 300 |
|
1050 | self.WIDTH = 300 | |
986 | self.HEIGHT = 500 |
|
1051 | self.HEIGHT = 500 | |
987 | self.counter_imagwr = 0 |
|
1052 | self.counter_imagwr = 0 | |
988 |
|
1053 | |||
989 | def getSubplots(self): |
|
1054 | def getSubplots(self): | |
990 | ncol = 1 |
|
1055 | ncol = 1 | |
991 | nrow = 1 |
|
1056 | nrow = 1 | |
992 |
|
1057 | |||
993 | return nrow, ncol |
|
1058 | return nrow, ncol | |
994 |
|
1059 | |||
995 | def setup(self, id, nplots, wintitle, show): |
|
1060 | def setup(self, id, nplots, wintitle, show): | |
996 |
|
1061 | |||
997 | self.nplots = nplots |
|
1062 | self.nplots = nplots | |
998 |
|
1063 | |||
999 | ncolspan = 1 |
|
1064 | ncolspan = 1 | |
1000 | colspan = 1 |
|
1065 | colspan = 1 | |
1001 |
|
1066 | |||
1002 | self.createFigure(id = id, |
|
1067 | self.createFigure(id = id, | |
1003 | wintitle = wintitle, |
|
1068 | wintitle = wintitle, | |
1004 | widthplot = self.WIDTH, |
|
1069 | widthplot = self.WIDTH, | |
1005 | heightplot = self.HEIGHT, |
|
1070 | heightplot = self.HEIGHT, | |
1006 | show=show) |
|
1071 | show=show) | |
1007 |
|
1072 | |||
1008 | nrow, ncol = self.getSubplots() |
|
1073 | nrow, ncol = self.getSubplots() | |
1009 |
|
1074 | |||
1010 | counter = 0 |
|
1075 | counter = 0 | |
1011 | for y in range(nrow): |
|
1076 | for y in range(nrow): | |
1012 | for x in range(ncol): |
|
1077 | for x in range(ncol): | |
1013 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1078 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1014 |
|
1079 | |||
1015 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1080 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1016 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1081 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1017 | save=False, figpath='./', figfile=None, show=True, wr_period=1, |
|
1082 | save=False, figpath='./', figfile=None, show=True, wr_period=1, | |
1018 | server=None, folder=None, username=None, password=None,): |
|
1083 | server=None, folder=None, username=None, password=None,): | |
1019 |
|
1084 | |||
1020 | if channelList == None: |
|
1085 | if channelList == None: | |
1021 | channelIndexList = dataOut.channelIndexList |
|
1086 | channelIndexList = dataOut.channelIndexList | |
1022 | channelList = dataOut.channelList |
|
1087 | channelList = dataOut.channelList | |
1023 | else: |
|
1088 | else: | |
1024 | channelIndexList = [] |
|
1089 | channelIndexList = [] | |
1025 | for channel in channelList: |
|
1090 | for channel in channelList: | |
1026 | if channel not in dataOut.channelList: |
|
1091 | if channel not in dataOut.channelList: | |
1027 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1092 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1028 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1093 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1029 |
|
1094 | |||
1030 | factor = dataOut.normFactor |
|
1095 | try: | |
1031 | y = dataOut.getHeiRange() |
|
1096 | factor = dataOut.normFactor | |
1032 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
1097 | except: | |
1033 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
1098 | factor = 1 | |
1034 | avg = numpy.average(x, axis=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 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1117 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1040 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1118 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1041 | xlabel = "dB" |
|
1119 | xlabel = "dB" | |
1042 | ylabel = "Range (Km)" |
|
1120 | ylabel = "Range (Km)" | |
1043 |
|
1121 | |||
1044 | if not self.__isConfig: |
|
1122 | if not self.__isConfig: | |
1045 |
|
1123 | |||
1046 | nplots = 1 |
|
1124 | nplots = 1 | |
1047 |
|
1125 | |||
1048 | self.setup(id=id, |
|
1126 | self.setup(id=id, | |
1049 | nplots=nplots, |
|
1127 | nplots=nplots, | |
1050 | wintitle=wintitle, |
|
1128 | wintitle=wintitle, | |
1051 | show=show) |
|
1129 | show=show) | |
1052 |
|
1130 | |||
1053 | if ymin == None: ymin = numpy.nanmin(y) |
|
1131 | if ymin == None: ymin = numpy.nanmin(y) | |
1054 | if ymax == None: ymax = numpy.nanmax(y) |
|
1132 | if ymax == None: ymax = numpy.nanmax(y) | |
1055 |
if xmin == None: xmin = numpy.nanmin( |
|
1133 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 | |
1056 |
if xmax == None: xmax = numpy.nanmax( |
|
1134 | if xmax == None: xmax = numpy.nanmax(xdB)*0.9 | |
1057 |
|
1135 | |||
1058 | self.__isConfig = True |
|
1136 | self.__isConfig = True | |
1059 |
|
1137 | |||
1060 | self.setWinTitle(title) |
|
1138 | self.setWinTitle(title) | |
1061 |
|
1139 | |||
1062 |
|
||||
1063 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1140 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1064 | axes = self.axesList[0] |
|
1141 | axes = self.axesList[0] | |
1065 |
|
1142 | |||
1066 | legendlabels = ["channel %d"%x for x in channelList] |
|
1143 | legendlabels = ["channel %d"%x for x in channelList] | |
1067 |
axes.pmultiline( |
|
1144 | axes.pmultiline(xdB, y, | |
1068 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1145 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1069 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
1146 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
1070 | ytick_visible=True, nxticks=5, |
|
1147 | ytick_visible=True, nxticks=5, | |
1071 | grid='x') |
|
1148 | grid='x') | |
1072 |
|
1149 | |||
1073 | self.draw() |
|
1150 | self.draw() | |
1074 |
|
1151 | |||
1075 | if save: |
|
1152 | if save: | |
1076 | date = thisDatetime.strftime("%Y%m%d") |
|
1153 | date = thisDatetime.strftime("%Y%m%d") | |
1077 | if figfile == None: |
|
1154 | if figfile == None: | |
1078 | figfile = self.getFilename(name = date) |
|
1155 | figfile = self.getFilename(name = date) | |
1079 |
|
1156 | |||
1080 | self.saveFigure(figpath, figfile) |
|
1157 | self.saveFigure(figpath, figfile) | |
1081 |
|
1158 | |||
1082 | self.counter_imagwr += 1 |
|
1159 | self.counter_imagwr += 1 | |
1083 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1160 | if (ftp and (self.counter_imagwr==wr_period)): | |
1084 | ftp_filename = os.path.join(figpath,figfile) |
|
1161 | ftp_filename = os.path.join(figpath,figfile) | |
1085 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1162 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1086 | self.counter_imagwr = 0 |
|
1163 | self.counter_imagwr = 0 | |
1087 |
|
1164 | |||
1088 | class CoherenceMap(Figure): |
|
1165 | class CoherenceMap(Figure): | |
1089 | __isConfig = None |
|
1166 | __isConfig = None | |
1090 | __nsubplots = None |
|
1167 | __nsubplots = None | |
1091 |
|
1168 | |||
1092 | WIDTHPROF = None |
|
1169 | WIDTHPROF = None | |
1093 | HEIGHTPROF = None |
|
1170 | HEIGHTPROF = None | |
1094 | PREFIX = 'cmap' |
|
1171 | PREFIX = 'cmap' | |
1095 |
|
1172 | |||
1096 | def __init__(self): |
|
1173 | def __init__(self): | |
1097 | self.timerange = 2*60*60 |
|
1174 | self.timerange = 2*60*60 | |
1098 | self.__isConfig = False |
|
1175 | self.__isConfig = False | |
1099 | self.__nsubplots = 1 |
|
1176 | self.__nsubplots = 1 | |
1100 |
|
1177 | |||
1101 | self.WIDTH = 800 |
|
1178 | self.WIDTH = 800 | |
1102 | self.HEIGHT = 150 |
|
1179 | self.HEIGHT = 150 | |
1103 | self.WIDTHPROF = 120 |
|
1180 | self.WIDTHPROF = 120 | |
1104 | self.HEIGHTPROF = 0 |
|
1181 | self.HEIGHTPROF = 0 | |
1105 | self.counter_imagwr = 0 |
|
1182 | self.counter_imagwr = 0 | |
1106 |
|
1183 | |||
1107 | self.PLOT_CODE = 3 |
|
1184 | self.PLOT_CODE = 3 | |
1108 | self.FTP_WEI = None |
|
1185 | self.FTP_WEI = None | |
1109 | self.EXP_CODE = None |
|
1186 | self.EXP_CODE = None | |
1110 | self.SUB_EXP_CODE = None |
|
1187 | self.SUB_EXP_CODE = None | |
1111 | self.PLOT_POS = None |
|
1188 | self.PLOT_POS = None | |
1112 | self.counter_imagwr = 0 |
|
1189 | self.counter_imagwr = 0 | |
1113 |
|
1190 | |||
1114 | self.xmin = None |
|
1191 | self.xmin = None | |
1115 | self.xmax = None |
|
1192 | self.xmax = None | |
1116 |
|
1193 | |||
1117 | def getSubplots(self): |
|
1194 | def getSubplots(self): | |
1118 | ncol = 1 |
|
1195 | ncol = 1 | |
1119 | nrow = self.nplots*2 |
|
1196 | nrow = self.nplots*2 | |
1120 |
|
1197 | |||
1121 | return nrow, ncol |
|
1198 | return nrow, ncol | |
1122 |
|
1199 | |||
1123 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1200 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1124 | self.__showprofile = showprofile |
|
1201 | self.__showprofile = showprofile | |
1125 | self.nplots = nplots |
|
1202 | self.nplots = nplots | |
1126 |
|
1203 | |||
1127 | ncolspan = 1 |
|
1204 | ncolspan = 1 | |
1128 | colspan = 1 |
|
1205 | colspan = 1 | |
1129 | if showprofile: |
|
1206 | if showprofile: | |
1130 | ncolspan = 7 |
|
1207 | ncolspan = 7 | |
1131 | colspan = 6 |
|
1208 | colspan = 6 | |
1132 | self.__nsubplots = 2 |
|
1209 | self.__nsubplots = 2 | |
1133 |
|
1210 | |||
1134 | self.createFigure(id = id, |
|
1211 | self.createFigure(id = id, | |
1135 | wintitle = wintitle, |
|
1212 | wintitle = wintitle, | |
1136 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1213 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1137 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1214 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1138 | show=True) |
|
1215 | show=True) | |
1139 |
|
1216 | |||
1140 | nrow, ncol = self.getSubplots() |
|
1217 | nrow, ncol = self.getSubplots() | |
1141 |
|
1218 | |||
1142 | for y in range(nrow): |
|
1219 | for y in range(nrow): | |
1143 | for x in range(ncol): |
|
1220 | for x in range(ncol): | |
1144 |
|
1221 | |||
1145 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1222 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1146 |
|
1223 | |||
1147 | if showprofile: |
|
1224 | if showprofile: | |
1148 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1225 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1149 |
|
1226 | |||
1150 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1227 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1151 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1228 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
1152 | timerange=None, |
|
1229 | timerange=None, | |
1153 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, |
|
1230 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
1154 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
1231 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
1155 | server=None, folder=None, username=None, password=None, |
|
1232 | server=None, folder=None, username=None, password=None, | |
1156 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1233 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1157 |
|
1234 | |||
1158 | if pairsList == None: |
|
1235 | if pairsList == None: | |
1159 | pairsIndexList = dataOut.pairsIndexList |
|
1236 | pairsIndexList = dataOut.pairsIndexList | |
1160 | else: |
|
1237 | else: | |
1161 | pairsIndexList = [] |
|
1238 | pairsIndexList = [] | |
1162 | for pair in pairsList: |
|
1239 | for pair in pairsList: | |
1163 | if pair not in dataOut.pairsList: |
|
1240 | if pair not in dataOut.pairsList: | |
1164 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1241 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1165 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1242 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1166 |
|
1243 | |||
1167 | if timerange != None: |
|
1244 | if timerange != None: | |
1168 | self.timerange = timerange |
|
1245 | self.timerange = timerange | |
1169 |
|
1246 | |||
1170 | if pairsIndexList == []: |
|
1247 | if pairsIndexList == []: | |
1171 | return |
|
1248 | return | |
1172 |
|
1249 | |||
1173 | if len(pairsIndexList) > 4: |
|
1250 | if len(pairsIndexList) > 4: | |
1174 | pairsIndexList = pairsIndexList[0:4] |
|
1251 | pairsIndexList = pairsIndexList[0:4] | |
1175 |
|
1252 | |||
1176 | # tmin = None |
|
1253 | # tmin = None | |
1177 | # tmax = None |
|
1254 | # tmax = None | |
1178 | x = dataOut.getTimeRange() |
|
1255 | x = dataOut.getTimeRange() | |
1179 | y = dataOut.getHeiRange() |
|
1256 | y = dataOut.getHeiRange() | |
1180 |
|
1257 | |||
1181 | #thisDatetime = dataOut.datatime |
|
1258 | #thisDatetime = dataOut.datatime | |
1182 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1259 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1183 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1260 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1184 | xlabel = "" |
|
1261 | xlabel = "" | |
1185 | ylabel = "Range (Km)" |
|
1262 | ylabel = "Range (Km)" | |
1186 |
|
1263 | |||
1187 | if not self.__isConfig: |
|
1264 | if not self.__isConfig: | |
1188 | nplots = len(pairsIndexList) |
|
1265 | nplots = len(pairsIndexList) | |
1189 | self.setup(id=id, |
|
1266 | self.setup(id=id, | |
1190 | nplots=nplots, |
|
1267 | nplots=nplots, | |
1191 | wintitle=wintitle, |
|
1268 | wintitle=wintitle, | |
1192 | showprofile=showprofile, |
|
1269 | showprofile=showprofile, | |
1193 | show=show) |
|
1270 | show=show) | |
1194 |
|
1271 | |||
1195 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1272 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1196 |
|
1273 | |||
1197 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1274 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
1198 |
|
1275 | |||
1199 | if ymin == None: ymin = numpy.nanmin(y) |
|
1276 | if ymin == None: ymin = numpy.nanmin(y) | |
1200 | if ymax == None: ymax = numpy.nanmax(y) |
|
1277 | if ymax == None: ymax = numpy.nanmax(y) | |
1201 | if zmin == None: zmin = 0. |
|
1278 | if zmin == None: zmin = 0. | |
1202 | if zmax == None: zmax = 1. |
|
1279 | if zmax == None: zmax = 1. | |
1203 |
|
1280 | |||
1204 | self.FTP_WEI = ftp_wei |
|
1281 | self.FTP_WEI = ftp_wei | |
1205 | self.EXP_CODE = exp_code |
|
1282 | self.EXP_CODE = exp_code | |
1206 | self.SUB_EXP_CODE = sub_exp_code |
|
1283 | self.SUB_EXP_CODE = sub_exp_code | |
1207 | self.PLOT_POS = plot_pos |
|
1284 | self.PLOT_POS = plot_pos | |
1208 |
|
1285 | |||
1209 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1286 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1210 |
|
1287 | |||
1211 | self.__isConfig = True |
|
1288 | self.__isConfig = True | |
1212 |
|
1289 | |||
1213 | self.setWinTitle(title) |
|
1290 | self.setWinTitle(title) | |
1214 |
|
1291 | |||
1215 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1292 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
1216 | x[1] = self.xmax |
|
1293 | x[1] = self.xmax | |
1217 |
|
1294 | |||
1218 | for i in range(self.nplots): |
|
1295 | for i in range(self.nplots): | |
1219 |
|
1296 | |||
1220 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1297 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1221 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
1298 | # coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
1222 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) |
|
1299 | # avgcoherenceComplex = numpy.average(coherenceComplex, axis=0) | |
1223 | # coherence = numpy.abs(avgcoherenceComplex) |
|
1300 | # coherence = numpy.abs(avgcoherenceComplex) | |
1224 |
|
1301 | |||
1225 | ## coherence = numpy.abs(coherenceComplex) |
|
1302 | ## coherence = numpy.abs(coherenceComplex) | |
1226 | ## avg = numpy.average(coherence, axis=0) |
|
1303 | ## avg = numpy.average(coherence, axis=0) | |
1227 |
|
1304 | |||
1228 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1305 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
1229 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1306 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
1230 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1307 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
1231 |
|
1308 | |||
1232 |
|
1309 | |||
1233 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1310 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1234 | coherence = numpy.abs(avgcoherenceComplex) |
|
1311 | coherence = numpy.abs(avgcoherenceComplex) | |
1235 |
|
1312 | |||
1236 | z = coherence.reshape((1,-1)) |
|
1313 | z = coherence.reshape((1,-1)) | |
1237 |
|
1314 | |||
1238 | counter = 0 |
|
1315 | counter = 0 | |
1239 |
|
1316 | |||
1240 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1317 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1241 | axes = self.axesList[i*self.__nsubplots*2] |
|
1318 | axes = self.axesList[i*self.__nsubplots*2] | |
1242 | axes.pcolorbuffer(x, y, z, |
|
1319 | axes.pcolorbuffer(x, y, z, | |
1243 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
1320 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
1244 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1321 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
1245 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
1322 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
1246 |
|
1323 | |||
1247 | if self.__showprofile: |
|
1324 | if self.__showprofile: | |
1248 | counter += 1 |
|
1325 | counter += 1 | |
1249 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1326 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1250 | axes.pline(coherence, y, |
|
1327 | axes.pline(coherence, y, | |
1251 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
1328 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
1252 | xlabel='', ylabel='', title='', ticksize=7, |
|
1329 | xlabel='', ylabel='', title='', ticksize=7, | |
1253 | ytick_visible=False, nxticks=5, |
|
1330 | ytick_visible=False, nxticks=5, | |
1254 | grid='x') |
|
1331 | grid='x') | |
1255 |
|
1332 | |||
1256 | counter += 1 |
|
1333 | counter += 1 | |
1257 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
1334 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
1258 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1335 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1259 | # avg = numpy.average(phase, axis=0) |
|
1336 | # avg = numpy.average(phase, axis=0) | |
1260 | z = phase.reshape((1,-1)) |
|
1337 | z = phase.reshape((1,-1)) | |
1261 |
|
1338 | |||
1262 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1339 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1263 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1340 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1264 | axes.pcolorbuffer(x, y, z, |
|
1341 | axes.pcolorbuffer(x, y, z, | |
1265 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
1342 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
1266 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1343 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
1267 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
1344 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
1268 |
|
1345 | |||
1269 | if self.__showprofile: |
|
1346 | if self.__showprofile: | |
1270 | counter += 1 |
|
1347 | counter += 1 | |
1271 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
1348 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
1272 | axes.pline(phase, y, |
|
1349 | axes.pline(phase, y, | |
1273 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
1350 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
1274 | xlabel='', ylabel='', title='', ticksize=7, |
|
1351 | xlabel='', ylabel='', title='', ticksize=7, | |
1275 | ytick_visible=False, nxticks=4, |
|
1352 | ytick_visible=False, nxticks=4, | |
1276 | grid='x') |
|
1353 | grid='x') | |
1277 |
|
1354 | |||
1278 | self.draw() |
|
1355 | self.draw() | |
1279 |
|
1356 | |||
1280 | if x[1] >= self.axesList[0].xmax: |
|
1357 | if x[1] >= self.axesList[0].xmax: | |
1281 | self.saveFigure(figpath, figfile) |
|
1358 | self.saveFigure(figpath, figfile) | |
1282 | self.__isConfig = False |
|
1359 | self.__isConfig = False | |
1283 |
|
1360 | |||
1284 | # if save: |
|
1361 | # if save: | |
1285 | # |
|
1362 | # | |
1286 | # self.counter_imagwr += 1 |
|
1363 | # self.counter_imagwr += 1 | |
1287 | # if (self.counter_imagwr==wr_period): |
|
1364 | # if (self.counter_imagwr==wr_period): | |
1288 | # if figfile == None: |
|
1365 | # if figfile == None: | |
1289 | # figfile = self.getFilename(name = self.name) |
|
1366 | # figfile = self.getFilename(name = self.name) | |
1290 | # self.saveFigure(figpath, figfile) |
|
1367 | # self.saveFigure(figpath, figfile) | |
1291 | # |
|
1368 | # | |
1292 | # if ftp: |
|
1369 | # if ftp: | |
1293 | # #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1370 | # #provisionalmente envia archivos en el formato de la web en tiempo real | |
1294 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1371 | # name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1295 | # path = '%s%03d' %(self.PREFIX, self.id) |
|
1372 | # path = '%s%03d' %(self.PREFIX, self.id) | |
1296 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1373 | # ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1297 | # self.saveFigure(figpath, ftp_file) |
|
1374 | # self.saveFigure(figpath, ftp_file) | |
1298 | # ftp_filename = os.path.join(figpath,ftp_file) |
|
1375 | # ftp_filename = os.path.join(figpath,ftp_file) | |
1299 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1376 | # self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1300 | # self.counter_imagwr = 0 |
|
1377 | # self.counter_imagwr = 0 | |
1301 | # |
|
1378 | # | |
1302 | # self.counter_imagwr = 0 |
|
1379 | # self.counter_imagwr = 0 | |
1303 | # |
|
1380 | # | |
1304 | # |
|
1381 | # | |
1305 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1382 | # if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1306 | # self.__isConfig = False |
|
1383 | # self.__isConfig = False | |
1307 |
|
1384 | |||
1308 | class BeaconPhase(Figure): |
|
1385 | class BeaconPhase(Figure): | |
1309 |
|
1386 | |||
1310 | __isConfig = None |
|
1387 | __isConfig = None | |
1311 | __nsubplots = None |
|
1388 | __nsubplots = None | |
1312 |
|
1389 | |||
1313 | PREFIX = 'beacon_phase' |
|
1390 | PREFIX = 'beacon_phase' | |
1314 |
|
1391 | |||
1315 | def __init__(self): |
|
1392 | def __init__(self): | |
1316 |
|
1393 | |||
1317 | self.timerange = 24*60*60 |
|
1394 | self.timerange = 24*60*60 | |
1318 | self.__isConfig = False |
|
1395 | self.__isConfig = False | |
1319 | self.__nsubplots = 1 |
|
1396 | self.__nsubplots = 1 | |
1320 | self.counter_imagwr = 0 |
|
1397 | self.counter_imagwr = 0 | |
1321 | self.WIDTH = 600 |
|
1398 | self.WIDTH = 600 | |
1322 | self.HEIGHT = 300 |
|
1399 | self.HEIGHT = 300 | |
1323 | self.WIDTHPROF = 120 |
|
1400 | self.WIDTHPROF = 120 | |
1324 | self.HEIGHTPROF = 0 |
|
1401 | self.HEIGHTPROF = 0 | |
1325 | self.xdata = None |
|
1402 | self.xdata = None | |
1326 | self.ydata = None |
|
1403 | self.ydata = None | |
1327 |
|
1404 | |||
1328 | self.PLOT_CODE = 18 |
|
1405 | self.PLOT_CODE = 18 | |
1329 | self.FTP_WEI = None |
|
1406 | self.FTP_WEI = None | |
1330 | self.EXP_CODE = None |
|
1407 | self.EXP_CODE = None | |
1331 | self.SUB_EXP_CODE = None |
|
1408 | self.SUB_EXP_CODE = None | |
1332 | self.PLOT_POS = None |
|
1409 | self.PLOT_POS = None | |
1333 |
|
1410 | |||
1334 | self.filename_phase = None |
|
1411 | self.filename_phase = None | |
1335 |
|
1412 | |||
1336 | def getSubplots(self): |
|
1413 | def getSubplots(self): | |
1337 |
|
1414 | |||
1338 | ncol = 1 |
|
1415 | ncol = 1 | |
1339 | nrow = 1 |
|
1416 | nrow = 1 | |
1340 |
|
1417 | |||
1341 | return nrow, ncol |
|
1418 | return nrow, ncol | |
1342 |
|
1419 | |||
1343 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1420 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1344 |
|
1421 | |||
1345 | self.__showprofile = showprofile |
|
1422 | self.__showprofile = showprofile | |
1346 | self.nplots = nplots |
|
1423 | self.nplots = nplots | |
1347 |
|
1424 | |||
1348 | ncolspan = 7 |
|
1425 | ncolspan = 7 | |
1349 | colspan = 6 |
|
1426 | colspan = 6 | |
1350 | self.__nsubplots = 2 |
|
1427 | self.__nsubplots = 2 | |
1351 |
|
1428 | |||
1352 | self.createFigure(id = id, |
|
1429 | self.createFigure(id = id, | |
1353 | wintitle = wintitle, |
|
1430 | wintitle = wintitle, | |
1354 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1431 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1355 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1432 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1356 | show=show) |
|
1433 | show=show) | |
1357 |
|
1434 | |||
1358 | nrow, ncol = self.getSubplots() |
|
1435 | nrow, ncol = self.getSubplots() | |
1359 |
|
1436 | |||
1360 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1437 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1361 |
|
1438 | |||
1362 | def save_phase(self, filename_phase): |
|
1439 | def save_phase(self, filename_phase): | |
1363 | f = open(filename_phase,'w+') |
|
1440 | f = open(filename_phase,'w+') | |
1364 | f.write('\n\n') |
|
1441 | f.write('\n\n') | |
1365 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1442 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') | |
1366 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1443 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) | |
1367 | f.close() |
|
1444 | f.close() | |
1368 |
|
1445 | |||
1369 | def save_data(self, filename_phase, data, data_datetime): |
|
1446 | def save_data(self, filename_phase, data, data_datetime): | |
1370 | f=open(filename_phase,'a') |
|
1447 | f=open(filename_phase,'a') | |
1371 | timetuple_data = data_datetime.timetuple() |
|
1448 | timetuple_data = data_datetime.timetuple() | |
1372 | day = str(timetuple_data.tm_mday) |
|
1449 | day = str(timetuple_data.tm_mday) | |
1373 | month = str(timetuple_data.tm_mon) |
|
1450 | month = str(timetuple_data.tm_mon) | |
1374 | year = str(timetuple_data.tm_year) |
|
1451 | year = str(timetuple_data.tm_year) | |
1375 | hour = str(timetuple_data.tm_hour) |
|
1452 | hour = str(timetuple_data.tm_hour) | |
1376 | minute = str(timetuple_data.tm_min) |
|
1453 | minute = str(timetuple_data.tm_min) | |
1377 | second = str(timetuple_data.tm_sec) |
|
1454 | second = str(timetuple_data.tm_sec) | |
1378 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1455 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1379 | f.close() |
|
1456 | f.close() | |
1380 |
|
1457 | |||
1381 |
|
1458 | |||
1382 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1459 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1383 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1460 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1384 | timerange=None, |
|
1461 | timerange=None, | |
1385 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1462 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1386 | server=None, folder=None, username=None, password=None, |
|
1463 | server=None, folder=None, username=None, password=None, | |
1387 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1464 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1388 |
|
1465 | |||
1389 | if pairsList == None: |
|
1466 | if pairsList == None: | |
1390 | pairsIndexList = dataOut.pairsIndexList |
|
1467 | pairsIndexList = dataOut.pairsIndexList | |
1391 | else: |
|
1468 | else: | |
1392 | pairsIndexList = [] |
|
1469 | pairsIndexList = [] | |
1393 | for pair in pairsList: |
|
1470 | for pair in pairsList: | |
1394 | if pair not in dataOut.pairsList: |
|
1471 | if pair not in dataOut.pairsList: | |
1395 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1472 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1396 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1473 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1397 |
|
1474 | |||
1398 | if pairsIndexList == []: |
|
1475 | if pairsIndexList == []: | |
1399 | return |
|
1476 | return | |
1400 |
|
1477 | |||
1401 | # if len(pairsIndexList) > 4: |
|
1478 | # if len(pairsIndexList) > 4: | |
1402 | # pairsIndexList = pairsIndexList[0:4] |
|
1479 | # pairsIndexList = pairsIndexList[0:4] | |
1403 |
|
1480 | |||
1404 | if timerange != None: |
|
1481 | if timerange != None: | |
1405 | self.timerange = timerange |
|
1482 | self.timerange = timerange | |
1406 |
|
1483 | |||
1407 | tmin = None |
|
1484 | tmin = None | |
1408 | tmax = None |
|
1485 | tmax = None | |
1409 | x = dataOut.getTimeRange() |
|
1486 | x = dataOut.getTimeRange() | |
1410 | y = dataOut.getHeiRange() |
|
1487 | y = dataOut.getHeiRange() | |
1411 |
|
1488 | |||
1412 |
|
1489 | |||
1413 | #thisDatetime = dataOut.datatime |
|
1490 | #thisDatetime = dataOut.datatime | |
1414 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1491 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1415 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1492 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1416 | xlabel = "Local Time" |
|
1493 | xlabel = "Local Time" | |
1417 | ylabel = "Phase" |
|
1494 | ylabel = "Phase" | |
1418 |
|
1495 | |||
1419 | nplots = len(pairsIndexList) |
|
1496 | nplots = len(pairsIndexList) | |
1420 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1497 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | |
1421 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1498 | phase_beacon = numpy.zeros(len(pairsIndexList)) | |
1422 | for i in range(nplots): |
|
1499 | for i in range(nplots): | |
1423 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1500 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1424 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1501 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
1425 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1502 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
1426 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1503 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
1427 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1504 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1428 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1505 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1429 |
|
1506 | |||
1430 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1507 | #print "Phase %d%d" %(pair[0], pair[1]) | |
1431 | #print phase[dataOut.beacon_heiIndexList] |
|
1508 | #print phase[dataOut.beacon_heiIndexList] | |
1432 |
|
1509 | |||
1433 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1510 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) | |
1434 |
|
1511 | |||
1435 | if not self.__isConfig: |
|
1512 | if not self.__isConfig: | |
1436 |
|
1513 | |||
1437 | nplots = len(pairsIndexList) |
|
1514 | nplots = len(pairsIndexList) | |
1438 |
|
1515 | |||
1439 | self.setup(id=id, |
|
1516 | self.setup(id=id, | |
1440 | nplots=nplots, |
|
1517 | nplots=nplots, | |
1441 | wintitle=wintitle, |
|
1518 | wintitle=wintitle, | |
1442 | showprofile=showprofile, |
|
1519 | showprofile=showprofile, | |
1443 | show=show) |
|
1520 | show=show) | |
1444 |
|
1521 | |||
1445 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1522 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1446 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1523 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 | |
1447 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1524 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 | |
1448 |
|
1525 | |||
1449 | self.FTP_WEI = ftp_wei |
|
1526 | self.FTP_WEI = ftp_wei | |
1450 | self.EXP_CODE = exp_code |
|
1527 | self.EXP_CODE = exp_code | |
1451 | self.SUB_EXP_CODE = sub_exp_code |
|
1528 | self.SUB_EXP_CODE = sub_exp_code | |
1452 | self.PLOT_POS = plot_pos |
|
1529 | self.PLOT_POS = plot_pos | |
1453 |
|
1530 | |||
1454 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1531 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1455 | self.__isConfig = True |
|
1532 | self.__isConfig = True | |
1456 |
|
1533 | |||
1457 | self.xdata = numpy.array([]) |
|
1534 | self.xdata = numpy.array([]) | |
1458 | self.ydata = numpy.array([]) |
|
1535 | self.ydata = numpy.array([]) | |
1459 |
|
1536 | |||
1460 | #open file beacon phase |
|
1537 | #open file beacon phase | |
1461 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1538 | path = '%s%03d' %(self.PREFIX, self.id) | |
1462 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1539 | beacon_file = os.path.join(path,'%s.txt'%self.name) | |
1463 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1540 | self.filename_phase = os.path.join(figpath,beacon_file) | |
1464 | #self.save_phase(self.filename_phase) |
|
1541 | #self.save_phase(self.filename_phase) | |
1465 |
|
1542 | |||
1466 |
|
1543 | |||
1467 | #store data beacon phase |
|
1544 | #store data beacon phase | |
1468 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1545 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) | |
1469 |
|
1546 | |||
1470 | self.setWinTitle(title) |
|
1547 | self.setWinTitle(title) | |
1471 |
|
1548 | |||
1472 |
|
1549 | |||
1473 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1550 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1474 |
|
1551 | |||
1475 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1552 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] | |
1476 |
|
1553 | |||
1477 | axes = self.axesList[0] |
|
1554 | axes = self.axesList[0] | |
1478 |
|
1555 | |||
1479 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1556 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1480 |
|
1557 | |||
1481 | if len(self.ydata)==0: |
|
1558 | if len(self.ydata)==0: | |
1482 | self.ydata = phase_beacon.reshape(-1,1) |
|
1559 | self.ydata = phase_beacon.reshape(-1,1) | |
1483 | else: |
|
1560 | else: | |
1484 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1561 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | |
1485 |
|
1562 | |||
1486 |
|
1563 | |||
1487 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1564 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1488 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1565 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1489 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1566 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1490 | XAxisAsTime=True, grid='both' |
|
1567 | XAxisAsTime=True, grid='both' | |
1491 | ) |
|
1568 | ) | |
1492 |
|
1569 | |||
1493 | self.draw() |
|
1570 | self.draw() | |
1494 |
|
1571 | |||
1495 | if save: |
|
1572 | if save: | |
1496 |
|
1573 | |||
1497 | self.counter_imagwr += 1 |
|
1574 | self.counter_imagwr += 1 | |
1498 | if (self.counter_imagwr==wr_period): |
|
1575 | if (self.counter_imagwr==wr_period): | |
1499 | if figfile == None: |
|
1576 | if figfile == None: | |
1500 | figfile = self.getFilename(name = self.name) |
|
1577 | figfile = self.getFilename(name = self.name) | |
1501 | self.saveFigure(figpath, figfile) |
|
1578 | self.saveFigure(figpath, figfile) | |
1502 |
|
1579 | |||
1503 | if ftp: |
|
1580 | if ftp: | |
1504 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1581 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
1505 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1582 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1506 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1583 | path = '%s%03d' %(self.PREFIX, self.id) | |
1507 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1584 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1508 | self.saveFigure(figpath, ftp_file) |
|
1585 | self.saveFigure(figpath, ftp_file) | |
1509 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1586 | ftp_filename = os.path.join(figpath,ftp_file) | |
1510 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1587 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1511 |
|
1588 | |||
1512 | self.counter_imagwr = 0 |
|
1589 | self.counter_imagwr = 0 | |
1513 |
|
1590 | |||
1514 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1591 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1515 | self.__isConfig = False |
|
1592 | self.__isConfig = False | |
1516 | del self.xdata |
|
1593 | del self.xdata | |
1517 | del self.ydata |
|
1594 | del self.ydata | |
1518 |
|
1595 | |||
1519 |
|
1596 | |||
1520 |
|
1597 | |||
1521 |
|
1598 | |||
1522 | class Noise(Figure): |
|
1599 | class Noise(Figure): | |
1523 |
|
1600 | |||
1524 | __isConfig = None |
|
1601 | __isConfig = None | |
1525 | __nsubplots = None |
|
1602 | __nsubplots = None | |
1526 |
|
1603 | |||
1527 | PREFIX = 'noise' |
|
1604 | PREFIX = 'noise' | |
1528 |
|
1605 | |||
1529 | def __init__(self): |
|
1606 | def __init__(self): | |
1530 |
|
1607 | |||
1531 | self.timerange = 24*60*60 |
|
1608 | self.timerange = 24*60*60 | |
1532 | self.__isConfig = False |
|
1609 | self.__isConfig = False | |
1533 | self.__nsubplots = 1 |
|
1610 | self.__nsubplots = 1 | |
1534 | self.counter_imagwr = 0 |
|
1611 | self.counter_imagwr = 0 | |
1535 | self.WIDTH = 600 |
|
1612 | self.WIDTH = 600 | |
1536 | self.HEIGHT = 300 |
|
1613 | self.HEIGHT = 300 | |
1537 | self.WIDTHPROF = 120 |
|
1614 | self.WIDTHPROF = 120 | |
1538 | self.HEIGHTPROF = 0 |
|
1615 | self.HEIGHTPROF = 0 | |
1539 | self.xdata = None |
|
1616 | self.xdata = None | |
1540 | self.ydata = None |
|
1617 | self.ydata = None | |
1541 |
|
1618 | |||
1542 | self.PLOT_CODE = 77 |
|
1619 | self.PLOT_CODE = 77 | |
1543 | self.FTP_WEI = None |
|
1620 | self.FTP_WEI = None | |
1544 | self.EXP_CODE = None |
|
1621 | self.EXP_CODE = None | |
1545 | self.SUB_EXP_CODE = None |
|
1622 | self.SUB_EXP_CODE = None | |
1546 | self.PLOT_POS = None |
|
1623 | self.PLOT_POS = None | |
1547 |
|
1624 | |||
1548 | def getSubplots(self): |
|
1625 | def getSubplots(self): | |
1549 |
|
1626 | |||
1550 | ncol = 1 |
|
1627 | ncol = 1 | |
1551 | nrow = 1 |
|
1628 | nrow = 1 | |
1552 |
|
1629 | |||
1553 | return nrow, ncol |
|
1630 | return nrow, ncol | |
1554 |
|
1631 | |||
1555 | def openfile(self, filename): |
|
1632 | def openfile(self, filename): | |
1556 | f = open(filename,'w+') |
|
1633 | f = open(filename,'w+') | |
1557 | f.write('\n\n') |
|
1634 | f.write('\n\n') | |
1558 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
1635 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') | |
1559 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
1636 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) | |
1560 | f.close() |
|
1637 | f.close() | |
1561 |
|
1638 | |||
1562 | def save_data(self, filename_phase, data, data_datetime): |
|
1639 | def save_data(self, filename_phase, data, data_datetime): | |
1563 | f=open(filename_phase,'a') |
|
1640 | f=open(filename_phase,'a') | |
1564 | timetuple_data = data_datetime.timetuple() |
|
1641 | timetuple_data = data_datetime.timetuple() | |
1565 | day = str(timetuple_data.tm_mday) |
|
1642 | day = str(timetuple_data.tm_mday) | |
1566 | month = str(timetuple_data.tm_mon) |
|
1643 | month = str(timetuple_data.tm_mon) | |
1567 | year = str(timetuple_data.tm_year) |
|
1644 | year = str(timetuple_data.tm_year) | |
1568 | hour = str(timetuple_data.tm_hour) |
|
1645 | hour = str(timetuple_data.tm_hour) | |
1569 | minute = str(timetuple_data.tm_min) |
|
1646 | minute = str(timetuple_data.tm_min) | |
1570 | second = str(timetuple_data.tm_sec) |
|
1647 | second = str(timetuple_data.tm_sec) | |
1571 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1648 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1572 | f.close() |
|
1649 | f.close() | |
1573 |
|
1650 | |||
1574 |
|
1651 | |||
1575 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1652 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1576 |
|
1653 | |||
1577 | self.__showprofile = showprofile |
|
1654 | self.__showprofile = showprofile | |
1578 | self.nplots = nplots |
|
1655 | self.nplots = nplots | |
1579 |
|
1656 | |||
1580 | ncolspan = 7 |
|
1657 | ncolspan = 7 | |
1581 | colspan = 6 |
|
1658 | colspan = 6 | |
1582 | self.__nsubplots = 2 |
|
1659 | self.__nsubplots = 2 | |
1583 |
|
1660 | |||
1584 | self.createFigure(id = id, |
|
1661 | self.createFigure(id = id, | |
1585 | wintitle = wintitle, |
|
1662 | wintitle = wintitle, | |
1586 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1663 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1587 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1664 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1588 | show=show) |
|
1665 | show=show) | |
1589 |
|
1666 | |||
1590 | nrow, ncol = self.getSubplots() |
|
1667 | nrow, ncol = self.getSubplots() | |
1591 |
|
1668 | |||
1592 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1669 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1593 |
|
1670 | |||
1594 |
|
1671 | |||
1595 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1672 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1596 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1673 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1597 | timerange=None, |
|
1674 | timerange=None, | |
1598 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
1675 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
1599 | server=None, folder=None, username=None, password=None, |
|
1676 | server=None, folder=None, username=None, password=None, | |
1600 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1677 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1601 |
|
1678 | |||
1602 | if channelList == None: |
|
1679 | if channelList == None: | |
1603 | channelIndexList = dataOut.channelIndexList |
|
1680 | channelIndexList = dataOut.channelIndexList | |
1604 | channelList = dataOut.channelList |
|
1681 | channelList = dataOut.channelList | |
1605 | else: |
|
1682 | else: | |
1606 | channelIndexList = [] |
|
1683 | channelIndexList = [] | |
1607 | for channel in channelList: |
|
1684 | for channel in channelList: | |
1608 | if channel not in dataOut.channelList: |
|
1685 | if channel not in dataOut.channelList: | |
1609 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1686 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1610 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1687 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1611 |
|
1688 | |||
1612 | if timerange != None: |
|
1689 | if timerange != None: | |
1613 | self.timerange = timerange |
|
1690 | self.timerange = timerange | |
1614 |
|
1691 | |||
1615 | tmin = None |
|
1692 | tmin = None | |
1616 | tmax = None |
|
1693 | tmax = None | |
1617 | x = dataOut.getTimeRange() |
|
1694 | x = dataOut.getTimeRange() | |
1618 | y = dataOut.getHeiRange() |
|
1695 | y = dataOut.getHeiRange() | |
1619 | factor = dataOut.normFactor |
|
1696 | factor = dataOut.normFactor | |
1620 | noise = dataOut.getNoise()/factor |
|
1697 | noise = dataOut.getNoise()/factor | |
1621 | noisedB = 10*numpy.log10(noise) |
|
1698 | noisedB = 10*numpy.log10(noise) | |
1622 |
|
1699 | |||
1623 | #thisDatetime = dataOut.datatime |
|
1700 | #thisDatetime = dataOut.datatime | |
1624 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1701 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1625 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1702 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1626 | xlabel = "" |
|
1703 | xlabel = "" | |
1627 | ylabel = "Intensity (dB)" |
|
1704 | ylabel = "Intensity (dB)" | |
1628 |
|
1705 | |||
1629 | if not self.__isConfig: |
|
1706 | if not self.__isConfig: | |
1630 |
|
1707 | |||
1631 | nplots = 1 |
|
1708 | nplots = 1 | |
1632 |
|
1709 | |||
1633 | self.setup(id=id, |
|
1710 | self.setup(id=id, | |
1634 | nplots=nplots, |
|
1711 | nplots=nplots, | |
1635 | wintitle=wintitle, |
|
1712 | wintitle=wintitle, | |
1636 | showprofile=showprofile, |
|
1713 | showprofile=showprofile, | |
1637 | show=show) |
|
1714 | show=show) | |
1638 |
|
1715 | |||
1639 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1716 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1640 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 |
|
1717 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 | |
1641 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1718 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 | |
1642 |
|
1719 | |||
1643 | self.FTP_WEI = ftp_wei |
|
1720 | self.FTP_WEI = ftp_wei | |
1644 | self.EXP_CODE = exp_code |
|
1721 | self.EXP_CODE = exp_code | |
1645 | self.SUB_EXP_CODE = sub_exp_code |
|
1722 | self.SUB_EXP_CODE = sub_exp_code | |
1646 | self.PLOT_POS = plot_pos |
|
1723 | self.PLOT_POS = plot_pos | |
1647 |
|
1724 | |||
1648 |
|
1725 | |||
1649 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1726 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1650 | self.__isConfig = True |
|
1727 | self.__isConfig = True | |
1651 |
|
1728 | |||
1652 | self.xdata = numpy.array([]) |
|
1729 | self.xdata = numpy.array([]) | |
1653 | self.ydata = numpy.array([]) |
|
1730 | self.ydata = numpy.array([]) | |
1654 |
|
1731 | |||
1655 | #open file beacon phase |
|
1732 | #open file beacon phase | |
1656 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1733 | path = '%s%03d' %(self.PREFIX, self.id) | |
1657 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1734 | noise_file = os.path.join(path,'%s.txt'%self.name) | |
1658 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1735 | self.filename_noise = os.path.join(figpath,noise_file) | |
1659 | self.openfile(self.filename_noise) |
|
1736 | self.openfile(self.filename_noise) | |
1660 |
|
1737 | |||
1661 |
|
1738 | |||
1662 | #store data beacon phase |
|
1739 | #store data beacon phase | |
1663 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1740 | self.save_data(self.filename_noise, noisedB, thisDatetime) | |
1664 |
|
1741 | |||
1665 |
|
1742 | |||
1666 | self.setWinTitle(title) |
|
1743 | self.setWinTitle(title) | |
1667 |
|
1744 | |||
1668 |
|
1745 | |||
1669 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1746 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1670 |
|
1747 | |||
1671 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1748 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] | |
1672 | axes = self.axesList[0] |
|
1749 | axes = self.axesList[0] | |
1673 |
|
1750 | |||
1674 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1751 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1675 |
|
1752 | |||
1676 | if len(self.ydata)==0: |
|
1753 | if len(self.ydata)==0: | |
1677 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1754 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1678 | else: |
|
1755 | else: | |
1679 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1756 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1680 |
|
1757 | |||
1681 |
|
1758 | |||
1682 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1759 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1683 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1760 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1684 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1761 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1685 | XAxisAsTime=True, grid='both' |
|
1762 | XAxisAsTime=True, grid='both' | |
1686 | ) |
|
1763 | ) | |
1687 |
|
1764 | |||
1688 | self.draw() |
|
1765 | self.draw() | |
1689 |
|
1766 | |||
1690 | # if save: |
|
1767 | # if save: | |
1691 | # |
|
1768 | # | |
1692 | # if figfile == None: |
|
1769 | # if figfile == None: | |
1693 | # figfile = self.getFilename(name = self.name) |
|
1770 | # figfile = self.getFilename(name = self.name) | |
1694 | # |
|
1771 | # | |
1695 | # self.saveFigure(figpath, figfile) |
|
1772 | # self.saveFigure(figpath, figfile) | |
1696 |
|
1773 | |||
1697 | if save: |
|
1774 | if save: | |
1698 |
|
1775 | |||
1699 | self.counter_imagwr += 1 |
|
1776 | self.counter_imagwr += 1 | |
1700 | if (self.counter_imagwr==wr_period): |
|
1777 | if (self.counter_imagwr==wr_period): | |
1701 | if figfile == None: |
|
1778 | if figfile == None: | |
1702 | figfile = self.getFilename(name = self.name) |
|
1779 | figfile = self.getFilename(name = self.name) | |
1703 | self.saveFigure(figpath, figfile) |
|
1780 | self.saveFigure(figpath, figfile) | |
1704 |
|
1781 | |||
1705 | if ftp: |
|
1782 | if ftp: | |
1706 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
1783 | #provisionalmente envia archivos en el formato de la web en tiempo real | |
1707 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1784 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1708 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1785 | path = '%s%03d' %(self.PREFIX, self.id) | |
1709 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
1786 | ftp_file = os.path.join(path,'ftp','%s.png'%name) | |
1710 | self.saveFigure(figpath, ftp_file) |
|
1787 | self.saveFigure(figpath, ftp_file) | |
1711 | ftp_filename = os.path.join(figpath,ftp_file) |
|
1788 | ftp_filename = os.path.join(figpath,ftp_file) | |
1712 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1789 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1713 | self.counter_imagwr = 0 |
|
1790 | self.counter_imagwr = 0 | |
1714 |
|
1791 | |||
1715 | self.counter_imagwr = 0 |
|
1792 | self.counter_imagwr = 0 | |
1716 |
|
1793 | |||
1717 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
1794 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
1718 | self.__isConfig = False |
|
1795 | self.__isConfig = False | |
1719 | del self.xdata |
|
1796 | del self.xdata | |
1720 | del self.ydata |
|
1797 | del self.ydata | |
1721 |
|
1798 | |||
1722 |
|
1799 | |||
1723 | class SpectraHeisScope(Figure): |
|
1800 | class SpectraHeisScope(Figure): | |
1724 |
|
1801 | |||
1725 |
|
1802 | |||
1726 | __isConfig = None |
|
1803 | __isConfig = None | |
1727 | __nsubplots = None |
|
1804 | __nsubplots = None | |
1728 |
|
1805 | |||
1729 | WIDTHPROF = None |
|
1806 | WIDTHPROF = None | |
1730 | HEIGHTPROF = None |
|
1807 | HEIGHTPROF = None | |
1731 | PREFIX = 'spc' |
|
1808 | PREFIX = 'spc' | |
1732 |
|
1809 | |||
1733 | def __init__(self): |
|
1810 | def __init__(self): | |
1734 |
|
1811 | |||
1735 | self.__isConfig = False |
|
1812 | self.__isConfig = False | |
1736 | self.__nsubplots = 1 |
|
1813 | self.__nsubplots = 1 | |
1737 |
|
1814 | |||
1738 | self.WIDTH = 230 |
|
1815 | self.WIDTH = 230 | |
1739 | self.HEIGHT = 250 |
|
1816 | self.HEIGHT = 250 | |
1740 | self.WIDTHPROF = 120 |
|
1817 | self.WIDTHPROF = 120 | |
1741 | self.HEIGHTPROF = 0 |
|
1818 | self.HEIGHTPROF = 0 | |
1742 | self.counter_imagwr = 0 |
|
1819 | self.counter_imagwr = 0 | |
1743 |
|
1820 | |||
1744 | def getSubplots(self): |
|
1821 | def getSubplots(self): | |
1745 |
|
1822 | |||
1746 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
1823 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
1747 | nrow = int(self.nplots*1./ncol + 0.9) |
|
1824 | nrow = int(self.nplots*1./ncol + 0.9) | |
1748 |
|
1825 | |||
1749 | return nrow, ncol |
|
1826 | return nrow, ncol | |
1750 |
|
1827 | |||
1751 | def setup(self, id, nplots, wintitle, show): |
|
1828 | def setup(self, id, nplots, wintitle, show): | |
1752 |
|
1829 | |||
1753 | showprofile = False |
|
1830 | showprofile = False | |
1754 | self.__showprofile = showprofile |
|
1831 | self.__showprofile = showprofile | |
1755 | self.nplots = nplots |
|
1832 | self.nplots = nplots | |
1756 |
|
1833 | |||
1757 | ncolspan = 1 |
|
1834 | ncolspan = 1 | |
1758 | colspan = 1 |
|
1835 | colspan = 1 | |
1759 | if showprofile: |
|
1836 | if showprofile: | |
1760 | ncolspan = 3 |
|
1837 | ncolspan = 3 | |
1761 | colspan = 2 |
|
1838 | colspan = 2 | |
1762 | self.__nsubplots = 2 |
|
1839 | self.__nsubplots = 2 | |
1763 |
|
1840 | |||
1764 | self.createFigure(id = id, |
|
1841 | self.createFigure(id = id, | |
1765 | wintitle = wintitle, |
|
1842 | wintitle = wintitle, | |
1766 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1843 | widthplot = self.WIDTH + self.WIDTHPROF, | |
1767 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1844 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
1768 | show = show) |
|
1845 | show = show) | |
1769 |
|
1846 | |||
1770 | nrow, ncol = self.getSubplots() |
|
1847 | nrow, ncol = self.getSubplots() | |
1771 |
|
1848 | |||
1772 | counter = 0 |
|
1849 | counter = 0 | |
1773 | for y in range(nrow): |
|
1850 | for y in range(nrow): | |
1774 | for x in range(ncol): |
|
1851 | for x in range(ncol): | |
1775 |
|
1852 | |||
1776 | if counter >= self.nplots: |
|
1853 | if counter >= self.nplots: | |
1777 | break |
|
1854 | break | |
1778 |
|
1855 | |||
1779 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
1856 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
1780 |
|
1857 | |||
1781 | if showprofile: |
|
1858 | if showprofile: | |
1782 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
1859 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
1783 |
|
1860 | |||
1784 | counter += 1 |
|
1861 | counter += 1 | |
1785 |
|
1862 | |||
1786 |
|
1863 | |||
1787 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1864 | def run(self, dataOut, id, wintitle="", channelList=None, | |
1788 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
1865 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, | |
1789 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
1866 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, | |
1790 | server=None, folder=None, username=None, password=None): |
|
1867 | server=None, folder=None, username=None, password=None): | |
1791 |
|
1868 | |||
1792 | """ |
|
1869 | """ | |
1793 |
|
1870 | |||
1794 | Input: |
|
1871 | Input: | |
1795 | dataOut : |
|
1872 | dataOut : | |
1796 | id : |
|
1873 | id : | |
1797 | wintitle : |
|
1874 | wintitle : | |
1798 | channelList : |
|
1875 | channelList : | |
1799 | xmin : None, |
|
1876 | xmin : None, | |
1800 | xmax : None, |
|
1877 | xmax : None, | |
1801 | ymin : None, |
|
1878 | ymin : None, | |
1802 | ymax : None, |
|
1879 | ymax : None, | |
1803 | """ |
|
1880 | """ | |
1804 |
|
1881 | |||
1805 | if dataOut.realtime: |
|
1882 | if dataOut.realtime: | |
1806 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
1883 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
1807 | print 'Skipping this plot function' |
|
1884 | print 'Skipping this plot function' | |
1808 | return |
|
1885 | return | |
1809 |
|
1886 | |||
1810 | if channelList == None: |
|
1887 | if channelList == None: | |
1811 | channelIndexList = dataOut.channelIndexList |
|
1888 | channelIndexList = dataOut.channelIndexList | |
1812 | else: |
|
1889 | else: | |
1813 | channelIndexList = [] |
|
1890 | channelIndexList = [] | |
1814 | for channel in channelList: |
|
1891 | for channel in channelList: | |
1815 | if channel not in dataOut.channelList: |
|
1892 | if channel not in dataOut.channelList: | |
1816 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1893 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1817 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1894 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1818 |
|
1895 | |||
1819 | # x = dataOut.heightList |
|
1896 | # x = dataOut.heightList | |
1820 | c = 3E8 |
|
1897 | c = 3E8 | |
1821 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1898 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1822 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
1899 | #deberia cambiar para el caso de 1Mhz y 100KHz | |
1823 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
1900 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) | |
1824 | #para 1Mhz descomentar la siguiente linea |
|
1901 | #para 1Mhz descomentar la siguiente linea | |
1825 | #x= x/(10000.0) |
|
1902 | #x= x/(10000.0) | |
1826 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
1903 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
1827 | # y = y.real |
|
1904 | # y = y.real | |
1828 | datadB = 10.*numpy.log10(dataOut.data_spc) |
|
1905 | datadB = 10.*numpy.log10(dataOut.data_spc) | |
1829 | y = datadB |
|
1906 | y = datadB | |
1830 |
|
1907 | |||
1831 | #thisDatetime = dataOut.datatime |
|
1908 | #thisDatetime = dataOut.datatime | |
1832 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1909 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1833 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
1910 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1834 | xlabel = "" |
|
1911 | xlabel = "" | |
1835 | #para 1Mhz descomentar la siguiente linea |
|
1912 | #para 1Mhz descomentar la siguiente linea | |
1836 | #xlabel = "Frequency x 10000" |
|
1913 | #xlabel = "Frequency x 10000" | |
1837 | ylabel = "Intensity (dB)" |
|
1914 | ylabel = "Intensity (dB)" | |
1838 |
|
1915 | |||
1839 | if not self.__isConfig: |
|
1916 | if not self.__isConfig: | |
1840 | nplots = len(channelIndexList) |
|
1917 | nplots = len(channelIndexList) | |
1841 |
|
1918 | |||
1842 | self.setup(id=id, |
|
1919 | self.setup(id=id, | |
1843 | nplots=nplots, |
|
1920 | nplots=nplots, | |
1844 | wintitle=wintitle, |
|
1921 | wintitle=wintitle, | |
1845 | show=show) |
|
1922 | show=show) | |
1846 |
|
1923 | |||
1847 | if xmin == None: xmin = numpy.nanmin(x) |
|
1924 | if xmin == None: xmin = numpy.nanmin(x) | |
1848 | if xmax == None: xmax = numpy.nanmax(x) |
|
1925 | if xmax == None: xmax = numpy.nanmax(x) | |
1849 | if ymin == None: ymin = numpy.nanmin(y) |
|
1926 | if ymin == None: ymin = numpy.nanmin(y) | |
1850 | if ymax == None: ymax = numpy.nanmax(y) |
|
1927 | if ymax == None: ymax = numpy.nanmax(y) | |
1851 |
|
1928 | |||
1852 | self.__isConfig = True |
|
1929 | self.__isConfig = True | |
1853 |
|
1930 | |||
1854 | self.setWinTitle(title) |
|
1931 | self.setWinTitle(title) | |
1855 |
|
1932 | |||
1856 | for i in range(len(self.axesList)): |
|
1933 | for i in range(len(self.axesList)): | |
1857 | ychannel = y[i,:] |
|
1934 | ychannel = y[i,:] | |
1858 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
1935 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
1859 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) |
|
1936 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) | |
1860 | axes = self.axesList[i] |
|
1937 | axes = self.axesList[i] | |
1861 | axes.pline(x, ychannel, |
|
1938 | axes.pline(x, ychannel, | |
1862 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
1939 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
1863 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
1940 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') | |
1864 |
|
1941 | |||
1865 |
|
1942 | |||
1866 | self.draw() |
|
1943 | self.draw() | |
1867 |
|
1944 | |||
1868 | if save: |
|
1945 | if save: | |
1869 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1946 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1870 | if figfile == None: |
|
1947 | if figfile == None: | |
1871 | figfile = self.getFilename(name = date) |
|
1948 | figfile = self.getFilename(name = date) | |
1872 |
|
1949 | |||
1873 | self.saveFigure(figpath, figfile) |
|
1950 | self.saveFigure(figpath, figfile) | |
1874 |
|
1951 | |||
1875 | self.counter_imagwr += 1 |
|
1952 | self.counter_imagwr += 1 | |
1876 | if (ftp and (self.counter_imagwr==wr_period)): |
|
1953 | if (ftp and (self.counter_imagwr==wr_period)): | |
1877 | ftp_filename = os.path.join(figpath,figfile) |
|
1954 | ftp_filename = os.path.join(figpath,figfile) | |
1878 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
1955 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
1879 | self.counter_imagwr = 0 |
|
1956 | self.counter_imagwr = 0 | |
1880 |
|
1957 | |||
1881 |
|
1958 | |||
1882 | class RTIfromSpectraHeis(Figure): |
|
1959 | class RTIfromSpectraHeis(Figure): | |
1883 |
|
1960 | |||
1884 | __isConfig = None |
|
1961 | __isConfig = None | |
1885 | __nsubplots = None |
|
1962 | __nsubplots = None | |
1886 |
|
1963 | |||
1887 | PREFIX = 'rtinoise' |
|
1964 | PREFIX = 'rtinoise' | |
1888 |
|
1965 | |||
1889 | def __init__(self): |
|
1966 | def __init__(self): | |
1890 |
|
1967 | |||
1891 | self.timerange = 24*60*60 |
|
1968 | self.timerange = 24*60*60 | |
1892 | self.__isConfig = False |
|
1969 | self.__isConfig = False | |
1893 | self.__nsubplots = 1 |
|
1970 | self.__nsubplots = 1 | |
1894 |
|
1971 | |||
1895 | self.WIDTH = 820 |
|
1972 | self.WIDTH = 820 | |
1896 | self.HEIGHT = 200 |
|
1973 | self.HEIGHT = 200 | |
1897 | self.WIDTHPROF = 120 |
|
1974 | self.WIDTHPROF = 120 | |
1898 | self.HEIGHTPROF = 0 |
|
1975 | self.HEIGHTPROF = 0 | |
1899 | self.counter_imagwr = 0 |
|
1976 | self.counter_imagwr = 0 | |
1900 | self.xdata = None |
|
1977 | self.xdata = None | |
1901 | self.ydata = None |
|
1978 | self.ydata = None | |
1902 |
|
1979 | |||
1903 | def getSubplots(self): |
|
1980 | def getSubplots(self): | |
1904 |
|
1981 | |||
1905 | ncol = 1 |
|
1982 | ncol = 1 | |
1906 | nrow = 1 |
|
1983 | nrow = 1 | |
1907 |
|
1984 | |||
1908 | return nrow, ncol |
|
1985 | return nrow, ncol | |
1909 |
|
1986 | |||
1910 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1987 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1911 |
|
1988 | |||
1912 | self.__showprofile = showprofile |
|
1989 | self.__showprofile = showprofile | |
1913 | self.nplots = nplots |
|
1990 | self.nplots = nplots | |
1914 |
|
1991 | |||
1915 | ncolspan = 7 |
|
1992 | ncolspan = 7 | |
1916 | colspan = 6 |
|
1993 | colspan = 6 | |
1917 | self.__nsubplots = 2 |
|
1994 | self.__nsubplots = 2 | |
1918 |
|
1995 | |||
1919 | self.createFigure(id = id, |
|
1996 | self.createFigure(id = id, | |
1920 | wintitle = wintitle, |
|
1997 | wintitle = wintitle, | |
1921 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1998 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1922 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1999 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1923 | show = show) |
|
2000 | show = show) | |
1924 |
|
2001 | |||
1925 | nrow, ncol = self.getSubplots() |
|
2002 | nrow, ncol = self.getSubplots() | |
1926 |
|
2003 | |||
1927 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
2004 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1928 |
|
2005 | |||
1929 |
|
2006 | |||
1930 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
2007 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1931 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
2008 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1932 | timerange=None, |
|
2009 | timerange=None, | |
1933 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
2010 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, | |
1934 | server=None, folder=None, username=None, password=None): |
|
2011 | server=None, folder=None, username=None, password=None): | |
1935 |
|
2012 | |||
1936 | if channelList == None: |
|
2013 | if channelList == None: | |
1937 | channelIndexList = dataOut.channelIndexList |
|
2014 | channelIndexList = dataOut.channelIndexList | |
1938 | channelList = dataOut.channelList |
|
2015 | channelList = dataOut.channelList | |
1939 | else: |
|
2016 | else: | |
1940 | channelIndexList = [] |
|
2017 | channelIndexList = [] | |
1941 | for channel in channelList: |
|
2018 | for channel in channelList: | |
1942 | if channel not in dataOut.channelList: |
|
2019 | if channel not in dataOut.channelList: | |
1943 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
2020 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1944 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
2021 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1945 |
|
2022 | |||
1946 | if timerange != None: |
|
2023 | if timerange != None: | |
1947 | self.timerange = timerange |
|
2024 | self.timerange = timerange | |
1948 |
|
2025 | |||
1949 | tmin = None |
|
2026 | tmin = None | |
1950 | tmax = None |
|
2027 | tmax = None | |
1951 | x = dataOut.getTimeRange() |
|
2028 | x = dataOut.getTimeRange() | |
1952 | y = dataOut.getHeiRange() |
|
2029 | y = dataOut.getHeiRange() | |
1953 |
|
2030 | |||
1954 | #factor = 1 |
|
2031 | #factor = 1 | |
1955 | data = dataOut.data_spc#/factor |
|
2032 | data = dataOut.data_spc#/factor | |
1956 | data = numpy.average(data,axis=1) |
|
2033 | data = numpy.average(data,axis=1) | |
1957 | datadB = 10*numpy.log10(data) |
|
2034 | datadB = 10*numpy.log10(data) | |
1958 |
|
2035 | |||
1959 | # factor = dataOut.normFactor |
|
2036 | # factor = dataOut.normFactor | |
1960 | # noise = dataOut.getNoise()/factor |
|
2037 | # noise = dataOut.getNoise()/factor | |
1961 | # noisedB = 10*numpy.log10(noise) |
|
2038 | # noisedB = 10*numpy.log10(noise) | |
1962 |
|
2039 | |||
1963 | #thisDatetime = dataOut.datatime |
|
2040 | #thisDatetime = dataOut.datatime | |
1964 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
2041 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1965 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
2042 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1966 | xlabel = "Local Time" |
|
2043 | xlabel = "Local Time" | |
1967 | ylabel = "Intensity (dB)" |
|
2044 | ylabel = "Intensity (dB)" | |
1968 |
|
2045 | |||
1969 | if not self.__isConfig: |
|
2046 | if not self.__isConfig: | |
1970 |
|
2047 | |||
1971 | nplots = 1 |
|
2048 | nplots = 1 | |
1972 |
|
2049 | |||
1973 | self.setup(id=id, |
|
2050 | self.setup(id=id, | |
1974 | nplots=nplots, |
|
2051 | nplots=nplots, | |
1975 | wintitle=wintitle, |
|
2052 | wintitle=wintitle, | |
1976 | showprofile=showprofile, |
|
2053 | showprofile=showprofile, | |
1977 | show=show) |
|
2054 | show=show) | |
1978 |
|
2055 | |||
1979 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
2056 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1980 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
2057 | if ymin == None: ymin = numpy.nanmin(datadB) | |
1981 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
2058 | if ymax == None: ymax = numpy.nanmax(datadB) | |
1982 |
|
2059 | |||
1983 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
2060 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1984 | self.__isConfig = True |
|
2061 | self.__isConfig = True | |
1985 |
|
2062 | |||
1986 | self.xdata = numpy.array([]) |
|
2063 | self.xdata = numpy.array([]) | |
1987 | self.ydata = numpy.array([]) |
|
2064 | self.ydata = numpy.array([]) | |
1988 |
|
2065 | |||
1989 | self.setWinTitle(title) |
|
2066 | self.setWinTitle(title) | |
1990 |
|
2067 | |||
1991 |
|
2068 | |||
1992 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
2069 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1993 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
2070 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
1994 |
|
2071 | |||
1995 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
2072 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] | |
1996 | axes = self.axesList[0] |
|
2073 | axes = self.axesList[0] | |
1997 |
|
2074 | |||
1998 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
2075 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1999 |
|
2076 | |||
2000 | if len(self.ydata)==0: |
|
2077 | if len(self.ydata)==0: | |
2001 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
2078 | self.ydata = datadB[channelIndexList].reshape(-1,1) | |
2002 | else: |
|
2079 | else: | |
2003 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
2080 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) | |
2004 |
|
2081 | |||
2005 |
|
2082 | |||
2006 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
2083 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
2007 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
2084 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
2008 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
2085 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', | |
2009 | XAxisAsTime=True |
|
2086 | XAxisAsTime=True | |
2010 | ) |
|
2087 | ) | |
2011 |
|
2088 | |||
2012 | self.draw() |
|
2089 | self.draw() | |
2013 |
|
2090 | |||
2014 | if save: |
|
2091 | if save: | |
2015 |
|
2092 | |||
2016 | if figfile == None: |
|
2093 | if figfile == None: | |
2017 | figfile = self.getFilename(name = self.name) |
|
2094 | figfile = self.getFilename(name = self.name) | |
2018 |
|
2095 | |||
2019 | self.saveFigure(figpath, figfile) |
|
2096 | self.saveFigure(figpath, figfile) | |
2020 |
|
2097 | |||
2021 | self.counter_imagwr += 1 |
|
2098 | self.counter_imagwr += 1 | |
2022 | if (ftp and (self.counter_imagwr==wr_period)): |
|
2099 | if (ftp and (self.counter_imagwr==wr_period)): | |
2023 | ftp_filename = os.path.join(figpath,figfile) |
|
2100 | ftp_filename = os.path.join(figpath,figfile) | |
2024 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
2101 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) | |
2025 | self.counter_imagwr = 0 |
|
2102 | self.counter_imagwr = 0 | |
2026 |
|
2103 | |||
2027 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
2104 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
2028 | self.__isConfig = False |
|
2105 | self.__isConfig = False | |
2029 | del self.xdata |
|
2106 | del self.xdata | |
2030 | del self.ydata |
|
2107 | del self.ydata | |
2031 |
|
2108 | |||
2032 |
|
2109 | |||
2033 | No newline at end of file |
|
2110 |
@@ -1,2044 +1,2066 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: dsuarez $ |
|
3 | $Author: dsuarez $ | |
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import numpy |
|
7 | import numpy | |
8 | import datetime |
|
8 | import datetime | |
9 | import time |
|
9 | import time | |
10 | import math |
|
10 | import math | |
11 | from jrodata import * |
|
11 | from jrodata import * | |
12 | from jrodataIO import * |
|
12 | from jrodataIO import * | |
13 | from jroplot import * |
|
13 | from jroplot import * | |
14 |
|
14 | |||
15 | try: |
|
15 | try: | |
16 | import cfunctions |
|
16 | import cfunctions | |
17 | except: |
|
17 | except: | |
18 | pass |
|
18 | pass | |
19 |
|
19 | |||
20 | class ProcessingUnit: |
|
20 | class ProcessingUnit: | |
21 |
|
21 | |||
22 | """ |
|
22 | """ | |
23 | Esta es la clase base para el procesamiento de datos. |
|
23 | Esta es la clase base para el procesamiento de datos. | |
24 |
|
24 | |||
25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
26 | - Metodos internos (callMethod) |
|
26 | - Metodos internos (callMethod) | |
27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
28 | tienen que ser agreagados con el metodo "add". |
|
28 | tienen que ser agreagados con el metodo "add". | |
29 |
|
29 | |||
30 | """ |
|
30 | """ | |
31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
32 | dataIn = None |
|
32 | dataIn = None | |
33 |
|
33 | |||
34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
35 | dataOut = None |
|
35 | dataOut = None | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | objectDict = None |
|
38 | objectDict = None | |
39 |
|
39 | |||
40 | def __init__(self): |
|
40 | def __init__(self): | |
41 |
|
41 | |||
42 | self.objectDict = {} |
|
42 | self.objectDict = {} | |
43 |
|
43 | |||
44 | def init(self): |
|
44 | def init(self): | |
45 |
|
45 | |||
46 | raise ValueError, "Not implemented" |
|
46 | raise ValueError, "Not implemented" | |
47 |
|
47 | |||
48 | def addOperation(self, object, objId): |
|
48 | def addOperation(self, object, objId): | |
49 |
|
49 | |||
50 | """ |
|
50 | """ | |
51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el | |
52 | identificador asociado a este objeto. |
|
52 | identificador asociado a este objeto. | |
53 |
|
53 | |||
54 | Input: |
|
54 | Input: | |
55 |
|
55 | |||
56 | object : objeto de la clase "Operation" |
|
56 | object : objeto de la clase "Operation" | |
57 |
|
57 | |||
58 | Return: |
|
58 | Return: | |
59 |
|
59 | |||
60 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
60 | objId : identificador del objeto, necesario para ejecutar la operacion | |
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | self.objectDict[objId] = object |
|
63 | self.objectDict[objId] = object | |
64 |
|
64 | |||
65 | return objId |
|
65 | return objId | |
66 |
|
66 | |||
67 | def operation(self, **kwargs): |
|
67 | def operation(self, **kwargs): | |
68 |
|
68 | |||
69 | """ |
|
69 | """ | |
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los | |
71 | atributos del objeto dataOut |
|
71 | atributos del objeto dataOut | |
72 |
|
72 | |||
73 | Input: |
|
73 | Input: | |
74 |
|
74 | |||
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
76 | """ |
|
76 | """ | |
77 |
|
77 | |||
78 | raise ValueError, "ImplementedError" |
|
78 | raise ValueError, "ImplementedError" | |
79 |
|
79 | |||
80 | def callMethod(self, name, **kwargs): |
|
80 | def callMethod(self, name, **kwargs): | |
81 |
|
81 | |||
82 | """ |
|
82 | """ | |
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | name : nombre del metodo a ejecutar |
|
86 | name : nombre del metodo a ejecutar | |
87 |
|
87 | |||
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
89 |
|
89 | |||
90 | """ |
|
90 | """ | |
91 | if name != 'run': |
|
91 | if name != 'run': | |
92 |
|
92 | |||
93 | if name == 'init' and self.dataIn.isEmpty(): |
|
93 | if name == 'init' and self.dataIn.isEmpty(): | |
94 | self.dataOut.flagNoData = True |
|
94 | self.dataOut.flagNoData = True | |
95 | return False |
|
95 | return False | |
96 |
|
96 | |||
97 | if name != 'init' and self.dataOut.isEmpty(): |
|
97 | if name != 'init' and self.dataOut.isEmpty(): | |
98 | return False |
|
98 | return False | |
99 |
|
99 | |||
100 | methodToCall = getattr(self, name) |
|
100 | methodToCall = getattr(self, name) | |
101 |
|
101 | |||
102 | methodToCall(**kwargs) |
|
102 | methodToCall(**kwargs) | |
103 |
|
103 | |||
104 | if name != 'run': |
|
104 | if name != 'run': | |
105 | return True |
|
105 | return True | |
106 |
|
106 | |||
107 | if self.dataOut.isEmpty(): |
|
107 | if self.dataOut.isEmpty(): | |
108 | return False |
|
108 | return False | |
109 |
|
109 | |||
110 | return True |
|
110 | return True | |
111 |
|
111 | |||
112 | def callObject(self, objId, **kwargs): |
|
112 | def callObject(self, objId, **kwargs): | |
113 |
|
113 | |||
114 | """ |
|
114 | """ | |
115 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
115 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
116 |
|
116 | |||
117 | Input: |
|
117 | Input: | |
118 |
|
118 | |||
119 | objId : identificador del objeto a ejecutar |
|
119 | objId : identificador del objeto a ejecutar | |
120 |
|
120 | |||
121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
122 |
|
122 | |||
123 | Return: |
|
123 | Return: | |
124 |
|
124 | |||
125 | None |
|
125 | None | |
126 | """ |
|
126 | """ | |
127 |
|
127 | |||
128 | if self.dataOut.isEmpty(): |
|
128 | if self.dataOut.isEmpty(): | |
129 | return False |
|
129 | return False | |
130 |
|
130 | |||
131 | object = self.objectDict[objId] |
|
131 | object = self.objectDict[objId] | |
132 |
|
132 | |||
133 | object.run(self.dataOut, **kwargs) |
|
133 | object.run(self.dataOut, **kwargs) | |
134 |
|
134 | |||
135 | return True |
|
135 | return True | |
136 |
|
136 | |||
137 | def call(self, operationConf, **kwargs): |
|
137 | def call(self, operationConf, **kwargs): | |
138 |
|
138 | |||
139 | """ |
|
139 | """ | |
140 | Return True si ejecuta la operacion "operationConf.name" con los |
|
140 | Return True si ejecuta la operacion "operationConf.name" con los | |
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. | |
142 | La operacion puede ser de dos tipos: |
|
142 | La operacion puede ser de dos tipos: | |
143 |
|
143 | |||
144 | 1. Un metodo propio de esta clase: |
|
144 | 1. Un metodo propio de esta clase: | |
145 |
|
145 | |||
146 | operation.type = "self" |
|
146 | operation.type = "self" | |
147 |
|
147 | |||
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
149 | operation.type = "other". |
|
149 | operation.type = "other". | |
150 |
|
150 | |||
151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
152 | "addOperation" e identificado con el operation.id |
|
152 | "addOperation" e identificado con el operation.id | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | con el id de la operacion. |
|
155 | con el id de la operacion. | |
156 |
|
156 | |||
157 | Input: |
|
157 | Input: | |
158 |
|
158 | |||
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
160 |
|
160 | |||
161 | """ |
|
161 | """ | |
162 |
|
162 | |||
163 | if operationConf.type == 'self': |
|
163 | if operationConf.type == 'self': | |
164 | sts = self.callMethod(operationConf.name, **kwargs) |
|
164 | sts = self.callMethod(operationConf.name, **kwargs) | |
165 |
|
165 | |||
166 | if operationConf.type == 'other': |
|
166 | if operationConf.type == 'other': | |
167 | sts = self.callObject(operationConf.id, **kwargs) |
|
167 | sts = self.callObject(operationConf.id, **kwargs) | |
168 |
|
168 | |||
169 | return sts |
|
169 | return sts | |
170 |
|
170 | |||
171 | def setInput(self, dataIn): |
|
171 | def setInput(self, dataIn): | |
172 |
|
172 | |||
173 | self.dataIn = dataIn |
|
173 | self.dataIn = dataIn | |
174 |
|
174 | |||
175 | def getOutput(self): |
|
175 | def getOutput(self): | |
176 |
|
176 | |||
177 | return self.dataOut |
|
177 | return self.dataOut | |
178 |
|
178 | |||
179 | class Operation(): |
|
179 | class Operation(): | |
180 |
|
180 | |||
181 | """ |
|
181 | """ | |
182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
184 | acumulacion dentro de esta clase |
|
184 | acumulacion dentro de esta clase | |
185 |
|
185 | |||
186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
187 |
|
187 | |||
188 | """ |
|
188 | """ | |
189 |
|
189 | |||
190 | __buffer = None |
|
190 | __buffer = None | |
191 | __isConfig = False |
|
191 | __isConfig = False | |
192 |
|
192 | |||
193 | def __init__(self): |
|
193 | def __init__(self): | |
194 |
|
194 | |||
195 | pass |
|
195 | pass | |
196 |
|
196 | |||
197 | def run(self, dataIn, **kwargs): |
|
197 | def run(self, dataIn, **kwargs): | |
198 |
|
198 | |||
199 | """ |
|
199 | """ | |
200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. | |
201 |
|
201 | |||
202 | Input: |
|
202 | Input: | |
203 |
|
203 | |||
204 | dataIn : objeto del tipo JROData |
|
204 | dataIn : objeto del tipo JROData | |
205 |
|
205 | |||
206 | Return: |
|
206 | Return: | |
207 |
|
207 | |||
208 | None |
|
208 | None | |
209 |
|
209 | |||
210 | Affected: |
|
210 | Affected: | |
211 | __buffer : buffer de recepcion de datos. |
|
211 | __buffer : buffer de recepcion de datos. | |
212 |
|
212 | |||
213 | """ |
|
213 | """ | |
214 |
|
214 | |||
215 | raise ValueError, "ImplementedError" |
|
215 | raise ValueError, "ImplementedError" | |
216 |
|
216 | |||
217 | class VoltageProc(ProcessingUnit): |
|
217 | class VoltageProc(ProcessingUnit): | |
218 |
|
218 | |||
219 |
|
219 | |||
220 | def __init__(self): |
|
220 | def __init__(self): | |
221 |
|
221 | |||
222 | self.objectDict = {} |
|
222 | self.objectDict = {} | |
223 | self.dataOut = Voltage() |
|
223 | self.dataOut = Voltage() | |
224 | self.flip = 1 |
|
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 | def init(self): |
|
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 | # No necesita copiar en cada init() los atributos de dataIn |
|
251 | # No necesita copiar en cada init() los atributos de dataIn | |
230 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
252 | # la copia deberia hacerse por cada nuevo bloque de datos | |
231 |
|
253 | |||
232 | def selectChannels(self, channelList): |
|
254 | def selectChannels(self, channelList): | |
233 |
|
255 | |||
234 | channelIndexList = [] |
|
256 | channelIndexList = [] | |
235 |
|
257 | |||
236 | for channel in channelList: |
|
258 | for channel in channelList: | |
237 | index = self.dataOut.channelList.index(channel) |
|
259 | index = self.dataOut.channelList.index(channel) | |
238 | channelIndexList.append(index) |
|
260 | channelIndexList.append(index) | |
239 |
|
261 | |||
240 | self.selectChannelsByIndex(channelIndexList) |
|
262 | self.selectChannelsByIndex(channelIndexList) | |
241 |
|
263 | |||
242 | def selectChannelsByIndex(self, channelIndexList): |
|
264 | def selectChannelsByIndex(self, channelIndexList): | |
243 | """ |
|
265 | """ | |
244 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
266 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
245 |
|
267 | |||
246 | Input: |
|
268 | Input: | |
247 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
269 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
248 |
|
270 | |||
249 | Affected: |
|
271 | Affected: | |
250 | self.dataOut.data |
|
272 | self.dataOut.data | |
251 | self.dataOut.channelIndexList |
|
273 | self.dataOut.channelIndexList | |
252 | self.dataOut.nChannels |
|
274 | self.dataOut.nChannels | |
253 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
275 | self.dataOut.m_ProcessingHeader.totalSpectra | |
254 | self.dataOut.systemHeaderObj.numChannels |
|
276 | self.dataOut.systemHeaderObj.numChannels | |
255 | self.dataOut.m_ProcessingHeader.blockSize |
|
277 | self.dataOut.m_ProcessingHeader.blockSize | |
256 |
|
278 | |||
257 | Return: |
|
279 | Return: | |
258 | None |
|
280 | None | |
259 | """ |
|
281 | """ | |
260 |
|
282 | |||
261 | for channelIndex in channelIndexList: |
|
283 | for channelIndex in channelIndexList: | |
262 | if channelIndex not in self.dataOut.channelIndexList: |
|
284 | if channelIndex not in self.dataOut.channelIndexList: | |
263 | print channelIndexList |
|
285 | print channelIndexList | |
264 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
286 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
265 |
|
287 | |||
266 | nChannels = len(channelIndexList) |
|
288 | nChannels = len(channelIndexList) | |
267 |
|
289 | |||
268 | data = self.dataOut.data[channelIndexList,:] |
|
290 | data = self.dataOut.data[channelIndexList,:] | |
269 |
|
291 | |||
270 | self.dataOut.data = data |
|
292 | self.dataOut.data = data | |
271 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
293 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
272 | # self.dataOut.nChannels = nChannels |
|
294 | # self.dataOut.nChannels = nChannels | |
273 |
|
295 | |||
274 | return 1 |
|
296 | return 1 | |
275 |
|
297 | |||
276 | def selectHeights(self, minHei=None, maxHei=None): |
|
298 | def selectHeights(self, minHei=None, maxHei=None): | |
277 | """ |
|
299 | """ | |
278 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
300 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
279 | minHei <= height <= maxHei |
|
301 | minHei <= height <= maxHei | |
280 |
|
302 | |||
281 | Input: |
|
303 | Input: | |
282 | minHei : valor minimo de altura a considerar |
|
304 | minHei : valor minimo de altura a considerar | |
283 | maxHei : valor maximo de altura a considerar |
|
305 | maxHei : valor maximo de altura a considerar | |
284 |
|
306 | |||
285 | Affected: |
|
307 | Affected: | |
286 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
308 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
287 |
|
309 | |||
288 | Return: |
|
310 | Return: | |
289 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
311 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
290 | """ |
|
312 | """ | |
291 |
|
313 | |||
292 | if minHei == None: |
|
314 | if minHei == None: | |
293 | minHei = self.dataOut.heightList[0] |
|
315 | minHei = self.dataOut.heightList[0] | |
294 |
|
316 | |||
295 | if maxHei == None: |
|
317 | if maxHei == None: | |
296 | maxHei = self.dataOut.heightList[-1] |
|
318 | maxHei = self.dataOut.heightList[-1] | |
297 |
|
319 | |||
298 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
320 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
299 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
321 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
300 |
|
322 | |||
301 |
|
323 | |||
302 | if (maxHei > self.dataOut.heightList[-1]): |
|
324 | if (maxHei > self.dataOut.heightList[-1]): | |
303 | maxHei = self.dataOut.heightList[-1] |
|
325 | maxHei = self.dataOut.heightList[-1] | |
304 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
326 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
305 |
|
327 | |||
306 | minIndex = 0 |
|
328 | minIndex = 0 | |
307 | maxIndex = 0 |
|
329 | maxIndex = 0 | |
308 | heights = self.dataOut.heightList |
|
330 | heights = self.dataOut.heightList | |
309 |
|
331 | |||
310 | inda = numpy.where(heights >= minHei) |
|
332 | inda = numpy.where(heights >= minHei) | |
311 | indb = numpy.where(heights <= maxHei) |
|
333 | indb = numpy.where(heights <= maxHei) | |
312 |
|
334 | |||
313 | try: |
|
335 | try: | |
314 | minIndex = inda[0][0] |
|
336 | minIndex = inda[0][0] | |
315 | except: |
|
337 | except: | |
316 | minIndex = 0 |
|
338 | minIndex = 0 | |
317 |
|
339 | |||
318 | try: |
|
340 | try: | |
319 | maxIndex = indb[0][-1] |
|
341 | maxIndex = indb[0][-1] | |
320 | except: |
|
342 | except: | |
321 | maxIndex = len(heights) |
|
343 | maxIndex = len(heights) | |
322 |
|
344 | |||
323 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
345 | self.selectHeightsByIndex(minIndex, maxIndex) | |
324 |
|
346 | |||
325 | return 1 |
|
347 | return 1 | |
326 |
|
348 | |||
327 |
|
349 | |||
328 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
350 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
329 | """ |
|
351 | """ | |
330 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
352 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
331 | minIndex <= index <= maxIndex |
|
353 | minIndex <= index <= maxIndex | |
332 |
|
354 | |||
333 | Input: |
|
355 | Input: | |
334 | minIndex : valor de indice minimo de altura a considerar |
|
356 | minIndex : valor de indice minimo de altura a considerar | |
335 | maxIndex : valor de indice maximo de altura a considerar |
|
357 | maxIndex : valor de indice maximo de altura a considerar | |
336 |
|
358 | |||
337 | Affected: |
|
359 | Affected: | |
338 | self.dataOut.data |
|
360 | self.dataOut.data | |
339 | self.dataOut.heightList |
|
361 | self.dataOut.heightList | |
340 |
|
362 | |||
341 | Return: |
|
363 | Return: | |
342 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
364 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
343 | """ |
|
365 | """ | |
344 |
|
366 | |||
345 | if (minIndex < 0) or (minIndex > maxIndex): |
|
367 | if (minIndex < 0) or (minIndex > maxIndex): | |
346 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
368 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
347 |
|
369 | |||
348 | if (maxIndex >= self.dataOut.nHeights): |
|
370 | if (maxIndex >= self.dataOut.nHeights): | |
349 | maxIndex = self.dataOut.nHeights-1 |
|
371 | maxIndex = self.dataOut.nHeights-1 | |
350 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
372 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
351 |
|
373 | |||
352 | nHeights = maxIndex - minIndex + 1 |
|
374 | nHeights = maxIndex - minIndex + 1 | |
353 |
|
375 | |||
354 | #voltage |
|
376 | #voltage | |
355 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
377 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
356 |
|
378 | |||
357 | firstHeight = self.dataOut.heightList[minIndex] |
|
379 | firstHeight = self.dataOut.heightList[minIndex] | |
358 |
|
380 | |||
359 | self.dataOut.data = data |
|
381 | self.dataOut.data = data | |
360 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
382 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
361 |
|
383 | |||
362 | return 1 |
|
384 | return 1 | |
363 |
|
385 | |||
364 |
|
386 | |||
365 | def filterByHeights(self, window): |
|
387 | def filterByHeights(self, window): | |
366 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
388 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
367 |
|
389 | |||
368 | if window == None: |
|
390 | if window == None: | |
369 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
391 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
370 |
|
392 | |||
371 | newdelta = deltaHeight * window |
|
393 | newdelta = deltaHeight * window | |
372 | r = self.dataOut.data.shape[1] % window |
|
394 | r = self.dataOut.data.shape[1] % window | |
373 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] |
|
395 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] | |
374 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) |
|
396 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) | |
375 | buffer = numpy.sum(buffer,2) |
|
397 | buffer = numpy.sum(buffer,2) | |
376 | self.dataOut.data = buffer |
|
398 | self.dataOut.data = buffer | |
377 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) |
|
399 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) | |
378 | self.dataOut.windowOfFilter = window |
|
400 | self.dataOut.windowOfFilter = window | |
379 |
|
401 | |||
380 | def deFlip(self): |
|
402 | def deFlip(self): | |
381 | self.dataOut.data *= self.flip |
|
403 | self.dataOut.data *= self.flip | |
382 | self.flip *= -1. |
|
404 | self.flip *= -1. | |
383 |
|
405 | |||
384 | def setRadarFrequency(self, frequency=None): |
|
406 | def setRadarFrequency(self, frequency=None): | |
385 | if frequency != None: |
|
407 | if frequency != None: | |
386 | self.dataOut.frequency = frequency |
|
408 | self.dataOut.frequency = frequency | |
387 |
|
409 | |||
388 | return 1 |
|
410 | return 1 | |
389 |
|
411 | |||
390 | class CohInt(Operation): |
|
412 | class CohInt(Operation): | |
391 |
|
413 | |||
392 | __isConfig = False |
|
414 | __isConfig = False | |
393 |
|
415 | |||
394 | __profIndex = 0 |
|
416 | __profIndex = 0 | |
395 | __withOverapping = False |
|
417 | __withOverapping = False | |
396 |
|
418 | |||
397 | __byTime = False |
|
419 | __byTime = False | |
398 | __initime = None |
|
420 | __initime = None | |
399 | __lastdatatime = None |
|
421 | __lastdatatime = None | |
400 | __integrationtime = None |
|
422 | __integrationtime = None | |
401 |
|
423 | |||
402 | __buffer = None |
|
424 | __buffer = None | |
403 |
|
425 | |||
404 | __dataReady = False |
|
426 | __dataReady = False | |
405 |
|
427 | |||
406 | n = None |
|
428 | n = None | |
407 |
|
429 | |||
408 |
|
430 | |||
409 | def __init__(self): |
|
431 | def __init__(self): | |
410 |
|
432 | |||
411 | self.__isConfig = False |
|
433 | self.__isConfig = False | |
412 |
|
434 | |||
413 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
435 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
414 | """ |
|
436 | """ | |
415 | Set the parameters of the integration class. |
|
437 | Set the parameters of the integration class. | |
416 |
|
438 | |||
417 | Inputs: |
|
439 | Inputs: | |
418 |
|
440 | |||
419 | n : Number of coherent integrations |
|
441 | n : Number of coherent integrations | |
420 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
442 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
421 | overlapping : |
|
443 | overlapping : | |
422 |
|
444 | |||
423 | """ |
|
445 | """ | |
424 |
|
446 | |||
425 | self.__initime = None |
|
447 | self.__initime = None | |
426 | self.__lastdatatime = 0 |
|
448 | self.__lastdatatime = 0 | |
427 | self.__buffer = None |
|
449 | self.__buffer = None | |
428 | self.__dataReady = False |
|
450 | self.__dataReady = False | |
429 |
|
451 | |||
430 |
|
452 | |||
431 | if n == None and timeInterval == None: |
|
453 | if n == None and timeInterval == None: | |
432 | raise ValueError, "n or timeInterval should be specified ..." |
|
454 | raise ValueError, "n or timeInterval should be specified ..." | |
433 |
|
455 | |||
434 | if n != None: |
|
456 | if n != None: | |
435 | self.n = n |
|
457 | self.n = n | |
436 | self.__byTime = False |
|
458 | self.__byTime = False | |
437 | else: |
|
459 | else: | |
438 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
460 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
439 | self.n = 9999 |
|
461 | self.n = 9999 | |
440 | self.__byTime = True |
|
462 | self.__byTime = True | |
441 |
|
463 | |||
442 | if overlapping: |
|
464 | if overlapping: | |
443 | self.__withOverapping = True |
|
465 | self.__withOverapping = True | |
444 | self.__buffer = None |
|
466 | self.__buffer = None | |
445 | else: |
|
467 | else: | |
446 | self.__withOverapping = False |
|
468 | self.__withOverapping = False | |
447 | self.__buffer = 0 |
|
469 | self.__buffer = 0 | |
448 |
|
470 | |||
449 | self.__profIndex = 0 |
|
471 | self.__profIndex = 0 | |
450 |
|
472 | |||
451 | def putData(self, data): |
|
473 | def putData(self, data): | |
452 |
|
474 | |||
453 | """ |
|
475 | """ | |
454 | Add a profile to the __buffer and increase in one the __profileIndex |
|
476 | Add a profile to the __buffer and increase in one the __profileIndex | |
455 |
|
477 | |||
456 | """ |
|
478 | """ | |
457 |
|
479 | |||
458 | if not self.__withOverapping: |
|
480 | if not self.__withOverapping: | |
459 | self.__buffer += data.copy() |
|
481 | self.__buffer += data.copy() | |
460 | self.__profIndex += 1 |
|
482 | self.__profIndex += 1 | |
461 | return |
|
483 | return | |
462 |
|
484 | |||
463 | #Overlapping data |
|
485 | #Overlapping data | |
464 | nChannels, nHeis = data.shape |
|
486 | nChannels, nHeis = data.shape | |
465 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
487 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
466 |
|
488 | |||
467 | #If the buffer is empty then it takes the data value |
|
489 | #If the buffer is empty then it takes the data value | |
468 | if self.__buffer == None: |
|
490 | if self.__buffer == None: | |
469 | self.__buffer = data |
|
491 | self.__buffer = data | |
470 | self.__profIndex += 1 |
|
492 | self.__profIndex += 1 | |
471 | return |
|
493 | return | |
472 |
|
494 | |||
473 | #If the buffer length is lower than n then stakcing the data value |
|
495 | #If the buffer length is lower than n then stakcing the data value | |
474 | if self.__profIndex < self.n: |
|
496 | if self.__profIndex < self.n: | |
475 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
497 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
476 | self.__profIndex += 1 |
|
498 | self.__profIndex += 1 | |
477 | return |
|
499 | return | |
478 |
|
500 | |||
479 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
501 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
480 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
502 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
481 | self.__buffer[self.n-1] = data |
|
503 | self.__buffer[self.n-1] = data | |
482 | self.__profIndex = self.n |
|
504 | self.__profIndex = self.n | |
483 | return |
|
505 | return | |
484 |
|
506 | |||
485 |
|
507 | |||
486 | def pushData(self): |
|
508 | def pushData(self): | |
487 | """ |
|
509 | """ | |
488 | Return the sum of the last profiles and the profiles used in the sum. |
|
510 | Return the sum of the last profiles and the profiles used in the sum. | |
489 |
|
511 | |||
490 | Affected: |
|
512 | Affected: | |
491 |
|
513 | |||
492 | self.__profileIndex |
|
514 | self.__profileIndex | |
493 |
|
515 | |||
494 | """ |
|
516 | """ | |
495 |
|
517 | |||
496 | if not self.__withOverapping: |
|
518 | if not self.__withOverapping: | |
497 | data = self.__buffer |
|
519 | data = self.__buffer | |
498 | n = self.__profIndex |
|
520 | n = self.__profIndex | |
499 |
|
521 | |||
500 | self.__buffer = 0 |
|
522 | self.__buffer = 0 | |
501 | self.__profIndex = 0 |
|
523 | self.__profIndex = 0 | |
502 |
|
524 | |||
503 | return data, n |
|
525 | return data, n | |
504 |
|
526 | |||
505 | #Integration with Overlapping |
|
527 | #Integration with Overlapping | |
506 | data = numpy.sum(self.__buffer, axis=0) |
|
528 | data = numpy.sum(self.__buffer, axis=0) | |
507 | n = self.__profIndex |
|
529 | n = self.__profIndex | |
508 |
|
530 | |||
509 | return data, n |
|
531 | return data, n | |
510 |
|
532 | |||
511 | def byProfiles(self, data): |
|
533 | def byProfiles(self, data): | |
512 |
|
534 | |||
513 | self.__dataReady = False |
|
535 | self.__dataReady = False | |
514 | avgdata = None |
|
536 | avgdata = None | |
515 | n = None |
|
537 | n = None | |
516 |
|
538 | |||
517 | self.putData(data) |
|
539 | self.putData(data) | |
518 |
|
540 | |||
519 | if self.__profIndex == self.n: |
|
541 | if self.__profIndex == self.n: | |
520 |
|
542 | |||
521 | avgdata, n = self.pushData() |
|
543 | avgdata, n = self.pushData() | |
522 | self.__dataReady = True |
|
544 | self.__dataReady = True | |
523 |
|
545 | |||
524 | return avgdata |
|
546 | return avgdata | |
525 |
|
547 | |||
526 | def byTime(self, data, datatime): |
|
548 | def byTime(self, data, datatime): | |
527 |
|
549 | |||
528 | self.__dataReady = False |
|
550 | self.__dataReady = False | |
529 | avgdata = None |
|
551 | avgdata = None | |
530 | n = None |
|
552 | n = None | |
531 |
|
553 | |||
532 | self.putData(data) |
|
554 | self.putData(data) | |
533 |
|
555 | |||
534 | if (datatime - self.__initime) >= self.__integrationtime: |
|
556 | if (datatime - self.__initime) >= self.__integrationtime: | |
535 | avgdata, n = self.pushData() |
|
557 | avgdata, n = self.pushData() | |
536 | self.n = n |
|
558 | self.n = n | |
537 | self.__dataReady = True |
|
559 | self.__dataReady = True | |
538 |
|
560 | |||
539 | return avgdata |
|
561 | return avgdata | |
540 |
|
562 | |||
541 | def integrate(self, data, datatime=None): |
|
563 | def integrate(self, data, datatime=None): | |
542 |
|
564 | |||
543 | if self.__initime == None: |
|
565 | if self.__initime == None: | |
544 | self.__initime = datatime |
|
566 | self.__initime = datatime | |
545 |
|
567 | |||
546 | if self.__byTime: |
|
568 | if self.__byTime: | |
547 | avgdata = self.byTime(data, datatime) |
|
569 | avgdata = self.byTime(data, datatime) | |
548 | else: |
|
570 | else: | |
549 | avgdata = self.byProfiles(data) |
|
571 | avgdata = self.byProfiles(data) | |
550 |
|
572 | |||
551 |
|
573 | |||
552 | self.__lastdatatime = datatime |
|
574 | self.__lastdatatime = datatime | |
553 |
|
575 | |||
554 | if avgdata == None: |
|
576 | if avgdata == None: | |
555 | return None, None |
|
577 | return None, None | |
556 |
|
578 | |||
557 | avgdatatime = self.__initime |
|
579 | avgdatatime = self.__initime | |
558 |
|
580 | |||
559 | deltatime = datatime -self.__lastdatatime |
|
581 | deltatime = datatime -self.__lastdatatime | |
560 |
|
582 | |||
561 | if not self.__withOverapping: |
|
583 | if not self.__withOverapping: | |
562 | self.__initime = datatime |
|
584 | self.__initime = datatime | |
563 | else: |
|
585 | else: | |
564 | self.__initime += deltatime |
|
586 | self.__initime += deltatime | |
565 |
|
587 | |||
566 | return avgdata, avgdatatime |
|
588 | return avgdata, avgdatatime | |
567 |
|
589 | |||
568 | def run(self, dataOut, **kwargs): |
|
590 | def run(self, dataOut, **kwargs): | |
569 |
|
591 | |||
570 | if not self.__isConfig: |
|
592 | if not self.__isConfig: | |
571 | self.setup(**kwargs) |
|
593 | self.setup(**kwargs) | |
572 | self.__isConfig = True |
|
594 | self.__isConfig = True | |
573 |
|
595 | |||
574 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
596 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
575 |
|
597 | |||
576 | # dataOut.timeInterval *= n |
|
598 | # dataOut.timeInterval *= n | |
577 | dataOut.flagNoData = True |
|
599 | dataOut.flagNoData = True | |
578 |
|
600 | |||
579 | if self.__dataReady: |
|
601 | if self.__dataReady: | |
580 | dataOut.data = avgdata |
|
602 | dataOut.data = avgdata | |
581 | dataOut.nCohInt *= self.n |
|
603 | dataOut.nCohInt *= self.n | |
582 | dataOut.utctime = avgdatatime |
|
604 | dataOut.utctime = avgdatatime | |
583 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
605 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
584 | dataOut.flagNoData = False |
|
606 | dataOut.flagNoData = False | |
585 |
|
607 | |||
586 |
|
608 | |||
587 | class Decoder(Operation): |
|
609 | class Decoder(Operation): | |
588 |
|
610 | |||
589 | __isConfig = False |
|
611 | __isConfig = False | |
590 | __profIndex = 0 |
|
612 | __profIndex = 0 | |
591 |
|
613 | |||
592 | code = None |
|
614 | code = None | |
593 |
|
615 | |||
594 | nCode = None |
|
616 | nCode = None | |
595 | nBaud = None |
|
617 | nBaud = None | |
596 |
|
618 | |||
597 | def __init__(self): |
|
619 | def __init__(self): | |
598 |
|
620 | |||
599 | self.__isConfig = False |
|
621 | self.__isConfig = False | |
600 |
|
622 | |||
601 | def setup(self, code, shape): |
|
623 | def setup(self, code, shape): | |
602 |
|
624 | |||
603 | self.__profIndex = 0 |
|
625 | self.__profIndex = 0 | |
604 |
|
626 | |||
605 | self.code = code |
|
627 | self.code = code | |
606 |
|
628 | |||
607 | self.nCode = len(code) |
|
629 | self.nCode = len(code) | |
608 | self.nBaud = len(code[0]) |
|
630 | self.nBaud = len(code[0]) | |
609 |
|
631 | |||
610 | self.__nChannels, self.__nHeis = shape |
|
632 | self.__nChannels, self.__nHeis = shape | |
611 |
|
633 | |||
612 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
634 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
613 |
|
635 | |||
614 | __codeBuffer[:,0:self.nBaud] = self.code |
|
636 | __codeBuffer[:,0:self.nBaud] = self.code | |
615 |
|
637 | |||
616 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
638 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
617 |
|
639 | |||
618 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
640 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
619 |
|
641 | |||
620 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
642 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
621 |
|
643 | |||
622 | def convolutionInFreq(self, data): |
|
644 | def convolutionInFreq(self, data): | |
623 |
|
645 | |||
624 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
646 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
625 |
|
647 | |||
626 | fft_data = numpy.fft.fft(data, axis=1) |
|
648 | fft_data = numpy.fft.fft(data, axis=1) | |
627 |
|
649 | |||
628 | conv = fft_data*fft_code |
|
650 | conv = fft_data*fft_code | |
629 |
|
651 | |||
630 | data = numpy.fft.ifft(conv,axis=1) |
|
652 | data = numpy.fft.ifft(conv,axis=1) | |
631 |
|
653 | |||
632 | datadec = data[:,:-self.nBaud+1] |
|
654 | datadec = data[:,:-self.nBaud+1] | |
633 |
|
655 | |||
634 | return datadec |
|
656 | return datadec | |
635 |
|
657 | |||
636 | def convolutionInFreqOpt(self, data): |
|
658 | def convolutionInFreqOpt(self, data): | |
637 |
|
659 | |||
638 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
660 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
639 |
|
661 | |||
640 | data = cfunctions.decoder(fft_code, data) |
|
662 | data = cfunctions.decoder(fft_code, data) | |
641 |
|
663 | |||
642 | datadec = data[:,:-self.nBaud+1] |
|
664 | datadec = data[:,:-self.nBaud+1] | |
643 |
|
665 | |||
644 | return datadec |
|
666 | return datadec | |
645 |
|
667 | |||
646 | def convolutionInTime(self, data): |
|
668 | def convolutionInTime(self, data): | |
647 |
|
669 | |||
648 | code = self.code[self.__profIndex] |
|
670 | code = self.code[self.__profIndex] | |
649 |
|
671 | |||
650 | for i in range(self.__nChannels): |
|
672 | for i in range(self.__nChannels): | |
651 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') |
|
673 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') | |
652 |
|
674 | |||
653 | return self.datadecTime |
|
675 | return self.datadecTime | |
654 |
|
676 | |||
655 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): |
|
677 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): | |
656 |
|
678 | |||
657 | if code == None: |
|
679 | if code == None: | |
658 | code = dataOut.code |
|
680 | code = dataOut.code | |
659 | else: |
|
681 | else: | |
660 | code = numpy.array(code).reshape(nCode,nBaud) |
|
682 | code = numpy.array(code).reshape(nCode,nBaud) | |
661 | dataOut.code = code |
|
683 | dataOut.code = code | |
662 | dataOut.nCode = nCode |
|
684 | dataOut.nCode = nCode | |
663 | dataOut.nBaud = nBaud |
|
685 | dataOut.nBaud = nBaud | |
664 | dataOut.radarControllerHeaderObj.code = code |
|
686 | dataOut.radarControllerHeaderObj.code = code | |
665 | dataOut.radarControllerHeaderObj.nCode = nCode |
|
687 | dataOut.radarControllerHeaderObj.nCode = nCode | |
666 | dataOut.radarControllerHeaderObj.nBaud = nBaud |
|
688 | dataOut.radarControllerHeaderObj.nBaud = nBaud | |
667 |
|
689 | |||
668 |
|
690 | |||
669 | if not self.__isConfig: |
|
691 | if not self.__isConfig: | |
670 |
|
692 | |||
671 | self.setup(code, dataOut.data.shape) |
|
693 | self.setup(code, dataOut.data.shape) | |
672 | self.__isConfig = True |
|
694 | self.__isConfig = True | |
673 |
|
695 | |||
674 | if mode == 0: |
|
696 | if mode == 0: | |
675 | datadec = self.convolutionInTime(dataOut.data) |
|
697 | datadec = self.convolutionInTime(dataOut.data) | |
676 |
|
698 | |||
677 | if mode == 1: |
|
699 | if mode == 1: | |
678 | datadec = self.convolutionInFreq(dataOut.data) |
|
700 | datadec = self.convolutionInFreq(dataOut.data) | |
679 |
|
701 | |||
680 | if mode == 2: |
|
702 | if mode == 2: | |
681 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
703 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
682 |
|
704 | |||
683 | dataOut.data = datadec |
|
705 | dataOut.data = datadec | |
684 |
|
706 | |||
685 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
707 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] | |
686 |
|
708 | |||
687 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
709 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada | |
688 |
|
710 | |||
689 | if self.__profIndex == self.nCode-1: |
|
711 | if self.__profIndex == self.nCode-1: | |
690 | self.__profIndex = 0 |
|
712 | self.__profIndex = 0 | |
691 | return 1 |
|
713 | return 1 | |
692 |
|
714 | |||
693 | self.__profIndex += 1 |
|
715 | self.__profIndex += 1 | |
694 |
|
716 | |||
695 | return 1 |
|
717 | return 1 | |
696 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
718 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
697 |
|
719 | |||
698 |
|
720 | |||
699 |
|
721 | |||
700 | class SpectraProc(ProcessingUnit): |
|
722 | class SpectraProc(ProcessingUnit): | |
701 |
|
723 | |||
702 | def __init__(self): |
|
724 | def __init__(self): | |
703 |
|
725 | |||
704 | self.objectDict = {} |
|
726 | self.objectDict = {} | |
705 | self.buffer = None |
|
727 | self.buffer = None | |
706 | self.firstdatatime = None |
|
728 | self.firstdatatime = None | |
707 | self.profIndex = 0 |
|
729 | self.profIndex = 0 | |
708 | self.dataOut = Spectra() |
|
730 | self.dataOut = Spectra() | |
709 |
|
731 | |||
710 | def __updateObjFromInput(self): |
|
732 | def __updateObjFromInput(self): | |
711 |
|
733 | |||
712 | self.dataOut.timeZone = self.dataIn.timeZone |
|
734 | self.dataOut.timeZone = self.dataIn.timeZone | |
713 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
735 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
714 | self.dataOut.errorCount = self.dataIn.errorCount |
|
736 | self.dataOut.errorCount = self.dataIn.errorCount | |
715 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
737 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
716 |
|
738 | |||
717 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
739 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
718 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
740 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
719 | self.dataOut.channelList = self.dataIn.channelList |
|
741 | self.dataOut.channelList = self.dataIn.channelList | |
720 | self.dataOut.heightList = self.dataIn.heightList |
|
742 | self.dataOut.heightList = self.dataIn.heightList | |
721 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
743 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
722 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
744 | # self.dataOut.nHeights = self.dataIn.nHeights | |
723 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
745 | # self.dataOut.nChannels = self.dataIn.nChannels | |
724 | self.dataOut.nBaud = self.dataIn.nBaud |
|
746 | self.dataOut.nBaud = self.dataIn.nBaud | |
725 | self.dataOut.nCode = self.dataIn.nCode |
|
747 | self.dataOut.nCode = self.dataIn.nCode | |
726 | self.dataOut.code = self.dataIn.code |
|
748 | self.dataOut.code = self.dataIn.code | |
727 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
749 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
728 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
750 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
729 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
751 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
730 | self.dataOut.utctime = self.firstdatatime |
|
752 | self.dataOut.utctime = self.firstdatatime | |
731 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
753 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
732 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
754 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
733 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
755 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
734 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
756 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
735 | self.dataOut.nIncohInt = 1 |
|
757 | self.dataOut.nIncohInt = 1 | |
736 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
758 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
737 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
759 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
738 |
|
760 | |||
739 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
761 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
740 | self.dataOut.frequency = self.dataIn.frequency |
|
762 | self.dataOut.frequency = self.dataIn.frequency | |
741 | self.dataOut.realtime = self.dataIn.realtime |
|
763 | self.dataOut.realtime = self.dataIn.realtime | |
742 |
|
764 | |||
743 | def __getFft(self): |
|
765 | def __getFft(self): | |
744 | """ |
|
766 | """ | |
745 | Convierte valores de Voltaje a Spectra |
|
767 | Convierte valores de Voltaje a Spectra | |
746 |
|
768 | |||
747 | Affected: |
|
769 | Affected: | |
748 | self.dataOut.data_spc |
|
770 | self.dataOut.data_spc | |
749 | self.dataOut.data_cspc |
|
771 | self.dataOut.data_cspc | |
750 | self.dataOut.data_dc |
|
772 | self.dataOut.data_dc | |
751 | self.dataOut.heightList |
|
773 | self.dataOut.heightList | |
752 | self.profIndex |
|
774 | self.profIndex | |
753 | self.buffer |
|
775 | self.buffer | |
754 | self.dataOut.flagNoData |
|
776 | self.dataOut.flagNoData | |
755 | """ |
|
777 | """ | |
756 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
778 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) | |
757 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
779 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
758 | dc = fft_volt[:,0,:] |
|
780 | dc = fft_volt[:,0,:] | |
759 |
|
781 | |||
760 | #calculo de self-spectra |
|
782 | #calculo de self-spectra | |
761 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
783 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
762 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
784 | spc = fft_volt * numpy.conjugate(fft_volt) | |
763 | spc = spc.real |
|
785 | spc = spc.real | |
764 |
|
786 | |||
765 | blocksize = 0 |
|
787 | blocksize = 0 | |
766 | blocksize += dc.size |
|
788 | blocksize += dc.size | |
767 | blocksize += spc.size |
|
789 | blocksize += spc.size | |
768 |
|
790 | |||
769 | cspc = None |
|
791 | cspc = None | |
770 | pairIndex = 0 |
|
792 | pairIndex = 0 | |
771 | if self.dataOut.pairsList != None: |
|
793 | if self.dataOut.pairsList != None: | |
772 | #calculo de cross-spectra |
|
794 | #calculo de cross-spectra | |
773 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
795 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
774 | for pair in self.dataOut.pairsList: |
|
796 | for pair in self.dataOut.pairsList: | |
775 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
797 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) | |
776 | pairIndex += 1 |
|
798 | pairIndex += 1 | |
777 | blocksize += cspc.size |
|
799 | blocksize += cspc.size | |
778 |
|
800 | |||
779 | self.dataOut.data_spc = spc |
|
801 | self.dataOut.data_spc = spc | |
780 | self.dataOut.data_cspc = cspc |
|
802 | self.dataOut.data_cspc = cspc | |
781 | self.dataOut.data_dc = dc |
|
803 | self.dataOut.data_dc = dc | |
782 | self.dataOut.blockSize = blocksize |
|
804 | self.dataOut.blockSize = blocksize | |
783 | self.dataOut.flagShiftFFT = False |
|
805 | self.dataOut.flagShiftFFT = False | |
784 |
|
806 | |||
785 | def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None): |
|
807 | def init(self, nProfiles=None, nFFTPoints=None, pairsList=None, ippFactor=None): | |
786 |
|
808 | |||
787 | self.dataOut.flagNoData = True |
|
809 | self.dataOut.flagNoData = True | |
788 |
|
810 | |||
789 | if self.dataIn.type == "Spectra": |
|
811 | if self.dataIn.type == "Spectra": | |
790 | self.dataOut.copy(self.dataIn) |
|
812 | self.dataOut.copy(self.dataIn) | |
791 | return |
|
813 | return | |
792 |
|
814 | |||
793 | if self.dataIn.type == "Voltage": |
|
815 | if self.dataIn.type == "Voltage": | |
794 |
|
816 | |||
795 | if nFFTPoints == None: |
|
817 | if nFFTPoints == None: | |
796 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" |
|
818 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" | |
797 |
|
819 | |||
798 | if pairsList == None: |
|
820 | if pairsList == None: | |
799 | nPairs = 0 |
|
821 | nPairs = 0 | |
800 | else: |
|
822 | else: | |
801 | nPairs = len(pairsList) |
|
823 | nPairs = len(pairsList) | |
802 |
|
824 | |||
803 | if ippFactor == None: |
|
825 | if ippFactor == None: | |
804 | ippFactor = 1 |
|
826 | ippFactor = 1 | |
805 | self.dataOut.ippFactor = ippFactor |
|
827 | self.dataOut.ippFactor = ippFactor | |
806 |
|
828 | |||
807 | self.dataOut.nFFTPoints = nFFTPoints |
|
829 | self.dataOut.nFFTPoints = nFFTPoints | |
808 | self.dataOut.pairsList = pairsList |
|
830 | self.dataOut.pairsList = pairsList | |
809 | self.dataOut.nPairs = nPairs |
|
831 | self.dataOut.nPairs = nPairs | |
810 |
|
832 | |||
811 | if self.buffer == None: |
|
833 | if self.buffer == None: | |
812 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
834 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
813 | nProfiles, |
|
835 | nProfiles, | |
814 | self.dataIn.nHeights), |
|
836 | self.dataIn.nHeights), | |
815 | dtype='complex') |
|
837 | dtype='complex') | |
816 |
|
838 | |||
817 |
|
839 | |||
818 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
840 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() | |
819 | self.profIndex += 1 |
|
841 | self.profIndex += 1 | |
820 |
|
842 | |||
821 | if self.firstdatatime == None: |
|
843 | if self.firstdatatime == None: | |
822 | self.firstdatatime = self.dataIn.utctime |
|
844 | self.firstdatatime = self.dataIn.utctime | |
823 |
|
845 | |||
824 | if self.profIndex == nProfiles: |
|
846 | if self.profIndex == nProfiles: | |
825 | self.__updateObjFromInput() |
|
847 | self.__updateObjFromInput() | |
826 | self.__getFft() |
|
848 | self.__getFft() | |
827 |
|
849 | |||
828 | self.dataOut.flagNoData = False |
|
850 | self.dataOut.flagNoData = False | |
829 |
|
851 | |||
830 | self.buffer = None |
|
852 | self.buffer = None | |
831 | self.firstdatatime = None |
|
853 | self.firstdatatime = None | |
832 | self.profIndex = 0 |
|
854 | self.profIndex = 0 | |
833 |
|
855 | |||
834 | return |
|
856 | return | |
835 |
|
857 | |||
836 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
858 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) | |
837 |
|
859 | |||
838 | def selectChannels(self, channelList): |
|
860 | def selectChannels(self, channelList): | |
839 |
|
861 | |||
840 | channelIndexList = [] |
|
862 | channelIndexList = [] | |
841 |
|
863 | |||
842 | for channel in channelList: |
|
864 | for channel in channelList: | |
843 | index = self.dataOut.channelList.index(channel) |
|
865 | index = self.dataOut.channelList.index(channel) | |
844 | channelIndexList.append(index) |
|
866 | channelIndexList.append(index) | |
845 |
|
867 | |||
846 | self.selectChannelsByIndex(channelIndexList) |
|
868 | self.selectChannelsByIndex(channelIndexList) | |
847 |
|
869 | |||
848 | def selectChannelsByIndex(self, channelIndexList): |
|
870 | def selectChannelsByIndex(self, channelIndexList): | |
849 | """ |
|
871 | """ | |
850 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
872 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
851 |
|
873 | |||
852 | Input: |
|
874 | Input: | |
853 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
875 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
854 |
|
876 | |||
855 | Affected: |
|
877 | Affected: | |
856 | self.dataOut.data_spc |
|
878 | self.dataOut.data_spc | |
857 | self.dataOut.channelIndexList |
|
879 | self.dataOut.channelIndexList | |
858 | self.dataOut.nChannels |
|
880 | self.dataOut.nChannels | |
859 |
|
881 | |||
860 | Return: |
|
882 | Return: | |
861 | None |
|
883 | None | |
862 | """ |
|
884 | """ | |
863 |
|
885 | |||
864 | for channelIndex in channelIndexList: |
|
886 | for channelIndex in channelIndexList: | |
865 | if channelIndex not in self.dataOut.channelIndexList: |
|
887 | if channelIndex not in self.dataOut.channelIndexList: | |
866 | print channelIndexList |
|
888 | print channelIndexList | |
867 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
889 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
868 |
|
890 | |||
869 | nChannels = len(channelIndexList) |
|
891 | nChannels = len(channelIndexList) | |
870 |
|
892 | |||
871 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
893 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
872 |
|
894 | |||
873 | self.dataOut.data_spc = data_spc |
|
895 | self.dataOut.data_spc = data_spc | |
874 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
896 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
875 | # self.dataOut.nChannels = nChannels |
|
897 | # self.dataOut.nChannels = nChannels | |
876 |
|
898 | |||
877 | return 1 |
|
899 | return 1 | |
878 |
|
900 | |||
879 | def selectHeights(self, minHei, maxHei): |
|
901 | def selectHeights(self, minHei, maxHei): | |
880 | """ |
|
902 | """ | |
881 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
903 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
882 | minHei <= height <= maxHei |
|
904 | minHei <= height <= maxHei | |
883 |
|
905 | |||
884 | Input: |
|
906 | Input: | |
885 | minHei : valor minimo de altura a considerar |
|
907 | minHei : valor minimo de altura a considerar | |
886 | maxHei : valor maximo de altura a considerar |
|
908 | maxHei : valor maximo de altura a considerar | |
887 |
|
909 | |||
888 | Affected: |
|
910 | Affected: | |
889 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
911 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
890 |
|
912 | |||
891 | Return: |
|
913 | Return: | |
892 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
914 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
893 | """ |
|
915 | """ | |
894 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
916 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
895 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
917 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
896 |
|
918 | |||
897 | if (maxHei > self.dataOut.heightList[-1]): |
|
919 | if (maxHei > self.dataOut.heightList[-1]): | |
898 | maxHei = self.dataOut.heightList[-1] |
|
920 | maxHei = self.dataOut.heightList[-1] | |
899 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
921 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
900 |
|
922 | |||
901 | minIndex = 0 |
|
923 | minIndex = 0 | |
902 | maxIndex = 0 |
|
924 | maxIndex = 0 | |
903 | heights = self.dataOut.heightList |
|
925 | heights = self.dataOut.heightList | |
904 |
|
926 | |||
905 | inda = numpy.where(heights >= minHei) |
|
927 | inda = numpy.where(heights >= minHei) | |
906 | indb = numpy.where(heights <= maxHei) |
|
928 | indb = numpy.where(heights <= maxHei) | |
907 |
|
929 | |||
908 | try: |
|
930 | try: | |
909 | minIndex = inda[0][0] |
|
931 | minIndex = inda[0][0] | |
910 | except: |
|
932 | except: | |
911 | minIndex = 0 |
|
933 | minIndex = 0 | |
912 |
|
934 | |||
913 | try: |
|
935 | try: | |
914 | maxIndex = indb[0][-1] |
|
936 | maxIndex = indb[0][-1] | |
915 | except: |
|
937 | except: | |
916 | maxIndex = len(heights) |
|
938 | maxIndex = len(heights) | |
917 |
|
939 | |||
918 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
940 | self.selectHeightsByIndex(minIndex, maxIndex) | |
919 |
|
941 | |||
920 | return 1 |
|
942 | return 1 | |
921 |
|
943 | |||
922 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
944 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): | |
923 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
945 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
924 |
|
946 | |||
925 | if hei_ref != None: |
|
947 | if hei_ref != None: | |
926 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
948 | newheis = numpy.where(self.dataOut.heightList>hei_ref) | |
927 |
|
949 | |||
928 | minIndex = min(newheis[0]) |
|
950 | minIndex = min(newheis[0]) | |
929 | maxIndex = max(newheis[0]) |
|
951 | maxIndex = max(newheis[0]) | |
930 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
952 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
931 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
953 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
932 |
|
954 | |||
933 | # determina indices |
|
955 | # determina indices | |
934 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
956 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) | |
935 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
957 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) | |
936 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
958 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
937 | beacon_heiIndexList = [] |
|
959 | beacon_heiIndexList = [] | |
938 | for val in avg_dB.tolist(): |
|
960 | for val in avg_dB.tolist(): | |
939 | if val >= beacon_dB[0]: |
|
961 | if val >= beacon_dB[0]: | |
940 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
962 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
941 |
|
963 | |||
942 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
964 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
943 | data_cspc = None |
|
965 | data_cspc = None | |
944 | if self.dataOut.data_cspc != None: |
|
966 | if self.dataOut.data_cspc != None: | |
945 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
967 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
946 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
968 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
947 |
|
969 | |||
948 | data_dc = None |
|
970 | data_dc = None | |
949 | if self.dataOut.data_dc != None: |
|
971 | if self.dataOut.data_dc != None: | |
950 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
972 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
951 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
973 | #data_dc = data_dc[:,beacon_heiIndexList] | |
952 |
|
974 | |||
953 | self.dataOut.data_spc = data_spc |
|
975 | self.dataOut.data_spc = data_spc | |
954 | self.dataOut.data_cspc = data_cspc |
|
976 | self.dataOut.data_cspc = data_cspc | |
955 | self.dataOut.data_dc = data_dc |
|
977 | self.dataOut.data_dc = data_dc | |
956 | self.dataOut.heightList = heightList |
|
978 | self.dataOut.heightList = heightList | |
957 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
979 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
958 |
|
980 | |||
959 | return 1 |
|
981 | return 1 | |
960 |
|
982 | |||
961 |
|
983 | |||
962 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
984 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
963 | """ |
|
985 | """ | |
964 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
986 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
965 | minIndex <= index <= maxIndex |
|
987 | minIndex <= index <= maxIndex | |
966 |
|
988 | |||
967 | Input: |
|
989 | Input: | |
968 | minIndex : valor de indice minimo de altura a considerar |
|
990 | minIndex : valor de indice minimo de altura a considerar | |
969 | maxIndex : valor de indice maximo de altura a considerar |
|
991 | maxIndex : valor de indice maximo de altura a considerar | |
970 |
|
992 | |||
971 | Affected: |
|
993 | Affected: | |
972 | self.dataOut.data_spc |
|
994 | self.dataOut.data_spc | |
973 | self.dataOut.data_cspc |
|
995 | self.dataOut.data_cspc | |
974 | self.dataOut.data_dc |
|
996 | self.dataOut.data_dc | |
975 | self.dataOut.heightList |
|
997 | self.dataOut.heightList | |
976 |
|
998 | |||
977 | Return: |
|
999 | Return: | |
978 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
1000 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
979 | """ |
|
1001 | """ | |
980 |
|
1002 | |||
981 | if (minIndex < 0) or (minIndex > maxIndex): |
|
1003 | if (minIndex < 0) or (minIndex > maxIndex): | |
982 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
1004 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
983 |
|
1005 | |||
984 | if (maxIndex >= self.dataOut.nHeights): |
|
1006 | if (maxIndex >= self.dataOut.nHeights): | |
985 | maxIndex = self.dataOut.nHeights-1 |
|
1007 | maxIndex = self.dataOut.nHeights-1 | |
986 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
1008 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
987 |
|
1009 | |||
988 | nHeights = maxIndex - minIndex + 1 |
|
1010 | nHeights = maxIndex - minIndex + 1 | |
989 |
|
1011 | |||
990 | #Spectra |
|
1012 | #Spectra | |
991 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
1013 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
992 |
|
1014 | |||
993 | data_cspc = None |
|
1015 | data_cspc = None | |
994 | if self.dataOut.data_cspc != None: |
|
1016 | if self.dataOut.data_cspc != None: | |
995 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
1017 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
996 |
|
1018 | |||
997 | data_dc = None |
|
1019 | data_dc = None | |
998 | if self.dataOut.data_dc != None: |
|
1020 | if self.dataOut.data_dc != None: | |
999 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
1021 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
1000 |
|
1022 | |||
1001 | self.dataOut.data_spc = data_spc |
|
1023 | self.dataOut.data_spc = data_spc | |
1002 | self.dataOut.data_cspc = data_cspc |
|
1024 | self.dataOut.data_cspc = data_cspc | |
1003 | self.dataOut.data_dc = data_dc |
|
1025 | self.dataOut.data_dc = data_dc | |
1004 |
|
1026 | |||
1005 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
1027 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
1006 |
|
1028 | |||
1007 | return 1 |
|
1029 | return 1 | |
1008 |
|
1030 | |||
1009 | def removeDC(self, mode = 2): |
|
1031 | def removeDC(self, mode = 2): | |
1010 | jspectra = self.dataOut.data_spc |
|
1032 | jspectra = self.dataOut.data_spc | |
1011 | jcspectra = self.dataOut.data_cspc |
|
1033 | jcspectra = self.dataOut.data_cspc | |
1012 |
|
1034 | |||
1013 |
|
1035 | |||
1014 | num_chan = jspectra.shape[0] |
|
1036 | num_chan = jspectra.shape[0] | |
1015 | num_hei = jspectra.shape[2] |
|
1037 | num_hei = jspectra.shape[2] | |
1016 |
|
1038 | |||
1017 | if jcspectra != None: |
|
1039 | if jcspectra != None: | |
1018 | jcspectraExist = True |
|
1040 | jcspectraExist = True | |
1019 | num_pairs = jcspectra.shape[0] |
|
1041 | num_pairs = jcspectra.shape[0] | |
1020 | else: jcspectraExist = False |
|
1042 | else: jcspectraExist = False | |
1021 |
|
1043 | |||
1022 | freq_dc = jspectra.shape[1]/2 |
|
1044 | freq_dc = jspectra.shape[1]/2 | |
1023 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
1045 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
1024 |
|
1046 | |||
1025 | if ind_vel[0]<0: |
|
1047 | if ind_vel[0]<0: | |
1026 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1048 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
1027 |
|
1049 | |||
1028 | if mode == 1: |
|
1050 | if mode == 1: | |
1029 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
1051 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
1030 |
|
1052 | |||
1031 | if jcspectraExist: |
|
1053 | if jcspectraExist: | |
1032 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
1054 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 | |
1033 |
|
1055 | |||
1034 | if mode == 2: |
|
1056 | if mode == 2: | |
1035 |
|
1057 | |||
1036 | vel = numpy.array([-2,-1,1,2]) |
|
1058 | vel = numpy.array([-2,-1,1,2]) | |
1037 | xx = numpy.zeros([4,4]) |
|
1059 | xx = numpy.zeros([4,4]) | |
1038 |
|
1060 | |||
1039 | for fil in range(4): |
|
1061 | for fil in range(4): | |
1040 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
1062 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
1041 |
|
1063 | |||
1042 | xx_inv = numpy.linalg.inv(xx) |
|
1064 | xx_inv = numpy.linalg.inv(xx) | |
1043 | xx_aux = xx_inv[0,:] |
|
1065 | xx_aux = xx_inv[0,:] | |
1044 |
|
1066 | |||
1045 | for ich in range(num_chan): |
|
1067 | for ich in range(num_chan): | |
1046 | yy = jspectra[ich,ind_vel,:] |
|
1068 | yy = jspectra[ich,ind_vel,:] | |
1047 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1069 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1048 |
|
1070 | |||
1049 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
1071 | junkid = jspectra[ich,freq_dc,:]<=0 | |
1050 | cjunkid = sum(junkid) |
|
1072 | cjunkid = sum(junkid) | |
1051 |
|
1073 | |||
1052 | if cjunkid.any(): |
|
1074 | if cjunkid.any(): | |
1053 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
1075 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
1054 |
|
1076 | |||
1055 | if jcspectraExist: |
|
1077 | if jcspectraExist: | |
1056 | for ip in range(num_pairs): |
|
1078 | for ip in range(num_pairs): | |
1057 | yy = jcspectra[ip,ind_vel,:] |
|
1079 | yy = jcspectra[ip,ind_vel,:] | |
1058 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
1080 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) | |
1059 |
|
1081 | |||
1060 |
|
1082 | |||
1061 | self.dataOut.data_spc = jspectra |
|
1083 | self.dataOut.data_spc = jspectra | |
1062 | self.dataOut.data_cspc = jcspectra |
|
1084 | self.dataOut.data_cspc = jcspectra | |
1063 |
|
1085 | |||
1064 | return 1 |
|
1086 | return 1 | |
1065 |
|
1087 | |||
1066 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
1088 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |
1067 |
|
1089 | |||
1068 | jspectra = self.dataOut.data_spc |
|
1090 | jspectra = self.dataOut.data_spc | |
1069 | jcspectra = self.dataOut.data_cspc |
|
1091 | jcspectra = self.dataOut.data_cspc | |
1070 | jnoise = self.dataOut.getNoise() |
|
1092 | jnoise = self.dataOut.getNoise() | |
1071 | num_incoh = self.dataOut.nIncohInt |
|
1093 | num_incoh = self.dataOut.nIncohInt | |
1072 |
|
1094 | |||
1073 | num_channel = jspectra.shape[0] |
|
1095 | num_channel = jspectra.shape[0] | |
1074 | num_prof = jspectra.shape[1] |
|
1096 | num_prof = jspectra.shape[1] | |
1075 | num_hei = jspectra.shape[2] |
|
1097 | num_hei = jspectra.shape[2] | |
1076 |
|
1098 | |||
1077 | #hei_interf |
|
1099 | #hei_interf | |
1078 | if hei_interf == None: |
|
1100 | if hei_interf == None: | |
1079 | count_hei = num_hei/2 #Como es entero no importa |
|
1101 | count_hei = num_hei/2 #Como es entero no importa | |
1080 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
1102 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei | |
1081 | hei_interf = numpy.asarray(hei_interf)[0] |
|
1103 | hei_interf = numpy.asarray(hei_interf)[0] | |
1082 | #nhei_interf |
|
1104 | #nhei_interf | |
1083 | if (nhei_interf == None): |
|
1105 | if (nhei_interf == None): | |
1084 | nhei_interf = 5 |
|
1106 | nhei_interf = 5 | |
1085 | if (nhei_interf < 1): |
|
1107 | if (nhei_interf < 1): | |
1086 | nhei_interf = 1 |
|
1108 | nhei_interf = 1 | |
1087 | if (nhei_interf > count_hei): |
|
1109 | if (nhei_interf > count_hei): | |
1088 | nhei_interf = count_hei |
|
1110 | nhei_interf = count_hei | |
1089 | if (offhei_interf == None): |
|
1111 | if (offhei_interf == None): | |
1090 | offhei_interf = 0 |
|
1112 | offhei_interf = 0 | |
1091 |
|
1113 | |||
1092 | ind_hei = range(num_hei) |
|
1114 | ind_hei = range(num_hei) | |
1093 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
1115 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
1094 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
1116 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
1095 | mask_prof = numpy.asarray(range(num_prof)) |
|
1117 | mask_prof = numpy.asarray(range(num_prof)) | |
1096 | num_mask_prof = mask_prof.size |
|
1118 | num_mask_prof = mask_prof.size | |
1097 | comp_mask_prof = [0, num_prof/2] |
|
1119 | comp_mask_prof = [0, num_prof/2] | |
1098 |
|
1120 | |||
1099 |
|
1121 | |||
1100 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
1122 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
1101 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
1123 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
1102 | jnoise = numpy.nan |
|
1124 | jnoise = numpy.nan | |
1103 | noise_exist = jnoise[0] < numpy.Inf |
|
1125 | noise_exist = jnoise[0] < numpy.Inf | |
1104 |
|
1126 | |||
1105 | #Subrutina de Remocion de la Interferencia |
|
1127 | #Subrutina de Remocion de la Interferencia | |
1106 | for ich in range(num_channel): |
|
1128 | for ich in range(num_channel): | |
1107 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
1129 | #Se ordena los espectros segun su potencia (menor a mayor) | |
1108 | power = jspectra[ich,mask_prof,:] |
|
1130 | power = jspectra[ich,mask_prof,:] | |
1109 | power = power[:,hei_interf] |
|
1131 | power = power[:,hei_interf] | |
1110 | power = power.sum(axis = 0) |
|
1132 | power = power.sum(axis = 0) | |
1111 | psort = power.ravel().argsort() |
|
1133 | psort = power.ravel().argsort() | |
1112 |
|
1134 | |||
1113 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
1135 | #Se estima la interferencia promedio en los Espectros de Potencia empleando | |
1114 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
1136 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
1115 |
|
1137 | |||
1116 | if noise_exist: |
|
1138 | if noise_exist: | |
1117 | # tmp_noise = jnoise[ich] / num_prof |
|
1139 | # tmp_noise = jnoise[ich] / num_prof | |
1118 | tmp_noise = jnoise[ich] |
|
1140 | tmp_noise = jnoise[ich] | |
1119 | junkspc_interf = junkspc_interf - tmp_noise |
|
1141 | junkspc_interf = junkspc_interf - tmp_noise | |
1120 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
1142 | #junkspc_interf[:,comp_mask_prof] = 0 | |
1121 |
|
1143 | |||
1122 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
1144 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf | |
1123 | jspc_interf = jspc_interf.transpose() |
|
1145 | jspc_interf = jspc_interf.transpose() | |
1124 | #Calculando el espectro de interferencia promedio |
|
1146 | #Calculando el espectro de interferencia promedio | |
1125 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) |
|
1147 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) | |
1126 | noiseid = noiseid[0] |
|
1148 | noiseid = noiseid[0] | |
1127 | cnoiseid = noiseid.size |
|
1149 | cnoiseid = noiseid.size | |
1128 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) |
|
1150 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) | |
1129 | interfid = interfid[0] |
|
1151 | interfid = interfid[0] | |
1130 | cinterfid = interfid.size |
|
1152 | cinterfid = interfid.size | |
1131 |
|
1153 | |||
1132 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
1154 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 | |
1133 |
|
1155 | |||
1134 | #Expandiendo los perfiles a limpiar |
|
1156 | #Expandiendo los perfiles a limpiar | |
1135 | if (cinterfid > 0): |
|
1157 | if (cinterfid > 0): | |
1136 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
1158 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof | |
1137 | new_interfid = numpy.asarray(new_interfid) |
|
1159 | new_interfid = numpy.asarray(new_interfid) | |
1138 | new_interfid = {x for x in new_interfid} |
|
1160 | new_interfid = {x for x in new_interfid} | |
1139 | new_interfid = numpy.array(list(new_interfid)) |
|
1161 | new_interfid = numpy.array(list(new_interfid)) | |
1140 | new_cinterfid = new_interfid.size |
|
1162 | new_cinterfid = new_interfid.size | |
1141 | else: new_cinterfid = 0 |
|
1163 | else: new_cinterfid = 0 | |
1142 |
|
1164 | |||
1143 | for ip in range(new_cinterfid): |
|
1165 | for ip in range(new_cinterfid): | |
1144 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
1166 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() | |
1145 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
1167 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] | |
1146 |
|
1168 | |||
1147 |
|
1169 | |||
1148 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
1170 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices | |
1149 |
|
1171 | |||
1150 | #Removiendo la interferencia del punto de mayor interferencia |
|
1172 | #Removiendo la interferencia del punto de mayor interferencia | |
1151 | ListAux = jspc_interf[mask_prof].tolist() |
|
1173 | ListAux = jspc_interf[mask_prof].tolist() | |
1152 | maxid = ListAux.index(max(ListAux)) |
|
1174 | maxid = ListAux.index(max(ListAux)) | |
1153 |
|
1175 | |||
1154 |
|
1176 | |||
1155 | if cinterfid > 0: |
|
1177 | if cinterfid > 0: | |
1156 | for ip in range(cinterfid*(interf == 2) - 1): |
|
1178 | for ip in range(cinterfid*(interf == 2) - 1): | |
1157 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() |
|
1179 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() | |
1158 | cind = len(ind) |
|
1180 | cind = len(ind) | |
1159 |
|
1181 | |||
1160 | if (cind > 0): |
|
1182 | if (cind > 0): | |
1161 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) |
|
1183 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) | |
1162 |
|
1184 | |||
1163 | ind = numpy.array([-2,-1,1,2]) |
|
1185 | ind = numpy.array([-2,-1,1,2]) | |
1164 | xx = numpy.zeros([4,4]) |
|
1186 | xx = numpy.zeros([4,4]) | |
1165 |
|
1187 | |||
1166 | for id1 in range(4): |
|
1188 | for id1 in range(4): | |
1167 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
1189 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
1168 |
|
1190 | |||
1169 | xx_inv = numpy.linalg.inv(xx) |
|
1191 | xx_inv = numpy.linalg.inv(xx) | |
1170 | xx = xx_inv[:,0] |
|
1192 | xx = xx_inv[:,0] | |
1171 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
1193 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
1172 | yy = jspectra[ich,mask_prof[ind],:] |
|
1194 | yy = jspectra[ich,mask_prof[ind],:] | |
1173 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
1195 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
1174 |
|
1196 | |||
1175 |
|
1197 | |||
1176 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() |
|
1198 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() | |
1177 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) |
|
1199 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) | |
1178 |
|
1200 | |||
1179 | #Remocion de Interferencia en el Cross Spectra |
|
1201 | #Remocion de Interferencia en el Cross Spectra | |
1180 | if jcspectra == None: return jspectra, jcspectra |
|
1202 | if jcspectra == None: return jspectra, jcspectra | |
1181 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
1203 | num_pairs = jcspectra.size/(num_prof*num_hei) | |
1182 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
1204 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
1183 |
|
1205 | |||
1184 | for ip in range(num_pairs): |
|
1206 | for ip in range(num_pairs): | |
1185 |
|
1207 | |||
1186 | #------------------------------------------- |
|
1208 | #------------------------------------------- | |
1187 |
|
1209 | |||
1188 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
1210 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) | |
1189 | cspower = cspower[:,hei_interf] |
|
1211 | cspower = cspower[:,hei_interf] | |
1190 | cspower = cspower.sum(axis = 0) |
|
1212 | cspower = cspower.sum(axis = 0) | |
1191 |
|
1213 | |||
1192 | cspsort = cspower.ravel().argsort() |
|
1214 | cspsort = cspower.ravel().argsort() | |
1193 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
1215 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
1194 | junkcspc_interf = junkcspc_interf.transpose() |
|
1216 | junkcspc_interf = junkcspc_interf.transpose() | |
1195 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
1217 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf | |
1196 |
|
1218 | |||
1197 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
1219 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
1198 |
|
1220 | |||
1199 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
1221 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
1200 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
1222 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
1201 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
1223 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) | |
1202 |
|
1224 | |||
1203 | for iprof in range(num_prof): |
|
1225 | for iprof in range(num_prof): | |
1204 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
1226 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() | |
1205 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
1227 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] | |
1206 |
|
1228 | |||
1207 | #Removiendo la Interferencia |
|
1229 | #Removiendo la Interferencia | |
1208 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
1230 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf | |
1209 |
|
1231 | |||
1210 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
1232 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
1211 | maxid = ListAux.index(max(ListAux)) |
|
1233 | maxid = ListAux.index(max(ListAux)) | |
1212 |
|
1234 | |||
1213 | ind = numpy.array([-2,-1,1,2]) |
|
1235 | ind = numpy.array([-2,-1,1,2]) | |
1214 | xx = numpy.zeros([4,4]) |
|
1236 | xx = numpy.zeros([4,4]) | |
1215 |
|
1237 | |||
1216 | for id1 in range(4): |
|
1238 | for id1 in range(4): | |
1217 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
1239 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
1218 |
|
1240 | |||
1219 | xx_inv = numpy.linalg.inv(xx) |
|
1241 | xx_inv = numpy.linalg.inv(xx) | |
1220 | xx = xx_inv[:,0] |
|
1242 | xx = xx_inv[:,0] | |
1221 |
|
1243 | |||
1222 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
1244 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
1223 | yy = jcspectra[ip,mask_prof[ind],:] |
|
1245 | yy = jcspectra[ip,mask_prof[ind],:] | |
1224 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
1246 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
1225 |
|
1247 | |||
1226 | #Guardar Resultados |
|
1248 | #Guardar Resultados | |
1227 | self.dataOut.data_spc = jspectra |
|
1249 | self.dataOut.data_spc = jspectra | |
1228 | self.dataOut.data_cspc = jcspectra |
|
1250 | self.dataOut.data_cspc = jcspectra | |
1229 |
|
1251 | |||
1230 | return 1 |
|
1252 | return 1 | |
1231 |
|
1253 | |||
1232 | def setRadarFrequency(self, frequency=None): |
|
1254 | def setRadarFrequency(self, frequency=None): | |
1233 | if frequency != None: |
|
1255 | if frequency != None: | |
1234 | self.dataOut.frequency = frequency |
|
1256 | self.dataOut.frequency = frequency | |
1235 |
|
1257 | |||
1236 | return 1 |
|
1258 | return 1 | |
1237 |
|
1259 | |||
1238 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
1260 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
1239 | #validacion de rango |
|
1261 | #validacion de rango | |
1240 | if minHei == None: |
|
1262 | if minHei == None: | |
1241 | minHei = self.dataOut.heightList[0] |
|
1263 | minHei = self.dataOut.heightList[0] | |
1242 |
|
1264 | |||
1243 | if maxHei == None: |
|
1265 | if maxHei == None: | |
1244 | maxHei = self.dataOut.heightList[-1] |
|
1266 | maxHei = self.dataOut.heightList[-1] | |
1245 |
|
1267 | |||
1246 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
1268 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
1247 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
1269 | print 'minHei: %.2f is out of the heights range'%(minHei) | |
1248 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
1270 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) | |
1249 | minHei = self.dataOut.heightList[0] |
|
1271 | minHei = self.dataOut.heightList[0] | |
1250 |
|
1272 | |||
1251 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
1273 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
1252 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
1274 | print 'maxHei: %.2f is out of the heights range'%(maxHei) | |
1253 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
1275 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) | |
1254 | maxHei = self.dataOut.heightList[-1] |
|
1276 | maxHei = self.dataOut.heightList[-1] | |
1255 |
|
1277 | |||
1256 | # validacion de velocidades |
|
1278 | # validacion de velocidades | |
1257 | velrange = self.dataOut.getVelRange(1) |
|
1279 | velrange = self.dataOut.getVelRange(1) | |
1258 |
|
1280 | |||
1259 | if minVel == None: |
|
1281 | if minVel == None: | |
1260 | minVel = velrange[0] |
|
1282 | minVel = velrange[0] | |
1261 |
|
1283 | |||
1262 | if maxVel == None: |
|
1284 | if maxVel == None: | |
1263 | maxVel = velrange[-1] |
|
1285 | maxVel = velrange[-1] | |
1264 |
|
1286 | |||
1265 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
1287 | if (minVel < velrange[0]) or (minVel > maxVel): | |
1266 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
1288 | print 'minVel: %.2f is out of the velocity range'%(minVel) | |
1267 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
1289 | print 'minVel is setting to %.2f'%(velrange[0]) | |
1268 | minVel = velrange[0] |
|
1290 | minVel = velrange[0] | |
1269 |
|
1291 | |||
1270 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
1292 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
1271 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
1293 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) | |
1272 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
1294 | print 'maxVel is setting to %.2f'%(velrange[-1]) | |
1273 | maxVel = velrange[-1] |
|
1295 | maxVel = velrange[-1] | |
1274 |
|
1296 | |||
1275 | # seleccion de indices para rango |
|
1297 | # seleccion de indices para rango | |
1276 | minIndex = 0 |
|
1298 | minIndex = 0 | |
1277 | maxIndex = 0 |
|
1299 | maxIndex = 0 | |
1278 | heights = self.dataOut.heightList |
|
1300 | heights = self.dataOut.heightList | |
1279 |
|
1301 | |||
1280 | inda = numpy.where(heights >= minHei) |
|
1302 | inda = numpy.where(heights >= minHei) | |
1281 | indb = numpy.where(heights <= maxHei) |
|
1303 | indb = numpy.where(heights <= maxHei) | |
1282 |
|
1304 | |||
1283 | try: |
|
1305 | try: | |
1284 | minIndex = inda[0][0] |
|
1306 | minIndex = inda[0][0] | |
1285 | except: |
|
1307 | except: | |
1286 | minIndex = 0 |
|
1308 | minIndex = 0 | |
1287 |
|
1309 | |||
1288 | try: |
|
1310 | try: | |
1289 | maxIndex = indb[0][-1] |
|
1311 | maxIndex = indb[0][-1] | |
1290 | except: |
|
1312 | except: | |
1291 | maxIndex = len(heights) |
|
1313 | maxIndex = len(heights) | |
1292 |
|
1314 | |||
1293 | if (minIndex < 0) or (minIndex > maxIndex): |
|
1315 | if (minIndex < 0) or (minIndex > maxIndex): | |
1294 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
1316 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
1295 |
|
1317 | |||
1296 | if (maxIndex >= self.dataOut.nHeights): |
|
1318 | if (maxIndex >= self.dataOut.nHeights): | |
1297 | maxIndex = self.dataOut.nHeights-1 |
|
1319 | maxIndex = self.dataOut.nHeights-1 | |
1298 |
|
1320 | |||
1299 | # seleccion de indices para velocidades |
|
1321 | # seleccion de indices para velocidades | |
1300 | indminvel = numpy.where(velrange >= minVel) |
|
1322 | indminvel = numpy.where(velrange >= minVel) | |
1301 | indmaxvel = numpy.where(velrange <= maxVel) |
|
1323 | indmaxvel = numpy.where(velrange <= maxVel) | |
1302 | try: |
|
1324 | try: | |
1303 | minIndexVel = indminvel[0][0] |
|
1325 | minIndexVel = indminvel[0][0] | |
1304 | except: |
|
1326 | except: | |
1305 | minIndexVel = 0 |
|
1327 | minIndexVel = 0 | |
1306 |
|
1328 | |||
1307 | try: |
|
1329 | try: | |
1308 | maxIndexVel = indmaxvel[0][-1] |
|
1330 | maxIndexVel = indmaxvel[0][-1] | |
1309 | except: |
|
1331 | except: | |
1310 | maxIndexVel = len(velrange) |
|
1332 | maxIndexVel = len(velrange) | |
1311 |
|
1333 | |||
1312 | #seleccion del espectro |
|
1334 | #seleccion del espectro | |
1313 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
1335 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] | |
1314 | #estimacion de ruido |
|
1336 | #estimacion de ruido | |
1315 | noise = numpy.zeros(self.dataOut.nChannels) |
|
1337 | noise = numpy.zeros(self.dataOut.nChannels) | |
1316 |
|
1338 | |||
1317 | for channel in range(self.dataOut.nChannels): |
|
1339 | for channel in range(self.dataOut.nChannels): | |
1318 | daux = data_spc[channel,:,:] |
|
1340 | daux = data_spc[channel,:,:] | |
1319 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
1341 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
1320 |
|
1342 | |||
1321 | self.dataOut.noise = noise.copy() |
|
1343 | self.dataOut.noise = noise.copy() | |
1322 |
|
1344 | |||
1323 | return 1 |
|
1345 | return 1 | |
1324 |
|
1346 | |||
1325 |
|
1347 | |||
1326 | class IncohInt(Operation): |
|
1348 | class IncohInt(Operation): | |
1327 |
|
1349 | |||
1328 |
|
1350 | |||
1329 | __profIndex = 0 |
|
1351 | __profIndex = 0 | |
1330 | __withOverapping = False |
|
1352 | __withOverapping = False | |
1331 |
|
1353 | |||
1332 | __byTime = False |
|
1354 | __byTime = False | |
1333 | __initime = None |
|
1355 | __initime = None | |
1334 | __lastdatatime = None |
|
1356 | __lastdatatime = None | |
1335 | __integrationtime = None |
|
1357 | __integrationtime = None | |
1336 |
|
1358 | |||
1337 | __buffer_spc = None |
|
1359 | __buffer_spc = None | |
1338 | __buffer_cspc = None |
|
1360 | __buffer_cspc = None | |
1339 | __buffer_dc = None |
|
1361 | __buffer_dc = None | |
1340 |
|
1362 | |||
1341 | __dataReady = False |
|
1363 | __dataReady = False | |
1342 |
|
1364 | |||
1343 | __timeInterval = None |
|
1365 | __timeInterval = None | |
1344 |
|
1366 | |||
1345 | n = None |
|
1367 | n = None | |
1346 |
|
1368 | |||
1347 |
|
1369 | |||
1348 |
|
1370 | |||
1349 | def __init__(self): |
|
1371 | def __init__(self): | |
1350 |
|
1372 | |||
1351 | self.__isConfig = False |
|
1373 | self.__isConfig = False | |
1352 |
|
1374 | |||
1353 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1375 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
1354 | """ |
|
1376 | """ | |
1355 | Set the parameters of the integration class. |
|
1377 | Set the parameters of the integration class. | |
1356 |
|
1378 | |||
1357 | Inputs: |
|
1379 | Inputs: | |
1358 |
|
1380 | |||
1359 | n : Number of coherent integrations |
|
1381 | n : Number of coherent integrations | |
1360 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1382 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
1361 | overlapping : |
|
1383 | overlapping : | |
1362 |
|
1384 | |||
1363 | """ |
|
1385 | """ | |
1364 |
|
1386 | |||
1365 | self.__initime = None |
|
1387 | self.__initime = None | |
1366 | self.__lastdatatime = 0 |
|
1388 | self.__lastdatatime = 0 | |
1367 | self.__buffer_spc = None |
|
1389 | self.__buffer_spc = None | |
1368 | self.__buffer_cspc = None |
|
1390 | self.__buffer_cspc = None | |
1369 | self.__buffer_dc = None |
|
1391 | self.__buffer_dc = None | |
1370 | self.__dataReady = False |
|
1392 | self.__dataReady = False | |
1371 |
|
1393 | |||
1372 |
|
1394 | |||
1373 | if n == None and timeInterval == None: |
|
1395 | if n == None and timeInterval == None: | |
1374 | raise ValueError, "n or timeInterval should be specified ..." |
|
1396 | raise ValueError, "n or timeInterval should be specified ..." | |
1375 |
|
1397 | |||
1376 | if n != None: |
|
1398 | if n != None: | |
1377 | self.n = n |
|
1399 | self.n = n | |
1378 | self.__byTime = False |
|
1400 | self.__byTime = False | |
1379 | else: |
|
1401 | else: | |
1380 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line |
|
1402 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line | |
1381 | self.n = 9999 |
|
1403 | self.n = 9999 | |
1382 | self.__byTime = True |
|
1404 | self.__byTime = True | |
1383 |
|
1405 | |||
1384 | if overlapping: |
|
1406 | if overlapping: | |
1385 | self.__withOverapping = True |
|
1407 | self.__withOverapping = True | |
1386 | else: |
|
1408 | else: | |
1387 | self.__withOverapping = False |
|
1409 | self.__withOverapping = False | |
1388 | self.__buffer_spc = 0 |
|
1410 | self.__buffer_spc = 0 | |
1389 | self.__buffer_cspc = 0 |
|
1411 | self.__buffer_cspc = 0 | |
1390 | self.__buffer_dc = 0 |
|
1412 | self.__buffer_dc = 0 | |
1391 |
|
1413 | |||
1392 | self.__profIndex = 0 |
|
1414 | self.__profIndex = 0 | |
1393 |
|
1415 | |||
1394 | def putData(self, data_spc, data_cspc, data_dc): |
|
1416 | def putData(self, data_spc, data_cspc, data_dc): | |
1395 |
|
1417 | |||
1396 | """ |
|
1418 | """ | |
1397 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
1419 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
1398 |
|
1420 | |||
1399 | """ |
|
1421 | """ | |
1400 |
|
1422 | |||
1401 | if not self.__withOverapping: |
|
1423 | if not self.__withOverapping: | |
1402 | self.__buffer_spc += data_spc |
|
1424 | self.__buffer_spc += data_spc | |
1403 |
|
1425 | |||
1404 | if data_cspc == None: |
|
1426 | if data_cspc == None: | |
1405 | self.__buffer_cspc = None |
|
1427 | self.__buffer_cspc = None | |
1406 | else: |
|
1428 | else: | |
1407 | self.__buffer_cspc += data_cspc |
|
1429 | self.__buffer_cspc += data_cspc | |
1408 |
|
1430 | |||
1409 | if data_dc == None: |
|
1431 | if data_dc == None: | |
1410 | self.__buffer_dc = None |
|
1432 | self.__buffer_dc = None | |
1411 | else: |
|
1433 | else: | |
1412 | self.__buffer_dc += data_dc |
|
1434 | self.__buffer_dc += data_dc | |
1413 |
|
1435 | |||
1414 | self.__profIndex += 1 |
|
1436 | self.__profIndex += 1 | |
1415 | return |
|
1437 | return | |
1416 |
|
1438 | |||
1417 | #Overlapping data |
|
1439 | #Overlapping data | |
1418 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
1440 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
1419 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
1441 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) | |
1420 | if data_cspc != None: |
|
1442 | if data_cspc != None: | |
1421 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
1443 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) | |
1422 | if data_dc != None: |
|
1444 | if data_dc != None: | |
1423 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
1445 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) | |
1424 |
|
1446 | |||
1425 | #If the buffer is empty then it takes the data value |
|
1447 | #If the buffer is empty then it takes the data value | |
1426 | if self.__buffer_spc == None: |
|
1448 | if self.__buffer_spc == None: | |
1427 | self.__buffer_spc = data_spc |
|
1449 | self.__buffer_spc = data_spc | |
1428 |
|
1450 | |||
1429 | if data_cspc == None: |
|
1451 | if data_cspc == None: | |
1430 | self.__buffer_cspc = None |
|
1452 | self.__buffer_cspc = None | |
1431 | else: |
|
1453 | else: | |
1432 | self.__buffer_cspc += data_cspc |
|
1454 | self.__buffer_cspc += data_cspc | |
1433 |
|
1455 | |||
1434 | if data_dc == None: |
|
1456 | if data_dc == None: | |
1435 | self.__buffer_dc = None |
|
1457 | self.__buffer_dc = None | |
1436 | else: |
|
1458 | else: | |
1437 | self.__buffer_dc += data_dc |
|
1459 | self.__buffer_dc += data_dc | |
1438 |
|
1460 | |||
1439 | self.__profIndex += 1 |
|
1461 | self.__profIndex += 1 | |
1440 | return |
|
1462 | return | |
1441 |
|
1463 | |||
1442 | #If the buffer length is lower than n then stakcing the data value |
|
1464 | #If the buffer length is lower than n then stakcing the data value | |
1443 | if self.__profIndex < self.n: |
|
1465 | if self.__profIndex < self.n: | |
1444 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
1466 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) | |
1445 |
|
1467 | |||
1446 | if data_cspc != None: |
|
1468 | if data_cspc != None: | |
1447 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
1469 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) | |
1448 |
|
1470 | |||
1449 | if data_dc != None: |
|
1471 | if data_dc != None: | |
1450 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
1472 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) | |
1451 |
|
1473 | |||
1452 | self.__profIndex += 1 |
|
1474 | self.__profIndex += 1 | |
1453 | return |
|
1475 | return | |
1454 |
|
1476 | |||
1455 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1477 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
1456 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
1478 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
1457 | self.__buffer_spc[self.n-1] = data_spc |
|
1479 | self.__buffer_spc[self.n-1] = data_spc | |
1458 |
|
1480 | |||
1459 | if data_cspc != None: |
|
1481 | if data_cspc != None: | |
1460 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
1482 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) | |
1461 | self.__buffer_cspc[self.n-1] = data_cspc |
|
1483 | self.__buffer_cspc[self.n-1] = data_cspc | |
1462 |
|
1484 | |||
1463 | if data_dc != None: |
|
1485 | if data_dc != None: | |
1464 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
1486 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) | |
1465 | self.__buffer_dc[self.n-1] = data_dc |
|
1487 | self.__buffer_dc[self.n-1] = data_dc | |
1466 |
|
1488 | |||
1467 | self.__profIndex = self.n |
|
1489 | self.__profIndex = self.n | |
1468 | return |
|
1490 | return | |
1469 |
|
1491 | |||
1470 |
|
1492 | |||
1471 | def pushData(self): |
|
1493 | def pushData(self): | |
1472 | """ |
|
1494 | """ | |
1473 | Return the sum of the last profiles and the profiles used in the sum. |
|
1495 | Return the sum of the last profiles and the profiles used in the sum. | |
1474 |
|
1496 | |||
1475 | Affected: |
|
1497 | Affected: | |
1476 |
|
1498 | |||
1477 | self.__profileIndex |
|
1499 | self.__profileIndex | |
1478 |
|
1500 | |||
1479 | """ |
|
1501 | """ | |
1480 | data_spc = None |
|
1502 | data_spc = None | |
1481 | data_cspc = None |
|
1503 | data_cspc = None | |
1482 | data_dc = None |
|
1504 | data_dc = None | |
1483 |
|
1505 | |||
1484 | if not self.__withOverapping: |
|
1506 | if not self.__withOverapping: | |
1485 | data_spc = self.__buffer_spc |
|
1507 | data_spc = self.__buffer_spc | |
1486 | data_cspc = self.__buffer_cspc |
|
1508 | data_cspc = self.__buffer_cspc | |
1487 | data_dc = self.__buffer_dc |
|
1509 | data_dc = self.__buffer_dc | |
1488 |
|
1510 | |||
1489 | n = self.__profIndex |
|
1511 | n = self.__profIndex | |
1490 |
|
1512 | |||
1491 | self.__buffer_spc = 0 |
|
1513 | self.__buffer_spc = 0 | |
1492 | self.__buffer_cspc = 0 |
|
1514 | self.__buffer_cspc = 0 | |
1493 | self.__buffer_dc = 0 |
|
1515 | self.__buffer_dc = 0 | |
1494 | self.__profIndex = 0 |
|
1516 | self.__profIndex = 0 | |
1495 |
|
1517 | |||
1496 | return data_spc, data_cspc, data_dc, n |
|
1518 | return data_spc, data_cspc, data_dc, n | |
1497 |
|
1519 | |||
1498 | #Integration with Overlapping |
|
1520 | #Integration with Overlapping | |
1499 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
1521 | data_spc = numpy.sum(self.__buffer_spc, axis=0) | |
1500 |
|
1522 | |||
1501 | if self.__buffer_cspc != None: |
|
1523 | if self.__buffer_cspc != None: | |
1502 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
1524 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) | |
1503 |
|
1525 | |||
1504 | if self.__buffer_dc != None: |
|
1526 | if self.__buffer_dc != None: | |
1505 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
1527 | data_dc = numpy.sum(self.__buffer_dc, axis=0) | |
1506 |
|
1528 | |||
1507 | n = self.__profIndex |
|
1529 | n = self.__profIndex | |
1508 |
|
1530 | |||
1509 | return data_spc, data_cspc, data_dc, n |
|
1531 | return data_spc, data_cspc, data_dc, n | |
1510 |
|
1532 | |||
1511 | def byProfiles(self, *args): |
|
1533 | def byProfiles(self, *args): | |
1512 |
|
1534 | |||
1513 | self.__dataReady = False |
|
1535 | self.__dataReady = False | |
1514 | avgdata_spc = None |
|
1536 | avgdata_spc = None | |
1515 | avgdata_cspc = None |
|
1537 | avgdata_cspc = None | |
1516 | avgdata_dc = None |
|
1538 | avgdata_dc = None | |
1517 | n = None |
|
1539 | n = None | |
1518 |
|
1540 | |||
1519 | self.putData(*args) |
|
1541 | self.putData(*args) | |
1520 |
|
1542 | |||
1521 | if self.__profIndex == self.n: |
|
1543 | if self.__profIndex == self.n: | |
1522 |
|
1544 | |||
1523 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1545 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1524 | self.__dataReady = True |
|
1546 | self.__dataReady = True | |
1525 |
|
1547 | |||
1526 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1548 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1527 |
|
1549 | |||
1528 | def byTime(self, datatime, *args): |
|
1550 | def byTime(self, datatime, *args): | |
1529 |
|
1551 | |||
1530 | self.__dataReady = False |
|
1552 | self.__dataReady = False | |
1531 | avgdata_spc = None |
|
1553 | avgdata_spc = None | |
1532 | avgdata_cspc = None |
|
1554 | avgdata_cspc = None | |
1533 | avgdata_dc = None |
|
1555 | avgdata_dc = None | |
1534 | n = None |
|
1556 | n = None | |
1535 |
|
1557 | |||
1536 | self.putData(*args) |
|
1558 | self.putData(*args) | |
1537 |
|
1559 | |||
1538 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1560 | if (datatime - self.__initime) >= self.__integrationtime: | |
1539 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1561 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1540 | self.n = n |
|
1562 | self.n = n | |
1541 | self.__dataReady = True |
|
1563 | self.__dataReady = True | |
1542 |
|
1564 | |||
1543 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1565 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1544 |
|
1566 | |||
1545 | def integrate(self, datatime, *args): |
|
1567 | def integrate(self, datatime, *args): | |
1546 |
|
1568 | |||
1547 | if self.__initime == None: |
|
1569 | if self.__initime == None: | |
1548 | self.__initime = datatime |
|
1570 | self.__initime = datatime | |
1549 |
|
1571 | |||
1550 | if self.__byTime: |
|
1572 | if self.__byTime: | |
1551 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
1573 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
1552 | else: |
|
1574 | else: | |
1553 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1575 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
1554 |
|
1576 | |||
1555 | self.__lastdatatime = datatime |
|
1577 | self.__lastdatatime = datatime | |
1556 |
|
1578 | |||
1557 | if avgdata_spc == None: |
|
1579 | if avgdata_spc == None: | |
1558 | return None, None, None, None |
|
1580 | return None, None, None, None | |
1559 |
|
1581 | |||
1560 | avgdatatime = self.__initime |
|
1582 | avgdatatime = self.__initime | |
1561 | try: |
|
1583 | try: | |
1562 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
1584 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) | |
1563 | except: |
|
1585 | except: | |
1564 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
1586 | self.__timeInterval = self.__lastdatatime - self.__initime | |
1565 |
|
1587 | |||
1566 | deltatime = datatime -self.__lastdatatime |
|
1588 | deltatime = datatime -self.__lastdatatime | |
1567 |
|
1589 | |||
1568 | if not self.__withOverapping: |
|
1590 | if not self.__withOverapping: | |
1569 | self.__initime = datatime |
|
1591 | self.__initime = datatime | |
1570 | else: |
|
1592 | else: | |
1571 | self.__initime += deltatime |
|
1593 | self.__initime += deltatime | |
1572 |
|
1594 | |||
1573 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1595 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
1574 |
|
1596 | |||
1575 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1597 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
1576 |
|
1598 | |||
1577 | if n==1: |
|
1599 | if n==1: | |
1578 | dataOut.flagNoData = False |
|
1600 | dataOut.flagNoData = False | |
1579 | return |
|
1601 | return | |
1580 |
|
1602 | |||
1581 | if not self.__isConfig: |
|
1603 | if not self.__isConfig: | |
1582 | self.setup(n, timeInterval, overlapping) |
|
1604 | self.setup(n, timeInterval, overlapping) | |
1583 | self.__isConfig = True |
|
1605 | self.__isConfig = True | |
1584 |
|
1606 | |||
1585 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1607 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
1586 | dataOut.data_spc, |
|
1608 | dataOut.data_spc, | |
1587 | dataOut.data_cspc, |
|
1609 | dataOut.data_cspc, | |
1588 | dataOut.data_dc) |
|
1610 | dataOut.data_dc) | |
1589 |
|
1611 | |||
1590 | # dataOut.timeInterval *= n |
|
1612 | # dataOut.timeInterval *= n | |
1591 | dataOut.flagNoData = True |
|
1613 | dataOut.flagNoData = True | |
1592 |
|
1614 | |||
1593 | if self.__dataReady: |
|
1615 | if self.__dataReady: | |
1594 |
|
1616 | |||
1595 | dataOut.data_spc = avgdata_spc |
|
1617 | dataOut.data_spc = avgdata_spc | |
1596 | dataOut.data_cspc = avgdata_cspc |
|
1618 | dataOut.data_cspc = avgdata_cspc | |
1597 | dataOut.data_dc = avgdata_dc |
|
1619 | dataOut.data_dc = avgdata_dc | |
1598 |
|
1620 | |||
1599 | dataOut.nIncohInt *= self.n |
|
1621 | dataOut.nIncohInt *= self.n | |
1600 | dataOut.utctime = avgdatatime |
|
1622 | dataOut.utctime = avgdatatime | |
1601 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
1623 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
1602 | dataOut.timeInterval = self.__timeInterval*self.n |
|
1624 | dataOut.timeInterval = self.__timeInterval*self.n | |
1603 | dataOut.flagNoData = False |
|
1625 | dataOut.flagNoData = False | |
1604 |
|
1626 | |||
1605 | class ProfileConcat(Operation): |
|
1627 | class ProfileConcat(Operation): | |
1606 |
|
1628 | |||
1607 | __isConfig = False |
|
1629 | __isConfig = False | |
1608 | buffer = None |
|
1630 | buffer = None | |
1609 |
|
1631 | |||
1610 | def __init__(self): |
|
1632 | def __init__(self): | |
1611 |
|
1633 | |||
1612 | self.profileIndex = 0 |
|
1634 | self.profileIndex = 0 | |
1613 |
|
1635 | |||
1614 | def reset(self): |
|
1636 | def reset(self): | |
1615 | self.buffer = numpy.zeros_like(self.buffer) |
|
1637 | self.buffer = numpy.zeros_like(self.buffer) | |
1616 | self.start_index = 0 |
|
1638 | self.start_index = 0 | |
1617 | self.times = 1 |
|
1639 | self.times = 1 | |
1618 |
|
1640 | |||
1619 | def setup(self, data, m, n=1): |
|
1641 | def setup(self, data, m, n=1): | |
1620 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
1642 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
1621 | self.profiles = data.shape[1] |
|
1643 | self.profiles = data.shape[1] | |
1622 | self.start_index = 0 |
|
1644 | self.start_index = 0 | |
1623 | self.times = 1 |
|
1645 | self.times = 1 | |
1624 |
|
1646 | |||
1625 | def concat(self, data): |
|
1647 | def concat(self, data): | |
1626 |
|
1648 | |||
1627 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() |
|
1649 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() | |
1628 | self.start_index = self.start_index + self.profiles |
|
1650 | self.start_index = self.start_index + self.profiles | |
1629 |
|
1651 | |||
1630 | def run(self, dataOut, m): |
|
1652 | def run(self, dataOut, m): | |
1631 |
|
1653 | |||
1632 | dataOut.flagNoData = True |
|
1654 | dataOut.flagNoData = True | |
1633 |
|
1655 | |||
1634 | if not self.__isConfig: |
|
1656 | if not self.__isConfig: | |
1635 | self.setup(dataOut.data, m, 1) |
|
1657 | self.setup(dataOut.data, m, 1) | |
1636 | self.__isConfig = True |
|
1658 | self.__isConfig = True | |
1637 |
|
1659 | |||
1638 | self.concat(dataOut.data) |
|
1660 | self.concat(dataOut.data) | |
1639 | self.times += 1 |
|
1661 | self.times += 1 | |
1640 | if self.times > m: |
|
1662 | if self.times > m: | |
1641 | dataOut.data = self.buffer |
|
1663 | dataOut.data = self.buffer | |
1642 | self.reset() |
|
1664 | self.reset() | |
1643 | dataOut.flagNoData = False |
|
1665 | dataOut.flagNoData = False | |
1644 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
1666 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
1645 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
1667 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
1646 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 |
|
1668 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 | |
1647 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
1669 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
1648 |
|
1670 | |||
1649 |
|
1671 | |||
1650 |
|
1672 | |||
1651 | class ProfileSelector(Operation): |
|
1673 | class ProfileSelector(Operation): | |
1652 |
|
1674 | |||
1653 | profileIndex = None |
|
1675 | profileIndex = None | |
1654 | # Tamanho total de los perfiles |
|
1676 | # Tamanho total de los perfiles | |
1655 | nProfiles = None |
|
1677 | nProfiles = None | |
1656 |
|
1678 | |||
1657 | def __init__(self): |
|
1679 | def __init__(self): | |
1658 |
|
1680 | |||
1659 | self.profileIndex = 0 |
|
1681 | self.profileIndex = 0 | |
1660 |
|
1682 | |||
1661 | def incIndex(self): |
|
1683 | def incIndex(self): | |
1662 | self.profileIndex += 1 |
|
1684 | self.profileIndex += 1 | |
1663 |
|
1685 | |||
1664 | if self.profileIndex >= self.nProfiles: |
|
1686 | if self.profileIndex >= self.nProfiles: | |
1665 | self.profileIndex = 0 |
|
1687 | self.profileIndex = 0 | |
1666 |
|
1688 | |||
1667 | def isProfileInRange(self, minIndex, maxIndex): |
|
1689 | def isProfileInRange(self, minIndex, maxIndex): | |
1668 |
|
1690 | |||
1669 | if self.profileIndex < minIndex: |
|
1691 | if self.profileIndex < minIndex: | |
1670 | return False |
|
1692 | return False | |
1671 |
|
1693 | |||
1672 | if self.profileIndex > maxIndex: |
|
1694 | if self.profileIndex > maxIndex: | |
1673 | return False |
|
1695 | return False | |
1674 |
|
1696 | |||
1675 | return True |
|
1697 | return True | |
1676 |
|
1698 | |||
1677 | def isProfileInList(self, profileList): |
|
1699 | def isProfileInList(self, profileList): | |
1678 |
|
1700 | |||
1679 | if self.profileIndex not in profileList: |
|
1701 | if self.profileIndex not in profileList: | |
1680 | return False |
|
1702 | return False | |
1681 |
|
1703 | |||
1682 | return True |
|
1704 | return True | |
1683 |
|
1705 | |||
1684 | def run(self, dataOut, profileList=None, profileRangeList=None): |
|
1706 | def run(self, dataOut, profileList=None, profileRangeList=None): | |
1685 |
|
1707 | |||
1686 | dataOut.flagNoData = True |
|
1708 | dataOut.flagNoData = True | |
1687 | self.nProfiles = dataOut.nProfiles |
|
1709 | self.nProfiles = dataOut.nProfiles | |
1688 |
|
1710 | |||
1689 | if profileList != None: |
|
1711 | if profileList != None: | |
1690 | if self.isProfileInList(profileList): |
|
1712 | if self.isProfileInList(profileList): | |
1691 | dataOut.flagNoData = False |
|
1713 | dataOut.flagNoData = False | |
1692 |
|
1714 | |||
1693 | self.incIndex() |
|
1715 | self.incIndex() | |
1694 | return 1 |
|
1716 | return 1 | |
1695 |
|
1717 | |||
1696 |
|
1718 | |||
1697 | elif profileRangeList != None: |
|
1719 | elif profileRangeList != None: | |
1698 | minIndex = profileRangeList[0] |
|
1720 | minIndex = profileRangeList[0] | |
1699 | maxIndex = profileRangeList[1] |
|
1721 | maxIndex = profileRangeList[1] | |
1700 | if self.isProfileInRange(minIndex, maxIndex): |
|
1722 | if self.isProfileInRange(minIndex, maxIndex): | |
1701 | dataOut.flagNoData = False |
|
1723 | dataOut.flagNoData = False | |
1702 |
|
1724 | |||
1703 | self.incIndex() |
|
1725 | self.incIndex() | |
1704 | return 1 |
|
1726 | return 1 | |
1705 |
|
1727 | |||
1706 | else: |
|
1728 | else: | |
1707 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
1729 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
1708 |
|
1730 | |||
1709 | return 0 |
|
1731 | return 0 | |
1710 |
|
1732 | |||
1711 | class SpectraHeisProc(ProcessingUnit): |
|
1733 | class SpectraHeisProc(ProcessingUnit): | |
1712 | def __init__(self): |
|
1734 | def __init__(self): | |
1713 | self.objectDict = {} |
|
1735 | self.objectDict = {} | |
1714 | # self.buffer = None |
|
1736 | # self.buffer = None | |
1715 | # self.firstdatatime = None |
|
1737 | # self.firstdatatime = None | |
1716 | # self.profIndex = 0 |
|
1738 | # self.profIndex = 0 | |
1717 | self.dataOut = SpectraHeis() |
|
1739 | self.dataOut = SpectraHeis() | |
1718 |
|
1740 | |||
1719 | def __updateObjFromInput(self): |
|
1741 | def __updateObjFromInput(self): | |
1720 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1742 | self.dataOut.timeZone = self.dataIn.timeZone | |
1721 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
1743 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
1722 | self.dataOut.errorCount = self.dataIn.errorCount |
|
1744 | self.dataOut.errorCount = self.dataIn.errorCount | |
1723 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
1745 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
1724 |
|
1746 | |||
1725 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# |
|
1747 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# | |
1726 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# |
|
1748 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# | |
1727 | self.dataOut.channelList = self.dataIn.channelList |
|
1749 | self.dataOut.channelList = self.dataIn.channelList | |
1728 | self.dataOut.heightList = self.dataIn.heightList |
|
1750 | self.dataOut.heightList = self.dataIn.heightList | |
1729 | # self.dataOut.dtype = self.dataIn.dtype |
|
1751 | # self.dataOut.dtype = self.dataIn.dtype | |
1730 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1752 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1731 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
1753 | # self.dataOut.nHeights = self.dataIn.nHeights | |
1732 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
1754 | # self.dataOut.nChannels = self.dataIn.nChannels | |
1733 | self.dataOut.nBaud = self.dataIn.nBaud |
|
1755 | self.dataOut.nBaud = self.dataIn.nBaud | |
1734 | self.dataOut.nCode = self.dataIn.nCode |
|
1756 | self.dataOut.nCode = self.dataIn.nCode | |
1735 | self.dataOut.code = self.dataIn.code |
|
1757 | self.dataOut.code = self.dataIn.code | |
1736 | # self.dataOut.nProfiles = 1 |
|
1758 | # self.dataOut.nProfiles = 1 | |
1737 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
1759 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
1738 | self.dataOut.nFFTPoints = self.dataIn.nHeights |
|
1760 | self.dataOut.nFFTPoints = self.dataIn.nHeights | |
1739 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1761 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
1740 | # self.dataOut.flagNoData = self.dataIn.flagNoData |
|
1762 | # self.dataOut.flagNoData = self.dataIn.flagNoData | |
1741 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
1763 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
1742 | self.dataOut.utctime = self.dataIn.utctime |
|
1764 | self.dataOut.utctime = self.dataIn.utctime | |
1743 | # self.dataOut.utctime = self.firstdatatime |
|
1765 | # self.dataOut.utctime = self.firstdatatime | |
1744 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
1766 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
1745 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
1767 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
1746 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
1768 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
1747 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
1769 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
1748 | self.dataOut.nIncohInt = 1 |
|
1770 | self.dataOut.nIncohInt = 1 | |
1749 | self.dataOut.ippSeconds= self.dataIn.ippSeconds |
|
1771 | self.dataOut.ippSeconds= self.dataIn.ippSeconds | |
1750 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
1772 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
1751 |
|
1773 | |||
1752 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt |
|
1774 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt | |
1753 | # self.dataOut.set=self.dataIn.set |
|
1775 | # self.dataOut.set=self.dataIn.set | |
1754 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight |
|
1776 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight | |
1755 |
|
1777 | |||
1756 |
|
1778 | |||
1757 | def __updateObjFromFits(self): |
|
1779 | def __updateObjFromFits(self): | |
1758 | self.dataOut.utctime = self.dataIn.utctime |
|
1780 | self.dataOut.utctime = self.dataIn.utctime | |
1759 | self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1781 | self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
1760 |
|
1782 | |||
1761 | self.dataOut.channelList = self.dataIn.channelList |
|
1783 | self.dataOut.channelList = self.dataIn.channelList | |
1762 | self.dataOut.heightList = self.dataIn.heightList |
|
1784 | self.dataOut.heightList = self.dataIn.heightList | |
1763 | self.dataOut.data_spc = self.dataIn.data |
|
1785 | self.dataOut.data_spc = self.dataIn.data | |
1764 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
1786 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
1765 | self.dataOut.timeZone = self.dataIn.timeZone |
|
1787 | self.dataOut.timeZone = self.dataIn.timeZone | |
1766 | self.dataOut.useLocalTime = True |
|
1788 | self.dataOut.useLocalTime = True | |
1767 | # self.dataOut. |
|
1789 | # self.dataOut. | |
1768 | # self.dataOut. |
|
1790 | # self.dataOut. | |
1769 |
|
1791 | |||
1770 | def __getFft(self): |
|
1792 | def __getFft(self): | |
1771 |
|
1793 | |||
1772 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) |
|
1794 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) | |
1773 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
1795 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
1774 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) |
|
1796 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) | |
1775 | self.dataOut.data_spc = spc |
|
1797 | self.dataOut.data_spc = spc | |
1776 |
|
1798 | |||
1777 | def init(self): |
|
1799 | def init(self): | |
1778 |
|
1800 | |||
1779 | self.dataOut.flagNoData = True |
|
1801 | self.dataOut.flagNoData = True | |
1780 |
|
1802 | |||
1781 | if self.dataIn.type == "Fits": |
|
1803 | if self.dataIn.type == "Fits": | |
1782 | self.__updateObjFromFits() |
|
1804 | self.__updateObjFromFits() | |
1783 | self.dataOut.flagNoData = False |
|
1805 | self.dataOut.flagNoData = False | |
1784 | return |
|
1806 | return | |
1785 |
|
1807 | |||
1786 | if self.dataIn.type == "SpectraHeis": |
|
1808 | if self.dataIn.type == "SpectraHeis": | |
1787 | self.dataOut.copy(self.dataIn) |
|
1809 | self.dataOut.copy(self.dataIn) | |
1788 | return |
|
1810 | return | |
1789 |
|
1811 | |||
1790 | if self.dataIn.type == "Voltage": |
|
1812 | if self.dataIn.type == "Voltage": | |
1791 | self.__updateObjFromInput() |
|
1813 | self.__updateObjFromInput() | |
1792 | self.__getFft() |
|
1814 | self.__getFft() | |
1793 | self.dataOut.flagNoData = False |
|
1815 | self.dataOut.flagNoData = False | |
1794 |
|
1816 | |||
1795 | return |
|
1817 | return | |
1796 |
|
1818 | |||
1797 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
1819 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) | |
1798 |
|
1820 | |||
1799 |
|
1821 | |||
1800 | def selectChannels(self, channelList): |
|
1822 | def selectChannels(self, channelList): | |
1801 |
|
1823 | |||
1802 | channelIndexList = [] |
|
1824 | channelIndexList = [] | |
1803 |
|
1825 | |||
1804 | for channel in channelList: |
|
1826 | for channel in channelList: | |
1805 | index = self.dataOut.channelList.index(channel) |
|
1827 | index = self.dataOut.channelList.index(channel) | |
1806 | channelIndexList.append(index) |
|
1828 | channelIndexList.append(index) | |
1807 |
|
1829 | |||
1808 | self.selectChannelsByIndex(channelIndexList) |
|
1830 | self.selectChannelsByIndex(channelIndexList) | |
1809 |
|
1831 | |||
1810 | def selectChannelsByIndex(self, channelIndexList): |
|
1832 | def selectChannelsByIndex(self, channelIndexList): | |
1811 | """ |
|
1833 | """ | |
1812 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
1834 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
1813 |
|
1835 | |||
1814 | Input: |
|
1836 | Input: | |
1815 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
1837 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
1816 |
|
1838 | |||
1817 | Affected: |
|
1839 | Affected: | |
1818 | self.dataOut.data |
|
1840 | self.dataOut.data | |
1819 | self.dataOut.channelIndexList |
|
1841 | self.dataOut.channelIndexList | |
1820 | self.dataOut.nChannels |
|
1842 | self.dataOut.nChannels | |
1821 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
1843 | self.dataOut.m_ProcessingHeader.totalSpectra | |
1822 | self.dataOut.systemHeaderObj.numChannels |
|
1844 | self.dataOut.systemHeaderObj.numChannels | |
1823 | self.dataOut.m_ProcessingHeader.blockSize |
|
1845 | self.dataOut.m_ProcessingHeader.blockSize | |
1824 |
|
1846 | |||
1825 | Return: |
|
1847 | Return: | |
1826 | None |
|
1848 | None | |
1827 | """ |
|
1849 | """ | |
1828 |
|
1850 | |||
1829 | for channelIndex in channelIndexList: |
|
1851 | for channelIndex in channelIndexList: | |
1830 | if channelIndex not in self.dataOut.channelIndexList: |
|
1852 | if channelIndex not in self.dataOut.channelIndexList: | |
1831 | print channelIndexList |
|
1853 | print channelIndexList | |
1832 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
1854 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
1833 |
|
1855 | |||
1834 | nChannels = len(channelIndexList) |
|
1856 | nChannels = len(channelIndexList) | |
1835 |
|
1857 | |||
1836 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
1858 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
1837 |
|
1859 | |||
1838 | self.dataOut.data_spc = data_spc |
|
1860 | self.dataOut.data_spc = data_spc | |
1839 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
1861 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
1840 |
|
1862 | |||
1841 | return 1 |
|
1863 | return 1 | |
1842 |
|
1864 | |||
1843 | class IncohInt4SpectraHeis(Operation): |
|
1865 | class IncohInt4SpectraHeis(Operation): | |
1844 |
|
1866 | |||
1845 | __isConfig = False |
|
1867 | __isConfig = False | |
1846 |
|
1868 | |||
1847 | __profIndex = 0 |
|
1869 | __profIndex = 0 | |
1848 | __withOverapping = False |
|
1870 | __withOverapping = False | |
1849 |
|
1871 | |||
1850 | __byTime = False |
|
1872 | __byTime = False | |
1851 | __initime = None |
|
1873 | __initime = None | |
1852 | __lastdatatime = None |
|
1874 | __lastdatatime = None | |
1853 | __integrationtime = None |
|
1875 | __integrationtime = None | |
1854 |
|
1876 | |||
1855 | __buffer = None |
|
1877 | __buffer = None | |
1856 |
|
1878 | |||
1857 | __dataReady = False |
|
1879 | __dataReady = False | |
1858 |
|
1880 | |||
1859 | n = None |
|
1881 | n = None | |
1860 |
|
1882 | |||
1861 |
|
1883 | |||
1862 | def __init__(self): |
|
1884 | def __init__(self): | |
1863 |
|
1885 | |||
1864 | self.__isConfig = False |
|
1886 | self.__isConfig = False | |
1865 |
|
1887 | |||
1866 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1888 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
1867 | """ |
|
1889 | """ | |
1868 | Set the parameters of the integration class. |
|
1890 | Set the parameters of the integration class. | |
1869 |
|
1891 | |||
1870 | Inputs: |
|
1892 | Inputs: | |
1871 |
|
1893 | |||
1872 | n : Number of coherent integrations |
|
1894 | n : Number of coherent integrations | |
1873 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1895 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
1874 | overlapping : |
|
1896 | overlapping : | |
1875 |
|
1897 | |||
1876 | """ |
|
1898 | """ | |
1877 |
|
1899 | |||
1878 | self.__initime = None |
|
1900 | self.__initime = None | |
1879 | self.__lastdatatime = 0 |
|
1901 | self.__lastdatatime = 0 | |
1880 | self.__buffer = None |
|
1902 | self.__buffer = None | |
1881 | self.__dataReady = False |
|
1903 | self.__dataReady = False | |
1882 |
|
1904 | |||
1883 |
|
1905 | |||
1884 | if n == None and timeInterval == None: |
|
1906 | if n == None and timeInterval == None: | |
1885 | raise ValueError, "n or timeInterval should be specified ..." |
|
1907 | raise ValueError, "n or timeInterval should be specified ..." | |
1886 |
|
1908 | |||
1887 | if n != None: |
|
1909 | if n != None: | |
1888 | self.n = n |
|
1910 | self.n = n | |
1889 | self.__byTime = False |
|
1911 | self.__byTime = False | |
1890 | else: |
|
1912 | else: | |
1891 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
1913 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
1892 | self.n = 9999 |
|
1914 | self.n = 9999 | |
1893 | self.__byTime = True |
|
1915 | self.__byTime = True | |
1894 |
|
1916 | |||
1895 | if overlapping: |
|
1917 | if overlapping: | |
1896 | self.__withOverapping = True |
|
1918 | self.__withOverapping = True | |
1897 | self.__buffer = None |
|
1919 | self.__buffer = None | |
1898 | else: |
|
1920 | else: | |
1899 | self.__withOverapping = False |
|
1921 | self.__withOverapping = False | |
1900 | self.__buffer = 0 |
|
1922 | self.__buffer = 0 | |
1901 |
|
1923 | |||
1902 | self.__profIndex = 0 |
|
1924 | self.__profIndex = 0 | |
1903 |
|
1925 | |||
1904 | def putData(self, data): |
|
1926 | def putData(self, data): | |
1905 |
|
1927 | |||
1906 | """ |
|
1928 | """ | |
1907 | Add a profile to the __buffer and increase in one the __profileIndex |
|
1929 | Add a profile to the __buffer and increase in one the __profileIndex | |
1908 |
|
1930 | |||
1909 | """ |
|
1931 | """ | |
1910 |
|
1932 | |||
1911 | if not self.__withOverapping: |
|
1933 | if not self.__withOverapping: | |
1912 | self.__buffer += data.copy() |
|
1934 | self.__buffer += data.copy() | |
1913 | self.__profIndex += 1 |
|
1935 | self.__profIndex += 1 | |
1914 | return |
|
1936 | return | |
1915 |
|
1937 | |||
1916 | #Overlapping data |
|
1938 | #Overlapping data | |
1917 | nChannels, nHeis = data.shape |
|
1939 | nChannels, nHeis = data.shape | |
1918 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
1940 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
1919 |
|
1941 | |||
1920 | #If the buffer is empty then it takes the data value |
|
1942 | #If the buffer is empty then it takes the data value | |
1921 | if self.__buffer == None: |
|
1943 | if self.__buffer == None: | |
1922 | self.__buffer = data |
|
1944 | self.__buffer = data | |
1923 | self.__profIndex += 1 |
|
1945 | self.__profIndex += 1 | |
1924 | return |
|
1946 | return | |
1925 |
|
1947 | |||
1926 | #If the buffer length is lower than n then stakcing the data value |
|
1948 | #If the buffer length is lower than n then stakcing the data value | |
1927 | if self.__profIndex < self.n: |
|
1949 | if self.__profIndex < self.n: | |
1928 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
1950 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
1929 | self.__profIndex += 1 |
|
1951 | self.__profIndex += 1 | |
1930 | return |
|
1952 | return | |
1931 |
|
1953 | |||
1932 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1954 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
1933 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
1955 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
1934 | self.__buffer[self.n-1] = data |
|
1956 | self.__buffer[self.n-1] = data | |
1935 | self.__profIndex = self.n |
|
1957 | self.__profIndex = self.n | |
1936 | return |
|
1958 | return | |
1937 |
|
1959 | |||
1938 |
|
1960 | |||
1939 | def pushData(self): |
|
1961 | def pushData(self): | |
1940 | """ |
|
1962 | """ | |
1941 | Return the sum of the last profiles and the profiles used in the sum. |
|
1963 | Return the sum of the last profiles and the profiles used in the sum. | |
1942 |
|
1964 | |||
1943 | Affected: |
|
1965 | Affected: | |
1944 |
|
1966 | |||
1945 | self.__profileIndex |
|
1967 | self.__profileIndex | |
1946 |
|
1968 | |||
1947 | """ |
|
1969 | """ | |
1948 |
|
1970 | |||
1949 | if not self.__withOverapping: |
|
1971 | if not self.__withOverapping: | |
1950 | data = self.__buffer |
|
1972 | data = self.__buffer | |
1951 | n = self.__profIndex |
|
1973 | n = self.__profIndex | |
1952 |
|
1974 | |||
1953 | self.__buffer = 0 |
|
1975 | self.__buffer = 0 | |
1954 | self.__profIndex = 0 |
|
1976 | self.__profIndex = 0 | |
1955 |
|
1977 | |||
1956 | return data, n |
|
1978 | return data, n | |
1957 |
|
1979 | |||
1958 | #Integration with Overlapping |
|
1980 | #Integration with Overlapping | |
1959 | data = numpy.sum(self.__buffer, axis=0) |
|
1981 | data = numpy.sum(self.__buffer, axis=0) | |
1960 | n = self.__profIndex |
|
1982 | n = self.__profIndex | |
1961 |
|
1983 | |||
1962 | return data, n |
|
1984 | return data, n | |
1963 |
|
1985 | |||
1964 | def byProfiles(self, data): |
|
1986 | def byProfiles(self, data): | |
1965 |
|
1987 | |||
1966 | self.__dataReady = False |
|
1988 | self.__dataReady = False | |
1967 | avgdata = None |
|
1989 | avgdata = None | |
1968 | n = None |
|
1990 | n = None | |
1969 |
|
1991 | |||
1970 | self.putData(data) |
|
1992 | self.putData(data) | |
1971 |
|
1993 | |||
1972 | if self.__profIndex == self.n: |
|
1994 | if self.__profIndex == self.n: | |
1973 |
|
1995 | |||
1974 | avgdata, n = self.pushData() |
|
1996 | avgdata, n = self.pushData() | |
1975 | self.__dataReady = True |
|
1997 | self.__dataReady = True | |
1976 |
|
1998 | |||
1977 | return avgdata |
|
1999 | return avgdata | |
1978 |
|
2000 | |||
1979 | def byTime(self, data, datatime): |
|
2001 | def byTime(self, data, datatime): | |
1980 |
|
2002 | |||
1981 | self.__dataReady = False |
|
2003 | self.__dataReady = False | |
1982 | avgdata = None |
|
2004 | avgdata = None | |
1983 | n = None |
|
2005 | n = None | |
1984 |
|
2006 | |||
1985 | self.putData(data) |
|
2007 | self.putData(data) | |
1986 |
|
2008 | |||
1987 | if (datatime - self.__initime) >= self.__integrationtime: |
|
2009 | if (datatime - self.__initime) >= self.__integrationtime: | |
1988 | avgdata, n = self.pushData() |
|
2010 | avgdata, n = self.pushData() | |
1989 | self.n = n |
|
2011 | self.n = n | |
1990 | self.__dataReady = True |
|
2012 | self.__dataReady = True | |
1991 |
|
2013 | |||
1992 | return avgdata |
|
2014 | return avgdata | |
1993 |
|
2015 | |||
1994 | def integrate(self, data, datatime=None): |
|
2016 | def integrate(self, data, datatime=None): | |
1995 |
|
2017 | |||
1996 | if self.__initime == None: |
|
2018 | if self.__initime == None: | |
1997 | self.__initime = datatime |
|
2019 | self.__initime = datatime | |
1998 |
|
2020 | |||
1999 | if self.__byTime: |
|
2021 | if self.__byTime: | |
2000 | avgdata = self.byTime(data, datatime) |
|
2022 | avgdata = self.byTime(data, datatime) | |
2001 | else: |
|
2023 | else: | |
2002 | avgdata = self.byProfiles(data) |
|
2024 | avgdata = self.byProfiles(data) | |
2003 |
|
2025 | |||
2004 |
|
2026 | |||
2005 | self.__lastdatatime = datatime |
|
2027 | self.__lastdatatime = datatime | |
2006 |
|
2028 | |||
2007 | if avgdata == None: |
|
2029 | if avgdata == None: | |
2008 | return None, None |
|
2030 | return None, None | |
2009 |
|
2031 | |||
2010 | avgdatatime = self.__initime |
|
2032 | avgdatatime = self.__initime | |
2011 |
|
2033 | |||
2012 | deltatime = datatime -self.__lastdatatime |
|
2034 | deltatime = datatime -self.__lastdatatime | |
2013 |
|
2035 | |||
2014 | if not self.__withOverapping: |
|
2036 | if not self.__withOverapping: | |
2015 | self.__initime = datatime |
|
2037 | self.__initime = datatime | |
2016 | else: |
|
2038 | else: | |
2017 | self.__initime += deltatime |
|
2039 | self.__initime += deltatime | |
2018 |
|
2040 | |||
2019 | return avgdata, avgdatatime |
|
2041 | return avgdata, avgdatatime | |
2020 |
|
2042 | |||
2021 | def run(self, dataOut, **kwargs): |
|
2043 | def run(self, dataOut, **kwargs): | |
2022 |
|
2044 | |||
2023 | if not self.__isConfig: |
|
2045 | if not self.__isConfig: | |
2024 | self.setup(**kwargs) |
|
2046 | self.setup(**kwargs) | |
2025 | self.__isConfig = True |
|
2047 | self.__isConfig = True | |
2026 |
|
2048 | |||
2027 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
2049 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) | |
2028 |
|
2050 | |||
2029 | # dataOut.timeInterval *= n |
|
2051 | # dataOut.timeInterval *= n | |
2030 | dataOut.flagNoData = True |
|
2052 | dataOut.flagNoData = True | |
2031 |
|
2053 | |||
2032 | if self.__dataReady: |
|
2054 | if self.__dataReady: | |
2033 | dataOut.data_spc = avgdata |
|
2055 | dataOut.data_spc = avgdata | |
2034 | dataOut.nIncohInt *= self.n |
|
2056 | dataOut.nIncohInt *= self.n | |
2035 | # dataOut.nCohInt *= self.n |
|
2057 | # dataOut.nCohInt *= self.n | |
2036 | dataOut.utctime = avgdatatime |
|
2058 | dataOut.utctime = avgdatatime | |
2037 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt |
|
2059 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt | |
2038 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
2060 | # dataOut.timeInterval = self.__timeInterval*self.n | |
2039 | dataOut.flagNoData = False |
|
2061 | dataOut.flagNoData = False | |
2040 |
|
2062 | |||
2041 |
|
2063 | |||
2042 |
|
2064 | |||
2043 |
|
2065 | |||
2044 | No newline at end of file |
|
2066 |
@@ -1,118 +1,121 | |||||
1 | import os, sys |
|
1 | import os, sys | |
2 |
|
2 | |||
3 | path = os.path.split(os.getcwd())[0] |
|
3 | path = os.path.split(os.getcwd())[0] | |
4 | sys.path.append(path) |
|
4 | sys.path.append(path) | |
5 |
|
5 | |||
6 | from controller import * |
|
6 | from controller import * | |
7 |
|
7 | |||
8 | desc = "EWDrifts Experiment Test" |
|
8 | desc = "EWDrifts Experiment Test" | |
9 | filename = "ewdrifts2.xml" |
|
9 | filename = "ewdrifts2.xml" | |
10 |
|
10 | |||
11 | controllerObj = Project() |
|
11 | controllerObj = Project() | |
12 |
|
12 | |||
13 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
13 | controllerObj.setup(id = '191', name='test01', description=desc) | |
14 |
|
14 | |||
15 | path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift' |
|
15 | path='/remote/ewdrifts/RAW_EXP/EW_DRIFT_FARADAY/EW_Drift' | |
16 |
|
16 | |||
17 | path = '/Users/dsuarez/Documents/Radar/drifts' |
|
17 | path = '/Users/dsuarez/Documents/Radar/drifts' | |
18 | path = '/Users/dsuarez/Documents/EW_DRIFT_WITH_TR' |
|
18 | path = '/Users/dsuarez/Documents/EW_DRIFT_WITH_TR' | |
|
19 | path = '/home/administrator/Radar/drifts/2014' | |||
19 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
20 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', | |
20 | path=path, |
|
21 | path=path, | |
21 |
startDate='201 |
|
22 | startDate='2014/01/11', | |
22 |
endDate='201 |
|
23 | endDate='2014/12/12', | |
23 |
startTime=' |
|
24 | startTime='00:00:00', | |
24 | endTime='23:59:59', |
|
25 | endTime='23:59:59', | |
25 | online=0, |
|
26 | online=0, | |
26 | delay=5, |
|
27 | delay=5, | |
27 | walk=0) |
|
28 | walk=0) | |
28 |
|
29 | |||
29 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
30 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) | |
30 |
|
31 | |||
31 |
opObj11 = procUnitConfObj0.addOperation(name=' |
|
32 | opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='other') | |
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') |
|
|||
60 | opObj11.addParameter(name='id', value='101', format='int') |
|
33 | opObj11.addParameter(name='id', value='101', format='int') | |
61 |
opObj11.addParameter(name='wintitle', value=' |
|
34 | opObj11.addParameter(name='wintitle', value='AMISR', format='str') | |
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 |
|
||||
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 | #opObj11 = procUnitConfObj1.addOperation(name='PowerProfilePlot', optype='other') |
|
76 | #opObj11 = procUnitConfObj1.addOperation(name='PowerProfilePlot', optype='other') | |
74 | #opObj11.addParameter(name='idfigure', value='2', format='int') |
|
77 | #opObj11.addParameter(name='idfigure', value='2', format='int') | |
75 | #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') |
|
78 | #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') | |
76 | #opObj11.addParameter(name='save', value='1', format='bool') |
|
79 | #opObj11.addParameter(name='save', value='1', format='bool') | |
77 | #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str') |
|
80 | #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str') | |
78 | ##opObj11.addParameter(name='xmin', value='10', format='int') |
|
81 | ##opObj11.addParameter(name='xmin', value='10', format='int') | |
79 | ##opObj11.addParameter(name='xmax', value='40', format='int') |
|
82 | ##opObj11.addParameter(name='xmax', value='40', format='int') | |
80 | # |
|
83 | # | |
81 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') |
|
84 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') | |
82 | # opObj11.addParameter(name='idfigure', value='3', format='int') |
|
85 | # opObj11.addParameter(name='idfigure', value='3', format='int') | |
83 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') |
|
86 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') | |
84 | # #opObj11.addParameter(name='save', value='1', format='bool') |
|
87 | # #opObj11.addParameter(name='save', value='1', format='bool') | |
85 | # #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str') |
|
88 | # #opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/EW_DRIFTS_2012_DEC', format='str') | |
86 | # ##opObj11.addParameter(name='zmin', value='10', format='int') |
|
89 | # ##opObj11.addParameter(name='zmin', value='10', format='int') | |
87 | # ##opObj11.addParameter(name='zmax', value='40', format='int') |
|
90 | # ##opObj11.addParameter(name='zmax', value='40', format='int') | |
88 | # ##opObj11.addParameter(name='save', value='1', format='bool') |
|
91 | # ##opObj11.addParameter(name='save', value='1', format='bool') | |
89 | # ##opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/cross_spc', format='str') |
|
92 | # ##opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/cross_spc', format='str') | |
90 | # opObj11.addParameter(name='zmin', value='20', format='int') |
|
93 | # opObj11.addParameter(name='zmin', value='20', format='int') | |
91 | # opObj11.addParameter(name='zmax', value='40', format='int') |
|
94 | # opObj11.addParameter(name='zmax', value='40', format='int') | |
92 | # opObj11.addParameter(name='save', value='1', format='bool') |
|
95 | # opObj11.addParameter(name='save', value='1', format='bool') | |
93 | # opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/ew_drifts_mz', format='str') |
|
96 | # opObj11.addParameter(name='figpath', value='/home/dsuarez/Pictures/ew_drifts_mz', format='str') | |
94 | # |
|
97 | # | |
95 | # |
|
98 | # # | |
96 | opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') |
|
99 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
97 | opObj11.addParameter(name='id', value='102', format='int') |
|
100 | # opObj11.addParameter(name='id', value='102', format='int') | |
98 | opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') |
|
101 | # opObj11.addParameter(name='wintitle', value='RTIPLot', format='str') | |
99 | opObj11.addParameter(name='xmin', value='10', format='float') |
|
102 | # opObj11.addParameter(name='xmin', value='10', format='float') | |
100 | opObj11.addParameter(name='xmax', value='11.5', format='float') |
|
103 | # opObj11.addParameter(name='xmax', value='11.5', format='float') | |
101 | # opObj11.addParameter(name='zmin', value='20', format='int') |
|
104 | # # opObj11.addParameter(name='zmin', value='20', format='int') | |
102 | # opObj11.addParameter(name='zmax', value='40', format='int') |
|
105 | # # opObj11.addParameter(name='zmax', value='40', format='int') | |
103 | # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') |
|
106 | # # #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist') | |
104 | # #opObj11.addParameter(name='timerange', value='86400', format='int') |
|
107 | # # #opObj11.addParameter(name='timerange', value='86400', format='int') | |
105 | opObj11.addParameter(name='showprofile', value='0', format='int') |
|
108 | # opObj11.addParameter(name='showprofile', value='0', format='int') | |
106 | opObj11.addParameter(name='save', value='1', format='bool') |
|
109 | # opObj11.addParameter(name='save', value='1', format='bool') | |
107 | opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') |
|
110 | # opObj11.addParameter(name='figpath', value='/Users/dsuarez/Pictures/tr', format='str') | |
108 |
|
111 | |||
109 | print "Escribiendo el archivo XML" |
|
112 | print "Escribiendo el archivo XML" | |
110 | controllerObj.writeXml(filename) |
|
113 | controllerObj.writeXml(filename) | |
111 | print "Leyendo el archivo XML" |
|
114 | print "Leyendo el archivo XML" | |
112 | controllerObj.readXml(filename) |
|
115 | controllerObj.readXml(filename) | |
113 |
|
116 | |||
114 | controllerObj.createObjects() |
|
117 | controllerObj.createObjects() | |
115 | controllerObj.connectObjects() |
|
118 | controllerObj.connectObjects() | |
116 | controllerObj.run() |
|
119 | controllerObj.run() | |
117 |
|
120 | |||
118 |
|
121 |
General Comments 0
You need to be logged in to leave comments.
Login now