This diff has been collapsed as it changes many lines, (590 lines changed) Show them Hide them | |||
@@ -0,0 +1,590 | |||
|
1 | ''' | |
|
2 | Created on Jul 3, 2014 | |
|
3 | ||
|
4 | @author: roj-idl71 | |
|
5 | ''' | |
|
6 | import os | |
|
7 | import datetime | |
|
8 | import numpy | |
|
9 | ||
|
10 | try: | |
|
11 | from gevent import sleep | |
|
12 | except: | |
|
13 | from time import sleep | |
|
14 | ||
|
15 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
|
16 | from schainpy.model.data.jrodata import Voltage | |
|
17 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
18 | ||
|
19 | try: | |
|
20 | import digital_rf | |
|
21 | except: | |
|
22 | print 'You should install "digital_rf" module if you want to read Digital RF data' | |
|
23 | ||
|
24 | class DigitalRFReader(ProcessingUnit): | |
|
25 | ''' | |
|
26 | classdocs | |
|
27 | ''' | |
|
28 | ||
|
29 | def __init__(self, **kwargs): | |
|
30 | ''' | |
|
31 | Constructor | |
|
32 | ''' | |
|
33 | ||
|
34 | ProcessingUnit.__init__(self, **kwargs) | |
|
35 | ||
|
36 | self.dataOut = Voltage() | |
|
37 | self.__printInfo = True | |
|
38 | self.__flagDiscontinuousBlock = False | |
|
39 | self.__bufferIndex = 9999999 | |
|
40 | ||
|
41 | self.__ippKm = None | |
|
42 | self.__codeType = 0 | |
|
43 | self.__nCode = None | |
|
44 | self.__nBaud = None | |
|
45 | self.__code = None | |
|
46 | ||
|
47 | def __getCurrentSecond(self): | |
|
48 | ||
|
49 | return self.__thisUnixSample/self.__sample_rate | |
|
50 | ||
|
51 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") | |
|
52 | ||
|
53 | def __setFileHeader(self): | |
|
54 | ''' | |
|
55 | In this method will be initialized every parameter of dataOut object (header, no data) | |
|
56 | ''' | |
|
57 | ippSeconds = 1.0*self.__nSamples/self.__sample_rate | |
|
58 | ||
|
59 | nProfiles = 1.0/ippSeconds #Number of profiles in one second | |
|
60 | ||
|
61 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ippKm=self.__ippKm, | |
|
62 | txA=0, | |
|
63 | txB=0, | |
|
64 | nWindows=1, | |
|
65 | nHeights=self.__nSamples, | |
|
66 | firstHeight=self.__firstHeigth, | |
|
67 | deltaHeight=self.__deltaHeigth, | |
|
68 | codeType=self.__codeType, | |
|
69 | nCode=self.__nCode, nBaud=self.__nBaud, | |
|
70 | code = self.__code) | |
|
71 | ||
|
72 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, | |
|
73 | nProfiles=nProfiles, | |
|
74 | nChannels=len(self.__channelList), | |
|
75 | adcResolution=14) | |
|
76 | ||
|
77 | self.dataOut.type = "Voltage" | |
|
78 | ||
|
79 | self.dataOut.data = None | |
|
80 | ||
|
81 | self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
|
82 | ||
|
83 | # self.dataOut.nChannels = 0 | |
|
84 | ||
|
85 | # self.dataOut.nHeights = 0 | |
|
86 | ||
|
87 | self.dataOut.nProfiles = nProfiles | |
|
88 | ||
|
89 | self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth | |
|
90 | ||
|
91 | self.dataOut.channelList = self.__channelList | |
|
92 | ||
|
93 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
|
94 | ||
|
95 | # self.dataOut.channelIndexList = None | |
|
96 | ||
|
97 | self.dataOut.flagNoData = True | |
|
98 | ||
|
99 | #Set to TRUE if the data is discontinuous | |
|
100 | self.dataOut.flagDiscontinuousBlock = False | |
|
101 | ||
|
102 | self.dataOut.utctime = None | |
|
103 | ||
|
104 | self.dataOut.timeZone = self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime | |
|
105 | ||
|
106 | self.dataOut.dstFlag = 0 | |
|
107 | ||
|
108 | self.dataOut.errorCount = 0 | |
|
109 | ||
|
110 | self.dataOut.nCohInt = 1 | |
|
111 | ||
|
112 | self.dataOut.flagDecodeData = False #asumo que la data esta decodificada | |
|
113 | ||
|
114 | self.dataOut.flagDeflipData = False #asumo que la data esta sin flip | |
|
115 | ||
|
116 | self.dataOut.flagShiftFFT = False | |
|
117 | ||
|
118 | self.dataOut.ippSeconds = ippSeconds | |
|
119 | ||
|
120 | #Time interval between profiles | |
|
121 | #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
|
122 | ||
|
123 | self.dataOut.frequency = self.__frequency | |
|
124 | ||
|
125 | self.dataOut.realtime = self.__online | |
|
126 | ||
|
127 | def findDatafiles(self, path, startDate=None, endDate=None): | |
|
128 | ||
|
129 | if not os.path.isdir(path): | |
|
130 | return [] | |
|
131 | ||
|
132 | try: | |
|
133 | digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True) | |
|
134 | except: | |
|
135 | digitalReadObj = digital_rf.DigitalRFReader(path) | |
|
136 | ||
|
137 | channelNameList = digitalReadObj.get_channels() | |
|
138 | ||
|
139 | if not channelNameList: | |
|
140 | return [] | |
|
141 | ||
|
142 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) | |
|
143 | ||
|
144 | sample_rate = metadata_dict['sample_rate'][0] | |
|
145 | ||
|
146 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) | |
|
147 | ||
|
148 | try: | |
|
149 | timezone = this_metadata_file['timezone'].value | |
|
150 | except: | |
|
151 | timezone = 0 | |
|
152 | ||
|
153 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone | |
|
154 | ||
|
155 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) | |
|
156 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) | |
|
157 | ||
|
158 | if not startDate: | |
|
159 | startDate = startDatetime.date() | |
|
160 | ||
|
161 | if not endDate: | |
|
162 | endDate = endDatatime.date() | |
|
163 | ||
|
164 | dateList = [] | |
|
165 | ||
|
166 | thisDatetime = startDatetime | |
|
167 | ||
|
168 | while(thisDatetime<=endDatatime): | |
|
169 | ||
|
170 | thisDate = thisDatetime.date() | |
|
171 | ||
|
172 | if thisDate < startDate: | |
|
173 | continue | |
|
174 | ||
|
175 | if thisDate > endDate: | |
|
176 | break | |
|
177 | ||
|
178 | dateList.append(thisDate) | |
|
179 | thisDatetime += datetime.timedelta(1) | |
|
180 | ||
|
181 | return dateList | |
|
182 | ||
|
183 | def setup(self, path = None, | |
|
184 | startDate = None, | |
|
185 | endDate = None, | |
|
186 | startTime = datetime.time(0,0,0), | |
|
187 | endTime = datetime.time(23,59,59), | |
|
188 | channelList = None, | |
|
189 | nSamples = None, | |
|
190 | ippKm = 60, | |
|
191 | online = False, | |
|
192 | delay = 60, | |
|
193 | buffer_size = 1024, | |
|
194 | **kwargs): | |
|
195 | ''' | |
|
196 | In this method we should set all initial parameters. | |
|
197 | ||
|
198 | Inputs: | |
|
199 | path | |
|
200 | startDate | |
|
201 | endDate | |
|
202 | startTime | |
|
203 | endTime | |
|
204 | set | |
|
205 | expLabel | |
|
206 | ext | |
|
207 | online | |
|
208 | delay | |
|
209 | ''' | |
|
210 | ||
|
211 | if not os.path.isdir(path): | |
|
212 | raise ValueError, "[Reading] Directory %s does not exist" %path | |
|
213 | ||
|
214 | try: | |
|
215 | self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True) | |
|
216 | except: | |
|
217 | self.digitalReadObj = digital_rf.DigitalRFReader(path) | |
|
218 | ||
|
219 | channelNameList = self.digitalReadObj.get_channels() | |
|
220 | ||
|
221 | if not channelNameList: | |
|
222 | raise ValueError, "[Reading] Directory %s does not have any files" %path | |
|
223 | ||
|
224 | if not channelList: | |
|
225 | channelList = range(len(channelNameList)) | |
|
226 | ||
|
227 | ########## Reading metadata ###################### | |
|
228 | ||
|
229 | metadata_dict = self.digitalReadObj.get_properties(channelNameList[channelList[0]]) | |
|
230 | ||
|
231 | self.__sample_rate = metadata_dict['sample_rate_numerator'] / metadata_dict['sample_rate_denominator'] | |
|
232 | # self.__samples_per_file = metadata_dict['samples_per_file'][0] | |
|
233 | self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15? | |
|
234 | ||
|
235 | this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]]) | |
|
236 | metadata_bounds = this_metadata_file.get_bounds() | |
|
237 | self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ##GET FIRST HEADER | |
|
238 | ||
|
239 | self.__frequency = None | |
|
240 | try: | |
|
241 | self.__frequency = self.fixed_metadata_dict['frequency'] | |
|
242 | except: | |
|
243 | self.__frequency = None | |
|
244 | ||
|
245 | try: | |
|
246 | self.__timezone = self.fixed_metadata_dict['timezone'] | |
|
247 | except: | |
|
248 | self.__timezone = 0 | |
|
249 | ||
|
250 | self.__firstHeigth = 0 | |
|
251 | ||
|
252 | ||
|
253 | try: | |
|
254 | codeType = self.fixed_metadata_dict['codeType'] | |
|
255 | except: | |
|
256 | codeType = 0 | |
|
257 | ||
|
258 | nCode = 1 | |
|
259 | nBaud = 1 | |
|
260 | code = numpy.ones((nCode, nBaud), dtype=numpy.int) | |
|
261 | ||
|
262 | if codeType: | |
|
263 | nCode = self.fixed_metadata_dict['nCode'] | |
|
264 | nBaud = self.fixed_metadata_dict['nBaud'] | |
|
265 | code = self.fixed_metadata_dict['code'] | |
|
266 | ||
|
267 | if not ippKm: | |
|
268 | try: | |
|
269 | #seconds to km | |
|
270 | ippKm = 1e6*0.15*self.fixed_metadata_dict['ipp'] | |
|
271 | except: | |
|
272 | ippKm = None | |
|
273 | #################################################### | |
|
274 | startUTCSecond = None | |
|
275 | endUTCSecond = None | |
|
276 | ||
|
277 | if startDate: | |
|
278 | startDatetime = datetime.datetime.combine(startDate, startTime) | |
|
279 | startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone | |
|
280 | ||
|
281 | if endDate: | |
|
282 | endDatetime = datetime.datetime.combine(endDate, endTime) | |
|
283 | endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone | |
|
284 | ||
|
285 | start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]]) | |
|
286 | ||
|
287 | if not startUTCSecond: | |
|
288 | startUTCSecond = start_index/self.__sample_rate | |
|
289 | ||
|
290 | if start_index > startUTCSecond*self.__sample_rate: | |
|
291 | startUTCSecond = start_index/self.__sample_rate | |
|
292 | ||
|
293 | if not endUTCSecond: | |
|
294 | endUTCSecond = end_index/self.__sample_rate | |
|
295 | ||
|
296 | if end_index < endUTCSecond*self.__sample_rate: | |
|
297 | endUTCSecond = end_index/self.__sample_rate | |
|
298 | ||
|
299 | if not nSamples: | |
|
300 | if not ippKm: | |
|
301 | raise ValueError, "[Reading] nSamples or ippKm should be defined" | |
|
302 | nSamples = int(ippKm / (1e6*0.15/self.__sample_rate)) | |
|
303 | ||
|
304 | channelBoundList = [] | |
|
305 | channelNameListFiltered = [] | |
|
306 | ||
|
307 | for thisIndexChannel in channelList: | |
|
308 | thisChannelName = channelNameList[thisIndexChannel] | |
|
309 | start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName) | |
|
310 | channelBoundList.append((start_index, end_index)) | |
|
311 | channelNameListFiltered.append(thisChannelName) | |
|
312 | ||
|
313 | self.profileIndex = 0 | |
|
314 | ||
|
315 | self.__delay = delay | |
|
316 | self.__ippKm = ippKm | |
|
317 | self.__codeType = codeType | |
|
318 | self.__nCode = nCode | |
|
319 | self.__nBaud = nBaud | |
|
320 | self.__code = code | |
|
321 | ||
|
322 | self.__datapath = path | |
|
323 | self.__online = online | |
|
324 | self.__channelList = channelList | |
|
325 | self.__channelNameList = channelNameListFiltered | |
|
326 | self.__channelBoundList = channelBoundList | |
|
327 | self.__nSamples = nSamples | |
|
328 | self.__samples_to_read = long(buffer_size*nSamples) #FIJO: AHORA 40 | |
|
329 | self.__nChannels = len(self.__channelList) | |
|
330 | ||
|
331 | self.__startUTCSecond = startUTCSecond | |
|
332 | self.__endUTCSecond = endUTCSecond | |
|
333 | ||
|
334 | self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate #Time interval | |
|
335 | ||
|
336 | if online: | |
|
337 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) | |
|
338 | startUTCSecond = numpy.floor(endUTCSecond) | |
|
339 | ||
|
340 | 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 | |
|
341 | ||
|
342 | self.__data_buffer = numpy.zeros((self.__nChannels, self.__samples_to_read), dtype = numpy.complex) | |
|
343 | ||
|
344 | self.__setFileHeader() | |
|
345 | self.isConfig = True | |
|
346 | ||
|
347 | print "[Reading] Digital RF Data was found from %s to %s " %( | |
|
348 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
349 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
350 | ) | |
|
351 | ||
|
352 | print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), | |
|
353 | datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone) | |
|
354 | ) | |
|
355 | ||
|
356 | def __reload(self): | |
|
357 | ||
|
358 | # print "%s not in range [%s, %s]" %( | |
|
359 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
360 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
361 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
362 | # ) | |
|
363 | print "[Reading] reloading metadata ..." | |
|
364 | ||
|
365 | try: | |
|
366 | self.digitalReadObj.reload(complete_update=True) | |
|
367 | except: | |
|
368 | self.digitalReadObj.reload() | |
|
369 | ||
|
370 | start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]]) | |
|
371 | ||
|
372 | if start_index > self.__startUTCSecond*self.__sample_rate: | |
|
373 | self.__startUTCSecond = 1.0*start_index/self.__sample_rate | |
|
374 | ||
|
375 | if end_index > self.__endUTCSecond*self.__sample_rate: | |
|
376 | self.__endUTCSecond = 1.0*end_index/self.__sample_rate | |
|
377 | ||
|
378 | print "[Reading] New timerange found [%s, %s] " %( | |
|
379 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
380 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
381 | ) | |
|
382 | ||
|
383 | return True | |
|
384 | ||
|
385 | return False | |
|
386 | ||
|
387 | def __readNextBlock(self, seconds=30, volt_scale = 218776): | |
|
388 | ''' | |
|
389 | ''' | |
|
390 | ||
|
391 | #Set the next data | |
|
392 | self.__flagDiscontinuousBlock = False | |
|
393 | self.__thisUnixSample += self.__samples_to_read | |
|
394 | ||
|
395 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: | |
|
396 | print "[Reading] There are no more data into selected time-range" | |
|
397 | if self.__online: | |
|
398 | self.__reload() | |
|
399 | else: | |
|
400 | return False | |
|
401 | ||
|
402 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: | |
|
403 | return False | |
|
404 | self.__thisUnixSample -= self.__samples_to_read | |
|
405 | ||
|
406 | indexChannel = 0 | |
|
407 | ||
|
408 | dataOk = False | |
|
409 | ||
|
410 | for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS? | |
|
411 | ||
|
412 | try: | |
|
413 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, | |
|
414 | self.__samples_to_read, | |
|
415 | thisChannelName) | |
|
416 | except IOError, e: | |
|
417 | #read next profile | |
|
418 | self.__flagDiscontinuousBlock = True | |
|
419 | print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e | |
|
420 | break | |
|
421 | ||
|
422 | if result.shape[0] != self.__samples_to_read: | |
|
423 | self.__flagDiscontinuousBlock = True | |
|
424 | print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
425 | result.shape[0], | |
|
426 | self.__samples_to_read) | |
|
427 | break | |
|
428 | ||
|
429 | self.__data_buffer[indexChannel,:] = result*volt_scale | |
|
430 | ||
|
431 | indexChannel += 1 | |
|
432 | ||
|
433 | dataOk = True | |
|
434 | ||
|
435 | self.__utctime = self.__thisUnixSample/self.__sample_rate | |
|
436 | ||
|
437 | if not dataOk: | |
|
438 | return False | |
|
439 | ||
|
440 | print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
441 | self.__samples_to_read, | |
|
442 | self.__timeInterval) | |
|
443 | ||
|
444 | self.__bufferIndex = 0 | |
|
445 | ||
|
446 | return True | |
|
447 | ||
|
448 | def __isBufferEmpty(self): | |
|
449 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40 | |
|
450 | ||
|
451 | def getData(self, seconds=30, nTries=5): | |
|
452 | ||
|
453 | ''' | |
|
454 | This method gets the data from files and put the data into the dataOut object | |
|
455 | ||
|
456 | In addition, increase el the buffer counter in one. | |
|
457 | ||
|
458 | Return: | |
|
459 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
|
460 | buffer. Si no hay mas archivos a leer retorna None. | |
|
461 | ||
|
462 | Affected: | |
|
463 | self.dataOut | |
|
464 | self.profileIndex | |
|
465 | self.flagDiscontinuousBlock | |
|
466 | self.flagIsNewBlock | |
|
467 | ''' | |
|
468 | ||
|
469 | err_counter = 0 | |
|
470 | self.dataOut.flagNoData = True | |
|
471 | ||
|
472 | if self.__isBufferEmpty(): | |
|
473 | ||
|
474 | self.__flagDiscontinuousBlock = False | |
|
475 | ||
|
476 | while True: | |
|
477 | if self.__readNextBlock(): | |
|
478 | break | |
|
479 | if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate: | |
|
480 | return False | |
|
481 | ||
|
482 | if self.__flagDiscontinuousBlock: | |
|
483 | print '[Reading] discontinuous block found ... continue with the next block' | |
|
484 | continue | |
|
485 | ||
|
486 | if not self.__online: | |
|
487 | return False | |
|
488 | ||
|
489 | err_counter += 1 | |
|
490 | if err_counter > nTries: | |
|
491 | return False | |
|
492 | ||
|
493 | print '[Reading] waiting %d seconds to read a new block' %seconds | |
|
494 | sleep(seconds) | |
|
495 | ||
|
496 | self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples] | |
|
497 | self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate | |
|
498 | self.dataOut.flagNoData = False | |
|
499 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
|
500 | self.dataOut.profileIndex = self.profileIndex | |
|
501 | ||
|
502 | self.__bufferIndex += self.__nSamples | |
|
503 | self.profileIndex += 1 | |
|
504 | ||
|
505 | if self.profileIndex == self.dataOut.nProfiles: | |
|
506 | self.profileIndex = 0 | |
|
507 | ||
|
508 | return True | |
|
509 | ||
|
510 | def printInfo(self): | |
|
511 | ''' | |
|
512 | ''' | |
|
513 | if self.__printInfo == False: | |
|
514 | return | |
|
515 | ||
|
516 | # self.systemHeaderObj.printInfo() | |
|
517 | # self.radarControllerHeaderObj.printInfo() | |
|
518 | ||
|
519 | self.__printInfo = False | |
|
520 | ||
|
521 | def printNumberOfBlock(self): | |
|
522 | ''' | |
|
523 | ''' | |
|
524 | return | |
|
525 | #print self.profileIndex | |
|
526 | ||
|
527 | def run(self, **kwargs): | |
|
528 | ''' | |
|
529 | This method will be called many times so here you should put all your code | |
|
530 | ''' | |
|
531 | ||
|
532 | if not self.isConfig: | |
|
533 | self.setup(**kwargs) | |
|
534 | ||
|
535 | self.getData(seconds=self.__delay) | |
|
536 | ||
|
537 | return | |
|
538 | ||
|
539 | class DigitalRFWriter(Operation): | |
|
540 | ''' | |
|
541 | classdocs | |
|
542 | ''' | |
|
543 | ||
|
544 | def __init__(self, **kwargs): | |
|
545 | ''' | |
|
546 | Constructor | |
|
547 | ''' | |
|
548 | Operation.__init__(self, **kwargs) | |
|
549 | self.dataOut = None | |
|
550 | ||
|
551 | def setup(self, dataIn, path, blocksPerFile, set=0, ext=None): | |
|
552 | ''' | |
|
553 | In this method we should set all initial parameters. | |
|
554 | ||
|
555 | Input: | |
|
556 | dataIn : Input data will also be outputa data | |
|
557 | ||
|
558 | ''' | |
|
559 | self.dataOut = dataIn | |
|
560 | ||
|
561 | ||
|
562 | ||
|
563 | ||
|
564 | ||
|
565 | self.isConfig = True | |
|
566 | ||
|
567 | return | |
|
568 | ||
|
569 | def run(self, dataIn, **kwargs): | |
|
570 | ''' | |
|
571 | This method will be called many times so here you should put all your code | |
|
572 | ||
|
573 | Inputs: | |
|
574 | ||
|
575 | dataIn : object with the data | |
|
576 | ||
|
577 | ''' | |
|
578 | ||
|
579 | if not self.isConfig: | |
|
580 | self.setup(dataIn, **kwargs) | |
|
581 | ||
|
582 | ||
|
583 | if __name__ == '__main__': | |
|
584 | ||
|
585 | readObj = DigitalRFReader() | |
|
586 | ||
|
587 | while True: | |
|
588 | readObj.run(path='/home/jchavez/jicamarca/mocked_data/') | |
|
589 | # readObj.printInfo() | |
|
590 | readObj.printNumberOfBlock() |
@@ -0,0 +1,118 | |||
|
1 | #!/usr/bin/env python | |
|
2 | ''' | |
|
3 | Created on Jul 7, 2014 | |
|
4 | ||
|
5 | @author: roj-idl71 | |
|
6 | ''' | |
|
7 | import os, sys | |
|
8 | ||
|
9 | from schainpy.controller import Project | |
|
10 | ||
|
11 | def main(): | |
|
12 | ||
|
13 | desc = "Testing USRP data reader" | |
|
14 | filename = "schain.xml" | |
|
15 | figpath = "./" | |
|
16 | remotefolder = "/home/wmaster/graficos" | |
|
17 | ||
|
18 | #this controller object save all user configuration and then execute each module | |
|
19 | #with their parameters. | |
|
20 | controllerObj = Project() | |
|
21 | ||
|
22 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
23 | ||
|
24 | #Creating a reader object with its parameters | |
|
25 | #schainpy.model.io.jroIO_usrp.USRPReader.setup() | |
|
26 | readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRF', | |
|
27 | path='/home/jchavez/jicamarca/mocked_data/', | |
|
28 | startDate='2000/07/03', | |
|
29 | endDate='2017/07/03', | |
|
30 | startTime='00:00:00', | |
|
31 | endTime='23:59:59', | |
|
32 | online=0, | |
|
33 | ippKm = 60) | |
|
34 | ||
|
35 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', | |
|
36 | inputId=readUnitConfObj.getId()) | |
|
37 | ||
|
38 | # opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
|
39 | # opObj10.addParameter(name='minHei', value='0', format='float') | |
|
40 | # opObj10.addParameter(name='maxHei', value='8', format='float') | |
|
41 | ||
|
42 | # opObj10 = procUnitConfObj0.addOperation(name='setH0') | |
|
43 | # opObj10.addParameter(name='h0', value='5.4', format='float') | |
|
44 | ||
|
45 | # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external') | |
|
46 | # opObj10.addParameter(name='code', value='1,-1', format='intlist') | |
|
47 | # opObj10.addParameter(name='nCode', value='2', format='float') | |
|
48 | # opObj10.addParameter(name='nBaud', value='1', format='float') | |
|
49 | ||
|
50 | opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
|
51 | opObj10.addParameter(name='n', value='1', format='float') | |
|
52 | ||
|
53 | opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='external') | |
|
54 | opObj11.addParameter(name='id', value='121', format='int') | |
|
55 | opObj11.addParameter(name='wintitle', value='Scope', format='str') | |
|
56 | ||
|
57 | # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', | |
|
58 | # inputId=procUnitConfObj0.getId()) | |
|
59 | ||
|
60 | # #Creating a processing object with its parameters | |
|
61 | # #schainpy.model.proc.jroproc_spectra.SpectraProc.run() | |
|
62 | # #If you need to add more parameters can use the "addParameter method" | |
|
63 | # procUnitConfObj1.addParameter(name='nFFTPoints', value='8', format='int') | |
|
64 | # procUnitConfObj1.addParameter(name='pairsList', value='(0,1)', format='pairslist') | |
|
65 | ||
|
66 | # opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') | |
|
67 | # opObj10.addParameter(name='n', value='2', format='float') | |
|
68 | # | |
|
69 | #Using internal methods | |
|
70 | #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels() | |
|
71 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
|
72 | # opObj10.addParameter(name='channelList', value='0,1', format='intlist') | |
|
73 | ||
|
74 | #Using internal methods | |
|
75 | #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights() | |
|
76 | # opObj10 = procUnitConfObj1.addOperation(name='selectHeights') | |
|
77 | # opObj10.addParameter(name='minHei', value='90', format='float') | |
|
78 | # opObj10.addParameter(name='maxHei', value='180', format='float') | |
|
79 | ||
|
80 | #Using external methods (new modules) | |
|
81 | # #schainpy.model.proc.jroproc_spectra.IncohInt.setup() | |
|
82 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
83 | # opObj12.addParameter(name='n', value='1', format='int') | |
|
84 | ||
|
85 | #Using external methods (new modules) | |
|
86 | #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup() | |
|
87 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
|
88 | # opObj11.addParameter(name='id', value='11', format='int') | |
|
89 | # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
|
90 | # opObj11.addParameter(name='zmin', value='0', format='int') | |
|
91 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
|
92 | # opObj11.addParameter(name='save', value='1', format='int') | |
|
93 | # opObj11.addParameter(name='xmin', value='-20', format='float') | |
|
94 | # opObj11.addParameter(name='xmax', value='20', format='float') | |
|
95 | ||
|
96 | #Using external methods (new modules) | |
|
97 | #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup() | |
|
98 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
|
99 | # opObj11.addParameter(name='id', value='30', format='int') | |
|
100 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') | |
|
101 | # # opObj11.addParameter(name='zmin', value='0', format='int') | |
|
102 | # # opObj11.addParameter(name='zmax', value='90', format='int') | |
|
103 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
104 | # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int') | |
|
105 | # opObj11.addParameter(name='xmin', value='19.5', format='float') | |
|
106 | # opObj11.addParameter(name='xmax', value='20', format='float') | |
|
107 | ||
|
108 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') | |
|
109 | # opObj11.addParameter(name='id', value='3', format='int') | |
|
110 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') | |
|
111 | # opObj11.addParameter(name='zmin', value='30', format='int') | |
|
112 | # opObj11.addParameter(name='zmax', value='120', format='int') | |
|
113 | # opObj11.addParameter(name='pairsList', value='(0,1)', format='pairslist') | |
|
114 | ||
|
115 | controllerObj.start() | |
|
116 | ||
|
117 | if __name__ == '__main__': | |
|
118 | main() |
@@ -50,7 +50,6 class ProjectParms(): | |||
|
50 | 50 | indexDatatype = 2 |
|
51 | 51 | if 'usrp' in self.datatype.lower(): |
|
52 | 52 | indexDatatype = 3 |
|
53 | ||
|
54 | 53 | return indexDatatype |
|
55 | 54 | |
|
56 | 55 | def getExt(self): |
@@ -65,7 +64,6 class ProjectParms(): | |||
|
65 | 64 | ext = '.fits' |
|
66 | 65 | if self.datatype.lower() == 'usrp': |
|
67 | 66 | ext = '.hdf5' |
|
68 | ||
|
69 | 67 | return ext |
|
70 | 68 | |
|
71 | 69 | def set(self, project_name, datatype, ext, dpath, online, |
@@ -13,8 +13,8 class Scope(Figure): | |||
|
13 | 13 | |
|
14 | 14 | isConfig = None |
|
15 | 15 | |
|
16 | def __init__(self): | |
|
17 | ||
|
16 | def __init__(self, **kwargs): | |
|
17 | Figure.__init__(self, **kwargs) | |
|
18 | 18 | self.isConfig = False |
|
19 | 19 | self.WIDTH = 300 |
|
20 | 20 | self.HEIGHT = 200 |
@@ -113,7 +113,7 class Scope(Figure): | |||
|
113 | 113 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
114 | 114 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
115 | 115 | figpath='./', figfile=None, show=True, wr_period=1, |
|
116 | ftp=False, server=None, folder=None, username=None, password=None, type='power'): | |
|
116 | ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs): | |
|
117 | 117 | |
|
118 | 118 | """ |
|
119 | 119 |
@@ -8,7 +8,7 from jroIO_voltage import * | |||
|
8 | 8 | from jroIO_spectra import * |
|
9 | 9 | from jroIO_heispectra import * |
|
10 | 10 | from jroIO_usrp import * |
|
11 | ||
|
11 | from jroIO_digitalRF import * | |
|
12 | 12 | from jroIO_kamisr import * |
|
13 | 13 | from jroIO_param import * |
|
14 | 14 | from jroIO_hf import * |
@@ -1,1 +1,1 | |||
|
1 | <Project description="HF_EXAMPLE" id="191" name="test01"><ReadUnit datatype="Spectra" id="1911" inputId="0" name="SpectraReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="SpectraReader" /><Parameter format="str" id="191112" name="path" value="/home/nanosat/data/sp1_f0" /><Parameter format="date" id="191113" name="startDate" value="2017/01/28" /><Parameter format="date" id="191114" name="endDate" value="2017/01/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="cursor" value="5" /><Parameter format="int" id="191119" name="skip" value="177" /><Parameter format="int" id="191120" name="walk" value="1" /><Parameter format="int" id="191121" name="verbose" value="1" /><Parameter format="int" id="191122" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="Parameters" id="1913" inputId="1911" name="ParametersProc"><Operation id="19131" name="run" priority="1" type="self" /><Operation id="19132" name="SpectralMoments" priority="2" type="other" /><Operation id="19133" name="PublishData" priority="3" type="other"><Parameter format="int" id="191331" name="zeromq" value="1" /><Parameter format="bool" id="191332" name="verbose" value="0" /><Parameter format="int" id="191333" name="delay" value="0" /></Operation></ProcUnit><ProcUnit datatype="Spectra" id="1912" inputId="1911" name="SpectraProc"><Operation id="19121" name="run" priority="1" type="self" /></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="/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="ippKm" value="60" /><Parameter format="int" id="191119" 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="CohInt" priority="2" type="external"><Parameter format="float" id="191221" name="n" value="1" /></Operation><Operation id="19123" name="Scope" priority="3" type="external"><Parameter format="int" id="191231" name="id" value="121" /><Parameter format="str" id="191232" name="wintitle" value="Scope" /></Operation></ProcUnit></Project> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now