##// END OF EJS Templates
Bug fixed: Al graficar los canales selecionados en SpectraPlot
Miguel Valdez -
r203:02fdfa7ac337
parent child
Show More
@@ -1,209 +1,215
1 import numpy
1 import numpy
2 import datetime
2 import datetime
3 from graphics.figure import *
3 from graphics.figure import *
4
4
5 class SpectraPlot(Figure):
5 class SpectraPlot(Figure):
6
6
7 __isConfig = None
7 __isConfig = None
8
8
9 def __init__(self):
9 def __init__(self):
10
10
11 self.__isConfig = False
11 self.__isConfig = False
12 self.WIDTH = 300
12 self.WIDTH = 300
13 self.HEIGHT = 400
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
24 rowspan = 1
24 rowspan = 1
25 counter = 0
25 counter = 0
26
26
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.addAxes(nrow, ncol, y, x, colspan, rowspan)
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):
34
34
35 colspan = 1
35 colspan = 1
36 rowspan = 1
36 rowspan = 1
37 factor = 2
37 factor = 2
38 ncol = ncol*factor
38 ncol = ncol*factor
39 counter = 0
39 counter = 0
40
40
41 for y in range(nrow):
41 for y in range(nrow):
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.addAxes(nrow, ncol, y, x, colspan, rowspan)
45 self.addAxes(nrow, ncol, y, x, colspan, rowspan)
46 counter += 1
46 counter += 1
47
47
48 def setup(self, idfigure, nplots, wintitle, showprofile=True):
48 def setup(self, idfigure, nplots, wintitle, showprofile=True):
49
49
50 self.init(idfigure, nplots, wintitle)
50 self.init(idfigure, nplots, wintitle)
51
51
52 nrow, ncol = self.getSubplots()
52 nrow, ncol = self.getSubplots()
53
53
54 if showprofile:
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, showprofile=False,
59 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile=False,
60 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
60 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
61
61
62 """
62 """
63
63
64 Input:
64 Input:
65 dataOut :
65 dataOut :
66 idfigure :
66 idfigure :
67 wintitle :
67 wintitle :
68 channelList :
68 channelList :
69 showProfile :
69 showProfile :
70 xmin : None,
70 xmin : None,
71 xmax : None,
71 xmax : None,
72 ymin : None,
72 ymin : None,
73 ymax : None,
73 ymax : None,
74 zmin : None,
74 zmin : None,
75 zmax : None
75 zmax : None
76 """
76 """
77
77
78 if channelList == None:
78 if channelList == None:
79 channelList = dataOut.channelList
79 channelIndexList = dataOut.channelIndexList
80 else:
81 channelIndexList = []
82 for channel in channelList:
83 if channel not in dataOut.channelList:
84 raise ValueError, "Channel %d is not in dataOut.channelList"
85 channelIndexList.append(channel)
80
86
81 x = dataOut.getVelRange(1)
87 x = dataOut.getVelRange(1)
82 y = dataOut.heightList
88 y = dataOut.heightList
83 z = 10.*numpy.log10(dataOut.data_spc[channelList,:,:])
89 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
84
90
85 noise = dataOut.getNoise()
91 noise = dataOut.getNoise()
86
92
87 if not self.__isConfig:
93 if not self.__isConfig:
88
94
89 nplots = len(channelList)
95 nplots = len(channelIndexList)
90
96
91 self.setup(idfigure=idfigure,
97 self.setup(idfigure=idfigure,
92 nplots=nplots,
98 nplots=nplots,
93 wintitle=wintitle,
99 wintitle=wintitle,
94 showprofile=showprofile)
100 showprofile=showprofile)
95
101
96 if xmin == None: xmin = numpy.nanmin(x)
102 if xmin == None: xmin = numpy.nanmin(x)
97 if xmax == None: xmax = numpy.nanmax(x)
103 if xmax == None: xmax = numpy.nanmax(x)
98 if ymin == None: ymin = numpy.nanmin(y)
104 if ymin == None: ymin = numpy.nanmin(y)
99 if ymax == None: ymax = numpy.nanmax(y)
105 if ymax == None: ymax = numpy.nanmax(y)
100 if zmin == None: zmin = numpy.nanmin(z)*0.9
106 if zmin == None: zmin = numpy.nanmin(z)*0.9
101 if zmax == None: zmax = numpy.nanmax(z)*0.9
107 if zmax == None: zmax = numpy.nanmax(z)*0.9
102
108
103 self.__isConfig = True
109 self.__isConfig = True
104
110
105 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
111 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
106 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
112 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
107 xlabel = "Velocity (m/s)"
113 xlabel = "Velocity (m/s)"
108 ylabel = "Range (Km)"
114 ylabel = "Range (Km)"
109
115
110 self.setWinTitle(title)
116 self.setWinTitle(title)
111
117
112 for i in range(self.nplots):
118 for i in range(self.nplots):
113 title = "Channel %d: %4.2fdB" %(channelList[i], noise[i])
119 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
114 zchannel = z[i,:,:]
120 zchannel = z[i,:,:]
115
121
116 axes = self.axesList[i]
122 axes = self.axesList[i]
117 axes.pcolor(x, y, zchannel,
123 axes.pcolor(x, y, zchannel,
118 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
124 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
119 xlabel=xlabel, ylabel=ylabel, title=title,
125 xlabel=xlabel, ylabel=ylabel, title=title,
120 ticksize=9, cblabel='dB')
126 ticksize=9, cblabel='dB')
121
127
122 self.draw()
128 self.draw()
123
129
124 class Scope(Figure):
130 class Scope(Figure):
125
131
126 __isConfig = None
132 __isConfig = None
127
133
128 def __init__(self):
134 def __init__(self):
129
135
130 self.__isConfig = False
136 self.__isConfig = False
131 self.WIDTH = 600
137 self.WIDTH = 600
132 self.HEIGHT = 200
138 self.HEIGHT = 200
133
139
134 def getSubplots(self):
140 def getSubplots(self):
135
141
136 nrow = self.nplots
142 nrow = self.nplots
137 ncol = 3
143 ncol = 3
138 return nrow, ncol
144 return nrow, ncol
139
145
140 def setup(self, idfigure, nplots, wintitle):
146 def setup(self, idfigure, nplots, wintitle):
141
147
142 self.init(idfigure, nplots, wintitle)
148 self.init(idfigure, nplots, wintitle)
143
149
144 nrow,ncol = self.getSubplots()
150 nrow,ncol = self.getSubplots()
145 colspan = 3
151 colspan = 3
146 rowspan = 1
152 rowspan = 1
147
153
148 for i in range(nplots):
154 for i in range(nplots):
149 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
155 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
150
156
151 def run(self, dataOut, idfigure, wintitle="", channelList=None,
157 def run(self, dataOut, idfigure, wintitle="", channelList=None,
152 xmin=None, xmax=None, ymin=None, ymax=None):
158 xmin=None, xmax=None, ymin=None, ymax=None):
153
159
154 """
160 """
155
161
156 Input:
162 Input:
157 dataOut :
163 dataOut :
158 idfigure :
164 idfigure :
159 wintitle :
165 wintitle :
160 channelList :
166 channelList :
161 xmin : None,
167 xmin : None,
162 xmax : None,
168 xmax : None,
163 ymin : None,
169 ymin : None,
164 ymax : None,
170 ymax : None,
165 """
171 """
166
172
167 if channelList == None:
173 if channelList == None:
168 channelList = dataOut.channelList
174 channelList = dataOut.channelList
169
175
170 x = dataOut.heightList
176 x = dataOut.heightList
171 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
177 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
172 y = y.real
178 y = y.real
173
179
174 noise = dataOut.getNoise()
180 noise = dataOut.getNoise()
175
181
176 if not self.__isConfig:
182 if not self.__isConfig:
177 nplots = len(channelList)
183 nplots = len(channelList)
178
184
179 self.setup(idfigure=idfigure,
185 self.setup(idfigure=idfigure,
180 nplots=nplots,
186 nplots=nplots,
181 wintitle=wintitle)
187 wintitle=wintitle)
182
188
183 if xmin == None: xmin = numpy.nanmin(x)
189 if xmin == None: xmin = numpy.nanmin(x)
184 if xmax == None: xmax = numpy.nanmax(x)
190 if xmax == None: xmax = numpy.nanmax(x)
185 if ymin == None: ymin = numpy.nanmin(y)
191 if ymin == None: ymin = numpy.nanmin(y)
186 if ymax == None: ymax = numpy.nanmax(y)
192 if ymax == None: ymax = numpy.nanmax(y)
187
193
188 self.__isConfig = True
194 self.__isConfig = True
189
195
190
196
191 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
197 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
192 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
198 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
193 xlabel = "Range (Km)"
199 xlabel = "Range (Km)"
194 ylabel = "Intensity"
200 ylabel = "Intensity"
195
201
196 self.setWinTitle(title)
202 self.setWinTitle(title)
197
203
198 for i in range(len(self.axesList)):
204 for i in range(len(self.axesList)):
199 title = "Channel %d: %4.2fdB" %(i, noise[i])
205 title = "Channel %d: %4.2fdB" %(i, noise[i])
200 axes = self.axesList[i]
206 axes = self.axesList[i]
201 ychannel = y[i,:]
207 ychannel = y[i,:]
202 axes.pline(x, ychannel,
208 axes.pline(x, ychannel,
203 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
209 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
204 xlabel=xlabel, ylabel=ylabel, title=title)
210 xlabel=xlabel, ylabel=ylabel, title=title)
205
211
206 self.draw()
212 self.draw()
207
213
208
214
209 No newline at end of file
215
General Comments 0
You need to be logged in to leave comments. Login now