This diff has been collapsed as it changes many lines, (801 lines changed) Show them Hide them | |||||
@@ -0,0 +1,801 | |||||
|
1 | ''' | |||
|
2 | Created on 23/01/2012 | |||
|
3 | ||||
|
4 | @author $Author$ | |||
|
5 | @version $Id$ | |||
|
6 | ''' | |||
|
7 | ||||
|
8 | import os, sys | |||
|
9 | import numpy | |||
|
10 | import glob | |||
|
11 | import fnmatch | |||
|
12 | import time, datetime | |||
|
13 | ||||
|
14 | path = os.path.split(os.getcwd())[0] | |||
|
15 | sys.path.append(path) | |||
|
16 | ||||
|
17 | from IO.HeaderIO import * | |||
|
18 | from IO.DataIO import DataReader | |||
|
19 | from IO.DataIO import DataWriter | |||
|
20 | ||||
|
21 | from Model.Voltage import Voltage | |||
|
22 | ||||
|
23 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |||
|
24 | """ | |||
|
25 | Esta funcion determina si un archivo de datos en formato Jicamarca(.r) se encuentra | |||
|
26 | o no dentro del rango de fecha especificado. | |||
|
27 | ||||
|
28 | Inputs: | |||
|
29 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |||
|
30 | ||||
|
31 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |||
|
32 | segundos contados desde 01/01/1970. | |||
|
33 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |||
|
34 | segundos contados desde 01/01/1970. | |||
|
35 | ||||
|
36 | Return: | |||
|
37 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |||
|
38 | fecha especificado, de lo contrario retorna False. | |||
|
39 | ||||
|
40 | Excepciones: | |||
|
41 | Si el archivo no existe o no puede ser abierto | |||
|
42 | Si la cabecera no puede ser leida. | |||
|
43 | ||||
|
44 | """ | |||
|
45 | m_BasicHeader = BasicHeader() | |||
|
46 | ||||
|
47 | try: | |||
|
48 | fp = open(filename,'rb') | |||
|
49 | except: | |||
|
50 | raise IOError, "The file %s can't be opened" %(filename) | |||
|
51 | ||||
|
52 | if not(m_BasicHeader.read(fp)): | |||
|
53 | raise IOError, "The file %s has not a valid header" %(filename) | |||
|
54 | ||||
|
55 | fp.close() | |||
|
56 | ||||
|
57 | if not ((startUTSeconds <= m_BasicHeader.utc) and (endUTSeconds >= m_BasicHeader.utc)): | |||
|
58 | return 0 | |||
|
59 | ||||
|
60 | return 1 | |||
|
61 | ||||
|
62 | class VoltageReader(DataReader): | |||
|
63 | """ | |||
|
64 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |||
|
65 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |||
|
66 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |||
|
67 | ||||
|
68 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |||
|
69 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |||
|
70 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |||
|
71 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |||
|
72 | ||||
|
73 | Example: | |||
|
74 | ||||
|
75 | dpath = "/home/myuser/data" | |||
|
76 | ||||
|
77 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |||
|
78 | ||||
|
79 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |||
|
80 | ||||
|
81 | readerObj = VoltageReader() | |||
|
82 | ||||
|
83 | readerObj.setup(dpath, startTime, endTime) | |||
|
84 | ||||
|
85 | while(True): | |||
|
86 | ||||
|
87 | readerObj.getData() | |||
|
88 | ||||
|
89 | print readerObj.m_Voltage.data | |||
|
90 | ||||
|
91 | if readerObj.noMoreFiles: | |||
|
92 | break | |||
|
93 | ||||
|
94 | """ | |||
|
95 | ||||
|
96 | #speed of light | |||
|
97 | __c = 3E8 | |||
|
98 | ||||
|
99 | def __init__(self, m_Voltage = None): | |||
|
100 | """ | |||
|
101 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |||
|
102 | ||||
|
103 | Input: | |||
|
104 | m_Voltage : Objeto de la clase Voltage. Este objeto sera utilizado para | |||
|
105 | almacenar un perfil de datos cada vez que se haga un requerimiento | |||
|
106 | (getData). El perfil sera obtenido a partir del buffer de datos, | |||
|
107 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |||
|
108 | bloque de datos. | |||
|
109 | Si este parametro no es pasado se creara uno internamente. | |||
|
110 | ||||
|
111 | Variables afectadas: | |||
|
112 | self.m_Voltage | |||
|
113 | self.m_BasicHeader | |||
|
114 | self.m_SystemHeader | |||
|
115 | self.m_RadarControllerHeader | |||
|
116 | self.m_ProcessingHeader | |||
|
117 | ||||
|
118 | ||||
|
119 | Return: | |||
|
120 | Void | |||
|
121 | ||||
|
122 | """ | |||
|
123 | if m_Voltage == None: | |||
|
124 | m_Voltage = Voltage() | |||
|
125 | ||||
|
126 | if not(isinstance(m_Voltage, Voltage)): | |||
|
127 | raise ValueError, "in VoltageReader, m_Voltage must be an Voltage class object" | |||
|
128 | ||||
|
129 | self.m_Voltage = m_Voltage | |||
|
130 | ||||
|
131 | self.m_BasicHeader = BasicHeader() | |||
|
132 | ||||
|
133 | self.m_SystemHeader = SystemHeader() | |||
|
134 | ||||
|
135 | self.m_RadarControllerHeader = RadarControllerHeader() | |||
|
136 | ||||
|
137 | self.m_ProcessingHeader = ProcessingHeader() | |||
|
138 | ||||
|
139 | self.__fp = None | |||
|
140 | ||||
|
141 | self.__idFile = None | |||
|
142 | ||||
|
143 | self.__startDateTime = None | |||
|
144 | ||||
|
145 | self.__endDateTime = None | |||
|
146 | ||||
|
147 | self.__dataType = None | |||
|
148 | ||||
|
149 | self.__fileSizeByHeader = 0 | |||
|
150 | ||||
|
151 | self.__pathList = [] | |||
|
152 | ||||
|
153 | self.filenameList = [] | |||
|
154 | ||||
|
155 | self.__lastUTTime = 0 | |||
|
156 | ||||
|
157 | self.__maxTimeStep = 30 | |||
|
158 | ||||
|
159 | self.__flagIsNewFile = 0 | |||
|
160 | ||||
|
161 | self.__ippSeconds = 0 | |||
|
162 | ||||
|
163 | self.flagResetProcessing = 0 | |||
|
164 | ||||
|
165 | self.flagIsNewBlock = 0 | |||
|
166 | ||||
|
167 | self.noMoreFiles = 0 | |||
|
168 | ||||
|
169 | self.nReadBlocks = 0 | |||
|
170 | ||||
|
171 | self.online = 0 | |||
|
172 | ||||
|
173 | self.filename = None | |||
|
174 | ||||
|
175 | self.fileSize = None | |||
|
176 | ||||
|
177 | self.firstHeaderSize = 0 | |||
|
178 | ||||
|
179 | self.basicHeaderSize = 24 | |||
|
180 | ||||
|
181 | self.idProfile = 0 | |||
|
182 | ||||
|
183 | self.__buffer = 0 | |||
|
184 | ||||
|
185 | self.__buffer_id = 9999 | |||
|
186 | ||||
|
187 | def __rdSystemHeader(self,fp=None): | |||
|
188 | if fp == None: | |||
|
189 | fp = self.__fp | |||
|
190 | ||||
|
191 | self.m_SystemHeader.read(fp) | |||
|
192 | ||||
|
193 | def __rdRadarControllerHeader(self,fp=None): | |||
|
194 | if fp == None: | |||
|
195 | fp = self.__fp | |||
|
196 | ||||
|
197 | self.m_RadarControllerHeader.read(fp) | |||
|
198 | ||||
|
199 | def __rdProcessingHeader(self,fp=None): | |||
|
200 | if fp == None: | |||
|
201 | fp = self.__fp | |||
|
202 | ||||
|
203 | self.m_ProcessingHeader.read(fp) | |||
|
204 | ||||
|
205 | def __rdBasicHeader(self, fp=None): | |||
|
206 | ||||
|
207 | if fp == None: | |||
|
208 | fp = self.__fp | |||
|
209 | ||||
|
210 | self.m_BasicHeader.read(fp) | |||
|
211 | ||||
|
212 | def __readFirstHeader(self): | |||
|
213 | ||||
|
214 | self.__rdBasicHeader() | |||
|
215 | self.__rdSystemHeader() | |||
|
216 | self.__rdRadarControllerHeader() | |||
|
217 | self.__rdProcessingHeader() | |||
|
218 | self.firstHeaderSize = self.m_BasicHeader.size | |||
|
219 | ||||
|
220 | data_type=int(numpy.log2((self.m_ProcessingHeader.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |||
|
221 | if data_type == 0: | |||
|
222 | tmp = numpy.dtype([('real','<i1'),('imag','<i1')]) | |||
|
223 | ||||
|
224 | elif data_type == 1: | |||
|
225 | tmp = numpy.dtype([('real','<i2'),('imag','<i2')]) | |||
|
226 | ||||
|
227 | elif data_type == 2: | |||
|
228 | tmp = numpy.dtype([('real','<i4'),('imag','<i4')]) | |||
|
229 | ||||
|
230 | elif data_type == 3: | |||
|
231 | tmp = numpy.dtype([('real','<i8'),('imag','<i8')]) | |||
|
232 | ||||
|
233 | elif data_type == 4: | |||
|
234 | tmp = numpy.dtype([('real','<f4'),('imag','<f4')]) | |||
|
235 | ||||
|
236 | elif data_type == 5: | |||
|
237 | tmp = numpy.dtype([('real','<f8'),('imag','<f8')]) | |||
|
238 | ||||
|
239 | else: | |||
|
240 | raise ValueError, 'Data type was not defined' | |||
|
241 | ||||
|
242 | xi = self.m_ProcessingHeader.firstHeight | |||
|
243 | step = self.m_ProcessingHeader.deltaHeight | |||
|
244 | xf = xi + self.m_ProcessingHeader.numHeights*step | |||
|
245 | ||||
|
246 | self.__heights = numpy.arange(xi, xf, step) | |||
|
247 | self.__dataType = tmp | |||
|
248 | self.__fileSizeByHeader = self.m_ProcessingHeader.dataBlocksPerFile * self.m_ProcessingHeader.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.m_ProcessingHeader.dataBlocksPerFile - 1) | |||
|
249 | self.__ippSeconds = 2*1000*self.m_RadarControllerHeader.ipp/self.__c | |||
|
250 | ||||
|
251 | def __setNextFileOnline(self): | |||
|
252 | return 0 | |||
|
253 | ||||
|
254 | def __setNextFileOffline(self): | |||
|
255 | ||||
|
256 | idFile = self.__idFile | |||
|
257 | while(True): | |||
|
258 | ||||
|
259 | idFile += 1 | |||
|
260 | ||||
|
261 | if not(idFile < len(self.filenameList)): | |||
|
262 | self.noMoreFiles = 1 | |||
|
263 | return 0 | |||
|
264 | ||||
|
265 | filename = self.filenameList[idFile] | |||
|
266 | fileSize = os.path.getsize(filename) | |||
|
267 | ||||
|
268 | try: | |||
|
269 | fp = open(filename,'rb') | |||
|
270 | except: | |||
|
271 | raise IOError, "The file %s can't be opened" %filename | |||
|
272 | ||||
|
273 | currentSize = fileSize - fp.tell() | |||
|
274 | neededSize = self.m_ProcessingHeader.blockSize + self.firstHeaderSize | |||
|
275 | ||||
|
276 | if (currentSize < neededSize): | |||
|
277 | print "Skipping the file %s due to it hasn't enough data" %filename | |||
|
278 | continue | |||
|
279 | ||||
|
280 | break | |||
|
281 | ||||
|
282 | self.__flagIsNewFile = 1 | |||
|
283 | self.__idFile = idFile | |||
|
284 | self.filename = filename | |||
|
285 | self.fileSize = fileSize | |||
|
286 | self.__fp = fp | |||
|
287 | ||||
|
288 | print 'Setting the file: %s'%self.filename | |||
|
289 | ||||
|
290 | return 1 | |||
|
291 | ||||
|
292 | def __setNextFile(self): | |||
|
293 | ||||
|
294 | if self.online: | |||
|
295 | newFile = self.__setNextFileOnline() | |||
|
296 | else: | |||
|
297 | newFile = self.__setNextFileOffline() | |||
|
298 | ||||
|
299 | if not(newFile): | |||
|
300 | return 0 | |||
|
301 | ||||
|
302 | self.__readFirstHeader() | |||
|
303 | ||||
|
304 | return 1 | |||
|
305 | ||||
|
306 | def __setNewBlock(self): | |||
|
307 | ||||
|
308 | if self.__fp == None: | |||
|
309 | return 0 | |||
|
310 | ||||
|
311 | if self.__flagIsNewFile: | |||
|
312 | return 1 | |||
|
313 | ||||
|
314 | currentSize = self.fileSize - self.__fp.tell() | |||
|
315 | neededSize = self.m_ProcessingHeader.blockSize + self.basicHeaderSize | |||
|
316 | ||||
|
317 | #If there is enough data setting new data block | |||
|
318 | if (currentSize >= neededSize): | |||
|
319 | self.__rdBasicHeader() | |||
|
320 | return 1 | |||
|
321 | ||||
|
322 | #Setting new file | |||
|
323 | if not(self.__setNextFile()): | |||
|
324 | return 0 | |||
|
325 | ||||
|
326 | deltaTime = self.m_BasicHeader.utc - self.__lastUTTime # check this | |||
|
327 | ||||
|
328 | self.flagResetProcessing = 0 | |||
|
329 | ||||
|
330 | if deltaTime > self.__maxTimeStep: | |||
|
331 | self.flagResetProcessing = 1 | |||
|
332 | self.nReadBlocks = 0 | |||
|
333 | ||||
|
334 | return 1 | |||
|
335 | ||||
|
336 | def __readBlock(self): | |||
|
337 | """ | |||
|
338 | __readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |||
|
339 | (self.__fp) y actualiza todos los parametros relacionados al bloque de datos | |||
|
340 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |||
|
341 | es seteado a 0 | |||
|
342 | ||||
|
343 | ||||
|
344 | Inputs: | |||
|
345 | None | |||
|
346 | ||||
|
347 | Return: | |||
|
348 | None | |||
|
349 | ||||
|
350 | Variables afectadas: | |||
|
351 | ||||
|
352 | self.__buffer_id | |||
|
353 | ||||
|
354 | self.__buffer | |||
|
355 | ||||
|
356 | self.__flagIsNewFile | |||
|
357 | ||||
|
358 | self.idProfile | |||
|
359 | ||||
|
360 | self.flagIsNewBlock | |||
|
361 | ||||
|
362 | self.nReadBlocks | |||
|
363 | ||||
|
364 | """ | |||
|
365 | ||||
|
366 | pts2read = self.m_ProcessingHeader.profilesPerBlock*self.m_ProcessingHeader.numHeights*self.m_SystemHeader.numChannels | |||
|
367 | ||||
|
368 | junk = numpy.fromfile(self.__fp, self.__dataType, pts2read) | |||
|
369 | ||||
|
370 | junk = junk.reshape((self.m_ProcessingHeader.profilesPerBlock, self.m_ProcessingHeader.numHeights, self.m_SystemHeader.numChannels)) | |||
|
371 | ||||
|
372 | data = junk['real'] + junk['imag']*1j | |||
|
373 | ||||
|
374 | self.__buffer_id = 0 | |||
|
375 | ||||
|
376 | self.__buffer = data | |||
|
377 | ||||
|
378 | self.__flagIsNewFile = 0 | |||
|
379 | ||||
|
380 | self.idProfile = 0 | |||
|
381 | ||||
|
382 | self.flagIsNewBlock = 1 | |||
|
383 | ||||
|
384 | self.nReadBlocks += 1 | |||
|
385 | ||||
|
386 | def __hasNotDataInBuffer(self): | |||
|
387 | if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock: | |||
|
388 | return 1 | |||
|
389 | ||||
|
390 | return 0 | |||
|
391 | ||||
|
392 | def __searchFiles(self, path, startDateTime, endDateTime, set=None, expLabel = "", ext = ".r"): | |||
|
393 | """ | |||
|
394 | __searchFiles realiza una busqueda de los archivos que coincidan con los parametros | |||
|
395 | especificados y se encuentren ubicados en el path indicado. Para realizar una busqueda | |||
|
396 | correcta la estructura de directorios debe ser la siguiente: | |||
|
397 | ||||
|
398 | ...path/D[yyyy][ddd]/expLabel/D[yyyy][ddd][sss].ext | |||
|
399 | ||||
|
400 | [yyyy]: anio | |||
|
401 | [ddd] : dia del anio | |||
|
402 | [sss] : set del archivo | |||
|
403 | ||||
|
404 | Inputs: | |||
|
405 | path : Directorio de datos donde se realizara la busqueda. Todos los | |||
|
406 | ficheros que concidan con el criterio de busqueda seran | |||
|
407 | almacenados en una lista y luego retornados. | |||
|
408 | startDateTime : Fecha inicial. Rechaza todos los archivos donde | |||
|
409 | file end time < startDateTime (obejto datetime.datetime) | |||
|
410 | ||||
|
411 | endDateTime : Fecha final. Rechaza todos los archivos donde | |||
|
412 | file start time > endDateTime (obejto datetime.datetime) | |||
|
413 | ||||
|
414 | set : Set del primer archivo a leer. Por defecto None | |||
|
415 | ||||
|
416 | expLabel : Nombre del subdirectorio de datos. Por defecto "" | |||
|
417 | ||||
|
418 | ext : Extension de los archivos a leer. Por defecto .r | |||
|
419 | ||||
|
420 | Return: | |||
|
421 | ||||
|
422 | (pathList, filenameList) | |||
|
423 | ||||
|
424 | pathList : Lista de directorios donde se encontraron archivos dentro | |||
|
425 | de los parametros especificados | |||
|
426 | filenameList : Lista de archivos (ruta completa) que coincidieron con los | |||
|
427 | parametros especificados. | |||
|
428 | ||||
|
429 | Variables afectadas: | |||
|
430 | ||||
|
431 | self.filenameList: Lista de archivos (ruta completa) que la clase utiliza | |||
|
432 | como fuente para leer los bloque de datos, si se termina | |||
|
433 | de leer todos los bloques de datos de un determinado | |||
|
434 | archivo se pasa al siguiente archivo de la lista. | |||
|
435 | ||||
|
436 | Excepciones: | |||
|
437 | ||||
|
438 | """ | |||
|
439 | ||||
|
440 | print "Searching files ..." | |||
|
441 | ||||
|
442 | dirList = [] | |||
|
443 | for thisPath in os.listdir(path): | |||
|
444 | if os.path.isdir(os.path.join(path,thisPath)): | |||
|
445 | dirList.append(thisPath) | |||
|
446 | ||||
|
447 | pathList = [] | |||
|
448 | ||||
|
449 | thisDateTime = startDateTime | |||
|
450 | ||||
|
451 | while(thisDateTime <= endDateTime): | |||
|
452 | year = thisDateTime.timetuple().tm_year | |||
|
453 | doy = thisDateTime.timetuple().tm_yday | |||
|
454 | ||||
|
455 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |||
|
456 | if len(match) == 0: | |||
|
457 | thisDateTime += datetime.timedelta(1) | |||
|
458 | continue | |||
|
459 | ||||
|
460 | pathList.append(os.path.join(path,match[0],expLabel)) | |||
|
461 | thisDateTime += datetime.timedelta(1) | |||
|
462 | ||||
|
463 | startUtSeconds = time.mktime(startDateTime.timetuple()) | |||
|
464 | endUtSeconds = time.mktime(endDateTime.timetuple()) | |||
|
465 | ||||
|
466 | filenameList = [] | |||
|
467 | for thisPath in pathList: | |||
|
468 | fileList = glob.glob1(thisPath, "*%s" %ext) | |||
|
469 | fileList.sort() | |||
|
470 | for file in fileList: | |||
|
471 | filename = os.path.join(thisPath,file) | |||
|
472 | if isThisFileinRange(filename, startUtSeconds, endUtSeconds): | |||
|
473 | filenameList.append(filename) | |||
|
474 | ||||
|
475 | self.filenameList = filenameList | |||
|
476 | ||||
|
477 | return pathList, filenameList | |||
|
478 | ||||
|
479 | def setup(self, path, startDateTime, endDateTime=None, set=None, expLabel = "", ext = ".r", online = 0): | |||
|
480 | """ | |||
|
481 | setup configura los parametros de lectura de la clase VoltageReader. | |||
|
482 | ||||
|
483 | Si el modo de lectura es offline, primero se realiza una busqueda de todos los archivos | |||
|
484 | que coincidan con los parametros especificados; esta lista de archivos son almacenados en | |||
|
485 | self.filenameList. | |||
|
486 | ||||
|
487 | Input: | |||
|
488 | path : Directorios donde se ubican los datos a leer. Dentro de este | |||
|
489 | directorio deberia de estar subdirectorios de la forma: | |||
|
490 | ||||
|
491 | path/D[yyyy][ddd]/expLabel/P[yyyy][ddd][sss][ext] | |||
|
492 | ||||
|
493 | startDateTime : Fecha inicial. Rechaza todos los archivos donde | |||
|
494 | file end time < startDatetime (obejto datetime.datetime) | |||
|
495 | ||||
|
496 | endDateTime : Fecha final. Si no es None, rechaza todos los archivos donde | |||
|
497 | file end time < startDatetime (obejto datetime.datetime) | |||
|
498 | ||||
|
499 | set : Set del primer archivo a leer. Por defecto None | |||
|
500 | ||||
|
501 | expLabel : Nombre del subdirectorio de datos. Por defecto "" | |||
|
502 | ||||
|
503 | ext : Extension de los archivos a leer. Por defecto .r | |||
|
504 | ||||
|
505 | online : | |||
|
506 | ||||
|
507 | Return: | |||
|
508 | ||||
|
509 | Affected: | |||
|
510 | ||||
|
511 | Excepciones: | |||
|
512 | ||||
|
513 | Example: | |||
|
514 | ||||
|
515 | """ | |||
|
516 | ||||
|
517 | if online == 0: | |||
|
518 | pathList, filenameList = self.__searchFiles(path, startDateTime, endDateTime, set, expLabel, ext) | |||
|
519 | ||||
|
520 | self.__idFile = -1 | |||
|
521 | ||||
|
522 | if not(self.__setNextFile()): | |||
|
523 | print "No files in range: %s - %s" %(startDateTime.ctime(), endDateTime.ctime()) | |||
|
524 | return 0 | |||
|
525 | ||||
|
526 | self.startUTCSeconds = time.mktime(startDateTime.timetuple()) | |||
|
527 | self.endUTCSeconds = time.mktime(endDateTime.timetuple()) | |||
|
528 | ||||
|
529 | self.startYear = startDateTime.timetuple().tm_year | |||
|
530 | self.endYear = endDateTime.timetuple().tm_year | |||
|
531 | ||||
|
532 | self.startDoy = startDateTime.timetuple().tm_yday | |||
|
533 | self.endDoy = endDateTime.timetuple().tm_yday | |||
|
534 | #call fillHeaderValues() - to Data Object | |||
|
535 | ||||
|
536 | self.__pathList = pathList | |||
|
537 | self.filenameList = filenameList | |||
|
538 | self.online = online | |||
|
539 | ||||
|
540 | def readNextBlock(self): | |||
|
541 | """ | |||
|
542 | readNextBlock establece un nuevo bloque de datos a leer y los lee, si es que no existiese | |||
|
543 | mas bloques disponibles en el archivo actual salta al siguiente. | |||
|
544 | ||||
|
545 | """ | |||
|
546 | ||||
|
547 | if not(self.__setNewBlock()): | |||
|
548 | return 0 | |||
|
549 | ||||
|
550 | self.__readBlock() | |||
|
551 | ||||
|
552 | self.__lastUTTime = self.m_BasicHeader.utc | |||
|
553 | ||||
|
554 | return 1 | |||
|
555 | ||||
|
556 | def getData(self): | |||
|
557 | """ | |||
|
558 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |||
|
559 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |||
|
560 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |||
|
561 | ||||
|
562 | Ademas incrementa el contador del buffer en 1. | |||
|
563 | ||||
|
564 | Inputs: | |||
|
565 | None | |||
|
566 | ||||
|
567 | Return: | |||
|
568 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |||
|
569 | buffer. Si no hay mas archivos a leer retorna None. | |||
|
570 | ||||
|
571 | Variables afectadas: | |||
|
572 | self.m_Voltage | |||
|
573 | self.__buffer_id | |||
|
574 | self.idProfile | |||
|
575 | ||||
|
576 | Excepciones: | |||
|
577 | ||||
|
578 | """ | |||
|
579 | self.flagResetProcessing = 0 | |||
|
580 | self.flagIsNewBlock = 0 | |||
|
581 | ||||
|
582 | if self.__hasNotDataInBuffer(): | |||
|
583 | self.readNextBlock() | |||
|
584 | ||||
|
585 | if self.noMoreFiles == 1: | |||
|
586 | print 'Process finished' | |||
|
587 | return None | |||
|
588 | ||||
|
589 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |||
|
590 | data = self.__buffer[self.__buffer_id,:,:] | |||
|
591 | ||||
|
592 | time = self.m_BasicHeader.utc + self.__buffer_id*self.__ippSeconds | |||
|
593 | ||||
|
594 | self.m_Voltage.m_BasicHeader = self.m_BasicHeader.copy() | |||
|
595 | self.m_Voltage.m_ProcessingHeader = self.m_ProcessingHeader.copy() | |||
|
596 | self.m_Voltage.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() | |||
|
597 | self.m_Voltage.m_SystemHeader = self.m_SystemHeader.copy() | |||
|
598 | self.m_Voltage.m_BasicHeader.utc = time | |||
|
599 | self.m_Voltage.data = data | |||
|
600 | self.m_Voltage.heights = self.__heights | |||
|
601 | self.m_Voltage.idProfile = self.idProfile | |||
|
602 | self.m_Voltage.dataType = self.__dataType | |||
|
603 | ||||
|
604 | self.__buffer_id += 1 | |||
|
605 | self.idProfile += 1 | |||
|
606 | ||||
|
607 | #call setData - to Data Object | |||
|
608 | ||||
|
609 | return data | |||
|
610 | ||||
|
611 | ||||
|
612 | ||||
|
613 | ||||
|
614 | class VoltageWriter(DataWriter): | |||
|
615 | ||||
|
616 | ||||
|
617 | def __init__(self, m_Voltage = None): | |||
|
618 | ||||
|
619 | if m_Voltage == None: | |||
|
620 | m_Voltage = Voltage() | |||
|
621 | ||||
|
622 | self.m_Voltage = m_Voltage | |||
|
623 | ||||
|
624 | self.__fp = None | |||
|
625 | ||||
|
626 | self.__blocksCounter = 0 | |||
|
627 | ||||
|
628 | self.__setFile = None | |||
|
629 | ||||
|
630 | self.__flagIsNewFile = 0 | |||
|
631 | ||||
|
632 | self.__buffer = 0 | |||
|
633 | ||||
|
634 | self.__buffer_id = 0 | |||
|
635 | ||||
|
636 | self.__dataType = None | |||
|
637 | ||||
|
638 | self.__ext = None | |||
|
639 | ||||
|
640 | self.nWriteBlocks = 0 | |||
|
641 | ||||
|
642 | self.flagIsNewBlock = 0 | |||
|
643 | ||||
|
644 | self.noMoreFiles = 0 | |||
|
645 | ||||
|
646 | self.filename = None | |||
|
647 | ||||
|
648 | self.m_BasicHeader= BasicHeader() | |||
|
649 | ||||
|
650 | self.m_SystemHeader = SystemHeader() | |||
|
651 | ||||
|
652 | self.m_RadarControllerHeader = RadarControllerHeader() | |||
|
653 | ||||
|
654 | self.m_ProcessingHeader = ProcessingHeader() | |||
|
655 | ||||
|
656 | def __setNextFile(self): | |||
|
657 | setFile = self.__setFile | |||
|
658 | ext = self.__ext | |||
|
659 | path = self.__path | |||
|
660 | ||||
|
661 | setFile += 1 | |||
|
662 | ||||
|
663 | if not(self.__blocksCounter >= self.m_ProcessingHeader.dataBlocksPerFile): | |||
|
664 | self.__fp.close() | |||
|
665 | return 0 | |||
|
666 | ||||
|
667 | timeTuple = time.localtime(self.m_Voltage.m_BasicHeader.utc) # utc from m_Voltage | |||
|
668 | file = 'D%4.4d%3.3d%3.3d%s' % (timeTuple.tm_year,timeTuple.tm_doy,setFile,ext) | |||
|
669 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_doy) | |||
|
670 | tmp = os.path.join(path,subfolder) | |||
|
671 | if not(os.path.exists(tmp)): | |||
|
672 | os.mkdir(tmp) | |||
|
673 | ||||
|
674 | filename = os.path.join(path,subfolder,file) | |||
|
675 | fp = open(filename,'wb') | |||
|
676 | ||||
|
677 | ||||
|
678 | ||||
|
679 | #guardando atributos | |||
|
680 | self.filename = filename | |||
|
681 | self.__subfolder = subfolder | |||
|
682 | self.__fp = fp | |||
|
683 | self.__setFile = setFile | |||
|
684 | self.__flagIsNewFile = 1 | |||
|
685 | ||||
|
686 | print 'Writing the file: %s'%self.filename | |||
|
687 | ||||
|
688 | return 1 | |||
|
689 | ||||
|
690 | ||||
|
691 | ||||
|
692 | def __setNewBlock(self): | |||
|
693 | if self.__fp == None: | |||
|
694 | return 0 | |||
|
695 | ||||
|
696 | if self.__flagIsNewFile: | |||
|
697 | return 1 | |||
|
698 | ||||
|
699 | #Bloques completados? | |||
|
700 | if self.__blocksCounter < self.m_ProcessingHeader.profilesPerBlock: | |||
|
701 | self.__writeBasicHeader() | |||
|
702 | return 1 | |||
|
703 | ||||
|
704 | if not(self.__setNextFile()): | |||
|
705 | return 0 | |||
|
706 | ||||
|
707 | self.__writeFirstHeader() | |||
|
708 | ||||
|
709 | return 1 | |||
|
710 | ||||
|
711 | def __writeBlock(self): | |||
|
712 | ||||
|
713 | numpy.save(self.__fp,self.__buffer) | |||
|
714 | ||||
|
715 | self.__buffer = numpy.array([],self.__dataType) | |||
|
716 | ||||
|
717 | self.__buffer_id = 0 | |||
|
718 | ||||
|
719 | self.__flagIsNewFile = 0 | |||
|
720 | ||||
|
721 | self.flagIsNewBlock = 1 | |||
|
722 | ||||
|
723 | self.nWriteBlocks += 1 | |||
|
724 | ||||
|
725 | self.__blocksCounter += 1 | |||
|
726 | ||||
|
727 | def writeNextBlock(self): | |||
|
728 | if not(self.__setNewBlock()): | |||
|
729 | return 0 | |||
|
730 | ||||
|
731 | self.__writeBlock() | |||
|
732 | ||||
|
733 | return 1 | |||
|
734 | ||||
|
735 | def __hasAllDataInBuffer(self): | |||
|
736 | if self.__buffer_id >= self.m_ProcessingHeader.profilesPerBlock: | |||
|
737 | return 1 | |||
|
738 | ||||
|
739 | return 0 | |||
|
740 | ||||
|
741 | def putData(self): | |||
|
742 | self.flagIsNewBlock = 0 | |||
|
743 | ||||
|
744 | if self.m_Voltage.noData: | |||
|
745 | return None | |||
|
746 | ||||
|
747 | shape = self.m_Voltage.data.shape | |||
|
748 | data = numpy.zeros(shape,self.__dataType) | |||
|
749 | data['real'] = self.m_Voltage.data.real | |||
|
750 | data['imag'] = self.m_Voltage.data.imag | |||
|
751 | data = data.reshape((-1)) | |||
|
752 | ||||
|
753 | self.__buffer = numpy.hstack((self.__buffer,data)) | |||
|
754 | ||||
|
755 | self.__buffer_id += 1 | |||
|
756 | ||||
|
757 | if __hasAllDataInBuffer(): | |||
|
758 | self.writeNextBlock() | |||
|
759 | ||||
|
760 | ||||
|
761 | if self.noMoreFiles: | |||
|
762 | print 'Process finished' | |||
|
763 | return None | |||
|
764 | ||||
|
765 | return 1 | |||
|
766 | ||||
|
767 | ||||
|
768 | def setup(self,path,set=None,format=None): | |||
|
769 | ||||
|
770 | if set == None: | |||
|
771 | set = -1 | |||
|
772 | else: | |||
|
773 | set -= 1 | |||
|
774 | ||||
|
775 | if format == 'hdf5': | |||
|
776 | ext = '.hdf5' | |||
|
777 | print 'call hdf5 library' | |||
|
778 | return 0 | |||
|
779 | ||||
|
780 | if format == 'rawdata': | |||
|
781 | ext = '.r' | |||
|
782 | ||||
|
783 | #call to config_headers | |||
|
784 | ||||
|
785 | self.__setFile = set | |||
|
786 | ||||
|
787 | if not(self.__setNextFile()): | |||
|
788 | print "zzzzzzzzzzzz" | |||
|
789 | return 0 | |||
|
790 | ||||
|
791 | self.__writeFirstHeader() # dentro de esta funcion se debe setear e __dataType | |||
|
792 | ||||
|
793 | self.__buffer = numpy.array([],self.__dataType) | |||
|
794 | ||||
|
795 | ||||
|
796 | ||||
|
797 | def __writeBasicHeader(self): | |||
|
798 | pass | |||
|
799 | ||||
|
800 | def __writeFirstHeader(self): | |||
|
801 | pass No newline at end of file |
@@ -0,0 +1,59 | |||||
|
1 | ''' | |||
|
2 | Created on 23/01/2012 | |||
|
3 | ||||
|
4 | @author $Author$ | |||
|
5 | @version $Id$ | |||
|
6 | ''' | |||
|
7 | import os, sys | |||
|
8 | import time, datetime | |||
|
9 | ||||
|
10 | from Model.Voltage import Voltage | |||
|
11 | from IO.VoltageIO import VoltageReader | |||
|
12 | from Graphics.VoltagePlot import Osciloscope | |||
|
13 | ||||
|
14 | class TestSChain(): | |||
|
15 | ||||
|
16 | ||||
|
17 | def __init__(self): | |||
|
18 | self.setValues() | |||
|
19 | self.createObjects() | |||
|
20 | self.testSChain() | |||
|
21 | pass | |||
|
22 | ||||
|
23 | def setValues(self): | |||
|
24 | ||||
|
25 | self.path = '/home/roj-idl71/Data/RAWDATA/DP_Faraday/' | |||
|
26 | self.path = '/home/roj-idl71/Data/RAWDATA/IMAGING' | |||
|
27 | #self.path = '/remote/puma/2004_11/DVD/' | |||
|
28 | self.startDateTime = datetime.datetime(2004,5,1,17,49,0) | |||
|
29 | self.endDateTime = datetime.datetime(2012,5,1,18,10,0) | |||
|
30 | ||||
|
31 | def createObjects(self): | |||
|
32 | ||||
|
33 | self.voltageObj = Voltage() | |||
|
34 | self.readerObj = VoltageReader(self.voltageObj) | |||
|
35 | self.plotObj = Osciloscope(self.voltageObj) | |||
|
36 | ||||
|
37 | self.readerObj.setup(self.path, self.startDateTime, self.endDateTime) | |||
|
38 | ||||
|
39 | def testSChain(self): | |||
|
40 | ||||
|
41 | while(True): | |||
|
42 | ||||
|
43 | self.readerObj.getData() | |||
|
44 | self.plotObj.plotData(idProfile = 1, type='iq', ymin = -100, ymax = 100) | |||
|
45 | ||||
|
46 | if self.readerObj.flagResetProcessing: | |||
|
47 | print 'jump' | |||
|
48 | ||||
|
49 | # if self.readerObj.flagIsNewBlock: | |||
|
50 | # print 'Block No %04d, Time: %s'%(self.readerObj.nReadBlocks, | |||
|
51 | # datetime.datetime.fromtimestamp(self.readerObj.m_BasicHeader.utc)) | |||
|
52 | ||||
|
53 | if self.readerObj.noMoreFiles: | |||
|
54 | break | |||
|
55 | ||||
|
56 | self.plotObj.end() | |||
|
57 | ||||
|
58 | if __name__ == '__main__': | |||
|
59 | TestSChain() No newline at end of file |
@@ -1,606 +1,603 | |||||
1 | """ |
|
1 | """ | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @autor $Author$ |
|
4 | @autor $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 |
|
6 | |||
7 | """ |
|
7 | """ | |
8 |
|
8 | |||
9 | import numpy |
|
9 | import numpy | |
10 | import plplot |
|
10 | import plplot | |
11 |
|
11 | |||
12 | class BaseGraph: |
|
12 | class BaseGraph: | |
13 | """ |
|
13 | """ | |
14 |
|
14 | |||
15 | """ |
|
15 | """ | |
16 |
|
16 | |||
17 | hasNotRange = True |
|
17 | ||
18 |
|
||||
19 | xrange = None |
|
|||
20 | yrange = None |
|
|||
21 | zrange = None |
|
|||
22 |
|
||||
23 | xlabel = None |
|
|||
24 | ylabel = None |
|
|||
25 | title = None |
|
|||
26 |
|
||||
27 | legends = None |
|
|||
28 |
|
||||
29 | __name = None |
|
|||
30 | __subpage = None |
|
|||
31 | __szchar = None |
|
|||
32 |
|
||||
33 | __colormap = None |
|
|||
34 | __colbox = None |
|
|||
35 | __colleg = None |
|
|||
36 |
|
||||
37 | __xpos = None |
|
|||
38 | __ypos = None |
|
|||
39 |
|
||||
40 | __xopt = None #"bcnst" |
|
|||
41 | __yopt = None #"bcnstv" |
|
|||
42 |
|
||||
43 | __xlpos = None |
|
|||
44 | __ylpos = None |
|
|||
45 |
|
||||
46 | __xrangeIsTime = False |
|
|||
47 |
|
||||
48 | #Advanced |
|
|||
49 | __xg = None |
|
|||
50 | __yg = None |
|
|||
51 |
|
18 | |||
52 | def __init__(self): |
|
19 | def __init__(self): | |
53 | """ |
|
20 | """ | |
54 |
|
21 | |||
55 | """ |
|
22 | """ | |
56 | pass |
|
23 | self.hasNotRange = True | |
57 |
|
||||
58 | def hasNotXrange(self): |
|
|||
59 |
|
24 | |||
60 |
|
|
25 | self.xrange = None | |
61 | return 1 |
|
26 | self.yrange = None | |
|
27 | self.zrange = None | |||
62 |
|
28 | |||
63 | return 0 |
|
29 | self.xlabel = None | |
64 |
|
30 | self.ylabel = None | ||
65 | def hasNotYrange(self): |
|
31 | self.title = None | |
66 |
|
32 | |||
67 |
|
|
33 | self.legends = None | |
68 | return 1 |
|
|||
69 |
|
34 | |||
70 | return 0 |
|
35 | self.__name = None | |
71 |
|
36 | |||
72 | def hasNotZrange(self): |
|
37 | self.__colormap = None | |
|
38 | self.__colbox = None | |||
|
39 | self.__colleg = None | |||
|
40 | ||||
|
41 | self.__xpos = None | |||
|
42 | self.__ypos = None | |||
73 |
|
43 | |||
74 |
|
|
44 | self.__xopt = None #"bcnst" | |
75 | return 1 |
|
45 | self.__yopt = None #"bcnstv" | |
|
46 | ||||
|
47 | self.__xlpos = None | |||
|
48 | self.__ylpos = None | |||
|
49 | ||||
|
50 | self.__xrangeIsTime = False | |||
|
51 | ||||
|
52 | #Advanced | |||
|
53 | self.__xg = None | |||
|
54 | self.__yg = None | |||
76 |
|
55 | |||
77 | return 0 |
|
|||
78 | def setName(self, name): |
|
56 | def setName(self, name): | |
79 | self.__name = name |
|
57 | self.__name = name | |
80 |
|
58 | |||
81 | def setScreenPos(self, xpos, ypos): |
|
59 | def setScreenPos(self, xpos, ypos): | |
82 | self.__xpos = xpos |
|
60 | self.__xpos = xpos | |
83 | self.__ypos = ypos |
|
61 | self.__ypos = ypos | |
84 |
|
||||
85 | def setScreenPosbyWidth(self, xoff, yoff, xw, yw): |
|
|||
86 | self.__xpos = [xoff, xoff + xw] |
|
|||
87 | self.__ypos = [yoff, yoff + yw] |
|
|||
88 |
|
||||
89 | def setSubpage(self, subpage): |
|
|||
90 | self.__subpage = subpage |
|
|||
91 |
|
||||
92 | def setSzchar(self, szchar): |
|
|||
93 | self.__szchar = szchar |
|
|||
94 |
|
62 | |||
95 | def setOpt(self, xopt, yopt): |
|
63 | def setOpt(self, xopt, yopt): | |
96 | self.__xopt = xopt |
|
64 | self.__xopt = xopt | |
97 | self.__yopt = yopt |
|
65 | self.__yopt = yopt | |
98 |
|
||||
99 | def setRanges(self, xrange, yrange, zrange=None): |
|
|||
100 | """ |
|
|||
101 | """ |
|
|||
102 | self.xrange = xrange |
|
|||
103 |
|
||||
104 | self.yrange = yrange |
|
|||
105 |
|
||||
106 | if zrange != None: |
|
|||
107 | self.zrange = zrange |
|
|||
108 |
|
||||
109 | self.hasNotRange = False |
|
|||
110 |
|
||||
111 | def setColormap(self, colormap=None): |
|
|||
112 |
|
66 | |||
113 | if colormap == None: |
|
|||
114 | colormap = self.__colormap |
|
|||
115 |
|
||||
116 | cmap1_init(colormap) |
|
|||
117 |
|
||||
118 | def setXAxisAsTime(self): |
|
67 | def setXAxisAsTime(self): | |
119 | self.__xrangeIsTime = True |
|
68 | self.__xrangeIsTime = True | |
120 |
|
69 | |||
121 | def plotBox(self): |
|
|||
122 | """ |
|
|||
123 |
|
||||
124 | """ |
|
|||
125 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) |
|
|||
126 | plplot.plwind(float(self.xrange[0]), |
|
|||
127 | float(self.xrange[1]), |
|
|||
128 | float(self.yrange[0]), |
|
|||
129 | float(self.yrange[1]) |
|
|||
130 | ) |
|
|||
131 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) |
|
|||
132 | plplot.pllab(self.xlabel, self.ylabel, self.title) |
|
|||
133 |
|
70 | |||
134 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): |
|
71 | def setup(self, title=None, xlabel=None, ylabel=None, colormap=None): | |
135 | """ |
|
72 | """ | |
136 | """ |
|
73 | """ | |
137 | self.title = title |
|
74 | self.title = title | |
138 | self.xlabel = xlabel |
|
75 | self.xlabel = xlabel | |
139 | self.ylabel = ylabel |
|
76 | self.ylabel = ylabel | |
140 | self.__colormap = colormap |
|
77 | self.__colormap = colormap | |
141 |
|
78 | |||
142 | def initSubpage(self): |
|
79 | def plotBox(self, xmin, xmax, ymin, ymax): | |
143 |
|
80 | """ | ||
144 | if plplot.plgdev() == '': |
|
|||
145 | raise ValueError, "Plot device has not been initialize" |
|
|||
146 |
|
||||
147 | plplot.pladv(self.__subpage) |
|
|||
148 | plplot.plschr(0.0, self.__szchar) |
|
|||
149 |
|
|
81 | ||
|
82 | """ | |||
150 | if self.__xrangeIsTime: |
|
83 | if self.__xrangeIsTime: | |
151 | plplot.pltimefmt("%H:%M") |
|
84 | plplot.pltimefmt("%H:%M") | |
152 |
|
85 | |||
153 | self.setColormap() |
|
86 | plplot.plvpor(self.__xpos[0], self.__xpos[1], self.__ypos[0], self.__ypos[1]) | |
154 | self.initPlot() |
|
87 | plplot.plwind(float(xmin), | |
155 |
|
88 | float(xmax), | ||
156 | def initPlot(self): |
|
89 | float(ymin), | |
157 | """ |
|
90 | float(ymax) | |
158 |
|
91 | ) | ||
159 | """ |
|
92 | plplot.plbox(self.__xopt, 0.0, 0, self.__yopt, 0.0, 0) | |
160 | if plplot.plgdev() == '': |
|
93 | plplot.pllab(self.xlabel, self.ylabel, self.title) | |
161 | raise ValueError, "Plot device has not been initialize" |
|
94 | ||
162 |
|
||||
163 | xrange = self.xrange |
|
|||
164 | if xrange == None: |
|
|||
165 | xrange = [0., 1.] |
|
|||
166 |
|
||||
167 | yrange = self.yrange |
|
|||
168 | if yrange == None: |
|
|||
169 | yrange = [0., 1.] |
|
|||
170 |
|
||||
171 | self.plotBox() |
|
|||
172 |
|
95 | |||
173 | def colorbarPlot(self): |
|
96 | def colorbarPlot(self, xmin=0., xmax=1., ymin=0., ymax=1.): | |
174 | data = numpy.arange(256) |
|
97 | data = numpy.arange(256) | |
175 | data = numpy.reshape(data, (1,-1)) |
|
98 | data = numpy.reshape(data, (1,-1)) | |
176 |
|
99 | |||
177 | self.plotBox() |
|
100 | self.plotBox(xmin, xmax, ymin, ymax) | |
178 | plplot.plimage(data, |
|
101 | plplot.plimage(data, | |
179 |
|
|
102 | float(xmin), | |
180 |
|
|
103 | float(xmax), | |
181 |
|
|
104 | float(ymin), | |
182 |
|
|
105 | float(ymax), | |
183 | 0., |
|
106 | 0., | |
184 | 255., |
|
107 | 255., | |
185 |
|
|
108 | float(xmin), | |
186 |
|
|
109 | float(xmax), | |
187 |
|
|
110 | float(ymin), | |
188 |
|
|
111 | float(ymax)) | |
|
112 | ||||
|
113 | def basicXYPlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None): | |||
|
114 | ||||
|
115 | if xmin == None: xmin = x[0] | |||
|
116 | if xmax == None: xmax = x[-1] | |||
|
117 | if ymin == None: ymin = y[0] | |||
|
118 | if ymax == None: ymax = y[-1] | |||
189 |
|
119 | |||
190 | def basicXYPlot(self, x, y): |
|
|||
191 | self.plotBox() |
|
|||
192 | plplot.plline(x, y) |
|
120 | plplot.plline(x, y) | |
193 |
|
121 | |||
194 | def basicXYwithErrorPlot(self): |
|
122 | def basicXYwithErrorPlot(self): | |
195 | pass |
|
123 | pass | |
196 |
|
124 | |||
197 | def basicLineTimePlot(self): |
|
125 | def basicLineTimePlot(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): | |
198 |
|
|
126 | ||
|
127 | if xmin == None: xmin = x[0] | |||
|
128 | if xmax == None: xmax = x[-1] | |||
|
129 | if ymin == None: ymin = y[0] | |||
|
130 | if ymax == None: ymax = y[-1] | |||
|
131 | ||||
|
132 | plplot.plcol0(colline) | |||
|
133 | plplot.plline(x, y) | |||
|
134 | plplot.plcol0(1) | |||
199 |
|
135 | |||
200 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
136 | def basicPcolorPlot(self, data, x, y, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
201 | """ |
|
137 | """ | |
202 | """ |
|
138 | """ | |
203 | if xmin == None: xmin = x[0] |
|
139 | if xmin == None: xmin = x[0] | |
204 | if xmax == None: xmax = x[-1] |
|
140 | if xmax == None: xmax = x[-1] | |
205 | if ymin == None: ymin = y[0] |
|
141 | if ymin == None: ymin = y[0] | |
206 | if ymax == None: ymax = y[-1] |
|
142 | if ymax == None: ymax = y[-1] | |
207 | if zmin == None: zmin = numpy.nanmin(data) |
|
143 | if zmin == None: zmin = numpy.nanmin(data) | |
208 | if zmax == None: zmax = numpy.nanmax(data) |
|
144 | if zmax == None: zmax = numpy.nanmax(data) | |
209 |
|
145 | |||
210 | self.plotBox() |
|
|||
211 | plplot.plimage(data, |
|
146 | plplot.plimage(data, | |
212 | float(x[0]), |
|
147 | float(x[0]), | |
213 | float(x[-1]), |
|
148 | float(x[-1]), | |
214 | float(y[0]), |
|
149 | float(y[0]), | |
215 | float(y[-1]), |
|
150 | float(y[-1]), | |
216 | float(zmin), |
|
151 | float(zmin), | |
217 | float(zmax), |
|
152 | float(zmax), | |
218 | float(xmin), |
|
153 | float(xmin), | |
219 | float(xmax), |
|
154 | float(xmax), | |
220 | float(ymin), |
|
155 | float(ymin), | |
221 | float(ymax) |
|
156 | float(ymax) | |
222 | ) |
|
157 | ) | |
223 |
|
158 | |||
224 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): |
|
159 | def __getBoxpltr(self, x, y, deltax=None, deltay=None): | |
225 |
|
160 | |||
226 | if not(len(x)>1 and len(y)>1): |
|
161 | if not(len(x)>1 and len(y)>1): | |
227 | raise ValueError, "x axis and y axis are empty" |
|
162 | raise ValueError, "x axis and y axis are empty" | |
228 |
|
163 | |||
229 | if deltax == None: deltax = x[-1] - x[-2] |
|
164 | if deltax == None: deltax = x[-1] - x[-2] | |
230 | if deltay == None: deltay = y[-1] - y[-2] |
|
165 | if deltay == None: deltay = y[-1] - y[-2] | |
231 |
|
166 | |||
232 | x1 = numpy.append(x, x[-1] + deltax) |
|
167 | x1 = numpy.append(x, x[-1] + deltax) | |
233 | y1 = numpy.append(y, y[-1] + deltay) |
|
168 | y1 = numpy.append(y, y[-1] + deltay) | |
234 |
|
169 | |||
235 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) |
|
170 | xg = (numpy.multiply.outer(x1, numpy.ones(len(y1)))) | |
236 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) |
|
171 | yg = (numpy.multiply.outer(numpy.ones(len(x1)), y1)) | |
237 |
|
172 | |||
238 | self.__xg = xg |
|
173 | self.__xg = xg | |
239 | self.__yg = yg |
|
174 | self.__yg = yg | |
240 |
|
175 | |||
241 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): |
|
176 | def advPcolorPlot(self, data, x, y, zmin=0., zmax=0.): | |
242 | """ |
|
177 | """ | |
243 | """ |
|
178 | """ | |
244 |
|
179 | |||
245 | if self.__xg == None and self.__yg == None: |
|
180 | if self.__xg == None and self.__yg == None: | |
246 | self.__getBoxpltr(x, y) |
|
181 | self.__getBoxpltr(x, y) | |
247 |
|
182 | |||
248 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) |
|
183 | plplot.plimagefr(data, x[0], x[-1], y[0], y[-1], 0., 0., zmin, zmax, plplot.pltr2, self.__xg, self.__yg) | |
249 |
|
184 | |||
250 |
|
185 | |||
|
186 | class LinearPlot(): | |||
|
187 | ||||
|
188 | __szchar = 1.0 | |||
|
189 | __xrange = None | |||
|
190 | __yrange = None | |||
|
191 | ||||
|
192 | m_BaseGraph = None | |||
|
193 | ||||
|
194 | def __init__(self): | |||
|
195 | ||||
|
196 | ||||
|
197 | key = "linearplot" | |||
|
198 | self.m_BaseGraph = BaseGraph() | |||
|
199 | self.m_BaseGraph.setName(key) | |||
|
200 | ||||
|
201 | def setColormap(self, colormap="br_green"): | |||
|
202 | ||||
|
203 | if colormap == None: | |||
|
204 | colormap = self.__colormap | |||
|
205 | ||||
|
206 | cmap1_init(colormap) | |||
|
207 | ||||
|
208 | def iniSubpage(self): | |||
|
209 | ||||
|
210 | if plplot.plgdev() == '': | |||
|
211 | raise ValueError, "Plot device has not been initialize" | |||
|
212 | ||||
|
213 | plplot.pladv(self.__subpage) | |||
|
214 | plplot.plschr(0.0, self.__szchar) | |||
|
215 | ||||
|
216 | self.setColormap() | |||
|
217 | ||||
|
218 | def setScreenPos(self, width='small'): | |||
|
219 | ||||
|
220 | if width == 'small': | |||
|
221 | xi = 0.12; yi = 0.14; xw = 0.78; yw = 0.80 | |||
|
222 | ||||
|
223 | if width == 'medium': | |||
|
224 | xi = 0.07; yi = 0.10; xw = 0.90; yw = 0.60 | |||
|
225 | ||||
|
226 | xf = xi + xw | |||
|
227 | yf = yi + yw | |||
|
228 | ||||
|
229 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) | |||
|
230 | ||||
|
231 | def setup(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): | |||
|
232 | """ | |||
|
233 | """ | |||
|
234 | ||||
|
235 | self.m_BaseGraph.setOpt("bcnts","bcntsv") | |||
|
236 | self.m_BaseGraph.setup(title, | |||
|
237 | xlabel, | |||
|
238 | ylabel | |||
|
239 | ) | |||
|
240 | ||||
|
241 | self.setScreenPos(width='medium') | |||
|
242 | ||||
|
243 | if XAxisAsTime: | |||
|
244 | self.m_BaseGraph.setXAxisAsTime() | |||
|
245 | ||||
|
246 | self.__subpage = subpage | |||
|
247 | # def setRanges(self, xrange, yrange, zrange): | |||
|
248 | # | |||
|
249 | # self.m_BaseGraph.setRanges(xrange, yrange, zrange) | |||
|
250 | ||||
|
251 | def plotData(self, x, y=None, xmin=None, xmax=None, ymin=None, ymax=None, colline=1): | |||
|
252 | """ | |||
|
253 | Inputs: | |||
|
254 | ||||
|
255 | x : Numpy array of dimension 1 | |||
|
256 | y : Numpy array of dimension 1 | |||
|
257 | ||||
|
258 | """ | |||
|
259 | ||||
|
260 | try: | |||
|
261 | nX = numpy.shape(x) | |||
|
262 | except: | |||
|
263 | raise ValueError, "x is not a numpy array" | |||
|
264 | ||||
|
265 | if y == None: y = numpy.arange(nX) | |||
|
266 | ||||
|
267 | if xmin == None: xmin = x[0] | |||
|
268 | if xmax == None: xmax = x[-1] | |||
|
269 | if ymin == None: ymin = y[0] | |||
|
270 | if ymax == None: ymax = y[-1] | |||
|
271 | ||||
|
272 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) | |||
|
273 | self.m_BaseGraph.basicLineTimePlot(x, y, xmin, xmax, ymin, ymax, colline) | |||
|
274 | ||||
|
275 | def plotComplexData(self, x, y, xmin=None, xmax=None, ymin=None, ymax=None, colline=1, type='power'): | |||
|
276 | """ | |||
|
277 | Inputs: | |||
|
278 | ||||
|
279 | x : Numpy array of dimension 1 | |||
|
280 | y : Complex numpy array of dimension 1 | |||
|
281 | ||||
|
282 | """ | |||
|
283 | ||||
|
284 | try: | |||
|
285 | nX = numpy.shape(x) | |||
|
286 | except: | |||
|
287 | raise ValueError, "x is not a numpy array" | |||
|
288 | ||||
|
289 | try: | |||
|
290 | nY = numpy.shape(y) | |||
|
291 | except: | |||
|
292 | raise ValueError, "y is not a numpy array" | |||
|
293 | ||||
|
294 | if xmin == None: xmin = x[0] | |||
|
295 | if xmax == None: xmax = x[-1] | |||
|
296 | if ymin == None: ymin = y[0] | |||
|
297 | if ymax == None: ymax = y[-1] | |||
|
298 | ||||
|
299 | self.m_BaseGraph.plotBox(xmin, xmax, ymin, ymax) | |||
|
300 | ||||
|
301 | if type.lower() == 'power': | |||
|
302 | self.m_BaseGraph.basicLineTimePlot(x, abs(y), xmin, xmax, ymin, ymax, colline) | |||
|
303 | ||||
|
304 | if type.lower() == 'iq': | |||
|
305 | ||||
|
306 | self.m_BaseGraph.basicLineTimePlot(x, y.real, xmin, xmax, ymin, ymax, colline) | |||
|
307 | self.m_BaseGraph.basicLineTimePlot(x, y.imag, xmin, xmax, ymin, ymax, colline+1) | |||
|
308 | ||||
251 | class ColorPlot(): |
|
309 | class ColorPlot(): | |
252 |
|
310 | |||
253 |
|
311 | |||
254 | graphObjDict = {} |
|
312 | graphObjDict = {} | |
255 | showColorbar = False |
|
313 | showColorbar = False | |
256 | showPowerProfile = True |
|
314 | showPowerProfile = True | |
257 |
|
315 | |||
258 | __szchar = 0.7 |
|
316 | __szchar = 0.7 | |
259 | __xrange = None |
|
317 | __xrange = None | |
260 | __yrange = None |
|
318 | __yrange = None | |
261 | __zrange = None |
|
319 | __zrange = None | |
262 |
|
320 | |||
263 | m_BaseGraph = BaseGraph() |
|
321 | m_BaseGraph = BaseGraph() | |
264 |
|
322 | |||
265 | def __init__(self): |
|
323 | def __init__(self): | |
266 |
|
324 | |||
267 | key = "colorplot" |
|
325 | key = "colorplot" | |
268 | self.m_BaseGraph.setName(key) |
|
326 | self.m_BaseGraph.setName(key) | |
269 |
|
327 | |||
270 | self.graphObjDict[key] = self.m_BaseGraph |
|
328 | self.graphObjDict[key] = self.m_BaseGraph | |
271 |
|
329 | |||
272 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): |
|
330 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", showColorbar=False, showPowerProfile=False, XAxisAsTime=False): | |
273 | """ |
|
331 | """ | |
274 | """ |
|
332 | """ | |
275 |
|
333 | |||
276 | self.m_BaseGraph.setSubpage(subpage) |
|
334 | self.m_BaseGraph.setSubpage(subpage) | |
277 | self.m_BaseGraph.setSzchar(self.__szchar) |
|
335 | self.m_BaseGraph.setSzchar(self.__szchar) | |
278 | self.m_BaseGraph.setOpt("bcnts","bcnts") |
|
336 | self.m_BaseGraph.setOpt("bcnts","bcntsv") | |
279 | self.m_BaseGraph.setup(title, |
|
337 | self.m_BaseGraph.setup(title, | |
280 | xlabel, |
|
338 | xlabel, | |
281 | ylabel, |
|
339 | ylabel, | |
282 | colormap) |
|
340 | colormap) | |
283 |
|
341 | |||
284 | if showColorbar: |
|
342 | if showColorbar: | |
285 | key = "colorbar" |
|
343 | key = "colorbar" | |
286 |
|
344 | |||
287 | cmapObj = BaseGraph() |
|
345 | cmapObj = BaseGraph() | |
288 | cmapObj.setName(key) |
|
346 | cmapObj.setName(key) | |
289 | cmapObj.setSubpage(subpage) |
|
347 | cmapObj.setSubpage(subpage) | |
290 | cmapObj.setSzchar(self.__szchar) |
|
348 | cmapObj.setSzchar(self.__szchar) | |
291 | cmapObj.setOpt("bc","bcmt") |
|
349 | cmapObj.setOpt("bc","bcmt") | |
292 | cmapObj.setup(title="dBs", |
|
350 | cmapObj.setup(title="dBs", | |
293 | xlabel="", |
|
351 | xlabel="", | |
294 | ylabel="", |
|
352 | ylabel="", | |
295 | colormap=colormap) |
|
353 | colormap=colormap) | |
296 |
|
354 | |||
297 | self.graphObjDict[key] = cmapObj |
|
355 | self.graphObjDict[key] = cmapObj | |
298 |
|
356 | |||
299 |
|
357 | |||
300 | if showPowerProfile: |
|
358 | if showPowerProfile: | |
301 | key = "powerprof" |
|
359 | key = "powerprof" | |
302 |
|
360 | |||
303 | powObj = BaseGraph() |
|
361 | powObj = BaseGraph() | |
304 | powObj.setName(key) |
|
362 | powObj.setName(key) | |
305 | powObj.setSubpage(subpage) |
|
363 | powObj.setSubpage(subpage) | |
306 | powObj.setSzchar(self.__szchar) |
|
364 | powObj.setSzchar(self.__szchar) | |
307 | plplot.pllsty(2) |
|
365 | plplot.pllsty(2) | |
308 | powObj.setOpt("bcntg","bc") |
|
366 | powObj.setOpt("bcntg","bc") | |
309 | plplot.pllsty(1) |
|
367 | plplot.pllsty(1) | |
310 | powObj.setup(title="Power Profile", |
|
368 | powObj.setup(title="Power Profile", | |
311 | xlabel="dBs", |
|
369 | xlabel="dBs", | |
312 | ylabel="") |
|
370 | ylabel="") | |
313 |
|
371 | |||
314 | self.graphObjDict[key] = powObj |
|
372 | self.graphObjDict[key] = powObj | |
315 |
|
373 | |||
316 | self.showColorbar = showColorbar |
|
374 | self.showColorbar = showColorbar | |
317 | self.showPowerProfile = showPowerProfile |
|
375 | self.showPowerProfile = showPowerProfile | |
318 | self.setPos() |
|
376 | self.setScreenPos() | |
319 |
|
377 | |||
320 | if XAxisAsTime: |
|
378 | if XAxisAsTime: | |
321 | self.m_BaseGraph.setXAxisAsTime() |
|
379 | self.m_BaseGraph.setXAxisAsTime() | |
322 | #self.setPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02) |
|
380 | #self.setScreenPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02) | |
323 |
|
381 | |||
324 |
|
382 | |||
325 | def setPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): |
|
383 | def setScreenPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80, xcmapw = 0.05, xpoww = 0.24, deltaxcmap = 0.02, deltaxpow = 0.06): | |
326 |
|
384 | |||
327 | if self.showColorbar: |
|
385 | if self.showColorbar: | |
328 | xw -= xcmapw + deltaxcmap |
|
386 | xw -= xcmapw + deltaxcmap | |
329 |
|
387 | |||
330 | if self.showPowerProfile: |
|
388 | if self.showPowerProfile: | |
331 | xw -= xpoww + deltaxpow |
|
389 | xw -= xpoww + deltaxpow | |
332 |
|
390 | |||
333 | xf = xi + xw |
|
391 | xf = xi + xw | |
334 | yf = yi + yw |
|
392 | yf = yi + yw | |
335 | xcmapf = xf |
|
393 | xcmapf = xf | |
336 |
|
394 | |||
337 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) |
|
395 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) | |
338 |
|
396 | |||
339 | if self.showColorbar: |
|
397 | if self.showColorbar: | |
340 | xcmapi = xf + deltaxcmap |
|
398 | xcmapi = xf + deltaxcmap | |
341 | xcmapf = xcmapi + xcmapw |
|
399 | xcmapf = xcmapi + xcmapw | |
342 |
|
400 | |||
343 | key = "colorbar" |
|
401 | key = "colorbar" | |
344 | cmapObj = self.graphObjDict[key] |
|
402 | cmapObj = self.graphObjDict[key] | |
345 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) |
|
403 | cmapObj.setScreenPos([xcmapi, xcmapf], [yi, yf]) | |
346 |
|
404 | |||
347 | if self.showPowerProfile: |
|
405 | if self.showPowerProfile: | |
348 |
|
406 | |||
349 | xpowi = xcmapf + deltaxpow |
|
407 | xpowi = xcmapf + deltaxpow | |
350 | xpowf = xpowi + xpoww |
|
408 | xpowf = xpowi + xpoww | |
351 |
|
409 | |||
352 | key = "powerprof" |
|
410 | key = "powerprof" | |
353 | powObj = self.graphObjDict[key] |
|
411 | powObj = self.graphObjDict[key] | |
354 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) |
|
412 | powObj.setScreenPos([xpowi, xpowf], [yi, yf]) | |
355 |
|
413 | |||
356 | def setRanges(self, xrange, yrange, zrange): |
|
414 | def setRanges(self, xrange, yrange, zrange): | |
357 |
|
415 | |||
358 | self.m_BaseGraph.setRanges(xrange, yrange, zrange) |
|
416 | self.m_BaseGraph.setRanges(xrange, yrange, zrange) | |
359 |
|
417 | |||
360 | keyList = self.graphObjDict.keys() |
|
418 | keyList = self.graphObjDict.keys() | |
361 |
|
419 | |||
362 | key = "colorbar" |
|
420 | key = "colorbar" | |
363 | if key in keyList: |
|
421 | if key in keyList: | |
364 | cmapObj = self.graphObjDict[key] |
|
422 | cmapObj = self.graphObjDict[key] | |
365 | cmapObj.setRanges([0., 1.], zrange) |
|
423 | cmapObj.setRanges([0., 1.], zrange) | |
366 |
|
424 | |||
367 | key = "powerprof" |
|
425 | key = "powerprof" | |
368 | if key in keyList: |
|
426 | if key in keyList: | |
369 | powObj = self.graphObjDict[key] |
|
427 | powObj = self.graphObjDict[key] | |
370 | powObj.setRanges(zrange, yrange) |
|
428 | powObj.setRanges(zrange, yrange) | |
371 |
|
429 | |||
372 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
430 | def plotData(self, data, x=None, y=None, xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): | |
373 | """ |
|
431 | """ | |
374 | """ |
|
432 | """ | |
375 |
|
433 | |||
376 | try: |
|
434 | try: | |
377 | nX, nY = numpy.shape(data) |
|
435 | nX, nY = numpy.shape(data) | |
378 | except: |
|
436 | except: | |
379 | raise ValueError, "data is not a numpy array" |
|
437 | raise ValueError, "data is not a numpy array" | |
380 |
|
438 | |||
381 | if x == None: x = numpy.arange(nX) |
|
439 | if x == None: x = numpy.arange(nX) | |
382 | if y == None: y = numpy.arange(nY) |
|
440 | if y == None: y = numpy.arange(nY) | |
383 |
|
441 | |||
384 | if xmin == None: xmin = x[0] |
|
442 | if xmin == None: xmin = x[0] | |
385 | if xmax == None: xmax = x[-1] |
|
443 | if xmax == None: xmax = x[-1] | |
386 | if ymin == None: ymin = y[0] |
|
444 | if ymin == None: ymin = y[0] | |
387 | if ymax == None: ymax = y[-1] |
|
445 | if ymax == None: ymax = y[-1] | |
388 | if zmin == None: zmin = numpy.nanmin(data) |
|
446 | if zmin == None: zmin = numpy.nanmin(data) | |
389 | if zmax == None: zmax = numpy.nanmax(data) |
|
447 | if zmax == None: zmax = numpy.nanmax(data) | |
390 |
|
448 | |||
391 | if self.m_BaseGraph.hasNotRange: |
|
449 | if self.m_BaseGraph.hasNotRange: | |
392 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) |
|
450 | self.setRanges([xmin, xmax], [ymin,ymax], [zmin,zmax]) | |
393 |
|
451 | |||
394 | self.m_BaseGraph.initSubpage() |
|
452 | self.m_BaseGraph.initSubpage() | |
395 | self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.m_BaseGraph.zrange[0], self.m_BaseGraph.zrange[1]) |
|
453 | self.m_BaseGraph.basicPcolorPlot(data, x, y, xmin, xmax, ymin, ymax, self.m_BaseGraph.zrange[0], self.m_BaseGraph.zrange[1]) | |
396 |
|
454 | |||
397 | if self.showColorbar: |
|
455 | if self.showColorbar: | |
398 | key = "colorbar" |
|
456 | key = "colorbar" | |
399 | cmapObj = self.graphObjDict[key] |
|
457 | cmapObj = self.graphObjDict[key] | |
400 | cmapObj.colorbarPlot() |
|
458 | cmapObj.colorbarPlot() | |
401 |
|
459 | |||
402 | if self.showPowerProfile: |
|
460 | if self.showPowerProfile: | |
403 | power = numpy.average(data, axis=1) |
|
461 | power = numpy.average(data, axis=1) | |
404 |
|
462 | |||
405 | step = (ymax - ymin)/(nY-1) |
|
463 | step = (ymax - ymin)/(nY-1) | |
406 | heis = numpy.arange(ymin, ymax + step, step) |
|
464 | heis = numpy.arange(ymin, ymax + step, step) | |
407 |
|
465 | |||
408 | key = "powerprof" |
|
466 | key = "powerprof" | |
409 | powObj = self.graphObjDict[key] |
|
467 | powObj = self.graphObjDict[key] | |
410 | powObj.basicXYPlot(power, heis) |
|
468 | powObj.basicXYPlot(power, heis) | |
411 |
|
469 | |||
412 | class LinearPlot(): |
|
|||
413 |
|
||||
414 | __szchar = 0.7 |
|
|||
415 | __xrange = None |
|
|||
416 | __yrange = None |
|
|||
417 |
|
||||
418 | m_BaseGraph = BaseGraph() |
|
|||
419 |
|
||||
420 | def __init__(self): |
|
|||
421 |
|
||||
422 | key = "linearplot" |
|
|||
423 | self.m_BaseGraph.setName(key) |
|
|||
424 |
|
||||
425 | self.graphObjDict[key] = self.m_BaseGraph |
|
|||
426 |
|
||||
427 | def setup(self, subpage, title="", xlabel="", ylabel="", colormap="jet", XAxisAsTime=False): |
|
|||
428 | """ |
|
|||
429 | """ |
|
|||
430 |
|
||||
431 | self.m_BaseGraph.setSubpage(subpage) |
|
|||
432 | self.m_BaseGraph.setSzchar(self.__szchar) |
|
|||
433 | self.m_BaseGraph.setOpt("bcnts","bcnts") |
|
|||
434 | self.m_BaseGraph.setup(title, |
|
|||
435 | xlabel, |
|
|||
436 | ylabel, |
|
|||
437 | colormap) |
|
|||
438 |
|
||||
439 | self.setPos() |
|
|||
440 |
|
||||
441 | if XAxisAsTime: |
|
|||
442 | self.m_BaseGraph.setXAxisAsTime() |
|
|||
443 | #self.setPos(xi = 0.05, yi = 0.18, xw = 0.92, yw = 0.74, xcmapw = 0.015, xpoww = 0.14, deltaxcmap = 0.01, deltaxpow = 0.02) |
|
|||
444 |
|
||||
445 |
|
||||
446 | def setPos(self, xi = 0.12, yi = 0.14, xw = 0.78, yw = 0.80): |
|
|||
447 |
|
||||
448 | xf = xi + xw |
|
|||
449 | yf = yi + yw |
|
|||
450 |
|
||||
451 | self.m_BaseGraph.setScreenPos([xi, xf], [yi, yf]) |
|
|||
452 |
|
||||
453 | def setRanges(self, xrange, yrange, zrange): |
|
|||
454 |
|
||||
455 | self.m_BaseGraph.setRanges(xrange, yrange, zrange) |
|
|||
456 |
|
||||
457 | def plotData(self, x, y): |
|
|||
458 | """ |
|
|||
459 | """ |
|
|||
460 | xmin = x[0] |
|
|||
461 | xmax = x[-1] |
|
|||
462 |
|
||||
463 | ymin = y[0] |
|
|||
464 | ymax = y[-1] |
|
|||
465 |
|
||||
466 | if self.m_BaseGraph.hasNotRange: |
|
|||
467 | self.setRanges([xmin, xmax], [ymin,ymax]) |
|
|||
468 |
|
||||
469 | self.m_BaseGraph.initSubpage() |
|
|||
470 | self.m_BaseGraph.basicLineTimePlot(x, y) |
|
|||
471 |
|
||||
472 |
|
||||
473 | def cmap1_init(colormap="gray"): |
|
470 | def cmap1_init(colormap="gray"): | |
474 |
|
471 | |||
475 | ncolor = None |
|
472 | ncolor = None | |
476 | rgb_lvl = None |
|
473 | rgb_lvl = None | |
477 |
|
474 | |||
478 | # Routine for defining a specific color map 1 in HLS space. |
|
475 | # Routine for defining a specific color map 1 in HLS space. | |
479 | # if gray is true, use basic grayscale variation from half-dark to light. |
|
476 | # if gray is true, use basic grayscale variation from half-dark to light. | |
480 | # otherwise use false color variation from blue (240 deg) to red (360 deg). |
|
477 | # otherwise use false color variation from blue (240 deg) to red (360 deg). | |
481 |
|
478 | |||
482 | # Independent variable of control points. |
|
479 | # Independent variable of control points. | |
483 | i = numpy.array((0., 1.)) |
|
480 | i = numpy.array((0., 1.)) | |
484 | if colormap=="gray": |
|
481 | if colormap=="gray": | |
485 | ncolor = 256 |
|
482 | ncolor = 256 | |
486 | # Hue for control points. Doesn't matter since saturation is zero. |
|
483 | # Hue for control points. Doesn't matter since saturation is zero. | |
487 | h = numpy.array((0., 0.)) |
|
484 | h = numpy.array((0., 0.)) | |
488 | # Lightness ranging from half-dark (for interest) to light. |
|
485 | # Lightness ranging from half-dark (for interest) to light. | |
489 | l = numpy.array((0.5, 1.)) |
|
486 | l = numpy.array((0.5, 1.)) | |
490 | # Gray scale has zero saturation |
|
487 | # Gray scale has zero saturation | |
491 | s = numpy.array((0., 0.)) |
|
488 | s = numpy.array((0., 0.)) | |
492 |
|
489 | |||
493 | # number of cmap1 colours is 256 in this case. |
|
490 | # number of cmap1 colours is 256 in this case. | |
494 | plplot.plscmap1n(ncolor) |
|
491 | plplot.plscmap1n(ncolor) | |
495 | # Interpolate between control points to set up cmap1. |
|
492 | # Interpolate between control points to set up cmap1. | |
496 | plplot.plscmap1l(0, i, h, l, s) |
|
493 | plplot.plscmap1l(0, i, h, l, s) | |
497 |
|
494 | |||
498 | return None |
|
495 | return None | |
499 |
|
496 | |||
500 | if colormap=="br_green": |
|
497 | if colormap=="br_green": | |
501 | ncolor = 256 |
|
498 | ncolor = 256 | |
502 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
499 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
503 | h = numpy.array((240., 0.)) |
|
500 | h = numpy.array((240., 0.)) | |
504 | # Lightness and saturation are constant (values taken from C example). |
|
501 | # Lightness and saturation are constant (values taken from C example). | |
505 | l = numpy.array((0.6, 0.6)) |
|
502 | l = numpy.array((0.6, 0.6)) | |
506 | s = numpy.array((0.8, 0.8)) |
|
503 | s = numpy.array((0.8, 0.8)) | |
507 |
|
504 | |||
508 | # number of cmap1 colours is 256 in this case. |
|
505 | # number of cmap1 colours is 256 in this case. | |
509 | plplot.plscmap1n(ncolor) |
|
506 | plplot.plscmap1n(ncolor) | |
510 | # Interpolate between control points to set up cmap1. |
|
507 | # Interpolate between control points to set up cmap1. | |
511 | plplot.plscmap1l(0, i, h, l, s) |
|
508 | plplot.plscmap1l(0, i, h, l, s) | |
512 |
|
509 | |||
513 | return None |
|
510 | return None | |
514 |
|
511 | |||
515 | if colormap=="tricolor": |
|
512 | if colormap=="tricolor": | |
516 | ncolor = 3 |
|
513 | ncolor = 3 | |
517 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) |
|
514 | # Hue ranges from blue (240 deg) to red (0 or 360 deg) | |
518 | h = numpy.array((240., 0.)) |
|
515 | h = numpy.array((240., 0.)) | |
519 | # Lightness and saturation are constant (values taken from C example). |
|
516 | # Lightness and saturation are constant (values taken from C example). | |
520 | l = numpy.array((0.6, 0.6)) |
|
517 | l = numpy.array((0.6, 0.6)) | |
521 | s = numpy.array((0.8, 0.8)) |
|
518 | s = numpy.array((0.8, 0.8)) | |
522 |
|
519 | |||
523 | # number of cmap1 colours is 256 in this case. |
|
520 | # number of cmap1 colours is 256 in this case. | |
524 | plplot.plscmap1n(ncolor) |
|
521 | plplot.plscmap1n(ncolor) | |
525 | # Interpolate between control points to set up cmap1. |
|
522 | # Interpolate between control points to set up cmap1. | |
526 | plplot.plscmap1l(0, i, h, l, s) |
|
523 | plplot.plscmap1l(0, i, h, l, s) | |
527 |
|
524 | |||
528 | return None |
|
525 | return None | |
529 |
|
526 | |||
530 | if colormap == 'rgb' or colormap == 'rgb666': |
|
527 | if colormap == 'rgb' or colormap == 'rgb666': | |
531 |
|
528 | |||
532 | color_sz = 6 |
|
529 | color_sz = 6 | |
533 | ncolor = color_sz*color_sz*color_sz |
|
530 | ncolor = color_sz*color_sz*color_sz | |
534 | pos = numpy.zeros((ncolor)) |
|
531 | pos = numpy.zeros((ncolor)) | |
535 | r = numpy.zeros((ncolor)) |
|
532 | r = numpy.zeros((ncolor)) | |
536 | g = numpy.zeros((ncolor)) |
|
533 | g = numpy.zeros((ncolor)) | |
537 | b = numpy.zeros((ncolor)) |
|
534 | b = numpy.zeros((ncolor)) | |
538 | ind = 0 |
|
535 | ind = 0 | |
539 | for ri in range(color_sz): |
|
536 | for ri in range(color_sz): | |
540 | for gi in range(color_sz): |
|
537 | for gi in range(color_sz): | |
541 | for bi in range(color_sz): |
|
538 | for bi in range(color_sz): | |
542 | r[ind] = ri/(color_sz-1.0) |
|
539 | r[ind] = ri/(color_sz-1.0) | |
543 | g[ind] = gi/(color_sz-1.0) |
|
540 | g[ind] = gi/(color_sz-1.0) | |
544 | b[ind] = bi/(color_sz-1.0) |
|
541 | b[ind] = bi/(color_sz-1.0) | |
545 | pos[ind] = ind/(ncolor-1.0) |
|
542 | pos[ind] = ind/(ncolor-1.0) | |
546 | ind += 1 |
|
543 | ind += 1 | |
547 | rgb_lvl = [6,6,6] #Levels for RGB colors |
|
544 | rgb_lvl = [6,6,6] #Levels for RGB colors | |
548 |
|
545 | |||
549 | if colormap == 'rgb676': |
|
546 | if colormap == 'rgb676': | |
550 | ncolor = 6*7*6 |
|
547 | ncolor = 6*7*6 | |
551 | pos = numpy.zeros((ncolor)) |
|
548 | pos = numpy.zeros((ncolor)) | |
552 | r = numpy.zeros((ncolor)) |
|
549 | r = numpy.zeros((ncolor)) | |
553 | g = numpy.zeros((ncolor)) |
|
550 | g = numpy.zeros((ncolor)) | |
554 | b = numpy.zeros((ncolor)) |
|
551 | b = numpy.zeros((ncolor)) | |
555 | ind = 0 |
|
552 | ind = 0 | |
556 | for ri in range(8): |
|
553 | for ri in range(8): | |
557 | for gi in range(8): |
|
554 | for gi in range(8): | |
558 | for bi in range(4): |
|
555 | for bi in range(4): | |
559 | r[ind] = ri/(6-1.0) |
|
556 | r[ind] = ri/(6-1.0) | |
560 | g[ind] = gi/(7-1.0) |
|
557 | g[ind] = gi/(7-1.0) | |
561 | b[ind] = bi/(6-1.0) |
|
558 | b[ind] = bi/(6-1.0) | |
562 | pos[ind] = ind/(ncolor-1.0) |
|
559 | pos[ind] = ind/(ncolor-1.0) | |
563 | ind += 1 |
|
560 | ind += 1 | |
564 | rgb_lvl = [6,7,6] #Levels for RGB colors |
|
561 | rgb_lvl = [6,7,6] #Levels for RGB colors | |
565 |
|
562 | |||
566 | if colormap == 'rgb685': |
|
563 | if colormap == 'rgb685': | |
567 | ncolor = 6*8*5 |
|
564 | ncolor = 6*8*5 | |
568 | pos = numpy.zeros((ncolor)) |
|
565 | pos = numpy.zeros((ncolor)) | |
569 | r = numpy.zeros((ncolor)) |
|
566 | r = numpy.zeros((ncolor)) | |
570 | g = numpy.zeros((ncolor)) |
|
567 | g = numpy.zeros((ncolor)) | |
571 | b = numpy.zeros((ncolor)) |
|
568 | b = numpy.zeros((ncolor)) | |
572 | ind = 0 |
|
569 | ind = 0 | |
573 | for ri in range(8): |
|
570 | for ri in range(8): | |
574 | for gi in range(8): |
|
571 | for gi in range(8): | |
575 | for bi in range(4): |
|
572 | for bi in range(4): | |
576 | r[ind] = ri/(6-1.0) |
|
573 | r[ind] = ri/(6-1.0) | |
577 | g[ind] = gi/(8-1.0) |
|
574 | g[ind] = gi/(8-1.0) | |
578 | b[ind] = bi/(5-1.0) |
|
575 | b[ind] = bi/(5-1.0) | |
579 | pos[ind] = ind/(ncolor-1.0) |
|
576 | pos[ind] = ind/(ncolor-1.0) | |
580 | ind += 1 |
|
577 | ind += 1 | |
581 | rgb_lvl = [6,8,5] #Levels for RGB colors |
|
578 | rgb_lvl = [6,8,5] #Levels for RGB colors | |
582 |
|
579 | |||
583 | if colormap == 'rgb884': |
|
580 | if colormap == 'rgb884': | |
584 | ncolor = 8*8*4 |
|
581 | ncolor = 8*8*4 | |
585 | pos = numpy.zeros((ncolor)) |
|
582 | pos = numpy.zeros((ncolor)) | |
586 | r = numpy.zeros((ncolor)) |
|
583 | r = numpy.zeros((ncolor)) | |
587 | g = numpy.zeros((ncolor)) |
|
584 | g = numpy.zeros((ncolor)) | |
588 | b = numpy.zeros((ncolor)) |
|
585 | b = numpy.zeros((ncolor)) | |
589 | ind = 0 |
|
586 | ind = 0 | |
590 | for ri in range(8): |
|
587 | for ri in range(8): | |
591 | for gi in range(8): |
|
588 | for gi in range(8): | |
592 | for bi in range(4): |
|
589 | for bi in range(4): | |
593 | r[ind] = ri/(8-1.0) |
|
590 | r[ind] = ri/(8-1.0) | |
594 | g[ind] = gi/(8-1.0) |
|
591 | g[ind] = gi/(8-1.0) | |
595 | b[ind] = bi/(4-1.0) |
|
592 | b[ind] = bi/(4-1.0) | |
596 | pos[ind] = ind/(ncolor-1.0) |
|
593 | pos[ind] = ind/(ncolor-1.0) | |
597 | ind += 1 |
|
594 | ind += 1 | |
598 | rgb_lvl = [8,8,4] #Levels for RGB colors |
|
595 | rgb_lvl = [8,8,4] #Levels for RGB colors | |
599 |
|
596 | |||
600 | if ncolor == None: |
|
597 | if ncolor == None: | |
601 | raise ValueError, "The colormap selected is not valid" |
|
598 | raise ValueError, "The colormap selected is not valid" | |
602 |
|
599 | |||
603 | plplot.plscmap1n(ncolor) |
|
600 | plplot.plscmap1n(ncolor) | |
604 | plplot.plscmap1l(1, pos, r, g, b) |
|
601 | plplot.plscmap1l(1, pos, r, g, b) | |
605 |
|
602 | |||
606 | return rgb_lvl No newline at end of file |
|
603 | return rgb_lvl |
@@ -1,96 +1,175 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 | import os, sys |
|
7 | import os, sys | |
8 | import numpy |
|
8 | import numpy | |
9 | import plplot |
|
9 | import plplot | |
10 |
|
10 | |||
11 | path = os.path.split(os.getcwd())[0] |
|
11 | path = os.path.split(os.getcwd())[0] | |
12 | sys.path.append(path) |
|
12 | sys.path.append(path) | |
13 |
|
13 | |||
14 |
from Graphics.Bas |
|
14 | from Graphics.BaseGraph import * | |
15 | from Model.Voltage import Voltage |
|
15 | from Model.Voltage import Voltage | |
16 |
|
16 | |||
17 | class Osciloscope(): |
|
17 | class Osciloscope(): | |
18 |
|
18 | |||
19 | graphObjDict = {} |
|
19 | def __init__(self, Voltage): | |
20 | showPower = True |
|
|||
21 |
|
||||
22 | __szchar = 0.7 |
|
|||
23 | __xrange = None |
|
|||
24 | __yrange = None |
|
|||
25 | __zrange = None |
|
|||
26 |
|
||||
27 | def __init__(self): |
|
|||
28 | key = "osc" |
|
|||
29 |
|
|
20 | ||
30 | baseObj = BasicGraph() |
|
21 | """ | |
31 | baseObj.setName(key) |
|
|||
32 |
|
|
22 | ||
33 | self.graphObjDict[key] = baseObj |
|
23 | Inputs: | |
|
24 | ||||
|
25 | type: "power" ->> Potencia | |||
|
26 | "iq" ->> Real + Imaginario | |||
|
27 | """ | |||
|
28 | ||||
|
29 | self.__isPlotConfig = False | |||
|
30 | ||||
|
31 | self.__isPlotIni = False | |||
|
32 | ||||
|
33 | self.__xrange = None | |||
|
34 | ||||
|
35 | self.__yrange = None | |||
|
36 | ||||
|
37 | self.m_Voltage = None | |||
|
38 | ||||
|
39 | self.nGraphs = 0 | |||
|
40 | ||||
|
41 | self.graphObjList = [] | |||
|
42 | ||||
|
43 | self.m_Voltage = Voltage | |||
34 |
|
44 | |||
35 |
|
45 | |||
36 |
def |
|
46 | def __addGraph(self, subpage, title="", xlabel="", ylabel="", XAxisAsTime=False): | |
37 |
|
|
47 | ||
38 |
|
48 | graphObj = LinearPlot() | ||
39 | def setRanges(self, xrange, yrange, zrange): |
|
49 | graphObj.setup(subpage, title="", xlabel="", ylabel="", XAxisAsTime=False) | |
40 | pass |
|
50 | #graphObj.setScreenPos() | |
|
51 | ||||
|
52 | self.graphObjList.append(graphObj) | |||
|
53 | ||||
|
54 | del graphObj | |||
41 |
|
55 | |||
42 | def plotData(self, data , xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None): |
|
56 | # def setXRange(self, xmin, xmax): | |
43 | pass |
|
57 | # self.__xrange = (xmin, xmax) | |
|
58 | # | |||
|
59 | # def setYRange(self, ymin, ymax): | |||
|
60 | # self.__yrange = (ymin, ymax) | |||
44 |
|
61 | |||
|
62 | ||||
|
63 | def setup(self, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False): | |||
|
64 | ||||
|
65 | nChan = int(self.m_Voltage.m_SystemHeader.numChannels) | |||
|
66 | ||||
|
67 | myTitle = "" | |||
|
68 | myXlabel = "" | |||
|
69 | myYlabel = "" | |||
|
70 | ||||
|
71 | for i in range(nChan): | |||
|
72 | if titleList != None: | |||
|
73 | myTitle = titleList[i] | |||
|
74 | myXlabel = xlabelList[i] | |||
|
75 | myYlabel = ylabelList[i] | |||
|
76 | ||||
|
77 | self.__addGraph(i+1, title=myTitle, xlabel=myXlabel, ylabel=myYlabel, XAxisAsTime=XAxisAsTime) | |||
|
78 | ||||
|
79 | self.nGraphs = nChan | |||
|
80 | self.__isPlotConfig = True | |||
45 |
|
81 | |||
|
82 | def iniPlot(self): | |||
|
83 | plplot.plsetopt("geometry", "%dx%d" %(700, 115*self.nGraphs)) | |||
|
84 | plplot.plsdev("xcairo") | |||
|
85 | plplot.plscolbg(255,255,255) | |||
|
86 | plplot.plscol0(1,0,0,0) | |||
|
87 | plplot.plinit() | |||
|
88 | plplot.plspause(False) | |||
|
89 | plplot.plssub(1, self.nGraphs) | |||
|
90 | ||||
|
91 | self.__isPlotIni = True | |||
|
92 | ||||
|
93 | def plotData(self, xmin=None, xmax=None, ymin=None, ymax=None, idProfile=None, titleList=None, xlabelList=None, ylabelList=None, XAxisAsTime=False, type='iq'): | |||
|
94 | ||||
|
95 | if idProfile != None and idProfile != self.m_Voltage.idProfile: | |||
|
96 | return | |||
|
97 | ||||
|
98 | if not(self.__isPlotConfig): | |||
|
99 | self.setup(titleList, xlabelList, ylabelList, XAxisAsTime) | |||
|
100 | ||||
|
101 | if not(self.__isPlotIni): | |||
|
102 | self.iniPlot() | |||
|
103 | ||||
|
104 | data = self.m_Voltage.data | |||
|
105 | ||||
|
106 | x = self.m_Voltage.heights | |||
|
107 | ||||
|
108 | if xmin == None: xmin = x[0] | |||
|
109 | if xmax == None: xmax = x[-1] | |||
|
110 | if ymin == None: ymin = numpy.nanmin(abs(data)) | |||
|
111 | if ymax == None: ymax = numpy.nanmax(abs(data)) | |||
|
112 | ||||
|
113 | plplot.plbop() | |||
|
114 | for i in range(self.nGraphs): | |||
|
115 | y = data[:,i] | |||
|
116 | ||||
|
117 | self.graphObjList[i].iniSubpage() | |||
|
118 | self.graphObjList[i].plotComplexData(x, y, xmin, xmax, ymin, ymax, 8, type) | |||
|
119 | ||||
|
120 | plplot.plflush() | |||
|
121 | plplot.pleop() | |||
46 |
|
122 | |||
|
123 | def end(self): | |||
|
124 | plplot.plend() | |||
|
125 | ||||
47 | class VoltagePlot(object): |
|
126 | class VoltagePlot(object): | |
48 | ''' |
|
127 | ''' | |
49 | classdocs |
|
128 | classdocs | |
50 | ''' |
|
129 | ''' | |
51 |
|
130 | |||
52 | __m_Voltage = None |
|
131 | __m_Voltage = None | |
53 |
|
132 | |||
54 | def __init__(self, m_Voltage): |
|
133 | def __init__(self, m_Voltage): | |
55 | ''' |
|
134 | ''' | |
56 | Constructor |
|
135 | Constructor | |
57 | ''' |
|
136 | ''' | |
58 | self.__m_Voltage = m_Voltage |
|
137 | self.__m_Voltage = m_Voltage | |
59 |
|
138 | |||
60 | def setup(self): |
|
139 | def setup(self): | |
61 | pass |
|
140 | pass | |
62 |
|
141 | |||
63 | def addGraph(self, type, xrange=None, yrange=None, zrange=None): |
|
142 | def addGraph(self, type, xrange=None, yrange=None, zrange=None): | |
64 | pass |
|
143 | pass | |
65 |
|
144 | |||
66 | def plotData(self): |
|
145 | def plotData(self): | |
67 | pass |
|
146 | pass | |
68 |
|
147 | |||
69 | if __name__ == '__main__': |
|
148 | if __name__ == '__main__': | |
70 |
|
149 | |||
71 | import numpy |
|
150 | import numpy | |
72 |
|
151 | |||
73 | plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) |
|
152 | plplot.plsetopt("geometry", "%dx%d" %(450*2, 200*2)) | |
74 | plplot.plsdev("xcairo") |
|
153 | plplot.plsdev("xcairo") | |
75 | plplot.plscolbg(255,255,255) |
|
154 | plplot.plscolbg(255,255,255) | |
76 | plplot.plscol0(1,0,0,0) |
|
155 | plplot.plscol0(1,0,0,0) | |
77 | plplot.plinit() |
|
156 | plplot.plinit() | |
78 | plplot.plssub(1, 2) |
|
157 | plplot.plssub(1, 2) | |
79 |
|
158 | |||
80 | nx = 64 |
|
159 | nx = 64 | |
81 | ny = 100 |
|
160 | ny = 100 | |
82 |
|
161 | |||
83 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
162 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
84 |
|
163 | |||
85 | baseObj = RTI() |
|
164 | baseObj = RTI() | |
86 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) |
|
165 | baseObj.setup(1, "Spectrum", "Frequency", "Range", "br_green", False, False) | |
87 | baseObj.plotData(data) |
|
166 | baseObj.plotData(data) | |
88 |
|
167 | |||
89 | data = numpy.random.uniform(-50,50,(nx,ny)) |
|
168 | data = numpy.random.uniform(-50,50,(nx,ny)) | |
90 |
|
169 | |||
91 | base2Obj = RTI() |
|
170 | base2Obj = RTI() | |
92 | base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) |
|
171 | base2Obj.setup(2, "Spectrum", "Frequency", "Range", "br_green", True, True) | |
93 | base2Obj.plotData(data) |
|
172 | base2Obj.plotData(data) | |
94 |
|
173 | |||
95 | plplot.plend() |
|
174 | plplot.plend() | |
96 | exit(0) No newline at end of file |
|
175 | exit(0) |
@@ -1,17 +1,17 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on 23/01/2012 |
|
2 | Created on 23/01/2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
8 | from Data import DataReader |
|
8 | from DataIO import DataReader | |
9 | from Data import DataWriter |
|
9 | from DataIO import DataWriter | |
10 |
|
10 | |||
11 | class CorrelationReader(DataReader): |
|
11 | class CorrelationReader(DataReader): | |
12 | def __init__(self): |
|
12 | def __init__(self): | |
13 | pass |
|
13 | pass | |
14 |
|
14 | |||
15 | class CorrelationWriter(DataWriter): |
|
15 | class CorrelationWriter(DataWriter): | |
16 | def __init__(self): |
|
16 | def __init__(self): | |
17 | pass No newline at end of file |
|
17 | pass |
1 | NO CONTENT: file renamed from schainpy/IO/Data.py to schainpy/IO/DataIO.py |
|
NO CONTENT: file renamed from schainpy/IO/Data.py to schainpy/IO/DataIO.py |
@@ -1,317 +1,317 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on 23/01/2012 |
|
2 | Created on 23/01/2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
8 | import numpy |
|
8 | import numpy | |
9 |
|
9 | |||
10 | class PROCFLAG: |
|
|||
11 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
|||
12 | DECODE_DATA = numpy.uint32(0x00000002) |
|
|||
13 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
|||
14 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
|||
15 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
|||
16 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
|||
17 |
|
||||
18 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
|||
19 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
|||
20 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
|||
21 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
|||
22 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
|||
23 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
|||
24 |
|
||||
25 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
|||
26 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
|||
27 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
|||
28 |
|
||||
29 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
|||
30 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
|||
31 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
|||
32 |
|
||||
33 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
|||
34 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
|||
35 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
|||
36 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
|||
37 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
|||
38 |
|
||||
39 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
|||
40 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
|||
41 |
|
||||
42 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
|||
43 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
|||
44 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
|||
45 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
|
|||
46 |
|
||||
47 | class BasicHeader: |
|
10 | class BasicHeader: | |
48 |
|
11 | |||
49 | def __init__(self): |
|
12 | def __init__(self): | |
50 | self.size = 0 |
|
13 | self.size = 0 | |
51 | self.version = 0 |
|
14 | self.version = 0 | |
52 | self.dataBlock = 0 |
|
15 | self.dataBlock = 0 | |
53 | self.utc = 0 |
|
16 | self.utc = 0 | |
54 | self.miliSecond = 0 |
|
17 | self.miliSecond = 0 | |
55 | self.timeZone = 0 |
|
18 | self.timeZone = 0 | |
56 | self.dstFlag = 0 |
|
19 | self.dstFlag = 0 | |
57 | self.errorCount = 0 |
|
20 | self.errorCount = 0 | |
58 | self.struct = numpy.dtype([ |
|
21 | self.struct = numpy.dtype([ | |
59 | ('nSize','<u4'), |
|
22 | ('nSize','<u4'), | |
60 | ('nVersion','<u2'), |
|
23 | ('nVersion','<u2'), | |
61 | ('nDataBlockId','<u4'), |
|
24 | ('nDataBlockId','<u4'), | |
62 | ('nUtime','<u4'), |
|
25 | ('nUtime','<u4'), | |
63 | ('nMilsec','<u2'), |
|
26 | ('nMilsec','<u2'), | |
64 | ('nTimezone','<i2'), |
|
27 | ('nTimezone','<i2'), | |
65 | ('nDstflag','<i2'), |
|
28 | ('nDstflag','<i2'), | |
66 | ('nErrorCount','<u4') |
|
29 | ('nErrorCount','<u4') | |
67 | ]) |
|
30 | ]) | |
68 | pass |
|
31 | pass | |
69 |
|
32 | |||
70 | def read(self, fp): |
|
33 | def read(self, fp): | |
71 |
|
34 | |||
72 | header = numpy.fromfile(fp, self.struct,1) |
|
35 | header = numpy.fromfile(fp, self.struct,1) | |
73 | self.size = header['nSize'][0] |
|
36 | self.size = header['nSize'][0] | |
74 | self.version = header['nVersion'][0] |
|
37 | self.version = header['nVersion'][0] | |
75 | self.dataBlock = header['nDataBlockId'][0] |
|
38 | self.dataBlock = header['nDataBlockId'][0] | |
76 | self.utc = header['nUtime'][0] |
|
39 | self.utc = header['nUtime'][0] | |
77 | self.miliSecond = header['nMilsec'][0] |
|
40 | self.miliSecond = header['nMilsec'][0] | |
78 | self.timeZone = header['nTimezone'][0] |
|
41 | self.timeZone = header['nTimezone'][0] | |
79 | self.dstFlag = header['nDstflag'][0] |
|
42 | self.dstFlag = header['nDstflag'][0] | |
80 | self.errorCount = header['nErrorCount'][0] |
|
43 | self.errorCount = header['nErrorCount'][0] | |
81 |
|
44 | |||
82 | return 1 |
|
45 | return 1 | |
83 |
|
46 | |||
84 | def copy(self): |
|
47 | def copy(self): | |
85 |
|
48 | |||
86 | obj = BasicHeader() |
|
49 | obj = BasicHeader() | |
87 | obj.size = self.size |
|
50 | obj.size = self.size | |
88 | obj.version = self.version |
|
51 | obj.version = self.version | |
89 | obj.dataBlock = self.dataBlock |
|
52 | obj.dataBlock = self.dataBlock | |
90 | obj.utc = self.utc |
|
53 | obj.utc = self.utc | |
91 | obj.miliSecond = self.miliSecond |
|
54 | obj.miliSecond = self.miliSecond | |
92 | obj.timeZone = self.timeZone |
|
55 | obj.timeZone = self.timeZone | |
93 | obj.dstFlag = self.dstFlag |
|
56 | obj.dstFlag = self.dstFlag | |
94 | obj.errorCount = self.errorCount |
|
57 | obj.errorCount = self.errorCount | |
95 |
|
58 | |||
96 | return obj |
|
59 | return obj | |
97 |
|
60 | |||
98 | class SystemHeader: |
|
61 | class SystemHeader: | |
99 |
|
62 | |||
100 | def __init__(self): |
|
63 | def __init__(self): | |
101 | self.size = 0 |
|
64 | self.size = 0 | |
102 | self.numSamples = 0 |
|
65 | self.numSamples = 0 | |
103 | self.numProfiles = 0 |
|
66 | self.numProfiles = 0 | |
104 | self.numChannels = 0 |
|
67 | self.numChannels = 0 | |
105 | self.adcResolution = 0 |
|
68 | self.adcResolution = 0 | |
106 | self.pciDioBusWidth = 0 |
|
69 | self.pciDioBusWidth = 0 | |
107 | self.struct = numpy.dtype([ |
|
70 | self.struct = numpy.dtype([ | |
108 | ('nSize','<u4'), |
|
71 | ('nSize','<u4'), | |
109 | ('nNumSamples','<u4'), |
|
72 | ('nNumSamples','<u4'), | |
110 | ('nNumProfiles','<u4'), |
|
73 | ('nNumProfiles','<u4'), | |
111 | ('nNumChannels','<u4'), |
|
74 | ('nNumChannels','<u4'), | |
112 | ('nADCResolution','<u4'), |
|
75 | ('nADCResolution','<u4'), | |
113 | ('nPCDIOBusWidth','<u4'), |
|
76 | ('nPCDIOBusWidth','<u4'), | |
114 | ]) |
|
77 | ]) | |
115 |
|
78 | |||
116 |
|
79 | |||
117 | def read(self, fp): |
|
80 | def read(self, fp): | |
118 | header = numpy.fromfile(fp,self.struct,1) |
|
81 | header = numpy.fromfile(fp,self.struct,1) | |
119 | self.size = header['nSize'][0] |
|
82 | self.size = header['nSize'][0] | |
120 | self.numSamples = header['nNumSamples'][0] |
|
83 | self.numSamples = header['nNumSamples'][0] | |
121 | self.numProfiles = header['nNumProfiles'][0] |
|
84 | self.numProfiles = header['nNumProfiles'][0] | |
122 | self.numChannels = header['nNumChannels'][0] |
|
85 | self.numChannels = header['nNumChannels'][0] | |
123 | self.adcResolution = header['nADCResolution'][0] |
|
86 | self.adcResolution = header['nADCResolution'][0] | |
124 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
87 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
125 |
|
88 | |||
126 |
|
89 | |||
127 | return 1 |
|
90 | return 1 | |
128 |
|
91 | |||
129 | def copy(self): |
|
92 | def copy(self): | |
130 |
|
93 | |||
131 | obj = SystemHeader() |
|
94 | obj = SystemHeader() | |
132 | obj.size = self.size |
|
95 | obj.size = self.size | |
133 | obj.numSamples = self.numSamples |
|
96 | obj.numSamples = self.numSamples | |
134 | obj.numProfiles = self.numProfiles |
|
97 | obj.numProfiles = self.numProfiles | |
135 | obj.numChannels = self.numChannels |
|
98 | obj.numChannels = self.numChannels | |
136 | obj.adcResolution = self.adcResolution |
|
99 | obj.adcResolution = self.adcResolution | |
137 | self.pciDioBusWidth = self.pciDioBusWidth |
|
100 | self.pciDioBusWidth = self.pciDioBusWidth | |
138 |
|
101 | |||
139 |
|
102 | |||
140 | return obj |
|
103 | return obj | |
141 |
|
104 | |||
142 | class RadarControllerHeader: |
|
105 | class RadarControllerHeader: | |
143 |
|
106 | |||
144 |
|
107 | |||
145 | def __init__(self): |
|
108 | def __init__(self): | |
146 | self.size = 0 |
|
109 | self.size = 0 | |
147 | self.expType = 0 |
|
110 | self.expType = 0 | |
148 | self.nTx = 0 |
|
111 | self.nTx = 0 | |
149 | self.ipp = 0 |
|
112 | self.ipp = 0 | |
150 | self.txA = 0 |
|
113 | self.txA = 0 | |
151 | self.txB = 0 |
|
114 | self.txB = 0 | |
152 | self.numWindows = 0 |
|
115 | self.numWindows = 0 | |
153 | self.numTaus = 0 |
|
116 | self.numTaus = 0 | |
154 | self.codeType = 0 |
|
117 | self.codeType = 0 | |
155 | self.line6Function = 0 |
|
118 | self.line6Function = 0 | |
156 | self.line5Fuction = 0 |
|
119 | self.line5Fuction = 0 | |
157 | self.fClock = 0 |
|
120 | self.fClock = 0 | |
158 | self.prePulseBefore = 0 |
|
121 | self.prePulseBefore = 0 | |
159 | self.prePulserAfter = 0 |
|
122 | self.prePulserAfter = 0 | |
160 | self.rangeIpp = 0 |
|
123 | self.rangeIpp = 0 | |
161 | self.rangeTxA = 0 |
|
124 | self.rangeTxA = 0 | |
162 | self.rangeTxB = 0 |
|
125 | self.rangeTxB = 0 | |
163 | self.struct = numpy.dtype([ |
|
126 | self.struct = numpy.dtype([ | |
164 | ('nSize','<u4'), |
|
127 | ('nSize','<u4'), | |
165 | ('nExpType','<u4'), |
|
128 | ('nExpType','<u4'), | |
166 | ('nNTx','<u4'), |
|
129 | ('nNTx','<u4'), | |
167 | ('fIpp','<f4'), |
|
130 | ('fIpp','<f4'), | |
168 | ('fTxA','<f4'), |
|
131 | ('fTxA','<f4'), | |
169 | ('fTxB','<f4'), |
|
132 | ('fTxB','<f4'), | |
170 | ('nNumWindows','<u4'), |
|
133 | ('nNumWindows','<u4'), | |
171 | ('nNumTaus','<u4'), |
|
134 | ('nNumTaus','<u4'), | |
172 | ('nCodeType','<u4'), |
|
135 | ('nCodeType','<u4'), | |
173 | ('nLine6Function','<u4'), |
|
136 | ('nLine6Function','<u4'), | |
174 | ('nLine5Function','<u4'), |
|
137 | ('nLine5Function','<u4'), | |
175 | ('fClock','<f4'), |
|
138 | ('fClock','<f4'), | |
176 | ('nPrePulseBefore','<u4'), |
|
139 | ('nPrePulseBefore','<u4'), | |
177 | ('nPrePulseAfter','<u4'), |
|
140 | ('nPrePulseAfter','<u4'), | |
178 | ('sRangeIPP','<a20'), |
|
141 | ('sRangeIPP','<a20'), | |
179 | ('sRangeTxA','<a20'), |
|
142 | ('sRangeTxA','<a20'), | |
180 | ('sRangeTxB','<a20'), |
|
143 | ('sRangeTxB','<a20'), | |
181 | ]) |
|
144 | ]) | |
182 |
|
145 | |||
183 |
|
146 | |||
184 | def read(self, fp): |
|
147 | def read(self, fp): | |
185 | header = numpy.fromfile(fp,self.struct,1) |
|
148 | header = numpy.fromfile(fp,self.struct,1) | |
186 | self.size = header['nSize'][0] |
|
149 | self.size = header['nSize'][0] | |
187 | self.expType = header['nExpType'][0] |
|
150 | self.expType = header['nExpType'][0] | |
188 | self.nTx = header['nNTx'][0] |
|
151 | self.nTx = header['nNTx'][0] | |
189 | self.ipp = header['fIpp'][0] |
|
152 | self.ipp = header['fIpp'][0] | |
190 | self.txA = header['fTxA'][0] |
|
153 | self.txA = header['fTxA'][0] | |
191 | self.txB = header['fTxB'][0] |
|
154 | self.txB = header['fTxB'][0] | |
192 | self.numWindows = header['nNumWindows'][0] |
|
155 | self.numWindows = header['nNumWindows'][0] | |
193 | self.numTaus = header['nNumTaus'][0] |
|
156 | self.numTaus = header['nNumTaus'][0] | |
194 | self.codeType = header['nCodeType'][0] |
|
157 | self.codeType = header['nCodeType'][0] | |
195 | self.line6Function = header['nLine6Function'][0] |
|
158 | self.line6Function = header['nLine6Function'][0] | |
196 | self.line5Fuction = header['nLine5Function'][0] |
|
159 | self.line5Fuction = header['nLine5Function'][0] | |
197 | self.fClock = header['fClock'][0] |
|
160 | self.fClock = header['fClock'][0] | |
198 | self.prePulseBefore = header['nPrePulseBefore'][0] |
|
161 | self.prePulseBefore = header['nPrePulseBefore'][0] | |
199 | self.prePulserAfter = header['nPrePulseAfter'][0] |
|
162 | self.prePulserAfter = header['nPrePulseAfter'][0] | |
200 | self.rangeIpp = header['sRangeIPP'][0] |
|
163 | self.rangeIpp = header['sRangeIPP'][0] | |
201 | self.rangeTxA = header['sRangeTxA'][0] |
|
164 | self.rangeTxA = header['sRangeTxA'][0] | |
202 | self.rangeTxB = header['sRangeTxB'][0] |
|
165 | self.rangeTxB = header['sRangeTxB'][0] | |
203 | # jump Dynamic Radar Controller Header |
|
166 | # jump Dynamic Radar Controller Header | |
204 | jumpHeader = self.size - 116 |
|
167 | jumpHeader = self.size - 116 | |
205 | fp.seek(fp.tell() + jumpHeader) |
|
168 | fp.seek(fp.tell() + jumpHeader) | |
206 |
|
169 | |||
207 | return 1 |
|
170 | return 1 | |
208 |
|
171 | |||
209 | def copy(self): |
|
172 | def copy(self): | |
210 |
|
173 | |||
211 | obj = RadarControllerHeader() |
|
174 | obj = RadarControllerHeader() | |
212 | obj.size = self.size |
|
175 | obj.size = self.size | |
213 | obj.expType = self.expType |
|
176 | obj.expType = self.expType | |
214 | obj.nTx = self.nTx |
|
177 | obj.nTx = self.nTx | |
215 | obj.ipp = self.ipp |
|
178 | obj.ipp = self.ipp | |
216 | obj.txA = self.txA |
|
179 | obj.txA = self.txA | |
217 | obj.txB = self.txB |
|
180 | obj.txB = self.txB | |
218 | obj.numWindows = self.numWindows |
|
181 | obj.numWindows = self.numWindows | |
219 | obj.numTaus = self.numTaus |
|
182 | obj.numTaus = self.numTaus | |
220 | obj.codeType = self.codeType |
|
183 | obj.codeType = self.codeType | |
221 | obj.line6Function = self.line6Function |
|
184 | obj.line6Function = self.line6Function | |
222 | obj.line5Fuction = self.line5Fuction |
|
185 | obj.line5Fuction = self.line5Fuction | |
223 | obj.fClock = self.fClock |
|
186 | obj.fClock = self.fClock | |
224 | obj.prePulseBefore = self.prePulseBefore |
|
187 | obj.prePulseBefore = self.prePulseBefore | |
225 | obj.prePulserAfter = self.prePulserAfter |
|
188 | obj.prePulserAfter = self.prePulserAfter | |
226 | obj.rangeIpp = self.rangeIpp |
|
189 | obj.rangeIpp = self.rangeIpp | |
227 | obj.rangeTxA = self.rangeTxA |
|
190 | obj.rangeTxA = self.rangeTxA | |
228 | obj.rangeTxB = self.rangeTxB |
|
191 | obj.rangeTxB = self.rangeTxB | |
229 |
|
192 | |||
230 | return obj |
|
193 | return obj | |
231 |
|
194 | |||
232 | class ProcessingHeader: |
|
195 | class ProcessingHeader: | |
233 |
|
196 | |||
234 | def __init__(self): |
|
197 | def __init__(self): | |
235 | self.size = 0 |
|
198 | self.size = 0 | |
236 | self.dataType = 0 |
|
199 | self.dataType = 0 | |
237 | self.blockSize = 0 |
|
200 | self.blockSize = 0 | |
238 | self.profilesPerBlock = 0 |
|
201 | self.profilesPerBlock = 0 | |
239 | self.dataBlocksPerFile = 0 |
|
202 | self.dataBlocksPerFile = 0 | |
240 | self.numWindows = 0 |
|
203 | self.numWindows = 0 | |
241 | self.processFlags = 0 |
|
204 | self.processFlags = 0 | |
242 | self.coherentInt = 0 |
|
205 | self.coherentInt = 0 | |
243 | self.incoherentInt = 0 |
|
206 | self.incoherentInt = 0 | |
244 | self.totalSpectra = 0 |
|
207 | self.totalSpectra = 0 | |
245 | self.struct = numpy.dtype([ |
|
208 | self.struct = numpy.dtype([ | |
246 | ('nSize','<u4'), |
|
209 | ('nSize','<u4'), | |
247 | ('nDataType','<u4'), |
|
210 | ('nDataType','<u4'), | |
248 | ('nSizeOfDataBlock','<u4'), |
|
211 | ('nSizeOfDataBlock','<u4'), | |
249 | ('nProfilesperBlock','<u4'), |
|
212 | ('nProfilesperBlock','<u4'), | |
250 | ('nDataBlocksperFile','<u4'), |
|
213 | ('nDataBlocksperFile','<u4'), | |
251 | ('nNumWindows','<u4'), |
|
214 | ('nNumWindows','<u4'), | |
252 | ('nProcessFlags','<u4'), |
|
215 | ('nProcessFlags','<u4'), | |
253 | ('nCoherentIntegrations','<u4'), |
|
216 | ('nCoherentIntegrations','<u4'), | |
254 | ('nIncoherentIntegrations','<u4'), |
|
217 | ('nIncoherentIntegrations','<u4'), | |
255 | ('nTotalSpectra','<u4') |
|
218 | ('nTotalSpectra','<u4') | |
256 | ]) |
|
219 | ]) | |
257 | self.samplingWindow = 0 |
|
220 | self.samplingWindow = 0 | |
258 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
221 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
259 | self.numHeights = 0 |
|
222 | self.numHeights = 0 | |
260 | self.firstHeight = 0 |
|
223 | self.firstHeight = 0 | |
261 | self.deltaHeight = 0 |
|
224 | self.deltaHeight = 0 | |
262 | self.samplesWin = 0 |
|
225 | self.samplesWin = 0 | |
263 | self.spectraComb = 0 |
|
226 | self.spectraComb = 0 | |
264 | self.numCode = 0 |
|
227 | self.numCode = 0 | |
265 | self.codes = 0 |
|
228 | self.codes = 0 | |
266 | self.numBaud = 0 |
|
229 | self.numBaud = 0 | |
267 |
|
230 | |||
268 | def read(self, fp): |
|
231 | def read(self, fp): | |
269 | header = numpy.fromfile(fp,self.struct,1) |
|
232 | header = numpy.fromfile(fp,self.struct,1) | |
270 | self.size = header['nSize'][0] |
|
233 | self.size = header['nSize'][0] | |
271 | self.dataType = header['nDataType'][0] |
|
234 | self.dataType = header['nDataType'][0] | |
272 | self.blockSize = header['nSizeOfDataBlock'][0] |
|
235 | self.blockSize = header['nSizeOfDataBlock'][0] | |
273 | self.profilesPerBlock = header['nProfilesperBlock'][0] |
|
236 | self.profilesPerBlock = header['nProfilesperBlock'][0] | |
274 | self.dataBlocksPerFile = header['nDataBlocksperFile'][0] |
|
237 | self.dataBlocksPerFile = header['nDataBlocksperFile'][0] | |
275 | self.numWindows = header['nNumWindows'][0] |
|
238 | self.numWindows = header['nNumWindows'][0] | |
276 | self.processFlags = header['nProcessFlags'] |
|
239 | self.processFlags = header['nProcessFlags'] | |
277 | self.coherentInt = header['nCoherentIntegrations'][0] |
|
240 | self.coherentInt = header['nCoherentIntegrations'][0] | |
278 | self.incoherentInt = header['nIncoherentIntegrations'][0] |
|
241 | self.incoherentInt = header['nIncoherentIntegrations'][0] | |
279 | self.totalSpectra = header['nTotalSpectra'][0] |
|
242 | self.totalSpectra = header['nTotalSpectra'][0] | |
280 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows) |
|
243 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.numWindows) | |
281 | self.numHeights = numpy.sum(self.samplingWindow['nsa']) |
|
244 | self.numHeights = numpy.sum(self.samplingWindow['nsa']) | |
282 | self.firstHeight = self.samplingWindow['h0'] |
|
245 | self.firstHeight = self.samplingWindow['h0'] | |
283 | self.deltaHeight = self.samplingWindow['dh'] |
|
246 | self.deltaHeight = self.samplingWindow['dh'] | |
284 | self.samplesWin = self.samplingWindow['nsa'] |
|
247 | self.samplesWin = self.samplingWindow['nsa'] | |
285 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
248 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) | |
286 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
249 | if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
287 | self.numCode = numpy.fromfile(fp,'<u4',1) |
|
250 | self.numCode = numpy.fromfile(fp,'<u4',1) | |
288 | self.numBaud = numpy.fromfile(fp,'<u4',1) |
|
251 | self.numBaud = numpy.fromfile(fp,'<u4',1) | |
289 | self.codes = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode) |
|
252 | self.codes = numpy.fromfile(fp,'<f4',self.numCode*self.numBaud).reshape(self.numBaud,self.numCode) | |
290 |
|
253 | |||
291 |
|
254 | |||
292 | return 1 |
|
255 | return 1 | |
293 |
|
256 | |||
294 | def copy(self): |
|
257 | def copy(self): | |
295 |
|
258 | |||
296 | obj = ProcessingHeader() |
|
259 | obj = ProcessingHeader() | |
297 | obj.size = self.size |
|
260 | obj.size = self.size | |
298 | obj.dataType = self.dataType |
|
261 | obj.dataType = self.dataType | |
299 | obj.blockSize = self.blockSize |
|
262 | obj.blockSize = self.blockSize | |
300 | obj.profilesPerBlock = self.profilesPerBlock |
|
263 | obj.profilesPerBlock = self.profilesPerBlock | |
301 | obj.dataBlocksPerFile = self.dataBlocksPerFile |
|
264 | obj.dataBlocksPerFile = self.dataBlocksPerFile | |
302 | obj.numWindows = self.numWindows |
|
265 | obj.numWindows = self.numWindows | |
303 | obj.processFlags = self.processFlags |
|
266 | obj.processFlags = self.processFlags | |
304 | obj.coherentInt = self.coherentInt |
|
267 | obj.coherentInt = self.coherentInt | |
305 | obj.incoherentInt = self.incoherentInt |
|
268 | obj.incoherentInt = self.incoherentInt | |
306 | obj.totalSpectra = self.totalSpectra |
|
269 | obj.totalSpectra = self.totalSpectra | |
307 | obj.samplingWindow = self.samplingWindow |
|
270 | obj.samplingWindow = self.samplingWindow | |
308 | obj.numHeights = self.numHeights |
|
271 | obj.numHeights = self.numHeights | |
309 | obj.firstHeight = self.firstHeight |
|
272 | obj.firstHeight = self.firstHeight | |
310 | obj.deltaHeight = self.deltaHeight |
|
273 | obj.deltaHeight = self.deltaHeight | |
311 | obj.samplesWin = self.samplesWin |
|
274 | obj.samplesWin = self.samplesWin | |
312 | obj.spectraComb = self.spectraComb |
|
275 | obj.spectraComb = self.spectraComb | |
313 | obj.numCode = self.numCode |
|
276 | obj.numCode = self.numCode | |
314 | obj.numBaud = self.numBaud |
|
277 | obj.numBaud = self.numBaud | |
315 | obj.codes = self.codes |
|
278 | obj.codes = self.codes | |
316 |
|
279 | |||
317 | return obj No newline at end of file |
|
280 | return obj | |
|
281 | ||||
|
282 | class PROCFLAG: | |||
|
283 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |||
|
284 | DECODE_DATA = numpy.uint32(0x00000002) | |||
|
285 | SPECTRA_CALC = numpy.uint32(0x00000004) | |||
|
286 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) | |||
|
287 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) | |||
|
288 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) | |||
|
289 | ||||
|
290 | DATATYPE_CHAR = numpy.uint32(0x00000040) | |||
|
291 | DATATYPE_SHORT = numpy.uint32(0x00000080) | |||
|
292 | DATATYPE_LONG = numpy.uint32(0x00000100) | |||
|
293 | DATATYPE_INT64 = numpy.uint32(0x00000200) | |||
|
294 | DATATYPE_FLOAT = numpy.uint32(0x00000400) | |||
|
295 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) | |||
|
296 | ||||
|
297 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) | |||
|
298 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) | |||
|
299 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) | |||
|
300 | ||||
|
301 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) | |||
|
302 | DEFLIP_DATA = numpy.uint32(0x00010000) | |||
|
303 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) | |||
|
304 | ||||
|
305 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) | |||
|
306 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) | |||
|
307 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) | |||
|
308 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) | |||
|
309 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) | |||
|
310 | ||||
|
311 | EXP_NAME_ESP = numpy.uint32(0x00200000) | |||
|
312 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) | |||
|
313 | ||||
|
314 | OPERATION_MASK = numpy.uint32(0x0000003F) | |||
|
315 | DATATYPE_MASK = numpy.uint32(0x00000FC0) | |||
|
316 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |||
|
317 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
@@ -1,20 +1,20 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on 23/01/2012 |
|
2 | Created on 23/01/2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 |
|
7 | |||
8 | from Header import * |
|
8 | from Header import * | |
9 | from Data import DataReader |
|
9 | from DataIO import DataReader | |
10 | from Data import DataWriter |
|
10 | from DataIO import DataWriter | |
11 |
|
11 | |||
12 |
|
12 | |||
13 | class SpectraReader(DataReader): |
|
13 | class SpectraReader(DataReader): | |
14 | def __init__(self): |
|
14 | def __init__(self): | |
15 | pass |
|
15 | pass | |
16 |
|
16 | |||
17 | class SpectraWriter(DataWriter): |
|
17 | class SpectraWriter(DataWriter): | |
18 | def __init__(self): |
|
18 | def __init__(self): | |
19 | pass |
|
19 | pass | |
20 |
|
20 |
@@ -1,54 +1,61 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Feb 7, 2012 |
|
2 | Created on Feb 7, 2012 | |
3 |
|
3 | |||
4 | @author $Author$ |
|
4 | @author $Author$ | |
5 | @version $Id$ |
|
5 | @version $Id$ | |
6 | ''' |
|
6 | ''' | |
7 | import os, sys |
|
7 | import os, sys | |
8 |
|
8 | |||
9 | path = os.path.split(os.getcwd())[0] |
|
9 | path = os.path.split(os.getcwd())[0] | |
10 | sys.path.append(path) |
|
10 | sys.path.append(path) | |
11 |
|
11 | |||
12 | from Model.Data import Data |
|
12 | from Model.Data import Data | |
13 | from IO.Header import * |
|
13 | from IO.HeaderIO import * | |
14 |
|
14 | |||
15 | class Voltage(Data): |
|
15 | class Voltage(Data): | |
16 | ''' |
|
16 | ''' | |
17 | classdocs |
|
17 | classdocs | |
18 | ''' |
|
18 | ''' | |
19 |
|
||||
20 |
|
||||
21 |
|
19 | |||
22 |
|
||||
23 |
|
||||
24 | def __init__(self): |
|
20 | def __init__(self): | |
25 | ''' |
|
21 | ''' | |
26 | Constructor |
|
22 | Constructor | |
27 | ''' |
|
23 | ''' | |
28 |
|
24 | |||
29 | self.m_RadarControllerHeader= RadarControllerHeader() |
|
25 | self.m_RadarControllerHeader= RadarControllerHeader() | |
30 |
|
||||
31 | self.m_ProcessingHeader= ProcessingHeader() |
|
|||
32 |
|
26 | |||
|
27 | self.m_ProcessingHeader= ProcessingHeader() | |||
|
28 | ||||
33 | self.m_SystemHeader= SystemHeader() |
|
29 | self.m_SystemHeader= SystemHeader() | |
34 |
|
|
30 | ||
35 | self.m_BasicHeader= BasicHeader() |
|
31 | self.m_BasicHeader= BasicHeader() | |
36 |
|
32 | |||
37 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
33 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
38 | self.data = None |
|
34 | self.data = None | |
39 |
|
35 | |||
40 |
self. |
|
36 | self.heights = None | |
41 |
|
37 | |||
42 | self.noData = True |
|
38 | self.noData = True | |
43 |
|
39 | |||
|
40 | self.nProfiles = None | |||
|
41 | ||||
|
42 | self.idProfile = None | |||
|
43 | ||||
|
44 | self.dataType = None | |||
44 |
|
45 | |||
45 |
|
||||
46 | def copy(self): |
|
46 | def copy(self): | |
47 | obj = Voltage() |
|
47 | obj = Voltage() | |
48 | obj.m_BasicHeader = self.m_BasicHeader.copy() |
|
48 | obj.m_BasicHeader = self.m_BasicHeader.copy() | |
49 | obj.m_SystemHeader = self.m_SystemHeader.copy() |
|
49 | obj.m_SystemHeader = self.m_SystemHeader.copy() | |
50 | obj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() |
|
50 | obj.m_RadarControllerHeader = self.m_RadarControllerHeader.copy() | |
51 | obj.m_ProcessingHeader = self.m_ProcessingHeader.copy() |
|
51 | obj.m_ProcessingHeader = self.m_ProcessingHeader.copy() | |
52 |
|
52 | |||
|
53 | obj.data = self.data | |||
|
54 | obj.heights = self.heights | |||
|
55 | obj.noData = self.noData | |||
|
56 | ||||
|
57 | obj.nProfiles = self.nProfiles | |||
|
58 | obj.idProfile = self.idProfile | |||
|
59 | ||||
53 | return obj |
|
60 | return obj | |
54 | No newline at end of file |
|
61 |
General Comments 0
You need to be logged in to leave comments.
Login now