@@ -1,2574 +1,2579 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ |
|
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import glob |
|
8 | import glob | |
9 | import time |
|
9 | import time | |
10 | import numpy |
|
10 | import numpy | |
11 | import fnmatch |
|
11 | import fnmatch | |
12 | import time, datetime |
|
12 | import time, datetime | |
13 |
|
13 | |||
14 | from jrodata import * |
|
14 | from jrodata import * | |
15 | from jroheaderIO import * |
|
15 | from jroheaderIO import * | |
16 | from jroprocessing import * |
|
16 | from jroprocessing import * | |
17 |
|
17 | |||
18 | LOCALTIME = -18000 |
|
18 | LOCALTIME = -18000 | |
19 |
|
19 | |||
20 | def isNumber(str): |
|
20 | def isNumber(str): | |
21 | """ |
|
21 | """ | |
22 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
22 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
23 |
|
23 | |||
24 | Excepciones: |
|
24 | Excepciones: | |
25 | Si un determinado string no puede ser convertido a numero |
|
25 | Si un determinado string no puede ser convertido a numero | |
26 | Input: |
|
26 | Input: | |
27 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
27 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
28 |
|
28 | |||
29 | Return: |
|
29 | Return: | |
30 | True : si el string es uno numerico |
|
30 | True : si el string es uno numerico | |
31 | False : no es un string numerico |
|
31 | False : no es un string numerico | |
32 | """ |
|
32 | """ | |
33 | try: |
|
33 | try: | |
34 | float( str ) |
|
34 | float( str ) | |
35 | return True |
|
35 | return True | |
36 | except: |
|
36 | except: | |
37 | return False |
|
37 | return False | |
38 |
|
38 | |||
39 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
39 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
40 | """ |
|
40 | """ | |
41 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
41 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
42 |
|
42 | |||
43 | Inputs: |
|
43 | Inputs: | |
44 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
44 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
45 |
|
45 | |||
46 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
46 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
47 | segundos contados desde 01/01/1970. |
|
47 | segundos contados desde 01/01/1970. | |
48 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
48 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
49 | segundos contados desde 01/01/1970. |
|
49 | segundos contados desde 01/01/1970. | |
50 |
|
50 | |||
51 | Return: |
|
51 | Return: | |
52 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
52 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
53 | fecha especificado, de lo contrario retorna False. |
|
53 | fecha especificado, de lo contrario retorna False. | |
54 |
|
54 | |||
55 | Excepciones: |
|
55 | Excepciones: | |
56 | Si el archivo no existe o no puede ser abierto |
|
56 | Si el archivo no existe o no puede ser abierto | |
57 | Si la cabecera no puede ser leida. |
|
57 | Si la cabecera no puede ser leida. | |
58 |
|
58 | |||
59 | """ |
|
59 | """ | |
60 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
60 | basicHeaderObj = BasicHeader(LOCALTIME) | |
61 |
|
61 | |||
62 | try: |
|
62 | try: | |
63 | fp = open(filename,'rb') |
|
63 | fp = open(filename,'rb') | |
64 | except: |
|
64 | except: | |
65 | raise IOError, "The file %s can't be opened" %(filename) |
|
65 | raise IOError, "The file %s can't be opened" %(filename) | |
66 |
|
66 | |||
67 | sts = basicHeaderObj.read(fp) |
|
67 | sts = basicHeaderObj.read(fp) | |
68 | fp.close() |
|
68 | fp.close() | |
69 |
|
69 | |||
70 | if not(sts): |
|
70 | if not(sts): | |
71 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
71 | print "Skipping the file %s because it has not a valid header" %(filename) | |
72 | return 0 |
|
72 | return 0 | |
73 |
|
73 | |||
74 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
74 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
75 | return 0 |
|
75 | return 0 | |
76 |
|
76 | |||
77 | return 1 |
|
77 | return 1 | |
78 |
|
78 | |||
79 | def isFileinThisTime(filename, startTime, endTime): |
|
79 | def isFileinThisTime(filename, startTime, endTime): | |
80 | """ |
|
80 | """ | |
81 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
81 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
82 |
|
82 | |||
83 | Inputs: |
|
83 | Inputs: | |
84 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
84 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
85 |
|
85 | |||
86 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
86 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
87 |
|
87 | |||
88 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
88 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
89 |
|
89 | |||
90 | Return: |
|
90 | Return: | |
91 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
91 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
92 | fecha especificado, de lo contrario retorna False. |
|
92 | fecha especificado, de lo contrario retorna False. | |
93 |
|
93 | |||
94 | Excepciones: |
|
94 | Excepciones: | |
95 | Si el archivo no existe o no puede ser abierto |
|
95 | Si el archivo no existe o no puede ser abierto | |
96 | Si la cabecera no puede ser leida. |
|
96 | Si la cabecera no puede ser leida. | |
97 |
|
97 | |||
98 | """ |
|
98 | """ | |
99 |
|
99 | |||
100 |
|
100 | |||
101 | try: |
|
101 | try: | |
102 | fp = open(filename,'rb') |
|
102 | fp = open(filename,'rb') | |
103 | except: |
|
103 | except: | |
104 | raise IOError, "The file %s can't be opened" %(filename) |
|
104 | raise IOError, "The file %s can't be opened" %(filename) | |
105 |
|
105 | |||
106 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
106 | basicHeaderObj = BasicHeader(LOCALTIME) | |
107 | sts = basicHeaderObj.read(fp) |
|
107 | sts = basicHeaderObj.read(fp) | |
108 | fp.close() |
|
108 | fp.close() | |
109 |
|
109 | |||
110 | thisTime = basicHeaderObj.datatime.time() |
|
110 | thisTime = basicHeaderObj.datatime.time() | |
111 |
|
111 | |||
112 | if not(sts): |
|
112 | if not(sts): | |
113 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
113 | print "Skipping the file %s because it has not a valid header" %(filename) | |
114 | return 0 |
|
114 | return 0 | |
115 |
|
115 | |||
116 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
116 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |
117 | return 0 |
|
117 | return 0 | |
118 |
|
118 | |||
119 | return 1 |
|
119 | return 1 | |
120 |
|
120 | |||
121 | def getlastFileFromPath(path, ext): |
|
121 | def getlastFileFromPath(path, ext): | |
122 | """ |
|
122 | """ | |
123 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
123 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
124 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
124 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
125 |
|
125 | |||
126 | Input: |
|
126 | Input: | |
127 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
127 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
128 | ext : extension de los files contenidos en una carpeta |
|
128 | ext : extension de los files contenidos en una carpeta | |
129 |
|
129 | |||
130 | Return: |
|
130 | Return: | |
131 | El ultimo file de una determinada carpeta, no se considera el path. |
|
131 | El ultimo file de una determinada carpeta, no se considera el path. | |
132 | """ |
|
132 | """ | |
133 | validFilelist = [] |
|
133 | validFilelist = [] | |
134 | fileList = os.listdir(path) |
|
134 | fileList = os.listdir(path) | |
135 |
|
135 | |||
136 | # 0 1234 567 89A BCDE |
|
136 | # 0 1234 567 89A BCDE | |
137 | # H YYYY DDD SSS .ext |
|
137 | # H YYYY DDD SSS .ext | |
138 |
|
138 | |||
139 | for file in fileList: |
|
139 | for file in fileList: | |
140 | try: |
|
140 | try: | |
141 | year = int(file[1:5]) |
|
141 | year = int(file[1:5]) | |
142 | doy = int(file[5:8]) |
|
142 | doy = int(file[5:8]) | |
143 |
|
143 | |||
144 |
|
144 | |||
145 | except: |
|
145 | except: | |
146 | continue |
|
146 | continue | |
147 |
|
147 | |||
148 | if (os.path.splitext(file)[-1].lower() != ext.lower()): |
|
148 | if (os.path.splitext(file)[-1].lower() != ext.lower()): | |
149 | continue |
|
149 | continue | |
150 |
|
150 | |||
151 | validFilelist.append(file) |
|
151 | validFilelist.append(file) | |
152 |
|
152 | |||
153 | if validFilelist: |
|
153 | if validFilelist: | |
154 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
154 | validFilelist = sorted( validFilelist, key=str.lower ) | |
155 | return validFilelist[-1] |
|
155 | return validFilelist[-1] | |
156 |
|
156 | |||
157 | return None |
|
157 | return None | |
158 |
|
158 | |||
159 | def checkForRealPath(path, year, doy, set, ext): |
|
159 | def checkForRealPath(path, year, doy, set, ext): | |
160 | """ |
|
160 | """ | |
161 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
161 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
162 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
162 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
163 | el path exacto de un determinado file. |
|
163 | el path exacto de un determinado file. | |
164 |
|
164 | |||
165 | Example : |
|
165 | Example : | |
166 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
166 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
167 |
|
167 | |||
168 | Entonces la funcion prueba con las siguientes combinaciones |
|
168 | Entonces la funcion prueba con las siguientes combinaciones | |
169 | .../.../y2009307367.ext |
|
169 | .../.../y2009307367.ext | |
170 | .../.../Y2009307367.ext |
|
170 | .../.../Y2009307367.ext | |
171 | .../.../x2009307/y2009307367.ext |
|
171 | .../.../x2009307/y2009307367.ext | |
172 | .../.../x2009307/Y2009307367.ext |
|
172 | .../.../x2009307/Y2009307367.ext | |
173 | .../.../X2009307/y2009307367.ext |
|
173 | .../.../X2009307/y2009307367.ext | |
174 | .../.../X2009307/Y2009307367.ext |
|
174 | .../.../X2009307/Y2009307367.ext | |
175 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
175 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
176 |
|
176 | |||
177 | Return: |
|
177 | Return: | |
178 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
178 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
179 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
179 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
180 | para el filename |
|
180 | para el filename | |
181 | """ |
|
181 | """ | |
182 | fullfilename = None |
|
182 | fullfilename = None | |
183 | find_flag = False |
|
183 | find_flag = False | |
184 | filename = None |
|
184 | filename = None | |
185 |
|
185 | |||
186 | prefixDirList = [None,'d','D'] |
|
186 | prefixDirList = [None,'d','D'] | |
187 | if ext.lower() == ".r": #voltage |
|
187 | if ext.lower() == ".r": #voltage | |
188 | prefixFileList = ['d','D'] |
|
188 | prefixFileList = ['d','D'] | |
189 | elif ext.lower() == ".pdata": #spectra |
|
189 | elif ext.lower() == ".pdata": #spectra | |
190 | prefixFileList = ['p','P'] |
|
190 | prefixFileList = ['p','P'] | |
191 | else: |
|
191 | else: | |
192 | return None, filename |
|
192 | return None, filename | |
193 |
|
193 | |||
194 | #barrido por las combinaciones posibles |
|
194 | #barrido por las combinaciones posibles | |
195 | for prefixDir in prefixDirList: |
|
195 | for prefixDir in prefixDirList: | |
196 | thispath = path |
|
196 | thispath = path | |
197 | if prefixDir != None: |
|
197 | if prefixDir != None: | |
198 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
198 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
199 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) |
|
199 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) | |
200 |
|
200 | |||
201 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" |
|
201 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" | |
202 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
202 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
203 | fullfilename = os.path.join( thispath, filename ) #formo el path completo |
|
203 | fullfilename = os.path.join( thispath, filename ) #formo el path completo | |
204 |
|
204 | |||
205 | if os.path.exists( fullfilename ): #verifico que exista |
|
205 | if os.path.exists( fullfilename ): #verifico que exista | |
206 | find_flag = True |
|
206 | find_flag = True | |
207 | break |
|
207 | break | |
208 | if find_flag: |
|
208 | if find_flag: | |
209 | break |
|
209 | break | |
210 |
|
210 | |||
211 | if not(find_flag): |
|
211 | if not(find_flag): | |
212 | return None, filename |
|
212 | return None, filename | |
213 |
|
213 | |||
214 | return fullfilename, filename |
|
214 | return fullfilename, filename | |
215 |
|
215 | |||
216 | class JRODataIO: |
|
216 | class JRODataIO: | |
217 |
|
217 | |||
218 | c = 3E8 |
|
218 | c = 3E8 | |
219 |
|
219 | |||
220 | isConfig = False |
|
220 | isConfig = False | |
221 |
|
221 | |||
222 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
222 | basicHeaderObj = BasicHeader(LOCALTIME) | |
223 |
|
223 | |||
224 | systemHeaderObj = SystemHeader() |
|
224 | systemHeaderObj = SystemHeader() | |
225 |
|
225 | |||
226 | radarControllerHeaderObj = RadarControllerHeader() |
|
226 | radarControllerHeaderObj = RadarControllerHeader() | |
227 |
|
227 | |||
228 | processingHeaderObj = ProcessingHeader() |
|
228 | processingHeaderObj = ProcessingHeader() | |
229 |
|
229 | |||
230 | online = 0 |
|
230 | online = 0 | |
231 |
|
231 | |||
232 | dtype = None |
|
232 | dtype = None | |
233 |
|
233 | |||
234 | pathList = [] |
|
234 | pathList = [] | |
235 |
|
235 | |||
236 | filenameList = [] |
|
236 | filenameList = [] | |
237 |
|
237 | |||
238 | filename = None |
|
238 | filename = None | |
239 |
|
239 | |||
240 | ext = None |
|
240 | ext = None | |
241 |
|
241 | |||
242 | flagIsNewFile = 1 |
|
242 | flagIsNewFile = 1 | |
243 |
|
243 | |||
244 | flagTimeBlock = 0 |
|
244 | flagTimeBlock = 0 | |
245 |
|
245 | |||
246 | flagIsNewBlock = 0 |
|
246 | flagIsNewBlock = 0 | |
247 |
|
247 | |||
248 | fp = None |
|
248 | fp = None | |
249 |
|
249 | |||
250 | firstHeaderSize = 0 |
|
250 | firstHeaderSize = 0 | |
251 |
|
251 | |||
252 | basicHeaderSize = 24 |
|
252 | basicHeaderSize = 24 | |
253 |
|
253 | |||
254 | versionFile = 1103 |
|
254 | versionFile = 1103 | |
255 |
|
255 | |||
256 | fileSize = None |
|
256 | fileSize = None | |
257 |
|
257 | |||
258 | ippSeconds = None |
|
258 | ippSeconds = None | |
259 |
|
259 | |||
260 | fileSizeByHeader = None |
|
260 | fileSizeByHeader = None | |
261 |
|
261 | |||
262 | fileIndex = None |
|
262 | fileIndex = None | |
263 |
|
263 | |||
264 | profileIndex = None |
|
264 | profileIndex = None | |
265 |
|
265 | |||
266 | blockIndex = None |
|
266 | blockIndex = None | |
267 |
|
267 | |||
268 | nTotalBlocks = None |
|
268 | nTotalBlocks = None | |
269 |
|
269 | |||
270 | maxTimeStep = 30 |
|
270 | maxTimeStep = 30 | |
271 |
|
271 | |||
272 | lastUTTime = None |
|
272 | lastUTTime = None | |
273 |
|
273 | |||
274 | datablock = None |
|
274 | datablock = None | |
275 |
|
275 | |||
276 | dataOut = None |
|
276 | dataOut = None | |
277 |
|
277 | |||
278 | blocksize = None |
|
278 | blocksize = None | |
279 |
|
279 | |||
280 | def __init__(self): |
|
280 | def __init__(self): | |
281 |
|
281 | |||
282 | raise ValueError, "Not implemented" |
|
282 | raise ValueError, "Not implemented" | |
283 |
|
283 | |||
284 | def run(self): |
|
284 | def run(self): | |
285 |
|
285 | |||
286 | raise ValueError, "Not implemented" |
|
286 | raise ValueError, "Not implemented" | |
287 |
|
287 | |||
288 | def getOutput(self): |
|
288 | def getOutput(self): | |
289 |
|
289 | |||
290 | return self.dataOut |
|
290 | return self.dataOut | |
291 |
|
291 | |||
292 | class JRODataReader(JRODataIO, ProcessingUnit): |
|
292 | class JRODataReader(JRODataIO, ProcessingUnit): | |
293 |
|
293 | |||
294 | nReadBlocks = 0 |
|
294 | nReadBlocks = 0 | |
295 |
|
295 | |||
296 | delay = 10 #number of seconds waiting a new file |
|
296 | delay = 10 #number of seconds waiting a new file | |
297 |
|
297 | |||
298 | nTries = 3 #quantity tries |
|
298 | nTries = 3 #quantity tries | |
299 |
|
299 | |||
300 | nFiles = 3 #number of files for searching |
|
300 | nFiles = 3 #number of files for searching | |
301 |
|
301 | |||
302 | flagNoMoreFiles = 0 |
|
302 | flagNoMoreFiles = 0 | |
303 |
|
303 | |||
304 | def __init__(self): |
|
304 | def __init__(self): | |
305 |
|
305 | |||
306 | """ |
|
306 | """ | |
307 |
|
307 | |||
308 | """ |
|
308 | """ | |
309 |
|
309 | |||
310 | raise ValueError, "This method has not been implemented" |
|
310 | raise ValueError, "This method has not been implemented" | |
311 |
|
311 | |||
312 |
|
312 | |||
313 | def createObjByDefault(self): |
|
313 | def createObjByDefault(self): | |
314 | """ |
|
314 | """ | |
315 |
|
315 | |||
316 | """ |
|
316 | """ | |
317 | raise ValueError, "This method has not been implemented" |
|
317 | raise ValueError, "This method has not been implemented" | |
318 |
|
318 | |||
319 | def getBlockDimension(self): |
|
319 | def getBlockDimension(self): | |
320 |
|
320 | |||
321 | raise ValueError, "No implemented" |
|
321 | raise ValueError, "No implemented" | |
322 |
|
322 | |||
323 | def __searchFilesOffLine(self, |
|
323 | def __searchFilesOffLine(self, | |
324 | path, |
|
324 | path, | |
325 | startDate, |
|
325 | startDate, | |
326 | endDate, |
|
326 | endDate, | |
327 | startTime=datetime.time(0,0,0), |
|
327 | startTime=datetime.time(0,0,0), | |
328 | endTime=datetime.time(23,59,59), |
|
328 | endTime=datetime.time(23,59,59), | |
329 | set=None, |
|
329 | set=None, | |
330 | expLabel='', |
|
330 | expLabel='', | |
331 | ext='.r', |
|
331 | ext='.r', | |
332 | walk=True): |
|
332 | walk=True): | |
333 |
|
333 | |||
334 | pathList = [] |
|
334 | pathList = [] | |
335 |
|
335 | |||
336 | if not walk: |
|
336 | if not walk: | |
337 | pathList.append(path) |
|
337 | pathList.append(path) | |
338 |
|
338 | |||
339 | else: |
|
339 | else: | |
340 | dirList = [] |
|
340 | dirList = [] | |
341 | for thisPath in os.listdir(path): |
|
341 | for thisPath in os.listdir(path): | |
342 | if os.path.isdir(os.path.join(path,thisPath)): |
|
342 | if os.path.isdir(os.path.join(path,thisPath)): | |
343 | dirList.append(thisPath) |
|
343 | dirList.append(thisPath) | |
344 |
|
344 | |||
345 | if not(dirList): |
|
345 | if not(dirList): | |
346 | return None, None |
|
346 | return None, None | |
347 |
|
347 | |||
348 | thisDate = startDate |
|
348 | thisDate = startDate | |
349 |
|
349 | |||
350 | while(thisDate <= endDate): |
|
350 | while(thisDate <= endDate): | |
351 | year = thisDate.timetuple().tm_year |
|
351 | year = thisDate.timetuple().tm_year | |
352 | doy = thisDate.timetuple().tm_yday |
|
352 | doy = thisDate.timetuple().tm_yday | |
353 |
|
353 | |||
354 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) |
|
354 | match = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy)) | |
355 | if len(match) == 0: |
|
355 | if len(match) == 0: | |
356 | thisDate += datetime.timedelta(1) |
|
356 | thisDate += datetime.timedelta(1) | |
357 | continue |
|
357 | continue | |
358 |
|
358 | |||
359 | pathList.append(os.path.join(path,match[0],expLabel)) |
|
359 | pathList.append(os.path.join(path,match[0],expLabel)) | |
360 | thisDate += datetime.timedelta(1) |
|
360 | thisDate += datetime.timedelta(1) | |
361 |
|
361 | |||
362 | if pathList == []: |
|
362 | if pathList == []: | |
363 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
363 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) | |
364 | return None, None |
|
364 | return None, None | |
365 |
|
365 | |||
366 | print "%d folder(s) was(were) found for the date range: %s-%s" %(len(pathList), startDate, endDate) |
|
366 | print "%d folder(s) was(were) found for the date range: %s-%s" %(len(pathList), startDate, endDate) | |
367 |
|
367 | |||
368 | filenameList = [] |
|
368 | filenameList = [] | |
369 | for thisPath in pathList: |
|
369 | for thisPath in pathList: | |
370 |
|
370 | |||
371 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
371 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
372 | fileList.sort() |
|
372 | fileList.sort() | |
373 |
|
373 | |||
374 | for file in fileList: |
|
374 | for file in fileList: | |
375 |
|
375 | |||
376 | filename = os.path.join(thisPath,file) |
|
376 | filename = os.path.join(thisPath,file) | |
377 |
|
377 | |||
378 | if isFileinThisTime(filename, startTime, endTime): |
|
378 | if isFileinThisTime(filename, startTime, endTime): | |
379 | filenameList.append(filename) |
|
379 | filenameList.append(filename) | |
380 |
|
380 | |||
381 | if not(filenameList): |
|
381 | if not(filenameList): | |
382 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
382 | print "Any file was found for the time range %s - %s" %(startTime, endTime) | |
383 | return None, None |
|
383 | return None, None | |
384 |
|
384 | |||
385 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
385 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) | |
386 |
|
386 | |||
387 | self.filenameList = filenameList |
|
387 | self.filenameList = filenameList | |
388 |
|
388 | |||
389 | return pathList, filenameList |
|
389 | return pathList, filenameList | |
390 |
|
390 | |||
391 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True): |
|
391 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True): | |
392 |
|
392 | |||
393 | """ |
|
393 | """ | |
394 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
394 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
395 | devuelve el archivo encontrado ademas de otros datos. |
|
395 | devuelve el archivo encontrado ademas de otros datos. | |
396 |
|
396 | |||
397 | Input: |
|
397 | Input: | |
398 | path : carpeta donde estan contenidos los files que contiene data |
|
398 | path : carpeta donde estan contenidos los files que contiene data | |
399 |
|
399 | |||
400 | expLabel : Nombre del subexperimento (subfolder) |
|
400 | expLabel : Nombre del subexperimento (subfolder) | |
401 |
|
401 | |||
402 | ext : extension de los files |
|
402 | ext : extension de los files | |
403 |
|
403 | |||
404 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
404 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) | |
405 |
|
405 | |||
406 | Return: |
|
406 | Return: | |
407 | directory : eL directorio donde esta el file encontrado |
|
407 | directory : eL directorio donde esta el file encontrado | |
408 | filename : el ultimo file de una determinada carpeta |
|
408 | filename : el ultimo file de una determinada carpeta | |
409 | year : el anho |
|
409 | year : el anho | |
410 | doy : el numero de dia del anho |
|
410 | doy : el numero de dia del anho | |
411 | set : el set del archivo |
|
411 | set : el set del archivo | |
412 |
|
412 | |||
413 |
|
413 | |||
414 | """ |
|
414 | """ | |
415 | dirList = [] |
|
415 | dirList = [] | |
416 |
|
416 | |||
417 | if walk: |
|
417 | if walk: | |
418 |
|
418 | |||
419 | #Filtra solo los directorios |
|
419 | #Filtra solo los directorios | |
420 | for thisPath in os.listdir(path): |
|
420 | for thisPath in os.listdir(path): | |
421 | if os.path.isdir(os.path.join(path, thisPath)): |
|
421 | if os.path.isdir(os.path.join(path, thisPath)): | |
422 | dirList.append(thisPath) |
|
422 | dirList.append(thisPath) | |
423 |
|
423 | |||
424 | if not(dirList): |
|
424 | if not(dirList): | |
425 | return None, None, None, None, None |
|
425 | return None, None, None, None, None | |
426 |
|
426 | |||
427 | dirList = sorted( dirList, key=str.lower ) |
|
427 | dirList = sorted( dirList, key=str.lower ) | |
428 |
|
428 | |||
429 | doypath = dirList[-1] |
|
429 | doypath = dirList[-1] | |
430 | fullpath = os.path.join(path, doypath, expLabel) |
|
430 | fullpath = os.path.join(path, doypath, expLabel) | |
431 |
|
431 | |||
432 | else: |
|
432 | else: | |
433 | fullpath = path |
|
433 | fullpath = path | |
434 |
|
434 | |||
435 | filename = getlastFileFromPath(fullpath, ext) |
|
435 | filename = getlastFileFromPath(fullpath, ext) | |
436 |
|
436 | |||
437 | if not(filename): |
|
437 | if not(filename): | |
438 | return None, None, None, None, None |
|
438 | return None, None, None, None, None | |
439 |
|
439 | |||
440 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
440 | if not(self.__verifyFile(os.path.join(fullpath, filename))): | |
441 | return None, None, None, None, None |
|
441 | return None, None, None, None, None | |
442 |
|
442 | |||
443 | year = int( filename[1:5] ) |
|
443 | year = int( filename[1:5] ) | |
444 | doy = int( filename[5:8] ) |
|
444 | doy = int( filename[5:8] ) | |
445 | set = int( filename[8:11] ) |
|
445 | set = int( filename[8:11] ) | |
446 |
|
446 | |||
447 | return fullpath, filename, year, doy, set |
|
447 | return fullpath, filename, year, doy, set | |
448 |
|
448 | |||
449 |
|
449 | |||
450 |
|
450 | |||
451 | def __setNextFileOffline(self): |
|
451 | def __setNextFileOffline(self): | |
452 |
|
452 | |||
453 | idFile = self.fileIndex |
|
453 | idFile = self.fileIndex | |
454 |
|
454 | |||
455 | while (True): |
|
455 | while (True): | |
456 | idFile += 1 |
|
456 | idFile += 1 | |
457 | if not(idFile < len(self.filenameList)): |
|
457 | if not(idFile < len(self.filenameList)): | |
458 | self.flagNoMoreFiles = 1 |
|
458 | self.flagNoMoreFiles = 1 | |
459 | print "No more Files" |
|
459 | print "No more Files" | |
460 | return 0 |
|
460 | return 0 | |
461 |
|
461 | |||
462 | filename = self.filenameList[idFile] |
|
462 | filename = self.filenameList[idFile] | |
463 |
|
463 | |||
464 | if not(self.__verifyFile(filename)): |
|
464 | if not(self.__verifyFile(filename)): | |
465 | continue |
|
465 | continue | |
466 |
|
466 | |||
467 | fileSize = os.path.getsize(filename) |
|
467 | fileSize = os.path.getsize(filename) | |
468 | fp = open(filename,'rb') |
|
468 | fp = open(filename,'rb') | |
469 | break |
|
469 | break | |
470 |
|
470 | |||
471 | self.flagIsNewFile = 1 |
|
471 | self.flagIsNewFile = 1 | |
472 | self.fileIndex = idFile |
|
472 | self.fileIndex = idFile | |
473 | self.filename = filename |
|
473 | self.filename = filename | |
474 | self.fileSize = fileSize |
|
474 | self.fileSize = fileSize | |
475 | self.fp = fp |
|
475 | self.fp = fp | |
476 |
|
476 | |||
477 | print "Setting the file: %s"%self.filename |
|
477 | print "Setting the file: %s"%self.filename | |
478 |
|
478 | |||
479 | return 1 |
|
479 | return 1 | |
480 |
|
480 | |||
481 | def __setNextFileOnline(self): |
|
481 | def __setNextFileOnline(self): | |
482 | """ |
|
482 | """ | |
483 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
483 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
484 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
484 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
485 | siguientes. |
|
485 | siguientes. | |
486 |
|
486 | |||
487 | Affected: |
|
487 | Affected: | |
488 | self.flagIsNewFile |
|
488 | self.flagIsNewFile | |
489 | self.filename |
|
489 | self.filename | |
490 | self.fileSize |
|
490 | self.fileSize | |
491 | self.fp |
|
491 | self.fp | |
492 | self.set |
|
492 | self.set | |
493 | self.flagNoMoreFiles |
|
493 | self.flagNoMoreFiles | |
494 |
|
494 | |||
495 | Return: |
|
495 | Return: | |
496 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
496 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
497 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
497 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
498 |
|
498 | |||
499 | Excepciones: |
|
499 | Excepciones: | |
500 | Si un determinado file no puede ser abierto |
|
500 | Si un determinado file no puede ser abierto | |
501 | """ |
|
501 | """ | |
502 | nFiles = 0 |
|
502 | nFiles = 0 | |
503 | fileOk_flag = False |
|
503 | fileOk_flag = False | |
504 | firstTime_flag = True |
|
504 | firstTime_flag = True | |
505 |
|
505 | |||
506 | self.set += 1 |
|
506 | self.set += 1 | |
507 |
|
507 | |||
508 | #busca el 1er file disponible |
|
508 | #busca el 1er file disponible | |
509 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
509 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
510 | if fullfilename: |
|
510 | if fullfilename: | |
511 | if self.__verifyFile(fullfilename, False): |
|
511 | if self.__verifyFile(fullfilename, False): | |
512 | fileOk_flag = True |
|
512 | fileOk_flag = True | |
513 |
|
513 | |||
514 | #si no encuentra un file entonces espera y vuelve a buscar |
|
514 | #si no encuentra un file entonces espera y vuelve a buscar | |
515 | if not(fileOk_flag): |
|
515 | if not(fileOk_flag): | |
516 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
516 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles | |
517 |
|
517 | |||
518 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
518 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
519 | tries = self.nTries |
|
519 | tries = self.nTries | |
520 | else: |
|
520 | else: | |
521 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
521 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
522 |
|
522 | |||
523 | for nTries in range( tries ): |
|
523 | for nTries in range( tries ): | |
524 | if firstTime_flag: |
|
524 | if firstTime_flag: | |
525 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
525 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) | |
526 | time.sleep( self.delay ) |
|
526 | time.sleep( self.delay ) | |
527 | else: |
|
527 | else: | |
528 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
528 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
529 |
|
529 | |||
530 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) |
|
530 | fullfilename, filename = checkForRealPath( self.path, self.year, self.doy, self.set, self.ext ) | |
531 | if fullfilename: |
|
531 | if fullfilename: | |
532 | if self.__verifyFile(fullfilename): |
|
532 | if self.__verifyFile(fullfilename): | |
533 | fileOk_flag = True |
|
533 | fileOk_flag = True | |
534 | break |
|
534 | break | |
535 |
|
535 | |||
536 | if fileOk_flag: |
|
536 | if fileOk_flag: | |
537 | break |
|
537 | break | |
538 |
|
538 | |||
539 | firstTime_flag = False |
|
539 | firstTime_flag = False | |
540 |
|
540 | |||
541 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
541 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename | |
542 | self.set += 1 |
|
542 | self.set += 1 | |
543 |
|
543 | |||
544 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
544 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
545 | self.set = 0 |
|
545 | self.set = 0 | |
546 | self.doy += 1 |
|
546 | self.doy += 1 | |
547 |
|
547 | |||
548 | if fileOk_flag: |
|
548 | if fileOk_flag: | |
549 | self.fileSize = os.path.getsize( fullfilename ) |
|
549 | self.fileSize = os.path.getsize( fullfilename ) | |
550 | self.filename = fullfilename |
|
550 | self.filename = fullfilename | |
551 | self.flagIsNewFile = 1 |
|
551 | self.flagIsNewFile = 1 | |
552 | if self.fp != None: self.fp.close() |
|
552 | if self.fp != None: self.fp.close() | |
553 | self.fp = open(fullfilename, 'rb') |
|
553 | self.fp = open(fullfilename, 'rb') | |
554 | self.flagNoMoreFiles = 0 |
|
554 | self.flagNoMoreFiles = 0 | |
555 | print 'Setting the file: %s' % fullfilename |
|
555 | print 'Setting the file: %s' % fullfilename | |
556 | else: |
|
556 | else: | |
557 | self.fileSize = 0 |
|
557 | self.fileSize = 0 | |
558 | self.filename = None |
|
558 | self.filename = None | |
559 | self.flagIsNewFile = 0 |
|
559 | self.flagIsNewFile = 0 | |
560 | self.fp = None |
|
560 | self.fp = None | |
561 | self.flagNoMoreFiles = 1 |
|
561 | self.flagNoMoreFiles = 1 | |
562 | print 'No more Files' |
|
562 | print 'No more Files' | |
563 |
|
563 | |||
564 | return fileOk_flag |
|
564 | return fileOk_flag | |
565 |
|
565 | |||
566 |
|
566 | |||
567 | def setNextFile(self): |
|
567 | def setNextFile(self): | |
568 | if self.fp != None: |
|
568 | if self.fp != None: | |
569 | self.fp.close() |
|
569 | self.fp.close() | |
570 |
|
570 | |||
571 | if self.online: |
|
571 | if self.online: | |
572 | newFile = self.__setNextFileOnline() |
|
572 | newFile = self.__setNextFileOnline() | |
573 | else: |
|
573 | else: | |
574 | newFile = self.__setNextFileOffline() |
|
574 | newFile = self.__setNextFileOffline() | |
575 |
|
575 | |||
576 | if not(newFile): |
|
576 | if not(newFile): | |
577 | return 0 |
|
577 | return 0 | |
578 |
|
578 | |||
579 | self.__readFirstHeader() |
|
579 | self.__readFirstHeader() | |
580 | self.nReadBlocks = 0 |
|
580 | self.nReadBlocks = 0 | |
581 | return 1 |
|
581 | return 1 | |
582 |
|
582 | |||
583 | def __waitNewBlock(self): |
|
583 | def __waitNewBlock(self): | |
584 | """ |
|
584 | """ | |
585 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
585 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
586 |
|
586 | |||
587 | Si el modo de lectura es OffLine siempre retorn 0 |
|
587 | Si el modo de lectura es OffLine siempre retorn 0 | |
588 | """ |
|
588 | """ | |
589 | if not self.online: |
|
589 | if not self.online: | |
590 | return 0 |
|
590 | return 0 | |
591 |
|
591 | |||
592 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
592 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |
593 | return 0 |
|
593 | return 0 | |
594 |
|
594 | |||
595 | currentPointer = self.fp.tell() |
|
595 | currentPointer = self.fp.tell() | |
596 |
|
596 | |||
597 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
597 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
598 |
|
598 | |||
599 | for nTries in range( self.nTries ): |
|
599 | for nTries in range( self.nTries ): | |
600 |
|
600 | |||
601 | self.fp.close() |
|
601 | self.fp.close() | |
602 | self.fp = open( self.filename, 'rb' ) |
|
602 | self.fp = open( self.filename, 'rb' ) | |
603 | self.fp.seek( currentPointer ) |
|
603 | self.fp.seek( currentPointer ) | |
604 |
|
604 | |||
605 | self.fileSize = os.path.getsize( self.filename ) |
|
605 | self.fileSize = os.path.getsize( self.filename ) | |
606 | currentSize = self.fileSize - currentPointer |
|
606 | currentSize = self.fileSize - currentPointer | |
607 |
|
607 | |||
608 | if ( currentSize >= neededSize ): |
|
608 | if ( currentSize >= neededSize ): | |
609 | self.__rdBasicHeader() |
|
609 | self.__rdBasicHeader() | |
610 | return 1 |
|
610 | return 1 | |
611 |
|
611 | |||
612 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
612 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
613 | time.sleep( self.delay ) |
|
613 | time.sleep( self.delay ) | |
614 |
|
614 | |||
615 |
|
615 | |||
616 | return 0 |
|
616 | return 0 | |
617 |
|
617 | |||
618 | def __setNewBlock(self): |
|
618 | def __setNewBlock(self): | |
619 |
|
619 | |||
620 | if self.fp == None: |
|
620 | if self.fp == None: | |
621 | return 0 |
|
621 | return 0 | |
622 |
|
622 | |||
623 | if self.flagIsNewFile: |
|
623 | if self.flagIsNewFile: | |
624 | return 1 |
|
624 | return 1 | |
625 |
|
625 | |||
626 | self.lastUTTime = self.basicHeaderObj.utc |
|
626 | self.lastUTTime = self.basicHeaderObj.utc | |
627 | currentSize = self.fileSize - self.fp.tell() |
|
627 | currentSize = self.fileSize - self.fp.tell() | |
628 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
628 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
629 |
|
629 | |||
630 | if (currentSize >= neededSize): |
|
630 | if (currentSize >= neededSize): | |
631 | self.__rdBasicHeader() |
|
631 | self.__rdBasicHeader() | |
632 | return 1 |
|
632 | return 1 | |
633 |
|
633 | |||
634 | if self.__waitNewBlock(): |
|
634 | if self.__waitNewBlock(): | |
635 | return 1 |
|
635 | return 1 | |
636 |
|
636 | |||
637 | if not(self.setNextFile()): |
|
637 | if not(self.setNextFile()): | |
638 | return 0 |
|
638 | return 0 | |
639 |
|
639 | |||
640 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
640 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
641 |
|
641 | |||
642 | self.flagTimeBlock = 0 |
|
642 | self.flagTimeBlock = 0 | |
643 |
|
643 | |||
644 | if deltaTime > self.maxTimeStep: |
|
644 | if deltaTime > self.maxTimeStep: | |
645 | self.flagTimeBlock = 1 |
|
645 | self.flagTimeBlock = 1 | |
646 |
|
646 | |||
647 | return 1 |
|
647 | return 1 | |
648 |
|
648 | |||
649 |
|
649 | |||
650 | def readNextBlock(self): |
|
650 | def readNextBlock(self): | |
651 | if not(self.__setNewBlock()): |
|
651 | if not(self.__setNewBlock()): | |
652 | return 0 |
|
652 | return 0 | |
653 |
|
653 | |||
654 | if not(self.readBlock()): |
|
654 | if not(self.readBlock()): | |
655 | return 0 |
|
655 | return 0 | |
656 |
|
656 | |||
657 | return 1 |
|
657 | return 1 | |
658 |
|
658 | |||
659 | def __rdProcessingHeader(self, fp=None): |
|
659 | def __rdProcessingHeader(self, fp=None): | |
660 | if fp == None: |
|
660 | if fp == None: | |
661 | fp = self.fp |
|
661 | fp = self.fp | |
662 |
|
662 | |||
663 | self.processingHeaderObj.read(fp) |
|
663 | self.processingHeaderObj.read(fp) | |
664 |
|
664 | |||
665 | def __rdRadarControllerHeader(self, fp=None): |
|
665 | def __rdRadarControllerHeader(self, fp=None): | |
666 | if fp == None: |
|
666 | if fp == None: | |
667 | fp = self.fp |
|
667 | fp = self.fp | |
668 |
|
668 | |||
669 | self.radarControllerHeaderObj.read(fp) |
|
669 | self.radarControllerHeaderObj.read(fp) | |
670 |
|
670 | |||
671 | def __rdSystemHeader(self, fp=None): |
|
671 | def __rdSystemHeader(self, fp=None): | |
672 | if fp == None: |
|
672 | if fp == None: | |
673 | fp = self.fp |
|
673 | fp = self.fp | |
674 |
|
674 | |||
675 | self.systemHeaderObj.read(fp) |
|
675 | self.systemHeaderObj.read(fp) | |
676 |
|
676 | |||
677 | def __rdBasicHeader(self, fp=None): |
|
677 | def __rdBasicHeader(self, fp=None): | |
678 | if fp == None: |
|
678 | if fp == None: | |
679 | fp = self.fp |
|
679 | fp = self.fp | |
680 |
|
680 | |||
681 | self.basicHeaderObj.read(fp) |
|
681 | self.basicHeaderObj.read(fp) | |
682 |
|
682 | |||
683 |
|
683 | |||
684 | def __readFirstHeader(self): |
|
684 | def __readFirstHeader(self): | |
685 | self.__rdBasicHeader() |
|
685 | self.__rdBasicHeader() | |
686 | self.__rdSystemHeader() |
|
686 | self.__rdSystemHeader() | |
687 | self.__rdRadarControllerHeader() |
|
687 | self.__rdRadarControllerHeader() | |
688 | self.__rdProcessingHeader() |
|
688 | self.__rdProcessingHeader() | |
689 |
|
689 | |||
690 | self.firstHeaderSize = self.basicHeaderObj.size |
|
690 | self.firstHeaderSize = self.basicHeaderObj.size | |
691 |
|
691 | |||
692 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
692 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
693 | if datatype == 0: |
|
693 | if datatype == 0: | |
694 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
694 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
695 | elif datatype == 1: |
|
695 | elif datatype == 1: | |
696 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
696 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
697 | elif datatype == 2: |
|
697 | elif datatype == 2: | |
698 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
698 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
699 | elif datatype == 3: |
|
699 | elif datatype == 3: | |
700 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
700 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
701 | elif datatype == 4: |
|
701 | elif datatype == 4: | |
702 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
702 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
703 | elif datatype == 5: |
|
703 | elif datatype == 5: | |
704 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
704 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
705 | else: |
|
705 | else: | |
706 | raise ValueError, 'Data type was not defined' |
|
706 | raise ValueError, 'Data type was not defined' | |
707 |
|
707 | |||
708 | self.dtype = datatype_str |
|
708 | self.dtype = datatype_str | |
709 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
709 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
710 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
710 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
711 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
711 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
712 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
712 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
713 | self.getBlockDimension() |
|
713 | self.getBlockDimension() | |
714 |
|
714 | |||
715 |
|
715 | |||
716 | def __verifyFile(self, filename, msgFlag=True): |
|
716 | def __verifyFile(self, filename, msgFlag=True): | |
717 | msg = None |
|
717 | msg = None | |
718 | try: |
|
718 | try: | |
719 | fp = open(filename, 'rb') |
|
719 | fp = open(filename, 'rb') | |
720 | currentPosition = fp.tell() |
|
720 | currentPosition = fp.tell() | |
721 | except: |
|
721 | except: | |
722 | if msgFlag: |
|
722 | if msgFlag: | |
723 | print "The file %s can't be opened" % (filename) |
|
723 | print "The file %s can't be opened" % (filename) | |
724 | return False |
|
724 | return False | |
725 |
|
725 | |||
726 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
726 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
727 |
|
727 | |||
728 | if neededSize == 0: |
|
728 | if neededSize == 0: | |
729 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
729 | basicHeaderObj = BasicHeader(LOCALTIME) | |
730 | systemHeaderObj = SystemHeader() |
|
730 | systemHeaderObj = SystemHeader() | |
731 | radarControllerHeaderObj = RadarControllerHeader() |
|
731 | radarControllerHeaderObj = RadarControllerHeader() | |
732 | processingHeaderObj = ProcessingHeader() |
|
732 | processingHeaderObj = ProcessingHeader() | |
733 |
|
733 | |||
734 | try: |
|
734 | try: | |
735 | if not( basicHeaderObj.read(fp) ): raise IOError |
|
735 | if not( basicHeaderObj.read(fp) ): raise IOError | |
736 | if not( systemHeaderObj.read(fp) ): raise IOError |
|
736 | if not( systemHeaderObj.read(fp) ): raise IOError | |
737 | if not( radarControllerHeaderObj.read(fp) ): raise IOError |
|
737 | if not( radarControllerHeaderObj.read(fp) ): raise IOError | |
738 | if not( processingHeaderObj.read(fp) ): raise IOError |
|
738 | if not( processingHeaderObj.read(fp) ): raise IOError | |
739 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
739 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
740 |
|
740 | |||
741 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
741 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
742 |
|
742 | |||
743 | except: |
|
743 | except: | |
744 | if msgFlag: |
|
744 | if msgFlag: | |
745 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
745 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
746 |
|
746 | |||
747 | fp.close() |
|
747 | fp.close() | |
748 | return False |
|
748 | return False | |
749 | else: |
|
749 | else: | |
750 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
750 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
751 |
|
751 | |||
752 | fp.close() |
|
752 | fp.close() | |
753 | fileSize = os.path.getsize(filename) |
|
753 | fileSize = os.path.getsize(filename) | |
754 | currentSize = fileSize - currentPosition |
|
754 | currentSize = fileSize - currentPosition | |
755 | if currentSize < neededSize: |
|
755 | if currentSize < neededSize: | |
756 | if msgFlag and (msg != None): |
|
756 | if msgFlag and (msg != None): | |
757 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
757 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
758 | return False |
|
758 | return False | |
759 |
|
759 | |||
760 | return True |
|
760 | return True | |
761 |
|
761 | |||
762 | def setup(self, |
|
762 | def setup(self, | |
763 | path=None, |
|
763 | path=None, | |
764 | startDate=None, |
|
764 | startDate=None, | |
765 | endDate=None, |
|
765 | endDate=None, | |
766 | startTime=datetime.time(0,0,0), |
|
766 | startTime=datetime.time(0,0,0), | |
767 | endTime=datetime.time(23,59,59), |
|
767 | endTime=datetime.time(23,59,59), | |
768 | set=0, |
|
768 | set=0, | |
769 | expLabel = "", |
|
769 | expLabel = "", | |
770 | ext = None, |
|
770 | ext = None, | |
771 | online = False, |
|
771 | online = False, | |
772 | delay = 60, |
|
772 | delay = 60, | |
773 | walk = True): |
|
773 | walk = True): | |
774 |
|
774 | |||
775 | if path == None: |
|
775 | if path == None: | |
776 | raise ValueError, "The path is not valid" |
|
776 | raise ValueError, "The path is not valid" | |
777 |
|
777 | |||
778 | if ext == None: |
|
778 | if ext == None: | |
779 | ext = self.ext |
|
779 | ext = self.ext | |
780 |
|
780 | |||
781 | if online: |
|
781 | if online: | |
782 | print "Searching files in online mode..." |
|
782 | print "Searching files in online mode..." | |
783 |
|
783 | |||
784 | for nTries in range( self.nTries ): |
|
784 | for nTries in range( self.nTries ): | |
785 | fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk) |
|
785 | fullpath, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk) | |
786 |
|
786 | |||
787 | if fullpath: |
|
787 | if fullpath: | |
788 | break |
|
788 | break | |
789 |
|
789 | |||
790 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
790 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
791 | time.sleep( self.delay ) |
|
791 | time.sleep( self.delay ) | |
792 |
|
792 | |||
793 | if not(fullpath): |
|
793 | if not(fullpath): | |
794 | print "There 'isn't valied files in %s" % path |
|
794 | print "There 'isn't valied files in %s" % path | |
795 | return None |
|
795 | return None | |
796 |
|
796 | |||
797 | self.year = year |
|
797 | self.year = year | |
798 | self.doy = doy |
|
798 | self.doy = doy | |
799 | self.set = set - 1 |
|
799 | self.set = set - 1 | |
800 | self.path = path |
|
800 | self.path = path | |
801 |
|
801 | |||
802 | else: |
|
802 | else: | |
803 | print "Searching files in offline mode ..." |
|
803 | print "Searching files in offline mode ..." | |
804 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
804 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
805 | startTime=startTime, endTime=endTime, |
|
805 | startTime=startTime, endTime=endTime, | |
806 | set=set, expLabel=expLabel, ext=ext, |
|
806 | set=set, expLabel=expLabel, ext=ext, | |
807 | walk=walk) |
|
807 | walk=walk) | |
808 |
|
808 | |||
809 | if not(pathList): |
|
809 | if not(pathList): | |
810 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
810 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
811 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
811 | datetime.datetime.combine(startDate,startTime).ctime(), | |
812 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
812 | datetime.datetime.combine(endDate,endTime).ctime()) | |
813 |
|
813 | |||
814 | sys.exit(-1) |
|
814 | sys.exit(-1) | |
815 |
|
815 | |||
816 |
|
816 | |||
817 | self.fileIndex = -1 |
|
817 | self.fileIndex = -1 | |
818 | self.pathList = pathList |
|
818 | self.pathList = pathList | |
819 | self.filenameList = filenameList |
|
819 | self.filenameList = filenameList | |
820 |
|
820 | |||
821 | self.online = online |
|
821 | self.online = online | |
822 | self.delay = delay |
|
822 | self.delay = delay | |
823 | ext = ext.lower() |
|
823 | ext = ext.lower() | |
824 | self.ext = ext |
|
824 | self.ext = ext | |
825 |
|
825 | |||
826 | if not(self.setNextFile()): |
|
826 | if not(self.setNextFile()): | |
827 | if (startDate!=None) and (endDate!=None): |
|
827 | if (startDate!=None) and (endDate!=None): | |
828 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
828 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
829 | elif startDate != None: |
|
829 | elif startDate != None: | |
830 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
830 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
831 | else: |
|
831 | else: | |
832 | print "No files" |
|
832 | print "No files" | |
833 |
|
833 | |||
834 | sys.exit(-1) |
|
834 | sys.exit(-1) | |
835 |
|
835 | |||
836 | # self.updateDataHeader() |
|
836 | # self.updateDataHeader() | |
837 |
|
837 | |||
838 | return self.dataOut |
|
838 | return self.dataOut | |
839 |
|
839 | |||
840 | def getData(): |
|
840 | def getData(): | |
841 |
|
841 | |||
842 | raise ValueError, "This method has not been implemented" |
|
842 | raise ValueError, "This method has not been implemented" | |
843 |
|
843 | |||
844 | def hasNotDataInBuffer(): |
|
844 | def hasNotDataInBuffer(): | |
845 |
|
845 | |||
846 | raise ValueError, "This method has not been implemented" |
|
846 | raise ValueError, "This method has not been implemented" | |
847 |
|
847 | |||
848 | def readBlock(): |
|
848 | def readBlock(): | |
849 |
|
849 | |||
850 | raise ValueError, "This method has not been implemented" |
|
850 | raise ValueError, "This method has not been implemented" | |
851 |
|
851 | |||
852 | def isEndProcess(self): |
|
852 | def isEndProcess(self): | |
853 |
|
853 | |||
854 | return self.flagNoMoreFiles |
|
854 | return self.flagNoMoreFiles | |
855 |
|
855 | |||
856 | def printReadBlocks(self): |
|
856 | def printReadBlocks(self): | |
857 |
|
857 | |||
858 | print "Number of read blocks per file %04d" %self.nReadBlocks |
|
858 | print "Number of read blocks per file %04d" %self.nReadBlocks | |
859 |
|
859 | |||
860 | def printTotalBlocks(self): |
|
860 | def printTotalBlocks(self): | |
861 |
|
861 | |||
862 | print "Number of read blocks %04d" %self.nTotalBlocks |
|
862 | print "Number of read blocks %04d" %self.nTotalBlocks | |
863 |
|
863 | |||
|
864 | def printNumberOfBlock(self): | |||
|
865 | ||||
|
866 | if self.flagIsNewBlock: | |||
|
867 | print "Block No. %04d, Total blocks %04d" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks) | |||
|
868 | ||||
864 | def printInfo(self): |
|
869 | def printInfo(self): | |
865 |
|
870 | |||
866 | print self.basicHeaderObj.printInfo() |
|
871 | print self.basicHeaderObj.printInfo() | |
867 | print self.systemHeaderObj.printInfo() |
|
872 | print self.systemHeaderObj.printInfo() | |
868 | print self.radarControllerHeaderObj.printInfo() |
|
873 | print self.radarControllerHeaderObj.printInfo() | |
869 | print self.processingHeaderObj.printInfo() |
|
874 | print self.processingHeaderObj.printInfo() | |
870 |
|
875 | |||
871 |
|
876 | |||
872 | def run(self, **kwargs): |
|
877 | def run(self, **kwargs): | |
873 |
|
878 | |||
874 | if not(self.isConfig): |
|
879 | if not(self.isConfig): | |
875 |
|
880 | |||
876 | # self.dataOut = dataOut |
|
881 | # self.dataOut = dataOut | |
877 | self.setup(**kwargs) |
|
882 | self.setup(**kwargs) | |
878 | self.isConfig = True |
|
883 | self.isConfig = True | |
879 |
|
884 | |||
880 | self.getData() |
|
885 | self.getData() | |
881 |
|
886 | |||
882 | class JRODataWriter(JRODataIO, Operation): |
|
887 | class JRODataWriter(JRODataIO, Operation): | |
883 |
|
888 | |||
884 | """ |
|
889 | """ | |
885 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
890 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
886 | de los datos siempre se realiza por bloques. |
|
891 | de los datos siempre se realiza por bloques. | |
887 | """ |
|
892 | """ | |
888 |
|
893 | |||
889 | blockIndex = 0 |
|
894 | blockIndex = 0 | |
890 |
|
895 | |||
891 | path = None |
|
896 | path = None | |
892 |
|
897 | |||
893 | setFile = None |
|
898 | setFile = None | |
894 |
|
899 | |||
895 | profilesPerBlock = None |
|
900 | profilesPerBlock = None | |
896 |
|
901 | |||
897 | blocksPerFile = None |
|
902 | blocksPerFile = None | |
898 |
|
903 | |||
899 | nWriteBlocks = 0 |
|
904 | nWriteBlocks = 0 | |
900 |
|
905 | |||
901 | def __init__(self, dataOut=None): |
|
906 | def __init__(self, dataOut=None): | |
902 | raise ValueError, "Not implemented" |
|
907 | raise ValueError, "Not implemented" | |
903 |
|
908 | |||
904 |
|
909 | |||
905 | def hasAllDataInBuffer(self): |
|
910 | def hasAllDataInBuffer(self): | |
906 | raise ValueError, "Not implemented" |
|
911 | raise ValueError, "Not implemented" | |
907 |
|
912 | |||
908 |
|
913 | |||
909 | def setBlockDimension(self): |
|
914 | def setBlockDimension(self): | |
910 | raise ValueError, "Not implemented" |
|
915 | raise ValueError, "Not implemented" | |
911 |
|
916 | |||
912 |
|
917 | |||
913 | def writeBlock(self): |
|
918 | def writeBlock(self): | |
914 | raise ValueError, "No implemented" |
|
919 | raise ValueError, "No implemented" | |
915 |
|
920 | |||
916 |
|
921 | |||
917 | def putData(self): |
|
922 | def putData(self): | |
918 | raise ValueError, "No implemented" |
|
923 | raise ValueError, "No implemented" | |
919 |
|
924 | |||
920 | def getDataHeader(self): |
|
925 | def getDataHeader(self): | |
921 | """ |
|
926 | """ | |
922 | Obtiene una copia del First Header |
|
927 | Obtiene una copia del First Header | |
923 |
|
928 | |||
924 | Affected: |
|
929 | Affected: | |
925 |
|
930 | |||
926 | self.basicHeaderObj |
|
931 | self.basicHeaderObj | |
927 | self.systemHeaderObj |
|
932 | self.systemHeaderObj | |
928 | self.radarControllerHeaderObj |
|
933 | self.radarControllerHeaderObj | |
929 | self.processingHeaderObj self. |
|
934 | self.processingHeaderObj self. | |
930 |
|
935 | |||
931 | Return: |
|
936 | Return: | |
932 | None |
|
937 | None | |
933 | """ |
|
938 | """ | |
934 |
|
939 | |||
935 | raise ValueError, "No implemented" |
|
940 | raise ValueError, "No implemented" | |
936 |
|
941 | |||
937 | def getBasicHeader(self): |
|
942 | def getBasicHeader(self): | |
938 |
|
943 | |||
939 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
944 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
940 | self.basicHeaderObj.version = self.versionFile |
|
945 | self.basicHeaderObj.version = self.versionFile | |
941 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
946 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |
942 |
|
947 | |||
943 | utc = numpy.floor(self.dataOut.utctime) |
|
948 | utc = numpy.floor(self.dataOut.utctime) | |
944 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
949 | milisecond = (self.dataOut.utctime - utc)* 1000.0 | |
945 |
|
950 | |||
946 | self.basicHeaderObj.utc = utc |
|
951 | self.basicHeaderObj.utc = utc | |
947 | self.basicHeaderObj.miliSecond = milisecond |
|
952 | self.basicHeaderObj.miliSecond = milisecond | |
948 | self.basicHeaderObj.timeZone = 0 |
|
953 | self.basicHeaderObj.timeZone = 0 | |
949 | self.basicHeaderObj.dstFlag = 0 |
|
954 | self.basicHeaderObj.dstFlag = 0 | |
950 | self.basicHeaderObj.errorCount = 0 |
|
955 | self.basicHeaderObj.errorCount = 0 | |
951 |
|
956 | |||
952 | def __writeFirstHeader(self): |
|
957 | def __writeFirstHeader(self): | |
953 | """ |
|
958 | """ | |
954 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
959 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
955 |
|
960 | |||
956 | Affected: |
|
961 | Affected: | |
957 | __dataType |
|
962 | __dataType | |
958 |
|
963 | |||
959 | Return: |
|
964 | Return: | |
960 | None |
|
965 | None | |
961 | """ |
|
966 | """ | |
962 |
|
967 | |||
963 | # CALCULAR PARAMETROS |
|
968 | # CALCULAR PARAMETROS | |
964 |
|
969 | |||
965 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
970 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
966 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
971 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
967 |
|
972 | |||
968 | self.basicHeaderObj.write(self.fp) |
|
973 | self.basicHeaderObj.write(self.fp) | |
969 | self.systemHeaderObj.write(self.fp) |
|
974 | self.systemHeaderObj.write(self.fp) | |
970 | self.radarControllerHeaderObj.write(self.fp) |
|
975 | self.radarControllerHeaderObj.write(self.fp) | |
971 | self.processingHeaderObj.write(self.fp) |
|
976 | self.processingHeaderObj.write(self.fp) | |
972 |
|
977 | |||
973 | self.dtype = self.dataOut.dtype |
|
978 | self.dtype = self.dataOut.dtype | |
974 |
|
979 | |||
975 | def __setNewBlock(self): |
|
980 | def __setNewBlock(self): | |
976 | """ |
|
981 | """ | |
977 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
982 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
978 |
|
983 | |||
979 | Return: |
|
984 | Return: | |
980 | 0 : si no pudo escribir nada |
|
985 | 0 : si no pudo escribir nada | |
981 | 1 : Si escribio el Basic el First Header |
|
986 | 1 : Si escribio el Basic el First Header | |
982 | """ |
|
987 | """ | |
983 | if self.fp == None: |
|
988 | if self.fp == None: | |
984 | self.setNextFile() |
|
989 | self.setNextFile() | |
985 |
|
990 | |||
986 | if self.flagIsNewFile: |
|
991 | if self.flagIsNewFile: | |
987 | return 1 |
|
992 | return 1 | |
988 |
|
993 | |||
989 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
994 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
990 | self.basicHeaderObj.write(self.fp) |
|
995 | self.basicHeaderObj.write(self.fp) | |
991 | return 1 |
|
996 | return 1 | |
992 |
|
997 | |||
993 | if not( self.setNextFile() ): |
|
998 | if not( self.setNextFile() ): | |
994 | return 0 |
|
999 | return 0 | |
995 |
|
1000 | |||
996 | return 1 |
|
1001 | return 1 | |
997 |
|
1002 | |||
998 |
|
1003 | |||
999 | def writeNextBlock(self): |
|
1004 | def writeNextBlock(self): | |
1000 | """ |
|
1005 | """ | |
1001 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1006 | Selecciona el bloque siguiente de datos y los escribe en un file | |
1002 |
|
1007 | |||
1003 | Return: |
|
1008 | Return: | |
1004 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1009 | 0 : Si no hizo pudo escribir el bloque de datos | |
1005 | 1 : Si no pudo escribir el bloque de datos |
|
1010 | 1 : Si no pudo escribir el bloque de datos | |
1006 | """ |
|
1011 | """ | |
1007 | if not( self.__setNewBlock() ): |
|
1012 | if not( self.__setNewBlock() ): | |
1008 | return 0 |
|
1013 | return 0 | |
1009 |
|
1014 | |||
1010 | self.writeBlock() |
|
1015 | self.writeBlock() | |
1011 |
|
1016 | |||
1012 | return 1 |
|
1017 | return 1 | |
1013 |
|
1018 | |||
1014 | def setNextFile(self): |
|
1019 | def setNextFile(self): | |
1015 | """ |
|
1020 | """ | |
1016 | Determina el siguiente file que sera escrito |
|
1021 | Determina el siguiente file que sera escrito | |
1017 |
|
1022 | |||
1018 | Affected: |
|
1023 | Affected: | |
1019 | self.filename |
|
1024 | self.filename | |
1020 | self.subfolder |
|
1025 | self.subfolder | |
1021 | self.fp |
|
1026 | self.fp | |
1022 | self.setFile |
|
1027 | self.setFile | |
1023 | self.flagIsNewFile |
|
1028 | self.flagIsNewFile | |
1024 |
|
1029 | |||
1025 | Return: |
|
1030 | Return: | |
1026 | 0 : Si el archivo no puede ser escrito |
|
1031 | 0 : Si el archivo no puede ser escrito | |
1027 | 1 : Si el archivo esta listo para ser escrito |
|
1032 | 1 : Si el archivo esta listo para ser escrito | |
1028 | """ |
|
1033 | """ | |
1029 | ext = self.ext |
|
1034 | ext = self.ext | |
1030 | path = self.path |
|
1035 | path = self.path | |
1031 |
|
1036 | |||
1032 | if self.fp != None: |
|
1037 | if self.fp != None: | |
1033 | self.fp.close() |
|
1038 | self.fp.close() | |
1034 |
|
1039 | |||
1035 | timeTuple = time.localtime( self.dataOut.utctime) |
|
1040 | timeTuple = time.localtime( self.dataOut.utctime) | |
1036 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1041 | subfolder = 'D%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
1037 |
|
1042 | |||
1038 | fullpath = os.path.join( path, subfolder ) |
|
1043 | fullpath = os.path.join( path, subfolder ) | |
1039 | if not( os.path.exists(fullpath) ): |
|
1044 | if not( os.path.exists(fullpath) ): | |
1040 | os.mkdir(fullpath) |
|
1045 | os.mkdir(fullpath) | |
1041 | self.setFile = -1 #inicializo mi contador de seteo |
|
1046 | self.setFile = -1 #inicializo mi contador de seteo | |
1042 | else: |
|
1047 | else: | |
1043 | filesList = os.listdir( fullpath ) |
|
1048 | filesList = os.listdir( fullpath ) | |
1044 | if len( filesList ) > 0: |
|
1049 | if len( filesList ) > 0: | |
1045 | filesList = sorted( filesList, key=str.lower ) |
|
1050 | filesList = sorted( filesList, key=str.lower ) | |
1046 | filen = filesList[-1] |
|
1051 | filen = filesList[-1] | |
1047 | # el filename debera tener el siguiente formato |
|
1052 | # el filename debera tener el siguiente formato | |
1048 | # 0 1234 567 89A BCDE (hex) |
|
1053 | # 0 1234 567 89A BCDE (hex) | |
1049 | # x YYYY DDD SSS .ext |
|
1054 | # x YYYY DDD SSS .ext | |
1050 | if isNumber( filen[8:11] ): |
|
1055 | if isNumber( filen[8:11] ): | |
1051 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
1056 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
1052 | else: |
|
1057 | else: | |
1053 | self.setFile = -1 |
|
1058 | self.setFile = -1 | |
1054 | else: |
|
1059 | else: | |
1055 | self.setFile = -1 #inicializo mi contador de seteo |
|
1060 | self.setFile = -1 #inicializo mi contador de seteo | |
1056 |
|
1061 | |||
1057 | setFile = self.setFile |
|
1062 | setFile = self.setFile | |
1058 | setFile += 1 |
|
1063 | setFile += 1 | |
1059 |
|
1064 | |||
1060 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
1065 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
1061 | timeTuple.tm_year, |
|
1066 | timeTuple.tm_year, | |
1062 | timeTuple.tm_yday, |
|
1067 | timeTuple.tm_yday, | |
1063 | setFile, |
|
1068 | setFile, | |
1064 | ext ) |
|
1069 | ext ) | |
1065 |
|
1070 | |||
1066 | filename = os.path.join( path, subfolder, file ) |
|
1071 | filename = os.path.join( path, subfolder, file ) | |
1067 |
|
1072 | |||
1068 | fp = open( filename,'wb' ) |
|
1073 | fp = open( filename,'wb' ) | |
1069 |
|
1074 | |||
1070 | self.blockIndex = 0 |
|
1075 | self.blockIndex = 0 | |
1071 |
|
1076 | |||
1072 | #guardando atributos |
|
1077 | #guardando atributos | |
1073 | self.filename = filename |
|
1078 | self.filename = filename | |
1074 | self.subfolder = subfolder |
|
1079 | self.subfolder = subfolder | |
1075 | self.fp = fp |
|
1080 | self.fp = fp | |
1076 | self.setFile = setFile |
|
1081 | self.setFile = setFile | |
1077 | self.flagIsNewFile = 1 |
|
1082 | self.flagIsNewFile = 1 | |
1078 |
|
1083 | |||
1079 | self.getDataHeader() |
|
1084 | self.getDataHeader() | |
1080 |
|
1085 | |||
1081 | print 'Writing the file: %s'%self.filename |
|
1086 | print 'Writing the file: %s'%self.filename | |
1082 |
|
1087 | |||
1083 | self.__writeFirstHeader() |
|
1088 | self.__writeFirstHeader() | |
1084 |
|
1089 | |||
1085 | return 1 |
|
1090 | return 1 | |
1086 |
|
1091 | |||
1087 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): |
|
1092 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): | |
1088 | """ |
|
1093 | """ | |
1089 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1094 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1090 |
|
1095 | |||
1091 | Inputs: |
|
1096 | Inputs: | |
1092 | path : el path destino en el cual se escribiran los files a crear |
|
1097 | path : el path destino en el cual se escribiran los files a crear | |
1093 | format : formato en el cual sera salvado un file |
|
1098 | format : formato en el cual sera salvado un file | |
1094 | set : el setebo del file |
|
1099 | set : el setebo del file | |
1095 |
|
1100 | |||
1096 | Return: |
|
1101 | Return: | |
1097 | 0 : Si no realizo un buen seteo |
|
1102 | 0 : Si no realizo un buen seteo | |
1098 | 1 : Si realizo un buen seteo |
|
1103 | 1 : Si realizo un buen seteo | |
1099 | """ |
|
1104 | """ | |
1100 |
|
1105 | |||
1101 | if ext == None: |
|
1106 | if ext == None: | |
1102 | ext = self.ext |
|
1107 | ext = self.ext | |
1103 |
|
1108 | |||
1104 | ext = ext.lower() |
|
1109 | ext = ext.lower() | |
1105 |
|
1110 | |||
1106 | self.ext = ext |
|
1111 | self.ext = ext | |
1107 |
|
1112 | |||
1108 | self.path = path |
|
1113 | self.path = path | |
1109 |
|
1114 | |||
1110 | self.setFile = set - 1 |
|
1115 | self.setFile = set - 1 | |
1111 |
|
1116 | |||
1112 | self.blocksPerFile = blocksPerFile |
|
1117 | self.blocksPerFile = blocksPerFile | |
1113 |
|
1118 | |||
1114 | self.profilesPerBlock = profilesPerBlock |
|
1119 | self.profilesPerBlock = profilesPerBlock | |
1115 |
|
1120 | |||
1116 | self.dataOut = dataOut |
|
1121 | self.dataOut = dataOut | |
1117 |
|
1122 | |||
1118 | if not(self.setNextFile()): |
|
1123 | if not(self.setNextFile()): | |
1119 | print "There isn't a next file" |
|
1124 | print "There isn't a next file" | |
1120 | return 0 |
|
1125 | return 0 | |
1121 |
|
1126 | |||
1122 | self.setBlockDimension() |
|
1127 | self.setBlockDimension() | |
1123 |
|
1128 | |||
1124 | return 1 |
|
1129 | return 1 | |
1125 |
|
1130 | |||
1126 | def run(self, dataOut, **kwargs): |
|
1131 | def run(self, dataOut, **kwargs): | |
1127 |
|
1132 | |||
1128 | if not(self.isConfig): |
|
1133 | if not(self.isConfig): | |
1129 |
|
1134 | |||
1130 | self.setup(dataOut, **kwargs) |
|
1135 | self.setup(dataOut, **kwargs) | |
1131 | self.isConfig = True |
|
1136 | self.isConfig = True | |
1132 |
|
1137 | |||
1133 | self.putData() |
|
1138 | self.putData() | |
1134 |
|
1139 | |||
1135 | class VoltageReader(JRODataReader): |
|
1140 | class VoltageReader(JRODataReader): | |
1136 | """ |
|
1141 | """ | |
1137 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
1142 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
1138 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
1143 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
1139 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
1144 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
1140 |
|
1145 | |||
1141 | perfiles * alturas * canales |
|
1146 | perfiles * alturas * canales | |
1142 |
|
1147 | |||
1143 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1148 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1144 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
1149 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
1145 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
1150 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
1146 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1151 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1147 |
|
1152 | |||
1148 | Example: |
|
1153 | Example: | |
1149 |
|
1154 | |||
1150 | dpath = "/home/myuser/data" |
|
1155 | dpath = "/home/myuser/data" | |
1151 |
|
1156 | |||
1152 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1157 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1153 |
|
1158 | |||
1154 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1159 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1155 |
|
1160 | |||
1156 | readerObj = VoltageReader() |
|
1161 | readerObj = VoltageReader() | |
1157 |
|
1162 | |||
1158 | readerObj.setup(dpath, startTime, endTime) |
|
1163 | readerObj.setup(dpath, startTime, endTime) | |
1159 |
|
1164 | |||
1160 | while(True): |
|
1165 | while(True): | |
1161 |
|
1166 | |||
1162 | #to get one profile |
|
1167 | #to get one profile | |
1163 | profile = readerObj.getData() |
|
1168 | profile = readerObj.getData() | |
1164 |
|
1169 | |||
1165 | #print the profile |
|
1170 | #print the profile | |
1166 | print profile |
|
1171 | print profile | |
1167 |
|
1172 | |||
1168 | #If you want to see all datablock |
|
1173 | #If you want to see all datablock | |
1169 | print readerObj.datablock |
|
1174 | print readerObj.datablock | |
1170 |
|
1175 | |||
1171 | if readerObj.flagNoMoreFiles: |
|
1176 | if readerObj.flagNoMoreFiles: | |
1172 | break |
|
1177 | break | |
1173 |
|
1178 | |||
1174 | """ |
|
1179 | """ | |
1175 |
|
1180 | |||
1176 | ext = ".r" |
|
1181 | ext = ".r" | |
1177 |
|
1182 | |||
1178 | optchar = "D" |
|
1183 | optchar = "D" | |
1179 | dataOut = None |
|
1184 | dataOut = None | |
1180 |
|
1185 | |||
1181 |
|
1186 | |||
1182 | def __init__(self): |
|
1187 | def __init__(self): | |
1183 | """ |
|
1188 | """ | |
1184 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
1189 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
1185 |
|
1190 | |||
1186 | Input: |
|
1191 | Input: | |
1187 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
1192 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
1188 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1193 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1189 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1194 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1190 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1195 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1191 | bloque de datos. |
|
1196 | bloque de datos. | |
1192 | Si este parametro no es pasado se creara uno internamente. |
|
1197 | Si este parametro no es pasado se creara uno internamente. | |
1193 |
|
1198 | |||
1194 | Variables afectadas: |
|
1199 | Variables afectadas: | |
1195 | self.dataOut |
|
1200 | self.dataOut | |
1196 |
|
1201 | |||
1197 | Return: |
|
1202 | Return: | |
1198 | None |
|
1203 | None | |
1199 | """ |
|
1204 | """ | |
1200 |
|
1205 | |||
1201 | self.isConfig = False |
|
1206 | self.isConfig = False | |
1202 |
|
1207 | |||
1203 | self.datablock = None |
|
1208 | self.datablock = None | |
1204 |
|
1209 | |||
1205 | self.utc = 0 |
|
1210 | self.utc = 0 | |
1206 |
|
1211 | |||
1207 | self.ext = ".r" |
|
1212 | self.ext = ".r" | |
1208 |
|
1213 | |||
1209 | self.optchar = "D" |
|
1214 | self.optchar = "D" | |
1210 |
|
1215 | |||
1211 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1216 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1212 |
|
1217 | |||
1213 | self.systemHeaderObj = SystemHeader() |
|
1218 | self.systemHeaderObj = SystemHeader() | |
1214 |
|
1219 | |||
1215 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1220 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1216 |
|
1221 | |||
1217 | self.processingHeaderObj = ProcessingHeader() |
|
1222 | self.processingHeaderObj = ProcessingHeader() | |
1218 |
|
1223 | |||
1219 | self.online = 0 |
|
1224 | self.online = 0 | |
1220 |
|
1225 | |||
1221 | self.fp = None |
|
1226 | self.fp = None | |
1222 |
|
1227 | |||
1223 | self.idFile = None |
|
1228 | self.idFile = None | |
1224 |
|
1229 | |||
1225 | self.dtype = None |
|
1230 | self.dtype = None | |
1226 |
|
1231 | |||
1227 | self.fileSizeByHeader = None |
|
1232 | self.fileSizeByHeader = None | |
1228 |
|
1233 | |||
1229 | self.filenameList = [] |
|
1234 | self.filenameList = [] | |
1230 |
|
1235 | |||
1231 | self.filename = None |
|
1236 | self.filename = None | |
1232 |
|
1237 | |||
1233 | self.fileSize = None |
|
1238 | self.fileSize = None | |
1234 |
|
1239 | |||
1235 | self.firstHeaderSize = 0 |
|
1240 | self.firstHeaderSize = 0 | |
1236 |
|
1241 | |||
1237 | self.basicHeaderSize = 24 |
|
1242 | self.basicHeaderSize = 24 | |
1238 |
|
1243 | |||
1239 | self.pathList = [] |
|
1244 | self.pathList = [] | |
1240 |
|
1245 | |||
1241 | self.filenameList = [] |
|
1246 | self.filenameList = [] | |
1242 |
|
1247 | |||
1243 | self.lastUTTime = 0 |
|
1248 | self.lastUTTime = 0 | |
1244 |
|
1249 | |||
1245 | self.maxTimeStep = 30 |
|
1250 | self.maxTimeStep = 30 | |
1246 |
|
1251 | |||
1247 | self.flagNoMoreFiles = 0 |
|
1252 | self.flagNoMoreFiles = 0 | |
1248 |
|
1253 | |||
1249 | self.set = 0 |
|
1254 | self.set = 0 | |
1250 |
|
1255 | |||
1251 | self.path = None |
|
1256 | self.path = None | |
1252 |
|
1257 | |||
1253 | self.profileIndex = 9999 |
|
1258 | self.profileIndex = 9999 | |
1254 |
|
1259 | |||
1255 | self.delay = 3 #seconds |
|
1260 | self.delay = 3 #seconds | |
1256 |
|
1261 | |||
1257 | self.nTries = 3 #quantity tries |
|
1262 | self.nTries = 3 #quantity tries | |
1258 |
|
1263 | |||
1259 | self.nFiles = 3 #number of files for searching |
|
1264 | self.nFiles = 3 #number of files for searching | |
1260 |
|
1265 | |||
1261 | self.nReadBlocks = 0 |
|
1266 | self.nReadBlocks = 0 | |
1262 |
|
1267 | |||
1263 | self.flagIsNewFile = 1 |
|
1268 | self.flagIsNewFile = 1 | |
1264 |
|
1269 | |||
1265 | self.ippSeconds = 0 |
|
1270 | self.ippSeconds = 0 | |
1266 |
|
1271 | |||
1267 | self.flagTimeBlock = 0 |
|
1272 | self.flagTimeBlock = 0 | |
1268 |
|
1273 | |||
1269 | self.flagIsNewBlock = 0 |
|
1274 | self.flagIsNewBlock = 0 | |
1270 |
|
1275 | |||
1271 | self.nTotalBlocks = 0 |
|
1276 | self.nTotalBlocks = 0 | |
1272 |
|
1277 | |||
1273 | self.blocksize = 0 |
|
1278 | self.blocksize = 0 | |
1274 |
|
1279 | |||
1275 | self.dataOut = self.createObjByDefault() |
|
1280 | self.dataOut = self.createObjByDefault() | |
1276 |
|
1281 | |||
1277 | def createObjByDefault(self): |
|
1282 | def createObjByDefault(self): | |
1278 |
|
1283 | |||
1279 | dataObj = Voltage() |
|
1284 | dataObj = Voltage() | |
1280 |
|
1285 | |||
1281 | return dataObj |
|
1286 | return dataObj | |
1282 |
|
1287 | |||
1283 | def __hasNotDataInBuffer(self): |
|
1288 | def __hasNotDataInBuffer(self): | |
1284 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1289 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1285 | return 1 |
|
1290 | return 1 | |
1286 | return 0 |
|
1291 | return 0 | |
1287 |
|
1292 | |||
1288 |
|
1293 | |||
1289 | def getBlockDimension(self): |
|
1294 | def getBlockDimension(self): | |
1290 | """ |
|
1295 | """ | |
1291 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1296 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1292 |
|
1297 | |||
1293 | Affected: |
|
1298 | Affected: | |
1294 | self.blocksize |
|
1299 | self.blocksize | |
1295 |
|
1300 | |||
1296 | Return: |
|
1301 | Return: | |
1297 | None |
|
1302 | None | |
1298 | """ |
|
1303 | """ | |
1299 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
1304 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
1300 | self.blocksize = pts2read |
|
1305 | self.blocksize = pts2read | |
1301 |
|
1306 | |||
1302 |
|
1307 | |||
1303 | def readBlock(self): |
|
1308 | def readBlock(self): | |
1304 | """ |
|
1309 | """ | |
1305 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1310 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
1306 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1311 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1307 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1312 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1308 | es seteado a 0 |
|
1313 | es seteado a 0 | |
1309 |
|
1314 | |||
1310 | Inputs: |
|
1315 | Inputs: | |
1311 | None |
|
1316 | None | |
1312 |
|
1317 | |||
1313 | Return: |
|
1318 | Return: | |
1314 | None |
|
1319 | None | |
1315 |
|
1320 | |||
1316 | Affected: |
|
1321 | Affected: | |
1317 | self.profileIndex |
|
1322 | self.profileIndex | |
1318 | self.datablock |
|
1323 | self.datablock | |
1319 | self.flagIsNewFile |
|
1324 | self.flagIsNewFile | |
1320 | self.flagIsNewBlock |
|
1325 | self.flagIsNewBlock | |
1321 | self.nTotalBlocks |
|
1326 | self.nTotalBlocks | |
1322 |
|
1327 | |||
1323 | Exceptions: |
|
1328 | Exceptions: | |
1324 | Si un bloque leido no es un bloque valido |
|
1329 | Si un bloque leido no es un bloque valido | |
1325 | """ |
|
1330 | """ | |
1326 |
|
1331 | |||
1327 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1332 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
1328 |
|
1333 | |||
1329 | try: |
|
1334 | try: | |
1330 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1335 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
1331 | except: |
|
1336 | except: | |
1332 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
1337 | print "The read block (%3d) has not enough data" %self.nReadBlocks | |
1333 | return 0 |
|
1338 | return 0 | |
1334 |
|
1339 | |||
1335 | junk = numpy.transpose(junk, (2,0,1)) |
|
1340 | junk = numpy.transpose(junk, (2,0,1)) | |
1336 | self.datablock = junk['real'] + junk['imag']*1j |
|
1341 | self.datablock = junk['real'] + junk['imag']*1j | |
1337 |
|
1342 | |||
1338 | self.profileIndex = 0 |
|
1343 | self.profileIndex = 0 | |
1339 |
|
1344 | |||
1340 | self.flagIsNewFile = 0 |
|
1345 | self.flagIsNewFile = 0 | |
1341 | self.flagIsNewBlock = 1 |
|
1346 | self.flagIsNewBlock = 1 | |
1342 |
|
1347 | |||
1343 | self.nTotalBlocks += 1 |
|
1348 | self.nTotalBlocks += 1 | |
1344 | self.nReadBlocks += 1 |
|
1349 | self.nReadBlocks += 1 | |
1345 |
|
1350 | |||
1346 | return 1 |
|
1351 | return 1 | |
1347 |
|
1352 | |||
1348 |
|
1353 | |||
1349 | def getData(self): |
|
1354 | def getData(self): | |
1350 | """ |
|
1355 | """ | |
1351 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
1356 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
1352 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1357 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1353 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1358 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1354 |
|
1359 | |||
1355 | Ademas incrementa el contador del buffer en 1. |
|
1360 | Ademas incrementa el contador del buffer en 1. | |
1356 |
|
1361 | |||
1357 | Return: |
|
1362 | Return: | |
1358 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
1363 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
1359 | buffer. Si no hay mas archivos a leer retorna None. |
|
1364 | buffer. Si no hay mas archivos a leer retorna None. | |
1360 |
|
1365 | |||
1361 | Variables afectadas: |
|
1366 | Variables afectadas: | |
1362 | self.dataOut |
|
1367 | self.dataOut | |
1363 | self.profileIndex |
|
1368 | self.profileIndex | |
1364 |
|
1369 | |||
1365 | Affected: |
|
1370 | Affected: | |
1366 | self.dataOut |
|
1371 | self.dataOut | |
1367 | self.profileIndex |
|
1372 | self.profileIndex | |
1368 | self.flagTimeBlock |
|
1373 | self.flagTimeBlock | |
1369 | self.flagIsNewBlock |
|
1374 | self.flagIsNewBlock | |
1370 | """ |
|
1375 | """ | |
1371 |
|
1376 | |||
1372 | if self.flagNoMoreFiles: |
|
1377 | if self.flagNoMoreFiles: | |
1373 | self.dataOut.flagNoData = True |
|
1378 | self.dataOut.flagNoData = True | |
1374 | print 'Process finished' |
|
1379 | print 'Process finished' | |
1375 | return 0 |
|
1380 | return 0 | |
1376 |
|
1381 | |||
1377 | self.flagTimeBlock = 0 |
|
1382 | self.flagTimeBlock = 0 | |
1378 | self.flagIsNewBlock = 0 |
|
1383 | self.flagIsNewBlock = 0 | |
1379 |
|
1384 | |||
1380 | if self.__hasNotDataInBuffer(): |
|
1385 | if self.__hasNotDataInBuffer(): | |
1381 |
|
1386 | |||
1382 | if not( self.readNextBlock() ): |
|
1387 | if not( self.readNextBlock() ): | |
1383 | return 0 |
|
1388 | return 0 | |
1384 |
|
1389 | |||
1385 | self.dataOut.dtype = numpy.dtype([('real','<f8'),('imag','<f8')]) #self.dtype |
|
1390 | self.dataOut.dtype = numpy.dtype([('real','<f8'),('imag','<f8')]) #self.dtype | |
1386 |
|
1391 | |||
1387 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
1392 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
1388 |
|
1393 | |||
1389 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
1394 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
1390 |
|
1395 | |||
1391 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
1396 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
1392 |
|
1397 | |||
1393 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
1398 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
1394 |
|
1399 | |||
1395 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
1400 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
1396 |
|
1401 | |||
1397 | self.dataOut.ippSeconds = self.ippSeconds |
|
1402 | self.dataOut.ippSeconds = self.ippSeconds | |
1398 |
|
1403 | |||
1399 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt |
|
1404 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |
1400 |
|
1405 | |||
1401 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
1406 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
1402 |
|
1407 | |||
1403 | self.dataOut.flagShiftFFT = False |
|
1408 | self.dataOut.flagShiftFFT = False | |
1404 |
|
1409 | |||
1405 | if self.radarControllerHeaderObj.code != None: |
|
1410 | if self.radarControllerHeaderObj.code != None: | |
1406 |
|
1411 | |||
1407 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
1412 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
1408 |
|
1413 | |||
1409 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
1414 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
1410 |
|
1415 | |||
1411 | self.dataOut.code = self.radarControllerHeaderObj.code |
|
1416 | self.dataOut.code = self.radarControllerHeaderObj.code | |
1412 |
|
1417 | |||
1413 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
1418 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
1414 |
|
1419 | |||
1415 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
1420 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
1416 |
|
1421 | |||
1417 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
1422 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |
1418 |
|
1423 | |||
1419 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip |
|
1424 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip | |
1420 |
|
1425 | |||
1421 | self.dataOut.flagShiftFFT = False |
|
1426 | self.dataOut.flagShiftFFT = False | |
1422 |
|
1427 | |||
1423 |
|
1428 | |||
1424 | # self.updateDataHeader() |
|
1429 | # self.updateDataHeader() | |
1425 |
|
1430 | |||
1426 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
1431 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
1427 |
|
1432 | |||
1428 | if self.datablock == None: |
|
1433 | if self.datablock == None: | |
1429 | self.dataOut.flagNoData = True |
|
1434 | self.dataOut.flagNoData = True | |
1430 | return 0 |
|
1435 | return 0 | |
1431 |
|
1436 | |||
1432 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
1437 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
1433 |
|
1438 | |||
1434 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
1439 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |
1435 |
|
1440 | |||
1436 | self.profileIndex += 1 |
|
1441 | self.profileIndex += 1 | |
1437 |
|
1442 | |||
1438 | self.dataOut.flagNoData = False |
|
1443 | self.dataOut.flagNoData = False | |
1439 |
|
1444 | |||
1440 | # print self.profileIndex, self.dataOut.utctime |
|
1445 | # print self.profileIndex, self.dataOut.utctime | |
1441 | # if self.profileIndex == 800: |
|
1446 | # if self.profileIndex == 800: | |
1442 | # a=1 |
|
1447 | # a=1 | |
1443 |
|
1448 | |||
1444 |
|
1449 | |||
1445 | return self.dataOut.data |
|
1450 | return self.dataOut.data | |
1446 |
|
1451 | |||
1447 |
|
1452 | |||
1448 | class VoltageWriter(JRODataWriter): |
|
1453 | class VoltageWriter(JRODataWriter): | |
1449 | """ |
|
1454 | """ | |
1450 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
1455 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
1451 | de los datos siempre se realiza por bloques. |
|
1456 | de los datos siempre se realiza por bloques. | |
1452 | """ |
|
1457 | """ | |
1453 |
|
1458 | |||
1454 | ext = ".r" |
|
1459 | ext = ".r" | |
1455 |
|
1460 | |||
1456 | optchar = "D" |
|
1461 | optchar = "D" | |
1457 |
|
1462 | |||
1458 | shapeBuffer = None |
|
1463 | shapeBuffer = None | |
1459 |
|
1464 | |||
1460 |
|
1465 | |||
1461 | def __init__(self): |
|
1466 | def __init__(self): | |
1462 | """ |
|
1467 | """ | |
1463 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
1468 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
1464 |
|
1469 | |||
1465 | Affected: |
|
1470 | Affected: | |
1466 | self.dataOut |
|
1471 | self.dataOut | |
1467 |
|
1472 | |||
1468 | Return: None |
|
1473 | Return: None | |
1469 | """ |
|
1474 | """ | |
1470 |
|
1475 | |||
1471 | self.nTotalBlocks = 0 |
|
1476 | self.nTotalBlocks = 0 | |
1472 |
|
1477 | |||
1473 | self.profileIndex = 0 |
|
1478 | self.profileIndex = 0 | |
1474 |
|
1479 | |||
1475 | self.isConfig = False |
|
1480 | self.isConfig = False | |
1476 |
|
1481 | |||
1477 | self.fp = None |
|
1482 | self.fp = None | |
1478 |
|
1483 | |||
1479 | self.flagIsNewFile = 1 |
|
1484 | self.flagIsNewFile = 1 | |
1480 |
|
1485 | |||
1481 | self.nTotalBlocks = 0 |
|
1486 | self.nTotalBlocks = 0 | |
1482 |
|
1487 | |||
1483 | self.flagIsNewBlock = 0 |
|
1488 | self.flagIsNewBlock = 0 | |
1484 |
|
1489 | |||
1485 | self.setFile = None |
|
1490 | self.setFile = None | |
1486 |
|
1491 | |||
1487 | self.dtype = None |
|
1492 | self.dtype = None | |
1488 |
|
1493 | |||
1489 | self.path = None |
|
1494 | self.path = None | |
1490 |
|
1495 | |||
1491 | self.filename = None |
|
1496 | self.filename = None | |
1492 |
|
1497 | |||
1493 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1498 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1494 |
|
1499 | |||
1495 | self.systemHeaderObj = SystemHeader() |
|
1500 | self.systemHeaderObj = SystemHeader() | |
1496 |
|
1501 | |||
1497 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1502 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1498 |
|
1503 | |||
1499 | self.processingHeaderObj = ProcessingHeader() |
|
1504 | self.processingHeaderObj = ProcessingHeader() | |
1500 |
|
1505 | |||
1501 | def hasAllDataInBuffer(self): |
|
1506 | def hasAllDataInBuffer(self): | |
1502 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1507 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1503 | return 1 |
|
1508 | return 1 | |
1504 | return 0 |
|
1509 | return 0 | |
1505 |
|
1510 | |||
1506 |
|
1511 | |||
1507 | def setBlockDimension(self): |
|
1512 | def setBlockDimension(self): | |
1508 | """ |
|
1513 | """ | |
1509 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
1514 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
1510 |
|
1515 | |||
1511 | Affected: |
|
1516 | Affected: | |
1512 | self.shape_spc_Buffer |
|
1517 | self.shape_spc_Buffer | |
1513 | self.shape_cspc_Buffer |
|
1518 | self.shape_cspc_Buffer | |
1514 | self.shape_dc_Buffer |
|
1519 | self.shape_dc_Buffer | |
1515 |
|
1520 | |||
1516 | Return: None |
|
1521 | Return: None | |
1517 | """ |
|
1522 | """ | |
1518 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
1523 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
1519 | self.processingHeaderObj.nHeights, |
|
1524 | self.processingHeaderObj.nHeights, | |
1520 | self.systemHeaderObj.nChannels) |
|
1525 | self.systemHeaderObj.nChannels) | |
1521 |
|
1526 | |||
1522 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
1527 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
1523 | self.processingHeaderObj.profilesPerBlock, |
|
1528 | self.processingHeaderObj.profilesPerBlock, | |
1524 | self.processingHeaderObj.nHeights), |
|
1529 | self.processingHeaderObj.nHeights), | |
1525 | dtype=numpy.dtype('complex')) |
|
1530 | dtype=numpy.dtype('complex')) | |
1526 |
|
1531 | |||
1527 |
|
1532 | |||
1528 | def writeBlock(self): |
|
1533 | def writeBlock(self): | |
1529 | """ |
|
1534 | """ | |
1530 | Escribe el buffer en el file designado |
|
1535 | Escribe el buffer en el file designado | |
1531 |
|
1536 | |||
1532 | Affected: |
|
1537 | Affected: | |
1533 | self.profileIndex |
|
1538 | self.profileIndex | |
1534 | self.flagIsNewFile |
|
1539 | self.flagIsNewFile | |
1535 | self.flagIsNewBlock |
|
1540 | self.flagIsNewBlock | |
1536 | self.nTotalBlocks |
|
1541 | self.nTotalBlocks | |
1537 | self.blockIndex |
|
1542 | self.blockIndex | |
1538 |
|
1543 | |||
1539 | Return: None |
|
1544 | Return: None | |
1540 | """ |
|
1545 | """ | |
1541 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
1546 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
1542 |
|
1547 | |||
1543 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
1548 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
1544 |
|
1549 | |||
1545 | data['real'] = junk.real |
|
1550 | data['real'] = junk.real | |
1546 | data['imag'] = junk.imag |
|
1551 | data['imag'] = junk.imag | |
1547 |
|
1552 | |||
1548 | data = data.reshape( (-1) ) |
|
1553 | data = data.reshape( (-1) ) | |
1549 |
|
1554 | |||
1550 | data.tofile( self.fp ) |
|
1555 | data.tofile( self.fp ) | |
1551 |
|
1556 | |||
1552 | self.datablock.fill(0) |
|
1557 | self.datablock.fill(0) | |
1553 |
|
1558 | |||
1554 | self.profileIndex = 0 |
|
1559 | self.profileIndex = 0 | |
1555 | self.flagIsNewFile = 0 |
|
1560 | self.flagIsNewFile = 0 | |
1556 | self.flagIsNewBlock = 1 |
|
1561 | self.flagIsNewBlock = 1 | |
1557 |
|
1562 | |||
1558 | self.blockIndex += 1 |
|
1563 | self.blockIndex += 1 | |
1559 | self.nTotalBlocks += 1 |
|
1564 | self.nTotalBlocks += 1 | |
1560 |
|
1565 | |||
1561 | def putData(self): |
|
1566 | def putData(self): | |
1562 | """ |
|
1567 | """ | |
1563 | Setea un bloque de datos y luego los escribe en un file |
|
1568 | Setea un bloque de datos y luego los escribe en un file | |
1564 |
|
1569 | |||
1565 | Affected: |
|
1570 | Affected: | |
1566 | self.flagIsNewBlock |
|
1571 | self.flagIsNewBlock | |
1567 | self.profileIndex |
|
1572 | self.profileIndex | |
1568 |
|
1573 | |||
1569 | Return: |
|
1574 | Return: | |
1570 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
1575 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
1571 | 1 : Si se escribio la data de un bloque en un file |
|
1576 | 1 : Si se escribio la data de un bloque en un file | |
1572 | """ |
|
1577 | """ | |
1573 | if self.dataOut.flagNoData: |
|
1578 | if self.dataOut.flagNoData: | |
1574 | return 0 |
|
1579 | return 0 | |
1575 |
|
1580 | |||
1576 | self.flagIsNewBlock = 0 |
|
1581 | self.flagIsNewBlock = 0 | |
1577 |
|
1582 | |||
1578 | if self.dataOut.flagTimeBlock: |
|
1583 | if self.dataOut.flagTimeBlock: | |
1579 |
|
1584 | |||
1580 | self.datablock.fill(0) |
|
1585 | self.datablock.fill(0) | |
1581 | self.profileIndex = 0 |
|
1586 | self.profileIndex = 0 | |
1582 | self.setNextFile() |
|
1587 | self.setNextFile() | |
1583 |
|
1588 | |||
1584 | if self.profileIndex == 0: |
|
1589 | if self.profileIndex == 0: | |
1585 | self.getBasicHeader() |
|
1590 | self.getBasicHeader() | |
1586 |
|
1591 | |||
1587 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
1592 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
1588 |
|
1593 | |||
1589 | self.profileIndex += 1 |
|
1594 | self.profileIndex += 1 | |
1590 |
|
1595 | |||
1591 | if self.hasAllDataInBuffer(): |
|
1596 | if self.hasAllDataInBuffer(): | |
1592 | #if self.flagIsNewFile: |
|
1597 | #if self.flagIsNewFile: | |
1593 | self.writeNextBlock() |
|
1598 | self.writeNextBlock() | |
1594 | # self.getDataHeader() |
|
1599 | # self.getDataHeader() | |
1595 |
|
1600 | |||
1596 | return 1 |
|
1601 | return 1 | |
1597 |
|
1602 | |||
1598 | def __getProcessFlags(self): |
|
1603 | def __getProcessFlags(self): | |
1599 |
|
1604 | |||
1600 | processFlags = 0 |
|
1605 | processFlags = 0 | |
1601 |
|
1606 | |||
1602 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1607 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1603 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1608 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1604 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1609 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1605 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1610 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1606 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1611 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1607 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1612 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1608 |
|
1613 | |||
1609 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1614 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1610 |
|
1615 | |||
1611 |
|
1616 | |||
1612 |
|
1617 | |||
1613 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
1618 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
1614 | PROCFLAG.DATATYPE_SHORT, |
|
1619 | PROCFLAG.DATATYPE_SHORT, | |
1615 | PROCFLAG.DATATYPE_LONG, |
|
1620 | PROCFLAG.DATATYPE_LONG, | |
1616 | PROCFLAG.DATATYPE_INT64, |
|
1621 | PROCFLAG.DATATYPE_INT64, | |
1617 | PROCFLAG.DATATYPE_FLOAT, |
|
1622 | PROCFLAG.DATATYPE_FLOAT, | |
1618 | PROCFLAG.DATATYPE_DOUBLE] |
|
1623 | PROCFLAG.DATATYPE_DOUBLE] | |
1619 |
|
1624 | |||
1620 |
|
1625 | |||
1621 | for index in range(len(dtypeList)): |
|
1626 | for index in range(len(dtypeList)): | |
1622 | if self.dataOut.dtype == dtypeList[index]: |
|
1627 | if self.dataOut.dtype == dtypeList[index]: | |
1623 | dtypeValue = datatypeValueList[index] |
|
1628 | dtypeValue = datatypeValueList[index] | |
1624 | break |
|
1629 | break | |
1625 |
|
1630 | |||
1626 | processFlags += dtypeValue |
|
1631 | processFlags += dtypeValue | |
1627 |
|
1632 | |||
1628 | if self.dataOut.flagDecodeData: |
|
1633 | if self.dataOut.flagDecodeData: | |
1629 | processFlags += PROCFLAG.DECODE_DATA |
|
1634 | processFlags += PROCFLAG.DECODE_DATA | |
1630 |
|
1635 | |||
1631 | if self.dataOut.flagDeflipData: |
|
1636 | if self.dataOut.flagDeflipData: | |
1632 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1637 | processFlags += PROCFLAG.DEFLIP_DATA | |
1633 |
|
1638 | |||
1634 | if self.dataOut.code != None: |
|
1639 | if self.dataOut.code != None: | |
1635 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1640 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
1636 |
|
1641 | |||
1637 | if self.dataOut.nCohInt > 1: |
|
1642 | if self.dataOut.nCohInt > 1: | |
1638 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1643 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
1639 |
|
1644 | |||
1640 | return processFlags |
|
1645 | return processFlags | |
1641 |
|
1646 | |||
1642 |
|
1647 | |||
1643 | def __getBlockSize(self): |
|
1648 | def __getBlockSize(self): | |
1644 | ''' |
|
1649 | ''' | |
1645 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
1650 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
1646 | ''' |
|
1651 | ''' | |
1647 |
|
1652 | |||
1648 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1653 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1649 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1654 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1650 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1655 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1651 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1656 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1652 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1657 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1653 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1658 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1654 |
|
1659 | |||
1655 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1660 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1656 | datatypeValueList = [1,2,4,8,4,8] |
|
1661 | datatypeValueList = [1,2,4,8,4,8] | |
1657 | for index in range(len(dtypeList)): |
|
1662 | for index in range(len(dtypeList)): | |
1658 | if self.dataOut.dtype == dtypeList[index]: |
|
1663 | if self.dataOut.dtype == dtypeList[index]: | |
1659 | datatypeValue = datatypeValueList[index] |
|
1664 | datatypeValue = datatypeValueList[index] | |
1660 | break |
|
1665 | break | |
1661 |
|
1666 | |||
1662 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) |
|
1667 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) | |
1663 |
|
1668 | |||
1664 | return blocksize |
|
1669 | return blocksize | |
1665 |
|
1670 | |||
1666 | def getDataHeader(self): |
|
1671 | def getDataHeader(self): | |
1667 |
|
1672 | |||
1668 | """ |
|
1673 | """ | |
1669 | Obtiene una copia del First Header |
|
1674 | Obtiene una copia del First Header | |
1670 |
|
1675 | |||
1671 | Affected: |
|
1676 | Affected: | |
1672 | self.systemHeaderObj |
|
1677 | self.systemHeaderObj | |
1673 | self.radarControllerHeaderObj |
|
1678 | self.radarControllerHeaderObj | |
1674 | self.dtype |
|
1679 | self.dtype | |
1675 |
|
1680 | |||
1676 | Return: |
|
1681 | Return: | |
1677 | None |
|
1682 | None | |
1678 | """ |
|
1683 | """ | |
1679 |
|
1684 | |||
1680 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
1685 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
1681 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
1686 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
1682 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
1687 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
1683 |
|
1688 | |||
1684 | self.getBasicHeader() |
|
1689 | self.getBasicHeader() | |
1685 |
|
1690 | |||
1686 | processingHeaderSize = 40 # bytes |
|
1691 | processingHeaderSize = 40 # bytes | |
1687 | self.processingHeaderObj.dtype = 0 # Voltage |
|
1692 | self.processingHeaderObj.dtype = 0 # Voltage | |
1688 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
1693 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
1689 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
1694 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
1690 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
1695 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
1691 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
1696 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
1692 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
1697 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
1693 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
1698 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
1694 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
1699 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
1695 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
1700 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
1696 |
|
1701 | |||
1697 | if self.dataOut.code != None: |
|
1702 | if self.dataOut.code != None: | |
1698 | self.processingHeaderObj.code = self.dataOut.code |
|
1703 | self.processingHeaderObj.code = self.dataOut.code | |
1699 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
1704 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
1700 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
1705 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
1701 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
1706 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) | |
1702 | processingHeaderSize += codesize |
|
1707 | processingHeaderSize += codesize | |
1703 |
|
1708 | |||
1704 | if self.processingHeaderObj.nWindows != 0: |
|
1709 | if self.processingHeaderObj.nWindows != 0: | |
1705 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
1710 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
1706 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
1711 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
1707 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
1712 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
1708 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
1713 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
1709 | processingHeaderSize += 12 |
|
1714 | processingHeaderSize += 12 | |
1710 |
|
1715 | |||
1711 | self.processingHeaderObj.size = processingHeaderSize |
|
1716 | self.processingHeaderObj.size = processingHeaderSize | |
1712 |
|
1717 | |||
1713 | class SpectraReader(JRODataReader): |
|
1718 | class SpectraReader(JRODataReader): | |
1714 | """ |
|
1719 | """ | |
1715 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
1720 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
1716 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
1721 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
1717 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
1722 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
1718 |
|
1723 | |||
1719 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
1724 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
1720 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
1725 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
1721 | canales * alturas (DC Channels) |
|
1726 | canales * alturas (DC Channels) | |
1722 |
|
1727 | |||
1723 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1728 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1724 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
1729 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
1725 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
1730 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
1726 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1731 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1727 |
|
1732 | |||
1728 | Example: |
|
1733 | Example: | |
1729 | dpath = "/home/myuser/data" |
|
1734 | dpath = "/home/myuser/data" | |
1730 |
|
1735 | |||
1731 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1736 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1732 |
|
1737 | |||
1733 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1738 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1734 |
|
1739 | |||
1735 | readerObj = SpectraReader() |
|
1740 | readerObj = SpectraReader() | |
1736 |
|
1741 | |||
1737 | readerObj.setup(dpath, startTime, endTime) |
|
1742 | readerObj.setup(dpath, startTime, endTime) | |
1738 |
|
1743 | |||
1739 | while(True): |
|
1744 | while(True): | |
1740 |
|
1745 | |||
1741 | readerObj.getData() |
|
1746 | readerObj.getData() | |
1742 |
|
1747 | |||
1743 | print readerObj.data_spc |
|
1748 | print readerObj.data_spc | |
1744 |
|
1749 | |||
1745 | print readerObj.data_cspc |
|
1750 | print readerObj.data_cspc | |
1746 |
|
1751 | |||
1747 | print readerObj.data_dc |
|
1752 | print readerObj.data_dc | |
1748 |
|
1753 | |||
1749 | if readerObj.flagNoMoreFiles: |
|
1754 | if readerObj.flagNoMoreFiles: | |
1750 | break |
|
1755 | break | |
1751 |
|
1756 | |||
1752 | """ |
|
1757 | """ | |
1753 |
|
1758 | |||
1754 | pts2read_SelfSpectra = 0 |
|
1759 | pts2read_SelfSpectra = 0 | |
1755 |
|
1760 | |||
1756 | pts2read_CrossSpectra = 0 |
|
1761 | pts2read_CrossSpectra = 0 | |
1757 |
|
1762 | |||
1758 | pts2read_DCchannels = 0 |
|
1763 | pts2read_DCchannels = 0 | |
1759 |
|
1764 | |||
1760 | ext = ".pdata" |
|
1765 | ext = ".pdata" | |
1761 |
|
1766 | |||
1762 | optchar = "P" |
|
1767 | optchar = "P" | |
1763 |
|
1768 | |||
1764 | dataOut = None |
|
1769 | dataOut = None | |
1765 |
|
1770 | |||
1766 | nRdChannels = None |
|
1771 | nRdChannels = None | |
1767 |
|
1772 | |||
1768 | nRdPairs = None |
|
1773 | nRdPairs = None | |
1769 |
|
1774 | |||
1770 | rdPairList = [] |
|
1775 | rdPairList = [] | |
1771 |
|
1776 | |||
1772 |
|
1777 | |||
1773 | def __init__(self): |
|
1778 | def __init__(self): | |
1774 | """ |
|
1779 | """ | |
1775 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
1780 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
1776 |
|
1781 | |||
1777 | Inputs: |
|
1782 | Inputs: | |
1778 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
1783 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para | |
1779 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1784 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1780 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1785 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1781 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1786 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1782 | bloque de datos. |
|
1787 | bloque de datos. | |
1783 | Si este parametro no es pasado se creara uno internamente. |
|
1788 | Si este parametro no es pasado se creara uno internamente. | |
1784 |
|
1789 | |||
1785 | Affected: |
|
1790 | Affected: | |
1786 | self.dataOut |
|
1791 | self.dataOut | |
1787 |
|
1792 | |||
1788 | Return : None |
|
1793 | Return : None | |
1789 | """ |
|
1794 | """ | |
1790 |
|
1795 | |||
1791 | self.isConfig = False |
|
1796 | self.isConfig = False | |
1792 |
|
1797 | |||
1793 | self.pts2read_SelfSpectra = 0 |
|
1798 | self.pts2read_SelfSpectra = 0 | |
1794 |
|
1799 | |||
1795 | self.pts2read_CrossSpectra = 0 |
|
1800 | self.pts2read_CrossSpectra = 0 | |
1796 |
|
1801 | |||
1797 | self.pts2read_DCchannels = 0 |
|
1802 | self.pts2read_DCchannels = 0 | |
1798 |
|
1803 | |||
1799 | self.datablock = None |
|
1804 | self.datablock = None | |
1800 |
|
1805 | |||
1801 | self.utc = None |
|
1806 | self.utc = None | |
1802 |
|
1807 | |||
1803 | self.ext = ".pdata" |
|
1808 | self.ext = ".pdata" | |
1804 |
|
1809 | |||
1805 | self.optchar = "P" |
|
1810 | self.optchar = "P" | |
1806 |
|
1811 | |||
1807 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1812 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1808 |
|
1813 | |||
1809 | self.systemHeaderObj = SystemHeader() |
|
1814 | self.systemHeaderObj = SystemHeader() | |
1810 |
|
1815 | |||
1811 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1816 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1812 |
|
1817 | |||
1813 | self.processingHeaderObj = ProcessingHeader() |
|
1818 | self.processingHeaderObj = ProcessingHeader() | |
1814 |
|
1819 | |||
1815 | self.online = 0 |
|
1820 | self.online = 0 | |
1816 |
|
1821 | |||
1817 | self.fp = None |
|
1822 | self.fp = None | |
1818 |
|
1823 | |||
1819 | self.idFile = None |
|
1824 | self.idFile = None | |
1820 |
|
1825 | |||
1821 | self.dtype = None |
|
1826 | self.dtype = None | |
1822 |
|
1827 | |||
1823 | self.fileSizeByHeader = None |
|
1828 | self.fileSizeByHeader = None | |
1824 |
|
1829 | |||
1825 | self.filenameList = [] |
|
1830 | self.filenameList = [] | |
1826 |
|
1831 | |||
1827 | self.filename = None |
|
1832 | self.filename = None | |
1828 |
|
1833 | |||
1829 | self.fileSize = None |
|
1834 | self.fileSize = None | |
1830 |
|
1835 | |||
1831 | self.firstHeaderSize = 0 |
|
1836 | self.firstHeaderSize = 0 | |
1832 |
|
1837 | |||
1833 | self.basicHeaderSize = 24 |
|
1838 | self.basicHeaderSize = 24 | |
1834 |
|
1839 | |||
1835 | self.pathList = [] |
|
1840 | self.pathList = [] | |
1836 |
|
1841 | |||
1837 | self.lastUTTime = 0 |
|
1842 | self.lastUTTime = 0 | |
1838 |
|
1843 | |||
1839 | self.maxTimeStep = 30 |
|
1844 | self.maxTimeStep = 30 | |
1840 |
|
1845 | |||
1841 | self.flagNoMoreFiles = 0 |
|
1846 | self.flagNoMoreFiles = 0 | |
1842 |
|
1847 | |||
1843 | self.set = 0 |
|
1848 | self.set = 0 | |
1844 |
|
1849 | |||
1845 | self.path = None |
|
1850 | self.path = None | |
1846 |
|
1851 | |||
1847 | self.delay = 3 #seconds |
|
1852 | self.delay = 3 #seconds | |
1848 |
|
1853 | |||
1849 | self.nTries = 3 #quantity tries |
|
1854 | self.nTries = 3 #quantity tries | |
1850 |
|
1855 | |||
1851 | self.nFiles = 3 #number of files for searching |
|
1856 | self.nFiles = 3 #number of files for searching | |
1852 |
|
1857 | |||
1853 | self.nReadBlocks = 0 |
|
1858 | self.nReadBlocks = 0 | |
1854 |
|
1859 | |||
1855 | self.flagIsNewFile = 1 |
|
1860 | self.flagIsNewFile = 1 | |
1856 |
|
1861 | |||
1857 | self.ippSeconds = 0 |
|
1862 | self.ippSeconds = 0 | |
1858 |
|
1863 | |||
1859 | self.flagTimeBlock = 0 |
|
1864 | self.flagTimeBlock = 0 | |
1860 |
|
1865 | |||
1861 | self.flagIsNewBlock = 0 |
|
1866 | self.flagIsNewBlock = 0 | |
1862 |
|
1867 | |||
1863 | self.nTotalBlocks = 0 |
|
1868 | self.nTotalBlocks = 0 | |
1864 |
|
1869 | |||
1865 | self.blocksize = 0 |
|
1870 | self.blocksize = 0 | |
1866 |
|
1871 | |||
1867 | self.dataOut = self.createObjByDefault() |
|
1872 | self.dataOut = self.createObjByDefault() | |
1868 |
|
1873 | |||
1869 |
|
1874 | |||
1870 | def createObjByDefault(self): |
|
1875 | def createObjByDefault(self): | |
1871 |
|
1876 | |||
1872 | dataObj = Spectra() |
|
1877 | dataObj = Spectra() | |
1873 |
|
1878 | |||
1874 | return dataObj |
|
1879 | return dataObj | |
1875 |
|
1880 | |||
1876 | def __hasNotDataInBuffer(self): |
|
1881 | def __hasNotDataInBuffer(self): | |
1877 | return 1 |
|
1882 | return 1 | |
1878 |
|
1883 | |||
1879 |
|
1884 | |||
1880 | def getBlockDimension(self): |
|
1885 | def getBlockDimension(self): | |
1881 | """ |
|
1886 | """ | |
1882 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1887 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1883 |
|
1888 | |||
1884 | Affected: |
|
1889 | Affected: | |
1885 | self.nRdChannels |
|
1890 | self.nRdChannels | |
1886 | self.nRdPairs |
|
1891 | self.nRdPairs | |
1887 | self.pts2read_SelfSpectra |
|
1892 | self.pts2read_SelfSpectra | |
1888 | self.pts2read_CrossSpectra |
|
1893 | self.pts2read_CrossSpectra | |
1889 | self.pts2read_DCchannels |
|
1894 | self.pts2read_DCchannels | |
1890 | self.blocksize |
|
1895 | self.blocksize | |
1891 | self.dataOut.nChannels |
|
1896 | self.dataOut.nChannels | |
1892 | self.dataOut.nPairs |
|
1897 | self.dataOut.nPairs | |
1893 |
|
1898 | |||
1894 | Return: |
|
1899 | Return: | |
1895 | None |
|
1900 | None | |
1896 | """ |
|
1901 | """ | |
1897 | self.nRdChannels = 0 |
|
1902 | self.nRdChannels = 0 | |
1898 | self.nRdPairs = 0 |
|
1903 | self.nRdPairs = 0 | |
1899 | self.rdPairList = [] |
|
1904 | self.rdPairList = [] | |
1900 |
|
1905 | |||
1901 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
1906 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
1902 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
1907 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
1903 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
1908 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
1904 | else: |
|
1909 | else: | |
1905 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
1910 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
1906 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
1911 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
1907 |
|
1912 | |||
1908 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
1913 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
1909 |
|
1914 | |||
1910 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
1915 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
1911 | self.blocksize = self.pts2read_SelfSpectra |
|
1916 | self.blocksize = self.pts2read_SelfSpectra | |
1912 |
|
1917 | |||
1913 | if self.processingHeaderObj.flag_cspc: |
|
1918 | if self.processingHeaderObj.flag_cspc: | |
1914 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
1919 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
1915 | self.blocksize += self.pts2read_CrossSpectra |
|
1920 | self.blocksize += self.pts2read_CrossSpectra | |
1916 |
|
1921 | |||
1917 | if self.processingHeaderObj.flag_dc: |
|
1922 | if self.processingHeaderObj.flag_dc: | |
1918 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
1923 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
1919 | self.blocksize += self.pts2read_DCchannels |
|
1924 | self.blocksize += self.pts2read_DCchannels | |
1920 |
|
1925 | |||
1921 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
1926 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
1922 |
|
1927 | |||
1923 |
|
1928 | |||
1924 | def readBlock(self): |
|
1929 | def readBlock(self): | |
1925 | """ |
|
1930 | """ | |
1926 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1931 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
1927 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1932 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1928 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1933 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1929 | es seteado a 0 |
|
1934 | es seteado a 0 | |
1930 |
|
1935 | |||
1931 | Return: None |
|
1936 | Return: None | |
1932 |
|
1937 | |||
1933 | Variables afectadas: |
|
1938 | Variables afectadas: | |
1934 |
|
1939 | |||
1935 | self.flagIsNewFile |
|
1940 | self.flagIsNewFile | |
1936 | self.flagIsNewBlock |
|
1941 | self.flagIsNewBlock | |
1937 | self.nTotalBlocks |
|
1942 | self.nTotalBlocks | |
1938 | self.data_spc |
|
1943 | self.data_spc | |
1939 | self.data_cspc |
|
1944 | self.data_cspc | |
1940 | self.data_dc |
|
1945 | self.data_dc | |
1941 |
|
1946 | |||
1942 | Exceptions: |
|
1947 | Exceptions: | |
1943 | Si un bloque leido no es un bloque valido |
|
1948 | Si un bloque leido no es un bloque valido | |
1944 | """ |
|
1949 | """ | |
1945 | blockOk_flag = False |
|
1950 | blockOk_flag = False | |
1946 | fpointer = self.fp.tell() |
|
1951 | fpointer = self.fp.tell() | |
1947 |
|
1952 | |||
1948 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
1953 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
1949 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
1954 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
1950 |
|
1955 | |||
1951 | if self.processingHeaderObj.flag_cspc: |
|
1956 | if self.processingHeaderObj.flag_cspc: | |
1952 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
1957 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
1953 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
1958 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
1954 |
|
1959 | |||
1955 | if self.processingHeaderObj.flag_dc: |
|
1960 | if self.processingHeaderObj.flag_dc: | |
1956 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
1961 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
1957 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
1962 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
1958 |
|
1963 | |||
1959 |
|
1964 | |||
1960 | if not(self.processingHeaderObj.shif_fft): |
|
1965 | if not(self.processingHeaderObj.shif_fft): | |
1961 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
1966 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
1962 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
1967 | shift = int(self.processingHeaderObj.profilesPerBlock/2) | |
1963 | spc = numpy.roll( spc, shift , axis=2 ) |
|
1968 | spc = numpy.roll( spc, shift , axis=2 ) | |
1964 |
|
1969 | |||
1965 | if self.processingHeaderObj.flag_cspc: |
|
1970 | if self.processingHeaderObj.flag_cspc: | |
1966 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
1971 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
1967 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
1972 | cspc = numpy.roll( cspc, shift, axis=2 ) | |
1968 |
|
1973 | |||
1969 | # self.processingHeaderObj.shif_fft = True |
|
1974 | # self.processingHeaderObj.shif_fft = True | |
1970 |
|
1975 | |||
1971 | spc = numpy.transpose( spc, (0,2,1) ) |
|
1976 | spc = numpy.transpose( spc, (0,2,1) ) | |
1972 | self.data_spc = spc |
|
1977 | self.data_spc = spc | |
1973 |
|
1978 | |||
1974 | if self.processingHeaderObj.flag_cspc: |
|
1979 | if self.processingHeaderObj.flag_cspc: | |
1975 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
1980 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
1976 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
1981 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
1977 | else: |
|
1982 | else: | |
1978 | self.data_cspc = None |
|
1983 | self.data_cspc = None | |
1979 |
|
1984 | |||
1980 | if self.processingHeaderObj.flag_dc: |
|
1985 | if self.processingHeaderObj.flag_dc: | |
1981 | self.data_dc = dc['real'] + dc['imag']*1j |
|
1986 | self.data_dc = dc['real'] + dc['imag']*1j | |
1982 | else: |
|
1987 | else: | |
1983 | self.data_dc = None |
|
1988 | self.data_dc = None | |
1984 |
|
1989 | |||
1985 | self.flagIsNewFile = 0 |
|
1990 | self.flagIsNewFile = 0 | |
1986 | self.flagIsNewBlock = 1 |
|
1991 | self.flagIsNewBlock = 1 | |
1987 |
|
1992 | |||
1988 | self.nTotalBlocks += 1 |
|
1993 | self.nTotalBlocks += 1 | |
1989 | self.nReadBlocks += 1 |
|
1994 | self.nReadBlocks += 1 | |
1990 |
|
1995 | |||
1991 | return 1 |
|
1996 | return 1 | |
1992 |
|
1997 | |||
1993 |
|
1998 | |||
1994 | def getData(self): |
|
1999 | def getData(self): | |
1995 | """ |
|
2000 | """ | |
1996 | Copia el buffer de lectura a la clase "Spectra", |
|
2001 | Copia el buffer de lectura a la clase "Spectra", | |
1997 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
2002 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1998 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
2003 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1999 |
|
2004 | |||
2000 | Return: |
|
2005 | Return: | |
2001 | 0 : Si no hay mas archivos disponibles |
|
2006 | 0 : Si no hay mas archivos disponibles | |
2002 | 1 : Si hizo una buena copia del buffer |
|
2007 | 1 : Si hizo una buena copia del buffer | |
2003 |
|
2008 | |||
2004 | Affected: |
|
2009 | Affected: | |
2005 | self.dataOut |
|
2010 | self.dataOut | |
2006 |
|
2011 | |||
2007 | self.flagTimeBlock |
|
2012 | self.flagTimeBlock | |
2008 | self.flagIsNewBlock |
|
2013 | self.flagIsNewBlock | |
2009 | """ |
|
2014 | """ | |
2010 |
|
2015 | |||
2011 | if self.flagNoMoreFiles: |
|
2016 | if self.flagNoMoreFiles: | |
2012 | self.dataOut.flagNoData = True |
|
2017 | self.dataOut.flagNoData = True | |
2013 | print 'Process finished' |
|
2018 | print 'Process finished' | |
2014 | return 0 |
|
2019 | return 0 | |
2015 |
|
2020 | |||
2016 | self.flagTimeBlock = 0 |
|
2021 | self.flagTimeBlock = 0 | |
2017 | self.flagIsNewBlock = 0 |
|
2022 | self.flagIsNewBlock = 0 | |
2018 |
|
2023 | |||
2019 | if self.__hasNotDataInBuffer(): |
|
2024 | if self.__hasNotDataInBuffer(): | |
2020 |
|
2025 | |||
2021 | if not( self.readNextBlock() ): |
|
2026 | if not( self.readNextBlock() ): | |
2022 | self.dataOut.flagNoData = True |
|
2027 | self.dataOut.flagNoData = True | |
2023 | return 0 |
|
2028 | return 0 | |
2024 |
|
2029 | |||
2025 | # self.updateDataHeader() |
|
2030 | # self.updateDataHeader() | |
2026 |
|
2031 | |||
2027 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
2032 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
2028 |
|
2033 | |||
2029 | if self.data_dc == None: |
|
2034 | if self.data_dc == None: | |
2030 | self.dataOut.flagNoData = True |
|
2035 | self.dataOut.flagNoData = True | |
2031 | return 0 |
|
2036 | return 0 | |
2032 |
|
2037 | |||
2033 | self.dataOut.data_spc = self.data_spc |
|
2038 | self.dataOut.data_spc = self.data_spc | |
2034 |
|
2039 | |||
2035 | self.dataOut.data_cspc = self.data_cspc |
|
2040 | self.dataOut.data_cspc = self.data_cspc | |
2036 |
|
2041 | |||
2037 | self.dataOut.data_dc = self.data_dc |
|
2042 | self.dataOut.data_dc = self.data_dc | |
2038 |
|
2043 | |||
2039 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
2044 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |
2040 |
|
2045 | |||
2041 | self.dataOut.flagNoData = False |
|
2046 | self.dataOut.flagNoData = False | |
2042 |
|
2047 | |||
2043 | self.dataOut.dtype = numpy.dtype([('real','<f8'),('imag','<f8')])#self.dtype |
|
2048 | self.dataOut.dtype = numpy.dtype([('real','<f8'),('imag','<f8')])#self.dtype | |
2044 |
|
2049 | |||
2045 | # self.dataOut.nChannels = self.nRdChannels |
|
2050 | # self.dataOut.nChannels = self.nRdChannels | |
2046 |
|
2051 | |||
2047 | self.dataOut.nPairs = self.nRdPairs |
|
2052 | self.dataOut.nPairs = self.nRdPairs | |
2048 |
|
2053 | |||
2049 | self.dataOut.pairsList = self.rdPairList |
|
2054 | self.dataOut.pairsList = self.rdPairList | |
2050 |
|
2055 | |||
2051 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights |
|
2056 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights | |
2052 |
|
2057 | |||
2053 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
2058 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |
2054 |
|
2059 | |||
2055 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
2060 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |
2056 |
|
2061 | |||
2057 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
2062 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |
2058 |
|
2063 | |||
2059 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
2064 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |
2060 |
|
2065 | |||
2061 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
2066 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |
2062 |
|
2067 | |||
2063 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
2068 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
2064 |
|
2069 | |||
2065 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
2070 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |
2066 |
|
2071 | |||
2067 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
2072 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) | |
2068 |
|
2073 | |||
2069 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds |
|
2074 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds | |
2070 |
|
2075 | |||
2071 | self.dataOut.ippSeconds = self.ippSeconds |
|
2076 | self.dataOut.ippSeconds = self.ippSeconds | |
2072 |
|
2077 | |||
2073 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints |
|
2078 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints | |
2074 |
|
2079 | |||
2075 | # self.profileIndex += 1 |
|
2080 | # self.profileIndex += 1 | |
2076 |
|
2081 | |||
2077 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
2082 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |
2078 |
|
2083 | |||
2079 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
2084 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |
2080 |
|
2085 | |||
2081 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
2086 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |
2082 |
|
2087 | |||
2083 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
2088 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |
2084 |
|
2089 | |||
2085 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
2090 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
2086 |
|
2091 | |||
2087 | if self.processingHeaderObj.code != None: |
|
2092 | if self.processingHeaderObj.code != None: | |
2088 |
|
2093 | |||
2089 | self.dataOut.nCode = self.processingHeaderObj.nCode |
|
2094 | self.dataOut.nCode = self.processingHeaderObj.nCode | |
2090 |
|
2095 | |||
2091 | self.dataOut.nBaud = self.processingHeaderObj.nBaud |
|
2096 | self.dataOut.nBaud = self.processingHeaderObj.nBaud | |
2092 |
|
2097 | |||
2093 | self.dataOut.code = self.processingHeaderObj.code |
|
2098 | self.dataOut.code = self.processingHeaderObj.code | |
2094 |
|
2099 | |||
2095 | self.dataOut.flagDecodeData = True |
|
2100 | self.dataOut.flagDecodeData = True | |
2096 |
|
2101 | |||
2097 | return self.dataOut.data_spc |
|
2102 | return self.dataOut.data_spc | |
2098 |
|
2103 | |||
2099 |
|
2104 | |||
2100 | class SpectraWriter(JRODataWriter): |
|
2105 | class SpectraWriter(JRODataWriter): | |
2101 |
|
2106 | |||
2102 | """ |
|
2107 | """ | |
2103 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
2108 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
2104 | de los datos siempre se realiza por bloques. |
|
2109 | de los datos siempre se realiza por bloques. | |
2105 | """ |
|
2110 | """ | |
2106 |
|
2111 | |||
2107 | ext = ".pdata" |
|
2112 | ext = ".pdata" | |
2108 |
|
2113 | |||
2109 | optchar = "P" |
|
2114 | optchar = "P" | |
2110 |
|
2115 | |||
2111 | shape_spc_Buffer = None |
|
2116 | shape_spc_Buffer = None | |
2112 |
|
2117 | |||
2113 | shape_cspc_Buffer = None |
|
2118 | shape_cspc_Buffer = None | |
2114 |
|
2119 | |||
2115 | shape_dc_Buffer = None |
|
2120 | shape_dc_Buffer = None | |
2116 |
|
2121 | |||
2117 | data_spc = None |
|
2122 | data_spc = None | |
2118 |
|
2123 | |||
2119 | data_cspc = None |
|
2124 | data_cspc = None | |
2120 |
|
2125 | |||
2121 | data_dc = None |
|
2126 | data_dc = None | |
2122 |
|
2127 | |||
2123 | # dataOut = None |
|
2128 | # dataOut = None | |
2124 |
|
2129 | |||
2125 | def __init__(self): |
|
2130 | def __init__(self): | |
2126 | """ |
|
2131 | """ | |
2127 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
2132 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
2128 |
|
2133 | |||
2129 | Affected: |
|
2134 | Affected: | |
2130 | self.dataOut |
|
2135 | self.dataOut | |
2131 | self.basicHeaderObj |
|
2136 | self.basicHeaderObj | |
2132 | self.systemHeaderObj |
|
2137 | self.systemHeaderObj | |
2133 | self.radarControllerHeaderObj |
|
2138 | self.radarControllerHeaderObj | |
2134 | self.processingHeaderObj |
|
2139 | self.processingHeaderObj | |
2135 |
|
2140 | |||
2136 | Return: None |
|
2141 | Return: None | |
2137 | """ |
|
2142 | """ | |
2138 |
|
2143 | |||
2139 | self.isConfig = False |
|
2144 | self.isConfig = False | |
2140 |
|
2145 | |||
2141 | self.nTotalBlocks = 0 |
|
2146 | self.nTotalBlocks = 0 | |
2142 |
|
2147 | |||
2143 | self.data_spc = None |
|
2148 | self.data_spc = None | |
2144 |
|
2149 | |||
2145 | self.data_cspc = None |
|
2150 | self.data_cspc = None | |
2146 |
|
2151 | |||
2147 | self.data_dc = None |
|
2152 | self.data_dc = None | |
2148 |
|
2153 | |||
2149 | self.fp = None |
|
2154 | self.fp = None | |
2150 |
|
2155 | |||
2151 | self.flagIsNewFile = 1 |
|
2156 | self.flagIsNewFile = 1 | |
2152 |
|
2157 | |||
2153 | self.nTotalBlocks = 0 |
|
2158 | self.nTotalBlocks = 0 | |
2154 |
|
2159 | |||
2155 | self.flagIsNewBlock = 0 |
|
2160 | self.flagIsNewBlock = 0 | |
2156 |
|
2161 | |||
2157 | self.setFile = None |
|
2162 | self.setFile = None | |
2158 |
|
2163 | |||
2159 | self.dtype = None |
|
2164 | self.dtype = None | |
2160 |
|
2165 | |||
2161 | self.path = None |
|
2166 | self.path = None | |
2162 |
|
2167 | |||
2163 | self.noMoreFiles = 0 |
|
2168 | self.noMoreFiles = 0 | |
2164 |
|
2169 | |||
2165 | self.filename = None |
|
2170 | self.filename = None | |
2166 |
|
2171 | |||
2167 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
2172 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
2168 |
|
2173 | |||
2169 | self.systemHeaderObj = SystemHeader() |
|
2174 | self.systemHeaderObj = SystemHeader() | |
2170 |
|
2175 | |||
2171 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2176 | self.radarControllerHeaderObj = RadarControllerHeader() | |
2172 |
|
2177 | |||
2173 | self.processingHeaderObj = ProcessingHeader() |
|
2178 | self.processingHeaderObj = ProcessingHeader() | |
2174 |
|
2179 | |||
2175 |
|
2180 | |||
2176 | def hasAllDataInBuffer(self): |
|
2181 | def hasAllDataInBuffer(self): | |
2177 | return 1 |
|
2182 | return 1 | |
2178 |
|
2183 | |||
2179 |
|
2184 | |||
2180 | def setBlockDimension(self): |
|
2185 | def setBlockDimension(self): | |
2181 | """ |
|
2186 | """ | |
2182 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
2187 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
2183 |
|
2188 | |||
2184 | Affected: |
|
2189 | Affected: | |
2185 | self.shape_spc_Buffer |
|
2190 | self.shape_spc_Buffer | |
2186 | self.shape_cspc_Buffer |
|
2191 | self.shape_cspc_Buffer | |
2187 | self.shape_dc_Buffer |
|
2192 | self.shape_dc_Buffer | |
2188 |
|
2193 | |||
2189 | Return: None |
|
2194 | Return: None | |
2190 | """ |
|
2195 | """ | |
2191 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
2196 | self.shape_spc_Buffer = (self.dataOut.nChannels, | |
2192 | self.processingHeaderObj.nHeights, |
|
2197 | self.processingHeaderObj.nHeights, | |
2193 | self.processingHeaderObj.profilesPerBlock) |
|
2198 | self.processingHeaderObj.profilesPerBlock) | |
2194 |
|
2199 | |||
2195 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
2200 | self.shape_cspc_Buffer = (self.dataOut.nPairs, | |
2196 | self.processingHeaderObj.nHeights, |
|
2201 | self.processingHeaderObj.nHeights, | |
2197 | self.processingHeaderObj.profilesPerBlock) |
|
2202 | self.processingHeaderObj.profilesPerBlock) | |
2198 |
|
2203 | |||
2199 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
2204 | self.shape_dc_Buffer = (self.dataOut.nChannels, | |
2200 | self.processingHeaderObj.nHeights) |
|
2205 | self.processingHeaderObj.nHeights) | |
2201 |
|
2206 | |||
2202 |
|
2207 | |||
2203 | def writeBlock(self): |
|
2208 | def writeBlock(self): | |
2204 | """ |
|
2209 | """ | |
2205 | Escribe el buffer en el file designado |
|
2210 | Escribe el buffer en el file designado | |
2206 |
|
2211 | |||
2207 | Affected: |
|
2212 | Affected: | |
2208 | self.data_spc |
|
2213 | self.data_spc | |
2209 | self.data_cspc |
|
2214 | self.data_cspc | |
2210 | self.data_dc |
|
2215 | self.data_dc | |
2211 | self.flagIsNewFile |
|
2216 | self.flagIsNewFile | |
2212 | self.flagIsNewBlock |
|
2217 | self.flagIsNewBlock | |
2213 | self.nTotalBlocks |
|
2218 | self.nTotalBlocks | |
2214 | self.nWriteBlocks |
|
2219 | self.nWriteBlocks | |
2215 |
|
2220 | |||
2216 | Return: None |
|
2221 | Return: None | |
2217 | """ |
|
2222 | """ | |
2218 |
|
2223 | |||
2219 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
2224 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
2220 | if not( self.processingHeaderObj.shif_fft ): |
|
2225 | if not( self.processingHeaderObj.shif_fft ): | |
2221 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2226 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2222 | data = spc.reshape((-1)) |
|
2227 | data = spc.reshape((-1)) | |
2223 | data.tofile(self.fp) |
|
2228 | data.tofile(self.fp) | |
2224 |
|
2229 | |||
2225 | if self.data_cspc != None: |
|
2230 | if self.data_cspc != None: | |
2226 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
2231 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
2227 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
2232 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
2228 | if not( self.processingHeaderObj.shif_fft ): |
|
2233 | if not( self.processingHeaderObj.shif_fft ): | |
2229 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2234 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2230 | data['real'] = cspc.real |
|
2235 | data['real'] = cspc.real | |
2231 | data['imag'] = cspc.imag |
|
2236 | data['imag'] = cspc.imag | |
2232 | data = data.reshape((-1)) |
|
2237 | data = data.reshape((-1)) | |
2233 | data.tofile(self.fp) |
|
2238 | data.tofile(self.fp) | |
2234 |
|
2239 | |||
2235 | if self.data_dc != None: |
|
2240 | if self.data_dc != None: | |
2236 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
2241 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
2237 | dc = self.data_dc |
|
2242 | dc = self.data_dc | |
2238 | data['real'] = dc.real |
|
2243 | data['real'] = dc.real | |
2239 | data['imag'] = dc.imag |
|
2244 | data['imag'] = dc.imag | |
2240 | data = data.reshape((-1)) |
|
2245 | data = data.reshape((-1)) | |
2241 | data.tofile(self.fp) |
|
2246 | data.tofile(self.fp) | |
2242 |
|
2247 | |||
2243 | self.data_spc.fill(0) |
|
2248 | self.data_spc.fill(0) | |
2244 | self.data_dc.fill(0) |
|
2249 | self.data_dc.fill(0) | |
2245 | if self.data_cspc != None: |
|
2250 | if self.data_cspc != None: | |
2246 | self.data_cspc.fill(0) |
|
2251 | self.data_cspc.fill(0) | |
2247 |
|
2252 | |||
2248 | self.flagIsNewFile = 0 |
|
2253 | self.flagIsNewFile = 0 | |
2249 | self.flagIsNewBlock = 1 |
|
2254 | self.flagIsNewBlock = 1 | |
2250 | self.nTotalBlocks += 1 |
|
2255 | self.nTotalBlocks += 1 | |
2251 | self.nWriteBlocks += 1 |
|
2256 | self.nWriteBlocks += 1 | |
2252 | self.blockIndex += 1 |
|
2257 | self.blockIndex += 1 | |
2253 |
|
2258 | |||
2254 |
|
2259 | |||
2255 | def putData(self): |
|
2260 | def putData(self): | |
2256 | """ |
|
2261 | """ | |
2257 | Setea un bloque de datos y luego los escribe en un file |
|
2262 | Setea un bloque de datos y luego los escribe en un file | |
2258 |
|
2263 | |||
2259 | Affected: |
|
2264 | Affected: | |
2260 | self.data_spc |
|
2265 | self.data_spc | |
2261 | self.data_cspc |
|
2266 | self.data_cspc | |
2262 | self.data_dc |
|
2267 | self.data_dc | |
2263 |
|
2268 | |||
2264 | Return: |
|
2269 | Return: | |
2265 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
2270 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
2266 | 1 : Si se escribio la data de un bloque en un file |
|
2271 | 1 : Si se escribio la data de un bloque en un file | |
2267 | """ |
|
2272 | """ | |
2268 |
|
2273 | |||
2269 | if self.dataOut.flagNoData: |
|
2274 | if self.dataOut.flagNoData: | |
2270 | return 0 |
|
2275 | return 0 | |
2271 |
|
2276 | |||
2272 | self.flagIsNewBlock = 0 |
|
2277 | self.flagIsNewBlock = 0 | |
2273 |
|
2278 | |||
2274 | if self.dataOut.flagTimeBlock: |
|
2279 | if self.dataOut.flagTimeBlock: | |
2275 | self.data_spc.fill(0) |
|
2280 | self.data_spc.fill(0) | |
2276 | self.data_cspc.fill(0) |
|
2281 | self.data_cspc.fill(0) | |
2277 | self.data_dc.fill(0) |
|
2282 | self.data_dc.fill(0) | |
2278 | self.setNextFile() |
|
2283 | self.setNextFile() | |
2279 |
|
2284 | |||
2280 | if self.flagIsNewFile == 0: |
|
2285 | if self.flagIsNewFile == 0: | |
2281 | self.getBasicHeader() |
|
2286 | self.getBasicHeader() | |
2282 |
|
2287 | |||
2283 | self.data_spc = self.dataOut.data_spc.copy() |
|
2288 | self.data_spc = self.dataOut.data_spc.copy() | |
2284 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
2289 | self.data_cspc = self.dataOut.data_cspc.copy() | |
2285 | self.data_dc = self.dataOut.data_dc.copy() |
|
2290 | self.data_dc = self.dataOut.data_dc.copy() | |
2286 |
|
2291 | |||
2287 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
2292 | # #self.processingHeaderObj.dataBlocksPerFile) | |
2288 | if self.hasAllDataInBuffer(): |
|
2293 | if self.hasAllDataInBuffer(): | |
2289 | # self.getDataHeader() |
|
2294 | # self.getDataHeader() | |
2290 | self.writeNextBlock() |
|
2295 | self.writeNextBlock() | |
2291 |
|
2296 | |||
2292 | return 1 |
|
2297 | return 1 | |
2293 |
|
2298 | |||
2294 |
|
2299 | |||
2295 | def __getProcessFlags(self): |
|
2300 | def __getProcessFlags(self): | |
2296 |
|
2301 | |||
2297 | processFlags = 0 |
|
2302 | processFlags = 0 | |
2298 |
|
2303 | |||
2299 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2304 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2300 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2305 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2301 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2306 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2302 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2307 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2303 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2308 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2304 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2309 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2305 |
|
2310 | |||
2306 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2311 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2307 |
|
2312 | |||
2308 |
|
2313 | |||
2309 |
|
2314 | |||
2310 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
2315 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
2311 | PROCFLAG.DATATYPE_SHORT, |
|
2316 | PROCFLAG.DATATYPE_SHORT, | |
2312 | PROCFLAG.DATATYPE_LONG, |
|
2317 | PROCFLAG.DATATYPE_LONG, | |
2313 | PROCFLAG.DATATYPE_INT64, |
|
2318 | PROCFLAG.DATATYPE_INT64, | |
2314 | PROCFLAG.DATATYPE_FLOAT, |
|
2319 | PROCFLAG.DATATYPE_FLOAT, | |
2315 | PROCFLAG.DATATYPE_DOUBLE] |
|
2320 | PROCFLAG.DATATYPE_DOUBLE] | |
2316 |
|
2321 | |||
2317 |
|
2322 | |||
2318 | for index in range(len(dtypeList)): |
|
2323 | for index in range(len(dtypeList)): | |
2319 | if self.dataOut.dtype == dtypeList[index]: |
|
2324 | if self.dataOut.dtype == dtypeList[index]: | |
2320 | dtypeValue = datatypeValueList[index] |
|
2325 | dtypeValue = datatypeValueList[index] | |
2321 | break |
|
2326 | break | |
2322 |
|
2327 | |||
2323 | processFlags += dtypeValue |
|
2328 | processFlags += dtypeValue | |
2324 |
|
2329 | |||
2325 | if self.dataOut.flagDecodeData: |
|
2330 | if self.dataOut.flagDecodeData: | |
2326 | processFlags += PROCFLAG.DECODE_DATA |
|
2331 | processFlags += PROCFLAG.DECODE_DATA | |
2327 |
|
2332 | |||
2328 | if self.dataOut.flagDeflipData: |
|
2333 | if self.dataOut.flagDeflipData: | |
2329 | processFlags += PROCFLAG.DEFLIP_DATA |
|
2334 | processFlags += PROCFLAG.DEFLIP_DATA | |
2330 |
|
2335 | |||
2331 | if self.dataOut.code != None: |
|
2336 | if self.dataOut.code != None: | |
2332 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
2337 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
2333 |
|
2338 | |||
2334 | if self.dataOut.nIncohInt > 1: |
|
2339 | if self.dataOut.nIncohInt > 1: | |
2335 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
2340 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
2336 |
|
2341 | |||
2337 | if self.dataOut.data_dc != None: |
|
2342 | if self.dataOut.data_dc != None: | |
2338 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
2343 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
2339 |
|
2344 | |||
2340 | return processFlags |
|
2345 | return processFlags | |
2341 |
|
2346 | |||
2342 |
|
2347 | |||
2343 | def __getBlockSize(self): |
|
2348 | def __getBlockSize(self): | |
2344 | ''' |
|
2349 | ''' | |
2345 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
2350 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
2346 | ''' |
|
2351 | ''' | |
2347 |
|
2352 | |||
2348 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2353 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2349 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2354 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2350 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2355 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2351 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2356 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2352 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2357 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2353 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2358 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2354 |
|
2359 | |||
2355 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2360 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2356 | datatypeValueList = [1,2,4,8,4,8] |
|
2361 | datatypeValueList = [1,2,4,8,4,8] | |
2357 | for index in range(len(dtypeList)): |
|
2362 | for index in range(len(dtypeList)): | |
2358 | if self.dataOut.dtype == dtypeList[index]: |
|
2363 | if self.dataOut.dtype == dtypeList[index]: | |
2359 | datatypeValue = datatypeValueList[index] |
|
2364 | datatypeValue = datatypeValueList[index] | |
2360 | break |
|
2365 | break | |
2361 |
|
2366 | |||
2362 |
|
2367 | |||
2363 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
2368 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints | |
2364 |
|
2369 | |||
2365 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
2370 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) | |
2366 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
2371 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
2367 |
|
2372 | |||
2368 | if self.dataOut.data_cspc != None: |
|
2373 | if self.dataOut.data_cspc != None: | |
2369 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
2374 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) | |
2370 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
2375 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
2371 |
|
2376 | |||
2372 | if self.dataOut.data_dc != None: |
|
2377 | if self.dataOut.data_dc != None: | |
2373 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
2378 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) | |
2374 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
2379 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
2375 |
|
2380 | |||
2376 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
2381 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
2377 |
|
2382 | |||
2378 | return blocksize |
|
2383 | return blocksize | |
2379 |
|
2384 | |||
2380 | def getDataHeader(self): |
|
2385 | def getDataHeader(self): | |
2381 |
|
2386 | |||
2382 | """ |
|
2387 | """ | |
2383 | Obtiene una copia del First Header |
|
2388 | Obtiene una copia del First Header | |
2384 |
|
2389 | |||
2385 | Affected: |
|
2390 | Affected: | |
2386 | self.systemHeaderObj |
|
2391 | self.systemHeaderObj | |
2387 | self.radarControllerHeaderObj |
|
2392 | self.radarControllerHeaderObj | |
2388 | self.dtype |
|
2393 | self.dtype | |
2389 |
|
2394 | |||
2390 | Return: |
|
2395 | Return: | |
2391 | None |
|
2396 | None | |
2392 | """ |
|
2397 | """ | |
2393 |
|
2398 | |||
2394 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
2399 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
2395 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
2400 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
2396 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
2401 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
2397 |
|
2402 | |||
2398 | self.getBasicHeader() |
|
2403 | self.getBasicHeader() | |
2399 |
|
2404 | |||
2400 | processingHeaderSize = 40 # bytes |
|
2405 | processingHeaderSize = 40 # bytes | |
2401 | self.processingHeaderObj.dtype = 0 # Voltage |
|
2406 | self.processingHeaderObj.dtype = 0 # Voltage | |
2402 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
2407 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
2403 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
2408 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints | |
2404 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
2409 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
2405 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
2410 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
2406 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
2411 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
2407 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
2412 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval | |
2408 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
2413 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
2409 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
2414 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels | |
2410 |
|
2415 | |||
2411 | if self.processingHeaderObj.totalSpectra > 0: |
|
2416 | if self.processingHeaderObj.totalSpectra > 0: | |
2412 | channelList = [] |
|
2417 | channelList = [] | |
2413 | for channel in range(self.dataOut.nChannels): |
|
2418 | for channel in range(self.dataOut.nChannels): | |
2414 | channelList.append(channel) |
|
2419 | channelList.append(channel) | |
2415 | channelList.append(channel) |
|
2420 | channelList.append(channel) | |
2416 |
|
2421 | |||
2417 | pairsList = [] |
|
2422 | pairsList = [] | |
2418 | for pair in self.dataOut.pairsList: |
|
2423 | for pair in self.dataOut.pairsList: | |
2419 | pairsList.append(pair[0]) |
|
2424 | pairsList.append(pair[0]) | |
2420 | pairsList.append(pair[1]) |
|
2425 | pairsList.append(pair[1]) | |
2421 | spectraComb = channelList + pairsList |
|
2426 | spectraComb = channelList + pairsList | |
2422 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
2427 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
2423 | self.processingHeaderObj.spectraComb = spectraComb |
|
2428 | self.processingHeaderObj.spectraComb = spectraComb | |
2424 | sizeOfSpcComb = len(spectraComb) |
|
2429 | sizeOfSpcComb = len(spectraComb) | |
2425 | processingHeaderSize += sizeOfSpcComb |
|
2430 | processingHeaderSize += sizeOfSpcComb | |
2426 |
|
2431 | |||
2427 | if self.dataOut.code != None: |
|
2432 | if self.dataOut.code != None: | |
2428 | self.processingHeaderObj.code = self.dataOut.code |
|
2433 | self.processingHeaderObj.code = self.dataOut.code | |
2429 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
2434 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
2430 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
2435 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
2431 | nCodeSize = 4 # bytes |
|
2436 | nCodeSize = 4 # bytes | |
2432 | nBaudSize = 4 # bytes |
|
2437 | nBaudSize = 4 # bytes | |
2433 | codeSize = 4 # bytes |
|
2438 | codeSize = 4 # bytes | |
2434 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
2439 | sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) | |
2435 | processingHeaderSize += sizeOfCode |
|
2440 | processingHeaderSize += sizeOfCode | |
2436 |
|
2441 | |||
2437 | if self.processingHeaderObj.nWindows != 0: |
|
2442 | if self.processingHeaderObj.nWindows != 0: | |
2438 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
2443 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
2439 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2444 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
2440 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
2445 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
2441 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
2446 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
2442 | sizeOfFirstHeight = 4 |
|
2447 | sizeOfFirstHeight = 4 | |
2443 | sizeOfdeltaHeight = 4 |
|
2448 | sizeOfdeltaHeight = 4 | |
2444 | sizeOfnHeights = 4 |
|
2449 | sizeOfnHeights = 4 | |
2445 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
2450 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
2446 | processingHeaderSize += sizeOfWindows |
|
2451 | processingHeaderSize += sizeOfWindows | |
2447 |
|
2452 | |||
2448 | self.processingHeaderObj.size = processingHeaderSize |
|
2453 | self.processingHeaderObj.size = processingHeaderSize | |
2449 |
|
2454 | |||
2450 | class SpectraHeisWriter(): |
|
2455 | class SpectraHeisWriter(): | |
2451 |
|
2456 | |||
2452 | i=0 |
|
2457 | i=0 | |
2453 |
|
2458 | |||
2454 | def __init__(self, dataOut): |
|
2459 | def __init__(self, dataOut): | |
2455 |
|
2460 | |||
2456 | self.wrObj = FITS() |
|
2461 | self.wrObj = FITS() | |
2457 | self.dataOut = dataOut |
|
2462 | self.dataOut = dataOut | |
2458 |
|
2463 | |||
2459 | def isNumber(str): |
|
2464 | def isNumber(str): | |
2460 | """ |
|
2465 | """ | |
2461 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
2466 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
2462 |
|
2467 | |||
2463 | Excepciones: |
|
2468 | Excepciones: | |
2464 | Si un determinado string no puede ser convertido a numero |
|
2469 | Si un determinado string no puede ser convertido a numero | |
2465 | Input: |
|
2470 | Input: | |
2466 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
2471 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
2467 |
|
2472 | |||
2468 | Return: |
|
2473 | Return: | |
2469 | True : si el string es uno numerico |
|
2474 | True : si el string es uno numerico | |
2470 | False : no es un string numerico |
|
2475 | False : no es un string numerico | |
2471 | """ |
|
2476 | """ | |
2472 | try: |
|
2477 | try: | |
2473 | float( str ) |
|
2478 | float( str ) | |
2474 | return True |
|
2479 | return True | |
2475 | except: |
|
2480 | except: | |
2476 | return False |
|
2481 | return False | |
2477 |
|
2482 | |||
2478 | def setup(self, wrpath,): |
|
2483 | def setup(self, wrpath,): | |
2479 |
|
2484 | |||
2480 | if not(os.path.exists(wrpath)): |
|
2485 | if not(os.path.exists(wrpath)): | |
2481 | os.mkdir(wrpath) |
|
2486 | os.mkdir(wrpath) | |
2482 |
|
2487 | |||
2483 | self.wrpath = wrpath |
|
2488 | self.wrpath = wrpath | |
2484 | self.setFile = 0 |
|
2489 | self.setFile = 0 | |
2485 |
|
2490 | |||
2486 | def putData(self): |
|
2491 | def putData(self): | |
2487 | # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints) |
|
2492 | # self.wrObj.writeHeader(nChannels=self.dataOut.nChannels, nFFTPoints=self.dataOut.nFFTPoints) | |
2488 | #name = self.dataOut.utctime |
|
2493 | #name = self.dataOut.utctime | |
2489 | name= time.localtime( self.dataOut.utctime) |
|
2494 | name= time.localtime( self.dataOut.utctime) | |
2490 | ext=".fits" |
|
2495 | ext=".fits" | |
2491 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) |
|
2496 | #folder='D%4.4d%3.3d'%(name.tm_year,name.tm_yday) | |
2492 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) |
|
2497 | subfolder = 'D%4.4d%3.3d' % (name.tm_year,name.tm_yday) | |
2493 |
|
2498 | |||
2494 | fullpath = os.path.join( self.wrpath, subfolder ) |
|
2499 | fullpath = os.path.join( self.wrpath, subfolder ) | |
2495 | if not( os.path.exists(fullpath) ): |
|
2500 | if not( os.path.exists(fullpath) ): | |
2496 | os.mkdir(fullpath) |
|
2501 | os.mkdir(fullpath) | |
2497 | self.setFile += 1 |
|
2502 | self.setFile += 1 | |
2498 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
2503 | file = 'D%4.4d%3.3d%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) | |
2499 |
|
2504 | |||
2500 | filename = os.path.join(self.wrpath,subfolder, file) |
|
2505 | filename = os.path.join(self.wrpath,subfolder, file) | |
2501 |
|
2506 | |||
2502 | # print self.dataOut.ippSeconds |
|
2507 | # print self.dataOut.ippSeconds | |
2503 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds) |
|
2508 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)/(2*self.dataOut.ippSeconds) | |
2504 |
|
2509 | |||
2505 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
2510 | col1=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) | |
2506 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:])) |
|
2511 | col2=self.wrObj.writeData(name="P_Ch1",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[0,:])) | |
2507 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:])) |
|
2512 | col3=self.wrObj.writeData(name="P_Ch2",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[1,:])) | |
2508 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:])) |
|
2513 | col4=self.wrObj.writeData(name="P_Ch3",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[2,:])) | |
2509 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:])) |
|
2514 | col5=self.wrObj.writeData(name="P_Ch4",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[3,:])) | |
2510 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:])) |
|
2515 | col6=self.wrObj.writeData(name="P_Ch5",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[4,:])) | |
2511 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:])) |
|
2516 | col7=self.wrObj.writeData(name="P_Ch6",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[5,:])) | |
2512 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:])) |
|
2517 | col8=self.wrObj.writeData(name="P_Ch7",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[6,:])) | |
2513 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:])) |
|
2518 | col9=self.wrObj.writeData(name="P_Ch8",format=str(self.dataOut.nFFTPoints)+'E',data=10*numpy.log10(self.dataOut.data_spc[7,:])) | |
2514 | #n=numpy.arange((100)) |
|
2519 | #n=numpy.arange((100)) | |
2515 | n=self.dataOut.data_spc[6,:] |
|
2520 | n=self.dataOut.data_spc[6,:] | |
2516 | a=self.wrObj.cFImage(n) |
|
2521 | a=self.wrObj.cFImage(n) | |
2517 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) |
|
2522 | b=self.wrObj.Ctable(col1,col2,col3,col4,col5,col6,col7,col8,col9) | |
2518 | self.wrObj.CFile(a,b) |
|
2523 | self.wrObj.CFile(a,b) | |
2519 | self.wrObj.wFile(filename) |
|
2524 | self.wrObj.wFile(filename) | |
2520 | return 1 |
|
2525 | return 1 | |
2521 |
|
2526 | |||
2522 | class FITS: |
|
2527 | class FITS: | |
2523 |
|
2528 | |||
2524 | name=None |
|
2529 | name=None | |
2525 | format=None |
|
2530 | format=None | |
2526 | array =None |
|
2531 | array =None | |
2527 | data =None |
|
2532 | data =None | |
2528 | thdulist=None |
|
2533 | thdulist=None | |
2529 |
|
2534 | |||
2530 | def __init__(self): |
|
2535 | def __init__(self): | |
2531 |
|
2536 | |||
2532 | pass |
|
2537 | pass | |
2533 |
|
2538 | |||
2534 | def setColF(self,name,format,array): |
|
2539 | def setColF(self,name,format,array): | |
2535 | self.name=name |
|
2540 | self.name=name | |
2536 | self.format=format |
|
2541 | self.format=format | |
2537 | self.array=array |
|
2542 | self.array=array | |
2538 | a1=numpy.array([self.array],dtype=numpy.float32) |
|
2543 | a1=numpy.array([self.array],dtype=numpy.float32) | |
2539 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) |
|
2544 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
2540 | return self.col1 |
|
2545 | return self.col1 | |
2541 |
|
2546 | |||
2542 | # def setColP(self,name,format,data): |
|
2547 | # def setColP(self,name,format,data): | |
2543 | # self.name=name |
|
2548 | # self.name=name | |
2544 | # self.format=format |
|
2549 | # self.format=format | |
2545 | # self.data=data |
|
2550 | # self.data=data | |
2546 | # a2=numpy.array([self.data],dtype=numpy.float32) |
|
2551 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
2547 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2552 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2548 | # return self.col2 |
|
2553 | # return self.col2 | |
2549 |
|
2554 | |||
2550 | def writeHeader(self,): |
|
2555 | def writeHeader(self,): | |
2551 | pass |
|
2556 | pass | |
2552 |
|
2557 | |||
2553 | def writeData(self,name,format,data): |
|
2558 | def writeData(self,name,format,data): | |
2554 | self.name=name |
|
2559 | self.name=name | |
2555 | self.format=format |
|
2560 | self.format=format | |
2556 | self.data=data |
|
2561 | self.data=data | |
2557 | a2=numpy.array([self.data],dtype=numpy.float32) |
|
2562 | a2=numpy.array([self.data],dtype=numpy.float32) | |
2558 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2563 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2559 | return self.col2 |
|
2564 | return self.col2 | |
2560 |
|
2565 | |||
2561 | def cFImage(self,n): |
|
2566 | def cFImage(self,n): | |
2562 | self.hdu= pyfits.PrimaryHDU(n) |
|
2567 | self.hdu= pyfits.PrimaryHDU(n) | |
2563 | return self.hdu |
|
2568 | return self.hdu | |
2564 |
|
2569 | |||
2565 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): |
|
2570 | def Ctable(self,col1,col2,col3,col4,col5,col6,col7,col8,col9): | |
2566 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) |
|
2571 | self.cols=pyfits.ColDefs( [col1,col2,col3,col4,col5,col6,col7,col8,col9]) | |
2567 | self.tbhdu = pyfits.new_table(self.cols) |
|
2572 | self.tbhdu = pyfits.new_table(self.cols) | |
2568 | return self.tbhdu |
|
2573 | return self.tbhdu | |
2569 |
|
2574 | |||
2570 | def CFile(self,hdu,tbhdu): |
|
2575 | def CFile(self,hdu,tbhdu): | |
2571 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) |
|
2576 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
2572 |
|
2577 | |||
2573 | def wFile(self,filename): |
|
2578 | def wFile(self,filename): | |
2574 | self.thdulist.writeto(filename) No newline at end of file |
|
2579 | self.thdulist.writeto(filename) |
General Comments 0
You need to be logged in to leave comments.
Login now