##// END OF EJS Templates
-Actualización del modulo SpectraProcessor, SchainPlot y schainPlotLib...
Miguel Valdez -
r153:e56dcbb72a43
parent child
Show More
@@ -1,219 +1,229
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import copy
9 9 import numpy
10 10
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 14 from IO.JROHeaderIO import SystemHeader, RadarControllerHeader
15 15
16 16 class JROData:
17 17
18 18 # m_BasicHeader = BasicHeader()
19 19 # m_ProcessingHeader = ProcessingHeader()
20 20
21 21 systemHeaderObj = SystemHeader()
22 22
23 23 radarControllerHeaderObj = RadarControllerHeader()
24 24
25 25 # data = None
26 26
27 27 type = None
28 28
29 29 dtype = None
30 30
31 31 nChannels = None
32 32
33 33 nHeights = None
34 34
35 35 nProfiles = None
36 36
37 37 heightList = None
38 38
39 39 channelList = None
40 40
41 41 channelIndexList = None
42 42
43 flagNoData = False
43 flagNoData = True
44 44
45 45 flagTimeBlock = False
46 46
47 dataUtcTime = None
47 utctime = None
48
49 blocksize = None
48 50
49 51 nCode = None
50 52
51 53 nBaud = None
52 54
53 55 code = None
54 56
55 57 flagDecodeData = True #asumo q la data esta decodificada
56 58
57 59 flagDeflipData = True #asumo q la data esta sin flip
58 60
59 61 flagShiftFFT = False
60 62
61 63 ippSeconds = None
62 64
63 65
64 66 def __init__(self):
65 67
66 68 raise ValueError, "This class has not been implemented"
67 69
68 70 def copy(self, inputObj=None):
69 71
70 72 if inputObj == None:
71 73 return copy.deepcopy(self)
72 74
73 75 for key in inputObj.__dict__.keys():
74 76 self.__dict__[key] = inputObj.__dict__[key]
75 77
76 78 def deepcopy(self):
77 79
78 80 return copy.deepcopy(self)
79 81
80 82 class Voltage(JROData):
81 83
82 84 nCohInt = None
83 85
84 86 #data es un numpy array de 2 dmensiones (canales, alturas)
85 87 data = None
86 88
87 89 def __init__(self):
88 90 '''
89 91 Constructor
90 92 '''
91 93
92 94 self.radarControllerHeaderObj = RadarControllerHeader()
93 95
94 96 self.systemHeaderObj = SystemHeader()
95 97
96 98 self.type = "Voltage"
97 99
98 100 self.data = None
99 101
100 102 self.dtype = None
101 103
102 104 self.nChannels = 0
103 105
104 106 self.nHeights = 0
105 107
106 108 self.nProfiles = None
107 109
108 110 self.heightList = None
109 111
110 112 self.channelList = None
111 113
112 114 self.channelIndexList = None
113 115
114 116 self.flagNoData = True
115 117
116 118 self.flagTimeBlock = False
117 119
118 self.dataUtcTime = None
120 self.utctime = None
119 121
120 122 self.nCohInt = None
121 123
124 self.blocksize = None
125
122 126 class Spectra(JROData):
123 127
124 128 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
125 129 data_spc = None
126 130
127 131 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
128 132 data_cspc = None
129 133
130 134 #data es un numpy array de 2 dmensiones (canales, alturas)
131 135 data_dc = None
132 136
133 137 nFFTPoints = None
134 138
135 139 nPairs = None
136 140
137 141 pairsList = None
138 142
139 143 nIncohInt = None
140 144
141 145 def __init__(self):
142 146 '''
143 147 Constructor
144 148 '''
145 149
146 150 self.radarControllerHeaderObj = RadarControllerHeader()
147 151
148 152 self.systemHeaderObj = SystemHeader()
149 153
150 154 self.type = "Spectra"
151 155
152 156 # self.data = None
153 157
154 158 self.dtype = None
155 159
156 160 self.nChannels = 0
157 161
158 162 self.nHeights = 0
159 163
160 164 self.nProfiles = None
161 165
162 166 self.heightList = None
163 167
164 168 self.channelList = None
165 169
166 170 self.channelIndexList = None
167 171
168 172 self.flagNoData = True
169 173
170 174 self.flagTimeBlock = False
171 175
172 self.dataUtcTime = None
176 self.utctime = None
173 177
174 178 self.nIncohInt = None
175 179
180 self.blocksize = None
181
176 182
177 183 class SpectraHeis(JROData):
178 184
179 185 data_spc = None
180 186
181 187 data_cspc = None
182 188
183 189 data_dc = None
184 190
185 191 nFFTPoints = None
186 192
187 193 nPairs = None
188 194
189 195 pairsList = None
190 196
191 197 nIncohInt = None
192 198
193 199 def __init__(self):
194 200
195 201 self.radarControllerHeaderObj = RadarControllerHeader()
196 202
197 203 self.systemHeaderObj = SystemHeader()
198 204
199 205 self.type = "SpectraHeis"
200 206
201 207 self.dtype = None
202 208
203 209 self.nChannels = 0
204 210
205 211 self.nHeights = 0
206 212
207 213 self.nProfiles = None
208 214
209 215 self.heightList = None
210 216
211 217 self.channelList = None
212 218
213 219 self.channelIndexList = None
214 220
215 221 self.flagNoData = True
216 222
217 223 self.flagTimeBlock = False
218 224
219 225 self.nPairs = 0
226
227 self.utctime = None
228
229 self.blocksize = None
@@ -1,351 +1,393
1 1 import numpy
2 2 import datetime
3 3 import time
4 4 import os
5 5 from schainPlotLib import Driver
6 6
7 7 class Figure:
8
8 9 __isDriverOpen = False
9 10 __isFigureOpen = False
10 11 __isConfig = False
12
11 13 drvObj = None
14 driver = None
12 15 idfigure = None
13 16 nframes = None
14 17 wintitle = None
15 18 colormap = None
16 driver = None
17 19 overplot = None
20 colorbar = None
21
22 frameObjList = []
23
24 xw = None
25 yw = None
26
18 27 xmin = None
19 28 xmax = None
20 29 ymin = None
21 30 ymax = None
31
22 32 minvalue = None
23 33 maxvalue = None
24 34 deltax = None
25 35 deltay = None
26 frameObjList = []
36
37
27 38 figuretitle = ""
28 39 xrangestep = None
29 40
30 41 def __init__(self,idfigure, nframes, wintitle, xw=600, yw=800, overplot=0, driver='plplot', colormap=None, colorbar= True, *args):
31 42
43 self.__isDriverOpen = False
44 self.__isFigureOpen = False
45 self.__isConfig = False
46
32 47 self.drvObj = Driver(driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
33 48 self.driver = driver
34 49 self.idfigure = idfigure
35 self.xw = xw
36 self.yw = yw
37 50 self.nframes = nframes
38 51 self.wintitle = wintitle
39 52 self.colormap = colormap
40 53 self.overplot = overplot
41 54 self.colorbar = colorbar
55
56 self.xw = xw
57 self.yw = yw
58
59 self.frameObjList = []
60
42 61 # self.showGraph1 = args[0]
43 62 # self.showGraph2 = args[1]
44 63
45 64 self.drvObj.driver.setFigure()
46 65 self.drvObj.driver.setColormap(colormap)
47 66
48
49
50 67 def __openDriver(self):
68
51 69 self.drvObj.driver.openDriver()
52 70
53 71 def __initFigure(self):
72
54 73 nrows, ncolumns = self.getSubplots()
55 74 self.drvObj.driver.openFigure()
56 75 self.drvObj.driver.setFigTitle(self.figuretitle)
57 76 self.drvObj.driver.setSubPlots(nrows, ncolumns)
58 77
78 def selectFigure(self):
79
80 self.drvObj.driver.selectFigure()
81
59 82 def __isOutOfXRange(self,x):
60 83 try:
61 84 if ((x>=self.xmin) and (x<self.xmax)):
62 85 return 0
63 86 except:
64 87 return 0
65 88
66 89 return 1
67 90
68 91 def changeXRange(self,x):
69 92
70 93 pass
71 94
72 95 def __refresh(self):
73 96 self.drvObj.driver.refresh()
74 97
75 98 def createFrames(self):
76 99 raise ValueError, "No implemented"
77 100
78 101 def save(self,filename):
102
79 103 self.drvObj.driver.save(filename)
80 104
81 105 def plot1DArray(self, data1D, x=None, channelList=None, xmin=None, xmax=None, minvalue=None, maxvalue=None, figuretitle=None, save=False, gpath='./'):
82 106
83 107 nx, ny = data1D.shape
84 108
85 109 if channelList == None:
86 110 channelList = range(nx)
87 111
88 112 if x == None:
89 113 x = numpy.arange(data1D.size)
90 114
91 115 if figuretitle == None:
92 116 self.figuretitle = ""
93 117 else:
94 118 self.figuretitle = figuretitle
95 119
96 120 if not(self.__isDriverOpen):
97 121 self.__openDriver()
98 122 self.__isDriverOpen = True
99 123
100 124 if not(self.__isConfig):
101 125 self.xmin = xmin
102 126 self.xmax = xmax
103 127 self.minvalue = minvalue
104 128 self.maxvalue = maxvalue
105 129
106 130 if self.xmin == None: self.xmin = numpy.min(x)
107 131 if self.xmax == None: self.xmax = numpy.max(x)
108 132 if self.minvalue == None: self.minvalue = numpy.min(data1D)
109 133 if self.maxvalue == None: self.maxvalue = numpy.max(data1D)
110 134
111 135 self.createFrames()
112 136 self.__isConfig = True
113 137
114 138 if not(self.__isOutOfXRange(x)):
115 139 self.changeXRange(x)
116 140
117 141 if self.__isFigureOpen:
118 142 self.drvObj.driver.closePage()
119 143 self.__isFigureOpen = False
120 144
121
145 self.selectFigure()
122 146 self.__initFigure()
123 147
124 148 for channel in channelList:
125 149 frameObj = self.frameObjList[channel]
126 150 frameObj.init(xmin=self.xmin,
127 151 xmax=self.xmax,
128 152 ymin=self.minvalue,
129 153 ymax=self.maxvalue,
130 154 minvalue=self.minvalue,
131 155 maxvalue=self.maxvalue)
132 156
133 157 for channel in channelList:
134 158 dataCh = data1D[channel,:]
135 159 frameObj = self.frameObjList[channel]
136 160 # frameObj.clearData()
137 161 frameObj.plot(x, dataCh)
138 162
139 163 # frameObj.refresh()
140 164 self.__refresh()
141 165
142 166
143 167
144 168 if save:
145 169 # self.colorplotObj.setFigure(indexPlot)
146 170
147 171 path = gpath
148 172 now = datetime.datetime.now()
149 173 file = "scope_img%02d_%d_%d.png"%(self.idfigure, time.mktime(now.timetuple()), now.microsecond)
150 174 filename = os.path.join(path,file)
151 175 self.save(filename)
152 176
153 177
154 178
155 179
156 180 def plotPcolor(self,data,
157 181 x=None,
158 182 y=None,
159 183 channelList=None,
160 184 xmin=None,
161 185 xmax=None,
162 186 ymin=None,
163 187 ymax=None,
164 188 minvalue=None,
165 189 maxvalue=None,
166 190 figuretitle=None,
167 191 xrangestep=None,
168 192 deltax=None,
169 193 save=False,
170 194 gpath='./',
171 195 clearData=False,
172 196 *args):
173 197
174 198
175 199 if figuretitle == None:
176 200 self.figuretitle = ""
177 201 else:
178 202 self.figuretitle = figuretitle
179 203
180 204
181 205
182 206 if not(self.__isDriverOpen):
183 207 self.__openDriver()
184 208 self.__isDriverOpen = True
185 209
186 210 if not(self.__isConfig):
187 211
188 212 self.setParms(data,x,y,xmin,xmax,ymin,ymax,minvalue,maxvalue,xrangestep,deltax)
189 213
190 214 self.createFrames()
191 215 self.__isConfig = True
192 216
193 217 if (self.__isOutOfXRange(x)):
194 218
195 219 if not(self.changeXRange(x)):
196 220 return 0
197 221
198 222 self.__isFigureOpen = False
199 223
200 224 if not(self.__isFigureOpen):
201 225
202 226
203 227 self.__initFigure()
204 228 self.__isFigureOpen = True
205 229
206 230 for channel in channelList:
207 231 if len(args) != 0: value = args[0][channel]
208 232 else: value = args
209 233
210 234 frameObj = self.frameObjList[channel]
211 235 frameObj.init(self.xmin,
212 236 self.xmax,
213 237 self.ymin,
214 238 self.ymax,
215 239 self.minvalue,
216 240 self.maxvalue,
217 241 self.deltax,
218 242 self.deltay,
219 243 self.colorbar,
220 244 value)
245 self.selectFigure()
221 246
222 247 for channel in channelList:
223 248 dataCh = data[channel,:]
224 249 frameObj = self.frameObjList[channel]
225 250 frameObj.plot(x, y, dataCh)
226 251
227 252
228 253 self.__refresh()
229 254 if clearData == True:
230 255 self.__isFigureOpen = False
231 256
232 257
233 258
234 259 class Frame:
260
261 drvObj = None
262 idFrame = None
235 263 nplots = None
236 264 plotObjList = []
237 265 title = ""
238 266
239 267 def __init__(self,drvObj, idframe):
268
240 269 self.drvObj = drvObj
241 270 self.idframe = idframe
271 nplots = None
272 self.plotObjList = []
273
242 274 self.createPlots()
243 275
244 276 def createPlots(self):
245 277 raise ValueError, "No implemented"
246 278
247 279 def getScreenPosMainPlot(self):
248 280 raise ValueError, "No implemented"
249 281
250 282 def getScreenPosGraph1(self):
251 283 raise ValueError, "No implemented"
252 284
253 285 def getScreenPos(self, nplot):
254 286
255 287 if nplot == 0:
256 288 xi, yi, xw, yw = self.getScreenPosMainPlot()
257 289
258 290 if nplot == 1:
259 291 xi, yi, xw, yw = self.getScreenPosGraph1()
260 292
261 293 return xi, yi, xw, yw
262 294
263 295
264 296 def init(self, xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax=None, deltay=None, colorbar=False, *args):
265 297
266 298 for plotObj in self.plotObjList:
267 299 plotObj.setBox(xmin, xmax, ymin, ymax, minvalue, maxvalue, deltax, deltay, colorbar, *args)
268 300 plotObj.plotBox()
269 301
270 302
271 303
272 304 class Plot:
305
306 drvObj = None
307 idframe = None
308 idplot = None
309 xi = None
310 yi = None
311 xw = None
312 yw = None
313
273 314 title = ""
274 315 xlabel = ""
275 316 ylabel = ""
276 317 xaxisastime = None
277 318 timefmt = None
278 319 xopt = ""
279 320 yopt = ""
280 321 xpos = None
281 322 ypos = None
282 323 szchar = None
283 324 idframe = None
284 325 idplot = None
285 326 colorbar = None
286 327 cbxpos = None
287 328 cbypos = None
288 329
289 330 def __init__(self, drvObj, idframe, idplot, xi, yi, xw, yw):
331
290 332 self.drvObj = drvObj
291 333 self.idframe = idframe
292 334 self.idplot = idplot
293 335 self.xi = xi
294 336 self.yi = yi
295 337 self.xw = xw
296 338 self.yw = yw
297 339
298 340
299 341 def plotBox(self):
300 342
301 343 self.drvObj.driver.plotBox(self.idframe,
302 344 self.xpos,
303 345 self.ypos,
304 346 self.xmin,
305 347 self.xmax,
306 348 self.ymin,
307 349 self.ymax,
308 350 self.minvalue,
309 351 self.maxvalue,
310 352 self.xopt,
311 353 self.yopt,
312 354 self.szchar,
313 355 self.xaxisastime,
314 356 self.timefmt)
315 357
316 358 self.drvObj.driver.setPlotLabels(self.idframe, self.xlabel, self.ylabel, self.title)
317 359
318 360 if self.colorbar:
319 361 self.drvObj.driver.plotColorbar(self.minvalue, self.maxvalue, self.cbxpos,self.cbypos)
320 362
321 363 def plotPcolor(self, x, y, z, deltax, deltay, getGrid):
322 364
323 365 self.drvObj.driver.pcolor(self.idframe,
324 366 self.xpos,
325 367 self.ypos,
326 368 z,
327 369 x,
328 370 y,
329 371 self.xmin,
330 372 self.xmax,
331 373 self.ymin,
332 374 self.ymax,
333 375 self.minvalue,
334 376 self.maxvalue,
335 377 deltax,
336 378 deltay,
337 379 getGrid,
338 380 self.xaxisastime,
339 381 self.timefmt)
340 382
341 383 def plotBasicLine(self,x, y, color):
342 384 """
343 385 Inputs:
344 386 x:
345 387
346 388 y:
347 389
348 390 color:
349 391 """
350 392 self.drvObj.driver.basicLine(self.idframe, self.xpos, self.ypos, x, y, self.xmin, self.xmax, self.ymin, self.ymax, color)
351 393 No newline at end of file
@@ -1,512 +1,515
1 1 import plplot
2 2 import numpy
3 3 import sys
4 4 import plplot #condicional
5 5
6 6 import matplotlib as mpl
7 7 #mpl.use('TKAgg')
8 8 import matplotlib.pyplot as plt
9 9
10 10 class Driver:
11 11 def __init__(self,driver, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
12 12 if driver == "plplot":
13 13 self.driver = PlplotDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
14 14 elif driver == "mpl":
15 15 self.driver = MplDriver(idfigure, xw, yw, wintitle, overplot, colormap, colorbar)
16 16 else:
17 17 raise ValueError, "The driver: %s is not defined"%driver
18 18
19 19 class PlplotDriver:
20 20
21 21 __isDriverOpen = False
22 22 pldriver = None
23 23 __xg = None
24 24 __yg = None
25 25 def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
26 26
27 27 if idfigure == None:
28 28 raise ValueError, 'idfigure input must be defined'
29 29
30 30 self.idfigure = idfigure
31 31 self.xw = xw
32 32 self.yw = yw
33 33 self.wintitle = wintitle
34 34 self.overplot = overplot
35 35 self.colormap = colormap
36 36 self.colorbar = colorbar
37 37
38 38 def setFigure(self):
39 39 """
40 40 previous configuration to open(init) the plplot driver
41 41 """
42 42 plplot.plsstrm(self.idfigure)
43 43 plplot.plparseopts([self.wintitle],plplot.PL_PARSE_FULL)
44 44 plplot.plsetopt("geometry", "%dx%d"%(self.xw, self.yw))
45 45
46 def selectFigure(self):
47
48 plplot.plsstrm(self.idfigure)
46 49
47 50 def openDriver(self, pldriver=None):
48 51 if pldriver == None:
49 52 if sys.platform == "linux":
50 53 pldriver = "xcairo"
51 54
52 55 if sys.platform == "linux2":
53 56 pldriver = "xcairo"
54 57
55 58 elif sys.platform == "darwin":
56 59 pldriver = "xwin"
57 60
58 61 else:
59 62 pldriver = ""
60 63
61 64 plplot.plsdev("xwin") #para pruebas
62 65 plplot.plscolbg(255,255,255)
63 66 plplot.plscol0(1,0,0,0)
64 67 plplot.plinit()
65 68 plplot.plspause(False)
66 69
67 70 self.pldriver = pldriver
68 71
69 72 def closeDriver(self):
70 73 pass
71 74
72 75 def openPage(self):
73 76 plplot.plbop()
74 77 plplot.pladv(0)
75 78
76 79 def closePage(self):
77 80 plplot.pleop()
78 81
79 82 def openFigure(self):
80 83 plplot.plbop()
81 84 plplot.pladv(0)
82 85
83 86 def closeFigure(self):
84 87 plplot.pleop()
85 88
86 89 def setSubPlots(self,nrows, ncolumns):
87 90 plplot.plssub(ncolumns,nrows)
88 91
89 92 def setPlotLabels(self, id, xlabel, ylabel, title):
90 93 plplot.pllab(xlabel, ylabel, title)
91 94
92 95 def setFigTitle(self, title,color="black", szchar=0.55):
93 96 self.setSubPlots(1, 0)
94 97 plplot.pladv(0)
95 98 plplot.plvpor(0., 1., 0., 1.)
96 99
97 100 if color == "black":
98 101 plplot.plcol0(1)
99 102 if color == "white":
100 103 plplot.plcol0(15)
101 104
102 105 plplot.plschr(0.0,szchar)
103 106 plplot.plmtex("t",-1., 0.5, 0.5, title)
104 107
105 108 def plotColorbar(self, minvalue, maxvalue, xpos, ypos):
106 109 # plplot.pladv(id)
107 110 # plplot.plschr(0.0,szchar-0.05)
108 111 xmin = 0; xmax = 1
109 112 ymin = minvalue; ymax = maxvalue
110 113 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
111 114 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
112 115 plplot.plbox("bc", 0.0, 0, "bcmtsv", 0.0, 0)
113 116
114 117 data = numpy.arange(256)
115 118 data = numpy.reshape(data, (1,-1))
116 119
117 120 plplot.plimage(data,
118 121 float(xmin),
119 122 float(xmax),
120 123 float(ymin),
121 124 float(ymax),
122 125 0.,
123 126 255.,
124 127 float(xmin),
125 128 float(xmax),
126 129 float(ymin),
127 130 float(ymax))
128 131
129 132
130 133 def __getGrid(self, x, y, deltax=None, deltay=None):
131 134
132 135 if not(len(x)>0 and len(y)>0):
133 136 raise ValueError, "x axis and y axis are empty"
134 137
135 138 if deltax == None: deltax = x[-1] - x[-2]
136 139 if deltay == None: deltay = y[-1] - y[-2]
137 140
138 141 x1 = numpy.append(x, x[-1] + deltax)
139 142 y1 = numpy.append(y, y[-1] + deltay)
140 143
141 144 xg = (numpy.multiply.outer(x1, numpy.ones(len(y1))))
142 145 yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1))
143 146
144 147 return xg, yg
145 148
146 149
147 150 def pcolor(self, id, xpos, ypos, data, x, y, xmin, xmax, ymin, ymax, zmin, zmax, deltax=None, deltay=None, getGrid=True, xaxisastime = False, timefmt="%H:%M"):
148 151
149 152 plplot.pladv(id)
150 153 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
151 154 plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax))
152 155
153 156 if xaxisastime:
154 157 timedelta = (xmax - xmin + 1)/8.
155 158
156 159 if getGrid:
157 160 self.__xg, self.__yg = self.__getGrid(x, y, deltax, deltay)
158 161
159 162 if deltax == None: deltax = x[-1] - x[0]
160 163 # if deltay == None: deltay = y[-1] - y[-2]
161 164
162 165 xmin = x[0]
163 166 xmax = xmin + deltax
164 167
165 168 plplot.plimagefr(data,
166 169 float(xmin),
167 170 float(xmax),
168 171 float(ymin),
169 172 float(ymax),
170 173 0.,
171 174 0.,
172 175 float(zmin),
173 176 float(zmax),
174 177 plplot.pltr2,
175 178 self.__xg,
176 179 self.__yg)
177 180
178 181 if xaxisastime:
179 182 plplot.pltimefmt(timefmt)
180 183 xopt = "bcstd"
181 184 yopt = "bcst"
182 185 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
183 186 else:
184 187 xopt = "bcst"
185 188 yopt = "bcst"
186 189 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
187 190
188 191
189 192 def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar=0.6, xaxisastime = False, timefmt="%H:%M"):
190 193 """
191 194 xopt, yopt: entradas que no se aplican en MPL
192 195 """
193 196 plplot.pladv(id)
194 197 plplot.plschr(0.0,szchar-0.05)
195 198 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
196 199 plplot.plwind(float(xmin), float(xmax), float(ymin), float(ymax))
197 200 if xaxisastime:
198 201 plplot.pltimefmt(timefmt)
199 202 timedelta = (xmax - xmin + 1)/8.
200 203 plplot.plbox(xopt, timedelta, 3, yopt, 0.0, 0)
201 204 else:
202 205 plplot.plbox(xopt, 0.0, 0, yopt, 0.0, 0)
203 206
204 207 def refresh(self):
205 208 plplot.plflush()
206 209
207 210 def show(self):
208 211 plplot.plspause(True)
209 212 plplot.plend()
210 213
211 214 def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color):
212 215
213 216 """
214 217 Inputs:
215 218 x: datos en el eje x
216 219
217 220 y: datos en el eje y
218 221
219 222 xmin, xmax: intervalo de datos en el eje x
220 223
221 224 ymin, ymax: intervalo de datos en el eje y
222 225
223 226 color: color de la linea a dibujarse
224 227
225 228 id: identificador del plot, en este caso indica al frame que pertenece, la posicion de cada
226 229 plot esta definido por xpos, ypos.
227 230
228 231 xpos,ypos: coordenadas que indican la posicion del plot en el frame
229 232
230 233 """
231 234
232 235 plplot.pladv(id)
233 236 plplot.plvpor(xpos[0], xpos[1], ypos[0], ypos[1])
234 237 plplot.plwind(float(xmin),float(xmax), float(ymin), float(ymax))
235 238
236 239 if color == "blue":
237 240 colline = 9
238 241 if color == "green":
239 242 colline = 3
240 243
241 244 plplot.plcol0(colline)
242 245 plplot.plline(x, y)
243 246 plplot.plcol0(1)
244 247 plplot.plbox("bcst", 0.0, 0, "bcst", 0.0, 0)
245 248
246 249 def save(self, filename):
247 250 curr_strm = plplot.plgstrm()
248 251 save_strm = plplot.plmkstrm()
249 252 plplot.plsetopt("geometry", "%dx%d"%(self.xw,self.yw))
250 253 plplot.plsdev("png")
251 254 plplot.plsfnam(filename)
252 255 plplot.plcpstrm(curr_strm,0)
253 256 plplot.plreplot()
254 257 plplot.plend1()
255 258 plplot.plsstrm(curr_strm)
256 259
257 260 def setColormap(self, colormap="gray"):
258 261
259 262 if colormap == None:
260 263 return
261 264
262 265 ncolor = None
263 266 rgb_lvl = None
264 267
265 268 # Routine for defining a specific color map 1 in HLS space.
266 269 # if gray is true, use basic grayscale variation from half-dark to light.
267 270 # otherwise use false color variation from blue (240 deg) to red (360 deg).
268 271
269 272 # Independent variable of control points.
270 273 i = numpy.array((0., 1.))
271 274 if colormap=="gray":
272 275 ncolor = 256
273 276 # Hue for control points. Doesn't matter since saturation is zero.
274 277 h = numpy.array((0., 0.))
275 278 # Lightness ranging from half-dark (for interest) to light.
276 279 l = numpy.array((0.5, 1.))
277 280 # Gray scale has zero saturation
278 281 s = numpy.array((0., 0.))
279 282
280 283 # number of cmap1 colours is 256 in this case.
281 284 plplot.plscmap1n(ncolor)
282 285 # Interpolate between control points to set up cmap1.
283 286 plplot.plscmap1l(0, i, h, l, s)
284 287
285 288 return None
286 289
287 290 if colormap == 'jet':
288 291 ncolor = 256
289 292 pos = numpy.zeros((ncolor))
290 293 r = numpy.zeros((ncolor))
291 294 g = numpy.zeros((ncolor))
292 295 b = numpy.zeros((ncolor))
293 296
294 297 for i in range(ncolor):
295 298 if(i <= 35.0/100*(ncolor-1)): rf = 0.0
296 299 elif (i <= 66.0/100*(ncolor-1)): rf = (100.0/31)*i/(ncolor-1) - 35.0/31
297 300 elif (i <= 89.0/100*(ncolor-1)): rf = 1.0
298 301 else: rf = (-100.0/22)*i/(ncolor-1) + 111.0/22
299 302
300 303 if(i <= 12.0/100*(ncolor-1)): gf = 0.0
301 304 elif(i <= 38.0/100*(ncolor-1)): gf = (100.0/26)*i/(ncolor-1) - 12.0/26
302 305 elif(i <= 64.0/100*(ncolor-1)): gf = 1.0
303 306 elif(i <= 91.0/100*(ncolor-1)): gf = (-100.0/27)*i/(ncolor-1) + 91.0/27
304 307 else: gf = 0.0
305 308
306 309 if(i <= 11.0/100*(ncolor-1)): bf = (50.0/11)*i/(ncolor-1) + 0.5
307 310 elif(i <= 34.0/100*(ncolor-1)): bf = 1.0
308 311 elif(i <= 65.0/100*(ncolor-1)): bf = (-100.0/31)*i/(ncolor-1) + 65.0/31
309 312 else: bf = 0
310 313
311 314 r[i] = rf
312 315 g[i] = gf
313 316 b[i] = bf
314 317
315 318 pos[i] = float(i)/float(ncolor-1)
316 319
317 320
318 321 plplot.plscmap1n(ncolor)
319 322 plplot.plscmap1l(1, pos, r, g, b)
320 323
321 324
322 325
323 326 if colormap=="br_green":
324 327 ncolor = 256
325 328 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
326 329 h = numpy.array((240., 0.))
327 330 # Lightness and saturation are constant (values taken from C example).
328 331 l = numpy.array((0.6, 0.6))
329 332 s = numpy.array((0.8, 0.8))
330 333
331 334 # number of cmap1 colours is 256 in this case.
332 335 plplot.plscmap1n(ncolor)
333 336 # Interpolate between control points to set up cmap1.
334 337 plplot.plscmap1l(0, i, h, l, s)
335 338
336 339 return None
337 340
338 341 if colormap=="tricolor":
339 342 ncolor = 3
340 343 # Hue ranges from blue (240 deg) to red (0 or 360 deg)
341 344 h = numpy.array((240., 0.))
342 345 # Lightness and saturation are constant (values taken from C example).
343 346 l = numpy.array((0.6, 0.6))
344 347 s = numpy.array((0.8, 0.8))
345 348
346 349 # number of cmap1 colours is 256 in this case.
347 350 plplot.plscmap1n(ncolor)
348 351 # Interpolate between control points to set up cmap1.
349 352 plplot.plscmap1l(0, i, h, l, s)
350 353
351 354 return None
352 355
353 356 if colormap == 'rgb' or colormap == 'rgb666':
354 357
355 358 color_sz = 6
356 359 ncolor = color_sz*color_sz*color_sz
357 360 pos = numpy.zeros((ncolor))
358 361 r = numpy.zeros((ncolor))
359 362 g = numpy.zeros((ncolor))
360 363 b = numpy.zeros((ncolor))
361 364 ind = 0
362 365 for ri in range(color_sz):
363 366 for gi in range(color_sz):
364 367 for bi in range(color_sz):
365 368 r[ind] = ri/(color_sz-1.0)
366 369 g[ind] = gi/(color_sz-1.0)
367 370 b[ind] = bi/(color_sz-1.0)
368 371 pos[ind] = ind/(ncolor-1.0)
369 372 ind += 1
370 373 rgb_lvl = [6,6,6] #Levels for RGB colors
371 374
372 375 if colormap == 'rgb676':
373 376 ncolor = 6*7*6
374 377 pos = numpy.zeros((ncolor))
375 378 r = numpy.zeros((ncolor))
376 379 g = numpy.zeros((ncolor))
377 380 b = numpy.zeros((ncolor))
378 381 ind = 0
379 382 for ri in range(8):
380 383 for gi in range(8):
381 384 for bi in range(4):
382 385 r[ind] = ri/(6-1.0)
383 386 g[ind] = gi/(7-1.0)
384 387 b[ind] = bi/(6-1.0)
385 388 pos[ind] = ind/(ncolor-1.0)
386 389 ind += 1
387 390 rgb_lvl = [6,7,6] #Levels for RGB colors
388 391
389 392 if colormap == 'rgb685':
390 393 ncolor = 6*8*5
391 394 pos = numpy.zeros((ncolor))
392 395 r = numpy.zeros((ncolor))
393 396 g = numpy.zeros((ncolor))
394 397 b = numpy.zeros((ncolor))
395 398 ind = 0
396 399 for ri in range(8):
397 400 for gi in range(8):
398 401 for bi in range(4):
399 402 r[ind] = ri/(6-1.0)
400 403 g[ind] = gi/(8-1.0)
401 404 b[ind] = bi/(5-1.0)
402 405 pos[ind] = ind/(ncolor-1.0)
403 406 ind += 1
404 407 rgb_lvl = [6,8,5] #Levels for RGB colors
405 408
406 409 if colormap == 'rgb884':
407 410 ncolor = 8*8*4
408 411 pos = numpy.zeros((ncolor))
409 412 r = numpy.zeros((ncolor))
410 413 g = numpy.zeros((ncolor))
411 414 b = numpy.zeros((ncolor))
412 415 ind = 0
413 416 for ri in range(8):
414 417 for gi in range(8):
415 418 for bi in range(4):
416 419 r[ind] = ri/(8-1.0)
417 420 g[ind] = gi/(8-1.0)
418 421 b[ind] = bi/(4-1.0)
419 422 pos[ind] = ind/(ncolor-1.0)
420 423 ind += 1
421 424 rgb_lvl = [8,8,4] #Levels for RGB colors
422 425
423 426 if ncolor == None:
424 raise ValueError, "The colormap selected is not valid"
427 raise ValueError, "The colormap selected (%s) is not valid" %(colormap)
425 428
426 429 plplot.plscmap1n(ncolor)
427 430 plplot.plscmap1l(1, pos, r, g, b)
428 431
429 432 return rgb_lvl
430 433
431 434
432 435 class MplDriver:
433 436 # fig = None
434 437 nrows = None
435 438 ncolumns = None
436 439 __axesId = None
437 440 __setData = None
438 441
439 442 def __init__(self, idfigure, xw, yw, wintitle, overplot, colormap, colorbar):
440 443
441 444 if idfigure == None:
442 445 raise ValueError, 'idfigure input must be defined'
443 446 self.idfigure = idfigure
444 447 self.xw = xw
445 448 self.yw = yw
446 449 self.wintitle = wintitle
447 450 self.overplot = overplot
448 451 self.colormap = colormap
449 452 self.colorbar = colorbar
450 453 self.__axesId = {}
451 454
452 455 def setFigure(self):
453 456 plt.ioff()
454 457 fig = plt.figure(self.idfigure)
455 458 fig.canvas.manager.set_window_title(self.wintitle)
456 459 fig.canvas.resize(self.xw,self.yw)
457 460 plt.ion()
458 461
459 462
460 463 def setColormap(self, colormap):
461 464 pass
462 465
463 466 def openDriver(self):
464 467 pass
465 468
466 469 def openFigure(self):
467 470 pass
468 471
469 472 def setFigTitle(self,title):
470 473 fig = plt.figure(self.idfigure)
471 474 fig.suptitle(title,fontsize=11, fontweight='bold')
472 475
473 476 def setSubPlots(self,nrows,ncolumns):
474 477 fig = plt.figure(self.idfigure)
475 478 self.nrows = nrows
476 479 self.ncolumns = ncolumns
477 480 #self.__axesId = fig.add_subplot(nrows,ncolumns)
478 481
479 482 def plotBox(self, id, xpos, ypos, xmin, xmax, ymin, ymax, minvalue, maxvalue, xopt, yopt, szchar, xaxisastime, timefmt):
480 483 fig = plt.figure(self.idfigure)
481 484 ax = fig.add_subplot(self.nrows,self.ncolumns,id)
482 485 ax.set_xlim([xmin,xmax])
483 486 ax.set_ylim([ymin,ymax])
484 487 self.__axesId.setdefault(id)
485 488 self.__axesId[id] = ax
486 489
487 490
488 491 def setPlotLabels(self, id, xlabel, ylabel, title):
489 492 ax = self.__axesId[id]
490 493 ax.set_xlabel(xlabel)
491 494 ax.set_ylabel(ylabel)
492 495 ax.set_title(title)
493 496
494 497 def basicLine(self, id, xpos, ypos, x, y, xmin, xmax, ymin, ymax, color):
495 498 ax = self.__axesId[id]
496 499
497 500 if self.__setData == None:
498 501 ax.plot(x,y,color)
499 502 self.__setData = True
500 503 else:
501 504 ax.lines[0].set_data(x,y)
502 505
503 506 def refresh(self):
504 507 plt.draw()
505 508
506 509
507 510 def plotColorbar(self):
508 511 pass
509 512
510 513
511 514 def closePage(self):
512 515 pass No newline at end of file
@@ -1,763 +1,763
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import glob
9 9 import time
10 10 import numpy
11 11 import fnmatch
12 12 import time, datetime
13 13
14 14 path = os.path.split(os.getcwd())[0]
15 15 sys.path.append(path)
16 16
17 17 from JROHeaderIO import *
18 18 from Data.JROData import JROData
19 19
20 20 def isNumber(str):
21 21 """
22 22 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
23 23
24 24 Excepciones:
25 25 Si un determinado string no puede ser convertido a numero
26 26 Input:
27 27 str, string al cual se le analiza para determinar si convertible a un numero o no
28 28
29 29 Return:
30 30 True : si el string es uno numerico
31 31 False : no es un string numerico
32 32 """
33 33 try:
34 34 float( str )
35 35 return True
36 36 except:
37 37 return False
38 38
39 39 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
40 40 """
41 41 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
42 42
43 43 Inputs:
44 44 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
45 45
46 46 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
47 47 segundos contados desde 01/01/1970.
48 48 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
49 49 segundos contados desde 01/01/1970.
50 50
51 51 Return:
52 52 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
53 53 fecha especificado, de lo contrario retorna False.
54 54
55 55 Excepciones:
56 56 Si el archivo no existe o no puede ser abierto
57 57 Si la cabecera no puede ser leida.
58 58
59 59 """
60 60 basicHeaderObj = BasicHeader()
61 61
62 62 try:
63 63 fp = open(filename,'rb')
64 64 except:
65 65 raise IOError, "The file %s can't be opened" %(filename)
66 66
67 67 sts = basicHeaderObj.read(fp)
68 68 fp.close()
69 69
70 70 if not(sts):
71 71 print "Skipping the file %s because it has not a valid header" %(filename)
72 72 return 0
73 73
74 74 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
75 75 return 0
76 76
77 77 return 1
78 78
79 79
80 80
81 81
82 82 class JRODataIO:
83 83
84 84 c = 3E8
85 85
86 86 basicHeaderObj = BasicHeader()
87 87
88 88 systemHeaderObj = SystemHeader()
89 89
90 90 radarControllerHeaderObj = RadarControllerHeader()
91 91
92 92 processingHeaderObj = ProcessingHeader()
93 93
94 94 online = 0
95 95
96 96 dtype = None
97 97
98 98 pathList = []
99 99
100 100 filenameList = []
101 101
102 102 filename = None
103 103
104 104 ext = None
105 105
106 106 flagNoMoreFiles = 0
107 107
108 108 flagIsNewFile = 1
109 109
110 110 flagTimeBlock = 0
111 111
112 112 flagIsNewBlock = 0
113 113
114 114 fp = None
115 115
116 116 firstHeaderSize = 0
117 117
118 118 basicHeaderSize = 24
119 119
120 120 versionFile = 1103
121 121
122 122 fileSize = None
123 123
124 124 ippSeconds = None
125 125
126 126 fileSizeByHeader = None
127 127
128 128 fileIndex = None
129 129
130 130 profileIndex = None
131 131
132 132 blockIndex = None
133 133
134 134 nTotalBlocks = None
135 135
136 136 maxTimeStep = 30
137 137
138 138 lastUTTime = None
139 139
140 140 datablock = None
141 141
142 142 dataOutObj = None
143 143
144 144 blocksize = None
145 145
146 146 def __init__(self):
147 147 pass
148 148
149 149 class JRODataReader(JRODataIO):
150 150
151 151 nReadBlocks = 0
152 152
153 153 def __init__(self):
154 154
155 155 pass
156 156
157 157 def createObjByDefault(self):
158 158 """
159 159
160 160 """
161 161 raise ValueError, "This method has not been implemented"
162 162
163 163 def getBlockDimension(self):
164 164
165 165 raise ValueError, "No implemented"
166 166
167 167 def __searchFilesOffLine(self,
168 168 path,
169 169 startDate,
170 170 endDate,
171 171 startTime=datetime.time(0,0,0),
172 172 endTime=datetime.time(23,59,59),
173 173 set=None,
174 174 expLabel="",
175 175 ext=".r"):
176 176 dirList = []
177 177 for thisPath in os.listdir(path):
178 178 if os.path.isdir(os.path.join(path,thisPath)):
179 179 dirList.append(thisPath)
180 180
181 181 if not(dirList):
182 182 return None, None
183 183
184 184 pathList = []
185 185 dateList = []
186 186
187 187 thisDate = startDate
188 188
189 189 while(thisDate <= endDate):
190 190 year = thisDate.timetuple().tm_year
191 191 doy = thisDate.timetuple().tm_yday
192 192
193 193 match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy))
194 194 if len(match) == 0:
195 195 thisDate += datetime.timedelta(1)
196 196 continue
197 197
198 198 pathList.append(os.path.join(path,match[0],expLabel))
199 199 dateList.append(thisDate)
200 200 thisDate += datetime.timedelta(1)
201 201
202 202 filenameList = []
203 203 for index in range(len(pathList)):
204 204
205 205 thisPath = pathList[index]
206 206 fileList = glob.glob1(thisPath, "*%s" %ext)
207 207 fileList.sort()
208 208
209 209 #Busqueda de datos en el rango de horas indicados
210 210 thisDate = dateList[index]
211 211 startDT = datetime.datetime.combine(thisDate, startTime)
212 212 endDT = datetime.datetime.combine(thisDate, endTime)
213 213
214 214 startUtSeconds = time.mktime(startDT.timetuple())
215 215 endUtSeconds = time.mktime(endDT.timetuple())
216 216
217 217 for file in fileList:
218 218
219 219 filename = os.path.join(thisPath,file)
220 220
221 221 if isThisFileinRange(filename, startUtSeconds, endUtSeconds):
222 222 filenameList.append(filename)
223 223
224 224 if not(filenameList):
225 225 return None, None
226 226
227 227 self.filenameList = filenameList
228 228
229 229 return pathList, filenameList
230 230
231 231 def setup(self,dataOutObj=None,
232 232 path=None,
233 233 startDate=None,
234 234 endDate=None,
235 235 startTime=datetime.time(0,0,0),
236 236 endTime=datetime.time(23,59,59),
237 237 set=0,
238 238 expLabel = "",
239 239 ext = None,
240 240 online = 0):
241 241
242 242 if path == None:
243 243 raise ValueError, "The path is not valid"
244 244
245 245 if ext == None:
246 246 ext = self.ext
247 247
248 248 if dataOutObj == None:
249 249 dataOutObj = self.createObjByDefault()
250 250
251 251 self.dataOutObj = dataOutObj
252 252
253 253 if online:
254 254 pass
255 255
256 256 else:
257 print "Searching files in offline mode"
257 print "Searching files in offline mode ..."
258 258 pathList, filenameList = self.__searchFilesOffLine(path, startDate, endDate, startTime, endTime, set, expLabel, ext)
259 259
260 260 if not(pathList):
261 261 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
262 262 datetime.datetime.combine(startDate,startTime).ctime(),
263 263 datetime.datetime.combine(endDate,endTime).ctime())
264 264
265 265 sys.exit(-1)
266 266
267 267
268 268 self.fileIndex = -1
269 269 self.pathList = pathList
270 270 self.filenameList = filenameList
271 271
272 272 self.online = online
273 273 ext = ext.lower()
274 274 self.ext = ext
275 275
276 276 if not(self.setNextFile()):
277 277 if (startDate!=None) and (endDate!=None):
278 278 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
279 279 elif startDate != None:
280 280 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
281 281 else:
282 282 print "No files"
283 283
284 284 sys.exit(-1)
285 285
286 286 # self.updateDataHeader()
287 287
288 288 return self.dataOutObj
289 289
290 290 def __setNextFileOffline(self):
291 291 idFile = self.fileIndex
292 292
293 293 while (True):
294 294 idFile += 1
295 295 if not(idFile < len(self.filenameList)):
296 296 self.flagNoMoreFiles = 1
297 297 print "No more Files"
298 298 return 0
299 299
300 300 filename = self.filenameList[idFile]
301 301
302 302 if not(self.__verifyFile(filename)):
303 303 continue
304 304
305 305 fileSize = os.path.getsize(filename)
306 306 fp = open(filename,'rb')
307 307 break
308 308
309 309 self.flagIsNewFile = 1
310 310 self.fileIndex = idFile
311 311 self.filename = filename
312 312 self.fileSize = fileSize
313 313 self.fp = fp
314 314
315 315 print "Setting the file: %s"%self.filename
316 316
317 317 return 1
318 318
319 319
320 320
321 321 def setNextFile(self):
322 322 if self.fp != None:
323 323 self.fp.close()
324 324
325 325 if self.online:
326 326 newFile = self.__setNextFileOnline()
327 327 else:
328 328 newFile = self.__setNextFileOffline()
329 329
330 330 if not(newFile):
331 331 return 0
332 332
333 333 self.__readFirstHeader()
334 334 self.nReadBlocks = 0
335 335 return 1
336 336
337 337 def __setNewBlock(self):
338 338 if self.fp == None:
339 339 return 0
340 340
341 341 if self.flagIsNewFile:
342 342 return 1
343 343
344 344 self.lastUTTime = self.basicHeaderObj.utc
345 345 currentSize = self.fileSize - self.fp.tell()
346 346 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
347 347
348 348 if (currentSize >= neededSize):
349 349 self.__rdBasicHeader()
350 350 return 1
351 351
352 352 if not(self.setNextFile()):
353 353 return 0
354 354
355 355 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
356 356
357 357 self.flagTimeBlock = 0
358 358
359 359 if deltaTime > self.maxTimeStep:
360 360 self.flagTimeBlock = 1
361 361
362 362 return 1
363 363
364 364
365 365 def readNextBlock(self):
366 366 if not(self.__setNewBlock()):
367 367 return 0
368 368
369 369 if not(self.readBlock()):
370 370 return 0
371 371
372 372 return 1
373 373
374 374 def __rdProcessingHeader(self, fp=None):
375 375 if fp == None:
376 376 fp = self.fp
377 377
378 378 self.processingHeaderObj.read(fp)
379 379
380 380 def __rdRadarControllerHeader(self, fp=None):
381 381 if fp == None:
382 382 fp = self.fp
383 383
384 384 self.radarControllerHeaderObj.read(fp)
385 385
386 386 def __rdSystemHeader(self, fp=None):
387 387 if fp == None:
388 388 fp = self.fp
389 389
390 390 self.systemHeaderObj.read(fp)
391 391
392 392 def __rdBasicHeader(self, fp=None):
393 393 if fp == None:
394 394 fp = self.fp
395 395
396 396 self.basicHeaderObj.read(fp)
397 397
398 398
399 399 def __readFirstHeader(self):
400 400 self.__rdBasicHeader()
401 401 self.__rdSystemHeader()
402 402 self.__rdRadarControllerHeader()
403 403 self.__rdProcessingHeader()
404 404
405 405 self.firstHeaderSize = self.basicHeaderObj.size
406 406
407 407 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
408 408 if datatype == 0:
409 409 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
410 410 elif datatype == 1:
411 411 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
412 412 elif datatype == 2:
413 413 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
414 414 elif datatype == 3:
415 415 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
416 416 elif datatype == 4:
417 417 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
418 418 elif datatype == 5:
419 419 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
420 420 else:
421 421 raise ValueError, 'Data type was not defined'
422 422
423 423 self.dtype = datatype_str
424 424 self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
425 425 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
426 426 # self.dataOutObj.channelList = numpy.arange(self.systemHeaderObj.numChannels)
427 427 # self.dataOutObj.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
428 428 self.getBlockDimension()
429 429
430 430
431 431 def __verifyFile(self, filename, msgFlag=True):
432 432 msg = None
433 433 try:
434 434 fp = open(filename, 'rb')
435 435 currentPosition = fp.tell()
436 436 except:
437 437 if msgFlag:
438 438 print "The file %s can't be opened" % (filename)
439 439 return False
440 440
441 441 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
442 442
443 443 if neededSize == 0:
444 444 basicHeaderObj = BasicHeader()
445 445 systemHeaderObj = SystemHeader()
446 446 radarControllerHeaderObj = RadarControllerHeader()
447 447 processingHeaderObj = ProcessingHeader()
448 448
449 449 try:
450 450 if not( basicHeaderObj.read(fp) ): raise ValueError
451 451 if not( systemHeaderObj.read(fp) ): raise ValueError
452 452 if not( radarControllerHeaderObj.read(fp) ): raise ValueError
453 453 if not( processingHeaderObj.read(fp) ): raise ValueError
454 454 data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
455 455
456 456 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
457 457
458 458 except:
459 459 if msgFlag:
460 460 print "\tThe file %s is empty or it hasn't enough data" % filename
461 461
462 462 fp.close()
463 463 return False
464 464 else:
465 465 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
466 466
467 467 fp.close()
468 468 fileSize = os.path.getsize(filename)
469 469 currentSize = fileSize - currentPosition
470 470 if currentSize < neededSize:
471 471 if msgFlag and (msg != None):
472 472 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
473 473 return False
474 474
475 475 return True
476 476
477 477 def getData():
478 478 pass
479 479
480 480 def hasNotDataInBuffer():
481 481 pass
482 482
483 483 def readBlock():
484 484 pass
485 485
486 486 class JRODataWriter(JRODataIO):
487 487
488 488 """
489 489 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
490 490 de los datos siempre se realiza por bloques.
491 491 """
492 492
493 493 blockIndex = 0
494 494
495 495 path = None
496 496
497 497 setFile = None
498 498
499 499 profilesPerBlock = None
500 500
501 501 blocksPerFile = None
502 502
503 503 nWriteBlocks = 0
504 504
505 505 def __init__(self, dataOutObj=None):
506 506 raise ValueError, "Not implemented"
507 507
508 508
509 509 def hasAllDataInBuffer(self):
510 510 raise ValueError, "Not implemented"
511 511
512 512
513 513 def setBlockDimension(self):
514 514 raise ValueError, "Not implemented"
515 515
516 516
517 517 def writeBlock(self):
518 518 raise ValueError, "No implemented"
519 519
520 520
521 521 def putData(self):
522 522 raise ValueError, "No implemented"
523 523
524 524
525 525 def __writeFirstHeader(self):
526 526 """
527 527 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
528 528
529 529 Affected:
530 530 __dataType
531 531
532 532 Return:
533 533 None
534 534 """
535 535
536 536 # CALCULAR PARAMETROS
537 537
538 538 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
539 539 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
540 540
541 541 self.__writeBasicHeader()
542 542 self.__wrSystemHeader()
543 543 self.__wrRadarControllerHeader()
544 544 self.__wrProcessingHeader()
545 545 self.dtype = self.dataOutObj.dtype
546 546
547 547
548 548 def __writeBasicHeader(self, fp=None):
549 549 """
550 550 Escribe solo el Basic header en el file creado
551 551
552 552 Return:
553 553 None
554 554 """
555 555 if fp == None:
556 556 fp = self.fp
557 557
558 558 self.basicHeaderObj.write(fp)
559 559
560 560
561 561 def __wrSystemHeader(self, fp=None):
562 562 """
563 563 Escribe solo el System header en el file creado
564 564
565 565 Return:
566 566 None
567 567 """
568 568 if fp == None:
569 569 fp = self.fp
570 570
571 571 self.systemHeaderObj.write(fp)
572 572
573 573
574 574 def __wrRadarControllerHeader(self, fp=None):
575 575 """
576 576 Escribe solo el RadarController header en el file creado
577 577
578 578 Return:
579 579 None
580 580 """
581 581 if fp == None:
582 582 fp = self.fp
583 583
584 584 self.radarControllerHeaderObj.write(fp)
585 585
586 586
587 587 def __wrProcessingHeader(self, fp=None):
588 588 """
589 589 Escribe solo el Processing header en el file creado
590 590
591 591 Return:
592 592 None
593 593 """
594 594 if fp == None:
595 595 fp = self.fp
596 596
597 597 self.processingHeaderObj.write(fp)
598 598
599 599
600 600 def setNextFile(self):
601 601 """
602 602 Determina el siguiente file que sera escrito
603 603
604 604 Affected:
605 605 self.filename
606 606 self.subfolder
607 607 self.fp
608 608 self.setFile
609 609 self.flagIsNewFile
610 610
611 611 Return:
612 612 0 : Si el archivo no puede ser escrito
613 613 1 : Si el archivo esta listo para ser escrito
614 614 """
615 615 ext = self.ext
616 616 path = self.path
617 617
618 618 if self.fp != None:
619 619 self.fp.close()
620 620
621 621 timeTuple = time.localtime( self.dataOutObj.dataUtcTime)
622 622 subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
623 623
624 624 doypath = os.path.join( path, subfolder )
625 625 if not( os.path.exists(doypath) ):
626 626 os.mkdir(doypath)
627 627 self.setFile = -1 #inicializo mi contador de seteo
628 628 else:
629 629 filesList = os.listdir( doypath )
630 630 if len( filesList ) > 0:
631 631 filesList = sorted( filesList, key=str.lower )
632 632 filen = filesList[-1]
633 633 # el filename debera tener el siguiente formato
634 634 # 0 1234 567 89A BCDE (hex)
635 635 # x YYYY DDD SSS .ext
636 636 if isNumber( filen[8:11] ):
637 637 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
638 638 else:
639 639 self.setFile = -1
640 640 else:
641 641 self.setFile = -1 #inicializo mi contador de seteo
642 642
643 643 setFile = self.setFile
644 644 setFile += 1
645 645
646 646 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
647 647 timeTuple.tm_year,
648 648 timeTuple.tm_yday,
649 649 setFile,
650 650 ext )
651 651
652 652 filename = os.path.join( path, subfolder, file )
653 653
654 654 fp = open( filename,'wb' )
655 655
656 656 self.blockIndex = 0
657 657
658 658 #guardando atributos
659 659 self.filename = filename
660 660 self.subfolder = subfolder
661 661 self.fp = fp
662 662 self.setFile = setFile
663 663 self.flagIsNewFile = 1
664 664
665 665 self.getDataHeader()
666 666
667 667 print 'Writing the file: %s'%self.filename
668 668
669 669 self.__writeFirstHeader()
670 670
671 671 return 1
672 672
673 673
674 674 def __setNewBlock(self):
675 675 """
676 676 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
677 677
678 678 Return:
679 679 0 : si no pudo escribir nada
680 680 1 : Si escribio el Basic el First Header
681 681 """
682 682 if self.fp == None:
683 683 self.setNextFile()
684 684
685 685 if self.flagIsNewFile:
686 686 return 1
687 687
688 688 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
689 689 self.__writeBasicHeader()
690 690 return 1
691 691
692 692 if not( self.setNextFile() ):
693 693 return 0
694 694
695 695 return 1
696 696
697 697
698 698 def writeNextBlock(self):
699 699 """
700 700 Selecciona el bloque siguiente de datos y los escribe en un file
701 701
702 702 Return:
703 703 0 : Si no hizo pudo escribir el bloque de datos
704 704 1 : Si no pudo escribir el bloque de datos
705 705 """
706 706 if not( self.__setNewBlock() ):
707 707 return 0
708 708
709 709 self.writeBlock()
710 710
711 711 return 1
712 712
713 713
714 714 def getDataHeader(self):
715 715 """Obtiene una copia del First Header Affected: self.basicHeaderObj self.
716 716 systemHeaderObj self.radarControllerHeaderObj self.processingHeaderObj self.
717 717 dtype Return: None
718 718 """
719 719
720 720 raise ValueError, "No implemented"
721 721
722 722 def setup(self, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None):
723 723 """
724 724 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
725 725
726 726 Inputs:
727 727 path : el path destino en el cual se escribiran los files a crear
728 728 format : formato en el cual sera salvado un file
729 729 set : el setebo del file
730 730
731 731 Return:
732 732 0 : Si no realizo un buen seteo
733 733 1 : Si realizo un buen seteo
734 734 """
735 735
736 736 if ext == None:
737 737 ext = self.ext
738 738
739 739 ext = ext.lower()
740 740
741 741 self.ext = ext
742 742
743 743 self.path = path
744 744
745 745 self.setFile = set - 1
746 746
747 747 self.blocksPerFile = blocksPerFile
748 748
749 749 self.profilesPerBlock = profilesPerBlock
750 750
751 751 if not(self.setNextFile()):
752 752 print "There isn't a next file"
753 753 return 0
754 754
755 755 self.setBlockDimension()
756 756
757 757 return 1
758 758
759 759
760 760
761 761
762 762
763 763
@@ -1,777 +1,777
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import numpy
9 9 import glob
10 10 import fnmatch
11 11 import time, datetime
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from JROHeaderIO import *
17 17 from JRODataIO import JRODataReader
18 18 from JRODataIO import JRODataWriter
19 19
20 20 from Data.JROData import Spectra
21 21
22 22 class SpectraReader(JRODataReader):
23 23 """
24 24 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
25 25 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
26 26 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
27 27
28 28 paresCanalesIguales * alturas * perfiles (Self Spectra)
29 29 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
30 30 canales * alturas (DC Channels)
31 31
32 32 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
33 33 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
34 34 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
35 35 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
36 36
37 37 Example:
38 38 dpath = "/home/myuser/data"
39 39
40 40 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
41 41
42 42 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
43 43
44 44 readerObj = SpectraReader()
45 45
46 46 readerObj.setup(dpath, startTime, endTime)
47 47
48 48 while(True):
49 49
50 50 readerObj.getData()
51 51
52 52 print readerObj.data_spc
53 53
54 54 print readerObj.data_cspc
55 55
56 56 print readerObj.data_dc
57 57
58 58 if readerObj.flagNoMoreFiles:
59 59 break
60 60
61 61 """
62 62
63 63 pts2read_SelfSpectra = 0
64 64
65 65 pts2read_CrossSpectra = 0
66 66
67 67 pts2read_DCchannels = 0
68 68
69 69 ext = ".pdata"
70 70
71 71 optchar = "P"
72 72
73 73 dataOutObj = None
74 74
75 75 nRdChannels = None
76 76
77 77 nRdPairs = None
78 78
79 79 rdPairList = []
80 80
81 81
82 82 def __init__(self, dataOutObj=None):
83 83 """
84 84 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
85 85
86 86 Inputs:
87 87 dataOutObj : Objeto de la clase Spectra. Este objeto sera utilizado para
88 88 almacenar un perfil de datos cada vez que se haga un requerimiento
89 89 (getData). El perfil sera obtenido a partir del buffer de datos,
90 90 si el buffer esta vacio se hara un nuevo proceso de lectura de un
91 91 bloque de datos.
92 92 Si este parametro no es pasado se creara uno internamente.
93 93
94 94 Affected:
95 95 self.dataOutObj
96 96
97 97 Return : None
98 98 """
99 99
100 100 self.pts2read_SelfSpectra = 0
101 101
102 102 self.pts2read_CrossSpectra = 0
103 103
104 104 self.pts2read_DCchannels = 0
105 105
106 106 self.datablock = None
107 107
108 108 self.utc = None
109 109
110 110 self.ext = ".pdata"
111 111
112 112 self.optchar = "P"
113 113
114 114 self.basicHeaderObj = BasicHeader()
115 115
116 116 self.systemHeaderObj = SystemHeader()
117 117
118 118 self.radarControllerHeaderObj = RadarControllerHeader()
119 119
120 120 self.processingHeaderObj = ProcessingHeader()
121 121
122 122 self.online = 0
123 123
124 124 self.fp = None
125 125
126 126 self.idFile = None
127 127
128 128 self.dtype = None
129 129
130 130 self.fileSizeByHeader = None
131 131
132 132 self.filenameList = []
133 133
134 134 self.filename = None
135 135
136 136 self.fileSize = None
137 137
138 138 self.firstHeaderSize = 0
139 139
140 140 self.basicHeaderSize = 24
141 141
142 142 self.pathList = []
143 143
144 144 self.lastUTTime = 0
145 145
146 146 self.maxTimeStep = 30
147 147
148 148 self.flagNoMoreFiles = 0
149 149
150 150 self.set = 0
151 151
152 152 self.path = None
153 153
154 154 self.delay = 3 #seconds
155 155
156 156 self.nTries = 3 #quantity tries
157 157
158 158 self.nFiles = 3 #number of files for searching
159 159
160 160 self.nReadBlocks = 0
161 161
162 162 self.flagIsNewFile = 1
163 163
164 164 self.ippSeconds = 0
165 165
166 166 self.flagTimeBlock = 0
167 167
168 168 self.flagIsNewBlock = 0
169 169
170 170 self.nTotalBlocks = 0
171 171
172 172 self.blocksize = 0
173 173
174 174
175 175 def createObjByDefault(self):
176 176
177 177 dataObj = Spectra()
178 178
179 179 return dataObj
180 180
181 181 def __hasNotDataInBuffer(self):
182 182 return 1
183 183
184 184
185 185 def getBlockDimension(self):
186 186 """
187 187 Obtiene la cantidad de puntos a leer por cada bloque de datos
188 188
189 189 Affected:
190 190 self.nRdChannels
191 191 self.nRdPairs
192 192 self.pts2read_SelfSpectra
193 193 self.pts2read_CrossSpectra
194 194 self.pts2read_DCchannels
195 195 self.blocksize
196 196 self.dataOutObj.nChannels
197 197 self.dataOutObj.nPairs
198 198
199 199 Return:
200 200 None
201 201 """
202 202 self.nRdChannels = 0
203 203 self.nRdPairs = 0
204 204 self.rdPairList = []
205 205
206 206 for i in range(0, self.processingHeaderObj.totalSpectra*2, 2):
207 207 if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]:
208 208 self.nRdChannels = self.nRdChannels + 1 #par de canales iguales
209 209 else:
210 210 self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes
211 211 self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1]))
212 212
213 213 pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock
214 214
215 215 self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read)
216 216 self.blocksize = self.pts2read_SelfSpectra
217 217
218 218 if self.processingHeaderObj.flag_cspc:
219 219 self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read)
220 220 self.blocksize += self.pts2read_CrossSpectra
221 221
222 222 if self.processingHeaderObj.flag_dc:
223 223 self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights)
224 224 self.blocksize += self.pts2read_DCchannels
225 225
226 226 # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
227 227
228 228
229 229 def readBlock(self):
230 230 """
231 231 Lee el bloque de datos desde la posicion actual del puntero del archivo
232 232 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
233 233 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
234 234 es seteado a 0
235 235
236 236 Return: None
237 237
238 238 Variables afectadas:
239 239
240 240 self.flagIsNewFile
241 241 self.flagIsNewBlock
242 242 self.nTotalBlocks
243 243 self.data_spc
244 244 self.data_cspc
245 245 self.data_dc
246 246
247 247 Exceptions:
248 248 Si un bloque leido no es un bloque valido
249 249 """
250 250 blockOk_flag = False
251 251 fpointer = self.fp.tell()
252 252
253 253 spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra )
254 254 spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
255 255
256 256 if self.processingHeaderObj.flag_cspc:
257 257 cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra )
258 258 cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D
259 259
260 260 if self.processingHeaderObj.flag_dc:
261 261 dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) )
262 262 dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D
263 263
264 264
265 265 if not(self.processingHeaderObj.shif_fft):
266 266 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
267 267
268 268 if self.processingHeaderObj.flag_cspc:
269 269 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
270 270
271 271
272 272 spc = numpy.transpose( spc, (0,2,1) )
273 273 self.data_spc = spc
274 274
275 275 if self.processingHeaderObj.flag_cspc:
276 276 cspc = numpy.transpose( cspc, (0,2,1) )
277 277 self.data_cspc = cspc['real'] + cspc['imag']*1j
278 278 else:
279 279 self.data_cspc = None
280 280
281 281 if self.processingHeaderObj.flag_dc:
282 282 self.data_dc = dc['real'] + dc['imag']*1j
283 283 else:
284 284 self.data_dc = None
285 285
286 286 self.flagIsNewFile = 0
287 287 self.flagIsNewBlock = 1
288 288
289 289 self.nTotalBlocks += 1
290 290 self.nReadBlocks += 1
291 291
292 292 return 1
293 293
294 294
295 295 def getData(self):
296 296 """
297 297 Copia el buffer de lectura a la clase "Spectra",
298 298 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
299 299 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
300 300
301 301 Return:
302 302 0 : Si no hay mas archivos disponibles
303 303 1 : Si hizo una buena copia del buffer
304 304
305 305 Affected:
306 306 self.dataOutObj
307 307
308 308 self.flagTimeBlock
309 309 self.flagIsNewBlock
310 310 """
311 311
312 312 if self.flagNoMoreFiles: return 0
313 313
314 314 self.flagTimeBlock = 0
315 315 self.flagIsNewBlock = 0
316 316
317 317 if self.__hasNotDataInBuffer():
318 318
319 319 if not( self.readNextBlock() ):
320 320 return 0
321 321
322 322 # self.updateDataHeader()
323 323
324 324 if self.flagNoMoreFiles == 1:
325 325 print 'Process finished'
326 326 return 0
327 327
328 328 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
329 329
330 330 if self.data_dc == None:
331 331 self.dataOutObj.flagNoData = True
332 332 return 0
333 333
334 334
335 335 self.dataOutObj.data_spc = self.data_spc
336 336
337 337 self.dataOutObj.data_cspc = self.data_cspc
338 338
339 339 self.dataOutObj.data_dc = self.data_dc
340 340
341 341 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
342 342
343 343 self.dataOutObj.flagNoData = False
344 344
345 345 self.dataOutObj.dtype = self.dtype
346 346
347 347 self.dataOutObj.nChannels = self.nRdChannels
348 348
349 349 self.dataOutObj.nPairs = self.nRdPairs
350 350
351 351 self.dataOutObj.pairsList = self.rdPairList
352 352
353 353 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
354 354
355 355 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
356 356
357 357 self.dataOutObj.nFFTPoints = self.processingHeaderObj.profilesPerBlock
358 358
359 359 self.dataOutObj.nIncohInt = self.processingHeaderObj.nIncohInt
360 360
361 361
362 362 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
363 363
364 364 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
365 365
366 366 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
367 367
368 368 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
369 369
370 self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
370 self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds
371 371
372 372 self.dataOutObj.flagShiftFFT = self.processingHeaderObj.shif_fft
373 373
374 374 # self.profileIndex += 1
375 375
376 376 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
377 377
378 378 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
379 379
380 380 return self.dataOutObj.data_spc
381 381
382 382
383 383 class SpectraWriter(JRODataWriter):
384 384
385 385 """
386 386 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
387 387 de los datos siempre se realiza por bloques.
388 388 """
389 389
390 390 ext = ".pdata"
391 391
392 392 optchar = "P"
393 393
394 394 shape_spc_Buffer = None
395 395
396 396 shape_cspc_Buffer = None
397 397
398 398 shape_dc_Buffer = None
399 399
400 400 data_spc = None
401 401
402 402 data_cspc = None
403 403
404 404 data_dc = None
405 405
406 406 wrPairList = []
407 407
408 408 nWrPairs = 0
409 409
410 410 nWrChannels = 0
411 411
412 412 # dataOutObj = None
413 413
414 414 def __init__(self, dataOutObj=None):
415 415 """
416 416 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
417 417
418 418 Affected:
419 419 self.dataOutObj
420 420 self.basicHeaderObj
421 421 self.systemHeaderObj
422 422 self.radarControllerHeaderObj
423 423 self.processingHeaderObj
424 424
425 425 Return: None
426 426 """
427 427 if dataOutObj == None:
428 428 dataOutObj = Spectra()
429 429
430 430 if not( isinstance(dataOutObj, Spectra) ):
431 431 raise ValueError, "in SpectraReader, dataOutObj must be an Spectra class object"
432 432
433 433 self.dataOutObj = dataOutObj
434 434
435 435 self.nTotalBlocks = 0
436 436
437 437 self.nWrChannels = self.dataOutObj.nChannels
438 438
439 439 # if len(pairList) > 0:
440 440 # self.wrPairList = pairList
441 441 #
442 442 # self.nWrPairs = len(pairList)
443 443
444 444 self.wrPairList = self.dataOutObj.pairsList
445 445
446 446 self.nWrPairs = self.dataOutObj.nPairs
447 447
448 448
449 449
450 450
451 451
452 452 # self.data_spc = None
453 453 # self.data_cspc = None
454 454 # self.data_dc = None
455 455
456 456 # self.fp = None
457 457
458 458 # self.flagIsNewFile = 1
459 459 #
460 460 # self.nTotalBlocks = 0
461 461 #
462 462 # self.flagIsNewBlock = 0
463 463 #
464 464 # self.flagNoMoreFiles = 0
465 465 #
466 466 # self.setFile = None
467 467 #
468 468 # self.dtype = None
469 469 #
470 470 # self.path = None
471 471 #
472 472 # self.noMoreFiles = 0
473 473 #
474 474 # self.filename = None
475 475 #
476 476 # self.basicHeaderObj = BasicHeader()
477 477 #
478 478 # self.systemHeaderObj = SystemHeader()
479 479 #
480 480 # self.radarControllerHeaderObj = RadarControllerHeader()
481 481 #
482 482 # self.processingHeaderObj = ProcessingHeader()
483 483
484 484
485 485 def hasAllDataInBuffer(self):
486 486 return 1
487 487
488 488
489 489 def setBlockDimension(self):
490 490 """
491 491 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
492 492
493 493 Affected:
494 494 self.shape_spc_Buffer
495 495 self.shape_cspc_Buffer
496 496 self.shape_dc_Buffer
497 497
498 498 Return: None
499 499 """
500 500 self.shape_spc_Buffer = (self.dataOutObj.nChannels,
501 501 self.processingHeaderObj.nHeights,
502 502 self.processingHeaderObj.profilesPerBlock)
503 503
504 504 self.shape_cspc_Buffer = (self.dataOutObj.nPairs,
505 505 self.processingHeaderObj.nHeights,
506 506 self.processingHeaderObj.profilesPerBlock)
507 507
508 508 self.shape_dc_Buffer = (self.dataOutObj.nChannels,
509 509 self.processingHeaderObj.nHeights)
510 510
511 511
512 512 def writeBlock(self):
513 513 """
514 514 Escribe el buffer en el file designado
515 515
516 516 Affected:
517 517 self.data_spc
518 518 self.data_cspc
519 519 self.data_dc
520 520 self.flagIsNewFile
521 521 self.flagIsNewBlock
522 522 self.nTotalBlocks
523 523 self.nWriteBlocks
524 524
525 525 Return: None
526 526 """
527 527
528 528 spc = numpy.transpose( self.data_spc, (0,2,1) )
529 529 if not( self.processingHeaderObj.shif_fft ):
530 530 spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
531 531 data = spc.reshape((-1))
532 532 data.tofile(self.fp)
533 533
534 534 if self.data_cspc != None:
535 535 data = numpy.zeros( self.shape_cspc_Buffer, self.dtype )
536 536 cspc = numpy.transpose( self.data_cspc, (0,2,1) )
537 537 if not( self.processingHeaderObj.shif_fft ):
538 538 cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
539 539 data['real'] = cspc.real
540 540 data['imag'] = cspc.imag
541 541 data = data.reshape((-1))
542 542 data.tofile(self.fp)
543 543
544 544 if self.data_dc != None:
545 545 data = numpy.zeros( self.shape_dc_Buffer, self.dtype )
546 546 dc = self.data_dc
547 547 data['real'] = dc.real
548 548 data['imag'] = dc.imag
549 549 data = data.reshape((-1))
550 550 data.tofile(self.fp)
551 551
552 552 self.data_spc.fill(0)
553 553 self.data_dc.fill(0)
554 554 if self.data_cspc != None:
555 555 self.data_cspc.fill(0)
556 556
557 557 self.flagIsNewFile = 0
558 558 self.flagIsNewBlock = 1
559 559 self.nTotalBlocks += 1
560 560 self.nWriteBlocks += 1
561 561 self.blockIndex += 1
562 562
563 563
564 564 def putData(self):
565 565 """
566 566 Setea un bloque de datos y luego los escribe en un file
567 567
568 568 Affected:
569 569 self.data_spc
570 570 self.data_cspc
571 571 self.data_dc
572 572
573 573 Return:
574 574 0 : Si no hay data o no hay mas files que puedan escribirse
575 575 1 : Si se escribio la data de un bloque en un file
576 576 """
577 577 self.flagIsNewBlock = 0
578 578
579 579 if self.dataOutObj.flagNoData:
580 580 return 0
581 581
582 582 if self.dataOutObj.flagTimeBlock:
583 583 self.data_spc.fill(0)
584 584 self.data_cspc.fill(0)
585 585 self.data_dc.fill(0)
586 586 self.setNextFile()
587 587
588 588 if self.flagIsNewFile == 0:
589 589 self.getBasicHeader()
590 590
591 591 self.data_spc = self.dataOutObj.data_spc
592 592 self.data_cspc = self.dataOutObj.data_cspc
593 593 self.data_dc = self.dataOutObj.data_dc
594 594
595 595 # #self.processingHeaderObj.dataBlocksPerFile)
596 596 if self.hasAllDataInBuffer():
597 597 # self.getDataHeader()
598 598 self.writeNextBlock()
599 599
600 600 if self.flagNoMoreFiles:
601 601 #print 'Process finished'
602 602 return 0
603 603
604 604 return 1
605 605
606 606
607 607 def __getProcessFlags(self):
608 608
609 609 processFlags = 0
610 610
611 611 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
612 612 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
613 613 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
614 614 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
615 615 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
616 616 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
617 617
618 618 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
619 619
620 620
621 621
622 622 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
623 623 PROCFLAG.DATATYPE_SHORT,
624 624 PROCFLAG.DATATYPE_LONG,
625 625 PROCFLAG.DATATYPE_INT64,
626 626 PROCFLAG.DATATYPE_FLOAT,
627 627 PROCFLAG.DATATYPE_DOUBLE]
628 628
629 629
630 630 for index in range(len(dtypeList)):
631 631 if self.dataOutObj.dtype == dtypeList[index]:
632 632 dtypeValue = datatypeValueList[index]
633 633 break
634 634
635 635 processFlags += dtypeValue
636 636
637 637 if self.dataOutObj.flagDecodeData:
638 638 processFlags += PROCFLAG.DECODE_DATA
639 639
640 640 if self.dataOutObj.flagDeflipData:
641 641 processFlags += PROCFLAG.DEFLIP_DATA
642 642
643 643 if self.dataOutObj.code != None:
644 644 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
645 645
646 646 if self.dataOutObj.nIncohInt > 1:
647 647 processFlags += PROCFLAG.INCOHERENT_INTEGRATION
648 648
649 649 if self.dataOutObj.data_dc != None:
650 650 processFlags += PROCFLAG.SAVE_CHANNELS_DC
651 651
652 652 return processFlags
653 653
654 654
655 655 def __getBlockSize(self):
656 656 '''
657 657 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra
658 658 '''
659 659
660 660 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
661 661 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
662 662 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
663 663 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
664 664 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
665 665 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
666 666
667 667 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
668 668 datatypeValueList = [1,2,4,8,4,8]
669 669 for index in range(len(dtypeList)):
670 670 if self.dataOutObj.dtype == dtypeList[index]:
671 671 datatypeValue = datatypeValueList[index]
672 672 break
673 673
674 674
675 675 pts2write = self.dataOutObj.nHeights * self.dataOutObj.nFFTPoints
676 676
677 677 pts2write_SelfSpectra = int(self.nWrChannels * pts2write)
678 678 blocksize = (pts2write_SelfSpectra*datatypeValue)
679 679
680 680 if self.dataOutObj.data_cspc != None:
681 681 pts2write_CrossSpectra = int(self.nWrPairs * pts2write)
682 682 blocksize += (pts2write_CrossSpectra*datatypeValue*2)
683 683
684 684 if self.dataOutObj.data_dc != None:
685 685 pts2write_DCchannels = int(self.nWrChannels * self.dataOutObj.nHeights)
686 686 blocksize += (pts2write_DCchannels*datatypeValue*2)
687 687
688 688 blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO
689 689
690 690 return blocksize
691 691
692 692
693 693 def getBasicHeader(self):
694 694 self.basicHeaderObj.size = self.basicHeaderSize #bytes
695 695 self.basicHeaderObj.version = self.versionFile
696 696 self.basicHeaderObj.dataBlock = self.nTotalBlocks
697 697
698 utc = numpy.floor(self.dataOutObj.dataUtcTime)
699 milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0
698 utc = numpy.floor(self.dataOutObj.utctime)
699 milisecond = (self.dataOutObj.utctime - utc)* 1000.0
700 700
701 701 self.basicHeaderObj.utc = utc
702 702 self.basicHeaderObj.miliSecond = milisecond
703 703 self.basicHeaderObj.timeZone = 0
704 704 self.basicHeaderObj.dstFlag = 0
705 705 self.basicHeaderObj.errorCount = 0
706 706
707 707 def getDataHeader(self):
708 708
709 709 """
710 710 Obtiene una copia del First Header
711 711
712 712 Affected:
713 713 self.systemHeaderObj
714 714 self.radarControllerHeaderObj
715 715 self.dtype
716 716
717 717 Return:
718 718 None
719 719 """
720 720
721 721 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
722 722 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
723 723 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
724 724
725 725 self.getBasicHeader()
726 726
727 727 processingHeaderSize = 40 # bytes
728 728 self.processingHeaderObj.dtype = 0 # Voltage
729 729 self.processingHeaderObj.blockSize = self.__getBlockSize()
730 730 self.processingHeaderObj.profilesPerBlock = self.dataOutObj.nFFTPoints
731 731 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
732 732 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
733 733 self.processingHeaderObj.processFlags = self.__getProcessFlags()
734 734 self.processingHeaderObj.nCohInt = 1# Cuando la data de origen es de tipo Spectra
735 735 self.processingHeaderObj.nIncohInt = self.dataOutObj.nIncohInt
736 736 self.processingHeaderObj.totalSpectra = self.dataOutObj.nPairs + self.dataOutObj.nChannels
737 737
738 738 if self.processingHeaderObj.totalSpectra > 0:
739 739 channelList = []
740 740 for channel in range(self.dataOutObj.nChannels):
741 741 channelList.append(channel)
742 742 channelList.append(channel)
743 743
744 744 pairsList = []
745 745 for pair in self.dataOutObj.pairsList:
746 746 pairsList.append(pair[0])
747 747 pairsList.append(pair[1])
748 748 spectraComb = channelList + pairsList
749 749 spectraComb = numpy.array(spectraComb,dtype="u1")
750 750 self.processingHeaderObj.spectraComb = spectraComb
751 751 sizeOfSpcComb = len(spectraComb)
752 752 processingHeaderSize += sizeOfSpcComb
753 753
754 754 if self.dataOutObj.code != None:
755 755 self.processingHeaderObj.code = self.dataOutObj.code
756 756 self.processingHeaderObj.nCode = self.dataOutObj.nCode
757 757 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
758 758 nCodeSize = 4 # bytes
759 759 nBaudSize = 4 # bytes
760 760 codeSize = 4 # bytes
761 761 sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOutObj.nCode * self.dataOutObj.nBaud)
762 762 processingHeaderSize += sizeOfCode
763 763
764 764 if self.processingHeaderObj.nWindows != 0:
765 765 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
766 766 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
767 767 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
768 768 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
769 769 sizeOfFirstHeight = 4
770 770 sizeOfdeltaHeight = 4
771 771 sizeOfnHeights = 4
772 772 sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows
773 773 processingHeaderSize += sizeOfWindows
774 774
775 775 self.processingHeaderObj.size = processingHeaderSize
776 776
777 777 No newline at end of file
@@ -1,584 +1,584
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import numpy
9 9 import glob
10 10 import fnmatch
11 11 import time, datetime
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from JROHeaderIO import *
17 17 from JRODataIO import JRODataReader
18 18 from JRODataIO import JRODataWriter
19 19
20 20 from Data.JROData import Voltage
21 21
22 22 class VoltageReader(JRODataReader):
23 23 """
24 24 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
25 25 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
26 26 perfiles*alturas*canales) son almacenados en la variable "buffer".
27 27
28 28 perfiles * alturas * canales
29 29
30 30 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
31 31 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
32 32 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
33 33 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
34 34
35 35 Example:
36 36
37 37 dpath = "/home/myuser/data"
38 38
39 39 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
40 40
41 41 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
42 42
43 43 readerObj = VoltageReader()
44 44
45 45 readerObj.setup(dpath, startTime, endTime)
46 46
47 47 while(True):
48 48
49 49 #to get one profile
50 50 profile = readerObj.getData()
51 51
52 52 #print the profile
53 53 print profile
54 54
55 55 #If you want to see all datablock
56 56 print readerObj.datablock
57 57
58 58 if readerObj.flagNoMoreFiles:
59 59 break
60 60
61 61 """
62 62
63 63 ext = ".r"
64 64
65 65 optchar = "D"
66 66 dataOutObj = None
67 67
68 68
69 69 def __init__(self, dataOutObj=None):
70 70 """
71 71 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
72 72
73 73 Input:
74 74 dataOutObj : Objeto de la clase Voltage. Este objeto sera utilizado para
75 75 almacenar un perfil de datos cada vez que se haga un requerimiento
76 76 (getData). El perfil sera obtenido a partir del buffer de datos,
77 77 si el buffer esta vacio se hara un nuevo proceso de lectura de un
78 78 bloque de datos.
79 79 Si este parametro no es pasado se creara uno internamente.
80 80
81 81 Variables afectadas:
82 82 self.dataOutObj
83 83
84 84 Return:
85 85 None
86 86 """
87 87
88 88 self.datablock = None
89 89
90 90 self.utc = 0
91 91
92 92 self.ext = ".r"
93 93
94 94 self.optchar = "D"
95 95
96 96 self.basicHeaderObj = BasicHeader()
97 97
98 98 self.systemHeaderObj = SystemHeader()
99 99
100 100 self.radarControllerHeaderObj = RadarControllerHeader()
101 101
102 102 self.processingHeaderObj = ProcessingHeader()
103 103
104 104 self.online = 0
105 105
106 106 self.fp = None
107 107
108 108 self.idFile = None
109 109
110 110 self.dtype = None
111 111
112 112 self.fileSizeByHeader = None
113 113
114 114 self.filenameList = []
115 115
116 116 self.filename = None
117 117
118 118 self.fileSize = None
119 119
120 120 self.firstHeaderSize = 0
121 121
122 122 self.basicHeaderSize = 24
123 123
124 124 self.pathList = []
125 125
126 126 self.filenameList = []
127 127
128 128 self.lastUTTime = 0
129 129
130 130 self.maxTimeStep = 30
131 131
132 132 self.flagNoMoreFiles = 0
133 133
134 134 self.set = 0
135 135
136 136 self.path = None
137 137
138 138 self.profileIndex = 9999
139 139
140 140 self.delay = 3 #seconds
141 141
142 142 self.nTries = 3 #quantity tries
143 143
144 144 self.nFiles = 3 #number of files for searching
145 145
146 146 self.nReadBlocks = 0
147 147
148 148 self.flagIsNewFile = 1
149 149
150 150 self.ippSeconds = 0
151 151
152 152 self.flagTimeBlock = 0
153 153
154 154 self.flagIsNewBlock = 0
155 155
156 156 self.nTotalBlocks = 0
157 157
158 158 self.blocksize = 0
159 159
160 160 def createObjByDefault(self):
161 161
162 162 dataObj = Voltage()
163 163
164 164 return dataObj
165 165
166 166 def __hasNotDataInBuffer(self):
167 167 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
168 168 return 1
169 169 return 0
170 170
171 171
172 172 def getBlockDimension(self):
173 173 """
174 174 Obtiene la cantidad de puntos a leer por cada bloque de datos
175 175
176 176 Affected:
177 177 self.blocksize
178 178
179 179 Return:
180 180 None
181 181 """
182 182 pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels
183 183 self.blocksize = pts2read
184 184
185 185
186 186 def readBlock(self):
187 187 """
188 188 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
189 189 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
190 190 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
191 191 es seteado a 0
192 192
193 193 Inputs:
194 194 None
195 195
196 196 Return:
197 197 None
198 198
199 199 Affected:
200 200 self.profileIndex
201 201 self.datablock
202 202 self.flagIsNewFile
203 203 self.flagIsNewBlock
204 204 self.nTotalBlocks
205 205
206 206 Exceptions:
207 207 Si un bloque leido no es un bloque valido
208 208 """
209 209
210 210 junk = numpy.fromfile( self.fp, self.dtype, self.blocksize )
211 211
212 212 try:
213 213 junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) )
214 214 except:
215 215 print "The read block (%3d) has not enough data" %self.nReadBlocks
216 216 return 0
217 217
218 218 junk = numpy.transpose(junk, (2,0,1))
219 219 self.datablock = junk['real'] + junk['imag']*1j
220 220
221 221 self.profileIndex = 0
222 222
223 223 self.flagIsNewFile = 0
224 224 self.flagIsNewBlock = 1
225 225
226 226 self.nTotalBlocks += 1
227 227 self.nReadBlocks += 1
228 228
229 229 return 1
230 230
231 231
232 232 def getData(self):
233 233 """
234 234 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
235 235 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
236 236 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
237 237
238 238 Ademas incrementa el contador del buffer en 1.
239 239
240 240 Return:
241 241 data : retorna un perfil de voltages (alturas * canales) copiados desde el
242 242 buffer. Si no hay mas archivos a leer retorna None.
243 243
244 244 Variables afectadas:
245 245 self.dataOutObj
246 246 self.profileIndex
247 247
248 248 Affected:
249 249 self.dataOutObj
250 250 self.profileIndex
251 251 self.flagTimeBlock
252 252 self.flagIsNewBlock
253 253 """
254 254 if self.flagNoMoreFiles: return 0
255 255
256 256 self.flagTimeBlock = 0
257 257 self.flagIsNewBlock = 0
258 258
259 259 if self.__hasNotDataInBuffer():
260 260
261 261 if not( self.readNextBlock() ):
262 262 return 0
263 263
264 264 # self.updateDataHeader()
265 265
266 266 if self.flagNoMoreFiles == 1:
267 267 print 'Process finished'
268 268 return 0
269 269
270 270 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
271 271
272 272 if self.datablock == None:
273 273 self.dataOutObj.flagNoData = True
274 274 return 0
275 275
276 276 self.dataOutObj.data = self.datablock[:,self.profileIndex,:]
277 277
278 278 self.dataOutObj.dtype = self.dtype
279 279
280 280 self.dataOutObj.nChannels = self.systemHeaderObj.nChannels
281 281
282 282 self.dataOutObj.nHeights = self.processingHeaderObj.nHeights
283 283
284 284 self.dataOutObj.nProfiles = self.processingHeaderObj.profilesPerBlock
285 285
286 286 xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight
287 287
288 288 self.dataOutObj.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight)
289 289
290 290 self.dataOutObj.channelList = range(self.systemHeaderObj.nChannels)
291 291
292 292 self.dataOutObj.channelIndexList = range(self.systemHeaderObj.nChannels)
293 293
294 294 self.dataOutObj.flagTimeBlock = self.flagTimeBlock
295 295
296 self.dataOutObj.dataUtcTime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
296 self.dataOutObj.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds
297 297
298 298 self.dataOutObj.nCohInt = self.processingHeaderObj.nCohInt
299 299
300 300 self.dataOutObj.flagShiftFFT = False
301 301
302 302 if self.processingHeaderObj.code != None:
303 303 self.dataOutObj.nCode = self.processingHeaderObj.nCode
304 304
305 305 self.dataOutObj.nBaud = self.processingHeaderObj.nBaud
306 306
307 307 self.dataOutObj.code = self.processingHeaderObj.code
308 308
309 309 self.profileIndex += 1
310 310
311 311 self.dataOutObj.systemHeaderObj = self.systemHeaderObj.copy()
312 312
313 313 self.dataOutObj.radarControllerHeaderObj = self.radarControllerHeaderObj.copy()
314 314
315 315 self.dataOutObj.flagNoData = False
316 316
317 317 return self.dataOutObj.data
318 318
319 319
320 320 class VoltageWriter(JRODataWriter):
321 321 """
322 322 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
323 323 de los datos siempre se realiza por bloques.
324 324 """
325 325
326 326 ext = ".r"
327 327
328 328 optchar = "D"
329 329
330 330 shapeBuffer = None
331 331
332 332
333 333 def __init__(self, dataOutObj=None):
334 334 """
335 335 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
336 336
337 337 Affected:
338 338 self.dataOutObj
339 339
340 340 Return: None
341 341 """
342 342 if dataOutObj == None:
343 343 dataOutObj = Voltage()
344 344
345 345 if not( isinstance(dataOutObj, Voltage) ):
346 346 raise ValueError, "in VoltageReader, dataOutObj must be an Spectra class object"
347 347
348 348 self.dataOutObj = dataOutObj
349 349
350 350 self.nTotalBlocks = 0
351 351
352 352 self.profileIndex = 0
353 353
354 354 def hasAllDataInBuffer(self):
355 355 if self.profileIndex >= self.processingHeaderObj.profilesPerBlock:
356 356 return 1
357 357 return 0
358 358
359 359
360 360 def setBlockDimension(self):
361 361 """
362 362 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
363 363
364 364 Affected:
365 365 self.shape_spc_Buffer
366 366 self.shape_cspc_Buffer
367 367 self.shape_dc_Buffer
368 368
369 369 Return: None
370 370 """
371 371 self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock,
372 372 self.processingHeaderObj.nHeights,
373 373 self.systemHeaderObj.nChannels)
374 374
375 375 self.datablock = numpy.zeros((self.systemHeaderObj.nChannels,
376 376 self.processingHeaderObj.profilesPerBlock,
377 377 self.processingHeaderObj.nHeights),
378 378 dtype=numpy.dtype('complex'))
379 379
380 380
381 381 def writeBlock(self):
382 382 """
383 383 Escribe el buffer en el file designado
384 384
385 385 Affected:
386 386 self.profileIndex
387 387 self.flagIsNewFile
388 388 self.flagIsNewBlock
389 389 self.nTotalBlocks
390 390 self.blockIndex
391 391
392 392 Return: None
393 393 """
394 394 data = numpy.zeros( self.shapeBuffer, self.dtype )
395 395
396 396 junk = numpy.transpose(self.datablock, (1,2,0))
397 397
398 398 data['real'] = junk.real
399 399 data['imag'] = junk.imag
400 400
401 401 data = data.reshape( (-1) )
402 402
403 403 data.tofile( self.fp )
404 404
405 405 self.datablock.fill(0)
406 406
407 407 self.profileIndex = 0
408 408 self.flagIsNewFile = 0
409 409 self.flagIsNewBlock = 1
410 410
411 411 self.blockIndex += 1
412 412 self.nTotalBlocks += 1
413 413
414 414 def putData(self):
415 415 """
416 416 Setea un bloque de datos y luego los escribe en un file
417 417
418 418 Affected:
419 419 self.flagIsNewBlock
420 420 self.profileIndex
421 421
422 422 Return:
423 423 0 : Si no hay data o no hay mas files que puedan escribirse
424 424 1 : Si se escribio la data de un bloque en un file
425 425 """
426 426 self.flagIsNewBlock = 0
427 427
428 428 if self.dataOutObj.flagNoData:
429 429 return 0
430 430
431 431 if self.dataOutObj.flagTimeBlock:
432 432
433 433 self.datablock.fill(0)
434 434 self.profileIndex = 0
435 435 self.setNextFile()
436 436
437 437 if self.profileIndex == 0:
438 438 self.getBasicHeader()
439 439
440 440 self.datablock[:,self.profileIndex,:] = self.dataOutObj.data
441 441
442 442 self.profileIndex += 1
443 443
444 444 if self.hasAllDataInBuffer():
445 445 #if self.flagIsNewFile:
446 446 self.writeNextBlock()
447 447 # self.getDataHeader()
448 448
449 449 if self.flagNoMoreFiles:
450 450 #print 'Process finished'
451 451 return 0
452 452
453 453 return 1
454 454
455 455 def __getProcessFlags(self):
456 456
457 457 processFlags = 0
458 458
459 459 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
460 460 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
461 461 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
462 462 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
463 463 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
464 464 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
465 465
466 466 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
467 467
468 468
469 469
470 470 datatypeValueList = [PROCFLAG.DATATYPE_CHAR,
471 471 PROCFLAG.DATATYPE_SHORT,
472 472 PROCFLAG.DATATYPE_LONG,
473 473 PROCFLAG.DATATYPE_INT64,
474 474 PROCFLAG.DATATYPE_FLOAT,
475 475 PROCFLAG.DATATYPE_DOUBLE]
476 476
477 477
478 478 for index in range(len(dtypeList)):
479 479 if self.dataOutObj.dtype == dtypeList[index]:
480 480 dtypeValue = datatypeValueList[index]
481 481 break
482 482
483 483 processFlags += dtypeValue
484 484
485 485 if self.dataOutObj.flagDecodeData:
486 486 processFlags += PROCFLAG.DECODE_DATA
487 487
488 488 if self.dataOutObj.flagDeflipData:
489 489 processFlags += PROCFLAG.DEFLIP_DATA
490 490
491 491 if self.dataOutObj.code != None:
492 492 processFlags += PROCFLAG.DEFINE_PROCESS_CODE
493 493
494 494 if self.dataOutObj.nCohInt > 1:
495 495 processFlags += PROCFLAG.COHERENT_INTEGRATION
496 496
497 497 return processFlags
498 498
499 499
500 500 def __getBlockSize(self):
501 501 '''
502 502 Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage
503 503 '''
504 504
505 505 dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')])
506 506 dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')])
507 507 dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')])
508 508 dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')])
509 509 dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')])
510 510 dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')])
511 511
512 512 dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5]
513 513 datatypeValueList = [1,2,4,8,4,8]
514 514 for index in range(len(dtypeList)):
515 515 if self.dataOutObj.dtype == dtypeList[index]:
516 516 datatypeValue = datatypeValueList[index]
517 517 break
518 518
519 519 blocksize = int(self.dataOutObj.nHeights * self.dataOutObj.nChannels * self.dataOutObj.nProfiles * datatypeValue * 2)
520 520
521 521 return blocksize
522 522
523 523
524 524 def getBasicHeader(self):
525 525 self.basicHeaderObj.size = self.basicHeaderSize #bytes
526 526 self.basicHeaderObj.version = self.versionFile
527 527 self.basicHeaderObj.dataBlock = self.nTotalBlocks
528 528
529 utc = numpy.floor(self.dataOutObj.dataUtcTime)
530 milisecond = (self.dataOutObj.dataUtcTime - utc)* 1000.0
529 utc = numpy.floor(self.dataOutObj.utctime)
530 milisecond = (self.dataOutObj.utctime - utc)* 1000.0
531 531
532 532 self.basicHeaderObj.utc = utc
533 533 self.basicHeaderObj.miliSecond = milisecond
534 534 self.basicHeaderObj.timeZone = 0
535 535 self.basicHeaderObj.dstFlag = 0
536 536 self.basicHeaderObj.errorCount = 0
537 537
538 538 def getDataHeader(self):
539 539
540 540 """
541 541 Obtiene una copia del First Header
542 542
543 543 Affected:
544 544 self.systemHeaderObj
545 545 self.radarControllerHeaderObj
546 546 self.dtype
547 547
548 548 Return:
549 549 None
550 550 """
551 551
552 552 self.systemHeaderObj = self.dataOutObj.systemHeaderObj.copy()
553 553 self.systemHeaderObj.nChannels = self.dataOutObj.nChannels
554 554 self.radarControllerHeaderObj = self.dataOutObj.radarControllerHeaderObj.copy()
555 555
556 556 self.getBasicHeader()
557 557
558 558 processingHeaderSize = 40 # bytes
559 559 self.processingHeaderObj.dtype = 0 # Voltage
560 560 self.processingHeaderObj.blockSize = self.__getBlockSize()
561 561 self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock
562 562 self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile
563 563 self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOutObj.processingHeaderObj.nWindows
564 564 self.processingHeaderObj.processFlags = self.__getProcessFlags()
565 565 self.processingHeaderObj.nCohInt = self.dataOutObj.nCohInt
566 566 self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage
567 567 self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage
568 568
569 569 if self.dataOutObj.code != None:
570 570 self.processingHeaderObj.code = self.dataOutObj.code
571 571 self.processingHeaderObj.nCode = self.dataOutObj.nCode
572 572 self.processingHeaderObj.nBaud = self.dataOutObj.nBaud
573 573 codesize = int(8 + 4 * self.dataOutObj.nCode * self.dataOutObj.nBaud)
574 574 processingHeaderSize += codesize
575 575
576 576 if self.processingHeaderObj.nWindows != 0:
577 577 self.processingHeaderObj.firstHeight = self.dataOutObj.heightList[0]
578 578 self.processingHeaderObj.deltaHeight = self.dataOutObj.heightList[1] - self.dataOutObj.heightList[0]
579 579 self.processingHeaderObj.nHeights = self.dataOutObj.nHeights
580 580 self.processingHeaderObj.samplesWin = self.dataOutObj.nHeights
581 581 processingHeaderSize += 12
582 582
583 583 self.processingHeaderObj.size = processingHeaderSize
584 584 No newline at end of file
@@ -1,541 +1,596
1 1 '''
2 2
3 3 $Author$
4 4 $Id$
5 5 '''
6 6
7 7 import os, sys
8 8 import numpy
9 9 import time
10 10 import datetime
11 11 path = os.path.split(os.getcwd())[0]
12 12 sys.path.append(path)
13 13
14 from Data.JROData import SpectraHeis
14 from Data.JROData import Spectra, SpectraHeis
15 15 from IO.SpectraIO import SpectraWriter
16 16 from Graphics.schainPlotTypes import ScopeFigure, SpcFigure
17 17 #from JRONoise import Noise
18 18
19 19 class SpectraProcessor:
20 20 '''
21 21 classdocs
22 22 '''
23 23
24 24 dataInObj = None
25 25
26 26 dataOutObj = None
27 27
28 28 noiseObj = None
29 29
30 30 integratorObjList = []
31 31
32 32 writerObjList = []
33 33
34 34 integratorObjIndex = None
35 35
36 36 writerObjIndex = None
37 37
38 38 profIndex = 0 # Se emplea cuando el objeto de entrada es un Voltage
39 39
40 40
41 41 def __init__(self):
42 42 '''
43 43 Constructor
44 44 '''
45 45
46 46 self.integratorObjIndex = None
47 47 self.writerObjIndex = None
48 48 self.plotObjIndex = None
49 49 self.integratorOst = []
50 50 self.plotObjList = []
51 self.noiseObj = bjList = []
52 self.writerObjLiNone
51 self.noiseObj = []
52 self.writerObjList = []
53 53 self.buffer = None
54 54 self.profIndex = 0
55 55
56 56 def setup(self, dataInObj=None, dataOutObj=None, nFFTPoints=None, pairList=None):
57 57
58 58 if dataInObj == None:
59 59 raise ValueError, "This SpectraProcessor.setup() function needs dataInObj input variable"
60 60
61 61 if dataInObj.type == "Voltage":
62 62 if nFFTPoints == None:
63 63 raise ValueError, "This SpectraProcessor.setup() function needs nFFTPoints input variable"
64 else:
64
65
66
67 if dataInObj.type == "Spectra":
68 if nFFTPoints != None:
69 raise ValueError, "The nFFTPoints cannot be selected to this object type"
70
65 71 nFFTPoints = dataInObj.nFFTPoints
66 72
73 if pairList == None:
74 pairList = self.dataInObj.pairList
75
76 if pairList == None:
77 nPairs = 0
78 else:
79 nPairs = len(pairList)
80
67 81 self.dataInObj = dataInObj
68 82
69 83 if dataOutObj == None:
70 84 dataOutObj = Spectra()
71 85
72 86 self.dataOutObj = dataOutObj
87 self.dataOutObj.nFFTPoints = nFFTPoints
88 self.dataOutObj.pairList = pairList
89 self.dataOutObj.nPairs = nPairs
73 90
74 91 return self.dataOutObj
75 92
76 93 def init(self):
77 94
95 self.dataOutObj.flagNoData = True
96
97 if self.dataInObj.flagNoData:
98 return 0
99
78 100 self.integratorObjIndex = 0
79 101 self.writerObjIndex = 0
80 102 self.plotObjIndex = 0
103
104
105 if self.dataInObj.type == "Spectra":
106
107 self.dataOutObj.copy(self.dataInObj)
108 self.dataOutObj.flagNoData = False
109 return
110
81 111 if self.dataInObj.type == "Voltage":
82 112
83 113 if self.buffer == None:
84 self.buffer = numpy.zeros((self.nChannels,
85 self.nFFTPoints,
114 self.buffer = numpy.zeros((self.dataInObj.nChannels,
115 self.dataOutObj.nFFTPoints,
86 116 self.dataInObj.nHeights),
87 117 dtype='complex')
88 118
89 119 self.buffer[:,self.profIndex,:] = self.dataInObj.data
90 120 self.profIndex += 1
91 121
92 if self.profIndex == self.nFFTPoints:
122 if self.profIndex == self.dataOutObj.nFFTPoints:
123
124 self.__updateObjFromInput()
93 125 self.__getFft()
126
94 127 self.dataOutObj.flagNoData = False
95 128
96 129 self.buffer = None
97 130 self.profIndex = 0
98 return
99
100 self.dataOutObj.flagNoData = True
101 131
102 132 return
103 133
104 134 #Other kind of data
105 if self.dataInObj.type == "Spectra":
106 self.dataOutObj.copy(self.dataInObj)
107 self.dataOutObj.flagNoData = False
108 return
109
110 raise ValueError, "The dtype is not valid"
135 raise ValueError, "The type object %(s) is not valid " %(self.dataOutObj.type)
111 136
112 137 def __getFft(self):
113 138 """
114 139 Convierte valores de Voltaje a Spectra
115 140
116 141 Affected:
117 142 self.dataOutObj.data_spc
118 143 self.dataOutObj.data_cspc
119 144 self.dataOutObj.data_dc
120 145 self.dataOutObj.heightList
121 146 self.dataOutObj.m_BasicHeader
122 147 self.dataOutObj.m_ProcessingHeader
123 148 self.dataOutObj.radarControllerHeaderObj
124 149 self.dataOutObj.systemHeaderObj
125 150 self.profIndex
126 151 self.buffer
127 152 self.dataOutObj.flagNoData
128 153 self.dataOutObj.dtype
129 154 self.dataOutObj.nPairs
130 155 self.dataOutObj.nChannels
131 156 self.dataOutObj.nProfiles
132 157 self.dataOutObj.systemHeaderObj.numChannels
133 158 self.dataOutObj.m_ProcessingHeader.totalSpectra
134 159 self.dataOutObj.m_ProcessingHeader.profilesPerBlock
135 160 self.dataOutObj.m_ProcessingHeader.numHeights
136 161 self.dataOutObj.m_ProcessingHeader.spectraComb
137 162 self.dataOutObj.m_ProcessingHeader.shif_fft
138 163 """
139 164
140 if self.dataInObj.flagNoData:
141 return 0
142
143 165 fft_volt = numpy.fft.fft(self.buffer,axis=1)
144 166 dc = fft_volt[:,0,:]
145 167
146 168 #calculo de self-spectra
147 169 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
148 170 spc = fft_volt * numpy.conjugate(fft_volt)
149 171 spc = spc.real
150 172
151 173 blocksize = 0
152 174 blocksize += dc.size
153 175 blocksize += spc.size
154 176
155 177 cspc = None
156 178 pairIndex = 0
157 if self.pairList != None:
179 if self.dataOutObj.pairList != None:
158 180 #calculo de cross-spectra
159 cspc = numpy.zeros((self.nPairs, self.nFFTPoints, self.nHeights), dtype='complex')
181 cspc = numpy.zeros((self.dataOutObj.nPairs, self.dataOutObj.nFFTPoints, self.dataOutObj.nHeights), dtype='complex')
160 182 for pair in self.pairList:
161 183 cspc[pairIndex,:,:] = numpy.abs(fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]))
162 184 pairIndex += 1
163 185 blocksize += cspc.size
164 186
165 187 self.dataOutObj.data_spc = spc
166 188 self.dataOutObj.data_cspc = cspc
167 189 self.dataOutObj.data_dc = dc
168 self.dataOutObj.m_ProcessingHeader.blockSize = blocksize
169 self.dataOutObj.m_BasicHeader.utc = self.dataInObj.m_BasicHeader.utc
190 self.dataOutObj.blockSize = blocksize
170 191
171 192 # self.getNoise()
172 193
194 def __updateObjFromInput(self):
195
196 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
197 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
198 self.dataOutObj.channelList = self.dataInObj.channelList
199 self.dataOutObj.heightList = self.dataInObj.heightList
200 self.dataOutObj.dtype = self.dataInObj.dtype
201 self.dataOutObj.nHeights = self.dataInObj.nHeights
202 self.dataOutObj.nChannels = self.dataInObj.nChannels
203 self.dataOutObj.nBaud = self.dataInObj.nBaud
204 self.dataOutObj.nCode = self.dataInObj.nCode
205 self.dataOutObj.code = self.dataInObj.code
206 self.dataOutObj.nProfiles = self.dataOutObj.nFFTPoints
207 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
208 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
209 self.dataOutObj.utctime = self.dataInObj.utctime
210 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
211 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
212 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
213 self.dataOutObj.nIncohInt = 1
214
173 215 def addWriter(self, wrpath, blocksPerFile):
216
174 217 objWriter = SpectraWriter(self.dataOutObj)
175 218 objWriter.setup(wrpath, blocksPerFile)
176 219 self.writerObjList.append(objWriter)
177 220
178 221 def addIntegrator(self,N,timeInterval):
179 222
180 223 objIncohInt = IncoherentIntegration(N,timeInterval)
181 224 self.integratorObjList.append(objIncohInt)
182 225
183 226 def addSpc(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
227
184 228 spcObj = SpcFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
185 229 self.plotObjList.append(spcObj)
186 230
187 231 def plotSpc(self, idfigure=None,
188 232 xmin=None,
189 233 xmax=None,
190 234 ymin=None,
191 235 ymax=None,
192 236 minvalue=None,
193 237 maxvalue=None,
194 238 wintitle='',
195 239 driver='plplot',
196 colormap='br_greeen',
240 colormap='br_green',
197 241 colorbar=True,
198 242 showprofile=False,
199 243 save=False,
200 gpath=None):
244 gpath=None,
245 channelList = None):
201 246
202 247 if self.dataOutObj.flagNoData:
203 248 return 0
204 249
205 nframes = len(self.dataOutObj.channelList)
250 if channelList == None:
251 channelList = self.dataOutObj.channelList
252
253 nframes = len(channelList)
206 254
207 255 if len(self.plotObjList) <= self.plotObjIndex:
208 256 self.addSpc(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
209 257
210 258 x = numpy.arange(self.dataOutObj.nFFTPoints)
211 259
212 260 y = self.dataOutObj.heightList
213 261
214 channelList = self.dataOutObj.channelList
215
216 262 data = 10.*numpy.log10(self.dataOutObj.data_spc[channelList,:,:])
217 263 # noisedB = 10.*numpy.log10(noise)
218 264 noisedB = numpy.arange(len(channelList)+1)
219 265 noisedB = noisedB *1.2
220 266 titleList = []
221 267 for i in range(len(noisedB)):
222 268 title = "%.2f"%noisedB[i]
223 269 titleList.append(title)
224 270
225 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
271 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
226 272 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
227 273 figuretitle = "Spc Radar Data: %s"%dateTime
228 274
229 275 cleardata = True
230 276
231 277 plotObj = self.plotObjList[self.plotObjIndex]
232 278
233 279 plotObj.plotPcolor(data,
234 280 x,
235 281 y,
236 282 channelList,
237 283 xmin,
238 284 xmax,
239 285 ymin,
240 286 ymax,
241 287 minvalue,
242 288 maxvalue,
243 289 figuretitle,
244 290 None,
245 291 save,
246 292 gpath,
247 293 cleardata,
248 294 titleList)
249 295
250 296 self.plotObjIndex += 1
251 297
252 298
253 299 def writeData(self, wrpath, blocksPerFile):
300
254 301 if self.dataOutObj.flagNoData:
255 302 return 0
256 303
257 304 if len(self.writerObjList) <= self.writerObjIndex:
258 305 self.addWriter(wrpath, blocksPerFile)
259 306
260 307 self.writerObjList[self.writerObjIndex].putData()
261 308
262 309 self.writerObjIndex += 1
263 310
264 311 def integrator(self, N=None, timeInterval=None):
265 312
266 313 if self.dataOutObj.flagNoData:
267 314 return 0
268 315
269 316 if len(self.integratorObjList) <= self.integratorObjIndex:
270 317 self.addIntegrator(N,timeInterval)
271 318
272 319 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
273 320 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.m_BasicHeader.utc)
274 321
275 322 if myIncohIntObj.isReady:
276 323 self.dataOutObj.data_spc = myIncohIntObj.data
277 324 self.dataOutObj.nAvg = myIncohIntObj.navg
278 325 self.dataOutObj.m_ProcessingHeader.incoherentInt = self.dataInObj.m_ProcessingHeader.incoherentInt*myIncohIntObj.navg
279 326 self.dataOutObj.flagNoData = False
280 327
281 328 """Calcular el ruido"""
282 329 self.getNoise()
283 330 else:
284 331 self.dataOutObj.flagNoData = True
285 332
286 333 self.integratorObjIndex += 1
287 334
288 335
289 336 class SpectraHeisProcessor:
290 337
291 338 def __init__(self):
292 339
293 340 self.integratorObjIndex = None
294 341 self.writerObjIndex = None
295 342 self.plotObjIndex = None
296 343 self.integratorObjList = []
297 344 self.writerObjList = []
298 345 self.plotObjList = []
299 346 #self.noiseObj = Noise()
300 347
301 348 def setup(self, dataInObj, dataOutObj=None, nFFTPoints=None, pairList=None):
302 349
303 350 if nFFTPoints == None:
304 351 nFFTPoints = self.dataInObj.nHeights
305 352
306 353 self.dataInObj = dataInObj
307 354
308 355 if dataOutObj == None:
309 356 dataOutObj = SpectraHeis()
310 357
311 358 self.dataOutObj = dataOutObj
312 359
313 360 return self.dataOutObj
314 361
315 362 def init(self):
363
364 self.dataOutObj.flagNoData = True
365
366 if self.dataInObj.flagNoData:
367 return 0
368
316 369 self.integratorObjIndex = 0
317 370 self.writerObjIndex = 0
318 371 self.plotObjIndex = 0
319 372
320 373 if self.dataInObj.type == "Voltage":
374 self.__updateObjFromInput()
321 375 self.__getFft()
322 self.__updateFromObj()
323 376 self.dataOutObj.flagNoData = False
324 377 return
325 378
326 379 #Other kind of data
327 380 if self.dataInObj.type == "SpectraHeis":
328 381 self.dataOutObj.copy(self.dataInObj)
329 382 self.dataOutObj.flagNoData = False
330 383 return
331 384
332 385 raise ValueError, "The type is not valid"
333 386
334 def __updateFromObj(self):
387 def __updateObjFromInput(self):
388
335 389 self.dataOutObj.radarControllerHeaderObj = self.dataInObj.radarControllerHeaderObj.copy()
336 390 self.dataOutObj.systemHeaderObj = self.dataInObj.systemHeaderObj.copy()
337 391 self.dataOutObj.channelList = self.dataInObj.channelList
338 392 self.dataOutObj.heightList = self.dataInObj.heightList
339 393 self.dataOutObj.dtype = self.dataInObj.dtype
340 394 self.dataOutObj.nHeights = self.dataInObj.nHeights
341 395 self.dataOutObj.nChannels = self.dataInObj.nChannels
342 396 self.dataOutObj.nBaud = self.dataInObj.nBaud
343 397 self.dataOutObj.nCode = self.dataInObj.nCode
344 398 self.dataOutObj.code = self.dataInObj.code
345 399 self.dataOutObj.nProfiles = 1
346 400 self.dataOutObj.nFFTPoints = self.dataInObj.nHeights
347 401 self.dataOutObj.channelIndexList = self.dataInObj.channelIndexList
348 402 self.dataOutObj.flagNoData = self.dataInObj.flagNoData
349 403 self.dataOutObj.flagTimeBlock = self.dataInObj.flagTimeBlock
350 self.dataOutObj.dataUtcTime = self.dataInObj.dataUtcTime
404 self.dataOutObj.utctime = self.dataInObj.utctime
351 405 self.dataOutObj.flagDecodeData = self.dataInObj.flagDecodeData #asumo q la data esta decodificada
352 406 self.dataOutObj.flagDeflipData = self.dataInObj.flagDeflipData #asumo q la data esta sin flip
353 407 self.dataOutObj.flagShiftFFT = self.dataInObj.flagShiftFFT
354 408 self.dataOutObj.nIncohInt = 1
355 409
356 410 def __getFft(self):
357 if self.dataInObj.flagNoData:
358 return 0
359 411
360 412 fft_volt = numpy.fft.fft(self.dataInObj.data, axis=1)
361 413 #print fft_volt
362 414 #calculo de self-spectra
363 415 fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,))
364 416
365 417 spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))
366 418 self.dataOutObj.data_spc = spc
367 419
368 420 def getSpectra(self):
369 421
370 422 return self.dataOutObj.data_spc
371 423
372 424 def getFrecuencies(self):
373 425
374 426 print self.nFFTPoints
375 427 return numpy.arange(int(self.nFFTPoints))
376 428
377 429 def addIntegrator(self,N,timeInterval):
430
378 431 objIncohInt = IncoherentIntegration(N,timeInterval)
379 432 self.integratorObjList.append(objIncohInt)
380 433
381 434 def integrator(self, N=None, timeInterval=None):
435
382 436 if self.dataOutObj.flagNoData:
383 437 return 0
384 438
385 439 if len(self.integratorObjList) <= self.integratorObjIndex:
386 440 self.addIntegrator(N,timeInterval)
387 441
388 442 myIncohIntObj = self.integratorObjList[self.integratorObjIndex]
389 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.dataUtcTime)
443 myIncohIntObj.exe(data=self.dataOutObj.data_spc,timeOfData=self.dataOutObj.utctime)
390 444
391 445 if myIncohIntObj.isReady:
392 446 self.dataOutObj.data_spc = myIncohIntObj.data
393 447 self.dataOutObj.nIncohInt = self.dataOutObj.nIncohInt*myIncohIntObj.navg
394 448 self.dataOutObj.flagNoData = False
395 449
396 450 #self.getNoise(type="hildebrand",parm=myIncohIntObj.navg)
397 451 # self.getNoise(type="sort", parm=16)
398 452
399 453 else:
400 454 self.dataOutObj.flagNoData = True
401 455
402 456 self.integratorObjIndex += 1
403 457
404 458
405 459 def addScope(self, idfigure, nframes, wintitle, driver):
460
406 461 if idfigure==None:
407 462 idfigure = self.plotObjIndex
408 463
409 464 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
410 465 self.plotObjList.append(scopeObj)
411 466
412 467 def plotScope(self,
413 468 idfigure=None,
414 469 minvalue=None,
415 470 maxvalue=None,
416 471 xmin=None,
417 472 xmax=None,
418 473 wintitle='',
419 474 driver='plplot',
420 475 save=False,
421 476 gpath=None,
422 477 titleList=None,
423 478 xlabelList=None,
424 479 ylabelList=None):
425 480
426 481 if self.dataOutObj.flagNoData:
427 482 return 0
428 483
429 484 nframes = len(self.dataOutObj.channelList)
430 485
431 486 if len(self.plotObjList) <= self.plotObjIndex:
432 487 self.addScope(idfigure, nframes, wintitle, driver)
433 488
434 489
435 490 data1D = self.dataOutObj.data_spc
436 491
437 492 x = numpy.arange(self.dataOutObj.nHeights)
438 493
439 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
494 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
440 495
441 496 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
442 497 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
443 498
444 499 figureTitle = "Scope Plot Radar Data: " + date
445 500
446 501 plotObj = self.plotObjList[self.plotObjIndex]
447 502
448 503 plotObj.plot1DArray(data1D,
449 504 x,
450 505 self.dataOutObj.channelList,
451 506 xmin,
452 507 xmax,
453 508 minvalue,
454 509 maxvalue,
455 510 figureTitle,
456 511 save,
457 512 gpath)
458 513
459 514 self.plotObjIndex += 1
460 515
461 516 class IncoherentIntegration:
462 517
463 518 integ_counter = None
464 519 data = None
465 520 navg = None
466 521 buffer = None
467 522 nIncohInt = None
468 523
469 524 def __init__(self, N = None, timeInterval = None):
470 525 """
471 526 N
472 527 timeInterval - interval time [min], integer value
473 528 """
474 529
475 530 self.data = None
476 531 self.navg = None
477 532 self.buffer = None
478 533 self.timeOut = None
479 534 self.exitCondition = False
480 535 self.isReady = False
481 536 self.nIncohInt = N
482 537 self.integ_counter = 0
483 538 if timeInterval!=None:
484 539 self.timeIntervalInSeconds = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
485 540
486 541 if ((timeInterval==None) and (N==None)):
487 542 print 'N = None ; timeInterval = None'
488 543 sys.exit(0)
489 544 elif timeInterval == None:
490 545 self.timeFlag = False
491 546 else:
492 547 self.timeFlag = True
493 548
494 549
495 550 def exe(self,data,timeOfData):
496 551 """
497 552 data
498 553
499 554 timeOfData [seconds]
500 555 """
501 556
502 557 if self.timeFlag:
503 558 if self.timeOut == None:
504 559 self.timeOut = timeOfData + self.timeIntervalInSeconds
505 560
506 561 if timeOfData < self.timeOut:
507 562 if self.buffer == None:
508 563 self.buffer = data
509 564 else:
510 565 self.buffer = self.buffer + data
511 566 self.integ_counter += 1
512 567 else:
513 568 self.exitCondition = True
514 569
515 570 else:
516 571 if self.integ_counter < self.nIncohInt:
517 572 if self.buffer == None:
518 573 self.buffer = data
519 574 else:
520 575 self.buffer = self.buffer + data
521 576
522 577 self.integ_counter += 1
523 578
524 579 if self.integ_counter == self.nIncohInt:
525 580 self.exitCondition = True
526 581
527 582 if self.exitCondition:
528 583 self.data = self.buffer
529 584 self.navg = self.integ_counter
530 585 self.isReady = True
531 586 self.buffer = None
532 587 self.timeOut = None
533 588 self.integ_counter = 0
534 589 self.exitCondition = False
535 590
536 591 if self.timeFlag:
537 592 self.buffer = data
538 593 self.timeOut = timeOfData + self.timeIntervalInSeconds
539 594 else:
540 595 self.isReady = False
541 596 No newline at end of file
@@ -1,372 +1,372
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 11 import time
12 12
13 13 path = os.path.split(os.getcwd())[0]
14 14 sys.path.append(path)
15 15
16 16 from Data.JROData import Voltage
17 17 from IO.VoltageIO import VoltageWriter
18 18 from Graphics.schainPlotTypes import ScopeFigure, RTIFigure
19 19
20 20 class VoltageProcessor:
21 21
22 22 dataInObj = None
23 23 dataOutObj = None
24 24 integratorObjIndex = None
25 25 writerObjIndex = None
26 26 integratorObjList = None
27 27 writerObjList = None
28 28
29 29 def __init__(self):
30 30 self.integratorObjIndex = None
31 31 self.writerObjIndex = None
32 32 self.plotObjIndex = None
33 33 self.integratorObjList = []
34 34 self.writerObjList = []
35 35 self.plotObjList = []
36 36
37 37 def setup(self,dataInObj=None,dataOutObj=None):
38 38 self.dataInObj = dataInObj
39 39
40 40 if self.dataOutObj == None:
41 41 dataOutObj = Voltage()
42 42
43 43 self.dataOutObj = dataOutObj
44 44
45 45 return self.dataOutObj
46 46
47 47 def init(self):
48 48 self.integratorObjIndex = 0
49 49 self.writerObjIndex = 0
50 50 self.plotObjIndex = 0
51 51
52 52 if not(self.dataInObj.flagNoData):
53 53 self.dataOutObj.copy(self.dataInObj)
54 54 # No necesita copiar en cada init() los atributos de dataInObj
55 55 # la copia deberia hacerse por cada nuevo bloque de datos
56 56
57 57 def addRti(self, idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile):
58 58 rtiObj = RTIFigure(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
59 59 self.plotObjList.append(rtiObj)
60 60
61 61 def plotRti(self, idfigure=None,
62 62 starttime=None,
63 63 endtime=None,
64 64 rangemin=None,
65 65 rangemax=None,
66 66 minvalue=None,
67 67 maxvalue=None,
68 68 wintitle='',
69 69 driver='plplot',
70 70 colormap='br_greeen',
71 71 colorbar=True,
72 72 showprofile=False,
73 73 xrangestep=None,
74 74 save=False,
75 75 gpath=None):
76 76
77 77 if self.dataOutObj.flagNoData:
78 78 return 0
79 79
80 80 nframes = len(self.dataOutObj.channelList)
81 81
82 82 if len(self.plotObjList) <= self.plotObjIndex:
83 83 self.addRti(idfigure, nframes, wintitle, driver, colormap, colorbar, showprofile)
84 84
85 85 data = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
86 86 data = 10*numpy.log10(data.real)
87 87
88 # currenttime = self.dataOutObj.dataUtcTime
88 # currenttime = self.dataOutObj.utctime
89 89 # if timezone == "lt":
90 currenttime = self.dataOutObj.dataUtcTime - time.timezone
90 currenttime = self.dataOutObj.utctime - time.timezone
91 91
92 92 range = self.dataOutObj.heightList
93 93
94 94 channelList = self.dataOutObj.channelList
95 95
96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
96 thisdatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
97 97 dateTime = "%s"%(thisdatetime.strftime("%d-%b-%Y %H:%M:%S"))
98 98 date = "%s"%(thisdatetime.strftime("%d-%b-%Y"))
99 99
100 100 figuretitle = "RTI Plot Radar Data" #+ date
101 101
102 102 plotObj = self.plotObjList[self.plotObjIndex]
103 103
104 104 cleardata = False
105 105
106 106 plotObj.plotPcolor(data,
107 107 currenttime,
108 108 range,
109 109 channelList,
110 110 starttime,
111 111 endtime,
112 112 rangemin,
113 113 rangemax,
114 114 minvalue,
115 115 maxvalue,
116 116 figuretitle,
117 117 xrangestep,
118 118 save,
119 119 gpath,
120 120 cleardata)
121 121
122 122 self.plotObjIndex += 1
123 123
124 124 def addScope(self, idfigure, nframes, wintitle, driver):
125 125 if idfigure==None:
126 126 idfigure = self.plotObjIndex
127 127
128 128 scopeObj = ScopeFigure(idfigure, nframes, wintitle, driver)
129 129 self.plotObjList.append(scopeObj)
130 130
131 131 def plotScope(self,
132 132 idfigure=None,
133 133 minvalue=None,
134 134 maxvalue=None,
135 135 xmin=None,
136 136 xmax=None,
137 137 wintitle='',
138 138 driver='plplot',
139 139 save=False,
140 140 gpath=None,
141 141 titleList=None,
142 142 xlabelList=None,
143 143 ylabelList=None,
144 144 type="power"):
145 145
146 146 if self.dataOutObj.flagNoData:
147 147 return 0
148 148
149 149 nframes = len(self.dataOutObj.channelList)
150 150
151 151 if len(self.plotObjList) <= self.plotObjIndex:
152 152 self.addScope(idfigure, nframes, wintitle, driver)
153 153
154 154
155 155 if type=="power":
156 156 data1D = self.dataOutObj.data * numpy.conjugate(self.dataOutObj.data)
157 157 data1D = data1D.real
158 158
159 159 if type =="iq":
160 160 data1D = self.dataOutObj.data
161 161
162 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.dataUtcTime)
162 thisDatetime = datetime.datetime.fromtimestamp(self.dataOutObj.utctime)
163 163
164 164 dateTime = "%s"%(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
165 165 date = "%s"%(thisDatetime.strftime("%d-%b-%Y"))
166 166
167 167 figureTitle = "Scope Plot Radar Data: " + date
168 168
169 169 plotObj = self.plotObjList[self.plotObjIndex]
170 170
171 171 plotObj.plot1DArray(data1D,
172 172 self.dataOutObj.heightList,
173 173 self.dataOutObj.channelList,
174 174 xmin,
175 175 xmax,
176 176 minvalue,
177 177 maxvalue,
178 178 figureTitle,
179 179 save,
180 180 gpath)
181 181
182 182 self.plotObjIndex += 1
183 183
184 184
185 185 def addIntegrator(self, *args):
186 186 objCohInt = CoherentIntegrator(*args)
187 187 self.integratorObjList.append(objCohInt)
188 188
189 189 def addWriter(self, *args):
190 190 writerObj = VoltageWriter(self.dataOutObj)
191 191 writerObj.setup(*args)
192 192 self.writerObjList.append(writerObj)
193 193
194 194 def writeData(self, wrpath, blocksPerFile, profilesPerBlock):
195 195
196 196 if self.dataOutObj.flagNoData:
197 197 return 0
198 198
199 199 if len(self.writerObjList) <= self.writerObjIndex:
200 200 self.addWriter(wrpath, blocksPerFile, profilesPerBlock)
201 201
202 202 self.writerObjList[self.writerObjIndex].putData()
203 203
204 204 self.writerObjIndex += 1
205 205
206 206 def integrator(self, nCohInt=None, timeInterval=None, overlapping=False):
207 207
208 208 if self.dataOutObj.flagNoData:
209 209 return 0
210 210
211 211 if len(self.integratorObjList) <= self.integratorObjIndex:
212 212 self.addIntegrator(nCohInt, timeInterval, overlapping)
213 213
214 214 myCohIntObj = self.integratorObjList[self.integratorObjIndex]
215 215 myCohIntObj.exe(data = self.dataOutObj.data, datatime=None)
216 216
217 217 self.dataOutObj.flagNoData = True
218 218
219 219 if myCohIntObj.isReady:
220 220 self.dataOutObj.flagNoData = False
221 221
222 222
223 223
224 224 class CoherentIntegrator:
225 225
226 226
227 227 __profIndex = 0
228 228 __withOverapping = False
229 229
230 230 __isByTime = False
231 231 __initime = None
232 232 __integrationtime = None
233 233
234 234 __buffer = None
235 235
236 236 isReady = False
237 237 nCohInt = None
238 238
239 239
240 240 def __init__(self, nCohInt=None, timeInterval=None, overlapping=False):
241 241
242 242 """
243 243 Set the parameters of the integration class.
244 244
245 245 Inputs:
246 246
247 247 nCohInt : Number of coherent integrations
248 248 timeInterval : Time of integration. If nCohInt is selected this parameter does not work
249 249 overlapping :
250 250
251 251 """
252 252
253 253 self.__buffer = None
254 254 self.isReady = False
255 255
256 256 if nCohInt == None and timeInterval == None:
257 257 raise ValueError, "nCohInt or timeInterval should be specified ..."
258 258
259 259 if nCohInt != None:
260 260 self.nCohInt = nCohInt
261 261 self.__isByTime = False
262 262 else:
263 263 self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line
264 264 self.__isByTime = True
265 265
266 266 if overlapping:
267 267 self.__withOverapping = True
268 268 self.__buffer = None
269 269 else:
270 270 self.__withOverapping = False
271 271 self.__buffer = 0
272 272
273 273 self.__profIndex = 0
274 274
275 275 def putData(self, data):
276 276
277 277 """
278 278 Add a profile to the __buffer and increase in one the __profileIndex
279 279
280 280 """
281 281 if not self.__withOverapping:
282 282 self.__buffer += data
283 283 self.__profIndex += 1
284 284 return
285 285
286 286 #Overlapping data
287 287 nChannels, nHeis = data.shape
288 288 data = numpy.reshape(data, (1, nChannels, nHeis))
289 289
290 290 if self.__buffer == None:
291 291 self.__buffer = data
292 292 self.__profIndex += 1
293 293 return
294 294
295 295 if self.__profIndex < self.nCohInt:
296 296 self.__buffer = numpy.vstack((self.__buffer, data))
297 297 self.__profIndex += 1
298 298 return
299 299
300 300 self.__buffer = numpy.roll(self.__buffer, -1, axis=0)
301 301 self.__buffer[self.nCohInt-1] = data
302 302 #self.__profIndex = self.nCohInt
303 303 return
304 304
305 305
306 306 def pushData(self):
307 307 """
308 308 Return the sum of the last profiles and the profiles used in the sum.
309 309
310 310 Affected:
311 311
312 312 self.__profileIndex
313 313
314 314 """
315 315
316 316 if not self.__withOverapping:
317 317 data = self.__buffer
318 318 nCohInt = self.__profIndex
319 319
320 320 self.__buffer = 0
321 321 self.__profIndex = 0
322 322
323 323 return data, nCohInt
324 324
325 325 #Overlapping data
326 326 data = numpy.sum(self.__buffer, axis=0)
327 327 nCohInt = self.__profIndex
328 328
329 329 return data, nCohInt
330 330
331 331 def byProfiles(self, data):
332 332
333 333 self.isReady = False
334 334 avg_data = None
335 335
336 336 self.putData(data)
337 337
338 338 if self.__profIndex == self.nCohInt:
339 339 avg_data, nCohInt = self.pushData()
340 340 self.isReady = True
341 341
342 342 return avg_data
343 343
344 344 def byTime(self, data, datatime):
345 345
346 346 self.isReady = False
347 347 avg_data = None
348 348
349 349 if self.__initime == None:
350 350 self.__initime = datatime
351 351
352 352 self.putData(data)
353 353
354 354 if (datatime - self.__initime) >= self.__integrationtime:
355 355 avg_data, nCohInt = self.pushData()
356 356 self.nCohInt = nCohInt
357 357 self.isReady = True
358 358
359 359 return avg_data
360 360
361 361 def exe(self, data, datatime=None):
362 362
363 363 if not self.__isByTime:
364 364 avg_data = self.byProfiles(data)
365 365 else:
366 366 avg_data = self.byTime(data, datatime)
367 367
368 368 self.data = avg_data
369 369
370 370 return avg_data
371 371
372 372
General Comments 0
You need to be logged in to leave comments. Login now