##// END OF EJS Templates
Modificaciones para hacer graficos RTI en SpectraPlot2
Daniel Valdez -
r131:9470fac491a8
parent child
Show More
@@ -1,167 +1,172
1 import numpy
1 import numpy
2 import sys
2 import schainPlot
3 import schainPlot
3
4
4 class RTIFigure(schainPlot.Figure):
5 class RTIFigure(schainPlot.Figure):
5
6
6 __driverObj = None
7 __driverObj = None
7 __isDriverOpen = False
8 __isDriverOpen = False
8 __isFigureOpen = False
9 __isFigureOpen = False
9 __isConfig = False
10 __isConfig = False
10 __xw = None
11 __xw = None
11 __yw = None
12 __yw = None
12
13
13 xmin = None
14 xmin = None
14 xmax = None
15 xmax = None
15 minvalue = None
16 minvalue = None
16 maxvalue = None
17 maxvalue = None
17
18
18 idfigure = None
19 id = None
19 nframes = None
20 nframes = None
20 wintitle = wintitle
21 wintitle = wintitle
21 colormap = None
22 colormap = None
22 driver = None
23 driver = None
23 overplot = None
24 overplot = None
24
25
25 frameObjList = []
26 frameObjList = []
26
27
27 def __init__(self, idfigure, wintitle, xw=600, yw=800, overplot=0, driver='xwin', colormap='br_green', *showGraphs):
28 def __init__(self, id, wintitle, xw=600, yw=800, overplot=0, driver=None, colormap='br_green', *showGraphs):
28
29
29 self.idfigure = idfigure
30 self.id = id
30 self.wintitle = wintitle
31 self.wintitle = wintitle
31 self.colormap = colormap
32 self.colormap = colormap
32 self.driver = driver
33 self.driver = driver
33 self.overplot = overplot
34 self.overplot = overplot
34
35
35 self.showGraphs = showGraphs
36 self.showGraphs = showGraphs
36
37
37 self.__driverObj = Driver(driver)
38 showColorbar = showGraphs[0]
39 showPowerprofile = showGraphs[1]
40 self.__driverObj = Driver(id, wintitle,xw,yw,overplot,driver,colormap,showColorbar,showPowerprofile)
41
42
38
43
39 def __openDriver(self):
44 def __openDriver(self):
40
45
41 self.__driverObj.openDriver(self.idfigure, self.wintitle, self.xw, self.yw)
46 self.__driverObj.openDriver(self.id, self.wintitle, self.xw, self.yw)
42
47
43 def __openFigure(self):
48 def __openFigure(self):
44
49
45 nrows, ncolumns = self.getSubplots()
50 nrows, ncolumns = self.getSubplots()
46
51
47 self.__driverObj.openFigure()
52 self.__driverObj.openFigure()
48 self.__driverObj.setSubPlots(nrows, ncolumns)
53 self.__driverObj.setSubPlots(nrows, ncolumns)
49
54
50
55
51 def __isOutOfXRange(self, x):
56 def __isOutOfXRange(self, x):
52 pass
57 pass
53
58
54 def __changeXRange(self, x):
59 def __changeXRange(self, x):
55 pass
60 pass
56
61
57 def __createFrames(self):
62 def __createFrames(self):
58
63
59 for frame in range(self.nframes):
64 for frame in range(self.nframes):
60 frameObj = Frame(idframe = frame,
65 frameObj = Frame(idframe = frame,
61 showGraph1 = self.showGraph1,
66 showGraph1 = self.showGraph1,
62 showGraph2 = self.showGraph2
67 showGraph2 = self.showGraph2
63 )
68 )
64
69
65 self.frameObjList.append(frameObj)
70 self.frameObjList.append(frameObj)
66
71
67 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvlaue=None, save=False, gpath='./'):
72 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvlaue=None, save=False, gpath='./'):
68
73
69 nx, ny = data1D.shape
74 nx, ny = data1D.shape
70
75
71 if channelList == None:
76 if channelList == None:
72 chanellList = range(nx)
77 chanellList = range(nx)
73
78
74 if x == None:
79 if x == None:
75 x = numpy.arange(data1D.size)
80 x = numpy.arange(data1D.size)
76
81
77
82
78
83
79
84
80 if not(self.__isDriverOpen):
85 if not(self.__isDriverOpen):
81 self.__openDriver()
86 self.__openDriver()
82 self.__isDriverOpen = True
87 self.__isDriverOpen = True
83
88
84 if not(self.__isConfig):
89 if not(self.__isConfig):
85 if self.xmin == None: xmin = numpy.min(x)
90 if self.xmin == None: xmin = numpy.min(x)
86 if self.xmax == None: xmax = numpy.max(x)
91 if self.xmax == None: xmax = numpy.max(x)
87 if self.minvalue == None: minvalue = numpy.min(data1D)
92 if self.minvalue == None: minvalue = numpy.min(data1D)
88 if self.maxvalue == None: maxvalue = numpy.max(data1D)
93 if self.maxvalue == None: maxvalue = numpy.max(data1D)
89
94
90 self.__createFrames()
95 self.__createFrames()
91 self.__isConfig = True
96 self.__isConfig = True
92
97
93
98
94 if not(self.__isOutOfXRange(x)):
99 if not(self.__isOutOfXRange(x)):
95 self.__changeXRange(x)
100 self.__changeXRange(x)
96
101
97 if self.__isFigureOpen:
102 if self.__isFigureOpen:
98 self.__driverObj.closePage()
103 self.__driverObj.closePage()
99 self.__isFigureOpen = False
104 self.__isFigureOpen = False
100
105
101 if not(self.__isFigureOpen):
106 if not(self.__isFigureOpen):
102 self.__openFigure()
107 self.__openFigure()
103
108
104 for channel in channelList:
109 for channel in channelList:
105 frameObj = self.frameObjList[channel]
110 frameObj = self.frameObjList[channel]
106 frameObj.init(xmin=xmin,
111 frameObj.init(xmin=xmin,
107 xmax=xmax,
112 xmax=xmax,
108 minvalue=minvalue,
113 minvalue=minvalue,
109 maxvalue=maxvalue)
114 maxvalue=maxvalue)
110
115
111 self.__isFigureOpen = True
116 self.__isFigureOpen = True
112
117
113
118
114 for channel in channelList:
119 for channel in channelList:
115 dataCh = data1D[channel]
120 dataCh = data1D[channel]
116 frameObj = self.frameObjList[channel]
121 frameObj = self.frameObjList[channel]
117
122
118 frameObj.clearData()
123 frameObj.clearData()
119 frameObj.plot(dataCh)
124 frameObj.plot(dataCh)
120
125
121 frameObj.refresh()
126 frameObj.refresh()
122
127
123 if not(self.overplot):
128 if not(self.overplot):
124 self.__driverObj.closeFigure()
129 self.__driverObj.closeFigure()
125 self.__isFigureOpen = False
130 self.__isFigureOpen = False
126
131
127
132
128 def plot2DArray(self, x, y, data2D, xmin=None, xmax=None, ymin=None, ymax=None, minvalue=None, maxvalue=None, save=False, gpath='./'):
133 def plot2DArray(self, x, y, data2D, xmin=None, xmax=None, ymin=None, ymax=None, minvalue=None, maxvalue=None, save=False, gpath='./'):
129
134
130 if not(self.__isCOpen):
135 if not(self.__isCOpen):
131 self.__createFrames()
136 self.__createFrames()
132 self.__openFigure()
137 self.__openFigure()
133 self.__isOpen = True
138 self.__isOpen = True
134
139
135 if not(self.__isConfig):
140 if not(self.__isConfig):
136 self.setRange(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, minvalue=minvalue, maxvalue=maxvalue)
141 self.setRange(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, minvalue=minvalue, maxvalue=maxvalue)
137
142
138 self.__isConfig = True
143 self.__isConfig = True
139
144
140 for channel in channelList:
145 for channel in channelList:
141 dataCh = dataArray[channel]
146 dataCh = dataArray[channel]
142 frameObj = frameObjList[channel]
147 frameObj = frameObjList[channel]
143 frameObj.plot(dataCh)
148 frameObj.plot(dataCh)
144
149
145 def saveFigure(self, filename):
150 def saveFigure(self, filename):
146 pass
151 pass
147
152
148
153
149 def getSubplots(self):
154 def getSubplots(self):
150
155
151 raise ValueError, ''
156 raise ValueError, ''
152
157
153 class RTIFrame(schainPlot.Frame):
158 class RTIFrame(schainPlot.Frame):
154
159
155 def __init__(self):
160 def __init__(self):
156 pass
161 pass
157
162
158 def setup(self):
163 def setup(self):
159 pass
164 pass
160
165
161 class RTIPlot(schainPlot.Plot):
166 class RTIPlot(schainPlot.Plot):
162
167
163 def __init__(self):
168 def __init__(self):
164 pass
169 pass
165
170
166 def setup(self):
171 def setup(self):
167 pass No newline at end of file
172 pass
@@ -1,468 +1,487
1 import plplot
1 import plplot
2 import numpy
2 import numpy
3 import sys
3 import sys
4
4
5 class Driver:
5 class PlplotDriver:
6
6
7 __isDriverOpen = False
7 __isDriverOpen = False
8
8
9 def __init__(self, driver=plplot):
9 def __init__(self, id=None, driver=None, wintitle, overplot, colormap, showGraph1, showGraph2):
10
10
11 self.idStream = idStream
11 if id == None:
12 self.nFrames = nFrames
12 raise ValueError, 'id input must be defined'
13 self.winTitle = winTitle
13
14 self.colormap = colormap
14 if driver == None:
15 if sys.platform == "linux":
16 driver = ""
17 elif sys.platform == "darwin":
18 driver = ""
19 else:
20 driver = ""
21
22 self.id = id
15 self.driver = driver
23 self.driver = driver
16
24
25
26 self.nFrames = nFrames
27 self.wintitle = wintitle
28 self.colormap = colormap
17 self.showGraph1 = showGraph1
29 self.showGraph1 = showGraph1
18 self.showGraph2 = showGraph2
30 self.showGraph2 = showGraph2
19
31
20 self.overplot = overplot
32 self.overplot = overplot
21
33
22 def configDriver(self):
34 def configDriver(self):
35 if self.driver == "":
36 import plplot
23
37
24 pass
38 pass
25
39
26 def openDriver(self):
40 def openDriver(self):
27
41
28 pass
42 pass
29
43
30 def closeDriver(self):
44 def closeDriver(self):
31
45
32 pass
46 pass
33
47
34 def openPage(self):
48 def openPage(self):
35 pass
49 pass
36
50
37 def closePage(self):
51 def closePage(self):
38
52
39 pass
53 pass
40
54
41 def setColorMap(self):
55 def setColorMap(self):
42
56
43 pass
57 pass
44
58
45 def setBox(self):
59 def setBox(self):
46
60
47 pass
61 pass
48
62
49 def refreshBox(self):
63 def refreshBox(self):
50
64
51 pass
65 pass
52
66
53 def save(self):
67 def save(self):
54
68
55 pass
69 pass
56
70
57 def show(self):
71 def show(self):
58
72
59 pass
73 pass
60
74
61 def colorbarPlot(self):
75 def colorbarPlot(self):
62
76
63 pass
77 pass
64
78
65 def linePlot(self):
79 def linePlot(self):
66
80
67 pass
81 pass
68
82
69 def pcolorPlot(self):
83 def pcolorPlot(self):
70
84
71 pass
85 pass
72
86
73 def setLabels(self):
87 def setLabels(self):
74
88
75 pass
89 pass
76
90
77 def figure(self):
91 def figure(self):
78
92
79 pass
93 pass
80
94
81 def setSubPlots(self):
95 def setSubPlots(self):
82
96
83 pass
97 pass
84
98
85
99
86 def config_driver(idStream, wintitle, width, height):
100
87 plplot.plsstrm(idStream)
101 class MplDriver:
102 def __init__(self):
103 pass
104
105 def config_driver(id, wintitle, width, height):
106 plplot.plsstrm(id)
88 plplot.plparseopts([wintitle],plplot.PL_PARSE_FULL)
107 plplot.plparseopts([wintitle],plplot.PL_PARSE_FULL)
89 plplot.plsetopt("geometry", "%dx%d"%(width,height))
108 plplot.plsetopt("geometry", "%dx%d"%(width,height))
90
109
91 def ini_driver(driver):
110 def ini_driver(driver):
92 if sys.platform == "darwin":
111 if sys.platform == "darwin":
93 plplot.plsdev("xwin")
112 plplot.plsdev("xwin")
94 if sys.platform == "linux":
113 if sys.platform == "linux":
95 plplot.plsdev("xcairo")
114 plplot.plsdev("xcairo")
96 plplot.plscolbg(255,255,255)
115 plplot.plscolbg(255,255,255)
97 plplot.plscol0(1,0,0,0)
116 plplot.plscol0(1,0,0,0)
98 plplot.plinit()
117 plplot.plinit()
99 plplot.plspause(False)
118 plplot.plspause(False)
100
119
101 def set_subpages(ncol,nrow):
120 def set_subpages(ncol,nrow):
102 plplot.plssub(ncol,nrow)
121 plplot.plssub(ncol,nrow)
103
122
104 def cmap1_init(colormap="gray"):
123 def cmap1_init(colormap="gray"):
105
124
106 if colormap == None:
125 if colormap == None:
107 return
126 return
108
127
109 ncolor = None
128 ncolor = None
110 rgb_lvl = None
129 rgb_lvl = None
111
130
112 # Routine for defining a specific color map 1 in HLS space.
131 # Routine for defining a specific color map 1 in HLS space.
113 # if gray is true, use basic grayscale variation from half-dark to light.
132 # if gray is true, use basic grayscale variation from half-dark to light.
114 # otherwise use false color variation from blue (240 deg) to red (360 deg).
133 # otherwise use false color variation from blue (240 deg) to red (360 deg).
115
134
116 # Independent variable of control points.
135 # Independent variable of control points.
117 i = numpy.array((0., 1.))
136 i = numpy.array((0., 1.))
118 if colormap=="gray":
137 if colormap=="gray":
119 ncolor = 256
138 ncolor = 256
120 # Hue for control points. Doesn't matter since saturation is zero.
139 # Hue for control points. Doesn't matter since saturation is zero.
121 h = numpy.array((0., 0.))
140 h = numpy.array((0., 0.))
122 # Lightness ranging from half-dark (for interest) to light.
141 # Lightness ranging from half-dark (for interest) to light.
123 l = numpy.array((0.5, 1.))
142 l = numpy.array((0.5, 1.))
124 # Gray scale has zero saturation
143 # Gray scale has zero saturation
125 s = numpy.array((0., 0.))
144 s = numpy.array((0., 0.))
126
145
127 # number of cmap1 colours is 256 in this case.
146 # number of cmap1 colours is 256 in this case.
128 plplot.plscmap1n(ncolor)
147 plplot.plscmap1n(ncolor)
129 # Interpolate between control points to set up cmap1.
148 # Interpolate between control points to set up cmap1.
130 plplot.plscmap1l(0, i, h, l, s)
149 plplot.plscmap1l(0, i, h, l, s)
131
150
132 return None
151 return None
133
152
134 if colormap == 'jet':
153 if colormap == 'jet':
135 ncolor = 256
154 ncolor = 256
136 pos = numpy.zeros((ncolor))
155 pos = numpy.zeros((ncolor))
137 r = numpy.zeros((ncolor))
156 r = numpy.zeros((ncolor))
138 g = numpy.zeros((ncolor))
157 g = numpy.zeros((ncolor))
139 b = numpy.zeros((ncolor))
158 b = numpy.zeros((ncolor))
140
159
141 for i in range(ncolor):
160 for i in range(ncolor):
142 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
161 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
143 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
162 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
144 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
163 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
145 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
164 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
146
165
147 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
166 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
148 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
167 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
149 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
168 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
150 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
169 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
151 else: gf = 0.0
170 else: gf = 0.0
152
171
153 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
172 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
154 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
173 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
155 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
174 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
156 else: bf = 0
175 else: bf = 0
157
176
158 r[i] = rf
177 r[i] = rf
159 g[i] = gf
178 g[i] = gf
160 b[i] = bf
179 b[i] = bf
161
180
162 pos[i] = float(i)/float(ncolor-1)
181 pos[i] = float(i)/float(ncolor-1)
163
182
164
183
165 plplot.plscmap1n(ncolor)
184 plplot.plscmap1n(ncolor)
166 plplot.plscmap1l(1, pos, r, g, b)
185 plplot.plscmap1l(1, pos, r, g, b)
167
186
168
187
169
188
170 if colormap=="br_green":
189 if colormap=="br_green":
171 ncolor = 256
190 ncolor = 256
172 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
191 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
173 h = numpy.array((240., 0.))
192 h = numpy.array((240., 0.))
174 # Lightness and saturation are constant (values taken from C example).
193 # Lightness and saturation are constant (values taken from C example).
175 l = numpy.array((0.6, 0.6))
194 l = numpy.array((0.6, 0.6))
176 s = numpy.array((0.8, 0.8))
195 s = numpy.array((0.8, 0.8))
177
196
178 # number of cmap1 colours is 256 in this case.
197 # number of cmap1 colours is 256 in this case.
179 plplot.plscmap1n(ncolor)
198 plplot.plscmap1n(ncolor)
180 # Interpolate between control points to set up cmap1.
199 # Interpolate between control points to set up cmap1.
181 plplot.plscmap1l(0, i, h, l, s)
200 plplot.plscmap1l(0, i, h, l, s)
182
201
183 return None
202 return None
184
203
185 if colormap=="tricolor":
204 if colormap=="tricolor":
186 ncolor = 3
205 ncolor = 3
187 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
206 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
188 h = numpy.array((240., 0.))
207 h = numpy.array((240., 0.))
189 # Lightness and saturation are constant (values taken from C example).
208 # Lightness and saturation are constant (values taken from C example).
190 l = numpy.array((0.6, 0.6))
209 l = numpy.array((0.6, 0.6))
191 s = numpy.array((0.8, 0.8))
210 s = numpy.array((0.8, 0.8))
192
211
193 # number of cmap1 colours is 256 in this case.
212 # number of cmap1 colours is 256 in this case.
194 plplot.plscmap1n(ncolor)
213 plplot.plscmap1n(ncolor)
195 # Interpolate between control points to set up cmap1.
214 # Interpolate between control points to set up cmap1.
196 plplot.plscmap1l(0, i, h, l, s)
215 plplot.plscmap1l(0, i, h, l, s)
197
216
198 return None
217 return None
199
218
200 if colormap == 'rgb' or colormap == 'rgb666':
219 if colormap == 'rgb' or colormap == 'rgb666':
201
220
202 color_sz = 6
221 color_sz = 6
203 ncolor = color_sz*color_sz*color_sz
222 ncolor = color_sz*color_sz*color_sz
204 pos = numpy.zeros((ncolor))
223 pos = numpy.zeros((ncolor))
205 r = numpy.zeros((ncolor))
224 r = numpy.zeros((ncolor))
206 g = numpy.zeros((ncolor))
225 g = numpy.zeros((ncolor))
207 b = numpy.zeros((ncolor))
226 b = numpy.zeros((ncolor))
208 ind = 0
227 ind = 0
209 for ri in range(color_sz):
228 for ri in range(color_sz):
210 for gi in range(color_sz):
229 for gi in range(color_sz):
211 for bi in range(color_sz):
230 for bi in range(color_sz):
212 r[ind] = ri/(color_sz-1.0)
231 r[ind] = ri/(color_sz-1.0)
213 g[ind] = gi/(color_sz-1.0)
232 g[ind] = gi/(color_sz-1.0)
214 b[ind] = bi/(color_sz-1.0)
233 b[ind] = bi/(color_sz-1.0)
215 pos[ind] = ind/(ncolor-1.0)
234 pos[ind] = ind/(ncolor-1.0)
216 ind += 1
235 ind += 1
217 rgb_lvl = [6,6,6] #Levels for RGB colors
236 rgb_lvl = [6,6,6] #Levels for RGB colors
218
237
219 if colormap == 'rgb676':
238 if colormap == 'rgb676':
220 ncolor = 6*7*6
239 ncolor = 6*7*6
221 pos = numpy.zeros((ncolor))
240 pos = numpy.zeros((ncolor))
222 r = numpy.zeros((ncolor))
241 r = numpy.zeros((ncolor))
223 g = numpy.zeros((ncolor))
242 g = numpy.zeros((ncolor))
224 b = numpy.zeros((ncolor))
243 b = numpy.zeros((ncolor))
225 ind = 0
244 ind = 0
226 for ri in range(8):
245 for ri in range(8):
227 for gi in range(8):
246 for gi in range(8):
228 for bi in range(4):
247 for bi in range(4):
229 r[ind] = ri/(6-1.0)
248 r[ind] = ri/(6-1.0)
230 g[ind] = gi/(7-1.0)
249 g[ind] = gi/(7-1.0)
231 b[ind] = bi/(6-1.0)
250 b[ind] = bi/(6-1.0)
232 pos[ind] = ind/(ncolor-1.0)
251 pos[ind] = ind/(ncolor-1.0)
233 ind += 1
252 ind += 1
234 rgb_lvl = [6,7,6] #Levels for RGB colors
253 rgb_lvl = [6,7,6] #Levels for RGB colors
235
254
236 if colormap == 'rgb685':
255 if colormap == 'rgb685':
237 ncolor = 6*8*5
256 ncolor = 6*8*5
238 pos = numpy.zeros((ncolor))
257 pos = numpy.zeros((ncolor))
239 r = numpy.zeros((ncolor))
258 r = numpy.zeros((ncolor))
240 g = numpy.zeros((ncolor))
259 g = numpy.zeros((ncolor))
241 b = numpy.zeros((ncolor))
260 b = numpy.zeros((ncolor))
242 ind = 0
261 ind = 0
243 for ri in range(8):
262 for ri in range(8):
244 for gi in range(8):
263 for gi in range(8):
245 for bi in range(4):
264 for bi in range(4):
246 r[ind] = ri/(6-1.0)
265 r[ind] = ri/(6-1.0)
247 g[ind] = gi/(8-1.0)
266 g[ind] = gi/(8-1.0)
248 b[ind] = bi/(5-1.0)
267 b[ind] = bi/(5-1.0)
249 pos[ind] = ind/(ncolor-1.0)
268 pos[ind] = ind/(ncolor-1.0)
250 ind += 1
269 ind += 1
251 rgb_lvl = [6,8,5] #Levels for RGB colors
270 rgb_lvl = [6,8,5] #Levels for RGB colors
252
271
253 if colormap == 'rgb884':
272 if colormap == 'rgb884':
254 ncolor = 8*8*4
273 ncolor = 8*8*4
255 pos = numpy.zeros((ncolor))
274 pos = numpy.zeros((ncolor))
256 r = numpy.zeros((ncolor))
275 r = numpy.zeros((ncolor))
257 g = numpy.zeros((ncolor))
276 g = numpy.zeros((ncolor))
258 b = numpy.zeros((ncolor))
277 b = numpy.zeros((ncolor))
259 ind = 0
278 ind = 0
260 for ri in range(8):
279 for ri in range(8):
261 for gi in range(8):
280 for gi in range(8):
262 for bi in range(4):
281 for bi in range(4):
263 r[ind] = ri/(8-1.0)
282 r[ind] = ri/(8-1.0)
264 g[ind] = gi/(8-1.0)
283 g[ind] = gi/(8-1.0)
265 b[ind] = bi/(4-1.0)
284 b[ind] = bi/(4-1.0)
266 pos[ind] = ind/(ncolor-1.0)
285 pos[ind] = ind/(ncolor-1.0)
267 ind += 1
286 ind += 1
268 rgb_lvl = [8,8,4] #Levels for RGB colors
287 rgb_lvl = [8,8,4] #Levels for RGB colors
269
288
270 if ncolor == None:
289 if ncolor == None:
271 raise ValueError, "The colormap selected is not valid"
290 raise ValueError, "The colormap selected is not valid"
272
291
273 plplot.plscmap1n(ncolor)
292 plplot.plscmap1n(ncolor)
274 plplot.plscmap1l(1, pos, r, g, b)
293 plplot.plscmap1l(1, pos, r, g, b)
275
294
276 return rgb_lvl
295 return rgb_lvl
277
296
278 def set_colormap(colormap="jet"):
297 def set_colormap(colormap="jet"):
279 cmap1_init(colormap)
298 cmap1_init(colormap)
280
299
281 def save_figure(filename,width,height):
300 def save_figure(filename,width,height):
282 curr_strm = plplot.plgstrm()
301 curr_strm = plplot.plgstrm()
283 save_strm = plplot.plmkstrm()
302 save_strm = plplot.plmkstrm()
284 plplot.plsetopt("geometry", "%dx%d"%(width,height))
303 plplot.plsetopt("geometry", "%dx%d"%(width,height))
285 if sys.platform == "darwin":
304 if sys.platform == "darwin":
286 plplot.plsdev("png")
305 plplot.plsdev("png")
287 if sys.platform == "linux":
306 if sys.platform == "linux":
288 plplot.plsdev("pngcairo")
307 plplot.plsdev("pngcairo")
289 plplot.plsfnam(filename)
308 plplot.plsfnam(filename)
290 plplot.plcpstrm(curr_strm,0)
309 plplot.plcpstrm(curr_strm,0)
291 plplot.plreplot()
310 plplot.plreplot()
292 plplot.plend1()
311 plplot.plend1()
293 plplot.plsstrm(curr_strm)
312 plplot.plsstrm(curr_strm)
294
313
295 def set_new_figure():
314 def set_new_figure():
296 plplot.plbop()
315 plplot.plbop()
297 plplot.pladv(0)
316 plplot.pladv(0)
298
317
299 def close_figure():
318 def close_figure():
300 plplot.pleop()
319 plplot.pleop()
301
320
302 def set_strm(indexPlot):
321 def set_strm(indexPlot):
303 plplot.plsstrm(indexPlot)
322 plplot.plsstrm(indexPlot)
304
323
305 def refresh():
324 def refresh():
306 plplot.plflush()
325 plplot.plflush()
307
326
308 def show():
327 def show():
309 plplot.plspause(True)
328 plplot.plspause(True)
310 plplot.plend()
329 plplot.plend()
311
330
312 def set_title(pltitle,color, szchar=0.7):
331 def set_title(pltitle,color, szchar=0.7):
313 setSubpages(1, 0)
332 setSubpages(1, 0)
314 plplot.pladv(0)
333 plplot.pladv(0)
315 plplot.plvpor(0., 1., 0., 1.)
334 plplot.plvpor(0., 1., 0., 1.)
316
335
317 if color == "black":
336 if color == "black":
318 plplot.plcol0(1)
337 plplot.plcol0(1)
319 if color == "white":
338 if color == "white":
320 plplot.plcol0(15)
339 plplot.plcol0(15)
321
340
322 plplot.plschr(0.0,szchar)
341 plplot.plschr(0.0,szchar)
323 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
342 plplot.plmtex("t",-1., 0.5, 0.5, pltitle)
324
343
325 def set_line_style(style):
344 def set_line_style(style):
326 plplot.pllsty(style)
345 plplot.pllsty(style)
327
346
328 def set_color(color):
347 def set_color(color):
329 plplot.plcol0(color)
348 plplot.plcol0(color)
330
349
331 def set_labels(xlabel, ylabel, title):
350 def set_labels(xlabel, ylabel, title):
332 plplot.pllab(xlabel, ylabel, title)
351 plplot.pllab(xlabel, ylabel, title)
333
352
334 def box(subplot, xpos, ypos, xmin, xmax, ymin, ymax, xopt, yopt, szchar, xaxisastime, timefmt="%H:%M"):
353 def box(subplot, xpos, ypos, xmin, xmax, ymin, ymax, xopt, yopt, szchar, xaxisastime, timefmt="%H:%M"):
335 plplot.pladv(subplot)
354 plplot.pladv(subplot)
336 plplot.plschr(0.0,szchar-0.05)
355 plplot.plschr(0.0,szchar-0.05)
337 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
356 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
338 plplot.plwind(float(xmin),
357 plplot.plwind(float(xmin),
339 float(xmax),
358 float(xmax),
340 float(ymin),
359 float(ymin),
341 float(ymax)
360 float(ymax)
342 )
361 )
343 if xaxisastime:
362 if xaxisastime:
344 plplot.pltimefmt(timefmt)
363 plplot.pltimefmt(timefmt)
345 timedelta = (xmax - xmin + 1)/8.
364 timedelta = (xmax - xmin + 1)/8.
346 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
365 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
347 else:
366 else:
348 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
367 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
349
368
350 def colorbar(xmin=0., xmax=1., ymin=0., ymax=1.):
369 def colorbar(xmin=0., xmax=1., ymin=0., ymax=1.):
351 data = numpy.arange(256)
370 data = numpy.arange(256)
352 data = numpy.reshape(data, (1,-1))
371 data = numpy.reshape(data, (1,-1))
353
372
354 plplot.plimage(data,
373 plplot.plimage(data,
355 float(xmin),
374 float(xmin),
356 float(xmax),
375 float(xmax),
357 float(ymin),
376 float(ymin),
358 float(ymax),
377 float(ymax),
359 0.,
378 0.,
360 255.,
379 255.,
361 float(xmin),
380 float(xmin),
362 float(xmax),
381 float(xmax),
363 float(ymin),
382 float(ymin),
364 float(ymax))
383 float(ymax))
365
384
366 def basicline_timeplot(x, y,colline=1):
385 def basicline_timeplot(x, y,colline=1):
367 plplot.plcol0(colline)
386 plplot.plcol0(colline)
368 plplot.plline(x, y)
387 plplot.plline(x, y)
369 plplot.plcol0(1)
388 plplot.plcol0(1)
370
389
371 def basic_xy_plot(x, y):
390 def basic_xy_plot(x, y):
372 plplot.plline(x, y)
391 plplot.plline(x, y)
373
392
374 def basic_pcolor_plot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
393 def basic_pcolor_plot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None):
375 """
394 """
376 """
395 """
377 if xmin == None: xmin = x[0]
396 if xmin == None: xmin = x[0]
378 if xmax == None: xmax = x[-1]
397 if xmax == None: xmax = x[-1]
379 if ymin == None: ymin = y[0]
398 if ymin == None: ymin = y[0]
380 if ymax == None: ymax = y[-1]
399 if ymax == None: ymax = y[-1]
381 if zmin == None: zmin = numpy.nanmin(data)
400 if zmin == None: zmin = numpy.nanmin(data)
382 if zmax == None: zmax = numpy.nanmax(data)
401 if zmax == None: zmax = numpy.nanmax(data)
383
402
384 plplot.plimage(data,
403 plplot.plimage(data,
385 float(x[0]),
404 float(x[0]),
386 float(x[-1]),
405 float(x[-1]),
387 float(y[0]),
406 float(y[0]),
388 float(y[-1]),
407 float(y[-1]),
389 float(zmin),
408 float(zmin),
390 float(zmax),
409 float(zmax),
391 float(xmin),
410 float(xmin),
392 float(xmax),
411 float(xmax),
393 float(ymin),
412 float(ymin),
394 float(ymax)
413 float(ymax)
395 )
414 )
396
415
397 def image_plot(self,x,y,z,xrange,yrange,zrange):
416 def image_plot(self,x,y,z,xrange,yrange,zrange):
398 xi = x[0]
417 xi = x[0]
399 xf = x[-1]
418 xf = x[-1]
400 yi = y[0]
419 yi = y[0]
401 yf = y[-1]
420 yf = y[-1]
402
421
403 plplot.plimage(z,
422 plplot.plimage(z,
404 float(xi),
423 float(xi),
405 float(xf),
424 float(xf),
406 float(yi),
425 float(yi),
407 float(yf),
426 float(yf),
408 float(zrange[0]),
427 float(zrange[0]),
409 float(zrange[1]),
428 float(zrange[1]),
410 float(xi),
429 float(xi),
411 float(xf),
430 float(xf),
412 float(yrange[0]),
431 float(yrange[0]),
413 yrange[1])
432 yrange[1])
414
433
415 def adv_pcolor_plot(data, x, y, xg, yg, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0.):
434 def adv_pcolor_plot(data, x, y, xg, yg, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0.):
416 plplot.plimagefr(data,
435 plplot.plimagefr(data,
417 float(xmin),
436 float(xmin),
418 float(xmax),
437 float(xmax),
419 float(ymin),
438 float(ymin),
420 float(ymax),
439 float(ymax),
421 0.,
440 0.,
422 0.,
441 0.,
423 float(zmin),
442 float(zmin),
424 float(zmax),
443 float(zmax),
425 plplot.pltr2,
444 plplot.pltr2,
426 xg,
445 xg,
427 yg)
446 yg)
428
447
429 #------------------------------------
448 #------------------------------------
430
449
431 #def get_grid(x, y, deltax=None, deltay=None):
450 #def get_grid(x, y, deltax=None, deltay=None):
432 #
451 #
433 # if not(len(x)>0 and len(y)>0):
452 # if not(len(x)>0 and len(y)>0):
434 # raise ValueError, "x axis and y axis are empty"
453 # raise ValueError, "x axis and y axis are empty"
435 #
454 #
436 # if deltax == None: deltax = x[-1] - x[-2]
455 # if deltax == None: deltax = x[-1] - x[-2]
437 # if deltay == None: deltay = y[-1] - y[-2]
456 # if deltay == None: deltay = y[-1] - y[-2]
438 #
457 #
439 # x1 = numpy.append(x, x[-1] + deltax)
458 # x1 = numpy.append(x, x[-1] + deltax)
440 # y1 = numpy.append(y, y[-1] + deltay)
459 # y1 = numpy.append(y, y[-1] + deltay)
441 #
460 #
442 # xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
461 # xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
443 # yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
462 # yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
444 #
463 #
445 # self.__xg = xg
464 # self.__xg = xg
446 # self.__yg = yg
465 # self.__yg = yg
447 #
466 #
448 # return xg, yg
467 # return xg, yg
449 #
468 #
450 #def advPcolorPlot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
469 #def advPcolorPlot(data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=0., zmax=0., deltax=1.0, deltay=None, getGrid = True):
451 # if getGrid:
470 # if getGrid:
452 # xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
471 # xg, yg = self.__getBoxpltr(x, y, deltax, deltay)
453 # else:
472 # else:
454 # xg = self.__xg
473 # xg = self.__xg
455 # yg = self.__yg
474 # yg = self.__yg
456 #
475 #
457 # plplot.plimagefr(data,
476 # plplot.plimagefr(data,
458 # float(xmin),
477 # float(xmin),
459 # float(xmax),
478 # float(xmax),
460 # float(ymin),
479 # float(ymin),
461 # float(ymax),
480 # float(ymax),
462 # 0.,
481 # 0.,
463 # 0.,
482 # 0.,
464 # float(zmin),
483 # float(zmin),
465 # float(zmax),
484 # float(zmax),
466 # plplot.pltr2,
485 # plplot.pltr2,
467 # xg,
486 # xg,
468 # yg)
487 # yg)
General Comments 0
You need to be logged in to leave comments. Login now