@@ -1,30 +1,19 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | from jroIO_voltage import * |
|
8 | 8 | from jroIO_spectra import * |
|
9 | 9 | from jroIO_heispectra import * |
|
10 | 10 | from jroIO_usrp import * |
|
11 | 11 | |
|
12 | 12 | # try: |
|
13 | 13 | # from jroIO_usrp_api import * |
|
14 | 14 | # except: |
|
15 | 15 | # print "jroIO_usrp_api could not be imported" |
|
16 | 16 | |
|
17 | try: | |
|
18 | 17 |
|
|
19 | except: | |
|
20 | print "jroIO_amisr could not be imported" | |
|
21 | ||
|
22 | try: | |
|
23 | 18 |
|
|
24 | except: | |
|
25 | print "jroIO_HDF5 could not be imported" | |
|
26 | ||
|
27 | try: | |
|
28 | 19 |
|
|
No newline at end of file | ||
|
29 | except: | |
|
30 | print "jroIO_hf could not be imported" No newline at end of file |
@@ -1,868 +1,867 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 3, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-com0419 |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os,sys |
|
8 | 8 | import time,datetime |
|
9 | 9 | import h5py |
|
10 | 10 | import numpy |
|
11 | 11 | import fnmatch |
|
12 | 12 | import re |
|
13 | import stuffr | |
|
14 | 13 | |
|
15 | from model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
|
16 | from model.data.jrodata import Voltage | |
|
17 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
|
14 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
|
15 | from schainpy.model.data.jrodata import Voltage | |
|
16 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
18 | 17 | |
|
19 | 18 | |
|
20 | 19 | def isNumber(str): |
|
21 | 20 | """ |
|
22 | 21 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
23 | 22 | |
|
24 | 23 | Excepciones: |
|
25 | 24 | Si un determinado string no puede ser convertido a numero |
|
26 | 25 | Input: |
|
27 | 26 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
28 | 27 | |
|
29 | 28 | Return: |
|
30 | 29 | True : si el string es uno numerico |
|
31 | 30 | False : no es un string numerico |
|
32 | 31 | """ |
|
33 | 32 | try: |
|
34 | 33 | float( str ) |
|
35 | 34 | return True |
|
36 | 35 | except: |
|
37 | 36 | return False |
|
38 | 37 | |
|
39 | 38 | def getFileFromSet(path, ext, set=None): |
|
40 | 39 | validFilelist = [] |
|
41 | 40 | fileList = os.listdir(path) |
|
42 | 41 | |
|
43 | 42 | |
|
44 | 43 | if len(fileList) < 1: |
|
45 | 44 | return None |
|
46 | 45 | |
|
47 | 46 | # 0 1234 567 89A BCDE |
|
48 | 47 | # H YYYY DDD SSS .ext |
|
49 | 48 | |
|
50 | 49 | for thisFile in fileList: |
|
51 | 50 | try: |
|
52 | 51 | number= int(thisFile[6:16]) |
|
53 | 52 | |
|
54 | 53 | # year = int(thisFile[1:5]) |
|
55 | 54 | # doy = int(thisFile[5:8]) |
|
56 | 55 | except: |
|
57 | 56 | continue |
|
58 | 57 | |
|
59 | 58 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
60 | 59 | continue |
|
61 | 60 | |
|
62 | 61 | validFilelist.append(thisFile) |
|
63 | 62 | |
|
64 | 63 | if len(validFilelist) < 1: |
|
65 | 64 | return None |
|
66 | 65 | |
|
67 | 66 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
68 | 67 | |
|
69 | 68 | if set == None: |
|
70 | 69 | return validFilelist[-1] |
|
71 | 70 | |
|
72 | 71 | print "set =" ,set |
|
73 | 72 | for thisFile in validFilelist: |
|
74 | 73 | if set <= int(thisFile[6:16]): |
|
75 | 74 | print thisFile,int(thisFile[6:16]) |
|
76 | 75 | return thisFile |
|
77 | 76 | |
|
78 | 77 | return validFilelist[-1] |
|
79 | 78 | |
|
80 | 79 | myfile = fnmatch.filter(validFilelist,'*%10d*'%(set)) |
|
81 | 80 | #myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set)) |
|
82 | 81 | |
|
83 | 82 | if len(myfile)!= 0: |
|
84 | 83 | return myfile[0] |
|
85 | 84 | else: |
|
86 | 85 | filename = '*%10.10d%s'%(set,ext.lower()) |
|
87 | 86 | print 'the filename %s does not exist'%filename |
|
88 | 87 | print '...going to the last file: ' |
|
89 | 88 | |
|
90 | 89 | if validFilelist: |
|
91 | 90 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
92 | 91 | return validFilelist[-1] |
|
93 | 92 | |
|
94 | 93 | return None |
|
95 | 94 | |
|
96 | 95 | def getlastFileFromPath(path, ext): |
|
97 | 96 | """ |
|
98 | 97 | Depura el fileList dejando solo los que cumplan el formato de "res-xxxxxx.ext" |
|
99 | 98 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
100 | 99 | |
|
101 | 100 | Input: |
|
102 | 101 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
103 | 102 | ext : extension de los files contenidos en una carpeta |
|
104 | 103 | |
|
105 | 104 | Return: |
|
106 | 105 | El ultimo file de una determinada carpeta, no se considera el path. |
|
107 | 106 | """ |
|
108 | 107 | validFilelist = [] |
|
109 | 108 | fileList = os.listdir(path) |
|
110 | 109 | |
|
111 | 110 | # 0 1234 567 89A BCDE |
|
112 | 111 | # H YYYY DDD SSS .ext |
|
113 | 112 | |
|
114 | 113 | for thisFile in fileList: |
|
115 | 114 | |
|
116 | 115 | try: |
|
117 | 116 | number= int(thisFile[6:16]) |
|
118 | 117 | except: |
|
119 | 118 | print "There is a file or folder with different format" |
|
120 | 119 | if not isNumber(number): |
|
121 | 120 | continue |
|
122 | 121 | |
|
123 | 122 | # year = thisFile[1:5] |
|
124 | 123 | # if not isNumber(year): |
|
125 | 124 | # continue |
|
126 | 125 | |
|
127 | 126 | # doy = thisFile[5:8] |
|
128 | 127 | # if not isNumber(doy): |
|
129 | 128 | # continue |
|
130 | 129 | |
|
131 | 130 | number= int(number) |
|
132 | 131 | # year = int(year) |
|
133 | 132 | # doy = int(doy) |
|
134 | 133 | |
|
135 | 134 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
136 | 135 | continue |
|
137 | 136 | |
|
138 | 137 | |
|
139 | 138 | validFilelist.append(thisFile) |
|
140 | 139 | |
|
141 | 140 | |
|
142 | 141 | if validFilelist: |
|
143 | 142 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
144 | 143 | return validFilelist[-1] |
|
145 | 144 | |
|
146 | 145 | return None |
|
147 | 146 | |
|
148 | 147 | |
|
149 | 148 | |
|
150 | 149 | class HFReader(ProcessingUnit): |
|
151 | 150 | ''' |
|
152 | 151 | classdocs |
|
153 | 152 | ''' |
|
154 | 153 | path = None |
|
155 | 154 | startDate= None |
|
156 | 155 | endDate = None |
|
157 | 156 | startTime= None |
|
158 | 157 | endTime = None |
|
159 | 158 | walk = None |
|
160 | 159 | isConfig = False |
|
161 | 160 | dataOut=None |
|
162 | 161 | nTries = 3 |
|
163 | 162 | ext = ".hdf5" |
|
164 | 163 | |
|
165 | 164 | def __init__(self): |
|
166 | 165 | ''' |
|
167 | 166 | Constructor |
|
168 | 167 | ''' |
|
169 | 168 | ProcessingUnit.__init__(self) |
|
170 | 169 | |
|
171 | 170 | self.isConfig =False |
|
172 | 171 | |
|
173 | 172 | self.datablock = None |
|
174 | 173 | |
|
175 | 174 | self.filename_current=None |
|
176 | 175 | |
|
177 | 176 | self.utc = 0 |
|
178 | 177 | |
|
179 | 178 | self.ext='.hdf5' |
|
180 | 179 | |
|
181 | 180 | self.flagIsNewFile = 1 |
|
182 | 181 | |
|
183 | 182 | #------------------------------------------------- |
|
184 | 183 | self.fileIndex=None |
|
185 | 184 | |
|
186 | 185 | self.profileIndex_offset=None |
|
187 | 186 | |
|
188 | 187 | self.filenameList=[] |
|
189 | 188 | |
|
190 | 189 | self.hfFilePointer= None |
|
191 | 190 | |
|
192 | 191 | self.filename_online = None |
|
193 | 192 | |
|
194 | 193 | self.status=True |
|
195 | 194 | |
|
196 | 195 | self.flagNoMoreFiles= False |
|
197 | 196 | |
|
198 | 197 | self.__waitForNewFile = 20 |
|
199 | 198 | |
|
200 | 199 | |
|
201 | 200 | #-------------------------------------------------- |
|
202 | 201 | |
|
203 | 202 | self.dataOut = self.createObjByDefault() |
|
204 | 203 | |
|
205 | 204 | |
|
206 | 205 | def createObjByDefault(self): |
|
207 | 206 | |
|
208 | 207 | dataObj = Voltage() |
|
209 | 208 | |
|
210 | 209 | return dataObj |
|
211 | 210 | |
|
212 | 211 | def setObjProperties(self): |
|
213 | 212 | |
|
214 | 213 | pass |
|
215 | 214 | |
|
216 | 215 | def getBlockDimension(self): |
|
217 | 216 | """ |
|
218 | 217 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
219 | 218 | |
|
220 | 219 | Affected: |
|
221 | 220 | self.blocksize |
|
222 | 221 | |
|
223 | 222 | Return: |
|
224 | 223 | None |
|
225 | 224 | """ |
|
226 | 225 | pts2read =self.nChannels*self.nHeights*self.nProfiles |
|
227 | 226 | self.blocksize = pts2read |
|
228 | 227 | |
|
229 | 228 | def __readHeader(self): |
|
230 | 229 | |
|
231 | 230 | self.nProfiles = 100 |
|
232 | 231 | self.nHeights = 1000 |
|
233 | 232 | self.nChannels = 2 |
|
234 | 233 | self.__firstHeigth=0 |
|
235 | 234 | self.__nSamples=1000 |
|
236 | 235 | self.__deltaHeigth=1.5 |
|
237 | 236 | self.__sample_rate=1e5 |
|
238 | 237 | #self.__frequency=2.72e6 |
|
239 | 238 | #self.__frequency=3.64e6 |
|
240 | 239 | self.__frequency=None |
|
241 | 240 | self.__online = False |
|
242 | 241 | self.filename_next_set=None |
|
243 | 242 | |
|
244 | 243 | #print "Frequency of Operation:", self.__frequency |
|
245 | 244 | |
|
246 | 245 | |
|
247 | 246 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): |
|
248 | 247 | self.path = path |
|
249 | 248 | self.startDate = startDate |
|
250 | 249 | self.endDate = endDate |
|
251 | 250 | self.startTime = startTime |
|
252 | 251 | self.endTime = endTime |
|
253 | 252 | self.walk = walk |
|
254 | 253 | |
|
255 | 254 | def __checkPath(self): |
|
256 | 255 | if os.path.exists(self.path): |
|
257 | 256 | self.status=1 |
|
258 | 257 | else: |
|
259 | 258 | self.status=0 |
|
260 | 259 | print 'Path %s does not exits'%self.path |
|
261 | 260 | return |
|
262 | 261 | return |
|
263 | 262 | |
|
264 | 263 | def __selDates(self, hf_dirname_format): |
|
265 | 264 | try: |
|
266 | 265 | dir_hf_filename= self.path+"/"+hf_dirname_format |
|
267 | 266 | fp= h5py.File(dir_hf_filename,'r') |
|
268 | 267 | hipoc=fp['t'].value |
|
269 | 268 | fp.close() |
|
270 |
date_time= |
|
|
269 | date_time=datetime.datetime.utcfromtimestamp(hipoc) | |
|
271 | 270 | year =int(date_time[0:4]) |
|
272 | 271 | month=int(date_time[5:7]) |
|
273 | 272 | dom =int(date_time[8:10]) |
|
274 | 273 | thisDate= datetime.date(year,month,dom) |
|
275 | 274 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
276 | 275 | return hf_dirname_format |
|
277 | 276 | except: |
|
278 | 277 | return None |
|
279 | 278 | |
|
280 | 279 | def __findDataForDates(self,online=False): |
|
281 | 280 | if not(self.status): |
|
282 | 281 | return None |
|
283 | 282 | |
|
284 | 283 | pat = '\d+.\d+' |
|
285 | 284 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] |
|
286 | 285 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
287 | 286 | dirnameList = [x.string for x in dirnameList] |
|
288 | 287 | if not(online): |
|
289 | 288 | |
|
290 | 289 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
291 | 290 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
292 | 291 | |
|
293 | 292 | if len(dirnameList)>0: |
|
294 | 293 | self.status = 1 |
|
295 | 294 | self.dirnameList = dirnameList |
|
296 | 295 | self.dirnameList.sort() |
|
297 | 296 | |
|
298 | 297 | else: |
|
299 | 298 | self.status = 0 |
|
300 | 299 | return None |
|
301 | 300 | |
|
302 | 301 | def __getTimeFromData(self): |
|
303 | 302 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) |
|
304 | 303 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
305 | 304 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) |
|
306 | 305 | print '........................................' |
|
307 | 306 | filter_filenameList=[] |
|
308 | 307 | self.filenameList.sort() |
|
309 | 308 | for i in range(len(self.filenameList)-1): |
|
310 | 309 | filename=self.filenameList[i] |
|
311 | 310 | dir_hf_filename= filename |
|
312 | 311 | fp= h5py.File(dir_hf_filename,'r') |
|
313 | 312 | hipoc=fp['t'].value |
|
314 | 313 | hipoc=hipoc+self.timezone |
|
315 |
date_time= |
|
|
314 | date_time=datetime.datetime.utcfromtimestamp(hipoc) | |
|
316 | 315 | fp.close() |
|
317 | 316 | year =int(date_time[0:4]) |
|
318 | 317 | month=int(date_time[5:7]) |
|
319 | 318 | dom =int(date_time[8:10]) |
|
320 | 319 | hour =int(date_time[11:13]) |
|
321 | 320 | min =int(date_time[14:16]) |
|
322 | 321 | sec =int(date_time[17:19]) |
|
323 | 322 | this_time=datetime.datetime(year,month,dom,hour,min,sec) |
|
324 | 323 | if (this_time>=startDateTime_Reader and this_time <= endDateTime_Reader): |
|
325 | 324 | filter_filenameList.append(filename) |
|
326 | 325 | filter_filenameList.sort() |
|
327 | 326 | self.filenameList = filter_filenameList |
|
328 | 327 | return 1 |
|
329 | 328 | |
|
330 | 329 | def __getFilenameList(self): |
|
331 | 330 | #print "hola" |
|
332 | 331 | #print self.dirnameList |
|
333 | 332 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
334 | 333 | self.filenameList= dirList |
|
335 | 334 | #print self.filenameList |
|
336 | 335 | #print "pase",len(self.filenameList) |
|
337 | 336 | |
|
338 | 337 | def __selectDataForTimes(self, online=False): |
|
339 | 338 | |
|
340 | 339 | if not(self.status): |
|
341 | 340 | return None |
|
342 | 341 | #---------------- |
|
343 | 342 | self.__getFilenameList() |
|
344 | 343 | #---------------- |
|
345 | 344 | if not(online): |
|
346 | 345 | if not(self.all): |
|
347 | 346 | self.__getTimeFromData() |
|
348 | 347 | if len(self.filenameList)>0: |
|
349 | 348 | self.status=1 |
|
350 | 349 | self.filenameList.sort() |
|
351 | 350 | else: |
|
352 | 351 | self.status=0 |
|
353 | 352 | return None |
|
354 | 353 | else: |
|
355 | 354 | if self.set != None: |
|
356 | 355 | |
|
357 | 356 | filename=getFileFromSet(self.path,self.ext,self.set) |
|
358 | 357 | |
|
359 | 358 | if self.flag_nextfile==True: |
|
360 | 359 | self.dirnameList=[filename] |
|
361 | 360 | fullfilename=self.path+"/"+filename |
|
362 | 361 | self.filenameList=[fullfilename] |
|
363 | 362 | self.filename_next_set=int(filename[6:16])+10 |
|
364 | 363 | |
|
365 | 364 | self.flag_nextfile=False |
|
366 | 365 | else: |
|
367 | 366 | print filename |
|
368 | 367 | print "PRIMERA CONDICION" |
|
369 | 368 | #if self.filename_next_set== int(filename[6:16]): |
|
370 | 369 | print "TODO BIEN" |
|
371 | 370 | |
|
372 | 371 | if filename == None: |
|
373 | 372 | raise ValueError, "corregir" |
|
374 | 373 | |
|
375 | 374 | self.dirnameList=[filename] |
|
376 | 375 | fullfilename=self.path+"/"+filename |
|
377 | 376 | self.filenameList=[fullfilename] |
|
378 | 377 | self.filename_next_set=int(filename[6:16])+10 |
|
379 | 378 | print "Setting next file",self.filename_next_set |
|
380 | 379 | self.set=int(filename[6:16]) |
|
381 | 380 | if True: |
|
382 | 381 | pass |
|
383 | 382 | else: |
|
384 | 383 | print "ESTOY AQUI PORQUE NO EXISTE EL SIGUIENTE ARCHIVO" |
|
385 | 384 | |
|
386 | 385 | else: |
|
387 | 386 | filename =getlastFileFromPath(self.path,self.ext) |
|
388 | 387 | |
|
389 | 388 | if self.flag_nextfile==True: |
|
390 | 389 | self.dirnameList=[filename] |
|
391 | 390 | fullfilename=self.path+"/"+filename |
|
392 | 391 | self.filenameList=[self.filenameList[-1]] |
|
393 | 392 | self.filename_next_set=int(filename[6:16])+10 |
|
394 | 393 | |
|
395 | 394 | self.flag_nextfile=False |
|
396 | 395 | else: |
|
397 | 396 | filename=getFileFromSet(self.path,self.ext,self.set) |
|
398 | 397 | print filename |
|
399 | 398 | print "PRIMERA CONDICION" |
|
400 | 399 | #if self.filename_next_set== int(filename[6:16]): |
|
401 | 400 | print "TODO BIEN" |
|
402 | 401 | |
|
403 | 402 | if filename == None: |
|
404 | 403 | raise ValueError, "corregir" |
|
405 | 404 | |
|
406 | 405 | self.dirnameList=[filename] |
|
407 | 406 | fullfilename=self.path+"/"+filename |
|
408 | 407 | self.filenameList=[fullfilename] |
|
409 | 408 | self.filename_next_set=int(filename[6:16])+10 |
|
410 | 409 | print "Setting next file",self.filename_next_set |
|
411 | 410 | self.set=int(filename[6:16]) |
|
412 | 411 | if True: |
|
413 | 412 | pass |
|
414 | 413 | else: |
|
415 | 414 | print "ESTOY AQUI PORQUE NO EXISTE EL SIGUIENTE ARCHIVO" |
|
416 | 415 | |
|
417 | 416 | |
|
418 | 417 | |
|
419 | 418 | def __searchFilesOffline(self, |
|
420 | 419 | path, |
|
421 | 420 | startDate, |
|
422 | 421 | endDate, |
|
423 | 422 | ext, |
|
424 | 423 | startTime=datetime.time(0,0,0), |
|
425 | 424 | endTime=datetime.time(23,59,59), |
|
426 | 425 | walk=True): |
|
427 | 426 | |
|
428 | 427 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
429 | 428 | |
|
430 | 429 | self.__checkPath() |
|
431 | 430 | |
|
432 | 431 | self.__findDataForDates() |
|
433 | 432 | #print self.dirnameList |
|
434 | 433 | |
|
435 | 434 | self.__selectDataForTimes() |
|
436 | 435 | |
|
437 | 436 | for i in range(len(self.filenameList)): |
|
438 | 437 | print "%s"% (self.filenameList[i]) |
|
439 | 438 | |
|
440 | 439 | return |
|
441 | 440 | |
|
442 | 441 | def __searchFilesOnline(self, |
|
443 | 442 | path, |
|
444 | 443 | expLabel= "", |
|
445 | 444 | ext=None, |
|
446 | 445 | startDate=None, |
|
447 | 446 | endDate=None, |
|
448 | 447 | walk=True, |
|
449 | 448 | set=None): |
|
450 | 449 | |
|
451 | 450 | |
|
452 | 451 | startDate = datetime.datetime.utcnow().date() |
|
453 | 452 | endDate = datetime.datetime.utcnow().date() |
|
454 | 453 | |
|
455 | 454 | self.__setParameters(path=path,startDate=startDate,endDate=endDate,walk=walk) |
|
456 | 455 | |
|
457 | 456 | self.__checkPath() |
|
458 | 457 | |
|
459 | 458 | fullpath=path |
|
460 | 459 | print "%s folder was found: " %(fullpath ) |
|
461 | 460 | |
|
462 | 461 | if set == None: |
|
463 | 462 | self.set=None |
|
464 | 463 | filename =getlastFileFromPath(fullpath,ext) |
|
465 | 464 | startDate= datetime.datetime.utcnow().date |
|
466 | 465 | endDate= datetime.datetime.utcnow().date() |
|
467 | 466 | # |
|
468 | 467 | else: |
|
469 | 468 | filename= getFileFromSet(fullpath,ext,set) |
|
470 | 469 | startDate=None |
|
471 | 470 | endDate=None |
|
472 | 471 | # |
|
473 | 472 | if not (filename): |
|
474 | 473 | return None,None,None,None,None |
|
475 | 474 | #print "%s file was found" %(filename) |
|
476 | 475 | |
|
477 | 476 | # |
|
478 | 477 | # dir_hf_filename= self.path+"/"+filename |
|
479 | 478 | # fp= h5py.File(dir_hf_filename,'r') |
|
480 | 479 | # hipoc=fp['t'].value |
|
481 | 480 | # fp.close() |
|
482 |
# date_time= |
|
|
481 | # date_time=datetime.datetime.utcfromtimestamp(hipoc) | |
|
483 | 482 | # |
|
484 | 483 | # year =int(date_time[0:4]) |
|
485 | 484 | # month=int(date_time[5:7]) |
|
486 | 485 | # dom =int(date_time[8:10]) |
|
487 | 486 | # set= int(filename[4:10]) |
|
488 | 487 | # self.set=set-1 |
|
489 | 488 | #self.dirnameList=[filename] |
|
490 | 489 | filenameList= fullpath+"/"+filename |
|
491 | 490 | self.dirnameList=[filename] |
|
492 | 491 | self.filenameList=[filenameList] |
|
493 | 492 | self.flag_nextfile=True |
|
494 | 493 | |
|
495 | 494 | #self.__findDataForDates(online=True) |
|
496 | 495 | #self.dirnameList=[self.dirnameList[-1]] |
|
497 | 496 | #print self.dirnameList |
|
498 | 497 | #self.__selectDataForTimes(online=True) |
|
499 | 498 | #return fullpath,filename,year,month,dom,set |
|
500 | 499 | return |
|
501 | 500 | |
|
502 | 501 | def __setNextFile(self,online=False): |
|
503 | 502 | """ |
|
504 | 503 | """ |
|
505 | 504 | if not(online): |
|
506 | 505 | newFile = self.__setNextFileOffline() |
|
507 | 506 | else: |
|
508 | 507 | newFile = self.__setNextFileOnline() |
|
509 | 508 | |
|
510 | 509 | if not(newFile): |
|
511 | 510 | return 0 |
|
512 | 511 | return 1 |
|
513 | 512 | |
|
514 | 513 | def __setNextFileOffline(self): |
|
515 | 514 | """ |
|
516 | 515 | """ |
|
517 | 516 | idFile= self.fileIndex |
|
518 | 517 | while(True): |
|
519 | 518 | idFile += 1 |
|
520 | 519 | if not (idFile < len(self.filenameList)): |
|
521 | 520 | self.flagNoMoreFiles = 1 |
|
522 | 521 | print "No more Files" |
|
523 | 522 | return 0 |
|
524 | 523 | filename = self.filenameList[idFile] |
|
525 | 524 | hfFilePointer =h5py.File(filename,'r') |
|
526 | 525 | |
|
527 | 526 | epoc=hfFilePointer['t'].value |
|
528 | 527 | #this_time=datetime.datetime(year,month,dom,hour,min,sec) |
|
529 | 528 | break |
|
530 | 529 | |
|
531 | 530 | self.flagIsNewFile = 1 |
|
532 | 531 | self.fileIndex = idFile |
|
533 | 532 | self.filename = filename |
|
534 | 533 | |
|
535 | 534 | self.hfFilePointer = hfFilePointer |
|
536 | 535 | hfFilePointer.close() |
|
537 | 536 | self.__t0=epoc |
|
538 | 537 | print "Setting the file: %s"%self.filename |
|
539 | 538 | |
|
540 | 539 | return 1 |
|
541 | 540 | |
|
542 | 541 | def __setNextFileOnline(self): |
|
543 | 542 | """ |
|
544 | 543 | """ |
|
545 | 544 | print "SOY NONE",self.set |
|
546 | 545 | if self.set==None: |
|
547 | 546 | pass |
|
548 | 547 | else: |
|
549 | 548 | self.set +=10 |
|
550 | 549 | |
|
551 | 550 | filename = self.filenameList[0]#fullfilename |
|
552 | 551 | if self.filename_online != None: |
|
553 | 552 | self.__selectDataForTimes(online=True) |
|
554 | 553 | filename = self.filenameList[0] |
|
555 | 554 | while self.filename_online == filename: |
|
556 | 555 | print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) |
|
557 | 556 | time.sleep(self.__waitForNewFile) |
|
558 | 557 | #self.__findDataForDates(online=True) |
|
559 | 558 | self.set=self.filename_next_set |
|
560 | 559 | self.__selectDataForTimes(online=True) |
|
561 | 560 | filename = self.filenameList[0] |
|
562 | 561 | sizeoffile=os.path.getsize(filename) |
|
563 | 562 | |
|
564 | 563 | #print filename |
|
565 | 564 | sizeoffile=os.path.getsize(filename) |
|
566 | 565 | if sizeoffile<1670240: |
|
567 | 566 | print "%s is not the rigth size"%filename |
|
568 | 567 | delay=50 |
|
569 | 568 | print 'waiting %d seconds for delay...'%(delay) |
|
570 | 569 | time.sleep(delay) |
|
571 | 570 | sizeoffile=os.path.getsize(filename) |
|
572 | 571 | if sizeoffile<1670240: |
|
573 | 572 | delay=50 |
|
574 | 573 | print 'waiting %d more seconds for delay...'%(delay) |
|
575 | 574 | time.sleep(delay) |
|
576 | 575 | |
|
577 | 576 | sizeoffile=os.path.getsize(filename) |
|
578 | 577 | if sizeoffile<1670240: |
|
579 | 578 | delay=50 |
|
580 | 579 | print 'waiting %d more seconds for delay...'%(delay) |
|
581 | 580 | time.sleep(delay) |
|
582 | 581 | |
|
583 | 582 | try: |
|
584 | 583 | hfFilePointer=h5py.File(filename,'r') |
|
585 | 584 | |
|
586 | 585 | except: |
|
587 | 586 | print "Error reading file %s"%filename |
|
588 | 587 | |
|
589 | 588 | self.filename_online=filename |
|
590 | 589 | epoc=hfFilePointer['t'].value |
|
591 | 590 | |
|
592 | 591 | self.hfFilePointer=hfFilePointer |
|
593 | 592 | hfFilePointer.close() |
|
594 | 593 | self.__t0=epoc |
|
595 | 594 | |
|
596 | 595 | |
|
597 | 596 | self.flagIsNewFile = 1 |
|
598 | 597 | self.filename = filename |
|
599 | 598 | |
|
600 | 599 | print "Setting the file: %s"%self.filename |
|
601 | 600 | return 1 |
|
602 | 601 | |
|
603 | 602 | def __getExpParameters(self): |
|
604 | 603 | if not(self.status): |
|
605 | 604 | return None |
|
606 | 605 | |
|
607 | 606 | def setup(self, |
|
608 | 607 | path = None, |
|
609 | 608 | startDate = None, |
|
610 | 609 | endDate = None, |
|
611 | 610 | startTime = datetime.time(0,0,0), |
|
612 | 611 | endTime = datetime.time(23,59,59), |
|
613 | 612 | set = None, |
|
614 | 613 | expLabel = "", |
|
615 | 614 | ext = None, |
|
616 | 615 | all=0, |
|
617 | 616 | timezone=0, |
|
618 | 617 | online = False, |
|
619 | 618 | delay = 60, |
|
620 | 619 | walk = True): |
|
621 | 620 | ''' |
|
622 | 621 | In this method we should set all initial parameters. |
|
623 | 622 | |
|
624 | 623 | ''' |
|
625 | 624 | if path==None: |
|
626 | 625 | raise ValueError,"The path is not valid" |
|
627 | 626 | |
|
628 | 627 | if ext==None: |
|
629 | 628 | ext = self.ext |
|
630 | 629 | |
|
631 | 630 | self.timezone= timezone |
|
632 | 631 | self.online= online |
|
633 | 632 | self.all=all |
|
634 | 633 | #if set==None: |
|
635 | 634 | |
|
636 | 635 | #print set |
|
637 | 636 | if not(online): |
|
638 | 637 | print "Searching files in offline mode..." |
|
639 | 638 | |
|
640 | 639 | self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, walk) |
|
641 | 640 | else: |
|
642 | 641 | print "Searching files in online mode..." |
|
643 | 642 | self.__searchFilesOnline(path, walk,ext,set=set) |
|
644 | 643 | if set==None: |
|
645 | 644 | pass |
|
646 | 645 | else: |
|
647 | 646 | self.set=set-10 |
|
648 | 647 | |
|
649 | 648 | # for nTries in range(self.nTries): |
|
650 | 649 | # |
|
651 | 650 | # fullpath,file,year,month,day,set = self.__searchFilesOnline(path=path,expLabel=expLabel,ext=ext, walk=walk,set=set) |
|
652 | 651 | # |
|
653 | 652 | # if fullpath: |
|
654 | 653 | # break |
|
655 | 654 | # print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
656 | 655 | # time.sleep(self.delay) |
|
657 | 656 | # if not(fullpath): |
|
658 | 657 | # print "There ins't valid files in %s" % path |
|
659 | 658 | # return None |
|
660 | 659 | |
|
661 | 660 | |
|
662 | 661 | if not(self.filenameList): |
|
663 | 662 | print "There is no files into the folder: %s"%(path) |
|
664 | 663 | sys.exit(-1) |
|
665 | 664 | |
|
666 | 665 | self.__getExpParameters() |
|
667 | 666 | |
|
668 | 667 | |
|
669 | 668 | self.fileIndex = -1 |
|
670 | 669 | |
|
671 | 670 | self.__setNextFile(online) |
|
672 | 671 | |
|
673 | 672 | self.__readMetadata() |
|
674 | 673 | |
|
675 | 674 | self.__setLocalVariables() |
|
676 | 675 | |
|
677 | 676 | self.__setHeaderDO() |
|
678 | 677 | #self.profileIndex_offset= 0 |
|
679 | 678 | |
|
680 | 679 | #self.profileIndex = self.profileIndex_offset |
|
681 | 680 | |
|
682 | 681 | self.isConfig = True |
|
683 | 682 | |
|
684 | 683 | def __readMetadata(self): |
|
685 | 684 | self.__readHeader() |
|
686 | 685 | |
|
687 | 686 | |
|
688 | 687 | def __setLocalVariables(self): |
|
689 | 688 | |
|
690 | 689 | self.datablock = numpy.zeros((self.nChannels, self.nHeights,self.nProfiles), dtype = numpy.complex) |
|
691 | 690 | # |
|
692 | 691 | |
|
693 | 692 | |
|
694 | 693 | |
|
695 | 694 | self.profileIndex = 9999 |
|
696 | 695 | |
|
697 | 696 | |
|
698 | 697 | def __setHeaderDO(self): |
|
699 | 698 | |
|
700 | 699 | |
|
701 | 700 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader() |
|
702 | 701 | |
|
703 | 702 | self.dataOut.systemHeaderObj = SystemHeader() |
|
704 | 703 | |
|
705 | 704 | |
|
706 | 705 | #--------------------------------------------------------- |
|
707 | 706 | self.dataOut.systemHeaderObj.nProfiles=100 |
|
708 | 707 | self.dataOut.systemHeaderObj.nSamples=1000 |
|
709 | 708 | |
|
710 | 709 | |
|
711 | 710 | SAMPLING_STRUCTURE=[('h0', '<f4'), ('dh', '<f4'), ('nsa', '<u4')] |
|
712 | 711 | self.dataOut.radarControllerHeaderObj.samplingWindow=numpy.zeros((1,),SAMPLING_STRUCTURE) |
|
713 | 712 | self.dataOut.radarControllerHeaderObj.samplingWindow['h0']=0 |
|
714 | 713 | self.dataOut.radarControllerHeaderObj.samplingWindow['dh']=1.5 |
|
715 | 714 | self.dataOut.radarControllerHeaderObj.samplingWindow['nsa']=1000 |
|
716 | 715 | self.dataOut.radarControllerHeaderObj.nHeights=int(self.dataOut.radarControllerHeaderObj.samplingWindow['nsa']) |
|
717 | 716 | self.dataOut.radarControllerHeaderObj.firstHeight = self.dataOut.radarControllerHeaderObj.samplingWindow['h0'] |
|
718 | 717 | self.dataOut.radarControllerHeaderObj.deltaHeight = self.dataOut.radarControllerHeaderObj.samplingWindow['dh'] |
|
719 | 718 | self.dataOut.radarControllerHeaderObj.samplesWin = self.dataOut.radarControllerHeaderObj.samplingWindow['nsa'] |
|
720 | 719 | |
|
721 | 720 | self.dataOut.radarControllerHeaderObj.nWindows=1 |
|
722 | 721 | self.dataOut.radarControllerHeaderObj.codetype=0 |
|
723 | 722 | self.dataOut.radarControllerHeaderObj.numTaus=0 |
|
724 | 723 | #self.dataOut.radarControllerHeaderObj.Taus = numpy.zeros((1,),'<f4') |
|
725 | 724 | |
|
726 | 725 | |
|
727 | 726 | #self.dataOut.radarControllerHeaderObj.nCode=numpy.zeros((1,), '<u4') |
|
728 | 727 | #self.dataOut.radarControllerHeaderObj.nBaud=numpy.zeros((1,), '<u4') |
|
729 | 728 | #self.dataOut.radarControllerHeaderObj.code=numpy.zeros(0) |
|
730 | 729 | |
|
731 | 730 | self.dataOut.radarControllerHeaderObj.code_size=0 |
|
732 | 731 | self.dataOut.nBaud=0 |
|
733 | 732 | self.dataOut.nCode=0 |
|
734 | 733 | self.dataOut.nPairs=0 |
|
735 | 734 | |
|
736 | 735 | |
|
737 | 736 | #--------------------------------------------------------- |
|
738 | 737 | |
|
739 | 738 | self.dataOut.type = "Voltage" |
|
740 | 739 | |
|
741 | 740 | self.dataOut.data = None |
|
742 | 741 | |
|
743 | 742 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
744 | 743 | |
|
745 | 744 | self.dataOut.nProfiles = 1 |
|
746 | 745 | |
|
747 | 746 | self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth |
|
748 | 747 | |
|
749 | 748 | self.dataOut.channelList = range(self.nChannels) |
|
750 | 749 | |
|
751 | 750 | #self.dataOut.channelIndexList = None |
|
752 | 751 | |
|
753 | 752 | self.dataOut.flagNoData = True |
|
754 | 753 | |
|
755 | 754 | #Set to TRUE if the data is discontinuous |
|
756 | 755 | self.dataOut.flagDiscontinuousBlock = False |
|
757 | 756 | |
|
758 | 757 | self.dataOut.utctime = None |
|
759 | 758 | |
|
760 | 759 | self.dataOut.timeZone = self.timezone |
|
761 | 760 | |
|
762 | 761 | self.dataOut.dstFlag = 0 |
|
763 | 762 | |
|
764 | 763 | self.dataOut.errorCount = 0 |
|
765 | 764 | |
|
766 | 765 | self.dataOut.nCohInt = 1 |
|
767 | 766 | |
|
768 | 767 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() |
|
769 | 768 | |
|
770 | 769 | self.dataOut.flagDecodeData = False #asumo que la data esta decodificada |
|
771 | 770 | |
|
772 | 771 | self.dataOut.flagDeflipData = False #asumo que la data esta sin flip |
|
773 | 772 | |
|
774 | 773 | self.dataOut.flagShiftFFT = False |
|
775 | 774 | |
|
776 | 775 | self.dataOut.ippSeconds = 1.0*self.__nSamples/self.__sample_rate |
|
777 | 776 | |
|
778 | 777 | #Time interval between profiles |
|
779 | 778 | #self.dataOut.timeInterval =self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
780 | 779 | |
|
781 | 780 | |
|
782 | 781 | self.dataOut.frequency = self.__frequency |
|
783 | 782 | |
|
784 | 783 | self.dataOut.realtime = self.__online |
|
785 | 784 | |
|
786 | 785 | def __hasNotDataInBuffer(self): |
|
787 | 786 | |
|
788 | 787 | if self.profileIndex >= self.nProfiles: |
|
789 | 788 | return 1 |
|
790 | 789 | |
|
791 | 790 | return 0 |
|
792 | 791 | |
|
793 | 792 | def readNextBlock(self): |
|
794 | 793 | if not(self.__setNewBlock()): |
|
795 | 794 | return 0 |
|
796 | 795 | |
|
797 | 796 | if not(self.readBlock()): |
|
798 | 797 | return 0 |
|
799 | 798 | |
|
800 | 799 | return 1 |
|
801 | 800 | |
|
802 | 801 | def __setNewBlock(self): |
|
803 | 802 | |
|
804 | 803 | if self.hfFilePointer==None: |
|
805 | 804 | return 0 |
|
806 | 805 | |
|
807 | 806 | if self.flagIsNewFile: |
|
808 | 807 | return 1 |
|
809 | 808 | |
|
810 | 809 | if self.profileIndex < self.nProfiles: |
|
811 | 810 | return 1 |
|
812 | 811 | |
|
813 | 812 | self.__setNextFile(self.online) |
|
814 | 813 | |
|
815 | 814 | return 1 |
|
816 | 815 | |
|
817 | 816 | |
|
818 | 817 | |
|
819 | 818 | def readBlock(self): |
|
820 | 819 | fp=h5py.File(self.filename,'r') |
|
821 | 820 | #Puntero que apunta al archivo hdf5 |
|
822 | 821 | ch0=(fp['ch0']).value #Primer canal (100,1000)--(perfiles,alturas) |
|
823 | 822 | ch1=(fp['ch1']).value #Segundo canal (100,1000)--(perfiles,alturas) |
|
824 | 823 | fp.close() |
|
825 | 824 | ch0= ch0.swapaxes(0,1) #Primer canal (100,1000)--(alturas,perfiles) |
|
826 | 825 | ch1= ch1.swapaxes(0,1) #Segundo canal (100,1000)--(alturas,perfiles) |
|
827 | 826 | self.datablock = numpy.array([ch0,ch1]) |
|
828 | 827 | self.flagIsNewFile=0 |
|
829 | 828 | |
|
830 | 829 | self.profileIndex=0 |
|
831 | 830 | |
|
832 | 831 | return 1 |
|
833 | 832 | |
|
834 | 833 | def getData(self): |
|
835 | 834 | if self.flagNoMoreFiles: |
|
836 | 835 | self.dataOut.flagNoData = True |
|
837 | 836 | print 'Process finished' |
|
838 | 837 | return 0 |
|
839 | 838 | |
|
840 | 839 | if self.__hasNotDataInBuffer(): |
|
841 | 840 | if not(self.readNextBlock()): |
|
842 | 841 | self.dataOut.flagNodata=True |
|
843 | 842 | return 0 |
|
844 | 843 | |
|
845 | 844 | ############################## |
|
846 | 845 | ############################## |
|
847 | 846 | self.dataOut.data = self.datablock[:,:,self.profileIndex] |
|
848 | 847 | self.dataOut.utctime = self.__t0 + self.dataOut.ippSeconds*self.profileIndex |
|
849 | 848 | self.dataOut.profileIndex= self.profileIndex |
|
850 | 849 | self.dataOut.flagNoData=False |
|
851 | 850 | self.profileIndex +=1 |
|
852 | 851 | |
|
853 | 852 | return self.dataOut.data |
|
854 | 853 | |
|
855 | 854 | |
|
856 | 855 | def run(self, **kwargs): |
|
857 | 856 | ''' |
|
858 | 857 | This method will be called many times so here you should put all your code |
|
859 | 858 | ''' |
|
860 | 859 | |
|
861 | 860 | if not self.isConfig: |
|
862 | 861 | self.setup(**kwargs) |
|
863 | 862 | self.isConfig = True |
|
864 | 863 | self.getData() |
|
865 | 864 | |
|
866 | 865 | |
|
867 | 866 | |
|
868 | 867 |
General Comments 0
You need to be logged in to leave comments.
Login now