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