@@ -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,3825 +1,3836 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ |
|
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import glob |
|
8 | import glob | |
9 | import time |
|
9 | import time | |
10 | import numpy |
|
10 | import numpy | |
11 | import fnmatch |
|
11 | import fnmatch | |
12 | import time, datetime |
|
12 | import time, datetime | |
13 | import h5py |
|
13 | import h5py | |
14 | from xml.etree.ElementTree import Element, SubElement, ElementTree |
|
14 | from xml.etree.ElementTree import Element, SubElement, ElementTree | |
15 | try: |
|
15 | try: | |
16 | import pyfits |
|
16 | import pyfits | |
17 | except: |
|
17 | except: | |
18 | print "pyfits module has not been imported, it should be installed to save files in fits format" |
|
18 | print "pyfits module has not been imported, it should be installed to save files in fits format" | |
19 |
|
19 | |||
20 | from jrodata import * |
|
20 | from jrodata import * | |
21 | from jroheaderIO import * |
|
21 | from jroheaderIO import * | |
22 | from jroprocessing import * |
|
22 | from jroprocessing import * | |
23 |
|
23 | |||
24 | LOCALTIME = True #-18000 |
|
24 | LOCALTIME = True #-18000 | |
25 |
|
25 | |||
26 | def isNumber(str): |
|
26 | def isNumber(str): | |
27 | """ |
|
27 | """ | |
28 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
28 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
29 |
|
29 | |||
30 | Excepciones: |
|
30 | Excepciones: | |
31 | Si un determinado string no puede ser convertido a numero |
|
31 | Si un determinado string no puede ser convertido a numero | |
32 | Input: |
|
32 | Input: | |
33 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
33 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
34 |
|
34 | |||
35 | Return: |
|
35 | Return: | |
36 | True : si el string es uno numerico |
|
36 | True : si el string es uno numerico | |
37 | False : no es un string numerico |
|
37 | False : no es un string numerico | |
38 | """ |
|
38 | """ | |
39 | try: |
|
39 | try: | |
40 | float( str ) |
|
40 | float( str ) | |
41 | return True |
|
41 | return True | |
42 | except: |
|
42 | except: | |
43 | return False |
|
43 | return False | |
44 |
|
44 | |||
45 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
45 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
46 | """ |
|
46 | """ | |
47 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
47 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
48 |
|
48 | |||
49 | Inputs: |
|
49 | Inputs: | |
50 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
50 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
51 |
|
51 | |||
52 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
52 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
53 | segundos contados desde 01/01/1970. |
|
53 | segundos contados desde 01/01/1970. | |
54 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
54 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
55 | segundos contados desde 01/01/1970. |
|
55 | segundos contados desde 01/01/1970. | |
56 |
|
56 | |||
57 | Return: |
|
57 | Return: | |
58 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
58 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
59 | fecha especificado, de lo contrario retorna False. |
|
59 | fecha especificado, de lo contrario retorna False. | |
60 |
|
60 | |||
61 | Excepciones: |
|
61 | Excepciones: | |
62 | Si el archivo no existe o no puede ser abierto |
|
62 | Si el archivo no existe o no puede ser abierto | |
63 | Si la cabecera no puede ser leida. |
|
63 | Si la cabecera no puede ser leida. | |
64 |
|
64 | |||
65 | """ |
|
65 | """ | |
66 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
66 | basicHeaderObj = BasicHeader(LOCALTIME) | |
67 |
|
67 | |||
68 | try: |
|
68 | try: | |
69 | fp = open(filename,'rb') |
|
69 | fp = open(filename,'rb') | |
70 | except: |
|
70 | except: | |
71 | raise IOError, "The file %s can't be opened" %(filename) |
|
71 | raise IOError, "The file %s can't be opened" %(filename) | |
72 |
|
72 | |||
73 | sts = basicHeaderObj.read(fp) |
|
73 | sts = basicHeaderObj.read(fp) | |
74 | fp.close() |
|
74 | fp.close() | |
75 |
|
75 | |||
76 | if not(sts): |
|
76 | if not(sts): | |
77 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
77 | print "Skipping the file %s because it has not a valid header" %(filename) | |
78 | return 0 |
|
78 | return 0 | |
79 |
|
79 | |||
80 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
80 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
81 | return 0 |
|
81 | return 0 | |
82 |
|
82 | |||
83 | return 1 |
|
83 | return 1 | |
84 |
|
84 | |||
85 | def isFileinThisTime(filename, startTime, endTime): |
|
85 | def isFileinThisTime(filename, startTime, endTime): | |
86 | """ |
|
86 | """ | |
87 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
87 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
88 |
|
88 | |||
89 | Inputs: |
|
89 | Inputs: | |
90 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
90 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
91 |
|
91 | |||
92 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
92 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
93 |
|
93 | |||
94 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
94 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
95 |
|
95 | |||
96 | Return: |
|
96 | Return: | |
97 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
97 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
98 | fecha especificado, de lo contrario retorna False. |
|
98 | fecha especificado, de lo contrario retorna False. | |
99 |
|
99 | |||
100 | Excepciones: |
|
100 | Excepciones: | |
101 | Si el archivo no existe o no puede ser abierto |
|
101 | Si el archivo no existe o no puede ser abierto | |
102 | Si la cabecera no puede ser leida. |
|
102 | Si la cabecera no puede ser leida. | |
103 |
|
103 | |||
104 | """ |
|
104 | """ | |
105 |
|
105 | |||
106 |
|
106 | |||
107 | try: |
|
107 | try: | |
108 | fp = open(filename,'rb') |
|
108 | fp = open(filename,'rb') | |
109 | except: |
|
109 | except: | |
110 | raise IOError, "The file %s can't be opened" %(filename) |
|
110 | raise IOError, "The file %s can't be opened" %(filename) | |
111 |
|
111 | |||
112 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
112 | basicHeaderObj = BasicHeader(LOCALTIME) | |
113 | sts = basicHeaderObj.read(fp) |
|
113 | sts = basicHeaderObj.read(fp) | |
114 | fp.close() |
|
114 | fp.close() | |
115 |
|
115 | |||
116 | thisDatetime = basicHeaderObj.datatime |
|
116 | thisDatetime = basicHeaderObj.datatime | |
117 | thisTime = basicHeaderObj.datatime.time() |
|
117 | thisTime = basicHeaderObj.datatime.time() | |
118 |
|
118 | |||
119 | if not(sts): |
|
119 | if not(sts): | |
120 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
120 | print "Skipping the file %s because it has not a valid header" %(filename) | |
121 | return None |
|
121 | return None | |
122 |
|
122 | |||
123 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
123 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |
124 | return None |
|
124 | return None | |
125 |
|
125 | |||
126 | return thisDatetime |
|
126 | return thisDatetime | |
127 |
|
127 | |||
128 | def getFileFromSet(path,ext,set): |
|
128 | def getFileFromSet(path,ext,set): | |
129 | validFilelist = [] |
|
129 | validFilelist = [] | |
130 | fileList = os.listdir(path) |
|
130 | fileList = os.listdir(path) | |
131 |
|
131 | |||
132 | # 0 1234 567 89A BCDE |
|
132 | # 0 1234 567 89A BCDE | |
133 | # H YYYY DDD SSS .ext |
|
133 | # H YYYY DDD SSS .ext | |
134 |
|
134 | |||
135 | for file in fileList: |
|
135 | for file in fileList: | |
136 | try: |
|
136 | try: | |
137 | year = int(file[1:5]) |
|
137 | year = int(file[1:5]) | |
138 | doy = int(file[5:8]) |
|
138 | doy = int(file[5:8]) | |
139 |
|
139 | |||
140 |
|
140 | |||
141 | except: |
|
141 | except: | |
142 | continue |
|
142 | continue | |
143 |
|
143 | |||
144 | if (os.path.splitext(file)[-1].lower() != ext.lower()): |
|
144 | if (os.path.splitext(file)[-1].lower() != ext.lower()): | |
145 | continue |
|
145 | continue | |
146 |
|
146 | |||
147 | validFilelist.append(file) |
|
147 | validFilelist.append(file) | |
148 |
|
148 | |||
149 | myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set)) |
|
149 | myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set)) | |
150 |
|
150 | |||
151 | if len(myfile)!= 0: |
|
151 | if len(myfile)!= 0: | |
152 | return myfile[0] |
|
152 | return myfile[0] | |
153 | else: |
|
153 | else: | |
154 | filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower()) |
|
154 | filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower()) | |
155 | print 'the filename %s does not exist'%filename |
|
155 | print 'the filename %s does not exist'%filename | |
156 | print '...going to the last file: ' |
|
156 | print '...going to the last file: ' | |
157 |
|
157 | |||
158 | if validFilelist: |
|
158 | if validFilelist: | |
159 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
159 | validFilelist = sorted( validFilelist, key=str.lower ) | |
160 | return validFilelist[-1] |
|
160 | return validFilelist[-1] | |
161 |
|
161 | |||
162 | return None |
|
162 | return None | |
163 |
|
163 | |||
164 |
|
164 | |||
165 | def getlastFileFromPath(path, ext): |
|
165 | def getlastFileFromPath(path, ext): | |
166 | """ |
|
166 | """ | |
167 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
167 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
168 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
168 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
169 |
|
169 | |||
170 | Input: |
|
170 | Input: | |
171 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
171 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
172 | ext : extension de los files contenidos en una carpeta |
|
172 | ext : extension de los files contenidos en una carpeta | |
173 |
|
173 | |||
174 | Return: |
|
174 | Return: | |
175 | El ultimo file de una determinada carpeta, no se considera el path. |
|
175 | El ultimo file de una determinada carpeta, no se considera el path. | |
176 | """ |
|
176 | """ | |
177 | validFilelist = [] |
|
177 | validFilelist = [] | |
178 | fileList = os.listdir(path) |
|
178 | fileList = os.listdir(path) | |
179 |
|
179 | |||
180 | # 0 1234 567 89A BCDE |
|
180 | # 0 1234 567 89A BCDE | |
181 | # H YYYY DDD SSS .ext |
|
181 | # H YYYY DDD SSS .ext | |
182 |
|
182 | |||
183 | for file in fileList: |
|
183 | for file in fileList: | |
184 | try: |
|
184 | try: | |
185 | year = int(file[1:5]) |
|
185 | year = int(file[1:5]) | |
186 | doy = int(file[5:8]) |
|
186 | doy = int(file[5:8]) | |
187 |
|
187 | |||
188 |
|
188 | |||
189 | except: |
|
189 | except: | |
190 | continue |
|
190 | continue | |
191 |
|
191 | |||
192 | if (os.path.splitext(file)[-1].lower() != ext.lower()): |
|
192 | if (os.path.splitext(file)[-1].lower() != ext.lower()): | |
193 | continue |
|
193 | continue | |
194 |
|
194 | |||
195 | validFilelist.append(file) |
|
195 | validFilelist.append(file) | |
196 |
|
196 | |||
197 | if validFilelist: |
|
197 | if validFilelist: | |
198 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
198 | validFilelist = sorted( validFilelist, key=str.lower ) | |
199 | return validFilelist[-1] |
|
199 | return validFilelist[-1] | |
200 |
|
200 | |||
201 | return None |
|
201 | return None | |
202 |
|
202 | |||
203 | def checkForRealPath(path, foldercounter, year, doy, set, ext): |
|
203 | def checkForRealPath(path, foldercounter, year, doy, set, ext): | |
204 | """ |
|
204 | """ | |
205 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
205 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
206 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
206 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
207 | el path exacto de un determinado file. |
|
207 | el path exacto de un determinado file. | |
208 |
|
208 | |||
209 | Example : |
|
209 | Example : | |
210 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
210 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
211 |
|
211 | |||
212 | Entonces la funcion prueba con las siguientes combinaciones |
|
212 | Entonces la funcion prueba con las siguientes combinaciones | |
213 | .../.../y2009307367.ext |
|
213 | .../.../y2009307367.ext | |
214 | .../.../Y2009307367.ext |
|
214 | .../.../Y2009307367.ext | |
215 | .../.../x2009307/y2009307367.ext |
|
215 | .../.../x2009307/y2009307367.ext | |
216 | .../.../x2009307/Y2009307367.ext |
|
216 | .../.../x2009307/Y2009307367.ext | |
217 | .../.../X2009307/y2009307367.ext |
|
217 | .../.../X2009307/y2009307367.ext | |
218 | .../.../X2009307/Y2009307367.ext |
|
218 | .../.../X2009307/Y2009307367.ext | |
219 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
219 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
220 |
|
220 | |||
221 | Return: |
|
221 | Return: | |
222 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
222 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
223 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
223 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
224 | para el filename |
|
224 | para el filename | |
225 | """ |
|
225 | """ | |
226 | fullfilename = None |
|
226 | fullfilename = None | |
227 | find_flag = False |
|
227 | find_flag = False | |
228 | filename = None |
|
228 | filename = None | |
229 |
|
229 | |||
230 | prefixDirList = [None,'d','D'] |
|
230 | prefixDirList = [None,'d','D'] | |
231 | if ext.lower() == ".r": #voltage |
|
231 | if ext.lower() == ".r": #voltage | |
232 | prefixFileList = ['d','D'] |
|
232 | prefixFileList = ['d','D'] | |
233 | elif ext.lower() == ".pdata": #spectra |
|
233 | elif ext.lower() == ".pdata": #spectra | |
234 | prefixFileList = ['p','P'] |
|
234 | prefixFileList = ['p','P'] | |
235 | else: |
|
235 | else: | |
236 | return None, filename |
|
236 | return None, filename | |
237 |
|
237 | |||
238 | #barrido por las combinaciones posibles |
|
238 | #barrido por las combinaciones posibles | |
239 | for prefixDir in prefixDirList: |
|
239 | for prefixDir in prefixDirList: | |
240 | thispath = path |
|
240 | thispath = path | |
241 | if prefixDir != None: |
|
241 | if prefixDir != None: | |
242 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
242 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
243 | if foldercounter == 0: |
|
243 | if foldercounter == 0: | |
244 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) |
|
244 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) | |
245 | else: |
|
245 | else: | |
246 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter)) |
|
246 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter)) | |
247 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" |
|
247 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" | |
248 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
248 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
249 | fullfilename = os.path.join( thispath, filename ) #formo el path completo |
|
249 | fullfilename = os.path.join( thispath, filename ) #formo el path completo | |
250 |
|
250 | |||
251 | if os.path.exists( fullfilename ): #verifico que exista |
|
251 | if os.path.exists( fullfilename ): #verifico que exista | |
252 | find_flag = True |
|
252 | find_flag = True | |
253 | break |
|
253 | break | |
254 | if find_flag: |
|
254 | if find_flag: | |
255 | break |
|
255 | break | |
256 |
|
256 | |||
257 | if not(find_flag): |
|
257 | if not(find_flag): | |
258 | return None, filename |
|
258 | return None, filename | |
259 |
|
259 | |||
260 | return fullfilename, filename |
|
260 | return fullfilename, filename | |
261 |
|
261 | |||
262 | def isDoyFolder(folder): |
|
262 | def isDoyFolder(folder): | |
263 | try: |
|
263 | try: | |
264 | year = int(folder[1:5]) |
|
264 | year = int(folder[1:5]) | |
265 | except: |
|
265 | except: | |
266 | return 0 |
|
266 | return 0 | |
267 |
|
267 | |||
268 | try: |
|
268 | try: | |
269 | doy = int(folder[5:8]) |
|
269 | doy = int(folder[5:8]) | |
270 | except: |
|
270 | except: | |
271 | return 0 |
|
271 | return 0 | |
272 |
|
272 | |||
273 | return 1 |
|
273 | return 1 | |
274 |
|
274 | |||
275 | class JRODataIO: |
|
275 | class JRODataIO: | |
276 |
|
276 | |||
277 | c = 3E8 |
|
277 | c = 3E8 | |
278 |
|
278 | |||
279 | isConfig = False |
|
279 | isConfig = False | |
280 |
|
280 | |||
281 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
281 | basicHeaderObj = BasicHeader(LOCALTIME) | |
282 |
|
282 | |||
283 | systemHeaderObj = SystemHeader() |
|
283 | systemHeaderObj = SystemHeader() | |
284 |
|
284 | |||
285 | radarControllerHeaderObj = RadarControllerHeader() |
|
285 | radarControllerHeaderObj = RadarControllerHeader() | |
286 |
|
286 | |||
287 | processingHeaderObj = ProcessingHeader() |
|
287 | processingHeaderObj = ProcessingHeader() | |
288 |
|
288 | |||
289 | online = 0 |
|
289 | online = 0 | |
290 |
|
290 | |||
291 | dtype = None |
|
291 | dtype = None | |
292 |
|
292 | |||
293 | pathList = [] |
|
293 | pathList = [] | |
294 |
|
294 | |||
295 | filenameList = [] |
|
295 | filenameList = [] | |
296 |
|
296 | |||
297 | filename = None |
|
297 | filename = None | |
298 |
|
298 | |||
299 | ext = None |
|
299 | ext = None | |
300 |
|
300 | |||
301 | flagIsNewFile = 1 |
|
301 | flagIsNewFile = 1 | |
302 |
|
302 | |||
303 | flagTimeBlock = 0 |
|
303 | flagTimeBlock = 0 | |
304 |
|
304 | |||
305 | flagIsNewBlock = 0 |
|
305 | flagIsNewBlock = 0 | |
306 |
|
306 | |||
307 | fp = None |
|
307 | fp = None | |
308 |
|
308 | |||
309 | firstHeaderSize = 0 |
|
309 | firstHeaderSize = 0 | |
310 |
|
310 | |||
311 | basicHeaderSize = 24 |
|
311 | basicHeaderSize = 24 | |
312 |
|
312 | |||
313 | versionFile = 1103 |
|
313 | versionFile = 1103 | |
314 |
|
314 | |||
315 | fileSize = None |
|
315 | fileSize = None | |
316 |
|
316 | |||
317 | ippSeconds = None |
|
317 | ippSeconds = None | |
318 |
|
318 | |||
319 | fileSizeByHeader = None |
|
319 | fileSizeByHeader = None | |
320 |
|
320 | |||
321 | fileIndex = None |
|
321 | fileIndex = None | |
322 |
|
322 | |||
323 | profileIndex = None |
|
323 | profileIndex = None | |
324 |
|
324 | |||
325 | blockIndex = None |
|
325 | blockIndex = None | |
326 |
|
326 | |||
327 | nTotalBlocks = None |
|
327 | nTotalBlocks = None | |
328 |
|
328 | |||
329 | maxTimeStep = 30 |
|
329 | maxTimeStep = 30 | |
330 |
|
330 | |||
331 | lastUTTime = None |
|
331 | lastUTTime = None | |
332 |
|
332 | |||
333 | datablock = None |
|
333 | datablock = None | |
334 |
|
334 | |||
335 | dataOut = None |
|
335 | dataOut = None | |
336 |
|
336 | |||
337 | blocksize = None |
|
337 | blocksize = None | |
338 |
|
338 | |||
339 | def __init__(self): |
|
339 | def __init__(self): | |
340 |
|
340 | |||
341 | raise ValueError, "Not implemented" |
|
341 | raise ValueError, "Not implemented" | |
342 |
|
342 | |||
343 | def run(self): |
|
343 | def run(self): | |
344 |
|
344 | |||
345 | raise ValueError, "Not implemented" |
|
345 | raise ValueError, "Not implemented" | |
346 |
|
346 | |||
347 | def getOutput(self): |
|
347 | def getOutput(self): | |
348 |
|
348 | |||
349 | return self.dataOut |
|
349 | return self.dataOut | |
350 |
|
350 | |||
351 | class JRODataReader(JRODataIO, ProcessingUnit): |
|
351 | class JRODataReader(JRODataIO, ProcessingUnit): | |
352 |
|
352 | |||
353 | nReadBlocks = 0 |
|
353 | nReadBlocks = 0 | |
354 |
|
354 | |||
355 | delay = 10 #number of seconds waiting a new file |
|
355 | delay = 10 #number of seconds waiting a new file | |
356 |
|
356 | |||
357 | nTries = 3 #quantity tries |
|
357 | nTries = 3 #quantity tries | |
358 |
|
358 | |||
359 | nFiles = 3 #number of files for searching |
|
359 | nFiles = 3 #number of files for searching | |
360 |
|
360 | |||
361 | path = None |
|
361 | path = None | |
362 |
|
362 | |||
363 | foldercounter = 0 |
|
363 | foldercounter = 0 | |
364 |
|
364 | |||
365 | flagNoMoreFiles = 0 |
|
365 | flagNoMoreFiles = 0 | |
366 |
|
366 | |||
367 | datetimeList = [] |
|
367 | datetimeList = [] | |
368 |
|
368 | |||
369 | __isFirstTimeOnline = 1 |
|
369 | __isFirstTimeOnline = 1 | |
370 |
|
370 | |||
371 | __printInfo = True |
|
371 | __printInfo = True | |
372 |
|
372 | |||
373 | profileIndex = None |
|
373 | profileIndex = None | |
374 |
|
374 | |||
375 | def __init__(self): |
|
375 | def __init__(self): | |
376 |
|
376 | |||
377 | """ |
|
377 | """ | |
378 |
|
378 | |||
379 | """ |
|
379 | """ | |
380 |
|
380 | |||
381 | raise ValueError, "This method has not been implemented" |
|
381 | raise ValueError, "This method has not been implemented" | |
382 |
|
382 | |||
383 |
|
383 | |||
384 | def createObjByDefault(self): |
|
384 | def createObjByDefault(self): | |
385 | """ |
|
385 | """ | |
386 |
|
386 | |||
387 | """ |
|
387 | """ | |
388 | raise ValueError, "This method has not been implemented" |
|
388 | raise ValueError, "This method has not been implemented" | |
389 |
|
389 | |||
390 | def getBlockDimension(self): |
|
390 | def getBlockDimension(self): | |
391 |
|
391 | |||
392 | raise ValueError, "No implemented" |
|
392 | raise ValueError, "No implemented" | |
393 |
|
393 | |||
394 | def __searchFilesOffLine(self, |
|
394 | def __searchFilesOffLine(self, | |
395 | path, |
|
395 | path, | |
396 | startDate, |
|
396 | startDate, | |
397 | endDate, |
|
397 | endDate, | |
398 | startTime=datetime.time(0,0,0), |
|
398 | startTime=datetime.time(0,0,0), | |
399 | endTime=datetime.time(23,59,59), |
|
399 | endTime=datetime.time(23,59,59), | |
400 | set=None, |
|
400 | set=None, | |
401 | expLabel='', |
|
401 | expLabel='', | |
402 | ext='.r', |
|
402 | ext='.r', | |
403 | walk=True): |
|
403 | walk=True): | |
404 |
|
404 | |||
405 | pathList = [] |
|
405 | pathList = [] | |
406 |
|
406 | |||
407 | if not walk: |
|
407 | if not walk: | |
408 | #pathList.append(path) |
|
408 | #pathList.append(path) | |
409 | multi_path = path.split(',') |
|
409 | multi_path = path.split(',') | |
410 | for single_path in multi_path: |
|
410 | for single_path in multi_path: | |
411 | pathList.append(single_path) |
|
411 | pathList.append(single_path) | |
412 |
|
412 | |||
413 | else: |
|
413 | else: | |
414 | #dirList = [] |
|
414 | #dirList = [] | |
415 | multi_path = path.split(',') |
|
415 | multi_path = path.split(',') | |
416 | for single_path in multi_path: |
|
416 | for single_path in multi_path: | |
417 | dirList = [] |
|
417 | dirList = [] | |
418 | for thisPath in os.listdir(single_path): |
|
418 | for thisPath in os.listdir(single_path): | |
419 | if not os.path.isdir(os.path.join(single_path,thisPath)): |
|
419 | if not os.path.isdir(os.path.join(single_path,thisPath)): | |
420 | continue |
|
420 | continue | |
421 | if not isDoyFolder(thisPath): |
|
421 | if not isDoyFolder(thisPath): | |
422 | continue |
|
422 | continue | |
423 |
|
423 | |||
424 | dirList.append(thisPath) |
|
424 | dirList.append(thisPath) | |
425 |
|
425 | |||
426 | if not(dirList): |
|
426 | if not(dirList): | |
427 | return None, None |
|
427 | return None, None | |
428 |
|
428 | |||
429 | thisDate = startDate |
|
429 | thisDate = startDate | |
430 |
|
430 | |||
431 | while(thisDate <= endDate): |
|
431 | while(thisDate <= endDate): | |
432 | year = thisDate.timetuple().tm_year |
|
432 | year = thisDate.timetuple().tm_year | |
433 | doy = thisDate.timetuple().tm_yday |
|
433 | doy = thisDate.timetuple().tm_yday | |
434 |
|
434 | |||
435 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
435 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') | |
436 | if len(matchlist) == 0: |
|
436 | if len(matchlist) == 0: | |
437 | thisDate += datetime.timedelta(1) |
|
437 | thisDate += datetime.timedelta(1) | |
438 | continue |
|
438 | continue | |
439 | for match in matchlist: |
|
439 | for match in matchlist: | |
440 | pathList.append(os.path.join(single_path,match,expLabel)) |
|
440 | pathList.append(os.path.join(single_path,match,expLabel)) | |
441 |
|
441 | |||
442 | thisDate += datetime.timedelta(1) |
|
442 | thisDate += datetime.timedelta(1) | |
443 |
|
443 | |||
444 | if pathList == []: |
|
444 | if pathList == []: | |
445 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
445 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) | |
446 | return None, None |
|
446 | return None, None | |
447 |
|
447 | |||
448 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
448 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) | |
449 |
|
449 | |||
450 | filenameList = [] |
|
450 | filenameList = [] | |
451 | datetimeList = [] |
|
451 | datetimeList = [] | |
452 | pathDict = {} |
|
452 | pathDict = {} | |
453 | filenameList_to_sort = [] |
|
453 | filenameList_to_sort = [] | |
454 |
|
454 | |||
455 | for i in range(len(pathList)): |
|
455 | for i in range(len(pathList)): | |
456 |
|
456 | |||
457 | thisPath = pathList[i] |
|
457 | thisPath = pathList[i] | |
458 |
|
458 | |||
459 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
459 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
460 | fileList.sort() |
|
460 | fileList.sort() | |
461 | pathDict.setdefault(fileList[0]) |
|
461 | pathDict.setdefault(fileList[0]) | |
462 | pathDict[fileList[0]] = i |
|
462 | pathDict[fileList[0]] = i | |
463 | filenameList_to_sort.append(fileList[0]) |
|
463 | filenameList_to_sort.append(fileList[0]) | |
464 |
|
464 | |||
465 | filenameList_to_sort.sort() |
|
465 | filenameList_to_sort.sort() | |
466 |
|
466 | |||
467 | for file in filenameList_to_sort: |
|
467 | for file in filenameList_to_sort: | |
468 | thisPath = pathList[pathDict[file]] |
|
468 | thisPath = pathList[pathDict[file]] | |
469 |
|
469 | |||
470 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
470 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
471 | fileList.sort() |
|
471 | fileList.sort() | |
472 |
|
472 | |||
473 | for file in fileList: |
|
473 | for file in fileList: | |
474 |
|
474 | |||
475 | filename = os.path.join(thisPath,file) |
|
475 | filename = os.path.join(thisPath,file) | |
476 | thisDatetime = isFileinThisTime(filename, startTime, endTime) |
|
476 | thisDatetime = isFileinThisTime(filename, startTime, endTime) | |
477 |
|
477 | |||
478 | if not(thisDatetime): |
|
478 | if not(thisDatetime): | |
479 | continue |
|
479 | continue | |
480 |
|
480 | |||
481 | filenameList.append(filename) |
|
481 | filenameList.append(filename) | |
482 | datetimeList.append(thisDatetime) |
|
482 | datetimeList.append(thisDatetime) | |
483 |
|
483 | |||
484 | if not(filenameList): |
|
484 | if not(filenameList): | |
485 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
485 | print "Any file was found for the time range %s - %s" %(startTime, endTime) | |
486 | return None, None |
|
486 | return None, None | |
487 |
|
487 | |||
488 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
488 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) | |
489 |
|
489 | |||
490 |
|
490 | |||
491 | for i in range(len(filenameList)): |
|
491 | for i in range(len(filenameList)): | |
492 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
492 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) | |
493 |
|
493 | |||
494 | self.filenameList = filenameList |
|
494 | self.filenameList = filenameList | |
495 | self.datetimeList = datetimeList |
|
495 | self.datetimeList = datetimeList | |
496 |
|
496 | |||
497 | return pathList, filenameList |
|
497 | return pathList, filenameList | |
498 |
|
498 | |||
499 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None): |
|
499 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None): | |
500 |
|
500 | |||
501 | """ |
|
501 | """ | |
502 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
502 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
503 | devuelve el archivo encontrado ademas de otros datos. |
|
503 | devuelve el archivo encontrado ademas de otros datos. | |
504 |
|
504 | |||
505 | Input: |
|
505 | Input: | |
506 | path : carpeta donde estan contenidos los files que contiene data |
|
506 | path : carpeta donde estan contenidos los files que contiene data | |
507 |
|
507 | |||
508 | expLabel : Nombre del subexperimento (subfolder) |
|
508 | expLabel : Nombre del subexperimento (subfolder) | |
509 |
|
509 | |||
510 | ext : extension de los files |
|
510 | ext : extension de los files | |
511 |
|
511 | |||
512 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
512 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) | |
513 |
|
513 | |||
514 | Return: |
|
514 | Return: | |
515 | directory : eL directorio donde esta el file encontrado |
|
515 | directory : eL directorio donde esta el file encontrado | |
516 | filename : el ultimo file de una determinada carpeta |
|
516 | filename : el ultimo file de una determinada carpeta | |
517 | year : el anho |
|
517 | year : el anho | |
518 | doy : el numero de dia del anho |
|
518 | doy : el numero de dia del anho | |
519 | set : el set del archivo |
|
519 | set : el set del archivo | |
520 |
|
520 | |||
521 |
|
521 | |||
522 | """ |
|
522 | """ | |
523 | dirList = [] |
|
523 | dirList = [] | |
524 |
|
524 | |||
525 | if not walk: |
|
525 | if not walk: | |
526 | fullpath = path |
|
526 | fullpath = path | |
527 | foldercounter = 0 |
|
527 | foldercounter = 0 | |
528 | else: |
|
528 | else: | |
529 | #Filtra solo los directorios |
|
529 | #Filtra solo los directorios | |
530 | for thisPath in os.listdir(path): |
|
530 | for thisPath in os.listdir(path): | |
531 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
531 | if not os.path.isdir(os.path.join(path,thisPath)): | |
532 | continue |
|
532 | continue | |
533 | if not isDoyFolder(thisPath): |
|
533 | if not isDoyFolder(thisPath): | |
534 | continue |
|
534 | continue | |
535 |
|
535 | |||
536 | dirList.append(thisPath) |
|
536 | dirList.append(thisPath) | |
537 |
|
537 | |||
538 | if not(dirList): |
|
538 | if not(dirList): | |
539 | return None, None, None, None, None, None |
|
539 | return None, None, None, None, None, None | |
540 |
|
540 | |||
541 | dirList = sorted( dirList, key=str.lower ) |
|
541 | dirList = sorted( dirList, key=str.lower ) | |
542 |
|
542 | |||
543 | doypath = dirList[-1] |
|
543 | doypath = dirList[-1] | |
544 | foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0 |
|
544 | foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0 | |
545 | fullpath = os.path.join(path, doypath, expLabel) |
|
545 | fullpath = os.path.join(path, doypath, expLabel) | |
546 |
|
546 | |||
547 |
|
547 | |||
548 | print "%s folder was found: " %(fullpath ) |
|
548 | print "%s folder was found: " %(fullpath ) | |
549 |
|
549 | |||
550 | if set == None: |
|
550 | if set == None: | |
551 | filename = getlastFileFromPath(fullpath, ext) |
|
551 | filename = getlastFileFromPath(fullpath, ext) | |
552 | else: |
|
552 | else: | |
553 | filename = getFileFromSet(fullpath, ext, set) |
|
553 | filename = getFileFromSet(fullpath, ext, set) | |
554 |
|
554 | |||
555 | if not(filename): |
|
555 | if not(filename): | |
556 | return None, None, None, None, None, None |
|
556 | return None, None, None, None, None, None | |
557 |
|
557 | |||
558 | print "%s file was found" %(filename) |
|
558 | print "%s file was found" %(filename) | |
559 |
|
559 | |||
560 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
560 | if not(self.__verifyFile(os.path.join(fullpath, filename))): | |
561 | return None, None, None, None, None, None |
|
561 | return None, None, None, None, None, None | |
562 |
|
562 | |||
563 | year = int( filename[1:5] ) |
|
563 | year = int( filename[1:5] ) | |
564 | doy = int( filename[5:8] ) |
|
564 | doy = int( filename[5:8] ) | |
565 | set = int( filename[8:11] ) |
|
565 | set = int( filename[8:11] ) | |
566 |
|
566 | |||
567 | return fullpath, foldercounter, filename, year, doy, set |
|
567 | return fullpath, foldercounter, filename, year, doy, set | |
568 |
|
568 | |||
569 | def __setNextFileOffline(self): |
|
569 | def __setNextFileOffline(self): | |
570 |
|
570 | |||
571 | idFile = self.fileIndex |
|
571 | idFile = self.fileIndex | |
572 |
|
572 | |||
573 | while (True): |
|
573 | while (True): | |
574 | idFile += 1 |
|
574 | idFile += 1 | |
575 | if not(idFile < len(self.filenameList)): |
|
575 | if not(idFile < len(self.filenameList)): | |
576 | self.flagNoMoreFiles = 1 |
|
576 | self.flagNoMoreFiles = 1 | |
577 | print "No more Files" |
|
577 | print "No more Files" | |
578 | return 0 |
|
578 | return 0 | |
579 |
|
579 | |||
580 | filename = self.filenameList[idFile] |
|
580 | filename = self.filenameList[idFile] | |
581 |
|
581 | |||
582 | if not(self.__verifyFile(filename)): |
|
582 | if not(self.__verifyFile(filename)): | |
583 | continue |
|
583 | continue | |
584 |
|
584 | |||
585 | fileSize = os.path.getsize(filename) |
|
585 | fileSize = os.path.getsize(filename) | |
586 | fp = open(filename,'rb') |
|
586 | fp = open(filename,'rb') | |
587 | break |
|
587 | break | |
588 |
|
588 | |||
589 | self.flagIsNewFile = 1 |
|
589 | self.flagIsNewFile = 1 | |
590 | self.fileIndex = idFile |
|
590 | self.fileIndex = idFile | |
591 | self.filename = filename |
|
591 | self.filename = filename | |
592 | self.fileSize = fileSize |
|
592 | self.fileSize = fileSize | |
593 | self.fp = fp |
|
593 | self.fp = fp | |
594 |
|
594 | |||
595 | print "Setting the file: %s"%self.filename |
|
595 | print "Setting the file: %s"%self.filename | |
596 |
|
596 | |||
597 | return 1 |
|
597 | return 1 | |
598 |
|
598 | |||
599 | def __setNextFileOnline(self): |
|
599 | def __setNextFileOnline(self): | |
600 | """ |
|
600 | """ | |
601 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
601 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
602 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
602 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
603 | siguientes. |
|
603 | siguientes. | |
604 |
|
604 | |||
605 | Affected: |
|
605 | Affected: | |
606 | self.flagIsNewFile |
|
606 | self.flagIsNewFile | |
607 | self.filename |
|
607 | self.filename | |
608 | self.fileSize |
|
608 | self.fileSize | |
609 | self.fp |
|
609 | self.fp | |
610 | self.set |
|
610 | self.set | |
611 | self.flagNoMoreFiles |
|
611 | self.flagNoMoreFiles | |
612 |
|
612 | |||
613 | Return: |
|
613 | Return: | |
614 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
614 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
615 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
615 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
616 |
|
616 | |||
617 | Excepciones: |
|
617 | Excepciones: | |
618 | Si un determinado file no puede ser abierto |
|
618 | Si un determinado file no puede ser abierto | |
619 | """ |
|
619 | """ | |
620 | nFiles = 0 |
|
620 | nFiles = 0 | |
621 | fileOk_flag = False |
|
621 | fileOk_flag = False | |
622 | firstTime_flag = True |
|
622 | firstTime_flag = True | |
623 |
|
623 | |||
624 | self.set += 1 |
|
624 | self.set += 1 | |
625 |
|
625 | |||
626 | if self.set > 999: |
|
626 | if self.set > 999: | |
627 | self.set = 0 |
|
627 | self.set = 0 | |
628 | self.foldercounter += 1 |
|
628 | self.foldercounter += 1 | |
629 |
|
629 | |||
630 | #busca el 1er file disponible |
|
630 | #busca el 1er file disponible | |
631 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
631 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) | |
632 | if fullfilename: |
|
632 | if fullfilename: | |
633 | if self.__verifyFile(fullfilename, False): |
|
633 | if self.__verifyFile(fullfilename, False): | |
634 | fileOk_flag = True |
|
634 | fileOk_flag = True | |
635 |
|
635 | |||
636 | #si no encuentra un file entonces espera y vuelve a buscar |
|
636 | #si no encuentra un file entonces espera y vuelve a buscar | |
637 | if not(fileOk_flag): |
|
637 | if not(fileOk_flag): | |
638 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
638 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles | |
639 |
|
639 | |||
640 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
640 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
641 | tries = self.nTries |
|
641 | tries = self.nTries | |
642 | else: |
|
642 | else: | |
643 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
643 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
644 |
|
644 | |||
645 | for nTries in range( tries ): |
|
645 | for nTries in range( tries ): | |
646 | if firstTime_flag: |
|
646 | if firstTime_flag: | |
647 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
647 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) | |
648 | time.sleep( self.delay ) |
|
648 | time.sleep( self.delay ) | |
649 | else: |
|
649 | else: | |
650 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
650 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
651 |
|
651 | |||
652 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
652 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) | |
653 | if fullfilename: |
|
653 | if fullfilename: | |
654 | if self.__verifyFile(fullfilename): |
|
654 | if self.__verifyFile(fullfilename): | |
655 | fileOk_flag = True |
|
655 | fileOk_flag = True | |
656 | break |
|
656 | break | |
657 |
|
657 | |||
658 | if fileOk_flag: |
|
658 | if fileOk_flag: | |
659 | break |
|
659 | break | |
660 |
|
660 | |||
661 | firstTime_flag = False |
|
661 | firstTime_flag = False | |
662 |
|
662 | |||
663 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
663 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename | |
664 | self.set += 1 |
|
664 | self.set += 1 | |
665 |
|
665 | |||
666 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
666 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
667 | self.set = 0 |
|
667 | self.set = 0 | |
668 | self.doy += 1 |
|
668 | self.doy += 1 | |
669 | self.foldercounter = 0 |
|
669 | self.foldercounter = 0 | |
670 |
|
670 | |||
671 | if fileOk_flag: |
|
671 | if fileOk_flag: | |
672 | self.fileSize = os.path.getsize( fullfilename ) |
|
672 | self.fileSize = os.path.getsize( fullfilename ) | |
673 | self.filename = fullfilename |
|
673 | self.filename = fullfilename | |
674 | self.flagIsNewFile = 1 |
|
674 | self.flagIsNewFile = 1 | |
675 | if self.fp != None: self.fp.close() |
|
675 | if self.fp != None: self.fp.close() | |
676 | self.fp = open(fullfilename, 'rb') |
|
676 | self.fp = open(fullfilename, 'rb') | |
677 | self.flagNoMoreFiles = 0 |
|
677 | self.flagNoMoreFiles = 0 | |
678 | print 'Setting the file: %s' % fullfilename |
|
678 | print 'Setting the file: %s' % fullfilename | |
679 | else: |
|
679 | else: | |
680 | self.fileSize = 0 |
|
680 | self.fileSize = 0 | |
681 | self.filename = None |
|
681 | self.filename = None | |
682 | self.flagIsNewFile = 0 |
|
682 | self.flagIsNewFile = 0 | |
683 | self.fp = None |
|
683 | self.fp = None | |
684 | self.flagNoMoreFiles = 1 |
|
684 | self.flagNoMoreFiles = 1 | |
685 | print 'No more Files' |
|
685 | print 'No more Files' | |
686 |
|
686 | |||
687 | return fileOk_flag |
|
687 | return fileOk_flag | |
688 |
|
688 | |||
689 |
|
689 | |||
690 | def setNextFile(self): |
|
690 | def setNextFile(self): | |
691 | if self.fp != None: |
|
691 | if self.fp != None: | |
692 | self.fp.close() |
|
692 | self.fp.close() | |
693 |
|
693 | |||
694 | if self.online: |
|
694 | if self.online: | |
695 | newFile = self.__setNextFileOnline() |
|
695 | newFile = self.__setNextFileOnline() | |
696 | else: |
|
696 | else: | |
697 | newFile = self.__setNextFileOffline() |
|
697 | newFile = self.__setNextFileOffline() | |
698 |
|
698 | |||
699 | if not(newFile): |
|
699 | if not(newFile): | |
700 | return 0 |
|
700 | return 0 | |
701 |
|
701 | |||
702 | self.__readFirstHeader() |
|
702 | self.__readFirstHeader() | |
703 | self.nReadBlocks = 0 |
|
703 | self.nReadBlocks = 0 | |
704 | return 1 |
|
704 | return 1 | |
705 |
|
705 | |||
706 | def __waitNewBlock(self): |
|
706 | def __waitNewBlock(self): | |
707 | """ |
|
707 | """ | |
708 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
708 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
709 |
|
709 | |||
710 | Si el modo de lectura es OffLine siempre retorn 0 |
|
710 | Si el modo de lectura es OffLine siempre retorn 0 | |
711 | """ |
|
711 | """ | |
712 | if not self.online: |
|
712 | if not self.online: | |
713 | return 0 |
|
713 | return 0 | |
714 |
|
714 | |||
715 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
715 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |
716 | return 0 |
|
716 | return 0 | |
717 |
|
717 | |||
718 | currentPointer = self.fp.tell() |
|
718 | currentPointer = self.fp.tell() | |
719 |
|
719 | |||
720 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
720 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
721 |
|
721 | |||
722 | for nTries in range( self.nTries ): |
|
722 | for nTries in range( self.nTries ): | |
723 |
|
723 | |||
724 | self.fp.close() |
|
724 | self.fp.close() | |
725 | self.fp = open( self.filename, 'rb' ) |
|
725 | self.fp = open( self.filename, 'rb' ) | |
726 | self.fp.seek( currentPointer ) |
|
726 | self.fp.seek( currentPointer ) | |
727 |
|
727 | |||
728 | self.fileSize = os.path.getsize( self.filename ) |
|
728 | self.fileSize = os.path.getsize( self.filename ) | |
729 | currentSize = self.fileSize - currentPointer |
|
729 | currentSize = self.fileSize - currentPointer | |
730 |
|
730 | |||
731 | if ( currentSize >= neededSize ): |
|
731 | if ( currentSize >= neededSize ): | |
732 | self.__rdBasicHeader() |
|
732 | self.__rdBasicHeader() | |
733 | return 1 |
|
733 | return 1 | |
734 |
|
734 | |||
735 | if self.fileSize == self.fileSizeByHeader: |
|
735 | if self.fileSize == self.fileSizeByHeader: | |
736 | # self.flagEoF = True |
|
736 | # self.flagEoF = True | |
737 | return 0 |
|
737 | return 0 | |
738 |
|
738 | |||
739 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
739 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
740 | time.sleep( self.delay ) |
|
740 | time.sleep( self.delay ) | |
741 |
|
741 | |||
742 |
|
742 | |||
743 | return 0 |
|
743 | return 0 | |
744 |
|
744 | |||
745 | def waitDataBlock(self,pointer_location): |
|
745 | def waitDataBlock(self,pointer_location): | |
746 |
|
746 | |||
747 | currentPointer = pointer_location |
|
747 | currentPointer = pointer_location | |
748 |
|
748 | |||
749 | neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize |
|
749 | neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize | |
750 |
|
750 | |||
751 | for nTries in range( self.nTries ): |
|
751 | for nTries in range( self.nTries ): | |
752 | self.fp.close() |
|
752 | self.fp.close() | |
753 | self.fp = open( self.filename, 'rb' ) |
|
753 | self.fp = open( self.filename, 'rb' ) | |
754 | self.fp.seek( currentPointer ) |
|
754 | self.fp.seek( currentPointer ) | |
755 |
|
755 | |||
756 | self.fileSize = os.path.getsize( self.filename ) |
|
756 | self.fileSize = os.path.getsize( self.filename ) | |
757 | currentSize = self.fileSize - currentPointer |
|
757 | currentSize = self.fileSize - currentPointer | |
758 |
|
758 | |||
759 | if ( currentSize >= neededSize ): |
|
759 | if ( currentSize >= neededSize ): | |
760 | return 1 |
|
760 | return 1 | |
761 |
|
761 | |||
762 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
762 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
763 | time.sleep( self.delay ) |
|
763 | time.sleep( self.delay ) | |
764 |
|
764 | |||
765 | return 0 |
|
765 | return 0 | |
766 |
|
766 | |||
767 |
|
767 | |||
768 | def __jumpToLastBlock(self): |
|
768 | def __jumpToLastBlock(self): | |
769 |
|
769 | |||
770 | if not(self.__isFirstTimeOnline): |
|
770 | if not(self.__isFirstTimeOnline): | |
771 | return |
|
771 | return | |
772 |
|
772 | |||
773 | csize = self.fileSize - self.fp.tell() |
|
773 | csize = self.fileSize - self.fp.tell() | |
774 | blocksize = self.processingHeaderObj.blockSize |
|
774 | blocksize = self.processingHeaderObj.blockSize | |
775 |
|
775 | |||
776 | #salta el primer bloque de datos |
|
776 | #salta el primer bloque de datos | |
777 | if csize > self.processingHeaderObj.blockSize: |
|
777 | if csize > self.processingHeaderObj.blockSize: | |
778 | self.fp.seek(self.fp.tell() + blocksize) |
|
778 | self.fp.seek(self.fp.tell() + blocksize) | |
779 | else: |
|
779 | else: | |
780 | return |
|
780 | return | |
781 |
|
781 | |||
782 | csize = self.fileSize - self.fp.tell() |
|
782 | csize = self.fileSize - self.fp.tell() | |
783 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
783 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
784 | while True: |
|
784 | while True: | |
785 |
|
785 | |||
786 | if self.fp.tell()<self.fileSize: |
|
786 | if self.fp.tell()<self.fileSize: | |
787 | self.fp.seek(self.fp.tell() + neededsize) |
|
787 | self.fp.seek(self.fp.tell() + neededsize) | |
788 | else: |
|
788 | else: | |
789 | self.fp.seek(self.fp.tell() - neededsize) |
|
789 | self.fp.seek(self.fp.tell() - neededsize) | |
790 | break |
|
790 | break | |
791 |
|
791 | |||
792 | # csize = self.fileSize - self.fp.tell() |
|
792 | # csize = self.fileSize - self.fp.tell() | |
793 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
793 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
794 | # factor = int(csize/neededsize) |
|
794 | # factor = int(csize/neededsize) | |
795 | # if factor > 0: |
|
795 | # if factor > 0: | |
796 | # self.fp.seek(self.fp.tell() + factor*neededsize) |
|
796 | # self.fp.seek(self.fp.tell() + factor*neededsize) | |
797 |
|
797 | |||
798 | self.flagIsNewFile = 0 |
|
798 | self.flagIsNewFile = 0 | |
799 | self.__isFirstTimeOnline = 0 |
|
799 | self.__isFirstTimeOnline = 0 | |
800 |
|
800 | |||
801 |
|
801 | |||
802 | def __setNewBlock(self): |
|
802 | def __setNewBlock(self): | |
803 |
|
803 | |||
804 | if self.fp == None: |
|
804 | if self.fp == None: | |
805 | return 0 |
|
805 | return 0 | |
806 |
|
806 | |||
807 | if self.online: |
|
807 | if self.online: | |
808 | self.__jumpToLastBlock() |
|
808 | self.__jumpToLastBlock() | |
809 |
|
809 | |||
810 | if self.flagIsNewFile: |
|
810 | if self.flagIsNewFile: | |
811 | return 1 |
|
811 | return 1 | |
812 |
|
812 | |||
813 | self.lastUTTime = self.basicHeaderObj.utc |
|
813 | self.lastUTTime = self.basicHeaderObj.utc | |
814 | currentSize = self.fileSize - self.fp.tell() |
|
814 | currentSize = self.fileSize - self.fp.tell() | |
815 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
815 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
816 |
|
816 | |||
817 | if (currentSize >= neededSize): |
|
817 | if (currentSize >= neededSize): | |
818 | self.__rdBasicHeader() |
|
818 | self.__rdBasicHeader() | |
819 | return 1 |
|
819 | return 1 | |
820 |
|
820 | |||
821 | if self.__waitNewBlock(): |
|
821 | if self.__waitNewBlock(): | |
822 | return 1 |
|
822 | return 1 | |
823 |
|
823 | |||
824 | if not(self.setNextFile()): |
|
824 | if not(self.setNextFile()): | |
825 | return 0 |
|
825 | return 0 | |
826 |
|
826 | |||
827 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
827 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
828 |
|
828 | |||
829 | self.flagTimeBlock = 0 |
|
829 | self.flagTimeBlock = 0 | |
830 |
|
830 | |||
831 | if deltaTime > self.maxTimeStep: |
|
831 | if deltaTime > self.maxTimeStep: | |
832 | self.flagTimeBlock = 1 |
|
832 | self.flagTimeBlock = 1 | |
833 |
|
833 | |||
834 | return 1 |
|
834 | return 1 | |
835 |
|
835 | |||
836 |
|
836 | |||
837 | def readNextBlock(self): |
|
837 | def readNextBlock(self): | |
838 | if not(self.__setNewBlock()): |
|
838 | if not(self.__setNewBlock()): | |
839 | return 0 |
|
839 | return 0 | |
840 |
|
840 | |||
841 | if not(self.readBlock()): |
|
841 | if not(self.readBlock()): | |
842 | return 0 |
|
842 | return 0 | |
843 |
|
843 | |||
844 | return 1 |
|
844 | return 1 | |
845 |
|
845 | |||
846 | def __rdProcessingHeader(self, fp=None): |
|
846 | def __rdProcessingHeader(self, fp=None): | |
847 | if fp == None: |
|
847 | if fp == None: | |
848 | fp = self.fp |
|
848 | fp = self.fp | |
849 |
|
849 | |||
850 | self.processingHeaderObj.read(fp) |
|
850 | self.processingHeaderObj.read(fp) | |
851 |
|
851 | |||
852 | def __rdRadarControllerHeader(self, fp=None): |
|
852 | def __rdRadarControllerHeader(self, fp=None): | |
853 | if fp == None: |
|
853 | if fp == None: | |
854 | fp = self.fp |
|
854 | fp = self.fp | |
855 |
|
855 | |||
856 | self.radarControllerHeaderObj.read(fp) |
|
856 | self.radarControllerHeaderObj.read(fp) | |
857 |
|
857 | |||
858 | def __rdSystemHeader(self, fp=None): |
|
858 | def __rdSystemHeader(self, fp=None): | |
859 | if fp == None: |
|
859 | if fp == None: | |
860 | fp = self.fp |
|
860 | fp = self.fp | |
861 |
|
861 | |||
862 | self.systemHeaderObj.read(fp) |
|
862 | self.systemHeaderObj.read(fp) | |
863 |
|
863 | |||
864 | def __rdBasicHeader(self, fp=None): |
|
864 | def __rdBasicHeader(self, fp=None): | |
865 | if fp == None: |
|
865 | if fp == None: | |
866 | fp = self.fp |
|
866 | fp = self.fp | |
867 |
|
867 | |||
868 | self.basicHeaderObj.read(fp) |
|
868 | self.basicHeaderObj.read(fp) | |
869 |
|
869 | |||
870 |
|
870 | |||
871 | def __readFirstHeader(self): |
|
871 | def __readFirstHeader(self): | |
872 | self.__rdBasicHeader() |
|
872 | self.__rdBasicHeader() | |
873 | self.__rdSystemHeader() |
|
873 | self.__rdSystemHeader() | |
874 | self.__rdRadarControllerHeader() |
|
874 | self.__rdRadarControllerHeader() | |
875 | self.__rdProcessingHeader() |
|
875 | self.__rdProcessingHeader() | |
876 |
|
876 | |||
877 | self.firstHeaderSize = self.basicHeaderObj.size |
|
877 | self.firstHeaderSize = self.basicHeaderObj.size | |
878 |
|
878 | |||
879 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
879 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
880 | if datatype == 0: |
|
880 | if datatype == 0: | |
881 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
881 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
882 | elif datatype == 1: |
|
882 | elif datatype == 1: | |
883 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
883 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
884 | elif datatype == 2: |
|
884 | elif datatype == 2: | |
885 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
885 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
886 | elif datatype == 3: |
|
886 | elif datatype == 3: | |
887 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
887 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
888 | elif datatype == 4: |
|
888 | elif datatype == 4: | |
889 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
889 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
890 | elif datatype == 5: |
|
890 | elif datatype == 5: | |
891 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
891 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
892 | else: |
|
892 | else: | |
893 | raise ValueError, 'Data type was not defined' |
|
893 | raise ValueError, 'Data type was not defined' | |
894 |
|
894 | |||
895 | self.dtype = datatype_str |
|
895 | self.dtype = datatype_str | |
896 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
896 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
897 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
897 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
898 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
898 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
899 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
899 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
900 | self.getBlockDimension() |
|
900 | self.getBlockDimension() | |
901 |
|
901 | |||
902 |
|
902 | |||
903 | def __verifyFile(self, filename, msgFlag=True): |
|
903 | def __verifyFile(self, filename, msgFlag=True): | |
904 | msg = None |
|
904 | msg = None | |
905 | try: |
|
905 | try: | |
906 | fp = open(filename, 'rb') |
|
906 | fp = open(filename, 'rb') | |
907 | currentPosition = fp.tell() |
|
907 | currentPosition = fp.tell() | |
908 | except: |
|
908 | except: | |
909 | if msgFlag: |
|
909 | if msgFlag: | |
910 | print "The file %s can't be opened" % (filename) |
|
910 | print "The file %s can't be opened" % (filename) | |
911 | return False |
|
911 | return False | |
912 |
|
912 | |||
913 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
913 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
914 |
|
914 | |||
915 | if neededSize == 0: |
|
915 | if neededSize == 0: | |
916 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
916 | basicHeaderObj = BasicHeader(LOCALTIME) | |
917 | systemHeaderObj = SystemHeader() |
|
917 | systemHeaderObj = SystemHeader() | |
918 | radarControllerHeaderObj = RadarControllerHeader() |
|
918 | radarControllerHeaderObj = RadarControllerHeader() | |
919 | processingHeaderObj = ProcessingHeader() |
|
919 | processingHeaderObj = ProcessingHeader() | |
920 |
|
920 | |||
921 | try: |
|
921 | try: | |
922 | if not( basicHeaderObj.read(fp) ): raise IOError |
|
922 | if not( basicHeaderObj.read(fp) ): raise IOError | |
923 | if not( systemHeaderObj.read(fp) ): raise IOError |
|
923 | if not( systemHeaderObj.read(fp) ): raise IOError | |
924 | if not( radarControllerHeaderObj.read(fp) ): raise IOError |
|
924 | if not( radarControllerHeaderObj.read(fp) ): raise IOError | |
925 | if not( processingHeaderObj.read(fp) ): raise IOError |
|
925 | if not( processingHeaderObj.read(fp) ): raise IOError | |
926 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
926 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
927 |
|
927 | |||
928 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
928 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
929 |
|
929 | |||
930 | except: |
|
930 | except: | |
931 | if msgFlag: |
|
931 | if msgFlag: | |
932 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
932 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
933 |
|
933 | |||
934 | fp.close() |
|
934 | fp.close() | |
935 | return False |
|
935 | return False | |
936 | else: |
|
936 | else: | |
937 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
937 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
938 |
|
938 | |||
939 | fp.close() |
|
939 | fp.close() | |
940 | fileSize = os.path.getsize(filename) |
|
940 | fileSize = os.path.getsize(filename) | |
941 | currentSize = fileSize - currentPosition |
|
941 | currentSize = fileSize - currentPosition | |
942 | if currentSize < neededSize: |
|
942 | if currentSize < neededSize: | |
943 | if msgFlag and (msg != None): |
|
943 | if msgFlag and (msg != None): | |
944 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
944 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
945 | return False |
|
945 | return False | |
946 |
|
946 | |||
947 | return True |
|
947 | return True | |
948 |
|
948 | |||
949 | def setup(self, |
|
949 | def setup(self, | |
950 | path=None, |
|
950 | path=None, | |
951 | startDate=None, |
|
951 | startDate=None, | |
952 | endDate=None, |
|
952 | endDate=None, | |
953 | startTime=datetime.time(0,0,0), |
|
953 | startTime=datetime.time(0,0,0), | |
954 | endTime=datetime.time(23,59,59), |
|
954 | endTime=datetime.time(23,59,59), | |
955 | set=None, |
|
955 | set=None, | |
956 | expLabel = "", |
|
956 | expLabel = "", | |
957 | ext = None, |
|
957 | ext = None, | |
958 | online = False, |
|
958 | online = False, | |
959 | delay = 60, |
|
959 | delay = 60, | |
960 | walk = True): |
|
960 | walk = True): | |
961 |
|
961 | |||
962 | if path == None: |
|
962 | if path == None: | |
963 | raise ValueError, "The path is not valid" |
|
963 | raise ValueError, "The path is not valid" | |
964 |
|
964 | |||
965 | if ext == None: |
|
965 | if ext == None: | |
966 | ext = self.ext |
|
966 | ext = self.ext | |
967 |
|
967 | |||
968 | if online: |
|
968 | if online: | |
969 | print "Searching files in online mode..." |
|
969 | print "Searching files in online mode..." | |
970 |
|
970 | |||
971 | for nTries in range( self.nTries ): |
|
971 | for nTries in range( self.nTries ): | |
972 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) |
|
972 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) | |
973 |
|
973 | |||
974 | if fullpath: |
|
974 | if fullpath: | |
975 | break |
|
975 | break | |
976 |
|
976 | |||
977 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
977 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
978 | time.sleep( self.delay ) |
|
978 | time.sleep( self.delay ) | |
979 |
|
979 | |||
980 | if not(fullpath): |
|
980 | if not(fullpath): | |
981 | print "There 'isn't valied files in %s" % path |
|
981 | print "There 'isn't valied files in %s" % path | |
982 | return None |
|
982 | return None | |
983 |
|
983 | |||
984 | self.year = year |
|
984 | self.year = year | |
985 | self.doy = doy |
|
985 | self.doy = doy | |
986 | self.set = set - 1 |
|
986 | self.set = set - 1 | |
987 | self.path = path |
|
987 | self.path = path | |
988 | self.foldercounter = foldercounter |
|
988 | self.foldercounter = foldercounter | |
989 | last_set = None |
|
989 | last_set = None | |
990 |
|
990 | |||
991 | else: |
|
991 | else: | |
992 | print "Searching files in offline mode ..." |
|
992 | print "Searching files in offline mode ..." | |
993 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
993 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
994 | startTime=startTime, endTime=endTime, |
|
994 | startTime=startTime, endTime=endTime, | |
995 | set=set, expLabel=expLabel, ext=ext, |
|
995 | set=set, expLabel=expLabel, ext=ext, | |
996 | walk=walk) |
|
996 | walk=walk) | |
997 |
|
997 | |||
998 | if not(pathList): |
|
998 | if not(pathList): | |
999 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
999 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
1000 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
1000 | datetime.datetime.combine(startDate,startTime).ctime(), | |
1001 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
1001 | datetime.datetime.combine(endDate,endTime).ctime()) | |
1002 |
|
1002 | |||
1003 | sys.exit(-1) |
|
1003 | sys.exit(-1) | |
1004 |
|
1004 | |||
1005 |
|
1005 | |||
1006 | self.fileIndex = -1 |
|
1006 | self.fileIndex = -1 | |
1007 | self.pathList = pathList |
|
1007 | self.pathList = pathList | |
1008 | self.filenameList = filenameList |
|
1008 | self.filenameList = filenameList | |
1009 | file_name = os.path.basename(filenameList[-1]) |
|
1009 | file_name = os.path.basename(filenameList[-1]) | |
1010 | basename, ext = os.path.splitext(file_name) |
|
1010 | basename, ext = os.path.splitext(file_name) | |
1011 | last_set = int(basename[-3:]) |
|
1011 | last_set = int(basename[-3:]) | |
1012 |
|
1012 | |||
1013 | self.online = online |
|
1013 | self.online = online | |
1014 | self.delay = delay |
|
1014 | self.delay = delay | |
1015 | ext = ext.lower() |
|
1015 | ext = ext.lower() | |
1016 | self.ext = ext |
|
1016 | self.ext = ext | |
1017 |
|
1017 | |||
1018 | if not(self.setNextFile()): |
|
1018 | if not(self.setNextFile()): | |
1019 | if (startDate!=None) and (endDate!=None): |
|
1019 | if (startDate!=None) and (endDate!=None): | |
1020 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
1020 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
1021 | elif startDate != None: |
|
1021 | elif startDate != None: | |
1022 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
1022 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
1023 | else: |
|
1023 | else: | |
1024 | print "No files" |
|
1024 | print "No files" | |
1025 |
|
1025 | |||
1026 | sys.exit(-1) |
|
1026 | sys.exit(-1) | |
1027 |
|
1027 | |||
1028 | # self.updateDataHeader() |
|
1028 | # self.updateDataHeader() | |
1029 | if last_set != None: |
|
1029 | if last_set != None: | |
1030 | self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock |
|
1030 | self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock | |
1031 | return self.dataOut |
|
1031 | return self.dataOut | |
1032 |
|
1032 | |||
1033 | def getBasicHeader(self): |
|
1033 | def getBasicHeader(self): | |
1034 |
|
1034 | |||
1035 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
1035 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
1036 |
|
1036 | |||
1037 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
1037 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
1038 |
|
1038 | |||
1039 | self.dataOut.timeZone = self.basicHeaderObj.timeZone |
|
1039 | self.dataOut.timeZone = self.basicHeaderObj.timeZone | |
1040 |
|
1040 | |||
1041 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag |
|
1041 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag | |
1042 |
|
1042 | |||
1043 | self.dataOut.errorCount = self.basicHeaderObj.errorCount |
|
1043 | self.dataOut.errorCount = self.basicHeaderObj.errorCount | |
1044 |
|
1044 | |||
1045 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime |
|
1045 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime | |
1046 |
|
1046 | |||
1047 | def getFirstHeader(self): |
|
1047 | def getFirstHeader(self): | |
1048 |
|
1048 | |||
1049 | raise ValueError, "This method has not been implemented" |
|
1049 | raise ValueError, "This method has not been implemented" | |
1050 |
|
1050 | |||
1051 | def getData(): |
|
1051 | def getData(): | |
1052 |
|
1052 | |||
1053 | raise ValueError, "This method has not been implemented" |
|
1053 | raise ValueError, "This method has not been implemented" | |
1054 |
|
1054 | |||
1055 | def hasNotDataInBuffer(): |
|
1055 | def hasNotDataInBuffer(): | |
1056 |
|
1056 | |||
1057 | raise ValueError, "This method has not been implemented" |
|
1057 | raise ValueError, "This method has not been implemented" | |
1058 |
|
1058 | |||
1059 | def readBlock(): |
|
1059 | def readBlock(): | |
1060 |
|
1060 | |||
1061 | raise ValueError, "This method has not been implemented" |
|
1061 | raise ValueError, "This method has not been implemented" | |
1062 |
|
1062 | |||
1063 | def isEndProcess(self): |
|
1063 | def isEndProcess(self): | |
1064 |
|
1064 | |||
1065 | return self.flagNoMoreFiles |
|
1065 | return self.flagNoMoreFiles | |
1066 |
|
1066 | |||
1067 | def printReadBlocks(self): |
|
1067 | def printReadBlocks(self): | |
1068 |
|
1068 | |||
1069 | print "Number of read blocks per file %04d" %self.nReadBlocks |
|
1069 | print "Number of read blocks per file %04d" %self.nReadBlocks | |
1070 |
|
1070 | |||
1071 | def printTotalBlocks(self): |
|
1071 | def printTotalBlocks(self): | |
1072 |
|
1072 | |||
1073 | print "Number of read blocks %04d" %self.nTotalBlocks |
|
1073 | print "Number of read blocks %04d" %self.nTotalBlocks | |
1074 |
|
1074 | |||
1075 | def printNumberOfBlock(self): |
|
1075 | def printNumberOfBlock(self): | |
1076 |
|
1076 | |||
1077 | if self.flagIsNewBlock: |
|
1077 | if self.flagIsNewBlock: | |
1078 | print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) |
|
1078 | print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) | |
1079 | self.dataOut.blocknow = self.basicHeaderObj.dataBlock |
|
1079 | self.dataOut.blocknow = self.basicHeaderObj.dataBlock | |
1080 | def printInfo(self): |
|
1080 | def printInfo(self): | |
1081 |
|
1081 | |||
1082 | if self.__printInfo == False: |
|
1082 | if self.__printInfo == False: | |
1083 | return |
|
1083 | return | |
1084 |
|
1084 | |||
1085 | self.basicHeaderObj.printInfo() |
|
1085 | self.basicHeaderObj.printInfo() | |
1086 | self.systemHeaderObj.printInfo() |
|
1086 | self.systemHeaderObj.printInfo() | |
1087 | self.radarControllerHeaderObj.printInfo() |
|
1087 | self.radarControllerHeaderObj.printInfo() | |
1088 | self.processingHeaderObj.printInfo() |
|
1088 | self.processingHeaderObj.printInfo() | |
1089 |
|
1089 | |||
1090 | self.__printInfo = False |
|
1090 | self.__printInfo = False | |
1091 |
|
1091 | |||
1092 |
|
1092 | |||
1093 | def run(self, **kwargs): |
|
1093 | def run(self, **kwargs): | |
1094 |
|
1094 | |||
1095 | if not(self.isConfig): |
|
1095 | if not(self.isConfig): | |
1096 |
|
1096 | |||
1097 | # self.dataOut = dataOut |
|
1097 | # self.dataOut = dataOut | |
1098 | self.setup(**kwargs) |
|
1098 | self.setup(**kwargs) | |
1099 | self.isConfig = True |
|
1099 | self.isConfig = True | |
1100 |
|
1100 | |||
1101 | self.getData() |
|
1101 | self.getData() | |
1102 |
|
1102 | |||
1103 | class JRODataWriter(JRODataIO, Operation): |
|
1103 | class JRODataWriter(JRODataIO, Operation): | |
1104 |
|
1104 | |||
1105 | """ |
|
1105 | """ | |
1106 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
1106 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
1107 | de los datos siempre se realiza por bloques. |
|
1107 | de los datos siempre se realiza por bloques. | |
1108 | """ |
|
1108 | """ | |
1109 |
|
1109 | |||
1110 | blockIndex = 0 |
|
1110 | blockIndex = 0 | |
1111 |
|
1111 | |||
1112 | path = None |
|
1112 | path = None | |
1113 |
|
1113 | |||
1114 | setFile = None |
|
1114 | setFile = None | |
1115 |
|
1115 | |||
1116 | profilesPerBlock = None |
|
1116 | profilesPerBlock = None | |
1117 |
|
1117 | |||
1118 | blocksPerFile = None |
|
1118 | blocksPerFile = None | |
1119 |
|
1119 | |||
1120 | nWriteBlocks = 0 |
|
1120 | nWriteBlocks = 0 | |
1121 |
|
1121 | |||
1122 | def __init__(self, dataOut=None): |
|
1122 | def __init__(self, dataOut=None): | |
1123 | raise ValueError, "Not implemented" |
|
1123 | raise ValueError, "Not implemented" | |
1124 |
|
1124 | |||
1125 |
|
1125 | |||
1126 | def hasAllDataInBuffer(self): |
|
1126 | def hasAllDataInBuffer(self): | |
1127 | raise ValueError, "Not implemented" |
|
1127 | raise ValueError, "Not implemented" | |
1128 |
|
1128 | |||
1129 |
|
1129 | |||
1130 | def setBlockDimension(self): |
|
1130 | def setBlockDimension(self): | |
1131 | raise ValueError, "Not implemented" |
|
1131 | raise ValueError, "Not implemented" | |
1132 |
|
1132 | |||
1133 |
|
1133 | |||
1134 | def writeBlock(self): |
|
1134 | def writeBlock(self): | |
1135 | raise ValueError, "No implemented" |
|
1135 | raise ValueError, "No implemented" | |
1136 |
|
1136 | |||
1137 |
|
1137 | |||
1138 | def putData(self): |
|
1138 | def putData(self): | |
1139 | raise ValueError, "No implemented" |
|
1139 | raise ValueError, "No implemented" | |
1140 |
|
1140 | |||
1141 |
|
1141 | |||
1142 | def setBasicHeader(self): |
|
1142 | def setBasicHeader(self): | |
1143 |
|
1143 | |||
1144 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
1144 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
1145 | self.basicHeaderObj.version = self.versionFile |
|
1145 | self.basicHeaderObj.version = self.versionFile | |
1146 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
1146 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
1147 |
|
1147 | |||
1148 | utc = numpy.floor(self.dataOut.utctime) |
|
1148 | utc = numpy.floor(self.dataOut.utctime) | |
1149 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
1149 | milisecond = (self.dataOut.utctime - utc)* 1000.0 | |
1150 |
|
1150 | |||
1151 | self.basicHeaderObj.utc = utc |
|
1151 | self.basicHeaderObj.utc = utc | |
1152 | self.basicHeaderObj.miliSecond = milisecond |
|
1152 | self.basicHeaderObj.miliSecond = milisecond | |
1153 | self.basicHeaderObj.timeZone = self.dataOut.timeZone |
|
1153 | self.basicHeaderObj.timeZone = self.dataOut.timeZone | |
1154 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag |
|
1154 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag | |
1155 | self.basicHeaderObj.errorCount = self.dataOut.errorCount |
|
1155 | self.basicHeaderObj.errorCount = self.dataOut.errorCount | |
1156 |
|
1156 | |||
1157 | def setFirstHeader(self): |
|
1157 | def setFirstHeader(self): | |
1158 | """ |
|
1158 | """ | |
1159 | Obtiene una copia del First Header |
|
1159 | Obtiene una copia del First Header | |
1160 |
|
1160 | |||
1161 | Affected: |
|
1161 | Affected: | |
1162 |
|
1162 | |||
1163 | self.basicHeaderObj |
|
1163 | self.basicHeaderObj | |
1164 | self.systemHeaderObj |
|
1164 | self.systemHeaderObj | |
1165 | self.radarControllerHeaderObj |
|
1165 | self.radarControllerHeaderObj | |
1166 | self.processingHeaderObj self. |
|
1166 | self.processingHeaderObj self. | |
1167 |
|
1167 | |||
1168 | Return: |
|
1168 | Return: | |
1169 | None |
|
1169 | None | |
1170 | """ |
|
1170 | """ | |
1171 |
|
1171 | |||
1172 | raise ValueError, "No implemented" |
|
1172 | raise ValueError, "No implemented" | |
1173 |
|
1173 | |||
1174 | def __writeFirstHeader(self): |
|
1174 | def __writeFirstHeader(self): | |
1175 | """ |
|
1175 | """ | |
1176 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
1176 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
1177 |
|
1177 | |||
1178 | Affected: |
|
1178 | Affected: | |
1179 | __dataType |
|
1179 | __dataType | |
1180 |
|
1180 | |||
1181 | Return: |
|
1181 | Return: | |
1182 | None |
|
1182 | None | |
1183 | """ |
|
1183 | """ | |
1184 |
|
1184 | |||
1185 | # CALCULAR PARAMETROS |
|
1185 | # CALCULAR PARAMETROS | |
1186 |
|
1186 | |||
1187 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
1187 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
1188 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
1188 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
1189 |
|
1189 | |||
1190 | self.basicHeaderObj.write(self.fp) |
|
1190 | self.basicHeaderObj.write(self.fp) | |
1191 | self.systemHeaderObj.write(self.fp) |
|
1191 | self.systemHeaderObj.write(self.fp) | |
1192 | self.radarControllerHeaderObj.write(self.fp) |
|
1192 | self.radarControllerHeaderObj.write(self.fp) | |
1193 | self.processingHeaderObj.write(self.fp) |
|
1193 | self.processingHeaderObj.write(self.fp) | |
1194 |
|
1194 | |||
1195 | self.dtype = self.dataOut.dtype |
|
1195 | self.dtype = self.dataOut.dtype | |
1196 |
|
1196 | |||
1197 | def __setNewBlock(self): |
|
1197 | def __setNewBlock(self): | |
1198 | """ |
|
1198 | """ | |
1199 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
1199 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
1200 |
|
1200 | |||
1201 | Return: |
|
1201 | Return: | |
1202 | 0 : si no pudo escribir nada |
|
1202 | 0 : si no pudo escribir nada | |
1203 | 1 : Si escribio el Basic el First Header |
|
1203 | 1 : Si escribio el Basic el First Header | |
1204 | """ |
|
1204 | """ | |
1205 | if self.fp == None: |
|
1205 | if self.fp == None: | |
1206 | self.setNextFile() |
|
1206 | self.setNextFile() | |
1207 |
|
1207 | |||
1208 | if self.flagIsNewFile: |
|
1208 | if self.flagIsNewFile: | |
1209 | return 1 |
|
1209 | return 1 | |
1210 |
|
1210 | |||
1211 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
1211 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
1212 | self.basicHeaderObj.write(self.fp) |
|
1212 | self.basicHeaderObj.write(self.fp) | |
1213 | return 1 |
|
1213 | return 1 | |
1214 |
|
1214 | |||
1215 | if not( self.setNextFile() ): |
|
1215 | if not( self.setNextFile() ): | |
1216 | return 0 |
|
1216 | return 0 | |
1217 |
|
1217 | |||
1218 | return 1 |
|
1218 | return 1 | |
1219 |
|
1219 | |||
1220 |
|
1220 | |||
1221 | def writeNextBlock(self): |
|
1221 | def writeNextBlock(self): | |
1222 | """ |
|
1222 | """ | |
1223 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1223 | Selecciona el bloque siguiente de datos y los escribe en un file | |
1224 |
|
1224 | |||
1225 | Return: |
|
1225 | Return: | |
1226 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1226 | 0 : Si no hizo pudo escribir el bloque de datos | |
1227 | 1 : Si no pudo escribir el bloque de datos |
|
1227 | 1 : Si no pudo escribir el bloque de datos | |
1228 | """ |
|
1228 | """ | |
1229 | if not( self.__setNewBlock() ): |
|
1229 | if not( self.__setNewBlock() ): | |
1230 | return 0 |
|
1230 | return 0 | |
1231 |
|
1231 | |||
1232 | self.writeBlock() |
|
1232 | self.writeBlock() | |
1233 |
|
1233 | |||
1234 | return 1 |
|
1234 | return 1 | |
1235 |
|
1235 | |||
1236 | def setNextFile(self): |
|
1236 | def setNextFile(self): | |
1237 | """ |
|
1237 | """ | |
1238 | Determina el siguiente file que sera escrito |
|
1238 | Determina el siguiente file que sera escrito | |
1239 |
|
1239 | |||
1240 | Affected: |
|
1240 | Affected: | |
1241 | self.filename |
|
1241 | self.filename | |
1242 | self.subfolder |
|
1242 | self.subfolder | |
1243 | self.fp |
|
1243 | self.fp | |
1244 | self.setFile |
|
1244 | self.setFile | |
1245 | self.flagIsNewFile |
|
1245 | self.flagIsNewFile | |
1246 |
|
1246 | |||
1247 | Return: |
|
1247 | Return: | |
1248 | 0 : Si el archivo no puede ser escrito |
|
1248 | 0 : Si el archivo no puede ser escrito | |
1249 | 1 : Si el archivo esta listo para ser escrito |
|
1249 | 1 : Si el archivo esta listo para ser escrito | |
1250 | """ |
|
1250 | """ | |
1251 | ext = self.ext |
|
1251 | ext = self.ext | |
1252 | path = self.path |
|
1252 | path = self.path | |
1253 |
|
1253 | |||
1254 | if self.fp != None: |
|
1254 | if self.fp != None: | |
1255 | self.fp.close() |
|
1255 | self.fp.close() | |
1256 |
|
1256 | |||
1257 | timeTuple = time.localtime( self.dataOut.utctime) |
|
1257 | timeTuple = time.localtime( self.dataOut.utctime) | |
1258 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1258 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
1259 |
|
1259 | |||
1260 | fullpath = os.path.join( path, subfolder ) |
|
1260 | fullpath = os.path.join( path, subfolder ) | |
1261 | if not( os.path.exists(fullpath) ): |
|
1261 | if not( os.path.exists(fullpath) ): | |
1262 | os.mkdir(fullpath) |
|
1262 | os.mkdir(fullpath) | |
1263 | self.setFile = -1 #inicializo mi contador de seteo |
|
1263 | self.setFile = -1 #inicializo mi contador de seteo | |
1264 | else: |
|
1264 | else: | |
1265 | filesList = os.listdir( fullpath ) |
|
1265 | filesList = os.listdir( fullpath ) | |
1266 | if len( filesList ) > 0: |
|
1266 | if len( filesList ) > 0: | |
1267 | filesList = sorted( filesList, key=str.lower ) |
|
1267 | filesList = sorted( filesList, key=str.lower ) | |
1268 | filen = filesList[-1] |
|
1268 | filen = filesList[-1] | |
1269 | # el filename debera tener el siguiente formato |
|
1269 | # el filename debera tener el siguiente formato | |
1270 | # 0 1234 567 89A BCDE (hex) |
|
1270 | # 0 1234 567 89A BCDE (hex) | |
1271 | # x YYYY DDD SSS .ext |
|
1271 | # x YYYY DDD SSS .ext | |
1272 | if isNumber( filen[8:11] ): |
|
1272 | if isNumber( filen[8:11] ): | |
1273 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
1273 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
1274 | else: |
|
1274 | else: | |
1275 | self.setFile = -1 |
|
1275 | self.setFile = -1 | |
1276 | else: |
|
1276 | else: | |
1277 | self.setFile = -1 #inicializo mi contador de seteo |
|
1277 | self.setFile = -1 #inicializo mi contador de seteo | |
1278 |
|
1278 | |||
1279 | setFile = self.setFile |
|
1279 | setFile = self.setFile | |
1280 | setFile += 1 |
|
1280 | setFile += 1 | |
1281 |
|
1281 | |||
1282 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
1282 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
1283 | timeTuple.tm_year, |
|
1283 | timeTuple.tm_year, | |
1284 | timeTuple.tm_yday, |
|
1284 | timeTuple.tm_yday, | |
1285 | setFile, |
|
1285 | setFile, | |
1286 | ext ) |
|
1286 | ext ) | |
1287 |
|
1287 | |||
1288 | filename = os.path.join( path, subfolder, file ) |
|
1288 | filename = os.path.join( path, subfolder, file ) | |
1289 |
|
1289 | |||
1290 | fp = open( filename,'wb' ) |
|
1290 | fp = open( filename,'wb' ) | |
1291 |
|
1291 | |||
1292 | self.blockIndex = 0 |
|
1292 | self.blockIndex = 0 | |
1293 |
|
1293 | |||
1294 | #guardando atributos |
|
1294 | #guardando atributos | |
1295 | self.filename = filename |
|
1295 | self.filename = filename | |
1296 | self.subfolder = subfolder |
|
1296 | self.subfolder = subfolder | |
1297 | self.fp = fp |
|
1297 | self.fp = fp | |
1298 | self.setFile = setFile |
|
1298 | self.setFile = setFile | |
1299 | self.flagIsNewFile = 1 |
|
1299 | self.flagIsNewFile = 1 | |
1300 |
|
1300 | |||
1301 | self.setFirstHeader() |
|
1301 | self.setFirstHeader() | |
1302 |
|
1302 | |||
1303 | print 'Writing the file: %s'%self.filename |
|
1303 | print 'Writing the file: %s'%self.filename | |
1304 |
|
1304 | |||
1305 | self.__writeFirstHeader() |
|
1305 | self.__writeFirstHeader() | |
1306 |
|
1306 | |||
1307 | return 1 |
|
1307 | return 1 | |
1308 |
|
1308 | |||
1309 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=0, ext=None): |
|
1309 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=0, ext=None): | |
1310 | """ |
|
1310 | """ | |
1311 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1311 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1312 |
|
1312 | |||
1313 | Inputs: |
|
1313 | Inputs: | |
1314 | path : el path destino en el cual se escribiran los files a crear |
|
1314 | path : el path destino en el cual se escribiran los files a crear | |
1315 | format : formato en el cual sera salvado un file |
|
1315 | format : formato en el cual sera salvado un file | |
1316 | set : el setebo del file |
|
1316 | set : el setebo del file | |
1317 |
|
1317 | |||
1318 | Return: |
|
1318 | Return: | |
1319 | 0 : Si no realizo un buen seteo |
|
1319 | 0 : Si no realizo un buen seteo | |
1320 | 1 : Si realizo un buen seteo |
|
1320 | 1 : Si realizo un buen seteo | |
1321 | """ |
|
1321 | """ | |
1322 |
|
1322 | |||
1323 | if ext == None: |
|
1323 | if ext == None: | |
1324 | ext = self.ext |
|
1324 | ext = self.ext | |
1325 |
|
1325 | |||
1326 | ext = ext.lower() |
|
1326 | ext = ext.lower() | |
1327 |
|
1327 | |||
1328 | self.ext = ext |
|
1328 | self.ext = ext | |
1329 |
|
1329 | |||
1330 | self.path = path |
|
1330 | self.path = path | |
1331 |
|
1331 | |||
1332 | self.setFile = set - 1 |
|
1332 | self.setFile = set - 1 | |
1333 |
|
1333 | |||
1334 | self.blocksPerFile = blocksPerFile |
|
1334 | self.blocksPerFile = blocksPerFile | |
1335 |
|
1335 | |||
1336 | self.profilesPerBlock = profilesPerBlock |
|
1336 | self.profilesPerBlock = profilesPerBlock | |
1337 |
|
1337 | |||
1338 | self.dataOut = dataOut |
|
1338 | self.dataOut = dataOut | |
1339 |
|
1339 | |||
1340 | if not(self.setNextFile()): |
|
1340 | if not(self.setNextFile()): | |
1341 | print "There isn't a next file" |
|
1341 | print "There isn't a next file" | |
1342 | return 0 |
|
1342 | return 0 | |
1343 |
|
1343 | |||
1344 | self.setBlockDimension() |
|
1344 | self.setBlockDimension() | |
1345 |
|
1345 | |||
1346 | return 1 |
|
1346 | return 1 | |
1347 |
|
1347 | |||
1348 | def run(self, dataOut, **kwargs): |
|
1348 | def run(self, dataOut, **kwargs): | |
1349 |
|
1349 | |||
1350 | if not(self.isConfig): |
|
1350 | if not(self.isConfig): | |
1351 |
|
1351 | |||
1352 | self.setup(dataOut, **kwargs) |
|
1352 | self.setup(dataOut, **kwargs) | |
1353 | self.isConfig = True |
|
1353 | self.isConfig = True | |
1354 |
|
1354 | |||
1355 | self.putData() |
|
1355 | self.putData() | |
1356 |
|
1356 | |||
1357 | class VoltageReader(JRODataReader): |
|
1357 | class VoltageReader(JRODataReader): | |
1358 | """ |
|
1358 | """ | |
1359 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
1359 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
1360 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
1360 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
1361 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
1361 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
1362 |
|
1362 | |||
1363 | perfiles * alturas * canales |
|
1363 | perfiles * alturas * canales | |
1364 |
|
1364 | |||
1365 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1365 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1366 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
1366 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
1367 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
1367 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
1368 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1368 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1369 |
|
1369 | |||
1370 | Example: |
|
1370 | Example: | |
1371 |
|
1371 | |||
1372 | dpath = "/home/myuser/data" |
|
1372 | dpath = "/home/myuser/data" | |
1373 |
|
1373 | |||
1374 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1374 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1375 |
|
1375 | |||
1376 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1376 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1377 |
|
1377 | |||
1378 | readerObj = VoltageReader() |
|
1378 | readerObj = VoltageReader() | |
1379 |
|
1379 | |||
1380 | readerObj.setup(dpath, startTime, endTime) |
|
1380 | readerObj.setup(dpath, startTime, endTime) | |
1381 |
|
1381 | |||
1382 | while(True): |
|
1382 | while(True): | |
1383 |
|
1383 | |||
1384 | #to get one profile |
|
1384 | #to get one profile | |
1385 | profile = readerObj.getData() |
|
1385 | profile = readerObj.getData() | |
1386 |
|
1386 | |||
1387 | #print the profile |
|
1387 | #print the profile | |
1388 | print profile |
|
1388 | print profile | |
1389 |
|
1389 | |||
1390 | #If you want to see all datablock |
|
1390 | #If you want to see all datablock | |
1391 | print readerObj.datablock |
|
1391 | print readerObj.datablock | |
1392 |
|
1392 | |||
1393 | if readerObj.flagNoMoreFiles: |
|
1393 | if readerObj.flagNoMoreFiles: | |
1394 | break |
|
1394 | break | |
1395 |
|
1395 | |||
1396 | """ |
|
1396 | """ | |
1397 |
|
1397 | |||
1398 | ext = ".r" |
|
1398 | ext = ".r" | |
1399 |
|
1399 | |||
1400 | optchar = "D" |
|
1400 | optchar = "D" | |
1401 | dataOut = None |
|
1401 | dataOut = None | |
1402 |
|
1402 | |||
1403 |
|
1403 | |||
1404 | def __init__(self): |
|
1404 | def __init__(self): | |
1405 | """ |
|
1405 | """ | |
1406 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
1406 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
1407 |
|
1407 | |||
1408 | Input: |
|
1408 | Input: | |
1409 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
1409 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
1410 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1410 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1411 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1411 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1412 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1412 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1413 | bloque de datos. |
|
1413 | bloque de datos. | |
1414 | Si este parametro no es pasado se creara uno internamente. |
|
1414 | Si este parametro no es pasado se creara uno internamente. | |
1415 |
|
1415 | |||
1416 | Variables afectadas: |
|
1416 | Variables afectadas: | |
1417 | self.dataOut |
|
1417 | self.dataOut | |
1418 |
|
1418 | |||
1419 | Return: |
|
1419 | Return: | |
1420 | None |
|
1420 | None | |
1421 | """ |
|
1421 | """ | |
1422 |
|
1422 | |||
1423 | self.isConfig = False |
|
1423 | self.isConfig = False | |
1424 |
|
1424 | |||
1425 | self.datablock = None |
|
1425 | self.datablock = None | |
1426 |
|
1426 | |||
1427 | self.utc = 0 |
|
1427 | self.utc = 0 | |
1428 |
|
1428 | |||
1429 | self.ext = ".r" |
|
1429 | self.ext = ".r" | |
1430 |
|
1430 | |||
1431 | self.optchar = "D" |
|
1431 | self.optchar = "D" | |
1432 |
|
1432 | |||
1433 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1433 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1434 |
|
1434 | |||
1435 | self.systemHeaderObj = SystemHeader() |
|
1435 | self.systemHeaderObj = SystemHeader() | |
1436 |
|
1436 | |||
1437 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1437 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1438 |
|
1438 | |||
1439 | self.processingHeaderObj = ProcessingHeader() |
|
1439 | self.processingHeaderObj = ProcessingHeader() | |
1440 |
|
1440 | |||
1441 | self.online = 0 |
|
1441 | self.online = 0 | |
1442 |
|
1442 | |||
1443 | self.fp = None |
|
1443 | self.fp = None | |
1444 |
|
1444 | |||
1445 | self.idFile = None |
|
1445 | self.idFile = None | |
1446 |
|
1446 | |||
1447 | self.dtype = None |
|
1447 | self.dtype = None | |
1448 |
|
1448 | |||
1449 | self.fileSizeByHeader = None |
|
1449 | self.fileSizeByHeader = None | |
1450 |
|
1450 | |||
1451 | self.filenameList = [] |
|
1451 | self.filenameList = [] | |
1452 |
|
1452 | |||
1453 | self.filename = None |
|
1453 | self.filename = None | |
1454 |
|
1454 | |||
1455 | self.fileSize = None |
|
1455 | self.fileSize = None | |
1456 |
|
1456 | |||
1457 | self.firstHeaderSize = 0 |
|
1457 | self.firstHeaderSize = 0 | |
1458 |
|
1458 | |||
1459 | self.basicHeaderSize = 24 |
|
1459 | self.basicHeaderSize = 24 | |
1460 |
|
1460 | |||
1461 | self.pathList = [] |
|
1461 | self.pathList = [] | |
1462 |
|
1462 | |||
1463 | self.filenameList = [] |
|
1463 | self.filenameList = [] | |
1464 |
|
1464 | |||
1465 | self.lastUTTime = 0 |
|
1465 | self.lastUTTime = 0 | |
1466 |
|
1466 | |||
1467 | self.maxTimeStep = 30 |
|
1467 | self.maxTimeStep = 30 | |
1468 |
|
1468 | |||
1469 | self.flagNoMoreFiles = 0 |
|
1469 | self.flagNoMoreFiles = 0 | |
1470 |
|
1470 | |||
1471 | self.set = 0 |
|
1471 | self.set = 0 | |
1472 |
|
1472 | |||
1473 | self.path = None |
|
1473 | self.path = None | |
1474 |
|
1474 | |||
1475 | self.profileIndex = 2**32-1 |
|
1475 | self.profileIndex = 2**32-1 | |
1476 |
|
1476 | |||
1477 | self.delay = 3 #seconds |
|
1477 | self.delay = 3 #seconds | |
1478 |
|
1478 | |||
1479 | self.nTries = 3 #quantity tries |
|
1479 | self.nTries = 3 #quantity tries | |
1480 |
|
1480 | |||
1481 | self.nFiles = 3 #number of files for searching |
|
1481 | self.nFiles = 3 #number of files for searching | |
1482 |
|
1482 | |||
1483 | self.nReadBlocks = 0 |
|
1483 | self.nReadBlocks = 0 | |
1484 |
|
1484 | |||
1485 | self.flagIsNewFile = 1 |
|
1485 | self.flagIsNewFile = 1 | |
1486 |
|
1486 | |||
1487 | self.__isFirstTimeOnline = 1 |
|
1487 | self.__isFirstTimeOnline = 1 | |
1488 |
|
1488 | |||
1489 | self.ippSeconds = 0 |
|
1489 | self.ippSeconds = 0 | |
1490 |
|
1490 | |||
1491 | self.flagTimeBlock = 0 |
|
1491 | self.flagTimeBlock = 0 | |
1492 |
|
1492 | |||
1493 | self.flagIsNewBlock = 0 |
|
1493 | self.flagIsNewBlock = 0 | |
1494 |
|
1494 | |||
1495 | self.nTotalBlocks = 0 |
|
1495 | self.nTotalBlocks = 0 | |
1496 |
|
1496 | |||
1497 | self.blocksize = 0 |
|
1497 | self.blocksize = 0 | |
1498 |
|
1498 | |||
1499 | self.dataOut = self.createObjByDefault() |
|
1499 | self.dataOut = self.createObjByDefault() | |
1500 |
|
1500 | |||
1501 | def createObjByDefault(self): |
|
1501 | def createObjByDefault(self): | |
1502 |
|
1502 | |||
1503 | dataObj = Voltage() |
|
1503 | dataObj = Voltage() | |
1504 |
|
1504 | |||
1505 | return dataObj |
|
1505 | return dataObj | |
1506 |
|
1506 | |||
1507 | def __hasNotDataInBuffer(self): |
|
1507 | def __hasNotDataInBuffer(self): | |
1508 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1508 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1509 | return 1 |
|
1509 | return 1 | |
1510 | return 0 |
|
1510 | return 0 | |
1511 |
|
1511 | |||
1512 |
|
1512 | |||
1513 | def getBlockDimension(self): |
|
1513 | def getBlockDimension(self): | |
1514 | """ |
|
1514 | """ | |
1515 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1515 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1516 |
|
1516 | |||
1517 | Affected: |
|
1517 | Affected: | |
1518 | self.blocksize |
|
1518 | self.blocksize | |
1519 |
|
1519 | |||
1520 | Return: |
|
1520 | Return: | |
1521 | None |
|
1521 | None | |
1522 | """ |
|
1522 | """ | |
1523 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
1523 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
1524 | self.blocksize = pts2read |
|
1524 | self.blocksize = pts2read | |
1525 |
|
1525 | |||
1526 |
|
1526 | |||
1527 | def readBlock(self): |
|
1527 | def readBlock(self): | |
1528 | """ |
|
1528 | """ | |
1529 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1529 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
1530 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1530 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1531 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1531 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1532 | es seteado a 0 |
|
1532 | es seteado a 0 | |
1533 |
|
1533 | |||
1534 | Inputs: |
|
1534 | Inputs: | |
1535 | None |
|
1535 | None | |
1536 |
|
1536 | |||
1537 | Return: |
|
1537 | Return: | |
1538 | None |
|
1538 | None | |
1539 |
|
1539 | |||
1540 | Affected: |
|
1540 | Affected: | |
1541 | self.profileIndex |
|
1541 | self.profileIndex | |
1542 | self.datablock |
|
1542 | self.datablock | |
1543 | self.flagIsNewFile |
|
1543 | self.flagIsNewFile | |
1544 | self.flagIsNewBlock |
|
1544 | self.flagIsNewBlock | |
1545 | self.nTotalBlocks |
|
1545 | self.nTotalBlocks | |
1546 |
|
1546 | |||
1547 | Exceptions: |
|
1547 | Exceptions: | |
1548 | Si un bloque leido no es un bloque valido |
|
1548 | Si un bloque leido no es un bloque valido | |
1549 | """ |
|
1549 | """ | |
1550 | current_pointer_location = self.fp.tell() |
|
1550 | current_pointer_location = self.fp.tell() | |
1551 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1551 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
1552 |
|
1552 | |||
1553 | try: |
|
1553 | try: | |
1554 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1554 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
1555 | except: |
|
1555 | except: | |
1556 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
1556 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
1557 |
|
1557 | |||
1558 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
1558 | if self.waitDataBlock(pointer_location=current_pointer_location): | |
1559 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1559 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
1560 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1560 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
1561 | # return 0 |
|
1561 | # return 0 | |
1562 |
|
1562 | |||
1563 | junk = numpy.transpose(junk, (2,0,1)) |
|
1563 | junk = numpy.transpose(junk, (2,0,1)) | |
1564 | self.datablock = junk['real'] + junk['imag']*1j |
|
1564 | self.datablock = junk['real'] + junk['imag']*1j | |
1565 |
|
1565 | |||
1566 | self.profileIndex = 0 |
|
1566 | self.profileIndex = 0 | |
1567 |
|
1567 | |||
1568 | self.flagIsNewFile = 0 |
|
1568 | self.flagIsNewFile = 0 | |
1569 | self.flagIsNewBlock = 1 |
|
1569 | self.flagIsNewBlock = 1 | |
1570 |
|
1570 | |||
1571 | self.nTotalBlocks += 1 |
|
1571 | self.nTotalBlocks += 1 | |
1572 | self.nReadBlocks += 1 |
|
1572 | self.nReadBlocks += 1 | |
1573 |
|
1573 | |||
1574 | return 1 |
|
1574 | return 1 | |
1575 |
|
1575 | |||
1576 | def getFirstHeader(self): |
|
1576 | def getFirstHeader(self): | |
1577 |
|
1577 | |||
1578 | self.dataOut.dtype = self.dtype |
|
1578 | self.dataOut.dtype = self.dtype | |
1579 |
|
1579 | |||
1580 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
1580 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
1581 |
|
1581 | |||
1582 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1582 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
1583 |
|
1583 | |||
1584 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
1584 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
1585 |
|
1585 | |||
1586 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
1586 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
1587 |
|
1587 | |||
1588 | self.dataOut.ippSeconds = self.ippSeconds |
|
1588 | self.dataOut.ippSeconds = self.ippSeconds | |
1589 |
|
1589 | |||
1590 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt |
|
1590 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |
1591 |
|
1591 | |||
1592 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
1592 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
1593 |
|
1593 | |||
1594 | self.dataOut.flagShiftFFT = False |
|
1594 | self.dataOut.flagShiftFFT = False | |
1595 |
|
1595 | |||
1596 | if self.radarControllerHeaderObj.code != None: |
|
1596 | if self.radarControllerHeaderObj.code != None: | |
1597 |
|
1597 | |||
1598 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
1598 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
1599 |
|
1599 | |||
1600 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
1600 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
1601 |
|
1601 | |||
1602 | self.dataOut.code = self.radarControllerHeaderObj.code |
|
1602 | self.dataOut.code = self.radarControllerHeaderObj.code | |
1603 |
|
1603 | |||
1604 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
1604 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
1605 |
|
1605 | |||
1606 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
1606 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
1607 |
|
1607 | |||
1608 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
1608 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |
1609 |
|
1609 | |||
1610 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip |
|
1610 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip | |
1611 |
|
1611 | |||
1612 | self.dataOut.flagShiftFFT = False |
|
1612 | self.dataOut.flagShiftFFT = False | |
1613 |
|
1613 | |||
1614 | def getData(self): |
|
1614 | def getData(self): | |
1615 | """ |
|
1615 | """ | |
1616 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
1616 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
1617 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1617 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1618 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1618 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1619 |
|
1619 | |||
1620 | Ademas incrementa el contador del buffer en 1. |
|
1620 | Ademas incrementa el contador del buffer en 1. | |
1621 |
|
1621 | |||
1622 | Return: |
|
1622 | Return: | |
1623 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
1623 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
1624 | buffer. Si no hay mas archivos a leer retorna None. |
|
1624 | buffer. Si no hay mas archivos a leer retorna None. | |
1625 |
|
1625 | |||
1626 | Variables afectadas: |
|
1626 | Variables afectadas: | |
1627 | self.dataOut |
|
1627 | self.dataOut | |
1628 | self.profileIndex |
|
1628 | self.profileIndex | |
1629 |
|
1629 | |||
1630 | Affected: |
|
1630 | Affected: | |
1631 | self.dataOut |
|
1631 | self.dataOut | |
1632 | self.profileIndex |
|
1632 | self.profileIndex | |
1633 | self.flagTimeBlock |
|
1633 | self.flagTimeBlock | |
1634 | self.flagIsNewBlock |
|
1634 | self.flagIsNewBlock | |
1635 | """ |
|
1635 | """ | |
1636 |
|
1636 | |||
1637 | if self.flagNoMoreFiles: |
|
1637 | if self.flagNoMoreFiles: | |
1638 | self.dataOut.flagNoData = True |
|
1638 | self.dataOut.flagNoData = True | |
1639 | print 'Process finished' |
|
1639 | print 'Process finished' | |
1640 | return 0 |
|
1640 | return 0 | |
1641 |
|
1641 | |||
1642 | self.flagTimeBlock = 0 |
|
1642 | self.flagTimeBlock = 0 | |
1643 | self.flagIsNewBlock = 0 |
|
1643 | self.flagIsNewBlock = 0 | |
1644 |
|
1644 | |||
1645 | if self.__hasNotDataInBuffer(): |
|
1645 | if self.__hasNotDataInBuffer(): | |
1646 |
|
1646 | |||
1647 | if not( self.readNextBlock() ): |
|
1647 | if not( self.readNextBlock() ): | |
1648 | return 0 |
|
1648 | return 0 | |
1649 |
|
1649 | |||
1650 | self.getFirstHeader() |
|
1650 | self.getFirstHeader() | |
1651 |
|
1651 | |||
1652 | if self.datablock == None: |
|
1652 | if self.datablock == None: | |
1653 | self.dataOut.flagNoData = True |
|
1653 | self.dataOut.flagNoData = True | |
1654 | return 0 |
|
1654 | return 0 | |
1655 |
|
1655 | |||
1656 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
1656 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
1657 |
|
1657 | |||
1658 | self.dataOut.flagNoData = False |
|
1658 | self.dataOut.flagNoData = False | |
1659 |
|
1659 | |||
1660 | self.getBasicHeader() |
|
1660 | self.getBasicHeader() | |
1661 |
|
1661 | |||
1662 | self.profileIndex += 1 |
|
1662 | self.profileIndex += 1 | |
1663 |
|
1663 | |||
1664 | self.dataOut.realtime = self.online |
|
1664 | self.dataOut.realtime = self.online | |
1665 |
|
1665 | |||
1666 | return self.dataOut.data |
|
1666 | return self.dataOut.data | |
1667 |
|
1667 | |||
1668 |
|
1668 | |||
1669 | class VoltageWriter(JRODataWriter): |
|
1669 | class VoltageWriter(JRODataWriter): | |
1670 | """ |
|
1670 | """ | |
1671 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
1671 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
1672 | de los datos siempre se realiza por bloques. |
|
1672 | de los datos siempre se realiza por bloques. | |
1673 | """ |
|
1673 | """ | |
1674 |
|
1674 | |||
1675 | ext = ".r" |
|
1675 | ext = ".r" | |
1676 |
|
1676 | |||
1677 | optchar = "D" |
|
1677 | optchar = "D" | |
1678 |
|
1678 | |||
1679 | shapeBuffer = None |
|
1679 | shapeBuffer = None | |
1680 |
|
1680 | |||
1681 |
|
1681 | |||
1682 | def __init__(self): |
|
1682 | def __init__(self): | |
1683 | """ |
|
1683 | """ | |
1684 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
1684 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
1685 |
|
1685 | |||
1686 | Affected: |
|
1686 | Affected: | |
1687 | self.dataOut |
|
1687 | self.dataOut | |
1688 |
|
1688 | |||
1689 | Return: None |
|
1689 | Return: None | |
1690 | """ |
|
1690 | """ | |
1691 |
|
1691 | |||
1692 | self.nTotalBlocks = 0 |
|
1692 | self.nTotalBlocks = 0 | |
1693 |
|
1693 | |||
1694 | self.profileIndex = 0 |
|
1694 | self.profileIndex = 0 | |
1695 |
|
1695 | |||
1696 | self.isConfig = False |
|
1696 | self.isConfig = False | |
1697 |
|
1697 | |||
1698 | self.fp = None |
|
1698 | self.fp = None | |
1699 |
|
1699 | |||
1700 | self.flagIsNewFile = 1 |
|
1700 | self.flagIsNewFile = 1 | |
1701 |
|
1701 | |||
1702 | self.nTotalBlocks = 0 |
|
1702 | self.nTotalBlocks = 0 | |
1703 |
|
1703 | |||
1704 | self.flagIsNewBlock = 0 |
|
1704 | self.flagIsNewBlock = 0 | |
1705 |
|
1705 | |||
1706 | self.setFile = None |
|
1706 | self.setFile = None | |
1707 |
|
1707 | |||
1708 | self.dtype = None |
|
1708 | self.dtype = None | |
1709 |
|
1709 | |||
1710 | self.path = None |
|
1710 | self.path = None | |
1711 |
|
1711 | |||
1712 | self.filename = None |
|
1712 | self.filename = None | |
1713 |
|
1713 | |||
1714 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1714 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1715 |
|
1715 | |||
1716 | self.systemHeaderObj = SystemHeader() |
|
1716 | self.systemHeaderObj = SystemHeader() | |
1717 |
|
1717 | |||
1718 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1718 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1719 |
|
1719 | |||
1720 | self.processingHeaderObj = ProcessingHeader() |
|
1720 | self.processingHeaderObj = ProcessingHeader() | |
1721 |
|
1721 | |||
1722 | def hasAllDataInBuffer(self): |
|
1722 | def hasAllDataInBuffer(self): | |
1723 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1723 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1724 | return 1 |
|
1724 | return 1 | |
1725 | return 0 |
|
1725 | return 0 | |
1726 |
|
1726 | |||
1727 |
|
1727 | |||
1728 | def setBlockDimension(self): |
|
1728 | def setBlockDimension(self): | |
1729 | """ |
|
1729 | """ | |
1730 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
1730 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
1731 |
|
1731 | |||
1732 | Affected: |
|
1732 | Affected: | |
1733 | self.shape_spc_Buffer |
|
1733 | self.shape_spc_Buffer | |
1734 | self.shape_cspc_Buffer |
|
1734 | self.shape_cspc_Buffer | |
1735 | self.shape_dc_Buffer |
|
1735 | self.shape_dc_Buffer | |
1736 |
|
1736 | |||
1737 | Return: None |
|
1737 | Return: None | |
1738 | """ |
|
1738 | """ | |
1739 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
1739 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
1740 | self.processingHeaderObj.nHeights, |
|
1740 | self.processingHeaderObj.nHeights, | |
1741 | self.systemHeaderObj.nChannels) |
|
1741 | self.systemHeaderObj.nChannels) | |
1742 |
|
1742 | |||
1743 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
1743 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
1744 | self.processingHeaderObj.profilesPerBlock, |
|
1744 | self.processingHeaderObj.profilesPerBlock, | |
1745 | self.processingHeaderObj.nHeights), |
|
1745 | self.processingHeaderObj.nHeights), | |
1746 | dtype=numpy.dtype('complex64')) |
|
1746 | dtype=numpy.dtype('complex64')) | |
1747 |
|
1747 | |||
1748 |
|
1748 | |||
1749 | def writeBlock(self): |
|
1749 | def writeBlock(self): | |
1750 | """ |
|
1750 | """ | |
1751 | Escribe el buffer en el file designado |
|
1751 | Escribe el buffer en el file designado | |
1752 |
|
1752 | |||
1753 | Affected: |
|
1753 | Affected: | |
1754 | self.profileIndex |
|
1754 | self.profileIndex | |
1755 | self.flagIsNewFile |
|
1755 | self.flagIsNewFile | |
1756 | self.flagIsNewBlock |
|
1756 | self.flagIsNewBlock | |
1757 | self.nTotalBlocks |
|
1757 | self.nTotalBlocks | |
1758 | self.blockIndex |
|
1758 | self.blockIndex | |
1759 |
|
1759 | |||
1760 | Return: None |
|
1760 | Return: None | |
1761 | """ |
|
1761 | """ | |
1762 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
1762 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
1763 |
|
1763 | |||
1764 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
1764 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
1765 |
|
1765 | |||
1766 | data['real'] = junk.real |
|
1766 | data['real'] = junk.real | |
1767 | data['imag'] = junk.imag |
|
1767 | data['imag'] = junk.imag | |
1768 |
|
1768 | |||
1769 | data = data.reshape( (-1) ) |
|
1769 | data = data.reshape( (-1) ) | |
1770 |
|
1770 | |||
1771 | data.tofile( self.fp ) |
|
1771 | data.tofile( self.fp ) | |
1772 |
|
1772 | |||
1773 | self.datablock.fill(0) |
|
1773 | self.datablock.fill(0) | |
1774 |
|
1774 | |||
1775 | self.profileIndex = 0 |
|
1775 | self.profileIndex = 0 | |
1776 | self.flagIsNewFile = 0 |
|
1776 | self.flagIsNewFile = 0 | |
1777 | self.flagIsNewBlock = 1 |
|
1777 | self.flagIsNewBlock = 1 | |
1778 |
|
1778 | |||
1779 | self.blockIndex += 1 |
|
1779 | self.blockIndex += 1 | |
1780 | self.nTotalBlocks += 1 |
|
1780 | self.nTotalBlocks += 1 | |
1781 |
|
1781 | |||
1782 | def putData(self): |
|
1782 | def putData(self): | |
1783 | """ |
|
1783 | """ | |
1784 | Setea un bloque de datos y luego los escribe en un file |
|
1784 | Setea un bloque de datos y luego los escribe en un file | |
1785 |
|
1785 | |||
1786 | Affected: |
|
1786 | Affected: | |
1787 | self.flagIsNewBlock |
|
1787 | self.flagIsNewBlock | |
1788 | self.profileIndex |
|
1788 | self.profileIndex | |
1789 |
|
1789 | |||
1790 | Return: |
|
1790 | Return: | |
1791 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
1791 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
1792 | 1 : Si se escribio la data de un bloque en un file |
|
1792 | 1 : Si se escribio la data de un bloque en un file | |
1793 | """ |
|
1793 | """ | |
1794 | if self.dataOut.flagNoData: |
|
1794 | if self.dataOut.flagNoData: | |
1795 | return 0 |
|
1795 | return 0 | |
1796 |
|
1796 | |||
1797 | self.flagIsNewBlock = 0 |
|
1797 | self.flagIsNewBlock = 0 | |
1798 |
|
1798 | |||
1799 | if self.dataOut.flagTimeBlock: |
|
1799 | if self.dataOut.flagTimeBlock: | |
1800 |
|
1800 | |||
1801 | self.datablock.fill(0) |
|
1801 | self.datablock.fill(0) | |
1802 | self.profileIndex = 0 |
|
1802 | self.profileIndex = 0 | |
1803 | self.setNextFile() |
|
1803 | self.setNextFile() | |
1804 |
|
1804 | |||
1805 | if self.profileIndex == 0: |
|
1805 | if self.profileIndex == 0: | |
1806 | self.setBasicHeader() |
|
1806 | self.setBasicHeader() | |
1807 |
|
1807 | |||
1808 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
1808 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
1809 |
|
1809 | |||
1810 | self.profileIndex += 1 |
|
1810 | self.profileIndex += 1 | |
1811 |
|
1811 | |||
1812 | if self.hasAllDataInBuffer(): |
|
1812 | if self.hasAllDataInBuffer(): | |
1813 | #if self.flagIsNewFile: |
|
1813 | #if self.flagIsNewFile: | |
1814 | self.writeNextBlock() |
|
1814 | self.writeNextBlock() | |
1815 | # self.setFirstHeader() |
|
1815 | # self.setFirstHeader() | |
1816 |
|
1816 | |||
1817 | return 1 |
|
1817 | return 1 | |
1818 |
|
1818 | |||
1819 | def __getProcessFlags(self): |
|
1819 | def __getProcessFlags(self): | |
1820 |
|
1820 | |||
1821 | processFlags = 0 |
|
1821 | processFlags = 0 | |
1822 |
|
1822 | |||
1823 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1823 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1824 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1824 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1825 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1825 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1826 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1826 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1827 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1827 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1828 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1828 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1829 |
|
1829 | |||
1830 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1830 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1831 |
|
1831 | |||
1832 |
|
1832 | |||
1833 |
|
1833 | |||
1834 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
1834 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
1835 | PROCFLAG.DATATYPE_SHORT, |
|
1835 | PROCFLAG.DATATYPE_SHORT, | |
1836 | PROCFLAG.DATATYPE_LONG, |
|
1836 | PROCFLAG.DATATYPE_LONG, | |
1837 | PROCFLAG.DATATYPE_INT64, |
|
1837 | PROCFLAG.DATATYPE_INT64, | |
1838 | PROCFLAG.DATATYPE_FLOAT, |
|
1838 | PROCFLAG.DATATYPE_FLOAT, | |
1839 | PROCFLAG.DATATYPE_DOUBLE] |
|
1839 | PROCFLAG.DATATYPE_DOUBLE] | |
1840 |
|
1840 | |||
1841 |
|
1841 | |||
1842 | for index in range(len(dtypeList)): |
|
1842 | for index in range(len(dtypeList)): | |
1843 | if self.dataOut.dtype == dtypeList[index]: |
|
1843 | if self.dataOut.dtype == dtypeList[index]: | |
1844 | dtypeValue = datatypeValueList[index] |
|
1844 | dtypeValue = datatypeValueList[index] | |
1845 | break |
|
1845 | break | |
1846 |
|
1846 | |||
1847 | processFlags += dtypeValue |
|
1847 | processFlags += dtypeValue | |
1848 |
|
1848 | |||
1849 | if self.dataOut.flagDecodeData: |
|
1849 | if self.dataOut.flagDecodeData: | |
1850 | processFlags += PROCFLAG.DECODE_DATA |
|
1850 | processFlags += PROCFLAG.DECODE_DATA | |
1851 |
|
1851 | |||
1852 | if self.dataOut.flagDeflipData: |
|
1852 | if self.dataOut.flagDeflipData: | |
1853 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1853 | processFlags += PROCFLAG.DEFLIP_DATA | |
1854 |
|
1854 | |||
1855 | if self.dataOut.code != None: |
|
1855 | if self.dataOut.code != None: | |
1856 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1856 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
1857 |
|
1857 | |||
1858 | if self.dataOut.nCohInt > 1: |
|
1858 | if self.dataOut.nCohInt > 1: | |
1859 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1859 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
1860 |
|
1860 | |||
1861 | return processFlags |
|
1861 | return processFlags | |
1862 |
|
1862 | |||
1863 |
|
1863 | |||
1864 | def __getBlockSize(self): |
|
1864 | def __getBlockSize(self): | |
1865 | ''' |
|
1865 | ''' | |
1866 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
1866 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
1867 | ''' |
|
1867 | ''' | |
1868 |
|
1868 | |||
1869 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1869 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1870 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1870 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1871 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1871 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1872 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1872 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1873 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1873 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1874 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1874 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1875 |
|
1875 | |||
1876 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1876 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1877 | datatypeValueList = [1,2,4,8,4,8] |
|
1877 | datatypeValueList = [1,2,4,8,4,8] | |
1878 | for index in range(len(dtypeList)): |
|
1878 | for index in range(len(dtypeList)): | |
1879 | if self.dataOut.dtype == dtypeList[index]: |
|
1879 | if self.dataOut.dtype == dtypeList[index]: | |
1880 | datatypeValue = datatypeValueList[index] |
|
1880 | datatypeValue = datatypeValueList[index] | |
1881 | break |
|
1881 | break | |
1882 |
|
1882 | |||
1883 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * datatypeValue * 2) |
|
1883 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * datatypeValue * 2) | |
1884 |
|
1884 | |||
1885 | return blocksize |
|
1885 | return blocksize | |
1886 |
|
1886 | |||
1887 | def setFirstHeader(self): |
|
1887 | def setFirstHeader(self): | |
1888 |
|
1888 | |||
1889 | """ |
|
1889 | """ | |
1890 | Obtiene una copia del First Header |
|
1890 | Obtiene una copia del First Header | |
1891 |
|
1891 | |||
1892 | Affected: |
|
1892 | Affected: | |
1893 | self.systemHeaderObj |
|
1893 | self.systemHeaderObj | |
1894 | self.radarControllerHeaderObj |
|
1894 | self.radarControllerHeaderObj | |
1895 | self.dtype |
|
1895 | self.dtype | |
1896 |
|
1896 | |||
1897 | Return: |
|
1897 | Return: | |
1898 | None |
|
1898 | None | |
1899 | """ |
|
1899 | """ | |
1900 |
|
1900 | |||
1901 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
1901 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
1902 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
1902 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
1903 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
1903 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
1904 |
|
1904 | |||
1905 | self.setBasicHeader() |
|
1905 | self.setBasicHeader() | |
1906 |
|
1906 | |||
1907 | processingHeaderSize = 40 # bytes |
|
1907 | processingHeaderSize = 40 # bytes | |
1908 | self.processingHeaderObj.dtype = 0 # Voltage |
|
1908 | self.processingHeaderObj.dtype = 0 # Voltage | |
1909 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
1909 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
1910 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
1910 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
1911 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
1911 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
1912 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
1912 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
1913 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
1913 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
1914 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
1914 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
1915 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
1915 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
1916 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
1916 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
1917 |
|
1917 | |||
1918 | # if self.dataOut.code != None: |
|
1918 | # if self.dataOut.code != None: | |
1919 | # self.processingHeaderObj.code = self.dataOut.code |
|
1919 | # self.processingHeaderObj.code = self.dataOut.code | |
1920 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
1920 | # self.processingHeaderObj.nCode = self.dataOut.nCode | |
1921 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
1921 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
1922 | # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
1922 | # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) | |
1923 | # processingHeaderSize += codesize |
|
1923 | # processingHeaderSize += codesize | |
1924 |
|
1924 | |||
1925 | if self.processingHeaderObj.nWindows != 0: |
|
1925 | if self.processingHeaderObj.nWindows != 0: | |
1926 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
1926 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
1927 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
1927 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
1928 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
1928 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
1929 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
1929 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
1930 | processingHeaderSize += 12 |
|
1930 | processingHeaderSize += 12 | |
1931 |
|
1931 | |||
1932 | self.processingHeaderObj.size = processingHeaderSize |
|
1932 | self.processingHeaderObj.size = processingHeaderSize | |
1933 |
|
1933 | |||
1934 | class SpectraReader(JRODataReader): |
|
1934 | class SpectraReader(JRODataReader): | |
1935 | """ |
|
1935 | """ | |
1936 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
1936 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
1937 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
1937 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
1938 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
1938 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
1939 |
|
1939 | |||
1940 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
1940 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
1941 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
1941 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
1942 | canales * alturas (DC Channels) |
|
1942 | canales * alturas (DC Channels) | |
1943 |
|
1943 | |||
1944 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1944 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1945 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
1945 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
1946 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
1946 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
1947 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1947 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1948 |
|
1948 | |||
1949 | Example: |
|
1949 | Example: | |
1950 | dpath = "/home/myuser/data" |
|
1950 | dpath = "/home/myuser/data" | |
1951 |
|
1951 | |||
1952 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1952 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1953 |
|
1953 | |||
1954 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1954 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1955 |
|
1955 | |||
1956 | readerObj = SpectraReader() |
|
1956 | readerObj = SpectraReader() | |
1957 |
|
1957 | |||
1958 | readerObj.setup(dpath, startTime, endTime) |
|
1958 | readerObj.setup(dpath, startTime, endTime) | |
1959 |
|
1959 | |||
1960 | while(True): |
|
1960 | while(True): | |
1961 |
|
1961 | |||
1962 | readerObj.getData() |
|
1962 | readerObj.getData() | |
1963 |
|
1963 | |||
1964 | print readerObj.data_spc |
|
1964 | print readerObj.data_spc | |
1965 |
|
1965 | |||
1966 | print readerObj.data_cspc |
|
1966 | print readerObj.data_cspc | |
1967 |
|
1967 | |||
1968 | print readerObj.data_dc |
|
1968 | print readerObj.data_dc | |
1969 |
|
1969 | |||
1970 | if readerObj.flagNoMoreFiles: |
|
1970 | if readerObj.flagNoMoreFiles: | |
1971 | break |
|
1971 | break | |
1972 |
|
1972 | |||
1973 | """ |
|
1973 | """ | |
1974 |
|
1974 | |||
1975 | pts2read_SelfSpectra = 0 |
|
1975 | pts2read_SelfSpectra = 0 | |
1976 |
|
1976 | |||
1977 | pts2read_CrossSpectra = 0 |
|
1977 | pts2read_CrossSpectra = 0 | |
1978 |
|
1978 | |||
1979 | pts2read_DCchannels = 0 |
|
1979 | pts2read_DCchannels = 0 | |
1980 |
|
1980 | |||
1981 | ext = ".pdata" |
|
1981 | ext = ".pdata" | |
1982 |
|
1982 | |||
1983 | optchar = "P" |
|
1983 | optchar = "P" | |
1984 |
|
1984 | |||
1985 | dataOut = None |
|
1985 | dataOut = None | |
1986 |
|
1986 | |||
1987 | nRdChannels = None |
|
1987 | nRdChannels = None | |
1988 |
|
1988 | |||
1989 | nRdPairs = None |
|
1989 | nRdPairs = None | |
1990 |
|
1990 | |||
1991 | rdPairList = [] |
|
1991 | rdPairList = [] | |
1992 |
|
1992 | |||
1993 | def __init__(self): |
|
1993 | def __init__(self): | |
1994 | """ |
|
1994 | """ | |
1995 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
1995 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
1996 |
|
1996 | |||
1997 | Inputs: |
|
1997 | Inputs: | |
1998 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
1998 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para | |
1999 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1999 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
2000 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
2000 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
2001 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
2001 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
2002 | bloque de datos. |
|
2002 | bloque de datos. | |
2003 | Si este parametro no es pasado se creara uno internamente. |
|
2003 | Si este parametro no es pasado se creara uno internamente. | |
2004 |
|
2004 | |||
2005 | Affected: |
|
2005 | Affected: | |
2006 | self.dataOut |
|
2006 | self.dataOut | |
2007 |
|
2007 | |||
2008 | Return : None |
|
2008 | Return : None | |
2009 | """ |
|
2009 | """ | |
2010 |
|
2010 | |||
2011 | self.isConfig = False |
|
2011 | self.isConfig = False | |
2012 |
|
2012 | |||
2013 | self.pts2read_SelfSpectra = 0 |
|
2013 | self.pts2read_SelfSpectra = 0 | |
2014 |
|
2014 | |||
2015 | self.pts2read_CrossSpectra = 0 |
|
2015 | self.pts2read_CrossSpectra = 0 | |
2016 |
|
2016 | |||
2017 | self.pts2read_DCchannels = 0 |
|
2017 | self.pts2read_DCchannels = 0 | |
2018 |
|
2018 | |||
2019 | self.datablock = None |
|
2019 | self.datablock = None | |
2020 |
|
2020 | |||
2021 | self.utc = None |
|
2021 | self.utc = None | |
2022 |
|
2022 | |||
2023 | self.ext = ".pdata" |
|
2023 | self.ext = ".pdata" | |
2024 |
|
2024 | |||
2025 | self.optchar = "P" |
|
2025 | self.optchar = "P" | |
2026 |
|
2026 | |||
2027 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
2027 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
2028 |
|
2028 | |||
2029 | self.systemHeaderObj = SystemHeader() |
|
2029 | self.systemHeaderObj = SystemHeader() | |
2030 |
|
2030 | |||
2031 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2031 | self.radarControllerHeaderObj = RadarControllerHeader() | |
2032 |
|
2032 | |||
2033 | self.processingHeaderObj = ProcessingHeader() |
|
2033 | self.processingHeaderObj = ProcessingHeader() | |
2034 |
|
2034 | |||
2035 | self.online = 0 |
|
2035 | self.online = 0 | |
2036 |
|
2036 | |||
2037 | self.fp = None |
|
2037 | self.fp = None | |
2038 |
|
2038 | |||
2039 | self.idFile = None |
|
2039 | self.idFile = None | |
2040 |
|
2040 | |||
2041 | self.dtype = None |
|
2041 | self.dtype = None | |
2042 |
|
2042 | |||
2043 | self.fileSizeByHeader = None |
|
2043 | self.fileSizeByHeader = None | |
2044 |
|
2044 | |||
2045 | self.filenameList = [] |
|
2045 | self.filenameList = [] | |
2046 |
|
2046 | |||
2047 | self.filename = None |
|
2047 | self.filename = None | |
2048 |
|
2048 | |||
2049 | self.fileSize = None |
|
2049 | self.fileSize = None | |
2050 |
|
2050 | |||
2051 | self.firstHeaderSize = 0 |
|
2051 | self.firstHeaderSize = 0 | |
2052 |
|
2052 | |||
2053 | self.basicHeaderSize = 24 |
|
2053 | self.basicHeaderSize = 24 | |
2054 |
|
2054 | |||
2055 | self.pathList = [] |
|
2055 | self.pathList = [] | |
2056 |
|
2056 | |||
2057 | self.lastUTTime = 0 |
|
2057 | self.lastUTTime = 0 | |
2058 |
|
2058 | |||
2059 | self.maxTimeStep = 30 |
|
2059 | self.maxTimeStep = 30 | |
2060 |
|
2060 | |||
2061 | self.flagNoMoreFiles = 0 |
|
2061 | self.flagNoMoreFiles = 0 | |
2062 |
|
2062 | |||
2063 | self.set = 0 |
|
2063 | self.set = 0 | |
2064 |
|
2064 | |||
2065 | self.path = None |
|
2065 | self.path = None | |
2066 |
|
2066 | |||
2067 | self.delay = 60 #seconds |
|
2067 | self.delay = 60 #seconds | |
2068 |
|
2068 | |||
2069 | self.nTries = 3 #quantity tries |
|
2069 | self.nTries = 3 #quantity tries | |
2070 |
|
2070 | |||
2071 | self.nFiles = 3 #number of files for searching |
|
2071 | self.nFiles = 3 #number of files for searching | |
2072 |
|
2072 | |||
2073 | self.nReadBlocks = 0 |
|
2073 | self.nReadBlocks = 0 | |
2074 |
|
2074 | |||
2075 | self.flagIsNewFile = 1 |
|
2075 | self.flagIsNewFile = 1 | |
2076 |
|
2076 | |||
2077 | self.__isFirstTimeOnline = 1 |
|
2077 | self.__isFirstTimeOnline = 1 | |
2078 |
|
2078 | |||
2079 | self.ippSeconds = 0 |
|
2079 | self.ippSeconds = 0 | |
2080 |
|
2080 | |||
2081 | self.flagTimeBlock = 0 |
|
2081 | self.flagTimeBlock = 0 | |
2082 |
|
2082 | |||
2083 | self.flagIsNewBlock = 0 |
|
2083 | self.flagIsNewBlock = 0 | |
2084 |
|
2084 | |||
2085 | self.nTotalBlocks = 0 |
|
2085 | self.nTotalBlocks = 0 | |
2086 |
|
2086 | |||
2087 | self.blocksize = 0 |
|
2087 | self.blocksize = 0 | |
2088 |
|
2088 | |||
2089 | self.dataOut = self.createObjByDefault() |
|
2089 | self.dataOut = self.createObjByDefault() | |
2090 |
|
2090 | |||
2091 | self.profileIndex = 1 #Always |
|
2091 | self.profileIndex = 1 #Always | |
2092 |
|
2092 | |||
2093 |
|
2093 | |||
2094 | def createObjByDefault(self): |
|
2094 | def createObjByDefault(self): | |
2095 |
|
2095 | |||
2096 | dataObj = Spectra() |
|
2096 | dataObj = Spectra() | |
2097 |
|
2097 | |||
2098 | return dataObj |
|
2098 | return dataObj | |
2099 |
|
2099 | |||
2100 | def __hasNotDataInBuffer(self): |
|
2100 | def __hasNotDataInBuffer(self): | |
2101 | return 1 |
|
2101 | return 1 | |
2102 |
|
2102 | |||
2103 |
|
2103 | |||
2104 | def getBlockDimension(self): |
|
2104 | def getBlockDimension(self): | |
2105 | """ |
|
2105 | """ | |
2106 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
2106 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
2107 |
|
2107 | |||
2108 | Affected: |
|
2108 | Affected: | |
2109 | self.nRdChannels |
|
2109 | self.nRdChannels | |
2110 | self.nRdPairs |
|
2110 | self.nRdPairs | |
2111 | self.pts2read_SelfSpectra |
|
2111 | self.pts2read_SelfSpectra | |
2112 | self.pts2read_CrossSpectra |
|
2112 | self.pts2read_CrossSpectra | |
2113 | self.pts2read_DCchannels |
|
2113 | self.pts2read_DCchannels | |
2114 | self.blocksize |
|
2114 | self.blocksize | |
2115 | self.dataOut.nChannels |
|
2115 | self.dataOut.nChannels | |
2116 | self.dataOut.nPairs |
|
2116 | self.dataOut.nPairs | |
2117 |
|
2117 | |||
2118 | Return: |
|
2118 | Return: | |
2119 | None |
|
2119 | None | |
2120 | """ |
|
2120 | """ | |
2121 | self.nRdChannels = 0 |
|
2121 | self.nRdChannels = 0 | |
2122 | self.nRdPairs = 0 |
|
2122 | self.nRdPairs = 0 | |
2123 | self.rdPairList = [] |
|
2123 | self.rdPairList = [] | |
2124 |
|
2124 | |||
2125 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
2125 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
2126 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
2126 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
2127 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
2127 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
2128 | else: |
|
2128 | else: | |
2129 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
2129 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
2130 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
2130 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
2131 |
|
2131 | |||
2132 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
2132 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
2133 |
|
2133 | |||
2134 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
2134 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
2135 | self.blocksize = self.pts2read_SelfSpectra |
|
2135 | self.blocksize = self.pts2read_SelfSpectra | |
2136 |
|
2136 | |||
2137 | if self.processingHeaderObj.flag_cspc: |
|
2137 | if self.processingHeaderObj.flag_cspc: | |
2138 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
2138 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
2139 | self.blocksize += self.pts2read_CrossSpectra |
|
2139 | self.blocksize += self.pts2read_CrossSpectra | |
2140 |
|
2140 | |||
2141 | if self.processingHeaderObj.flag_dc: |
|
2141 | if self.processingHeaderObj.flag_dc: | |
2142 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
2142 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
2143 | self.blocksize += self.pts2read_DCchannels |
|
2143 | self.blocksize += self.pts2read_DCchannels | |
2144 |
|
2144 | |||
2145 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
2145 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
2146 |
|
2146 | |||
2147 |
|
2147 | |||
2148 | def readBlock(self): |
|
2148 | def readBlock(self): | |
2149 | """ |
|
2149 | """ | |
2150 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
2150 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
2151 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
2151 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
2152 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
2152 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
2153 | es seteado a 0 |
|
2153 | es seteado a 0 | |
2154 |
|
2154 | |||
2155 | Return: None |
|
2155 | Return: None | |
2156 |
|
2156 | |||
2157 | Variables afectadas: |
|
2157 | Variables afectadas: | |
2158 |
|
2158 | |||
2159 | self.flagIsNewFile |
|
2159 | self.flagIsNewFile | |
2160 | self.flagIsNewBlock |
|
2160 | self.flagIsNewBlock | |
2161 | self.nTotalBlocks |
|
2161 | self.nTotalBlocks | |
2162 | self.data_spc |
|
2162 | self.data_spc | |
2163 | self.data_cspc |
|
2163 | self.data_cspc | |
2164 | self.data_dc |
|
2164 | self.data_dc | |
2165 |
|
2165 | |||
2166 | Exceptions: |
|
2166 | Exceptions: | |
2167 | Si un bloque leido no es un bloque valido |
|
2167 | Si un bloque leido no es un bloque valido | |
2168 | """ |
|
2168 | """ | |
2169 | blockOk_flag = False |
|
2169 | blockOk_flag = False | |
2170 | fpointer = self.fp.tell() |
|
2170 | fpointer = self.fp.tell() | |
2171 |
|
2171 | |||
2172 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
2172 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
2173 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
2173 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
2174 |
|
2174 | |||
2175 | if self.processingHeaderObj.flag_cspc: |
|
2175 | if self.processingHeaderObj.flag_cspc: | |
2176 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
2176 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
2177 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
2177 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
2178 |
|
2178 | |||
2179 | if self.processingHeaderObj.flag_dc: |
|
2179 | if self.processingHeaderObj.flag_dc: | |
2180 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
2180 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
2181 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
2181 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
2182 |
|
2182 | |||
2183 |
|
2183 | |||
2184 | if not(self.processingHeaderObj.shif_fft): |
|
2184 | if not(self.processingHeaderObj.shif_fft): | |
2185 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2185 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
2186 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
2186 | shift = int(self.processingHeaderObj.profilesPerBlock/2) | |
2187 | spc = numpy.roll( spc, shift , axis=2 ) |
|
2187 | spc = numpy.roll( spc, shift , axis=2 ) | |
2188 |
|
2188 | |||
2189 | if self.processingHeaderObj.flag_cspc: |
|
2189 | if self.processingHeaderObj.flag_cspc: | |
2190 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2190 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
2191 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
2191 | cspc = numpy.roll( cspc, shift, axis=2 ) | |
2192 |
|
2192 | |||
2193 | # self.processingHeaderObj.shif_fft = True |
|
2193 | # self.processingHeaderObj.shif_fft = True | |
2194 |
|
2194 | |||
2195 | spc = numpy.transpose( spc, (0,2,1) ) |
|
2195 | spc = numpy.transpose( spc, (0,2,1) ) | |
2196 | self.data_spc = spc |
|
2196 | self.data_spc = spc | |
2197 |
|
2197 | |||
2198 | if self.processingHeaderObj.flag_cspc: |
|
2198 | if self.processingHeaderObj.flag_cspc: | |
2199 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
2199 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
2200 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
2200 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
2201 | else: |
|
2201 | else: | |
2202 | self.data_cspc = None |
|
2202 | self.data_cspc = None | |
2203 |
|
2203 | |||
2204 | if self.processingHeaderObj.flag_dc: |
|
2204 | if self.processingHeaderObj.flag_dc: | |
2205 | self.data_dc = dc['real'] + dc['imag']*1j |
|
2205 | self.data_dc = dc['real'] + dc['imag']*1j | |
2206 | else: |
|
2206 | else: | |
2207 | self.data_dc = None |
|
2207 | self.data_dc = None | |
2208 |
|
2208 | |||
2209 | self.flagIsNewFile = 0 |
|
2209 | self.flagIsNewFile = 0 | |
2210 | self.flagIsNewBlock = 1 |
|
2210 | self.flagIsNewBlock = 1 | |
2211 |
|
2211 | |||
2212 | self.nTotalBlocks += 1 |
|
2212 | self.nTotalBlocks += 1 | |
2213 | self.nReadBlocks += 1 |
|
2213 | self.nReadBlocks += 1 | |
2214 |
|
2214 | |||
2215 | return 1 |
|
2215 | return 1 | |
2216 |
|
2216 | |||
2217 | def getFirstHeader(self): |
|
2217 | def getFirstHeader(self): | |
2218 |
|
2218 | |||
2219 | self.dataOut.dtype = self.dtype |
|
2219 | self.dataOut.dtype = self.dtype | |
2220 |
|
2220 | |||
2221 | self.dataOut.nPairs = self.nRdPairs |
|
2221 | self.dataOut.nPairs = self.nRdPairs | |
2222 |
|
2222 | |||
2223 | self.dataOut.pairsList = self.rdPairList |
|
2223 | self.dataOut.pairsList = self.rdPairList | |
2224 |
|
2224 | |||
2225 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
2225 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
2226 |
|
2226 | |||
2227 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
2227 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
2228 |
|
2228 | |||
2229 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
2229 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
2230 |
|
2230 | |||
2231 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
2231 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |
2232 |
|
2232 | |||
2233 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
2233 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
2234 |
|
2234 | |||
2235 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
2235 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
2236 |
|
2236 | |||
2237 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
2237 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
2238 |
|
2238 | |||
2239 | self.dataOut.ippSeconds = self.ippSeconds |
|
2239 | self.dataOut.ippSeconds = self.ippSeconds | |
2240 |
|
2240 | |||
2241 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints |
|
2241 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints | |
2242 |
|
2242 | |||
2243 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
2243 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
2244 |
|
2244 | |||
2245 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
2245 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
2246 |
|
2246 | |||
2247 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
2247 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
2248 |
|
2248 | |||
2249 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
2249 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |
2250 |
|
2250 | |||
2251 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
2251 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
2252 |
|
2252 | |||
2253 | if self.radarControllerHeaderObj.code != None: |
|
2253 | if self.radarControllerHeaderObj.code != None: | |
2254 |
|
2254 | |||
2255 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
2255 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
2256 |
|
2256 | |||
2257 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
2257 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
2258 |
|
2258 | |||
2259 | self.dataOut.code = self.radarControllerHeaderObj.code |
|
2259 | self.dataOut.code = self.radarControllerHeaderObj.code | |
2260 |
|
2260 | |||
2261 | self.dataOut.flagDecodeData = True |
|
2261 | self.dataOut.flagDecodeData = True | |
2262 |
|
2262 | |||
2263 | def getData(self): |
|
2263 | def getData(self): | |
2264 | """ |
|
2264 | """ | |
2265 | Copia el buffer de lectura a la clase "Spectra", |
|
2265 | Copia el buffer de lectura a la clase "Spectra", | |
2266 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
2266 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
2267 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
2267 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
2268 |
|
2268 | |||
2269 | Return: |
|
2269 | Return: | |
2270 | 0 : Si no hay mas archivos disponibles |
|
2270 | 0 : Si no hay mas archivos disponibles | |
2271 | 1 : Si hizo una buena copia del buffer |
|
2271 | 1 : Si hizo una buena copia del buffer | |
2272 |
|
2272 | |||
2273 | Affected: |
|
2273 | Affected: | |
2274 | self.dataOut |
|
2274 | self.dataOut | |
2275 |
|
2275 | |||
2276 | self.flagTimeBlock |
|
2276 | self.flagTimeBlock | |
2277 | self.flagIsNewBlock |
|
2277 | self.flagIsNewBlock | |
2278 | """ |
|
2278 | """ | |
2279 |
|
2279 | |||
2280 | if self.flagNoMoreFiles: |
|
2280 | if self.flagNoMoreFiles: | |
2281 | self.dataOut.flagNoData = True |
|
2281 | self.dataOut.flagNoData = True | |
2282 | print 'Process finished' |
|
2282 | print 'Process finished' | |
2283 | return 0 |
|
2283 | return 0 | |
2284 |
|
2284 | |||
2285 | self.flagTimeBlock = 0 |
|
2285 | self.flagTimeBlock = 0 | |
2286 | self.flagIsNewBlock = 0 |
|
2286 | self.flagIsNewBlock = 0 | |
2287 |
|
2287 | |||
2288 | if self.__hasNotDataInBuffer(): |
|
2288 | if self.__hasNotDataInBuffer(): | |
2289 |
|
2289 | |||
2290 | if not( self.readNextBlock() ): |
|
2290 | if not( self.readNextBlock() ): | |
2291 | self.dataOut.flagNoData = True |
|
2291 | self.dataOut.flagNoData = True | |
2292 | return 0 |
|
2292 | return 0 | |
2293 |
|
2293 | |||
2294 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
2294 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
2295 |
|
2295 | |||
2296 | if self.data_dc == None: |
|
2296 | if self.data_dc == None: | |
2297 | self.dataOut.flagNoData = True |
|
2297 | self.dataOut.flagNoData = True | |
2298 | return 0 |
|
2298 | return 0 | |
2299 |
|
2299 | |||
2300 | self.getBasicHeader() |
|
2300 | self.getBasicHeader() | |
2301 |
|
2301 | |||
2302 | self.getFirstHeader() |
|
2302 | self.getFirstHeader() | |
2303 |
|
2303 | |||
2304 | self.dataOut.data_spc = self.data_spc |
|
2304 | self.dataOut.data_spc = self.data_spc | |
2305 |
|
2305 | |||
2306 | self.dataOut.data_cspc = self.data_cspc |
|
2306 | self.dataOut.data_cspc = self.data_cspc | |
2307 |
|
2307 | |||
2308 | self.dataOut.data_dc = self.data_dc |
|
2308 | self.dataOut.data_dc = self.data_dc | |
2309 |
|
2309 | |||
2310 | self.dataOut.flagNoData = False |
|
2310 | self.dataOut.flagNoData = False | |
2311 |
|
2311 | |||
2312 | self.dataOut.realtime = self.online |
|
2312 | self.dataOut.realtime = self.online | |
2313 |
|
2313 | |||
2314 | return self.dataOut.data_spc |
|
2314 | return self.dataOut.data_spc | |
2315 |
|
2315 | |||
2316 |
|
2316 | |||
2317 | class SpectraWriter(JRODataWriter): |
|
2317 | class SpectraWriter(JRODataWriter): | |
2318 |
|
2318 | |||
2319 | """ |
|
2319 | """ | |
2320 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
2320 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
2321 | de los datos siempre se realiza por bloques. |
|
2321 | de los datos siempre se realiza por bloques. | |
2322 | """ |
|
2322 | """ | |
2323 |
|
2323 | |||
2324 | ext = ".pdata" |
|
2324 | ext = ".pdata" | |
2325 |
|
2325 | |||
2326 | optchar = "P" |
|
2326 | optchar = "P" | |
2327 |
|
2327 | |||
2328 | shape_spc_Buffer = None |
|
2328 | shape_spc_Buffer = None | |
2329 |
|
2329 | |||
2330 | shape_cspc_Buffer = None |
|
2330 | shape_cspc_Buffer = None | |
2331 |
|
2331 | |||
2332 | shape_dc_Buffer = None |
|
2332 | shape_dc_Buffer = None | |
2333 |
|
2333 | |||
2334 | data_spc = None |
|
2334 | data_spc = None | |
2335 |
|
2335 | |||
2336 | data_cspc = None |
|
2336 | data_cspc = None | |
2337 |
|
2337 | |||
2338 | data_dc = None |
|
2338 | data_dc = None | |
2339 |
|
2339 | |||
2340 | # dataOut = None |
|
2340 | # dataOut = None | |
2341 |
|
2341 | |||
2342 | def __init__(self): |
|
2342 | def __init__(self): | |
2343 | """ |
|
2343 | """ | |
2344 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
2344 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
2345 |
|
2345 | |||
2346 | Affected: |
|
2346 | Affected: | |
2347 | self.dataOut |
|
2347 | self.dataOut | |
2348 | self.basicHeaderObj |
|
2348 | self.basicHeaderObj | |
2349 | self.systemHeaderObj |
|
2349 | self.systemHeaderObj | |
2350 | self.radarControllerHeaderObj |
|
2350 | self.radarControllerHeaderObj | |
2351 | self.processingHeaderObj |
|
2351 | self.processingHeaderObj | |
2352 |
|
2352 | |||
2353 | Return: None |
|
2353 | Return: None | |
2354 | """ |
|
2354 | """ | |
2355 |
|
2355 | |||
2356 | self.isConfig = False |
|
2356 | self.isConfig = False | |
2357 |
|
2357 | |||
2358 | self.nTotalBlocks = 0 |
|
2358 | self.nTotalBlocks = 0 | |
2359 |
|
2359 | |||
2360 | self.data_spc = None |
|
2360 | self.data_spc = None | |
2361 |
|
2361 | |||
2362 | self.data_cspc = None |
|
2362 | self.data_cspc = None | |
2363 |
|
2363 | |||
2364 | self.data_dc = None |
|
2364 | self.data_dc = None | |
2365 |
|
2365 | |||
2366 | self.fp = None |
|
2366 | self.fp = None | |
2367 |
|
2367 | |||
2368 | self.flagIsNewFile = 1 |
|
2368 | self.flagIsNewFile = 1 | |
2369 |
|
2369 | |||
2370 | self.nTotalBlocks = 0 |
|
2370 | self.nTotalBlocks = 0 | |
2371 |
|
2371 | |||
2372 | self.flagIsNewBlock = 0 |
|
2372 | self.flagIsNewBlock = 0 | |
2373 |
|
2373 | |||
2374 | self.setFile = None |
|
2374 | self.setFile = None | |
2375 |
|
2375 | |||
2376 | self.dtype = None |
|
2376 | self.dtype = None | |
2377 |
|
2377 | |||
2378 | self.path = None |
|
2378 | self.path = None | |
2379 |
|
2379 | |||
2380 | self.noMoreFiles = 0 |
|
2380 | self.noMoreFiles = 0 | |
2381 |
|
2381 | |||
2382 | self.filename = None |
|
2382 | self.filename = None | |
2383 |
|
2383 | |||
2384 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
2384 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
2385 |
|
2385 | |||
2386 | self.systemHeaderObj = SystemHeader() |
|
2386 | self.systemHeaderObj = SystemHeader() | |
2387 |
|
2387 | |||
2388 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2388 | self.radarControllerHeaderObj = RadarControllerHeader() | |
2389 |
|
2389 | |||
2390 | self.processingHeaderObj = ProcessingHeader() |
|
2390 | self.processingHeaderObj = ProcessingHeader() | |
2391 |
|
2391 | |||
2392 |
|
2392 | |||
2393 | def hasAllDataInBuffer(self): |
|
2393 | def hasAllDataInBuffer(self): | |
2394 | return 1 |
|
2394 | return 1 | |
2395 |
|
2395 | |||
2396 |
|
2396 | |||
2397 | def setBlockDimension(self): |
|
2397 | def setBlockDimension(self): | |
2398 | """ |
|
2398 | """ | |
2399 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
2399 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
2400 |
|
2400 | |||
2401 | Affected: |
|
2401 | Affected: | |
2402 | self.shape_spc_Buffer |
|
2402 | self.shape_spc_Buffer | |
2403 | self.shape_cspc_Buffer |
|
2403 | self.shape_cspc_Buffer | |
2404 | self.shape_dc_Buffer |
|
2404 | self.shape_dc_Buffer | |
2405 |
|
2405 | |||
2406 | Return: None |
|
2406 | Return: None | |
2407 | """ |
|
2407 | """ | |
2408 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
2408 | self.shape_spc_Buffer = (self.dataOut.nChannels, | |
2409 | self.processingHeaderObj.nHeights, |
|
2409 | self.processingHeaderObj.nHeights, | |
2410 | self.processingHeaderObj.profilesPerBlock) |
|
2410 | self.processingHeaderObj.profilesPerBlock) | |
2411 |
|
2411 | |||
2412 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
2412 | self.shape_cspc_Buffer = (self.dataOut.nPairs, | |
2413 | self.processingHeaderObj.nHeights, |
|
2413 | self.processingHeaderObj.nHeights, | |
2414 | self.processingHeaderObj.profilesPerBlock) |
|
2414 | self.processingHeaderObj.profilesPerBlock) | |
2415 |
|
2415 | |||
2416 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
2416 | self.shape_dc_Buffer = (self.dataOut.nChannels, | |
2417 | self.processingHeaderObj.nHeights) |
|
2417 | self.processingHeaderObj.nHeights) | |
2418 |
|
2418 | |||
2419 |
|
2419 | |||
2420 | def writeBlock(self): |
|
2420 | def writeBlock(self): | |
2421 | """ |
|
2421 | """ | |
2422 | Escribe el buffer en el file designado |
|
2422 | Escribe el buffer en el file designado | |
2423 |
|
2423 | |||
2424 | Affected: |
|
2424 | Affected: | |
2425 | self.data_spc |
|
2425 | self.data_spc | |
2426 | self.data_cspc |
|
2426 | self.data_cspc | |
2427 | self.data_dc |
|
2427 | self.data_dc | |
2428 | self.flagIsNewFile |
|
2428 | self.flagIsNewFile | |
2429 | self.flagIsNewBlock |
|
2429 | self.flagIsNewBlock | |
2430 | self.nTotalBlocks |
|
2430 | self.nTotalBlocks | |
2431 | self.nWriteBlocks |
|
2431 | self.nWriteBlocks | |
2432 |
|
2432 | |||
2433 | Return: None |
|
2433 | Return: None | |
2434 | """ |
|
2434 | """ | |
2435 |
|
2435 | |||
2436 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
2436 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
2437 | if not( self.processingHeaderObj.shif_fft ): |
|
2437 | if not( self.processingHeaderObj.shif_fft ): | |
2438 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2438 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2439 | data = spc.reshape((-1)) |
|
2439 | data = spc.reshape((-1)) | |
2440 | data = data.astype(self.dtype[0]) |
|
2440 | data = data.astype(self.dtype[0]) | |
2441 | data.tofile(self.fp) |
|
2441 | data.tofile(self.fp) | |
2442 |
|
2442 | |||
2443 | if self.data_cspc != None: |
|
2443 | if self.data_cspc != None: | |
2444 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
2444 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
2445 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
2445 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
2446 | if not( self.processingHeaderObj.shif_fft ): |
|
2446 | if not( self.processingHeaderObj.shif_fft ): | |
2447 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2447 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2448 | data['real'] = cspc.real |
|
2448 | data['real'] = cspc.real | |
2449 | data['imag'] = cspc.imag |
|
2449 | data['imag'] = cspc.imag | |
2450 | data = data.reshape((-1)) |
|
2450 | data = data.reshape((-1)) | |
2451 | data.tofile(self.fp) |
|
2451 | data.tofile(self.fp) | |
2452 |
|
2452 | |||
2453 | if self.data_dc != None: |
|
2453 | if self.data_dc != None: | |
2454 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
2454 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
2455 | dc = self.data_dc |
|
2455 | dc = self.data_dc | |
2456 | data['real'] = dc.real |
|
2456 | data['real'] = dc.real | |
2457 | data['imag'] = dc.imag |
|
2457 | data['imag'] = dc.imag | |
2458 | data = data.reshape((-1)) |
|
2458 | data = data.reshape((-1)) | |
2459 | data.tofile(self.fp) |
|
2459 | data.tofile(self.fp) | |
2460 |
|
2460 | |||
2461 | self.data_spc.fill(0) |
|
2461 | self.data_spc.fill(0) | |
2462 |
|
2462 | |||
2463 | if self.data_dc != None: |
|
2463 | if self.data_dc != None: | |
2464 | self.data_dc.fill(0) |
|
2464 | self.data_dc.fill(0) | |
2465 |
|
2465 | |||
2466 | if self.data_cspc != None: |
|
2466 | if self.data_cspc != None: | |
2467 | self.data_cspc.fill(0) |
|
2467 | self.data_cspc.fill(0) | |
2468 |
|
2468 | |||
2469 | self.flagIsNewFile = 0 |
|
2469 | self.flagIsNewFile = 0 | |
2470 | self.flagIsNewBlock = 1 |
|
2470 | self.flagIsNewBlock = 1 | |
2471 | self.nTotalBlocks += 1 |
|
2471 | self.nTotalBlocks += 1 | |
2472 | self.nWriteBlocks += 1 |
|
2472 | self.nWriteBlocks += 1 | |
2473 | self.blockIndex += 1 |
|
2473 | self.blockIndex += 1 | |
2474 |
|
2474 | |||
2475 |
|
2475 | |||
2476 | def putData(self): |
|
2476 | def putData(self): | |
2477 | """ |
|
2477 | """ | |
2478 | Setea un bloque de datos y luego los escribe en un file |
|
2478 | Setea un bloque de datos y luego los escribe en un file | |
2479 |
|
2479 | |||
2480 | Affected: |
|
2480 | Affected: | |
2481 | self.data_spc |
|
2481 | self.data_spc | |
2482 | self.data_cspc |
|
2482 | self.data_cspc | |
2483 | self.data_dc |
|
2483 | self.data_dc | |
2484 |
|
2484 | |||
2485 | Return: |
|
2485 | Return: | |
2486 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
2486 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
2487 | 1 : Si se escribio la data de un bloque en un file |
|
2487 | 1 : Si se escribio la data de un bloque en un file | |
2488 | """ |
|
2488 | """ | |
2489 |
|
2489 | |||
2490 | if self.dataOut.flagNoData: |
|
2490 | if self.dataOut.flagNoData: | |
2491 | return 0 |
|
2491 | return 0 | |
2492 |
|
2492 | |||
2493 | self.flagIsNewBlock = 0 |
|
2493 | self.flagIsNewBlock = 0 | |
2494 |
|
2494 | |||
2495 | if self.dataOut.flagTimeBlock: |
|
2495 | if self.dataOut.flagTimeBlock: | |
2496 | self.data_spc.fill(0) |
|
2496 | self.data_spc.fill(0) | |
2497 | self.data_cspc.fill(0) |
|
2497 | self.data_cspc.fill(0) | |
2498 | self.data_dc.fill(0) |
|
2498 | self.data_dc.fill(0) | |
2499 | self.setNextFile() |
|
2499 | self.setNextFile() | |
2500 |
|
2500 | |||
2501 | if self.flagIsNewFile == 0: |
|
2501 | if self.flagIsNewFile == 0: | |
2502 | self.setBasicHeader() |
|
2502 | self.setBasicHeader() | |
2503 |
|
2503 | |||
2504 | self.data_spc = self.dataOut.data_spc.copy() |
|
2504 | self.data_spc = self.dataOut.data_spc.copy() | |
2505 | if self.dataOut.data_cspc != None: |
|
2505 | if self.dataOut.data_cspc != None: | |
2506 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
2506 | self.data_cspc = self.dataOut.data_cspc.copy() | |
2507 | self.data_dc = self.dataOut.data_dc.copy() |
|
2507 | self.data_dc = self.dataOut.data_dc.copy() | |
2508 |
|
2508 | |||
2509 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
2509 | # #self.processingHeaderObj.dataBlocksPerFile) | |
2510 | if self.hasAllDataInBuffer(): |
|
2510 | if self.hasAllDataInBuffer(): | |
2511 | # self.setFirstHeader() |
|
2511 | # self.setFirstHeader() | |
2512 | self.writeNextBlock() |
|
2512 | self.writeNextBlock() | |
2513 |
|
2513 | |||
2514 | return 1 |
|
2514 | return 1 | |
2515 |
|
2515 | |||
2516 |
|
2516 | |||
2517 | def __getProcessFlags(self): |
|
2517 | def __getProcessFlags(self): | |
2518 |
|
2518 | |||
2519 | processFlags = 0 |
|
2519 | processFlags = 0 | |
2520 |
|
2520 | |||
2521 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2521 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2522 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2522 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2523 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2523 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2524 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2524 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2525 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2525 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2526 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2526 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2527 |
|
2527 | |||
2528 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2528 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2529 |
|
2529 | |||
2530 |
|
2530 | |||
2531 |
|
2531 | |||
2532 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
2532 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
2533 | PROCFLAG.DATATYPE_SHORT, |
|
2533 | PROCFLAG.DATATYPE_SHORT, | |
2534 | PROCFLAG.DATATYPE_LONG, |
|
2534 | PROCFLAG.DATATYPE_LONG, | |
2535 | PROCFLAG.DATATYPE_INT64, |
|
2535 | PROCFLAG.DATATYPE_INT64, | |
2536 | PROCFLAG.DATATYPE_FLOAT, |
|
2536 | PROCFLAG.DATATYPE_FLOAT, | |
2537 | PROCFLAG.DATATYPE_DOUBLE] |
|
2537 | PROCFLAG.DATATYPE_DOUBLE] | |
2538 |
|
2538 | |||
2539 |
|
2539 | |||
2540 | for index in range(len(dtypeList)): |
|
2540 | for index in range(len(dtypeList)): | |
2541 | if self.dataOut.dtype == dtypeList[index]: |
|
2541 | if self.dataOut.dtype == dtypeList[index]: | |
2542 | dtypeValue = datatypeValueList[index] |
|
2542 | dtypeValue = datatypeValueList[index] | |
2543 | break |
|
2543 | break | |
2544 |
|
2544 | |||
2545 | processFlags += dtypeValue |
|
2545 | processFlags += dtypeValue | |
2546 |
|
2546 | |||
2547 | if self.dataOut.flagDecodeData: |
|
2547 | if self.dataOut.flagDecodeData: | |
2548 | processFlags += PROCFLAG.DECODE_DATA |
|
2548 | processFlags += PROCFLAG.DECODE_DATA | |
2549 |
|
2549 | |||
2550 | if self.dataOut.flagDeflipData: |
|
2550 | if self.dataOut.flagDeflipData: | |
2551 | processFlags += PROCFLAG.DEFLIP_DATA |
|
2551 | processFlags += PROCFLAG.DEFLIP_DATA | |
2552 |
|
2552 | |||
2553 | if self.dataOut.code != None: |
|
2553 | if self.dataOut.code != None: | |
2554 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
2554 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
2555 |
|
2555 | |||
2556 | if self.dataOut.nIncohInt > 1: |
|
2556 | if self.dataOut.nIncohInt > 1: | |
2557 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
2557 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
2558 |
|
2558 | |||
2559 | if self.dataOut.data_dc != None: |
|
2559 | if self.dataOut.data_dc != None: | |
2560 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
2560 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
2561 |
|
2561 | |||
2562 | return processFlags |
|
2562 | return processFlags | |
2563 |
|
2563 | |||
2564 |
|
2564 | |||
2565 | def __getBlockSize(self): |
|
2565 | def __getBlockSize(self): | |
2566 | ''' |
|
2566 | ''' | |
2567 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
2567 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
2568 | ''' |
|
2568 | ''' | |
2569 |
|
2569 | |||
2570 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2570 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2571 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2571 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2572 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2572 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2573 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2573 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2574 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2574 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2575 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2575 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2576 |
|
2576 | |||
2577 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2577 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2578 | datatypeValueList = [1,2,4,8,4,8] |
|
2578 | datatypeValueList = [1,2,4,8,4,8] | |
2579 | for index in range(len(dtypeList)): |
|
2579 | for index in range(len(dtypeList)): | |
2580 | if self.dataOut.dtype == dtypeList[index]: |
|
2580 | if self.dataOut.dtype == dtypeList[index]: | |
2581 | datatypeValue = datatypeValueList[index] |
|
2581 | datatypeValue = datatypeValueList[index] | |
2582 | break |
|
2582 | break | |
2583 |
|
2583 | |||
2584 |
|
2584 | |||
2585 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
2585 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints | |
2586 |
|
2586 | |||
2587 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
2587 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) | |
2588 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
2588 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
2589 |
|
2589 | |||
2590 | if self.dataOut.data_cspc != None: |
|
2590 | if self.dataOut.data_cspc != None: | |
2591 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
2591 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) | |
2592 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
2592 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
2593 |
|
2593 | |||
2594 | if self.dataOut.data_dc != None: |
|
2594 | if self.dataOut.data_dc != None: | |
2595 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
2595 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) | |
2596 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
2596 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
2597 |
|
2597 | |||
2598 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
2598 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
2599 |
|
2599 | |||
2600 | return blocksize |
|
2600 | return blocksize | |
2601 |
|
2601 | |||
2602 | def setFirstHeader(self): |
|
2602 | def setFirstHeader(self): | |
2603 |
|
2603 | |||
2604 | """ |
|
2604 | """ | |
2605 | Obtiene una copia del First Header |
|
2605 | Obtiene una copia del First Header | |
2606 |
|
2606 | |||
2607 | Affected: |
|
2607 | Affected: | |
2608 | self.systemHeaderObj |
|
2608 | self.systemHeaderObj | |
2609 | self.radarControllerHeaderObj |
|
2609 | self.radarControllerHeaderObj | |
2610 | self.dtype |
|
2610 | self.dtype | |
2611 |
|
2611 | |||
2612 | Return: |
|
2612 | Return: | |
2613 | None |
|
2613 | None | |
2614 | """ |
|
2614 | """ | |
2615 |
|
2615 | |||
2616 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
2616 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
2617 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
2617 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
2618 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
2618 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
2619 | old_code_size = self.dataOut.radarControllerHeaderObj.code_size |
|
2619 | old_code_size = self.dataOut.radarControllerHeaderObj.code_size | |
2620 | new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4 |
|
2620 | new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4 | |
2621 | self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size |
|
2621 | self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size | |
2622 |
|
2622 | |||
2623 | self.setBasicHeader() |
|
2623 | self.setBasicHeader() | |
2624 |
|
2624 | |||
2625 | processingHeaderSize = 40 # bytes |
|
2625 | processingHeaderSize = 40 # bytes | |
2626 | self.processingHeaderObj.dtype = 1 # Spectra |
|
2626 | self.processingHeaderObj.dtype = 1 # Spectra | |
2627 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
2627 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
2628 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
2628 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints | |
2629 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
2629 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
2630 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
2630 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
2631 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
2631 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
2632 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
2632 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval | |
2633 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
2633 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
2634 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
2634 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels | |
2635 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT |
|
2635 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT | |
2636 |
|
2636 | |||
2637 | if self.processingHeaderObj.totalSpectra > 0: |
|
2637 | if self.processingHeaderObj.totalSpectra > 0: | |
2638 | channelList = [] |
|
2638 | channelList = [] | |
2639 | for channel in range(self.dataOut.nChannels): |
|
2639 | for channel in range(self.dataOut.nChannels): | |
2640 | channelList.append(channel) |
|
2640 | channelList.append(channel) | |
2641 | channelList.append(channel) |
|
2641 | channelList.append(channel) | |
2642 |
|
2642 | |||
2643 | pairsList = [] |
|
2643 | pairsList = [] | |
2644 | if self.dataOut.nPairs > 0: |
|
2644 | if self.dataOut.nPairs > 0: | |
2645 | for pair in self.dataOut.pairsList: |
|
2645 | for pair in self.dataOut.pairsList: | |
2646 | pairsList.append(pair[0]) |
|
2646 | pairsList.append(pair[0]) | |
2647 | pairsList.append(pair[1]) |
|
2647 | pairsList.append(pair[1]) | |
2648 |
|
2648 | |||
2649 | spectraComb = channelList + pairsList |
|
2649 | spectraComb = channelList + pairsList | |
2650 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
2650 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
2651 | self.processingHeaderObj.spectraComb = spectraComb |
|
2651 | self.processingHeaderObj.spectraComb = spectraComb | |
2652 | sizeOfSpcComb = len(spectraComb) |
|
2652 | sizeOfSpcComb = len(spectraComb) | |
2653 | processingHeaderSize += sizeOfSpcComb |
|
2653 | processingHeaderSize += sizeOfSpcComb | |
2654 |
|
2654 | |||
2655 | # The processing header should not have information about code |
|
2655 | # The processing header should not have information about code | |
2656 | # if self.dataOut.code != None: |
|
2656 | # if self.dataOut.code != None: | |
2657 | # self.processingHeaderObj.code = self.dataOut.code |
|
2657 | # self.processingHeaderObj.code = self.dataOut.code | |
2658 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
2658 | # self.processingHeaderObj.nCode = self.dataOut.nCode | |
2659 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
2659 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
2660 | # nCodeSize = 4 # bytes |
|
2660 | # nCodeSize = 4 # bytes | |
2661 | # nBaudSize = 4 # bytes |
|
2661 | # nBaudSize = 4 # bytes | |
2662 | # codeSize = 4 # bytes |
|
2662 | # codeSize = 4 # bytes | |
2663 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
2663 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) | |
2664 | # processingHeaderSize += sizeOfCode |
|
2664 | # processingHeaderSize += sizeOfCode | |
2665 |
|
2665 | |||
2666 | if self.processingHeaderObj.nWindows != 0: |
|
2666 | if self.processingHeaderObj.nWindows != 0: | |
2667 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
2667 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
2668 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2668 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
2669 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
2669 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
2670 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
2670 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
2671 | sizeOfFirstHeight = 4 |
|
2671 | sizeOfFirstHeight = 4 | |
2672 | sizeOfdeltaHeight = 4 |
|
2672 | sizeOfdeltaHeight = 4 | |
2673 | sizeOfnHeights = 4 |
|
2673 | sizeOfnHeights = 4 | |
2674 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
2674 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
2675 | processingHeaderSize += sizeOfWindows |
|
2675 | processingHeaderSize += sizeOfWindows | |
2676 |
|
2676 | |||
2677 | self.processingHeaderObj.size = processingHeaderSize |
|
2677 | self.processingHeaderObj.size = processingHeaderSize | |
2678 |
|
2678 | |||
2679 | class SpectraHeisWriter(Operation): |
|
2679 | class SpectraHeisWriter(Operation): | |
2680 | # set = None |
|
2680 | # set = None | |
2681 | setFile = None |
|
2681 | setFile = None | |
2682 | idblock = None |
|
2682 | idblock = None | |
2683 | doypath = None |
|
2683 | doypath = None | |
2684 | subfolder = None |
|
2684 | subfolder = None | |
2685 |
|
2685 | |||
2686 | def __init__(self): |
|
2686 | def __init__(self): | |
2687 | self.wrObj = FITS() |
|
2687 | self.wrObj = FITS() | |
2688 | # self.dataOut = dataOut |
|
2688 | # self.dataOut = dataOut | |
2689 | self.nTotalBlocks=0 |
|
2689 | self.nTotalBlocks=0 | |
2690 | # self.set = None |
|
2690 | # self.set = None | |
2691 | self.setFile = None |
|
2691 | self.setFile = None | |
2692 | self.idblock = 0 |
|
2692 | self.idblock = 0 | |
2693 | self.wrpath = None |
|
2693 | self.wrpath = None | |
2694 | self.doypath = None |
|
2694 | self.doypath = None | |
2695 | self.subfolder = None |
|
2695 | self.subfolder = None | |
2696 | self.isConfig = False |
|
2696 | self.isConfig = False | |
2697 |
|
2697 | |||
2698 | def isNumber(str): |
|
2698 | def isNumber(str): | |
2699 | """ |
|
2699 | """ | |
2700 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
2700 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
2701 |
|
2701 | |||
2702 | Excepciones: |
|
2702 | Excepciones: | |
2703 | Si un determinado string no puede ser convertido a numero |
|
2703 | Si un determinado string no puede ser convertido a numero | |
2704 | Input: |
|
2704 | Input: | |
2705 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
2705 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
2706 |
|
2706 | |||
2707 | Return: |
|
2707 | Return: | |
2708 | True : si el string es uno numerico |
|
2708 | True : si el string es uno numerico | |
2709 | False : no es un string numerico |
|
2709 | False : no es un string numerico | |
2710 | """ |
|
2710 | """ | |
2711 | try: |
|
2711 | try: | |
2712 | float( str ) |
|
2712 | float( str ) | |
2713 | return True |
|
2713 | return True | |
2714 | except: |
|
2714 | except: | |
2715 | return False |
|
2715 | return False | |
2716 |
|
2716 | |||
2717 | def setup(self, dataOut, wrpath): |
|
2717 | def setup(self, dataOut, wrpath): | |
2718 |
|
2718 | |||
2719 | if not(os.path.exists(wrpath)): |
|
2719 | if not(os.path.exists(wrpath)): | |
2720 | os.mkdir(wrpath) |
|
2720 | os.mkdir(wrpath) | |
2721 |
|
2721 | |||
2722 | self.wrpath = wrpath |
|
2722 | self.wrpath = wrpath | |
2723 | # self.setFile = 0 |
|
2723 | # self.setFile = 0 | |
2724 | self.dataOut = dataOut |
|
2724 | self.dataOut = dataOut | |
2725 |
|
2725 | |||
2726 | def putData(self): |
|
2726 | def putData(self): | |
2727 | name= time.localtime( self.dataOut.utctime) |
|
2727 | name= time.localtime( self.dataOut.utctime) | |
2728 | ext=".fits" |
|
2728 | ext=".fits" | |
2729 |
|
2729 | |||
2730 | if self.doypath == None: |
|
2730 | if self.doypath == None: | |
2731 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) |
|
2731 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) | |
2732 | self.doypath = os.path.join( self.wrpath, self.subfolder ) |
|
2732 | self.doypath = os.path.join( self.wrpath, self.subfolder ) | |
2733 | os.mkdir(self.doypath) |
|
2733 | os.mkdir(self.doypath) | |
2734 |
|
2734 | |||
2735 | if self.setFile == None: |
|
2735 | if self.setFile == None: | |
2736 | # self.set = self.dataOut.set |
|
2736 | # self.set = self.dataOut.set | |
2737 | self.setFile = 0 |
|
2737 | self.setFile = 0 | |
2738 | # if self.set != self.dataOut.set: |
|
2738 | # if self.set != self.dataOut.set: | |
2739 | ## self.set = self.dataOut.set |
|
2739 | ## self.set = self.dataOut.set | |
2740 | # self.setFile = 0 |
|
2740 | # self.setFile = 0 | |
2741 |
|
2741 | |||
2742 | #make the filename |
|
2742 | #make the filename | |
2743 | file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
2743 | file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) | |
2744 |
|
2744 | |||
2745 | filename = os.path.join(self.wrpath,self.subfolder, file) |
|
2745 | filename = os.path.join(self.wrpath,self.subfolder, file) | |
2746 |
|
2746 | |||
2747 | idblock = numpy.array([self.idblock],dtype="int64") |
|
2747 | idblock = numpy.array([self.idblock],dtype="int64") | |
2748 | header=self.wrObj.cFImage(idblock=idblock, |
|
2748 | header=self.wrObj.cFImage(idblock=idblock, | |
2749 | year=time.gmtime(self.dataOut.utctime).tm_year, |
|
2749 | year=time.gmtime(self.dataOut.utctime).tm_year, | |
2750 | month=time.gmtime(self.dataOut.utctime).tm_mon, |
|
2750 | month=time.gmtime(self.dataOut.utctime).tm_mon, | |
2751 | day=time.gmtime(self.dataOut.utctime).tm_mday, |
|
2751 | day=time.gmtime(self.dataOut.utctime).tm_mday, | |
2752 | hour=time.gmtime(self.dataOut.utctime).tm_hour, |
|
2752 | hour=time.gmtime(self.dataOut.utctime).tm_hour, | |
2753 | minute=time.gmtime(self.dataOut.utctime).tm_min, |
|
2753 | minute=time.gmtime(self.dataOut.utctime).tm_min, | |
2754 | second=time.gmtime(self.dataOut.utctime).tm_sec) |
|
2754 | second=time.gmtime(self.dataOut.utctime).tm_sec) | |
2755 |
|
2755 | |||
2756 | c=3E8 |
|
2756 | c=3E8 | |
2757 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2757 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
2758 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000)) |
|
2758 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000)) | |
2759 |
|
2759 | |||
2760 | colList = [] |
|
2760 | colList = [] | |
2761 |
|
2761 | |||
2762 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
2762 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) | |
2763 |
|
2763 | |||
2764 | colList.append(colFreq) |
|
2764 | colList.append(colFreq) | |
2765 |
|
2765 | |||
2766 | nchannel=self.dataOut.nChannels |
|
2766 | nchannel=self.dataOut.nChannels | |
2767 |
|
2767 | |||
2768 | for i in range(nchannel): |
|
2768 | for i in range(nchannel): | |
2769 | col = self.wrObj.writeData(name="PCh"+str(i+1), |
|
2769 | col = self.wrObj.writeData(name="PCh"+str(i+1), | |
2770 | format=str(self.dataOut.nFFTPoints)+'E', |
|
2770 | format=str(self.dataOut.nFFTPoints)+'E', | |
2771 | data=10*numpy.log10(self.dataOut.data_spc[i,:])) |
|
2771 | data=10*numpy.log10(self.dataOut.data_spc[i,:])) | |
2772 |
|
2772 | |||
2773 | colList.append(col) |
|
2773 | colList.append(col) | |
2774 |
|
2774 | |||
2775 | data=self.wrObj.Ctable(colList=colList) |
|
2775 | data=self.wrObj.Ctable(colList=colList) | |
2776 |
|
2776 | |||
2777 | self.wrObj.CFile(header,data) |
|
2777 | self.wrObj.CFile(header,data) | |
2778 |
|
2778 | |||
2779 | self.wrObj.wFile(filename) |
|
2779 | self.wrObj.wFile(filename) | |
2780 |
|
2780 | |||
2781 | #update the setFile |
|
2781 | #update the setFile | |
2782 | self.setFile += 1 |
|
2782 | self.setFile += 1 | |
2783 | self.idblock += 1 |
|
2783 | self.idblock += 1 | |
2784 |
|
2784 | |||
2785 | return 1 |
|
2785 | return 1 | |
2786 |
|
2786 | |||
2787 | def run(self, dataOut, **kwargs): |
|
2787 | def run(self, dataOut, **kwargs): | |
2788 |
|
2788 | |||
2789 | if not(self.isConfig): |
|
2789 | if not(self.isConfig): | |
2790 |
|
2790 | |||
2791 | self.setup(dataOut, **kwargs) |
|
2791 | self.setup(dataOut, **kwargs) | |
2792 | self.isConfig = True |
|
2792 | self.isConfig = True | |
2793 |
|
2793 | |||
2794 | self.putData() |
|
2794 | self.putData() | |
2795 |
|
2795 | |||
2796 |
|
2796 | |||
2797 |
|
2797 | |||
2798 | class ParameterConf: |
|
2798 | class ParameterConf: | |
2799 | ELEMENTNAME = 'Parameter' |
|
2799 | ELEMENTNAME = 'Parameter' | |
2800 | def __init__(self): |
|
2800 | def __init__(self): | |
2801 | self.name = '' |
|
2801 | self.name = '' | |
2802 | self.value = '' |
|
2802 | self.value = '' | |
2803 |
|
2803 | |||
2804 | def readXml(self, parmElement): |
|
2804 | def readXml(self, parmElement): | |
2805 | self.name = parmElement.get('name') |
|
2805 | self.name = parmElement.get('name') | |
2806 | self.value = parmElement.get('value') |
|
2806 | self.value = parmElement.get('value') | |
2807 |
|
2807 | |||
2808 | def getElementName(self): |
|
2808 | def getElementName(self): | |
2809 | return self.ELEMENTNAME |
|
2809 | return self.ELEMENTNAME | |
2810 |
|
2810 | |||
2811 | class Metadata: |
|
2811 | class Metadata: | |
2812 |
|
2812 | |||
2813 | def __init__(self, filename): |
|
2813 | def __init__(self, filename): | |
2814 | self.parmConfObjList = [] |
|
2814 | self.parmConfObjList = [] | |
2815 | self.readXml(filename) |
|
2815 | self.readXml(filename) | |
2816 |
|
2816 | |||
2817 | def readXml(self, filename): |
|
2817 | def readXml(self, filename): | |
2818 | self.projectElement = None |
|
2818 | self.projectElement = None | |
2819 | self.procUnitConfObjDict = {} |
|
2819 | self.procUnitConfObjDict = {} | |
2820 | self.projectElement = ElementTree().parse(filename) |
|
2820 | self.projectElement = ElementTree().parse(filename) | |
2821 | self.project = self.projectElement.tag |
|
2821 | self.project = self.projectElement.tag | |
2822 |
|
2822 | |||
2823 | parmElementList = self.projectElement.getiterator(ParameterConf().getElementName()) |
|
2823 | parmElementList = self.projectElement.getiterator(ParameterConf().getElementName()) | |
2824 |
|
2824 | |||
2825 | for parmElement in parmElementList: |
|
2825 | for parmElement in parmElementList: | |
2826 | parmConfObj = ParameterConf() |
|
2826 | parmConfObj = ParameterConf() | |
2827 | parmConfObj.readXml(parmElement) |
|
2827 | parmConfObj.readXml(parmElement) | |
2828 | self.parmConfObjList.append(parmConfObj) |
|
2828 | self.parmConfObjList.append(parmConfObj) | |
2829 |
|
2829 | |||
2830 | class FitsWriter(Operation): |
|
2830 | class FitsWriter(Operation): | |
2831 |
|
2831 | |||
2832 | def __init__(self): |
|
2832 | def __init__(self): | |
2833 | self.isConfig = False |
|
2833 | self.isConfig = False | |
2834 | self.dataBlocksPerFile = None |
|
2834 | self.dataBlocksPerFile = None | |
2835 | self.blockIndex = 0 |
|
2835 | self.blockIndex = 0 | |
2836 | self.flagIsNewFile = 1 |
|
2836 | self.flagIsNewFile = 1 | |
2837 | self.fitsObj = None |
|
2837 | self.fitsObj = None | |
2838 | self.optchar = 'P' |
|
2838 | self.optchar = 'P' | |
2839 | self.ext = '.fits' |
|
2839 | self.ext = '.fits' | |
2840 | self.setFile = 0 |
|
2840 | self.setFile = 0 | |
2841 |
|
2841 | |||
2842 | def setFitsHeader(self, dataOut, metadatafile): |
|
2842 | def setFitsHeader(self, dataOut, metadatafile): | |
2843 |
|
2843 | |||
2844 | header_data = pyfits.PrimaryHDU() |
|
2844 | header_data = pyfits.PrimaryHDU() | |
2845 |
|
2845 | |||
2846 | metadata4fits = Metadata(metadatafile) |
|
2846 | metadata4fits = Metadata(metadatafile) | |
2847 | for parameter in metadata4fits.parmConfObjList: |
|
2847 | for parameter in metadata4fits.parmConfObjList: | |
2848 | parm_name = parameter.name |
|
2848 | parm_name = parameter.name | |
2849 | parm_value = parameter.value |
|
2849 | parm_value = parameter.value | |
2850 |
|
2850 | |||
2851 | # if parm_value == 'fromdatadatetime': |
|
2851 | # if parm_value == 'fromdatadatetime': | |
2852 | # value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) |
|
2852 | # value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) | |
2853 | # elif parm_value == 'fromdataheights': |
|
2853 | # elif parm_value == 'fromdataheights': | |
2854 | # value = dataOut.nHeights |
|
2854 | # value = dataOut.nHeights | |
2855 | # elif parm_value == 'fromdatachannel': |
|
2855 | # elif parm_value == 'fromdatachannel': | |
2856 | # value = dataOut.nChannels |
|
2856 | # value = dataOut.nChannels | |
2857 | # elif parm_value == 'fromdatasamples': |
|
2857 | # elif parm_value == 'fromdatasamples': | |
2858 | # value = dataOut.nFFTPoints |
|
2858 | # value = dataOut.nFFTPoints | |
2859 | # else: |
|
2859 | # else: | |
2860 | # value = parm_value |
|
2860 | # value = parm_value | |
2861 |
|
2861 | |||
2862 | header_data.header[parm_name] = parm_value |
|
2862 | header_data.header[parm_name] = parm_value | |
2863 |
|
2863 | |||
2864 |
|
2864 | |||
2865 | header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) |
|
2865 | header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) | |
2866 | header_data.header['CHANNELLIST'] = str(dataOut.channelList) |
|
2866 | header_data.header['CHANNELLIST'] = str(dataOut.channelList) | |
2867 | header_data.header['NCHANNELS'] = dataOut.nChannels |
|
2867 | header_data.header['NCHANNELS'] = dataOut.nChannels | |
2868 | #header_data.header['HEIGHTS'] = dataOut.heightList |
|
2868 | #header_data.header['HEIGHTS'] = dataOut.heightList | |
2869 | header_data.header['NHEIGHTS'] = dataOut.nHeights |
|
2869 | header_data.header['NHEIGHTS'] = dataOut.nHeights | |
2870 |
|
2870 | |||
2871 | header_data.header['IPPSECONDS'] = dataOut.ippSeconds |
|
2871 | header_data.header['IPPSECONDS'] = dataOut.ippSeconds | |
2872 | header_data.header['NCOHINT'] = dataOut.nCohInt |
|
2872 | header_data.header['NCOHINT'] = dataOut.nCohInt | |
2873 | header_data.header['NINCOHINT'] = dataOut.nIncohInt |
|
2873 | header_data.header['NINCOHINT'] = dataOut.nIncohInt | |
2874 | header_data.header['TIMEZONE'] = dataOut.timeZone |
|
2874 | header_data.header['TIMEZONE'] = dataOut.timeZone | |
2875 | header_data.header['NBLOCK'] = self.blockIndex |
|
2875 | header_data.header['NBLOCK'] = self.blockIndex | |
2876 |
|
2876 | |||
2877 | header_data.writeto(self.filename) |
|
2877 | header_data.writeto(self.filename) | |
2878 |
|
2878 | |||
2879 | self.addExtension(dataOut.heightList,'HEIGHTLIST') |
|
2879 | self.addExtension(dataOut.heightList,'HEIGHTLIST') | |
2880 |
|
2880 | |||
2881 |
|
2881 | |||
2882 | def setup(self, dataOut, path, dataBlocksPerFile, metadatafile): |
|
2882 | def setup(self, dataOut, path, dataBlocksPerFile, metadatafile): | |
2883 |
|
2883 | |||
2884 | self.path = path |
|
2884 | self.path = path | |
2885 | self.dataOut = dataOut |
|
2885 | self.dataOut = dataOut | |
2886 | self.metadatafile = metadatafile |
|
2886 | self.metadatafile = metadatafile | |
2887 | self.dataBlocksPerFile = dataBlocksPerFile |
|
2887 | self.dataBlocksPerFile = dataBlocksPerFile | |
2888 |
|
2888 | |||
2889 | def open(self): |
|
2889 | def open(self): | |
2890 | self.fitsObj = pyfits.open(self.filename, mode='update') |
|
2890 | self.fitsObj = pyfits.open(self.filename, mode='update') | |
2891 |
|
2891 | |||
2892 |
|
2892 | |||
2893 | def addExtension(self, data, tagname): |
|
2893 | def addExtension(self, data, tagname): | |
2894 | self.open() |
|
2894 | self.open() | |
2895 | extension = pyfits.ImageHDU(data=data, name=tagname) |
|
2895 | extension = pyfits.ImageHDU(data=data, name=tagname) | |
2896 | #extension.header['TAG'] = tagname |
|
2896 | #extension.header['TAG'] = tagname | |
2897 | self.fitsObj.append(extension) |
|
2897 | self.fitsObj.append(extension) | |
2898 | self.write() |
|
2898 | self.write() | |
2899 |
|
2899 | |||
2900 | def addData(self, data): |
|
2900 | def addData(self, data): | |
2901 | self.open() |
|
2901 | self.open() | |
2902 | extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE']) |
|
2902 | extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE']) | |
2903 | extension.header['UTCTIME'] = self.dataOut.utctime |
|
2903 | extension.header['UTCTIME'] = self.dataOut.utctime | |
2904 | self.fitsObj.append(extension) |
|
2904 | self.fitsObj.append(extension) | |
2905 | self.blockIndex += 1 |
|
2905 | self.blockIndex += 1 | |
2906 | self.fitsObj[0].header['NBLOCK'] = self.blockIndex |
|
2906 | self.fitsObj[0].header['NBLOCK'] = self.blockIndex | |
2907 |
|
2907 | |||
2908 | self.write() |
|
2908 | self.write() | |
2909 |
|
2909 | |||
2910 | def write(self): |
|
2910 | def write(self): | |
2911 |
|
2911 | |||
2912 | self.fitsObj.flush(verbose=True) |
|
2912 | self.fitsObj.flush(verbose=True) | |
2913 | self.fitsObj.close() |
|
2913 | self.fitsObj.close() | |
2914 |
|
2914 | |||
2915 |
|
2915 | |||
2916 | def setNextFile(self): |
|
2916 | def setNextFile(self): | |
2917 |
|
2917 | |||
2918 | ext = self.ext |
|
2918 | ext = self.ext | |
2919 | path = self.path |
|
2919 | path = self.path | |
2920 |
|
2920 | |||
2921 | timeTuple = time.localtime( self.dataOut.utctime) |
|
2921 | timeTuple = time.localtime( self.dataOut.utctime) | |
2922 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
2922 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
2923 |
|
2923 | |||
2924 | fullpath = os.path.join( path, subfolder ) |
|
2924 | fullpath = os.path.join( path, subfolder ) | |
2925 | if not( os.path.exists(fullpath) ): |
|
2925 | if not( os.path.exists(fullpath) ): | |
2926 | os.mkdir(fullpath) |
|
2926 | os.mkdir(fullpath) | |
2927 | self.setFile = -1 #inicializo mi contador de seteo |
|
2927 | self.setFile = -1 #inicializo mi contador de seteo | |
2928 | else: |
|
2928 | else: | |
2929 | filesList = os.listdir( fullpath ) |
|
2929 | filesList = os.listdir( fullpath ) | |
2930 | if len( filesList ) > 0: |
|
2930 | if len( filesList ) > 0: | |
2931 | filesList = sorted( filesList, key=str.lower ) |
|
2931 | filesList = sorted( filesList, key=str.lower ) | |
2932 | filen = filesList[-1] |
|
2932 | filen = filesList[-1] | |
2933 |
|
2933 | |||
2934 | if isNumber( filen[8:11] ): |
|
2934 | if isNumber( filen[8:11] ): | |
2935 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
2935 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
2936 | else: |
|
2936 | else: | |
2937 | self.setFile = -1 |
|
2937 | self.setFile = -1 | |
2938 | else: |
|
2938 | else: | |
2939 | self.setFile = -1 #inicializo mi contador de seteo |
|
2939 | self.setFile = -1 #inicializo mi contador de seteo | |
2940 |
|
2940 | |||
2941 | setFile = self.setFile |
|
2941 | setFile = self.setFile | |
2942 | setFile += 1 |
|
2942 | setFile += 1 | |
2943 |
|
2943 | |||
2944 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
2944 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
2945 | timeTuple.tm_year, |
|
2945 | timeTuple.tm_year, | |
2946 | timeTuple.tm_yday, |
|
2946 | timeTuple.tm_yday, | |
2947 | setFile, |
|
2947 | setFile, | |
2948 | ext ) |
|
2948 | ext ) | |
2949 |
|
2949 | |||
2950 | filename = os.path.join( path, subfolder, file ) |
|
2950 | filename = os.path.join( path, subfolder, file ) | |
2951 |
|
2951 | |||
2952 | self.blockIndex = 0 |
|
2952 | self.blockIndex = 0 | |
2953 | self.filename = filename |
|
2953 | self.filename = filename | |
2954 | self.setFile = setFile |
|
2954 | self.setFile = setFile | |
2955 | self.flagIsNewFile = 1 |
|
2955 | self.flagIsNewFile = 1 | |
2956 |
|
2956 | |||
2957 | print 'Writing the file: %s'%self.filename |
|
2957 | print 'Writing the file: %s'%self.filename | |
2958 |
|
2958 | |||
2959 | self.setFitsHeader(self.dataOut, self.metadatafile) |
|
2959 | self.setFitsHeader(self.dataOut, self.metadatafile) | |
2960 |
|
2960 | |||
2961 | return 1 |
|
2961 | return 1 | |
2962 |
|
2962 | |||
2963 | def writeBlock(self): |
|
2963 | def writeBlock(self): | |
2964 | self.addData(self.dataOut.data_spc) |
|
2964 | self.addData(self.dataOut.data_spc) | |
2965 | self.flagIsNewFile = 0 |
|
2965 | self.flagIsNewFile = 0 | |
2966 |
|
2966 | |||
2967 |
|
2967 | |||
2968 | def __setNewBlock(self): |
|
2968 | def __setNewBlock(self): | |
2969 |
|
2969 | |||
2970 | if self.flagIsNewFile: |
|
2970 | if self.flagIsNewFile: | |
2971 | return 1 |
|
2971 | return 1 | |
2972 |
|
2972 | |||
2973 | if self.blockIndex < self.dataBlocksPerFile: |
|
2973 | if self.blockIndex < self.dataBlocksPerFile: | |
2974 | return 1 |
|
2974 | return 1 | |
2975 |
|
2975 | |||
2976 | if not( self.setNextFile() ): |
|
2976 | if not( self.setNextFile() ): | |
2977 | return 0 |
|
2977 | return 0 | |
2978 |
|
2978 | |||
2979 | return 1 |
|
2979 | return 1 | |
2980 |
|
2980 | |||
2981 | def writeNextBlock(self): |
|
2981 | def writeNextBlock(self): | |
2982 | if not( self.__setNewBlock() ): |
|
2982 | if not( self.__setNewBlock() ): | |
2983 | return 0 |
|
2983 | return 0 | |
2984 | self.writeBlock() |
|
2984 | self.writeBlock() | |
2985 | return 1 |
|
2985 | return 1 | |
2986 |
|
2986 | |||
2987 | def putData(self): |
|
2987 | def putData(self): | |
2988 | if self.flagIsNewFile: |
|
2988 | if self.flagIsNewFile: | |
2989 | self.setNextFile() |
|
2989 | self.setNextFile() | |
2990 | self.writeNextBlock() |
|
2990 | self.writeNextBlock() | |
2991 |
|
2991 | |||
2992 | def run(self, dataOut, **kwargs): |
|
2992 | def run(self, dataOut, **kwargs): | |
2993 | if not(self.isConfig): |
|
2993 | if not(self.isConfig): | |
2994 | self.setup(dataOut, **kwargs) |
|
2994 | self.setup(dataOut, **kwargs) | |
2995 | self.isConfig = True |
|
2995 | self.isConfig = True | |
2996 | self.putData() |
|
2996 | self.putData() | |
2997 |
|
2997 | |||
2998 |
|
2998 | |||
2999 | class FitsReader(ProcessingUnit): |
|
2999 | class FitsReader(ProcessingUnit): | |
3000 |
|
3000 | |||
3001 | # __TIMEZONE = time.timezone |
|
3001 | # __TIMEZONE = time.timezone | |
3002 |
|
3002 | |||
3003 | expName = None |
|
3003 | expName = None | |
3004 | datetimestr = None |
|
3004 | datetimestr = None | |
3005 | utc = None |
|
3005 | utc = None | |
3006 | nChannels = None |
|
3006 | nChannels = None | |
3007 | nSamples = None |
|
3007 | nSamples = None | |
3008 | dataBlocksPerFile = None |
|
3008 | dataBlocksPerFile = None | |
3009 | comments = None |
|
3009 | comments = None | |
3010 | lastUTTime = None |
|
3010 | lastUTTime = None | |
3011 | header_dict = None |
|
3011 | header_dict = None | |
3012 | data = None |
|
3012 | data = None | |
3013 | data_header_dict = None |
|
3013 | data_header_dict = None | |
3014 |
|
3014 | |||
3015 | def __init__(self): |
|
3015 | def __init__(self): | |
3016 | self.isConfig = False |
|
3016 | self.isConfig = False | |
3017 | self.ext = '.fits' |
|
3017 | self.ext = '.fits' | |
3018 | self.setFile = 0 |
|
3018 | self.setFile = 0 | |
3019 | self.flagNoMoreFiles = 0 |
|
3019 | self.flagNoMoreFiles = 0 | |
3020 | self.flagIsNewFile = 1 |
|
3020 | self.flagIsNewFile = 1 | |
3021 | self.flagTimeBlock = None |
|
3021 | self.flagTimeBlock = None | |
3022 | self.fileIndex = None |
|
3022 | self.fileIndex = None | |
3023 | self.filename = None |
|
3023 | self.filename = None | |
3024 | self.fileSize = None |
|
3024 | self.fileSize = None | |
3025 | self.fitsObj = None |
|
3025 | self.fitsObj = None | |
3026 | self.timeZone = None |
|
3026 | self.timeZone = None | |
3027 | self.nReadBlocks = 0 |
|
3027 | self.nReadBlocks = 0 | |
3028 | self.nTotalBlocks = 0 |
|
3028 | self.nTotalBlocks = 0 | |
3029 | self.dataOut = self.createObjByDefault() |
|
3029 | self.dataOut = self.createObjByDefault() | |
3030 | self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup() |
|
3030 | self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup() | |
3031 | self.blockIndex = 1 |
|
3031 | self.blockIndex = 1 | |
3032 |
|
3032 | |||
3033 | def createObjByDefault(self): |
|
3033 | def createObjByDefault(self): | |
3034 |
|
3034 | |||
3035 | dataObj = Fits() |
|
3035 | dataObj = Fits() | |
3036 |
|
3036 | |||
3037 | return dataObj |
|
3037 | return dataObj | |
3038 |
|
3038 | |||
3039 | def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False): |
|
3039 | def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False): | |
3040 | try: |
|
3040 | try: | |
3041 | fitsObj = pyfits.open(filename,'readonly') |
|
3041 | fitsObj = pyfits.open(filename,'readonly') | |
3042 | except: |
|
3042 | except: | |
3043 | raise IOError, "The file %s can't be opened" %(filename) |
|
3043 | raise IOError, "The file %s can't be opened" %(filename) | |
3044 |
|
3044 | |||
3045 | header = fitsObj[0].header |
|
3045 | header = fitsObj[0].header | |
3046 | struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S") |
|
3046 | struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S") | |
3047 | utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS |
|
3047 | utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS | |
3048 |
|
3048 | |||
3049 | ltc = utc |
|
3049 | ltc = utc | |
3050 | if useLocalTime: |
|
3050 | if useLocalTime: | |
3051 | ltc -= time.timezone |
|
3051 | ltc -= time.timezone | |
3052 | thisDatetime = datetime.datetime.utcfromtimestamp(ltc) |
|
3052 | thisDatetime = datetime.datetime.utcfromtimestamp(ltc) | |
3053 | thisTime = thisDatetime.time() |
|
3053 | thisTime = thisDatetime.time() | |
3054 |
|
3054 | |||
3055 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
3055 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |
3056 | return None |
|
3056 | return None | |
3057 |
|
3057 | |||
3058 | return thisDatetime |
|
3058 | return thisDatetime | |
3059 |
|
3059 | |||
3060 | def __setNextFileOnline(self): |
|
3060 | def __setNextFileOnline(self): | |
3061 | raise ValueError, "No implemented" |
|
3061 | raise ValueError, "No implemented" | |
3062 |
|
3062 | |||
3063 | def __setNextFileOffline(self): |
|
3063 | def __setNextFileOffline(self): | |
3064 | idFile = self.fileIndex |
|
3064 | idFile = self.fileIndex | |
3065 |
|
3065 | |||
3066 | while (True): |
|
3066 | while (True): | |
3067 | idFile += 1 |
|
3067 | idFile += 1 | |
3068 | if not(idFile < len(self.filenameList)): |
|
3068 | if not(idFile < len(self.filenameList)): | |
3069 | self.flagNoMoreFiles = 1 |
|
3069 | self.flagNoMoreFiles = 1 | |
3070 | print "No more Files" |
|
3070 | print "No more Files" | |
3071 | return 0 |
|
3071 | return 0 | |
3072 |
|
3072 | |||
3073 | filename = self.filenameList[idFile] |
|
3073 | filename = self.filenameList[idFile] | |
3074 |
|
3074 | |||
3075 | # if not(self.__verifyFile(filename)): |
|
3075 | # if not(self.__verifyFile(filename)): | |
3076 | # continue |
|
3076 | # continue | |
3077 |
|
3077 | |||
3078 | fileSize = os.path.getsize(filename) |
|
3078 | fileSize = os.path.getsize(filename) | |
3079 | fitsObj = pyfits.open(filename,'readonly') |
|
3079 | fitsObj = pyfits.open(filename,'readonly') | |
3080 | break |
|
3080 | break | |
3081 |
|
3081 | |||
3082 | self.flagIsNewFile = 1 |
|
3082 | self.flagIsNewFile = 1 | |
3083 | self.fileIndex = idFile |
|
3083 | self.fileIndex = idFile | |
3084 | self.filename = filename |
|
3084 | self.filename = filename | |
3085 | self.fileSize = fileSize |
|
3085 | self.fileSize = fileSize | |
3086 | self.fitsObj = fitsObj |
|
3086 | self.fitsObj = fitsObj | |
3087 | self.blockIndex = 0 |
|
3087 | self.blockIndex = 0 | |
3088 | print "Setting the file: %s"%self.filename |
|
3088 | print "Setting the file: %s"%self.filename | |
3089 |
|
3089 | |||
3090 | return 1 |
|
3090 | return 1 | |
3091 |
|
3091 | |||
3092 | def readHeader(self): |
|
3092 | def readHeader(self): | |
3093 | headerObj = self.fitsObj[0] |
|
3093 | headerObj = self.fitsObj[0] | |
3094 |
|
3094 | |||
3095 | self.header_dict = headerObj.header |
|
3095 | self.header_dict = headerObj.header | |
3096 | if 'EXPNAME' in headerObj.header.keys(): |
|
3096 | if 'EXPNAME' in headerObj.header.keys(): | |
3097 | self.expName = headerObj.header['EXPNAME'] |
|
3097 | self.expName = headerObj.header['EXPNAME'] | |
3098 |
|
3098 | |||
3099 | if 'DATATYPE' in headerObj.header.keys(): |
|
3099 | if 'DATATYPE' in headerObj.header.keys(): | |
3100 | self.dataType = headerObj.header['DATATYPE'] |
|
3100 | self.dataType = headerObj.header['DATATYPE'] | |
3101 |
|
3101 | |||
3102 | self.datetimestr = headerObj.header['DATETIME'] |
|
3102 | self.datetimestr = headerObj.header['DATETIME'] | |
3103 | channelList = headerObj.header['CHANNELLIST'] |
|
3103 | channelList = headerObj.header['CHANNELLIST'] | |
3104 | channelList = channelList.split('[') |
|
3104 | channelList = channelList.split('[') | |
3105 | channelList = channelList[1].split(']') |
|
3105 | channelList = channelList[1].split(']') | |
3106 | channelList = channelList[0].split(',') |
|
3106 | channelList = channelList[0].split(',') | |
3107 | channelList = [int(ch) for ch in channelList] |
|
3107 | channelList = [int(ch) for ch in channelList] | |
3108 | self.channelList = channelList |
|
3108 | self.channelList = channelList | |
3109 | self.nChannels = headerObj.header['NCHANNELS'] |
|
3109 | self.nChannels = headerObj.header['NCHANNELS'] | |
3110 | self.nHeights = headerObj.header['NHEIGHTS'] |
|
3110 | self.nHeights = headerObj.header['NHEIGHTS'] | |
3111 | self.ippSeconds = headerObj.header['IPPSECONDS'] |
|
3111 | self.ippSeconds = headerObj.header['IPPSECONDS'] | |
3112 | self.nCohInt = headerObj.header['NCOHINT'] |
|
3112 | self.nCohInt = headerObj.header['NCOHINT'] | |
3113 | self.nIncohInt = headerObj.header['NINCOHINT'] |
|
3113 | self.nIncohInt = headerObj.header['NINCOHINT'] | |
3114 | self.dataBlocksPerFile = headerObj.header['NBLOCK'] |
|
3114 | self.dataBlocksPerFile = headerObj.header['NBLOCK'] | |
3115 | self.timeZone = headerObj.header['TIMEZONE'] |
|
3115 | self.timeZone = headerObj.header['TIMEZONE'] | |
3116 |
|
3116 | |||
3117 | self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
3117 | self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt | |
3118 |
|
3118 | |||
3119 | if 'COMMENT' in headerObj.header.keys(): |
|
3119 | if 'COMMENT' in headerObj.header.keys(): | |
3120 | self.comments = headerObj.header['COMMENT'] |
|
3120 | self.comments = headerObj.header['COMMENT'] | |
3121 |
|
3121 | |||
3122 | self.readHeightList() |
|
3122 | self.readHeightList() | |
3123 |
|
3123 | |||
3124 | def readHeightList(self): |
|
3124 | def readHeightList(self): | |
3125 | self.blockIndex = self.blockIndex + 1 |
|
3125 | self.blockIndex = self.blockIndex + 1 | |
3126 | obj = self.fitsObj[self.blockIndex] |
|
3126 | obj = self.fitsObj[self.blockIndex] | |
3127 | self.heightList = obj.data |
|
3127 | self.heightList = obj.data | |
3128 | self.blockIndex = self.blockIndex + 1 |
|
3128 | self.blockIndex = self.blockIndex + 1 | |
3129 |
|
3129 | |||
3130 | def readExtension(self): |
|
3130 | def readExtension(self): | |
3131 | obj = self.fitsObj[self.blockIndex] |
|
3131 | obj = self.fitsObj[self.blockIndex] | |
3132 | self.heightList = obj.data |
|
3132 | self.heightList = obj.data | |
3133 | self.blockIndex = self.blockIndex + 1 |
|
3133 | self.blockIndex = self.blockIndex + 1 | |
3134 |
|
3134 | |||
3135 | def setNextFile(self): |
|
3135 | def setNextFile(self): | |
3136 |
|
3136 | |||
3137 | if self.online: |
|
3137 | if self.online: | |
3138 | newFile = self.__setNextFileOnline() |
|
3138 | newFile = self.__setNextFileOnline() | |
3139 | else: |
|
3139 | else: | |
3140 | newFile = self.__setNextFileOffline() |
|
3140 | newFile = self.__setNextFileOffline() | |
3141 |
|
3141 | |||
3142 | if not(newFile): |
|
3142 | if not(newFile): | |
3143 | return 0 |
|
3143 | return 0 | |
3144 |
|
3144 | |||
3145 | self.readHeader() |
|
3145 | self.readHeader() | |
3146 |
|
3146 | |||
3147 | self.nReadBlocks = 0 |
|
3147 | self.nReadBlocks = 0 | |
3148 | # self.blockIndex = 1 |
|
3148 | # self.blockIndex = 1 | |
3149 | return 1 |
|
3149 | return 1 | |
3150 |
|
3150 | |||
3151 | def __searchFilesOffLine(self, |
|
3151 | def __searchFilesOffLine(self, | |
3152 | path, |
|
3152 | path, | |
3153 | startDate, |
|
3153 | startDate, | |
3154 | endDate, |
|
3154 | endDate, | |
3155 | startTime=datetime.time(0,0,0), |
|
3155 | startTime=datetime.time(0,0,0), | |
3156 | endTime=datetime.time(23,59,59), |
|
3156 | endTime=datetime.time(23,59,59), | |
3157 | set=None, |
|
3157 | set=None, | |
3158 | expLabel='', |
|
3158 | expLabel='', | |
3159 | ext='.fits', |
|
3159 | ext='.fits', | |
3160 | walk=True): |
|
3160 | walk=True): | |
3161 |
|
3161 | |||
3162 | pathList = [] |
|
3162 | pathList = [] | |
3163 |
|
3163 | |||
3164 | if not walk: |
|
3164 | if not walk: | |
3165 | pathList.append(path) |
|
3165 | pathList.append(path) | |
3166 |
|
3166 | |||
3167 | else: |
|
3167 | else: | |
3168 | dirList = [] |
|
3168 | dirList = [] | |
3169 | for thisPath in os.listdir(path): |
|
3169 | for thisPath in os.listdir(path): | |
3170 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
3170 | if not os.path.isdir(os.path.join(path,thisPath)): | |
3171 | continue |
|
3171 | continue | |
3172 | if not isDoyFolder(thisPath): |
|
3172 | if not isDoyFolder(thisPath): | |
3173 | continue |
|
3173 | continue | |
3174 |
|
3174 | |||
3175 | dirList.append(thisPath) |
|
3175 | dirList.append(thisPath) | |
3176 |
|
3176 | |||
3177 | if not(dirList): |
|
3177 | if not(dirList): | |
3178 | return None, None |
|
3178 | return None, None | |
3179 |
|
3179 | |||
3180 | thisDate = startDate |
|
3180 | thisDate = startDate | |
3181 |
|
3181 | |||
3182 | while(thisDate <= endDate): |
|
3182 | while(thisDate <= endDate): | |
3183 | year = thisDate.timetuple().tm_year |
|
3183 | year = thisDate.timetuple().tm_year | |
3184 | doy = thisDate.timetuple().tm_yday |
|
3184 | doy = thisDate.timetuple().tm_yday | |
3185 |
|
3185 | |||
3186 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
3186 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') | |
3187 | if len(matchlist) == 0: |
|
3187 | if len(matchlist) == 0: | |
3188 | thisDate += datetime.timedelta(1) |
|
3188 | thisDate += datetime.timedelta(1) | |
3189 | continue |
|
3189 | continue | |
3190 | for match in matchlist: |
|
3190 | for match in matchlist: | |
3191 | pathList.append(os.path.join(path,match,expLabel)) |
|
3191 | pathList.append(os.path.join(path,match,expLabel)) | |
3192 |
|
3192 | |||
3193 | thisDate += datetime.timedelta(1) |
|
3193 | thisDate += datetime.timedelta(1) | |
3194 |
|
3194 | |||
3195 | if pathList == []: |
|
3195 | if pathList == []: | |
3196 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
3196 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) | |
3197 | return None, None |
|
3197 | return None, None | |
3198 |
|
3198 | |||
3199 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
3199 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) | |
3200 |
|
3200 | |||
3201 | filenameList = [] |
|
3201 | filenameList = [] | |
3202 | datetimeList = [] |
|
3202 | datetimeList = [] | |
3203 |
|
3203 | |||
3204 | for i in range(len(pathList)): |
|
3204 | for i in range(len(pathList)): | |
3205 |
|
3205 | |||
3206 | thisPath = pathList[i] |
|
3206 | thisPath = pathList[i] | |
3207 |
|
3207 | |||
3208 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
3208 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
3209 | fileList.sort() |
|
3209 | fileList.sort() | |
3210 |
|
3210 | |||
3211 | for file in fileList: |
|
3211 | for file in fileList: | |
3212 |
|
3212 | |||
3213 | filename = os.path.join(thisPath,file) |
|
3213 | filename = os.path.join(thisPath,file) | |
3214 | thisDatetime = self.isFileinThisTime(filename, startTime, endTime) |
|
3214 | thisDatetime = self.isFileinThisTime(filename, startTime, endTime) | |
3215 |
|
3215 | |||
3216 | if not(thisDatetime): |
|
3216 | if not(thisDatetime): | |
3217 | continue |
|
3217 | continue | |
3218 |
|
3218 | |||
3219 | filenameList.append(filename) |
|
3219 | filenameList.append(filename) | |
3220 | datetimeList.append(thisDatetime) |
|
3220 | datetimeList.append(thisDatetime) | |
3221 |
|
3221 | |||
3222 | if not(filenameList): |
|
3222 | if not(filenameList): | |
3223 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
3223 | print "Any file was found for the time range %s - %s" %(startTime, endTime) | |
3224 | return None, None |
|
3224 | return None, None | |
3225 |
|
3225 | |||
3226 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
3226 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) | |
3227 |
|
3227 | |||
3228 |
|
3228 | |||
3229 | for i in range(len(filenameList)): |
|
3229 | for i in range(len(filenameList)): | |
3230 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
3230 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) | |
3231 |
|
3231 | |||
3232 | self.filenameList = filenameList |
|
3232 | self.filenameList = filenameList | |
3233 | self.datetimeList = datetimeList |
|
3233 | self.datetimeList = datetimeList | |
3234 |
|
3234 | |||
3235 | return pathList, filenameList |
|
3235 | return pathList, filenameList | |
3236 |
|
3236 | |||
3237 | def setup(self, path=None, |
|
3237 | def setup(self, path=None, | |
3238 | startDate=None, |
|
3238 | startDate=None, | |
3239 | endDate=None, |
|
3239 | endDate=None, | |
3240 | startTime=datetime.time(0,0,0), |
|
3240 | startTime=datetime.time(0,0,0), | |
3241 | endTime=datetime.time(23,59,59), |
|
3241 | endTime=datetime.time(23,59,59), | |
3242 | set=0, |
|
3242 | set=0, | |
3243 | expLabel = "", |
|
3243 | expLabel = "", | |
3244 | ext = None, |
|
3244 | ext = None, | |
3245 | online = False, |
|
3245 | online = False, | |
3246 | delay = 60, |
|
3246 | delay = 60, | |
3247 | walk = True): |
|
3247 | walk = True): | |
3248 |
|
3248 | |||
3249 | if path == None: |
|
3249 | if path == None: | |
3250 | raise ValueError, "The path is not valid" |
|
3250 | raise ValueError, "The path is not valid" | |
3251 |
|
3251 | |||
3252 | if ext == None: |
|
3252 | if ext == None: | |
3253 | ext = self.ext |
|
3253 | ext = self.ext | |
3254 |
|
3254 | |||
3255 | if not(online): |
|
3255 | if not(online): | |
3256 | print "Searching files in offline mode ..." |
|
3256 | print "Searching files in offline mode ..." | |
3257 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
3257 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
3258 | startTime=startTime, endTime=endTime, |
|
3258 | startTime=startTime, endTime=endTime, | |
3259 | set=set, expLabel=expLabel, ext=ext, |
|
3259 | set=set, expLabel=expLabel, ext=ext, | |
3260 | walk=walk) |
|
3260 | walk=walk) | |
3261 |
|
3261 | |||
3262 | if not(pathList): |
|
3262 | if not(pathList): | |
3263 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
3263 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
3264 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
3264 | datetime.datetime.combine(startDate,startTime).ctime(), | |
3265 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
3265 | datetime.datetime.combine(endDate,endTime).ctime()) | |
3266 |
|
3266 | |||
3267 | sys.exit(-1) |
|
3267 | sys.exit(-1) | |
3268 |
|
3268 | |||
3269 | self.fileIndex = -1 |
|
3269 | self.fileIndex = -1 | |
3270 | self.pathList = pathList |
|
3270 | self.pathList = pathList | |
3271 | self.filenameList = filenameList |
|
3271 | self.filenameList = filenameList | |
3272 |
|
3272 | |||
3273 | self.online = online |
|
3273 | self.online = online | |
3274 | self.delay = delay |
|
3274 | self.delay = delay | |
3275 | ext = ext.lower() |
|
3275 | ext = ext.lower() | |
3276 | self.ext = ext |
|
3276 | self.ext = ext | |
3277 |
|
3277 | |||
3278 | if not(self.setNextFile()): |
|
3278 | if not(self.setNextFile()): | |
3279 | if (startDate!=None) and (endDate!=None): |
|
3279 | if (startDate!=None) and (endDate!=None): | |
3280 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
3280 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
3281 | elif startDate != None: |
|
3281 | elif startDate != None: | |
3282 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
3282 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
3283 | else: |
|
3283 | else: | |
3284 | print "No files" |
|
3284 | print "No files" | |
3285 |
|
3285 | |||
3286 | sys.exit(-1) |
|
3286 | sys.exit(-1) | |
3287 |
|
3287 | |||
3288 |
|
3288 | |||
3289 |
|
3289 | |||
3290 | def readBlock(self): |
|
3290 | def readBlock(self): | |
3291 | dataObj = self.fitsObj[self.blockIndex] |
|
3291 | dataObj = self.fitsObj[self.blockIndex] | |
3292 |
|
3292 | |||
3293 | self.data = dataObj.data |
|
3293 | self.data = dataObj.data | |
3294 | self.data_header_dict = dataObj.header |
|
3294 | self.data_header_dict = dataObj.header | |
3295 | self.utc = self.data_header_dict['UTCTIME'] |
|
3295 | self.utc = self.data_header_dict['UTCTIME'] | |
3296 |
|
3296 | |||
3297 | self.flagIsNewFile = 0 |
|
3297 | self.flagIsNewFile = 0 | |
3298 | self.blockIndex += 1 |
|
3298 | self.blockIndex += 1 | |
3299 | self.nTotalBlocks += 1 |
|
3299 | self.nTotalBlocks += 1 | |
3300 | self.nReadBlocks += 1 |
|
3300 | self.nReadBlocks += 1 | |
3301 |
|
3301 | |||
3302 | return 1 |
|
3302 | return 1 | |
3303 |
|
3303 | |||
3304 | def __jumpToLastBlock(self): |
|
3304 | def __jumpToLastBlock(self): | |
3305 | raise ValueError, "No implemented" |
|
3305 | raise ValueError, "No implemented" | |
3306 |
|
3306 | |||
3307 | def __waitNewBlock(self): |
|
3307 | def __waitNewBlock(self): | |
3308 | """ |
|
3308 | """ | |
3309 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
3309 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
3310 |
|
3310 | |||
3311 | Si el modo de lectura es OffLine siempre retorn 0 |
|
3311 | Si el modo de lectura es OffLine siempre retorn 0 | |
3312 | """ |
|
3312 | """ | |
3313 | if not self.online: |
|
3313 | if not self.online: | |
3314 | return 0 |
|
3314 | return 0 | |
3315 |
|
3315 | |||
3316 | if (self.nReadBlocks >= self.dataBlocksPerFile): |
|
3316 | if (self.nReadBlocks >= self.dataBlocksPerFile): | |
3317 | return 0 |
|
3317 | return 0 | |
3318 |
|
3318 | |||
3319 | currentPointer = self.fp.tell() |
|
3319 | currentPointer = self.fp.tell() | |
3320 |
|
3320 | |||
3321 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
3321 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
3322 |
|
3322 | |||
3323 | for nTries in range( self.nTries ): |
|
3323 | for nTries in range( self.nTries ): | |
3324 |
|
3324 | |||
3325 | self.fp.close() |
|
3325 | self.fp.close() | |
3326 | self.fp = open( self.filename, 'rb' ) |
|
3326 | self.fp = open( self.filename, 'rb' ) | |
3327 | self.fp.seek( currentPointer ) |
|
3327 | self.fp.seek( currentPointer ) | |
3328 |
|
3328 | |||
3329 | self.fileSize = os.path.getsize( self.filename ) |
|
3329 | self.fileSize = os.path.getsize( self.filename ) | |
3330 | currentSize = self.fileSize - currentPointer |
|
3330 | currentSize = self.fileSize - currentPointer | |
3331 |
|
3331 | |||
3332 | if ( currentSize >= neededSize ): |
|
3332 | if ( currentSize >= neededSize ): | |
3333 | self.__rdBasicHeader() |
|
3333 | self.__rdBasicHeader() | |
3334 | return 1 |
|
3334 | return 1 | |
3335 |
|
3335 | |||
3336 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
3336 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
3337 | time.sleep( self.delay ) |
|
3337 | time.sleep( self.delay ) | |
3338 |
|
3338 | |||
3339 |
|
3339 | |||
3340 | return 0 |
|
3340 | return 0 | |
3341 |
|
3341 | |||
3342 | def __setNewBlock(self): |
|
3342 | def __setNewBlock(self): | |
3343 |
|
3343 | |||
3344 | if self.online: |
|
3344 | if self.online: | |
3345 | self.__jumpToLastBlock() |
|
3345 | self.__jumpToLastBlock() | |
3346 |
|
3346 | |||
3347 | if self.flagIsNewFile: |
|
3347 | if self.flagIsNewFile: | |
3348 | return 1 |
|
3348 | return 1 | |
3349 |
|
3349 | |||
3350 | self.lastUTTime = self.utc |
|
3350 | self.lastUTTime = self.utc | |
3351 |
|
3351 | |||
3352 | if self.online: |
|
3352 | if self.online: | |
3353 | if self.__waitNewBlock(): |
|
3353 | if self.__waitNewBlock(): | |
3354 | return 1 |
|
3354 | return 1 | |
3355 |
|
3355 | |||
3356 | if self.nReadBlocks < self.dataBlocksPerFile: |
|
3356 | if self.nReadBlocks < self.dataBlocksPerFile: | |
3357 | return 1 |
|
3357 | return 1 | |
3358 |
|
3358 | |||
3359 | if not(self.setNextFile()): |
|
3359 | if not(self.setNextFile()): | |
3360 | return 0 |
|
3360 | return 0 | |
3361 |
|
3361 | |||
3362 | deltaTime = self.utc - self.lastUTTime |
|
3362 | deltaTime = self.utc - self.lastUTTime | |
3363 |
|
3363 | |||
3364 | self.flagTimeBlock = 0 |
|
3364 | self.flagTimeBlock = 0 | |
3365 |
|
3365 | |||
3366 | if deltaTime > self.maxTimeStep: |
|
3366 | if deltaTime > self.maxTimeStep: | |
3367 | self.flagTimeBlock = 1 |
|
3367 | self.flagTimeBlock = 1 | |
3368 |
|
3368 | |||
3369 | return 1 |
|
3369 | return 1 | |
3370 |
|
3370 | |||
3371 |
|
3371 | |||
3372 | def readNextBlock(self): |
|
3372 | def readNextBlock(self): | |
3373 | if not(self.__setNewBlock()): |
|
3373 | if not(self.__setNewBlock()): | |
3374 | return 0 |
|
3374 | return 0 | |
3375 |
|
3375 | |||
3376 | if not(self.readBlock()): |
|
3376 | if not(self.readBlock()): | |
3377 | return 0 |
|
3377 | return 0 | |
3378 |
|
3378 | |||
3379 | return 1 |
|
3379 | return 1 | |
3380 |
|
3380 | |||
3381 |
|
3381 | |||
3382 | def getData(self): |
|
3382 | def getData(self): | |
3383 |
|
3383 | |||
3384 | if self.flagNoMoreFiles: |
|
3384 | if self.flagNoMoreFiles: | |
3385 | self.dataOut.flagNoData = True |
|
3385 | self.dataOut.flagNoData = True | |
3386 | print 'Process finished' |
|
3386 | print 'Process finished' | |
3387 | return 0 |
|
3387 | return 0 | |
3388 |
|
3388 | |||
3389 | self.flagTimeBlock = 0 |
|
3389 | self.flagTimeBlock = 0 | |
3390 | self.flagIsNewBlock = 0 |
|
3390 | self.flagIsNewBlock = 0 | |
3391 |
|
3391 | |||
3392 | if not(self.readNextBlock()): |
|
3392 | if not(self.readNextBlock()): | |
3393 | return 0 |
|
3393 | return 0 | |
3394 |
|
3394 | |||
3395 | if self.data == None: |
|
3395 | if self.data == None: | |
3396 | self.dataOut.flagNoData = True |
|
3396 | self.dataOut.flagNoData = True | |
3397 | return 0 |
|
3397 | return 0 | |
3398 |
|
3398 | |||
3399 | self.dataOut.data = self.data |
|
3399 | self.dataOut.data = self.data | |
3400 | self.dataOut.data_header = self.data_header_dict |
|
3400 | self.dataOut.data_header = self.data_header_dict | |
3401 | self.dataOut.utctime = self.utc |
|
3401 | self.dataOut.utctime = self.utc | |
3402 |
|
3402 | |||
3403 | self.dataOut.header = self.header_dict |
|
3403 | self.dataOut.header = self.header_dict | |
3404 | self.dataOut.expName = self.expName |
|
3404 | self.dataOut.expName = self.expName | |
3405 | self.dataOut.nChannels = self.nChannels |
|
3405 | self.dataOut.nChannels = self.nChannels | |
3406 | self.dataOut.timeZone = self.timeZone |
|
3406 | self.dataOut.timeZone = self.timeZone | |
3407 | self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile |
|
3407 | self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile | |
3408 | self.dataOut.comments = self.comments |
|
3408 | self.dataOut.comments = self.comments | |
3409 | self.dataOut.timeInterval = self.timeInterval |
|
3409 | self.dataOut.timeInterval = self.timeInterval | |
3410 | self.dataOut.channelList = self.channelList |
|
3410 | self.dataOut.channelList = self.channelList | |
3411 | self.dataOut.heightList = self.heightList |
|
3411 | self.dataOut.heightList = self.heightList | |
3412 | self.dataOut.flagNoData = False |
|
3412 | self.dataOut.flagNoData = False | |
3413 |
|
3413 | |||
3414 | return self.dataOut.data |
|
3414 | return self.dataOut.data | |
3415 |
|
3415 | |||
3416 | def run(self, **kwargs): |
|
3416 | def run(self, **kwargs): | |
3417 |
|
3417 | |||
3418 | if not(self.isConfig): |
|
3418 | if not(self.isConfig): | |
3419 | self.setup(**kwargs) |
|
3419 | self.setup(**kwargs) | |
3420 | self.isConfig = True |
|
3420 | self.isConfig = True | |
3421 |
|
3421 | |||
3422 | self.getData() |
|
3422 | self.getData() | |
3423 |
|
3423 | |||
3424 |
|
3424 | |||
3425 | class RadacHeader(): |
|
3425 | class RadacHeader(): | |
3426 | def __init__(self, fp): |
|
3426 | def __init__(self, fp): | |
3427 | header = 'Raw11/Data/RadacHeader' |
|
3427 | header = 'Raw11/Data/RadacHeader' | |
3428 | self.beamCode = fp.get(header+'/BeamCode') |
|
3428 | self.beamCode = fp.get(header+'/BeamCode') | |
3429 | self.code = fp.get(header+'/Code') |
|
3429 | self.code = fp.get(header+'/Code') | |
3430 | self.frameCount = fp.get(header+'/FrameCount') |
|
3430 | self.frameCount = fp.get(header+'/FrameCount') | |
3431 | self.modeGroup = fp.get(header+'/ModeGroup') |
|
3431 | self.modeGroup = fp.get(header+'/ModeGroup') | |
3432 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') |
|
3432 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') | |
3433 | self.pulseCount = fp.get(header+'/PulseCount') |
|
3433 | self.pulseCount = fp.get(header+'/PulseCount') | |
3434 | self.radacTime = fp.get(header+'/RadacTime') |
|
3434 | self.radacTime = fp.get(header+'/RadacTime') | |
3435 | self.timeCount = fp.get(header+'/TimeCount') |
|
3435 | self.timeCount = fp.get(header+'/TimeCount') | |
3436 | self.timeStatus = fp.get(header+'/TimeStatus') |
|
3436 | self.timeStatus = fp.get(header+'/TimeStatus') | |
3437 |
|
3437 | |||
3438 | self.nrecords = self.pulseCount.shape[0] #numero de bloques |
|
3438 | self.nrecords = self.pulseCount.shape[0] #numero de bloques | |
3439 | self.npulses = self.pulseCount.shape[1] #numero de perfiles |
|
3439 | self.npulses = self.pulseCount.shape[1] #numero de perfiles | |
3440 | self.nsamples = self.nsamplesPulse[0,0] #numero de alturas |
|
3440 | self.nsamples = self.nsamplesPulse[0,0] #numero de alturas | |
3441 |
|
3441 | |||
3442 |
|
3442 | |||
3443 | def getIndexRangeToPulse(self, idrecord=0): |
|
3443 | def getIndexRangeToPulse(self, idrecord=0): | |
3444 | indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) |
|
3444 | indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) | |
3445 | startPulseCountId = indexToZero[0][0] |
|
3445 | startPulseCountId = indexToZero[0][0] | |
3446 | endPulseCountId = startPulseCountId - 1 |
|
3446 | endPulseCountId = startPulseCountId - 1 | |
3447 | range1 = numpy.arange(startPulseCountId,self.npulses,1) |
|
3447 | range1 = numpy.arange(startPulseCountId,self.npulses,1) | |
3448 | range2 = numpy.arange(0,startPulseCountId,1) |
|
3448 | range2 = numpy.arange(0,startPulseCountId,1) | |
3449 | return range1, range2 |
|
3449 | return range1, range2 | |
3450 |
|
3450 | |||
3451 |
|
3451 | |||
3452 | class AMISRReader(ProcessingUnit): |
|
3452 | class AMISRReader(ProcessingUnit): | |
3453 |
|
3453 | |||
3454 | path = None |
|
3454 | path = None | |
3455 | startDate = None |
|
3455 | startDate = None | |
3456 | endDate = None |
|
3456 | endDate = None | |
3457 | startTime = None |
|
3457 | startTime = None | |
3458 | endTime = None |
|
3458 | endTime = None | |
3459 | walk = None |
|
3459 | walk = None | |
3460 | isConfig = False |
|
3460 | isConfig = False | |
3461 |
|
3461 | |||
3462 | def __init__(self): |
|
3462 | def __init__(self): | |
3463 | self.set = None |
|
3463 | self.set = None | |
3464 | self.subset = None |
|
3464 | self.subset = None | |
3465 | self.extension_file = '.h5' |
|
3465 | self.extension_file = '.h5' | |
3466 | self.dtc_str = 'dtc' |
|
3466 | self.dtc_str = 'dtc' | |
3467 | self.dtc_id = 0 |
|
3467 | self.dtc_id = 0 | |
3468 | self.status = True |
|
3468 | self.status = True | |
3469 | self.isConfig = False |
|
3469 | self.isConfig = False | |
3470 | self.dirnameList = [] |
|
3470 | self.dirnameList = [] | |
3471 | self.filenameList = [] |
|
3471 | self.filenameList = [] | |
3472 | self.fileIndex = None |
|
3472 | self.fileIndex = None | |
3473 | self.flagNoMoreFiles = False |
|
3473 | self.flagNoMoreFiles = False | |
3474 | self.flagIsNewFile = 0 |
|
3474 | self.flagIsNewFile = 0 | |
3475 | self.filename = '' |
|
3475 | self.filename = '' | |
3476 | self.amisrFilePointer = None |
|
3476 | self.amisrFilePointer = None | |
3477 | self.radacHeaderObj = None |
|
3477 | self.radacHeaderObj = None | |
3478 | self.dataOut = self.__createObjByDefault() |
|
3478 | self.dataOut = self.__createObjByDefault() | |
3479 | self.datablock = None |
|
3479 | self.datablock = None | |
3480 | self.rest_datablock = None |
|
3480 | self.rest_datablock = None | |
3481 | self.range = None |
|
3481 | self.range = None | |
3482 | self.idrecord_count = 0 |
|
3482 | self.idrecord_count = 0 | |
3483 | self.profileIndex = 0 |
|
3483 | self.profileIndex = 0 | |
3484 | self.idpulse_range1 = None |
|
3484 | self.idpulse_range1 = None | |
3485 | self.idpulse_range2 = None |
|
3485 | self.idpulse_range2 = None | |
3486 | self.beamCodeByFrame = None |
|
3486 | self.beamCodeByFrame = None | |
3487 | self.radacTimeByFrame = None |
|
3487 | self.radacTimeByFrame = None | |
3488 | #atributos originales tal y como esta en el archivo de datos |
|
3488 | #atributos originales tal y como esta en el archivo de datos | |
3489 | self.beamCodesFromFile = None |
|
3489 | self.beamCodesFromFile = None | |
3490 | self.radacTimeFromFile = None |
|
3490 | self.radacTimeFromFile = None | |
3491 | self.rangeFromFile = None |
|
3491 | self.rangeFromFile = None | |
3492 | self.dataByFrame = None |
|
3492 | self.dataByFrame = None | |
3493 | self.dataset = None |
|
3493 | self.dataset = None | |
3494 |
|
3494 | |||
3495 |
|
3495 | |||
3496 | def __createObjByDefault(self): |
|
3496 | def __createObjByDefault(self): | |
3497 |
|
3497 | |||
3498 | dataObj = AMISR() |
|
3498 | dataObj = AMISR() | |
3499 |
|
3499 | |||
3500 | return dataObj |
|
3500 | return dataObj | |
3501 |
|
3501 | |||
3502 | def __setParameters(self,path,startDate,endDate,startTime,endTime,walk): |
|
3502 | def __setParameters(self,path,startDate,endDate,startTime,endTime,walk): | |
3503 | self.path = path |
|
3503 | self.path = path | |
3504 | self.startDate = startDate |
|
3504 | self.startDate = startDate | |
3505 | self.endDate = endDate |
|
3505 | self.endDate = endDate | |
3506 | self.startTime = startTime |
|
3506 | self.startTime = startTime | |
3507 | self.endTime = endTime |
|
3507 | self.endTime = endTime | |
3508 | self.walk = walk |
|
3508 | self.walk = walk | |
3509 |
|
3509 | |||
3510 | def __checkPath(self): |
|
3510 | def __checkPath(self): | |
3511 | if os.path.exists(self.path): |
|
3511 | if os.path.exists(self.path): | |
3512 | self.status = 1 |
|
3512 | self.status = 1 | |
3513 | else: |
|
3513 | else: | |
3514 | self.status = 0 |
|
3514 | self.status = 0 | |
3515 | print 'Path:%s does not exists'%self.path |
|
3515 | print 'Path:%s does not exists'%self.path | |
3516 |
|
3516 | |||
3517 | return |
|
3517 | return | |
3518 |
|
3518 | |||
3519 | def __selDates(self, amisr_dirname_format): |
|
3519 | def __selDates(self, amisr_dirname_format): | |
3520 | year = int(amisr_dirname_format[0:4]) |
|
3520 | year = int(amisr_dirname_format[0:4]) | |
3521 | month = int(amisr_dirname_format[4:6]) |
|
3521 | month = int(amisr_dirname_format[4:6]) | |
3522 | dom = int(amisr_dirname_format[6:8]) |
|
3522 | dom = int(amisr_dirname_format[6:8]) | |
3523 | thisDate = datetime.date(year,month,dom) |
|
3523 | thisDate = datetime.date(year,month,dom) | |
3524 |
|
3524 | |||
3525 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
3525 | if (thisDate>=self.startDate and thisDate <= self.endDate): | |
3526 | return amisr_dirname_format |
|
3526 | return amisr_dirname_format | |
3527 |
|
3527 | |||
3528 | def __findDataForDates(self): |
|
3528 | def __findDataForDates(self): | |
3529 |
|
3529 | |||
3530 | import re |
|
3530 | import re | |
3531 |
|
3531 | |||
3532 | if not(self.status): |
|
3532 | if not(self.status): | |
3533 | return None |
|
3533 | return None | |
3534 |
|
3534 | |||
3535 | pat = '\d+.\d+' |
|
3535 | pat = '\d+.\d+' | |
3536 | dirnameList = [re.search(pat,x).string for x in os.listdir(self.path)] |
|
3536 | dirnameList = [re.search(pat,x).string for x in os.listdir(self.path)] | |
3537 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
3537 | dirnameList = [self.__selDates(x) for x in dirnameList] | |
3538 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
3538 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
3539 | if len(dirnameList)>0: |
|
3539 | if len(dirnameList)>0: | |
3540 | self.status = 1 |
|
3540 | self.status = 1 | |
3541 | self.dirnameList = dirnameList |
|
3541 | self.dirnameList = dirnameList | |
3542 | self.dirnameList.sort() |
|
3542 | self.dirnameList.sort() | |
3543 | else: |
|
3543 | else: | |
3544 | self.status = 0 |
|
3544 | self.status = 0 | |
3545 | return None |
|
3545 | return None | |
3546 |
|
3546 | |||
3547 | def __getTimeFromData(self): |
|
3547 | def __getTimeFromData(self): | |
3548 | pass |
|
3548 | pass | |
3549 |
|
3549 | |||
3550 | def __filterByGlob1(self, dirName): |
|
3550 | def __filterByGlob1(self, dirName): | |
3551 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) |
|
3551 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) | |
3552 | filterDict = {} |
|
3552 | filterDict = {} | |
3553 | filterDict.setdefault(dirName) |
|
3553 | filterDict.setdefault(dirName) | |
3554 | filterDict[dirName] = filter_files |
|
3554 | filterDict[dirName] = filter_files | |
3555 | return filterDict |
|
3555 | return filterDict | |
3556 |
|
3556 | |||
3557 | def __getFilenameList(self, fileListInKeys, dirList): |
|
3557 | def __getFilenameList(self, fileListInKeys, dirList): | |
3558 | for value in fileListInKeys: |
|
3558 | for value in fileListInKeys: | |
3559 | dirName = value.keys()[0] |
|
3559 | dirName = value.keys()[0] | |
3560 | for file in value[dirName]: |
|
3560 | for file in value[dirName]: | |
3561 | filename = os.path.join(dirName, file) |
|
3561 | filename = os.path.join(dirName, file) | |
3562 | self.filenameList.append(filename) |
|
3562 | self.filenameList.append(filename) | |
3563 |
|
3563 | |||
3564 |
|
3564 | |||
3565 | def __selectDataForTimes(self): |
|
3565 | def __selectDataForTimes(self): | |
3566 | #aun no esta implementado el filtro for tiempo |
|
3566 | #aun no esta implementado el filtro for tiempo | |
3567 | if not(self.status): |
|
3567 | if not(self.status): | |
3568 | return None |
|
3568 | return None | |
3569 |
|
3569 | |||
3570 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
3570 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] | |
3571 |
|
3571 | |||
3572 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] |
|
3572 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] | |
3573 |
|
3573 | |||
3574 | self.__getFilenameList(fileListInKeys, dirList) |
|
3574 | self.__getFilenameList(fileListInKeys, dirList) | |
3575 |
|
3575 | |||
3576 | if len(self.filenameList)>0: |
|
3576 | if len(self.filenameList)>0: | |
3577 | self.status = 1 |
|
3577 | self.status = 1 | |
3578 | self.filenameList.sort() |
|
3578 | self.filenameList.sort() | |
3579 | else: |
|
3579 | else: | |
3580 | self.status = 0 |
|
3580 | self.status = 0 | |
3581 | return None |
|
3581 | return None | |
3582 |
|
3582 | |||
3583 |
|
3583 | |||
3584 | def __searchFilesOffline(self, |
|
3584 | def __searchFilesOffline(self, | |
3585 | path, |
|
3585 | path, | |
3586 | startDate, |
|
3586 | startDate, | |
3587 | endDate, |
|
3587 | endDate, | |
3588 | startTime=datetime.time(0,0,0), |
|
3588 | startTime=datetime.time(0,0,0), | |
3589 | endTime=datetime.time(23,59,59), |
|
3589 | endTime=datetime.time(23,59,59), | |
3590 | walk=True): |
|
3590 | walk=True): | |
3591 |
|
3591 | |||
3592 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
3592 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) | |
3593 |
|
3593 | |||
3594 | self.__checkPath() |
|
3594 | self.__checkPath() | |
3595 |
|
3595 | |||
3596 | self.__findDataForDates() |
|
3596 | self.__findDataForDates() | |
3597 |
|
3597 | |||
3598 | self.__selectDataForTimes() |
|
3598 | self.__selectDataForTimes() | |
3599 |
|
3599 | |||
3600 | for i in range(len(self.filenameList)): |
|
3600 | for i in range(len(self.filenameList)): | |
3601 | print "%s" %(self.filenameList[i]) |
|
3601 | print "%s" %(self.filenameList[i]) | |
3602 |
|
3602 | |||
3603 | return |
|
3603 | return | |
3604 |
|
3604 | |||
3605 | def __setNextFileOffline(self): |
|
3605 | def __setNextFileOffline(self): | |
3606 | idFile = self.fileIndex |
|
3606 | idFile = self.fileIndex | |
3607 |
|
3607 | |||
3608 | while (True): |
|
3608 | while (True): | |
3609 | idFile += 1 |
|
3609 | idFile += 1 | |
3610 | if not(idFile < len(self.filenameList)): |
|
3610 | if not(idFile < len(self.filenameList)): | |
3611 | self.flagNoMoreFiles = 1 |
|
3611 | self.flagNoMoreFiles = 1 | |
3612 | print "No more Files" |
|
3612 | print "No more Files" | |
3613 | return 0 |
|
3613 | return 0 | |
3614 |
|
3614 | |||
3615 | filename = self.filenameList[idFile] |
|
3615 | filename = self.filenameList[idFile] | |
3616 |
|
3616 | |||
3617 | amisrFilePointer = h5py.File(filename,'r') |
|
3617 | amisrFilePointer = h5py.File(filename,'r') | |
3618 |
|
3618 | |||
3619 | break |
|
3619 | break | |
3620 |
|
3620 | |||
3621 | self.flagIsNewFile = 1 |
|
3621 | self.flagIsNewFile = 1 | |
3622 | self.fileIndex = idFile |
|
3622 | self.fileIndex = idFile | |
3623 | self.filename = filename |
|
3623 | self.filename = filename | |
3624 |
|
3624 | |||
3625 | self.amisrFilePointer = amisrFilePointer |
|
3625 | self.amisrFilePointer = amisrFilePointer | |
3626 |
|
3626 | |||
3627 | print "Setting the file: %s"%self.filename |
|
3627 | print "Setting the file: %s"%self.filename | |
3628 |
|
3628 | |||
3629 | return 1 |
|
3629 | return 1 | |
3630 |
|
3630 | |||
3631 | def __readHeader(self): |
|
3631 | def __readHeader(self): | |
3632 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) |
|
3632 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) | |
3633 | self.flagIsNewFile = 1 |
|
3633 | self.flagIsNewFile = 1 | |
3634 |
|
3634 | |||
3635 |
|
3635 | |||
3636 |
|
3636 | |||
3637 | def __setNextFile(self): |
|
3637 | def __setNextFile(self): | |
3638 |
|
3638 | |||
3639 | newFile = self.__setNextFileOffline() |
|
3639 | newFile = self.__setNextFileOffline() | |
3640 |
|
3640 | |||
3641 | if not(newFile): |
|
3641 | if not(newFile): | |
3642 | return 0 |
|
3642 | return 0 | |
3643 |
|
3643 | |||
3644 | self.__readHeader() |
|
3644 | self.__readHeader() | |
3645 |
|
3645 | |||
3646 | self.readDataBlock() |
|
3646 | self.readDataBlock() | |
3647 |
|
3647 | |||
3648 |
|
3648 | |||
3649 | def setup(self,path=None, |
|
3649 | def setup(self,path=None, | |
3650 | startDate=None, |
|
3650 | startDate=None, | |
3651 | endDate=None, |
|
3651 | endDate=None, | |
3652 | startTime=datetime.time(0,0,0), |
|
3652 | startTime=datetime.time(0,0,0), | |
3653 | endTime=datetime.time(23,59,59), |
|
3653 | endTime=datetime.time(23,59,59), | |
3654 | walk=True): |
|
3654 | walk=True): | |
3655 |
|
3655 | |||
3656 | #Busqueda de archivos offline |
|
3656 | #Busqueda de archivos offline | |
3657 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) |
|
3657 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) | |
3658 |
|
3658 | |||
3659 | if not(self.filenameList): |
|
3659 | if not(self.filenameList): | |
3660 | print "There is no files into the folder: %s"%(path) |
|
3660 | print "There is no files into the folder: %s"%(path) | |
3661 |
|
3661 | |||
3662 | sys.exit(-1) |
|
3662 | sys.exit(-1) | |
3663 |
|
3663 | |||
3664 | self.fileIndex = -1 |
|
3664 | self.fileIndex = -1 | |
3665 |
|
3665 | |||
3666 | self.__setNextFile() |
|
3666 | self.__setNextFile() | |
3667 |
|
3667 | |||
3668 | def readRanges(self): |
|
3668 | def readRanges(self): | |
3669 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') |
|
3669 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') | |
3670 |
self.rangeFromFile = dataset.value |
|
3670 | #self.rangeFromFile = dataset.value | |
|
3671 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) | |||
3671 | return range |
|
3672 | return range | |
3672 |
|
3673 | |||
3673 |
|
3674 | |||
3674 | def readRadacTime(self,idrecord, range1, range2): |
|
3675 | def readRadacTime(self,idrecord, range1, range2): | |
3675 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value |
|
3676 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value | |
3676 |
|
3677 | |||
3677 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
3678 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) | |
3678 | #radacTimeByFrame = dataset[idrecord - 1,range1] |
|
3679 | #radacTimeByFrame = dataset[idrecord - 1,range1] | |
3679 | #radacTimeByFrame = dataset[idrecord,range2] |
|
3680 | #radacTimeByFrame = dataset[idrecord,range2] | |
3680 |
|
3681 | |||
3681 | return radacTimeByFrame |
|
3682 | return radacTimeByFrame | |
3682 |
|
3683 | |||
3683 | def readBeamCode(self, idrecord, range1, range2): |
|
3684 | def readBeamCode(self, idrecord, range1, range2): | |
3684 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') |
|
3685 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') | |
3685 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
3686 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) | |
3686 | self.beamCodesFromFile = dataset.value |
|
3687 | self.beamCodesFromFile = dataset.value | |
3687 |
|
3688 | |||
3688 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] |
|
3689 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] | |
3689 | #beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
3690 | #beamcodeByFrame[range2] = dataset[idrecord, range2] | |
3690 | beamcodeByFrame[range1] = dataset[idrecord, range1] |
|
3691 | beamcodeByFrame[range1] = dataset[idrecord, range1] | |
3691 | beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
3692 | beamcodeByFrame[range2] = dataset[idrecord, range2] | |
3692 |
|
3693 | |||
3693 | return beamcodeByFrame |
|
3694 | return beamcodeByFrame | |
3694 |
|
3695 | |||
3695 |
|
3696 | |||
3696 | def __setDataByFrame(self): |
|
3697 | def __setDataByFrame(self): | |
3697 | ndata = 2 # porque es complejo |
|
3698 | ndata = 2 # porque es complejo | |
3698 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) |
|
3699 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) | |
3699 | return dataByFrame |
|
3700 | return dataByFrame | |
3700 |
|
3701 | |||
3701 | def __readDataSet(self): |
|
3702 | def __readDataSet(self): | |
3702 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') |
|
3703 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') | |
3703 | return dataset |
|
3704 | return dataset | |
3704 |
|
3705 | |||
3705 | def __setDataBlock(self,): |
|
3706 | def __setDataBlock(self,): | |
3706 | real = self.dataByFrame[:,:,0] #asumo que 0 es real |
|
3707 | real = self.dataByFrame[:,:,0] #asumo que 0 es real | |
3707 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario |
|
3708 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario | |
3708 | datablock = real + imag*1j #armo el complejo |
|
3709 | datablock = real + imag*1j #armo el complejo | |
3709 | return datablock |
|
3710 | return datablock | |
3710 |
|
3711 | |||
3711 | def readSamples_version1(self,idrecord): |
|
3712 | def readSamples_version1(self,idrecord): | |
3712 | #estas tres primeras lineas solo se deben ejecutar una vez |
|
3713 | #estas tres primeras lineas solo se deben ejecutar una vez | |
3713 | if self.flagIsNewFile: |
|
3714 | if self.flagIsNewFile: | |
3714 | self.idpulse_range1, self.idpulse_range2 = self.radacHeaderObj.getIndexRangeToPulse(0) |
|
3715 | self.idpulse_range1, self.idpulse_range2 = self.radacHeaderObj.getIndexRangeToPulse(0) | |
3715 | self.dataByFrame = self.__setDataByFrame() |
|
3716 | self.dataByFrame = self.__setDataByFrame() | |
3716 | self.beamCodeByFrame = self.readBeamCode(idrecord, self.idpulse_range1, self.idpulse_range2) |
|
3717 | self.beamCodeByFrame = self.readBeamCode(idrecord, self.idpulse_range1, self.idpulse_range2) | |
3717 | self.radacTimeByFrame = self.readRadacTime(idrecord, self.idpulse_range1, self.idpulse_range2) |
|
3718 | self.radacTimeByFrame = self.readRadacTime(idrecord, self.idpulse_range1, self.idpulse_range2) | |
3718 | #reading dataset |
|
3719 | #reading dataset | |
3719 | self.dataset = self.__readDataSet() |
|
3720 | self.dataset = self.__readDataSet() | |
3720 |
|
3721 | |||
3721 | if idrecord == 0: |
|
3722 | if idrecord == 0: | |
3722 |
|
3723 | |||
3723 | if len(numpy.where(self.dataByFrame!=0.0)[0]) or len(numpy.where(self.dataByFrame!=0.0)[1]) or len(numpy.where(self.dataByFrame!=0.0)[2]): |
|
3724 | if len(numpy.where(self.dataByFrame!=0.0)[0]) or len(numpy.where(self.dataByFrame!=0.0)[1]) or len(numpy.where(self.dataByFrame!=0.0)[2]): | |
3724 | #falta agregar una condicion para datos discontinuos |
|
3725 | #falta agregar una condicion para datos discontinuos | |
3725 | #por defecto une los datos del record anterior |
|
3726 | #por defecto une los datos del record anterior | |
3726 | self.dataByFrame[self.idpulse_range2, :, :] = self.dataset[idrecord, self.idpulse_range2, :, :] |
|
3727 | self.dataByFrame[self.idpulse_range2, :, :] = self.dataset[idrecord, self.idpulse_range2, :, :] | |
3727 | #timepulse |
|
3728 | #timepulse | |
3728 | self.radacTimeByFrame[self.idpulse_range2] = self.radacHeaderObj.radacTime[idrecord, self.idpulse_range2] |
|
3729 | self.radacTimeByFrame[self.idpulse_range2] = self.radacHeaderObj.radacTime[idrecord, self.idpulse_range2] | |
3729 | else: |
|
3730 | else: | |
3730 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord, self.idpulse_range1, :, :] |
|
3731 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord, self.idpulse_range1, :, :] | |
3731 |
|
3732 | |||
3732 | self.radacTimeByFrame[self.idpulse_range1] = self.radacHeaderObj.radacTime[idrecord, self.idpulse_range1] |
|
3733 | self.radacTimeByFrame[self.idpulse_range1] = self.radacHeaderObj.radacTime[idrecord, self.idpulse_range1] | |
3733 |
|
3734 | |||
3734 | datablock = self.__setDataBlock() |
|
3735 | datablock = self.__setDataBlock() | |
3735 |
|
3736 | |||
3736 | return datablock |
|
3737 | return datablock | |
3737 |
|
3738 | |||
3738 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord - 1,self.idpulse_range1, :, :] |
|
3739 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord - 1,self.idpulse_range1, :, :] | |
3739 | self.dataByFrame[self.idpulse_range2, :, :] = self.dataset[idrecord, self.idpulse_range2, :, :] |
|
3740 | self.dataByFrame[self.idpulse_range2, :, :] = self.dataset[idrecord, self.idpulse_range2, :, :] | |
3740 | datablock = self.__setDataBlock() |
|
3741 | datablock = self.__setDataBlock() | |
3741 | self.flagIsNewFile = 0 |
|
3742 | self.flagIsNewFile = 0 | |
3742 |
|
3743 | |||
3743 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord, self.idpulse_range1, :, :] |
|
3744 | self.dataByFrame[self.idpulse_range1, :, :] = self.dataset[idrecord, self.idpulse_range1, :, :] | |
3744 |
|
3745 | |||
3745 |
|
3746 | |||
3746 | return datablock |
|
3747 | return datablock | |
3747 |
|
3748 | |||
3748 |
|
3749 | |||
3749 | def readSamples(self,idrecord): |
|
3750 | def readSamples(self,idrecord): | |
3750 | if self.flagIsNewFile: |
|
3751 | if self.flagIsNewFile: | |
3751 | self.dataByFrame = self.__setDataByFrame() |
|
3752 | self.dataByFrame = self.__setDataByFrame() | |
3752 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] |
|
3753 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] | |
3753 |
|
3754 | |||
|
3755 | #reading ranges | |||
|
3756 | self.readRanges() | |||
3754 | #reading dataset |
|
3757 | #reading dataset | |
3755 | self.dataset = self.__readDataSet() |
|
3758 | self.dataset = self.__readDataSet() | |
3756 |
|
3759 | |||
3757 | self.flagIsNewFile = 0 |
|
3760 | self.flagIsNewFile = 0 | |
3758 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] |
|
3761 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] | |
3759 | self.dataByFrame = self.dataset[idrecord, :, :, :] |
|
3762 | self.dataByFrame = self.dataset[idrecord, :, :, :] | |
3760 | datablock = self.__setDataBlock() |
|
3763 | datablock = self.__setDataBlock() | |
3761 | return datablock |
|
3764 | return datablock | |
3762 |
|
3765 | |||
3763 |
|
3766 | |||
3764 | def readDataBlock(self): |
|
3767 | def readDataBlock(self): | |
3765 |
|
3768 | |||
3766 | #self.datablock = self.readSamples(self.idrecord_count) |
|
3769 | #self.datablock = self.readSamples(self.idrecord_count) | |
3767 | self.datablock = self.readSamples(self.idrecord_count) |
|
3770 | self.datablock = self.readSamples(self.idrecord_count) | |
3768 | #print 'record:', self.idrecord_count |
|
3771 | #print 'record:', self.idrecord_count | |
3769 |
|
3772 | |||
3770 | self.idrecord_count += 1 |
|
3773 | self.idrecord_count += 1 | |
3771 | self.profileIndex = 0 |
|
3774 | self.profileIndex = 0 | |
3772 |
|
3775 | |||
3773 | if self.idrecord_count >= self.radacHeaderObj.nrecords: |
|
3776 | if self.idrecord_count >= self.radacHeaderObj.nrecords: | |
3774 | self.idrecord_count = 0 |
|
3777 | self.idrecord_count = 0 | |
3775 | self.flagIsNewFile = 1 |
|
3778 | self.flagIsNewFile = 1 | |
3776 |
|
3779 | |||
3777 | def readNextBlock(self): |
|
3780 | def readNextBlock(self): | |
3778 |
|
3781 | |||
3779 | self.readDataBlock() |
|
3782 | self.readDataBlock() | |
3780 |
|
3783 | |||
3781 | if self.flagIsNewFile: |
|
3784 | if self.flagIsNewFile: | |
3782 | self.__setNextFile() |
|
3785 | self.__setNextFile() | |
3783 | pass |
|
3786 | pass | |
3784 |
|
3787 | |||
3785 | def __hasNotDataInBuffer(self): |
|
3788 | def __hasNotDataInBuffer(self): | |
3786 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record |
|
3789 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record | |
3787 | if self.profileIndex >= self.radacHeaderObj.npulses: |
|
3790 | if self.profileIndex >= self.radacHeaderObj.npulses: | |
3788 | return 1 |
|
3791 | return 1 | |
3789 | return 0 |
|
3792 | return 0 | |
3790 |
|
3793 | |||
|
3794 | def setObjProperties(self): | |||
|
3795 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km | |||
|
3796 | self.dataOut.nProfiles = self.radacHeaderObj.npulses | |||
|
3797 | self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |||
|
3798 | self.dataOut.nBaud = None | |||
|
3799 | self.dataOut.nCode = None | |||
|
3800 | self.dataOut.code = None | |||
3791 |
|
3801 | |||
3792 | def getData(self): |
|
3802 | def getData(self): | |
3793 |
|
3803 | |||
3794 | if self.flagNoMoreFiles: |
|
3804 | if self.flagNoMoreFiles: | |
3795 | self.dataOut.flagNoData = True |
|
3805 | self.dataOut.flagNoData = True | |
3796 | print 'Process finished' |
|
3806 | print 'Process finished' | |
3797 | return 0 |
|
3807 | return 0 | |
3798 |
|
3808 | |||
3799 | if self.__hasNotDataInBuffer(): |
|
3809 | if self.__hasNotDataInBuffer(): | |
3800 | self.readNextBlock() |
|
3810 | self.readNextBlock() | |
3801 | # if not( self.readNextBlock() ): |
|
3811 | # if not( self.readNextBlock() ): | |
3802 | # return 0 |
|
3812 | # return 0 | |
3803 | # self.getFirstHeader() |
|
3813 | # self.getFirstHeader() | |
3804 |
|
3814 | |||
3805 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
3815 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers | |
3806 | self.dataOut.flagNoData = True |
|
3816 | self.dataOut.flagNoData = True | |
3807 | return 0 |
|
3817 | return 0 | |
3808 |
|
3818 | |||
3809 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) |
|
3819 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) | |
3810 |
|
3820 | |||
3811 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] |
|
3821 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] | |
3812 |
|
3822 | |||
3813 | self.dataOut.flagNoData = False |
|
3823 | self.dataOut.flagNoData = False | |
3814 |
|
3824 | |||
3815 | self.profileIndex += 1 |
|
3825 | self.profileIndex += 1 | |
3816 |
|
3826 | |||
3817 | return self.dataOut.data |
|
3827 | return self.dataOut.data | |
3818 |
|
3828 | |||
3819 |
|
3829 | |||
3820 | def run(self, **kwargs): |
|
3830 | def run(self, **kwargs): | |
3821 | if not(self.isConfig): |
|
3831 | if not(self.isConfig): | |
3822 | self.setup(**kwargs) |
|
3832 | self.setup(**kwargs) | |
|
3833 | self.setObjProperties() | |||
3823 | self.isConfig = True |
|
3834 | self.isConfig = True | |
3824 |
|
3835 | |||
3825 | self.getData() |
|
3836 | self.getData() |
@@ -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