##// END OF EJS Templates
Bug plotting RTI fixed: timezone was removed from getLimit function
Miguel Valdez -
r566:e8eb3a2dac97
parent child
Show More
@@ -0,0 +1,61
1 <Project description="150 km Jicamarca January 2015" id="191" name="test01">
2 <ReadUnit datatype="VoltageReader" id="1911" inputId="0" name="VoltageReader">
3 <Operation id="19111" name="run" priority="1" type="self">
4 <Parameter format="str" id="191111" name="path" value="./" />
5 <Parameter format="date" id="191112" name="startDate" value="2015/01/14" />
6 <Parameter format="date" id="191113" name="endDate" value="2015/01/14" />
7 <Parameter format="time" id="191114" name="startTime" value="08:30:00" />
8 <Parameter format="time" id="191115" name="endTime" value="09:30:59" />
9 <Parameter format="int" id="191116" name="delay" value="10" />
10 <Parameter format="int" id="191117" name="nTxs" value="4" />
11 <Parameter format="int" id="191118" name="walk" value="1" />
12 <Parameter format="int" id="191119" name="online" value="1" />
13 </Operation>
14 <Operation id="19112" name="printNumberOfBlock" priority="2" type="self" />
15 </ReadUnit>
16 <ProcUnit datatype="SpectraProc" id="1913" inputId="1912" name="SpectraProc">
17 <Operation id="19131" name="run" priority="1" type="self">
18 <Parameter format="int" id="191311" name="nFFTPoints" value="80" />
19 <Parameter format="int" id="191312" name="nProfiles" value="80" />
20 <Parameter format="pairslist" id="191313" name="pairsList" value="(1,0),(3,2),(5,4),(7,6)" />
21 </Operation>
22 <Operation id="19132" name="IncohInt" priority="2" type="other">
23 <Parameter format="float" id="191321" name="timeInterval" value="60" />
24 </Operation>
25 <Operation id="19133" name="CrossSpectraPlot" priority="3" type="other">
26 <Parameter format="int" id="191331" name="id" value="2006" />
27 <Parameter format="str" id="191332" name="wintitle" value="CrossSpectraPlot_ShortPulse" />
28 <Parameter format="int" id="191333" name="ymin" value="0" />
29 <Parameter format="int" id="191334" name="ymax" value="105" />
30 <Parameter format="str" id="191335" name="phase_cmap" value="jet" />
31 <Parameter format="int" id="191336" name="zmin" value="15" />
32 <Parameter format="int" id="191337" name="zmax" value="45" />
33 <Parameter format="str" id="191338" name="figpath" value="/Users/miguel/tmp" />
34 <Parameter format="int" id="191339" name="exp_code" value="13" />
35 </Operation>
36 <Operation id="19134" name="CoherenceMap" priority="4" type="other">
37 <Parameter format="int" id="191341" name="id" value="102" />
38 <Parameter format="str" id="191342" name="wintitle" value="Coherence" />
39 <Parameter format="str" id="191343" name="phase_cmap" value="jet" />
40 <Parameter format="float" id="191344" name="xmin" value="8.5" />
41 <Parameter format="float" id="191345" name="xmax" value="9.5" />
42 <Parameter format="str" id="191346" name="figpath" value="/Users/miguel/tmp" />
43 <Parameter format="bool" id="191347" name="save" value="1" />
44 <Parameter format="pairslist" id="191348" name="pairsList" value="(1,0),(3,2)" />
45 </Operation>
46 </ProcUnit>
47 <ProcUnit datatype="VoltageProc" id="1912" inputId="1911" name="VoltageProc">
48 <Operation id="19121" name="run" priority="1" type="self" />
49 <Operation id="19122" name="ProfileSelector" priority="2" type="other">
50 <Parameter format="multilist" id="191221" name="rangeList" value="(1,80),(341,420),(681,760),(1021,1100)" />
51 </Operation>
52 <Operation id="19123" name="Decoder" priority="3" type="other">
53 <Parameter format="floatlist" id="191231" name="code" value="1,1,1,-1,-1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,1,-1,1" />
54 <Parameter format="int" id="191232" name="nCode" value="4" />
55 <Parameter format="int" id="191233" name="nBaud" value="7" />
56 </Operation>
57 <Operation id="19124" name="deFlip" priority="4" type="self">
58 <Parameter format="intlist" id="191241" name="channelList" value="1,3,5,7" />
59 </Operation>
60 </ProcUnit>
61 </Project> No newline at end of file
@@ -1,1025 +1,1029
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:
92 class Beam:
93 def __init__(self):
93 def __init__(self):
94 self.codeList = []
94 self.codeList = []
95 self.azimuthList = []
95 self.azimuthList = []
96 self.zenithList = []
96 self.zenithList = []
97
97
98 class GenericData(object):
98 class GenericData(object):
99
99
100 flagNoData = True
100 flagNoData = True
101
101
102 def __init__(self):
102 def __init__(self):
103
103
104 raise ValueError, "This class has not been implemented"
104 raise ValueError, "This class has not been implemented"
105
105
106 def copy(self, inputObj=None):
106 def copy(self, inputObj=None):
107
107
108 if inputObj == None:
108 if inputObj == None:
109 return copy.deepcopy(self)
109 return copy.deepcopy(self)
110
110
111 for key in inputObj.__dict__.keys():
111 for key in inputObj.__dict__.keys():
112 self.__dict__[key] = inputObj.__dict__[key]
112 self.__dict__[key] = inputObj.__dict__[key]
113
113
114 def deepcopy(self):
114 def deepcopy(self):
115
115
116 return copy.deepcopy(self)
116 return copy.deepcopy(self)
117
117
118 def isEmpty(self):
118 def isEmpty(self):
119
119
120 return self.flagNoData
120 return self.flagNoData
121
121
122 class JROData(GenericData):
122 class JROData(GenericData):
123
123
124 # m_BasicHeader = BasicHeader()
124 # m_BasicHeader = BasicHeader()
125 # m_ProcessingHeader = ProcessingHeader()
125 # m_ProcessingHeader = ProcessingHeader()
126
126
127 systemHeaderObj = SystemHeader()
127 systemHeaderObj = SystemHeader()
128
128
129 radarControllerHeaderObj = RadarControllerHeader()
129 radarControllerHeaderObj = RadarControllerHeader()
130
130
131 # data = None
131 # data = None
132
132
133 type = None
133 type = None
134
134
135 datatype = None #dtype but in string
135 datatype = None #dtype but in string
136
136
137 # dtype = None
137 # dtype = None
138
138
139 # nChannels = None
139 # nChannels = None
140
140
141 # nHeights = None
141 # nHeights = None
142
142
143 nProfiles = None
143 nProfiles = None
144
144
145 heightList = None
145 heightList = None
146
146
147 channelList = None
147 channelList = None
148
148
149 flagTimeBlock = False
149 flagTimeBlock = False
150
150
151 useLocalTime = False
151 useLocalTime = False
152
152
153 utctime = None
153 utctime = None
154
154
155 timeZone = None
155 timeZone = None
156
156
157 dstFlag = None
157 dstFlag = None
158
158
159 errorCount = None
159 errorCount = None
160
160
161 blocksize = None
161 blocksize = None
162
162
163 nCode = None
163 nCode = None
164
164
165 nBaud = None
165 nBaud = None
166
166
167 code = None
167 code = None
168
168
169 flagDecodeData = False #asumo q la data no esta decodificada
169 flagDecodeData = False #asumo q la data no esta decodificada
170
170
171 flagDeflipData = False #asumo q la data no esta sin flip
171 flagDeflipData = False #asumo q la data no esta sin flip
172
172
173 flagShiftFFT = False
173 flagShiftFFT = False
174
174
175 # ippSeconds = None
175 # ippSeconds = None
176
176
177 # timeInterval = None
177 # timeInterval = None
178
178
179 nCohInt = None
179 nCohInt = None
180
180
181 noise = None
181 noise = None
182
182
183 windowOfFilter = 1
183 windowOfFilter = 1
184
184
185 #Speed of ligth
185 #Speed of ligth
186 C = 3e8
186 C = 3e8
187
187
188 frequency = 49.92e6
188 frequency = 49.92e6
189
189
190 realtime = False
190 realtime = False
191
191
192 beacon_heiIndexList = None
192 beacon_heiIndexList = None
193
193
194 last_block = None
194 last_block = None
195
195
196 blocknow = None
196 blocknow = None
197
197
198 azimuth = None
198 azimuth = None
199
199
200 zenith = None
200 zenith = None
201
201
202 beam = Beam()
202 beam = Beam()
203
203
204 profileIndex = None
204 profileIndex = None
205
205
206 def __init__(self):
206 def __init__(self):
207
207
208 raise ValueError, "This class has not been implemented"
208 raise ValueError, "This class has not been implemented"
209
209
210 def getNoise(self):
210 def getNoise(self):
211
211
212 raise ValueError, "Not implemented"
212 raise ValueError, "Not implemented"
213
213
214 def getNChannels(self):
214 def getNChannels(self):
215
215
216 return len(self.channelList)
216 return len(self.channelList)
217
217
218 def getChannelIndexList(self):
218 def getChannelIndexList(self):
219
219
220 return range(self.nChannels)
220 return range(self.nChannels)
221
221
222 def getNHeights(self):
222 def getNHeights(self):
223
223
224 return len(self.heightList)
224 return len(self.heightList)
225
225
226 def getHeiRange(self, extrapoints=0):
226 def getHeiRange(self, extrapoints=0):
227
227
228 heis = self.heightList
228 heis = self.heightList
229 # deltah = self.heightList[1] - self.heightList[0]
229 # deltah = self.heightList[1] - self.heightList[0]
230 #
230 #
231 # heis.append(self.heightList[-1])
231 # heis.append(self.heightList[-1])
232
232
233 return heis
233 return heis
234
234
235 def getltctime(self):
235 def getltctime(self):
236
236
237 if self.useLocalTime:
237 if self.useLocalTime:
238 return self.utctime - self.timeZone*60
238 return self.utctime - self.timeZone*60
239
239
240 return self.utctime
240 return self.utctime
241
241
242 def getDatatime(self):
242 def getDatatime(self):
243
243
244 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
244 datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime)
245 return datatimeValue
245 return datatimeValue
246
246
247 def getTimeRange(self):
247 def getTimeRange(self):
248
248
249 datatime = []
249 datatime = []
250
250
251 datatime.append(self.ltctime)
251 datatime.append(self.ltctime)
252 datatime.append(self.ltctime + self.timeInterval)
252 datatime.append(self.ltctime + self.timeInterval+60)
253
253
254 datatime = numpy.array(datatime)
254 datatime = numpy.array(datatime)
255
255
256 return datatime
256 return datatime
257
257
258 def getFmax(self):
258 def getFmax(self):
259
259
260 PRF = 1./(self.ippSeconds * self.nCohInt)
260 PRF = 1./(self.ippSeconds * self.nCohInt)
261
261
262 fmax = PRF/2.
262 fmax = PRF/2.
263
263
264 return fmax
264 return fmax
265
265
266 def getVmax(self):
266 def getVmax(self):
267
267
268 _lambda = self.C/self.frequency
268 _lambda = self.C/self.frequency
269
269
270 vmax = self.getFmax() * _lambda
270 vmax = self.getFmax() * _lambda
271
271
272 return vmax
272 return vmax
273
273
274 def get_ippSeconds(self):
274 def get_ippSeconds(self):
275 '''
275 '''
276 '''
276 '''
277 return self.radarControllerHeaderObj.ippSeconds
277 return self.radarControllerHeaderObj.ippSeconds
278
278
279 def set_ippSeconds(self, ippSeconds):
279 def set_ippSeconds(self, ippSeconds):
280 '''
280 '''
281 '''
281 '''
282
282
283 self.radarControllerHeaderObj.ippSeconds = ippSeconds
283 self.radarControllerHeaderObj.ippSeconds = ippSeconds
284
284
285 return
285 return
286
286
287 def get_dtype(self):
287 def get_dtype(self):
288 '''
288 '''
289 '''
289 '''
290 return getNumpyDtype(self.datatype)
290 return getNumpyDtype(self.datatype)
291
291
292 def set_dtype(self, numpyDtype):
292 def set_dtype(self, numpyDtype):
293 '''
293 '''
294 '''
294 '''
295
295
296 self.datatype = getDataTypeCode(numpyDtype)
296 self.datatype = getDataTypeCode(numpyDtype)
297
297
298 # def getTimeInterval(self):
298 # def getTimeInterval(self):
299 #
299 #
300 # raise IOError, "This method should be implemented inside each Class"
300 # raise IOError, "This method should be implemented inside each Class"
301
301
302 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
302 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
303 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
303 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
304 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
304 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
305 #noise = property(getNoise, "I'm the 'nHeights' property.")
305 #noise = property(getNoise, "I'm the 'nHeights' property.")
306 datatime = property(getDatatime, "I'm the 'datatime' property")
306 datatime = property(getDatatime, "I'm the 'datatime' property")
307 ltctime = property(getltctime, "I'm the 'ltctime' property")
307 ltctime = property(getltctime, "I'm the 'ltctime' property")
308 ippSeconds = property(get_ippSeconds, set_ippSeconds)
308 ippSeconds = property(get_ippSeconds, set_ippSeconds)
309 dtype = property(get_dtype, set_dtype)
309 dtype = property(get_dtype, set_dtype)
310 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
310 # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
311
311
312 class Voltage(JROData):
312 class Voltage(JROData):
313
313
314 #data es un numpy array de 2 dmensiones (canales, alturas)
314 #data es un numpy array de 2 dmensiones (canales, alturas)
315 data = None
315 data = None
316
316
317 def __init__(self):
317 def __init__(self):
318 '''
318 '''
319 Constructor
319 Constructor
320 '''
320 '''
321
321
322 self.useLocalTime = True
323
322 self.radarControllerHeaderObj = RadarControllerHeader()
324 self.radarControllerHeaderObj = RadarControllerHeader()
323
325
324 self.systemHeaderObj = SystemHeader()
326 self.systemHeaderObj = SystemHeader()
325
327
326 self.type = "Voltage"
328 self.type = "Voltage"
327
329
328 self.data = None
330 self.data = None
329
331
330 # self.dtype = None
332 # self.dtype = None
331
333
332 # self.nChannels = 0
334 # self.nChannels = 0
333
335
334 # self.nHeights = 0
336 # self.nHeights = 0
335
337
336 self.nProfiles = None
338 self.nProfiles = None
337
339
338 self.heightList = None
340 self.heightList = None
339
341
340 self.channelList = None
342 self.channelList = None
341
343
342 # self.channelIndexList = None
344 # self.channelIndexList = None
343
345
344 self.flagNoData = True
346 self.flagNoData = True
345
347
346 self.flagTimeBlock = False
348 self.flagTimeBlock = False
347
349
348 self.utctime = None
350 self.utctime = None
349
351
350 self.timeZone = None
352 self.timeZone = None
351
353
352 self.dstFlag = None
354 self.dstFlag = None
353
355
354 self.errorCount = None
356 self.errorCount = None
355
357
356 self.nCohInt = None
358 self.nCohInt = None
357
359
358 self.blocksize = None
360 self.blocksize = None
359
361
360 self.flagDecodeData = False #asumo q la data no esta decodificada
362 self.flagDecodeData = False #asumo q la data no esta decodificada
361
363
362 self.flagDeflipData = False #asumo q la data no esta sin flip
364 self.flagDeflipData = False #asumo q la data no esta sin flip
363
365
364 self.flagShiftFFT = False
366 self.flagShiftFFT = False
365
367
366 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
368 self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil
367
369
368 self.profileIndex = 0
370 self.profileIndex = 0
369
371
370 def getNoisebyHildebrand(self):
372 def getNoisebyHildebrand(self):
371 """
373 """
372 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
374 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
373
375
374 Return:
376 Return:
375 noiselevel
377 noiselevel
376 """
378 """
377
379
378 for channel in range(self.nChannels):
380 for channel in range(self.nChannels):
379 daux = self.data_spc[channel,:,:]
381 daux = self.data_spc[channel,:,:]
380 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
382 self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt)
381
383
382 return self.noise
384 return self.noise
383
385
384 def getNoise(self, type = 1):
386 def getNoise(self, type = 1):
385
387
386 self.noise = numpy.zeros(self.nChannels)
388 self.noise = numpy.zeros(self.nChannels)
387
389
388 if type == 1:
390 if type == 1:
389 noise = self.getNoisebyHildebrand()
391 noise = self.getNoisebyHildebrand()
390
392
391 return 10*numpy.log10(noise)
393 return 10*numpy.log10(noise)
392
394
393 def getTimeInterval(self):
395 def getTimeInterval(self):
394
396
395 timeInterval = self.ippSeconds * self.nCohInt
397 timeInterval = self.ippSeconds * self.nCohInt
396
398
397 return timeInterval
399 return timeInterval
398
400
399 noise = property(getNoise, "I'm the 'nHeights' property.")
401 noise = property(getNoise, "I'm the 'nHeights' property.")
400 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
402 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
401
403
402 class Spectra(JROData):
404 class Spectra(JROData):
403
405
404 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
406 #data es un numpy array de 2 dmensiones (canales, perfiles, alturas)
405 data_spc = None
407 data_spc = None
406
408
407 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
409 #data es un numpy array de 2 dmensiones (canales, pares, alturas)
408 data_cspc = None
410 data_cspc = None
409
411
410 #data es un numpy array de 2 dmensiones (canales, alturas)
412 #data es un numpy array de 2 dmensiones (canales, alturas)
411 data_dc = None
413 data_dc = None
412
414
413 nFFTPoints = None
415 nFFTPoints = None
414
416
415 # nPairs = None
417 # nPairs = None
416
418
417 pairsList = None
419 pairsList = None
418
420
419 nIncohInt = None
421 nIncohInt = None
420
422
421 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
423 wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia
422
424
423 nCohInt = None #se requiere para determinar el valor de timeInterval
425 nCohInt = None #se requiere para determinar el valor de timeInterval
424
426
425 ippFactor = None
427 ippFactor = None
426
428
427 profileIndex = 0
429 profileIndex = 0
428
430
429 def __init__(self):
431 def __init__(self):
430 '''
432 '''
431 Constructor
433 Constructor
432 '''
434 '''
433
435
436 self.useLocalTime = True
437
434 self.radarControllerHeaderObj = RadarControllerHeader()
438 self.radarControllerHeaderObj = RadarControllerHeader()
435
439
436 self.systemHeaderObj = SystemHeader()
440 self.systemHeaderObj = SystemHeader()
437
441
438 self.type = "Spectra"
442 self.type = "Spectra"
439
443
440 # self.data = None
444 # self.data = None
441
445
442 # self.dtype = None
446 # self.dtype = None
443
447
444 # self.nChannels = 0
448 # self.nChannels = 0
445
449
446 # self.nHeights = 0
450 # self.nHeights = 0
447
451
448 self.nProfiles = None
452 self.nProfiles = None
449
453
450 self.heightList = None
454 self.heightList = None
451
455
452 self.channelList = None
456 self.channelList = None
453
457
454 # self.channelIndexList = None
458 # self.channelIndexList = None
455
459
456 self.pairsList = None
460 self.pairsList = None
457
461
458 self.flagNoData = True
462 self.flagNoData = True
459
463
460 self.flagTimeBlock = False
464 self.flagTimeBlock = False
461
465
462 self.utctime = None
466 self.utctime = None
463
467
464 self.nCohInt = None
468 self.nCohInt = None
465
469
466 self.nIncohInt = None
470 self.nIncohInt = None
467
471
468 self.blocksize = None
472 self.blocksize = None
469
473
470 self.nFFTPoints = None
474 self.nFFTPoints = None
471
475
472 self.wavelength = None
476 self.wavelength = None
473
477
474 self.flagDecodeData = False #asumo q la data no esta decodificada
478 self.flagDecodeData = False #asumo q la data no esta decodificada
475
479
476 self.flagDeflipData = False #asumo q la data no esta sin flip
480 self.flagDeflipData = False #asumo q la data no esta sin flip
477
481
478 self.flagShiftFFT = False
482 self.flagShiftFFT = False
479
483
480 self.ippFactor = 1
484 self.ippFactor = 1
481
485
482 #self.noise = None
486 #self.noise = None
483
487
484 self.beacon_heiIndexList = []
488 self.beacon_heiIndexList = []
485
489
486 self.noise_estimation = None
490 self.noise_estimation = None
487
491
488
492
489 def getNoisebyHildebrand(self):
493 def getNoisebyHildebrand(self):
490 """
494 """
491 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
495 Determino el nivel de ruido usando el metodo Hildebrand-Sekhon
492
496
493 Return:
497 Return:
494 noiselevel
498 noiselevel
495 """
499 """
496
500
497 noise = numpy.zeros(self.nChannels)
501 noise = numpy.zeros(self.nChannels)
498 for channel in range(self.nChannels):
502 for channel in range(self.nChannels):
499 daux = self.data_spc[channel,:,:]
503 daux = self.data_spc[channel,:,:]
500 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
504 noise[channel] = hildebrand_sekhon(daux, self.nIncohInt)
501
505
502 return noise
506 return noise
503
507
504 def getNoise(self):
508 def getNoise(self):
505 if self.noise_estimation != None:
509 if self.noise_estimation != None:
506 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
510 return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py
507 else:
511 else:
508 noise = self.getNoisebyHildebrand()
512 noise = self.getNoisebyHildebrand()
509 return noise
513 return noise
510
514
511
515
512 def getFreqRange(self, extrapoints=0):
516 def getFreqRange(self, extrapoints=0):
513
517
514 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
518 deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor)
515 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
519 freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2
516
520
517 return freqrange
521 return freqrange
518
522
519 def getVelRange(self, extrapoints=0):
523 def getVelRange(self, extrapoints=0):
520
524
521 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
525 deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor)
522 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
526 velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2
523
527
524 return velrange
528 return velrange
525
529
526 def getNPairs(self):
530 def getNPairs(self):
527
531
528 return len(self.pairsList)
532 return len(self.pairsList)
529
533
530 def getPairsIndexList(self):
534 def getPairsIndexList(self):
531
535
532 return range(self.nPairs)
536 return range(self.nPairs)
533
537
534 def getNormFactor(self):
538 def getNormFactor(self):
535 pwcode = 1
539 pwcode = 1
536 if self.flagDecodeData:
540 if self.flagDecodeData:
537 pwcode = numpy.sum(self.code[0]**2)
541 pwcode = numpy.sum(self.code[0]**2)
538 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
542 #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
539 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
543 normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter
540
544
541 return normFactor
545 return normFactor
542
546
543 def getFlagCspc(self):
547 def getFlagCspc(self):
544
548
545 if self.data_cspc == None:
549 if self.data_cspc == None:
546 return True
550 return True
547
551
548 return False
552 return False
549
553
550 def getFlagDc(self):
554 def getFlagDc(self):
551
555
552 if self.data_dc == None:
556 if self.data_dc == None:
553 return True
557 return True
554
558
555 return False
559 return False
556
560
557 def getTimeInterval(self):
561 def getTimeInterval(self):
558
562
559 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
563 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles
560
564
561 return timeInterval
565 return timeInterval
562
566
563 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
567 nPairs = property(getNPairs, "I'm the 'nPairs' property.")
564 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
568 pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.")
565 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
569 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
566 flag_cspc = property(getFlagCspc)
570 flag_cspc = property(getFlagCspc)
567 flag_dc = property(getFlagDc)
571 flag_dc = property(getFlagDc)
568 noise = property(getNoise, "I'm the 'nHeights' property.")
572 noise = property(getNoise, "I'm the 'nHeights' property.")
569 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
573 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
570
574
571 class SpectraHeis(Spectra):
575 class SpectraHeis(Spectra):
572
576
573 data_spc = None
577 data_spc = None
574
578
575 data_cspc = None
579 data_cspc = None
576
580
577 data_dc = None
581 data_dc = None
578
582
579 nFFTPoints = None
583 nFFTPoints = None
580
584
581 # nPairs = None
585 # nPairs = None
582
586
583 pairsList = None
587 pairsList = None
584
588
585 nIncohInt = None
589 nIncohInt = None
586
590
587 def __init__(self):
591 def __init__(self):
588
592
589 self.radarControllerHeaderObj = RadarControllerHeader()
593 self.radarControllerHeaderObj = RadarControllerHeader()
590
594
591 self.systemHeaderObj = SystemHeader()
595 self.systemHeaderObj = SystemHeader()
592
596
593 self.type = "SpectraHeis"
597 self.type = "SpectraHeis"
594
598
595 # self.dtype = None
599 # self.dtype = None
596
600
597 # self.nChannels = 0
601 # self.nChannels = 0
598
602
599 # self.nHeights = 0
603 # self.nHeights = 0
600
604
601 self.nProfiles = None
605 self.nProfiles = None
602
606
603 self.heightList = None
607 self.heightList = None
604
608
605 self.channelList = None
609 self.channelList = None
606
610
607 # self.channelIndexList = None
611 # self.channelIndexList = None
608
612
609 self.flagNoData = True
613 self.flagNoData = True
610
614
611 self.flagTimeBlock = False
615 self.flagTimeBlock = False
612
616
613 # self.nPairs = 0
617 # self.nPairs = 0
614
618
615 self.utctime = None
619 self.utctime = None
616
620
617 self.blocksize = None
621 self.blocksize = None
618
622
619 self.profileIndex = 0
623 self.profileIndex = 0
620
624
621 def getNormFactor(self):
625 def getNormFactor(self):
622 pwcode = 1
626 pwcode = 1
623 if self.flagDecodeData:
627 if self.flagDecodeData:
624 pwcode = numpy.sum(self.code[0]**2)
628 pwcode = numpy.sum(self.code[0]**2)
625
629
626 normFactor = self.nIncohInt*self.nCohInt*pwcode
630 normFactor = self.nIncohInt*self.nCohInt*pwcode
627
631
628 return normFactor
632 return normFactor
629
633
630 def getTimeInterval(self):
634 def getTimeInterval(self):
631
635
632 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
636 timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt
633
637
634 return timeInterval
638 return timeInterval
635
639
636 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
640 normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.")
637 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
641 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
638
642
639 class Fits:
643 class Fits:
640
644
641 heightList = None
645 heightList = None
642
646
643 channelList = None
647 channelList = None
644
648
645 flagNoData = True
649 flagNoData = True
646
650
647 flagTimeBlock = False
651 flagTimeBlock = False
648
652
649 useLocalTime = False
653 useLocalTime = False
650
654
651 utctime = None
655 utctime = None
652
656
653 timeZone = None
657 timeZone = None
654
658
655 # ippSeconds = None
659 # ippSeconds = None
656
660
657 # timeInterval = None
661 # timeInterval = None
658
662
659 nCohInt = None
663 nCohInt = None
660
664
661 nIncohInt = None
665 nIncohInt = None
662
666
663 noise = None
667 noise = None
664
668
665 windowOfFilter = 1
669 windowOfFilter = 1
666
670
667 #Speed of ligth
671 #Speed of ligth
668 C = 3e8
672 C = 3e8
669
673
670 frequency = 49.92e6
674 frequency = 49.92e6
671
675
672 realtime = False
676 realtime = False
673
677
674
678
675 def __init__(self):
679 def __init__(self):
676
680
677 self.type = "Fits"
681 self.type = "Fits"
678
682
679 self.nProfiles = None
683 self.nProfiles = None
680
684
681 self.heightList = None
685 self.heightList = None
682
686
683 self.channelList = None
687 self.channelList = None
684
688
685 # self.channelIndexList = None
689 # self.channelIndexList = None
686
690
687 self.flagNoData = True
691 self.flagNoData = True
688
692
689 self.utctime = None
693 self.utctime = None
690
694
691 self.nCohInt = None
695 self.nCohInt = None
692
696
693 self.nIncohInt = None
697 self.nIncohInt = None
694
698
695 self.useLocalTime = True
699 self.useLocalTime = True
696
700
697 self.profileIndex = 0
701 self.profileIndex = 0
698
702
699 # self.utctime = None
703 # self.utctime = None
700 # self.timeZone = None
704 # self.timeZone = None
701 # self.ltctime = None
705 # self.ltctime = None
702 # self.timeInterval = None
706 # self.timeInterval = None
703 # self.header = None
707 # self.header = None
704 # self.data_header = None
708 # self.data_header = None
705 # self.data = None
709 # self.data = None
706 # self.datatime = None
710 # self.datatime = None
707 # self.flagNoData = False
711 # self.flagNoData = False
708 # self.expName = ''
712 # self.expName = ''
709 # self.nChannels = None
713 # self.nChannels = None
710 # self.nSamples = None
714 # self.nSamples = None
711 # self.dataBlocksPerFile = None
715 # self.dataBlocksPerFile = None
712 # self.comments = ''
716 # self.comments = ''
713 #
717 #
714
718
715
719
716 def getltctime(self):
720 def getltctime(self):
717
721
718 if self.useLocalTime:
722 if self.useLocalTime:
719 return self.utctime - self.timeZone*60
723 return self.utctime - self.timeZone*60
720
724
721 return self.utctime
725 return self.utctime
722
726
723 def getDatatime(self):
727 def getDatatime(self):
724
728
725 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
729 datatime = datetime.datetime.utcfromtimestamp(self.ltctime)
726 return datatime
730 return datatime
727
731
728 def getTimeRange(self):
732 def getTimeRange(self):
729
733
730 datatime = []
734 datatime = []
731
735
732 datatime.append(self.ltctime)
736 datatime.append(self.ltctime)
733 datatime.append(self.ltctime + self.timeInterval)
737 datatime.append(self.ltctime + self.timeInterval)
734
738
735 datatime = numpy.array(datatime)
739 datatime = numpy.array(datatime)
736
740
737 return datatime
741 return datatime
738
742
739 def getHeiRange(self):
743 def getHeiRange(self):
740
744
741 heis = self.heightList
745 heis = self.heightList
742
746
743 return heis
747 return heis
744
748
745 def isEmpty(self):
749 def isEmpty(self):
746
750
747 return self.flagNoData
751 return self.flagNoData
748
752
749 def getNHeights(self):
753 def getNHeights(self):
750
754
751 return len(self.heightList)
755 return len(self.heightList)
752
756
753 def getNChannels(self):
757 def getNChannels(self):
754
758
755 return len(self.channelList)
759 return len(self.channelList)
756
760
757 def getChannelIndexList(self):
761 def getChannelIndexList(self):
758
762
759 return range(self.nChannels)
763 return range(self.nChannels)
760
764
761 def getNoise(self, type = 1):
765 def getNoise(self, type = 1):
762
766
763 self.noise = numpy.zeros(self.nChannels)
767 self.noise = numpy.zeros(self.nChannels)
764
768
765 if type == 1:
769 if type == 1:
766 noise = self.getNoisebyHildebrand()
770 noise = self.getNoisebyHildebrand()
767
771
768 if type == 2:
772 if type == 2:
769 noise = self.getNoisebySort()
773 noise = self.getNoisebySort()
770
774
771 if type == 3:
775 if type == 3:
772 noise = self.getNoisebyWindow()
776 noise = self.getNoisebyWindow()
773
777
774 return noise
778 return noise
775
779
776 def getTimeInterval(self):
780 def getTimeInterval(self):
777
781
778 raise ValueError, "This method is not implemented yet"
782 raise ValueError, "This method is not implemented yet"
779
783
780 datatime = property(getDatatime, "I'm the 'datatime' property")
784 datatime = property(getDatatime, "I'm the 'datatime' property")
781 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
785 nHeights = property(getNHeights, "I'm the 'nHeights' property.")
782 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
786 nChannels = property(getNChannels, "I'm the 'nChannel' property.")
783 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
787 channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.")
784 noise = property(getNoise, "I'm the 'nHeights' property.")
788 noise = property(getNoise, "I'm the 'nHeights' property.")
785 datatime = property(getDatatime, "I'm the 'datatime' property")
789 datatime = property(getDatatime, "I'm the 'datatime' property")
786 ltctime = property(getltctime, "I'm the 'ltctime' property")
790 ltctime = property(getltctime, "I'm the 'ltctime' property")
787 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
791 timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property")
788
792
789 class Correlation(JROData):
793 class Correlation(JROData):
790
794
791 noise = None
795 noise = None
792
796
793 SNR = None
797 SNR = None
794
798
795 pairsAutoCorr = None #Pairs of Autocorrelation
799 pairsAutoCorr = None #Pairs of Autocorrelation
796
800
797 #--------------------------------------------------
801 #--------------------------------------------------
798
802
799 data_corr = None
803 data_corr = None
800
804
801 data_volt = None
805 data_volt = None
802
806
803 lagT = None # each element value is a profileIndex
807 lagT = None # each element value is a profileIndex
804
808
805 lagR = None # each element value is in km
809 lagR = None # each element value is in km
806
810
807 pairsList = None
811 pairsList = None
808
812
809 calculateVelocity = None
813 calculateVelocity = None
810
814
811 nPoints = None
815 nPoints = None
812
816
813 nAvg = None
817 nAvg = None
814
818
815 bufferSize = None
819 bufferSize = None
816
820
817 def __init__(self):
821 def __init__(self):
818 '''
822 '''
819 Constructor
823 Constructor
820 '''
824 '''
821 self.radarControllerHeaderObj = RadarControllerHeader()
825 self.radarControllerHeaderObj = RadarControllerHeader()
822
826
823 self.systemHeaderObj = SystemHeader()
827 self.systemHeaderObj = SystemHeader()
824
828
825 self.type = "Correlation"
829 self.type = "Correlation"
826
830
827 self.data = None
831 self.data = None
828
832
829 self.dtype = None
833 self.dtype = None
830
834
831 self.nProfiles = None
835 self.nProfiles = None
832
836
833 self.heightList = None
837 self.heightList = None
834
838
835 self.channelList = None
839 self.channelList = None
836
840
837 self.flagNoData = True
841 self.flagNoData = True
838
842
839 self.flagTimeBlock = False
843 self.flagTimeBlock = False
840
844
841 self.utctime = None
845 self.utctime = None
842
846
843 self.timeZone = None
847 self.timeZone = None
844
848
845 self.dstFlag = None
849 self.dstFlag = None
846
850
847 self.errorCount = None
851 self.errorCount = None
848
852
849 self.blocksize = None
853 self.blocksize = None
850
854
851 self.flagDecodeData = False #asumo q la data no esta decodificada
855 self.flagDecodeData = False #asumo q la data no esta decodificada
852
856
853 self.flagDeflipData = False #asumo q la data no esta sin flip
857 self.flagDeflipData = False #asumo q la data no esta sin flip
854
858
855 self.pairsList = None
859 self.pairsList = None
856
860
857 self.nPoints = None
861 self.nPoints = None
858
862
859 def getLagTRange(self, extrapoints=0):
863 def getLagTRange(self, extrapoints=0):
860
864
861 lagTRange = self.lagT
865 lagTRange = self.lagT
862 diff = lagTRange[1] - lagTRange[0]
866 diff = lagTRange[1] - lagTRange[0]
863 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
867 extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1]
864 lagTRange = numpy.hstack((lagTRange, extra))
868 lagTRange = numpy.hstack((lagTRange, extra))
865
869
866 return lagTRange
870 return lagTRange
867
871
868 def getLagRRange(self, extrapoints=0):
872 def getLagRRange(self, extrapoints=0):
869
873
870 return self.lagR
874 return self.lagR
871
875
872 def getPairsList(self):
876 def getPairsList(self):
873
877
874 return self.pairsList
878 return self.pairsList
875
879
876 def getCalculateVelocity(self):
880 def getCalculateVelocity(self):
877
881
878 return self.calculateVelocity
882 return self.calculateVelocity
879
883
880 def getNPoints(self):
884 def getNPoints(self):
881
885
882 return self.nPoints
886 return self.nPoints
883
887
884 def getNAvg(self):
888 def getNAvg(self):
885
889
886 return self.nAvg
890 return self.nAvg
887
891
888 def getBufferSize(self):
892 def getBufferSize(self):
889
893
890 return self.bufferSize
894 return self.bufferSize
891
895
892 def getPairsAutoCorr(self):
896 def getPairsAutoCorr(self):
893 pairsList = self.pairsList
897 pairsList = self.pairsList
894 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
898 pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan
895
899
896 for l in range(len(pairsList)):
900 for l in range(len(pairsList)):
897 firstChannel = pairsList[l][0]
901 firstChannel = pairsList[l][0]
898 secondChannel = pairsList[l][1]
902 secondChannel = pairsList[l][1]
899
903
900 #Obteniendo pares de Autocorrelacion
904 #Obteniendo pares de Autocorrelacion
901 if firstChannel == secondChannel:
905 if firstChannel == secondChannel:
902 pairsAutoCorr[firstChannel] = int(l)
906 pairsAutoCorr[firstChannel] = int(l)
903
907
904 pairsAutoCorr = pairsAutoCorr.astype(int)
908 pairsAutoCorr = pairsAutoCorr.astype(int)
905
909
906 return pairsAutoCorr
910 return pairsAutoCorr
907
911
908 def getNoise(self, mode = 2):
912 def getNoise(self, mode = 2):
909
913
910 indR = numpy.where(self.lagR == 0)[0][0]
914 indR = numpy.where(self.lagR == 0)[0][0]
911 indT = numpy.where(self.lagT == 0)[0][0]
915 indT = numpy.where(self.lagT == 0)[0][0]
912
916
913 jspectra0 = self.data_corr[:,:,indR,:]
917 jspectra0 = self.data_corr[:,:,indR,:]
914 jspectra = copy.copy(jspectra0)
918 jspectra = copy.copy(jspectra0)
915
919
916 num_chan = jspectra.shape[0]
920 num_chan = jspectra.shape[0]
917 num_hei = jspectra.shape[2]
921 num_hei = jspectra.shape[2]
918
922
919 freq_dc = jspectra.shape[1]/2
923 freq_dc = jspectra.shape[1]/2
920 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
924 ind_vel = numpy.array([-2,-1,1,2]) + freq_dc
921
925
922 if ind_vel[0]<0:
926 if ind_vel[0]<0:
923 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
927 ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof
924
928
925 if mode == 1:
929 if mode == 1:
926 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
930 jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION
927
931
928 if mode == 2:
932 if mode == 2:
929
933
930 vel = numpy.array([-2,-1,1,2])
934 vel = numpy.array([-2,-1,1,2])
931 xx = numpy.zeros([4,4])
935 xx = numpy.zeros([4,4])
932
936
933 for fil in range(4):
937 for fil in range(4):
934 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
938 xx[fil,:] = vel[fil]**numpy.asarray(range(4))
935
939
936 xx_inv = numpy.linalg.inv(xx)
940 xx_inv = numpy.linalg.inv(xx)
937 xx_aux = xx_inv[0,:]
941 xx_aux = xx_inv[0,:]
938
942
939 for ich in range(num_chan):
943 for ich in range(num_chan):
940 yy = jspectra[ich,ind_vel,:]
944 yy = jspectra[ich,ind_vel,:]
941 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
945 jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy)
942
946
943 junkid = jspectra[ich,freq_dc,:]<=0
947 junkid = jspectra[ich,freq_dc,:]<=0
944 cjunkid = sum(junkid)
948 cjunkid = sum(junkid)
945
949
946 if cjunkid.any():
950 if cjunkid.any():
947 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
951 jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2
948
952
949 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
953 noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:]
950
954
951 return noise
955 return noise
952
956
953 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
957 # pairsList = property(getPairsList, "I'm the 'pairsList' property.")
954 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
958 # nPoints = property(getNPoints, "I'm the 'nPoints' property.")
955 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
959 calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.")
956 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
960 nAvg = property(getNAvg, "I'm the 'nAvg' property.")
957 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
961 bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.")
958
962
959
963
960 class Parameters(JROData):
964 class Parameters(JROData):
961
965
962 #Information from previous data
966 #Information from previous data
963
967
964 inputUnit = None #Type of data to be processed
968 inputUnit = None #Type of data to be processed
965
969
966 operation = None #Type of operation to parametrize
970 operation = None #Type of operation to parametrize
967
971
968 normFactor = None #Normalization Factor
972 normFactor = None #Normalization Factor
969
973
970 groupList = None #List of Pairs, Groups, etc
974 groupList = None #List of Pairs, Groups, etc
971
975
972 #Parameters
976 #Parameters
973
977
974 data_param = None #Parameters obtained
978 data_param = None #Parameters obtained
975
979
976 data_pre = None #Data Pre Parametrization
980 data_pre = None #Data Pre Parametrization
977
981
978 data_SNR = None #Signal to Noise Ratio
982 data_SNR = None #Signal to Noise Ratio
979
983
980 heightRange = None #Heights
984 heightRange = None #Heights
981
985
982 abscissaRange = None #Abscissa, can be velocities, lags or time
986 abscissaRange = None #Abscissa, can be velocities, lags or time
983
987
984 noise = None #Noise Potency
988 noise = None #Noise Potency
985
989
986 utctimeInit = None #Initial UTC time
990 utctimeInit = None #Initial UTC time
987
991
988 paramInterval = None #Time interval to calculate Parameters in seconds
992 paramInterval = None #Time interval to calculate Parameters in seconds
989
993
990 #Fitting
994 #Fitting
991
995
992 data_error = None #Error of the estimation
996 data_error = None #Error of the estimation
993
997
994 constants = None
998 constants = None
995
999
996 library = None
1000 library = None
997
1001
998 #Output signal
1002 #Output signal
999
1003
1000 outputInterval = None #Time interval to calculate output signal in seconds
1004 outputInterval = None #Time interval to calculate output signal in seconds
1001
1005
1002 data_output = None #Out signal
1006 data_output = None #Out signal
1003
1007
1004
1008
1005
1009
1006 def __init__(self):
1010 def __init__(self):
1007 '''
1011 '''
1008 Constructor
1012 Constructor
1009 '''
1013 '''
1010 self.radarControllerHeaderObj = RadarControllerHeader()
1014 self.radarControllerHeaderObj = RadarControllerHeader()
1011
1015
1012 self.systemHeaderObj = SystemHeader()
1016 self.systemHeaderObj = SystemHeader()
1013
1017
1014 self.type = "Parameters"
1018 self.type = "Parameters"
1015
1019
1016 def getTimeRange1(self):
1020 def getTimeRange1(self):
1017
1021
1018 datatime = []
1022 datatime = []
1019
1023
1020 datatime.append(self.utctimeInit)
1024 datatime.append(self.utctimeInit)
1021 datatime.append(self.utctimeInit + self.outputInterval - 1)
1025 datatime.append(self.utctimeInit + self.outputInterval - 1)
1022
1026
1023 datatime = numpy.array(datatime)
1027 datatime = numpy.array(datatime)
1024
1028
1025 return datatime
1029 return datatime
@@ -1,607 +1,607
1 import os
1 import os
2 import numpy
2 import numpy
3 import time, datetime
3 import time, datetime
4 import mpldriver
4 import mpldriver
5
5
6
6
7 import Queue
7 import Queue
8 import threading
8 import threading
9
9
10 def isRealtime(utcdatatime):
10 def isRealtime(utcdatatime):
11 utcnow = time.mktime(time.localtime())
11 utcnow = time.mktime(time.localtime())
12 delta = abs(utcnow - utcdatatime) # abs
12 delta = abs(utcnow - utcdatatime) # abs
13 if delta >= 30.:
13 if delta >= 30.:
14 return False
14 return False
15 return True
15 return True
16
16
17
17
18
18
19
19
20 class Figure:
20 class Figure:
21
21
22 __driver = mpldriver
22 __driver = mpldriver
23 __isConfigThread = False
23 __isConfigThread = False
24 fig = None
24 fig = None
25
25
26 id = None
26 id = None
27 wintitle = None
27 wintitle = None
28 width = None
28 width = None
29 height = None
29 height = None
30 nplots = None
30 nplots = None
31 timerange = None
31 timerange = None
32
32
33 axesObjList = []
33 axesObjList = []
34
34
35 WIDTH = None
35 WIDTH = None
36 HEIGHT = None
36 HEIGHT = None
37 PREFIX = 'fig'
37 PREFIX = 'fig'
38
38
39 xmin = None
39 xmin = None
40 xmax = None
40 xmax = None
41
41
42 def __init__(self):
42 def __init__(self):
43
43
44 raise ValueError, "This method is not implemented"
44 raise ValueError, "This method is not implemented"
45
45
46 def __del__(self):
46 def __del__(self):
47
47
48 self.__driver.closeFigure()
48 self.__driver.closeFigure()
49
49
50 def getFilename(self, name, ext='.png'):
50 def getFilename(self, name, ext='.png'):
51
51
52 path = '%s%03d' %(self.PREFIX, self.id)
52 path = '%s%03d' %(self.PREFIX, self.id)
53 filename = '%s_%s%s' %(self.PREFIX, name, ext)
53 filename = '%s_%s%s' %(self.PREFIX, name, ext)
54 return os.path.join(path, filename)
54 return os.path.join(path, filename)
55
55
56 def getAxesObjList(self):
56 def getAxesObjList(self):
57
57
58 return self.axesObjList
58 return self.axesObjList
59
59
60 def getSubplots(self):
60 def getSubplots(self):
61
61
62 raise ValueError, "Abstract method: This method should be defined"
62 raise ValueError, "Abstract method: This method should be defined"
63
63
64 def getScreenDim(self, widthplot, heightplot):
64 def getScreenDim(self, widthplot, heightplot):
65
65
66 nrow, ncol = self.getSubplots()
66 nrow, ncol = self.getSubplots()
67
67
68 widthscreen = widthplot*ncol
68 widthscreen = widthplot*ncol
69 heightscreen = heightplot*nrow
69 heightscreen = heightplot*nrow
70
70
71 return widthscreen, heightscreen
71 return widthscreen, heightscreen
72
72
73 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None, timezone=0):
73 def getTimeLim(self, x, xmin=None, xmax=None, timerange=None, timezone=0):
74
74
75 if self.xmin != None and self.xmax != None:
75 if self.xmin != None and self.xmax != None:
76 if timerange == None:
76 if timerange == None:
77 timerange = self.xmax - self.xmin
77 timerange = self.xmax - self.xmin
78 xmin = self.xmin + timerange
78 xmin = self.xmin + timerange
79 xmax = self.xmax + timerange
79 xmax = self.xmax + timerange
80
80
81 return xmin, xmax
81 return xmin, xmax
82
82
83
83
84 if timerange != None and self.xmin == None and self.xmax == None:
84 if timerange != None and self.xmin == None and self.xmax == None:
85 txmin = x[0] - x[0]%timerange
85 txmin = x[0] - x[0]%timerange
86 else:
86 else:
87 txmin = numpy.min(x)
87 txmin = numpy.min(x)
88 timerange = self.timerange
88 timerange = self.timerange
89
89 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
90 thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
90 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
91 thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
92
91 if xmin == None and xmax == None:
93 if xmin == None and xmax == None:
92 xmin = (thisdatetime - thisdate).seconds/(60*60.)
94 xmin = (thisdatetime - thisdate).seconds/(60*60.)
93 xmax = xmin + timerange/(60*60.)
95 xmax = xmin + timerange/(60*60.)
94
95
96
96
97 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=timezone)
97 mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
98 xmin_sec = time.mktime(mindt.timetuple())
98 xmin_sec = time.mktime(mindt.timetuple())
99
99
100 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=timezone)
100 maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
101 xmax_sec = time.mktime(maxdt.timetuple())
101 xmax_sec = time.mktime(maxdt.timetuple())
102
102
103 return xmin_sec, xmax_sec
103 return xmin_sec, xmax_sec
104
104
105
105
106
106
107
107
108
108
109 # if timerange != None:
109 # if timerange != None:
110 # txmin = x[0] - x[0]%timerange
110 # txmin = x[0] - x[0]%timerange
111 # else:
111 # else:
112 # txmin = numpy.min(x)
112 # txmin = numpy.min(x)
113 #
113 #
114 # thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
114 # thisdatetime = datetime.datetime.utcfromtimestamp(txmin)
115 # thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
115 # thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0))
116 #
116 #
117 # ####################################################
117 # ####################################################
118 # #If the x is out of xrange
118 # #If the x is out of xrange
119 # if xmax != None:
119 # if xmax != None:
120 # if xmax < (thisdatetime - thisdate).seconds/(60*60.):
120 # if xmax < (thisdatetime - thisdate).seconds/(60*60.):
121 # xmin = None
121 # xmin = None
122 # xmax = None
122 # xmax = None
123 #
123 #
124 # if xmin == None:
124 # if xmin == None:
125 # td = thisdatetime - thisdate
125 # td = thisdatetime - thisdate
126 # xmin = td.seconds/(60*60.)
126 # xmin = td.seconds/(60*60.)
127 #
127 #
128 # if xmax == None:
128 # if xmax == None:
129 # xmax = xmin + self.timerange/(60*60.)
129 # xmax = xmin + self.timerange/(60*60.)
130 #
130 #
131 # mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
131 # mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone)
132 # tmin = time.mktime(mindt.timetuple())
132 # tmin = time.mktime(mindt.timetuple())
133 #
133 #
134 # maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
134 # maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone)
135 # tmax = time.mktime(maxdt.timetuple())
135 # tmax = time.mktime(maxdt.timetuple())
136 #
136 #
137 # #self.timerange = tmax - tmin
137 # #self.timerange = tmax - tmin
138 #
138 #
139 # return tmin, tmax
139 # return tmin, tmax
140
140
141 def init(self, id, nplots, wintitle):
141 def init(self, id, nplots, wintitle):
142
142
143 raise ValueError, "This method has been replaced with createFigure"
143 raise ValueError, "This method has been replaced with createFigure"
144
144
145 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
145 def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True):
146
146
147 """
147 """
148 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
148 Crea la figura de acuerdo al driver y parametros seleccionados seleccionados.
149 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
149 Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH
150 y self.HEIGHT y el numero de subplots (nrow, ncol)
150 y self.HEIGHT y el numero de subplots (nrow, ncol)
151
151
152 Input:
152 Input:
153 id : Los parametros necesarios son
153 id : Los parametros necesarios son
154 wintitle :
154 wintitle :
155
155
156 """
156 """
157
157
158 if widthplot == None:
158 if widthplot == None:
159 widthplot = self.WIDTH
159 widthplot = self.WIDTH
160
160
161 if heightplot == None:
161 if heightplot == None:
162 heightplot = self.HEIGHT
162 heightplot = self.HEIGHT
163
163
164 self.id = id
164 self.id = id
165
165
166 self.wintitle = wintitle
166 self.wintitle = wintitle
167
167
168 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
168 self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot)
169
169
170 self.fig = self.__driver.createFigure(id=self.id,
170 self.fig = self.__driver.createFigure(id=self.id,
171 wintitle=self.wintitle,
171 wintitle=self.wintitle,
172 width=self.widthscreen,
172 width=self.widthscreen,
173 height=self.heightscreen,
173 height=self.heightscreen,
174 show=show)
174 show=show)
175
175
176 self.axesObjList = []
176 self.axesObjList = []
177
177
178
178
179 def setDriver(self, driver=mpldriver):
179 def setDriver(self, driver=mpldriver):
180
180
181 self.__driver = driver
181 self.__driver = driver
182
182
183 def setTitle(self, title):
183 def setTitle(self, title):
184
184
185 self.__driver.setTitle(self.fig, title)
185 self.__driver.setTitle(self.fig, title)
186
186
187 def setWinTitle(self, title):
187 def setWinTitle(self, title):
188
188
189 self.__driver.setWinTitle(self.fig, title=title)
189 self.__driver.setWinTitle(self.fig, title=title)
190
190
191 def setTextFromAxes(self, text):
191 def setTextFromAxes(self, text):
192
192
193 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
193 raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes"
194
194
195 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
195 def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan):
196
196
197 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
197 raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes"
198
198
199 def addAxes(self, *args):
199 def addAxes(self, *args):
200 """
200 """
201
201
202 Input:
202 Input:
203 *args : Los parametros necesarios son
203 *args : Los parametros necesarios son
204 nrow, ncol, xpos, ypos, colspan, rowspan
204 nrow, ncol, xpos, ypos, colspan, rowspan
205 """
205 """
206
206
207 axesObj = Axes(self.fig, *args)
207 axesObj = Axes(self.fig, *args)
208 self.axesObjList.append(axesObj)
208 self.axesObjList.append(axesObj)
209
209
210 def saveFigure(self, figpath, figfile, *args):
210 def saveFigure(self, figpath, figfile, *args):
211
211
212 filename = os.path.join(figpath, figfile)
212 filename = os.path.join(figpath, figfile)
213
213
214 fullpath = os.path.split(filename)[0]
214 fullpath = os.path.split(filename)[0]
215
215
216 if not os.path.exists(fullpath):
216 if not os.path.exists(fullpath):
217 subpath = os.path.split(fullpath)[0]
217 subpath = os.path.split(fullpath)[0]
218
218
219 if not os.path.exists(subpath):
219 if not os.path.exists(subpath):
220 os.mkdir(subpath)
220 os.mkdir(subpath)
221
221
222 os.mkdir(fullpath)
222 os.mkdir(fullpath)
223
223
224 self.__driver.saveFigure(self.fig, filename, *args)
224 self.__driver.saveFigure(self.fig, filename, *args)
225
225
226
226
227
227
228
228
229 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
229 def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS):
230 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
230 YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year
231 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
231 DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday
232 FTP_WEI = '%2.2d'%FTP_WEI
232 FTP_WEI = '%2.2d'%FTP_WEI
233 EXP_CODE = '%3.3d'%EXP_CODE
233 EXP_CODE = '%3.3d'%EXP_CODE
234 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
234 SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE
235 PLOT_CODE = '%2.2d'%PLOT_CODE
235 PLOT_CODE = '%2.2d'%PLOT_CODE
236 PLOT_POS = '%2.2d'%PLOT_POS
236 PLOT_POS = '%2.2d'%PLOT_POS
237 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
237 name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS
238 return name
238 return name
239
239
240 def draw(self):
240 def draw(self):
241
241
242 self.__driver.draw(self.fig)
242 self.__driver.draw(self.fig)
243
243
244 def run(self):
244 def run(self):
245
245
246 raise ValueError, "This method is not implemented"
246 raise ValueError, "This method is not implemented"
247
247
248 def close(self):
248 def close(self):
249
249
250 self.__driver.show(True)
250 self.__driver.show(True)
251
251
252 axesList = property(getAxesObjList)
252 axesList = property(getAxesObjList)
253
253
254
254
255 class Axes:
255 class Axes:
256
256
257 __driver = mpldriver
257 __driver = mpldriver
258 fig = None
258 fig = None
259 ax = None
259 ax = None
260 plot = None
260 plot = None
261 __missing = 1E30
261 __missing = 1E30
262 __firsttime = None
262 __firsttime = None
263
263
264 __showprofile = False
264 __showprofile = False
265
265
266 xmin = None
266 xmin = None
267 xmax = None
267 xmax = None
268 ymin = None
268 ymin = None
269 ymax = None
269 ymax = None
270 zmin = None
270 zmin = None
271 zmax = None
271 zmax = None
272
272
273 x_buffer = None
273 x_buffer = None
274 z_buffer = None
274 z_buffer = None
275
275
276 decimationx = None
276 decimationx = None
277 decimationy = None
277 decimationy = None
278
278
279 __MAXNUMX = 300
279 __MAXNUMX = 300
280 __MAXNUMY = 150
280 __MAXNUMY = 150
281
281
282 def __init__(self, *args):
282 def __init__(self, *args):
283
283
284 """
284 """
285
285
286 Input:
286 Input:
287 *args : Los parametros necesarios son
287 *args : Los parametros necesarios son
288 fig, nrow, ncol, xpos, ypos, colspan, rowspan
288 fig, nrow, ncol, xpos, ypos, colspan, rowspan
289 """
289 """
290
290
291 ax = self.__driver.createAxes(*args)
291 ax = self.__driver.createAxes(*args)
292 self.fig = args[0]
292 self.fig = args[0]
293 self.ax = ax
293 self.ax = ax
294 self.plot = None
294 self.plot = None
295
295
296 self.__firsttime = True
296 self.__firsttime = True
297 self.idlineList = []
297 self.idlineList = []
298
298
299 self.x_buffer = numpy.array([])
299 self.x_buffer = numpy.array([])
300 self.z_buffer = numpy.array([])
300 self.z_buffer = numpy.array([])
301
301
302 def setText(self, text):
302 def setText(self, text):
303
303
304 self.__driver.setAxesText(self.ax, text)
304 self.__driver.setAxesText(self.ax, text)
305
305
306 def setXAxisAsTime(self):
306 def setXAxisAsTime(self):
307 pass
307 pass
308
308
309 def pline(self, x, y,
309 def pline(self, x, y,
310 xmin=None, xmax=None,
310 xmin=None, xmax=None,
311 ymin=None, ymax=None,
311 ymin=None, ymax=None,
312 xlabel='', ylabel='',
312 xlabel='', ylabel='',
313 title='',
313 title='',
314 **kwargs):
314 **kwargs):
315
315
316 """
316 """
317
317
318 Input:
318 Input:
319 x :
319 x :
320 y :
320 y :
321 xmin :
321 xmin :
322 xmax :
322 xmax :
323 ymin :
323 ymin :
324 ymax :
324 ymax :
325 xlabel :
325 xlabel :
326 ylabel :
326 ylabel :
327 title :
327 title :
328 **kwargs : Los parametros aceptados son
328 **kwargs : Los parametros aceptados son
329
329
330 ticksize
330 ticksize
331 ytick_visible
331 ytick_visible
332 """
332 """
333
333
334 if self.__firsttime:
334 if self.__firsttime:
335
335
336 if xmin == None: xmin = numpy.nanmin(x)
336 if xmin == None: xmin = numpy.nanmin(x)
337 if xmax == None: xmax = numpy.nanmax(x)
337 if xmax == None: xmax = numpy.nanmax(x)
338 if ymin == None: ymin = numpy.nanmin(y)
338 if ymin == None: ymin = numpy.nanmin(y)
339 if ymax == None: ymax = numpy.nanmax(y)
339 if ymax == None: ymax = numpy.nanmax(y)
340
340
341 self.plot = self.__driver.createPline(self.ax, x, y,
341 self.plot = self.__driver.createPline(self.ax, x, y,
342 xmin, xmax,
342 xmin, xmax,
343 ymin, ymax,
343 ymin, ymax,
344 xlabel=xlabel,
344 xlabel=xlabel,
345 ylabel=ylabel,
345 ylabel=ylabel,
346 title=title,
346 title=title,
347 **kwargs)
347 **kwargs)
348
348
349 self.idlineList.append(0)
349 self.idlineList.append(0)
350 self.__firsttime = False
350 self.__firsttime = False
351 return
351 return
352
352
353 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
353 self.__driver.pline(self.plot, x, y, xlabel=xlabel,
354 ylabel=ylabel,
354 ylabel=ylabel,
355 title=title)
355 title=title)
356
356
357 def addpline(self, x, y, idline, **kwargs):
357 def addpline(self, x, y, idline, **kwargs):
358 lines = self.ax.lines
358 lines = self.ax.lines
359
359
360 if idline in self.idlineList:
360 if idline in self.idlineList:
361 self.__driver.set_linedata(self.ax, x, y, idline)
361 self.__driver.set_linedata(self.ax, x, y, idline)
362
362
363 if idline not in(self.idlineList):
363 if idline not in(self.idlineList):
364 self.__driver.addpline(self.ax, x, y, **kwargs)
364 self.__driver.addpline(self.ax, x, y, **kwargs)
365 self.idlineList.append(idline)
365 self.idlineList.append(idline)
366
366
367 return
367 return
368
368
369 def pmultiline(self, x, y,
369 def pmultiline(self, x, y,
370 xmin=None, xmax=None,
370 xmin=None, xmax=None,
371 ymin=None, ymax=None,
371 ymin=None, ymax=None,
372 xlabel='', ylabel='',
372 xlabel='', ylabel='',
373 title='',
373 title='',
374 **kwargs):
374 **kwargs):
375
375
376 if self.__firsttime:
376 if self.__firsttime:
377
377
378 if xmin == None: xmin = numpy.nanmin(x)
378 if xmin == None: xmin = numpy.nanmin(x)
379 if xmax == None: xmax = numpy.nanmax(x)
379 if xmax == None: xmax = numpy.nanmax(x)
380 if ymin == None: ymin = numpy.nanmin(y)
380 if ymin == None: ymin = numpy.nanmin(y)
381 if ymax == None: ymax = numpy.nanmax(y)
381 if ymax == None: ymax = numpy.nanmax(y)
382
382
383 self.plot = self.__driver.createPmultiline(self.ax, x, y,
383 self.plot = self.__driver.createPmultiline(self.ax, x, y,
384 xmin, xmax,
384 xmin, xmax,
385 ymin, ymax,
385 ymin, ymax,
386 xlabel=xlabel,
386 xlabel=xlabel,
387 ylabel=ylabel,
387 ylabel=ylabel,
388 title=title,
388 title=title,
389 **kwargs)
389 **kwargs)
390 self.__firsttime = False
390 self.__firsttime = False
391 return
391 return
392
392
393 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
393 self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel,
394 ylabel=ylabel,
394 ylabel=ylabel,
395 title=title)
395 title=title)
396
396
397 def pmultilineyaxis(self, x, y,
397 def pmultilineyaxis(self, x, y,
398 xmin=None, xmax=None,
398 xmin=None, xmax=None,
399 ymin=None, ymax=None,
399 ymin=None, ymax=None,
400 xlabel='', ylabel='',
400 xlabel='', ylabel='',
401 title='',
401 title='',
402 **kwargs):
402 **kwargs):
403
403
404 if self.__firsttime:
404 if self.__firsttime:
405
405
406 if xmin == None: xmin = numpy.nanmin(x)
406 if xmin == None: xmin = numpy.nanmin(x)
407 if xmax == None: xmax = numpy.nanmax(x)
407 if xmax == None: xmax = numpy.nanmax(x)
408 if ymin == None: ymin = numpy.nanmin(y)
408 if ymin == None: ymin = numpy.nanmin(y)
409 if ymax == None: ymax = numpy.nanmax(y)
409 if ymax == None: ymax = numpy.nanmax(y)
410
410
411 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
411 self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y,
412 xmin, xmax,
412 xmin, xmax,
413 ymin, ymax,
413 ymin, ymax,
414 xlabel=xlabel,
414 xlabel=xlabel,
415 ylabel=ylabel,
415 ylabel=ylabel,
416 title=title,
416 title=title,
417 **kwargs)
417 **kwargs)
418 if self.xmin == None: self.xmin = xmin
418 if self.xmin == None: self.xmin = xmin
419 if self.xmax == None: self.xmax = xmax
419 if self.xmax == None: self.xmax = xmax
420 if self.ymin == None: self.ymin = ymin
420 if self.ymin == None: self.ymin = ymin
421 if self.ymax == None: self.ymax = ymax
421 if self.ymax == None: self.ymax = ymax
422
422
423 self.__firsttime = False
423 self.__firsttime = False
424 return
424 return
425
425
426 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
426 self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel,
427 ylabel=ylabel,
427 ylabel=ylabel,
428 title=title)
428 title=title)
429
429
430 def pcolor(self, x, y, z,
430 def pcolor(self, x, y, z,
431 xmin=None, xmax=None,
431 xmin=None, xmax=None,
432 ymin=None, ymax=None,
432 ymin=None, ymax=None,
433 zmin=None, zmax=None,
433 zmin=None, zmax=None,
434 xlabel='', ylabel='',
434 xlabel='', ylabel='',
435 title='', rti = False, colormap='jet',
435 title='', rti = False, colormap='jet',
436 **kwargs):
436 **kwargs):
437
437
438 """
438 """
439 Input:
439 Input:
440 x :
440 x :
441 y :
441 y :
442 x :
442 x :
443 xmin :
443 xmin :
444 xmax :
444 xmax :
445 ymin :
445 ymin :
446 ymax :
446 ymax :
447 zmin :
447 zmin :
448 zmax :
448 zmax :
449 xlabel :
449 xlabel :
450 ylabel :
450 ylabel :
451 title :
451 title :
452 **kwargs : Los parametros aceptados son
452 **kwargs : Los parametros aceptados son
453 ticksize=9,
453 ticksize=9,
454 cblabel=''
454 cblabel=''
455 rti = True or False
455 rti = True or False
456 """
456 """
457
457
458 if self.__firsttime:
458 if self.__firsttime:
459
459
460 if xmin == None: xmin = numpy.nanmin(x)
460 if xmin == None: xmin = numpy.nanmin(x)
461 if xmax == None: xmax = numpy.nanmax(x)
461 if xmax == None: xmax = numpy.nanmax(x)
462 if ymin == None: ymin = numpy.nanmin(y)
462 if ymin == None: ymin = numpy.nanmin(y)
463 if ymax == None: ymax = numpy.nanmax(y)
463 if ymax == None: ymax = numpy.nanmax(y)
464 if zmin == None: zmin = numpy.nanmin(z)
464 if zmin == None: zmin = numpy.nanmin(z)
465 if zmax == None: zmax = numpy.nanmax(z)
465 if zmax == None: zmax = numpy.nanmax(z)
466
466
467
467
468 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
468 self.plot = self.__driver.createPcolor(self.ax, x, y, z,
469 xmin, xmax,
469 xmin, xmax,
470 ymin, ymax,
470 ymin, ymax,
471 zmin, zmax,
471 zmin, zmax,
472 xlabel=xlabel,
472 xlabel=xlabel,
473 ylabel=ylabel,
473 ylabel=ylabel,
474 title=title,
474 title=title,
475 colormap=colormap,
475 colormap=colormap,
476 **kwargs)
476 **kwargs)
477
477
478 if self.xmin == None: self.xmin = xmin
478 if self.xmin == None: self.xmin = xmin
479 if self.xmax == None: self.xmax = xmax
479 if self.xmax == None: self.xmax = xmax
480 if self.ymin == None: self.ymin = ymin
480 if self.ymin == None: self.ymin = ymin
481 if self.ymax == None: self.ymax = ymax
481 if self.ymax == None: self.ymax = ymax
482 if self.zmin == None: self.zmin = zmin
482 if self.zmin == None: self.zmin = zmin
483 if self.zmax == None: self.zmax = zmax
483 if self.zmax == None: self.zmax = zmax
484
484
485 self.__firsttime = False
485 self.__firsttime = False
486 return
486 return
487
487
488 if rti:
488 if rti:
489 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
489 self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax,
490 xlabel=xlabel,
490 xlabel=xlabel,
491 ylabel=ylabel,
491 ylabel=ylabel,
492 title=title,
492 title=title,
493 colormap=colormap)
493 colormap=colormap)
494 return
494 return
495
495
496 self.__driver.pcolor(self.plot, z,
496 self.__driver.pcolor(self.plot, z,
497 xlabel=xlabel,
497 xlabel=xlabel,
498 ylabel=ylabel,
498 ylabel=ylabel,
499 title=title)
499 title=title)
500
500
501 def pcolorbuffer(self, x, y, z,
501 def pcolorbuffer(self, x, y, z,
502 xmin=None, xmax=None,
502 xmin=None, xmax=None,
503 ymin=None, ymax=None,
503 ymin=None, ymax=None,
504 zmin=None, zmax=None,
504 zmin=None, zmax=None,
505 xlabel='', ylabel='',
505 xlabel='', ylabel='',
506 title='', rti = True, colormap='jet',
506 title='', rti = True, colormap='jet',
507 maxNumX = None, maxNumY = None,
507 maxNumX = None, maxNumY = None,
508 **kwargs):
508 **kwargs):
509
509
510 if maxNumX == None:
510 if maxNumX == None:
511 maxNumX = self.__MAXNUMX
511 maxNumX = self.__MAXNUMX
512
512
513 if maxNumY == None:
513 if maxNumY == None:
514 maxNumY = self.__MAXNUMY
514 maxNumY = self.__MAXNUMY
515
515
516 if self.__firsttime:
516 if self.__firsttime:
517 self.z_buffer = z
517 self.z_buffer = z
518 self.x_buffer = numpy.hstack((self.x_buffer, x))
518 self.x_buffer = numpy.hstack((self.x_buffer, x))
519
519
520 if xmin == None: xmin = numpy.nanmin(x)
520 if xmin == None: xmin = numpy.nanmin(x)
521 if xmax == None: xmax = numpy.nanmax(x)
521 if xmax == None: xmax = numpy.nanmax(x)
522 if ymin == None: ymin = numpy.nanmin(y)
522 if ymin == None: ymin = numpy.nanmin(y)
523 if ymax == None: ymax = numpy.nanmax(y)
523 if ymax == None: ymax = numpy.nanmax(y)
524 if zmin == None: zmin = numpy.nanmin(z)
524 if zmin == None: zmin = numpy.nanmin(z)
525 if zmax == None: zmax = numpy.nanmax(z)
525 if zmax == None: zmax = numpy.nanmax(z)
526
526
527
527
528 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
528 self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z,
529 xmin, xmax,
529 xmin, xmax,
530 ymin, ymax,
530 ymin, ymax,
531 zmin, zmax,
531 zmin, zmax,
532 xlabel=xlabel,
532 xlabel=xlabel,
533 ylabel=ylabel,
533 ylabel=ylabel,
534 title=title,
534 title=title,
535 colormap=colormap,
535 colormap=colormap,
536 **kwargs)
536 **kwargs)
537
537
538 if self.xmin == None: self.xmin = xmin
538 if self.xmin == None: self.xmin = xmin
539 if self.xmax == None: self.xmax = xmax
539 if self.xmax == None: self.xmax = xmax
540 if self.ymin == None: self.ymin = ymin
540 if self.ymin == None: self.ymin = ymin
541 if self.ymax == None: self.ymax = ymax
541 if self.ymax == None: self.ymax = ymax
542 if self.zmin == None: self.zmin = zmin
542 if self.zmin == None: self.zmin = zmin
543 if self.zmax == None: self.zmax = zmax
543 if self.zmax == None: self.zmax = zmax
544
544
545 self.__firsttime = False
545 self.__firsttime = False
546 return
546 return
547
547
548 self.x_buffer = numpy.hstack((self.x_buffer, x[-1]))
548 self.x_buffer = numpy.hstack((self.x_buffer, x[-1]))
549 self.z_buffer = numpy.hstack((self.z_buffer, z))
549 self.z_buffer = numpy.hstack((self.z_buffer, z))
550
550
551 if self.decimationx == None:
551 if self.decimationx == None:
552 deltax = float(self.xmax - self.xmin)/maxNumX
552 deltax = float(self.xmax - self.xmin)/maxNumX
553 deltay = float(self.ymax - self.ymin)/maxNumY
553 deltay = float(self.ymax - self.ymin)/maxNumY
554
554
555 resolutionx = self.x_buffer[2]-self.x_buffer[0]
555 resolutionx = self.x_buffer[2]-self.x_buffer[0]
556 resolutiony = y[1]-y[0]
556 resolutiony = y[1]-y[0]
557
557
558 self.decimationx = numpy.ceil(deltax / resolutionx)
558 self.decimationx = numpy.ceil(deltax / resolutionx)
559 self.decimationy = numpy.ceil(deltay / resolutiony)
559 self.decimationy = numpy.ceil(deltay / resolutiony)
560
560
561 z_buffer = self.z_buffer.reshape(-1,len(y))
561 z_buffer = self.z_buffer.reshape(-1,len(y))
562
562
563 x_buffer = self.x_buffer[::self.decimationx]
563 x_buffer = self.x_buffer[::self.decimationx]
564 y_buffer = y[::self.decimationy]
564 y_buffer = y[::self.decimationy]
565 z_buffer = z_buffer[::self.decimationx, ::self.decimationy]
565 z_buffer = z_buffer[::self.decimationx, ::self.decimationy]
566 #===================================================
566 #===================================================
567
567
568 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
568 x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer)
569
569
570 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
570 self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax,
571 xlabel=xlabel,
571 xlabel=xlabel,
572 ylabel=ylabel,
572 ylabel=ylabel,
573 title=title,
573 title=title,
574 colormap=colormap)
574 colormap=colormap)
575
575
576 def polar(self, x, y,
576 def polar(self, x, y,
577 title='', xlabel='',ylabel='',**kwargs):
577 title='', xlabel='',ylabel='',**kwargs):
578
578
579 if self.__firsttime:
579 if self.__firsttime:
580 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
580 self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel)
581 self.__firsttime = False
581 self.__firsttime = False
582 self.x_buffer = x
582 self.x_buffer = x
583 self.y_buffer = y
583 self.y_buffer = y
584 return
584 return
585
585
586 self.x_buffer = numpy.hstack((self.x_buffer,x))
586 self.x_buffer = numpy.hstack((self.x_buffer,x))
587 self.y_buffer = numpy.hstack((self.y_buffer,y))
587 self.y_buffer = numpy.hstack((self.y_buffer,y))
588 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
588 self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel,
589 ylabel=ylabel,
589 ylabel=ylabel,
590 title=title)
590 title=title)
591
591
592 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
592 def __fillGaps(self, x_buffer, y_buffer, z_buffer):
593
593
594 deltas = x_buffer[1:] - x_buffer[0:-1]
594 deltas = x_buffer[1:] - x_buffer[0:-1]
595 x_median = numpy.median(deltas)
595 x_median = numpy.median(deltas)
596
596
597 index = numpy.where(deltas >= 2*x_median)
597 index = numpy.where(deltas >= 2*x_median)
598
598
599 if len(index[0]) != 0:
599 if len(index[0]) != 0:
600 z_buffer[index[0],::] = self.__missing
600 z_buffer[index[0],::] = self.__missing
601 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
601 z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing)
602
602
603 return x_buffer, y_buffer, z_buffer
603 return x_buffer, y_buffer, z_buffer
604
604
605
605
606
606
607 No newline at end of file
607
@@ -1,1356 +1,1356
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:
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)
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
171
172 axes = self.axesList[i*self.__nsubplots]
172 axes = self.axesList[i*self.__nsubplots]
173 axes.pcolor(x, y, zdB[i,:,:],
173 axes.pcolor(x, y, zdB[i,:,:],
174 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,
175 xlabel=xlabel, ylabel=ylabel, title=title,
175 xlabel=xlabel, ylabel=ylabel, title=title,
176 ticksize=9, cblabel='')
176 ticksize=9, cblabel='')
177
177
178 if self.__showprofile:
178 if self.__showprofile:
179 axes = self.axesList[i*self.__nsubplots +1]
179 axes = self.axesList[i*self.__nsubplots +1]
180 axes.pline(avgdB[i], y,
180 axes.pline(avgdB[i], y,
181 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
181 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
182 xlabel='dB', ylabel='', title='',
182 xlabel='dB', ylabel='', title='',
183 ytick_visible=False,
183 ytick_visible=False,
184 grid='x')
184 grid='x')
185
185
186 noiseline = numpy.repeat(noisedB[i], len(y))
186 noiseline = numpy.repeat(noisedB[i], len(y))
187 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)
188
188
189 self.draw()
189 self.draw()
190
190
191 if figfile == None:
191 if figfile == None:
192 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
192 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
193 figfile = self.getFilename(name = str_datetime)
193 figfile = self.getFilename(name = str_datetime)
194 name = str_datetime
194 name = str_datetime
195 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
195 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
196 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)
197 figfile = self.getFilename(name)
197 figfile = self.getFilename(name)
198 if figpath != '':
198 if figpath != '':
199 self.counter_imagwr += 1
199 self.counter_imagwr += 1
200 if (self.counter_imagwr>=wr_period):
200 if (self.counter_imagwr>=wr_period):
201 # store png plot to local folder
201 # store png plot to local folder
202 self.saveFigure(figpath, figfile)
202 self.saveFigure(figpath, figfile)
203 # store png plot to FTP server according to RT-Web format
203 # store png plot to FTP server according to RT-Web format
204 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)
205 ftp_filename = os.path.join(figpath, name)
205 ftp_filename = os.path.join(figpath, name)
206 self.saveFigure(figpath, ftp_filename)
206 self.saveFigure(figpath, ftp_filename)
207 self.counter_imagwr = 0
207 self.counter_imagwr = 0
208
208
209
209
210 class CrossSpectraPlot(Figure):
210 class CrossSpectraPlot(Figure):
211
211
212 isConfig = None
212 isConfig = None
213 __nsubplots = None
213 __nsubplots = None
214
214
215 WIDTH = None
215 WIDTH = None
216 HEIGHT = None
216 HEIGHT = None
217 WIDTHPROF = None
217 WIDTHPROF = None
218 HEIGHTPROF = None
218 HEIGHTPROF = None
219 PREFIX = 'cspc'
219 PREFIX = 'cspc'
220
220
221 def __init__(self):
221 def __init__(self):
222
222
223 self.isConfig = False
223 self.isConfig = False
224 self.__nsubplots = 4
224 self.__nsubplots = 4
225 self.counter_imagwr = 0
225 self.counter_imagwr = 0
226 self.WIDTH = 250
226 self.WIDTH = 250
227 self.HEIGHT = 250
227 self.HEIGHT = 250
228 self.WIDTHPROF = 0
228 self.WIDTHPROF = 0
229 self.HEIGHTPROF = 0
229 self.HEIGHTPROF = 0
230
230
231 self.PLOT_CODE = 1
231 self.PLOT_CODE = 1
232 self.FTP_WEI = None
232 self.FTP_WEI = None
233 self.EXP_CODE = None
233 self.EXP_CODE = None
234 self.SUB_EXP_CODE = None
234 self.SUB_EXP_CODE = None
235 self.PLOT_POS = None
235 self.PLOT_POS = None
236
236
237 def getSubplots(self):
237 def getSubplots(self):
238
238
239 ncol = 4
239 ncol = 4
240 nrow = self.nplots
240 nrow = self.nplots
241
241
242 return nrow, ncol
242 return nrow, ncol
243
243
244 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
244 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
245
245
246 self.__showprofile = showprofile
246 self.__showprofile = showprofile
247 self.nplots = nplots
247 self.nplots = nplots
248
248
249 ncolspan = 1
249 ncolspan = 1
250 colspan = 1
250 colspan = 1
251
251
252 self.createFigure(id = id,
252 self.createFigure(id = id,
253 wintitle = wintitle,
253 wintitle = wintitle,
254 widthplot = self.WIDTH + self.WIDTHPROF,
254 widthplot = self.WIDTH + self.WIDTHPROF,
255 heightplot = self.HEIGHT + self.HEIGHTPROF,
255 heightplot = self.HEIGHT + self.HEIGHTPROF,
256 show=True)
256 show=True)
257
257
258 nrow, ncol = self.getSubplots()
258 nrow, ncol = self.getSubplots()
259
259
260 counter = 0
260 counter = 0
261 for y in range(nrow):
261 for y in range(nrow):
262 for x in range(ncol):
262 for x in range(ncol):
263 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
263 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
264
264
265 counter += 1
265 counter += 1
266
266
267 def run(self, dataOut, id, wintitle="", pairsList=None,
267 def run(self, dataOut, id, wintitle="", pairsList=None,
268 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,
269 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
269 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
270 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,
271 server=None, folder=None, username=None, password=None,
271 server=None, folder=None, username=None, password=None,
272 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):
273
273
274 """
274 """
275
275
276 Input:
276 Input:
277 dataOut :
277 dataOut :
278 id :
278 id :
279 wintitle :
279 wintitle :
280 channelList :
280 channelList :
281 showProfile :
281 showProfile :
282 xmin : None,
282 xmin : None,
283 xmax : None,
283 xmax : None,
284 ymin : None,
284 ymin : None,
285 ymax : None,
285 ymax : None,
286 zmin : None,
286 zmin : None,
287 zmax : None
287 zmax : None
288 """
288 """
289
289
290 if pairsList == None:
290 if pairsList == None:
291 pairsIndexList = dataOut.pairsIndexList
291 pairsIndexList = dataOut.pairsIndexList
292 else:
292 else:
293 pairsIndexList = []
293 pairsIndexList = []
294 for pair in pairsList:
294 for pair in pairsList:
295 if pair not in dataOut.pairsList:
295 if pair not in dataOut.pairsList:
296 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
296 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
297 pairsIndexList.append(dataOut.pairsList.index(pair))
297 pairsIndexList.append(dataOut.pairsList.index(pair))
298
298
299 if pairsIndexList == []:
299 if pairsIndexList == []:
300 return
300 return
301
301
302 if len(pairsIndexList) > 4:
302 if len(pairsIndexList) > 4:
303 pairsIndexList = pairsIndexList[0:4]
303 pairsIndexList = pairsIndexList[0:4]
304 factor = dataOut.normFactor
304 factor = dataOut.normFactor
305 x = dataOut.getVelRange(1)
305 x = dataOut.getVelRange(1)
306 y = dataOut.getHeiRange()
306 y = dataOut.getHeiRange()
307 z = dataOut.data_spc[:,:,:]/factor
307 z = dataOut.data_spc[:,:,:]/factor
308 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
308 # z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
309 avg = numpy.abs(numpy.average(z, axis=1))
309 avg = numpy.abs(numpy.average(z, axis=1))
310 noise = dataOut.noise/factor
310 noise = dataOut.noise/factor
311
311
312 zdB = 10*numpy.log10(z)
312 zdB = 10*numpy.log10(z)
313 avgdB = 10*numpy.log10(avg)
313 avgdB = 10*numpy.log10(avg)
314 noisedB = 10*numpy.log10(noise)
314 noisedB = 10*numpy.log10(noise)
315
315
316
316
317 #thisDatetime = dataOut.datatime
317 #thisDatetime = dataOut.datatime
318 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
318 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
319 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"))
320 xlabel = "Velocity (m/s)"
320 xlabel = "Velocity (m/s)"
321 ylabel = "Range (Km)"
321 ylabel = "Range (Km)"
322
322
323 if not self.isConfig:
323 if not self.isConfig:
324
324
325 nplots = len(pairsIndexList)
325 nplots = len(pairsIndexList)
326
326
327 self.setup(id=id,
327 self.setup(id=id,
328 nplots=nplots,
328 nplots=nplots,
329 wintitle=wintitle,
329 wintitle=wintitle,
330 showprofile=False,
330 showprofile=False,
331 show=show)
331 show=show)
332
332
333 if xmin == None: xmin = numpy.nanmin(x)
333 if xmin == None: xmin = numpy.nanmin(x)
334 if xmax == None: xmax = numpy.nanmax(x)
334 if xmax == None: xmax = numpy.nanmax(x)
335 if ymin == None: ymin = numpy.nanmin(y)
335 if ymin == None: ymin = numpy.nanmin(y)
336 if ymax == None: ymax = numpy.nanmax(y)
336 if ymax == None: ymax = numpy.nanmax(y)
337 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
337 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
338 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
338 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
339
339
340 self.FTP_WEI = ftp_wei
340 self.FTP_WEI = ftp_wei
341 self.EXP_CODE = exp_code
341 self.EXP_CODE = exp_code
342 self.SUB_EXP_CODE = sub_exp_code
342 self.SUB_EXP_CODE = sub_exp_code
343 self.PLOT_POS = plot_pos
343 self.PLOT_POS = plot_pos
344
344
345 self.isConfig = True
345 self.isConfig = True
346
346
347 self.setWinTitle(title)
347 self.setWinTitle(title)
348
348
349 for i in range(self.nplots):
349 for i in range(self.nplots):
350 pair = dataOut.pairsList[pairsIndexList[i]]
350 pair = dataOut.pairsList[pairsIndexList[i]]
351 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"))
352 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)
353 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
353 zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor)
354 axes0 = self.axesList[i*self.__nsubplots]
354 axes0 = self.axesList[i*self.__nsubplots]
355 axes0.pcolor(x, y, zdB,
355 axes0.pcolor(x, y, zdB,
356 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,
357 xlabel=xlabel, ylabel=ylabel, title=title,
357 xlabel=xlabel, ylabel=ylabel, title=title,
358 ticksize=9, colormap=power_cmap, cblabel='')
358 ticksize=9, colormap=power_cmap, cblabel='')
359
359
360 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)
361 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
361 zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor)
362 axes0 = self.axesList[i*self.__nsubplots+1]
362 axes0 = self.axesList[i*self.__nsubplots+1]
363 axes0.pcolor(x, y, zdB,
363 axes0.pcolor(x, y, zdB,
364 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,
365 xlabel=xlabel, ylabel=ylabel, title=title,
365 xlabel=xlabel, ylabel=ylabel, title=title,
366 ticksize=9, colormap=power_cmap, cblabel='')
366 ticksize=9, colormap=power_cmap, cblabel='')
367
367
368 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],:,:])
369 coherence = numpy.abs(coherenceComplex)
369 coherence = numpy.abs(coherenceComplex)
370 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
370 # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi
371 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
371 phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi
372
372
373 title = "Coherence %d%d" %(pair[0], pair[1])
373 title = "Coherence %d%d" %(pair[0], pair[1])
374 axes0 = self.axesList[i*self.__nsubplots+2]
374 axes0 = self.axesList[i*self.__nsubplots+2]
375 axes0.pcolor(x, y, coherence,
375 axes0.pcolor(x, y, coherence,
376 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,
377 xlabel=xlabel, ylabel=ylabel, title=title,
377 xlabel=xlabel, ylabel=ylabel, title=title,
378 ticksize=9, colormap=coherence_cmap, cblabel='')
378 ticksize=9, colormap=coherence_cmap, cblabel='')
379
379
380 title = "Phase %d%d" %(pair[0], pair[1])
380 title = "Phase %d%d" %(pair[0], pair[1])
381 axes0 = self.axesList[i*self.__nsubplots+3]
381 axes0 = self.axesList[i*self.__nsubplots+3]
382 axes0.pcolor(x, y, phase,
382 axes0.pcolor(x, y, phase,
383 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,
384 xlabel=xlabel, ylabel=ylabel, title=title,
384 xlabel=xlabel, ylabel=ylabel, title=title,
385 ticksize=9, colormap=phase_cmap, cblabel='')
385 ticksize=9, colormap=phase_cmap, cblabel='')
386
386
387
387
388
388
389 self.draw()
389 self.draw()
390
390
391 if figfile == None:
391 if figfile == None:
392 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
392 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
393 figfile = self.getFilename(name = str_datetime)
393 figfile = self.getFilename(name = str_datetime)
394
394
395 if figpath != '':
395 if figpath != '':
396 self.counter_imagwr += 1
396 self.counter_imagwr += 1
397 if (self.counter_imagwr>=wr_period):
397 if (self.counter_imagwr>=wr_period):
398 # store png plot to local folder
398 # store png plot to local folder
399 self.saveFigure(figpath, figfile)
399 self.saveFigure(figpath, figfile)
400 # store png plot to FTP server according to RT-Web format
400 # store png plot to FTP server according to RT-Web format
401 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)
402 ftp_filename = os.path.join(figpath, name)
402 ftp_filename = os.path.join(figpath, name)
403 self.saveFigure(figpath, ftp_filename)
403 self.saveFigure(figpath, ftp_filename)
404 self.counter_imagwr = 0
404 self.counter_imagwr = 0
405
405
406
406
407 class RTIPlot(Figure):
407 class RTIPlot(Figure):
408
408
409 __isConfig = None
409 __isConfig = None
410 __nsubplots = None
410 __nsubplots = None
411
411
412 WIDTHPROF = None
412 WIDTHPROF = None
413 HEIGHTPROF = None
413 HEIGHTPROF = None
414 PREFIX = 'rti'
414 PREFIX = 'rti'
415
415
416 def __init__(self):
416 def __init__(self):
417
417
418 self.timerange = 2*60*60
418 self.timerange = 2*60*60
419 self.__isConfig = False
419 self.__isConfig = False
420 self.__nsubplots = 1
420 self.__nsubplots = 1
421
421
422 self.WIDTH = 800
422 self.WIDTH = 800
423 self.HEIGHT = 150
423 self.HEIGHT = 150
424 self.WIDTHPROF = 120
424 self.WIDTHPROF = 120
425 self.HEIGHTPROF = 0
425 self.HEIGHTPROF = 0
426 self.counter_imagwr = 0
426 self.counter_imagwr = 0
427
427
428 self.PLOT_CODE = 0
428 self.PLOT_CODE = 0
429 self.FTP_WEI = None
429 self.FTP_WEI = None
430 self.EXP_CODE = None
430 self.EXP_CODE = None
431 self.SUB_EXP_CODE = None
431 self.SUB_EXP_CODE = None
432 self.PLOT_POS = None
432 self.PLOT_POS = None
433 self.tmin = None
433 self.tmin = None
434 self.tmax = None
434 self.tmax = None
435
435
436 self.xmin = None
436 self.xmin = None
437 self.xmax = None
437 self.xmax = None
438
438
439 self.figfile = None
439 self.figfile = None
440
440
441 def getSubplots(self):
441 def getSubplots(self):
442
442
443 ncol = 1
443 ncol = 1
444 nrow = self.nplots
444 nrow = self.nplots
445
445
446 return nrow, ncol
446 return nrow, ncol
447
447
448 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
448 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
449
449
450 self.__showprofile = showprofile
450 self.__showprofile = showprofile
451 self.nplots = nplots
451 self.nplots = nplots
452
452
453 ncolspan = 1
453 ncolspan = 1
454 colspan = 1
454 colspan = 1
455 if showprofile:
455 if showprofile:
456 ncolspan = 7
456 ncolspan = 7
457 colspan = 6
457 colspan = 6
458 self.__nsubplots = 2
458 self.__nsubplots = 2
459
459
460 self.createFigure(id = id,
460 self.createFigure(id = id,
461 wintitle = wintitle,
461 wintitle = wintitle,
462 widthplot = self.WIDTH + self.WIDTHPROF,
462 widthplot = self.WIDTH + self.WIDTHPROF,
463 heightplot = self.HEIGHT + self.HEIGHTPROF,
463 heightplot = self.HEIGHT + self.HEIGHTPROF,
464 show=show)
464 show=show)
465
465
466 nrow, ncol = self.getSubplots()
466 nrow, ncol = self.getSubplots()
467
467
468 counter = 0
468 counter = 0
469 for y in range(nrow):
469 for y in range(nrow):
470 for x in range(ncol):
470 for x in range(ncol):
471
471
472 if counter >= self.nplots:
472 if counter >= self.nplots:
473 break
473 break
474
474
475 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
475 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
476
476
477 if showprofile:
477 if showprofile:
478 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
478 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
479
479
480 counter += 1
480 counter += 1
481
481
482 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
482 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
483 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,
484 timerange=None,
484 timerange=None,
485 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,
486 server=None, folder=None, username=None, password=None,
486 server=None, folder=None, username=None, password=None,
487 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):
488
488
489 """
489 """
490
490
491 Input:
491 Input:
492 dataOut :
492 dataOut :
493 id :
493 id :
494 wintitle :
494 wintitle :
495 channelList :
495 channelList :
496 showProfile :
496 showProfile :
497 xmin : None,
497 xmin : None,
498 xmax : None,
498 xmax : None,
499 ymin : None,
499 ymin : None,
500 ymax : None,
500 ymax : None,
501 zmin : None,
501 zmin : None,
502 zmax : None
502 zmax : None
503 """
503 """
504
504
505 if channelList == None:
505 if channelList == None:
506 channelIndexList = dataOut.channelIndexList
506 channelIndexList = dataOut.channelIndexList
507 else:
507 else:
508 channelIndexList = []
508 channelIndexList = []
509 for channel in channelList:
509 for channel in channelList:
510 if channel not in dataOut.channelList:
510 if channel not in dataOut.channelList:
511 raise ValueError, "Channel %d is not in dataOut.channelList"
511 raise ValueError, "Channel %d is not in dataOut.channelList"
512 channelIndexList.append(dataOut.channelList.index(channel))
512 channelIndexList.append(dataOut.channelList.index(channel))
513
513
514 if timerange != None:
514 if timerange != None:
515 self.timerange = timerange
515 self.timerange = timerange
516
516
517 #tmin = None
517 #tmin = None
518 #tmax = None
518 #tmax = None
519 factor = dataOut.normFactor
519 factor = dataOut.normFactor
520 x = dataOut.getTimeRange()
520 x = dataOut.getTimeRange()
521 y = dataOut.getHeiRange()
521 y = dataOut.getHeiRange()
522
522
523 z = dataOut.data_spc[channelIndexList,:,:]/factor
523 z = dataOut.data_spc[channelIndexList,:,:]/factor
524 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
524 z = numpy.where(numpy.isfinite(z), z, numpy.NAN)
525 avg = numpy.average(z, axis=1)
525 avg = numpy.average(z, axis=1)
526
526
527 avgdB = 10.*numpy.log10(avg)
527 avgdB = 10.*numpy.log10(avg)
528
528
529
529
530 # thisDatetime = dataOut.datatime
530 # thisDatetime = dataOut.datatime
531 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
531 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
532 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
532 title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
533 xlabel = ""
533 xlabel = ""
534 ylabel = "Range (Km)"
534 ylabel = "Range (Km)"
535
535
536 if not self.__isConfig:
536 if not self.__isConfig:
537
537
538 nplots = len(channelIndexList)
538 nplots = len(channelIndexList)
539
539
540 self.setup(id=id,
540 self.setup(id=id,
541 nplots=nplots,
541 nplots=nplots,
542 wintitle=wintitle,
542 wintitle=wintitle,
543 showprofile=showprofile,
543 showprofile=showprofile,
544 show=show)
544 show=show)
545
545
546 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange, timezone = dataOut.timezone)
546 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange)
547
547
548 # if timerange != None:
548 # if timerange != None:
549 # self.timerange = timerange
549 # self.timerange = timerange
550 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange, timezone = dataOut.timezone)
550 # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange, timezone = dataOut.timezone)
551
551
552
552
553
553
554 if ymin == None: ymin = numpy.nanmin(y)
554 if ymin == None: ymin = numpy.nanmin(y)
555 if ymax == None: ymax = numpy.nanmax(y)
555 if ymax == None: ymax = numpy.nanmax(y)
556 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
556 if zmin == None: zmin = numpy.nanmin(avgdB)*0.9
557 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
557 if zmax == None: zmax = numpy.nanmax(avgdB)*0.9
558
558
559 self.FTP_WEI = ftp_wei
559 self.FTP_WEI = ftp_wei
560 self.EXP_CODE = exp_code
560 self.EXP_CODE = exp_code
561 self.SUB_EXP_CODE = sub_exp_code
561 self.SUB_EXP_CODE = sub_exp_code
562 self.PLOT_POS = plot_pos
562 self.PLOT_POS = plot_pos
563
563
564 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
564 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
565 self.__isConfig = True
565 self.__isConfig = True
566 self.figfile = figfile
566 self.figfile = figfile
567
567
568 self.setWinTitle(title)
568 self.setWinTitle(title)
569
569
570 if ((self.xmax - x[1]) < (x[1]-x[0])):
570 if ((self.xmax - x[1]) < (x[1]-x[0])):
571 x[1] = self.xmax
571 x[1] = self.xmax
572
572
573 for i in range(self.nplots):
573 for i in range(self.nplots):
574 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"))
575 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
575 if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)):
576 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)
577 axes = self.axesList[i*self.__nsubplots]
577 axes = self.axesList[i*self.__nsubplots]
578 zdB = avgdB[i].reshape((1,-1))
578 zdB = avgdB[i].reshape((1,-1))
579 axes.pcolorbuffer(x, y, zdB,
579 axes.pcolorbuffer(x, y, zdB,
580 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,
581 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
581 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
582 ticksize=9, cblabel='', cbsize="1%")
582 ticksize=9, cblabel='', cbsize="1%")
583
583
584 if self.__showprofile:
584 if self.__showprofile:
585 axes = self.axesList[i*self.__nsubplots +1]
585 axes = self.axesList[i*self.__nsubplots +1]
586 axes.pline(avgdB[i], y,
586 axes.pline(avgdB[i], y,
587 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
587 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
588 xlabel='dB', ylabel='', title='',
588 xlabel='dB', ylabel='', title='',
589 ytick_visible=False,
589 ytick_visible=False,
590 grid='x')
590 grid='x')
591
591
592 self.draw()
592 self.draw()
593
593
594 if self.figfile == None:
594 if self.figfile == None:
595 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
595 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
596 self.figfile = self.getFilename(name = str_datetime)
596 self.figfile = self.getFilename(name = str_datetime)
597
597
598 if figpath != '':
598 if figpath != '':
599
599
600 self.counter_imagwr += 1
600 self.counter_imagwr += 1
601 if (self.counter_imagwr>=wr_period):
601 if (self.counter_imagwr>=wr_period):
602 # store png plot to local folder
602 # store png plot to local folder
603 self.saveFigure(figpath, self.figfile)
603 self.saveFigure(figpath, self.figfile)
604 # store png plot to FTP server according to RT-Web format
604 # store png plot to FTP server according to RT-Web format
605 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
605 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
606 ftp_filename = os.path.join(figpath, name)
606 ftp_filename = os.path.join(figpath, name)
607 self.saveFigure(figpath, ftp_filename)
607 self.saveFigure(figpath, ftp_filename)
608
608
609 self.counter_imagwr = 0
609 self.counter_imagwr = 0
610
610
611 if x[1] >= self.axesList[0].xmax:
611 if x[1] >= self.axesList[0].xmax:
612 self.counter_imagwr = wr_period
612 self.counter_imagwr = wr_period
613 self.__isConfig = False
613 self.__isConfig = False
614 self.figfile = None
614 self.figfile = None
615
615
616 class CoherenceMap(Figure):
616 class CoherenceMap(Figure):
617 isConfig = None
617 isConfig = None
618 __nsubplots = None
618 __nsubplots = None
619
619
620 WIDTHPROF = None
620 WIDTHPROF = None
621 HEIGHTPROF = None
621 HEIGHTPROF = None
622 PREFIX = 'cmap'
622 PREFIX = 'cmap'
623
623
624 def __init__(self):
624 def __init__(self):
625 self.timerange = 2*60*60
625 self.timerange = 2*60*60
626 self.isConfig = False
626 self.isConfig = False
627 self.__nsubplots = 1
627 self.__nsubplots = 1
628
628
629 self.WIDTH = 800
629 self.WIDTH = 800
630 self.HEIGHT = 150
630 self.HEIGHT = 150
631 self.WIDTHPROF = 120
631 self.WIDTHPROF = 120
632 self.HEIGHTPROF = 0
632 self.HEIGHTPROF = 0
633 self.counter_imagwr = 0
633 self.counter_imagwr = 0
634
634
635 self.PLOT_CODE = 3
635 self.PLOT_CODE = 3
636 self.FTP_WEI = None
636 self.FTP_WEI = None
637 self.EXP_CODE = None
637 self.EXP_CODE = None
638 self.SUB_EXP_CODE = None
638 self.SUB_EXP_CODE = None
639 self.PLOT_POS = None
639 self.PLOT_POS = None
640 self.counter_imagwr = 0
640 self.counter_imagwr = 0
641
641
642 self.xmin = None
642 self.xmin = None
643 self.xmax = None
643 self.xmax = None
644
644
645 def getSubplots(self):
645 def getSubplots(self):
646 ncol = 1
646 ncol = 1
647 nrow = self.nplots*2
647 nrow = self.nplots*2
648
648
649 return nrow, ncol
649 return nrow, ncol
650
650
651 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
651 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
652 self.__showprofile = showprofile
652 self.__showprofile = showprofile
653 self.nplots = nplots
653 self.nplots = nplots
654
654
655 ncolspan = 1
655 ncolspan = 1
656 colspan = 1
656 colspan = 1
657 if showprofile:
657 if showprofile:
658 ncolspan = 7
658 ncolspan = 7
659 colspan = 6
659 colspan = 6
660 self.__nsubplots = 2
660 self.__nsubplots = 2
661
661
662 self.createFigure(id = id,
662 self.createFigure(id = id,
663 wintitle = wintitle,
663 wintitle = wintitle,
664 widthplot = self.WIDTH + self.WIDTHPROF,
664 widthplot = self.WIDTH + self.WIDTHPROF,
665 heightplot = self.HEIGHT + self.HEIGHTPROF,
665 heightplot = self.HEIGHT + self.HEIGHTPROF,
666 show=True)
666 show=True)
667
667
668 nrow, ncol = self.getSubplots()
668 nrow, ncol = self.getSubplots()
669
669
670 for y in range(nrow):
670 for y in range(nrow):
671 for x in range(ncol):
671 for x in range(ncol):
672
672
673 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
673 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
674
674
675 if showprofile:
675 if showprofile:
676 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
676 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1)
677
677
678 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
678 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
679 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
679 xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,
680 timerange=None,
680 timerange=None,
681 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
681 save=False, figpath='', figfile=None, ftp=False, wr_period=1,
682 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
682 coherence_cmap='jet', phase_cmap='RdBu_r', show=True,
683 server=None, folder=None, username=None, password=None,
683 server=None, folder=None, username=None, password=None,
684 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
684 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
685
685
686 if pairsList == None:
686 if pairsList == None:
687 pairsIndexList = dataOut.pairsIndexList
687 pairsIndexList = dataOut.pairsIndexList
688 else:
688 else:
689 pairsIndexList = []
689 pairsIndexList = []
690 for pair in pairsList:
690 for pair in pairsList:
691 if pair not in dataOut.pairsList:
691 if pair not in dataOut.pairsList:
692 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
692 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
693 pairsIndexList.append(dataOut.pairsList.index(pair))
693 pairsIndexList.append(dataOut.pairsList.index(pair))
694
694
695 if timerange != None:
695 if timerange != None:
696 self.timerange = timerange
696 self.timerange = timerange
697
697
698 if pairsIndexList == []:
698 if pairsIndexList == []:
699 return
699 return
700
700
701 if len(pairsIndexList) > 4:
701 if len(pairsIndexList) > 4:
702 pairsIndexList = pairsIndexList[0:4]
702 pairsIndexList = pairsIndexList[0:4]
703
703
704 # tmin = None
704 # tmin = None
705 # tmax = None
705 # tmax = None
706 x = dataOut.getTimeRange()
706 x = dataOut.getTimeRange()
707 y = dataOut.getHeiRange()
707 y = dataOut.getHeiRange()
708
708
709 #thisDatetime = dataOut.datatime
709 #thisDatetime = dataOut.datatime
710 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
710 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
711 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
711 title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y"))
712 xlabel = ""
712 xlabel = ""
713 ylabel = "Range (Km)"
713 ylabel = "Range (Km)"
714
714
715 if not self.isConfig:
715 if not self.isConfig:
716 nplots = len(pairsIndexList)
716 nplots = len(pairsIndexList)
717 self.setup(id=id,
717 self.setup(id=id,
718 nplots=nplots,
718 nplots=nplots,
719 wintitle=wintitle,
719 wintitle=wintitle,
720 showprofile=showprofile,
720 showprofile=showprofile,
721 show=show)
721 show=show)
722
722
723 #tmin, tmax = self.getTimeLim(x, xmin, xmax, timezone = dataOut.timezone)
723 #tmin, tmax = self.getTimeLim(x, xmin, xmax, timezone = dataOut.timezone)
724
724
725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange, timezone = dataOut.timezone)
725 self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange, timezone = dataOut.timezone)
726
726
727 if ymin == None: ymin = numpy.nanmin(y)
727 if ymin == None: ymin = numpy.nanmin(y)
728 if ymax == None: ymax = numpy.nanmax(y)
728 if ymax == None: ymax = numpy.nanmax(y)
729 if zmin == None: zmin = 0.
729 if zmin == None: zmin = 0.
730 if zmax == None: zmax = 1.
730 if zmax == None: zmax = 1.
731
731
732 self.FTP_WEI = ftp_wei
732 self.FTP_WEI = ftp_wei
733 self.EXP_CODE = exp_code
733 self.EXP_CODE = exp_code
734 self.SUB_EXP_CODE = sub_exp_code
734 self.SUB_EXP_CODE = sub_exp_code
735 self.PLOT_POS = plot_pos
735 self.PLOT_POS = plot_pos
736
736
737 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
737 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
738
738
739 self.isConfig = True
739 self.isConfig = True
740
740
741 self.setWinTitle(title)
741 self.setWinTitle(title)
742
742
743 if ((self.xmax - x[1]) < (x[1]-x[0])):
743 if ((self.xmax - x[1]) < (x[1]-x[0])):
744 x[1] = self.xmax
744 x[1] = self.xmax
745
745
746 for i in range(self.nplots):
746 for i in range(self.nplots):
747
747
748 pair = dataOut.pairsList[pairsIndexList[i]]
748 pair = dataOut.pairsList[pairsIndexList[i]]
749
749
750 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
750 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
751 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
751 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
752 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
752 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
753
753
754
754
755 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
755 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
756 coherence = numpy.abs(avgcoherenceComplex)
756 coherence = numpy.abs(avgcoherenceComplex)
757
757
758 z = coherence.reshape((1,-1))
758 z = coherence.reshape((1,-1))
759
759
760 counter = 0
760 counter = 0
761
761
762 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
762 title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
763 axes = self.axesList[i*self.__nsubplots*2]
763 axes = self.axesList[i*self.__nsubplots*2]
764 axes.pcolorbuffer(x, y, z,
764 axes.pcolorbuffer(x, y, z,
765 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
765 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax,
766 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
766 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
767 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
767 ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%")
768
768
769 if self.__showprofile:
769 if self.__showprofile:
770 counter += 1
770 counter += 1
771 axes = self.axesList[i*self.__nsubplots*2 + counter]
771 axes = self.axesList[i*self.__nsubplots*2 + counter]
772 axes.pline(coherence, y,
772 axes.pline(coherence, y,
773 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
773 xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax,
774 xlabel='', ylabel='', title='', ticksize=7,
774 xlabel='', ylabel='', title='', ticksize=7,
775 ytick_visible=False, nxticks=5,
775 ytick_visible=False, nxticks=5,
776 grid='x')
776 grid='x')
777
777
778 counter += 1
778 counter += 1
779
779
780 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
780 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
781
781
782 z = phase.reshape((1,-1))
782 z = phase.reshape((1,-1))
783
783
784 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
784 title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
785 axes = self.axesList[i*self.__nsubplots*2 + counter]
785 axes = self.axesList[i*self.__nsubplots*2 + counter]
786 axes.pcolorbuffer(x, y, z,
786 axes.pcolorbuffer(x, y, z,
787 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
787 xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180,
788 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
788 xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,
789 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
789 ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%")
790
790
791 if self.__showprofile:
791 if self.__showprofile:
792 counter += 1
792 counter += 1
793 axes = self.axesList[i*self.__nsubplots*2 + counter]
793 axes = self.axesList[i*self.__nsubplots*2 + counter]
794 axes.pline(phase, y,
794 axes.pline(phase, y,
795 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
795 xmin=-180, xmax=180, ymin=ymin, ymax=ymax,
796 xlabel='', ylabel='', title='', ticksize=7,
796 xlabel='', ylabel='', title='', ticksize=7,
797 ytick_visible=False, nxticks=4,
797 ytick_visible=False, nxticks=4,
798 grid='x')
798 grid='x')
799
799
800 self.draw()
800 self.draw()
801
801
802 if x[1] >= self.axesList[0].xmax:
802 if x[1] >= self.axesList[0].xmax:
803 self.counter_imagwr = wr_period
803 self.counter_imagwr = wr_period
804 self.__isConfig = False
804 self.__isConfig = False
805
805
806 if figfile == None:
806 if figfile == None:
807 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
807 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
808 figfile = self.getFilename(name = str_datetime)
808 figfile = self.getFilename(name = str_datetime)
809
809
810 if figpath != '':
810 if figpath != '':
811
811
812 self.counter_imagwr += 1
812 self.counter_imagwr += 1
813 if (self.counter_imagwr>=wr_period):
813 if (self.counter_imagwr>=wr_period):
814 # store png plot to local folder
814 # store png plot to local folder
815 self.saveFigure(figpath, figfile)
815 self.saveFigure(figpath, figfile)
816 # store png plot to FTP server according to RT-Web format
816 # store png plot to FTP server according to RT-Web format
817 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
817 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
818 ftp_filename = os.path.join(figpath, name)
818 ftp_filename = os.path.join(figpath, name)
819 self.saveFigure(figpath, ftp_filename)
819 self.saveFigure(figpath, ftp_filename)
820
820
821 self.counter_imagwr = 0
821 self.counter_imagwr = 0
822
822
823 class PowerProfile(Figure):
823 class PowerProfile(Figure):
824 isConfig = None
824 isConfig = None
825 __nsubplots = None
825 __nsubplots = None
826
826
827 WIDTHPROF = None
827 WIDTHPROF = None
828 HEIGHTPROF = None
828 HEIGHTPROF = None
829 PREFIX = 'spcprofile'
829 PREFIX = 'spcprofile'
830
830
831 def __init__(self):
831 def __init__(self):
832 self.isConfig = False
832 self.isConfig = False
833 self.__nsubplots = 1
833 self.__nsubplots = 1
834
834
835 self.WIDTH = 300
835 self.WIDTH = 300
836 self.HEIGHT = 500
836 self.HEIGHT = 500
837 self.counter_imagwr = 0
837 self.counter_imagwr = 0
838
838
839 def getSubplots(self):
839 def getSubplots(self):
840 ncol = 1
840 ncol = 1
841 nrow = 1
841 nrow = 1
842
842
843 return nrow, ncol
843 return nrow, ncol
844
844
845 def setup(self, id, nplots, wintitle, show):
845 def setup(self, id, nplots, wintitle, show):
846
846
847 self.nplots = nplots
847 self.nplots = nplots
848
848
849 ncolspan = 1
849 ncolspan = 1
850 colspan = 1
850 colspan = 1
851
851
852 self.createFigure(id = id,
852 self.createFigure(id = id,
853 wintitle = wintitle,
853 wintitle = wintitle,
854 widthplot = self.WIDTH,
854 widthplot = self.WIDTH,
855 heightplot = self.HEIGHT,
855 heightplot = self.HEIGHT,
856 show=show)
856 show=show)
857
857
858 nrow, ncol = self.getSubplots()
858 nrow, ncol = self.getSubplots()
859
859
860 counter = 0
860 counter = 0
861 for y in range(nrow):
861 for y in range(nrow):
862 for x in range(ncol):
862 for x in range(ncol):
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
863 self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1)
864
864
865 def run(self, dataOut, id, wintitle="", channelList=None,
865 def run(self, dataOut, id, wintitle="", channelList=None,
866 xmin=None, xmax=None, ymin=None, ymax=None,
866 xmin=None, xmax=None, ymin=None, ymax=None,
867 save=False, figpath='', figfile=None, show=True, wr_period=1,
867 save=False, figpath='', figfile=None, show=True, wr_period=1,
868 server=None, folder=None, username=None, password=None,):
868 server=None, folder=None, username=None, password=None,):
869
869
870 if dataOut.flagNoData:
870 if dataOut.flagNoData:
871 return None
871 return None
872
872
873 if channelList == None:
873 if channelList == None:
874 channelIndexList = dataOut.channelIndexList
874 channelIndexList = dataOut.channelIndexList
875 channelList = dataOut.channelList
875 channelList = dataOut.channelList
876 else:
876 else:
877 channelIndexList = []
877 channelIndexList = []
878 for channel in channelList:
878 for channel in channelList:
879 if channel not in dataOut.channelList:
879 if channel not in dataOut.channelList:
880 raise ValueError, "Channel %d is not in dataOut.channelList"
880 raise ValueError, "Channel %d is not in dataOut.channelList"
881 channelIndexList.append(dataOut.channelList.index(channel))
881 channelIndexList.append(dataOut.channelList.index(channel))
882
882
883 try:
883 try:
884 factor = dataOut.normFactor
884 factor = dataOut.normFactor
885 except:
885 except:
886 factor = 1
886 factor = 1
887
887
888 y = dataOut.getHeiRange()
888 y = dataOut.getHeiRange()
889
889
890 #for voltage
890 #for voltage
891 if dataOut.type == 'Voltage':
891 if dataOut.type == 'Voltage':
892 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
892 x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:])
893 x = x.real
893 x = x.real
894 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
894 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
895
895
896 #for spectra
896 #for spectra
897 if dataOut.type == 'Spectra':
897 if dataOut.type == 'Spectra':
898 x = dataOut.data_spc[channelIndexList,:,:]/factor
898 x = dataOut.data_spc[channelIndexList,:,:]/factor
899 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
899 x = numpy.where(numpy.isfinite(x), x, numpy.NAN)
900 x = numpy.average(x, axis=1)
900 x = numpy.average(x, axis=1)
901
901
902
902
903 xdB = 10*numpy.log10(x)
903 xdB = 10*numpy.log10(x)
904
904
905 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
905 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
906 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
906 title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y"))
907 xlabel = "dB"
907 xlabel = "dB"
908 ylabel = "Range (Km)"
908 ylabel = "Range (Km)"
909
909
910 if not self.isConfig:
910 if not self.isConfig:
911
911
912 nplots = 1
912 nplots = 1
913
913
914 self.setup(id=id,
914 self.setup(id=id,
915 nplots=nplots,
915 nplots=nplots,
916 wintitle=wintitle,
916 wintitle=wintitle,
917 show=show)
917 show=show)
918
918
919 if ymin == None: ymin = numpy.nanmin(y)
919 if ymin == None: ymin = numpy.nanmin(y)
920 if ymax == None: ymax = numpy.nanmax(y)
920 if ymax == None: ymax = numpy.nanmax(y)
921 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
921 if xmin == None: xmin = numpy.nanmin(xdB)*0.9
922 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
922 if xmax == None: xmax = numpy.nanmax(xdB)*0.9
923
923
924 self.__isConfig = True
924 self.__isConfig = True
925
925
926 self.setWinTitle(title)
926 self.setWinTitle(title)
927
927
928 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
928 title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S"))
929 axes = self.axesList[0]
929 axes = self.axesList[0]
930
930
931 legendlabels = ["channel %d"%x for x in channelList]
931 legendlabels = ["channel %d"%x for x in channelList]
932 axes.pmultiline(xdB, y,
932 axes.pmultiline(xdB, y,
933 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
933 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
934 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
934 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels,
935 ytick_visible=True, nxticks=5,
935 ytick_visible=True, nxticks=5,
936 grid='x')
936 grid='x')
937
937
938 self.draw()
938 self.draw()
939
939
940 if figfile == None:
940 if figfile == None:
941 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
941 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
942 figfile = self.getFilename(name = str_datetime)
942 figfile = self.getFilename(name = str_datetime)
943
943
944 if figpath != '':
944 if figpath != '':
945 self.counter_imagwr += 1
945 self.counter_imagwr += 1
946 if (self.counter_imagwr>=wr_period):
946 if (self.counter_imagwr>=wr_period):
947 # store png plot to local folder
947 # store png plot to local folder
948 self.saveFigure(figpath, figfile)
948 self.saveFigure(figpath, figfile)
949 # store png plot to FTP server according to RT-Web format
949 # store png plot to FTP server according to RT-Web format
950 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
950 #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
951 #ftp_filename = os.path.join(figpath, name)
951 #ftp_filename = os.path.join(figpath, name)
952 #self.saveFigure(figpath, ftp_filename)
952 #self.saveFigure(figpath, ftp_filename)
953 self.counter_imagwr = 0
953 self.counter_imagwr = 0
954
954
955
955
956
956
957 class Noise(Figure):
957 class Noise(Figure):
958
958
959 isConfig = None
959 isConfig = None
960 __nsubplots = None
960 __nsubplots = None
961
961
962 PREFIX = 'noise'
962 PREFIX = 'noise'
963
963
964 def __init__(self):
964 def __init__(self):
965
965
966 self.timerange = 24*60*60
966 self.timerange = 24*60*60
967 self.isConfig = False
967 self.isConfig = False
968 self.__nsubplots = 1
968 self.__nsubplots = 1
969 self.counter_imagwr = 0
969 self.counter_imagwr = 0
970 self.WIDTH = 600
970 self.WIDTH = 600
971 self.HEIGHT = 300
971 self.HEIGHT = 300
972 self.WIDTHPROF = 120
972 self.WIDTHPROF = 120
973 self.HEIGHTPROF = 0
973 self.HEIGHTPROF = 0
974 self.xdata = None
974 self.xdata = None
975 self.ydata = None
975 self.ydata = None
976
976
977 self.PLOT_CODE = 17
977 self.PLOT_CODE = 17
978 self.FTP_WEI = None
978 self.FTP_WEI = None
979 self.EXP_CODE = None
979 self.EXP_CODE = None
980 self.SUB_EXP_CODE = None
980 self.SUB_EXP_CODE = None
981 self.PLOT_POS = None
981 self.PLOT_POS = None
982 self.figfile = None
982 self.figfile = None
983
983
984 def getSubplots(self):
984 def getSubplots(self):
985
985
986 ncol = 1
986 ncol = 1
987 nrow = 1
987 nrow = 1
988
988
989 return nrow, ncol
989 return nrow, ncol
990
990
991 def openfile(self, filename):
991 def openfile(self, filename):
992 f = open(filename,'w+')
992 f = open(filename,'w+')
993 f.write('\n\n')
993 f.write('\n\n')
994 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
994 f.write('JICAMARCA RADIO OBSERVATORY - Noise \n')
995 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
995 f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' )
996 f.close()
996 f.close()
997
997
998 def save_data(self, filename_phase, data, data_datetime):
998 def save_data(self, filename_phase, data, data_datetime):
999 f=open(filename_phase,'a')
999 f=open(filename_phase,'a')
1000 timetuple_data = data_datetime.timetuple()
1000 timetuple_data = data_datetime.timetuple()
1001 day = str(timetuple_data.tm_mday)
1001 day = str(timetuple_data.tm_mday)
1002 month = str(timetuple_data.tm_mon)
1002 month = str(timetuple_data.tm_mon)
1003 year = str(timetuple_data.tm_year)
1003 year = str(timetuple_data.tm_year)
1004 hour = str(timetuple_data.tm_hour)
1004 hour = str(timetuple_data.tm_hour)
1005 minute = str(timetuple_data.tm_min)
1005 minute = str(timetuple_data.tm_min)
1006 second = str(timetuple_data.tm_sec)
1006 second = str(timetuple_data.tm_sec)
1007 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1007 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1008 f.close()
1008 f.close()
1009
1009
1010
1010
1011 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1011 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1012
1012
1013 self.__showprofile = showprofile
1013 self.__showprofile = showprofile
1014 self.nplots = nplots
1014 self.nplots = nplots
1015
1015
1016 ncolspan = 7
1016 ncolspan = 7
1017 colspan = 6
1017 colspan = 6
1018 self.__nsubplots = 2
1018 self.__nsubplots = 2
1019
1019
1020 self.createFigure(id = id,
1020 self.createFigure(id = id,
1021 wintitle = wintitle,
1021 wintitle = wintitle,
1022 widthplot = self.WIDTH+self.WIDTHPROF,
1022 widthplot = self.WIDTH+self.WIDTHPROF,
1023 heightplot = self.HEIGHT+self.HEIGHTPROF,
1023 heightplot = self.HEIGHT+self.HEIGHTPROF,
1024 show=show)
1024 show=show)
1025
1025
1026 nrow, ncol = self.getSubplots()
1026 nrow, ncol = self.getSubplots()
1027
1027
1028 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1028 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1029
1029
1030
1030
1031 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1031 def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True',
1032 xmin=None, xmax=None, ymin=None, ymax=None,
1032 xmin=None, xmax=None, ymin=None, ymax=None,
1033 timerange=None,
1033 timerange=None,
1034 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1034 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1035 server=None, folder=None, username=None, password=None,
1035 server=None, folder=None, username=None, password=None,
1036 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1036 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1037
1037
1038 if channelList == None:
1038 if channelList == None:
1039 channelIndexList = dataOut.channelIndexList
1039 channelIndexList = dataOut.channelIndexList
1040 channelList = dataOut.channelList
1040 channelList = dataOut.channelList
1041 else:
1041 else:
1042 channelIndexList = []
1042 channelIndexList = []
1043 for channel in channelList:
1043 for channel in channelList:
1044 if channel not in dataOut.channelList:
1044 if channel not in dataOut.channelList:
1045 raise ValueError, "Channel %d is not in dataOut.channelList"
1045 raise ValueError, "Channel %d is not in dataOut.channelList"
1046 channelIndexList.append(dataOut.channelList.index(channel))
1046 channelIndexList.append(dataOut.channelList.index(channel))
1047
1047
1048 if timerange != None:
1048 if timerange != None:
1049 self.timerange = timerange
1049 self.timerange = timerange
1050
1050
1051 tmin = None
1051 tmin = None
1052 tmax = None
1052 tmax = None
1053 x = dataOut.getTimeRange()
1053 x = dataOut.getTimeRange()
1054 y = dataOut.getHeiRange()
1054 y = dataOut.getHeiRange()
1055 factor = dataOut.normFactor
1055 factor = dataOut.normFactor
1056 noise = dataOut.noise/factor
1056 noise = dataOut.noise/factor
1057 noisedB = 10*numpy.log10(noise)
1057 noisedB = 10*numpy.log10(noise)
1058
1058
1059 #thisDatetime = dataOut.datatime
1059 #thisDatetime = dataOut.datatime
1060 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1060 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1061 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1061 title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1062 xlabel = ""
1062 xlabel = ""
1063 ylabel = "Intensity (dB)"
1063 ylabel = "Intensity (dB)"
1064
1064
1065 if not self.isConfig:
1065 if not self.isConfig:
1066
1066
1067 nplots = 1
1067 nplots = 1
1068
1068
1069 self.setup(id=id,
1069 self.setup(id=id,
1070 nplots=nplots,
1070 nplots=nplots,
1071 wintitle=wintitle,
1071 wintitle=wintitle,
1072 showprofile=showprofile,
1072 showprofile=showprofile,
1073 show=show)
1073 show=show)
1074
1074
1075 tmin, tmax = self.getTimeLim(x, xmin, xmax, timezone = dataOut.timezone)
1075 tmin, tmax = self.getTimeLim(x, xmin, xmax, timezone = dataOut.timezone)
1076 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1076 if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0
1077 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1077 if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0
1078
1078
1079 self.FTP_WEI = ftp_wei
1079 self.FTP_WEI = ftp_wei
1080 self.EXP_CODE = exp_code
1080 self.EXP_CODE = exp_code
1081 self.SUB_EXP_CODE = sub_exp_code
1081 self.SUB_EXP_CODE = sub_exp_code
1082 self.PLOT_POS = plot_pos
1082 self.PLOT_POS = plot_pos
1083
1083
1084
1084
1085 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1085 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1086 self.isConfig = True
1086 self.isConfig = True
1087 self.figfile = figfile
1087 self.figfile = figfile
1088 self.xdata = numpy.array([])
1088 self.xdata = numpy.array([])
1089 self.ydata = numpy.array([])
1089 self.ydata = numpy.array([])
1090
1090
1091 #open file beacon phase
1091 #open file beacon phase
1092 path = '%s%03d' %(self.PREFIX, self.id)
1092 path = '%s%03d' %(self.PREFIX, self.id)
1093 noise_file = os.path.join(path,'%s.txt'%self.name)
1093 noise_file = os.path.join(path,'%s.txt'%self.name)
1094 self.filename_noise = os.path.join(figpath,noise_file)
1094 self.filename_noise = os.path.join(figpath,noise_file)
1095 self.openfile(self.filename_noise)
1095 self.openfile(self.filename_noise)
1096
1096
1097
1097
1098 #store data beacon phase
1098 #store data beacon phase
1099 self.save_data(self.filename_noise, noisedB, thisDatetime)
1099 self.save_data(self.filename_noise, noisedB, thisDatetime)
1100
1100
1101
1101
1102 self.setWinTitle(title)
1102 self.setWinTitle(title)
1103
1103
1104
1104
1105 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1105 title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1106
1106
1107 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1107 legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList]
1108 axes = self.axesList[0]
1108 axes = self.axesList[0]
1109
1109
1110 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1110 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1111
1111
1112 if len(self.ydata)==0:
1112 if len(self.ydata)==0:
1113 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1113 self.ydata = noisedB[channelIndexList].reshape(-1,1)
1114 else:
1114 else:
1115 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1115 self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1)))
1116
1116
1117
1117
1118 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1118 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1119 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1119 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1120 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1120 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1121 XAxisAsTime=True, grid='both'
1121 XAxisAsTime=True, grid='both'
1122 )
1122 )
1123
1123
1124 self.draw()
1124 self.draw()
1125
1125
1126 if x[1] >= self.axesList[0].xmax:
1126 if x[1] >= self.axesList[0].xmax:
1127 self.counter_imagwr = wr_period
1127 self.counter_imagwr = wr_period
1128 del self.xdata
1128 del self.xdata
1129 del self.ydata
1129 del self.ydata
1130 self.__isConfig = False
1130 self.__isConfig = False
1131
1131
1132 if self.figfile == None:
1132 if self.figfile == None:
1133 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1133 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1134 self.figfile = self.getFilename(name = str_datetime)
1134 self.figfile = self.getFilename(name = str_datetime)
1135
1135
1136 if figpath != '':
1136 if figpath != '':
1137 self.counter_imagwr += 1
1137 self.counter_imagwr += 1
1138 if (self.counter_imagwr>=wr_period):
1138 if (self.counter_imagwr>=wr_period):
1139 # store png plot to local folder
1139 # store png plot to local folder
1140 self.saveFigure(figpath, self.figfile)
1140 self.saveFigure(figpath, self.figfile)
1141 # store png plot to FTP server according to RT-Web format
1141 # store png plot to FTP server according to RT-Web format
1142 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1142 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1143 ftp_filename = os.path.join(figpath, name)
1143 ftp_filename = os.path.join(figpath, name)
1144 self.saveFigure(figpath, ftp_filename)
1144 self.saveFigure(figpath, ftp_filename)
1145 self.counter_imagwr = 0
1145 self.counter_imagwr = 0
1146
1146
1147
1147
1148 class BeaconPhase(Figure):
1148 class BeaconPhase(Figure):
1149
1149
1150 __isConfig = None
1150 __isConfig = None
1151 __nsubplots = None
1151 __nsubplots = None
1152
1152
1153 PREFIX = 'beacon_phase'
1153 PREFIX = 'beacon_phase'
1154
1154
1155 def __init__(self):
1155 def __init__(self):
1156
1156
1157 self.timerange = 24*60*60
1157 self.timerange = 24*60*60
1158 self.__isConfig = False
1158 self.__isConfig = False
1159 self.__nsubplots = 1
1159 self.__nsubplots = 1
1160 self.counter_imagwr = 0
1160 self.counter_imagwr = 0
1161 self.WIDTH = 600
1161 self.WIDTH = 600
1162 self.HEIGHT = 300
1162 self.HEIGHT = 300
1163 self.WIDTHPROF = 120
1163 self.WIDTHPROF = 120
1164 self.HEIGHTPROF = 0
1164 self.HEIGHTPROF = 0
1165 self.xdata = None
1165 self.xdata = None
1166 self.ydata = None
1166 self.ydata = None
1167
1167
1168 self.PLOT_CODE = 18
1168 self.PLOT_CODE = 18
1169 self.FTP_WEI = None
1169 self.FTP_WEI = None
1170 self.EXP_CODE = None
1170 self.EXP_CODE = None
1171 self.SUB_EXP_CODE = None
1171 self.SUB_EXP_CODE = None
1172 self.PLOT_POS = None
1172 self.PLOT_POS = None
1173
1173
1174 self.filename_phase = None
1174 self.filename_phase = None
1175
1175
1176 self.figfile = None
1176 self.figfile = None
1177
1177
1178 def getSubplots(self):
1178 def getSubplots(self):
1179
1179
1180 ncol = 1
1180 ncol = 1
1181 nrow = 1
1181 nrow = 1
1182
1182
1183 return nrow, ncol
1183 return nrow, ncol
1184
1184
1185 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1185 def setup(self, id, nplots, wintitle, showprofile=True, show=True):
1186
1186
1187 self.__showprofile = showprofile
1187 self.__showprofile = showprofile
1188 self.nplots = nplots
1188 self.nplots = nplots
1189
1189
1190 ncolspan = 7
1190 ncolspan = 7
1191 colspan = 6
1191 colspan = 6
1192 self.__nsubplots = 2
1192 self.__nsubplots = 2
1193
1193
1194 self.createFigure(id = id,
1194 self.createFigure(id = id,
1195 wintitle = wintitle,
1195 wintitle = wintitle,
1196 widthplot = self.WIDTH+self.WIDTHPROF,
1196 widthplot = self.WIDTH+self.WIDTHPROF,
1197 heightplot = self.HEIGHT+self.HEIGHTPROF,
1197 heightplot = self.HEIGHT+self.HEIGHTPROF,
1198 show=show)
1198 show=show)
1199
1199
1200 nrow, ncol = self.getSubplots()
1200 nrow, ncol = self.getSubplots()
1201
1201
1202 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1202 self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1)
1203
1203
1204 def save_phase(self, filename_phase):
1204 def save_phase(self, filename_phase):
1205 f = open(filename_phase,'w+')
1205 f = open(filename_phase,'w+')
1206 f.write('\n\n')
1206 f.write('\n\n')
1207 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1207 f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n')
1208 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1208 f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' )
1209 f.close()
1209 f.close()
1210
1210
1211 def save_data(self, filename_phase, data, data_datetime):
1211 def save_data(self, filename_phase, data, data_datetime):
1212 f=open(filename_phase,'a')
1212 f=open(filename_phase,'a')
1213 timetuple_data = data_datetime.timetuple()
1213 timetuple_data = data_datetime.timetuple()
1214 day = str(timetuple_data.tm_mday)
1214 day = str(timetuple_data.tm_mday)
1215 month = str(timetuple_data.tm_mon)
1215 month = str(timetuple_data.tm_mon)
1216 year = str(timetuple_data.tm_year)
1216 year = str(timetuple_data.tm_year)
1217 hour = str(timetuple_data.tm_hour)
1217 hour = str(timetuple_data.tm_hour)
1218 minute = str(timetuple_data.tm_min)
1218 minute = str(timetuple_data.tm_min)
1219 second = str(timetuple_data.tm_sec)
1219 second = str(timetuple_data.tm_sec)
1220 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1220 f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n')
1221 f.close()
1221 f.close()
1222
1222
1223
1223
1224 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1224 def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True',
1225 xmin=None, xmax=None, ymin=None, ymax=None,
1225 xmin=None, xmax=None, ymin=None, ymax=None,
1226 timerange=None,
1226 timerange=None,
1227 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1227 save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1,
1228 server=None, folder=None, username=None, password=None,
1228 server=None, folder=None, username=None, password=None,
1229 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1229 ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0):
1230
1230
1231 if pairsList == None:
1231 if pairsList == None:
1232 pairsIndexList = dataOut.pairsIndexList
1232 pairsIndexList = dataOut.pairsIndexList
1233 else:
1233 else:
1234 pairsIndexList = []
1234 pairsIndexList = []
1235 for pair in pairsList:
1235 for pair in pairsList:
1236 if pair not in dataOut.pairsList:
1236 if pair not in dataOut.pairsList:
1237 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1237 raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair)
1238 pairsIndexList.append(dataOut.pairsList.index(pair))
1238 pairsIndexList.append(dataOut.pairsList.index(pair))
1239
1239
1240 if pairsIndexList == []:
1240 if pairsIndexList == []:
1241 return
1241 return
1242
1242
1243 # if len(pairsIndexList) > 4:
1243 # if len(pairsIndexList) > 4:
1244 # pairsIndexList = pairsIndexList[0:4]
1244 # pairsIndexList = pairsIndexList[0:4]
1245
1245
1246 if timerange != None:
1246 if timerange != None:
1247 self.timerange = timerange
1247 self.timerange = timerange
1248
1248
1249 tmin = None
1249 tmin = None
1250 tmax = None
1250 tmax = None
1251 x = dataOut.getTimeRange()
1251 x = dataOut.getTimeRange()
1252 y = dataOut.getHeiRange()
1252 y = dataOut.getHeiRange()
1253
1253
1254
1254
1255 #thisDatetime = dataOut.datatime
1255 #thisDatetime = dataOut.datatime
1256 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1256 thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1])
1257 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1257 title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y"))
1258 xlabel = "Local Time"
1258 xlabel = "Local Time"
1259 ylabel = "Phase"
1259 ylabel = "Phase"
1260
1260
1261 nplots = len(pairsIndexList)
1261 nplots = len(pairsIndexList)
1262 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1262 #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList)))
1263 phase_beacon = numpy.zeros(len(pairsIndexList))
1263 phase_beacon = numpy.zeros(len(pairsIndexList))
1264 for i in range(nplots):
1264 for i in range(nplots):
1265 pair = dataOut.pairsList[pairsIndexList[i]]
1265 pair = dataOut.pairsList[pairsIndexList[i]]
1266 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1266 ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0)
1267 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1267 powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0)
1268 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1268 powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0)
1269 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1269 avgcoherenceComplex = ccf/numpy.sqrt(powa*powb)
1270 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1270 phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi
1271
1271
1272 #print "Phase %d%d" %(pair[0], pair[1])
1272 #print "Phase %d%d" %(pair[0], pair[1])
1273 #print phase[dataOut.beacon_heiIndexList]
1273 #print phase[dataOut.beacon_heiIndexList]
1274
1274
1275 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1275 phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList])
1276
1276
1277 if not self.__isConfig:
1277 if not self.__isConfig:
1278
1278
1279 nplots = len(pairsIndexList)
1279 nplots = len(pairsIndexList)
1280
1280
1281 self.setup(id=id,
1281 self.setup(id=id,
1282 nplots=nplots,
1282 nplots=nplots,
1283 wintitle=wintitle,
1283 wintitle=wintitle,
1284 showprofile=showprofile,
1284 showprofile=showprofile,
1285 show=show)
1285 show=show)
1286
1286
1287 tmin, tmax = self.getTimeLim(x, xmin, xmax, timezone = dataOut.timezone)
1287 tmin, tmax = self.getTimeLim(x, xmin, xmax, timezone = dataOut.timezone)
1288 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1288 if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0
1289 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1289 if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0
1290
1290
1291 self.FTP_WEI = ftp_wei
1291 self.FTP_WEI = ftp_wei
1292 self.EXP_CODE = exp_code
1292 self.EXP_CODE = exp_code
1293 self.SUB_EXP_CODE = sub_exp_code
1293 self.SUB_EXP_CODE = sub_exp_code
1294 self.PLOT_POS = plot_pos
1294 self.PLOT_POS = plot_pos
1295
1295
1296 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1296 self.name = thisDatetime.strftime("%Y%m%d_%H%M%S")
1297 self.__isConfig = True
1297 self.__isConfig = True
1298 self.figfile = figfile
1298 self.figfile = figfile
1299 self.xdata = numpy.array([])
1299 self.xdata = numpy.array([])
1300 self.ydata = numpy.array([])
1300 self.ydata = numpy.array([])
1301
1301
1302 #open file beacon phase
1302 #open file beacon phase
1303 path = '%s%03d' %(self.PREFIX, self.id)
1303 path = '%s%03d' %(self.PREFIX, self.id)
1304 beacon_file = os.path.join(path,'%s.txt'%self.name)
1304 beacon_file = os.path.join(path,'%s.txt'%self.name)
1305 self.filename_phase = os.path.join(figpath,beacon_file)
1305 self.filename_phase = os.path.join(figpath,beacon_file)
1306 #self.save_phase(self.filename_phase)
1306 #self.save_phase(self.filename_phase)
1307
1307
1308
1308
1309 #store data beacon phase
1309 #store data beacon phase
1310 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1310 #self.save_data(self.filename_phase, phase_beacon, thisDatetime)
1311
1311
1312 self.setWinTitle(title)
1312 self.setWinTitle(title)
1313
1313
1314
1314
1315 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1315 title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S"))
1316
1316
1317 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1317 legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList]
1318
1318
1319 axes = self.axesList[0]
1319 axes = self.axesList[0]
1320
1320
1321 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1321 self.xdata = numpy.hstack((self.xdata, x[0:1]))
1322
1322
1323 if len(self.ydata)==0:
1323 if len(self.ydata)==0:
1324 self.ydata = phase_beacon.reshape(-1,1)
1324 self.ydata = phase_beacon.reshape(-1,1)
1325 else:
1325 else:
1326 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1326 self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1)))
1327
1327
1328
1328
1329 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1329 axes.pmultilineyaxis(x=self.xdata, y=self.ydata,
1330 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1330 xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax,
1331 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1331 xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid",
1332 XAxisAsTime=True, grid='both'
1332 XAxisAsTime=True, grid='both'
1333 )
1333 )
1334
1334
1335 self.draw()
1335 self.draw()
1336
1336
1337 if x[1] >= self.axesList[0].xmax:
1337 if x[1] >= self.axesList[0].xmax:
1338 self.counter_imagwr = wr_period
1338 self.counter_imagwr = wr_period
1339 del self.xdata
1339 del self.xdata
1340 del self.ydata
1340 del self.ydata
1341 self.__isConfig = False
1341 self.__isConfig = False
1342
1342
1343 if self.figfile == None:
1343 if self.figfile == None:
1344 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1344 str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S")
1345 self.figfile = self.getFilename(name = str_datetime)
1345 self.figfile = self.getFilename(name = str_datetime)
1346
1346
1347 if figpath != '':
1347 if figpath != '':
1348 self.counter_imagwr += 1
1348 self.counter_imagwr += 1
1349 if (self.counter_imagwr>=wr_period):
1349 if (self.counter_imagwr>=wr_period):
1350 # store png plot to local folder
1350 # store png plot to local folder
1351 self.saveFigure(figpath, self.figfile)
1351 self.saveFigure(figpath, self.figfile)
1352 # store png plot to FTP server according to RT-Web format
1352 # store png plot to FTP server according to RT-Web format
1353 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1353 name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS)
1354 ftp_filename = os.path.join(figpath, name)
1354 ftp_filename = os.path.join(figpath, name)
1355 self.saveFigure(figpath, ftp_filename)
1355 self.saveFigure(figpath, ftp_filename)
1356 self.counter_imagwr = 0
1356 self.counter_imagwr = 0
@@ -1,1349 +1,1352
1 '''
1 '''
2
2
3 '''
3 '''
4 import os
4 import os
5 import sys
5 import sys
6 import glob
6 import glob
7 import time
7 import time
8 import numpy
8 import numpy
9 import fnmatch
9 import fnmatch
10 import time, datetime
10 import time, datetime
11 #import h5py
11 #import h5py
12 import traceback
12 import traceback
13
13
14 #try:
14 #try:
15 # import pyfits
15 # import pyfits
16 #except:
16 #except:
17 # print "pyfits module has not been imported, it should be installed to save files in fits format"
17 # print "pyfits module has not been imported, it should be installed to save files in fits format"
18
18
19 #from jrodata import *
19 #from jrodata import *
20 #from jroheaderIO import *
20 #from jroheaderIO import *
21 #from jroprocessing import *
21 #from jroprocessing import *
22
22
23 #import re
23 #import re
24 #from xml.etree.ElementTree import Element, SubElement, ElementTree
24 #from xml.etree.ElementTree import Element, SubElement, ElementTree
25
25
26
26
27 LOCALTIME = True #-18000
27 LOCALTIME = True #-18000
28
28
29 from model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
29 from model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader
30
30
31 def isNumber(str):
31 def isNumber(str):
32 """
32 """
33 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
33 Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero.
34
34
35 Excepciones:
35 Excepciones:
36 Si un determinado string no puede ser convertido a numero
36 Si un determinado string no puede ser convertido a numero
37 Input:
37 Input:
38 str, string al cual se le analiza para determinar si convertible a un numero o no
38 str, string al cual se le analiza para determinar si convertible a un numero o no
39
39
40 Return:
40 Return:
41 True : si el string es uno numerico
41 True : si el string es uno numerico
42 False : no es un string numerico
42 False : no es un string numerico
43 """
43 """
44 try:
44 try:
45 float( str )
45 float( str )
46 return True
46 return True
47 except:
47 except:
48 return False
48 return False
49
49
50 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
50 def isThisFileinRange(filename, startUTSeconds, endUTSeconds):
51 """
51 """
52 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
52 Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado.
53
53
54 Inputs:
54 Inputs:
55 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
55 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
56
56
57 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
57 startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en
58 segundos contados desde 01/01/1970.
58 segundos contados desde 01/01/1970.
59 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
59 endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en
60 segundos contados desde 01/01/1970.
60 segundos contados desde 01/01/1970.
61
61
62 Return:
62 Return:
63 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
63 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
64 fecha especificado, de lo contrario retorna False.
64 fecha especificado, de lo contrario retorna False.
65
65
66 Excepciones:
66 Excepciones:
67 Si el archivo no existe o no puede ser abierto
67 Si el archivo no existe o no puede ser abierto
68 Si la cabecera no puede ser leida.
68 Si la cabecera no puede ser leida.
69
69
70 """
70 """
71 basicHeaderObj = BasicHeader(LOCALTIME)
71 basicHeaderObj = BasicHeader(LOCALTIME)
72
72
73 try:
73 try:
74 fp = open(filename,'rb')
74 fp = open(filename,'rb')
75 except IOError:
75 except IOError:
76 traceback.print_exc()
76 traceback.print_exc()
77 raise IOError, "The file %s can't be opened" %(filename)
77 raise IOError, "The file %s can't be opened" %(filename)
78
78
79 sts = basicHeaderObj.read(fp)
79 sts = basicHeaderObj.read(fp)
80 fp.close()
80 fp.close()
81
81
82 if not(sts):
82 if not(sts):
83 print "Skipping the file %s because it has not a valid header" %(filename)
83 print "Skipping the file %s because it has not a valid header" %(filename)
84 return 0
84 return 0
85
85
86 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
86 if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)):
87 return 0
87 return 0
88
88
89 return 1
89 return 1
90
90
91 def isFileinThisTime(filename, startTime, endTime):
91 def isFileinThisTime(filename, startTime, endTime):
92 """
92 """
93 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
93 Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado.
94
94
95 Inputs:
95 Inputs:
96 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
96 filename : nombre completo del archivo de datos en formato Jicamarca (.r)
97
97
98 startTime : tiempo inicial del rango seleccionado en formato datetime.time
98 startTime : tiempo inicial del rango seleccionado en formato datetime.time
99
99
100 endTime : tiempo final del rango seleccionado en formato datetime.time
100 endTime : tiempo final del rango seleccionado en formato datetime.time
101
101
102 Return:
102 Return:
103 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
103 Boolean : Retorna True si el archivo de datos contiene datos en el rango de
104 fecha especificado, de lo contrario retorna False.
104 fecha especificado, de lo contrario retorna False.
105
105
106 Excepciones:
106 Excepciones:
107 Si el archivo no existe o no puede ser abierto
107 Si el archivo no existe o no puede ser abierto
108 Si la cabecera no puede ser leida.
108 Si la cabecera no puede ser leida.
109
109
110 """
110 """
111
111
112
112
113 try:
113 try:
114 fp = open(filename,'rb')
114 fp = open(filename,'rb')
115 except IOError:
115 except IOError:
116 traceback.print_exc()
116 traceback.print_exc()
117 raise IOError, "The file %s can't be opened" %(filename)
117 raise IOError, "The file %s can't be opened" %(filename)
118
118
119 basicHeaderObj = BasicHeader(LOCALTIME)
119 basicHeaderObj = BasicHeader(LOCALTIME)
120 sts = basicHeaderObj.read(fp)
120 sts = basicHeaderObj.read(fp)
121 fp.close()
121 fp.close()
122
122
123 thisDatetime = basicHeaderObj.datatime
123 thisDatetime = basicHeaderObj.datatime
124 thisTime = thisDatetime.time()
124 thisTime = thisDatetime.time()
125
125
126 if not(sts):
126 if not(sts):
127 print "Skipping the file %s because it has not a valid header" %(filename)
127 print "Skipping the file %s because it has not a valid header" %(filename)
128 return None
128 return None
129
129
130 if not ((startTime <= thisTime) and (endTime > thisTime)):
130 if not ((startTime <= thisTime) and (endTime > thisTime)):
131 return None
131 return None
132
132
133 return thisDatetime
133 return thisDatetime
134
134
135 def getFileFromSet(path, ext, set):
135 def getFileFromSet(path, ext, set):
136 validFilelist = []
136 validFilelist = []
137 fileList = os.listdir(path)
137 fileList = os.listdir(path)
138
138
139 # 0 1234 567 89A BCDE
139 # 0 1234 567 89A BCDE
140 # H YYYY DDD SSS .ext
140 # H YYYY DDD SSS .ext
141
141
142 for thisFile in fileList:
142 for thisFile in fileList:
143 try:
143 try:
144 year = int(thisFile[1:5])
144 year = int(thisFile[1:5])
145 doy = int(thisFile[5:8])
145 doy = int(thisFile[5:8])
146 except:
146 except:
147 continue
147 continue
148
148
149 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
149 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
150 continue
150 continue
151
151
152 validFilelist.append(thisFile)
152 validFilelist.append(thisFile)
153
153
154 myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set))
154 myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set))
155
155
156 if len(myfile)!= 0:
156 if len(myfile)!= 0:
157 return myfile[0]
157 return myfile[0]
158 else:
158 else:
159 filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower())
159 filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower())
160 print 'the filename %s does not exist'%filename
160 print 'the filename %s does not exist'%filename
161 print '...going to the last file: '
161 print '...going to the last file: '
162
162
163 if validFilelist:
163 if validFilelist:
164 validFilelist = sorted( validFilelist, key=str.lower )
164 validFilelist = sorted( validFilelist, key=str.lower )
165 return validFilelist[-1]
165 return validFilelist[-1]
166
166
167 return None
167 return None
168
168
169 def getlastFileFromPath(path, ext):
169 def getlastFileFromPath(path, ext):
170 """
170 """
171 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
171 Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext"
172 al final de la depuracion devuelve el ultimo file de la lista que quedo.
172 al final de la depuracion devuelve el ultimo file de la lista que quedo.
173
173
174 Input:
174 Input:
175 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
175 fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta
176 ext : extension de los files contenidos en una carpeta
176 ext : extension de los files contenidos en una carpeta
177
177
178 Return:
178 Return:
179 El ultimo file de una determinada carpeta, no se considera el path.
179 El ultimo file de una determinada carpeta, no se considera el path.
180 """
180 """
181 validFilelist = []
181 validFilelist = []
182 fileList = os.listdir(path)
182 fileList = os.listdir(path)
183
183
184 # 0 1234 567 89A BCDE
184 # 0 1234 567 89A BCDE
185 # H YYYY DDD SSS .ext
185 # H YYYY DDD SSS .ext
186
186
187 for thisFile in fileList:
187 for thisFile in fileList:
188
188
189 year = thisFile[1:5]
189 year = thisFile[1:5]
190 if not isNumber(year):
190 if not isNumber(year):
191 continue
191 continue
192
192
193 doy = thisFile[5:8]
193 doy = thisFile[5:8]
194 if not isNumber(doy):
194 if not isNumber(doy):
195 continue
195 continue
196
196
197 year = int(year)
197 year = int(year)
198 doy = int(doy)
198 doy = int(doy)
199
199
200 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
200 if (os.path.splitext(thisFile)[-1].lower() != ext.lower()):
201 continue
201 continue
202
202
203 validFilelist.append(thisFile)
203 validFilelist.append(thisFile)
204
204
205 if validFilelist:
205 if validFilelist:
206 validFilelist = sorted( validFilelist, key=str.lower )
206 validFilelist = sorted( validFilelist, key=str.lower )
207 return validFilelist[-1]
207 return validFilelist[-1]
208
208
209 return None
209 return None
210
210
211 def checkForRealPath(path, foldercounter, year, doy, set, ext):
211 def checkForRealPath(path, foldercounter, year, doy, set, ext):
212 """
212 """
213 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
213 Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path,
214 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
214 Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar
215 el path exacto de un determinado file.
215 el path exacto de un determinado file.
216
216
217 Example :
217 Example :
218 nombre correcto del file es .../.../D2009307/P2009307367.ext
218 nombre correcto del file es .../.../D2009307/P2009307367.ext
219
219
220 Entonces la funcion prueba con las siguientes combinaciones
220 Entonces la funcion prueba con las siguientes combinaciones
221 .../.../y2009307367.ext
221 .../.../y2009307367.ext
222 .../.../Y2009307367.ext
222 .../.../Y2009307367.ext
223 .../.../x2009307/y2009307367.ext
223 .../.../x2009307/y2009307367.ext
224 .../.../x2009307/Y2009307367.ext
224 .../.../x2009307/Y2009307367.ext
225 .../.../X2009307/y2009307367.ext
225 .../.../X2009307/y2009307367.ext
226 .../.../X2009307/Y2009307367.ext
226 .../.../X2009307/Y2009307367.ext
227 siendo para este caso, la ultima combinacion de letras, identica al file buscado
227 siendo para este caso, la ultima combinacion de letras, identica al file buscado
228
228
229 Return:
229 Return:
230 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
230 Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file
231 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
231 caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas
232 para el filename
232 para el filename
233 """
233 """
234 fullfilename = None
234 fullfilename = None
235 find_flag = False
235 find_flag = False
236 filename = None
236 filename = None
237
237
238 prefixDirList = [None,'d','D']
238 prefixDirList = [None,'d','D']
239 if ext.lower() == ".r": #voltage
239 if ext.lower() == ".r": #voltage
240 prefixFileList = ['d','D']
240 prefixFileList = ['d','D']
241 elif ext.lower() == ".pdata": #spectra
241 elif ext.lower() == ".pdata": #spectra
242 prefixFileList = ['p','P']
242 prefixFileList = ['p','P']
243 else:
243 else:
244 return None, filename
244 return None, filename
245
245
246 #barrido por las combinaciones posibles
246 #barrido por las combinaciones posibles
247 for prefixDir in prefixDirList:
247 for prefixDir in prefixDirList:
248 thispath = path
248 thispath = path
249 if prefixDir != None:
249 if prefixDir != None:
250 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
250 #formo el nombre del directorio xYYYYDDD (x=d o x=D)
251 if foldercounter == 0:
251 if foldercounter == 0:
252 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
252 thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy ))
253 else:
253 else:
254 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
254 thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter))
255 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
255 for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D"
256 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
256 filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext
257 fullfilename = os.path.join( thispath, filename ) #formo el path completo
257 fullfilename = os.path.join( thispath, filename ) #formo el path completo
258
258
259 if os.path.exists( fullfilename ): #verifico que exista
259 if os.path.exists( fullfilename ): #verifico que exista
260 find_flag = True
260 find_flag = True
261 break
261 break
262 if find_flag:
262 if find_flag:
263 break
263 break
264
264
265 if not(find_flag):
265 if not(find_flag):
266 return None, filename
266 return None, filename
267
267
268 return fullfilename, filename
268 return fullfilename, filename
269
269
270 def isDoyFolder(folder):
270 def isDoyFolder(folder):
271 try:
271 try:
272 year = int(folder[1:5])
272 year = int(folder[1:5])
273 except:
273 except:
274 return 0
274 return 0
275
275
276 try:
276 try:
277 doy = int(folder[5:8])
277 doy = int(folder[5:8])
278 except:
278 except:
279 return 0
279 return 0
280
280
281 return 1
281 return 1
282
282
283 class JRODataIO:
283 class JRODataIO:
284
284
285 c = 3E8
285 c = 3E8
286
286
287 isConfig = False
287 isConfig = False
288
288
289 basicHeaderObj = None
289 basicHeaderObj = None
290
290
291 systemHeaderObj = None
291 systemHeaderObj = None
292
292
293 radarControllerHeaderObj = None
293 radarControllerHeaderObj = None
294
294
295 processingHeaderObj = None
295 processingHeaderObj = None
296
296
297 online = 0
297 online = 0
298
298
299 dtype = None
299 dtype = None
300
300
301 pathList = []
301 pathList = []
302
302
303 filenameList = []
303 filenameList = []
304
304
305 filename = None
305 filename = None
306
306
307 ext = None
307 ext = None
308
308
309 flagIsNewFile = 1
309 flagIsNewFile = 1
310
310
311 flagTimeBlock = 0
311 flagTimeBlock = 0
312
312
313 flagIsNewBlock = 0
313 flagIsNewBlock = 0
314
314
315 fp = None
315 fp = None
316
316
317 firstHeaderSize = 0
317 firstHeaderSize = 0
318
318
319 basicHeaderSize = 24
319 basicHeaderSize = 24
320
320
321 versionFile = 1103
321 versionFile = 1103
322
322
323 fileSize = None
323 fileSize = None
324
324
325 # ippSeconds = None
325 # ippSeconds = None
326
326
327 fileSizeByHeader = None
327 fileSizeByHeader = None
328
328
329 fileIndex = None
329 fileIndex = None
330
330
331 profileIndex = None
331 profileIndex = None
332
332
333 blockIndex = None
333 blockIndex = None
334
334
335 nTotalBlocks = None
335 nTotalBlocks = None
336
336
337 maxTimeStep = 30
337 maxTimeStep = 30
338
338
339 lastUTTime = None
339 lastUTTime = None
340
340
341 datablock = None
341 datablock = None
342
342
343 dataOut = None
343 dataOut = None
344
344
345 blocksize = None
345 blocksize = None
346
346
347 getByBlock = False
347 getByBlock = False
348
348
349 def __init__(self):
349 def __init__(self):
350
350
351 raise ValueError, "Not implemented"
351 raise ValueError, "Not implemented"
352
352
353 def run(self):
353 def run(self):
354
354
355 raise ValueError, "Not implemented"
355 raise ValueError, "Not implemented"
356
356
357 class JRODataReader(JRODataIO):
357 class JRODataReader(JRODataIO):
358
358
359 nReadBlocks = 0
359 nReadBlocks = 0
360
360
361 delay = 10 #number of seconds waiting a new file
361 delay = 10 #number of seconds waiting a new file
362
362
363 nTries = 3 #quantity tries
363 nTries = 3 #quantity tries
364
364
365 nFiles = 3 #number of files for searching
365 nFiles = 3 #number of files for searching
366
366
367 path = None
367 path = None
368
368
369 foldercounter = 0
369 foldercounter = 0
370
370
371 flagNoMoreFiles = 0
371 flagNoMoreFiles = 0
372
372
373 datetimeList = []
373 datetimeList = []
374
374
375 __isFirstTimeOnline = 1
375 __isFirstTimeOnline = 1
376
376
377 __printInfo = True
377 __printInfo = True
378
378
379 profileIndex = None
379 profileIndex = None
380
380
381 nTxs = 1
381 nTxs = 1
382
382
383 txIndex = None
383 txIndex = None
384
384
385 def __init__(self):
385 def __init__(self):
386
386
387 """
387 """
388
388
389 """
389 """
390
390
391 raise ValueError, "This method has not been implemented"
391 raise ValueError, "This method has not been implemented"
392
392
393
393
394 def createObjByDefault(self):
394 def createObjByDefault(self):
395 """
395 """
396
396
397 """
397 """
398 raise ValueError, "This method has not been implemented"
398 raise ValueError, "This method has not been implemented"
399
399
400 def getBlockDimension(self):
400 def getBlockDimension(self):
401
401
402 raise ValueError, "No implemented"
402 raise ValueError, "No implemented"
403
403
404 def __searchFilesOffLine(self,
404 def __searchFilesOffLine(self,
405 path,
405 path,
406 startDate,
406 startDate,
407 endDate,
407 endDate,
408 startTime=datetime.time(0,0,0),
408 startTime=datetime.time(0,0,0),
409 endTime=datetime.time(23,59,59),
409 endTime=datetime.time(23,59,59),
410 set=None,
410 set=None,
411 expLabel='',
411 expLabel='',
412 ext='.r',
412 ext='.r',
413 walk=True):
413 walk=True):
414
414
415 pathList = []
415 pathList = []
416
416
417 if not walk:
417 if not walk:
418 #pathList.append(path)
418 #pathList.append(path)
419 multi_path = path.split(',')
419 multi_path = path.split(',')
420 for single_path in multi_path:
420 for single_path in multi_path:
421 pathList.append(single_path)
421 pathList.append(single_path)
422
422
423 else:
423 else:
424 #dirList = []
424 #dirList = []
425 multi_path = path.split(',')
425 multi_path = path.split(',')
426 for single_path in multi_path:
426 for single_path in multi_path:
427 dirList = []
427 dirList = []
428 for thisPath in os.listdir(single_path):
428 for thisPath in os.listdir(single_path):
429 if not os.path.isdir(os.path.join(single_path,thisPath)):
429 if not os.path.isdir(os.path.join(single_path,thisPath)):
430 continue
430 continue
431 if not isDoyFolder(thisPath):
431 if not isDoyFolder(thisPath):
432 continue
432 continue
433
433
434 dirList.append(thisPath)
434 dirList.append(thisPath)
435
435
436 if not(dirList):
436 if not(dirList):
437 return None, None
437 return None, None
438
438
439 thisDate = startDate
439 thisDate = startDate
440
440
441 while(thisDate <= endDate):
441 while(thisDate <= endDate):
442 year = thisDate.timetuple().tm_year
442 year = thisDate.timetuple().tm_year
443 doy = thisDate.timetuple().tm_yday
443 doy = thisDate.timetuple().tm_yday
444
444
445 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
445 matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*')
446 if len(matchlist) == 0:
446 if len(matchlist) == 0:
447 thisDate += datetime.timedelta(1)
447 thisDate += datetime.timedelta(1)
448 continue
448 continue
449 for match in matchlist:
449 for match in matchlist:
450 pathList.append(os.path.join(single_path,match,expLabel))
450 pathList.append(os.path.join(single_path,match,expLabel))
451
451
452 thisDate += datetime.timedelta(1)
452 thisDate += datetime.timedelta(1)
453
453
454 if pathList == []:
454 if pathList == []:
455 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
455 print "Any folder was found for the date range: %s-%s" %(startDate, endDate)
456 return None, None
456 return None, None
457
457
458 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
458 print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate)
459
459
460 filenameList = []
460 filenameList = []
461 datetimeList = []
461 datetimeList = []
462 pathDict = {}
462 pathDict = {}
463 filenameList_to_sort = []
463 filenameList_to_sort = []
464
464
465 for i in range(len(pathList)):
465 for i in range(len(pathList)):
466
466
467 thisPath = pathList[i]
467 thisPath = pathList[i]
468
468
469 fileList = glob.glob1(thisPath, "*%s" %ext)
469 fileList = glob.glob1(thisPath, "*%s" %ext)
470 if len(fileList) < 1:
471 continue
472
470 fileList.sort()
473 fileList.sort()
471 pathDict.setdefault(fileList[0])
474 pathDict.setdefault(fileList[0])
472 pathDict[fileList[0]] = i
475 pathDict[fileList[0]] = i
473 filenameList_to_sort.append(fileList[0])
476 filenameList_to_sort.append(fileList[0])
474
477
475 filenameList_to_sort.sort()
478 filenameList_to_sort.sort()
476
479
477 for file in filenameList_to_sort:
480 for file in filenameList_to_sort:
478 thisPath = pathList[pathDict[file]]
481 thisPath = pathList[pathDict[file]]
479
482
480 fileList = glob.glob1(thisPath, "*%s" %ext)
483 fileList = glob.glob1(thisPath, "*%s" %ext)
481 fileList.sort()
484 fileList.sort()
482
485
483 for file in fileList:
486 for file in fileList:
484
487
485 filename = os.path.join(thisPath,file)
488 filename = os.path.join(thisPath,file)
486 thisDatetime = isFileinThisTime(filename, startTime, endTime)
489 thisDatetime = isFileinThisTime(filename, startTime, endTime)
487
490
488 if not(thisDatetime):
491 if not(thisDatetime):
489 continue
492 continue
490
493
491 filenameList.append(filename)
494 filenameList.append(filename)
492 datetimeList.append(thisDatetime)
495 datetimeList.append(thisDatetime)
493
496
494 if not(filenameList):
497 if not(filenameList):
495 print "Any file was found for the time range %s - %s" %(startTime, endTime)
498 print "Any file was found for the time range %s - %s" %(startTime, endTime)
496 return None, None
499 return None, None
497
500
498 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
501 print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime)
499 print
502 print
500
503
501 for i in range(len(filenameList)):
504 for i in range(len(filenameList)):
502 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
505 print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime())
503
506
504 self.filenameList = filenameList
507 self.filenameList = filenameList
505 self.datetimeList = datetimeList
508 self.datetimeList = datetimeList
506
509
507 return pathList, filenameList
510 return pathList, filenameList
508
511
509 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None):
512 def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None):
510
513
511 """
514 """
512 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
515 Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y
513 devuelve el archivo encontrado ademas de otros datos.
516 devuelve el archivo encontrado ademas de otros datos.
514
517
515 Input:
518 Input:
516 path : carpeta donde estan contenidos los files que contiene data
519 path : carpeta donde estan contenidos los files que contiene data
517
520
518 expLabel : Nombre del subexperimento (subfolder)
521 expLabel : Nombre del subexperimento (subfolder)
519
522
520 ext : extension de los files
523 ext : extension de los files
521
524
522 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
525 walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath)
523
526
524 Return:
527 Return:
525 directory : eL directorio donde esta el file encontrado
528 directory : eL directorio donde esta el file encontrado
526 filename : el ultimo file de una determinada carpeta
529 filename : el ultimo file de una determinada carpeta
527 year : el anho
530 year : el anho
528 doy : el numero de dia del anho
531 doy : el numero de dia del anho
529 set : el set del archivo
532 set : el set del archivo
530
533
531
534
532 """
535 """
533 dirList = []
536 dirList = []
534
537
535 if not walk:
538 if not walk:
536 fullpath = path
539 fullpath = path
537 foldercounter = 0
540 foldercounter = 0
538 else:
541 else:
539 #Filtra solo los directorios
542 #Filtra solo los directorios
540 for thisPath in os.listdir(path):
543 for thisPath in os.listdir(path):
541 if not os.path.isdir(os.path.join(path,thisPath)):
544 if not os.path.isdir(os.path.join(path,thisPath)):
542 continue
545 continue
543 if not isDoyFolder(thisPath):
546 if not isDoyFolder(thisPath):
544 continue
547 continue
545
548
546 dirList.append(thisPath)
549 dirList.append(thisPath)
547
550
548 if not(dirList):
551 if not(dirList):
549 return None, None, None, None, None, None
552 return None, None, None, None, None, None
550
553
551 dirList = sorted( dirList, key=str.lower )
554 dirList = sorted( dirList, key=str.lower )
552
555
553 doypath = dirList[-1]
556 doypath = dirList[-1]
554 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
557 foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0
555 fullpath = os.path.join(path, doypath, expLabel)
558 fullpath = os.path.join(path, doypath, expLabel)
556
559
557
560
558 print "%s folder was found: " %(fullpath )
561 print "%s folder was found: " %(fullpath )
559
562
560 if set == None:
563 if set == None:
561 filename = getlastFileFromPath(fullpath, ext)
564 filename = getlastFileFromPath(fullpath, ext)
562 else:
565 else:
563 filename = getFileFromSet(fullpath, ext, set)
566 filename = getFileFromSet(fullpath, ext, set)
564
567
565 if not(filename):
568 if not(filename):
566 return None, None, None, None, None, None
569 return None, None, None, None, None, None
567
570
568 print "%s file was found" %(filename)
571 print "%s file was found" %(filename)
569
572
570 if not(self.__verifyFile(os.path.join(fullpath, filename))):
573 if not(self.__verifyFile(os.path.join(fullpath, filename))):
571 return None, None, None, None, None, None
574 return None, None, None, None, None, None
572
575
573 year = int( filename[1:5] )
576 year = int( filename[1:5] )
574 doy = int( filename[5:8] )
577 doy = int( filename[5:8] )
575 set = int( filename[8:11] )
578 set = int( filename[8:11] )
576
579
577 return fullpath, foldercounter, filename, year, doy, set
580 return fullpath, foldercounter, filename, year, doy, set
578
581
579 def __setNextFileOffline(self):
582 def __setNextFileOffline(self):
580
583
581 idFile = self.fileIndex
584 idFile = self.fileIndex
582
585
583 while (True):
586 while (True):
584 idFile += 1
587 idFile += 1
585 if not(idFile < len(self.filenameList)):
588 if not(idFile < len(self.filenameList)):
586 self.flagNoMoreFiles = 1
589 self.flagNoMoreFiles = 1
587 print "No more Files"
590 print "No more Files"
588 return 0
591 return 0
589
592
590 filename = self.filenameList[idFile]
593 filename = self.filenameList[idFile]
591
594
592 if not(self.__verifyFile(filename)):
595 if not(self.__verifyFile(filename)):
593 continue
596 continue
594
597
595 fileSize = os.path.getsize(filename)
598 fileSize = os.path.getsize(filename)
596 fp = open(filename,'rb')
599 fp = open(filename,'rb')
597 break
600 break
598
601
599 self.flagIsNewFile = 1
602 self.flagIsNewFile = 1
600 self.fileIndex = idFile
603 self.fileIndex = idFile
601 self.filename = filename
604 self.filename = filename
602 self.fileSize = fileSize
605 self.fileSize = fileSize
603 self.fp = fp
606 self.fp = fp
604
607
605 print "Setting the file: %s"%self.filename
608 print "Setting the file: %s"%self.filename
606
609
607 return 1
610 return 1
608
611
609 def __setNextFileOnline(self):
612 def __setNextFileOnline(self):
610 """
613 """
611 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
614 Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si
612 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
615 no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files
613 siguientes.
616 siguientes.
614
617
615 Affected:
618 Affected:
616 self.flagIsNewFile
619 self.flagIsNewFile
617 self.filename
620 self.filename
618 self.fileSize
621 self.fileSize
619 self.fp
622 self.fp
620 self.set
623 self.set
621 self.flagNoMoreFiles
624 self.flagNoMoreFiles
622
625
623 Return:
626 Return:
624 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
627 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado
625 1 : si el file fue abierto con exito y esta listo a ser leido
628 1 : si el file fue abierto con exito y esta listo a ser leido
626
629
627 Excepciones:
630 Excepciones:
628 Si un determinado file no puede ser abierto
631 Si un determinado file no puede ser abierto
629 """
632 """
630 nFiles = 0
633 nFiles = 0
631 fileOk_flag = False
634 fileOk_flag = False
632 firstTime_flag = True
635 firstTime_flag = True
633
636
634 self.set += 1
637 self.set += 1
635
638
636 if self.set > 999:
639 if self.set > 999:
637 self.set = 0
640 self.set = 0
638 self.foldercounter += 1
641 self.foldercounter += 1
639
642
640 #busca el 1er file disponible
643 #busca el 1er file disponible
641 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
644 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
642 if fullfilename:
645 if fullfilename:
643 if self.__verifyFile(fullfilename, False):
646 if self.__verifyFile(fullfilename, False):
644 fileOk_flag = True
647 fileOk_flag = True
645
648
646 #si no encuentra un file entonces espera y vuelve a buscar
649 #si no encuentra un file entonces espera y vuelve a buscar
647 if not(fileOk_flag):
650 if not(fileOk_flag):
648 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
651 for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles
649
652
650 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
653 if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces
651 tries = self.nTries
654 tries = self.nTries
652 else:
655 else:
653 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
656 tries = 1 #si no es la 1era vez entonces solo lo hace una vez
654
657
655 for nTries in range( tries ):
658 for nTries in range( tries ):
656 if firstTime_flag:
659 if firstTime_flag:
657 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
660 print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 )
658 time.sleep( self.delay )
661 time.sleep( self.delay )
659 else:
662 else:
660 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
663 print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext)
661
664
662 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
665 fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext )
663 if fullfilename:
666 if fullfilename:
664 if self.__verifyFile(fullfilename):
667 if self.__verifyFile(fullfilename):
665 fileOk_flag = True
668 fileOk_flag = True
666 break
669 break
667
670
668 if fileOk_flag:
671 if fileOk_flag:
669 break
672 break
670
673
671 firstTime_flag = False
674 firstTime_flag = False
672
675
673 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
676 print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename
674 self.set += 1
677 self.set += 1
675
678
676 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
679 if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta
677 self.set = 0
680 self.set = 0
678 self.doy += 1
681 self.doy += 1
679 self.foldercounter = 0
682 self.foldercounter = 0
680
683
681 if fileOk_flag:
684 if fileOk_flag:
682 self.fileSize = os.path.getsize( fullfilename )
685 self.fileSize = os.path.getsize( fullfilename )
683 self.filename = fullfilename
686 self.filename = fullfilename
684 self.flagIsNewFile = 1
687 self.flagIsNewFile = 1
685 if self.fp != None: self.fp.close()
688 if self.fp != None: self.fp.close()
686 self.fp = open(fullfilename, 'rb')
689 self.fp = open(fullfilename, 'rb')
687 self.flagNoMoreFiles = 0
690 self.flagNoMoreFiles = 0
688 print 'Setting the file: %s' % fullfilename
691 print 'Setting the file: %s' % fullfilename
689 else:
692 else:
690 self.fileSize = 0
693 self.fileSize = 0
691 self.filename = None
694 self.filename = None
692 self.flagIsNewFile = 0
695 self.flagIsNewFile = 0
693 self.fp = None
696 self.fp = None
694 self.flagNoMoreFiles = 1
697 self.flagNoMoreFiles = 1
695 print 'No more Files'
698 print 'No more Files'
696
699
697 return fileOk_flag
700 return fileOk_flag
698
701
699 def setNextFile(self):
702 def setNextFile(self):
700 if self.fp != None:
703 if self.fp != None:
701 self.fp.close()
704 self.fp.close()
702
705
703 if self.online:
706 if self.online:
704 newFile = self.__setNextFileOnline()
707 newFile = self.__setNextFileOnline()
705 else:
708 else:
706 newFile = self.__setNextFileOffline()
709 newFile = self.__setNextFileOffline()
707
710
708 if not(newFile):
711 if not(newFile):
709 return 0
712 return 0
710
713
711 self.__readFirstHeader()
714 self.__readFirstHeader()
712 self.nReadBlocks = 0
715 self.nReadBlocks = 0
713 return 1
716 return 1
714
717
715 def __waitNewBlock(self):
718 def __waitNewBlock(self):
716 """
719 """
717 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
720 Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma.
718
721
719 Si el modo de lectura es OffLine siempre retorn 0
722 Si el modo de lectura es OffLine siempre retorn 0
720 """
723 """
721 if not self.online:
724 if not self.online:
722 return 0
725 return 0
723
726
724 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
727 if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile):
725 return 0
728 return 0
726
729
727 currentPointer = self.fp.tell()
730 currentPointer = self.fp.tell()
728
731
729 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
732 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
730
733
731 for nTries in range( self.nTries ):
734 for nTries in range( self.nTries ):
732
735
733 self.fp.close()
736 self.fp.close()
734 self.fp = open( self.filename, 'rb' )
737 self.fp = open( self.filename, 'rb' )
735 self.fp.seek( currentPointer )
738 self.fp.seek( currentPointer )
736
739
737 self.fileSize = os.path.getsize( self.filename )
740 self.fileSize = os.path.getsize( self.filename )
738 currentSize = self.fileSize - currentPointer
741 currentSize = self.fileSize - currentPointer
739
742
740 if ( currentSize >= neededSize ):
743 if ( currentSize >= neededSize ):
741 self.basicHeaderObj.read(self.fp)
744 self.basicHeaderObj.read(self.fp)
742 return 1
745 return 1
743
746
744 if self.fileSize == self.fileSizeByHeader:
747 if self.fileSize == self.fileSizeByHeader:
745 # self.flagEoF = True
748 # self.flagEoF = True
746 return 0
749 return 0
747
750
748 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
751 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
749 time.sleep( self.delay )
752 time.sleep( self.delay )
750
753
751
754
752 return 0
755 return 0
753
756
754 def waitDataBlock(self,pointer_location):
757 def waitDataBlock(self,pointer_location):
755
758
756 currentPointer = pointer_location
759 currentPointer = pointer_location
757
760
758 neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize
761 neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize
759
762
760 for nTries in range( self.nTries ):
763 for nTries in range( self.nTries ):
761 self.fp.close()
764 self.fp.close()
762 self.fp = open( self.filename, 'rb' )
765 self.fp = open( self.filename, 'rb' )
763 self.fp.seek( currentPointer )
766 self.fp.seek( currentPointer )
764
767
765 self.fileSize = os.path.getsize( self.filename )
768 self.fileSize = os.path.getsize( self.filename )
766 currentSize = self.fileSize - currentPointer
769 currentSize = self.fileSize - currentPointer
767
770
768 if ( currentSize >= neededSize ):
771 if ( currentSize >= neededSize ):
769 return 1
772 return 1
770
773
771 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
774 print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1)
772 time.sleep( self.delay )
775 time.sleep( self.delay )
773
776
774 return 0
777 return 0
775
778
776 def __jumpToLastBlock(self):
779 def __jumpToLastBlock(self):
777
780
778 if not(self.__isFirstTimeOnline):
781 if not(self.__isFirstTimeOnline):
779 return
782 return
780
783
781 csize = self.fileSize - self.fp.tell()
784 csize = self.fileSize - self.fp.tell()
782 blocksize = self.processingHeaderObj.blockSize
785 blocksize = self.processingHeaderObj.blockSize
783
786
784 #salta el primer bloque de datos
787 #salta el primer bloque de datos
785 if csize > self.processingHeaderObj.blockSize:
788 if csize > self.processingHeaderObj.blockSize:
786 self.fp.seek(self.fp.tell() + blocksize)
789 self.fp.seek(self.fp.tell() + blocksize)
787 else:
790 else:
788 return
791 return
789
792
790 csize = self.fileSize - self.fp.tell()
793 csize = self.fileSize - self.fp.tell()
791 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
794 neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
792 while True:
795 while True:
793
796
794 if self.fp.tell()<self.fileSize:
797 if self.fp.tell()<self.fileSize:
795 self.fp.seek(self.fp.tell() + neededsize)
798 self.fp.seek(self.fp.tell() + neededsize)
796 else:
799 else:
797 self.fp.seek(self.fp.tell() - neededsize)
800 self.fp.seek(self.fp.tell() - neededsize)
798 break
801 break
799
802
800 # csize = self.fileSize - self.fp.tell()
803 # csize = self.fileSize - self.fp.tell()
801 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
804 # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize
802 # factor = int(csize/neededsize)
805 # factor = int(csize/neededsize)
803 # if factor > 0:
806 # if factor > 0:
804 # self.fp.seek(self.fp.tell() + factor*neededsize)
807 # self.fp.seek(self.fp.tell() + factor*neededsize)
805
808
806 self.flagIsNewFile = 0
809 self.flagIsNewFile = 0
807 self.__isFirstTimeOnline = 0
810 self.__isFirstTimeOnline = 0
808
811
809 def __setNewBlock(self):
812 def __setNewBlock(self):
810
813
811 if self.fp == None:
814 if self.fp == None:
812 return 0
815 return 0
813
816
814 if self.online:
817 if self.online:
815 self.__jumpToLastBlock()
818 self.__jumpToLastBlock()
816
819
817 if self.flagIsNewFile:
820 if self.flagIsNewFile:
818 return 1
821 return 1
819
822
820 self.lastUTTime = self.basicHeaderObj.utc
823 self.lastUTTime = self.basicHeaderObj.utc
821 currentSize = self.fileSize - self.fp.tell()
824 currentSize = self.fileSize - self.fp.tell()
822 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
825 neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize
823
826
824 if (currentSize >= neededSize):
827 if (currentSize >= neededSize):
825 self.basicHeaderObj.read(self.fp)
828 self.basicHeaderObj.read(self.fp)
826 return 1
829 return 1
827
830
828 if self.__waitNewBlock():
831 if self.__waitNewBlock():
829 return 1
832 return 1
830
833
831 if not(self.setNextFile()):
834 if not(self.setNextFile()):
832 return 0
835 return 0
833
836
834 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
837 deltaTime = self.basicHeaderObj.utc - self.lastUTTime #
835
838
836 self.flagTimeBlock = 0
839 self.flagTimeBlock = 0
837
840
838 if deltaTime > self.maxTimeStep:
841 if deltaTime > self.maxTimeStep:
839 self.flagTimeBlock = 1
842 self.flagTimeBlock = 1
840
843
841 return 1
844 return 1
842
845
843 def readNextBlock(self):
846 def readNextBlock(self):
844 if not(self.__setNewBlock()):
847 if not(self.__setNewBlock()):
845 return 0
848 return 0
846
849
847 if not(self.readBlock()):
850 if not(self.readBlock()):
848 return 0
851 return 0
849
852
850 return 1
853 return 1
851
854
852 def __readFirstHeader(self):
855 def __readFirstHeader(self):
853
856
854 self.basicHeaderObj.read(self.fp)
857 self.basicHeaderObj.read(self.fp)
855 self.systemHeaderObj.read(self.fp)
858 self.systemHeaderObj.read(self.fp)
856 self.radarControllerHeaderObj.read(self.fp)
859 self.radarControllerHeaderObj.read(self.fp)
857 self.processingHeaderObj.read(self.fp)
860 self.processingHeaderObj.read(self.fp)
858
861
859 self.firstHeaderSize = self.basicHeaderObj.size
862 self.firstHeaderSize = self.basicHeaderObj.size
860
863
861 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
864 datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
862 if datatype == 0:
865 if datatype == 0:
863 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
866 datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')])
864 elif datatype == 1:
867 elif datatype == 1:
865 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
868 datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')])
866 elif datatype == 2:
869 elif datatype == 2:
867 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
870 datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')])
868 elif datatype == 3:
871 elif datatype == 3:
869 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
872 datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')])
870 elif datatype == 4:
873 elif datatype == 4:
871 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
874 datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')])
872 elif datatype == 5:
875 elif datatype == 5:
873 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
876 datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')])
874 else:
877 else:
875 raise ValueError, 'Data type was not defined'
878 raise ValueError, 'Data type was not defined'
876
879
877 self.dtype = datatype_str
880 self.dtype = datatype_str
878 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
881 #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c
879 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
882 self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1)
880 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
883 # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels)
881 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
884 # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels)
882 self.getBlockDimension()
885 self.getBlockDimension()
883
886
884 def __verifyFile(self, filename, msgFlag=True):
887 def __verifyFile(self, filename, msgFlag=True):
885 msg = None
888 msg = None
886 try:
889 try:
887 fp = open(filename, 'rb')
890 fp = open(filename, 'rb')
888 currentPosition = fp.tell()
891 currentPosition = fp.tell()
889 except IOError:
892 except IOError:
890 traceback.print_exc()
893 traceback.print_exc()
891 if msgFlag:
894 if msgFlag:
892 print "The file %s can't be opened" % (filename)
895 print "The file %s can't be opened" % (filename)
893 return False
896 return False
894
897
895 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
898 neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize
896
899
897 if neededSize == 0:
900 if neededSize == 0:
898 basicHeaderObj = BasicHeader(LOCALTIME)
901 basicHeaderObj = BasicHeader(LOCALTIME)
899 systemHeaderObj = SystemHeader()
902 systemHeaderObj = SystemHeader()
900 radarControllerHeaderObj = RadarControllerHeader()
903 radarControllerHeaderObj = RadarControllerHeader()
901 processingHeaderObj = ProcessingHeader()
904 processingHeaderObj = ProcessingHeader()
902
905
903 try:
906 try:
904 if not( basicHeaderObj.read(fp) ): raise IOError
907 if not( basicHeaderObj.read(fp) ): raise IOError
905 if not( systemHeaderObj.read(fp) ): raise IOError
908 if not( systemHeaderObj.read(fp) ): raise IOError
906 if not( radarControllerHeaderObj.read(fp) ): raise IOError
909 if not( radarControllerHeaderObj.read(fp) ): raise IOError
907 if not( processingHeaderObj.read(fp) ): raise IOError
910 if not( processingHeaderObj.read(fp) ): raise IOError
908 # data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
911 # data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR))
909
912
910 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
913 neededSize = processingHeaderObj.blockSize + basicHeaderObj.size
911
914
912 except IOError:
915 except IOError:
913 traceback.print_exc()
916 traceback.print_exc()
914 if msgFlag:
917 if msgFlag:
915 print "\tThe file %s is empty or it hasn't enough data" % filename
918 print "\tThe file %s is empty or it hasn't enough data" % filename
916
919
917 fp.close()
920 fp.close()
918 return False
921 return False
919 else:
922 else:
920 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
923 msg = "\tSkipping the file %s due to it hasn't enough data" %filename
921
924
922 fp.close()
925 fp.close()
923 fileSize = os.path.getsize(filename)
926 fileSize = os.path.getsize(filename)
924 currentSize = fileSize - currentPosition
927 currentSize = fileSize - currentPosition
925 if currentSize < neededSize:
928 if currentSize < neededSize:
926 if msgFlag and (msg != None):
929 if msgFlag and (msg != None):
927 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
930 print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename
928 return False
931 return False
929
932
930 return True
933 return True
931
934
932 def setup(self,
935 def setup(self,
933 path=None,
936 path=None,
934 startDate=None,
937 startDate=None,
935 endDate=None,
938 endDate=None,
936 startTime=datetime.time(0,0,0),
939 startTime=datetime.time(0,0,0),
937 endTime=datetime.time(23,59,59),
940 endTime=datetime.time(23,59,59),
938 set=None,
941 set=None,
939 expLabel = "",
942 expLabel = "",
940 ext = None,
943 ext = None,
941 online = False,
944 online = False,
942 delay = 60,
945 delay = 60,
943 walk = True,
946 walk = True,
944 getblock = False,
947 getblock = False,
945 nTxs = 1):
948 nTxs = 1):
946
949
947 if path == None:
950 if path == None:
948 raise ValueError, "The path is not valid"
951 raise ValueError, "The path is not valid"
949
952
950 if ext == None:
953 if ext == None:
951 ext = self.ext
954 ext = self.ext
952
955
953 if online:
956 if online:
954 print "Searching files in online mode..."
957 print "Searching files in online mode..."
955
958
956 for nTries in range( self.nTries ):
959 for nTries in range( self.nTries ):
957 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
960 fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set)
958
961
959 if fullpath:
962 if fullpath:
960 break
963 break
961
964
962 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
965 print '\tWaiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1)
963 time.sleep( self.delay )
966 time.sleep( self.delay )
964
967
965 if not(fullpath):
968 if not(fullpath):
966 print "There 'isn't valied files in %s" % path
969 print "There 'isn't valied files in %s" % path
967 return None
970 return None
968
971
969 self.year = year
972 self.year = year
970 self.doy = doy
973 self.doy = doy
971 self.set = set - 1
974 self.set = set - 1
972 self.path = path
975 self.path = path
973 self.foldercounter = foldercounter
976 self.foldercounter = foldercounter
974 last_set = None
977 last_set = None
975
978
976 else:
979 else:
977 print "Searching files in offline mode ..."
980 print "Searching files in offline mode ..."
978 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
981 pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate,
979 startTime=startTime, endTime=endTime,
982 startTime=startTime, endTime=endTime,
980 set=set, expLabel=expLabel, ext=ext,
983 set=set, expLabel=expLabel, ext=ext,
981 walk=walk)
984 walk=walk)
982
985
983 if not(pathList):
986 if not(pathList):
984 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
987 print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path,
985 datetime.datetime.combine(startDate,startTime).ctime(),
988 datetime.datetime.combine(startDate,startTime).ctime(),
986 datetime.datetime.combine(endDate,endTime).ctime())
989 datetime.datetime.combine(endDate,endTime).ctime())
987
990
988 sys.exit(-1)
991 sys.exit(-1)
989
992
990
993
991 self.fileIndex = -1
994 self.fileIndex = -1
992 self.pathList = pathList
995 self.pathList = pathList
993 self.filenameList = filenameList
996 self.filenameList = filenameList
994 file_name = os.path.basename(filenameList[-1])
997 file_name = os.path.basename(filenameList[-1])
995 basename, ext = os.path.splitext(file_name)
998 basename, ext = os.path.splitext(file_name)
996 last_set = int(basename[-3:])
999 last_set = int(basename[-3:])
997
1000
998 self.online = online
1001 self.online = online
999 self.delay = delay
1002 self.delay = delay
1000 ext = ext.lower()
1003 ext = ext.lower()
1001 self.ext = ext
1004 self.ext = ext
1002 self.getByBlock = getblock
1005 self.getByBlock = getblock
1003 self.nTxs = int(nTxs)
1006 self.nTxs = int(nTxs)
1004
1007
1005 if not(self.setNextFile()):
1008 if not(self.setNextFile()):
1006 if (startDate!=None) and (endDate!=None):
1009 if (startDate!=None) and (endDate!=None):
1007 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
1010 print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime())
1008 elif startDate != None:
1011 elif startDate != None:
1009 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
1012 print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime())
1010 else:
1013 else:
1011 print "No files"
1014 print "No files"
1012
1015
1013 sys.exit(-1)
1016 sys.exit(-1)
1014
1017
1015 # self.updateDataHeader()
1018 # self.updateDataHeader()
1016 if last_set != None:
1019 if last_set != None:
1017 self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1020 self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock
1018 return
1021 return
1019
1022
1020 def getBasicHeader(self):
1023 def getBasicHeader(self):
1021
1024
1022 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1025 self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds
1023
1026
1024 self.dataOut.flagTimeBlock = self.flagTimeBlock
1027 self.dataOut.flagTimeBlock = self.flagTimeBlock
1025
1028
1026 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1029 self.dataOut.timeZone = self.basicHeaderObj.timeZone
1027
1030
1028 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1031 self.dataOut.dstFlag = self.basicHeaderObj.dstFlag
1029
1032
1030 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1033 self.dataOut.errorCount = self.basicHeaderObj.errorCount
1031
1034
1032 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1035 self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime
1033
1036
1034 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
1037 self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs
1035
1038
1036 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1039 self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs
1037
1040
1038
1041
1039 def getFirstHeader(self):
1042 def getFirstHeader(self):
1040
1043
1041 raise ValueError, "This method has not been implemented"
1044 raise ValueError, "This method has not been implemented"
1042
1045
1043 def getData(self):
1046 def getData(self):
1044
1047
1045 raise ValueError, "This method has not been implemented"
1048 raise ValueError, "This method has not been implemented"
1046
1049
1047 def hasNotDataInBuffer(self):
1050 def hasNotDataInBuffer(self):
1048
1051
1049 raise ValueError, "This method has not been implemented"
1052 raise ValueError, "This method has not been implemented"
1050
1053
1051 def readBlock(self):
1054 def readBlock(self):
1052
1055
1053 raise ValueError, "This method has not been implemented"
1056 raise ValueError, "This method has not been implemented"
1054
1057
1055 def isEndProcess(self):
1058 def isEndProcess(self):
1056
1059
1057 return self.flagNoMoreFiles
1060 return self.flagNoMoreFiles
1058
1061
1059 def printReadBlocks(self):
1062 def printReadBlocks(self):
1060
1063
1061 print "Number of read blocks per file %04d" %self.nReadBlocks
1064 print "Number of read blocks per file %04d" %self.nReadBlocks
1062
1065
1063 def printTotalBlocks(self):
1066 def printTotalBlocks(self):
1064
1067
1065 print "Number of read blocks %04d" %self.nTotalBlocks
1068 print "Number of read blocks %04d" %self.nTotalBlocks
1066
1069
1067 def printNumberOfBlock(self):
1070 def printNumberOfBlock(self):
1068
1071
1069 if self.flagIsNewBlock:
1072 if self.flagIsNewBlock:
1070 print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime())
1073 print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime())
1071 self.dataOut.blocknow = self.basicHeaderObj.dataBlock
1074 self.dataOut.blocknow = self.basicHeaderObj.dataBlock
1072
1075
1073 def printInfo(self):
1076 def printInfo(self):
1074
1077
1075 if self.__printInfo == False:
1078 if self.__printInfo == False:
1076 return
1079 return
1077
1080
1078 self.basicHeaderObj.printInfo()
1081 self.basicHeaderObj.printInfo()
1079 self.systemHeaderObj.printInfo()
1082 self.systemHeaderObj.printInfo()
1080 self.radarControllerHeaderObj.printInfo()
1083 self.radarControllerHeaderObj.printInfo()
1081 self.processingHeaderObj.printInfo()
1084 self.processingHeaderObj.printInfo()
1082
1085
1083 self.__printInfo = False
1086 self.__printInfo = False
1084
1087
1085
1088
1086 def run(self, **kwargs):
1089 def run(self, **kwargs):
1087
1090
1088 if not(self.isConfig):
1091 if not(self.isConfig):
1089
1092
1090 # self.dataOut = dataOut
1093 # self.dataOut = dataOut
1091 self.setup(**kwargs)
1094 self.setup(**kwargs)
1092 self.isConfig = True
1095 self.isConfig = True
1093
1096
1094 self.getData()
1097 self.getData()
1095
1098
1096 class JRODataWriter(JRODataIO):
1099 class JRODataWriter(JRODataIO):
1097
1100
1098 """
1101 """
1099 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1102 Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura
1100 de los datos siempre se realiza por bloques.
1103 de los datos siempre se realiza por bloques.
1101 """
1104 """
1102
1105
1103 blockIndex = 0
1106 blockIndex = 0
1104
1107
1105 path = None
1108 path = None
1106
1109
1107 setFile = None
1110 setFile = None
1108
1111
1109 profilesPerBlock = None
1112 profilesPerBlock = None
1110
1113
1111 blocksPerFile = None
1114 blocksPerFile = None
1112
1115
1113 nWriteBlocks = 0
1116 nWriteBlocks = 0
1114
1117
1115 def __init__(self, dataOut=None):
1118 def __init__(self, dataOut=None):
1116 raise ValueError, "Not implemented"
1119 raise ValueError, "Not implemented"
1117
1120
1118
1121
1119 def hasAllDataInBuffer(self):
1122 def hasAllDataInBuffer(self):
1120 raise ValueError, "Not implemented"
1123 raise ValueError, "Not implemented"
1121
1124
1122
1125
1123 def setBlockDimension(self):
1126 def setBlockDimension(self):
1124 raise ValueError, "Not implemented"
1127 raise ValueError, "Not implemented"
1125
1128
1126
1129
1127 def writeBlock(self):
1130 def writeBlock(self):
1128 raise ValueError, "No implemented"
1131 raise ValueError, "No implemented"
1129
1132
1130
1133
1131 def putData(self):
1134 def putData(self):
1132 raise ValueError, "No implemented"
1135 raise ValueError, "No implemented"
1133
1136
1134
1137
1135 def setBasicHeader(self):
1138 def setBasicHeader(self):
1136
1139
1137 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1140 self.basicHeaderObj.size = self.basicHeaderSize #bytes
1138 self.basicHeaderObj.version = self.versionFile
1141 self.basicHeaderObj.version = self.versionFile
1139 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1142 self.basicHeaderObj.dataBlock = self.nTotalBlocks
1140
1143
1141 utc = numpy.floor(self.dataOut.utctime)
1144 utc = numpy.floor(self.dataOut.utctime)
1142 milisecond = (self.dataOut.utctime - utc)* 1000.0
1145 milisecond = (self.dataOut.utctime - utc)* 1000.0
1143
1146
1144 self.basicHeaderObj.utc = utc
1147 self.basicHeaderObj.utc = utc
1145 self.basicHeaderObj.miliSecond = milisecond
1148 self.basicHeaderObj.miliSecond = milisecond
1146 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1149 self.basicHeaderObj.timeZone = self.dataOut.timeZone
1147 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1150 self.basicHeaderObj.dstFlag = self.dataOut.dstFlag
1148 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1151 self.basicHeaderObj.errorCount = self.dataOut.errorCount
1149
1152
1150 def setFirstHeader(self):
1153 def setFirstHeader(self):
1151 """
1154 """
1152 Obtiene una copia del First Header
1155 Obtiene una copia del First Header
1153
1156
1154 Affected:
1157 Affected:
1155
1158
1156 self.basicHeaderObj
1159 self.basicHeaderObj
1157 self.systemHeaderObj
1160 self.systemHeaderObj
1158 self.radarControllerHeaderObj
1161 self.radarControllerHeaderObj
1159 self.processingHeaderObj self.
1162 self.processingHeaderObj self.
1160
1163
1161 Return:
1164 Return:
1162 None
1165 None
1163 """
1166 """
1164
1167
1165 raise ValueError, "No implemented"
1168 raise ValueError, "No implemented"
1166
1169
1167 def __writeFirstHeader(self):
1170 def __writeFirstHeader(self):
1168 """
1171 """
1169 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1172 Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader)
1170
1173
1171 Affected:
1174 Affected:
1172 __dataType
1175 __dataType
1173
1176
1174 Return:
1177 Return:
1175 None
1178 None
1176 """
1179 """
1177
1180
1178 # CALCULAR PARAMETROS
1181 # CALCULAR PARAMETROS
1179
1182
1180 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1183 sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size
1181 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1184 self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader
1182
1185
1183 self.basicHeaderObj.write(self.fp)
1186 self.basicHeaderObj.write(self.fp)
1184 self.systemHeaderObj.write(self.fp)
1187 self.systemHeaderObj.write(self.fp)
1185 self.radarControllerHeaderObj.write(self.fp)
1188 self.radarControllerHeaderObj.write(self.fp)
1186 self.processingHeaderObj.write(self.fp)
1189 self.processingHeaderObj.write(self.fp)
1187
1190
1188 self.dtype = self.dataOut.dtype
1191 self.dtype = self.dataOut.dtype
1189
1192
1190 def __setNewBlock(self):
1193 def __setNewBlock(self):
1191 """
1194 """
1192 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1195 Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header
1193
1196
1194 Return:
1197 Return:
1195 0 : si no pudo escribir nada
1198 0 : si no pudo escribir nada
1196 1 : Si escribio el Basic el First Header
1199 1 : Si escribio el Basic el First Header
1197 """
1200 """
1198 if self.fp == None:
1201 if self.fp == None:
1199 self.setNextFile()
1202 self.setNextFile()
1200
1203
1201 if self.flagIsNewFile:
1204 if self.flagIsNewFile:
1202 return 1
1205 return 1
1203
1206
1204 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1207 if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile:
1205 self.basicHeaderObj.write(self.fp)
1208 self.basicHeaderObj.write(self.fp)
1206 return 1
1209 return 1
1207
1210
1208 if not( self.setNextFile() ):
1211 if not( self.setNextFile() ):
1209 return 0
1212 return 0
1210
1213
1211 return 1
1214 return 1
1212
1215
1213
1216
1214 def writeNextBlock(self):
1217 def writeNextBlock(self):
1215 """
1218 """
1216 Selecciona el bloque siguiente de datos y los escribe en un file
1219 Selecciona el bloque siguiente de datos y los escribe en un file
1217
1220
1218 Return:
1221 Return:
1219 0 : Si no hizo pudo escribir el bloque de datos
1222 0 : Si no hizo pudo escribir el bloque de datos
1220 1 : Si no pudo escribir el bloque de datos
1223 1 : Si no pudo escribir el bloque de datos
1221 """
1224 """
1222 if not( self.__setNewBlock() ):
1225 if not( self.__setNewBlock() ):
1223 return 0
1226 return 0
1224
1227
1225 self.writeBlock()
1228 self.writeBlock()
1226
1229
1227 return 1
1230 return 1
1228
1231
1229 def setNextFile(self):
1232 def setNextFile(self):
1230 """
1233 """
1231 Determina el siguiente file que sera escrito
1234 Determina el siguiente file que sera escrito
1232
1235
1233 Affected:
1236 Affected:
1234 self.filename
1237 self.filename
1235 self.subfolder
1238 self.subfolder
1236 self.fp
1239 self.fp
1237 self.setFile
1240 self.setFile
1238 self.flagIsNewFile
1241 self.flagIsNewFile
1239
1242
1240 Return:
1243 Return:
1241 0 : Si el archivo no puede ser escrito
1244 0 : Si el archivo no puede ser escrito
1242 1 : Si el archivo esta listo para ser escrito
1245 1 : Si el archivo esta listo para ser escrito
1243 """
1246 """
1244 ext = self.ext
1247 ext = self.ext
1245 path = self.path
1248 path = self.path
1246
1249
1247 if self.fp != None:
1250 if self.fp != None:
1248 self.fp.close()
1251 self.fp.close()
1249
1252
1250 timeTuple = time.localtime( self.dataOut.utctime)
1253 timeTuple = time.localtime( self.dataOut.utctime)
1251 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1254 subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday)
1252
1255
1253 fullpath = os.path.join( path, subfolder )
1256 fullpath = os.path.join( path, subfolder )
1254 if not( os.path.exists(fullpath) ):
1257 if not( os.path.exists(fullpath) ):
1255 os.mkdir(fullpath)
1258 os.mkdir(fullpath)
1256 self.setFile = -1 #inicializo mi contador de seteo
1259 self.setFile = -1 #inicializo mi contador de seteo
1257 else:
1260 else:
1258 filesList = os.listdir( fullpath )
1261 filesList = os.listdir( fullpath )
1259 if len( filesList ) > 0:
1262 if len( filesList ) > 0:
1260 filesList = sorted( filesList, key=str.lower )
1263 filesList = sorted( filesList, key=str.lower )
1261 filen = filesList[-1]
1264 filen = filesList[-1]
1262 # el filename debera tener el siguiente formato
1265 # el filename debera tener el siguiente formato
1263 # 0 1234 567 89A BCDE (hex)
1266 # 0 1234 567 89A BCDE (hex)
1264 # x YYYY DDD SSS .ext
1267 # x YYYY DDD SSS .ext
1265 if isNumber( filen[8:11] ):
1268 if isNumber( filen[8:11] ):
1266 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1269 self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file
1267 else:
1270 else:
1268 self.setFile = -1
1271 self.setFile = -1
1269 else:
1272 else:
1270 self.setFile = -1 #inicializo mi contador de seteo
1273 self.setFile = -1 #inicializo mi contador de seteo
1271
1274
1272 setFile = self.setFile
1275 setFile = self.setFile
1273 setFile += 1
1276 setFile += 1
1274
1277
1275 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1278 file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar,
1276 timeTuple.tm_year,
1279 timeTuple.tm_year,
1277 timeTuple.tm_yday,
1280 timeTuple.tm_yday,
1278 setFile,
1281 setFile,
1279 ext )
1282 ext )
1280
1283
1281 filename = os.path.join( path, subfolder, file )
1284 filename = os.path.join( path, subfolder, file )
1282
1285
1283 fp = open( filename,'wb' )
1286 fp = open( filename,'wb' )
1284
1287
1285 self.blockIndex = 0
1288 self.blockIndex = 0
1286
1289
1287 #guardando atributos
1290 #guardando atributos
1288 self.filename = filename
1291 self.filename = filename
1289 self.subfolder = subfolder
1292 self.subfolder = subfolder
1290 self.fp = fp
1293 self.fp = fp
1291 self.setFile = setFile
1294 self.setFile = setFile
1292 self.flagIsNewFile = 1
1295 self.flagIsNewFile = 1
1293
1296
1294 self.setFirstHeader()
1297 self.setFirstHeader()
1295
1298
1296 print 'Writing the file: %s'%self.filename
1299 print 'Writing the file: %s'%self.filename
1297
1300
1298 self.__writeFirstHeader()
1301 self.__writeFirstHeader()
1299
1302
1300 return 1
1303 return 1
1301
1304
1302 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=0, ext=None):
1305 def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=0, ext=None):
1303 """
1306 """
1304 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1307 Setea el tipo de formato en la cual sera guardada la data y escribe el First Header
1305
1308
1306 Inputs:
1309 Inputs:
1307 path : el path destino en el cual se escribiran los files a crear
1310 path : el path destino en el cual se escribiran los files a crear
1308 format : formato en el cual sera salvado un file
1311 format : formato en el cual sera salvado un file
1309 set : el setebo del file
1312 set : el setebo del file
1310
1313
1311 Return:
1314 Return:
1312 0 : Si no realizo un buen seteo
1315 0 : Si no realizo un buen seteo
1313 1 : Si realizo un buen seteo
1316 1 : Si realizo un buen seteo
1314 """
1317 """
1315
1318
1316 if ext == None:
1319 if ext == None:
1317 ext = self.ext
1320 ext = self.ext
1318
1321
1319 ext = ext.lower()
1322 ext = ext.lower()
1320
1323
1321 self.ext = ext
1324 self.ext = ext
1322
1325
1323 self.path = path
1326 self.path = path
1324
1327
1325 self.setFile = set - 1
1328 self.setFile = set - 1
1326
1329
1327 self.blocksPerFile = blocksPerFile
1330 self.blocksPerFile = blocksPerFile
1328
1331
1329 self.profilesPerBlock = profilesPerBlock
1332 self.profilesPerBlock = profilesPerBlock
1330
1333
1331 self.dataOut = dataOut
1334 self.dataOut = dataOut
1332
1335
1333 if not(self.setNextFile()):
1336 if not(self.setNextFile()):
1334 print "There isn't a next file"
1337 print "There isn't a next file"
1335 return 0
1338 return 0
1336
1339
1337 self.setBlockDimension()
1340 self.setBlockDimension()
1338
1341
1339 return 1
1342 return 1
1340
1343
1341 def run(self, dataOut, **kwargs):
1344 def run(self, dataOut, **kwargs):
1342
1345
1343 if not(self.isConfig):
1346 if not(self.isConfig):
1344
1347
1345 self.setup(dataOut, **kwargs)
1348 self.setup(dataOut, **kwargs)
1346 self.isConfig = True
1349 self.isConfig = True
1347
1350
1348 self.putData()
1351 self.putData()
1349
1352
@@ -1,6 +1,9
1 from jroIO_voltage import *
1 from jroIO_voltage import *
2 from jroIO_spectra import *
2 from jroIO_spectra import *
3 from jroIO_heispectra import *
3 from jroIO_heispectra import *
4 from jroIO_amisr import *
4 from jroIO_amisr import *
5 from jroIO_HDF5 import *
5 from jroIO_HDF5 import *
6 from jroIO_hf import * No newline at end of file
6 try:
7 from jroIO_hf import *
8 except:
9 pass No newline at end of file
@@ -1,162 +1,128
1 import os, sys
1 import os, sys
2 #import timeit
2 #import timeit
3 import datetime
3 import datetime
4
4
5 path = os.path.split(os.getcwd())[0]
5 path = os.path.split(os.getcwd())[0]
6 sys.path.append(path)
6 sys.path.append(path)
7
7
8 from controller import *
8 from controller import *
9
9
10 desc = "150 km Jicamarca January 2015"
10 desc = "150 km Jicamarca January 2015"
11 filename = "150km_jicamarca.xml"
11 filename = "150km_jicamarca.xml"
12
12
13 controllerObj = Project()
13 controllerObj = Project()
14
14
15 controllerObj.setup(id = '191', name='test01', description=desc)
15 controllerObj.setup(id = '191', name='test01', description=desc)
16
16
17 path = '/Volumes/DATA/RAW_EXP/2015_ISR'
17 path = './'
18
18
19 figpath = '/Users/miguel/tmp'
19 figpath = '/Users/miguel/tmp'
20
20
21 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
21 readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader',
22 path=path,
22 path=path,
23 startDate='2015/01/14',
23 startDate='2015/01/14',
24 endDate='2015/01/14',
24 endDate='2015/01/14',
25 startTime='08:30:00',
25 startTime='08:30:00',
26 endTime='09:30:59',
26 endTime='09:30:59',
27 online=1,
27 online=1,
28 delay=10,
28 delay=10,
29 walk=1,
29 walk=1,
30 nTxs = 4)
30 nTxs = 4)
31
31
32 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
32 opObj11 = readUnitConfObj.addOperation(name='printNumberOfBlock')
33
33
34 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
34 procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', inputId=readUnitConfObj.getId())
35
36 # opObj10 = procUnitConfObj0.addOperation(name='selectHeightsByIndex')
37 # opObj10.addParameter(name='minIndex', value='0', format='int')
38 # opObj10.addParameter(name='maxIndex', value='131', format='int')
39
35
40 opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other')
36 opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other')
41 # profileIndex = '20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99'
42 # opObj11.addParameter(name='profileList', value=profileIndex, format='intlist')
43 # opObj11.addParameter(name='rangeList', value='((1, 80), (341, 420), (761, 840), (1181,1260))', format='multiList')
44 opObj11.addParameter(name='rangeList', value='(1,80),(341,420),(681,760),(1021,1100)', format='multiList')
37 opObj11.addParameter(name='rangeList', value='(1,80),(341,420),(681,760),(1021,1100)', format='multiList')
45
38
46 # opObj11 = procUnitConfObjISR.addOperation(name='ProfileConcat', optype='other')
47 # opObj11.addParameter(name='m', value='5', format='int')
48
49 # opObj11 = procUnitConfObj0.addOperation(name='Reshaper', optype='other') #Esta Operacion opera sobre bloques y reemplaza el ProfileConcat que opera sobre perfiles
50 # opObj11.addParameter(name='shape', value='8,84,140', format='intlist') # shape = (nchannels, nprofiles, nhieghts)
51 #
52 #
53 # opObj11 = procUnitConfObj0.addOperation(name='ProfileSelector', optype='other')
54 # # profileIndex = '20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99'
55 # # opObj11.addParameter(name='profileList', value=profileIndex, format='intlist')
56 # opObj11.addParameter(name='profileRangeList', value='1,80', format='intlist')
57
58
59 # opObj11 = procUnitConfObj0.addOperation(name='filterByHeights')
60 # opObj11.addParameter(name='window', value='1', format='int')
61 # opObj11.addParameter(name='axis', value='2', format='int')
62
39
63 cod7barker="1,1,1,-1,-1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,1,-1,1"
40 cod7barker="1,1,1,-1,-1,1,-1,1,1,1,-1,-1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,1,-1,1"
64 # 1,1,1,-1,-1,1,-1
41
65 #-1,-1,-1,1,1,-1,1
66 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
42 opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
67 opObj11.addParameter(name='code', value=cod7barker, format='floatlist')
43 opObj11.addParameter(name='code', value=cod7barker, format='floatlist')
68 opObj11.addParameter(name='nCode', value='4', format='int')
44 opObj11.addParameter(name='nCode', value='4', format='int')
69 opObj11.addParameter(name='nBaud', value='7', format='int')
45 opObj11.addParameter(name='nBaud', value='7', format='int')
70 #
46 #
71 opObj11 = procUnitConfObj0.addOperation(name='deFlip')
47 opObj11 = procUnitConfObj0.addOperation(name='deFlip')
72 opObj11.addParameter(name='channelList', value='1,3,5,7', format='intlist')
48 opObj11.addParameter(name='channelList', value='1,3,5,7', format='intlist')
73
49
74 # cod7barker="1,1,1,-1,-1,1,-1"
75 # opObj11 = procUnitConfObj0.addOperation(name='Decoder', optype='other')
76 # opObj11.addParameter(name='code', value=cod7barker, format='intlist')
77 # opObj11.addParameter(name='nCode', value='1', format='int')
78 # opObj11.addParameter(name='nBaud', value='7', format='int')
79
80 # opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='other')
81 # opObj11.addParameter(name='id', value='10', format='int')
82 # opObj11.addParameter(name='wintitle', value='Voltage', format='str')
83
84 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId())
50 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=procUnitConfObj0.getId())
85 procUnitConfObj1.addParameter(name='nFFTPoints', value='80', format='int')
51 procUnitConfObj1.addParameter(name='nFFTPoints', value='80', format='int')
86 procUnitConfObj1.addParameter(name='nProfiles', value='80', format='int')
52 procUnitConfObj1.addParameter(name='nProfiles', value='80', format='int')
87 procUnitConfObj1.addParameter(name='pairsList', value='(1,0),(3,2),(5,4),(7,6)', format='pairsList')
53 procUnitConfObj1.addParameter(name='pairsList', value='(1,0),(3,2),(5,4),(7,6)', format='pairsList')
88 #
54 #
89 # #
55 # #
90 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
56 opObj11 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
91 opObj11.addParameter(name='timeInterval', value='60', format='float')
57 opObj11.addParameter(name='timeInterval', value='60', format='float')
92 #
58 #
93 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
59 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
94 # opObj11.addParameter(name='id', value='2004', format='int')
60 # opObj11.addParameter(name='id', value='2004', format='int')
95 # opObj11.addParameter(name='wintitle', value='150km_Jicamarca_ShortPulse', format='str')
61 # opObj11.addParameter(name='wintitle', value='150km_Jicamarca_ShortPulse', format='str')
96 # #opObj11.addParameter(name='channelList', value='0,1,2,3,45', format='intlist')
62 # #opObj11.addParameter(name='channelList', value='0,1,2,3,45', format='intlist')
97 # opObj11.addParameter(name='zmin', value='15', format='int')
63 # opObj11.addParameter(name='zmin', value='15', format='int')
98 # opObj11.addParameter(name='zmax', value='45', format='int')
64 # opObj11.addParameter(name='zmax', value='45', format='int')
99 # opObj11.addParameter(name='figpath', value=figpath, format='str')
65 # opObj11.addParameter(name='figpath', value=figpath, format='str')
100 # opObj11.addParameter(name='exp_code', value='13', format='int')
66 # opObj11.addParameter(name='exp_code', value='13', format='int')
101
67
102 #
68 #
103 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
69 opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
104 opObj11.addParameter(name='id', value='2006', format='int')
70 opObj11.addParameter(name='id', value='2006', format='int')
105 opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
71 opObj11.addParameter(name='wintitle', value='CrossSpectraPlot_ShortPulse', format='str')
106 opObj11.addParameter(name='ymin', value='0', format='int')
72 opObj11.addParameter(name='ymin', value='0', format='int')
107 opObj11.addParameter(name='ymax', value='105', format='int')
73 opObj11.addParameter(name='ymax', value='105', format='int')
108 opObj11.addParameter(name='phase_cmap', value='jet', format='str')
74 opObj11.addParameter(name='phase_cmap', value='jet', format='str')
109 opObj11.addParameter(name='zmin', value='15', format='int')
75 opObj11.addParameter(name='zmin', value='15', format='int')
110 opObj11.addParameter(name='zmax', value='45', format='int')
76 opObj11.addParameter(name='zmax', value='45', format='int')
111 opObj11.addParameter(name='figpath', value=figpath, format='str')
77 opObj11.addParameter(name='figpath', value=figpath, format='str')
112 opObj11.addParameter(name='exp_code', value='13', format='int')
78 opObj11.addParameter(name='exp_code', value='13', format='int')
113 #
79 #
114 #
80 #
115 opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
81 opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
116 opObj11.addParameter(name='id', value='102', format='int')
82 opObj11.addParameter(name='id', value='102', format='int')
117 opObj11.addParameter(name='wintitle', value='Coherence', format='str')
83 opObj11.addParameter(name='wintitle', value='Coherence', format='str')
118 opObj11.addParameter(name='phase_cmap', value='jet', format='str')
84 opObj11.addParameter(name='phase_cmap', value='jet', format='str')
119 opObj11.addParameter(name='xmin', value='8.5', format='float')
85 opObj11.addParameter(name='xmin', value='8.5', format='float')
120 opObj11.addParameter(name='xmax', value='9.5', format='float')
86 opObj11.addParameter(name='xmax', value='9.5', format='float')
121 opObj11.addParameter(name='figpath', value=figpath, format='str')
87 opObj11.addParameter(name='figpath', value=figpath, format='str')
122 opObj11.addParameter(name='save', value=1, format='bool')
88 opObj11.addParameter(name='save', value=1, format='bool')
123 opObj11.addParameter(name='pairsList', value='(1,0),(3,2)', format='pairsList')
89 opObj11.addParameter(name='pairsList', value='(1,0),(3,2)', format='pairsList')
124
90
125 # opObj11.addParameter(name='wr_period', value='2', format='int')
91 # opObj11.addParameter(name='wr_period', value='2', format='int')
126
92
127 # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
93 # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
128 # opObj11.addParameter(name='id', value='103', format='int')
94 # opObj11.addParameter(name='id', value='103', format='int')
129 # opObj11.addParameter(name='wintitle', value='Coherence', format='str')
95 # opObj11.addParameter(name='wintitle', value='Coherence', format='str')
130 # opObj11.addParameter(name='phase_cmap', value='jet', format='str')
96 # opObj11.addParameter(name='phase_cmap', value='jet', format='str')
131 # opObj11.addParameter(name='xmin', value='8.5', format='float')
97 # opObj11.addParameter(name='xmin', value='8.5', format='float')
132 # opObj11.addParameter(name='xmax', value='9.5', format='float')
98 # opObj11.addParameter(name='xmax', value='9.5', format='float')
133 # opObj11.addParameter(name='figpath', value=figpath, format='str')
99 # opObj11.addParameter(name='figpath', value=figpath, format='str')
134 # opObj11.addParameter(name='save', value=1, format='bool')
100 # opObj11.addParameter(name='save', value=1, format='bool')
135 # opObj11.addParameter(name='pairsList', value='(5,4),(7,6)', format='pairsList')
101 # opObj11.addParameter(name='pairsList', value='(5,4),(7,6)', format='pairsList')
136
102
137 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
103 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
138 # opObj11.addParameter(name='id', value='3005', format='int')
104 # opObj11.addParameter(name='id', value='3005', format='int')
139 # opObj11.addParameter(name='wintitle', value='150km_Jicamarca_ShortPulse', format='str')
105 # opObj11.addParameter(name='wintitle', value='150km_Jicamarca_ShortPulse', format='str')
140 # # opObj11.addParameter(name='xmin', value='20.5', format='float')
106 # # opObj11.addParameter(name='xmin', value='20.5', format='float')
141 # # opObj11.addParameter(name='xmax', value='24', format='float')
107 # # opObj11.addParameter(name='xmax', value='24', format='float')
142 # opObj11.addParameter(name='zmin', value='15', format='int')
108 # opObj11.addParameter(name='zmin', value='15', format='int')
143 # opObj11.addParameter(name='zmax', value='45', format='int')
109 # opObj11.addParameter(name='zmax', value='45', format='int')
144 #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
110 #opObj11.addParameter(name='channelList', value='0,1,2,3', format='intlist')
145 #opObj11.addParameter(name='channelList', value='0,1,2,3,4,5,6,7', format='intlist')
111 #opObj11.addParameter(name='channelList', value='0,1,2,3,4,5,6,7', format='intlist')
146 # opObj11.addParameter(name='showprofile', value='0', format='int')
112 # opObj11.addParameter(name='showprofile', value='0', format='int')
147 # opObj11.addParameter(name='figpath', value=figpath, format='str')
113 # opObj11.addParameter(name='figpath', value=figpath, format='str')
148 # opObj11.addParameter(name='exp_code', value='13', format='int')
114 # opObj11.addParameter(name='exp_code', value='13', format='int')
149
115
150
116
151
117
152 print "Escribiendo el archivo XML"
118 print "Escribiendo el archivo XML"
153 controllerObj.writeXml(filename)
119 controllerObj.writeXml(filename)
154 print "Leyendo el archivo XML"
120 print "Leyendo el archivo XML"
155 controllerObj.readXml(filename)
121 controllerObj.readXml(filename)
156
122
157 controllerObj.createObjects()
123 controllerObj.createObjects()
158 controllerObj.connectObjects()
124 controllerObj.connectObjects()
159
125
160 #timeit.timeit('controllerObj.run()', number=2)
126 #timeit.timeit('controllerObj.run()', number=2)
161
127
162 controllerObj.run() No newline at end of file
128 controllerObj.run()
@@ -1,150 +1,151
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 if __name__ == '__main__':
8 if __name__ == '__main__':
9
9
10 desc = "Segundo Test"
10 desc = "Segundo Test"
11 filename = "schain.xml"
11 filename = "schain.xml"
12
12
13 controllerObj = Project()
13 controllerObj = Project()
14
14
15 controllerObj.setup(id = '191', name='test01', description=desc)
15 controllerObj.setup(id = '191', name='test01', description=desc)
16
16
17 readUnitConfObj = controllerObj.addReadUnit(datatype='Spectra',
17 readUnitConfObj = controllerObj.addReadUnit(datatype='SpectraReader',
18 path='/remote/datos/IMAGING/IMAGING2',
18 path='/remote/puma/JULIA_EW_IMAGING/JULIA_EW/D2015',
19 startDate='2012/12/18',
19 startDate='2015/01/18',
20 endDate='2012/12/22',
20 endDate='2015/01/22',
21 startTime='00:00:00',
21 startTime='00:00:00',
22 endTime='23:59:59',
22 endTime='23:59:59',
23 online=0,
23 online=0,
24 walk=1,
24 walk=1,
25 expLabel='')
25 expLabel='ESF_EW')
26
26
27 # opObj00 = readUnitConfObj.addOperation(name='printInfo')
27 opObj00 = readUnitConfObj.addOperation(name='printInfo')
28 opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock')
28
29
29 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=readUnitConfObj.getId())
30 procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', inputId=readUnitConfObj.getId())
30
31
31 # opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
32 # opObj10 = procUnitConfObj0.addOperation(name='selectChannels')
32 # opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
33 # opObj10.addParameter(name='channelList', value='3,4,5', format='intlist')
33
34
34 # opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
35 # opObj10 = procUnitConfObj0.addOperation(name='selectHeights')
35 # opObj10.addParameter(name='minHei', value='90', format='float')
36 # opObj10.addParameter(name='minHei', value='90', format='float')
36 # opObj10.addParameter(name='maxHei', value='180', format='float')
37 # opObj10.addParameter(name='maxHei', value='180', format='float')
37
38
38 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
39 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
39 # opObj12.addParameter(name='n', value='10', format='int')
40 # opObj12.addParameter(name='n', value='10', format='int')
40
41
41 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
42 # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId())
42 # procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int')
43 # procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int')
43 # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='')
44 # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='')
44
45
45
46
46 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
47 opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
47 # opObj11.addParameter(name='idfigure', value='1', format='int')
48 opObj11.addParameter(name='id', value='1', format='int')
48 # opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
49 opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str')
49 ## opObj11.addParameter(name='zmin', value='30', format='int')
50 # opObj11.addParameter(name='zmin', value='30', format='int')
50 ## opObj11.addParameter(name='zmax', value='70', format='int')
51 # opObj11.addParameter(name='zmax', value='70', format='int')
51 # opObj11.addParameter(name='showprofile', value='1', format='int')
52 opObj11.addParameter(name='showprofile', value='1', format='int')
52 # opObj11.addParameter(name='save', value='1', format='int')
53 # opObj11.addParameter(name='save', value='1', format='int')
53 # opObj11.addParameter(name='figpath', value='/home/roj-idl71/tmp/graphs')
54 # opObj11.addParameter(name='figpath', value='/home/roj-idl71/tmp/graphs')
54 ##
55 ##
55 # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
56 # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other')
56 # opObj11.addParameter(name='idfigure', value='2', format='int')
57 # opObj11.addParameter(name='idfigure', value='2', format='int')
57 # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str')
58 # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str')
58 ## opObj11.addParameter(name='zmin', value='30', format='int')
59 ## opObj11.addParameter(name='zmin', value='30', format='int')
59 ## opObj11.addParameter(name='zmax', value='70', format='int')
60 ## opObj11.addParameter(name='zmax', value='70', format='int')
60 # opObj11.addParameter(name='save', value='1', format='int')
61 # opObj11.addParameter(name='save', value='1', format='int')
61 # opObj11.addParameter(name='figpath', value='/home/roj-idl71/tmp/graphs')
62 # opObj11.addParameter(name='figpath', value='/home/roj-idl71/tmp/graphs')
62
63
63 #
64
64 # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
65 # opObj11 = procUnitConfObj1.addOperation(name='CoherenceMap', optype='other')
65 # opObj11.addParameter(name='idfigure', value='3', format='int')
66 # opObj11.addParameter(name='idfigure', value='3', format='int')
66 # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str')
67 # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str')
67 # opObj11.addParameter(name='zmin', value='40', format='int')
68 # opObj11.addParameter(name='zmin', value='40', format='int')
68 # opObj11.addParameter(name='zmax', value='90', format='int')
69 # opObj11.addParameter(name='zmax', value='90', format='int')
69
70
70 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId())
71 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId())
71 #
72 #
72 # opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other')
73 # opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='other')
73 # opObj12.addParameter(name='n', value='2', format='int')
74 # opObj12.addParameter(name='n', value='2', format='int')
74 # opObj12.addParameter(name='overlapping', value='1', format='int')
75 # opObj12.addParameter(name='overlapping', value='1', format='int')
75 #
76 #
76 # procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId())
77 # procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId())
77 # procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int')
78 # procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int')
78 #
79 #
79 # opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other')
80 # opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='other')
80 # opObj11.addParameter(name='idfigure', value='2', format='int')
81 # opObj11.addParameter(name='idfigure', value='2', format='int')
81 # opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str')
82 # opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str')
82 # opObj11.addParameter(name='zmin', value='40', format='int')
83 # opObj11.addParameter(name='zmin', value='40', format='int')
83 # opObj11.addParameter(name='zmax', value='90', format='int')
84 # opObj11.addParameter(name='zmax', value='90', format='int')
84 # opObj11.addParameter(name='showprofile', value='1', format='int')
85 # opObj11.addParameter(name='showprofile', value='1', format='int')
85
86
86 # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
87 opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other')
87 # opObj11.addParameter(name='idfigure', value='10', format='int')
88 opObj11.addParameter(name='id', value='10', format='int')
88 # opObj11.addParameter(name='wintitle', value='RTI', format='str')
89 opObj11.addParameter(name='wintitle', value='RTI', format='str')
89 ## opObj11.addParameter(name='xmin', value='21', format='float')
90 # opObj11.addParameter(name='xmin', value='0', format='float')
90 ## opObj11.addParameter(name='xmax', value='22', format='float')
91 # opObj11.addParameter(name='xmax', value='10', format='float')
91 # opObj11.addParameter(name='zmin', value='40', format='int')
92 # opObj11.addParameter(name='zmin', value='40', format='int')
92 # opObj11.addParameter(name='zmax', value='90', format='int')
93 # opObj11.addParameter(name='zmax', value='90', format='int')
93 # opObj11.addParameter(name='showprofile', value='1', format='int')
94 opObj11.addParameter(name='showprofile', value='1', format='int')
94 # opObj11.addParameter(name='timerange', value=str(60), format='int')
95 opObj11.addParameter(name='timerange', value=str(2*60*60), format='int')
95
96
96 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
97 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
97 # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist')
98 # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist')
98 #
99 #
99 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
100 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
100 # opObj12.addParameter(name='n', value='2', format='int')
101 # opObj12.addParameter(name='n', value='2', format='int')
101 #
102 #
102 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
103 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
103 # opObj11.addParameter(name='idfigure', value='2', format='int')
104 # opObj11.addParameter(name='idfigure', value='2', format='int')
104 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
105 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
105 # opObj11.addParameter(name='zmin', value='70', format='int')
106 # opObj11.addParameter(name='zmin', value='70', format='int')
106 # opObj11.addParameter(name='zmax', value='90', format='int')
107 # opObj11.addParameter(name='zmax', value='90', format='int')
107 #
108 #
108 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
109 # opObj10 = procUnitConfObj1.addOperation(name='selectChannels')
109 # opObj10.addParameter(name='channelList', value='2,6', format='intlist')
110 # opObj10.addParameter(name='channelList', value='2,6', format='intlist')
110 #
111 #
111 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
112 # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other')
112 # opObj12.addParameter(name='n', value='2', format='int')
113 # opObj12.addParameter(name='n', value='2', format='int')
113 #
114 #
114 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
115 # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='other')
115 # opObj11.addParameter(name='idfigure', value='3', format='int')
116 # opObj11.addParameter(name='idfigure', value='3', format='int')
116 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
117 # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str')
117 # opObj11.addParameter(name='zmin', value='70', format='int')
118 # opObj11.addParameter(name='zmin', value='70', format='int')
118 # opObj11.addParameter(name='zmax', value='90', format='int')
119 # opObj11.addParameter(name='zmax', value='90', format='int')
119
120
120
121
121 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
122 # opObj12 = procUnitConfObj1.addOperation(name='decoder')
122 # opObj12.addParameter(name='ncode', value='2', format='int')
123 # opObj12.addParameter(name='ncode', value='2', format='int')
123 # opObj12.addParameter(name='nbauds', value='8', format='int')
124 # opObj12.addParameter(name='nbauds', value='8', format='int')
124 # opObj12.addParameter(name='code0', value='001110011', format='int')
125 # opObj12.addParameter(name='code0', value='001110011', format='int')
125 # opObj12.addParameter(name='code1', value='001110011', format='int')
126 # opObj12.addParameter(name='code1', value='001110011', format='int')
126
127
127
128
128
129
129 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId())
130 # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId())
130 #
131 #
131 # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other')
132 # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='other')
132 # opObj21.addParameter(name='n', value='2', format='int')
133 # opObj21.addParameter(name='n', value='2', format='int')
133 #
134 #
134 # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
135 # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='other')
135 # opObj11.addParameter(name='idfigure', value='4', format='int')
136 # opObj11.addParameter(name='idfigure', value='4', format='int')
136 # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str')
137 # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str')
137 # opObj11.addParameter(name='zmin', value='70', format='int')
138 # opObj11.addParameter(name='zmin', value='70', format='int')
138 # opObj11.addParameter(name='zmax', value='90', format='int')
139 # opObj11.addParameter(name='zmax', value='90', format='int')
139
140
140 print "Escribiendo el archivo XML"
141 print "Escribiendo el archivo XML"
141
142
142 controllerObj.writeXml(filename)
143 controllerObj.writeXml(filename)
143
144
144 print "Leyendo el archivo XML"
145 print "Leyendo el archivo XML"
145 controllerObj.readXml(filename)
146 controllerObj.readXml(filename)
146 #controllerObj.printattr()
147 #controllerObj.printattr()
147
148
148 controllerObj.createObjects()
149 controllerObj.createObjects()
149 controllerObj.connectObjects()
150 controllerObj.connectObjects()
150 controllerObj.run() No newline at end of file
151 controllerObj.run()
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1078 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1211 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (680 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (1267 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (535 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (505 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (700 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
This diff has been collapsed as it changes many lines, (679 lines changed) Show them Hide them
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now