##// END OF EJS Templates
Se agregó metodos para plotear RTI
Daniel Valdez -
r140:6d29f38e29fd
parent child
Show More
@@ -1,220 +1,287
1 '''
1 '''
2
2
3 $Author$
3 $Author$
4 $Id$
4 $Id$
5 '''
5 '''
6
6
7 import os
7 import os
8 import sys
8 import sys
9 import numpy
9 import numpy
10 import datetime
10 import datetime
11 import time
11
12
12 path = os.path.split(os.getcwd())[0]
13 path = os.path.split(os.getcwd())[0]
13 sys.path.append(path)
14 sys.path.append(path)
14
15
15 from Data.JROData import Voltage
16 from Data.JROData import Voltage
16 from IO.VoltageIO import VoltageWriter
17 from IO.VoltageIO import VoltageWriter
17 from Graphics2.schainPlotTypes import ScopeFigure
18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
18
19
19 class VoltageProcessor:
20 class VoltageProcessor:
20
21
21 dataInObj = None
22 dataInObj = None
22 dataOutObj = None
23 dataOutObj = None
23 integratorObjIndex = None
24 integratorObjIndex = None
24 writerObjIndex = None
25 writerObjIndex = None
25 integratorObjList = None
26 integratorObjList = None
26 writerObjList = None
27 writerObjList = None
27
28
28 def __init__(self):
29 def __init__(self):
29 self.integratorObjIndex = None
30 self.integratorObjIndex = None
30 self.writerObjIndex = None
31 self.writerObjIndex = None
31 self.plotObjIndex = None
32 self.plotObjIndex = None
32 self.integratorObjList = []
33 self.integratorObjList = []
33 self.writerObjList = []
34 self.writerObjList = []
34 self.plotObjList = []
35 self.plotObjList = []
35
36
36 def setup(self,dataInObj=None,dataOutObj=None):
37 def setup(self,dataInObj=None,dataOutObj=None):
37 self.dataInObj = dataInObj
38 self.dataInObj = dataInObj
38
39
39 if self.dataOutObj == None:
40 if self.dataOutObj == None:
40 dataOutObj = Voltage()
41 dataOutObj = Voltage()
41
42
42 self.dataOutObj = dataOutObj
43 self.dataOutObj = dataOutObj
43
44
44 return self.dataOutObj
45 return self.dataOutObj
45
46
46 def init(self):
47 def init(self):
47 self.integratorObjIndex = 0
48 self.integratorObjIndex = 0
48 self.writerObjIndex = 0
49 self.writerObjIndex = 0
49 self.plotObjIndex = 0
50 self.plotObjIndex = 0
50
51
51 if not(self.dataInObj.flagNoData):
52 if not(self.dataInObj.flagNoData):
52 self.dataOutObj.copy(self.dataInObj)
53 self.dataOutObj.copy(self.dataInObj)
53 # No necesita copiar en cada init() los atributos de dataInObj
54 # No necesita copiar en cada init() los atributos de dataInObj
54 # la copia deberia hacerse por cada nuevo bloque de datos
55 # la copia deberia hacerse por cada nuevo bloque de datos
55
56
57 def addRti(self, idfigure, nframes, wintitle, driver, colorbar, colormap, showprofile):
58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colorbar, colormap, showprofile)
59 self.plotObjList.append(rtiObj)
60
61 def plotRti(self, idfigure=None,
62 starttime=None,
63 endtime=None,
64 rangemin=None,
65 rangemax=None,
66 minvalue=None,
67 maxvalue=None,
68 wintitle='',
69 driver='plplot',
70 colormap='br_greeen',
71 colorbar=True,
72 showprofile=False,
73 xrangestep=None,
74 save=False,
75 gpath=None):
76
77 if self.dataOutObj.flagNoData:
78 return 0
79
80 nframes = len(self.dataOutObj.channelList)
81
82 if len(self.plotObjList) <= self.plotObjIndex:
83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
84
85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
86 data = 10*numpy.log10(data.real)
87
88 # currenttime = self.dataOutObj.dataUtcTime
89 # if timezone == "lt":
90 currenttime = self.dataOutObj.dataUtcTime - time.timezone
91
92
93
94 range = self.dataOutObj.heightList
95
96 channelList = self.dataOutObj.channelList
97
98 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
99 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
100 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
101
102 figuretitle = "RTI Plot Radar Data" #+ date
103
104 plotObj = self.plotObjList[self.plotObjIndex]
105
106 plotObj.plotPcolor(data,
107 currenttime,
108 range,
109 channelList,
110 starttime,
111 endtime,
112 rangemin,
113 rangemax,
114 minvalue,
115 maxvalue,
116 figuretitle,
117 xrangestep,
118 save,
119 gpath)
120
121 self.plotObjIndex += 1
122
56 def addScope(self, idfigure, nframes, wintitle, driver):
123 def addScope(self, idfigure, nframes, wintitle, driver):
57 if idfigure==None:
124 if idfigure==None:
58 idfigure = self.plotObjIndex
125 idfigure = self.plotObjIndex
59
126
60 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
127 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
61 self.plotObjList.append(scopeObj)
128 self.plotObjList.append(scopeObj)
62
129
63 def plotScope(self,
130 def plotScope(self,
64 idfigure=None,
131 idfigure=None,
65 minvalue=None,
132 minvalue=None,
66 maxvalue=None,
133 maxvalue=None,
67 xmin=None,
134 xmin=None,
68 xmax=None,
135 xmax=None,
69 wintitle='',
136 wintitle='',
70 driver='plplot',
137 driver='plplot',
71 save=False,
138 save=False,
72 gpath=None,
139 gpath=None,
73 titleList=None,
140 titleList=None,
74 xlabelList=None,
141 xlabelList=None,
75 ylabelList=None,
142 ylabelList=None,
76 type="power"):
143 type="power"):
77
144
78 if self.dataOutObj.flagNoData:
145 if self.dataOutObj.flagNoData:
79 return 0
146 return 0
80
147
81 nframes = len(self.dataOutObj.channelList)
148 nframes = len(self.dataOutObj.channelList)
82
149
83 if len(self.plotObjList) <= self.plotObjIndex:
150 if len(self.plotObjList) <= self.plotObjIndex:
84 self.addScope(idfigure, nframes, wintitle, driver)
151 self.addScope(idfigure, nframes, wintitle, driver)
85
152
86
153
87 if type=="power":
154 if type=="power":
88 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
155 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
89 data1D = data1D.real
156 data1D = data1D.real
90
157
91 if type =="iq":
158 if type =="iq":
92 data1D = self.dataOutObj.data
159 data1D = self.dataOutObj.data
93
160
94 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
161 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
95
162
96 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
163 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
97 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
164 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
98
165
99 figureTitle = "Scope Plot Radar Data: " + date
166 figureTitle = "Scope Plot Radar Data: " + date
100
167
101 plotObj = self.plotObjList[self.plotObjIndex]
168 plotObj = self.plotObjList[self.plotObjIndex]
102
169
103 plotObj.plot1DArray(data1D,
170 plotObj.plot1DArray(data1D,
104 self.dataOutObj.heightList,
171 self.dataOutObj.heightList,
105 self.dataOutObj.channelList,
172 self.dataOutObj.channelList,
106 xmin,
173 xmin,
107 xmax,
174 xmax,
108 minvalue,
175 minvalue,
109 maxvalue,
176 maxvalue,
110 figureTitle,
177 figureTitle,
111 save,
178 save,
112 gpath)
179 gpath)
113
180
114 self.plotObjIndex += 1
181 self.plotObjIndex += 1
115
182
116
183
117 def addIntegrator(self,N,timeInterval):
184 def addIntegrator(self,N,timeInterval):
118 objCohInt = CoherentIntegrator(N,timeInterval)
185 objCohInt = CoherentIntegrator(N,timeInterval)
119 self.integratorObjList.append(objCohInt)
186 self.integratorObjList.append(objCohInt)
120
187
121 def addWriter(self, wrpath, blocksPerFile, profilesPerBlock):
188 def addWriter(self, wrpath, blocksPerFile, profilesPerBlock):
122 writerObj = VoltageWriter(self.dataOutObj)
189 writerObj = VoltageWriter(self.dataOutObj)
123 writerObj.setup(wrpath,blocksPerFile,profilesPerBlock)
190 writerObj.setup(wrpath,blocksPerFile,profilesPerBlock)
124 self.writerObjList.append(writerObj)
191 self.writerObjList.append(writerObj)
125
192
126 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
193 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
127
194
128 if self.dataOutObj.flagNoData:
195 if self.dataOutObj.flagNoData:
129 return 0
196 return 0
130
197
131 if len(self.writerObjList) <= self.writerObjIndex:
198 if len(self.writerObjList) <= self.writerObjIndex:
132 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
199 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
133
200
134 self.writerObjList[self.writerObjIndex].putData()
201 self.writerObjList[self.writerObjIndex].putData()
135
202
136 self.writerObjIndex += 1
203 self.writerObjIndex += 1
137
204
138 def integrator(self, N=None, timeInterval=None):
205 def integrator(self, N=None, timeInterval=None):
139 if self.dataOutObj.flagNoData:
206 if self.dataOutObj.flagNoData:
140 return 0
207 return 0
141 if len(self.integratorObjList) <= self.integratorObjIndex:
208 if len(self.integratorObjList) <= self.integratorObjIndex:
142 self.addIntegrator(N,timeInterval)
209 self.addIntegrator(N,timeInterval)
143
210
144 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
211 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
145 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None)
212 myCohIntObj.exe(data=self.dataOutObj.data,timeOfData=None)
146
213
147
214
148
215
149 class CoherentIntegrator:
216 class CoherentIntegrator:
150
217
151 integ_counter = None
218 integ_counter = None
152 data = None
219 data = None
153 navg = None
220 navg = None
154 buffer = None
221 buffer = None
155 nCohInt = None
222 nCohInt = None
156
223
157 def __init__(self, N=None,timeInterval=None):
224 def __init__(self, N=None,timeInterval=None):
158
225
159 self.data = None
226 self.data = None
160 self.navg = None
227 self.navg = None
161 self.buffer = None
228 self.buffer = None
162 self.timeOut = None
229 self.timeOut = None
163 self.exitCondition = False
230 self.exitCondition = False
164 self.isReady = False
231 self.isReady = False
165 self.nCohInt = N
232 self.nCohInt = N
166 self.integ_counter = 0
233 self.integ_counter = 0
167 if timeInterval!=None:
234 if timeInterval!=None:
168 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
235 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
169
236
170 if ((timeInterval==None) and (N==None)):
237 if ((timeInterval==None) and (N==None)):
171 raise ValueError, "N = None ; timeInterval = None"
238 raise ValueError, "N = None ; timeInterval = None"
172
239
173 if timeInterval == None:
240 if timeInterval == None:
174 self.timeFlag = False
241 self.timeFlag = False
175 else:
242 else:
176 self.timeFlag = True
243 self.timeFlag = True
177
244
178 def exe(self, data, timeOfData):
245 def exe(self, data, timeOfData):
179
246
180 if self.timeFlag:
247 if self.timeFlag:
181 if self.timeOut == None:
248 if self.timeOut == None:
182 self.timeOut = timeOfData + self.timeIntervalInSeconds
249 self.timeOut = timeOfData + self.timeIntervalInSeconds
183
250
184 if timeOfData < self.timeOut:
251 if timeOfData < self.timeOut:
185 if self.buffer == None:
252 if self.buffer == None:
186 self.buffer = data
253 self.buffer = data
187 else:
254 else:
188 self.buffer = self.buffer + data
255 self.buffer = self.buffer + data
189 self.integ_counter += 1
256 self.integ_counter += 1
190 else:
257 else:
191 self.exitCondition = True
258 self.exitCondition = True
192
259
193 else:
260 else:
194 if self.integ_counter < self.nCohInt:
261 if self.integ_counter < self.nCohInt:
195 if self.buffer == None:
262 if self.buffer == None:
196 self.buffer = data
263 self.buffer = data
197 else:
264 else:
198 self.buffer = self.buffer + data
265 self.buffer = self.buffer + data
199
266
200 self.integ_counter += 1
267 self.integ_counter += 1
201
268
202 if self.integ_counter == self.nCohInt:
269 if self.integ_counter == self.nCohInt:
203 self.exitCondition = True
270 self.exitCondition = True
204
271
205 if self.exitCondition:
272 if self.exitCondition:
206 self.data = self.buffer
273 self.data = self.buffer
207 self.navg = self.integ_counter
274 self.navg = self.integ_counter
208 self.isReady = True
275 self.isReady = True
209 self.buffer = None
276 self.buffer = None
210 self.timeOut = None
277 self.timeOut = None
211 self.integ_counter = 0
278 self.integ_counter = 0
212 self.exitCondition = False
279 self.exitCondition = False
213
280
214 if self.timeFlag:
281 if self.timeFlag:
215 self.buffer = data
282 self.buffer = data
216 self.timeOut = timeOfData + self.timeIntervalInSeconds
283 self.timeOut = timeOfData + self.timeIntervalInSeconds
217 else:
284 else:
218 self.isReady = False
285 self.isReady = False
219
286
220
287
General Comments 0
You need to be logged in to leave comments. Login now