@@ -1,289 +1,288 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import matplotlib |
|
4 | 4 | matplotlib.use("TKAgg") |
|
5 | 5 | import matplotlib.pyplot |
|
6 | 6 | import matplotlib.dates |
|
7 | 7 | #import scitools.numpyutils |
|
8 | 8 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
9 | 9 | |
|
10 | 10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter |
|
11 | 11 | from matplotlib.ticker import FuncFormatter |
|
12 | 12 | from matplotlib.ticker import * |
|
13 | 13 | |
|
14 | 14 | def init(idfigure, wintitle, width, height, facecolor="w"): |
|
15 | 15 | |
|
16 | 16 | matplotlib.pyplot.ioff() |
|
17 | 17 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
18 | 18 | fig.canvas.manager.set_window_title(wintitle) |
|
19 | 19 | fig.canvas.manager.resize(width, height) |
|
20 | 20 | matplotlib.pyplot.ion() |
|
21 | 21 | |
|
22 | 22 | return fig |
|
23 | 23 | |
|
24 | 24 | def setWinTitle(fig, title): |
|
25 | 25 | |
|
26 | 26 | fig.canvas.manager.set_window_title(title) |
|
27 | 27 | |
|
28 | 28 | def setTitle(idfigure, title): |
|
29 | 29 | fig = matplotlib.pyplot.figure(idfigure) |
|
30 | 30 | fig.suptitle(title) |
|
31 | 31 | |
|
32 | 32 | def makeAxes(idfigure, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
33 | 33 | fig = matplotlib.pyplot.figure(idfigure) |
|
34 | 34 | ax = matplotlib.pyplot.subplot2grid((nrow, ncol), (xpos, ypos), colspan=colspan, rowspan=rowspan) |
|
35 | 35 | return ax |
|
36 | 36 | |
|
37 | 37 | def setTextFromAxes(idfigure, ax, title): |
|
38 | 38 | fig = matplotlib.pyplot.figure(idfigure) |
|
39 | 39 | ax.annotate(title, xy=(.1, .99), |
|
40 | 40 | xycoords='figure fraction', |
|
41 | 41 | horizontalalignment='left', verticalalignment='top', |
|
42 | 42 | fontsize=10) |
|
43 | 43 | |
|
44 | 44 | def pline(ax, x, y, xmin, xmax, ymin, ymax, xlabel, ylabel, title, firsttime): |
|
45 | 45 | |
|
46 | 46 | if firsttime: |
|
47 | 47 | ax.plot(x, y) |
|
48 | 48 | ax.set_xlim([xmin,xmax]) |
|
49 | 49 | ax.set_ylim([ymin,ymax]) |
|
50 | 50 | ax.set_xlabel(xlabel, size=8) |
|
51 | 51 | ax.set_ylabel(ylabel, size=8) |
|
52 | 52 | ax.set_title(title, size=10) |
|
53 | 53 | matplotlib.pyplot.tight_layout() |
|
54 | 54 | else: |
|
55 | 55 | ax.lines[0].set_data(x,y) |
|
56 | 56 | |
|
57 | 57 | def draw(idfigure): |
|
58 | 58 | |
|
59 | 59 | fig = matplotlib.pyplot.figure(idfigure) |
|
60 | 60 | fig.canvas.draw() |
|
61 | 61 | |
|
62 | 62 | def pcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel, ylabel, title, firsttime, mesh): |
|
63 | 63 | |
|
64 | 64 | if firsttime: |
|
65 | 65 | divider = make_axes_locatable(ax) |
|
66 | 66 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
|
67 | 67 | fig1 = ax.get_figure() |
|
68 | 68 | fig1.add_axes(ax_cb) |
|
69 | 69 | |
|
70 | 70 | ax.set_xlim([xmin,xmax]) |
|
71 | 71 | ax.set_ylim([ymin,ymax]) |
|
72 | 72 | ax.set_xlabel(xlabel) |
|
73 | 73 | ax.set_ylabel(ylabel) |
|
74 | 74 | ax.set_title(title) |
|
75 | 75 | print x |
|
76 | 76 | imesh=ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
77 | 77 | matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
78 | 78 | ax_cb.yaxis.tick_right() |
|
79 | 79 | for tl in ax_cb.get_yticklabels(): |
|
80 | 80 | tl.set_visible(True) |
|
81 | 81 | ax_cb.yaxis.tick_right() |
|
82 | 82 | matplotlib.pyplot.tight_layout() |
|
83 | 83 | return imesh |
|
84 | 84 | else: |
|
85 | 85 | # ax.set_xlim([xmin,xmax]) |
|
86 | 86 | # ax.set_ylim([ymin,ymax]) |
|
87 | 87 | ax.set_xlabel(xlabel) |
|
88 | 88 | ax.set_ylabel(ylabel) |
|
89 | 89 | ax.set_title(title) |
|
90 | 90 | |
|
91 | 91 | z = z.T |
|
92 | 92 | # z = z[0:-1,0:-1] |
|
93 | 93 | mesh.set_array(z.ravel()) |
|
94 | 94 | |
|
95 | 95 | return mesh |
|
96 | 96 | |
|
97 | 97 | ########################################### |
|
98 | 98 | #Actualizacion de las funciones del driver |
|
99 | 99 | ########################################### |
|
100 | 100 | |
|
101 | 101 | def createFigure(idfigure, wintitle, width, height, facecolor="w"): |
|
102 | 102 | |
|
103 | 103 | matplotlib.pyplot.ioff() |
|
104 | 104 | fig = matplotlib.pyplot.matplotlib.pyplot.figure(num=idfigure, facecolor=facecolor) |
|
105 | 105 | fig.canvas.manager.set_window_title(wintitle) |
|
106 | 106 | fig.canvas.manager.resize(width, height) |
|
107 | 107 | matplotlib.pyplot.ion() |
|
108 | 108 | |
|
109 | 109 | return fig |
|
110 | 110 | |
|
111 | 111 | def closeFigure(): |
|
112 | 112 | |
|
113 | 113 | matplotlib.pyplot.ioff() |
|
114 | 114 | matplotlib.pyplot.show() |
|
115 | 115 | |
|
116 | 116 | return |
|
117 | 117 | |
|
118 | 118 | def saveFigure(fig, filename): |
|
119 | 119 | fig.savefig(filename) |
|
120 | 120 | |
|
121 | 121 | def setWinTitle(fig, title): |
|
122 | 122 | |
|
123 | 123 | fig.canvas.manager.set_window_title(title) |
|
124 | 124 | |
|
125 | 125 | def setTitle(fig, title): |
|
126 | 126 | |
|
127 | 127 | fig.suptitle(title) |
|
128 | 128 | |
|
129 | 129 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
130 | 130 | |
|
131 | 131 | matplotlib.pyplot.figure(fig.number) |
|
132 | 132 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
133 | 133 | (xpos, ypos), |
|
134 | 134 | colspan=colspan, |
|
135 | 135 | rowspan=rowspan) |
|
136 | 136 | return axes |
|
137 | 137 | |
|
138 | 138 | def setAxesText(ax, text): |
|
139 | 139 | |
|
140 | 140 | ax.annotate(text, |
|
141 | 141 | xy = (.1, .99), |
|
142 | 142 | xycoords = 'figure fraction', |
|
143 | 143 | horizontalalignment = 'left', |
|
144 | 144 | verticalalignment = 'top', |
|
145 | 145 | fontsize = 10) |
|
146 | 146 | |
|
147 | 147 | def printLabels(ax, xlabel, ylabel, title): |
|
148 | 148 | |
|
149 | 149 | ax.set_xlabel(xlabel, size=11) |
|
150 | 150 | ax.set_ylabel(ylabel, size=11) |
|
151 | 151 | ax.set_title(title, size=12) |
|
152 | 152 | |
|
153 | 153 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
154 | 154 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
155 | 155 | nxticks=4, nyticks=10, |
|
156 | 156 | grid=None): |
|
157 | 157 | |
|
158 | 158 | """ |
|
159 | 159 | |
|
160 | 160 | Input: |
|
161 | 161 | grid : None, 'both', 'x', 'y' |
|
162 | 162 | """ |
|
163 | 163 | |
|
164 | 164 | ax.plot(x, y) |
|
165 | 165 | ax.set_xlim([xmin,xmax]) |
|
166 | 166 | ax.set_ylim([ymin,ymax]) |
|
167 | 167 | |
|
168 | 168 | printLabels(ax, xlabel, ylabel, title) |
|
169 | 169 | |
|
170 | 170 | ###################################################### |
|
171 | 171 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/nxticks) + int(xmin) |
|
172 | 172 | ax.set_xticks(xtickspos) |
|
173 | 173 | |
|
174 | 174 | for tick in ax.get_xticklabels(): |
|
175 | 175 | tick.set_visible(xtick_visible) |
|
176 | 176 | |
|
177 | 177 | for tick in ax.xaxis.get_major_ticks(): |
|
178 | 178 | tick.label.set_fontsize(ticksize) |
|
179 | 179 | |
|
180 | 180 | ###################################################### |
|
181 | 181 | for tick in ax.get_yticklabels(): |
|
182 | 182 | tick.set_visible(ytick_visible) |
|
183 | 183 | |
|
184 | 184 | for tick in ax.yaxis.get_major_ticks(): |
|
185 | 185 | tick.label.set_fontsize(ticksize) |
|
186 | 186 | |
|
187 | 187 | ###################################################### |
|
188 | 188 | if grid != None: |
|
189 | 189 | ax.grid(b=True, which='major', axis=grid) |
|
190 | 190 | |
|
191 | 191 | matplotlib.pyplot.tight_layout() |
|
192 | 192 | |
|
193 | 193 | iplot = ax.lines[-1] |
|
194 | 194 | |
|
195 | 195 | return iplot |
|
196 | 196 | |
|
197 | 197 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
198 | 198 | |
|
199 | 199 | ax = iplot.get_axes() |
|
200 | 200 | |
|
201 | 201 | printLabels(ax, xlabel, ylabel, title) |
|
202 | 202 | |
|
203 | 203 | iplot.set_data(x, y) |
|
204 | 204 | |
|
205 | 205 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
206 | 206 | xlabel='', ylabel='', title='', ticksize = 9, |
|
207 |
cblabel='', |
|
|
207 | cblabel='', cbsize="5%", | |
|
208 | XAxisAsTime=False): | |
|
208 | 209 | |
|
209 | 210 | divider = make_axes_locatable(ax) |
|
210 |
ax_cb = divider.new_horizontal(size= |
|
|
211 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) | |
|
211 | 212 | fig = ax.get_figure() |
|
212 | 213 | fig.add_axes(ax_cb) |
|
213 | 214 | |
|
214 | 215 | ax.set_xlim([xmin,xmax]) |
|
215 | 216 | ax.set_ylim([ymin,ymax]) |
|
216 | 217 | |
|
217 | 218 | printLabels(ax, xlabel, ylabel, title) |
|
218 | 219 | |
|
219 | 220 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
220 | 221 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
221 | 222 | cb.set_label(cblabel) |
|
222 | 223 | |
|
223 | ax_cb.yaxis.tick_right() | |
|
224 | ||
|
225 | 224 | # for tl in ax_cb.get_yticklabels(): |
|
226 | 225 | # tl.set_visible(True) |
|
227 | 226 | |
|
228 | 227 | for tick in ax.yaxis.get_major_ticks(): |
|
229 | 228 | tick.label.set_fontsize(ticksize) |
|
230 | 229 | |
|
231 | 230 | for tick in ax.xaxis.get_major_ticks(): |
|
232 | 231 | tick.label.set_fontsize(ticksize) |
|
233 | 232 | |
|
234 | 233 | for tick in cb.ax.get_yticklabels(): |
|
235 | 234 | tick.set_fontsize(ticksize) |
|
236 | 235 | |
|
237 | 236 | ax_cb.yaxis.tick_right() |
|
238 | 237 | matplotlib.pyplot.tight_layout() |
|
239 | 238 | |
|
240 | 239 | if XAxisAsTime: |
|
241 | 240 | |
|
242 | 241 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime("%H:%M:%S")) |
|
243 | 242 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
244 | 243 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
245 | 244 | |
|
246 | 245 | # seconds = numpy.array([xmin, xmax]) |
|
247 | 246 | # datesList = map(datetime.datetime.fromtimestamp, seconds) |
|
248 | 247 | # ax.set_xlim([datesList[0],datesList[-1]]) |
|
249 | 248 | # ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) |
|
250 | 249 | # ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) |
|
251 | 250 | # ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) |
|
252 | 251 | # xdateList = map(datetime.datetime.fromtimestamp, x) |
|
253 | 252 | # xdate = matplotlib.dates.date2num(xdateList) |
|
254 | 253 | # x = xdate |
|
255 | 254 | |
|
256 | 255 | # labels = [] |
|
257 | 256 | # for item in ax.xaxis.get_ticklabels(): |
|
258 | 257 | # stri = item.get_text() |
|
259 | 258 | # text = datetime.datetime.fromtimestamp(float(stri)) |
|
260 | 259 | # labels.append(text) |
|
261 | 260 | # |
|
262 | 261 | # ax.xaxis.set_ticklabels(labels) |
|
263 | 262 | return imesh |
|
264 | 263 | |
|
265 | 264 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
266 | 265 | |
|
267 | 266 | z = z.T |
|
268 | 267 | |
|
269 | 268 | ax = imesh.get_axes() |
|
270 | 269 | |
|
271 | 270 | printLabels(ax, xlabel, ylabel, title) |
|
272 | 271 | |
|
273 | 272 | imesh.set_array(z.ravel()) |
|
274 | 273 | |
|
275 | 274 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''): |
|
276 | 275 | |
|
277 | 276 | # xdateList = map(datetime.datetime.fromtimestamp, x) |
|
278 | 277 | # xdate = matplotlib.dates.date2num(xdateList) |
|
279 | 278 | |
|
280 | 279 | printLabels(ax, xlabel, ylabel, title) |
|
281 | 280 | |
|
282 | 281 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) |
|
283 | 282 | |
|
284 | 283 | def draw(fig): |
|
285 | 284 | |
|
286 | 285 | if type(fig) == 'int': |
|
287 | 286 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
288 | 287 | |
|
289 | 288 | fig.canvas.draw() No newline at end of file |
@@ -1,410 +1,410 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time, datetime |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class RTIPlot(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.__timerange = 24*60*60 |
|
16 | 16 | self.__isConfig = False |
|
17 | 17 | self.__nsubplots = 1 |
|
18 | 18 | |
|
19 | 19 | self.WIDTH = 800 |
|
20 | 20 | self.HEIGHT = 300 |
|
21 | 21 | self.WIDTHPROF = 120 |
|
22 | 22 | self.HEIGHTPROF = 0 |
|
23 | 23 | |
|
24 | 24 | def getSubplots(self): |
|
25 | 25 | |
|
26 | 26 | ncol = 1 |
|
27 | 27 | nrow = self.nplots |
|
28 | 28 | |
|
29 | 29 | return nrow, ncol |
|
30 | 30 | |
|
31 | 31 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
32 | 32 | |
|
33 | 33 | self.__showprofile = showprofile |
|
34 | 34 | self.nplots = nplots |
|
35 | 35 | |
|
36 | 36 | ncolspan = 1 |
|
37 | 37 | colspan = 1 |
|
38 | 38 | if showprofile: |
|
39 | 39 | ncolspan = 7 |
|
40 | 40 | colspan = 6 |
|
41 | 41 | self.__nsubplots = 2 |
|
42 | 42 | |
|
43 | 43 | self.createFigure(idfigure = idfigure, |
|
44 | 44 | wintitle = wintitle, |
|
45 | 45 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
46 | 46 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
47 | 47 | |
|
48 | 48 | nrow, ncol = self.getSubplots() |
|
49 | 49 | |
|
50 | 50 | counter = 0 |
|
51 | 51 | for y in range(nrow): |
|
52 | 52 | for x in range(ncol): |
|
53 | 53 | |
|
54 | 54 | if counter >= self.nplots: |
|
55 | 55 | break |
|
56 | 56 | |
|
57 | 57 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
58 | 58 | |
|
59 | 59 | if showprofile: |
|
60 | 60 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
61 | 61 | |
|
62 | 62 | counter += 1 |
|
63 | 63 | |
|
64 | 64 | def __getTimeLim(self, x, xmin, xmax): |
|
65 | 65 | |
|
66 | 66 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) |
|
67 | 67 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
68 | 68 | |
|
69 | 69 | #################################################### |
|
70 | 70 | #If the x is out of xrange |
|
71 | 71 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
72 | 72 | xmin = None |
|
73 | 73 | xmax = None |
|
74 | 74 | |
|
75 | 75 | if xmin == None: |
|
76 | 76 | td = thisdatetime - thisdate |
|
77 | 77 | xmin = td.seconds/(60*60.) |
|
78 | 78 | |
|
79 | 79 | if xmax == None: |
|
80 | 80 | xmax = xmin + self.__timerange/(60*60.) |
|
81 | 81 | |
|
82 | 82 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) |
|
83 | 83 | tmin = time.mktime(mindt.timetuple()) |
|
84 | 84 | |
|
85 | 85 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) |
|
86 | 86 | tmax = time.mktime(maxdt.timetuple()) |
|
87 | 87 | |
|
88 | 88 | self.__timerange = tmax - tmin |
|
89 | 89 | |
|
90 | 90 | return tmin, tmax |
|
91 | 91 | |
|
92 | 92 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
93 | 93 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
94 | 94 | timerange=None, |
|
95 | 95 | save=False, filename=None): |
|
96 | 96 | |
|
97 | 97 | """ |
|
98 | 98 | |
|
99 | 99 | Input: |
|
100 | 100 | dataOut : |
|
101 | 101 | idfigure : |
|
102 | 102 | wintitle : |
|
103 | 103 | channelList : |
|
104 | 104 | showProfile : |
|
105 | 105 | xmin : None, |
|
106 | 106 | xmax : None, |
|
107 | 107 | ymin : None, |
|
108 | 108 | ymax : None, |
|
109 | 109 | zmin : None, |
|
110 | 110 | zmax : None |
|
111 | 111 | """ |
|
112 | 112 | |
|
113 | 113 | if channelList == None: |
|
114 | 114 | channelIndexList = dataOut.channelIndexList |
|
115 | 115 | else: |
|
116 | 116 | channelIndexList = [] |
|
117 | 117 | for channel in channelList: |
|
118 | 118 | if channel not in dataOut.channelList: |
|
119 | 119 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
120 | 120 | channelIndexList.append(channel) |
|
121 | 121 | |
|
122 | 122 | if timerange != None: |
|
123 | 123 | self.__timerange = timerange |
|
124 | 124 | |
|
125 | 125 | tmin = None |
|
126 | 126 | tmax = None |
|
127 | 127 | x = dataOut.getDatatime() |
|
128 | 128 | y = dataOut.getHeiRange() |
|
129 | 129 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
130 | 130 | avg = numpy.average(z, axis=1) |
|
131 | 131 | |
|
132 | 132 | noise = dataOut.getNoise() |
|
133 | 133 | |
|
134 | 134 | if not self.__isConfig: |
|
135 | 135 | |
|
136 | 136 | nplots = len(channelIndexList) |
|
137 | 137 | |
|
138 | 138 | self.setup(idfigure=idfigure, |
|
139 | 139 | nplots=nplots, |
|
140 | 140 | wintitle=wintitle, |
|
141 | 141 | showprofile=showprofile) |
|
142 | 142 | |
|
143 | 143 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) |
|
144 | 144 | if ymin == None: ymin = numpy.nanmin(y) |
|
145 | 145 | if ymax == None: ymax = numpy.nanmax(y) |
|
146 | 146 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
147 | 147 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
148 | 148 | |
|
149 | 149 | self.__isConfig = True |
|
150 | 150 | |
|
151 | 151 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
152 | 152 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
153 | 153 | xlabel = "Velocity (m/s)" |
|
154 | 154 | ylabel = "Range (Km)" |
|
155 | 155 | |
|
156 | 156 | self.setWinTitle(title) |
|
157 | 157 | |
|
158 | 158 | for i in range(self.nplots): |
|
159 | 159 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
160 | 160 | axes = self.axesList[i*self.__nsubplots] |
|
161 | 161 | z = avg[i].reshape((1,-1)) |
|
162 | 162 | axes.pcolor(x, y, z, |
|
163 | 163 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
164 | 164 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
165 | ticksize=9, cblabel='') | |
|
165 | ticksize=9, cblabel='', cbsize="1%") | |
|
166 | 166 | |
|
167 | 167 | if self.__showprofile: |
|
168 | 168 | axes = self.axesList[i*self.__nsubplots +1] |
|
169 | 169 | axes.pline(avg[i], y, |
|
170 | 170 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
171 | 171 | xlabel='dB', ylabel='', title='', |
|
172 | 172 | ytick_visible=False, |
|
173 | 173 | grid='x') |
|
174 | 174 | |
|
175 | 175 | self.draw() |
|
176 | 176 | |
|
177 | 177 | if save: |
|
178 | 178 | self.saveFigure(filename) |
|
179 | 179 | |
|
180 | 180 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: |
|
181 | 181 | self.__isConfig = False |
|
182 | 182 | |
|
183 | 183 | class SpectraPlot(Figure): |
|
184 | 184 | |
|
185 | 185 | __isConfig = None |
|
186 | 186 | __nsubplots = None |
|
187 | 187 | |
|
188 | 188 | WIDTHPROF = None |
|
189 | 189 | HEIGHTPROF = None |
|
190 | 190 | |
|
191 | 191 | def __init__(self): |
|
192 | 192 | |
|
193 | 193 | self.__isConfig = False |
|
194 | 194 | self.__nsubplots = 1 |
|
195 | 195 | |
|
196 | 196 | self.WIDTH = 300 |
|
197 | 197 | self.HEIGHT = 400 |
|
198 | 198 | self.WIDTHPROF = 120 |
|
199 | 199 | self.HEIGHTPROF = 0 |
|
200 | 200 | |
|
201 | 201 | def getSubplots(self): |
|
202 | 202 | |
|
203 | 203 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
204 | 204 | nrow = int(self.nplots*1./ncol + 0.9) |
|
205 | 205 | |
|
206 | 206 | return nrow, ncol |
|
207 | 207 | |
|
208 | 208 | def setup(self, idfigure, nplots, wintitle, showprofile=True): |
|
209 | 209 | |
|
210 | 210 | self.__showprofile = showprofile |
|
211 | 211 | self.nplots = nplots |
|
212 | 212 | |
|
213 | 213 | ncolspan = 1 |
|
214 | 214 | colspan = 1 |
|
215 | 215 | if showprofile: |
|
216 | 216 | ncolspan = 3 |
|
217 | 217 | colspan = 2 |
|
218 | 218 | self.__nsubplots = 2 |
|
219 | 219 | |
|
220 | 220 | self.createFigure(idfigure = idfigure, |
|
221 | 221 | wintitle = wintitle, |
|
222 | 222 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
223 | 223 | heightplot = self.HEIGHT + self.HEIGHTPROF) |
|
224 | 224 | |
|
225 | 225 | nrow, ncol = self.getSubplots() |
|
226 | 226 | |
|
227 | 227 | counter = 0 |
|
228 | 228 | for y in range(nrow): |
|
229 | 229 | for x in range(ncol): |
|
230 | 230 | |
|
231 | 231 | if counter >= self.nplots: |
|
232 | 232 | break |
|
233 | 233 | |
|
234 | 234 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
235 | 235 | |
|
236 | 236 | if showprofile: |
|
237 | 237 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
238 | 238 | |
|
239 | 239 | counter += 1 |
|
240 | 240 | |
|
241 | 241 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
242 | 242 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, save=False, filename=None): |
|
243 | 243 | |
|
244 | 244 | """ |
|
245 | 245 | |
|
246 | 246 | Input: |
|
247 | 247 | dataOut : |
|
248 | 248 | idfigure : |
|
249 | 249 | wintitle : |
|
250 | 250 | channelList : |
|
251 | 251 | showProfile : |
|
252 | 252 | xmin : None, |
|
253 | 253 | xmax : None, |
|
254 | 254 | ymin : None, |
|
255 | 255 | ymax : None, |
|
256 | 256 | zmin : None, |
|
257 | 257 | zmax : None |
|
258 | 258 | """ |
|
259 | 259 | |
|
260 | 260 | if channelList == None: |
|
261 | 261 | channelIndexList = dataOut.channelIndexList |
|
262 | 262 | else: |
|
263 | 263 | channelIndexList = [] |
|
264 | 264 | for channel in channelList: |
|
265 | 265 | if channel not in dataOut.channelList: |
|
266 | 266 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
267 | 267 | channelIndexList.append(channel) |
|
268 | 268 | |
|
269 | 269 | x = dataOut.getVelRange(1) |
|
270 | 270 | y = dataOut.getHeiRange() |
|
271 | 271 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
272 | 272 | avg = numpy.average(z, axis=1) |
|
273 | 273 | |
|
274 | 274 | noise = dataOut.getNoise() |
|
275 | 275 | |
|
276 | 276 | if not self.__isConfig: |
|
277 | 277 | |
|
278 | 278 | nplots = len(channelIndexList) |
|
279 | 279 | |
|
280 | 280 | self.setup(idfigure=idfigure, |
|
281 | 281 | nplots=nplots, |
|
282 | 282 | wintitle=wintitle, |
|
283 | 283 | showprofile=showprofile) |
|
284 | 284 | |
|
285 | 285 | if xmin == None: xmin = numpy.nanmin(x) |
|
286 | 286 | if xmax == None: xmax = numpy.nanmax(x) |
|
287 | 287 | if ymin == None: ymin = numpy.nanmin(y) |
|
288 | 288 | if ymax == None: ymax = numpy.nanmax(y) |
|
289 | 289 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
|
290 | 290 | if zmax == None: zmax = numpy.nanmax(avg)*0.9 |
|
291 | 291 | |
|
292 | 292 | self.__isConfig = True |
|
293 | 293 | |
|
294 | 294 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
295 | 295 | title = "Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
296 | 296 | xlabel = "Velocity (m/s)" |
|
297 | 297 | ylabel = "Range (Km)" |
|
298 | 298 | |
|
299 | 299 | self.setWinTitle(title) |
|
300 | 300 | |
|
301 | 301 | for i in range(self.nplots): |
|
302 | 302 | title = "Channel %d: %4.2fdB" %(dataOut.channelList[i], noise[i]) |
|
303 | 303 | axes = self.axesList[i*self.__nsubplots] |
|
304 | 304 | axes.pcolor(x, y, z[i,:,:], |
|
305 | 305 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
306 | 306 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
307 | 307 | ticksize=9, cblabel='') |
|
308 | 308 | |
|
309 | 309 | if self.__showprofile: |
|
310 | 310 | axes = self.axesList[i*self.__nsubplots +1] |
|
311 | 311 | axes.pline(avg[i], y, |
|
312 | 312 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
313 | 313 | xlabel='dB', ylabel='', title='', |
|
314 | 314 | ytick_visible=False, |
|
315 | 315 | grid='x') |
|
316 | 316 | |
|
317 | 317 | self.draw() |
|
318 | 318 | |
|
319 | 319 | if save: |
|
320 | 320 | self.saveFigure(filename) |
|
321 | 321 | |
|
322 | 322 | class Scope(Figure): |
|
323 | 323 | |
|
324 | 324 | __isConfig = None |
|
325 | 325 | |
|
326 | 326 | def __init__(self): |
|
327 | 327 | |
|
328 | 328 | self.__isConfig = False |
|
329 | 329 | self.WIDTH = 600 |
|
330 | 330 | self.HEIGHT = 200 |
|
331 | 331 | |
|
332 | 332 | def getSubplots(self): |
|
333 | 333 | |
|
334 | 334 | nrow = self.nplots |
|
335 | 335 | ncol = 3 |
|
336 | 336 | return nrow, ncol |
|
337 | 337 | |
|
338 | 338 | def setup(self, idfigure, nplots, wintitle): |
|
339 | 339 | |
|
340 | 340 | self.createFigure(idfigure, wintitle) |
|
341 | 341 | |
|
342 | 342 | nrow,ncol = self.getSubplots() |
|
343 | 343 | colspan = 3 |
|
344 | 344 | rowspan = 1 |
|
345 | 345 | |
|
346 | 346 | for i in range(nplots): |
|
347 | 347 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
348 | 348 | |
|
349 | 349 | self.nplots = nplots |
|
350 | 350 | |
|
351 | 351 | def run(self, dataOut, idfigure, wintitle="", channelList=None, |
|
352 | 352 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, filename=None): |
|
353 | 353 | |
|
354 | 354 | """ |
|
355 | 355 | |
|
356 | 356 | Input: |
|
357 | 357 | dataOut : |
|
358 | 358 | idfigure : |
|
359 | 359 | wintitle : |
|
360 | 360 | channelList : |
|
361 | 361 | xmin : None, |
|
362 | 362 | xmax : None, |
|
363 | 363 | ymin : None, |
|
364 | 364 | ymax : None, |
|
365 | 365 | """ |
|
366 | 366 | |
|
367 | 367 | if channelList == None: |
|
368 | 368 | channelList = dataOut.channelList |
|
369 | 369 | |
|
370 | 370 | x = dataOut.heightList |
|
371 | 371 | y = dataOut.data[channelList,:] * numpy.conjugate(dataOut.data[channelList,:]) |
|
372 | 372 | y = y.real |
|
373 | 373 | |
|
374 | 374 | noise = dataOut.getNoise() |
|
375 | 375 | |
|
376 | 376 | if not self.__isConfig: |
|
377 | 377 | nplots = len(channelList) |
|
378 | 378 | |
|
379 | 379 | self.setup(idfigure=idfigure, |
|
380 | 380 | nplots=nplots, |
|
381 | 381 | wintitle=wintitle) |
|
382 | 382 | |
|
383 | 383 | if xmin == None: xmin = numpy.nanmin(x) |
|
384 | 384 | if xmax == None: xmax = numpy.nanmax(x) |
|
385 | 385 | if ymin == None: ymin = numpy.nanmin(y) |
|
386 | 386 | if ymax == None: ymax = numpy.nanmax(y) |
|
387 | 387 | |
|
388 | 388 | self.__isConfig = True |
|
389 | 389 | |
|
390 | 390 | |
|
391 | 391 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
392 | 392 | title = "Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
393 | 393 | xlabel = "Range (Km)" |
|
394 | 394 | ylabel = "Intensity" |
|
395 | 395 | |
|
396 | 396 | self.setWinTitle(title) |
|
397 | 397 | |
|
398 | 398 | for i in range(len(self.axesList)): |
|
399 | 399 | title = "Channel %d: %4.2fdB" %(i, noise[i]) |
|
400 | 400 | axes = self.axesList[i] |
|
401 | 401 | ychannel = y[i,:] |
|
402 | 402 | axes.pline(x, ychannel, |
|
403 | 403 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
404 | 404 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
405 | 405 | |
|
406 | 406 | self.draw() |
|
407 | 407 | |
|
408 | 408 | if save: |
|
409 | 409 | self.saveFigure(filename) |
|
410 | 410 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now