@@ -1,552 +1,574 | |||||
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 os, sys |
|
7 | import os, sys | |
8 | import copy |
|
8 | import copy | |
9 | import numpy |
|
9 | import numpy | |
10 | import datetime |
|
10 | import datetime | |
11 |
|
11 | |||
12 | from jroheaderIO import SystemHeader, RadarControllerHeader |
|
12 | from jroheaderIO import SystemHeader, RadarControllerHeader | |
13 |
|
13 | |||
14 | def hildebrand_sekhon(data, navg): |
|
14 | def hildebrand_sekhon(data, navg): | |
15 | """ |
|
15 | """ | |
16 | This method is for the objective determination of de noise level in Doppler spectra. This |
|
16 | This method is for the objective determination of de noise level in Doppler spectra. This | |
17 | implementation technique is based on the fact that the standard deviation of the spectral |
|
17 | implementation technique is based on the fact that the standard deviation of the spectral | |
18 | densities is equal to the mean spectral density for white Gaussian noise |
|
18 | densities is equal to the mean spectral density for white Gaussian noise | |
19 |
|
19 | |||
20 | Inputs: |
|
20 | Inputs: | |
21 | Data : heights |
|
21 | Data : heights | |
22 | navg : numbers of averages |
|
22 | navg : numbers of averages | |
23 |
|
23 | |||
24 | Return: |
|
24 | Return: | |
25 | -1 : any error |
|
25 | -1 : any error | |
26 | anoise : noise's level |
|
26 | anoise : noise's level | |
27 | """ |
|
27 | """ | |
28 |
|
28 | |||
29 | dataflat = data.copy().reshape(-1) |
|
29 | dataflat = data.copy().reshape(-1) | |
30 | dataflat.sort() |
|
30 | dataflat.sort() | |
31 | npts = dataflat.size #numbers of points of the data |
|
31 | npts = dataflat.size #numbers of points of the data | |
32 | npts_noise = 0.2*npts |
|
32 | npts_noise = 0.2*npts | |
33 |
|
33 | |||
34 | if npts < 32: |
|
34 | if npts < 32: | |
35 | print "error in noise - requires at least 32 points" |
|
35 | print "error in noise - requires at least 32 points" | |
36 | return -1.0 |
|
36 | return -1.0 | |
37 |
|
37 | |||
38 | dataflat2 = numpy.power(dataflat,2) |
|
38 | dataflat2 = numpy.power(dataflat,2) | |
39 |
|
39 | |||
40 | cs = numpy.cumsum(dataflat) |
|
40 | cs = numpy.cumsum(dataflat) | |
41 | cs2 = numpy.cumsum(dataflat2) |
|
41 | cs2 = numpy.cumsum(dataflat2) | |
42 |
|
42 | |||
43 | # data sorted in ascending order |
|
43 | # data sorted in ascending order | |
44 | nmin = int((npts + 7.)/8) |
|
44 | nmin = int((npts + 7.)/8) | |
45 |
|
45 | |||
46 | for i in range(nmin, npts): |
|
46 | for i in range(nmin, npts): | |
47 | s = cs[i] |
|
47 | s = cs[i] | |
48 | s2 = cs2[i] |
|
48 | s2 = cs2[i] | |
49 | p = s / float(i); |
|
49 | p = s / float(i); | |
50 | p2 = p**2; |
|
50 | p2 = p**2; | |
51 | q = s2 / float(i) - p2; |
|
51 | q = s2 / float(i) - p2; | |
52 | leftc = p2; |
|
52 | leftc = p2; | |
53 | rightc = q * float(navg); |
|
53 | rightc = q * float(navg); | |
54 | R2 = leftc/rightc |
|
54 | R2 = leftc/rightc | |
55 |
|
55 | |||
56 | # Signal detect: R2 < 1 (R2 = leftc/rightc) |
|
56 | # Signal detect: R2 < 1 (R2 = leftc/rightc) | |
57 | if R2 < 1: |
|
57 | if R2 < 1: | |
58 | npts_noise = i |
|
58 | npts_noise = i | |
59 | break |
|
59 | break | |
60 |
|
60 | |||
61 |
|
61 | |||
62 | anoise = numpy.average(dataflat[0:npts_noise]) |
|
62 | anoise = numpy.average(dataflat[0:npts_noise]) | |
63 |
|
63 | |||
64 | return anoise; |
|
64 | return anoise; | |
65 |
|
65 | |||
66 | def sorting_bruce(data, navg): |
|
66 | def sorting_bruce(data, navg): | |
67 |
|
67 | |||
68 | data = data.copy() |
|
68 | data = data.copy() | |
69 |
|
69 | |||
70 | sortdata = numpy.sort(data) |
|
70 | sortdata = numpy.sort(data) | |
71 | lenOfData = len(data) |
|
71 | lenOfData = len(data) | |
72 | nums_min = lenOfData/10 |
|
72 | nums_min = lenOfData/10 | |
73 |
|
73 | |||
74 | if (lenOfData/10) > 0: |
|
74 | if (lenOfData/10) > 0: | |
75 | nums_min = lenOfData/10 |
|
75 | nums_min = lenOfData/10 | |
76 | else: |
|
76 | else: | |
77 | nums_min = 0 |
|
77 | nums_min = 0 | |
78 |
|
78 | |||
79 | rtest = 1.0 + 1.0/navg |
|
79 | rtest = 1.0 + 1.0/navg | |
80 |
|
80 | |||
81 | sum = 0. |
|
81 | sum = 0. | |
82 |
|
82 | |||
83 | sumq = 0. |
|
83 | sumq = 0. | |
84 |
|
84 | |||
85 | j = 0 |
|
85 | j = 0 | |
86 |
|
86 | |||
87 | cont = 1 |
|
87 | cont = 1 | |
88 |
|
88 | |||
89 | while((cont==1)and(j<lenOfData)): |
|
89 | while((cont==1)and(j<lenOfData)): | |
90 |
|
90 | |||
91 | sum += sortdata[j] |
|
91 | sum += sortdata[j] | |
92 |
|
92 | |||
93 | sumq += sortdata[j]**2 |
|
93 | sumq += sortdata[j]**2 | |
94 |
|
94 | |||
95 | j += 1 |
|
95 | j += 1 | |
96 |
|
96 | |||
97 | if j > nums_min: |
|
97 | if j > nums_min: | |
98 | if ((sumq*j) <= (rtest*sum**2)): |
|
98 | if ((sumq*j) <= (rtest*sum**2)): | |
99 | lnoise = sum / j |
|
99 | lnoise = sum / j | |
100 | else: |
|
100 | else: | |
101 | j = j - 1 |
|
101 | j = j - 1 | |
102 | sum = sum - sordata[j] |
|
102 | sum = sum - sordata[j] | |
103 | sumq = sumq - sordata[j]**2 |
|
103 | sumq = sumq - sordata[j]**2 | |
104 | cont = 0 |
|
104 | cont = 0 | |
105 |
|
105 | |||
106 | if j == nums_min: |
|
106 | if j == nums_min: | |
107 | lnoise = sum /j |
|
107 | lnoise = sum /j | |
108 |
|
108 | |||
109 | return lnoise |
|
109 | return lnoise | |
110 |
|
110 | |||
111 | class JROData: |
|
111 | class JROData: | |
112 |
|
112 | |||
113 | # m_BasicHeader = BasicHeader() |
|
113 | # m_BasicHeader = BasicHeader() | |
114 | # m_ProcessingHeader = ProcessingHeader() |
|
114 | # m_ProcessingHeader = ProcessingHeader() | |
115 |
|
115 | |||
116 | systemHeaderObj = SystemHeader() |
|
116 | systemHeaderObj = SystemHeader() | |
117 |
|
117 | |||
118 | radarControllerHeaderObj = RadarControllerHeader() |
|
118 | radarControllerHeaderObj = RadarControllerHeader() | |
119 |
|
119 | |||
120 | # data = None |
|
120 | # data = None | |
121 |
|
121 | |||
122 | type = None |
|
122 | type = None | |
123 |
|
123 | |||
124 | dtype = None |
|
124 | dtype = None | |
125 |
|
125 | |||
126 | # nChannels = None |
|
126 | # nChannels = None | |
127 |
|
127 | |||
128 | # nHeights = None |
|
128 | # nHeights = None | |
129 |
|
129 | |||
130 | nProfiles = None |
|
130 | nProfiles = None | |
131 |
|
131 | |||
132 | heightList = None |
|
132 | heightList = None | |
133 |
|
133 | |||
134 | channelList = None |
|
134 | channelList = None | |
135 |
|
135 | |||
136 | flagNoData = True |
|
136 | flagNoData = True | |
137 |
|
137 | |||
138 | flagTimeBlock = False |
|
138 | flagTimeBlock = False | |
139 |
|
139 | |||
|
140 | useLocalTime = False | |||
|
141 | ||||
140 | utctime = None |
|
142 | utctime = None | |
141 |
|
143 | |||
|
144 | timeZone = None | |||
|
145 | ||||
|
146 | dstFlag = None | |||
|
147 | ||||
|
148 | errorCount = None | |||
|
149 | ||||
142 | blocksize = None |
|
150 | blocksize = None | |
143 |
|
151 | |||
144 | nCode = None |
|
152 | nCode = None | |
145 |
|
153 | |||
146 | nBaud = None |
|
154 | nBaud = None | |
147 |
|
155 | |||
148 | code = None |
|
156 | code = None | |
149 |
|
157 | |||
150 | flagDecodeData = False #asumo q la data no esta decodificada |
|
158 | flagDecodeData = False #asumo q la data no esta decodificada | |
151 |
|
159 | |||
152 | flagDeflipData = False #asumo q la data no esta sin flip |
|
160 | flagDeflipData = False #asumo q la data no esta sin flip | |
153 |
|
161 | |||
154 | flagShiftFFT = False |
|
162 | flagShiftFFT = False | |
155 |
|
163 | |||
156 | ippSeconds = None |
|
164 | ippSeconds = None | |
157 |
|
165 | |||
158 | timeInterval = None |
|
166 | timeInterval = None | |
159 |
|
167 | |||
160 | nCohInt = None |
|
168 | nCohInt = None | |
161 |
|
169 | |||
162 | noise = None |
|
170 | noise = None | |
163 |
|
171 | |||
164 | windowOfFilter = 1 |
|
172 | windowOfFilter = 1 | |
165 |
|
173 | |||
166 | #Speed of ligth |
|
174 | #Speed of ligth | |
167 | C = 3e8 |
|
175 | C = 3e8 | |
168 |
|
176 | |||
169 | frequency = 49.92e6 |
|
177 | frequency = 49.92e6 | |
170 |
|
178 | |||
171 | def __init__(self): |
|
179 | def __init__(self): | |
172 |
|
180 | |||
173 | raise ValueError, "This class has not been implemented" |
|
181 | raise ValueError, "This class has not been implemented" | |
174 |
|
182 | |||
175 | def copy(self, inputObj=None): |
|
183 | def copy(self, inputObj=None): | |
176 |
|
184 | |||
177 | if inputObj == None: |
|
185 | if inputObj == None: | |
178 | return copy.deepcopy(self) |
|
186 | return copy.deepcopy(self) | |
179 |
|
187 | |||
180 | for key in inputObj.__dict__.keys(): |
|
188 | for key in inputObj.__dict__.keys(): | |
181 | self.__dict__[key] = inputObj.__dict__[key] |
|
189 | self.__dict__[key] = inputObj.__dict__[key] | |
182 |
|
190 | |||
183 | def deepcopy(self): |
|
191 | def deepcopy(self): | |
184 |
|
192 | |||
185 | return copy.deepcopy(self) |
|
193 | return copy.deepcopy(self) | |
186 |
|
194 | |||
187 | def isEmpty(self): |
|
195 | def isEmpty(self): | |
188 |
|
196 | |||
189 | return self.flagNoData |
|
197 | return self.flagNoData | |
190 |
|
198 | |||
191 | def getNoise(self): |
|
199 | def getNoise(self): | |
192 |
|
200 | |||
193 | raise ValueError, "Not implemented" |
|
201 | raise ValueError, "Not implemented" | |
194 |
|
202 | |||
195 | def getNChannels(self): |
|
203 | def getNChannels(self): | |
196 |
|
204 | |||
197 | return len(self.channelList) |
|
205 | return len(self.channelList) | |
198 |
|
206 | |||
199 | def getChannelIndexList(self): |
|
207 | def getChannelIndexList(self): | |
200 |
|
208 | |||
201 | return range(self.nChannels) |
|
209 | return range(self.nChannels) | |
202 |
|
210 | |||
203 | def getNHeights(self): |
|
211 | def getNHeights(self): | |
204 |
|
212 | |||
205 | return len(self.heightList) |
|
213 | return len(self.heightList) | |
206 |
|
214 | |||
207 | def getHeiRange(self, extrapoints=0): |
|
215 | def getHeiRange(self, extrapoints=0): | |
208 |
|
216 | |||
209 | heis = self.heightList |
|
217 | heis = self.heightList | |
210 | # deltah = self.heightList[1] - self.heightList[0] |
|
218 | # deltah = self.heightList[1] - self.heightList[0] | |
211 | # |
|
219 | # | |
212 | # heis.append(self.heightList[-1]) |
|
220 | # heis.append(self.heightList[-1]) | |
213 |
|
221 | |||
214 | return heis |
|
222 | return heis | |
215 |
|
223 | |||
|
224 | def getltctime(self): | |||
|
225 | ||||
|
226 | if self.useLocalTime: | |||
|
227 | return self.utctime - self.timeZone*60 | |||
|
228 | ||||
|
229 | return self.utctime | |||
|
230 | ||||
216 | def getDatatime(self): |
|
231 | def getDatatime(self): | |
217 |
|
232 | |||
218 |
datatime = datetime.datetime.utcfromtimestamp(self. |
|
233 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) | |
219 | return datatime |
|
234 | return datatime | |
220 |
|
235 | |||
221 | def getTimeRange(self): |
|
236 | def getTimeRange(self): | |
222 |
|
237 | |||
223 | datatime = [] |
|
238 | datatime = [] | |
224 |
|
239 | |||
225 |
datatime.append(self. |
|
240 | datatime.append(self.ltctime) | |
226 |
datatime.append(self. |
|
241 | datatime.append(self.ltctime + self.timeInterval) | |
227 |
|
242 | |||
228 | datatime = numpy.array(datatime) |
|
243 | datatime = numpy.array(datatime) | |
229 |
|
244 | |||
230 | return datatime |
|
245 | return datatime | |
231 |
|
246 | |||
232 | def getFmax(self): |
|
247 | def getFmax(self): | |
233 |
|
248 | |||
234 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
249 | PRF = 1./(self.ippSeconds * self.nCohInt) | |
235 |
|
250 | |||
236 | fmax = PRF/2. |
|
251 | fmax = PRF/2. | |
237 |
|
252 | |||
238 | return fmax |
|
253 | return fmax | |
239 |
|
254 | |||
240 | def getVmax(self): |
|
255 | def getVmax(self): | |
241 |
|
256 | |||
242 | _lambda = self.C/self.frequency |
|
257 | _lambda = self.C/self.frequency | |
243 |
|
258 | |||
244 | vmax = self.getFmax() * _lambda |
|
259 | vmax = self.getFmax() * _lambda | |
245 |
|
260 | |||
246 | return vmax |
|
261 | return vmax | |
247 |
|
262 | |||
248 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
263 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") | |
249 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
264 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") | |
250 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
265 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") | |
251 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
266 | noise = property(getNoise, "I'm the 'nHeights' property.") | |
252 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
267 | datatime = property(getDatatime, "I'm the 'datatime' property") | |
|
268 | ltctime = property(getltctime, "I'm the 'ltctime' property") | |||
253 |
|
269 | |||
254 | class Voltage(JROData): |
|
270 | class Voltage(JROData): | |
255 |
|
271 | |||
256 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
272 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
257 | data = None |
|
273 | data = None | |
258 |
|
274 | |||
259 | def __init__(self): |
|
275 | def __init__(self): | |
260 | ''' |
|
276 | ''' | |
261 | Constructor |
|
277 | Constructor | |
262 | ''' |
|
278 | ''' | |
263 |
|
279 | |||
264 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
280 | self.radarControllerHeaderObj = RadarControllerHeader() | |
265 |
|
281 | |||
266 | self.systemHeaderObj = SystemHeader() |
|
282 | self.systemHeaderObj = SystemHeader() | |
267 |
|
283 | |||
268 | self.type = "Voltage" |
|
284 | self.type = "Voltage" | |
269 |
|
285 | |||
270 | self.data = None |
|
286 | self.data = None | |
271 |
|
287 | |||
272 | self.dtype = None |
|
288 | self.dtype = None | |
273 |
|
289 | |||
274 | # self.nChannels = 0 |
|
290 | # self.nChannels = 0 | |
275 |
|
291 | |||
276 | # self.nHeights = 0 |
|
292 | # self.nHeights = 0 | |
277 |
|
293 | |||
278 | self.nProfiles = None |
|
294 | self.nProfiles = None | |
279 |
|
295 | |||
280 | self.heightList = None |
|
296 | self.heightList = None | |
281 |
|
297 | |||
282 | self.channelList = None |
|
298 | self.channelList = None | |
283 |
|
299 | |||
284 | # self.channelIndexList = None |
|
300 | # self.channelIndexList = None | |
285 |
|
301 | |||
286 | self.flagNoData = True |
|
302 | self.flagNoData = True | |
287 |
|
303 | |||
288 | self.flagTimeBlock = False |
|
304 | self.flagTimeBlock = False | |
289 |
|
305 | |||
290 | self.utctime = None |
|
306 | self.utctime = None | |
291 |
|
307 | |||
|
308 | self.timeZone = None | |||
|
309 | ||||
|
310 | self.dstFlag = None | |||
|
311 | ||||
|
312 | self.errorCount = None | |||
|
313 | ||||
292 | self.nCohInt = None |
|
314 | self.nCohInt = None | |
293 |
|
315 | |||
294 | self.blocksize = None |
|
316 | self.blocksize = None | |
295 |
|
317 | |||
296 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
318 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
297 |
|
319 | |||
298 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
320 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
299 |
|
321 | |||
300 | self.flagShiftFFT = False |
|
322 | self.flagShiftFFT = False | |
301 |
|
323 | |||
302 |
|
324 | |||
303 | def getNoisebyHildebrand(self): |
|
325 | def getNoisebyHildebrand(self): | |
304 | """ |
|
326 | """ | |
305 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
327 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
306 |
|
328 | |||
307 | Return: |
|
329 | Return: | |
308 | noiselevel |
|
330 | noiselevel | |
309 | """ |
|
331 | """ | |
310 |
|
332 | |||
311 | for channel in range(self.nChannels): |
|
333 | for channel in range(self.nChannels): | |
312 | daux = self.data_spc[channel,:,:] |
|
334 | daux = self.data_spc[channel,:,:] | |
313 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) |
|
335 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) | |
314 |
|
336 | |||
315 | return self.noise |
|
337 | return self.noise | |
316 |
|
338 | |||
317 | def getNoise(self, type = 1): |
|
339 | def getNoise(self, type = 1): | |
318 |
|
340 | |||
319 | self.noise = numpy.zeros(self.nChannels) |
|
341 | self.noise = numpy.zeros(self.nChannels) | |
320 |
|
342 | |||
321 | if type == 1: |
|
343 | if type == 1: | |
322 | noise = self.getNoisebyHildebrand() |
|
344 | noise = self.getNoisebyHildebrand() | |
323 |
|
345 | |||
324 | return 10*numpy.log10(noise) |
|
346 | return 10*numpy.log10(noise) | |
325 |
|
347 | |||
326 | class Spectra(JROData): |
|
348 | class Spectra(JROData): | |
327 |
|
349 | |||
328 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
350 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) | |
329 | data_spc = None |
|
351 | data_spc = None | |
330 |
|
352 | |||
331 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
353 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) | |
332 | data_cspc = None |
|
354 | data_cspc = None | |
333 |
|
355 | |||
334 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
356 | #data es un numpy array de 2 dmensiones (canales, alturas) | |
335 | data_dc = None |
|
357 | data_dc = None | |
336 |
|
358 | |||
337 | nFFTPoints = None |
|
359 | nFFTPoints = None | |
338 |
|
360 | |||
339 | nPairs = None |
|
361 | nPairs = None | |
340 |
|
362 | |||
341 | pairsList = None |
|
363 | pairsList = None | |
342 |
|
364 | |||
343 | nIncohInt = None |
|
365 | nIncohInt = None | |
344 |
|
366 | |||
345 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
367 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia | |
346 |
|
368 | |||
347 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
369 | nCohInt = None #se requiere para determinar el valor de timeInterval | |
348 |
|
370 | |||
349 | def __init__(self): |
|
371 | def __init__(self): | |
350 | ''' |
|
372 | ''' | |
351 | Constructor |
|
373 | Constructor | |
352 | ''' |
|
374 | ''' | |
353 |
|
375 | |||
354 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
376 | self.radarControllerHeaderObj = RadarControllerHeader() | |
355 |
|
377 | |||
356 | self.systemHeaderObj = SystemHeader() |
|
378 | self.systemHeaderObj = SystemHeader() | |
357 |
|
379 | |||
358 | self.type = "Spectra" |
|
380 | self.type = "Spectra" | |
359 |
|
381 | |||
360 | # self.data = None |
|
382 | # self.data = None | |
361 |
|
383 | |||
362 | self.dtype = None |
|
384 | self.dtype = None | |
363 |
|
385 | |||
364 | # self.nChannels = 0 |
|
386 | # self.nChannels = 0 | |
365 |
|
387 | |||
366 | # self.nHeights = 0 |
|
388 | # self.nHeights = 0 | |
367 |
|
389 | |||
368 | self.nProfiles = None |
|
390 | self.nProfiles = None | |
369 |
|
391 | |||
370 | self.heightList = None |
|
392 | self.heightList = None | |
371 |
|
393 | |||
372 | self.channelList = None |
|
394 | self.channelList = None | |
373 |
|
395 | |||
374 | # self.channelIndexList = None |
|
396 | # self.channelIndexList = None | |
375 |
|
397 | |||
376 | self.flagNoData = True |
|
398 | self.flagNoData = True | |
377 |
|
399 | |||
378 | self.flagTimeBlock = False |
|
400 | self.flagTimeBlock = False | |
379 |
|
401 | |||
380 | self.utctime = None |
|
402 | self.utctime = None | |
381 |
|
403 | |||
382 | self.nCohInt = None |
|
404 | self.nCohInt = None | |
383 |
|
405 | |||
384 | self.nIncohInt = None |
|
406 | self.nIncohInt = None | |
385 |
|
407 | |||
386 | self.blocksize = None |
|
408 | self.blocksize = None | |
387 |
|
409 | |||
388 | self.nFFTPoints = None |
|
410 | self.nFFTPoints = None | |
389 |
|
411 | |||
390 | self.wavelength = None |
|
412 | self.wavelength = None | |
391 |
|
413 | |||
392 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
414 | self.flagDecodeData = False #asumo q la data no esta decodificada | |
393 |
|
415 | |||
394 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
416 | self.flagDeflipData = False #asumo q la data no esta sin flip | |
395 |
|
417 | |||
396 | self.flagShiftFFT = False |
|
418 | self.flagShiftFFT = False | |
397 |
|
419 | |||
398 | def getNoisebyHildebrand(self): |
|
420 | def getNoisebyHildebrand(self): | |
399 | """ |
|
421 | """ | |
400 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
422 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon | |
401 |
|
423 | |||
402 | Return: |
|
424 | Return: | |
403 | noiselevel |
|
425 | noiselevel | |
404 | """ |
|
426 | """ | |
405 |
|
427 | |||
406 | for channel in range(self.nChannels): |
|
428 | for channel in range(self.nChannels): | |
407 | daux = self.data_spc[channel,:,:] |
|
429 | daux = self.data_spc[channel,:,:] | |
408 | self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
430 | self.noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) | |
409 |
|
431 | |||
410 | return self.noise |
|
432 | return self.noise | |
411 |
|
433 | |||
412 | def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): |
|
434 | def getNoisebyWindow(self, heiIndexMin=0, heiIndexMax=-1, freqIndexMin=0, freqIndexMax=-1): | |
413 | """ |
|
435 | """ | |
414 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: |
|
436 | Determina el ruido del canal utilizando la ventana indicada con las coordenadas: | |
415 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) |
|
437 | (heiIndexMIn, freqIndexMin) hasta (heiIndexMax, freqIndexMAx) | |
416 |
|
438 | |||
417 | Inputs: |
|
439 | Inputs: | |
418 | heiIndexMin: Limite inferior del eje de alturas |
|
440 | heiIndexMin: Limite inferior del eje de alturas | |
419 | heiIndexMax: Limite superior del eje de alturas |
|
441 | heiIndexMax: Limite superior del eje de alturas | |
420 | freqIndexMin: Limite inferior del eje de frecuencia |
|
442 | freqIndexMin: Limite inferior del eje de frecuencia | |
421 | freqIndexMax: Limite supoerior del eje de frecuencia |
|
443 | freqIndexMax: Limite supoerior del eje de frecuencia | |
422 | """ |
|
444 | """ | |
423 |
|
445 | |||
424 | data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] |
|
446 | data = self.data_spc[:, heiIndexMin:heiIndexMax, freqIndexMin:freqIndexMax] | |
425 |
|
447 | |||
426 | for channel in range(self.nChannels): |
|
448 | for channel in range(self.nChannels): | |
427 | daux = data[channel,:,:] |
|
449 | daux = data[channel,:,:] | |
428 | self.noise[channel] = numpy.average(daux) |
|
450 | self.noise[channel] = numpy.average(daux) | |
429 |
|
451 | |||
430 | return self.noise |
|
452 | return self.noise | |
431 |
|
453 | |||
432 | def getNoisebySort(self): |
|
454 | def getNoisebySort(self): | |
433 |
|
455 | |||
434 | for channel in range(self.nChannels): |
|
456 | for channel in range(self.nChannels): | |
435 | daux = self.data_spc[channel,:,:] |
|
457 | daux = self.data_spc[channel,:,:] | |
436 | self.noise[channel] = sorting_bruce(daux, self.nIncohInt) |
|
458 | self.noise[channel] = sorting_bruce(daux, self.nIncohInt) | |
437 |
|
459 | |||
438 | return self.noise |
|
460 | return self.noise | |
439 |
|
461 | |||
440 | def getNoise(self, type = 1): |
|
462 | def getNoise(self, type = 1): | |
441 |
|
463 | |||
442 | self.noise = numpy.zeros(self.nChannels) |
|
464 | self.noise = numpy.zeros(self.nChannels) | |
443 |
|
465 | |||
444 | if type == 1: |
|
466 | if type == 1: | |
445 | noise = self.getNoisebyHildebrand() |
|
467 | noise = self.getNoisebyHildebrand() | |
446 |
|
468 | |||
447 | if type == 2: |
|
469 | if type == 2: | |
448 | noise = self.getNoisebySort() |
|
470 | noise = self.getNoisebySort() | |
449 |
|
471 | |||
450 | if type == 3: |
|
472 | if type == 3: | |
451 | noise = self.getNoisebyWindow() |
|
473 | noise = self.getNoisebyWindow() | |
452 |
|
474 | |||
453 | return noise |
|
475 | return noise | |
454 |
|
476 | |||
455 |
|
477 | |||
456 | def getFreqRange(self, extrapoints=0): |
|
478 | def getFreqRange(self, extrapoints=0): | |
457 |
|
479 | |||
458 | deltafreq = self.getFmax() / self.nFFTPoints |
|
480 | deltafreq = self.getFmax() / self.nFFTPoints | |
459 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
481 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 | |
460 |
|
482 | |||
461 | return freqrange |
|
483 | return freqrange | |
462 |
|
484 | |||
463 | def getVelRange(self, extrapoints=0): |
|
485 | def getVelRange(self, extrapoints=0): | |
464 |
|
486 | |||
465 | deltav = self.getVmax() / self.nFFTPoints |
|
487 | deltav = self.getVmax() / self.nFFTPoints | |
466 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
488 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 | |
467 |
|
489 | |||
468 | return velrange |
|
490 | return velrange | |
469 |
|
491 | |||
470 | def getNPairs(self): |
|
492 | def getNPairs(self): | |
471 |
|
493 | |||
472 | return len(self.pairsList) |
|
494 | return len(self.pairsList) | |
473 |
|
495 | |||
474 | def getPairsIndexList(self): |
|
496 | def getPairsIndexList(self): | |
475 |
|
497 | |||
476 | return range(self.nPairs) |
|
498 | return range(self.nPairs) | |
477 |
|
499 | |||
478 | def getNormFactor(self): |
|
500 | def getNormFactor(self): | |
479 | pwcode = 1 |
|
501 | pwcode = 1 | |
480 | if self.flagDecodeData: |
|
502 | if self.flagDecodeData: | |
481 | pwcode = numpy.sum(self.code[0]**2) |
|
503 | pwcode = numpy.sum(self.code[0]**2) | |
482 | normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode |
|
504 | normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode | |
483 |
|
505 | |||
484 | return normFactor |
|
506 | return normFactor | |
485 |
|
507 | |||
486 | def getFlagCspc(self): |
|
508 | def getFlagCspc(self): | |
487 |
|
509 | |||
488 | if self.data_cspc == None: |
|
510 | if self.data_cspc == None: | |
489 | return True |
|
511 | return True | |
490 |
|
512 | |||
491 | return False |
|
513 | return False | |
492 |
|
514 | |||
493 | def getFlagDc(self): |
|
515 | def getFlagDc(self): | |
494 |
|
516 | |||
495 | if self.data_dc == None: |
|
517 | if self.data_dc == None: | |
496 | return True |
|
518 | return True | |
497 |
|
519 | |||
498 | return False |
|
520 | return False | |
499 |
|
521 | |||
500 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
522 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") | |
501 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
523 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") | |
502 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
524 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") | |
503 | flag_cspc = property(getFlagCspc) |
|
525 | flag_cspc = property(getFlagCspc) | |
504 | flag_dc = property(getFlagDc) |
|
526 | flag_dc = property(getFlagDc) | |
505 |
|
527 | |||
506 | class SpectraHeis(JROData): |
|
528 | class SpectraHeis(JROData): | |
507 |
|
529 | |||
508 | data_spc = None |
|
530 | data_spc = None | |
509 |
|
531 | |||
510 | data_cspc = None |
|
532 | data_cspc = None | |
511 |
|
533 | |||
512 | data_dc = None |
|
534 | data_dc = None | |
513 |
|
535 | |||
514 | nFFTPoints = None |
|
536 | nFFTPoints = None | |
515 |
|
537 | |||
516 | nPairs = None |
|
538 | nPairs = None | |
517 |
|
539 | |||
518 | pairsList = None |
|
540 | pairsList = None | |
519 |
|
541 | |||
520 | nIncohInt = None |
|
542 | nIncohInt = None | |
521 |
|
543 | |||
522 | def __init__(self): |
|
544 | def __init__(self): | |
523 |
|
545 | |||
524 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
546 | self.radarControllerHeaderObj = RadarControllerHeader() | |
525 |
|
547 | |||
526 | self.systemHeaderObj = SystemHeader() |
|
548 | self.systemHeaderObj = SystemHeader() | |
527 |
|
549 | |||
528 | self.type = "SpectraHeis" |
|
550 | self.type = "SpectraHeis" | |
529 |
|
551 | |||
530 | self.dtype = None |
|
552 | self.dtype = None | |
531 |
|
553 | |||
532 | # self.nChannels = 0 |
|
554 | # self.nChannels = 0 | |
533 |
|
555 | |||
534 | # self.nHeights = 0 |
|
556 | # self.nHeights = 0 | |
535 |
|
557 | |||
536 | self.nProfiles = None |
|
558 | self.nProfiles = None | |
537 |
|
559 | |||
538 | self.heightList = None |
|
560 | self.heightList = None | |
539 |
|
561 | |||
540 | self.channelList = None |
|
562 | self.channelList = None | |
541 |
|
563 | |||
542 | # self.channelIndexList = None |
|
564 | # self.channelIndexList = None | |
543 |
|
565 | |||
544 | self.flagNoData = True |
|
566 | self.flagNoData = True | |
545 |
|
567 | |||
546 | self.flagTimeBlock = False |
|
568 | self.flagTimeBlock = False | |
547 |
|
569 | |||
548 | self.nPairs = 0 |
|
570 | self.nPairs = 0 | |
549 |
|
571 | |||
550 | self.utctime = None |
|
572 | self.utctime = None | |
551 |
|
573 | |||
552 | self.blocksize = None |
|
574 | self.blocksize = None |
@@ -1,2729 +1,2737 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ |
|
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 |
|
6 | |||
7 | import os, sys |
|
7 | import os, sys | |
8 | import glob |
|
8 | import glob | |
9 | import time |
|
9 | import time | |
10 | import numpy |
|
10 | import numpy | |
11 | import fnmatch |
|
11 | import fnmatch | |
12 | import time, datetime |
|
12 | import time, datetime | |
13 | import pyfits |
|
13 | try: | |
|
14 | import pyfits | |||
|
15 | except: | |||
|
16 | print "pyfits module has not been imported, it should be installed to save files in fits format" | |||
14 |
|
17 | |||
15 | from jrodata import * |
|
18 | from jrodata import * | |
16 | from jroheaderIO import * |
|
19 | from jroheaderIO import * | |
17 | from jroprocessing import * |
|
20 | from jroprocessing import * | |
18 |
|
21 | |||
19 | LOCALTIME = -18000 |
|
22 | LOCALTIME = True #-18000 | |
20 |
|
23 | |||
21 | def isNumber(str): |
|
24 | def isNumber(str): | |
22 | """ |
|
25 | """ | |
23 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
26 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
24 |
|
27 | |||
25 | Excepciones: |
|
28 | Excepciones: | |
26 | Si un determinado string no puede ser convertido a numero |
|
29 | Si un determinado string no puede ser convertido a numero | |
27 | Input: |
|
30 | Input: | |
28 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
31 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
29 |
|
32 | |||
30 | Return: |
|
33 | Return: | |
31 | True : si el string es uno numerico |
|
34 | True : si el string es uno numerico | |
32 | False : no es un string numerico |
|
35 | False : no es un string numerico | |
33 | """ |
|
36 | """ | |
34 | try: |
|
37 | try: | |
35 | float( str ) |
|
38 | float( str ) | |
36 | return True |
|
39 | return True | |
37 | except: |
|
40 | except: | |
38 | return False |
|
41 | return False | |
39 |
|
42 | |||
40 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
43 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): | |
41 | """ |
|
44 | """ | |
42 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
45 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. | |
43 |
|
46 | |||
44 | Inputs: |
|
47 | Inputs: | |
45 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
48 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
46 |
|
49 | |||
47 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
50 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en | |
48 | segundos contados desde 01/01/1970. |
|
51 | segundos contados desde 01/01/1970. | |
49 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
52 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en | |
50 | segundos contados desde 01/01/1970. |
|
53 | segundos contados desde 01/01/1970. | |
51 |
|
54 | |||
52 | Return: |
|
55 | Return: | |
53 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
56 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
54 | fecha especificado, de lo contrario retorna False. |
|
57 | fecha especificado, de lo contrario retorna False. | |
55 |
|
58 | |||
56 | Excepciones: |
|
59 | Excepciones: | |
57 | Si el archivo no existe o no puede ser abierto |
|
60 | Si el archivo no existe o no puede ser abierto | |
58 | Si la cabecera no puede ser leida. |
|
61 | Si la cabecera no puede ser leida. | |
59 |
|
62 | |||
60 | """ |
|
63 | """ | |
61 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
64 | basicHeaderObj = BasicHeader(LOCALTIME) | |
62 |
|
65 | |||
63 | try: |
|
66 | try: | |
64 | fp = open(filename,'rb') |
|
67 | fp = open(filename,'rb') | |
65 | except: |
|
68 | except: | |
66 | raise IOError, "The file %s can't be opened" %(filename) |
|
69 | raise IOError, "The file %s can't be opened" %(filename) | |
67 |
|
70 | |||
68 | sts = basicHeaderObj.read(fp) |
|
71 | sts = basicHeaderObj.read(fp) | |
69 | fp.close() |
|
72 | fp.close() | |
70 |
|
73 | |||
71 | if not(sts): |
|
74 | if not(sts): | |
72 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
75 | print "Skipping the file %s because it has not a valid header" %(filename) | |
73 | return 0 |
|
76 | return 0 | |
74 |
|
77 | |||
75 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
78 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): | |
76 | return 0 |
|
79 | return 0 | |
77 |
|
80 | |||
78 | return 1 |
|
81 | return 1 | |
79 |
|
82 | |||
80 | def isFileinThisTime(filename, startTime, endTime): |
|
83 | def isFileinThisTime(filename, startTime, endTime): | |
81 | """ |
|
84 | """ | |
82 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
85 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. | |
83 |
|
86 | |||
84 | Inputs: |
|
87 | Inputs: | |
85 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
88 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) | |
86 |
|
89 | |||
87 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
90 | startTime : tiempo inicial del rango seleccionado en formato datetime.time | |
88 |
|
91 | |||
89 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
92 | endTime : tiempo final del rango seleccionado en formato datetime.time | |
90 |
|
93 | |||
91 | Return: |
|
94 | Return: | |
92 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
95 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de | |
93 | fecha especificado, de lo contrario retorna False. |
|
96 | fecha especificado, de lo contrario retorna False. | |
94 |
|
97 | |||
95 | Excepciones: |
|
98 | Excepciones: | |
96 | Si el archivo no existe o no puede ser abierto |
|
99 | Si el archivo no existe o no puede ser abierto | |
97 | Si la cabecera no puede ser leida. |
|
100 | Si la cabecera no puede ser leida. | |
98 |
|
101 | |||
99 | """ |
|
102 | """ | |
100 |
|
103 | |||
101 |
|
104 | |||
102 | try: |
|
105 | try: | |
103 | fp = open(filename,'rb') |
|
106 | fp = open(filename,'rb') | |
104 | except: |
|
107 | except: | |
105 | raise IOError, "The file %s can't be opened" %(filename) |
|
108 | raise IOError, "The file %s can't be opened" %(filename) | |
106 |
|
109 | |||
107 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
110 | basicHeaderObj = BasicHeader(LOCALTIME) | |
108 | sts = basicHeaderObj.read(fp) |
|
111 | sts = basicHeaderObj.read(fp) | |
109 | fp.close() |
|
112 | fp.close() | |
110 |
|
113 | |||
111 | thisDatetime = basicHeaderObj.datatime |
|
114 | thisDatetime = basicHeaderObj.datatime | |
112 | thisTime = basicHeaderObj.datatime.time() |
|
115 | thisTime = basicHeaderObj.datatime.time() | |
113 |
|
116 | |||
114 | if not(sts): |
|
117 | if not(sts): | |
115 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
118 | print "Skipping the file %s because it has not a valid header" %(filename) | |
116 | return None |
|
119 | return None | |
117 |
|
120 | |||
118 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
121 | if not ((startTime <= thisTime) and (endTime > thisTime)): | |
119 | return None |
|
122 | return None | |
120 |
|
123 | |||
121 | return thisDatetime |
|
124 | return thisDatetime | |
122 |
|
125 | |||
123 | def getlastFileFromPath(path, ext): |
|
126 | def getlastFileFromPath(path, ext): | |
124 | """ |
|
127 | """ | |
125 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
128 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" | |
126 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
129 | al final de la depuracion devuelve el ultimo file de la lista que quedo. | |
127 |
|
130 | |||
128 | Input: |
|
131 | Input: | |
129 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
132 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta | |
130 | ext : extension de los files contenidos en una carpeta |
|
133 | ext : extension de los files contenidos en una carpeta | |
131 |
|
134 | |||
132 | Return: |
|
135 | Return: | |
133 | El ultimo file de una determinada carpeta, no se considera el path. |
|
136 | El ultimo file de una determinada carpeta, no se considera el path. | |
134 | """ |
|
137 | """ | |
135 | validFilelist = [] |
|
138 | validFilelist = [] | |
136 | fileList = os.listdir(path) |
|
139 | fileList = os.listdir(path) | |
137 |
|
140 | |||
138 | # 0 1234 567 89A BCDE |
|
141 | # 0 1234 567 89A BCDE | |
139 | # H YYYY DDD SSS .ext |
|
142 | # H YYYY DDD SSS .ext | |
140 |
|
143 | |||
141 | for file in fileList: |
|
144 | for file in fileList: | |
142 | try: |
|
145 | try: | |
143 | year = int(file[1:5]) |
|
146 | year = int(file[1:5]) | |
144 | doy = int(file[5:8]) |
|
147 | doy = int(file[5:8]) | |
145 |
|
148 | |||
146 |
|
149 | |||
147 | except: |
|
150 | except: | |
148 | continue |
|
151 | continue | |
149 |
|
152 | |||
150 | if (os.path.splitext(file)[-1].lower() != ext.lower()): |
|
153 | if (os.path.splitext(file)[-1].lower() != ext.lower()): | |
151 | continue |
|
154 | continue | |
152 |
|
155 | |||
153 | validFilelist.append(file) |
|
156 | validFilelist.append(file) | |
154 |
|
157 | |||
155 | if validFilelist: |
|
158 | if validFilelist: | |
156 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
159 | validFilelist = sorted( validFilelist, key=str.lower ) | |
157 | return validFilelist[-1] |
|
160 | return validFilelist[-1] | |
158 |
|
161 | |||
159 | return None |
|
162 | return None | |
160 |
|
163 | |||
161 | def checkForRealPath(path, foldercounter, year, doy, set, ext): |
|
164 | def checkForRealPath(path, foldercounter, year, doy, set, ext): | |
162 | """ |
|
165 | """ | |
163 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
166 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, | |
164 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
167 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar | |
165 | el path exacto de un determinado file. |
|
168 | el path exacto de un determinado file. | |
166 |
|
169 | |||
167 | Example : |
|
170 | Example : | |
168 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
171 | nombre correcto del file es .../.../D2009307/P2009307367.ext | |
169 |
|
172 | |||
170 | Entonces la funcion prueba con las siguientes combinaciones |
|
173 | Entonces la funcion prueba con las siguientes combinaciones | |
171 | .../.../y2009307367.ext |
|
174 | .../.../y2009307367.ext | |
172 | .../.../Y2009307367.ext |
|
175 | .../.../Y2009307367.ext | |
173 | .../.../x2009307/y2009307367.ext |
|
176 | .../.../x2009307/y2009307367.ext | |
174 | .../.../x2009307/Y2009307367.ext |
|
177 | .../.../x2009307/Y2009307367.ext | |
175 | .../.../X2009307/y2009307367.ext |
|
178 | .../.../X2009307/y2009307367.ext | |
176 | .../.../X2009307/Y2009307367.ext |
|
179 | .../.../X2009307/Y2009307367.ext | |
177 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
180 | siendo para este caso, la ultima combinacion de letras, identica al file buscado | |
178 |
|
181 | |||
179 | Return: |
|
182 | Return: | |
180 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
183 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file | |
181 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
184 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas | |
182 | para el filename |
|
185 | para el filename | |
183 | """ |
|
186 | """ | |
184 | fullfilename = None |
|
187 | fullfilename = None | |
185 | find_flag = False |
|
188 | find_flag = False | |
186 | filename = None |
|
189 | filename = None | |
187 |
|
190 | |||
188 | prefixDirList = [None,'d','D'] |
|
191 | prefixDirList = [None,'d','D'] | |
189 | if ext.lower() == ".r": #voltage |
|
192 | if ext.lower() == ".r": #voltage | |
190 | prefixFileList = ['d','D'] |
|
193 | prefixFileList = ['d','D'] | |
191 | elif ext.lower() == ".pdata": #spectra |
|
194 | elif ext.lower() == ".pdata": #spectra | |
192 | prefixFileList = ['p','P'] |
|
195 | prefixFileList = ['p','P'] | |
193 | else: |
|
196 | else: | |
194 | return None, filename |
|
197 | return None, filename | |
195 |
|
198 | |||
196 | #barrido por las combinaciones posibles |
|
199 | #barrido por las combinaciones posibles | |
197 | for prefixDir in prefixDirList: |
|
200 | for prefixDir in prefixDirList: | |
198 | thispath = path |
|
201 | thispath = path | |
199 | if prefixDir != None: |
|
202 | if prefixDir != None: | |
200 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
203 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
201 | if foldercounter == 0: |
|
204 | if foldercounter == 0: | |
202 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) |
|
205 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) | |
203 | else: |
|
206 | else: | |
204 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter)) |
|
207 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter)) | |
205 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" |
|
208 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" | |
206 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
209 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
207 | fullfilename = os.path.join( thispath, filename ) #formo el path completo |
|
210 | fullfilename = os.path.join( thispath, filename ) #formo el path completo | |
208 |
|
211 | |||
209 | if os.path.exists( fullfilename ): #verifico que exista |
|
212 | if os.path.exists( fullfilename ): #verifico que exista | |
210 | find_flag = True |
|
213 | find_flag = True | |
211 | break |
|
214 | break | |
212 | if find_flag: |
|
215 | if find_flag: | |
213 | break |
|
216 | break | |
214 |
|
217 | |||
215 | if not(find_flag): |
|
218 | if not(find_flag): | |
216 | return None, filename |
|
219 | return None, filename | |
217 |
|
220 | |||
218 | return fullfilename, filename |
|
221 | return fullfilename, filename | |
219 |
|
222 | |||
220 | def isDoyFolder(folder): |
|
223 | def isDoyFolder(folder): | |
221 | try: |
|
224 | try: | |
222 | year = int(folder[1:5]) |
|
225 | year = int(folder[1:5]) | |
223 | except: |
|
226 | except: | |
224 | return 0 |
|
227 | return 0 | |
225 |
|
228 | |||
226 | try: |
|
229 | try: | |
227 | doy = int(folder[5:8]) |
|
230 | doy = int(folder[5:8]) | |
228 | except: |
|
231 | except: | |
229 | return 0 |
|
232 | return 0 | |
230 |
|
233 | |||
231 | return 1 |
|
234 | return 1 | |
232 |
|
235 | |||
233 | class JRODataIO: |
|
236 | class JRODataIO: | |
234 |
|
237 | |||
235 | c = 3E8 |
|
238 | c = 3E8 | |
236 |
|
239 | |||
237 | isConfig = False |
|
240 | isConfig = False | |
238 |
|
241 | |||
239 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
242 | basicHeaderObj = BasicHeader(LOCALTIME) | |
240 |
|
243 | |||
241 | systemHeaderObj = SystemHeader() |
|
244 | systemHeaderObj = SystemHeader() | |
242 |
|
245 | |||
243 | radarControllerHeaderObj = RadarControllerHeader() |
|
246 | radarControllerHeaderObj = RadarControllerHeader() | |
244 |
|
247 | |||
245 | processingHeaderObj = ProcessingHeader() |
|
248 | processingHeaderObj = ProcessingHeader() | |
246 |
|
249 | |||
247 | online = 0 |
|
250 | online = 0 | |
248 |
|
251 | |||
249 | dtype = None |
|
252 | dtype = None | |
250 |
|
253 | |||
251 | pathList = [] |
|
254 | pathList = [] | |
252 |
|
255 | |||
253 | filenameList = [] |
|
256 | filenameList = [] | |
254 |
|
257 | |||
255 | filename = None |
|
258 | filename = None | |
256 |
|
259 | |||
257 | ext = None |
|
260 | ext = None | |
258 |
|
261 | |||
259 | flagIsNewFile = 1 |
|
262 | flagIsNewFile = 1 | |
260 |
|
263 | |||
261 | flagTimeBlock = 0 |
|
264 | flagTimeBlock = 0 | |
262 |
|
265 | |||
263 | flagIsNewBlock = 0 |
|
266 | flagIsNewBlock = 0 | |
264 |
|
267 | |||
265 | fp = None |
|
268 | fp = None | |
266 |
|
269 | |||
267 | firstHeaderSize = 0 |
|
270 | firstHeaderSize = 0 | |
268 |
|
271 | |||
269 | basicHeaderSize = 24 |
|
272 | basicHeaderSize = 24 | |
270 |
|
273 | |||
271 | versionFile = 1103 |
|
274 | versionFile = 1103 | |
272 |
|
275 | |||
273 | fileSize = None |
|
276 | fileSize = None | |
274 |
|
277 | |||
275 | ippSeconds = None |
|
278 | ippSeconds = None | |
276 |
|
279 | |||
277 | fileSizeByHeader = None |
|
280 | fileSizeByHeader = None | |
278 |
|
281 | |||
279 | fileIndex = None |
|
282 | fileIndex = None | |
280 |
|
283 | |||
281 | profileIndex = None |
|
284 | profileIndex = None | |
282 |
|
285 | |||
283 | blockIndex = None |
|
286 | blockIndex = None | |
284 |
|
287 | |||
285 | nTotalBlocks = None |
|
288 | nTotalBlocks = None | |
286 |
|
289 | |||
287 | maxTimeStep = 30 |
|
290 | maxTimeStep = 30 | |
288 |
|
291 | |||
289 | lastUTTime = None |
|
292 | lastUTTime = None | |
290 |
|
293 | |||
291 | datablock = None |
|
294 | datablock = None | |
292 |
|
295 | |||
293 | dataOut = None |
|
296 | dataOut = None | |
294 |
|
297 | |||
295 | blocksize = None |
|
298 | blocksize = None | |
296 |
|
299 | |||
297 | def __init__(self): |
|
300 | def __init__(self): | |
298 |
|
301 | |||
299 | raise ValueError, "Not implemented" |
|
302 | raise ValueError, "Not implemented" | |
300 |
|
303 | |||
301 | def run(self): |
|
304 | def run(self): | |
302 |
|
305 | |||
303 | raise ValueError, "Not implemented" |
|
306 | raise ValueError, "Not implemented" | |
304 |
|
307 | |||
305 | def getOutput(self): |
|
308 | def getOutput(self): | |
306 |
|
309 | |||
307 | return self.dataOut |
|
310 | return self.dataOut | |
308 |
|
311 | |||
309 | class JRODataReader(JRODataIO, ProcessingUnit): |
|
312 | class JRODataReader(JRODataIO, ProcessingUnit): | |
310 |
|
313 | |||
311 | nReadBlocks = 0 |
|
314 | nReadBlocks = 0 | |
312 |
|
315 | |||
313 | delay = 10 #number of seconds waiting a new file |
|
316 | delay = 10 #number of seconds waiting a new file | |
314 |
|
317 | |||
315 | nTries = 3 #quantity tries |
|
318 | nTries = 3 #quantity tries | |
316 |
|
319 | |||
317 | nFiles = 3 #number of files for searching |
|
320 | nFiles = 3 #number of files for searching | |
318 |
|
321 | |||
319 | path = None |
|
322 | path = None | |
320 |
|
323 | |||
321 | foldercounter = 0 |
|
324 | foldercounter = 0 | |
322 |
|
325 | |||
323 | flagNoMoreFiles = 0 |
|
326 | flagNoMoreFiles = 0 | |
324 |
|
327 | |||
325 | datetimeList = [] |
|
328 | datetimeList = [] | |
326 |
|
329 | |||
327 | __isFirstTimeOnline = 1 |
|
330 | __isFirstTimeOnline = 1 | |
328 |
|
331 | |||
329 | __printInfo = True |
|
332 | __printInfo = True | |
330 |
|
333 | |||
|
334 | profileIndex = None | |||
|
335 | ||||
331 | def __init__(self): |
|
336 | def __init__(self): | |
332 |
|
337 | |||
333 | """ |
|
338 | """ | |
334 |
|
339 | |||
335 | """ |
|
340 | """ | |
336 |
|
341 | |||
337 | raise ValueError, "This method has not been implemented" |
|
342 | raise ValueError, "This method has not been implemented" | |
338 |
|
343 | |||
339 |
|
344 | |||
340 | def createObjByDefault(self): |
|
345 | def createObjByDefault(self): | |
341 | """ |
|
346 | """ | |
342 |
|
347 | |||
343 | """ |
|
348 | """ | |
344 | raise ValueError, "This method has not been implemented" |
|
349 | raise ValueError, "This method has not been implemented" | |
345 |
|
350 | |||
346 | def getBlockDimension(self): |
|
351 | def getBlockDimension(self): | |
347 |
|
352 | |||
348 | raise ValueError, "No implemented" |
|
353 | raise ValueError, "No implemented" | |
349 |
|
354 | |||
350 | def __searchFilesOffLine(self, |
|
355 | def __searchFilesOffLine(self, | |
351 | path, |
|
356 | path, | |
352 | startDate, |
|
357 | startDate, | |
353 | endDate, |
|
358 | endDate, | |
354 | startTime=datetime.time(0,0,0), |
|
359 | startTime=datetime.time(0,0,0), | |
355 | endTime=datetime.time(23,59,59), |
|
360 | endTime=datetime.time(23,59,59), | |
356 | set=None, |
|
361 | set=None, | |
357 | expLabel='', |
|
362 | expLabel='', | |
358 | ext='.r', |
|
363 | ext='.r', | |
359 | walk=True): |
|
364 | walk=True): | |
360 |
|
365 | |||
361 | pathList = [] |
|
366 | pathList = [] | |
362 |
|
367 | |||
363 | if not walk: |
|
368 | if not walk: | |
364 | pathList.append(path) |
|
369 | pathList.append(path) | |
365 |
|
370 | |||
366 | else: |
|
371 | else: | |
367 | dirList = [] |
|
372 | dirList = [] | |
368 | for thisPath in os.listdir(path): |
|
373 | for thisPath in os.listdir(path): | |
369 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
374 | if not os.path.isdir(os.path.join(path,thisPath)): | |
370 | continue |
|
375 | continue | |
371 | if not isDoyFolder(thisPath): |
|
376 | if not isDoyFolder(thisPath): | |
372 | continue |
|
377 | continue | |
373 |
|
378 | |||
374 | dirList.append(thisPath) |
|
379 | dirList.append(thisPath) | |
375 |
|
380 | |||
376 | if not(dirList): |
|
381 | if not(dirList): | |
377 | return None, None |
|
382 | return None, None | |
378 |
|
383 | |||
379 | thisDate = startDate |
|
384 | thisDate = startDate | |
380 |
|
385 | |||
381 | while(thisDate <= endDate): |
|
386 | while(thisDate <= endDate): | |
382 | year = thisDate.timetuple().tm_year |
|
387 | year = thisDate.timetuple().tm_year | |
383 | doy = thisDate.timetuple().tm_yday |
|
388 | doy = thisDate.timetuple().tm_yday | |
384 |
|
389 | |||
385 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
390 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') | |
386 | if len(matchlist) == 0: |
|
391 | if len(matchlist) == 0: | |
387 | thisDate += datetime.timedelta(1) |
|
392 | thisDate += datetime.timedelta(1) | |
388 | continue |
|
393 | continue | |
389 | for match in matchlist: |
|
394 | for match in matchlist: | |
390 | pathList.append(os.path.join(path,match,expLabel)) |
|
395 | pathList.append(os.path.join(path,match,expLabel)) | |
391 |
|
396 | |||
392 | thisDate += datetime.timedelta(1) |
|
397 | thisDate += datetime.timedelta(1) | |
393 |
|
398 | |||
394 | if pathList == []: |
|
399 | if pathList == []: | |
395 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
400 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) | |
396 | return None, None |
|
401 | return None, None | |
397 |
|
402 | |||
398 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
403 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) | |
399 |
|
404 | |||
400 | filenameList = [] |
|
405 | filenameList = [] | |
401 | datetimeList = [] |
|
406 | datetimeList = [] | |
402 |
|
407 | |||
403 | for i in range(len(pathList)): |
|
408 | for i in range(len(pathList)): | |
404 |
|
409 | |||
405 | thisPath = pathList[i] |
|
410 | thisPath = pathList[i] | |
406 |
|
411 | |||
407 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
412 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
408 | fileList.sort() |
|
413 | fileList.sort() | |
409 |
|
414 | |||
410 | for file in fileList: |
|
415 | for file in fileList: | |
411 |
|
416 | |||
412 | filename = os.path.join(thisPath,file) |
|
417 | filename = os.path.join(thisPath,file) | |
413 | thisDatetime = isFileinThisTime(filename, startTime, endTime) |
|
418 | thisDatetime = isFileinThisTime(filename, startTime, endTime) | |
414 |
|
419 | |||
415 | if not(thisDatetime): |
|
420 | if not(thisDatetime): | |
416 | continue |
|
421 | continue | |
417 |
|
422 | |||
418 | filenameList.append(filename) |
|
423 | filenameList.append(filename) | |
419 | datetimeList.append(thisDatetime) |
|
424 | datetimeList.append(thisDatetime) | |
420 |
|
425 | |||
421 | if not(filenameList): |
|
426 | if not(filenameList): | |
422 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
427 | print "Any file was found for the time range %s - %s" %(startTime, endTime) | |
423 | return None, None |
|
428 | return None, None | |
424 |
|
429 | |||
425 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
430 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) | |
426 |
|
431 | |||
427 |
|
432 | |||
428 | for i in range(len(filenameList)): |
|
433 | for i in range(len(filenameList)): | |
429 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
434 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) | |
430 |
|
435 | |||
431 | self.filenameList = filenameList |
|
436 | self.filenameList = filenameList | |
432 | self.datetimeList = datetimeList |
|
437 | self.datetimeList = datetimeList | |
433 |
|
438 | |||
434 | return pathList, filenameList |
|
439 | return pathList, filenameList | |
435 |
|
440 | |||
436 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True): |
|
441 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True): | |
437 |
|
442 | |||
438 | """ |
|
443 | """ | |
439 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
444 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y | |
440 | devuelve el archivo encontrado ademas de otros datos. |
|
445 | devuelve el archivo encontrado ademas de otros datos. | |
441 |
|
446 | |||
442 | Input: |
|
447 | Input: | |
443 | path : carpeta donde estan contenidos los files que contiene data |
|
448 | path : carpeta donde estan contenidos los files que contiene data | |
444 |
|
449 | |||
445 | expLabel : Nombre del subexperimento (subfolder) |
|
450 | expLabel : Nombre del subexperimento (subfolder) | |
446 |
|
451 | |||
447 | ext : extension de los files |
|
452 | ext : extension de los files | |
448 |
|
453 | |||
449 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
454 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) | |
450 |
|
455 | |||
451 | Return: |
|
456 | Return: | |
452 | directory : eL directorio donde esta el file encontrado |
|
457 | directory : eL directorio donde esta el file encontrado | |
453 | filename : el ultimo file de una determinada carpeta |
|
458 | filename : el ultimo file de una determinada carpeta | |
454 | year : el anho |
|
459 | year : el anho | |
455 | doy : el numero de dia del anho |
|
460 | doy : el numero de dia del anho | |
456 | set : el set del archivo |
|
461 | set : el set del archivo | |
457 |
|
462 | |||
458 |
|
463 | |||
459 | """ |
|
464 | """ | |
460 | dirList = [] |
|
465 | dirList = [] | |
461 |
|
466 | |||
462 | if not walk: |
|
467 | if not walk: | |
463 | fullpath = path |
|
468 | fullpath = path | |
464 |
|
469 | |||
465 | else: |
|
470 | else: | |
466 | #Filtra solo los directorios |
|
471 | #Filtra solo los directorios | |
467 | for thisPath in os.listdir(path): |
|
472 | for thisPath in os.listdir(path): | |
468 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
473 | if not os.path.isdir(os.path.join(path,thisPath)): | |
469 | continue |
|
474 | continue | |
470 | if not isDoyFolder(thisPath): |
|
475 | if not isDoyFolder(thisPath): | |
471 | continue |
|
476 | continue | |
472 |
|
477 | |||
473 | dirList.append(thisPath) |
|
478 | dirList.append(thisPath) | |
474 |
|
479 | |||
475 | if not(dirList): |
|
480 | if not(dirList): | |
476 | return None, None, None, None, None |
|
481 | return None, None, None, None, None | |
477 |
|
482 | |||
478 | dirList = sorted( dirList, key=str.lower ) |
|
483 | dirList = sorted( dirList, key=str.lower ) | |
479 |
|
484 | |||
480 | doypath = dirList[-1] |
|
485 | doypath = dirList[-1] | |
481 | foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0 |
|
486 | foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0 | |
482 | fullpath = os.path.join(path, doypath, expLabel) |
|
487 | fullpath = os.path.join(path, doypath, expLabel) | |
483 |
|
488 | |||
484 |
|
489 | |||
485 | print "%s folder was found: " %(fullpath ) |
|
490 | print "%s folder was found: " %(fullpath ) | |
486 |
|
491 | |||
487 | filename = getlastFileFromPath(fullpath, ext) |
|
492 | filename = getlastFileFromPath(fullpath, ext) | |
488 |
|
493 | |||
489 | if not(filename): |
|
494 | if not(filename): | |
490 | return None, None, None, None, None |
|
495 | return None, None, None, None, None | |
491 |
|
496 | |||
492 | print "%s file was found" %(filename) |
|
497 | print "%s file was found" %(filename) | |
493 |
|
498 | |||
494 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
499 | if not(self.__verifyFile(os.path.join(fullpath, filename))): | |
495 | return None, None, None, None, None |
|
500 | return None, None, None, None, None | |
496 |
|
501 | |||
497 | year = int( filename[1:5] ) |
|
502 | year = int( filename[1:5] ) | |
498 | doy = int( filename[5:8] ) |
|
503 | doy = int( filename[5:8] ) | |
499 | set = int( filename[8:11] ) |
|
504 | set = int( filename[8:11] ) | |
500 |
|
505 | |||
501 | return fullpath, foldercounter, filename, year, doy, set |
|
506 | return fullpath, foldercounter, filename, year, doy, set | |
502 |
|
507 | |||
503 | def __setNextFileOffline(self): |
|
508 | def __setNextFileOffline(self): | |
504 |
|
509 | |||
505 | idFile = self.fileIndex |
|
510 | idFile = self.fileIndex | |
506 |
|
511 | |||
507 | while (True): |
|
512 | while (True): | |
508 | idFile += 1 |
|
513 | idFile += 1 | |
509 | if not(idFile < len(self.filenameList)): |
|
514 | if not(idFile < len(self.filenameList)): | |
510 | self.flagNoMoreFiles = 1 |
|
515 | self.flagNoMoreFiles = 1 | |
511 | print "No more Files" |
|
516 | print "No more Files" | |
512 | return 0 |
|
517 | return 0 | |
513 |
|
518 | |||
514 | filename = self.filenameList[idFile] |
|
519 | filename = self.filenameList[idFile] | |
515 |
|
520 | |||
516 | if not(self.__verifyFile(filename)): |
|
521 | if not(self.__verifyFile(filename)): | |
517 | continue |
|
522 | continue | |
518 |
|
523 | |||
519 | fileSize = os.path.getsize(filename) |
|
524 | fileSize = os.path.getsize(filename) | |
520 | fp = open(filename,'rb') |
|
525 | fp = open(filename,'rb') | |
521 | break |
|
526 | break | |
522 |
|
527 | |||
523 | self.flagIsNewFile = 1 |
|
528 | self.flagIsNewFile = 1 | |
524 | self.fileIndex = idFile |
|
529 | self.fileIndex = idFile | |
525 | self.filename = filename |
|
530 | self.filename = filename | |
526 | self.fileSize = fileSize |
|
531 | self.fileSize = fileSize | |
527 | self.fp = fp |
|
532 | self.fp = fp | |
528 |
|
533 | |||
529 | print "Setting the file: %s"%self.filename |
|
534 | print "Setting the file: %s"%self.filename | |
530 |
|
535 | |||
531 | return 1 |
|
536 | return 1 | |
532 |
|
537 | |||
533 | def __setNextFileOnline(self): |
|
538 | def __setNextFileOnline(self): | |
534 | """ |
|
539 | """ | |
535 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
540 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si | |
536 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
541 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files | |
537 | siguientes. |
|
542 | siguientes. | |
538 |
|
543 | |||
539 | Affected: |
|
544 | Affected: | |
540 | self.flagIsNewFile |
|
545 | self.flagIsNewFile | |
541 | self.filename |
|
546 | self.filename | |
542 | self.fileSize |
|
547 | self.fileSize | |
543 | self.fp |
|
548 | self.fp | |
544 | self.set |
|
549 | self.set | |
545 | self.flagNoMoreFiles |
|
550 | self.flagNoMoreFiles | |
546 |
|
551 | |||
547 | Return: |
|
552 | Return: | |
548 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
553 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado | |
549 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
554 | 1 : si el file fue abierto con exito y esta listo a ser leido | |
550 |
|
555 | |||
551 | Excepciones: |
|
556 | Excepciones: | |
552 | Si un determinado file no puede ser abierto |
|
557 | Si un determinado file no puede ser abierto | |
553 | """ |
|
558 | """ | |
554 | nFiles = 0 |
|
559 | nFiles = 0 | |
555 | fileOk_flag = False |
|
560 | fileOk_flag = False | |
556 | firstTime_flag = True |
|
561 | firstTime_flag = True | |
557 |
|
562 | |||
558 | self.set += 1 |
|
563 | self.set += 1 | |
559 |
|
564 | |||
560 | if self.set > 999: |
|
565 | if self.set > 999: | |
561 | self.set = 0 |
|
566 | self.set = 0 | |
562 | self.foldercounter += 1 |
|
567 | self.foldercounter += 1 | |
563 |
|
568 | |||
564 | #busca el 1er file disponible |
|
569 | #busca el 1er file disponible | |
565 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
570 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) | |
566 | if fullfilename: |
|
571 | if fullfilename: | |
567 | if self.__verifyFile(fullfilename, False): |
|
572 | if self.__verifyFile(fullfilename, False): | |
568 | fileOk_flag = True |
|
573 | fileOk_flag = True | |
569 |
|
574 | |||
570 | #si no encuentra un file entonces espera y vuelve a buscar |
|
575 | #si no encuentra un file entonces espera y vuelve a buscar | |
571 | if not(fileOk_flag): |
|
576 | if not(fileOk_flag): | |
572 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
577 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles | |
573 |
|
578 | |||
574 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
579 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
575 | tries = self.nTries |
|
580 | tries = self.nTries | |
576 | else: |
|
581 | else: | |
577 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
582 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
578 |
|
583 | |||
579 | for nTries in range( tries ): |
|
584 | for nTries in range( tries ): | |
580 | if firstTime_flag: |
|
585 | if firstTime_flag: | |
581 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
586 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) | |
582 | time.sleep( self.delay ) |
|
587 | time.sleep( self.delay ) | |
583 | else: |
|
588 | else: | |
584 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
589 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) | |
585 |
|
590 | |||
586 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
591 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) | |
587 | if fullfilename: |
|
592 | if fullfilename: | |
588 | if self.__verifyFile(fullfilename): |
|
593 | if self.__verifyFile(fullfilename): | |
589 | fileOk_flag = True |
|
594 | fileOk_flag = True | |
590 | break |
|
595 | break | |
591 |
|
596 | |||
592 | if fileOk_flag: |
|
597 | if fileOk_flag: | |
593 | break |
|
598 | break | |
594 |
|
599 | |||
595 | firstTime_flag = False |
|
600 | firstTime_flag = False | |
596 |
|
601 | |||
597 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
602 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename | |
598 | self.set += 1 |
|
603 | self.set += 1 | |
599 |
|
604 | |||
600 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
605 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
601 | self.set = 0 |
|
606 | self.set = 0 | |
602 | self.doy += 1 |
|
607 | self.doy += 1 | |
603 | self.foldercounter = 0 |
|
608 | self.foldercounter = 0 | |
604 |
|
609 | |||
605 | if fileOk_flag: |
|
610 | if fileOk_flag: | |
606 | self.fileSize = os.path.getsize( fullfilename ) |
|
611 | self.fileSize = os.path.getsize( fullfilename ) | |
607 | self.filename = fullfilename |
|
612 | self.filename = fullfilename | |
608 | self.flagIsNewFile = 1 |
|
613 | self.flagIsNewFile = 1 | |
609 | if self.fp != None: self.fp.close() |
|
614 | if self.fp != None: self.fp.close() | |
610 | self.fp = open(fullfilename, 'rb') |
|
615 | self.fp = open(fullfilename, 'rb') | |
611 | self.flagNoMoreFiles = 0 |
|
616 | self.flagNoMoreFiles = 0 | |
612 | print 'Setting the file: %s' % fullfilename |
|
617 | print 'Setting the file: %s' % fullfilename | |
613 | else: |
|
618 | else: | |
614 | self.fileSize = 0 |
|
619 | self.fileSize = 0 | |
615 | self.filename = None |
|
620 | self.filename = None | |
616 | self.flagIsNewFile = 0 |
|
621 | self.flagIsNewFile = 0 | |
617 | self.fp = None |
|
622 | self.fp = None | |
618 | self.flagNoMoreFiles = 1 |
|
623 | self.flagNoMoreFiles = 1 | |
619 | print 'No more Files' |
|
624 | print 'No more Files' | |
620 |
|
625 | |||
621 | return fileOk_flag |
|
626 | return fileOk_flag | |
622 |
|
627 | |||
623 |
|
628 | |||
624 | def setNextFile(self): |
|
629 | def setNextFile(self): | |
625 | if self.fp != None: |
|
630 | if self.fp != None: | |
626 | self.fp.close() |
|
631 | self.fp.close() | |
627 |
|
632 | |||
628 | if self.online: |
|
633 | if self.online: | |
629 | newFile = self.__setNextFileOnline() |
|
634 | newFile = self.__setNextFileOnline() | |
630 | else: |
|
635 | else: | |
631 | newFile = self.__setNextFileOffline() |
|
636 | newFile = self.__setNextFileOffline() | |
632 |
|
637 | |||
633 | if not(newFile): |
|
638 | if not(newFile): | |
634 | return 0 |
|
639 | return 0 | |
635 |
|
640 | |||
636 | self.__readFirstHeader() |
|
641 | self.__readFirstHeader() | |
637 | self.nReadBlocks = 0 |
|
642 | self.nReadBlocks = 0 | |
638 | return 1 |
|
643 | return 1 | |
639 |
|
644 | |||
640 | def __waitNewBlock(self): |
|
645 | def __waitNewBlock(self): | |
641 | """ |
|
646 | """ | |
642 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
647 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. | |
643 |
|
648 | |||
644 | Si el modo de lectura es OffLine siempre retorn 0 |
|
649 | Si el modo de lectura es OffLine siempre retorn 0 | |
645 | """ |
|
650 | """ | |
646 | if not self.online: |
|
651 | if not self.online: | |
647 | return 0 |
|
652 | return 0 | |
648 |
|
653 | |||
649 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
654 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): | |
650 | return 0 |
|
655 | return 0 | |
651 |
|
656 | |||
652 | currentPointer = self.fp.tell() |
|
657 | currentPointer = self.fp.tell() | |
653 |
|
658 | |||
654 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
659 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
655 |
|
660 | |||
656 | for nTries in range( self.nTries ): |
|
661 | for nTries in range( self.nTries ): | |
657 |
|
662 | |||
658 | self.fp.close() |
|
663 | self.fp.close() | |
659 | self.fp = open( self.filename, 'rb' ) |
|
664 | self.fp = open( self.filename, 'rb' ) | |
660 | self.fp.seek( currentPointer ) |
|
665 | self.fp.seek( currentPointer ) | |
661 |
|
666 | |||
662 | self.fileSize = os.path.getsize( self.filename ) |
|
667 | self.fileSize = os.path.getsize( self.filename ) | |
663 | currentSize = self.fileSize - currentPointer |
|
668 | currentSize = self.fileSize - currentPointer | |
664 |
|
669 | |||
665 | if ( currentSize >= neededSize ): |
|
670 | if ( currentSize >= neededSize ): | |
666 | self.__rdBasicHeader() |
|
671 | self.__rdBasicHeader() | |
667 | return 1 |
|
672 | return 1 | |
668 |
|
673 | |||
669 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
674 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
670 | time.sleep( self.delay ) |
|
675 | time.sleep( self.delay ) | |
671 |
|
676 | |||
672 |
|
677 | |||
673 | return 0 |
|
678 | return 0 | |
674 |
|
679 | |||
675 | def __jumpToLastBlock(self): |
|
680 | def __jumpToLastBlock(self): | |
676 |
|
681 | |||
677 | if not(self.__isFirstTimeOnline): |
|
682 | if not(self.__isFirstTimeOnline): | |
678 | return |
|
683 | return | |
679 |
|
684 | |||
680 | csize = self.fileSize - self.fp.tell() |
|
685 | csize = self.fileSize - self.fp.tell() | |
681 |
|
686 | |||
682 | #sata el primer bloque de datos |
|
687 | #sata el primer bloque de datos | |
683 | if csize > self.processingHeaderObj.blockSize: |
|
688 | if csize > self.processingHeaderObj.blockSize: | |
684 | self.fp.seek(self.fp.tell() + self.processingHeaderObj.blockSize) |
|
689 | self.fp.seek(self.fp.tell() + self.processingHeaderObj.blockSize) | |
685 | else: |
|
690 | else: | |
686 | return |
|
691 | return | |
687 |
|
692 | |||
688 | csize = self.fileSize - self.fp.tell() |
|
693 | csize = self.fileSize - self.fp.tell() | |
689 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
694 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
690 | factor = int(csize/neededsize) |
|
695 | factor = int(csize/neededsize) | |
691 | if factor > 0: |
|
696 | if factor > 0: | |
692 | self.fp.seek(self.fp.tell() + factor*neededsize) |
|
697 | self.fp.seek(self.fp.tell() + factor*neededsize) | |
693 |
|
698 | |||
694 | self.flagIsNewFile = 0 |
|
699 | self.flagIsNewFile = 0 | |
695 | self.__isFirstTimeOnline = 0 |
|
700 | self.__isFirstTimeOnline = 0 | |
696 |
|
701 | |||
697 |
|
702 | |||
698 | def __setNewBlock(self): |
|
703 | def __setNewBlock(self): | |
699 |
|
704 | |||
700 | if self.fp == None: |
|
705 | if self.fp == None: | |
701 | return 0 |
|
706 | return 0 | |
702 |
|
707 | |||
703 | if self.online: |
|
708 | if self.online: | |
704 | self.__jumpToLastBlock() |
|
709 | self.__jumpToLastBlock() | |
705 |
|
710 | |||
706 | if self.flagIsNewFile: |
|
711 | if self.flagIsNewFile: | |
707 | return 1 |
|
712 | return 1 | |
708 |
|
713 | |||
709 | self.lastUTTime = self.basicHeaderObj.utc |
|
714 | self.lastUTTime = self.basicHeaderObj.utc | |
710 | currentSize = self.fileSize - self.fp.tell() |
|
715 | currentSize = self.fileSize - self.fp.tell() | |
711 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
716 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize | |
712 |
|
717 | |||
713 | if (currentSize >= neededSize): |
|
718 | if (currentSize >= neededSize): | |
714 | self.__rdBasicHeader() |
|
719 | self.__rdBasicHeader() | |
715 | return 1 |
|
720 | return 1 | |
716 |
|
721 | |||
717 | if self.__waitNewBlock(): |
|
722 | if self.__waitNewBlock(): | |
718 | return 1 |
|
723 | return 1 | |
719 |
|
724 | |||
720 | if not(self.setNextFile()): |
|
725 | if not(self.setNextFile()): | |
721 | return 0 |
|
726 | return 0 | |
722 |
|
727 | |||
723 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
728 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # | |
724 |
|
729 | |||
725 | self.flagTimeBlock = 0 |
|
730 | self.flagTimeBlock = 0 | |
726 |
|
731 | |||
727 | if deltaTime > self.maxTimeStep: |
|
732 | if deltaTime > self.maxTimeStep: | |
728 | self.flagTimeBlock = 1 |
|
733 | self.flagTimeBlock = 1 | |
729 |
|
734 | |||
730 | return 1 |
|
735 | return 1 | |
731 |
|
736 | |||
732 |
|
737 | |||
733 | def readNextBlock(self): |
|
738 | def readNextBlock(self): | |
734 | if not(self.__setNewBlock()): |
|
739 | if not(self.__setNewBlock()): | |
735 | return 0 |
|
740 | return 0 | |
736 |
|
741 | |||
737 | if not(self.readBlock()): |
|
742 | if not(self.readBlock()): | |
738 | return 0 |
|
743 | return 0 | |
739 |
|
744 | |||
740 | return 1 |
|
745 | return 1 | |
741 |
|
746 | |||
742 | def __rdProcessingHeader(self, fp=None): |
|
747 | def __rdProcessingHeader(self, fp=None): | |
743 | if fp == None: |
|
748 | if fp == None: | |
744 | fp = self.fp |
|
749 | fp = self.fp | |
745 |
|
750 | |||
746 | self.processingHeaderObj.read(fp) |
|
751 | self.processingHeaderObj.read(fp) | |
747 |
|
752 | |||
748 | def __rdRadarControllerHeader(self, fp=None): |
|
753 | def __rdRadarControllerHeader(self, fp=None): | |
749 | if fp == None: |
|
754 | if fp == None: | |
750 | fp = self.fp |
|
755 | fp = self.fp | |
751 |
|
756 | |||
752 | self.radarControllerHeaderObj.read(fp) |
|
757 | self.radarControllerHeaderObj.read(fp) | |
753 |
|
758 | |||
754 | def __rdSystemHeader(self, fp=None): |
|
759 | def __rdSystemHeader(self, fp=None): | |
755 | if fp == None: |
|
760 | if fp == None: | |
756 | fp = self.fp |
|
761 | fp = self.fp | |
757 |
|
762 | |||
758 | self.systemHeaderObj.read(fp) |
|
763 | self.systemHeaderObj.read(fp) | |
759 |
|
764 | |||
760 | def __rdBasicHeader(self, fp=None): |
|
765 | def __rdBasicHeader(self, fp=None): | |
761 | if fp == None: |
|
766 | if fp == None: | |
762 | fp = self.fp |
|
767 | fp = self.fp | |
763 |
|
768 | |||
764 | self.basicHeaderObj.read(fp) |
|
769 | self.basicHeaderObj.read(fp) | |
765 |
|
770 | |||
766 |
|
771 | |||
767 | def __readFirstHeader(self): |
|
772 | def __readFirstHeader(self): | |
768 | self.__rdBasicHeader() |
|
773 | self.__rdBasicHeader() | |
769 | self.__rdSystemHeader() |
|
774 | self.__rdSystemHeader() | |
770 | self.__rdRadarControllerHeader() |
|
775 | self.__rdRadarControllerHeader() | |
771 | self.__rdProcessingHeader() |
|
776 | self.__rdProcessingHeader() | |
772 |
|
777 | |||
773 | self.firstHeaderSize = self.basicHeaderObj.size |
|
778 | self.firstHeaderSize = self.basicHeaderObj.size | |
774 |
|
779 | |||
775 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
780 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
776 | if datatype == 0: |
|
781 | if datatype == 0: | |
777 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
782 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
778 | elif datatype == 1: |
|
783 | elif datatype == 1: | |
779 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
784 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
780 | elif datatype == 2: |
|
785 | elif datatype == 2: | |
781 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
786 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
782 | elif datatype == 3: |
|
787 | elif datatype == 3: | |
783 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
788 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
784 | elif datatype == 4: |
|
789 | elif datatype == 4: | |
785 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
790 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
786 | elif datatype == 5: |
|
791 | elif datatype == 5: | |
787 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
792 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
788 | else: |
|
793 | else: | |
789 | raise ValueError, 'Data type was not defined' |
|
794 | raise ValueError, 'Data type was not defined' | |
790 |
|
795 | |||
791 | self.dtype = datatype_str |
|
796 | self.dtype = datatype_str | |
792 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
797 | self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c | |
793 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
798 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) | |
794 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
799 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
795 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
800 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
796 | self.getBlockDimension() |
|
801 | self.getBlockDimension() | |
797 |
|
802 | |||
798 |
|
803 | |||
799 | def __verifyFile(self, filename, msgFlag=True): |
|
804 | def __verifyFile(self, filename, msgFlag=True): | |
800 | msg = None |
|
805 | msg = None | |
801 | try: |
|
806 | try: | |
802 | fp = open(filename, 'rb') |
|
807 | fp = open(filename, 'rb') | |
803 | currentPosition = fp.tell() |
|
808 | currentPosition = fp.tell() | |
804 | except: |
|
809 | except: | |
805 | if msgFlag: |
|
810 | if msgFlag: | |
806 | print "The file %s can't be opened" % (filename) |
|
811 | print "The file %s can't be opened" % (filename) | |
807 | return False |
|
812 | return False | |
808 |
|
813 | |||
809 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
814 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize | |
810 |
|
815 | |||
811 | if neededSize == 0: |
|
816 | if neededSize == 0: | |
812 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
817 | basicHeaderObj = BasicHeader(LOCALTIME) | |
813 | systemHeaderObj = SystemHeader() |
|
818 | systemHeaderObj = SystemHeader() | |
814 | radarControllerHeaderObj = RadarControllerHeader() |
|
819 | radarControllerHeaderObj = RadarControllerHeader() | |
815 | processingHeaderObj = ProcessingHeader() |
|
820 | processingHeaderObj = ProcessingHeader() | |
816 |
|
821 | |||
817 | try: |
|
822 | try: | |
818 | if not( basicHeaderObj.read(fp) ): raise IOError |
|
823 | if not( basicHeaderObj.read(fp) ): raise IOError | |
819 | if not( systemHeaderObj.read(fp) ): raise IOError |
|
824 | if not( systemHeaderObj.read(fp) ): raise IOError | |
820 | if not( radarControllerHeaderObj.read(fp) ): raise IOError |
|
825 | if not( radarControllerHeaderObj.read(fp) ): raise IOError | |
821 | if not( processingHeaderObj.read(fp) ): raise IOError |
|
826 | if not( processingHeaderObj.read(fp) ): raise IOError | |
822 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
827 | data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
823 |
|
828 | |||
824 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
829 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size | |
825 |
|
830 | |||
826 | except: |
|
831 | except: | |
827 | if msgFlag: |
|
832 | if msgFlag: | |
828 | print "\tThe file %s is empty or it hasn't enough data" % filename |
|
833 | print "\tThe file %s is empty or it hasn't enough data" % filename | |
829 |
|
834 | |||
830 | fp.close() |
|
835 | fp.close() | |
831 | return False |
|
836 | return False | |
832 | else: |
|
837 | else: | |
833 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename |
|
838 | msg = "\tSkipping the file %s due to it hasn't enough data" %filename | |
834 |
|
839 | |||
835 | fp.close() |
|
840 | fp.close() | |
836 | fileSize = os.path.getsize(filename) |
|
841 | fileSize = os.path.getsize(filename) | |
837 | currentSize = fileSize - currentPosition |
|
842 | currentSize = fileSize - currentPosition | |
838 | if currentSize < neededSize: |
|
843 | if currentSize < neededSize: | |
839 | if msgFlag and (msg != None): |
|
844 | if msgFlag and (msg != None): | |
840 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
845 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename | |
841 | return False |
|
846 | return False | |
842 |
|
847 | |||
843 | return True |
|
848 | return True | |
844 |
|
849 | |||
845 | def setup(self, |
|
850 | def setup(self, | |
846 | path=None, |
|
851 | path=None, | |
847 | startDate=None, |
|
852 | startDate=None, | |
848 | endDate=None, |
|
853 | endDate=None, | |
849 | startTime=datetime.time(0,0,0), |
|
854 | startTime=datetime.time(0,0,0), | |
850 | endTime=datetime.time(23,59,59), |
|
855 | endTime=datetime.time(23,59,59), | |
851 | set=0, |
|
856 | set=0, | |
852 | expLabel = "", |
|
857 | expLabel = "", | |
853 | ext = None, |
|
858 | ext = None, | |
854 | online = False, |
|
859 | online = False, | |
855 | delay = 60, |
|
860 | delay = 60, | |
856 | walk = True): |
|
861 | walk = True): | |
857 |
|
862 | |||
858 | if path == None: |
|
863 | if path == None: | |
859 | raise ValueError, "The path is not valid" |
|
864 | raise ValueError, "The path is not valid" | |
860 |
|
865 | |||
861 | if ext == None: |
|
866 | if ext == None: | |
862 | ext = self.ext |
|
867 | ext = self.ext | |
863 |
|
868 | |||
864 | if online: |
|
869 | if online: | |
865 | print "Searching files in online mode..." |
|
870 | print "Searching files in online mode..." | |
866 |
|
871 | |||
867 | for nTries in range( self.nTries ): |
|
872 | for nTries in range( self.nTries ): | |
868 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk) |
|
873 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk) | |
869 |
|
874 | |||
870 | if fullpath: |
|
875 | if fullpath: | |
871 | break |
|
876 | break | |
872 |
|
877 | |||
873 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) |
|
878 | print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
874 | time.sleep( self.delay ) |
|
879 | time.sleep( self.delay ) | |
875 |
|
880 | |||
876 | if not(fullpath): |
|
881 | if not(fullpath): | |
877 | print "There 'isn't valied files in %s" % path |
|
882 | print "There 'isn't valied files in %s" % path | |
878 | return None |
|
883 | return None | |
879 |
|
884 | |||
880 | self.year = year |
|
885 | self.year = year | |
881 | self.doy = doy |
|
886 | self.doy = doy | |
882 | self.set = set - 1 |
|
887 | self.set = set - 1 | |
883 | self.path = path |
|
888 | self.path = path | |
884 | self.foldercounter = foldercounter |
|
889 | self.foldercounter = foldercounter | |
885 |
|
890 | |||
886 | else: |
|
891 | else: | |
887 | print "Searching files in offline mode ..." |
|
892 | print "Searching files in offline mode ..." | |
888 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
893 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, | |
889 | startTime=startTime, endTime=endTime, |
|
894 | startTime=startTime, endTime=endTime, | |
890 | set=set, expLabel=expLabel, ext=ext, |
|
895 | set=set, expLabel=expLabel, ext=ext, | |
891 | walk=walk) |
|
896 | walk=walk) | |
892 |
|
897 | |||
893 | if not(pathList): |
|
898 | if not(pathList): | |
894 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
899 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
895 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
900 | datetime.datetime.combine(startDate,startTime).ctime(), | |
896 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
901 | datetime.datetime.combine(endDate,endTime).ctime()) | |
897 |
|
902 | |||
898 | sys.exit(-1) |
|
903 | sys.exit(-1) | |
899 |
|
904 | |||
900 |
|
905 | |||
901 | self.fileIndex = -1 |
|
906 | self.fileIndex = -1 | |
902 | self.pathList = pathList |
|
907 | self.pathList = pathList | |
903 | self.filenameList = filenameList |
|
908 | self.filenameList = filenameList | |
904 |
|
909 | |||
905 | self.online = online |
|
910 | self.online = online | |
906 | self.delay = delay |
|
911 | self.delay = delay | |
907 | ext = ext.lower() |
|
912 | ext = ext.lower() | |
908 | self.ext = ext |
|
913 | self.ext = ext | |
909 |
|
914 | |||
910 | if not(self.setNextFile()): |
|
915 | if not(self.setNextFile()): | |
911 | if (startDate!=None) and (endDate!=None): |
|
916 | if (startDate!=None) and (endDate!=None): | |
912 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
917 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
913 | elif startDate != None: |
|
918 | elif startDate != None: | |
914 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
919 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
915 | else: |
|
920 | else: | |
916 | print "No files" |
|
921 | print "No files" | |
917 |
|
922 | |||
918 | sys.exit(-1) |
|
923 | sys.exit(-1) | |
919 |
|
924 | |||
920 | # self.updateDataHeader() |
|
925 | # self.updateDataHeader() | |
921 |
|
926 | |||
922 | return self.dataOut |
|
927 | return self.dataOut | |
923 |
|
928 | |||
|
929 | def getBasicHeader(self): | |||
|
930 | ||||
|
931 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds | |||
|
932 | ||||
|
933 | self.dataOut.flagTimeBlock = self.flagTimeBlock | |||
|
934 | ||||
|
935 | self.dataOut.timeZone = self.basicHeaderObj.timeZone | |||
|
936 | ||||
|
937 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag | |||
|
938 | ||||
|
939 | self.dataOut.errorCount = self.basicHeaderObj.errorCount | |||
|
940 | ||||
|
941 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime | |||
|
942 | ||||
|
943 | def getFirstHeader(self): | |||
|
944 | ||||
|
945 | raise ValueError, "This method has not been implemented" | |||
|
946 | ||||
924 | def getData(): |
|
947 | def getData(): | |
925 |
|
948 | |||
926 | raise ValueError, "This method has not been implemented" |
|
949 | raise ValueError, "This method has not been implemented" | |
927 |
|
950 | |||
928 | def hasNotDataInBuffer(): |
|
951 | def hasNotDataInBuffer(): | |
929 |
|
952 | |||
930 | raise ValueError, "This method has not been implemented" |
|
953 | raise ValueError, "This method has not been implemented" | |
931 |
|
954 | |||
932 | def readBlock(): |
|
955 | def readBlock(): | |
933 |
|
956 | |||
934 | raise ValueError, "This method has not been implemented" |
|
957 | raise ValueError, "This method has not been implemented" | |
935 |
|
958 | |||
936 | def isEndProcess(self): |
|
959 | def isEndProcess(self): | |
937 |
|
960 | |||
938 | return self.flagNoMoreFiles |
|
961 | return self.flagNoMoreFiles | |
939 |
|
962 | |||
940 | def printReadBlocks(self): |
|
963 | def printReadBlocks(self): | |
941 |
|
964 | |||
942 | print "Number of read blocks per file %04d" %self.nReadBlocks |
|
965 | print "Number of read blocks per file %04d" %self.nReadBlocks | |
943 |
|
966 | |||
944 | def printTotalBlocks(self): |
|
967 | def printTotalBlocks(self): | |
945 |
|
968 | |||
946 | print "Number of read blocks %04d" %self.nTotalBlocks |
|
969 | print "Number of read blocks %04d" %self.nTotalBlocks | |
947 |
|
970 | |||
948 | def printNumberOfBlock(self): |
|
971 | def printNumberOfBlock(self): | |
949 |
|
972 | |||
950 | if self.flagIsNewBlock: |
|
973 | if self.flagIsNewBlock: | |
951 | print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) |
|
974 | print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) | |
952 |
|
975 | |||
953 | def printInfo(self): |
|
976 | def printInfo(self): | |
954 |
|
977 | |||
955 | if self.__printInfo == False: |
|
978 | if self.__printInfo == False: | |
956 | return |
|
979 | return | |
957 |
|
980 | |||
958 | self.basicHeaderObj.printInfo() |
|
981 | self.basicHeaderObj.printInfo() | |
959 | self.systemHeaderObj.printInfo() |
|
982 | self.systemHeaderObj.printInfo() | |
960 | self.radarControllerHeaderObj.printInfo() |
|
983 | self.radarControllerHeaderObj.printInfo() | |
961 | self.processingHeaderObj.printInfo() |
|
984 | self.processingHeaderObj.printInfo() | |
962 |
|
985 | |||
963 | self.__printInfo = False |
|
986 | self.__printInfo = False | |
964 |
|
987 | |||
965 |
|
988 | |||
966 | def run(self, **kwargs): |
|
989 | def run(self, **kwargs): | |
967 |
|
990 | |||
968 | if not(self.isConfig): |
|
991 | if not(self.isConfig): | |
969 |
|
992 | |||
970 | # self.dataOut = dataOut |
|
993 | # self.dataOut = dataOut | |
971 | self.setup(**kwargs) |
|
994 | self.setup(**kwargs) | |
972 | self.isConfig = True |
|
995 | self.isConfig = True | |
973 |
|
996 | |||
974 | self.getData() |
|
997 | self.getData() | |
975 |
|
998 | |||
976 | class JRODataWriter(JRODataIO, Operation): |
|
999 | class JRODataWriter(JRODataIO, Operation): | |
977 |
|
1000 | |||
978 | """ |
|
1001 | """ | |
979 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
1002 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura | |
980 | de los datos siempre se realiza por bloques. |
|
1003 | de los datos siempre se realiza por bloques. | |
981 | """ |
|
1004 | """ | |
982 |
|
1005 | |||
983 | blockIndex = 0 |
|
1006 | blockIndex = 0 | |
984 |
|
1007 | |||
985 | path = None |
|
1008 | path = None | |
986 |
|
1009 | |||
987 | setFile = None |
|
1010 | setFile = None | |
988 |
|
1011 | |||
989 | profilesPerBlock = None |
|
1012 | profilesPerBlock = None | |
990 |
|
1013 | |||
991 | blocksPerFile = None |
|
1014 | blocksPerFile = None | |
992 |
|
1015 | |||
993 | nWriteBlocks = 0 |
|
1016 | nWriteBlocks = 0 | |
994 |
|
1017 | |||
995 | def __init__(self, dataOut=None): |
|
1018 | def __init__(self, dataOut=None): | |
996 | raise ValueError, "Not implemented" |
|
1019 | raise ValueError, "Not implemented" | |
997 |
|
1020 | |||
998 |
|
1021 | |||
999 | def hasAllDataInBuffer(self): |
|
1022 | def hasAllDataInBuffer(self): | |
1000 | raise ValueError, "Not implemented" |
|
1023 | raise ValueError, "Not implemented" | |
1001 |
|
1024 | |||
1002 |
|
1025 | |||
1003 | def setBlockDimension(self): |
|
1026 | def setBlockDimension(self): | |
1004 | raise ValueError, "Not implemented" |
|
1027 | raise ValueError, "Not implemented" | |
1005 |
|
1028 | |||
1006 |
|
1029 | |||
1007 | def writeBlock(self): |
|
1030 | def writeBlock(self): | |
1008 | raise ValueError, "No implemented" |
|
1031 | raise ValueError, "No implemented" | |
1009 |
|
1032 | |||
1010 |
|
1033 | |||
1011 | def putData(self): |
|
1034 | def putData(self): | |
1012 | raise ValueError, "No implemented" |
|
1035 | raise ValueError, "No implemented" | |
1013 |
|
1036 | |||
1014 | def getDataHeader(self): |
|
1037 | ||
|
1038 | def setBasicHeader(self): | |||
|
1039 | ||||
|
1040 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |||
|
1041 | self.basicHeaderObj.version = self.versionFile | |||
|
1042 | self.basicHeaderObj.dataBlock = self.nTotalBlocks | |||
|
1043 | ||||
|
1044 | utc = numpy.floor(self.dataOut.utctime) | |||
|
1045 | milisecond = (self.dataOut.utctime - utc)* 1000.0 | |||
|
1046 | ||||
|
1047 | self.basicHeaderObj.utc = utc | |||
|
1048 | self.basicHeaderObj.miliSecond = milisecond | |||
|
1049 | self.basicHeaderObj.timeZone = self.dataOut.timeZone | |||
|
1050 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag | |||
|
1051 | self.basicHeaderObj.errorCount = self.dataOut.errorCount | |||
|
1052 | ||||
|
1053 | def setFirstHeader(self): | |||
1015 | """ |
|
1054 | """ | |
1016 | Obtiene una copia del First Header |
|
1055 | Obtiene una copia del First Header | |
1017 |
|
1056 | |||
1018 | Affected: |
|
1057 | Affected: | |
1019 |
|
1058 | |||
1020 | self.basicHeaderObj |
|
1059 | self.basicHeaderObj | |
1021 | self.systemHeaderObj |
|
1060 | self.systemHeaderObj | |
1022 | self.radarControllerHeaderObj |
|
1061 | self.radarControllerHeaderObj | |
1023 | self.processingHeaderObj self. |
|
1062 | self.processingHeaderObj self. | |
1024 |
|
1063 | |||
1025 | Return: |
|
1064 | Return: | |
1026 | None |
|
1065 | None | |
1027 | """ |
|
1066 | """ | |
1028 |
|
1067 | |||
1029 | raise ValueError, "No implemented" |
|
1068 | raise ValueError, "No implemented" | |
1030 |
|
1069 | |||
1031 | def getBasicHeader(self): |
|
|||
1032 |
|
||||
1033 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
|||
1034 | self.basicHeaderObj.version = self.versionFile |
|
|||
1035 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
|||
1036 |
|
||||
1037 | utc = numpy.floor(self.dataOut.utctime) |
|
|||
1038 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
|||
1039 |
|
||||
1040 | self.basicHeaderObj.utc = utc |
|
|||
1041 | self.basicHeaderObj.miliSecond = milisecond |
|
|||
1042 | self.basicHeaderObj.timeZone = 0 |
|
|||
1043 | self.basicHeaderObj.dstFlag = 0 |
|
|||
1044 | self.basicHeaderObj.errorCount = 0 |
|
|||
1045 |
|
||||
1046 | def __writeFirstHeader(self): |
|
1070 | def __writeFirstHeader(self): | |
1047 | """ |
|
1071 | """ | |
1048 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
1072 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) | |
1049 |
|
1073 | |||
1050 | Affected: |
|
1074 | Affected: | |
1051 | __dataType |
|
1075 | __dataType | |
1052 |
|
1076 | |||
1053 | Return: |
|
1077 | Return: | |
1054 | None |
|
1078 | None | |
1055 | """ |
|
1079 | """ | |
1056 |
|
1080 | |||
1057 | # CALCULAR PARAMETROS |
|
1081 | # CALCULAR PARAMETROS | |
1058 |
|
1082 | |||
1059 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
1083 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
1060 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
1084 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader | |
1061 |
|
1085 | |||
1062 | self.basicHeaderObj.write(self.fp) |
|
1086 | self.basicHeaderObj.write(self.fp) | |
1063 | self.systemHeaderObj.write(self.fp) |
|
1087 | self.systemHeaderObj.write(self.fp) | |
1064 | self.radarControllerHeaderObj.write(self.fp) |
|
1088 | self.radarControllerHeaderObj.write(self.fp) | |
1065 | self.processingHeaderObj.write(self.fp) |
|
1089 | self.processingHeaderObj.write(self.fp) | |
1066 |
|
1090 | |||
1067 | self.dtype = self.dataOut.dtype |
|
1091 | self.dtype = self.dataOut.dtype | |
1068 |
|
1092 | |||
1069 | def __setNewBlock(self): |
|
1093 | def __setNewBlock(self): | |
1070 | """ |
|
1094 | """ | |
1071 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
1095 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header | |
1072 |
|
1096 | |||
1073 | Return: |
|
1097 | Return: | |
1074 | 0 : si no pudo escribir nada |
|
1098 | 0 : si no pudo escribir nada | |
1075 | 1 : Si escribio el Basic el First Header |
|
1099 | 1 : Si escribio el Basic el First Header | |
1076 | """ |
|
1100 | """ | |
1077 | if self.fp == None: |
|
1101 | if self.fp == None: | |
1078 | self.setNextFile() |
|
1102 | self.setNextFile() | |
1079 |
|
1103 | |||
1080 | if self.flagIsNewFile: |
|
1104 | if self.flagIsNewFile: | |
1081 | return 1 |
|
1105 | return 1 | |
1082 |
|
1106 | |||
1083 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
1107 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: | |
1084 | self.basicHeaderObj.write(self.fp) |
|
1108 | self.basicHeaderObj.write(self.fp) | |
1085 | return 1 |
|
1109 | return 1 | |
1086 |
|
1110 | |||
1087 | if not( self.setNextFile() ): |
|
1111 | if not( self.setNextFile() ): | |
1088 | return 0 |
|
1112 | return 0 | |
1089 |
|
1113 | |||
1090 | return 1 |
|
1114 | return 1 | |
1091 |
|
1115 | |||
1092 |
|
1116 | |||
1093 | def writeNextBlock(self): |
|
1117 | def writeNextBlock(self): | |
1094 | """ |
|
1118 | """ | |
1095 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1119 | Selecciona el bloque siguiente de datos y los escribe en un file | |
1096 |
|
1120 | |||
1097 | Return: |
|
1121 | Return: | |
1098 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1122 | 0 : Si no hizo pudo escribir el bloque de datos | |
1099 | 1 : Si no pudo escribir el bloque de datos |
|
1123 | 1 : Si no pudo escribir el bloque de datos | |
1100 | """ |
|
1124 | """ | |
1101 | if not( self.__setNewBlock() ): |
|
1125 | if not( self.__setNewBlock() ): | |
1102 | return 0 |
|
1126 | return 0 | |
1103 |
|
1127 | |||
1104 | self.writeBlock() |
|
1128 | self.writeBlock() | |
1105 |
|
1129 | |||
1106 | return 1 |
|
1130 | return 1 | |
1107 |
|
1131 | |||
1108 | def setNextFile(self): |
|
1132 | def setNextFile(self): | |
1109 | """ |
|
1133 | """ | |
1110 | Determina el siguiente file que sera escrito |
|
1134 | Determina el siguiente file que sera escrito | |
1111 |
|
1135 | |||
1112 | Affected: |
|
1136 | Affected: | |
1113 | self.filename |
|
1137 | self.filename | |
1114 | self.subfolder |
|
1138 | self.subfolder | |
1115 | self.fp |
|
1139 | self.fp | |
1116 | self.setFile |
|
1140 | self.setFile | |
1117 | self.flagIsNewFile |
|
1141 | self.flagIsNewFile | |
1118 |
|
1142 | |||
1119 | Return: |
|
1143 | Return: | |
1120 | 0 : Si el archivo no puede ser escrito |
|
1144 | 0 : Si el archivo no puede ser escrito | |
1121 | 1 : Si el archivo esta listo para ser escrito |
|
1145 | 1 : Si el archivo esta listo para ser escrito | |
1122 | """ |
|
1146 | """ | |
1123 | ext = self.ext |
|
1147 | ext = self.ext | |
1124 | path = self.path |
|
1148 | path = self.path | |
1125 |
|
1149 | |||
1126 | if self.fp != None: |
|
1150 | if self.fp != None: | |
1127 | self.fp.close() |
|
1151 | self.fp.close() | |
1128 |
|
1152 | |||
1129 | timeTuple = time.localtime( self.dataOut.utctime) |
|
1153 | timeTuple = time.localtime( self.dataOut.utctime) | |
1130 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1154 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
1131 |
|
1155 | |||
1132 | fullpath = os.path.join( path, subfolder ) |
|
1156 | fullpath = os.path.join( path, subfolder ) | |
1133 | if not( os.path.exists(fullpath) ): |
|
1157 | if not( os.path.exists(fullpath) ): | |
1134 | os.mkdir(fullpath) |
|
1158 | os.mkdir(fullpath) | |
1135 | self.setFile = -1 #inicializo mi contador de seteo |
|
1159 | self.setFile = -1 #inicializo mi contador de seteo | |
1136 | else: |
|
1160 | else: | |
1137 | filesList = os.listdir( fullpath ) |
|
1161 | filesList = os.listdir( fullpath ) | |
1138 | if len( filesList ) > 0: |
|
1162 | if len( filesList ) > 0: | |
1139 | filesList = sorted( filesList, key=str.lower ) |
|
1163 | filesList = sorted( filesList, key=str.lower ) | |
1140 | filen = filesList[-1] |
|
1164 | filen = filesList[-1] | |
1141 | # el filename debera tener el siguiente formato |
|
1165 | # el filename debera tener el siguiente formato | |
1142 | # 0 1234 567 89A BCDE (hex) |
|
1166 | # 0 1234 567 89A BCDE (hex) | |
1143 | # x YYYY DDD SSS .ext |
|
1167 | # x YYYY DDD SSS .ext | |
1144 | if isNumber( filen[8:11] ): |
|
1168 | if isNumber( filen[8:11] ): | |
1145 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
1169 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file | |
1146 | else: |
|
1170 | else: | |
1147 | self.setFile = -1 |
|
1171 | self.setFile = -1 | |
1148 | else: |
|
1172 | else: | |
1149 | self.setFile = -1 #inicializo mi contador de seteo |
|
1173 | self.setFile = -1 #inicializo mi contador de seteo | |
1150 |
|
1174 | |||
1151 | setFile = self.setFile |
|
1175 | setFile = self.setFile | |
1152 | setFile += 1 |
|
1176 | setFile += 1 | |
1153 |
|
1177 | |||
1154 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
1178 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
1155 | timeTuple.tm_year, |
|
1179 | timeTuple.tm_year, | |
1156 | timeTuple.tm_yday, |
|
1180 | timeTuple.tm_yday, | |
1157 | setFile, |
|
1181 | setFile, | |
1158 | ext ) |
|
1182 | ext ) | |
1159 |
|
1183 | |||
1160 | filename = os.path.join( path, subfolder, file ) |
|
1184 | filename = os.path.join( path, subfolder, file ) | |
1161 |
|
1185 | |||
1162 | fp = open( filename,'wb' ) |
|
1186 | fp = open( filename,'wb' ) | |
1163 |
|
1187 | |||
1164 | self.blockIndex = 0 |
|
1188 | self.blockIndex = 0 | |
1165 |
|
1189 | |||
1166 | #guardando atributos |
|
1190 | #guardando atributos | |
1167 | self.filename = filename |
|
1191 | self.filename = filename | |
1168 | self.subfolder = subfolder |
|
1192 | self.subfolder = subfolder | |
1169 | self.fp = fp |
|
1193 | self.fp = fp | |
1170 | self.setFile = setFile |
|
1194 | self.setFile = setFile | |
1171 | self.flagIsNewFile = 1 |
|
1195 | self.flagIsNewFile = 1 | |
1172 |
|
1196 | |||
1173 |
self. |
|
1197 | self.setFirstHeader() | |
1174 |
|
1198 | |||
1175 | print 'Writing the file: %s'%self.filename |
|
1199 | print 'Writing the file: %s'%self.filename | |
1176 |
|
1200 | |||
1177 | self.__writeFirstHeader() |
|
1201 | self.__writeFirstHeader() | |
1178 |
|
1202 | |||
1179 | return 1 |
|
1203 | return 1 | |
1180 |
|
1204 | |||
1181 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): |
|
1205 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=None, set=0, ext=None): | |
1182 | """ |
|
1206 | """ | |
1183 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1207 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header | |
1184 |
|
1208 | |||
1185 | Inputs: |
|
1209 | Inputs: | |
1186 | path : el path destino en el cual se escribiran los files a crear |
|
1210 | path : el path destino en el cual se escribiran los files a crear | |
1187 | format : formato en el cual sera salvado un file |
|
1211 | format : formato en el cual sera salvado un file | |
1188 | set : el setebo del file |
|
1212 | set : el setebo del file | |
1189 |
|
1213 | |||
1190 | Return: |
|
1214 | Return: | |
1191 | 0 : Si no realizo un buen seteo |
|
1215 | 0 : Si no realizo un buen seteo | |
1192 | 1 : Si realizo un buen seteo |
|
1216 | 1 : Si realizo un buen seteo | |
1193 | """ |
|
1217 | """ | |
1194 |
|
1218 | |||
1195 | if ext == None: |
|
1219 | if ext == None: | |
1196 | ext = self.ext |
|
1220 | ext = self.ext | |
1197 |
|
1221 | |||
1198 | ext = ext.lower() |
|
1222 | ext = ext.lower() | |
1199 |
|
1223 | |||
1200 | self.ext = ext |
|
1224 | self.ext = ext | |
1201 |
|
1225 | |||
1202 | self.path = path |
|
1226 | self.path = path | |
1203 |
|
1227 | |||
1204 | self.setFile = set - 1 |
|
1228 | self.setFile = set - 1 | |
1205 |
|
1229 | |||
1206 | self.blocksPerFile = blocksPerFile |
|
1230 | self.blocksPerFile = blocksPerFile | |
1207 |
|
1231 | |||
1208 | self.profilesPerBlock = profilesPerBlock |
|
1232 | self.profilesPerBlock = profilesPerBlock | |
1209 |
|
1233 | |||
1210 | self.dataOut = dataOut |
|
1234 | self.dataOut = dataOut | |
1211 |
|
1235 | |||
1212 | if not(self.setNextFile()): |
|
1236 | if not(self.setNextFile()): | |
1213 | print "There isn't a next file" |
|
1237 | print "There isn't a next file" | |
1214 | return 0 |
|
1238 | return 0 | |
1215 |
|
1239 | |||
1216 | self.setBlockDimension() |
|
1240 | self.setBlockDimension() | |
1217 |
|
1241 | |||
1218 | return 1 |
|
1242 | return 1 | |
1219 |
|
1243 | |||
1220 | def run(self, dataOut, **kwargs): |
|
1244 | def run(self, dataOut, **kwargs): | |
1221 |
|
1245 | |||
1222 | if not(self.isConfig): |
|
1246 | if not(self.isConfig): | |
1223 |
|
1247 | |||
1224 | self.setup(dataOut, **kwargs) |
|
1248 | self.setup(dataOut, **kwargs) | |
1225 | self.isConfig = True |
|
1249 | self.isConfig = True | |
1226 |
|
1250 | |||
1227 | self.putData() |
|
1251 | self.putData() | |
1228 |
|
1252 | |||
1229 | class VoltageReader(JRODataReader): |
|
1253 | class VoltageReader(JRODataReader): | |
1230 | """ |
|
1254 | """ | |
1231 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
1255 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura | |
1232 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
1256 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: | |
1233 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
1257 | perfiles*alturas*canales) son almacenados en la variable "buffer". | |
1234 |
|
1258 | |||
1235 | perfiles * alturas * canales |
|
1259 | perfiles * alturas * canales | |
1236 |
|
1260 | |||
1237 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1261 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1238 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
1262 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la | |
1239 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
1263 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de | |
1240 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1264 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1241 |
|
1265 | |||
1242 | Example: |
|
1266 | Example: | |
1243 |
|
1267 | |||
1244 | dpath = "/home/myuser/data" |
|
1268 | dpath = "/home/myuser/data" | |
1245 |
|
1269 | |||
1246 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1270 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1247 |
|
1271 | |||
1248 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1272 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1249 |
|
1273 | |||
1250 | readerObj = VoltageReader() |
|
1274 | readerObj = VoltageReader() | |
1251 |
|
1275 | |||
1252 | readerObj.setup(dpath, startTime, endTime) |
|
1276 | readerObj.setup(dpath, startTime, endTime) | |
1253 |
|
1277 | |||
1254 | while(True): |
|
1278 | while(True): | |
1255 |
|
1279 | |||
1256 | #to get one profile |
|
1280 | #to get one profile | |
1257 | profile = readerObj.getData() |
|
1281 | profile = readerObj.getData() | |
1258 |
|
1282 | |||
1259 | #print the profile |
|
1283 | #print the profile | |
1260 | print profile |
|
1284 | print profile | |
1261 |
|
1285 | |||
1262 | #If you want to see all datablock |
|
1286 | #If you want to see all datablock | |
1263 | print readerObj.datablock |
|
1287 | print readerObj.datablock | |
1264 |
|
1288 | |||
1265 | if readerObj.flagNoMoreFiles: |
|
1289 | if readerObj.flagNoMoreFiles: | |
1266 | break |
|
1290 | break | |
1267 |
|
1291 | |||
1268 | """ |
|
1292 | """ | |
1269 |
|
1293 | |||
1270 | ext = ".r" |
|
1294 | ext = ".r" | |
1271 |
|
1295 | |||
1272 | optchar = "D" |
|
1296 | optchar = "D" | |
1273 | dataOut = None |
|
1297 | dataOut = None | |
1274 |
|
1298 | |||
1275 |
|
1299 | |||
1276 | def __init__(self): |
|
1300 | def __init__(self): | |
1277 | """ |
|
1301 | """ | |
1278 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
1302 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. | |
1279 |
|
1303 | |||
1280 | Input: |
|
1304 | Input: | |
1281 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
1305 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para | |
1282 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1306 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1283 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1307 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1284 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1308 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1285 | bloque de datos. |
|
1309 | bloque de datos. | |
1286 | Si este parametro no es pasado se creara uno internamente. |
|
1310 | Si este parametro no es pasado se creara uno internamente. | |
1287 |
|
1311 | |||
1288 | Variables afectadas: |
|
1312 | Variables afectadas: | |
1289 | self.dataOut |
|
1313 | self.dataOut | |
1290 |
|
1314 | |||
1291 | Return: |
|
1315 | Return: | |
1292 | None |
|
1316 | None | |
1293 | """ |
|
1317 | """ | |
1294 |
|
1318 | |||
1295 | self.isConfig = False |
|
1319 | self.isConfig = False | |
1296 |
|
1320 | |||
1297 | self.datablock = None |
|
1321 | self.datablock = None | |
1298 |
|
1322 | |||
1299 | self.utc = 0 |
|
1323 | self.utc = 0 | |
1300 |
|
1324 | |||
1301 | self.ext = ".r" |
|
1325 | self.ext = ".r" | |
1302 |
|
1326 | |||
1303 | self.optchar = "D" |
|
1327 | self.optchar = "D" | |
1304 |
|
1328 | |||
1305 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1329 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1306 |
|
1330 | |||
1307 | self.systemHeaderObj = SystemHeader() |
|
1331 | self.systemHeaderObj = SystemHeader() | |
1308 |
|
1332 | |||
1309 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1333 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1310 |
|
1334 | |||
1311 | self.processingHeaderObj = ProcessingHeader() |
|
1335 | self.processingHeaderObj = ProcessingHeader() | |
1312 |
|
1336 | |||
1313 | self.online = 0 |
|
1337 | self.online = 0 | |
1314 |
|
1338 | |||
1315 | self.fp = None |
|
1339 | self.fp = None | |
1316 |
|
1340 | |||
1317 | self.idFile = None |
|
1341 | self.idFile = None | |
1318 |
|
1342 | |||
1319 | self.dtype = None |
|
1343 | self.dtype = None | |
1320 |
|
1344 | |||
1321 | self.fileSizeByHeader = None |
|
1345 | self.fileSizeByHeader = None | |
1322 |
|
1346 | |||
1323 | self.filenameList = [] |
|
1347 | self.filenameList = [] | |
1324 |
|
1348 | |||
1325 | self.filename = None |
|
1349 | self.filename = None | |
1326 |
|
1350 | |||
1327 | self.fileSize = None |
|
1351 | self.fileSize = None | |
1328 |
|
1352 | |||
1329 | self.firstHeaderSize = 0 |
|
1353 | self.firstHeaderSize = 0 | |
1330 |
|
1354 | |||
1331 | self.basicHeaderSize = 24 |
|
1355 | self.basicHeaderSize = 24 | |
1332 |
|
1356 | |||
1333 | self.pathList = [] |
|
1357 | self.pathList = [] | |
1334 |
|
1358 | |||
1335 | self.filenameList = [] |
|
1359 | self.filenameList = [] | |
1336 |
|
1360 | |||
1337 | self.lastUTTime = 0 |
|
1361 | self.lastUTTime = 0 | |
1338 |
|
1362 | |||
1339 | self.maxTimeStep = 30 |
|
1363 | self.maxTimeStep = 30 | |
1340 |
|
1364 | |||
1341 | self.flagNoMoreFiles = 0 |
|
1365 | self.flagNoMoreFiles = 0 | |
1342 |
|
1366 | |||
1343 | self.set = 0 |
|
1367 | self.set = 0 | |
1344 |
|
1368 | |||
1345 | self.path = None |
|
1369 | self.path = None | |
1346 |
|
1370 | |||
1347 | self.profileIndex = 2**32-1 |
|
1371 | self.profileIndex = 2**32-1 | |
1348 |
|
1372 | |||
1349 | self.delay = 3 #seconds |
|
1373 | self.delay = 3 #seconds | |
1350 |
|
1374 | |||
1351 | self.nTries = 3 #quantity tries |
|
1375 | self.nTries = 3 #quantity tries | |
1352 |
|
1376 | |||
1353 | self.nFiles = 3 #number of files for searching |
|
1377 | self.nFiles = 3 #number of files for searching | |
1354 |
|
1378 | |||
1355 | self.nReadBlocks = 0 |
|
1379 | self.nReadBlocks = 0 | |
1356 |
|
1380 | |||
1357 | self.flagIsNewFile = 1 |
|
1381 | self.flagIsNewFile = 1 | |
1358 |
|
1382 | |||
1359 | self.__isFirstTimeOnline = 1 |
|
1383 | self.__isFirstTimeOnline = 1 | |
1360 |
|
1384 | |||
1361 | self.ippSeconds = 0 |
|
1385 | self.ippSeconds = 0 | |
1362 |
|
1386 | |||
1363 | self.flagTimeBlock = 0 |
|
1387 | self.flagTimeBlock = 0 | |
1364 |
|
1388 | |||
1365 | self.flagIsNewBlock = 0 |
|
1389 | self.flagIsNewBlock = 0 | |
1366 |
|
1390 | |||
1367 | self.nTotalBlocks = 0 |
|
1391 | self.nTotalBlocks = 0 | |
1368 |
|
1392 | |||
1369 | self.blocksize = 0 |
|
1393 | self.blocksize = 0 | |
1370 |
|
1394 | |||
1371 | self.dataOut = self.createObjByDefault() |
|
1395 | self.dataOut = self.createObjByDefault() | |
1372 |
|
1396 | |||
1373 | def createObjByDefault(self): |
|
1397 | def createObjByDefault(self): | |
1374 |
|
1398 | |||
1375 | dataObj = Voltage() |
|
1399 | dataObj = Voltage() | |
1376 |
|
1400 | |||
1377 | return dataObj |
|
1401 | return dataObj | |
1378 |
|
1402 | |||
1379 | def __hasNotDataInBuffer(self): |
|
1403 | def __hasNotDataInBuffer(self): | |
1380 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1404 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1381 | return 1 |
|
1405 | return 1 | |
1382 | return 0 |
|
1406 | return 0 | |
1383 |
|
1407 | |||
1384 |
|
1408 | |||
1385 | def getBlockDimension(self): |
|
1409 | def getBlockDimension(self): | |
1386 | """ |
|
1410 | """ | |
1387 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1411 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1388 |
|
1412 | |||
1389 | Affected: |
|
1413 | Affected: | |
1390 | self.blocksize |
|
1414 | self.blocksize | |
1391 |
|
1415 | |||
1392 | Return: |
|
1416 | Return: | |
1393 | None |
|
1417 | None | |
1394 | """ |
|
1418 | """ | |
1395 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
1419 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
1396 | self.blocksize = pts2read |
|
1420 | self.blocksize = pts2read | |
1397 |
|
1421 | |||
1398 |
|
1422 | |||
1399 | def readBlock(self): |
|
1423 | def readBlock(self): | |
1400 | """ |
|
1424 | """ | |
1401 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
1425 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo | |
1402 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
1426 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
1403 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
1427 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
1404 | es seteado a 0 |
|
1428 | es seteado a 0 | |
1405 |
|
1429 | |||
1406 | Inputs: |
|
1430 | Inputs: | |
1407 | None |
|
1431 | None | |
1408 |
|
1432 | |||
1409 | Return: |
|
1433 | Return: | |
1410 | None |
|
1434 | None | |
1411 |
|
1435 | |||
1412 | Affected: |
|
1436 | Affected: | |
1413 | self.profileIndex |
|
1437 | self.profileIndex | |
1414 | self.datablock |
|
1438 | self.datablock | |
1415 | self.flagIsNewFile |
|
1439 | self.flagIsNewFile | |
1416 | self.flagIsNewBlock |
|
1440 | self.flagIsNewBlock | |
1417 | self.nTotalBlocks |
|
1441 | self.nTotalBlocks | |
1418 |
|
1442 | |||
1419 | Exceptions: |
|
1443 | Exceptions: | |
1420 | Si un bloque leido no es un bloque valido |
|
1444 | Si un bloque leido no es un bloque valido | |
1421 | """ |
|
1445 | """ | |
1422 |
|
1446 | |||
1423 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
1447 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) | |
1424 |
|
1448 | |||
1425 | try: |
|
1449 | try: | |
1426 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
1450 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
1427 | except: |
|
1451 | except: | |
1428 | print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
1452 | print "The read block (%3d) has not enough data" %self.nReadBlocks | |
1429 | return 0 |
|
1453 | return 0 | |
1430 |
|
1454 | |||
1431 | junk = numpy.transpose(junk, (2,0,1)) |
|
1455 | junk = numpy.transpose(junk, (2,0,1)) | |
1432 | self.datablock = junk['real'] + junk['imag']*1j |
|
1456 | self.datablock = junk['real'] + junk['imag']*1j | |
1433 |
|
1457 | |||
1434 | self.profileIndex = 0 |
|
1458 | self.profileIndex = 0 | |
1435 |
|
1459 | |||
1436 | self.flagIsNewFile = 0 |
|
1460 | self.flagIsNewFile = 0 | |
1437 | self.flagIsNewBlock = 1 |
|
1461 | self.flagIsNewBlock = 1 | |
1438 |
|
1462 | |||
1439 | self.nTotalBlocks += 1 |
|
1463 | self.nTotalBlocks += 1 | |
1440 | self.nReadBlocks += 1 |
|
1464 | self.nReadBlocks += 1 | |
1441 |
|
1465 | |||
1442 | return 1 |
|
1466 | return 1 | |
1443 |
|
1467 | |||
|
1468 | def getFirstHeader(self): | |||
|
1469 | ||||
|
1470 | self.dataOut.dtype = self.dtype | |||
|
1471 | ||||
|
1472 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |||
|
1473 | ||||
|
1474 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |||
|
1475 | ||||
|
1476 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |||
|
1477 | ||||
|
1478 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |||
|
1479 | ||||
|
1480 | self.dataOut.ippSeconds = self.ippSeconds | |||
|
1481 | ||||
|
1482 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt | |||
|
1483 | ||||
|
1484 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |||
|
1485 | ||||
|
1486 | self.dataOut.flagShiftFFT = False | |||
|
1487 | ||||
|
1488 | if self.radarControllerHeaderObj.code != None: | |||
|
1489 | ||||
|
1490 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |||
|
1491 | ||||
|
1492 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |||
|
1493 | ||||
|
1494 | self.dataOut.code = self.radarControllerHeaderObj.code | |||
|
1495 | ||||
|
1496 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |||
|
1497 | ||||
|
1498 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |||
|
1499 | ||||
|
1500 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |||
|
1501 | ||||
|
1502 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip | |||
|
1503 | ||||
|
1504 | self.dataOut.flagShiftFFT = False | |||
1444 |
|
1505 | |||
1445 | def getData(self): |
|
1506 | def getData(self): | |
1446 | """ |
|
1507 | """ | |
1447 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" |
|
1508 | getData obtiene una unidad de datos del buffer de lectura y la copia a la clase "Voltage" | |
1448 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
1509 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
1449 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
1510 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
1450 |
|
1511 | |||
1451 | Ademas incrementa el contador del buffer en 1. |
|
1512 | Ademas incrementa el contador del buffer en 1. | |
1452 |
|
1513 | |||
1453 | Return: |
|
1514 | Return: | |
1454 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
1515 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
1455 | buffer. Si no hay mas archivos a leer retorna None. |
|
1516 | buffer. Si no hay mas archivos a leer retorna None. | |
1456 |
|
1517 | |||
1457 | Variables afectadas: |
|
1518 | Variables afectadas: | |
1458 | self.dataOut |
|
1519 | self.dataOut | |
1459 | self.profileIndex |
|
1520 | self.profileIndex | |
1460 |
|
1521 | |||
1461 | Affected: |
|
1522 | Affected: | |
1462 | self.dataOut |
|
1523 | self.dataOut | |
1463 | self.profileIndex |
|
1524 | self.profileIndex | |
1464 | self.flagTimeBlock |
|
1525 | self.flagTimeBlock | |
1465 | self.flagIsNewBlock |
|
1526 | self.flagIsNewBlock | |
1466 | """ |
|
1527 | """ | |
1467 |
|
1528 | |||
1468 | if self.flagNoMoreFiles: |
|
1529 | if self.flagNoMoreFiles: | |
1469 | self.dataOut.flagNoData = True |
|
1530 | self.dataOut.flagNoData = True | |
1470 | print 'Process finished' |
|
1531 | print 'Process finished' | |
1471 | return 0 |
|
1532 | return 0 | |
1472 |
|
1533 | |||
1473 | self.flagTimeBlock = 0 |
|
1534 | self.flagTimeBlock = 0 | |
1474 | self.flagIsNewBlock = 0 |
|
1535 | self.flagIsNewBlock = 0 | |
1475 |
|
1536 | |||
1476 | if self.__hasNotDataInBuffer(): |
|
1537 | if self.__hasNotDataInBuffer(): | |
1477 |
|
1538 | |||
1478 | if not( self.readNextBlock() ): |
|
1539 | if not( self.readNextBlock() ): | |
1479 | return 0 |
|
1540 | return 0 | |
1480 |
|
1541 | |||
1481 | self.dataOut.dtype = self.dtype |
|
1542 | self.getFirstHeader() | |
1482 |
|
||||
1483 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
|||
1484 |
|
||||
1485 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
|||
1486 |
|
||||
1487 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
|||
1488 |
|
||||
1489 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
|||
1490 |
|
||||
1491 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
|||
1492 |
|
||||
1493 | self.dataOut.ippSeconds = self.ippSeconds |
|
|||
1494 |
|
||||
1495 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt |
|
|||
1496 |
|
||||
1497 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
|||
1498 |
|
||||
1499 | self.dataOut.flagShiftFFT = False |
|
|||
1500 |
|
||||
1501 | if self.radarControllerHeaderObj.code != None: |
|
|||
1502 |
|
||||
1503 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode |
|
|||
1504 |
|
||||
1505 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud |
|
|||
1506 |
|
||||
1507 | self.dataOut.code = self.radarControllerHeaderObj.code |
|
|||
1508 |
|
||||
1509 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
|||
1510 |
|
||||
1511 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
|||
1512 |
|
||||
1513 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
|||
1514 |
|
||||
1515 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip |
|
|||
1516 |
|
||||
1517 | self.dataOut.flagShiftFFT = False |
|
|||
1518 |
|
||||
1519 |
|
||||
1520 | # self.updateDataHeader() |
|
|||
1521 |
|
||||
1522 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
|||
1523 |
|
1543 | |||
1524 | if self.datablock == None: |
|
1544 | if self.datablock == None: | |
1525 | self.dataOut.flagNoData = True |
|
1545 | self.dataOut.flagNoData = True | |
1526 | return 0 |
|
1546 | return 0 | |
1527 |
|
1547 | |||
1528 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
1548 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
1529 |
|
1549 | |||
1530 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.ippSeconds |
|
|||
1531 |
|
||||
1532 | self.profileIndex += 1 |
|
|||
1533 |
|
||||
1534 | self.dataOut.flagNoData = False |
|
1550 | self.dataOut.flagNoData = False | |
1535 |
|
1551 | |||
1536 | # print self.profileIndex, self.dataOut.utctime |
|
1552 | self.getBasicHeader() | |
1537 | # if self.profileIndex == 800: |
|
|||
1538 | # a=1 |
|
|||
1539 |
|
1553 | |||
|
1554 | self.profileIndex += 1 | |||
1540 |
|
1555 | |||
1541 | return self.dataOut.data |
|
1556 | return self.dataOut.data | |
1542 |
|
1557 | |||
1543 |
|
1558 | |||
1544 | class VoltageWriter(JRODataWriter): |
|
1559 | class VoltageWriter(JRODataWriter): | |
1545 | """ |
|
1560 | """ | |
1546 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
1561 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura | |
1547 | de los datos siempre se realiza por bloques. |
|
1562 | de los datos siempre se realiza por bloques. | |
1548 | """ |
|
1563 | """ | |
1549 |
|
1564 | |||
1550 | ext = ".r" |
|
1565 | ext = ".r" | |
1551 |
|
1566 | |||
1552 | optchar = "D" |
|
1567 | optchar = "D" | |
1553 |
|
1568 | |||
1554 | shapeBuffer = None |
|
1569 | shapeBuffer = None | |
1555 |
|
1570 | |||
1556 |
|
1571 | |||
1557 | def __init__(self): |
|
1572 | def __init__(self): | |
1558 | """ |
|
1573 | """ | |
1559 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
1574 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. | |
1560 |
|
1575 | |||
1561 | Affected: |
|
1576 | Affected: | |
1562 | self.dataOut |
|
1577 | self.dataOut | |
1563 |
|
1578 | |||
1564 | Return: None |
|
1579 | Return: None | |
1565 | """ |
|
1580 | """ | |
1566 |
|
1581 | |||
1567 | self.nTotalBlocks = 0 |
|
1582 | self.nTotalBlocks = 0 | |
1568 |
|
1583 | |||
1569 | self.profileIndex = 0 |
|
1584 | self.profileIndex = 0 | |
1570 |
|
1585 | |||
1571 | self.isConfig = False |
|
1586 | self.isConfig = False | |
1572 |
|
1587 | |||
1573 | self.fp = None |
|
1588 | self.fp = None | |
1574 |
|
1589 | |||
1575 | self.flagIsNewFile = 1 |
|
1590 | self.flagIsNewFile = 1 | |
1576 |
|
1591 | |||
1577 | self.nTotalBlocks = 0 |
|
1592 | self.nTotalBlocks = 0 | |
1578 |
|
1593 | |||
1579 | self.flagIsNewBlock = 0 |
|
1594 | self.flagIsNewBlock = 0 | |
1580 |
|
1595 | |||
1581 | self.setFile = None |
|
1596 | self.setFile = None | |
1582 |
|
1597 | |||
1583 | self.dtype = None |
|
1598 | self.dtype = None | |
1584 |
|
1599 | |||
1585 | self.path = None |
|
1600 | self.path = None | |
1586 |
|
1601 | |||
1587 | self.filename = None |
|
1602 | self.filename = None | |
1588 |
|
1603 | |||
1589 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1604 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1590 |
|
1605 | |||
1591 | self.systemHeaderObj = SystemHeader() |
|
1606 | self.systemHeaderObj = SystemHeader() | |
1592 |
|
1607 | |||
1593 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1608 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1594 |
|
1609 | |||
1595 | self.processingHeaderObj = ProcessingHeader() |
|
1610 | self.processingHeaderObj = ProcessingHeader() | |
1596 |
|
1611 | |||
1597 | def hasAllDataInBuffer(self): |
|
1612 | def hasAllDataInBuffer(self): | |
1598 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
1613 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: | |
1599 | return 1 |
|
1614 | return 1 | |
1600 | return 0 |
|
1615 | return 0 | |
1601 |
|
1616 | |||
1602 |
|
1617 | |||
1603 | def setBlockDimension(self): |
|
1618 | def setBlockDimension(self): | |
1604 | """ |
|
1619 | """ | |
1605 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
1620 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
1606 |
|
1621 | |||
1607 | Affected: |
|
1622 | Affected: | |
1608 | self.shape_spc_Buffer |
|
1623 | self.shape_spc_Buffer | |
1609 | self.shape_cspc_Buffer |
|
1624 | self.shape_cspc_Buffer | |
1610 | self.shape_dc_Buffer |
|
1625 | self.shape_dc_Buffer | |
1611 |
|
1626 | |||
1612 | Return: None |
|
1627 | Return: None | |
1613 | """ |
|
1628 | """ | |
1614 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
1629 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, | |
1615 | self.processingHeaderObj.nHeights, |
|
1630 | self.processingHeaderObj.nHeights, | |
1616 | self.systemHeaderObj.nChannels) |
|
1631 | self.systemHeaderObj.nChannels) | |
1617 |
|
1632 | |||
1618 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
1633 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, | |
1619 | self.processingHeaderObj.profilesPerBlock, |
|
1634 | self.processingHeaderObj.profilesPerBlock, | |
1620 | self.processingHeaderObj.nHeights), |
|
1635 | self.processingHeaderObj.nHeights), | |
1621 | dtype=numpy.dtype('complex64')) |
|
1636 | dtype=numpy.dtype('complex64')) | |
1622 |
|
1637 | |||
1623 |
|
1638 | |||
1624 | def writeBlock(self): |
|
1639 | def writeBlock(self): | |
1625 | """ |
|
1640 | """ | |
1626 | Escribe el buffer en el file designado |
|
1641 | Escribe el buffer en el file designado | |
1627 |
|
1642 | |||
1628 | Affected: |
|
1643 | Affected: | |
1629 | self.profileIndex |
|
1644 | self.profileIndex | |
1630 | self.flagIsNewFile |
|
1645 | self.flagIsNewFile | |
1631 | self.flagIsNewBlock |
|
1646 | self.flagIsNewBlock | |
1632 | self.nTotalBlocks |
|
1647 | self.nTotalBlocks | |
1633 | self.blockIndex |
|
1648 | self.blockIndex | |
1634 |
|
1649 | |||
1635 | Return: None |
|
1650 | Return: None | |
1636 | """ |
|
1651 | """ | |
1637 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
1652 | data = numpy.zeros( self.shapeBuffer, self.dtype ) | |
1638 |
|
1653 | |||
1639 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
1654 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
1640 |
|
1655 | |||
1641 | data['real'] = junk.real |
|
1656 | data['real'] = junk.real | |
1642 | data['imag'] = junk.imag |
|
1657 | data['imag'] = junk.imag | |
1643 |
|
1658 | |||
1644 | data = data.reshape( (-1) ) |
|
1659 | data = data.reshape( (-1) ) | |
1645 |
|
1660 | |||
1646 | data.tofile( self.fp ) |
|
1661 | data.tofile( self.fp ) | |
1647 |
|
1662 | |||
1648 | self.datablock.fill(0) |
|
1663 | self.datablock.fill(0) | |
1649 |
|
1664 | |||
1650 | self.profileIndex = 0 |
|
1665 | self.profileIndex = 0 | |
1651 | self.flagIsNewFile = 0 |
|
1666 | self.flagIsNewFile = 0 | |
1652 | self.flagIsNewBlock = 1 |
|
1667 | self.flagIsNewBlock = 1 | |
1653 |
|
1668 | |||
1654 | self.blockIndex += 1 |
|
1669 | self.blockIndex += 1 | |
1655 | self.nTotalBlocks += 1 |
|
1670 | self.nTotalBlocks += 1 | |
1656 |
|
1671 | |||
1657 | def putData(self): |
|
1672 | def putData(self): | |
1658 | """ |
|
1673 | """ | |
1659 | Setea un bloque de datos y luego los escribe en un file |
|
1674 | Setea un bloque de datos y luego los escribe en un file | |
1660 |
|
1675 | |||
1661 | Affected: |
|
1676 | Affected: | |
1662 | self.flagIsNewBlock |
|
1677 | self.flagIsNewBlock | |
1663 | self.profileIndex |
|
1678 | self.profileIndex | |
1664 |
|
1679 | |||
1665 | Return: |
|
1680 | Return: | |
1666 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
1681 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
1667 | 1 : Si se escribio la data de un bloque en un file |
|
1682 | 1 : Si se escribio la data de un bloque en un file | |
1668 | """ |
|
1683 | """ | |
1669 | if self.dataOut.flagNoData: |
|
1684 | if self.dataOut.flagNoData: | |
1670 | return 0 |
|
1685 | return 0 | |
1671 |
|
1686 | |||
1672 | self.flagIsNewBlock = 0 |
|
1687 | self.flagIsNewBlock = 0 | |
1673 |
|
1688 | |||
1674 | if self.dataOut.flagTimeBlock: |
|
1689 | if self.dataOut.flagTimeBlock: | |
1675 |
|
1690 | |||
1676 | self.datablock.fill(0) |
|
1691 | self.datablock.fill(0) | |
1677 | self.profileIndex = 0 |
|
1692 | self.profileIndex = 0 | |
1678 | self.setNextFile() |
|
1693 | self.setNextFile() | |
1679 |
|
1694 | |||
1680 | if self.profileIndex == 0: |
|
1695 | if self.profileIndex == 0: | |
1681 |
self. |
|
1696 | self.setBasicHeader() | |
1682 |
|
1697 | |||
1683 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
1698 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
1684 |
|
1699 | |||
1685 | self.profileIndex += 1 |
|
1700 | self.profileIndex += 1 | |
1686 |
|
1701 | |||
1687 | if self.hasAllDataInBuffer(): |
|
1702 | if self.hasAllDataInBuffer(): | |
1688 | #if self.flagIsNewFile: |
|
1703 | #if self.flagIsNewFile: | |
1689 | self.writeNextBlock() |
|
1704 | self.writeNextBlock() | |
1690 |
# self. |
|
1705 | # self.setFirstHeader() | |
1691 |
|
1706 | |||
1692 | return 1 |
|
1707 | return 1 | |
1693 |
|
1708 | |||
1694 | def __getProcessFlags(self): |
|
1709 | def __getProcessFlags(self): | |
1695 |
|
1710 | |||
1696 | processFlags = 0 |
|
1711 | processFlags = 0 | |
1697 |
|
1712 | |||
1698 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1713 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1699 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1714 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1700 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1715 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1701 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1716 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1702 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1717 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1703 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1718 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1704 |
|
1719 | |||
1705 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1720 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1706 |
|
1721 | |||
1707 |
|
1722 | |||
1708 |
|
1723 | |||
1709 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
1724 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
1710 | PROCFLAG.DATATYPE_SHORT, |
|
1725 | PROCFLAG.DATATYPE_SHORT, | |
1711 | PROCFLAG.DATATYPE_LONG, |
|
1726 | PROCFLAG.DATATYPE_LONG, | |
1712 | PROCFLAG.DATATYPE_INT64, |
|
1727 | PROCFLAG.DATATYPE_INT64, | |
1713 | PROCFLAG.DATATYPE_FLOAT, |
|
1728 | PROCFLAG.DATATYPE_FLOAT, | |
1714 | PROCFLAG.DATATYPE_DOUBLE] |
|
1729 | PROCFLAG.DATATYPE_DOUBLE] | |
1715 |
|
1730 | |||
1716 |
|
1731 | |||
1717 | for index in range(len(dtypeList)): |
|
1732 | for index in range(len(dtypeList)): | |
1718 | if self.dataOut.dtype == dtypeList[index]: |
|
1733 | if self.dataOut.dtype == dtypeList[index]: | |
1719 | dtypeValue = datatypeValueList[index] |
|
1734 | dtypeValue = datatypeValueList[index] | |
1720 | break |
|
1735 | break | |
1721 |
|
1736 | |||
1722 | processFlags += dtypeValue |
|
1737 | processFlags += dtypeValue | |
1723 |
|
1738 | |||
1724 | if self.dataOut.flagDecodeData: |
|
1739 | if self.dataOut.flagDecodeData: | |
1725 | processFlags += PROCFLAG.DECODE_DATA |
|
1740 | processFlags += PROCFLAG.DECODE_DATA | |
1726 |
|
1741 | |||
1727 | if self.dataOut.flagDeflipData: |
|
1742 | if self.dataOut.flagDeflipData: | |
1728 | processFlags += PROCFLAG.DEFLIP_DATA |
|
1743 | processFlags += PROCFLAG.DEFLIP_DATA | |
1729 |
|
1744 | |||
1730 | if self.dataOut.code != None: |
|
1745 | if self.dataOut.code != None: | |
1731 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
1746 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
1732 |
|
1747 | |||
1733 | if self.dataOut.nCohInt > 1: |
|
1748 | if self.dataOut.nCohInt > 1: | |
1734 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
1749 | processFlags += PROCFLAG.COHERENT_INTEGRATION | |
1735 |
|
1750 | |||
1736 | return processFlags |
|
1751 | return processFlags | |
1737 |
|
1752 | |||
1738 |
|
1753 | |||
1739 | def __getBlockSize(self): |
|
1754 | def __getBlockSize(self): | |
1740 | ''' |
|
1755 | ''' | |
1741 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
1756 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage | |
1742 | ''' |
|
1757 | ''' | |
1743 |
|
1758 | |||
1744 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
1759 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
1745 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
1760 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
1746 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
1761 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
1747 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
1762 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
1748 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1763 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1749 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
1764 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
1750 |
|
1765 | |||
1751 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
1766 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
1752 | datatypeValueList = [1,2,4,8,4,8] |
|
1767 | datatypeValueList = [1,2,4,8,4,8] | |
1753 | for index in range(len(dtypeList)): |
|
1768 | for index in range(len(dtypeList)): | |
1754 | if self.dataOut.dtype == dtypeList[index]: |
|
1769 | if self.dataOut.dtype == dtypeList[index]: | |
1755 | datatypeValue = datatypeValueList[index] |
|
1770 | datatypeValue = datatypeValueList[index] | |
1756 | break |
|
1771 | break | |
1757 |
|
1772 | |||
1758 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) |
|
1773 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.dataOut.nProfiles * datatypeValue * 2) | |
1759 |
|
1774 | |||
1760 | return blocksize |
|
1775 | return blocksize | |
1761 |
|
1776 | |||
1762 |
def |
|
1777 | def setFirstHeader(self): | |
1763 |
|
1778 | |||
1764 | """ |
|
1779 | """ | |
1765 | Obtiene una copia del First Header |
|
1780 | Obtiene una copia del First Header | |
1766 |
|
1781 | |||
1767 | Affected: |
|
1782 | Affected: | |
1768 | self.systemHeaderObj |
|
1783 | self.systemHeaderObj | |
1769 | self.radarControllerHeaderObj |
|
1784 | self.radarControllerHeaderObj | |
1770 | self.dtype |
|
1785 | self.dtype | |
1771 |
|
1786 | |||
1772 | Return: |
|
1787 | Return: | |
1773 | None |
|
1788 | None | |
1774 | """ |
|
1789 | """ | |
1775 |
|
1790 | |||
1776 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
1791 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
1777 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
1792 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
1778 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
1793 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
1779 |
|
1794 | |||
1780 |
self. |
|
1795 | self.setBasicHeader() | |
1781 |
|
1796 | |||
1782 | processingHeaderSize = 40 # bytes |
|
1797 | processingHeaderSize = 40 # bytes | |
1783 | self.processingHeaderObj.dtype = 0 # Voltage |
|
1798 | self.processingHeaderObj.dtype = 0 # Voltage | |
1784 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
1799 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
1785 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
1800 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock | |
1786 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
1801 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
1787 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
1802 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
1788 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
1803 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
1789 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
1804 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt | |
1790 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
1805 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage | |
1791 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
1806 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
1792 |
|
1807 | |||
1793 | if self.dataOut.code != None: |
|
1808 | if self.dataOut.code != None: | |
1794 | self.processingHeaderObj.code = self.dataOut.code |
|
1809 | self.processingHeaderObj.code = self.dataOut.code | |
1795 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
1810 | self.processingHeaderObj.nCode = self.dataOut.nCode | |
1796 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
1811 | self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
1797 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
1812 | codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) | |
1798 | processingHeaderSize += codesize |
|
1813 | processingHeaderSize += codesize | |
1799 |
|
1814 | |||
1800 | if self.processingHeaderObj.nWindows != 0: |
|
1815 | if self.processingHeaderObj.nWindows != 0: | |
1801 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
1816 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
1802 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
1817 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
1803 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
1818 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
1804 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
1819 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
1805 | processingHeaderSize += 12 |
|
1820 | processingHeaderSize += 12 | |
1806 |
|
1821 | |||
1807 | self.processingHeaderObj.size = processingHeaderSize |
|
1822 | self.processingHeaderObj.size = processingHeaderSize | |
1808 |
|
1823 | |||
1809 | class SpectraReader(JRODataReader): |
|
1824 | class SpectraReader(JRODataReader): | |
1810 | """ |
|
1825 | """ | |
1811 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
1826 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura | |
1812 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
1827 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) | |
1813 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
1828 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. | |
1814 |
|
1829 | |||
1815 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
1830 | paresCanalesIguales * alturas * perfiles (Self Spectra) | |
1816 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
1831 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) | |
1817 | canales * alturas (DC Channels) |
|
1832 | canales * alturas (DC Channels) | |
1818 |
|
1833 | |||
1819 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
1834 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, | |
1820 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
1835 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la | |
1821 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
1836 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de | |
1822 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
1837 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". | |
1823 |
|
1838 | |||
1824 | Example: |
|
1839 | Example: | |
1825 | dpath = "/home/myuser/data" |
|
1840 | dpath = "/home/myuser/data" | |
1826 |
|
1841 | |||
1827 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
1842 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) | |
1828 |
|
1843 | |||
1829 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
1844 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) | |
1830 |
|
1845 | |||
1831 | readerObj = SpectraReader() |
|
1846 | readerObj = SpectraReader() | |
1832 |
|
1847 | |||
1833 | readerObj.setup(dpath, startTime, endTime) |
|
1848 | readerObj.setup(dpath, startTime, endTime) | |
1834 |
|
1849 | |||
1835 | while(True): |
|
1850 | while(True): | |
1836 |
|
1851 | |||
1837 | readerObj.getData() |
|
1852 | readerObj.getData() | |
1838 |
|
1853 | |||
1839 | print readerObj.data_spc |
|
1854 | print readerObj.data_spc | |
1840 |
|
1855 | |||
1841 | print readerObj.data_cspc |
|
1856 | print readerObj.data_cspc | |
1842 |
|
1857 | |||
1843 | print readerObj.data_dc |
|
1858 | print readerObj.data_dc | |
1844 |
|
1859 | |||
1845 | if readerObj.flagNoMoreFiles: |
|
1860 | if readerObj.flagNoMoreFiles: | |
1846 | break |
|
1861 | break | |
1847 |
|
1862 | |||
1848 | """ |
|
1863 | """ | |
1849 |
|
1864 | |||
1850 | pts2read_SelfSpectra = 0 |
|
1865 | pts2read_SelfSpectra = 0 | |
1851 |
|
1866 | |||
1852 | pts2read_CrossSpectra = 0 |
|
1867 | pts2read_CrossSpectra = 0 | |
1853 |
|
1868 | |||
1854 | pts2read_DCchannels = 0 |
|
1869 | pts2read_DCchannels = 0 | |
1855 |
|
1870 | |||
1856 | ext = ".pdata" |
|
1871 | ext = ".pdata" | |
1857 |
|
1872 | |||
1858 | optchar = "P" |
|
1873 | optchar = "P" | |
1859 |
|
1874 | |||
1860 | dataOut = None |
|
1875 | dataOut = None | |
1861 |
|
1876 | |||
1862 | nRdChannels = None |
|
1877 | nRdChannels = None | |
1863 |
|
1878 | |||
1864 | nRdPairs = None |
|
1879 | nRdPairs = None | |
1865 |
|
1880 | |||
1866 | rdPairList = [] |
|
1881 | rdPairList = [] | |
1867 |
|
||||
1868 |
|
1882 | |||
1869 | def __init__(self): |
|
1883 | def __init__(self): | |
1870 | """ |
|
1884 | """ | |
1871 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
1885 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. | |
1872 |
|
1886 | |||
1873 | Inputs: |
|
1887 | Inputs: | |
1874 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
1888 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para | |
1875 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
1889 | almacenar un perfil de datos cada vez que se haga un requerimiento | |
1876 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
1890 | (getData). El perfil sera obtenido a partir del buffer de datos, | |
1877 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
1891 | si el buffer esta vacio se hara un nuevo proceso de lectura de un | |
1878 | bloque de datos. |
|
1892 | bloque de datos. | |
1879 | Si este parametro no es pasado se creara uno internamente. |
|
1893 | Si este parametro no es pasado se creara uno internamente. | |
1880 |
|
1894 | |||
1881 | Affected: |
|
1895 | Affected: | |
1882 | self.dataOut |
|
1896 | self.dataOut | |
1883 |
|
1897 | |||
1884 | Return : None |
|
1898 | Return : None | |
1885 | """ |
|
1899 | """ | |
1886 |
|
1900 | |||
1887 | self.isConfig = False |
|
1901 | self.isConfig = False | |
1888 |
|
1902 | |||
1889 | self.pts2read_SelfSpectra = 0 |
|
1903 | self.pts2read_SelfSpectra = 0 | |
1890 |
|
1904 | |||
1891 | self.pts2read_CrossSpectra = 0 |
|
1905 | self.pts2read_CrossSpectra = 0 | |
1892 |
|
1906 | |||
1893 | self.pts2read_DCchannels = 0 |
|
1907 | self.pts2read_DCchannels = 0 | |
1894 |
|
1908 | |||
1895 | self.datablock = None |
|
1909 | self.datablock = None | |
1896 |
|
1910 | |||
1897 | self.utc = None |
|
1911 | self.utc = None | |
1898 |
|
1912 | |||
1899 | self.ext = ".pdata" |
|
1913 | self.ext = ".pdata" | |
1900 |
|
1914 | |||
1901 | self.optchar = "P" |
|
1915 | self.optchar = "P" | |
1902 |
|
1916 | |||
1903 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
1917 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
1904 |
|
1918 | |||
1905 | self.systemHeaderObj = SystemHeader() |
|
1919 | self.systemHeaderObj = SystemHeader() | |
1906 |
|
1920 | |||
1907 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1921 | self.radarControllerHeaderObj = RadarControllerHeader() | |
1908 |
|
1922 | |||
1909 | self.processingHeaderObj = ProcessingHeader() |
|
1923 | self.processingHeaderObj = ProcessingHeader() | |
1910 |
|
1924 | |||
1911 | self.online = 0 |
|
1925 | self.online = 0 | |
1912 |
|
1926 | |||
1913 | self.fp = None |
|
1927 | self.fp = None | |
1914 |
|
1928 | |||
1915 | self.idFile = None |
|
1929 | self.idFile = None | |
1916 |
|
1930 | |||
1917 | self.dtype = None |
|
1931 | self.dtype = None | |
1918 |
|
1932 | |||
1919 | self.fileSizeByHeader = None |
|
1933 | self.fileSizeByHeader = None | |
1920 |
|
1934 | |||
1921 | self.filenameList = [] |
|
1935 | self.filenameList = [] | |
1922 |
|
1936 | |||
1923 | self.filename = None |
|
1937 | self.filename = None | |
1924 |
|
1938 | |||
1925 | self.fileSize = None |
|
1939 | self.fileSize = None | |
1926 |
|
1940 | |||
1927 | self.firstHeaderSize = 0 |
|
1941 | self.firstHeaderSize = 0 | |
1928 |
|
1942 | |||
1929 | self.basicHeaderSize = 24 |
|
1943 | self.basicHeaderSize = 24 | |
1930 |
|
1944 | |||
1931 | self.pathList = [] |
|
1945 | self.pathList = [] | |
1932 |
|
1946 | |||
1933 | self.lastUTTime = 0 |
|
1947 | self.lastUTTime = 0 | |
1934 |
|
1948 | |||
1935 | self.maxTimeStep = 30 |
|
1949 | self.maxTimeStep = 30 | |
1936 |
|
1950 | |||
1937 | self.flagNoMoreFiles = 0 |
|
1951 | self.flagNoMoreFiles = 0 | |
1938 |
|
1952 | |||
1939 | self.set = 0 |
|
1953 | self.set = 0 | |
1940 |
|
1954 | |||
1941 | self.path = None |
|
1955 | self.path = None | |
1942 |
|
1956 | |||
1943 | self.delay = 60 #seconds |
|
1957 | self.delay = 60 #seconds | |
1944 |
|
1958 | |||
1945 | self.nTries = 3 #quantity tries |
|
1959 | self.nTries = 3 #quantity tries | |
1946 |
|
1960 | |||
1947 | self.nFiles = 3 #number of files for searching |
|
1961 | self.nFiles = 3 #number of files for searching | |
1948 |
|
1962 | |||
1949 | self.nReadBlocks = 0 |
|
1963 | self.nReadBlocks = 0 | |
1950 |
|
1964 | |||
1951 | self.flagIsNewFile = 1 |
|
1965 | self.flagIsNewFile = 1 | |
1952 |
|
1966 | |||
1953 | self.__isFirstTimeOnline = 1 |
|
1967 | self.__isFirstTimeOnline = 1 | |
1954 |
|
1968 | |||
1955 | self.ippSeconds = 0 |
|
1969 | self.ippSeconds = 0 | |
1956 |
|
1970 | |||
1957 | self.flagTimeBlock = 0 |
|
1971 | self.flagTimeBlock = 0 | |
1958 |
|
1972 | |||
1959 | self.flagIsNewBlock = 0 |
|
1973 | self.flagIsNewBlock = 0 | |
1960 |
|
1974 | |||
1961 | self.nTotalBlocks = 0 |
|
1975 | self.nTotalBlocks = 0 | |
1962 |
|
1976 | |||
1963 | self.blocksize = 0 |
|
1977 | self.blocksize = 0 | |
1964 |
|
1978 | |||
1965 | self.dataOut = self.createObjByDefault() |
|
1979 | self.dataOut = self.createObjByDefault() | |
|
1980 | ||||
|
1981 | self.profileIndex = 1 #Always | |||
1966 |
|
1982 | |||
1967 |
|
1983 | |||
1968 | def createObjByDefault(self): |
|
1984 | def createObjByDefault(self): | |
1969 |
|
1985 | |||
1970 | dataObj = Spectra() |
|
1986 | dataObj = Spectra() | |
1971 |
|
1987 | |||
1972 | return dataObj |
|
1988 | return dataObj | |
1973 |
|
1989 | |||
1974 | def __hasNotDataInBuffer(self): |
|
1990 | def __hasNotDataInBuffer(self): | |
1975 | return 1 |
|
1991 | return 1 | |
1976 |
|
1992 | |||
1977 |
|
1993 | |||
1978 | def getBlockDimension(self): |
|
1994 | def getBlockDimension(self): | |
1979 | """ |
|
1995 | """ | |
1980 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
1996 | Obtiene la cantidad de puntos a leer por cada bloque de datos | |
1981 |
|
1997 | |||
1982 | Affected: |
|
1998 | Affected: | |
1983 | self.nRdChannels |
|
1999 | self.nRdChannels | |
1984 | self.nRdPairs |
|
2000 | self.nRdPairs | |
1985 | self.pts2read_SelfSpectra |
|
2001 | self.pts2read_SelfSpectra | |
1986 | self.pts2read_CrossSpectra |
|
2002 | self.pts2read_CrossSpectra | |
1987 | self.pts2read_DCchannels |
|
2003 | self.pts2read_DCchannels | |
1988 | self.blocksize |
|
2004 | self.blocksize | |
1989 | self.dataOut.nChannels |
|
2005 | self.dataOut.nChannels | |
1990 | self.dataOut.nPairs |
|
2006 | self.dataOut.nPairs | |
1991 |
|
2007 | |||
1992 | Return: |
|
2008 | Return: | |
1993 | None |
|
2009 | None | |
1994 | """ |
|
2010 | """ | |
1995 | self.nRdChannels = 0 |
|
2011 | self.nRdChannels = 0 | |
1996 | self.nRdPairs = 0 |
|
2012 | self.nRdPairs = 0 | |
1997 | self.rdPairList = [] |
|
2013 | self.rdPairList = [] | |
1998 |
|
2014 | |||
1999 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
2015 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): | |
2000 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
2016 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: | |
2001 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
2017 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
2002 | else: |
|
2018 | else: | |
2003 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
2019 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes | |
2004 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
2020 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) | |
2005 |
|
2021 | |||
2006 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
2022 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock | |
2007 |
|
2023 | |||
2008 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
2024 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) | |
2009 | self.blocksize = self.pts2read_SelfSpectra |
|
2025 | self.blocksize = self.pts2read_SelfSpectra | |
2010 |
|
2026 | |||
2011 | if self.processingHeaderObj.flag_cspc: |
|
2027 | if self.processingHeaderObj.flag_cspc: | |
2012 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
2028 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) | |
2013 | self.blocksize += self.pts2read_CrossSpectra |
|
2029 | self.blocksize += self.pts2read_CrossSpectra | |
2014 |
|
2030 | |||
2015 | if self.processingHeaderObj.flag_dc: |
|
2031 | if self.processingHeaderObj.flag_dc: | |
2016 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
2032 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) | |
2017 | self.blocksize += self.pts2read_DCchannels |
|
2033 | self.blocksize += self.pts2read_DCchannels | |
2018 |
|
2034 | |||
2019 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
2035 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels | |
2020 |
|
2036 | |||
2021 |
|
2037 | |||
2022 | def readBlock(self): |
|
2038 | def readBlock(self): | |
2023 | """ |
|
2039 | """ | |
2024 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
2040 | Lee el bloque de datos desde la posicion actual del puntero del archivo | |
2025 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
2041 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos | |
2026 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
2042 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer | |
2027 | es seteado a 0 |
|
2043 | es seteado a 0 | |
2028 |
|
2044 | |||
2029 | Return: None |
|
2045 | Return: None | |
2030 |
|
2046 | |||
2031 | Variables afectadas: |
|
2047 | Variables afectadas: | |
2032 |
|
2048 | |||
2033 | self.flagIsNewFile |
|
2049 | self.flagIsNewFile | |
2034 | self.flagIsNewBlock |
|
2050 | self.flagIsNewBlock | |
2035 | self.nTotalBlocks |
|
2051 | self.nTotalBlocks | |
2036 | self.data_spc |
|
2052 | self.data_spc | |
2037 | self.data_cspc |
|
2053 | self.data_cspc | |
2038 | self.data_dc |
|
2054 | self.data_dc | |
2039 |
|
2055 | |||
2040 | Exceptions: |
|
2056 | Exceptions: | |
2041 | Si un bloque leido no es un bloque valido |
|
2057 | Si un bloque leido no es un bloque valido | |
2042 | """ |
|
2058 | """ | |
2043 | blockOk_flag = False |
|
2059 | blockOk_flag = False | |
2044 | fpointer = self.fp.tell() |
|
2060 | fpointer = self.fp.tell() | |
2045 |
|
2061 | |||
2046 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
2062 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) | |
2047 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
2063 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
2048 |
|
2064 | |||
2049 | if self.processingHeaderObj.flag_cspc: |
|
2065 | if self.processingHeaderObj.flag_cspc: | |
2050 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
2066 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) | |
2051 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
2067 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D | |
2052 |
|
2068 | |||
2053 | if self.processingHeaderObj.flag_dc: |
|
2069 | if self.processingHeaderObj.flag_dc: | |
2054 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
2070 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) | |
2055 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
2071 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D | |
2056 |
|
2072 | |||
2057 |
|
2073 | |||
2058 | if not(self.processingHeaderObj.shif_fft): |
|
2074 | if not(self.processingHeaderObj.shif_fft): | |
2059 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2075 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
2060 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
2076 | shift = int(self.processingHeaderObj.profilesPerBlock/2) | |
2061 | spc = numpy.roll( spc, shift , axis=2 ) |
|
2077 | spc = numpy.roll( spc, shift , axis=2 ) | |
2062 |
|
2078 | |||
2063 | if self.processingHeaderObj.flag_cspc: |
|
2079 | if self.processingHeaderObj.flag_cspc: | |
2064 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2080 | #desplaza a la derecha en el eje 2 determinadas posiciones | |
2065 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
2081 | cspc = numpy.roll( cspc, shift, axis=2 ) | |
2066 |
|
2082 | |||
2067 | # self.processingHeaderObj.shif_fft = True |
|
2083 | # self.processingHeaderObj.shif_fft = True | |
2068 |
|
2084 | |||
2069 | spc = numpy.transpose( spc, (0,2,1) ) |
|
2085 | spc = numpy.transpose( spc, (0,2,1) ) | |
2070 | self.data_spc = spc |
|
2086 | self.data_spc = spc | |
2071 |
|
2087 | |||
2072 | if self.processingHeaderObj.flag_cspc: |
|
2088 | if self.processingHeaderObj.flag_cspc: | |
2073 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
2089 | cspc = numpy.transpose( cspc, (0,2,1) ) | |
2074 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
2090 | self.data_cspc = cspc['real'] + cspc['imag']*1j | |
2075 | else: |
|
2091 | else: | |
2076 | self.data_cspc = None |
|
2092 | self.data_cspc = None | |
2077 |
|
2093 | |||
2078 | if self.processingHeaderObj.flag_dc: |
|
2094 | if self.processingHeaderObj.flag_dc: | |
2079 | self.data_dc = dc['real'] + dc['imag']*1j |
|
2095 | self.data_dc = dc['real'] + dc['imag']*1j | |
2080 | else: |
|
2096 | else: | |
2081 | self.data_dc = None |
|
2097 | self.data_dc = None | |
2082 |
|
2098 | |||
2083 | self.flagIsNewFile = 0 |
|
2099 | self.flagIsNewFile = 0 | |
2084 | self.flagIsNewBlock = 1 |
|
2100 | self.flagIsNewBlock = 1 | |
2085 |
|
2101 | |||
2086 | self.nTotalBlocks += 1 |
|
2102 | self.nTotalBlocks += 1 | |
2087 | self.nReadBlocks += 1 |
|
2103 | self.nReadBlocks += 1 | |
2088 |
|
2104 | |||
2089 | return 1 |
|
2105 | return 1 | |
2090 |
|
2106 | |||
|
2107 | def getFirstHeader(self): | |||
|
2108 | ||||
|
2109 | self.dataOut.dtype = self.dtype | |||
|
2110 | ||||
|
2111 | self.dataOut.nPairs = self.nRdPairs | |||
|
2112 | ||||
|
2113 | self.dataOut.pairsList = self.rdPairList | |||
|
2114 | ||||
|
2115 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock | |||
|
2116 | ||||
|
2117 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock | |||
|
2118 | ||||
|
2119 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt | |||
|
2120 | ||||
|
2121 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt | |||
|
2122 | ||||
|
2123 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight | |||
2091 |
|
2124 | |||
|
2125 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |||
|
2126 | ||||
|
2127 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) | |||
|
2128 | ||||
|
2129 | self.dataOut.ippSeconds = self.ippSeconds | |||
|
2130 | ||||
|
2131 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints | |||
|
2132 | ||||
|
2133 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() | |||
|
2134 | ||||
|
2135 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() | |||
|
2136 | ||||
|
2137 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft | |||
|
2138 | ||||
|
2139 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada | |||
|
2140 | ||||
|
2141 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |||
|
2142 | ||||
|
2143 | if self.processingHeaderObj.code != None: | |||
|
2144 | ||||
|
2145 | self.dataOut.nCode = self.processingHeaderObj.nCode | |||
|
2146 | ||||
|
2147 | self.dataOut.nBaud = self.processingHeaderObj.nBaud | |||
|
2148 | ||||
|
2149 | self.dataOut.code = self.processingHeaderObj.code | |||
|
2150 | ||||
|
2151 | self.dataOut.flagDecodeData = True | |||
|
2152 | ||||
2092 | def getData(self): |
|
2153 | def getData(self): | |
2093 | """ |
|
2154 | """ | |
2094 | Copia el buffer de lectura a la clase "Spectra", |
|
2155 | Copia el buffer de lectura a la clase "Spectra", | |
2095 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
2156 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de | |
2096 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
2157 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" | |
2097 |
|
2158 | |||
2098 | Return: |
|
2159 | Return: | |
2099 | 0 : Si no hay mas archivos disponibles |
|
2160 | 0 : Si no hay mas archivos disponibles | |
2100 | 1 : Si hizo una buena copia del buffer |
|
2161 | 1 : Si hizo una buena copia del buffer | |
2101 |
|
2162 | |||
2102 | Affected: |
|
2163 | Affected: | |
2103 | self.dataOut |
|
2164 | self.dataOut | |
2104 |
|
2165 | |||
2105 | self.flagTimeBlock |
|
2166 | self.flagTimeBlock | |
2106 | self.flagIsNewBlock |
|
2167 | self.flagIsNewBlock | |
2107 | """ |
|
2168 | """ | |
2108 |
|
2169 | |||
2109 | if self.flagNoMoreFiles: |
|
2170 | if self.flagNoMoreFiles: | |
2110 | self.dataOut.flagNoData = True |
|
2171 | self.dataOut.flagNoData = True | |
2111 | print 'Process finished' |
|
2172 | print 'Process finished' | |
2112 | return 0 |
|
2173 | return 0 | |
2113 |
|
2174 | |||
2114 | self.flagTimeBlock = 0 |
|
2175 | self.flagTimeBlock = 0 | |
2115 | self.flagIsNewBlock = 0 |
|
2176 | self.flagIsNewBlock = 0 | |
2116 |
|
2177 | |||
2117 | if self.__hasNotDataInBuffer(): |
|
2178 | if self.__hasNotDataInBuffer(): | |
2118 |
|
2179 | |||
2119 | if not( self.readNextBlock() ): |
|
2180 | if not( self.readNextBlock() ): | |
2120 | self.dataOut.flagNoData = True |
|
2181 | self.dataOut.flagNoData = True | |
2121 |
return 0 |
|
2182 | return 0 | |
2122 |
|
||||
2123 | # self.updateDataHeader() |
|
|||
2124 |
|
2183 | |||
2125 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
2184 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) | |
2126 |
|
2185 | |||
2127 | if self.data_dc == None: |
|
2186 | if self.data_dc == None: | |
2128 | self.dataOut.flagNoData = True |
|
2187 | self.dataOut.flagNoData = True | |
2129 | return 0 |
|
2188 | return 0 | |
|
2189 | ||||
|
2190 | self.getBasicHeader() | |||
|
2191 | ||||
|
2192 | self.getFirstHeader() | |||
2130 |
|
2193 | |||
2131 | self.dataOut.data_spc = self.data_spc |
|
2194 | self.dataOut.data_spc = self.data_spc | |
2132 |
|
2195 | |||
2133 | self.dataOut.data_cspc = self.data_cspc |
|
2196 | self.dataOut.data_cspc = self.data_cspc | |
2134 |
|
2197 | |||
2135 | self.dataOut.data_dc = self.data_dc |
|
2198 | self.dataOut.data_dc = self.data_dc | |
2136 |
|
||||
2137 | self.dataOut.flagTimeBlock = self.flagTimeBlock |
|
|||
2138 |
|
2199 | |||
2139 | self.dataOut.flagNoData = False |
|
2200 | self.dataOut.flagNoData = False | |
2140 |
|
||||
2141 | self.dataOut.dtype = self.dtype |
|
|||
2142 |
|
||||
2143 | # self.dataOut.nChannels = self.nRdChannels |
|
|||
2144 |
|
||||
2145 | self.dataOut.nPairs = self.nRdPairs |
|
|||
2146 |
|
||||
2147 | self.dataOut.pairsList = self.rdPairList |
|
|||
2148 |
|
||||
2149 | # self.dataOut.nHeights = self.processingHeaderObj.nHeights |
|
|||
2150 |
|
||||
2151 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
|||
2152 |
|
||||
2153 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
|||
2154 |
|
||||
2155 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
|||
2156 |
|
||||
2157 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
|||
2158 |
|
||||
2159 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
|||
2160 |
|
||||
2161 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
|||
2162 |
|
||||
2163 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
|||
2164 |
|
2201 | |||
2165 | # self.dataOut.channelIndexList = range(self.systemHeaderObj.nChannels) |
|
|||
2166 |
|
||||
2167 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000.#+ self.profileIndex * self.ippSeconds |
|
|||
2168 |
|
||||
2169 | self.dataOut.ippSeconds = self.ippSeconds |
|
|||
2170 |
|
||||
2171 | self.dataOut.timeInterval = self.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.dataOut.nFFTPoints |
|
|||
2172 |
|
||||
2173 | # self.profileIndex += 1 |
|
|||
2174 |
|
||||
2175 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
|||
2176 |
|
||||
2177 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
|||
2178 |
|
||||
2179 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
|||
2180 |
|
||||
2181 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
|||
2182 |
|
||||
2183 | self.dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
|||
2184 |
|
||||
2185 | if self.processingHeaderObj.code != None: |
|
|||
2186 |
|
||||
2187 | self.dataOut.nCode = self.processingHeaderObj.nCode |
|
|||
2188 |
|
||||
2189 | self.dataOut.nBaud = self.processingHeaderObj.nBaud |
|
|||
2190 |
|
||||
2191 | self.dataOut.code = self.processingHeaderObj.code |
|
|||
2192 |
|
||||
2193 | self.dataOut.flagDecodeData = True |
|
|||
2194 |
|
||||
2195 | return self.dataOut.data_spc |
|
2202 | return self.dataOut.data_spc | |
2196 |
|
2203 | |||
2197 |
|
2204 | |||
2198 | class SpectraWriter(JRODataWriter): |
|
2205 | class SpectraWriter(JRODataWriter): | |
2199 |
|
2206 | |||
2200 | """ |
|
2207 | """ | |
2201 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
2208 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura | |
2202 | de los datos siempre se realiza por bloques. |
|
2209 | de los datos siempre se realiza por bloques. | |
2203 | """ |
|
2210 | """ | |
2204 |
|
2211 | |||
2205 | ext = ".pdata" |
|
2212 | ext = ".pdata" | |
2206 |
|
2213 | |||
2207 | optchar = "P" |
|
2214 | optchar = "P" | |
2208 |
|
2215 | |||
2209 | shape_spc_Buffer = None |
|
2216 | shape_spc_Buffer = None | |
2210 |
|
2217 | |||
2211 | shape_cspc_Buffer = None |
|
2218 | shape_cspc_Buffer = None | |
2212 |
|
2219 | |||
2213 | shape_dc_Buffer = None |
|
2220 | shape_dc_Buffer = None | |
2214 |
|
2221 | |||
2215 | data_spc = None |
|
2222 | data_spc = None | |
2216 |
|
2223 | |||
2217 | data_cspc = None |
|
2224 | data_cspc = None | |
2218 |
|
2225 | |||
2219 | data_dc = None |
|
2226 | data_dc = None | |
2220 |
|
2227 | |||
2221 | # dataOut = None |
|
2228 | # dataOut = None | |
2222 |
|
2229 | |||
2223 | def __init__(self): |
|
2230 | def __init__(self): | |
2224 | """ |
|
2231 | """ | |
2225 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
2232 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. | |
2226 |
|
2233 | |||
2227 | Affected: |
|
2234 | Affected: | |
2228 | self.dataOut |
|
2235 | self.dataOut | |
2229 | self.basicHeaderObj |
|
2236 | self.basicHeaderObj | |
2230 | self.systemHeaderObj |
|
2237 | self.systemHeaderObj | |
2231 | self.radarControllerHeaderObj |
|
2238 | self.radarControllerHeaderObj | |
2232 | self.processingHeaderObj |
|
2239 | self.processingHeaderObj | |
2233 |
|
2240 | |||
2234 | Return: None |
|
2241 | Return: None | |
2235 | """ |
|
2242 | """ | |
2236 |
|
2243 | |||
2237 | self.isConfig = False |
|
2244 | self.isConfig = False | |
2238 |
|
2245 | |||
2239 | self.nTotalBlocks = 0 |
|
2246 | self.nTotalBlocks = 0 | |
2240 |
|
2247 | |||
2241 | self.data_spc = None |
|
2248 | self.data_spc = None | |
2242 |
|
2249 | |||
2243 | self.data_cspc = None |
|
2250 | self.data_cspc = None | |
2244 |
|
2251 | |||
2245 | self.data_dc = None |
|
2252 | self.data_dc = None | |
2246 |
|
2253 | |||
2247 | self.fp = None |
|
2254 | self.fp = None | |
2248 |
|
2255 | |||
2249 | self.flagIsNewFile = 1 |
|
2256 | self.flagIsNewFile = 1 | |
2250 |
|
2257 | |||
2251 | self.nTotalBlocks = 0 |
|
2258 | self.nTotalBlocks = 0 | |
2252 |
|
2259 | |||
2253 | self.flagIsNewBlock = 0 |
|
2260 | self.flagIsNewBlock = 0 | |
2254 |
|
2261 | |||
2255 | self.setFile = None |
|
2262 | self.setFile = None | |
2256 |
|
2263 | |||
2257 | self.dtype = None |
|
2264 | self.dtype = None | |
2258 |
|
2265 | |||
2259 | self.path = None |
|
2266 | self.path = None | |
2260 |
|
2267 | |||
2261 | self.noMoreFiles = 0 |
|
2268 | self.noMoreFiles = 0 | |
2262 |
|
2269 | |||
2263 | self.filename = None |
|
2270 | self.filename = None | |
2264 |
|
2271 | |||
2265 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
2272 | self.basicHeaderObj = BasicHeader(LOCALTIME) | |
2266 |
|
2273 | |||
2267 | self.systemHeaderObj = SystemHeader() |
|
2274 | self.systemHeaderObj = SystemHeader() | |
2268 |
|
2275 | |||
2269 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
2276 | self.radarControllerHeaderObj = RadarControllerHeader() | |
2270 |
|
2277 | |||
2271 | self.processingHeaderObj = ProcessingHeader() |
|
2278 | self.processingHeaderObj = ProcessingHeader() | |
2272 |
|
2279 | |||
2273 |
|
2280 | |||
2274 | def hasAllDataInBuffer(self): |
|
2281 | def hasAllDataInBuffer(self): | |
2275 | return 1 |
|
2282 | return 1 | |
2276 |
|
2283 | |||
2277 |
|
2284 | |||
2278 | def setBlockDimension(self): |
|
2285 | def setBlockDimension(self): | |
2279 | """ |
|
2286 | """ | |
2280 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
2287 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque | |
2281 |
|
2288 | |||
2282 | Affected: |
|
2289 | Affected: | |
2283 | self.shape_spc_Buffer |
|
2290 | self.shape_spc_Buffer | |
2284 | self.shape_cspc_Buffer |
|
2291 | self.shape_cspc_Buffer | |
2285 | self.shape_dc_Buffer |
|
2292 | self.shape_dc_Buffer | |
2286 |
|
2293 | |||
2287 | Return: None |
|
2294 | Return: None | |
2288 | """ |
|
2295 | """ | |
2289 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
2296 | self.shape_spc_Buffer = (self.dataOut.nChannels, | |
2290 | self.processingHeaderObj.nHeights, |
|
2297 | self.processingHeaderObj.nHeights, | |
2291 | self.processingHeaderObj.profilesPerBlock) |
|
2298 | self.processingHeaderObj.profilesPerBlock) | |
2292 |
|
2299 | |||
2293 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
2300 | self.shape_cspc_Buffer = (self.dataOut.nPairs, | |
2294 | self.processingHeaderObj.nHeights, |
|
2301 | self.processingHeaderObj.nHeights, | |
2295 | self.processingHeaderObj.profilesPerBlock) |
|
2302 | self.processingHeaderObj.profilesPerBlock) | |
2296 |
|
2303 | |||
2297 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
2304 | self.shape_dc_Buffer = (self.dataOut.nChannels, | |
2298 | self.processingHeaderObj.nHeights) |
|
2305 | self.processingHeaderObj.nHeights) | |
2299 |
|
2306 | |||
2300 |
|
2307 | |||
2301 | def writeBlock(self): |
|
2308 | def writeBlock(self): | |
2302 | """ |
|
2309 | """ | |
2303 | Escribe el buffer en el file designado |
|
2310 | Escribe el buffer en el file designado | |
2304 |
|
2311 | |||
2305 | Affected: |
|
2312 | Affected: | |
2306 | self.data_spc |
|
2313 | self.data_spc | |
2307 | self.data_cspc |
|
2314 | self.data_cspc | |
2308 | self.data_dc |
|
2315 | self.data_dc | |
2309 | self.flagIsNewFile |
|
2316 | self.flagIsNewFile | |
2310 | self.flagIsNewBlock |
|
2317 | self.flagIsNewBlock | |
2311 | self.nTotalBlocks |
|
2318 | self.nTotalBlocks | |
2312 | self.nWriteBlocks |
|
2319 | self.nWriteBlocks | |
2313 |
|
2320 | |||
2314 | Return: None |
|
2321 | Return: None | |
2315 | """ |
|
2322 | """ | |
2316 |
|
2323 | |||
2317 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
2324 | spc = numpy.transpose( self.data_spc, (0,2,1) ) | |
2318 | if not( self.processingHeaderObj.shif_fft ): |
|
2325 | if not( self.processingHeaderObj.shif_fft ): | |
2319 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2326 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2320 | data = spc.reshape((-1)) |
|
2327 | data = spc.reshape((-1)) | |
2321 | data = data.astype(self.dtype[0]) |
|
2328 | data = data.astype(self.dtype[0]) | |
2322 | data.tofile(self.fp) |
|
2329 | data.tofile(self.fp) | |
2323 |
|
2330 | |||
2324 | if self.data_cspc != None: |
|
2331 | if self.data_cspc != None: | |
2325 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
2332 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) | |
2326 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
2333 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) | |
2327 | if not( self.processingHeaderObj.shif_fft ): |
|
2334 | if not( self.processingHeaderObj.shif_fft ): | |
2328 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
2335 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones | |
2329 | data['real'] = cspc.real |
|
2336 | data['real'] = cspc.real | |
2330 | data['imag'] = cspc.imag |
|
2337 | data['imag'] = cspc.imag | |
2331 | data = data.reshape((-1)) |
|
2338 | data = data.reshape((-1)) | |
2332 | data.tofile(self.fp) |
|
2339 | data.tofile(self.fp) | |
2333 |
|
2340 | |||
2334 | if self.data_dc != None: |
|
2341 | if self.data_dc != None: | |
2335 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
2342 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) | |
2336 | dc = self.data_dc |
|
2343 | dc = self.data_dc | |
2337 | data['real'] = dc.real |
|
2344 | data['real'] = dc.real | |
2338 | data['imag'] = dc.imag |
|
2345 | data['imag'] = dc.imag | |
2339 | data = data.reshape((-1)) |
|
2346 | data = data.reshape((-1)) | |
2340 | data.tofile(self.fp) |
|
2347 | data.tofile(self.fp) | |
2341 |
|
2348 | |||
2342 | self.data_spc.fill(0) |
|
2349 | self.data_spc.fill(0) | |
2343 | self.data_dc.fill(0) |
|
2350 | self.data_dc.fill(0) | |
2344 | if self.data_cspc != None: |
|
2351 | if self.data_cspc != None: | |
2345 | self.data_cspc.fill(0) |
|
2352 | self.data_cspc.fill(0) | |
2346 |
|
2353 | |||
2347 | self.flagIsNewFile = 0 |
|
2354 | self.flagIsNewFile = 0 | |
2348 | self.flagIsNewBlock = 1 |
|
2355 | self.flagIsNewBlock = 1 | |
2349 | self.nTotalBlocks += 1 |
|
2356 | self.nTotalBlocks += 1 | |
2350 | self.nWriteBlocks += 1 |
|
2357 | self.nWriteBlocks += 1 | |
2351 | self.blockIndex += 1 |
|
2358 | self.blockIndex += 1 | |
2352 |
|
2359 | |||
2353 |
|
2360 | |||
2354 | def putData(self): |
|
2361 | def putData(self): | |
2355 | """ |
|
2362 | """ | |
2356 | Setea un bloque de datos y luego los escribe en un file |
|
2363 | Setea un bloque de datos y luego los escribe en un file | |
2357 |
|
2364 | |||
2358 | Affected: |
|
2365 | Affected: | |
2359 | self.data_spc |
|
2366 | self.data_spc | |
2360 | self.data_cspc |
|
2367 | self.data_cspc | |
2361 | self.data_dc |
|
2368 | self.data_dc | |
2362 |
|
2369 | |||
2363 | Return: |
|
2370 | Return: | |
2364 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
2371 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
2365 | 1 : Si se escribio la data de un bloque en un file |
|
2372 | 1 : Si se escribio la data de un bloque en un file | |
2366 | """ |
|
2373 | """ | |
2367 |
|
2374 | |||
2368 | if self.dataOut.flagNoData: |
|
2375 | if self.dataOut.flagNoData: | |
2369 | return 0 |
|
2376 | return 0 | |
2370 |
|
2377 | |||
2371 | self.flagIsNewBlock = 0 |
|
2378 | self.flagIsNewBlock = 0 | |
2372 |
|
2379 | |||
2373 | if self.dataOut.flagTimeBlock: |
|
2380 | if self.dataOut.flagTimeBlock: | |
2374 | self.data_spc.fill(0) |
|
2381 | self.data_spc.fill(0) | |
2375 | self.data_cspc.fill(0) |
|
2382 | self.data_cspc.fill(0) | |
2376 | self.data_dc.fill(0) |
|
2383 | self.data_dc.fill(0) | |
2377 | self.setNextFile() |
|
2384 | self.setNextFile() | |
2378 |
|
2385 | |||
2379 | if self.flagIsNewFile == 0: |
|
2386 | if self.flagIsNewFile == 0: | |
2380 |
self. |
|
2387 | self.setBasicHeader() | |
2381 |
|
2388 | |||
2382 | self.data_spc = self.dataOut.data_spc.copy() |
|
2389 | self.data_spc = self.dataOut.data_spc.copy() | |
2383 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
2390 | self.data_cspc = self.dataOut.data_cspc.copy() | |
2384 | self.data_dc = self.dataOut.data_dc.copy() |
|
2391 | self.data_dc = self.dataOut.data_dc.copy() | |
2385 |
|
2392 | |||
2386 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
2393 | # #self.processingHeaderObj.dataBlocksPerFile) | |
2387 | if self.hasAllDataInBuffer(): |
|
2394 | if self.hasAllDataInBuffer(): | |
2388 |
# self. |
|
2395 | # self.setFirstHeader() | |
2389 | self.writeNextBlock() |
|
2396 | self.writeNextBlock() | |
2390 |
|
2397 | |||
2391 | return 1 |
|
2398 | return 1 | |
2392 |
|
2399 | |||
2393 |
|
2400 | |||
2394 | def __getProcessFlags(self): |
|
2401 | def __getProcessFlags(self): | |
2395 |
|
2402 | |||
2396 | processFlags = 0 |
|
2403 | processFlags = 0 | |
2397 |
|
2404 | |||
2398 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2405 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2399 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2406 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2400 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2407 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2401 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2408 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2402 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2409 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2403 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2410 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2404 |
|
2411 | |||
2405 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2412 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2406 |
|
2413 | |||
2407 |
|
2414 | |||
2408 |
|
2415 | |||
2409 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
2416 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, | |
2410 | PROCFLAG.DATATYPE_SHORT, |
|
2417 | PROCFLAG.DATATYPE_SHORT, | |
2411 | PROCFLAG.DATATYPE_LONG, |
|
2418 | PROCFLAG.DATATYPE_LONG, | |
2412 | PROCFLAG.DATATYPE_INT64, |
|
2419 | PROCFLAG.DATATYPE_INT64, | |
2413 | PROCFLAG.DATATYPE_FLOAT, |
|
2420 | PROCFLAG.DATATYPE_FLOAT, | |
2414 | PROCFLAG.DATATYPE_DOUBLE] |
|
2421 | PROCFLAG.DATATYPE_DOUBLE] | |
2415 |
|
2422 | |||
2416 |
|
2423 | |||
2417 | for index in range(len(dtypeList)): |
|
2424 | for index in range(len(dtypeList)): | |
2418 | if self.dataOut.dtype == dtypeList[index]: |
|
2425 | if self.dataOut.dtype == dtypeList[index]: | |
2419 | dtypeValue = datatypeValueList[index] |
|
2426 | dtypeValue = datatypeValueList[index] | |
2420 | break |
|
2427 | break | |
2421 |
|
2428 | |||
2422 | processFlags += dtypeValue |
|
2429 | processFlags += dtypeValue | |
2423 |
|
2430 | |||
2424 | if self.dataOut.flagDecodeData: |
|
2431 | if self.dataOut.flagDecodeData: | |
2425 | processFlags += PROCFLAG.DECODE_DATA |
|
2432 | processFlags += PROCFLAG.DECODE_DATA | |
2426 |
|
2433 | |||
2427 | if self.dataOut.flagDeflipData: |
|
2434 | if self.dataOut.flagDeflipData: | |
2428 | processFlags += PROCFLAG.DEFLIP_DATA |
|
2435 | processFlags += PROCFLAG.DEFLIP_DATA | |
2429 |
|
2436 | |||
2430 | if self.dataOut.code != None: |
|
2437 | if self.dataOut.code != None: | |
2431 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
2438 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE | |
2432 |
|
2439 | |||
2433 | if self.dataOut.nIncohInt > 1: |
|
2440 | if self.dataOut.nIncohInt > 1: | |
2434 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
2441 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION | |
2435 |
|
2442 | |||
2436 | if self.dataOut.data_dc != None: |
|
2443 | if self.dataOut.data_dc != None: | |
2437 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
2444 | processFlags += PROCFLAG.SAVE_CHANNELS_DC | |
2438 |
|
2445 | |||
2439 | return processFlags |
|
2446 | return processFlags | |
2440 |
|
2447 | |||
2441 |
|
2448 | |||
2442 | def __getBlockSize(self): |
|
2449 | def __getBlockSize(self): | |
2443 | ''' |
|
2450 | ''' | |
2444 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
2451 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra | |
2445 | ''' |
|
2452 | ''' | |
2446 |
|
2453 | |||
2447 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
2454 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
2448 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
2455 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
2449 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
2456 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
2450 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
2457 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
2451 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
2458 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
2452 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
2459 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
2453 |
|
2460 | |||
2454 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
2461 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] | |
2455 | datatypeValueList = [1,2,4,8,4,8] |
|
2462 | datatypeValueList = [1,2,4,8,4,8] | |
2456 | for index in range(len(dtypeList)): |
|
2463 | for index in range(len(dtypeList)): | |
2457 | if self.dataOut.dtype == dtypeList[index]: |
|
2464 | if self.dataOut.dtype == dtypeList[index]: | |
2458 | datatypeValue = datatypeValueList[index] |
|
2465 | datatypeValue = datatypeValueList[index] | |
2459 | break |
|
2466 | break | |
2460 |
|
2467 | |||
2461 |
|
2468 | |||
2462 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
2469 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints | |
2463 |
|
2470 | |||
2464 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
2471 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) | |
2465 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
2472 | blocksize = (pts2write_SelfSpectra*datatypeValue) | |
2466 |
|
2473 | |||
2467 | if self.dataOut.data_cspc != None: |
|
2474 | if self.dataOut.data_cspc != None: | |
2468 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
2475 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) | |
2469 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
2476 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) | |
2470 |
|
2477 | |||
2471 | if self.dataOut.data_dc != None: |
|
2478 | if self.dataOut.data_dc != None: | |
2472 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
2479 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) | |
2473 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
2480 | blocksize += (pts2write_DCchannels*datatypeValue*2) | |
2474 |
|
2481 | |||
2475 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
2482 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO | |
2476 |
|
2483 | |||
2477 | return blocksize |
|
2484 | return blocksize | |
2478 |
|
2485 | |||
2479 |
def |
|
2486 | def setFirstHeader(self): | |
2480 |
|
2487 | |||
2481 | """ |
|
2488 | """ | |
2482 | Obtiene una copia del First Header |
|
2489 | Obtiene una copia del First Header | |
2483 |
|
2490 | |||
2484 | Affected: |
|
2491 | Affected: | |
2485 | self.systemHeaderObj |
|
2492 | self.systemHeaderObj | |
2486 | self.radarControllerHeaderObj |
|
2493 | self.radarControllerHeaderObj | |
2487 | self.dtype |
|
2494 | self.dtype | |
2488 |
|
2495 | |||
2489 | Return: |
|
2496 | Return: | |
2490 | None |
|
2497 | None | |
2491 | """ |
|
2498 | """ | |
2492 |
|
2499 | |||
2493 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
2500 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() | |
2494 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
2501 | self.systemHeaderObj.nChannels = self.dataOut.nChannels | |
2495 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
2502 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() | |
2496 |
|
2503 | |||
2497 |
self. |
|
2504 | self.setBasicHeader() | |
2498 |
|
2505 | |||
2499 | processingHeaderSize = 40 # bytes |
|
2506 | processingHeaderSize = 40 # bytes | |
2500 | self.processingHeaderObj.dtype = 1 # Spectra |
|
2507 | self.processingHeaderObj.dtype = 1 # Spectra | |
2501 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
2508 | self.processingHeaderObj.blockSize = self.__getBlockSize() | |
2502 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
2509 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints | |
2503 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
2510 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile | |
2504 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
2511 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
2505 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
2512 | self.processingHeaderObj.processFlags = self.__getProcessFlags() | |
2506 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
2513 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval | |
2507 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
2514 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
2508 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
2515 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels | |
|
2516 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT | |||
2509 |
|
2517 | |||
2510 | if self.processingHeaderObj.totalSpectra > 0: |
|
2518 | if self.processingHeaderObj.totalSpectra > 0: | |
2511 | channelList = [] |
|
2519 | channelList = [] | |
2512 | for channel in range(self.dataOut.nChannels): |
|
2520 | for channel in range(self.dataOut.nChannels): | |
2513 | channelList.append(channel) |
|
2521 | channelList.append(channel) | |
2514 | channelList.append(channel) |
|
2522 | channelList.append(channel) | |
2515 |
|
2523 | |||
2516 | pairsList = [] |
|
2524 | pairsList = [] | |
2517 | for pair in self.dataOut.pairsList: |
|
2525 | for pair in self.dataOut.pairsList: | |
2518 | pairsList.append(pair[0]) |
|
2526 | pairsList.append(pair[0]) | |
2519 | pairsList.append(pair[1]) |
|
2527 | pairsList.append(pair[1]) | |
2520 | spectraComb = channelList + pairsList |
|
2528 | spectraComb = channelList + pairsList | |
2521 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
2529 | spectraComb = numpy.array(spectraComb,dtype="u1") | |
2522 | self.processingHeaderObj.spectraComb = spectraComb |
|
2530 | self.processingHeaderObj.spectraComb = spectraComb | |
2523 | sizeOfSpcComb = len(spectraComb) |
|
2531 | sizeOfSpcComb = len(spectraComb) | |
2524 | processingHeaderSize += sizeOfSpcComb |
|
2532 | processingHeaderSize += sizeOfSpcComb | |
2525 |
|
2533 | |||
2526 | # The processing header should not have information about code |
|
2534 | # The processing header should not have information about code | |
2527 | # if self.dataOut.code != None: |
|
2535 | # if self.dataOut.code != None: | |
2528 | # self.processingHeaderObj.code = self.dataOut.code |
|
2536 | # self.processingHeaderObj.code = self.dataOut.code | |
2529 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
2537 | # self.processingHeaderObj.nCode = self.dataOut.nCode | |
2530 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
2538 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud | |
2531 | # nCodeSize = 4 # bytes |
|
2539 | # nCodeSize = 4 # bytes | |
2532 | # nBaudSize = 4 # bytes |
|
2540 | # nBaudSize = 4 # bytes | |
2533 | # codeSize = 4 # bytes |
|
2541 | # codeSize = 4 # bytes | |
2534 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
2542 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) | |
2535 | # processingHeaderSize += sizeOfCode |
|
2543 | # processingHeaderSize += sizeOfCode | |
2536 |
|
2544 | |||
2537 | if self.processingHeaderObj.nWindows != 0: |
|
2545 | if self.processingHeaderObj.nWindows != 0: | |
2538 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
2546 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] | |
2539 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2547 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
2540 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
2548 | self.processingHeaderObj.nHeights = self.dataOut.nHeights | |
2541 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
2549 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights | |
2542 | sizeOfFirstHeight = 4 |
|
2550 | sizeOfFirstHeight = 4 | |
2543 | sizeOfdeltaHeight = 4 |
|
2551 | sizeOfdeltaHeight = 4 | |
2544 | sizeOfnHeights = 4 |
|
2552 | sizeOfnHeights = 4 | |
2545 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
2553 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows | |
2546 | processingHeaderSize += sizeOfWindows |
|
2554 | processingHeaderSize += sizeOfWindows | |
2547 |
|
2555 | |||
2548 | self.processingHeaderObj.size = processingHeaderSize |
|
2556 | self.processingHeaderObj.size = processingHeaderSize | |
2549 |
|
2557 | |||
2550 | class SpectraHeisWriter(Operation): |
|
2558 | class SpectraHeisWriter(Operation): | |
2551 | # set = None |
|
2559 | # set = None | |
2552 | setFile = None |
|
2560 | setFile = None | |
2553 | idblock = None |
|
2561 | idblock = None | |
2554 | doypath = None |
|
2562 | doypath = None | |
2555 | subfolder = None |
|
2563 | subfolder = None | |
2556 |
|
2564 | |||
2557 | def __init__(self): |
|
2565 | def __init__(self): | |
2558 | self.wrObj = FITS() |
|
2566 | self.wrObj = FITS() | |
2559 | # self.dataOut = dataOut |
|
2567 | # self.dataOut = dataOut | |
2560 | self.nTotalBlocks=0 |
|
2568 | self.nTotalBlocks=0 | |
2561 | # self.set = None |
|
2569 | # self.set = None | |
2562 | self.setFile = None |
|
2570 | self.setFile = None | |
2563 | self.idblock = 0 |
|
2571 | self.idblock = 0 | |
2564 | self.wrpath = None |
|
2572 | self.wrpath = None | |
2565 | self.doypath = None |
|
2573 | self.doypath = None | |
2566 | self.subfolder = None |
|
2574 | self.subfolder = None | |
2567 | self.isConfig = False |
|
2575 | self.isConfig = False | |
2568 |
|
2576 | |||
2569 | def isNumber(str): |
|
2577 | def isNumber(str): | |
2570 | """ |
|
2578 | """ | |
2571 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
2579 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. | |
2572 |
|
2580 | |||
2573 | Excepciones: |
|
2581 | Excepciones: | |
2574 | Si un determinado string no puede ser convertido a numero |
|
2582 | Si un determinado string no puede ser convertido a numero | |
2575 | Input: |
|
2583 | Input: | |
2576 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
2584 | str, string al cual se le analiza para determinar si convertible a un numero o no | |
2577 |
|
2585 | |||
2578 | Return: |
|
2586 | Return: | |
2579 | True : si el string es uno numerico |
|
2587 | True : si el string es uno numerico | |
2580 | False : no es un string numerico |
|
2588 | False : no es un string numerico | |
2581 | """ |
|
2589 | """ | |
2582 | try: |
|
2590 | try: | |
2583 | float( str ) |
|
2591 | float( str ) | |
2584 | return True |
|
2592 | return True | |
2585 | except: |
|
2593 | except: | |
2586 | return False |
|
2594 | return False | |
2587 |
|
2595 | |||
2588 | def setup(self, dataOut, wrpath): |
|
2596 | def setup(self, dataOut, wrpath): | |
2589 |
|
2597 | |||
2590 | if not(os.path.exists(wrpath)): |
|
2598 | if not(os.path.exists(wrpath)): | |
2591 | os.mkdir(wrpath) |
|
2599 | os.mkdir(wrpath) | |
2592 |
|
2600 | |||
2593 | self.wrpath = wrpath |
|
2601 | self.wrpath = wrpath | |
2594 | # self.setFile = 0 |
|
2602 | # self.setFile = 0 | |
2595 | self.dataOut = dataOut |
|
2603 | self.dataOut = dataOut | |
2596 |
|
2604 | |||
2597 | def putData(self): |
|
2605 | def putData(self): | |
2598 | name= time.localtime( self.dataOut.utctime) |
|
2606 | name= time.localtime( self.dataOut.utctime) | |
2599 | ext=".fits" |
|
2607 | ext=".fits" | |
2600 |
|
2608 | |||
2601 | if self.doypath == None: |
|
2609 | if self.doypath == None: | |
2602 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) |
|
2610 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) | |
2603 | self.doypath = os.path.join( self.wrpath, self.subfolder ) |
|
2611 | self.doypath = os.path.join( self.wrpath, self.subfolder ) | |
2604 | os.mkdir(self.doypath) |
|
2612 | os.mkdir(self.doypath) | |
2605 |
|
2613 | |||
2606 | if self.setFile == None: |
|
2614 | if self.setFile == None: | |
2607 | # self.set = self.dataOut.set |
|
2615 | # self.set = self.dataOut.set | |
2608 | self.setFile = 0 |
|
2616 | self.setFile = 0 | |
2609 | # if self.set != self.dataOut.set: |
|
2617 | # if self.set != self.dataOut.set: | |
2610 | ## self.set = self.dataOut.set |
|
2618 | ## self.set = self.dataOut.set | |
2611 | # self.setFile = 0 |
|
2619 | # self.setFile = 0 | |
2612 |
|
2620 | |||
2613 | #make the filename |
|
2621 | #make the filename | |
2614 | file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) |
|
2622 | file = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) | |
2615 |
|
2623 | |||
2616 | filename = os.path.join(self.wrpath,self.subfolder, file) |
|
2624 | filename = os.path.join(self.wrpath,self.subfolder, file) | |
2617 |
|
2625 | |||
2618 | idblock = numpy.array([self.idblock],dtype="int64") |
|
2626 | idblock = numpy.array([self.idblock],dtype="int64") | |
2619 | header=self.wrObj.cFImage(idblock=idblock, |
|
2627 | header=self.wrObj.cFImage(idblock=idblock, | |
2620 | year=time.gmtime(self.dataOut.utctime).tm_year, |
|
2628 | year=time.gmtime(self.dataOut.utctime).tm_year, | |
2621 | month=time.gmtime(self.dataOut.utctime).tm_mon, |
|
2629 | month=time.gmtime(self.dataOut.utctime).tm_mon, | |
2622 | day=time.gmtime(self.dataOut.utctime).tm_mday, |
|
2630 | day=time.gmtime(self.dataOut.utctime).tm_mday, | |
2623 | hour=time.gmtime(self.dataOut.utctime).tm_hour, |
|
2631 | hour=time.gmtime(self.dataOut.utctime).tm_hour, | |
2624 | minute=time.gmtime(self.dataOut.utctime).tm_min, |
|
2632 | minute=time.gmtime(self.dataOut.utctime).tm_min, | |
2625 | second=time.gmtime(self.dataOut.utctime).tm_sec) |
|
2633 | second=time.gmtime(self.dataOut.utctime).tm_sec) | |
2626 |
|
2634 | |||
2627 | c=3E8 |
|
2635 | c=3E8 | |
2628 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
2636 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
2629 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000)) |
|
2637 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000)) | |
2630 |
|
2638 | |||
2631 | colList = [] |
|
2639 | colList = [] | |
2632 |
|
2640 | |||
2633 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
2641 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) | |
2634 |
|
2642 | |||
2635 | colList.append(colFreq) |
|
2643 | colList.append(colFreq) | |
2636 |
|
2644 | |||
2637 | nchannel=self.dataOut.nChannels |
|
2645 | nchannel=self.dataOut.nChannels | |
2638 |
|
2646 | |||
2639 | for i in range(nchannel): |
|
2647 | for i in range(nchannel): | |
2640 | col = self.wrObj.writeData(name="PCh"+str(i+1), |
|
2648 | col = self.wrObj.writeData(name="PCh"+str(i+1), | |
2641 | format=str(self.dataOut.nFFTPoints)+'E', |
|
2649 | format=str(self.dataOut.nFFTPoints)+'E', | |
2642 | data=10*numpy.log10(self.dataOut.data_spc[i,:])) |
|
2650 | data=10*numpy.log10(self.dataOut.data_spc[i,:])) | |
2643 |
|
2651 | |||
2644 | colList.append(col) |
|
2652 | colList.append(col) | |
2645 |
|
2653 | |||
2646 | data=self.wrObj.Ctable(colList=colList) |
|
2654 | data=self.wrObj.Ctable(colList=colList) | |
2647 |
|
2655 | |||
2648 | self.wrObj.CFile(header,data) |
|
2656 | self.wrObj.CFile(header,data) | |
2649 |
|
2657 | |||
2650 | self.wrObj.wFile(filename) |
|
2658 | self.wrObj.wFile(filename) | |
2651 |
|
2659 | |||
2652 | #update the setFile |
|
2660 | #update the setFile | |
2653 | self.setFile += 1 |
|
2661 | self.setFile += 1 | |
2654 | self.idblock += 1 |
|
2662 | self.idblock += 1 | |
2655 |
|
2663 | |||
2656 | return 1 |
|
2664 | return 1 | |
2657 |
|
2665 | |||
2658 | def run(self, dataOut, **kwargs): |
|
2666 | def run(self, dataOut, **kwargs): | |
2659 |
|
2667 | |||
2660 | if not(self.isConfig): |
|
2668 | if not(self.isConfig): | |
2661 |
|
2669 | |||
2662 | self.setup(dataOut, **kwargs) |
|
2670 | self.setup(dataOut, **kwargs) | |
2663 | self.isConfig = True |
|
2671 | self.isConfig = True | |
2664 |
|
2672 | |||
2665 | self.putData() |
|
2673 | self.putData() | |
2666 |
|
2674 | |||
2667 |
|
2675 | |||
2668 | class FITS: |
|
2676 | class FITS: | |
2669 | name=None |
|
2677 | name=None | |
2670 | format=None |
|
2678 | format=None | |
2671 | array =None |
|
2679 | array =None | |
2672 | data =None |
|
2680 | data =None | |
2673 | thdulist=None |
|
2681 | thdulist=None | |
2674 | prihdr=None |
|
2682 | prihdr=None | |
2675 | hdu=None |
|
2683 | hdu=None | |
2676 |
|
2684 | |||
2677 | def __init__(self): |
|
2685 | def __init__(self): | |
2678 |
|
2686 | |||
2679 | pass |
|
2687 | pass | |
2680 |
|
2688 | |||
2681 | def setColF(self,name,format,array): |
|
2689 | def setColF(self,name,format,array): | |
2682 | self.name=name |
|
2690 | self.name=name | |
2683 | self.format=format |
|
2691 | self.format=format | |
2684 | self.array=array |
|
2692 | self.array=array | |
2685 | a1=numpy.array([self.array],dtype=numpy.float32) |
|
2693 | a1=numpy.array([self.array],dtype=numpy.float32) | |
2686 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) |
|
2694 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
2687 | return self.col1 |
|
2695 | return self.col1 | |
2688 |
|
2696 | |||
2689 | # def setColP(self,name,format,data): |
|
2697 | # def setColP(self,name,format,data): | |
2690 | # self.name=name |
|
2698 | # self.name=name | |
2691 | # self.format=format |
|
2699 | # self.format=format | |
2692 | # self.data=data |
|
2700 | # self.data=data | |
2693 | # a2=numpy.array([self.data],dtype=numpy.float32) |
|
2701 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
2694 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2702 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2695 | # return self.col2 |
|
2703 | # return self.col2 | |
2696 |
|
2704 | |||
2697 |
|
2705 | |||
2698 | def writeData(self,name,format,data): |
|
2706 | def writeData(self,name,format,data): | |
2699 | self.name=name |
|
2707 | self.name=name | |
2700 | self.format=format |
|
2708 | self.format=format | |
2701 | self.data=data |
|
2709 | self.data=data | |
2702 | a2=numpy.array([self.data],dtype=numpy.float32) |
|
2710 | a2=numpy.array([self.data],dtype=numpy.float32) | |
2703 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) |
|
2711 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
2704 | return self.col2 |
|
2712 | return self.col2 | |
2705 |
|
2713 | |||
2706 | def cFImage(self,idblock,year,month,day,hour,minute,second): |
|
2714 | def cFImage(self,idblock,year,month,day,hour,minute,second): | |
2707 | self.hdu= pyfits.PrimaryHDU(idblock) |
|
2715 | self.hdu= pyfits.PrimaryHDU(idblock) | |
2708 | self.hdu.header.set("Year",year) |
|
2716 | self.hdu.header.set("Year",year) | |
2709 | self.hdu.header.set("Month",month) |
|
2717 | self.hdu.header.set("Month",month) | |
2710 | self.hdu.header.set("Day",day) |
|
2718 | self.hdu.header.set("Day",day) | |
2711 | self.hdu.header.set("Hour",hour) |
|
2719 | self.hdu.header.set("Hour",hour) | |
2712 | self.hdu.header.set("Minute",minute) |
|
2720 | self.hdu.header.set("Minute",minute) | |
2713 | self.hdu.header.set("Second",second) |
|
2721 | self.hdu.header.set("Second",second) | |
2714 | return self.hdu |
|
2722 | return self.hdu | |
2715 |
|
2723 | |||
2716 |
|
2724 | |||
2717 | def Ctable(self,colList): |
|
2725 | def Ctable(self,colList): | |
2718 | self.cols=pyfits.ColDefs(colList) |
|
2726 | self.cols=pyfits.ColDefs(colList) | |
2719 | self.tbhdu = pyfits.new_table(self.cols) |
|
2727 | self.tbhdu = pyfits.new_table(self.cols) | |
2720 | return self.tbhdu |
|
2728 | return self.tbhdu | |
2721 |
|
2729 | |||
2722 |
|
2730 | |||
2723 | def CFile(self,hdu,tbhdu): |
|
2731 | def CFile(self,hdu,tbhdu): | |
2724 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) |
|
2732 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
2725 |
|
2733 | |||
2726 | def wFile(self,filename): |
|
2734 | def wFile(self,filename): | |
2727 | if os.path.isfile(filename): |
|
2735 | if os.path.isfile(filename): | |
2728 | os.remove(filename) |
|
2736 | os.remove(filename) | |
2729 | self.thdulist.writeto(filename) |
|
2737 | self.thdulist.writeto(filename) |
@@ -1,530 +1,534 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: murco $ |
|
3 | $Author: murco $ | |
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ | |
5 | ''' |
|
5 | ''' | |
6 | import sys |
|
6 | import sys | |
7 | import numpy |
|
7 | import numpy | |
8 | import copy |
|
8 | import copy | |
9 | import datetime |
|
9 | import datetime | |
10 |
|
10 | |||
11 | class Header: |
|
11 | class Header: | |
12 |
|
12 | |||
13 | def __init__(self): |
|
13 | def __init__(self): | |
14 | raise |
|
14 | raise | |
15 |
|
15 | |||
16 | def copy(self): |
|
16 | def copy(self): | |
17 | return copy.deepcopy(self) |
|
17 | return copy.deepcopy(self) | |
18 |
|
18 | |||
19 | def read(): |
|
19 | def read(): | |
20 | pass |
|
20 | pass | |
21 |
|
21 | |||
22 | def write(): |
|
22 | def write(): | |
23 | pass |
|
23 | pass | |
24 |
|
24 | |||
25 | def printInfo(self): |
|
25 | def printInfo(self): | |
26 |
|
26 | |||
27 | print "#"*100 |
|
27 | print "#"*100 | |
28 | print self.__class__.__name__.upper() |
|
28 | print self.__class__.__name__.upper() | |
29 | print "#"*100 |
|
29 | print "#"*100 | |
30 | for key in self.__dict__.keys(): |
|
30 | for key in self.__dict__.keys(): | |
31 | print "%s = %s" %(key, self.__dict__[key]) |
|
31 | print "%s = %s" %(key, self.__dict__[key]) | |
32 |
|
32 | |||
33 | class BasicHeader(Header): |
|
33 | class BasicHeader(Header): | |
34 |
|
34 | |||
35 | size = None |
|
35 | size = None | |
36 | version = None |
|
36 | version = None | |
37 | dataBlock = None |
|
37 | dataBlock = None | |
38 | utc = None |
|
38 | utc = None | |
|
39 | ltc = None | |||
39 | miliSecond = None |
|
40 | miliSecond = None | |
40 | timeZone = None |
|
41 | timeZone = None | |
41 | dstFlag = None |
|
42 | dstFlag = None | |
42 | errorCount = None |
|
43 | errorCount = None | |
43 | struct = None |
|
44 | struct = None | |
44 | datatime = None |
|
45 | datatime = None | |
45 |
|
46 | |||
46 | __LOCALTIME = None |
|
47 | __LOCALTIME = None | |
47 |
|
48 | |||
48 |
def __init__(self, |
|
49 | def __init__(self, useLocalTime=True): | |
49 |
|
50 | |||
50 | self.size = 0 |
|
51 | self.size = 0 | |
51 | self.version = 0 |
|
52 | self.version = 0 | |
52 | self.dataBlock = 0 |
|
53 | self.dataBlock = 0 | |
53 | self.utc = 0 |
|
54 | self.utc = 0 | |
54 | self.miliSecond = 0 |
|
55 | self.miliSecond = 0 | |
55 | self.timeZone = 0 |
|
56 | self.timeZone = 0 | |
56 | self.dstFlag = 0 |
|
57 | self.dstFlag = 0 | |
57 | self.errorCount = 0 |
|
58 | self.errorCount = 0 | |
58 | self.struct = numpy.dtype([ |
|
59 | self.struct = numpy.dtype([ | |
59 | ('nSize','<u4'), |
|
60 | ('nSize','<u4'), | |
60 | ('nVersion','<u2'), |
|
61 | ('nVersion','<u2'), | |
61 | ('nDataBlockId','<u4'), |
|
62 | ('nDataBlockId','<u4'), | |
62 | ('nUtime','<u4'), |
|
63 | ('nUtime','<u4'), | |
63 | ('nMilsec','<u2'), |
|
64 | ('nMilsec','<u2'), | |
64 | ('nTimezone','<i2'), |
|
65 | ('nTimezone','<i2'), | |
65 | ('nDstflag','<i2'), |
|
66 | ('nDstflag','<i2'), | |
66 | ('nErrorCount','<u4') |
|
67 | ('nErrorCount','<u4') | |
67 | ]) |
|
68 | ]) | |
68 |
|
69 | |||
69 | self.__LOCALTIME = localtime |
|
70 | self.useLocalTime = useLocalTime | |
70 |
|
71 | |||
71 | def read(self, fp): |
|
72 | def read(self, fp): | |
72 | try: |
|
73 | try: | |
73 | header = numpy.fromfile(fp, self.struct,1) |
|
74 | header = numpy.fromfile(fp, self.struct,1) | |
74 | self.size = int(header['nSize'][0]) |
|
75 | self.size = int(header['nSize'][0]) | |
75 | self.version = int(header['nVersion'][0]) |
|
76 | self.version = int(header['nVersion'][0]) | |
76 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
77 | self.dataBlock = int(header['nDataBlockId'][0]) | |
77 | self.utc = int(header['nUtime'][0]) |
|
78 | self.utc = int(header['nUtime'][0]) | |
78 | self.miliSecond = int(header['nMilsec'][0]) |
|
79 | self.miliSecond = int(header['nMilsec'][0]) | |
79 | self.timeZone = int(header['nTimezone'][0]) |
|
80 | self.timeZone = int(header['nTimezone'][0]) | |
80 | self.dstFlag = int(header['nDstflag'][0]) |
|
81 | self.dstFlag = int(header['nDstflag'][0]) | |
81 | self.errorCount = int(header['nErrorCount'][0]) |
|
82 | self.errorCount = int(header['nErrorCount'][0]) | |
82 |
|
83 | |||
83 |
self. |
|
84 | self.ltc = self.utc | |
84 |
|
85 | |||
85 | self.datatime = datetime.datetime.utcfromtimestamp(self.utc) |
|
86 | if self.useLocalTime: | |
|
87 | self.ltc -= self.timeZone*60 | |||
|
88 | ||||
|
89 | self.datatime = datetime.datetime.utcfromtimestamp(self.ltc) | |||
86 |
|
90 | |||
87 | except Exception, e: |
|
91 | except Exception, e: | |
88 | print "BasicHeader: " |
|
92 | print "BasicHeader: " | |
89 | print e |
|
93 | print e | |
90 | return 0 |
|
94 | return 0 | |
91 |
|
95 | |||
92 | return 1 |
|
96 | return 1 | |
93 |
|
97 | |||
94 | def write(self, fp): |
|
98 | def write(self, fp): | |
95 | self.utc -= self.__LOCALTIME |
|
99 | ||
96 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
100 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) | |
97 | header = numpy.array(headerTuple,self.struct) |
|
101 | header = numpy.array(headerTuple,self.struct) | |
98 | header.tofile(fp) |
|
102 | header.tofile(fp) | |
99 |
|
103 | |||
100 | return 1 |
|
104 | return 1 | |
101 |
|
105 | |||
102 | class SystemHeader(Header): |
|
106 | class SystemHeader(Header): | |
103 |
|
107 | |||
104 | size = None |
|
108 | size = None | |
105 | nSamples = None |
|
109 | nSamples = None | |
106 | nProfiles = None |
|
110 | nProfiles = None | |
107 | nChannels = None |
|
111 | nChannels = None | |
108 | adcResolution = None |
|
112 | adcResolution = None | |
109 | pciDioBusWidth = None |
|
113 | pciDioBusWidth = None | |
110 | struct = None |
|
114 | struct = None | |
111 |
|
115 | |||
112 | def __init__(self): |
|
116 | def __init__(self): | |
113 | self.size = 0 |
|
117 | self.size = 0 | |
114 | self.nSamples = 0 |
|
118 | self.nSamples = 0 | |
115 | self.nProfiles = 0 |
|
119 | self.nProfiles = 0 | |
116 | self.nChannels = 0 |
|
120 | self.nChannels = 0 | |
117 | self.adcResolution = 0 |
|
121 | self.adcResolution = 0 | |
118 | self.pciDioBusWidth = 0 |
|
122 | self.pciDioBusWidth = 0 | |
119 | self.struct = numpy.dtype([ |
|
123 | self.struct = numpy.dtype([ | |
120 | ('nSize','<u4'), |
|
124 | ('nSize','<u4'), | |
121 | ('nNumSamples','<u4'), |
|
125 | ('nNumSamples','<u4'), | |
122 | ('nNumProfiles','<u4'), |
|
126 | ('nNumProfiles','<u4'), | |
123 | ('nNumChannels','<u4'), |
|
127 | ('nNumChannels','<u4'), | |
124 | ('nADCResolution','<u4'), |
|
128 | ('nADCResolution','<u4'), | |
125 | ('nPCDIOBusWidth','<u4'), |
|
129 | ('nPCDIOBusWidth','<u4'), | |
126 | ]) |
|
130 | ]) | |
127 |
|
131 | |||
128 |
|
132 | |||
129 | def read(self, fp): |
|
133 | def read(self, fp): | |
130 | try: |
|
134 | try: | |
131 | header = numpy.fromfile(fp,self.struct,1) |
|
135 | header = numpy.fromfile(fp,self.struct,1) | |
132 | self.size = header['nSize'][0] |
|
136 | self.size = header['nSize'][0] | |
133 | self.nSamples = header['nNumSamples'][0] |
|
137 | self.nSamples = header['nNumSamples'][0] | |
134 | self.nProfiles = header['nNumProfiles'][0] |
|
138 | self.nProfiles = header['nNumProfiles'][0] | |
135 | self.nChannels = header['nNumChannels'][0] |
|
139 | self.nChannels = header['nNumChannels'][0] | |
136 | self.adcResolution = header['nADCResolution'][0] |
|
140 | self.adcResolution = header['nADCResolution'][0] | |
137 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
141 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] | |
138 |
|
142 | |||
139 | except Exception, e: |
|
143 | except Exception, e: | |
140 | print "SystemHeader: " + e |
|
144 | print "SystemHeader: " + e | |
141 | return 0 |
|
145 | return 0 | |
142 |
|
146 | |||
143 | return 1 |
|
147 | return 1 | |
144 |
|
148 | |||
145 | def write(self, fp): |
|
149 | def write(self, fp): | |
146 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
150 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) | |
147 | header = numpy.array(headerTuple,self.struct) |
|
151 | header = numpy.array(headerTuple,self.struct) | |
148 | header.tofile(fp) |
|
152 | header.tofile(fp) | |
149 |
|
153 | |||
150 | return 1 |
|
154 | return 1 | |
151 |
|
155 | |||
152 | class RadarControllerHeader(Header): |
|
156 | class RadarControllerHeader(Header): | |
153 |
|
157 | |||
154 | size = None |
|
158 | size = None | |
155 | expType = None |
|
159 | expType = None | |
156 | nTx = None |
|
160 | nTx = None | |
157 | ipp = None |
|
161 | ipp = None | |
158 | txA = None |
|
162 | txA = None | |
159 | txB = None |
|
163 | txB = None | |
160 | nWindows = None |
|
164 | nWindows = None | |
161 | numTaus = None |
|
165 | numTaus = None | |
162 | codeType = None |
|
166 | codeType = None | |
163 | line6Function = None |
|
167 | line6Function = None | |
164 | line5Function = None |
|
168 | line5Function = None | |
165 | fClock = None |
|
169 | fClock = None | |
166 | prePulseBefore = None |
|
170 | prePulseBefore = None | |
167 | prePulserAfter = None |
|
171 | prePulserAfter = None | |
168 | rangeIpp = None |
|
172 | rangeIpp = None | |
169 | rangeTxA = None |
|
173 | rangeTxA = None | |
170 | rangeTxB = None |
|
174 | rangeTxB = None | |
171 | struct = None |
|
175 | struct = None | |
172 |
|
176 | |||
173 | def __init__(self): |
|
177 | def __init__(self): | |
174 | self.size = 0 |
|
178 | self.size = 0 | |
175 | self.expType = 0 |
|
179 | self.expType = 0 | |
176 | self.nTx = 0 |
|
180 | self.nTx = 0 | |
177 | self.ipp = 0 |
|
181 | self.ipp = 0 | |
178 | self.txA = 0 |
|
182 | self.txA = 0 | |
179 | self.txB = 0 |
|
183 | self.txB = 0 | |
180 | self.nWindows = 0 |
|
184 | self.nWindows = 0 | |
181 | self.numTaus = 0 |
|
185 | self.numTaus = 0 | |
182 | self.codeType = 0 |
|
186 | self.codeType = 0 | |
183 | self.line6Function = 0 |
|
187 | self.line6Function = 0 | |
184 | self.line5Function = 0 |
|
188 | self.line5Function = 0 | |
185 | self.fClock = 0 |
|
189 | self.fClock = 0 | |
186 | self.prePulseBefore = 0 |
|
190 | self.prePulseBefore = 0 | |
187 | self.prePulserAfter = 0 |
|
191 | self.prePulserAfter = 0 | |
188 | self.rangeIpp = 0 |
|
192 | self.rangeIpp = 0 | |
189 | self.rangeTxA = 0 |
|
193 | self.rangeTxA = 0 | |
190 | self.rangeTxB = 0 |
|
194 | self.rangeTxB = 0 | |
191 | self.struct = numpy.dtype([ |
|
195 | self.struct = numpy.dtype([ | |
192 | ('nSize','<u4'), |
|
196 | ('nSize','<u4'), | |
193 | ('nExpType','<u4'), |
|
197 | ('nExpType','<u4'), | |
194 | ('nNTx','<u4'), |
|
198 | ('nNTx','<u4'), | |
195 | ('fIpp','<f4'), |
|
199 | ('fIpp','<f4'), | |
196 | ('fTxA','<f4'), |
|
200 | ('fTxA','<f4'), | |
197 | ('fTxB','<f4'), |
|
201 | ('fTxB','<f4'), | |
198 | ('nNumWindows','<u4'), |
|
202 | ('nNumWindows','<u4'), | |
199 | ('nNumTaus','<u4'), |
|
203 | ('nNumTaus','<u4'), | |
200 | ('nCodeType','<u4'), |
|
204 | ('nCodeType','<u4'), | |
201 | ('nLine6Function','<u4'), |
|
205 | ('nLine6Function','<u4'), | |
202 | ('nLine5Function','<u4'), |
|
206 | ('nLine5Function','<u4'), | |
203 | ('fClock','<f4'), |
|
207 | ('fClock','<f4'), | |
204 | ('nPrePulseBefore','<u4'), |
|
208 | ('nPrePulseBefore','<u4'), | |
205 | ('nPrePulseAfter','<u4'), |
|
209 | ('nPrePulseAfter','<u4'), | |
206 | ('sRangeIPP','<a20'), |
|
210 | ('sRangeIPP','<a20'), | |
207 | ('sRangeTxA','<a20'), |
|
211 | ('sRangeTxA','<a20'), | |
208 | ('sRangeTxB','<a20'), |
|
212 | ('sRangeTxB','<a20'), | |
209 | ]) |
|
213 | ]) | |
210 |
|
214 | |||
211 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
215 | self.samplingWindowStruct = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
212 |
|
216 | |||
213 | self.samplingWindow = None |
|
217 | self.samplingWindow = None | |
214 | self.nHeights = None |
|
218 | self.nHeights = None | |
215 | self.firstHeight = None |
|
219 | self.firstHeight = None | |
216 | self.deltaHeight = None |
|
220 | self.deltaHeight = None | |
217 | self.samplesWin = None |
|
221 | self.samplesWin = None | |
218 |
|
222 | |||
219 | self.nCode = None |
|
223 | self.nCode = None | |
220 | self.nBaud = None |
|
224 | self.nBaud = None | |
221 | self.code = None |
|
225 | self.code = None | |
222 | self.flip1 = None |
|
226 | self.flip1 = None | |
223 | self.flip2 = None |
|
227 | self.flip2 = None | |
224 |
|
228 | |||
225 | self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
229 | self.dynamic = numpy.array([],numpy.dtype('byte')) | |
226 |
|
230 | |||
227 |
|
231 | |||
228 | def read(self, fp): |
|
232 | def read(self, fp): | |
229 | try: |
|
233 | try: | |
230 | startFp = fp.tell() |
|
234 | startFp = fp.tell() | |
231 | header = numpy.fromfile(fp,self.struct,1) |
|
235 | header = numpy.fromfile(fp,self.struct,1) | |
232 | self.size = int(header['nSize'][0]) |
|
236 | self.size = int(header['nSize'][0]) | |
233 | self.expType = int(header['nExpType'][0]) |
|
237 | self.expType = int(header['nExpType'][0]) | |
234 | self.nTx = int(header['nNTx'][0]) |
|
238 | self.nTx = int(header['nNTx'][0]) | |
235 | self.ipp = float(header['fIpp'][0]) |
|
239 | self.ipp = float(header['fIpp'][0]) | |
236 | self.txA = float(header['fTxA'][0]) |
|
240 | self.txA = float(header['fTxA'][0]) | |
237 | self.txB = float(header['fTxB'][0]) |
|
241 | self.txB = float(header['fTxB'][0]) | |
238 | self.nWindows = int(header['nNumWindows'][0]) |
|
242 | self.nWindows = int(header['nNumWindows'][0]) | |
239 | self.numTaus = int(header['nNumTaus'][0]) |
|
243 | self.numTaus = int(header['nNumTaus'][0]) | |
240 | self.codeType = int(header['nCodeType'][0]) |
|
244 | self.codeType = int(header['nCodeType'][0]) | |
241 | self.line6Function = int(header['nLine6Function'][0]) |
|
245 | self.line6Function = int(header['nLine6Function'][0]) | |
242 | self.line5Function = int(header['nLine5Function'][0]) |
|
246 | self.line5Function = int(header['nLine5Function'][0]) | |
243 | self.fClock = float(header['fClock'][0]) |
|
247 | self.fClock = float(header['fClock'][0]) | |
244 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
248 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) | |
245 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) |
|
249 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) | |
246 | self.rangeIpp = header['sRangeIPP'][0] |
|
250 | self.rangeIpp = header['sRangeIPP'][0] | |
247 | self.rangeTxA = header['sRangeTxA'][0] |
|
251 | self.rangeTxA = header['sRangeTxA'][0] | |
248 | self.rangeTxB = header['sRangeTxB'][0] |
|
252 | self.rangeTxB = header['sRangeTxB'][0] | |
249 | # jump Dynamic Radar Controller Header |
|
253 | # jump Dynamic Radar Controller Header | |
250 | jumpFp = self.size - 116 |
|
254 | jumpFp = self.size - 116 | |
251 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
255 | self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) | |
252 | #pointer backward to dynamic header and read |
|
256 | #pointer backward to dynamic header and read | |
253 | backFp = fp.tell() - jumpFp |
|
257 | backFp = fp.tell() - jumpFp | |
254 | fp.seek(backFp) |
|
258 | fp.seek(backFp) | |
255 |
|
259 | |||
256 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) |
|
260 | self.samplingWindow = numpy.fromfile(fp,self.samplingWindowStruct,self.nWindows) | |
257 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) |
|
261 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) | |
258 | self.firstHeight = self.samplingWindow['h0'] |
|
262 | self.firstHeight = self.samplingWindow['h0'] | |
259 | self.deltaHeight = self.samplingWindow['dh'] |
|
263 | self.deltaHeight = self.samplingWindow['dh'] | |
260 | self.samplesWin = self.samplingWindow['nsa'] |
|
264 | self.samplesWin = self.samplingWindow['nsa'] | |
261 |
|
265 | |||
262 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
266 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) | |
263 |
|
267 | |||
264 | if self.codeType != 0: |
|
268 | if self.codeType != 0: | |
265 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
269 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
266 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
270 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
267 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') |
|
271 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='u1') | |
268 | tempList = [] |
|
272 | tempList = [] | |
269 | for ic in range(self.nCode): |
|
273 | for ic in range(self.nCode): | |
270 | temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.))) |
|
274 | temp = numpy.fromfile(fp,'u1',4*int(numpy.ceil(self.nBaud/32.))) | |
271 | tempList.append(temp) |
|
275 | tempList.append(temp) | |
272 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] |
|
276 | self.code[ic] = numpy.unpackbits(temp[::-1])[-1*self.nBaud:] | |
273 | self.code = 2.0*self.code - 1.0 |
|
277 | self.code = 2.0*self.code - 1.0 | |
274 |
|
278 | |||
275 | if self.line5Function == RCfunction.FLIP: |
|
279 | if self.line5Function == RCfunction.FLIP: | |
276 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
280 | self.flip1 = numpy.fromfile(fp,'<u4',1) | |
277 |
|
281 | |||
278 | if self.line6Function == RCfunction.FLIP: |
|
282 | if self.line6Function == RCfunction.FLIP: | |
279 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
283 | self.flip2 = numpy.fromfile(fp,'<u4',1) | |
280 |
|
284 | |||
281 | endFp = self.size + startFp |
|
285 | endFp = self.size + startFp | |
282 | jumpFp = endFp - fp.tell() |
|
286 | jumpFp = endFp - fp.tell() | |
283 | if jumpFp > 0: |
|
287 | if jumpFp > 0: | |
284 | fp.seek(jumpFp) |
|
288 | fp.seek(jumpFp) | |
285 |
|
289 | |||
286 | except Exception, e: |
|
290 | except Exception, e: | |
287 | print "RadarControllerHeader: " + e |
|
291 | print "RadarControllerHeader: " + e | |
288 | return 0 |
|
292 | return 0 | |
289 |
|
293 | |||
290 | return 1 |
|
294 | return 1 | |
291 |
|
295 | |||
292 | def write(self, fp): |
|
296 | def write(self, fp): | |
293 | headerTuple = (self.size, |
|
297 | headerTuple = (self.size, | |
294 | self.expType, |
|
298 | self.expType, | |
295 | self.nTx, |
|
299 | self.nTx, | |
296 | self.ipp, |
|
300 | self.ipp, | |
297 | self.txA, |
|
301 | self.txA, | |
298 | self.txB, |
|
302 | self.txB, | |
299 | self.nWindows, |
|
303 | self.nWindows, | |
300 | self.numTaus, |
|
304 | self.numTaus, | |
301 | self.codeType, |
|
305 | self.codeType, | |
302 | self.line6Function, |
|
306 | self.line6Function, | |
303 | self.line5Function, |
|
307 | self.line5Function, | |
304 | self.fClock, |
|
308 | self.fClock, | |
305 | self.prePulseBefore, |
|
309 | self.prePulseBefore, | |
306 | self.prePulserAfter, |
|
310 | self.prePulserAfter, | |
307 | self.rangeIpp, |
|
311 | self.rangeIpp, | |
308 | self.rangeTxA, |
|
312 | self.rangeTxA, | |
309 | self.rangeTxB) |
|
313 | self.rangeTxB) | |
310 |
|
314 | |||
311 | header = numpy.array(headerTuple,self.struct) |
|
315 | header = numpy.array(headerTuple,self.struct) | |
312 | header.tofile(fp) |
|
316 | header.tofile(fp) | |
313 |
|
317 | |||
314 | dynamic = self.dynamic |
|
318 | dynamic = self.dynamic | |
315 | dynamic.tofile(fp) |
|
319 | dynamic.tofile(fp) | |
316 |
|
320 | |||
317 | return 1 |
|
321 | return 1 | |
318 |
|
322 | |||
319 |
|
323 | |||
320 |
|
324 | |||
321 | class ProcessingHeader(Header): |
|
325 | class ProcessingHeader(Header): | |
322 |
|
326 | |||
323 | size = None |
|
327 | size = None | |
324 | dtype = None |
|
328 | dtype = None | |
325 | blockSize = None |
|
329 | blockSize = None | |
326 | profilesPerBlock = None |
|
330 | profilesPerBlock = None | |
327 | dataBlocksPerFile = None |
|
331 | dataBlocksPerFile = None | |
328 | nWindows = None |
|
332 | nWindows = None | |
329 | processFlags = None |
|
333 | processFlags = None | |
330 | nCohInt = None |
|
334 | nCohInt = None | |
331 | nIncohInt = None |
|
335 | nIncohInt = None | |
332 | totalSpectra = None |
|
336 | totalSpectra = None | |
333 | struct = None |
|
337 | struct = None | |
334 | flag_dc = None |
|
338 | flag_dc = None | |
335 | flag_cspc = None |
|
339 | flag_cspc = None | |
336 |
|
340 | |||
337 | def __init__(self): |
|
341 | def __init__(self): | |
338 | self.size = 0 |
|
342 | self.size = 0 | |
339 | self.dtype = 0 |
|
343 | self.dtype = 0 | |
340 | self.blockSize = 0 |
|
344 | self.blockSize = 0 | |
341 | self.profilesPerBlock = 0 |
|
345 | self.profilesPerBlock = 0 | |
342 | self.dataBlocksPerFile = 0 |
|
346 | self.dataBlocksPerFile = 0 | |
343 | self.nWindows = 0 |
|
347 | self.nWindows = 0 | |
344 | self.processFlags = 0 |
|
348 | self.processFlags = 0 | |
345 | self.nCohInt = 0 |
|
349 | self.nCohInt = 0 | |
346 | self.nIncohInt = 0 |
|
350 | self.nIncohInt = 0 | |
347 | self.totalSpectra = 0 |
|
351 | self.totalSpectra = 0 | |
348 | self.struct = numpy.dtype([ |
|
352 | self.struct = numpy.dtype([ | |
349 | ('nSize','<u4'), |
|
353 | ('nSize','<u4'), | |
350 | ('nDataType','<u4'), |
|
354 | ('nDataType','<u4'), | |
351 | ('nSizeOfDataBlock','<u4'), |
|
355 | ('nSizeOfDataBlock','<u4'), | |
352 | ('nProfilesperBlock','<u4'), |
|
356 | ('nProfilesperBlock','<u4'), | |
353 | ('nDataBlocksperFile','<u4'), |
|
357 | ('nDataBlocksperFile','<u4'), | |
354 | ('nNumWindows','<u4'), |
|
358 | ('nNumWindows','<u4'), | |
355 | ('nProcessFlags','<u4'), |
|
359 | ('nProcessFlags','<u4'), | |
356 | ('nCoherentIntegrations','<u4'), |
|
360 | ('nCoherentIntegrations','<u4'), | |
357 | ('nIncoherentIntegrations','<u4'), |
|
361 | ('nIncoherentIntegrations','<u4'), | |
358 | ('nTotalSpectra','<u4') |
|
362 | ('nTotalSpectra','<u4') | |
359 | ]) |
|
363 | ]) | |
360 | self.samplingWindow = 0 |
|
364 | self.samplingWindow = 0 | |
361 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
365 | self.structSamplingWindow = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) | |
362 | self.nHeights = 0 |
|
366 | self.nHeights = 0 | |
363 | self.firstHeight = 0 |
|
367 | self.firstHeight = 0 | |
364 | self.deltaHeight = 0 |
|
368 | self.deltaHeight = 0 | |
365 | self.samplesWin = 0 |
|
369 | self.samplesWin = 0 | |
366 | self.spectraComb = 0 |
|
370 | self.spectraComb = 0 | |
367 | self.nCode = None |
|
371 | self.nCode = None | |
368 | self.code = None |
|
372 | self.code = None | |
369 | self.nBaud = None |
|
373 | self.nBaud = None | |
370 | self.shif_fft = False |
|
374 | self.shif_fft = False | |
371 | self.flag_dc = False |
|
375 | self.flag_dc = False | |
372 | self.flag_cspc = False |
|
376 | self.flag_cspc = False | |
373 |
|
377 | |||
374 | def read(self, fp): |
|
378 | def read(self, fp): | |
375 | try: |
|
379 | try: | |
376 | header = numpy.fromfile(fp,self.struct,1) |
|
380 | header = numpy.fromfile(fp,self.struct,1) | |
377 | self.size = int(header['nSize'][0]) |
|
381 | self.size = int(header['nSize'][0]) | |
378 | self.dtype = int(header['nDataType'][0]) |
|
382 | self.dtype = int(header['nDataType'][0]) | |
379 | self.blockSize = int(header['nSizeOfDataBlock'][0]) |
|
383 | self.blockSize = int(header['nSizeOfDataBlock'][0]) | |
380 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) |
|
384 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) | |
381 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) |
|
385 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) | |
382 | self.nWindows = int(header['nNumWindows'][0]) |
|
386 | self.nWindows = int(header['nNumWindows'][0]) | |
383 | self.processFlags = header['nProcessFlags'] |
|
387 | self.processFlags = header['nProcessFlags'] | |
384 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
388 | self.nCohInt = int(header['nCoherentIntegrations'][0]) | |
385 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
389 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) | |
386 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
390 | self.totalSpectra = int(header['nTotalSpectra'][0]) | |
387 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) |
|
391 | self.samplingWindow = numpy.fromfile(fp,self.structSamplingWindow,self.nWindows) | |
388 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) |
|
392 | self.nHeights = int(numpy.sum(self.samplingWindow['nsa'])) | |
389 | self.firstHeight = float(self.samplingWindow['h0'][0]) |
|
393 | self.firstHeight = float(self.samplingWindow['h0'][0]) | |
390 | self.deltaHeight = float(self.samplingWindow['dh'][0]) |
|
394 | self.deltaHeight = float(self.samplingWindow['dh'][0]) | |
391 | self.samplesWin = self.samplingWindow['nsa'] |
|
395 | self.samplesWin = self.samplingWindow['nsa'] | |
392 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
396 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) | |
393 |
|
397 | |||
394 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
398 | if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): | |
395 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
399 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) | |
396 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
400 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) | |
397 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) |
|
401 | self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) | |
398 |
|
402 | |||
399 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
403 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): | |
400 | self.shif_fft = True |
|
404 | self.shif_fft = True | |
401 | else: |
|
405 | else: | |
402 | self.shif_fft = False |
|
406 | self.shif_fft = False | |
403 |
|
407 | |||
404 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
408 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): | |
405 | self.flag_dc = True |
|
409 | self.flag_dc = True | |
406 |
|
410 | |||
407 | nChannels = 0 |
|
411 | nChannels = 0 | |
408 | nPairs = 0 |
|
412 | nPairs = 0 | |
409 | pairList = [] |
|
413 | pairList = [] | |
410 |
|
414 | |||
411 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
415 | for i in range( 0, self.totalSpectra*2, 2 ): | |
412 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
416 | if self.spectraComb[i] == self.spectraComb[i+1]: | |
413 | nChannels = nChannels + 1 #par de canales iguales |
|
417 | nChannels = nChannels + 1 #par de canales iguales | |
414 | else: |
|
418 | else: | |
415 | nPairs = nPairs + 1 #par de canales diferentes |
|
419 | nPairs = nPairs + 1 #par de canales diferentes | |
416 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
420 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) | |
417 |
|
421 | |||
418 | self.flag_cspc = False |
|
422 | self.flag_cspc = False | |
419 | if nPairs > 0: |
|
423 | if nPairs > 0: | |
420 | self.flag_cspc = True |
|
424 | self.flag_cspc = True | |
421 |
|
425 | |||
422 | except Exception, e: |
|
426 | except Exception, e: | |
423 | print "ProcessingHeader: " + e |
|
427 | print "ProcessingHeader: " + e | |
424 | return 0 |
|
428 | return 0 | |
425 |
|
429 | |||
426 | return 1 |
|
430 | return 1 | |
427 |
|
431 | |||
428 | def write(self, fp): |
|
432 | def write(self, fp): | |
429 | headerTuple = (self.size, |
|
433 | headerTuple = (self.size, | |
430 | self.dtype, |
|
434 | self.dtype, | |
431 | self.blockSize, |
|
435 | self.blockSize, | |
432 | self.profilesPerBlock, |
|
436 | self.profilesPerBlock, | |
433 | self.dataBlocksPerFile, |
|
437 | self.dataBlocksPerFile, | |
434 | self.nWindows, |
|
438 | self.nWindows, | |
435 | self.processFlags, |
|
439 | self.processFlags, | |
436 | self.nCohInt, |
|
440 | self.nCohInt, | |
437 | self.nIncohInt, |
|
441 | self.nIncohInt, | |
438 | self.totalSpectra) |
|
442 | self.totalSpectra) | |
439 |
|
443 | |||
440 | header = numpy.array(headerTuple,self.struct) |
|
444 | header = numpy.array(headerTuple,self.struct) | |
441 | header.tofile(fp) |
|
445 | header.tofile(fp) | |
442 |
|
446 | |||
443 | if self.nWindows != 0: |
|
447 | if self.nWindows != 0: | |
444 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
448 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) | |
445 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) |
|
449 | samplingWindow = numpy.array(sampleWindowTuple,self.structSamplingWindow) | |
446 | samplingWindow.tofile(fp) |
|
450 | samplingWindow.tofile(fp) | |
447 |
|
451 | |||
448 |
|
452 | |||
449 | if self.totalSpectra != 0: |
|
453 | if self.totalSpectra != 0: | |
450 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
454 | spectraComb = numpy.array([],numpy.dtype('u1')) | |
451 | spectraComb = self.spectraComb |
|
455 | spectraComb = self.spectraComb | |
452 | spectraComb.tofile(fp) |
|
456 | spectraComb.tofile(fp) | |
453 |
|
457 | |||
454 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
458 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: | |
455 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
459 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba | |
456 | # nCode.tofile(fp) |
|
460 | # nCode.tofile(fp) | |
457 | # |
|
461 | # | |
458 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) |
|
462 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) | |
459 | # nBaud.tofile(fp) |
|
463 | # nBaud.tofile(fp) | |
460 | # |
|
464 | # | |
461 | # code = self.code.reshape(self.nCode*self.nBaud) |
|
465 | # code = self.code.reshape(self.nCode*self.nBaud) | |
462 | # code = code.astype(numpy.dtype('<f4')) |
|
466 | # code = code.astype(numpy.dtype('<f4')) | |
463 | # code.tofile(fp) |
|
467 | # code.tofile(fp) | |
464 |
|
468 | |||
465 | return 1 |
|
469 | return 1 | |
466 |
|
470 | |||
467 | class RCfunction: |
|
471 | class RCfunction: | |
468 | NONE=0 |
|
472 | NONE=0 | |
469 | FLIP=1 |
|
473 | FLIP=1 | |
470 | CODE=2 |
|
474 | CODE=2 | |
471 | SAMPLING=3 |
|
475 | SAMPLING=3 | |
472 | LIN6DIV256=4 |
|
476 | LIN6DIV256=4 | |
473 | SYNCHRO=5 |
|
477 | SYNCHRO=5 | |
474 |
|
478 | |||
475 | class nCodeType: |
|
479 | class nCodeType: | |
476 | NONE=0 |
|
480 | NONE=0 | |
477 | USERDEFINE=1 |
|
481 | USERDEFINE=1 | |
478 | BARKER2=2 |
|
482 | BARKER2=2 | |
479 | BARKER3=3 |
|
483 | BARKER3=3 | |
480 | BARKER4=4 |
|
484 | BARKER4=4 | |
481 | BARKER5=5 |
|
485 | BARKER5=5 | |
482 | BARKER7=6 |
|
486 | BARKER7=6 | |
483 | BARKER11=7 |
|
487 | BARKER11=7 | |
484 | BARKER13=8 |
|
488 | BARKER13=8 | |
485 | AC128=9 |
|
489 | AC128=9 | |
486 | COMPLEMENTARYCODE2=10 |
|
490 | COMPLEMENTARYCODE2=10 | |
487 | COMPLEMENTARYCODE4=11 |
|
491 | COMPLEMENTARYCODE4=11 | |
488 | COMPLEMENTARYCODE8=12 |
|
492 | COMPLEMENTARYCODE8=12 | |
489 | COMPLEMENTARYCODE16=13 |
|
493 | COMPLEMENTARYCODE16=13 | |
490 | COMPLEMENTARYCODE32=14 |
|
494 | COMPLEMENTARYCODE32=14 | |
491 | COMPLEMENTARYCODE64=15 |
|
495 | COMPLEMENTARYCODE64=15 | |
492 | COMPLEMENTARYCODE128=16 |
|
496 | COMPLEMENTARYCODE128=16 | |
493 | CODE_BINARY28=17 |
|
497 | CODE_BINARY28=17 | |
494 |
|
498 | |||
495 | class PROCFLAG: |
|
499 | class PROCFLAG: | |
496 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
500 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) | |
497 | DECODE_DATA = numpy.uint32(0x00000002) |
|
501 | DECODE_DATA = numpy.uint32(0x00000002) | |
498 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
502 | SPECTRA_CALC = numpy.uint32(0x00000004) | |
499 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
503 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) | |
500 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
504 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) | |
501 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
505 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) | |
502 |
|
506 | |||
503 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
507 | DATATYPE_CHAR = numpy.uint32(0x00000040) | |
504 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
508 | DATATYPE_SHORT = numpy.uint32(0x00000080) | |
505 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
509 | DATATYPE_LONG = numpy.uint32(0x00000100) | |
506 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
510 | DATATYPE_INT64 = numpy.uint32(0x00000200) | |
507 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
511 | DATATYPE_FLOAT = numpy.uint32(0x00000400) | |
508 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
512 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) | |
509 |
|
513 | |||
510 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
514 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) | |
511 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
515 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) | |
512 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
516 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) | |
513 |
|
517 | |||
514 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
518 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) | |
515 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
519 | DEFLIP_DATA = numpy.uint32(0x00010000) | |
516 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
520 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) | |
517 |
|
521 | |||
518 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
522 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) | |
519 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
523 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) | |
520 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
524 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) | |
521 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
525 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) | |
522 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
526 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) | |
523 |
|
527 | |||
524 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
528 | EXP_NAME_ESP = numpy.uint32(0x00200000) | |
525 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
529 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) | |
526 |
|
530 | |||
527 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
531 | OPERATION_MASK = numpy.uint32(0x0000003F) | |
528 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
532 | DATATYPE_MASK = numpy.uint32(0x00000FC0) | |
529 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
533 | DATAARRANGE_MASK = numpy.uint32(0x00007000) | |
530 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
|
534 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) |
@@ -1,1621 +1,1627 | |||||
1 | ''' |
|
1 | ''' | |
2 |
|
2 | |||
3 | $Author: dsuarez $ |
|
3 | $Author: dsuarez $ | |
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z dsuarez $ | |
5 | ''' |
|
5 | ''' | |
6 | import os |
|
6 | import os | |
7 | import numpy |
|
7 | import numpy | |
8 | import datetime |
|
8 | import datetime | |
9 | import time |
|
9 | import time | |
10 |
|
10 | |||
11 | from jrodata import * |
|
11 | from jrodata import * | |
12 | from jrodataIO import * |
|
12 | from jrodataIO import * | |
13 | from jroplot import * |
|
13 | from jroplot import * | |
14 |
|
14 | |||
15 | try: |
|
15 | try: | |
16 | import cfunctions |
|
16 | import cfunctions | |
17 | except: |
|
17 | except: | |
18 | pass |
|
18 | pass | |
19 |
|
19 | |||
20 | class ProcessingUnit: |
|
20 | class ProcessingUnit: | |
21 |
|
21 | |||
22 | """ |
|
22 | """ | |
23 | Esta es la clase base para el procesamiento de datos. |
|
23 | Esta es la clase base para el procesamiento de datos. | |
24 |
|
24 | |||
25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
25 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: | |
26 | - Metodos internos (callMethod) |
|
26 | - Metodos internos (callMethod) | |
27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
27 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos | |
28 | tienen que ser agreagados con el metodo "add". |
|
28 | tienen que ser agreagados con el metodo "add". | |
29 |
|
29 | |||
30 | """ |
|
30 | """ | |
31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
31 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
32 | dataIn = None |
|
32 | dataIn = None | |
33 |
|
33 | |||
34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
34 | # objeto de datos de entrada (Voltage, Spectra o Correlation) | |
35 | dataOut = None |
|
35 | dataOut = None | |
36 |
|
36 | |||
37 |
|
37 | |||
38 | objectDict = None |
|
38 | objectDict = None | |
39 |
|
39 | |||
40 | def __init__(self): |
|
40 | def __init__(self): | |
41 |
|
41 | |||
42 | self.objectDict = {} |
|
42 | self.objectDict = {} | |
43 |
|
43 | |||
44 | def init(self): |
|
44 | def init(self): | |
45 |
|
45 | |||
46 | raise ValueError, "Not implemented" |
|
46 | raise ValueError, "Not implemented" | |
47 |
|
47 | |||
48 | def addOperation(self, object, objId): |
|
48 | def addOperation(self, object, objId): | |
49 |
|
49 | |||
50 | """ |
|
50 | """ | |
51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el |
|
51 | Agrega el objeto "object" a la lista de objetos "self.objectList" y retorna el | |
52 | identificador asociado a este objeto. |
|
52 | identificador asociado a este objeto. | |
53 |
|
53 | |||
54 | Input: |
|
54 | Input: | |
55 |
|
55 | |||
56 | object : objeto de la clase "Operation" |
|
56 | object : objeto de la clase "Operation" | |
57 |
|
57 | |||
58 | Return: |
|
58 | Return: | |
59 |
|
59 | |||
60 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
60 | objId : identificador del objeto, necesario para ejecutar la operacion | |
61 | """ |
|
61 | """ | |
62 |
|
62 | |||
63 | self.objectDict[objId] = object |
|
63 | self.objectDict[objId] = object | |
64 |
|
64 | |||
65 | return objId |
|
65 | return objId | |
66 |
|
66 | |||
67 | def operation(self, **kwargs): |
|
67 | def operation(self, **kwargs): | |
68 |
|
68 | |||
69 | """ |
|
69 | """ | |
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
70 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los | |
71 | atributos del objeto dataOut |
|
71 | atributos del objeto dataOut | |
72 |
|
72 | |||
73 | Input: |
|
73 | Input: | |
74 |
|
74 | |||
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
75 | **kwargs : Diccionario de argumentos de la funcion a ejecutar | |
76 | """ |
|
76 | """ | |
77 |
|
77 | |||
78 | raise ValueError, "ImplementedError" |
|
78 | raise ValueError, "ImplementedError" | |
79 |
|
79 | |||
80 | def callMethod(self, name, **kwargs): |
|
80 | def callMethod(self, name, **kwargs): | |
81 |
|
81 | |||
82 | """ |
|
82 | """ | |
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
83 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. | |
84 |
|
84 | |||
85 | Input: |
|
85 | Input: | |
86 | name : nombre del metodo a ejecutar |
|
86 | name : nombre del metodo a ejecutar | |
87 |
|
87 | |||
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
88 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
89 |
|
89 | |||
90 | """ |
|
90 | """ | |
91 | if name != 'run': |
|
91 | if name != 'run': | |
92 |
|
92 | |||
93 | if name == 'init' and self.dataIn.isEmpty(): |
|
93 | if name == 'init' and self.dataIn.isEmpty(): | |
94 | self.dataOut.flagNoData = True |
|
94 | self.dataOut.flagNoData = True | |
95 | return False |
|
95 | return False | |
96 |
|
96 | |||
97 | if name != 'init' and self.dataOut.isEmpty(): |
|
97 | if name != 'init' and self.dataOut.isEmpty(): | |
98 | return False |
|
98 | return False | |
99 |
|
99 | |||
100 | methodToCall = getattr(self, name) |
|
100 | methodToCall = getattr(self, name) | |
101 |
|
101 | |||
102 | methodToCall(**kwargs) |
|
102 | methodToCall(**kwargs) | |
103 |
|
103 | |||
104 | if name != 'run': |
|
104 | if name != 'run': | |
105 | return True |
|
105 | return True | |
106 |
|
106 | |||
107 | if self.dataOut.isEmpty(): |
|
107 | if self.dataOut.isEmpty(): | |
108 | return False |
|
108 | return False | |
109 |
|
109 | |||
110 | return True |
|
110 | return True | |
111 |
|
111 | |||
112 | def callObject(self, objId, **kwargs): |
|
112 | def callObject(self, objId, **kwargs): | |
113 |
|
113 | |||
114 | """ |
|
114 | """ | |
115 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
115 | Ejecuta la operacion asociada al identificador del objeto "objId" | |
116 |
|
116 | |||
117 | Input: |
|
117 | Input: | |
118 |
|
118 | |||
119 | objId : identificador del objeto a ejecutar |
|
119 | objId : identificador del objeto a ejecutar | |
120 |
|
120 | |||
121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
121 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. | |
122 |
|
122 | |||
123 | Return: |
|
123 | Return: | |
124 |
|
124 | |||
125 | None |
|
125 | None | |
126 | """ |
|
126 | """ | |
127 |
|
127 | |||
128 | if self.dataOut.isEmpty(): |
|
128 | if self.dataOut.isEmpty(): | |
129 | return False |
|
129 | return False | |
130 |
|
130 | |||
131 | object = self.objectDict[objId] |
|
131 | object = self.objectDict[objId] | |
132 |
|
132 | |||
133 | object.run(self.dataOut, **kwargs) |
|
133 | object.run(self.dataOut, **kwargs) | |
134 |
|
134 | |||
135 | return True |
|
135 | return True | |
136 |
|
136 | |||
137 | def call(self, operationConf, **kwargs): |
|
137 | def call(self, operationConf, **kwargs): | |
138 |
|
138 | |||
139 | """ |
|
139 | """ | |
140 | Return True si ejecuta la operacion "operationConf.name" con los |
|
140 | Return True si ejecuta la operacion "operationConf.name" con los | |
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. |
|
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. | |
142 | La operacion puede ser de dos tipos: |
|
142 | La operacion puede ser de dos tipos: | |
143 |
|
143 | |||
144 | 1. Un metodo propio de esta clase: |
|
144 | 1. Un metodo propio de esta clase: | |
145 |
|
145 | |||
146 | operation.type = "self" |
|
146 | operation.type = "self" | |
147 |
|
147 | |||
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: |
|
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
149 | operation.type = "other". |
|
149 | operation.type = "other". | |
150 |
|
150 | |||
151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: |
|
151 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
152 | "addOperation" e identificado con el operation.id |
|
152 | "addOperation" e identificado con el operation.id | |
153 |
|
153 | |||
154 |
|
154 | |||
155 | con el id de la operacion. |
|
155 | con el id de la operacion. | |
156 |
|
156 | |||
157 | Input: |
|
157 | Input: | |
158 |
|
158 | |||
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. |
|
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
160 |
|
160 | |||
161 | """ |
|
161 | """ | |
162 |
|
162 | |||
163 | if operationConf.type == 'self': |
|
163 | if operationConf.type == 'self': | |
164 | sts = self.callMethod(operationConf.name, **kwargs) |
|
164 | sts = self.callMethod(operationConf.name, **kwargs) | |
165 |
|
165 | |||
166 | if operationConf.type == 'other': |
|
166 | if operationConf.type == 'other': | |
167 | sts = self.callObject(operationConf.id, **kwargs) |
|
167 | sts = self.callObject(operationConf.id, **kwargs) | |
168 |
|
168 | |||
169 | return sts |
|
169 | return sts | |
170 |
|
170 | |||
171 | def setInput(self, dataIn): |
|
171 | def setInput(self, dataIn): | |
172 |
|
172 | |||
173 | self.dataIn = dataIn |
|
173 | self.dataIn = dataIn | |
174 |
|
174 | |||
175 | def getOutput(self): |
|
175 | def getOutput(self): | |
176 |
|
176 | |||
177 | return self.dataOut |
|
177 | return self.dataOut | |
178 |
|
178 | |||
179 | class Operation(): |
|
179 | class Operation(): | |
180 |
|
180 | |||
181 | """ |
|
181 | """ | |
182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
182 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit | |
183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
183 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de | |
184 | acumulacion dentro de esta clase |
|
184 | acumulacion dentro de esta clase | |
185 |
|
185 | |||
186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
186 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) | |
187 |
|
187 | |||
188 | """ |
|
188 | """ | |
189 |
|
189 | |||
190 | __buffer = None |
|
190 | __buffer = None | |
191 | __isConfig = False |
|
191 | __isConfig = False | |
192 |
|
192 | |||
193 | def __init__(self): |
|
193 | def __init__(self): | |
194 |
|
194 | |||
195 | pass |
|
195 | pass | |
196 |
|
196 | |||
197 | def run(self, dataIn, **kwargs): |
|
197 | def run(self, dataIn, **kwargs): | |
198 |
|
198 | |||
199 | """ |
|
199 | """ | |
200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. |
|
200 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los atributos del objeto dataIn. | |
201 |
|
201 | |||
202 | Input: |
|
202 | Input: | |
203 |
|
203 | |||
204 | dataIn : objeto del tipo JROData |
|
204 | dataIn : objeto del tipo JROData | |
205 |
|
205 | |||
206 | Return: |
|
206 | Return: | |
207 |
|
207 | |||
208 | None |
|
208 | None | |
209 |
|
209 | |||
210 | Affected: |
|
210 | Affected: | |
211 | __buffer : buffer de recepcion de datos. |
|
211 | __buffer : buffer de recepcion de datos. | |
212 |
|
212 | |||
213 | """ |
|
213 | """ | |
214 |
|
214 | |||
215 | raise ValueError, "ImplementedError" |
|
215 | raise ValueError, "ImplementedError" | |
216 |
|
216 | |||
217 | class VoltageProc(ProcessingUnit): |
|
217 | class VoltageProc(ProcessingUnit): | |
218 |
|
218 | |||
219 |
|
219 | |||
220 | def __init__(self): |
|
220 | def __init__(self): | |
221 |
|
221 | |||
222 | self.objectDict = {} |
|
222 | self.objectDict = {} | |
223 | self.dataOut = Voltage() |
|
223 | self.dataOut = Voltage() | |
224 | self.flip = 1 |
|
224 | self.flip = 1 | |
225 |
|
225 | |||
226 | def init(self): |
|
226 | def init(self): | |
227 |
|
227 | |||
228 | self.dataOut.copy(self.dataIn) |
|
228 | self.dataOut.copy(self.dataIn) | |
229 | # No necesita copiar en cada init() los atributos de dataIn |
|
229 | # No necesita copiar en cada init() los atributos de dataIn | |
230 | # la copia deberia hacerse por cada nuevo bloque de datos |
|
230 | # la copia deberia hacerse por cada nuevo bloque de datos | |
231 |
|
231 | |||
232 | def selectChannels(self, channelList): |
|
232 | def selectChannels(self, channelList): | |
233 |
|
233 | |||
234 | channelIndexList = [] |
|
234 | channelIndexList = [] | |
235 |
|
235 | |||
236 | for channel in channelList: |
|
236 | for channel in channelList: | |
237 | index = self.dataOut.channelList.index(channel) |
|
237 | index = self.dataOut.channelList.index(channel) | |
238 | channelIndexList.append(index) |
|
238 | channelIndexList.append(index) | |
239 |
|
239 | |||
240 | self.selectChannelsByIndex(channelIndexList) |
|
240 | self.selectChannelsByIndex(channelIndexList) | |
241 |
|
241 | |||
242 | def selectChannelsByIndex(self, channelIndexList): |
|
242 | def selectChannelsByIndex(self, channelIndexList): | |
243 | """ |
|
243 | """ | |
244 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
244 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
245 |
|
245 | |||
246 | Input: |
|
246 | Input: | |
247 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
247 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
248 |
|
248 | |||
249 | Affected: |
|
249 | Affected: | |
250 | self.dataOut.data |
|
250 | self.dataOut.data | |
251 | self.dataOut.channelIndexList |
|
251 | self.dataOut.channelIndexList | |
252 | self.dataOut.nChannels |
|
252 | self.dataOut.nChannels | |
253 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
253 | self.dataOut.m_ProcessingHeader.totalSpectra | |
254 | self.dataOut.systemHeaderObj.numChannels |
|
254 | self.dataOut.systemHeaderObj.numChannels | |
255 | self.dataOut.m_ProcessingHeader.blockSize |
|
255 | self.dataOut.m_ProcessingHeader.blockSize | |
256 |
|
256 | |||
257 | Return: |
|
257 | Return: | |
258 | None |
|
258 | None | |
259 | """ |
|
259 | """ | |
260 |
|
260 | |||
261 | for channelIndex in channelIndexList: |
|
261 | for channelIndex in channelIndexList: | |
262 | if channelIndex not in self.dataOut.channelIndexList: |
|
262 | if channelIndex not in self.dataOut.channelIndexList: | |
263 | print channelIndexList |
|
263 | print channelIndexList | |
264 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
264 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
265 |
|
265 | |||
266 | nChannels = len(channelIndexList) |
|
266 | nChannels = len(channelIndexList) | |
267 |
|
267 | |||
268 | data = self.dataOut.data[channelIndexList,:] |
|
268 | data = self.dataOut.data[channelIndexList,:] | |
269 |
|
269 | |||
270 | self.dataOut.data = data |
|
270 | self.dataOut.data = data | |
271 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
271 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
272 | # self.dataOut.nChannels = nChannels |
|
272 | # self.dataOut.nChannels = nChannels | |
273 |
|
273 | |||
274 | return 1 |
|
274 | return 1 | |
275 |
|
275 | |||
276 | def selectHeights(self, minHei, maxHei): |
|
276 | def selectHeights(self, minHei, maxHei): | |
277 | """ |
|
277 | """ | |
278 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
278 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
279 | minHei <= height <= maxHei |
|
279 | minHei <= height <= maxHei | |
280 |
|
280 | |||
281 | Input: |
|
281 | Input: | |
282 | minHei : valor minimo de altura a considerar |
|
282 | minHei : valor minimo de altura a considerar | |
283 | maxHei : valor maximo de altura a considerar |
|
283 | maxHei : valor maximo de altura a considerar | |
284 |
|
284 | |||
285 | Affected: |
|
285 | Affected: | |
286 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
286 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
287 |
|
287 | |||
288 | Return: |
|
288 | Return: | |
289 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
289 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
290 | """ |
|
290 | """ | |
291 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
291 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
292 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
292 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
293 |
|
293 | |||
294 | if (maxHei > self.dataOut.heightList[-1]): |
|
294 | if (maxHei > self.dataOut.heightList[-1]): | |
295 | maxHei = self.dataOut.heightList[-1] |
|
295 | maxHei = self.dataOut.heightList[-1] | |
296 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
296 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
297 |
|
297 | |||
298 | minIndex = 0 |
|
298 | minIndex = 0 | |
299 | maxIndex = 0 |
|
299 | maxIndex = 0 | |
300 | heights = self.dataOut.heightList |
|
300 | heights = self.dataOut.heightList | |
301 |
|
301 | |||
302 | inda = numpy.where(heights >= minHei) |
|
302 | inda = numpy.where(heights >= minHei) | |
303 | indb = numpy.where(heights <= maxHei) |
|
303 | indb = numpy.where(heights <= maxHei) | |
304 |
|
304 | |||
305 | try: |
|
305 | try: | |
306 | minIndex = inda[0][0] |
|
306 | minIndex = inda[0][0] | |
307 | except: |
|
307 | except: | |
308 | minIndex = 0 |
|
308 | minIndex = 0 | |
309 |
|
309 | |||
310 | try: |
|
310 | try: | |
311 | maxIndex = indb[0][-1] |
|
311 | maxIndex = indb[0][-1] | |
312 | except: |
|
312 | except: | |
313 | maxIndex = len(heights) |
|
313 | maxIndex = len(heights) | |
314 |
|
314 | |||
315 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
315 | self.selectHeightsByIndex(minIndex, maxIndex) | |
316 |
|
316 | |||
317 | return 1 |
|
317 | return 1 | |
318 |
|
318 | |||
319 |
|
319 | |||
320 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
320 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
321 | """ |
|
321 | """ | |
322 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
322 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
323 | minIndex <= index <= maxIndex |
|
323 | minIndex <= index <= maxIndex | |
324 |
|
324 | |||
325 | Input: |
|
325 | Input: | |
326 | minIndex : valor de indice minimo de altura a considerar |
|
326 | minIndex : valor de indice minimo de altura a considerar | |
327 | maxIndex : valor de indice maximo de altura a considerar |
|
327 | maxIndex : valor de indice maximo de altura a considerar | |
328 |
|
328 | |||
329 | Affected: |
|
329 | Affected: | |
330 | self.dataOut.data |
|
330 | self.dataOut.data | |
331 | self.dataOut.heightList |
|
331 | self.dataOut.heightList | |
332 |
|
332 | |||
333 | Return: |
|
333 | Return: | |
334 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
334 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
335 | """ |
|
335 | """ | |
336 |
|
336 | |||
337 | if (minIndex < 0) or (minIndex > maxIndex): |
|
337 | if (minIndex < 0) or (minIndex > maxIndex): | |
338 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
338 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
339 |
|
339 | |||
340 | if (maxIndex >= self.dataOut.nHeights): |
|
340 | if (maxIndex >= self.dataOut.nHeights): | |
341 | maxIndex = self.dataOut.nHeights-1 |
|
341 | maxIndex = self.dataOut.nHeights-1 | |
342 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
342 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
343 |
|
343 | |||
344 | nHeights = maxIndex - minIndex + 1 |
|
344 | nHeights = maxIndex - minIndex + 1 | |
345 |
|
345 | |||
346 | #voltage |
|
346 | #voltage | |
347 | data = self.dataOut.data[:,minIndex:maxIndex+1] |
|
347 | data = self.dataOut.data[:,minIndex:maxIndex+1] | |
348 |
|
348 | |||
349 | firstHeight = self.dataOut.heightList[minIndex] |
|
349 | firstHeight = self.dataOut.heightList[minIndex] | |
350 |
|
350 | |||
351 | self.dataOut.data = data |
|
351 | self.dataOut.data = data | |
352 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
352 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
353 |
|
353 | |||
354 | return 1 |
|
354 | return 1 | |
355 |
|
355 | |||
356 |
|
356 | |||
357 | def filterByHeights(self, window): |
|
357 | def filterByHeights(self, window): | |
358 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
358 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] | |
359 |
|
359 | |||
360 | if window == None: |
|
360 | if window == None: | |
361 | window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight |
|
361 | window = self.dataOut.radarControllerHeaderObj.txA / deltaHeight | |
362 |
|
362 | |||
363 | newdelta = deltaHeight * window |
|
363 | newdelta = deltaHeight * window | |
364 | r = self.dataOut.data.shape[1] % window |
|
364 | r = self.dataOut.data.shape[1] % window | |
365 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] |
|
365 | buffer = self.dataOut.data[:,0:self.dataOut.data.shape[1]-r] | |
366 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) |
|
366 | buffer = buffer.reshape(self.dataOut.data.shape[0],self.dataOut.data.shape[1]/window,window) | |
367 | buffer = numpy.sum(buffer,2) |
|
367 | buffer = numpy.sum(buffer,2) | |
368 | self.dataOut.data = buffer |
|
368 | self.dataOut.data = buffer | |
369 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window-newdelta,newdelta) |
|
369 | self.dataOut.heightList = numpy.arange(self.dataOut.heightList[0],newdelta*self.dataOut.nHeights/window-newdelta,newdelta) | |
370 | self.dataOut.windowOfFilter = window |
|
370 | self.dataOut.windowOfFilter = window | |
371 |
|
371 | |||
372 | def deFlip(self): |
|
372 | def deFlip(self): | |
373 | self.dataOut.data *= self.flip |
|
373 | self.dataOut.data *= self.flip | |
374 | self.flip *= -1. |
|
374 | self.flip *= -1. | |
375 |
|
375 | |||
376 |
|
376 | |||
377 | class CohInt(Operation): |
|
377 | class CohInt(Operation): | |
378 |
|
378 | |||
379 | __isConfig = False |
|
379 | __isConfig = False | |
380 |
|
380 | |||
381 | __profIndex = 0 |
|
381 | __profIndex = 0 | |
382 | __withOverapping = False |
|
382 | __withOverapping = False | |
383 |
|
383 | |||
384 | __byTime = False |
|
384 | __byTime = False | |
385 | __initime = None |
|
385 | __initime = None | |
386 | __lastdatatime = None |
|
386 | __lastdatatime = None | |
387 | __integrationtime = None |
|
387 | __integrationtime = None | |
388 |
|
388 | |||
389 | __buffer = None |
|
389 | __buffer = None | |
390 |
|
390 | |||
391 | __dataReady = False |
|
391 | __dataReady = False | |
392 |
|
392 | |||
393 | n = None |
|
393 | n = None | |
394 |
|
394 | |||
395 |
|
395 | |||
396 | def __init__(self): |
|
396 | def __init__(self): | |
397 |
|
397 | |||
398 | self.__isConfig = False |
|
398 | self.__isConfig = False | |
399 |
|
399 | |||
400 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
400 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
401 | """ |
|
401 | """ | |
402 | Set the parameters of the integration class. |
|
402 | Set the parameters of the integration class. | |
403 |
|
403 | |||
404 | Inputs: |
|
404 | Inputs: | |
405 |
|
405 | |||
406 | n : Number of coherent integrations |
|
406 | n : Number of coherent integrations | |
407 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
407 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
408 | overlapping : |
|
408 | overlapping : | |
409 |
|
409 | |||
410 | """ |
|
410 | """ | |
411 |
|
411 | |||
412 | self.__initime = None |
|
412 | self.__initime = None | |
413 | self.__lastdatatime = 0 |
|
413 | self.__lastdatatime = 0 | |
414 | self.__buffer = None |
|
414 | self.__buffer = None | |
415 | self.__dataReady = False |
|
415 | self.__dataReady = False | |
416 |
|
416 | |||
417 |
|
417 | |||
418 | if n == None and timeInterval == None: |
|
418 | if n == None and timeInterval == None: | |
419 | raise ValueError, "n or timeInterval should be specified ..." |
|
419 | raise ValueError, "n or timeInterval should be specified ..." | |
420 |
|
420 | |||
421 | if n != None: |
|
421 | if n != None: | |
422 | self.n = n |
|
422 | self.n = n | |
423 | self.__byTime = False |
|
423 | self.__byTime = False | |
424 | else: |
|
424 | else: | |
425 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
425 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
426 | self.n = 9999 |
|
426 | self.n = 9999 | |
427 | self.__byTime = True |
|
427 | self.__byTime = True | |
428 |
|
428 | |||
429 | if overlapping: |
|
429 | if overlapping: | |
430 | self.__withOverapping = True |
|
430 | self.__withOverapping = True | |
431 | self.__buffer = None |
|
431 | self.__buffer = None | |
432 | else: |
|
432 | else: | |
433 | self.__withOverapping = False |
|
433 | self.__withOverapping = False | |
434 | self.__buffer = 0 |
|
434 | self.__buffer = 0 | |
435 |
|
435 | |||
436 | self.__profIndex = 0 |
|
436 | self.__profIndex = 0 | |
437 |
|
437 | |||
438 | def putData(self, data): |
|
438 | def putData(self, data): | |
439 |
|
439 | |||
440 | """ |
|
440 | """ | |
441 | Add a profile to the __buffer and increase in one the __profileIndex |
|
441 | Add a profile to the __buffer and increase in one the __profileIndex | |
442 |
|
442 | |||
443 | """ |
|
443 | """ | |
444 |
|
444 | |||
445 | if not self.__withOverapping: |
|
445 | if not self.__withOverapping: | |
446 | self.__buffer += data.copy() |
|
446 | self.__buffer += data.copy() | |
447 | self.__profIndex += 1 |
|
447 | self.__profIndex += 1 | |
448 | return |
|
448 | return | |
449 |
|
449 | |||
450 | #Overlapping data |
|
450 | #Overlapping data | |
451 | nChannels, nHeis = data.shape |
|
451 | nChannels, nHeis = data.shape | |
452 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
452 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
453 |
|
453 | |||
454 | #If the buffer is empty then it takes the data value |
|
454 | #If the buffer is empty then it takes the data value | |
455 | if self.__buffer == None: |
|
455 | if self.__buffer == None: | |
456 | self.__buffer = data |
|
456 | self.__buffer = data | |
457 | self.__profIndex += 1 |
|
457 | self.__profIndex += 1 | |
458 | return |
|
458 | return | |
459 |
|
459 | |||
460 | #If the buffer length is lower than n then stakcing the data value |
|
460 | #If the buffer length is lower than n then stakcing the data value | |
461 | if self.__profIndex < self.n: |
|
461 | if self.__profIndex < self.n: | |
462 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
462 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
463 | self.__profIndex += 1 |
|
463 | self.__profIndex += 1 | |
464 | return |
|
464 | return | |
465 |
|
465 | |||
466 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
466 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
467 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
467 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
468 | self.__buffer[self.n-1] = data |
|
468 | self.__buffer[self.n-1] = data | |
469 | self.__profIndex = self.n |
|
469 | self.__profIndex = self.n | |
470 | return |
|
470 | return | |
471 |
|
471 | |||
472 |
|
472 | |||
473 | def pushData(self): |
|
473 | def pushData(self): | |
474 | """ |
|
474 | """ | |
475 | Return the sum of the last profiles and the profiles used in the sum. |
|
475 | Return the sum of the last profiles and the profiles used in the sum. | |
476 |
|
476 | |||
477 | Affected: |
|
477 | Affected: | |
478 |
|
478 | |||
479 | self.__profileIndex |
|
479 | self.__profileIndex | |
480 |
|
480 | |||
481 | """ |
|
481 | """ | |
482 |
|
482 | |||
483 | if not self.__withOverapping: |
|
483 | if not self.__withOverapping: | |
484 | data = self.__buffer |
|
484 | data = self.__buffer | |
485 | n = self.__profIndex |
|
485 | n = self.__profIndex | |
486 |
|
486 | |||
487 | self.__buffer = 0 |
|
487 | self.__buffer = 0 | |
488 | self.__profIndex = 0 |
|
488 | self.__profIndex = 0 | |
489 |
|
489 | |||
490 | return data, n |
|
490 | return data, n | |
491 |
|
491 | |||
492 | #Integration with Overlapping |
|
492 | #Integration with Overlapping | |
493 | data = numpy.sum(self.__buffer, axis=0) |
|
493 | data = numpy.sum(self.__buffer, axis=0) | |
494 | n = self.__profIndex |
|
494 | n = self.__profIndex | |
495 |
|
495 | |||
496 | return data, n |
|
496 | return data, n | |
497 |
|
497 | |||
498 | def byProfiles(self, data): |
|
498 | def byProfiles(self, data): | |
499 |
|
499 | |||
500 | self.__dataReady = False |
|
500 | self.__dataReady = False | |
501 | avgdata = None |
|
501 | avgdata = None | |
502 | n = None |
|
502 | n = None | |
503 |
|
503 | |||
504 | self.putData(data) |
|
504 | self.putData(data) | |
505 |
|
505 | |||
506 | if self.__profIndex == self.n: |
|
506 | if self.__profIndex == self.n: | |
507 |
|
507 | |||
508 | avgdata, n = self.pushData() |
|
508 | avgdata, n = self.pushData() | |
509 | self.__dataReady = True |
|
509 | self.__dataReady = True | |
510 |
|
510 | |||
511 | return avgdata |
|
511 | return avgdata | |
512 |
|
512 | |||
513 | def byTime(self, data, datatime): |
|
513 | def byTime(self, data, datatime): | |
514 |
|
514 | |||
515 | self.__dataReady = False |
|
515 | self.__dataReady = False | |
516 | avgdata = None |
|
516 | avgdata = None | |
517 | n = None |
|
517 | n = None | |
518 |
|
518 | |||
519 | self.putData(data) |
|
519 | self.putData(data) | |
520 |
|
520 | |||
521 | if (datatime - self.__initime) >= self.__integrationtime: |
|
521 | if (datatime - self.__initime) >= self.__integrationtime: | |
522 | avgdata, n = self.pushData() |
|
522 | avgdata, n = self.pushData() | |
523 | self.n = n |
|
523 | self.n = n | |
524 | self.__dataReady = True |
|
524 | self.__dataReady = True | |
525 |
|
525 | |||
526 | return avgdata |
|
526 | return avgdata | |
527 |
|
527 | |||
528 | def integrate(self, data, datatime=None): |
|
528 | def integrate(self, data, datatime=None): | |
529 |
|
529 | |||
530 | if self.__initime == None: |
|
530 | if self.__initime == None: | |
531 | self.__initime = datatime |
|
531 | self.__initime = datatime | |
532 |
|
532 | |||
533 | if self.__byTime: |
|
533 | if self.__byTime: | |
534 | avgdata = self.byTime(data, datatime) |
|
534 | avgdata = self.byTime(data, datatime) | |
535 | else: |
|
535 | else: | |
536 | avgdata = self.byProfiles(data) |
|
536 | avgdata = self.byProfiles(data) | |
537 |
|
537 | |||
538 |
|
538 | |||
539 | self.__lastdatatime = datatime |
|
539 | self.__lastdatatime = datatime | |
540 |
|
540 | |||
541 | if avgdata == None: |
|
541 | if avgdata == None: | |
542 | return None, None |
|
542 | return None, None | |
543 |
|
543 | |||
544 | avgdatatime = self.__initime |
|
544 | avgdatatime = self.__initime | |
545 |
|
545 | |||
546 | deltatime = datatime -self.__lastdatatime |
|
546 | deltatime = datatime -self.__lastdatatime | |
547 |
|
547 | |||
548 | if not self.__withOverapping: |
|
548 | if not self.__withOverapping: | |
549 | self.__initime = datatime |
|
549 | self.__initime = datatime | |
550 | else: |
|
550 | else: | |
551 | self.__initime += deltatime |
|
551 | self.__initime += deltatime | |
552 |
|
552 | |||
553 | return avgdata, avgdatatime |
|
553 | return avgdata, avgdatatime | |
554 |
|
554 | |||
555 | def run(self, dataOut, **kwargs): |
|
555 | def run(self, dataOut, **kwargs): | |
556 |
|
556 | |||
557 | if not self.__isConfig: |
|
557 | if not self.__isConfig: | |
558 | self.setup(**kwargs) |
|
558 | self.setup(**kwargs) | |
559 | self.__isConfig = True |
|
559 | self.__isConfig = True | |
560 |
|
560 | |||
561 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) |
|
561 | avgdata, avgdatatime = self.integrate(dataOut.data, dataOut.utctime) | |
562 |
|
562 | |||
563 | # dataOut.timeInterval *= n |
|
563 | # dataOut.timeInterval *= n | |
564 | dataOut.flagNoData = True |
|
564 | dataOut.flagNoData = True | |
565 |
|
565 | |||
566 | if self.__dataReady: |
|
566 | if self.__dataReady: | |
567 | dataOut.data = avgdata |
|
567 | dataOut.data = avgdata | |
568 | dataOut.nCohInt *= self.n |
|
568 | dataOut.nCohInt *= self.n | |
569 | dataOut.utctime = avgdatatime |
|
569 | dataOut.utctime = avgdatatime | |
570 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt |
|
570 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt | |
571 | dataOut.flagNoData = False |
|
571 | dataOut.flagNoData = False | |
572 |
|
572 | |||
573 |
|
573 | |||
574 | class Decoder(Operation): |
|
574 | class Decoder(Operation): | |
575 |
|
575 | |||
576 | __isConfig = False |
|
576 | __isConfig = False | |
577 | __profIndex = 0 |
|
577 | __profIndex = 0 | |
578 |
|
578 | |||
579 | code = None |
|
579 | code = None | |
580 |
|
580 | |||
581 | nCode = None |
|
581 | nCode = None | |
582 | nBaud = None |
|
582 | nBaud = None | |
583 |
|
583 | |||
584 | def __init__(self): |
|
584 | def __init__(self): | |
585 |
|
585 | |||
586 | self.__isConfig = False |
|
586 | self.__isConfig = False | |
587 |
|
587 | |||
588 | def setup(self, code, shape): |
|
588 | def setup(self, code, shape): | |
589 |
|
589 | |||
590 | self.__profIndex = 0 |
|
590 | self.__profIndex = 0 | |
591 |
|
591 | |||
592 | self.code = code |
|
592 | self.code = code | |
593 |
|
593 | |||
594 | self.nCode = len(code) |
|
594 | self.nCode = len(code) | |
595 | self.nBaud = len(code[0]) |
|
595 | self.nBaud = len(code[0]) | |
596 |
|
596 | |||
597 | self.__nChannels, self.__nHeis = shape |
|
597 | self.__nChannels, self.__nHeis = shape | |
598 |
|
598 | |||
599 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) |
|
599 | __codeBuffer = numpy.zeros((self.nCode, self.__nHeis), dtype=numpy.complex) | |
600 |
|
600 | |||
601 | __codeBuffer[:,0:self.nBaud] = self.code |
|
601 | __codeBuffer[:,0:self.nBaud] = self.code | |
602 |
|
602 | |||
603 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) |
|
603 | self.fft_code = numpy.conj(numpy.fft.fft(__codeBuffer, axis=1)) | |
604 |
|
604 | |||
605 | self.ndatadec = self.__nHeis - self.nBaud + 1 |
|
605 | self.ndatadec = self.__nHeis - self.nBaud + 1 | |
606 |
|
606 | |||
607 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) |
|
607 | self.datadecTime = numpy.zeros((self.__nChannels, self.ndatadec), dtype=numpy.complex) | |
608 |
|
608 | |||
609 | def convolutionInFreq(self, data): |
|
609 | def convolutionInFreq(self, data): | |
610 |
|
610 | |||
611 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
611 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
612 |
|
612 | |||
613 | fft_data = numpy.fft.fft(data, axis=1) |
|
613 | fft_data = numpy.fft.fft(data, axis=1) | |
614 |
|
614 | |||
615 | conv = fft_data*fft_code |
|
615 | conv = fft_data*fft_code | |
616 |
|
616 | |||
617 | data = numpy.fft.ifft(conv,axis=1) |
|
617 | data = numpy.fft.ifft(conv,axis=1) | |
618 |
|
618 | |||
619 | datadec = data[:,:-self.nBaud+1] |
|
619 | datadec = data[:,:-self.nBaud+1] | |
620 |
|
620 | |||
621 | return datadec |
|
621 | return datadec | |
622 |
|
622 | |||
623 | def convolutionInFreqOpt(self, data): |
|
623 | def convolutionInFreqOpt(self, data): | |
624 |
|
624 | |||
625 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) |
|
625 | fft_code = self.fft_code[self.__profIndex].reshape(1,-1) | |
626 |
|
626 | |||
627 | data = cfunctions.decoder(fft_code, data) |
|
627 | data = cfunctions.decoder(fft_code, data) | |
628 |
|
628 | |||
629 | datadec = data[:,:-self.nBaud+1] |
|
629 | datadec = data[:,:-self.nBaud+1] | |
630 |
|
630 | |||
631 | return datadec |
|
631 | return datadec | |
632 |
|
632 | |||
633 | def convolutionInTime(self, data): |
|
633 | def convolutionInTime(self, data): | |
634 |
|
634 | |||
635 | code = self.code[self.__profIndex] |
|
635 | code = self.code[self.__profIndex] | |
636 |
|
636 | |||
637 | for i in range(self.__nChannels): |
|
637 | for i in range(self.__nChannels): | |
638 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') |
|
638 | self.datadecTime[i,:] = numpy.correlate(data[i,:], code, mode='valid') | |
639 |
|
639 | |||
640 | return self.datadecTime |
|
640 | return self.datadecTime | |
641 |
|
641 | |||
642 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): |
|
642 | def run(self, dataOut, code=None, nCode=None, nBaud=None, mode = 0): | |
643 |
|
643 | |||
644 | if not self.__isConfig: |
|
644 | if not self.__isConfig: | |
645 |
|
645 | |||
646 | if code == None: |
|
646 | if code == None: | |
647 | code = dataOut.code |
|
647 | code = dataOut.code | |
648 | else: |
|
648 | else: | |
649 | code = numpy.array(code).reshape(nCode,nBaud) |
|
649 | code = numpy.array(code).reshape(nCode,nBaud) | |
650 | dataOut.code = code |
|
650 | dataOut.code = code | |
651 | dataOut.nCode = nCode |
|
651 | dataOut.nCode = nCode | |
652 | dataOut.nBaud = nBaud |
|
652 | dataOut.nBaud = nBaud | |
653 |
|
653 | |||
654 | if code == None: |
|
654 | if code == None: | |
655 | return 1 |
|
655 | return 1 | |
656 |
|
656 | |||
657 | self.setup(code, dataOut.data.shape) |
|
657 | self.setup(code, dataOut.data.shape) | |
658 | self.__isConfig = True |
|
658 | self.__isConfig = True | |
659 |
|
659 | |||
660 | if mode == 0: |
|
660 | if mode == 0: | |
661 | datadec = self.convolutionInTime(dataOut.data) |
|
661 | datadec = self.convolutionInTime(dataOut.data) | |
662 |
|
662 | |||
663 | if mode == 1: |
|
663 | if mode == 1: | |
664 | datadec = self.convolutionInFreq(dataOut.data) |
|
664 | datadec = self.convolutionInFreq(dataOut.data) | |
665 |
|
665 | |||
666 | if mode == 2: |
|
666 | if mode == 2: | |
667 | datadec = self.convolutionInFreqOpt(dataOut.data) |
|
667 | datadec = self.convolutionInFreqOpt(dataOut.data) | |
668 |
|
668 | |||
669 | dataOut.data = datadec |
|
669 | dataOut.data = datadec | |
670 |
|
670 | |||
671 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] |
|
671 | dataOut.heightList = dataOut.heightList[0:self.ndatadec] | |
672 |
|
672 | |||
673 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada |
|
673 | dataOut.flagDecodeData = True #asumo q la data no esta decodificada | |
674 |
|
674 | |||
675 | if self.__profIndex == self.nCode-1: |
|
675 | if self.__profIndex == self.nCode-1: | |
676 | self.__profIndex = 0 |
|
676 | self.__profIndex = 0 | |
677 | return 1 |
|
677 | return 1 | |
678 |
|
678 | |||
679 | self.__profIndex += 1 |
|
679 | self.__profIndex += 1 | |
680 |
|
680 | |||
681 | return 1 |
|
681 | return 1 | |
682 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip |
|
682 | # dataOut.flagDeflipData = True #asumo q la data no esta sin flip | |
683 |
|
683 | |||
684 |
|
684 | |||
685 |
|
685 | |||
686 | class SpectraProc(ProcessingUnit): |
|
686 | class SpectraProc(ProcessingUnit): | |
687 |
|
687 | |||
688 | def __init__(self): |
|
688 | def __init__(self): | |
689 |
|
689 | |||
690 | self.objectDict = {} |
|
690 | self.objectDict = {} | |
691 | self.buffer = None |
|
691 | self.buffer = None | |
692 | self.firstdatatime = None |
|
692 | self.firstdatatime = None | |
693 | self.profIndex = 0 |
|
693 | self.profIndex = 0 | |
694 | self.dataOut = Spectra() |
|
694 | self.dataOut = Spectra() | |
695 |
|
695 | |||
696 | def __updateObjFromInput(self): |
|
696 | def __updateObjFromInput(self): | |
697 |
|
697 | |||
|
698 | self.dataOut.timeZone = self.dataIn.timeZone | |||
|
699 | self.dataOut.dstFlag = self.dataIn.dstFlag | |||
|
700 | self.dataOut.errorCount = self.dataIn.errorCount | |||
|
701 | self.dataOut.useLocalTime = self.dataIn.useLocalTime | |||
|
702 | ||||
698 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
703 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() | |
699 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
704 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() | |
700 | self.dataOut.channelList = self.dataIn.channelList |
|
705 | self.dataOut.channelList = self.dataIn.channelList | |
701 | self.dataOut.heightList = self.dataIn.heightList |
|
706 | self.dataOut.heightList = self.dataIn.heightList | |
702 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
707 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
703 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
708 | # self.dataOut.nHeights = self.dataIn.nHeights | |
704 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
709 | # self.dataOut.nChannels = self.dataIn.nChannels | |
705 | self.dataOut.nBaud = self.dataIn.nBaud |
|
710 | self.dataOut.nBaud = self.dataIn.nBaud | |
706 | self.dataOut.nCode = self.dataIn.nCode |
|
711 | self.dataOut.nCode = self.dataIn.nCode | |
707 | self.dataOut.code = self.dataIn.code |
|
712 | self.dataOut.code = self.dataIn.code | |
708 | self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
713 | self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
709 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
714 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
710 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
715 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
711 | self.dataOut.utctime = self.firstdatatime |
|
716 | self.dataOut.utctime = self.firstdatatime | |
712 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
717 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
713 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
718 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
714 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
719 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
715 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
720 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
716 | self.dataOut.nIncohInt = 1 |
|
721 | self.dataOut.nIncohInt = 1 | |
717 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
722 | self.dataOut.ippSeconds = self.dataIn.ippSeconds | |
718 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
723 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
719 |
|
724 | |||
720 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
725 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt | |
721 |
|
726 | |||
722 | def __getFft(self): |
|
727 | def __getFft(self): | |
723 | """ |
|
728 | """ | |
724 | Convierte valores de Voltaje a Spectra |
|
729 | Convierte valores de Voltaje a Spectra | |
725 |
|
730 | |||
726 | Affected: |
|
731 | Affected: | |
727 | self.dataOut.data_spc |
|
732 | self.dataOut.data_spc | |
728 | self.dataOut.data_cspc |
|
733 | self.dataOut.data_cspc | |
729 | self.dataOut.data_dc |
|
734 | self.dataOut.data_dc | |
730 | self.dataOut.heightList |
|
735 | self.dataOut.heightList | |
731 | self.profIndex |
|
736 | self.profIndex | |
732 | self.buffer |
|
737 | self.buffer | |
733 | self.dataOut.flagNoData |
|
738 | self.dataOut.flagNoData | |
734 | """ |
|
739 | """ | |
735 | fft_volt = numpy.fft.fft(self.buffer,axis=1) |
|
740 | fft_volt = numpy.fft.fft(self.buffer,axis=1) | |
736 | fft_volt = fft_volt.astype(numpy.dtype('complex')) |
|
741 | fft_volt = fft_volt.astype(numpy.dtype('complex')) | |
737 | dc = fft_volt[:,0,:] |
|
742 | dc = fft_volt[:,0,:] | |
738 |
|
743 | |||
739 | #calculo de self-spectra |
|
744 | #calculo de self-spectra | |
740 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
745 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
741 | spc = fft_volt * numpy.conjugate(fft_volt) |
|
746 | spc = fft_volt * numpy.conjugate(fft_volt) | |
742 | spc = spc.real |
|
747 | spc = spc.real | |
743 |
|
748 | |||
744 | blocksize = 0 |
|
749 | blocksize = 0 | |
745 | blocksize += dc.size |
|
750 | blocksize += dc.size | |
746 | blocksize += spc.size |
|
751 | blocksize += spc.size | |
747 |
|
752 | |||
748 | cspc = None |
|
753 | cspc = None | |
749 | pairIndex = 0 |
|
754 | pairIndex = 0 | |
750 | if self.dataOut.pairsList != None: |
|
755 | if self.dataOut.pairsList != None: | |
751 | #calculo de cross-spectra |
|
756 | #calculo de cross-spectra | |
752 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') |
|
757 | cspc = numpy.zeros((self.dataOut.nPairs, self.dataOut.nFFTPoints, self.dataOut.nHeights), dtype='complex') | |
753 | for pair in self.dataOut.pairsList: |
|
758 | for pair in self.dataOut.pairsList: | |
754 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) |
|
759 | cspc[pairIndex,:,:] = fft_volt[pair[0],:,:] * numpy.conjugate(fft_volt[pair[1],:,:]) | |
755 | pairIndex += 1 |
|
760 | pairIndex += 1 | |
756 | blocksize += cspc.size |
|
761 | blocksize += cspc.size | |
757 |
|
762 | |||
758 | self.dataOut.data_spc = spc |
|
763 | self.dataOut.data_spc = spc | |
759 | self.dataOut.data_cspc = cspc |
|
764 | self.dataOut.data_cspc = cspc | |
760 | self.dataOut.data_dc = dc |
|
765 | self.dataOut.data_dc = dc | |
761 | self.dataOut.blockSize = blocksize |
|
766 | self.dataOut.blockSize = blocksize | |
|
767 | self.dataOut.flagShiftFFT = True | |||
762 |
|
768 | |||
763 | def init(self, nFFTPoints=None, pairsList=None): |
|
769 | def init(self, nFFTPoints=None, pairsList=None): | |
764 |
|
770 | |||
765 | self.dataOut.flagNoData = True |
|
771 | self.dataOut.flagNoData = True | |
766 |
|
772 | |||
767 | if self.dataIn.type == "Spectra": |
|
773 | if self.dataIn.type == "Spectra": | |
768 | self.dataOut.copy(self.dataIn) |
|
774 | self.dataOut.copy(self.dataIn) | |
769 | return |
|
775 | return | |
770 |
|
776 | |||
771 | if self.dataIn.type == "Voltage": |
|
777 | if self.dataIn.type == "Voltage": | |
772 |
|
778 | |||
773 | if nFFTPoints == None: |
|
779 | if nFFTPoints == None: | |
774 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" |
|
780 | raise ValueError, "This SpectraProc.init() need nFFTPoints input variable" | |
775 |
|
781 | |||
776 | if pairsList == None: |
|
782 | if pairsList == None: | |
777 | nPairs = 0 |
|
783 | nPairs = 0 | |
778 | else: |
|
784 | else: | |
779 | nPairs = len(pairsList) |
|
785 | nPairs = len(pairsList) | |
780 |
|
786 | |||
781 | self.dataOut.nFFTPoints = nFFTPoints |
|
787 | self.dataOut.nFFTPoints = nFFTPoints | |
782 | self.dataOut.pairsList = pairsList |
|
788 | self.dataOut.pairsList = pairsList | |
783 | self.dataOut.nPairs = nPairs |
|
789 | self.dataOut.nPairs = nPairs | |
784 |
|
790 | |||
785 | if self.buffer == None: |
|
791 | if self.buffer == None: | |
786 | self.buffer = numpy.zeros((self.dataIn.nChannels, |
|
792 | self.buffer = numpy.zeros((self.dataIn.nChannels, | |
787 | self.dataOut.nFFTPoints, |
|
793 | self.dataOut.nFFTPoints, | |
788 | self.dataIn.nHeights), |
|
794 | self.dataIn.nHeights), | |
789 | dtype='complex') |
|
795 | dtype='complex') | |
790 |
|
796 | |||
791 |
|
797 | |||
792 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() |
|
798 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy() | |
793 | self.profIndex += 1 |
|
799 | self.profIndex += 1 | |
794 |
|
800 | |||
795 | if self.firstdatatime == None: |
|
801 | if self.firstdatatime == None: | |
796 | self.firstdatatime = self.dataIn.utctime |
|
802 | self.firstdatatime = self.dataIn.utctime | |
797 |
|
803 | |||
798 | if self.profIndex == self.dataOut.nFFTPoints: |
|
804 | if self.profIndex == self.dataOut.nFFTPoints: | |
799 | self.__updateObjFromInput() |
|
805 | self.__updateObjFromInput() | |
800 | self.__getFft() |
|
806 | self.__getFft() | |
801 |
|
807 | |||
802 | self.dataOut.flagNoData = False |
|
808 | self.dataOut.flagNoData = False | |
803 |
|
809 | |||
804 | self.buffer = None |
|
810 | self.buffer = None | |
805 | self.firstdatatime = None |
|
811 | self.firstdatatime = None | |
806 | self.profIndex = 0 |
|
812 | self.profIndex = 0 | |
807 |
|
813 | |||
808 | return |
|
814 | return | |
809 |
|
815 | |||
810 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) |
|
816 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) | |
811 |
|
817 | |||
812 | def selectChannels(self, channelList): |
|
818 | def selectChannels(self, channelList): | |
813 |
|
819 | |||
814 | channelIndexList = [] |
|
820 | channelIndexList = [] | |
815 |
|
821 | |||
816 | for channel in channelList: |
|
822 | for channel in channelList: | |
817 | index = self.dataOut.channelList.index(channel) |
|
823 | index = self.dataOut.channelList.index(channel) | |
818 | channelIndexList.append(index) |
|
824 | channelIndexList.append(index) | |
819 |
|
825 | |||
820 | self.selectChannelsByIndex(channelIndexList) |
|
826 | self.selectChannelsByIndex(channelIndexList) | |
821 |
|
827 | |||
822 | def selectChannelsByIndex(self, channelIndexList): |
|
828 | def selectChannelsByIndex(self, channelIndexList): | |
823 | """ |
|
829 | """ | |
824 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
830 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
825 |
|
831 | |||
826 | Input: |
|
832 | Input: | |
827 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
833 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
828 |
|
834 | |||
829 | Affected: |
|
835 | Affected: | |
830 | self.dataOut.data_spc |
|
836 | self.dataOut.data_spc | |
831 | self.dataOut.channelIndexList |
|
837 | self.dataOut.channelIndexList | |
832 | self.dataOut.nChannels |
|
838 | self.dataOut.nChannels | |
833 |
|
839 | |||
834 | Return: |
|
840 | Return: | |
835 | None |
|
841 | None | |
836 | """ |
|
842 | """ | |
837 |
|
843 | |||
838 | for channelIndex in channelIndexList: |
|
844 | for channelIndex in channelIndexList: | |
839 | if channelIndex not in self.dataOut.channelIndexList: |
|
845 | if channelIndex not in self.dataOut.channelIndexList: | |
840 | print channelIndexList |
|
846 | print channelIndexList | |
841 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
847 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
842 |
|
848 | |||
843 | nChannels = len(channelIndexList) |
|
849 | nChannels = len(channelIndexList) | |
844 |
|
850 | |||
845 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
851 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
846 |
|
852 | |||
847 | self.dataOut.data_spc = data_spc |
|
853 | self.dataOut.data_spc = data_spc | |
848 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
854 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
849 | # self.dataOut.nChannels = nChannels |
|
855 | # self.dataOut.nChannels = nChannels | |
850 |
|
856 | |||
851 | return 1 |
|
857 | return 1 | |
852 |
|
858 | |||
853 | def selectHeights(self, minHei, maxHei): |
|
859 | def selectHeights(self, minHei, maxHei): | |
854 | """ |
|
860 | """ | |
855 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango |
|
861 | Selecciona un bloque de datos en base a un grupo de valores de alturas segun el rango | |
856 | minHei <= height <= maxHei |
|
862 | minHei <= height <= maxHei | |
857 |
|
863 | |||
858 | Input: |
|
864 | Input: | |
859 | minHei : valor minimo de altura a considerar |
|
865 | minHei : valor minimo de altura a considerar | |
860 | maxHei : valor maximo de altura a considerar |
|
866 | maxHei : valor maximo de altura a considerar | |
861 |
|
867 | |||
862 | Affected: |
|
868 | Affected: | |
863 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex |
|
869 | Indirectamente son cambiados varios valores a travez del metodo selectHeightsByIndex | |
864 |
|
870 | |||
865 | Return: |
|
871 | Return: | |
866 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
872 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
867 | """ |
|
873 | """ | |
868 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): |
|
874 | if (minHei < self.dataOut.heightList[0]) or (minHei > maxHei): | |
869 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
875 | raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
870 |
|
876 | |||
871 | if (maxHei > self.dataOut.heightList[-1]): |
|
877 | if (maxHei > self.dataOut.heightList[-1]): | |
872 | maxHei = self.dataOut.heightList[-1] |
|
878 | maxHei = self.dataOut.heightList[-1] | |
873 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) |
|
879 | # raise ValueError, "some value in (%d,%d) is not valid" % (minHei, maxHei) | |
874 |
|
880 | |||
875 | minIndex = 0 |
|
881 | minIndex = 0 | |
876 | maxIndex = 0 |
|
882 | maxIndex = 0 | |
877 | heights = self.dataOut.heightList |
|
883 | heights = self.dataOut.heightList | |
878 |
|
884 | |||
879 | inda = numpy.where(heights >= minHei) |
|
885 | inda = numpy.where(heights >= minHei) | |
880 | indb = numpy.where(heights <= maxHei) |
|
886 | indb = numpy.where(heights <= maxHei) | |
881 |
|
887 | |||
882 | try: |
|
888 | try: | |
883 | minIndex = inda[0][0] |
|
889 | minIndex = inda[0][0] | |
884 | except: |
|
890 | except: | |
885 | minIndex = 0 |
|
891 | minIndex = 0 | |
886 |
|
892 | |||
887 | try: |
|
893 | try: | |
888 | maxIndex = indb[0][-1] |
|
894 | maxIndex = indb[0][-1] | |
889 | except: |
|
895 | except: | |
890 | maxIndex = len(heights) |
|
896 | maxIndex = len(heights) | |
891 |
|
897 | |||
892 | self.selectHeightsByIndex(minIndex, maxIndex) |
|
898 | self.selectHeightsByIndex(minIndex, maxIndex) | |
893 |
|
899 | |||
894 | return 1 |
|
900 | return 1 | |
895 |
|
901 | |||
896 |
|
902 | |||
897 | def selectHeightsByIndex(self, minIndex, maxIndex): |
|
903 | def selectHeightsByIndex(self, minIndex, maxIndex): | |
898 | """ |
|
904 | """ | |
899 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango |
|
905 | Selecciona un bloque de datos en base a un grupo indices de alturas segun el rango | |
900 | minIndex <= index <= maxIndex |
|
906 | minIndex <= index <= maxIndex | |
901 |
|
907 | |||
902 | Input: |
|
908 | Input: | |
903 | minIndex : valor de indice minimo de altura a considerar |
|
909 | minIndex : valor de indice minimo de altura a considerar | |
904 | maxIndex : valor de indice maximo de altura a considerar |
|
910 | maxIndex : valor de indice maximo de altura a considerar | |
905 |
|
911 | |||
906 | Affected: |
|
912 | Affected: | |
907 | self.dataOut.data_spc |
|
913 | self.dataOut.data_spc | |
908 | self.dataOut.data_cspc |
|
914 | self.dataOut.data_cspc | |
909 | self.dataOut.data_dc |
|
915 | self.dataOut.data_dc | |
910 | self.dataOut.heightList |
|
916 | self.dataOut.heightList | |
911 |
|
917 | |||
912 | Return: |
|
918 | Return: | |
913 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 |
|
919 | 1 si el metodo se ejecuto con exito caso contrario devuelve 0 | |
914 | """ |
|
920 | """ | |
915 |
|
921 | |||
916 | if (minIndex < 0) or (minIndex > maxIndex): |
|
922 | if (minIndex < 0) or (minIndex > maxIndex): | |
917 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
923 | raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
918 |
|
924 | |||
919 | if (maxIndex >= self.dataOut.nHeights): |
|
925 | if (maxIndex >= self.dataOut.nHeights): | |
920 | maxIndex = self.dataOut.nHeights-1 |
|
926 | maxIndex = self.dataOut.nHeights-1 | |
921 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) |
|
927 | # raise ValueError, "some value in (%d,%d) is not valid" % (minIndex, maxIndex) | |
922 |
|
928 | |||
923 | nHeights = maxIndex - minIndex + 1 |
|
929 | nHeights = maxIndex - minIndex + 1 | |
924 |
|
930 | |||
925 | #Spectra |
|
931 | #Spectra | |
926 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] |
|
932 | data_spc = self.dataOut.data_spc[:,:,minIndex:maxIndex+1] | |
927 |
|
933 | |||
928 | data_cspc = None |
|
934 | data_cspc = None | |
929 | if self.dataOut.data_cspc != None: |
|
935 | if self.dataOut.data_cspc != None: | |
930 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] |
|
936 | data_cspc = self.dataOut.data_cspc[:,:,minIndex:maxIndex+1] | |
931 |
|
937 | |||
932 | data_dc = None |
|
938 | data_dc = None | |
933 | if self.dataOut.data_dc != None: |
|
939 | if self.dataOut.data_dc != None: | |
934 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] |
|
940 | data_dc = self.dataOut.data_dc[:,minIndex:maxIndex+1] | |
935 |
|
941 | |||
936 | self.dataOut.data_spc = data_spc |
|
942 | self.dataOut.data_spc = data_spc | |
937 | self.dataOut.data_cspc = data_cspc |
|
943 | self.dataOut.data_cspc = data_cspc | |
938 | self.dataOut.data_dc = data_dc |
|
944 | self.dataOut.data_dc = data_dc | |
939 |
|
945 | |||
940 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] |
|
946 | self.dataOut.heightList = self.dataOut.heightList[minIndex:maxIndex+1] | |
941 |
|
947 | |||
942 | return 1 |
|
948 | return 1 | |
943 |
|
949 | |||
944 | def removeDC(self, mode = 1): |
|
950 | def removeDC(self, mode = 1): | |
945 |
|
951 | |||
946 | dc_index = 0 |
|
952 | dc_index = 0 | |
947 | freq_index = numpy.array([-2,-1,1,2]) |
|
953 | freq_index = numpy.array([-2,-1,1,2]) | |
948 | data_spc = self.dataOut.data_spc |
|
954 | data_spc = self.dataOut.data_spc | |
949 | data_cspc = self.dataOut.data_cspc |
|
955 | data_cspc = self.dataOut.data_cspc | |
950 | data_dc = self.dataOut.data_dc |
|
956 | data_dc = self.dataOut.data_dc | |
951 |
|
957 | |||
952 | if self.dataOut.flagShiftFFT: |
|
958 | if self.dataOut.flagShiftFFT: | |
953 | dc_index += self.dataOut.nFFTPoints/2 |
|
959 | dc_index += self.dataOut.nFFTPoints/2 | |
954 | freq_index += self.dataOut.nFFTPoints/2 |
|
960 | freq_index += self.dataOut.nFFTPoints/2 | |
955 |
|
961 | |||
956 | if mode == 1: |
|
962 | if mode == 1: | |
957 | data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2 |
|
963 | data_spc[dc_index] = (data_spc[:,freq_index[1],:] + data_spc[:,freq_index[2],:])/2 | |
958 | if data_cspc != None: |
|
964 | if data_cspc != None: | |
959 | data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2 |
|
965 | data_cspc[dc_index] = (data_cspc[:,freq_index[1],:] + data_cspc[:,freq_index[2],:])/2 | |
960 | return 1 |
|
966 | return 1 | |
961 |
|
967 | |||
962 | if mode == 2: |
|
968 | if mode == 2: | |
963 | pass |
|
969 | pass | |
964 |
|
970 | |||
965 | if mode == 3: |
|
971 | if mode == 3: | |
966 | pass |
|
972 | pass | |
967 |
|
973 | |||
968 | raise ValueError, "mode parameter has to be 1, 2 or 3" |
|
974 | raise ValueError, "mode parameter has to be 1, 2 or 3" | |
969 |
|
975 | |||
970 | def removeInterference(self): |
|
976 | def removeInterference(self): | |
971 |
|
977 | |||
972 | pass |
|
978 | pass | |
973 |
|
979 | |||
974 |
|
980 | |||
975 | class IncohInt(Operation): |
|
981 | class IncohInt(Operation): | |
976 |
|
982 | |||
977 |
|
983 | |||
978 | __profIndex = 0 |
|
984 | __profIndex = 0 | |
979 | __withOverapping = False |
|
985 | __withOverapping = False | |
980 |
|
986 | |||
981 | __byTime = False |
|
987 | __byTime = False | |
982 | __initime = None |
|
988 | __initime = None | |
983 | __lastdatatime = None |
|
989 | __lastdatatime = None | |
984 | __integrationtime = None |
|
990 | __integrationtime = None | |
985 |
|
991 | |||
986 | __buffer_spc = None |
|
992 | __buffer_spc = None | |
987 | __buffer_cspc = None |
|
993 | __buffer_cspc = None | |
988 | __buffer_dc = None |
|
994 | __buffer_dc = None | |
989 |
|
995 | |||
990 | __dataReady = False |
|
996 | __dataReady = False | |
991 |
|
997 | |||
992 | __timeInterval = None |
|
998 | __timeInterval = None | |
993 |
|
999 | |||
994 | n = None |
|
1000 | n = None | |
995 |
|
1001 | |||
996 |
|
1002 | |||
997 |
|
1003 | |||
998 | def __init__(self): |
|
1004 | def __init__(self): | |
999 |
|
1005 | |||
1000 | self.__isConfig = False |
|
1006 | self.__isConfig = False | |
1001 |
|
1007 | |||
1002 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1008 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
1003 | """ |
|
1009 | """ | |
1004 | Set the parameters of the integration class. |
|
1010 | Set the parameters of the integration class. | |
1005 |
|
1011 | |||
1006 | Inputs: |
|
1012 | Inputs: | |
1007 |
|
1013 | |||
1008 | n : Number of coherent integrations |
|
1014 | n : Number of coherent integrations | |
1009 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1015 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
1010 | overlapping : |
|
1016 | overlapping : | |
1011 |
|
1017 | |||
1012 | """ |
|
1018 | """ | |
1013 |
|
1019 | |||
1014 | self.__initime = None |
|
1020 | self.__initime = None | |
1015 | self.__lastdatatime = 0 |
|
1021 | self.__lastdatatime = 0 | |
1016 | self.__buffer_spc = None |
|
1022 | self.__buffer_spc = None | |
1017 | self.__buffer_cspc = None |
|
1023 | self.__buffer_cspc = None | |
1018 | self.__buffer_dc = None |
|
1024 | self.__buffer_dc = None | |
1019 | self.__dataReady = False |
|
1025 | self.__dataReady = False | |
1020 |
|
1026 | |||
1021 |
|
1027 | |||
1022 | if n == None and timeInterval == None: |
|
1028 | if n == None and timeInterval == None: | |
1023 | raise ValueError, "n or timeInterval should be specified ..." |
|
1029 | raise ValueError, "n or timeInterval should be specified ..." | |
1024 |
|
1030 | |||
1025 | if n != None: |
|
1031 | if n != None: | |
1026 | self.n = n |
|
1032 | self.n = n | |
1027 | self.__byTime = False |
|
1033 | self.__byTime = False | |
1028 | else: |
|
1034 | else: | |
1029 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line |
|
1035 | self.__integrationtime = timeInterval * 60. #if (type(timeInterval)!=integer) -> change this line | |
1030 | self.n = 9999 |
|
1036 | self.n = 9999 | |
1031 | self.__byTime = True |
|
1037 | self.__byTime = True | |
1032 |
|
1038 | |||
1033 | if overlapping: |
|
1039 | if overlapping: | |
1034 | self.__withOverapping = True |
|
1040 | self.__withOverapping = True | |
1035 | else: |
|
1041 | else: | |
1036 | self.__withOverapping = False |
|
1042 | self.__withOverapping = False | |
1037 | self.__buffer_spc = 0 |
|
1043 | self.__buffer_spc = 0 | |
1038 | self.__buffer_cspc = 0 |
|
1044 | self.__buffer_cspc = 0 | |
1039 | self.__buffer_dc = 0 |
|
1045 | self.__buffer_dc = 0 | |
1040 |
|
1046 | |||
1041 | self.__profIndex = 0 |
|
1047 | self.__profIndex = 0 | |
1042 |
|
1048 | |||
1043 | def putData(self, data_spc, data_cspc, data_dc): |
|
1049 | def putData(self, data_spc, data_cspc, data_dc): | |
1044 |
|
1050 | |||
1045 | """ |
|
1051 | """ | |
1046 | Add a profile to the __buffer_spc and increase in one the __profileIndex |
|
1052 | Add a profile to the __buffer_spc and increase in one the __profileIndex | |
1047 |
|
1053 | |||
1048 | """ |
|
1054 | """ | |
1049 |
|
1055 | |||
1050 | if not self.__withOverapping: |
|
1056 | if not self.__withOverapping: | |
1051 | self.__buffer_spc += data_spc |
|
1057 | self.__buffer_spc += data_spc | |
1052 |
|
1058 | |||
1053 | if data_cspc == None: |
|
1059 | if data_cspc == None: | |
1054 | self.__buffer_cspc = None |
|
1060 | self.__buffer_cspc = None | |
1055 | else: |
|
1061 | else: | |
1056 | self.__buffer_cspc += data_cspc |
|
1062 | self.__buffer_cspc += data_cspc | |
1057 |
|
1063 | |||
1058 | if data_dc == None: |
|
1064 | if data_dc == None: | |
1059 | self.__buffer_dc = None |
|
1065 | self.__buffer_dc = None | |
1060 | else: |
|
1066 | else: | |
1061 | self.__buffer_dc += data_dc |
|
1067 | self.__buffer_dc += data_dc | |
1062 |
|
1068 | |||
1063 | self.__profIndex += 1 |
|
1069 | self.__profIndex += 1 | |
1064 | return |
|
1070 | return | |
1065 |
|
1071 | |||
1066 | #Overlapping data |
|
1072 | #Overlapping data | |
1067 | nChannels, nFFTPoints, nHeis = data_spc.shape |
|
1073 | nChannels, nFFTPoints, nHeis = data_spc.shape | |
1068 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) |
|
1074 | data_spc = numpy.reshape(data_spc, (1, nChannels, nFFTPoints, nHeis)) | |
1069 | if data_cspc != None: |
|
1075 | if data_cspc != None: | |
1070 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) |
|
1076 | data_cspc = numpy.reshape(data_cspc, (1, -1, nFFTPoints, nHeis)) | |
1071 | if data_dc != None: |
|
1077 | if data_dc != None: | |
1072 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) |
|
1078 | data_dc = numpy.reshape(data_dc, (1, -1, nHeis)) | |
1073 |
|
1079 | |||
1074 | #If the buffer is empty then it takes the data value |
|
1080 | #If the buffer is empty then it takes the data value | |
1075 | if self.__buffer_spc == None: |
|
1081 | if self.__buffer_spc == None: | |
1076 | self.__buffer_spc = data_spc |
|
1082 | self.__buffer_spc = data_spc | |
1077 |
|
1083 | |||
1078 | if data_cspc == None: |
|
1084 | if data_cspc == None: | |
1079 | self.__buffer_cspc = None |
|
1085 | self.__buffer_cspc = None | |
1080 | else: |
|
1086 | else: | |
1081 | self.__buffer_cspc += data_cspc |
|
1087 | self.__buffer_cspc += data_cspc | |
1082 |
|
1088 | |||
1083 | if data_dc == None: |
|
1089 | if data_dc == None: | |
1084 | self.__buffer_dc = None |
|
1090 | self.__buffer_dc = None | |
1085 | else: |
|
1091 | else: | |
1086 | self.__buffer_dc += data_dc |
|
1092 | self.__buffer_dc += data_dc | |
1087 |
|
1093 | |||
1088 | self.__profIndex += 1 |
|
1094 | self.__profIndex += 1 | |
1089 | return |
|
1095 | return | |
1090 |
|
1096 | |||
1091 | #If the buffer length is lower than n then stakcing the data value |
|
1097 | #If the buffer length is lower than n then stakcing the data value | |
1092 | if self.__profIndex < self.n: |
|
1098 | if self.__profIndex < self.n: | |
1093 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) |
|
1099 | self.__buffer_spc = numpy.vstack((self.__buffer_spc, data_spc)) | |
1094 |
|
1100 | |||
1095 | if data_cspc != None: |
|
1101 | if data_cspc != None: | |
1096 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) |
|
1102 | self.__buffer_cspc = numpy.vstack((self.__buffer_cspc, data_cspc)) | |
1097 |
|
1103 | |||
1098 | if data_dc != None: |
|
1104 | if data_dc != None: | |
1099 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) |
|
1105 | self.__buffer_dc = numpy.vstack((self.__buffer_dc, data_dc)) | |
1100 |
|
1106 | |||
1101 | self.__profIndex += 1 |
|
1107 | self.__profIndex += 1 | |
1102 | return |
|
1108 | return | |
1103 |
|
1109 | |||
1104 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1110 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
1105 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) |
|
1111 | self.__buffer_spc = numpy.roll(self.__buffer_spc, -1, axis=0) | |
1106 | self.__buffer_spc[self.n-1] = data_spc |
|
1112 | self.__buffer_spc[self.n-1] = data_spc | |
1107 |
|
1113 | |||
1108 | if data_cspc != None: |
|
1114 | if data_cspc != None: | |
1109 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) |
|
1115 | self.__buffer_cspc = numpy.roll(self.__buffer_cspc, -1, axis=0) | |
1110 | self.__buffer_cspc[self.n-1] = data_cspc |
|
1116 | self.__buffer_cspc[self.n-1] = data_cspc | |
1111 |
|
1117 | |||
1112 | if data_dc != None: |
|
1118 | if data_dc != None: | |
1113 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) |
|
1119 | self.__buffer_dc = numpy.roll(self.__buffer_dc, -1, axis=0) | |
1114 | self.__buffer_dc[self.n-1] = data_dc |
|
1120 | self.__buffer_dc[self.n-1] = data_dc | |
1115 |
|
1121 | |||
1116 | self.__profIndex = self.n |
|
1122 | self.__profIndex = self.n | |
1117 | return |
|
1123 | return | |
1118 |
|
1124 | |||
1119 |
|
1125 | |||
1120 | def pushData(self): |
|
1126 | def pushData(self): | |
1121 | """ |
|
1127 | """ | |
1122 | Return the sum of the last profiles and the profiles used in the sum. |
|
1128 | Return the sum of the last profiles and the profiles used in the sum. | |
1123 |
|
1129 | |||
1124 | Affected: |
|
1130 | Affected: | |
1125 |
|
1131 | |||
1126 | self.__profileIndex |
|
1132 | self.__profileIndex | |
1127 |
|
1133 | |||
1128 | """ |
|
1134 | """ | |
1129 | data_spc = None |
|
1135 | data_spc = None | |
1130 | data_cspc = None |
|
1136 | data_cspc = None | |
1131 | data_dc = None |
|
1137 | data_dc = None | |
1132 |
|
1138 | |||
1133 | if not self.__withOverapping: |
|
1139 | if not self.__withOverapping: | |
1134 | data_spc = self.__buffer_spc |
|
1140 | data_spc = self.__buffer_spc | |
1135 | data_cspc = self.__buffer_cspc |
|
1141 | data_cspc = self.__buffer_cspc | |
1136 | data_dc = self.__buffer_dc |
|
1142 | data_dc = self.__buffer_dc | |
1137 |
|
1143 | |||
1138 | n = self.__profIndex |
|
1144 | n = self.__profIndex | |
1139 |
|
1145 | |||
1140 | self.__buffer_spc = 0 |
|
1146 | self.__buffer_spc = 0 | |
1141 | self.__buffer_cspc = 0 |
|
1147 | self.__buffer_cspc = 0 | |
1142 | self.__buffer_dc = 0 |
|
1148 | self.__buffer_dc = 0 | |
1143 | self.__profIndex = 0 |
|
1149 | self.__profIndex = 0 | |
1144 |
|
1150 | |||
1145 | return data_spc, data_cspc, data_dc, n |
|
1151 | return data_spc, data_cspc, data_dc, n | |
1146 |
|
1152 | |||
1147 | #Integration with Overlapping |
|
1153 | #Integration with Overlapping | |
1148 | data_spc = numpy.sum(self.__buffer_spc, axis=0) |
|
1154 | data_spc = numpy.sum(self.__buffer_spc, axis=0) | |
1149 |
|
1155 | |||
1150 | if self.__buffer_cspc != None: |
|
1156 | if self.__buffer_cspc != None: | |
1151 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) |
|
1157 | data_cspc = numpy.sum(self.__buffer_cspc, axis=0) | |
1152 |
|
1158 | |||
1153 | if self.__buffer_dc != None: |
|
1159 | if self.__buffer_dc != None: | |
1154 | data_dc = numpy.sum(self.__buffer_dc, axis=0) |
|
1160 | data_dc = numpy.sum(self.__buffer_dc, axis=0) | |
1155 |
|
1161 | |||
1156 | n = self.__profIndex |
|
1162 | n = self.__profIndex | |
1157 |
|
1163 | |||
1158 | return data_spc, data_cspc, data_dc, n |
|
1164 | return data_spc, data_cspc, data_dc, n | |
1159 |
|
1165 | |||
1160 | def byProfiles(self, *args): |
|
1166 | def byProfiles(self, *args): | |
1161 |
|
1167 | |||
1162 | self.__dataReady = False |
|
1168 | self.__dataReady = False | |
1163 | avgdata_spc = None |
|
1169 | avgdata_spc = None | |
1164 | avgdata_cspc = None |
|
1170 | avgdata_cspc = None | |
1165 | avgdata_dc = None |
|
1171 | avgdata_dc = None | |
1166 | n = None |
|
1172 | n = None | |
1167 |
|
1173 | |||
1168 | self.putData(*args) |
|
1174 | self.putData(*args) | |
1169 |
|
1175 | |||
1170 | if self.__profIndex == self.n: |
|
1176 | if self.__profIndex == self.n: | |
1171 |
|
1177 | |||
1172 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1178 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1173 | self.__dataReady = True |
|
1179 | self.__dataReady = True | |
1174 |
|
1180 | |||
1175 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1181 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1176 |
|
1182 | |||
1177 | def byTime(self, datatime, *args): |
|
1183 | def byTime(self, datatime, *args): | |
1178 |
|
1184 | |||
1179 | self.__dataReady = False |
|
1185 | self.__dataReady = False | |
1180 | avgdata_spc = None |
|
1186 | avgdata_spc = None | |
1181 | avgdata_cspc = None |
|
1187 | avgdata_cspc = None | |
1182 | avgdata_dc = None |
|
1188 | avgdata_dc = None | |
1183 | n = None |
|
1189 | n = None | |
1184 |
|
1190 | |||
1185 | self.putData(*args) |
|
1191 | self.putData(*args) | |
1186 |
|
1192 | |||
1187 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1193 | if (datatime - self.__initime) >= self.__integrationtime: | |
1188 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() |
|
1194 | avgdata_spc, avgdata_cspc, avgdata_dc, n = self.pushData() | |
1189 | self.n = n |
|
1195 | self.n = n | |
1190 | self.__dataReady = True |
|
1196 | self.__dataReady = True | |
1191 |
|
1197 | |||
1192 | return avgdata_spc, avgdata_cspc, avgdata_dc |
|
1198 | return avgdata_spc, avgdata_cspc, avgdata_dc | |
1193 |
|
1199 | |||
1194 | def integrate(self, datatime, *args): |
|
1200 | def integrate(self, datatime, *args): | |
1195 |
|
1201 | |||
1196 | if self.__initime == None: |
|
1202 | if self.__initime == None: | |
1197 | self.__initime = datatime |
|
1203 | self.__initime = datatime | |
1198 |
|
1204 | |||
1199 | if self.__byTime: |
|
1205 | if self.__byTime: | |
1200 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) |
|
1206 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byTime(datatime, *args) | |
1201 | else: |
|
1207 | else: | |
1202 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) |
|
1208 | avgdata_spc, avgdata_cspc, avgdata_dc = self.byProfiles(*args) | |
1203 |
|
1209 | |||
1204 | self.__lastdatatime = datatime |
|
1210 | self.__lastdatatime = datatime | |
1205 |
|
1211 | |||
1206 | if avgdata_spc == None: |
|
1212 | if avgdata_spc == None: | |
1207 | return None, None, None, None |
|
1213 | return None, None, None, None | |
1208 |
|
1214 | |||
1209 | avgdatatime = self.__initime |
|
1215 | avgdatatime = self.__initime | |
1210 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) |
|
1216 | self.__timeInterval = (self.__lastdatatime - self.__initime)/(self.n - 1) | |
1211 |
|
1217 | |||
1212 | deltatime = datatime -self.__lastdatatime |
|
1218 | deltatime = datatime -self.__lastdatatime | |
1213 |
|
1219 | |||
1214 | if not self.__withOverapping: |
|
1220 | if not self.__withOverapping: | |
1215 | self.__initime = datatime |
|
1221 | self.__initime = datatime | |
1216 | else: |
|
1222 | else: | |
1217 | self.__initime += deltatime |
|
1223 | self.__initime += deltatime | |
1218 |
|
1224 | |||
1219 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
1225 | return avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc | |
1220 |
|
1226 | |||
1221 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
1227 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): | |
1222 |
|
1228 | |||
1223 | if n==1: |
|
1229 | if n==1: | |
1224 | dataOut.flagNoData = False |
|
1230 | dataOut.flagNoData = False | |
1225 | return |
|
1231 | return | |
1226 |
|
1232 | |||
1227 | if not self.__isConfig: |
|
1233 | if not self.__isConfig: | |
1228 | self.setup(n, timeInterval, overlapping) |
|
1234 | self.setup(n, timeInterval, overlapping) | |
1229 | self.__isConfig = True |
|
1235 | self.__isConfig = True | |
1230 |
|
1236 | |||
1231 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, |
|
1237 | avgdatatime, avgdata_spc, avgdata_cspc, avgdata_dc = self.integrate(dataOut.utctime, | |
1232 | dataOut.data_spc, |
|
1238 | dataOut.data_spc, | |
1233 | dataOut.data_cspc, |
|
1239 | dataOut.data_cspc, | |
1234 | dataOut.data_dc) |
|
1240 | dataOut.data_dc) | |
1235 |
|
1241 | |||
1236 | # dataOut.timeInterval *= n |
|
1242 | # dataOut.timeInterval *= n | |
1237 | dataOut.flagNoData = True |
|
1243 | dataOut.flagNoData = True | |
1238 |
|
1244 | |||
1239 | if self.__dataReady: |
|
1245 | if self.__dataReady: | |
1240 |
|
1246 | |||
1241 | dataOut.data_spc = avgdata_spc |
|
1247 | dataOut.data_spc = avgdata_spc | |
1242 | dataOut.data_cspc = avgdata_cspc |
|
1248 | dataOut.data_cspc = avgdata_cspc | |
1243 | dataOut.data_dc = avgdata_dc |
|
1249 | dataOut.data_dc = avgdata_dc | |
1244 |
|
1250 | |||
1245 | dataOut.nIncohInt *= self.n |
|
1251 | dataOut.nIncohInt *= self.n | |
1246 | dataOut.utctime = avgdatatime |
|
1252 | dataOut.utctime = avgdatatime | |
1247 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints |
|
1253 | #dataOut.timeInterval = dataOut.ippSeconds * dataOut.nCohInt * dataOut.nIncohInt * dataOut.nFFTPoints | |
1248 | dataOut.timeInterval = self.__timeInterval*self.n |
|
1254 | dataOut.timeInterval = self.__timeInterval*self.n | |
1249 | dataOut.flagNoData = False |
|
1255 | dataOut.flagNoData = False | |
1250 |
|
1256 | |||
1251 | class ProfileSelector(Operation): |
|
1257 | class ProfileSelector(Operation): | |
1252 |
|
1258 | |||
1253 | profileIndex = None |
|
1259 | profileIndex = None | |
1254 | # Tamanho total de los perfiles |
|
1260 | # Tamanho total de los perfiles | |
1255 | nProfiles = None |
|
1261 | nProfiles = None | |
1256 |
|
1262 | |||
1257 | def __init__(self): |
|
1263 | def __init__(self): | |
1258 |
|
1264 | |||
1259 | self.profileIndex = 0 |
|
1265 | self.profileIndex = 0 | |
1260 |
|
1266 | |||
1261 | def incIndex(self): |
|
1267 | def incIndex(self): | |
1262 | self.profileIndex += 1 |
|
1268 | self.profileIndex += 1 | |
1263 |
|
1269 | |||
1264 | if self.profileIndex >= self.nProfiles: |
|
1270 | if self.profileIndex >= self.nProfiles: | |
1265 | self.profileIndex = 0 |
|
1271 | self.profileIndex = 0 | |
1266 |
|
1272 | |||
1267 | def isProfileInRange(self, minIndex, maxIndex): |
|
1273 | def isProfileInRange(self, minIndex, maxIndex): | |
1268 |
|
1274 | |||
1269 | if self.profileIndex < minIndex: |
|
1275 | if self.profileIndex < minIndex: | |
1270 | return False |
|
1276 | return False | |
1271 |
|
1277 | |||
1272 | if self.profileIndex > maxIndex: |
|
1278 | if self.profileIndex > maxIndex: | |
1273 | return False |
|
1279 | return False | |
1274 |
|
1280 | |||
1275 | return True |
|
1281 | return True | |
1276 |
|
1282 | |||
1277 | def isProfileInList(self, profileList): |
|
1283 | def isProfileInList(self, profileList): | |
1278 |
|
1284 | |||
1279 | if self.profileIndex not in profileList: |
|
1285 | if self.profileIndex not in profileList: | |
1280 | return False |
|
1286 | return False | |
1281 |
|
1287 | |||
1282 | return True |
|
1288 | return True | |
1283 |
|
1289 | |||
1284 | def run(self, dataOut, profileList=None, profileRangeList=None): |
|
1290 | def run(self, dataOut, profileList=None, profileRangeList=None): | |
1285 |
|
1291 | |||
1286 | dataOut.flagNoData = True |
|
1292 | dataOut.flagNoData = True | |
1287 | self.nProfiles = dataOut.nProfiles |
|
1293 | self.nProfiles = dataOut.nProfiles | |
1288 |
|
1294 | |||
1289 | if profileList != None: |
|
1295 | if profileList != None: | |
1290 | if self.isProfileInList(profileList): |
|
1296 | if self.isProfileInList(profileList): | |
1291 | dataOut.flagNoData = False |
|
1297 | dataOut.flagNoData = False | |
1292 |
|
1298 | |||
1293 | self.incIndex() |
|
1299 | self.incIndex() | |
1294 | return 1 |
|
1300 | return 1 | |
1295 |
|
1301 | |||
1296 |
|
1302 | |||
1297 | elif profileRangeList != None: |
|
1303 | elif profileRangeList != None: | |
1298 | minIndex = profileRangeList[0] |
|
1304 | minIndex = profileRangeList[0] | |
1299 | maxIndex = profileRangeList[1] |
|
1305 | maxIndex = profileRangeList[1] | |
1300 | if self.isProfileInRange(minIndex, maxIndex): |
|
1306 | if self.isProfileInRange(minIndex, maxIndex): | |
1301 | dataOut.flagNoData = False |
|
1307 | dataOut.flagNoData = False | |
1302 |
|
1308 | |||
1303 | self.incIndex() |
|
1309 | self.incIndex() | |
1304 | return 1 |
|
1310 | return 1 | |
1305 |
|
1311 | |||
1306 | else: |
|
1312 | else: | |
1307 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" |
|
1313 | raise ValueError, "ProfileSelector needs profileList or profileRangeList" | |
1308 |
|
1314 | |||
1309 | return 0 |
|
1315 | return 0 | |
1310 |
|
1316 | |||
1311 | class SpectraHeisProc(ProcessingUnit): |
|
1317 | class SpectraHeisProc(ProcessingUnit): | |
1312 | def __init__(self): |
|
1318 | def __init__(self): | |
1313 | self.objectDict = {} |
|
1319 | self.objectDict = {} | |
1314 | # self.buffer = None |
|
1320 | # self.buffer = None | |
1315 | # self.firstdatatime = None |
|
1321 | # self.firstdatatime = None | |
1316 | # self.profIndex = 0 |
|
1322 | # self.profIndex = 0 | |
1317 | self.dataOut = SpectraHeis() |
|
1323 | self.dataOut = SpectraHeis() | |
1318 |
|
1324 | |||
1319 | def __updateObjFromInput(self): |
|
1325 | def __updateObjFromInput(self): | |
1320 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# |
|
1326 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# | |
1321 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# |
|
1327 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# | |
1322 | self.dataOut.channelList = self.dataIn.channelList |
|
1328 | self.dataOut.channelList = self.dataIn.channelList | |
1323 | self.dataOut.heightList = self.dataIn.heightList |
|
1329 | self.dataOut.heightList = self.dataIn.heightList | |
1324 | # self.dataOut.dtype = self.dataIn.dtype |
|
1330 | # self.dataOut.dtype = self.dataIn.dtype | |
1325 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
1331 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
1326 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
1332 | # self.dataOut.nHeights = self.dataIn.nHeights | |
1327 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
1333 | # self.dataOut.nChannels = self.dataIn.nChannels | |
1328 | self.dataOut.nBaud = self.dataIn.nBaud |
|
1334 | self.dataOut.nBaud = self.dataIn.nBaud | |
1329 | self.dataOut.nCode = self.dataIn.nCode |
|
1335 | self.dataOut.nCode = self.dataIn.nCode | |
1330 | self.dataOut.code = self.dataIn.code |
|
1336 | self.dataOut.code = self.dataIn.code | |
1331 | # self.dataOut.nProfiles = 1 |
|
1337 | # self.dataOut.nProfiles = 1 | |
1332 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
1338 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints | |
1333 | self.dataOut.nFFTPoints = self.dataIn.nHeights |
|
1339 | self.dataOut.nFFTPoints = self.dataIn.nHeights | |
1334 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
1340 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList | |
1335 | # self.dataOut.flagNoData = self.dataIn.flagNoData |
|
1341 | # self.dataOut.flagNoData = self.dataIn.flagNoData | |
1336 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock |
|
1342 | self.dataOut.flagTimeBlock = self.dataIn.flagTimeBlock | |
1337 | self.dataOut.utctime = self.dataIn.utctime |
|
1343 | self.dataOut.utctime = self.dataIn.utctime | |
1338 | # self.dataOut.utctime = self.firstdatatime |
|
1344 | # self.dataOut.utctime = self.firstdatatime | |
1339 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
1345 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada | |
1340 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
1346 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip | |
1341 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
1347 | self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT | |
1342 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
1348 | self.dataOut.nCohInt = self.dataIn.nCohInt | |
1343 | self.dataOut.nIncohInt = 1 |
|
1349 | self.dataOut.nIncohInt = 1 | |
1344 | self.dataOut.ippSeconds= self.dataIn.ippSeconds |
|
1350 | self.dataOut.ippSeconds= self.dataIn.ippSeconds | |
1345 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
1351 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter | |
1346 |
|
1352 | |||
1347 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt |
|
1353 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt | |
1348 | # self.dataOut.set=self.dataIn.set |
|
1354 | # self.dataOut.set=self.dataIn.set | |
1349 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight |
|
1355 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight | |
1350 |
|
1356 | |||
1351 |
|
1357 | |||
1352 | def __getFft(self): |
|
1358 | def __getFft(self): | |
1353 |
|
1359 | |||
1354 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) |
|
1360 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) | |
1355 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
1361 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) | |
1356 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) |
|
1362 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) | |
1357 | self.dataOut.data_spc = spc |
|
1363 | self.dataOut.data_spc = spc | |
1358 |
|
1364 | |||
1359 | def init(self): |
|
1365 | def init(self): | |
1360 |
|
1366 | |||
1361 | self.dataOut.flagNoData = True |
|
1367 | self.dataOut.flagNoData = True | |
1362 |
|
1368 | |||
1363 | if self.dataIn.type == "SpectraHeis": |
|
1369 | if self.dataIn.type == "SpectraHeis": | |
1364 | self.dataOut.copy(self.dataIn) |
|
1370 | self.dataOut.copy(self.dataIn) | |
1365 | return |
|
1371 | return | |
1366 |
|
1372 | |||
1367 | if self.dataIn.type == "Voltage": |
|
1373 | if self.dataIn.type == "Voltage": | |
1368 | self.__updateObjFromInput() |
|
1374 | self.__updateObjFromInput() | |
1369 | self.__getFft() |
|
1375 | self.__getFft() | |
1370 | self.dataOut.flagNoData = False |
|
1376 | self.dataOut.flagNoData = False | |
1371 |
|
1377 | |||
1372 | return |
|
1378 | return | |
1373 |
|
1379 | |||
1374 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) |
|
1380 | raise ValuError, "The type object %s is not valid"%(self.dataIn.type) | |
1375 |
|
1381 | |||
1376 |
|
1382 | |||
1377 | def selectChannels(self, channelList): |
|
1383 | def selectChannels(self, channelList): | |
1378 |
|
1384 | |||
1379 | channelIndexList = [] |
|
1385 | channelIndexList = [] | |
1380 |
|
1386 | |||
1381 | for channel in channelList: |
|
1387 | for channel in channelList: | |
1382 | index = self.dataOut.channelList.index(channel) |
|
1388 | index = self.dataOut.channelList.index(channel) | |
1383 | channelIndexList.append(index) |
|
1389 | channelIndexList.append(index) | |
1384 |
|
1390 | |||
1385 | self.selectChannelsByIndex(channelIndexList) |
|
1391 | self.selectChannelsByIndex(channelIndexList) | |
1386 |
|
1392 | |||
1387 | def selectChannelsByIndex(self, channelIndexList): |
|
1393 | def selectChannelsByIndex(self, channelIndexList): | |
1388 | """ |
|
1394 | """ | |
1389 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
1395 | Selecciona un bloque de datos en base a canales segun el channelIndexList | |
1390 |
|
1396 | |||
1391 | Input: |
|
1397 | Input: | |
1392 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
1398 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] | |
1393 |
|
1399 | |||
1394 | Affected: |
|
1400 | Affected: | |
1395 | self.dataOut.data |
|
1401 | self.dataOut.data | |
1396 | self.dataOut.channelIndexList |
|
1402 | self.dataOut.channelIndexList | |
1397 | self.dataOut.nChannels |
|
1403 | self.dataOut.nChannels | |
1398 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
1404 | self.dataOut.m_ProcessingHeader.totalSpectra | |
1399 | self.dataOut.systemHeaderObj.numChannels |
|
1405 | self.dataOut.systemHeaderObj.numChannels | |
1400 | self.dataOut.m_ProcessingHeader.blockSize |
|
1406 | self.dataOut.m_ProcessingHeader.blockSize | |
1401 |
|
1407 | |||
1402 | Return: |
|
1408 | Return: | |
1403 | None |
|
1409 | None | |
1404 | """ |
|
1410 | """ | |
1405 |
|
1411 | |||
1406 | for channelIndex in channelIndexList: |
|
1412 | for channelIndex in channelIndexList: | |
1407 | if channelIndex not in self.dataOut.channelIndexList: |
|
1413 | if channelIndex not in self.dataOut.channelIndexList: | |
1408 | print channelIndexList |
|
1414 | print channelIndexList | |
1409 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
1415 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex | |
1410 |
|
1416 | |||
1411 | nChannels = len(channelIndexList) |
|
1417 | nChannels = len(channelIndexList) | |
1412 |
|
1418 | |||
1413 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
1419 | data_spc = self.dataOut.data_spc[channelIndexList,:] | |
1414 |
|
1420 | |||
1415 | self.dataOut.data_spc = data_spc |
|
1421 | self.dataOut.data_spc = data_spc | |
1416 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
1422 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] | |
1417 |
|
1423 | |||
1418 | return 1 |
|
1424 | return 1 | |
1419 |
|
1425 | |||
1420 | class IncohInt4SpectraHeis(Operation): |
|
1426 | class IncohInt4SpectraHeis(Operation): | |
1421 |
|
1427 | |||
1422 | __isConfig = False |
|
1428 | __isConfig = False | |
1423 |
|
1429 | |||
1424 | __profIndex = 0 |
|
1430 | __profIndex = 0 | |
1425 | __withOverapping = False |
|
1431 | __withOverapping = False | |
1426 |
|
1432 | |||
1427 | __byTime = False |
|
1433 | __byTime = False | |
1428 | __initime = None |
|
1434 | __initime = None | |
1429 | __lastdatatime = None |
|
1435 | __lastdatatime = None | |
1430 | __integrationtime = None |
|
1436 | __integrationtime = None | |
1431 |
|
1437 | |||
1432 | __buffer = None |
|
1438 | __buffer = None | |
1433 |
|
1439 | |||
1434 | __dataReady = False |
|
1440 | __dataReady = False | |
1435 |
|
1441 | |||
1436 | n = None |
|
1442 | n = None | |
1437 |
|
1443 | |||
1438 |
|
1444 | |||
1439 | def __init__(self): |
|
1445 | def __init__(self): | |
1440 |
|
1446 | |||
1441 | self.__isConfig = False |
|
1447 | self.__isConfig = False | |
1442 |
|
1448 | |||
1443 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
1449 | def setup(self, n=None, timeInterval=None, overlapping=False): | |
1444 | """ |
|
1450 | """ | |
1445 | Set the parameters of the integration class. |
|
1451 | Set the parameters of the integration class. | |
1446 |
|
1452 | |||
1447 | Inputs: |
|
1453 | Inputs: | |
1448 |
|
1454 | |||
1449 | n : Number of coherent integrations |
|
1455 | n : Number of coherent integrations | |
1450 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
1456 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work | |
1451 | overlapping : |
|
1457 | overlapping : | |
1452 |
|
1458 | |||
1453 | """ |
|
1459 | """ | |
1454 |
|
1460 | |||
1455 | self.__initime = None |
|
1461 | self.__initime = None | |
1456 | self.__lastdatatime = 0 |
|
1462 | self.__lastdatatime = 0 | |
1457 | self.__buffer = None |
|
1463 | self.__buffer = None | |
1458 | self.__dataReady = False |
|
1464 | self.__dataReady = False | |
1459 |
|
1465 | |||
1460 |
|
1466 | |||
1461 | if n == None and timeInterval == None: |
|
1467 | if n == None and timeInterval == None: | |
1462 | raise ValueError, "n or timeInterval should be specified ..." |
|
1468 | raise ValueError, "n or timeInterval should be specified ..." | |
1463 |
|
1469 | |||
1464 | if n != None: |
|
1470 | if n != None: | |
1465 | self.n = n |
|
1471 | self.n = n | |
1466 | self.__byTime = False |
|
1472 | self.__byTime = False | |
1467 | else: |
|
1473 | else: | |
1468 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
1474 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line | |
1469 | self.n = 9999 |
|
1475 | self.n = 9999 | |
1470 | self.__byTime = True |
|
1476 | self.__byTime = True | |
1471 |
|
1477 | |||
1472 | if overlapping: |
|
1478 | if overlapping: | |
1473 | self.__withOverapping = True |
|
1479 | self.__withOverapping = True | |
1474 | self.__buffer = None |
|
1480 | self.__buffer = None | |
1475 | else: |
|
1481 | else: | |
1476 | self.__withOverapping = False |
|
1482 | self.__withOverapping = False | |
1477 | self.__buffer = 0 |
|
1483 | self.__buffer = 0 | |
1478 |
|
1484 | |||
1479 | self.__profIndex = 0 |
|
1485 | self.__profIndex = 0 | |
1480 |
|
1486 | |||
1481 | def putData(self, data): |
|
1487 | def putData(self, data): | |
1482 |
|
1488 | |||
1483 | """ |
|
1489 | """ | |
1484 | Add a profile to the __buffer and increase in one the __profileIndex |
|
1490 | Add a profile to the __buffer and increase in one the __profileIndex | |
1485 |
|
1491 | |||
1486 | """ |
|
1492 | """ | |
1487 |
|
1493 | |||
1488 | if not self.__withOverapping: |
|
1494 | if not self.__withOverapping: | |
1489 | self.__buffer += data.copy() |
|
1495 | self.__buffer += data.copy() | |
1490 | self.__profIndex += 1 |
|
1496 | self.__profIndex += 1 | |
1491 | return |
|
1497 | return | |
1492 |
|
1498 | |||
1493 | #Overlapping data |
|
1499 | #Overlapping data | |
1494 | nChannels, nHeis = data.shape |
|
1500 | nChannels, nHeis = data.shape | |
1495 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
1501 | data = numpy.reshape(data, (1, nChannels, nHeis)) | |
1496 |
|
1502 | |||
1497 | #If the buffer is empty then it takes the data value |
|
1503 | #If the buffer is empty then it takes the data value | |
1498 | if self.__buffer == None: |
|
1504 | if self.__buffer == None: | |
1499 | self.__buffer = data |
|
1505 | self.__buffer = data | |
1500 | self.__profIndex += 1 |
|
1506 | self.__profIndex += 1 | |
1501 | return |
|
1507 | return | |
1502 |
|
1508 | |||
1503 | #If the buffer length is lower than n then stakcing the data value |
|
1509 | #If the buffer length is lower than n then stakcing the data value | |
1504 | if self.__profIndex < self.n: |
|
1510 | if self.__profIndex < self.n: | |
1505 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
1511 | self.__buffer = numpy.vstack((self.__buffer, data)) | |
1506 | self.__profIndex += 1 |
|
1512 | self.__profIndex += 1 | |
1507 | return |
|
1513 | return | |
1508 |
|
1514 | |||
1509 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
1515 | #If the buffer length is equal to n then replacing the last buffer value with the data value | |
1510 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
1516 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) | |
1511 | self.__buffer[self.n-1] = data |
|
1517 | self.__buffer[self.n-1] = data | |
1512 | self.__profIndex = self.n |
|
1518 | self.__profIndex = self.n | |
1513 | return |
|
1519 | return | |
1514 |
|
1520 | |||
1515 |
|
1521 | |||
1516 | def pushData(self): |
|
1522 | def pushData(self): | |
1517 | """ |
|
1523 | """ | |
1518 | Return the sum of the last profiles and the profiles used in the sum. |
|
1524 | Return the sum of the last profiles and the profiles used in the sum. | |
1519 |
|
1525 | |||
1520 | Affected: |
|
1526 | Affected: | |
1521 |
|
1527 | |||
1522 | self.__profileIndex |
|
1528 | self.__profileIndex | |
1523 |
|
1529 | |||
1524 | """ |
|
1530 | """ | |
1525 |
|
1531 | |||
1526 | if not self.__withOverapping: |
|
1532 | if not self.__withOverapping: | |
1527 | data = self.__buffer |
|
1533 | data = self.__buffer | |
1528 | n = self.__profIndex |
|
1534 | n = self.__profIndex | |
1529 |
|
1535 | |||
1530 | self.__buffer = 0 |
|
1536 | self.__buffer = 0 | |
1531 | self.__profIndex = 0 |
|
1537 | self.__profIndex = 0 | |
1532 |
|
1538 | |||
1533 | return data, n |
|
1539 | return data, n | |
1534 |
|
1540 | |||
1535 | #Integration with Overlapping |
|
1541 | #Integration with Overlapping | |
1536 | data = numpy.sum(self.__buffer, axis=0) |
|
1542 | data = numpy.sum(self.__buffer, axis=0) | |
1537 | n = self.__profIndex |
|
1543 | n = self.__profIndex | |
1538 |
|
1544 | |||
1539 | return data, n |
|
1545 | return data, n | |
1540 |
|
1546 | |||
1541 | def byProfiles(self, data): |
|
1547 | def byProfiles(self, data): | |
1542 |
|
1548 | |||
1543 | self.__dataReady = False |
|
1549 | self.__dataReady = False | |
1544 | avgdata = None |
|
1550 | avgdata = None | |
1545 | n = None |
|
1551 | n = None | |
1546 |
|
1552 | |||
1547 | self.putData(data) |
|
1553 | self.putData(data) | |
1548 |
|
1554 | |||
1549 | if self.__profIndex == self.n: |
|
1555 | if self.__profIndex == self.n: | |
1550 |
|
1556 | |||
1551 | avgdata, n = self.pushData() |
|
1557 | avgdata, n = self.pushData() | |
1552 | self.__dataReady = True |
|
1558 | self.__dataReady = True | |
1553 |
|
1559 | |||
1554 | return avgdata |
|
1560 | return avgdata | |
1555 |
|
1561 | |||
1556 | def byTime(self, data, datatime): |
|
1562 | def byTime(self, data, datatime): | |
1557 |
|
1563 | |||
1558 | self.__dataReady = False |
|
1564 | self.__dataReady = False | |
1559 | avgdata = None |
|
1565 | avgdata = None | |
1560 | n = None |
|
1566 | n = None | |
1561 |
|
1567 | |||
1562 | self.putData(data) |
|
1568 | self.putData(data) | |
1563 |
|
1569 | |||
1564 | if (datatime - self.__initime) >= self.__integrationtime: |
|
1570 | if (datatime - self.__initime) >= self.__integrationtime: | |
1565 | avgdata, n = self.pushData() |
|
1571 | avgdata, n = self.pushData() | |
1566 | self.n = n |
|
1572 | self.n = n | |
1567 | self.__dataReady = True |
|
1573 | self.__dataReady = True | |
1568 |
|
1574 | |||
1569 | return avgdata |
|
1575 | return avgdata | |
1570 |
|
1576 | |||
1571 | def integrate(self, data, datatime=None): |
|
1577 | def integrate(self, data, datatime=None): | |
1572 |
|
1578 | |||
1573 | if self.__initime == None: |
|
1579 | if self.__initime == None: | |
1574 | self.__initime = datatime |
|
1580 | self.__initime = datatime | |
1575 |
|
1581 | |||
1576 | if self.__byTime: |
|
1582 | if self.__byTime: | |
1577 | avgdata = self.byTime(data, datatime) |
|
1583 | avgdata = self.byTime(data, datatime) | |
1578 | else: |
|
1584 | else: | |
1579 | avgdata = self.byProfiles(data) |
|
1585 | avgdata = self.byProfiles(data) | |
1580 |
|
1586 | |||
1581 |
|
1587 | |||
1582 | self.__lastdatatime = datatime |
|
1588 | self.__lastdatatime = datatime | |
1583 |
|
1589 | |||
1584 | if avgdata == None: |
|
1590 | if avgdata == None: | |
1585 | return None, None |
|
1591 | return None, None | |
1586 |
|
1592 | |||
1587 | avgdatatime = self.__initime |
|
1593 | avgdatatime = self.__initime | |
1588 |
|
1594 | |||
1589 | deltatime = datatime -self.__lastdatatime |
|
1595 | deltatime = datatime -self.__lastdatatime | |
1590 |
|
1596 | |||
1591 | if not self.__withOverapping: |
|
1597 | if not self.__withOverapping: | |
1592 | self.__initime = datatime |
|
1598 | self.__initime = datatime | |
1593 | else: |
|
1599 | else: | |
1594 | self.__initime += deltatime |
|
1600 | self.__initime += deltatime | |
1595 |
|
1601 | |||
1596 | return avgdata, avgdatatime |
|
1602 | return avgdata, avgdatatime | |
1597 |
|
1603 | |||
1598 | def run(self, dataOut, **kwargs): |
|
1604 | def run(self, dataOut, **kwargs): | |
1599 |
|
1605 | |||
1600 | if not self.__isConfig: |
|
1606 | if not self.__isConfig: | |
1601 | self.setup(**kwargs) |
|
1607 | self.setup(**kwargs) | |
1602 | self.__isConfig = True |
|
1608 | self.__isConfig = True | |
1603 |
|
1609 | |||
1604 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
1610 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) | |
1605 |
|
1611 | |||
1606 | # dataOut.timeInterval *= n |
|
1612 | # dataOut.timeInterval *= n | |
1607 | dataOut.flagNoData = True |
|
1613 | dataOut.flagNoData = True | |
1608 |
|
1614 | |||
1609 | if self.__dataReady: |
|
1615 | if self.__dataReady: | |
1610 | dataOut.data_spc = avgdata |
|
1616 | dataOut.data_spc = avgdata | |
1611 | dataOut.nIncohInt *= self.n |
|
1617 | dataOut.nIncohInt *= self.n | |
1612 | # dataOut.nCohInt *= self.n |
|
1618 | # dataOut.nCohInt *= self.n | |
1613 | dataOut.utctime = avgdatatime |
|
1619 | dataOut.utctime = avgdatatime | |
1614 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt |
|
1620 | dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt | |
1615 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
1621 | # dataOut.timeInterval = self.__timeInterval*self.n | |
1616 | dataOut.flagNoData = False |
|
1622 | dataOut.flagNoData = False | |
1617 |
|
1623 | |||
1618 |
|
1624 | |||
1619 |
|
1625 | |||
1620 |
|
1626 | |||
1621 | No newline at end of file |
|
1627 |
General Comments 0
You need to be logged in to leave comments.
Login now