@@ -1,61 +1,65 | |||||
1 | import numpy |
|
1 | import numpy | |
2 |
|
2 | |||
3 | class AMISR: |
|
3 | class AMISR: | |
4 | def __init__(self): |
|
4 | def __init__(self): | |
5 | self.flagNoData = True |
|
5 | self.flagNoData = True | |
6 | self.data = None |
|
6 | self.data = None | |
7 | self.utctime = None |
|
7 | self.utctime = None | |
8 | self.type = "AMISR" |
|
8 | self.type = "AMISR" | |
9 |
|
9 | |||
10 | #propiedades para compatibilidad con Voltages |
|
10 | #propiedades para compatibilidad con Voltages | |
11 | self.timeZone = 0#timezone like jroheader, difference in minutes between UTC and localtime |
|
11 | self.timeZone = 0#timezone like jroheader, difference in minutes between UTC and localtime | |
12 | self.dstFlag = 0#self.dataIn.dstFlag |
|
12 | self.dstFlag = 0#self.dataIn.dstFlag | |
13 | self.errorCount = 0#self.dataIn.errorCount |
|
13 | self.errorCount = 0#self.dataIn.errorCount | |
14 | self.useLocalTime = True#self.dataIn.useLocalTime |
|
14 | self.useLocalTime = True#self.dataIn.useLocalTime | |
15 |
|
15 | |||
16 | self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy() |
|
16 | self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy() | |
17 | self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy() |
|
17 | self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy() | |
18 | self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR |
|
18 | self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR | |
19 | self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
19 | self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
20 |
|
20 | |||
21 | self.flagTimeBlock = None#self.dataIn.flagTimeBlock |
|
21 | self.flagTimeBlock = None#self.dataIn.flagTimeBlock | |
22 | #self.utctime = #self.firstdatatime |
|
22 | #self.utctime = #self.firstdatatime | |
23 | self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
23 | self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
24 | self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
24 | self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
25 |
|
25 | |||
26 | self.nCohInt = 1#self.dataIn.nCohInt |
|
26 | self.nCohInt = 1#self.dataIn.nCohInt | |
27 | self.nIncohInt = 1 |
|
27 | self.nIncohInt = 1 | |
28 | self.ippSeconds = None#self.dataIn.ippSeconds, segun el filename/Setup/Tufile |
|
28 | self.ippSeconds = None#self.dataIn.ippSeconds, segun el filename/Setup/Tufile | |
29 | self.windowOfFilter = None#self.dataIn.windowOfFilter |
|
29 | self.windowOfFilter = None#self.dataIn.windowOfFilter | |
30 |
|
30 | |||
31 | self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
31 | self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
32 | self.frequency = None#self.dataIn.frequency |
|
32 | self.frequency = None#self.dataIn.frequency | |
33 | self.realtime = 0#self.dataIn.realtime |
|
33 | self.realtime = 0#self.dataIn.realtime | |
34 |
|
34 | |||
35 | #actualizar en la lectura de datos |
|
35 | #actualizar en la lectura de datos | |
36 | self.heightList = None#self.dataIn.heightList |
|
36 | self.heightList = None#self.dataIn.heightList | |
37 | self.nProfiles = None#Number of samples or nFFTPoints |
|
37 | self.nProfiles = None#Number of samples or nFFTPoints | |
38 | self.nRecords = None |
|
38 | self.nRecords = None | |
39 | self.nBeams = None |
|
39 | self.nBeams = None | |
40 | self.nBaud = None#self.dataIn.nBaud |
|
40 | self.nBaud = None#self.dataIn.nBaud | |
41 | self.nCode = None#self.dataIn.nCode |
|
41 | self.nCode = None#self.dataIn.nCode | |
42 | self.code = None#self.dataIn.code |
|
42 | self.code = None#self.dataIn.code | |
43 |
|
43 | |||
44 | #consideracion para los Beams |
|
44 | #consideracion para los Beams | |
45 | self.beamCodeDict = None |
|
45 | self.beamCodeDict = None | |
46 | self.beamRangeDict = None |
|
46 | self.beamRangeDict = None | |
47 |
|
47 | self.beamcode = None | ||
|
48 | self.azimuth = None | |||
|
49 | self.zenith = None | |||
|
50 | self.gain = None | |||
|
51 | ||||
48 | self.npulseByFrame = None |
|
52 | self.npulseByFrame = None | |
49 |
|
53 | |||
50 | def copy(self, inputObj=None): |
|
54 | def copy(self, inputObj=None): | |
51 |
|
55 | |||
52 | if inputObj == None: |
|
56 | if inputObj == None: | |
53 | return copy.deepcopy(self) |
|
57 | return copy.deepcopy(self) | |
54 |
|
58 | |||
55 | for key in inputObj.__dict__.keys(): |
|
59 | for key in inputObj.__dict__.keys(): | |
56 | self.__dict__[key] = inputObj.__dict__[key] |
|
60 | self.__dict__[key] = inputObj.__dict__[key] | |
57 |
|
61 | |||
58 |
|
62 | |||
59 | def isEmpty(self): |
|
63 | def isEmpty(self): | |
60 |
|
64 | |||
61 | return self.flagNoData No newline at end of file |
|
65 | return self.flagNoData |
@@ -1,736 +1,740 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ |
|
4 | $Id: JROData.py 173 2012-11-20 15:06:21Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import copy |
|
7 | import copy | |
8 | import numpy |
|
8 | import numpy | |
9 | import datetime |
|
9 | import datetime | |
10 |
|
10 | |||
11 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
11 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
12 |
|
12 | |||
13 | def getNumpyDtype(dataTypeCode): |
|
13 | def getNumpyDtype(dataTypeCode): | |
14 |
|
14 | |||
15 | if dataTypeCode == 0: |
|
15 | if dataTypeCode == 0: | |
16 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
16 | numpyDtype = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
17 | elif dataTypeCode == 1: |
|
17 | elif dataTypeCode == 1: | |
18 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
18 | numpyDtype = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
19 | elif dataTypeCode == 2: |
|
19 | elif dataTypeCode == 2: | |
20 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
20 | numpyDtype = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
21 | elif dataTypeCode == 3: |
|
21 | elif dataTypeCode == 3: | |
22 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
22 | numpyDtype = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
23 | elif dataTypeCode == 4: |
|
23 | elif dataTypeCode == 4: | |
24 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
24 | numpyDtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
25 | elif dataTypeCode == 5: |
|
25 | elif dataTypeCode == 5: | |
26 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
26 | numpyDtype = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
27 | else: |
|
27 | else: | |
28 | raise ValueError, 'dataTypeCode was not defined' |
|
28 | raise ValueError, 'dataTypeCode was not defined' | |
29 |
|
29 | |||
30 | return numpyDtype |
|
30 | return numpyDtype | |
31 |
|
31 | |||
32 | def getDataTypeCode(numpyDtype): |
|
32 | def getDataTypeCode(numpyDtype): | |
33 |
|
33 | |||
34 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): |
|
34 | if numpyDtype == numpy.dtype([('real','<i1'),('imag','<i1')]): | |
35 | datatype = 0 |
|
35 | datatype = 0 | |
36 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): |
|
36 | elif numpyDtype == numpy.dtype([('real','<i2'),('imag','<i2')]): | |
37 | datatype = 1 |
|
37 | datatype = 1 | |
38 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): |
|
38 | elif numpyDtype == numpy.dtype([('real','<i4'),('imag','<i4')]): | |
39 | datatype = 2 |
|
39 | datatype = 2 | |
40 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): |
|
40 | elif numpyDtype == numpy.dtype([('real','<i8'),('imag','<i8')]): | |
41 | datatype = 3 |
|
41 | datatype = 3 | |
42 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): |
|
42 | elif numpyDtype == numpy.dtype([('real','<f4'),('imag','<f4')]): | |
43 | datatype = 4 |
|
43 | datatype = 4 | |
44 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): |
|
44 | elif numpyDtype == numpy.dtype([('real','<f8'),('imag','<f8')]): | |
45 | datatype = 5 |
|
45 | datatype = 5 | |
46 | else: |
|
46 | else: | |
47 | datatype = None |
|
47 | datatype = None | |
48 |
|
48 | |||
49 | return datatype |
|
49 | return datatype | |
50 |
|
50 | |||
51 | def hildebrand_sekhon(data, navg): |
|
51 | def hildebrand_sekhon(data, navg): | |
52 |
|
52 | |||
53 | data = data.copy() |
|
53 | data = data.copy() | |
54 |
|
54 | |||
55 | sortdata = numpy.sort(data,axis=None) |
|
55 | sortdata = numpy.sort(data,axis=None) | |
56 | lenOfData = len(sortdata) |
|
56 | lenOfData = len(sortdata) | |
57 | nums_min = lenOfData/10 |
|
57 | nums_min = lenOfData/10 | |
58 |
|
58 | |||
59 | if (lenOfData/10) > 2: |
|
59 | if (lenOfData/10) > 2: | |
60 | nums_min = lenOfData/10 |
|
60 | nums_min = lenOfData/10 | |
61 | else: |
|
61 | else: | |
62 | nums_min = 2 |
|
62 | nums_min = 2 | |
63 |
|
63 | |||
64 | sump = 0. |
|
64 | sump = 0. | |
65 |
|
65 | |||
66 | sumq = 0. |
|
66 | sumq = 0. | |
67 |
|
67 | |||
68 | j = 0 |
|
68 | j = 0 | |
69 |
|
69 | |||
70 | cont = 1 |
|
70 | cont = 1 | |
71 |
|
71 | |||
72 | while((cont==1)and(j<lenOfData)): |
|
72 | while((cont==1)and(j<lenOfData)): | |
73 |
|
73 | |||
74 | sump += sortdata[j] |
|
74 | sump += sortdata[j] | |
75 |
|
75 | |||
76 | sumq += sortdata[j]**2 |
|
76 | sumq += sortdata[j]**2 | |
77 |
|
77 | |||
78 | j += 1 |
|
78 | j += 1 | |
79 |
|
79 | |||
80 | if j > nums_min: |
|
80 | if j > nums_min: | |
81 | rtest = float(j)/(j-1) + 1.0/navg |
|
81 | rtest = float(j)/(j-1) + 1.0/navg | |
82 | if ((sumq*j) > (rtest*sump**2)): |
|
82 | if ((sumq*j) > (rtest*sump**2)): | |
83 | j = j - 1 |
|
83 | j = j - 1 | |
84 | sump = sump - sortdata[j] |
|
84 | sump = sump - sortdata[j] | |
85 | sumq = sumq - sortdata[j]**2 |
|
85 | sumq = sumq - sortdata[j]**2 | |
86 | cont = 0 |
|
86 | cont = 0 | |
87 |
|
87 | |||
88 | lnoise = sump /j |
|
88 | lnoise = sump /j | |
89 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) |
|
89 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) | |
90 | return lnoise |
|
90 | return lnoise | |
91 |
|
91 | |||
92 | class GenericData(object): |
|
92 | class GenericData(object): | |
93 |
|
93 | |||
94 | flagNoData = True |
|
94 | flagNoData = True | |
95 |
|
95 | |||
96 | def __init__(self): |
|
96 | def __init__(self): | |
97 |
|
97 | |||
98 | raise ValueError, "This class has not been implemented" |
|
98 | raise ValueError, "This class has not been implemented" | |
99 |
|
99 | |||
100 | def copy(self, inputObj=None): |
|
100 | def copy(self, inputObj=None): | |
101 |
|
101 | |||
102 | if inputObj == None: |
|
102 | if inputObj == None: | |
103 | return copy.deepcopy(self) |
|
103 | return copy.deepcopy(self) | |
104 |
|
104 | |||
105 | for key in inputObj.__dict__.keys(): |
|
105 | for key in inputObj.__dict__.keys(): | |
106 | self.__dict__[key] = inputObj.__dict__[key] |
|
106 | self.__dict__[key] = inputObj.__dict__[key] | |
107 |
|
107 | |||
108 | def deepcopy(self): |
|
108 | def deepcopy(self): | |
109 |
|
109 | |||
110 | return copy.deepcopy(self) |
|
110 | return copy.deepcopy(self) | |
111 |
|
111 | |||
112 | def isEmpty(self): |
|
112 | def isEmpty(self): | |
113 |
|
113 | |||
114 | return self.flagNoData |
|
114 | return self.flagNoData | |
115 |
|
115 | |||
116 | class JROData(GenericData): |
|
116 | class JROData(GenericData): | |
117 |
|
117 | |||
118 | # m_BasicHeader = BasicHeader() |
|
118 | # m_BasicHeader = BasicHeader() | |
119 | # m_ProcessingHeader = ProcessingHeader() |
|
119 | # m_ProcessingHeader = ProcessingHeader() | |
120 |
|
120 | |||
121 | systemHeaderObj = SystemHeader() |
|
121 | systemHeaderObj = SystemHeader() | |
122 |
|
122 | |||
123 | radarControllerHeaderObj = RadarControllerHeader() |
|
123 | radarControllerHeaderObj = RadarControllerHeader() | |
124 |
|
124 | |||
125 | # data = None |
|
125 | # data = None | |
126 |
|
126 | |||
127 | type = None |
|
127 | type = None | |
128 |
|
128 | |||
129 | datatype = None #dtype but in string |
|
129 | datatype = None #dtype but in string | |
130 |
|
130 | |||
131 | # dtype = None |
|
131 | # dtype = None | |
132 |
|
132 | |||
133 | # nChannels = None |
|
133 | # nChannels = None | |
134 |
|
134 | |||
135 | # nHeights = None |
|
135 | # nHeights = None | |
136 |
|
136 | |||
137 | nProfiles = None |
|
137 | nProfiles = None | |
138 |
|
138 | |||
139 | heightList = None |
|
139 | heightList = None | |
140 |
|
140 | |||
141 | channelList = None |
|
141 | channelList = None | |
142 |
|
142 | |||
143 | flagTimeBlock = False |
|
143 | flagTimeBlock = False | |
144 |
|
144 | |||
145 | useLocalTime = False |
|
145 | useLocalTime = False | |
146 |
|
146 | |||
147 | utctime = None |
|
147 | utctime = None | |
148 |
|
148 | |||
149 | timeZone = None |
|
149 | timeZone = None | |
150 |
|
150 | |||
151 | dstFlag = None |
|
151 | dstFlag = None | |
152 |
|
152 | |||
153 | errorCount = None |
|
153 | errorCount = None | |
154 |
|
154 | |||
155 | blocksize = None |
|
155 | blocksize = None | |
156 |
|
156 | |||
157 | nCode = None |
|
157 | nCode = None | |
158 |
|
158 | |||
159 | nBaud = None |
|
159 | nBaud = None | |
160 |
|
160 | |||
161 | code = None |
|
161 | code = None | |
162 |
|
162 | |||
163 | flagDecodeData = False #asumo q la data no esta decodificada |
|
163 | flagDecodeData = False #asumo q la data no esta decodificada | |
164 |
|
164 | |||
165 | flagDeflipData = False #asumo q la data no esta sin flip |
|
165 | flagDeflipData = False #asumo q la data no esta sin flip | |
166 |
|
166 | |||
167 | flagShiftFFT = False |
|
167 | flagShiftFFT = False | |
168 |
|
168 | |||
169 | # ippSeconds = None |
|
169 | # ippSeconds = None | |
170 |
|
170 | |||
171 | timeInterval = None |
|
171 | timeInterval = None | |
172 |
|
172 | |||
173 | nCohInt = None |
|
173 | nCohInt = None | |
174 |
|
174 | |||
175 | noise = None |
|
175 | noise = None | |
176 |
|
176 | |||
177 | windowOfFilter = 1 |
|
177 | windowOfFilter = 1 | |
178 |
|
178 | |||
179 | #Speed of ligth |
|
179 | #Speed of ligth | |
180 | C = 3e8 |
|
180 | C = 3e8 | |
181 |
|
181 | |||
182 | frequency = 49.92e6 |
|
182 | frequency = 49.92e6 | |
183 |
|
183 | |||
184 | realtime = False |
|
184 | realtime = False | |
185 |
|
185 | |||
186 | beacon_heiIndexList = None |
|
186 | beacon_heiIndexList = None | |
187 |
|
187 | |||
188 | last_block = None |
|
188 | last_block = None | |
189 |
|
189 | |||
190 | blocknow = None |
|
190 | blocknow = None | |
191 |
|
191 | |||
|
192 | azimuth = None | |||
|
193 | ||||
|
194 | zenith = None | |||
|
195 | ||||
192 | def __init__(self): |
|
196 | def __init__(self): | |
193 |
|
197 | |||
194 | raise ValueError, "This class has not been implemented" |
|
198 | raise ValueError, "This class has not been implemented" | |
195 |
|
199 | |||
196 | def getNoise(self): |
|
200 | def getNoise(self): | |
197 |
|
201 | |||
198 | raise ValueError, "Not implemented" |
|
202 | raise ValueError, "Not implemented" | |
199 |
|
203 | |||
200 | def getNChannels(self): |
|
204 | def getNChannels(self): | |
201 |
|
205 | |||
202 | return len(self.channelList) |
|
206 | return len(self.channelList) | |
203 |
|
207 | |||
204 | def getChannelIndexList(self): |
|
208 | def getChannelIndexList(self): | |
205 |
|
209 | |||
206 | return range(self.nChannels) |
|
210 | return range(self.nChannels) | |
207 |
|
211 | |||
208 | def getNHeights(self): |
|
212 | def getNHeights(self): | |
209 |
|
213 | |||
210 | return len(self.heightList) |
|
214 | return len(self.heightList) | |
211 |
|
215 | |||
212 | def getHeiRange(self, extrapoints=0): |
|
216 | def getHeiRange(self, extrapoints=0): | |
213 |
|
217 | |||
214 | heis = self.heightList |
|
218 | heis = self.heightList | |
215 | # deltah = self.heightList[1] - self.heightList[0] |
|
219 | # deltah = self.heightList[1] - self.heightList[0] | |
216 | # |
|
220 | # | |
217 | # heis.append(self.heightList[-1]) |
|
221 | # heis.append(self.heightList[-1]) | |
218 |
|
222 | |||
219 | return heis |
|
223 | return heis | |
220 |
|
224 | |||
221 | def getltctime(self): |
|
225 | def getltctime(self): | |
222 |
|
226 | |||
223 | if self.useLocalTime: |
|
227 | if self.useLocalTime: | |
224 | return self.utctime - self.timeZone*60 |
|
228 | return self.utctime - self.timeZone*60 | |
225 |
|
229 | |||
226 | return self.utctime |
|
230 | return self.utctime | |
227 |
|
231 | |||
228 | def getDatatime(self): |
|
232 | def getDatatime(self): | |
229 |
|
233 | |||
230 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
234 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) | |
231 | return datatimeValue |
|
235 | return datatimeValue | |
232 |
|
236 | |||
233 | def getTimeRange(self): |
|
237 | def getTimeRange(self): | |
234 |
|
238 | |||
235 | datatime = [] |
|
239 | datatime = [] | |
236 |
|
240 | |||
237 | datatime.append(self.ltctime) |
|
241 | datatime.append(self.ltctime) | |
238 | datatime.append(self.ltctime + self.timeInterval) |
|
242 | datatime.append(self.ltctime + self.timeInterval) | |
239 |
|
243 | |||
240 | datatime = numpy.array(datatime) |
|
244 | datatime = numpy.array(datatime) | |
241 |
|
245 | |||
242 | return datatime |
|
246 | return datatime | |
243 |
|
247 | |||
244 | def getFmax(self): |
|
248 | def getFmax(self): | |
245 |
|
249 | |||
246 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
250 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
247 |
|
251 | |||
248 | fmax = PRF/2. |
|
252 | fmax = PRF/2. | |
249 |
|
253 | |||
250 | return fmax |
|
254 | return fmax | |
251 |
|
255 | |||
252 | def getVmax(self): |
|
256 | def getVmax(self): | |
253 |
|
257 | |||
254 | _lambda = self.C/self.frequency |
|
258 | _lambda = self.C/self.frequency | |
255 |
|
259 | |||
256 | vmax = self.getFmax() * _lambda |
|
260 | vmax = self.getFmax() * _lambda | |
257 |
|
261 | |||
258 | return vmax |
|
262 | return vmax | |
259 |
|
263 | |||
260 | def get_ippSeconds(self): |
|
264 | def get_ippSeconds(self): | |
261 | ''' |
|
265 | ''' | |
262 | ''' |
|
266 | ''' | |
263 | return self.radarControllerHeaderObj.ippSeconds |
|
267 | return self.radarControllerHeaderObj.ippSeconds | |
264 |
|
268 | |||
265 | def set_ippSeconds(self, ippSeconds): |
|
269 | def set_ippSeconds(self, ippSeconds): | |
266 | ''' |
|
270 | ''' | |
267 | ''' |
|
271 | ''' | |
268 |
|
272 | |||
269 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
273 | self.radarControllerHeaderObj.ippSeconds = ippSeconds | |
270 |
|
274 | |||
271 | return |
|
275 | return | |
272 |
|
276 | |||
273 | def get_dtype(self): |
|
277 | def get_dtype(self): | |
274 | ''' |
|
278 | ''' | |
275 | ''' |
|
279 | ''' | |
276 | return getNumpyDtype(self.datatype) |
|
280 | return getNumpyDtype(self.datatype) | |
277 |
|
281 | |||
278 | def set_dtype(self, numpyDtype): |
|
282 | def set_dtype(self, numpyDtype): | |
279 | ''' |
|
283 | ''' | |
280 | ''' |
|
284 | ''' | |
281 |
|
285 | |||
282 | self.datatype = getDataTypeCode(numpyDtype) |
|
286 | self.datatype = getDataTypeCode(numpyDtype) | |
283 |
|
287 | |||
284 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
288 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
285 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
289 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
286 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
290 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
287 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
291 | #noise = property(getNoise, "I'm the 'nHeights' property.") | |
288 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
292 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
289 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
293 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
290 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
294 | ippSeconds = property(get_ippSeconds, set_ippSeconds) | |
291 | dtype = property(get_dtype, set_dtype) |
|
295 | dtype = property(get_dtype, set_dtype) | |
292 |
|
296 | |||
293 | class Voltage(JROData): |
|
297 | class Voltage(JROData): | |
294 |
|
298 | |||
295 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
299 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
296 | data = None |
|
300 | data = None | |
297 |
|
301 | |||
298 | def __init__(self): |
|
302 | def __init__(self): | |
299 | ''' |
|
303 | ''' | |
300 | Constructor |
|
304 | Constructor | |
301 | ''' |
|
305 | ''' | |
302 |
|
306 | |||
303 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
307 | self.radarControllerHeaderObj = RadarControllerHeader() | |
304 |
|
308 | |||
305 | self.systemHeaderObj = SystemHeader() |
|
309 | self.systemHeaderObj = SystemHeader() | |
306 |
|
310 | |||
307 | self.type = "Voltage" |
|
311 | self.type = "Voltage" | |
308 |
|
312 | |||
309 | self.data = None |
|
313 | self.data = None | |
310 |
|
314 | |||
311 | # self.dtype = None |
|
315 | # self.dtype = None | |
312 |
|
316 | |||
313 | # self.nChannels = 0 |
|
317 | # self.nChannels = 0 | |
314 |
|
318 | |||
315 | # self.nHeights = 0 |
|
319 | # self.nHeights = 0 | |
316 |
|
320 | |||
317 | self.nProfiles = None |
|
321 | self.nProfiles = None | |
318 |
|
322 | |||
319 | self.heightList = None |
|
323 | self.heightList = None | |
320 |
|
324 | |||
321 | self.channelList = None |
|
325 | self.channelList = None | |
322 |
|
326 | |||
323 | # self.channelIndexList = None |
|
327 | # self.channelIndexList = None | |
324 |
|
328 | |||
325 | self.flagNoData = True |
|
329 | self.flagNoData = True | |
326 |
|
330 | |||
327 | self.flagTimeBlock = False |
|
331 | self.flagTimeBlock = False | |
328 |
|
332 | |||
329 | self.utctime = None |
|
333 | self.utctime = None | |
330 |
|
334 | |||
331 | self.timeZone = None |
|
335 | self.timeZone = None | |
332 |
|
336 | |||
333 | self.dstFlag = None |
|
337 | self.dstFlag = None | |
334 |
|
338 | |||
335 | self.errorCount = None |
|
339 | self.errorCount = None | |
336 |
|
340 | |||
337 | self.nCohInt = None |
|
341 | self.nCohInt = None | |
338 |
|
342 | |||
339 | self.blocksize = None |
|
343 | self.blocksize = None | |
340 |
|
344 | |||
341 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
345 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
342 |
|
346 | |||
343 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
347 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
344 |
|
348 | |||
345 | self.flagShiftFFT = False |
|
349 | self.flagShiftFFT = False | |
346 |
|
350 | |||
347 |
|
351 | |||
348 | def getNoisebyHildebrand(self): |
|
352 | def getNoisebyHildebrand(self): | |
349 | """ |
|
353 | """ | |
350 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
354 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
351 |
|
355 | |||
352 | Return: |
|
356 | Return: | |
353 | noiselevel |
|
357 | noiselevel | |
354 | """ |
|
358 | """ | |
355 |
|
359 | |||
356 | for channel in range(self.nChannels): |
|
360 | for channel in range(self.nChannels): | |
357 | daux = self.data_spc[channel,:,:] |
|
361 | daux = self.data_spc[channel,:,:] | |
358 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
362 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) | |
359 |
|
363 | |||
360 | return self.noise |
|
364 | return self.noise | |
361 |
|
365 | |||
362 | def getNoise(self, type = 1): |
|
366 | def getNoise(self, type = 1): | |
363 |
|
367 | |||
364 | self.noise = numpy.zeros(self.nChannels) |
|
368 | self.noise = numpy.zeros(self.nChannels) | |
365 |
|
369 | |||
366 | if type == 1: |
|
370 | if type == 1: | |
367 | noise = self.getNoisebyHildebrand() |
|
371 | noise = self.getNoisebyHildebrand() | |
368 |
|
372 | |||
369 | return 10*numpy.log10(noise) |
|
373 | return 10*numpy.log10(noise) | |
370 |
|
374 | |||
371 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
375 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
372 |
|
376 | |||
373 | class Spectra(JROData): |
|
377 | class Spectra(JROData): | |
374 |
|
378 | |||
375 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
379 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
376 | data_spc = None |
|
380 | data_spc = None | |
377 |
|
381 | |||
378 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
382 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
379 | data_cspc = None |
|
383 | data_cspc = None | |
380 |
|
384 | |||
381 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
385 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
382 | data_dc = None |
|
386 | data_dc = None | |
383 |
|
387 | |||
384 | nFFTPoints = None |
|
388 | nFFTPoints = None | |
385 |
|
389 | |||
386 | # nPairs = None |
|
390 | # nPairs = None | |
387 |
|
391 | |||
388 | pairsList = None |
|
392 | pairsList = None | |
389 |
|
393 | |||
390 | nIncohInt = None |
|
394 | nIncohInt = None | |
391 |
|
395 | |||
392 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
396 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
393 |
|
397 | |||
394 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
398 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
395 |
|
399 | |||
396 | ippFactor = None |
|
400 | ippFactor = None | |
397 |
|
401 | |||
398 | def __init__(self): |
|
402 | def __init__(self): | |
399 | ''' |
|
403 | ''' | |
400 | Constructor |
|
404 | Constructor | |
401 | ''' |
|
405 | ''' | |
402 |
|
406 | |||
403 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
407 | self.radarControllerHeaderObj = RadarControllerHeader() | |
404 |
|
408 | |||
405 | self.systemHeaderObj = SystemHeader() |
|
409 | self.systemHeaderObj = SystemHeader() | |
406 |
|
410 | |||
407 | self.type = "Spectra" |
|
411 | self.type = "Spectra" | |
408 |
|
412 | |||
409 | # self.data = None |
|
413 | # self.data = None | |
410 |
|
414 | |||
411 | # self.dtype = None |
|
415 | # self.dtype = None | |
412 |
|
416 | |||
413 | # self.nChannels = 0 |
|
417 | # self.nChannels = 0 | |
414 |
|
418 | |||
415 | # self.nHeights = 0 |
|
419 | # self.nHeights = 0 | |
416 |
|
420 | |||
417 | self.nProfiles = None |
|
421 | self.nProfiles = None | |
418 |
|
422 | |||
419 | self.heightList = None |
|
423 | self.heightList = None | |
420 |
|
424 | |||
421 | self.channelList = None |
|
425 | self.channelList = None | |
422 |
|
426 | |||
423 | # self.channelIndexList = None |
|
427 | # self.channelIndexList = None | |
424 |
|
428 | |||
425 | self.pairsList = None |
|
429 | self.pairsList = None | |
426 |
|
430 | |||
427 | self.flagNoData = True |
|
431 | self.flagNoData = True | |
428 |
|
432 | |||
429 | self.flagTimeBlock = False |
|
433 | self.flagTimeBlock = False | |
430 |
|
434 | |||
431 | self.utctime = None |
|
435 | self.utctime = None | |
432 |
|
436 | |||
433 | self.nCohInt = None |
|
437 | self.nCohInt = None | |
434 |
|
438 | |||
435 | self.nIncohInt = None |
|
439 | self.nIncohInt = None | |
436 |
|
440 | |||
437 | self.blocksize = None |
|
441 | self.blocksize = None | |
438 |
|
442 | |||
439 | self.nFFTPoints = None |
|
443 | self.nFFTPoints = None | |
440 |
|
444 | |||
441 | self.wavelength = None |
|
445 | self.wavelength = None | |
442 |
|
446 | |||
443 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
447 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
444 |
|
448 | |||
445 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
449 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
446 |
|
450 | |||
447 | self.flagShiftFFT = False |
|
451 | self.flagShiftFFT = False | |
448 |
|
452 | |||
449 | self.ippFactor = 1 |
|
453 | self.ippFactor = 1 | |
450 |
|
454 | |||
451 | #self.noise = None |
|
455 | #self.noise = None | |
452 |
|
456 | |||
453 | self.beacon_heiIndexList = [] |
|
457 | self.beacon_heiIndexList = [] | |
454 |
|
458 | |||
455 | self.noise_estimation = None |
|
459 | self.noise_estimation = None | |
456 |
|
460 | |||
457 |
|
461 | |||
458 | def getNoisebyHildebrand(self): |
|
462 | def getNoisebyHildebrand(self): | |
459 | """ |
|
463 | """ | |
460 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
464 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
461 |
|
465 | |||
462 | Return: |
|
466 | Return: | |
463 | noiselevel |
|
467 | noiselevel | |
464 | """ |
|
468 | """ | |
465 |
|
469 | |||
466 | noise = numpy.zeros(self.nChannels) |
|
470 | noise = numpy.zeros(self.nChannels) | |
467 | for channel in range(self.nChannels): |
|
471 | for channel in range(self.nChannels): | |
468 | daux = self.data_spc[channel,:,:] |
|
472 | daux = self.data_spc[channel,:,:] | |
469 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
473 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
470 |
|
474 | |||
471 | return noise |
|
475 | return noise | |
472 |
|
476 | |||
473 | def getNoise(self): |
|
477 | def getNoise(self): | |
474 | if self.noise_estimation != None: |
|
478 | if self.noise_estimation != None: | |
475 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
479 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py | |
476 | else: |
|
480 | else: | |
477 | noise = self.getNoisebyHildebrand() |
|
481 | noise = self.getNoisebyHildebrand() | |
478 | return noise |
|
482 | return noise | |
479 |
|
483 | |||
480 |
|
484 | |||
481 | def getFreqRange(self, extrapoints=0): |
|
485 | def getFreqRange(self, extrapoints=0): | |
482 |
|
486 | |||
483 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
487 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) | |
484 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
488 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
485 |
|
489 | |||
486 | return freqrange |
|
490 | return freqrange | |
487 |
|
491 | |||
488 | def getVelRange(self, extrapoints=0): |
|
492 | def getVelRange(self, extrapoints=0): | |
489 |
|
493 | |||
490 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
494 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) | |
491 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
495 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |
492 |
|
496 | |||
493 | return velrange |
|
497 | return velrange | |
494 |
|
498 | |||
495 | def getNPairs(self): |
|
499 | def getNPairs(self): | |
496 |
|
500 | |||
497 | return len(self.pairsList) |
|
501 | return len(self.pairsList) | |
498 |
|
502 | |||
499 | def getPairsIndexList(self): |
|
503 | def getPairsIndexList(self): | |
500 |
|
504 | |||
501 | return range(self.nPairs) |
|
505 | return range(self.nPairs) | |
502 |
|
506 | |||
503 | def getNormFactor(self): |
|
507 | def getNormFactor(self): | |
504 | pwcode = 1 |
|
508 | pwcode = 1 | |
505 | if self.flagDecodeData: |
|
509 | if self.flagDecodeData: | |
506 | pwcode = numpy.sum(self.code[0]**2) |
|
510 | pwcode = numpy.sum(self.code[0]**2) | |
507 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
511 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
508 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
512 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter | |
509 |
|
513 | |||
510 | return normFactor |
|
514 | return normFactor | |
511 |
|
515 | |||
512 | def getFlagCspc(self): |
|
516 | def getFlagCspc(self): | |
513 |
|
517 | |||
514 | if self.data_cspc == None: |
|
518 | if self.data_cspc == None: | |
515 | return True |
|
519 | return True | |
516 |
|
520 | |||
517 | return False |
|
521 | return False | |
518 |
|
522 | |||
519 | def getFlagDc(self): |
|
523 | def getFlagDc(self): | |
520 |
|
524 | |||
521 | if self.data_dc == None: |
|
525 | if self.data_dc == None: | |
522 | return True |
|
526 | return True | |
523 |
|
527 | |||
524 | return False |
|
528 | return False | |
525 |
|
529 | |||
526 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
530 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") | |
527 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
531 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") | |
528 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
532 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
529 | flag_cspc = property(getFlagCspc) |
|
533 | flag_cspc = property(getFlagCspc) | |
530 | flag_dc = property(getFlagDc) |
|
534 | flag_dc = property(getFlagDc) | |
531 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
535 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
532 |
|
536 | |||
533 | class SpectraHeis(Spectra): |
|
537 | class SpectraHeis(Spectra): | |
534 |
|
538 | |||
535 | data_spc = None |
|
539 | data_spc = None | |
536 |
|
540 | |||
537 | data_cspc = None |
|
541 | data_cspc = None | |
538 |
|
542 | |||
539 | data_dc = None |
|
543 | data_dc = None | |
540 |
|
544 | |||
541 | nFFTPoints = None |
|
545 | nFFTPoints = None | |
542 |
|
546 | |||
543 | # nPairs = None |
|
547 | # nPairs = None | |
544 |
|
548 | |||
545 | pairsList = None |
|
549 | pairsList = None | |
546 |
|
550 | |||
547 | nIncohInt = None |
|
551 | nIncohInt = None | |
548 |
|
552 | |||
549 | def __init__(self): |
|
553 | def __init__(self): | |
550 |
|
554 | |||
551 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
555 | self.radarControllerHeaderObj = RadarControllerHeader() | |
552 |
|
556 | |||
553 | self.systemHeaderObj = SystemHeader() |
|
557 | self.systemHeaderObj = SystemHeader() | |
554 |
|
558 | |||
555 | self.type = "SpectraHeis" |
|
559 | self.type = "SpectraHeis" | |
556 |
|
560 | |||
557 | # self.dtype = None |
|
561 | # self.dtype = None | |
558 |
|
562 | |||
559 | # self.nChannels = 0 |
|
563 | # self.nChannels = 0 | |
560 |
|
564 | |||
561 | # self.nHeights = 0 |
|
565 | # self.nHeights = 0 | |
562 |
|
566 | |||
563 | self.nProfiles = None |
|
567 | self.nProfiles = None | |
564 |
|
568 | |||
565 | self.heightList = None |
|
569 | self.heightList = None | |
566 |
|
570 | |||
567 | self.channelList = None |
|
571 | self.channelList = None | |
568 |
|
572 | |||
569 | # self.channelIndexList = None |
|
573 | # self.channelIndexList = None | |
570 |
|
574 | |||
571 | self.flagNoData = True |
|
575 | self.flagNoData = True | |
572 |
|
576 | |||
573 | self.flagTimeBlock = False |
|
577 | self.flagTimeBlock = False | |
574 |
|
578 | |||
575 | # self.nPairs = 0 |
|
579 | # self.nPairs = 0 | |
576 |
|
580 | |||
577 | self.utctime = None |
|
581 | self.utctime = None | |
578 |
|
582 | |||
579 | self.blocksize = None |
|
583 | self.blocksize = None | |
580 |
|
584 | |||
581 | def getNormFactor(self): |
|
585 | def getNormFactor(self): | |
582 | pwcode = 1 |
|
586 | pwcode = 1 | |
583 | if self.flagDecodeData: |
|
587 | if self.flagDecodeData: | |
584 | pwcode = numpy.sum(self.code[0]**2) |
|
588 | pwcode = numpy.sum(self.code[0]**2) | |
585 |
|
589 | |||
586 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
590 | normFactor = self.nIncohInt*self.nCohInt*pwcode | |
587 |
|
591 | |||
588 | return normFactor |
|
592 | return normFactor | |
589 |
|
593 | |||
590 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
594 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
591 |
|
595 | |||
592 | class Fits: |
|
596 | class Fits: | |
593 |
|
597 | |||
594 | heightList = None |
|
598 | heightList = None | |
595 |
|
599 | |||
596 | channelList = None |
|
600 | channelList = None | |
597 |
|
601 | |||
598 | flagNoData = True |
|
602 | flagNoData = True | |
599 |
|
603 | |||
600 | flagTimeBlock = False |
|
604 | flagTimeBlock = False | |
601 |
|
605 | |||
602 | useLocalTime = False |
|
606 | useLocalTime = False | |
603 |
|
607 | |||
604 | utctime = None |
|
608 | utctime = None | |
605 |
|
609 | |||
606 | timeZone = None |
|
610 | timeZone = None | |
607 |
|
611 | |||
608 | # ippSeconds = None |
|
612 | # ippSeconds = None | |
609 |
|
613 | |||
610 | timeInterval = None |
|
614 | timeInterval = None | |
611 |
|
615 | |||
612 | nCohInt = None |
|
616 | nCohInt = None | |
613 |
|
617 | |||
614 | nIncohInt = None |
|
618 | nIncohInt = None | |
615 |
|
619 | |||
616 | noise = None |
|
620 | noise = None | |
617 |
|
621 | |||
618 | windowOfFilter = 1 |
|
622 | windowOfFilter = 1 | |
619 |
|
623 | |||
620 | #Speed of ligth |
|
624 | #Speed of ligth | |
621 | C = 3e8 |
|
625 | C = 3e8 | |
622 |
|
626 | |||
623 | frequency = 49.92e6 |
|
627 | frequency = 49.92e6 | |
624 |
|
628 | |||
625 | realtime = False |
|
629 | realtime = False | |
626 |
|
630 | |||
627 |
|
631 | |||
628 | def __init__(self): |
|
632 | def __init__(self): | |
629 |
|
633 | |||
630 | self.type = "Fits" |
|
634 | self.type = "Fits" | |
631 |
|
635 | |||
632 | self.nProfiles = None |
|
636 | self.nProfiles = None | |
633 |
|
637 | |||
634 | self.heightList = None |
|
638 | self.heightList = None | |
635 |
|
639 | |||
636 | self.channelList = None |
|
640 | self.channelList = None | |
637 |
|
641 | |||
638 | # self.channelIndexList = None |
|
642 | # self.channelIndexList = None | |
639 |
|
643 | |||
640 | self.flagNoData = True |
|
644 | self.flagNoData = True | |
641 |
|
645 | |||
642 | self.utctime = None |
|
646 | self.utctime = None | |
643 |
|
647 | |||
644 | self.nCohInt = None |
|
648 | self.nCohInt = None | |
645 |
|
649 | |||
646 | self.nIncohInt = None |
|
650 | self.nIncohInt = None | |
647 |
|
651 | |||
648 | self.useLocalTime = True |
|
652 | self.useLocalTime = True | |
649 |
|
653 | |||
650 | # self.utctime = None |
|
654 | # self.utctime = None | |
651 | # self.timeZone = None |
|
655 | # self.timeZone = None | |
652 | # self.ltctime = None |
|
656 | # self.ltctime = None | |
653 | # self.timeInterval = None |
|
657 | # self.timeInterval = None | |
654 | # self.header = None |
|
658 | # self.header = None | |
655 | # self.data_header = None |
|
659 | # self.data_header = None | |
656 | # self.data = None |
|
660 | # self.data = None | |
657 | # self.datatime = None |
|
661 | # self.datatime = None | |
658 | # self.flagNoData = False |
|
662 | # self.flagNoData = False | |
659 | # self.expName = '' |
|
663 | # self.expName = '' | |
660 | # self.nChannels = None |
|
664 | # self.nChannels = None | |
661 | # self.nSamples = None |
|
665 | # self.nSamples = None | |
662 | # self.dataBlocksPerFile = None |
|
666 | # self.dataBlocksPerFile = None | |
663 | # self.comments = '' |
|
667 | # self.comments = '' | |
664 | # |
|
668 | # | |
665 |
|
669 | |||
666 |
|
670 | |||
667 | def getltctime(self): |
|
671 | def getltctime(self): | |
668 |
|
672 | |||
669 | if self.useLocalTime: |
|
673 | if self.useLocalTime: | |
670 | return self.utctime - self.timeZone*60 |
|
674 | return self.utctime - self.timeZone*60 | |
671 |
|
675 | |||
672 | return self.utctime |
|
676 | return self.utctime | |
673 |
|
677 | |||
674 | def getDatatime(self): |
|
678 | def getDatatime(self): | |
675 |
|
679 | |||
676 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
680 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
677 | return datatime |
|
681 | return datatime | |
678 |
|
682 | |||
679 | def getTimeRange(self): |
|
683 | def getTimeRange(self): | |
680 |
|
684 | |||
681 | datatime = [] |
|
685 | datatime = [] | |
682 |
|
686 | |||
683 | datatime.append(self.ltctime) |
|
687 | datatime.append(self.ltctime) | |
684 | datatime.append(self.ltctime + self.timeInterval) |
|
688 | datatime.append(self.ltctime + self.timeInterval) | |
685 |
|
689 | |||
686 | datatime = numpy.array(datatime) |
|
690 | datatime = numpy.array(datatime) | |
687 |
|
691 | |||
688 | return datatime |
|
692 | return datatime | |
689 |
|
693 | |||
690 | def getHeiRange(self): |
|
694 | def getHeiRange(self): | |
691 |
|
695 | |||
692 | heis = self.heightList |
|
696 | heis = self.heightList | |
693 |
|
697 | |||
694 | return heis |
|
698 | return heis | |
695 |
|
699 | |||
696 | def isEmpty(self): |
|
700 | def isEmpty(self): | |
697 |
|
701 | |||
698 | return self.flagNoData |
|
702 | return self.flagNoData | |
699 |
|
703 | |||
700 | def getNHeights(self): |
|
704 | def getNHeights(self): | |
701 |
|
705 | |||
702 | return len(self.heightList) |
|
706 | return len(self.heightList) | |
703 |
|
707 | |||
704 | def getNChannels(self): |
|
708 | def getNChannels(self): | |
705 |
|
709 | |||
706 | return len(self.channelList) |
|
710 | return len(self.channelList) | |
707 |
|
711 | |||
708 | def getChannelIndexList(self): |
|
712 | def getChannelIndexList(self): | |
709 |
|
713 | |||
710 | return range(self.nChannels) |
|
714 | return range(self.nChannels) | |
711 |
|
715 | |||
712 | def getNoise(self, type = 1): |
|
716 | def getNoise(self, type = 1): | |
713 |
|
717 | |||
714 | self.noise = numpy.zeros(self.nChannels) |
|
718 | self.noise = numpy.zeros(self.nChannels) | |
715 |
|
719 | |||
716 | if type == 1: |
|
720 | if type == 1: | |
717 | noise = self.getNoisebyHildebrand() |
|
721 | noise = self.getNoisebyHildebrand() | |
718 |
|
722 | |||
719 | if type == 2: |
|
723 | if type == 2: | |
720 | noise = self.getNoisebySort() |
|
724 | noise = self.getNoisebySort() | |
721 |
|
725 | |||
722 | if type == 3: |
|
726 | if type == 3: | |
723 | noise = self.getNoisebyWindow() |
|
727 | noise = self.getNoisebyWindow() | |
724 |
|
728 | |||
725 | return noise |
|
729 | return noise | |
726 |
|
730 | |||
727 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
731 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
728 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
732 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
729 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
733 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
730 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
734 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
731 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
735 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
732 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
736 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
733 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
737 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
734 |
|
738 | |||
735 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
739 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |
736 |
|
740 |
@@ -1,1346 +1,1354 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Daniel Suarez |
|
2 | @author: Daniel Suarez | |
3 | ''' |
|
3 | ''' | |
4 | import os |
|
4 | import os | |
5 | import datetime |
|
5 | import datetime | |
6 | import numpy |
|
6 | import numpy | |
7 |
|
7 | |||
8 | from figure import Figure, isRealtime |
|
8 | from figure import Figure, isRealtime | |
9 |
|
9 | |||
10 | class SpectraPlot(Figure): |
|
10 | class SpectraPlot(Figure): | |
11 |
|
11 | |||
12 | isConfig = None |
|
12 | isConfig = None | |
13 | __nsubplots = None |
|
13 | __nsubplots = None | |
14 |
|
14 | |||
15 | WIDTHPROF = None |
|
15 | WIDTHPROF = None | |
16 | HEIGHTPROF = None |
|
16 | HEIGHTPROF = None | |
17 | PREFIX = 'spc' |
|
17 | PREFIX = 'spc' | |
18 |
|
18 | |||
19 | def __init__(self): |
|
19 | def __init__(self): | |
20 |
|
20 | |||
21 | self.isConfig = False |
|
21 | self.isConfig = False | |
22 | self.__nsubplots = 1 |
|
22 | self.__nsubplots = 1 | |
23 |
|
23 | |||
24 | self.WIDTH = 280 |
|
24 | self.WIDTH = 280 | |
25 | self.HEIGHT = 250 |
|
25 | self.HEIGHT = 250 | |
26 | self.WIDTHPROF = 120 |
|
26 | self.WIDTHPROF = 120 | |
27 | self.HEIGHTPROF = 0 |
|
27 | self.HEIGHTPROF = 0 | |
28 | self.counter_imagwr = 0 |
|
28 | self.counter_imagwr = 0 | |
29 |
|
29 | |||
30 | self.PLOT_CODE = 1 |
|
30 | self.PLOT_CODE = 1 | |
31 | self.FTP_WEI = None |
|
31 | self.FTP_WEI = None | |
32 | self.EXP_CODE = None |
|
32 | self.EXP_CODE = None | |
33 | self.SUB_EXP_CODE = None |
|
33 | self.SUB_EXP_CODE = None | |
34 | self.PLOT_POS = None |
|
34 | self.PLOT_POS = None | |
35 |
|
35 | |||
36 | def getSubplots(self): |
|
36 | def getSubplots(self): | |
37 |
|
37 | |||
38 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
38 | ncol = int(numpy.sqrt(self.nplots)+0.9) | |
39 | nrow = int(self.nplots*1./ncol + 0.9) |
|
39 | nrow = int(self.nplots*1./ncol + 0.9) | |
40 |
|
40 | |||
41 | return nrow, ncol |
|
41 | return nrow, ncol | |
42 |
|
42 | |||
43 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
43 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
44 |
|
44 | |||
45 | self.__showprofile = showprofile |
|
45 | self.__showprofile = showprofile | |
46 | self.nplots = nplots |
|
46 | self.nplots = nplots | |
47 |
|
47 | |||
48 | ncolspan = 1 |
|
48 | ncolspan = 1 | |
49 | colspan = 1 |
|
49 | colspan = 1 | |
50 | if showprofile: |
|
50 | if showprofile: | |
51 | ncolspan = 3 |
|
51 | ncolspan = 3 | |
52 | colspan = 2 |
|
52 | colspan = 2 | |
53 | self.__nsubplots = 2 |
|
53 | self.__nsubplots = 2 | |
54 |
|
54 | |||
55 | self.createFigure(id = id, |
|
55 | self.createFigure(id = id, | |
56 | wintitle = wintitle, |
|
56 | wintitle = wintitle, | |
57 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
57 | widthplot = self.WIDTH + self.WIDTHPROF, | |
58 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
58 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
59 | show=show) |
|
59 | show=show) | |
60 |
|
60 | |||
61 | nrow, ncol = self.getSubplots() |
|
61 | nrow, ncol = self.getSubplots() | |
62 |
|
62 | |||
63 | counter = 0 |
|
63 | counter = 0 | |
64 | for y in range(nrow): |
|
64 | for y in range(nrow): | |
65 | for x in range(ncol): |
|
65 | for x in range(ncol): | |
66 |
|
66 | |||
67 | if counter >= self.nplots: |
|
67 | if counter >= self.nplots: | |
68 | break |
|
68 | break | |
69 |
|
69 | |||
70 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
70 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
71 |
|
71 | |||
72 | if showprofile: |
|
72 | if showprofile: | |
73 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
73 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
74 |
|
74 | |||
75 | counter += 1 |
|
75 | counter += 1 | |
76 |
|
76 | |||
77 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
77 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, | |
78 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
78 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
79 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
79 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
80 | server=None, folder=None, username=None, password=None, |
|
80 | server=None, folder=None, username=None, password=None, | |
81 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
81 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): | |
82 |
|
82 | |||
83 | """ |
|
83 | """ | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | dataOut : |
|
86 | dataOut : | |
87 | id : |
|
87 | id : | |
88 | wintitle : |
|
88 | wintitle : | |
89 | channelList : |
|
89 | channelList : | |
90 | showProfile : |
|
90 | showProfile : | |
91 | xmin : None, |
|
91 | xmin : None, | |
92 | xmax : None, |
|
92 | xmax : None, | |
93 | ymin : None, |
|
93 | ymin : None, | |
94 | ymax : None, |
|
94 | ymax : None, | |
95 | zmin : None, |
|
95 | zmin : None, | |
96 | zmax : None |
|
96 | zmax : None | |
97 | """ |
|
97 | """ | |
98 |
|
98 | |||
99 | if dataOut.flagNoData: |
|
99 | if dataOut.flagNoData: | |
100 | return None |
|
100 | return None | |
101 |
|
101 | |||
102 | if realtime: |
|
102 | if realtime: | |
103 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
103 | if not(isRealtime(utcdatatime = dataOut.utctime)): | |
104 | print 'Skipping this plot function' |
|
104 | print 'Skipping this plot function' | |
105 | return |
|
105 | return | |
106 |
|
106 | |||
107 | if channelList == None: |
|
107 | if channelList == None: | |
108 | channelIndexList = dataOut.channelIndexList |
|
108 | channelIndexList = dataOut.channelIndexList | |
109 | else: |
|
109 | else: | |
110 | channelIndexList = [] |
|
110 | channelIndexList = [] | |
111 | for channel in channelList: |
|
111 | for channel in channelList: | |
112 | if channel not in dataOut.channelList: |
|
112 | if channel not in dataOut.channelList: | |
113 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
113 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
114 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
114 | channelIndexList.append(dataOut.channelList.index(channel)) | |
115 |
|
115 | |||
116 | factor = dataOut.normFactor |
|
116 | factor = dataOut.normFactor | |
117 |
|
117 | |||
118 | x = dataOut.getVelRange(1) |
|
118 | x = dataOut.getVelRange(1) | |
119 | y = dataOut.getHeiRange() |
|
119 | y = dataOut.getHeiRange() | |
120 |
|
120 | |||
121 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
121 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
122 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
122 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
123 | avg = numpy.average(z, axis=1) |
|
123 | avg = numpy.average(z, axis=1) | |
124 | avg = numpy.nanmean(z, axis=1) |
|
124 | avg = numpy.nanmean(z, axis=1) | |
125 | noise = dataOut.noise/factor |
|
125 | noise = dataOut.noise/factor | |
126 |
|
126 | |||
127 | zdB = 10*numpy.log10(z) |
|
127 | zdB = 10*numpy.log10(z) | |
128 | avgdB = 10*numpy.log10(avg) |
|
128 | avgdB = 10*numpy.log10(avg) | |
129 | noisedB = 10*numpy.log10(noise) |
|
129 | noisedB = 10*numpy.log10(noise) | |
130 |
|
130 | |||
131 | #thisDatetime = dataOut.datatime |
|
131 | #thisDatetime = dataOut.datatime | |
132 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
132 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
133 | title = wintitle + " Spectra" |
|
133 | title = wintitle + " Spectra" | |
|
134 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |||
|
135 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | |||
|
136 | ||||
134 | xlabel = "Velocity (m/s)" |
|
137 | xlabel = "Velocity (m/s)" | |
135 | ylabel = "Range (Km)" |
|
138 | ylabel = "Range (Km)" | |
136 |
|
139 | |||
137 | if not self.isConfig: |
|
140 | if not self.isConfig: | |
138 |
|
141 | |||
139 | nplots = len(channelIndexList) |
|
142 | nplots = len(channelIndexList) | |
140 |
|
143 | |||
141 | self.setup(id=id, |
|
144 | self.setup(id=id, | |
142 | nplots=nplots, |
|
145 | nplots=nplots, | |
143 | wintitle=wintitle, |
|
146 | wintitle=wintitle, | |
144 | showprofile=showprofile, |
|
147 | showprofile=showprofile, | |
145 | show=show) |
|
148 | show=show) | |
146 |
|
149 | |||
147 | if xmin == None: xmin = numpy.nanmin(x) |
|
150 | if xmin == None: xmin = numpy.nanmin(x) | |
148 | if xmax == None: xmax = numpy.nanmax(x) |
|
151 | if xmax == None: xmax = numpy.nanmax(x) | |
149 | if ymin == None: ymin = numpy.nanmin(y) |
|
152 | if ymin == None: ymin = numpy.nanmin(y) | |
150 | if ymax == None: ymax = numpy.nanmax(y) |
|
153 | if ymax == None: ymax = numpy.nanmax(y) | |
151 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
154 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
152 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
155 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
153 |
|
156 | |||
154 | self.FTP_WEI = ftp_wei |
|
157 | self.FTP_WEI = ftp_wei | |
155 | self.EXP_CODE = exp_code |
|
158 | self.EXP_CODE = exp_code | |
156 | self.SUB_EXP_CODE = sub_exp_code |
|
159 | self.SUB_EXP_CODE = sub_exp_code | |
157 | self.PLOT_POS = plot_pos |
|
160 | self.PLOT_POS = plot_pos | |
158 |
|
161 | |||
159 | self.isConfig = True |
|
162 | self.isConfig = True | |
160 |
|
163 | |||
161 | self.setWinTitle(title) |
|
164 | self.setWinTitle(title) | |
162 |
|
165 | |||
163 | for i in range(self.nplots): |
|
166 | for i in range(self.nplots): | |
164 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
167 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
165 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
168 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) | |
166 | axes = self.axesList[i*self.__nsubplots] |
|
169 | axes = self.axesList[i*self.__nsubplots] | |
167 | axes.pcolor(x, y, zdB[i,:,:], |
|
170 | axes.pcolor(x, y, zdB[i,:,:], | |
168 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
171 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
169 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
172 | xlabel=xlabel, ylabel=ylabel, title=title, | |
170 | ticksize=9, cblabel='') |
|
173 | ticksize=9, cblabel='') | |
171 |
|
174 | |||
172 | if self.__showprofile: |
|
175 | if self.__showprofile: | |
173 | axes = self.axesList[i*self.__nsubplots +1] |
|
176 | axes = self.axesList[i*self.__nsubplots +1] | |
174 | axes.pline(avgdB[i], y, |
|
177 | axes.pline(avgdB[i], y, | |
175 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
178 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
176 | xlabel='dB', ylabel='', title='', |
|
179 | xlabel='dB', ylabel='', title='', | |
177 | ytick_visible=False, |
|
180 | ytick_visible=False, | |
178 | grid='x') |
|
181 | grid='x') | |
179 |
|
182 | |||
180 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
183 | noiseline = numpy.repeat(noisedB[i], len(y)) | |
181 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
184 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) | |
182 |
|
185 | |||
183 | self.draw() |
|
186 | self.draw() | |
184 |
|
187 | |||
185 | if figfile == None: |
|
188 | if figfile == None: | |
186 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
189 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
187 | figfile = self.getFilename(name = str_datetime) |
|
190 | figfile = self.getFilename(name = str_datetime) | |
188 |
|
191 | name = str_datetime | ||
|
192 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |||
|
193 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) | |||
|
194 | figfile = self.getFilename(name) | |||
189 | if figpath != '': |
|
195 | if figpath != '': | |
190 | self.counter_imagwr += 1 |
|
196 | self.counter_imagwr += 1 | |
191 | if (self.counter_imagwr>=wr_period): |
|
197 | if (self.counter_imagwr>=wr_period): | |
192 | # store png plot to local folder |
|
198 | # store png plot to local folder | |
193 | self.saveFigure(figpath, figfile) |
|
199 | self.saveFigure(figpath, figfile) | |
194 | # store png plot to FTP server according to RT-Web format |
|
200 | # store png plot to FTP server according to RT-Web format | |
195 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
201 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
196 | ftp_filename = os.path.join(figpath, name) |
|
202 | ftp_filename = os.path.join(figpath, name) | |
197 | self.saveFigure(figpath, ftp_filename) |
|
203 | self.saveFigure(figpath, ftp_filename) | |
198 | self.counter_imagwr = 0 |
|
204 | self.counter_imagwr = 0 | |
199 |
|
205 | |||
200 |
|
206 | |||
201 | class CrossSpectraPlot(Figure): |
|
207 | class CrossSpectraPlot(Figure): | |
202 |
|
208 | |||
203 | isConfig = None |
|
209 | isConfig = None | |
204 | __nsubplots = None |
|
210 | __nsubplots = None | |
205 |
|
211 | |||
206 | WIDTH = None |
|
212 | WIDTH = None | |
207 | HEIGHT = None |
|
213 | HEIGHT = None | |
208 | WIDTHPROF = None |
|
214 | WIDTHPROF = None | |
209 | HEIGHTPROF = None |
|
215 | HEIGHTPROF = None | |
210 | PREFIX = 'cspc' |
|
216 | PREFIX = 'cspc' | |
211 |
|
217 | |||
212 | def __init__(self): |
|
218 | def __init__(self): | |
213 |
|
219 | |||
214 | self.isConfig = False |
|
220 | self.isConfig = False | |
215 | self.__nsubplots = 4 |
|
221 | self.__nsubplots = 4 | |
216 | self.counter_imagwr = 0 |
|
222 | self.counter_imagwr = 0 | |
217 | self.WIDTH = 250 |
|
223 | self.WIDTH = 250 | |
218 | self.HEIGHT = 250 |
|
224 | self.HEIGHT = 250 | |
219 | self.WIDTHPROF = 0 |
|
225 | self.WIDTHPROF = 0 | |
220 | self.HEIGHTPROF = 0 |
|
226 | self.HEIGHTPROF = 0 | |
221 |
|
227 | |||
222 | self.PLOT_CODE = 1 |
|
228 | self.PLOT_CODE = 1 | |
223 | self.FTP_WEI = None |
|
229 | self.FTP_WEI = None | |
224 | self.EXP_CODE = None |
|
230 | self.EXP_CODE = None | |
225 | self.SUB_EXP_CODE = None |
|
231 | self.SUB_EXP_CODE = None | |
226 | self.PLOT_POS = None |
|
232 | self.PLOT_POS = None | |
227 |
|
233 | |||
228 | def getSubplots(self): |
|
234 | def getSubplots(self): | |
229 |
|
235 | |||
230 | ncol = 4 |
|
236 | ncol = 4 | |
231 | nrow = self.nplots |
|
237 | nrow = self.nplots | |
232 |
|
238 | |||
233 | return nrow, ncol |
|
239 | return nrow, ncol | |
234 |
|
240 | |||
235 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
241 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
236 |
|
242 | |||
237 | self.__showprofile = showprofile |
|
243 | self.__showprofile = showprofile | |
238 | self.nplots = nplots |
|
244 | self.nplots = nplots | |
239 |
|
245 | |||
240 | ncolspan = 1 |
|
246 | ncolspan = 1 | |
241 | colspan = 1 |
|
247 | colspan = 1 | |
242 |
|
248 | |||
243 | self.createFigure(id = id, |
|
249 | self.createFigure(id = id, | |
244 | wintitle = wintitle, |
|
250 | wintitle = wintitle, | |
245 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
251 | widthplot = self.WIDTH + self.WIDTHPROF, | |
246 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
252 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
247 | show=True) |
|
253 | show=True) | |
248 |
|
254 | |||
249 | nrow, ncol = self.getSubplots() |
|
255 | nrow, ncol = self.getSubplots() | |
250 |
|
256 | |||
251 | counter = 0 |
|
257 | counter = 0 | |
252 | for y in range(nrow): |
|
258 | for y in range(nrow): | |
253 | for x in range(ncol): |
|
259 | for x in range(ncol): | |
254 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
260 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
255 |
|
261 | |||
256 | counter += 1 |
|
262 | counter += 1 | |
257 |
|
263 | |||
258 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
264 | def run(self, dataOut, id, wintitle="", pairsList=None, | |
259 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
265 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
260 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, |
|
266 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, | |
261 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
267 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
262 | server=None, folder=None, username=None, password=None, |
|
268 | server=None, folder=None, username=None, password=None, | |
263 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
269 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
264 |
|
270 | |||
265 | """ |
|
271 | """ | |
266 |
|
272 | |||
267 | Input: |
|
273 | Input: | |
268 | dataOut : |
|
274 | dataOut : | |
269 | id : |
|
275 | id : | |
270 | wintitle : |
|
276 | wintitle : | |
271 | channelList : |
|
277 | channelList : | |
272 | showProfile : |
|
278 | showProfile : | |
273 | xmin : None, |
|
279 | xmin : None, | |
274 | xmax : None, |
|
280 | xmax : None, | |
275 | ymin : None, |
|
281 | ymin : None, | |
276 | ymax : None, |
|
282 | ymax : None, | |
277 | zmin : None, |
|
283 | zmin : None, | |
278 | zmax : None |
|
284 | zmax : None | |
279 | """ |
|
285 | """ | |
280 |
|
286 | |||
281 | if pairsList == None: |
|
287 | if pairsList == None: | |
282 | pairsIndexList = dataOut.pairsIndexList |
|
288 | pairsIndexList = dataOut.pairsIndexList | |
283 | else: |
|
289 | else: | |
284 | pairsIndexList = [] |
|
290 | pairsIndexList = [] | |
285 | for pair in pairsList: |
|
291 | for pair in pairsList: | |
286 | if pair not in dataOut.pairsList: |
|
292 | if pair not in dataOut.pairsList: | |
287 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
293 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
288 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
294 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
289 |
|
295 | |||
290 | if pairsIndexList == []: |
|
296 | if pairsIndexList == []: | |
291 | return |
|
297 | return | |
292 |
|
298 | |||
293 | if len(pairsIndexList) > 4: |
|
299 | if len(pairsIndexList) > 4: | |
294 | pairsIndexList = pairsIndexList[0:4] |
|
300 | pairsIndexList = pairsIndexList[0:4] | |
295 | factor = dataOut.normFactor |
|
301 | factor = dataOut.normFactor | |
296 | x = dataOut.getVelRange(1) |
|
302 | x = dataOut.getVelRange(1) | |
297 | y = dataOut.getHeiRange() |
|
303 | y = dataOut.getHeiRange() | |
298 | z = dataOut.data_spc[:,:,:]/factor |
|
304 | z = dataOut.data_spc[:,:,:]/factor | |
299 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
305 | # z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
300 | avg = numpy.abs(numpy.average(z, axis=1)) |
|
306 | avg = numpy.abs(numpy.average(z, axis=1)) | |
301 | noise = dataOut.noise()/factor |
|
307 | noise = dataOut.noise()/factor | |
302 |
|
308 | |||
303 | zdB = 10*numpy.log10(z) |
|
309 | zdB = 10*numpy.log10(z) | |
304 | avgdB = 10*numpy.log10(avg) |
|
310 | avgdB = 10*numpy.log10(avg) | |
305 | noisedB = 10*numpy.log10(noise) |
|
311 | noisedB = 10*numpy.log10(noise) | |
306 |
|
312 | |||
307 |
|
313 | |||
308 | #thisDatetime = dataOut.datatime |
|
314 | #thisDatetime = dataOut.datatime | |
309 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
315 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
310 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
316 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
311 | xlabel = "Velocity (m/s)" |
|
317 | xlabel = "Velocity (m/s)" | |
312 | ylabel = "Range (Km)" |
|
318 | ylabel = "Range (Km)" | |
313 |
|
319 | |||
314 | if not self.isConfig: |
|
320 | if not self.isConfig: | |
315 |
|
321 | |||
316 | nplots = len(pairsIndexList) |
|
322 | nplots = len(pairsIndexList) | |
317 |
|
323 | |||
318 | self.setup(id=id, |
|
324 | self.setup(id=id, | |
319 | nplots=nplots, |
|
325 | nplots=nplots, | |
320 | wintitle=wintitle, |
|
326 | wintitle=wintitle, | |
321 | showprofile=False, |
|
327 | showprofile=False, | |
322 | show=show) |
|
328 | show=show) | |
323 |
|
329 | |||
324 | if xmin == None: xmin = numpy.nanmin(x) |
|
330 | if xmin == None: xmin = numpy.nanmin(x) | |
325 | if xmax == None: xmax = numpy.nanmax(x) |
|
331 | if xmax == None: xmax = numpy.nanmax(x) | |
326 | if ymin == None: ymin = numpy.nanmin(y) |
|
332 | if ymin == None: ymin = numpy.nanmin(y) | |
327 | if ymax == None: ymax = numpy.nanmax(y) |
|
333 | if ymax == None: ymax = numpy.nanmax(y) | |
328 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
334 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
329 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
335 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
330 |
|
336 | |||
331 | self.FTP_WEI = ftp_wei |
|
337 | self.FTP_WEI = ftp_wei | |
332 | self.EXP_CODE = exp_code |
|
338 | self.EXP_CODE = exp_code | |
333 | self.SUB_EXP_CODE = sub_exp_code |
|
339 | self.SUB_EXP_CODE = sub_exp_code | |
334 | self.PLOT_POS = plot_pos |
|
340 | self.PLOT_POS = plot_pos | |
335 |
|
341 | |||
336 | self.isConfig = True |
|
342 | self.isConfig = True | |
337 |
|
343 | |||
338 | self.setWinTitle(title) |
|
344 | self.setWinTitle(title) | |
339 |
|
345 | |||
340 | for i in range(self.nplots): |
|
346 | for i in range(self.nplots): | |
341 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
347 | pair = dataOut.pairsList[pairsIndexList[i]] | |
342 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
348 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) | |
343 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
349 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) | |
344 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
350 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) | |
345 | axes0 = self.axesList[i*self.__nsubplots] |
|
351 | axes0 = self.axesList[i*self.__nsubplots] | |
346 | axes0.pcolor(x, y, zdB, |
|
352 | axes0.pcolor(x, y, zdB, | |
347 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
353 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
348 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
354 | xlabel=xlabel, ylabel=ylabel, title=title, | |
349 | ticksize=9, colormap=power_cmap, cblabel='') |
|
355 | ticksize=9, colormap=power_cmap, cblabel='') | |
350 |
|
356 | |||
351 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
357 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) | |
352 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
358 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) | |
353 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
359 | axes0 = self.axesList[i*self.__nsubplots+1] | |
354 | axes0.pcolor(x, y, zdB, |
|
360 | axes0.pcolor(x, y, zdB, | |
355 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
361 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
356 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
362 | xlabel=xlabel, ylabel=ylabel, title=title, | |
357 | ticksize=9, colormap=power_cmap, cblabel='') |
|
363 | ticksize=9, colormap=power_cmap, cblabel='') | |
358 |
|
364 | |||
359 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
365 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) | |
360 | coherence = numpy.abs(coherenceComplex) |
|
366 | coherence = numpy.abs(coherenceComplex) | |
361 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
367 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi | |
362 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
368 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi | |
363 |
|
369 | |||
364 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
370 | title = "Coherence %d%d" %(pair[0], pair[1]) | |
365 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
371 | axes0 = self.axesList[i*self.__nsubplots+2] | |
366 | axes0.pcolor(x, y, coherence, |
|
372 | axes0.pcolor(x, y, coherence, | |
367 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
373 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, | |
368 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
374 | xlabel=xlabel, ylabel=ylabel, title=title, | |
369 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
375 | ticksize=9, colormap=coherence_cmap, cblabel='') | |
370 |
|
376 | |||
371 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
377 | title = "Phase %d%d" %(pair[0], pair[1]) | |
372 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
378 | axes0 = self.axesList[i*self.__nsubplots+3] | |
373 | axes0.pcolor(x, y, phase, |
|
379 | axes0.pcolor(x, y, phase, | |
374 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
380 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
375 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
381 | xlabel=xlabel, ylabel=ylabel, title=title, | |
376 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
382 | ticksize=9, colormap=phase_cmap, cblabel='') | |
377 |
|
383 | |||
378 |
|
384 | |||
379 |
|
385 | |||
380 | self.draw() |
|
386 | self.draw() | |
381 |
|
387 | |||
382 | if figfile == None: |
|
388 | if figfile == None: | |
383 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
389 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
384 | figfile = self.getFilename(name = str_datetime) |
|
390 | figfile = self.getFilename(name = str_datetime) | |
385 |
|
391 | |||
386 | if figpath != '': |
|
392 | if figpath != '': | |
387 | self.counter_imagwr += 1 |
|
393 | self.counter_imagwr += 1 | |
388 | if (self.counter_imagwr>=wr_period): |
|
394 | if (self.counter_imagwr>=wr_period): | |
389 | # store png plot to local folder |
|
395 | # store png plot to local folder | |
390 | self.saveFigure(figpath, figfile) |
|
396 | self.saveFigure(figpath, figfile) | |
391 | # store png plot to FTP server according to RT-Web format |
|
397 | # store png plot to FTP server according to RT-Web format | |
392 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
398 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
393 | ftp_filename = os.path.join(figpath, name) |
|
399 | ftp_filename = os.path.join(figpath, name) | |
394 | self.saveFigure(figpath, ftp_filename) |
|
400 | self.saveFigure(figpath, ftp_filename) | |
395 | self.counter_imagwr = 0 |
|
401 | self.counter_imagwr = 0 | |
396 |
|
402 | |||
397 |
|
403 | |||
398 | class RTIPlot(Figure): |
|
404 | class RTIPlot(Figure): | |
399 |
|
405 | |||
400 | isConfig = None |
|
406 | isConfig = None | |
401 | __nsubplots = None |
|
407 | __nsubplots = None | |
402 |
|
408 | |||
403 | WIDTHPROF = None |
|
409 | WIDTHPROF = None | |
404 | HEIGHTPROF = None |
|
410 | HEIGHTPROF = None | |
405 | PREFIX = 'rti' |
|
411 | PREFIX = 'rti' | |
406 |
|
412 | |||
407 | def __init__(self): |
|
413 | def __init__(self): | |
408 |
|
414 | |||
409 | self.timerange = 2*60*60 |
|
415 | self.timerange = 2*60*60 | |
410 | self.isConfig = False |
|
416 | self.isConfig = False | |
411 | self.__nsubplots = 1 |
|
417 | self.__nsubplots = 1 | |
412 |
|
418 | |||
413 | self.WIDTH = 800 |
|
419 | self.WIDTH = 800 | |
414 | self.HEIGHT = 150 |
|
420 | self.HEIGHT = 150 | |
415 | self.WIDTHPROF = 120 |
|
421 | self.WIDTHPROF = 120 | |
416 | self.HEIGHTPROF = 0 |
|
422 | self.HEIGHTPROF = 0 | |
417 | self.counter_imagwr = 0 |
|
423 | self.counter_imagwr = 0 | |
418 |
|
424 | |||
419 | self.PLOT_CODE = 0 |
|
425 | self.PLOT_CODE = 0 | |
420 | self.FTP_WEI = None |
|
426 | self.FTP_WEI = None | |
421 | self.EXP_CODE = None |
|
427 | self.EXP_CODE = None | |
422 | self.SUB_EXP_CODE = None |
|
428 | self.SUB_EXP_CODE = None | |
423 | self.PLOT_POS = None |
|
429 | self.PLOT_POS = None | |
424 | self.tmin = None |
|
430 | self.tmin = None | |
425 | self.tmax = None |
|
431 | self.tmax = None | |
426 |
|
432 | |||
427 | self.xmin = None |
|
433 | self.xmin = None | |
428 | self.xmax = None |
|
434 | self.xmax = None | |
429 |
|
435 | |||
430 | self.figfile = None |
|
436 | self.figfile = None | |
431 |
|
437 | |||
432 | def getSubplots(self): |
|
438 | def getSubplots(self): | |
433 |
|
439 | |||
434 | ncol = 1 |
|
440 | ncol = 1 | |
435 | nrow = self.nplots |
|
441 | nrow = self.nplots | |
436 |
|
442 | |||
437 | return nrow, ncol |
|
443 | return nrow, ncol | |
438 |
|
444 | |||
439 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
445 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
440 |
|
446 | |||
441 | self.__showprofile = showprofile |
|
447 | self.__showprofile = showprofile | |
442 | self.nplots = nplots |
|
448 | self.nplots = nplots | |
443 |
|
449 | |||
444 | ncolspan = 1 |
|
450 | ncolspan = 1 | |
445 | colspan = 1 |
|
451 | colspan = 1 | |
446 | if showprofile: |
|
452 | if showprofile: | |
447 | ncolspan = 7 |
|
453 | ncolspan = 7 | |
448 | colspan = 6 |
|
454 | colspan = 6 | |
449 | self.__nsubplots = 2 |
|
455 | self.__nsubplots = 2 | |
450 |
|
456 | |||
451 | self.createFigure(id = id, |
|
457 | self.createFigure(id = id, | |
452 | wintitle = wintitle, |
|
458 | wintitle = wintitle, | |
453 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
459 | widthplot = self.WIDTH + self.WIDTHPROF, | |
454 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
460 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
455 | show=show) |
|
461 | show=show) | |
456 |
|
462 | |||
457 | nrow, ncol = self.getSubplots() |
|
463 | nrow, ncol = self.getSubplots() | |
458 |
|
464 | |||
459 | counter = 0 |
|
465 | counter = 0 | |
460 | for y in range(nrow): |
|
466 | for y in range(nrow): | |
461 | for x in range(ncol): |
|
467 | for x in range(ncol): | |
462 |
|
468 | |||
463 | if counter >= self.nplots: |
|
469 | if counter >= self.nplots: | |
464 | break |
|
470 | break | |
465 |
|
471 | |||
466 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
472 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
467 |
|
473 | |||
468 | if showprofile: |
|
474 | if showprofile: | |
469 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
475 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
470 |
|
476 | |||
471 | counter += 1 |
|
477 | counter += 1 | |
472 |
|
478 | |||
473 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
479 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
474 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
480 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
475 | timerange=None, |
|
481 | timerange=None, | |
476 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, |
|
482 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
477 | server=None, folder=None, username=None, password=None, |
|
483 | server=None, folder=None, username=None, password=None, | |
478 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
484 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
479 |
|
485 | |||
480 | """ |
|
486 | """ | |
481 |
|
487 | |||
482 | Input: |
|
488 | Input: | |
483 | dataOut : |
|
489 | dataOut : | |
484 | id : |
|
490 | id : | |
485 | wintitle : |
|
491 | wintitle : | |
486 | channelList : |
|
492 | channelList : | |
487 | showProfile : |
|
493 | showProfile : | |
488 | xmin : None, |
|
494 | xmin : None, | |
489 | xmax : None, |
|
495 | xmax : None, | |
490 | ymin : None, |
|
496 | ymin : None, | |
491 | ymax : None, |
|
497 | ymax : None, | |
492 | zmin : None, |
|
498 | zmin : None, | |
493 | zmax : None |
|
499 | zmax : None | |
494 | """ |
|
500 | """ | |
495 |
|
501 | |||
496 | if channelList == None: |
|
502 | if channelList == None: | |
497 | channelIndexList = dataOut.channelIndexList |
|
503 | channelIndexList = dataOut.channelIndexList | |
498 | else: |
|
504 | else: | |
499 | channelIndexList = [] |
|
505 | channelIndexList = [] | |
500 | for channel in channelList: |
|
506 | for channel in channelList: | |
501 | if channel not in dataOut.channelList: |
|
507 | if channel not in dataOut.channelList: | |
502 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
508 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
503 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
509 | channelIndexList.append(dataOut.channelList.index(channel)) | |
504 |
|
510 | |||
505 | if timerange != None: |
|
511 | if timerange != None: | |
506 | self.timerange = timerange |
|
512 | self.timerange = timerange | |
507 |
|
513 | |||
508 | #tmin = None |
|
514 | #tmin = None | |
509 | #tmax = None |
|
515 | #tmax = None | |
510 | factor = dataOut.normFactor |
|
516 | factor = dataOut.normFactor | |
511 | x = dataOut.getTimeRange() |
|
517 | x = dataOut.getTimeRange() | |
512 | y = dataOut.getHeiRange() |
|
518 | y = dataOut.getHeiRange() | |
513 |
|
519 | |||
514 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
520 | z = dataOut.data_spc[channelIndexList,:,:]/factor | |
515 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
521 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
516 | avg = numpy.average(z, axis=1) |
|
522 | avg = numpy.average(z, axis=1) | |
517 |
|
523 | |||
518 | avgdB = 10.*numpy.log10(avg) |
|
524 | avgdB = 10.*numpy.log10(avg) | |
519 |
|
525 | |||
520 |
|
526 | |||
521 | # thisDatetime = dataOut.datatime |
|
527 | # thisDatetime = dataOut.datatime | |
522 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
528 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
523 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
529 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
524 | xlabel = "" |
|
530 | xlabel = "" | |
525 | ylabel = "Range (Km)" |
|
531 | ylabel = "Range (Km)" | |
526 |
|
532 | |||
527 | if not self.isConfig: |
|
533 | if not self.isConfig: | |
528 |
|
534 | |||
529 | nplots = len(channelIndexList) |
|
535 | nplots = len(channelIndexList) | |
530 |
|
536 | |||
531 | self.setup(id=id, |
|
537 | self.setup(id=id, | |
532 | nplots=nplots, |
|
538 | nplots=nplots, | |
533 | wintitle=wintitle, |
|
539 | wintitle=wintitle, | |
534 | showprofile=showprofile, |
|
540 | showprofile=showprofile, | |
535 | show=show) |
|
541 | show=show) | |
536 |
|
542 | |||
537 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
543 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
538 |
|
544 | |||
539 | # if timerange != None: |
|
545 | # if timerange != None: | |
540 | # self.timerange = timerange |
|
546 | # self.timerange = timerange | |
541 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
547 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) | |
542 |
|
548 | |||
543 |
|
549 | |||
544 |
|
550 | |||
545 | if ymin == None: ymin = numpy.nanmin(y) |
|
551 | if ymin == None: ymin = numpy.nanmin(y) | |
546 | if ymax == None: ymax = numpy.nanmax(y) |
|
552 | if ymax == None: ymax = numpy.nanmax(y) | |
547 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
553 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 | |
548 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
554 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 | |
549 |
|
555 | |||
550 | self.FTP_WEI = ftp_wei |
|
556 | self.FTP_WEI = ftp_wei | |
551 | self.EXP_CODE = exp_code |
|
557 | self.EXP_CODE = exp_code | |
552 | self.SUB_EXP_CODE = sub_exp_code |
|
558 | self.SUB_EXP_CODE = sub_exp_code | |
553 | self.PLOT_POS = plot_pos |
|
559 | self.PLOT_POS = plot_pos | |
554 |
|
560 | |||
555 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
561 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
556 | self.isConfig = True |
|
562 | self.isConfig = True | |
557 | self.figfile = figfile |
|
563 | self.figfile = figfile | |
558 |
|
564 | |||
559 | self.setWinTitle(title) |
|
565 | self.setWinTitle(title) | |
560 |
|
566 | |||
561 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
567 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
562 | x[1] = self.xmax |
|
568 | x[1] = self.xmax | |
563 |
|
569 | |||
564 | for i in range(self.nplots): |
|
570 | for i in range(self.nplots): | |
565 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
571 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
|
572 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |||
|
573 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) | |||
566 | axes = self.axesList[i*self.__nsubplots] |
|
574 | axes = self.axesList[i*self.__nsubplots] | |
567 | zdB = avgdB[i].reshape((1,-1)) |
|
575 | zdB = avgdB[i].reshape((1,-1)) | |
568 | axes.pcolorbuffer(x, y, zdB, |
|
576 | axes.pcolorbuffer(x, y, zdB, | |
569 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
577 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
570 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
578 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
571 | ticksize=9, cblabel='', cbsize="1%") |
|
579 | ticksize=9, cblabel='', cbsize="1%") | |
572 |
|
580 | |||
573 | if self.__showprofile: |
|
581 | if self.__showprofile: | |
574 | axes = self.axesList[i*self.__nsubplots +1] |
|
582 | axes = self.axesList[i*self.__nsubplots +1] | |
575 | axes.pline(avgdB[i], y, |
|
583 | axes.pline(avgdB[i], y, | |
576 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
584 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
577 | xlabel='dB', ylabel='', title='', |
|
585 | xlabel='dB', ylabel='', title='', | |
578 | ytick_visible=False, |
|
586 | ytick_visible=False, | |
579 | grid='x') |
|
587 | grid='x') | |
580 |
|
588 | |||
581 | self.draw() |
|
589 | self.draw() | |
582 |
|
590 | |||
583 | if x[1] >= self.axesList[0].xmax: |
|
591 | if x[1] >= self.axesList[0].xmax: | |
584 | self.counter_imagwr = wr_period |
|
592 | self.counter_imagwr = wr_period | |
585 | self.__isConfig = False |
|
593 | self.__isConfig = False | |
586 |
|
594 | |||
587 |
|
595 | |||
588 | if self.figfile == None: |
|
596 | if self.figfile == None: | |
589 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
597 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
590 | self.figfile = self.getFilename(name = str_datetime) |
|
598 | self.figfile = self.getFilename(name = str_datetime) | |
591 |
|
599 | |||
592 | if figpath != '': |
|
600 | if figpath != '': | |
593 |
|
601 | |||
594 | self.counter_imagwr += 1 |
|
602 | self.counter_imagwr += 1 | |
595 | if (self.counter_imagwr>=wr_period): |
|
603 | if (self.counter_imagwr>=wr_period): | |
596 | # store png plot to local folder |
|
604 | # store png plot to local folder | |
597 | self.saveFigure(figpath, self.figfile) |
|
605 | self.saveFigure(figpath, self.figfile) | |
598 | # store png plot to FTP server according to RT-Web format |
|
606 | # store png plot to FTP server according to RT-Web format | |
599 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
607 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
600 | ftp_filename = os.path.join(figpath, name) |
|
608 | ftp_filename = os.path.join(figpath, name) | |
601 | self.saveFigure(figpath, ftp_filename) |
|
609 | self.saveFigure(figpath, ftp_filename) | |
602 |
|
610 | |||
603 | self.counter_imagwr = 0 |
|
611 | self.counter_imagwr = 0 | |
604 |
|
612 | |||
605 |
|
613 | |||
606 | class CoherenceMap(Figure): |
|
614 | class CoherenceMap(Figure): | |
607 | isConfig = None |
|
615 | isConfig = None | |
608 | __nsubplots = None |
|
616 | __nsubplots = None | |
609 |
|
617 | |||
610 | WIDTHPROF = None |
|
618 | WIDTHPROF = None | |
611 | HEIGHTPROF = None |
|
619 | HEIGHTPROF = None | |
612 | PREFIX = 'cmap' |
|
620 | PREFIX = 'cmap' | |
613 |
|
621 | |||
614 | def __init__(self): |
|
622 | def __init__(self): | |
615 | self.timerange = 2*60*60 |
|
623 | self.timerange = 2*60*60 | |
616 | self.isConfig = False |
|
624 | self.isConfig = False | |
617 | self.__nsubplots = 1 |
|
625 | self.__nsubplots = 1 | |
618 |
|
626 | |||
619 | self.WIDTH = 800 |
|
627 | self.WIDTH = 800 | |
620 | self.HEIGHT = 150 |
|
628 | self.HEIGHT = 150 | |
621 | self.WIDTHPROF = 120 |
|
629 | self.WIDTHPROF = 120 | |
622 | self.HEIGHTPROF = 0 |
|
630 | self.HEIGHTPROF = 0 | |
623 | self.counter_imagwr = 0 |
|
631 | self.counter_imagwr = 0 | |
624 |
|
632 | |||
625 | self.PLOT_CODE = 3 |
|
633 | self.PLOT_CODE = 3 | |
626 | self.FTP_WEI = None |
|
634 | self.FTP_WEI = None | |
627 | self.EXP_CODE = None |
|
635 | self.EXP_CODE = None | |
628 | self.SUB_EXP_CODE = None |
|
636 | self.SUB_EXP_CODE = None | |
629 | self.PLOT_POS = None |
|
637 | self.PLOT_POS = None | |
630 | self.counter_imagwr = 0 |
|
638 | self.counter_imagwr = 0 | |
631 |
|
639 | |||
632 | self.xmin = None |
|
640 | self.xmin = None | |
633 | self.xmax = None |
|
641 | self.xmax = None | |
634 |
|
642 | |||
635 | def getSubplots(self): |
|
643 | def getSubplots(self): | |
636 | ncol = 1 |
|
644 | ncol = 1 | |
637 | nrow = self.nplots*2 |
|
645 | nrow = self.nplots*2 | |
638 |
|
646 | |||
639 | return nrow, ncol |
|
647 | return nrow, ncol | |
640 |
|
648 | |||
641 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
649 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
642 | self.__showprofile = showprofile |
|
650 | self.__showprofile = showprofile | |
643 | self.nplots = nplots |
|
651 | self.nplots = nplots | |
644 |
|
652 | |||
645 | ncolspan = 1 |
|
653 | ncolspan = 1 | |
646 | colspan = 1 |
|
654 | colspan = 1 | |
647 | if showprofile: |
|
655 | if showprofile: | |
648 | ncolspan = 7 |
|
656 | ncolspan = 7 | |
649 | colspan = 6 |
|
657 | colspan = 6 | |
650 | self.__nsubplots = 2 |
|
658 | self.__nsubplots = 2 | |
651 |
|
659 | |||
652 | self.createFigure(id = id, |
|
660 | self.createFigure(id = id, | |
653 | wintitle = wintitle, |
|
661 | wintitle = wintitle, | |
654 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
662 | widthplot = self.WIDTH + self.WIDTHPROF, | |
655 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
663 | heightplot = self.HEIGHT + self.HEIGHTPROF, | |
656 | show=True) |
|
664 | show=True) | |
657 |
|
665 | |||
658 | nrow, ncol = self.getSubplots() |
|
666 | nrow, ncol = self.getSubplots() | |
659 |
|
667 | |||
660 | for y in range(nrow): |
|
668 | for y in range(nrow): | |
661 | for x in range(ncol): |
|
669 | for x in range(ncol): | |
662 |
|
670 | |||
663 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
671 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
664 |
|
672 | |||
665 | if showprofile: |
|
673 | if showprofile: | |
666 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
674 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) | |
667 |
|
675 | |||
668 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
676 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
669 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
677 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, | |
670 | timerange=None, |
|
678 | timerange=None, | |
671 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, |
|
679 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, | |
672 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
680 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, | |
673 | server=None, folder=None, username=None, password=None, |
|
681 | server=None, folder=None, username=None, password=None, | |
674 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
682 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
675 |
|
683 | |||
676 | if pairsList == None: |
|
684 | if pairsList == None: | |
677 | pairsIndexList = dataOut.pairsIndexList |
|
685 | pairsIndexList = dataOut.pairsIndexList | |
678 | else: |
|
686 | else: | |
679 | pairsIndexList = [] |
|
687 | pairsIndexList = [] | |
680 | for pair in pairsList: |
|
688 | for pair in pairsList: | |
681 | if pair not in dataOut.pairsList: |
|
689 | if pair not in dataOut.pairsList: | |
682 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
690 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
683 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
691 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
684 |
|
692 | |||
685 | if timerange != None: |
|
693 | if timerange != None: | |
686 | self.timerange = timerange |
|
694 | self.timerange = timerange | |
687 |
|
695 | |||
688 | if pairsIndexList == []: |
|
696 | if pairsIndexList == []: | |
689 | return |
|
697 | return | |
690 |
|
698 | |||
691 | if len(pairsIndexList) > 4: |
|
699 | if len(pairsIndexList) > 4: | |
692 | pairsIndexList = pairsIndexList[0:4] |
|
700 | pairsIndexList = pairsIndexList[0:4] | |
693 |
|
701 | |||
694 | # tmin = None |
|
702 | # tmin = None | |
695 | # tmax = None |
|
703 | # tmax = None | |
696 | x = dataOut.getTimeRange() |
|
704 | x = dataOut.getTimeRange() | |
697 | y = dataOut.getHeiRange() |
|
705 | y = dataOut.getHeiRange() | |
698 |
|
706 | |||
699 | #thisDatetime = dataOut.datatime |
|
707 | #thisDatetime = dataOut.datatime | |
700 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
708 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
701 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
709 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
702 | xlabel = "" |
|
710 | xlabel = "" | |
703 | ylabel = "Range (Km)" |
|
711 | ylabel = "Range (Km)" | |
704 |
|
712 | |||
705 | if not self.isConfig: |
|
713 | if not self.isConfig: | |
706 | nplots = len(pairsIndexList) |
|
714 | nplots = len(pairsIndexList) | |
707 | self.setup(id=id, |
|
715 | self.setup(id=id, | |
708 | nplots=nplots, |
|
716 | nplots=nplots, | |
709 | wintitle=wintitle, |
|
717 | wintitle=wintitle, | |
710 | showprofile=showprofile, |
|
718 | showprofile=showprofile, | |
711 | show=show) |
|
719 | show=show) | |
712 |
|
720 | |||
713 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
721 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
714 |
|
722 | |||
715 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
723 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
716 |
|
724 | |||
717 | if ymin == None: ymin = numpy.nanmin(y) |
|
725 | if ymin == None: ymin = numpy.nanmin(y) | |
718 | if ymax == None: ymax = numpy.nanmax(y) |
|
726 | if ymax == None: ymax = numpy.nanmax(y) | |
719 | if zmin == None: zmin = 0. |
|
727 | if zmin == None: zmin = 0. | |
720 | if zmax == None: zmax = 1. |
|
728 | if zmax == None: zmax = 1. | |
721 |
|
729 | |||
722 | self.FTP_WEI = ftp_wei |
|
730 | self.FTP_WEI = ftp_wei | |
723 | self.EXP_CODE = exp_code |
|
731 | self.EXP_CODE = exp_code | |
724 | self.SUB_EXP_CODE = sub_exp_code |
|
732 | self.SUB_EXP_CODE = sub_exp_code | |
725 | self.PLOT_POS = plot_pos |
|
733 | self.PLOT_POS = plot_pos | |
726 |
|
734 | |||
727 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
735 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
728 |
|
736 | |||
729 | self.isConfig = True |
|
737 | self.isConfig = True | |
730 |
|
738 | |||
731 | self.setWinTitle(title) |
|
739 | self.setWinTitle(title) | |
732 |
|
740 | |||
733 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
741 | if ((self.xmax - x[1]) < (x[1]-x[0])): | |
734 | x[1] = self.xmax |
|
742 | x[1] = self.xmax | |
735 |
|
743 | |||
736 | for i in range(self.nplots): |
|
744 | for i in range(self.nplots): | |
737 |
|
745 | |||
738 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
746 | pair = dataOut.pairsList[pairsIndexList[i]] | |
739 |
|
747 | |||
740 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
748 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
741 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
749 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
742 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
750 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
743 |
|
751 | |||
744 |
|
752 | |||
745 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
753 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
746 | coherence = numpy.abs(avgcoherenceComplex) |
|
754 | coherence = numpy.abs(avgcoherenceComplex) | |
747 |
|
755 | |||
748 | z = coherence.reshape((1,-1)) |
|
756 | z = coherence.reshape((1,-1)) | |
749 |
|
757 | |||
750 | counter = 0 |
|
758 | counter = 0 | |
751 |
|
759 | |||
752 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
760 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
753 | axes = self.axesList[i*self.__nsubplots*2] |
|
761 | axes = self.axesList[i*self.__nsubplots*2] | |
754 | axes.pcolorbuffer(x, y, z, |
|
762 | axes.pcolorbuffer(x, y, z, | |
755 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
763 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, | |
756 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
764 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
757 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
765 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") | |
758 |
|
766 | |||
759 | if self.__showprofile: |
|
767 | if self.__showprofile: | |
760 | counter += 1 |
|
768 | counter += 1 | |
761 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
769 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
762 | axes.pline(coherence, y, |
|
770 | axes.pline(coherence, y, | |
763 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
771 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, | |
764 | xlabel='', ylabel='', title='', ticksize=7, |
|
772 | xlabel='', ylabel='', title='', ticksize=7, | |
765 | ytick_visible=False, nxticks=5, |
|
773 | ytick_visible=False, nxticks=5, | |
766 | grid='x') |
|
774 | grid='x') | |
767 |
|
775 | |||
768 | counter += 1 |
|
776 | counter += 1 | |
769 |
|
777 | |||
770 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
778 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
771 |
|
779 | |||
772 | z = phase.reshape((1,-1)) |
|
780 | z = phase.reshape((1,-1)) | |
773 |
|
781 | |||
774 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
782 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
775 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
783 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
776 | axes.pcolorbuffer(x, y, z, |
|
784 | axes.pcolorbuffer(x, y, z, | |
777 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
785 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, | |
778 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
786 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, | |
779 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
787 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") | |
780 |
|
788 | |||
781 | if self.__showprofile: |
|
789 | if self.__showprofile: | |
782 | counter += 1 |
|
790 | counter += 1 | |
783 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
791 | axes = self.axesList[i*self.__nsubplots*2 + counter] | |
784 | axes.pline(phase, y, |
|
792 | axes.pline(phase, y, | |
785 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
793 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, | |
786 | xlabel='', ylabel='', title='', ticksize=7, |
|
794 | xlabel='', ylabel='', title='', ticksize=7, | |
787 | ytick_visible=False, nxticks=4, |
|
795 | ytick_visible=False, nxticks=4, | |
788 | grid='x') |
|
796 | grid='x') | |
789 |
|
797 | |||
790 | self.draw() |
|
798 | self.draw() | |
791 |
|
799 | |||
792 | if x[1] >= self.axesList[0].xmax: |
|
800 | if x[1] >= self.axesList[0].xmax: | |
793 | self.counter_imagwr = wr_period |
|
801 | self.counter_imagwr = wr_period | |
794 | self.__isConfig = False |
|
802 | self.__isConfig = False | |
795 |
|
803 | |||
796 | if figfile == None: |
|
804 | if figfile == None: | |
797 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
805 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
798 | figfile = self.getFilename(name = str_datetime) |
|
806 | figfile = self.getFilename(name = str_datetime) | |
799 |
|
807 | |||
800 | if figpath != '': |
|
808 | if figpath != '': | |
801 |
|
809 | |||
802 | self.counter_imagwr += 1 |
|
810 | self.counter_imagwr += 1 | |
803 | if (self.counter_imagwr>=wr_period): |
|
811 | if (self.counter_imagwr>=wr_period): | |
804 | # store png plot to local folder |
|
812 | # store png plot to local folder | |
805 | self.saveFigure(figpath, figfile) |
|
813 | self.saveFigure(figpath, figfile) | |
806 | # store png plot to FTP server according to RT-Web format |
|
814 | # store png plot to FTP server according to RT-Web format | |
807 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
815 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
808 | ftp_filename = os.path.join(figpath, name) |
|
816 | ftp_filename = os.path.join(figpath, name) | |
809 | self.saveFigure(figpath, ftp_filename) |
|
817 | self.saveFigure(figpath, ftp_filename) | |
810 |
|
818 | |||
811 | self.counter_imagwr = 0 |
|
819 | self.counter_imagwr = 0 | |
812 |
|
820 | |||
813 | class PowerProfile(Figure): |
|
821 | class PowerProfile(Figure): | |
814 | isConfig = None |
|
822 | isConfig = None | |
815 | __nsubplots = None |
|
823 | __nsubplots = None | |
816 |
|
824 | |||
817 | WIDTHPROF = None |
|
825 | WIDTHPROF = None | |
818 | HEIGHTPROF = None |
|
826 | HEIGHTPROF = None | |
819 | PREFIX = 'spcprofile' |
|
827 | PREFIX = 'spcprofile' | |
820 |
|
828 | |||
821 | def __init__(self): |
|
829 | def __init__(self): | |
822 | self.isConfig = False |
|
830 | self.isConfig = False | |
823 | self.__nsubplots = 1 |
|
831 | self.__nsubplots = 1 | |
824 |
|
832 | |||
825 | self.WIDTH = 300 |
|
833 | self.WIDTH = 300 | |
826 | self.HEIGHT = 500 |
|
834 | self.HEIGHT = 500 | |
827 | self.counter_imagwr = 0 |
|
835 | self.counter_imagwr = 0 | |
828 |
|
836 | |||
829 | def getSubplots(self): |
|
837 | def getSubplots(self): | |
830 | ncol = 1 |
|
838 | ncol = 1 | |
831 | nrow = 1 |
|
839 | nrow = 1 | |
832 |
|
840 | |||
833 | return nrow, ncol |
|
841 | return nrow, ncol | |
834 |
|
842 | |||
835 | def setup(self, id, nplots, wintitle, show): |
|
843 | def setup(self, id, nplots, wintitle, show): | |
836 |
|
844 | |||
837 | self.nplots = nplots |
|
845 | self.nplots = nplots | |
838 |
|
846 | |||
839 | ncolspan = 1 |
|
847 | ncolspan = 1 | |
840 | colspan = 1 |
|
848 | colspan = 1 | |
841 |
|
849 | |||
842 | self.createFigure(id = id, |
|
850 | self.createFigure(id = id, | |
843 | wintitle = wintitle, |
|
851 | wintitle = wintitle, | |
844 | widthplot = self.WIDTH, |
|
852 | widthplot = self.WIDTH, | |
845 | heightplot = self.HEIGHT, |
|
853 | heightplot = self.HEIGHT, | |
846 | show=show) |
|
854 | show=show) | |
847 |
|
855 | |||
848 | nrow, ncol = self.getSubplots() |
|
856 | nrow, ncol = self.getSubplots() | |
849 |
|
857 | |||
850 | counter = 0 |
|
858 | counter = 0 | |
851 | for y in range(nrow): |
|
859 | for y in range(nrow): | |
852 | for x in range(ncol): |
|
860 | for x in range(ncol): | |
853 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
861 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) | |
854 |
|
862 | |||
855 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
863 | def run(self, dataOut, id, wintitle="", channelList=None, | |
856 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
864 | xmin=None, xmax=None, ymin=None, ymax=None, | |
857 | save=False, figpath='', figfile=None, show=True, wr_period=1, |
|
865 | save=False, figpath='', figfile=None, show=True, wr_period=1, | |
858 | server=None, folder=None, username=None, password=None,): |
|
866 | server=None, folder=None, username=None, password=None,): | |
859 |
|
867 | |||
860 | if dataOut.flagNoData: |
|
868 | if dataOut.flagNoData: | |
861 | return None |
|
869 | return None | |
862 |
|
870 | |||
863 | if channelList == None: |
|
871 | if channelList == None: | |
864 | channelIndexList = dataOut.channelIndexList |
|
872 | channelIndexList = dataOut.channelIndexList | |
865 | channelList = dataOut.channelList |
|
873 | channelList = dataOut.channelList | |
866 | else: |
|
874 | else: | |
867 | channelIndexList = [] |
|
875 | channelIndexList = [] | |
868 | for channel in channelList: |
|
876 | for channel in channelList: | |
869 | if channel not in dataOut.channelList: |
|
877 | if channel not in dataOut.channelList: | |
870 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
878 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
871 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
879 | channelIndexList.append(dataOut.channelList.index(channel)) | |
872 |
|
880 | |||
873 | try: |
|
881 | try: | |
874 | factor = dataOut.normFactor |
|
882 | factor = dataOut.normFactor | |
875 | except: |
|
883 | except: | |
876 | factor = 1 |
|
884 | factor = 1 | |
877 |
|
885 | |||
878 | y = dataOut.getHeiRange() |
|
886 | y = dataOut.getHeiRange() | |
879 |
|
887 | |||
880 | #for voltage |
|
888 | #for voltage | |
881 | if dataOut.type == 'Voltage': |
|
889 | if dataOut.type == 'Voltage': | |
882 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
890 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) | |
883 | x = x.real |
|
891 | x = x.real | |
884 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
892 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
885 |
|
893 | |||
886 | #for spectra |
|
894 | #for spectra | |
887 | if dataOut.type == 'Spectra': |
|
895 | if dataOut.type == 'Spectra': | |
888 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
896 | x = dataOut.data_spc[channelIndexList,:,:]/factor | |
889 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
897 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) | |
890 | x = numpy.average(x, axis=1) |
|
898 | x = numpy.average(x, axis=1) | |
891 |
|
899 | |||
892 |
|
900 | |||
893 | xdB = 10*numpy.log10(x) |
|
901 | xdB = 10*numpy.log10(x) | |
894 |
|
902 | |||
895 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
903 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
896 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
904 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
897 | xlabel = "dB" |
|
905 | xlabel = "dB" | |
898 | ylabel = "Range (Km)" |
|
906 | ylabel = "Range (Km)" | |
899 |
|
907 | |||
900 | if not self.isConfig: |
|
908 | if not self.isConfig: | |
901 |
|
909 | |||
902 | nplots = 1 |
|
910 | nplots = 1 | |
903 |
|
911 | |||
904 | self.setup(id=id, |
|
912 | self.setup(id=id, | |
905 | nplots=nplots, |
|
913 | nplots=nplots, | |
906 | wintitle=wintitle, |
|
914 | wintitle=wintitle, | |
907 | show=show) |
|
915 | show=show) | |
908 |
|
916 | |||
909 | if ymin == None: ymin = numpy.nanmin(y) |
|
917 | if ymin == None: ymin = numpy.nanmin(y) | |
910 | if ymax == None: ymax = numpy.nanmax(y) |
|
918 | if ymax == None: ymax = numpy.nanmax(y) | |
911 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
919 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 | |
912 | if xmax == None: xmax = numpy.nanmax(xdB)*0.9 |
|
920 | if xmax == None: xmax = numpy.nanmax(xdB)*0.9 | |
913 |
|
921 | |||
914 | self.__isConfig = True |
|
922 | self.__isConfig = True | |
915 |
|
923 | |||
916 | self.setWinTitle(title) |
|
924 | self.setWinTitle(title) | |
917 |
|
925 | |||
918 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
926 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) | |
919 | axes = self.axesList[0] |
|
927 | axes = self.axesList[0] | |
920 |
|
928 | |||
921 | legendlabels = ["channel %d"%x for x in channelList] |
|
929 | legendlabels = ["channel %d"%x for x in channelList] | |
922 | axes.pmultiline(xdB, y, |
|
930 | axes.pmultiline(xdB, y, | |
923 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
931 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, | |
924 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
932 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, | |
925 | ytick_visible=True, nxticks=5, |
|
933 | ytick_visible=True, nxticks=5, | |
926 | grid='x') |
|
934 | grid='x') | |
927 |
|
935 | |||
928 | self.draw() |
|
936 | self.draw() | |
929 |
|
937 | |||
930 | if figfile == None: |
|
938 | if figfile == None: | |
931 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
939 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
932 | figfile = self.getFilename(name = str_datetime) |
|
940 | figfile = self.getFilename(name = str_datetime) | |
933 |
|
941 | |||
934 | if figpath != '': |
|
942 | if figpath != '': | |
935 | self.counter_imagwr += 1 |
|
943 | self.counter_imagwr += 1 | |
936 | if (self.counter_imagwr>=wr_period): |
|
944 | if (self.counter_imagwr>=wr_period): | |
937 | # store png plot to local folder |
|
945 | # store png plot to local folder | |
938 | self.saveFigure(figpath, figfile) |
|
946 | self.saveFigure(figpath, figfile) | |
939 | # store png plot to FTP server according to RT-Web format |
|
947 | # store png plot to FTP server according to RT-Web format | |
940 | #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
948 | #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
941 | #ftp_filename = os.path.join(figpath, name) |
|
949 | #ftp_filename = os.path.join(figpath, name) | |
942 | #self.saveFigure(figpath, ftp_filename) |
|
950 | #self.saveFigure(figpath, ftp_filename) | |
943 | self.counter_imagwr = 0 |
|
951 | self.counter_imagwr = 0 | |
944 |
|
952 | |||
945 |
|
953 | |||
946 |
|
954 | |||
947 | class Noise(Figure): |
|
955 | class Noise(Figure): | |
948 |
|
956 | |||
949 | isConfig = None |
|
957 | isConfig = None | |
950 | __nsubplots = None |
|
958 | __nsubplots = None | |
951 |
|
959 | |||
952 | PREFIX = 'noise' |
|
960 | PREFIX = 'noise' | |
953 |
|
961 | |||
954 | def __init__(self): |
|
962 | def __init__(self): | |
955 |
|
963 | |||
956 | self.timerange = 24*60*60 |
|
964 | self.timerange = 24*60*60 | |
957 | self.isConfig = False |
|
965 | self.isConfig = False | |
958 | self.__nsubplots = 1 |
|
966 | self.__nsubplots = 1 | |
959 | self.counter_imagwr = 0 |
|
967 | self.counter_imagwr = 0 | |
960 | self.WIDTH = 600 |
|
968 | self.WIDTH = 600 | |
961 | self.HEIGHT = 300 |
|
969 | self.HEIGHT = 300 | |
962 | self.WIDTHPROF = 120 |
|
970 | self.WIDTHPROF = 120 | |
963 | self.HEIGHTPROF = 0 |
|
971 | self.HEIGHTPROF = 0 | |
964 | self.xdata = None |
|
972 | self.xdata = None | |
965 | self.ydata = None |
|
973 | self.ydata = None | |
966 |
|
974 | |||
967 | self.PLOT_CODE = 17 |
|
975 | self.PLOT_CODE = 17 | |
968 | self.FTP_WEI = None |
|
976 | self.FTP_WEI = None | |
969 | self.EXP_CODE = None |
|
977 | self.EXP_CODE = None | |
970 | self.SUB_EXP_CODE = None |
|
978 | self.SUB_EXP_CODE = None | |
971 | self.PLOT_POS = None |
|
979 | self.PLOT_POS = None | |
972 | self.figfile = None |
|
980 | self.figfile = None | |
973 |
|
981 | |||
974 | def getSubplots(self): |
|
982 | def getSubplots(self): | |
975 |
|
983 | |||
976 | ncol = 1 |
|
984 | ncol = 1 | |
977 | nrow = 1 |
|
985 | nrow = 1 | |
978 |
|
986 | |||
979 | return nrow, ncol |
|
987 | return nrow, ncol | |
980 |
|
988 | |||
981 | def openfile(self, filename): |
|
989 | def openfile(self, filename): | |
982 | f = open(filename,'w+') |
|
990 | f = open(filename,'w+') | |
983 | f.write('\n\n') |
|
991 | f.write('\n\n') | |
984 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
992 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') | |
985 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
993 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) | |
986 | f.close() |
|
994 | f.close() | |
987 |
|
995 | |||
988 | def save_data(self, filename_phase, data, data_datetime): |
|
996 | def save_data(self, filename_phase, data, data_datetime): | |
989 | f=open(filename_phase,'a') |
|
997 | f=open(filename_phase,'a') | |
990 | timetuple_data = data_datetime.timetuple() |
|
998 | timetuple_data = data_datetime.timetuple() | |
991 | day = str(timetuple_data.tm_mday) |
|
999 | day = str(timetuple_data.tm_mday) | |
992 | month = str(timetuple_data.tm_mon) |
|
1000 | month = str(timetuple_data.tm_mon) | |
993 | year = str(timetuple_data.tm_year) |
|
1001 | year = str(timetuple_data.tm_year) | |
994 | hour = str(timetuple_data.tm_hour) |
|
1002 | hour = str(timetuple_data.tm_hour) | |
995 | minute = str(timetuple_data.tm_min) |
|
1003 | minute = str(timetuple_data.tm_min) | |
996 | second = str(timetuple_data.tm_sec) |
|
1004 | second = str(timetuple_data.tm_sec) | |
997 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1005 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
998 | f.close() |
|
1006 | f.close() | |
999 |
|
1007 | |||
1000 |
|
1008 | |||
1001 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1009 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1002 |
|
1010 | |||
1003 | self.__showprofile = showprofile |
|
1011 | self.__showprofile = showprofile | |
1004 | self.nplots = nplots |
|
1012 | self.nplots = nplots | |
1005 |
|
1013 | |||
1006 | ncolspan = 7 |
|
1014 | ncolspan = 7 | |
1007 | colspan = 6 |
|
1015 | colspan = 6 | |
1008 | self.__nsubplots = 2 |
|
1016 | self.__nsubplots = 2 | |
1009 |
|
1017 | |||
1010 | self.createFigure(id = id, |
|
1018 | self.createFigure(id = id, | |
1011 | wintitle = wintitle, |
|
1019 | wintitle = wintitle, | |
1012 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1020 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1013 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1021 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1014 | show=show) |
|
1022 | show=show) | |
1015 |
|
1023 | |||
1016 | nrow, ncol = self.getSubplots() |
|
1024 | nrow, ncol = self.getSubplots() | |
1017 |
|
1025 | |||
1018 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1026 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1019 |
|
1027 | |||
1020 |
|
1028 | |||
1021 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1029 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', | |
1022 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1030 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1023 | timerange=None, |
|
1031 | timerange=None, | |
1024 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
1032 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
1025 | server=None, folder=None, username=None, password=None, |
|
1033 | server=None, folder=None, username=None, password=None, | |
1026 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1034 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1027 |
|
1035 | |||
1028 | if channelList == None: |
|
1036 | if channelList == None: | |
1029 | channelIndexList = dataOut.channelIndexList |
|
1037 | channelIndexList = dataOut.channelIndexList | |
1030 | channelList = dataOut.channelList |
|
1038 | channelList = dataOut.channelList | |
1031 | else: |
|
1039 | else: | |
1032 | channelIndexList = [] |
|
1040 | channelIndexList = [] | |
1033 | for channel in channelList: |
|
1041 | for channel in channelList: | |
1034 | if channel not in dataOut.channelList: |
|
1042 | if channel not in dataOut.channelList: | |
1035 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1043 | raise ValueError, "Channel %d is not in dataOut.channelList" | |
1036 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1044 | channelIndexList.append(dataOut.channelList.index(channel)) | |
1037 |
|
1045 | |||
1038 | if timerange != None: |
|
1046 | if timerange != None: | |
1039 | self.timerange = timerange |
|
1047 | self.timerange = timerange | |
1040 |
|
1048 | |||
1041 | tmin = None |
|
1049 | tmin = None | |
1042 | tmax = None |
|
1050 | tmax = None | |
1043 | x = dataOut.getTimeRange() |
|
1051 | x = dataOut.getTimeRange() | |
1044 | y = dataOut.getHeiRange() |
|
1052 | y = dataOut.getHeiRange() | |
1045 | factor = dataOut.normFactor |
|
1053 | factor = dataOut.normFactor | |
1046 | noise = dataOut.noise()/factor |
|
1054 | noise = dataOut.noise()/factor | |
1047 | noisedB = 10*numpy.log10(noise) |
|
1055 | noisedB = 10*numpy.log10(noise) | |
1048 |
|
1056 | |||
1049 | #thisDatetime = dataOut.datatime |
|
1057 | #thisDatetime = dataOut.datatime | |
1050 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1058 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1051 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1059 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1052 | xlabel = "" |
|
1060 | xlabel = "" | |
1053 | ylabel = "Intensity (dB)" |
|
1061 | ylabel = "Intensity (dB)" | |
1054 |
|
1062 | |||
1055 | if not self.isConfig: |
|
1063 | if not self.isConfig: | |
1056 |
|
1064 | |||
1057 | nplots = 1 |
|
1065 | nplots = 1 | |
1058 |
|
1066 | |||
1059 | self.setup(id=id, |
|
1067 | self.setup(id=id, | |
1060 | nplots=nplots, |
|
1068 | nplots=nplots, | |
1061 | wintitle=wintitle, |
|
1069 | wintitle=wintitle, | |
1062 | showprofile=showprofile, |
|
1070 | showprofile=showprofile, | |
1063 | show=show) |
|
1071 | show=show) | |
1064 |
|
1072 | |||
1065 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1073 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1066 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 |
|
1074 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 | |
1067 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1075 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 | |
1068 |
|
1076 | |||
1069 | self.FTP_WEI = ftp_wei |
|
1077 | self.FTP_WEI = ftp_wei | |
1070 | self.EXP_CODE = exp_code |
|
1078 | self.EXP_CODE = exp_code | |
1071 | self.SUB_EXP_CODE = sub_exp_code |
|
1079 | self.SUB_EXP_CODE = sub_exp_code | |
1072 | self.PLOT_POS = plot_pos |
|
1080 | self.PLOT_POS = plot_pos | |
1073 |
|
1081 | |||
1074 |
|
1082 | |||
1075 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1083 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1076 | self.isConfig = True |
|
1084 | self.isConfig = True | |
1077 | self.figfile = figfile |
|
1085 | self.figfile = figfile | |
1078 | self.xdata = numpy.array([]) |
|
1086 | self.xdata = numpy.array([]) | |
1079 | self.ydata = numpy.array([]) |
|
1087 | self.ydata = numpy.array([]) | |
1080 |
|
1088 | |||
1081 | #open file beacon phase |
|
1089 | #open file beacon phase | |
1082 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1090 | path = '%s%03d' %(self.PREFIX, self.id) | |
1083 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1091 | noise_file = os.path.join(path,'%s.txt'%self.name) | |
1084 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1092 | self.filename_noise = os.path.join(figpath,noise_file) | |
1085 | self.openfile(self.filename_noise) |
|
1093 | self.openfile(self.filename_noise) | |
1086 |
|
1094 | |||
1087 |
|
1095 | |||
1088 | #store data beacon phase |
|
1096 | #store data beacon phase | |
1089 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1097 | self.save_data(self.filename_noise, noisedB, thisDatetime) | |
1090 |
|
1098 | |||
1091 |
|
1099 | |||
1092 | self.setWinTitle(title) |
|
1100 | self.setWinTitle(title) | |
1093 |
|
1101 | |||
1094 |
|
1102 | |||
1095 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1103 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1096 |
|
1104 | |||
1097 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1105 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] | |
1098 | axes = self.axesList[0] |
|
1106 | axes = self.axesList[0] | |
1099 |
|
1107 | |||
1100 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1108 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1101 |
|
1109 | |||
1102 | if len(self.ydata)==0: |
|
1110 | if len(self.ydata)==0: | |
1103 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1111 | self.ydata = noisedB[channelIndexList].reshape(-1,1) | |
1104 | else: |
|
1112 | else: | |
1105 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1113 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) | |
1106 |
|
1114 | |||
1107 |
|
1115 | |||
1108 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1116 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1109 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1117 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1110 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1118 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1111 | XAxisAsTime=True, grid='both' |
|
1119 | XAxisAsTime=True, grid='both' | |
1112 | ) |
|
1120 | ) | |
1113 |
|
1121 | |||
1114 | self.draw() |
|
1122 | self.draw() | |
1115 |
|
1123 | |||
1116 | if x[1] >= self.axesList[0].xmax: |
|
1124 | if x[1] >= self.axesList[0].xmax: | |
1117 | self.counter_imagwr = wr_period |
|
1125 | self.counter_imagwr = wr_period | |
1118 | del self.xdata |
|
1126 | del self.xdata | |
1119 | del self.ydata |
|
1127 | del self.ydata | |
1120 | self.__isConfig = False |
|
1128 | self.__isConfig = False | |
1121 |
|
1129 | |||
1122 | if self.figfile == None: |
|
1130 | if self.figfile == None: | |
1123 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1131 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1124 | self.figfile = self.getFilename(name = str_datetime) |
|
1132 | self.figfile = self.getFilename(name = str_datetime) | |
1125 |
|
1133 | |||
1126 | if figpath != '': |
|
1134 | if figpath != '': | |
1127 | self.counter_imagwr += 1 |
|
1135 | self.counter_imagwr += 1 | |
1128 | if (self.counter_imagwr>=wr_period): |
|
1136 | if (self.counter_imagwr>=wr_period): | |
1129 | # store png plot to local folder |
|
1137 | # store png plot to local folder | |
1130 | self.saveFigure(figpath, self.figfile) |
|
1138 | self.saveFigure(figpath, self.figfile) | |
1131 | # store png plot to FTP server according to RT-Web format |
|
1139 | # store png plot to FTP server according to RT-Web format | |
1132 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1140 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1133 | ftp_filename = os.path.join(figpath, name) |
|
1141 | ftp_filename = os.path.join(figpath, name) | |
1134 | self.saveFigure(figpath, ftp_filename) |
|
1142 | self.saveFigure(figpath, ftp_filename) | |
1135 | self.counter_imagwr = 0 |
|
1143 | self.counter_imagwr = 0 | |
1136 |
|
1144 | |||
1137 |
|
1145 | |||
1138 | class BeaconPhase(Figure): |
|
1146 | class BeaconPhase(Figure): | |
1139 |
|
1147 | |||
1140 | __isConfig = None |
|
1148 | __isConfig = None | |
1141 | __nsubplots = None |
|
1149 | __nsubplots = None | |
1142 |
|
1150 | |||
1143 | PREFIX = 'beacon_phase' |
|
1151 | PREFIX = 'beacon_phase' | |
1144 |
|
1152 | |||
1145 | def __init__(self): |
|
1153 | def __init__(self): | |
1146 |
|
1154 | |||
1147 | self.timerange = 24*60*60 |
|
1155 | self.timerange = 24*60*60 | |
1148 | self.__isConfig = False |
|
1156 | self.__isConfig = False | |
1149 | self.__nsubplots = 1 |
|
1157 | self.__nsubplots = 1 | |
1150 | self.counter_imagwr = 0 |
|
1158 | self.counter_imagwr = 0 | |
1151 | self.WIDTH = 600 |
|
1159 | self.WIDTH = 600 | |
1152 | self.HEIGHT = 300 |
|
1160 | self.HEIGHT = 300 | |
1153 | self.WIDTHPROF = 120 |
|
1161 | self.WIDTHPROF = 120 | |
1154 | self.HEIGHTPROF = 0 |
|
1162 | self.HEIGHTPROF = 0 | |
1155 | self.xdata = None |
|
1163 | self.xdata = None | |
1156 | self.ydata = None |
|
1164 | self.ydata = None | |
1157 |
|
1165 | |||
1158 | self.PLOT_CODE = 18 |
|
1166 | self.PLOT_CODE = 18 | |
1159 | self.FTP_WEI = None |
|
1167 | self.FTP_WEI = None | |
1160 | self.EXP_CODE = None |
|
1168 | self.EXP_CODE = None | |
1161 | self.SUB_EXP_CODE = None |
|
1169 | self.SUB_EXP_CODE = None | |
1162 | self.PLOT_POS = None |
|
1170 | self.PLOT_POS = None | |
1163 |
|
1171 | |||
1164 | self.filename_phase = None |
|
1172 | self.filename_phase = None | |
1165 |
|
1173 | |||
1166 | self.figfile = None |
|
1174 | self.figfile = None | |
1167 |
|
1175 | |||
1168 | def getSubplots(self): |
|
1176 | def getSubplots(self): | |
1169 |
|
1177 | |||
1170 | ncol = 1 |
|
1178 | ncol = 1 | |
1171 | nrow = 1 |
|
1179 | nrow = 1 | |
1172 |
|
1180 | |||
1173 | return nrow, ncol |
|
1181 | return nrow, ncol | |
1174 |
|
1182 | |||
1175 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1183 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): | |
1176 |
|
1184 | |||
1177 | self.__showprofile = showprofile |
|
1185 | self.__showprofile = showprofile | |
1178 | self.nplots = nplots |
|
1186 | self.nplots = nplots | |
1179 |
|
1187 | |||
1180 | ncolspan = 7 |
|
1188 | ncolspan = 7 | |
1181 | colspan = 6 |
|
1189 | colspan = 6 | |
1182 | self.__nsubplots = 2 |
|
1190 | self.__nsubplots = 2 | |
1183 |
|
1191 | |||
1184 | self.createFigure(id = id, |
|
1192 | self.createFigure(id = id, | |
1185 | wintitle = wintitle, |
|
1193 | wintitle = wintitle, | |
1186 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1194 | widthplot = self.WIDTH+self.WIDTHPROF, | |
1187 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1195 | heightplot = self.HEIGHT+self.HEIGHTPROF, | |
1188 | show=show) |
|
1196 | show=show) | |
1189 |
|
1197 | |||
1190 | nrow, ncol = self.getSubplots() |
|
1198 | nrow, ncol = self.getSubplots() | |
1191 |
|
1199 | |||
1192 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1200 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) | |
1193 |
|
1201 | |||
1194 | def save_phase(self, filename_phase): |
|
1202 | def save_phase(self, filename_phase): | |
1195 | f = open(filename_phase,'w+') |
|
1203 | f = open(filename_phase,'w+') | |
1196 | f.write('\n\n') |
|
1204 | f.write('\n\n') | |
1197 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1205 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') | |
1198 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1206 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) | |
1199 | f.close() |
|
1207 | f.close() | |
1200 |
|
1208 | |||
1201 | def save_data(self, filename_phase, data, data_datetime): |
|
1209 | def save_data(self, filename_phase, data, data_datetime): | |
1202 | f=open(filename_phase,'a') |
|
1210 | f=open(filename_phase,'a') | |
1203 | timetuple_data = data_datetime.timetuple() |
|
1211 | timetuple_data = data_datetime.timetuple() | |
1204 | day = str(timetuple_data.tm_mday) |
|
1212 | day = str(timetuple_data.tm_mday) | |
1205 | month = str(timetuple_data.tm_mon) |
|
1213 | month = str(timetuple_data.tm_mon) | |
1206 | year = str(timetuple_data.tm_year) |
|
1214 | year = str(timetuple_data.tm_year) | |
1207 | hour = str(timetuple_data.tm_hour) |
|
1215 | hour = str(timetuple_data.tm_hour) | |
1208 | minute = str(timetuple_data.tm_min) |
|
1216 | minute = str(timetuple_data.tm_min) | |
1209 | second = str(timetuple_data.tm_sec) |
|
1217 | second = str(timetuple_data.tm_sec) | |
1210 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1218 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') | |
1211 | f.close() |
|
1219 | f.close() | |
1212 |
|
1220 | |||
1213 |
|
1221 | |||
1214 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1222 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', | |
1215 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1223 | xmin=None, xmax=None, ymin=None, ymax=None, | |
1216 | timerange=None, |
|
1224 | timerange=None, | |
1217 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, |
|
1225 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
1218 | server=None, folder=None, username=None, password=None, |
|
1226 | server=None, folder=None, username=None, password=None, | |
1219 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1227 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): | |
1220 |
|
1228 | |||
1221 | if pairsList == None: |
|
1229 | if pairsList == None: | |
1222 | pairsIndexList = dataOut.pairsIndexList |
|
1230 | pairsIndexList = dataOut.pairsIndexList | |
1223 | else: |
|
1231 | else: | |
1224 | pairsIndexList = [] |
|
1232 | pairsIndexList = [] | |
1225 | for pair in pairsList: |
|
1233 | for pair in pairsList: | |
1226 | if pair not in dataOut.pairsList: |
|
1234 | if pair not in dataOut.pairsList: | |
1227 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1235 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
1228 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1236 | pairsIndexList.append(dataOut.pairsList.index(pair)) | |
1229 |
|
1237 | |||
1230 | if pairsIndexList == []: |
|
1238 | if pairsIndexList == []: | |
1231 | return |
|
1239 | return | |
1232 |
|
1240 | |||
1233 | # if len(pairsIndexList) > 4: |
|
1241 | # if len(pairsIndexList) > 4: | |
1234 | # pairsIndexList = pairsIndexList[0:4] |
|
1242 | # pairsIndexList = pairsIndexList[0:4] | |
1235 |
|
1243 | |||
1236 | if timerange != None: |
|
1244 | if timerange != None: | |
1237 | self.timerange = timerange |
|
1245 | self.timerange = timerange | |
1238 |
|
1246 | |||
1239 | tmin = None |
|
1247 | tmin = None | |
1240 | tmax = None |
|
1248 | tmax = None | |
1241 | x = dataOut.getTimeRange() |
|
1249 | x = dataOut.getTimeRange() | |
1242 | y = dataOut.getHeiRange() |
|
1250 | y = dataOut.getHeiRange() | |
1243 |
|
1251 | |||
1244 |
|
1252 | |||
1245 | #thisDatetime = dataOut.datatime |
|
1253 | #thisDatetime = dataOut.datatime | |
1246 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) |
|
1254 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
1247 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1255 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) | |
1248 | xlabel = "Local Time" |
|
1256 | xlabel = "Local Time" | |
1249 | ylabel = "Phase" |
|
1257 | ylabel = "Phase" | |
1250 |
|
1258 | |||
1251 | nplots = len(pairsIndexList) |
|
1259 | nplots = len(pairsIndexList) | |
1252 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1260 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) | |
1253 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1261 | phase_beacon = numpy.zeros(len(pairsIndexList)) | |
1254 | for i in range(nplots): |
|
1262 | for i in range(nplots): | |
1255 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1263 | pair = dataOut.pairsList[pairsIndexList[i]] | |
1256 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1264 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) | |
1257 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1265 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) | |
1258 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1266 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) | |
1259 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1267 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) | |
1260 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1268 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi | |
1261 |
|
1269 | |||
1262 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1270 | #print "Phase %d%d" %(pair[0], pair[1]) | |
1263 | #print phase[dataOut.beacon_heiIndexList] |
|
1271 | #print phase[dataOut.beacon_heiIndexList] | |
1264 |
|
1272 | |||
1265 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1273 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) | |
1266 |
|
1274 | |||
1267 | if not self.__isConfig: |
|
1275 | if not self.__isConfig: | |
1268 |
|
1276 | |||
1269 | nplots = len(pairsIndexList) |
|
1277 | nplots = len(pairsIndexList) | |
1270 |
|
1278 | |||
1271 | self.setup(id=id, |
|
1279 | self.setup(id=id, | |
1272 | nplots=nplots, |
|
1280 | nplots=nplots, | |
1273 | wintitle=wintitle, |
|
1281 | wintitle=wintitle, | |
1274 | showprofile=showprofile, |
|
1282 | showprofile=showprofile, | |
1275 | show=show) |
|
1283 | show=show) | |
1276 |
|
1284 | |||
1277 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
1285 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
1278 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1286 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 | |
1279 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1287 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 | |
1280 |
|
1288 | |||
1281 | self.FTP_WEI = ftp_wei |
|
1289 | self.FTP_WEI = ftp_wei | |
1282 | self.EXP_CODE = exp_code |
|
1290 | self.EXP_CODE = exp_code | |
1283 | self.SUB_EXP_CODE = sub_exp_code |
|
1291 | self.SUB_EXP_CODE = sub_exp_code | |
1284 | self.PLOT_POS = plot_pos |
|
1292 | self.PLOT_POS = plot_pos | |
1285 |
|
1293 | |||
1286 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1294 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1287 | self.__isConfig = True |
|
1295 | self.__isConfig = True | |
1288 | self.figfile = figfile |
|
1296 | self.figfile = figfile | |
1289 | self.xdata = numpy.array([]) |
|
1297 | self.xdata = numpy.array([]) | |
1290 | self.ydata = numpy.array([]) |
|
1298 | self.ydata = numpy.array([]) | |
1291 |
|
1299 | |||
1292 | #open file beacon phase |
|
1300 | #open file beacon phase | |
1293 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1301 | path = '%s%03d' %(self.PREFIX, self.id) | |
1294 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1302 | beacon_file = os.path.join(path,'%s.txt'%self.name) | |
1295 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1303 | self.filename_phase = os.path.join(figpath,beacon_file) | |
1296 | #self.save_phase(self.filename_phase) |
|
1304 | #self.save_phase(self.filename_phase) | |
1297 |
|
1305 | |||
1298 |
|
1306 | |||
1299 | #store data beacon phase |
|
1307 | #store data beacon phase | |
1300 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1308 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) | |
1301 |
|
1309 | |||
1302 | self.setWinTitle(title) |
|
1310 | self.setWinTitle(title) | |
1303 |
|
1311 | |||
1304 |
|
1312 | |||
1305 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1313 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) | |
1306 |
|
1314 | |||
1307 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1315 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] | |
1308 |
|
1316 | |||
1309 | axes = self.axesList[0] |
|
1317 | axes = self.axesList[0] | |
1310 |
|
1318 | |||
1311 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1319 | self.xdata = numpy.hstack((self.xdata, x[0:1])) | |
1312 |
|
1320 | |||
1313 | if len(self.ydata)==0: |
|
1321 | if len(self.ydata)==0: | |
1314 | self.ydata = phase_beacon.reshape(-1,1) |
|
1322 | self.ydata = phase_beacon.reshape(-1,1) | |
1315 | else: |
|
1323 | else: | |
1316 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1324 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) | |
1317 |
|
1325 | |||
1318 |
|
1326 | |||
1319 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1327 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, | |
1320 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
1328 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, | |
1321 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1329 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", | |
1322 | XAxisAsTime=True, grid='both' |
|
1330 | XAxisAsTime=True, grid='both' | |
1323 | ) |
|
1331 | ) | |
1324 |
|
1332 | |||
1325 | self.draw() |
|
1333 | self.draw() | |
1326 |
|
1334 | |||
1327 | if x[1] >= self.axesList[0].xmax: |
|
1335 | if x[1] >= self.axesList[0].xmax: | |
1328 | self.counter_imagwr = wr_period |
|
1336 | self.counter_imagwr = wr_period | |
1329 | del self.xdata |
|
1337 | del self.xdata | |
1330 | del self.ydata |
|
1338 | del self.ydata | |
1331 | self.__isConfig = False |
|
1339 | self.__isConfig = False | |
1332 |
|
1340 | |||
1333 | if self.figfile == None: |
|
1341 | if self.figfile == None: | |
1334 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1342 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
1335 | self.figfile = self.getFilename(name = str_datetime) |
|
1343 | self.figfile = self.getFilename(name = str_datetime) | |
1336 |
|
1344 | |||
1337 | if figpath != '': |
|
1345 | if figpath != '': | |
1338 | self.counter_imagwr += 1 |
|
1346 | self.counter_imagwr += 1 | |
1339 | if (self.counter_imagwr>=wr_period): |
|
1347 | if (self.counter_imagwr>=wr_period): | |
1340 | # store png plot to local folder |
|
1348 | # store png plot to local folder | |
1341 | self.saveFigure(figpath, self.figfile) |
|
1349 | self.saveFigure(figpath, self.figfile) | |
1342 | # store png plot to FTP server according to RT-Web format |
|
1350 | # store png plot to FTP server according to RT-Web format | |
1343 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
1351 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
1344 | ftp_filename = os.path.join(figpath, name) |
|
1352 | ftp_filename = os.path.join(figpath, name) | |
1345 | self.saveFigure(figpath, ftp_filename) |
|
1353 | self.saveFigure(figpath, ftp_filename) | |
1346 | self.counter_imagwr = 0 |
|
1354 | self.counter_imagwr = 0 |
@@ -1,573 +1,616 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Daniel Suarez |
|
2 | @author: Daniel Suarez | |
3 | ''' |
|
3 | ''' | |
4 |
|
4 | |||
5 | import os |
|
5 | import os | |
6 | import sys |
|
6 | import sys | |
7 | import glob |
|
7 | import glob | |
8 | import fnmatch |
|
8 | import fnmatch | |
9 | import datetime |
|
9 | import datetime | |
10 | import time |
|
10 | import time | |
11 | import re |
|
11 | import re | |
12 | import h5py |
|
12 | import h5py | |
13 | import numpy |
|
13 | import numpy | |
14 |
|
14 | |||
15 | from model.proc.jroproc_base import ProcessingUnit, Operation |
|
15 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
16 | from model.data.jroamisr import AMISR |
|
16 | from model.data.jroamisr import AMISR | |
17 |
|
17 | |||
18 | class RadacHeader(): |
|
18 | class RadacHeader(): | |
19 | def __init__(self, fp): |
|
19 | def __init__(self, fp): | |
20 | header = 'Raw11/Data/RadacHeader' |
|
20 | header = 'Raw11/Data/RadacHeader' | |
21 | self.beamCodeByPulse = fp.get(header+'/BeamCode') |
|
21 | self.beamCodeByPulse = fp.get(header+'/BeamCode') | |
22 | self.beamCode = fp.get('Raw11/Data/Beamcodes') |
|
22 | self.beamCode = fp.get('Raw11/Data/Beamcodes') | |
23 | self.code = fp.get(header+'/Code') |
|
23 | self.code = fp.get(header+'/Code') | |
24 | self.frameCount = fp.get(header+'/FrameCount') |
|
24 | self.frameCount = fp.get(header+'/FrameCount') | |
25 | self.modeGroup = fp.get(header+'/ModeGroup') |
|
25 | self.modeGroup = fp.get(header+'/ModeGroup') | |
26 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') |
|
26 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') | |
27 | self.pulseCount = fp.get(header+'/PulseCount') |
|
27 | self.pulseCount = fp.get(header+'/PulseCount') | |
28 | self.radacTime = fp.get(header+'/RadacTime') |
|
28 | self.radacTime = fp.get(header+'/RadacTime') | |
29 | self.timeCount = fp.get(header+'/TimeCount') |
|
29 | self.timeCount = fp.get(header+'/TimeCount') | |
30 | self.timeStatus = fp.get(header+'/TimeStatus') |
|
30 | self.timeStatus = fp.get(header+'/TimeStatus') | |
31 |
|
31 | |||
32 | self.nrecords = self.pulseCount.shape[0] #nblocks |
|
32 | self.nrecords = self.pulseCount.shape[0] #nblocks | |
33 | self.npulses = self.pulseCount.shape[1] #nprofile |
|
33 | self.npulses = self.pulseCount.shape[1] #nprofile | |
34 | self.nsamples = self.nsamplesPulse[0,0] #ngates |
|
34 | self.nsamples = self.nsamplesPulse[0,0] #ngates | |
35 | self.nbeams = self.beamCode.shape[1] |
|
35 | self.nbeams = self.beamCode.shape[1] | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | def getIndexRangeToPulse(self, idrecord=0): |
|
38 | def getIndexRangeToPulse(self, idrecord=0): | |
39 | #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) |
|
39 | #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) | |
40 | #startPulseCountId = indexToZero[0][0] |
|
40 | #startPulseCountId = indexToZero[0][0] | |
41 | #endPulseCountId = startPulseCountId - 1 |
|
41 | #endPulseCountId = startPulseCountId - 1 | |
42 | #range1 = numpy.arange(startPulseCountId,self.npulses,1) |
|
42 | #range1 = numpy.arange(startPulseCountId,self.npulses,1) | |
43 | #range2 = numpy.arange(0,startPulseCountId,1) |
|
43 | #range2 = numpy.arange(0,startPulseCountId,1) | |
44 | #return range1, range2 |
|
44 | #return range1, range2 | |
45 |
|
45 | |||
46 | looking_zeros_index = numpy.where(self.pulseCount.value[idrecord,:]==0)[0] |
|
46 | looking_zeros_index = numpy.where(self.pulseCount.value[idrecord,:]==0)[0] | |
47 | getLastIndexZero = looking_zeros_index[-1] |
|
47 | getLastIndexZero = looking_zeros_index[-1] | |
48 | index_data = numpy.arange(0,getLastIndexZero,1) |
|
48 | index_data = numpy.arange(0,getLastIndexZero,1) | |
49 | index_buffer = numpy.arange(getLastIndexZero,self.npulses,1) |
|
49 | index_buffer = numpy.arange(getLastIndexZero,self.npulses,1) | |
50 | return index_data, index_buffer |
|
50 | return index_data, index_buffer | |
51 |
|
51 | |||
52 | class AMISRReader(ProcessingUnit): |
|
52 | class AMISRReader(ProcessingUnit): | |
53 |
|
53 | |||
54 | path = None |
|
54 | path = None | |
55 | startDate = None |
|
55 | startDate = None | |
56 | endDate = None |
|
56 | endDate = None | |
57 | startTime = None |
|
57 | startTime = None | |
58 | endTime = None |
|
58 | endTime = None | |
59 | walk = None |
|
59 | walk = None | |
60 | isConfig = False |
|
60 | isConfig = False | |
61 |
|
61 | |||
62 | def __init__(self): |
|
62 | def __init__(self): | |
63 | self.set = None |
|
63 | self.set = None | |
64 | self.subset = None |
|
64 | self.subset = None | |
65 | self.extension_file = '.h5' |
|
65 | self.extension_file = '.h5' | |
66 | self.dtc_str = 'dtc' |
|
66 | self.dtc_str = 'dtc' | |
67 | self.dtc_id = 0 |
|
67 | self.dtc_id = 0 | |
68 | self.status = True |
|
68 | self.status = True | |
69 | self.isConfig = False |
|
69 | self.isConfig = False | |
70 | self.dirnameList = [] |
|
70 | self.dirnameList = [] | |
71 | self.filenameList = [] |
|
71 | self.filenameList = [] | |
72 | self.fileIndex = None |
|
72 | self.fileIndex = None | |
73 | self.flagNoMoreFiles = False |
|
73 | self.flagNoMoreFiles = False | |
74 | self.flagIsNewFile = 0 |
|
74 | self.flagIsNewFile = 0 | |
75 | self.filename = '' |
|
75 | self.filename = '' | |
76 | self.amisrFilePointer = None |
|
76 | self.amisrFilePointer = None | |
77 | self.radacHeaderObj = None |
|
77 | self.radacHeaderObj = None | |
78 | self.dataOut = self.__createObjByDefault() |
|
78 | self.dataOut = self.__createObjByDefault() | |
79 | self.datablock = None |
|
79 | self.datablock = None | |
80 | self.rest_datablock = None |
|
80 | self.rest_datablock = None | |
81 | self.range = None |
|
81 | self.range = None | |
82 | self.idrecord_count = 0 |
|
82 | self.idrecord_count = 0 | |
83 | self.profileIndex = 0 |
|
83 | self.profileIndex = 0 | |
84 | self.index_amisr_sample = None |
|
84 | self.index_amisr_sample = None | |
85 | self.index_amisr_buffer = None |
|
85 | self.index_amisr_buffer = None | |
86 | self.beamCodeByFrame = None |
|
86 | self.beamCodeByFrame = None | |
87 | self.radacTimeByFrame = None |
|
87 | self.radacTimeByFrame = None | |
88 | #atributos originales tal y como esta en el archivo de datos |
|
88 | #atributos originales tal y como esta en el archivo de datos | |
89 | self.beamCodesFromFile = None |
|
89 | self.beamCodesFromFile = None | |
90 | self.radacTimeFromFile = None |
|
90 | self.radacTimeFromFile = None | |
91 | self.rangeFromFile = None |
|
91 | self.rangeFromFile = None | |
92 | self.dataByFrame = None |
|
92 | self.dataByFrame = None | |
93 | self.dataset = None |
|
93 | self.dataset = None | |
94 |
|
94 | |||
95 | self.beamCodeDict = {} |
|
95 | self.beamCodeDict = {} | |
96 | self.beamRangeDict = {} |
|
96 | self.beamRangeDict = {} | |
97 |
|
97 | |||
98 | #experiment cgf file |
|
98 | #experiment cgf file | |
99 | self.npulsesint_fromfile = None |
|
99 | self.npulsesint_fromfile = None | |
100 | self.recordsperfile_fromfile = None |
|
100 | self.recordsperfile_fromfile = None | |
101 | self.nbeamcodes_fromfile = None |
|
101 | self.nbeamcodes_fromfile = None | |
102 | self.ngates_fromfile = None |
|
102 | self.ngates_fromfile = None | |
103 | self.ippSeconds_fromfile = None |
|
103 | self.ippSeconds_fromfile = None | |
104 | self.frequency_h5file = None |
|
104 | self.frequency_h5file = None | |
105 |
|
105 | |||
106 |
|
106 | |||
107 | self.__firstFile = True |
|
107 | self.__firstFile = True | |
108 | self.buffer_radactime = None |
|
108 | self.buffer_radactime = None | |
109 |
|
109 | |||
110 | self.index4_schain_datablock = None |
|
110 | self.index4_schain_datablock = None | |
111 | self.index4_buffer = None |
|
111 | self.index4_buffer = None | |
112 | self.schain_datablock = None |
|
112 | self.schain_datablock = None | |
113 | self.buffer = None |
|
113 | self.buffer = None | |
114 | self.linear_pulseCount = None |
|
114 | self.linear_pulseCount = None | |
115 | self.npulseByFrame = None |
|
115 | self.npulseByFrame = None | |
116 | self.profileIndex_offset = None |
|
116 | self.profileIndex_offset = None | |
117 | self.timezone = 'ut' |
|
117 | self.timezone = 'ut' | |
118 |
|
118 | |||
119 | def __createObjByDefault(self): |
|
119 | def __createObjByDefault(self): | |
120 |
|
120 | |||
121 | dataObj = AMISR() |
|
121 | dataObj = AMISR() | |
122 |
|
122 | |||
123 | return dataObj |
|
123 | return dataObj | |
124 |
|
124 | |||
125 | def __setParameters(self,path,startDate,endDate,startTime,endTime,walk): |
|
125 | def __setParameters(self,path,startDate,endDate,startTime,endTime,walk): | |
126 | self.path = path |
|
126 | self.path = path | |
127 | self.startDate = startDate |
|
127 | self.startDate = startDate | |
128 | self.endDate = endDate |
|
128 | self.endDate = endDate | |
129 | self.startTime = startTime |
|
129 | self.startTime = startTime | |
130 | self.endTime = endTime |
|
130 | self.endTime = endTime | |
131 | self.walk = walk |
|
131 | self.walk = walk | |
132 |
|
132 | |||
133 | def __checkPath(self): |
|
133 | def __checkPath(self): | |
134 | if os.path.exists(self.path): |
|
134 | if os.path.exists(self.path): | |
135 | self.status = 1 |
|
135 | self.status = 1 | |
136 | else: |
|
136 | else: | |
137 | self.status = 0 |
|
137 | self.status = 0 | |
138 | print 'Path:%s does not exists'%self.path |
|
138 | print 'Path:%s does not exists'%self.path | |
139 |
|
139 | |||
140 | return |
|
140 | return | |
141 |
|
141 | |||
142 | def __selDates(self, amisr_dirname_format): |
|
142 | def __selDates(self, amisr_dirname_format): | |
143 | try: |
|
143 | try: | |
144 | year = int(amisr_dirname_format[0:4]) |
|
144 | year = int(amisr_dirname_format[0:4]) | |
145 | month = int(amisr_dirname_format[4:6]) |
|
145 | month = int(amisr_dirname_format[4:6]) | |
146 | dom = int(amisr_dirname_format[6:8]) |
|
146 | dom = int(amisr_dirname_format[6:8]) | |
147 | thisDate = datetime.date(year,month,dom) |
|
147 | thisDate = datetime.date(year,month,dom) | |
148 |
|
148 | |||
149 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
149 | if (thisDate>=self.startDate and thisDate <= self.endDate): | |
150 | return amisr_dirname_format |
|
150 | return amisr_dirname_format | |
151 | except: |
|
151 | except: | |
152 | return None |
|
152 | return None | |
153 |
|
153 | |||
154 | def __findDataForDates(self): |
|
154 | def __findDataForDates(self): | |
155 |
|
155 | |||
156 |
|
156 | |||
157 |
|
157 | |||
158 | if not(self.status): |
|
158 | if not(self.status): | |
159 | return None |
|
159 | return None | |
160 |
|
160 | |||
161 | pat = '\d+.\d+' |
|
161 | pat = '\d+.\d+' | |
162 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] |
|
162 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] | |
163 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
163 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
164 | dirnameList = [x.string for x in dirnameList] |
|
164 | dirnameList = [x.string for x in dirnameList] | |
165 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
165 | dirnameList = [self.__selDates(x) for x in dirnameList] | |
166 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
166 | dirnameList = filter(lambda x:x!=None,dirnameList) | |
167 | if len(dirnameList)>0: |
|
167 | if len(dirnameList)>0: | |
168 | self.status = 1 |
|
168 | self.status = 1 | |
169 | self.dirnameList = dirnameList |
|
169 | self.dirnameList = dirnameList | |
170 | self.dirnameList.sort() |
|
170 | self.dirnameList.sort() | |
171 | else: |
|
171 | else: | |
172 | self.status = 0 |
|
172 | self.status = 0 | |
173 | return None |
|
173 | return None | |
174 |
|
174 | |||
175 | def __getTimeFromData(self): |
|
175 | def __getTimeFromData(self): | |
176 | pass |
|
176 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) | |
|
177 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) | |||
|
178 | ||||
|
179 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) | |||
|
180 | print '........................................' | |||
|
181 | filter_filenameList = [] | |||
|
182 | for filename in self.filenameList: | |||
|
183 | fp = h5py.File(filename,'r') | |||
|
184 | time_str = fp.get('Time/RadacTimeString') | |||
|
185 | ||||
|
186 | startDateTimeStr_File = time_str[0][0].split('.')[0] | |||
|
187 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |||
|
188 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |||
|
189 | ||||
|
190 | endDateTimeStr_File = time_str[-1][-1].split('.')[0] | |||
|
191 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') | |||
|
192 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) | |||
|
193 | ||||
|
194 | fp.close() | |||
|
195 | ||||
|
196 | if self.timezone == 'lt': | |||
|
197 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) | |||
|
198 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) | |||
|
199 | ||||
|
200 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader): | |||
|
201 | #self.filenameList.remove(filename) | |||
|
202 | filter_filenameList.append(filename) | |||
|
203 | ||||
|
204 | filter_filenameList.sort() | |||
|
205 | self.filenameList = filter_filenameList | |||
|
206 | return 1 | |||
177 |
|
207 | |||
178 | def __filterByGlob1(self, dirName): |
|
208 | def __filterByGlob1(self, dirName): | |
179 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) |
|
209 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) | |
180 | filterDict = {} |
|
210 | filterDict = {} | |
181 | filterDict.setdefault(dirName) |
|
211 | filterDict.setdefault(dirName) | |
182 | filterDict[dirName] = filter_files |
|
212 | filterDict[dirName] = filter_files | |
183 | return filterDict |
|
213 | return filterDict | |
184 |
|
214 | |||
185 | def __getFilenameList(self, fileListInKeys, dirList): |
|
215 | def __getFilenameList(self, fileListInKeys, dirList): | |
186 | for value in fileListInKeys: |
|
216 | for value in fileListInKeys: | |
187 | dirName = value.keys()[0] |
|
217 | dirName = value.keys()[0] | |
188 | for file in value[dirName]: |
|
218 | for file in value[dirName]: | |
189 | filename = os.path.join(dirName, file) |
|
219 | filename = os.path.join(dirName, file) | |
190 | self.filenameList.append(filename) |
|
220 | self.filenameList.append(filename) | |
191 |
|
221 | |||
192 |
|
222 | |||
193 | def __selectDataForTimes(self): |
|
223 | def __selectDataForTimes(self): | |
194 | #aun no esta implementado el filtro for tiempo |
|
224 | #aun no esta implementado el filtro for tiempo | |
195 | if not(self.status): |
|
225 | if not(self.status): | |
196 | return None |
|
226 | return None | |
197 |
|
227 | |||
198 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
228 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] | |
199 |
|
229 | |||
200 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] |
|
230 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] | |
201 |
|
231 | |||
202 | self.__getFilenameList(fileListInKeys, dirList) |
|
232 | self.__getFilenameList(fileListInKeys, dirList) | |
203 |
|
233 | #filtro por tiempo | ||
|
234 | if not(self.all): | |||
|
235 | self.__getTimeFromData() | |||
|
236 | ||||
|
237 | ||||
204 | if len(self.filenameList)>0: |
|
238 | if len(self.filenameList)>0: | |
205 | self.status = 1 |
|
239 | self.status = 1 | |
206 | self.filenameList.sort() |
|
240 | self.filenameList.sort() | |
207 | else: |
|
241 | else: | |
208 | self.status = 0 |
|
242 | self.status = 0 | |
209 | return None |
|
243 | return None | |
210 |
|
244 | |||
211 |
|
245 | |||
212 | def __searchFilesOffline(self, |
|
246 | def __searchFilesOffline(self, | |
213 | path, |
|
247 | path, | |
214 | startDate, |
|
248 | startDate, | |
215 | endDate, |
|
249 | endDate, | |
216 | startTime=datetime.time(0,0,0), |
|
250 | startTime=datetime.time(0,0,0), | |
217 | endTime=datetime.time(23,59,59), |
|
251 | endTime=datetime.time(23,59,59), | |
218 | walk=True): |
|
252 | walk=True): | |
219 |
|
253 | |||
220 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
254 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) | |
221 |
|
255 | |||
222 | self.__checkPath() |
|
256 | self.__checkPath() | |
223 |
|
257 | |||
224 | self.__findDataForDates() |
|
258 | self.__findDataForDates() | |
225 |
|
259 | |||
226 | self.__selectDataForTimes() |
|
260 | self.__selectDataForTimes() | |
227 |
|
261 | |||
228 | for i in range(len(self.filenameList)): |
|
262 | for i in range(len(self.filenameList)): | |
229 | print "%s" %(self.filenameList[i]) |
|
263 | print "%s" %(self.filenameList[i]) | |
230 |
|
264 | |||
231 | return |
|
265 | return | |
232 |
|
266 | |||
233 | def __setNextFileOffline(self): |
|
267 | def __setNextFileOffline(self): | |
234 | idFile = self.fileIndex |
|
268 | idFile = self.fileIndex | |
235 |
|
269 | |||
236 | while (True): |
|
270 | while (True): | |
237 | idFile += 1 |
|
271 | idFile += 1 | |
238 | if not(idFile < len(self.filenameList)): |
|
272 | if not(idFile < len(self.filenameList)): | |
239 | self.flagNoMoreFiles = 1 |
|
273 | self.flagNoMoreFiles = 1 | |
240 | print "No more Files" |
|
274 | print "No more Files" | |
241 | return 0 |
|
275 | return 0 | |
242 |
|
276 | |||
243 | filename = self.filenameList[idFile] |
|
277 | filename = self.filenameList[idFile] | |
244 |
|
278 | |||
245 | amisrFilePointer = h5py.File(filename,'r') |
|
279 | amisrFilePointer = h5py.File(filename,'r') | |
246 |
|
280 | |||
247 | break |
|
281 | break | |
248 |
|
282 | |||
249 | self.flagIsNewFile = 1 |
|
283 | self.flagIsNewFile = 1 | |
250 | self.fileIndex = idFile |
|
284 | self.fileIndex = idFile | |
251 | self.filename = filename |
|
285 | self.filename = filename | |
252 |
|
286 | |||
253 | self.amisrFilePointer = amisrFilePointer |
|
287 | self.amisrFilePointer = amisrFilePointer | |
254 |
|
288 | |||
255 | print "Setting the file: %s"%self.filename |
|
289 | print "Setting the file: %s"%self.filename | |
256 |
|
290 | |||
257 | return 1 |
|
291 | return 1 | |
258 |
|
292 | |||
259 | def __readHeader(self): |
|
293 | def __readHeader(self): | |
260 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) |
|
294 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) | |
261 |
|
295 | |||
262 | #update values from experiment cfg file |
|
296 | #update values from experiment cfg file | |
263 | if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile: |
|
297 | if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile: | |
264 | self.radacHeaderObj.nrecords = self.recordsperfile_fromfile |
|
298 | self.radacHeaderObj.nrecords = self.recordsperfile_fromfile | |
265 | self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile |
|
299 | self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile | |
266 | self.radacHeaderObj.npulses = self.npulsesint_fromfile |
|
300 | self.radacHeaderObj.npulses = self.npulsesint_fromfile | |
267 | self.radacHeaderObj.nsamples = self.ngates_fromfile |
|
301 | self.radacHeaderObj.nsamples = self.ngates_fromfile | |
268 |
|
302 | |||
269 | #looking index list for data |
|
303 | #looking index list for data | |
270 | start_index = self.radacHeaderObj.pulseCount[0,:][0] |
|
304 | start_index = self.radacHeaderObj.pulseCount[0,:][0] | |
271 | end_index = self.radacHeaderObj.npulses |
|
305 | end_index = self.radacHeaderObj.npulses | |
272 | range4data = range(start_index, end_index) |
|
306 | range4data = range(start_index, end_index) | |
273 | self.index4_schain_datablock = numpy.array(range4data) |
|
307 | self.index4_schain_datablock = numpy.array(range4data) | |
274 |
|
308 | |||
275 | buffer_start_index = 0 |
|
309 | buffer_start_index = 0 | |
276 | buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0] |
|
310 | buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0] | |
277 | range4buffer = range(buffer_start_index, buffer_end_index) |
|
311 | range4buffer = range(buffer_start_index, buffer_end_index) | |
278 | self.index4_buffer = numpy.array(range4buffer) |
|
312 | self.index4_buffer = numpy.array(range4buffer) | |
279 |
|
313 | |||
280 | self.linear_pulseCount = numpy.array(range4data + range4buffer) |
|
314 | self.linear_pulseCount = numpy.array(range4data + range4buffer) | |
281 | self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1) |
|
315 | self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1) | |
282 |
|
316 | |||
283 | #get tuning frequency |
|
317 | #get tuning frequency | |
284 | frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency') |
|
318 | frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency') | |
285 | self.frequency_h5file = frequency_h5file_dataset[0,0] |
|
319 | self.frequency_h5file = frequency_h5file_dataset[0,0] | |
286 |
|
320 | |||
287 | self.flagIsNewFile = 1 |
|
321 | self.flagIsNewFile = 1 | |
288 |
|
322 | |||
289 | def __getBeamCode(self): |
|
323 | def __getBeamCode(self): | |
290 | self.beamCodeDict = {} |
|
324 | self.beamCodeDict = {} | |
291 | self.beamRangeDict = {} |
|
325 | self.beamRangeDict = {} | |
292 |
|
326 | |||
|
327 | beamCodeMap = self.amisrFilePointer.get('Setup/BeamcodeMap') | |||
|
328 | ||||
293 | for i in range(len(self.radacHeaderObj.beamCode[0,:])): |
|
329 | for i in range(len(self.radacHeaderObj.beamCode[0,:])): | |
294 | self.beamCodeDict.setdefault(i) |
|
330 | self.beamCodeDict.setdefault(i) | |
295 | self.beamRangeDict.setdefault(i) |
|
331 | self.beamRangeDict.setdefault(i) | |
296 |
|
|
332 | beamcodeValue = self.radacHeaderObj.beamCode[0,i] | |
|
333 | beamcodeIndex = numpy.where(beamCodeMap[:,0] == beamcodeValue)[0][0] | |||
|
334 | x = beamCodeMap[beamcodeIndex][1] | |||
|
335 | y = beamCodeMap[beamcodeIndex][2] | |||
|
336 | z = beamCodeMap[beamcodeIndex][3] | |||
|
337 | self.beamCodeDict[i] = [beamcodeValue, x, y, z] | |||
297 |
|
338 | |||
298 |
|
||||
299 | just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:] |
|
339 | just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:] | |
300 |
|
340 | |||
301 | for i in range(len(self.beamCodeDict.values())): |
|
341 | for i in range(len(self.beamCodeDict.values())): | |
302 | xx = numpy.where(just4record0==self.beamCodeDict.values()[i]) |
|
342 | xx = numpy.where(just4record0==self.beamCodeDict.values()[i][0]) | |
303 | self.beamRangeDict[i] = xx[0] |
|
343 | self.beamRangeDict[i] = xx[0] | |
304 |
|
344 | |||
305 | def __getExpParameters(self): |
|
345 | def __getExpParameters(self): | |
306 | if not(self.status): |
|
346 | if not(self.status): | |
307 | return None |
|
347 | return None | |
308 |
|
348 | |||
309 | experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup') |
|
349 | experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup') | |
310 |
|
350 | |||
311 | expFinder = glob.glob1(experimentCfgPath,'*.exp') |
|
351 | expFinder = glob.glob1(experimentCfgPath,'*.exp') | |
312 | if len(expFinder)== 0: |
|
352 | if len(expFinder)== 0: | |
313 | self.status = 0 |
|
353 | self.status = 0 | |
314 | return None |
|
354 | return None | |
315 |
|
355 | |||
316 | experimentFilename = os.path.join(experimentCfgPath,expFinder[0]) |
|
356 | experimentFilename = os.path.join(experimentCfgPath,expFinder[0]) | |
317 |
|
357 | |||
318 | f = open(experimentFilename) |
|
358 | f = open(experimentFilename) | |
319 | lines = f.readlines() |
|
359 | lines = f.readlines() | |
320 | f.close() |
|
360 | f.close() | |
321 |
|
361 | |||
322 | parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*'] |
|
362 | parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*'] | |
323 | filterList = [fnmatch.filter(lines, x) for x in parmsList] |
|
363 | filterList = [fnmatch.filter(lines, x) for x in parmsList] | |
324 |
|
364 | |||
325 |
|
365 | |||
326 | values = [re.sub(r'\D',"",x[0]) for x in filterList] |
|
366 | values = [re.sub(r'\D',"",x[0]) for x in filterList] | |
327 |
|
367 | |||
328 | self.npulsesint_fromfile = int(values[0]) |
|
368 | self.npulsesint_fromfile = int(values[0]) | |
329 | self.recordsperfile_fromfile = int(values[1]) |
|
369 | self.recordsperfile_fromfile = int(values[1]) | |
330 | self.nbeamcodes_fromfile = int(values[2]) |
|
370 | self.nbeamcodes_fromfile = int(values[2]) | |
331 | self.ngates_fromfile = int(values[3]) |
|
371 | self.ngates_fromfile = int(values[3]) | |
332 |
|
372 | |||
333 | tufileFinder = fnmatch.filter(lines, 'tufile=*') |
|
373 | tufileFinder = fnmatch.filter(lines, 'tufile=*') | |
334 | tufile = tufileFinder[0].split('=')[1].split('\n')[0] |
|
374 | tufile = tufileFinder[0].split('=')[1].split('\n')[0] | |
|
375 | tufile = tufile.split('\r')[0] | |||
335 | tufilename = os.path.join(experimentCfgPath,tufile) |
|
376 | tufilename = os.path.join(experimentCfgPath,tufile) | |
336 |
|
377 | |||
337 | f = open(tufilename) |
|
378 | f = open(tufilename) | |
338 | lines = f.readlines() |
|
379 | lines = f.readlines() | |
339 | f.close() |
|
380 | f.close() | |
340 | self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6 |
|
381 | self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6 | |
341 |
|
382 | |||
342 |
|
383 | |||
343 | self.status = 1 |
|
384 | self.status = 1 | |
344 |
|
385 | |||
345 | def __setIdsAndArrays(self): |
|
386 | def __setIdsAndArrays(self): | |
346 | self.dataByFrame = self.__setDataByFrame() |
|
387 | self.dataByFrame = self.__setDataByFrame() | |
347 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :] |
|
388 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :] | |
348 | self.readRanges() |
|
389 | self.readRanges() | |
349 | self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0) |
|
390 | self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0) | |
350 | self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses) |
|
391 | self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses) | |
351 | self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame) |
|
392 | self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame) | |
352 |
|
393 | |||
353 |
|
394 | |||
354 | def __setNextFile(self): |
|
395 | def __setNextFile(self): | |
355 |
|
396 | |||
356 | newFile = self.__setNextFileOffline() |
|
397 | newFile = self.__setNextFileOffline() | |
357 |
|
398 | |||
358 | if not(newFile): |
|
399 | if not(newFile): | |
359 | return 0 |
|
400 | return 0 | |
360 |
|
401 | |||
361 | self.__readHeader() |
|
402 | self.__readHeader() | |
362 |
|
403 | |||
363 | if self.__firstFile: |
|
404 | if self.__firstFile: | |
364 | self.__setIdsAndArrays() |
|
405 | self.__setIdsAndArrays() | |
365 | self.__firstFile = False |
|
406 | self.__firstFile = False | |
366 |
|
407 | |||
367 | self.__getBeamCode() |
|
408 | self.__getBeamCode() | |
368 | self.readDataBlock() |
|
409 | self.readDataBlock() | |
369 |
|
410 | |||
370 |
|
411 | |||
371 | def setup(self,path=None, |
|
412 | def setup(self,path=None, | |
372 | startDate=None, |
|
413 | startDate=None, | |
373 | endDate=None, |
|
414 | endDate=None, | |
374 | startTime=datetime.time(0,0,0), |
|
415 | startTime=datetime.time(0,0,0), | |
375 | endTime=datetime.time(23,59,59), |
|
416 | endTime=datetime.time(23,59,59), | |
376 | walk=True, |
|
417 | walk=True, | |
377 |
timezone='ut', |
|
418 | timezone='ut', | |
|
419 | all=0,): | |||
378 |
|
420 | |||
379 | self.timezone = timezone |
|
421 | self.timezone = timezone | |
|
422 | self.all = all | |||
380 | #Busqueda de archivos offline |
|
423 | #Busqueda de archivos offline | |
381 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) |
|
424 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) | |
382 |
|
425 | |||
383 | if not(self.filenameList): |
|
426 | if not(self.filenameList): | |
384 | print "There is no files into the folder: %s"%(path) |
|
427 | print "There is no files into the folder: %s"%(path) | |
385 |
|
428 | |||
386 | sys.exit(-1) |
|
429 | sys.exit(-1) | |
387 |
|
430 | |||
388 | self.__getExpParameters() |
|
431 | self.__getExpParameters() | |
389 |
|
432 | |||
390 | self.fileIndex = -1 |
|
433 | self.fileIndex = -1 | |
391 |
|
434 | |||
392 | self.__setNextFile() |
|
435 | self.__setNextFile() | |
393 |
|
436 | |||
394 | first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0] |
|
437 | first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0] | |
395 | index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0] |
|
438 | index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0] | |
396 | self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][index] |
|
439 | self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][index] | |
397 | self.profileIndex = self.profileIndex_offset |
|
440 | self.profileIndex = self.profileIndex_offset | |
398 |
|
441 | |||
399 | def readRanges(self): |
|
442 | def readRanges(self): | |
400 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') |
|
443 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') | |
401 | #self.rangeFromFile = dataset.value |
|
444 | #self.rangeFromFile = dataset.value | |
402 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) |
|
445 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) | |
403 | return range |
|
446 | return range | |
404 |
|
447 | |||
405 |
|
448 | |||
406 | def readRadacTime(self,idrecord, range1, range2): |
|
449 | def readRadacTime(self,idrecord, range1, range2): | |
407 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value |
|
450 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value | |
408 |
|
451 | |||
409 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
452 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) | |
410 | #radacTimeByFrame = dataset[idrecord - 1,range1] |
|
453 | #radacTimeByFrame = dataset[idrecord - 1,range1] | |
411 | #radacTimeByFrame = dataset[idrecord,range2] |
|
454 | #radacTimeByFrame = dataset[idrecord,range2] | |
412 |
|
455 | |||
413 | return radacTimeByFrame |
|
456 | return radacTimeByFrame | |
414 |
|
457 | |||
415 | def readBeamCode(self, idrecord, range1, range2): |
|
458 | def readBeamCode(self, idrecord, range1, range2): | |
416 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') |
|
459 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') | |
417 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
460 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) | |
418 | self.beamCodesFromFile = dataset.value |
|
461 | self.beamCodesFromFile = dataset.value | |
419 |
|
462 | |||
420 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] |
|
463 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] | |
421 | #beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
464 | #beamcodeByFrame[range2] = dataset[idrecord, range2] | |
422 | beamcodeByFrame[range1] = dataset[idrecord, range1] |
|
465 | beamcodeByFrame[range1] = dataset[idrecord, range1] | |
423 | beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
466 | beamcodeByFrame[range2] = dataset[idrecord, range2] | |
424 |
|
467 | |||
425 | return beamcodeByFrame |
|
468 | return beamcodeByFrame | |
426 |
|
469 | |||
427 |
|
470 | |||
428 | def __setDataByFrame(self): |
|
471 | def __setDataByFrame(self): | |
429 | ndata = 2 # porque es complejo |
|
472 | ndata = 2 # porque es complejo | |
430 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) |
|
473 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) | |
431 | return dataByFrame |
|
474 | return dataByFrame | |
432 |
|
475 | |||
433 | def __readDataSet(self): |
|
476 | def __readDataSet(self): | |
434 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') |
|
477 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') | |
435 | return dataset |
|
478 | return dataset | |
436 |
|
479 | |||
437 | def __setDataBlock(self,): |
|
480 | def __setDataBlock(self,): | |
438 | real = self.dataByFrame[:,:,0] #asumo que 0 es real |
|
481 | real = self.dataByFrame[:,:,0] #asumo que 0 es real | |
439 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario |
|
482 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario | |
440 | datablock = real + imag*1j #armo el complejo |
|
483 | datablock = real + imag*1j #armo el complejo | |
441 | return datablock |
|
484 | return datablock | |
442 |
|
485 | |||
443 | def readSamples_version1(self,idrecord): |
|
486 | def readSamples_version1(self,idrecord): | |
444 | #estas tres primeras lineas solo se deben ejecutar una vez |
|
487 | #estas tres primeras lineas solo se deben ejecutar una vez | |
445 | if self.flagIsNewFile: |
|
488 | if self.flagIsNewFile: | |
446 | #reading dataset |
|
489 | #reading dataset | |
447 | self.dataset = self.__readDataSet() |
|
490 | self.dataset = self.__readDataSet() | |
448 | self.flagIsNewFile = 0 |
|
491 | self.flagIsNewFile = 0 | |
449 |
|
492 | |||
450 | if idrecord == 0: |
|
493 | if idrecord == 0: | |
451 | self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:] |
|
494 | self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:] | |
452 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample] |
|
495 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample] | |
453 | datablock = self.__setDataBlock() |
|
496 | datablock = self.__setDataBlock() | |
454 |
|
497 | |||
455 | self.buffer = self.dataset[0, self.index_amisr_buffer,:,:] |
|
498 | self.buffer = self.dataset[0, self.index_amisr_buffer,:,:] | |
456 | self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer] |
|
499 | self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer] | |
457 |
|
500 | |||
458 | return datablock |
|
501 | return datablock | |
459 |
|
502 | |||
460 | self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy() |
|
503 | self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy() | |
461 | self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy() |
|
504 | self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy() | |
462 | self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:] |
|
505 | self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:] | |
463 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample] |
|
506 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample] | |
464 | datablock = self.__setDataBlock() |
|
507 | datablock = self.__setDataBlock() | |
465 |
|
508 | |||
466 | self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :] |
|
509 | self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :] | |
467 | self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer] |
|
510 | self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer] | |
468 |
|
511 | |||
469 | return datablock |
|
512 | return datablock | |
470 |
|
513 | |||
471 |
|
514 | |||
472 | def readSamples(self,idrecord): |
|
515 | def readSamples(self,idrecord): | |
473 | if self.flagIsNewFile: |
|
516 | if self.flagIsNewFile: | |
474 | self.dataByFrame = self.__setDataByFrame() |
|
517 | self.dataByFrame = self.__setDataByFrame() | |
475 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] |
|
518 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] | |
476 |
|
519 | |||
477 | #reading ranges |
|
520 | #reading ranges | |
478 | self.readRanges() |
|
521 | self.readRanges() | |
479 | #reading dataset |
|
522 | #reading dataset | |
480 | self.dataset = self.__readDataSet() |
|
523 | self.dataset = self.__readDataSet() | |
481 |
|
524 | |||
482 | self.flagIsNewFile = 0 |
|
525 | self.flagIsNewFile = 0 | |
483 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] |
|
526 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] | |
484 | self.dataByFrame = self.dataset[idrecord, :, :, :] |
|
527 | self.dataByFrame = self.dataset[idrecord, :, :, :] | |
485 | datablock = self.__setDataBlock() |
|
528 | datablock = self.__setDataBlock() | |
486 | return datablock |
|
529 | return datablock | |
487 |
|
530 | |||
488 |
|
531 | |||
489 | def readDataBlock(self): |
|
532 | def readDataBlock(self): | |
490 |
|
533 | |||
491 | self.datablock = self.readSamples_version1(self.idrecord_count) |
|
534 | self.datablock = self.readSamples_version1(self.idrecord_count) | |
492 | #self.datablock = self.readSamples(self.idrecord_count) |
|
535 | #self.datablock = self.readSamples(self.idrecord_count) | |
493 | #print 'record:', self.idrecord_count |
|
536 | #print 'record:', self.idrecord_count | |
494 |
|
537 | |||
495 | self.idrecord_count += 1 |
|
538 | self.idrecord_count += 1 | |
496 | self.profileIndex = 0 |
|
539 | self.profileIndex = 0 | |
497 |
|
540 | |||
498 | if self.idrecord_count >= self.radacHeaderObj.nrecords: |
|
541 | if self.idrecord_count >= self.radacHeaderObj.nrecords: | |
499 | self.idrecord_count = 0 |
|
542 | self.idrecord_count = 0 | |
500 | self.flagIsNewFile = 1 |
|
543 | self.flagIsNewFile = 1 | |
501 |
|
544 | |||
502 | def readNextBlock(self): |
|
545 | def readNextBlock(self): | |
503 |
|
546 | |||
504 | self.readDataBlock() |
|
547 | self.readDataBlock() | |
505 |
|
548 | |||
506 | if self.flagIsNewFile: |
|
549 | if self.flagIsNewFile: | |
507 | self.__setNextFile() |
|
550 | self.__setNextFile() | |
508 | pass |
|
551 | pass | |
509 |
|
552 | |||
510 | def __hasNotDataInBuffer(self): |
|
553 | def __hasNotDataInBuffer(self): | |
511 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record |
|
554 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record | |
512 | if self.profileIndex >= self.radacHeaderObj.npulses: |
|
555 | if self.profileIndex >= self.radacHeaderObj.npulses: | |
513 | return 1 |
|
556 | return 1 | |
514 | return 0 |
|
557 | return 0 | |
515 |
|
558 | |||
516 | def printUTC(self): |
|
559 | def printUTC(self): | |
517 | print self.dataOut.utctime |
|
560 | print self.dataOut.utctime | |
518 | print '' |
|
561 | print '' | |
519 |
|
562 | |||
520 | def setObjProperties(self): |
|
563 | def setObjProperties(self): | |
521 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km |
|
564 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km | |
522 | self.dataOut.nProfiles = self.radacHeaderObj.npulses |
|
565 | self.dataOut.nProfiles = self.radacHeaderObj.npulses | |
523 | self.dataOut.nRecords = self.radacHeaderObj.nrecords |
|
566 | self.dataOut.nRecords = self.radacHeaderObj.nrecords | |
524 | self.dataOut.nBeams = self.radacHeaderObj.nbeams |
|
567 | self.dataOut.nBeams = self.radacHeaderObj.nbeams | |
525 | self.dataOut.ippSeconds = self.ippSeconds_fromfile |
|
568 | self.dataOut.ippSeconds = self.ippSeconds_fromfile | |
526 | self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
569 | self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
527 | self.dataOut.frequency = self.frequency_h5file |
|
570 | self.dataOut.frequency = self.frequency_h5file | |
528 | self.dataOut.npulseByFrame = self.npulseByFrame |
|
571 | self.dataOut.npulseByFrame = self.npulseByFrame | |
529 | self.dataOut.nBaud = None |
|
572 | self.dataOut.nBaud = None | |
530 | self.dataOut.nCode = None |
|
573 | self.dataOut.nCode = None | |
531 | self.dataOut.code = None |
|
574 | self.dataOut.code = None | |
532 |
|
575 | |||
533 | self.dataOut.beamCodeDict = self.beamCodeDict |
|
576 | self.dataOut.beamCodeDict = self.beamCodeDict | |
534 | self.dataOut.beamRangeDict = self.beamRangeDict |
|
577 | self.dataOut.beamRangeDict = self.beamRangeDict | |
535 |
|
578 | |||
536 | if self.timezone == 'lt': |
|
579 | if self.timezone == 'lt': | |
537 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes |
|
580 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes | |
538 | else: |
|
581 | else: | |
539 | self.dataOut.timeZone = 0 #by default time is UTC |
|
582 | self.dataOut.timeZone = 0 #by default time is UTC | |
540 |
|
583 | |||
541 | def getData(self): |
|
584 | def getData(self): | |
542 |
|
585 | |||
543 | if self.flagNoMoreFiles: |
|
586 | if self.flagNoMoreFiles: | |
544 | self.dataOut.flagNoData = True |
|
587 | self.dataOut.flagNoData = True | |
545 | print 'Process finished' |
|
588 | print 'Process finished' | |
546 | return 0 |
|
589 | return 0 | |
547 |
|
590 | |||
548 | if self.__hasNotDataInBuffer(): |
|
591 | if self.__hasNotDataInBuffer(): | |
549 | self.readNextBlock() |
|
592 | self.readNextBlock() | |
550 |
|
593 | |||
551 |
|
594 | |||
552 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
595 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers | |
553 | self.dataOut.flagNoData = True |
|
596 | self.dataOut.flagNoData = True | |
554 | return 0 |
|
597 | return 0 | |
555 |
|
598 | |||
556 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) |
|
599 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) | |
557 |
|
600 | |||
558 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] |
|
601 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] | |
559 |
|
602 | |||
560 | self.dataOut.flagNoData = False |
|
603 | self.dataOut.flagNoData = False | |
561 |
|
604 | |||
562 | self.profileIndex += 1 |
|
605 | self.profileIndex += 1 | |
563 |
|
606 | |||
564 | return self.dataOut.data |
|
607 | return self.dataOut.data | |
565 |
|
608 | |||
566 |
|
609 | |||
567 | def run(self, **kwargs): |
|
610 | def run(self, **kwargs): | |
568 | if not(self.isConfig): |
|
611 | if not(self.isConfig): | |
569 | self.setup(**kwargs) |
|
612 | self.setup(**kwargs) | |
570 | self.setObjProperties() |
|
613 | self.setObjProperties() | |
571 | self.isConfig = True |
|
614 | self.isConfig = True | |
572 |
|
615 | |||
573 | self.getData() |
|
616 | self.getData() |
@@ -1,87 +1,91 | |||||
1 | ''' |
|
1 | ''' | |
2 | @author: Daniel Suarez |
|
2 | @author: Daniel Suarez | |
3 | ''' |
|
3 | ''' | |
4 |
|
4 | |||
5 | from jroproc_base import ProcessingUnit, Operation |
|
5 | from jroproc_base import ProcessingUnit, Operation | |
6 | from model.data.jroamisr import AMISR |
|
6 | from model.data.jroamisr import AMISR | |
7 |
|
7 | |||
8 | class AMISRProc(ProcessingUnit): |
|
8 | class AMISRProc(ProcessingUnit): | |
9 | def __init__(self): |
|
9 | def __init__(self): | |
10 | ProcessingUnit.__init__(self) |
|
10 | ProcessingUnit.__init__(self) | |
11 | self.objectDict = {} |
|
11 | self.objectDict = {} | |
12 | self.dataOut = AMISR() |
|
12 | self.dataOut = AMISR() | |
13 |
|
13 | |||
14 | def run(self): |
|
14 | def run(self): | |
15 | if self.dataIn.type == 'AMISR': |
|
15 | if self.dataIn.type == 'AMISR': | |
16 | self.dataOut.copy(self.dataIn) |
|
16 | self.dataOut.copy(self.dataIn) | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | class PrintInfo(Operation): |
|
19 | class PrintInfo(Operation): | |
20 | def __init__(self): |
|
20 | def __init__(self): | |
21 | self.__isPrinted = False |
|
21 | self.__isPrinted = False | |
22 |
|
22 | |||
23 | def run(self, dataOut): |
|
23 | def run(self, dataOut): | |
24 |
|
24 | |||
25 | if not self.__isPrinted: |
|
25 | if not self.__isPrinted: | |
26 | print 'Number of Records by File: %d'%dataOut.nRecords |
|
26 | print 'Number of Records by File: %d'%dataOut.nRecords | |
27 | print 'Number of Pulses: %d'%dataOut.nProfiles |
|
27 | print 'Number of Pulses: %d'%dataOut.nProfiles | |
28 | print 'Number of Pulses by Frame: %d'%dataOut.npulseByFrame |
|
28 | print 'Number of Pulses by Frame: %d'%dataOut.npulseByFrame | |
29 | print 'Number of Samples by Pulse: %d'%len(dataOut.heightList) |
|
29 | print 'Number of Samples by Pulse: %d'%len(dataOut.heightList) | |
30 | print 'Ipp Seconds: %f'%dataOut.ippSeconds |
|
30 | print 'Ipp Seconds: %f'%dataOut.ippSeconds | |
31 | print 'Number of Beams: %d'%dataOut.nBeams |
|
31 | print 'Number of Beams: %d'%dataOut.nBeams | |
32 | print 'BeamCodes:' |
|
32 | print 'BeamCodes:' | |
33 |
beamStrList = ['Beam %d -> Code |
|
33 | beamStrList = ['Beam %d -> Code=%d, azimuth=%2.2f, zenith=%2.2f, gain=%2.2f'%(k,v[0],v[1],v[2],v[3]) for k,v in dataOut.beamCodeDict.items()] | |
34 | for b in beamStrList: |
|
34 | for b in beamStrList: | |
35 | print b |
|
35 | print b | |
36 | self.__isPrinted = True |
|
36 | self.__isPrinted = True | |
37 |
|
37 | |||
38 | return |
|
38 | return | |
39 |
|
39 | |||
40 |
|
40 | |||
41 | class BeamSelector(Operation): |
|
41 | class BeamSelector(Operation): | |
42 | profileIndex = None |
|
42 | profileIndex = None | |
43 | nProfiles = None |
|
43 | nProfiles = None | |
44 |
|
44 | |||
45 | def __init__(self): |
|
45 | def __init__(self): | |
46 |
|
46 | |||
47 | self.profileIndex = 0 |
|
47 | self.profileIndex = 0 | |
48 |
|
48 | |||
49 | def incIndex(self): |
|
49 | def incIndex(self): | |
50 | self.profileIndex += 1 |
|
50 | self.profileIndex += 1 | |
51 |
|
51 | |||
52 | if self.profileIndex >= self.nProfiles: |
|
52 | if self.profileIndex >= self.nProfiles: | |
53 | self.profileIndex = 0 |
|
53 | self.profileIndex = 0 | |
54 |
|
54 | |||
55 | def isProfileInRange(self, minIndex, maxIndex): |
|
55 | def isProfileInRange(self, minIndex, maxIndex): | |
56 |
|
56 | |||
57 | if self.profileIndex < minIndex: |
|
57 | if self.profileIndex < minIndex: | |
58 | return False |
|
58 | return False | |
59 |
|
59 | |||
60 | if self.profileIndex > maxIndex: |
|
60 | if self.profileIndex > maxIndex: | |
61 | return False |
|
61 | return False | |
62 |
|
62 | |||
63 | return True |
|
63 | return True | |
64 |
|
64 | |||
65 | def isProfileInList(self, profileList): |
|
65 | def isProfileInList(self, profileList): | |
66 |
|
66 | |||
67 | if self.profileIndex not in profileList: |
|
67 | if self.profileIndex not in profileList: | |
68 | return False |
|
68 | return False | |
69 |
|
69 | |||
70 | return True |
|
70 | return True | |
71 |
|
71 | |||
72 | def run(self, dataOut, beam=None): |
|
72 | def run(self, dataOut, beam=None): | |
73 |
|
73 | |||
74 | dataOut.flagNoData = True |
|
74 | dataOut.flagNoData = True | |
75 | self.nProfiles = dataOut.nProfiles |
|
75 | self.nProfiles = dataOut.nProfiles | |
76 |
|
76 | |||
77 | if beam != None: |
|
77 | if beam != None: | |
78 | if self.isProfileInList(dataOut.beamRangeDict[beam]): |
|
78 | if self.isProfileInList(dataOut.beamRangeDict[beam]): | |
|
79 | beamInfo = dataOut.beamCodeDict[beam] | |||
|
80 | dataOut.azimuth = beamInfo[1] | |||
|
81 | dataOut.zenith = beamInfo[2] | |||
|
82 | dataOut.gain = beamInfo[3] | |||
79 | dataOut.flagNoData = False |
|
83 | dataOut.flagNoData = False | |
80 |
|
84 | |||
81 | self.incIndex() |
|
85 | self.incIndex() | |
82 | return 1 |
|
86 | return 1 | |
83 |
|
87 | |||
84 | else: |
|
88 | else: | |
85 | raise ValueError, "BeamSelector needs beam value" |
|
89 | raise ValueError, "BeamSelector needs beam value" | |
86 |
|
90 | |||
87 | return 0 No newline at end of file |
|
91 | return 0 |
@@ -1,927 +1,930 | |||||
1 | import numpy |
|
1 | import numpy | |
2 |
|
2 | |||
3 | from jroproc_base import ProcessingUnit, Operation |
|
3 | from jroproc_base import ProcessingUnit, Operation | |
4 | from model.data.jrodata import Spectra |
|
4 | from model.data.jrodata import Spectra | |
5 | from model.data.jrodata import hildebrand_sekhon |
|
5 | from model.data.jrodata import hildebrand_sekhon | |
6 |
|
6 | |||
7 | class SpectraProc(ProcessingUnit): |
|
7 | class SpectraProc(ProcessingUnit): | |
8 |
|
8 | |||
9 | def __init__(self): |
|
9 | def __init__(self): | |
10 |
|
10 | |||
11 | ProcessingUnit.__init__(self) |
|
11 | ProcessingUnit.__init__(self) | |
12 |
|
12 | |||
13 | self.buffer = None |
|
13 | self.buffer = None | |
14 | self.firstdatatime = None |
|
14 | self.firstdatatime = None | |
15 | self.profIndex = 0 |
|
15 | self.profIndex = 0 | |
16 | self.dataOut = Spectra() |
|
16 | self.dataOut = Spectra() | |
17 | self.id_min = None |
|
17 | self.id_min = None | |
18 | self.id_max = None |
|
18 | self.id_max = None | |
19 |
|
19 | |||
20 | def __updateObjFromInput(self): |
|
20 | def __updateObjFromInput(self): | |
21 |
|
21 | |||
22 | self.dataOut.timeZone = self.dataIn.timeZone |
|
22 | self.dataOut.timeZone = self.dataIn.timeZone | |
23 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
23 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
24 | self.dataOut.errorCount = self.dataIn.errorCount |
|
24 | self.dataOut.errorCount = self.dataIn.errorCount | |
25 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
25 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
26 |
|
26 | |||
27 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
27 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
28 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
28 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
29 | self.dataOut.channelList = self.dataIn.channelList |
|
29 | self.dataOut.channelList = self.dataIn.channelList | |
30 | self.dataOut.heightList = self.dataIn.heightList |
|
30 | self.dataOut.heightList = self.dataIn.heightList | |
31 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
31 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
32 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
32 | # self.dataOut.nHeights = self.dataIn.nHeights | |
33 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
33 | # self.dataOut.nChannels = self.dataIn.nChannels | |
34 | self.dataOut.nBaud = self.dataIn.nBaud |
|
34 | self.dataOut.nBaud = self.dataIn.nBaud | |
35 | self.dataOut.nCode = self.dataIn.nCode |
|
35 | self.dataOut.nCode = self.dataIn.nCode | |
36 | self.dataOut.code = self.dataIn.code |
|
36 | self.dataOut.code = self.dataIn.code | |
37 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
37 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
38 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
38 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
39 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
39 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
40 | self.dataOut.utctime = self.firstdatatime |
|
40 | self.dataOut.utctime = self.firstdatatime | |
41 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
41 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
42 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
42 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
43 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
43 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
44 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
44 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
45 | self.dataOut.nIncohInt = 1 |
|
45 | self.dataOut.nIncohInt = 1 | |
46 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
46 | # self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
47 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
47 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
48 |
|
48 | |||
49 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
49 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
50 | self.dataOut.frequency = self.dataIn.frequency |
|
50 | self.dataOut.frequency = self.dataIn.frequency | |
51 | self.dataOut.realtime = self.dataIn.realtime |
|
51 | self.dataOut.realtime = self.dataIn.realtime | |
52 |
|
52 | |||
|
53 | self.dataOut.azimuth = self.dataIn.azimuth | |||
|
54 | self.dataOut.zenith = self.dataIn.zenith | |||
|
55 | ||||
53 | def __getFft(self): |
|
56 | def __getFft(self): | |
54 | """ |
|
57 | """ | |
55 | Convierte valores de Voltaje a Spectra |
|
58 | Convierte valores de Voltaje a Spectra | |
56 |
|
59 | |||
57 | Affected: |
|
60 | Affected: | |
58 | self.dataOut.data_spc |
|
61 | self.dataOut.data_spc | |
59 | self.dataOut.data_cspc |
|
62 | self.dataOut.data_cspc | |
60 | self.dataOut.data_dc |
|
63 | self.dataOut.data_dc | |
61 | self.dataOut.heightList |
|
64 | self.dataOut.heightList | |
62 | self.profIndex |
|
65 | self.profIndex | |
63 | self.buffer |
|
66 | self.buffer | |
64 | self.dataOut.flagNoData |
|
67 | self.dataOut.flagNoData | |
65 | """ |
|
68 | """ | |
66 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) |
|
69 | fft_volt = numpy.fft.fft(self.buffer,n=self.dataOut.nFFTPoints,axis=1) | |
67 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
70 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
68 | dc = fft_volt[:,0,:] |
|
71 | dc = fft_volt[:,0,:] | |
69 |
|
72 | |||
70 | #calculo de self-spectra |
|
73 | #calculo de self-spectra | |
71 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
74 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
72 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
75 | spc = fft_volt * numpy.conjugate(fft_volt) | |
73 | spc = spc.real |
|
76 | spc = spc.real | |
74 |
|
77 | |||
75 | blocksize = 0 |
|
78 | blocksize = 0 | |
76 | blocksize += dc.size |
|
79 | blocksize += dc.size | |
77 | blocksize += spc.size |
|
80 | blocksize += spc.size | |
78 |
|
81 | |||
79 | cspc = None |
|
82 | cspc = None | |
80 | pairIndex = 0 |
|
83 | pairIndex = 0 | |
81 | if self.dataOut.pairsList != None: |
|
84 | if self.dataOut.pairsList != None: | |
82 | #calculo de cross-spectra |
|
85 | #calculo de cross-spectra | |
83 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
86 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
84 | for pair in self.dataOut.pairsList: |
|
87 | for pair in self.dataOut.pairsList: | |
85 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
88 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) | |
86 | pairIndex += 1 |
|
89 | pairIndex += 1 | |
87 | blocksize += cspc.size |
|
90 | blocksize += cspc.size | |
88 |
|
91 | |||
89 | self.dataOut.data_spc = spc |
|
92 | self.dataOut.data_spc = spc | |
90 | self.dataOut.data_cspc = cspc |
|
93 | self.dataOut.data_cspc = cspc | |
91 | self.dataOut.data_dc = dc |
|
94 | self.dataOut.data_dc = dc | |
92 | self.dataOut.blockSize = blocksize |
|
95 | self.dataOut.blockSize = blocksize | |
93 | self.dataOut.flagShiftFFT = False |
|
96 | self.dataOut.flagShiftFFT = False | |
94 |
|
97 | |||
95 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None): |
|
98 | def run(self, nProfiles=None, nFFTPoints=None, pairsList=[], ippFactor=None): | |
96 |
|
99 | |||
97 | self.dataOut.flagNoData = True |
|
100 | self.dataOut.flagNoData = True | |
98 |
|
101 | |||
99 | if self.dataIn.type == "Spectra": |
|
102 | if self.dataIn.type == "Spectra": | |
100 | self.dataOut.copy(self.dataIn) |
|
103 | self.dataOut.copy(self.dataIn) | |
101 | return True |
|
104 | return True | |
102 |
|
105 | |||
103 | if self.dataIn.type == "Voltage": |
|
106 | if self.dataIn.type == "Voltage": | |
104 |
|
107 | |||
105 | if nFFTPoints == None: |
|
108 | if nFFTPoints == None: | |
106 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" |
|
109 | raise ValueError, "This SpectraProc.run() need nFFTPoints input variable" | |
107 |
|
110 | |||
108 | if nProfiles == None: |
|
111 | if nProfiles == None: | |
109 | raise ValueError, "This SpectraProc.run() need nProfiles input variable" |
|
112 | raise ValueError, "This SpectraProc.run() need nProfiles input variable" | |
110 |
|
113 | |||
111 |
|
114 | |||
112 | if ippFactor == None: |
|
115 | if ippFactor == None: | |
113 | ippFactor = 1 |
|
116 | ippFactor = 1 | |
114 | self.dataOut.ippFactor = ippFactor |
|
117 | self.dataOut.ippFactor = ippFactor | |
115 |
|
118 | |||
116 | self.dataOut.nFFTPoints = nFFTPoints |
|
119 | self.dataOut.nFFTPoints = nFFTPoints | |
117 | self.dataOut.pairsList = pairsList |
|
120 | self.dataOut.pairsList = pairsList | |
118 |
|
121 | |||
119 | if self.buffer == None: |
|
122 | if self.buffer == None: | |
120 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
123 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
121 | nProfiles, |
|
124 | nProfiles, | |
122 | self.dataIn.nHeights), |
|
125 | self.dataIn.nHeights), | |
123 | dtype='complex') |
|
126 | dtype='complex') | |
124 | self.id_min = 0 |
|
127 | self.id_min = 0 | |
125 | self.id_max = self.dataIn.data.shape[1] |
|
128 | self.id_max = self.dataIn.data.shape[1] | |
126 |
|
129 | |||
127 | if len(self.dataIn.data.shape) == 2: |
|
130 | if len(self.dataIn.data.shape) == 2: | |
128 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
131 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() | |
129 | self.profIndex += 1 |
|
132 | self.profIndex += 1 | |
130 | else: |
|
133 | else: | |
131 | if self.dataIn.data.shape[1] == nProfiles: |
|
134 | if self.dataIn.data.shape[1] == nProfiles: | |
132 | self.buffer = self.dataIn.data.copy() |
|
135 | self.buffer = self.dataIn.data.copy() | |
133 | self.profIndex = nProfiles |
|
136 | self.profIndex = nProfiles | |
134 | elif self.dataIn.data.shape[1] < nProfiles: |
|
137 | elif self.dataIn.data.shape[1] < nProfiles: | |
135 | self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data |
|
138 | self.buffer[:,self.id_min:self.id_max,:] = self.dataIn.data | |
136 | self.profIndex += self.dataIn.data.shape[1] |
|
139 | self.profIndex += self.dataIn.data.shape[1] | |
137 | self.id_min += self.dataIn.data.shape[1] |
|
140 | self.id_min += self.dataIn.data.shape[1] | |
138 | self.id_max += self.dataIn.data.shape[1] |
|
141 | self.id_max += self.dataIn.data.shape[1] | |
139 | else: |
|
142 | else: | |
140 | raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles) |
|
143 | raise ValueError, "The type object %s has %d profiles, it should be equal to %d profiles"%(self.dataIn.type,self.dataIn.data.shape[1],nProfiles) | |
141 | self.dataOut.flagNoData = True |
|
144 | self.dataOut.flagNoData = True | |
142 | return 0 |
|
145 | return 0 | |
143 |
|
146 | |||
144 |
|
147 | |||
145 | if self.firstdatatime == None: |
|
148 | if self.firstdatatime == None: | |
146 | self.firstdatatime = self.dataIn.utctime |
|
149 | self.firstdatatime = self.dataIn.utctime | |
147 |
|
150 | |||
148 | if self.profIndex == nProfiles: |
|
151 | if self.profIndex == nProfiles: | |
149 | self.__updateObjFromInput() |
|
152 | self.__updateObjFromInput() | |
150 | self.__getFft() |
|
153 | self.__getFft() | |
151 |
|
154 | |||
152 | self.dataOut.flagNoData = False |
|
155 | self.dataOut.flagNoData = False | |
153 |
|
156 | |||
154 | self.buffer = None |
|
157 | self.buffer = None | |
155 | self.firstdatatime = None |
|
158 | self.firstdatatime = None | |
156 | self.profIndex = 0 |
|
159 | self.profIndex = 0 | |
157 |
|
160 | |||
158 | return True |
|
161 | return True | |
159 |
|
162 | |||
160 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
163 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) | |
161 |
|
164 | |||
162 | def selectChannels(self, channelList): |
|
165 | def selectChannels(self, channelList): | |
163 |
|
166 | |||
164 | channelIndexList = [] |
|
167 | channelIndexList = [] | |
165 |
|
168 | |||
166 | for channel in channelList: |
|
169 | for channel in channelList: | |
167 | index = self.dataOut.channelList.index(channel) |
|
170 | index = self.dataOut.channelList.index(channel) | |
168 | channelIndexList.append(index) |
|
171 | channelIndexList.append(index) | |
169 |
|
172 | |||
170 | self.selectChannelsByIndex(channelIndexList) |
|
173 | self.selectChannelsByIndex(channelIndexList) | |
171 |
|
174 | |||
172 | def selectChannelsByIndex(self, channelIndexList): |
|
175 | def selectChannelsByIndex(self, channelIndexList): | |
173 | """ |
|
176 | """ | |
174 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
177 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
175 |
|
178 | |||
176 | Input: |
|
179 | Input: | |
177 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
180 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
178 |
|
181 | |||
179 | Affected: |
|
182 | Affected: | |
180 | self.dataOut.data_spc |
|
183 | self.dataOut.data_spc | |
181 | self.dataOut.channelIndexList |
|
184 | self.dataOut.channelIndexList | |
182 | self.dataOut.nChannels |
|
185 | self.dataOut.nChannels | |
183 |
|
186 | |||
184 | Return: |
|
187 | Return: | |
185 | None |
|
188 | None | |
186 | """ |
|
189 | """ | |
187 |
|
190 | |||
188 | for channelIndex in channelIndexList: |
|
191 | for channelIndex in channelIndexList: | |
189 | if channelIndex not in self.dataOut.channelIndexList: |
|
192 | if channelIndex not in self.dataOut.channelIndexList: | |
190 | print channelIndexList |
|
193 | print channelIndexList | |
191 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
194 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
192 |
|
195 | |||
193 | # nChannels = len(channelIndexList) |
|
196 | # nChannels = len(channelIndexList) | |
194 |
|
197 | |||
195 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
198 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
196 |
|
199 | |||
197 | self.dataOut.data_spc = data_spc |
|
200 | self.dataOut.data_spc = data_spc | |
198 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
201 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
199 | # self.dataOut.nChannels = nChannels |
|
202 | # self.dataOut.nChannels = nChannels | |
200 |
|
203 | |||
201 | return 1 |
|
204 | return 1 | |
202 |
|
205 | |||
203 | def selectHeights(self, minHei, maxHei): |
|
206 | def selectHeights(self, minHei, maxHei): | |
204 | """ |
|
207 | """ | |
205 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
208 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
206 | minHei <= height <= maxHei |
|
209 | minHei <= height <= maxHei | |
207 |
|
210 | |||
208 | Input: |
|
211 | Input: | |
209 | minHei : valor minimo de altura a considerar |
|
212 | minHei : valor minimo de altura a considerar | |
210 | maxHei : valor maximo de altura a considerar |
|
213 | maxHei : valor maximo de altura a considerar | |
211 |
|
214 | |||
212 | Affected: |
|
215 | Affected: | |
213 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
216 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
214 |
|
217 | |||
215 | Return: |
|
218 | Return: | |
216 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
219 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
217 | """ |
|
220 | """ | |
218 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
221 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
219 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
222 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
220 |
|
223 | |||
221 | if (maxHei > self.dataOut.heightList[-1]): |
|
224 | if (maxHei > self.dataOut.heightList[-1]): | |
222 | maxHei = self.dataOut.heightList[-1] |
|
225 | maxHei = self.dataOut.heightList[-1] | |
223 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
226 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
224 |
|
227 | |||
225 | minIndex = 0 |
|
228 | minIndex = 0 | |
226 | maxIndex = 0 |
|
229 | maxIndex = 0 | |
227 | heights = self.dataOut.heightList |
|
230 | heights = self.dataOut.heightList | |
228 |
|
231 | |||
229 | inda = numpy.where(heights >= minHei) |
|
232 | inda = numpy.where(heights >= minHei) | |
230 | indb = numpy.where(heights <= maxHei) |
|
233 | indb = numpy.where(heights <= maxHei) | |
231 |
|
234 | |||
232 | try: |
|
235 | try: | |
233 | minIndex = inda[0][0] |
|
236 | minIndex = inda[0][0] | |
234 | except: |
|
237 | except: | |
235 | minIndex = 0 |
|
238 | minIndex = 0 | |
236 |
|
239 | |||
237 | try: |
|
240 | try: | |
238 | maxIndex = indb[0][-1] |
|
241 | maxIndex = indb[0][-1] | |
239 | except: |
|
242 | except: | |
240 | maxIndex = len(heights) |
|
243 | maxIndex = len(heights) | |
241 |
|
244 | |||
242 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
245 | self.selectHeightsByIndex(minIndex, maxIndex) | |
243 |
|
246 | |||
244 | return 1 |
|
247 | return 1 | |
245 |
|
248 | |||
246 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): |
|
249 | def getBeaconSignal(self, tauindex = 0, channelindex = 0, hei_ref=None): | |
247 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) |
|
250 | newheis = numpy.where(self.dataOut.heightList>self.dataOut.radarControllerHeaderObj.Taus[tauindex]) | |
248 |
|
251 | |||
249 | if hei_ref != None: |
|
252 | if hei_ref != None: | |
250 | newheis = numpy.where(self.dataOut.heightList>hei_ref) |
|
253 | newheis = numpy.where(self.dataOut.heightList>hei_ref) | |
251 |
|
254 | |||
252 | minIndex = min(newheis[0]) |
|
255 | minIndex = min(newheis[0]) | |
253 | maxIndex = max(newheis[0]) |
|
256 | maxIndex = max(newheis[0]) | |
254 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
257 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
255 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
258 | heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
256 |
|
259 | |||
257 | # determina indices |
|
260 | # determina indices | |
258 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) |
|
261 | nheis = int(self.dataOut.radarControllerHeaderObj.txB/(self.dataOut.heightList[1]-self.dataOut.heightList[0])) | |
259 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) |
|
262 | avg_dB = 10*numpy.log10(numpy.sum(data_spc[channelindex,:,:],axis=0)) | |
260 | beacon_dB = numpy.sort(avg_dB)[-nheis:] |
|
263 | beacon_dB = numpy.sort(avg_dB)[-nheis:] | |
261 | beacon_heiIndexList = [] |
|
264 | beacon_heiIndexList = [] | |
262 | for val in avg_dB.tolist(): |
|
265 | for val in avg_dB.tolist(): | |
263 | if val >= beacon_dB[0]: |
|
266 | if val >= beacon_dB[0]: | |
264 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) |
|
267 | beacon_heiIndexList.append(avg_dB.tolist().index(val)) | |
265 |
|
268 | |||
266 | #data_spc = data_spc[:,:,beacon_heiIndexList] |
|
269 | #data_spc = data_spc[:,:,beacon_heiIndexList] | |
267 | data_cspc = None |
|
270 | data_cspc = None | |
268 | if self.dataOut.data_cspc != None: |
|
271 | if self.dataOut.data_cspc != None: | |
269 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
272 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
270 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] |
|
273 | #data_cspc = data_cspc[:,:,beacon_heiIndexList] | |
271 |
|
274 | |||
272 | data_dc = None |
|
275 | data_dc = None | |
273 | if self.dataOut.data_dc != None: |
|
276 | if self.dataOut.data_dc != None: | |
274 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
277 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
275 | #data_dc = data_dc[:,beacon_heiIndexList] |
|
278 | #data_dc = data_dc[:,beacon_heiIndexList] | |
276 |
|
279 | |||
277 | self.dataOut.data_spc = data_spc |
|
280 | self.dataOut.data_spc = data_spc | |
278 | self.dataOut.data_cspc = data_cspc |
|
281 | self.dataOut.data_cspc = data_cspc | |
279 | self.dataOut.data_dc = data_dc |
|
282 | self.dataOut.data_dc = data_dc | |
280 | self.dataOut.heightList = heightList |
|
283 | self.dataOut.heightList = heightList | |
281 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList |
|
284 | self.dataOut.beacon_heiIndexList = beacon_heiIndexList | |
282 |
|
285 | |||
283 | return 1 |
|
286 | return 1 | |
284 |
|
287 | |||
285 |
|
288 | |||
286 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
289 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
287 | """ |
|
290 | """ | |
288 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
291 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
289 | minIndex <= index <= maxIndex |
|
292 | minIndex <= index <= maxIndex | |
290 |
|
293 | |||
291 | Input: |
|
294 | Input: | |
292 | minIndex : valor de indice minimo de altura a considerar |
|
295 | minIndex : valor de indice minimo de altura a considerar | |
293 | maxIndex : valor de indice maximo de altura a considerar |
|
296 | maxIndex : valor de indice maximo de altura a considerar | |
294 |
|
297 | |||
295 | Affected: |
|
298 | Affected: | |
296 | self.dataOut.data_spc |
|
299 | self.dataOut.data_spc | |
297 | self.dataOut.data_cspc |
|
300 | self.dataOut.data_cspc | |
298 | self.dataOut.data_dc |
|
301 | self.dataOut.data_dc | |
299 | self.dataOut.heightList |
|
302 | self.dataOut.heightList | |
300 |
|
303 | |||
301 | Return: |
|
304 | Return: | |
302 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
305 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
303 | """ |
|
306 | """ | |
304 |
|
307 | |||
305 | if (minIndex < 0) or (minIndex > maxIndex): |
|
308 | if (minIndex < 0) or (minIndex > maxIndex): | |
306 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
309 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
307 |
|
310 | |||
308 | if (maxIndex >= self.dataOut.nHeights): |
|
311 | if (maxIndex >= self.dataOut.nHeights): | |
309 | maxIndex = self.dataOut.nHeights-1 |
|
312 | maxIndex = self.dataOut.nHeights-1 | |
310 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
313 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
311 |
|
314 | |||
312 | # nHeights = maxIndex - minIndex + 1 |
|
315 | # nHeights = maxIndex - minIndex + 1 | |
313 |
|
316 | |||
314 | #Spectra |
|
317 | #Spectra | |
315 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
318 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
316 |
|
319 | |||
317 | data_cspc = None |
|
320 | data_cspc = None | |
318 | if self.dataOut.data_cspc != None: |
|
321 | if self.dataOut.data_cspc != None: | |
319 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
322 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
320 |
|
323 | |||
321 | data_dc = None |
|
324 | data_dc = None | |
322 | if self.dataOut.data_dc != None: |
|
325 | if self.dataOut.data_dc != None: | |
323 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
326 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
324 |
|
327 | |||
325 | self.dataOut.data_spc = data_spc |
|
328 | self.dataOut.data_spc = data_spc | |
326 | self.dataOut.data_cspc = data_cspc |
|
329 | self.dataOut.data_cspc = data_cspc | |
327 | self.dataOut.data_dc = data_dc |
|
330 | self.dataOut.data_dc = data_dc | |
328 |
|
331 | |||
329 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
332 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
330 |
|
333 | |||
331 | return 1 |
|
334 | return 1 | |
332 |
|
335 | |||
333 | def removeDC(self, mode = 2): |
|
336 | def removeDC(self, mode = 2): | |
334 | jspectra = self.dataOut.data_spc |
|
337 | jspectra = self.dataOut.data_spc | |
335 | jcspectra = self.dataOut.data_cspc |
|
338 | jcspectra = self.dataOut.data_cspc | |
336 |
|
339 | |||
337 |
|
340 | |||
338 | num_chan = jspectra.shape[0] |
|
341 | num_chan = jspectra.shape[0] | |
339 | num_hei = jspectra.shape[2] |
|
342 | num_hei = jspectra.shape[2] | |
340 |
|
343 | |||
341 | if jcspectra != None: |
|
344 | if jcspectra != None: | |
342 | jcspectraExist = True |
|
345 | jcspectraExist = True | |
343 | num_pairs = jcspectra.shape[0] |
|
346 | num_pairs = jcspectra.shape[0] | |
344 | else: jcspectraExist = False |
|
347 | else: jcspectraExist = False | |
345 |
|
348 | |||
346 | freq_dc = jspectra.shape[1]/2 |
|
349 | freq_dc = jspectra.shape[1]/2 | |
347 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
350 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc | |
348 |
|
351 | |||
349 | if ind_vel[0]<0: |
|
352 | if ind_vel[0]<0: | |
350 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
353 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof | |
351 |
|
354 | |||
352 | if mode == 1: |
|
355 | if mode == 1: | |
353 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
356 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION | |
354 |
|
357 | |||
355 | if jcspectraExist: |
|
358 | if jcspectraExist: | |
356 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 |
|
359 | jcspectra[:,freq_dc,:] = (jcspectra[:,ind_vel[1],:] + jcspectra[:,ind_vel[2],:])/2 | |
357 |
|
360 | |||
358 | if mode == 2: |
|
361 | if mode == 2: | |
359 |
|
362 | |||
360 | vel = numpy.array([-2,-1,1,2]) |
|
363 | vel = numpy.array([-2,-1,1,2]) | |
361 | xx = numpy.zeros([4,4]) |
|
364 | xx = numpy.zeros([4,4]) | |
362 |
|
365 | |||
363 | for fil in range(4): |
|
366 | for fil in range(4): | |
364 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
367 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) | |
365 |
|
368 | |||
366 | xx_inv = numpy.linalg.inv(xx) |
|
369 | xx_inv = numpy.linalg.inv(xx) | |
367 | xx_aux = xx_inv[0,:] |
|
370 | xx_aux = xx_inv[0,:] | |
368 |
|
371 | |||
369 | for ich in range(num_chan): |
|
372 | for ich in range(num_chan): | |
370 | yy = jspectra[ich,ind_vel,:] |
|
373 | yy = jspectra[ich,ind_vel,:] | |
371 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
374 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) | |
372 |
|
375 | |||
373 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
376 | junkid = jspectra[ich,freq_dc,:]<=0 | |
374 | cjunkid = sum(junkid) |
|
377 | cjunkid = sum(junkid) | |
375 |
|
378 | |||
376 | if cjunkid.any(): |
|
379 | if cjunkid.any(): | |
377 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
380 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 | |
378 |
|
381 | |||
379 | if jcspectraExist: |
|
382 | if jcspectraExist: | |
380 | for ip in range(num_pairs): |
|
383 | for ip in range(num_pairs): | |
381 | yy = jcspectra[ip,ind_vel,:] |
|
384 | yy = jcspectra[ip,ind_vel,:] | |
382 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
385 | jcspectra[ip,freq_dc,:] = numpy.dot(xx_aux,yy) | |
383 |
|
386 | |||
384 |
|
387 | |||
385 | self.dataOut.data_spc = jspectra |
|
388 | self.dataOut.data_spc = jspectra | |
386 | self.dataOut.data_cspc = jcspectra |
|
389 | self.dataOut.data_cspc = jcspectra | |
387 |
|
390 | |||
388 | return 1 |
|
391 | return 1 | |
389 |
|
392 | |||
390 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): |
|
393 | def removeInterference(self, interf = 2,hei_interf = None, nhei_interf = None, offhei_interf = None): | |
391 |
|
394 | |||
392 | jspectra = self.dataOut.data_spc |
|
395 | jspectra = self.dataOut.data_spc | |
393 | jcspectra = self.dataOut.data_cspc |
|
396 | jcspectra = self.dataOut.data_cspc | |
394 | jnoise = self.dataOut.getNoise() |
|
397 | jnoise = self.dataOut.getNoise() | |
395 | num_incoh = self.dataOut.nIncohInt |
|
398 | num_incoh = self.dataOut.nIncohInt | |
396 |
|
399 | |||
397 | num_channel = jspectra.shape[0] |
|
400 | num_channel = jspectra.shape[0] | |
398 | num_prof = jspectra.shape[1] |
|
401 | num_prof = jspectra.shape[1] | |
399 | num_hei = jspectra.shape[2] |
|
402 | num_hei = jspectra.shape[2] | |
400 |
|
403 | |||
401 | #hei_interf |
|
404 | #hei_interf | |
402 | if hei_interf == None: |
|
405 | if hei_interf == None: | |
403 | count_hei = num_hei/2 #Como es entero no importa |
|
406 | count_hei = num_hei/2 #Como es entero no importa | |
404 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei |
|
407 | hei_interf = numpy.asmatrix(range(count_hei)) + num_hei - count_hei | |
405 | hei_interf = numpy.asarray(hei_interf)[0] |
|
408 | hei_interf = numpy.asarray(hei_interf)[0] | |
406 | #nhei_interf |
|
409 | #nhei_interf | |
407 | if (nhei_interf == None): |
|
410 | if (nhei_interf == None): | |
408 | nhei_interf = 5 |
|
411 | nhei_interf = 5 | |
409 | if (nhei_interf < 1): |
|
412 | if (nhei_interf < 1): | |
410 | nhei_interf = 1 |
|
413 | nhei_interf = 1 | |
411 | if (nhei_interf > count_hei): |
|
414 | if (nhei_interf > count_hei): | |
412 | nhei_interf = count_hei |
|
415 | nhei_interf = count_hei | |
413 | if (offhei_interf == None): |
|
416 | if (offhei_interf == None): | |
414 | offhei_interf = 0 |
|
417 | offhei_interf = 0 | |
415 |
|
418 | |||
416 | ind_hei = range(num_hei) |
|
419 | ind_hei = range(num_hei) | |
417 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 |
|
420 | # mask_prof = numpy.asarray(range(num_prof - 2)) + 1 | |
418 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 |
|
421 | # mask_prof[range(num_prof/2 - 1,len(mask_prof))] += 1 | |
419 | mask_prof = numpy.asarray(range(num_prof)) |
|
422 | mask_prof = numpy.asarray(range(num_prof)) | |
420 | num_mask_prof = mask_prof.size |
|
423 | num_mask_prof = mask_prof.size | |
421 | comp_mask_prof = [0, num_prof/2] |
|
424 | comp_mask_prof = [0, num_prof/2] | |
422 |
|
425 | |||
423 |
|
426 | |||
424 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal |
|
427 | #noise_exist: Determina si la variable jnoise ha sido definida y contiene la informacion del ruido de cada canal | |
425 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): |
|
428 | if (jnoise.size < num_channel or numpy.isnan(jnoise).any()): | |
426 | jnoise = numpy.nan |
|
429 | jnoise = numpy.nan | |
427 | noise_exist = jnoise[0] < numpy.Inf |
|
430 | noise_exist = jnoise[0] < numpy.Inf | |
428 |
|
431 | |||
429 | #Subrutina de Remocion de la Interferencia |
|
432 | #Subrutina de Remocion de la Interferencia | |
430 | for ich in range(num_channel): |
|
433 | for ich in range(num_channel): | |
431 | #Se ordena los espectros segun su potencia (menor a mayor) |
|
434 | #Se ordena los espectros segun su potencia (menor a mayor) | |
432 | power = jspectra[ich,mask_prof,:] |
|
435 | power = jspectra[ich,mask_prof,:] | |
433 | power = power[:,hei_interf] |
|
436 | power = power[:,hei_interf] | |
434 | power = power.sum(axis = 0) |
|
437 | power = power.sum(axis = 0) | |
435 | psort = power.ravel().argsort() |
|
438 | psort = power.ravel().argsort() | |
436 |
|
439 | |||
437 | #Se estima la interferencia promedio en los Espectros de Potencia empleando |
|
440 | #Se estima la interferencia promedio en los Espectros de Potencia empleando | |
438 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
441 | junkspc_interf = jspectra[ich,:,hei_interf[psort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
439 |
|
442 | |||
440 | if noise_exist: |
|
443 | if noise_exist: | |
441 | # tmp_noise = jnoise[ich] / num_prof |
|
444 | # tmp_noise = jnoise[ich] / num_prof | |
442 | tmp_noise = jnoise[ich] |
|
445 | tmp_noise = jnoise[ich] | |
443 | junkspc_interf = junkspc_interf - tmp_noise |
|
446 | junkspc_interf = junkspc_interf - tmp_noise | |
444 | #junkspc_interf[:,comp_mask_prof] = 0 |
|
447 | #junkspc_interf[:,comp_mask_prof] = 0 | |
445 |
|
448 | |||
446 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf |
|
449 | jspc_interf = junkspc_interf.sum(axis = 0) / nhei_interf | |
447 | jspc_interf = jspc_interf.transpose() |
|
450 | jspc_interf = jspc_interf.transpose() | |
448 | #Calculando el espectro de interferencia promedio |
|
451 | #Calculando el espectro de interferencia promedio | |
449 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) |
|
452 | noiseid = numpy.where(jspc_interf <= tmp_noise/ math.sqrt(num_incoh)) | |
450 | noiseid = noiseid[0] |
|
453 | noiseid = noiseid[0] | |
451 | cnoiseid = noiseid.size |
|
454 | cnoiseid = noiseid.size | |
452 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) |
|
455 | interfid = numpy.where(jspc_interf > tmp_noise/ math.sqrt(num_incoh)) | |
453 | interfid = interfid[0] |
|
456 | interfid = interfid[0] | |
454 | cinterfid = interfid.size |
|
457 | cinterfid = interfid.size | |
455 |
|
458 | |||
456 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 |
|
459 | if (cnoiseid > 0): jspc_interf[noiseid] = 0 | |
457 |
|
460 | |||
458 | #Expandiendo los perfiles a limpiar |
|
461 | #Expandiendo los perfiles a limpiar | |
459 | if (cinterfid > 0): |
|
462 | if (cinterfid > 0): | |
460 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof |
|
463 | new_interfid = (numpy.r_[interfid - 1, interfid, interfid + 1] + num_prof)%num_prof | |
461 | new_interfid = numpy.asarray(new_interfid) |
|
464 | new_interfid = numpy.asarray(new_interfid) | |
462 | new_interfid = {x for x in new_interfid} |
|
465 | new_interfid = {x for x in new_interfid} | |
463 | new_interfid = numpy.array(list(new_interfid)) |
|
466 | new_interfid = numpy.array(list(new_interfid)) | |
464 | new_cinterfid = new_interfid.size |
|
467 | new_cinterfid = new_interfid.size | |
465 | else: new_cinterfid = 0 |
|
468 | else: new_cinterfid = 0 | |
466 |
|
469 | |||
467 | for ip in range(new_cinterfid): |
|
470 | for ip in range(new_cinterfid): | |
468 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() |
|
471 | ind = junkspc_interf[:,new_interfid[ip]].ravel().argsort() | |
469 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] |
|
472 | jspc_interf[new_interfid[ip]] = junkspc_interf[ind[nhei_interf/2],new_interfid[ip]] | |
470 |
|
473 | |||
471 |
|
474 | |||
472 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices |
|
475 | jspectra[ich,:,ind_hei] = jspectra[ich,:,ind_hei] - jspc_interf #Corregir indices | |
473 |
|
476 | |||
474 | #Removiendo la interferencia del punto de mayor interferencia |
|
477 | #Removiendo la interferencia del punto de mayor interferencia | |
475 | ListAux = jspc_interf[mask_prof].tolist() |
|
478 | ListAux = jspc_interf[mask_prof].tolist() | |
476 | maxid = ListAux.index(max(ListAux)) |
|
479 | maxid = ListAux.index(max(ListAux)) | |
477 |
|
480 | |||
478 |
|
481 | |||
479 | if cinterfid > 0: |
|
482 | if cinterfid > 0: | |
480 | for ip in range(cinterfid*(interf == 2) - 1): |
|
483 | for ip in range(cinterfid*(interf == 2) - 1): | |
481 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() |
|
484 | ind = (jspectra[ich,interfid[ip],:] < tmp_noise*(1 + 1/math.sqrt(num_incoh))).nonzero() | |
482 | cind = len(ind) |
|
485 | cind = len(ind) | |
483 |
|
486 | |||
484 | if (cind > 0): |
|
487 | if (cind > 0): | |
485 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) |
|
488 | jspectra[ich,interfid[ip],ind] = tmp_noise*(1 + (numpy.random.uniform(cind) - 0.5)/math.sqrt(num_incoh)) | |
486 |
|
489 | |||
487 | ind = numpy.array([-2,-1,1,2]) |
|
490 | ind = numpy.array([-2,-1,1,2]) | |
488 | xx = numpy.zeros([4,4]) |
|
491 | xx = numpy.zeros([4,4]) | |
489 |
|
492 | |||
490 | for id1 in range(4): |
|
493 | for id1 in range(4): | |
491 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
494 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
492 |
|
495 | |||
493 | xx_inv = numpy.linalg.inv(xx) |
|
496 | xx_inv = numpy.linalg.inv(xx) | |
494 | xx = xx_inv[:,0] |
|
497 | xx = xx_inv[:,0] | |
495 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
498 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
496 | yy = jspectra[ich,mask_prof[ind],:] |
|
499 | yy = jspectra[ich,mask_prof[ind],:] | |
497 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
500 | jspectra[ich,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
498 |
|
501 | |||
499 |
|
502 | |||
500 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() |
|
503 | indAux = (jspectra[ich,:,:] < tmp_noise*(1-1/math.sqrt(num_incoh))).nonzero() | |
501 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) |
|
504 | jspectra[ich,indAux[0],indAux[1]] = tmp_noise * (1 - 1/math.sqrt(num_incoh)) | |
502 |
|
505 | |||
503 | #Remocion de Interferencia en el Cross Spectra |
|
506 | #Remocion de Interferencia en el Cross Spectra | |
504 | if jcspectra == None: return jspectra, jcspectra |
|
507 | if jcspectra == None: return jspectra, jcspectra | |
505 | num_pairs = jcspectra.size/(num_prof*num_hei) |
|
508 | num_pairs = jcspectra.size/(num_prof*num_hei) | |
506 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) |
|
509 | jcspectra = jcspectra.reshape(num_pairs, num_prof, num_hei) | |
507 |
|
510 | |||
508 | for ip in range(num_pairs): |
|
511 | for ip in range(num_pairs): | |
509 |
|
512 | |||
510 | #------------------------------------------- |
|
513 | #------------------------------------------- | |
511 |
|
514 | |||
512 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) |
|
515 | cspower = numpy.abs(jcspectra[ip,mask_prof,:]) | |
513 | cspower = cspower[:,hei_interf] |
|
516 | cspower = cspower[:,hei_interf] | |
514 | cspower = cspower.sum(axis = 0) |
|
517 | cspower = cspower.sum(axis = 0) | |
515 |
|
518 | |||
516 | cspsort = cspower.ravel().argsort() |
|
519 | cspsort = cspower.ravel().argsort() | |
517 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] |
|
520 | junkcspc_interf = jcspectra[ip,:,hei_interf[cspsort[range(offhei_interf, nhei_interf + offhei_interf)]]] | |
518 | junkcspc_interf = junkcspc_interf.transpose() |
|
521 | junkcspc_interf = junkcspc_interf.transpose() | |
519 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf |
|
522 | jcspc_interf = junkcspc_interf.sum(axis = 1)/nhei_interf | |
520 |
|
523 | |||
521 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() |
|
524 | ind = numpy.abs(jcspc_interf[mask_prof]).ravel().argsort() | |
522 |
|
525 | |||
523 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
526 | median_real = numpy.median(numpy.real(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
524 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) |
|
527 | median_imag = numpy.median(numpy.imag(junkcspc_interf[mask_prof[ind[range(3*num_prof/4)]],:])) | |
525 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) |
|
528 | junkcspc_interf[comp_mask_prof,:] = numpy.complex(median_real, median_imag) | |
526 |
|
529 | |||
527 | for iprof in range(num_prof): |
|
530 | for iprof in range(num_prof): | |
528 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() |
|
531 | ind = numpy.abs(junkcspc_interf[iprof,:]).ravel().argsort() | |
529 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] |
|
532 | jcspc_interf[iprof] = junkcspc_interf[iprof, ind[nhei_interf/2]] | |
530 |
|
533 | |||
531 | #Removiendo la Interferencia |
|
534 | #Removiendo la Interferencia | |
532 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf |
|
535 | jcspectra[ip,:,ind_hei] = jcspectra[ip,:,ind_hei] - jcspc_interf | |
533 |
|
536 | |||
534 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() |
|
537 | ListAux = numpy.abs(jcspc_interf[mask_prof]).tolist() | |
535 | maxid = ListAux.index(max(ListAux)) |
|
538 | maxid = ListAux.index(max(ListAux)) | |
536 |
|
539 | |||
537 | ind = numpy.array([-2,-1,1,2]) |
|
540 | ind = numpy.array([-2,-1,1,2]) | |
538 | xx = numpy.zeros([4,4]) |
|
541 | xx = numpy.zeros([4,4]) | |
539 |
|
542 | |||
540 | for id1 in range(4): |
|
543 | for id1 in range(4): | |
541 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) |
|
544 | xx[:,id1] = ind[id1]**numpy.asarray(range(4)) | |
542 |
|
545 | |||
543 | xx_inv = numpy.linalg.inv(xx) |
|
546 | xx_inv = numpy.linalg.inv(xx) | |
544 | xx = xx_inv[:,0] |
|
547 | xx = xx_inv[:,0] | |
545 |
|
548 | |||
546 | ind = (ind + maxid + num_mask_prof)%num_mask_prof |
|
549 | ind = (ind + maxid + num_mask_prof)%num_mask_prof | |
547 | yy = jcspectra[ip,mask_prof[ind],:] |
|
550 | yy = jcspectra[ip,mask_prof[ind],:] | |
548 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) |
|
551 | jcspectra[ip,mask_prof[maxid],:] = numpy.dot(yy.transpose(),xx) | |
549 |
|
552 | |||
550 | #Guardar Resultados |
|
553 | #Guardar Resultados | |
551 | self.dataOut.data_spc = jspectra |
|
554 | self.dataOut.data_spc = jspectra | |
552 | self.dataOut.data_cspc = jcspectra |
|
555 | self.dataOut.data_cspc = jcspectra | |
553 |
|
556 | |||
554 | return 1 |
|
557 | return 1 | |
555 |
|
558 | |||
556 | def setRadarFrequency(self, frequency=None): |
|
559 | def setRadarFrequency(self, frequency=None): | |
557 | if frequency != None: |
|
560 | if frequency != None: | |
558 | self.dataOut.frequency = frequency |
|
561 | self.dataOut.frequency = frequency | |
559 |
|
562 | |||
560 | return 1 |
|
563 | return 1 | |
561 |
|
564 | |||
562 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): |
|
565 | def getNoise(self, minHei=None, maxHei=None, minVel=None, maxVel=None): | |
563 | #validacion de rango |
|
566 | #validacion de rango | |
564 | if minHei == None: |
|
567 | if minHei == None: | |
565 | minHei = self.dataOut.heightList[0] |
|
568 | minHei = self.dataOut.heightList[0] | |
566 |
|
569 | |||
567 | if maxHei == None: |
|
570 | if maxHei == None: | |
568 | maxHei = self.dataOut.heightList[-1] |
|
571 | maxHei = self.dataOut.heightList[-1] | |
569 |
|
572 | |||
570 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
573 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
571 | print 'minHei: %.2f is out of the heights range'%(minHei) |
|
574 | print 'minHei: %.2f is out of the heights range'%(minHei) | |
572 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) |
|
575 | print 'minHei is setting to %.2f'%(self.dataOut.heightList[0]) | |
573 | minHei = self.dataOut.heightList[0] |
|
576 | minHei = self.dataOut.heightList[0] | |
574 |
|
577 | |||
575 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): |
|
578 | if (maxHei > self.dataOut.heightList[-1]) or (maxHei < minHei): | |
576 | print 'maxHei: %.2f is out of the heights range'%(maxHei) |
|
579 | print 'maxHei: %.2f is out of the heights range'%(maxHei) | |
577 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) |
|
580 | print 'maxHei is setting to %.2f'%(self.dataOut.heightList[-1]) | |
578 | maxHei = self.dataOut.heightList[-1] |
|
581 | maxHei = self.dataOut.heightList[-1] | |
579 |
|
582 | |||
580 | # validacion de velocidades |
|
583 | # validacion de velocidades | |
581 | velrange = self.dataOut.getVelRange(1) |
|
584 | velrange = self.dataOut.getVelRange(1) | |
582 |
|
585 | |||
583 | if minVel == None: |
|
586 | if minVel == None: | |
584 | minVel = velrange[0] |
|
587 | minVel = velrange[0] | |
585 |
|
588 | |||
586 | if maxVel == None: |
|
589 | if maxVel == None: | |
587 | maxVel = velrange[-1] |
|
590 | maxVel = velrange[-1] | |
588 |
|
591 | |||
589 | if (minVel < velrange[0]) or (minVel > maxVel): |
|
592 | if (minVel < velrange[0]) or (minVel > maxVel): | |
590 | print 'minVel: %.2f is out of the velocity range'%(minVel) |
|
593 | print 'minVel: %.2f is out of the velocity range'%(minVel) | |
591 | print 'minVel is setting to %.2f'%(velrange[0]) |
|
594 | print 'minVel is setting to %.2f'%(velrange[0]) | |
592 | minVel = velrange[0] |
|
595 | minVel = velrange[0] | |
593 |
|
596 | |||
594 | if (maxVel > velrange[-1]) or (maxVel < minVel): |
|
597 | if (maxVel > velrange[-1]) or (maxVel < minVel): | |
595 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) |
|
598 | print 'maxVel: %.2f is out of the velocity range'%(maxVel) | |
596 | print 'maxVel is setting to %.2f'%(velrange[-1]) |
|
599 | print 'maxVel is setting to %.2f'%(velrange[-1]) | |
597 | maxVel = velrange[-1] |
|
600 | maxVel = velrange[-1] | |
598 |
|
601 | |||
599 | # seleccion de indices para rango |
|
602 | # seleccion de indices para rango | |
600 | minIndex = 0 |
|
603 | minIndex = 0 | |
601 | maxIndex = 0 |
|
604 | maxIndex = 0 | |
602 | heights = self.dataOut.heightList |
|
605 | heights = self.dataOut.heightList | |
603 |
|
606 | |||
604 | inda = numpy.where(heights >= minHei) |
|
607 | inda = numpy.where(heights >= minHei) | |
605 | indb = numpy.where(heights <= maxHei) |
|
608 | indb = numpy.where(heights <= maxHei) | |
606 |
|
609 | |||
607 | try: |
|
610 | try: | |
608 | minIndex = inda[0][0] |
|
611 | minIndex = inda[0][0] | |
609 | except: |
|
612 | except: | |
610 | minIndex = 0 |
|
613 | minIndex = 0 | |
611 |
|
614 | |||
612 | try: |
|
615 | try: | |
613 | maxIndex = indb[0][-1] |
|
616 | maxIndex = indb[0][-1] | |
614 | except: |
|
617 | except: | |
615 | maxIndex = len(heights) |
|
618 | maxIndex = len(heights) | |
616 |
|
619 | |||
617 | if (minIndex < 0) or (minIndex > maxIndex): |
|
620 | if (minIndex < 0) or (minIndex > maxIndex): | |
618 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
621 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
619 |
|
622 | |||
620 | if (maxIndex >= self.dataOut.nHeights): |
|
623 | if (maxIndex >= self.dataOut.nHeights): | |
621 | maxIndex = self.dataOut.nHeights-1 |
|
624 | maxIndex = self.dataOut.nHeights-1 | |
622 |
|
625 | |||
623 | # seleccion de indices para velocidades |
|
626 | # seleccion de indices para velocidades | |
624 | indminvel = numpy.where(velrange >= minVel) |
|
627 | indminvel = numpy.where(velrange >= minVel) | |
625 | indmaxvel = numpy.where(velrange <= maxVel) |
|
628 | indmaxvel = numpy.where(velrange <= maxVel) | |
626 | try: |
|
629 | try: | |
627 | minIndexVel = indminvel[0][0] |
|
630 | minIndexVel = indminvel[0][0] | |
628 | except: |
|
631 | except: | |
629 | minIndexVel = 0 |
|
632 | minIndexVel = 0 | |
630 |
|
633 | |||
631 | try: |
|
634 | try: | |
632 | maxIndexVel = indmaxvel[0][-1] |
|
635 | maxIndexVel = indmaxvel[0][-1] | |
633 | except: |
|
636 | except: | |
634 | maxIndexVel = len(velrange) |
|
637 | maxIndexVel = len(velrange) | |
635 |
|
638 | |||
636 | #seleccion del espectro |
|
639 | #seleccion del espectro | |
637 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] |
|
640 | data_spc = self.dataOut.data_spc[:,minIndexVel:maxIndexVel+1,minIndex:maxIndex+1] | |
638 | #estimacion de ruido |
|
641 | #estimacion de ruido | |
639 | noise = numpy.zeros(self.dataOut.nChannels) |
|
642 | noise = numpy.zeros(self.dataOut.nChannels) | |
640 |
|
643 | |||
641 | for channel in range(self.dataOut.nChannels): |
|
644 | for channel in range(self.dataOut.nChannels): | |
642 | daux = data_spc[channel,:,:] |
|
645 | daux = data_spc[channel,:,:] | |
643 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) |
|
646 | noise[channel] = hildebrand_sekhon(daux, self.dataOut.nIncohInt) | |
644 |
|
647 | |||
645 | self.dataOut.noise_estimation = noise.copy() |
|
648 | self.dataOut.noise_estimation = noise.copy() | |
646 |
|
649 | |||
647 | return 1 |
|
650 | return 1 | |
648 |
|
651 | |||
649 | class IncohInt(Operation): |
|
652 | class IncohInt(Operation): | |
650 |
|
653 | |||
651 |
|
654 | |||
652 | __profIndex = 0 |
|
655 | __profIndex = 0 | |
653 | __withOverapping = False |
|
656 | __withOverapping = False | |
654 |
|
657 | |||
655 | __byTime = False |
|
658 | __byTime = False | |
656 | __initime = None |
|
659 | __initime = None | |
657 | __lastdatatime = None |
|
660 | __lastdatatime = None | |
658 | __integrationtime = None |
|
661 | __integrationtime = None | |
659 |
|
662 | |||
660 | __buffer_spc = None |
|
663 | __buffer_spc = None | |
661 | __buffer_cspc = None |
|
664 | __buffer_cspc = None | |
662 | __buffer_dc = None |
|
665 | __buffer_dc = None | |
663 |
|
666 | |||
664 | __dataReady = False |
|
667 | __dataReady = False | |
665 |
|
668 | |||
666 | __timeInterval = None |
|
669 | __timeInterval = None | |
667 |
|
670 | |||
668 | n = None |
|
671 | n = None | |
669 |
|
672 | |||
670 |
|
673 | |||
671 |
|
674 | |||
672 | def __init__(self): |
|
675 | def __init__(self): | |
673 |
|
676 | |||
674 | Operation.__init__(self) |
|
677 | Operation.__init__(self) | |
675 | # self.isConfig = False |
|
678 | # self.isConfig = False | |
676 |
|
679 | |||
677 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
680 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
678 | """ |
|
681 | """ | |
679 | Set the parameters of the integration class. |
|
682 | Set the parameters of the integration class. | |
680 |
|
683 | |||
681 | Inputs: |
|
684 | Inputs: | |
682 |
|
685 | |||
683 | n : Number of coherent integrations |
|
686 | n : Number of coherent integrations | |
684 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
687 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
685 | overlapping : |
|
688 | overlapping : | |
686 |
|
689 | |||
687 | """ |
|
690 | """ | |
688 |
|
691 | |||
689 | self.__initime = None |
|
692 | self.__initime = None | |
690 | self.__lastdatatime = 0 |
|
693 | self.__lastdatatime = 0 | |
691 | self.__buffer_spc = None |
|
694 | self.__buffer_spc = None | |
692 | self.__buffer_cspc = None |
|
695 | self.__buffer_cspc = None | |
693 | self.__buffer_dc = None |
|
696 | self.__buffer_dc = None | |
694 | self.__dataReady = False |
|
697 | self.__dataReady = False | |
695 |
|
698 | |||
696 |
|
699 | |||
697 | if n == None and timeInterval == None: |
|
700 | if n == None and timeInterval == None: | |
698 | raise ValueError, "n or timeInterval should be specified ..." |
|
701 | raise ValueError, "n or timeInterval should be specified ..." | |
699 |
|
702 | |||
700 | if n != None: |
|
703 | if n != None: | |
701 | self.n = n |
|
704 | self.n = n | |
702 | self.__byTime = False |
|
705 | self.__byTime = False | |
703 | else: |
|
706 | else: | |
704 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line |
|
707 | self.__integrationtime = timeInterval #if (type(timeInterval)!=integer) -> change this line | |
705 | self.n = 9999 |
|
708 | self.n = 9999 | |
706 | self.__byTime = True |
|
709 | self.__byTime = True | |
707 |
|
710 | |||
708 | if overlapping: |
|
711 | if overlapping: | |
709 | self.__withOverapping = True |
|
712 | self.__withOverapping = True | |
710 | else: |
|
713 | else: | |
711 | self.__withOverapping = False |
|
714 | self.__withOverapping = False | |
712 | self.__buffer_spc = 0 |
|
715 | self.__buffer_spc = 0 | |
713 | self.__buffer_cspc = 0 |
|
716 | self.__buffer_cspc = 0 | |
714 | self.__buffer_dc = 0 |
|
717 | self.__buffer_dc = 0 | |
715 |
|
718 | |||
716 | self.__profIndex = 0 |
|
719 | self.__profIndex = 0 | |
717 |
|
720 | |||
718 | def putData(self, data_spc, data_cspc, data_dc): |
|
721 | def putData(self, data_spc, data_cspc, data_dc): | |
719 |
|
722 | |||
720 | """ |
|
723 | """ | |
721 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
724 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
722 |
|
725 | |||
723 | """ |
|
726 | """ | |
724 |
|
727 | |||
725 | if not self.__withOverapping: |
|
728 | if not self.__withOverapping: | |
726 | self.__buffer_spc += data_spc |
|
729 | self.__buffer_spc += data_spc | |
727 |
|
730 | |||
728 | if data_cspc == None: |
|
731 | if data_cspc == None: | |
729 | self.__buffer_cspc = None |
|
732 | self.__buffer_cspc = None | |
730 | else: |
|
733 | else: | |
731 | self.__buffer_cspc += data_cspc |
|
734 | self.__buffer_cspc += data_cspc | |
732 |
|
735 | |||
733 | if data_dc == None: |
|
736 | if data_dc == None: | |
734 | self.__buffer_dc = None |
|
737 | self.__buffer_dc = None | |
735 | else: |
|
738 | else: | |
736 | self.__buffer_dc += data_dc |
|
739 | self.__buffer_dc += data_dc | |
737 |
|
740 | |||
738 | self.__profIndex += 1 |
|
741 | self.__profIndex += 1 | |
739 | return |
|
742 | return | |
740 |
|
743 | |||
741 | #Overlapping data |
|
744 | #Overlapping data | |
742 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
745 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
743 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
746 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) | |
744 | if data_cspc != None: |
|
747 | if data_cspc != None: | |
745 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
748 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) | |
746 | if data_dc != None: |
|
749 | if data_dc != None: | |
747 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
750 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) | |
748 |
|
751 | |||
749 | #If the buffer is empty then it takes the data value |
|
752 | #If the buffer is empty then it takes the data value | |
750 | if self.__buffer_spc == None: |
|
753 | if self.__buffer_spc == None: | |
751 | self.__buffer_spc = data_spc |
|
754 | self.__buffer_spc = data_spc | |
752 |
|
755 | |||
753 | if data_cspc == None: |
|
756 | if data_cspc == None: | |
754 | self.__buffer_cspc = None |
|
757 | self.__buffer_cspc = None | |
755 | else: |
|
758 | else: | |
756 | self.__buffer_cspc += data_cspc |
|
759 | self.__buffer_cspc += data_cspc | |
757 |
|
760 | |||
758 | if data_dc == None: |
|
761 | if data_dc == None: | |
759 | self.__buffer_dc = None |
|
762 | self.__buffer_dc = None | |
760 | else: |
|
763 | else: | |
761 | self.__buffer_dc += data_dc |
|
764 | self.__buffer_dc += data_dc | |
762 |
|
765 | |||
763 | self.__profIndex += 1 |
|
766 | self.__profIndex += 1 | |
764 | return |
|
767 | return | |
765 |
|
768 | |||
766 | #If the buffer length is lower than n then stakcing the data value |
|
769 | #If the buffer length is lower than n then stakcing the data value | |
767 | if self.__profIndex < self.n: |
|
770 | if self.__profIndex < self.n: | |
768 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
771 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) | |
769 |
|
772 | |||
770 | if data_cspc != None: |
|
773 | if data_cspc != None: | |
771 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
774 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) | |
772 |
|
775 | |||
773 | if data_dc != None: |
|
776 | if data_dc != None: | |
774 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
777 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) | |
775 |
|
778 | |||
776 | self.__profIndex += 1 |
|
779 | self.__profIndex += 1 | |
777 | return |
|
780 | return | |
778 |
|
781 | |||
779 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
782 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
780 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
783 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
781 | self.__buffer_spc[self.n-1] = data_spc |
|
784 | self.__buffer_spc[self.n-1] = data_spc | |
782 |
|
785 | |||
783 | if data_cspc != None: |
|
786 | if data_cspc != None: | |
784 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
787 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) | |
785 | self.__buffer_cspc[self.n-1] = data_cspc |
|
788 | self.__buffer_cspc[self.n-1] = data_cspc | |
786 |
|
789 | |||
787 | if data_dc != None: |
|
790 | if data_dc != None: | |
788 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
791 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) | |
789 | self.__buffer_dc[self.n-1] = data_dc |
|
792 | self.__buffer_dc[self.n-1] = data_dc | |
790 |
|
793 | |||
791 | self.__profIndex = self.n |
|
794 | self.__profIndex = self.n | |
792 | return |
|
795 | return | |
793 |
|
796 | |||
794 |
|
797 | |||
795 | def pushData(self): |
|
798 | def pushData(self): | |
796 | """ |
|
799 | """ | |
797 | Return the sum of the last profiles and the profiles used in the sum. |
|
800 | Return the sum of the last profiles and the profiles used in the sum. | |
798 |
|
801 | |||
799 | Affected: |
|
802 | Affected: | |
800 |
|
803 | |||
801 | self.__profileIndex |
|
804 | self.__profileIndex | |
802 |
|
805 | |||
803 | """ |
|
806 | """ | |
804 | data_spc = None |
|
807 | data_spc = None | |
805 | data_cspc = None |
|
808 | data_cspc = None | |
806 | data_dc = None |
|
809 | data_dc = None | |
807 |
|
810 | |||
808 | if not self.__withOverapping: |
|
811 | if not self.__withOverapping: | |
809 | data_spc = self.__buffer_spc |
|
812 | data_spc = self.__buffer_spc | |
810 | data_cspc = self.__buffer_cspc |
|
813 | data_cspc = self.__buffer_cspc | |
811 | data_dc = self.__buffer_dc |
|
814 | data_dc = self.__buffer_dc | |
812 |
|
815 | |||
813 | n = self.__profIndex |
|
816 | n = self.__profIndex | |
814 |
|
817 | |||
815 | self.__buffer_spc = 0 |
|
818 | self.__buffer_spc = 0 | |
816 | self.__buffer_cspc = 0 |
|
819 | self.__buffer_cspc = 0 | |
817 | self.__buffer_dc = 0 |
|
820 | self.__buffer_dc = 0 | |
818 | self.__profIndex = 0 |
|
821 | self.__profIndex = 0 | |
819 |
|
822 | |||
820 | return data_spc, data_cspc, data_dc, n |
|
823 | return data_spc, data_cspc, data_dc, n | |
821 |
|
824 | |||
822 | #Integration with Overlapping |
|
825 | #Integration with Overlapping | |
823 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
826 | data_spc = numpy.sum(self.__buffer_spc, axis=0) | |
824 |
|
827 | |||
825 | if self.__buffer_cspc != None: |
|
828 | if self.__buffer_cspc != None: | |
826 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
829 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) | |
827 |
|
830 | |||
828 | if self.__buffer_dc != None: |
|
831 | if self.__buffer_dc != None: | |
829 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
832 | data_dc = numpy.sum(self.__buffer_dc, axis=0) | |
830 |
|
833 | |||
831 | n = self.__profIndex |
|
834 | n = self.__profIndex | |
832 |
|
835 | |||
833 | return data_spc, data_cspc, data_dc, n |
|
836 | return data_spc, data_cspc, data_dc, n | |
834 |
|
837 | |||
835 | def byProfiles(self, *args): |
|
838 | def byProfiles(self, *args): | |
836 |
|
839 | |||
837 | self.__dataReady = False |
|
840 | self.__dataReady = False | |
838 | avgdata_spc = None |
|
841 | avgdata_spc = None | |
839 | avgdata_cspc = None |
|
842 | avgdata_cspc = None | |
840 | avgdata_dc = None |
|
843 | avgdata_dc = None | |
841 | # n = None |
|
844 | # n = None | |
842 |
|
845 | |||
843 | self.putData(*args) |
|
846 | self.putData(*args) | |
844 |
|
847 | |||
845 | if self.__profIndex == self.n: |
|
848 | if self.__profIndex == self.n: | |
846 |
|
849 | |||
847 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
850 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
848 | self.__dataReady = True |
|
851 | self.__dataReady = True | |
849 |
|
852 | |||
850 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
853 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
851 |
|
854 | |||
852 | def byTime(self, datatime, *args): |
|
855 | def byTime(self, datatime, *args): | |
853 |
|
856 | |||
854 | self.__dataReady = False |
|
857 | self.__dataReady = False | |
855 | avgdata_spc = None |
|
858 | avgdata_spc = None | |
856 | avgdata_cspc = None |
|
859 | avgdata_cspc = None | |
857 | avgdata_dc = None |
|
860 | avgdata_dc = None | |
858 | n = None |
|
861 | n = None | |
859 |
|
862 | |||
860 | self.putData(*args) |
|
863 | self.putData(*args) | |
861 |
|
864 | |||
862 | if (datatime - self.__initime) >= self.__integrationtime: |
|
865 | if (datatime - self.__initime) >= self.__integrationtime: | |
863 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
866 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
864 | self.n = n |
|
867 | self.n = n | |
865 | self.__dataReady = True |
|
868 | self.__dataReady = True | |
866 |
|
869 | |||
867 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
870 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
868 |
|
871 | |||
869 | def integrate(self, datatime, *args): |
|
872 | def integrate(self, datatime, *args): | |
870 |
|
873 | |||
871 | if self.__initime == None: |
|
874 | if self.__initime == None: | |
872 | self.__initime = datatime |
|
875 | self.__initime = datatime | |
873 |
|
876 | |||
874 | if self.__byTime: |
|
877 | if self.__byTime: | |
875 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
878 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
876 | else: |
|
879 | else: | |
877 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
880 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
878 |
|
881 | |||
879 | self.__lastdatatime = datatime |
|
882 | self.__lastdatatime = datatime | |
880 |
|
883 | |||
881 | if avgdata_spc == None: |
|
884 | if avgdata_spc == None: | |
882 | return None, None, None, None |
|
885 | return None, None, None, None | |
883 |
|
886 | |||
884 | avgdatatime = self.__initime |
|
887 | avgdatatime = self.__initime | |
885 | try: |
|
888 | try: | |
886 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
889 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) | |
887 | except: |
|
890 | except: | |
888 | self.__timeInterval = self.__lastdatatime - self.__initime |
|
891 | self.__timeInterval = self.__lastdatatime - self.__initime | |
889 |
|
892 | |||
890 | deltatime = datatime -self.__lastdatatime |
|
893 | deltatime = datatime -self.__lastdatatime | |
891 |
|
894 | |||
892 | if not self.__withOverapping: |
|
895 | if not self.__withOverapping: | |
893 | self.__initime = datatime |
|
896 | self.__initime = datatime | |
894 | else: |
|
897 | else: | |
895 | self.__initime += deltatime |
|
898 | self.__initime += deltatime | |
896 |
|
899 | |||
897 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
900 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
898 |
|
901 | |||
899 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
902 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
900 |
|
903 | |||
901 | if n==1: |
|
904 | if n==1: | |
902 | dataOut.flagNoData = False |
|
905 | dataOut.flagNoData = False | |
903 | return |
|
906 | return | |
904 |
|
907 | |||
905 | if not self.isConfig: |
|
908 | if not self.isConfig: | |
906 | self.setup(n, timeInterval, overlapping) |
|
909 | self.setup(n, timeInterval, overlapping) | |
907 | self.isConfig = True |
|
910 | self.isConfig = True | |
908 |
|
911 | |||
909 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
912 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
910 | dataOut.data_spc, |
|
913 | dataOut.data_spc, | |
911 | dataOut.data_cspc, |
|
914 | dataOut.data_cspc, | |
912 | dataOut.data_dc) |
|
915 | dataOut.data_dc) | |
913 |
|
916 | |||
914 | # dataOut.timeInterval *= n |
|
917 | # dataOut.timeInterval *= n | |
915 | dataOut.flagNoData = True |
|
918 | dataOut.flagNoData = True | |
916 |
|
919 | |||
917 | if self.__dataReady: |
|
920 | if self.__dataReady: | |
918 |
|
921 | |||
919 | dataOut.data_spc = avgdata_spc |
|
922 | dataOut.data_spc = avgdata_spc | |
920 | dataOut.data_cspc = avgdata_cspc |
|
923 | dataOut.data_cspc = avgdata_cspc | |
921 | dataOut.data_dc = avgdata_dc |
|
924 | dataOut.data_dc = avgdata_dc | |
922 |
|
925 | |||
923 | dataOut.nIncohInt *= self.n |
|
926 | dataOut.nIncohInt *= self.n | |
924 | dataOut.utctime = avgdatatime |
|
927 | dataOut.utctime = avgdatatime | |
925 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
928 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
926 | dataOut.timeInterval = self.__timeInterval*self.n |
|
929 | dataOut.timeInterval = self.__timeInterval*self.n | |
927 | dataOut.flagNoData = False |
|
930 | dataOut.flagNoData = False |
@@ -1,751 +1,754 | |||||
1 | import numpy |
|
1 | import numpy | |
2 |
|
2 | |||
3 | from jroproc_base import ProcessingUnit, Operation |
|
3 | from jroproc_base import ProcessingUnit, Operation | |
4 | from model.data.jrodata import Voltage |
|
4 | from model.data.jrodata import Voltage | |
5 |
|
5 | |||
6 | class VoltageProc(ProcessingUnit): |
|
6 | class VoltageProc(ProcessingUnit): | |
7 |
|
7 | |||
8 |
|
8 | |||
9 | def __init__(self): |
|
9 | def __init__(self): | |
10 |
|
10 | |||
11 | ProcessingUnit.__init__(self) |
|
11 | ProcessingUnit.__init__(self) | |
12 |
|
12 | |||
13 | # self.objectDict = {} |
|
13 | # self.objectDict = {} | |
14 | self.dataOut = Voltage() |
|
14 | self.dataOut = Voltage() | |
15 | self.flip = 1 |
|
15 | self.flip = 1 | |
16 |
|
16 | |||
17 | def run(self): |
|
17 | def run(self): | |
18 | if self.dataIn.type == 'AMISR': |
|
18 | if self.dataIn.type == 'AMISR': | |
19 | self.__updateObjFromAmisrInput() |
|
19 | self.__updateObjFromAmisrInput() | |
20 |
|
20 | |||
21 | if self.dataIn.type == 'Voltage': |
|
21 | if self.dataIn.type == 'Voltage': | |
22 | self.dataOut.copy(self.dataIn) |
|
22 | self.dataOut.copy(self.dataIn) | |
23 |
|
23 | |||
24 | # self.dataOut.copy(self.dataIn) |
|
24 | # self.dataOut.copy(self.dataIn) | |
25 |
|
25 | |||
26 | def __updateObjFromAmisrInput(self): |
|
26 | def __updateObjFromAmisrInput(self): | |
27 |
|
27 | |||
28 | self.dataOut.timeZone = self.dataIn.timeZone |
|
28 | self.dataOut.timeZone = self.dataIn.timeZone | |
29 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
29 | self.dataOut.dstFlag = self.dataIn.dstFlag | |
30 | self.dataOut.errorCount = self.dataIn.errorCount |
|
30 | self.dataOut.errorCount = self.dataIn.errorCount | |
31 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
31 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |
32 |
|
32 | |||
33 | self.dataOut.flagNoData = self.dataIn.flagNoData |
|
33 | self.dataOut.flagNoData = self.dataIn.flagNoData | |
34 | self.dataOut.data = self.dataIn.data |
|
34 | self.dataOut.data = self.dataIn.data | |
35 | self.dataOut.utctime = self.dataIn.utctime |
|
35 | self.dataOut.utctime = self.dataIn.utctime | |
36 | self.dataOut.channelList = self.dataIn.channelList |
|
36 | self.dataOut.channelList = self.dataIn.channelList | |
37 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
37 | self.dataOut.timeInterval = self.dataIn.timeInterval | |
38 | self.dataOut.heightList = self.dataIn.heightList |
|
38 | self.dataOut.heightList = self.dataIn.heightList | |
39 | self.dataOut.nProfiles = self.dataIn.nProfiles |
|
39 | self.dataOut.nProfiles = self.dataIn.nProfiles | |
40 |
|
40 | |||
41 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
41 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
42 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
42 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
43 | self.dataOut.frequency = self.dataIn.frequency |
|
43 | self.dataOut.frequency = self.dataIn.frequency | |
|
44 | ||||
|
45 | self.dataOut.azimuth = self.dataIn.azimuth | |||
|
46 | self.dataOut.zenith = self.dataIn.zenith | |||
44 | # |
|
47 | # | |
45 | # pass# |
|
48 | # pass# | |
46 | # |
|
49 | # | |
47 | # def init(self): |
|
50 | # def init(self): | |
48 | # |
|
51 | # | |
49 | # |
|
52 | # | |
50 | # if self.dataIn.type == 'AMISR': |
|
53 | # if self.dataIn.type == 'AMISR': | |
51 | # self.__updateObjFromAmisrInput() |
|
54 | # self.__updateObjFromAmisrInput() | |
52 | # |
|
55 | # | |
53 | # if self.dataIn.type == 'Voltage': |
|
56 | # if self.dataIn.type == 'Voltage': | |
54 | # self.dataOut.copy(self.dataIn) |
|
57 | # self.dataOut.copy(self.dataIn) | |
55 | # # No necesita copiar en cada init() los atributos de dataIn |
|
58 | # # No necesita copiar en cada init() los atributos de dataIn | |
56 | # # la copia deberia hacerse por cada nuevo bloque de datos |
|
59 | # # la copia deberia hacerse por cada nuevo bloque de datos | |
57 |
|
60 | |||
58 | def selectChannels(self, channelList): |
|
61 | def selectChannels(self, channelList): | |
59 |
|
62 | |||
60 | channelIndexList = [] |
|
63 | channelIndexList = [] | |
61 |
|
64 | |||
62 | for channel in channelList: |
|
65 | for channel in channelList: | |
63 | index = self.dataOut.channelList.index(channel) |
|
66 | index = self.dataOut.channelList.index(channel) | |
64 | channelIndexList.append(index) |
|
67 | channelIndexList.append(index) | |
65 |
|
68 | |||
66 | self.selectChannelsByIndex(channelIndexList) |
|
69 | self.selectChannelsByIndex(channelIndexList) | |
67 |
|
70 | |||
68 | def selectChannelsByIndex(self, channelIndexList): |
|
71 | def selectChannelsByIndex(self, channelIndexList): | |
69 | """ |
|
72 | """ | |
70 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
73 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
71 |
|
74 | |||
72 | Input: |
|
75 | Input: | |
73 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
76 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
74 |
|
77 | |||
75 | Affected: |
|
78 | Affected: | |
76 | self.dataOut.data |
|
79 | self.dataOut.data | |
77 | self.dataOut.channelIndexList |
|
80 | self.dataOut.channelIndexList | |
78 | self.dataOut.nChannels |
|
81 | self.dataOut.nChannels | |
79 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
82 | self.dataOut.m_ProcessingHeader.totalSpectra | |
80 | self.dataOut.systemHeaderObj.numChannels |
|
83 | self.dataOut.systemHeaderObj.numChannels | |
81 | self.dataOut.m_ProcessingHeader.blockSize |
|
84 | self.dataOut.m_ProcessingHeader.blockSize | |
82 |
|
85 | |||
83 | Return: |
|
86 | Return: | |
84 | None |
|
87 | None | |
85 | """ |
|
88 | """ | |
86 |
|
89 | |||
87 | for channelIndex in channelIndexList: |
|
90 | for channelIndex in channelIndexList: | |
88 | if channelIndex not in self.dataOut.channelIndexList: |
|
91 | if channelIndex not in self.dataOut.channelIndexList: | |
89 | print channelIndexList |
|
92 | print channelIndexList | |
90 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
93 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
91 |
|
94 | |||
92 | # nChannels = len(channelIndexList) |
|
95 | # nChannels = len(channelIndexList) | |
93 |
|
96 | |||
94 | data = self.dataOut.data[channelIndexList,:] |
|
97 | data = self.dataOut.data[channelIndexList,:] | |
95 |
|
98 | |||
96 | self.dataOut.data = data |
|
99 | self.dataOut.data = data | |
97 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
100 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
98 | # self.dataOut.nChannels = nChannels |
|
101 | # self.dataOut.nChannels = nChannels | |
99 |
|
102 | |||
100 | return 1 |
|
103 | return 1 | |
101 |
|
104 | |||
102 | def selectHeights(self, minHei=None, maxHei=None): |
|
105 | def selectHeights(self, minHei=None, maxHei=None): | |
103 | """ |
|
106 | """ | |
104 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
107 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
105 | minHei <= height <= maxHei |
|
108 | minHei <= height <= maxHei | |
106 |
|
109 | |||
107 | Input: |
|
110 | Input: | |
108 | minHei : valor minimo de altura a considerar |
|
111 | minHei : valor minimo de altura a considerar | |
109 | maxHei : valor maximo de altura a considerar |
|
112 | maxHei : valor maximo de altura a considerar | |
110 |
|
113 | |||
111 | Affected: |
|
114 | Affected: | |
112 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
115 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
113 |
|
116 | |||
114 | Return: |
|
117 | Return: | |
115 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
118 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
116 | """ |
|
119 | """ | |
117 |
|
120 | |||
118 | if minHei == None: |
|
121 | if minHei == None: | |
119 | minHei = self.dataOut.heightList[0] |
|
122 | minHei = self.dataOut.heightList[0] | |
120 |
|
123 | |||
121 | if maxHei == None: |
|
124 | if maxHei == None: | |
122 | maxHei = self.dataOut.heightList[-1] |
|
125 | maxHei = self.dataOut.heightList[-1] | |
123 |
|
126 | |||
124 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
127 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
125 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
128 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
126 |
|
129 | |||
127 |
|
130 | |||
128 | if (maxHei > self.dataOut.heightList[-1]): |
|
131 | if (maxHei > self.dataOut.heightList[-1]): | |
129 | maxHei = self.dataOut.heightList[-1] |
|
132 | maxHei = self.dataOut.heightList[-1] | |
130 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
133 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
131 |
|
134 | |||
132 | minIndex = 0 |
|
135 | minIndex = 0 | |
133 | maxIndex = 0 |
|
136 | maxIndex = 0 | |
134 | heights = self.dataOut.heightList |
|
137 | heights = self.dataOut.heightList | |
135 |
|
138 | |||
136 | inda = numpy.where(heights >= minHei) |
|
139 | inda = numpy.where(heights >= minHei) | |
137 | indb = numpy.where(heights <= maxHei) |
|
140 | indb = numpy.where(heights <= maxHei) | |
138 |
|
141 | |||
139 | try: |
|
142 | try: | |
140 | minIndex = inda[0][0] |
|
143 | minIndex = inda[0][0] | |
141 | except: |
|
144 | except: | |
142 | minIndex = 0 |
|
145 | minIndex = 0 | |
143 |
|
146 | |||
144 | try: |
|
147 | try: | |
145 | maxIndex = indb[0][-1] |
|
148 | maxIndex = indb[0][-1] | |
146 | except: |
|
149 | except: | |
147 | maxIndex = len(heights) |
|
150 | maxIndex = len(heights) | |
148 |
|
151 | |||
149 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
152 | self.selectHeightsByIndex(minIndex, maxIndex) | |
150 |
|
153 | |||
151 | return 1 |
|
154 | return 1 | |
152 |
|
155 | |||
153 |
|
156 | |||
154 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
157 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
155 | """ |
|
158 | """ | |
156 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
159 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
157 | minIndex <= index <= maxIndex |
|
160 | minIndex <= index <= maxIndex | |
158 |
|
161 | |||
159 | Input: |
|
162 | Input: | |
160 | minIndex : valor de indice minimo de altura a considerar |
|
163 | minIndex : valor de indice minimo de altura a considerar | |
161 | maxIndex : valor de indice maximo de altura a considerar |
|
164 | maxIndex : valor de indice maximo de altura a considerar | |
162 |
|
165 | |||
163 | Affected: |
|
166 | Affected: | |
164 | self.dataOut.data |
|
167 | self.dataOut.data | |
165 | self.dataOut.heightList |
|
168 | self.dataOut.heightList | |
166 |
|
169 | |||
167 | Return: |
|
170 | Return: | |
168 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
171 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
169 | """ |
|
172 | """ | |
170 |
|
173 | |||
171 | if (minIndex < 0) or (minIndex > maxIndex): |
|
174 | if (minIndex < 0) or (minIndex > maxIndex): | |
172 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
175 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
173 |
|
176 | |||
174 | if (maxIndex >= self.dataOut.nHeights): |
|
177 | if (maxIndex >= self.dataOut.nHeights): | |
175 | maxIndex = self.dataOut.nHeights-1 |
|
178 | maxIndex = self.dataOut.nHeights-1 | |
176 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
179 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
177 |
|
180 | |||
178 | # nHeights = maxIndex - minIndex + 1 |
|
181 | # nHeights = maxIndex - minIndex + 1 | |
179 |
|
182 | |||
180 | #voltage |
|
183 | #voltage | |
181 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
184 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
182 |
|
185 | |||
183 | # firstHeight = self.dataOut.heightList[minIndex] |
|
186 | # firstHeight = self.dataOut.heightList[minIndex] | |
184 |
|
187 | |||
185 | self.dataOut.data = data |
|
188 | self.dataOut.data = data | |
186 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
189 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
187 |
|
190 | |||
188 | return 1 |
|
191 | return 1 | |
189 |
|
192 | |||
190 |
|
193 | |||
191 | def filterByHeights(self, window, axis=1): |
|
194 | def filterByHeights(self, window, axis=1): | |
192 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
195 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
193 |
|
196 | |||
194 | if window == None: |
|
197 | if window == None: | |
195 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight |
|
198 | window = (self.dataOut.radarControllerHeaderObj.txA/self.dataOut.radarControllerHeaderObj.nBaud) / deltaHeight | |
196 |
|
199 | |||
197 | newdelta = deltaHeight * window |
|
200 | newdelta = deltaHeight * window | |
198 | r = self.dataOut.data.shape[axis] % window |
|
201 | r = self.dataOut.data.shape[axis] % window | |
199 | if axis == 1: |
|
202 | if axis == 1: | |
200 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[axis]-r] |
|
203 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[axis]-r] | |
201 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[axis]/window,window) |
|
204 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[axis]/window,window) | |
202 | buffer = numpy.sum(buffer,axis+1) |
|
205 | buffer = numpy.sum(buffer,axis+1) | |
203 |
|
206 | |||
204 | elif axis == 2: |
|
207 | elif axis == 2: | |
205 | buffer = self.dataOut.data[:, :, 0:self.dataOut.data.shape[axis]-r] |
|
208 | buffer = self.dataOut.data[:, :, 0:self.dataOut.data.shape[axis]-r] | |
206 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1],self.dataOut.data.shape[axis]/window,window) |
|
209 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1],self.dataOut.data.shape[axis]/window,window) | |
207 | buffer = numpy.sum(buffer,axis+1) |
|
210 | buffer = numpy.sum(buffer,axis+1) | |
208 |
|
211 | |||
209 | else: |
|
212 | else: | |
210 | raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis) |
|
213 | raise ValueError, "axis value should be 1 or 2, the input value %d is not valid" % (axis) | |
211 |
|
214 | |||
212 | self.dataOut.data = buffer.copy() |
|
215 | self.dataOut.data = buffer.copy() | |
213 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) |
|
216 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*(self.dataOut.nHeights-r)/window,newdelta) | |
214 | self.dataOut.windowOfFilter = window |
|
217 | self.dataOut.windowOfFilter = window | |
215 |
|
218 | |||
216 | return 1 |
|
219 | return 1 | |
217 |
|
220 | |||
218 | def deFlip(self): |
|
221 | def deFlip(self): | |
219 | self.dataOut.data *= self.flip |
|
222 | self.dataOut.data *= self.flip | |
220 | self.flip *= -1. |
|
223 | self.flip *= -1. | |
221 |
|
224 | |||
222 | def setRadarFrequency(self, frequency=None): |
|
225 | def setRadarFrequency(self, frequency=None): | |
223 | if frequency != None: |
|
226 | if frequency != None: | |
224 | self.dataOut.frequency = frequency |
|
227 | self.dataOut.frequency = frequency | |
225 |
|
228 | |||
226 | return 1 |
|
229 | return 1 | |
227 |
|
230 | |||
228 | class CohInt(Operation): |
|
231 | class CohInt(Operation): | |
229 |
|
232 | |||
230 | isConfig = False |
|
233 | isConfig = False | |
231 |
|
234 | |||
232 | __profIndex = 0 |
|
235 | __profIndex = 0 | |
233 | __withOverapping = False |
|
236 | __withOverapping = False | |
234 |
|
237 | |||
235 | __byTime = False |
|
238 | __byTime = False | |
236 | __initime = None |
|
239 | __initime = None | |
237 | __lastdatatime = None |
|
240 | __lastdatatime = None | |
238 | __integrationtime = None |
|
241 | __integrationtime = None | |
239 |
|
242 | |||
240 | __buffer = None |
|
243 | __buffer = None | |
241 |
|
244 | |||
242 | __dataReady = False |
|
245 | __dataReady = False | |
243 |
|
246 | |||
244 | n = None |
|
247 | n = None | |
245 |
|
248 | |||
246 |
|
249 | |||
247 | def __init__(self): |
|
250 | def __init__(self): | |
248 |
|
251 | |||
249 | Operation.__init__(self) |
|
252 | Operation.__init__(self) | |
250 |
|
253 | |||
251 | # self.isConfig = False |
|
254 | # self.isConfig = False | |
252 |
|
255 | |||
253 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): |
|
256 | def setup(self, n=None, timeInterval=None, overlapping=False, byblock=False): | |
254 | """ |
|
257 | """ | |
255 | Set the parameters of the integration class. |
|
258 | Set the parameters of the integration class. | |
256 |
|
259 | |||
257 | Inputs: |
|
260 | Inputs: | |
258 |
|
261 | |||
259 | n : Number of coherent integrations |
|
262 | n : Number of coherent integrations | |
260 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
263 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
261 | overlapping : |
|
264 | overlapping : | |
262 |
|
265 | |||
263 | """ |
|
266 | """ | |
264 |
|
267 | |||
265 | self.__initime = None |
|
268 | self.__initime = None | |
266 | self.__lastdatatime = 0 |
|
269 | self.__lastdatatime = 0 | |
267 | self.__buffer = None |
|
270 | self.__buffer = None | |
268 | self.__dataReady = False |
|
271 | self.__dataReady = False | |
269 | self.byblock = byblock |
|
272 | self.byblock = byblock | |
270 |
|
273 | |||
271 | if n == None and timeInterval == None: |
|
274 | if n == None and timeInterval == None: | |
272 | raise ValueError, "n or timeInterval should be specified ..." |
|
275 | raise ValueError, "n or timeInterval should be specified ..." | |
273 |
|
276 | |||
274 | if n != None: |
|
277 | if n != None: | |
275 | self.n = n |
|
278 | self.n = n | |
276 | self.__byTime = False |
|
279 | self.__byTime = False | |
277 | else: |
|
280 | else: | |
278 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
281 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
279 | self.n = 9999 |
|
282 | self.n = 9999 | |
280 | self.__byTime = True |
|
283 | self.__byTime = True | |
281 |
|
284 | |||
282 | if overlapping: |
|
285 | if overlapping: | |
283 | self.__withOverapping = True |
|
286 | self.__withOverapping = True | |
284 | self.__buffer = None |
|
287 | self.__buffer = None | |
285 | else: |
|
288 | else: | |
286 | self.__withOverapping = False |
|
289 | self.__withOverapping = False | |
287 | self.__buffer = 0 |
|
290 | self.__buffer = 0 | |
288 |
|
291 | |||
289 | self.__profIndex = 0 |
|
292 | self.__profIndex = 0 | |
290 |
|
293 | |||
291 | def putData(self, data): |
|
294 | def putData(self, data): | |
292 |
|
295 | |||
293 | """ |
|
296 | """ | |
294 | Add a profile to the __buffer and increase in one the __profileIndex |
|
297 | Add a profile to the __buffer and increase in one the __profileIndex | |
295 |
|
298 | |||
296 | """ |
|
299 | """ | |
297 |
|
300 | |||
298 | if not self.__withOverapping: |
|
301 | if not self.__withOverapping: | |
299 | self.__buffer += data.copy() |
|
302 | self.__buffer += data.copy() | |
300 | self.__profIndex += 1 |
|
303 | self.__profIndex += 1 | |
301 | return |
|
304 | return | |
302 |
|
305 | |||
303 | #Overlapping data |
|
306 | #Overlapping data | |
304 | nChannels, nHeis = data.shape |
|
307 | nChannels, nHeis = data.shape | |
305 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
308 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
306 |
|
309 | |||
307 | #If the buffer is empty then it takes the data value |
|
310 | #If the buffer is empty then it takes the data value | |
308 | if self.__buffer == None: |
|
311 | if self.__buffer == None: | |
309 | self.__buffer = data |
|
312 | self.__buffer = data | |
310 | self.__profIndex += 1 |
|
313 | self.__profIndex += 1 | |
311 | return |
|
314 | return | |
312 |
|
315 | |||
313 | #If the buffer length is lower than n then stakcing the data value |
|
316 | #If the buffer length is lower than n then stakcing the data value | |
314 | if self.__profIndex < self.n: |
|
317 | if self.__profIndex < self.n: | |
315 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
318 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
316 | self.__profIndex += 1 |
|
319 | self.__profIndex += 1 | |
317 | return |
|
320 | return | |
318 |
|
321 | |||
319 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
322 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
320 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
323 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
321 | self.__buffer[self.n-1] = data |
|
324 | self.__buffer[self.n-1] = data | |
322 | self.__profIndex = self.n |
|
325 | self.__profIndex = self.n | |
323 | return |
|
326 | return | |
324 |
|
327 | |||
325 |
|
328 | |||
326 | def pushData(self): |
|
329 | def pushData(self): | |
327 | """ |
|
330 | """ | |
328 | Return the sum of the last profiles and the profiles used in the sum. |
|
331 | Return the sum of the last profiles and the profiles used in the sum. | |
329 |
|
332 | |||
330 | Affected: |
|
333 | Affected: | |
331 |
|
334 | |||
332 | self.__profileIndex |
|
335 | self.__profileIndex | |
333 |
|
336 | |||
334 | """ |
|
337 | """ | |
335 |
|
338 | |||
336 | if not self.__withOverapping: |
|
339 | if not self.__withOverapping: | |
337 | data = self.__buffer |
|
340 | data = self.__buffer | |
338 | n = self.__profIndex |
|
341 | n = self.__profIndex | |
339 |
|
342 | |||
340 | self.__buffer = 0 |
|
343 | self.__buffer = 0 | |
341 | self.__profIndex = 0 |
|
344 | self.__profIndex = 0 | |
342 |
|
345 | |||
343 | return data, n |
|
346 | return data, n | |
344 |
|
347 | |||
345 | #Integration with Overlapping |
|
348 | #Integration with Overlapping | |
346 | data = numpy.sum(self.__buffer, axis=0) |
|
349 | data = numpy.sum(self.__buffer, axis=0) | |
347 | n = self.__profIndex |
|
350 | n = self.__profIndex | |
348 |
|
351 | |||
349 | return data, n |
|
352 | return data, n | |
350 |
|
353 | |||
351 | def byProfiles(self, data): |
|
354 | def byProfiles(self, data): | |
352 |
|
355 | |||
353 | self.__dataReady = False |
|
356 | self.__dataReady = False | |
354 | avgdata = None |
|
357 | avgdata = None | |
355 | # n = None |
|
358 | # n = None | |
356 |
|
359 | |||
357 | self.putData(data) |
|
360 | self.putData(data) | |
358 |
|
361 | |||
359 | if self.__profIndex == self.n: |
|
362 | if self.__profIndex == self.n: | |
360 |
|
363 | |||
361 | avgdata, n = self.pushData() |
|
364 | avgdata, n = self.pushData() | |
362 | self.__dataReady = True |
|
365 | self.__dataReady = True | |
363 |
|
366 | |||
364 | return avgdata |
|
367 | return avgdata | |
365 |
|
368 | |||
366 | def byTime(self, data, datatime): |
|
369 | def byTime(self, data, datatime): | |
367 |
|
370 | |||
368 | self.__dataReady = False |
|
371 | self.__dataReady = False | |
369 | avgdata = None |
|
372 | avgdata = None | |
370 | n = None |
|
373 | n = None | |
371 |
|
374 | |||
372 | self.putData(data) |
|
375 | self.putData(data) | |
373 |
|
376 | |||
374 | if (datatime - self.__initime) >= self.__integrationtime: |
|
377 | if (datatime - self.__initime) >= self.__integrationtime: | |
375 | avgdata, n = self.pushData() |
|
378 | avgdata, n = self.pushData() | |
376 | self.n = n |
|
379 | self.n = n | |
377 | self.__dataReady = True |
|
380 | self.__dataReady = True | |
378 |
|
381 | |||
379 | return avgdata |
|
382 | return avgdata | |
380 |
|
383 | |||
381 | def integrate(self, data, datatime=None): |
|
384 | def integrate(self, data, datatime=None): | |
382 |
|
385 | |||
383 | if self.__initime == None: |
|
386 | if self.__initime == None: | |
384 | self.__initime = datatime |
|
387 | self.__initime = datatime | |
385 |
|
388 | |||
386 | if self.__byTime: |
|
389 | if self.__byTime: | |
387 | avgdata = self.byTime(data, datatime) |
|
390 | avgdata = self.byTime(data, datatime) | |
388 | else: |
|
391 | else: | |
389 | avgdata = self.byProfiles(data) |
|
392 | avgdata = self.byProfiles(data) | |
390 |
|
393 | |||
391 |
|
394 | |||
392 | self.__lastdatatime = datatime |
|
395 | self.__lastdatatime = datatime | |
393 |
|
396 | |||
394 | if avgdata == None: |
|
397 | if avgdata == None: | |
395 | return None, None |
|
398 | return None, None | |
396 |
|
399 | |||
397 | avgdatatime = self.__initime |
|
400 | avgdatatime = self.__initime | |
398 |
|
401 | |||
399 | deltatime = datatime -self.__lastdatatime |
|
402 | deltatime = datatime -self.__lastdatatime | |
400 |
|
403 | |||
401 | if not self.__withOverapping: |
|
404 | if not self.__withOverapping: | |
402 | self.__initime = datatime |
|
405 | self.__initime = datatime | |
403 | else: |
|
406 | else: | |
404 | self.__initime += deltatime |
|
407 | self.__initime += deltatime | |
405 |
|
408 | |||
406 | return avgdata, avgdatatime |
|
409 | return avgdata, avgdatatime | |
407 |
|
410 | |||
408 | def integrateByBlock(self, dataOut): |
|
411 | def integrateByBlock(self, dataOut): | |
409 | times = int(dataOut.data.shape[1]/self.n) |
|
412 | times = int(dataOut.data.shape[1]/self.n) | |
410 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) |
|
413 | avgdata = numpy.zeros((dataOut.nChannels, times, dataOut.nHeights), dtype=numpy.complex) | |
411 |
|
414 | |||
412 | id_min = 0 |
|
415 | id_min = 0 | |
413 | id_max = self.n |
|
416 | id_max = self.n | |
414 |
|
417 | |||
415 | for i in range(times): |
|
418 | for i in range(times): | |
416 | junk = dataOut.data[:,id_min:id_max,:] |
|
419 | junk = dataOut.data[:,id_min:id_max,:] | |
417 | avgdata[:,i,:] = junk.sum(axis=1) |
|
420 | avgdata[:,i,:] = junk.sum(axis=1) | |
418 | id_min += self.n |
|
421 | id_min += self.n | |
419 | id_max += self.n |
|
422 | id_max += self.n | |
420 |
|
423 | |||
421 | timeInterval = dataOut.ippSeconds*self.n |
|
424 | timeInterval = dataOut.ippSeconds*self.n | |
422 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime |
|
425 | avgdatatime = (times - 1) * timeInterval + dataOut.utctime | |
423 | self.__dataReady = True |
|
426 | self.__dataReady = True | |
424 | return avgdata, avgdatatime |
|
427 | return avgdata, avgdatatime | |
425 |
|
428 | |||
426 | def run(self, dataOut, **kwargs): |
|
429 | def run(self, dataOut, **kwargs): | |
427 |
|
430 | |||
428 | if not self.isConfig: |
|
431 | if not self.isConfig: | |
429 | self.setup(**kwargs) |
|
432 | self.setup(**kwargs) | |
430 | self.isConfig = True |
|
433 | self.isConfig = True | |
431 |
|
434 | |||
432 | if self.byblock: |
|
435 | if self.byblock: | |
433 | avgdata, avgdatatime = self.integrateByBlock(dataOut) |
|
436 | avgdata, avgdatatime = self.integrateByBlock(dataOut) | |
434 | else: |
|
437 | else: | |
435 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
438 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
436 |
|
439 | |||
437 | # dataOut.timeInterval *= n |
|
440 | # dataOut.timeInterval *= n | |
438 | dataOut.flagNoData = True |
|
441 | dataOut.flagNoData = True | |
439 |
|
442 | |||
440 | if self.__dataReady: |
|
443 | if self.__dataReady: | |
441 | dataOut.data = avgdata |
|
444 | dataOut.data = avgdata | |
442 | dataOut.nCohInt *= self.n |
|
445 | dataOut.nCohInt *= self.n | |
443 | dataOut.utctime = avgdatatime |
|
446 | dataOut.utctime = avgdatatime | |
444 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
447 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
445 | dataOut.flagNoData = False |
|
448 | dataOut.flagNoData = False | |
446 |
|
449 | |||
447 | class Decoder(Operation): |
|
450 | class Decoder(Operation): | |
448 |
|
451 | |||
449 | isConfig = False |
|
452 | isConfig = False | |
450 | __profIndex = 0 |
|
453 | __profIndex = 0 | |
451 |
|
454 | |||
452 | code = None |
|
455 | code = None | |
453 |
|
456 | |||
454 | nCode = None |
|
457 | nCode = None | |
455 | nBaud = None |
|
458 | nBaud = None | |
456 |
|
459 | |||
457 |
|
460 | |||
458 | def __init__(self): |
|
461 | def __init__(self): | |
459 |
|
462 | |||
460 | Operation.__init__(self) |
|
463 | Operation.__init__(self) | |
461 |
|
464 | |||
462 | self.times = None |
|
465 | self.times = None | |
463 | self.osamp = None |
|
466 | self.osamp = None | |
464 | self.__setValues = False |
|
467 | self.__setValues = False | |
465 | # self.isConfig = False |
|
468 | # self.isConfig = False | |
466 |
|
469 | |||
467 | def setup(self, code, shape, times, osamp): |
|
470 | def setup(self, code, shape, times, osamp): | |
468 |
|
471 | |||
469 | self.__profIndex = 0 |
|
472 | self.__profIndex = 0 | |
470 |
|
473 | |||
471 | self.code = code |
|
474 | self.code = code | |
472 |
|
475 | |||
473 | self.nCode = len(code) |
|
476 | self.nCode = len(code) | |
474 | self.nBaud = len(code[0]) |
|
477 | self.nBaud = len(code[0]) | |
475 |
|
478 | |||
476 | if times != None: |
|
479 | if times != None: | |
477 | self.times = times |
|
480 | self.times = times | |
478 |
|
481 | |||
479 | if ((osamp != None) and (osamp >1)): |
|
482 | if ((osamp != None) and (osamp >1)): | |
480 | self.osamp = osamp |
|
483 | self.osamp = osamp | |
481 | self.code = numpy.repeat(code, repeats=self.osamp,axis=1) |
|
484 | self.code = numpy.repeat(code, repeats=self.osamp,axis=1) | |
482 | self.nBaud = self.nBaud*self.osamp |
|
485 | self.nBaud = self.nBaud*self.osamp | |
483 |
|
486 | |||
484 | if len(shape) == 2: |
|
487 | if len(shape) == 2: | |
485 | self.__nChannels, self.__nHeis = shape |
|
488 | self.__nChannels, self.__nHeis = shape | |
486 |
|
489 | |||
487 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
490 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
488 |
|
491 | |||
489 | __codeBuffer[:,0:self.nBaud] = self.code |
|
492 | __codeBuffer[:,0:self.nBaud] = self.code | |
490 |
|
493 | |||
491 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
494 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
492 |
|
495 | |||
493 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
496 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
494 |
|
497 | |||
495 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
498 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
496 | else: |
|
499 | else: | |
497 | self.__nChannels, self.__nProfiles, self.__nHeis = shape |
|
500 | self.__nChannels, self.__nProfiles, self.__nHeis = shape | |
498 |
|
501 | |||
499 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
502 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
500 |
|
503 | |||
501 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) |
|
504 | self.datadecTime = numpy.zeros((self.__nChannels, self.__nProfiles, self.ndatadec), dtype=numpy.complex) | |
502 |
|
505 | |||
503 |
|
506 | |||
504 |
|
507 | |||
505 | def convolutionInFreq(self, data): |
|
508 | def convolutionInFreq(self, data): | |
506 |
|
509 | |||
507 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
510 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
508 |
|
511 | |||
509 | fft_data = numpy.fft.fft(data, axis=1) |
|
512 | fft_data = numpy.fft.fft(data, axis=1) | |
510 |
|
513 | |||
511 | conv = fft_data*fft_code |
|
514 | conv = fft_data*fft_code | |
512 |
|
515 | |||
513 | data = numpy.fft.ifft(conv,axis=1) |
|
516 | data = numpy.fft.ifft(conv,axis=1) | |
514 |
|
517 | |||
515 | datadec = data[:,:-self.nBaud+1] |
|
518 | datadec = data[:,:-self.nBaud+1] | |
516 |
|
519 | |||
517 | return datadec |
|
520 | return datadec | |
518 |
|
521 | |||
519 | def convolutionInFreqOpt(self, data): |
|
522 | def convolutionInFreqOpt(self, data): | |
520 |
|
523 | |||
521 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
524 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
522 |
|
525 | |||
523 | data = cfunctions.decoder(fft_code, data) |
|
526 | data = cfunctions.decoder(fft_code, data) | |
524 |
|
527 | |||
525 | datadec = data[:,:-self.nBaud+1] |
|
528 | datadec = data[:,:-self.nBaud+1] | |
526 |
|
529 | |||
527 | return datadec |
|
530 | return datadec | |
528 |
|
531 | |||
529 | def convolutionInTime(self, data): |
|
532 | def convolutionInTime(self, data): | |
530 |
|
533 | |||
531 | code = self.code[self.__profIndex] |
|
534 | code = self.code[self.__profIndex] | |
532 |
|
535 | |||
533 | for i in range(self.__nChannels): |
|
536 | for i in range(self.__nChannels): | |
534 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') |
|
537 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') | |
535 |
|
538 | |||
536 | return self.datadecTime |
|
539 | return self.datadecTime | |
537 |
|
540 | |||
538 | def convolutionByBlockInTime(self, data): |
|
541 | def convolutionByBlockInTime(self, data): | |
539 | junk = numpy.lib.stride_tricks.as_strided(self.code, (self.times, self.code.size), (0, self.code.itemsize)) |
|
542 | junk = numpy.lib.stride_tricks.as_strided(self.code, (self.times, self.code.size), (0, self.code.itemsize)) | |
540 | junk = junk.flatten() |
|
543 | junk = junk.flatten() | |
541 | code_block = numpy.reshape(junk, (self.nCode*self.times,self.nBaud)) |
|
544 | code_block = numpy.reshape(junk, (self.nCode*self.times,self.nBaud)) | |
542 |
|
545 | |||
543 | for i in range(self.__nChannels): |
|
546 | for i in range(self.__nChannels): | |
544 | for j in range(self.__nProfiles): |
|
547 | for j in range(self.__nProfiles): | |
545 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='valid') |
|
548 | self.datadecTime[i,j,:] = numpy.correlate(data[i,j,:], code_block[j,:], mode='valid') | |
546 |
|
549 | |||
547 | return self.datadecTime |
|
550 | return self.datadecTime | |
548 |
|
551 | |||
549 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None): |
|
552 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0, times=None, osamp=None): | |
550 |
|
553 | |||
551 | if code == None: |
|
554 | if code == None: | |
552 | code = dataOut.code |
|
555 | code = dataOut.code | |
553 | else: |
|
556 | else: | |
554 | code = numpy.array(code).reshape(nCode,nBaud) |
|
557 | code = numpy.array(code).reshape(nCode,nBaud) | |
555 |
|
558 | |||
556 |
|
559 | |||
557 |
|
560 | |||
558 | if not self.isConfig: |
|
561 | if not self.isConfig: | |
559 |
|
562 | |||
560 | self.setup(code, dataOut.data.shape, times, osamp) |
|
563 | self.setup(code, dataOut.data.shape, times, osamp) | |
561 |
|
564 | |||
562 | dataOut.code = code |
|
565 | dataOut.code = code | |
563 | dataOut.nCode = nCode |
|
566 | dataOut.nCode = nCode | |
564 | dataOut.nBaud = nBaud |
|
567 | dataOut.nBaud = nBaud | |
565 | dataOut.radarControllerHeaderObj.code = code |
|
568 | dataOut.radarControllerHeaderObj.code = code | |
566 | dataOut.radarControllerHeaderObj.nCode = nCode |
|
569 | dataOut.radarControllerHeaderObj.nCode = nCode | |
567 | dataOut.radarControllerHeaderObj.nBaud = nBaud |
|
570 | dataOut.radarControllerHeaderObj.nBaud = nBaud | |
568 |
|
571 | |||
569 | self.isConfig = True |
|
572 | self.isConfig = True | |
570 |
|
573 | |||
571 | if mode == 0: |
|
574 | if mode == 0: | |
572 | datadec = self.convolutionInTime(dataOut.data) |
|
575 | datadec = self.convolutionInTime(dataOut.data) | |
573 |
|
576 | |||
574 | if mode == 1: |
|
577 | if mode == 1: | |
575 | datadec = self.convolutionInFreq(dataOut.data) |
|
578 | datadec = self.convolutionInFreq(dataOut.data) | |
576 |
|
579 | |||
577 | if mode == 2: |
|
580 | if mode == 2: | |
578 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
581 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
579 |
|
582 | |||
580 | if mode == 3: |
|
583 | if mode == 3: | |
581 | datadec = self.convolutionByBlockInTime(dataOut.data) |
|
584 | datadec = self.convolutionByBlockInTime(dataOut.data) | |
582 |
|
585 | |||
583 | if not(self.__setValues): |
|
586 | if not(self.__setValues): | |
584 | dataOut.code = self.code |
|
587 | dataOut.code = self.code | |
585 | dataOut.nCode = self.nCode |
|
588 | dataOut.nCode = self.nCode | |
586 | dataOut.nBaud = self.nBaud |
|
589 | dataOut.nBaud = self.nBaud | |
587 | dataOut.radarControllerHeaderObj.code = self.code |
|
590 | dataOut.radarControllerHeaderObj.code = self.code | |
588 | dataOut.radarControllerHeaderObj.nCode = self.nCode |
|
591 | dataOut.radarControllerHeaderObj.nCode = self.nCode | |
589 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud |
|
592 | dataOut.radarControllerHeaderObj.nBaud = self.nBaud | |
590 | self.__setValues = True |
|
593 | self.__setValues = True | |
591 |
|
594 | |||
592 | dataOut.data = datadec |
|
595 | dataOut.data = datadec | |
593 |
|
596 | |||
594 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
597 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] | |
595 |
|
598 | |||
596 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
599 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada | |
597 |
|
600 | |||
598 | if self.__profIndex == self.nCode-1: |
|
601 | if self.__profIndex == self.nCode-1: | |
599 | self.__profIndex = 0 |
|
602 | self.__profIndex = 0 | |
600 | return 1 |
|
603 | return 1 | |
601 |
|
604 | |||
602 | self.__profIndex += 1 |
|
605 | self.__profIndex += 1 | |
603 |
|
606 | |||
604 | return 1 |
|
607 | return 1 | |
605 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
608 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
606 |
|
609 | |||
607 |
|
610 | |||
608 | class ProfileConcat(Operation): |
|
611 | class ProfileConcat(Operation): | |
609 |
|
612 | |||
610 | isConfig = False |
|
613 | isConfig = False | |
611 | buffer = None |
|
614 | buffer = None | |
612 |
|
615 | |||
613 | def __init__(self): |
|
616 | def __init__(self): | |
614 |
|
617 | |||
615 | Operation.__init__(self) |
|
618 | Operation.__init__(self) | |
616 | self.profileIndex = 0 |
|
619 | self.profileIndex = 0 | |
617 |
|
620 | |||
618 | def reset(self): |
|
621 | def reset(self): | |
619 | self.buffer = numpy.zeros_like(self.buffer) |
|
622 | self.buffer = numpy.zeros_like(self.buffer) | |
620 | self.start_index = 0 |
|
623 | self.start_index = 0 | |
621 | self.times = 1 |
|
624 | self.times = 1 | |
622 |
|
625 | |||
623 | def setup(self, data, m, n=1): |
|
626 | def setup(self, data, m, n=1): | |
624 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) |
|
627 | self.buffer = numpy.zeros((data.shape[0],data.shape[1]*m),dtype=type(data[0,0])) | |
625 | self.profiles = data.shape[1] |
|
628 | self.profiles = data.shape[1] | |
626 | self.start_index = 0 |
|
629 | self.start_index = 0 | |
627 | self.times = 1 |
|
630 | self.times = 1 | |
628 |
|
631 | |||
629 | def concat(self, data): |
|
632 | def concat(self, data): | |
630 |
|
633 | |||
631 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() |
|
634 | self.buffer[:,self.start_index:self.profiles*self.times] = data.copy() | |
632 | self.start_index = self.start_index + self.profiles |
|
635 | self.start_index = self.start_index + self.profiles | |
633 |
|
636 | |||
634 | def run(self, dataOut, m): |
|
637 | def run(self, dataOut, m): | |
635 |
|
638 | |||
636 | dataOut.flagNoData = True |
|
639 | dataOut.flagNoData = True | |
637 |
|
640 | |||
638 | if not self.isConfig: |
|
641 | if not self.isConfig: | |
639 | self.setup(dataOut.data, m, 1) |
|
642 | self.setup(dataOut.data, m, 1) | |
640 | self.isConfig = True |
|
643 | self.isConfig = True | |
641 |
|
644 | |||
642 | self.concat(dataOut.data) |
|
645 | self.concat(dataOut.data) | |
643 | self.times += 1 |
|
646 | self.times += 1 | |
644 | if self.times > m: |
|
647 | if self.times > m: | |
645 | dataOut.data = self.buffer |
|
648 | dataOut.data = self.buffer | |
646 | self.reset() |
|
649 | self.reset() | |
647 | dataOut.flagNoData = False |
|
650 | dataOut.flagNoData = False | |
648 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas |
|
651 | # se deben actualizar mas propiedades del header y del objeto dataOut, por ejemplo, las alturas | |
649 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
652 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
650 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 |
|
653 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * 5 | |
651 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
|
654 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) | |
652 |
|
655 | |||
653 | class ProfileSelector(Operation): |
|
656 | class ProfileSelector(Operation): | |
654 |
|
657 | |||
655 | profileIndex = None |
|
658 | profileIndex = None | |
656 | # Tamanho total de los perfiles |
|
659 | # Tamanho total de los perfiles | |
657 | nProfiles = None |
|
660 | nProfiles = None | |
658 |
|
661 | |||
659 | def __init__(self): |
|
662 | def __init__(self): | |
660 |
|
663 | |||
661 | Operation.__init__(self) |
|
664 | Operation.__init__(self) | |
662 | self.profileIndex = 0 |
|
665 | self.profileIndex = 0 | |
663 |
|
666 | |||
664 | def incIndex(self): |
|
667 | def incIndex(self): | |
665 | self.profileIndex += 1 |
|
668 | self.profileIndex += 1 | |
666 |
|
669 | |||
667 | if self.profileIndex >= self.nProfiles: |
|
670 | if self.profileIndex >= self.nProfiles: | |
668 | self.profileIndex = 0 |
|
671 | self.profileIndex = 0 | |
669 |
|
672 | |||
670 | def isProfileInRange(self, minIndex, maxIndex): |
|
673 | def isProfileInRange(self, minIndex, maxIndex): | |
671 |
|
674 | |||
672 | if self.profileIndex < minIndex: |
|
675 | if self.profileIndex < minIndex: | |
673 | return False |
|
676 | return False | |
674 |
|
677 | |||
675 | if self.profileIndex > maxIndex: |
|
678 | if self.profileIndex > maxIndex: | |
676 | return False |
|
679 | return False | |
677 |
|
680 | |||
678 | return True |
|
681 | return True | |
679 |
|
682 | |||
680 | def isProfileInList(self, profileList): |
|
683 | def isProfileInList(self, profileList): | |
681 |
|
684 | |||
682 | if self.profileIndex not in profileList: |
|
685 | if self.profileIndex not in profileList: | |
683 | return False |
|
686 | return False | |
684 |
|
687 | |||
685 | return True |
|
688 | return True | |
686 |
|
689 | |||
687 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False): |
|
690 | def run(self, dataOut, profileList=None, profileRangeList=None, beam=None, byblock=False): | |
688 |
|
691 | |||
689 | dataOut.flagNoData = True |
|
692 | dataOut.flagNoData = True | |
690 | self.nProfiles = dataOut.nProfiles |
|
693 | self.nProfiles = dataOut.nProfiles | |
691 |
|
694 | |||
692 | if byblock: |
|
695 | if byblock: | |
693 |
|
696 | |||
694 | if profileList != None: |
|
697 | if profileList != None: | |
695 | dataOut.data = dataOut.data[:,profileList,:] |
|
698 | dataOut.data = dataOut.data[:,profileList,:] | |
696 | pass |
|
699 | pass | |
697 | else: |
|
700 | else: | |
698 | pmin = profileRangeList[0] |
|
701 | pmin = profileRangeList[0] | |
699 | pmax = profileRangeList[1] |
|
702 | pmax = profileRangeList[1] | |
700 | dataOut.data = dataOut.data[:,pmin:pmax+1,:] |
|
703 | dataOut.data = dataOut.data[:,pmin:pmax+1,:] | |
701 | dataOut.flagNoData = False |
|
704 | dataOut.flagNoData = False | |
702 | self.profileIndex = 0 |
|
705 | self.profileIndex = 0 | |
703 | return 1 |
|
706 | return 1 | |
704 |
|
707 | |||
705 | if profileList != None: |
|
708 | if profileList != None: | |
706 | if self.isProfileInList(profileList): |
|
709 | if self.isProfileInList(profileList): | |
707 | dataOut.flagNoData = False |
|
710 | dataOut.flagNoData = False | |
708 |
|
711 | |||
709 | self.incIndex() |
|
712 | self.incIndex() | |
710 | return 1 |
|
713 | return 1 | |
711 |
|
714 | |||
712 |
|
715 | |||
713 | elif profileRangeList != None: |
|
716 | elif profileRangeList != None: | |
714 | minIndex = profileRangeList[0] |
|
717 | minIndex = profileRangeList[0] | |
715 | maxIndex = profileRangeList[1] |
|
718 | maxIndex = profileRangeList[1] | |
716 | if self.isProfileInRange(minIndex, maxIndex): |
|
719 | if self.isProfileInRange(minIndex, maxIndex): | |
717 | dataOut.flagNoData = False |
|
720 | dataOut.flagNoData = False | |
718 |
|
721 | |||
719 | self.incIndex() |
|
722 | self.incIndex() | |
720 | return 1 |
|
723 | return 1 | |
721 | elif beam != None: #beam is only for AMISR data |
|
724 | elif beam != None: #beam is only for AMISR data | |
722 | if self.isProfileInList(dataOut.beamRangeDict[beam]): |
|
725 | if self.isProfileInList(dataOut.beamRangeDict[beam]): | |
723 | dataOut.flagNoData = False |
|
726 | dataOut.flagNoData = False | |
724 |
|
727 | |||
725 | self.incIndex() |
|
728 | self.incIndex() | |
726 | return 1 |
|
729 | return 1 | |
727 |
|
730 | |||
728 | else: |
|
731 | else: | |
729 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
732 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
730 |
|
733 | |||
731 | return 0 |
|
734 | return 0 | |
732 |
|
735 | |||
733 |
|
736 | |||
734 |
|
737 | |||
735 | class Reshaper(Operation): |
|
738 | class Reshaper(Operation): | |
736 | def __init__(self): |
|
739 | def __init__(self): | |
737 | Operation.__init__(self) |
|
740 | Operation.__init__(self) | |
738 | self.updateNewHeights = False |
|
741 | self.updateNewHeights = False | |
739 |
|
742 | |||
740 | def run(self, dataOut, shape): |
|
743 | def run(self, dataOut, shape): | |
741 | shape_tuple = tuple(shape) |
|
744 | shape_tuple = tuple(shape) | |
742 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) |
|
745 | dataOut.data = numpy.reshape(dataOut.data, shape_tuple) | |
743 | dataOut.flagNoData = False |
|
746 | dataOut.flagNoData = False | |
744 |
|
747 | |||
745 | if not(self.updateNewHeights): |
|
748 | if not(self.updateNewHeights): | |
746 | old_nheights = dataOut.nHeights |
|
749 | old_nheights = dataOut.nHeights | |
747 | new_nheights = dataOut.data.shape[2] |
|
750 | new_nheights = dataOut.data.shape[2] | |
748 | factor = new_nheights / old_nheights |
|
751 | factor = new_nheights / old_nheights | |
749 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
752 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] | |
750 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor |
|
753 | xf = dataOut.heightList[0] + dataOut.nHeights * deltaHeight * factor | |
751 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) No newline at end of file |
|
754 | dataOut.heightList = numpy.arange(dataOut.heightList[0], xf, deltaHeight) |
General Comments 0
You need to be logged in to leave comments.
Login now