##// END OF EJS Templates
formatting, template actualizado, decimation a 300
José Chávez -
r1092:57cb558a168b
parent child
Show More
@@ -30,7 +30,7 rti.addParameter(name='wr_period', value='5', format='int')
30 rti.addParameter(name='exp_code', value='22', format='int')
30 rti.addParameter(name='exp_code', value='22', format='int')
31
31
32
32
33 controller.start()
33 project.start()
34 '''
34 '''
35
35
36 multiprocess = '''from schainpy.controller import Project, MPProject
36 multiprocess = '''from schainpy.controller import Project, MPProject
@@ -15,41 +15,43 from schainpy import cSchain
15 def getNumpyDtype(dataTypeCode):
15 def getNumpyDtype(dataTypeCode):
16
16
17 if dataTypeCode == 0:
17 if dataTypeCode == 0:
18 numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')])
18 numpyDtype = numpy.dtype([('real', '<i1'), ('imag', '<i1')])
19 elif dataTypeCode == 1:
19 elif dataTypeCode == 1:
20 numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')])
20 numpyDtype = numpy.dtype([('real', '<i2'), ('imag', '<i2')])
21 elif dataTypeCode == 2:
21 elif dataTypeCode == 2:
22 numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')])
22 numpyDtype = numpy.dtype([('real', '<i4'), ('imag', '<i4')])
23 elif dataTypeCode == 3:
23 elif dataTypeCode == 3:
24 numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')])
24 numpyDtype = numpy.dtype([('real', '<i8'), ('imag', '<i8')])
25 elif dataTypeCode == 4:
25 elif dataTypeCode == 4:
26 numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')])
26 numpyDtype = numpy.dtype([('real', '<f4'), ('imag', '<f4')])
27 elif dataTypeCode == 5:
27 elif dataTypeCode == 5:
28 numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')])
28 numpyDtype = numpy.dtype([('real', '<f8'), ('imag', '<f8')])
29 else:
29 else:
30 raise ValueError, 'dataTypeCode was not defined'
30 raise ValueError, 'dataTypeCode was not defined'
31
31
32 return numpyDtype
32 return numpyDtype
33
33
34
34 def getDataTypeCode(numpyDtype):
35 def getDataTypeCode(numpyDtype):
35
36
36 if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]):
37 if numpyDtype == numpy.dtype([('real', '<i1'), ('imag', '<i1')]):
37 datatype = 0
38 datatype = 0
38 elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]):
39 elif numpyDtype == numpy.dtype([('real', '<i2'), ('imag', '<i2')]):
39 datatype = 1
40 datatype = 1
40 elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]):
41 elif numpyDtype == numpy.dtype([('real', '<i4'), ('imag', '<i4')]):
41 datatype = 2
42 datatype = 2
42 elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]):
43 elif numpyDtype == numpy.dtype([('real', '<i8'), ('imag', '<i8')]):
43 datatype = 3
44 datatype = 3
44 elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]):
45 elif numpyDtype == numpy.dtype([('real', '<f4'), ('imag', '<f4')]):
45 datatype = 4
46 datatype = 4
46 elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]):
47 elif numpyDtype == numpy.dtype([('real', '<f8'), ('imag', '<f8')]):
47 datatype = 5
48 datatype = 5
48 else:
49 else:
49 datatype = None
50 datatype = None
50
51
51 return datatype
52 return datatype
52
53
54
53 def hildebrand_sekhon(data, navg):
55 def hildebrand_sekhon(data, navg):
54 """
56 """
55 This method is for the objective determination of the noise level in Doppler spectra. This
57 This method is for the objective determination of the noise level in Doppler spectra. This
@@ -110,6 +112,7 class Beam:
110 self.azimuthList = []
112 self.azimuthList = []
111 self.zenithList = []
113 self.zenithList = []
112
114
115
113 class GenericData(object):
116 class GenericData(object):
114
117
115 flagNoData = True
118 flagNoData = True
@@ -123,12 +126,12 class GenericData(object):
123
126
124 attribute = inputObj.__dict__[key]
127 attribute = inputObj.__dict__[key]
125
128
126 #If this attribute is a tuple or list
129 # If this attribute is a tuple or list
127 if type(inputObj.__dict__[key]) in (tuple, list):
130 if type(inputObj.__dict__[key]) in (tuple, list):
128 self.__dict__[key] = attribute[:]
131 self.__dict__[key] = attribute[:]
129 continue
132 continue
130
133
131 #If this attribute is another object or instance
134 # If this attribute is another object or instance
132 if hasattr(attribute, '__dict__'):
135 if hasattr(attribute, '__dict__'):
133 self.__dict__[key] = attribute.copy()
136 self.__dict__[key] = attribute.copy()
134 continue
137 continue
@@ -143,10 +146,11 class GenericData(object):
143
146
144 return self.flagNoData
147 return self.flagNoData
145
148
149
146 class JROData(GenericData):
150 class JROData(GenericData):
147
151
148 # m_BasicHeader = BasicHeader()
152 # m_BasicHeader = BasicHeader()
149 # m_ProcessingHeader = ProcessingHeader()
153 # m_ProcessingHeader = ProcessingHeader()
150
154
151 systemHeaderObj = SystemHeader()
155 systemHeaderObj = SystemHeader()
152
156
@@ -156,7 +160,7 class JROData(GenericData):
156
160
157 type = None
161 type = None
158
162
159 datatype = None #dtype but in string
163 datatype = None # dtype but in string
160
164
161 # dtype = None
165 # dtype = None
162
166
@@ -190,9 +194,9 class JROData(GenericData):
190 #
194 #
191 # code = None
195 # code = None
192
196
193 flagDecodeData = False #asumo q la data no esta decodificada
197 flagDecodeData = False # asumo q la data no esta decodificada
194
198
195 flagDeflipData = False #asumo q la data no esta sin flip
199 flagDeflipData = False # asumo q la data no esta sin flip
196
200
197 flagShiftFFT = False
201 flagShiftFFT = False
198
202
@@ -206,7 +210,7 class JROData(GenericData):
206
210
207 windowOfFilter = 1
211 windowOfFilter = 1
208
212
209 #Speed of ligth
213 # Speed of ligth
210 C = 3e8
214 C = 3e8
211
215
212 frequency = 49.92e6
216 frequency = 49.92e6
@@ -261,7 +265,7 class JROData(GenericData):
261 def getltctime(self):
265 def getltctime(self):
262
266
263 if self.useLocalTime:
267 if self.useLocalTime:
264 return self.utctime - self.timeZone*60
268 return self.utctime - self.timeZone * 60
265
269
266 return self.utctime
270 return self.utctime
267
271
@@ -275,7 +279,7 class JROData(GenericData):
275 datatime = []
279 datatime = []
276
280
277 datatime.append(self.ltctime)
281 datatime.append(self.ltctime)
278 datatime.append(self.ltctime + self.timeInterval+1)
282 datatime.append(self.ltctime + self.timeInterval + 1)
279
283
280 datatime = numpy.array(datatime)
284 datatime = numpy.array(datatime)
281
285
@@ -283,25 +287,25 class JROData(GenericData):
283
287
284 def getFmaxTimeResponse(self):
288 def getFmaxTimeResponse(self):
285
289
286 period = (10**-6)*self.getDeltaH()/(0.15)
290 period = (10**-6) * self.getDeltaH() / (0.15)
287
291
288 PRF = 1./(period * self.nCohInt)
292 PRF = 1. / (period * self.nCohInt)
289
293
290 fmax = PRF
294 fmax = PRF
291
295
292 return fmax
296 return fmax
293
297
294 def getFmax(self):
298 def getFmax(self):
295 PRF = 1./(self.ippSeconds * self.nCohInt)
299 PRF = 1. / (self.ippSeconds * self.nCohInt)
296
300
297 fmax = PRF
301 fmax = PRF
298 return fmax
302 return fmax
299
303
300 def getVmax(self):
304 def getVmax(self):
301
305
302 _lambda = self.C/self.frequency
306 _lambda = self.C / self.frequency
303
307
304 vmax = self.getFmax() * _lambda/2
308 vmax = self.getFmax() * _lambda / 2
305
309
306 return vmax
310 return vmax
307
311
@@ -366,7 +370,8 class JROData(GenericData):
366 return
370 return
367
371
368 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
372 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
369 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
373 channelIndexList = property(
374 getChannelIndexList, "I'm the 'channelIndexList' property.")
370 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
375 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
371 #noise = property(getNoise, "I'm the 'nHeights' property.")
376 #noise = property(getNoise, "I'm the 'nHeights' property.")
372 datatime = property(getDatatime, "I'm the 'datatime' property")
377 datatime = property(getDatatime, "I'm the 'datatime' property")
@@ -378,9 +383,10 class JROData(GenericData):
378 nCode = property(get_ncode, set_ncode)
383 nCode = property(get_ncode, set_ncode)
379 nBaud = property(get_nbaud, set_nbaud)
384 nBaud = property(get_nbaud, set_nbaud)
380
385
386
381 class Voltage(JROData):
387 class Voltage(JROData):
382
388
383 #data es un numpy array de 2 dmensiones (canales, alturas)
389 # data es un numpy array de 2 dmensiones (canales, alturas)
384 data = None
390 data = None
385
391
386 def __init__(self):
392 def __init__(self):
@@ -428,17 +434,17 class Voltage(JROData):
428
434
429 self.blocksize = None
435 self.blocksize = None
430
436
431 self.flagDecodeData = False #asumo q la data no esta decodificada
437 self.flagDecodeData = False # asumo q la data no esta decodificada
432
438
433 self.flagDeflipData = False #asumo q la data no esta sin flip
439 self.flagDeflipData = False # asumo q la data no esta sin flip
434
440
435 self.flagShiftFFT = False
441 self.flagShiftFFT = False
436
442
437 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
443 self.flagDataAsBlock = False # Asumo que la data es leida perfil a perfil
438
444
439 self.profileIndex = 0
445 self.profileIndex = 0
440
446
441 def getNoisebyHildebrand(self, channel = None):
447 def getNoisebyHildebrand(self, channel=None):
442 """
448 """
443 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
449 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
444
450
@@ -460,19 +466,19 class Voltage(JROData):
460 if nChannels == 1:
466 if nChannels == 1:
461 daux = power[:].real
467 daux = power[:].real
462 else:
468 else:
463 daux = power[thisChannel,:].real
469 daux = power[thisChannel, :].real
464 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
470 noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt)
465
471
466 return noise
472 return noise
467
473
468 def getNoise(self, type = 1, channel = None):
474 def getNoise(self, type=1, channel=None):
469
475
470 if type == 1:
476 if type == 1:
471 noise = self.getNoisebyHildebrand(channel)
477 noise = self.getNoisebyHildebrand(channel)
472
478
473 return noise
479 return noise
474
480
475 def getPower(self, channel = None):
481 def getPower(self, channel=None):
476
482
477 if channel != None:
483 if channel != None:
478 data = self.data[channel]
484 data = self.data[channel]
@@ -480,7 +486,7 class Voltage(JROData):
480 data = self.data
486 data = self.data
481
487
482 power = data * numpy.conjugate(data)
488 power = data * numpy.conjugate(data)
483 powerdB = 10*numpy.log10(power.real)
489 powerdB = 10 * numpy.log10(power.real)
484 powerdB = numpy.squeeze(powerdB)
490 powerdB = numpy.squeeze(powerdB)
485
491
486 return powerdB
492 return powerdB
@@ -494,18 +500,19 class Voltage(JROData):
494 noise = property(getNoise, "I'm the 'nHeights' property.")
500 noise = property(getNoise, "I'm the 'nHeights' property.")
495 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
501 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
496
502
503
497 class Spectra(JROData):
504 class Spectra(JROData):
498
505
499 #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
506 # data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas)
500 data_spc = None
507 data_spc = None
501
508
502 #data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
509 # data cspc es un numpy array de 2 dmensiones (canales, pares, alturas)
503 data_cspc = None
510 data_cspc = None
504
511
505 #data dc es un numpy array de 2 dmensiones (canales, alturas)
512 # data dc es un numpy array de 2 dmensiones (canales, alturas)
506 data_dc = None
513 data_dc = None
507
514
508 #data power
515 # data power
509 data_pwr = None
516 data_pwr = None
510
517
511 nFFTPoints = None
518 nFFTPoints = None
@@ -516,9 +523,9 class Spectra(JROData):
516
523
517 nIncohInt = None
524 nIncohInt = None
518
525
519 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
526 wavelength = None # Necesario para cacular el rango de velocidad desde la frecuencia
520
527
521 nCohInt = None #se requiere para determinar el valor de timeInterval
528 nCohInt = None # se requiere para determinar el valor de timeInterval
522
529
523 ippFactor = None
530 ippFactor = None
524
531
@@ -573,9 +580,9 class Spectra(JROData):
573
580
574 self.wavelength = None
581 self.wavelength = None
575
582
576 self.flagDecodeData = False #asumo q la data no esta decodificada
583 self.flagDecodeData = False # asumo q la data no esta decodificada
577
584
578 self.flagDeflipData = False #asumo q la data no esta sin flip
585 self.flagDeflipData = False # asumo q la data no esta sin flip
579
586
580 self.flagShiftFFT = False
587 self.flagShiftFFT = False
581
588
@@ -587,7 +594,6 class Spectra(JROData):
587
594
588 self.noise_estimation = None
595 self.noise_estimation = None
589
596
590
591 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
597 def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
592 """
598 """
593 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
599 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
@@ -599,7 +605,8 class Spectra(JROData):
599 noise = numpy.zeros(self.nChannels)
605 noise = numpy.zeros(self.nChannels)
600
606
601 for channel in range(self.nChannels):
607 for channel in range(self.nChannels):
602 daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index]
608 daux = self.data_spc[channel,
609 xmin_index:xmax_index, ymin_index:ymax_index]
603 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
610 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
604
611
605 return noise
612 return noise
@@ -607,36 +614,45 class Spectra(JROData):
607 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
614 def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None):
608
615
609 if self.noise_estimation is not None:
616 if self.noise_estimation is not None:
610 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
617 # this was estimated by getNoise Operation defined in jroproc_spectra.py
618 return self.noise_estimation
611 else:
619 else:
612 noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index)
620 noise = self.getNoisebyHildebrand(
621 xmin_index, xmax_index, ymin_index, ymax_index)
613 return noise
622 return noise
614
623
615 def getFreqRangeTimeResponse(self, extrapoints=0):
624 def getFreqRangeTimeResponse(self, extrapoints=0):
616
625
617 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints*self.ippFactor)
626 deltafreq = self.getFmaxTimeResponse() / (self.nFFTPoints * self.ippFactor)
618 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
627 freqrange = deltafreq * \
628 (numpy.arange(self.nFFTPoints + extrapoints) -
629 self.nFFTPoints / 2.) - deltafreq / 2
619
630
620 return freqrange
631 return freqrange
621
632
622 def getAcfRange(self, extrapoints=0):
633 def getAcfRange(self, extrapoints=0):
623
634
624 deltafreq = 10./(self.getFmax() / (self.nFFTPoints*self.ippFactor))
635 deltafreq = 10. / (self.getFmax() / (self.nFFTPoints * self.ippFactor))
625 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
636 freqrange = deltafreq * \
637 (numpy.arange(self.nFFTPoints + extrapoints) -
638 self.nFFTPoints / 2.) - deltafreq / 2
626
639
627 return freqrange
640 return freqrange
628
641
629 def getFreqRange(self, extrapoints=0):
642 def getFreqRange(self, extrapoints=0):
630
643
631 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
644 deltafreq = self.getFmax() / (self.nFFTPoints * self.ippFactor)
632 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
645 freqrange = deltafreq * \
646 (numpy.arange(self.nFFTPoints + extrapoints) -
647 self.nFFTPoints / 2.) - deltafreq / 2
633
648
634 return freqrange
649 return freqrange
635
650
636 def getVelRange(self, extrapoints=0):
651 def getVelRange(self, extrapoints=0):
637
652
638 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
653 deltav = self.getVmax() / (self.nFFTPoints * self.ippFactor)
639 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) #- deltav/2
654 velrange = deltav * (numpy.arange(self.nFFTPoints +
655 extrapoints) - self.nFFTPoints / 2.) # - deltav/2
640
656
641 return velrange
657 return velrange
642
658
@@ -655,7 +671,8 class Spectra(JROData):
655 if self.flagDecodeData:
671 if self.flagDecodeData:
656 pwcode = numpy.sum(self.code[0]**2)
672 pwcode = numpy.sum(self.code[0]**2)
657 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
673 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
658 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
674 normFactor = self.nProfiles * self.nIncohInt * \
675 self.nCohInt * pwcode * self.windowOfFilter
659
676
660 return normFactor
677 return normFactor
661
678
@@ -682,11 +699,11 class Spectra(JROData):
682 def getPower(self):
699 def getPower(self):
683
700
684 factor = self.normFactor
701 factor = self.normFactor
685 z = self.data_spc/factor
702 z = self.data_spc / factor
686 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
703 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
687 avg = numpy.average(z, axis=1)
704 avg = numpy.average(z, axis=1)
688
705
689 return 10*numpy.log10(avg)
706 return 10 * numpy.log10(avg)
690
707
691 def getCoherence(self, pairsList=None, phase=False):
708 def getCoherence(self, pairsList=None, phase=False):
692
709
@@ -697,17 +714,19 class Spectra(JROData):
697 pairsIndexList = []
714 pairsIndexList = []
698 for pair in pairsList:
715 for pair in pairsList:
699 if pair not in self.pairsList:
716 if pair not in self.pairsList:
700 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
717 raise ValueError, "Pair %s is not in dataOut.pairsList" % (
701 pairsIndexList.append(self.pairsList.index(pair))
718 pair)
719 pairsIndexList.append(self.pairsList.index(pair))
702 for i in range(len(pairsIndexList)):
720 for i in range(len(pairsIndexList)):
703 pair = self.pairsList[pairsIndexList[i]]
721 pair = self.pairsList[pairsIndexList[i]]
704 ccf = numpy.average(self.data_cspc[pairsIndexList[i], :, :], axis=0)
722 ccf = numpy.average(
723 self.data_cspc[pairsIndexList[i], :, :], axis=0)
705 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
724 powa = numpy.average(self.data_spc[pair[0], :, :], axis=0)
706 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
725 powb = numpy.average(self.data_spc[pair[1], :, :], axis=0)
707 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
726 avgcoherenceComplex = ccf / numpy.sqrt(powa * powb)
708 if phase:
727 if phase:
709 data = numpy.arctan2(avgcoherenceComplex.imag,
728 data = numpy.arctan2(avgcoherenceComplex.imag,
710 avgcoherenceComplex.real)*180/numpy.pi
729 avgcoherenceComplex.real) * 180 / numpy.pi
711 else:
730 else:
712 data = numpy.abs(avgcoherenceComplex)
731 data = numpy.abs(avgcoherenceComplex)
713
732
@@ -722,12 +741,16 class Spectra(JROData):
722 return
741 return
723
742
724 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
743 nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.")
725 pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
744 pairsIndexList = property(
726 normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.")
745 getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.")
746 normFactor = property(getNormFactor, setValue,
747 "I'm the 'getNormFactor' property.")
727 flag_cspc = property(getFlagCspc, setValue)
748 flag_cspc = property(getFlagCspc, setValue)
728 flag_dc = property(getFlagDc, setValue)
749 flag_dc = property(getFlagDc, setValue)
729 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
750 noise = property(getNoise, setValue, "I'm the 'nHeights' property.")
730 timeInterval = property(getTimeInterval, setValue, "I'm the 'timeInterval' property")
751 timeInterval = property(getTimeInterval, setValue,
752 "I'm the 'timeInterval' property")
753
731
754
732 class SpectraHeis(Spectra):
755 class SpectraHeis(Spectra):
733
756
@@ -790,7 +813,7 class SpectraHeis(Spectra):
790 if self.flagDecodeData:
813 if self.flagDecodeData:
791 pwcode = numpy.sum(self.code[0]**2)
814 pwcode = numpy.sum(self.code[0]**2)
792
815
793 normFactor = self.nIncohInt*self.nCohInt*pwcode
816 normFactor = self.nIncohInt * self.nCohInt * pwcode
794
817
795 return normFactor
818 return normFactor
796
819
@@ -803,6 +826,7 class SpectraHeis(Spectra):
803 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
826 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
804 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
827 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
805
828
829
806 class Fits(JROData):
830 class Fits(JROData):
807
831
808 heightList = None
832 heightList = None
@@ -831,14 +855,13 class Fits(JROData):
831
855
832 windowOfFilter = 1
856 windowOfFilter = 1
833
857
834 #Speed of ligth
858 # Speed of ligth
835 C = 3e8
859 C = 3e8
836
860
837 frequency = 49.92e6
861 frequency = 49.92e6
838
862
839 realtime = False
863 realtime = False
840
864
841
842 def __init__(self):
865 def __init__(self):
843
866
844 self.type = "Fits"
867 self.type = "Fits"
@@ -879,11 +902,10 class Fits(JROData):
879 # self.comments = ''
902 # self.comments = ''
880 #
903 #
881
904
882
883 def getltctime(self):
905 def getltctime(self):
884
906
885 if self.useLocalTime:
907 if self.useLocalTime:
886 return self.utctime - self.timeZone*60
908 return self.utctime - self.timeZone * 60
887
909
888 return self.utctime
910 return self.utctime
889
911
@@ -921,7 +943,7 class Fits(JROData):
921
943
922 return range(self.nChannels)
944 return range(self.nChannels)
923
945
924 def getNoise(self, type = 1):
946 def getNoise(self, type=1):
925
947
926 #noise = numpy.zeros(self.nChannels)
948 #noise = numpy.zeros(self.nChannels)
927
949
@@ -945,7 +967,8 class Fits(JROData):
945 datatime = property(getDatatime, "I'm the 'datatime' property")
967 datatime = property(getDatatime, "I'm the 'datatime' property")
946 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
968 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
947 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
969 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
948 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
970 channelIndexList = property(
971 getChannelIndexList, "I'm the 'channelIndexList' property.")
949 noise = property(getNoise, "I'm the 'nHeights' property.")
972 noise = property(getNoise, "I'm the 'nHeights' property.")
950
973
951 ltctime = property(getltctime, "I'm the 'ltctime' property")
974 ltctime = property(getltctime, "I'm the 'ltctime' property")
@@ -984,7 +1007,6 class Correlation(JROData):
984
1007
985 nAvg = None
1008 nAvg = None
986
1009
987
988 def __init__(self):
1010 def __init__(self):
989 '''
1011 '''
990 Constructor
1012 Constructor
@@ -1019,9 +1041,9 class Correlation(JROData):
1019
1041
1020 self.blocksize = None
1042 self.blocksize = None
1021
1043
1022 self.flagDecodeData = False #asumo q la data no esta decodificada
1044 self.flagDecodeData = False # asumo q la data no esta decodificada
1023
1045
1024 self.flagDeflipData = False #asumo q la data no esta sin flip
1046 self.flagDeflipData = False # asumo q la data no esta sin flip
1025
1047
1026 self.pairsList = None
1048 self.pairsList = None
1027
1049
@@ -1031,48 +1053,50 class Correlation(JROData):
1031
1053
1032 return self.pairsList
1054 return self.pairsList
1033
1055
1034 def getNoise(self, mode = 2):
1056 def getNoise(self, mode=2):
1035
1057
1036 indR = numpy.where(self.lagR == 0)[0][0]
1058 indR = numpy.where(self.lagR == 0)[0][0]
1037 indT = numpy.where(self.lagT == 0)[0][0]
1059 indT = numpy.where(self.lagT == 0)[0][0]
1038
1060
1039 jspectra0 = self.data_corr[:,:,indR,:]
1061 jspectra0 = self.data_corr[:, :, indR, :]
1040 jspectra = copy.copy(jspectra0)
1062 jspectra = copy.copy(jspectra0)
1041
1063
1042 num_chan = jspectra.shape[0]
1064 num_chan = jspectra.shape[0]
1043 num_hei = jspectra.shape[2]
1065 num_hei = jspectra.shape[2]
1044
1066
1045 freq_dc = jspectra.shape[1]/2
1067 freq_dc = jspectra.shape[1] / 2
1046 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
1068 ind_vel = numpy.array([-2, -1, 1, 2]) + freq_dc
1047
1069
1048 if ind_vel[0]<0:
1070 if ind_vel[0] < 0:
1049 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
1071 ind_vel[range(0, 1)] = ind_vel[range(0, 1)] + self.num_prof
1050
1072
1051 if mode == 1:
1073 if mode == 1:
1052 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
1074 jspectra[:, freq_dc, :] = (
1075 jspectra[:, ind_vel[1], :] + jspectra[:, ind_vel[2], :]) / 2 # CORRECCION
1053
1076
1054 if mode == 2:
1077 if mode == 2:
1055
1078
1056 vel = numpy.array([-2,-1,1,2])
1079 vel = numpy.array([-2, -1, 1, 2])
1057 xx = numpy.zeros([4,4])
1080 xx = numpy.zeros([4, 4])
1058
1081
1059 for fil in range(4):
1082 for fil in range(4):
1060 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
1083 xx[fil, :] = vel[fil]**numpy.asarray(range(4))
1061
1084
1062 xx_inv = numpy.linalg.inv(xx)
1085 xx_inv = numpy.linalg.inv(xx)
1063 xx_aux = xx_inv[0,:]
1086 xx_aux = xx_inv[0, :]
1064
1087
1065 for ich in range(num_chan):
1088 for ich in range(num_chan):
1066 yy = jspectra[ich,ind_vel,:]
1089 yy = jspectra[ich, ind_vel, :]
1067 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
1090 jspectra[ich, freq_dc, :] = numpy.dot(xx_aux, yy)
1068
1091
1069 junkid = jspectra[ich,freq_dc,:]<=0
1092 junkid = jspectra[ich, freq_dc, :] <= 0
1070 cjunkid = sum(junkid)
1093 cjunkid = sum(junkid)
1071
1094
1072 if cjunkid.any():
1095 if cjunkid.any():
1073 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
1096 jspectra[ich, freq_dc, junkid.nonzero()] = (
1097 jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2
1074
1098
1075 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
1099 noise = jspectra0[:, freq_dc, :] - jspectra[:, freq_dc, :]
1076
1100
1077 return noise
1101 return noise
1078
1102
@@ -1093,7 +1117,7 class Correlation(JROData):
1093 chan0 = pairsList[l][0]
1117 chan0 = pairsList[l][0]
1094 chan1 = pairsList[l][1]
1118 chan1 = pairsList[l][1]
1095
1119
1096 #Obteniendo pares de Autocorrelacion
1120 # Obteniendo pares de Autocorrelacion
1097 if chan0 == chan1:
1121 if chan0 == chan1:
1098 acf_pairs.append(chan0)
1122 acf_pairs.append(chan0)
1099 acf_ind.append(l)
1123 acf_ind.append(l)
@@ -1109,7 +1133,7 class Correlation(JROData):
1109 def getNormFactor(self):
1133 def getNormFactor(self):
1110 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1134 acf_ind, ccf_ind, acf_pairs, ccf_pairs, data_acf, data_ccf = self.splitFunctions()
1111 acf_pairs = numpy.array(acf_pairs)
1135 acf_pairs = numpy.array(acf_pairs)
1112 normFactor = numpy.zeros((self.nPairs,self.nHeights))
1136 normFactor = numpy.zeros((self.nPairs, self.nHeights))
1113
1137
1114 for p in range(self.nPairs):
1138 for p in range(self.nPairs):
1115 pair = self.pairsList[p]
1139 pair = self.pairsList[p]
@@ -1117,69 +1141,69 class Correlation(JROData):
1117 ch0 = pair[0]
1141 ch0 = pair[0]
1118 ch1 = pair[1]
1142 ch1 = pair[1]
1119
1143
1120 ch0_max = numpy.max(data_acf[acf_pairs==ch0,:,:], axis=1)
1144 ch0_max = numpy.max(data_acf[acf_pairs == ch0, :, :], axis=1)
1121 ch1_max = numpy.max(data_acf[acf_pairs==ch1,:,:], axis=1)
1145 ch1_max = numpy.max(data_acf[acf_pairs == ch1, :, :], axis=1)
1122 normFactor[p,:] = numpy.sqrt(ch0_max*ch1_max)
1146 normFactor[p, :] = numpy.sqrt(ch0_max * ch1_max)
1123
1147
1124 return normFactor
1148 return normFactor
1125
1149
1126 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1150 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
1127 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1151 normFactor = property(getNormFactor, "I'm the 'normFactor property'")
1128
1152
1153
1129 class Parameters(Spectra):
1154 class Parameters(Spectra):
1130
1155
1131 experimentInfo = None #Information about the experiment
1156 experimentInfo = None # Information about the experiment
1132
1157
1133 #Information from previous data
1158 # Information from previous data
1134
1159
1135 inputUnit = None #Type of data to be processed
1160 inputUnit = None # Type of data to be processed
1136
1161
1137 operation = None #Type of operation to parametrize
1162 operation = None # Type of operation to parametrize
1138
1163
1139 #normFactor = None #Normalization Factor
1164 # normFactor = None #Normalization Factor
1140
1165
1141 groupList = None #List of Pairs, Groups, etc
1166 groupList = None # List of Pairs, Groups, etc
1142
1167
1143 #Parameters
1168 # Parameters
1144
1169
1145 data_param = None #Parameters obtained
1170 data_param = None # Parameters obtained
1146
1171
1147 data_pre = None #Data Pre Parametrization
1172 data_pre = None # Data Pre Parametrization
1148
1173
1149 data_SNR = None #Signal to Noise Ratio
1174 data_SNR = None # Signal to Noise Ratio
1150
1175
1151 # heightRange = None #Heights
1176 # heightRange = None #Heights
1152
1177
1153 abscissaList = None #Abscissa, can be velocities, lags or time
1178 abscissaList = None # Abscissa, can be velocities, lags or time
1154
1179
1155 # noise = None #Noise Potency
1180 # noise = None #Noise Potency
1156
1181
1157 utctimeInit = None #Initial UTC time
1182 utctimeInit = None # Initial UTC time
1158
1183
1159 paramInterval = None #Time interval to calculate Parameters in seconds
1184 paramInterval = None # Time interval to calculate Parameters in seconds
1160
1185
1161 useLocalTime = True
1186 useLocalTime = True
1162
1187
1163 #Fitting
1188 # Fitting
1164
1189
1165 data_error = None #Error of the estimation
1190 data_error = None # Error of the estimation
1166
1191
1167 constants = None
1192 constants = None
1168
1193
1169 library = None
1194 library = None
1170
1195
1171 #Output signal
1196 # Output signal
1172
1197
1173 outputInterval = None #Time interval to calculate output signal in seconds
1198 outputInterval = None # Time interval to calculate output signal in seconds
1174
1199
1175 data_output = None #Out signal
1200 data_output = None # Out signal
1176
1201
1177 nAvg = None
1202 nAvg = None
1178
1203
1179 noise_estimation = None
1204 noise_estimation = None
1180
1181 GauSPC = None #Fit gaussian SPC
1182
1205
1206 GauSPC = None # Fit gaussian SPC
1183
1207
1184 def __init__(self):
1208 def __init__(self):
1185 '''
1209 '''
@@ -1196,7 +1220,7 class Parameters(Spectra):
1196 datatime = []
1220 datatime = []
1197
1221
1198 if self.useLocalTime:
1222 if self.useLocalTime:
1199 time1 = self.utctimeInit - self.timeZone*60
1223 time1 = self.utctimeInit - self.timeZone * 60
1200 else:
1224 else:
1201 time1 = self.utctimeInit
1225 time1 = self.utctimeInit
1202
1226
@@ -15,7 +15,6 import os
15 import datetime
15 import datetime
16 import numpy
16 import numpy
17 import timeit
17 import timeit
18 from profilehooks import coverage, profile
19 from fractions import Fraction
18 from fractions import Fraction
20
19
21 try:
20 try:
@@ -34,6 +33,7 try:
34 except:
33 except:
35 print 'You should install "digital_rf" module if you want to read Digital RF data'
34 print 'You should install "digital_rf" module if you want to read Digital RF data'
36
35
36
37 class DigitalRFReader(ProcessingUnit):
37 class DigitalRFReader(ProcessingUnit):
38 '''
38 '''
39 classdocs
39 classdocs
@@ -63,7 +63,7 class DigitalRFReader(ProcessingUnit):
63
63
64 def __getCurrentSecond(self):
64 def __getCurrentSecond(self):
65
65
66 return self.__thisUnixSample/self.__sample_rate
66 return self.__thisUnixSample / self.__sample_rate
67
67
68 thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
68 thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.")
69
69
@@ -71,33 +71,35 class DigitalRFReader(ProcessingUnit):
71 '''
71 '''
72 In this method will be initialized every parameter of dataOut object (header, no data)
72 In this method will be initialized every parameter of dataOut object (header, no data)
73 '''
73 '''
74 ippSeconds = 1.0*self.__nSamples/self.__sample_rate
74 ippSeconds = 1.0 * self.__nSamples / self.__sample_rate
75
76 nProfiles = 1.0 / ippSeconds # Number of profiles in one second
75
77
76 nProfiles = 1.0/ippSeconds # Number of profiles in one second
77
78 try:
78 try:
79 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(self.__radarControllerHeader)
79 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
80 self.__radarControllerHeader)
80 except:
81 except:
81 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
82 self.dataOut.radarControllerHeaderObj = RadarControllerHeader(
82 txA=0,
83 txA=0,
83 txB=0,
84 txB=0,
84 nWindows=1,
85 nWindows=1,
85 nHeights=self.__nSamples,
86 nHeights=self.__nSamples,
86 firstHeight=self.__firstHeigth,
87 firstHeight=self.__firstHeigth,
87 deltaHeight=self.__deltaHeigth,
88 deltaHeight=self.__deltaHeigth,
88 codeType=self.__codeType,
89 codeType=self.__codeType,
89 nCode=self.__nCode, nBaud=self.__nBaud,
90 nCode=self.__nCode, nBaud=self.__nBaud,
90 code = self.__code)
91 code=self.__code)
91
92
92 try:
93 try:
93 self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader)
94 self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader)
94 except:
95 except:
95 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
96 self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples,
96 nProfiles=nProfiles,
97 nProfiles=nProfiles,
97 nChannels=len(self.__channelList),
98 nChannels=len(
99 self.__channelList),
98 adcResolution=14)
100 adcResolution=14)
99 self.dataOut.type = "Voltage"
101 self.dataOut.type = "Voltage"
100
102
101 self.dataOut.data = None
103 self.dataOut.data = None
102
104
103 self.dataOut.dtype = self.dtype
105 self.dataOut.dtype = self.dtype
@@ -108,7 +110,9 class DigitalRFReader(ProcessingUnit):
108
110
109 self.dataOut.nProfiles = int(nProfiles)
111 self.dataOut.nProfiles = int(nProfiles)
110
112
111 self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth
113 self.dataOut.heightList = self.__firstHeigth + \
114 numpy.arange(self.__nSamples, dtype=numpy.float) * \
115 self.__deltaHeigth
112
116
113 self.dataOut.channelList = range(self.__num_subchannels)
117 self.dataOut.channelList = range(self.__num_subchannels)
114
118
@@ -124,25 +128,29 class DigitalRFReader(ProcessingUnit):
124
128
125 self.dataOut.utctime = None
129 self.dataOut.utctime = None
126
130
127 self.dataOut.timeZone = self.__timezone/60 # timezone like jroheader, difference in minutes between UTC and localtime
131 # timezone like jroheader, difference in minutes between UTC and localtime
132 self.dataOut.timeZone = self.__timezone / 60
128
133
129 self.dataOut.dstFlag = 0
134 self.dataOut.dstFlag = 0
130
135
131 self.dataOut.errorCount = 0
136 self.dataOut.errorCount = 0
132
137
133 try:
138 try:
134 self.dataOut.nCohInt = self.fixed_metadata_dict.get('nCohInt', 1)
139 self.dataOut.nCohInt = self.fixed_metadata_dict.get(
140 'nCohInt', self.nCohInt)
135
141
136 self.dataOut.flagDecodeData = self.fixed_metadata_dict['flagDecodeData'] # asumo que la data esta decodificada
142 # asumo que la data esta decodificada
143 self.dataOut.flagDecodeData = self.fixed_metadata_dict.get(
144 'flagDecodeData', self.flagDecodeData)
137
145
138 self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] # asumo que la data esta sin flip
146 # asumo que la data esta sin flip
147 self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData']
139
148
140 self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT']
149 self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT']
141
150
142 self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime']
151 self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime']
143 except:
152 except:
144 pass
153 pass
145
146
154
147 self.dataOut.ippSeconds = ippSeconds
155 self.dataOut.ippSeconds = ippSeconds
148
156
@@ -159,7 +167,8 class DigitalRFReader(ProcessingUnit):
159 return []
167 return []
160
168
161 try:
169 try:
162 digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
170 digitalReadObj = digital_rf.DigitalRFReader(
171 path, load_all_metadata=True)
163 except:
172 except:
164 digitalReadObj = digital_rf.DigitalRFReader(path)
173 digitalReadObj = digital_rf.DigitalRFReader(path)
165
174
@@ -179,7 +188,8 class DigitalRFReader(ProcessingUnit):
179 except:
188 except:
180 timezone = 0
189 timezone = 0
181
190
182 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone
191 startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(
192 channelNameList[0]) / sample_rate - timezone
183
193
184 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
194 startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond)
185 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
195 endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond)
@@ -194,7 +204,7 class DigitalRFReader(ProcessingUnit):
194
204
195 thisDatetime = startDatetime
205 thisDatetime = startDatetime
196
206
197 while(thisDatetime<=endDatatime):
207 while(thisDatetime <= endDatatime):
198
208
199 thisDate = thisDatetime.date()
209 thisDate = thisDatetime.date()
200
210
@@ -209,18 +219,23 class DigitalRFReader(ProcessingUnit):
209
219
210 return dateList
220 return dateList
211
221
212 def setup(self, path = None,
222 def setup(self, path=None,
213 startDate = None,
223 startDate=None,
214 endDate = None,
224 endDate=None,
215 startTime = datetime.time(0,0,0),
225 startTime=datetime.time(0, 0, 0),
216 endTime = datetime.time(23,59,59),
226 endTime=datetime.time(23, 59, 59),
217 channelList = None,
227 channelList=None,
218 nSamples = None,
228 nSamples=None,
219 online = False,
229 online=False,
220 delay = 60,
230 delay=60,
221 buffer_size = 1024,
231 buffer_size=1024,
222 ippKm=None,
232 ippKm=None,
223 **kwargs):
233 nCohInt=1,
234 nCode=1,
235 nBaud=1,
236 flagDecodeData=False,
237 code=numpy.ones((1, 1), dtype=numpy.int),
238 **kwargs):
224 '''
239 '''
225 In this method we should set all initial parameters.
240 In this method we should set all initial parameters.
226
241
@@ -236,37 +251,43 class DigitalRFReader(ProcessingUnit):
236 online
251 online
237 delay
252 delay
238 '''
253 '''
254 self.nCohInt = nCohInt
255 self.flagDecodeData = flagDecodeData
239 self.i = 0
256 self.i = 0
240 if not os.path.isdir(path):
257 if not os.path.isdir(path):
241 raise ValueError, "[Reading] Directory %s does not exist" %path
258 raise ValueError, "[Reading] Directory %s does not exist" % path
242
259
243 try:
260 try:
244 self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True)
261 self.digitalReadObj = digital_rf.DigitalRFReader(
262 path, load_all_metadata=True)
245 except:
263 except:
246 self.digitalReadObj = digital_rf.DigitalRFReader(path)
264 self.digitalReadObj = digital_rf.DigitalRFReader(path)
247
265
248 channelNameList = self.digitalReadObj.get_channels()
266 channelNameList = self.digitalReadObj.get_channels()
249
267
250 if not channelNameList:
268 if not channelNameList:
251 raise ValueError, "[Reading] Directory %s does not have any files" %path
269 raise ValueError, "[Reading] Directory %s does not have any files" % path
252
270
253 if not channelList:
271 if not channelList:
254 channelList = range(len(channelNameList))
272 channelList = range(len(channelNameList))
255
273
256
257 ########## Reading metadata ######################
274 ########## Reading metadata ######################
258
275
259 top_properties = self.digitalReadObj.get_properties(channelNameList[channelList[0]])
276 top_properties = self.digitalReadObj.get_properties(
260
277 channelNameList[channelList[0]])
261
278
262 self.__num_subchannels = top_properties['num_subchannels']
279 self.__num_subchannels = top_properties['num_subchannels']
263 self.__sample_rate = 1.0 * top_properties['sample_rate_numerator'] / top_properties['sample_rate_denominator']
280 self.__sample_rate = 1.0 * \
281 top_properties['sample_rate_numerator'] / \
282 top_properties['sample_rate_denominator']
264 # self.__samples_per_file = top_properties['samples_per_file'][0]
283 # self.__samples_per_file = top_properties['samples_per_file'][0]
265 self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15?
284 self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15?
266
285
267 this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]])
286 this_metadata_file = self.digitalReadObj.get_digital_metadata(
287 channelNameList[channelList[0]])
268 metadata_bounds = this_metadata_file.get_bounds()
288 metadata_bounds = this_metadata_file.get_bounds()
269 self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ## GET FIRST HEADER
289 self.fixed_metadata_dict = this_metadata_file.read(
290 metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER
270
291
271 try:
292 try:
272 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
293 self.__processingHeader = self.fixed_metadata_dict['processingHeader']
@@ -275,7 +296,6 class DigitalRFReader(ProcessingUnit):
275 self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype'])
296 self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype'])
276 except:
297 except:
277 pass
298 pass
278
279
299
280 self.__frequency = None
300 self.__frequency = None
281
301
@@ -283,12 +303,11 class DigitalRFReader(ProcessingUnit):
283
303
284 self.__timezone = self.fixed_metadata_dict.get('timezone', 300)
304 self.__timezone = self.fixed_metadata_dict.get('timezone', 300)
285
305
286
287 try:
306 try:
288 nSamples = self.fixed_metadata_dict['nSamples']
307 nSamples = self.fixed_metadata_dict['nSamples']
289 except:
308 except:
290 nSamples = None
309 nSamples = None
291
310
292 self.__firstHeigth = 0
311 self.__firstHeigth = 0
293
312
294 try:
313 try:
@@ -296,10 +315,6 class DigitalRFReader(ProcessingUnit):
296 except:
315 except:
297 codeType = 0
316 codeType = 0
298
317
299 nCode = 1
300 nBaud = 1
301 code = numpy.ones((nCode, nBaud), dtype=numpy.int)
302
303 try:
318 try:
304 if codeType:
319 if codeType:
305 nCode = self.__radarControllerHeader['nCode']
320 nCode = self.__radarControllerHeader['nCode']
@@ -307,8 +322,7 class DigitalRFReader(ProcessingUnit):
307 code = self.__radarControllerHeader['code']
322 code = self.__radarControllerHeader['code']
308 except:
323 except:
309 pass
324 pass
310
325
311
312 if not ippKm:
326 if not ippKm:
313 try:
327 try:
314 # seconds to km
328 # seconds to km
@@ -322,42 +336,46 class DigitalRFReader(ProcessingUnit):
322
336
323 if startDate:
337 if startDate:
324 startDatetime = datetime.datetime.combine(startDate, startTime)
338 startDatetime = datetime.datetime.combine(startDate, startTime)
325 startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
339 startUTCSecond = (
340 startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone
326
341
327 if endDate:
342 if endDate:
328 endDatetime = datetime.datetime.combine(endDate, endTime)
343 endDatetime = datetime.datetime.combine(endDate, endTime)
329 endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone
344 endUTCSecond = (endDatetime - datetime.datetime(1970,
345 1, 1)).total_seconds() + self.__timezone
330
346
331 start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]])
347 start_index, end_index = self.digitalReadObj.get_bounds(
348 channelNameList[channelList[0]])
332
349
333 if not startUTCSecond:
350 if not startUTCSecond:
334 startUTCSecond = start_index/self.__sample_rate
351 startUTCSecond = start_index / self.__sample_rate
335
352
336 if start_index > startUTCSecond*self.__sample_rate:
353 if start_index > startUTCSecond * self.__sample_rate:
337 startUTCSecond = start_index/self.__sample_rate
354 startUTCSecond = start_index / self.__sample_rate
338
355
339 if not endUTCSecond:
356 if not endUTCSecond:
340 endUTCSecond = end_index/self.__sample_rate
357 endUTCSecond = end_index / self.__sample_rate
341
358
342 if end_index < endUTCSecond*self.__sample_rate:
359 if end_index < endUTCSecond * self.__sample_rate:
343 endUTCSecond = end_index/self.__sample_rate
360 endUTCSecond = end_index / self.__sample_rate
344 if not nSamples:
361 if not nSamples:
345 if not ippKm:
362 if not ippKm:
346 raise ValueError, "[Reading] nSamples or ippKm should be defined"
363 raise ValueError, "[Reading] nSamples or ippKm should be defined"
347 nSamples = int(ippKm / (1e6*0.15/self.__sample_rate))
364 nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate))
348 channelBoundList = []
365 channelBoundList = []
349 channelNameListFiltered = []
366 channelNameListFiltered = []
350
367
351 for thisIndexChannel in channelList:
368 for thisIndexChannel in channelList:
352 thisChannelName = channelNameList[thisIndexChannel]
369 thisChannelName = channelNameList[thisIndexChannel]
353 start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName)
370 start_index, end_index = self.digitalReadObj.get_bounds(
371 thisChannelName)
354 channelBoundList.append((start_index, end_index))
372 channelBoundList.append((start_index, end_index))
355 channelNameListFiltered.append(thisChannelName)
373 channelNameListFiltered.append(thisChannelName)
356
374
357 self.profileIndex = 0
375 self.profileIndex = 0
358 self.i= 0
376 self.i = 0
359 self.__delay = delay
377 self.__delay = delay
360
378
361 self.__codeType = codeType
379 self.__codeType = codeType
362 self.__nCode = nCode
380 self.__nCode = nCode
363 self.__nBaud = nBaud
381 self.__nBaud = nBaud
@@ -369,36 +387,44 class DigitalRFReader(ProcessingUnit):
369 self.__channelNameList = channelNameListFiltered
387 self.__channelNameList = channelNameListFiltered
370 self.__channelBoundList = channelBoundList
388 self.__channelBoundList = channelBoundList
371 self.__nSamples = nSamples
389 self.__nSamples = nSamples
372 self.__samples_to_read = long(nSamples) # FIJO: AHORA 40
390 self.__samples_to_read = long(nSamples) # FIJO: AHORA 40
373 self.__nChannels = len(self.__channelList)
391 self.__nChannels = len(self.__channelList)
374
392
375 self.__startUTCSecond = startUTCSecond
393 self.__startUTCSecond = startUTCSecond
376 self.__endUTCSecond = endUTCSecond
394 self.__endUTCSecond = endUTCSecond
377
395
378 self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate # Time interval
396 self.__timeInterval = 1.0 * self.__samples_to_read / \
397 self.__sample_rate # Time interval
379
398
380 if online:
399 if online:
381 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
400 # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read)
382 startUTCSecond = numpy.floor(endUTCSecond)
401 startUTCSecond = numpy.floor(endUTCSecond)
383
402
384 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
403 # por que en el otro metodo lo primero q se hace es sumar samplestoread
404 self.__thisUnixSample = long(
405 startUTCSecond * self.__sample_rate) - self.__samples_to_read
385
406
386 self.__data_buffer = numpy.zeros((self.__num_subchannels, self.__samples_to_read), dtype = numpy.complex)
407 self.__data_buffer = numpy.zeros(
408 (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex)
387
409
388 self.__setFileHeader()
410 self.__setFileHeader()
389 self.isConfig = True
411 self.isConfig = True
390
412
391 print "[Reading] Digital RF Data was found from %s to %s " %(
413 print "[Reading] Digital RF Data was found from %s to %s " % (
392 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
414 datetime.datetime.utcfromtimestamp(
393 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
415 self.__startUTCSecond - self.__timezone),
394 )
416 datetime.datetime.utcfromtimestamp(
395
417 self.__endUTCSecond - self.__timezone)
396 print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
418 )
397 datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone)
419
398 )
420 print "[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone),
421 datetime.datetime.utcfromtimestamp(
422 endUTCSecond - self.__timezone)
423 )
399 self.oldAverage = None
424 self.oldAverage = None
400 self.count = 0
425 self.count = 0
401 self.executionTime = 0
426 self.executionTime = 0
427
402 def __reload(self):
428 def __reload(self):
403 # print
429 # print
404 # print "%s not in range [%s, %s]" %(
430 # print "%s not in range [%s, %s]" %(
@@ -413,18 +439,21 class DigitalRFReader(ProcessingUnit):
413 except:
439 except:
414 self.digitalReadObj.reload()
440 self.digitalReadObj.reload()
415
441
416 start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]])
442 start_index, end_index = self.digitalReadObj.get_bounds(
443 self.__channelNameList[self.__channelList[0]])
417
444
418 if start_index > self.__startUTCSecond*self.__sample_rate:
445 if start_index > self.__startUTCSecond * self.__sample_rate:
419 self.__startUTCSecond = 1.0*start_index/self.__sample_rate
446 self.__startUTCSecond = 1.0 * start_index / self.__sample_rate
420
447
421 if end_index > self.__endUTCSecond*self.__sample_rate:
448 if end_index > self.__endUTCSecond * self.__sample_rate:
422 self.__endUTCSecond = 1.0*end_index/self.__sample_rate
449 self.__endUTCSecond = 1.0 * end_index / self.__sample_rate
423 print
450 print
424 print "[Reading] New timerange found [%s, %s] " %(
451 print "[Reading] New timerange found [%s, %s] " % (
425 datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone),
452 datetime.datetime.utcfromtimestamp(
426 datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone)
453 self.__startUTCSecond - self.__timezone),
427 )
454 datetime.datetime.utcfromtimestamp(
455 self.__endUTCSecond - self.__timezone)
456 )
428
457
429 return True
458 return True
430
459
@@ -434,12 +463,14 class DigitalRFReader(ProcessingUnit):
434 t0 = time()
463 t0 = time()
435 toExecute()
464 toExecute()
436 self.executionTime = time() - t0
465 self.executionTime = time() - t0
437 if self.oldAverage is None: self.oldAverage = self.executionTime
466 if self.oldAverage is None:
438 self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0)
467 self.oldAverage = self.executionTime
468 self.oldAverage = (self.executionTime + self.count *
469 self.oldAverage) / (self.count + 1.0)
439 self.count = self.count + 1.0
470 self.count = self.count + 1.0
440 return
471 return
441
472
442 def __readNextBlock(self, seconds=30, volt_scale = 1):
473 def __readNextBlock(self, seconds=30, volt_scale=1):
443 '''
474 '''
444 '''
475 '''
445
476
@@ -447,21 +478,21 class DigitalRFReader(ProcessingUnit):
447 self.__flagDiscontinuousBlock = False
478 self.__flagDiscontinuousBlock = False
448 self.__thisUnixSample += self.__samples_to_read
479 self.__thisUnixSample += self.__samples_to_read
449
480
450 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
481 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
451 print "[Reading] There are no more data into selected time-range"
482 print "[Reading] There are no more data into selected time-range"
452 if self.__online:
483 if self.__online:
453 self.__reload()
484 self.__reload()
454 else:
485 else:
455 return False
486 return False
456
487
457 if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate:
488 if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate:
458 return False
489 return False
459 self.__thisUnixSample -= self.__samples_to_read
490 self.__thisUnixSample -= self.__samples_to_read
460
491
461 indexChannel = 0
492 indexChannel = 0
462
493
463 dataOk = False
494 dataOk = False
464 for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS?
495 for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS?
465 for indexSubchannel in range(self.__num_subchannels):
496 for indexSubchannel in range(self.__num_subchannels):
466 try:
497 try:
467 t0 = time()
498 t0 = time()
@@ -469,47 +500,48 class DigitalRFReader(ProcessingUnit):
469 self.__samples_to_read,
500 self.__samples_to_read,
470 thisChannelName, sub_channel=indexSubchannel)
501 thisChannelName, sub_channel=indexSubchannel)
471 self.executionTime = time() - t0
502 self.executionTime = time() - t0
472 if self.oldAverage is None: self.oldAverage = self.executionTime
503 if self.oldAverage is None:
473 self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0)
504 self.oldAverage = self.executionTime
505 self.oldAverage = (
506 self.executionTime + self.count * self.oldAverage) / (self.count + 1.0)
474 self.count = self.count + 1.0
507 self.count = self.count + 1.0
475
508
476 except IOError, e:
509 except IOError, e:
477 #read next profile
510 # read next profile
478 self.__flagDiscontinuousBlock = True
511 self.__flagDiscontinuousBlock = True
479 print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
512 print "[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e
480 break
513 break
481
514
482 if result.shape[0] != self.__samples_to_read:
515 if result.shape[0] != self.__samples_to_read:
483 self.__flagDiscontinuousBlock = True
516 self.__flagDiscontinuousBlock = True
484 print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
517 print "[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
485 result.shape[0],
518 result.shape[0],
486 self.__samples_to_read)
519 self.__samples_to_read)
487 break
520 break
488
521
489 self.__data_buffer[indexSubchannel,:] = result*volt_scale
522 self.__data_buffer[indexSubchannel, :] = result * volt_scale
490
523
491 indexChannel += 1
524 indexChannel += 1
492
525
493 dataOk = True
526 dataOk = True
494
527
495 self.__utctime = self.__thisUnixSample/self.__sample_rate
528 self.__utctime = self.__thisUnixSample / self.__sample_rate
496
529
497 if not dataOk:
530 if not dataOk:
498 return False
531 return False
499
532
500 print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
533 print "[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone),
501 self.__samples_to_read,
534 self.__samples_to_read,
502 self.__timeInterval)
535 self.__timeInterval)
503
536
504 self.__bufferIndex = 0
537 self.__bufferIndex = 0
505
538
506 return True
539 return True
507
540
508 def __isBufferEmpty(self):
541 def __isBufferEmpty(self):
509 return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40
542 return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40
510
543
511 def getData(self, seconds=30, nTries=5):
544 def getData(self, seconds=30, nTries=5):
512
513 '''
545 '''
514 This method gets the data from files and put the data into the dataOut object
546 This method gets the data from files and put the data into the dataOut object
515
547
@@ -535,7 +567,7 class DigitalRFReader(ProcessingUnit):
535 while True:
567 while True:
536 if self.__readNextBlock():
568 if self.__readNextBlock():
537 break
569 break
538 if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate:
570 if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate:
539 return False
571 return False
540
572
541 if self.__flagDiscontinuousBlock:
573 if self.__flagDiscontinuousBlock:
@@ -549,11 +581,13 class DigitalRFReader(ProcessingUnit):
549 if err_counter > nTries:
581 if err_counter > nTries:
550 return False
582 return False
551
583
552 print '[Reading] waiting %d seconds to read a new block' %seconds
584 print '[Reading] waiting %d seconds to read a new block' % seconds
553 sleep(seconds)
585 sleep(seconds)
554
586
555 self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples]
587 self.dataOut.data = self.__data_buffer[:,
556 self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate
588 self.__bufferIndex:self.__bufferIndex + self.__nSamples]
589 self.dataOut.utctime = (
590 self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate
557 self.dataOut.flagNoData = False
591 self.dataOut.flagNoData = False
558 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
592 self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock
559 self.dataOut.profileIndex = self.profileIndex
593 self.dataOut.profileIndex = self.profileIndex
@@ -583,12 +617,11 class DigitalRFReader(ProcessingUnit):
583 return
617 return
584 # print self.profileIndex
618 # print self.profileIndex
585
619
586
587 def run(self, **kwargs):
620 def run(self, **kwargs):
588 '''
621 '''
589 This method will be called many times so here you should put all your code
622 This method will be called many times so here you should put all your code
590 '''
623 '''
591
624
592 if not self.isConfig:
625 if not self.isConfig:
593 self.setup(**kwargs)
626 self.setup(**kwargs)
594 #self.i = self.i+1
627 #self.i = self.i+1
@@ -596,6 +629,7 class DigitalRFReader(ProcessingUnit):
596
629
597 return
630 return
598
631
632
599 class DigitalRFWriter(Operation):
633 class DigitalRFWriter(Operation):
600 '''
634 '''
601 classdocs
635 classdocs
@@ -607,7 +641,7 class DigitalRFWriter(Operation):
607 '''
641 '''
608 Operation.__init__(self, **kwargs)
642 Operation.__init__(self, **kwargs)
609 self.metadata_dict = {}
643 self.metadata_dict = {}
610 self.dataOut = None
644 self.dataOut = None
611 self.dtype = None
645 self.dtype = None
612
646
613 def setHeader(self):
647 def setHeader(self):
@@ -624,7 +658,7 class DigitalRFWriter(Operation):
624 self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock
658 self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock
625 self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime
659 self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime
626 self.metadata_dict['nCohInt'] = self.dataOut.nCohInt
660 self.metadata_dict['nCohInt'] = self.dataOut.nCohInt
627
661
628 return
662 return
629
663
630 def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'):
664 def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'):
@@ -636,7 +670,7 class DigitalRFWriter(Operation):
636 self.setHeader()
670 self.setHeader()
637 self.__ippSeconds = dataOut.ippSeconds
671 self.__ippSeconds = dataOut.ippSeconds
638 self.__deltaH = dataOut.getDeltaH()
672 self.__deltaH = dataOut.getDeltaH()
639 self.__sample_rate = 1e6*0.15/self.__deltaH
673 self.__sample_rate = 1e6 * 0.15 / self.__deltaH
640 self.__dtype = dataOut.dtype
674 self.__dtype = dataOut.dtype
641 if len(dataOut.dtype) == 2:
675 if len(dataOut.dtype) == 2:
642 self.__dtype = dataOut.dtype[0]
676 self.__dtype = dataOut.dtype[0]
@@ -644,16 +678,18 class DigitalRFWriter(Operation):
644 self.__nProfiles = dataOut.nProfiles
678 self.__nProfiles = dataOut.nProfiles
645 self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile
679 self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile
646
680
647 self.arr_data = arr_data = numpy.ones((self.__nSamples, len(self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
681 self.arr_data = arr_data = numpy.ones((self.__nSamples, len(
682 self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)])
648
683
649 file_cadence_millisecs = long(1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000
684 file_cadence_millisecs = long(
685 1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000
650 sub_cadence_secs = file_cadence_millisecs / 500
686 sub_cadence_secs = file_cadence_millisecs / 500
651
687
652 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
688 sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator()
653 sample_rate_numerator = long(sample_rate_fraction.numerator)
689 sample_rate_numerator = long(sample_rate_fraction.numerator)
654 sample_rate_denominator = long(sample_rate_fraction.denominator)
690 sample_rate_denominator = long(sample_rate_fraction.denominator)
655 start_global_index = dataOut.utctime * self.__sample_rate
691 start_global_index = dataOut.utctime * self.__sample_rate
656
692
657 uuid = 'prueba'
693 uuid = 'prueba'
658 compression_level = 1
694 compression_level = 1
659 checksum = False
695 checksum = False
@@ -663,45 +699,47 class DigitalRFWriter(Operation):
663 marching_periods = False
699 marching_periods = False
664
700
665 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence,
701 self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence,
666 fileCadence, start_global_index,
702 fileCadence, start_global_index,
667 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
703 sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum,
668 is_complex, num_subchannels, is_continuous, marching_periods)
704 is_complex, num_subchannels, is_continuous, marching_periods)
669
705
670 metadata_dir = os.path.join(path, 'metadata')
706 metadata_dir = os.path.join(path, 'metadata')
671 os.system('mkdir %s' % (metadata_dir))
707 os.system('mkdir %s' % (metadata_dir))
672
673 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, ##236, file_cadence_millisecs / 1000
674 sample_rate_numerator, sample_rate_denominator,
675 metadataFile)
676
708
709 self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000
710 sample_rate_numerator, sample_rate_denominator,
711 metadataFile)
677
712
678 self.isConfig = True
713 self.isConfig = True
679 self.currentSample = 0
714 self.currentSample = 0
680 self.oldAverage = 0
715 self.oldAverage = 0
681 self.count = 0
716 self.count = 0
682 return
717 return
683
718
684 def writeMetadata(self):
719 def writeMetadata(self):
685 print '[Writing] - Writing metadata'
720 print '[Writing] - Writing metadata'
686 start_idx = self.__sample_rate * self.dataOut.utctime
721 start_idx = self.__sample_rate * self.dataOut.utctime
687
722
688 self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict()
723 self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict(
689 self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict()
724 )
690 self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict()
725 self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict(
726 )
727 self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict(
728 )
691 self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict)
729 self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict)
692 return
730 return
693
731
694
695 def timeit(self, toExecute):
732 def timeit(self, toExecute):
696 t0 = time()
733 t0 = time()
697 toExecute()
734 toExecute()
698 self.executionTime = time() - t0
735 self.executionTime = time() - t0
699 if self.oldAverage is None: self.oldAverage = self.executionTime
736 if self.oldAverage is None:
700 self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0)
737 self.oldAverage = self.executionTime
738 self.oldAverage = (self.executionTime + self.count *
739 self.oldAverage) / (self.count + 1.0)
701 self.count = self.count + 1.0
740 self.count = self.count + 1.0
702 return
741 return
703
742
704
705 def writeData(self):
743 def writeData(self):
706 for i in range(self.dataOut.systemHeaderObj.nSamples):
744 for i in range(self.dataOut.systemHeaderObj.nSamples):
707 for channel in self.dataOut.channelList:
745 for channel in self.dataOut.channelList:
@@ -710,9 +748,9 class DigitalRFWriter(Operation):
710
748
711 def f(): return self.digitalWriteObj.rf_write(self.arr_data)
749 def f(): return self.digitalWriteObj.rf_write(self.arr_data)
712 self.timeit(f)
750 self.timeit(f)
713
751
714 return
752 return
715
753
716 def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=100, dirCadence=25, metadataCadence=1, **kwargs):
754 def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=100, dirCadence=25, metadataCadence=1, **kwargs):
717 '''
755 '''
718 This method will be called many times so here you should put all your code
756 This method will be called many times so here you should put all your code
@@ -722,14 +760,15 class DigitalRFWriter(Operation):
722 # print dataOut.__dict__
760 # print dataOut.__dict__
723 self.dataOut = dataOut
761 self.dataOut = dataOut
724 if not self.isConfig:
762 if not self.isConfig:
725 self.setup(dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, **kwargs)
763 self.setup(dataOut, path, frequency, fileCadence,
764 dirCadence, metadataCadence, **kwargs)
726 self.writeMetadata()
765 self.writeMetadata()
727
766
728 self.writeData()
767 self.writeData()
729
768
730 ## self.currentSample += 1
769 ## self.currentSample += 1
731 ## if self.dataOut.flagDataAsBlock or self.currentSample == 1:
770 # if self.dataOut.flagDataAsBlock or self.currentSample == 1:
732 ## self.writeMetadata()
771 # self.writeMetadata()
733 ## if self.currentSample == self.__nProfiles: self.currentSample = 0
772 ## if self.currentSample == self.__nProfiles: self.currentSample = 0
734
773
735 def close(self):
774 def close(self):
@@ -739,7 +778,7 class DigitalRFWriter(Operation):
739 self.digitalWriteObj.close()
778 self.digitalWriteObj.close()
740 except:
779 except:
741 pass
780 pass
742
781
743 # raise
782 # raise
744 if __name__ == '__main__':
783 if __name__ == '__main__':
745
784
@@ -748,4 +787,4 if __name__ == '__main__':
748 while True:
787 while True:
749 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
788 readObj.run(path='/home/jchavez/jicamarca/mocked_data/')
750 # readObj.printInfo()
789 # readObj.printInfo()
751 # readObj.printNumberOfBlock()
790 # readObj.printNumberOfBlock()
@@ -616,7 +616,6 class Decoder(Operation):
616 def __convolutionInTime(self, data):
616 def __convolutionInTime(self, data):
617
617
618 code = self.code[self.__profIndex]
618 code = self.code[self.__profIndex]
619
620 for i in range(self.__nChannels):
619 for i in range(self.__nChannels):
621 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
620 self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:]
622
621
@@ -666,7 +665,6 class Decoder(Operation):
666 code = dataOut.code
665 code = dataOut.code
667 else:
666 else:
668 code = numpy.array(code).reshape(nCode,nBaud)
667 code = numpy.array(code).reshape(nCode,nBaud)
669
670 self.setup(code, osamp, dataOut)
668 self.setup(code, osamp, dataOut)
671
669
672 self.isConfig = True
670 self.isConfig = True
General Comments 0
You need to be logged in to leave comments. Login now