@@ -30,7 +30,7 rti.addParameter(name='wr_period', value='5', format='int') | |||
|
30 | 30 | rti.addParameter(name='exp_code', value='22', format='int') |
|
31 | 31 | |
|
32 | 32 | |
|
33 |
|
|
|
33 | project.start() | |
|
34 | 34 | ''' |
|
35 | 35 | |
|
36 | 36 | multiprocess = '''from schainpy.controller import Project, MPProject |
@@ -31,6 +31,7 def getNumpyDtype(dataTypeCode): | |||
|
31 | 31 | |
|
32 | 32 | return numpyDtype |
|
33 | 33 | |
|
34 | ||
|
34 | 35 | def getDataTypeCode(numpyDtype): |
|
35 | 36 | |
|
36 | 37 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
@@ -50,6 +51,7 def getDataTypeCode(numpyDtype): | |||
|
50 | 51 | |
|
51 | 52 | return datatype |
|
52 | 53 | |
|
54 | ||
|
53 | 55 | def hildebrand_sekhon(data, navg): |
|
54 | 56 | """ |
|
55 | 57 | This method is for the objective determination of the noise level in Doppler spectra. This |
@@ -110,6 +112,7 class Beam: | |||
|
110 | 112 | self.azimuthList = [] |
|
111 | 113 | self.zenithList = [] |
|
112 | 114 | |
|
115 | ||
|
113 | 116 | class GenericData(object): |
|
114 | 117 | |
|
115 | 118 | flagNoData = True |
@@ -143,6 +146,7 class GenericData(object): | |||
|
143 | 146 | |
|
144 | 147 | return self.flagNoData |
|
145 | 148 | |
|
149 | ||
|
146 | 150 | class JROData(GenericData): |
|
147 | 151 | |
|
148 | 152 | # m_BasicHeader = BasicHeader() |
@@ -366,7 +370,8 class JROData(GenericData): | |||
|
366 | 370 | return |
|
367 | 371 | |
|
368 | 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 | 375 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
371 | 376 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
372 | 377 | datatime = property(getDatatime, "I'm the 'datatime' property") |
@@ -378,6 +383,7 class JROData(GenericData): | |||
|
378 | 383 | nCode = property(get_ncode, set_ncode) |
|
379 | 384 | nBaud = property(get_nbaud, set_nbaud) |
|
380 | 385 | |
|
386 | ||
|
381 | 387 | class Voltage(JROData): |
|
382 | 388 | |
|
383 | 389 | #data es un numpy array de 2 dmensiones (canales, alturas) |
@@ -494,6 +500,7 class Voltage(JROData): | |||
|
494 | 500 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
495 | 501 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
496 | 502 | |
|
503 | ||
|
497 | 504 | class Spectra(JROData): |
|
498 | 505 | |
|
499 | 506 | #data spc es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
@@ -587,7 +594,6 class Spectra(JROData): | |||
|
587 | 594 | |
|
588 | 595 | self.noise_estimation = None |
|
589 | 596 | |
|
590 | ||
|
591 | 597 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
592 | 598 | """ |
|
593 | 599 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
@@ -599,7 +605,8 class Spectra(JROData): | |||
|
599 | 605 | noise = numpy.zeros(self.nChannels) |
|
600 | 606 | |
|
601 | 607 | for channel in range(self.nChannels): |
|
602 |
daux = self.data_spc[channel, |
|
|
608 | daux = self.data_spc[channel, | |
|
609 | xmin_index:xmax_index, ymin_index:ymax_index] | |
|
603 | 610 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
604 | 611 | |
|
605 | 612 | return noise |
@@ -607,36 +614,45 class Spectra(JROData): | |||
|
607 | 614 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): |
|
608 | 615 | |
|
609 | 616 | if self.noise_estimation is not None: |
|
610 |
|
|
|
617 | # this was estimated by getNoise Operation defined in jroproc_spectra.py | |
|
618 | return self.noise_estimation | |
|
611 | 619 | else: |
|
612 |
noise = self.getNoisebyHildebrand( |
|
|
620 | noise = self.getNoisebyHildebrand( | |
|
621 | xmin_index, xmax_index, ymin_index, ymax_index) | |
|
613 | 622 | return noise |
|
614 | 623 | |
|
615 | 624 | def getFreqRangeTimeResponse(self, extrapoints=0): |
|
616 | 625 | |
|
617 | 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 | 631 | return freqrange |
|
621 | 632 | |
|
622 | 633 | def getAcfRange(self, extrapoints=0): |
|
623 | 634 | |
|
624 | 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 | 640 | return freqrange |
|
628 | 641 | |
|
629 | 642 | def getFreqRange(self, extrapoints=0): |
|
630 | 643 | |
|
631 | 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 | 649 | return freqrange |
|
635 | 650 | |
|
636 | 651 | def getVelRange(self, extrapoints=0): |
|
637 | 652 | |
|
638 | 653 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
639 |
velrange = deltav*(numpy.arange(self.nFFTPoints+ |
|
|
654 | velrange = deltav * (numpy.arange(self.nFFTPoints + | |
|
655 | extrapoints) - self.nFFTPoints / 2.) # - deltav/2 | |
|
640 | 656 | |
|
641 | 657 | return velrange |
|
642 | 658 | |
@@ -655,7 +671,8 class Spectra(JROData): | |||
|
655 | 671 | if self.flagDecodeData: |
|
656 | 672 | pwcode = numpy.sum(self.code[0]**2) |
|
657 | 673 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
658 |
normFactor = self.nProfiles*self.nIncohInt* |
|
|
674 | normFactor = self.nProfiles * self.nIncohInt * \ | |
|
675 | self.nCohInt * pwcode * self.windowOfFilter | |
|
659 | 676 | |
|
660 | 677 | return normFactor |
|
661 | 678 | |
@@ -697,11 +714,13 class Spectra(JROData): | |||
|
697 | 714 | pairsIndexList = [] |
|
698 | 715 | for pair in pairsList: |
|
699 | 716 | if pair not in self.pairsList: |
|
700 |
raise ValueError, "Pair %s is not in dataOut.pairsList" %( |
|
|
717 | raise ValueError, "Pair %s is not in dataOut.pairsList" % ( | |
|
718 | pair) | |
|
701 | 719 |
pairsIndexList.append(self.pairsList.index(pair)) |
|
702 | 720 | for i in range(len(pairsIndexList)): |
|
703 | 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 | 724 | powa = numpy.average(self.data_spc[pair[0], :, :], axis=0) |
|
706 | 725 | powb = numpy.average(self.data_spc[pair[1], :, :], axis=0) |
|
707 | 726 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
@@ -722,12 +741,16 class Spectra(JROData): | |||
|
722 | 741 | return |
|
723 | 742 | |
|
724 | 743 | nPairs = property(getNPairs, setValue, "I'm the 'nPairs' property.") |
|
725 | pairsIndexList = property(getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") | |
|
726 | normFactor = property(getNormFactor, setValue, "I'm the 'getNormFactor' property.") | |
|
744 | pairsIndexList = property( | |
|
745 | getPairsIndexList, setValue, "I'm the 'pairsIndexList' property.") | |
|
746 | normFactor = property(getNormFactor, setValue, | |
|
747 | "I'm the 'getNormFactor' property.") | |
|
727 | 748 | flag_cspc = property(getFlagCspc, setValue) |
|
728 | 749 | flag_dc = property(getFlagDc, setValue) |
|
729 | 750 | noise = property(getNoise, setValue, "I'm the 'nHeights' property.") |
|
730 |
timeInterval = property(getTimeInterval, setValue, |
|
|
751 | timeInterval = property(getTimeInterval, setValue, | |
|
752 | "I'm the 'timeInterval' property") | |
|
753 | ||
|
731 | 754 | |
|
732 | 755 | class SpectraHeis(Spectra): |
|
733 | 756 | |
@@ -803,6 +826,7 class SpectraHeis(Spectra): | |||
|
803 | 826 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
804 | 827 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
805 | 828 | |
|
829 | ||
|
806 | 830 | class Fits(JROData): |
|
807 | 831 | |
|
808 | 832 | heightList = None |
@@ -838,7 +862,6 class Fits(JROData): | |||
|
838 | 862 | |
|
839 | 863 | realtime = False |
|
840 | 864 | |
|
841 | ||
|
842 | 865 | def __init__(self): |
|
843 | 866 | |
|
844 | 867 | self.type = "Fits" |
@@ -879,7 +902,6 class Fits(JROData): | |||
|
879 | 902 | # self.comments = '' |
|
880 | 903 | # |
|
881 | 904 | |
|
882 | ||
|
883 | 905 | def getltctime(self): |
|
884 | 906 | |
|
885 | 907 | if self.useLocalTime: |
@@ -945,7 +967,8 class Fits(JROData): | |||
|
945 | 967 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
946 | 968 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
947 | 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 | 972 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
950 | 973 | |
|
951 | 974 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
@@ -984,7 +1007,6 class Correlation(JROData): | |||
|
984 | 1007 | |
|
985 | 1008 | nAvg = None |
|
986 | 1009 | |
|
987 | ||
|
988 | 1010 | def __init__(self): |
|
989 | 1011 | ''' |
|
990 | 1012 | Constructor |
@@ -1049,7 +1071,8 class Correlation(JROData): | |||
|
1049 | 1071 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
1050 | 1072 | |
|
1051 | 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 | 1077 | if mode == 2: |
|
1055 | 1078 | |
@@ -1070,7 +1093,8 class Correlation(JROData): | |||
|
1070 | 1093 | cjunkid = sum(junkid) |
|
1071 | 1094 | |
|
1072 | 1095 | if cjunkid.any(): |
|
1073 |
jspectra[ich,freq_dc,junkid.nonzero()] = ( |
|
|
1096 | jspectra[ich, freq_dc, junkid.nonzero()] = ( | |
|
1097 | jspectra[ich, ind_vel[1], junkid] + jspectra[ich, ind_vel[2], junkid]) / 2 | |
|
1074 | 1098 | |
|
1075 | 1099 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] |
|
1076 | 1100 | |
@@ -1126,6 +1150,7 class Correlation(JROData): | |||
|
1126 | 1150 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
1127 | 1151 | normFactor = property(getNormFactor, "I'm the 'normFactor property'") |
|
1128 | 1152 | |
|
1153 | ||
|
1129 | 1154 | class Parameters(Spectra): |
|
1130 | 1155 | |
|
1131 | 1156 |
experimentInfo = None |
@@ -1180,7 +1205,6 class Parameters(Spectra): | |||
|
1180 | 1205 | |
|
1181 | 1206 | GauSPC = None #Fit gaussian SPC |
|
1182 | 1207 | |
|
1183 | ||
|
1184 | 1208 | def __init__(self): |
|
1185 | 1209 | ''' |
|
1186 | 1210 | Constructor |
@@ -15,7 +15,6 import os | |||
|
15 | 15 | import datetime |
|
16 | 16 | import numpy |
|
17 | 17 | import timeit |
|
18 | from profilehooks import coverage, profile | |
|
19 | 18 | from fractions import Fraction |
|
20 | 19 | |
|
21 | 20 | try: |
@@ -34,6 +33,7 try: | |||
|
34 | 33 | except: |
|
35 | 34 | print 'You should install "digital_rf" module if you want to read Digital RF data' |
|
36 | 35 | |
|
36 | ||
|
37 | 37 | class DigitalRFReader(ProcessingUnit): |
|
38 | 38 | ''' |
|
39 | 39 | classdocs |
@@ -76,7 +76,8 class DigitalRFReader(ProcessingUnit): | |||
|
76 | 76 | nProfiles = 1.0/ippSeconds # Number of profiles in one second |
|
77 | 77 | |
|
78 | 78 | try: |
|
79 |
self.dataOut.radarControllerHeaderObj = RadarControllerHeader( |
|
|
79 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( | |
|
80 | self.__radarControllerHeader) | |
|
80 | 81 | except: |
|
81 | 82 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( |
|
82 | 83 | txA=0, |
@@ -94,7 +95,8 class DigitalRFReader(ProcessingUnit): | |||
|
94 | 95 | except: |
|
95 | 96 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, |
|
96 | 97 | nProfiles=nProfiles, |
|
97 |
nChannels=len( |
|
|
98 | nChannels=len( | |
|
99 | self.__channelList), | |
|
98 | 100 | adcResolution=14) |
|
99 | 101 | self.dataOut.type = "Voltage" |
|
100 | 102 | |
@@ -108,7 +110,9 class DigitalRFReader(ProcessingUnit): | |||
|
108 | 110 | |
|
109 | 111 | self.dataOut.nProfiles = int(nProfiles) |
|
110 | 112 | |
|
111 |
self.dataOut.heightList = self.__firstHeigth + |
|
|
113 | self.dataOut.heightList = self.__firstHeigth + \ | |
|
114 | numpy.arange(self.__nSamples, dtype=numpy.float) * \ | |
|
115 | self.__deltaHeigth | |
|
112 | 116 | |
|
113 | 117 | self.dataOut.channelList = range(self.__num_subchannels) |
|
114 | 118 | |
@@ -124,18 +128,23 class DigitalRFReader(ProcessingUnit): | |||
|
124 | 128 | |
|
125 | 129 | self.dataOut.utctime = None |
|
126 | 130 | |
|
127 |
|
|
|
131 | # timezone like jroheader, difference in minutes between UTC and localtime | |
|
132 | self.dataOut.timeZone = self.__timezone / 60 | |
|
128 | 133 | |
|
129 | 134 | self.dataOut.dstFlag = 0 |
|
130 | 135 | |
|
131 | 136 | self.dataOut.errorCount = 0 |
|
132 | 137 | |
|
133 | 138 | try: |
|
134 |
self.dataOut.nCohInt = self.fixed_metadata_dict.get( |
|
|
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 | 149 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] |
|
141 | 150 | |
@@ -143,7 +152,6 class DigitalRFReader(ProcessingUnit): | |||
|
143 | 152 | except: |
|
144 | 153 | pass |
|
145 | 154 | |
|
146 | ||
|
147 | 155 | self.dataOut.ippSeconds = ippSeconds |
|
148 | 156 | |
|
149 | 157 | # Time interval between profiles |
@@ -159,7 +167,8 class DigitalRFReader(ProcessingUnit): | |||
|
159 | 167 | return [] |
|
160 | 168 | |
|
161 | 169 | try: |
|
162 |
digitalReadObj = digital_rf.DigitalRFReader( |
|
|
170 | digitalReadObj = digital_rf.DigitalRFReader( | |
|
171 | path, load_all_metadata=True) | |
|
163 | 172 | except: |
|
164 | 173 | digitalReadObj = digital_rf.DigitalRFReader(path) |
|
165 | 174 | |
@@ -179,7 +188,8 class DigitalRFReader(ProcessingUnit): | |||
|
179 | 188 | except: |
|
180 | 189 | timezone = 0 |
|
181 | 190 | |
|
182 |
startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( |
|
|
191 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( | |
|
192 | channelNameList[0]) / sample_rate - timezone | |
|
183 | 193 | |
|
184 | 194 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) |
|
185 | 195 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) |
@@ -220,6 +230,11 class DigitalRFReader(ProcessingUnit): | |||
|
220 | 230 |
|
|
221 | 231 |
|
|
222 | 232 |
|
|
233 | nCohInt=1, | |
|
234 | nCode=1, | |
|
235 | nBaud=1, | |
|
236 | flagDecodeData=False, | |
|
237 | code=numpy.ones((1, 1), dtype=numpy.int), | |
|
223 | 238 |
|
|
224 | 239 | ''' |
|
225 | 240 | In this method we should set all initial parameters. |
@@ -236,12 +251,15 class DigitalRFReader(ProcessingUnit): | |||
|
236 | 251 | online |
|
237 | 252 | delay |
|
238 | 253 | ''' |
|
254 | self.nCohInt = nCohInt | |
|
255 | self.flagDecodeData = flagDecodeData | |
|
239 | 256 | self.i = 0 |
|
240 | 257 | if not os.path.isdir(path): |
|
241 | 258 | raise ValueError, "[Reading] Directory %s does not exist" %path |
|
242 | 259 | |
|
243 | 260 | try: |
|
244 |
self.digitalReadObj = digital_rf.DigitalRFReader( |
|
|
261 | self.digitalReadObj = digital_rf.DigitalRFReader( | |
|
262 | path, load_all_metadata=True) | |
|
245 | 263 | except: |
|
246 | 264 | self.digitalReadObj = digital_rf.DigitalRFReader(path) |
|
247 | 265 | |
@@ -253,20 +271,23 class DigitalRFReader(ProcessingUnit): | |||
|
253 | 271 | if not channelList: |
|
254 | 272 | channelList = range(len(channelNameList)) |
|
255 | 273 | |
|
256 | ||
|
257 | 274 | ########## Reading metadata ###################### |
|
258 | 275 | |
|
259 |
top_properties = self.digitalReadObj.get_properties( |
|
|
260 | ||
|
276 | top_properties = self.digitalReadObj.get_properties( | |
|
277 | channelNameList[channelList[0]]) | |
|
261 | 278 | |
|
262 | 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 | 283 | # self.__samples_per_file = top_properties['samples_per_file'][0] |
|
265 |
self.__deltaHeigth = 1e6*0.15/self.__sample_rate |
|
|
284 | self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15? | |
|
266 | 285 | |
|
267 |
this_metadata_file = self.digitalReadObj.get_digital_metadata( |
|
|
286 | this_metadata_file = self.digitalReadObj.get_digital_metadata( | |
|
287 | channelNameList[channelList[0]]) | |
|
268 | 288 | metadata_bounds = this_metadata_file.get_bounds() |
|
269 |
self.fixed_metadata_dict = this_metadata_file.read( |
|
|
289 | self.fixed_metadata_dict = this_metadata_file.read( | |
|
290 | metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER | |
|
270 | 291 | |
|
271 | 292 | try: |
|
272 | 293 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] |
@@ -276,14 +297,12 class DigitalRFReader(ProcessingUnit): | |||
|
276 | 297 | except: |
|
277 | 298 | pass |
|
278 | 299 | |
|
279 | ||
|
280 | 300 | self.__frequency = None |
|
281 | 301 | |
|
282 | 302 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) |
|
283 | 303 | |
|
284 | 304 | self.__timezone = self.fixed_metadata_dict.get('timezone', 300) |
|
285 | 305 | |
|
286 | ||
|
287 | 306 | try: |
|
288 | 307 | nSamples = self.fixed_metadata_dict['nSamples'] |
|
289 | 308 | except: |
@@ -296,10 +315,6 class DigitalRFReader(ProcessingUnit): | |||
|
296 | 315 | except: |
|
297 | 316 | codeType = 0 |
|
298 | 317 | |
|
299 | nCode = 1 | |
|
300 | nBaud = 1 | |
|
301 | code = numpy.ones((nCode, nBaud), dtype=numpy.int) | |
|
302 | ||
|
303 | 318 | try: |
|
304 | 319 | if codeType: |
|
305 | 320 | nCode = self.__radarControllerHeader['nCode'] |
@@ -308,7 +323,6 class DigitalRFReader(ProcessingUnit): | |||
|
308 | 323 | except: |
|
309 | 324 | pass |
|
310 | 325 | |
|
311 | ||
|
312 | 326 | if not ippKm: |
|
313 | 327 | try: |
|
314 | 328 | # seconds to km |
@@ -322,13 +336,16 class DigitalRFReader(ProcessingUnit): | |||
|
322 | 336 | |
|
323 | 337 | if startDate: |
|
324 | 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 | 342 | if endDate: |
|
328 | 343 | endDatetime = datetime.datetime.combine(endDate, endTime) |
|
329 |
endUTCSecond = (endDatetime-datetime.datetime(1970, |
|
|
344 | endUTCSecond = (endDatetime - datetime.datetime(1970, | |
|
345 | 1, 1)).total_seconds() + self.__timezone | |
|
330 | 346 | |
|
331 |
start_index, end_index = self.digitalReadObj.get_bounds( |
|
|
347 | start_index, end_index = self.digitalReadObj.get_bounds( | |
|
348 | channelNameList[channelList[0]]) | |
|
332 | 349 | |
|
333 | 350 | if not startUTCSecond: |
|
334 | 351 |
startUTCSecond = start_index/self.__sample_rate |
@@ -350,7 +367,8 class DigitalRFReader(ProcessingUnit): | |||
|
350 | 367 | |
|
351 | 368 | for thisIndexChannel in channelList: |
|
352 | 369 |
thisChannelName = |
|
353 |
start_index, end_index = self.digitalReadObj.get_bounds( |
|
|
370 | start_index, end_index = self.digitalReadObj.get_bounds( | |
|
371 | thisChannelName) | |
|
354 | 372 | channelBoundList.append((start_index, end_index)) |
|
355 | 373 | channelNameListFiltered.append(thisChannelName) |
|
356 | 374 | |
@@ -375,30 +393,38 class DigitalRFReader(ProcessingUnit): | |||
|
375 | 393 | self.__startUTCSecond = startUTCSecond |
|
376 | 394 | self.__endUTCSecond = endUTCSecond |
|
377 | 395 | |
|
378 |
self.__timeInterval = 1.0 * self.__samples_to_read/ |
|
|
396 | self.__timeInterval = 1.0 * self.__samples_to_read / \ | |
|
397 | self.__sample_rate # Time interval | |
|
379 | 398 | |
|
380 | 399 | if online: |
|
381 | 400 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) |
|
382 | 401 | startUTCSecond = numpy.floor(endUTCSecond) |
|
383 | 402 | |
|
384 |
|
|
|
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 | 410 | self.__setFileHeader() |
|
389 | 411 | self.isConfig = True |
|
390 | 412 | |
|
391 | 413 | print "[Reading] Digital RF Data was found from %s to %s " %( |
|
392 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
393 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
414 | datetime.datetime.utcfromtimestamp( | |
|
415 | self.__startUTCSecond - self.__timezone), | |
|
416 | datetime.datetime.utcfromtimestamp( | |
|
417 | self.__endUTCSecond - self.__timezone) | |
|
394 | 418 | ) |
|
395 | 419 | |
|
396 | 420 | print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), |
|
397 |
datetime.datetime.utcfromtimestamp( |
|
|
421 | datetime.datetime.utcfromtimestamp( | |
|
422 | endUTCSecond - self.__timezone) | |
|
398 | 423 | ) |
|
399 | 424 | self.oldAverage = None |
|
400 | 425 | self.count = 0 |
|
401 | 426 | self.executionTime = 0 |
|
427 | ||
|
402 | 428 | def __reload(self): |
|
403 | 429 | |
|
404 | 430 | # print "%s not in range [%s, %s]" %( |
@@ -413,7 +439,8 class DigitalRFReader(ProcessingUnit): | |||
|
413 | 439 | except: |
|
414 | 440 | self.digitalReadObj.reload() |
|
415 | 441 | |
|
416 |
start_index, end_index = self.digitalReadObj.get_bounds( |
|
|
442 | start_index, end_index = self.digitalReadObj.get_bounds( | |
|
443 | self.__channelNameList[self.__channelList[0]]) | |
|
417 | 444 | |
|
418 | 445 | if start_index > self.__startUTCSecond*self.__sample_rate: |
|
419 | 446 | self.__startUTCSecond = 1.0*start_index/self.__sample_rate |
@@ -422,8 +449,10 class DigitalRFReader(ProcessingUnit): | |||
|
422 | 449 | self.__endUTCSecond = 1.0*end_index/self.__sample_rate |
|
423 | 450 | |
|
424 | 451 | print "[Reading] New timerange found [%s, %s] " %( |
|
425 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
426 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
452 | datetime.datetime.utcfromtimestamp( | |
|
453 | self.__startUTCSecond - self.__timezone), | |
|
454 | datetime.datetime.utcfromtimestamp( | |
|
455 | self.__endUTCSecond - self.__timezone) | |
|
427 | 456 | ) |
|
428 | 457 | |
|
429 | 458 | return True |
@@ -434,8 +463,10 class DigitalRFReader(ProcessingUnit): | |||
|
434 | 463 | t0 = time() |
|
435 | 464 | toExecute() |
|
436 | 465 | self.executionTime = time() - t0 |
|
437 |
if self.oldAverage is None: |
|
|
438 |
self.oldAverage = |
|
|
466 | if self.oldAverage is None: | |
|
467 | self.oldAverage = self.executionTime | |
|
468 | self.oldAverage = (self.executionTime + self.count * | |
|
469 | self.oldAverage) / (self.count + 1.0) | |
|
439 | 470 | self.count = self.count + 1.0 |
|
440 | 471 | return |
|
441 | 472 | |
@@ -461,7 +492,7 class DigitalRFReader(ProcessingUnit): | |||
|
461 | 492 | indexChannel = 0 |
|
462 | 493 | |
|
463 | 494 | dataOk = False |
|
464 |
for thisChannelName in self.__channelNameList: |
|
|
495 | for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS? | |
|
465 | 496 | for indexSubchannel in range(self.__num_subchannels): |
|
466 | 497 | try: |
|
467 | 498 | t0 = time() |
@@ -469,8 +500,10 class DigitalRFReader(ProcessingUnit): | |||
|
469 | 500 | self.__samples_to_read, |
|
470 | 501 | thisChannelName, sub_channel=indexSubchannel) |
|
471 | 502 | self.executionTime = time() - t0 |
|
472 |
if self.oldAverage is None: |
|
|
473 |
self.oldAverage = |
|
|
503 | if self.oldAverage is None: | |
|
504 | self.oldAverage = self.executionTime | |
|
505 | self.oldAverage = ( | |
|
506 | self.executionTime + self.count * self.oldAverage) / (self.count + 1.0) | |
|
474 | 507 | self.count = self.count + 1.0 |
|
475 | 508 | |
|
476 | 509 | except IOError, e: |
@@ -509,7 +542,6 class DigitalRFReader(ProcessingUnit): | |||
|
509 | 542 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40 |
|
510 | 543 | |
|
511 | 544 | def getData(self, seconds=30, nTries=5): |
|
512 | ||
|
513 | 545 | ''' |
|
514 | 546 | This method gets the data from files and put the data into the dataOut object |
|
515 | 547 | |
@@ -552,8 +584,10 class DigitalRFReader(ProcessingUnit): | |||
|
552 | 584 | print '[Reading] waiting %d seconds to read a new block' %seconds |
|
553 | 585 | sleep(seconds) |
|
554 | 586 | |
|
555 |
self.dataOut.data = self.__data_buffer[:, |
|
|
556 | self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate | |
|
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 | |
|
557 | 591 | self.dataOut.flagNoData = False |
|
558 | 592 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock |
|
559 | 593 | self.dataOut.profileIndex = self.profileIndex |
@@ -583,7 +617,6 class DigitalRFReader(ProcessingUnit): | |||
|
583 | 617 | return |
|
584 | 618 | # print self.profileIndex |
|
585 | 619 | |
|
586 | ||
|
587 | 620 | def run(self, **kwargs): |
|
588 | 621 | ''' |
|
589 | 622 | This method will be called many times so here you should put all your code |
@@ -596,6 +629,7 class DigitalRFReader(ProcessingUnit): | |||
|
596 | 629 | |
|
597 | 630 | return |
|
598 | 631 | |
|
632 | ||
|
599 | 633 | class DigitalRFWriter(Operation): |
|
600 | 634 | ''' |
|
601 | 635 | classdocs |
@@ -644,9 +678,11 class DigitalRFWriter(Operation): | |||
|
644 | 678 | self.__nProfiles = dataOut.nProfiles |
|
645 | 679 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile |
|
646 | 680 | |
|
647 |
self.arr_data = arr_data = numpy.ones((self.__nSamples, len( |
|
|
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 | 686 | sub_cadence_secs = file_cadence_millisecs / 500 |
|
651 | 687 | |
|
652 | 688 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() |
@@ -670,11 +706,10 class DigitalRFWriter(Operation): | |||
|
670 | 706 | metadata_dir = os.path.join(path, 'metadata') |
|
671 | 707 | os.system('mkdir %s' % (metadata_dir)) |
|
672 | 708 | |
|
673 |
self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, |
|
|
709 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 | |
|
674 | 710 | sample_rate_numerator, sample_rate_denominator, |
|
675 | 711 | metadataFile) |
|
676 | 712 | |
|
677 | ||
|
678 | 713 | self.isConfig = True |
|
679 | 714 | self.currentSample = 0 |
|
680 | 715 | self.oldAverage = 0 |
@@ -685,23 +720,26 class DigitalRFWriter(Operation): | |||
|
685 | 720 | print '[Writing] - Writing metadata' |
|
686 | 721 | start_idx = self.__sample_rate * self.dataOut.utctime |
|
687 | 722 | |
|
688 |
self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( |
|
|
689 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict() | |
|
690 |
self.metadata_dict[' |
|
|
723 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( | |
|
724 | ) | |
|
725 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict( | |
|
726 | ) | |
|
727 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict( | |
|
728 | ) | |
|
691 | 729 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) |
|
692 | 730 | return |
|
693 | 731 | |
|
694 | ||
|
695 | 732 | def timeit(self, toExecute): |
|
696 | 733 | t0 = time() |
|
697 | 734 | toExecute() |
|
698 | 735 | self.executionTime = time() - t0 |
|
699 |
if self.oldAverage is None: |
|
|
700 |
self.oldAverage = |
|
|
736 | if self.oldAverage is None: | |
|
737 | self.oldAverage = self.executionTime | |
|
738 | self.oldAverage = (self.executionTime + self.count * | |
|
739 | self.oldAverage) / (self.count + 1.0) | |
|
701 | 740 | self.count = self.count + 1.0 |
|
702 | 741 | return |
|
703 | 742 | |
|
704 | ||
|
705 | 743 | def writeData(self): |
|
706 | 744 | for i in range(self.dataOut.systemHeaderObj.nSamples): |
|
707 | 745 | for channel in self.dataOut.channelList: |
@@ -722,14 +760,15 class DigitalRFWriter(Operation): | |||
|
722 | 760 | # print dataOut.__dict__ |
|
723 | 761 | self.dataOut = dataOut |
|
724 | 762 | if not self.isConfig: |
|
725 |
self.setup(dataOut, path, frequency, fileCadence, |
|
|
763 | self.setup(dataOut, path, frequency, fileCadence, | |
|
764 | dirCadence, metadataCadence, **kwargs) | |
|
726 | 765 | self.writeMetadata() |
|
727 | 766 | |
|
728 | 767 | self.writeData() |
|
729 | 768 | |
|
730 | 769 | ## self.currentSample += 1 |
|
731 |
|
|
|
732 |
|
|
|
770 | # if self.dataOut.flagDataAsBlock or self.currentSample == 1: | |
|
771 | # self.writeMetadata() | |
|
733 | 772 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 |
|
734 | 773 | |
|
735 | 774 | def close(self): |
@@ -616,7 +616,6 class Decoder(Operation): | |||
|
616 | 616 | def __convolutionInTime(self, data): |
|
617 | 617 | |
|
618 | 618 | code = self.code[self.__profIndex] |
|
619 | ||
|
620 | 619 | for i in range(self.__nChannels): |
|
621 | 620 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='full')[self.nBaud-1:] |
|
622 | 621 | |
@@ -666,7 +665,6 class Decoder(Operation): | |||
|
666 | 665 | code = dataOut.code |
|
667 | 666 | else: |
|
668 | 667 | code = numpy.array(code).reshape(nCode,nBaud) |
|
669 | ||
|
670 | 668 | self.setup(code, osamp, dataOut) |
|
671 | 669 | |
|
672 | 670 | self.isConfig = True |
General Comments 0
You need to be logged in to leave comments.
Login now