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