##// END OF EJS Templates
Actualización de la libreria de graficos para manejar varios plots
Miguel Valdez -
r43:fedfeee62f2e
parent child
Show More
@@ -1,168 +1,171
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7
7
8 import os, sys
8 import os, sys
9 import numpy
9 import numpy
10 import datetime
10 import datetime
11 import plplot
11 import plplot
12
12
13 path = os.path.split(os.getcwd())[0]
13 path = os.path.split(os.getcwd())[0]
14 sys.path.append(path)
14 sys.path.append(path)
15
15
16 from Graphics.BaseGraph import *
16 from Graphics.BaseGraph import *
17 from Model.Spectra import Spectra
17 from Model.Spectra import Spectra
18
18
19 class Spectrum():
19 class Spectrum():
20
20
21 def __init__(self, Spectra):
21 def __init__(self, Spectra, index=0):
22
22
23 """
23 """
24
24
25 Inputs:
25 Inputs:
26
26
27 type: "power" ->> Potencia
27 type: "power" ->> Potencia
28 "iq" ->> Real + Imaginario
28 "iq" ->> Real + Imaginario
29 """
29 """
30
30
31 self.__isPlotConfig = False
31 self.__isPlotConfig = False
32
32
33 self.__isPlotIni = False
33 self.__isPlotIni = False
34
34
35 self.__xrange = None
35 self.__xrange = None
36
36
37 self.__yrange = None
37 self.__yrange = None
38
38
39 self.nGraphs = 0
39 self.nGraphs = 0
40
40
41 self.indexPlot = index
42
41 self.graphObjList = []
43 self.graphObjList = []
42
44
43 self.m_Spectra = Spectra
45 self.m_Spectra = Spectra
44
46
45
47
46 def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
48 def __addGraph(self, subpage, title="", xlabel="", ylabel="", showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
47
49
48 graphObj = ColorPlot()
50 graphObj = ColorPlot()
49 graphObj.setup(subpage,
51 graphObj.setup(subpage,
50 title,
52 title,
51 xlabel,
53 xlabel,
52 ylabel,
54 ylabel,
53 showColorbar=showColorbar,
55 showColorbar=showColorbar,
54 showPowerProfile=showPowerProfile,
56 showPowerProfile=showPowerProfile,
55 XAxisAsTime=XAxisAsTime)
57 XAxisAsTime=XAxisAsTime)
56
58
57 self.graphObjList.append(graphObj)
59 self.graphObjList.append(graphObj)
58
60
59
61
60 def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
62 def setup(self, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
61
63
62 nChan = int(self.m_Spectra.m_SystemHeader.numChannels)
64 nChan = int(self.m_Spectra.m_SystemHeader.numChannels)
63 channels = range(nChan)
65 channels = range(nChan)
64
66
65 myXlabel = "Radial Velocity (m/s)"
67 myXlabel = "Radial Velocity (m/s)"
66 myYlabel = "Range (km)"
68 myYlabel = "Range (km)"
67
69
68 for i in channels:
70 for i in channels:
69 if titleList != None:
71 if titleList != None:
70 myTitle = titleList[i]
72 myTitle = titleList[i]
71 myXlabel = xlabelList[i]
73 myXlabel = xlabelList[i]
72 myYlabel = ylabelList[i]
74 myYlabel = ylabelList[i]
73
75
74 if self.m_Spectra.noise != None:
76 if self.m_Spectra.noise != None:
75 noise = '%4.2fdB' %(self.m_Spectra.noise[i])
77 noise = '%4.2fdB' %(self.m_Spectra.noise[i])
76 else:
78 else:
77 noise = '--'
79 noise = '--'
78
80
79 myTitle = "Channel: %d - Noise: %s" %(i, noise)
81 myTitle = "Channel: %d - Noise: %s" %(i, noise)
80
82
81 self.__addGraph(i+1,
83 self.__addGraph(i+1,
82 title=myTitle,
84 title=myTitle,
83 xlabel=myXlabel,
85 xlabel=myXlabel,
84 ylabel=myYlabel,
86 ylabel=myYlabel,
85 showColorbar=showColorbar,
87 showColorbar=showColorbar,
86 showPowerProfile=showPowerProfile,
88 showPowerProfile=showPowerProfile,
87 XAxisAsTime=XAxisAsTime)
89 XAxisAsTime=XAxisAsTime)
88
90
89 self.nGraphs = nChan
91 self.nGraphs = nChan
90 self.__isPlotConfig = True
92 self.__isPlotConfig = True
91
93
92 def iniPlot(self):
94 def iniPlot(self):
93
95
94 nx = int(numpy.sqrt(self.nGraphs)+1)
96 nx = int(numpy.sqrt(self.nGraphs)+1)
95 #ny = int(self.nGraphs/nx)
97 #ny = int(self.nGraphs/nx)
96
98
99 plplot.plsstrm(self.indexPlot)
97 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
100 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
98 plplot.plsdev("xcairo")
101 plplot.plsdev("xcairo")
99 plplot.plscolbg(255,255,255)
102 plplot.plscolbg(255,255,255)
100 plplot.plscol0(1,0,0,0)
103 plplot.plscol0(1,0,0,0)
101 plplot.plinit()
104 plplot.plinit()
102 plplot.plspause(False)
105 plplot.plspause(False)
103 plplot.pladv(0)
106 plplot.pladv(0)
104 plplot.plssub(nx, nx)
107 plplot.plssub(nx, nx)
105
108
106 self.__nx = nx
109 self.__nx = nx
107 self.__ny = nx
110 self.__ny = nx
108 self.__isPlotIni = True
111 self.__isPlotIni = True
109
112
110
113
111 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
114 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, titleList=None, xlabelList=None, ylabelList=None, showColorbar=False, showPowerProfile=True, XAxisAsTime=False):
112
115
113 if not(self.__isPlotConfig):
116 if not(self.__isPlotConfig):
114 self.setup(titleList,
117 self.setup(titleList,
115 xlabelList,
118 xlabelList,
116 ylabelList,
119 ylabelList,
117 showColorbar,
120 showColorbar,
118 showPowerProfile,
121 showPowerProfile,
119 XAxisAsTime)
122 XAxisAsTime)
120
123
121 if not(self.__isPlotIni):
124 if not(self.__isPlotIni):
122 self.iniPlot()
125 self.iniPlot()
123
126
124 data = 10.*numpy.log10(self.m_Spectra.data_spc)
127 data = 10.*numpy.log10(self.m_Spectra.data_spc)
125
128
126 nX, nY, nChan = numpy.shape(data)
129 nX, nY, nChan = numpy.shape(data)
127
130
128 x = numpy.arange(nX)
131 x = numpy.arange(nX)
129 y = self.m_Spectra.heights
132 y = self.m_Spectra.heights
130
133
131 thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc)
134 thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc)
132 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
135 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
133
136
134 if xmin == None: xmin = x[0]
137 if xmin == None: xmin = x[0]
135 if xmax == None: xmax = x[-1]
138 if xmax == None: xmax = x[-1]
136 if ymin == None: ymin = y[0]
139 if ymin == None: ymin = y[0]
137 if ymax == None: ymax = y[-1]
140 if ymax == None: ymax = y[-1]
138 if zmin == None: zmin = numpy.nanmin(abs(data))
141 if zmin == None: zmin = numpy.nanmin(abs(data))
139 if zmax == None: zmax = numpy.nanmax(abs(data))
142 if zmax == None: zmax = numpy.nanmax(abs(data))
140
143
141 plplot.plbop()
144 plplot.plbop()
142
145
143 plplot.plssub(self.__nx, self.__ny)
146 plplot.plssub(self.__nx, self.__ny)
144 for i in range(self.nGraphs):
147 for i in range(self.nGraphs):
145 self.graphObjList[i].iniSubpage()
148 self.graphObjList[i].iniSubpage()
146 self.graphObjList[i].plotData(data[i,:,:],
149 self.graphObjList[i].plotData(data[i,:,:],
147 x,
150 x,
148 y,
151 y,
149 xmin=xmin,
152 xmin=xmin,
150 xmax=xmax,
153 xmax=xmax,
151 ymin=ymin,
154 ymin=ymin,
152 ymax=ymax,
155 ymax=ymax,
153 zmin=zmin,
156 zmin=zmin,
154 zmax=zmax)
157 zmax=zmax)
155
158
156 plplot.plssub(1,0)
159 plplot.plssub(1,0)
157 plplot.pladv(0)
160 plplot.pladv(0)
158 plplot.plvpor(0., 1., 0., 1.)
161 plplot.plvpor(0., 1., 0., 1.)
159 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
162 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
160 plplot.plflush()
163 plplot.plflush()
161 plplot.pleop()
164 plplot.pleop()
162
165
163 def end(self):
166 def end(self):
164 plplot.plend()
167 plplot.plend()
165
168
166
169
167 if __name__ == '__main__':
170 if __name__ == '__main__':
168 pass No newline at end of file
171 pass
@@ -1,175 +1,179
1 '''
1 '''
2 Created on Feb 7, 2012
2 Created on Feb 7, 2012
3
3
4 @author $Author$
4 @author $Author$
5 @version $Id$
5 @version $Id$
6 '''
6 '''
7 import os, sys
7 import os, sys
8 import numpy
8 import numpy
9 import plplot
9 import plplot
10
10
11 path = os.path.split(os.getcwd())[0]
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
12 sys.path.append(path)
13
13
14 from Graphics.BaseGraph import *
14 from Graphics.BaseGraph import *
15 from Model.Voltage import Voltage
15 from Model.Voltage import Voltage
16
16
17 class Osciloscope():
17 class Osciloscope():
18
18
19 def __init__(self, Voltage):
19 def __init__(self, Voltage, index=0):
20
20
21 """
21 """
22
22
23 Inputs:
23 Inputs:
24
24
25 type: "power" ->> Potencia
25 type: "power" ->> Potencia
26 "iq" ->> Real + Imaginario
26 "iq" ->> Real + Imaginario
27 """
27 """
28
28
29 self.__isPlotConfig = False
29 self.__isPlotConfig = False
30
30
31 self.__isPlotIni = False
31 self.__isPlotIni = False
32
32
33 self.__xrange = None
33 self.__xrange = None
34
34
35 self.__yrange = None
35 self.__yrange = None
36
36
37 self.m_Voltage = None
37 self.m_Voltage = None
38
38
39 self.nGraphs = 0
39 self.nGraphs = 0
40
40
41 self.indexPlot = index
42
41 self.graphObjList = []
43 self.graphObjList = []
42
44
43 self.m_Voltage = Voltage
45 self.m_Voltage = Voltage
44
46
45
47
46 def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False):
48 def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False):
47
49
48 graphObj = LinearPlot()
50 graphObj = LinearPlot()
49 graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False)
51 graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False)
50 #graphObj.setScreenPos()
52 #graphObj.setScreenPos()
51
53
52 self.graphObjList.append(graphObj)
54 self.graphObjList.append(graphObj)
53
55
54 del graphObj
56 del graphObj
55
57
56 # def setXRange(self, xmin, xmax):
58 # def setXRange(self, xmin, xmax):
57 # self.__xrange = (xmin, xmax)
59 # self.__xrange = (xmin, xmax)
58 #
60 #
59 # def setYRange(self, ymin, ymax):
61 # def setYRange(self, ymin, ymax):
60 # self.__yrange = (ymin, ymax)
62 # self.__yrange = (ymin, ymax)
61
63
62
64
63 def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False):
65 def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False):
64
66
65 nChan = int(self.m_Voltage.m_SystemHeader.numChannels)
67 nChan = int(self.m_Voltage.m_SystemHeader.numChannels)
66
68
67 myTitle = ""
69 myTitle = ""
68 myXlabel = ""
70 myXlabel = ""
69 myYlabel = ""
71 myYlabel = ""
70
72
71 for i in range(nChan):
73 for i in range(nChan):
72 if titleList != None:
74 if titleList != None:
73 myTitle = titleList[i]
75 myTitle = titleList[i]
74 myXlabel = xlabelList[i]
76 myXlabel = xlabelList[i]
75 myYlabel = ylabelList[i]
77 myYlabel = ylabelList[i]
76
78
77 self.__addGraph(i+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime)
79 self.__addGraph(i+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime)
78
80
79 self.nGraphs = nChan
81 self.nGraphs = nChan
80 self.__isPlotConfig = True
82 self.__isPlotConfig = True
81
83
82 def iniPlot(self):
84 def iniPlot(self):
85
86 plplot.plsstrm(self.indexPlot)
83 plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs))
87 plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs))
84 plplot.plsdev("xcairo")
88 plplot.plsdev("xcairo")
85 plplot.plscolbg(255,255,255)
89 plplot.plscolbg(255,255,255)
86 plplot.plscol0(1,0,0,0)
90 plplot.plscol0(1,0,0,0)
87 plplot.plinit()
91 plplot.plinit()
88 plplot.plspause(False)
92 plplot.plspause(False)
89 plplot.plssub(1, self.nGraphs)
93 plplot.plssub(1, self.nGraphs)
90
94
91 self.__isPlotIni = True
95 self.__isPlotIni = True
92
96
93 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq'):
97 def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq'):
94
98
95 if idProfile != None and idProfile != self.m_Voltage.idProfile:
99 if idProfile != None and idProfile != self.m_Voltage.idProfile:
96 return
100 return
97
101
98 if not(self.__isPlotConfig):
102 if not(self.__isPlotConfig):
99 self.setup(titleList, xlabelList, ylabelList, XAxisAsTime)
103 self.setup(titleList, xlabelList, ylabelList, XAxisAsTime)
100
104
101 if not(self.__isPlotIni):
105 if not(self.__isPlotIni):
102 self.iniPlot()
106 self.iniPlot()
103
107
104 data = self.m_Voltage.data
108 data = self.m_Voltage.data
105
109
106 x = self.m_Voltage.heights
110 x = self.m_Voltage.heights
107
111
108 if xmin == None: xmin = x[0]
112 if xmin == None: xmin = x[0]
109 if xmax == None: xmax = x[-1]
113 if xmax == None: xmax = x[-1]
110 if ymin == None: ymin = numpy.nanmin(abs(data))
114 if ymin == None: ymin = numpy.nanmin(abs(data))
111 if ymax == None: ymax = numpy.nanmax(abs(data))
115 if ymax == None: ymax = numpy.nanmax(abs(data))
112
116
113 plplot.plbop()
117 plplot.plbop()
114 for i in range(self.nGraphs):
118 for i in range(self.nGraphs):
115 y = data[:,i]
119 y = data[:,i]
116
120
117 self.graphObjList[i].iniSubpage()
121 self.graphObjList[i].iniSubpage()
118 self.graphObjList[i].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type)
122 self.graphObjList[i].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type)
119
123
120 plplot.plflush()
124 plplot.plflush()
121 plplot.pleop()
125 plplot.pleop()
122
126
123 def end(self):
127 def end(self):
124 plplot.plend()
128 plplot.plend()
125
129
126 class VoltagePlot(object):
130 class VoltagePlot(object):
127 '''
131 '''
128 classdocs
132 classdocs
129 '''
133 '''
130
134
131 __m_Voltage = None
135 __m_Voltage = None
132
136
133 def __init__(self, m_Voltage):
137 def __init__(self, m_Voltage):
134 '''
138 '''
135 Constructor
139 Constructor
136 '''
140 '''
137 self.__m_Voltage = m_Voltage
141 self.__m_Voltage = m_Voltage
138
142
139 def setup(self):
143 def setup(self):
140 pass
144 pass
141
145
142 def addGraph(self, type, xrange=None, yrange=None, zrange=None):
146 def addGraph(self, type, xrange=None, yrange=None, zrange=None):
143 pass
147 pass
144
148
145 def plotData(self):
149 def plotData(self):
146 pass
150 pass
147
151
148 if __name__ == '__main__':
152 if __name__ == '__main__':
149
153
150 import numpy
154 import numpy
151
155
152 plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2))
156 plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2))
153 plplot.plsdev("xcairo")
157 plplot.plsdev("xcairo")
154 plplot.plscolbg(255,255,255)
158 plplot.plscolbg(255,255,255)
155 plplot.plscol0(1,0,0,0)
159 plplot.plscol0(1,0,0,0)
156 plplot.plinit()
160 plplot.plinit()
157 plplot.plssub(1, 2)
161 plplot.plssub(1, 2)
158
162
159 nx = 64
163 nx = 64
160 ny = 100
164 ny = 100
161
165
162 data = numpy.random.uniform(-50,50,(nx,ny))
166 data = numpy.random.uniform(-50,50,(nx,ny))
163
167
164 baseObj = RTI()
168 baseObj = RTI()
165 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False)
169 baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False)
166 baseObj.plotData(data)
170 baseObj.plotData(data)
167
171
168 data = numpy.random.uniform(-50,50,(nx,ny))
172 data = numpy.random.uniform(-50,50,(nx,ny))
169
173
170 base2Obj = RTI()
174 base2Obj = RTI()
171 base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True)
175 base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True)
172 base2Obj.plotData(data)
176 base2Obj.plotData(data)
173
177
174 plplot.plend()
178 plplot.plend()
175 exit(0) No newline at end of file
179 exit(0)
General Comments 0
You need to be logged in to leave comments. Login now