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