@@ -1,25 +1,40 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on 23/01/2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | from JRODataIO import JRODataIO | |
|
8 | import os, sys | |
|
9 | import numpy | |
|
10 | import glob | |
|
11 | import fnmatch | |
|
12 | import time, datetime | |
|
9 | 13 | |
|
10 | class CorrelationReader(JRODataIO): | |
|
14 | path = os.path.split(os.getcwd())[0] | |
|
15 | sys.path.append(path) | |
|
16 | ||
|
17 | from Model.JROHeader import * | |
|
18 | from Model.Voltage import Voltage | |
|
19 | ||
|
20 | from IO.JRODataIO import JRODataReader | |
|
21 | from IO.JRODataIO import JRODataWriter | |
|
22 | ||
|
23 | ||
|
24 | class CorrelationReader(JRODataReader):#JRODataReader para lectura de correlaciones en archivos HDF5 | |
|
11 | 25 | |
|
12 | 26 | def __init__(self): |
|
13 | 27 | |
|
14 | 28 | pass |
|
15 | 29 | |
|
16 | class CorrelationWriter(JRODataIO): | |
|
30 | class CorrelationWriter(JRODataWriter):#JRODataWriter para escritura de correlaciones en archivos HDF5 | |
|
17 | 31 | |
|
18 | 32 | def __init__(self): |
|
33 | ||
|
19 | 34 | pass |
|
20 | 35 | |
|
21 |
def pu |
|
|
36 | def puData(self): | |
|
22 | 37 | pass |
|
23 | 38 | |
|
24 | 39 | def writeBlock(self): |
|
25 | 40 | pass No newline at end of file |
@@ -1,58 +1,60 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | from JROData import JROData, Noise |
|
8 | 8 | from JROHeader import RadarControllerHeader, ProcessingHeader, SystemHeader, BasicHeader |
|
9 | 9 | |
|
10 | 10 | class Correlation(JROData): |
|
11 | 11 | ''' |
|
12 | 12 | classdocs |
|
13 | 13 | ''' |
|
14 | 14 | |
|
15 | 15 | data = None |
|
16 | 16 | |
|
17 | 17 | nLags = None |
|
18 | 18 | |
|
19 | 19 | lagsList = None |
|
20 | 20 | |
|
21 | 21 | def __init__(self): |
|
22 | 22 | ''' |
|
23 | 23 | Constructor |
|
24 | 24 | ''' |
|
25 | 25 | |
|
26 | 26 | self.m_RadarControllerHeader = RadarControllerHeader() |
|
27 | 27 | |
|
28 | 28 | self.m_ProcessingHeader = ProcessingHeader() |
|
29 | 29 | |
|
30 | 30 | self.m_SystemHeader = SystemHeader() |
|
31 | 31 | |
|
32 | 32 | self.m_BasicHeader = BasicHeader() |
|
33 | 33 | |
|
34 | 34 | self.m_NoiseObj = Noise() |
|
35 | 35 | |
|
36 |
self.type = " |
|
|
36 | self.type = "Correlation" | |
|
37 | 37 | |
|
38 | 38 | self.dataType = None |
|
39 | 39 | |
|
40 | 40 | self.nHeights = 0 |
|
41 | 41 | |
|
42 | 42 | self.nChannels = 0 |
|
43 | 43 | |
|
44 | 44 | self.channelList = None |
|
45 | 45 | |
|
46 | 46 | self.heightList = None |
|
47 | 47 | |
|
48 | 48 | self.flagNoData = True |
|
49 | 49 | |
|
50 | 50 | self.flagResetProcessing = False |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | self.data = None |
|
54 | 54 | |
|
55 | 55 | self.nLags = 0 |
|
56 | 56 | |
|
57 |
self. |
|
|
57 | self.tauList = None | |
|
58 | ||
|
59 | self.pairList = None | |
|
58 | 60 | No newline at end of file |
@@ -1,22 +1,146 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | import os, sys | |
|
9 | import numpy | |
|
10 | ||
|
11 | path = os.path.split(os.getcwd())[0] | |
|
12 | sys.path.append(path) | |
|
13 | ||
|
14 | from Model.Correlation import Correlation | |
|
15 | from IO.CorrelationIO import CorrelationWriter | |
|
16 | #from Graphics.CorrelationPlot import Correlator | |
|
17 | ||
|
18 | ||
|
19 | from Model.Voltage import Voltage | |
|
20 | from Model.Spectra import Spectra | |
|
21 | ||
|
8 | 22 | class CorrelationProcessor: |
|
9 | 23 | ''' |
|
10 | 24 | classdocs |
|
11 | 25 | ''' |
|
12 | 26 | |
|
27 | integratorIndex = None | |
|
28 | writerIndex = None | |
|
29 | plotterIndex = None | |
|
13 | 30 | |
|
14 | def __init__(self): | |
|
31 | lagsList = None | |
|
32 | ||
|
33 | nLags = None | |
|
34 | tauList = None | |
|
35 | pairList = None | |
|
36 | indexTau = None | |
|
37 | ||
|
38 | ||
|
39 | def __init__(self,dataInObj, dataOutObj=None): | |
|
15 | 40 | ''' |
|
16 | 41 | Constructor |
|
17 | 42 | ''' |
|
43 | self.dataInObj = dataInObj | |
|
44 | ||
|
45 | if dataOutObj == None: | |
|
46 | self.dataOutObj = Correlation() | |
|
47 | else: | |
|
48 | self.dataOutObj = dataOutObj | |
|
49 | ||
|
50 | self.indexTau = 0 | |
|
51 | self.buffer = None | |
|
52 | ||
|
53 | def init(self,pairList=None,tauList=None): | |
|
54 | ||
|
55 | self.integratorIndex = 0 | |
|
56 | self.writerIndex = 0 | |
|
57 | self.plotterIndex = 0 | |
|
58 | ||
|
59 | self.pairList = pairList | |
|
60 | self.tauList = tauList | |
|
61 | ||
|
62 | if ( isinstance(self.dataInObj, Voltage) ): | |
|
63 | self.__getCorrelation() | |
|
64 | ||
|
65 | if ( isinstance(self.dataInObj, Spectra) ): | |
|
66 | sys.exit(0) | |
|
67 | ||
|
68 | if ( isinstance(self.dataInObj, Correlation) ): | |
|
69 | sel.__getCopy() | |
|
70 | ||
|
71 | def __getCorrelation(self): | |
|
72 | if self.dataInObj.flagNoData: | |
|
73 | return 0 | |
|
74 | ||
|
75 | if self.tauList == None: # se lee el tauList desde el archivo | |
|
76 | flip = None | |
|
77 | if self.dataInObj.m_RadarControllerHeader.flip1 != None: | |
|
78 | flip = self.dataInObj.m_RadarControllerHeader.flip1 | |
|
79 | ||
|
80 | if self.dataInObj.m_RadarControllerHeader.flip2 != None: | |
|
81 | flip = self.dataInObj.m_RadarControllerHeader.flip2 | |
|
82 | ||
|
83 | if flip == None: | |
|
84 | flip = 2 | |
|
85 | print 'flip is None --> flip = %d '%flip | |
|
86 | ||
|
87 | ntaus = self.dataInObj.m_RadarControllerHeader.numTaus | |
|
88 | taus = self.dataInObj.m_RadarControllerHeader.Taus.reshape(ntaus/flip,flip) | |
|
89 | ||
|
90 | index = 0 | |
|
91 | self.tauList = taus[:,index] | |
|
92 | print 'tauList is None --> tauList = obj.m_RadarControllerHeader.Taus[:,%d]'%index | |
|
93 | ||
|
94 | self.nLags = len(self.tauList) | |
|
95 | ||
|
96 | if self.pairList == None: | |
|
97 | self.pairList = [(0,0)] # por defecto calcula la AutoCorrelacion de una canal | |
|
98 | ||
|
99 | self.dataOutObj.tauList = self.tauList | |
|
100 | self.dataOutObj.nLags = self.nLags | |
|
101 | self.dataOutObj.pairList = self.pairList | |
|
102 | ||
|
103 | if self.buffer == None: | |
|
104 | nhei = self.dataInObj.nHeights | |
|
105 | npairList = len(self.pairList) | |
|
106 | self.buffer = numpy.zeros((self.nLags,nhei,npairList),dtype='complex') | |
|
107 | ||
|
108 | bufferZ = numpy.zeros((npairList,self.dataInObj.nHeights),dtype='complex') | |
|
109 | ||
|
110 | indexHeight = self.tauList[self.indexTau] / self.dataInObj.m_ProcessingHeader.deltaHeight | |
|
111 | ||
|
112 | countPair = 0 | |
|
113 | ||
|
114 | # make (signalA*signalB'), where signalA: channel without delay, signalB: channel with delay, | |
|
115 | for pair in self.pairList: | |
|
116 | bufferZ[countPair,0:self.dataInObj.nHeights-indexHeight] = self.dataInObj.data[pair[1],indexHeight:self.dataInObj.nHeights] | |
|
117 | signalA = self.dataInObj.data[pair[0],:] | |
|
118 | signalB = bufferZ[countPair,:] | |
|
119 | data = signalA * numpy.conjugate(signalB) | |
|
120 | self.buffer[self.indexTau,:,countPair] = data | |
|
121 | countPair += 1 | |
|
122 | ||
|
123 | # change index Tau and lagCounter | |
|
124 | self.indexTau += 1 | |
|
125 | if self.indexTau >= self.nLags: | |
|
126 | self.indexTau = 0 | |
|
127 | self.dataOutObj.data = self.buffer | |
|
128 | self.buffer = None | |
|
129 | self.dataOutObj.flagNoData = False | |
|
130 | else: | |
|
131 | self.dataOutObj.flagNoData = True | |
|
132 | ||
|
133 | ||
|
134 | def addIntegrator(self): | |
|
135 | pass | |
|
136 | ||
|
137 | def addWriter(self): | |
|
138 | pass | |
|
139 | ||
|
140 | def addPlotter(self): | |
|
18 | 141 | pass |
|
19 | m_Correlation= Correlation() | |
|
20 | 142 | |
|
21 | m_Voltage= Voltage() | |
|
143 | class Integrator(): | |
|
144 | def __init__(self): | |
|
145 | pass | |
|
22 | 146 |
@@ -1,503 +1,548 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Feb 7, 2012 |
|
3 | 3 | |
|
4 | 4 | @author $Author$ |
|
5 | 5 | @version $Id$ |
|
6 | 6 | ''' |
|
7 | 7 | |
|
8 | 8 | import os, sys |
|
9 | 9 | import numpy |
|
10 | 10 | |
|
11 | 11 | path = os.path.split(os.getcwd())[0] |
|
12 | 12 | sys.path.append(path) |
|
13 | 13 | |
|
14 | 14 | from Model.Voltage import Voltage |
|
15 | 15 | from IO.VoltageIO import VoltageWriter |
|
16 | 16 | from Graphics.VoltagePlot import Osciloscope |
|
17 | 17 | |
|
18 | 18 | class VoltageProcessor: |
|
19 | 19 | ''' |
|
20 | 20 | classdocs |
|
21 | 21 | ''' |
|
22 | 22 | |
|
23 | 23 | dataInObj = None |
|
24 | 24 | dataOutObj = None |
|
25 | 25 | |
|
26 | 26 | integratorObjIndex = None |
|
27 | 27 | decoderObjIndex = None |
|
28 | 28 | profSelectorObjIndex = None |
|
29 | 29 | writerObjIndex = None |
|
30 | 30 | plotterObjIndex = None |
|
31 | flipIndex = None | |
|
31 | 32 | |
|
32 | 33 | integratorObjList = [] |
|
33 | 34 | decoderObjList = [] |
|
34 | 35 | profileSelectorObjList = [] |
|
35 | 36 | writerObjList = [] |
|
36 | 37 | plotterObjList = [] |
|
37 | 38 | m_Voltage= Voltage() |
|
38 | 39 | |
|
39 | 40 | m_ProfileSelector= ProfileSelector() |
|
40 | 41 | |
|
41 | 42 | m_Decoder= Decoder() |
|
42 | 43 | |
|
43 | 44 | m_CoherentIntegrator= CoherentIntegrator() |
|
44 | 45 | |
|
45 | 46 | |
|
46 | 47 | def __init__(self, dataInObj, dataOutObj=None): |
|
47 | 48 | ''' |
|
48 | 49 | Constructor |
|
49 | 50 | ''' |
|
50 | 51 | |
|
51 | 52 | self.dataInObj = dataInObj |
|
52 | 53 | |
|
53 | 54 | if dataOutObj == None: |
|
54 | 55 | self.dataOutObj = Voltage() |
|
55 | 56 | else: |
|
56 | 57 | self.dataOutObj = dataOutObj |
|
57 | 58 | |
|
58 | 59 | self.integratorObjIndex = None |
|
59 | 60 | self.decoderObjIndex = None |
|
60 | 61 | self.profSelectorObjIndex = None |
|
61 | 62 | self.writerObjIndex = None |
|
62 | 63 | self.plotterObjIndex = None |
|
63 | ||
|
64 | self.flipIndex = 1 | |
|
64 | 65 | self.integratorObjList = [] |
|
65 | 66 | self.decoderObjList = [] |
|
66 | 67 | self.profileSelectorObjList = [] |
|
67 | 68 | self.writerObjList = [] |
|
68 | 69 | self.plotterObjList = [] |
|
69 | 70 | |
|
70 | 71 | def init(self): |
|
71 | 72 | |
|
72 | 73 | self.integratorObjIndex = 0 |
|
73 | 74 | self.decoderObjIndex = 0 |
|
74 | 75 | self.profSelectorObjIndex = 0 |
|
75 | 76 | self.writerObjIndex = 0 |
|
76 | 77 | self.plotterObjIndex = 0 |
|
77 | 78 | self.dataOutObj.copy(self.dataInObj) |
|
78 | 79 |
|
|
80 | if self.profSelectorObjIndex != None: | |
|
81 | for profSelObj in self.profileSelectorObjList: | |
|
82 | profSelObj.incIndex() | |
|
83 | ||
|
79 | 84 | def addWriter(self, wrpath): |
|
80 | 85 | objWriter = VoltageWriter(self.dataOutObj) |
|
81 | 86 | objWriter.setup(wrpath) |
|
82 | 87 | self.writerObjList.append(objWriter) |
|
83 | 88 | |
|
84 | 89 | def addPlotter(self): |
|
85 | 90 | |
|
86 | 91 | plotObj = Osciloscope(self.dataOutObj,self.plotterObjIndex) |
|
87 | 92 | self.plotterObjList.append(plotObj) |
|
88 | 93 | |
|
89 | 94 | def addIntegrator(self, nCohInt): |
|
90 | 95 | |
|
91 | 96 | objCohInt = CoherentIntegrator(nCohInt) |
|
92 | 97 | self.integratorObjList.append(objCohInt) |
|
93 | 98 | |
|
94 | 99 | def addDecoder(self, code, ncode, nbaud): |
|
95 | 100 | |
|
96 | 101 | objDecoder = Decoder(code,ncode,nbaud) |
|
97 | 102 | self.decoderObjList.append(objDecoder) |
|
98 | 103 | |
|
99 | 104 | def addProfileSelector(self, nProfiles): |
|
100 | 105 | |
|
101 | 106 | objProfSelector = ProfileSelector(nProfiles) |
|
102 | 107 | self.profileSelectorObjList.append(objProfSelector) |
|
103 | 108 | |
|
104 | 109 | def writeData(self,wrpath): |
|
105 | 110 | |
|
106 | 111 | if self.dataOutObj.flagNoData: |
|
107 | 112 | return 0 |
|
108 | 113 | |
|
109 | 114 | if len(self.writerObjList) <= self.writerObjIndex: |
|
110 | 115 | self.addWriter(wrpath) |
|
111 | 116 | |
|
112 | 117 | self.writerObjList[self.writerObjIndex].putData() |
|
113 | 118 | |
|
114 | 119 | # myWrObj = self.writerObjList[self.writerObjIndex] |
|
115 | 120 | # myWrObj.putData() |
|
116 | 121 | |
|
117 | 122 | self.writerObjIndex += 1 |
|
118 | 123 | |
|
119 | 124 | def plotData(self,idProfile, type, xmin=None, xmax=None, ymin=None, ymax=None, winTitle=''): |
|
120 | 125 | if self.dataOutObj.flagNoData: |
|
121 | 126 | return 0 |
|
122 | 127 | |
|
123 | 128 | if len(self.plotterObjList) <= self.plotterObjIndex: |
|
124 | 129 | self.addPlotter() |
|
125 | 130 | |
|
126 | 131 | self.plotterObjList[self.plotterObjIndex].plotData(type=type, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,winTitle=winTitle) |
|
127 | 132 | |
|
128 | 133 | self.plotterObjIndex += 1 |
|
129 | 134 | |
|
130 | 135 | def integrator(self, N): |
|
131 | 136 | |
|
132 | 137 | if self.dataOutObj.flagNoData: |
|
133 | 138 | return 0 |
|
134 | 139 | |
|
135 | 140 | if len(self.integratorObjList) <= self.integratorObjIndex: |
|
136 | 141 | self.addIntegrator(N) |
|
137 | 142 | |
|
138 | 143 | myCohIntObj = self.integratorObjList[self.integratorObjIndex] |
|
139 | 144 | myCohIntObj.exe(self.dataOutObj.data) |
|
140 | 145 | |
|
141 | 146 | if myCohIntObj.flag: |
|
142 | 147 | self.dataOutObj.data = myCohIntObj.data |
|
143 | 148 | self.dataOutObj.m_ProcessingHeader.coherentInt *= N |
|
144 | 149 | self.dataOutObj.flagNoData = False |
|
145 | 150 | |
|
146 | 151 | else: |
|
147 | 152 | self.dataOutObj.flagNoData = True |
|
148 | 153 | |
|
149 | 154 | self.integratorObjIndex += 1 |
|
150 | 155 | |
|
151 | 156 | def decoder(self,code=None,type = 0): |
|
152 | 157 | |
|
153 | 158 | if self.dataOutObj.flagNoData: |
|
154 | 159 | return 0 |
|
155 | 160 | |
|
156 | 161 | if code == None: |
|
157 | 162 | code = self.dataOutObj.m_RadarControllerHeader.code |
|
158 | 163 | ncode, nbaud = code.shape |
|
159 | 164 | |
|
160 | 165 | if len(self.decoderObjList) <= self.decoderObjIndex: |
|
161 | 166 | self.addDecoder(code,ncode,nbaud) |
|
162 | 167 | |
|
163 | 168 | myDecodObj = self.decoderObjList[self.decoderObjIndex] |
|
164 | 169 | myDecodObj.exe(data=self.dataOutObj.data,type=type) |
|
165 | 170 | |
|
166 | 171 | if myDecodObj.flag: |
|
167 | 172 | self.dataOutObj.data = myDecodObj.data |
|
168 | 173 | self.dataOutObj.flagNoData = False |
|
169 | 174 | else: |
|
170 | 175 | self.dataOutObj.flagNoData = True |
|
171 | 176 | |
|
172 | 177 | self.decoderObjIndex += 1 |
|
173 | 178 | |
|
174 | 179 | |
|
175 | 180 | def filterByHei(self, window): |
|
176 | pass | |
|
181 | if window == None: | |
|
182 | window = self.dataOutObj.m_RadarControllerHeader.txA / self.dataOutObj.m_ProcessingHeader.deltaHeight[0] | |
|
183 | ||
|
184 | newdelta = self.dataOutObj.m_ProcessingHeader.deltaHeight[0] * window | |
|
185 | dim1 = self.dataOutObj.data.shape[0] | |
|
186 | dim2 = self.dataOutObj.data.shape[1] | |
|
187 | r = dim2 % window | |
|
188 | ||
|
189 | buffer = self.dataOutObj.data[:,0:dim2-r] | |
|
190 | buffer = buffer.reshape(dim1,dim2/window,window) | |
|
191 | buffer = numpy.sum(buffer,2) | |
|
192 | self.dataOutObj.data = buffer | |
|
177 | 193 | |
|
194 | self.dataOutObj.m_ProcessingHeader.deltaHeight = newdelta | |
|
195 | self.dataOutObj.m_ProcessingHeader.numHeights = buffer.shape[1] | |
|
196 | ||
|
197 | self.dataOutObj.nHeights = self.dataOutObj.m_ProcessingHeader.numHeights | |
|
198 | ||
|
199 | #self.dataOutObj.heightList es un numpy.array | |
|
200 | self.dataOutObj.heightList = numpy.arange(self.dataOutObj.m_ProcessingHeader.firstHeight[0],newdelta*self.dataOutObj.nHeights,newdelta) | |
|
201 | ||
|
202 | def deFlip(self): | |
|
203 | self.dataOutObj.data *= self.flipIndex | |
|
204 | self.flipIndex *= -1. | |
|
178 | 205 | |
|
179 | 206 | def selectChannels(self, channelList): |
|
180 | 207 | """ |
|
181 | 208 | Selecciona un bloque de datos en base a canales y pares segun el channelList y el pairList |
|
182 | 209 | |
|
183 | 210 | Input: |
|
184 | 211 | channelList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
185 | 212 | |
|
186 | 213 | Affected: |
|
187 | 214 | self.dataOutObj.data |
|
188 | 215 | self.dataOutObj.channelList |
|
189 | 216 | self.dataOutObj.nChannels |
|
190 | 217 | self.dataOutObj.m_ProcessingHeader.totalSpectra |
|
191 | 218 | self.dataOutObj.m_SystemHeader.numChannels |
|
192 | 219 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
193 | 220 | |
|
194 | 221 | Return: |
|
195 | 222 | None |
|
196 | 223 | """ |
|
197 | 224 | if self.dataOutObj.flagNoData: |
|
198 | 225 | return 0 |
|
199 | 226 | |
|
200 | 227 | for channel in channelList: |
|
201 | 228 | if channel not in self.dataOutObj.channelList: |
|
202 | 229 | raise ValueError, "The value %d in channelList is not valid" %channel |
|
203 | 230 | |
|
204 | 231 | nchannels = len(channelList) |
|
205 | 232 | profiles = self.dataOutObj.nProfiles |
|
206 | 233 | heights = self.dataOutObj.nHeights #m_ProcessingHeader.numHeights |
|
207 | 234 | |
|
208 | 235 | data = numpy.zeros( (nchannels,heights), dtype='complex' ) |
|
209 | 236 | for index,channel in enumerate(channelList): |
|
210 | 237 | data[index,:] = self.dataOutObj.data[channel,:] |
|
211 | 238 | |
|
212 | 239 | self.dataOutObj.data = data |
|
213 | 240 | self.dataOutObj.channelList = channelList |
|
214 | 241 | self.dataOutObj.nChannels = nchannels |
|
215 | 242 | self.dataOutObj.m_ProcessingHeader.totalSpectra = nchannels |
|
216 | 243 | self.dataOutObj.m_SystemHeader.numChannels = nchannels |
|
217 | 244 | self.dataOutObj.m_ProcessingHeader.blockSize = data.size |
|
218 | 245 | return 1 |
|
219 | 246 | |
|
220 | 247 | |
|
221 | 248 | def selectHeightsByValue(self, minHei, maxHei): |
|
222 | 249 | """ |
|
223 | 250 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
224 | 251 | minHei <= height <= maxHei |
|
225 | 252 | |
|
226 | 253 | Input: |
|
227 | 254 | minHei : valor minimo de altura a considerar |
|
228 | 255 | maxHei : valor maximo de altura a considerar |
|
229 | 256 | |
|
230 | 257 | Affected: |
|
231 | 258 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
232 | 259 | |
|
233 | 260 | Return: |
|
234 | 261 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
235 | 262 | """ |
|
236 | 263 | if self.dataOutObj.flagNoData: |
|
237 | 264 | return 0 |
|
238 | 265 | |
|
239 | 266 | if (minHei < self.dataOutObj.heightList[0]) or (minHei > maxHei): |
|
240 | 267 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
241 | 268 | |
|
242 | 269 | if (maxHei > self.dataOutObj.heightList[-1]): |
|
243 | 270 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
244 | 271 | |
|
245 | 272 | minIndex = 0 |
|
246 | 273 | maxIndex = 0 |
|
247 | 274 | data = self.dataOutObj.heightList |
|
248 | 275 | |
|
249 | 276 | for i,val in enumerate(data): |
|
250 | 277 | if val < minHei: |
|
251 | 278 | continue |
|
252 | 279 | else: |
|
253 | 280 | minIndex = i; |
|
254 | 281 | break |
|
255 | 282 | |
|
256 | 283 | for i,val in enumerate(data): |
|
257 | 284 | if val <= maxHei: |
|
258 | 285 | maxIndex = i; |
|
259 | 286 | else: |
|
260 | 287 | break |
|
261 | 288 | |
|
262 | 289 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
263 | 290 | return 1 |
|
264 | 291 | |
|
265 | 292 | |
|
266 | 293 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
267 | 294 | """ |
|
268 | 295 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
269 | 296 | minIndex <= index <= maxIndex |
|
270 | 297 | |
|
271 | 298 | Input: |
|
272 | 299 | minIndex : valor de indice minimo de altura a considerar |
|
273 | 300 | maxIndex : valor de indice maximo de altura a considerar |
|
274 | 301 | |
|
275 | 302 | Affected: |
|
276 | 303 | self.dataOutObj.data |
|
277 | 304 | self.dataOutObj.heightList |
|
278 | 305 | self.dataOutObj.nHeights |
|
279 | 306 | self.dataOutObj.m_ProcessingHeader.blockSize |
|
280 | 307 | self.dataOutObj.m_ProcessingHeader.numHeights |
|
281 | 308 | self.dataOutObj.m_ProcessingHeader.firstHeight |
|
282 | 309 | self.dataOutObj.m_RadarControllerHeader |
|
283 | 310 | |
|
284 | 311 | Return: |
|
285 | 312 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
286 | 313 | """ |
|
287 | 314 | if self.dataOutObj.flagNoData: |
|
288 | 315 | return 0 |
|
289 | 316 | |
|
290 | 317 | if (minIndex < 0) or (minIndex > maxIndex): |
|
291 | 318 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
292 | 319 | |
|
293 | 320 | if (maxIndex >= self.dataOutObj.nHeights): |
|
294 | 321 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
295 | 322 | |
|
296 | 323 | nHeights = maxIndex - minIndex + 1 |
|
297 | 324 | firstHeight = 0 |
|
298 | 325 | |
|
299 | 326 | #voltage |
|
300 | 327 | data = self.dataOutObj.data[:,minIndex:maxIndex+1] |
|
301 | 328 | |
|
302 | 329 | firstHeight = self.dataOutObj.heightList[minIndex] |
|
303 | 330 | |
|
304 | 331 | self.dataOutObj.data = data |
|
305 | 332 | self.dataOutObj.heightList = self.dataOutObj.heightList[minIndex:maxIndex+1] |
|
306 | 333 | self.dataOutObj.nHeights = nHeights |
|
307 | 334 | self.dataOutObj.m_ProcessingHeader.blockSize = data.size |
|
308 | 335 | self.dataOutObj.m_ProcessingHeader.numHeights = nHeights |
|
309 | 336 | self.dataOutObj.m_ProcessingHeader.firstHeight = firstHeight |
|
310 | 337 | self.dataOutObj.m_RadarControllerHeader.numHeights = nHeights |
|
311 | 338 | return 1 |
|
312 | 339 | |
|
340 | def selectProfilesByValue(self,indexList, nProfiles): | |
|
341 | if self.dataOutObj.flagNoData: | |
|
342 | return 0 | |
|
343 | ||
|
344 | if self.profSelectorObjIndex >= len(self.profileSelectorObjList): | |
|
345 | self.addProfileSelector(nProfiles) | |
|
346 | ||
|
347 | profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex] | |
|
348 | ||
|
349 | if not(profileSelectorObj.isProfileInList(indexList)): | |
|
350 | self.dataOutObj.flagNoData = True | |
|
351 | self.profSelectorObjIndex += 1 | |
|
352 | return 0 | |
|
313 | 353 | |
|
314 | def selectProfiles(self, minIndex, maxIndex, nProfiles): | |
|
354 | self.dataOutObj.flagNoData = False | |
|
355 | self.profSelectorObjIndex += 1 | |
|
356 | ||
|
357 | return 1 | |
|
358 | ||
|
359 | ||
|
360 | def selectProfilesByIndex(self, minIndex, maxIndex, nProfiles): | |
|
315 | 361 | """ |
|
316 | 362 | Selecciona un bloque de datos en base a un grupo indices de perfiles segun el rango |
|
317 | 363 | minIndex <= index <= maxIndex |
|
318 | 364 | |
|
319 | 365 | Input: |
|
320 | 366 | minIndex : valor de indice minimo de perfil a considerar |
|
321 | 367 | maxIndex : valor de indice maximo de perfil a considerar |
|
322 | 368 | nProfiles : numero de profiles |
|
323 | 369 | |
|
324 | 370 | Affected: |
|
325 | 371 | self.dataOutObj.flagNoData |
|
326 | 372 | self.profSelectorObjIndex |
|
327 | 373 | |
|
328 | 374 | Return: |
|
329 | 375 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
330 | 376 | """ |
|
331 | 377 | |
|
332 | 378 | if self.dataOutObj.flagNoData: |
|
333 | 379 | return 0 |
|
334 | 380 | |
|
335 | 381 | if self.profSelectorObjIndex >= len(self.profileSelectorObjList): |
|
336 | 382 | self.addProfileSelector(nProfiles) |
|
337 | 383 | |
|
338 | 384 | profileSelectorObj = self.profileSelectorObjList[self.profSelectorObjIndex] |
|
339 | 385 | |
|
340 | if profileSelectorObj.isProfileInRange(minIndex, maxIndex): | |
|
341 |
self.dataOutObj.flagNoData = |
|
|
386 | if not(profileSelectorObj.isProfileInRange(minIndex, maxIndex)): | |
|
387 | self.dataOutObj.flagNoData = True | |
|
342 | 388 | self.profSelectorObjIndex += 1 |
|
343 |
return |
|
|
389 | return 0 | |
|
344 | 390 | |
|
345 |
self.dataOutObj.flagNoData = |
|
|
391 | self.dataOutObj.flagNoData = False | |
|
346 | 392 | self.profSelectorObjIndex += 1 |
|
347 | 393 | |
|
348 |
return |
|
|
394 | return 1 | |
|
349 | 395 | |
|
350 | 396 | def selectNtxs(self, ntx): |
|
351 | 397 | pass |
|
352 | 398 | |
|
353 | 399 | |
|
354 | 400 | class Decoder: |
|
355 | 401 | |
|
356 | 402 | data = None |
|
357 | 403 | profCounter = 1 |
|
358 | 404 | nCode = ncode |
|
359 | 405 | nBaud = nbaud |
|
360 | 406 | codeIndex = 0 |
|
361 | 407 | code = code #this is a List |
|
362 | 408 | fft_code = None |
|
363 | 409 | flag = False |
|
364 | 410 | setCodeFft = False |
|
365 | 411 | |
|
366 | 412 | def __init__(self,code, ncode, nbaud): |
|
367 | 413 | |
|
368 | 414 | self.data = None |
|
369 | 415 | self.profCounter = 1 |
|
370 | 416 | self.nCode = ncode |
|
371 | 417 | self.nBaud = nbaud |
|
372 | 418 | self.codeIndex = 0 |
|
373 | 419 | self.code = code #this is a List |
|
374 | 420 | self.fft_code = None |
|
375 | 421 | self.flag = False |
|
376 | 422 | self.setCodeFft = False |
|
377 | 423 | |
|
378 | 424 | def exe(self, data, ndata=None, type = 0): |
|
379 | 425 | |
|
380 | 426 | if ndata == None: ndata = data.shape[1] |
|
381 | 427 | |
|
382 | 428 | if type == 0: |
|
383 | 429 | self.convolutionInFreq(data,ndata) |
|
384 | 430 | |
|
385 | 431 | if type == 1: |
|
386 | 432 | self.convolutionInTime(data, ndata) |
|
387 | 433 | |
|
388 | 434 | def convolutionInFreq(self,data, ndata): |
|
389 | 435 | |
|
390 | 436 | newcode = numpy.zeros(ndata) |
|
391 | 437 | newcode[0:self.nBaud] = self.code[self.codeIndex] |
|
392 | 438 | |
|
393 | 439 | self.codeIndex += 1 |
|
394 | 440 | |
|
395 | 441 | fft_data = numpy.fft.fft(data, axis=1) |
|
396 | 442 | fft_code = numpy.conj(numpy.fft.fft(newcode)) |
|
397 | 443 | fft_code = fft_code.reshape(1,len(fft_code)) |
|
398 | 444 | |
|
399 | 445 | conv = fft_data.copy() |
|
400 | 446 | conv.fill(0) |
|
401 | 447 | |
|
402 | 448 | conv = fft_data*fft_code # This other way to calculate multiplication between bidimensional arrays |
|
403 | 449 | # for i in range(ndata): |
|
404 | 450 | # conv[i,:] = fft_data[i,:]*fft_code[i] |
|
405 | 451 | |
|
406 | 452 | self.data = numpy.fft.ifft(conv,axis=1) |
|
407 | 453 | self.flag = True |
|
408 | 454 | |
|
409 | 455 | if self.profCounter == self.nCode: |
|
410 | 456 | self.profCounter = 0 |
|
411 | 457 | self.codeIndex = 0 |
|
412 | 458 | |
|
413 | 459 | self.profCounter += 1 |
|
414 | 460 | |
|
415 | 461 | def convolutionInTime(self, data, ndata): |
|
416 | 462 | |
|
417 | 463 | nchannel = data.shape[1] |
|
418 | 464 | newcode = self.code[self.codeIndex] |
|
419 | 465 | self.codeIndex += 1 |
|
420 | 466 | conv = data.copy() |
|
421 | 467 | for i in range(nchannel): |
|
422 | 468 | conv[i,:] = numpy.correlate(data[i,:], newcode, 'same') |
|
423 | 469 | |
|
424 | 470 | self.data = conv |
|
425 | 471 | self.flag = True |
|
426 | 472 | |
|
427 | 473 | if self.profCounter == self.nCode: |
|
428 | 474 | self.profCounter = 0 |
|
429 | 475 | self.codeIndex = 0 |
|
430 | 476 | |
|
431 | 477 | self.profCounter += 1 |
|
432 | 478 | |
|
433 | 479 | |
|
434 | 480 | class CoherentIntegrator: |
|
435 | 481 | |
|
436 | 482 | profCounter = 1 |
|
437 | 483 | data = None |
|
438 | 484 | buffer = None |
|
439 | 485 | flag = False |
|
440 | 486 | nCohInt = N |
|
441 | 487 | |
|
442 | 488 | def __init__(self, N): |
|
443 | 489 | |
|
444 | 490 | self.profCounter = 1 |
|
445 | 491 | self.data = None |
|
446 | 492 | self.buffer = None |
|
447 | 493 | self.flag = False |
|
448 | 494 | self.nCohInt = N |
|
449 | 495 | |
|
450 | 496 | def exe(self, data): |
|
451 | 497 | |
|
452 | 498 | if self.buffer == None: |
|
453 | 499 | self.buffer = data |
|
454 | 500 | else: |
|
455 | 501 | self.buffer = self.buffer + data |
|
456 | 502 | |
|
457 | 503 | if self.profCounter == self.nCohInt: |
|
458 | 504 | self.data = self.buffer |
|
459 | 505 | self.buffer = None |
|
460 | 506 | self.profCounter = 0 |
|
461 | 507 | self.flag = True |
|
462 | 508 | else: |
|
463 | 509 | self.flag = False |
|
464 | 510 | |
|
465 | 511 | self.profCounter += 1 |
|
466 | 512 | |
|
467 | 513 | class ProfileSelector: |
|
468 | 514 | |
|
469 |
|
|
|
515 | profileIndex = None | |
|
470 | 516 | # Tamanho total de los perfiles |
|
471 | 517 | nProfiles = None |
|
472 | 518 | |
|
473 | 519 | def __init__(self, nProfiles): |
|
474 | 520 | |
|
475 |
self. |
|
|
521 | self.profileIndex = 0 | |
|
476 | 522 | self.nProfiles = nProfiles |
|
477 | 523 | |
|
524 | def incIndex(self): | |
|
525 | self.profileIndex += 1 | |
|
526 | ||
|
527 | if self.profileIndex >= self.nProfiles: | |
|
528 | self.profileIndex = 0 | |
|
529 | ||
|
478 | 530 | def isProfileInRange(self, minIndex, maxIndex): |
|
479 | 531 | |
|
480 |
if self. |
|
|
481 | self.indexProfile += 1 | |
|
532 | if self.profileIndex < minIndex: | |
|
482 | 533 | return False |
|
483 | 534 | |
|
484 |
if self. |
|
|
485 | self.indexProfile += 1 | |
|
535 | if self.profileIndex > maxIndex: | |
|
486 | 536 | return False |
|
487 | 537 | |
|
488 | self.indexProfile += 1 | |
|
489 | ||
|
490 | 538 | return True |
|
491 | 539 | |
|
492 | 540 | def isProfileInList(self, profileList): |
|
493 | 541 | |
|
494 |
if self. |
|
|
495 | self.indexProfile += 1 | |
|
542 | if self.profileIndex not in profileList: | |
|
496 | 543 | return False |
|
497 | 544 | |
|
498 | self.indexProfile += 1 | |
|
499 | ||
|
500 | 545 | return True |
|
501 | 546 | |
|
502 | 547 | |
|
503 | 548 | No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now