##// END OF EJS Templates
SpectraPlot.py:...
Victor Sarmiento -
r63:d3ce6a17a0b7
parent child
Show More
@@ -1,174 +1,178
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, index=0):
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
41 self.indexPlot = index
42
42
43 self.graphObjList = []
43 self.graphObjList = []
44
44
45 self.m_Spectra = Spectra
45 self.m_Spectra = Spectra
46
46
47
47
48 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):
49
49
50 graphObj = ColorPlot()
50 graphObj = ColorPlot()
51 graphObj.setup(subpage,
51 graphObj.setup(subpage,
52 title,
52 title,
53 xlabel,
53 xlabel,
54 ylabel,
54 ylabel,
55 showColorbar=showColorbar,
55 showColorbar=showColorbar,
56 showPowerProfile=showPowerProfile,
56 showPowerProfile=showPowerProfile,
57 XAxisAsTime=XAxisAsTime)
57 XAxisAsTime=XAxisAsTime)
58
58
59 self.graphObjList.append(graphObj)
59 self.graphObjList.append(graphObj)
60
60
61
61
62 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):
63
63
64 nChan = int(self.m_Spectra.m_SystemHeader.numChannels)
64 nChan = int(self.m_Spectra.m_SystemHeader.numChannels)
65 channels = range(nChan)
65 channels = range(nChan)
66
66
67 myXlabel = "Radial Velocity (m/s)"
67 myXlabel = "Radial Velocity (m/s)"
68 myYlabel = "Range (km)"
68 myYlabel = "Range (km)"
69
69
70 for i in channels:
70 for i in channels:
71 if titleList != None:
71 if titleList != None:
72 myTitle = titleList[i]
72 myTitle = titleList[i]
73 myXlabel = xlabelList[i]
73 myXlabel = xlabelList[i]
74 myYlabel = ylabelList[i]
74 myYlabel = ylabelList[i]
75
75
76 # if self.m_Spectra.m_NoiseObj != None:
76 # if self.m_Spectra.m_NoiseObj != None:
77 # noise = '%4.2fdB' %(self.m_Spectra.m_NoiseObj[i])
77 # noise = '%4.2fdB' %(self.m_Spectra.m_NoiseObj[i])
78 # else:
78 # else:
79 noise = '--'
79 noise = '--'
80
80
81 myTitle = "Channel: %d - Noise: %s" %(i, noise)
81 myTitle = "Channel: %d - Noise: %s" %(i, noise)
82
82
83 self.__addGraph(i+1,
83 self.__addGraph(i+1,
84 title=myTitle,
84 title=myTitle,
85 xlabel=myXlabel,
85 xlabel=myXlabel,
86 ylabel=myYlabel,
86 ylabel=myYlabel,
87 showColorbar=showColorbar,
87 showColorbar=showColorbar,
88 showPowerProfile=showPowerProfile,
88 showPowerProfile=showPowerProfile,
89 XAxisAsTime=XAxisAsTime)
89 XAxisAsTime=XAxisAsTime)
90
90
91 self.nGraphs = nChan
91 self.nGraphs = nChan
92 self.__isPlotConfig = True
92 self.__isPlotConfig = True
93
93
94 def iniPlot(self, winTitle=""):
94 def iniPlot(self, winTitle=""):
95
95
96 nx = int(numpy.sqrt(self.nGraphs)+1)
96 nx = int(numpy.sqrt(self.nGraphs)+1)
97 #ny = int(self.nGraphs/nx)
97 #ny = int(self.nGraphs/nx)
98
98
99 plplot.plsstrm(self.indexPlot)
99 plplot.plsstrm(self.indexPlot)
100 plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL)
100 plplot.plparseopts([winTitle], plplot.PL_PARSE_FULL)
101 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
101 plplot.plsetopt("geometry", "%dx%d" %(300*nx, 240*nx))
102 plplot.plsdev("xwin")
102 plplot.plsdev("xwin")
103 plplot.plscolbg(255,255,255)
103 plplot.plscolbg(255,255,255)
104 plplot.plscol0(1,0,0,0)
104 plplot.plscol0(1,0,0,0)
105 plplot.plinit()
105 plplot.plinit()
106 plplot.plspause(False)
106 plplot.plspause(False)
107 plplot.pladv(0)
107 plplot.pladv(0)
108 plplot.plssub(nx, nx)
108 plplot.plssub(nx, nx)
109
109
110 self.__nx = nx
110 self.__nx = nx
111 self.__ny = nx
111 self.__ny = nx
112 self.__isPlotIni = True
112 self.__isPlotIni = True
113
113
114
114
115 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, winTitle="Spectra"):
115 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, winTitle="Spectra"):
116
116
117 if not(self.__isPlotConfig):
117 if not(self.__isPlotConfig):
118 self.setup(titleList,
118 self.setup(titleList,
119 xlabelList,
119 xlabelList,
120 ylabelList,
120 ylabelList,
121 showColorbar,
121 showColorbar,
122 showPowerProfile,
122 showPowerProfile,
123 XAxisAsTime)
123 XAxisAsTime)
124
124
125 if not(self.__isPlotIni):
125 if not(self.__isPlotIni):
126 self.iniPlot(winTitle)
126 self.iniPlot(winTitle)
127
127
128 plplot.plsstrm(self.indexPlot)
128 plplot.plsstrm(self.indexPlot)
129
129
130 data = 10.*numpy.log10(self.m_Spectra.data_spc)
130 data = 10.*numpy.log10(self.m_Spectra.data_spc)
131
131
132 nX, nY, nChan = numpy.shape(data)
132 #data.shape = Channels x Heights x Profiles
133 data = numpy.transpose( data, (0,2,1) )
134 #data.shape = Channels x Profiles x Heights
135
136 nChan, nX, nY = numpy.shape(data)
133
137
134 x = numpy.arange(nX)
138 x = numpy.arange(nX)
135 y = self.m_Spectra.heights
139 y = self.m_Spectra.heights
136
140
137 thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc)
141 thisDatetime = datetime.datetime.fromtimestamp(self.m_Spectra.m_BasicHeader.utc)
138 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
142 txtDate = "Self Spectra - Date: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
139
143
140 if xmin == None: xmin = x[0]
144 if xmin == None: xmin = x[0]
141 if xmax == None: xmax = x[-1]
145 if xmax == None: xmax = x[-1]
142 if ymin == None: ymin = y[0]
146 if ymin == None: ymin = y[0]
143 if ymax == None: ymax = y[-1]
147 if ymax == None: ymax = y[-1]
144 if zmin == None: zmin = numpy.nanmin(abs(data))
148 if zmin == None: zmin = numpy.nanmin(abs(data))
145 if zmax == None: zmax = numpy.nanmax(abs(data))
149 if zmax == None: zmax = numpy.nanmax(abs(data))
146
150
147 plplot.plbop()
151 plplot.plbop()
148
152
149 plplot.plssub(self.__nx, self.__ny)
153 plplot.plssub(self.__nx, self.__ny)
150 for i in range(self.nGraphs):
154 for i in range(self.nGraphs):
151 self.graphObjList[i].iniSubpage()
155 self.graphObjList[i].iniSubpage()
152 self.graphObjList[i].plotData(data[i,:,:],
156 self.graphObjList[i].plotData(data[i,:,:],
153 x,
157 x,
154 y,
158 y,
155 xmin=xmin,
159 xmin=xmin,
156 xmax=xmax,
160 xmax=xmax,
157 ymin=ymin,
161 ymin=ymin,
158 ymax=ymax,
162 ymax=ymax,
159 zmin=zmin,
163 zmin=zmin,
160 zmax=zmax)
164 zmax=zmax)
161
165
162 plplot.plssub(1,0)
166 plplot.plssub(1,0)
163 plplot.pladv(0)
167 plplot.pladv(0)
164 plplot.plvpor(0., 1., 0., 1.)
168 plplot.plvpor(0., 1., 0., 1.)
165 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
169 plplot.plmtex("t",-1., 0.5, 0.5, txtDate)
166 plplot.plflush()
170 plplot.plflush()
167 plplot.pleop()
171 plplot.pleop()
168
172
169 def end(self):
173 def end(self):
170 plplot.plend()
174 plplot.plend()
171
175
172
176
173 if __name__ == '__main__':
177 if __name__ == '__main__':
174 pass No newline at end of file
178 pass
General Comments 0
You need to be logged in to leave comments. Login now