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