@@ -1,500 +1,506 | |||||
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 |
|
7 | import os,sys | |
8 | import time,datetime |
|
8 | import time,datetime | |
9 | import os |
|
|||
10 | import h5py |
|
9 | import h5py | |
|
10 | import numpy | |||
11 | import re |
|
11 | import re | |
12 | import stuffr |
|
12 | import stuffr | |
13 |
|
13 | |||
14 | from model.data.jrodata import * |
|
14 | from model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
|
15 | from model.data.jrodata import Voltage | |||
15 | from model.proc.jroproc_base import ProcessingUnit, Operation |
|
16 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
16 |
|
17 | |||
17 | class HFReader(ProcessingUnit): |
|
18 | class HFReader(ProcessingUnit): | |
18 | ''' |
|
19 | ''' | |
19 | classdocs |
|
20 | classdocs | |
20 | ''' |
|
21 | ''' | |
21 | path = None |
|
22 | path = None | |
22 | startDate= None |
|
23 | startDate= None | |
23 | endDate = None |
|
24 | endDate = None | |
24 | startTime= None |
|
25 | startTime= None | |
25 | endTime = None |
|
26 | endTime = None | |
26 | walk = None |
|
27 | walk = None | |
27 | isConfig = False |
|
28 | isConfig = False | |
28 | dataOut=None |
|
29 | dataOut=None | |
29 | ext = ".hdf5" |
|
30 | ext = ".hdf5" | |
30 |
|
31 | |||
31 | def __init__(self): |
|
32 | def __init__(self): | |
32 | ''' |
|
33 | ''' | |
33 | Constructor |
|
34 | Constructor | |
34 | ''' |
|
35 | ''' | |
35 | ProcessingUnit.__init__(self) |
|
36 | ProcessingUnit.__init__(self) | |
36 |
|
37 | |||
37 | self.isConfig =False |
|
38 | self.isConfig =False | |
38 |
|
39 | |||
39 | self.datablock = None |
|
40 | self.datablock = None | |
40 |
|
41 | |||
41 | self.utc = 0 |
|
42 | self.utc = 0 | |
42 |
|
43 | |||
43 | self.ext='.hdf5' |
|
44 | self.ext='.hdf5' | |
44 |
|
45 | |||
45 | self.flagIsNewFile = 1 |
|
46 | self.flagIsNewFile = 1 | |
46 |
|
47 | |||
47 | #------------------------------------------------- |
|
48 | #------------------------------------------------- | |
48 | self.fileIndex=None |
|
49 | self.fileIndex=None | |
49 |
|
50 | |||
50 | self.profileIndex_offset=None |
|
51 | self.profileIndex_offset=None | |
51 |
|
52 | |||
52 | self.filenameList=[] |
|
53 | self.filenameList=[] | |
53 |
|
54 | |||
54 | self.hfFilePointer= None |
|
55 | self.hfFilePointer= None | |
55 |
|
56 | |||
56 | self.__filename_online = None |
|
57 | self.__filename_online = None | |
57 |
|
58 | |||
58 | self.status=True |
|
59 | self.status=True | |
59 |
|
60 | |||
60 | self.flagNoMoreFiles= False |
|
61 | self.flagNoMoreFiles= False | |
61 |
|
62 | |||
62 | #-------------------------------------------------- |
|
63 | #-------------------------------------------------- | |
63 |
|
64 | |||
64 | self.dataOut = self.createObjByDefault() |
|
65 | self.dataOut = self.createObjByDefault() | |
65 |
|
66 | |||
66 |
|
67 | |||
67 | def createObjByDefault(self): |
|
68 | def createObjByDefault(self): | |
68 |
|
69 | |||
69 | dataObj = Voltage() |
|
70 | dataObj = Voltage() | |
70 |
|
71 | |||
71 | return dataObj |
|
72 | return dataObj | |
72 |
|
73 | |||
73 | def setObjProperties(self): |
|
74 | def setObjProperties(self): | |
74 |
|
75 | |||
75 | pass |
|
76 | pass | |
76 |
|
77 | |||
77 | def getBlockDimension(self): |
|
78 | def getBlockDimension(self): | |
78 | """ |
|
79 | """ | |
79 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
80 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
80 |
|
81 | |||
81 | Affected: |
|
82 | Affected: | |
82 | self.blocksize |
|
83 | self.blocksize | |
83 |
|
84 | |||
84 | Return: |
|
85 | Return: | |
85 | None |
|
86 | None | |
86 | """ |
|
87 | """ | |
87 | pts2read =self.nChannels*self.nHeights*self.nProfiles |
|
88 | pts2read =self.nChannels*self.nHeights*self.nProfiles | |
88 | self.blocksize = pts2read |
|
89 | self.blocksize = pts2read | |
89 |
|
90 | |||
90 | def __readHeader(self): |
|
91 | def __readHeader(self): | |
91 |
|
92 | |||
92 | self.nProfiles = 100 |
|
93 | self.nProfiles = 100 | |
93 | self.nHeights = 1000 |
|
94 | self.nHeights = 1000 | |
94 | self.nChannels = 2 |
|
95 | self.nChannels = 2 | |
95 | self.__firstHeigth=0 |
|
96 | self.__firstHeigth=0 | |
96 | self.__nSamples=1000 |
|
97 | self.__nSamples=1000 | |
97 | self.__deltaHeigth=1.5 |
|
98 | self.__deltaHeigth=1.5 | |
98 |
self.__sample_rate=1 |
|
99 | self.__sample_rate=1e5 | |
99 | self.__frequency=2.72e6 |
|
100 | #self.__frequency=2.72e6 | |
|
101 | self.__frequency=3.64e6 | |||
100 | self.__online = False |
|
102 | self.__online = False | |
101 |
|
103 | |||
102 |
|
104 | |||
103 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): |
|
105 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): | |
104 | self.path = path |
|
106 | self.path = path | |
105 | self.startDate = startDate |
|
107 | self.startDate = startDate | |
106 | self.endDate = endDate |
|
108 | self.endDate = endDate | |
107 | self.startTime = startTime |
|
109 | self.startTime = startTime | |
108 | self.endTime = endTime |
|
110 | self.endTime = endTime | |
109 | self.walk = walk |
|
111 | self.walk = walk | |
110 |
|
112 | |||
111 | def __checkPath(self): |
|
113 | def __checkPath(self): | |
112 | if os.path.exists(self.path): |
|
114 | if os.path.exists(self.path): | |
113 | self.status=1 |
|
115 | self.status=1 | |
114 | else: |
|
116 | else: | |
115 | self.status=0 |
|
117 | self.status=0 | |
116 | print 'Path %s does not exits'%self.path |
|
118 | print 'Path %s does not exits'%self.path | |
117 | return |
|
119 | return | |
118 |
|
120 | |||
119 | def __selDates(self, hf_dirname_format): |
|
121 | def __selDates(self, hf_dirname_format): | |
120 | try: |
|
122 | try: | |
121 | dir_hf_filename= self.path+"/"+hf_dirname_format |
|
123 | dir_hf_filename= self.path+"/"+hf_dirname_format | |
122 | fp= h5py.File(dir_hf_filename,'r') |
|
124 | fp= h5py.File(dir_hf_filename,'r') | |
123 | hipoc=fp['t'].value |
|
125 | hipoc=fp['t'].value | |
|
126 | fp.close() | |||
124 | date_time=stuffr.unix2datestr(hipoc) |
|
127 | date_time=stuffr.unix2datestr(hipoc) | |
125 | year =int(date_time[0:4]) |
|
128 | year =int(date_time[0:4]) | |
126 | month=int(date_time[5:7]) |
|
129 | month=int(date_time[5:7]) | |
127 | dom =int(date_time[8:10]) |
|
130 | dom =int(date_time[8:10]) | |
128 | thisDate= datetime.date(year,month,dom) |
|
131 | thisDate= datetime.date(year,month,dom) | |
129 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
132 | if (thisDate>=self.startDate and thisDate <= self.endDate): | |
130 | return hf_dirname_format |
|
133 | return hf_dirname_format | |
131 | except: |
|
134 | except: | |
132 | return None |
|
135 | return None | |
133 |
|
136 | |||
134 | def __findDataForDates(self,online=False): |
|
137 | def __findDataForDates(self,online=False): | |
135 | if not(self.status): |
|
138 | if not(self.status): | |
136 | return None |
|
139 | return None | |
137 |
|
140 | |||
138 | pat = '\d+.\d+' |
|
141 | pat = '\d+.\d+' | |
139 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] |
|
142 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] | |
140 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
143 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
141 | dirnameList = [x.string for x in dirnameList] |
|
144 | dirnameList = [x.string for x in dirnameList] | |
142 | if not(online): |
|
145 | if not(online): | |
143 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
146 | dirnameList = [self.__selDates(x) for x in dirnameList] | |
144 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
147 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
145 | if len(dirnameList)>0: |
|
148 | if len(dirnameList)>0: | |
146 | self.status = 1 |
|
149 | self.status = 1 | |
147 | self.dirnameList = dirnameList |
|
150 | self.dirnameList = dirnameList | |
148 | self.dirnameList.sort() |
|
151 | self.dirnameList.sort() | |
149 | else: |
|
152 | else: | |
150 | self.status = 0 |
|
153 | self.status = 0 | |
151 | return None |
|
154 | return None | |
152 |
|
155 | |||
153 | def __getTimeFromData(self): |
|
156 | def __getTimeFromData(self): | |
154 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) |
|
157 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) | |
155 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
158 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) | |
156 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) |
|
159 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) | |
157 | print '........................................' |
|
160 | print '........................................' | |
158 | filter_filenameList=[] |
|
161 | filter_filenameList=[] | |
159 | self.filenameList.sort() |
|
162 | self.filenameList.sort() | |
160 | for i in range(len(self.filenameList)-1): |
|
163 | for i in range(len(self.filenameList)-1): | |
161 | filename=self.filenameList[i] |
|
164 | filename=self.filenameList[i] | |
162 | dir_hf_filename= filename |
|
165 | dir_hf_filename= filename | |
163 | fp= h5py.File(dir_hf_filename,'r') |
|
166 | fp= h5py.File(dir_hf_filename,'r') | |
164 | hipoc=fp['t'].value |
|
167 | hipoc=fp['t'].value | |
165 | date_time=stuffr.unix2datestr(hipoc) |
|
168 | date_time=stuffr.unix2datestr(hipoc) | |
|
169 | fp.close() | |||
166 | year =int(date_time[0:4]) |
|
170 | year =int(date_time[0:4]) | |
167 | month=int(date_time[5:7]) |
|
171 | month=int(date_time[5:7]) | |
168 | dom =int(date_time[8:10]) |
|
172 | dom =int(date_time[8:10]) | |
169 | hour =int(date_time[11:13]) |
|
173 | hour =int(date_time[11:13]) | |
170 | min =int(date_time[14:16]) |
|
174 | min =int(date_time[14:16]) | |
171 | sec =int(date_time[17:19]) |
|
175 | sec =int(date_time[17:19]) | |
172 | this_time=datetime.datetime(year,month,dom,hour,min,sec) |
|
176 | this_time=datetime.datetime(year,month,dom,hour,min,sec) | |
173 | if (this_time>=startDateTime_Reader and this_time <= endDateTime_Reader): |
|
177 | if (this_time>=startDateTime_Reader and this_time <= endDateTime_Reader): | |
174 | filter_filenameList.append(filename) |
|
178 | filter_filenameList.append(filename) | |
175 | filter_filenameList.sort() |
|
179 | filter_filenameList.sort() | |
176 | self.filenameList = filter_filenameList |
|
180 | self.filenameList = filter_filenameList | |
177 | return 1 |
|
181 | return 1 | |
178 |
|
182 | |||
179 | def __getFilenameList(self): |
|
183 | def __getFilenameList(self): | |
180 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
184 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] | |
181 | self.filenameList= dirList |
|
185 | self.filenameList= dirList | |
182 |
|
186 | |||
183 | def __selectDataForTimes(self, online=False): |
|
187 | def __selectDataForTimes(self, online=False): | |
184 |
|
188 | |||
185 | if not(self.status): |
|
189 | if not(self.status): | |
186 |
return |
|
190 | return None | |
187 | self.__getFilenameList() |
|
191 | self.__getFilenameList() | |
188 | if not(online): |
|
192 | if not(online): | |
189 | if not(self.all): |
|
193 | if not(self.all): | |
190 | self.__getTimeFromData() |
|
194 | self.__getTimeFromData() | |
191 | if len(self.filenameList)>0: |
|
195 | if len(self.filenameList)>0: | |
192 | self.status=1 |
|
196 | self.status=1 | |
193 | self.filenameList.sort() |
|
197 | self.filenameList.sort() | |
194 | else: |
|
198 | else: | |
195 | self.status=0 |
|
199 | self.status=0 | |
196 | return None |
|
200 | return None | |
197 | else: |
|
201 | else: | |
198 | self.filenameList=[self.filenameList[-2]] |
|
202 | self.filenameList=[self.filenameList[-2]] | |
199 |
|
203 | |||
200 | def __searchFilesOffline(self, |
|
204 | def __searchFilesOffline(self, | |
201 | path, |
|
205 | path, | |
202 | startDate, |
|
206 | startDate, | |
203 | endDate, |
|
207 | endDate, | |
204 | ext, |
|
208 | ext, | |
205 | startTime=datetime.time(0,0,0), |
|
209 | startTime=datetime.time(0,0,0), | |
206 | endTime=datetime.time(23,59,59), |
|
210 | endTime=datetime.time(23,59,59), | |
207 | walk=True): |
|
211 | walk=True): | |
208 |
|
212 | |||
209 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
213 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) | |
210 |
|
214 | |||
211 | self.__checkPath() |
|
215 | self.__checkPath() | |
212 |
|
216 | |||
213 | self.__findDataForDates() |
|
217 | self.__findDataForDates() | |
214 |
|
218 | |||
215 | self.__selectDataForTimes() |
|
219 | self.__selectDataForTimes() | |
216 |
|
220 | |||
217 | for i in range(len(self.filenameList)): |
|
221 | for i in range(len(self.filenameList)): | |
218 | print "%s"% (self.filenameList[i]) |
|
222 | print "%s"% (self.filenameList[i]) | |
219 |
|
223 | |||
220 | return |
|
224 | return | |
221 |
|
225 | |||
222 | def __searchFilesOnline(self, |
|
226 | def __searchFilesOnline(self, | |
223 | path, |
|
227 | path, | |
224 | walk=True): |
|
228 | walk=True): | |
225 | startDate= datetime.datetime.utcnow().date |
|
229 | startDate= datetime.datetime.utcnow().date | |
226 | endDate= datetime.datetime.utcnow().date() |
|
230 | endDate= datetime.datetime.utcnow().date() | |
227 | self.__setParameters(path=path,startDate=startDate,endDate=endDate,walk=walk) |
|
231 | self.__setParameters(path=path,startDate=startDate,endDate=endDate,walk=walk) | |
228 | self.__checkPath() |
|
232 | self.__checkPath() | |
229 | self.__findDataForDates(online=True) |
|
233 | self.__findDataForDates(online=True) | |
230 | self.dirnameList= [self.dirnameList[-1]] |
|
234 | self.dirnameList= [self.dirnameList[-1]] | |
231 | self.__selectDataForTimes(online=True) |
|
235 | self.__selectDataForTimes(online=True) | |
232 | return |
|
236 | return | |
233 |
|
237 | |||
234 | def __setNextFile(self,online=False): |
|
238 | def __setNextFile(self,online=False): | |
235 | """ |
|
239 | """ | |
236 | """ |
|
240 | """ | |
237 | if not(online): |
|
241 | if not(online): | |
238 | newFile = self.__setNextFileOffline() |
|
242 | newFile = self.__setNextFileOffline() | |
239 | else: |
|
243 | else: | |
240 | newFile = self.__setNextFileOnline() |
|
244 | newFile = self.__setNextFileOnline() | |
241 |
|
245 | |||
242 | if not(newFile): |
|
246 | if not(newFile): | |
243 | return 0 |
|
247 | return 0 | |
244 | return 1 |
|
248 | return 1 | |
245 |
|
249 | |||
246 | def __setNextFileOffline(self): |
|
250 | def __setNextFileOffline(self): | |
247 | """ |
|
251 | """ | |
248 | """ |
|
252 | """ | |
249 | idFile= self.fileIndex |
|
253 | idFile= self.fileIndex | |
250 | while(True): |
|
254 | while(True): | |
251 | idFile += 1 |
|
255 | idFile += 1 | |
252 | if not (idFile < len(self.filenameList)): |
|
256 | if not (idFile < len(self.filenameList)): | |
253 | self.flagNoMoreFiles = 1 |
|
257 | self.flagNoMoreFiles = 1 | |
254 | print "No more Files" |
|
258 | print "No more Files" | |
255 | return 0 |
|
259 | return 0 | |
256 | filename = self.filenameList[idFile] |
|
260 | filename = self.filenameList[idFile] | |
257 | hfFilePointer =h5py.File(filename,'r') |
|
261 | hfFilePointer =h5py.File(filename,'r') | |
258 |
|
262 | |||
259 | epoc=hfFilePointer['t'].value |
|
263 | epoc=hfFilePointer['t'].value | |
260 | #this_time=datetime.datetime(year,month,dom,hour,min,sec) |
|
264 | #this_time=datetime.datetime(year,month,dom,hour,min,sec) | |
261 | break |
|
265 | break | |
262 |
|
266 | |||
263 | self.flagIsNewFile = 1 |
|
267 | self.flagIsNewFile = 1 | |
264 | self.fileIndex = idFile |
|
268 | self.fileIndex = idFile | |
265 | self.filename = filename |
|
269 | self.filename = filename | |
266 |
|
270 | |||
267 | self.hfFilePointer = hfFilePointer |
|
271 | self.hfFilePointer = hfFilePointer | |
|
272 | hfFilePointer.close() | |||
268 | self.__t0=epoc |
|
273 | self.__t0=epoc | |
269 |
|
274 | |||
270 |
|
275 | |||
271 | print "Setting the file: %s"%self.filename |
|
276 | print "Setting the file: %s"%self.filename | |
272 |
|
277 | |||
273 |
|
278 | |||
274 |
|
279 | |||
275 | return 1 |
|
280 | return 1 | |
276 |
|
281 | |||
277 | def __setNextFileOnline(self): |
|
282 | def __setNextFileOnline(self): | |
278 | """ |
|
283 | """ | |
279 | """ |
|
284 | """ | |
280 | filename = self.filenameList[0] |
|
285 | filename = self.filenameList[0] | |
281 | if self.__filename_online != None: |
|
286 | if self.__filename_online != None: | |
282 | self.__selecDataForTimes(online=True) |
|
287 | self.__selecDataForTimes(online=True) | |
283 | filename = self.filenameList[0] |
|
288 | filename = self.filenameList[0] | |
284 | while self.__filename_online == filename: |
|
289 | while self.__filename_online == filename: | |
285 | print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) |
|
290 | print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) | |
286 | time.sleep(self.__waitForNewFile) |
|
291 | time.sleep(self.__waitForNewFile) | |
287 | self.__selectDataForTimes(online=True) |
|
292 | self.__selectDataForTimes(online=True) | |
288 | filename = self.filenameList[0] |
|
293 | filename = self.filenameList[0] | |
289 |
|
294 | |||
290 | self.__filename_online=filename |
|
295 | self.__filename_online=filename | |
291 | self.hfFilePointer=h5py.File(filename,'r') |
|
296 | self.hfFilePointer=h5py.File(filename,'r') | |
292 | self.flagIsNewFile = 1 |
|
297 | self.flagIsNewFile = 1 | |
293 | self.filename = filename |
|
298 | self.filename = filename | |
294 |
|
299 | |||
295 | print "Setting the file: %s"%self.filename |
|
300 | print "Setting the file: %s"%self.filename | |
296 | return 1 |
|
301 | return 1 | |
297 |
|
302 | |||
298 | def __getExpParameters(self): |
|
303 | def __getExpParameters(self): | |
299 | if not(self.status): |
|
304 | if not(self.status): | |
300 | return None |
|
305 | return None | |
301 |
|
|
306 | ||
302 | fp=self.hfFilePointer |
|
|||
303 |
|
||||
304 | def setup(self, path = None, |
|
307 | def setup(self, path = None, | |
305 | startDate = None, |
|
308 | startDate = None, | |
306 | endDate = None, |
|
309 | endDate = None, | |
307 | startTime = datetime.time(0,0,0), |
|
310 | startTime = datetime.time(0,0,0), | |
308 | endTime = datetime.time(23,59,59), |
|
311 | endTime = datetime.time(23,59,59), | |
309 | set = None, |
|
312 | set = None, | |
310 | expLabel = "", |
|
313 | expLabel = "", | |
311 | ext = None, |
|
314 | ext = None, | |
312 | all=0, |
|
315 | all=0, | |
313 |
timezone= |
|
316 | timezone=0, | |
314 | online = False, |
|
317 | online = False, | |
315 | delay = 60, |
|
318 | delay = 60, | |
316 | walk = True): |
|
319 | walk = True): | |
317 | ''' |
|
320 | ''' | |
318 | In this method we should set all initial parameters. |
|
321 | In this method we should set all initial parameters. | |
319 |
|
322 | |||
320 | ''' |
|
323 | ''' | |
321 | self.timezone= timezone |
|
324 | self.timezone= timezone | |
322 | self.online= online |
|
325 | self.online= online | |
323 | self.all=all |
|
326 | self.all=all | |
324 | if ext==None: |
|
327 | if ext==None: | |
325 | ext = self.ext |
|
328 | ext = self.ext | |
326 |
|
329 | |||
327 | if not(online): |
|
330 | if not(online): | |
328 | self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, walk) |
|
331 | self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, walk) | |
329 | else: |
|
332 | else: | |
330 | self.__searchFilesOnline(path,walk) |
|
333 | self.__searchFilesOnline(path,walk) | |
331 |
|
334 | |||
332 | if not(self.filenameList): |
|
335 | if not(self.filenameList): | |
333 | print "There is no files into the folder: %s"%(path) |
|
336 | print "There is no files into the folder: %s"%(path) | |
334 | sys.exit(-1) |
|
337 | sys.exit(-1) | |
335 |
|
338 | |||
336 | self.__getExpParameters() |
|
339 | self.__getExpParameters() | |
337 |
|
340 | |||
338 | self.fileIndex = -1 |
|
341 | self.fileIndex = -1 | |
339 |
|
342 | |||
340 | self.__setNextFile(online) |
|
343 | self.__setNextFile(online) | |
341 |
|
344 | |||
342 | self.__readMetadata() |
|
345 | self.__readMetadata() | |
343 |
|
346 | |||
344 | self.__setLocalVariables() |
|
347 | self.__setLocalVariables() | |
345 |
|
348 | |||
346 | self.__setHeaderDO() |
|
349 | self.__setHeaderDO() | |
347 | #self.profileIndex_offset= 0 |
|
350 | #self.profileIndex_offset= 0 | |
348 |
|
351 | |||
349 | #self.profileIndex = self.profileIndex_offset |
|
352 | #self.profileIndex = self.profileIndex_offset | |
350 |
|
353 | |||
351 | self.isConfig = True |
|
354 | self.isConfig = True | |
352 |
|
355 | |||
353 | def __readMetadata(self): |
|
356 | def __readMetadata(self): | |
354 | self.__readHeader() |
|
357 | self.__readHeader() | |
355 |
|
358 | |||
356 |
|
359 | |||
357 | def __setLocalVariables(self): |
|
360 | def __setLocalVariables(self): | |
358 |
|
361 | |||
359 | self.datablock = numpy.zeros((self.nChannels, self.nHeights,self.nProfiles), dtype = numpy.complex) |
|
362 | self.datablock = numpy.zeros((self.nChannels, self.nHeights,self.nProfiles), dtype = numpy.complex) | |
360 | # |
|
363 | # | |
361 |
|
364 | |||
362 |
|
365 | |||
363 |
|
366 | |||
364 | self.profileIndex = 9999 |
|
367 | self.profileIndex = 9999 | |
365 |
|
368 | |||
366 |
|
369 | |||
367 | def __setHeaderDO(self): |
|
370 | def __setHeaderDO(self): | |
368 |
|
371 | |||
|
372 | ||||
369 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader() |
|
373 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader() | |
370 |
|
374 | |||
371 | self.dataOut.systemHeaderObj = SystemHeader() |
|
375 | self.dataOut.systemHeaderObj = SystemHeader() | |
372 |
|
376 | |||
373 | self.dataOut.type = "Voltage" |
|
377 | self.dataOut.type = "Voltage" | |
374 |
|
378 | |||
375 | self.dataOut.data = None |
|
379 | self.dataOut.data = None | |
376 |
|
380 | |||
377 | self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
381 | self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
378 |
|
382 | |||
379 | self.dataOut.nProfiles = 1 |
|
383 | self.dataOut.nProfiles = 1 | |
380 |
|
384 | |||
381 | self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth |
|
385 | self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth | |
382 |
|
386 | |||
383 |
self.dataOut.channelList = |
|
387 | self.dataOut.channelList = range(self.nChannels) | |
384 |
|
|
388 | ||
385 |
|
|
389 | #self.dataOut.channelIndexList = None | |
386 |
|
390 | |||
387 | self.dataOut.flagNoData = True |
|
391 | self.dataOut.flagNoData = True | |
388 |
|
392 | |||
389 | #Set to TRUE if the data is discontinuous |
|
393 | #Set to TRUE if the data is discontinuous | |
390 | self.dataOut.flagDiscontinuousBlock = False |
|
394 | self.dataOut.flagDiscontinuousBlock = False | |
391 |
|
395 | |||
392 | self.dataOut.utctime = None |
|
396 | self.dataOut.utctime = None | |
393 |
|
397 | |||
394 | self.dataOut.timeZone = 0 |
|
398 | self.dataOut.timeZone = 0 | |
395 |
|
399 | |||
396 | self.dataOut.dstFlag = 0 |
|
400 | self.dataOut.dstFlag = 0 | |
397 |
|
401 | |||
398 | self.dataOut.errorCount = 0 |
|
402 | self.dataOut.errorCount = 0 | |
399 |
|
403 | |||
400 |
self.dataOut.nCohInt = 1 |
|
404 | self.dataOut.nCohInt = 1 | |
401 |
|
405 | |||
402 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() |
|
406 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
403 |
|
407 | |||
404 | self.dataOut.flagDecodeData = False #asumo que la data esta decodificada |
|
408 | self.dataOut.flagDecodeData = False #asumo que la data esta decodificada | |
405 |
|
409 | |||
406 | self.dataOut.flagDeflipData = False #asumo que la data esta sin flip |
|
410 | self.dataOut.flagDeflipData = False #asumo que la data esta sin flip | |
407 |
|
411 | |||
408 | self.dataOut.flagShiftFFT = False |
|
412 | self.dataOut.flagShiftFFT = False | |
409 |
|
413 | |||
410 | self.dataOut.ippSeconds = 1.0*self.__nSamples/self.__sample_rate |
|
414 | self.dataOut.ippSeconds = 1.0*self.__nSamples/self.__sample_rate | |
411 |
|
415 | |||
412 | #Time interval between profiles |
|
416 | #Time interval between profiles | |
413 | #self.dataOut.timeInterval =self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
417 | #self.dataOut.timeInterval =self.dataOut.ippSeconds * self.dataOut.nCohInt | |
414 |
|
418 | |||
415 |
|
419 | |||
416 | self.dataOut.frequency = self.__frequency |
|
420 | self.dataOut.frequency = self.__frequency | |
417 |
|
421 | |||
418 | self.dataOut.realtime = self.__online |
|
422 | self.dataOut.realtime = self.__online | |
419 |
|
423 | |||
420 | def __hasNotDataInBuffer(self): |
|
424 | def __hasNotDataInBuffer(self): | |
421 |
|
425 | |||
422 | if self.profileIndex >= self.nProfiles: |
|
426 | if self.profileIndex >= self.nProfiles: | |
423 | return 1 |
|
427 | return 1 | |
424 |
|
428 | |||
425 | return 0 |
|
429 | return 0 | |
426 |
|
430 | |||
427 | def readNextBlock(self): |
|
431 | def readNextBlock(self): | |
428 | if not(self.__setNewBlock()): |
|
432 | if not(self.__setNewBlock()): | |
429 | return 0 |
|
433 | return 0 | |
430 |
|
434 | |||
431 | if not(self.readBlock()): |
|
435 | if not(self.readBlock()): | |
432 | return 0 |
|
436 | return 0 | |
433 |
|
437 | |||
434 | return 1 |
|
438 | return 1 | |
435 |
|
439 | |||
436 | def __setNewBlock(self): |
|
440 | def __setNewBlock(self): | |
437 |
|
441 | |||
438 | if self.hfFilePointer==None: |
|
442 | if self.hfFilePointer==None: | |
439 | return 0 |
|
443 | return 0 | |
440 |
|
444 | |||
441 | if self.flagIsNewFile: |
|
445 | if self.flagIsNewFile: | |
442 | return 1 |
|
446 | return 1 | |
443 |
|
447 | |||
444 | if self.profileIndex < self.nProfiles: |
|
448 | if self.profileIndex < self.nProfiles: | |
445 | return 1 |
|
449 | return 1 | |
446 |
|
450 | |||
447 | self.__setNextFile(self.online) |
|
451 | self.__setNextFile(self.online) | |
448 |
|
452 | |||
449 | return 1 |
|
453 | return 1 | |
450 |
|
454 | |||
451 |
|
455 | |||
452 |
|
456 | |||
453 | def readBlock(self): |
|
457 | def readBlock(self): | |
454 | fp=self.hfFilePointer #Puntero que apunta al archivo hdf5 |
|
458 | fp=h5py.File(self.filename,'r') | |
|
459 | #Puntero que apunta al archivo hdf5 | |||
455 | ch0=(fp['ch0']).value #Primer canal (100,1000)--(perfiles,alturas) |
|
460 | ch0=(fp['ch0']).value #Primer canal (100,1000)--(perfiles,alturas) | |
456 | ch1=(fp['ch1']).value #Segundo canal (100,1000)--(perfiles,alturas) |
|
461 | ch1=(fp['ch1']).value #Segundo canal (100,1000)--(perfiles,alturas) | |
|
462 | fp.close() | |||
457 | ch0= ch0.swapaxes(0,1) #Primer canal (100,1000)--(alturas,perfiles) |
|
463 | ch0= ch0.swapaxes(0,1) #Primer canal (100,1000)--(alturas,perfiles) | |
458 | ch1= ch1.swapaxes(0,1) #Segundo canal (100,1000)--(alturas,perfiles) |
|
464 | ch1= ch1.swapaxes(0,1) #Segundo canal (100,1000)--(alturas,perfiles) | |
459 | self.datablock = numpy.array([ch0,ch1]) |
|
465 | self.datablock = numpy.array([ch0,ch1]) | |
460 | self.flagIsNewFile=0 |
|
466 | self.flagIsNewFile=0 | |
461 |
|
467 | |||
462 | self.profileIndex=0 |
|
468 | self.profileIndex=0 | |
463 |
|
469 | |||
464 | return 1 |
|
470 | return 1 | |
465 |
|
471 | |||
466 | def getData(self): |
|
472 | def getData(self): | |
467 | if self.flagNoMoreFiles: |
|
473 | if self.flagNoMoreFiles: | |
468 | self.dataOut.flagNoData = True |
|
474 | self.dataOut.flagNoData = True | |
469 | print 'Process finished' |
|
475 | print 'Process finished' | |
470 | return 0 |
|
476 | return 0 | |
471 |
|
477 | |||
472 | if self.__hasNotDataInBuffer(): |
|
478 | if self.__hasNotDataInBuffer(): | |
473 | if not(self.readNextBlock()): |
|
479 | if not(self.readNextBlock()): | |
474 | self.dataOut.flagNodata=True |
|
480 | self.dataOut.flagNodata=True | |
475 | return 0 |
|
481 | return 0 | |
476 |
|
482 | |||
477 | ############################## |
|
483 | ############################## | |
478 | ############################## |
|
484 | ############################## | |
479 | self.dataOut.data = self.datablock[:,:,self.profileIndex] |
|
485 | self.dataOut.data = self.datablock[:,:,self.profileIndex] | |
480 | self.dataOut.utctime= self.__t0 + self.dataOut.ippSeconds*self.profileIndex |
|
486 | self.dataOut.utctime= self.__t0 + self.dataOut.ippSeconds*self.profileIndex+self.timezone | |
481 | self.dataOut.profileIndex= self.profileIndex |
|
487 | self.dataOut.profileIndex= self.profileIndex | |
482 | self.dataOut.flagNoData=False |
|
488 | self.dataOut.flagNoData=False | |
483 | self.profileIndex +=1 |
|
489 | self.profileIndex +=1 | |
484 |
|
490 | |||
485 | return self.dataOut.data |
|
491 | return self.dataOut.data | |
486 |
|
492 | |||
487 |
|
493 | |||
488 | def run(self, **kwargs): |
|
494 | def run(self, **kwargs): | |
489 | ''' |
|
495 | ''' | |
490 | This method will be called many times so here you should put all your code |
|
496 | This method will be called many times so here you should put all your code | |
491 | ''' |
|
497 | ''' | |
492 |
|
498 | |||
493 | if not self.isConfig: |
|
499 | if not self.isConfig: | |
494 | self.setup(**kwargs) |
|
500 | self.setup(**kwargs) | |
495 | self.isConfig = True |
|
501 | self.isConfig = True | |
496 | self.getData() |
|
502 | self.getData() | |
497 |
|
503 | |||
498 |
|
504 | |||
499 |
|
505 | |||
500 | No newline at end of file |
|
506 |
General Comments 0
You need to be logged in to leave comments.
Login now