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