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