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