@@ -598,13 +598,22 if __name__ == '__main__': | |||
|
598 | 598 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
599 | 599 | |
|
600 | 600 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
601 |
opObj10.addParameter(name='channelList', value='0,1 |
|
|
601 | opObj10.addParameter(name='channelList', value='0,1', format='intlist') | |
|
602 | 602 | |
|
603 | 603 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
604 | 604 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
605 | 605 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') |
|
606 | opObj11.addParameter(name='zmin', value='60', format='int') | |
|
607 | opObj11.addParameter(name='zmax', value='100', format='int') | |
|
606 | # opObj11.addParameter(name='zmin', value='60', format='int') | |
|
607 | # opObj11.addParameter(name='zmax', value='100', format='int') | |
|
608 | ||
|
609 | opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
610 | opObj12.addParameter(name='n', value='30', format='int') | |
|
611 | ||
|
612 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
|
613 | opObj11.addParameter(name='idfigure', value='2', format='int') | |
|
614 | opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') | |
|
615 | # opObj11.addParameter(name='zmin', value='60', format='int') | |
|
616 | # opObj11.addParameter(name='zmax', value='100', format='int') | |
|
608 | 617 | |
|
609 | 618 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
610 | 619 | # opObj12.addParameter(name='ncode', value='2', format='int') |
@@ -1,84 +1,231 | |||
|
1 | import numpy | |
|
1 | 2 | import mpldriver |
|
2 | 3 | |
|
4 | ||
|
3 | 5 | class Figure: |
|
4 | axesList = None | |
|
6 | ||
|
7 | __driver = mpldriver | |
|
8 | ||
|
9 | idfigure = None | |
|
10 | wintitle = None | |
|
5 | 11 | width = None |
|
6 | 12 | height = None |
|
7 | def __init__(self): | |
|
8 | pass | |
|
13 | nplots = None | |
|
14 | ||
|
15 | axesObjList = [] | |
|
16 | ||
|
17 | WIDTH = None | |
|
18 | HEIGHT = None | |
|
19 | ||
|
20 | def __init__(self): | |
|
21 | ||
|
22 | raise ValueError, "This method is not implemented" | |
|
23 | ||
|
24 | def getAxesObjList(self): | |
|
25 | ||
|
26 | return self.axesObjList | |
|
27 | ||
|
28 | def getSubplots(self): | |
|
29 | ||
|
30 | raise ValueError, "Abstract method: This method should be defined" | |
|
31 | ||
|
32 | def getScreenDim(self): | |
|
33 | ||
|
34 | nrow, ncol = self.getSubplots() | |
|
35 | ||
|
36 | width = self.WIDTH*ncol | |
|
37 | height = self.HEIGHT*nrow | |
|
38 | ||
|
39 | return width, height | |
|
40 | ||
|
41 | def init(self, idfigure, nplots, wintitle): | |
|
42 | ||
|
43 | """ | |
|
44 | Inicializa la figura de acuerdo al driver seleccionado | |
|
45 | Input: | |
|
46 | *args : Los parametros necesarios son | |
|
47 | idfigure, wintitle, width, height | |
|
48 | """ | |
|
9 | 49 | |
|
10 | def init(self, idfigure, wintitle, width, height, nplots): | |
|
11 | 50 | self.idfigure = idfigure |
|
12 | self.wintitle = wintitle | |
|
13 | self.width = width | |
|
14 | self.height = height | |
|
51 | ||
|
15 | 52 | self.nplots = nplots |
|
16 | self.fig = mpldriver.init(idfigure, wintitle, width, height) | |
|
17 | 53 | |
|
18 | self.axesList = [] | |
|
54 | self.wintitle = wintitle | |
|
55 | ||
|
56 | self.width, self.height = self.getScreenDim() | |
|
57 | ||
|
58 | self.fig = self.__driver.createFigure(self.idfigure, | |
|
59 | self.wintitle, | |
|
60 | self.width, | |
|
61 | self.height) | |
|
62 | ||
|
63 | self.axesObjList = [] | |
|
19 | 64 | |
|
65 | def setDriver(self, driver=mpldriver): | |
|
66 | ||
|
67 | self.__driver = driver | |
|
68 | ||
|
20 | 69 | def setTitle(self, title): |
|
21 | mpldriver.setTitle(self.idfigure, title) | |
|
70 | ||
|
71 | self.__driver.setTitle(self.fig, title) | |
|
22 | 72 | |
|
23 | def setWinTitle(self,title): | |
|
24 | mpldriver.setWinTitle(fig=self.fig, title=title) | |
|
73 | def setWinTitle(self, title): | |
|
74 | ||
|
75 | self.__driver.setWinTitle(self.fig, title=title) | |
|
25 | 76 | |
|
26 |
def setTextFromAxes(self, t |
|
|
27 | mpldriver.setTextFromAxes(self.idfigure, self.axesList[0].ax, title) | |
|
77 | def setTextFromAxes(self, text): | |
|
78 | ||
|
79 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |
|
28 | 80 | |
|
29 | 81 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
30 | ax = mpldriver.makeAxes(self.idfigure, nrow, ncol, xpos, ypos, colspan, rowspan) | |
|
31 | axesObj = Axes(ax) | |
|
32 | self.axesList.append(axesObj) | |
|
82 | ||
|
83 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
|
84 | ||
|
85 | def addAxes(self, *args): | |
|
86 | """ | |
|
87 | ||
|
88 | Input: | |
|
89 | *args : Los parametros necesarios son | |
|
90 | nrow, ncol, xpos, ypos, colspan, rowspan | |
|
91 | """ | |
|
92 | ||
|
93 | axesObj = Axes(self.fig, *args) | |
|
94 | self.axesObjList.append(axesObj) | |
|
33 | 95 | |
|
34 | 96 | def draw(self): |
|
35 | mpldriver.draw(self.idfigure) | |
|
97 | ||
|
98 | self.__driver.draw(self.fig) | |
|
36 | 99 | |
|
37 | 100 | def run(self): |
|
38 |
|
|
|
101 | ||
|
102 | raise ValueError, "This method is not implemented" | |
|
103 | ||
|
104 | axesList = property(getAxesObjList) | |
|
39 | 105 | |
|
40 | 106 | |
|
41 | 107 | class Axes: |
|
42 | firsttime = None | |
|
108 | ||
|
109 | __driver = mpldriver | |
|
110 | fig = None | |
|
43 | 111 | ax = None |
|
44 |
|
|
|
112 | plot = None | |
|
45 | 113 | |
|
46 | def __init__(self, ax): | |
|
47 | self.firsttime = True | |
|
114 | firsttime = None | |
|
115 | ||
|
116 | def __init__(self, *args): | |
|
117 | ||
|
118 | """ | |
|
119 | ||
|
120 | Input: | |
|
121 | *args : Los parametros necesarios son | |
|
122 | fig, nrow, ncol, xpos, ypos, colspan, rowspan | |
|
123 | """ | |
|
124 | ||
|
125 | ax = self.__driver.createAxes(*args) | |
|
126 | self.fig = args[0] | |
|
48 | 127 | self.ax = ax |
|
49 |
self. |
|
|
50 | ||
|
51 | def pline(self, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title): | |
|
52 | ||
|
53 | mpldriver.pline(ax=self.ax, | |
|
54 | x=x, | |
|
55 | y=y, | |
|
56 | xmin=xmin, | |
|
57 | xmax=xmax, | |
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 | title=title, | |
|
63 | firsttime=self.firsttime) | |
|
64 |
|
|
|
65 | self.firsttime = False | |
|
66 | ||
|
67 | def pcolor(self, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title): | |
|
68 | meshfromaxes=mpldriver.pcolor(ax=self.ax, | |
|
69 | x=x, | |
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 | xmax=xmax, | |
|
74 | ymin=ymin, | |
|
75 | ymax=ymax, | |
|
76 | zmin=zmin, | |
|
77 |
|
|
|
78 |
|
|
|
79 | ylabel=ylabel, | |
|
80 | title=title, | |
|
81 |
|
|
|
82 | mesh=self.mesh) | |
|
83 | self.mesh = meshfromaxes | |
|
84 | self.firsttime = False | |
|
128 | self.plot = None | |
|
129 | ||
|
130 | self.firsttime = True | |
|
131 | ||
|
132 | def setText(self, text): | |
|
133 | ||
|
134 | self.__driver.setAxesText(self.ax, text) | |
|
135 | ||
|
136 | def pline(self, x, y, | |
|
137 | xmin=None, xmax=None, | |
|
138 | ymin=None, ymax=None, | |
|
139 | xlabel='', ylabel='', | |
|
140 | title='', | |
|
141 | **kwargs): | |
|
142 | ||
|
143 | """ | |
|
144 | ||
|
145 | Input: | |
|
146 | x : | |
|
147 | y : | |
|
148 | xmin : | |
|
149 | xmax : | |
|
150 | ymin : | |
|
151 | ymax : | |
|
152 | xlabel : | |
|
153 | ylabel : | |
|
154 | title : | |
|
155 | **kwargs : Los parametros aceptados son | |
|
156 | ||
|
157 | ticksize | |
|
158 | """ | |
|
159 | ||
|
160 | if self.firsttime: | |
|
161 | ||
|
162 | if xmin == None: xmin = numpy.nanmin(x) | |
|
163 | if xmax == None: xmax = numpy.nanmax(x) | |
|
164 | if ymin == None: ymin = numpy.nanmin(y) | |
|
165 | if ymax == None: ymax = numpy.nanmax(y) | |
|
166 | ||
|
167 | self.plot = self.__driver.createPline(self.ax, x, y, | |
|
168 | xmin, xmax, | |
|
169 | ymin, ymax, | |
|
170 | xlabel=xlabel, | |
|
171 | ylabel=ylabel, | |
|
172 | title=title, | |
|
173 | **kwargs) | |
|
174 | self.firsttime = False | |
|
175 | return | |
|
176 | ||
|
177 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, | |
|
178 | ylabel=ylabel, | |
|
179 | title=title) | |
|
180 | ||
|
181 | ||
|
182 | def pcolor(self, x, y, z, | |
|
183 | xmin=None, xmax=None, | |
|
184 | ymin=None, ymax=None, | |
|
185 | zmin=None, zmax=None, | |
|
186 | xlabel='', ylabel='', | |
|
187 | title='', | |
|
188 | **kwargs): | |
|
189 | ||
|
190 | """ | |
|
191 | Input: | |
|
192 | x : | |
|
193 | y : | |
|
194 | x : | |
|
195 | xmin : | |
|
196 | xmax : | |
|
197 | ymin : | |
|
198 | ymax : | |
|
199 | zmin : | |
|
200 | zmax : | |
|
201 | xlabel : | |
|
202 | ylabel : | |
|
203 | title : | |
|
204 | **kwargs : Los parametros aceptados son | |
|
205 | ticksize=9, | |
|
206 | cblabel='' | |
|
207 | """ | |
|
208 | ||
|
209 | if self.firsttime: | |
|
210 | ||
|
211 | if xmin == None: xmin = numpy.nanmin(x) | |
|
212 | if xmax == None: xmax = numpy.nanmax(x) | |
|
213 | if ymin == None: ymin = numpy.nanmin(y) | |
|
214 | if ymax == None: ymax = numpy.nanmax(y) | |
|
215 | if zmin == None: zmin = numpy.nanmin(z) | |
|
216 | if zmax == None: zmax = numpy.nanmax(z) | |
|
217 | ||
|
218 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, | |
|
219 | xmin, xmax, | |
|
220 | ymin, ymax, | |
|
221 | zmin, zmax, | |
|
222 | xlabel=xlabel, | |
|
223 | ylabel=ylabel, | |
|
224 | title=title, | |
|
225 | **kwargs) | |
|
226 | self.firsttime = False | |
|
227 | return | |
|
228 | ||
|
229 | mesh = self.__driver.pcolor(self.plot, z, xlabel=xlabel, | |
|
230 | ylabel=ylabel, | |
|
231 | title=title) |
@@ -1,27 +1,24 | |||
|
1 | import numpy | |
|
1 | 2 | import matplotlib |
|
2 | 3 | matplotlib.use("TKAgg") |
|
3 | 4 | import matplotlib.pyplot |
|
4 | 5 | #import scitools.numpyutils |
|
5 | 6 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
6 | 7 | |
|
7 | def init(idfigure, wintitle, width, height): | |
|
8 | def init(idfigure, wintitle, width, height, facecolor="w"): | |
|
9 | ||
|
8 | 10 | matplotlib.pyplot.ioff() |
|
9 |
fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor= |
|
|
11 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
|
10 | 12 | fig.canvas.manager.set_window_title(wintitle) |
|
11 | fig.canvas.manager.resize(width,height) | |
|
13 | fig.canvas.manager.resize(width, height) | |
|
12 | 14 | matplotlib.pyplot.ion() |
|
15 | ||
|
13 | 16 | return fig |
|
14 | 17 | |
|
15 | 18 | def setWinTitle(fig, title): |
|
19 | ||
|
16 | 20 | fig.canvas.manager.set_window_title(title) |
|
17 | 21 | |
|
18 | def setTextFromAxes(idfigure, ax, title): | |
|
19 | fig = matplotlib.pyplot.figure(idfigure) | |
|
20 | ax.annotate(title, xy=(.1, .99), | |
|
21 | xycoords='figure fraction', | |
|
22 | horizontalalignment='left', verticalalignment='top', | |
|
23 | fontsize=10) | |
|
24 | ||
|
25 | 22 | def setTitle(idfigure, title): |
|
26 | 23 | fig = matplotlib.pyplot.figure(idfigure) |
|
27 | 24 | fig.suptitle(title) |
@@ -31,7 +28,15 def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): | |||
|
31 | 28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) |
|
32 | 29 | return ax |
|
33 | 30 | |
|
31 | def setTextFromAxes(idfigure, ax, title): | |
|
32 | fig = matplotlib.pyplot.figure(idfigure) | |
|
33 | ax.annotate(title, xy=(.1, .99), | |
|
34 | xycoords='figure fraction', | |
|
35 | horizontalalignment='left', verticalalignment='top', | |
|
36 | fontsize=10) | |
|
37 | ||
|
34 | 38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): |
|
39 | ||
|
35 | 40 | if firsttime: |
|
36 | 41 | ax.plot(x, y) |
|
37 | 42 | ax.set_xlim([xmin,xmax]) |
@@ -44,13 +49,15 def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): | |||
|
44 | 49 | ax.lines[0].set_data(x,y) |
|
45 | 50 | |
|
46 | 51 | def draw(idfigure): |
|
52 | ||
|
47 | 53 | fig = matplotlib.pyplot.figure(idfigure) |
|
48 | 54 | fig.canvas.draw() |
|
49 | 55 | |
|
50 | 56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
57 | ||
|
51 | 58 | if firsttime: |
|
52 | 59 | divider = make_axes_locatable(ax) |
|
53 |
ax_cb = divider.new_horizontal(size=" |
|
|
60 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
|
54 | 61 | fig1 = ax.get_figure() |
|
55 | 62 | fig1.add_axes(ax_cb) |
|
56 | 63 | |
@@ -59,7 +66,7 def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, titl | |||
|
59 | 66 | ax.set_xlabel(xlabel) |
|
60 | 67 | ax.set_ylabel(ylabel) |
|
61 | 68 | ax.set_title(title) |
|
62 | ||
|
69 | print x | |
|
63 | 70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
64 | 71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
65 | 72 | ax_cb.yaxis.tick_right() |
@@ -69,18 +76,140 def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, titl | |||
|
69 | 76 | matplotlib.pyplot.tight_layout() |
|
70 | 77 | return imesh |
|
71 | 78 | else: |
|
72 | ax.set_xlim([xmin,xmax]) | |
|
73 | ax.set_ylim([ymin,ymax]) | |
|
79 | # ax.set_xlim([xmin,xmax]) | |
|
80 | # ax.set_ylim([ymin,ymax]) | |
|
74 | 81 | ax.set_xlabel(xlabel) |
|
75 | 82 | ax.set_ylabel(ylabel) |
|
76 | 83 | ax.set_title(title) |
|
77 | 84 | |
|
78 | 85 | z = z.T |
|
79 | z = z[0:-1,0:-1] | |
|
86 | # z = z[0:-1,0:-1] | |
|
80 | 87 | mesh.set_array(z.ravel()) |
|
81 | 88 | |
|
82 | 89 | return mesh |
|
83 | 90 | |
|
91 | ########################################### | |
|
92 | #Actualizacion de las funciones del driver | |
|
93 | ########################################### | |
|
94 | ||
|
95 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): | |
|
96 | ||
|
97 | matplotlib.pyplot.ioff() | |
|
98 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) | |
|
99 | fig.canvas.manager.set_window_title(wintitle) | |
|
100 | fig.canvas.manager.resize(width, height) | |
|
101 | matplotlib.pyplot.ion() | |
|
102 | ||
|
103 | return fig | |
|
104 | ||
|
105 | def setWinTitle(fig, title): | |
|
106 | ||
|
107 | fig.canvas.manager.set_window_title(title) | |
|
108 | ||
|
109 | def setTitle(fig, title): | |
|
110 | ||
|
111 | fig.suptitle(title) | |
|
112 | ||
|
113 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): | |
|
114 | ||
|
115 | matplotlib.pyplot.figure(fig.number) | |
|
116 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), | |
|
117 | (xpos, ypos), | |
|
118 | colspan=colspan, | |
|
119 | rowspan=rowspan) | |
|
120 | return axes | |
|
121 | ||
|
122 | def setAxesText(ax, text): | |
|
123 | ||
|
124 | ax.annotate(text, | |
|
125 | xy = (.1, .99), | |
|
126 | xycoords = 'figure fraction', | |
|
127 | horizontalalignment = 'left', | |
|
128 | verticalalignment = 'top', | |
|
129 | fontsize = 10) | |
|
130 | ||
|
131 | def printLabels(ax, xlabel, ylabel, title): | |
|
132 | ||
|
133 | ax.set_xlabel(xlabel, size=11) | |
|
134 | ax.set_ylabel(ylabel, size=11) | |
|
135 | ax.set_title(title, size=12) | |
|
136 | ||
|
137 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', ticksize = 9): | |
|
138 | ||
|
139 | ax.plot(x, y) | |
|
140 | ax.set_xlim([xmin,xmax]) | |
|
141 | ax.set_ylim([ymin,ymax]) | |
|
142 | ||
|
143 | printLabels(ax, xlabel, ylabel, title) | |
|
144 | ||
|
145 | for tick in ax.yaxis.get_major_ticks(): | |
|
146 | tick.label.set_fontsize(ticksize) | |
|
147 | ||
|
148 | for tick in ax.xaxis.get_major_ticks(): | |
|
149 | tick.label.set_fontsize(ticksize) | |
|
150 | ||
|
151 | matplotlib.pyplot.tight_layout() | |
|
152 | ||
|
153 | iplot = ax.lines[-1] | |
|
154 | ||
|
155 | return iplot | |
|
156 | ||
|
157 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |
|
158 | ||
|
159 | ax = iplot.get_axes() | |
|
160 | ||
|
161 | printLabels(ax, xlabel, ylabel, title) | |
|
162 | ||
|
163 | iplot.set_data(x, y) | |
|
164 | ||
|
165 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', ylabel='', title='', ticksize = 9, cblabel=''): | |
|
166 | ||
|
167 | divider = make_axes_locatable(ax) | |
|
168 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) | |
|
169 | fig = ax.get_figure() | |
|
170 | fig.add_axes(ax_cb) | |
|
171 | ||
|
172 | ax.set_xlim([xmin,xmax]) | |
|
173 | ax.set_ylim([ymin,ymax]) | |
|
174 | ||
|
175 | printLabels(ax, xlabel, ylabel, title) | |
|
176 | ||
|
177 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
|
178 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
|
179 | cb.set_label(cblabel) | |
|
180 | ||
|
181 | ax_cb.yaxis.tick_right() | |
|
182 | ||
|
183 | for tl in ax_cb.get_yticklabels(): | |
|
184 | tl.set_visible(True) | |
|
185 | ||
|
186 | for tick in ax.yaxis.get_major_ticks(): | |
|
187 | tick.label.set_fontsize(ticksize) | |
|
188 | ||
|
189 | for tick in ax.xaxis.get_major_ticks(): | |
|
190 | tick.label.set_fontsize(ticksize) | |
|
191 | ||
|
192 | for tick in cb.ax.get_yticklabels(): | |
|
193 | tick.set_fontsize(ticksize) | |
|
194 | ||
|
195 | ax_cb.yaxis.tick_right() | |
|
196 | matplotlib.pyplot.tight_layout() | |
|
197 | ||
|
198 | return imesh | |
|
84 | 199 | |
|
200 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
|
201 | ||
|
202 | z = z.T | |
|
203 | ||
|
204 | ax = imesh.get_axes() | |
|
205 | ||
|
206 | printLabels(ax, xlabel, ylabel, title) | |
|
207 | ||
|
208 | imesh.set_array(z.ravel()) | |
|
85 | 209 | |
|
86 | No newline at end of file | |
|
210 | def draw(fig): | |
|
211 | ||
|
212 | if type(fig) == 'int': | |
|
213 | raise ValueError, "This parameter should be of tpye matplotlib figure" | |
|
214 | ||
|
215 | fig.canvas.draw() No newline at end of file |
@@ -25,7 +25,7 def hildebrand_sekhon(data, navg): | |||
|
25 | 25 | anoise : noise's level |
|
26 | 26 | """ |
|
27 | 27 | |
|
28 | dataflat = data.reshape(-1) | |
|
28 | dataflat = data.copy().reshape(-1) | |
|
29 | 29 | dataflat.sort() |
|
30 | 30 | npts = dataflat.size #numbers of points of the data |
|
31 | 31 | |
@@ -61,9 +61,12 def hildebrand_sekhon(data, navg): | |||
|
61 | 61 | |
|
62 | 62 | return anoise; |
|
63 | 63 | |
|
64 |
def sorting_bruce( |
|
|
65 | sortdata = numpy.sort(Data) | |
|
66 | lenOfData = len(Data) | |
|
64 | def sorting_bruce(data, navg): | |
|
65 | ||
|
66 | data = data.copy() | |
|
67 | ||
|
68 | sortdata = numpy.sort(data) | |
|
69 | lenOfData = len(data) | |
|
67 | 70 | nums_min = lenOfData/10 |
|
68 | 71 | |
|
69 | 72 | if (lenOfData/10) > 0: |
@@ -155,6 +158,11 class JROData: | |||
|
155 | 158 | nCohInt = None |
|
156 | 159 | |
|
157 | 160 | noise = None |
|
161 | ||
|
162 | #Speed of ligth | |
|
163 | C = 3e8 | |
|
164 | ||
|
165 | frequency = 49.92e6 | |
|
158 | 166 | |
|
159 | 167 | def __init__(self): |
|
160 | 168 | |
@@ -318,11 +326,35 class Spectra(JROData): | |||
|
318 | 326 | |
|
319 | 327 | self.wavelength = None |
|
320 | 328 | |
|
321 |
def getF |
|
|
329 | def getFmax(self): | |
|
330 | ||
|
331 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
|
332 | ||
|
333 | fmax = PRF/2. | |
|
334 | ||
|
335 | return fmax | |
|
336 | ||
|
337 | def getVmax(self): | |
|
338 | ||
|
339 | _lambda = self.C/self.frequency | |
|
340 | ||
|
341 | vmax = self.getFmax() * _lambda / 2. | |
|
342 | ||
|
343 | return vmax | |
|
344 | ||
|
345 | def getFreqRange(self, extrapoints=0): | |
|
346 | ||
|
347 | delfreq = 2 * self.getFmax() / self.nFFTPoints | |
|
348 | freqrange = deltafreqs*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
|
349 | ||
|
350 | return freqrange | |
|
351 | ||
|
352 | def getVelRange(self, extrapoints=0): | |
|
353 | ||
|
354 | deltav = 2 * self.getVmax() / self.nFFTPoints | |
|
355 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |
|
322 | 356 | |
|
323 | xrange = numpy.arange(self.nFFTPoints) | |
|
324 | xrange = xrange | |
|
325 | return None | |
|
357 | return velrange | |
|
326 | 358 | |
|
327 | 359 | def getNoisebyHildebrand(self): |
|
328 | 360 | """ |
@@ -1973,8 +1973,9 class SpectraReader(JRODataReader): | |||
|
1973 | 1973 | |
|
1974 | 1974 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
1975 | 1975 | |
|
1976 |
self.dataOut.n |
|
|
1976 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
|
1977 | 1977 | |
|
1978 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |
|
1978 | 1979 | |
|
1979 | 1980 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1980 | 1981 |
@@ -9,15 +9,15 class SpectraPlot(Figure): | |||
|
9 | 9 | def __init__(self): |
|
10 | 10 | |
|
11 | 11 | self.__isConfig = False |
|
12 |
self. |
|
|
13 |
self. |
|
|
14 | ||
|
12 | self.WIDTH = 300 | |
|
13 | self.HEIGHT = 400 | |
|
14 | ||
|
15 | 15 | def getSubplots(self): |
|
16 | 16 | |
|
17 | 17 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
18 | 18 | nrow = int(self.nplots*1./ncol + 0.9) |
|
19 | 19 | return nrow, ncol |
|
20 | ||
|
20 | ||
|
21 | 21 | def setAxesWithOutProfiles(self, nrow, ncol): |
|
22 | 22 | |
|
23 | 23 | colspan = 1 |
@@ -27,7 +27,7 class SpectraPlot(Figure): | |||
|
27 | 27 | for y in range(nrow): |
|
28 | 28 | for x in range(ncol): |
|
29 | 29 | if counter < self.nplots: |
|
30 |
self. |
|
|
30 | self.addAxes(nrow, ncol, y, x, colspan, rowspan) | |
|
31 | 31 | counter += 1 |
|
32 | 32 | |
|
33 | 33 | def setAxesWithProfiles(self, nrow, ncol): |
@@ -42,150 +42,166 class SpectraPlot(Figure): | |||
|
42 | 42 | for x in range(ncol): |
|
43 | 43 | if counter < self.nplots*factor: |
|
44 | 44 | # plt.subplot2grid((nrow, ncol), (y, x), colspan=colspan, rowspan=rowspan) |
|
45 |
self. |
|
|
45 | self.addAxes(nrow, ncol, y, x, colspan, rowspan) | |
|
46 | 46 | counter += 1 |
|
47 | 47 | |
|
48 |
def setup(self, idfigure, wintitle, |
|
|
48 | def setup(self, idfigure, nplots, wintitle, showprofile=True): | |
|
49 | 49 | |
|
50 |
self.init(idfigure, |
|
|
50 | self.init(idfigure, nplots, wintitle) | |
|
51 | 51 | |
|
52 | nrow,ncol = self.getSubplots() | |
|
52 | nrow, ncol = self.getSubplots() | |
|
53 | 53 | |
|
54 | if profile: | |
|
54 | if showprofile: | |
|
55 | 55 | self.setAxesWithProfiles(nrow, ncol) |
|
56 | 56 | else: |
|
57 | 57 | self.setAxesWithOutProfiles(nrow, ncol) |
|
58 | 58 | |
|
59 |
def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
|
59 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile=False, | |
|
60 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
|
61 | ||
|
62 | """ | |
|
63 | ||
|
64 | Input: | |
|
65 | dataOut : | |
|
66 | idfigure : | |
|
67 | wintitle : | |
|
68 | channelList : | |
|
69 | showProfile : | |
|
70 | xmin : None, | |
|
71 | xmax : None, | |
|
72 | ymin : None, | |
|
73 | ymax : None, | |
|
74 | zmin : None, | |
|
75 | zmax : None | |
|
76 | """ | |
|
60 | 77 | |
|
61 | 78 | if channelList == None: |
|
62 | 79 | channelList = dataOut.channelList |
|
63 | ||
|
64 | nplots = len(channelList) | |
|
65 | ||
|
66 | z = 10.*numpy.log10(dataOut.data_spc[channelList,:,:]) | |
|
67 | 80 | |
|
81 | x = dataOut.getVelRange(1) | |
|
68 | 82 | y = dataOut.heightList |
|
69 | ||
|
70 | x = numpy.arange(dataOut.nFFTPoints) | |
|
83 | z = 10.*numpy.log10(dataOut.data_spc[channelList,:,:]) | |
|
71 | 84 | |
|
72 | 85 | noise = dataOut.getNoise() |
|
73 | 86 | |
|
74 | 87 | if not self.__isConfig: |
|
75 | self.setup(idfigure=idfigure, | |
|
76 | wintitle=wintitle, | |
|
77 | width=self.width, | |
|
78 | height=self.height, | |
|
79 | nplots=nplots, | |
|
80 | profile=profile) | |
|
81 | 88 | |
|
82 | if xmin == None: xmin = numpy.min(x) | |
|
83 | if xmax == None: xmax = numpy.max(x) | |
|
84 | if ymin == None: ymin = numpy.min(y) | |
|
85 | if ymax == None: ymax = numpy.max(y) | |
|
86 | if zmin == None: zmin = numpy.min(z) | |
|
87 | if zmax == None: zmax = numpy.max(z) | |
|
89 | nplots = len(channelList) | |
|
88 | 90 | |
|
89 | self.xmin = xmin | |
|
90 | self.xmax = xmax | |
|
91 | self.ymin = ymin | |
|
92 | self.ymax = ymax | |
|
93 |
|
|
|
94 | self.zmax = zmax | |
|
91 | self.setup(idfigure=idfigure, | |
|
92 | nplots=nplots, | |
|
93 | wintitle=wintitle, | |
|
94 | showprofile=showprofile) | |
|
95 | ||
|
96 | if xmin == None: xmin = numpy.nanmin(x) | |
|
97 | if xmax == None: xmax = numpy.nanmax(x) | |
|
98 | if ymin == None: ymin = numpy.nanmin(y) | |
|
99 | if ymax == None: ymax = numpy.nanmax(y) | |
|
100 | if zmin == None: zmin = numpy.nanmin(z)*0.9 | |
|
101 | if zmax == None: zmax = numpy.nanmax(z)*0.9 | |
|
95 | 102 | |
|
96 | 103 | self.__isConfig = True |
|
97 | ||
|
104 | ||
|
98 | 105 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
99 |
|
|
|
100 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |
|
101 | title = "Spectra: " + dateTime | |
|
106 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
107 | xlabel = "Velocity (m/s)" | |
|
108 | ylabel = "Range (Km)" | |
|
102 | 109 | |
|
103 | 110 | self.setWinTitle(title) |
|
104 | 111 | |
|
105 | ylabel = "Range[Km]" | |
|
106 | ||
|
107 | xlabel = "m/s" | |
|
108 | ||
|
109 | for i in range(len(self.axesList)): | |
|
112 | for i in range(self.nplots): | |
|
110 | 113 | title = "Channel %d: %4.2fdB" %(channelList[i], noise[i]) |
|
114 | zchannel = z[i,:,:] | |
|
115 | ||
|
111 | 116 | axes = self.axesList[i] |
|
112 | z2 = z[i,:,:] | |
|
113 | axes.pcolor(x, y, z2, self.xmin, self.xmax, self.ymin, self.ymax, self.zmin, self.zmax, xlabel, ylabel, title) | |
|
117 | axes.pcolor(x, y, zchannel, | |
|
118 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
119 | xlabel=xlabel, ylabel=ylabel, title=title, | |
|
120 | ticksize=9, cblabel='dB') | |
|
114 | 121 | |
|
115 | 122 | self.draw() |
|
116 | 123 | |
|
117 | 124 | class Scope(Figure): |
|
125 | ||
|
118 | 126 | __isConfig = None |
|
119 | 127 | |
|
120 | 128 | def __init__(self): |
|
129 | ||
|
121 | 130 | self.__isConfig = False |
|
122 |
self. |
|
|
123 |
self. |
|
|
131 | self.WIDTH = 600 | |
|
132 | self.HEIGHT = 200 | |
|
124 | 133 | |
|
125 | 134 | def getSubplots(self): |
|
135 | ||
|
126 | 136 | nrow = self.nplots |
|
127 | 137 | ncol = 3 |
|
128 | 138 | return nrow, ncol |
|
129 | 139 | |
|
130 |
def setup(self, idfigure, |
|
|
131 | self.init(idfigure, wintitle, width, height, nplots) | |
|
140 | def setup(self, idfigure, nplots, wintitle): | |
|
141 | ||
|
142 | self.init(idfigure, nplots, wintitle) | |
|
132 | 143 | |
|
133 | 144 | nrow,ncol = self.getSubplots() |
|
134 | 145 | colspan = 3 |
|
135 | 146 | rowspan = 1 |
|
136 | 147 | |
|
137 | 148 | for i in range(nplots): |
|
138 |
self. |
|
|
139 | ||
|
140 | ||
|
149 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
|
141 | 150 | |
|
142 |
def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
|
143 | ||
|
144 | if dataOut.isEmpty(): | |
|
145 | return None | |
|
151 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
|
152 | xmin=None, xmax=None, ymin=None, ymax=None): | |
|
153 | ||
|
154 | """ | |
|
155 | ||
|
156 | Input: | |
|
157 | dataOut : | |
|
158 | idfigure : | |
|
159 | wintitle : | |
|
160 | channelList : | |
|
161 | xmin : None, | |
|
162 | xmax : None, | |
|
163 | ymin : None, | |
|
164 | ymax : None, | |
|
165 | """ | |
|
146 | 166 | |
|
147 | 167 | if channelList == None: |
|
148 |
|
|
|
149 | ||
|
150 | nplots = len(channelList) | |
|
168 | channelList = dataOut.channelList | |
|
151 | 169 | |
|
170 | x = dataOut.heightList | |
|
152 | 171 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
153 | 172 | y = y.real |
|
154 | 173 | |
|
155 |
|
|
|
174 | noise = dataOut.getNoise() | |
|
156 | 175 | |
|
157 | 176 | if not self.__isConfig: |
|
158 | self.setup(idfigure=idfigure, | |
|
159 | wintitle=wintitle, | |
|
160 | width=self.width, | |
|
161 |
|
|
|
162 |
|
|
|
177 | nplots = len(channelList) | |
|
178 | ||
|
179 | self.setup(idfigure=idfigure, | |
|
180 | nplots=nplots, | |
|
181 | wintitle=wintitle) | |
|
163 | 182 | |
|
164 |
if xmin == None: |
|
|
165 |
if xmax == None: |
|
|
166 |
if ymin == None: |
|
|
167 |
if ymax == None: |
|
|
183 | if xmin == None: xmin = numpy.nanmin(x) | |
|
184 | if xmax == None: xmax = numpy.nanmax(x) | |
|
185 | if ymin == None: ymin = numpy.nanmin(y) | |
|
186 | if ymax == None: ymax = numpy.nanmax(y) | |
|
168 | 187 | |
|
169 | 188 | self.__isConfig = True |
|
170 | 189 | |
|
171 | 190 | |
|
172 | ||
|
173 | 191 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
174 |
|
|
|
175 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) | |
|
176 | title = "Scope: " + dateTime | |
|
177 | ||
|
178 | self.setWinTitle(title) | |
|
179 | ||
|
192 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
193 | xlabel = "Range (Km)" | |
|
180 | 194 | ylabel = "Intensity" |
|
181 | 195 | |
|
182 | xlabel = "Range[Km]" | |
|
196 | self.setWinTitle(title) | |
|
183 | 197 | |
|
184 | 198 | for i in range(len(self.axesList)): |
|
185 | 199 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
186 | 200 | axes = self.axesList[i] |
|
187 |
y |
|
|
188 | axes.pline(x, y2, self.xmin, self.xmax, self.ymin, self.ymax, xlabel, ylabel, title) | |
|
201 | ychannel = y[i,:] | |
|
202 | axes.pline(x, ychannel, | |
|
203 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
|
204 | xlabel=xlabel, ylabel=ylabel, title=title) | |
|
189 | 205 | |
|
190 | 206 | self.draw() |
|
191 | 207 |
@@ -281,21 +281,21 class CohInt(Operation): | |||
|
281 | 281 | |
|
282 | 282 | __dataReady = False |
|
283 | 283 | |
|
284 |
n |
|
|
284 | n = None | |
|
285 | 285 | |
|
286 | 286 | |
|
287 | 287 | def __init__(self): |
|
288 | 288 | |
|
289 | 289 | self.__isConfig = False |
|
290 | 290 | |
|
291 |
def setup(self, n |
|
|
291 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
|
292 | 292 | """ |
|
293 | 293 | Set the parameters of the integration class. |
|
294 | 294 | |
|
295 | 295 | Inputs: |
|
296 | 296 | |
|
297 |
n |
|
|
298 |
timeInterval : Time of integration. If the parameter "n |
|
|
297 | n : Number of coherent integrations | |
|
298 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
|
299 | 299 | overlapping : |
|
300 | 300 | |
|
301 | 301 | """ |
@@ -306,15 +306,15 class CohInt(Operation): | |||
|
306 | 306 | self.__dataReady = False |
|
307 | 307 | |
|
308 | 308 | |
|
309 |
if n |
|
|
310 |
raise ValueError, "n |
|
|
309 | if n == None and timeInterval == None: | |
|
310 | raise ValueError, "n or timeInterval should be specified ..." | |
|
311 | 311 | |
|
312 |
if n |
|
|
313 |
self.n |
|
|
312 | if n != None: | |
|
313 | self.n = n | |
|
314 | 314 | self.__byTime = False |
|
315 | 315 | else: |
|
316 | 316 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
317 |
self.n |
|
|
317 | self.n = 9999 | |
|
318 | 318 | self.__byTime = True |
|
319 | 319 | |
|
320 | 320 | if overlapping: |
@@ -334,7 +334,7 class CohInt(Operation): | |||
|
334 | 334 | """ |
|
335 | 335 | |
|
336 | 336 | if not self.__withOverapping: |
|
337 | self.__buffer += data | |
|
337 | self.__buffer += data.copy() | |
|
338 | 338 | self.__profIndex += 1 |
|
339 | 339 | return |
|
340 | 340 | |
@@ -348,16 +348,16 class CohInt(Operation): | |||
|
348 | 348 | self.__profIndex += 1 |
|
349 | 349 | return |
|
350 | 350 | |
|
351 |
#If the buffer length is lower than n |
|
|
352 |
if self.__profIndex < self.n |
|
|
351 | #If the buffer length is lower than n then stakcing the data value | |
|
352 | if self.__profIndex < self.n: | |
|
353 | 353 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
354 | 354 | self.__profIndex += 1 |
|
355 | 355 | return |
|
356 | 356 | |
|
357 |
#If the buffer length is equal to n |
|
|
357 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
|
358 | 358 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
359 |
self.__buffer[self.n |
|
|
360 |
self.__profIndex = self.n |
|
|
359 | self.__buffer[self.n-1] = data | |
|
360 | self.__profIndex = self.n | |
|
361 | 361 | return |
|
362 | 362 | |
|
363 | 363 | |
@@ -373,30 +373,30 class CohInt(Operation): | |||
|
373 | 373 | |
|
374 | 374 | if not self.__withOverapping: |
|
375 | 375 | data = self.__buffer |
|
376 |
n |
|
|
376 | n = self.__profIndex | |
|
377 | 377 | |
|
378 | 378 | self.__buffer = 0 |
|
379 | 379 | self.__profIndex = 0 |
|
380 | 380 | |
|
381 |
return data, n |
|
|
381 | return data, n | |
|
382 | 382 | |
|
383 | 383 | #Integration with Overlapping |
|
384 | 384 | data = numpy.sum(self.__buffer, axis=0) |
|
385 |
n |
|
|
385 | n = self.__profIndex | |
|
386 | 386 | |
|
387 |
return data, n |
|
|
387 | return data, n | |
|
388 | 388 | |
|
389 | 389 | def byProfiles(self, data): |
|
390 | 390 | |
|
391 | 391 | self.__dataReady = False |
|
392 | 392 | avgdata = None |
|
393 |
n |
|
|
393 | n = None | |
|
394 | 394 | |
|
395 | 395 | self.putData(data) |
|
396 | 396 | |
|
397 |
if self.__profIndex == self.n |
|
|
397 | if self.__profIndex == self.n: | |
|
398 | 398 | |
|
399 |
avgdata, n |
|
|
399 | avgdata, n = self.pushData() | |
|
400 | 400 | self.__dataReady = True |
|
401 | 401 | |
|
402 | 402 | return avgdata |
@@ -405,13 +405,13 class CohInt(Operation): | |||
|
405 | 405 | |
|
406 | 406 | self.__dataReady = False |
|
407 | 407 | avgdata = None |
|
408 |
n |
|
|
408 | n = None | |
|
409 | 409 | |
|
410 | 410 | self.putData(data) |
|
411 | 411 | |
|
412 | 412 | if (datatime - self.__initime) >= self.__integrationtime: |
|
413 |
avgdata, n |
|
|
414 |
self.n |
|
|
413 | avgdata, n = self.pushData() | |
|
414 | self.n = n | |
|
415 | 415 | self.__dataReady = True |
|
416 | 416 | |
|
417 | 417 | return avgdata |
@@ -443,22 +443,22 class CohInt(Operation): | |||
|
443 | 443 | |
|
444 | 444 | return avgdata, avgdatatime |
|
445 | 445 | |
|
446 |
def run(self, dataOut, n |
|
|
446 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
|
447 | 447 | |
|
448 | 448 | if not self.__isConfig: |
|
449 |
self.setup(n |
|
|
449 | self.setup(n, timeInterval, overlapping) | |
|
450 | 450 | self.__isConfig = True |
|
451 | 451 | |
|
452 | 452 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
453 | 453 | |
|
454 |
# dataOut.timeInterval *= n |
|
|
454 | # dataOut.timeInterval *= n | |
|
455 | 455 | dataOut.flagNoData = True |
|
456 | 456 | |
|
457 | 457 | if self.__dataReady: |
|
458 | 458 | dataOut.data = avgdata |
|
459 |
dataOut. |
|
|
460 | dataOut.nCohInt *= self.nCohInt | |
|
459 | dataOut.nCohInt *= self.n | |
|
461 | 460 | dataOut.utctime = avgdatatime |
|
461 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
|
462 | 462 | dataOut.flagNoData = False |
|
463 | 463 | |
|
464 | 464 | |
@@ -615,12 +615,9 class SpectraProc(ProcessingUnit): | |||
|
615 | 615 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
616 | 616 | |
|
617 | 617 | Affected: |
|
618 | self.dataOut.data | |
|
618 | self.dataOut.data_spc | |
|
619 | 619 | self.dataOut.channelIndexList |
|
620 | 620 | self.dataOut.nChannels |
|
621 | self.dataOut.m_ProcessingHeader.totalSpectra | |
|
622 | self.dataOut.systemHeaderObj.numChannels | |
|
623 | self.dataOut.m_ProcessingHeader.blockSize | |
|
624 | 621 | |
|
625 | 622 | Return: |
|
626 | 623 | None |
@@ -633,9 +630,9 class SpectraProc(ProcessingUnit): | |||
|
633 | 630 | |
|
634 | 631 | nChannels = len(channelIndexList) |
|
635 | 632 | |
|
636 | data = self.dataOut.data_spc[channelIndexList,:] | |
|
633 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
|
637 | 634 | |
|
638 | self.dataOut.data = data | |
|
635 | self.dataOut.data_spc = data_spc | |
|
639 | 636 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
640 | 637 | # self.dataOut.nChannels = nChannels |
|
641 | 638 | |
@@ -644,5 +641,196 class SpectraProc(ProcessingUnit): | |||
|
644 | 641 | |
|
645 | 642 | class IncohInt(Operation): |
|
646 | 643 | |
|
647 | def __init__(self): | |
|
648 | pass No newline at end of file | |
|
644 | ||
|
645 | __profIndex = 0 | |
|
646 | __withOverapping = False | |
|
647 | ||
|
648 | __byTime = False | |
|
649 | __initime = None | |
|
650 | __lastdatatime = None | |
|
651 | __integrationtime = None | |
|
652 | ||
|
653 | __buffer = None | |
|
654 | ||
|
655 | __dataReady = False | |
|
656 | ||
|
657 | n = None | |
|
658 | ||
|
659 | ||
|
660 | def __init__(self): | |
|
661 | ||
|
662 | self.__isConfig = False | |
|
663 | ||
|
664 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
|
665 | """ | |
|
666 | Set the parameters of the integration class. | |
|
667 | ||
|
668 | Inputs: | |
|
669 | ||
|
670 | n : Number of coherent integrations | |
|
671 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
|
672 | overlapping : | |
|
673 | ||
|
674 | """ | |
|
675 | ||
|
676 | self.__initime = None | |
|
677 | self.__lastdatatime = 0 | |
|
678 | self.__buffer = None | |
|
679 | self.__dataReady = False | |
|
680 | ||
|
681 | ||
|
682 | if n == None and timeInterval == None: | |
|
683 | raise ValueError, "n or timeInterval should be specified ..." | |
|
684 | ||
|
685 | if n != None: | |
|
686 | self.n = n | |
|
687 | self.__byTime = False | |
|
688 | else: | |
|
689 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
|
690 | self.n = 9999 | |
|
691 | self.__byTime = True | |
|
692 | ||
|
693 | if overlapping: | |
|
694 | self.__withOverapping = True | |
|
695 | self.__buffer = None | |
|
696 | else: | |
|
697 | self.__withOverapping = False | |
|
698 | self.__buffer = 0 | |
|
699 | ||
|
700 | self.__profIndex = 0 | |
|
701 | ||
|
702 | def putData(self, data): | |
|
703 | ||
|
704 | """ | |
|
705 | Add a profile to the __buffer and increase in one the __profileIndex | |
|
706 | ||
|
707 | """ | |
|
708 | ||
|
709 | if not self.__withOverapping: | |
|
710 | self.__buffer += data.copy() | |
|
711 | self.__profIndex += 1 | |
|
712 | return | |
|
713 | ||
|
714 | #Overlapping data | |
|
715 | nChannels, nFFTPoints, nHeis = data.shape | |
|
716 | data = numpy.reshape(data, (1, nChannels, nFFTPoints, nHeis)) | |
|
717 | ||
|
718 | #If the buffer is empty then it takes the data value | |
|
719 | if self.__buffer == None: | |
|
720 | self.__buffer = data | |
|
721 | self.__profIndex += 1 | |
|
722 | return | |
|
723 | ||
|
724 | #If the buffer length is lower than n then stakcing the data value | |
|
725 | if self.__profIndex < self.n: | |
|
726 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
|
727 | self.__profIndex += 1 | |
|
728 | return | |
|
729 | ||
|
730 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
|
731 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
|
732 | self.__buffer[self.n-1] = data | |
|
733 | self.__profIndex = self.n | |
|
734 | return | |
|
735 | ||
|
736 | ||
|
737 | def pushData(self): | |
|
738 | """ | |
|
739 | Return the sum of the last profiles and the profiles used in the sum. | |
|
740 | ||
|
741 | Affected: | |
|
742 | ||
|
743 | self.__profileIndex | |
|
744 | ||
|
745 | """ | |
|
746 | ||
|
747 | if not self.__withOverapping: | |
|
748 | data = self.__buffer | |
|
749 | n = self.__profIndex | |
|
750 | ||
|
751 | self.__buffer = 0 | |
|
752 | self.__profIndex = 0 | |
|
753 | ||
|
754 | return data, n | |
|
755 | ||
|
756 | #Integration with Overlapping | |
|
757 | data = numpy.sum(self.__buffer, axis=0) | |
|
758 | n = self.__profIndex | |
|
759 | ||
|
760 | return data, n | |
|
761 | ||
|
762 | def byProfiles(self, data): | |
|
763 | ||
|
764 | self.__dataReady = False | |
|
765 | avgdata = None | |
|
766 | n = None | |
|
767 | ||
|
768 | self.putData(data) | |
|
769 | ||
|
770 | if self.__profIndex == self.n: | |
|
771 | ||
|
772 | avgdata, n = self.pushData() | |
|
773 | self.__dataReady = True | |
|
774 | ||
|
775 | return avgdata | |
|
776 | ||
|
777 | def byTime(self, data, datatime): | |
|
778 | ||
|
779 | self.__dataReady = False | |
|
780 | avgdata = None | |
|
781 | n = None | |
|
782 | ||
|
783 | self.putData(data) | |
|
784 | ||
|
785 | if (datatime - self.__initime) >= self.__integrationtime: | |
|
786 | avgdata, n = self.pushData() | |
|
787 | self.n = n | |
|
788 | self.__dataReady = True | |
|
789 | ||
|
790 | return avgdata | |
|
791 | ||
|
792 | def integrate(self, data, datatime=None): | |
|
793 | ||
|
794 | if self.__initime == None: | |
|
795 | self.__initime = datatime | |
|
796 | ||
|
797 | if self.__byTime: | |
|
798 | avgdata = self.byTime(data, datatime) | |
|
799 | else: | |
|
800 | avgdata = self.byProfiles(data) | |
|
801 | ||
|
802 | ||
|
803 | self.__lastdatatime = datatime | |
|
804 | ||
|
805 | if avgdata == None: | |
|
806 | return None, None | |
|
807 | ||
|
808 | avgdatatime = self.__initime | |
|
809 | ||
|
810 | deltatime = datatime -self.__lastdatatime | |
|
811 | ||
|
812 | if not self.__withOverapping: | |
|
813 | self.__initime = datatime | |
|
814 | else: | |
|
815 | self.__initime += deltatime | |
|
816 | ||
|
817 | return avgdata, avgdatatime | |
|
818 | ||
|
819 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
|
820 | ||
|
821 | if not self.__isConfig: | |
|
822 | self.setup(n, timeInterval, overlapping) | |
|
823 | self.__isConfig = True | |
|
824 | ||
|
825 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) | |
|
826 | ||
|
827 | # dataOut.timeInterval *= n | |
|
828 | dataOut.flagNoData = True | |
|
829 | ||
|
830 | if self.__dataReady: | |
|
831 | dataOut.data_spc = avgdata | |
|
832 | dataOut.nIncohInt *= self.n | |
|
833 | dataOut.utctime = avgdatatime | |
|
834 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt | |
|
835 | dataOut.flagNoData = False | |
|
836 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now