@@ -598,13 +598,22 if __name__ == '__main__': | |||||
598 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) |
|
598 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId()) | |
599 |
|
599 | |||
600 | opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
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 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') |
|
603 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other') | |
604 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
604 | opObj11.addParameter(name='idfigure', value='1', format='int') | |
605 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') |
|
605 | opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
606 | opObj11.addParameter(name='zmin', value='60', format='int') |
|
606 | # opObj11.addParameter(name='zmin', value='60', format='int') | |
607 | opObj11.addParameter(name='zmax', value='100', 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 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
618 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') | |
610 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
619 | # opObj12.addParameter(name='ncode', value='2', format='int') |
@@ -1,84 +1,231 | |||||
|
1 | import numpy | |||
1 | import mpldriver |
|
2 | import mpldriver | |
2 |
|
3 | |||
|
4 | ||||
3 | class Figure: |
|
5 | class Figure: | |
4 | axesList = None |
|
6 | ||
|
7 | __driver = mpldriver | |||
|
8 | ||||
|
9 | idfigure = None | |||
|
10 | wintitle = None | |||
5 | width = None |
|
11 | width = None | |
6 | height = None |
|
12 | height = None | |
7 | def __init__(self): |
|
13 | nplots = None | |
8 | pass |
|
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 | self.idfigure = idfigure |
|
50 | self.idfigure = idfigure | |
12 | self.wintitle = wintitle |
|
51 | ||
13 | self.width = width |
|
|||
14 | self.height = height |
|
|||
15 | self.nplots = nplots |
|
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 | def setTitle(self, title): |
|
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): |
|
73 | def setWinTitle(self, title): | |
24 | mpldriver.setWinTitle(fig=self.fig, title=title) |
|
74 | ||
|
75 | self.__driver.setWinTitle(self.fig, title=title) | |||
25 |
|
76 | |||
26 |
def setTextFromAxes(self, t |
|
77 | def setTextFromAxes(self, text): | |
27 | mpldriver.setTextFromAxes(self.idfigure, self.axesList[0].ax, title) |
|
78 | ||
|
79 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" | |||
28 |
|
80 | |||
29 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
81 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): | |
30 | ax = mpldriver.makeAxes(self.idfigure, nrow, ncol, xpos, ypos, colspan, rowspan) |
|
82 | ||
31 | axesObj = Axes(ax) |
|
83 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" | |
32 | self.axesList.append(axesObj) |
|
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 | def draw(self): |
|
96 | def draw(self): | |
35 | mpldriver.draw(self.idfigure) |
|
97 | ||
|
98 | self.__driver.draw(self.fig) | |||
36 |
|
99 | |||
37 | def run(self): |
|
100 | def run(self): | |
38 |
|
|
101 | ||
|
102 | raise ValueError, "This method is not implemented" | |||
|
103 | ||||
|
104 | axesList = property(getAxesObjList) | |||
39 |
|
105 | |||
40 |
|
106 | |||
41 | class Axes: |
|
107 | class Axes: | |
42 | firsttime = None |
|
108 | ||
|
109 | __driver = mpldriver | |||
|
110 | fig = None | |||
43 | ax = None |
|
111 | ax = None | |
44 |
|
|
112 | plot = None | |
45 |
|
113 | |||
46 | def __init__(self, ax): |
|
114 | firsttime = None | |
47 | self.firsttime = True |
|
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 | self.ax = ax |
|
127 | self.ax = ax | |
49 |
self. |
|
128 | self.plot = None | |
50 |
|
129 | |||
51 | def pline(self, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title): |
|
130 | self.firsttime = True | |
52 |
|
131 | |||
53 | mpldriver.pline(ax=self.ax, |
|
132 | def setText(self, text): | |
54 | x=x, |
|
133 | ||
55 | y=y, |
|
134 | self.__driver.setAxesText(self.ax, text) | |
56 | xmin=xmin, |
|
135 | ||
57 | xmax=xmax, |
|
136 | def pline(self, x, y, | |
58 |
|
|
137 | xmin=None, xmax=None, | |
59 |
|
|
138 | ymin=None, ymax=None, | |
60 |
|
|
139 | xlabel='', ylabel='', | |
61 |
|
|
140 | title='', | |
62 | title=title, |
|
141 | **kwargs): | |
63 | firsttime=self.firsttime) |
|
142 | ||
64 |
|
|
143 | """ | |
65 | self.firsttime = False |
|
144 | ||
66 |
|
145 | Input: | ||
67 | def pcolor(self, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title): |
|
146 | x : | |
68 | meshfromaxes=mpldriver.pcolor(ax=self.ax, |
|
147 | y : | |
69 | x=x, |
|
148 | xmin : | |
70 |
|
|
149 | xmax : | |
71 |
|
|
150 | ymin : | |
72 |
|
|
151 | ymax : | |
73 | xmax=xmax, |
|
152 | xlabel : | |
74 | ymin=ymin, |
|
153 | ylabel : | |
75 | ymax=ymax, |
|
154 | title : | |
76 | zmin=zmin, |
|
155 | **kwargs : Los parametros aceptados son | |
77 |
|
|
156 | ||
78 |
|
|
157 | ticksize | |
79 | ylabel=ylabel, |
|
158 | """ | |
80 | title=title, |
|
159 | ||
81 |
|
|
160 | if self.firsttime: | |
82 | mesh=self.mesh) |
|
161 | ||
83 | self.mesh = meshfromaxes |
|
162 | if xmin == None: xmin = numpy.nanmin(x) | |
84 | self.firsttime = False |
|
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 | import matplotlib |
|
2 | import matplotlib | |
2 | matplotlib.use("TKAgg") |
|
3 | matplotlib.use("TKAgg") | |
3 | import matplotlib.pyplot |
|
4 | import matplotlib.pyplot | |
4 | #import scitools.numpyutils |
|
5 | #import scitools.numpyutils | |
5 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
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 | matplotlib.pyplot.ioff() |
|
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 | fig.canvas.manager.set_window_title(wintitle) |
|
12 | fig.canvas.manager.set_window_title(wintitle) | |
11 | fig.canvas.manager.resize(width,height) |
|
13 | fig.canvas.manager.resize(width, height) | |
12 | matplotlib.pyplot.ion() |
|
14 | matplotlib.pyplot.ion() | |
|
15 | ||||
13 | return fig |
|
16 | return fig | |
14 |
|
17 | |||
15 | def setWinTitle(fig, title): |
|
18 | def setWinTitle(fig, title): | |
|
19 | ||||
16 | fig.canvas.manager.set_window_title(title) |
|
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 | def setTitle(idfigure, title): |
|
22 | def setTitle(idfigure, title): | |
26 | fig = matplotlib.pyplot.figure(idfigure) |
|
23 | fig = matplotlib.pyplot.figure(idfigure) | |
27 | fig.suptitle(title) |
|
24 | fig.suptitle(title) | |
@@ -31,7 +28,15 def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): | |||||
31 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) |
|
28 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) | |
32 | return ax |
|
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 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): |
|
38 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): | |
|
39 | ||||
35 | if firsttime: |
|
40 | if firsttime: | |
36 | ax.plot(x, y) |
|
41 | ax.plot(x, y) | |
37 | ax.set_xlim([xmin,xmax]) |
|
42 | ax.set_xlim([xmin,xmax]) | |
@@ -44,13 +49,15 def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): | |||||
44 | ax.lines[0].set_data(x,y) |
|
49 | ax.lines[0].set_data(x,y) | |
45 |
|
50 | |||
46 | def draw(idfigure): |
|
51 | def draw(idfigure): | |
|
52 | ||||
47 | fig = matplotlib.pyplot.figure(idfigure) |
|
53 | fig = matplotlib.pyplot.figure(idfigure) | |
48 | fig.canvas.draw() |
|
54 | fig.canvas.draw() | |
49 |
|
55 | |||
50 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
56 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): | |
|
57 | ||||
51 | if firsttime: |
|
58 | if firsttime: | |
52 | divider = make_axes_locatable(ax) |
|
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 | fig1 = ax.get_figure() |
|
61 | fig1 = ax.get_figure() | |
55 | fig1.add_axes(ax_cb) |
|
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 | ax.set_xlabel(xlabel) |
|
66 | ax.set_xlabel(xlabel) | |
60 | ax.set_ylabel(ylabel) |
|
67 | ax.set_ylabel(ylabel) | |
61 | ax.set_title(title) |
|
68 | ax.set_title(title) | |
62 |
|
69 | print x | ||
63 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
70 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
64 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
71 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
65 | ax_cb.yaxis.tick_right() |
|
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 | matplotlib.pyplot.tight_layout() |
|
76 | matplotlib.pyplot.tight_layout() | |
70 | return imesh |
|
77 | return imesh | |
71 | else: |
|
78 | else: | |
72 | ax.set_xlim([xmin,xmax]) |
|
79 | # ax.set_xlim([xmin,xmax]) | |
73 | ax.set_ylim([ymin,ymax]) |
|
80 | # ax.set_ylim([ymin,ymax]) | |
74 | ax.set_xlabel(xlabel) |
|
81 | ax.set_xlabel(xlabel) | |
75 | ax.set_ylabel(ylabel) |
|
82 | ax.set_ylabel(ylabel) | |
76 | ax.set_title(title) |
|
83 | ax.set_title(title) | |
77 |
|
84 | |||
78 | z = z.T |
|
85 | z = z.T | |
79 | z = z[0:-1,0:-1] |
|
86 | # z = z[0:-1,0:-1] | |
80 | mesh.set_array(z.ravel()) |
|
87 | mesh.set_array(z.ravel()) | |
81 |
|
88 | |||
82 | return mesh |
|
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 | anoise : noise's level |
|
25 | anoise : noise's level | |
26 | """ |
|
26 | """ | |
27 |
|
27 | |||
28 | dataflat = data.reshape(-1) |
|
28 | dataflat = data.copy().reshape(-1) | |
29 | dataflat.sort() |
|
29 | dataflat.sort() | |
30 | npts = dataflat.size #numbers of points of the data |
|
30 | npts = dataflat.size #numbers of points of the data | |
31 |
|
31 | |||
@@ -61,9 +61,12 def hildebrand_sekhon(data, navg): | |||||
61 |
|
61 | |||
62 | return anoise; |
|
62 | return anoise; | |
63 |
|
63 | |||
64 |
def sorting_bruce( |
|
64 | def sorting_bruce(data, navg): | |
65 | sortdata = numpy.sort(Data) |
|
65 | ||
66 | lenOfData = len(Data) |
|
66 | data = data.copy() | |
|
67 | ||||
|
68 | sortdata = numpy.sort(data) | |||
|
69 | lenOfData = len(data) | |||
67 | nums_min = lenOfData/10 |
|
70 | nums_min = lenOfData/10 | |
68 |
|
71 | |||
69 | if (lenOfData/10) > 0: |
|
72 | if (lenOfData/10) > 0: | |
@@ -155,6 +158,11 class JROData: | |||||
155 | nCohInt = None |
|
158 | nCohInt = None | |
156 |
|
159 | |||
157 | noise = None |
|
160 | noise = None | |
|
161 | ||||
|
162 | #Speed of ligth | |||
|
163 | C = 3e8 | |||
|
164 | ||||
|
165 | frequency = 49.92e6 | |||
158 |
|
166 | |||
159 | def __init__(self): |
|
167 | def __init__(self): | |
160 |
|
168 | |||
@@ -318,11 +326,35 class Spectra(JROData): | |||||
318 |
|
326 | |||
319 | self.wavelength = None |
|
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) |
|
357 | return velrange | |
324 | xrange = xrange |
|
|||
325 | return None |
|
|||
326 |
|
358 | |||
327 | def getNoisebyHildebrand(self): |
|
359 | def getNoisebyHildebrand(self): | |
328 | """ |
|
360 | """ |
@@ -1973,8 +1973,9 class SpectraReader(JRODataReader): | |||||
1973 |
|
1973 | |||
1974 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
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 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1980 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
1980 |
|
1981 |
@@ -9,15 +9,15 class SpectraPlot(Figure): | |||||
9 | def __init__(self): |
|
9 | def __init__(self): | |
10 |
|
10 | |||
11 | self.__isConfig = False |
|
11 | self.__isConfig = False | |
12 |
self. |
|
12 | self.WIDTH = 300 | |
13 |
self. |
|
13 | self.HEIGHT = 400 | |
14 |
|
14 | |||
15 | def getSubplots(self): |
|
15 | def getSubplots(self): | |
16 |
|
16 | |||
17 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
17 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
18 | nrow = int(self.nplots*1./ncol + 0.9) |
|
18 | nrow = int(self.nplots*1./ncol + 0.9) | |
19 | return nrow, ncol |
|
19 | return nrow, ncol | |
20 |
|
20 | |||
21 | def setAxesWithOutProfiles(self, nrow, ncol): |
|
21 | def setAxesWithOutProfiles(self, nrow, ncol): | |
22 |
|
22 | |||
23 | colspan = 1 |
|
23 | colspan = 1 | |
@@ -27,7 +27,7 class SpectraPlot(Figure): | |||||
27 | for y in range(nrow): |
|
27 | for y in range(nrow): | |
28 | for x in range(ncol): |
|
28 | for x in range(ncol): | |
29 | if counter < self.nplots: |
|
29 | if counter < self.nplots: | |
30 |
self. |
|
30 | self.addAxes(nrow, ncol, y, x, colspan, rowspan) | |
31 | counter += 1 |
|
31 | counter += 1 | |
32 |
|
32 | |||
33 | def setAxesWithProfiles(self, nrow, ncol): |
|
33 | def setAxesWithProfiles(self, nrow, ncol): | |
@@ -42,150 +42,166 class SpectraPlot(Figure): | |||||
42 | for x in range(ncol): |
|
42 | for x in range(ncol): | |
43 | if counter < self.nplots*factor: |
|
43 | if counter < self.nplots*factor: | |
44 | # plt.subplot2grid((nrow, ncol), (y, x), colspan=colspan, rowspan=rowspan) |
|
44 | # plt.subplot2grid((nrow, ncol), (y, x), colspan=colspan, rowspan=rowspan) | |
45 |
self. |
|
45 | self.addAxes(nrow, ncol, y, x, colspan, rowspan) | |
46 | counter += 1 |
|
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 | self.setAxesWithProfiles(nrow, ncol) |
|
55 | self.setAxesWithProfiles(nrow, ncol) | |
56 | else: |
|
56 | else: | |
57 | self.setAxesWithOutProfiles(nrow, ncol) |
|
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 | if channelList == None: |
|
78 | if channelList == None: | |
62 | channelList = dataOut.channelList |
|
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 | y = dataOut.heightList |
|
82 | y = dataOut.heightList | |
69 |
|
83 | z = 10.*numpy.log10(dataOut.data_spc[channelList,:,:]) | ||
70 | x = numpy.arange(dataOut.nFFTPoints) |
|
|||
71 |
|
84 | |||
72 | noise = dataOut.getNoise() |
|
85 | noise = dataOut.getNoise() | |
73 |
|
86 | |||
74 | if not self.__isConfig: |
|
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) |
|
89 | nplots = len(channelList) | |
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) |
|
|||
88 |
|
90 | |||
89 | self.xmin = xmin |
|
91 | self.setup(idfigure=idfigure, | |
90 | self.xmax = xmax |
|
92 | nplots=nplots, | |
91 | self.ymin = ymin |
|
93 | wintitle=wintitle, | |
92 | self.ymax = ymax |
|
94 | showprofile=showprofile) | |
93 |
|
|
95 | ||
94 | self.zmax = zmax |
|
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 | self.__isConfig = True |
|
103 | self.__isConfig = True | |
97 |
|
104 | |||
98 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
105 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
99 |
|
|
106 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
100 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
107 | xlabel = "Velocity (m/s)" | |
101 | title = "Spectra: " + dateTime |
|
108 | ylabel = "Range (Km)" | |
102 |
|
109 | |||
103 | self.setWinTitle(title) |
|
110 | self.setWinTitle(title) | |
104 |
|
111 | |||
105 | ylabel = "Range[Km]" |
|
112 | for i in range(self.nplots): | |
106 |
|
||||
107 | xlabel = "m/s" |
|
|||
108 |
|
||||
109 | for i in range(len(self.axesList)): |
|
|||
110 | title = "Channel %d: %4.2fdB" %(channelList[i], noise[i]) |
|
113 | title = "Channel %d: %4.2fdB" %(channelList[i], noise[i]) | |
|
114 | zchannel = z[i,:,:] | |||
|
115 | ||||
111 | axes = self.axesList[i] |
|
116 | axes = self.axesList[i] | |
112 | z2 = z[i,:,:] |
|
117 | axes.pcolor(x, y, zchannel, | |
113 | axes.pcolor(x, y, z2, self.xmin, self.xmax, self.ymin, self.ymax, self.zmin, self.zmax, xlabel, ylabel, title) |
|
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 | self.draw() |
|
122 | self.draw() | |
116 |
|
123 | |||
117 | class Scope(Figure): |
|
124 | class Scope(Figure): | |
|
125 | ||||
118 | __isConfig = None |
|
126 | __isConfig = None | |
119 |
|
127 | |||
120 | def __init__(self): |
|
128 | def __init__(self): | |
|
129 | ||||
121 | self.__isConfig = False |
|
130 | self.__isConfig = False | |
122 |
self. |
|
131 | self.WIDTH = 600 | |
123 |
self. |
|
132 | self.HEIGHT = 200 | |
124 |
|
133 | |||
125 | def getSubplots(self): |
|
134 | def getSubplots(self): | |
|
135 | ||||
126 | nrow = self.nplots |
|
136 | nrow = self.nplots | |
127 | ncol = 3 |
|
137 | ncol = 3 | |
128 | return nrow, ncol |
|
138 | return nrow, ncol | |
129 |
|
139 | |||
130 |
def setup(self, idfigure, |
|
140 | def setup(self, idfigure, nplots, wintitle): | |
131 | self.init(idfigure, wintitle, width, height, nplots) |
|
141 | ||
|
142 | self.init(idfigure, nplots, wintitle) | |||
132 |
|
143 | |||
133 | nrow,ncol = self.getSubplots() |
|
144 | nrow,ncol = self.getSubplots() | |
134 | colspan = 3 |
|
145 | colspan = 3 | |
135 | rowspan = 1 |
|
146 | rowspan = 1 | |
136 |
|
147 | |||
137 | for i in range(nplots): |
|
148 | for i in range(nplots): | |
138 |
self. |
|
149 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) | |
139 |
|
||||
140 |
|
||||
141 |
|
150 | |||
142 |
def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
151 | def run(self, dataOut, idfigure, wintitle="", channelList=None, | |
143 |
|
152 | xmin=None, xmax=None, ymin=None, ymax=None): | ||
144 | if dataOut.isEmpty(): |
|
153 | ||
145 | return None |
|
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 | if channelList == None: |
|
167 | if channelList == None: | |
148 |
|
|
168 | channelList = dataOut.channelList | |
149 |
|
||||
150 | nplots = len(channelList) |
|
|||
151 |
|
169 | |||
|
170 | x = dataOut.heightList | |||
152 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
171 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) | |
153 | y = y.real |
|
172 | y = y.real | |
154 |
|
173 | |||
155 |
|
|
174 | noise = dataOut.getNoise() | |
156 |
|
175 | |||
157 | if not self.__isConfig: |
|
176 | if not self.__isConfig: | |
158 | self.setup(idfigure=idfigure, |
|
177 | nplots = len(channelList) | |
159 | wintitle=wintitle, |
|
178 | ||
160 | width=self.width, |
|
179 | self.setup(idfigure=idfigure, | |
161 |
|
|
180 | nplots=nplots, | |
162 |
|
|
181 | wintitle=wintitle) | |
163 |
|
182 | |||
164 |
if xmin == None: |
|
183 | if xmin == None: xmin = numpy.nanmin(x) | |
165 |
if xmax == None: |
|
184 | if xmax == None: xmax = numpy.nanmax(x) | |
166 |
if ymin == None: |
|
185 | if ymin == None: ymin = numpy.nanmin(y) | |
167 |
if ymax == None: |
|
186 | if ymax == None: ymax = numpy.nanmax(y) | |
168 |
|
187 | |||
169 | self.__isConfig = True |
|
188 | self.__isConfig = True | |
170 |
|
189 | |||
171 |
|
190 | |||
172 |
|
||||
173 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
191 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) | |
174 |
|
|
192 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
175 | date = "%s"%(thisDatetime.strftime("%d-%b-%Y")) |
|
193 | xlabel = "Range (Km)" | |
176 | title = "Scope: " + dateTime |
|
|||
177 |
|
||||
178 | self.setWinTitle(title) |
|
|||
179 |
|
||||
180 | ylabel = "Intensity" |
|
194 | ylabel = "Intensity" | |
181 |
|
195 | |||
182 | xlabel = "Range[Km]" |
|
196 | self.setWinTitle(title) | |
183 |
|
197 | |||
184 | for i in range(len(self.axesList)): |
|
198 | for i in range(len(self.axesList)): | |
185 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
199 | title = "Channel %d: %4.2fdB" %(i, noise[i]) | |
186 | axes = self.axesList[i] |
|
200 | axes = self.axesList[i] | |
187 |
y |
|
201 | ychannel = y[i,:] | |
188 | axes.pline(x, y2, self.xmin, self.xmax, self.ymin, self.ymax, xlabel, ylabel, title) |
|
202 | axes.pline(x, ychannel, | |
|
203 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |||
|
204 | xlabel=xlabel, ylabel=ylabel, title=title) | |||
189 |
|
205 | |||
190 | self.draw() |
|
206 | self.draw() | |
191 |
|
207 |
@@ -281,21 +281,21 class CohInt(Operation): | |||||
281 |
|
281 | |||
282 | __dataReady = False |
|
282 | __dataReady = False | |
283 |
|
283 | |||
284 |
n |
|
284 | n = None | |
285 |
|
285 | |||
286 |
|
286 | |||
287 | def __init__(self): |
|
287 | def __init__(self): | |
288 |
|
288 | |||
289 | self.__isConfig = False |
|
289 | self.__isConfig = False | |
290 |
|
290 | |||
291 |
def setup(self, n |
|
291 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
292 | """ |
|
292 | """ | |
293 | Set the parameters of the integration class. |
|
293 | Set the parameters of the integration class. | |
294 |
|
294 | |||
295 | Inputs: |
|
295 | Inputs: | |
296 |
|
296 | |||
297 |
n |
|
297 | n : Number of coherent integrations | |
298 |
timeInterval : Time of integration. If the parameter "n |
|
298 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
299 | overlapping : |
|
299 | overlapping : | |
300 |
|
300 | |||
301 | """ |
|
301 | """ | |
@@ -306,15 +306,15 class CohInt(Operation): | |||||
306 | self.__dataReady = False |
|
306 | self.__dataReady = False | |
307 |
|
307 | |||
308 |
|
308 | |||
309 |
if n |
|
309 | if n == None and timeInterval == None: | |
310 |
raise ValueError, "n |
|
310 | raise ValueError, "n or timeInterval should be specified ..." | |
311 |
|
311 | |||
312 |
if n |
|
312 | if n != None: | |
313 |
self.n |
|
313 | self.n = n | |
314 | self.__byTime = False |
|
314 | self.__byTime = False | |
315 | else: |
|
315 | else: | |
316 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
316 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
317 |
self.n |
|
317 | self.n = 9999 | |
318 | self.__byTime = True |
|
318 | self.__byTime = True | |
319 |
|
319 | |||
320 | if overlapping: |
|
320 | if overlapping: | |
@@ -334,7 +334,7 class CohInt(Operation): | |||||
334 | """ |
|
334 | """ | |
335 |
|
335 | |||
336 | if not self.__withOverapping: |
|
336 | if not self.__withOverapping: | |
337 | self.__buffer += data |
|
337 | self.__buffer += data.copy() | |
338 | self.__profIndex += 1 |
|
338 | self.__profIndex += 1 | |
339 | return |
|
339 | return | |
340 |
|
340 | |||
@@ -348,16 +348,16 class CohInt(Operation): | |||||
348 | self.__profIndex += 1 |
|
348 | self.__profIndex += 1 | |
349 | return |
|
349 | return | |
350 |
|
350 | |||
351 |
#If the buffer length is lower than n |
|
351 | #If the buffer length is lower than n then stakcing the data value | |
352 |
if self.__profIndex < self.n |
|
352 | if self.__profIndex < self.n: | |
353 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
353 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
354 | self.__profIndex += 1 |
|
354 | self.__profIndex += 1 | |
355 | return |
|
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 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
358 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
359 |
self.__buffer[self.n |
|
359 | self.__buffer[self.n-1] = data | |
360 |
self.__profIndex = self.n |
|
360 | self.__profIndex = self.n | |
361 | return |
|
361 | return | |
362 |
|
362 | |||
363 |
|
363 | |||
@@ -373,30 +373,30 class CohInt(Operation): | |||||
373 |
|
373 | |||
374 | if not self.__withOverapping: |
|
374 | if not self.__withOverapping: | |
375 | data = self.__buffer |
|
375 | data = self.__buffer | |
376 |
n |
|
376 | n = self.__profIndex | |
377 |
|
377 | |||
378 | self.__buffer = 0 |
|
378 | self.__buffer = 0 | |
379 | self.__profIndex = 0 |
|
379 | self.__profIndex = 0 | |
380 |
|
380 | |||
381 |
return data, n |
|
381 | return data, n | |
382 |
|
382 | |||
383 | #Integration with Overlapping |
|
383 | #Integration with Overlapping | |
384 | data = numpy.sum(self.__buffer, axis=0) |
|
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 | def byProfiles(self, data): |
|
389 | def byProfiles(self, data): | |
390 |
|
390 | |||
391 | self.__dataReady = False |
|
391 | self.__dataReady = False | |
392 | avgdata = None |
|
392 | avgdata = None | |
393 |
n |
|
393 | n = None | |
394 |
|
394 | |||
395 | self.putData(data) |
|
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 | self.__dataReady = True |
|
400 | self.__dataReady = True | |
401 |
|
401 | |||
402 | return avgdata |
|
402 | return avgdata | |
@@ -405,13 +405,13 class CohInt(Operation): | |||||
405 |
|
405 | |||
406 | self.__dataReady = False |
|
406 | self.__dataReady = False | |
407 | avgdata = None |
|
407 | avgdata = None | |
408 |
n |
|
408 | n = None | |
409 |
|
409 | |||
410 | self.putData(data) |
|
410 | self.putData(data) | |
411 |
|
411 | |||
412 | if (datatime - self.__initime) >= self.__integrationtime: |
|
412 | if (datatime - self.__initime) >= self.__integrationtime: | |
413 |
avgdata, n |
|
413 | avgdata, n = self.pushData() | |
414 |
self.n |
|
414 | self.n = n | |
415 | self.__dataReady = True |
|
415 | self.__dataReady = True | |
416 |
|
416 | |||
417 | return avgdata |
|
417 | return avgdata | |
@@ -443,22 +443,22 class CohInt(Operation): | |||||
443 |
|
443 | |||
444 | return avgdata, avgdatatime |
|
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 | if not self.__isConfig: |
|
448 | if not self.__isConfig: | |
449 |
self.setup(n |
|
449 | self.setup(n, timeInterval, overlapping) | |
450 | self.__isConfig = True |
|
450 | self.__isConfig = True | |
451 |
|
451 | |||
452 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
452 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
453 |
|
453 | |||
454 |
# dataOut.timeInterval *= n |
|
454 | # dataOut.timeInterval *= n | |
455 | dataOut.flagNoData = True |
|
455 | dataOut.flagNoData = True | |
456 |
|
456 | |||
457 | if self.__dataReady: |
|
457 | if self.__dataReady: | |
458 | dataOut.data = avgdata |
|
458 | dataOut.data = avgdata | |
459 |
dataOut. |
|
459 | dataOut.nCohInt *= self.n | |
460 | dataOut.nCohInt *= self.nCohInt |
|
|||
461 | dataOut.utctime = avgdatatime |
|
460 | dataOut.utctime = avgdatatime | |
|
461 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |||
462 | dataOut.flagNoData = False |
|
462 | dataOut.flagNoData = False | |
463 |
|
463 | |||
464 |
|
464 | |||
@@ -615,12 +615,9 class SpectraProc(ProcessingUnit): | |||||
615 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
615 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
616 |
|
616 | |||
617 | Affected: |
|
617 | Affected: | |
618 | self.dataOut.data |
|
618 | self.dataOut.data_spc | |
619 | self.dataOut.channelIndexList |
|
619 | self.dataOut.channelIndexList | |
620 | self.dataOut.nChannels |
|
620 | self.dataOut.nChannels | |
621 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
|||
622 | self.dataOut.systemHeaderObj.numChannels |
|
|||
623 | self.dataOut.m_ProcessingHeader.blockSize |
|
|||
624 |
|
621 | |||
625 | Return: |
|
622 | Return: | |
626 | None |
|
623 | None | |
@@ -633,9 +630,9 class SpectraProc(ProcessingUnit): | |||||
633 |
|
630 | |||
634 | nChannels = len(channelIndexList) |
|
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 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
636 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
640 | # self.dataOut.nChannels = nChannels |
|
637 | # self.dataOut.nChannels = nChannels | |
641 |
|
638 | |||
@@ -644,5 +641,196 class SpectraProc(ProcessingUnit): | |||||
644 |
|
641 | |||
645 | class IncohInt(Operation): |
|
642 | class IncohInt(Operation): | |
646 |
|
643 | |||
647 | def __init__(self): |
|
644 | ||
648 | pass No newline at end of file |
|
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