##// END OF EJS Templates
Se modifico el calculo automatico del rango de valores del grafico de Espectros.
Miguel Valdez -
r205:1ee343fe61a4
parent child
Show More
@@ -1,229 +1,227
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 __nsubplots = None
8 __nsubplots = None
9
9
10 WIDTHPROF = None
10 WIDTHPROF = None
11 HEIGHTPROF = None
11 HEIGHTPROF = None
12
12
13 def __init__(self):
13 def __init__(self):
14
14
15 self.__isConfig = False
15 self.__isConfig = False
16 self.__nsubplots = 1
16 self.__nsubplots = 1
17
17
18 self.WIDTH = 300
18 self.WIDTH = 300
19 self.HEIGHT = 400
19 self.HEIGHT = 400
20 self.WIDTHPROF = 120
20 self.WIDTHPROF = 120
21 self.HEIGHTPROF = 0
21 self.HEIGHTPROF = 0
22
22
23 def getSubplots(self):
23 def getSubplots(self):
24
24
25 ncol = int(numpy.sqrt(self.nplots)+0.9)
25 ncol = int(numpy.sqrt(self.nplots)+0.9)
26 nrow = int(self.nplots*1./ncol + 0.9)
26 nrow = int(self.nplots*1./ncol + 0.9)
27
27
28 return nrow, ncol
28 return nrow, ncol
29
29
30 def setup(self, idfigure, nplots, wintitle, showprofile=True):
30 def setup(self, idfigure, nplots, wintitle, showprofile=True):
31
31
32 self.__showprofile = showprofile
32 self.__showprofile = showprofile
33 self.nplots = nplots
33 self.nplots = nplots
34
34
35 ncolspan = 1
35 ncolspan = 1
36 colspan = 1
36 colspan = 1
37 if showprofile:
37 if showprofile:
38 ncolspan = 3
38 ncolspan = 3
39 colspan = 2
39 colspan = 2
40 self.__nsubplots = 2
40 self.__nsubplots = 2
41 self.WIDTH += self.WIDTHPROF
41 self.WIDTH += self.WIDTHPROF
42 self.HEIGHT += self.HEIGHTPROF
42 self.HEIGHT += self.HEIGHTPROF
43
43
44 self.createFigure(idfigure, wintitle)
44 self.createFigure(idfigure, wintitle)
45
45
46 nrow, ncol = self.getSubplots()
46 nrow, ncol = self.getSubplots()
47
47
48 counter = 0
48 counter = 0
49 for y in range(nrow):
49 for y in range(nrow):
50 for x in range(ncol):
50 for x in range(ncol):
51
51
52 if counter >= self.nplots:
52 if counter >= self.nplots:
53 break
53 break
54
54
55 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
55 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
56
56
57 if showprofile:
57 if showprofile:
58 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+2, 1, 1)
58 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+2, 1, 1)
59
59
60 counter += 1
60 counter += 1
61
61
62 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
62 def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True',
63 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
63 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
64
64
65 """
65 """
66
66
67 Input:
67 Input:
68 dataOut :
68 dataOut :
69 idfigure :
69 idfigure :
70 wintitle :
70 wintitle :
71 channelList :
71 channelList :
72 showProfile :
72 showProfile :
73 xmin : None,
73 xmin : None,
74 xmax : None,
74 xmax : None,
75 ymin : None,
75 ymin : None,
76 ymax : None,
76 ymax : None,
77 zmin : None,
77 zmin : None,
78 zmax : None
78 zmax : None
79 """
79 """
80
80
81 if channelList == None:
81 if channelList == None:
82 channelIndexList = dataOut.channelIndexList
82 channelIndexList = dataOut.channelIndexList
83 else:
83 else:
84 channelIndexList = []
84 channelIndexList = []
85 for channel in channelList:
85 for channel in channelList:
86 if channel not in dataOut.channelList:
86 if channel not in dataOut.channelList:
87 raise ValueError, "Channel %d is not in dataOut.channelList"
87 raise ValueError, "Channel %d is not in dataOut.channelList"
88 channelIndexList.append(channel)
88 channelIndexList.append(channel)
89
89
90 x = dataOut.getVelRange(1)
90 x = dataOut.getVelRange(1)
91 y = dataOut.heightList
91 y = dataOut.heightList
92 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
92 z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:])
93 avg = numpy.average(z, axis=1)
93
94
94 noise = dataOut.getNoise()
95 noise = dataOut.getNoise()
95
96
96 if not self.__isConfig:
97 if not self.__isConfig:
97
98
98 nplots = len(channelIndexList)
99 nplots = len(channelIndexList)
99
100
100 self.setup(idfigure=idfigure,
101 self.setup(idfigure=idfigure,
101 nplots=nplots,
102 nplots=nplots,
102 wintitle=wintitle,
103 wintitle=wintitle,
103 showprofile=showprofile)
104 showprofile=showprofile)
104
105
105 if xmin == None: xmin = numpy.nanmin(x)
106 if xmin == None: xmin = numpy.nanmin(x)
106 if xmax == None: xmax = numpy.nanmax(x)
107 if xmax == None: xmax = numpy.nanmax(x)
107 if ymin == None: ymin = numpy.nanmin(y)
108 if ymin == None: ymin = numpy.nanmin(y)
108 if ymax == None: ymax = numpy.nanmax(y)
109 if ymax == None: ymax = numpy.nanmax(y)
109 if zmin == None: zmin = numpy.nanmin(z)*0.9
110 if zmin == None: zmin = numpy.nanmin(avg)*0.9
110 if zmax == None: zmax = numpy.nanmax(z)*0.9
111 if zmax == None: zmax = numpy.nanmax(avg)*0.9
111
112
112 self.__isConfig = True
113 self.__isConfig = True
113
114
114 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
115 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
115 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
116 title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
116 xlabel = "Velocity (m/s)"
117 xlabel = "Velocity (m/s)"
117 ylabel = "Range (Km)"
118 ylabel = "Range (Km)"
118
119
119 self.setWinTitle(title)
120 self.setWinTitle(title)
120
121 if self.__showprofile:
122 avg = numpy.average(z, axis=1)
123
121
124 for i in range(self.nplots):
122 for i in range(self.nplots):
125 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
123 title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i])
126 axes = self.axesList[i*self.__nsubplots]
124 axes = self.axesList[i*self.__nsubplots]
127 axes.pcolor(x, y, z[i,:,:],
125 axes.pcolor(x, y, z[i,:,:],
128 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
126 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
129 xlabel=xlabel, ylabel=ylabel, title=title,
127 xlabel=xlabel, ylabel=ylabel, title=title,
130 ticksize=9, cblabel='')
128 ticksize=9, cblabel='')
131
129
132 if self.__showprofile:
130 if self.__showprofile:
133 axes = self.axesList[i*self.__nsubplots +1]
131 axes = self.axesList[i*self.__nsubplots +1]
134 axes.pline(avg[i], y,
132 axes.pline(avg[i], y,
135 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
133 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
136 xlabel='dB', ylabel='', title='',
134 xlabel='dB', ylabel='', title='',
137 ytick_visible=False,
135 ytick_visible=False,
138 grid='x')
136 grid='x')
139
137
140 self.draw()
138 self.draw()
141
139
142 class Scope(Figure):
140 class Scope(Figure):
143
141
144 __isConfig = None
142 __isConfig = None
145
143
146 def __init__(self):
144 def __init__(self):
147
145
148 self.__isConfig = False
146 self.__isConfig = False
149 self.WIDTH = 600
147 self.WIDTH = 600
150 self.HEIGHT = 200
148 self.HEIGHT = 200
151
149
152 def getSubplots(self):
150 def getSubplots(self):
153
151
154 nrow = self.nplots
152 nrow = self.nplots
155 ncol = 3
153 ncol = 3
156 return nrow, ncol
154 return nrow, ncol
157
155
158 def setup(self, idfigure, nplots, wintitle):
156 def setup(self, idfigure, nplots, wintitle):
159
157
160 self.createFigure(idfigure, wintitle)
158 self.createFigure(idfigure, wintitle)
161
159
162 nrow,ncol = self.getSubplots()
160 nrow,ncol = self.getSubplots()
163 colspan = 3
161 colspan = 3
164 rowspan = 1
162 rowspan = 1
165
163
166 for i in range(nplots):
164 for i in range(nplots):
167 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
165 self.addAxes(nrow, ncol, i, 0, colspan, rowspan)
168
166
169 self.nplots = nplots
167 self.nplots = nplots
170
168
171 def run(self, dataOut, idfigure, wintitle="", channelList=None,
169 def run(self, dataOut, idfigure, wintitle="", channelList=None,
172 xmin=None, xmax=None, ymin=None, ymax=None):
170 xmin=None, xmax=None, ymin=None, ymax=None):
173
171
174 """
172 """
175
173
176 Input:
174 Input:
177 dataOut :
175 dataOut :
178 idfigure :
176 idfigure :
179 wintitle :
177 wintitle :
180 channelList :
178 channelList :
181 xmin : None,
179 xmin : None,
182 xmax : None,
180 xmax : None,
183 ymin : None,
181 ymin : None,
184 ymax : None,
182 ymax : None,
185 """
183 """
186
184
187 if channelList == None:
185 if channelList == None:
188 channelList = dataOut.channelList
186 channelList = dataOut.channelList
189
187
190 x = dataOut.heightList
188 x = dataOut.heightList
191 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
189 y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:])
192 y = y.real
190 y = y.real
193
191
194 noise = dataOut.getNoise()
192 noise = dataOut.getNoise()
195
193
196 if not self.__isConfig:
194 if not self.__isConfig:
197 nplots = len(channelList)
195 nplots = len(channelList)
198
196
199 self.setup(idfigure=idfigure,
197 self.setup(idfigure=idfigure,
200 nplots=nplots,
198 nplots=nplots,
201 wintitle=wintitle)
199 wintitle=wintitle)
202
200
203 if xmin == None: xmin = numpy.nanmin(x)
201 if xmin == None: xmin = numpy.nanmin(x)
204 if xmax == None: xmax = numpy.nanmax(x)
202 if xmax == None: xmax = numpy.nanmax(x)
205 if ymin == None: ymin = numpy.nanmin(y)
203 if ymin == None: ymin = numpy.nanmin(y)
206 if ymax == None: ymax = numpy.nanmax(y)
204 if ymax == None: ymax = numpy.nanmax(y)
207
205
208 self.__isConfig = True
206 self.__isConfig = True
209
207
210
208
211 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
209 thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime)
212 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
210 title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
213 xlabel = "Range (Km)"
211 xlabel = "Range (Km)"
214 ylabel = "Intensity"
212 ylabel = "Intensity"
215
213
216 self.setWinTitle(title)
214 self.setWinTitle(title)
217
215
218 for i in range(len(self.axesList)):
216 for i in range(len(self.axesList)):
219 title = "Channel %d: %4.2fdB" %(i, noise[i])
217 title = "Channel %d: %4.2fdB" %(i, noise[i])
220 axes = self.axesList[i]
218 axes = self.axesList[i]
221 ychannel = y[i,:]
219 ychannel = y[i,:]
222 axes.pline(x, ychannel,
220 axes.pline(x, ychannel,
223 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
221 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
224 xlabel=xlabel, ylabel=ylabel, title=title)
222 xlabel=xlabel, ylabel=ylabel, title=title)
225
223
226 self.draw()
224 self.draw()
227
225
228
226
229 No newline at end of file
227
General Comments 0
You need to be logged in to leave comments. Login now