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