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