##// END OF EJS Templates
update jroIO_digitalRF.py
avaldez -
r1263:6b55a7081d5a
parent child
Show More
@@ -17,6 +17,7 import datetime
17 17 import numpy
18 18 import timeit
19 19 from fractions import Fraction
20 from time import time
20 21
21 22 import schainpy.admin
22 23 from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader
@@ -42,17 +43,18 class DigitalRFReader(ProcessingUnit):
42 43
43 44 ProcessingUnit.__init__(self)
44 45
45 self.dataOut = Voltage()
46 self.__printInfo = True
46 self.dataOut = Voltage()
47 self.__printInfo = True
47 48 self.__flagDiscontinuousBlock = False
48 49 self.__bufferIndex = 9999999
49 self.__ippKm = None
50 self.__codeType = 0
51 self.__nCode = None
52 self.__nBaud = None
53 self.__code = None
54 self.dtype = None
55 self.oldAverage = None
50 self.__codeType = 0
51 self.__ippKm = None
52 self.__nCode = None
53 self.__nBaud = None
54 self.__code = None
55 self.dtype = None
56 self.oldAverage = None
57 self.path = None
56 58
57 59 def close(self):
58 60 print('Average of writing to digital rf format is ', self.oldAverage * 1000)
@@ -95,9 +97,9 class DigitalRFReader(ProcessingUnit):
95 97 nChannels=len(
96 98 self.__channelList),
97 99 adcResolution=14)
98 self.dataOut.type = "Voltage"
100 self.dataOut.type = "Voltage"
99 101
100 self.dataOut.data = None
102 self.dataOut.data = None
101 103
102 104 self.dataOut.dtype = self.dtype
103 105
@@ -105,32 +107,32 class DigitalRFReader(ProcessingUnit):
105 107
106 108 # self.dataOut.nHeights = 0
107 109
108 self.dataOut.nProfiles = int(nProfiles)
110 self.dataOut.nProfiles = int(nProfiles)
109 111
110 self.dataOut.heightList = self.__firstHeigth + \
112 self.dataOut.heightList = self.__firstHeigth + \
111 113 numpy.arange(self.__nSamples, dtype=numpy.float) * \
112 114 self.__deltaHeigth
113 115
114 116 self.dataOut.channelList = list(range(self.__num_subchannels))
115 117
116 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
118 self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights()
117 119
118 120 # self.dataOut.channelIndexList = None
119 121
120 self.dataOut.flagNoData = True
122 self.dataOut.flagNoData = True
121 123
122 124 self.dataOut.flagDataAsBlock = False
123 125 # Set to TRUE if the data is discontinuous
124 126 self.dataOut.flagDiscontinuousBlock = False
125 127
126 self.dataOut.utctime = None
128 self.dataOut.utctime = None
127 129
128 130 # timezone like jroheader, difference in minutes between UTC and localtime
129 self.dataOut.timeZone = self.__timezone / 60
131 self.dataOut.timeZone = self.__timezone / 60
130 132
131 self.dataOut.dstFlag = 0
133 self.dataOut.dstFlag = 0
132 134
133 self.dataOut.errorCount = 0
135 self.dataOut.errorCount = 0
134 136
135 137 try:
136 138 self.dataOut.nCohInt = self.fixed_metadata_dict.get(
@@ -143,9 +145,9 class DigitalRFReader(ProcessingUnit):
143 145 # asumo que la data esta sin flip
144 146 self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData']
145 147
146 self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT']
148 self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT']
147 149
148 self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime']
150 self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime']
149 151 except:
150 152 pass
151 153
@@ -154,9 +156,9 class DigitalRFReader(ProcessingUnit):
154 156 # Time interval between profiles
155 157 # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt
156 158
157 self.dataOut.frequency = self.__frequency
159 self.dataOut.frequency = self.__frequency
158 160
159 self.dataOut.realtime = self.__online
161 self.dataOut.realtime = self.__online
160 162
161 163 def findDatafiles(self, path, startDate=None, endDate=None):
162 164
@@ -169,46 +171,46 class DigitalRFReader(ProcessingUnit):
169 171 except:
170 172 digitalReadObj = digital_rf.DigitalRFReader(path)
171 173
172 channelNameList = digitalReadObj.get_channels()
174 channelNameList = digitalReadObj.get_channels()
173 175
174 176 if not channelNameList:
175 177 return []
176 178
177 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
179 metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0])
178 180
179 sample_rate = metadata_dict['sample_rate'][0]
181 sample_rate = metadata_dict['sample_rate'][0]
180 182
181 183 this_metadata_file = digitalReadObj.get_metadata(channelNameList[0])
182 184
183 185 try:
184 timezone = this_metadata_file['timezone'].value
186 timezone = this_metadata_file['timezone'].value
185 187 except:
186 timezone = 0
188 timezone = 0
187 189
188 190 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(
189 191 channelNameList[0]) / sample_rate - timezone
190 192
191 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
192 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
193 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
194 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
193 195
194 196 if not startDate:
195 startDate = startDatetime.date()
197 startDate = startDatetime.date()
196 198
197 199 if not endDate:
198 endDate = endDatatime.date()
200 endDate = endDatatime.date()
199 201
200 dateList = []
202 dateList = []
201 203
202 thisDatetime = startDatetime
204 thisDatetime = startDatetime
203 205
204 206 while(thisDatetime <= endDatatime):
205 207
206 thisDate = thisDatetime.date()
208 thisDate = thisDatetime.date()
207 209
208 if thisDate < startDate:
210 if thisDate < startDate:
209 211 continue
210 212
211 if thisDate > endDate:
213 if thisDate > endDate:
212 214 break
213 215
214 216 dateList.append(thisDate)
@@ -241,16 +243,17 class DigitalRFReader(ProcessingUnit):
241 243 startDate
242 244 endDate
243 245 startTime
244 endTime
246 endTime
245 247 set
246 248 expLabel
247 249 ext
248 250 online
249 251 delay
250 252 '''
251 self.nCohInt = nCohInt
253 self.path = path
254 self.nCohInt = nCohInt
252 255 self.flagDecodeData = flagDecodeData
253 self.i = 0
256 self.i = 0
254 257 if not os.path.isdir(path):
255 258 raise ValueError("[Reading] Directory %s does not exist" % path)
256 259
@@ -260,7 +263,7 class DigitalRFReader(ProcessingUnit):
260 263 except:
261 264 self.digitalReadObj = digital_rf.DigitalRFReader(path)
262 265
263 channelNameList = self.digitalReadObj.get_channels()
266 channelNameList = self.digitalReadObj.get_channels()
264 267
265 268 if not channelNameList:
266 269 raise ValueError("[Reading] Directory %s does not have any files" % path)
@@ -270,27 +273,27 class DigitalRFReader(ProcessingUnit):
270 273
271 274 ########## Reading metadata ######################
272 275
273 top_properties = self.digitalReadObj.get_properties(
276 top_properties = self.digitalReadObj.get_properties(
274 277 channelNameList[channelList[0]])
275 278
276 self.__num_subchannels = top_properties['num_subchannels']
277 self.__sample_rate = 1.0 * \
279 self.__num_subchannels = top_properties['num_subchannels']
280 self.__sample_rate = 1.0 * \
278 281 top_properties['sample_rate_numerator'] / \
279 282 top_properties['sample_rate_denominator']
280 283 # self.__samples_per_file = top_properties['samples_per_file'][0]
281 self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15?
284 self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15?
282 285
283 this_metadata_file = self.digitalReadObj.get_digital_metadata(
286 this_metadata_file = self.digitalReadObj.get_digital_metadata(
284 287 channelNameList[channelList[0]])
285 metadata_bounds = this_metadata_file.get_bounds()
288 metadata_bounds = this_metadata_file.get_bounds()
286 289 self.fixed_metadata_dict = this_metadata_file.read(
287 290 metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER
288 291
289 292 try:
290 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
293 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
291 294 self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader']
292 self.__systemHeader = self.fixed_metadata_dict['systemHeader']
293 self.dtype = pickle.loads(self.fixed_metadata_dict['dtype'])
295 self.__systemHeader = self.fixed_metadata_dict['systemHeader']
296 self.dtype = pickle.loads(self.fixed_metadata_dict['dtype'])
294 297 except:
295 298 pass
296 299
@@ -298,7 +301,7 class DigitalRFReader(ProcessingUnit):
298 301
299 302 self.__frequency = self.fixed_metadata_dict.get('frequency', 1)
300 303
301 self.__timezone = self.fixed_metadata_dict.get('timezone', 300)
304 self.__timezone = self.fixed_metadata_dict.get('timezone', 18000)
302 305
303 306 try:
304 307 nSamples = self.fixed_metadata_dict['nSamples']
@@ -308,15 +311,15 class DigitalRFReader(ProcessingUnit):
308 311 self.__firstHeigth = 0
309 312
310 313 try:
311 codeType = self.__radarControllerHeader['codeType']
314 codeType = self.__radarControllerHeader['codeType']
312 315 except:
313 codeType = 0
316 codeType = 0
314 317
315 318 try:
316 319 if codeType:
317 320 nCode = self.__radarControllerHeader['nCode']
318 321 nBaud = self.__radarControllerHeader['nBaud']
319 code = self.__radarControllerHeader['code']
322 code = self.__radarControllerHeader['code']
320 323 except:
321 324 pass
322 325
@@ -327,18 +330,18 class DigitalRFReader(ProcessingUnit):
327 330 except:
328 331 ippKm = None
329 332 ####################################################
330 self.__ippKm = ippKm
333 self.__ippKm = ippKm
331 334 startUTCSecond = None
332 endUTCSecond = None
335 endUTCSecond = None
333 336
334 337 if startDate:
335 startDatetime = datetime.datetime.combine(startDate, startTime)
338 startDatetime = datetime.datetime.combine(startDate, startTime)
336 339 startUTCSecond = (
337 340 startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone
338 341
339 342 if endDate:
340 endDatetime = datetime.datetime.combine(endDate, endTime)
341 endUTCSecond = (endDatetime - datetime.datetime(1970,
343 endDatetime = datetime.datetime.combine(endDate, endTime)
344 endUTCSecond = (endDatetime - datetime.datetime(1970,
342 345 1, 1)).total_seconds() + self.__timezone
343 346
344 347 start_index, end_index = self.digitalReadObj.get_bounds(
@@ -347,50 +350,50 class DigitalRFReader(ProcessingUnit):
347 350 if not startUTCSecond:
348 351 startUTCSecond = start_index / self.__sample_rate
349 352
350 if start_index > startUTCSecond * self.__sample_rate:
353 if start_index > startUTCSecond * self.__sample_rate:
351 354 startUTCSecond = start_index / self.__sample_rate
352 355
353 356 if not endUTCSecond:
354 endUTCSecond = end_index / self.__sample_rate
357 endUTCSecond = end_index / self.__sample_rate
355 358
356 if end_index < endUTCSecond * self.__sample_rate:
357 endUTCSecond = end_index / self.__sample_rate
359 if end_index < endUTCSecond * self.__sample_rate:
360 endUTCSecond = end_index / self.__sample_rate
358 361 if not nSamples:
359 362 if not ippKm:
360 363 raise ValueError("[Reading] nSamples or ippKm should be defined")
361 nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate))
362 channelBoundList = []
364 nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate))
365 channelBoundList = []
363 366 channelNameListFiltered = []
364 367
365 368 for thisIndexChannel in channelList:
366 thisChannelName = channelNameList[thisIndexChannel]
369 thisChannelName = channelNameList[thisIndexChannel]
367 370 start_index, end_index = self.digitalReadObj.get_bounds(
368 371 thisChannelName)
369 372 channelBoundList.append((start_index, end_index))
370 373 channelNameListFiltered.append(thisChannelName)
371 374
372 375 self.profileIndex = 0
373 self.i = 0
374 self.__delay = delay
375
376 self.__codeType = codeType
377 self.__nCode = nCode
378 self.__nBaud = nBaud
379 self.__code = code
380
381 self.__datapath = path
382 self.__online = online
383 self.__channelList = channelList
384 self.__channelNameList = channelNameListFiltered
376 self.i = 0
377 self.__delay = delay
378
379 self.__codeType = codeType
380 self.__nCode = nCode
381 self.__nBaud = nBaud
382 self.__code = code
383
384 self.__datapath = path
385 self.__online = online
386 self.__channelList = channelList
387 self.__channelNameList = channelNameListFiltered
385 388 self.__channelBoundList = channelBoundList
386 self.__nSamples = nSamples
387 self.__samples_to_read = int(nSamples) # FIJO: AHORA 40
388 self.__nChannels = len(self.__channelList)
389 self.__nSamples = nSamples
390 self.__samples_to_read = int(nSamples) # FIJO: AHORA 40
391 self.__nChannels = len(self.__channelList)
389 392
390 self.__startUTCSecond = startUTCSecond
391 self.__endUTCSecond = endUTCSecond
393 self.__startUTCSecond = startUTCSecond
394 self.__endUTCSecond = endUTCSecond
392 395
393 self.__timeInterval = 1.0 * self.__samples_to_read / \
396 self.__timeInterval = 1.0 * self.__samples_to_read / \
394 397 self.__sample_rate # Time interval
395 398
396 399 if online:
@@ -398,10 +401,9 class DigitalRFReader(ProcessingUnit):
398 401 startUTCSecond = numpy.floor(endUTCSecond)
399 402
400 403 # por que en el otro metodo lo primero q se hace es sumar samplestoread
401 self.__thisUnixSample = int(
402 startUTCSecond * self.__sample_rate) - self.__samples_to_read
404 self.__thisUnixSample = int(startUTCSecond * self.__sample_rate) - self.__samples_to_read
403 405
404 self.__data_buffer = numpy.zeros(
406 self.__data_buffer = numpy.zeros(
405 407 (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex)
406 408
407 409 self.__setFileHeader()
@@ -418,8 +420,8 class DigitalRFReader(ProcessingUnit):
418 420 datetime.datetime.utcfromtimestamp(
419 421 endUTCSecond - self.__timezone)
420 422 ))
421 self.oldAverage = None
422 self.count = 0
423 self.oldAverage = None
424 self.count = 0
423 425 self.executionTime = 0
424 426
425 427 def __reload(self):
@@ -434,15 +436,15 class DigitalRFReader(ProcessingUnit):
434 436 try:
435 437 self.digitalReadObj.reload(complete_update=True)
436 438 except:
437 self.digitalReadObj.reload()
439 self.digitalReadObj = digital_rf.DigitalRFReader(self.path)
438 440
439 start_index, end_index = self.digitalReadObj.get_bounds(
441 start_index, end_index = self.digitalReadObj.get_bounds(
440 442 self.__channelNameList[self.__channelList[0]])
441 443
442 if start_index > self.__startUTCSecond * self.__sample_rate:
444 if start_index > self.__startUTCSecond * self.__sample_rate:
443 445 self.__startUTCSecond = 1.0 * start_index / self.__sample_rate
444 446
445 if end_index > self.__endUTCSecond * self.__sample_rate:
447 if end_index > self.__endUTCSecond * self.__sample_rate:
446 448 self.__endUTCSecond = 1.0 * end_index / self.__sample_rate
447 449 print()
448 450 print("[Reading] New timerange found [%s, %s] " % (
@@ -457,14 +459,14 class DigitalRFReader(ProcessingUnit):
457 459 return False
458 460
459 461 def timeit(self, toExecute):
460 t0 = time.time()
462 t0 = time.time()
461 463 toExecute()
462 self.executionTime = time.time() - t0
464 self.executionTime = time.time() - t0
463 465 if self.oldAverage is None:
464 466 self.oldAverage = self.executionTime
465 self.oldAverage = (self.executionTime + self.count *
467 self.oldAverage = (self.executionTime + self.count *
466 468 self.oldAverage) / (self.count + 1.0)
467 self.count = self.count + 1.0
469 self.count = self.count + 1.0
468 470 return
469 471
470 472 def __readNextBlock(self, seconds=30, volt_scale=1):
@@ -473,10 +475,10 class DigitalRFReader(ProcessingUnit):
473 475
474 476 # Set the next data
475 477 self.__flagDiscontinuousBlock = False
476 self.__thisUnixSample += self.__samples_to_read
477
478 self.__thisUnixSample += self.__samples_to_read
479
478 480 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
479 print("[Reading] There are no more data into selected time-range")
481 print ("[Reading] There are no more data into selected time-range")
480 482 if self.__online:
481 483 self.__reload()
482 484 else:
@@ -489,17 +491,18 class DigitalRFReader(ProcessingUnit):
489 491 indexChannel = 0
490 492
491 493 dataOk = False
494
492 495 for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS?
493 496 for indexSubchannel in range(self.__num_subchannels):
494 497 try:
495 t0 = time()
498 t0 = time()
496 499 result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,
497 500 self.__samples_to_read,
498 501 thisChannelName, sub_channel=indexSubchannel)
499 self.executionTime = time() - t0
502 self.executionTime = time() - t0
500 503 if self.oldAverage is None:
501 504 self.oldAverage = self.executionTime
502 self.oldAverage = (
505 self.oldAverage = (
503 506 self.executionTime + self.count * self.oldAverage) / (self.count + 1.0)
504 507 self.count = self.count + 1.0
505 508
@@ -515,14 +518,13 class DigitalRFReader(ProcessingUnit):
515 518 result.shape[0],
516 519 self.__samples_to_read))
517 520 break
518
521
519 522 self.__data_buffer[indexSubchannel, :] = result * volt_scale
523 indexChannel+=1
520 524
521 indexChannel += 1
525 dataOk = True
522 526
523 dataOk = True
524
525 self.__utctime = self.__thisUnixSample / self.__sample_rate
527 self.__utctime = self.__thisUnixSample / self.__sample_rate
526 528
527 529 if not dataOk:
528 530 return False
@@ -531,7 +533,7 class DigitalRFReader(ProcessingUnit):
531 533 self.__samples_to_read,
532 534 self.__timeInterval))
533 535
534 self.__bufferIndex = 0
536 self.__bufferIndex = 0
535 537
536 538 return True
537 539
@@ -554,27 +556,29 class DigitalRFReader(ProcessingUnit):
554 556 self.flagDiscontinuousBlock
555 557 self.flagIsNewBlock
556 558 '''
557
559 #print("getdata")
558 560 err_counter = 0
559 561 self.dataOut.flagNoData = True
560 562
561 563 if self.__isBufferEmpty():
564 #print("hi")
562 565 self.__flagDiscontinuousBlock = False
563 566
564 567 while True:
568 #print ("q ha pasado")
565 569 if self.__readNextBlock():
566 570 break
567 571 if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate:
568 572 raise schainpy.admin.SchainError('Error')
569 return
573 return
570 574
571 575 if self.__flagDiscontinuousBlock:
572 576 raise schainpy.admin.SchainError('discontinuous block found')
573 577 return
574
578
575 579 if not self.__online:
576 580 raise schainpy.admin.SchainError('Online?')
577 return
581 return
578 582
579 583 err_counter += 1
580 584 if err_counter > nTries:
@@ -584,21 +588,19 class DigitalRFReader(ProcessingUnit):
584 588 print('[Reading] waiting %d seconds to read a new block' % seconds)
585 589 time.sleep(seconds)
586 590
587 self.dataOut.data = self.__data_buffer[:,
588 self.__bufferIndex:self.__bufferIndex + self.__nSamples]
589 self.dataOut.utctime = (
590 self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate
591 self.dataOut.flagNoData = False
591 self.dataOut.data = self.__data_buffer[:, self.__bufferIndex:self.__bufferIndex + self.__nSamples]
592 self.dataOut.utctime = ( self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate
593 self.dataOut.flagNoData = False
592 594 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
593 self.dataOut.profileIndex = self.profileIndex
595 self.dataOut.profileIndex = self.profileIndex
594 596
595 597 self.__bufferIndex += self.__nSamples
596 self.profileIndex += 1
598 self.profileIndex += 1
597 599
598 600 if self.profileIndex == self.dataOut.nProfiles:
599 601 self.profileIndex = 0
600 602
601 return
603 return True
602 604
603 605 def printInfo(self):
604 606 '''
@@ -621,12 +623,12 class DigitalRFReader(ProcessingUnit):
621 623 '''
622 624 This method will be called many times so here you should put all your code
623 625 '''
624
626
625 627 if not self.isConfig:
626 628 self.setup(**kwargs)
627 629 #self.i = self.i+1
628 630 self.getData(seconds=self.__delay)
629
631
630 632 return
631 633
632 634
@@ -641,25 +643,25 class DigitalRFWriter(Operation):
641 643 '''
642 644 Operation.__init__(self, **kwargs)
643 645 self.metadata_dict = {}
644 self.dataOut = None
645 self.dtype = None
646 self.oldAverage = 0
646 self.dataOut = None
647 self.dtype = None
648 self.oldAverage = 0
647 649
648 650 def setHeader(self):
649 651
650 self.metadata_dict['frequency'] = self.dataOut.frequency
651 self.metadata_dict['timezone'] = self.dataOut.timeZone
652 self.metadata_dict['dtype'] = pickle.dumps(self.dataOut.dtype)
653 self.metadata_dict['nProfiles'] = self.dataOut.nProfiles
654 self.metadata_dict['heightList'] = self.dataOut.heightList
655 self.metadata_dict['channelList'] = self.dataOut.channelList
652 self.metadata_dict['frequency'] = self.dataOut.frequency
653 self.metadata_dict['timezone'] = self.dataOut.timeZone
654 self.metadata_dict['dtype'] = pickle.dumps(self.dataOut.dtype)
655 self.metadata_dict['nProfiles'] = self.dataOut.nProfiles
656 self.metadata_dict['heightList'] = self.dataOut.heightList
657 self.metadata_dict['channelList'] = self.dataOut.channelList
656 658 self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData
657 659 self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData
658 self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT
659 self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime
660 self.metadata_dict['nCohInt'] = self.dataOut.nCohInt
661 self.metadata_dict['type'] = self.dataOut.type
662 self.metadata_dict['flagDataAsBlock'] = getattr(
660 self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT
661 self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime
662 self.metadata_dict['nCohInt'] = self.dataOut.nCohInt
663 self.metadata_dict['type'] = self.dataOut.type
664 self.metadata_dict['flagDataAsBlock']= getattr(
663 665 self.dataOut, 'flagDataAsBlock', None) # chequear
664 666
665 667 def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'):
@@ -669,13 +671,13 class DigitalRFWriter(Operation):
669 671 dataOut: Input data will also be outputa data
670 672 '''
671 673 self.setHeader()
672 self.__ippSeconds = dataOut.ippSeconds
673 self.__deltaH = dataOut.getDeltaH()
674 self.__ippSeconds = dataOut.ippSeconds
675 self.__deltaH = dataOut.getDeltaH()
674 676 self.__sample_rate = 1e6 * 0.15 / self.__deltaH
675 self.__dtype = dataOut.dtype
677 self.__dtype = dataOut.dtype
676 678 if len(dataOut.dtype) == 2:
677 679 self.__dtype = dataOut.dtype[0]
678 self.__nSamples = dataOut.systemHeaderObj.nSamples
680 self.__nSamples = dataOut.systemHeaderObj.nSamples
679 681 self.__nProfiles = dataOut.nProfiles
680 682
681 683 if self.dataOut.type != 'Voltage':
@@ -686,44 +688,44 class DigitalRFWriter(Operation):
686 688 self.arr_data = numpy.ones((self.__nSamples, len(
687 689 self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
688 690
689 file_cadence_millisecs = 1000
691 file_cadence_millisecs = 1000
690 692
691 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
692 sample_rate_numerator = int(sample_rate_fraction.numerator)
693 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
694 sample_rate_numerator = int(sample_rate_fraction.numerator)
693 695 sample_rate_denominator = int(sample_rate_fraction.denominator)
694 start_global_index = dataOut.utctime * self.__sample_rate
696 start_global_index = dataOut.utctime * self.__sample_rate
695 697
696 uuid = 'prueba'
698 uuid = 'prueba'
697 699 compression_level = 0
698 checksum = False
699 is_complex = True
700 num_subchannels = len(dataOut.channelList)
701 is_continuous = True
702 marching_periods = False
700 checksum = False
701 is_complex = True
702 num_subchannels = len(dataOut.channelList)
703 is_continuous = True
704 marching_periods = False
703 705
704 706 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence,
705 707 fileCadence, start_global_index,
706 708 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
707 709 is_complex, num_subchannels, is_continuous, marching_periods)
708 metadata_dir = os.path.join(path, 'metadata')
710 metadata_dir = os.path.join(path, 'metadata')
709 711 os.system('mkdir %s' % (metadata_dir))
710 712 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000
711 713 sample_rate_numerator, sample_rate_denominator,
712 714 metadataFile)
713 self.isConfig = True
715 self.isConfig = True
714 716 self.currentSample = 0
715 self.oldAverage = 0
716 self.count = 0
717 self.oldAverage = 0
718 self.count = 0
717 719 return
718 720
719 721 def writeMetadata(self):
720 start_idx = self.__sample_rate * self.dataOut.utctime
722 start_idx = self.__sample_rate * self.dataOut.utctime
721 723
722 self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict(
724 self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict(
723 725 )
724 726 self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict(
725 727 )
726 self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict(
728 self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict(
727 729 )
728 730 self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict)
729 731 return
@@ -731,12 +733,12 class DigitalRFWriter(Operation):
731 733 def timeit(self, toExecute):
732 734 t0 = time()
733 735 toExecute()
734 self.executionTime = time() - t0
736 self.executionTime = time() - t0
735 737 if self.oldAverage is None:
736 738 self.oldAverage = self.executionTime
737 self.oldAverage = (self.executionTime + self.count *
739 self.oldAverage = (self.executionTime + self.count *
738 740 self.oldAverage) / (self.count + 1.0)
739 self.count = self.count + 1.0
741 self.count = self.count + 1.0
740 742 return
741 743
742 744 def writeData(self):
@@ -779,7 +781,7 class DigitalRFWriter(Operation):
779 781 # self.writeMetadata()
780 782 ## if self.currentSample == self.__nProfiles: self.currentSample = 0
781 783
782 return dataOut
784 return dataOut# en la version 2.7 no aparece este return
783 785
784 786 def close(self):
785 787 print('[Writing] - Closing files ')
@@ -788,5 +790,3 class DigitalRFWriter(Operation):
788 790 self.digitalWriteObj.close()
789 791 except:
790 792 pass
791
792
General Comments 0
You need to be logged in to leave comments. Login now