##// END OF EJS Templates
Agregando los metodos para VoltageProcessor y SpectraProcessor.
Daniel Valdez -
r72:42a785dbddc5
parent child
Show More
@@ -1,433 +1,434
1 1 '''
2 2 File: SpectraIO.py
3 3 Created on 20/02/2012
4 4
5 5 @author $Author$
6 6 @version $Id$
7 7 '''
8 8
9 9 import os, sys
10 10 import numpy
11 11 import glob
12 12 import fnmatch
13 13 import time, datetime
14 14
15 15 path = os.path.split(os.getcwd())[0]
16 16 sys.path.append(path)
17 17
18 18 from Model.JROHeader import *
19 19 from Model.Spectra import Spectra
20 20
21 21 from DataIO import JRODataReader
22 22 from DataIO import JRODataWriter
23 23 from DataIO import isNumber
24 24
25 25
26 26 class SpectraReader( JRODataReader ):
27 27 """
28 28 Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura
29 29 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones)
30 30 son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel.
31 31
32 32 paresCanalesIguales * alturas * perfiles (Self Spectra)
33 33 paresCanalesDiferentes * alturas * perfiles (Cross Spectra)
34 34 canales * alturas (DC Channels)
35 35
36 36 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
37 37 RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la
38 38 cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de
39 39 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
40 40
41 41 Example:
42 42 dpath = "/home/myuser/data"
43 43
44 44 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
45 45
46 46 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
47 47
48 48 readerObj = SpectraReader()
49 49
50 50 readerObj.setup(dpath, startTime, endTime)
51 51
52 52 while(True):
53 53
54 54 readerObj.getData()
55 55
56 56 print readerObj.m_Spectra.data
57 57
58 58 if readerObj.flagNoMoreFiles:
59 59 break
60 60
61 61 """
62 62 m_DataObj = None
63 63
64 64 data_spc = None
65 65 data_cspc = None
66 66 data_dc = None
67 67
68 68 pts2read_SelfSpectra = 0
69 69 pts2read_CrossSpectra = 0
70 70 pts2read_DCchannels = 0
71 71
72 72 nPairsEqualChannels = 0
73 73
74 74 nPairsUnequalChannels = 0
75 75
76 76 ext = ".pdata"
77 77
78 78 optchar = "P"
79 79
80 80
81 81 def __init__(self, m_Spectra=None):
82 82 """
83 83 Inicializador de la clase SpectraReader para la lectura de datos de espectros.
84 84
85 85 Inputs:
86 86 m_Spectra : Objeto de la clase Spectra. Este objeto sera utilizado para
87 87 almacenar un perfil de datos cada vez que se haga un requerimiento
88 88 (getData). El perfil sera obtenido a partir del buffer de datos,
89 89 si el buffer esta vacio se hara un nuevo proceso de lectura de un
90 90 bloque de datos.
91 91 Si este parametro no es pasado se creara uno internamente.
92 92
93 93 Affected:
94 94 self.m_DataObj
95 95
96 96 Return : None
97 97 """
98 98 if m_Spectra == None:
99 99 m_Spectra = Spectra()
100 100
101 101 if not( isinstance(m_Spectra, Spectra) ):
102 102 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
103 103
104 104 self.m_DataObj = m_Spectra
105 105
106 106
107 107 def __hasNotDataInBuffer(self):
108 108 return 1
109 109
110 110
111 111 def getBlockDimension(self):
112 112 """
113 113 Obtiene la cantidad de puntos a leer por cada bloque de datos
114 114
115 115 Affected:
116 116 self.nPairsEqualChannels
117 117 self.nPairsUnequalChannels
118 118 self.pts2read_SelfSpectra
119 119 self.pts2read_CrossSpectra
120 120 self.pts2read_DCchannels
121 121 self.blocksize
122 122 self.m_DataObj.nPairsEqualChannels
123 123 self.m_DataObj.nPairsUnequalChannels
124 124
125 125 Return:
126 126 None
127 127 """
128 128 self.nPairsEqualChannels = 0
129 129 self.nPairsUnequalChannels = 0
130 130
131 131 for i in range( 0, self.m_ProcessingHeader.totalSpectra*2, 2 ):
132 132 if self.m_ProcessingHeader.spectraComb[i] == self.m_ProcessingHeader.spectraComb[i+1]:
133 133 self.nPairsEqualChannels = self.nPairsEqualChannels + 1 #par de canales iguales
134 134 else:
135 135 self.nPairsUnequalChannels = self.nPairsUnequalChannels + 1 #par de canales diferentes
136 136
137 137 pts2read = self.m_ProcessingHeader.numHeights * self.m_ProcessingHeader.profilesPerBlock
138 138
139 139 self.pts2read_SelfSpectra = int( self.nPairsEqualChannels * pts2read )
140 140 self.pts2read_CrossSpectra = int( self.nPairsUnequalChannels * pts2read )
141 141 self.pts2read_DCchannels = int( self.m_SystemHeader.numChannels * self.m_ProcessingHeader.numHeights )
142 142
143 143 self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels
144 144
145 self.m_DataObj.nPoints = self.m_ProcessingHeader.profilesPerBlock
145 146 self.m_DataObj.nPairsEqualChannels = self.nPairsEqualChannels
146 147 self.m_DataObj.nPairsUnequalChannels = self.nPairsUnequalChannels
147 148
148 149
149 150 def readBlock(self):
150 151 """
151 152 Lee el bloque de datos desde la posicion actual del puntero del archivo
152 153 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
153 154 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
154 155 es seteado a 0
155 156
156 157 Return: None
157 158
158 159 Variables afectadas:
159 160 self.datablockIndex
160 161 self.flagIsNewFile
161 162 self.flagIsNewBlock
162 163 self.nReadBlocks
163 164 self.data_spc
164 165 self.data_cspc
165 166 self.data_dc
166 167
167 168 Exceptions:
168 169 Si un bloque leido no es un bloque valido
169 170 """
170 171 blockOk_flag = False
171 172 fpointer = self.fp.tell()
172 173
173 174 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
174 175 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
175 176 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
176 177
177 178 if self.online:
178 179 if (spc.size + cspc.size + dc.size) != self.blocksize:
179 180 for nTries in range( self.nTries ):
180 181 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
181 182 time.sleep( self.delay )
182 183 self.fp.seek( fpointer )
183 184 fpointer = self.fp.tell()
184 185
185 186 spc = numpy.fromfile( self.fp, self.dataType[0], self.pts2read_SelfSpectra )
186 187 cspc = numpy.fromfile( self.fp, self.dataType, self.pts2read_CrossSpectra )
187 188 dc = numpy.fromfile( self.fp, self.dataType, self.pts2read_DCchannels ) #int(self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels) )
188 189
189 190 if (spc.size + cspc.size + dc.size) == self.blocksize:
190 191 blockOk_flag = True
191 192 break
192 193
193 194 if not( blockOk_flag ):
194 195 return 0
195 196
196 197 try:
197 198 spc = spc.reshape( (self.nPairsEqualChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
198 199 cspc = cspc.reshape( (self.nPairsUnequalChannels, self.m_ProcessingHeader.numHeights, self.m_ProcessingHeader.profilesPerBlock) ) #transforma a un arreglo 3D
199 200 dc = dc.reshape( (self.m_SystemHeader.numChannels, self.m_ProcessingHeader.numHeights) ) #transforma a un arreglo 2D
200 201 except:
201 202 print "Data file %s is invalid" % self.filename
202 203 return 0
203 204
204 205 if not( self.m_ProcessingHeader.shif_fft ):
205 206 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
206 207 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
207 208
208 209 # spc = numpy.transpose( spc, (0,2,1) )
209 210 # cspc = numpy.transpose( cspc, (0,2,1) )
210 211 #dc = numpy.transpose(dc, (0,2,1))
211 212
212 213 self.data_spc = spc
213 214 self.data_cspc = cspc['real'] + cspc['imag']*1j
214 215 self.data_dc = dc['real'] + dc['imag']*1j
215 216
216 217 self.datablockIndex = 0
217 218 self.flagIsNewFile = 0
218 219 self.flagIsNewBlock = 1
219 220
220 221 self.nReadBlocks += 1
221 222 self.nBlocks += 1
222 223
223 224 return 1
224 225
225 226
226 227 def getData(self):
227 228 """
228 229 Copia el buffer de lectura a la clase "Spectra",
229 230 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
230 231 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
231 232
232 233 Return:
233 234 0 : Si no hay mas archivos disponibles
234 235 1 : Si hizo una buena copia del buffer
235 236
236 237 Affected:
237 238 self.m_DataObj
238 239 self.datablockIndex
239 240 self.flagResetProcessing
240 241 self.flagIsNewBlock
241 242 """
242 243
243 244 if self.flagNoMoreFiles: return 0
244 245
245 246 self.flagResetProcessing = 0
246 247 self.flagIsNewBlock = 0
247 248
248 249 if self.__hasNotDataInBuffer():
249 250
250 251 if not( self.readNextBlock() ):
251 252 self.setNextFile()
252 253 return 0
253 254
254 255 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
255 256 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
256 257 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
257 258 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
258 259 self.m_DataObj.heights = self.heights
259 260 self.m_DataObj.dataType = self.dataType
260 261
261 262 if self.flagNoMoreFiles == 1:
262 263 print 'Process finished'
263 264 return 0
264 265
265 266 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
266 267
267 268 if self.data_dc == None:
268 269 self.m_DataObj.flagNoData = True
269 270 return 0
270 271
271 272 self.m_DataObj.flagNoData = False
272 273 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
273 274
274 275 self.m_DataObj.data_spc = self.data_spc
275 276 self.m_DataObj.data_cspc = self.data_cspc
276 277 self.m_DataObj.data_dc = self.data_dc
277 278
278 279 return 1
279 280
280 281
281 282 class SpectraWriter(JRODataWriter):
282 283
283 284 """
284 285 Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura
285 286 de los datos siempre se realiza por bloques.
286 287 """
287 288
288 289 m_DataObj = None
289 290
290 291 ext = ".pdata"
291 292
292 293 optchar = "P"
293 294
294 295 shape_spc_Buffer = None
295 296 shape_cspc_Buffer = None
296 297 shape_dc_Buffer = None
297 298
298 299
299 300 def __init__(self, m_Spectra=None):
300 301 """
301 302 Inicializador de la clase SpectraWriter para la escritura de datos de espectros.
302 303
303 304 Affected:
304 305 self.m_DataObj
305 306 self.m_BasicHeader
306 307 self.m_SystemHeader
307 308 self.m_RadarControllerHeader
308 309 self.m_ProcessingHeader
309 310
310 311 Return: None
311 312 """
312 313 if m_Spectra == None:
313 314 m_Spectra = Spectra()
314 315
315 316 if not( isinstance(m_Spectra, Spectra) ):
316 317 raise ValueError, "in SpectraReader, m_Spectra must be an Spectra class object"
317 318
318 319 self.m_DataObj = m_Spectra
319 320
320 321
321 322 def hasAllDataInBuffer(self):
322 323 return 1
323 324
324 325
325 326 def setBlockDimension(self):
326 327 """
327 328 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
328 329
329 330 Affected:
330 331 self.shape_spc_Buffer
331 332 self.shape_cspc_Buffer
332 333 self.shape_dc_Buffer
333 334
334 335 Return: None
335 336 """
336 337 self.shape_spc_Buffer = (self.m_DataObj.nPairsEqualChannels,
337 338 self.m_ProcessingHeader.numHeights,
338 339 self.m_ProcessingHeader.profilesPerBlock)
339 340
340 341 self.shape_cspc_Buffer = (self.m_DataObj.nPairsUnequalChannels,
341 342 self.m_ProcessingHeader.numHeights,
342 343 self.m_ProcessingHeader.profilesPerBlock)
343 344
344 345 self.shape_dc_Buffer = (self.m_SystemHeader.numChannels,
345 346 self.m_ProcessingHeader.numHeights)
346 347
347 348
348 349 def writeBlock(self):
349 350 """
350 351 Escribe el buffer en el file designado
351 352
352 353 Affected:
353 354 self.data_spc
354 355 self.data_cspc
355 356 self.data_dc
356 357 self.flagIsNewFile
357 358 self.flagIsNewBlock
358 359 self.nWriteBlocks
359 360 self.blocksCounter
360 361
361 362 Return: None
362 363 """
363 364 spc = self.data_spc
364 365 # spc = numpy.transpose( self.data_spc, (0,2,1) )
365 366 if not( self.m_ProcessingHeader.shif_fft ):
366 367 spc = numpy.roll( spc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
367 368 data = spc.reshape((-1))
368 369 data.tofile(self.fp)
369 370
370 371 data = numpy.zeros( self.shape_cspc_Buffer, self.dataType )
371 372 cspc = self.data_cspc
372 373 # cspc = numpy.transpose( self.data_cspc, (0,2,1) )
373 374 if not( self.m_ProcessingHeader.shif_fft ):
374 375 cspc = numpy.roll( cspc, self.m_ProcessingHeader.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones
375 376 data['imag'] = cspc.imag
376 377 data = data.reshape((-1))
377 378 data.tofile(self.fp)
378 379
379 380 data = numpy.zeros( self.shape_dc_Buffer, self.dataType )
380 381 dc = self.data_dc
381 382 data['real'] = dc.real
382 383 data['imag'] = dc.imag
383 384 data = data.reshape((-1))
384 385 data.tofile(self.fp)
385 386
386 387 self.data_spc.fill(0)
387 388 self.data_cspc.fill(0)
388 389 self.data_dc.fill(0)
389 390
390 391 self.flagIsNewFile = 0
391 392 self.flagIsNewBlock = 1
392 393 self.nWriteBlocks += 1
393 394 self.blocksCounter += 1
394 395
395 396
396 397 def putData(self):
397 398 """
398 399 Setea un bloque de datos y luego los escribe en un file
399 400
400 401 Affected:
401 402 self.data_spc
402 403 self.data_cspc
403 404 self.data_dc
404 405
405 406 Return:
406 407 0 : Si no hay data o no hay mas files que puedan escribirse
407 408 1 : Si se escribio la data de un bloque en un file
408 409 """
409 410 self.flagIsNewBlock = 0
410 411
411 412 if self.m_DataObj.flagNoData:
412 413 return 0
413 414
414 415 if self.m_DataObj.flagResetProcessing:
415 416 self.data_spc.fill(0)
416 417 self.data_cspc.fill(0)
417 418 self.data_dc.fill(0)
418 419 self.setNextFile()
419 420
420 421 self.data_spc = self.m_DataObj.data_spc
421 422 self.data_cspc = self.m_DataObj.data_cspc
422 423 self.data_dc = self.m_DataObj.data_dc
423 424
424 425 # #self.m_ProcessingHeader.dataBlocksPerFile)
425 426 if True:
426 427 self.getHeader()
427 428 self.writeNextBlock()
428 429
429 430 if self.flagNoMoreFiles:
430 431 #print 'Process finished'
431 432 return 0
432 433
433 434 return 1 No newline at end of file
@@ -1,391 +1,392
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 import os, sys
9 9 import numpy
10 10 import glob
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 Model.JROHeader import *
18 18 from Model.Voltage import Voltage
19 19
20 20 from IO.DataIO import JRODataReader
21 21 from IO.DataIO import JRODataWriter
22 22
23 23
24 24 class VoltageReader(JRODataReader):
25 25 """
26 26 Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura
27 27 de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones:
28 28 perfiles*alturas*canales) son almacenados en la variable "buffer".
29 29
30 30 perfiles * alturas * canales
31 31
32 32 Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader,
33 33 RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la
34 34 cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de
35 35 datos desde el "buffer" cada vez que se ejecute el metodo "getData".
36 36
37 37 Example:
38 38
39 39 dpath = "/home/myuser/data"
40 40
41 41 startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0)
42 42
43 43 endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0)
44 44
45 45 readerObj = VoltageReader()
46 46
47 47 readerObj.setup(dpath, startTime, endTime)
48 48
49 49 while(True):
50 50
51 51 #to get one profile
52 52 profile = readerObj.getData()
53 53
54 54 #print the profile
55 55 print profile
56 56
57 57 #If you want to see all datablock
58 58 print readerObj.datablock
59 59
60 60 if readerObj.flagNoMoreFiles:
61 61 break
62 62
63 63 """
64 64 m_DataObj = None
65 65
66 66 idProfile = 0
67 67
68 68 datablock = None
69 69
70 70 pts2read = 0
71 71
72 72 utc = 0
73 73
74 74 ext = ".r"
75 75
76 76 optchar = "D"
77 77
78 78
79 79 def __init__(self, m_Voltage=None):
80 80 """
81 81 Inicializador de la clase VoltageReader para la lectura de datos de voltage.
82 82
83 83 Input:
84 84 m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para
85 85 almacenar un perfil de datos cada vez que se haga un requerimiento
86 86 (getData). El perfil sera obtenido a partir del buffer de datos,
87 87 si el buffer esta vacio se hara un nuevo proceso de lectura de un
88 88 bloque de datos.
89 89 Si este parametro no es pasado se creara uno internamente.
90 90
91 91 Variables afectadas:
92 92 self.m_DataObj
93 93
94 94 Return:
95 95 None
96 96 """
97 97 if m_Voltage == None:
98 98 m_Voltage = Voltage()
99 99
100 100 if not(isinstance(m_Voltage, Voltage)):
101 101 raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object"
102 102
103 103 self.m_DataObj = m_Voltage
104 104
105 105
106 106 def __hasNotDataInBuffer(self):
107 107 if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock:
108 108 return 1
109 109 return 0
110 110
111 111
112 112 def getBlockDimension(self):
113 113 """
114 114 Obtiene la cantidad de puntos a leer por cada bloque de datos
115 115
116 116 Affected:
117 117 self.pts2read
118 118 self.blocksize
119 119
120 120 Return:
121 121 None
122 122 """
123 123 self.pts2read = self.m_ProcessingHeader.profilesPerBlock * self.m_ProcessingHeader.numHeights * self.m_SystemHeader.numChannels
124 124 self.blocksize = self.pts2read
125 self.m_DataObj.nProfiles = self.m_ProcessingHeader.profilesPerBlock
125 126
126 127
127 128 def readBlock(self):
128 129 """
129 130 readBlock lee el bloque de datos desde la posicion actual del puntero del archivo
130 131 (self.fp) y actualiza todos los parametros relacionados al bloque de datos
131 132 (metadata + data). La data leida es almacenada en el buffer y el contador del buffer
132 133 es seteado a 0
133 134
134 135 Inputs:
135 136 None
136 137
137 138 Return:
138 139 None
139 140
140 141 Affected:
141 142 self.datablockIndex
142 143 self.datablock
143 144 self.flagIsNewFile
144 145 self.idProfile
145 146 self.flagIsNewBlock
146 147 self.nReadBlocks
147 148
148 149 Exceptions:
149 150 Si un bloque leido no es un bloque valido
150 151 """
151 152 blockOk_flag = False
152 153 fpointer = self.fp.tell()
153 154
154 155 junk = numpy.fromfile( self.fp, self.dataType, self.pts2read )
155 156
156 157 if self.online:
157 158 if junk.size != self.blocksize:
158 159 for nTries in range( self.nTries ):
159 160 print "\tWaiting %0.2f sec for the next block, try %03d ..." % (self.delay, nTries+1)
160 161 time.sleep( self.delay )
161 162 self.fp.seek( fpointer )
162 163 fpointer = self.fp.tell()
163 164
164 165 junk = numpy.fromfile( self.fp, self.dataType, self.pts2read )
165 166
166 167 if junk.size == self.blocksize:
167 168 blockOk_flag = True
168 169 break
169 170
170 171 if not( blockOk_flag ):
171 172 return 0
172 173
173 174 try:
174 175 junk = junk.reshape( (self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels) )
175 176 except:
176 177 print "Data file %s is invalid" % self.filename
177 178 return 0
178 179
179 180 self.datablock = junk['real'] + junk['imag']*1j
180 181
181 182 self.datablockIndex = 0
182 183 self.flagIsNewFile = 0
183 184 self.idProfile = 0
184 185 self.flagIsNewBlock = 1
185 186
186 187 self.nReadBlocks += 1
187 188 self.nBlocks += 1
188 189
189 190 return 1
190 191
191 192
192 193 def getData(self):
193 194 """
194 195 getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage"
195 196 con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de
196 197 lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock"
197 198
198 199 Ademas incrementa el contador del buffer en 1.
199 200
200 201 Return:
201 202 data : retorna un perfil de voltages (alturas * canales) copiados desde el
202 203 buffer. Si no hay mas archivos a leer retorna None.
203 204
204 205 Variables afectadas:
205 206 self.m_DataObj
206 207 self.datablockIndex
207 208 self.idProfile
208 209
209 210 Affected:
210 211 self.m_DataObj
211 212 self.datablockIndex
212 213 self.flagResetProcessing
213 214 self.flagIsNewBlock
214 215 self.idProfile
215 216 """
216 217 if self.flagNoMoreFiles: return 0
217 218
218 219 self.flagResetProcessing = 0
219 220 self.flagIsNewBlock = 0
220 221
221 222 if self.__hasNotDataInBuffer():
222 223
223 224 if not( self.readNextBlock() ):
224 225 self.setNextFile()
225 226 return 0
226 227
227 228 self.m_DataObj.m_BasicHeader = self.m_BasicHeader.copy()
228 229 self.m_DataObj.m_ProcessingHeader = self.m_ProcessingHeader.copy()
229 230 self.m_DataObj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy()
230 231 self.m_DataObj.m_SystemHeader = self.m_SystemHeader.copy()
231 232 self.m_DataObj.heights = self.heights
232 233 self.m_DataObj.dataType = self.dataType
233 234
234 235 if self.flagNoMoreFiles == 1:
235 236 print 'Process finished'
236 237 return 0
237 238
238 239 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
239 240
240 241 if self.datablock == None:
241 242 self.m_DataObj.flagNoData = True
242 243 return 0
243 244
244 245 time = self.m_BasicHeader.utc + self.datablockIndex * self.ippSeconds
245 246 self.utc = time
246 247 #self.m_DataObj.m_BasicHeader.utc = time
247 248
248 249 self.m_DataObj.flagNoData = False
249 250 self.m_DataObj.flagResetProcessing = self.flagResetProcessing
250 251
251 252 self.m_DataObj.data = self.datablock[self.datablockIndex,:,:]
252 253 self.m_DataObj.idProfile = self.idProfile
253 254
254 255 self.datablockIndex += 1
255 256 self.idProfile += 1
256 257
257 258 #call setData - to Data Object
258 259
259 260 return 1 #self.m_DataObj.data
260 261
261 262
262 263 class VoltageWriter( JRODataWriter ):
263 264 """
264 265 Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura
265 266 de los datos siempre se realiza por bloques.
266 267 """
267 268 __configHeaderFile = 'wrSetHeadet.txt'
268 269
269 270 m_DataObj = None
270 271
271 272 ext = ".r"
272 273
273 274 optchar = "D"
274 275
275 276 datablock = None
276 277
277 278 datablockIndex = 0
278 279
279 280 shapeBuffer = None
280 281
281 282
282 283 def __init__(self, m_Voltage=None):
283 284 """
284 285 Inicializador de la clase VoltageWriter para la escritura de datos de espectros.
285 286
286 287 Affected:
287 288 self.m_DataObj
288 289
289 290 Return: None
290 291 """
291 292 if m_Voltage == None:
292 293 m_Voltage = Voltage()
293 294
294 295 if not( isinstance(m_Voltage, Voltage) ):
295 296 raise ValueError, "in VoltageReader, m_Spectra must be an Spectra class object"
296 297
297 298 self.m_DataObj = m_Voltage
298 299
299 300
300 301 def hasAllDataInBuffer(self):
301 302 if self.datablockIndex >= self.m_ProcessingHeader.profilesPerBlock:
302 303 return 1
303 304 return 0
304 305
305 306
306 307 def setBlockDimension(self):
307 308 """
308 309 Obtiene las formas dimensionales del los subbloques de datos que componen un bloque
309 310
310 311 Affected:
311 312 self.shape_spc_Buffer
312 313 self.shape_cspc_Buffer
313 314 self.shape_dc_Buffer
314 315
315 316 Return: None
316 317 """
317 318 self.shapeBuffer = (self.m_ProcessingHeader.profilesPerBlock,
318 319 self.m_ProcessingHeader.numHeights,
319 320 self.m_SystemHeader.numChannels )
320 321
321 322 self.datablock = numpy.zeros(self.shapeBuffer, numpy.dtype('complex'))
322 323
323 324
324 325 def writeBlock(self):
325 326 """
326 327 Escribe el buffer en el file designado
327 328
328 329 Affected:
329 330 self.datablockIndex
330 331 self.flagIsNewFile
331 332 self.flagIsNewBlock
332 333 self.nWriteBlocks
333 334 self.blocksCounter
334 335
335 336 Return: None
336 337 """
337 338 data = numpy.zeros( self.shapeBuffer, self.dataType )
338 339
339 340 data['real'] = self.datablock.real
340 341 data['imag'] = self.datablock.imag
341 342
342 343 data = data.reshape( (-1) )
343 344
344 345 data.tofile( self.fp )
345 346
346 347 self.datablock.fill(0)
347 348 self.datablockIndex = 0
348 349 self.flagIsNewFile = 0
349 350 self.flagIsNewBlock = 1
350 351 self.nWriteBlocks += 1
351 352 self.blocksCounter += 1
352 353
353 354
354 355 def putData(self):
355 356 """
356 357 Setea un bloque de datos y luego los escribe en un file
357 358
358 359 Affected:
359 360 self.flagIsNewBlock
360 361 self.datablockIndex
361 362
362 363 Return:
363 364 0 : Si no hay data o no hay mas files que puedan escribirse
364 365 1 : Si se escribio la data de un bloque en un file
365 366 """
366 367 self.flagIsNewBlock = 0
367 368
368 369 if self.m_DataObj.flagNoData:
369 370 return 0
370 371
371 372 if self.m_DataObj.flagResetProcessing:
372 373
373 374 self.datablock.fill(0)
374 375 self.datablockIndex = 0
375 376 self.setNextFile()
376 377
377 378 self.datablock[self.datablockIndex,:,:] = self.m_DataObj.data
378 379
379 380 self.datablockIndex += 1
380 381
381 382 if self.hasAllDataInBuffer():
382 383 #if self.flagIsNewFile:
383 384 self.getHeader()
384 385 self.writeNextBlock()
385 386
386 387 if self.flagNoMoreFiles:
387 388 #print 'Process finished'
388 389 return 0
389 390
390 391 return 1
391 392 No newline at end of file
@@ -1,405 +1,482
1 1 '''
2 2 Created on 23/01/2012
3 3
4 4 @author $Author: vsarmiento $
5 5 @version $Id: HeaderIO.py 37 2012-03-26 22:55:13Z vsarmiento $
6 6 '''
7 7
8 8 import numpy
9 9 import copy
10 10
11 11 class Header:
12 12
13 13 def __init__(self):
14 14 raise
15 15
16 16 def copy(self):
17 17 return copy.deepcopy(self)
18 18
19 19 def read():
20 20 pass
21 21
22 22 def write():
23 23 pass
24 24
25 25 class BasicHeader(Header):
26 26
27 27 size = None
28 28 version = None
29 29 dataBlock = None
30 30 utc = None
31 31 miliSecond = None
32 32 timeZone = None
33 33 dstFlag = None
34 34 errorCount = None
35 35 struct = None
36 36
37 37 def __init__(self):
38 38 self.size = 0
39 39 self.version = 0
40 40 self.dataBlock = 0
41 41 self.utc = 0
42 42 self.miliSecond = 0
43 43 self.timeZone = 0
44 44 self.dstFlag = 0
45 45 self.errorCount = 0
46 46 self.struct = numpy.dtype([
47 47 ('nSize','<u4'),
48 48 ('nVersion','<u2'),
49 49 ('nDataBlockId','<u4'),
50 50 ('nUtime','<u4'),
51 51 ('nMilsec','<u2'),
52 52 ('nTimezone','<i2'),
53 53 ('nDstflag','<i2'),
54 54 ('nErrorCount','<u4')
55 55 ])
56 pass
56
57 57
58 58 def read(self, fp):
59 59 try:
60 60 header = numpy.fromfile(fp, self.struct,1)
61 61 self.size = header['nSize'][0]
62 62 self.version = header['nVersion'][0]
63 63 self.dataBlock = header['nDataBlockId'][0]
64 64 self.utc = header['nUtime'][0]
65 65 self.miliSecond = header['nMilsec'][0]
66 66 self.timeZone = header['nTimezone'][0]
67 67 self.dstFlag = header['nDstflag'][0]
68 68 self.errorCount = header['nErrorCount'][0]
69 69 except:
70 70 return 0
71 71
72 72 return 1
73 73
74 74 def write(self, fp):
75 75 headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount)
76 76 header = numpy.array(headerTuple,self.struct)
77 77 header.tofile(fp)
78 78
79 79 return 1
80 80
81 81 class SystemHeader(Header):
82 82
83 83 size = None
84 84 numSamples = None
85 85 numProfiles = None
86 86 numChannels = None
87 87 adcResolution = None
88 88 pciDioBusWidth = None
89 89 struct = None
90 90
91 91 def __init__(self):
92 92 self.size = 0
93 93 self.numSamples = 0
94 94 self.numProfiles = 0
95 95 self.numChannels = 0
96 96 self.adcResolution = 0
97 97 self.pciDioBusWidth = 0
98 98 self.struct = numpy.dtype([
99 99 ('nSize','<u4'),
100 100 ('nNumSamples','<u4'),
101 101 ('nNumProfiles','<u4'),
102 102 ('nNumChannels','<u4'),
103 103 ('nADCResolution','<u4'),
104 104 ('nPCDIOBusWidth','<u4'),
105 105 ])
106 106
107 107
108 108 def read(self, fp):
109 109 try:
110 110 header = numpy.fromfile(fp,self.struct,1)
111 111 self.size = header['nSize'][0]
112 112 self.numSamples = header['nNumSamples'][0]
113 113 self.numProfiles = header['nNumProfiles'][0]
114 114 self.numChannels = header['nNumChannels'][0]
115 115 self.adcResolution = header['nADCResolution'][0]
116 116 self.pciDioBusWidth = header['nPCDIOBusWidth'][0]
117 117 except:
118 118 return 0
119 119
120 120 return 1
121 121
122 122 def write(self, fp):
123 123 headerTuple = (self.size,self.numSamples,self.numProfiles,self.numChannels,self.adcResolution,self.pciDioBusWidth)
124 124 header = numpy.array(headerTuple,self.struct)
125 125 header.tofile(fp)
126 126
127 127 return 1
128 128
129 129 class RadarControllerHeader(Header):
130 130
131 131 size = None
132 132 expType = None
133 133 nTx = None
134 134 ipp = None
135 135 txA = None
136 136 txB = None
137 137 numWindows = None
138 138 numTaus = None
139 139 codeType = None
140 140 line6Function = None
141 141 line5Function = None
142 142 fClock = None
143 143 prePulseBefore = None
144 144 prePulserAfter = None
145 145 rangeIpp = None
146 146 rangeTxA = None
147 147 rangeTxB = None
148 148 struct = None
149 149
150 150 def __init__(self):
151 151 self.size = 0
152 152 self.expType = 0
153 153 self.nTx = 0
154 154 self.ipp = 0
155 155 self.txA = 0
156 156 self.txB = 0
157 157 self.numWindows = 0
158 158 self.numTaus = 0
159 159 self.codeType = 0
160 160 self.line6Function = 0
161 161 self.line5Function = 0
162 162 self.fClock = 0
163 163 self.prePulseBefore = 0
164 164 self.prePulserAfter = 0
165 165 self.rangeIpp = 0
166 166 self.rangeTxA = 0
167 167 self.rangeTxB = 0
168 168 self.struct = numpy.dtype([
169 169 ('nSize','<u4'),
170 170 ('nExpType','<u4'),
171 171 ('nNTx','<u4'),
172 172 ('fIpp','<f4'),
173 173 ('fTxA','<f4'),
174 174 ('fTxB','<f4'),
175 175 ('nNumWindows','<u4'),
176 176 ('nNumTaus','<u4'),
177 177 ('nCodeType','<u4'),
178 178 ('nLine6Function','<u4'),
179 179 ('nLine5Function','<u4'),
180 180 ('fClock','<f4'),
181 181 ('nPrePulseBefore','<u4'),
182 182 ('nPrePulseAfter','<u4'),
183 183 ('sRangeIPP','<a20'),
184 184 ('sRangeTxA','<a20'),
185 185 ('sRangeTxB','<a20'),
186 186 ])
187
188 self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
189
190 self.samplingWindow = None
191 self.numHeights = None
192 self.firstHeight = None
193 self.deltaHeight = None
194 self.samplesWin = None
195
196 self.numCode = None
197 self.numBaud = None
198 self.code = None
199 self.flip1 = None
200 self.flip2 = None
201
187 202 self.dynamic = numpy.array([],numpy.dtype('byte'))
188 203
189 204
190 205 def read(self, fp):
191 206 try:
207 startFp = fp.tell()
192 208 header = numpy.fromfile(fp,self.struct,1)
193 209 self.size = header['nSize'][0]
194 210 self.expType = header['nExpType'][0]
195 211 self.nTx = header['nNTx'][0]
196 212 self.ipp = header['fIpp'][0]
197 213 self.txA = header['fTxA'][0]
198 214 self.txB = header['fTxB'][0]
199 215 self.numWindows = header['nNumWindows'][0]
200 216 self.numTaus = header['nNumTaus'][0]
201 217 self.codeType = header['nCodeType'][0]
202 218 self.line6Function = header['nLine6Function'][0]
203 219 self.line5Function = header['nLine5Function'][0]
204 220 self.fClock = header['fClock'][0]
205 221 self.prePulseBefore = header['nPrePulseBefore'][0]
206 222 self.prePulserAfter = header['nPrePulseAfter'][0]
207 223 self.rangeIpp = header['sRangeIPP'][0]
208 224 self.rangeTxA = header['sRangeTxA'][0]
209 225 self.rangeTxB = header['sRangeTxB'][0]
210 226 # jump Dynamic Radar Controller Header
211 jumpHeader = self.size - 116
212 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpHeader)
227 jumpFp = self.size - 116
228 self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp)
229 #pointer backward to dynamic header and read
230 backFp = fp.tell() - jumpFp
231 fp.seek(backFp)
232
233 self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.numWindows)
234 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
235 self.firstHeight = self.samplingWindow['h0']
236 self.deltaHeight = self.samplingWindow['dh']
237 self.samplesWin = self.samplingWindow['nsa']
238
239 self.Taus = numpy.fromfile(fp,'<f4',self.numTaus)
240
241 if self.codeType != 0:
242 self.numCode = numpy.fromfile(fp,'<u4',1)
243 self.numBaud = numpy.fromfile(fp,'<u4',1)
244 self.code = numpy.empty([self.numCode,self.numBaud],dtype='u1')
245 tempList = []
246 for ic in range(self.numCode):
247 temp = numpy.fromfile(fp,'u1',4*numpy.ceil(self.numBaud/32.))
248 tempList.append(temp)
249 self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.numBaud:]
250 self.code = 2.0*self.code - 1.0
251
252 if self.line5Function == RCfunction.FLIP:
253 self.flip1 = numpy.fromfile(fp,'<u4',1)
254
255 if self.line6Function == RCfunction.FLIP:
256 self.flip2 = numpy.fromfile(fp,'<u4',1)
257
258 endFp = self.size + startFp
259 jumpFp = endFp - fp.tell()
260 if jumpFp > 0:
261 fp.seek(jumpFp)
262
213 263 except:
214 264 return 0
215 265
216 266 return 1
217 267
218 268 def write(self, fp):
219 269 headerTuple = (self.size,
220 270 self.expType,
221 271 self.nTx,
222 272 self.ipp,
223 273 self.txA,
224 274 self.txB,
225 275 self.numWindows,
226 276 self.numTaus,
227 277 self.codeType,
228 278 self.line6Function,
229 279 self.line5Function,
230 280 self.fClock,
231 281 self.prePulseBefore,
232 282 self.prePulserAfter,
233 283 self.rangeIpp,
234 284 self.rangeTxA,
235 285 self.rangeTxB)
236 286
237 287 header = numpy.array(headerTuple,self.struct)
238 288 header.tofile(fp)
239 289
240 290 dynamic = self.dynamic
241 291 dynamic.tofile(fp)
242 292
243 293 return 1
244 294
245 295
246 296
247 297 class ProcessingHeader(Header):
248 298
249 299 size = None
250 300 dataType = None
251 301 blockSize = None
252 302 profilesPerBlock = None
253 303 dataBlocksPerFile = None
254 304 numWindows = None
255 305 processFlags = None
256 306 coherentInt = None
257 307 incoherentInt = None
258 308 totalSpectra = None
259 309 struct = None
260 310
261 311 def __init__(self):
262 312 self.size = 0
263 313 self.dataType = 0
264 314 self.blockSize = 0
265 315 self.profilesPerBlock = 0
266 316 self.dataBlocksPerFile = 0
267 317 self.numWindows = 0
268 318 self.processFlags = 0
269 319 self.coherentInt = 0
270 320 self.incoherentInt = 0
271 321 self.totalSpectra = 0
272 322 self.struct = numpy.dtype([
273 323 ('nSize','<u4'),
274 324 ('nDataType','<u4'),
275 325 ('nSizeOfDataBlock','<u4'),
276 326 ('nProfilesperBlock','<u4'),
277 327 ('nDataBlocksperFile','<u4'),
278 328 ('nNumWindows','<u4'),
279 329 ('nProcessFlags','<u4'),
280 330 ('nCoherentIntegrations','<u4'),
281 331 ('nIncoherentIntegrations','<u4'),
282 332 ('nTotalSpectra','<u4')
283 333 ])
284 334 self.samplingWindow = 0
285 335 self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')])
286 336 self.numHeights = 0
287 337 self.firstHeight = 0
288 338 self.deltaHeight = 0
289 339 self.samplesWin = 0
290 340 self.spectraComb = 0
291 341 self.numCode = 0
292 self.codes = 0
342 self.code = 0
293 343 self.numBaud = 0
294 344 self.shif_fft = False
295 345
296 346 def read(self, fp):
297 347 try:
298 348 header = numpy.fromfile(fp,self.struct,1)
299 349 self.size = header['nSize'][0]
300 350 self.dataType = header['nDataType'][0]
301 351 self.blockSize = header['nSizeOfDataBlock'][0]
302 352 self.profilesPerBlock = header['nProfilesperBlock'][0]
303 353 self.dataBlocksPerFile = header['nDataBlocksperFile'][0]
304 354 self.numWindows = header['nNumWindows'][0]
305 355 self.processFlags = header['nProcessFlags']
306 356 self.coherentInt = header['nCoherentIntegrations'][0]
307 357 self.incoherentInt = header['nIncoherentIntegrations'][0]
308 358 self.totalSpectra = header['nTotalSpectra'][0]
309 359 self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows)
310 360 self.numHeights = numpy.sum(self.samplingWindow['nsa'])
311 361 self.firstHeight = self.samplingWindow['h0']
312 362 self.deltaHeight = self.samplingWindow['dh']
313 363 self.samplesWin = self.samplingWindow['nsa']
314 364 self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra)
315 365
316 366 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
317 367 self.numCode = numpy.fromfile(fp,'<u4',1)
318 368 self.numBaud = numpy.fromfile(fp,'<u4',1)
319 self.codes = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode)
369 self.code = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode)
320 370
321 371 if self.processFlags & PROCFLAG.SHIFT_FFT_DATA == PROCFLAG.SHIFT_FFT_DATA:
322 372 self.shif_fft = True
323 373 else:
324 374 self.shif_fft = False
325 375 except:
326 376 return 0
327 377
328 378 return 1
329 379
330 380 def write(self, fp):
331 381 headerTuple = (self.size,
332 382 self.dataType,
333 383 self.blockSize,
334 384 self.profilesPerBlock,
335 385 self.dataBlocksPerFile,
336 386 self.numWindows,
337 387 self.processFlags,
338 388 self.coherentInt,
339 389 self.incoherentInt,
340 390 self.totalSpectra)
341 391
342 392 header = numpy.array(headerTuple,self.struct)
343 393 header.tofile(fp)
344 394
345 395 if self.numWindows != 0:
346 396 sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin)
347 397 samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow)
348 398 samplingWindow.tofile(fp)
349 399
350 400
351 401 if self.totalSpectra != 0:
352 402 spectraComb = numpy.array([],numpy.dtype('u1'))
353 403 spectraComb = self.spectraComb
354 404 spectraComb.tofile(fp)
355 405
356 406
357 407 if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE:
358 408 numCode = self.numCode
359 409 numCode.tofile(fp)
360 410
361 411 numBaud = self.numBaud
362 412 numBaud.tofile(fp)
363 413
364 codes = self.codes.reshape(numCode*numBaud)
365 codes.tofile(fp)
414 code = self.code.reshape(numCode*numBaud)
415 code.tofile(fp)
366 416
367 417 return 1
368 418
419 class RCfunction:
420 NONE=0
421 FLIP=1
422 CODE=2
423 SAMPLING=3
424 LIN6DIV256=4
425 SYNCHRO=5
426
427 class nCodeType:
428 NONE=0
429 USERDEFINE=1
430 BARKER2=2
431 BARKER3=3
432 BARKER4=4
433 BARKER5=5
434 BARKER7=6
435 BARKER11=7
436 BARKER13=8
437 AC128=9
438 COMPLEMENTARYCODE2=10
439 COMPLEMENTARYCODE4=11
440 COMPLEMENTARYCODE8=12
441 COMPLEMENTARYCODE16=13
442 COMPLEMENTARYCODE32=14
443 COMPLEMENTARYCODE64=15
444 COMPLEMENTARYCODE128=16
445 CODE_BINARY28=17
369 446
370 447 class PROCFLAG:
371 448 COHERENT_INTEGRATION = numpy.uint32(0x00000001)
372 449 DECODE_DATA = numpy.uint32(0x00000002)
373 450 SPECTRA_CALC = numpy.uint32(0x00000004)
374 451 INCOHERENT_INTEGRATION = numpy.uint32(0x00000008)
375 452 POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010)
376 453 SHIFT_FFT_DATA = numpy.uint32(0x00000020)
377 454
378 455 DATATYPE_CHAR = numpy.uint32(0x00000040)
379 456 DATATYPE_SHORT = numpy.uint32(0x00000080)
380 457 DATATYPE_LONG = numpy.uint32(0x00000100)
381 458 DATATYPE_INT64 = numpy.uint32(0x00000200)
382 459 DATATYPE_FLOAT = numpy.uint32(0x00000400)
383 460 DATATYPE_DOUBLE = numpy.uint32(0x00000800)
384 461
385 462 DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000)
386 463 DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000)
387 464 DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000)
388 465
389 466 SAVE_CHANNELS_DC = numpy.uint32(0x00008000)
390 467 DEFLIP_DATA = numpy.uint32(0x00010000)
391 468 DEFINE_PROCESS_CODE = numpy.uint32(0x00020000)
392 469
393 470 ACQ_SYS_NATALIA = numpy.uint32(0x00040000)
394 471 ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000)
395 472 ACQ_SYS_ADRXD = numpy.uint32(0x000C0000)
396 473 ACQ_SYS_JULIA = numpy.uint32(0x00100000)
397 474 ACQ_SYS_XXXXXX = numpy.uint32(0x00140000)
398 475
399 476 EXP_NAME_ESP = numpy.uint32(0x00200000)
400 477 CHANNEL_NAMES_ESP = numpy.uint32(0x00400000)
401 478
402 479 OPERATION_MASK = numpy.uint32(0x0000003F)
403 480 DATATYPE_MASK = numpy.uint32(0x00000FC0)
404 481 DATAARRANGE_MASK = numpy.uint32(0x00007000)
405 482 ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file
@@ -1,56 +1,58
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 8 from JROData import JROData, Noise
9 9 from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader
10 10
11 11 class Spectra(JROData):
12 12 '''
13 13 classdocs
14 14 '''
15 15
16 16 type = "Spectra"
17 17 data_spc = None
18 18 data_cspc = None
19 19 data_dc = None
20 20
21 21
22 22 def __init__(self):
23 23 '''
24 24 Constructor
25 25 '''
26 26
27 27 self.m_RadarControllerHeader = RadarControllerHeader()
28 28
29 29 self.m_ProcessingHeader = ProcessingHeader()
30 30
31 31 self.m_SystemHeader = SystemHeader()
32 32
33 33 self.m_BasicHeader = BasicHeader()
34 34
35 35 m_NoiseObj = Noise()
36 36
37 37 #data es un numpy array de 3 dmensiones (perfiles, alturas y canales)
38 38 self.data_spc = None
39 39
40 40 self.data_cspc = None
41 41
42 42 self.data_dc = None
43 43
44 44 self.heights = None
45 45
46 46 self.flagNoData = True
47 47
48 48 self.nProfiles = None
49 49
50 self.nPoints = None
51
50 52 self.dataType = None
51 53
52 54 self.flagResetProcessing = False
53 55
54 56 self.nPairsUnequalChannels = 0
55 57
56 58 self.nPairsEqualChannels = 0 No newline at end of file
@@ -1,18 +1,183
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 import os, sys
8 import numpy
9
10 path = os.path.split(os.getcwd())[0]
11 sys.path.append(path)
12
13 from Model.Spectra import Spectra
14 from IO.SpectraIO import SpectraWriter
15 from Graphics.SpectraPlot import Spectrum
16
7 17
8 18 class SpectraProcessor:
9 19 '''
10 20 classdocs
11 21 '''
12
13
14 def __init__(self):
22
23 def __init__(self, spectraInObj, spectraOutObj=None, npts = None):
15 24 '''
16 25 Constructor
17 26 '''
18 pass No newline at end of file
27 self.spectraInObj = spectraInObj
28
29 if spectraOutObj == None:
30 self.spectraOutObj = Spectra()
31 else:
32 self.spectraOutObj = spectraOutObj
33
34
35 self.integratorIndex = None
36 self.decoderIndex = None
37 self.writerIndex = None
38 self.plotterIndex = None
39
40 if npts != None:
41 self.spectraOutObj.nPoints = npts
42
43 self.npts = self.spectraOutObj.nPoints
44
45 self.integratorList = []
46 self.decoderList = []
47 self.writerList = []
48 self.plotterList = []
49
50 self.buffer = None
51 self.ptsId = 0
52
53 def init(self):
54 self.integratorIndex = 0
55 self.decoderIndex = 0
56 self.writerIndex = 0
57 self.plotterIndex = 0
58
59 if not( isinstance(self.spectraInObj, Spectra) ):
60 self.getFft()
61 else:
62 self.spectraOutObj.copy(self.spectraInObj)
63
64
65 def getFft(self):
66
67 if self.buffer == None:
68 nheis = self.spectraInObj.data.shape[0]
69 nchannel = self.spectraInObj.data.shape[1]
70 npoints = self.spectraOutObj.nPoints
71 self.buffer = numpy.zeros((nchannel,nheis,npoints),dtype='complex')
72
73 data = numpy.transpose(self.spectraInObj.data)
74 self.buffer[:,:,self.ptsId] = data
75 self.ptsId += 1
76 self.spectraOutObj.flagNoData = True
77 if self.ptsId >= self.spectraOutObj.nPoints:
78 data_spc = numpy.fft.fft(self.buffer,axis=2)
79 self.ptsId = 0
80 self.buffer = None
81
82 #calculo de self-spectra
83 self.spectraOutObj.data_spc = numpy.abs(data_spc * numpy.conjugate(data_spc))
84
85
86
87 #calculo de cross-spectra
88 #self.m_Spectra.data_cspc = self.__data_cspc
89
90
91 #escribiendo dc
92 #self.m_Spectra.data_dc = self.__data_dc
93
94
95 self.spectraOutObj.flagNoData = False
96
97
98 def addWriter(self,wrpath):
99 objWriter = SpectraWriter(self.spectraOutObj)
100 objWriter.setup(wrpath)
101 self.writerList.append(objWriter)
102
103
104 def addPlotter(self):
105
106 plotObj = Spectrum(self.spectraOutObj,self.plotterIndex)
107 self.plotterList.append(plotObj)
108
109
110 def addIntegrator(self,N):
111
112 objIncohInt = IncoherentIntegration(N)
113 self.integratorList.append(objIncohInt)
114
115
116 def writeData(self):
117 if self.voltageOutObj.flagNoData:
118 return 0
119
120 if len(self.writerList) <= self.writerIndex:
121 self.addWriter(wrpath)
122
123 self.writerList[self.writerIndex].putData()
124
125 self.writerIndex += 1
126
127 def plotData(self,xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
128 if self.spectraOutObj.flagNoData:
129 return 0
130
131 if len(self.plotterList) <= self.plotterIndex:
132 self.addPlotter()
133
134 self.plotterList[self.plotterIndex].plotData(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
135
136 self.plotterIndex += 1
137
138 def integrator(self, N):
139 if self.spectraOutObj.flagNoData:
140 return 0
141
142 if len(self.integratorList) <= self.integratorIndex:
143 self.addIntegrator(N)
144
145 myCohIntObj = self.integratorList[self.integratorIndex]
146 myCohIntObj.exe(self.spectraOutObj.data_spc)
147
148 if myCohIntObj.flag:
149 self.spectraOutObj.data_spc = myCohIntObj.data
150 self.spectraOutObj.m_ProcessingHeader.incoherentInt *= N
151 self.spectraOutObj.flagNoData = False
152
153 else:
154 self.spectraOutObj.flagNoData = True
155
156 self.integratorIndex += 1
157
158 class IncoherentIntegration:
159 def __init__(self, N):
160 self.profCounter = 1
161 self.data = None
162 self.buffer = None
163 self.flag = False
164 self.nIncohInt = N
165
166 def exe(self,data):
167 print 'intg:', self.profCounter
168
169 if self.buffer == None:
170 self.buffer = data
171 else:
172 self.buffer = self.buffer + data
173
174 if self.profCounter == self.nIncohInt:
175 self.data = self.buffer
176 self.buffer = None
177 self.profCounter = 0
178 self.flag = True
179 else:
180 self.flag = False
181
182 self.profCounter += 1
183
@@ -1,18 +1,247
1 1 '''
2 2 Created on Feb 7, 2012
3 3
4 4 @author $Author$
5 5 @version $Id$
6 6 '''
7 7
8 import os, sys
9 import numpy
10
11 path = os.path.split(os.getcwd())[0]
12 sys.path.append(path)
13
14 from Model.Voltage import Voltage
15 from IO.VoltageIO import VoltageWriter
16 from Graphics.VoltagePlot import Osciloscope
17
8 18 class VoltageProcessor:
9 19 '''
10 20 classdocs
11 21 '''
12 22
13
14 def __init__(self):
23 def __init__(self, voltageInObj, voltageOutObj=None):
15 24 '''
16 25 Constructor
17 26 '''
18 pass No newline at end of file
27
28 self.voltageInObj = voltageInObj
29
30 if voltageOutObj == None:
31 self.voltageOutObj = Voltage()
32 else:
33 self.voltageOutObj = voltageOutObj
34
35 self.integratorIndex = None
36 self.decoderIndex = None
37 self.writerIndex = None
38 self.plotterIndex = None
39
40 self.integratorList = []
41 self.decoderList = []
42 self.writerList = []
43 self.plotterList = []
44
45 def init(self):
46 self.integratorIndex = 0
47 self.decoderIndex = 0
48 self.writerIndex = 0
49 self.plotterIndex = 0
50 self.voltageOutObj.copy(self.voltageInObj)
51
52 def addWriter(self,wrpath):
53 objWriter = VoltageWriter(self.voltageOutObj)
54 objWriter.setup(wrpath)
55 self.writerList.append(objWriter)
56
57 def addPlotter(self):
58
59 plotObj = Osciloscope(self.voltageOutObj,self.plotterIndex)
60 self.plotterList.append(plotObj)
61
62 def addIntegrator(self,N):
63
64 objCohInt = CoherentIntegrator(N)
65 self.integratorList.append(objCohInt)
66
67 def addDecoder(self,code,ncode,nbaud):
68
69 objDecoder = Decoder(code,ncode,nbaud)
70 self.decoderList.append(objDecoder)
71
72 def writeData(self,wrpath):
73 if self.voltageOutObj.flagNoData:
74 return 0
75
76 if len(self.writerList) <= self.writerIndex:
77 self.addWriter(wrpath)
78
79 self.writerList[self.writerIndex].putData()
80
81 # myWrObj = self.writerList[self.writerIndex]
82 # myWrObj.putData()
83
84 self.writerIndex += 1
85
86 def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''):
87 if self.voltageOutObj.flagNoData:
88 return 0
89
90 if len(self.plotterList) <= self.plotterIndex:
91 self.addPlotter()
92
93 self.plotterList[self.plotterIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle)
94
95 self.plotterIndex += 1
96
97 def integrator(self, N):
98 if self.voltageOutObj.flagNoData:
99 return 0
100
101 if len(self.integratorList) <= self.integratorIndex:
102 self.addIntegrator(N)
103
104 myCohIntObj = self.integratorList[self.integratorIndex]
105 myCohIntObj.exe(self.voltageOutObj.data)
106
107 if myCohIntObj.flag:
108 self.voltageOutObj.data = myCohIntObj.data
109 self.voltageOutObj.m_ProcessingHeader.coherentInt *= N
110 self.voltageOutObj.flagNoData = False
111
112 else:
113 self.voltageOutObj.flagNoData = True
114
115 self.integratorIndex += 1
116
117 def decoder(self,code=None,type = 0):
118 if self.voltageOutObj.flagNoData:
119 return 0
120 if code == None:
121 code = self.voltageOutObj.m_RadarControllerHeader.code
122 ncode, nbaud = code.shape
123
124 if len(self.decoderList) <= self.decoderIndex:
125 self.addDecoder(code,ncode,nbaud)
126
127 myDecodObj = self.decoderList[self.decoderIndex]
128 myDecodObj.exe(data=self.voltageOutObj.data,type=type)
129
130 if myDecodObj.flag:
131 self.voltageOutObj.data = myDecodObj.data
132 self.voltageOutObj.flagNoData = False
133 else:
134 self.voltageOutObj.flagNoData = True
135
136 self.decoderIndex += 1
137
138 def removeDC(self):
139 pass
140
141 def removeSignalInt(self):
142 pass
143
144 def selChannel(self):
145 pass
146
147 def selRange(self):
148 pass
149
150 def selProfiles(self):
151 pass
152
153
154 class Decoder:
155 def __init__(self,code, ncode, nbaud):
156 self.buffer = None
157 self.profCounter = 1
158 self.nCode = ncode
159 self.nBaud = nbaud
160 self.codeIndex = 0
161 self.code = code #this is a List
162 self.fft_code = None
163 self.flag = False
164 self.setCodeFft = False
165
166 def exe(self, data, ndata=None, type = 0):
167 if ndata == None: ndata = data.shape[0]
168
169 if type == 0:
170 self.convolutionInFreq(data,ndata)
171
172 if type == 1:
173 self.convolutionInTime(data, ndata)
174
175 def convolutionInFreq(self,data,ndata):
176
177 newcode = numpy.zeros(ndata)
178 newcode[0:self.nBaud] = self.code[self.codeIndex]
179
180 self.codeIndex += 1
181
182 fft_data = numpy.fft.fft(data, axis=0)
183 fft_code = numpy.conj(numpy.fft.fft(newcode))
184 fft_code = fft_code.reshape(len(fft_code),1)
185
186 conv = fft_data.copy()
187 conv.fill(0)
188
189 conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays
190 # for i in range(ndata):
191 # conv[i,:] = fft_data[i,:]*fft_code[i]
192
193 self.data = numpy.fft.ifft(conv,axis=0)
194 self.flag = True
195
196 if self.profCounter == self.nCode:
197 self.profCounter = 0
198 self.codeIndex = 0
199
200 self.profCounter += 1
201
202 def convolutionInTime(self, data, ndata):
203
204 nchannel = data.shape[1]
205 newcode = self.code[self.codeIndex]
206 self.codeIndex += 1
207 conv = data.copy()
208 for i in range(nchannel):
209 conv[:,i] = numpy.correlate(data[:,i], newcode, 'same')
210
211 self.data = conv
212 self.flag = True
213
214 if self.profCounter == self.nCode:
215 self.profCounter = 0
216 self.codeIndex = 0
217
218 self.profCounter += 1
219
220
221 class CoherentIntegrator:
222 def __init__(self, N):
223 self.profCounter = 1
224 self.data = None
225 self.buffer = None
226 self.flag = False
227 self.nCohInt = N
228
229 def exe(self,data):
230
231 if self.buffer == None:
232 self.buffer = data
233 else:
234 self.buffer = self.buffer + data
235
236 if self.profCounter == self.nCohInt:
237 self.data = self.buffer
238 self.buffer = None
239 self.profCounter = 0
240 self.flag = True
241 else:
242 self.flag = False
243
244 self.profCounter += 1
245
246
247 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now