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