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