@@ -34,20 +34,20 class Figure: | |||
|
34 | 34 | |
|
35 | 35 | raise ValueError, "Abstract method: This method should be defined" |
|
36 | 36 | |
|
37 | def getScreenDim(self): | |
|
37 | def getScreenDim(self, widthplot, heightplot): | |
|
38 | 38 | |
|
39 | 39 | nrow, ncol = self.getSubplots() |
|
40 | 40 | |
|
41 |
width = |
|
|
42 |
height = |
|
|
41 | widthscreen = widthplot*ncol | |
|
42 | heightscreen = heightplot*nrow | |
|
43 | 43 | |
|
44 | return width, height | |
|
44 | return widthscreen, heightscreen | |
|
45 | 45 | |
|
46 | 46 | def init(self, idfigure, nplots, wintitle): |
|
47 | 47 | |
|
48 | 48 | raise ValueError, "This method has been replaced with createFigure" |
|
49 | 49 | |
|
50 | def createFigure(self, idfigure, wintitle): | |
|
50 | def createFigure(self, idfigure, wintitle, widthplot=None, heightplot=None): | |
|
51 | 51 | |
|
52 | 52 | """ |
|
53 | 53 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
@@ -60,16 +60,22 class Figure: | |||
|
60 | 60 | |
|
61 | 61 | """ |
|
62 | 62 | |
|
63 | if widthplot == None: | |
|
64 | widthplot = self.WIDTH | |
|
65 | ||
|
66 | if heightplot == None: | |
|
67 | heightplot = self.HEIGHT | |
|
68 | ||
|
63 | 69 | self.idfigure = idfigure |
|
64 | 70 | |
|
65 | 71 | self.wintitle = wintitle |
|
66 | 72 | |
|
67 | self.width, self.height = self.getScreenDim() | |
|
73 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) | |
|
68 | 74 | |
|
69 | 75 | self.fig = self.__driver.createFigure(self.idfigure, |
|
70 | 76 | self.wintitle, |
|
71 | self.width, | |
|
72 | self.height) | |
|
77 | self.widthscreen, | |
|
78 | self.heightscreen) | |
|
73 | 79 | |
|
74 | 80 | self.axesObjList = [] |
|
75 | 81 | |
@@ -125,12 +131,16 class Axes: | |||
|
125 | 131 | ax = None |
|
126 | 132 | plot = None |
|
127 | 133 | |
|
128 | firsttime = None | |
|
134 | __firsttime = None | |
|
129 | 135 | |
|
130 | 136 | __showprofile = False |
|
131 | 137 | |
|
132 |
|
|
|
133 |
|
|
|
138 | xmin = None | |
|
139 | xmax = None | |
|
140 | ymin = None | |
|
141 | ymax = None | |
|
142 | zmin = None | |
|
143 | zmax = None | |
|
134 | 144 | |
|
135 | 145 | def __init__(self, *args): |
|
136 | 146 | |
@@ -146,7 +156,7 class Axes: | |||
|
146 | 156 | self.ax = ax |
|
147 | 157 | self.plot = None |
|
148 | 158 | |
|
149 | self.firsttime = True | |
|
159 | self.__firsttime = True | |
|
150 | 160 | |
|
151 | 161 | def setText(self, text): |
|
152 | 162 | |
@@ -180,7 +190,7 class Axes: | |||
|
180 | 190 | ytick_visible |
|
181 | 191 | """ |
|
182 | 192 | |
|
183 | if self.firsttime: | |
|
193 | if self.__firsttime: | |
|
184 | 194 | |
|
185 | 195 | if xmin == None: xmin = numpy.nanmin(x) |
|
186 | 196 | if xmax == None: xmax = numpy.nanmax(x) |
@@ -194,7 +204,7 class Axes: | |||
|
194 | 204 | ylabel=ylabel, |
|
195 | 205 | title=title, |
|
196 | 206 | **kwargs) |
|
197 | self.firsttime = False | |
|
207 | self.__firsttime = False | |
|
198 | 208 | return |
|
199 | 209 | |
|
200 | 210 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
@@ -230,7 +240,7 class Axes: | |||
|
230 | 240 | rti = True or False |
|
231 | 241 | """ |
|
232 | 242 | |
|
233 | if self.firsttime: | |
|
243 | if self.__firsttime: | |
|
234 | 244 | |
|
235 | 245 | if xmin == None: xmin = numpy.nanmin(x) |
|
236 | 246 | if xmax == None: xmax = numpy.nanmax(x) |
@@ -248,15 +258,27 class Axes: | |||
|
248 | 258 | ylabel=ylabel, |
|
249 | 259 | title=title, |
|
250 | 260 | **kwargs) |
|
251 | self.firsttime = False | |
|
252 |
if self. |
|
|
253 |
if self. |
|
|
261 | ||
|
262 | if self.xmin == None: self.xmin = xmin | |
|
263 | if self.xmax == None: self.xmax = xmax | |
|
264 | if self.ymin == None: self.ymin = ymin | |
|
265 | if self.ymax == None: self.ymax = ymax | |
|
266 | if self.zmin == None: self.zmin = zmin | |
|
267 | if self.zmax == None: self.zmax = zmax | |
|
268 | ||
|
269 | self.__firsttime = False | |
|
254 | 270 | return |
|
255 | 271 | |
|
256 | 272 | if rti: |
|
257 |
self.__driver.addpcolor(self.ax, x, y, z, self. |
|
|
273 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, | |
|
274 | xlabel=xlabel, | |
|
275 | ylabel=ylabel, | |
|
276 | title=title) | |
|
258 | 277 | return |
|
259 | 278 | |
|
260 |
self.__driver.pcolor(self.plot, z, |
|
|
279 | self.__driver.pcolor(self.plot, z, | |
|
280 | xlabel=xlabel, | |
|
281 | ylabel=ylabel, | |
|
282 | title=title) | |
|
261 | 283 | |
|
262 | 284 | No newline at end of file |
@@ -7,7 +7,9 import matplotlib.dates | |||
|
7 | 7 | #import scitools.numpyutils |
|
8 | 8 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
9 | 9 | |
|
10 |
from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter |
|
|
10 | from matplotlib.dates import DayLocator, HourLocator, MinuteLocator, SecondLocator, DateFormatter | |
|
11 | from matplotlib.ticker import FuncFormatter | |
|
12 | from matplotlib.ticker import * | |
|
11 | 13 | |
|
12 | 14 | def init(idfigure, wintitle, width, height, facecolor="w"): |
|
13 | 15 | |
@@ -200,7 +202,9 def pline(iplot, x, y, xlabel='', ylabel='', title=''): | |||
|
200 | 202 | |
|
201 | 203 | iplot.set_data(x, y) |
|
202 | 204 | |
|
203 |
def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
|
205 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |
|
206 | xlabel='', ylabel='', title='', ticksize = 9, | |
|
207 | cblabel='',XAxisAsTime=False): | |
|
204 | 208 | |
|
205 | 209 | divider = make_axes_locatable(ax) |
|
206 | 210 | ax_cb = divider.new_horizontal(size="4%", pad=0.05) |
@@ -208,19 +212,6 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', yla | |||
|
208 | 212 | fig.add_axes(ax_cb) |
|
209 | 213 | |
|
210 | 214 | ax.set_xlim([xmin,xmax]) |
|
211 | ||
|
212 | if XAxisAsTime: | |
|
213 | seconds = numpy.array([xmin, xmax]) | |
|
214 | datesList = map(datetime.datetime.fromtimestamp, seconds) | |
|
215 | ax.set_xlim([datesList[0],datesList[-1]]) | |
|
216 | ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) | |
|
217 | ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) | |
|
218 | ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) | |
|
219 | xdateList = map(datetime.datetime.fromtimestamp, x) | |
|
220 | xdate = matplotlib.dates.date2num(xdateList) | |
|
221 | x = xdate | |
|
222 | ||
|
223 | ||
|
224 | 215 | ax.set_ylim([ymin,ymax]) |
|
225 | 216 | |
|
226 | 217 | printLabels(ax, xlabel, ylabel, title) |
@@ -231,8 +222,8 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', yla | |||
|
231 | 222 | |
|
232 | 223 | ax_cb.yaxis.tick_right() |
|
233 | 224 | |
|
234 | for tl in ax_cb.get_yticklabels(): | |
|
235 | tl.set_visible(True) | |
|
225 | # for tl in ax_cb.get_yticklabels(): | |
|
226 | # tl.set_visible(True) | |
|
236 | 227 | |
|
237 | 228 | for tick in ax.yaxis.get_major_ticks(): |
|
238 | 229 | tick.label.set_fontsize(ticksize) |
@@ -246,6 +237,29 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, xlabel='', yla | |||
|
246 | 237 | ax_cb.yaxis.tick_right() |
|
247 | 238 | matplotlib.pyplot.tight_layout() |
|
248 | 239 | |
|
240 | if XAxisAsTime: | |
|
241 | ||
|
242 | func = lambda x, pos: ('%s') %(datetime.datetime.fromtimestamp(x).strftime("%H:%M:%S")) | |
|
243 | ax.xaxis.set_major_formatter(FuncFormatter(func)) | |
|
244 | ax.xaxis.set_major_locator(LinearLocator(7)) | |
|
245 | ||
|
246 | # seconds = numpy.array([xmin, xmax]) | |
|
247 | # datesList = map(datetime.datetime.fromtimestamp, seconds) | |
|
248 | # ax.set_xlim([datesList[0],datesList[-1]]) | |
|
249 | # ax.xaxis.set_major_locator(MinuteLocator(numpy.arange(0,61,10))) | |
|
250 | # ax.xaxis.set_minor_locator(SecondLocator(numpy.arange(0,61,60))) | |
|
251 | # ax.xaxis.set_major_formatter(DateFormatter("%H:%M:%S")) | |
|
252 | # xdateList = map(datetime.datetime.fromtimestamp, x) | |
|
253 | # xdate = matplotlib.dates.date2num(xdateList) | |
|
254 | # x = xdate | |
|
255 | ||
|
256 | # labels = [] | |
|
257 | # for item in ax.xaxis.get_ticklabels(): | |
|
258 | # stri = item.get_text() | |
|
259 | # text = datetime.datetime.fromtimestamp(float(stri)) | |
|
260 | # labels.append(text) | |
|
261 | # | |
|
262 | # ax.xaxis.set_ticklabels(labels) | |
|
249 | 263 | return imesh |
|
250 | 264 | |
|
251 | 265 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
@@ -258,11 +272,14 def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |||
|
258 | 272 | |
|
259 | 273 | imesh.set_array(z.ravel()) |
|
260 | 274 | |
|
261 | def addpcolor(ax, x, y, z, zmin, zmax): | |
|
262 | xdateList = map(datetime.datetime.fromtimestamp, x) | |
|
263 | xdate = matplotlib.dates.date2num(xdateList) | |
|
275 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title=''): | |
|
276 | ||
|
277 | # xdateList = map(datetime.datetime.fromtimestamp, x) | |
|
278 | # xdate = matplotlib.dates.date2num(xdateList) | |
|
264 | 279 | |
|
265 | imesh = ax.pcolormesh(xdate,y,z.T,vmin=zmin,vmax=zmax) | |
|
280 | printLabels(ax, xlabel, ylabel, title) | |
|
281 | ||
|
282 | imesh = ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax) | |
|
266 | 283 | |
|
267 | 284 | def draw(fig): |
|
268 | 285 |
@@ -1,5 +1,5 | |||
|
1 | 1 | import numpy |
|
2 | import datetime | |
|
2 | import time, datetime | |
|
3 | 3 | from graphics.figure import * |
|
4 | 4 | |
|
5 | 5 | class RTIPlot(Figure): |
@@ -12,12 +12,12 class RTIPlot(Figure): | |||
|
12 | 12 | |
|
13 | 13 | def __init__(self): |
|
14 | 14 | |
|
15 |
self.__timerange = |
|
|
15 | self.__timerange = 24*60*60 | |
|
16 | 16 | self.__isConfig = False |
|
17 | 17 | self.__nsubplots = 1 |
|
18 | 18 | |
|
19 | 19 | self.WIDTH = 800 |
|
20 |
self.HEIGHT = |
|
|
20 | self.HEIGHT = 300 | |
|
21 | 21 | self.WIDTHPROF = 120 |
|
22 | 22 | self.HEIGHTPROF = 0 |
|
23 | 23 | |
@@ -39,10 +39,11 class RTIPlot(Figure): | |||
|
39 | 39 | ncolspan = 7 |
|
40 | 40 | colspan = 6 |
|
41 | 41 | self.__nsubplots = 2 |
|
42 | self.WIDTH += self.WIDTHPROF | |
|
43 | self.HEIGHT += self.HEIGHTPROF | |
|
44 | 42 | |
|
45 |
self.createFigure(idfigure, |
|
|
43 | self.createFigure(idfigure = idfigure, | |
|
44 | wintitle = wintitle, | |
|
45 | widthplot = self.WIDTH + self.WIDTHPROF, | |
|
46 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
|
46 | 47 | |
|
47 | 48 | nrow, ncol = self.getSubplots() |
|
48 | 49 | |
@@ -60,8 +61,38 class RTIPlot(Figure): | |||
|
60 | 61 | |
|
61 | 62 | counter += 1 |
|
62 | 63 | |
|
64 | def __getTimeLim(self, x, xmin, xmax): | |
|
65 | ||
|
66 | thisdatetime = datetime.datetime.fromtimestamp(numpy.min(x)) | |
|
67 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) | |
|
68 | ||
|
69 | #################################################### | |
|
70 | #If the x is out of xrange | |
|
71 | if xmax < (thisdatetime - thisdate).seconds/(60*60.): | |
|
72 | xmin = None | |
|
73 | xmax = None | |
|
74 | ||
|
75 | if xmin == None: | |
|
76 | td = thisdatetime - thisdate | |
|
77 | xmin = td.seconds/(60*60.) | |
|
78 | ||
|
79 | if xmax == None: | |
|
80 | xmax = xmin + self.__timerange/(60*60.) | |
|
81 | ||
|
82 | mindt = thisdate + datetime.timedelta(0,0,0,0,0, xmin) | |
|
83 | tmin = time.mktime(mindt.timetuple()) | |
|
84 | ||
|
85 | maxdt = thisdate + datetime.timedelta(0,0,0,0,0, xmax) | |
|
86 | tmax = time.mktime(maxdt.timetuple()) | |
|
87 | ||
|
88 | self.__timerange = tmax - tmin | |
|
89 | ||
|
90 | return tmin, tmax | |
|
91 | ||
|
63 | 92 | def run(self, dataOut, idfigure, wintitle="", channelList=None, showprofile='True', |
|
64 |
xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
|
93 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
|
94 | timerange=None, | |
|
95 | save=False, filename=None): | |
|
65 | 96 | |
|
66 | 97 | """ |
|
67 | 98 | |
@@ -88,13 +119,18 class RTIPlot(Figure): | |||
|
88 | 119 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
89 | 120 | channelIndexList.append(channel) |
|
90 | 121 | |
|
122 | if timerange != None: | |
|
123 | self.__timerange = timerange | |
|
124 | ||
|
125 | tmin = None | |
|
126 | tmax = None | |
|
91 | 127 | x = dataOut.getDatatime() |
|
92 | 128 | y = dataOut.getHeiRange() |
|
93 | 129 | z = 10.*numpy.log10(dataOut.data_spc[channelIndexList,:,:]) |
|
94 | 130 | avg = numpy.average(z, axis=1) |
|
95 | 131 | |
|
96 | 132 | noise = dataOut.getNoise() |
|
97 | ||
|
133 | ||
|
98 | 134 | if not self.__isConfig: |
|
99 | 135 | |
|
100 | 136 | nplots = len(channelIndexList) |
@@ -104,8 +140,7 class RTIPlot(Figure): | |||
|
104 | 140 | wintitle=wintitle, |
|
105 | 141 | showprofile=showprofile) |
|
106 | 142 | |
|
107 | if xmin == None: xmin = numpy.min(x) | |
|
108 | if xmax == None: xmax = xmin + self.__timerange | |
|
143 | tmin, tmax = self.__getTimeLim(x, xmin, xmax) | |
|
109 | 144 | if ymin == None: ymin = numpy.nanmin(y) |
|
110 | 145 | if ymax == None: ymax = numpy.nanmax(y) |
|
111 | 146 | if zmin == None: zmin = numpy.nanmin(avg)*0.9 |
@@ -114,18 +149,18 class RTIPlot(Figure): | |||
|
114 | 149 | self.__isConfig = True |
|
115 | 150 | |
|
116 | 151 | thisDatetime = datetime.datetime.fromtimestamp(dataOut.utctime) |
|
117 |
title = " |
|
|
152 | title = "RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
|
118 | 153 | xlabel = "Velocity (m/s)" |
|
119 | 154 | ylabel = "Range (Km)" |
|
120 | 155 | |
|
121 | 156 | self.setWinTitle(title) |
|
122 | 157 | |
|
123 | 158 | for i in range(self.nplots): |
|
124 |
title = "Channel %d: % |
|
|
159 | title = "Channel %d: %s" %(dataOut.channelList[i], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
|
125 | 160 | axes = self.axesList[i*self.__nsubplots] |
|
126 | 161 | z = avg[i].reshape((1,-1)) |
|
127 | 162 | axes.pcolor(x, y, z, |
|
128 |
xmin= |
|
|
163 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
|
129 | 164 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
130 | 165 | ticksize=9, cblabel='') |
|
131 | 166 | |
@@ -141,6 +176,9 class RTIPlot(Figure): | |||
|
141 | 176 | |
|
142 | 177 | if save: |
|
143 | 178 | self.saveFigure(filename) |
|
179 | ||
|
180 | if x[1] + (x[1]-x[0]) >= self.axesList[0].xmax: | |
|
181 | self.__isConfig = False | |
|
144 | 182 | |
|
145 | 183 | class SpectraPlot(Figure): |
|
146 | 184 | |
@@ -178,10 +216,11 class SpectraPlot(Figure): | |||
|
178 | 216 | ncolspan = 3 |
|
179 | 217 | colspan = 2 |
|
180 | 218 | self.__nsubplots = 2 |
|
181 | self.WIDTH += self.WIDTHPROF | |
|
182 | self.HEIGHT += self.HEIGHTPROF | |
|
183 | ||
|
184 | self.createFigure(idfigure, wintitle) | |
|
219 | ||
|
220 | self.createFigure(idfigure = idfigure, | |
|
221 | wintitle = wintitle, | |
|
222 | widthplot = self.WIDTH + self.WIDTHPROF, | |
|
223 | heightplot = self.HEIGHT + self.HEIGHTPROF) | |
|
185 | 224 | |
|
186 | 225 | nrow, ncol = self.getSubplots() |
|
187 | 226 |
General Comments 0
You need to be logged in to leave comments.
Login now