##// END OF EJS Templates
Se realizar la lectura en modo online llamando al metodo digitalRFReader(self.path) en reemplazo del metodo reload(), grabando previamente el path de lectura o directorio superior donde se almacena la data. Adicionalmente, se ha definido un tiempo de espera de 3 segundos para dar tiempo suficiente al programa de adquisicion de generar archivos. ...
Alexander Valdez -
r1234:b6a76136b1f3
parent child
Show More
@@ -1,800 +1,803
1
2 '''
1 '''
3 Created on Jul 3, 2014
2 Created on Jul 3, 2014
4
3
5 @author: roj-idl71
4 @author: roj-idl71
6 '''
5 '''
7 # SUBCHANNELS EN VEZ DE CHANNELS
6 # SUBCHANNELS EN VEZ DE CHANNELS
8 # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO
7 # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO
9 # ACTUALIZACION DE VERSION
8 # ACTUALIZACION DE VERSION
10 # HEADERS
9 # HEADERS
11 # MODULO DE ESCRITURA
10 # MODULO DE ESCRITURA
12 # METADATA
11 # METADATA
13
12
14 import os
13 import os
15 import datetime
14 import datetime
16 import numpy
15 import numpy
17 import timeit
16 import timeit
18 from fractions import Fraction
17 from fractions import Fraction
19
18
20 try:
19 try:
21 from gevent import sleep
20 from gevent import sleep
22 except:
21 except:
23 from time import sleep
22 from time import sleep
24
23
25 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
24 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
26 from schainpy.model.data.jrodata import Voltage
25 from schainpy.model.data.jrodata import Voltage
27 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
26 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation
28 from time import time
27 from time import time
29
28
30 import cPickle
29 import cPickle
31 try:
30 try:
32 import digital_rf
31 import digital_rf
33 except:
32 except:
34 print 'You should install "digital_rf" module if you want to read Digital RF data'
33 print 'You should install "digital_rf" module if you want to read Digital RF data'
35
34
36
35
37 class DigitalRFReader(ProcessingUnit):
36 class DigitalRFReader(ProcessingUnit):
38 '''
37 '''
39 classdocs
38 classdocs
40 '''
39 '''
41
40
42 def __init__(self, **kwargs):
41 def __init__(self, **kwargs):
43 '''
42 '''
44 Constructor
43 Constructor
45 '''
44 '''
46
45
47 ProcessingUnit.__init__(self, **kwargs)
46 ProcessingUnit.__init__(self, **kwargs)
48
47
49 self.dataOut = Voltage()
48 self.dataOut = Voltage()
50 self.__printInfo = True
49 self.__printInfo = True
51 self.__flagDiscontinuousBlock = False
50 self.__flagDiscontinuousBlock = False
52 self.__bufferIndex = 9999999
51 self.__bufferIndex = 9999999
53 self.__ippKm = None
52 self.__ippKm = None
54 self.__codeType = 0
53 self.__codeType = 0
55 self.__nCode = None
54 self.__nCode = None
56 self.__nBaud = None
55 self.__nBaud = None
57 self.__code = None
56 self.__code = None
58 self.dtype = None
57 self.dtype = None
59 self.oldAverage = None
58 self.oldAverage = None
59 self.path = None
60
60
61 def close(self):
61 def close(self):
62 print 'Average of writing to digital rf format is ', self.oldAverage * 1000
62 print 'Average of writing to digital rf format is ', self.oldAverage * 1000
63 return
63 return
64
64
65 def __getCurrentSecond(self):
65 def __getCurrentSecond(self):
66
66
67 return self.__thisUnixSample / self.__sample_rate
67 return self.__thisUnixSample / self.__sample_rate
68
68
69 thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
69 thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
70
70
71 def __setFileHeader(self):
71 def __setFileHeader(self):
72 '''
72 '''
73 In this method will be initialized every parameter of dataOut object (header, no data)
73 In this method will be initialized every parameter of dataOut object (header, no data)
74 '''
74 '''
75 ippSeconds = 1.0 * self.__nSamples / self.__sample_rate
75 ippSeconds = 1.0 * self.__nSamples / self.__sample_rate
76
76
77 nProfiles = 1.0 / ippSeconds # Number of profiles in one second
77 nProfiles = 1.0 / ippSeconds # Number of profiles in one second
78
78
79 try:
79 try:
80 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
80 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
81 self.__radarControllerHeader)
81 self.__radarControllerHeader)
82 except:
82 except:
83 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
83 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
84 txA=0,
84 txA=0,
85 txB=0,
85 txB=0,
86 nWindows=1,
86 nWindows=1,
87 nHeights=self.__nSamples,
87 nHeights=self.__nSamples,
88 firstHeight=self.__firstHeigth,
88 firstHeight=self.__firstHeigth,
89 deltaHeight=self.__deltaHeigth,
89 deltaHeight=self.__deltaHeigth,
90 codeType=self.__codeType,
90 codeType=self.__codeType,
91 nCode=self.__nCode, nBaud=self.__nBaud,
91 nCode=self.__nCode, nBaud=self.__nBaud,
92 code=self.__code)
92 code=self.__code)
93
93
94 try:
94 try:
95 self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader)
95 self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader)
96 except:
96 except:
97 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
97 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
98 nProfiles=nProfiles,
98 nProfiles=nProfiles,
99 nChannels=len(
99 nChannels=len(
100 self.__channelList),
100 self.__channelList),
101 adcResolution=14)
101 adcResolution=14)
102 self.dataOut.type = "Voltage"
102 self.dataOut.type = "Voltage"
103
103
104 self.dataOut.data = None
104 self.dataOut.data = None
105
105
106 self.dataOut.dtype = self.dtype
106 self.dataOut.dtype = self.dtype
107
107
108 # self.dataOut.nChannels = 0
108 # self.dataOut.nChannels = 0
109
109
110 # self.dataOut.nHeights = 0
110 # self.dataOut.nHeights = 0
111
111
112 self.dataOut.nProfiles = int(nProfiles)
112 self.dataOut.nProfiles = int(nProfiles)
113
113
114 self.dataOut.heightList = self.__firstHeigth + \
114 self.dataOut.heightList = self.__firstHeigth + \
115 numpy.arange(self.__nSamples, dtype=numpy.float) * \
115 numpy.arange(self.__nSamples, dtype=numpy.float) * \
116 self.__deltaHeigth
116 self.__deltaHeigth
117
117
118 self.dataOut.channelList = range(self.__num_subchannels)
118 self.dataOut.channelList = range(self.__num_subchannels)
119
119
120 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
120 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
121
121
122 # self.dataOut.channelIndexList = None
122 # self.dataOut.channelIndexList = None
123
123
124 self.dataOut.flagNoData = True
124 self.dataOut.flagNoData = True
125
125
126 self.dataOut.flagDataAsBlock = False
126 self.dataOut.flagDataAsBlock = False
127 # Set to TRUE if the data is discontinuous
127 # Set to TRUE if the data is discontinuous
128 self.dataOut.flagDiscontinuousBlock = False
128 self.dataOut.flagDiscontinuousBlock = False
129
129
130 self.dataOut.utctime = None
130 self.dataOut.utctime = None
131
131
132 # timezone like jroheader, difference in minutes between UTC and localtime
132 # timezone like jroheader, difference in minutes between UTC and localtime
133 self.dataOut.timeZone = self.__timezone / 60
133 self.dataOut.timeZone = self.__timezone / 60
134
134
135 self.dataOut.dstFlag = 0
135 self.dataOut.dstFlag = 0
136
136
137 self.dataOut.errorCount = 0
137 self.dataOut.errorCount = 0
138
138
139 try:
139 try:
140 self.dataOut.nCohInt = self.fixed_metadata_dict.get(
140 self.dataOut.nCohInt = self.fixed_metadata_dict.get(
141 'nCohInt', self.nCohInt)
141 'nCohInt', self.nCohInt)
142
142
143 # asumo que la data esta decodificada
143 # asumo que la data esta decodificada
144 self.dataOut.flagDecodeData = self.fixed_metadata_dict.get(
144 self.dataOut.flagDecodeData = self.fixed_metadata_dict.get(
145 'flagDecodeData', self.flagDecodeData)
145 'flagDecodeData', self.flagDecodeData)
146
146
147 # asumo que la data esta sin flip
147 # asumo que la data esta sin flip
148 self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData']
148 self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData']
149
149
150 self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT']
150 self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT']
151
151
152 self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime']
152 self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime']
153 except:
153 except:
154 pass
154 pass
155
155
156 self.dataOut.ippSeconds = ippSeconds
156 self.dataOut.ippSeconds = ippSeconds
157
157
158 # Time interval between profiles
158 # Time interval between profiles
159 # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
159 # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
160
160
161 self.dataOut.frequency = self.__frequency
161 self.dataOut.frequency = self.__frequency
162
162
163 self.dataOut.realtime = self.__online
163 self.dataOut.realtime = self.__online
164
164
165 def findDatafiles(self, path, startDate=None, endDate=None):
165 def findDatafiles(self, path, startDate=None, endDate=None):
166
166
167 if not os.path.isdir(path):
167 if not os.path.isdir(path):
168 return []
168 return []
169
169
170 try:
170 try:
171 digitalReadObj = digital_rf.DigitalRFReader(
171 digitalReadObj = digital_rf.DigitalRFReader(
172 path, load_all_metadata=True)
172 path, load_all_metadata=True)
173 except:
173 except:
174 digitalReadObj = digital_rf.DigitalRFReader(path)
174 digitalReadObj = digital_rf.DigitalRFReader(path)
175
175
176 channelNameList = digitalReadObj.get_channels()
176 channelNameList = digitalReadObj.get_channels()
177
177
178 if not channelNameList:
178 if not channelNameList:
179 return []
179 return []
180
180
181 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
181 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
182
182
183 sample_rate = metadata_dict['sample_rate'][0]
183 sample_rate = metadata_dict['sample_rate'][0]
184
184
185 this_metadata_file = digitalReadObj.get_metadata(channelNameList[0])
185 this_metadata_file = digitalReadObj.get_metadata(channelNameList[0])
186
186
187 try:
187 try:
188 timezone = this_metadata_file['timezone'].value
188 timezone = this_metadata_file['timezone'].value
189 except:
189 except:
190 timezone = 0
190 timezone = 0
191
191
192 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(
192 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(
193 channelNameList[0]) / sample_rate - timezone
193 channelNameList[0]) / sample_rate - timezone
194
194
195 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
195 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
196 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
196 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
197
197
198 if not startDate:
198 if not startDate:
199 startDate = startDatetime.date()
199 startDate = startDatetime.date()
200
200
201 if not endDate:
201 if not endDate:
202 endDate = endDatatime.date()
202 endDate = endDatatime.date()
203
203
204 dateList = []
204 dateList = []
205
205
206 thisDatetime = startDatetime
206 thisDatetime = startDatetime
207
207
208 while(thisDatetime <= endDatatime):
208 while(thisDatetime <= endDatatime):
209
209
210 thisDate = thisDatetime.date()
210 thisDate = thisDatetime.date()
211
211
212 if thisDate < startDate:
212 if thisDate < startDate:
213 continue
213 continue
214
214
215 if thisDate > endDate:
215 if thisDate > endDate:
216 break
216 break
217
217
218 dateList.append(thisDate)
218 dateList.append(thisDate)
219 thisDatetime += datetime.timedelta(1)
219 thisDatetime += datetime.timedelta(1)
220
220
221 return dateList
221 return dateList
222
222
223 def setup(self, path=None,
223 def setup(self, path=None,
224 startDate=None,
224 startDate=None,
225 endDate=None,
225 endDate=None,
226 startTime=datetime.time(0, 0, 0),
226 startTime=datetime.time(0, 0, 0),
227 endTime=datetime.time(23, 59, 59),
227 endTime=datetime.time(23, 59, 59),
228 channelList=None,
228 channelList=None,
229 nSamples=None,
229 nSamples=None,
230 online=False,
230 online=False,
231 delay=60,
231 delay=60,
232 buffer_size=1024,
232 buffer_size=1024,
233 ippKm=None,
233 ippKm=None,
234 nCohInt=1,
234 nCohInt=1,
235 nCode=1,
235 nCode=1,
236 nBaud=1,
236 nBaud=1,
237 flagDecodeData=False,
237 flagDecodeData=False,
238 code=numpy.ones((1, 1), dtype=numpy.int),
238 code=numpy.ones((1, 1), dtype=numpy.int),
239 **kwargs):
239 **kwargs):
240 '''
240 '''
241 In this method we should set all initial parameters.
241 In this method we should set all initial parameters.
242
242
243 Inputs:
243 Inputs:
244 path
244 path
245 startDate
245 startDate
246 endDate
246 endDate
247 startTime
247 startTime
248 endTime
248 endTime
249 set
249 set
250 expLabel
250 expLabel
251 ext
251 ext
252 online
252 online
253 delay
253 delay
254 '''
254 '''
255 self.path = path
255 self.nCohInt = nCohInt
256 self.nCohInt = nCohInt
256 self.flagDecodeData = flagDecodeData
257 self.flagDecodeData = flagDecodeData
257 self.i = 0
258 self.i = 0
258 if not os.path.isdir(path):
259 if not os.path.isdir(path):
259 raise ValueError, "[Reading] Directory %s does not exist" % path
260 raise ValueError, "[Reading] Directory %s does not exist" % path
260
261
261 try:
262 try:
262 self.digitalReadObj = digital_rf.DigitalRFReader(
263 self.digitalReadObj = digital_rf.DigitalRFReader(
263 path, load_all_metadata=True)
264 path, load_all_metadata=True)
264 except:
265 except:
265 self.digitalReadObj = digital_rf.DigitalRFReader(path)
266 self.digitalReadObj = digital_rf.DigitalRFReader(path)
266
267
267 channelNameList = self.digitalReadObj.get_channels()
268 channelNameList = self.digitalReadObj.get_channels()
268
269
269 if not channelNameList:
270 if not channelNameList:
270 raise ValueError, "[Reading] Directory %s does not have any files" % path
271 raise ValueError, "[Reading] Directory %s does not have any files" % path
271
272
272 if not channelList:
273 if not channelList:
273 channelList = range(len(channelNameList))
274 channelList = range(len(channelNameList))
274
275
275 ########## Reading metadata ######################
276 ########## Reading metadata ######################
276
277
277 top_properties = self.digitalReadObj.get_properties(
278 top_properties = self.digitalReadObj.get_properties(
278 channelNameList[channelList[0]])
279 channelNameList[channelList[0]])
279
280
280 self.__num_subchannels = top_properties['num_subchannels']
281 self.__num_subchannels = top_properties['num_subchannels']
281 self.__sample_rate = 1.0 * \
282 self.__sample_rate = 1.0 * \
282 top_properties['sample_rate_numerator'] / \
283 top_properties['sample_rate_numerator'] / \
283 top_properties['sample_rate_denominator']
284 top_properties['sample_rate_denominator']
284 # self.__samples_per_file = top_properties['samples_per_file'][0]
285 # self.__samples_per_file = top_properties['samples_per_file'][0]
285 self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15?
286 self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15?
286
287
287 this_metadata_file = self.digitalReadObj.get_digital_metadata(
288 this_metadata_file = self.digitalReadObj.get_digital_metadata(
288 channelNameList[channelList[0]])
289 channelNameList[channelList[0]])
289 metadata_bounds = this_metadata_file.get_bounds()
290 metadata_bounds = this_metadata_file.get_bounds()
290 self.fixed_metadata_dict = this_metadata_file.read(
291 self.fixed_metadata_dict = this_metadata_file.read(
291 metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER
292 metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER
292
293
293 try:
294 try:
294 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
295 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
295 self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader']
296 self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader']
296 self.__systemHeader = self.fixed_metadata_dict['systemHeader']
297 self.__systemHeader = self.fixed_metadata_dict['systemHeader']
297 self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype'])
298 self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype'])
298 except:
299 except:
299 pass
300 pass
300
301
301 self.__frequency = None
302 self.__frequency = None
302
303
303 self.__frequency = self.fixed_metadata_dict.get('frequency', 1)
304 self.__frequency = self.fixed_metadata_dict.get('frequency', 1)
304
305
305 self.__timezone = self.fixed_metadata_dict.get('timezone', 300)
306 self.__timezone = self.fixed_metadata_dict.get('timezone', 300)
306
307
307 try:
308 try:
308 nSamples = self.fixed_metadata_dict['nSamples']
309 nSamples = self.fixed_metadata_dict['nSamples']
309 except:
310 except:
310 nSamples = None
311 nSamples = None
311
312
312 self.__firstHeigth = 0
313 self.__firstHeigth = 0
313
314
314 try:
315 try:
315 codeType = self.__radarControllerHeader['codeType']
316 codeType = self.__radarControllerHeader['codeType']
316 except:
317 except:
317 codeType = 0
318 codeType = 0
318
319
319 try:
320 try:
320 if codeType:
321 if codeType:
321 nCode = self.__radarControllerHeader['nCode']
322 nCode = self.__radarControllerHeader['nCode']
322 nBaud = self.__radarControllerHeader['nBaud']
323 nBaud = self.__radarControllerHeader['nBaud']
323 code = self.__radarControllerHeader['code']
324 code = self.__radarControllerHeader['code']
324 except:
325 except:
325 pass
326 pass
326
327
327 if not ippKm:
328 if not ippKm:
328 try:
329 try:
329 # seconds to km
330 # seconds to km
330 ippKm = self.__radarControllerHeader['ipp']
331 ippKm = self.__radarControllerHeader['ipp']
331 except:
332 except:
332 ippKm = None
333 ippKm = None
333 ####################################################
334 ####################################################
334 self.__ippKm = ippKm
335 self.__ippKm = ippKm
335 startUTCSecond = None
336 startUTCSecond = None
336 endUTCSecond = None
337 endUTCSecond = None
337
338
338 if startDate:
339 if startDate:
339 startDatetime = datetime.datetime.combine(startDate, startTime)
340 startDatetime = datetime.datetime.combine(startDate, startTime)
340 startUTCSecond = (
341 startUTCSecond = (
341 startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone
342 startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone
342
343
343 if endDate:
344 if endDate:
344 endDatetime = datetime.datetime.combine(endDate, endTime)
345 endDatetime = datetime.datetime.combine(endDate, endTime)
345 endUTCSecond = (endDatetime - datetime.datetime(1970,
346 endUTCSecond = (endDatetime - datetime.datetime(1970,
346 1, 1)).total_seconds() + self.__timezone
347 1, 1)).total_seconds() + self.__timezone
347
348
348 start_index, end_index = self.digitalReadObj.get_bounds(
349 start_index, end_index = self.digitalReadObj.get_bounds(
349 channelNameList[channelList[0]])
350 channelNameList[channelList[0]])
350
351
351 if not startUTCSecond:
352 if not startUTCSecond:
352 startUTCSecond = start_index / self.__sample_rate
353 startUTCSecond = start_index / self.__sample_rate
353
354
354 if start_index > startUTCSecond * self.__sample_rate:
355 if start_index > startUTCSecond * self.__sample_rate:
355 startUTCSecond = start_index / self.__sample_rate
356 startUTCSecond = start_index / self.__sample_rate
356
357
357 if not endUTCSecond:
358 if not endUTCSecond:
358 endUTCSecond = end_index / self.__sample_rate
359 endUTCSecond = end_index / self.__sample_rate
359
360
360 if end_index < endUTCSecond * self.__sample_rate:
361 if end_index < endUTCSecond * self.__sample_rate:
361 endUTCSecond = end_index / self.__sample_rate
362 endUTCSecond = end_index / self.__sample_rate
362 if not nSamples:
363 if not nSamples:
363 if not ippKm:
364 if not ippKm:
364 raise ValueError, "[Reading] nSamples or ippKm should be defined"
365 raise ValueError, "[Reading] nSamples or ippKm should be defined"
365 nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate))
366 nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate))
366 channelBoundList = []
367 channelBoundList = []
367 channelNameListFiltered = []
368 channelNameListFiltered = []
368
369
369 for thisIndexChannel in channelList:
370 for thisIndexChannel in channelList:
370 thisChannelName = channelNameList[thisIndexChannel]
371 thisChannelName = channelNameList[thisIndexChannel]
371 start_index, end_index = self.digitalReadObj.get_bounds(
372 start_index, end_index = self.digitalReadObj.get_bounds(
372 thisChannelName)
373 thisChannelName)
373 channelBoundList.append((start_index, end_index))
374 channelBoundList.append((start_index, end_index))
374 channelNameListFiltered.append(thisChannelName)
375 channelNameListFiltered.append(thisChannelName)
375
376
376 self.profileIndex = 0
377 self.profileIndex = 0
377 self.i = 0
378 self.i = 0
378 self.__delay = delay
379 self.__delay = delay
379
380
380 self.__codeType = codeType
381 self.__codeType = codeType
381 self.__nCode = nCode
382 self.__nCode = nCode
382 self.__nBaud = nBaud
383 self.__nBaud = nBaud
383 self.__code = code
384 self.__code = code
384
385
385 self.__datapath = path
386 self.__datapath = path
386 self.__online = online
387 self.__online = online
387 self.__channelList = channelList
388 self.__channelList = channelList
388 self.__channelNameList = channelNameListFiltered
389 self.__channelNameList = channelNameListFiltered
389 self.__channelBoundList = channelBoundList
390 self.__channelBoundList = channelBoundList
390 self.__nSamples = nSamples
391 self.__nSamples = nSamples
391 self.__samples_to_read = long(nSamples) # FIJO: AHORA 40
392 self.__samples_to_read = long(nSamples) # FIJO: AHORA 40
392 self.__nChannels = len(self.__channelList)
393 self.__nChannels = len(self.__channelList)
393
394
394 self.__startUTCSecond = startUTCSecond
395 self.__startUTCSecond = startUTCSecond
395 self.__endUTCSecond = endUTCSecond
396 self.__endUTCSecond = endUTCSecond
396
397
397 self.__timeInterval = 1.0 * self.__samples_to_read / \
398 self.__timeInterval = 1.0 * self.__samples_to_read / \
398 self.__sample_rate # Time interval
399 self.__sample_rate # Time interval
399
400
400 if online:
401 if online:
401 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
402 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
402 startUTCSecond = numpy.floor(endUTCSecond)
403 startUTCSecond = numpy.floor(endUTCSecond)
403
404
404 # por que en el otro metodo lo primero q se hace es sumar samplestoread
405 # por que en el otro metodo lo primero q se hace es sumar samplestoread
405 self.__thisUnixSample = long(
406 self.__thisUnixSample = long(
406 startUTCSecond * self.__sample_rate) - self.__samples_to_read
407 startUTCSecond * self.__sample_rate) - self.__samples_to_read
407
408
408 self.__data_buffer = numpy.zeros(
409 self.__data_buffer = numpy.zeros(
409 (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex)
410 (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex)
410
411
411 self.__setFileHeader()
412 self.__setFileHeader()
412 self.isConfig = True
413 self.isConfig = True
413
414
414 print "[Reading] Digital RF Data was found from %s to %s " % (
415 print "[Reading] Digital RF Data was found from %s to %s " % (
415 datetime.datetime.utcfromtimestamp(
416 datetime.datetime.utcfromtimestamp(
416 self.__startUTCSecond - self.__timezone),
417 self.__startUTCSecond - self.__timezone),
417 datetime.datetime.utcfromtimestamp(
418 datetime.datetime.utcfromtimestamp(
418 self.__endUTCSecond - self.__timezone)
419 self.__endUTCSecond - self.__timezone)
419 )
420 )
420
421
421 print "[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
422 print "[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
422 datetime.datetime.utcfromtimestamp(
423 datetime.datetime.utcfromtimestamp(
423 endUTCSecond - self.__timezone)
424 endUTCSecond - self.__timezone)
424 )
425 )
425 self.oldAverage = None
426 self.oldAverage = None
426 self.count = 0
427 self.count = 0
427 self.executionTime = 0
428 self.executionTime = 0
428
429
429 def __reload(self):
430 def __reload(self):
430 # print
431 # print
431 # print "%s not in range [%s, %s]" %(
432 # print "%s not in range [%s, %s]" %(
432 # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
433 # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
433 # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
434 # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
434 # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
435 # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
435 # )
436 # )
436 print "[Reading] reloading metadata ..."
437 print "[Reading] reloading metadata ..."
437
438
438 try:
439 try:
439 self.digitalReadObj.reload(complete_update=True)
440 self.digitalReadObj.reload(complete_update=True)
440 except:
441 except:
441 self.digitalReadObj.reload()
442 self.digitalReadObj = digital_rf.DigitalRFReader(self.path)
443 #self.digitalReadObj.reload()
442
444
443 start_index, end_index = self.digitalReadObj.get_bounds(
445 start_index, end_index = self.digitalReadObj.get_bounds(
444 self.__channelNameList[self.__channelList[0]])
446 self.__channelNameList[self.__channelList[0]])
445
447
446 if start_index > self.__startUTCSecond * self.__sample_rate:
448 if start_index > self.__startUTCSecond * self.__sample_rate:
447 self.__startUTCSecond = 1.0 * start_index / self.__sample_rate
449 self.__startUTCSecond = 1.0 * start_index / self.__sample_rate
448
450
449 if end_index > self.__endUTCSecond * self.__sample_rate:
451 if end_index > self.__endUTCSecond * self.__sample_rate:
450 self.__endUTCSecond = 1.0 * end_index / self.__sample_rate
452 self.__endUTCSecond = 1.0 * end_index / self.__sample_rate
451 print
453 print
452 print "[Reading] New timerange found [%s, %s] " % (
454 print "[Reading] New timerange found [%s, %s] " % (
453 datetime.datetime.utcfromtimestamp(
455 datetime.datetime.utcfromtimestamp(
454 self.__startUTCSecond - self.__timezone),
456 self.__startUTCSecond - self.__timezone),
455 datetime.datetime.utcfromtimestamp(
457 datetime.datetime.utcfromtimestamp(
456 self.__endUTCSecond - self.__timezone)
458 self.__endUTCSecond - self.__timezone)
457 )
459 )
458
460
459 return True
461 return True
460
462
461 return False
463 return False
462
464
463 def timeit(self, toExecute):
465 def timeit(self, toExecute):
464 t0 = time()
466 t0 = time()
465 toExecute()
467 toExecute()
466 self.executionTime = time() - t0
468 self.executionTime = time() - t0
467 if self.oldAverage is None:
469 if self.oldAverage is None:
468 self.oldAverage = self.executionTime
470 self.oldAverage = self.executionTime
469 self.oldAverage = (self.executionTime + self.count *
471 self.oldAverage = (self.executionTime + self.count *
470 self.oldAverage) / (self.count + 1.0)
472 self.oldAverage) / (self.count + 1.0)
471 self.count = self.count + 1.0
473 self.count = self.count + 1.0
472 return
474 return
473
475
474 def __readNextBlock(self, seconds=30, volt_scale=1):
476 def __readNextBlock(self, seconds=30, volt_scale=1):
475 '''
477 '''
476 '''
478 '''
477
479
478 # Set the next data
480 # Set the next data
479 self.__flagDiscontinuousBlock = False
481 self.__flagDiscontinuousBlock = False
480 self.__thisUnixSample += self.__samples_to_read
482 self.__thisUnixSample += self.__samples_to_read
481
483
482 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
484 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
483 print "[Reading] There are no more data into selected time-range"
485 print "[Reading] There are no more data into selected time-range"
484 if self.__online:
486 if self.__online:
487 sleep(3)
485 self.__reload()
488 self.__reload()
486 else:
489 else:
487 return False
490 return False
488
491
489 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
492 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
490 return False
493 return False
491 self.__thisUnixSample -= self.__samples_to_read
494 self.__thisUnixSample -= self.__samples_to_read
492
495
493 indexChannel = 0
496 indexChannel = 0
494
497
495 dataOk = False
498 dataOk = False
496 for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS?
499 for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS?
497 for indexSubchannel in range(self.__num_subchannels):
500 for indexSubchannel in range(self.__num_subchannels):
498 try:
501 try:
499 t0 = time()
502 t0 = time()
500 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
503 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
501 self.__samples_to_read,
504 self.__samples_to_read,
502 thisChannelName, sub_channel=indexSubchannel)
505 thisChannelName, sub_channel=indexSubchannel)
503 self.executionTime = time() - t0
506 self.executionTime = time() - t0
504 if self.oldAverage is None:
507 if self.oldAverage is None:
505 self.oldAverage = self.executionTime
508 self.oldAverage = self.executionTime
506 self.oldAverage = (
509 self.oldAverage = (
507 self.executionTime + self.count * self.oldAverage) / (self.count + 1.0)
510 self.executionTime + self.count * self.oldAverage) / (self.count + 1.0)
508 self.count = self.count + 1.0
511 self.count = self.count + 1.0
509
512
510 except IOError, e:
513 except IOError, e:
511 # read next profile
514 # read next profile
512 self.__flagDiscontinuousBlock = True
515 self.__flagDiscontinuousBlock = True
513 print "[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
516 print "[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
514 break
517 break
515
518
516 if result.shape[0] != self.__samples_to_read:
519 if result.shape[0] != self.__samples_to_read:
517 self.__flagDiscontinuousBlock = True
520 self.__flagDiscontinuousBlock = True
518 print "[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
521 print "[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
519 result.shape[0],
522 result.shape[0],
520 self.__samples_to_read)
523 self.__samples_to_read)
521 break
524 break
522
525
523 self.__data_buffer[indexSubchannel, :] = result * volt_scale
526 self.__data_buffer[indexSubchannel, :] = result * volt_scale
524
527
525 indexChannel += 1
528 indexChannel += 1
526
529
527 dataOk = True
530 dataOk = True
528
531
529 self.__utctime = self.__thisUnixSample / self.__sample_rate
532 self.__utctime = self.__thisUnixSample / self.__sample_rate
530
533
531 if not dataOk:
534 if not dataOk:
532 return False
535 return False
533
536
534 print "[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
537 print "[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
535 self.__samples_to_read,
538 self.__samples_to_read,
536 self.__timeInterval)
539 self.__timeInterval)
537
540
538 self.__bufferIndex = 0
541 self.__bufferIndex = 0
539
542
540 return True
543 return True
541
544
542 def __isBufferEmpty(self):
545 def __isBufferEmpty(self):
543 return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40
546 return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40
544
547
545 def getData(self, seconds=30, nTries=5):
548 def getData(self, seconds=30, nTries=5):
546 '''
549 '''
547 This method gets the data from files and put the data into the dataOut object
550 This method gets the data from files and put the data into the dataOut object
548
551
549 In addition, increase el the buffer counter in one.
552 In addition, increase el the buffer counter in one.
550
553
551 Return:
554 Return:
552 data : retorna un perfil de voltages (alturas * canales) copiados desde el
555 data : retorna un perfil de voltages (alturas * canales) copiados desde el
553 buffer. Si no hay mas archivos a leer retorna None.
556 buffer. Si no hay mas archivos a leer retorna None.
554
557
555 Affected:
558 Affected:
556 self.dataOut
559 self.dataOut
557 self.profileIndex
560 self.profileIndex
558 self.flagDiscontinuousBlock
561 self.flagDiscontinuousBlock
559 self.flagIsNewBlock
562 self.flagIsNewBlock
560 '''
563 '''
561
564
562 err_counter = 0
565 err_counter = 0
563 self.dataOut.flagNoData = True
566 self.dataOut.flagNoData = True
564
567
565 if self.__isBufferEmpty():
568 if self.__isBufferEmpty():
566 self.__flagDiscontinuousBlock = False
569 self.__flagDiscontinuousBlock = False
567
570
568 while True:
571 while True:
569 if self.__readNextBlock():
572 if self.__readNextBlock():
570 break
573 break
571 if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate:
574 if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate:
572 return False
575 return False
573
576
574 if self.__flagDiscontinuousBlock:
577 if self.__flagDiscontinuousBlock:
575 print '[Reading] discontinuous block found ... continue with the next block'
578 print '[Reading] discontinuous block found ... continue with the next block'
576 continue
579 continue
577
580
578 if not self.__online:
581 if not self.__online:
579 return False
582 return False
580
583
581 err_counter += 1
584 err_counter += 1
582 if err_counter > nTries:
585 if err_counter > nTries:
583 return False
586 return False
584
587
585 print '[Reading] waiting %d seconds to read a new block' % seconds
588 print '[Reading] waiting %d seconds to read a new block' % seconds
586 sleep(seconds)
589 sleep(seconds)
587
590
588 self.dataOut.data = self.__data_buffer[:,
591 self.dataOut.data = self.__data_buffer[:,
589 self.__bufferIndex:self.__bufferIndex + self.__nSamples]
592 self.__bufferIndex:self.__bufferIndex + self.__nSamples]
590 self.dataOut.utctime = (
593 self.dataOut.utctime = (
591 self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate
594 self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate
592 self.dataOut.flagNoData = False
595 self.dataOut.flagNoData = False
593 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
596 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
594 self.dataOut.profileIndex = self.profileIndex
597 self.dataOut.profileIndex = self.profileIndex
595
598
596 self.__bufferIndex += self.__nSamples
599 self.__bufferIndex += self.__nSamples
597 self.profileIndex += 1
600 self.profileIndex += 1
598
601
599 if self.profileIndex == self.dataOut.nProfiles:
602 if self.profileIndex == self.dataOut.nProfiles:
600 self.profileIndex = 0
603 self.profileIndex = 0
601
604
602 return True
605 return True
603
606
604 def printInfo(self):
607 def printInfo(self):
605 '''
608 '''
606 '''
609 '''
607 if self.__printInfo == False:
610 if self.__printInfo == False:
608 return
611 return
609
612
610 # self.systemHeaderObj.printInfo()
613 # self.systemHeaderObj.printInfo()
611 # self.radarControllerHeaderObj.printInfo()
614 # self.radarControllerHeaderObj.printInfo()
612
615
613 self.__printInfo = False
616 self.__printInfo = False
614
617
615 def printNumberOfBlock(self):
618 def printNumberOfBlock(self):
616 '''
619 '''
617 '''
620 '''
618 return
621 return
619 # print self.profileIndex
622 # print self.profileIndex
620
623
621 def run(self, **kwargs):
624 def run(self, **kwargs):
622 '''
625 '''
623 This method will be called many times so here you should put all your code
626 This method will be called many times so here you should put all your code
624 '''
627 '''
625
628
626 if not self.isConfig:
629 if not self.isConfig:
627 self.setup(**kwargs)
630 self.setup(**kwargs)
628 #self.i = self.i+1
631 #self.i = self.i+1
629 self.getData(seconds=self.__delay)
632 self.getData(seconds=self.__delay)
630
633
631 return
634 return
632
635
633
636
634 class DigitalRFWriter(Operation):
637 class DigitalRFWriter(Operation):
635 '''
638 '''
636 classdocs
639 classdocs
637 '''
640 '''
638
641
639 def __init__(self, **kwargs):
642 def __init__(self, **kwargs):
640 '''
643 '''
641 Constructor
644 Constructor
642 '''
645 '''
643 Operation.__init__(self, **kwargs)
646 Operation.__init__(self, **kwargs)
644 self.metadata_dict = {}
647 self.metadata_dict = {}
645 self.dataOut = None
648 self.dataOut = None
646 self.dtype = None
649 self.dtype = None
647 self.oldAverage = 0
650 self.oldAverage = 0
648
651
649 def setHeader(self):
652 def setHeader(self):
650
653
651 self.metadata_dict['frequency'] = self.dataOut.frequency
654 self.metadata_dict['frequency'] = self.dataOut.frequency
652 self.metadata_dict['timezone'] = self.dataOut.timeZone
655 self.metadata_dict['timezone'] = self.dataOut.timeZone
653 self.metadata_dict['dtype'] = cPickle.dumps(self.dataOut.dtype)
656 self.metadata_dict['dtype'] = cPickle.dumps(self.dataOut.dtype)
654 self.metadata_dict['nProfiles'] = self.dataOut.nProfiles
657 self.metadata_dict['nProfiles'] = self.dataOut.nProfiles
655 self.metadata_dict['heightList'] = self.dataOut.heightList
658 self.metadata_dict['heightList'] = self.dataOut.heightList
656 self.metadata_dict['channelList'] = self.dataOut.channelList
659 self.metadata_dict['channelList'] = self.dataOut.channelList
657 self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData
660 self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData
658 self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData
661 self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData
659 self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT
662 self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT
660 self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime
663 self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime
661 self.metadata_dict['nCohInt'] = self.dataOut.nCohInt
664 self.metadata_dict['nCohInt'] = self.dataOut.nCohInt
662 self.metadata_dict['type'] = self.dataOut.type
665 self.metadata_dict['type'] = self.dataOut.type
663 self.metadata_dict['flagDataAsBlock'] = getattr(
666 self.metadata_dict['flagDataAsBlock'] = getattr(
664 self.dataOut, 'flagDataAsBlock', None) # chequear
667 self.dataOut, 'flagDataAsBlock', None) # chequear
665
668
666 def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'):
669 def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'):
667 '''
670 '''
668 In this method we should set all initial parameters.
671 In this method we should set all initial parameters.
669 Input:
672 Input:
670 dataOut: Input data will also be outputa data
673 dataOut: Input data will also be outputa data
671 '''
674 '''
672 self.setHeader()
675 self.setHeader()
673 self.__ippSeconds = dataOut.ippSeconds
676 self.__ippSeconds = dataOut.ippSeconds
674 self.__deltaH = dataOut.getDeltaH()
677 self.__deltaH = dataOut.getDeltaH()
675 self.__sample_rate = 1e6 * 0.15 / self.__deltaH
678 self.__sample_rate = 1e6 * 0.15 / self.__deltaH
676 self.__dtype = dataOut.dtype
679 self.__dtype = dataOut.dtype
677 if len(dataOut.dtype) == 2:
680 if len(dataOut.dtype) == 2:
678 self.__dtype = dataOut.dtype[0]
681 self.__dtype = dataOut.dtype[0]
679 self.__nSamples = dataOut.systemHeaderObj.nSamples
682 self.__nSamples = dataOut.systemHeaderObj.nSamples
680 self.__nProfiles = dataOut.nProfiles
683 self.__nProfiles = dataOut.nProfiles
681
684
682 if self.dataOut.type != 'Voltage':
685 if self.dataOut.type != 'Voltage':
683 raise 'Digital RF cannot be used with this data type'
686 raise 'Digital RF cannot be used with this data type'
684 self.arr_data = numpy.ones((1, dataOut.nFFTPoints * len(
687 self.arr_data = numpy.ones((1, dataOut.nFFTPoints * len(
685 self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
688 self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
686 else:
689 else:
687 self.arr_data = numpy.ones((self.__nSamples, len(
690 self.arr_data = numpy.ones((self.__nSamples, len(
688 self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
691 self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
689
692
690 file_cadence_millisecs = 1000
693 file_cadence_millisecs = 1000
691
694
692 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
695 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
693 sample_rate_numerator = long(sample_rate_fraction.numerator)
696 sample_rate_numerator = long(sample_rate_fraction.numerator)
694 sample_rate_denominator = long(sample_rate_fraction.denominator)
697 sample_rate_denominator = long(sample_rate_fraction.denominator)
695 start_global_index = dataOut.utctime * self.__sample_rate
698 start_global_index = dataOut.utctime * self.__sample_rate
696
699
697 uuid = 'prueba'
700 uuid = 'prueba'
698 compression_level = 0
701 compression_level = 0
699 checksum = False
702 checksum = False
700 is_complex = True
703 is_complex = True
701 num_subchannels = len(dataOut.channelList)
704 num_subchannels = len(dataOut.channelList)
702 is_continuous = True
705 is_continuous = True
703 marching_periods = False
706 marching_periods = False
704
707
705 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence,
708 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence,
706 fileCadence, start_global_index,
709 fileCadence, start_global_index,
707 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
710 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
708 is_complex, num_subchannels, is_continuous, marching_periods)
711 is_complex, num_subchannels, is_continuous, marching_periods)
709 metadata_dir = os.path.join(path, 'metadata')
712 metadata_dir = os.path.join(path, 'metadata')
710 os.system('mkdir %s' % (metadata_dir))
713 os.system('mkdir %s' % (metadata_dir))
711 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000
714 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000
712 sample_rate_numerator, sample_rate_denominator,
715 sample_rate_numerator, sample_rate_denominator,
713 metadataFile)
716 metadataFile)
714 self.isConfig = True
717 self.isConfig = True
715 self.currentSample = 0
718 self.currentSample = 0
716 self.oldAverage = 0
719 self.oldAverage = 0
717 self.count = 0
720 self.count = 0
718 return
721 return
719
722
720 def writeMetadata(self):
723 def writeMetadata(self):
721 start_idx = self.__sample_rate * self.dataOut.utctime
724 start_idx = self.__sample_rate * self.dataOut.utctime
722
725
723 self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict(
726 self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict(
724 )
727 )
725 self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict(
728 self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict(
726 )
729 )
727 self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict(
730 self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict(
728 )
731 )
729 self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict)
732 self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict)
730 return
733 return
731
734
732 def timeit(self, toExecute):
735 def timeit(self, toExecute):
733 t0 = time()
736 t0 = time()
734 toExecute()
737 toExecute()
735 self.executionTime = time() - t0
738 self.executionTime = time() - t0
736 if self.oldAverage is None:
739 if self.oldAverage is None:
737 self.oldAverage = self.executionTime
740 self.oldAverage = self.executionTime
738 self.oldAverage = (self.executionTime + self.count *
741 self.oldAverage = (self.executionTime + self.count *
739 self.oldAverage) / (self.count + 1.0)
742 self.oldAverage) / (self.count + 1.0)
740 self.count = self.count + 1.0
743 self.count = self.count + 1.0
741 return
744 return
742
745
743 def writeData(self):
746 def writeData(self):
744 if self.dataOut.type != 'Voltage':
747 if self.dataOut.type != 'Voltage':
745 raise 'Digital RF cannot be used with this data type'
748 raise 'Digital RF cannot be used with this data type'
746 for channel in self.dataOut.channelList:
749 for channel in self.dataOut.channelList:
747 for i in range(self.dataOut.nFFTPoints):
750 for i in range(self.dataOut.nFFTPoints):
748 self.arr_data[1][channel * self.dataOut.nFFTPoints +
751 self.arr_data[1][channel * self.dataOut.nFFTPoints +
749 i]['r'] = self.dataOut.data[channel][i].real
752 i]['r'] = self.dataOut.data[channel][i].real
750 self.arr_data[1][channel * self.dataOut.nFFTPoints +
753 self.arr_data[1][channel * self.dataOut.nFFTPoints +
751 i]['i'] = self.dataOut.data[channel][i].imag
754 i]['i'] = self.dataOut.data[channel][i].imag
752 else:
755 else:
753 for i in range(self.dataOut.systemHeaderObj.nSamples):
756 for i in range(self.dataOut.systemHeaderObj.nSamples):
754 for channel in self.dataOut.channelList:
757 for channel in self.dataOut.channelList:
755 self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real
758 self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real
756 self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag
759 self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag
757
760
758 def f(): return self.digitalWriteObj.rf_write(self.arr_data)
761 def f(): return self.digitalWriteObj.rf_write(self.arr_data)
759 self.timeit(f)
762 self.timeit(f)
760
763
761 return
764 return
762
765
763 def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=1000, dirCadence=36000, metadataCadence=1, **kwargs):
766 def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=1000, dirCadence=36000, metadataCadence=1, **kwargs):
764 '''
767 '''
765 This method will be called many times so here you should put all your code
768 This method will be called many times so here you should put all your code
766 Inputs:
769 Inputs:
767 dataOut: object with the data
770 dataOut: object with the data
768 '''
771 '''
769 # print dataOut.__dict__
772 # print dataOut.__dict__
770 self.dataOut = dataOut
773 self.dataOut = dataOut
771 if not self.isConfig:
774 if not self.isConfig:
772 self.setup(dataOut, path, frequency, fileCadence,
775 self.setup(dataOut, path, frequency, fileCadence,
773 dirCadence, metadataCadence, **kwargs)
776 dirCadence, metadataCadence, **kwargs)
774 self.writeMetadata()
777 self.writeMetadata()
775
778
776 self.writeData()
779 self.writeData()
777
780
778 ## self.currentSample += 1
781 ## self.currentSample += 1
779 # if self.dataOut.flagDataAsBlock or self.currentSample == 1:
782 # if self.dataOut.flagDataAsBlock or self.currentSample == 1:
780 # self.writeMetadata()
783 # self.writeMetadata()
781 ## if self.currentSample == self.__nProfiles: self.currentSample = 0
784 ## if self.currentSample == self.__nProfiles: self.currentSample = 0
782
785
783 def close(self):
786 def close(self):
784 print '[Writing] - Closing files '
787 print '[Writing] - Closing files '
785 print 'Average of writing to digital rf format is ', self.oldAverage * 1000
788 print 'Average of writing to digital rf format is ', self.oldAverage * 1000
786 try:
789 try:
787 self.digitalWriteObj.close()
790 self.digitalWriteObj.close()
788 except:
791 except:
789 pass
792 pass
790
793
791
794
792 # raise
795 # raise
793 if __name__ == '__main__':
796 if __name__ == '__main__':
794
797
795 readObj = DigitalRFReader()
798 readObj = DigitalRFReader()
796
799
797 while True:
800 while True:
798 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
801 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
799 # readObj.printInfo()
802 # readObj.printInfo()
800 # readObj.printNumberOfBlock()
803 # readObj.printNumberOfBlock()
General Comments 0
You need to be logged in to leave comments. Login now