The requested changes are too big and content was truncated. Show full diff
This diff has been collapsed as it changes many lines, (517 lines changed) Show them Hide them | |||
@@ -0,0 +1,517 | |||
|
1 | ''' | |
|
2 | Created on Jul 3, 2014 | |
|
3 | ||
|
4 | @author: roj-idl71 | |
|
5 | ''' | |
|
6 | import datetime | |
|
7 | import numpy | |
|
8 | ||
|
9 | try: | |
|
10 | from gevent import sleep | |
|
11 | except: | |
|
12 | from time import sleep | |
|
13 | ||
|
14 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
|
15 | from schainpy.model.data.jrodata import Voltage | |
|
16 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
17 | ||
|
18 | try: | |
|
19 | import digital_rf_hdf5 | |
|
20 | except: | |
|
21 | print 'You should install "digital_rf_hdf5" module if you want to read USRP data' | |
|
22 | ||
|
23 | class USRPReader(ProcessingUnit): | |
|
24 | ''' | |
|
25 | classdocs | |
|
26 | ''' | |
|
27 | ||
|
28 | def __init__(self): | |
|
29 | ''' | |
|
30 | Constructor | |
|
31 | ''' | |
|
32 | ||
|
33 | ProcessingUnit.__init__(self) | |
|
34 | ||
|
35 | self.dataOut = Voltage() | |
|
36 | self.__printInfo = True | |
|
37 | self.__flagDiscontinuousBlock = False | |
|
38 | self.__bufferIndex = 9999999 | |
|
39 | ||
|
40 | self.__ippKm = None | |
|
41 | self.__codeType = 0 | |
|
42 | self.__nCode = None | |
|
43 | self.__nBaud = None | |
|
44 | self.__code = None | |
|
45 | ||
|
46 | def __getCurrentSecond(self): | |
|
47 | ||
|
48 | return self.__thisUnixSample/self.__sample_rate | |
|
49 | ||
|
50 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") | |
|
51 | ||
|
52 | def __setFileHeader(self): | |
|
53 | ''' | |
|
54 | In this method will be initialized every parameter of dataOut object (header, no data) | |
|
55 | ''' | |
|
56 | ||
|
57 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader(ippKm=self.__ippKm, | |
|
58 | txA=0, | |
|
59 | txB=0, | |
|
60 | nWindows=1, | |
|
61 | nHeights=self.__nSamples, | |
|
62 | firstHeight=self.__firstHeigth, | |
|
63 | deltaHeight=self.__deltaHeigth, | |
|
64 | codeType=self.__codeType, | |
|
65 | nCode=self.__nCode, nBaud=self.__nBaud, | |
|
66 | code = self.__code) | |
|
67 | ||
|
68 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, | |
|
69 | nProfiles=1024, | |
|
70 | nChannels=len(self.__channelList), | |
|
71 | adcResolution=14) | |
|
72 | ||
|
73 | self.dataOut.type = "Voltage" | |
|
74 | ||
|
75 | self.dataOut.data = None | |
|
76 | ||
|
77 | self.dataOut.dtype = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
|
78 | ||
|
79 | # self.dataOut.nChannels = 0 | |
|
80 | ||
|
81 | # self.dataOut.nHeights = 0 | |
|
82 | ||
|
83 | self.dataOut.nProfiles = 1 | |
|
84 | ||
|
85 | self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth | |
|
86 | ||
|
87 | self.dataOut.channelList = self.__channelList | |
|
88 | ||
|
89 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
|
90 | ||
|
91 | # self.dataOut.channelIndexList = None | |
|
92 | ||
|
93 | self.dataOut.flagNoData = True | |
|
94 | ||
|
95 | #Set to TRUE if the data is discontinuous | |
|
96 | self.dataOut.flagDiscontinuousBlock = False | |
|
97 | ||
|
98 | self.dataOut.utctime = None | |
|
99 | ||
|
100 | self.dataOut.timeZone = self.__timezone/60 #timezone like jroheader, difference in minutes between UTC and localtime | |
|
101 | ||
|
102 | self.dataOut.dstFlag = 0 | |
|
103 | ||
|
104 | self.dataOut.errorCount = 0 | |
|
105 | ||
|
106 | self.dataOut.nCohInt = 1 | |
|
107 | ||
|
108 | self.dataOut.flagDecodeData = False #asumo que la data esta decodificada | |
|
109 | ||
|
110 | self.dataOut.flagDeflipData = False #asumo que la data esta sin flip | |
|
111 | ||
|
112 | self.dataOut.flagShiftFFT = False | |
|
113 | ||
|
114 | self.dataOut.ippSeconds = 1.0*self.__nSamples/self.__sample_rate | |
|
115 | ||
|
116 | #Time interval between profiles | |
|
117 | #self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
|
118 | ||
|
119 | self.dataOut.frequency = self.__frequency | |
|
120 | ||
|
121 | self.dataOut.realtime = self.__online | |
|
122 | ||
|
123 | def setup(self, path = None, | |
|
124 | startDate = None, | |
|
125 | endDate = None, | |
|
126 | startTime = datetime.time(0,0,0), | |
|
127 | endTime = datetime.time(23,59,59), | |
|
128 | channelList = None, | |
|
129 | nSamples = None, | |
|
130 | ippKm = None, | |
|
131 | online = False, | |
|
132 | wait = 60, | |
|
133 | nbuffer = 1024*4): | |
|
134 | ''' | |
|
135 | In this method we should set all initial parameters. | |
|
136 | ||
|
137 | Inputs: | |
|
138 | path | |
|
139 | startDate | |
|
140 | endDate | |
|
141 | startTime | |
|
142 | endTime | |
|
143 | set | |
|
144 | expLabel | |
|
145 | ext | |
|
146 | online | |
|
147 | wait | |
|
148 | ''' | |
|
149 | try: | |
|
150 | self.digitalReadObj = digital_rf_hdf5.read_hdf5(path, load_all_metadata=True) | |
|
151 | except: | |
|
152 | self.digitalReadObj = digital_rf_hdf5.read_hdf5(path) | |
|
153 | ||
|
154 | channelNameList = self.digitalReadObj.get_channels() | |
|
155 | ||
|
156 | if not channelNameList: | |
|
157 | raise IOError, "[Reading] The path doesn,t have any files .. " | |
|
158 | ||
|
159 | if not channelList: | |
|
160 | channelList = range(len(channelNameList)) | |
|
161 | ||
|
162 | ########## Reading metadata ###################### | |
|
163 | ||
|
164 | metadata_dict = self.digitalReadObj.get_rf_file_metadata(channelNameList[channelList[0]]) | |
|
165 | ||
|
166 | self.__sample_rate = metadata_dict['sample_rate'][0] | |
|
167 | self.__samples_per_file = metadata_dict['samples_per_file'][0] | |
|
168 | self.__deltaHeigth = 1e6*0.15/self.__sample_rate | |
|
169 | ||
|
170 | this_metadata_file = self.digitalReadObj.get_metadata(channelNameList[channelList[0]]) | |
|
171 | ||
|
172 | self.__frequency = this_metadata_file['center_frequencies'].value | |
|
173 | try: | |
|
174 | self.__timezone = this_metadata_file['timezone'].value | |
|
175 | except: | |
|
176 | self.__timezone = 0 | |
|
177 | ||
|
178 | self.__firstHeigth = 0 | |
|
179 | ||
|
180 | try: | |
|
181 | codeType = this_metadata_file['codeType'].value | |
|
182 | except: | |
|
183 | codeType = 0 | |
|
184 | ||
|
185 | nCode = 0 | |
|
186 | nBaud = 0 | |
|
187 | code = None | |
|
188 | ||
|
189 | if codeType: | |
|
190 | nCode = this_metadata_file['nCode'].value | |
|
191 | nBaud = this_metadata_file['nBaud'].value | |
|
192 | code = this_metadata_file['code'].value | |
|
193 | ||
|
194 | if not ippKm: | |
|
195 | try: | |
|
196 | #seconds to km | |
|
197 | ippKm = 1e6*0.15*this_metadata_file['ipp'].value | |
|
198 | except: | |
|
199 | ippKm = None | |
|
200 | ||
|
201 | #################################################### | |
|
202 | startUTCSecond = None | |
|
203 | endUTCSecond = None | |
|
204 | ||
|
205 | if startDate: | |
|
206 | startDatetime = datetime.datetime.combine(startDate, startTime) | |
|
207 | startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone | |
|
208 | ||
|
209 | if endDate: | |
|
210 | endDatetime = datetime.datetime.combine(endDate, endTime) | |
|
211 | endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone | |
|
212 | ||
|
213 | start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]]) | |
|
214 | ||
|
215 | if not startUTCSecond: | |
|
216 | startUTCSecond = start_index/self.__sample_rate | |
|
217 | ||
|
218 | if start_index > startUTCSecond*self.__sample_rate: | |
|
219 | startUTCSecond = start_index/self.__sample_rate | |
|
220 | ||
|
221 | if not endUTCSecond: | |
|
222 | endUTCSecond = end_index/self.__sample_rate | |
|
223 | ||
|
224 | if end_index < endUTCSecond*self.__sample_rate: | |
|
225 | endUTCSecond = end_index/self.__sample_rate | |
|
226 | ||
|
227 | if not nSamples: | |
|
228 | if not ippKm: | |
|
229 | raise ValueError, "[Reading] nSamples or ippKm should be defined" | |
|
230 | ||
|
231 | nSamples = ippKm / (1e6*0.15/self.__sample_rate) | |
|
232 | ||
|
233 | channelBoundList = [] | |
|
234 | channelNameListFiltered = [] | |
|
235 | ||
|
236 | for thisIndexChannel in channelList: | |
|
237 | thisChannelName = channelNameList[thisIndexChannel] | |
|
238 | start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName) | |
|
239 | channelBoundList.append((start_index, end_index)) | |
|
240 | channelNameListFiltered.append(thisChannelName) | |
|
241 | ||
|
242 | self.profileIndex = 0 | |
|
243 | ||
|
244 | self.__ippKm = ippKm | |
|
245 | self.__codeType = codeType | |
|
246 | self.__nCode = nCode | |
|
247 | self.__nBaud = nBaud | |
|
248 | self.__code = code | |
|
249 | ||
|
250 | self.__datapath = path | |
|
251 | self.__online = online | |
|
252 | self.__channelList = channelList | |
|
253 | self.__channelNameList = channelNameListFiltered | |
|
254 | self.__channelBoundList = channelBoundList | |
|
255 | self.__nSamples = nSamples | |
|
256 | self.__samples_to_read = nbuffer*nSamples | |
|
257 | self.__nChannels = len(self.__channelList) | |
|
258 | ||
|
259 | self.__startUTCSecond = startUTCSecond | |
|
260 | self.__endUTCSecond = endUTCSecond | |
|
261 | ||
|
262 | self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate #Time interval | |
|
263 | ||
|
264 | if online: | |
|
265 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) | |
|
266 | startUTCSecond = numpy.floor(endUTCSecond) | |
|
267 | ||
|
268 | self.__thisUnixSample = int(startUTCSecond*self.__sample_rate) - self.__samples_to_read | |
|
269 | ||
|
270 | self.__data_buffer = numpy.zeros((self.__nChannels, self.__samples_to_read), dtype = numpy.complex) | |
|
271 | ||
|
272 | self.__setFileHeader() | |
|
273 | self.isConfig = True | |
|
274 | ||
|
275 | print "[Reading] USRP Data was found from %s to %s " %( | |
|
276 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
277 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
278 | ) | |
|
279 | ||
|
280 | print "[Reading] Starting process from ", datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), " to ", datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone) | |
|
281 | ||
|
282 | def __reload(self): | |
|
283 | ||
|
284 | if not self.__online: | |
|
285 | return | |
|
286 | ||
|
287 | ||
|
288 | # print "%s not in range [%s, %s]" %( | |
|
289 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
290 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
291 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
292 | # ) | |
|
293 | print "[Reading] reloading metadata ..." | |
|
294 | ||
|
295 | self.digitalReadObj.reload(complete_update=True) | |
|
296 | ||
|
297 | start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]]) | |
|
298 | ||
|
299 | if start_index > self.__startUTCSecond*self.__sample_rate: | |
|
300 | self.__startUTCSecond = 1.0*start_index/self.__sample_rate | |
|
301 | ||
|
302 | if end_index > self.__endUTCSecond*self.__sample_rate: | |
|
303 | self.__endUTCSecond = 1.0*end_index/self.__sample_rate | |
|
304 | ||
|
305 | print "[Reading] New timerange found [%s, %s] " %( | |
|
306 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
307 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
308 | ) | |
|
309 | ||
|
310 | return True | |
|
311 | ||
|
312 | return False | |
|
313 | ||
|
314 | def __readNextBlock(self, seconds=30, volt_scale = 218776): | |
|
315 | ''' | |
|
316 | ''' | |
|
317 | ||
|
318 | #Set the next data | |
|
319 | self.__flagDiscontinuousBlock = False | |
|
320 | self.__thisUnixSample += self.__samples_to_read | |
|
321 | ||
|
322 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: | |
|
323 | print "[Reading] There are no more data into selected timerange" | |
|
324 | ||
|
325 | self.__reload() | |
|
326 | ||
|
327 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: | |
|
328 | self.__thisUnixSample -= self.__samples_to_read | |
|
329 | return False | |
|
330 | ||
|
331 | indexChannel = 0 | |
|
332 | ||
|
333 | dataOk = False | |
|
334 | ||
|
335 | for thisChannelName in self.__channelNameList: | |
|
336 | ||
|
337 | try: | |
|
338 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, | |
|
339 | self.__samples_to_read, | |
|
340 | thisChannelName) | |
|
341 | ||
|
342 | except IOError, e: | |
|
343 | #read next profile | |
|
344 | self.__flagDiscontinuousBlock = True | |
|
345 | print e | |
|
346 | break | |
|
347 | ||
|
348 | if result.shape[0] != self.__samples_to_read: | |
|
349 | self.__flagDiscontinuousBlock = True | |
|
350 | print "[Reading] %s: Too few samples were found, just %d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
351 | result.shape[0]) | |
|
352 | break | |
|
353 | ||
|
354 | self.__data_buffer[indexChannel,:] = result*volt_scale | |
|
355 | ||
|
356 | indexChannel += 1 | |
|
357 | ||
|
358 | dataOk = True | |
|
359 | ||
|
360 | self.__utctime = self.__thisUnixSample/self.__sample_rate | |
|
361 | ||
|
362 | if not dataOk: | |
|
363 | return False | |
|
364 | ||
|
365 | print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
366 | self.__samples_to_read, | |
|
367 | self.__timeInterval) | |
|
368 | ||
|
369 | self.__bufferIndex = 0 | |
|
370 | ||
|
371 | return True | |
|
372 | ||
|
373 | def __isBufferEmpty(self): | |
|
374 | ||
|
375 | if self.__bufferIndex <= self.__samples_to_read - self.__nSamples: | |
|
376 | return False | |
|
377 | ||
|
378 | return True | |
|
379 | ||
|
380 | def getData(self, seconds=30, nTries=5): | |
|
381 | ||
|
382 | ''' | |
|
383 | This method gets the data from files and put the data into the dataOut object | |
|
384 | ||
|
385 | In addition, increase el the buffer counter in one. | |
|
386 | ||
|
387 | Return: | |
|
388 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
|
389 | buffer. Si no hay mas archivos a leer retorna None. | |
|
390 | ||
|
391 | Affected: | |
|
392 | self.dataOut | |
|
393 | self.profileIndex | |
|
394 | self.flagDiscontinuousBlock | |
|
395 | self.flagIsNewBlock | |
|
396 | ''' | |
|
397 | ||
|
398 | err_counter = 0 | |
|
399 | self.dataOut.flagNoData = True | |
|
400 | ||
|
401 | if self.__isBufferEmpty(): | |
|
402 | ||
|
403 | self.__flagDiscontinuousBlock = False | |
|
404 | ||
|
405 | while True: | |
|
406 | if self.__readNextBlock(): | |
|
407 | break | |
|
408 | ||
|
409 | if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate: | |
|
410 | return False | |
|
411 | ||
|
412 | if self.__flagDiscontinuousBlock: | |
|
413 | print '[Reading] discontinuous block found ... continue with the next block' | |
|
414 | continue | |
|
415 | ||
|
416 | if not self.__online: | |
|
417 | return False | |
|
418 | ||
|
419 | err_counter += 1 | |
|
420 | if err_counter > nTries: | |
|
421 | return False | |
|
422 | ||
|
423 | print '[Reading] waiting %d seconds to read a new block' %seconds | |
|
424 | sleep(seconds) | |
|
425 | ||
|
426 | self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples] | |
|
427 | self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate | |
|
428 | self.dataOut.flagNoData = False | |
|
429 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
|
430 | ||
|
431 | self.__bufferIndex += self.__nSamples | |
|
432 | self.profileIndex += 1 | |
|
433 | ||
|
434 | return True | |
|
435 | ||
|
436 | def printInfo(self): | |
|
437 | ''' | |
|
438 | ''' | |
|
439 | if self.__printInfo == False: | |
|
440 | return | |
|
441 | ||
|
442 | # self.systemHeaderObj.printInfo() | |
|
443 | # self.radarControllerHeaderObj.printInfo() | |
|
444 | ||
|
445 | self.__printInfo = False | |
|
446 | ||
|
447 | def printNumberOfBlock(self): | |
|
448 | ''' | |
|
449 | ''' | |
|
450 | ||
|
451 | print self.profileIndex | |
|
452 | ||
|
453 | def run(self, **kwargs): | |
|
454 | ''' | |
|
455 | This method will be called many times so here you should put all your code | |
|
456 | ''' | |
|
457 | ||
|
458 | if not self.isConfig: | |
|
459 | self.setup(**kwargs) | |
|
460 | ||
|
461 | self.getData() | |
|
462 | ||
|
463 | return | |
|
464 | ||
|
465 | class USRPWriter(Operation): | |
|
466 | ''' | |
|
467 | classdocs | |
|
468 | ''' | |
|
469 | ||
|
470 | def __init__(self): | |
|
471 | ''' | |
|
472 | Constructor | |
|
473 | ''' | |
|
474 | self.dataOut = None | |
|
475 | ||
|
476 | def setup(self, dataIn, path, blocksPerFile, set=0, ext=None): | |
|
477 | ''' | |
|
478 | In this method we should set all initial parameters. | |
|
479 | ||
|
480 | Input: | |
|
481 | dataIn : Input data will also be outputa data | |
|
482 | ||
|
483 | ''' | |
|
484 | self.dataOut = dataIn | |
|
485 | ||
|
486 | ||
|
487 | ||
|
488 | ||
|
489 | ||
|
490 | self.isConfig = True | |
|
491 | ||
|
492 | return | |
|
493 | ||
|
494 | def run(self, dataIn, **kwargs): | |
|
495 | ''' | |
|
496 | This method will be called many times so here you should put all your code | |
|
497 | ||
|
498 | Inputs: | |
|
499 | ||
|
500 | dataIn : object with the data | |
|
501 | ||
|
502 | ''' | |
|
503 | ||
|
504 | if not self.isConfig: | |
|
505 | self.setup(dataIn, **kwargs) | |
|
506 | ||
|
507 | ||
|
508 | if __name__ == '__main__': | |
|
509 | ||
|
510 | readObj = USRPReader() | |
|
511 | ||
|
512 | while True: | |
|
513 | readObj.run(path='/Volumes/DATA/haystack/passive_radar/') | |
|
514 | # readObj.printInfo() | |
|
515 | readObj.printNumberOfBlock() | |
|
516 | ||
|
517 | No newline at end of file |
@@ -0,0 +1,135 | |||
|
1 | ''' | |
|
2 | Created on Jul 15, 2014 | |
|
3 | ||
|
4 | @author: roj-idl71 | |
|
5 | ''' | |
|
6 | import time | |
|
7 | import threading | |
|
8 | import cPickle | |
|
9 | ||
|
10 | try: | |
|
11 | from gevent import sleep | |
|
12 | except: | |
|
13 | from time import sleep | |
|
14 | ||
|
15 | SERIALIZER = cPickle | |
|
16 | ||
|
17 | # from schainpy.serializer import DynamicSerializer | |
|
18 | from schainpy.model.io.jroIO_usrp import USRPReader | |
|
19 | from schainpy.serializer.DataTranslate import obj2Serial | |
|
20 | ||
|
21 | class USRPReaderAPI(USRPReader, threading.Thread): | |
|
22 | ||
|
23 | # __isBufferEmpty = True | |
|
24 | ||
|
25 | __DATAKEYLIST = ['data','utctime','flagNoData'] | |
|
26 | ||
|
27 | def __init__(self, serializer='msgpack'): | |
|
28 | ||
|
29 | threading.Thread.__init__(self) | |
|
30 | USRPReader.__init__(self) | |
|
31 | ||
|
32 | # self.__serializerObj = DynamicSerializer.DynamicSerializer('msgpack') | |
|
33 | self.__mySerial = None | |
|
34 | self.__isBufferEmpty = True | |
|
35 | ||
|
36 | self.setSerializer(serializer) | |
|
37 | ||
|
38 | def setSerializer(self, serializer): | |
|
39 | ||
|
40 | self.__serializer = serializer | |
|
41 | ||
|
42 | def getSerializer(self): | |
|
43 | ||
|
44 | return self.__serializer | |
|
45 | ||
|
46 | def getProfileIndex(self): | |
|
47 | ||
|
48 | return self.profileIndex | |
|
49 | ||
|
50 | def getSerialMetaData(self): | |
|
51 | ||
|
52 | if self.__isBufferEmpty: | |
|
53 | ini = time.time() | |
|
54 | ||
|
55 | while True: | |
|
56 | ||
|
57 | if not self.__isBufferEmpty: | |
|
58 | break | |
|
59 | ||
|
60 | if time.time() - ini > 20: | |
|
61 | break | |
|
62 | ||
|
63 | sleep(1e-12) | |
|
64 | ||
|
65 | ||
|
66 | # if not self.getData(): | |
|
67 | # self.__isBufferEmpty = False | |
|
68 | # return None | |
|
69 | ||
|
70 | if self.dataOut.flagNoData: | |
|
71 | return None | |
|
72 | ||
|
73 | myMetadataSerial = obj2Serial(self.dataOut, | |
|
74 | serializer = self.__serializer) | |
|
75 | ||
|
76 | return myMetadataSerial | |
|
77 | ||
|
78 | def getSerialData(self): | |
|
79 | ||
|
80 | if self.__isBufferEmpty: | |
|
81 | ini = time.time() | |
|
82 | ||
|
83 | while True: | |
|
84 | ||
|
85 | if not self.__isBufferEmpty: | |
|
86 | break | |
|
87 | ||
|
88 | if time.time() - ini > 20: | |
|
89 | break | |
|
90 | ||
|
91 | sleep(1e-12) | |
|
92 | ||
|
93 | ||
|
94 | # if not self.getData(): | |
|
95 | # self.__isBufferEmpty = False | |
|
96 | # return None | |
|
97 | ||
|
98 | if self.dataOut.flagNoData: | |
|
99 | return None | |
|
100 | ||
|
101 | self.__isBufferEmpty = True | |
|
102 | ||
|
103 | return self.__mySerial | |
|
104 | ||
|
105 | def run(self): | |
|
106 | ||
|
107 | ''' | |
|
108 | This method will be called many times so here you should put all your code | |
|
109 | ''' | |
|
110 | ||
|
111 | if not self.isConfig: | |
|
112 | raise IOError, 'setup() method has to be called before start()' | |
|
113 | ||
|
114 | while True: | |
|
115 | ||
|
116 | if not self.__isBufferEmpty: | |
|
117 | sleep(1e-12) | |
|
118 | continue | |
|
119 | ||
|
120 | if not self.getData(): | |
|
121 | break | |
|
122 | ||
|
123 | print ".", | |
|
124 | ||
|
125 | self.__mySerial = obj2Serial(self.dataOut, | |
|
126 | keyList = self.__DATAKEYLIST, | |
|
127 | serializer = self.__serializer) | |
|
128 | self.__isBufferEmpty = False | |
|
129 | ||
|
130 | # print self.profileIndex | |
|
131 | # print 'wait 1 second' | |
|
132 | ||
|
133 | # sleep(0.1) | |
|
134 | ||
|
135 | return No newline at end of file |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: new file 100644 | |
The requested commit or file is too big and content was truncated. Show full diff |
@@ -1,784 +1,844 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on September , 2012 |
|
3 | 3 | @author: |
|
4 | 4 | ''' |
|
5 |
from xml.etree.ElementTree import Element, SubElement |
|
|
5 | from xml.etree.ElementTree import Element, SubElement | |
|
6 | 6 | from xml.etree import ElementTree as ET |
|
7 | 7 | from xml.dom import minidom |
|
8 | 8 | |
|
9 | import datetime | |
|
9 | #import datetime | |
|
10 | 10 | from model import * |
|
11 | 11 | |
|
12 | 12 | import ast |
|
13 | 13 | |
|
14 | 14 | def prettify(elem): |
|
15 | 15 | """Return a pretty-printed XML string for the Element. |
|
16 | 16 | """ |
|
17 | 17 | rough_string = ET.tostring(elem, 'utf-8') |
|
18 | 18 | reparsed = minidom.parseString(rough_string) |
|
19 | 19 | return reparsed.toprettyxml(indent=" ") |
|
20 | 20 | |
|
21 | 21 | class ParameterConf(): |
|
22 | 22 | |
|
23 | 23 | id = None |
|
24 | 24 | name = None |
|
25 | 25 | value = None |
|
26 | 26 | format = None |
|
27 | 27 | |
|
28 | 28 | __formated_value = None |
|
29 | 29 | |
|
30 | 30 | ELEMENTNAME = 'Parameter' |
|
31 | 31 | |
|
32 | 32 | def __init__(self): |
|
33 | 33 | |
|
34 | 34 | self.format = 'str' |
|
35 | 35 | |
|
36 | 36 | def getElementName(self): |
|
37 | 37 | |
|
38 | 38 | return self.ELEMENTNAME |
|
39 | 39 | |
|
40 | 40 | def getValue(self): |
|
41 | 41 | |
|
42 | 42 | if self.__formated_value != None: |
|
43 | 43 | |
|
44 | 44 | return self.__formated_value |
|
45 | 45 | |
|
46 | 46 | value = self.value |
|
47 | 47 | |
|
48 | 48 | if self.format == 'bool': |
|
49 | 49 | value = int(value) |
|
50 | 50 | |
|
51 | 51 | if self.format == 'list': |
|
52 | 52 | strList = value.split(',') |
|
53 | 53 | |
|
54 | 54 | self.__formated_value = strList |
|
55 | 55 | |
|
56 | 56 | return self.__formated_value |
|
57 | 57 | |
|
58 | 58 | if self.format == 'intlist': |
|
59 | 59 | """ |
|
60 | 60 | Example: |
|
61 | 61 | value = (0,1,2) |
|
62 | 62 | """ |
|
63 | 63 | strList = value.split(',') |
|
64 | 64 | intList = [int(x) for x in strList] |
|
65 | 65 | |
|
66 | 66 | self.__formated_value = intList |
|
67 | 67 | |
|
68 | 68 | return self.__formated_value |
|
69 | 69 | |
|
70 | 70 | if self.format == 'floatlist': |
|
71 | 71 | """ |
|
72 | 72 | Example: |
|
73 | 73 | value = (0.5, 1.4, 2.7) |
|
74 | 74 | """ |
|
75 | 75 | strList = value.split(',') |
|
76 | 76 | floatList = [float(x) for x in strList] |
|
77 | 77 | |
|
78 | 78 | self.__formated_value = floatList |
|
79 | 79 | |
|
80 | 80 | return self.__formated_value |
|
81 | 81 | |
|
82 | 82 | if self.format == 'date': |
|
83 | 83 | strList = value.split('/') |
|
84 | 84 | intList = [int(x) for x in strList] |
|
85 | 85 | date = datetime.date(intList[0], intList[1], intList[2]) |
|
86 | 86 | |
|
87 | 87 | self.__formated_value = date |
|
88 | 88 | |
|
89 | 89 | return self.__formated_value |
|
90 | 90 | |
|
91 | 91 | if self.format == 'time': |
|
92 | 92 | strList = value.split(':') |
|
93 | 93 | intList = [int(x) for x in strList] |
|
94 | 94 | time = datetime.time(intList[0], intList[1], intList[2]) |
|
95 | 95 | |
|
96 | 96 | self.__formated_value = time |
|
97 | 97 | |
|
98 | 98 | return self.__formated_value |
|
99 | 99 | |
|
100 | 100 | if self.format == 'pairslist': |
|
101 | 101 | """ |
|
102 | 102 | Example: |
|
103 | 103 | value = (0,1),(1,2) |
|
104 | 104 | """ |
|
105 | 105 | |
|
106 | 106 | value = value.replace('(', '') |
|
107 | 107 | value = value.replace(')', '') |
|
108 | 108 | |
|
109 | 109 | strList = value.split(',') |
|
110 | 110 | intList = [int(item) for item in strList] |
|
111 | 111 | pairList = [] |
|
112 | 112 | for i in range(len(intList)/2): |
|
113 | 113 | pairList.append((intList[i*2], intList[i*2 + 1])) |
|
114 | 114 | |
|
115 | 115 | self.__formated_value = pairList |
|
116 | 116 | |
|
117 | 117 | return self.__formated_value |
|
118 | 118 | |
|
119 | 119 | if self.format == 'multilist': |
|
120 | 120 | """ |
|
121 | 121 | Example: |
|
122 | 122 | value = (0,1,2),(3,4,5) |
|
123 | 123 | """ |
|
124 | 124 | multiList = ast.literal_eval(value) |
|
125 | 125 | |
|
126 | 126 | self.__formated_value = multiList |
|
127 | 127 | |
|
128 | 128 | return self.__formated_value |
|
129 | 129 | |
|
130 | 130 | format_func = eval(self.format) |
|
131 | 131 | |
|
132 | 132 | self.__formated_value = format_func(value) |
|
133 | 133 | |
|
134 | 134 | return self.__formated_value |
|
135 | 135 | |
|
136 | 136 | def setup(self, id, name, value, format='str'): |
|
137 | 137 | |
|
138 | 138 | self.id = id |
|
139 | 139 | self.name = name |
|
140 | 140 | self.value = str(value) |
|
141 | 141 | self.format = str.lower(format) |
|
142 | 142 | |
|
143 | 143 | def makeXml(self, opElement): |
|
144 | 144 | |
|
145 | 145 | parmElement = SubElement(opElement, self.ELEMENTNAME) |
|
146 | 146 | parmElement.set('id', str(self.id)) |
|
147 | 147 | parmElement.set('name', self.name) |
|
148 | 148 | parmElement.set('value', self.value) |
|
149 | 149 | parmElement.set('format', self.format) |
|
150 | 150 | |
|
151 | 151 | def readXml(self, parmElement): |
|
152 | 152 | |
|
153 | 153 | self.id = parmElement.get('id') |
|
154 | 154 | self.name = parmElement.get('name') |
|
155 | 155 | self.value = parmElement.get('value') |
|
156 | self.format = parmElement.get('format') | |
|
156 | self.format = str.lower(parmElement.get('format')) | |
|
157 | 157 | |
|
158 | #Compatible with old signal chain version | |
|
159 | if self.format == 'int' and self.name == 'idfigure': | |
|
160 | self.name = 'id' | |
|
161 | ||
|
158 | 162 | def printattr(self): |
|
159 | 163 | |
|
160 | 164 | print "Parameter[%s]: name = %s, value = %s, format = %s" %(self.id, self.name, self.value, self.format) |
|
161 | 165 | |
|
162 | 166 | class OperationConf(): |
|
163 | 167 | |
|
164 | 168 | id = None |
|
165 | 169 | name = None |
|
166 | 170 | priority = None |
|
167 | 171 | type = None |
|
168 | 172 | |
|
169 | 173 | parmConfObjList = [] |
|
170 | 174 | |
|
171 | 175 | ELEMENTNAME = 'Operation' |
|
172 | 176 | |
|
173 | 177 | def __init__(self): |
|
174 | 178 | |
|
175 | id = 0 | |
|
176 | name = None | |
|
177 | priority = None | |
|
178 | type = 'self' | |
|
179 | self.id = 0 | |
|
180 | self.name = None | |
|
181 | self.priority = None | |
|
182 | self.type = 'self' | |
|
179 | 183 | |
|
180 | 184 | |
|
181 | 185 | def __getNewId(self): |
|
182 | 186 | |
|
183 | 187 | return int(self.id)*10 + len(self.parmConfObjList) + 1 |
|
184 | 188 | |
|
185 | 189 | def getElementName(self): |
|
186 | 190 | |
|
187 | 191 | return self.ELEMENTNAME |
|
188 | 192 | |
|
189 | 193 | def getParameterObjList(self): |
|
190 | 194 | |
|
191 | 195 | return self.parmConfObjList |
|
192 | 196 | |
|
193 | 197 | def setup(self, id, name, priority, type): |
|
194 | 198 | |
|
195 | 199 | self.id = id |
|
196 | 200 | self.name = name |
|
197 | 201 | self.type = type |
|
198 | 202 | self.priority = priority |
|
199 | 203 | |
|
200 | 204 | self.parmConfObjList = [] |
|
201 | 205 | |
|
202 | 206 | def addParameter(self, name, value, format='str'): |
|
203 | 207 | |
|
204 | 208 | id = self.__getNewId() |
|
205 | 209 | |
|
206 | 210 | parmConfObj = ParameterConf() |
|
207 | 211 | parmConfObj.setup(id, name, value, format) |
|
208 | 212 | |
|
209 | 213 | self.parmConfObjList.append(parmConfObj) |
|
210 | 214 | |
|
211 | 215 | return parmConfObj |
|
212 | 216 | |
|
213 | 217 | def makeXml(self, upElement): |
|
214 | 218 | |
|
215 | 219 | opElement = SubElement(upElement, self.ELEMENTNAME) |
|
216 | 220 | opElement.set('id', str(self.id)) |
|
217 | 221 | opElement.set('name', self.name) |
|
218 | 222 | opElement.set('type', self.type) |
|
219 | 223 | opElement.set('priority', str(self.priority)) |
|
220 | 224 | |
|
221 | 225 | for parmConfObj in self.parmConfObjList: |
|
222 | 226 | parmConfObj.makeXml(opElement) |
|
223 | 227 | |
|
224 | 228 | def readXml(self, opElement): |
|
225 | 229 | |
|
226 | 230 | self.id = opElement.get('id') |
|
227 | 231 | self.name = opElement.get('name') |
|
228 | 232 | self.type = opElement.get('type') |
|
229 | 233 | self.priority = opElement.get('priority') |
|
230 | 234 | |
|
235 | #Compatible with old signal chain version | |
|
236 | #Use of 'run' method instead 'init' | |
|
237 | if self.type == 'self' and self.name == 'init': | |
|
238 | self.name = 'run' | |
|
239 | ||
|
231 | 240 | self.parmConfObjList = [] |
|
232 | 241 | |
|
233 | 242 | parmElementList = opElement.getiterator(ParameterConf().getElementName()) |
|
234 | 243 | |
|
235 | 244 | for parmElement in parmElementList: |
|
236 | 245 | parmConfObj = ParameterConf() |
|
237 | 246 | parmConfObj.readXml(parmElement) |
|
238 | self.parmConfObjList.append(parmConfObj) | |
|
247 | ||
|
248 | #Compatible with old signal chain version | |
|
249 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
|
250 | if self.type != 'self' and self.name == 'Plot': | |
|
251 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': | |
|
252 | self.name = parmConfObj.value | |
|
253 | continue | |
|
239 | 254 | |
|
255 | self.parmConfObjList.append(parmConfObj) | |
|
256 | ||
|
240 | 257 | def printattr(self): |
|
241 | 258 | |
|
242 | 259 | print "%s[%s]: name = %s, type = %s, priority = %s" %(self.ELEMENTNAME, |
|
243 | 260 | self.id, |
|
244 | 261 | self.name, |
|
245 | 262 | self.type, |
|
246 | 263 | self.priority) |
|
247 | 264 | |
|
248 | 265 | for parmConfObj in self.parmConfObjList: |
|
249 | 266 | parmConfObj.printattr() |
|
250 | 267 | |
|
251 | 268 | def createObject(self): |
|
252 | 269 | |
|
253 | 270 | if self.type == 'self': |
|
254 | 271 | raise ValueError, "This operation type cannot be created" |
|
255 | 272 | |
|
256 | 273 | if self.type == 'external' or self.type == 'other': |
|
257 | 274 | className = eval(self.name) |
|
258 | 275 | opObj = className() |
|
259 | 276 | |
|
260 | 277 | return opObj |
|
261 | 278 | |
|
262 | 279 | class ProcUnitConf(): |
|
263 | 280 | |
|
264 | 281 | id = None |
|
265 | 282 | name = None |
|
266 | 283 | datatype = None |
|
267 | 284 | inputId = None |
|
268 | 285 | |
|
269 | 286 | opConfObjList = [] |
|
270 | 287 | |
|
271 | 288 | procUnitObj = None |
|
272 | 289 | opObjList = [] |
|
273 | 290 | |
|
274 | 291 | ELEMENTNAME = 'ProcUnit' |
|
275 | 292 | |
|
276 | 293 | def __init__(self): |
|
277 | 294 | |
|
278 | 295 | self.id = None |
|
279 | 296 | self.datatype = None |
|
280 | 297 | self.name = None |
|
281 | 298 | self.inputId = None |
|
282 | 299 | |
|
283 | 300 | self.opConfObjList = [] |
|
284 | 301 | |
|
285 | 302 | self.procUnitObj = None |
|
286 | 303 | self.opObjDict = {} |
|
287 | 304 | |
|
288 | 305 | def __getPriority(self): |
|
289 | 306 | |
|
290 | 307 | return len(self.opConfObjList)+1 |
|
291 | 308 | |
|
292 | 309 | def __getNewId(self): |
|
293 | 310 | |
|
294 | 311 | return int(self.id)*10 + len(self.opConfObjList) + 1 |
|
295 | 312 | |
|
296 | 313 | def getElementName(self): |
|
297 | 314 | |
|
298 | 315 | return self.ELEMENTNAME |
|
299 | 316 | |
|
300 | 317 | def getId(self): |
|
301 | 318 | |
|
302 | 319 | return str(self.id) |
|
303 | 320 | |
|
304 | 321 | def getInputId(self): |
|
305 | 322 | |
|
306 | 323 | return str(self.inputId) |
|
307 | 324 | |
|
308 | 325 | def getOperationObjList(self): |
|
309 | 326 | |
|
310 | 327 | return self.opConfObjList |
|
311 | 328 | |
|
312 | 329 | def getProcUnitObj(self): |
|
313 | 330 | |
|
314 | 331 | return self.procUnitObj |
|
315 | 332 | |
|
316 | 333 | def setup(self, id, name, datatype, inputId): |
|
317 | 334 | |
|
318 | 335 | self.id = id |
|
319 | 336 | self.name = name |
|
320 | 337 | self.datatype = datatype |
|
321 | 338 | self.inputId = inputId |
|
322 | 339 | |
|
323 | 340 | self.opConfObjList = [] |
|
324 | 341 | |
|
325 | 342 | self.addOperation(name='run', optype='self') |
|
326 | 343 | |
|
327 | 344 | def addParameter(self, **kwargs): |
|
328 | 345 | |
|
329 | 346 | opObj = self.opConfObjList[0] |
|
330 | 347 | |
|
331 | 348 | opObj.addParameter(**kwargs) |
|
332 | 349 | |
|
333 | 350 | return opObj |
|
334 | 351 | |
|
335 | 352 | def addOperation(self, name, optype='self'): |
|
336 | 353 | |
|
337 | 354 | id = self.__getNewId() |
|
338 | 355 | priority = self.__getPriority() |
|
339 | 356 | |
|
340 | 357 | opConfObj = OperationConf() |
|
341 | 358 | opConfObj.setup(id, name=name, priority=priority, type=optype) |
|
342 | 359 | |
|
343 | 360 | self.opConfObjList.append(opConfObj) |
|
344 | 361 | |
|
345 | 362 | return opConfObj |
|
346 | 363 | |
|
347 | 364 | def makeXml(self, procUnitElement): |
|
348 | 365 | |
|
349 | 366 | upElement = SubElement(procUnitElement, self.ELEMENTNAME) |
|
350 | 367 | upElement.set('id', str(self.id)) |
|
351 | 368 | upElement.set('name', self.name) |
|
352 | 369 | upElement.set('datatype', self.datatype) |
|
353 | 370 | upElement.set('inputId', str(self.inputId)) |
|
354 | 371 | |
|
355 | 372 | for opConfObj in self.opConfObjList: |
|
356 | 373 | opConfObj.makeXml(upElement) |
|
357 | 374 | |
|
358 | 375 | def readXml(self, upElement): |
|
359 | 376 | |
|
360 | 377 | self.id = upElement.get('id') |
|
361 | 378 | self.name = upElement.get('name') |
|
362 | 379 | self.datatype = upElement.get('datatype') |
|
363 | 380 | self.inputId = upElement.get('inputId') |
|
364 |
|
|
|
381 | ||
|
382 | #Compatible with old signal chain version | |
|
383 | if self.ELEMENTNAME == ReadUnitConf().getElementName(): | |
|
384 | if 'Reader' not in self.name: | |
|
385 | self.name += 'Reader' | |
|
386 | ||
|
387 | if self.ELEMENTNAME == ProcUnitConf().getElementName(): | |
|
388 | if 'Proc' not in self.name: | |
|
389 | self.name += 'Proc' | |
|
390 | ||
|
365 | 391 | self.opConfObjList = [] |
|
366 | 392 | |
|
367 | 393 | opElementList = upElement.getiterator(OperationConf().getElementName()) |
|
368 | 394 | |
|
369 | 395 | for opElement in opElementList: |
|
370 | 396 | opConfObj = OperationConf() |
|
371 | 397 | opConfObj.readXml(opElement) |
|
372 | 398 | self.opConfObjList.append(opConfObj) |
|
373 | 399 | |
|
374 | 400 | def printattr(self): |
|
375 | 401 | |
|
376 | 402 | print "%s[%s]: name = %s, datatype = %s, inputId = %s" %(self.ELEMENTNAME, |
|
377 | 403 | self.id, |
|
378 | 404 | self.name, |
|
379 | 405 | self.datatype, |
|
380 | 406 | self.inputId) |
|
381 | 407 | |
|
382 | 408 | for opConfObj in self.opConfObjList: |
|
383 | 409 | opConfObj.printattr() |
|
384 | 410 | |
|
385 | 411 | def createObjects(self): |
|
386 | 412 | |
|
387 | 413 | className = eval(self.name) |
|
388 | 414 | procUnitObj = className() |
|
389 | 415 | |
|
390 | 416 | for opConfObj in self.opConfObjList: |
|
391 | 417 | |
|
392 | 418 | if opConfObj.type == 'self': |
|
393 | 419 | continue |
|
394 | 420 | |
|
395 | 421 | opObj = opConfObj.createObject() |
|
396 | 422 | |
|
397 | 423 | self.opObjDict[opConfObj.id] = opObj |
|
398 | 424 | procUnitObj.addOperation(opObj, opConfObj.id) |
|
399 | 425 | |
|
400 | 426 | self.procUnitObj = procUnitObj |
|
401 | 427 | |
|
402 | 428 | return procUnitObj |
|
403 | 429 | |
|
404 | 430 | def run(self): |
|
405 | 431 | |
|
406 | 432 | finalSts = False |
|
407 | 433 | |
|
408 | 434 | for opConfObj in self.opConfObjList: |
|
409 | 435 | |
|
410 | 436 | kwargs = {} |
|
411 | 437 | for parmConfObj in opConfObj.getParameterObjList(): |
|
412 | 438 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
413 | 439 | |
|
414 | 440 | #print "\tRunning the '%s' operation with %s" %(opConfObj.name, opConfObj.id) |
|
415 | 441 | sts = self.procUnitObj.call(opType = opConfObj.type, |
|
416 | 442 | opName = opConfObj.name, |
|
417 | 443 | opId = opConfObj.id, |
|
418 | 444 | **kwargs) |
|
419 | 445 | finalSts = finalSts or sts |
|
420 | 446 | |
|
421 | 447 | return finalSts |
|
422 | 448 | |
|
423 | 449 | class ReadUnitConf(ProcUnitConf): |
|
424 | 450 | |
|
425 | 451 | path = None |
|
426 | 452 | startDate = None |
|
427 | 453 | endDate = None |
|
428 | 454 | startTime = None |
|
429 | 455 | endTime = None |
|
430 | 456 | |
|
431 | 457 | ELEMENTNAME = 'ReadUnit' |
|
432 | 458 | |
|
433 | 459 | def __init__(self): |
|
434 | 460 | |
|
435 | 461 | self.id = None |
|
436 | 462 | self.datatype = None |
|
437 | 463 | self.name = None |
|
438 | 464 | self.inputId = 0 |
|
439 | 465 | |
|
440 | 466 | self.opConfObjList = [] |
|
441 | 467 | self.opObjList = [] |
|
442 | 468 | |
|
443 | 469 | def getElementName(self): |
|
444 | 470 | |
|
445 | 471 | return self.ELEMENTNAME |
|
446 | 472 | |
|
447 | 473 | def setup(self, id, name, datatype, path="", startDate="", endDate="", startTime="", endTime="", **kwargs): |
|
448 | 474 | |
|
449 | 475 | self.id = id |
|
450 | 476 | self.name = name |
|
451 | 477 | self.datatype = datatype |
|
452 | 478 | |
|
453 | 479 | self.path = path |
|
454 | 480 | self.startDate = startDate |
|
455 | 481 | self.endDate = endDate |
|
456 | 482 | self.startTime = startTime |
|
457 | 483 | self.endTime = endTime |
|
458 | 484 | |
|
459 | 485 | self.addRunOperation(**kwargs) |
|
460 | 486 | |
|
461 | 487 | def addRunOperation(self, **kwargs): |
|
462 | 488 | |
|
463 | 489 | opObj = self.addOperation(name = 'run', optype = 'self') |
|
464 | 490 | |
|
465 | 491 | opObj.addParameter(name='path' , value=self.path, format='str') |
|
466 | 492 | opObj.addParameter(name='startDate' , value=self.startDate, format='date') |
|
467 | 493 | opObj.addParameter(name='endDate' , value=self.endDate, format='date') |
|
468 | 494 | opObj.addParameter(name='startTime' , value=self.startTime, format='time') |
|
469 | 495 | opObj.addParameter(name='endTime' , value=self.endTime, format='time') |
|
470 | 496 | |
|
471 | 497 | for key, value in kwargs.items(): |
|
472 | 498 | opObj.addParameter(name=key, value=value, format=type(value).__name__) |
|
473 | 499 | |
|
474 | 500 | return opObj |
|
475 | 501 | |
|
476 | 502 | |
|
477 | 503 | class Project(): |
|
478 | 504 | |
|
479 | 505 | id = None |
|
480 | 506 | name = None |
|
481 | 507 | description = None |
|
482 | 508 | # readUnitConfObjList = None |
|
483 | 509 | procUnitConfObjDict = None |
|
484 | 510 | |
|
485 | 511 | ELEMENTNAME = 'Project' |
|
486 | 512 | |
|
487 | 513 | def __init__(self): |
|
488 | 514 | |
|
489 | 515 | self.id = None |
|
490 | 516 | self.name = None |
|
491 | 517 | self.description = None |
|
492 | 518 | |
|
493 | 519 | # self.readUnitConfObjList = [] |
|
494 | 520 | self.procUnitConfObjDict = {} |
|
495 | 521 | |
|
496 | 522 | def __getNewId(self): |
|
497 | 523 | |
|
498 | 524 | id = int(self.id)*10 + len(self.procUnitConfObjDict) + 1 |
|
499 | 525 | |
|
500 | 526 | return str(id) |
|
501 | 527 | |
|
502 | 528 | def getElementName(self): |
|
503 | 529 | |
|
504 | 530 | return self.ELEMENTNAME |
|
505 | 531 | |
|
506 | 532 | def setup(self, id, name, description): |
|
507 | 533 | |
|
508 | 534 | self.id = id |
|
509 | 535 | self.name = name |
|
510 | 536 | self.description = description |
|
511 | 537 | |
|
512 | def addReadUnit(self, datatype, **kwargs): | |
|
538 | def addReadUnit(self, datatype=None, name=None, **kwargs): | |
|
513 | 539 | |
|
540 | #Compatible with old signal chain version | |
|
541 | if datatype==None and name==None: | |
|
542 | raise ValueError, "datatype or name should be defined" | |
|
543 | ||
|
544 | if name==None: | |
|
545 | if 'Reader' in datatype: | |
|
546 | name = datatype | |
|
547 | else: | |
|
548 | name = '%sReader' %(datatype) | |
|
549 | ||
|
550 | if datatype==None: | |
|
551 | datatype = name.replace('Reader','') | |
|
552 | ||
|
514 | 553 | id = self.__getNewId() |
|
515 | name = '%s' %(datatype) | |
|
516 | 554 | |
|
517 | 555 | readUnitConfObj = ReadUnitConf() |
|
518 | 556 | readUnitConfObj.setup(id, name, datatype, **kwargs) |
|
519 | 557 | |
|
520 | 558 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
521 | 559 | |
|
522 | 560 | return readUnitConfObj |
|
523 | 561 | |
|
524 |
def addProcUnit(self, d |
|
|
562 | def addProcUnit(self, inputId, datatype=None, name=None): | |
|
563 | ||
|
564 | #Compatible with old signal chain version | |
|
565 | if datatype==None and name==None: | |
|
566 | raise ValueError, "datatype or name should be defined" | |
|
567 | ||
|
568 | if name==None: | |
|
569 | if 'Proc' in datatype: | |
|
570 | name = datatype | |
|
571 | else: | |
|
572 | name = '%sProc' %(datatype) | |
|
573 | ||
|
574 | if datatype==None: | |
|
575 | datatype = name.replace('Proc','') | |
|
525 | 576 | |
|
526 | 577 | id = self.__getNewId() |
|
527 | name = '%s' %(datatype) | |
|
528 | 578 | |
|
529 | 579 | procUnitConfObj = ProcUnitConf() |
|
530 | 580 | procUnitConfObj.setup(id, name, datatype, inputId) |
|
531 | 581 | |
|
532 | 582 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
533 | 583 | |
|
534 | 584 | return procUnitConfObj |
|
535 | 585 | |
|
536 | 586 | def makeXml(self): |
|
537 | 587 | |
|
538 | 588 | projectElement = Element('Project') |
|
539 | 589 | projectElement.set('id', str(self.id)) |
|
540 | 590 | projectElement.set('name', self.name) |
|
541 | 591 | projectElement.set('description', self.description) |
|
542 | 592 | |
|
543 | 593 | # for readUnitConfObj in self.readUnitConfObjList: |
|
544 | 594 | # readUnitConfObj.makeXml(projectElement) |
|
545 | 595 | |
|
546 | 596 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
547 | 597 | procUnitConfObj.makeXml(projectElement) |
|
548 | 598 | |
|
549 | 599 | self.projectElement = projectElement |
|
550 | 600 | |
|
551 | 601 | def writeXml(self, filename): |
|
552 | 602 | |
|
553 | 603 | self.makeXml() |
|
554 | 604 | |
|
555 | print prettify(self.projectElement) | |
|
605 | #print prettify(self.projectElement) | |
|
556 | 606 | |
|
557 | 607 | ElementTree(self.projectElement).write(filename, method='xml') |
|
558 | 608 | |
|
559 | 609 | def readXml(self, filename): |
|
560 | 610 | |
|
561 | 611 | #tree = ET.parse(filename) |
|
562 | 612 | self.projectElement = None |
|
563 | 613 | # self.readUnitConfObjList = [] |
|
564 | 614 | self.procUnitConfObjDict = {} |
|
565 | 615 | |
|
566 | 616 | self.projectElement = ElementTree().parse(filename) |
|
567 | 617 | |
|
568 | 618 | self.project = self.projectElement.tag |
|
569 | 619 | |
|
570 | 620 | self.id = self.projectElement.get('id') |
|
571 | 621 | self.name = self.projectElement.get('name') |
|
572 | 622 | self.description = self.projectElement.get('description') |
|
573 | 623 | |
|
574 | 624 | readUnitElementList = self.projectElement.getiterator(ReadUnitConf().getElementName()) |
|
575 | 625 | |
|
576 | 626 | for readUnitElement in readUnitElementList: |
|
577 | 627 | readUnitConfObj = ReadUnitConf() |
|
578 | 628 | readUnitConfObj.readXml(readUnitElement) |
|
579 | 629 | |
|
580 | 630 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
581 | 631 | |
|
582 | 632 | procUnitElementList = self.projectElement.getiterator(ProcUnitConf().getElementName()) |
|
583 | 633 | |
|
584 | 634 | for procUnitElement in procUnitElementList: |
|
585 | 635 | procUnitConfObj = ProcUnitConf() |
|
586 | 636 | procUnitConfObj.readXml(procUnitElement) |
|
587 | 637 | |
|
588 | 638 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
589 | 639 | |
|
590 | 640 | def printattr(self): |
|
591 | 641 | |
|
592 | 642 | print "Project[%s]: name = %s, description = %s" %(self.id, |
|
593 | 643 | self.name, |
|
594 | 644 | self.description) |
|
595 | 645 | |
|
596 | 646 | # for readUnitConfObj in self.readUnitConfObjList: |
|
597 | 647 | # readUnitConfObj.printattr() |
|
598 | 648 | |
|
599 | 649 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
600 | 650 | procUnitConfObj.printattr() |
|
601 | 651 | |
|
602 | 652 | def createObjects(self): |
|
603 | 653 | |
|
604 | 654 | # for readUnitConfObj in self.readUnitConfObjList: |
|
605 | 655 | # readUnitConfObj.createObjects() |
|
606 | 656 | |
|
607 | 657 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
608 | 658 | procUnitConfObj.createObjects() |
|
609 | 659 | |
|
610 | 660 | def __connect(self, objIN, thisObj): |
|
611 | 661 | |
|
612 | 662 | thisObj.setInput(objIN.getOutputObj()) |
|
613 | 663 | |
|
614 | 664 | def connectObjects(self): |
|
615 | 665 | |
|
616 | 666 | for thisPUConfObj in self.procUnitConfObjDict.values(): |
|
617 | 667 | |
|
618 | 668 | inputId = thisPUConfObj.getInputId() |
|
619 | 669 | |
|
620 | 670 | if int(inputId) == 0: |
|
621 | 671 | continue |
|
622 | 672 | |
|
623 | 673 | #Get input object |
|
624 | 674 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
625 | 675 | puObjIN = puConfINObj.getProcUnitObj() |
|
626 | 676 | |
|
627 | 677 | #Get current object |
|
628 | 678 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
629 | 679 | |
|
630 | 680 | self.__connect(puObjIN, thisPUObj) |
|
631 | 681 | |
|
632 | 682 | def run(self): |
|
633 | 683 | |
|
634 | 684 | # for readUnitConfObj in self.readUnitConfObjList: |
|
635 | 685 | # readUnitConfObj.run() |
|
636 | ||
|
686 | ||
|
687 | print "*"*40 | |
|
688 | print " Starting SIGNAL CHAIN PROCESSING " | |
|
689 | print "*"*40 | |
|
690 | ||
|
691 | ||
|
692 | keyList = self.procUnitConfObjDict.keys() | |
|
693 | keyList.sort() | |
|
694 | ||
|
637 | 695 | while(True): |
|
638 | 696 | |
|
639 | 697 | finalSts = False |
|
640 | 698 | |
|
641 | for procUnitConfObj in self.procUnitConfObjDict.values(): | |
|
642 |
|
|
|
699 | for procKey in keyList: | |
|
700 | # print "Running the '%s' process with %s" %(procUnitConfObj.name, procUnitConfObj.id) | |
|
701 | ||
|
702 | procUnitConfObj = self.procUnitConfObjDict[procKey] | |
|
643 | 703 | sts = procUnitConfObj.run() |
|
644 | 704 | finalSts = finalSts or sts |
|
645 | 705 | |
|
646 | 706 | #If every process unit finished so end process |
|
647 | 707 | if not(finalSts): |
|
648 |
print "Every process unit |
|
|
708 | print "Every process unit have finished" | |
|
649 | 709 | break |
|
650 | 710 | |
|
651 | 711 | if __name__ == '__main__': |
|
652 | 712 | |
|
653 | 713 | desc = "Segundo Test" |
|
654 | 714 | filename = "schain.xml" |
|
655 | 715 | |
|
656 | 716 | controllerObj = Project() |
|
657 | 717 | |
|
658 | 718 | controllerObj.setup(id = '191', name='test01', description=desc) |
|
659 | 719 | |
|
660 | 720 | readUnitConfObj = controllerObj.addReadUnit(datatype='Voltage', |
|
661 | 721 | path='data/rawdata/', |
|
662 | 722 | startDate='2011/01/01', |
|
663 | 723 | endDate='2012/12/31', |
|
664 | 724 | startTime='00:00:00', |
|
665 | 725 | endTime='23:59:59', |
|
666 | 726 | online=1, |
|
667 | 727 | walk=1) |
|
668 | 728 | |
|
669 | 729 | # opObj00 = readUnitConfObj.addOperation(name='printInfo') |
|
670 | 730 | |
|
671 | 731 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', inputId=readUnitConfObj.getId()) |
|
672 | 732 | |
|
673 | 733 | opObj10 = procUnitConfObj0.addOperation(name='selectChannels') |
|
674 | 734 | opObj10.addParameter(name='channelList', value='3,4,5', format='intlist') |
|
675 | 735 | |
|
676 | 736 | opObj10 = procUnitConfObj0.addOperation(name='selectHeights') |
|
677 | 737 | opObj10.addParameter(name='minHei', value='90', format='float') |
|
678 | 738 | opObj10.addParameter(name='maxHei', value='180', format='float') |
|
679 | 739 | |
|
680 | 740 | opObj12 = procUnitConfObj0.addOperation(name='CohInt', optype='external') |
|
681 | 741 | opObj12.addParameter(name='n', value='10', format='int') |
|
682 | 742 | |
|
683 | 743 | procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj0.getId()) |
|
684 | 744 | procUnitConfObj1.addParameter(name='nFFTPoints', value='32', format='int') |
|
685 | 745 | # procUnitConfObj1.addParameter(name='pairList', value='(0,1),(0,2),(1,2)', format='') |
|
686 | 746 | |
|
687 | 747 | |
|
688 | 748 | opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
689 | 749 | opObj11.addParameter(name='idfigure', value='1', format='int') |
|
690 | 750 | opObj11.addParameter(name='wintitle', value='SpectraPlot0', format='str') |
|
691 | 751 | opObj11.addParameter(name='zmin', value='40', format='int') |
|
692 | 752 | opObj11.addParameter(name='zmax', value='90', format='int') |
|
693 | 753 | opObj11.addParameter(name='showprofile', value='1', format='int') |
|
694 | 754 | |
|
695 | 755 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='external') |
|
696 | 756 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
697 | 757 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') |
|
698 | 758 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
699 | 759 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
700 | 760 | |
|
701 | 761 | |
|
702 | 762 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Voltage', inputId=procUnitConfObj0.getId()) |
|
703 | 763 | # |
|
704 | 764 | # opObj12 = procUnitConfObj2.addOperation(name='CohInt', optype='external') |
|
705 | 765 | # opObj12.addParameter(name='n', value='2', format='int') |
|
706 | 766 | # opObj12.addParameter(name='overlapping', value='1', format='int') |
|
707 | 767 | # |
|
708 | 768 | # procUnitConfObj3 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj2.getId()) |
|
709 | 769 | # procUnitConfObj3.addParameter(name='nFFTPoints', value='32', format='int') |
|
710 | 770 | # |
|
711 | 771 | # opObj11 = procUnitConfObj3.addOperation(name='SpectraPlot', optype='external') |
|
712 | 772 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
713 | 773 | # opObj11.addParameter(name='wintitle', value='SpectraPlot1', format='str') |
|
714 | 774 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
715 | 775 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
716 | 776 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
717 | 777 | |
|
718 | 778 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='external') |
|
719 | 779 | # opObj11.addParameter(name='idfigure', value='10', format='int') |
|
720 | 780 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') |
|
721 | 781 | ## opObj11.addParameter(name='xmin', value='21', format='float') |
|
722 | 782 | ## opObj11.addParameter(name='xmax', value='22', format='float') |
|
723 | 783 | # opObj11.addParameter(name='zmin', value='40', format='int') |
|
724 | 784 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
725 | 785 | # opObj11.addParameter(name='showprofile', value='1', format='int') |
|
726 | 786 | # opObj11.addParameter(name='timerange', value=str(60), format='int') |
|
727 | 787 | |
|
728 | 788 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
729 | 789 | # opObj10.addParameter(name='channelList', value='0,2,4,6', format='intlist') |
|
730 | 790 | # |
|
731 | 791 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') |
|
732 | 792 | # opObj12.addParameter(name='n', value='2', format='int') |
|
733 | 793 | # |
|
734 | 794 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
735 | 795 | # opObj11.addParameter(name='idfigure', value='2', format='int') |
|
736 | 796 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
737 | 797 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
738 | 798 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
739 | 799 | # |
|
740 | 800 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') |
|
741 | 801 | # opObj10.addParameter(name='channelList', value='2,6', format='intlist') |
|
742 | 802 | # |
|
743 | 803 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') |
|
744 | 804 | # opObj12.addParameter(name='n', value='2', format='int') |
|
745 | 805 | # |
|
746 | 806 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') |
|
747 | 807 | # opObj11.addParameter(name='idfigure', value='3', format='int') |
|
748 | 808 | # opObj11.addParameter(name='wintitle', value='SpectraPlot10', format='str') |
|
749 | 809 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
750 | 810 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
751 | 811 | |
|
752 | 812 | |
|
753 | 813 | # opObj12 = procUnitConfObj1.addOperation(name='decoder') |
|
754 | 814 | # opObj12.addParameter(name='ncode', value='2', format='int') |
|
755 | 815 | # opObj12.addParameter(name='nbauds', value='8', format='int') |
|
756 | 816 | # opObj12.addParameter(name='code0', value='001110011', format='int') |
|
757 | 817 | # opObj12.addParameter(name='code1', value='001110011', format='int') |
|
758 | 818 | |
|
759 | 819 | |
|
760 | 820 | |
|
761 | 821 | # procUnitConfObj2 = controllerObj.addProcUnit(datatype='Spectra', inputId=procUnitConfObj1.getId()) |
|
762 | 822 | # |
|
763 | 823 | # opObj21 = procUnitConfObj2.addOperation(name='IncohInt', optype='external') |
|
764 | 824 | # opObj21.addParameter(name='n', value='2', format='int') |
|
765 | 825 | # |
|
766 | 826 | # opObj11 = procUnitConfObj2.addOperation(name='SpectraPlot', optype='external') |
|
767 | 827 | # opObj11.addParameter(name='idfigure', value='4', format='int') |
|
768 | 828 | # opObj11.addParameter(name='wintitle', value='SpectraPlot OBJ 2', format='str') |
|
769 | 829 | # opObj11.addParameter(name='zmin', value='70', format='int') |
|
770 | 830 | # opObj11.addParameter(name='zmax', value='90', format='int') |
|
771 | 831 | |
|
772 | 832 | print "Escribiendo el archivo XML" |
|
773 | 833 | |
|
774 | 834 | controllerObj.writeXml(filename) |
|
775 | 835 | |
|
776 | 836 | print "Leyendo el archivo XML" |
|
777 | 837 | controllerObj.readXml(filename) |
|
778 | 838 | #controllerObj.printattr() |
|
779 | 839 | |
|
780 | 840 | controllerObj.createObjects() |
|
781 | 841 | controllerObj.connectObjects() |
|
782 | 842 | controllerObj.run() |
|
783 | 843 | |
|
784 | 844 | No newline at end of file |
@@ -1,5 +1,12 | |||
|
1 | from model.data.jrodata import * | |
|
2 | from model.io.jrodataIO import * | |
|
3 | from model.proc.jroprocessing import * | |
|
4 | from model.graphics.jroplot import * | |
|
5 | from model.utils.jroutils import * No newline at end of file | |
|
1 | #from schainpy.model.data.jrodata import * | |
|
2 | # from schainpy.model.io.jrodataIO import * | |
|
3 | # from schainpy.model.proc.jroprocessing import * | |
|
4 | # from schainpy.model.graphics.jroplot import * | |
|
5 | # from schainpy.model.utils.jroutils import * | |
|
6 | # from schainpy.serializer import * | |
|
7 | ||
|
8 | from data import * | |
|
9 | from io import * | |
|
10 | from proc import * | |
|
11 | from graphics import * | |
|
12 | from utils import * |
@@ -0,0 +1,3 | |||
|
1 | from jrodata import * | |
|
2 | from jroheaderIO import * | |
|
3 | from jroamisr import * No newline at end of file |
@@ -1,82 +1,83 | |||
|
1 | 1 | import numpy |
|
2 | import copy | |
|
2 | 3 | |
|
3 | 4 | class Beam: |
|
4 | 5 | def __init__(self): |
|
5 | 6 | self.codeList = [] |
|
6 | 7 | self.azimuthList = [] |
|
7 | 8 | self.zenithList = [] |
|
8 | 9 | |
|
9 | 10 | |
|
10 | 11 | class AMISR: |
|
11 | 12 | def __init__(self): |
|
12 | 13 | self.flagNoData = True |
|
13 | 14 | self.data = None |
|
14 | 15 | self.utctime = None |
|
15 | 16 | self.type = "AMISR" |
|
16 | 17 | |
|
17 | 18 | #propiedades para compatibilidad con Voltages |
|
18 | 19 | self.timeZone = 0#timezone like jroheader, difference in minutes between UTC and localtime |
|
19 | 20 | self.dstFlag = 0#self.dataIn.dstFlag |
|
20 | 21 | self.errorCount = 0#self.dataIn.errorCount |
|
21 | 22 | self.useLocalTime = True#self.dataIn.useLocalTime |
|
22 | 23 | |
|
23 | 24 | self.radarControllerHeaderObj = None#self.dataIn.radarControllerHeaderObj.copy() |
|
24 | 25 | self.systemHeaderObj = None#self.dataIn.systemHeaderObj.copy() |
|
25 | 26 | self.channelList = [0]#self.dataIn.channelList esto solo aplica para el caso de AMISR |
|
26 | 27 | self.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
27 | 28 | |
|
28 |
self.flag |
|
|
29 | self.flagDiscontinuousBlock = None#self.dataIn.flagDiscontinuousBlock | |
|
29 | 30 | #self.utctime = #self.firstdatatime |
|
30 | 31 | self.flagDecodeData = None#self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
31 | 32 | self.flagDeflipData = None#self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
32 | 33 | |
|
33 | 34 | self.nCohInt = 1#self.dataIn.nCohInt |
|
34 | 35 | self.nIncohInt = 1 |
|
35 | 36 | self.ippSeconds = None#self.dataIn.ippSeconds, segun el filename/Setup/Tufile |
|
36 | 37 | self.windowOfFilter = None#self.dataIn.windowOfFilter |
|
37 | 38 | |
|
38 | 39 | self.timeInterval = None#self.dataIn.timeInterval*self.dataOut.nFFTPoints*self.dataOut.nIncohInt |
|
39 | 40 | self.frequency = None#self.dataIn.frequency |
|
40 | 41 | self.realtime = 0#self.dataIn.realtime |
|
41 | 42 | |
|
42 | 43 | #actualizar en la lectura de datos |
|
43 | 44 | self.heightList = None#self.dataIn.heightList |
|
44 | 45 | self.nProfiles = None#Number of samples or nFFTPoints |
|
45 | 46 | self.nRecords = None |
|
46 | 47 | self.nBeams = None |
|
47 | 48 | self.nBaud = None#self.dataIn.nBaud |
|
48 | 49 | self.nCode = None#self.dataIn.nCode |
|
49 | 50 | self.code = None#self.dataIn.code |
|
50 | 51 | |
|
51 | 52 | #consideracion para los Beams |
|
52 | 53 | self.beamCodeDict = None |
|
53 | 54 | self.beamRangeDict = None |
|
54 | 55 | self.beamcode = None |
|
55 | 56 | self.azimuth = None |
|
56 | 57 | self.zenith = None |
|
57 | 58 | self.gain = None |
|
58 | 59 | |
|
59 | 60 | self.npulseByFrame = None |
|
60 | 61 | |
|
61 | 62 | self.profileIndex = None |
|
62 | 63 | |
|
63 | 64 | self.beam = Beam() |
|
64 | 65 | |
|
65 | 66 | def copy(self, inputObj=None): |
|
66 | 67 | |
|
67 | 68 | if inputObj == None: |
|
68 | 69 | return copy.deepcopy(self) |
|
69 | 70 | |
|
70 | 71 | for key in inputObj.__dict__.keys(): |
|
71 | 72 | self.__dict__[key] = inputObj.__dict__[key] |
|
72 | 73 | |
|
73 | 74 | def getNHeights(self): |
|
74 | 75 | |
|
75 | 76 | return len(self.heightList) |
|
76 | 77 | |
|
77 | 78 | |
|
78 | 79 | def isEmpty(self): |
|
79 | 80 | |
|
80 | 81 | return self.flagNoData |
|
81 | 82 | |
|
82 | 83 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") No newline at end of file |
@@ -1,1029 +1,1102 | |||
|
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 | """ | |
|
53 | This method is for the objective determination of the noise level in Doppler spectra. This | |
|
54 | implementation technique is based on the fact that the standard deviation of the spectral | |
|
55 | densities is equal to the mean spectral density for white Gaussian noise | |
|
52 | 56 |
|
|
53 | data = data.copy() | |
|
57 | Inputs: | |
|
58 | Data : heights | |
|
59 | navg : numbers of averages | |
|
60 | ||
|
61 | Return: | |
|
62 | -1 : any error | |
|
63 | anoise : noise's level | |
|
64 | """ | |
|
54 | 65 | |
|
55 | 66 | sortdata = numpy.sort(data,axis=None) |
|
56 | 67 | lenOfData = len(sortdata) |
|
57 | 68 | nums_min = lenOfData/10 |
|
58 | 69 | |
|
59 | 70 | if (lenOfData/10) > 2: |
|
60 | 71 | nums_min = lenOfData/10 |
|
61 | 72 | else: |
|
62 | 73 | nums_min = 2 |
|
63 | 74 | |
|
64 | 75 | sump = 0. |
|
65 | 76 | |
|
66 | 77 | sumq = 0. |
|
67 | 78 | |
|
68 | 79 | j = 0 |
|
69 | 80 | |
|
70 | 81 | cont = 1 |
|
71 | 82 | |
|
72 | 83 | while((cont==1)and(j<lenOfData)): |
|
73 | 84 | |
|
74 | 85 | sump += sortdata[j] |
|
75 | 86 | |
|
76 | 87 | sumq += sortdata[j]**2 |
|
77 | 88 | |
|
78 | 89 | j += 1 |
|
79 | 90 | |
|
80 | 91 | if j > nums_min: |
|
81 | 92 | rtest = float(j)/(j-1) + 1.0/navg |
|
82 | 93 | if ((sumq*j) > (rtest*sump**2)): |
|
83 | 94 | j = j - 1 |
|
84 | 95 | sump = sump - sortdata[j] |
|
85 | 96 | sumq = sumq - sortdata[j]**2 |
|
86 | 97 | cont = 0 |
|
87 | 98 | |
|
88 | 99 | lnoise = sump /j |
|
89 | 100 | stdv = numpy.sqrt((sumq - lnoise**2)/(j - 1)) |
|
90 | 101 | return lnoise |
|
91 | 102 | |
|
92 | 103 | class Beam: |
|
93 | 104 | def __init__(self): |
|
94 | 105 | self.codeList = [] |
|
95 | 106 | self.azimuthList = [] |
|
96 | 107 | self.zenithList = [] |
|
97 | 108 | |
|
98 | 109 | class GenericData(object): |
|
99 | 110 | |
|
100 | 111 | flagNoData = True |
|
101 | 112 | |
|
102 | 113 | def __init__(self): |
|
103 | 114 | |
|
104 | 115 | raise ValueError, "This class has not been implemented" |
|
105 | 116 | |
|
106 | 117 | def copy(self, inputObj=None): |
|
107 | 118 | |
|
108 | 119 | if inputObj == None: |
|
109 | 120 | return copy.deepcopy(self) |
|
110 | 121 | |
|
111 | 122 | for key in inputObj.__dict__.keys(): |
|
112 | 123 | self.__dict__[key] = inputObj.__dict__[key] |
|
113 | 124 | |
|
114 | 125 | def deepcopy(self): |
|
115 | 126 | |
|
116 | 127 | return copy.deepcopy(self) |
|
117 | 128 | |
|
118 | 129 | def isEmpty(self): |
|
119 | 130 | |
|
120 | 131 | return self.flagNoData |
|
121 | 132 | |
|
122 | 133 | class JROData(GenericData): |
|
123 | 134 | |
|
124 | 135 | # m_BasicHeader = BasicHeader() |
|
125 | 136 | # m_ProcessingHeader = ProcessingHeader() |
|
126 | 137 | |
|
127 | 138 | systemHeaderObj = SystemHeader() |
|
128 | 139 | |
|
129 | 140 | radarControllerHeaderObj = RadarControllerHeader() |
|
130 | 141 | |
|
131 | 142 | # data = None |
|
132 | 143 | |
|
133 | 144 | type = None |
|
134 | 145 | |
|
135 | 146 | datatype = None #dtype but in string |
|
136 | 147 | |
|
137 | 148 | # dtype = None |
|
138 | 149 | |
|
139 | 150 | # nChannels = None |
|
140 | 151 | |
|
141 | 152 | # nHeights = None |
|
142 | 153 | |
|
143 | 154 | nProfiles = None |
|
144 | 155 | |
|
145 | 156 | heightList = None |
|
146 | 157 | |
|
147 | 158 | channelList = None |
|
148 | 159 | |
|
149 |
flag |
|
|
160 | flagDiscontinuousBlock = False | |
|
150 | 161 | |
|
151 | 162 | useLocalTime = False |
|
152 | 163 | |
|
153 | 164 | utctime = None |
|
154 | 165 | |
|
155 | 166 | timeZone = None |
|
156 | 167 | |
|
157 | 168 | dstFlag = None |
|
158 | 169 | |
|
159 | 170 | errorCount = None |
|
160 | 171 | |
|
161 | 172 | blocksize = None |
|
162 | 173 | |
|
163 | nCode = None | |
|
164 | ||
|
165 | nBaud = None | |
|
166 | ||
|
167 | code = None | |
|
174 | # nCode = None | |
|
175 | # | |
|
176 | # nBaud = None | |
|
177 | # | |
|
178 | # code = None | |
|
168 | 179 | |
|
169 | 180 | flagDecodeData = False #asumo q la data no esta decodificada |
|
170 | 181 | |
|
171 | 182 | flagDeflipData = False #asumo q la data no esta sin flip |
|
172 | 183 | |
|
173 | 184 | flagShiftFFT = False |
|
174 | 185 | |
|
175 | 186 | # ippSeconds = None |
|
176 | 187 | |
|
177 | 188 | # timeInterval = None |
|
178 | 189 | |
|
179 | 190 | nCohInt = None |
|
180 | 191 | |
|
181 | noise = None | |
|
192 | # noise = None | |
|
182 | 193 | |
|
183 | 194 | windowOfFilter = 1 |
|
184 | 195 | |
|
185 | 196 | #Speed of ligth |
|
186 | 197 | C = 3e8 |
|
187 | 198 | |
|
188 | 199 | frequency = 49.92e6 |
|
189 | 200 | |
|
190 | 201 | realtime = False |
|
191 | 202 | |
|
192 | 203 | beacon_heiIndexList = None |
|
193 | 204 | |
|
194 | 205 | last_block = None |
|
195 | 206 | |
|
196 | 207 | blocknow = None |
|
197 | 208 | |
|
198 | 209 | azimuth = None |
|
199 | 210 | |
|
200 | 211 | zenith = None |
|
201 | 212 | |
|
202 | 213 | beam = Beam() |
|
203 | 214 | |
|
204 | 215 | profileIndex = None |
|
205 | 216 | |
|
206 | 217 | def __init__(self): |
|
207 | 218 | |
|
208 | 219 | raise ValueError, "This class has not been implemented" |
|
209 | 220 | |
|
210 | 221 | def getNoise(self): |
|
211 | 222 | |
|
212 | 223 | raise ValueError, "Not implemented" |
|
213 | 224 | |
|
214 | 225 | def getNChannels(self): |
|
215 | 226 | |
|
216 | 227 | return len(self.channelList) |
|
217 | 228 | |
|
218 | 229 | def getChannelIndexList(self): |
|
219 | 230 | |
|
220 | 231 | return range(self.nChannels) |
|
221 | 232 | |
|
222 | 233 | def getNHeights(self): |
|
223 | 234 | |
|
224 | 235 | return len(self.heightList) |
|
225 | 236 | |
|
226 | 237 | def getHeiRange(self, extrapoints=0): |
|
227 | 238 | |
|
228 | 239 | heis = self.heightList |
|
229 | 240 | # deltah = self.heightList[1] - self.heightList[0] |
|
230 | 241 | # |
|
231 | 242 | # heis.append(self.heightList[-1]) |
|
232 | 243 | |
|
233 | 244 | return heis |
|
234 | 245 | |
|
235 | 246 | def getltctime(self): |
|
236 | 247 | |
|
237 | 248 | if self.useLocalTime: |
|
238 | 249 | return self.utctime - self.timeZone*60 |
|
239 | 250 | |
|
240 | 251 | return self.utctime |
|
241 | 252 | |
|
242 | 253 | def getDatatime(self): |
|
243 | 254 | |
|
244 | 255 | datatimeValue = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
245 | 256 | return datatimeValue |
|
246 | 257 | |
|
247 | 258 | def getTimeRange(self): |
|
248 | 259 | |
|
249 | 260 | datatime = [] |
|
250 | 261 | |
|
251 | 262 | datatime.append(self.ltctime) |
|
252 | 263 | datatime.append(self.ltctime + self.timeInterval+60) |
|
253 | 264 | |
|
254 | 265 | datatime = numpy.array(datatime) |
|
255 | 266 | |
|
256 | 267 | return datatime |
|
257 | 268 | |
|
258 | 269 | def getFmax(self): |
|
259 | 270 | |
|
260 | 271 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
261 | 272 | |
|
262 | 273 | fmax = PRF/2. |
|
263 | 274 | |
|
264 | 275 | return fmax |
|
265 | 276 | |
|
266 | 277 | def getVmax(self): |
|
267 | 278 | |
|
268 | 279 | _lambda = self.C/self.frequency |
|
269 | 280 | |
|
270 | 281 | vmax = self.getFmax() * _lambda |
|
271 | 282 | |
|
272 | 283 | return vmax |
|
273 | 284 | |
|
274 | 285 | def get_ippSeconds(self): |
|
275 | 286 | ''' |
|
276 | 287 | ''' |
|
277 | 288 | return self.radarControllerHeaderObj.ippSeconds |
|
278 | 289 | |
|
279 | 290 | def set_ippSeconds(self, ippSeconds): |
|
280 | 291 | ''' |
|
281 | 292 | ''' |
|
282 | 293 | |
|
283 | 294 | self.radarControllerHeaderObj.ippSeconds = ippSeconds |
|
284 | 295 | |
|
285 | 296 | return |
|
286 | 297 | |
|
287 | 298 | def get_dtype(self): |
|
288 | 299 | ''' |
|
289 | 300 | ''' |
|
290 | 301 | return getNumpyDtype(self.datatype) |
|
291 | 302 | |
|
292 | 303 | def set_dtype(self, numpyDtype): |
|
293 | 304 | ''' |
|
294 | 305 | ''' |
|
295 | 306 | |
|
296 | 307 | self.datatype = getDataTypeCode(numpyDtype) |
|
308 | ||
|
309 | def get_code(self): | |
|
310 | ''' | |
|
311 | ''' | |
|
312 | return self.radarControllerHeaderObj.code | |
|
313 | ||
|
314 | def set_code(self, code): | |
|
315 | ''' | |
|
316 | ''' | |
|
317 | self.radarControllerHeaderObj.code = code | |
|
318 | ||
|
319 | return | |
|
320 | ||
|
321 | def get_ncode(self): | |
|
322 | ''' | |
|
323 | ''' | |
|
324 | return self.radarControllerHeaderObj.nCode | |
|
325 | ||
|
326 | def set_ncode(self, nCode): | |
|
327 | ''' | |
|
328 | ''' | |
|
329 | self.radarControllerHeaderObj.nCode = nCode | |
|
330 | ||
|
331 | return | |
|
332 | ||
|
333 | def get_nbaud(self): | |
|
334 | ''' | |
|
335 | ''' | |
|
336 | return self.radarControllerHeaderObj.nBaud | |
|
297 | 337 | |
|
338 | def set_nbaud(self, nBaud): | |
|
339 | ''' | |
|
340 | ''' | |
|
341 | self.radarControllerHeaderObj.nBaud = nBaud | |
|
342 | ||
|
343 | return | |
|
298 | 344 | # def getTimeInterval(self): |
|
299 | 345 | # |
|
300 | 346 | # raise IOError, "This method should be implemented inside each Class" |
|
301 | 347 | |
|
302 | 348 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
303 | 349 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
304 | 350 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
305 | 351 | #noise = property(getNoise, "I'm the 'nHeights' property.") |
|
306 | 352 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
307 | 353 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
308 | 354 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
309 | 355 | dtype = property(get_dtype, set_dtype) |
|
310 | 356 | # timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
357 | code = property(get_code, set_code) | |
|
358 | nCode = property(get_ncode, set_ncode) | |
|
359 | nBaud = property(get_nbaud, set_nbaud) | |
|
311 | 360 | |
|
312 | 361 | class Voltage(JROData): |
|
313 | 362 | |
|
314 | 363 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
315 | 364 | data = None |
|
316 | 365 | |
|
317 | 366 | def __init__(self): |
|
318 | 367 | ''' |
|
319 | 368 | Constructor |
|
320 | 369 | ''' |
|
321 | 370 | |
|
322 | 371 | self.useLocalTime = True |
|
323 | 372 | |
|
324 | 373 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
325 | 374 | |
|
326 | 375 | self.systemHeaderObj = SystemHeader() |
|
327 | 376 | |
|
328 | 377 | self.type = "Voltage" |
|
329 | 378 | |
|
330 | 379 | self.data = None |
|
331 | 380 | |
|
332 | 381 | # self.dtype = None |
|
333 | 382 | |
|
334 | 383 | # self.nChannels = 0 |
|
335 | 384 | |
|
336 | 385 | # self.nHeights = 0 |
|
337 | 386 | |
|
338 | 387 | self.nProfiles = None |
|
339 | 388 | |
|
340 | 389 | self.heightList = None |
|
341 | 390 | |
|
342 | 391 | self.channelList = None |
|
343 | 392 | |
|
344 | 393 | # self.channelIndexList = None |
|
345 | 394 | |
|
346 | 395 | self.flagNoData = True |
|
347 | 396 | |
|
348 |
self.flag |
|
|
397 | self.flagDiscontinuousBlock = False | |
|
349 | 398 | |
|
350 | 399 | self.utctime = None |
|
351 | 400 | |
|
352 | 401 | self.timeZone = None |
|
353 | 402 | |
|
354 | 403 | self.dstFlag = None |
|
355 | 404 | |
|
356 | 405 | self.errorCount = None |
|
357 | 406 | |
|
358 | 407 | self.nCohInt = None |
|
359 | 408 | |
|
360 | 409 | self.blocksize = None |
|
361 | 410 | |
|
362 | 411 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
363 | 412 | |
|
364 | 413 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
365 | 414 | |
|
366 | 415 | self.flagShiftFFT = False |
|
367 | 416 | |
|
368 | 417 | self.flagDataAsBlock = False #Asumo que la data es leida perfil a perfil |
|
369 | ||
|
418 | ||
|
370 | 419 | self.profileIndex = 0 |
|
371 | 420 | |
|
372 | def getNoisebyHildebrand(self): | |
|
421 | def getNoisebyHildebrand(self, channel = None): | |
|
373 | 422 | """ |
|
374 | 423 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
375 | 424 | |
|
376 | 425 | Return: |
|
377 | 426 | noiselevel |
|
378 | 427 | """ |
|
379 | 428 | |
|
380 |
f |
|
|
381 |
da |
|
|
382 | self.noise[channel] = hildebrand_sekhon(daux, self.nCohInt) | |
|
429 | if channel != None: | |
|
430 | data = self.data[channel] | |
|
431 | nChannels = 1 | |
|
432 | else: | |
|
433 | data = self.data | |
|
434 | nChannels = self.nChannels | |
|
435 | ||
|
436 | noise = numpy.zeros(nChannels) | |
|
437 | power = data * numpy.conjugate(data) | |
|
383 | 438 | |
|
384 | return self.noise | |
|
385 | ||
|
386 | def getNoise(self, type = 1): | |
|
439 | for thisChannel in range(nChannels): | |
|
440 | if nChannels == 1: | |
|
441 | daux = power[:].real | |
|
442 | else: | |
|
443 | daux = power[thisChannel,:].real | |
|
444 | noise[thisChannel] = hildebrand_sekhon(daux, self.nCohInt) | |
|
387 | 445 | |
|
388 | self.noise = numpy.zeros(self.nChannels) | |
|
446 | return noise | |
|
447 | ||
|
448 | def getNoise(self, type = 1, channel = None): | |
|
389 | 449 | |
|
390 | 450 | if type == 1: |
|
391 | noise = self.getNoisebyHildebrand() | |
|
451 | noise = self.getNoisebyHildebrand(channel) | |
|
392 | 452 | |
|
393 | 453 | return 10*numpy.log10(noise) |
|
394 | 454 | |
|
455 | def getPower(self, channel = None): | |
|
456 | ||
|
457 | if channel != None: | |
|
458 | data = self.data[channel] | |
|
459 | else: | |
|
460 | data = self.data | |
|
461 | ||
|
462 | power = data * numpy.conjugate(data) | |
|
463 | ||
|
464 | return 10*numpy.log10(power.real) | |
|
465 | ||
|
395 | 466 | def getTimeInterval(self): |
|
396 | 467 | |
|
397 | 468 | timeInterval = self.ippSeconds * self.nCohInt |
|
398 | 469 | |
|
399 | 470 | return timeInterval |
|
400 | 471 | |
|
401 | 472 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
402 | 473 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
403 | 474 | |
|
404 | 475 | class Spectra(JROData): |
|
405 | 476 | |
|
406 | 477 | #data es un numpy array de 2 dmensiones (canales, perfiles, alturas) |
|
407 | 478 | data_spc = None |
|
408 | 479 | |
|
409 | 480 | #data es un numpy array de 2 dmensiones (canales, pares, alturas) |
|
410 | 481 | data_cspc = None |
|
411 | 482 | |
|
412 | 483 | #data es un numpy array de 2 dmensiones (canales, alturas) |
|
413 | 484 | data_dc = None |
|
414 | 485 | |
|
415 | 486 | nFFTPoints = None |
|
416 | 487 | |
|
417 | 488 | # nPairs = None |
|
418 | 489 | |
|
419 | 490 | pairsList = None |
|
420 | 491 | |
|
421 | 492 | nIncohInt = None |
|
422 | 493 | |
|
423 | 494 | wavelength = None #Necesario para cacular el rango de velocidad desde la frecuencia |
|
424 | 495 | |
|
425 | 496 | nCohInt = None #se requiere para determinar el valor de timeInterval |
|
426 | 497 | |
|
427 | 498 | ippFactor = None |
|
428 | 499 | |
|
429 | 500 | profileIndex = 0 |
|
430 | 501 | |
|
431 | 502 | def __init__(self): |
|
432 | 503 | ''' |
|
433 | 504 | Constructor |
|
434 | 505 | ''' |
|
435 | 506 | |
|
436 | 507 | self.useLocalTime = True |
|
437 | 508 | |
|
438 | 509 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
439 | 510 | |
|
440 | 511 | self.systemHeaderObj = SystemHeader() |
|
441 | 512 | |
|
442 | 513 | self.type = "Spectra" |
|
443 | 514 | |
|
444 | 515 | # self.data = None |
|
445 | 516 | |
|
446 | 517 | # self.dtype = None |
|
447 | 518 | |
|
448 | 519 | # self.nChannels = 0 |
|
449 | 520 | |
|
450 | 521 | # self.nHeights = 0 |
|
451 | 522 | |
|
452 | 523 | self.nProfiles = None |
|
453 | 524 | |
|
454 | 525 | self.heightList = None |
|
455 | 526 | |
|
456 | 527 | self.channelList = None |
|
457 | 528 | |
|
458 | 529 | # self.channelIndexList = None |
|
459 | 530 | |
|
460 | 531 | self.pairsList = None |
|
461 | 532 | |
|
462 | 533 | self.flagNoData = True |
|
463 | 534 | |
|
464 |
self.flag |
|
|
535 | self.flagDiscontinuousBlock = False | |
|
465 | 536 | |
|
466 | 537 | self.utctime = None |
|
467 | 538 | |
|
468 | 539 | self.nCohInt = None |
|
469 | 540 | |
|
470 | 541 | self.nIncohInt = None |
|
471 | 542 | |
|
472 | 543 | self.blocksize = None |
|
473 | 544 | |
|
474 | 545 | self.nFFTPoints = None |
|
475 | 546 | |
|
476 | 547 | self.wavelength = None |
|
477 | 548 | |
|
478 | 549 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
479 | 550 | |
|
480 | 551 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
481 | 552 | |
|
482 | 553 | self.flagShiftFFT = False |
|
483 | 554 | |
|
484 | 555 | self.ippFactor = 1 |
|
485 | 556 | |
|
486 | 557 | #self.noise = None |
|
487 | 558 | |
|
488 | 559 | self.beacon_heiIndexList = [] |
|
489 | 560 | |
|
490 | 561 | self.noise_estimation = None |
|
491 | 562 | |
|
492 | 563 | |
|
493 | def getNoisebyHildebrand(self): | |
|
564 | def getNoisebyHildebrand(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
|
494 | 565 | """ |
|
495 | 566 | Determino el nivel de ruido usando el metodo Hildebrand-Sekhon |
|
496 | 567 | |
|
497 | 568 | Return: |
|
498 | 569 | noiselevel |
|
499 | 570 | """ |
|
500 | 571 | |
|
501 | 572 | noise = numpy.zeros(self.nChannels) |
|
573 | ||
|
502 | 574 | for channel in range(self.nChannels): |
|
503 | daux = self.data_spc[channel,:,:] | |
|
575 | daux = self.data_spc[channel,xmin_index:xmax_index,ymin_index:ymax_index] | |
|
504 | 576 | noise[channel] = hildebrand_sekhon(daux, self.nIncohInt) |
|
505 | 577 | |
|
506 | 578 | return noise |
|
507 | 579 | |
|
508 | def getNoise(self): | |
|
580 | def getNoise(self, xmin_index=None, xmax_index=None, ymin_index=None, ymax_index=None): | |
|
581 | ||
|
509 | 582 | if self.noise_estimation != None: |
|
510 | 583 | return self.noise_estimation #this was estimated by getNoise Operation defined in jroproc_spectra.py |
|
511 | 584 | else: |
|
512 | noise = self.getNoisebyHildebrand() | |
|
585 | noise = self.getNoisebyHildebrand(xmin_index, xmax_index, ymin_index, ymax_index) | |
|
513 | 586 | return noise |
|
514 | 587 | |
|
515 | 588 | |
|
516 | 589 | def getFreqRange(self, extrapoints=0): |
|
517 | 590 | |
|
518 | 591 | deltafreq = self.getFmax() / (self.nFFTPoints*self.ippFactor) |
|
519 | 592 | freqrange = deltafreq*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltafreq/2 |
|
520 | 593 | |
|
521 | 594 | return freqrange |
|
522 | 595 | |
|
523 | 596 | def getVelRange(self, extrapoints=0): |
|
524 | 597 | |
|
525 | 598 | deltav = self.getVmax() / (self.nFFTPoints*self.ippFactor) |
|
526 | 599 | velrange = deltav*(numpy.arange(self.nFFTPoints+extrapoints)-self.nFFTPoints/2.) - deltav/2 |
|
527 | 600 | |
|
528 | 601 | return velrange |
|
529 | 602 | |
|
530 | 603 | def getNPairs(self): |
|
531 | 604 | |
|
532 | 605 | return len(self.pairsList) |
|
533 | 606 | |
|
534 | 607 | def getPairsIndexList(self): |
|
535 | 608 | |
|
536 | 609 | return range(self.nPairs) |
|
537 | 610 | |
|
538 | 611 | def getNormFactor(self): |
|
539 | 612 | pwcode = 1 |
|
540 | 613 | if self.flagDecodeData: |
|
541 | 614 | pwcode = numpy.sum(self.code[0]**2) |
|
542 | 615 | #normFactor = min(self.nFFTPoints,self.nProfiles)*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
543 | 616 | normFactor = self.nProfiles*self.nIncohInt*self.nCohInt*pwcode*self.windowOfFilter |
|
544 | 617 | |
|
545 | 618 | return normFactor |
|
546 | 619 | |
|
547 | 620 | def getFlagCspc(self): |
|
548 | 621 | |
|
549 | 622 | if self.data_cspc == None: |
|
550 | 623 | return True |
|
551 | 624 | |
|
552 | 625 | return False |
|
553 | 626 | |
|
554 | 627 | def getFlagDc(self): |
|
555 | 628 | |
|
556 | 629 | if self.data_dc == None: |
|
557 | 630 | return True |
|
558 | 631 | |
|
559 | 632 | return False |
|
560 | 633 | |
|
561 | 634 | def getTimeInterval(self): |
|
562 | 635 | |
|
563 | 636 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt * self.nProfiles |
|
564 | 637 | |
|
565 | 638 | return timeInterval |
|
566 | 639 | |
|
567 | 640 | nPairs = property(getNPairs, "I'm the 'nPairs' property.") |
|
568 | 641 | pairsIndexList = property(getPairsIndexList, "I'm the 'pairsIndexList' property.") |
|
569 | 642 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
570 | 643 | flag_cspc = property(getFlagCspc) |
|
571 | 644 | flag_dc = property(getFlagDc) |
|
572 | 645 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
573 | 646 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
574 | 647 | |
|
575 | 648 | class SpectraHeis(Spectra): |
|
576 | 649 | |
|
577 | 650 | data_spc = None |
|
578 | 651 | |
|
579 | 652 | data_cspc = None |
|
580 | 653 | |
|
581 | 654 | data_dc = None |
|
582 | 655 | |
|
583 | 656 | nFFTPoints = None |
|
584 | 657 | |
|
585 | 658 | # nPairs = None |
|
586 | 659 | |
|
587 | 660 | pairsList = None |
|
588 | 661 | |
|
589 | 662 | nIncohInt = None |
|
590 | 663 | |
|
591 | 664 | def __init__(self): |
|
592 | 665 | |
|
593 | 666 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
594 | 667 | |
|
595 | 668 | self.systemHeaderObj = SystemHeader() |
|
596 | 669 | |
|
597 | 670 | self.type = "SpectraHeis" |
|
598 | 671 | |
|
599 | 672 | # self.dtype = None |
|
600 | 673 | |
|
601 | 674 | # self.nChannels = 0 |
|
602 | 675 | |
|
603 | 676 | # self.nHeights = 0 |
|
604 | 677 | |
|
605 | 678 | self.nProfiles = None |
|
606 | 679 | |
|
607 | 680 | self.heightList = None |
|
608 | 681 | |
|
609 | 682 | self.channelList = None |
|
610 | 683 | |
|
611 | 684 | # self.channelIndexList = None |
|
612 | 685 | |
|
613 | 686 | self.flagNoData = True |
|
614 | 687 | |
|
615 |
self.flag |
|
|
688 | self.flagDiscontinuousBlock = False | |
|
616 | 689 | |
|
617 | 690 | # self.nPairs = 0 |
|
618 | 691 | |
|
619 | 692 | self.utctime = None |
|
620 | 693 | |
|
621 | 694 | self.blocksize = None |
|
622 | 695 | |
|
623 | 696 | self.profileIndex = 0 |
|
624 | 697 | |
|
625 | 698 | def getNormFactor(self): |
|
626 | 699 | pwcode = 1 |
|
627 | 700 | if self.flagDecodeData: |
|
628 | 701 | pwcode = numpy.sum(self.code[0]**2) |
|
629 | 702 | |
|
630 | 703 | normFactor = self.nIncohInt*self.nCohInt*pwcode |
|
631 | 704 | |
|
632 | 705 | return normFactor |
|
633 | 706 | |
|
634 | 707 | def getTimeInterval(self): |
|
635 | 708 | |
|
636 | 709 | timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
637 | 710 | |
|
638 | 711 | return timeInterval |
|
639 | 712 | |
|
640 | 713 | normFactor = property(getNormFactor, "I'm the 'getNormFactor' property.") |
|
641 | 714 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
642 | 715 | |
|
643 | 716 | class Fits: |
|
644 | 717 | |
|
645 | 718 | heightList = None |
|
646 | 719 | |
|
647 | 720 | channelList = None |
|
648 | 721 | |
|
649 | 722 | flagNoData = True |
|
650 | 723 | |
|
651 |
flag |
|
|
724 | flagDiscontinuousBlock = False | |
|
652 | 725 | |
|
653 | 726 | useLocalTime = False |
|
654 | 727 | |
|
655 | 728 | utctime = None |
|
656 | 729 | |
|
657 | 730 | timeZone = None |
|
658 | 731 | |
|
659 | 732 | # ippSeconds = None |
|
660 | 733 | |
|
661 | 734 | # timeInterval = None |
|
662 | 735 | |
|
663 | 736 | nCohInt = None |
|
664 | 737 | |
|
665 | 738 | nIncohInt = None |
|
666 | 739 | |
|
667 | 740 | noise = None |
|
668 | 741 | |
|
669 | 742 | windowOfFilter = 1 |
|
670 | 743 | |
|
671 | 744 | #Speed of ligth |
|
672 | 745 | C = 3e8 |
|
673 | 746 | |
|
674 | 747 | frequency = 49.92e6 |
|
675 | 748 | |
|
676 | 749 | realtime = False |
|
677 | 750 | |
|
678 | 751 | |
|
679 | 752 | def __init__(self): |
|
680 | 753 | |
|
681 | 754 | self.type = "Fits" |
|
682 | 755 | |
|
683 | 756 | self.nProfiles = None |
|
684 | 757 | |
|
685 | 758 | self.heightList = None |
|
686 | 759 | |
|
687 | 760 | self.channelList = None |
|
688 | 761 | |
|
689 | 762 | # self.channelIndexList = None |
|
690 | 763 | |
|
691 | 764 | self.flagNoData = True |
|
692 | 765 | |
|
693 | 766 | self.utctime = None |
|
694 | 767 | |
|
695 | 768 | self.nCohInt = None |
|
696 | 769 | |
|
697 | 770 | self.nIncohInt = None |
|
698 | 771 | |
|
699 | 772 | self.useLocalTime = True |
|
700 | 773 | |
|
701 | 774 | self.profileIndex = 0 |
|
702 | 775 | |
|
703 | 776 | # self.utctime = None |
|
704 | 777 | # self.timeZone = None |
|
705 | 778 | # self.ltctime = None |
|
706 | 779 | # self.timeInterval = None |
|
707 | 780 | # self.header = None |
|
708 | 781 | # self.data_header = None |
|
709 | 782 | # self.data = None |
|
710 | 783 | # self.datatime = None |
|
711 | 784 | # self.flagNoData = False |
|
712 | 785 | # self.expName = '' |
|
713 | 786 | # self.nChannels = None |
|
714 | 787 | # self.nSamples = None |
|
715 | 788 | # self.dataBlocksPerFile = None |
|
716 | 789 | # self.comments = '' |
|
717 | 790 | # |
|
718 | 791 | |
|
719 | 792 | |
|
720 | 793 | def getltctime(self): |
|
721 | 794 | |
|
722 | 795 | if self.useLocalTime: |
|
723 | 796 | return self.utctime - self.timeZone*60 |
|
724 | 797 | |
|
725 | 798 | return self.utctime |
|
726 | 799 | |
|
727 | 800 | def getDatatime(self): |
|
728 | 801 | |
|
729 | 802 | datatime = datetime.datetime.utcfromtimestamp(self.ltctime) |
|
730 | 803 | return datatime |
|
731 | 804 | |
|
732 | 805 | def getTimeRange(self): |
|
733 | 806 | |
|
734 | 807 | datatime = [] |
|
735 | 808 | |
|
736 | 809 | datatime.append(self.ltctime) |
|
737 | 810 | datatime.append(self.ltctime + self.timeInterval) |
|
738 | 811 | |
|
739 | 812 | datatime = numpy.array(datatime) |
|
740 | 813 | |
|
741 | 814 | return datatime |
|
742 | 815 | |
|
743 | 816 | def getHeiRange(self): |
|
744 | 817 | |
|
745 | 818 | heis = self.heightList |
|
746 | 819 | |
|
747 | 820 | return heis |
|
748 | 821 | |
|
749 | 822 | def isEmpty(self): |
|
750 | 823 | |
|
751 | 824 | return self.flagNoData |
|
752 | 825 | |
|
753 | 826 | def getNHeights(self): |
|
754 | 827 | |
|
755 | 828 | return len(self.heightList) |
|
756 | 829 | |
|
757 | 830 | def getNChannels(self): |
|
758 | 831 | |
|
759 | 832 | return len(self.channelList) |
|
760 | 833 | |
|
761 | 834 | def getChannelIndexList(self): |
|
762 | 835 | |
|
763 | 836 | return range(self.nChannels) |
|
764 | 837 | |
|
765 | 838 | def getNoise(self, type = 1): |
|
766 | 839 | |
|
767 |
|
|
|
840 | #noise = numpy.zeros(self.nChannels) | |
|
768 | 841 | |
|
769 | 842 | if type == 1: |
|
770 | 843 | noise = self.getNoisebyHildebrand() |
|
771 | 844 | |
|
772 | 845 | if type == 2: |
|
773 | 846 | noise = self.getNoisebySort() |
|
774 | 847 | |
|
775 | 848 | if type == 3: |
|
776 | 849 | noise = self.getNoisebyWindow() |
|
777 | 850 | |
|
778 | 851 | return noise |
|
779 | 852 | |
|
780 | 853 | def getTimeInterval(self): |
|
781 | 854 | |
|
782 | 855 | raise ValueError, "This method is not implemented yet" |
|
783 | 856 | |
|
784 | 857 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
785 | 858 | nHeights = property(getNHeights, "I'm the 'nHeights' property.") |
|
786 | 859 | nChannels = property(getNChannels, "I'm the 'nChannel' property.") |
|
787 | 860 | channelIndexList = property(getChannelIndexList, "I'm the 'channelIndexList' property.") |
|
788 | 861 | noise = property(getNoise, "I'm the 'nHeights' property.") |
|
789 | 862 | datatime = property(getDatatime, "I'm the 'datatime' property") |
|
790 | 863 | ltctime = property(getltctime, "I'm the 'ltctime' property") |
|
791 | 864 | timeInterval = property(getTimeInterval, "I'm the 'timeInterval' property") |
|
792 | 865 | |
|
793 | 866 | class Correlation(JROData): |
|
794 | 867 | |
|
795 | 868 | noise = None |
|
796 | 869 | |
|
797 | 870 | SNR = None |
|
798 | 871 | |
|
799 | 872 | pairsAutoCorr = None #Pairs of Autocorrelation |
|
800 | 873 | |
|
801 | 874 | #-------------------------------------------------- |
|
802 | 875 | |
|
803 | 876 | data_corr = None |
|
804 | 877 | |
|
805 | 878 | data_volt = None |
|
806 | 879 | |
|
807 | 880 | lagT = None # each element value is a profileIndex |
|
808 | 881 | |
|
809 | 882 | lagR = None # each element value is in km |
|
810 | 883 | |
|
811 | 884 | pairsList = None |
|
812 | 885 | |
|
813 | 886 | calculateVelocity = None |
|
814 | 887 | |
|
815 | 888 | nPoints = None |
|
816 | 889 | |
|
817 | 890 | nAvg = None |
|
818 | 891 | |
|
819 | 892 | bufferSize = None |
|
820 | 893 | |
|
821 | 894 | def __init__(self): |
|
822 | 895 | ''' |
|
823 | 896 | Constructor |
|
824 | 897 | ''' |
|
825 | 898 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
826 | 899 | |
|
827 | 900 | self.systemHeaderObj = SystemHeader() |
|
828 | 901 | |
|
829 | 902 | self.type = "Correlation" |
|
830 | 903 | |
|
831 | 904 | self.data = None |
|
832 | 905 | |
|
833 | 906 | self.dtype = None |
|
834 | 907 | |
|
835 | 908 | self.nProfiles = None |
|
836 | 909 | |
|
837 | 910 | self.heightList = None |
|
838 | 911 | |
|
839 | 912 | self.channelList = None |
|
840 | 913 | |
|
841 | 914 | self.flagNoData = True |
|
842 | 915 | |
|
843 |
self.flag |
|
|
916 | self.flagDiscontinuousBlock = False | |
|
844 | 917 | |
|
845 | 918 | self.utctime = None |
|
846 | 919 | |
|
847 | 920 | self.timeZone = None |
|
848 | 921 | |
|
849 | 922 | self.dstFlag = None |
|
850 | 923 | |
|
851 | 924 | self.errorCount = None |
|
852 | 925 | |
|
853 | 926 | self.blocksize = None |
|
854 | 927 | |
|
855 | 928 | self.flagDecodeData = False #asumo q la data no esta decodificada |
|
856 | 929 | |
|
857 | 930 | self.flagDeflipData = False #asumo q la data no esta sin flip |
|
858 | 931 | |
|
859 | 932 | self.pairsList = None |
|
860 | 933 | |
|
861 | 934 | self.nPoints = None |
|
862 | 935 | |
|
863 | 936 | def getLagTRange(self, extrapoints=0): |
|
864 | 937 | |
|
865 | 938 | lagTRange = self.lagT |
|
866 | 939 | diff = lagTRange[1] - lagTRange[0] |
|
867 | 940 | extra = numpy.arange(1,extrapoints + 1)*diff + lagTRange[-1] |
|
868 | 941 | lagTRange = numpy.hstack((lagTRange, extra)) |
|
869 | 942 | |
|
870 | 943 | return lagTRange |
|
871 | 944 | |
|
872 | 945 | def getLagRRange(self, extrapoints=0): |
|
873 | 946 | |
|
874 | 947 | return self.lagR |
|
875 | 948 | |
|
876 | 949 | def getPairsList(self): |
|
877 | 950 | |
|
878 | 951 | return self.pairsList |
|
879 | 952 | |
|
880 | 953 | def getCalculateVelocity(self): |
|
881 | 954 | |
|
882 | 955 | return self.calculateVelocity |
|
883 | 956 | |
|
884 | 957 | def getNPoints(self): |
|
885 | 958 | |
|
886 | 959 | return self.nPoints |
|
887 | 960 | |
|
888 | 961 | def getNAvg(self): |
|
889 | 962 | |
|
890 | 963 | return self.nAvg |
|
891 | 964 | |
|
892 | 965 | def getBufferSize(self): |
|
893 | 966 | |
|
894 | 967 | return self.bufferSize |
|
895 | 968 | |
|
896 | 969 | def getPairsAutoCorr(self): |
|
897 | 970 | pairsList = self.pairsList |
|
898 | 971 | pairsAutoCorr = numpy.zeros(self.nChannels, dtype = 'int')*numpy.nan |
|
899 | 972 | |
|
900 | 973 | for l in range(len(pairsList)): |
|
901 | 974 | firstChannel = pairsList[l][0] |
|
902 | 975 | secondChannel = pairsList[l][1] |
|
903 | 976 | |
|
904 | 977 | #Obteniendo pares de Autocorrelacion |
|
905 | 978 | if firstChannel == secondChannel: |
|
906 | 979 | pairsAutoCorr[firstChannel] = int(l) |
|
907 | 980 | |
|
908 | 981 | pairsAutoCorr = pairsAutoCorr.astype(int) |
|
909 | 982 | |
|
910 | 983 | return pairsAutoCorr |
|
911 | 984 | |
|
912 | 985 | def getNoise(self, mode = 2): |
|
913 | 986 | |
|
914 | 987 | indR = numpy.where(self.lagR == 0)[0][0] |
|
915 | 988 | indT = numpy.where(self.lagT == 0)[0][0] |
|
916 | 989 | |
|
917 | 990 | jspectra0 = self.data_corr[:,:,indR,:] |
|
918 | 991 | jspectra = copy.copy(jspectra0) |
|
919 | 992 | |
|
920 | 993 | num_chan = jspectra.shape[0] |
|
921 | 994 | num_hei = jspectra.shape[2] |
|
922 | 995 | |
|
923 | 996 | freq_dc = jspectra.shape[1]/2 |
|
924 | 997 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
925 | 998 | |
|
926 | 999 | if ind_vel[0]<0: |
|
927 | 1000 | ind_vel[range(0,1)] = ind_vel[range(0,1)] + self.num_prof |
|
928 | 1001 | |
|
929 | 1002 | if mode == 1: |
|
930 | 1003 | jspectra[:,freq_dc,:] = (jspectra[:,ind_vel[1],:] + jspectra[:,ind_vel[2],:])/2 #CORRECCION |
|
931 | 1004 | |
|
932 | 1005 | if mode == 2: |
|
933 | 1006 | |
|
934 | 1007 | vel = numpy.array([-2,-1,1,2]) |
|
935 | 1008 | xx = numpy.zeros([4,4]) |
|
936 | 1009 | |
|
937 | 1010 | for fil in range(4): |
|
938 | 1011 | xx[fil,:] = vel[fil]**numpy.asarray(range(4)) |
|
939 | 1012 | |
|
940 | 1013 | xx_inv = numpy.linalg.inv(xx) |
|
941 | 1014 | xx_aux = xx_inv[0,:] |
|
942 | 1015 | |
|
943 | 1016 | for ich in range(num_chan): |
|
944 | 1017 | yy = jspectra[ich,ind_vel,:] |
|
945 | 1018 | jspectra[ich,freq_dc,:] = numpy.dot(xx_aux,yy) |
|
946 | 1019 | |
|
947 | 1020 | junkid = jspectra[ich,freq_dc,:]<=0 |
|
948 | 1021 | cjunkid = sum(junkid) |
|
949 | 1022 | |
|
950 | 1023 | if cjunkid.any(): |
|
951 | 1024 | jspectra[ich,freq_dc,junkid.nonzero()] = (jspectra[ich,ind_vel[1],junkid] + jspectra[ich,ind_vel[2],junkid])/2 |
|
952 | 1025 | |
|
953 | 1026 | noise = jspectra0[:,freq_dc,:] - jspectra[:,freq_dc,:] |
|
954 | 1027 | |
|
955 | 1028 | return noise |
|
956 | 1029 | |
|
957 | 1030 | # pairsList = property(getPairsList, "I'm the 'pairsList' property.") |
|
958 | 1031 | # nPoints = property(getNPoints, "I'm the 'nPoints' property.") |
|
959 | 1032 | calculateVelocity = property(getCalculateVelocity, "I'm the 'calculateVelocity' property.") |
|
960 | 1033 | nAvg = property(getNAvg, "I'm the 'nAvg' property.") |
|
961 | 1034 | bufferSize = property(getBufferSize, "I'm the 'bufferSize' property.") |
|
962 | 1035 | |
|
963 | 1036 | |
|
964 | 1037 | class Parameters(JROData): |
|
965 | 1038 | |
|
966 | 1039 | #Information from previous data |
|
967 | 1040 | |
|
968 | 1041 | inputUnit = None #Type of data to be processed |
|
969 | 1042 | |
|
970 | 1043 | operation = None #Type of operation to parametrize |
|
971 | 1044 | |
|
972 | 1045 | normFactor = None #Normalization Factor |
|
973 | 1046 | |
|
974 | 1047 | groupList = None #List of Pairs, Groups, etc |
|
975 | 1048 | |
|
976 | 1049 | #Parameters |
|
977 | 1050 | |
|
978 | 1051 | data_param = None #Parameters obtained |
|
979 | 1052 | |
|
980 | 1053 | data_pre = None #Data Pre Parametrization |
|
981 | 1054 | |
|
982 | 1055 | data_SNR = None #Signal to Noise Ratio |
|
983 | 1056 | |
|
984 | 1057 | heightRange = None #Heights |
|
985 | 1058 | |
|
986 | 1059 | abscissaRange = None #Abscissa, can be velocities, lags or time |
|
987 | 1060 | |
|
988 | 1061 | noise = None #Noise Potency |
|
989 | 1062 | |
|
990 |
|
|
|
1063 | initUtcTime = None #Initial UTC time | |
|
991 | 1064 | |
|
992 | 1065 | paramInterval = None #Time interval to calculate Parameters in seconds |
|
993 | 1066 | |
|
994 | 1067 | #Fitting |
|
995 | 1068 | |
|
996 | 1069 | data_error = None #Error of the estimation |
|
997 | 1070 | |
|
998 | 1071 | constants = None |
|
999 | 1072 | |
|
1000 | 1073 | library = None |
|
1001 | 1074 | |
|
1002 | 1075 | #Output signal |
|
1003 | 1076 | |
|
1004 | 1077 | outputInterval = None #Time interval to calculate output signal in seconds |
|
1005 | 1078 | |
|
1006 | 1079 | data_output = None #Out signal |
|
1007 | 1080 | |
|
1008 | 1081 | |
|
1009 | 1082 | |
|
1010 | 1083 | def __init__(self): |
|
1011 | 1084 | ''' |
|
1012 | 1085 | Constructor |
|
1013 | 1086 | ''' |
|
1014 | 1087 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
1015 | 1088 | |
|
1016 | 1089 | self.systemHeaderObj = SystemHeader() |
|
1017 | 1090 | |
|
1018 | 1091 | self.type = "Parameters" |
|
1019 | 1092 | |
|
1020 | 1093 | def getTimeRange1(self): |
|
1021 | 1094 | |
|
1022 | 1095 | datatime = [] |
|
1023 | 1096 | |
|
1024 |
datatime.append(self. |
|
|
1025 |
datatime.append(self. |
|
|
1097 | datatime.append(self.initUtcTime) | |
|
1098 | datatime.append(self.initUtcTime + self.outputInterval - 1) | |
|
1026 | 1099 | |
|
1027 | 1100 | datatime = numpy.array(datatime) |
|
1028 | 1101 | |
|
1029 | 1102 | return datatime |
@@ -1,605 +1,616 | |||
|
1 | 1 | ''' |
|
2 | 2 | |
|
3 | 3 | $Author: murco $ |
|
4 | 4 | $Id: JROHeaderIO.py 151 2012-10-31 19:00:51Z murco $ |
|
5 | 5 | ''' |
|
6 | 6 | import numpy |
|
7 | 7 | import copy |
|
8 | 8 | import datetime |
|
9 | 9 | |
|
10 | 10 | BASIC_STRUCTURE = numpy.dtype([ |
|
11 | 11 | ('nSize','<u4'), |
|
12 | 12 | ('nVersion','<u2'), |
|
13 | 13 | ('nDataBlockId','<u4'), |
|
14 | 14 | ('nUtime','<u4'), |
|
15 | 15 | ('nMilsec','<u2'), |
|
16 | 16 | ('nTimezone','<i2'), |
|
17 | 17 | ('nDstflag','<i2'), |
|
18 | 18 | ('nErrorCount','<u4') |
|
19 | 19 | ]) |
|
20 | 20 | |
|
21 | 21 | SYSTEM_STRUCTURE = numpy.dtype([ |
|
22 | 22 | ('nSize','<u4'), |
|
23 | 23 | ('nNumSamples','<u4'), |
|
24 | 24 | ('nNumProfiles','<u4'), |
|
25 | 25 | ('nNumChannels','<u4'), |
|
26 | 26 | ('nADCResolution','<u4'), |
|
27 | 27 | ('nPCDIOBusWidth','<u4'), |
|
28 | 28 | ]) |
|
29 | 29 | |
|
30 | 30 | RADAR_STRUCTURE = numpy.dtype([ |
|
31 | 31 | ('nSize','<u4'), |
|
32 | 32 | ('nExpType','<u4'), |
|
33 | 33 | ('nNTx','<u4'), |
|
34 | 34 | ('fIpp','<f4'), |
|
35 | 35 | ('fTxA','<f4'), |
|
36 | 36 | ('fTxB','<f4'), |
|
37 | 37 | ('nNumWindows','<u4'), |
|
38 | 38 | ('nNumTaus','<u4'), |
|
39 | 39 | ('nCodeType','<u4'), |
|
40 | 40 | ('nLine6Function','<u4'), |
|
41 | 41 | ('nLine5Function','<u4'), |
|
42 | 42 | ('fClock','<f4'), |
|
43 | 43 | ('nPrePulseBefore','<u4'), |
|
44 | 44 | ('nPrePulseAfter','<u4'), |
|
45 | 45 | ('sRangeIPP','<a20'), |
|
46 | 46 | ('sRangeTxA','<a20'), |
|
47 | 47 | ('sRangeTxB','<a20'), |
|
48 | 48 | ]) |
|
49 | 49 | |
|
50 | 50 | SAMPLING_STRUCTURE = numpy.dtype([('h0','<f4'),('dh','<f4'),('nsa','<u4')]) |
|
51 | 51 | |
|
52 | 52 | |
|
53 | 53 | PROCESSING_STRUCTURE = numpy.dtype([ |
|
54 | 54 | ('nSize','<u4'), |
|
55 | 55 | ('nDataType','<u4'), |
|
56 | 56 | ('nSizeOfDataBlock','<u4'), |
|
57 | 57 | ('nProfilesperBlock','<u4'), |
|
58 | 58 | ('nDataBlocksperFile','<u4'), |
|
59 | 59 | ('nNumWindows','<u4'), |
|
60 | 60 | ('nProcessFlags','<u4'), |
|
61 | 61 | ('nCoherentIntegrations','<u4'), |
|
62 | 62 | ('nIncoherentIntegrations','<u4'), |
|
63 | 63 | ('nTotalSpectra','<u4') |
|
64 | 64 | ]) |
|
65 | 65 | |
|
66 | 66 | class Header(object): |
|
67 | 67 | |
|
68 | 68 | def __init__(self): |
|
69 | 69 | raise |
|
70 | 70 | |
|
71 | 71 | def copy(self): |
|
72 | 72 | return copy.deepcopy(self) |
|
73 | 73 | |
|
74 | 74 | def read(self): |
|
75 | 75 | |
|
76 | 76 | raise ValueError |
|
77 | 77 | |
|
78 | 78 | def write(self): |
|
79 | 79 | |
|
80 | 80 | raise ValueError |
|
81 | 81 | |
|
82 | 82 | def printInfo(self): |
|
83 | 83 | |
|
84 | 84 | print "#"*100 |
|
85 | 85 | print self.__class__.__name__.upper() |
|
86 | 86 | print "#"*100 |
|
87 | 87 | for key in self.__dict__.keys(): |
|
88 | 88 | print "%s = %s" %(key, self.__dict__[key]) |
|
89 | ||
|
89 | ||
|
90 | 90 | class BasicHeader(Header): |
|
91 | 91 | |
|
92 | 92 | size = None |
|
93 | 93 | version = None |
|
94 | 94 | dataBlock = None |
|
95 | 95 | utc = None |
|
96 | 96 | ltc = None |
|
97 | 97 | miliSecond = None |
|
98 | 98 | timeZone = None |
|
99 | 99 | dstFlag = None |
|
100 | 100 | errorCount = None |
|
101 | 101 | datatime = None |
|
102 | 102 | |
|
103 | 103 | __LOCALTIME = None |
|
104 | 104 | |
|
105 | 105 | def __init__(self, useLocalTime=True): |
|
106 | 106 | |
|
107 | 107 | self.size = 24 |
|
108 | 108 | self.version = 0 |
|
109 | 109 | self.dataBlock = 0 |
|
110 | 110 | self.utc = 0 |
|
111 | 111 | self.miliSecond = 0 |
|
112 | 112 | self.timeZone = 0 |
|
113 | 113 | self.dstFlag = 0 |
|
114 | 114 | self.errorCount = 0 |
|
115 | 115 | |
|
116 | 116 | self.useLocalTime = useLocalTime |
|
117 | 117 | |
|
118 | 118 | def read(self, fp): |
|
119 | 119 | try: |
|
120 | 120 | |
|
121 | 121 | header = numpy.fromfile(fp, BASIC_STRUCTURE,1) |
|
122 | 122 | |
|
123 | 123 | self.size = int(header['nSize'][0]) |
|
124 | 124 | self.version = int(header['nVersion'][0]) |
|
125 | 125 | self.dataBlock = int(header['nDataBlockId'][0]) |
|
126 | 126 | self.utc = int(header['nUtime'][0]) |
|
127 | 127 | self.miliSecond = int(header['nMilsec'][0]) |
|
128 | 128 | self.timeZone = int(header['nTimezone'][0]) |
|
129 | 129 | self.dstFlag = int(header['nDstflag'][0]) |
|
130 | 130 | self.errorCount = int(header['nErrorCount'][0]) |
|
131 | 131 | |
|
132 | 132 | except Exception, e: |
|
133 | 133 | print "BasicHeader: " |
|
134 | 134 | print e |
|
135 | 135 | return 0 |
|
136 | 136 | |
|
137 | 137 | return 1 |
|
138 | 138 | |
|
139 | 139 | def write(self, fp): |
|
140 | 140 | |
|
141 | 141 | headerTuple = (self.size,self.version,self.dataBlock,self.utc,self.miliSecond,self.timeZone,self.dstFlag,self.errorCount) |
|
142 | 142 | header = numpy.array(headerTuple, BASIC_STRUCTURE) |
|
143 | 143 | header.tofile(fp) |
|
144 | 144 | |
|
145 | 145 | return 1 |
|
146 | 146 | |
|
147 | 147 | def get_ltc(self): |
|
148 | 148 | |
|
149 | 149 | return self.utc - self.timeZone*60 |
|
150 | 150 | |
|
151 | 151 | def set_ltc(self, value): |
|
152 | 152 | |
|
153 | 153 | self.utc = value + self.timeZone*60 |
|
154 | 154 | |
|
155 | 155 | def get_datatime(self): |
|
156 | 156 | |
|
157 | 157 | return datetime.datetime.utcfromtimestamp(self.ltc) |
|
158 | 158 | |
|
159 | 159 | ltc = property(get_ltc, set_ltc) |
|
160 | 160 | datatime = property(get_datatime) |
|
161 | 161 | |
|
162 | 162 | class SystemHeader(Header): |
|
163 | 163 | |
|
164 | 164 | size = None |
|
165 | 165 | nSamples = None |
|
166 | 166 | nProfiles = None |
|
167 | 167 | nChannels = None |
|
168 | 168 | adcResolution = None |
|
169 | 169 | pciDioBusWidth = None |
|
170 | 170 | |
|
171 | def __init__(self): | |
|
171 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0): | |
|
172 | ||
|
172 | 173 | self.size = 24 |
|
173 |
self.nSamples = |
|
|
174 |
self.nProfiles = |
|
|
175 |
self.nChannels = |
|
|
176 |
self.adcResolution = |
|
|
177 |
self.pciDioBusWidth = |
|
|
178 | ||
|
174 | self.nSamples = nSamples | |
|
175 | self.nProfiles = nProfiles | |
|
176 | self.nChannels = nChannels | |
|
177 | self.adcResolution = adcResolution | |
|
178 | self.pciDioBusWidth = pciDioBusWith | |
|
179 | ||
|
179 | 180 | def read(self, fp): |
|
181 | ||
|
180 | 182 | try: |
|
181 | 183 | header = numpy.fromfile(fp,SYSTEM_STRUCTURE,1) |
|
182 | 184 | self.size = header['nSize'][0] |
|
183 | 185 | self.nSamples = header['nNumSamples'][0] |
|
184 | 186 | self.nProfiles = header['nNumProfiles'][0] |
|
185 | 187 | self.nChannels = header['nNumChannels'][0] |
|
186 | 188 | self.adcResolution = header['nADCResolution'][0] |
|
187 | 189 | self.pciDioBusWidth = header['nPCDIOBusWidth'][0] |
|
188 | 190 | |
|
189 | 191 | except Exception, e: |
|
190 | 192 | print "SystemHeader: " + e |
|
191 | 193 | return 0 |
|
192 | 194 | |
|
193 | 195 | return 1 |
|
194 | 196 | |
|
195 | 197 | def write(self, fp): |
|
196 | 198 | |
|
197 | 199 | headerTuple = (self.size,self.nSamples,self.nProfiles,self.nChannels,self.adcResolution,self.pciDioBusWidth) |
|
198 | 200 | header = numpy.array(headerTuple,SYSTEM_STRUCTURE) |
|
199 | 201 | header.tofile(fp) |
|
200 | 202 | |
|
201 | 203 | return 1 |
|
202 | 204 | |
|
203 | 205 | class RadarControllerHeader(Header): |
|
204 | 206 | |
|
205 | 207 | size = None |
|
206 | 208 | expType = None |
|
207 | 209 | nTx = None |
|
208 | 210 | ipp = None |
|
209 | 211 | txA = None |
|
210 | 212 | txB = None |
|
211 | 213 | nWindows = None |
|
212 | 214 | numTaus = None |
|
213 | 215 | codeType = None |
|
214 | 216 | line6Function = None |
|
215 | 217 | line5Function = None |
|
216 | 218 | fClock = None |
|
217 | 219 | prePulseBefore = None |
|
218 | 220 | prePulserAfter = None |
|
219 | 221 | rangeIpp = None |
|
220 | 222 | rangeTxA = None |
|
221 | 223 | rangeTxB = None |
|
222 | 224 | |
|
223 | 225 | __C = 3e8 |
|
224 | 226 | |
|
225 |
def __init__(self |
|
|
227 | def __init__(self, expType=2, nTx=1, | |
|
228 | ippKm=None, txA=0, txB=0, | |
|
229 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, | |
|
230 | numTaus=0, line6Function=0, line5Function=0, fClock=0, | |
|
231 | prePulseBefore=0, prePulseAfter=0, | |
|
232 | codeType=0, nCode=0, nBaud=0, code=None, | |
|
233 | flip1=0, flip2=0): | |
|
234 | ||
|
226 | 235 | self.size = 116 |
|
227 |
self.expType = |
|
|
228 |
self.nTx = |
|
|
229 |
self.ipp = |
|
|
230 |
self.txA = |
|
|
231 |
self.txB = |
|
|
232 |
self. |
|
|
233 |
self. |
|
|
234 |
self. |
|
|
235 | self.line6Function = 0 | |
|
236 |
self. |
|
|
237 |
self. |
|
|
238 | self.prePulseBefore = 0 | |
|
239 | self.prePulserAfter = 0 | |
|
240 | self.rangeIpp = 0 | |
|
241 |
self. |
|
|
242 | self.rangeTxB = 0 | |
|
243 | ||
|
244 | self.samplingWindow = None | |
|
245 |
self.nHeights = |
|
|
246 |
self.firstHeight = |
|
|
247 |
self.deltaHeight = |
|
|
248 |
self.samplesWin = |
|
|
249 | ||
|
250 |
self.nCode = |
|
|
251 |
self.nBaud = |
|
|
252 |
self.code = |
|
|
253 |
self.flip1 = |
|
|
254 |
self.flip2 = |
|
|
236 | self.expType = expType | |
|
237 | self.nTx = nTx | |
|
238 | self.ipp = ippKm | |
|
239 | self.txA = txA | |
|
240 | self.txB = txB | |
|
241 | self.rangeIpp = ippKm | |
|
242 | self.rangeTxA = txA | |
|
243 | self.rangeTxB = txB | |
|
244 | ||
|
245 | self.nWindows = nWindows | |
|
246 | self.numTaus = numTaus | |
|
247 | self.codeType = codeType | |
|
248 | self.line6Function = line6Function | |
|
249 | self.line5Function = line5Function | |
|
250 | self.fClock = fClock | |
|
251 | self.prePulseBefore = prePulseBefore | |
|
252 | self.prePulserAfter = prePulseAfter | |
|
253 | ||
|
254 | self.nHeights = nHeights | |
|
255 | self.firstHeight = firstHeight | |
|
256 | self.deltaHeight = deltaHeight | |
|
257 | self.samplesWin = nHeights | |
|
258 | ||
|
259 | self.nCode = nCode | |
|
260 | self.nBaud = nBaud | |
|
261 | self.code = code | |
|
262 | self.flip1 = flip1 | |
|
263 | self.flip2 = flip2 | |
|
255 | 264 | |
|
256 | 265 | # self.dynamic = numpy.array([],numpy.dtype('byte')) |
|
257 | 266 | |
|
258 | 267 | |
|
259 | 268 | def read(self, fp): |
|
269 | ||
|
260 | 270 | try: |
|
261 | 271 | startFp = fp.tell() |
|
262 | 272 | header = numpy.fromfile(fp,RADAR_STRUCTURE,1) |
|
263 | 273 | |
|
264 | 274 | self.size = int(header['nSize'][0]) |
|
265 | 275 | self.expType = int(header['nExpType'][0]) |
|
266 | 276 | self.nTx = int(header['nNTx'][0]) |
|
267 | 277 | self.ipp = float(header['fIpp'][0]) |
|
268 | 278 | self.txA = float(header['fTxA'][0]) |
|
269 | 279 | self.txB = float(header['fTxB'][0]) |
|
270 | 280 | self.nWindows = int(header['nNumWindows'][0]) |
|
271 | 281 | self.numTaus = int(header['nNumTaus'][0]) |
|
272 | 282 | self.codeType = int(header['nCodeType'][0]) |
|
273 | 283 | self.line6Function = int(header['nLine6Function'][0]) |
|
274 | 284 | self.line5Function = int(header['nLine5Function'][0]) |
|
275 | 285 | self.fClock = float(header['fClock'][0]) |
|
276 | 286 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
277 | 287 | self.prePulserAfter = int(header['nPrePulseAfter'][0]) |
|
278 | 288 | self.rangeIpp = header['sRangeIPP'][0] |
|
279 | 289 | self.rangeTxA = header['sRangeTxA'][0] |
|
280 | 290 | self.rangeTxB = header['sRangeTxB'][0] |
|
281 | 291 | # jump Dynamic Radar Controller Header |
|
282 | 292 | # jumpFp = self.size - 116 |
|
283 | 293 | # self.dynamic = numpy.fromfile(fp,numpy.dtype('byte'),jumpFp) |
|
284 | 294 | #pointer backward to dynamic header and read |
|
285 | 295 | # backFp = fp.tell() - jumpFp |
|
286 | 296 | # fp.seek(backFp) |
|
287 | 297 | |
|
288 |
|
|
|
298 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) | |
|
289 | 299 | |
|
290 |
self.nHeights = int(numpy.sum( |
|
|
291 |
self.firstHeight = |
|
|
292 |
self.deltaHeight = |
|
|
293 |
self.samplesWin = |
|
|
300 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) | |
|
301 | self.firstHeight = samplingWindow['h0'] | |
|
302 | self.deltaHeight = samplingWindow['dh'] | |
|
303 | self.samplesWin = samplingWindow['nsa'] | |
|
294 | 304 | |
|
295 | 305 | self.Taus = numpy.fromfile(fp,'<f4',self.numTaus) |
|
296 | 306 | |
|
297 | 307 | if self.codeType != 0: |
|
298 | 308 | self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
299 | 309 | self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
300 |
self.code = numpy.empty([self.nCode,self.nBaud],dtype=' |
|
|
301 | ||
|
310 | self.code = numpy.empty([self.nCode,self.nBaud],dtype='i1') | |
|
311 | ||
|
302 | 312 | for ic in range(self.nCode): |
|
303 | 313 | temp = numpy.fromfile(fp,'u4',int(numpy.ceil(self.nBaud/32.))) |
|
304 | 314 | for ib in range(self.nBaud-1,-1,-1): |
|
305 | 315 | self.code[ic,ib] = temp[ib/32]%2 |
|
306 | 316 | temp[ib/32] = temp[ib/32]/2 |
|
307 | 317 | self.code = 2.0*self.code - 1.0 |
|
308 | 318 | self.code_size = int(numpy.ceil(self.nBaud/32.))*self.nCode*4 |
|
309 | 319 | |
|
310 | 320 | if self.line5Function == RCfunction.FLIP: |
|
311 | 321 | self.flip1 = numpy.fromfile(fp,'<u4',1) |
|
312 | 322 | |
|
313 | 323 | if self.line6Function == RCfunction.FLIP: |
|
314 | 324 | self.flip2 = numpy.fromfile(fp,'<u4',1) |
|
315 | 325 | |
|
316 | 326 | endFp = self.size + startFp |
|
317 | 327 | jumpFp = endFp - fp.tell() |
|
318 | 328 | if jumpFp > 0: |
|
319 | 329 | fp.seek(jumpFp) |
|
320 | 330 | |
|
321 | 331 | except Exception, e: |
|
322 | 332 | print "RadarControllerHeader: " + e |
|
323 | 333 | return 0 |
|
324 | 334 | |
|
325 | 335 | return 1 |
|
326 | 336 | |
|
327 | 337 | def write(self, fp): |
|
328 | 338 | headerTuple = (self.size, |
|
329 | 339 | self.expType, |
|
330 | 340 | self.nTx, |
|
331 | 341 | self.ipp, |
|
332 | 342 | self.txA, |
|
333 | 343 | self.txB, |
|
334 | 344 | self.nWindows, |
|
335 | 345 | self.numTaus, |
|
336 | 346 | self.codeType, |
|
337 | 347 | self.line6Function, |
|
338 | 348 | self.line5Function, |
|
339 | 349 | self.fClock, |
|
340 | 350 | self.prePulseBefore, |
|
341 | 351 | self.prePulserAfter, |
|
342 | 352 | self.rangeIpp, |
|
343 | 353 | self.rangeTxA, |
|
344 | 354 | self.rangeTxB) |
|
345 | 355 | |
|
346 | 356 | header = numpy.array(headerTuple,RADAR_STRUCTURE) |
|
347 | 357 | header.tofile(fp) |
|
348 | 358 | |
|
349 | 359 | #dynamic = self.dynamic |
|
350 | 360 | #dynamic.tofile(fp) |
|
351 | 361 | |
|
352 | samplingWindow = self.samplingWindow | |
|
362 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) | |
|
363 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) | |
|
353 | 364 | samplingWindow.tofile(fp) |
|
354 | 365 | |
|
355 | 366 | if self.numTaus > 0: |
|
356 | 367 | self.Taus.tofile(fp) |
|
357 | 368 | |
|
358 | 369 | if self.codeType !=0: |
|
359 | 370 | nCode = numpy.array(self.nCode, '<u4') |
|
360 | 371 | nCode.tofile(fp) |
|
361 | 372 | nBaud = numpy.array(self.nBaud, '<u4') |
|
362 | 373 | nBaud.tofile(fp) |
|
363 | 374 | code1 = (self.code + 1.0)/2. |
|
364 | 375 | |
|
365 | 376 | for ic in range(self.nCode): |
|
366 | 377 | tempx = numpy.zeros(numpy.ceil(self.nBaud/32.)) |
|
367 | 378 | start = 0 |
|
368 | 379 | end = 32 |
|
369 | 380 | for i in range(len(tempx)): |
|
370 | 381 | code_selected = code1[ic,start:end] |
|
371 | 382 | for j in range(len(code_selected)-1,-1,-1): |
|
372 | 383 | if code_selected[j] == 1: |
|
373 | 384 | tempx[i] = tempx[i] + 2**(len(code_selected)-1-j) |
|
374 | 385 | start = start + 32 |
|
375 | 386 | end = end + 32 |
|
376 | 387 | |
|
377 | 388 | tempx = tempx.astype('u4') |
|
378 | 389 | tempx.tofile(fp) |
|
379 | 390 | |
|
380 | 391 | if self.line5Function == RCfunction.FLIP: |
|
381 | 392 | self.flip1.tofile(fp) |
|
382 | 393 | |
|
383 | 394 | if self.line6Function == RCfunction.FLIP: |
|
384 | 395 | self.flip2.tofile(fp) |
|
385 | 396 | |
|
386 | 397 | return 1 |
|
387 | 398 | |
|
388 | 399 | def get_ippSeconds(self): |
|
389 | 400 | ''' |
|
390 | 401 | ''' |
|
391 | 402 | ippSeconds = 2.0 * 1000 * self.ipp / self.__C |
|
392 | 403 | |
|
393 | 404 | return ippSeconds |
|
394 | 405 | |
|
395 | 406 | def set_ippSeconds(self, ippSeconds): |
|
396 | 407 | ''' |
|
397 | 408 | ''' |
|
398 | 409 | |
|
399 | 410 | self.ipp = ippSeconds * self.__C / (2.0*1000) |
|
400 | 411 | |
|
401 | 412 | return |
|
402 | 413 | |
|
403 | 414 | ippSeconds = property(get_ippSeconds, set_ippSeconds) |
|
404 | 415 | |
|
405 | 416 | class ProcessingHeader(Header): |
|
406 | 417 | |
|
407 | 418 | size = None |
|
408 | 419 | dtype = None |
|
409 | 420 | blockSize = None |
|
410 | 421 | profilesPerBlock = None |
|
411 | 422 | dataBlocksPerFile = None |
|
412 | 423 | nWindows = None |
|
413 | 424 | processFlags = None |
|
414 | 425 | nCohInt = None |
|
415 | 426 | nIncohInt = None |
|
416 | 427 | totalSpectra = None |
|
417 | 428 | |
|
418 | 429 | flag_dc = None |
|
419 | 430 | flag_cspc = None |
|
420 | 431 | |
|
421 | 432 | def __init__(self): |
|
433 | ||
|
422 | 434 | self.size = 0 |
|
423 | 435 | self.dtype = 0 |
|
424 | 436 | self.blockSize = 0 |
|
425 | 437 | self.profilesPerBlock = 0 |
|
426 | 438 | self.dataBlocksPerFile = 0 |
|
427 | 439 | self.nWindows = 0 |
|
428 | 440 | self.processFlags = 0 |
|
429 | 441 | self.nCohInt = 0 |
|
430 | 442 | self.nIncohInt = 0 |
|
431 | 443 | self.totalSpectra = 0 |
|
432 | 444 | |
|
433 | self.samplingWindow = 0 | |
|
434 | ||
|
435 | 445 | self.nHeights = 0 |
|
436 | 446 | self.firstHeight = 0 |
|
437 | 447 | self.deltaHeight = 0 |
|
438 | 448 | self.samplesWin = 0 |
|
439 | 449 | self.spectraComb = 0 |
|
440 | 450 | # self.nCode = None |
|
441 | 451 | # self.code = None |
|
442 | 452 | # self.nBaud = None |
|
443 | 453 | self.shif_fft = False |
|
444 | 454 | self.flag_dc = False |
|
445 | 455 | self.flag_cspc = False |
|
446 | 456 | |
|
447 | 457 | def read(self, fp): |
|
448 | 458 | # try: |
|
449 | 459 | header = numpy.fromfile(fp,PROCESSING_STRUCTURE,1) |
|
450 | 460 | self.size = int(header['nSize'][0]) |
|
451 | 461 | self.dtype = int(header['nDataType'][0]) |
|
452 | 462 | self.blockSize = int(header['nSizeOfDataBlock'][0]) |
|
453 | 463 | self.profilesPerBlock = int(header['nProfilesperBlock'][0]) |
|
454 | 464 | self.dataBlocksPerFile = int(header['nDataBlocksperFile'][0]) |
|
455 | 465 | self.nWindows = int(header['nNumWindows'][0]) |
|
456 | 466 | self.processFlags = header['nProcessFlags'] |
|
457 | 467 | self.nCohInt = int(header['nCoherentIntegrations'][0]) |
|
458 | 468 | self.nIncohInt = int(header['nIncoherentIntegrations'][0]) |
|
459 | 469 | self.totalSpectra = int(header['nTotalSpectra'][0]) |
|
460 | 470 | |
|
461 |
|
|
|
471 | samplingWindow = numpy.fromfile(fp,SAMPLING_STRUCTURE,self.nWindows) | |
|
462 | 472 | |
|
463 |
self.nHeights = int(numpy.sum( |
|
|
464 |
self.firstHeight = float( |
|
|
465 |
self.deltaHeight = float( |
|
|
466 |
self.samplesWin = |
|
|
473 | self.nHeights = int(numpy.sum(samplingWindow['nsa'])) | |
|
474 | self.firstHeight = float(samplingWindow['h0'][0]) | |
|
475 | self.deltaHeight = float(samplingWindow['dh'][0]) | |
|
476 | self.samplesWin = samplingWindow['nsa'][0] | |
|
467 | 477 | self.spectraComb = numpy.fromfile(fp,'u1',2*self.totalSpectra) |
|
468 | 478 | |
|
469 | 479 | # if ((self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE) == PROCFLAG.DEFINE_PROCESS_CODE): |
|
470 | 480 | # self.nCode = int(numpy.fromfile(fp,'<u4',1)) |
|
471 | 481 | # self.nBaud = int(numpy.fromfile(fp,'<u4',1)) |
|
472 | 482 | # self.code = numpy.fromfile(fp,'<f4',self.nCode*self.nBaud).reshape(self.nCode,self.nBaud) |
|
473 | 483 | |
|
474 | 484 | if ((self.processFlags & PROCFLAG.SHIFT_FFT_DATA) == PROCFLAG.SHIFT_FFT_DATA): |
|
475 | 485 | self.shif_fft = True |
|
476 | 486 | else: |
|
477 | 487 | self.shif_fft = False |
|
478 | 488 | |
|
479 | 489 | if ((self.processFlags & PROCFLAG.SAVE_CHANNELS_DC) == PROCFLAG.SAVE_CHANNELS_DC): |
|
480 | 490 | self.flag_dc = True |
|
481 | 491 | |
|
482 | 492 | nChannels = 0 |
|
483 | 493 | nPairs = 0 |
|
484 | 494 | pairList = [] |
|
485 | 495 | |
|
486 | 496 | for i in range( 0, self.totalSpectra*2, 2 ): |
|
487 | 497 | if self.spectraComb[i] == self.spectraComb[i+1]: |
|
488 | 498 | nChannels = nChannels + 1 #par de canales iguales |
|
489 | 499 | else: |
|
490 | 500 | nPairs = nPairs + 1 #par de canales diferentes |
|
491 | 501 | pairList.append( (self.spectraComb[i], self.spectraComb[i+1]) ) |
|
492 | 502 | |
|
493 | 503 | self.flag_cspc = False |
|
494 | 504 | if nPairs > 0: |
|
495 | 505 | self.flag_cspc = True |
|
496 | 506 | |
|
497 | 507 | # except Exception, e: |
|
498 | 508 | # print "Error ProcessingHeader: " |
|
499 | 509 | # return 0 |
|
500 | 510 | |
|
501 | 511 | return 1 |
|
502 | 512 | |
|
503 | 513 | def write(self, fp): |
|
514 | ||
|
504 | 515 | headerTuple = (self.size, |
|
505 | 516 | self.dtype, |
|
506 | 517 | self.blockSize, |
|
507 | 518 | self.profilesPerBlock, |
|
508 | 519 | self.dataBlocksPerFile, |
|
509 | 520 | self.nWindows, |
|
510 | 521 | self.processFlags, |
|
511 | 522 | self.nCohInt, |
|
512 | 523 | self.nIncohInt, |
|
513 | 524 | self.totalSpectra) |
|
514 | 525 | |
|
515 | 526 | header = numpy.array(headerTuple,PROCESSING_STRUCTURE) |
|
516 | 527 | header.tofile(fp) |
|
517 | 528 | |
|
518 | 529 | if self.nWindows != 0: |
|
519 | 530 | sampleWindowTuple = (self.firstHeight,self.deltaHeight,self.samplesWin) |
|
520 | 531 | samplingWindow = numpy.array(sampleWindowTuple,SAMPLING_STRUCTURE) |
|
521 | 532 | samplingWindow.tofile(fp) |
|
522 | 533 | |
|
523 | 534 | |
|
524 | 535 | if self.totalSpectra != 0: |
|
525 | 536 | spectraComb = numpy.array([],numpy.dtype('u1')) |
|
526 | 537 | spectraComb = self.spectraComb |
|
527 | 538 | spectraComb.tofile(fp) |
|
528 | 539 | |
|
529 | 540 | # if self.processFlags & PROCFLAG.DEFINE_PROCESS_CODE == PROCFLAG.DEFINE_PROCESS_CODE: |
|
530 | 541 | # nCode = numpy.array([self.nCode], numpy.dtype('u4')) #Probar con un dato que almacene codigo, hasta el momento no se hizo la prueba |
|
531 | 542 | # nCode.tofile(fp) |
|
532 | 543 | # |
|
533 | 544 | # nBaud = numpy.array([self.nBaud], numpy.dtype('u4')) |
|
534 | 545 | # nBaud.tofile(fp) |
|
535 | 546 | # |
|
536 | 547 | # code = self.code.reshape(self.nCode*self.nBaud) |
|
537 | 548 | # code = code.astype(numpy.dtype('<f4')) |
|
538 | 549 | # code.tofile(fp) |
|
539 | 550 | |
|
540 | 551 | return 1 |
|
541 | 552 | |
|
542 | 553 | class RCfunction: |
|
543 | 554 | NONE=0 |
|
544 | 555 | FLIP=1 |
|
545 | 556 | CODE=2 |
|
546 | 557 | SAMPLING=3 |
|
547 | 558 | LIN6DIV256=4 |
|
548 | 559 | SYNCHRO=5 |
|
549 | 560 | |
|
550 | 561 | class nCodeType: |
|
551 | 562 | NONE=0 |
|
552 | 563 | USERDEFINE=1 |
|
553 | 564 | BARKER2=2 |
|
554 | 565 | BARKER3=3 |
|
555 | 566 | BARKER4=4 |
|
556 | 567 | BARKER5=5 |
|
557 | 568 | BARKER7=6 |
|
558 | 569 | BARKER11=7 |
|
559 | 570 | BARKER13=8 |
|
560 | 571 | AC128=9 |
|
561 | 572 | COMPLEMENTARYCODE2=10 |
|
562 | 573 | COMPLEMENTARYCODE4=11 |
|
563 | 574 | COMPLEMENTARYCODE8=12 |
|
564 | 575 | COMPLEMENTARYCODE16=13 |
|
565 | 576 | COMPLEMENTARYCODE32=14 |
|
566 | 577 | COMPLEMENTARYCODE64=15 |
|
567 | 578 | COMPLEMENTARYCODE128=16 |
|
568 | 579 | CODE_BINARY28=17 |
|
569 | 580 | |
|
570 | 581 | class PROCFLAG: |
|
571 | 582 | COHERENT_INTEGRATION = numpy.uint32(0x00000001) |
|
572 | 583 | DECODE_DATA = numpy.uint32(0x00000002) |
|
573 | 584 | SPECTRA_CALC = numpy.uint32(0x00000004) |
|
574 | 585 | INCOHERENT_INTEGRATION = numpy.uint32(0x00000008) |
|
575 | 586 | POST_COHERENT_INTEGRATION = numpy.uint32(0x00000010) |
|
576 | 587 | SHIFT_FFT_DATA = numpy.uint32(0x00000020) |
|
577 | 588 | |
|
578 | 589 | DATATYPE_CHAR = numpy.uint32(0x00000040) |
|
579 | 590 | DATATYPE_SHORT = numpy.uint32(0x00000080) |
|
580 | 591 | DATATYPE_LONG = numpy.uint32(0x00000100) |
|
581 | 592 | DATATYPE_INT64 = numpy.uint32(0x00000200) |
|
582 | 593 | DATATYPE_FLOAT = numpy.uint32(0x00000400) |
|
583 | 594 | DATATYPE_DOUBLE = numpy.uint32(0x00000800) |
|
584 | 595 | |
|
585 | 596 | DATAARRANGE_CONTIGUOUS_CH = numpy.uint32(0x00001000) |
|
586 | 597 | DATAARRANGE_CONTIGUOUS_H = numpy.uint32(0x00002000) |
|
587 | 598 | DATAARRANGE_CONTIGUOUS_P = numpy.uint32(0x00004000) |
|
588 | 599 | |
|
589 | 600 | SAVE_CHANNELS_DC = numpy.uint32(0x00008000) |
|
590 | 601 | DEFLIP_DATA = numpy.uint32(0x00010000) |
|
591 | 602 | DEFINE_PROCESS_CODE = numpy.uint32(0x00020000) |
|
592 | 603 | |
|
593 | 604 | ACQ_SYS_NATALIA = numpy.uint32(0x00040000) |
|
594 | 605 | ACQ_SYS_ECHOTEK = numpy.uint32(0x00080000) |
|
595 | 606 | ACQ_SYS_ADRXD = numpy.uint32(0x000C0000) |
|
596 | 607 | ACQ_SYS_JULIA = numpy.uint32(0x00100000) |
|
597 | 608 | ACQ_SYS_XXXXXX = numpy.uint32(0x00140000) |
|
598 | 609 | |
|
599 | 610 | EXP_NAME_ESP = numpy.uint32(0x00200000) |
|
600 | 611 | CHANNEL_NAMES_ESP = numpy.uint32(0x00400000) |
|
601 | 612 | |
|
602 | 613 | OPERATION_MASK = numpy.uint32(0x0000003F) |
|
603 | 614 | DATATYPE_MASK = numpy.uint32(0x00000FC0) |
|
604 | 615 | DATAARRANGE_MASK = numpy.uint32(0x00007000) |
|
605 | 616 | ACQ_SYS_MASK = numpy.uint32(0x001C0000) No newline at end of file |
@@ -0,0 +1,5 | |||
|
1 | from jroplot_voltage import * | |
|
2 | from jroplot_spectra import * | |
|
3 | from jroplot_heispectra import * | |
|
4 | from jroplot_correlation import * | |
|
5 | from jroplot_parameters import * No newline at end of file |
@@ -1,607 +1,608 | |||
|
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 | self.__driver.closeFigure() | |
|
48 | self.__driver.closeFigure(True) | |
|
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 |
def getTimeLim(self, x, xmin=None, xmax=None, timerange=None |
|
|
73 | def getTimeLim(self, x, xmin=None, xmax=None, timerange=None): | |
|
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 | ||
|
84 | if timerange != None and self.xmin == None and self.xmax == None: | |
|
85 | txmin = x[0] - x[0]%timerange | |
|
83 | if timerange == None and (xmin==None or xmax==None): | |
|
84 | raise ValueError, "timerange or xmin+xmax should be defined" | |
|
85 | ||
|
86 | if timerange != None: | |
|
87 | txmin = x[0] - x[0] % min(timerange/10, 10*60) | |
|
86 | 88 | else: |
|
87 | txmin = numpy.min(x) | |
|
88 | timerange = self.timerange | |
|
89 | txmin = x[0] - x[0] % 10*60 | |
|
89 | 90 | |
|
90 | 91 | thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
91 | 92 | thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
92 | 93 | |
|
93 |
if |
|
|
94 | if timerange != None: | |
|
94 | 95 | xmin = (thisdatetime - thisdate).seconds/(60*60.) |
|
95 | 96 | xmax = xmin + timerange/(60*60.) |
|
96 | 97 | |
|
97 | 98 | mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
98 | 99 | xmin_sec = time.mktime(mindt.timetuple()) |
|
99 | 100 | |
|
100 | 101 | maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
101 | 102 | xmax_sec = time.mktime(maxdt.timetuple()) |
|
102 | 103 | |
|
103 | 104 | return xmin_sec, xmax_sec |
|
104 | 105 | |
|
105 | 106 | |
|
106 | 107 | |
|
107 | 108 | |
|
108 | 109 | |
|
109 | 110 | # if timerange != None: |
|
110 | 111 | # txmin = x[0] - x[0]%timerange |
|
111 | 112 | # else: |
|
112 | 113 | # txmin = numpy.min(x) |
|
113 | 114 | # |
|
114 | 115 | # thisdatetime = datetime.datetime.utcfromtimestamp(txmin) |
|
115 | 116 | # thisdate = datetime.datetime.combine(thisdatetime.date(), datetime.time(0,0,0)) |
|
116 | 117 | # |
|
117 | 118 | # #################################################### |
|
118 | 119 | # #If the x is out of xrange |
|
119 | 120 | # if xmax != None: |
|
120 | 121 | # if xmax < (thisdatetime - thisdate).seconds/(60*60.): |
|
121 | 122 | # xmin = None |
|
122 | 123 | # xmax = None |
|
123 | 124 | # |
|
124 | 125 | # if xmin == None: |
|
125 | 126 | # td = thisdatetime - thisdate |
|
126 | 127 | # xmin = td.seconds/(60*60.) |
|
127 | 128 | # |
|
128 | 129 | # if xmax == None: |
|
129 | 130 | # xmax = xmin + self.timerange/(60*60.) |
|
130 | 131 | # |
|
131 | 132 | # mindt = thisdate + datetime.timedelta(hours=xmin) - datetime.timedelta(seconds=time.timezone) |
|
132 | 133 | # tmin = time.mktime(mindt.timetuple()) |
|
133 | 134 | # |
|
134 | 135 | # maxdt = thisdate + datetime.timedelta(hours=xmax) - datetime.timedelta(seconds=time.timezone) |
|
135 | 136 | # tmax = time.mktime(maxdt.timetuple()) |
|
136 | 137 | # |
|
137 | 138 | # #self.timerange = tmax - tmin |
|
138 | 139 | # |
|
139 | 140 | # return tmin, tmax |
|
140 | 141 | |
|
141 | 142 | def init(self, id, nplots, wintitle): |
|
142 | 143 | |
|
143 | 144 | raise ValueError, "This method has been replaced with createFigure" |
|
144 | 145 | |
|
145 | 146 | def createFigure(self, id, wintitle, widthplot=None, heightplot=None, show=True): |
|
146 | 147 | |
|
147 | 148 | """ |
|
148 | 149 | Crea la figura de acuerdo al driver y parametros seleccionados seleccionados. |
|
149 | 150 | Las dimensiones de la pantalla es calculada a partir de los atributos self.WIDTH |
|
150 | 151 | y self.HEIGHT y el numero de subplots (nrow, ncol) |
|
151 | 152 | |
|
152 | 153 | Input: |
|
153 | 154 | id : Los parametros necesarios son |
|
154 | 155 | wintitle : |
|
155 | 156 | |
|
156 | 157 | """ |
|
157 | 158 | |
|
158 | 159 | if widthplot == None: |
|
159 | 160 | widthplot = self.WIDTH |
|
160 | 161 | |
|
161 | 162 | if heightplot == None: |
|
162 | 163 | heightplot = self.HEIGHT |
|
163 | 164 | |
|
164 | 165 | self.id = id |
|
165 | 166 | |
|
166 | 167 | self.wintitle = wintitle |
|
167 | 168 | |
|
168 | 169 | self.widthscreen, self.heightscreen = self.getScreenDim(widthplot, heightplot) |
|
169 | 170 | |
|
170 | 171 | self.fig = self.__driver.createFigure(id=self.id, |
|
171 | 172 | wintitle=self.wintitle, |
|
172 | 173 | width=self.widthscreen, |
|
173 | 174 | height=self.heightscreen, |
|
174 | 175 | show=show) |
|
175 | 176 | |
|
176 | 177 | self.axesObjList = [] |
|
177 | 178 | |
|
178 | 179 | |
|
179 | 180 | def setDriver(self, driver=mpldriver): |
|
180 | 181 | |
|
181 | 182 | self.__driver = driver |
|
182 | 183 | |
|
183 | 184 | def setTitle(self, title): |
|
184 | 185 | |
|
185 | 186 | self.__driver.setTitle(self.fig, title) |
|
186 | 187 | |
|
187 | 188 | def setWinTitle(self, title): |
|
188 | 189 | |
|
189 | 190 | self.__driver.setWinTitle(self.fig, title=title) |
|
190 | 191 | |
|
191 | 192 | def setTextFromAxes(self, text): |
|
192 | 193 | |
|
193 | 194 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo setText de la clase Axes" |
|
194 | 195 | |
|
195 | 196 | def makeAxes(self, nrow, ncol, xpos, ypos, colspan, rowspan): |
|
196 | 197 | |
|
197 | 198 | raise ValueError, "Este metodo ha sido reemplazaado con el metodo addAxes" |
|
198 | 199 | |
|
199 | 200 | def addAxes(self, *args): |
|
200 | 201 | """ |
|
201 | 202 | |
|
202 | 203 | Input: |
|
203 | 204 | *args : Los parametros necesarios son |
|
204 | 205 | nrow, ncol, xpos, ypos, colspan, rowspan |
|
205 | 206 | """ |
|
206 | 207 | |
|
207 | 208 | axesObj = Axes(self.fig, *args) |
|
208 | 209 | self.axesObjList.append(axesObj) |
|
209 | 210 | |
|
210 | 211 | def saveFigure(self, figpath, figfile, *args): |
|
211 | 212 | |
|
212 | 213 | filename = os.path.join(figpath, figfile) |
|
213 | 214 | |
|
214 | 215 | fullpath = os.path.split(filename)[0] |
|
215 | 216 | |
|
216 | 217 | if not os.path.exists(fullpath): |
|
217 | 218 | subpath = os.path.split(fullpath)[0] |
|
218 | 219 | |
|
219 | 220 | if not os.path.exists(subpath): |
|
220 | 221 | os.mkdir(subpath) |
|
221 | 222 | |
|
222 | 223 | os.mkdir(fullpath) |
|
223 | 224 | |
|
224 | 225 | self.__driver.saveFigure(self.fig, filename, *args) |
|
225 | 226 | |
|
226 | 227 | |
|
227 | 228 | |
|
228 | 229 | |
|
229 | 230 | def getNameToFtp(self, thisDatetime, FTP_WEI, EXP_CODE, SUB_EXP_CODE, PLOT_CODE, PLOT_POS): |
|
230 | 231 | YEAR_STR = '%4.4d'%thisDatetime.timetuple().tm_year |
|
231 | 232 | DOY_STR = '%3.3d'%thisDatetime.timetuple().tm_yday |
|
232 | 233 | FTP_WEI = '%2.2d'%FTP_WEI |
|
233 | 234 | EXP_CODE = '%3.3d'%EXP_CODE |
|
234 | 235 | SUB_EXP_CODE = '%2.2d'%SUB_EXP_CODE |
|
235 | 236 | PLOT_CODE = '%2.2d'%PLOT_CODE |
|
236 | 237 | PLOT_POS = '%2.2d'%PLOT_POS |
|
237 | 238 | name = YEAR_STR + DOY_STR + FTP_WEI + EXP_CODE + SUB_EXP_CODE + PLOT_CODE + PLOT_POS |
|
238 | 239 | return name |
|
239 | 240 | |
|
240 | 241 | def draw(self): |
|
241 | 242 | |
|
242 | 243 | self.__driver.draw(self.fig) |
|
243 | 244 | |
|
244 | 245 | def run(self): |
|
245 | 246 | |
|
246 | 247 | raise ValueError, "This method is not implemented" |
|
247 | 248 | |
|
248 | 249 | def close(self): |
|
249 | 250 | |
|
250 | 251 | self.__driver.show(True) |
|
251 | 252 | |
|
252 | 253 | axesList = property(getAxesObjList) |
|
253 | 254 | |
|
254 | 255 | |
|
255 | 256 | class Axes: |
|
256 | 257 | |
|
257 | 258 | __driver = mpldriver |
|
258 | 259 | fig = None |
|
259 | 260 | ax = None |
|
260 | 261 | plot = None |
|
261 | 262 | __missing = 1E30 |
|
262 | 263 | __firsttime = None |
|
263 | 264 | |
|
264 | 265 | __showprofile = False |
|
265 | 266 | |
|
266 | 267 | xmin = None |
|
267 | 268 | xmax = None |
|
268 | 269 | ymin = None |
|
269 | 270 | ymax = None |
|
270 | 271 | zmin = None |
|
271 | 272 | zmax = None |
|
272 | 273 | |
|
273 | 274 | x_buffer = None |
|
274 | 275 | z_buffer = None |
|
275 | 276 | |
|
276 | 277 | decimationx = None |
|
277 | 278 | decimationy = None |
|
278 | 279 | |
|
279 | 280 | __MAXNUMX = 300 |
|
280 | 281 | __MAXNUMY = 150 |
|
281 | 282 | |
|
282 | 283 | def __init__(self, *args): |
|
283 | 284 | |
|
284 | 285 | """ |
|
285 | 286 | |
|
286 | 287 | Input: |
|
287 | 288 | *args : Los parametros necesarios son |
|
288 | 289 | fig, nrow, ncol, xpos, ypos, colspan, rowspan |
|
289 | 290 | """ |
|
290 | 291 | |
|
291 | 292 | ax = self.__driver.createAxes(*args) |
|
292 | 293 | self.fig = args[0] |
|
293 | 294 | self.ax = ax |
|
294 | 295 | self.plot = None |
|
295 | 296 | |
|
296 | 297 | self.__firsttime = True |
|
297 | 298 | self.idlineList = [] |
|
298 | 299 | |
|
299 | 300 | self.x_buffer = numpy.array([]) |
|
300 | 301 | self.z_buffer = numpy.array([]) |
|
301 | 302 | |
|
302 | 303 | def setText(self, text): |
|
303 | 304 | |
|
304 | 305 | self.__driver.setAxesText(self.ax, text) |
|
305 | 306 | |
|
306 | 307 | def setXAxisAsTime(self): |
|
307 | 308 | pass |
|
308 | 309 | |
|
309 | 310 | def pline(self, x, y, |
|
310 | 311 | xmin=None, xmax=None, |
|
311 | 312 | ymin=None, ymax=None, |
|
312 | 313 | xlabel='', ylabel='', |
|
313 | 314 | title='', |
|
314 | 315 | **kwargs): |
|
315 | 316 | |
|
316 | 317 | """ |
|
317 | 318 | |
|
318 | 319 | Input: |
|
319 | 320 | x : |
|
320 | 321 | y : |
|
321 | 322 | xmin : |
|
322 | 323 | xmax : |
|
323 | 324 | ymin : |
|
324 | 325 | ymax : |
|
325 | 326 | xlabel : |
|
326 | 327 | ylabel : |
|
327 | 328 | title : |
|
328 | 329 | **kwargs : Los parametros aceptados son |
|
329 | 330 | |
|
330 | 331 | ticksize |
|
331 | 332 | ytick_visible |
|
332 | 333 | """ |
|
333 | 334 | |
|
334 | 335 | if self.__firsttime: |
|
335 | 336 | |
|
336 | 337 | if xmin == None: xmin = numpy.nanmin(x) |
|
337 | 338 | if xmax == None: xmax = numpy.nanmax(x) |
|
338 | 339 | if ymin == None: ymin = numpy.nanmin(y) |
|
339 | 340 | if ymax == None: ymax = numpy.nanmax(y) |
|
340 | 341 | |
|
341 | 342 | self.plot = self.__driver.createPline(self.ax, x, y, |
|
342 | 343 | xmin, xmax, |
|
343 | 344 | ymin, ymax, |
|
344 | 345 | xlabel=xlabel, |
|
345 | 346 | ylabel=ylabel, |
|
346 | 347 | title=title, |
|
347 | 348 | **kwargs) |
|
348 | 349 | |
|
349 | 350 | self.idlineList.append(0) |
|
350 | 351 | self.__firsttime = False |
|
351 | 352 | return |
|
352 | 353 | |
|
353 | 354 | self.__driver.pline(self.plot, x, y, xlabel=xlabel, |
|
354 | 355 | ylabel=ylabel, |
|
355 | 356 | title=title) |
|
356 | 357 | |
|
357 | 358 | def addpline(self, x, y, idline, **kwargs): |
|
358 | 359 | lines = self.ax.lines |
|
359 | 360 | |
|
360 | 361 | if idline in self.idlineList: |
|
361 | 362 | self.__driver.set_linedata(self.ax, x, y, idline) |
|
362 | 363 | |
|
363 | 364 | if idline not in(self.idlineList): |
|
364 | 365 | self.__driver.addpline(self.ax, x, y, **kwargs) |
|
365 | 366 | self.idlineList.append(idline) |
|
366 | 367 | |
|
367 | 368 | return |
|
368 | 369 | |
|
369 | 370 | def pmultiline(self, x, y, |
|
370 | 371 | xmin=None, xmax=None, |
|
371 | 372 | ymin=None, ymax=None, |
|
372 | 373 | xlabel='', ylabel='', |
|
373 | 374 | title='', |
|
374 | 375 | **kwargs): |
|
375 | 376 | |
|
376 | 377 | if self.__firsttime: |
|
377 | 378 | |
|
378 | 379 | if xmin == None: xmin = numpy.nanmin(x) |
|
379 | 380 | if xmax == None: xmax = numpy.nanmax(x) |
|
380 | 381 | if ymin == None: ymin = numpy.nanmin(y) |
|
381 | 382 | if ymax == None: ymax = numpy.nanmax(y) |
|
382 | 383 | |
|
383 | 384 | self.plot = self.__driver.createPmultiline(self.ax, x, y, |
|
384 | 385 | xmin, xmax, |
|
385 | 386 | ymin, ymax, |
|
386 | 387 | xlabel=xlabel, |
|
387 | 388 | ylabel=ylabel, |
|
388 | 389 | title=title, |
|
389 | 390 | **kwargs) |
|
390 | 391 | self.__firsttime = False |
|
391 | 392 | return |
|
392 | 393 | |
|
393 | 394 | self.__driver.pmultiline(self.plot, x, y, xlabel=xlabel, |
|
394 | 395 | ylabel=ylabel, |
|
395 | 396 | title=title) |
|
396 | 397 | |
|
397 | 398 | def pmultilineyaxis(self, x, y, |
|
398 | 399 | xmin=None, xmax=None, |
|
399 | 400 | ymin=None, ymax=None, |
|
400 | 401 | xlabel='', ylabel='', |
|
401 | 402 | title='', |
|
402 | 403 | **kwargs): |
|
403 | 404 | |
|
404 | 405 | if self.__firsttime: |
|
405 | 406 | |
|
406 | 407 | if xmin == None: xmin = numpy.nanmin(x) |
|
407 | 408 | if xmax == None: xmax = numpy.nanmax(x) |
|
408 | 409 | if ymin == None: ymin = numpy.nanmin(y) |
|
409 | 410 | if ymax == None: ymax = numpy.nanmax(y) |
|
410 | 411 | |
|
411 | 412 | self.plot = self.__driver.createPmultilineYAxis(self.ax, x, y, |
|
412 | 413 | xmin, xmax, |
|
413 | 414 | ymin, ymax, |
|
414 | 415 | xlabel=xlabel, |
|
415 | 416 | ylabel=ylabel, |
|
416 | 417 | title=title, |
|
417 | 418 | **kwargs) |
|
418 | 419 | if self.xmin == None: self.xmin = xmin |
|
419 | 420 | if self.xmax == None: self.xmax = xmax |
|
420 | 421 | if self.ymin == None: self.ymin = ymin |
|
421 | 422 | if self.ymax == None: self.ymax = ymax |
|
422 | 423 | |
|
423 | 424 | self.__firsttime = False |
|
424 | 425 | return |
|
425 | 426 | |
|
426 | 427 | self.__driver.pmultilineyaxis(self.plot, x, y, xlabel=xlabel, |
|
427 | 428 | ylabel=ylabel, |
|
428 | 429 | title=title) |
|
429 | 430 | |
|
430 | 431 | def pcolor(self, x, y, z, |
|
431 | 432 | xmin=None, xmax=None, |
|
432 | 433 | ymin=None, ymax=None, |
|
433 | 434 | zmin=None, zmax=None, |
|
434 | 435 | xlabel='', ylabel='', |
|
435 | 436 | title='', rti = False, colormap='jet', |
|
436 | 437 | **kwargs): |
|
437 | 438 | |
|
438 | 439 | """ |
|
439 | 440 | Input: |
|
440 | 441 | x : |
|
441 | 442 | y : |
|
442 | 443 | x : |
|
443 | 444 | xmin : |
|
444 | 445 | xmax : |
|
445 | 446 | ymin : |
|
446 | 447 | ymax : |
|
447 | 448 | zmin : |
|
448 | 449 | zmax : |
|
449 | 450 | xlabel : |
|
450 | 451 | ylabel : |
|
451 | 452 | title : |
|
452 | 453 | **kwargs : Los parametros aceptados son |
|
453 | 454 | ticksize=9, |
|
454 | 455 | cblabel='' |
|
455 | 456 | rti = True or False |
|
456 | 457 | """ |
|
457 | 458 | |
|
458 | 459 | if self.__firsttime: |
|
459 | 460 | |
|
460 | 461 | if xmin == None: xmin = numpy.nanmin(x) |
|
461 | 462 | if xmax == None: xmax = numpy.nanmax(x) |
|
462 | 463 | if ymin == None: ymin = numpy.nanmin(y) |
|
463 | 464 | if ymax == None: ymax = numpy.nanmax(y) |
|
464 | 465 | if zmin == None: zmin = numpy.nanmin(z) |
|
465 | 466 | if zmax == None: zmax = numpy.nanmax(z) |
|
466 | 467 | |
|
467 | 468 | |
|
468 | 469 | self.plot = self.__driver.createPcolor(self.ax, x, y, z, |
|
469 | 470 | xmin, xmax, |
|
470 | 471 | ymin, ymax, |
|
471 | 472 | zmin, zmax, |
|
472 | 473 | xlabel=xlabel, |
|
473 | 474 | ylabel=ylabel, |
|
474 | 475 | title=title, |
|
475 | 476 | colormap=colormap, |
|
476 | 477 | **kwargs) |
|
477 | 478 | |
|
478 | 479 | if self.xmin == None: self.xmin = xmin |
|
479 | 480 | if self.xmax == None: self.xmax = xmax |
|
480 | 481 | if self.ymin == None: self.ymin = ymin |
|
481 | 482 | if self.ymax == None: self.ymax = ymax |
|
482 | 483 | if self.zmin == None: self.zmin = zmin |
|
483 | 484 | if self.zmax == None: self.zmax = zmax |
|
484 | 485 | |
|
485 | 486 | self.__firsttime = False |
|
486 | 487 | return |
|
487 | 488 | |
|
488 | 489 | if rti: |
|
489 | 490 | self.__driver.addpcolor(self.ax, x, y, z, self.zmin, self.zmax, |
|
490 | 491 | xlabel=xlabel, |
|
491 | 492 | ylabel=ylabel, |
|
492 | 493 | title=title, |
|
493 | 494 | colormap=colormap) |
|
494 | 495 | return |
|
495 | 496 | |
|
496 | 497 | self.__driver.pcolor(self.plot, z, |
|
497 | 498 | xlabel=xlabel, |
|
498 | 499 | ylabel=ylabel, |
|
499 | 500 | title=title) |
|
500 | 501 | |
|
501 | 502 | def pcolorbuffer(self, x, y, z, |
|
502 | 503 | xmin=None, xmax=None, |
|
503 | 504 | ymin=None, ymax=None, |
|
504 | 505 | zmin=None, zmax=None, |
|
505 | 506 | xlabel='', ylabel='', |
|
506 | 507 | title='', rti = True, colormap='jet', |
|
507 | 508 | maxNumX = None, maxNumY = None, |
|
508 | 509 | **kwargs): |
|
509 | 510 | |
|
510 | 511 | if maxNumX == None: |
|
511 | 512 | maxNumX = self.__MAXNUMX |
|
512 | 513 | |
|
513 | 514 | if maxNumY == None: |
|
514 | 515 | maxNumY = self.__MAXNUMY |
|
515 | 516 | |
|
516 | 517 | if self.__firsttime: |
|
517 | 518 | self.z_buffer = z |
|
518 | 519 | self.x_buffer = numpy.hstack((self.x_buffer, x)) |
|
519 | 520 | |
|
520 | 521 | if xmin == None: xmin = numpy.nanmin(x) |
|
521 | 522 | if xmax == None: xmax = numpy.nanmax(x) |
|
522 | 523 | if ymin == None: ymin = numpy.nanmin(y) |
|
523 | 524 | if ymax == None: ymax = numpy.nanmax(y) |
|
524 | 525 | if zmin == None: zmin = numpy.nanmin(z) |
|
525 | 526 | if zmax == None: zmax = numpy.nanmax(z) |
|
526 | 527 | |
|
527 | 528 | |
|
528 | 529 | self.plot = self.__driver.createPcolor(self.ax, self.x_buffer, y, z, |
|
529 | 530 | xmin, xmax, |
|
530 | 531 | ymin, ymax, |
|
531 | 532 | zmin, zmax, |
|
532 | 533 | xlabel=xlabel, |
|
533 | 534 | ylabel=ylabel, |
|
534 | 535 | title=title, |
|
535 | 536 | colormap=colormap, |
|
536 | 537 | **kwargs) |
|
537 | 538 | |
|
538 | 539 | if self.xmin == None: self.xmin = xmin |
|
539 | 540 | if self.xmax == None: self.xmax = xmax |
|
540 | 541 | if self.ymin == None: self.ymin = ymin |
|
541 | 542 | if self.ymax == None: self.ymax = ymax |
|
542 | 543 | if self.zmin == None: self.zmin = zmin |
|
543 | 544 | if self.zmax == None: self.zmax = zmax |
|
544 | 545 | |
|
545 | 546 | self.__firsttime = False |
|
546 | 547 | return |
|
547 | 548 | |
|
548 | 549 | self.x_buffer = numpy.hstack((self.x_buffer, x[-1])) |
|
549 | 550 | self.z_buffer = numpy.hstack((self.z_buffer, z)) |
|
550 | 551 | |
|
551 | 552 | if self.decimationx == None: |
|
552 | 553 | deltax = float(self.xmax - self.xmin)/maxNumX |
|
553 | 554 | deltay = float(self.ymax - self.ymin)/maxNumY |
|
554 | 555 | |
|
555 | 556 | resolutionx = self.x_buffer[2]-self.x_buffer[0] |
|
556 | 557 | resolutiony = y[1]-y[0] |
|
557 | 558 | |
|
558 | 559 | self.decimationx = numpy.ceil(deltax / resolutionx) |
|
559 | 560 | self.decimationy = numpy.ceil(deltay / resolutiony) |
|
560 | 561 | |
|
561 | 562 | z_buffer = self.z_buffer.reshape(-1,len(y)) |
|
562 | 563 | |
|
563 | 564 | x_buffer = self.x_buffer[::self.decimationx] |
|
564 | 565 | y_buffer = y[::self.decimationy] |
|
565 | 566 | z_buffer = z_buffer[::self.decimationx, ::self.decimationy] |
|
566 | 567 | #=================================================== |
|
567 | 568 | |
|
568 | 569 | x_buffer, y_buffer, z_buffer = self.__fillGaps(x_buffer, y_buffer, z_buffer) |
|
569 | 570 | |
|
570 | 571 | self.__driver.addpcolorbuffer(self.ax, x_buffer, y_buffer, z_buffer, self.zmin, self.zmax, |
|
571 | 572 | xlabel=xlabel, |
|
572 | 573 | ylabel=ylabel, |
|
573 | 574 | title=title, |
|
574 | 575 | colormap=colormap) |
|
575 | 576 | |
|
576 | 577 | def polar(self, x, y, |
|
577 | 578 | title='', xlabel='',ylabel='',**kwargs): |
|
578 | 579 | |
|
579 | 580 | if self.__firsttime: |
|
580 | 581 | self.plot = self.__driver.createPolar(self.ax, x, y, title = title, xlabel = xlabel, ylabel = ylabel) |
|
581 | 582 | self.__firsttime = False |
|
582 | 583 | self.x_buffer = x |
|
583 | 584 | self.y_buffer = y |
|
584 | 585 | return |
|
585 | 586 | |
|
586 | 587 | self.x_buffer = numpy.hstack((self.x_buffer,x)) |
|
587 | 588 | self.y_buffer = numpy.hstack((self.y_buffer,y)) |
|
588 | 589 | self.__driver.polar(self.plot, self.x_buffer, self.y_buffer, xlabel=xlabel, |
|
589 | 590 | ylabel=ylabel, |
|
590 | 591 | title=title) |
|
591 | 592 | |
|
592 | 593 | def __fillGaps(self, x_buffer, y_buffer, z_buffer): |
|
593 | 594 | |
|
594 | 595 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
595 | 596 | x_median = numpy.median(deltas) |
|
596 | 597 | |
|
597 | 598 | index = numpy.where(deltas >= 2*x_median) |
|
598 | 599 | |
|
599 | 600 | if len(index[0]) != 0: |
|
600 | 601 | z_buffer[index[0],::] = self.__missing |
|
601 | 602 | z_buffer = numpy.ma.masked_inside(z_buffer,0.99*self.__missing,1.01*self.__missing) |
|
602 | 603 | |
|
603 | 604 | return x_buffer, y_buffer, z_buffer |
|
604 | 605 | |
|
605 | 606 | |
|
606 | 607 | |
|
607 | 608 | No newline at end of file |
@@ -1,196 +1,198 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | import copy |
|
5 | 5 | |
|
6 | 6 | from figure import Figure, isRealtime |
|
7 | 7 | |
|
8 | 8 | class CorrelationPlot(Figure): |
|
9 | 9 | |
|
10 | 10 | isConfig = None |
|
11 | 11 | __nsubplots = None |
|
12 | 12 | |
|
13 | 13 | WIDTHPROF = None |
|
14 | 14 | HEIGHTPROF = None |
|
15 | 15 | PREFIX = 'corr' |
|
16 | 16 | |
|
17 | 17 | def __init__(self): |
|
18 | 18 | |
|
19 | 19 | self.isConfig = False |
|
20 | 20 | self.__nsubplots = 1 |
|
21 | 21 | |
|
22 | 22 | self.WIDTH = 280 |
|
23 | 23 | self.HEIGHT = 250 |
|
24 | 24 | self.WIDTHPROF = 120 |
|
25 | 25 | self.HEIGHTPROF = 0 |
|
26 | 26 | self.counter_imagwr = 0 |
|
27 | 27 | |
|
28 | 28 | self.PLOT_CODE = 1 |
|
29 | 29 | self.FTP_WEI = None |
|
30 | 30 | self.EXP_CODE = None |
|
31 | 31 | self.SUB_EXP_CODE = None |
|
32 | 32 | self.PLOT_POS = None |
|
33 | 33 | |
|
34 | 34 | def getSubplots(self): |
|
35 | 35 | |
|
36 | 36 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
37 | 37 | nrow = int(self.nplots*1./ncol + 0.9) |
|
38 | 38 | |
|
39 | 39 | return nrow, ncol |
|
40 | 40 | |
|
41 | 41 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
42 | 42 | |
|
43 | 43 | showprofile = False |
|
44 | 44 | self.__showprofile = showprofile |
|
45 | 45 | self.nplots = nplots |
|
46 | 46 | |
|
47 | 47 | ncolspan = 1 |
|
48 | 48 | colspan = 1 |
|
49 | 49 | if showprofile: |
|
50 | 50 | ncolspan = 3 |
|
51 | 51 | colspan = 2 |
|
52 | 52 | self.__nsubplots = 2 |
|
53 | 53 | |
|
54 | 54 | self.createFigure(id = id, |
|
55 | 55 | wintitle = wintitle, |
|
56 | 56 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
57 | 57 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
58 | 58 | show=show) |
|
59 | 59 | |
|
60 | 60 | nrow, ncol = self.getSubplots() |
|
61 | 61 | |
|
62 | 62 | counter = 0 |
|
63 | 63 | for y in range(nrow): |
|
64 | 64 | for x in range(ncol): |
|
65 | 65 | |
|
66 | 66 | if counter >= self.nplots: |
|
67 | 67 | break |
|
68 | 68 | |
|
69 | 69 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
70 | 70 | |
|
71 | 71 | if showprofile: |
|
72 | 72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
73 | 73 | |
|
74 | 74 | counter += 1 |
|
75 | 75 | |
|
76 | 76 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
77 | 77 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
78 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
|
78 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
|
79 | 79 | server=None, folder=None, username=None, password=None, |
|
80 | 80 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
81 | 81 | |
|
82 | 82 | """ |
|
83 | 83 | |
|
84 | 84 | Input: |
|
85 | 85 | dataOut : |
|
86 | 86 | id : |
|
87 | 87 | wintitle : |
|
88 | 88 | channelList : |
|
89 | 89 | showProfile : |
|
90 | 90 | xmin : None, |
|
91 | 91 | xmax : None, |
|
92 | 92 | ymin : None, |
|
93 | 93 | ymax : None, |
|
94 | 94 | zmin : None, |
|
95 | 95 | zmax : None |
|
96 | 96 | """ |
|
97 | 97 | |
|
98 | 98 | if dataOut.flagNoData: |
|
99 | 99 | return None |
|
100 | 100 | |
|
101 | 101 | if realtime: |
|
102 | 102 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
103 | 103 | print 'Skipping this plot function' |
|
104 | 104 | return |
|
105 | 105 | |
|
106 | 106 | if channelList == None: |
|
107 | 107 | channelIndexList = dataOut.channelIndexList |
|
108 | 108 | else: |
|
109 | 109 | channelIndexList = [] |
|
110 | 110 | for channel in channelList: |
|
111 | 111 | if channel not in dataOut.channelList: |
|
112 | 112 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
113 | 113 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
114 | 114 | |
|
115 | 115 | factor = dataOut.normFactor |
|
116 | 116 | lenfactor = factor.shape[1] |
|
117 | 117 | x = dataOut.getLagTRange(1) |
|
118 | 118 | y = dataOut.getHeiRange() |
|
119 | 119 | |
|
120 | 120 | z = copy.copy(dataOut.data_corr[:,:,0,:]) |
|
121 | 121 | for i in range(dataOut.data_corr.shape[0]): |
|
122 | 122 | z[i,:,:] = z[i,:,:]/factor[i,:] |
|
123 | 123 | zdB = numpy.abs(z) |
|
124 | 124 | |
|
125 | 125 | avg = numpy.average(z, axis=1) |
|
126 | 126 | # avg = numpy.nanmean(z, axis=1) |
|
127 | 127 | # noise = dataOut.noise/factor |
|
128 | 128 | |
|
129 | 129 | #thisDatetime = dataOut.datatime |
|
130 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
130 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
131 | 131 | title = wintitle + " Correlation" |
|
132 | 132 | xlabel = "Lag T (s)" |
|
133 | 133 | ylabel = "Range (Km)" |
|
134 | 134 | |
|
135 | 135 | if not self.isConfig: |
|
136 | 136 | |
|
137 | 137 | nplots = dataOut.data_corr.shape[0] |
|
138 | 138 | |
|
139 | 139 | self.setup(id=id, |
|
140 | 140 | nplots=nplots, |
|
141 | 141 | wintitle=wintitle, |
|
142 | 142 | showprofile=showprofile, |
|
143 | 143 | show=show) |
|
144 | 144 | |
|
145 | 145 | if xmin == None: xmin = numpy.nanmin(x) |
|
146 | 146 | if xmax == None: xmax = numpy.nanmax(x) |
|
147 | 147 | if ymin == None: ymin = numpy.nanmin(y) |
|
148 | 148 | if ymax == None: ymax = numpy.nanmax(y) |
|
149 | 149 | if zmin == None: zmin = 0 |
|
150 | 150 | if zmax == None: zmax = 1 |
|
151 | 151 | |
|
152 | 152 | self.FTP_WEI = ftp_wei |
|
153 | 153 | self.EXP_CODE = exp_code |
|
154 | 154 | self.SUB_EXP_CODE = sub_exp_code |
|
155 | 155 | self.PLOT_POS = plot_pos |
|
156 | 156 | |
|
157 | 157 | self.isConfig = True |
|
158 | 158 | |
|
159 | 159 | self.setWinTitle(title) |
|
160 | 160 | |
|
161 | 161 | for i in range(self.nplots): |
|
162 | 162 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
163 | 163 | title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0]+1,dataOut.pairsList[i][1]+1 , str_datetime) |
|
164 | 164 | axes = self.axesList[i*self.__nsubplots] |
|
165 | 165 | axes.pcolor(x, y, zdB[i,:,:], |
|
166 | 166 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
167 | 167 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
168 | 168 | ticksize=9, cblabel='') |
|
169 | 169 | |
|
170 | 170 | # if self.__showprofile: |
|
171 | 171 | # axes = self.axesList[i*self.__nsubplots +1] |
|
172 | 172 | # axes.pline(avgdB[i], y, |
|
173 | 173 | # xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
174 | 174 | # xlabel='dB', ylabel='', title='', |
|
175 | 175 | # ytick_visible=False, |
|
176 | 176 | # grid='x') |
|
177 | 177 | # |
|
178 | 178 | # noiseline = numpy.repeat(noisedB[i], len(y)) |
|
179 | 179 | # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
180 | 180 | |
|
181 | 181 | self.draw() |
|
182 | 182 | |
|
183 |
if |
|
|
184 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
185 | figfile = self.getFilename(name = str_datetime) | |
|
186 | ||
|
187 | if figpath != '': | |
|
183 | if save: | |
|
184 | ||
|
185 | if figfile == None: | |
|
186 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
187 | figfile = self.getFilename(name = str_datetime) | |
|
188 | ||
|
188 | 189 | self.counter_imagwr += 1 |
|
189 | 190 | if (self.counter_imagwr>=wr_period): |
|
190 | 191 | # store png plot to local folder |
|
191 | 192 | self.saveFigure(figpath, figfile) |
|
192 |
# store png plot to FTP server according to RT-Web format |
|
|
193 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
194 | ftp_filename = os.path.join(figpath, name) | |
|
195 | self.saveFigure(figpath, ftp_filename) | |
|
193 | # store png plot to FTP server according to RT-Web format | |
|
194 | if ftp: | |
|
195 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
196 | ftp_filename = os.path.join(figpath, name) | |
|
197 | self.saveFigure(figpath, ftp_filename) | |
|
196 | 198 | self.counter_imagwr = 0 |
@@ -1,326 +1,328 | |||
|
1 | 1 | ''' |
|
2 | Created on Jul 9, 2014 | |
|
2 | 3 | |
|
3 | @author: Daniel Suarez | |
|
4 | @author: roj-idl71 | |
|
4 | 5 | ''' |
|
5 | ||
|
6 | 6 | import os |
|
7 | 7 | import datetime |
|
8 | 8 | import numpy |
|
9 | 9 | |
|
10 | 10 | from figure import Figure, isRealtime |
|
11 | 11 | |
|
12 | 12 | class SpectraHeisScope(Figure): |
|
13 | 13 | |
|
14 | 14 | |
|
15 | 15 | isConfig = None |
|
16 | 16 | __nsubplots = None |
|
17 | 17 | |
|
18 | 18 | WIDTHPROF = None |
|
19 | 19 | HEIGHTPROF = None |
|
20 | 20 | PREFIX = 'spc' |
|
21 | 21 | |
|
22 | 22 | def __init__(self): |
|
23 | 23 | |
|
24 | 24 | self.isConfig = False |
|
25 | 25 | self.__nsubplots = 1 |
|
26 | 26 | |
|
27 | 27 | self.WIDTH = 230 |
|
28 | 28 | self.HEIGHT = 250 |
|
29 | 29 | self.WIDTHPROF = 120 |
|
30 | 30 | self.HEIGHTPROF = 0 |
|
31 | 31 | self.counter_imagwr = 0 |
|
32 | 32 | |
|
33 | 33 | def getSubplots(self): |
|
34 | 34 | |
|
35 | 35 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
36 | 36 | nrow = int(self.nplots*1./ncol + 0.9) |
|
37 | 37 | |
|
38 | 38 | return nrow, ncol |
|
39 | 39 | |
|
40 | 40 | def setup(self, id, nplots, wintitle, show): |
|
41 | 41 | |
|
42 | 42 | showprofile = False |
|
43 | 43 | self.__showprofile = showprofile |
|
44 | 44 | self.nplots = nplots |
|
45 | 45 | |
|
46 | 46 | ncolspan = 1 |
|
47 | 47 | colspan = 1 |
|
48 | 48 | if showprofile: |
|
49 | 49 | ncolspan = 3 |
|
50 | 50 | colspan = 2 |
|
51 | 51 | self.__nsubplots = 2 |
|
52 | 52 | |
|
53 | 53 | self.createFigure(id = id, |
|
54 | 54 | wintitle = wintitle, |
|
55 | 55 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
56 | 56 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
57 | 57 | show = show) |
|
58 | 58 | |
|
59 | 59 | nrow, ncol = self.getSubplots() |
|
60 | 60 | |
|
61 | 61 | counter = 0 |
|
62 | 62 | for y in range(nrow): |
|
63 | 63 | for x in range(ncol): |
|
64 | 64 | |
|
65 | 65 | if counter >= self.nplots: |
|
66 | 66 | break |
|
67 | 67 | |
|
68 | 68 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
69 | 69 | |
|
70 | 70 | if showprofile: |
|
71 | 71 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
72 | 72 | |
|
73 | 73 | counter += 1 |
|
74 | 74 | |
|
75 | 75 | |
|
76 | 76 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
77 | 77 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
78 | figpath='', figfile=None, ftp=False, wr_period=1, show=True, | |
|
78 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, | |
|
79 | 79 | server=None, folder=None, username=None, password=None): |
|
80 | 80 | |
|
81 | 81 | """ |
|
82 | 82 | |
|
83 | 83 | Input: |
|
84 | 84 | dataOut : |
|
85 | 85 | id : |
|
86 | 86 | wintitle : |
|
87 | 87 | channelList : |
|
88 | 88 | xmin : None, |
|
89 | 89 | xmax : None, |
|
90 | 90 | ymin : None, |
|
91 | 91 | ymax : None, |
|
92 | 92 | """ |
|
93 | 93 | |
|
94 | 94 | if dataOut.realtime: |
|
95 | 95 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
96 | 96 | print 'Skipping this plot function' |
|
97 | 97 | return |
|
98 | 98 | |
|
99 | 99 | if channelList == None: |
|
100 | 100 | channelIndexList = dataOut.channelIndexList |
|
101 | 101 | else: |
|
102 | 102 | channelIndexList = [] |
|
103 | 103 | for channel in channelList: |
|
104 | 104 | if channel not in dataOut.channelList: |
|
105 | 105 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
106 | 106 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
107 | 107 | |
|
108 | 108 | # x = dataOut.heightList |
|
109 | 109 | c = 3E8 |
|
110 | 110 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
111 | 111 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
112 | 112 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
|
113 | 113 | #para 1Mhz descomentar la siguiente linea |
|
114 | 114 | #x= x/(10000.0) |
|
115 | 115 | # y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
116 | 116 | # y = y.real |
|
117 | 117 | factor = dataOut.normFactor |
|
118 | 118 | data = dataOut.data_spc / factor |
|
119 | 119 | datadB = 10.*numpy.log10(data) |
|
120 | 120 | y = datadB |
|
121 | 121 | |
|
122 | 122 | #thisDatetime = dataOut.datatime |
|
123 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
123 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
124 | 124 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
125 | 125 | xlabel = "" |
|
126 | 126 | #para 1Mhz descomentar la siguiente linea |
|
127 | 127 | #xlabel = "Frequency x 10000" |
|
128 | 128 | ylabel = "Intensity (dB)" |
|
129 | 129 | |
|
130 | 130 | if not self.isConfig: |
|
131 | 131 | nplots = len(channelIndexList) |
|
132 | 132 | |
|
133 | 133 | self.setup(id=id, |
|
134 | 134 | nplots=nplots, |
|
135 | 135 | wintitle=wintitle, |
|
136 | 136 | show=show) |
|
137 | 137 | |
|
138 | 138 | if xmin == None: xmin = numpy.nanmin(x) |
|
139 | 139 | if xmax == None: xmax = numpy.nanmax(x) |
|
140 | 140 | if ymin == None: ymin = numpy.nanmin(y) |
|
141 | 141 | if ymax == None: ymax = numpy.nanmax(y) |
|
142 | 142 | |
|
143 | 143 | self.isConfig = True |
|
144 | 144 | |
|
145 | 145 | self.setWinTitle(title) |
|
146 | 146 | |
|
147 | 147 | for i in range(len(self.axesList)): |
|
148 | 148 | ychannel = y[i,:] |
|
149 | 149 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
150 | 150 | title = "Channel %d: %4.2fdB: %s" %(i, numpy.max(ychannel), str_datetime) |
|
151 | 151 | axes = self.axesList[i] |
|
152 | 152 | axes.pline(x, ychannel, |
|
153 | 153 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
154 | 154 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
155 | 155 | |
|
156 | 156 | |
|
157 | 157 | self.draw() |
|
158 | ||
|
159 | if figfile == None: | |
|
160 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
161 | figfile = self.getFilename(name = str_datetime) | |
|
162 | 158 | |
|
163 |
if |
|
|
159 | if save: | |
|
160 | ||
|
161 | if figfile == None: | |
|
162 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
163 | figfile = self.getFilename(name = str_datetime) | |
|
164 | ||
|
164 | 165 | self.counter_imagwr += 1 |
|
165 | 166 | if (self.counter_imagwr>=wr_period): |
|
166 | 167 | # store png plot to local folder |
|
167 | 168 | self.saveFigure(figpath, figfile) |
|
168 | 169 | # store png plot to FTP server according to RT-Web format |
|
169 | 170 | #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
170 | 171 | #ftp_filename = os.path.join(figpath, name) |
|
171 | 172 | #self.saveFigure(figpath, ftp_filename) |
|
172 | 173 | self.counter_imagwr = 0 |
|
173 | 174 | |
|
174 | 175 | class RTIfromSpectraHeis(Figure): |
|
175 | 176 | |
|
176 | 177 | isConfig = None |
|
177 | 178 | __nsubplots = None |
|
178 | 179 | |
|
179 | 180 | PREFIX = 'rtinoise' |
|
180 | 181 | |
|
181 | 182 | def __init__(self): |
|
182 | 183 | |
|
183 | 184 | self.timerange = 24*60*60 |
|
184 | 185 | self.isConfig = False |
|
185 | 186 | self.__nsubplots = 1 |
|
186 | 187 | |
|
187 | 188 | self.WIDTH = 820 |
|
188 | 189 | self.HEIGHT = 200 |
|
189 | 190 | self.WIDTHPROF = 120 |
|
190 | 191 | self.HEIGHTPROF = 0 |
|
191 | 192 | self.counter_imagwr = 0 |
|
192 | 193 | self.xdata = None |
|
193 | 194 | self.ydata = None |
|
194 | 195 | self.figfile = None |
|
195 | 196 | |
|
196 | 197 | def getSubplots(self): |
|
197 | 198 | |
|
198 | 199 | ncol = 1 |
|
199 | 200 | nrow = 1 |
|
200 | 201 | |
|
201 | 202 | return nrow, ncol |
|
202 | 203 | |
|
203 | 204 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
204 | 205 | |
|
205 | 206 | self.__showprofile = showprofile |
|
206 | 207 | self.nplots = nplots |
|
207 | 208 | |
|
208 | 209 | ncolspan = 7 |
|
209 | 210 | colspan = 6 |
|
210 | 211 | self.__nsubplots = 2 |
|
211 | 212 | |
|
212 | 213 | self.createFigure(id = id, |
|
213 | 214 | wintitle = wintitle, |
|
214 | 215 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
215 | 216 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
216 | 217 | show = show) |
|
217 | 218 | |
|
218 | 219 | nrow, ncol = self.getSubplots() |
|
219 | 220 | |
|
220 | 221 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
221 | 222 | |
|
222 | 223 | |
|
223 | 224 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
224 | 225 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
225 | 226 | timerange=None, |
|
226 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, show=True, | |
|
227 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, | |
|
227 | 228 | server=None, folder=None, username=None, password=None): |
|
228 | 229 | |
|
229 | 230 | if channelList == None: |
|
230 | 231 | channelIndexList = dataOut.channelIndexList |
|
231 | 232 | channelList = dataOut.channelList |
|
232 | 233 | else: |
|
233 | 234 | channelIndexList = [] |
|
234 | 235 | for channel in channelList: |
|
235 | 236 | if channel not in dataOut.channelList: |
|
236 | 237 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
237 | 238 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
238 | 239 | |
|
239 | 240 | if timerange != None: |
|
240 | 241 | self.timerange = timerange |
|
241 | 242 | |
|
242 | 243 | tmin = None |
|
243 | 244 | tmax = None |
|
244 | 245 | x = dataOut.getTimeRange() |
|
245 | 246 | y = dataOut.getHeiRange() |
|
246 | 247 | |
|
247 | 248 | factor = dataOut.normFactor |
|
248 | 249 | data = dataOut.data_spc / factor |
|
249 | 250 | data = numpy.average(data,axis=1) |
|
250 | 251 | datadB = 10*numpy.log10(data) |
|
251 | 252 | |
|
252 | 253 | # factor = dataOut.normFactor |
|
253 | 254 | # noise = dataOut.getNoise()/factor |
|
254 | 255 | # noisedB = 10*numpy.log10(noise) |
|
255 | 256 | |
|
256 | 257 | #thisDatetime = dataOut.datatime |
|
257 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
258 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
258 | 259 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
259 | 260 | xlabel = "Local Time" |
|
260 | 261 | ylabel = "Intensity (dB)" |
|
261 | 262 | |
|
262 | 263 | if not self.isConfig: |
|
263 | 264 | |
|
264 | 265 | nplots = 1 |
|
265 | 266 | |
|
266 | 267 | self.setup(id=id, |
|
267 | 268 | nplots=nplots, |
|
268 | 269 | wintitle=wintitle, |
|
269 | 270 | showprofile=showprofile, |
|
270 | 271 | show=show) |
|
271 | 272 | |
|
272 | 273 | tmin, tmax = self.getTimeLim(x, xmin, xmax) |
|
273 | 274 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
274 | 275 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
275 | 276 | |
|
276 | 277 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
277 | 278 | self.isConfig = True |
|
278 | 279 | self.figfile = figfile |
|
279 | 280 | self.xdata = numpy.array([]) |
|
280 | 281 | self.ydata = numpy.array([]) |
|
281 | 282 | |
|
282 | 283 | self.setWinTitle(title) |
|
283 | 284 | |
|
284 | 285 | |
|
285 | 286 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
286 | 287 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
287 | 288 | |
|
288 | 289 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
289 | 290 | axes = self.axesList[0] |
|
290 | 291 | |
|
291 | 292 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
292 | 293 | |
|
293 | 294 | if len(self.ydata)==0: |
|
294 | 295 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
295 | 296 | else: |
|
296 | 297 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
297 | 298 | |
|
298 | 299 | |
|
299 | 300 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
300 | 301 | xmin=tmin, xmax=tmax, ymin=ymin, ymax=ymax, |
|
301 | 302 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
302 | 303 | XAxisAsTime=True |
|
303 | 304 | ) |
|
304 | 305 | |
|
305 | 306 | self.draw() |
|
306 | 307 | |
|
307 | 308 | if x[1] >= self.axesList[0].xmax: |
|
308 | 309 | self.counter_imagwr = wr_period |
|
309 | 310 | del self.xdata |
|
310 | 311 | del self.ydata |
|
311 | 312 | self.__isConfig = False |
|
312 | 313 | |
|
313 | if self.figfile == None: | |
|
314 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
315 | self.figfile = self.getFilename(name = str_datetime) | |
|
316 | ||
|
317 | if figpath != '': | |
|
314 | if save: | |
|
315 | ||
|
316 | if self.figfile == None: | |
|
317 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
318 | self.figfile = self.getFilename(name = str_datetime) | |
|
319 | ||
|
318 | 320 | self.counter_imagwr += 1 |
|
319 | 321 | if (self.counter_imagwr>=wr_period): |
|
320 | 322 | # store png plot to local folder |
|
321 | 323 | self.saveFigure(figpath, self.figfile) |
|
322 | 324 | # store png plot to FTP server according to RT-Web format |
|
323 | 325 | #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
324 | 326 | #ftp_filename = os.path.join(figpath, name) |
|
325 | 327 | #self.saveFigure(figpath, ftp_filename) |
|
326 | 328 | self.counter_imagwr = 0 |
@@ -1,1195 +1,1208 | |||
|
1 | 1 | import os |
|
2 | 2 | import datetime |
|
3 | 3 | import numpy |
|
4 | 4 | |
|
5 | 5 | from figure import Figure, isRealtime |
|
6 | 6 | |
|
7 | 7 | class MomentsPlot(Figure): |
|
8 | 8 | |
|
9 | 9 | isConfig = None |
|
10 | 10 | __nsubplots = None |
|
11 | 11 | |
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'prm' |
|
15 | 15 | |
|
16 | 16 | def __init__(self): |
|
17 | 17 | |
|
18 | 18 | self.isConfig = False |
|
19 | 19 | self.__nsubplots = 1 |
|
20 | 20 | |
|
21 | 21 | self.WIDTH = 280 |
|
22 | 22 | self.HEIGHT = 250 |
|
23 | 23 | self.WIDTHPROF = 120 |
|
24 | 24 | self.HEIGHTPROF = 0 |
|
25 | 25 | self.counter_imagwr = 0 |
|
26 | 26 | |
|
27 | 27 | self.PLOT_CODE = 1 |
|
28 | 28 | self.FTP_WEI = None |
|
29 | 29 | self.EXP_CODE = None |
|
30 | 30 | self.SUB_EXP_CODE = None |
|
31 | 31 | self.PLOT_POS = None |
|
32 | 32 | |
|
33 | 33 | def getSubplots(self): |
|
34 | 34 | |
|
35 | 35 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
36 | 36 | nrow = int(self.nplots*1./ncol + 0.9) |
|
37 | 37 | |
|
38 | 38 | return nrow, ncol |
|
39 | 39 | |
|
40 | 40 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
41 | 41 | |
|
42 | 42 | self.__showprofile = showprofile |
|
43 | 43 | self.nplots = nplots |
|
44 | 44 | |
|
45 | 45 | ncolspan = 1 |
|
46 | 46 | colspan = 1 |
|
47 | 47 | if showprofile: |
|
48 | 48 | ncolspan = 3 |
|
49 | 49 | colspan = 2 |
|
50 | 50 | self.__nsubplots = 2 |
|
51 | 51 | |
|
52 | 52 | self.createFigure(id = id, |
|
53 | 53 | wintitle = wintitle, |
|
54 | 54 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
55 | 55 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
56 | 56 | show=show) |
|
57 | 57 | |
|
58 | 58 | nrow, ncol = self.getSubplots() |
|
59 | 59 | |
|
60 | 60 | counter = 0 |
|
61 | 61 | for y in range(nrow): |
|
62 | 62 | for x in range(ncol): |
|
63 | 63 | |
|
64 | 64 | if counter >= self.nplots: |
|
65 | 65 | break |
|
66 | 66 | |
|
67 | 67 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
68 | 68 | |
|
69 | 69 | if showprofile: |
|
70 | 70 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
71 | 71 | |
|
72 | 72 | counter += 1 |
|
73 | 73 | |
|
74 | 74 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
75 | 75 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
76 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
|
76 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
|
77 | 77 | server=None, folder=None, username=None, password=None, |
|
78 | 78 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
79 | 79 | |
|
80 | 80 | """ |
|
81 | 81 | |
|
82 | 82 | Input: |
|
83 | 83 | dataOut : |
|
84 | 84 | id : |
|
85 | 85 | wintitle : |
|
86 | 86 | channelList : |
|
87 | 87 | showProfile : |
|
88 | 88 | xmin : None, |
|
89 | 89 | xmax : None, |
|
90 | 90 | ymin : None, |
|
91 | 91 | ymax : None, |
|
92 | 92 | zmin : None, |
|
93 | 93 | zmax : None |
|
94 | 94 | """ |
|
95 | 95 | |
|
96 | 96 | if dataOut.flagNoData: |
|
97 | 97 | return None |
|
98 | 98 | |
|
99 | 99 | if realtime: |
|
100 | 100 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
101 | 101 | print 'Skipping this plot function' |
|
102 | 102 | return |
|
103 | 103 | |
|
104 | 104 | if channelList == None: |
|
105 | 105 | channelIndexList = dataOut.channelIndexList |
|
106 | 106 | else: |
|
107 | 107 | channelIndexList = [] |
|
108 | 108 | for channel in channelList: |
|
109 | 109 | if channel not in dataOut.channelList: |
|
110 | 110 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
111 | 111 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
112 | 112 | |
|
113 | 113 | factor = dataOut.normFactor |
|
114 | 114 | x = dataOut.abscissaList |
|
115 | 115 | y = dataOut.heightList |
|
116 | 116 | |
|
117 | 117 | z = dataOut.data_pre[channelIndexList,:,:]/factor |
|
118 | 118 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
119 | 119 | avg = numpy.average(z, axis=1) |
|
120 | 120 | noise = dataOut.noise/factor |
|
121 | 121 | |
|
122 | 122 | zdB = 10*numpy.log10(z) |
|
123 | 123 | avgdB = 10*numpy.log10(avg) |
|
124 | 124 | noisedB = 10*numpy.log10(noise) |
|
125 | 125 | |
|
126 | 126 | #thisDatetime = dataOut.datatime |
|
127 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
127 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
128 | 128 | title = wintitle + " Parameters" |
|
129 | 129 | xlabel = "Velocity (m/s)" |
|
130 | 130 | ylabel = "Range (Km)" |
|
131 | 131 | |
|
132 | 132 | if not self.isConfig: |
|
133 | 133 | |
|
134 | 134 | nplots = len(channelIndexList) |
|
135 | 135 | |
|
136 | 136 | self.setup(id=id, |
|
137 | 137 | nplots=nplots, |
|
138 | 138 | wintitle=wintitle, |
|
139 | 139 | showprofile=showprofile, |
|
140 | 140 | show=show) |
|
141 | 141 | |
|
142 | 142 | if xmin == None: xmin = numpy.nanmin(x) |
|
143 | 143 | if xmax == None: xmax = numpy.nanmax(x) |
|
144 | 144 | if ymin == None: ymin = numpy.nanmin(y) |
|
145 | 145 | if ymax == None: ymax = numpy.nanmax(y) |
|
146 | 146 | if zmin == None: zmin = numpy.nanmin(avgdB)*0.9 |
|
147 | 147 | if zmax == None: zmax = numpy.nanmax(avgdB)*0.9 |
|
148 | 148 | |
|
149 | 149 | self.FTP_WEI = ftp_wei |
|
150 | 150 | self.EXP_CODE = exp_code |
|
151 | 151 | self.SUB_EXP_CODE = sub_exp_code |
|
152 | 152 | self.PLOT_POS = plot_pos |
|
153 | 153 | |
|
154 | 154 | self.isConfig = True |
|
155 | 155 | |
|
156 | 156 | self.setWinTitle(title) |
|
157 | 157 | |
|
158 | 158 | for i in range(self.nplots): |
|
159 | 159 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
160 | 160 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
161 | 161 | axes = self.axesList[i*self.__nsubplots] |
|
162 | 162 | axes.pcolor(x, y, zdB[i,:,:], |
|
163 | 163 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
164 | 164 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
165 | 165 | ticksize=9, cblabel='') |
|
166 | 166 | #Mean Line |
|
167 | 167 | mean = dataOut.data_param[i, 1, :] |
|
168 | 168 | axes.addpline(mean, y, idline=0, color="black", linestyle="solid", lw=1) |
|
169 | 169 | |
|
170 | 170 | if self.__showprofile: |
|
171 | 171 | axes = self.axesList[i*self.__nsubplots +1] |
|
172 | 172 | axes.pline(avgdB[i], y, |
|
173 | 173 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
174 | 174 | xlabel='dB', ylabel='', title='', |
|
175 | 175 | ytick_visible=False, |
|
176 | 176 | grid='x') |
|
177 | 177 | |
|
178 | 178 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
179 | 179 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
180 | 180 | |
|
181 | 181 | self.draw() |
|
182 | 182 | |
|
183 |
if |
|
|
184 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
185 | figfile = self.getFilename(name = str_datetime) | |
|
186 | ||
|
187 | if figpath != '': | |
|
183 | if save: | |
|
184 | ||
|
185 | if figfile == None: | |
|
186 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
187 | figfile = self.getFilename(name = str_datetime) | |
|
188 | ||
|
188 | 189 | self.counter_imagwr += 1 |
|
189 | 190 | if (self.counter_imagwr>=wr_period): |
|
190 | 191 | # store png plot to local folder |
|
191 | 192 | self.saveFigure(figpath, figfile) |
|
192 | # store png plot to FTP server according to RT-Web format | |
|
193 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
194 | ftp_filename = os.path.join(figpath, name) | |
|
195 | self.saveFigure(figpath, ftp_filename) | |
|
196 | 193 | self.counter_imagwr = 0 |
|
194 | # store png plot to FTP server according to RT-Web format | |
|
195 | if ftp: | |
|
196 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
197 | ftp_filename = os.path.join(figpath, name) | |
|
198 | self.saveFigure(figpath, ftp_filename) | |
|
199 | ||
|
200 | ||
|
197 | 201 | |
|
198 | 202 | class SkyMapPlot(Figure): |
|
199 | 203 | |
|
200 | 204 | __isConfig = None |
|
201 | 205 | __nsubplots = None |
|
202 | 206 | |
|
203 | 207 | WIDTHPROF = None |
|
204 | 208 | HEIGHTPROF = None |
|
205 | 209 | PREFIX = 'prm' |
|
206 | 210 | |
|
207 | 211 | def __init__(self): |
|
208 | 212 | |
|
209 | 213 | self.__isConfig = False |
|
210 | 214 | self.__nsubplots = 1 |
|
211 | 215 | |
|
212 | 216 | # self.WIDTH = 280 |
|
213 | 217 | # self.HEIGHT = 250 |
|
214 | 218 | self.WIDTH = 600 |
|
215 | 219 | self.HEIGHT = 600 |
|
216 | 220 | self.WIDTHPROF = 120 |
|
217 | 221 | self.HEIGHTPROF = 0 |
|
218 | 222 | self.counter_imagwr = 0 |
|
219 | 223 | |
|
220 | 224 | self.PLOT_CODE = 1 |
|
221 | 225 | self.FTP_WEI = None |
|
222 | 226 | self.EXP_CODE = None |
|
223 | 227 | self.SUB_EXP_CODE = None |
|
224 | 228 | self.PLOT_POS = None |
|
225 | 229 | |
|
226 | 230 | def getSubplots(self): |
|
227 | 231 | |
|
228 | 232 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
229 | 233 | nrow = int(self.nplots*1./ncol + 0.9) |
|
230 | 234 | |
|
231 | 235 | return nrow, ncol |
|
232 | 236 | |
|
233 | 237 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
234 | 238 | |
|
235 | 239 | self.__showprofile = showprofile |
|
236 | 240 | self.nplots = nplots |
|
237 | 241 | |
|
238 | 242 | ncolspan = 1 |
|
239 | 243 | colspan = 1 |
|
240 | 244 | |
|
241 | 245 | self.createFigure(id = id, |
|
242 | 246 | wintitle = wintitle, |
|
243 | 247 | widthplot = self.WIDTH, #+ self.WIDTHPROF, |
|
244 | 248 | heightplot = self.HEIGHT,# + self.HEIGHTPROF, |
|
245 | 249 | show=show) |
|
246 | 250 | |
|
247 | 251 | nrow, ncol = 1,1 |
|
248 | 252 | counter = 0 |
|
249 | 253 | x = 0 |
|
250 | 254 | y = 0 |
|
251 | 255 | self.addAxes(1, 1, 0, 0, 1, 1, True) |
|
252 | 256 | |
|
253 | 257 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
254 | 258 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
255 | 259 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
256 | 260 | server=None, folder=None, username=None, password=None, |
|
257 | 261 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
258 | 262 | |
|
259 | 263 | """ |
|
260 | 264 | |
|
261 | 265 | Input: |
|
262 | 266 | dataOut : |
|
263 | 267 | id : |
|
264 | 268 | wintitle : |
|
265 | 269 | channelList : |
|
266 | 270 | showProfile : |
|
267 | 271 | xmin : None, |
|
268 | 272 | xmax : None, |
|
269 | 273 | ymin : None, |
|
270 | 274 | ymax : None, |
|
271 | 275 | zmin : None, |
|
272 | 276 | zmax : None |
|
273 | 277 | """ |
|
274 | 278 | |
|
275 | 279 | arrayParameters = dataOut.data_param |
|
276 | 280 | error = arrayParameters[:,-1] |
|
277 | 281 | indValid = numpy.where(error == 0)[0] |
|
278 | 282 | finalMeteor = arrayParameters[indValid,:] |
|
279 | 283 | finalAzimuth = finalMeteor[:,4] |
|
280 | 284 | finalZenith = finalMeteor[:,5] |
|
281 | 285 | |
|
282 | 286 | x = finalAzimuth*numpy.pi/180 |
|
283 | 287 | y = finalZenith |
|
284 | 288 | |
|
285 | 289 | |
|
286 | 290 | #thisDatetime = dataOut.datatime |
|
287 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
291 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
288 | 292 | title = wintitle + " Parameters" |
|
289 | 293 | xlabel = "Zonal Zenith Angle (deg) " |
|
290 | 294 | ylabel = "Meridional Zenith Angle (deg)" |
|
291 | 295 | |
|
292 | 296 | if not self.__isConfig: |
|
293 | 297 | |
|
294 | 298 | nplots = 1 |
|
295 | 299 | |
|
296 | 300 | self.setup(id=id, |
|
297 | 301 | nplots=nplots, |
|
298 | 302 | wintitle=wintitle, |
|
299 | 303 | showprofile=showprofile, |
|
300 | 304 | show=show) |
|
301 | 305 | |
|
302 | 306 | self.FTP_WEI = ftp_wei |
|
303 | 307 | self.EXP_CODE = exp_code |
|
304 | 308 | self.SUB_EXP_CODE = sub_exp_code |
|
305 | 309 | self.PLOT_POS = plot_pos |
|
306 | 310 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
307 | 311 | self.firstdate = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
308 | 312 | self.__isConfig = True |
|
309 | 313 | |
|
310 | 314 | self.setWinTitle(title) |
|
311 | 315 | |
|
312 | 316 | i = 0 |
|
313 | 317 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
314 | 318 | |
|
315 | 319 | axes = self.axesList[i*self.__nsubplots] |
|
316 | 320 | nevents = axes.x_buffer.shape[0] + x.shape[0] |
|
317 | 321 | title = "Meteor Detection Sky Map\n %s - %s \n Number of events: %5.0f\n" %(self.firstdate,str_datetime,nevents) |
|
318 | 322 | axes.polar(x, y, |
|
319 | 323 | title=title, xlabel=xlabel, ylabel=ylabel, |
|
320 | 324 | ticksize=9, cblabel='') |
|
321 | 325 | |
|
322 | 326 | self.draw() |
|
323 | 327 | |
|
324 | 328 | if save: |
|
325 | 329 | |
|
326 | 330 | self.counter_imagwr += 1 |
|
327 | 331 | if (self.counter_imagwr==wr_period): |
|
328 | 332 | |
|
329 | 333 | if figfile == None: |
|
330 | 334 | figfile = self.getFilename(name = self.name) |
|
335 | ||
|
331 | 336 | self.saveFigure(figpath, figfile) |
|
337 | self.counter_imagwr = 0 | |
|
332 | 338 | |
|
333 | 339 | if ftp: |
|
334 | 340 | #provisionalmente envia archivos en el formato de la web en tiempo real |
|
335 | 341 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) |
|
336 | 342 | path = '%s%03d' %(self.PREFIX, self.id) |
|
337 | 343 | ftp_file = os.path.join(path,'ftp','%s.png'%name) |
|
338 | 344 | self.saveFigure(figpath, ftp_file) |
|
339 | 345 | ftp_filename = os.path.join(figpath,ftp_file) |
|
340 | 346 | |
|
341 | 347 | |
|
342 | 348 | try: |
|
343 | 349 | self.sendByFTP(ftp_filename, server, folder, username, password) |
|
344 | 350 | except: |
|
345 | 351 | self.counter_imagwr = 0 |
|
346 | 352 | raise ValueError, 'Error FTP' |
|
347 | 353 | |
|
348 | self.counter_imagwr = 0 | |
|
354 | ||
|
349 | 355 | |
|
350 | 356 | |
|
351 | 357 | class WindProfilerPlot(Figure): |
|
352 | 358 | |
|
353 | 359 | __isConfig = None |
|
354 | 360 | __nsubplots = None |
|
355 | 361 | |
|
356 | 362 | WIDTHPROF = None |
|
357 | 363 | HEIGHTPROF = None |
|
358 | 364 | PREFIX = 'wind' |
|
359 | 365 | |
|
360 | 366 | def __init__(self): |
|
361 | 367 | |
|
362 | 368 | self.timerange = 2*60*60 |
|
363 | 369 | self.__isConfig = False |
|
364 | 370 | self.__nsubplots = 1 |
|
365 | 371 | |
|
366 | 372 | self.WIDTH = 800 |
|
367 | 373 | self.HEIGHT = 150 |
|
368 | 374 | self.WIDTHPROF = 120 |
|
369 | 375 | self.HEIGHTPROF = 0 |
|
370 | 376 | self.counter_imagwr = 0 |
|
371 | 377 | |
|
372 | 378 | self.PLOT_CODE = 0 |
|
373 | 379 | self.FTP_WEI = None |
|
374 | 380 | self.EXP_CODE = None |
|
375 | 381 | self.SUB_EXP_CODE = None |
|
376 | 382 | self.PLOT_POS = None |
|
377 | 383 | self.tmin = None |
|
378 | 384 | self.tmax = None |
|
379 | 385 | |
|
380 | 386 | self.xmin = None |
|
381 | 387 | self.xmax = None |
|
382 | 388 | |
|
383 | 389 | self.figfile = None |
|
384 | 390 | |
|
385 | 391 | def getSubplots(self): |
|
386 | 392 | |
|
387 | 393 | ncol = 1 |
|
388 | 394 | nrow = self.nplots |
|
389 | 395 | |
|
390 | 396 | return nrow, ncol |
|
391 | 397 | |
|
392 | 398 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
393 | 399 | |
|
394 | 400 | self.__showprofile = showprofile |
|
395 | 401 | self.nplots = nplots |
|
396 | 402 | |
|
397 | 403 | ncolspan = 1 |
|
398 | 404 | colspan = 1 |
|
399 | 405 | |
|
400 | 406 | self.createFigure(id = id, |
|
401 | 407 | wintitle = wintitle, |
|
402 | 408 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
403 | 409 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
404 | 410 | show=show) |
|
405 | 411 | |
|
406 | 412 | nrow, ncol = self.getSubplots() |
|
407 | 413 | |
|
408 | 414 | counter = 0 |
|
409 | 415 | for y in range(nrow): |
|
410 | 416 | if counter >= self.nplots: |
|
411 | 417 | break |
|
412 | 418 | |
|
413 | 419 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
414 | 420 | counter += 1 |
|
415 | 421 | |
|
416 | 422 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
417 | 423 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
418 | 424 | zmax_ver = None, zmin_ver = None, SNRmin = None, SNRmax = None, |
|
419 | 425 | timerange=None, SNRthresh = None, |
|
420 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
426 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
421 | 427 | server=None, folder=None, username=None, password=None, |
|
422 | 428 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
423 | 429 | """ |
|
424 | 430 | |
|
425 | 431 | Input: |
|
426 | 432 | dataOut : |
|
427 | 433 | id : |
|
428 | 434 | wintitle : |
|
429 | 435 | channelList : |
|
430 | 436 | showProfile : |
|
431 | 437 | xmin : None, |
|
432 | 438 | xmax : None, |
|
433 | 439 | ymin : None, |
|
434 | 440 | ymax : None, |
|
435 | 441 | zmin : None, |
|
436 | 442 | zmax : None |
|
437 | 443 | """ |
|
438 | 444 | |
|
439 | 445 | if channelList == None: |
|
440 | 446 | channelIndexList = dataOut.channelIndexList |
|
441 | 447 | else: |
|
442 | 448 | channelIndexList = [] |
|
443 | 449 | for channel in channelList: |
|
444 | 450 | if channel not in dataOut.channelList: |
|
445 | 451 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
446 | 452 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
447 | 453 | |
|
448 | 454 | if timerange != None: |
|
449 | 455 | self.timerange = timerange |
|
450 | 456 | |
|
451 | 457 | tmin = None |
|
452 | 458 | tmax = None |
|
453 | 459 | |
|
454 | 460 | x = dataOut.getTimeRange1() |
|
455 | 461 | # y = dataOut.heightList |
|
456 | 462 | y = dataOut.heightList |
|
457 | 463 | |
|
458 | 464 | z = dataOut.data_output.copy() |
|
459 | 465 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
460 | 466 | nplotsw = nplots |
|
461 | 467 | |
|
462 | 468 | #If there is a SNR function defined |
|
463 | 469 | if dataOut.data_SNR != None: |
|
464 | 470 | nplots += 1 |
|
465 | 471 | SNR = dataOut.data_SNR |
|
466 | 472 | SNRavg = numpy.average(SNR, axis=0) |
|
467 | 473 | |
|
468 | 474 | SNRdB = 10*numpy.log10(SNR) |
|
469 | 475 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
470 | 476 | |
|
471 | 477 | if SNRthresh == None: SNRthresh = -5.0 |
|
472 | 478 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
473 | 479 | |
|
474 | 480 | for i in range(nplotsw): |
|
475 | 481 | z[i,ind] = numpy.nan |
|
476 | 482 | |
|
477 | 483 | |
|
478 | 484 | showprofile = False |
|
479 | 485 | # thisDatetime = dataOut.datatime |
|
480 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
486 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
481 | 487 | title = wintitle + "Wind" |
|
482 | 488 | xlabel = "" |
|
483 | 489 | ylabel = "Range (Km)" |
|
484 | 490 | |
|
485 | 491 | if not self.__isConfig: |
|
486 | 492 | |
|
487 | 493 | self.setup(id=id, |
|
488 | 494 | nplots=nplots, |
|
489 | 495 | wintitle=wintitle, |
|
490 | 496 | showprofile=showprofile, |
|
491 | 497 | show=show) |
|
492 | 498 | |
|
493 | 499 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
494 | 500 | |
|
495 | 501 | if ymin == None: ymin = numpy.nanmin(y) |
|
496 | 502 | if ymax == None: ymax = numpy.nanmax(y) |
|
497 | 503 | |
|
498 | 504 | if zmax == None: zmax = numpy.nanmax(abs(z[range(2),:])) |
|
499 | 505 | #if numpy.isnan(zmax): zmax = 50 |
|
500 | 506 | if zmin == None: zmin = -zmax |
|
501 | 507 | |
|
502 | 508 | if nplotsw == 3: |
|
503 | 509 | if zmax_ver == None: zmax_ver = numpy.nanmax(abs(z[2,:])) |
|
504 | 510 | if zmin_ver == None: zmin_ver = -zmax_ver |
|
505 | 511 | |
|
506 | 512 | if dataOut.data_SNR != None: |
|
507 | 513 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
508 | 514 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
509 | 515 | |
|
510 | 516 | self.FTP_WEI = ftp_wei |
|
511 | 517 | self.EXP_CODE = exp_code |
|
512 | 518 | self.SUB_EXP_CODE = sub_exp_code |
|
513 | 519 | self.PLOT_POS = plot_pos |
|
514 | 520 | |
|
515 | 521 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
516 | 522 | self.__isConfig = True |
|
517 | 523 | |
|
518 | 524 | |
|
519 | 525 | self.setWinTitle(title) |
|
520 | 526 | |
|
521 | 527 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
522 | 528 | x[1] = self.xmax |
|
523 | 529 | |
|
524 | 530 | strWind = ['Zonal', 'Meridional', 'Vertical'] |
|
525 | 531 | strCb = ['Velocity (m/s)','Velocity (m/s)','Velocity (cm/s)'] |
|
526 | 532 | zmaxVector = [zmax, zmax, zmax_ver] |
|
527 | 533 | zminVector = [zmin, zmin, zmin_ver] |
|
528 | 534 | windFactor = [1,1,100] |
|
529 | 535 | |
|
530 | 536 | for i in range(nplotsw): |
|
531 | 537 | |
|
532 | 538 | title = "%s Wind: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
533 | 539 | axes = self.axesList[i*self.__nsubplots] |
|
534 | 540 | |
|
535 | 541 | z1 = z[i,:].reshape((1,-1))*windFactor[i] |
|
536 | 542 | |
|
537 | 543 | axes.pcolorbuffer(x, y, z1, |
|
538 | 544 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
539 | 545 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
540 | 546 | ticksize=9, cblabel=strCb[i], cbsize="1%", colormap="RdBu_r" ) |
|
541 | 547 | |
|
542 | 548 | if dataOut.data_SNR != None: |
|
543 | 549 | i += 1 |
|
544 | 550 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
545 | 551 | axes = self.axesList[i*self.__nsubplots] |
|
546 | 552 | |
|
547 | 553 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
548 | 554 | |
|
549 | 555 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
550 | 556 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
551 | 557 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
552 | 558 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
553 | 559 | |
|
554 | 560 | self.draw() |
|
555 | 561 | |
|
556 | if self.figfile == None: | |
|
557 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
558 | self.figfile = self.getFilename(name = str_datetime) | |
|
559 | ||
|
560 | if figpath != '': | |
|
562 | if save: | |
|
561 | 563 | |
|
564 | if self.figfile == None: | |
|
565 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
566 | self.figfile = self.getFilename(name = str_datetime) | |
|
567 | ||
|
562 | 568 | self.counter_imagwr += 1 |
|
569 | ||
|
563 | 570 | if (self.counter_imagwr>=wr_period): |
|
564 | 571 | # store png plot to local folder |
|
565 | 572 | self.saveFigure(figpath, self.figfile) |
|
566 | # store png plot to FTP server according to RT-Web format | |
|
567 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
568 | ftp_filename = os.path.join(figpath, name) | |
|
569 | self.saveFigure(figpath, ftp_filename) | |
|
570 | ||
|
571 | 573 | self.counter_imagwr = 0 |
|
574 | ||
|
575 | if ftp: | |
|
576 | # store png plot to FTP server according to RT-Web format | |
|
577 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
578 | ftp_filename = os.path.join(figpath, name) | |
|
579 | self.saveFigure(figpath, ftp_filename) | |
|
580 | ||
|
581 | ||
|
572 | 582 | |
|
573 | 583 | if x[1] >= self.axesList[0].xmax: |
|
574 | 584 | self.counter_imagwr = wr_period |
|
575 | 585 | self.__isConfig = False |
|
576 | 586 | self.figfile = None |
|
577 | 587 | |
|
578 | 588 | |
|
579 | 589 | class ParametersPlot(Figure): |
|
580 | 590 | |
|
581 | 591 | __isConfig = None |
|
582 | 592 | __nsubplots = None |
|
583 | 593 | |
|
584 | 594 | WIDTHPROF = None |
|
585 | 595 | HEIGHTPROF = None |
|
586 | 596 | PREFIX = 'prm' |
|
587 | 597 | |
|
588 | 598 | def __init__(self): |
|
589 | 599 | |
|
590 | 600 | self.timerange = 2*60*60 |
|
591 | 601 | self.__isConfig = False |
|
592 | 602 | self.__nsubplots = 1 |
|
593 | 603 | |
|
594 | 604 | self.WIDTH = 800 |
|
595 | 605 | self.HEIGHT = 150 |
|
596 | 606 | self.WIDTHPROF = 120 |
|
597 | 607 | self.HEIGHTPROF = 0 |
|
598 | 608 | self.counter_imagwr = 0 |
|
599 | 609 | |
|
600 | 610 | self.PLOT_CODE = 0 |
|
601 | 611 | self.FTP_WEI = None |
|
602 | 612 | self.EXP_CODE = None |
|
603 | 613 | self.SUB_EXP_CODE = None |
|
604 | 614 | self.PLOT_POS = None |
|
605 | 615 | self.tmin = None |
|
606 | 616 | self.tmax = None |
|
607 | 617 | |
|
608 | 618 | self.xmin = None |
|
609 | 619 | self.xmax = None |
|
610 | 620 | |
|
611 | 621 | self.figfile = None |
|
612 | 622 | |
|
613 | 623 | def getSubplots(self): |
|
614 | 624 | |
|
615 | 625 | ncol = 1 |
|
616 | 626 | nrow = self.nplots |
|
617 | 627 | |
|
618 | 628 | return nrow, ncol |
|
619 | 629 | |
|
620 | 630 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
621 | 631 | |
|
622 | 632 | self.__showprofile = showprofile |
|
623 | 633 | self.nplots = nplots |
|
624 | 634 | |
|
625 | 635 | ncolspan = 1 |
|
626 | 636 | colspan = 1 |
|
627 | 637 | |
|
628 | 638 | self.createFigure(id = id, |
|
629 | 639 | wintitle = wintitle, |
|
630 | 640 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
631 | 641 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
632 | 642 | show=show) |
|
633 | 643 | |
|
634 | 644 | nrow, ncol = self.getSubplots() |
|
635 | 645 | |
|
636 | 646 | counter = 0 |
|
637 | 647 | for y in range(nrow): |
|
638 | 648 | for x in range(ncol): |
|
639 | 649 | |
|
640 | 650 | if counter >= self.nplots: |
|
641 | 651 | break |
|
642 | 652 | |
|
643 | 653 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
644 | 654 | |
|
645 | 655 | if showprofile: |
|
646 | 656 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
647 | 657 | |
|
648 | 658 | counter += 1 |
|
649 | 659 | |
|
650 | 660 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
651 | 661 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None,timerange=None, |
|
652 | 662 | parameterIndex = None, onlyPositive = False, |
|
653 | 663 | SNRthresh = -numpy.inf, SNR = True, SNRmin = None, SNRmax = None, |
|
654 | ||
|
655 | 664 | zlabel = "", parameterName = "", parameterObject = "data_param", |
|
656 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
665 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
657 | 666 | server=None, folder=None, username=None, password=None, |
|
658 | 667 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
659 | 668 | |
|
660 | 669 | """ |
|
661 | 670 | |
|
662 | 671 | Input: |
|
663 | 672 | dataOut : |
|
664 | 673 | id : |
|
665 | 674 | wintitle : |
|
666 | 675 | channelList : |
|
667 | 676 | showProfile : |
|
668 | 677 | xmin : None, |
|
669 | 678 | xmax : None, |
|
670 | 679 | ymin : None, |
|
671 | 680 | ymax : None, |
|
672 | 681 | zmin : None, |
|
673 | 682 | zmax : None |
|
674 | 683 | """ |
|
675 | 684 | |
|
676 | 685 | data_param = getattr(dataOut, parameterObject) |
|
677 | 686 | |
|
678 | 687 | if channelList == None: |
|
679 | 688 | channelIndexList = numpy.arange(data_param.shape[0]) |
|
680 | 689 | else: |
|
681 | 690 | channelIndexList = numpy.array(channelList) |
|
682 | 691 | |
|
683 | 692 | nchan = len(channelIndexList) #Number of channels being plotted |
|
684 | 693 | |
|
685 | 694 | if timerange != None: |
|
686 | 695 | self.timerange = timerange |
|
687 | 696 | |
|
688 | 697 | #tmin = None |
|
689 | 698 | #tmax = None |
|
690 | 699 | if parameterIndex == None: |
|
691 | 700 | parameterIndex = 1 |
|
692 | 701 | x = dataOut.getTimeRange1() |
|
693 | 702 | y = dataOut.heightList |
|
694 | 703 | z = data_param[channelIndexList,parameterIndex,:].copy() |
|
695 | 704 | |
|
696 | 705 | zRange = dataOut.abscissaList |
|
697 | 706 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
698 | 707 | # thisDatetime = dataOut.datatime |
|
699 | 708 | |
|
700 | 709 | if dataOut.data_SNR != None: |
|
701 | 710 | SNRarray = dataOut.data_SNR[channelIndexList,:] |
|
702 | 711 | SNRdB = 10*numpy.log10(SNRarray) |
|
703 | 712 | # SNRavgdB = 10*numpy.log10(SNRavg) |
|
704 | 713 | ind = numpy.where(SNRdB < 10**(SNRthresh/10)) |
|
705 | 714 | z[ind] = numpy.nan |
|
706 | 715 | |
|
707 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
716 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
708 | 717 | title = wintitle + " Parameters Plot" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
709 | 718 | xlabel = "" |
|
710 | 719 | ylabel = "Range (Km)" |
|
711 | 720 | |
|
712 | 721 | if SNR: nplots = 2*nplots |
|
713 | 722 | |
|
714 | 723 | if onlyPositive: |
|
715 | 724 | colormap = "jet" |
|
716 | 725 | zmin = 0 |
|
717 | 726 | else: colormap = "RdBu_r" |
|
718 | 727 | |
|
719 | 728 | if not self.__isConfig: |
|
720 | 729 | |
|
721 | 730 | self.setup(id=id, |
|
722 | 731 | nplots=nplots, |
|
723 | 732 | wintitle=wintitle, |
|
724 | 733 | showprofile=showprofile, |
|
725 | 734 | show=show) |
|
726 | 735 | |
|
727 | 736 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
728 | 737 | |
|
729 | 738 | if ymin == None: ymin = numpy.nanmin(y) |
|
730 | 739 | if ymax == None: ymax = numpy.nanmax(y) |
|
731 | 740 | if zmin == None: zmin = numpy.nanmin(zRange) |
|
732 | 741 | if zmax == None: zmax = numpy.nanmax(zRange) |
|
733 | 742 | |
|
734 | 743 | if SNR != None: |
|
735 | 744 | if SNRmin == None: SNRmin = numpy.nanmin(SNRdB) |
|
736 | 745 | if SNRmax == None: SNRmax = numpy.nanmax(SNRdB) |
|
737 | 746 | |
|
738 | 747 | self.FTP_WEI = ftp_wei |
|
739 | 748 | self.EXP_CODE = exp_code |
|
740 | 749 | self.SUB_EXP_CODE = sub_exp_code |
|
741 | 750 | self.PLOT_POS = plot_pos |
|
742 | 751 | |
|
743 | 752 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
744 | 753 | self.__isConfig = True |
|
745 | 754 | self.figfile = figfile |
|
746 | 755 | |
|
747 | 756 | self.setWinTitle(title) |
|
748 | 757 | |
|
749 | 758 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
750 | 759 | x[1] = self.xmax |
|
751 | 760 | |
|
752 | 761 | for i in range(nchan): |
|
753 | 762 | if SNR: j = 2*i |
|
754 | 763 | else: j = i |
|
755 | 764 | |
|
756 | 765 | title = "%s Channel %d: %s" %(parameterName, channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
757 | 766 | |
|
758 | 767 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
759 | 768 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
760 | 769 | axes = self.axesList[j*self.__nsubplots] |
|
761 | 770 | z1 = z[i,:].reshape((1,-1)) |
|
762 | 771 | axes.pcolorbuffer(x, y, z1, |
|
763 | 772 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
764 | 773 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap=colormap, |
|
765 | 774 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
766 | 775 | |
|
767 | 776 | if SNR: |
|
768 | 777 | title = "Channel %d Signal Noise Ratio (SNR): %s" %(channelIndexList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
769 | 778 | axes = self.axesList[(j + 1)*self.__nsubplots] |
|
770 | 779 | z1 = SNRdB[i,:].reshape((1,-1)) |
|
771 | 780 | axes.pcolorbuffer(x, y, z1, |
|
772 | 781 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
773 | 782 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True,colormap="jet", |
|
774 | 783 | ticksize=9, cblabel=zlabel, cbsize="1%") |
|
775 | 784 | |
|
776 | 785 | |
|
777 | 786 | |
|
778 |
self.draw() |
|
|
779 | ||
|
780 | if self.figfile == None: | |
|
781 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
782 | self.figfile = self.getFilename(name = str_datetime) | |
|
787 | self.draw() | |
|
783 | 788 | |
|
784 |
if |
|
|
789 | if save: | |
|
785 | 790 | |
|
791 | if self.figfile == None: | |
|
792 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
793 | self.figfile = self.getFilename(name = str_datetime) | |
|
794 | ||
|
786 | 795 | self.counter_imagwr += 1 |
|
796 | ||
|
787 | 797 | if (self.counter_imagwr>=wr_period): |
|
788 | # store png plot to local folder | |
|
798 | # store png plot to local folder | |
|
789 | 799 | self.saveFigure(figpath, self.figfile) |
|
790 | # store png plot to FTP server according to RT-Web format | |
|
791 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
792 | ftp_filename = os.path.join(figpath, name) | |
|
793 | self.saveFigure(figpath, ftp_filename) | |
|
794 | ||
|
795 | 800 | self.counter_imagwr = 0 |
|
796 | ||
|
801 | ||
|
802 | if ftp: | |
|
803 | # store png plot to FTP server according to RT-Web format | |
|
804 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
805 | ftp_filename = os.path.join(figpath, name) | |
|
806 | self.saveFigure(figpath, ftp_filename) | |
|
807 | ||
|
797 | 808 | if x[1] >= self.axesList[0].xmax: |
|
798 | 809 | self.counter_imagwr = wr_period |
|
799 | 810 | self.__isConfig = False |
|
800 | 811 | self.figfile = None |
|
801 | 812 | |
|
802 | 813 | |
|
803 | 814 | class SpectralFittingPlot(Figure): |
|
804 | 815 | |
|
805 | 816 | __isConfig = None |
|
806 | 817 | __nsubplots = None |
|
807 | 818 | |
|
808 | 819 | WIDTHPROF = None |
|
809 | 820 | HEIGHTPROF = None |
|
810 | 821 | PREFIX = 'prm' |
|
811 | 822 | |
|
812 | 823 | |
|
813 | 824 | N = None |
|
814 | 825 | ippSeconds = None |
|
815 | 826 | |
|
816 | 827 | def __init__(self): |
|
817 | 828 | self.__isConfig = False |
|
818 | 829 | self.__nsubplots = 1 |
|
819 | 830 | |
|
820 | 831 | self.WIDTH = 450 |
|
821 | 832 | self.HEIGHT = 250 |
|
822 | 833 | self.WIDTHPROF = 0 |
|
823 | 834 | self.HEIGHTPROF = 0 |
|
824 | 835 | |
|
825 | 836 | def getSubplots(self): |
|
826 | 837 | |
|
827 | 838 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
828 | 839 | nrow = int(self.nplots*1./ncol + 0.9) |
|
829 | 840 | |
|
830 | 841 | return nrow, ncol |
|
831 | 842 | |
|
832 | 843 | def setup(self, id, nplots, wintitle, showprofile=False, show=True): |
|
833 | 844 | |
|
834 | 845 | showprofile = False |
|
835 | 846 | self.__showprofile = showprofile |
|
836 | 847 | self.nplots = nplots |
|
837 | 848 | |
|
838 | 849 | ncolspan = 5 |
|
839 | 850 | colspan = 4 |
|
840 | 851 | if showprofile: |
|
841 | 852 | ncolspan = 5 |
|
842 | 853 | colspan = 4 |
|
843 | 854 | self.__nsubplots = 2 |
|
844 | 855 | |
|
845 | 856 | self.createFigure(id = id, |
|
846 | 857 | wintitle = wintitle, |
|
847 | 858 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
848 | 859 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
849 | 860 | show=show) |
|
850 | 861 | |
|
851 | 862 | nrow, ncol = self.getSubplots() |
|
852 | 863 | |
|
853 | 864 | counter = 0 |
|
854 | 865 | for y in range(nrow): |
|
855 | 866 | for x in range(ncol): |
|
856 | 867 | |
|
857 | 868 | if counter >= self.nplots: |
|
858 | 869 | break |
|
859 | 870 | |
|
860 | 871 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
861 | 872 | |
|
862 | 873 | if showprofile: |
|
863 | 874 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
864 | 875 | |
|
865 | 876 | counter += 1 |
|
866 | 877 | |
|
867 | 878 | def run(self, dataOut, id, cutHeight=None, fit=False, wintitle="", channelList=None, showprofile=True, |
|
868 | 879 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
869 | 880 | save=False, figpath='./', figfile=None, show=True): |
|
870 | 881 | |
|
871 | 882 | """ |
|
872 | 883 | |
|
873 | 884 | Input: |
|
874 | 885 | dataOut : |
|
875 | 886 | id : |
|
876 | 887 | wintitle : |
|
877 | 888 | channelList : |
|
878 | 889 | showProfile : |
|
879 | 890 | xmin : None, |
|
880 | 891 | xmax : None, |
|
881 | 892 | zmin : None, |
|
882 | 893 | zmax : None |
|
883 | 894 | """ |
|
884 | 895 | |
|
885 | 896 | if cutHeight==None: |
|
886 | 897 | h=270 |
|
887 | 898 | heightindex = numpy.abs(cutHeight - dataOut.heightList).argmin() |
|
888 | 899 | cutHeight = dataOut.heightList[heightindex] |
|
889 | 900 | |
|
890 | 901 | factor = dataOut.normFactor |
|
891 | 902 | x = dataOut.abscissaList[:-1] |
|
892 | 903 | #y = dataOut.getHeiRange() |
|
893 | 904 | |
|
894 | 905 | z = dataOut.data_pre[:,:,heightindex]/factor |
|
895 | 906 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
896 | 907 | avg = numpy.average(z, axis=1) |
|
897 | 908 | listChannels = z.shape[0] |
|
898 | 909 | |
|
899 | 910 | #Reconstruct Function |
|
900 | 911 | if fit==True: |
|
901 | 912 | groupArray = dataOut.groupList |
|
902 | 913 | listChannels = groupArray.reshape((groupArray.size)) |
|
903 | 914 | listChannels.sort() |
|
904 | 915 | spcFitLine = numpy.zeros(z.shape) |
|
905 | 916 | constants = dataOut.constants |
|
906 | 917 | |
|
907 | 918 | nGroups = groupArray.shape[0] |
|
908 | 919 | nChannels = groupArray.shape[1] |
|
909 | 920 | nProfiles = z.shape[1] |
|
910 | 921 | |
|
911 | 922 | for f in range(nGroups): |
|
912 | 923 | groupChann = groupArray[f,:] |
|
913 | 924 | p = dataOut.data_param[f,:,heightindex] |
|
914 | 925 | # p = numpy.array([ 89.343967,0.14036615,0.17086219,18.89835291,1.58388365,1.55099167]) |
|
915 | 926 | fitLineAux = dataOut.library.modelFunction(p, constants)*nProfiles |
|
916 | 927 | fitLineAux = fitLineAux.reshape((nChannels,nProfiles)) |
|
917 | 928 | spcFitLine[groupChann,:] = fitLineAux |
|
918 | 929 | # spcFitLine = spcFitLine/factor |
|
919 | 930 | |
|
920 | 931 | z = z[listChannels,:] |
|
921 | 932 | spcFitLine = spcFitLine[listChannels,:] |
|
922 | 933 | spcFitLinedB = 10*numpy.log10(spcFitLine) |
|
923 | 934 | |
|
924 | 935 | zdB = 10*numpy.log10(z) |
|
925 | 936 | #thisDatetime = dataOut.datatime |
|
926 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
937 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
927 | 938 | title = wintitle + " Doppler Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
928 | 939 | xlabel = "Velocity (m/s)" |
|
929 | 940 | ylabel = "Spectrum" |
|
930 | 941 | |
|
931 | 942 | if not self.__isConfig: |
|
932 | 943 | |
|
933 | 944 | nplots = listChannels.size |
|
934 | 945 | |
|
935 | 946 | self.setup(id=id, |
|
936 | 947 | nplots=nplots, |
|
937 | 948 | wintitle=wintitle, |
|
938 | 949 | showprofile=showprofile, |
|
939 | 950 | show=show) |
|
940 | 951 | |
|
941 | 952 | if xmin == None: xmin = numpy.nanmin(x) |
|
942 | 953 | if xmax == None: xmax = numpy.nanmax(x) |
|
943 | 954 | if ymin == None: ymin = numpy.nanmin(zdB) |
|
944 | 955 | if ymax == None: ymax = numpy.nanmax(zdB)+2 |
|
945 | 956 | |
|
946 | 957 | self.__isConfig = True |
|
947 | 958 | |
|
948 | 959 | self.setWinTitle(title) |
|
949 | 960 | for i in range(self.nplots): |
|
950 | 961 | # title = "Channel %d: %4.2fdB" %(dataOut.channelList[i]+1, noisedB[i]) |
|
951 | 962 | title = "Height %4.1f km\nChannel %d:" %(cutHeight, listChannels[i]+1) |
|
952 | 963 | axes = self.axesList[i*self.__nsubplots] |
|
953 | 964 | if fit == False: |
|
954 | 965 | axes.pline(x, zdB[i,:], |
|
955 | 966 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
956 | 967 | xlabel=xlabel, ylabel=ylabel, title=title |
|
957 | 968 | ) |
|
958 | 969 | if fit == True: |
|
959 | 970 | fitline=spcFitLinedB[i,:] |
|
960 | 971 | y=numpy.vstack([zdB[i,:],fitline] ) |
|
961 | 972 | legendlabels=['Data','Fitting'] |
|
962 | 973 | axes.pmultilineyaxis(x, y, |
|
963 | 974 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
964 | 975 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
965 | 976 | legendlabels=legendlabels, marker=None, |
|
966 | 977 | linestyle='solid', grid='both') |
|
967 | 978 | |
|
968 | 979 | self.draw() |
|
969 | 980 | |
|
970 | 981 | if save: |
|
971 | 982 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
972 | 983 | if figfile == None: |
|
973 | 984 | figfile = self.getFilename(name = date) |
|
974 | 985 | |
|
975 | 986 | self.saveFigure(figpath, figfile) |
|
976 | 987 | |
|
977 | 988 | |
|
978 | 989 | class EWDriftsPlot(Figure): |
|
979 | 990 | |
|
980 | 991 | __isConfig = None |
|
981 | 992 | __nsubplots = None |
|
982 | 993 | |
|
983 | 994 | WIDTHPROF = None |
|
984 | 995 | HEIGHTPROF = None |
|
985 | 996 | PREFIX = 'drift' |
|
986 | 997 | |
|
987 | 998 | def __init__(self): |
|
988 | 999 | |
|
989 | 1000 | self.timerange = 2*60*60 |
|
990 | 1001 | self.isConfig = False |
|
991 | 1002 | self.__nsubplots = 1 |
|
992 | 1003 | |
|
993 | 1004 | self.WIDTH = 800 |
|
994 | 1005 | self.HEIGHT = 150 |
|
995 | 1006 | self.WIDTHPROF = 120 |
|
996 | 1007 | self.HEIGHTPROF = 0 |
|
997 | 1008 | self.counter_imagwr = 0 |
|
998 | 1009 | |
|
999 | 1010 | self.PLOT_CODE = 0 |
|
1000 | 1011 | self.FTP_WEI = None |
|
1001 | 1012 | self.EXP_CODE = None |
|
1002 | 1013 | self.SUB_EXP_CODE = None |
|
1003 | 1014 | self.PLOT_POS = None |
|
1004 | 1015 | self.tmin = None |
|
1005 | 1016 | self.tmax = None |
|
1006 | 1017 | |
|
1007 | 1018 | self.xmin = None |
|
1008 | 1019 | self.xmax = None |
|
1009 | 1020 | |
|
1010 | 1021 | self.figfile = None |
|
1011 | 1022 | |
|
1012 | 1023 | def getSubplots(self): |
|
1013 | 1024 | |
|
1014 | 1025 | ncol = 1 |
|
1015 | 1026 | nrow = self.nplots |
|
1016 | 1027 | |
|
1017 | 1028 | return nrow, ncol |
|
1018 | 1029 | |
|
1019 | 1030 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1020 | 1031 | |
|
1021 | 1032 | self.__showprofile = showprofile |
|
1022 | 1033 | self.nplots = nplots |
|
1023 | 1034 | |
|
1024 | 1035 | ncolspan = 1 |
|
1025 | 1036 | colspan = 1 |
|
1026 | 1037 | |
|
1027 | 1038 | self.createFigure(id = id, |
|
1028 | 1039 | wintitle = wintitle, |
|
1029 | 1040 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
1030 | 1041 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
1031 | 1042 | show=show) |
|
1032 | 1043 | |
|
1033 | 1044 | nrow, ncol = self.getSubplots() |
|
1034 | 1045 | |
|
1035 | 1046 | counter = 0 |
|
1036 | 1047 | for y in range(nrow): |
|
1037 | 1048 | if counter >= self.nplots: |
|
1038 | 1049 | break |
|
1039 | 1050 | |
|
1040 | 1051 | self.addAxes(nrow, ncol*ncolspan, y, 0, colspan, 1) |
|
1041 | 1052 | counter += 1 |
|
1042 | 1053 | |
|
1043 | 1054 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
1044 | 1055 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
1045 | 1056 | zmaxVertical = None, zminVertical = None, zmaxZonal = None, zminZonal = None, |
|
1046 | 1057 | timerange=None, SNRthresh = -numpy.inf, SNRmin = None, SNRmax = None, SNR_1 = False, |
|
1047 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
1058 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
1048 | 1059 | server=None, folder=None, username=None, password=None, |
|
1049 | 1060 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1050 | 1061 | """ |
|
1051 | 1062 | |
|
1052 | 1063 | Input: |
|
1053 | 1064 | dataOut : |
|
1054 | 1065 | id : |
|
1055 | 1066 | wintitle : |
|
1056 | 1067 | channelList : |
|
1057 | 1068 | showProfile : |
|
1058 | 1069 | xmin : None, |
|
1059 | 1070 | xmax : None, |
|
1060 | 1071 | ymin : None, |
|
1061 | 1072 | ymax : None, |
|
1062 | 1073 | zmin : None, |
|
1063 | 1074 | zmax : None |
|
1064 | 1075 | """ |
|
1065 | 1076 | |
|
1066 | 1077 | if timerange != None: |
|
1067 | 1078 | self.timerange = timerange |
|
1068 | 1079 | |
|
1069 | 1080 | tmin = None |
|
1070 | 1081 | tmax = None |
|
1071 | 1082 | |
|
1072 | 1083 | x = dataOut.getTimeRange1() |
|
1073 | 1084 | # y = dataOut.heightList |
|
1074 | 1085 | y = dataOut.heightList |
|
1075 | 1086 | |
|
1076 | 1087 | z = dataOut.data_output |
|
1077 | 1088 | nplots = z.shape[0] #Number of wind dimensions estimated |
|
1078 | 1089 | nplotsw = nplots |
|
1079 | 1090 | |
|
1080 | 1091 | #If there is a SNR function defined |
|
1081 | 1092 | if dataOut.data_SNR != None: |
|
1082 | 1093 | nplots += 1 |
|
1083 | 1094 | SNR = dataOut.data_SNR |
|
1084 | 1095 | |
|
1085 | 1096 | if SNR_1: |
|
1086 | 1097 | SNR += 1 |
|
1087 | 1098 | |
|
1088 | 1099 | SNRavg = numpy.average(SNR, axis=0) |
|
1089 | 1100 | |
|
1090 | 1101 | SNRdB = 10*numpy.log10(SNR) |
|
1091 | 1102 | SNRavgdB = 10*numpy.log10(SNRavg) |
|
1092 | 1103 | |
|
1093 | 1104 | ind = numpy.where(SNRavg < 10**(SNRthresh/10))[0] |
|
1094 | 1105 | |
|
1095 | 1106 | for i in range(nplotsw): |
|
1096 | 1107 | z[i,ind] = numpy.nan |
|
1097 | 1108 | |
|
1098 | 1109 | |
|
1099 | 1110 | showprofile = False |
|
1100 | 1111 | # thisDatetime = dataOut.datatime |
|
1101 | 1112 | thisDatetime = datetime.datetime.utcfromtimestamp(x[1]) |
|
1102 | 1113 | title = wintitle + " EW Drifts" |
|
1103 | 1114 | xlabel = "" |
|
1104 | 1115 | ylabel = "Height (Km)" |
|
1105 | 1116 | |
|
1106 | 1117 | if not self.__isConfig: |
|
1107 | 1118 | |
|
1108 | 1119 | self.setup(id=id, |
|
1109 | 1120 | nplots=nplots, |
|
1110 | 1121 | wintitle=wintitle, |
|
1111 | 1122 | showprofile=showprofile, |
|
1112 | 1123 | show=show) |
|
1113 | 1124 | |
|
1114 | 1125 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
1115 | 1126 | |
|
1116 | 1127 | if ymin == None: ymin = numpy.nanmin(y) |
|
1117 | 1128 | if ymax == None: ymax = numpy.nanmax(y) |
|
1118 | 1129 | |
|
1119 | 1130 | if zmaxZonal == None: zmaxZonal = numpy.nanmax(abs(z[0,:])) |
|
1120 | 1131 | if zminZonal == None: zminZonal = -zmaxZonal |
|
1121 | 1132 | if zmaxVertical == None: zmaxVertical = numpy.nanmax(abs(z[1,:])) |
|
1122 | 1133 | if zminVertical == None: zminVertical = -zmaxVertical |
|
1123 | 1134 | |
|
1124 | 1135 | if dataOut.data_SNR != None: |
|
1125 | 1136 | if SNRmin == None: SNRmin = numpy.nanmin(SNRavgdB) |
|
1126 | 1137 | if SNRmax == None: SNRmax = numpy.nanmax(SNRavgdB) |
|
1127 | 1138 | |
|
1128 | 1139 | self.FTP_WEI = ftp_wei |
|
1129 | 1140 | self.EXP_CODE = exp_code |
|
1130 | 1141 | self.SUB_EXP_CODE = sub_exp_code |
|
1131 | 1142 | self.PLOT_POS = plot_pos |
|
1132 | 1143 | |
|
1133 | 1144 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1134 | 1145 | self.__isConfig = True |
|
1135 | 1146 | |
|
1136 | 1147 | |
|
1137 | 1148 | self.setWinTitle(title) |
|
1138 | 1149 | |
|
1139 | 1150 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
1140 | 1151 | x[1] = self.xmax |
|
1141 | 1152 | |
|
1142 | 1153 | strWind = ['Zonal','Vertical'] |
|
1143 | 1154 | strCb = 'Velocity (m/s)' |
|
1144 | 1155 | zmaxVector = [zmaxZonal, zmaxVertical] |
|
1145 | 1156 | zminVector = [zminZonal, zminVertical] |
|
1146 | 1157 | |
|
1147 | 1158 | for i in range(nplotsw): |
|
1148 | 1159 | |
|
1149 | 1160 | title = "%s Drifts: %s" %(strWind[i], thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1150 | 1161 | axes = self.axesList[i*self.__nsubplots] |
|
1151 | 1162 | |
|
1152 | 1163 | z1 = z[i,:].reshape((1,-1)) |
|
1153 | 1164 | |
|
1154 | 1165 | axes.pcolorbuffer(x, y, z1, |
|
1155 | 1166 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zminVector[i], zmax=zmaxVector[i], |
|
1156 | 1167 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1157 | 1168 | ticksize=9, cblabel=strCb, cbsize="1%", colormap="RdBu_r") |
|
1158 | 1169 | |
|
1159 | 1170 | if dataOut.data_SNR != None: |
|
1160 | 1171 | i += 1 |
|
1161 | 1172 | if SNR_1: |
|
1162 | 1173 | title = "Signal Noise Ratio + 1 (SNR+1): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1163 | 1174 | else: |
|
1164 | 1175 | title = "Signal Noise Ratio (SNR): %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1165 | 1176 | axes = self.axesList[i*self.__nsubplots] |
|
1166 | 1177 | SNRavgdB = SNRavgdB.reshape((1,-1)) |
|
1167 | 1178 | |
|
1168 | 1179 | axes.pcolorbuffer(x, y, SNRavgdB, |
|
1169 | 1180 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=SNRmin, zmax=SNRmax, |
|
1170 | 1181 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
1171 | 1182 | ticksize=9, cblabel='', cbsize="1%", colormap="jet") |
|
1172 | 1183 | |
|
1173 | 1184 | self.draw() |
|
1174 | ||
|
1175 | if self.figfile == None: | |
|
1176 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
1177 | self.figfile = self.getFilename(name = str_datetime) | |
|
1178 | 1185 | |
|
1179 |
if |
|
|
1186 | if save: | |
|
1180 | 1187 | |
|
1188 | if self.figfile == None: | |
|
1189 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
1190 | self.figfile = self.getFilename(name = str_datetime) | |
|
1191 | ||
|
1181 | 1192 | self.counter_imagwr += 1 |
|
1193 | ||
|
1182 | 1194 | if (self.counter_imagwr>=wr_period): |
|
1183 | # store png plot to local folder | |
|
1195 | # store png plot to local folder | |
|
1184 | 1196 | self.saveFigure(figpath, self.figfile) |
|
1185 | # store png plot to FTP server according to RT-Web format | |
|
1186 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
1187 | ftp_filename = os.path.join(figpath, name) | |
|
1188 | self.saveFigure(figpath, ftp_filename) | |
|
1189 | ||
|
1190 | 1197 | self.counter_imagwr = 0 |
|
1198 | ||
|
1199 | if ftp: | |
|
1200 | # store png plot to FTP server according to RT-Web format | |
|
1201 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
1202 | ftp_filename = os.path.join(figpath, name) | |
|
1203 | self.saveFigure(figpath, ftp_filename) | |
|
1191 | 1204 | |
|
1192 | 1205 | if x[1] >= self.axesList[0].xmax: |
|
1193 | 1206 | self.counter_imagwr = wr_period |
|
1194 | 1207 | self.__isConfig = False |
|
1195 | 1208 | self.figfile = None No newline at end of file |
@@ -1,1356 +1,1375 | |||
|
1 | 1 | ''' |
|
2 | @author: Daniel Suarez | |
|
2 | Created on Jul 9, 2014 | |
|
3 | ||
|
4 | @author: roj-idl71 | |
|
3 | 5 | ''' |
|
4 | 6 | import os |
|
5 | 7 | import datetime |
|
6 | 8 | import numpy |
|
7 | 9 | |
|
8 | 10 | from figure import Figure, isRealtime |
|
9 | 11 | |
|
10 | 12 | class SpectraPlot(Figure): |
|
11 | 13 | |
|
12 | 14 | isConfig = None |
|
13 | 15 | __nsubplots = None |
|
14 | 16 | |
|
15 | 17 | WIDTHPROF = None |
|
16 | 18 | HEIGHTPROF = None |
|
17 | 19 | PREFIX = 'spc' |
|
18 | 20 | |
|
19 | 21 | def __init__(self): |
|
20 | 22 | |
|
21 | 23 | self.isConfig = False |
|
22 | 24 | self.__nsubplots = 1 |
|
23 | 25 | |
|
24 | 26 | self.WIDTH = 280 |
|
25 | 27 | self.HEIGHT = 250 |
|
26 | 28 | self.WIDTHPROF = 120 |
|
27 | 29 | self.HEIGHTPROF = 0 |
|
28 | 30 | self.counter_imagwr = 0 |
|
29 | 31 | |
|
30 | 32 | self.PLOT_CODE = 1 |
|
31 | 33 | self.FTP_WEI = None |
|
32 | 34 | self.EXP_CODE = None |
|
33 | 35 | self.SUB_EXP_CODE = None |
|
34 | 36 | self.PLOT_POS = None |
|
35 | 37 | |
|
38 | self.__xfilter_ena = False | |
|
39 | self.__yfilter_ena = False | |
|
40 | ||
|
36 | 41 | def getSubplots(self): |
|
37 | 42 | |
|
38 | 43 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
39 | 44 | nrow = int(self.nplots*1./ncol + 0.9) |
|
40 | 45 | |
|
41 | 46 | return nrow, ncol |
|
42 | 47 | |
|
43 | 48 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
44 | 49 | |
|
45 | 50 | self.__showprofile = showprofile |
|
46 | 51 | self.nplots = nplots |
|
47 | 52 | |
|
48 | 53 | ncolspan = 1 |
|
49 | 54 | colspan = 1 |
|
50 | 55 | if showprofile: |
|
51 | 56 | ncolspan = 3 |
|
52 | 57 | colspan = 2 |
|
53 | 58 | self.__nsubplots = 2 |
|
54 | 59 | |
|
55 | 60 | self.createFigure(id = id, |
|
56 | 61 | wintitle = wintitle, |
|
57 | 62 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
58 | 63 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
59 | 64 | show=show) |
|
60 | 65 | |
|
61 | 66 | nrow, ncol = self.getSubplots() |
|
62 | 67 | |
|
63 | 68 | counter = 0 |
|
64 | 69 | for y in range(nrow): |
|
65 | 70 | for x in range(ncol): |
|
66 | 71 | |
|
67 | 72 | if counter >= self.nplots: |
|
68 | 73 | break |
|
69 | 74 | |
|
70 | 75 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
71 | 76 | |
|
72 | 77 | if showprofile: |
|
73 | 78 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
74 | 79 | |
|
75 | 80 | counter += 1 |
|
76 | 81 | |
|
77 | 82 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=True, |
|
78 | 83 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
79 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
|
84 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
|
80 | 85 | server=None, folder=None, username=None, password=None, |
|
81 | 86 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
82 | 87 | |
|
83 | 88 | """ |
|
84 | 89 | |
|
85 | 90 | Input: |
|
86 | 91 | dataOut : |
|
87 | 92 | id : |
|
88 | 93 | wintitle : |
|
89 | 94 | channelList : |
|
90 | 95 | showProfile : |
|
91 | 96 | xmin : None, |
|
92 | 97 | xmax : None, |
|
93 | 98 | ymin : None, |
|
94 | 99 | ymax : None, |
|
95 | 100 | zmin : None, |
|
96 | 101 | zmax : None |
|
97 | 102 | """ |
|
98 | 103 | |
|
99 | if dataOut.flagNoData: | |
|
100 | return None | |
|
101 | ||
|
102 | 104 | if realtime: |
|
103 | 105 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
104 | 106 | print 'Skipping this plot function' |
|
105 | 107 | return |
|
106 | 108 | |
|
107 | 109 | if channelList == None: |
|
108 | 110 | channelIndexList = dataOut.channelIndexList |
|
109 | 111 | else: |
|
110 | 112 | channelIndexList = [] |
|
111 | 113 | for channel in channelList: |
|
112 | 114 | if channel not in dataOut.channelList: |
|
113 | 115 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
114 | 116 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
115 | 117 | |
|
116 | 118 | factor = dataOut.normFactor |
|
117 | 119 | |
|
118 | 120 | x = dataOut.getVelRange(1) |
|
119 | 121 | y = dataOut.getHeiRange() |
|
120 | 122 | |
|
121 | 123 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
122 | 124 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
123 | avg = numpy.average(z, axis=1) | |
|
124 | #avg = numpy.nanmean(z, axis=1) | |
|
125 | noise = dataOut.noise/factor | |
|
126 | ||
|
127 | 125 | zdB = 10*numpy.log10(z) |
|
126 | ||
|
127 | avg = numpy.nanmean(z, axis=1) | |
|
128 | 128 | avgdB = 10*numpy.log10(avg) |
|
129 | ||
|
130 | noise = dataOut.getNoise()/factor | |
|
129 | 131 | noisedB = 10*numpy.log10(noise) |
|
130 | 132 | |
|
131 | #thisDatetime = dataOut.datatime | |
|
132 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[1]) | |
|
133 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
133 | 134 | title = wintitle + " Spectra" |
|
134 | 135 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
135 | 136 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
136 | 137 | |
|
137 | 138 | xlabel = "Velocity (m/s)" |
|
138 | 139 | ylabel = "Range (Km)" |
|
139 | 140 | |
|
140 | 141 | if not self.isConfig: |
|
141 | 142 | |
|
142 | 143 | nplots = len(channelIndexList) |
|
143 | 144 | |
|
144 | 145 | self.setup(id=id, |
|
145 | 146 | nplots=nplots, |
|
146 | 147 | wintitle=wintitle, |
|
147 | 148 | showprofile=showprofile, |
|
148 | 149 | show=show) |
|
149 | 150 | |
|
150 | 151 | if xmin == None: xmin = numpy.nanmin(x) |
|
151 | 152 | if xmax == None: xmax = numpy.nanmax(x) |
|
152 | 153 | if ymin == None: ymin = numpy.nanmin(y) |
|
153 | 154 | if ymax == None: ymax = numpy.nanmax(y) |
|
154 |
if zmin == None: zmin = numpy.nanmin( |
|
|
155 |
if zmax == None: zmax = numpy.nanmax(avgdB) |
|
|
156 | ||
|
155 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
|
156 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
|
157 | ||
|
157 | 158 | self.FTP_WEI = ftp_wei |
|
158 | 159 | self.EXP_CODE = exp_code |
|
159 | 160 | self.SUB_EXP_CODE = sub_exp_code |
|
160 | 161 | self.PLOT_POS = plot_pos |
|
161 | 162 | |
|
162 | 163 | self.isConfig = True |
|
163 | 164 | |
|
164 | 165 | self.setWinTitle(title) |
|
165 | 166 | |
|
166 | 167 | for i in range(self.nplots): |
|
167 | 168 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
168 | 169 | title = "Channel %d: %4.2fdB: %s" %(dataOut.channelList[i]+1, noisedB[i], str_datetime) |
|
169 | 170 | if len(dataOut.beam.codeList) != 0: |
|
170 | 171 | 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 | 172 | |
|
172 | 173 | axes = self.axesList[i*self.__nsubplots] |
|
173 | 174 | axes.pcolor(x, y, zdB[i,:,:], |
|
174 | 175 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
175 | 176 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
176 | 177 | ticksize=9, cblabel='') |
|
177 | 178 | |
|
178 | 179 | if self.__showprofile: |
|
179 | 180 | axes = self.axesList[i*self.__nsubplots +1] |
|
180 | axes.pline(avgdB[i], y, | |
|
181 | axes.pline(avgdB[i,:], y, | |
|
181 | 182 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
182 | 183 | xlabel='dB', ylabel='', title='', |
|
183 | 184 | ytick_visible=False, |
|
184 | 185 | grid='x') |
|
185 | 186 | |
|
186 | 187 | noiseline = numpy.repeat(noisedB[i], len(y)) |
|
187 | 188 | axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
188 | 189 | |
|
189 | 190 | self.draw() |
|
190 | ||
|
191 |
if |
|
|
192 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
193 | figfile = self.getFilename(name = str_datetime) | |
|
194 | name = str_datetime | |
|
195 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
|
196 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) | |
|
197 | figfile = self.getFilename(name) | |
|
198 | if figpath != '': | |
|
191 | ||
|
192 | if save: | |
|
193 | ||
|
194 | if figfile == None: | |
|
195 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
196 | figfile = self.getFilename(name = str_datetime) | |
|
197 | name = str_datetime | |
|
198 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): | |
|
199 | name = name + '_az' + '_%2.2f'%(dataOut.azimuth) + '_zn' + '_%2.2f'%(dataOut.zenith) | |
|
200 | figfile = self.getFilename(name) | |
|
201 | ||
|
199 | 202 | self.counter_imagwr += 1 |
|
203 | ||
|
200 | 204 | if (self.counter_imagwr>=wr_period): |
|
201 | # store png plot to local folder | |
|
205 | # store png plot to local folder | |
|
202 | 206 | self.saveFigure(figpath, figfile) |
|
203 | # store png plot to FTP server according to RT-Web format | |
|
204 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
205 | ftp_filename = os.path.join(figpath, name) | |
|
206 | self.saveFigure(figpath, ftp_filename) | |
|
207 | 207 | self.counter_imagwr = 0 |
|
208 | ||
|
209 | if ftp: | |
|
210 | # store png plot to FTP server according to RT-Web format | |
|
211 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
212 | ftp_filename = os.path.join(figpath, name) | |
|
213 | self.saveFigure(figpath, ftp_filename) | |
|
214 | ||
|
208 | 215 | |
|
209 | 216 | |
|
210 | 217 | class CrossSpectraPlot(Figure): |
|
211 | 218 | |
|
212 | 219 | isConfig = None |
|
213 | 220 | __nsubplots = None |
|
214 | 221 | |
|
215 | 222 | WIDTH = None |
|
216 | 223 | HEIGHT = None |
|
217 | 224 | WIDTHPROF = None |
|
218 | 225 | HEIGHTPROF = None |
|
219 | 226 | PREFIX = 'cspc' |
|
220 | 227 | |
|
221 | 228 | def __init__(self): |
|
222 | 229 | |
|
223 | 230 | self.isConfig = False |
|
224 | 231 | self.__nsubplots = 4 |
|
225 | 232 | self.counter_imagwr = 0 |
|
226 | 233 | self.WIDTH = 250 |
|
227 | 234 | self.HEIGHT = 250 |
|
228 | 235 | self.WIDTHPROF = 0 |
|
229 | 236 | self.HEIGHTPROF = 0 |
|
230 | 237 | |
|
231 | 238 | self.PLOT_CODE = 1 |
|
232 | 239 | self.FTP_WEI = None |
|
233 | 240 | self.EXP_CODE = None |
|
234 | 241 | self.SUB_EXP_CODE = None |
|
235 | 242 | self.PLOT_POS = None |
|
236 | 243 | |
|
237 | 244 | def getSubplots(self): |
|
238 | 245 | |
|
239 | 246 | ncol = 4 |
|
240 | 247 | nrow = self.nplots |
|
241 | 248 | |
|
242 | 249 | return nrow, ncol |
|
243 | 250 | |
|
244 | 251 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
245 | 252 | |
|
246 | 253 | self.__showprofile = showprofile |
|
247 | 254 | self.nplots = nplots |
|
248 | 255 | |
|
249 | 256 | ncolspan = 1 |
|
250 | 257 | colspan = 1 |
|
251 | 258 | |
|
252 | 259 | self.createFigure(id = id, |
|
253 | 260 | wintitle = wintitle, |
|
254 | 261 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
255 | 262 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
256 | 263 | show=True) |
|
257 | 264 | |
|
258 | 265 | nrow, ncol = self.getSubplots() |
|
259 | 266 | |
|
260 | 267 | counter = 0 |
|
261 | 268 | for y in range(nrow): |
|
262 | 269 | for x in range(ncol): |
|
263 | 270 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
264 | 271 | |
|
265 | 272 | counter += 1 |
|
266 | 273 | |
|
267 | 274 | def run(self, dataOut, id, wintitle="", pairsList=None, |
|
268 | 275 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
269 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, | |
|
276 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
|
270 | 277 | power_cmap='jet', coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
271 | 278 | server=None, folder=None, username=None, password=None, |
|
272 | 279 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
273 | 280 | |
|
274 | 281 | """ |
|
275 | 282 | |
|
276 | 283 | Input: |
|
277 | 284 | dataOut : |
|
278 | 285 | id : |
|
279 | 286 | wintitle : |
|
280 | 287 | channelList : |
|
281 | 288 | showProfile : |
|
282 | 289 | xmin : None, |
|
283 | 290 | xmax : None, |
|
284 | 291 | ymin : None, |
|
285 | 292 | ymax : None, |
|
286 | 293 | zmin : None, |
|
287 | 294 | zmax : None |
|
288 | 295 | """ |
|
289 | 296 | |
|
290 | 297 | if pairsList == None: |
|
291 | 298 | pairsIndexList = dataOut.pairsIndexList |
|
292 | 299 | else: |
|
293 | 300 | pairsIndexList = [] |
|
294 | 301 | for pair in pairsList: |
|
295 | 302 | if pair not in dataOut.pairsList: |
|
296 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) | |
|
303 | raise ValueError, "Pair %s is not in dataOut.pairsList" %str(pair) | |
|
297 | 304 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
298 | 305 | |
|
299 | 306 | if pairsIndexList == []: |
|
300 | 307 | return |
|
301 | 308 | |
|
302 | 309 | if len(pairsIndexList) > 4: |
|
303 | 310 | pairsIndexList = pairsIndexList[0:4] |
|
304 | 311 | factor = dataOut.normFactor |
|
305 | 312 | x = dataOut.getVelRange(1) |
|
306 | 313 | y = dataOut.getHeiRange() |
|
307 | 314 | z = dataOut.data_spc[:,:,:]/factor |
|
308 |
|
|
|
309 | avg = numpy.abs(numpy.average(z, axis=1)) | |
|
315 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) | |
|
316 | ||
|
310 | 317 | noise = dataOut.noise/factor |
|
311 | 318 | |
|
312 | 319 | zdB = 10*numpy.log10(z) |
|
313 | avgdB = 10*numpy.log10(avg) | |
|
314 | 320 | noisedB = 10*numpy.log10(noise) |
|
315 | 321 | |
|
316 | 322 | |
|
317 | 323 | #thisDatetime = dataOut.datatime |
|
318 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
324 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
319 | 325 | title = wintitle + " Cross-Spectra: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
320 | 326 | xlabel = "Velocity (m/s)" |
|
321 | 327 | ylabel = "Range (Km)" |
|
322 | 328 | |
|
323 | 329 | if not self.isConfig: |
|
324 | 330 | |
|
325 | 331 | nplots = len(pairsIndexList) |
|
326 | 332 | |
|
327 | 333 | self.setup(id=id, |
|
328 | 334 | nplots=nplots, |
|
329 | 335 | wintitle=wintitle, |
|
330 | 336 | showprofile=False, |
|
331 | 337 | show=show) |
|
332 | 338 | |
|
339 | avg = numpy.abs(numpy.average(z, axis=1)) | |
|
340 | avgdB = 10*numpy.log10(avg) | |
|
341 | ||
|
333 | 342 | if xmin == None: xmin = numpy.nanmin(x) |
|
334 | 343 | if xmax == None: xmax = numpy.nanmax(x) |
|
335 | 344 | if ymin == None: ymin = numpy.nanmin(y) |
|
336 | 345 | if ymax == None: ymax = numpy.nanmax(y) |
|
337 |
if zmin == None: zmin = numpy.nanmin( |
|
|
338 |
if zmax == None: zmax = numpy.nanmax(avgdB) |
|
|
346 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
|
347 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
|
339 | 348 | |
|
340 | 349 | self.FTP_WEI = ftp_wei |
|
341 | 350 | self.EXP_CODE = exp_code |
|
342 | 351 | self.SUB_EXP_CODE = sub_exp_code |
|
343 | 352 | self.PLOT_POS = plot_pos |
|
344 | 353 | |
|
345 | 354 | self.isConfig = True |
|
346 | 355 | |
|
347 | 356 | self.setWinTitle(title) |
|
348 | 357 | |
|
349 | 358 | for i in range(self.nplots): |
|
350 | 359 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
351 | 360 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
352 | 361 | title = "Ch%d: %4.2fdB: %s" %(pair[0], noisedB[pair[0]], str_datetime) |
|
353 | 362 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[0],:,:]/factor) |
|
354 | 363 | axes0 = self.axesList[i*self.__nsubplots] |
|
355 | 364 | axes0.pcolor(x, y, zdB, |
|
356 | 365 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
357 | 366 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
358 | 367 | ticksize=9, colormap=power_cmap, cblabel='') |
|
359 | 368 | |
|
360 | 369 | title = "Ch%d: %4.2fdB: %s" %(pair[1], noisedB[pair[1]], str_datetime) |
|
361 | 370 | zdB = 10.*numpy.log10(dataOut.data_spc[pair[1],:,:]/factor) |
|
362 | 371 | axes0 = self.axesList[i*self.__nsubplots+1] |
|
363 | 372 | axes0.pcolor(x, y, zdB, |
|
364 | 373 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
365 | 374 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
366 | 375 | ticksize=9, colormap=power_cmap, cblabel='') |
|
367 | 376 | |
|
368 | 377 | coherenceComplex = dataOut.data_cspc[pairsIndexList[i],:,:]/numpy.sqrt(dataOut.data_spc[pair[0],:,:]*dataOut.data_spc[pair[1],:,:]) |
|
369 | 378 | coherence = numpy.abs(coherenceComplex) |
|
370 | 379 | # phase = numpy.arctan(-1*coherenceComplex.imag/coherenceComplex.real)*180/numpy.pi |
|
371 | 380 | phase = numpy.arctan2(coherenceComplex.imag, coherenceComplex.real)*180/numpy.pi |
|
372 | 381 | |
|
373 | 382 | title = "Coherence %d%d" %(pair[0], pair[1]) |
|
374 | 383 | axes0 = self.axesList[i*self.__nsubplots+2] |
|
375 | 384 | axes0.pcolor(x, y, coherence, |
|
376 | 385 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=0, zmax=1, |
|
377 | 386 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
378 | 387 | ticksize=9, colormap=coherence_cmap, cblabel='') |
|
379 | 388 | |
|
380 | 389 | title = "Phase %d%d" %(pair[0], pair[1]) |
|
381 | 390 | axes0 = self.axesList[i*self.__nsubplots+3] |
|
382 | 391 | axes0.pcolor(x, y, phase, |
|
383 | 392 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
384 | 393 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
385 | 394 | ticksize=9, colormap=phase_cmap, cblabel='') |
|
386 | 395 | |
|
387 | 396 | |
|
388 | 397 | |
|
389 | 398 | self.draw() |
|
390 | 399 | |
|
391 |
if |
|
|
392 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
393 | figfile = self.getFilename(name = str_datetime) | |
|
394 | ||
|
395 | if figpath != '': | |
|
400 | if save != '': | |
|
401 | ||
|
402 | if figfile == None: | |
|
403 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
404 | figfile = self.getFilename(name = str_datetime) | |
|
405 | ||
|
396 | 406 | self.counter_imagwr += 1 |
|
407 | ||
|
397 | 408 | if (self.counter_imagwr>=wr_period): |
|
398 | # store png plot to local folder | |
|
409 | # store png plot to local folder | |
|
399 | 410 | self.saveFigure(figpath, figfile) |
|
400 | # store png plot to FTP server according to RT-Web format | |
|
401 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
402 | ftp_filename = os.path.join(figpath, name) | |
|
403 | self.saveFigure(figpath, ftp_filename) | |
|
404 | 411 | self.counter_imagwr = 0 |
|
412 | ||
|
413 | if ftp: | |
|
414 | # store png plot to FTP server according to RT-Web format | |
|
415 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
416 | ftp_filename = os.path.join(figpath, name) | |
|
417 | self.saveFigure(figpath, ftp_filename) | |
|
405 | 418 | |
|
406 | 419 | |
|
407 | 420 | class RTIPlot(Figure): |
|
408 | 421 | |
|
409 | 422 | __isConfig = None |
|
410 | 423 | __nsubplots = None |
|
411 | 424 | |
|
412 | 425 | WIDTHPROF = None |
|
413 | 426 | HEIGHTPROF = None |
|
414 | 427 | PREFIX = 'rti' |
|
415 | 428 | |
|
416 | 429 | def __init__(self): |
|
417 | 430 | |
|
418 | 431 | self.timerange = 2*60*60 |
|
419 | 432 | self.__isConfig = False |
|
420 | 433 | self.__nsubplots = 1 |
|
421 | 434 | |
|
422 | 435 | self.WIDTH = 800 |
|
423 | 436 | self.HEIGHT = 150 |
|
424 | 437 | self.WIDTHPROF = 120 |
|
425 | 438 | self.HEIGHTPROF = 0 |
|
426 | 439 | self.counter_imagwr = 0 |
|
427 | 440 | |
|
428 | 441 | self.PLOT_CODE = 0 |
|
429 | 442 | self.FTP_WEI = None |
|
430 | 443 | self.EXP_CODE = None |
|
431 | 444 | self.SUB_EXP_CODE = None |
|
432 | 445 | self.PLOT_POS = None |
|
433 | 446 | self.tmin = None |
|
434 | 447 | self.tmax = None |
|
435 | 448 | |
|
436 | 449 | self.xmin = None |
|
437 | 450 | self.xmax = None |
|
438 | 451 | |
|
439 | 452 | self.figfile = None |
|
440 | 453 | |
|
441 | 454 | def getSubplots(self): |
|
442 | 455 | |
|
443 | 456 | ncol = 1 |
|
444 | 457 | nrow = self.nplots |
|
445 | 458 | |
|
446 | 459 | return nrow, ncol |
|
447 | 460 | |
|
448 | 461 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
449 | 462 | |
|
450 | 463 | self.__showprofile = showprofile |
|
451 | 464 | self.nplots = nplots |
|
452 | 465 | |
|
453 | 466 | ncolspan = 1 |
|
454 | 467 | colspan = 1 |
|
455 | 468 | if showprofile: |
|
456 | 469 | ncolspan = 7 |
|
457 | 470 | colspan = 6 |
|
458 | 471 | self.__nsubplots = 2 |
|
459 | 472 | |
|
460 | 473 | self.createFigure(id = id, |
|
461 | 474 | wintitle = wintitle, |
|
462 | 475 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
463 | 476 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
464 | 477 | show=show) |
|
465 | 478 | |
|
466 | 479 | nrow, ncol = self.getSubplots() |
|
467 | 480 | |
|
468 | 481 | counter = 0 |
|
469 | 482 | for y in range(nrow): |
|
470 | 483 | for x in range(ncol): |
|
471 | 484 | |
|
472 | 485 | if counter >= self.nplots: |
|
473 | 486 | break |
|
474 | 487 | |
|
475 | 488 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
476 | 489 | |
|
477 | 490 | if showprofile: |
|
478 | 491 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
479 | 492 | |
|
480 | 493 | counter += 1 |
|
481 | 494 | |
|
482 | 495 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
483 | 496 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
484 | 497 | timerange=None, |
|
485 | save=False, figpath='', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
498 | save=False, figpath='./', lastone=0,figfile=None, ftp=False, wr_period=1, show=True, | |
|
486 | 499 | server=None, folder=None, username=None, password=None, |
|
487 | 500 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
488 | 501 | |
|
489 | 502 | """ |
|
490 | 503 | |
|
491 | 504 | Input: |
|
492 | 505 | dataOut : |
|
493 | 506 | id : |
|
494 | 507 | wintitle : |
|
495 | 508 | channelList : |
|
496 | 509 | showProfile : |
|
497 | 510 | xmin : None, |
|
498 | 511 | xmax : None, |
|
499 | 512 | ymin : None, |
|
500 | 513 | ymax : None, |
|
501 | 514 | zmin : None, |
|
502 | 515 | zmax : None |
|
503 | 516 | """ |
|
504 | 517 | |
|
505 | 518 | if channelList == None: |
|
506 | 519 | channelIndexList = dataOut.channelIndexList |
|
507 | 520 | else: |
|
508 | 521 | channelIndexList = [] |
|
509 | 522 | for channel in channelList: |
|
510 | 523 | if channel not in dataOut.channelList: |
|
511 | 524 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
512 | 525 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
513 | 526 | |
|
514 | if timerange != None: | |
|
515 | self.timerange = timerange | |
|
527 | # if timerange != None: | |
|
528 | # self.timerange = timerange | |
|
516 | 529 | |
|
517 | 530 | #tmin = None |
|
518 | 531 | #tmax = None |
|
519 | 532 | factor = dataOut.normFactor |
|
520 | 533 | x = dataOut.getTimeRange() |
|
521 | 534 | y = dataOut.getHeiRange() |
|
522 | 535 | |
|
523 | 536 | z = dataOut.data_spc[channelIndexList,:,:]/factor |
|
524 | 537 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
525 | 538 | avg = numpy.average(z, axis=1) |
|
526 | 539 | |
|
527 | 540 | avgdB = 10.*numpy.log10(avg) |
|
528 | 541 | |
|
529 | 542 | |
|
530 | 543 | # thisDatetime = dataOut.datatime |
|
531 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
544 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
532 | 545 | title = wintitle + " RTI" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
533 | 546 | xlabel = "" |
|
534 | 547 | ylabel = "Range (Km)" |
|
535 | 548 | |
|
536 | 549 | if not self.__isConfig: |
|
537 | 550 | |
|
538 | 551 | nplots = len(channelIndexList) |
|
539 | 552 | |
|
540 | 553 | self.setup(id=id, |
|
541 | 554 | nplots=nplots, |
|
542 | 555 | wintitle=wintitle, |
|
543 | 556 | showprofile=showprofile, |
|
544 | 557 | show=show) |
|
545 | 558 | |
|
546 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
|
547 | ||
|
548 | # if timerange != None: | |
|
549 | # self.timerange = timerange | |
|
550 | # self.xmin, self.tmax = self.getTimeLim(x, xmin, xmax, timerange) | |
|
559 | if timerange != None: | |
|
560 | self.timerange = timerange | |
|
551 | 561 | |
|
562 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
|
552 | 563 | |
|
564 | noise = dataOut.noise/factor | |
|
565 | noisedB = 10*numpy.log10(noise) | |
|
553 | 566 | |
|
554 | 567 | if ymin == None: ymin = numpy.nanmin(y) |
|
555 | 568 | if ymax == None: ymax = numpy.nanmax(y) |
|
556 |
if zmin == None: zmin = numpy.nanmin( |
|
|
557 |
if zmax == None: zmax = numpy.nanmax(avgdB) |
|
|
569 | if zmin == None: zmin = numpy.floor(numpy.nanmin(noisedB)) - 3 | |
|
570 | if zmax == None: zmax = numpy.ceil(numpy.nanmax(avgdB)) + 3 | |
|
558 | 571 | |
|
559 | 572 | self.FTP_WEI = ftp_wei |
|
560 | 573 | self.EXP_CODE = exp_code |
|
561 | 574 | self.SUB_EXP_CODE = sub_exp_code |
|
562 | 575 | self.PLOT_POS = plot_pos |
|
563 | 576 | |
|
564 | 577 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
565 | 578 | self.__isConfig = True |
|
566 | 579 | self.figfile = figfile |
|
567 | 580 | |
|
568 | 581 | self.setWinTitle(title) |
|
569 | 582 | |
|
570 | 583 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
571 | 584 | x[1] = self.xmax |
|
572 | 585 | |
|
573 | 586 | for i in range(self.nplots): |
|
574 | 587 | title = "Channel %d: %s" %(dataOut.channelList[i]+1, thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
575 | 588 | if ((dataOut.azimuth!=None) and (dataOut.zenith!=None)): |
|
576 | 589 | title = title + '_' + 'azimuth,zenith=%2.2f,%2.2f'%(dataOut.azimuth, dataOut.zenith) |
|
577 | 590 | axes = self.axesList[i*self.__nsubplots] |
|
578 | 591 | zdB = avgdB[i].reshape((1,-1)) |
|
579 | 592 | axes.pcolorbuffer(x, y, zdB, |
|
580 | 593 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
581 | 594 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
582 | 595 | ticksize=9, cblabel='', cbsize="1%") |
|
583 | 596 | |
|
584 | 597 | if self.__showprofile: |
|
585 | 598 | axes = self.axesList[i*self.__nsubplots +1] |
|
586 | 599 | axes.pline(avgdB[i], y, |
|
587 | 600 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
588 | 601 | xlabel='dB', ylabel='', title='', |
|
589 | 602 | ytick_visible=False, |
|
590 | 603 | grid='x') |
|
591 | 604 | |
|
592 | 605 | self.draw() |
|
593 | 606 | |
|
594 | if self.figfile == None: | |
|
595 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
596 | self.figfile = self.getFilename(name = str_datetime) | |
|
597 | ||
|
598 | if figpath != '': | |
|
607 | if save: | |
|
608 | ||
|
609 | if self.figfile == None: | |
|
610 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
611 | self.figfile = self.getFilename(name = str_datetime) | |
|
599 | 612 | |
|
600 | 613 | self.counter_imagwr += 1 |
|
614 | ||
|
601 | 615 | if (self.counter_imagwr>=wr_period): |
|
602 | # store png plot to local folder | |
|
616 | # store png plot to local folder | |
|
603 | 617 | self.saveFigure(figpath, self.figfile) |
|
604 | # store png plot to FTP server according to RT-Web format | |
|
605 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
606 | ftp_filename = os.path.join(figpath, name) | |
|
607 | self.saveFigure(figpath, ftp_filename) | |
|
608 | ||
|
609 | 618 | self.counter_imagwr = 0 |
|
619 | ||
|
620 | if ftp: | |
|
621 | # store png plot to FTP server according to RT-Web format | |
|
622 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
623 | ftp_filename = os.path.join(figpath, name) | |
|
624 | self.saveFigure(figpath, ftp_filename) | |
|
610 | 625 | |
|
611 | 626 | if x[1] >= self.axesList[0].xmax: |
|
612 | 627 | self.counter_imagwr = wr_period |
|
613 | 628 | self.__isConfig = False |
|
614 | 629 | self.figfile = None |
|
615 | 630 | |
|
616 | 631 | class CoherenceMap(Figure): |
|
617 | 632 | isConfig = None |
|
618 | 633 | __nsubplots = None |
|
619 | 634 | |
|
620 | 635 | WIDTHPROF = None |
|
621 | 636 | HEIGHTPROF = None |
|
622 | 637 | PREFIX = 'cmap' |
|
623 | 638 | |
|
624 | 639 | def __init__(self): |
|
625 | 640 | self.timerange = 2*60*60 |
|
626 | 641 | self.isConfig = False |
|
627 | 642 | self.__nsubplots = 1 |
|
628 | 643 | |
|
629 | 644 | self.WIDTH = 800 |
|
630 | 645 | self.HEIGHT = 150 |
|
631 | 646 | self.WIDTHPROF = 120 |
|
632 | 647 | self.HEIGHTPROF = 0 |
|
633 | 648 | self.counter_imagwr = 0 |
|
634 | 649 | |
|
635 | 650 | self.PLOT_CODE = 3 |
|
636 | 651 | self.FTP_WEI = None |
|
637 | 652 | self.EXP_CODE = None |
|
638 | 653 | self.SUB_EXP_CODE = None |
|
639 | 654 | self.PLOT_POS = None |
|
640 | 655 | self.counter_imagwr = 0 |
|
641 | 656 | |
|
642 | 657 | self.xmin = None |
|
643 | 658 | self.xmax = None |
|
644 | 659 | |
|
645 | 660 | def getSubplots(self): |
|
646 | 661 | ncol = 1 |
|
647 | 662 | nrow = self.nplots*2 |
|
648 | 663 | |
|
649 | 664 | return nrow, ncol |
|
650 | 665 | |
|
651 | 666 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
652 | 667 | self.__showprofile = showprofile |
|
653 | 668 | self.nplots = nplots |
|
654 | 669 | |
|
655 | 670 | ncolspan = 1 |
|
656 | 671 | colspan = 1 |
|
657 | 672 | if showprofile: |
|
658 | 673 | ncolspan = 7 |
|
659 | 674 | colspan = 6 |
|
660 | 675 | self.__nsubplots = 2 |
|
661 | 676 | |
|
662 | 677 | self.createFigure(id = id, |
|
663 | 678 | wintitle = wintitle, |
|
664 | 679 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
665 | 680 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
666 | 681 | show=True) |
|
667 | 682 | |
|
668 | 683 | nrow, ncol = self.getSubplots() |
|
669 | 684 | |
|
670 | 685 | for y in range(nrow): |
|
671 | 686 | for x in range(ncol): |
|
672 | 687 | |
|
673 | 688 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
674 | 689 | |
|
675 | 690 | if showprofile: |
|
676 | 691 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
677 | 692 | |
|
678 | 693 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
679 | 694 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
680 | 695 | timerange=None, |
|
681 | save=False, figpath='', figfile=None, ftp=False, wr_period=1, | |
|
696 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, | |
|
682 | 697 | coherence_cmap='jet', phase_cmap='RdBu_r', show=True, |
|
683 | 698 | server=None, folder=None, username=None, password=None, |
|
684 | 699 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
685 | 700 | |
|
686 | 701 | if pairsList == None: |
|
687 | 702 | pairsIndexList = dataOut.pairsIndexList |
|
688 | 703 | else: |
|
689 | 704 | pairsIndexList = [] |
|
690 | 705 | for pair in pairsList: |
|
691 | 706 | if pair not in dataOut.pairsList: |
|
692 | 707 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
693 | 708 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
694 | 709 | |
|
695 | if timerange != None: | |
|
696 | self.timerange = timerange | |
|
697 | ||
|
698 | 710 | if pairsIndexList == []: |
|
699 | 711 | return |
|
700 | 712 | |
|
701 | 713 | if len(pairsIndexList) > 4: |
|
702 | 714 | pairsIndexList = pairsIndexList[0:4] |
|
703 | 715 | |
|
704 | 716 | # tmin = None |
|
705 | 717 | # tmax = None |
|
706 | 718 | x = dataOut.getTimeRange() |
|
707 | 719 | y = dataOut.getHeiRange() |
|
708 | 720 | |
|
709 | 721 | #thisDatetime = dataOut.datatime |
|
710 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
722 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
711 | 723 | title = wintitle + " CoherenceMap" #: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
712 | 724 | xlabel = "" |
|
713 | 725 | ylabel = "Range (Km)" |
|
714 | 726 | |
|
715 | 727 | if not self.isConfig: |
|
716 | 728 | nplots = len(pairsIndexList) |
|
717 | 729 | self.setup(id=id, |
|
718 | 730 | nplots=nplots, |
|
719 | 731 | wintitle=wintitle, |
|
720 | 732 | showprofile=showprofile, |
|
721 | 733 | show=show) |
|
722 | 734 | |
|
723 | #tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
735 | if timerange != None: | |
|
736 | self.timerange = timerange | |
|
724 | 737 | |
|
725 | 738 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) |
|
726 | 739 | |
|
727 | 740 | if ymin == None: ymin = numpy.nanmin(y) |
|
728 | 741 | if ymax == None: ymax = numpy.nanmax(y) |
|
729 | 742 | if zmin == None: zmin = 0. |
|
730 | 743 | if zmax == None: zmax = 1. |
|
731 | 744 | |
|
732 | 745 | self.FTP_WEI = ftp_wei |
|
733 | 746 | self.EXP_CODE = exp_code |
|
734 | 747 | self.SUB_EXP_CODE = sub_exp_code |
|
735 | 748 | self.PLOT_POS = plot_pos |
|
736 | 749 | |
|
737 | 750 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
738 | 751 | |
|
739 | 752 | self.isConfig = True |
|
740 | 753 | |
|
741 | 754 | self.setWinTitle(title) |
|
742 | 755 | |
|
743 | 756 | if ((self.xmax - x[1]) < (x[1]-x[0])): |
|
744 | 757 | x[1] = self.xmax |
|
745 | 758 | |
|
746 | 759 | for i in range(self.nplots): |
|
747 | 760 | |
|
748 | 761 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
749 | 762 | |
|
750 | 763 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
751 | 764 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
752 | 765 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
753 | 766 | |
|
754 | 767 | |
|
755 | 768 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
756 | 769 | coherence = numpy.abs(avgcoherenceComplex) |
|
757 | 770 | |
|
758 | 771 | z = coherence.reshape((1,-1)) |
|
759 | 772 | |
|
760 | 773 | counter = 0 |
|
761 | 774 | |
|
762 | 775 | title = "Coherence %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
763 | 776 | axes = self.axesList[i*self.__nsubplots*2] |
|
764 | 777 | axes.pcolorbuffer(x, y, z, |
|
765 | 778 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
766 | 779 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
767 | 780 | ticksize=9, cblabel='', colormap=coherence_cmap, cbsize="1%") |
|
768 | 781 | |
|
769 | 782 | if self.__showprofile: |
|
770 | 783 | counter += 1 |
|
771 | 784 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
772 | 785 | axes.pline(coherence, y, |
|
773 | 786 | xmin=zmin, xmax=zmax, ymin=ymin, ymax=ymax, |
|
774 | 787 | xlabel='', ylabel='', title='', ticksize=7, |
|
775 | 788 | ytick_visible=False, nxticks=5, |
|
776 | 789 | grid='x') |
|
777 | 790 | |
|
778 | 791 | counter += 1 |
|
779 | 792 | |
|
780 | 793 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
781 | 794 | |
|
782 | 795 | z = phase.reshape((1,-1)) |
|
783 | 796 | |
|
784 | 797 | title = "Phase %d%d: %s" %(pair[0], pair[1], thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
785 | 798 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
786 | 799 | axes.pcolorbuffer(x, y, z, |
|
787 | 800 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, zmin=-180, zmax=180, |
|
788 | 801 | xlabel=xlabel, ylabel=ylabel, title=title, rti=True, XAxisAsTime=True, |
|
789 | 802 | ticksize=9, cblabel='', colormap=phase_cmap, cbsize="1%") |
|
790 | 803 | |
|
791 | 804 | if self.__showprofile: |
|
792 | 805 | counter += 1 |
|
793 | 806 | axes = self.axesList[i*self.__nsubplots*2 + counter] |
|
794 | 807 | axes.pline(phase, y, |
|
795 | 808 | xmin=-180, xmax=180, ymin=ymin, ymax=ymax, |
|
796 | 809 | xlabel='', ylabel='', title='', ticksize=7, |
|
797 | 810 | ytick_visible=False, nxticks=4, |
|
798 | 811 | grid='x') |
|
799 | 812 | |
|
800 | 813 | self.draw() |
|
801 | 814 | |
|
802 | 815 | if x[1] >= self.axesList[0].xmax: |
|
803 | 816 | self.counter_imagwr = wr_period |
|
804 | 817 | self.__isConfig = False |
|
805 | 818 | |
|
806 |
if |
|
|
807 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
808 | figfile = self.getFilename(name = str_datetime) | |
|
809 | ||
|
810 | if figpath != '': | |
|
811 | ||
|
819 | if save: | |
|
820 | ||
|
821 | if figfile == None: | |
|
822 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
823 | figfile = self.getFilename(name = str_datetime) | |
|
824 | ||
|
812 | 825 | self.counter_imagwr += 1 |
|
826 | ||
|
813 | 827 | if (self.counter_imagwr>=wr_period): |
|
814 | # store png plot to local folder | |
|
828 | # store png plot to local folder | |
|
815 | 829 | self.saveFigure(figpath, figfile) |
|
816 | # store png plot to FTP server according to RT-Web format | |
|
817 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
818 | ftp_filename = os.path.join(figpath, name) | |
|
819 | self.saveFigure(figpath, ftp_filename) | |
|
820 | ||
|
821 | 830 | self.counter_imagwr = 0 |
|
831 | ||
|
832 | if ftp: | |
|
833 | # store png plot to FTP server according to RT-Web format | |
|
834 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
835 | ftp_filename = os.path.join(figpath, name) | |
|
836 | self.saveFigure(figpath, ftp_filename) | |
|
822 | 837 | |
|
823 | 838 | class PowerProfile(Figure): |
|
824 | 839 | isConfig = None |
|
825 | 840 | __nsubplots = None |
|
826 | 841 | |
|
827 | 842 | WIDTHPROF = None |
|
828 | 843 | HEIGHTPROF = None |
|
829 | 844 | PREFIX = 'spcprofile' |
|
830 | 845 | |
|
831 | 846 | def __init__(self): |
|
832 | 847 | self.isConfig = False |
|
833 | 848 | self.__nsubplots = 1 |
|
834 | 849 | |
|
835 | 850 | self.WIDTH = 300 |
|
836 | 851 | self.HEIGHT = 500 |
|
837 | 852 | self.counter_imagwr = 0 |
|
838 | 853 | |
|
839 | 854 | def getSubplots(self): |
|
840 | 855 | ncol = 1 |
|
841 | 856 | nrow = 1 |
|
842 | 857 | |
|
843 | 858 | return nrow, ncol |
|
844 | 859 | |
|
845 | 860 | def setup(self, id, nplots, wintitle, show): |
|
846 | 861 | |
|
847 | 862 | self.nplots = nplots |
|
848 | 863 | |
|
849 | 864 | ncolspan = 1 |
|
850 | 865 | colspan = 1 |
|
851 | 866 | |
|
852 | 867 | self.createFigure(id = id, |
|
853 | 868 | wintitle = wintitle, |
|
854 | 869 | widthplot = self.WIDTH, |
|
855 | 870 | heightplot = self.HEIGHT, |
|
856 | 871 | show=show) |
|
857 | 872 | |
|
858 | 873 | nrow, ncol = self.getSubplots() |
|
859 | 874 | |
|
860 | 875 | counter = 0 |
|
861 | 876 | for y in range(nrow): |
|
862 | 877 | for x in range(ncol): |
|
863 | 878 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
864 | 879 | |
|
865 | 880 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
866 | 881 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
867 |
save=False, figpath='', figfile=None, show=True, |
|
|
868 | server=None, folder=None, username=None, password=None,): | |
|
882 | save=False, figpath='./', figfile=None, show=True, | |
|
883 | ftp=False, wr_period=1, server=None, | |
|
884 | folder=None, username=None, password=None): | |
|
869 | 885 | |
|
870 | if dataOut.flagNoData: | |
|
871 | return None | |
|
872 | 886 | |
|
873 | 887 | if channelList == None: |
|
874 | 888 | channelIndexList = dataOut.channelIndexList |
|
875 | 889 | channelList = dataOut.channelList |
|
876 | 890 | else: |
|
877 | 891 | channelIndexList = [] |
|
878 | 892 | for channel in channelList: |
|
879 | 893 | if channel not in dataOut.channelList: |
|
880 | 894 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
881 | 895 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
882 | 896 | |
|
883 | try: | |
|
884 | factor = dataOut.normFactor | |
|
885 | except: | |
|
886 | factor = 1 | |
|
897 | factor = dataOut.normFactor | |
|
887 | 898 | |
|
888 | 899 | y = dataOut.getHeiRange() |
|
889 | 900 | |
|
890 | 901 | #for voltage |
|
891 | 902 | if dataOut.type == 'Voltage': |
|
892 | 903 | x = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
893 | 904 | x = x.real |
|
894 | 905 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
895 | 906 | |
|
896 | 907 | #for spectra |
|
897 | 908 | if dataOut.type == 'Spectra': |
|
898 | 909 | x = dataOut.data_spc[channelIndexList,:,:]/factor |
|
899 | 910 | x = numpy.where(numpy.isfinite(x), x, numpy.NAN) |
|
900 | 911 | x = numpy.average(x, axis=1) |
|
901 | 912 | |
|
902 | 913 | |
|
903 | 914 | xdB = 10*numpy.log10(x) |
|
904 | 915 | |
|
905 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
916 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
906 | 917 | title = wintitle + " Power Profile %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
907 | 918 | xlabel = "dB" |
|
908 | 919 | ylabel = "Range (Km)" |
|
909 | 920 | |
|
910 | 921 | if not self.isConfig: |
|
911 | 922 | |
|
912 | 923 | nplots = 1 |
|
913 | 924 | |
|
914 | 925 | self.setup(id=id, |
|
915 | 926 | nplots=nplots, |
|
916 | 927 | wintitle=wintitle, |
|
917 | 928 | show=show) |
|
918 | 929 | |
|
919 | 930 | if ymin == None: ymin = numpy.nanmin(y) |
|
920 | 931 | if ymax == None: ymax = numpy.nanmax(y) |
|
921 | 932 | if xmin == None: xmin = numpy.nanmin(xdB)*0.9 |
|
922 |
if xmax == None: xmax = numpy.nanmax(xdB)* |
|
|
933 | if xmax == None: xmax = numpy.nanmax(xdB)*1.1 | |
|
923 | 934 | |
|
924 | 935 | self.__isConfig = True |
|
925 | 936 | |
|
926 | 937 | self.setWinTitle(title) |
|
927 | 938 | |
|
928 | 939 | title = "Power Profile: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
929 | 940 | axes = self.axesList[0] |
|
930 | 941 | |
|
931 | 942 | legendlabels = ["channel %d"%x for x in channelList] |
|
932 | 943 | axes.pmultiline(xdB, y, |
|
933 | 944 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
934 | 945 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, |
|
935 | 946 | ytick_visible=True, nxticks=5, |
|
936 | 947 | grid='x') |
|
937 | 948 | |
|
938 | 949 | self.draw() |
|
939 | 950 | |
|
940 |
if |
|
|
941 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
942 | figfile = self.getFilename(name = str_datetime) | |
|
943 | ||
|
944 | if figpath != '': | |
|
951 | if save: | |
|
952 | ||
|
953 | if figfile == None: | |
|
954 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
955 | figfile = self.getFilename(name = str_datetime) | |
|
956 | ||
|
945 | 957 | self.counter_imagwr += 1 |
|
958 | ||
|
946 | 959 | if (self.counter_imagwr>=wr_period): |
|
947 | # store png plot to local folder | |
|
960 | # store png plot to local folder | |
|
948 | 961 | self.saveFigure(figpath, figfile) |
|
949 | # store png plot to FTP server according to RT-Web format | |
|
950 | #name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
951 | #ftp_filename = os.path.join(figpath, name) | |
|
952 | #self.saveFigure(figpath, ftp_filename) | |
|
953 | 962 | self.counter_imagwr = 0 |
|
954 | 963 | |
|
955 | ||
|
956 | ||
|
957 | 964 | class Noise(Figure): |
|
958 | 965 | |
|
959 | 966 | isConfig = None |
|
960 | 967 | __nsubplots = None |
|
961 | 968 | |
|
962 | 969 | PREFIX = 'noise' |
|
963 | 970 | |
|
964 | 971 | def __init__(self): |
|
965 | 972 | |
|
966 | 973 | self.timerange = 24*60*60 |
|
967 | 974 | self.isConfig = False |
|
968 | 975 | self.__nsubplots = 1 |
|
969 | 976 | self.counter_imagwr = 0 |
|
970 | 977 | self.WIDTH = 600 |
|
971 | 978 | self.HEIGHT = 300 |
|
972 | 979 | self.WIDTHPROF = 120 |
|
973 | 980 | self.HEIGHTPROF = 0 |
|
974 | 981 | self.xdata = None |
|
975 | 982 | self.ydata = None |
|
976 | 983 | |
|
977 | 984 | self.PLOT_CODE = 17 |
|
978 | 985 | self.FTP_WEI = None |
|
979 | 986 | self.EXP_CODE = None |
|
980 | 987 | self.SUB_EXP_CODE = None |
|
981 | 988 | self.PLOT_POS = None |
|
982 | 989 | self.figfile = None |
|
983 | 990 | |
|
991 | self.xmin = None | |
|
992 | self.xmax = None | |
|
993 | ||
|
984 | 994 | def getSubplots(self): |
|
985 | 995 | |
|
986 | 996 | ncol = 1 |
|
987 | 997 | nrow = 1 |
|
988 | 998 | |
|
989 | 999 | return nrow, ncol |
|
990 | 1000 | |
|
991 | 1001 | def openfile(self, filename): |
|
992 | 1002 | f = open(filename,'w+') |
|
993 | 1003 | f.write('\n\n') |
|
994 | 1004 | f.write('JICAMARCA RADIO OBSERVATORY - Noise \n') |
|
995 | 1005 | f.write('DD MM YYYY HH MM SS Channel0 Channel1 Channel2 Channel3\n\n' ) |
|
996 | 1006 | f.close() |
|
997 | 1007 | |
|
998 | 1008 | def save_data(self, filename_phase, data, data_datetime): |
|
999 | 1009 | f=open(filename_phase,'a') |
|
1000 | 1010 | timetuple_data = data_datetime.timetuple() |
|
1001 | 1011 | day = str(timetuple_data.tm_mday) |
|
1002 | 1012 | month = str(timetuple_data.tm_mon) |
|
1003 | 1013 | year = str(timetuple_data.tm_year) |
|
1004 | 1014 | hour = str(timetuple_data.tm_hour) |
|
1005 | 1015 | minute = str(timetuple_data.tm_min) |
|
1006 | 1016 | second = str(timetuple_data.tm_sec) |
|
1007 | 1017 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1008 | 1018 | f.close() |
|
1009 | 1019 | |
|
1010 | 1020 | |
|
1011 | 1021 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1012 | 1022 | |
|
1013 | 1023 | self.__showprofile = showprofile |
|
1014 | 1024 | self.nplots = nplots |
|
1015 | 1025 | |
|
1016 | 1026 | ncolspan = 7 |
|
1017 | 1027 | colspan = 6 |
|
1018 | 1028 | self.__nsubplots = 2 |
|
1019 | 1029 | |
|
1020 | 1030 | self.createFigure(id = id, |
|
1021 | 1031 | wintitle = wintitle, |
|
1022 | 1032 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1023 | 1033 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1024 | 1034 | show=show) |
|
1025 | 1035 | |
|
1026 | 1036 | nrow, ncol = self.getSubplots() |
|
1027 | 1037 | |
|
1028 | 1038 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1029 | 1039 | |
|
1030 | 1040 | |
|
1031 | 1041 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
1032 | 1042 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1033 | 1043 | timerange=None, |
|
1034 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
|
1044 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
|
1035 | 1045 | server=None, folder=None, username=None, password=None, |
|
1036 | 1046 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1037 | 1047 | |
|
1038 | 1048 | if channelList == None: |
|
1039 | 1049 | channelIndexList = dataOut.channelIndexList |
|
1040 | 1050 | channelList = dataOut.channelList |
|
1041 | 1051 | else: |
|
1042 | 1052 | channelIndexList = [] |
|
1043 | 1053 | for channel in channelList: |
|
1044 | 1054 | if channel not in dataOut.channelList: |
|
1045 | 1055 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
1046 | 1056 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
1047 | 1057 | |
|
1048 | if timerange != None: | |
|
1049 | self.timerange = timerange | |
|
1050 | ||
|
1051 | tmin = None | |
|
1052 | tmax = None | |
|
1053 | 1058 | x = dataOut.getTimeRange() |
|
1054 | y = dataOut.getHeiRange() | |
|
1059 | #y = dataOut.getHeiRange() | |
|
1055 | 1060 | factor = dataOut.normFactor |
|
1056 | 1061 | noise = dataOut.noise/factor |
|
1057 | 1062 | noisedB = 10*numpy.log10(noise) |
|
1058 | 1063 | |
|
1059 | 1064 | #thisDatetime = dataOut.datatime |
|
1060 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
1065 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
1061 | 1066 | title = wintitle + " Noise" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1062 | 1067 | xlabel = "" |
|
1063 | 1068 | ylabel = "Intensity (dB)" |
|
1064 | 1069 | |
|
1065 | 1070 | if not self.isConfig: |
|
1066 | 1071 | |
|
1067 | 1072 | nplots = 1 |
|
1068 | 1073 | |
|
1069 | 1074 | self.setup(id=id, |
|
1070 | 1075 | nplots=nplots, |
|
1071 | 1076 | wintitle=wintitle, |
|
1072 | 1077 | showprofile=showprofile, |
|
1073 | 1078 | show=show) |
|
1074 | 1079 | |
|
1075 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
1076 | if ymin == None: ymin = numpy.nanmin(noisedB) - 10.0 | |
|
1080 | if timerange != None: | |
|
1081 | self.timerange = timerange | |
|
1082 | ||
|
1083 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
|
1084 | ||
|
1085 | if ymin == None: ymin = numpy.floor(numpy.nanmin(noisedB)) - 10.0 | |
|
1077 | 1086 | if ymax == None: ymax = numpy.nanmax(noisedB) + 10.0 |
|
1078 | 1087 | |
|
1079 | 1088 | self.FTP_WEI = ftp_wei |
|
1080 | 1089 | self.EXP_CODE = exp_code |
|
1081 | 1090 | self.SUB_EXP_CODE = sub_exp_code |
|
1082 | 1091 | self.PLOT_POS = plot_pos |
|
1083 | 1092 | |
|
1084 | 1093 | |
|
1085 | 1094 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1086 | 1095 | self.isConfig = True |
|
1087 | 1096 | self.figfile = figfile |
|
1088 | 1097 | self.xdata = numpy.array([]) |
|
1089 | 1098 | self.ydata = numpy.array([]) |
|
1090 | 1099 | |
|
1091 | 1100 | #open file beacon phase |
|
1092 | 1101 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1093 | 1102 | noise_file = os.path.join(path,'%s.txt'%self.name) |
|
1094 | 1103 | self.filename_noise = os.path.join(figpath,noise_file) |
|
1095 | 1104 | self.openfile(self.filename_noise) |
|
1096 | 1105 | |
|
1097 | 1106 | |
|
1098 | 1107 | #store data beacon phase |
|
1099 | 1108 | self.save_data(self.filename_noise, noisedB, thisDatetime) |
|
1100 | 1109 | |
|
1101 | 1110 | |
|
1102 | 1111 | self.setWinTitle(title) |
|
1103 | 1112 | |
|
1104 | 1113 | |
|
1105 | 1114 | title = "Noise %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1106 | 1115 | |
|
1107 | 1116 | legendlabels = ["channel %d"%(idchannel+1) for idchannel in channelList] |
|
1108 | 1117 | axes = self.axesList[0] |
|
1109 | 1118 | |
|
1110 | 1119 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1111 | 1120 | |
|
1112 | 1121 | if len(self.ydata)==0: |
|
1113 | 1122 | self.ydata = noisedB[channelIndexList].reshape(-1,1) |
|
1114 | 1123 | else: |
|
1115 | 1124 | self.ydata = numpy.hstack((self.ydata, noisedB[channelIndexList].reshape(-1,1))) |
|
1116 | 1125 | |
|
1117 | 1126 | |
|
1118 | 1127 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1119 |
xmin= |
|
|
1128 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | |
|
1120 | 1129 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1121 | 1130 | XAxisAsTime=True, grid='both' |
|
1122 | 1131 | ) |
|
1123 | 1132 | |
|
1124 | 1133 | self.draw() |
|
1125 | 1134 | |
|
1126 | 1135 | if x[1] >= self.axesList[0].xmax: |
|
1127 | 1136 | self.counter_imagwr = wr_period |
|
1128 | 1137 | del self.xdata |
|
1129 | 1138 | del self.ydata |
|
1130 | 1139 | self.__isConfig = False |
|
1131 | 1140 | |
|
1132 |
if s |
|
|
1133 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
1134 | self.figfile = self.getFilename(name = str_datetime) | |
|
1135 | ||
|
1136 | if figpath != '': | |
|
1141 | if save != '': | |
|
1142 | ||
|
1143 | if self.figfile == None: | |
|
1144 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
1145 | self.figfile = self.getFilename(name = str_datetime) | |
|
1146 | ||
|
1137 | 1147 | self.counter_imagwr += 1 |
|
1148 | ||
|
1138 | 1149 | if (self.counter_imagwr>=wr_period): |
|
1139 | # store png plot to local folder | |
|
1150 | # store png plot to local folder | |
|
1140 | 1151 | self.saveFigure(figpath, self.figfile) |
|
1141 | # store png plot to FTP server according to RT-Web format | |
|
1142 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
1143 | ftp_filename = os.path.join(figpath, name) | |
|
1144 | self.saveFigure(figpath, ftp_filename) | |
|
1145 | 1152 | self.counter_imagwr = 0 |
|
1153 | ||
|
1154 | if ftp: | |
|
1155 | # store png plot to FTP server according to RT-Web format | |
|
1156 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
1157 | ftp_filename = os.path.join(figpath, name) | |
|
1158 | self.saveFigure(figpath, ftp_filename) | |
|
1146 | 1159 | |
|
1147 | 1160 | |
|
1148 | 1161 | class BeaconPhase(Figure): |
|
1149 | 1162 | |
|
1150 | 1163 | __isConfig = None |
|
1151 | 1164 | __nsubplots = None |
|
1152 | 1165 | |
|
1153 | 1166 | PREFIX = 'beacon_phase' |
|
1154 | 1167 | |
|
1155 | 1168 | def __init__(self): |
|
1156 | 1169 | |
|
1157 | 1170 | self.timerange = 24*60*60 |
|
1158 | 1171 | self.__isConfig = False |
|
1159 | 1172 | self.__nsubplots = 1 |
|
1160 | 1173 | self.counter_imagwr = 0 |
|
1161 | 1174 | self.WIDTH = 600 |
|
1162 | 1175 | self.HEIGHT = 300 |
|
1163 | 1176 | self.WIDTHPROF = 120 |
|
1164 | 1177 | self.HEIGHTPROF = 0 |
|
1165 | 1178 | self.xdata = None |
|
1166 | 1179 | self.ydata = None |
|
1167 | 1180 | |
|
1168 | 1181 | self.PLOT_CODE = 18 |
|
1169 | 1182 | self.FTP_WEI = None |
|
1170 | 1183 | self.EXP_CODE = None |
|
1171 | 1184 | self.SUB_EXP_CODE = None |
|
1172 | 1185 | self.PLOT_POS = None |
|
1173 | 1186 | |
|
1174 | 1187 | self.filename_phase = None |
|
1175 | 1188 | |
|
1176 | 1189 | self.figfile = None |
|
1177 | 1190 | |
|
1191 | self.xmin = None | |
|
1192 | self.xmax = None | |
|
1193 | ||
|
1178 | 1194 | def getSubplots(self): |
|
1179 | 1195 | |
|
1180 | 1196 | ncol = 1 |
|
1181 | 1197 | nrow = 1 |
|
1182 | 1198 | |
|
1183 | 1199 | return nrow, ncol |
|
1184 | 1200 | |
|
1185 | 1201 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
1186 | 1202 | |
|
1187 | 1203 | self.__showprofile = showprofile |
|
1188 | 1204 | self.nplots = nplots |
|
1189 | 1205 | |
|
1190 | 1206 | ncolspan = 7 |
|
1191 | 1207 | colspan = 6 |
|
1192 | 1208 | self.__nsubplots = 2 |
|
1193 | 1209 | |
|
1194 | 1210 | self.createFigure(id = id, |
|
1195 | 1211 | wintitle = wintitle, |
|
1196 | 1212 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
1197 | 1213 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
1198 | 1214 | show=show) |
|
1199 | 1215 | |
|
1200 | 1216 | nrow, ncol = self.getSubplots() |
|
1201 | 1217 | |
|
1202 | 1218 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
1203 | 1219 | |
|
1204 | 1220 | def save_phase(self, filename_phase): |
|
1205 | 1221 | f = open(filename_phase,'w+') |
|
1206 | 1222 | f.write('\n\n') |
|
1207 | 1223 | f.write('JICAMARCA RADIO OBSERVATORY - Beacon Phase \n') |
|
1208 | 1224 | f.write('DD MM YYYY HH MM SS pair(2,0) pair(2,1) pair(2,3) pair(2,4)\n\n' ) |
|
1209 | 1225 | f.close() |
|
1210 | 1226 | |
|
1211 | 1227 | def save_data(self, filename_phase, data, data_datetime): |
|
1212 | 1228 | f=open(filename_phase,'a') |
|
1213 | 1229 | timetuple_data = data_datetime.timetuple() |
|
1214 | 1230 | day = str(timetuple_data.tm_mday) |
|
1215 | 1231 | month = str(timetuple_data.tm_mon) |
|
1216 | 1232 | year = str(timetuple_data.tm_year) |
|
1217 | 1233 | hour = str(timetuple_data.tm_hour) |
|
1218 | 1234 | minute = str(timetuple_data.tm_min) |
|
1219 | 1235 | second = str(timetuple_data.tm_sec) |
|
1220 | 1236 | f.write(day+' '+month+' '+year+' '+hour+' '+minute+' '+second+' '+str(data[0])+' '+str(data[1])+' '+str(data[2])+' '+str(data[3])+'\n') |
|
1221 | 1237 | f.close() |
|
1222 | 1238 | |
|
1223 | 1239 | |
|
1224 | 1240 | def run(self, dataOut, id, wintitle="", pairsList=None, showprofile='True', |
|
1225 | 1241 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
1226 | 1242 | timerange=None, |
|
1227 | save=False, figpath='', figfile=None, show=True, ftp=False, wr_period=1, | |
|
1243 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, | |
|
1228 | 1244 | server=None, folder=None, username=None, password=None, |
|
1229 | 1245 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
1230 | 1246 | |
|
1231 | 1247 | if pairsList == None: |
|
1232 | 1248 | pairsIndexList = dataOut.pairsIndexList |
|
1233 | 1249 | else: |
|
1234 | 1250 | pairsIndexList = [] |
|
1235 | 1251 | for pair in pairsList: |
|
1236 | 1252 | if pair not in dataOut.pairsList: |
|
1237 | 1253 | raise ValueError, "Pair %s is not in dataOut.pairsList" %(pair) |
|
1238 | 1254 | pairsIndexList.append(dataOut.pairsList.index(pair)) |
|
1239 | 1255 | |
|
1240 | 1256 | if pairsIndexList == []: |
|
1241 | 1257 | return |
|
1242 | 1258 | |
|
1243 | 1259 | # if len(pairsIndexList) > 4: |
|
1244 | 1260 | # pairsIndexList = pairsIndexList[0:4] |
|
1245 | ||
|
1246 | if timerange != None: | |
|
1247 | self.timerange = timerange | |
|
1248 | 1261 | |
|
1249 | tmin = None | |
|
1250 | tmax = None | |
|
1251 | 1262 | x = dataOut.getTimeRange() |
|
1252 | y = dataOut.getHeiRange() | |
|
1263 | #y = dataOut.getHeiRange() | |
|
1253 | 1264 | |
|
1254 | 1265 | |
|
1255 | 1266 | #thisDatetime = dataOut.datatime |
|
1256 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
1267 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
1257 | 1268 | title = wintitle + " Phase of Beacon Signal" # : %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
1258 | 1269 | xlabel = "Local Time" |
|
1259 | 1270 | ylabel = "Phase" |
|
1260 | 1271 | |
|
1261 | 1272 | nplots = len(pairsIndexList) |
|
1262 | 1273 | #phase = numpy.zeros((len(pairsIndexList),len(dataOut.beacon_heiIndexList))) |
|
1263 | 1274 | phase_beacon = numpy.zeros(len(pairsIndexList)) |
|
1264 | 1275 | for i in range(nplots): |
|
1265 | 1276 | pair = dataOut.pairsList[pairsIndexList[i]] |
|
1266 | 1277 | ccf = numpy.average(dataOut.data_cspc[pairsIndexList[i],:,:],axis=0) |
|
1267 | 1278 | powa = numpy.average(dataOut.data_spc[pair[0],:,:],axis=0) |
|
1268 | 1279 | powb = numpy.average(dataOut.data_spc[pair[1],:,:],axis=0) |
|
1269 | 1280 | avgcoherenceComplex = ccf/numpy.sqrt(powa*powb) |
|
1270 | 1281 | phase = numpy.arctan2(avgcoherenceComplex.imag, avgcoherenceComplex.real)*180/numpy.pi |
|
1271 | 1282 | |
|
1272 | 1283 | #print "Phase %d%d" %(pair[0], pair[1]) |
|
1273 | 1284 | #print phase[dataOut.beacon_heiIndexList] |
|
1274 | 1285 | |
|
1275 | 1286 | phase_beacon[i] = numpy.average(phase[dataOut.beacon_heiIndexList]) |
|
1276 | 1287 | |
|
1277 | 1288 | if not self.__isConfig: |
|
1278 | 1289 | |
|
1279 | 1290 | nplots = len(pairsIndexList) |
|
1280 | 1291 | |
|
1281 | 1292 | self.setup(id=id, |
|
1282 | 1293 | nplots=nplots, |
|
1283 | 1294 | wintitle=wintitle, |
|
1284 | 1295 | showprofile=showprofile, |
|
1285 | 1296 | show=show) |
|
1286 | 1297 | |
|
1287 | tmin, tmax = self.getTimeLim(x, xmin, xmax) | |
|
1298 | if timerange != None: | |
|
1299 | self.timerange = timerange | |
|
1300 | ||
|
1301 | self.xmin, self.xmax = self.getTimeLim(x, xmin, xmax, timerange) | |
|
1302 | ||
|
1288 | 1303 | if ymin == None: ymin = numpy.nanmin(phase_beacon) - 10.0 |
|
1289 | 1304 | if ymax == None: ymax = numpy.nanmax(phase_beacon) + 10.0 |
|
1290 | 1305 | |
|
1291 | 1306 | self.FTP_WEI = ftp_wei |
|
1292 | 1307 | self.EXP_CODE = exp_code |
|
1293 | 1308 | self.SUB_EXP_CODE = sub_exp_code |
|
1294 | 1309 | self.PLOT_POS = plot_pos |
|
1295 | 1310 | |
|
1296 | 1311 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
1297 | 1312 | self.__isConfig = True |
|
1298 | 1313 | self.figfile = figfile |
|
1299 | 1314 | self.xdata = numpy.array([]) |
|
1300 | 1315 | self.ydata = numpy.array([]) |
|
1301 | 1316 | |
|
1302 | 1317 | #open file beacon phase |
|
1303 | 1318 | path = '%s%03d' %(self.PREFIX, self.id) |
|
1304 | 1319 | beacon_file = os.path.join(path,'%s.txt'%self.name) |
|
1305 | 1320 | self.filename_phase = os.path.join(figpath,beacon_file) |
|
1306 | 1321 | #self.save_phase(self.filename_phase) |
|
1307 | 1322 | |
|
1308 | 1323 | |
|
1309 | 1324 | #store data beacon phase |
|
1310 | 1325 | #self.save_data(self.filename_phase, phase_beacon, thisDatetime) |
|
1311 | 1326 | |
|
1312 | 1327 | self.setWinTitle(title) |
|
1313 | 1328 | |
|
1314 | 1329 | |
|
1315 | 1330 | title = "Beacon Signal %s" %(thisDatetime.strftime("%Y/%m/%d %H:%M:%S")) |
|
1316 | 1331 | |
|
1317 | 1332 | legendlabels = ["pairs %d%d"%(pair[0], pair[1]) for pair in dataOut.pairsList] |
|
1318 | 1333 | |
|
1319 | 1334 | axes = self.axesList[0] |
|
1320 | 1335 | |
|
1321 | 1336 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
1322 | 1337 | |
|
1323 | 1338 | if len(self.ydata)==0: |
|
1324 | 1339 | self.ydata = phase_beacon.reshape(-1,1) |
|
1325 | 1340 | else: |
|
1326 | 1341 | self.ydata = numpy.hstack((self.ydata, phase_beacon.reshape(-1,1))) |
|
1327 | 1342 | |
|
1328 | 1343 | |
|
1329 | 1344 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
1330 |
xmin= |
|
|
1345 | xmin=self.xmin, xmax=self.xmax, ymin=ymin, ymax=ymax, | |
|
1331 | 1346 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='x', markersize=8, linestyle="solid", |
|
1332 | 1347 | XAxisAsTime=True, grid='both' |
|
1333 | 1348 | ) |
|
1334 | 1349 | |
|
1335 | 1350 | self.draw() |
|
1336 | 1351 | |
|
1337 | 1352 | if x[1] >= self.axesList[0].xmax: |
|
1338 | 1353 | self.counter_imagwr = wr_period |
|
1339 | 1354 | del self.xdata |
|
1340 | 1355 | del self.ydata |
|
1341 | 1356 | self.__isConfig = False |
|
1342 | 1357 | |
|
1343 | if self.figfile == None: | |
|
1344 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
1345 | self.figfile = self.getFilename(name = str_datetime) | |
|
1346 | ||
|
1347 | if figpath != '': | |
|
1358 | if save: | |
|
1359 | ||
|
1360 | if self.figfile == None: | |
|
1361 | str_datetime = thisDatetime.strftime("%Y%m%d_%H%M%S") | |
|
1362 | self.figfile = self.getFilename(name = str_datetime) | |
|
1363 | ||
|
1348 | 1364 | self.counter_imagwr += 1 |
|
1365 | ||
|
1349 | 1366 | if (self.counter_imagwr>=wr_period): |
|
1350 | # store png plot to local folder | |
|
1367 | # store png plot to local folder | |
|
1351 | 1368 | self.saveFigure(figpath, self.figfile) |
|
1352 | # store png plot to FTP server according to RT-Web format | |
|
1353 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
1354 | ftp_filename = os.path.join(figpath, name) | |
|
1355 | self.saveFigure(figpath, ftp_filename) | |
|
1356 | 1369 | self.counter_imagwr = 0 |
|
1370 | ||
|
1371 | if ftp: | |
|
1372 | # store png plot to FTP server according to RT-Web format | |
|
1373 | name = self.getNameToFtp(thisDatetime, self.FTP_WEI, self.EXP_CODE, self.SUB_EXP_CODE, self.PLOT_CODE, self.PLOT_POS) | |
|
1374 | ftp_filename = os.path.join(figpath, name) | |
|
1375 | self.saveFigure(figpath, ftp_filename) |
@@ -1,186 +1,186 | |||
|
1 | 1 | ''' |
|
2 | @author: Daniel Suarez | |
|
3 | ''' | |
|
2 | Created on Jul 9, 2014 | |
|
4 | 3 |
|
|
4 | @author: roj-idl71 | |
|
5 | ''' | |
|
6 | import os | |
|
5 | 7 | import datetime |
|
6 | 8 | import numpy |
|
7 | 9 | |
|
8 | 10 | from figure import Figure |
|
9 | 11 | |
|
10 | 12 | class Scope(Figure): |
|
11 | 13 | |
|
12 | 14 | isConfig = None |
|
13 | 15 | |
|
14 | 16 | def __init__(self): |
|
15 | 17 | |
|
16 | 18 | self.isConfig = False |
|
17 | 19 | self.WIDTH = 300 |
|
18 | 20 | self.HEIGHT = 200 |
|
19 | 21 | self.counter_imagwr = 0 |
|
20 | 22 | |
|
21 | 23 | def getSubplots(self): |
|
22 | 24 | |
|
23 | 25 | nrow = self.nplots |
|
24 | 26 | ncol = 3 |
|
25 | 27 | return nrow, ncol |
|
26 | 28 | |
|
27 | 29 | def setup(self, id, nplots, wintitle, show): |
|
28 | 30 | |
|
29 | 31 | self.nplots = nplots |
|
30 | 32 | |
|
31 | 33 | self.createFigure(id=id, |
|
32 | 34 | wintitle=wintitle, |
|
33 | 35 | show=show) |
|
34 | 36 | |
|
35 | 37 | nrow,ncol = self.getSubplots() |
|
36 | 38 | colspan = 3 |
|
37 | 39 | rowspan = 1 |
|
38 | 40 | |
|
39 | 41 | for i in range(nplots): |
|
40 | 42 | self.addAxes(nrow, ncol, i, 0, colspan, rowspan) |
|
41 | 43 | |
|
42 | 44 | def plot_iq(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): |
|
43 | 45 | yreal = y[channelIndexList,:].real |
|
44 | 46 | yimag = y[channelIndexList,:].imag |
|
45 | 47 | |
|
46 | 48 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
47 | 49 | xlabel = "Range (Km)" |
|
48 | 50 | ylabel = "Intensity - IQ" |
|
49 | 51 | |
|
50 | 52 | if not self.isConfig: |
|
51 | 53 | nplots = len(channelIndexList) |
|
52 | 54 | |
|
53 | 55 | self.setup(id=id, |
|
54 | 56 | nplots=nplots, |
|
55 | 57 | wintitle='', |
|
56 | 58 | show=show) |
|
57 | 59 | |
|
58 | 60 | if xmin == None: xmin = numpy.nanmin(x) |
|
59 | 61 | if xmax == None: xmax = numpy.nanmax(x) |
|
60 | 62 | if ymin == None: ymin = min(numpy.nanmin(yreal),numpy.nanmin(yimag)) |
|
61 | 63 | if ymax == None: ymax = max(numpy.nanmax(yreal),numpy.nanmax(yimag)) |
|
62 | 64 | |
|
63 | 65 | self.isConfig = True |
|
64 | 66 | |
|
65 | 67 | self.setWinTitle(title) |
|
66 | 68 | |
|
67 | 69 | for i in range(len(self.axesList)): |
|
68 | 70 | title = "Channel %d" %(i) |
|
69 | 71 | axes = self.axesList[i] |
|
70 | 72 | |
|
71 | 73 | axes.pline(x, yreal[i,:], |
|
72 | 74 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
73 | 75 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
74 | 76 | |
|
75 | 77 | axes.addpline(x, yimag[i,:], idline=1, color="red", linestyle="solid", lw=2) |
|
76 | 78 | |
|
77 | 79 | def plot_power(self, x, y, id, channelIndexList, thisDatetime, wintitle, show, xmin, xmax, ymin, ymax): |
|
78 | 80 | y = y[channelIndexList,:] * numpy.conjugate(y[channelIndexList,:]) |
|
79 | 81 | yreal = y.real |
|
80 | 82 | |
|
81 | 83 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
82 | 84 | xlabel = "Range (Km)" |
|
83 | 85 | ylabel = "Intensity" |
|
84 | 86 | |
|
85 | 87 | if not self.isConfig: |
|
86 | 88 | nplots = len(channelIndexList) |
|
87 | 89 | |
|
88 | 90 | self.setup(id=id, |
|
89 | 91 | nplots=nplots, |
|
90 | 92 | wintitle='', |
|
91 | 93 | show=show) |
|
92 | 94 | |
|
93 | 95 | if xmin == None: xmin = numpy.nanmin(x) |
|
94 | 96 | if xmax == None: xmax = numpy.nanmax(x) |
|
95 | 97 | if ymin == None: ymin = numpy.nanmin(yreal) |
|
96 | 98 | if ymax == None: ymax = numpy.nanmax(yreal) |
|
97 | 99 | |
|
98 | 100 | self.isConfig = True |
|
99 | 101 | |
|
100 | 102 | self.setWinTitle(title) |
|
101 | 103 | |
|
102 | 104 | for i in range(len(self.axesList)): |
|
103 | 105 | title = "Channel %d" %(i) |
|
104 | 106 | axes = self.axesList[i] |
|
105 | 107 | ychannel = yreal[i,:] |
|
106 | 108 | axes.pline(x, ychannel, |
|
107 | 109 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
108 | 110 | xlabel=xlabel, ylabel=ylabel, title=title) |
|
109 | 111 | |
|
110 | 112 | |
|
111 | 113 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
112 | 114 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
113 | 115 | figpath='./', figfile=None, show=True, wr_period=1, |
|
114 | server=None, folder=None, username=None, password=None, type='power'): | |
|
116 | ftp=False, server=None, folder=None, username=None, password=None, type='power'): | |
|
115 | 117 | |
|
116 | 118 | """ |
|
117 | 119 | |
|
118 | 120 | Input: |
|
119 | 121 | dataOut : |
|
120 | 122 | id : |
|
121 | 123 | wintitle : |
|
122 | 124 | channelList : |
|
123 | 125 | xmin : None, |
|
124 | 126 | xmax : None, |
|
125 | 127 | ymin : None, |
|
126 | 128 | ymax : None, |
|
127 | 129 | """ |
|
128 | if dataOut.flagNoData: | |
|
129 | return None | |
|
130 | 130 | |
|
131 | 131 | if channelList == None: |
|
132 | 132 | channelIndexList = dataOut.channelIndexList |
|
133 | 133 | else: |
|
134 | 134 | channelIndexList = [] |
|
135 | 135 | for channel in channelList: |
|
136 | 136 | if channel not in dataOut.channelList: |
|
137 | 137 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
138 | 138 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
139 | 139 | |
|
140 | 140 | x = dataOut.heightList |
|
141 | 141 | y = dataOut.data[channelIndexList,:] * numpy.conjugate(dataOut.data[channelIndexList,:]) |
|
142 | 142 | y = y.real |
|
143 | 143 | |
|
144 |
thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[ |
|
|
144 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) | |
|
145 | 145 | |
|
146 | 146 | if type == "power": |
|
147 | 147 | self.plot_power(dataOut.heightList, |
|
148 | 148 | dataOut.data, |
|
149 | 149 | id, |
|
150 | 150 | channelIndexList, |
|
151 | 151 | thisDatetime, |
|
152 | 152 | wintitle, |
|
153 | 153 | show, |
|
154 | 154 | xmin, |
|
155 | 155 | xmax, |
|
156 | 156 | ymin, |
|
157 | 157 | ymax) |
|
158 | 158 | |
|
159 | 159 | if type == "iq": |
|
160 | 160 | self.plot_iq(dataOut.heightList, |
|
161 | 161 | dataOut.data, |
|
162 | 162 | id, |
|
163 | 163 | channelIndexList, |
|
164 | 164 | thisDatetime, |
|
165 | 165 | wintitle, |
|
166 | 166 | show, |
|
167 | 167 | xmin, |
|
168 | 168 | xmax, |
|
169 | 169 | ymin, |
|
170 | 170 | ymax) |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | self.draw() |
|
174 | 174 | |
|
175 | 175 | if save: |
|
176 | 176 | date = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
177 | 177 | if figfile == None: |
|
178 | 178 | figfile = self.getFilename(name = date) |
|
179 | 179 | |
|
180 | 180 | self.saveFigure(figpath, figfile) |
|
181 | 181 | |
|
182 | 182 | self.counter_imagwr += 1 |
|
183 | 183 | if (ftp and (self.counter_imagwr==wr_period)): |
|
184 | 184 | ftp_filename = os.path.join(figpath,figfile) |
|
185 | 185 | self.sendByFTP_Thread(ftp_filename, server, folder, username, password) |
|
186 | 186 | self.counter_imagwr = 0 |
@@ -1,427 +1,424 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import datetime |
|
3 | 3 | import sys |
|
4 | 4 | import matplotlib |
|
5 | 5 | |
|
6 | 6 | if 'linux' in sys.platform: |
|
7 | 7 | matplotlib.use("TKAgg") |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 | 10 | matplotlib.use("TKAgg") |
|
11 | 11 | |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
|
14 | 14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
15 | 15 | from matplotlib.ticker import * |
|
16 | 16 | |
|
17 | 17 | ########################################### |
|
18 | 18 | #Actualizacion de las funciones del driver |
|
19 | 19 | ########################################### |
|
20 | 20 | |
|
21 | 21 | def createFigure(id, wintitle, width, height, facecolor="w", show=True): |
|
22 | 22 | |
|
23 | 23 | matplotlib.pyplot.ioff() |
|
24 | 24 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor) |
|
25 | 25 | fig.canvas.manager.set_window_title(wintitle) |
|
26 | 26 | fig.canvas.manager.resize(width, height) |
|
27 | 27 | matplotlib.pyplot.ion() |
|
28 | 28 | if show: |
|
29 | 29 | matplotlib.pyplot.show() |
|
30 | 30 | |
|
31 | 31 | return fig |
|
32 | 32 | |
|
33 | 33 | def closeFigure(show=True): |
|
34 | 34 | |
|
35 | 35 | matplotlib.pyplot.ioff() |
|
36 | 36 | if show: |
|
37 | 37 | matplotlib.pyplot.show() |
|
38 | 38 | |
|
39 | 39 | return |
|
40 | 40 | |
|
41 | 41 | def saveFigure(fig, filename): |
|
42 | 42 | |
|
43 | 43 | matplotlib.pyplot.ioff() |
|
44 | 44 | fig.savefig(filename) |
|
45 | 45 | matplotlib.pyplot.ion() |
|
46 | 46 | |
|
47 | 47 | def setWinTitle(fig, title): |
|
48 | 48 | |
|
49 | 49 | fig.canvas.manager.set_window_title(title) |
|
50 | 50 | |
|
51 | 51 | def setTitle(fig, title): |
|
52 | 52 | |
|
53 | 53 | fig.suptitle(title) |
|
54 | 54 | |
|
55 | 55 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): |
|
56 | 56 | |
|
57 | 57 | matplotlib.pyplot.ioff() |
|
58 | 58 | matplotlib.pyplot.figure(fig.number) |
|
59 | 59 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
60 | 60 | (xpos, ypos), |
|
61 | 61 | colspan=colspan, |
|
62 | 62 | rowspan=rowspan, |
|
63 | 63 | polar=polar) |
|
64 | 64 | |
|
65 | 65 | matplotlib.pyplot.ion() |
|
66 | 66 | return axes |
|
67 | 67 | |
|
68 | 68 | def setAxesText(ax, text): |
|
69 | 69 | |
|
70 | 70 | ax.annotate(text, |
|
71 | 71 | xy = (.1, .99), |
|
72 | 72 | xycoords = 'figure fraction', |
|
73 | 73 | horizontalalignment = 'left', |
|
74 | 74 | verticalalignment = 'top', |
|
75 | 75 | fontsize = 10) |
|
76 | 76 | |
|
77 | 77 | def printLabels(ax, xlabel, ylabel, title): |
|
78 | 78 | |
|
79 | 79 | ax.set_xlabel(xlabel, size=11) |
|
80 | 80 | ax.set_ylabel(ylabel, size=11) |
|
81 | 81 | ax.set_title(title, size=8) |
|
82 | 82 | |
|
83 | 83 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
84 | 84 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
85 | 85 | nxticks=4, nyticks=10, |
|
86 | 86 | grid=None,color='blue'): |
|
87 | 87 | |
|
88 | 88 | """ |
|
89 | 89 | |
|
90 | 90 | Input: |
|
91 | 91 | grid : None, 'both', 'x', 'y' |
|
92 | 92 | """ |
|
93 | 93 | |
|
94 | 94 | matplotlib.pyplot.ioff() |
|
95 | 95 | |
|
96 | 96 | ax.set_xlim([xmin,xmax]) |
|
97 | 97 | ax.set_ylim([ymin,ymax]) |
|
98 | 98 | |
|
99 | 99 | printLabels(ax, xlabel, ylabel, title) |
|
100 | 100 | |
|
101 | 101 | ###################################################### |
|
102 | 102 | if (xmax-xmin)<=1: |
|
103 | 103 | xtickspos = numpy.linspace(xmin,xmax,nxticks) |
|
104 | 104 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) |
|
105 | 105 | ax.set_xticks(xtickspos) |
|
106 | 106 | else: |
|
107 | 107 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
108 | 108 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
109 | 109 | ax.set_xticks(xtickspos) |
|
110 | 110 | |
|
111 | 111 | for tick in ax.get_xticklabels(): |
|
112 | 112 | tick.set_visible(xtick_visible) |
|
113 | 113 | |
|
114 | 114 | for tick in ax.xaxis.get_major_ticks(): |
|
115 | 115 | tick.label.set_fontsize(ticksize) |
|
116 | 116 | |
|
117 | 117 | ###################################################### |
|
118 | 118 | for tick in ax.get_yticklabels(): |
|
119 | 119 | tick.set_visible(ytick_visible) |
|
120 | 120 | |
|
121 | 121 | for tick in ax.yaxis.get_major_ticks(): |
|
122 | 122 | tick.label.set_fontsize(ticksize) |
|
123 | 123 | |
|
124 | 124 | ax.plot(x, y, color=color) |
|
125 | 125 | iplot = ax.lines[-1] |
|
126 | 126 | |
|
127 | 127 | ###################################################### |
|
128 | 128 | if '0.' in matplotlib.__version__[0:2]: |
|
129 | 129 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
130 | 130 | return iplot |
|
131 | 131 | |
|
132 | 132 | if '1.0.' in matplotlib.__version__[0:4]: |
|
133 | 133 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
134 | 134 | return iplot |
|
135 | 135 | |
|
136 | 136 | if grid != None: |
|
137 | 137 | ax.grid(b=True, which='major', axis=grid) |
|
138 | 138 | |
|
139 | 139 | matplotlib.pyplot.tight_layout() |
|
140 | 140 | |
|
141 | 141 | matplotlib.pyplot.ion() |
|
142 | 142 | |
|
143 | 143 | return iplot |
|
144 | 144 | |
|
145 | 145 | def set_linedata(ax, x, y, idline): |
|
146 | 146 | |
|
147 | 147 | ax.lines[idline].set_data(x,y) |
|
148 | 148 | |
|
149 | 149 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
150 | 150 | |
|
151 | 151 | ax = iplot.get_axes() |
|
152 | 152 | |
|
153 | 153 | printLabels(ax, xlabel, ylabel, title) |
|
154 | 154 | |
|
155 | 155 | set_linedata(ax, x, y, idline=0) |
|
156 | 156 | |
|
157 | 157 | def addpline(ax, x, y, color, linestyle, lw): |
|
158 | 158 | |
|
159 | 159 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) |
|
160 | 160 | |
|
161 | 161 | |
|
162 | 162 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
163 | 163 | xlabel='', ylabel='', title='', ticksize = 9, |
|
164 | 164 | colormap='jet',cblabel='', cbsize="5%", |
|
165 | 165 | XAxisAsTime=False): |
|
166 | 166 | |
|
167 | 167 | matplotlib.pyplot.ioff() |
|
168 | 168 | |
|
169 | 169 | divider = make_axes_locatable(ax) |
|
170 | 170 | ax_cb = divider.new_horizontal(size=cbsize, pad=0.05) |
|
171 | 171 | fig = ax.get_figure() |
|
172 | 172 | fig.add_axes(ax_cb) |
|
173 | 173 | |
|
174 | 174 | ax.set_xlim([xmin,xmax]) |
|
175 | 175 | ax.set_ylim([ymin,ymax]) |
|
176 | 176 | |
|
177 | 177 | printLabels(ax, xlabel, ylabel, title) |
|
178 | 178 | |
|
179 | 179 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
180 | 180 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) |
|
181 | 181 | cb.set_label(cblabel) |
|
182 | 182 | |
|
183 | 183 | # for tl in ax_cb.get_yticklabels(): |
|
184 | 184 | # tl.set_visible(True) |
|
185 | 185 | |
|
186 | 186 | for tick in ax.yaxis.get_major_ticks(): |
|
187 | 187 | tick.label.set_fontsize(ticksize) |
|
188 | 188 | |
|
189 | 189 | for tick in ax.xaxis.get_major_ticks(): |
|
190 | 190 | tick.label.set_fontsize(ticksize) |
|
191 | 191 | |
|
192 | 192 | for tick in cb.ax.get_yticklabels(): |
|
193 | 193 | tick.set_fontsize(ticksize) |
|
194 | 194 | |
|
195 | 195 | ax_cb.yaxis.tick_right() |
|
196 | 196 | |
|
197 | 197 | if '0.' in matplotlib.__version__[0:2]: |
|
198 | 198 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
199 | 199 | return imesh |
|
200 | 200 | |
|
201 | 201 | if '1.0.' in matplotlib.__version__[0:4]: |
|
202 | 202 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
203 | 203 | return imesh |
|
204 | 204 | |
|
205 | 205 | matplotlib.pyplot.tight_layout() |
|
206 | 206 | |
|
207 | 207 | if XAxisAsTime: |
|
208 | 208 | |
|
209 | 209 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
210 | 210 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
211 | 211 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
212 | 212 | |
|
213 | 213 | matplotlib.pyplot.ion() |
|
214 | 214 | return imesh |
|
215 | 215 | |
|
216 | 216 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): |
|
217 | 217 | |
|
218 | 218 | z = z.T |
|
219 | ||
|
220 | 219 | ax = imesh.get_axes() |
|
221 | ||
|
222 | 220 | printLabels(ax, xlabel, ylabel, title) |
|
223 | ||
|
224 | 221 | imesh.set_array(z.ravel()) |
|
225 | 222 | |
|
226 | 223 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
227 | 224 | |
|
228 | 225 | printLabels(ax, xlabel, ylabel, title) |
|
229 | 226 | |
|
230 | 227 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
231 | 228 | |
|
232 | 229 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
233 | 230 | |
|
234 | 231 | printLabels(ax, xlabel, ylabel, title) |
|
235 | 232 | |
|
236 | 233 | ax.collections.remove(ax.collections[0]) |
|
237 | 234 | |
|
238 | 235 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) |
|
239 | 236 | |
|
240 | 237 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
241 | 238 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
242 | 239 | nxticks=4, nyticks=10, |
|
243 | 240 | grid=None): |
|
244 | 241 | |
|
245 | 242 | """ |
|
246 | 243 | |
|
247 | 244 | Input: |
|
248 | 245 | grid : None, 'both', 'x', 'y' |
|
249 | 246 | """ |
|
250 | 247 | |
|
251 | 248 | matplotlib.pyplot.ioff() |
|
252 | 249 | |
|
253 | 250 | lines = ax.plot(x.T, y) |
|
254 | 251 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
255 | 252 | leg.get_frame().set_alpha(0.5) |
|
256 | 253 | ax.set_xlim([xmin,xmax]) |
|
257 | 254 | ax.set_ylim([ymin,ymax]) |
|
258 | 255 | printLabels(ax, xlabel, ylabel, title) |
|
259 | 256 | |
|
260 | 257 | xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
261 | 258 | ax.set_xticks(xtickspos) |
|
262 | 259 | |
|
263 | 260 | for tick in ax.get_xticklabels(): |
|
264 | 261 | tick.set_visible(xtick_visible) |
|
265 | 262 | |
|
266 | 263 | for tick in ax.xaxis.get_major_ticks(): |
|
267 | 264 | tick.label.set_fontsize(ticksize) |
|
268 | 265 | |
|
269 | 266 | for tick in ax.get_yticklabels(): |
|
270 | 267 | tick.set_visible(ytick_visible) |
|
271 | 268 | |
|
272 | 269 | for tick in ax.yaxis.get_major_ticks(): |
|
273 | 270 | tick.label.set_fontsize(ticksize) |
|
274 | 271 | |
|
275 | 272 | iplot = ax.lines[-1] |
|
276 | 273 | |
|
277 | 274 | if '0.' in matplotlib.__version__[0:2]: |
|
278 | 275 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
279 | 276 | return iplot |
|
280 | 277 | |
|
281 | 278 | if '1.0.' in matplotlib.__version__[0:4]: |
|
282 | 279 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
283 | 280 | return iplot |
|
284 | 281 | |
|
285 | 282 | if grid != None: |
|
286 | 283 | ax.grid(b=True, which='major', axis=grid) |
|
287 | 284 | |
|
288 | 285 | matplotlib.pyplot.tight_layout() |
|
289 | 286 | |
|
290 | 287 | matplotlib.pyplot.ion() |
|
291 | 288 | |
|
292 | 289 | return iplot |
|
293 | 290 | |
|
294 | 291 | |
|
295 | 292 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
296 | 293 | |
|
297 | 294 | ax = iplot.get_axes() |
|
298 | 295 | |
|
299 | 296 | printLabels(ax, xlabel, ylabel, title) |
|
300 | 297 | |
|
301 | 298 | for i in range(len(ax.lines)): |
|
302 | 299 | line = ax.lines[i] |
|
303 | 300 | line.set_data(x[i,:],y) |
|
304 | 301 | |
|
305 | 302 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, |
|
306 | 303 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
307 | 304 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", |
|
308 | 305 | grid=None, XAxisAsTime=False): |
|
309 | 306 | |
|
310 | 307 | """ |
|
311 | 308 | |
|
312 | 309 | Input: |
|
313 | 310 | grid : None, 'both', 'x', 'y' |
|
314 | 311 | """ |
|
315 | 312 | |
|
316 | 313 | matplotlib.pyplot.ioff() |
|
317 | 314 | |
|
318 | 315 | # lines = ax.plot(x, y.T, marker=marker,markersize=markersize,linestyle=linestyle) |
|
319 | 316 | lines = ax.plot(x, y.T, linestyle=linestyle, marker=marker, markersize=markersize) |
|
320 | 317 | leg = ax.legend(lines, legendlabels, loc='upper left', bbox_to_anchor=(1.01, 1.00), numpoints=1, handlelength=1.5, \ |
|
321 | 318 | handletextpad=0.5, borderpad=0.5, labelspacing=0.5, borderaxespad=0.) |
|
322 | 319 | |
|
323 | 320 | for label in leg.get_texts(): label.set_fontsize(9) |
|
324 | 321 | |
|
325 | 322 | ax.set_xlim([xmin,xmax]) |
|
326 | 323 | ax.set_ylim([ymin,ymax]) |
|
327 | 324 | printLabels(ax, xlabel, ylabel, title) |
|
328 | 325 | |
|
329 | 326 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
|
330 | 327 | # ax.set_xticks(xtickspos) |
|
331 | 328 | |
|
332 | 329 | for tick in ax.get_xticklabels(): |
|
333 | 330 | tick.set_visible(xtick_visible) |
|
334 | 331 | |
|
335 | 332 | for tick in ax.xaxis.get_major_ticks(): |
|
336 | 333 | tick.label.set_fontsize(ticksize) |
|
337 | 334 | |
|
338 | 335 | for tick in ax.get_yticklabels(): |
|
339 | 336 | tick.set_visible(ytick_visible) |
|
340 | 337 | |
|
341 | 338 | for tick in ax.yaxis.get_major_ticks(): |
|
342 | 339 | tick.label.set_fontsize(ticksize) |
|
343 | 340 | |
|
344 | 341 | iplot = ax.lines[-1] |
|
345 | 342 | |
|
346 | 343 | if '0.' in matplotlib.__version__[0:2]: |
|
347 | 344 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
348 | 345 | return iplot |
|
349 | 346 | |
|
350 | 347 | if '1.0.' in matplotlib.__version__[0:4]: |
|
351 | 348 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
352 | 349 | return iplot |
|
353 | 350 | |
|
354 | 351 | if grid != None: |
|
355 | 352 | ax.grid(b=True, which='major', axis=grid) |
|
356 | 353 | |
|
357 | 354 | matplotlib.pyplot.tight_layout() |
|
358 | 355 | |
|
359 | 356 | if XAxisAsTime: |
|
360 | 357 | |
|
361 | 358 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) |
|
362 | 359 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
363 | 360 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
364 | 361 | |
|
365 | 362 | matplotlib.pyplot.ion() |
|
366 | 363 | |
|
367 | 364 | return iplot |
|
368 | 365 | |
|
369 | 366 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
370 | 367 | |
|
371 | 368 | ax = iplot.get_axes() |
|
372 | 369 | |
|
373 | 370 | printLabels(ax, xlabel, ylabel, title) |
|
374 | 371 | |
|
375 | 372 | for i in range(len(ax.lines)): |
|
376 | 373 | line = ax.lines[i] |
|
377 | 374 | line.set_data(x,y[i,:]) |
|
378 | 375 | |
|
379 | 376 | def createPolar(ax, x, y, |
|
380 | 377 | xlabel='', ylabel='', title='', ticksize = 9, |
|
381 | 378 | colormap='jet',cblabel='', cbsize="5%", |
|
382 | 379 | XAxisAsTime=False): |
|
383 | 380 | |
|
384 | 381 | matplotlib.pyplot.ioff() |
|
385 | 382 | |
|
386 | 383 | ax.plot(x,y,'bo', markersize=5) |
|
387 | 384 | # ax.set_rmax(90) |
|
388 | 385 | ax.set_ylim(0,90) |
|
389 | 386 | ax.set_yticks(numpy.arange(0,90,20)) |
|
390 | 387 | ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') |
|
391 | 388 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') |
|
392 | 389 | printLabels(ax, xlabel, '', title) |
|
393 | 390 | iplot = ax.lines[-1] |
|
394 | 391 | |
|
395 | 392 | if '0.' in matplotlib.__version__[0:2]: |
|
396 | 393 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
397 | 394 | return iplot |
|
398 | 395 | |
|
399 | 396 | if '1.0.' in matplotlib.__version__[0:4]: |
|
400 | 397 | print "The matplotlib version has to be updated to 1.1 or newer" |
|
401 | 398 | return iplot |
|
402 | 399 | |
|
403 | 400 | # if grid != None: |
|
404 | 401 | # ax.grid(b=True, which='major', axis=grid) |
|
405 | 402 | |
|
406 | 403 | matplotlib.pyplot.tight_layout() |
|
407 | 404 | |
|
408 | 405 | matplotlib.pyplot.ion() |
|
409 | 406 | |
|
410 | 407 | |
|
411 | 408 | return iplot |
|
412 | 409 | |
|
413 | 410 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): |
|
414 | 411 | |
|
415 | 412 | ax = iplot.get_axes() |
|
416 | 413 | |
|
417 | 414 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') |
|
418 | 415 | printLabels(ax, xlabel, '', title) |
|
419 | 416 | |
|
420 | 417 | set_linedata(ax, x, y, idline=0) |
|
421 | 418 | |
|
422 | 419 | def draw(fig): |
|
423 | 420 | |
|
424 | 421 | if type(fig) == 'int': |
|
425 | 422 | raise ValueError, "This parameter should be of tpye matplotlib figure" |
|
426 | 423 | |
|
427 | 424 | fig.canvas.draw() |
@@ -0,0 +1,30 | |||
|
1 | ''' | |
|
2 | ||
|
3 | $Author: murco $ | |
|
4 | $Id: JRODataIO.py 169 2012-11-19 21:57:03Z murco $ | |
|
5 | ''' | |
|
6 | ||
|
7 | from jroIO_voltage import * | |
|
8 | from jroIO_spectra import * | |
|
9 | from jroIO_heispectra import * | |
|
10 | from jroIO_usrp import * | |
|
11 | ||
|
12 | try: | |
|
13 | from jroIO_usrp_api import * | |
|
14 | except: | |
|
15 | print "jroIO_usrp_api could not be imported" | |
|
16 | ||
|
17 | try: | |
|
18 | from jroIO_amisr import * | |
|
19 | except: | |
|
20 | print "jroIO_amisr could not be imported" | |
|
21 | ||
|
22 | try: | |
|
23 | from jroIO_HDF5 import * | |
|
24 | except: | |
|
25 | print "jroIO_HDF5 could not be imported" | |
|
26 | ||
|
27 | try: | |
|
28 | from jroIO_hf import * | |
|
29 | except: | |
|
30 | print "jroIO_hf could not be imported" No newline at end of file |
@@ -1,903 +1,903 | |||
|
1 | 1 | import numpy |
|
2 | 2 | import time |
|
3 | 3 | import os |
|
4 | 4 | import h5py |
|
5 | 5 | import re |
|
6 | 6 | |
|
7 | from model.data.jrodata import * | |
|
8 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
|
9 | from model.io.jroIO_base import * | |
|
7 | from schainpy.model.data.jrodata import * | |
|
8 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
9 | from schainpy.model.io.jroIO_base import * | |
|
10 | 10 | |
|
11 | 11 | |
|
12 | 12 | class HDF5Reader(ProcessingUnit): |
|
13 | 13 | |
|
14 | 14 | ext = ".hdf5" |
|
15 | 15 | |
|
16 | 16 | optchar = "D" |
|
17 | 17 | |
|
18 | 18 | timezone = None |
|
19 | 19 | |
|
20 | 20 | secStart = None |
|
21 | 21 | |
|
22 | 22 | secEnd = None |
|
23 | 23 | |
|
24 | 24 | fileIndex = None |
|
25 | 25 | |
|
26 | 26 | blockIndex = None |
|
27 | 27 | |
|
28 | 28 | blocksPerFile = None |
|
29 | 29 | |
|
30 | 30 | path = None |
|
31 | 31 | |
|
32 | 32 | #List of Files |
|
33 | 33 | |
|
34 | 34 | filenameList = None |
|
35 | 35 | |
|
36 | 36 | datetimeList = None |
|
37 | 37 | |
|
38 | 38 | #Hdf5 File |
|
39 | 39 | |
|
40 | 40 | fpMetadata = None |
|
41 | 41 | |
|
42 | 42 | pathMeta = None |
|
43 | 43 | |
|
44 | 44 | listMetaname = None |
|
45 | 45 | |
|
46 | 46 | listMeta = None |
|
47 | 47 | |
|
48 | 48 | listDataname = None |
|
49 | 49 | |
|
50 | 50 | listData = None |
|
51 | 51 | |
|
52 | 52 | listShapes = None |
|
53 | 53 | |
|
54 | 54 | fp = None |
|
55 | 55 | |
|
56 | 56 | #dataOut reconstruction |
|
57 | 57 | |
|
58 | 58 | dataOut = None |
|
59 | 59 | |
|
60 | 60 | nRecords = None |
|
61 | 61 | |
|
62 | 62 | |
|
63 | 63 | def __init__(self): |
|
64 | 64 | self.dataOut = self.__createObjByDefault() |
|
65 | 65 | return |
|
66 | 66 | |
|
67 | 67 | def __createObjByDefault(self): |
|
68 | 68 | |
|
69 | 69 | dataObj = Parameters() |
|
70 | 70 | |
|
71 | 71 | return dataObj |
|
72 | 72 | |
|
73 | 73 | def setup(self,path=None, |
|
74 | 74 | startDate=None, |
|
75 | 75 | endDate=None, |
|
76 | 76 | startTime=datetime.time(0,0,0), |
|
77 | 77 | endTime=datetime.time(23,59,59), |
|
78 | 78 | walk=True, |
|
79 | 79 | timezone='ut', |
|
80 | 80 | all=0, |
|
81 | 81 | online=False, |
|
82 | 82 | ext=None): |
|
83 | 83 | |
|
84 | 84 | if ext==None: |
|
85 | 85 | ext = self.ext |
|
86 | 86 | self.timezone = timezone |
|
87 | 87 | # self.all = all |
|
88 | 88 | # self.online = online |
|
89 | 89 | self.path = path |
|
90 | 90 | |
|
91 | 91 | startDateTime = datetime.datetime.combine(startDate,startTime) |
|
92 | 92 | endDateTime = datetime.datetime.combine(endDate,endTime) |
|
93 | 93 | secStart = (startDateTime-datetime.datetime(1970,1,1)).total_seconds() |
|
94 | 94 | secEnd = (endDateTime-datetime.datetime(1970,1,1)).total_seconds() |
|
95 | 95 | |
|
96 | 96 | self.secStart = secStart |
|
97 | 97 | self.secEnd = secEnd |
|
98 | 98 | |
|
99 | 99 | if not(online): |
|
100 | 100 | #Busqueda de archivos offline |
|
101 | 101 | self.__searchFilesOffline(path, startDate, endDate, ext, startTime, endTime, secStart, secEnd, walk) |
|
102 | 102 | else: |
|
103 | 103 | self.__searchFilesOnline(path, walk) |
|
104 | 104 | |
|
105 | 105 | if not(self.filenameList): |
|
106 | 106 | print "There is no files into the folder: %s"%(path) |
|
107 | 107 | sys.exit(-1) |
|
108 | 108 | |
|
109 | 109 | # self.__getExpParameters() |
|
110 | 110 | |
|
111 | 111 | self.fileIndex = -1 |
|
112 | 112 | |
|
113 | 113 | self.__setNextFileOffline() |
|
114 | 114 | |
|
115 | 115 | self.__readMetadata() |
|
116 | 116 | |
|
117 | 117 | self.blockIndex = 0 |
|
118 | 118 | |
|
119 | 119 | return |
|
120 | 120 | |
|
121 | 121 | def __searchFilesOffline(self, |
|
122 | 122 | path, |
|
123 | 123 | startDate, |
|
124 | 124 | endDate, |
|
125 | 125 | ext, |
|
126 | 126 | startTime=datetime.time(0,0,0), |
|
127 | 127 | endTime=datetime.time(23,59,59), |
|
128 | 128 | secStart = 0, |
|
129 | 129 | secEnd = numpy.inf, |
|
130 | 130 | walk=True): |
|
131 | 131 | |
|
132 | 132 | # self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
133 | 133 | # |
|
134 | 134 | # self.__checkPath() |
|
135 | 135 | # |
|
136 | 136 | # self.__findDataForDates() |
|
137 | 137 | # |
|
138 | 138 | # self.__selectDataForTimes() |
|
139 | 139 | # |
|
140 | 140 | # for i in range(len(self.filenameList)): |
|
141 | 141 | # print "%s" %(self.filenameList[i]) |
|
142 | 142 | |
|
143 | 143 | pathList = [] |
|
144 | 144 | |
|
145 | 145 | if not walk: |
|
146 | 146 | #pathList.append(path) |
|
147 | 147 | multi_path = path.split(',') |
|
148 | 148 | for single_path in multi_path: |
|
149 | 149 | pathList.append(single_path) |
|
150 | 150 | |
|
151 | 151 | else: |
|
152 | 152 | #dirList = [] |
|
153 | 153 | multi_path = path.split(',') |
|
154 | 154 | for single_path in multi_path: |
|
155 | 155 | dirList = [] |
|
156 | 156 | for thisPath in os.listdir(single_path): |
|
157 | 157 | if not os.path.isdir(os.path.join(single_path,thisPath)): |
|
158 | 158 | continue |
|
159 | 159 | if not isDoyFolder(thisPath): |
|
160 | 160 | continue |
|
161 | 161 | |
|
162 | 162 | dirList.append(thisPath) |
|
163 | 163 | |
|
164 | 164 | if not(dirList): |
|
165 | 165 | return None, None |
|
166 | 166 | |
|
167 | 167 | thisDate = startDate |
|
168 | 168 | |
|
169 | 169 | while(thisDate <= endDate): |
|
170 | 170 | year = thisDate.timetuple().tm_year |
|
171 | 171 | doy = thisDate.timetuple().tm_yday |
|
172 | 172 | |
|
173 | 173 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
174 | 174 | if len(matchlist) == 0: |
|
175 | 175 | thisDate += datetime.timedelta(1) |
|
176 | 176 | continue |
|
177 | 177 | for match in matchlist: |
|
178 | 178 | pathList.append(os.path.join(single_path,match)) |
|
179 | 179 | |
|
180 | 180 | thisDate += datetime.timedelta(1) |
|
181 | 181 | |
|
182 | 182 | if pathList == []: |
|
183 | 183 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
184 | 184 | return None, None |
|
185 | 185 | |
|
186 | 186 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
187 | 187 | |
|
188 | 188 | filenameList = [] |
|
189 | 189 | datetimeList = [] |
|
190 | 190 | pathDict = {} |
|
191 | 191 | filenameList_to_sort = [] |
|
192 | 192 | |
|
193 | 193 | for i in range(len(pathList)): |
|
194 | 194 | |
|
195 | 195 | thisPath = pathList[i] |
|
196 | 196 | |
|
197 | 197 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
198 | 198 | fileList.sort() |
|
199 | 199 | pathDict.setdefault(fileList[0]) |
|
200 | 200 | pathDict[fileList[0]] = i |
|
201 | 201 | filenameList_to_sort.append(fileList[0]) |
|
202 | 202 | |
|
203 | 203 | filenameList_to_sort.sort() |
|
204 | 204 | |
|
205 | 205 | for file in filenameList_to_sort: |
|
206 | 206 | thisPath = pathList[pathDict[file]] |
|
207 | 207 | |
|
208 | 208 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
209 | 209 | fileList.sort() |
|
210 | 210 | |
|
211 | 211 | for file in fileList: |
|
212 | 212 | |
|
213 | 213 | filename = os.path.join(thisPath,file) |
|
214 | 214 | thisDatetime = self.__isFileinThisTime(filename, secStart, secEnd) |
|
215 | 215 | |
|
216 | 216 | if not(thisDatetime): |
|
217 | 217 | continue |
|
218 | 218 | |
|
219 | 219 | filenameList.append(filename) |
|
220 | 220 | datetimeList.append(thisDatetime) |
|
221 | 221 | |
|
222 | 222 | if not(filenameList): |
|
223 | 223 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
224 | 224 | return None, None |
|
225 | 225 | |
|
226 | 226 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
227 | 227 | |
|
228 | 228 | |
|
229 | 229 | for i in range(len(filenameList)): |
|
230 | 230 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
231 | 231 | |
|
232 | 232 | self.filenameList = filenameList |
|
233 | 233 | self.datetimeList = datetimeList |
|
234 | 234 | |
|
235 | 235 | return pathList, filenameList |
|
236 | 236 | |
|
237 | 237 | def __isFileinThisTime(self, filename, startSeconds, endSeconds): |
|
238 | 238 | """ |
|
239 | 239 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
240 | 240 | |
|
241 | 241 | Inputs: |
|
242 | 242 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
243 | 243 | |
|
244 | 244 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
245 | 245 | |
|
246 | 246 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
247 | 247 | |
|
248 | 248 | Return: |
|
249 | 249 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
250 | 250 | fecha especificado, de lo contrario retorna False. |
|
251 | 251 | |
|
252 | 252 | Excepciones: |
|
253 | 253 | Si el archivo no existe o no puede ser abierto |
|
254 | 254 | Si la cabecera no puede ser leida. |
|
255 | 255 | |
|
256 | 256 | """ |
|
257 | 257 | |
|
258 | 258 | try: |
|
259 | 259 | fp = fp = h5py.File(filename,'r') |
|
260 | 260 | except IOError: |
|
261 | 261 | traceback.print_exc() |
|
262 | 262 | raise IOError, "The file %s can't be opened" %(filename) |
|
263 | 263 | |
|
264 | 264 | grp = fp['Data'] |
|
265 | 265 | timeAux = grp['time'] |
|
266 | 266 | time0 = timeAux[:][0].astype(numpy.float) #Time Vector |
|
267 | 267 | |
|
268 | 268 | fp.close() |
|
269 | 269 | |
|
270 | 270 | if self.timezone == 'lt': |
|
271 | 271 | time0 -= 5*3600 |
|
272 | 272 | |
|
273 | 273 | boolTimer = numpy.logical_and(time0 >= startSeconds,time0 < endSeconds) |
|
274 | 274 | |
|
275 | 275 | if not (numpy.any(boolTimer)): |
|
276 | 276 | return None |
|
277 | 277 | |
|
278 | 278 | thisDatetime = datetime.datetime.utcfromtimestamp(time0[0]) |
|
279 | 279 | return thisDatetime |
|
280 | 280 | |
|
281 | 281 | def __checkPath(self): |
|
282 | 282 | if os.path.exists(self.path): |
|
283 | 283 | self.status = 1 |
|
284 | 284 | else: |
|
285 | 285 | self.status = 0 |
|
286 | 286 | print 'Path:%s does not exists'%self.path |
|
287 | 287 | |
|
288 | 288 | return |
|
289 | 289 | |
|
290 | 290 | def __setNextFileOffline(self): |
|
291 | 291 | idFile = self.fileIndex |
|
292 | 292 | idFile += 1 |
|
293 | 293 | |
|
294 | 294 | if not(idFile < len(self.filenameList)): |
|
295 | 295 | print "No more Files" |
|
296 | 296 | return 0 |
|
297 | 297 | |
|
298 | 298 | filename = self.filenameList[idFile] |
|
299 | 299 | |
|
300 | 300 | filePointer = h5py.File(filename,'r') |
|
301 | 301 | |
|
302 | 302 | self.flagIsNewFile = 1 |
|
303 | 303 | self.fileIndex = idFile |
|
304 | 304 | self.filename = filename |
|
305 | 305 | |
|
306 | 306 | self.fp = filePointer |
|
307 | 307 | |
|
308 | 308 | print "Setting the file: %s"%self.filename |
|
309 | 309 | |
|
310 | 310 | self.__readMetadata() |
|
311 | 311 | self.__setBlockList() |
|
312 | 312 | # self.nRecords = self.fp['Data'].attrs['blocksPerFile'] |
|
313 | 313 | self.nRecords = self.fp['Data'].attrs['nRecords'] |
|
314 | 314 | self.blockIndex = 0 |
|
315 | 315 | return 1 |
|
316 | 316 | |
|
317 | 317 | def __setBlockList(self): |
|
318 | 318 | ''' |
|
319 | 319 | self.fp |
|
320 | 320 | self.startDateTime |
|
321 | 321 | self.endDateTime |
|
322 | 322 | |
|
323 | 323 | self.blockList |
|
324 | 324 | self.blocksPerFile |
|
325 | 325 | |
|
326 | 326 | ''' |
|
327 | 327 | filePointer = self.fp |
|
328 | 328 | secStart = self.secStart |
|
329 | 329 | secEnd = self.secEnd |
|
330 | 330 | |
|
331 | 331 | grp = filePointer['Data'] |
|
332 | 332 | timeVector = grp['time'].value.astype(numpy.float)[0] |
|
333 | 333 | |
|
334 | 334 | if self.timezone == 'lt': |
|
335 | 335 | timeVector -= 5*3600 |
|
336 | 336 | |
|
337 | 337 | ind = numpy.where(numpy.logical_and(timeVector >= secStart , timeVector < secEnd))[0] |
|
338 | 338 | |
|
339 | 339 | self.blockList = ind |
|
340 | 340 | self.blocksPerFile = len(ind) |
|
341 | 341 | |
|
342 | 342 | return |
|
343 | 343 | |
|
344 | 344 | def __readMetadata(self): |
|
345 | 345 | ''' |
|
346 | 346 | self.pathMeta |
|
347 | 347 | |
|
348 | 348 | self.listShapes |
|
349 | 349 | self.listMetaname |
|
350 | 350 | self.listMeta |
|
351 | 351 | |
|
352 | 352 | ''' |
|
353 | 353 | |
|
354 | 354 | grp = self.fp['Data'] |
|
355 | 355 | pathMeta = os.path.join(self.path, grp.attrs['metadata']) |
|
356 | 356 | |
|
357 | 357 | if pathMeta == self.pathMeta: |
|
358 | 358 | return |
|
359 | 359 | else: |
|
360 | 360 | self.pathMeta = pathMeta |
|
361 | 361 | |
|
362 | 362 | filePointer = h5py.File(self.pathMeta,'r') |
|
363 | 363 | groupPointer = filePointer['Metadata'] |
|
364 | 364 | |
|
365 | 365 | listMetaname = [] |
|
366 | 366 | listMetadata = [] |
|
367 | 367 | for item in groupPointer.items(): |
|
368 | 368 | name = item[0] |
|
369 | 369 | |
|
370 | 370 | if name=='array dimensions': |
|
371 | 371 | table = groupPointer[name][:] |
|
372 | 372 | listShapes = {} |
|
373 | 373 | for shapes in table: |
|
374 | 374 | listShapes[shapes[0]] = numpy.array([shapes[1],shapes[2],shapes[3],shapes[4]]) |
|
375 | 375 | else: |
|
376 | 376 | data = groupPointer[name].value |
|
377 | 377 | listMetaname.append(name) |
|
378 | 378 | listMetadata.append(data) |
|
379 | 379 | |
|
380 | 380 | if name=='type': |
|
381 | 381 | self.__initDataOut(data) |
|
382 | 382 | |
|
383 | 383 | filePointer.close() |
|
384 | 384 | |
|
385 | 385 | self.listShapes = listShapes |
|
386 | 386 | self.listMetaname = listMetaname |
|
387 | 387 | self.listMeta = listMetadata |
|
388 | 388 | |
|
389 | 389 | return |
|
390 | 390 | |
|
391 | 391 | def __readData(self): |
|
392 | 392 | grp = self.fp['Data'] |
|
393 | 393 | listdataname = [] |
|
394 | 394 | listdata = [] |
|
395 | 395 | |
|
396 | 396 | for item in grp.items(): |
|
397 | 397 | name = item[0] |
|
398 | 398 | |
|
399 | 399 | if name == 'time': |
|
400 | 400 | listdataname.append('utctime') |
|
401 | 401 | timeAux = grp[name].value.astype(numpy.float)[0] |
|
402 | 402 | listdata.append(timeAux) |
|
403 | 403 | continue |
|
404 | 404 | |
|
405 | 405 | listdataname.append(name) |
|
406 | 406 | array = self.__setDataArray(self.nRecords, grp[name],self.listShapes[name]) |
|
407 | 407 | listdata.append(array) |
|
408 | 408 | |
|
409 | 409 | self.listDataname = listdataname |
|
410 | 410 | self.listData = listdata |
|
411 | 411 | return |
|
412 | 412 | |
|
413 | 413 | def __setDataArray(self, nRecords, dataset, shapes): |
|
414 | 414 | |
|
415 | 415 | nChannels = shapes[0] #Dimension 0 |
|
416 | 416 | |
|
417 | 417 | nPoints = shapes[1] #Dimension 1, number of Points or Parameters |
|
418 | 418 | |
|
419 | 419 | nSamples = shapes[2] #Dimension 2, number of samples or ranges |
|
420 | 420 | |
|
421 | 421 | mode = shapes[3] |
|
422 | 422 | |
|
423 | 423 | # if nPoints>1: |
|
424 | 424 | # arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples)) |
|
425 | 425 | # else: |
|
426 | 426 | # arrayData = numpy.zeros((nRecords,nChannels,nSamples)) |
|
427 | 427 | # |
|
428 | 428 | # chn = 'channel' |
|
429 | 429 | # |
|
430 | 430 | # for i in range(nChannels): |
|
431 | 431 | # |
|
432 | 432 | # data = dataset[chn + str(i)].value |
|
433 | 433 | # |
|
434 | 434 | # if nPoints>1: |
|
435 | 435 | # data = numpy.rollaxis(data,2) |
|
436 | 436 | # |
|
437 | 437 | # arrayData[:,i,:] = data |
|
438 | 438 | |
|
439 | 439 | arrayData = numpy.zeros((nRecords,nChannels,nPoints,nSamples)) |
|
440 | 440 | doSqueeze = False |
|
441 | 441 | if mode == 0: |
|
442 | 442 | strds = 'channel' |
|
443 | 443 | nDatas = nChannels |
|
444 | 444 | newShapes = (nRecords,nPoints,nSamples) |
|
445 | 445 | if nPoints == 1: |
|
446 | 446 | doSqueeze = True |
|
447 | 447 | axisSqueeze = 2 |
|
448 | 448 | else: |
|
449 | 449 | strds = 'param' |
|
450 | 450 | nDatas = nPoints |
|
451 | 451 | newShapes = (nRecords,nChannels,nSamples) |
|
452 | 452 | if nChannels == 1: |
|
453 | 453 | doSqueeze = True |
|
454 | 454 | axisSqueeze = 1 |
|
455 | 455 | |
|
456 | 456 | for i in range(nDatas): |
|
457 | 457 | |
|
458 | 458 | data = dataset[strds + str(i)].value |
|
459 | 459 | data = data.reshape(newShapes) |
|
460 | 460 | |
|
461 | 461 | if mode == 0: |
|
462 | 462 | arrayData[:,i,:,:] = data |
|
463 | 463 | else: |
|
464 | 464 | arrayData[:,:,i,:] = data |
|
465 | 465 | |
|
466 | 466 | if doSqueeze: |
|
467 | 467 | arrayData = numpy.squeeze(arrayData, axis=axisSqueeze) |
|
468 | 468 | |
|
469 | 469 | return arrayData |
|
470 | 470 | |
|
471 | 471 | def __initDataOut(self, type): |
|
472 | 472 | |
|
473 | 473 | # if type =='Parameters': |
|
474 | 474 | # self.dataOut = Parameters() |
|
475 | 475 | # elif type =='Spectra': |
|
476 | 476 | # self.dataOut = Spectra() |
|
477 | 477 | # elif type =='Voltage': |
|
478 | 478 | # self.dataOut = Voltage() |
|
479 | 479 | # elif type =='Correlation': |
|
480 | 480 | # self.dataOut = Correlation() |
|
481 | 481 | |
|
482 | 482 | return |
|
483 | 483 | |
|
484 | 484 | def __setDataOut(self): |
|
485 | 485 | listMeta = self.listMeta |
|
486 | 486 | listMetaname = self.listMetaname |
|
487 | 487 | listDataname = self.listDataname |
|
488 | 488 | listData = self.listData |
|
489 | 489 | |
|
490 | 490 | blockIndex = self.blockIndex |
|
491 | 491 | blockList = self.blockList |
|
492 | 492 | |
|
493 | 493 | for i in range(len(listMeta)): |
|
494 | 494 | setattr(self.dataOut,listMetaname[i],listMeta[i]) |
|
495 | 495 | |
|
496 | 496 | for j in range(len(listData)): |
|
497 | 497 | if listDataname[j]=='utctime': |
|
498 | 498 | # setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex]]) |
|
499 | 499 | setattr(self.dataOut,'utctimeInit',listData[j][blockList[blockIndex]]) |
|
500 | 500 | continue |
|
501 | 501 | |
|
502 | 502 | setattr(self.dataOut,listDataname[j],listData[j][blockList[blockIndex],:]) |
|
503 | 503 | |
|
504 | 504 | return self.dataOut.data_param |
|
505 | 505 | |
|
506 | 506 | def getData(self): |
|
507 | 507 | |
|
508 | 508 | # if self.flagNoMoreFiles: |
|
509 | 509 | # self.dataOut.flagNoData = True |
|
510 | 510 | # print 'Process finished' |
|
511 | 511 | # return 0 |
|
512 | 512 | # |
|
513 | 513 | if self.blockIndex==self.blocksPerFile: |
|
514 | 514 | if not( self.__setNextFileOffline() ): |
|
515 | 515 | self.dataOut.flagNoData = True |
|
516 | 516 | return 0 |
|
517 | 517 | |
|
518 | 518 | # |
|
519 | 519 | # if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
520 | 520 | # self.dataOut.flagNoData = True |
|
521 | 521 | # return 0 |
|
522 | 522 | |
|
523 | 523 | self.__readData() |
|
524 | 524 | self.__setDataOut() |
|
525 | 525 | self.dataOut.flagNoData = False |
|
526 | 526 | |
|
527 | 527 | self.blockIndex += 1 |
|
528 | 528 | |
|
529 | 529 | return |
|
530 | 530 | |
|
531 | 531 | def run(self, **kwargs): |
|
532 | 532 | |
|
533 | 533 | if not(self.isConfig): |
|
534 | 534 | self.setup(**kwargs) |
|
535 | 535 | # self.setObjProperties() |
|
536 | 536 | self.isConfig = True |
|
537 | 537 | |
|
538 | 538 | self.getData() |
|
539 | 539 | |
|
540 | 540 | return |
|
541 | 541 | |
|
542 | 542 | class HDF5Writer(Operation): |
|
543 | 543 | |
|
544 | 544 | ext = ".hdf5" |
|
545 | 545 | |
|
546 | 546 | optchar = "D" |
|
547 | 547 | |
|
548 | 548 | metaoptchar = "M" |
|
549 | 549 | |
|
550 | 550 | metaFile = None |
|
551 | 551 | |
|
552 | 552 | path = None |
|
553 | 553 | |
|
554 | 554 | setFile = None |
|
555 | 555 | |
|
556 | 556 | fp = None |
|
557 | 557 | |
|
558 | 558 | grp = None |
|
559 | 559 | |
|
560 | 560 | ds = None |
|
561 | 561 | |
|
562 | 562 | firsttime = True |
|
563 | 563 | |
|
564 | 564 | #Configurations |
|
565 | 565 | |
|
566 | 566 | blocksPerFile = None |
|
567 | 567 | |
|
568 | 568 | blockIndex = None |
|
569 | 569 | |
|
570 | 570 | dataOut = None |
|
571 | 571 | |
|
572 | 572 | #Data Arrays |
|
573 | 573 | |
|
574 | 574 | dataList = None |
|
575 | 575 | |
|
576 | 576 | metadataList = None |
|
577 | 577 | |
|
578 | 578 | arrayDim = None |
|
579 | 579 | |
|
580 | 580 | tableDim = None |
|
581 | 581 | |
|
582 | 582 | # dtype = [('arrayName', 'S20'),('nChannels', 'i'), ('nPoints', 'i'), ('nSamples', 'i'),('mode', 'b')] |
|
583 | 583 | |
|
584 | 584 | dtype = [('arrayName', 'S20'),('nDimensions', 'i'), ('dim2', 'i'), ('dim1', 'i'),('dim0', 'i'),('mode', 'b')] |
|
585 | 585 | |
|
586 | 586 | mode = None |
|
587 | 587 | |
|
588 | 588 | nDatas = None #Number of datasets to be stored per array |
|
589 | 589 | |
|
590 | 590 | nDims = None #Number Dimensions in each dataset |
|
591 | 591 | |
|
592 | 592 | def __init__(self): |
|
593 | 593 | |
|
594 | 594 | Operation.__init__(self) |
|
595 | 595 | self.isConfig = False |
|
596 | 596 | return |
|
597 | 597 | |
|
598 | 598 | |
|
599 | 599 | def setup(self, dataOut, **kwargs): |
|
600 | 600 | |
|
601 | 601 | self.path = kwargs['path'] |
|
602 | 602 | |
|
603 | 603 | if kwargs.has_key('ext'): |
|
604 | 604 | self.ext = kwargs['ext'] |
|
605 | 605 | |
|
606 | 606 | if kwargs.has_key('blocksPerFile'): |
|
607 | 607 | self.blocksPerFile = kwargs['blocksPerFile'] |
|
608 | 608 | else: |
|
609 | 609 | self.blocksPerFile = 10 |
|
610 | 610 | |
|
611 | 611 | self.metadataList = kwargs['metadataList'] |
|
612 | 612 | |
|
613 | 613 | self.dataList = kwargs['dataList'] |
|
614 | 614 | |
|
615 | 615 | self.dataOut = dataOut |
|
616 | 616 | |
|
617 | 617 | if kwargs.has_key('mode'): |
|
618 | 618 | mode = kwargs['mode'] |
|
619 | 619 | |
|
620 | 620 | if type(mode) == int: |
|
621 | 621 | mode = numpy.zeros(len(self.dataList)) + mode |
|
622 | 622 | else: |
|
623 | 623 | mode = numpy.zeros(len(self.dataList)) |
|
624 | 624 | |
|
625 | 625 | self.mode = mode |
|
626 | 626 | |
|
627 | 627 | arrayDim = numpy.zeros((len(self.dataList),5)) |
|
628 | 628 | |
|
629 | 629 | #Table dimensions |
|
630 | 630 | |
|
631 | 631 | dtype0 = self.dtype |
|
632 | 632 | |
|
633 | 633 | tableList = [] |
|
634 | 634 | |
|
635 | 635 | for i in range(len(self.dataList)): |
|
636 | 636 | |
|
637 | 637 | dataAux = getattr(self.dataOut, self.dataList[i]) |
|
638 | 638 | |
|
639 | 639 | if type(dataAux)==float or type(dataAux)==int: |
|
640 | 640 | arrayDim[i,0] = 1 |
|
641 | 641 | else: |
|
642 | 642 | arrayDim0 = dataAux.shape |
|
643 | 643 | arrayDim[i,0] = len(arrayDim0) |
|
644 | 644 | arrayDim[i,4] = mode[i] |
|
645 | 645 | |
|
646 | 646 | if len(arrayDim0) == 3: |
|
647 | 647 | arrayDim[i,1:-1] = numpy.array(arrayDim0) |
|
648 | 648 | elif len(arrayDim0) == 2: |
|
649 | 649 | arrayDim[i,2:-1] = numpy.array(arrayDim0) #nHeights |
|
650 | 650 | elif len(arrayDim0) == 1: |
|
651 | 651 | arrayDim[i,3] = arrayDim0 |
|
652 | 652 | elif len(arrayDim0) == 0: |
|
653 | 653 | arrayDim[i,0] = 1 |
|
654 | 654 | arrayDim[i,3] = 1 |
|
655 | 655 | |
|
656 | 656 | table = numpy.array((self.dataList[i],) + tuple(arrayDim[i,:]),dtype = dtype0) |
|
657 | 657 | tableList.append(table) |
|
658 | 658 | |
|
659 | 659 | self.arrayDim = arrayDim |
|
660 | 660 | self.tableDim = numpy.array(tableList, dtype = dtype0) |
|
661 | 661 | self.blockIndex = 0 |
|
662 | 662 | |
|
663 | 663 | return |
|
664 | 664 | |
|
665 | 665 | def putMetadata(self): |
|
666 | 666 | |
|
667 | 667 | fp = self.createMetadataFile() |
|
668 | 668 | self.writeMetadata(fp) |
|
669 | 669 | fp.close() |
|
670 | 670 | return |
|
671 | 671 | |
|
672 | 672 | def createMetadataFile(self): |
|
673 | 673 | ext = self.ext |
|
674 | 674 | path = self.path |
|
675 | 675 | setFile = self.setFile |
|
676 | 676 | |
|
677 | 677 | timeTuple = time.localtime(self.dataOut.utctime) |
|
678 | 678 | subfolder = '' |
|
679 | 679 | |
|
680 | 680 | fullpath = os.path.join( path, subfolder ) |
|
681 | 681 | if not( os.path.exists(fullpath) ): |
|
682 | 682 | os.mkdir(fullpath) |
|
683 | 683 | setFile = -1 #inicializo mi contador de seteo |
|
684 | 684 | else: |
|
685 | 685 | filesList = os.listdir( fullpath ) |
|
686 | 686 | if len( filesList ) > 0: |
|
687 | 687 | filesList = sorted( filesList, key=str.lower ) |
|
688 | 688 | filen = filesList[-1] |
|
689 | 689 | # el filename debera tener el siguiente formato |
|
690 | 690 | # 0 1234 567 89A BCDE (hex) |
|
691 | 691 | # x YYYY DDD SSS .ext |
|
692 | 692 | if isNumber( filen[8:11] ): |
|
693 | 693 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
694 | 694 | else: |
|
695 | 695 | setFile = -1 |
|
696 | 696 | else: |
|
697 | 697 | setFile = -1 #inicializo mi contador de seteo |
|
698 | 698 | |
|
699 | 699 | setFile += 1 |
|
700 | 700 | |
|
701 | 701 | file = '%s%4.4d%3.3d%3.3d%s' % (self.metaoptchar, |
|
702 | 702 | timeTuple.tm_year, |
|
703 | 703 | timeTuple.tm_yday, |
|
704 | 704 | setFile, |
|
705 | 705 | ext ) |
|
706 | 706 | |
|
707 | 707 | filename = os.path.join( path, subfolder, file ) |
|
708 | 708 | self.metaFile = file |
|
709 | 709 | #Setting HDF5 File |
|
710 | 710 | fp = h5py.File(filename,'w') |
|
711 | 711 | |
|
712 | 712 | return fp |
|
713 | 713 | |
|
714 | 714 | def writeMetadata(self, fp): |
|
715 | 715 | |
|
716 | 716 | grp = fp.create_group("Metadata") |
|
717 | 717 | grp.create_dataset('array dimensions', data = self.tableDim, dtype = self.dtype) |
|
718 | 718 | |
|
719 | 719 | for i in range(len(self.metadataList)): |
|
720 | 720 | grp.create_dataset(self.metadataList[i], data=getattr(self.dataOut, self.metadataList[i])) |
|
721 | 721 | return |
|
722 | 722 | |
|
723 | 723 | def setNextFile(self): |
|
724 | 724 | |
|
725 | 725 | ext = self.ext |
|
726 | 726 | path = self.path |
|
727 | 727 | setFile = self.setFile |
|
728 | 728 | mode = self.mode |
|
729 | 729 | |
|
730 | 730 | if self.fp != None: |
|
731 | 731 | self.fp.close() |
|
732 | 732 | |
|
733 | 733 | timeTuple = time.localtime(self.dataOut.utctime) |
|
734 | 734 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
735 | 735 | |
|
736 | 736 | fullpath = os.path.join( path, subfolder ) |
|
737 | 737 | if not( os.path.exists(fullpath) ): |
|
738 | 738 | os.mkdir(fullpath) |
|
739 | 739 | setFile = -1 #inicializo mi contador de seteo |
|
740 | 740 | else: |
|
741 | 741 | filesList = os.listdir( fullpath ) |
|
742 | 742 | if len( filesList ) > 0: |
|
743 | 743 | filesList = sorted( filesList, key=str.lower ) |
|
744 | 744 | filen = filesList[-1] |
|
745 | 745 | # el filename debera tener el siguiente formato |
|
746 | 746 | # 0 1234 567 89A BCDE (hex) |
|
747 | 747 | # x YYYY DDD SSS .ext |
|
748 | 748 | if isNumber( filen[8:11] ): |
|
749 | 749 | setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
750 | 750 | else: |
|
751 | 751 | setFile = -1 |
|
752 | 752 | else: |
|
753 | 753 | setFile = -1 #inicializo mi contador de seteo |
|
754 | 754 | |
|
755 | 755 | setFile += 1 |
|
756 | 756 | |
|
757 | 757 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, |
|
758 | 758 | timeTuple.tm_year, |
|
759 | 759 | timeTuple.tm_yday, |
|
760 | 760 | setFile, |
|
761 | 761 | ext ) |
|
762 | 762 | |
|
763 | 763 | filename = os.path.join( path, subfolder, file ) |
|
764 | 764 | |
|
765 | 765 | #Setting HDF5 File |
|
766 | 766 | fp = h5py.File(filename,'w') |
|
767 | 767 | grp = fp.create_group("Data") |
|
768 | 768 | grp.attrs['metadata'] = self.metaFile |
|
769 | 769 | |
|
770 | 770 | # grp.attrs['blocksPerFile'] = 0 |
|
771 | 771 | |
|
772 | 772 | ds = [] |
|
773 | 773 | data = [] |
|
774 | 774 | |
|
775 | 775 | nDatas = numpy.zeros(len(self.dataList)) |
|
776 | 776 | nDims = self.arrayDim[:,0] |
|
777 | 777 | |
|
778 | 778 | for i in range(len(self.dataList)): |
|
779 | 779 | |
|
780 | 780 | if nDims[i]==1: |
|
781 | 781 | ds0 = grp.create_dataset(self.dataList[i], (1,1), maxshape=(1,None) , chunks = True, dtype='S20') |
|
782 | 782 | ds.append(ds0) |
|
783 | 783 | data.append([]) |
|
784 | 784 | |
|
785 | 785 | else: |
|
786 | 786 | |
|
787 | 787 | if mode[i]==0: |
|
788 | 788 | strMode = "channel" |
|
789 | 789 | nDatas[i] = self.arrayDim[i,1] |
|
790 | 790 | else: |
|
791 | 791 | strMode = "param" |
|
792 | 792 | nDatas[i] = self.arrayDim[i,2] |
|
793 | 793 | |
|
794 | 794 | if nDims[i]==2: |
|
795 | 795 | nDatas[i] = self.arrayDim[i,2] |
|
796 | 796 | |
|
797 | 797 | grp0 = grp.create_group(self.dataList[i]) |
|
798 | 798 | |
|
799 | 799 | for j in range(int(nDatas[i])): |
|
800 | 800 | tableName = strMode + str(j) |
|
801 | 801 | |
|
802 | 802 | if nDims[i] == 3: |
|
803 | 803 | ds0 = grp0.create_dataset(tableName, (1,1,1) , maxshape=(None,None,None), chunks=True) |
|
804 | 804 | else: |
|
805 | 805 | ds0 = grp0.create_dataset(tableName, (1,1) , maxshape=(None,None), chunks=True) |
|
806 | 806 | |
|
807 | 807 | ds.append(ds0) |
|
808 | 808 | data.append([]) |
|
809 | 809 | |
|
810 | 810 | self.nDatas = nDatas |
|
811 | 811 | self.nDims = nDims |
|
812 | 812 | |
|
813 | 813 | #Saving variables |
|
814 | 814 | print 'Writing the file: %s'%filename |
|
815 | 815 | self.fp = fp |
|
816 | 816 | self.grp = grp |
|
817 | 817 | self.ds = ds |
|
818 | 818 | self.data = data |
|
819 | 819 | |
|
820 | 820 | self.setFile = setFile |
|
821 | 821 | self.firsttime = True |
|
822 | 822 | self.blockIndex = 0 |
|
823 | 823 | return |
|
824 | 824 | |
|
825 | 825 | def putData(self): |
|
826 | 826 | self.setBlock() |
|
827 | 827 | self.writeBlock() |
|
828 | 828 | |
|
829 | 829 | if self.blockIndex == self.blocksPerFile: |
|
830 | 830 | self.setNextFile() |
|
831 | 831 | return |
|
832 | 832 | |
|
833 | 833 | def setBlock(self): |
|
834 | 834 | ''' |
|
835 | 835 | data Array configured |
|
836 | 836 | |
|
837 | 837 | |
|
838 | 838 | self.data |
|
839 | 839 | ''' |
|
840 | 840 | #Creating Arrays |
|
841 | 841 | data = self.data |
|
842 | 842 | nDatas = self.nDatas |
|
843 | 843 | nDims = self.nDims |
|
844 | 844 | mode = self.mode |
|
845 | 845 | ind = 0 |
|
846 | 846 | |
|
847 | 847 | for i in range(len(self.dataList)): |
|
848 | 848 | dataAux = getattr(self.dataOut,self.dataList[i]) |
|
849 | 849 | |
|
850 | 850 | if nDims[i] == 1: |
|
851 | 851 | data[ind] = numpy.array([str(dataAux)]).reshape((1,1)) |
|
852 | 852 | if not self.firsttime: |
|
853 | 853 | data[ind] = numpy.hstack((self.ds[ind][:], self.data[ind])) |
|
854 | 854 | ind += 1 |
|
855 | 855 | |
|
856 | 856 | else: |
|
857 | 857 | for j in range(int(nDatas[i])): |
|
858 | 858 | if (mode[i] == 0) or (nDims[i] == 2): #In case division per channel or Dimensions is only 1 |
|
859 | 859 | data[ind] = dataAux[j,:] |
|
860 | 860 | else: |
|
861 | 861 | data[ind] = dataAux[:,j,:] |
|
862 | 862 | |
|
863 | 863 | if nDims[i] == 3: |
|
864 | 864 | data[ind] = data[ind].reshape((data[ind].shape[0],data[ind].shape[1],1)) |
|
865 | 865 | |
|
866 | 866 | if not self.firsttime: |
|
867 | 867 | data[ind] = numpy.dstack((self.ds[ind][:], data[ind])) |
|
868 | 868 | |
|
869 | 869 | else: |
|
870 | 870 | data[ind] = data[ind].reshape((1,data[ind].shape[0])) |
|
871 | 871 | |
|
872 | 872 | if not self.firsttime: |
|
873 | 873 | data[ind] = numpy.vstack((self.ds[ind][:], data[ind])) |
|
874 | 874 | ind += 1 |
|
875 | 875 | |
|
876 | 876 | self.data = data |
|
877 | 877 | return |
|
878 | 878 | |
|
879 | 879 | def writeBlock(self): |
|
880 | 880 | ''' |
|
881 | 881 | Saves the block in the HDF5 file |
|
882 | 882 | ''' |
|
883 | 883 | for i in range(len(self.ds)): |
|
884 | 884 | self.ds[i].resize(self.data[i].shape) |
|
885 | 885 | self.ds[i][:] = self.data[i] |
|
886 | 886 | |
|
887 | 887 | self.blockIndex += 1 |
|
888 | 888 | |
|
889 | 889 | self.grp.attrs.modify('nRecords', self.blockIndex) |
|
890 | 890 | |
|
891 | 891 | self.firsttime = False |
|
892 | 892 | return |
|
893 | 893 | |
|
894 | 894 | def run(self, dataOut, **kwargs): |
|
895 | 895 | if not(self.isConfig): |
|
896 | 896 | self.setup(dataOut, **kwargs) |
|
897 | 897 | self.isConfig = True |
|
898 | 898 | self.putMetadata() |
|
899 | 899 | self.setNextFile() |
|
900 | 900 | |
|
901 | 901 | self.putData() |
|
902 | 902 | return |
|
903 | 903 |
@@ -1,687 +1,687 | |||
|
1 | 1 | ''' |
|
2 | 2 | @author: Daniel Suarez |
|
3 | 3 | ''' |
|
4 | 4 | |
|
5 | 5 | import os |
|
6 | 6 | import sys |
|
7 | 7 | import glob |
|
8 | 8 | import fnmatch |
|
9 | 9 | import datetime |
|
10 | 10 | import time |
|
11 | 11 | import re |
|
12 | 12 | import h5py |
|
13 | 13 | import numpy |
|
14 | 14 | |
|
15 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
|
16 | from model.data.jroamisr import AMISR | |
|
15 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
16 | from schainpy.model.data.jroamisr import AMISR | |
|
17 | 17 | |
|
18 | 18 | class RadacHeader(): |
|
19 | 19 | def __init__(self, fp): |
|
20 | 20 | header = 'Raw11/Data/RadacHeader' |
|
21 | 21 | self.beamCodeByPulse = fp.get(header+'/BeamCode') |
|
22 | 22 | self.beamCode = fp.get('Raw11/Data/Beamcodes') |
|
23 | 23 | self.code = fp.get(header+'/Code') |
|
24 | 24 | self.frameCount = fp.get(header+'/FrameCount') |
|
25 | 25 | self.modeGroup = fp.get(header+'/ModeGroup') |
|
26 | 26 | self.nsamplesPulse = fp.get(header+'/NSamplesPulse') |
|
27 | 27 | self.pulseCount = fp.get(header+'/PulseCount') |
|
28 | 28 | self.radacTime = fp.get(header+'/RadacTime') |
|
29 | 29 | self.timeCount = fp.get(header+'/TimeCount') |
|
30 | 30 | self.timeStatus = fp.get(header+'/TimeStatus') |
|
31 | 31 | |
|
32 | 32 | self.nrecords = self.pulseCount.shape[0] #nblocks |
|
33 | 33 | self.npulses = self.pulseCount.shape[1] #nprofile |
|
34 | 34 | self.nsamples = self.nsamplesPulse[0,0] #ngates |
|
35 | 35 | self.nbeams = self.beamCode.shape[1] |
|
36 | 36 | |
|
37 | 37 | |
|
38 | 38 | def getIndexRangeToPulse(self, idrecord=0): |
|
39 | 39 | #indexToZero = numpy.where(self.pulseCount.value[idrecord,:]==0) |
|
40 | 40 | #startPulseCountId = indexToZero[0][0] |
|
41 | 41 | #endPulseCountId = startPulseCountId - 1 |
|
42 | 42 | #range1 = numpy.arange(startPulseCountId,self.npulses,1) |
|
43 | 43 | #range2 = numpy.arange(0,startPulseCountId,1) |
|
44 | 44 | #return range1, range2 |
|
45 | 45 | zero = 0 |
|
46 | 46 | npulse = max(self.pulseCount[0,:]+1)-1 |
|
47 | 47 | looking_index = numpy.where(self.pulseCount.value[idrecord,:]==npulse)[0] |
|
48 | 48 | getLastIndex = looking_index[-1] |
|
49 | 49 | index_data = numpy.arange(0,getLastIndex+1,1) |
|
50 | 50 | index_buffer = numpy.arange(getLastIndex+1,self.npulses,1) |
|
51 | 51 | return index_data, index_buffer |
|
52 | 52 | |
|
53 | 53 | class AMISRReader(ProcessingUnit): |
|
54 | 54 | |
|
55 | 55 | path = None |
|
56 | 56 | startDate = None |
|
57 | 57 | endDate = None |
|
58 | 58 | startTime = None |
|
59 | 59 | endTime = None |
|
60 | 60 | walk = None |
|
61 | 61 | isConfig = False |
|
62 | 62 | |
|
63 | 63 | def __init__(self): |
|
64 | 64 | self.set = None |
|
65 | 65 | self.subset = None |
|
66 | 66 | self.extension_file = '.h5' |
|
67 | 67 | self.dtc_str = 'dtc' |
|
68 | 68 | self.dtc_id = 0 |
|
69 | 69 | self.status = True |
|
70 | 70 | self.isConfig = False |
|
71 | 71 | self.dirnameList = [] |
|
72 | 72 | self.filenameList = [] |
|
73 | 73 | self.fileIndex = None |
|
74 | 74 | self.flagNoMoreFiles = False |
|
75 | 75 | self.flagIsNewFile = 0 |
|
76 | 76 | self.filename = '' |
|
77 | 77 | self.amisrFilePointer = None |
|
78 | 78 | self.radacHeaderObj = None |
|
79 | 79 | self.dataOut = self.__createObjByDefault() |
|
80 | 80 | self.datablock = None |
|
81 | 81 | self.rest_datablock = None |
|
82 | 82 | self.range = None |
|
83 | 83 | self.idrecord_count = 0 |
|
84 | 84 | self.profileIndex = 0 |
|
85 | 85 | self.index_amisr_sample = None |
|
86 | 86 | self.index_amisr_buffer = None |
|
87 | 87 | self.beamCodeByFrame = None |
|
88 | 88 | self.radacTimeByFrame = None |
|
89 | 89 | #atributos originales tal y como esta en el archivo de datos |
|
90 | 90 | self.beamCodesFromFile = None |
|
91 | 91 | self.radacTimeFromFile = None |
|
92 | 92 | self.rangeFromFile = None |
|
93 | 93 | self.dataByFrame = None |
|
94 | 94 | self.dataset = None |
|
95 | 95 | |
|
96 | 96 | self.beamCodeDict = {} |
|
97 | 97 | self.beamRangeDict = {} |
|
98 | 98 | |
|
99 | 99 | #experiment cgf file |
|
100 | 100 | self.npulsesint_fromfile = None |
|
101 | 101 | self.recordsperfile_fromfile = None |
|
102 | 102 | self.nbeamcodes_fromfile = None |
|
103 | 103 | self.ngates_fromfile = None |
|
104 | 104 | self.ippSeconds_fromfile = None |
|
105 | 105 | self.frequency_h5file = None |
|
106 | 106 | |
|
107 | 107 | |
|
108 | 108 | self.__firstFile = True |
|
109 | 109 | self.buffer_radactime = None |
|
110 | 110 | |
|
111 | 111 | self.index4_schain_datablock = None |
|
112 | 112 | self.index4_buffer = None |
|
113 | 113 | self.schain_datablock = None |
|
114 | 114 | self.buffer = None |
|
115 | 115 | self.linear_pulseCount = None |
|
116 | 116 | self.npulseByFrame = None |
|
117 | 117 | self.profileIndex_offset = None |
|
118 | 118 | self.timezone = 'ut' |
|
119 | 119 | |
|
120 | 120 | self.__waitForNewFile = 20 |
|
121 | 121 | self.__filename_online = None |
|
122 | 122 | |
|
123 | 123 | def __createObjByDefault(self): |
|
124 | 124 | |
|
125 | 125 | dataObj = AMISR() |
|
126 | 126 | |
|
127 | 127 | return dataObj |
|
128 | 128 | |
|
129 | 129 | def __setParameters(self,path='', startDate='',endDate='',startTime='', endTime='', walk=''): |
|
130 | 130 | self.path = path |
|
131 | 131 | self.startDate = startDate |
|
132 | 132 | self.endDate = endDate |
|
133 | 133 | self.startTime = startTime |
|
134 | 134 | self.endTime = endTime |
|
135 | 135 | self.walk = walk |
|
136 | 136 | |
|
137 | 137 | def __checkPath(self): |
|
138 | 138 | if os.path.exists(self.path): |
|
139 | 139 | self.status = 1 |
|
140 | 140 | else: |
|
141 | 141 | self.status = 0 |
|
142 | 142 | print 'Path:%s does not exists'%self.path |
|
143 | 143 | |
|
144 | 144 | return |
|
145 | 145 | |
|
146 | 146 | def __selDates(self, amisr_dirname_format): |
|
147 | 147 | try: |
|
148 | 148 | year = int(amisr_dirname_format[0:4]) |
|
149 | 149 | month = int(amisr_dirname_format[4:6]) |
|
150 | 150 | dom = int(amisr_dirname_format[6:8]) |
|
151 | 151 | thisDate = datetime.date(year,month,dom) |
|
152 | 152 | |
|
153 | 153 | if (thisDate>=self.startDate and thisDate <= self.endDate): |
|
154 | 154 | return amisr_dirname_format |
|
155 | 155 | except: |
|
156 | 156 | return None |
|
157 | 157 | |
|
158 | 158 | def __findDataForDates(self,online=False): |
|
159 | 159 | |
|
160 | 160 | |
|
161 | 161 | |
|
162 | 162 | if not(self.status): |
|
163 | 163 | return None |
|
164 | 164 | |
|
165 | 165 | pat = '\d+.\d+' |
|
166 | 166 | dirnameList = [re.search(pat,x) for x in os.listdir(self.path)] |
|
167 | 167 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
168 | 168 | dirnameList = [x.string for x in dirnameList] |
|
169 | 169 | if not(online): |
|
170 | 170 | dirnameList = [self.__selDates(x) for x in dirnameList] |
|
171 | 171 | dirnameList = filter(lambda x:x!=None,dirnameList) |
|
172 | 172 | if len(dirnameList)>0: |
|
173 | 173 | self.status = 1 |
|
174 | 174 | self.dirnameList = dirnameList |
|
175 | 175 | self.dirnameList.sort() |
|
176 | 176 | else: |
|
177 | 177 | self.status = 0 |
|
178 | 178 | return None |
|
179 | 179 | |
|
180 | 180 | def __getTimeFromData(self): |
|
181 | 181 | startDateTime_Reader = datetime.datetime.combine(self.startDate,self.startTime) |
|
182 | 182 | endDateTime_Reader = datetime.datetime.combine(self.endDate,self.endTime) |
|
183 | 183 | |
|
184 | 184 | print 'Filtering Files from %s to %s'%(startDateTime_Reader, endDateTime_Reader) |
|
185 | 185 | print '........................................' |
|
186 | 186 | filter_filenameList = [] |
|
187 | 187 | self.filenameList.sort() |
|
188 | 188 | for i in range(len(self.filenameList)-1): |
|
189 | 189 | filename = self.filenameList[i] |
|
190 | 190 | fp = h5py.File(filename,'r') |
|
191 | 191 | time_str = fp.get('Time/RadacTimeString') |
|
192 | 192 | |
|
193 | 193 | startDateTimeStr_File = time_str[0][0].split('.')[0] |
|
194 | 194 | junk = time.strptime(startDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
195 | 195 | startDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
196 | 196 | |
|
197 | 197 | endDateTimeStr_File = time_str[-1][-1].split('.')[0] |
|
198 | 198 | junk = time.strptime(endDateTimeStr_File, '%Y-%m-%d %H:%M:%S') |
|
199 | 199 | endDateTime_File = datetime.datetime(junk.tm_year,junk.tm_mon,junk.tm_mday,junk.tm_hour, junk.tm_min, junk.tm_sec) |
|
200 | 200 | |
|
201 | 201 | fp.close() |
|
202 | 202 | |
|
203 | 203 | if self.timezone == 'lt': |
|
204 | 204 | startDateTime_File = startDateTime_File - datetime.timedelta(minutes = 300) |
|
205 | 205 | endDateTime_File = endDateTime_File - datetime.timedelta(minutes = 300) |
|
206 | 206 | |
|
207 | 207 | if (endDateTime_File>=startDateTime_Reader and endDateTime_File<endDateTime_Reader): |
|
208 | 208 | #self.filenameList.remove(filename) |
|
209 | 209 | filter_filenameList.append(filename) |
|
210 | 210 | |
|
211 | 211 | filter_filenameList.sort() |
|
212 | 212 | self.filenameList = filter_filenameList |
|
213 | 213 | return 1 |
|
214 | 214 | |
|
215 | 215 | def __filterByGlob1(self, dirName): |
|
216 | 216 | filter_files = glob.glob1(dirName, '*.*%s'%self.extension_file) |
|
217 | 217 | filterDict = {} |
|
218 | 218 | filterDict.setdefault(dirName) |
|
219 | 219 | filterDict[dirName] = filter_files |
|
220 | 220 | return filterDict |
|
221 | 221 | |
|
222 | 222 | def __getFilenameList(self, fileListInKeys, dirList): |
|
223 | 223 | for value in fileListInKeys: |
|
224 | 224 | dirName = value.keys()[0] |
|
225 | 225 | for file in value[dirName]: |
|
226 | 226 | filename = os.path.join(dirName, file) |
|
227 | 227 | self.filenameList.append(filename) |
|
228 | 228 | |
|
229 | 229 | |
|
230 | 230 | def __selectDataForTimes(self, online=False): |
|
231 | 231 | #aun no esta implementado el filtro for tiempo |
|
232 | 232 | if not(self.status): |
|
233 | 233 | return None |
|
234 | 234 | |
|
235 | 235 | dirList = [os.path.join(self.path,x) for x in self.dirnameList] |
|
236 | 236 | |
|
237 | 237 | fileListInKeys = [self.__filterByGlob1(x) for x in dirList] |
|
238 | 238 | |
|
239 | 239 | self.__getFilenameList(fileListInKeys, dirList) |
|
240 | 240 | if not(online): |
|
241 | 241 | #filtro por tiempo |
|
242 | 242 | if not(self.all): |
|
243 | 243 | self.__getTimeFromData() |
|
244 | 244 | |
|
245 | 245 | if len(self.filenameList)>0: |
|
246 | 246 | self.status = 1 |
|
247 | 247 | self.filenameList.sort() |
|
248 | 248 | else: |
|
249 | 249 | self.status = 0 |
|
250 | 250 | return None |
|
251 | 251 | |
|
252 | 252 | else: |
|
253 | 253 | #get the last file - 1 |
|
254 | 254 | self.filenameList = [self.filenameList[-2]] |
|
255 | 255 | |
|
256 | 256 | new_dirnameList = [] |
|
257 | 257 | for dirname in self.dirnameList: |
|
258 | 258 | junk = numpy.array([dirname in x for x in self.filenameList]) |
|
259 | 259 | junk_sum = junk.sum() |
|
260 | 260 | if junk_sum > 0: |
|
261 | 261 | new_dirnameList.append(dirname) |
|
262 | 262 | self.dirnameList = new_dirnameList |
|
263 | 263 | return 1 |
|
264 | 264 | |
|
265 | 265 | def __searchFilesOnline(self, |
|
266 | 266 | path, |
|
267 | 267 | walk=True): |
|
268 | 268 | |
|
269 | 269 | startDate = datetime.datetime.utcnow().date() |
|
270 | 270 | endDate = datetime.datetime.utcnow().date() |
|
271 | 271 | |
|
272 | 272 | self.__setParameters(path=path, startDate=startDate, endDate=endDate, walk=walk) |
|
273 | 273 | |
|
274 | 274 | self.__checkPath() |
|
275 | 275 | |
|
276 | 276 | self.__findDataForDates(online=True) |
|
277 | 277 | |
|
278 | 278 | self.dirnameList = [self.dirnameList[-1]] |
|
279 | 279 | |
|
280 | 280 | self.__selectDataForTimes(online=True) |
|
281 | 281 | |
|
282 | 282 | return |
|
283 | 283 | |
|
284 | 284 | |
|
285 | 285 | def __searchFilesOffline(self, |
|
286 | 286 | path, |
|
287 | 287 | startDate, |
|
288 | 288 | endDate, |
|
289 | 289 | startTime=datetime.time(0,0,0), |
|
290 | 290 | endTime=datetime.time(23,59,59), |
|
291 | 291 | walk=True): |
|
292 | 292 | |
|
293 | 293 | self.__setParameters(path, startDate, endDate, startTime, endTime, walk) |
|
294 | 294 | |
|
295 | 295 | self.__checkPath() |
|
296 | 296 | |
|
297 | 297 | self.__findDataForDates() |
|
298 | 298 | |
|
299 | 299 | self.__selectDataForTimes() |
|
300 | 300 | |
|
301 | 301 | for i in range(len(self.filenameList)): |
|
302 | 302 | print "%s" %(self.filenameList[i]) |
|
303 | 303 | |
|
304 | 304 | return |
|
305 | 305 | |
|
306 | 306 | def __setNextFileOffline(self): |
|
307 | 307 | idFile = self.fileIndex |
|
308 | 308 | |
|
309 | 309 | while (True): |
|
310 | 310 | idFile += 1 |
|
311 | 311 | if not(idFile < len(self.filenameList)): |
|
312 | 312 | self.flagNoMoreFiles = 1 |
|
313 | 313 | print "No more Files" |
|
314 | 314 | return 0 |
|
315 | 315 | |
|
316 | 316 | filename = self.filenameList[idFile] |
|
317 | 317 | |
|
318 | 318 | amisrFilePointer = h5py.File(filename,'r') |
|
319 | 319 | |
|
320 | 320 | break |
|
321 | 321 | |
|
322 | 322 | self.flagIsNewFile = 1 |
|
323 | 323 | self.fileIndex = idFile |
|
324 | 324 | self.filename = filename |
|
325 | 325 | |
|
326 | 326 | self.amisrFilePointer = amisrFilePointer |
|
327 | 327 | |
|
328 | 328 | print "Setting the file: %s"%self.filename |
|
329 | 329 | |
|
330 | 330 | return 1 |
|
331 | 331 | |
|
332 | 332 | |
|
333 | 333 | def __setNextFileOnline(self): |
|
334 | 334 | filename = self.filenameList[0] |
|
335 | 335 | if self.__filename_online != None: |
|
336 | 336 | self.__selectDataForTimes(online=True) |
|
337 | 337 | filename = self.filenameList[0] |
|
338 | 338 | while self.__filename_online == filename: |
|
339 | 339 | print 'waiting %d seconds to get a new file...'%(self.__waitForNewFile) |
|
340 | 340 | time.sleep(self.__waitForNewFile) |
|
341 | 341 | self.__selectDataForTimes(online=True) |
|
342 | 342 | filename = self.filenameList[0] |
|
343 | 343 | |
|
344 | 344 | self.__filename_online = filename |
|
345 | 345 | |
|
346 | 346 | self.amisrFilePointer = h5py.File(filename,'r') |
|
347 | 347 | self.flagIsNewFile = 1 |
|
348 | 348 | self.filename = filename |
|
349 | 349 | print "Setting the file: %s"%self.filename |
|
350 | 350 | return 1 |
|
351 | 351 | |
|
352 | 352 | |
|
353 | 353 | def __readHeader(self): |
|
354 | 354 | self.radacHeaderObj = RadacHeader(self.amisrFilePointer) |
|
355 | 355 | |
|
356 | 356 | #update values from experiment cfg file |
|
357 | 357 | if self.radacHeaderObj.nrecords == self.recordsperfile_fromfile: |
|
358 | 358 | self.radacHeaderObj.nrecords = self.recordsperfile_fromfile |
|
359 | 359 | self.radacHeaderObj.nbeams = self.nbeamcodes_fromfile |
|
360 | 360 | self.radacHeaderObj.npulses = self.npulsesint_fromfile |
|
361 | 361 | self.radacHeaderObj.nsamples = self.ngates_fromfile |
|
362 | 362 | |
|
363 | 363 | #looking index list for data |
|
364 | 364 | start_index = self.radacHeaderObj.pulseCount[0,:][0] |
|
365 | 365 | end_index = self.radacHeaderObj.npulses |
|
366 | 366 | range4data = range(start_index, end_index) |
|
367 | 367 | self.index4_schain_datablock = numpy.array(range4data) |
|
368 | 368 | |
|
369 | 369 | buffer_start_index = 0 |
|
370 | 370 | buffer_end_index = self.radacHeaderObj.pulseCount[0,:][0] |
|
371 | 371 | range4buffer = range(buffer_start_index, buffer_end_index) |
|
372 | 372 | self.index4_buffer = numpy.array(range4buffer) |
|
373 | 373 | |
|
374 | 374 | self.linear_pulseCount = numpy.array(range4data + range4buffer) |
|
375 | 375 | self.npulseByFrame = max(self.radacHeaderObj.pulseCount[0,:]+1) |
|
376 | 376 | |
|
377 | 377 | #get tuning frequency |
|
378 | 378 | frequency_h5file_dataset = self.amisrFilePointer.get('Rx'+'/TuningFrequency') |
|
379 | 379 | self.frequency_h5file = frequency_h5file_dataset[0,0] |
|
380 | 380 | |
|
381 | 381 | self.flagIsNewFile = 1 |
|
382 | 382 | |
|
383 | 383 | def __getBeamCode(self): |
|
384 | 384 | self.beamCodeDict = {} |
|
385 | 385 | self.beamRangeDict = {} |
|
386 | 386 | |
|
387 | 387 | beamCodeMap = self.amisrFilePointer.get('Setup/BeamcodeMap') |
|
388 | 388 | |
|
389 | 389 | for i in range(len(self.radacHeaderObj.beamCode[0,:])): |
|
390 | 390 | self.beamCodeDict.setdefault(i) |
|
391 | 391 | self.beamRangeDict.setdefault(i) |
|
392 | 392 | beamcodeValue = self.radacHeaderObj.beamCode[0,i] |
|
393 | 393 | beamcodeIndex = numpy.where(beamCodeMap[:,0] == beamcodeValue)[0][0] |
|
394 | 394 | x = beamCodeMap[beamcodeIndex][1] |
|
395 | 395 | y = beamCodeMap[beamcodeIndex][2] |
|
396 | 396 | z = beamCodeMap[beamcodeIndex][3] |
|
397 | 397 | self.beamCodeDict[i] = [beamcodeValue, x, y, z] |
|
398 | 398 | |
|
399 | 399 | just4record0 = self.radacHeaderObj.beamCodeByPulse[0,:] |
|
400 | 400 | |
|
401 | 401 | for i in range(len(self.beamCodeDict.values())): |
|
402 | 402 | xx = numpy.where(just4record0==self.beamCodeDict.values()[i][0]) |
|
403 | 403 | indexPulseByBeam = self.linear_pulseCount[xx[0]] |
|
404 | 404 | self.beamRangeDict[i] = indexPulseByBeam |
|
405 | 405 | |
|
406 | 406 | def __getExpParameters(self): |
|
407 | 407 | if not(self.status): |
|
408 | 408 | return None |
|
409 | 409 | |
|
410 | 410 | experimentCfgPath = os.path.join(self.path, self.dirnameList[0], 'Setup') |
|
411 | 411 | |
|
412 | 412 | expFinder = glob.glob1(experimentCfgPath,'*.exp') |
|
413 | 413 | if len(expFinder)== 0: |
|
414 | 414 | self.status = 0 |
|
415 | 415 | return None |
|
416 | 416 | |
|
417 | 417 | experimentFilename = os.path.join(experimentCfgPath,expFinder[0]) |
|
418 | 418 | |
|
419 | 419 | f = open(experimentFilename) |
|
420 | 420 | lines = f.readlines() |
|
421 | 421 | f.close() |
|
422 | 422 | |
|
423 | 423 | parmsList = ['npulsesint*','recordsperfile*','nbeamcodes*','ngates*'] |
|
424 | 424 | filterList = [fnmatch.filter(lines, x) for x in parmsList] |
|
425 | 425 | |
|
426 | 426 | |
|
427 | 427 | values = [re.sub(r'\D',"",x[0]) for x in filterList] |
|
428 | 428 | |
|
429 | 429 | self.npulsesint_fromfile = int(values[0]) |
|
430 | 430 | self.recordsperfile_fromfile = int(values[1]) |
|
431 | 431 | self.nbeamcodes_fromfile = int(values[2]) |
|
432 | 432 | self.ngates_fromfile = int(values[3]) |
|
433 | 433 | |
|
434 | 434 | tufileFinder = fnmatch.filter(lines, 'tufile=*') |
|
435 | 435 | tufile = tufileFinder[0].split('=')[1].split('\n')[0] |
|
436 | 436 | tufile = tufile.split('\r')[0] |
|
437 | 437 | tufilename = os.path.join(experimentCfgPath,tufile) |
|
438 | 438 | |
|
439 | 439 | f = open(tufilename) |
|
440 | 440 | lines = f.readlines() |
|
441 | 441 | f.close() |
|
442 | 442 | self.ippSeconds_fromfile = float(lines[1].split()[2])/1E6 |
|
443 | 443 | |
|
444 | 444 | |
|
445 | 445 | self.status = 1 |
|
446 | 446 | |
|
447 | 447 | def __setIdsAndArrays(self): |
|
448 | 448 | self.dataByFrame = self.__setDataByFrame() |
|
449 | 449 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[0, :] |
|
450 | 450 | self.readRanges() |
|
451 | 451 | self.index_amisr_sample, self.index_amisr_buffer = self.radacHeaderObj.getIndexRangeToPulse(0) |
|
452 | 452 | self.radacTimeByFrame = numpy.zeros(self.radacHeaderObj.npulses) |
|
453 | 453 | if len(self.index_amisr_buffer) > 0: |
|
454 | 454 | self.buffer_radactime = numpy.zeros_like(self.radacTimeByFrame) |
|
455 | 455 | |
|
456 | 456 | |
|
457 | 457 | def __setNextFile(self,online=False): |
|
458 | 458 | |
|
459 | 459 | if not(online): |
|
460 | 460 | newFile = self.__setNextFileOffline() |
|
461 | 461 | else: |
|
462 | 462 | newFile = self.__setNextFileOnline() |
|
463 | 463 | |
|
464 | 464 | if not(newFile): |
|
465 | 465 | return 0 |
|
466 | 466 | |
|
467 | 467 | self.__readHeader() |
|
468 | 468 | |
|
469 | 469 | if self.__firstFile: |
|
470 | 470 | self.__setIdsAndArrays() |
|
471 | 471 | self.__firstFile = False |
|
472 | 472 | |
|
473 | 473 | self.__getBeamCode() |
|
474 | 474 | self.readDataBlock() |
|
475 | 475 | |
|
476 | 476 | |
|
477 | 477 | def setup(self,path=None, |
|
478 | 478 | startDate=None, |
|
479 | 479 | endDate=None, |
|
480 | 480 | startTime=datetime.time(0,0,0), |
|
481 | 481 | endTime=datetime.time(23,59,59), |
|
482 | 482 | walk=True, |
|
483 | 483 | timezone='ut', |
|
484 | 484 | all=0, |
|
485 | 485 | online=False): |
|
486 | 486 | |
|
487 | 487 | self.timezone = timezone |
|
488 | 488 | self.all = all |
|
489 | 489 | self.online = online |
|
490 | 490 | if not(online): |
|
491 | 491 | #Busqueda de archivos offline |
|
492 | 492 | self.__searchFilesOffline(path, startDate, endDate, startTime, endTime, walk) |
|
493 | 493 | else: |
|
494 | 494 | self.__searchFilesOnline(path, walk) |
|
495 | 495 | |
|
496 | 496 | if not(self.filenameList): |
|
497 | 497 | print "There is no files into the folder: %s"%(path) |
|
498 | 498 | |
|
499 | 499 | sys.exit(-1) |
|
500 | 500 | |
|
501 | 501 | self.__getExpParameters() |
|
502 | 502 | |
|
503 | 503 | self.fileIndex = -1 |
|
504 | 504 | |
|
505 | 505 | self.__setNextFile(online) |
|
506 | 506 | |
|
507 | 507 | # first_beamcode = self.radacHeaderObj.beamCodeByPulse[0,0] |
|
508 | 508 | # index = numpy.where(self.radacHeaderObj.beamCodeByPulse[0,:]!=first_beamcode)[0][0] |
|
509 | 509 | self.profileIndex_offset = self.radacHeaderObj.pulseCount[0,:][0] |
|
510 | 510 | self.profileIndex = self.profileIndex_offset |
|
511 | 511 | |
|
512 | 512 | def readRanges(self): |
|
513 | 513 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Range') |
|
514 | 514 | |
|
515 | 515 | self.rangeFromFile = numpy.reshape(dataset.value,(-1)) |
|
516 | 516 | return self.rangeFromFile |
|
517 | 517 | |
|
518 | 518 | |
|
519 | 519 | def readRadacTime(self,idrecord, range1, range2): |
|
520 | 520 | self.radacTimeFromFile = self.radacHeaderObj.radacTime.value |
|
521 | 521 | |
|
522 | 522 | radacTimeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
523 | 523 | #radacTimeByFrame = dataset[idrecord - 1,range1] |
|
524 | 524 | #radacTimeByFrame = dataset[idrecord,range2] |
|
525 | 525 | |
|
526 | 526 | return radacTimeByFrame |
|
527 | 527 | |
|
528 | 528 | def readBeamCode(self, idrecord, range1, range2): |
|
529 | 529 | dataset = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode') |
|
530 | 530 | beamcodeByFrame = numpy.zeros((self.radacHeaderObj.npulses)) |
|
531 | 531 | self.beamCodesFromFile = dataset.value |
|
532 | 532 | |
|
533 | 533 | #beamcodeByFrame[range1] = dataset[idrecord - 1, range1] |
|
534 | 534 | #beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
535 | 535 | beamcodeByFrame[range1] = dataset[idrecord, range1] |
|
536 | 536 | beamcodeByFrame[range2] = dataset[idrecord, range2] |
|
537 | 537 | |
|
538 | 538 | return beamcodeByFrame |
|
539 | 539 | |
|
540 | 540 | |
|
541 | 541 | def __setDataByFrame(self): |
|
542 | 542 | ndata = 2 # porque es complejo |
|
543 | 543 | dataByFrame = numpy.zeros((self.radacHeaderObj.npulses, self.radacHeaderObj.nsamples, ndata)) |
|
544 | 544 | return dataByFrame |
|
545 | 545 | |
|
546 | 546 | def __readDataSet(self): |
|
547 | 547 | dataset = self.amisrFilePointer.get('Raw11/Data/Samples/Data') |
|
548 | 548 | return dataset |
|
549 | 549 | |
|
550 | 550 | def __setDataBlock(self,): |
|
551 | 551 | real = self.dataByFrame[:,:,0] #asumo que 0 es real |
|
552 | 552 | imag = self.dataByFrame[:,:,1] #asumo que 1 es imaginario |
|
553 | 553 | datablock = real + imag*1j #armo el complejo |
|
554 | 554 | return datablock |
|
555 | 555 | |
|
556 | 556 | def readSamples_version1(self,idrecord): |
|
557 | 557 | #estas tres primeras lineas solo se deben ejecutar una vez |
|
558 | 558 | if self.flagIsNewFile: |
|
559 | 559 | #reading dataset |
|
560 | 560 | self.dataset = self.__readDataSet() |
|
561 | 561 | self.flagIsNewFile = 0 |
|
562 | 562 | |
|
563 | 563 | if idrecord == 0: |
|
564 | 564 | self.dataByFrame[self.index4_schain_datablock, : ,:] = self.dataset[0, self.index_amisr_sample,:,:] |
|
565 | 565 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[0, self.index_amisr_sample] |
|
566 | 566 | datablock = self.__setDataBlock() |
|
567 | 567 | if len(self.index_amisr_buffer) > 0: |
|
568 | 568 | self.buffer = self.dataset[0, self.index_amisr_buffer,:,:] |
|
569 | 569 | self.buffer_radactime = self.radacHeaderObj.radacTime[0, self.index_amisr_buffer] |
|
570 | 570 | |
|
571 | 571 | return datablock |
|
572 | 572 | if len(self.index_amisr_buffer) > 0: |
|
573 | 573 | self.dataByFrame[self.index4_buffer,:,:] = self.buffer.copy() |
|
574 | 574 | self.radacTimeByFrame[self.index4_buffer] = self.buffer_radactime.copy() |
|
575 | 575 | self.dataByFrame[self.index4_schain_datablock,:,:] = self.dataset[idrecord, self.index_amisr_sample,:,:] |
|
576 | 576 | self.radacTimeByFrame[self.index4_schain_datablock] = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_sample] |
|
577 | 577 | datablock = self.__setDataBlock() |
|
578 | 578 | if len(self.index_amisr_buffer) > 0: |
|
579 | 579 | self.buffer = self.dataset[idrecord, self.index_amisr_buffer, :, :] |
|
580 | 580 | self.buffer_radactime = self.radacHeaderObj.radacTime[idrecord, self.index_amisr_buffer] |
|
581 | 581 | |
|
582 | 582 | return datablock |
|
583 | 583 | |
|
584 | 584 | |
|
585 | 585 | def readSamples(self,idrecord): |
|
586 | 586 | if self.flagIsNewFile: |
|
587 | 587 | self.dataByFrame = self.__setDataByFrame() |
|
588 | 588 | self.beamCodeByFrame = self.amisrFilePointer.get('Raw11/Data/RadacHeader/BeamCode').value[idrecord, :] |
|
589 | 589 | |
|
590 | 590 | #reading ranges |
|
591 | 591 | self.readRanges() |
|
592 | 592 | #reading dataset |
|
593 | 593 | self.dataset = self.__readDataSet() |
|
594 | 594 | |
|
595 | 595 | self.flagIsNewFile = 0 |
|
596 | 596 | self.radacTimeByFrame = self.radacHeaderObj.radacTime.value[idrecord, :] |
|
597 | 597 | self.dataByFrame = self.dataset[idrecord, :, :, :] |
|
598 | 598 | datablock = self.__setDataBlock() |
|
599 | 599 | return datablock |
|
600 | 600 | |
|
601 | 601 | |
|
602 | 602 | def readDataBlock(self): |
|
603 | 603 | |
|
604 | 604 | self.datablock = self.readSamples_version1(self.idrecord_count) |
|
605 | 605 | #self.datablock = self.readSamples(self.idrecord_count) |
|
606 | 606 | #print 'record:', self.idrecord_count |
|
607 | 607 | |
|
608 | 608 | self.idrecord_count += 1 |
|
609 | 609 | self.profileIndex = 0 |
|
610 | 610 | |
|
611 | 611 | if self.idrecord_count >= self.radacHeaderObj.nrecords: |
|
612 | 612 | self.idrecord_count = 0 |
|
613 | 613 | self.flagIsNewFile = 1 |
|
614 | 614 | |
|
615 | 615 | def readNextBlock(self): |
|
616 | 616 | |
|
617 | 617 | self.readDataBlock() |
|
618 | 618 | |
|
619 | 619 | if self.flagIsNewFile: |
|
620 | 620 | self.__setNextFile(self.online) |
|
621 | 621 | pass |
|
622 | 622 | |
|
623 | 623 | def __hasNotDataInBuffer(self): |
|
624 | 624 | #self.radacHeaderObj.npulses debe ser otra variable para considerar el numero de pulsos a tomar en el primer y ultimo record |
|
625 | 625 | if self.profileIndex >= self.radacHeaderObj.npulses: |
|
626 | 626 | return 1 |
|
627 | 627 | return 0 |
|
628 | 628 | |
|
629 | 629 | def printUTC(self): |
|
630 | 630 | print self.dataOut.utctime |
|
631 | 631 | print '' |
|
632 | 632 | |
|
633 | 633 | def setObjProperties(self): |
|
634 | 634 | |
|
635 | 635 | self.dataOut.heightList = self.rangeFromFile/1000.0 #km |
|
636 | 636 | self.dataOut.nProfiles = self.radacHeaderObj.npulses |
|
637 | 637 | self.dataOut.nRecords = self.radacHeaderObj.nrecords |
|
638 | 638 | self.dataOut.nBeams = self.radacHeaderObj.nbeams |
|
639 | 639 | self.dataOut.ippSeconds = self.ippSeconds_fromfile |
|
640 | 640 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
641 | 641 | self.dataOut.frequency = self.frequency_h5file |
|
642 | 642 | self.dataOut.npulseByFrame = self.npulseByFrame |
|
643 | 643 | self.dataOut.nBaud = None |
|
644 | 644 | self.dataOut.nCode = None |
|
645 | 645 | self.dataOut.code = None |
|
646 | 646 | |
|
647 | 647 | self.dataOut.beamCodeDict = self.beamCodeDict |
|
648 | 648 | self.dataOut.beamRangeDict = self.beamRangeDict |
|
649 | 649 | |
|
650 | 650 | if self.timezone == 'lt': |
|
651 | 651 | self.dataOut.timeZone = time.timezone / 60. #get the timezone in minutes |
|
652 | 652 | else: |
|
653 | 653 | self.dataOut.timeZone = 0 #by default time is UTC |
|
654 | 654 | |
|
655 | 655 | def getData(self): |
|
656 | 656 | |
|
657 | 657 | if self.flagNoMoreFiles: |
|
658 | 658 | self.dataOut.flagNoData = True |
|
659 | 659 | print 'Process finished' |
|
660 | 660 | return 0 |
|
661 | 661 | |
|
662 | 662 | if self.__hasNotDataInBuffer(): |
|
663 | 663 | self.readNextBlock() |
|
664 | 664 | |
|
665 | 665 | |
|
666 | 666 | if self.datablock == None: # setear esta condicion cuando no hayan datos por leers |
|
667 | 667 | self.dataOut.flagNoData = True |
|
668 | 668 | return 0 |
|
669 | 669 | |
|
670 | 670 | self.dataOut.data = numpy.reshape(self.datablock[self.profileIndex,:],(1,-1)) |
|
671 | 671 | |
|
672 | 672 | self.dataOut.utctime = self.radacTimeByFrame[self.profileIndex] |
|
673 | 673 | self.dataOut.profileIndex = self.profileIndex |
|
674 | 674 | self.dataOut.flagNoData = False |
|
675 | 675 | |
|
676 | 676 | self.profileIndex += 1 |
|
677 | 677 | |
|
678 | 678 | return self.dataOut.data |
|
679 | 679 | |
|
680 | 680 | |
|
681 | 681 | def run(self, **kwargs): |
|
682 | 682 | if not(self.isConfig): |
|
683 | 683 | self.setup(**kwargs) |
|
684 | 684 | self.setObjProperties() |
|
685 | 685 | self.isConfig = True |
|
686 | 686 | |
|
687 | 687 | self.getData() |
@@ -1,1352 +1,1345 | |||
|
1 | 1 | ''' |
|
2 | Created on Jul 2, 2014 | |
|
2 | 3 | |
|
4 | @author: roj-idl71 | |
|
3 | 5 | ''' |
|
4 | 6 | import os |
|
5 | 7 | import sys |
|
6 | 8 | import glob |
|
7 | 9 | import time |
|
8 | 10 | import numpy |
|
9 | 11 | import fnmatch |
|
10 | 12 | import time, datetime |
|
11 | 13 | #import h5py |
|
12 | 14 | import traceback |
|
13 | 15 | |
|
14 |
|
|
|
15 | # import pyfits | |
|
16 |
|
|
|
17 | # print "pyfits module has not been imported, it should be installed to save files in fits format" | |
|
18 | ||
|
19 | #from jrodata import * | |
|
20 | #from jroheaderIO import * | |
|
21 | #from jroprocessing import * | |
|
22 | ||
|
23 | #import re | |
|
24 | #from xml.etree.ElementTree import Element, SubElement, ElementTree | |
|
25 | ||
|
26 | ||
|
27 | LOCALTIME = True #-18000 | |
|
16 | try: | |
|
17 | from gevent import sleep | |
|
18 | except: | |
|
19 | from time import sleep | |
|
20 | ||
|
21 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
|
28 | 22 | |
|
29 | from model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
|
23 | LOCALTIME = True | |
|
30 | 24 | |
|
31 |
def isNumber( |
|
|
25 | def isNumber(cad): | |
|
32 | 26 | """ |
|
33 | 27 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
34 | 28 | |
|
35 | 29 | Excepciones: |
|
36 | 30 | Si un determinado string no puede ser convertido a numero |
|
37 | 31 | Input: |
|
38 | 32 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
39 | 33 | |
|
40 | 34 | Return: |
|
41 | 35 | True : si el string es uno numerico |
|
42 | 36 | False : no es un string numerico |
|
43 | 37 | """ |
|
44 | 38 | try: |
|
45 |
float( |
|
|
39 | float( cad ) | |
|
46 | 40 | return True |
|
47 | 41 | except: |
|
48 | 42 | return False |
|
49 | 43 | |
|
50 | 44 | def isThisFileinRange(filename, startUTSeconds, endUTSeconds): |
|
51 | 45 | """ |
|
52 | 46 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
|
53 | 47 | |
|
54 | 48 | Inputs: |
|
55 | 49 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
56 | 50 | |
|
57 | 51 | startUTSeconds : fecha inicial del rango seleccionado. La fecha esta dada en |
|
58 | 52 | segundos contados desde 01/01/1970. |
|
59 | 53 | endUTSeconds : fecha final del rango seleccionado. La fecha esta dada en |
|
60 | 54 | segundos contados desde 01/01/1970. |
|
61 | 55 | |
|
62 | 56 | Return: |
|
63 | 57 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
64 | 58 | fecha especificado, de lo contrario retorna False. |
|
65 | 59 | |
|
66 | 60 | Excepciones: |
|
67 | 61 | Si el archivo no existe o no puede ser abierto |
|
68 | 62 | Si la cabecera no puede ser leida. |
|
69 | 63 | |
|
70 | 64 | """ |
|
71 | 65 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
72 | 66 | |
|
73 | 67 | try: |
|
74 | 68 | fp = open(filename,'rb') |
|
75 | 69 | except IOError: |
|
76 | 70 | traceback.print_exc() |
|
77 | 71 | raise IOError, "The file %s can't be opened" %(filename) |
|
78 | 72 | |
|
79 | 73 | sts = basicHeaderObj.read(fp) |
|
80 | 74 | fp.close() |
|
81 | 75 | |
|
82 | 76 | if not(sts): |
|
83 | 77 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
84 | 78 | return 0 |
|
85 | 79 | |
|
86 | 80 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
|
87 | 81 | return 0 |
|
88 | 82 | |
|
89 | 83 | return 1 |
|
90 | 84 | |
|
91 | 85 | def isFileinThisTime(filename, startTime, endTime): |
|
92 | 86 | """ |
|
93 | 87 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
|
94 | 88 | |
|
95 | 89 | Inputs: |
|
96 | 90 | filename : nombre completo del archivo de datos en formato Jicamarca (.r) |
|
97 | 91 | |
|
98 | 92 | startTime : tiempo inicial del rango seleccionado en formato datetime.time |
|
99 | 93 | |
|
100 | 94 | endTime : tiempo final del rango seleccionado en formato datetime.time |
|
101 | 95 | |
|
102 | 96 | Return: |
|
103 | 97 | Boolean : Retorna True si el archivo de datos contiene datos en el rango de |
|
104 | 98 | fecha especificado, de lo contrario retorna False. |
|
105 | 99 | |
|
106 | 100 | Excepciones: |
|
107 | 101 | Si el archivo no existe o no puede ser abierto |
|
108 | 102 | Si la cabecera no puede ser leida. |
|
109 | 103 | |
|
110 | 104 | """ |
|
111 | 105 | |
|
112 | 106 | |
|
113 | 107 | try: |
|
114 | 108 | fp = open(filename,'rb') |
|
115 | 109 | except IOError: |
|
116 | 110 | traceback.print_exc() |
|
117 | 111 | raise IOError, "The file %s can't be opened" %(filename) |
|
118 | 112 | |
|
119 | 113 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
120 | 114 | sts = basicHeaderObj.read(fp) |
|
121 | 115 | fp.close() |
|
122 | 116 | |
|
123 | 117 | thisDatetime = basicHeaderObj.datatime |
|
124 | 118 | thisTime = thisDatetime.time() |
|
125 | 119 | |
|
126 | 120 | if not(sts): |
|
127 | 121 | print "Skipping the file %s because it has not a valid header" %(filename) |
|
128 | 122 | return None |
|
129 | 123 | |
|
130 | 124 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
131 | 125 | return None |
|
132 | 126 | |
|
133 | 127 | return thisDatetime |
|
134 | 128 | |
|
135 | 129 | def getFileFromSet(path, ext, set): |
|
136 | 130 | validFilelist = [] |
|
137 | 131 | fileList = os.listdir(path) |
|
138 | 132 | |
|
139 | 133 | # 0 1234 567 89A BCDE |
|
140 | 134 | # H YYYY DDD SSS .ext |
|
141 | 135 | |
|
142 | 136 | for thisFile in fileList: |
|
143 | 137 | try: |
|
144 | 138 | year = int(thisFile[1:5]) |
|
145 | 139 | doy = int(thisFile[5:8]) |
|
146 | 140 | except: |
|
147 | 141 | continue |
|
148 | 142 | |
|
149 | 143 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
150 | 144 | continue |
|
151 | 145 | |
|
152 | 146 | validFilelist.append(thisFile) |
|
153 | 147 | |
|
154 | 148 | myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set)) |
|
155 | 149 | |
|
156 | 150 | if len(myfile)!= 0: |
|
157 | 151 | return myfile[0] |
|
158 | 152 | else: |
|
159 | 153 | filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower()) |
|
160 | 154 | print 'the filename %s does not exist'%filename |
|
161 | 155 | print '...going to the last file: ' |
|
162 | 156 | |
|
163 | 157 | if validFilelist: |
|
164 | 158 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
165 | 159 | return validFilelist[-1] |
|
166 | 160 | |
|
167 | 161 | return None |
|
168 | 162 | |
|
169 | 163 | def getlastFileFromPath(path, ext): |
|
170 | 164 | """ |
|
171 | 165 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
|
172 | 166 | al final de la depuracion devuelve el ultimo file de la lista que quedo. |
|
173 | 167 | |
|
174 | 168 | Input: |
|
175 | 169 | fileList : lista conteniendo todos los files (sin path) que componen una determinada carpeta |
|
176 | 170 | ext : extension de los files contenidos en una carpeta |
|
177 | 171 | |
|
178 | 172 | Return: |
|
179 | 173 | El ultimo file de una determinada carpeta, no se considera el path. |
|
180 | 174 | """ |
|
181 | 175 | validFilelist = [] |
|
182 | 176 | fileList = os.listdir(path) |
|
183 | 177 | |
|
184 | 178 | # 0 1234 567 89A BCDE |
|
185 | 179 | # H YYYY DDD SSS .ext |
|
186 | 180 | |
|
187 | 181 | for thisFile in fileList: |
|
188 | 182 | |
|
189 | 183 | year = thisFile[1:5] |
|
190 | 184 | if not isNumber(year): |
|
191 | 185 | continue |
|
192 | 186 | |
|
193 | 187 | doy = thisFile[5:8] |
|
194 | 188 | if not isNumber(doy): |
|
195 | 189 | continue |
|
196 | 190 | |
|
197 | 191 | year = int(year) |
|
198 | 192 | doy = int(doy) |
|
199 | 193 | |
|
200 | 194 | if (os.path.splitext(thisFile)[-1].lower() != ext.lower()): |
|
201 | 195 | continue |
|
202 | 196 | |
|
203 | 197 | validFilelist.append(thisFile) |
|
204 | 198 | |
|
205 | 199 | if validFilelist: |
|
206 | 200 | validFilelist = sorted( validFilelist, key=str.lower ) |
|
207 | 201 | return validFilelist[-1] |
|
208 | 202 | |
|
209 | 203 | return None |
|
210 | 204 | |
|
211 | 205 | def checkForRealPath(path, foldercounter, year, doy, set, ext): |
|
212 | 206 | """ |
|
213 | 207 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
|
214 | 208 | Prueba por varias combinaciones de nombres entre mayusculas y minusculas para determinar |
|
215 | 209 | el path exacto de un determinado file. |
|
216 | 210 | |
|
217 | 211 | Example : |
|
218 | 212 | nombre correcto del file es .../.../D2009307/P2009307367.ext |
|
219 | 213 | |
|
220 | 214 | Entonces la funcion prueba con las siguientes combinaciones |
|
221 | 215 | .../.../y2009307367.ext |
|
222 | 216 | .../.../Y2009307367.ext |
|
223 | 217 | .../.../x2009307/y2009307367.ext |
|
224 | 218 | .../.../x2009307/Y2009307367.ext |
|
225 | 219 | .../.../X2009307/y2009307367.ext |
|
226 | 220 | .../.../X2009307/Y2009307367.ext |
|
227 | 221 | siendo para este caso, la ultima combinacion de letras, identica al file buscado |
|
228 | 222 | |
|
229 | 223 | Return: |
|
230 | 224 | Si encuentra la cobinacion adecuada devuelve el path completo y el nombre del file |
|
231 | 225 | caso contrario devuelve None como path y el la ultima combinacion de nombre en mayusculas |
|
232 | 226 | para el filename |
|
233 | 227 | """ |
|
234 | 228 | fullfilename = None |
|
235 | 229 | find_flag = False |
|
236 | 230 | filename = None |
|
237 | 231 | |
|
238 | 232 | prefixDirList = [None,'d','D'] |
|
239 | 233 | if ext.lower() == ".r": #voltage |
|
240 | 234 | prefixFileList = ['d','D'] |
|
241 | 235 | elif ext.lower() == ".pdata": #spectra |
|
242 | 236 | prefixFileList = ['p','P'] |
|
243 | 237 | else: |
|
244 | 238 | return None, filename |
|
245 | 239 | |
|
246 | 240 | #barrido por las combinaciones posibles |
|
247 | 241 | for prefixDir in prefixDirList: |
|
248 | 242 | thispath = path |
|
249 | 243 | if prefixDir != None: |
|
250 | 244 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) |
|
251 | 245 | if foldercounter == 0: |
|
252 | 246 | thispath = os.path.join(path, "%s%04d%03d" % ( prefixDir, year, doy )) |
|
253 | 247 | else: |
|
254 | 248 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( prefixDir, year, doy , foldercounter)) |
|
255 | 249 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" |
|
256 | 250 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext |
|
257 | 251 | fullfilename = os.path.join( thispath, filename ) #formo el path completo |
|
258 | 252 | |
|
259 | 253 | if os.path.exists( fullfilename ): #verifico que exista |
|
260 | 254 | find_flag = True |
|
261 | 255 | break |
|
262 | 256 | if find_flag: |
|
263 | 257 | break |
|
264 | 258 | |
|
265 | 259 | if not(find_flag): |
|
266 | 260 | return None, filename |
|
267 | 261 | |
|
268 | 262 | return fullfilename, filename |
|
269 | 263 | |
|
270 | 264 | def isDoyFolder(folder): |
|
271 | 265 | try: |
|
272 | 266 | year = int(folder[1:5]) |
|
273 | 267 | except: |
|
274 | 268 | return 0 |
|
275 | 269 | |
|
276 | 270 | try: |
|
277 | 271 | doy = int(folder[5:8]) |
|
278 | 272 | except: |
|
279 | 273 | return 0 |
|
280 | 274 | |
|
281 | 275 | return 1 |
|
282 | 276 | |
|
283 | 277 | class JRODataIO: |
|
284 | 278 | |
|
285 | 279 | c = 3E8 |
|
286 | 280 | |
|
287 | 281 | isConfig = False |
|
288 | 282 | |
|
289 | 283 | basicHeaderObj = None |
|
290 | 284 | |
|
291 | 285 | systemHeaderObj = None |
|
292 | 286 | |
|
293 | 287 | radarControllerHeaderObj = None |
|
294 | 288 | |
|
295 | 289 | processingHeaderObj = None |
|
296 | 290 | |
|
297 | 291 | online = 0 |
|
298 | 292 | |
|
299 | 293 | dtype = None |
|
300 | 294 | |
|
301 | 295 | pathList = [] |
|
302 | 296 | |
|
303 | 297 | filenameList = [] |
|
304 | 298 | |
|
305 | 299 | filename = None |
|
306 | 300 | |
|
307 | 301 | ext = None |
|
308 | 302 | |
|
309 | 303 | flagIsNewFile = 1 |
|
310 | 304 | |
|
311 |
flag |
|
|
305 | flagDiscontinuousBlock = 0 | |
|
312 | 306 | |
|
313 | 307 | flagIsNewBlock = 0 |
|
314 | 308 | |
|
315 | 309 | fp = None |
|
316 | 310 | |
|
317 | 311 | firstHeaderSize = 0 |
|
318 | 312 | |
|
319 | 313 | basicHeaderSize = 24 |
|
320 | 314 | |
|
321 | 315 | versionFile = 1103 |
|
322 | 316 | |
|
323 | 317 | fileSize = None |
|
324 | 318 | |
|
325 | 319 | # ippSeconds = None |
|
326 | 320 | |
|
327 | 321 | fileSizeByHeader = None |
|
328 | 322 | |
|
329 | 323 | fileIndex = None |
|
330 | 324 | |
|
331 | 325 | profileIndex = None |
|
332 | 326 | |
|
333 | 327 | blockIndex = None |
|
334 | 328 | |
|
335 | 329 | nTotalBlocks = None |
|
336 | 330 | |
|
337 | 331 | maxTimeStep = 30 |
|
338 | 332 | |
|
339 | 333 | lastUTTime = None |
|
340 | 334 | |
|
341 | 335 | datablock = None |
|
342 | 336 | |
|
343 | 337 | dataOut = None |
|
344 | 338 | |
|
345 | 339 | blocksize = None |
|
346 | 340 | |
|
347 | 341 | getByBlock = False |
|
348 | 342 | |
|
349 | 343 | def __init__(self): |
|
350 | 344 | |
|
351 | 345 | raise ValueError, "Not implemented" |
|
352 | 346 | |
|
353 | 347 | def run(self): |
|
354 | 348 | |
|
355 | 349 | raise ValueError, "Not implemented" |
|
356 | 350 | |
|
357 | 351 | class JRODataReader(JRODataIO): |
|
358 | 352 | |
|
359 | 353 | nReadBlocks = 0 |
|
360 | 354 | |
|
361 | 355 | delay = 10 #number of seconds waiting a new file |
|
362 | 356 | |
|
363 | 357 | nTries = 3 #quantity tries |
|
364 | 358 | |
|
365 | 359 | nFiles = 3 #number of files for searching |
|
366 | 360 | |
|
367 | 361 | path = None |
|
368 | 362 | |
|
369 | 363 | foldercounter = 0 |
|
370 | 364 | |
|
371 | 365 | flagNoMoreFiles = 0 |
|
372 | 366 | |
|
373 | 367 | datetimeList = [] |
|
374 | 368 | |
|
375 | 369 | __isFirstTimeOnline = 1 |
|
376 | 370 | |
|
377 | 371 | __printInfo = True |
|
378 | 372 | |
|
379 | 373 | profileIndex = None |
|
380 | 374 | |
|
381 | 375 | nTxs = 1 |
|
382 | 376 | |
|
383 | 377 | txIndex = None |
|
384 | 378 | |
|
385 | 379 | def __init__(self): |
|
386 | 380 | |
|
387 | 381 | """ |
|
388 | 382 | |
|
389 | 383 | """ |
|
390 | 384 | |
|
391 | 385 | raise ValueError, "This method has not been implemented" |
|
392 | 386 | |
|
393 | 387 | |
|
394 | 388 | def createObjByDefault(self): |
|
395 | 389 | """ |
|
396 | 390 | |
|
397 | 391 | """ |
|
398 | 392 | raise ValueError, "This method has not been implemented" |
|
399 | 393 | |
|
400 | 394 | def getBlockDimension(self): |
|
401 | 395 | |
|
402 | 396 | raise ValueError, "No implemented" |
|
403 | 397 | |
|
404 | 398 | def __searchFilesOffLine(self, |
|
405 | 399 | path, |
|
406 | 400 | startDate, |
|
407 | 401 | endDate, |
|
408 | 402 | startTime=datetime.time(0,0,0), |
|
409 | 403 | endTime=datetime.time(23,59,59), |
|
410 | 404 | set=None, |
|
411 | 405 | expLabel='', |
|
412 | 406 | ext='.r', |
|
413 | 407 | walk=True): |
|
414 | 408 | |
|
415 | 409 | pathList = [] |
|
416 | 410 | |
|
417 | 411 | if not walk: |
|
418 | 412 | #pathList.append(path) |
|
419 | 413 | multi_path = path.split(',') |
|
420 | 414 | for single_path in multi_path: |
|
421 | 415 | pathList.append(single_path) |
|
422 | 416 | |
|
423 | 417 | else: |
|
424 | 418 | #dirList = [] |
|
425 | 419 | multi_path = path.split(',') |
|
426 | 420 | for single_path in multi_path: |
|
427 | 421 | dirList = [] |
|
428 | 422 | for thisPath in os.listdir(single_path): |
|
429 | 423 | if not os.path.isdir(os.path.join(single_path,thisPath)): |
|
430 | 424 | continue |
|
431 | 425 | if not isDoyFolder(thisPath): |
|
432 | 426 | continue |
|
433 | 427 | |
|
434 | 428 | dirList.append(thisPath) |
|
435 | 429 | |
|
436 | 430 | if not(dirList): |
|
437 | 431 | return None, None |
|
438 | 432 | |
|
439 | 433 | thisDate = startDate |
|
440 | 434 | |
|
441 | 435 | while(thisDate <= endDate): |
|
442 | 436 | year = thisDate.timetuple().tm_year |
|
443 | 437 | doy = thisDate.timetuple().tm_yday |
|
444 | 438 | |
|
445 | 439 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
446 | 440 | if len(matchlist) == 0: |
|
447 | 441 | thisDate += datetime.timedelta(1) |
|
448 | 442 | continue |
|
449 | 443 | for match in matchlist: |
|
450 | 444 | pathList.append(os.path.join(single_path,match,expLabel)) |
|
451 | 445 | |
|
452 | 446 | thisDate += datetime.timedelta(1) |
|
453 | 447 | |
|
454 | 448 | if pathList == []: |
|
455 | 449 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
456 | 450 | return None, None |
|
457 | 451 | |
|
458 | 452 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
459 | 453 | |
|
460 | 454 | filenameList = [] |
|
461 | 455 | datetimeList = [] |
|
462 | 456 | pathDict = {} |
|
463 | 457 | filenameList_to_sort = [] |
|
464 | 458 | |
|
465 | 459 | for i in range(len(pathList)): |
|
466 | 460 | |
|
467 | 461 | thisPath = pathList[i] |
|
468 | 462 | |
|
469 | 463 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
470 | 464 | if len(fileList) < 1: |
|
471 | 465 | continue |
|
472 | ||
|
473 | 466 | fileList.sort() |
|
474 | 467 | pathDict.setdefault(fileList[0]) |
|
475 | 468 | pathDict[fileList[0]] = i |
|
476 | 469 | filenameList_to_sort.append(fileList[0]) |
|
477 | 470 | |
|
478 | 471 | filenameList_to_sort.sort() |
|
479 | 472 | |
|
480 | 473 | for file in filenameList_to_sort: |
|
481 | 474 | thisPath = pathList[pathDict[file]] |
|
482 | 475 | |
|
483 | 476 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
484 | 477 | fileList.sort() |
|
485 | 478 | |
|
486 | 479 | for file in fileList: |
|
487 | 480 | |
|
488 | 481 | filename = os.path.join(thisPath,file) |
|
489 | 482 | thisDatetime = isFileinThisTime(filename, startTime, endTime) |
|
490 | 483 | |
|
491 | 484 | if not(thisDatetime): |
|
492 | 485 | continue |
|
493 | 486 | |
|
494 | 487 | filenameList.append(filename) |
|
495 | 488 | datetimeList.append(thisDatetime) |
|
496 | 489 | |
|
497 | 490 | if not(filenameList): |
|
498 | 491 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
499 | 492 | return None, None |
|
500 | 493 | |
|
501 | 494 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
502 | 495 | |
|
503 | 496 | |
|
504 | 497 | for i in range(len(filenameList)): |
|
505 | 498 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
506 | 499 | |
|
507 | 500 | self.filenameList = filenameList |
|
508 | 501 | self.datetimeList = datetimeList |
|
509 | 502 | |
|
510 | 503 | return pathList, filenameList |
|
511 | 504 | |
|
512 | 505 | def __searchFilesOnLine(self, path, expLabel = "", ext = None, walk=True, set=None): |
|
513 | 506 | |
|
514 | 507 | """ |
|
515 | 508 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
516 | 509 | devuelve el archivo encontrado ademas de otros datos. |
|
517 | 510 | |
|
518 | 511 | Input: |
|
519 | 512 | path : carpeta donde estan contenidos los files que contiene data |
|
520 | 513 | |
|
521 | 514 | expLabel : Nombre del subexperimento (subfolder) |
|
522 | 515 | |
|
523 | 516 | ext : extension de los files |
|
524 | 517 | |
|
525 | 518 | walk : Si es habilitado no realiza busquedas dentro de los ubdirectorios (doypath) |
|
526 | 519 | |
|
527 | 520 | Return: |
|
528 | 521 | directory : eL directorio donde esta el file encontrado |
|
529 | 522 | filename : el ultimo file de una determinada carpeta |
|
530 | 523 | year : el anho |
|
531 | 524 | doy : el numero de dia del anho |
|
532 | 525 | set : el set del archivo |
|
533 | 526 | |
|
534 | 527 | |
|
535 | 528 | """ |
|
536 | 529 | dirList = [] |
|
537 | 530 | |
|
538 | 531 | if not walk: |
|
539 | 532 | fullpath = path |
|
540 | 533 | foldercounter = 0 |
|
541 | 534 | else: |
|
542 | 535 | #Filtra solo los directorios |
|
543 | 536 | for thisPath in os.listdir(path): |
|
544 | 537 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
545 | 538 | continue |
|
546 | 539 | if not isDoyFolder(thisPath): |
|
547 | 540 | continue |
|
548 | 541 | |
|
549 | 542 | dirList.append(thisPath) |
|
550 | 543 | |
|
551 | 544 | if not(dirList): |
|
552 | 545 | return None, None, None, None, None, None |
|
553 | 546 | |
|
554 | 547 | dirList = sorted( dirList, key=str.lower ) |
|
555 | 548 | |
|
556 | 549 | doypath = dirList[-1] |
|
557 | 550 | foldercounter = int(doypath.split('_')[1]) if len(doypath.split('_'))>1 else 0 |
|
558 | 551 | fullpath = os.path.join(path, doypath, expLabel) |
|
559 | 552 | |
|
560 | 553 | |
|
561 | 554 | print "%s folder was found: " %(fullpath ) |
|
562 | 555 | |
|
563 | 556 | if set == None: |
|
564 | 557 | filename = getlastFileFromPath(fullpath, ext) |
|
565 | 558 | else: |
|
566 | 559 | filename = getFileFromSet(fullpath, ext, set) |
|
567 | 560 | |
|
568 | 561 | if not(filename): |
|
569 | 562 | return None, None, None, None, None, None |
|
570 | 563 | |
|
571 | 564 | print "%s file was found" %(filename) |
|
572 | 565 | |
|
573 | 566 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
574 | 567 | return None, None, None, None, None, None |
|
575 | 568 | |
|
576 | 569 | year = int( filename[1:5] ) |
|
577 | 570 | doy = int( filename[5:8] ) |
|
578 | 571 | set = int( filename[8:11] ) |
|
579 | 572 | |
|
580 | 573 | return fullpath, foldercounter, filename, year, doy, set |
|
581 | 574 | |
|
582 | 575 | def __setNextFileOffline(self): |
|
583 | 576 | |
|
584 | 577 | idFile = self.fileIndex |
|
585 | 578 | |
|
586 | 579 | while (True): |
|
587 | 580 | idFile += 1 |
|
588 | 581 | if not(idFile < len(self.filenameList)): |
|
589 | 582 | self.flagNoMoreFiles = 1 |
|
590 | 583 | print "No more Files" |
|
591 | 584 | return 0 |
|
592 | 585 | |
|
593 | 586 | filename = self.filenameList[idFile] |
|
594 | 587 | |
|
595 | 588 | if not(self.__verifyFile(filename)): |
|
596 | 589 | continue |
|
597 | 590 | |
|
598 | 591 | fileSize = os.path.getsize(filename) |
|
599 | 592 | fp = open(filename,'rb') |
|
600 | 593 | break |
|
601 | 594 | |
|
602 | 595 | self.flagIsNewFile = 1 |
|
603 | 596 | self.fileIndex = idFile |
|
604 | 597 | self.filename = filename |
|
605 | 598 | self.fileSize = fileSize |
|
606 | 599 | self.fp = fp |
|
607 | 600 | |
|
608 | 601 | print "Setting the file: %s"%self.filename |
|
609 | 602 | |
|
610 | 603 | return 1 |
|
611 | 604 | |
|
612 | 605 | def __setNextFileOnline(self): |
|
613 | 606 | """ |
|
614 | 607 | Busca el siguiente file que tenga suficiente data para ser leida, dentro de un folder especifico, si |
|
615 | 608 | no encuentra un file valido espera un tiempo determinado y luego busca en los posibles n files |
|
616 | 609 | siguientes. |
|
617 | 610 | |
|
618 | 611 | Affected: |
|
619 | 612 | self.flagIsNewFile |
|
620 | 613 | self.filename |
|
621 | 614 | self.fileSize |
|
622 | 615 | self.fp |
|
623 | 616 | self.set |
|
624 | 617 | self.flagNoMoreFiles |
|
625 | 618 | |
|
626 | 619 | Return: |
|
627 | 620 | 0 : si luego de una busqueda del siguiente file valido este no pudo ser encontrado |
|
628 | 621 | 1 : si el file fue abierto con exito y esta listo a ser leido |
|
629 | 622 | |
|
630 | 623 | Excepciones: |
|
631 | 624 | Si un determinado file no puede ser abierto |
|
632 | 625 | """ |
|
633 | 626 | nFiles = 0 |
|
634 | 627 | fileOk_flag = False |
|
635 | 628 | firstTime_flag = True |
|
636 | 629 | |
|
637 | 630 | self.set += 1 |
|
638 | 631 | |
|
639 | 632 | if self.set > 999: |
|
640 | 633 | self.set = 0 |
|
641 | 634 | self.foldercounter += 1 |
|
642 | 635 | |
|
643 | 636 | #busca el 1er file disponible |
|
644 | 637 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
645 | 638 | if fullfilename: |
|
646 | 639 | if self.__verifyFile(fullfilename, False): |
|
647 | 640 | fileOk_flag = True |
|
648 | 641 | |
|
649 | 642 | #si no encuentra un file entonces espera y vuelve a buscar |
|
650 | 643 | if not(fileOk_flag): |
|
651 | 644 | for nFiles in range(self.nFiles+1): #busco en los siguientes self.nFiles+1 files posibles |
|
652 | 645 | |
|
653 | 646 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces |
|
654 | 647 | tries = self.nTries |
|
655 | 648 | else: |
|
656 | 649 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez |
|
657 | 650 | |
|
658 | 651 | for nTries in range( tries ): |
|
659 | 652 | if firstTime_flag: |
|
660 | 653 | print "\tWaiting %0.2f sec for the file \"%s\" , try %03d ..." % ( self.delay, filename, nTries+1 ) |
|
661 |
|
|
|
654 | sleep( self.delay ) | |
|
662 | 655 | else: |
|
663 | 656 | print "\tSearching next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
664 | 657 | |
|
665 | 658 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) |
|
666 | 659 | if fullfilename: |
|
667 | 660 | if self.__verifyFile(fullfilename): |
|
668 | 661 | fileOk_flag = True |
|
669 | 662 | break |
|
670 | 663 | |
|
671 | 664 | if fileOk_flag: |
|
672 | 665 | break |
|
673 | 666 | |
|
674 | 667 | firstTime_flag = False |
|
675 | 668 | |
|
676 | 669 | print "\tSkipping the file \"%s\" due to this file doesn't exist" % filename |
|
677 | 670 | self.set += 1 |
|
678 | 671 | |
|
679 | 672 | if nFiles == (self.nFiles-1): #si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta |
|
680 | 673 | self.set = 0 |
|
681 | 674 | self.doy += 1 |
|
682 | 675 | self.foldercounter = 0 |
|
683 | 676 | |
|
684 | 677 | if fileOk_flag: |
|
685 | 678 | self.fileSize = os.path.getsize( fullfilename ) |
|
686 | 679 | self.filename = fullfilename |
|
687 | 680 | self.flagIsNewFile = 1 |
|
688 | 681 | if self.fp != None: self.fp.close() |
|
689 | 682 | self.fp = open(fullfilename, 'rb') |
|
690 | 683 | self.flagNoMoreFiles = 0 |
|
691 | 684 | print 'Setting the file: %s' % fullfilename |
|
692 | 685 | else: |
|
693 | 686 | self.fileSize = 0 |
|
694 | 687 | self.filename = None |
|
695 | 688 | self.flagIsNewFile = 0 |
|
696 | 689 | self.fp = None |
|
697 | 690 | self.flagNoMoreFiles = 1 |
|
698 | 691 | print 'No more Files' |
|
699 | 692 | |
|
700 | 693 | return fileOk_flag |
|
701 | 694 | |
|
702 | 695 | def setNextFile(self): |
|
703 | 696 | if self.fp != None: |
|
704 | 697 | self.fp.close() |
|
705 | 698 | |
|
706 | 699 | if self.online: |
|
707 | 700 | newFile = self.__setNextFileOnline() |
|
708 | 701 | else: |
|
709 | 702 | newFile = self.__setNextFileOffline() |
|
710 | 703 | |
|
711 | 704 | if not(newFile): |
|
712 | 705 | return 0 |
|
713 | 706 | |
|
714 | 707 | self.__readFirstHeader() |
|
715 | 708 | self.nReadBlocks = 0 |
|
716 | 709 | return 1 |
|
717 | 710 | |
|
718 | 711 | def __waitNewBlock(self): |
|
719 | 712 | """ |
|
720 | 713 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
721 | 714 | |
|
722 | 715 | Si el modo de lectura es OffLine siempre retorn 0 |
|
723 | 716 | """ |
|
724 | 717 | if not self.online: |
|
725 | 718 | return 0 |
|
726 | 719 | |
|
727 | 720 | if (self.nReadBlocks >= self.processingHeaderObj.dataBlocksPerFile): |
|
728 | 721 | return 0 |
|
729 | 722 | |
|
730 | 723 | currentPointer = self.fp.tell() |
|
731 | 724 | |
|
732 | 725 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
733 | 726 | |
|
734 | 727 | for nTries in range( self.nTries ): |
|
735 | 728 | |
|
736 | 729 | self.fp.close() |
|
737 | 730 | self.fp = open( self.filename, 'rb' ) |
|
738 | 731 | self.fp.seek( currentPointer ) |
|
739 | 732 | |
|
740 | 733 | self.fileSize = os.path.getsize( self.filename ) |
|
741 | 734 | currentSize = self.fileSize - currentPointer |
|
742 | 735 | |
|
743 | 736 | if ( currentSize >= neededSize ): |
|
744 | 737 | self.basicHeaderObj.read(self.fp) |
|
745 | 738 | return 1 |
|
746 | 739 | |
|
747 | 740 | if self.fileSize == self.fileSizeByHeader: |
|
748 | 741 | # self.flagEoF = True |
|
749 | 742 | return 0 |
|
750 | 743 | |
|
751 |
print " |
|
|
752 |
|
|
|
744 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
|
745 | sleep( self.delay ) | |
|
753 | 746 | |
|
754 | 747 | |
|
755 | 748 | return 0 |
|
756 | 749 | |
|
757 | 750 | def waitDataBlock(self,pointer_location): |
|
758 | 751 | |
|
759 | 752 | currentPointer = pointer_location |
|
760 | 753 | |
|
761 | 754 | neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize |
|
762 | 755 | |
|
763 | 756 | for nTries in range( self.nTries ): |
|
764 | 757 | self.fp.close() |
|
765 | 758 | self.fp = open( self.filename, 'rb' ) |
|
766 | 759 | self.fp.seek( currentPointer ) |
|
767 | 760 | |
|
768 | 761 | self.fileSize = os.path.getsize( self.filename ) |
|
769 | 762 | currentSize = self.fileSize - currentPointer |
|
770 | 763 | |
|
771 | 764 | if ( currentSize >= neededSize ): |
|
772 | 765 | return 1 |
|
773 | 766 | |
|
774 |
print " |
|
|
775 |
|
|
|
767 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
|
768 | sleep( self.delay ) | |
|
776 | 769 | |
|
777 | 770 | return 0 |
|
778 | 771 | |
|
779 | 772 | def __jumpToLastBlock(self): |
|
780 | 773 | |
|
781 | 774 | if not(self.__isFirstTimeOnline): |
|
782 | 775 | return |
|
783 | 776 | |
|
784 | 777 | csize = self.fileSize - self.fp.tell() |
|
785 | 778 | blocksize = self.processingHeaderObj.blockSize |
|
786 | 779 | |
|
787 | 780 | #salta el primer bloque de datos |
|
788 | 781 | if csize > self.processingHeaderObj.blockSize: |
|
789 | 782 | self.fp.seek(self.fp.tell() + blocksize) |
|
790 | 783 | else: |
|
791 | 784 | return |
|
792 | 785 | |
|
793 | 786 | csize = self.fileSize - self.fp.tell() |
|
794 | 787 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
795 | 788 | while True: |
|
796 | 789 | |
|
797 | 790 | if self.fp.tell()<self.fileSize: |
|
798 | 791 | self.fp.seek(self.fp.tell() + neededsize) |
|
799 | 792 | else: |
|
800 | 793 | self.fp.seek(self.fp.tell() - neededsize) |
|
801 | 794 | break |
|
802 | 795 | |
|
803 | 796 | # csize = self.fileSize - self.fp.tell() |
|
804 | 797 | # neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
805 | 798 | # factor = int(csize/neededsize) |
|
806 | 799 | # if factor > 0: |
|
807 | 800 | # self.fp.seek(self.fp.tell() + factor*neededsize) |
|
808 | 801 | |
|
809 | 802 | self.flagIsNewFile = 0 |
|
810 | 803 | self.__isFirstTimeOnline = 0 |
|
811 | 804 | |
|
812 | 805 | def __setNewBlock(self): |
|
813 | 806 | |
|
814 | 807 | if self.fp == None: |
|
815 | 808 | return 0 |
|
816 | 809 | |
|
817 | 810 | if self.online: |
|
818 | 811 | self.__jumpToLastBlock() |
|
819 | 812 | |
|
820 | 813 | if self.flagIsNewFile: |
|
821 | 814 | return 1 |
|
822 | 815 | |
|
823 | 816 | self.lastUTTime = self.basicHeaderObj.utc |
|
824 | 817 | currentSize = self.fileSize - self.fp.tell() |
|
825 | 818 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
826 | 819 | |
|
827 | 820 | if (currentSize >= neededSize): |
|
828 | 821 | self.basicHeaderObj.read(self.fp) |
|
829 | 822 | return 1 |
|
830 | 823 | |
|
831 | 824 | if self.__waitNewBlock(): |
|
832 | 825 | return 1 |
|
833 | 826 | |
|
834 | 827 | if not(self.setNextFile()): |
|
835 | 828 | return 0 |
|
836 | 829 | |
|
837 | 830 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime # |
|
838 | 831 | |
|
839 |
self.flag |
|
|
832 | self.flagDiscontinuousBlock = 0 | |
|
840 | 833 | |
|
841 | 834 | if deltaTime > self.maxTimeStep: |
|
842 |
self.flag |
|
|
835 | self.flagDiscontinuousBlock = 1 | |
|
843 | 836 | |
|
844 | 837 | return 1 |
|
845 | 838 | |
|
846 | 839 | def readNextBlock(self): |
|
847 | 840 | if not(self.__setNewBlock()): |
|
848 | 841 | return 0 |
|
849 | 842 | |
|
850 | 843 | if not(self.readBlock()): |
|
851 | 844 | return 0 |
|
852 | 845 | |
|
853 | 846 | return 1 |
|
854 | 847 | |
|
855 | 848 | def __readFirstHeader(self): |
|
856 | 849 | |
|
857 | 850 | self.basicHeaderObj.read(self.fp) |
|
858 | 851 | self.systemHeaderObj.read(self.fp) |
|
859 | 852 | self.radarControllerHeaderObj.read(self.fp) |
|
860 | 853 | self.processingHeaderObj.read(self.fp) |
|
861 | 854 | |
|
862 | 855 | self.firstHeaderSize = self.basicHeaderObj.size |
|
863 | 856 | |
|
864 | 857 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
865 | 858 | if datatype == 0: |
|
866 | 859 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
867 | 860 | elif datatype == 1: |
|
868 | 861 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
869 | 862 | elif datatype == 2: |
|
870 | 863 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
871 | 864 | elif datatype == 3: |
|
872 | 865 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
873 | 866 | elif datatype == 4: |
|
874 | 867 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
875 | 868 | elif datatype == 5: |
|
876 | 869 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
877 | 870 | else: |
|
878 | 871 | raise ValueError, 'Data type was not defined' |
|
879 | 872 | |
|
880 | 873 | self.dtype = datatype_str |
|
881 | 874 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
882 | 875 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + self.firstHeaderSize + self.basicHeaderSize*(self.processingHeaderObj.dataBlocksPerFile - 1) |
|
883 | 876 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
884 | 877 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
885 | 878 | self.getBlockDimension() |
|
886 | 879 | |
|
887 | 880 | def __verifyFile(self, filename, msgFlag=True): |
|
888 | 881 | msg = None |
|
889 | 882 | try: |
|
890 | 883 | fp = open(filename, 'rb') |
|
891 | 884 | currentPosition = fp.tell() |
|
892 | 885 | except IOError: |
|
893 | 886 | traceback.print_exc() |
|
894 | 887 | if msgFlag: |
|
895 | print "The file %s can't be opened" % (filename) | |
|
888 | print "[Reading] The file %s can't be opened" % (filename) | |
|
896 | 889 | return False |
|
897 | 890 | |
|
898 | 891 | neededSize = self.processingHeaderObj.blockSize + self.firstHeaderSize |
|
899 | 892 | |
|
900 | 893 | if neededSize == 0: |
|
901 | 894 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
902 | 895 | systemHeaderObj = SystemHeader() |
|
903 | 896 | radarControllerHeaderObj = RadarControllerHeader() |
|
904 | 897 | processingHeaderObj = ProcessingHeader() |
|
905 | 898 | |
|
906 | 899 | try: |
|
907 | 900 | if not( basicHeaderObj.read(fp) ): raise IOError |
|
908 | 901 | if not( systemHeaderObj.read(fp) ): raise IOError |
|
909 | 902 | if not( radarControllerHeaderObj.read(fp) ): raise IOError |
|
910 | 903 | if not( processingHeaderObj.read(fp) ): raise IOError |
|
911 | 904 | # data_type = int(numpy.log2((processingHeaderObj.processFlags & PROCFLAG.DATATYPE_MASK))-numpy.log2(PROCFLAG.DATATYPE_CHAR)) |
|
912 | 905 | |
|
913 | 906 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
914 | 907 | |
|
915 | 908 | except IOError: |
|
916 | 909 | traceback.print_exc() |
|
917 | 910 | if msgFlag: |
|
918 |
print " |
|
|
911 | print "[Reading] The file %s is empty or it hasn't enough data" % filename | |
|
919 | 912 | |
|
920 | 913 | fp.close() |
|
921 | 914 | return False |
|
922 | 915 | else: |
|
923 |
msg = " |
|
|
916 | msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename | |
|
924 | 917 | |
|
925 | 918 | fp.close() |
|
926 | 919 | fileSize = os.path.getsize(filename) |
|
927 | 920 | currentSize = fileSize - currentPosition |
|
928 | 921 | if currentSize < neededSize: |
|
929 | 922 | if msgFlag and (msg != None): |
|
930 | 923 | print msg #print"\tSkipping the file %s due to it hasn't enough data" %filename |
|
931 | 924 | return False |
|
932 | 925 | |
|
933 | 926 | return True |
|
934 | 927 | |
|
935 | 928 | def setup(self, |
|
936 | 929 | path=None, |
|
937 | 930 | startDate=None, |
|
938 | 931 | endDate=None, |
|
939 | 932 | startTime=datetime.time(0,0,0), |
|
940 | 933 | endTime=datetime.time(23,59,59), |
|
941 | 934 | set=None, |
|
942 | 935 | expLabel = "", |
|
943 | 936 | ext = None, |
|
944 | 937 | online = False, |
|
945 | 938 | delay = 60, |
|
946 | 939 | walk = True, |
|
947 | 940 | getblock = False, |
|
948 | 941 | nTxs = 1): |
|
949 | 942 | |
|
950 | 943 | if path == None: |
|
951 | raise ValueError, "The path is not valid" | |
|
944 | raise ValueError, "[Reading] The path is not valid" | |
|
952 | 945 | |
|
953 | 946 | if ext == None: |
|
954 | 947 | ext = self.ext |
|
955 | 948 | |
|
956 | 949 | if online: |
|
957 | print "Searching files in online mode..." | |
|
950 | print "[Reading] Searching files in online mode..." | |
|
958 | 951 | |
|
959 | 952 | for nTries in range( self.nTries ): |
|
960 | 953 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine(path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) |
|
961 | 954 | |
|
962 | 955 | if fullpath: |
|
963 | 956 | break |
|
964 | 957 | |
|
965 |
print ' |
|
|
966 |
|
|
|
958 | print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
|
959 | sleep( self.delay ) | |
|
967 | 960 | |
|
968 | 961 | if not(fullpath): |
|
969 |
print "There 'isn't vali |
|
|
962 | print "There 'isn't any valid file in %s" % path | |
|
970 | 963 | return None |
|
971 | 964 | |
|
972 | 965 | self.year = year |
|
973 | 966 | self.doy = doy |
|
974 | 967 | self.set = set - 1 |
|
975 | 968 | self.path = path |
|
976 | 969 | self.foldercounter = foldercounter |
|
977 | 970 | last_set = None |
|
978 | 971 | |
|
979 | 972 | else: |
|
980 | print "Searching files in offline mode ..." | |
|
973 | print "[Reading] Searching files in offline mode ..." | |
|
981 | 974 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
982 | 975 | startTime=startTime, endTime=endTime, |
|
983 | 976 | set=set, expLabel=expLabel, ext=ext, |
|
984 | 977 | walk=walk) |
|
985 | 978 | |
|
986 | 979 | if not(pathList): |
|
987 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
|
980 | print "[Reading] No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, | |
|
988 | 981 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
989 | 982 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
990 | 983 | |
|
991 | 984 | sys.exit(-1) |
|
992 | 985 | |
|
993 | 986 | |
|
994 | 987 | self.fileIndex = -1 |
|
995 | 988 | self.pathList = pathList |
|
996 | 989 | self.filenameList = filenameList |
|
997 | 990 | file_name = os.path.basename(filenameList[-1]) |
|
998 | 991 | basename, ext = os.path.splitext(file_name) |
|
999 | 992 | last_set = int(basename[-3:]) |
|
1000 | 993 | |
|
1001 | 994 | self.online = online |
|
1002 | 995 | self.delay = delay |
|
1003 | 996 | ext = ext.lower() |
|
1004 | 997 | self.ext = ext |
|
1005 | 998 | self.getByBlock = getblock |
|
1006 | 999 | self.nTxs = int(nTxs) |
|
1007 | 1000 | |
|
1008 | 1001 | if not(self.setNextFile()): |
|
1009 | 1002 | if (startDate!=None) and (endDate!=None): |
|
1010 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
|
1003 | print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
|
1011 | 1004 | elif startDate != None: |
|
1012 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
|
1005 | print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
|
1013 | 1006 | else: |
|
1014 | print "No files" | |
|
1007 | print "[Reading] No files" | |
|
1015 | 1008 | |
|
1016 | 1009 | sys.exit(-1) |
|
1017 | 1010 | |
|
1018 | 1011 | # self.updateDataHeader() |
|
1019 | 1012 | if last_set != None: |
|
1020 | 1013 | self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock |
|
1021 | 1014 | return |
|
1022 | 1015 | |
|
1023 | 1016 | def getBasicHeader(self): |
|
1024 | 1017 | |
|
1025 | 1018 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds |
|
1026 | 1019 | |
|
1027 |
self.dataOut.flag |
|
|
1020 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock | |
|
1028 | 1021 | |
|
1029 | 1022 | self.dataOut.timeZone = self.basicHeaderObj.timeZone |
|
1030 | 1023 | |
|
1031 | 1024 | self.dataOut.dstFlag = self.basicHeaderObj.dstFlag |
|
1032 | 1025 | |
|
1033 | 1026 | self.dataOut.errorCount = self.basicHeaderObj.errorCount |
|
1034 | 1027 | |
|
1035 | 1028 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime |
|
1036 | 1029 | |
|
1037 | 1030 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
1038 | 1031 | |
|
1039 | 1032 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
1040 | 1033 | |
|
1041 | 1034 | |
|
1042 | 1035 | def getFirstHeader(self): |
|
1043 | 1036 | |
|
1044 | 1037 | raise ValueError, "This method has not been implemented" |
|
1045 | 1038 | |
|
1046 | 1039 | def getData(self): |
|
1047 | 1040 | |
|
1048 | 1041 | raise ValueError, "This method has not been implemented" |
|
1049 | 1042 | |
|
1050 | 1043 | def hasNotDataInBuffer(self): |
|
1051 | 1044 | |
|
1052 | 1045 | raise ValueError, "This method has not been implemented" |
|
1053 | 1046 | |
|
1054 | 1047 | def readBlock(self): |
|
1055 | 1048 | |
|
1056 | 1049 | raise ValueError, "This method has not been implemented" |
|
1057 | 1050 | |
|
1058 | 1051 | def isEndProcess(self): |
|
1059 | 1052 | |
|
1060 | 1053 | return self.flagNoMoreFiles |
|
1061 | 1054 | |
|
1062 | 1055 | def printReadBlocks(self): |
|
1063 | 1056 | |
|
1064 | print "Number of read blocks per file %04d" %self.nReadBlocks | |
|
1057 | print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks | |
|
1065 | 1058 | |
|
1066 | 1059 | def printTotalBlocks(self): |
|
1067 | 1060 | |
|
1068 | print "Number of read blocks %04d" %self.nTotalBlocks | |
|
1061 | print "[Reading] Number of read blocks %04d" %self.nTotalBlocks | |
|
1069 | 1062 | |
|
1070 | 1063 | def printNumberOfBlock(self): |
|
1071 | 1064 | |
|
1072 | 1065 | if self.flagIsNewBlock: |
|
1073 | print "Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) | |
|
1066 | print "[Reading] Block No. %04d, Total blocks %04d -> %s" %(self.basicHeaderObj.dataBlock, self.nTotalBlocks, self.dataOut.datatime.ctime()) | |
|
1074 | 1067 | self.dataOut.blocknow = self.basicHeaderObj.dataBlock |
|
1075 | 1068 | |
|
1076 | 1069 | def printInfo(self): |
|
1077 | 1070 | |
|
1078 | 1071 | if self.__printInfo == False: |
|
1079 | 1072 | return |
|
1080 | 1073 | |
|
1081 | 1074 | self.basicHeaderObj.printInfo() |
|
1082 | 1075 | self.systemHeaderObj.printInfo() |
|
1083 | 1076 | self.radarControllerHeaderObj.printInfo() |
|
1084 | 1077 | self.processingHeaderObj.printInfo() |
|
1085 | 1078 | |
|
1086 | 1079 | self.__printInfo = False |
|
1087 | 1080 | |
|
1088 | 1081 | |
|
1089 | 1082 | def run(self, **kwargs): |
|
1090 | 1083 | |
|
1091 | 1084 | if not(self.isConfig): |
|
1092 | 1085 | |
|
1093 | 1086 | # self.dataOut = dataOut |
|
1094 | 1087 | self.setup(**kwargs) |
|
1095 | 1088 | self.isConfig = True |
|
1096 | 1089 | |
|
1097 | 1090 | self.getData() |
|
1098 | 1091 | |
|
1099 | 1092 | class JRODataWriter(JRODataIO): |
|
1100 | 1093 | |
|
1101 | 1094 | """ |
|
1102 | 1095 | Esta clase permite escribir datos a archivos procesados (.r o ,pdata). La escritura |
|
1103 | 1096 | de los datos siempre se realiza por bloques. |
|
1104 | 1097 | """ |
|
1105 | 1098 | |
|
1106 | 1099 | blockIndex = 0 |
|
1107 | 1100 | |
|
1108 | 1101 | path = None |
|
1109 | 1102 | |
|
1110 | 1103 | setFile = None |
|
1111 | 1104 | |
|
1112 | 1105 | profilesPerBlock = None |
|
1113 | 1106 | |
|
1114 | 1107 | blocksPerFile = None |
|
1115 | 1108 | |
|
1116 | 1109 | nWriteBlocks = 0 |
|
1117 | 1110 | |
|
1118 | 1111 | def __init__(self, dataOut=None): |
|
1119 | 1112 | raise ValueError, "Not implemented" |
|
1120 | 1113 | |
|
1121 | 1114 | |
|
1122 | 1115 | def hasAllDataInBuffer(self): |
|
1123 | 1116 | raise ValueError, "Not implemented" |
|
1124 | 1117 | |
|
1125 | 1118 | |
|
1126 | 1119 | def setBlockDimension(self): |
|
1127 | 1120 | raise ValueError, "Not implemented" |
|
1128 | 1121 | |
|
1129 | 1122 | |
|
1130 | 1123 | def writeBlock(self): |
|
1131 | 1124 | raise ValueError, "No implemented" |
|
1132 | 1125 | |
|
1133 | 1126 | |
|
1134 | 1127 | def putData(self): |
|
1135 | 1128 | raise ValueError, "No implemented" |
|
1136 | 1129 | |
|
1137 | 1130 | |
|
1138 | 1131 | def setBasicHeader(self): |
|
1139 | 1132 | |
|
1140 | 1133 | self.basicHeaderObj.size = self.basicHeaderSize #bytes |
|
1141 | 1134 | self.basicHeaderObj.version = self.versionFile |
|
1142 | 1135 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
1143 | 1136 | |
|
1144 | 1137 | utc = numpy.floor(self.dataOut.utctime) |
|
1145 | 1138 | milisecond = (self.dataOut.utctime - utc)* 1000.0 |
|
1146 | 1139 | |
|
1147 | 1140 | self.basicHeaderObj.utc = utc |
|
1148 | 1141 | self.basicHeaderObj.miliSecond = milisecond |
|
1149 | 1142 | self.basicHeaderObj.timeZone = self.dataOut.timeZone |
|
1150 | 1143 | self.basicHeaderObj.dstFlag = self.dataOut.dstFlag |
|
1151 | 1144 | self.basicHeaderObj.errorCount = self.dataOut.errorCount |
|
1152 | 1145 | |
|
1153 | 1146 | def setFirstHeader(self): |
|
1154 | 1147 | """ |
|
1155 | 1148 | Obtiene una copia del First Header |
|
1156 | 1149 | |
|
1157 | 1150 | Affected: |
|
1158 | 1151 | |
|
1159 | 1152 | self.basicHeaderObj |
|
1160 | 1153 | self.systemHeaderObj |
|
1161 | 1154 | self.radarControllerHeaderObj |
|
1162 | 1155 | self.processingHeaderObj self. |
|
1163 | 1156 | |
|
1164 | 1157 | Return: |
|
1165 | 1158 | None |
|
1166 | 1159 | """ |
|
1167 | 1160 | |
|
1168 | 1161 | raise ValueError, "No implemented" |
|
1169 | 1162 | |
|
1170 | 1163 | def __writeFirstHeader(self): |
|
1171 | 1164 | """ |
|
1172 | 1165 | Escribe el primer header del file es decir el Basic header y el Long header (SystemHeader, RadarControllerHeader, ProcessingHeader) |
|
1173 | 1166 | |
|
1174 | 1167 | Affected: |
|
1175 | 1168 | __dataType |
|
1176 | 1169 | |
|
1177 | 1170 | Return: |
|
1178 | 1171 | None |
|
1179 | 1172 | """ |
|
1180 | 1173 | |
|
1181 | 1174 | # CALCULAR PARAMETROS |
|
1182 | 1175 | |
|
1183 | 1176 | sizeLongHeader = self.systemHeaderObj.size + self.radarControllerHeaderObj.size + self.processingHeaderObj.size |
|
1184 | 1177 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
1185 | 1178 | |
|
1186 | 1179 | self.basicHeaderObj.write(self.fp) |
|
1187 | 1180 | self.systemHeaderObj.write(self.fp) |
|
1188 | 1181 | self.radarControllerHeaderObj.write(self.fp) |
|
1189 | 1182 | self.processingHeaderObj.write(self.fp) |
|
1190 | 1183 | |
|
1191 | 1184 | self.dtype = self.dataOut.dtype |
|
1192 | 1185 | |
|
1193 | 1186 | def __setNewBlock(self): |
|
1194 | 1187 | """ |
|
1195 | 1188 | Si es un nuevo file escribe el First Header caso contrario escribe solo el Basic Header |
|
1196 | 1189 | |
|
1197 | 1190 | Return: |
|
1198 | 1191 | 0 : si no pudo escribir nada |
|
1199 | 1192 | 1 : Si escribio el Basic el First Header |
|
1200 | 1193 | """ |
|
1201 | 1194 | if self.fp == None: |
|
1202 | 1195 | self.setNextFile() |
|
1203 | 1196 | |
|
1204 | 1197 | if self.flagIsNewFile: |
|
1205 | 1198 | return 1 |
|
1206 | 1199 | |
|
1207 | 1200 | if self.blockIndex < self.processingHeaderObj.dataBlocksPerFile: |
|
1208 | 1201 | self.basicHeaderObj.write(self.fp) |
|
1209 | 1202 | return 1 |
|
1210 | 1203 | |
|
1211 | 1204 | if not( self.setNextFile() ): |
|
1212 | 1205 | return 0 |
|
1213 | 1206 | |
|
1214 | 1207 | return 1 |
|
1215 | 1208 | |
|
1216 | 1209 | |
|
1217 | 1210 | def writeNextBlock(self): |
|
1218 | 1211 | """ |
|
1219 | 1212 | Selecciona el bloque siguiente de datos y los escribe en un file |
|
1220 | 1213 | |
|
1221 | 1214 | Return: |
|
1222 | 1215 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1223 | 1216 | 1 : Si no pudo escribir el bloque de datos |
|
1224 | 1217 | """ |
|
1225 | 1218 | if not( self.__setNewBlock() ): |
|
1226 | 1219 | return 0 |
|
1227 | 1220 | |
|
1228 | 1221 | self.writeBlock() |
|
1229 | 1222 | |
|
1230 | 1223 | return 1 |
|
1231 | 1224 | |
|
1232 | 1225 | def setNextFile(self): |
|
1233 | 1226 | """ |
|
1234 | 1227 | Determina el siguiente file que sera escrito |
|
1235 | 1228 | |
|
1236 | 1229 | Affected: |
|
1237 | 1230 | self.filename |
|
1238 | 1231 | self.subfolder |
|
1239 | 1232 | self.fp |
|
1240 | 1233 | self.setFile |
|
1241 | 1234 | self.flagIsNewFile |
|
1242 | 1235 | |
|
1243 | 1236 | Return: |
|
1244 | 1237 | 0 : Si el archivo no puede ser escrito |
|
1245 | 1238 | 1 : Si el archivo esta listo para ser escrito |
|
1246 | 1239 | """ |
|
1247 | 1240 | ext = self.ext |
|
1248 | 1241 | path = self.path |
|
1249 | 1242 | |
|
1250 | 1243 | if self.fp != None: |
|
1251 | 1244 | self.fp.close() |
|
1252 | 1245 | |
|
1253 | 1246 | timeTuple = time.localtime( self.dataOut.utctime) |
|
1254 | 1247 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
1255 | 1248 | |
|
1256 | 1249 | fullpath = os.path.join( path, subfolder ) |
|
1257 | 1250 | if not( os.path.exists(fullpath) ): |
|
1258 | 1251 | os.mkdir(fullpath) |
|
1259 | 1252 | self.setFile = -1 #inicializo mi contador de seteo |
|
1260 | 1253 | else: |
|
1261 | 1254 | filesList = os.listdir( fullpath ) |
|
1262 | 1255 | if len( filesList ) > 0: |
|
1263 | 1256 | filesList = sorted( filesList, key=str.lower ) |
|
1264 | 1257 | filen = filesList[-1] |
|
1265 | 1258 | # el filename debera tener el siguiente formato |
|
1266 | 1259 | # 0 1234 567 89A BCDE (hex) |
|
1267 | 1260 | # x YYYY DDD SSS .ext |
|
1268 | 1261 | if isNumber( filen[8:11] ): |
|
1269 | 1262 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
1270 | 1263 | else: |
|
1271 | 1264 | self.setFile = -1 |
|
1272 | 1265 | else: |
|
1273 | 1266 | self.setFile = -1 #inicializo mi contador de seteo |
|
1274 | 1267 | |
|
1275 | 1268 | setFile = self.setFile |
|
1276 | 1269 | setFile += 1 |
|
1277 | 1270 | |
|
1278 | file = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
|
1271 | filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
|
1279 | 1272 | timeTuple.tm_year, |
|
1280 | 1273 | timeTuple.tm_yday, |
|
1281 | 1274 | setFile, |
|
1282 | 1275 | ext ) |
|
1283 | 1276 | |
|
1284 | filename = os.path.join( path, subfolder, file ) | |
|
1277 | filename = os.path.join( path, subfolder, filen ) | |
|
1285 | 1278 | |
|
1286 | 1279 | fp = open( filename,'wb' ) |
|
1287 | 1280 | |
|
1288 | 1281 | self.blockIndex = 0 |
|
1289 | 1282 | |
|
1290 | 1283 | #guardando atributos |
|
1291 | 1284 | self.filename = filename |
|
1292 | 1285 | self.subfolder = subfolder |
|
1293 | 1286 | self.fp = fp |
|
1294 | 1287 | self.setFile = setFile |
|
1295 | 1288 | self.flagIsNewFile = 1 |
|
1296 | 1289 | |
|
1297 | 1290 | self.setFirstHeader() |
|
1298 | 1291 | |
|
1299 |
print 'Writing |
|
|
1292 | print '[Writing] file: %s'%self.filename | |
|
1300 | 1293 | |
|
1301 | 1294 | self.__writeFirstHeader() |
|
1302 | 1295 | |
|
1303 | 1296 | return 1 |
|
1304 | 1297 | |
|
1305 | 1298 | def setup(self, dataOut, path, blocksPerFile, profilesPerBlock=64, set=0, ext=None): |
|
1306 | 1299 | """ |
|
1307 | 1300 | Setea el tipo de formato en la cual sera guardada la data y escribe el First Header |
|
1308 | 1301 | |
|
1309 | 1302 | Inputs: |
|
1310 | 1303 | path : el path destino en el cual se escribiran los files a crear |
|
1311 | 1304 | format : formato en el cual sera salvado un file |
|
1312 | 1305 | set : el setebo del file |
|
1313 | 1306 | |
|
1314 | 1307 | Return: |
|
1315 | 1308 | 0 : Si no realizo un buen seteo |
|
1316 | 1309 | 1 : Si realizo un buen seteo |
|
1317 | 1310 | """ |
|
1318 | 1311 | |
|
1319 | 1312 | if ext == None: |
|
1320 | 1313 | ext = self.ext |
|
1321 | 1314 | |
|
1322 | 1315 | ext = ext.lower() |
|
1323 | 1316 | |
|
1324 | 1317 | self.ext = ext |
|
1325 | 1318 | |
|
1326 | 1319 | self.path = path |
|
1327 | 1320 | |
|
1328 | 1321 | self.setFile = set - 1 |
|
1329 | 1322 | |
|
1330 | 1323 | self.blocksPerFile = blocksPerFile |
|
1331 | 1324 | |
|
1332 | 1325 | self.profilesPerBlock = profilesPerBlock |
|
1333 | 1326 | |
|
1334 | 1327 | self.dataOut = dataOut |
|
1335 | 1328 | |
|
1336 | 1329 | if not(self.setNextFile()): |
|
1337 | print "There isn't a next file" | |
|
1330 | print "[Writing] There isn't a next file" | |
|
1338 | 1331 | return 0 |
|
1339 | 1332 | |
|
1340 | 1333 | self.setBlockDimension() |
|
1341 | 1334 | |
|
1342 | 1335 | return 1 |
|
1343 | 1336 | |
|
1344 | 1337 | def run(self, dataOut, **kwargs): |
|
1345 | 1338 | |
|
1346 | 1339 | if not(self.isConfig): |
|
1347 | 1340 | |
|
1348 | 1341 | self.setup(dataOut, **kwargs) |
|
1349 | 1342 | self.isConfig = True |
|
1350 | 1343 | |
|
1351 | 1344 | self.putData() |
|
1352 | 1345 |
@@ -1,100 +1,104 | |||
|
1 | 1 | ''' |
|
2 | 2 | Created on Jul 3, 2014 |
|
3 | 3 | |
|
4 | 4 | @author: roj-idl71 |
|
5 | 5 | ''' |
|
6 | 6 | |
|
7 | 7 | import os |
|
8 | 8 | |
|
9 | 9 | from schainpy.model.data.jrodata import Voltage |
|
10 | 10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
11 | 11 | |
|
12 | 12 | class Reader(ProcessingUnit): |
|
13 | 13 | ''' |
|
14 | 14 | classdocs |
|
15 | 15 | ''' |
|
16 | 16 | |
|
17 | 17 | def __init__(self): |
|
18 | 18 | ''' |
|
19 | 19 | Constructor |
|
20 | 20 | ''' |
|
21 | 21 | |
|
22 | 22 | ProcessingUnit.__init__(self) |
|
23 | 23 | |
|
24 | # self.dataIn = None | |
|
25 | # | |
|
26 | # self.isConfig = False | |
|
27 | ||
|
28 | 24 | #Is really necessary create the output object in the initializer |
|
29 | 25 | self.dataOut = Voltage() |
|
30 | 26 | |
|
31 | 27 | def setup(self, path = None, |
|
32 | 28 | startDate = None, |
|
33 | 29 | endDate = None, |
|
34 | 30 | startTime = None, |
|
35 | 31 | endTime = None, |
|
36 | 32 | set = None, |
|
37 | 33 | expLabel = "", |
|
38 | 34 | ext = None, |
|
39 | 35 | online = False, |
|
40 | 36 | delay = 60, |
|
41 | 37 | walk = True): |
|
42 | 38 | ''' |
|
43 | 39 | In this method we should set all initial parameters. |
|
44 | 40 | |
|
45 | 41 | ''' |
|
46 | 42 |
|
|
43 | ''' | |
|
44 | Add code | |
|
45 | ''' | |
|
46 | ||
|
47 | 47 | self.isConfig = True |
|
48 | 48 | |
|
49 | 49 | def run(self, **kwargs): |
|
50 | 50 | ''' |
|
51 | 51 | This method will be called many times so here you should put all your code |
|
52 | 52 | ''' |
|
53 | 53 | |
|
54 | 54 | if not self.isConfig: |
|
55 | 55 | self.setup(**kwargs) |
|
56 | 56 |
|
|
57 | ''' | |
|
58 | Add code | |
|
59 | ''' | |
|
60 | ||
|
57 | 61 | class Writer(Operation): |
|
58 | 62 | ''' |
|
59 | 63 | classdocs |
|
60 | 64 | ''' |
|
61 | 65 | |
|
62 | 66 | def __init__(self): |
|
63 | 67 | ''' |
|
64 | 68 | Constructor |
|
65 | 69 | ''' |
|
66 | 70 | self.dataOut = None |
|
67 | 71 | |
|
68 | 72 | self.isConfig = False |
|
69 | 73 | |
|
70 | 74 | def setup(self, dataIn, path, blocksPerFile, set=0, ext=None): |
|
71 | 75 | ''' |
|
72 | 76 | In this method we should set all initial parameters. |
|
73 | 77 | |
|
74 | 78 | Input: |
|
75 | 79 | dataIn : Input data will also be outputa data |
|
76 | 80 | |
|
77 | 81 | ''' |
|
78 | 82 | self.dataOut = dataIn |
|
79 | 83 | |
|
80 | 84 | |
|
81 | 85 | |
|
82 | 86 | |
|
83 | 87 | |
|
84 | 88 | self.isConfig = True |
|
85 | 89 | |
|
86 | 90 | return |
|
87 | 91 | |
|
88 | 92 | def run(self, dataIn, **kwargs): |
|
89 | 93 | ''' |
|
90 | 94 | This method will be called many times so here you should put all your code |
|
91 | 95 | |
|
92 | 96 | Inputs: |
|
93 | 97 | |
|
94 | 98 | dataIn : object with the data |
|
95 | 99 | |
|
96 | 100 | ''' |
|
97 | 101 | |
|
98 | 102 | if not self.isConfig: |
|
99 | 103 | self.setup(dataIn, **kwargs) |
|
100 | 104 | No newline at end of file |
@@ -1,763 +1,834 | |||
|
1 | 1 | ''' |
|
2 | Created on Jul 3, 2014 | |
|
2 | 3 | |
|
4 | @author: roj-idl71 | |
|
3 | 5 | ''' |
|
4 | 6 | |
|
5 | 7 | import os, sys |
|
6 | 8 | import time, datetime |
|
7 | 9 | import numpy |
|
8 | 10 | import fnmatch |
|
9 | 11 | import glob |
|
10 | 12 | |
|
11 | 13 | try: |
|
14 | from gevent import sleep | |
|
15 | except: | |
|
16 | from time import sleep | |
|
17 | ||
|
18 | try: | |
|
12 | 19 | import pyfits |
|
13 | 20 | except: |
|
14 | 21 | """ |
|
15 | 22 | """ |
|
16 | ||
|
23 | ||
|
17 | 24 | from xml.etree.ElementTree import ElementTree |
|
18 | 25 | |
|
19 | 26 | from jroIO_base import isDoyFolder, isNumber |
|
20 | from model.proc.jroproc_base import Operation, ProcessingUnit | |
|
27 | from schainpy.model.proc.jroproc_base import Operation, ProcessingUnit | |
|
28 | ||
|
29 | class Fits: | |
|
30 | name=None | |
|
31 | format=None | |
|
32 | array =None | |
|
33 | data =None | |
|
34 | thdulist=None | |
|
35 | prihdr=None | |
|
36 | hdu=None | |
|
37 | ||
|
38 | def __init__(self): | |
|
39 | ||
|
40 | pass | |
|
41 | ||
|
42 | def setColF(self,name,format,array): | |
|
43 | self.name=name | |
|
44 | self.format=format | |
|
45 | self.array=array | |
|
46 | a1=numpy.array([self.array],dtype=numpy.float32) | |
|
47 | self.col1 = pyfits.Column(name=self.name, format=self.format, array=a1) | |
|
48 | return self.col1 | |
|
49 | ||
|
50 | # def setColP(self,name,format,data): | |
|
51 | # self.name=name | |
|
52 | # self.format=format | |
|
53 | # self.data=data | |
|
54 | # a2=numpy.array([self.data],dtype=numpy.float32) | |
|
55 | # self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
|
56 | # return self.col2 | |
|
57 | ||
|
58 | ||
|
59 | def writeData(self,name,format,data): | |
|
60 | self.name=name | |
|
61 | self.format=format | |
|
62 | self.data=data | |
|
63 | a2=numpy.array([self.data],dtype=numpy.float32) | |
|
64 | self.col2 = pyfits.Column(name=self.name, format=self.format, array=a2) | |
|
65 | return self.col2 | |
|
66 | ||
|
67 | def cFImage(self,idblock,year,month,day,hour,minute,second): | |
|
68 | self.hdu= pyfits.PrimaryHDU(idblock) | |
|
69 | self.hdu.header.set("Year",year) | |
|
70 | self.hdu.header.set("Month",month) | |
|
71 | self.hdu.header.set("Day",day) | |
|
72 | self.hdu.header.set("Hour",hour) | |
|
73 | self.hdu.header.set("Minute",minute) | |
|
74 | self.hdu.header.set("Second",second) | |
|
75 | return self.hdu | |
|
76 | ||
|
77 | ||
|
78 | def Ctable(self,colList): | |
|
79 | self.cols=pyfits.ColDefs(colList) | |
|
80 | self.tbhdu = pyfits.new_table(self.cols) | |
|
81 | return self.tbhdu | |
|
82 | ||
|
83 | ||
|
84 | def CFile(self,hdu,tbhdu): | |
|
85 | self.thdulist=pyfits.HDUList([hdu,tbhdu]) | |
|
86 | ||
|
87 | def wFile(self,filename): | |
|
88 | if os.path.isfile(filename): | |
|
89 | os.remove(filename) | |
|
90 | self.thdulist.writeto(filename) | |
|
91 | ||
|
21 | 92 | |
|
22 | 93 | class ParameterConf: |
|
23 | 94 | ELEMENTNAME = 'Parameter' |
|
24 | 95 | def __init__(self): |
|
25 | 96 | self.name = '' |
|
26 | 97 | self.value = '' |
|
27 | 98 | |
|
28 | 99 | def readXml(self, parmElement): |
|
29 | 100 | self.name = parmElement.get('name') |
|
30 | 101 | self.value = parmElement.get('value') |
|
31 | 102 | |
|
32 | 103 | def getElementName(self): |
|
33 | 104 | return self.ELEMENTNAME |
|
34 | 105 | |
|
35 | 106 | class Metadata: |
|
36 | 107 | |
|
37 | 108 | def __init__(self, filename): |
|
38 | 109 | self.parmConfObjList = [] |
|
39 | 110 | self.readXml(filename) |
|
40 | 111 | |
|
41 | 112 | def readXml(self, filename): |
|
42 | 113 | self.projectElement = None |
|
43 | 114 | self.procUnitConfObjDict = {} |
|
44 | 115 | self.projectElement = ElementTree().parse(filename) |
|
45 | 116 | self.project = self.projectElement.tag |
|
46 | 117 | |
|
47 | 118 | parmElementList = self.projectElement.getiterator(ParameterConf().getElementName()) |
|
48 | 119 | |
|
49 | 120 | for parmElement in parmElementList: |
|
50 | 121 | parmConfObj = ParameterConf() |
|
51 | 122 | parmConfObj.readXml(parmElement) |
|
52 | 123 | self.parmConfObjList.append(parmConfObj) |
|
53 | 124 | |
|
54 | 125 | class FitsWriter(Operation): |
|
55 | 126 | |
|
56 | 127 | def __init__(self): |
|
57 | 128 | self.isConfig = False |
|
58 | 129 | self.dataBlocksPerFile = None |
|
59 | 130 | self.blockIndex = 0 |
|
60 | 131 | self.flagIsNewFile = 1 |
|
61 | 132 | self.fitsObj = None |
|
62 | 133 | self.optchar = 'P' |
|
63 | 134 | self.ext = '.fits' |
|
64 | 135 | self.setFile = 0 |
|
65 | 136 | |
|
66 | 137 | def setFitsHeader(self, dataOut, metadatafile): |
|
67 | 138 | |
|
68 | 139 | header_data = pyfits.PrimaryHDU() |
|
69 | 140 | |
|
70 | 141 | metadata4fits = Metadata(metadatafile) |
|
71 | 142 | for parameter in metadata4fits.parmConfObjList: |
|
72 | 143 | parm_name = parameter.name |
|
73 | 144 | parm_value = parameter.value |
|
74 | 145 | |
|
75 | 146 | # if parm_value == 'fromdatadatetime': |
|
76 | 147 | # value = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) |
|
77 | 148 | # elif parm_value == 'fromdataheights': |
|
78 | 149 | # value = dataOut.nHeights |
|
79 | 150 | # elif parm_value == 'fromdatachannel': |
|
80 | 151 | # value = dataOut.nChannels |
|
81 | 152 | # elif parm_value == 'fromdatasamples': |
|
82 | 153 | # value = dataOut.nFFTPoints |
|
83 | 154 | # else: |
|
84 | 155 | # value = parm_value |
|
85 | 156 | |
|
86 | 157 | header_data.header[parm_name] = parm_value |
|
87 | 158 | |
|
88 | 159 | |
|
89 | 160 | header_data.header['DATETIME'] = time.strftime("%b %d %Y %H:%M:%S", dataOut.datatime.timetuple()) |
|
90 | 161 | header_data.header['CHANNELLIST'] = str(dataOut.channelList) |
|
91 | 162 | header_data.header['NCHANNELS'] = dataOut.nChannels |
|
92 | 163 | #header_data.header['HEIGHTS'] = dataOut.heightList |
|
93 | 164 | header_data.header['NHEIGHTS'] = dataOut.nHeights |
|
94 | 165 | |
|
95 | 166 | header_data.header['IPPSECONDS'] = dataOut.ippSeconds |
|
96 | 167 | header_data.header['NCOHINT'] = dataOut.nCohInt |
|
97 | 168 | header_data.header['NINCOHINT'] = dataOut.nIncohInt |
|
98 | 169 | header_data.header['TIMEZONE'] = dataOut.timeZone |
|
99 | 170 | header_data.header['NBLOCK'] = self.blockIndex |
|
100 | 171 | |
|
101 | 172 | header_data.writeto(self.filename) |
|
102 | 173 | |
|
103 | 174 | self.addExtension(dataOut.heightList,'HEIGHTLIST') |
|
104 | 175 | |
|
105 | 176 | |
|
106 | 177 | def setup(self, dataOut, path, dataBlocksPerFile, metadatafile): |
|
107 | 178 | |
|
108 | 179 | self.path = path |
|
109 | 180 | self.dataOut = dataOut |
|
110 | 181 | self.metadatafile = metadatafile |
|
111 | 182 | self.dataBlocksPerFile = dataBlocksPerFile |
|
112 | 183 | |
|
113 | 184 | def open(self): |
|
114 | 185 | self.fitsObj = pyfits.open(self.filename, mode='update') |
|
115 | 186 | |
|
116 | 187 | |
|
117 | 188 | def addExtension(self, data, tagname): |
|
118 | 189 | self.open() |
|
119 | 190 | extension = pyfits.ImageHDU(data=data, name=tagname) |
|
120 | 191 | #extension.header['TAG'] = tagname |
|
121 | 192 | self.fitsObj.append(extension) |
|
122 | 193 | self.write() |
|
123 | 194 | |
|
124 | 195 | def addData(self, data): |
|
125 | 196 | self.open() |
|
126 | 197 | extension = pyfits.ImageHDU(data=data, name=self.fitsObj[0].header['DATATYPE']) |
|
127 | 198 | extension.header['UTCTIME'] = self.dataOut.utctime |
|
128 | 199 | self.fitsObj.append(extension) |
|
129 | 200 | self.blockIndex += 1 |
|
130 | 201 | self.fitsObj[0].header['NBLOCK'] = self.blockIndex |
|
131 | 202 | |
|
132 | 203 | self.write() |
|
133 | 204 | |
|
134 | 205 | def write(self): |
|
135 | 206 | |
|
136 | 207 | self.fitsObj.flush(verbose=True) |
|
137 | 208 | self.fitsObj.close() |
|
138 | 209 | |
|
139 | 210 | |
|
140 | 211 | def setNextFile(self): |
|
141 | 212 | |
|
142 | 213 | ext = self.ext |
|
143 | 214 | path = self.path |
|
144 | 215 | |
|
145 | 216 | timeTuple = time.localtime( self.dataOut.utctime) |
|
146 | 217 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) |
|
147 | 218 | |
|
148 | 219 | fullpath = os.path.join( path, subfolder ) |
|
149 | 220 | if not( os.path.exists(fullpath) ): |
|
150 | 221 | os.mkdir(fullpath) |
|
151 | 222 | self.setFile = -1 #inicializo mi contador de seteo |
|
152 | 223 | else: |
|
153 | 224 | filesList = os.listdir( fullpath ) |
|
154 | 225 | if len( filesList ) > 0: |
|
155 | 226 | filesList = sorted( filesList, key=str.lower ) |
|
156 | 227 | filen = filesList[-1] |
|
157 | 228 | |
|
158 | 229 | if isNumber( filen[8:11] ): |
|
159 | 230 | self.setFile = int( filen[8:11] ) #inicializo mi contador de seteo al seteo del ultimo file |
|
160 | 231 | else: |
|
161 | 232 | self.setFile = -1 |
|
162 | 233 | else: |
|
163 | 234 | self.setFile = -1 #inicializo mi contador de seteo |
|
164 | 235 | |
|
165 | 236 | setFile = self.setFile |
|
166 | 237 | setFile += 1 |
|
167 | 238 | |
|
168 |
|
|
|
239 | thisFile = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, | |
|
169 | 240 | timeTuple.tm_year, |
|
170 | 241 | timeTuple.tm_yday, |
|
171 | 242 | setFile, |
|
172 | 243 | ext ) |
|
173 | 244 | |
|
174 |
filename = os.path.join( path, subfolder, |
|
|
245 | filename = os.path.join( path, subfolder, thisFile ) | |
|
175 | 246 | |
|
176 | 247 | self.blockIndex = 0 |
|
177 | 248 | self.filename = filename |
|
178 | 249 | self.setFile = setFile |
|
179 | 250 | self.flagIsNewFile = 1 |
|
180 | 251 | |
|
181 | 252 | print 'Writing the file: %s'%self.filename |
|
182 | 253 | |
|
183 | 254 | self.setFitsHeader(self.dataOut, self.metadatafile) |
|
184 | 255 | |
|
185 | 256 | return 1 |
|
186 | 257 | |
|
187 | 258 | def writeBlock(self): |
|
188 | 259 | self.addData(self.dataOut.data_spc) |
|
189 | 260 | self.flagIsNewFile = 0 |
|
190 | 261 | |
|
191 | 262 | |
|
192 | 263 | def __setNewBlock(self): |
|
193 | 264 | |
|
194 | 265 | if self.flagIsNewFile: |
|
195 | 266 | return 1 |
|
196 | 267 | |
|
197 | 268 | if self.blockIndex < self.dataBlocksPerFile: |
|
198 | 269 | return 1 |
|
199 | 270 | |
|
200 | 271 | if not( self.setNextFile() ): |
|
201 | 272 | return 0 |
|
202 | 273 | |
|
203 | 274 | return 1 |
|
204 | 275 | |
|
205 | 276 | def writeNextBlock(self): |
|
206 | 277 | if not( self.__setNewBlock() ): |
|
207 | 278 | return 0 |
|
208 | 279 | self.writeBlock() |
|
209 | 280 | return 1 |
|
210 | 281 | |
|
211 | 282 | def putData(self): |
|
212 | 283 | if self.flagIsNewFile: |
|
213 | 284 | self.setNextFile() |
|
214 | 285 | self.writeNextBlock() |
|
215 | 286 | |
|
216 | 287 | def run(self, dataOut, **kwargs): |
|
217 | 288 | if not(self.isConfig): |
|
218 | 289 | self.setup(dataOut, **kwargs) |
|
219 | 290 | self.isConfig = True |
|
220 | 291 | self.putData() |
|
221 | 292 | |
|
222 | 293 | |
|
223 | 294 | class FitsReader(ProcessingUnit): |
|
224 | 295 | |
|
225 | 296 | # __TIMEZONE = time.timezone |
|
226 | 297 | |
|
227 | 298 | expName = None |
|
228 | 299 | datetimestr = None |
|
229 | 300 | utc = None |
|
230 | 301 | nChannels = None |
|
231 | 302 | nSamples = None |
|
232 | 303 | dataBlocksPerFile = None |
|
233 | 304 | comments = None |
|
234 | 305 | lastUTTime = None |
|
235 | 306 | header_dict = None |
|
236 | 307 | data = None |
|
237 | 308 | data_header_dict = None |
|
238 | 309 | |
|
239 | 310 | def __init__(self): |
|
240 | 311 | self.isConfig = False |
|
241 | 312 | self.ext = '.fits' |
|
242 | 313 | self.setFile = 0 |
|
243 | 314 | self.flagNoMoreFiles = 0 |
|
244 | 315 | self.flagIsNewFile = 1 |
|
245 |
self.flag |
|
|
316 | self.flagDiscontinuousBlock = None | |
|
246 | 317 | self.fileIndex = None |
|
247 | 318 | self.filename = None |
|
248 | 319 | self.fileSize = None |
|
249 | 320 | self.fitsObj = None |
|
250 | 321 | self.timeZone = None |
|
251 | 322 | self.nReadBlocks = 0 |
|
252 | 323 | self.nTotalBlocks = 0 |
|
253 | 324 | self.dataOut = self.createObjByDefault() |
|
254 | 325 | self.maxTimeStep = 10# deberia ser definido por el usuario usando el metodo setup() |
|
255 | 326 | self.blockIndex = 1 |
|
256 | 327 | |
|
257 | 328 | def createObjByDefault(self): |
|
258 | 329 | |
|
259 | 330 | dataObj = Fits() |
|
260 | 331 | |
|
261 | 332 | return dataObj |
|
262 | 333 | |
|
263 | 334 | def isFileinThisTime(self, filename, startTime, endTime, useLocalTime=False): |
|
264 | 335 | try: |
|
265 | 336 | fitsObj = pyfits.open(filename,'readonly') |
|
266 | 337 | except: |
|
267 | 338 | raise IOError, "The file %s can't be opened" %(filename) |
|
268 | 339 | |
|
269 | 340 | header = fitsObj[0].header |
|
270 | 341 | struct_time = time.strptime(header['DATETIME'], "%b %d %Y %H:%M:%S") |
|
271 | 342 | utc = time.mktime(struct_time) - time.timezone #TIMEZONE debe ser un parametro del header FITS |
|
272 | 343 | |
|
273 | 344 | ltc = utc |
|
274 | 345 | if useLocalTime: |
|
275 | 346 | ltc -= time.timezone |
|
276 | 347 | thisDatetime = datetime.datetime.utcfromtimestamp(ltc) |
|
277 | 348 | thisTime = thisDatetime.time() |
|
278 | 349 | |
|
279 | 350 | if not ((startTime <= thisTime) and (endTime > thisTime)): |
|
280 | 351 | return None |
|
281 | 352 | |
|
282 | 353 | return thisDatetime |
|
283 | 354 | |
|
284 | 355 | def __setNextFileOnline(self): |
|
285 | 356 | raise ValueError, "No implemented" |
|
286 | 357 | |
|
287 | 358 | def __setNextFileOffline(self): |
|
288 | 359 | idFile = self.fileIndex |
|
289 | 360 | |
|
290 | 361 | while (True): |
|
291 | 362 | idFile += 1 |
|
292 | 363 | if not(idFile < len(self.filenameList)): |
|
293 | 364 | self.flagNoMoreFiles = 1 |
|
294 | 365 | print "No more Files" |
|
295 | 366 | return 0 |
|
296 | 367 | |
|
297 | 368 | filename = self.filenameList[idFile] |
|
298 | 369 | |
|
299 | 370 | # if not(self.__verifyFile(filename)): |
|
300 | 371 | # continue |
|
301 | 372 | |
|
302 | 373 | fileSize = os.path.getsize(filename) |
|
303 | 374 | fitsObj = pyfits.open(filename,'readonly') |
|
304 | 375 | break |
|
305 | 376 | |
|
306 | 377 | self.flagIsNewFile = 1 |
|
307 | 378 | self.fileIndex = idFile |
|
308 | 379 | self.filename = filename |
|
309 | 380 | self.fileSize = fileSize |
|
310 | 381 | self.fitsObj = fitsObj |
|
311 | 382 | self.blockIndex = 0 |
|
312 | 383 | print "Setting the file: %s"%self.filename |
|
313 | 384 | |
|
314 | 385 | return 1 |
|
315 | 386 | |
|
316 | 387 | def readHeader(self): |
|
317 | 388 | headerObj = self.fitsObj[0] |
|
318 | 389 | |
|
319 | 390 | self.header_dict = headerObj.header |
|
320 | 391 | if 'EXPNAME' in headerObj.header.keys(): |
|
321 | 392 | self.expName = headerObj.header['EXPNAME'] |
|
322 | 393 | |
|
323 | 394 | if 'DATATYPE' in headerObj.header.keys(): |
|
324 | 395 | self.dataType = headerObj.header['DATATYPE'] |
|
325 | 396 | |
|
326 | 397 | self.datetimestr = headerObj.header['DATETIME'] |
|
327 | 398 | channelList = headerObj.header['CHANNELLIST'] |
|
328 | 399 | channelList = channelList.split('[') |
|
329 | 400 | channelList = channelList[1].split(']') |
|
330 | 401 | channelList = channelList[0].split(',') |
|
331 | 402 | channelList = [int(ch) for ch in channelList] |
|
332 | 403 | self.channelList = channelList |
|
333 | 404 | self.nChannels = headerObj.header['NCHANNELS'] |
|
334 | 405 | self.nHeights = headerObj.header['NHEIGHTS'] |
|
335 | 406 | self.ippSeconds = headerObj.header['IPPSECONDS'] |
|
336 | 407 | self.nCohInt = headerObj.header['NCOHINT'] |
|
337 | 408 | self.nIncohInt = headerObj.header['NINCOHINT'] |
|
338 | 409 | self.dataBlocksPerFile = headerObj.header['NBLOCK'] |
|
339 | 410 | self.timeZone = headerObj.header['TIMEZONE'] |
|
340 | 411 | |
|
341 | 412 | # self.timeInterval = self.ippSeconds * self.nCohInt * self.nIncohInt |
|
342 | 413 | |
|
343 | 414 | if 'COMMENT' in headerObj.header.keys(): |
|
344 | 415 | self.comments = headerObj.header['COMMENT'] |
|
345 | 416 | |
|
346 | 417 | self.readHeightList() |
|
347 | 418 | |
|
348 | 419 | def readHeightList(self): |
|
349 | 420 | self.blockIndex = self.blockIndex + 1 |
|
350 | 421 | obj = self.fitsObj[self.blockIndex] |
|
351 | 422 | self.heightList = obj.data |
|
352 | 423 | self.blockIndex = self.blockIndex + 1 |
|
353 | 424 | |
|
354 | 425 | def readExtension(self): |
|
355 | 426 | obj = self.fitsObj[self.blockIndex] |
|
356 | 427 | self.heightList = obj.data |
|
357 | 428 | self.blockIndex = self.blockIndex + 1 |
|
358 | 429 | |
|
359 | 430 | def setNextFile(self): |
|
360 | 431 | |
|
361 | 432 | if self.online: |
|
362 | 433 | newFile = self.__setNextFileOnline() |
|
363 | 434 | else: |
|
364 | 435 | newFile = self.__setNextFileOffline() |
|
365 | 436 | |
|
366 | 437 | if not(newFile): |
|
367 | 438 | return 0 |
|
368 | 439 | |
|
369 | 440 | self.readHeader() |
|
370 | 441 | |
|
371 | 442 | self.nReadBlocks = 0 |
|
372 | 443 | # self.blockIndex = 1 |
|
373 | 444 | return 1 |
|
374 | 445 | |
|
375 | 446 | def __searchFilesOffLine(self, |
|
376 | 447 | path, |
|
377 | 448 | startDate, |
|
378 | 449 | endDate, |
|
379 | 450 | startTime=datetime.time(0,0,0), |
|
380 | 451 | endTime=datetime.time(23,59,59), |
|
381 | 452 | set=None, |
|
382 | 453 | expLabel='', |
|
383 | 454 | ext='.fits', |
|
384 | 455 | walk=True): |
|
385 | 456 | |
|
386 | 457 | pathList = [] |
|
387 | 458 | |
|
388 | 459 | if not walk: |
|
389 | 460 | pathList.append(path) |
|
390 | 461 | |
|
391 | 462 | else: |
|
392 | 463 | dirList = [] |
|
393 | 464 | for thisPath in os.listdir(path): |
|
394 | 465 | if not os.path.isdir(os.path.join(path,thisPath)): |
|
395 | 466 | continue |
|
396 | 467 | if not isDoyFolder(thisPath): |
|
397 | 468 | continue |
|
398 | 469 | |
|
399 | 470 | dirList.append(thisPath) |
|
400 | 471 | |
|
401 | 472 | if not(dirList): |
|
402 | 473 | return None, None |
|
403 | 474 | |
|
404 | 475 | thisDate = startDate |
|
405 | 476 | |
|
406 | 477 | while(thisDate <= endDate): |
|
407 | 478 | year = thisDate.timetuple().tm_year |
|
408 | 479 | doy = thisDate.timetuple().tm_yday |
|
409 | 480 | |
|
410 | 481 | matchlist = fnmatch.filter(dirList, '?' + '%4.4d%3.3d' % (year,doy) + '*') |
|
411 | 482 | if len(matchlist) == 0: |
|
412 | 483 | thisDate += datetime.timedelta(1) |
|
413 | 484 | continue |
|
414 | 485 | for match in matchlist: |
|
415 | 486 | pathList.append(os.path.join(path,match,expLabel)) |
|
416 | 487 | |
|
417 | 488 | thisDate += datetime.timedelta(1) |
|
418 | 489 | |
|
419 | 490 | if pathList == []: |
|
420 | 491 | print "Any folder was found for the date range: %s-%s" %(startDate, endDate) |
|
421 | 492 | return None, None |
|
422 | 493 | |
|
423 | 494 | print "%d folder(s) was(were) found for the date range: %s - %s" %(len(pathList), startDate, endDate) |
|
424 | 495 | |
|
425 | 496 | filenameList = [] |
|
426 | 497 | datetimeList = [] |
|
427 | 498 | |
|
428 | 499 | for i in range(len(pathList)): |
|
429 | 500 | |
|
430 | 501 | thisPath = pathList[i] |
|
431 | 502 | |
|
432 | 503 | fileList = glob.glob1(thisPath, "*%s" %ext) |
|
433 | 504 | fileList.sort() |
|
434 | 505 | |
|
435 |
for |
|
|
506 | for thisFile in fileList: | |
|
436 | 507 | |
|
437 |
filename = os.path.join(thisPath, |
|
|
508 | filename = os.path.join(thisPath,thisFile) | |
|
438 | 509 | thisDatetime = self.isFileinThisTime(filename, startTime, endTime) |
|
439 | 510 | |
|
440 | 511 | if not(thisDatetime): |
|
441 | 512 | continue |
|
442 | 513 | |
|
443 | 514 | filenameList.append(filename) |
|
444 | 515 | datetimeList.append(thisDatetime) |
|
445 | 516 | |
|
446 | 517 | if not(filenameList): |
|
447 | 518 | print "Any file was found for the time range %s - %s" %(startTime, endTime) |
|
448 | 519 | return None, None |
|
449 | 520 | |
|
450 | 521 | print "%d file(s) was(were) found for the time range: %s - %s" %(len(filenameList), startTime, endTime) |
|
451 | 522 | |
|
452 | 523 | |
|
453 | 524 | for i in range(len(filenameList)): |
|
454 | 525 | print "%s -> [%s]" %(filenameList[i], datetimeList[i].ctime()) |
|
455 | 526 | |
|
456 | 527 | self.filenameList = filenameList |
|
457 | 528 | self.datetimeList = datetimeList |
|
458 | 529 | |
|
459 | 530 | return pathList, filenameList |
|
460 | 531 | |
|
461 | 532 | def setup(self, path=None, |
|
462 | 533 | startDate=None, |
|
463 | 534 | endDate=None, |
|
464 | 535 | startTime=datetime.time(0,0,0), |
|
465 | 536 | endTime=datetime.time(23,59,59), |
|
466 | 537 | set=0, |
|
467 | 538 | expLabel = "", |
|
468 | 539 | ext = None, |
|
469 | 540 | online = False, |
|
470 | 541 | delay = 60, |
|
471 | 542 | walk = True): |
|
472 | 543 | |
|
473 | 544 | if path == None: |
|
474 | 545 | raise ValueError, "The path is not valid" |
|
475 | 546 | |
|
476 | 547 | if ext == None: |
|
477 | 548 | ext = self.ext |
|
478 | 549 | |
|
479 | 550 | if not(online): |
|
480 | 551 | print "Searching files in offline mode ..." |
|
481 | 552 | pathList, filenameList = self.__searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
482 | 553 | startTime=startTime, endTime=endTime, |
|
483 | 554 | set=set, expLabel=expLabel, ext=ext, |
|
484 | 555 | walk=walk) |
|
485 | 556 | |
|
486 | 557 | if not(pathList): |
|
487 | 558 | print "No *%s files into the folder %s \nfor the range: %s - %s"%(ext, path, |
|
488 | 559 | datetime.datetime.combine(startDate,startTime).ctime(), |
|
489 | 560 | datetime.datetime.combine(endDate,endTime).ctime()) |
|
490 | 561 | |
|
491 | 562 | sys.exit(-1) |
|
492 | 563 | |
|
493 | 564 | self.fileIndex = -1 |
|
494 | 565 | self.pathList = pathList |
|
495 | 566 | self.filenameList = filenameList |
|
496 | 567 | |
|
497 | 568 | self.online = online |
|
498 | 569 | self.delay = delay |
|
499 | 570 | ext = ext.lower() |
|
500 | 571 | self.ext = ext |
|
501 | 572 | |
|
502 | 573 | if not(self.setNextFile()): |
|
503 | 574 | if (startDate!=None) and (endDate!=None): |
|
504 | 575 | print "No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) |
|
505 | 576 | elif startDate != None: |
|
506 | 577 | print "No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) |
|
507 | 578 | else: |
|
508 | 579 | print "No files" |
|
509 | 580 | |
|
510 | 581 | sys.exit(-1) |
|
511 | 582 | |
|
512 | 583 | |
|
513 | 584 | |
|
514 | 585 | def readBlock(self): |
|
515 | 586 | dataObj = self.fitsObj[self.blockIndex] |
|
516 | 587 | |
|
517 | 588 | self.data = dataObj.data |
|
518 | 589 | self.data_header_dict = dataObj.header |
|
519 | 590 | self.utc = self.data_header_dict['UTCTIME'] |
|
520 | 591 | |
|
521 | 592 | self.flagIsNewFile = 0 |
|
522 | 593 | self.blockIndex += 1 |
|
523 | 594 | self.nTotalBlocks += 1 |
|
524 | 595 | self.nReadBlocks += 1 |
|
525 | 596 | |
|
526 | 597 | return 1 |
|
527 | 598 | |
|
528 | 599 | def __jumpToLastBlock(self): |
|
529 | 600 | raise ValueError, "No implemented" |
|
530 | 601 | |
|
531 | 602 | def __waitNewBlock(self): |
|
532 | 603 | """ |
|
533 | 604 | Return 1 si se encontro un nuevo bloque de datos, 0 de otra forma. |
|
534 | 605 | |
|
535 | 606 | Si el modo de lectura es OffLine siempre retorn 0 |
|
536 | 607 | """ |
|
537 | 608 | if not self.online: |
|
538 | 609 | return 0 |
|
539 | 610 | |
|
540 | 611 | if (self.nReadBlocks >= self.dataBlocksPerFile): |
|
541 | 612 | return 0 |
|
542 | 613 | |
|
543 | 614 | currentPointer = self.fp.tell() |
|
544 | 615 | |
|
545 | 616 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
546 | 617 | |
|
547 | 618 | for nTries in range( self.nTries ): |
|
548 | 619 | |
|
549 | 620 | self.fp.close() |
|
550 | 621 | self.fp = open( self.filename, 'rb' ) |
|
551 | 622 | self.fp.seek( currentPointer ) |
|
552 | 623 | |
|
553 | 624 | self.fileSize = os.path.getsize( self.filename ) |
|
554 | 625 | currentSize = self.fileSize - currentPointer |
|
555 | 626 | |
|
556 | 627 | if ( currentSize >= neededSize ): |
|
557 | 628 | self.__rdBasicHeader() |
|
558 | 629 | return 1 |
|
559 | 630 | |
|
560 | 631 | print "\tWaiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) |
|
561 |
|
|
|
632 | sleep( self.delay ) | |
|
562 | 633 | |
|
563 | 634 | |
|
564 | 635 | return 0 |
|
565 | 636 | |
|
566 | 637 | def __setNewBlock(self): |
|
567 | 638 | |
|
568 | 639 | if self.online: |
|
569 | 640 | self.__jumpToLastBlock() |
|
570 | 641 | |
|
571 | 642 | if self.flagIsNewFile: |
|
572 | 643 | return 1 |
|
573 | 644 | |
|
574 | 645 | self.lastUTTime = self.utc |
|
575 | 646 | |
|
576 | 647 | if self.online: |
|
577 | 648 | if self.__waitNewBlock(): |
|
578 | 649 | return 1 |
|
579 | 650 | |
|
580 | 651 | if self.nReadBlocks < self.dataBlocksPerFile: |
|
581 | 652 | return 1 |
|
582 | 653 | |
|
583 | 654 | if not(self.setNextFile()): |
|
584 | 655 | return 0 |
|
585 | 656 | |
|
586 | 657 | deltaTime = self.utc - self.lastUTTime |
|
587 | 658 | |
|
588 |
self.flag |
|
|
659 | self.flagDiscontinuousBlock = 0 | |
|
589 | 660 | |
|
590 | 661 | if deltaTime > self.maxTimeStep: |
|
591 |
self.flag |
|
|
662 | self.flagDiscontinuousBlock = 1 | |
|
592 | 663 | |
|
593 | 664 | return 1 |
|
594 | 665 | |
|
595 | 666 | |
|
596 | 667 | def readNextBlock(self): |
|
597 | 668 | if not(self.__setNewBlock()): |
|
598 | 669 | return 0 |
|
599 | 670 | |
|
600 | 671 | if not(self.readBlock()): |
|
601 | 672 | return 0 |
|
602 | 673 | |
|
603 | 674 | return 1 |
|
604 | 675 | |
|
605 | 676 | |
|
606 | 677 | def getData(self): |
|
607 | 678 | |
|
608 | 679 | if self.flagNoMoreFiles: |
|
609 | 680 | self.dataOut.flagNoData = True |
|
610 | 681 | print 'Process finished' |
|
611 | 682 | return 0 |
|
612 | 683 | |
|
613 |
self.flag |
|
|
684 | self.flagDiscontinuousBlock = 0 | |
|
614 | 685 | self.flagIsNewBlock = 0 |
|
615 | 686 | |
|
616 | 687 | if not(self.readNextBlock()): |
|
617 | 688 | return 0 |
|
618 | 689 | |
|
619 | 690 | if self.data == None: |
|
620 | 691 | self.dataOut.flagNoData = True |
|
621 | 692 | return 0 |
|
622 | 693 | |
|
623 | 694 | self.dataOut.data = self.data |
|
624 | 695 | self.dataOut.data_header = self.data_header_dict |
|
625 | 696 | self.dataOut.utctime = self.utc |
|
626 | 697 | |
|
627 | 698 | self.dataOut.header = self.header_dict |
|
628 | 699 | self.dataOut.expName = self.expName |
|
629 | 700 | self.dataOut.nChannels = self.nChannels |
|
630 | 701 | self.dataOut.timeZone = self.timeZone |
|
631 | 702 | self.dataOut.dataBlocksPerFile = self.dataBlocksPerFile |
|
632 | 703 | self.dataOut.comments = self.comments |
|
633 | 704 | self.dataOut.timeInterval = self.timeInterval |
|
634 | 705 | self.dataOut.channelList = self.channelList |
|
635 | 706 | self.dataOut.heightList = self.heightList |
|
636 | 707 | self.dataOut.flagNoData = False |
|
637 | 708 | |
|
638 | 709 | return self.dataOut.data |
|
639 | 710 | |
|
640 | 711 | def run(self, **kwargs): |
|
641 | 712 | |
|
642 | 713 | if not(self.isConfig): |
|
643 | 714 | self.setup(**kwargs) |
|
644 | 715 | self.isConfig = True |
|
645 | 716 | |
|
646 | 717 | self.getData() |
|
647 | 718 | |
|
648 | 719 | class SpectraHeisWriter(Operation): |
|
649 | 720 | # set = None |
|
650 | 721 | setFile = None |
|
651 | 722 | idblock = None |
|
652 | 723 | doypath = None |
|
653 | 724 | subfolder = None |
|
654 | 725 | |
|
655 | 726 | def __init__(self): |
|
656 |
self.wrObj = F |
|
|
727 | self.wrObj = Fits() | |
|
657 | 728 | # self.dataOut = dataOut |
|
658 | 729 | self.nTotalBlocks=0 |
|
659 | 730 | # self.set = None |
|
660 | 731 | self.setFile = None |
|
661 | 732 | self.idblock = 0 |
|
662 | 733 | self.wrpath = None |
|
663 | 734 | self.doypath = None |
|
664 | 735 | self.subfolder = None |
|
665 | 736 | self.isConfig = False |
|
666 | 737 | |
|
667 | 738 | def isNumber(str): |
|
668 | 739 | """ |
|
669 | 740 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
|
670 | 741 | |
|
671 | 742 | Excepciones: |
|
672 | 743 | Si un determinado string no puede ser convertido a numero |
|
673 | 744 | Input: |
|
674 | 745 | str, string al cual se le analiza para determinar si convertible a un numero o no |
|
675 | 746 | |
|
676 | 747 | Return: |
|
677 | 748 | True : si el string es uno numerico |
|
678 | 749 | False : no es un string numerico |
|
679 | 750 | """ |
|
680 | 751 | try: |
|
681 | 752 | float( str ) |
|
682 | 753 | return True |
|
683 | 754 | except: |
|
684 | 755 | return False |
|
685 | 756 | |
|
686 | 757 | def setup(self, dataOut, wrpath): |
|
687 | 758 | |
|
688 | 759 | if not(os.path.exists(wrpath)): |
|
689 | 760 | os.mkdir(wrpath) |
|
690 | 761 | |
|
691 | 762 | self.wrpath = wrpath |
|
692 | 763 | # self.setFile = 0 |
|
693 | 764 | self.dataOut = dataOut |
|
694 | 765 | |
|
695 | 766 | def putData(self): |
|
696 | 767 | name= time.localtime( self.dataOut.utctime) |
|
697 | 768 | ext=".fits" |
|
698 | 769 | |
|
699 | 770 | if self.doypath == None: |
|
700 | 771 | self.subfolder = 'F%4.4d%3.3d_%d' % (name.tm_year,name.tm_yday,time.mktime(datetime.datetime.now().timetuple())) |
|
701 | 772 | self.doypath = os.path.join( self.wrpath, self.subfolder ) |
|
702 | 773 | os.mkdir(self.doypath) |
|
703 | 774 | |
|
704 | 775 | if self.setFile == None: |
|
705 | 776 | # self.set = self.dataOut.set |
|
706 | 777 | self.setFile = 0 |
|
707 | 778 | # if self.set != self.dataOut.set: |
|
708 | 779 | ## self.set = self.dataOut.set |
|
709 | 780 | # self.setFile = 0 |
|
710 | 781 | |
|
711 | 782 | #make the filename |
|
712 |
|
|
|
783 | thisFile = 'D%4.4d%3.3d_%3.3d%s' % (name.tm_year,name.tm_yday,self.setFile,ext) | |
|
713 | 784 | |
|
714 |
filename = os.path.join(self.wrpath,self.subfolder, |
|
|
785 | filename = os.path.join(self.wrpath,self.subfolder, thisFile) | |
|
715 | 786 | |
|
716 | 787 | idblock = numpy.array([self.idblock],dtype="int64") |
|
717 | 788 | header=self.wrObj.cFImage(idblock=idblock, |
|
718 | 789 | year=time.gmtime(self.dataOut.utctime).tm_year, |
|
719 | 790 | month=time.gmtime(self.dataOut.utctime).tm_mon, |
|
720 | 791 | day=time.gmtime(self.dataOut.utctime).tm_mday, |
|
721 | 792 | hour=time.gmtime(self.dataOut.utctime).tm_hour, |
|
722 | 793 | minute=time.gmtime(self.dataOut.utctime).tm_min, |
|
723 | 794 | second=time.gmtime(self.dataOut.utctime).tm_sec) |
|
724 | 795 | |
|
725 | 796 | c=3E8 |
|
726 | 797 | deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
727 | 798 | freq=numpy.arange(-1*self.dataOut.nHeights/2.,self.dataOut.nHeights/2.)*(c/(2*deltaHeight*1000)) |
|
728 | 799 | |
|
729 | 800 | colList = [] |
|
730 | 801 | |
|
731 | 802 | colFreq=self.wrObj.setColF(name="freq", format=str(self.dataOut.nFFTPoints)+'E', array=freq) |
|
732 | 803 | |
|
733 | 804 | colList.append(colFreq) |
|
734 | 805 | |
|
735 | 806 | nchannel=self.dataOut.nChannels |
|
736 | 807 | |
|
737 | 808 | for i in range(nchannel): |
|
738 | 809 | col = self.wrObj.writeData(name="PCh"+str(i+1), |
|
739 | 810 | format=str(self.dataOut.nFFTPoints)+'E', |
|
740 | 811 | data=10*numpy.log10(self.dataOut.data_spc[i,:])) |
|
741 | 812 | |
|
742 | 813 | colList.append(col) |
|
743 | 814 | |
|
744 | 815 | data=self.wrObj.Ctable(colList=colList) |
|
745 | 816 | |
|
746 | 817 | self.wrObj.CFile(header,data) |
|
747 | 818 | |
|
748 | 819 | self.wrObj.wFile(filename) |
|
749 | 820 | |
|
750 | 821 | #update the setFile |
|
751 | 822 | self.setFile += 1 |
|
752 | 823 | self.idblock += 1 |
|
753 | 824 | |
|
754 | 825 | return 1 |
|
755 | 826 | |
|
756 | 827 | def run(self, dataOut, **kwargs): |
|
757 | 828 | |
|
758 | 829 | if not(self.isConfig): |
|
759 | 830 | |
|
760 | 831 | self.setup(dataOut, **kwargs) |
|
761 | 832 | self.isConfig = True |
|
762 | 833 | |
|
763 | 834 | self.putData() No newline at end of file |
@@ -1,761 +1,764 | |||
|
1 | 1 | ''' |
|
2 | ''' | |
|
2 | Created on Jul 2, 2014 | |
|
3 | 3 |
|
|
4 | @author: roj-idl71 | |
|
5 | ''' | |
|
4 | 6 | import numpy |
|
5 | 7 | |
|
6 | 8 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter |
|
7 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
|
8 | from model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
|
9 | from model.data.jrodata import Spectra | |
|
9 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
10 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
|
11 | from schainpy.model.data.jrodata import Spectra | |
|
10 | 12 | |
|
11 | 13 | class SpectraReader(JRODataReader, ProcessingUnit): |
|
12 | 14 | """ |
|
13 | 15 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
14 | 16 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
|
15 | 17 | son almacenados en tres buffer's para el Self Spectra, el Cross Spectra y el DC Channel. |
|
16 | 18 | |
|
17 | 19 | paresCanalesIguales * alturas * perfiles (Self Spectra) |
|
18 | 20 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
19 | 21 | canales * alturas (DC Channels) |
|
20 | 22 | |
|
21 | 23 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
22 | 24 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
23 | 25 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
|
24 | 26 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
25 | 27 | |
|
26 | 28 | Example: |
|
27 | 29 | dpath = "/home/myuser/data" |
|
28 | 30 | |
|
29 | 31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
30 | 32 | |
|
31 | 33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
32 | 34 | |
|
33 | 35 | readerObj = SpectraReader() |
|
34 | 36 | |
|
35 | 37 | readerObj.setup(dpath, startTime, endTime) |
|
36 | 38 | |
|
37 | 39 | while(True): |
|
38 | 40 | |
|
39 | 41 | readerObj.getData() |
|
40 | 42 | |
|
41 | 43 | print readerObj.data_spc |
|
42 | 44 | |
|
43 | 45 | print readerObj.data_cspc |
|
44 | 46 | |
|
45 | 47 | print readerObj.data_dc |
|
46 | 48 | |
|
47 | 49 | if readerObj.flagNoMoreFiles: |
|
48 | 50 | break |
|
49 | 51 | |
|
50 | 52 | """ |
|
51 | 53 | |
|
52 | 54 | pts2read_SelfSpectra = 0 |
|
53 | 55 | |
|
54 | 56 | pts2read_CrossSpectra = 0 |
|
55 | 57 | |
|
56 | 58 | pts2read_DCchannels = 0 |
|
57 | 59 | |
|
58 | 60 | ext = ".pdata" |
|
59 | 61 | |
|
60 | 62 | optchar = "P" |
|
61 | 63 | |
|
62 | 64 | dataOut = None |
|
63 | 65 | |
|
64 | 66 | nRdChannels = None |
|
65 | 67 | |
|
66 | 68 | nRdPairs = None |
|
67 | 69 | |
|
68 | 70 | rdPairList = [] |
|
69 | 71 | |
|
70 | 72 | def __init__(self): |
|
71 | 73 | """ |
|
72 | 74 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
73 | 75 | |
|
74 | 76 | Inputs: |
|
75 | 77 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
76 | 78 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
77 | 79 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
78 | 80 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
79 | 81 | bloque de datos. |
|
80 | 82 | Si este parametro no es pasado se creara uno internamente. |
|
81 | 83 | |
|
82 | 84 | Affected: |
|
83 | 85 | self.dataOut |
|
84 | 86 | |
|
85 | 87 | Return : None |
|
86 | 88 | """ |
|
87 | 89 | |
|
88 | 90 | #Eliminar de la base la herencia |
|
89 | 91 | ProcessingUnit.__init__(self) |
|
90 | 92 | |
|
91 | 93 | # self.isConfig = False |
|
92 | 94 | |
|
93 | 95 | self.pts2read_SelfSpectra = 0 |
|
94 | 96 | |
|
95 | 97 | self.pts2read_CrossSpectra = 0 |
|
96 | 98 | |
|
97 | 99 | self.pts2read_DCchannels = 0 |
|
98 | 100 | |
|
99 | 101 | self.datablock = None |
|
100 | 102 | |
|
101 | 103 | self.utc = None |
|
102 | 104 | |
|
103 | 105 | self.ext = ".pdata" |
|
104 | 106 | |
|
105 | 107 | self.optchar = "P" |
|
106 | 108 | |
|
107 | 109 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
108 | 110 | |
|
109 | 111 | self.systemHeaderObj = SystemHeader() |
|
110 | 112 | |
|
111 | 113 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
112 | 114 | |
|
113 | 115 | self.processingHeaderObj = ProcessingHeader() |
|
114 | 116 | |
|
115 | 117 | self.online = 0 |
|
116 | 118 | |
|
117 | 119 | self.fp = None |
|
118 | 120 | |
|
119 | 121 | self.idFile = None |
|
120 | 122 | |
|
121 | 123 | self.dtype = None |
|
122 | 124 | |
|
123 | 125 | self.fileSizeByHeader = None |
|
124 | 126 | |
|
125 | 127 | self.filenameList = [] |
|
126 | 128 | |
|
127 | 129 | self.filename = None |
|
128 | 130 | |
|
129 | 131 | self.fileSize = None |
|
130 | 132 | |
|
131 | 133 | self.firstHeaderSize = 0 |
|
132 | 134 | |
|
133 | 135 | self.basicHeaderSize = 24 |
|
134 | 136 | |
|
135 | 137 | self.pathList = [] |
|
136 | 138 | |
|
137 | 139 | self.lastUTTime = 0 |
|
138 | 140 | |
|
139 | 141 | self.maxTimeStep = 30 |
|
140 | 142 | |
|
141 | 143 | self.flagNoMoreFiles = 0 |
|
142 | 144 | |
|
143 | 145 | self.set = 0 |
|
144 | 146 | |
|
145 | 147 | self.path = None |
|
146 | 148 | |
|
147 | 149 | self.delay = 60 #seconds |
|
148 | 150 | |
|
149 | 151 | self.nTries = 3 #quantity tries |
|
150 | 152 | |
|
151 | 153 | self.nFiles = 3 #number of files for searching |
|
152 | 154 | |
|
153 | 155 | self.nReadBlocks = 0 |
|
154 | 156 | |
|
155 | 157 | self.flagIsNewFile = 1 |
|
156 | 158 | |
|
157 | 159 | self.__isFirstTimeOnline = 1 |
|
158 | 160 | |
|
159 | 161 | # self.ippSeconds = 0 |
|
160 | 162 | |
|
161 |
self.flag |
|
|
163 | self.flagDiscontinuousBlock = 0 | |
|
162 | 164 | |
|
163 | 165 | self.flagIsNewBlock = 0 |
|
164 | 166 | |
|
165 | 167 | self.nTotalBlocks = 0 |
|
166 | 168 | |
|
167 | 169 | self.blocksize = 0 |
|
168 | 170 | |
|
169 | 171 | self.dataOut = self.createObjByDefault() |
|
170 | 172 | |
|
171 | 173 | self.profileIndex = 1 #Always |
|
172 | 174 | |
|
173 | 175 | |
|
174 | 176 | def createObjByDefault(self): |
|
175 | 177 | |
|
176 | 178 | dataObj = Spectra() |
|
177 | 179 | |
|
178 | 180 | return dataObj |
|
179 | 181 | |
|
180 | 182 | def __hasNotDataInBuffer(self): |
|
181 | 183 | return 1 |
|
182 | 184 | |
|
183 | 185 | |
|
184 | 186 | def getBlockDimension(self): |
|
185 | 187 | """ |
|
186 | 188 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
187 | 189 | |
|
188 | 190 | Affected: |
|
189 | 191 | self.nRdChannels |
|
190 | 192 | self.nRdPairs |
|
191 | 193 | self.pts2read_SelfSpectra |
|
192 | 194 | self.pts2read_CrossSpectra |
|
193 | 195 | self.pts2read_DCchannels |
|
194 | 196 | self.blocksize |
|
195 | 197 | self.dataOut.nChannels |
|
196 | 198 | self.dataOut.nPairs |
|
197 | 199 | |
|
198 | 200 | Return: |
|
199 | 201 | None |
|
200 | 202 | """ |
|
201 | 203 | self.nRdChannels = 0 |
|
202 | 204 | self.nRdPairs = 0 |
|
203 | 205 | self.rdPairList = [] |
|
204 | 206 | |
|
205 | 207 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
206 | 208 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
207 | 209 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
208 | 210 | else: |
|
209 | 211 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
210 | 212 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
211 | 213 | |
|
212 | 214 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
213 | 215 | |
|
214 | 216 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
215 | 217 | self.blocksize = self.pts2read_SelfSpectra |
|
216 | 218 | |
|
217 | 219 | if self.processingHeaderObj.flag_cspc: |
|
218 | 220 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
219 | 221 | self.blocksize += self.pts2read_CrossSpectra |
|
220 | 222 | |
|
221 | 223 | if self.processingHeaderObj.flag_dc: |
|
222 | 224 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
223 | 225 | self.blocksize += self.pts2read_DCchannels |
|
224 | 226 | |
|
225 | 227 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
226 | 228 | |
|
227 | 229 | |
|
228 | 230 | def readBlock(self): |
|
229 | 231 | """ |
|
230 | 232 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
231 | 233 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
232 | 234 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
233 | 235 | es seteado a 0 |
|
234 | 236 | |
|
235 | 237 | Return: None |
|
236 | 238 | |
|
237 | 239 | Variables afectadas: |
|
238 | 240 | |
|
239 | 241 | self.flagIsNewFile |
|
240 | 242 | self.flagIsNewBlock |
|
241 | 243 | self.nTotalBlocks |
|
242 | 244 | self.data_spc |
|
243 | 245 | self.data_cspc |
|
244 | 246 | self.data_dc |
|
245 | 247 | |
|
246 | 248 | Exceptions: |
|
247 | 249 | Si un bloque leido no es un bloque valido |
|
248 | 250 | """ |
|
249 | 251 | blockOk_flag = False |
|
250 | 252 | fpointer = self.fp.tell() |
|
251 | 253 | |
|
252 | 254 | spc = numpy.fromfile( self.fp, self.dtype[0], self.pts2read_SelfSpectra ) |
|
253 | 255 | spc = spc.reshape( (self.nRdChannels, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
254 | 256 | |
|
255 | 257 | if self.processingHeaderObj.flag_cspc: |
|
256 | 258 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
257 | 259 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
258 | 260 | |
|
259 | 261 | if self.processingHeaderObj.flag_dc: |
|
260 | 262 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
261 | 263 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
262 | 264 | |
|
263 | 265 | |
|
264 | 266 | if not(self.processingHeaderObj.shif_fft): |
|
265 | 267 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
266 | 268 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
267 | 269 | spc = numpy.roll( spc, shift , axis=2 ) |
|
268 | 270 | |
|
269 | 271 | if self.processingHeaderObj.flag_cspc: |
|
270 | 272 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
271 | 273 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
272 | 274 | |
|
273 | 275 | # self.processingHeaderObj.shif_fft = True |
|
274 | 276 | |
|
275 | 277 | spc = numpy.transpose( spc, (0,2,1) ) |
|
276 | 278 | self.data_spc = spc |
|
277 | 279 | |
|
278 | 280 | if self.processingHeaderObj.flag_cspc: |
|
279 | 281 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
280 | 282 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
281 | 283 | else: |
|
282 | 284 | self.data_cspc = None |
|
283 | 285 | |
|
284 | 286 | if self.processingHeaderObj.flag_dc: |
|
285 | 287 | self.data_dc = dc['real'] + dc['imag']*1j |
|
286 | 288 | else: |
|
287 | 289 | self.data_dc = None |
|
288 | 290 | |
|
289 | 291 | self.flagIsNewFile = 0 |
|
290 | 292 | self.flagIsNewBlock = 1 |
|
291 | 293 | |
|
292 | 294 | self.nTotalBlocks += 1 |
|
293 | 295 | self.nReadBlocks += 1 |
|
294 | 296 | |
|
295 | 297 | return 1 |
|
296 | 298 | |
|
297 | 299 | def getFirstHeader(self): |
|
298 | 300 | |
|
299 | 301 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
300 | 302 | |
|
301 | 303 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
302 | 304 | |
|
303 | 305 | # self.dataOut.ippSeconds = self.ippSeconds |
|
304 | 306 | |
|
305 | 307 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock |
|
306 | 308 | |
|
307 | 309 | self.dataOut.dtype = self.dtype |
|
308 | 310 | |
|
309 | 311 | # self.dataOut.nPairs = self.nPairs |
|
310 | 312 | |
|
311 | 313 | self.dataOut.pairsList = self.rdPairList |
|
312 | 314 | |
|
313 | 315 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
314 | 316 | |
|
315 | 317 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
316 | 318 | |
|
317 | 319 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
318 | 320 | |
|
319 | 321 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
320 | 322 | |
|
321 | 323 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
322 | 324 | |
|
323 | 325 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
324 | 326 | |
|
325 | 327 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
326 | 328 | |
|
327 | 329 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
328 | 330 | |
|
329 | 331 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
330 | 332 | |
|
331 |
self.dataOut.flagDeflipData = |
|
|
333 | self.dataOut.flagDeflipData = False #asumo q la data esta sin flip | |
|
332 | 334 | |
|
333 | 335 | if self.radarControllerHeaderObj.code != None: |
|
334 | 336 | |
|
335 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
|
336 | ||
|
337 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
|
338 | ||
|
339 | self.dataOut.code = self.radarControllerHeaderObj.code | |
|
337 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
|
338 | # | |
|
339 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
|
340 | # | |
|
341 | # self.dataOut.code = self.radarControllerHeaderObj.code | |
|
340 | 342 | |
|
341 | 343 | self.dataOut.flagDecodeData = True |
|
342 | 344 | |
|
343 | 345 | def getData(self): |
|
344 | 346 | """ |
|
345 | 347 | First method to execute before "RUN" is called. |
|
346 | 348 | |
|
347 | 349 | Copia el buffer de lectura a la clase "Spectra", |
|
348 | 350 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
349 | 351 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
350 | 352 | |
|
351 | 353 | Return: |
|
352 | 354 | 0 : Si no hay mas archivos disponibles |
|
353 | 355 | 1 : Si hizo una buena copia del buffer |
|
354 | 356 | |
|
355 | 357 | Affected: |
|
356 | 358 | self.dataOut |
|
357 | 359 | |
|
358 |
self.flag |
|
|
360 | self.flagDiscontinuousBlock | |
|
359 | 361 | self.flagIsNewBlock |
|
360 | 362 | """ |
|
361 | 363 | |
|
362 | 364 | if self.flagNoMoreFiles: |
|
363 | 365 | self.dataOut.flagNoData = True |
|
364 | 366 | print 'Process finished' |
|
365 | 367 | return 0 |
|
366 | 368 | |
|
367 |
self.flag |
|
|
369 | self.flagDiscontinuousBlock = 0 | |
|
368 | 370 | self.flagIsNewBlock = 0 |
|
369 | 371 | |
|
370 | 372 | if self.__hasNotDataInBuffer(): |
|
371 | 373 | |
|
372 | 374 | if not( self.readNextBlock() ): |
|
373 | 375 | self.dataOut.flagNoData = True |
|
374 | 376 | return 0 |
|
375 | 377 | |
|
376 | 378 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
377 | 379 | |
|
378 | 380 | if self.data_dc == None: |
|
379 | 381 | self.dataOut.flagNoData = True |
|
380 | 382 | return 0 |
|
381 | 383 | |
|
382 | 384 | self.getBasicHeader() |
|
383 | 385 | |
|
384 | 386 | self.getFirstHeader() |
|
385 | 387 | |
|
386 | 388 | self.dataOut.data_spc = self.data_spc |
|
387 | 389 | |
|
388 | 390 | self.dataOut.data_cspc = self.data_cspc |
|
389 | 391 | |
|
390 | 392 | self.dataOut.data_dc = self.data_dc |
|
391 | 393 | |
|
392 | 394 | self.dataOut.flagNoData = False |
|
393 | 395 | |
|
394 | 396 | self.dataOut.realtime = self.online |
|
395 | 397 | |
|
396 | 398 | return self.dataOut.data_spc |
|
397 | 399 | |
|
398 | 400 | class SpectraWriter(JRODataWriter, Operation): |
|
399 | 401 | |
|
400 | 402 | """ |
|
401 | 403 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
402 | 404 | de los datos siempre se realiza por bloques. |
|
403 | 405 | """ |
|
404 | 406 | |
|
405 | 407 | ext = ".pdata" |
|
406 | 408 | |
|
407 | 409 | optchar = "P" |
|
408 | 410 | |
|
409 | 411 | shape_spc_Buffer = None |
|
410 | 412 | |
|
411 | 413 | shape_cspc_Buffer = None |
|
412 | 414 | |
|
413 | 415 | shape_dc_Buffer = None |
|
414 | 416 | |
|
415 | 417 | data_spc = None |
|
416 | 418 | |
|
417 | 419 | data_cspc = None |
|
418 | 420 | |
|
419 | 421 | data_dc = None |
|
420 | 422 | |
|
421 | 423 | # dataOut = None |
|
422 | 424 | |
|
423 | 425 | def __init__(self): |
|
424 | 426 | """ |
|
425 | 427 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
426 | 428 | |
|
427 | 429 | Affected: |
|
428 | 430 | self.dataOut |
|
429 | 431 | self.basicHeaderObj |
|
430 | 432 | self.systemHeaderObj |
|
431 | 433 | self.radarControllerHeaderObj |
|
432 | 434 | self.processingHeaderObj |
|
433 | 435 | |
|
434 | 436 | Return: None |
|
435 | 437 | """ |
|
436 | 438 | |
|
437 | 439 | Operation.__init__(self) |
|
438 | 440 | |
|
439 | 441 | self.isConfig = False |
|
440 | 442 | |
|
441 | 443 | self.nTotalBlocks = 0 |
|
442 | 444 | |
|
443 | 445 | self.data_spc = None |
|
444 | 446 | |
|
445 | 447 | self.data_cspc = None |
|
446 | 448 | |
|
447 | 449 | self.data_dc = None |
|
448 | 450 | |
|
449 | 451 | self.fp = None |
|
450 | 452 | |
|
451 | 453 | self.flagIsNewFile = 1 |
|
452 | 454 | |
|
453 | 455 | self.nTotalBlocks = 0 |
|
454 | 456 | |
|
455 | 457 | self.flagIsNewBlock = 0 |
|
456 | 458 | |
|
457 | 459 | self.setFile = None |
|
458 | 460 | |
|
459 | 461 | self.dtype = None |
|
460 | 462 | |
|
461 | 463 | self.path = None |
|
462 | 464 | |
|
463 | 465 | self.noMoreFiles = 0 |
|
464 | 466 | |
|
465 | 467 | self.filename = None |
|
466 | 468 | |
|
467 | 469 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
468 | 470 | |
|
469 | 471 | self.systemHeaderObj = SystemHeader() |
|
470 | 472 | |
|
471 | 473 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
472 | 474 | |
|
473 | 475 | self.processingHeaderObj = ProcessingHeader() |
|
474 | 476 | |
|
475 | 477 | |
|
476 | 478 | def hasAllDataInBuffer(self): |
|
477 | 479 | return 1 |
|
478 | 480 | |
|
479 | 481 | |
|
480 | 482 | def setBlockDimension(self): |
|
481 | 483 | """ |
|
482 | 484 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
483 | 485 | |
|
484 | 486 | Affected: |
|
485 | 487 | self.shape_spc_Buffer |
|
486 | 488 | self.shape_cspc_Buffer |
|
487 | 489 | self.shape_dc_Buffer |
|
488 | 490 | |
|
489 | 491 | Return: None |
|
490 | 492 | """ |
|
491 | 493 | self.shape_spc_Buffer = (self.dataOut.nChannels, |
|
492 | 494 | self.processingHeaderObj.nHeights, |
|
493 | 495 | self.processingHeaderObj.profilesPerBlock) |
|
494 | 496 | |
|
495 | 497 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
496 | 498 | self.processingHeaderObj.nHeights, |
|
497 | 499 | self.processingHeaderObj.profilesPerBlock) |
|
498 | 500 | |
|
499 | 501 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
500 | 502 | self.processingHeaderObj.nHeights) |
|
501 | 503 | |
|
502 | 504 | |
|
503 | 505 | def writeBlock(self): |
|
504 | 506 | """ |
|
505 | 507 | Escribe el buffer en el file designado |
|
506 | 508 | |
|
507 | 509 | Affected: |
|
508 | 510 | self.data_spc |
|
509 | 511 | self.data_cspc |
|
510 | 512 | self.data_dc |
|
511 | 513 | self.flagIsNewFile |
|
512 | 514 | self.flagIsNewBlock |
|
513 | 515 | self.nTotalBlocks |
|
514 | 516 | self.nWriteBlocks |
|
515 | 517 | |
|
516 | 518 | Return: None |
|
517 | 519 | """ |
|
518 | 520 | |
|
519 | 521 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
520 | 522 | if not( self.processingHeaderObj.shif_fft ): |
|
521 | 523 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
522 | 524 | data = spc.reshape((-1)) |
|
523 | 525 | data = data.astype(self.dtype[0]) |
|
524 | 526 | data.tofile(self.fp) |
|
525 | 527 | |
|
526 | 528 | if self.data_cspc != None: |
|
527 | 529 | data = numpy.zeros( self.shape_cspc_Buffer, self.dtype ) |
|
528 | 530 | cspc = numpy.transpose( self.data_cspc, (0,2,1) ) |
|
529 | 531 | if not( self.processingHeaderObj.shif_fft ): |
|
530 | 532 | cspc = numpy.roll( cspc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
|
531 | 533 | data['real'] = cspc.real |
|
532 | 534 | data['imag'] = cspc.imag |
|
533 | 535 | data = data.reshape((-1)) |
|
534 | 536 | data.tofile(self.fp) |
|
535 | 537 | |
|
536 | 538 | if self.data_dc != None: |
|
537 | 539 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
|
538 | 540 | dc = self.data_dc |
|
539 | 541 | data['real'] = dc.real |
|
540 | 542 | data['imag'] = dc.imag |
|
541 | 543 | data = data.reshape((-1)) |
|
542 | 544 | data.tofile(self.fp) |
|
543 | 545 | |
|
544 | 546 | self.data_spc.fill(0) |
|
545 | 547 | |
|
546 | 548 | if self.data_dc != None: |
|
547 | 549 | self.data_dc.fill(0) |
|
548 | 550 | |
|
549 | 551 | if self.data_cspc != None: |
|
550 | 552 | self.data_cspc.fill(0) |
|
551 | 553 | |
|
552 | 554 | self.flagIsNewFile = 0 |
|
553 | 555 | self.flagIsNewBlock = 1 |
|
554 | 556 | self.nTotalBlocks += 1 |
|
555 | 557 | self.nWriteBlocks += 1 |
|
556 | 558 | self.blockIndex += 1 |
|
557 | 559 | |
|
560 | print "[Writing] Block = ", self.blockIndex | |
|
558 | 561 | |
|
559 | 562 | def putData(self): |
|
560 | 563 | """ |
|
561 | 564 | Setea un bloque de datos y luego los escribe en un file |
|
562 | 565 | |
|
563 | 566 | Affected: |
|
564 | 567 | self.data_spc |
|
565 | 568 | self.data_cspc |
|
566 | 569 | self.data_dc |
|
567 | 570 | |
|
568 | 571 | Return: |
|
569 | 572 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
570 | 573 | 1 : Si se escribio la data de un bloque en un file |
|
571 | 574 | """ |
|
572 | 575 | |
|
573 | 576 | if self.dataOut.flagNoData: |
|
574 | 577 | return 0 |
|
575 | 578 | |
|
576 | 579 | self.flagIsNewBlock = 0 |
|
577 | 580 | |
|
578 |
if self.dataOut.flag |
|
|
581 | if self.dataOut.flagDiscontinuousBlock: | |
|
579 | 582 | self.data_spc.fill(0) |
|
580 | 583 | self.data_cspc.fill(0) |
|
581 | 584 | self.data_dc.fill(0) |
|
582 | 585 | self.setNextFile() |
|
583 | 586 | |
|
584 | 587 | if self.flagIsNewFile == 0: |
|
585 | 588 | self.setBasicHeader() |
|
586 | 589 | |
|
587 | 590 | self.data_spc = self.dataOut.data_spc.copy() |
|
588 | 591 | if self.dataOut.data_cspc != None: |
|
589 | 592 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
590 | 593 | self.data_dc = self.dataOut.data_dc.copy() |
|
591 | 594 | |
|
592 | 595 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
593 | 596 | if self.hasAllDataInBuffer(): |
|
594 | 597 | # self.setFirstHeader() |
|
595 | 598 | self.writeNextBlock() |
|
596 | 599 | |
|
597 | 600 | return 1 |
|
598 | 601 | |
|
599 | 602 | |
|
600 | 603 | def __getProcessFlags(self): |
|
601 | 604 | |
|
602 | 605 | processFlags = 0 |
|
603 | 606 | |
|
604 | 607 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
605 | 608 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
606 | 609 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
607 | 610 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
608 | 611 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
609 | 612 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
610 | 613 | |
|
611 | 614 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
612 | 615 | |
|
613 | 616 | |
|
614 | 617 | |
|
615 | 618 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
616 | 619 | PROCFLAG.DATATYPE_SHORT, |
|
617 | 620 | PROCFLAG.DATATYPE_LONG, |
|
618 | 621 | PROCFLAG.DATATYPE_INT64, |
|
619 | 622 | PROCFLAG.DATATYPE_FLOAT, |
|
620 | 623 | PROCFLAG.DATATYPE_DOUBLE] |
|
621 | 624 | |
|
622 | 625 | |
|
623 | 626 | for index in range(len(dtypeList)): |
|
624 | 627 | if self.dataOut.dtype == dtypeList[index]: |
|
625 | 628 | dtypeValue = datatypeValueList[index] |
|
626 | 629 | break |
|
627 | 630 | |
|
628 | 631 | processFlags += dtypeValue |
|
629 | 632 | |
|
630 | 633 | if self.dataOut.flagDecodeData: |
|
631 | 634 | processFlags += PROCFLAG.DECODE_DATA |
|
632 | 635 | |
|
633 | 636 | if self.dataOut.flagDeflipData: |
|
634 | 637 | processFlags += PROCFLAG.DEFLIP_DATA |
|
635 | 638 | |
|
636 | 639 | if self.dataOut.code != None: |
|
637 | 640 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
638 | 641 | |
|
639 | 642 | if self.dataOut.nIncohInt > 1: |
|
640 | 643 | processFlags += PROCFLAG.INCOHERENT_INTEGRATION |
|
641 | 644 | |
|
642 | 645 | if self.dataOut.data_dc != None: |
|
643 | 646 | processFlags += PROCFLAG.SAVE_CHANNELS_DC |
|
644 | 647 | |
|
645 | 648 | return processFlags |
|
646 | 649 | |
|
647 | 650 | |
|
648 | 651 | def __getBlockSize(self): |
|
649 | 652 | ''' |
|
650 | 653 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
651 | 654 | ''' |
|
652 | 655 | |
|
653 | 656 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
654 | 657 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
655 | 658 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
656 | 659 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
657 | 660 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
658 | 661 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
659 | 662 | |
|
660 | 663 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
661 | 664 | datatypeValueList = [1,2,4,8,4,8] |
|
662 | 665 | for index in range(len(dtypeList)): |
|
663 | 666 | if self.dataOut.dtype == dtypeList[index]: |
|
664 | 667 | datatypeValue = datatypeValueList[index] |
|
665 | 668 | break |
|
666 | 669 | |
|
667 | 670 | |
|
668 | 671 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
669 | 672 | |
|
670 | 673 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
671 | 674 | blocksize = (pts2write_SelfSpectra*datatypeValue) |
|
672 | 675 | |
|
673 | 676 | if self.dataOut.data_cspc != None: |
|
674 | 677 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
675 | 678 | blocksize += (pts2write_CrossSpectra*datatypeValue*2) |
|
676 | 679 | |
|
677 | 680 | if self.dataOut.data_dc != None: |
|
678 | 681 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
679 | 682 | blocksize += (pts2write_DCchannels*datatypeValue*2) |
|
680 | 683 | |
|
681 | 684 | blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
682 | 685 | |
|
683 | 686 | return blocksize |
|
684 | 687 | |
|
685 | 688 | def setFirstHeader(self): |
|
686 | 689 | |
|
687 | 690 | """ |
|
688 | 691 | Obtiene una copia del First Header |
|
689 | 692 | |
|
690 | 693 | Affected: |
|
691 | 694 | self.systemHeaderObj |
|
692 | 695 | self.radarControllerHeaderObj |
|
693 | 696 | self.dtype |
|
694 | 697 | |
|
695 | 698 | Return: |
|
696 | 699 | None |
|
697 | 700 | """ |
|
698 | 701 | |
|
699 | 702 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
700 | 703 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
701 | 704 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
702 | 705 | old_code_size = self.dataOut.radarControllerHeaderObj.code_size |
|
703 | 706 | new_code_size = int(numpy.ceil(self.dataOut.nBaud/32.))*self.dataOut.nCode*4 |
|
704 | 707 | self.radarControllerHeaderObj.size = self.radarControllerHeaderObj.size - old_code_size + new_code_size |
|
705 | 708 | |
|
706 | 709 | self.setBasicHeader() |
|
707 | 710 | |
|
708 | 711 | processingHeaderSize = 40 # bytes |
|
709 | 712 | self.processingHeaderObj.dtype = 1 # Spectra |
|
710 | 713 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
711 | 714 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
712 | 715 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
713 | 716 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
714 | 717 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
715 | 718 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
716 | 719 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
717 | 720 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
718 | 721 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT |
|
719 | 722 | |
|
720 | 723 | if self.processingHeaderObj.totalSpectra > 0: |
|
721 | 724 | channelList = [] |
|
722 | 725 | for channel in range(self.dataOut.nChannels): |
|
723 | 726 | channelList.append(channel) |
|
724 | 727 | channelList.append(channel) |
|
725 | 728 | |
|
726 | 729 | pairsList = [] |
|
727 | 730 | if self.dataOut.nPairs > 0: |
|
728 | 731 | for pair in self.dataOut.pairsList: |
|
729 | 732 | pairsList.append(pair[0]) |
|
730 | 733 | pairsList.append(pair[1]) |
|
731 | 734 | |
|
732 | 735 | spectraComb = channelList + pairsList |
|
733 | 736 | spectraComb = numpy.array(spectraComb,dtype="u1") |
|
734 | 737 | self.processingHeaderObj.spectraComb = spectraComb |
|
735 | 738 | sizeOfSpcComb = len(spectraComb) |
|
736 | 739 | processingHeaderSize += sizeOfSpcComb |
|
737 | 740 | |
|
738 | 741 | # The processing header should not have information about code |
|
739 | 742 | # if self.dataOut.code != None: |
|
740 | 743 | # self.processingHeaderObj.code = self.dataOut.code |
|
741 | 744 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
742 | 745 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
743 | 746 | # nCodeSize = 4 # bytes |
|
744 | 747 | # nBaudSize = 4 # bytes |
|
745 | 748 | # codeSize = 4 # bytes |
|
746 | 749 | # sizeOfCode = int(nCodeSize + nBaudSize + codeSize * self.dataOut.nCode * self.dataOut.nBaud) |
|
747 | 750 | # processingHeaderSize += sizeOfCode |
|
748 | 751 | |
|
749 | 752 | if self.processingHeaderObj.nWindows != 0: |
|
750 | 753 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
751 | 754 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
752 | 755 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
753 | 756 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
754 | 757 | sizeOfFirstHeight = 4 |
|
755 | 758 | sizeOfdeltaHeight = 4 |
|
756 | 759 | sizeOfnHeights = 4 |
|
757 | 760 | sizeOfWindows = (sizeOfFirstHeight + sizeOfdeltaHeight + sizeOfnHeights)*self.processingHeaderObj.nWindows |
|
758 | 761 | processingHeaderSize += sizeOfWindows |
|
759 | 762 | |
|
760 | 763 | self.processingHeaderObj.size = processingHeaderSize |
|
761 | 764 |
@@ -1,650 +1,653 | |||
|
1 | 1 | ''' |
|
2 | Created on Jul 2, 2014 | |
|
2 | 3 | |
|
4 | @author: roj-idl71 | |
|
3 | 5 | ''' |
|
6 | ||
|
4 | 7 | import numpy |
|
5 | 8 | |
|
6 | 9 | from jroIO_base import LOCALTIME, JRODataReader, JRODataWriter |
|
7 | from model.proc.jroproc_base import ProcessingUnit, Operation | |
|
8 | from model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
|
9 | from model.data.jrodata import Voltage | |
|
10 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
11 | from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, RadarControllerHeader, ProcessingHeader | |
|
12 | from schainpy.model.data.jrodata import Voltage | |
|
10 | 13 | |
|
11 | 14 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
12 | 15 | """ |
|
13 | 16 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
|
14 | 17 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones: |
|
15 | 18 | perfiles*alturas*canales) son almacenados en la variable "buffer". |
|
16 | 19 | |
|
17 | 20 | perfiles * alturas * canales |
|
18 | 21 | |
|
19 | 22 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
20 | 23 | RadarControllerHeader y Voltage. Los tres primeros se usan para almacenar informacion de la |
|
21 | 24 | cabecera de datos (metadata), y el cuarto (Voltage) para obtener y almacenar un perfil de |
|
22 | 25 | datos desde el "buffer" cada vez que se ejecute el metodo "getData". |
|
23 | 26 | |
|
24 | 27 | Example: |
|
25 | 28 | |
|
26 | 29 | dpath = "/home/myuser/data" |
|
27 | 30 | |
|
28 | 31 | startTime = datetime.datetime(2010,1,20,0,0,0,0,0,0) |
|
29 | 32 | |
|
30 | 33 | endTime = datetime.datetime(2010,1,21,23,59,59,0,0,0) |
|
31 | 34 | |
|
32 | 35 | readerObj = VoltageReader() |
|
33 | 36 | |
|
34 | 37 | readerObj.setup(dpath, startTime, endTime) |
|
35 | 38 | |
|
36 | 39 | while(True): |
|
37 | 40 | |
|
38 | 41 | #to get one profile |
|
39 | 42 | profile = readerObj.getData() |
|
40 | 43 | |
|
41 | 44 | #print the profile |
|
42 | 45 | print profile |
|
43 | 46 | |
|
44 | 47 | #If you want to see all datablock |
|
45 | 48 | print readerObj.datablock |
|
46 | 49 | |
|
47 | 50 | if readerObj.flagNoMoreFiles: |
|
48 | 51 | break |
|
49 | 52 | |
|
50 | 53 | """ |
|
51 | 54 | |
|
52 | 55 | ext = ".r" |
|
53 | 56 | |
|
54 | 57 | optchar = "D" |
|
55 | 58 | dataOut = None |
|
56 | 59 | |
|
57 | 60 | |
|
58 | 61 | def __init__(self): |
|
59 | 62 | """ |
|
60 | 63 | Inicializador de la clase VoltageReader para la lectura de datos de voltage. |
|
61 | 64 | |
|
62 | 65 | Input: |
|
63 | 66 | dataOut : Objeto de la clase Voltage. Este objeto sera utilizado para |
|
64 | 67 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
65 | 68 | (getData). El perfil sera obtenido a partir del buffer de datos, |
|
66 | 69 | si el buffer esta vacio se hara un nuevo proceso de lectura de un |
|
67 | 70 | bloque de datos. |
|
68 | 71 | Si este parametro no es pasado se creara uno internamente. |
|
69 | 72 | |
|
70 | 73 | Variables afectadas: |
|
71 | 74 | self.dataOut |
|
72 | 75 | |
|
73 | 76 | Return: |
|
74 | 77 | None |
|
75 | 78 | """ |
|
76 | 79 | |
|
77 | 80 | ProcessingUnit.__init__(self) |
|
78 | 81 | |
|
79 | 82 | self.isConfig = False |
|
80 | 83 | |
|
81 | 84 | self.datablock = None |
|
82 | 85 | |
|
83 | 86 | self.utc = 0 |
|
84 | 87 | |
|
85 | 88 | self.ext = ".r" |
|
86 | 89 | |
|
87 | 90 | self.optchar = "D" |
|
88 | 91 | |
|
89 | 92 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
90 | 93 | |
|
91 | 94 | self.systemHeaderObj = SystemHeader() |
|
92 | 95 | |
|
93 | 96 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
94 | 97 | |
|
95 | 98 | self.processingHeaderObj = ProcessingHeader() |
|
96 | 99 | |
|
97 | 100 | self.online = 0 |
|
98 | 101 | |
|
99 | 102 | self.fp = None |
|
100 | 103 | |
|
101 | 104 | self.idFile = None |
|
102 | 105 | |
|
103 | 106 | self.dtype = None |
|
104 | 107 | |
|
105 | 108 | self.fileSizeByHeader = None |
|
106 | 109 | |
|
107 | 110 | self.filenameList = [] |
|
108 | 111 | |
|
109 | 112 | self.filename = None |
|
110 | 113 | |
|
111 | 114 | self.fileSize = None |
|
112 | 115 | |
|
113 | 116 | self.firstHeaderSize = 0 |
|
114 | 117 | |
|
115 | 118 | self.basicHeaderSize = 24 |
|
116 | 119 | |
|
117 | 120 | self.pathList = [] |
|
118 | 121 | |
|
119 | 122 | self.filenameList = [] |
|
120 | 123 | |
|
121 | 124 | self.lastUTTime = 0 |
|
122 | 125 | |
|
123 | 126 | self.maxTimeStep = 30 |
|
124 | 127 | |
|
125 | 128 | self.flagNoMoreFiles = 0 |
|
126 | 129 | |
|
127 | 130 | self.set = 0 |
|
128 | 131 | |
|
129 | 132 | self.path = None |
|
130 | 133 | |
|
131 | 134 | self.profileIndex = 2**32-1 |
|
132 | 135 | |
|
133 | 136 | self.delay = 3 #seconds |
|
134 | 137 | |
|
135 | 138 | self.nTries = 3 #quantity tries |
|
136 | 139 | |
|
137 | 140 | self.nFiles = 3 #number of files for searching |
|
138 | 141 | |
|
139 | 142 | self.nReadBlocks = 0 |
|
140 | 143 | |
|
141 | 144 | self.flagIsNewFile = 1 |
|
142 | 145 | |
|
143 | 146 | self.__isFirstTimeOnline = 1 |
|
144 | 147 | |
|
145 | 148 | # self.ippSeconds = 0 |
|
146 | 149 | |
|
147 |
self.flag |
|
|
150 | self.flagDiscontinuousBlock = 0 | |
|
148 | 151 | |
|
149 | 152 | self.flagIsNewBlock = 0 |
|
150 | 153 | |
|
151 | 154 | self.nTotalBlocks = 0 |
|
152 | 155 | |
|
153 | 156 | self.blocksize = 0 |
|
154 | 157 | |
|
155 | 158 | self.dataOut = self.createObjByDefault() |
|
156 | 159 | |
|
157 | 160 | self.nTxs = 1 |
|
158 | 161 | |
|
159 | 162 | self.txIndex = 0 |
|
160 | 163 | |
|
161 | 164 | def createObjByDefault(self): |
|
162 | 165 | |
|
163 | 166 | dataObj = Voltage() |
|
164 | 167 | |
|
165 | 168 | return dataObj |
|
166 | 169 | |
|
167 | 170 | def __hasNotDataInBuffer(self): |
|
168 | 171 | |
|
169 | 172 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
170 | 173 | return 1 |
|
171 | 174 | |
|
172 | 175 | return 0 |
|
173 | 176 | |
|
174 | 177 | |
|
175 | 178 | def getBlockDimension(self): |
|
176 | 179 | """ |
|
177 | 180 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
178 | 181 | |
|
179 | 182 | Affected: |
|
180 | 183 | self.blocksize |
|
181 | 184 | |
|
182 | 185 | Return: |
|
183 | 186 | None |
|
184 | 187 | """ |
|
185 | 188 | pts2read = self.processingHeaderObj.profilesPerBlock * self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels |
|
186 | 189 | self.blocksize = pts2read |
|
187 | 190 | |
|
188 | 191 | |
|
189 | 192 | def readBlock(self): |
|
190 | 193 | """ |
|
191 | 194 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
192 | 195 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
193 | 196 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
194 | 197 | es seteado a 0 |
|
195 | 198 | |
|
196 | 199 | Inputs: |
|
197 | 200 | None |
|
198 | 201 | |
|
199 | 202 | Return: |
|
200 | 203 | None |
|
201 | 204 | |
|
202 | 205 | Affected: |
|
203 | 206 | self.profileIndex |
|
204 | 207 | self.datablock |
|
205 | 208 | self.flagIsNewFile |
|
206 | 209 | self.flagIsNewBlock |
|
207 | 210 | self.nTotalBlocks |
|
208 | 211 | |
|
209 | 212 | Exceptions: |
|
210 | 213 | Si un bloque leido no es un bloque valido |
|
211 | 214 | """ |
|
212 | 215 | current_pointer_location = self.fp.tell() |
|
213 | 216 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
214 | 217 | |
|
215 | 218 | try: |
|
216 | 219 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
217 | 220 | except: |
|
218 | 221 | #print "The read block (%3d) has not enough data" %self.nReadBlocks |
|
219 | 222 | |
|
220 | 223 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
221 | 224 | junk = numpy.fromfile( self.fp, self.dtype, self.blocksize ) |
|
222 | 225 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) |
|
223 | 226 | # return 0 |
|
224 | 227 | |
|
225 | 228 | junk = numpy.transpose(junk, (2,0,1)) |
|
226 | 229 | self.datablock = junk['real'] + junk['imag']*1j |
|
227 | 230 | |
|
228 | 231 | self.profileIndex = 0 |
|
229 | 232 | |
|
230 | 233 | self.flagIsNewFile = 0 |
|
231 | 234 | self.flagIsNewBlock = 1 |
|
232 | 235 | |
|
233 | 236 | self.nTotalBlocks += 1 |
|
234 | 237 | self.nReadBlocks += 1 |
|
235 | 238 | |
|
236 | 239 | return 1 |
|
237 | 240 | |
|
238 | 241 | def getFirstHeader(self): |
|
239 | 242 | |
|
240 | 243 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
241 | 244 | |
|
242 | 245 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
243 | 246 | |
|
244 | 247 | if self.nTxs > 1: |
|
245 | 248 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs |
|
246 | 249 | |
|
247 | 250 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt |
|
248 | ||
|
249 | if self.radarControllerHeaderObj.code != None: | |
|
250 | ||
|
251 | self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
|
252 | ||
|
253 | self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
|
254 | ||
|
255 | self.dataOut.code = self.radarControllerHeaderObj.code | |
|
251 | # | |
|
252 | # if self.radarControllerHeaderObj.code != None: | |
|
253 | # | |
|
254 | # self.dataOut.nCode = self.radarControllerHeaderObj.nCode | |
|
255 | # | |
|
256 | # self.dataOut.nBaud = self.radarControllerHeaderObj.nBaud | |
|
257 | # | |
|
258 | # self.dataOut.code = self.radarControllerHeaderObj.code | |
|
256 | 259 | |
|
257 | 260 | self.dataOut.dtype = self.dtype |
|
258 | 261 | |
|
259 | 262 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
260 | 263 | |
|
261 | 264 | if self.processingHeaderObj.nHeights % self.nTxs != 0: |
|
262 | 265 | raise ValueError, "nTxs (%d) should be a multiple of nHeights (%d)" %(self.nTxs, self.processingHeaderObj.nHeights) |
|
263 | 266 | |
|
264 | 267 | xf = self.processingHeaderObj.firstHeight + int(self.processingHeaderObj.nHeights/self.nTxs)*self.processingHeaderObj.deltaHeight |
|
265 | 268 | |
|
266 | 269 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
267 | 270 | |
|
268 | 271 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
269 | 272 | |
|
270 | 273 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
271 | 274 | |
|
272 | 275 | self.dataOut.flagShiftFFT = False |
|
273 | 276 | |
|
274 | 277 | self.dataOut.flagDecodeData = False #asumo q la data no esta decodificada |
|
275 | 278 | |
|
276 | 279 | self.dataOut.flagDeflipData = False #asumo q la data no esta sin flip |
|
277 | 280 | |
|
278 | 281 | self.dataOut.flagShiftFFT = False |
|
279 | 282 | |
|
280 | 283 | def getData(self): |
|
281 | 284 | """ |
|
282 | 285 | getData obtiene una unidad de datos del buffer de lectura, un perfil, y la copia al objeto self.dataOut |
|
283 | 286 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos |
|
284 | 287 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando |
|
285 | 288 | "readNextBlock" |
|
286 | 289 | |
|
287 | 290 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. |
|
288 | 291 | |
|
289 | 292 | Return: |
|
290 | 293 | |
|
291 | 294 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex |
|
292 | 295 | es igual al total de perfiles leidos desde el archivo. |
|
293 | 296 | |
|
294 | 297 | Si self.getByBlock == False: |
|
295 | 298 | |
|
296 | 299 | self.dataOut.data = buffer[:, thisProfile, :] |
|
297 | 300 | |
|
298 | 301 | shape = [nChannels, nHeis] |
|
299 | 302 | |
|
300 | 303 | Si self.getByBlock == True: |
|
301 | 304 | |
|
302 | 305 | self.dataOut.data = buffer[:, :, :] |
|
303 | 306 | |
|
304 | 307 | shape = [nChannels, nProfiles, nHeis] |
|
305 | 308 | |
|
306 | 309 | Variables afectadas: |
|
307 | 310 | self.dataOut |
|
308 | 311 | self.profileIndex |
|
309 | 312 | |
|
310 | 313 | Affected: |
|
311 | 314 | self.dataOut |
|
312 | 315 | self.profileIndex |
|
313 |
self.flag |
|
|
316 | self.flagDiscontinuousBlock | |
|
314 | 317 | self.flagIsNewBlock |
|
315 | 318 | """ |
|
316 | 319 | |
|
317 | 320 | if self.flagNoMoreFiles: |
|
318 | 321 | self.dataOut.flagNoData = True |
|
319 | 322 | print 'Process finished' |
|
320 | 323 | return 0 |
|
321 | 324 | |
|
322 |
self.flag |
|
|
325 | self.flagDiscontinuousBlock = 0 | |
|
323 | 326 | self.flagIsNewBlock = 0 |
|
324 | 327 | |
|
325 | 328 | if self.__hasNotDataInBuffer(): |
|
326 | 329 | |
|
327 | 330 | if not( self.readNextBlock() ): |
|
328 | 331 | return 0 |
|
329 | 332 | |
|
330 | 333 | self.getFirstHeader() |
|
331 | 334 | |
|
332 | 335 | if self.datablock == None: |
|
333 | 336 | self.dataOut.flagNoData = True |
|
334 | 337 | return 0 |
|
335 | 338 | |
|
336 | 339 | if not self.getByBlock: |
|
337 | 340 | |
|
338 | 341 | """ |
|
339 | 342 | Return profile by profile |
|
340 | 343 | |
|
341 | 344 | If nTxs > 1 then one profile is divided by nTxs and number of total |
|
342 | 345 | blocks is increased by nTxs (nProfiles *= nTxs) |
|
343 | 346 | """ |
|
344 | 347 | if self.nTxs == 1: |
|
345 | 348 | self.dataOut.flagDataAsBlock = False |
|
346 | 349 | self.dataOut.data = self.datablock[:,self.profileIndex,:] |
|
347 | 350 | self.dataOut.profileIndex = self.profileIndex |
|
348 | 351 | |
|
349 | 352 | self.profileIndex += 1 |
|
350 | 353 | |
|
351 | 354 | else: |
|
352 | 355 | self.dataOut.flagDataAsBlock = False |
|
353 | 356 | |
|
354 | 357 | iniHei_ForThisTx = (self.txIndex)*int(self.processingHeaderObj.nHeights/self.nTxs) |
|
355 | 358 | endHei_ForThisTx = (self.txIndex+1)*int(self.processingHeaderObj.nHeights/self.nTxs) |
|
356 | 359 | |
|
357 | 360 | # print iniHei_ForThisTx, endHei_ForThisTx |
|
358 | 361 | |
|
359 | 362 | self.dataOut.data = self.datablock[:, self.profileIndex, iniHei_ForThisTx:endHei_ForThisTx] |
|
360 | 363 | self.dataOut.profileIndex = self.profileIndex*self.nTxs + self.txIndex |
|
361 | 364 | |
|
362 | 365 | self.txIndex += 1 |
|
363 | 366 | |
|
364 | 367 | if self.txIndex == self.nTxs: |
|
365 | 368 | self.txIndex = 0 |
|
366 | 369 | self.profileIndex += 1 |
|
367 | 370 | |
|
368 | 371 | else: |
|
369 | 372 | """ |
|
370 | 373 | Return all block |
|
371 | 374 | """ |
|
372 | 375 | self.dataOut.flagDataAsBlock = True |
|
373 | 376 | self.dataOut.data = self.datablock |
|
374 | 377 | self.dataOut.profileIndex = self.processingHeaderObj.profilesPerBlock - 1 |
|
375 | 378 | |
|
376 | 379 | self.profileIndex = self.processingHeaderObj.profilesPerBlock - 1 |
|
377 | 380 | |
|
378 | 381 | self.dataOut.flagNoData = False |
|
379 | 382 | |
|
380 | 383 | self.getBasicHeader() |
|
381 | 384 | |
|
382 | 385 | self.dataOut.realtime = self.online |
|
383 | 386 | |
|
384 | 387 | return self.dataOut.data |
|
385 | 388 | |
|
386 | 389 | class VoltageWriter(JRODataWriter, Operation): |
|
387 | 390 | """ |
|
388 | 391 | Esta clase permite escribir datos de voltajes a archivos procesados (.r). La escritura |
|
389 | 392 | de los datos siempre se realiza por bloques. |
|
390 | 393 | """ |
|
391 | 394 | |
|
392 | 395 | ext = ".r" |
|
393 | 396 | |
|
394 | 397 | optchar = "D" |
|
395 | 398 | |
|
396 | 399 | shapeBuffer = None |
|
397 | 400 | |
|
398 | 401 | |
|
399 | 402 | def __init__(self): |
|
400 | 403 | """ |
|
401 | 404 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
|
402 | 405 | |
|
403 | 406 | Affected: |
|
404 | 407 | self.dataOut |
|
405 | 408 | |
|
406 | 409 | Return: None |
|
407 | 410 | """ |
|
408 | 411 | Operation.__init__(self) |
|
409 | 412 | |
|
410 | 413 | self.nTotalBlocks = 0 |
|
411 | 414 | |
|
412 | 415 | self.profileIndex = 0 |
|
413 | 416 | |
|
414 | 417 | self.isConfig = False |
|
415 | 418 | |
|
416 | 419 | self.fp = None |
|
417 | 420 | |
|
418 | 421 | self.flagIsNewFile = 1 |
|
419 | 422 | |
|
420 | 423 | self.nTotalBlocks = 0 |
|
421 | 424 | |
|
422 | 425 | self.flagIsNewBlock = 0 |
|
423 | 426 | |
|
424 | 427 | self.setFile = None |
|
425 | 428 | |
|
426 | 429 | self.dtype = None |
|
427 | 430 | |
|
428 | 431 | self.path = None |
|
429 | 432 | |
|
430 | 433 | self.filename = None |
|
431 | 434 | |
|
432 | 435 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
433 | 436 | |
|
434 | 437 | self.systemHeaderObj = SystemHeader() |
|
435 | 438 | |
|
436 | 439 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
437 | 440 | |
|
438 | 441 | self.processingHeaderObj = ProcessingHeader() |
|
439 | 442 | |
|
440 | 443 | def hasAllDataInBuffer(self): |
|
441 | 444 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock: |
|
442 | 445 | return 1 |
|
443 | 446 | return 0 |
|
444 | 447 | |
|
445 | 448 | |
|
446 | 449 | def setBlockDimension(self): |
|
447 | 450 | """ |
|
448 | 451 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
|
449 | 452 | |
|
450 | 453 | Affected: |
|
451 | 454 | self.shape_spc_Buffer |
|
452 | 455 | self.shape_cspc_Buffer |
|
453 | 456 | self.shape_dc_Buffer |
|
454 | 457 | |
|
455 | 458 | Return: None |
|
456 | 459 | """ |
|
457 | 460 | self.shapeBuffer = (self.processingHeaderObj.profilesPerBlock, |
|
458 | 461 | self.processingHeaderObj.nHeights, |
|
459 | 462 | self.systemHeaderObj.nChannels) |
|
460 | 463 | |
|
461 | 464 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
462 | 465 | self.processingHeaderObj.profilesPerBlock, |
|
463 | 466 | self.processingHeaderObj.nHeights), |
|
464 | 467 | dtype=numpy.dtype('complex64')) |
|
465 | ||
|
466 | 468 | |
|
467 | 469 | def writeBlock(self): |
|
468 | 470 | """ |
|
469 | 471 | Escribe el buffer en el file designado |
|
470 | 472 | |
|
471 | 473 | Affected: |
|
472 | 474 | self.profileIndex |
|
473 | 475 | self.flagIsNewFile |
|
474 | 476 | self.flagIsNewBlock |
|
475 | 477 | self.nTotalBlocks |
|
476 | 478 | self.blockIndex |
|
477 | 479 | |
|
478 | 480 | Return: None |
|
479 | 481 | """ |
|
480 | 482 | data = numpy.zeros( self.shapeBuffer, self.dtype ) |
|
481 | 483 | |
|
482 | 484 | junk = numpy.transpose(self.datablock, (1,2,0)) |
|
483 | 485 | |
|
484 | 486 | data['real'] = junk.real |
|
485 | 487 | data['imag'] = junk.imag |
|
486 | 488 | |
|
487 | 489 | data = data.reshape( (-1) ) |
|
488 | 490 | |
|
489 | 491 | data.tofile( self.fp ) |
|
490 | 492 | |
|
491 | 493 | self.datablock.fill(0) |
|
492 | 494 | |
|
493 | 495 | self.profileIndex = 0 |
|
494 | 496 | self.flagIsNewFile = 0 |
|
495 | 497 | self.flagIsNewBlock = 1 |
|
496 | 498 | |
|
497 | 499 | self.blockIndex += 1 |
|
498 | 500 | self.nTotalBlocks += 1 |
|
499 | 501 | |
|
502 | print "[Writing] Block = ", self.blockIndex | |
|
503 | ||
|
500 | 504 | def putData(self): |
|
501 | 505 | """ |
|
502 | 506 | Setea un bloque de datos y luego los escribe en un file |
|
503 | 507 | |
|
504 | 508 | Affected: |
|
505 | 509 | self.flagIsNewBlock |
|
506 | 510 | self.profileIndex |
|
507 | 511 | |
|
508 | 512 | Return: |
|
509 | 513 | 0 : Si no hay data o no hay mas files que puedan escribirse |
|
510 | 514 | 1 : Si se escribio la data de un bloque en un file |
|
511 | 515 | """ |
|
512 | 516 | if self.dataOut.flagNoData: |
|
513 | 517 | return 0 |
|
514 | 518 | |
|
515 | 519 | self.flagIsNewBlock = 0 |
|
516 | 520 | |
|
517 |
if self.dataOut.flag |
|
|
518 | ||
|
521 | if self.dataOut.flagDiscontinuousBlock: | |
|
519 | 522 | self.datablock.fill(0) |
|
520 | 523 | self.profileIndex = 0 |
|
521 | 524 | self.setNextFile() |
|
522 | 525 | |
|
523 | 526 | if self.profileIndex == 0: |
|
524 | 527 | self.setBasicHeader() |
|
525 | 528 | |
|
526 | 529 | self.datablock[:,self.profileIndex,:] = self.dataOut.data |
|
527 | 530 | |
|
528 | 531 | self.profileIndex += 1 |
|
529 | 532 | |
|
530 | 533 | if self.hasAllDataInBuffer(): |
|
531 | 534 | #if self.flagIsNewFile: |
|
532 | 535 | self.writeNextBlock() |
|
533 | 536 | # self.setFirstHeader() |
|
534 | 537 | |
|
535 | 538 | return 1 |
|
536 | 539 | |
|
537 | 540 | def __getProcessFlags(self): |
|
538 | 541 | |
|
539 | 542 | processFlags = 0 |
|
540 | 543 | |
|
541 | 544 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
542 | 545 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
543 | 546 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
544 | 547 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
545 | 548 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
546 | 549 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
547 | 550 | |
|
548 | 551 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
549 | 552 | |
|
550 | 553 | |
|
551 | 554 | |
|
552 | 555 | datatypeValueList = [PROCFLAG.DATATYPE_CHAR, |
|
553 | 556 | PROCFLAG.DATATYPE_SHORT, |
|
554 | 557 | PROCFLAG.DATATYPE_LONG, |
|
555 | 558 | PROCFLAG.DATATYPE_INT64, |
|
556 | 559 | PROCFLAG.DATATYPE_FLOAT, |
|
557 | 560 | PROCFLAG.DATATYPE_DOUBLE] |
|
558 | 561 | |
|
559 | 562 | |
|
560 | 563 | for index in range(len(dtypeList)): |
|
561 | 564 | if self.dataOut.dtype == dtypeList[index]: |
|
562 | 565 | dtypeValue = datatypeValueList[index] |
|
563 | 566 | break |
|
564 | 567 | |
|
565 | 568 | processFlags += dtypeValue |
|
566 | 569 | |
|
567 | 570 | if self.dataOut.flagDecodeData: |
|
568 | 571 | processFlags += PROCFLAG.DECODE_DATA |
|
569 | 572 | |
|
570 | 573 | if self.dataOut.flagDeflipData: |
|
571 | 574 | processFlags += PROCFLAG.DEFLIP_DATA |
|
572 | 575 | |
|
573 | 576 | if self.dataOut.code != None: |
|
574 | 577 | processFlags += PROCFLAG.DEFINE_PROCESS_CODE |
|
575 | 578 | |
|
576 | 579 | if self.dataOut.nCohInt > 1: |
|
577 | 580 | processFlags += PROCFLAG.COHERENT_INTEGRATION |
|
578 | 581 | |
|
579 | 582 | return processFlags |
|
580 | 583 | |
|
581 | 584 | |
|
582 | 585 | def __getBlockSize(self): |
|
583 | 586 | ''' |
|
584 | 587 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Voltage |
|
585 | 588 | ''' |
|
586 | 589 | |
|
587 | 590 | dtype0 = numpy.dtype([('real','<i1'),('imag','<i1')]) |
|
588 | 591 | dtype1 = numpy.dtype([('real','<i2'),('imag','<i2')]) |
|
589 | 592 | dtype2 = numpy.dtype([('real','<i4'),('imag','<i4')]) |
|
590 | 593 | dtype3 = numpy.dtype([('real','<i8'),('imag','<i8')]) |
|
591 | 594 | dtype4 = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
592 | 595 | dtype5 = numpy.dtype([('real','<f8'),('imag','<f8')]) |
|
593 | 596 | |
|
594 | 597 | dtypeList = [dtype0, dtype1, dtype2, dtype3, dtype4, dtype5] |
|
595 | 598 | datatypeValueList = [1,2,4,8,4,8] |
|
596 | 599 | for index in range(len(dtypeList)): |
|
597 | 600 | if self.dataOut.dtype == dtypeList[index]: |
|
598 | 601 | datatypeValue = datatypeValueList[index] |
|
599 | 602 | break |
|
600 | 603 | |
|
601 | 604 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * self.profilesPerBlock * datatypeValue * 2) |
|
602 | 605 | |
|
603 | 606 | return blocksize |
|
604 | 607 | |
|
605 | 608 | def setFirstHeader(self): |
|
606 | 609 | |
|
607 | 610 | """ |
|
608 | 611 | Obtiene una copia del First Header |
|
609 | 612 | |
|
610 | 613 | Affected: |
|
611 | 614 | self.systemHeaderObj |
|
612 | 615 | self.radarControllerHeaderObj |
|
613 | 616 | self.dtype |
|
614 | 617 | |
|
615 | 618 | Return: |
|
616 | 619 | None |
|
617 | 620 | """ |
|
618 | 621 | |
|
619 | 622 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
620 | 623 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
621 | 624 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
622 | 625 | |
|
623 | 626 | self.setBasicHeader() |
|
624 | 627 | |
|
625 | 628 | processingHeaderSize = 40 # bytes |
|
626 | 629 | self.processingHeaderObj.dtype = 0 # Voltage |
|
627 | 630 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
628 | 631 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
629 | 632 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
630 | 633 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
631 | 634 | self.processingHeaderObj.processFlags = self.__getProcessFlags() |
|
632 | 635 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
633 | 636 | self.processingHeaderObj.nIncohInt = 1 # Cuando la data de origen es de tipo Voltage |
|
634 | 637 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage |
|
635 | 638 | |
|
636 | 639 | # if self.dataOut.code != None: |
|
637 | 640 | # self.processingHeaderObj.code = self.dataOut.code |
|
638 | 641 | # self.processingHeaderObj.nCode = self.dataOut.nCode |
|
639 | 642 | # self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
640 | 643 | # codesize = int(8 + 4 * self.dataOut.nCode * self.dataOut.nBaud) |
|
641 | 644 | # processingHeaderSize += codesize |
|
642 | 645 | |
|
643 | 646 | if self.processingHeaderObj.nWindows != 0: |
|
644 | 647 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
645 | 648 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
646 | 649 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
647 | 650 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
648 | 651 | processingHeaderSize += 12 |
|
649 | 652 | |
|
650 | 653 | self.processingHeaderObj.size = processingHeaderSize No newline at end of file |
@@ -0,0 +1,12 | |||
|
1 | ''' | |
|
2 | ||
|
3 | $Author: murco $ | |
|
4 | $Id: Processor.py 1 2012-11-12 18:56:07Z murco $ | |
|
5 | ''' | |
|
6 | ||
|
7 | from jroproc_voltage import * | |
|
8 | from jroproc_spectra import * | |
|
9 | from jroproc_heispectra import * | |
|
10 | from jroproc_amisr import * | |
|
11 | from jroproc_correlation import * | |
|
12 | from jroproc_parameters import * No newline at end of file |
@@ -1,10 +1,10 | |||
|
1 | import numpy | |
|
1 | # import numpy | |
|
2 | 2 | cimport numpy |
|
3 | 3 | |
|
4 | 4 | def decoder(numpy.ndarray[numpy.complex_t, ndim=2] fft_code, numpy.ndarray[numpy.complex_t, ndim=2] data): |
|
5 | 5 | |
|
6 | 6 | fft_data = numpy.fft.fft(data, axis=1) |
|
7 | 7 | conv = fft_data*fft_code |
|
8 | 8 | data = numpy.fft.ifft(conv, axis=1) |
|
9 | 9 | |
|
10 | 10 | return data No newline at end of file |
@@ -1,141 +1,141 | |||
|
1 | 1 | ''' |
|
2 | 2 | @author: Daniel Suarez |
|
3 | 3 | ''' |
|
4 | 4 | import numpy |
|
5 | 5 | from jroproc_base import ProcessingUnit, Operation |
|
6 | from model.data.jroamisr import AMISR | |
|
6 | from schainpy.model.data.jroamisr import AMISR | |
|
7 | 7 | |
|
8 | 8 | class AMISRProc(ProcessingUnit): |
|
9 | 9 | def __init__(self): |
|
10 | 10 | ProcessingUnit.__init__(self) |
|
11 | 11 | self.objectDict = {} |
|
12 | 12 | self.dataOut = AMISR() |
|
13 | 13 | |
|
14 | 14 | def run(self): |
|
15 | 15 | if self.dataIn.type == 'AMISR': |
|
16 | 16 | self.dataOut.copy(self.dataIn) |
|
17 | 17 | |
|
18 | 18 | |
|
19 | 19 | class PrintInfo(Operation): |
|
20 | 20 | def __init__(self): |
|
21 | 21 | self.__isPrinted = False |
|
22 | 22 | |
|
23 | 23 | def run(self, dataOut): |
|
24 | 24 | |
|
25 | 25 | if not self.__isPrinted: |
|
26 | 26 | print 'Number of Records by File: %d'%dataOut.nRecords |
|
27 | 27 | print 'Number of Pulses: %d'%dataOut.nProfiles |
|
28 | 28 | print 'Number of Pulses by Frame: %d'%dataOut.npulseByFrame |
|
29 | 29 | print 'Number of Samples by Pulse: %d'%len(dataOut.heightList) |
|
30 | 30 | print 'Ipp Seconds: %f'%dataOut.ippSeconds |
|
31 | 31 | print 'Number of Beams: %d'%dataOut.nBeams |
|
32 | 32 | print 'BeamCodes:' |
|
33 | 33 | beamStrList = ['Beam %d -> Code=%d, azimuth=%2.2f, zenith=%2.2f, gain=%2.2f'%(k,v[0],v[1],v[2],v[3]) for k,v in dataOut.beamCodeDict.items()] |
|
34 | 34 | for b in beamStrList: |
|
35 | 35 | print b |
|
36 | 36 | self.__isPrinted = True |
|
37 | 37 | |
|
38 | 38 | return |
|
39 | 39 | |
|
40 | 40 | |
|
41 | 41 | class BeamSelector(Operation): |
|
42 | 42 | profileIndex = None |
|
43 | 43 | nProfiles = None |
|
44 | 44 | |
|
45 | 45 | def __init__(self): |
|
46 | 46 | |
|
47 | 47 | self.profileIndex = 0 |
|
48 | 48 | self.__isConfig = False |
|
49 | 49 | |
|
50 | 50 | def incIndex(self): |
|
51 | 51 | self.profileIndex += 1 |
|
52 | 52 | |
|
53 | 53 | if self.profileIndex >= self.nProfiles: |
|
54 | 54 | self.profileIndex = 0 |
|
55 | 55 | |
|
56 | 56 | def isProfileInRange(self, minIndex, maxIndex): |
|
57 | 57 | |
|
58 | 58 | if self.profileIndex < minIndex: |
|
59 | 59 | return False |
|
60 | 60 | |
|
61 | 61 | if self.profileIndex > maxIndex: |
|
62 | 62 | return False |
|
63 | 63 | |
|
64 | 64 | return True |
|
65 | 65 | |
|
66 | 66 | def isProfileInList(self, profileList): |
|
67 | 67 | |
|
68 | 68 | if self.profileIndex not in profileList: |
|
69 | 69 | return False |
|
70 | 70 | |
|
71 | 71 | return True |
|
72 | 72 | |
|
73 | 73 | def run(self, dataOut, beam=None): |
|
74 | 74 | |
|
75 | 75 | dataOut.flagNoData = True |
|
76 | 76 | |
|
77 | 77 | if not(self.__isConfig): |
|
78 | 78 | |
|
79 | 79 | self.nProfiles = dataOut.nProfiles |
|
80 | 80 | self.profileIndex = dataOut.profileIndex |
|
81 | 81 | self.__isConfig = True |
|
82 | 82 | |
|
83 | 83 | if beam != None: |
|
84 | 84 | if self.isProfileInList(dataOut.beamRangeDict[beam]): |
|
85 | 85 | beamInfo = dataOut.beamCodeDict[beam] |
|
86 | 86 | dataOut.azimuth = beamInfo[1] |
|
87 | 87 | dataOut.zenith = beamInfo[2] |
|
88 | 88 | dataOut.gain = beamInfo[3] |
|
89 | 89 | dataOut.flagNoData = False |
|
90 | 90 | |
|
91 | 91 | self.incIndex() |
|
92 | 92 | return 1 |
|
93 | 93 | |
|
94 | 94 | else: |
|
95 | 95 | raise ValueError, "BeamSelector needs beam value" |
|
96 | 96 | |
|
97 | 97 | return 0 |
|
98 | 98 | |
|
99 | 99 | class ProfileToChannels(Operation): |
|
100 | 100 | |
|
101 | 101 | def __init__(self): |
|
102 | 102 | self.__isConfig = False |
|
103 | 103 | self.__counter_chan = 0 |
|
104 | 104 | self.buffer = None |
|
105 | 105 | |
|
106 | 106 | def isProfileInList(self, profileList): |
|
107 | 107 | |
|
108 | 108 | if self.profileIndex not in profileList: |
|
109 | 109 | return False |
|
110 | 110 | |
|
111 | 111 | return True |
|
112 | 112 | |
|
113 | 113 | def run(self, dataOut): |
|
114 | 114 | |
|
115 | 115 | dataOut.flagNoData = True |
|
116 | 116 | |
|
117 | 117 | if not(self.__isConfig): |
|
118 | 118 | nchannels = len(dataOut.beamRangeDict.keys()) |
|
119 | 119 | nsamples = dataOut.nHeights |
|
120 | 120 | self.buffer = numpy.zeros((nchannels, nsamples), dtype = 'complex128') |
|
121 | 121 | dataOut.beam.codeList = [dataOut.beamCodeDict[x][0] for x in range(nchannels)] |
|
122 | 122 | dataOut.beam.azimuthList = [dataOut.beamCodeDict[x][1] for x in range(nchannels)] |
|
123 | 123 | dataOut.beam.zenithList = [dataOut.beamCodeDict[x][2] for x in range(nchannels)] |
|
124 | 124 | self.__isConfig = True |
|
125 | 125 | |
|
126 | 126 | for i in range(self.buffer.shape[0]): |
|
127 | 127 | if dataOut.profileIndex in dataOut.beamRangeDict[i]: |
|
128 | 128 | self.buffer[i,:] = dataOut.data |
|
129 | 129 | break |
|
130 | 130 | |
|
131 | 131 | |
|
132 | 132 | self.__counter_chan += 1 |
|
133 | 133 | |
|
134 | 134 | if self.__counter_chan >= self.buffer.shape[0]: |
|
135 | 135 | self.__counter_chan = 0 |
|
136 | 136 | dataOut.data = self.buffer.copy() |
|
137 | 137 | dataOut.channelList = range(self.buffer.shape[0]) |
|
138 | 138 | self.__isConfig = False |
|
139 | 139 | dataOut.flagNoData = False |
|
140 | 140 | pass |
|
141 | 141 | No newline at end of file |
@@ -1,253 +1,268 | |||
|
1 | 1 | ''' |
|
2 | ||
|
3 | $Author: murco $ | |
|
4 | $Id: jroproc_base.py 1 2012-11-12 18:56:07Z murco $ | |
|
2 | 5 | ''' |
|
3 | 6 | |
|
4 | class ProcessingUnit: | |
|
7 | class ProcessingUnit(object): | |
|
5 | 8 | |
|
6 | 9 | """ |
|
7 | 10 | Esta es la clase base para el procesamiento de datos. |
|
8 | 11 | |
|
9 | 12 | Contiene el metodo "call" para llamar operaciones. Las operaciones pueden ser: |
|
10 | 13 | - Metodos internos (callMethod) |
|
11 | 14 | - Objetos del tipo Operation (callObject). Antes de ser llamados, estos objetos |
|
12 | 15 | tienen que ser agreagados con el metodo "add". |
|
13 | 16 | |
|
14 | 17 | """ |
|
15 | 18 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
16 | 19 | dataIn = None |
|
17 | 20 | dataInList = [] |
|
18 | 21 | |
|
19 | 22 | # objeto de datos de entrada (Voltage, Spectra o Correlation) |
|
20 | 23 | dataOut = None |
|
21 | 24 | |
|
22 | 25 | operations2RunDict = None |
|
23 | 26 | |
|
24 | 27 | isConfig = False |
|
25 | 28 | |
|
26 | 29 | |
|
27 | 30 | def __init__(self): |
|
28 | 31 | |
|
29 | 32 | self.dataIn = None |
|
30 | 33 | self.dataInList = [] |
|
31 | 34 | |
|
32 | 35 | self.dataOut = {} |
|
33 | 36 | |
|
34 | 37 | self.operations2RunDict = {} |
|
35 | 38 | |
|
36 | 39 | self.isConfig = False |
|
37 | 40 | |
|
38 | 41 | def addOperation(self, opObj, objId): |
|
39 | 42 | |
|
40 | 43 | """ |
|
41 | 44 | Agrega un objeto del tipo "Operation" (opObj) a la lista de objetos "self.objectList" y retorna el |
|
42 | 45 | identificador asociado a este objeto. |
|
43 | 46 | |
|
44 | 47 | Input: |
|
45 | 48 | |
|
46 | 49 | object : objeto de la clase "Operation" |
|
47 | 50 | |
|
48 | 51 | Return: |
|
49 | 52 | |
|
50 | 53 | objId : identificador del objeto, necesario para ejecutar la operacion |
|
51 | 54 | """ |
|
52 | 55 | |
|
53 | 56 | self.operations2RunDict[objId] = opObj |
|
54 | 57 | |
|
55 | 58 | return objId |
|
56 | 59 | |
|
57 | 60 | def operation(self, **kwargs): |
|
58 | 61 | |
|
59 | 62 | """ |
|
60 | 63 | Operacion directa sobre la data (dataOut.data). Es necesario actualizar los valores de los |
|
61 | 64 | atributos del objeto dataOut |
|
62 | 65 | |
|
63 | 66 | Input: |
|
64 | 67 | |
|
65 | 68 | **kwargs : Diccionario de argumentos de la funcion a ejecutar |
|
66 | 69 | """ |
|
67 | 70 | |
|
68 | 71 | raise ValueError, "ImplementedError" |
|
69 | 72 | |
|
70 | 73 | def callMethod(self, name, **kwargs): |
|
71 | 74 | |
|
72 | 75 | """ |
|
73 | 76 | Ejecuta el metodo con el nombre "name" y con argumentos **kwargs de la propia clase. |
|
74 | 77 | |
|
75 | 78 | Input: |
|
76 | 79 | name : nombre del metodo a ejecutar |
|
77 | 80 | |
|
78 | 81 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
79 | 82 | |
|
80 | 83 | """ |
|
84 | ||
|
85 | #Checking the inputs | |
|
81 | 86 | if name == 'run': |
|
82 | 87 | |
|
83 | 88 | if not self.checkInputs(): |
|
84 | 89 | self.dataOut.flagNoData = True |
|
85 | 90 | return False |
|
86 | 91 | else: |
|
87 | 92 | #Si no es un metodo RUN la entrada es la misma dataOut (interna) |
|
88 | 93 | if self.dataOut.isEmpty(): |
|
89 | 94 | return False |
|
90 | 95 | |
|
91 | 96 | #Getting the pointer to method |
|
92 | 97 | methodToCall = getattr(self, name) |
|
93 | 98 | |
|
94 | 99 | #Executing the self method |
|
95 | 100 | methodToCall(**kwargs) |
|
96 | 101 | |
|
97 | 102 | #Checkin the outputs |
|
98 | 103 | |
|
99 | 104 | # if name == 'run': |
|
100 | 105 | # pass |
|
101 | 106 | # else: |
|
102 | 107 | # pass |
|
103 | 108 | # |
|
104 | 109 | # if name != 'run': |
|
105 | 110 | # return True |
|
106 | 111 | |
|
107 | 112 | if self.dataOut.isEmpty(): |
|
108 | 113 | return False |
|
109 | 114 | |
|
110 | 115 | return True |
|
111 | 116 | |
|
112 | 117 | def callObject(self, objId, **kwargs): |
|
113 | 118 | |
|
114 | 119 | """ |
|
115 | 120 | Ejecuta la operacion asociada al identificador del objeto "objId" |
|
116 | 121 | |
|
117 | 122 | Input: |
|
118 | 123 | |
|
119 | 124 | objId : identificador del objeto a ejecutar |
|
120 | 125 | |
|
121 | 126 | **kwargs : diccionario con los nombres y valores de la funcion a ejecutar. |
|
122 | 127 | |
|
123 | 128 | Return: |
|
124 | 129 | |
|
125 | 130 | None |
|
126 | 131 | """ |
|
127 | 132 | |
|
128 | 133 | if self.dataOut.isEmpty(): |
|
129 | 134 | return False |
|
130 | 135 | |
|
131 | 136 | externalProcObj = self.operations2RunDict[objId] |
|
132 | 137 | |
|
133 | 138 | externalProcObj.run(self.dataOut, **kwargs) |
|
134 | 139 | |
|
135 | 140 | return True |
|
136 | 141 | |
|
137 | 142 | def call(self, opType, opName=None, opId=None, **kwargs): |
|
138 | 143 | |
|
139 | 144 | """ |
|
140 |
Return True si ejecuta la operacion |
|
|
141 | argumentos "**kwargs". False si la operacion no se ha ejecutado. | |
|
142 | La operacion puede ser de dos tipos: | |
|
145 | Return True si ejecuta la operacion interna nombrada "opName" o la operacion externa | |
|
146 | identificada con el id "opId"; con los argumentos "**kwargs". | |
|
143 | 147 | |
|
144 | 1. Un metodo propio de esta clase: | |
|
145 |
|
|
|
146 | operation.type = "self" | |
|
148 | False si la operacion no se ha ejecutado. | |
|
149 | ||
|
150 | Input: | |
|
151 | ||
|
152 | opType : Puede ser "self" o "external" | |
|
153 | ||
|
154 | La operacion puede ser de dos tipos (callMethod or callObject): | |
|
147 | 155 | |
|
148 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
|
149 | operation.type = "other". | |
|
156 | 1. Un metodo propio de esta clase: | |
|
157 | ||
|
158 | opType = "self" | |
|
150 | 159 | |
|
151 |
|
|
|
152 | "addOperation" e identificado con el operation.id | |
|
153 | ||
|
160 | 2. El metodo "run" de un objeto del tipo Operation o de un derivado de ella: | |
|
161 | ||
|
162 | opType = "other" or "external". | |
|
154 | 163 | |
|
155 | con el id de la operacion. | |
|
156 | ||
|
157 |
|
|
|
164 | opName : Si la operacion es interna (opType = 'self'), entonces el "opName" sera | |
|
165 | usada para llamar a un metodo interno de la clase Processing | |
|
166 | ||
|
167 | opId : Si la operacion es externa (opType = 'other'), entonces el "opId" sera | |
|
168 | usada para llamar al metodo "run" de la clase Operation registrada con ese Id | |
|
158 | 169 | |
|
159 | Operation : Objeto del tipo operacion con los atributos: name, type y id. | |
|
170 | Exception: | |
|
171 | Este objeto de tipo Operation debe de haber sido agregado antes con el metodo: | |
|
172 | "addOperation" e identificado con el valor "opId" = el id de la operacion. | |
|
173 | De lo contrario retornara un error del tipo IOError | |
|
160 | 174 | |
|
161 | 175 | """ |
|
162 | 176 | |
|
163 | 177 | if opType == 'self': |
|
164 | 178 | |
|
165 | 179 | if not opName: |
|
166 | 180 | raise IOError, "opName parameter should be defined" |
|
167 | 181 | |
|
168 | 182 | sts = self.callMethod(opName, **kwargs) |
|
169 | 183 | |
|
170 | 184 | if opType == 'other' or opType == 'external': |
|
171 | 185 | |
|
172 | 186 | if not opId: |
|
173 | 187 | raise IOError, "opId parameter should be defined" |
|
174 | 188 | |
|
175 | 189 | if opId not in self.operations2RunDict.keys(): |
|
176 | 190 | raise IOError, "This id operation have not been registered" |
|
177 | 191 | |
|
178 | 192 | sts = self.callObject(opId, **kwargs) |
|
179 | 193 | |
|
180 | 194 | return sts |
|
181 | 195 | |
|
182 | 196 | def setInput(self, dataIn): |
|
183 | 197 | |
|
184 | 198 | self.dataIn = dataIn |
|
185 | 199 | self.dataInList.append(dataIn) |
|
186 | 200 | |
|
187 | 201 | def getOutputObj(self): |
|
188 | 202 | |
|
189 | 203 | return self.dataOut |
|
190 | 204 | |
|
191 | 205 | def checkInputs(self): |
|
192 | 206 | |
|
193 | 207 | for thisDataIn in self.dataInList: |
|
194 | 208 | |
|
195 | 209 | if thisDataIn.isEmpty(): |
|
196 | 210 | return False |
|
197 | 211 | |
|
198 | 212 | return True |
|
199 | 213 | |
|
200 | 214 | def setup(self): |
|
201 | 215 | |
|
202 | 216 | raise ValueError, "Not implemented" |
|
203 | 217 | |
|
204 | 218 | def run(self): |
|
205 | 219 | |
|
206 | 220 | raise ValueError, "Not implemented" |
|
207 | 221 | |
|
208 | class Operation(): | |
|
222 | class Operation(object): | |
|
209 | 223 | |
|
210 | 224 | """ |
|
211 | 225 | Clase base para definir las operaciones adicionales que se pueden agregar a la clase ProcessingUnit |
|
212 | 226 | y necesiten acumular informacion previa de los datos a procesar. De preferencia usar un buffer de |
|
213 | 227 | acumulacion dentro de esta clase |
|
214 | 228 | |
|
215 | 229 | Ejemplo: Integraciones coherentes, necesita la informacion previa de los n perfiles anteriores (bufffer) |
|
216 | 230 | |
|
217 | 231 | """ |
|
218 | 232 | |
|
219 | 233 | __buffer = None |
|
220 | 234 | isConfig = False |
|
221 | 235 | |
|
222 | 236 | def __init__(self): |
|
223 | 237 | |
|
224 | 238 | self.__buffer = None |
|
225 | 239 | self.isConfig = False |
|
226 | 240 | |
|
227 | 241 | def setup(self): |
|
228 | 242 | |
|
229 | 243 | self.isConfig = True |
|
230 | 244 | |
|
231 | 245 | raise ValueError, "Not implemented" |
|
232 | 246 | |
|
233 | 247 | def run(self, dataIn, **kwargs): |
|
234 | 248 | |
|
235 | 249 | """ |
|
236 |
Realiza las operaciones necesarias sobre la dataIn.data y actualiza los |
|
|
250 | Realiza las operaciones necesarias sobre la dataIn.data y actualiza los | |
|
251 | atributos del objeto dataIn. | |
|
237 | 252 | |
|
238 | 253 | Input: |
|
239 | 254 | |
|
240 | 255 | dataIn : objeto del tipo JROData |
|
241 | 256 | |
|
242 | 257 | Return: |
|
243 | 258 | |
|
244 | 259 | None |
|
245 | 260 | |
|
246 | 261 | Affected: |
|
247 | 262 | __buffer : buffer de recepcion de datos. |
|
248 | 263 | |
|
249 | 264 | """ |
|
250 | 265 | if not self.isConfig: |
|
251 | 266 | self.setup(**kwargs) |
|
252 | 267 | |
|
253 | 268 | raise ValueError, "ImplementedError" No newline at end of file |
@@ -1,246 +1,246 | |||
|
1 | 1 | import numpy |
|
2 | 2 | |
|
3 | 3 | from jroproc_base import ProcessingUnit, Operation |
|
4 | from model.data.jrodata import Correlation | |
|
4 | from schainpy.model.data.jrodata import Correlation | |
|
5 | 5 | |
|
6 | 6 | class CorrelationProc(ProcessingUnit): |
|
7 | 7 | |
|
8 | 8 | def __init__(self): |
|
9 | 9 | |
|
10 | 10 | ProcessingUnit.__init__(self) |
|
11 | 11 | |
|
12 | 12 | self.objectDict = {} |
|
13 | 13 | self.buffer = None |
|
14 | 14 | self.firstdatatime = None |
|
15 | 15 | self.profIndex = 0 |
|
16 | 16 | self.dataOut = Correlation() |
|
17 | 17 | |
|
18 | 18 | def __updateObjFromInput(self): |
|
19 | 19 | |
|
20 | 20 | self.dataOut.timeZone = self.dataIn.timeZone |
|
21 | 21 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
22 | 22 | self.dataOut.errorCount = self.dataIn.errorCount |
|
23 | 23 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
24 | 24 | |
|
25 | 25 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy() |
|
26 | 26 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy() |
|
27 | 27 | self.dataOut.channelList = self.dataIn.channelList |
|
28 | 28 | self.dataOut.heightList = self.dataIn.heightList |
|
29 | 29 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
30 | 30 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
31 | 31 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
32 | 32 | self.dataOut.nBaud = self.dataIn.nBaud |
|
33 | 33 | self.dataOut.nCode = self.dataIn.nCode |
|
34 | 34 | self.dataOut.code = self.dataIn.code |
|
35 | 35 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
36 |
self.dataOut.flag |
|
|
36 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
|
37 | 37 | self.dataOut.utctime = self.firstdatatime |
|
38 | 38 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
39 | 39 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
40 | 40 | # self.dataOut.nCohInt = self.dataIn.nCohInt |
|
41 | 41 | # self.dataOut.nIncohInt = 1 |
|
42 | 42 | self.dataOut.ippSeconds = self.dataIn.ippSeconds |
|
43 | 43 | # self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
44 | 44 | |
|
45 | 45 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nPoints |
|
46 | 46 | |
|
47 | 47 | |
|
48 | 48 | def removeDC(self, jspectra): |
|
49 | 49 | |
|
50 | 50 | nChannel = jspectra.shape[0] |
|
51 | 51 | |
|
52 | 52 | for i in range(nChannel): |
|
53 | 53 | jspectra_tmp = jspectra[i,:,:] |
|
54 | 54 | jspectra_DC = numpy.mean(jspectra_tmp,axis = 0) |
|
55 | 55 | |
|
56 | 56 | jspectra_tmp = jspectra_tmp - jspectra_DC |
|
57 | 57 | jspectra[i,:,:] = jspectra_tmp |
|
58 | 58 | |
|
59 | 59 | return jspectra |
|
60 | 60 | |
|
61 | 61 | |
|
62 | 62 | def removeNoise(self, mode = 2): |
|
63 | 63 | indR = numpy.where(self.dataOut.lagR == 0)[0][0] |
|
64 | 64 | indT = numpy.where(self.dataOut.lagT == 0)[0][0] |
|
65 | 65 | |
|
66 | 66 | jspectra = self.dataOut.data_corr[:,:,indR,:] |
|
67 | 67 | |
|
68 | 68 | num_chan = jspectra.shape[0] |
|
69 | 69 | num_hei = jspectra.shape[2] |
|
70 | 70 | |
|
71 | 71 | freq_dc = indT |
|
72 | 72 | ind_vel = numpy.array([-2,-1,1,2]) + freq_dc |
|
73 | 73 | |
|
74 | 74 | NPot = self.dataOut.getNoise(mode) |
|
75 | 75 | jspectra[:,freq_dc,:] = jspectra[:,freq_dc,:] - NPot |
|
76 | 76 | SPot = jspectra[:,freq_dc,:] |
|
77 | 77 | pairsAutoCorr = self.dataOut.getPairsAutoCorr() |
|
78 | 78 | # self.dataOut.signalPotency = SPot |
|
79 | 79 | self.dataOut.noise = NPot |
|
80 | 80 | self.dataOut.SNR = (SPot/NPot)[pairsAutoCorr] |
|
81 | 81 | self.dataOut.data_corr[:,:,indR,:] = jspectra |
|
82 | 82 | |
|
83 | 83 | return 1 |
|
84 | 84 | |
|
85 | 85 | |
|
86 | 86 | def calculateNormFactor(self): |
|
87 | 87 | |
|
88 | 88 | pairsList = self.dataOut.pairsList |
|
89 | 89 | pairsAutoCorr = self.dataOut.pairsAutoCorr |
|
90 | 90 | nHeights = self.dataOut.nHeights |
|
91 | 91 | nPairs = len(pairsList) |
|
92 | 92 | normFactor = numpy.zeros((nPairs,nHeights)) |
|
93 | 93 | |
|
94 | 94 | indR = numpy.where(self.dataOut.lagR == 0)[0][0] |
|
95 | 95 | indT = numpy.where(self.dataOut.lagT == 0)[0][0] |
|
96 | 96 | |
|
97 | 97 | for l in range(len(pairsList)): |
|
98 | 98 | firstChannel = pairsList[l][0] |
|
99 | 99 | secondChannel = pairsList[l][1] |
|
100 | 100 | |
|
101 | 101 | AC1 = pairsAutoCorr[firstChannel] |
|
102 | 102 | AC2 = pairsAutoCorr[secondChannel] |
|
103 | 103 | |
|
104 | 104 | if (AC1 >= 0 and AC2 >= 0): |
|
105 | 105 | |
|
106 | 106 | data1 = numpy.abs(self.dataOut.data_corr[AC1,:,indR,:]) |
|
107 | 107 | data2 = numpy.abs(self.dataOut.data_corr[AC2,:,indR,:]) |
|
108 | 108 | maxim1 = data1.max(axis = 0) |
|
109 | 109 | maxim2 = data1.max(axis = 0) |
|
110 | 110 | maxim = numpy.sqrt(maxim1*maxim2) |
|
111 | 111 | else: |
|
112 | 112 | #In case there is no autocorrelation for the pair |
|
113 | 113 | data = numpy.abs(self.dataOut.data_corr[l,:,indR,:]) |
|
114 | 114 | maxim = numpy.max(data, axis = 0) |
|
115 | 115 | |
|
116 | 116 | normFactor[l,:] = maxim |
|
117 | 117 | |
|
118 | 118 | self.dataOut.normFactor = normFactor |
|
119 | 119 | |
|
120 | 120 | return 1 |
|
121 | 121 | |
|
122 | 122 | def run(self, lagT=None, lagR=None, pairsList=None, |
|
123 | 123 | nPoints=None, nAvg=None, bufferSize=None, |
|
124 | 124 | fullT = False, fullR = False, removeDC = False): |
|
125 | 125 | |
|
126 | 126 | self.dataOut.flagNoData = True |
|
127 | 127 | |
|
128 | 128 | if self.dataIn.type == "Correlation": |
|
129 | 129 | |
|
130 | 130 | self.dataOut.copy(self.dataIn) |
|
131 | 131 | |
|
132 | 132 | return |
|
133 | 133 | |
|
134 | 134 | if self.dataIn.type == "Voltage": |
|
135 | 135 | |
|
136 | 136 | if pairsList == None: |
|
137 | 137 | pairsList = [numpy.array([0,0])] |
|
138 | 138 | |
|
139 | 139 | if nPoints == None: |
|
140 | 140 | nPoints = 128 |
|
141 | 141 | #------------------------------------------------------------ |
|
142 | 142 | #Condicionales para calcular Correlaciones en Tiempo y Rango |
|
143 | 143 | if fullT: |
|
144 | 144 | lagT = numpy.arange(nPoints*2 - 1) - nPoints + 1 |
|
145 | 145 | elif lagT == None: |
|
146 | 146 | lagT = numpy.array([0]) |
|
147 | 147 | else: |
|
148 | 148 | lagT = numpy.array(lagT) |
|
149 | 149 | |
|
150 | 150 | if fullR: |
|
151 | 151 | lagR = numpy.arange(self.dataOut.nHeights) |
|
152 | 152 | elif lagR == None: |
|
153 | 153 | lagR = numpy.array([0]) |
|
154 | 154 | #------------------------------------------------------------- |
|
155 | 155 | |
|
156 | 156 | if nAvg == None: |
|
157 | 157 | nAvg = 1 |
|
158 | 158 | |
|
159 | 159 | if bufferSize == None: |
|
160 | 160 | bufferSize = 0 |
|
161 | 161 | |
|
162 | 162 | deltaH = self.dataIn.heightList[1] - self.dataIn.heightList[0] |
|
163 | 163 | self.dataOut.lagR = numpy.round(numpy.array(lagR)/deltaH) |
|
164 | 164 | self.dataOut.pairsList = pairsList |
|
165 | 165 | self.dataOut.nPoints = nPoints |
|
166 | 166 | # channels = numpy.sort(list(set(list(itertools.chain.from_iterable(pairsList))))) |
|
167 | 167 | |
|
168 | 168 | if self.buffer == None: |
|
169 | 169 | |
|
170 | 170 | self.buffer = numpy.zeros((self.dataIn.nChannels,self.dataIn.nProfiles,self.dataIn.nHeights),dtype='complex') |
|
171 | 171 | |
|
172 | 172 | |
|
173 | 173 | self.buffer[:,self.profIndex,:] = self.dataIn.data.copy()[:,:] |
|
174 | 174 | |
|
175 | 175 | self.profIndex += 1 |
|
176 | 176 | |
|
177 | 177 | if self.firstdatatime == None: |
|
178 | 178 | |
|
179 | 179 | self.firstdatatime = self.dataIn.utctime |
|
180 | 180 | |
|
181 | 181 | if self.profIndex == nPoints: |
|
182 | 182 | |
|
183 | 183 | tmp = self.buffer[:,0:nPoints,:] |
|
184 | 184 | self.buffer = None |
|
185 | 185 | self.buffer = tmp |
|
186 | 186 | |
|
187 | 187 | #--------------- Remover DC ------------ |
|
188 | 188 | if removeDC: |
|
189 | 189 | self.buffer = self.removeDC(self.buffer) |
|
190 | 190 | #--------------------------------------------- |
|
191 | 191 | self.dataOut.data_volts = self.buffer |
|
192 | 192 | self.__updateObjFromInput() |
|
193 | 193 | self.dataOut.data_corr = numpy.zeros((len(pairsList), |
|
194 | 194 | len(lagT),len(lagR), |
|
195 | 195 | self.dataIn.nHeights), |
|
196 | 196 | dtype='complex') |
|
197 | 197 | |
|
198 | 198 | for l in range(len(pairsList)): |
|
199 | 199 | |
|
200 | 200 | firstChannel = pairsList[l][0] |
|
201 | 201 | secondChannel = pairsList[l][1] |
|
202 | 202 | |
|
203 | 203 | tmp = None |
|
204 | 204 | tmp = numpy.zeros((len(lagT),len(lagR),self.dataIn.nHeights),dtype='complex') |
|
205 | 205 | |
|
206 | 206 | for t in range(len(lagT)): |
|
207 | 207 | |
|
208 | 208 | for r in range(len(lagR)): |
|
209 | 209 | |
|
210 | 210 | idxT = lagT[t] |
|
211 | 211 | idxR = lagR[r] |
|
212 | 212 | |
|
213 | 213 | if idxT >= 0: |
|
214 | 214 | vStacked = numpy.vstack((self.buffer[secondChannel,idxT:,:], |
|
215 | 215 | numpy.zeros((idxT,self.dataIn.nHeights),dtype='complex'))) |
|
216 | 216 | else: |
|
217 | 217 | vStacked = numpy.vstack((numpy.zeros((-idxT,self.dataIn.nHeights),dtype='complex'), |
|
218 | 218 | self.buffer[secondChannel,:(nPoints + idxT),:])) |
|
219 | 219 | |
|
220 | 220 | if idxR >= 0: |
|
221 | 221 | hStacked = numpy.hstack((vStacked[:,idxR:],numpy.zeros((nPoints,idxR),dtype='complex'))) |
|
222 | 222 | else: |
|
223 | 223 | hStacked = numpy.hstack((numpy.zeros((nPoints,-idxR),dtype='complex'),vStacked[:,(self.dataOut.nHeights + idxR)])) |
|
224 | 224 | |
|
225 | 225 | |
|
226 | 226 | tmp[t,r,:] = numpy.sum((numpy.conjugate(self.buffer[firstChannel,:,:])*hStacked),axis=0) |
|
227 | 227 | |
|
228 | 228 | |
|
229 | 229 | hStacked = None |
|
230 | 230 | vStacked = None |
|
231 | 231 | |
|
232 | 232 | self.dataOut.data_corr[l,:,:,:] = tmp[:,:,:] |
|
233 | 233 | |
|
234 | 234 | #Se Calcula los factores de Normalizacion |
|
235 | 235 | self.dataOut.pairsAutoCorr = self.dataOut.getPairsAutoCorr() |
|
236 | 236 | self.dataOut.lagT = lagT*self.dataIn.ippSeconds*self.dataIn.nCohInt |
|
237 | 237 | self.dataOut.lagR = lagR |
|
238 | 238 | |
|
239 | 239 | self.calculateNormFactor() |
|
240 | 240 | |
|
241 | 241 | self.dataOut.flagNoData = False |
|
242 | 242 | self.buffer = None |
|
243 | 243 | self.firstdatatime = None |
|
244 | 244 | self.profIndex = 0 |
|
245 | 245 | |
|
246 | 246 | return No newline at end of file |
@@ -1,339 +1,339 | |||
|
1 | 1 | import numpy |
|
2 | 2 | |
|
3 | 3 | from jroproc_base import ProcessingUnit, Operation |
|
4 | from model.data.jrodata import SpectraHeis | |
|
4 | from schainpy.model.data.jrodata import SpectraHeis | |
|
5 | 5 | |
|
6 | 6 | class SpectraHeisProc(ProcessingUnit): |
|
7 | 7 | |
|
8 | 8 | def __init__(self): |
|
9 | 9 | |
|
10 | 10 | ProcessingUnit.__init__(self) |
|
11 | 11 | |
|
12 | 12 | # self.buffer = None |
|
13 | 13 | # self.firstdatatime = None |
|
14 | 14 | # self.profIndex = 0 |
|
15 | 15 | self.dataOut = SpectraHeis() |
|
16 | 16 | |
|
17 | 17 | def __updateObjFromInput(self): |
|
18 | 18 | |
|
19 | 19 | self.dataOut.timeZone = self.dataIn.timeZone |
|
20 | 20 | self.dataOut.dstFlag = self.dataIn.dstFlag |
|
21 | 21 | self.dataOut.errorCount = self.dataIn.errorCount |
|
22 | 22 | self.dataOut.useLocalTime = self.dataIn.useLocalTime |
|
23 | 23 | |
|
24 | 24 | self.dataOut.radarControllerHeaderObj = self.dataIn.radarControllerHeaderObj.copy()# |
|
25 | 25 | self.dataOut.systemHeaderObj = self.dataIn.systemHeaderObj.copy()# |
|
26 | 26 | self.dataOut.channelList = self.dataIn.channelList |
|
27 | 27 | self.dataOut.heightList = self.dataIn.heightList |
|
28 | 28 | # self.dataOut.dtype = self.dataIn.dtype |
|
29 | 29 | self.dataOut.dtype = numpy.dtype([('real','<f4'),('imag','<f4')]) |
|
30 | 30 | # self.dataOut.nHeights = self.dataIn.nHeights |
|
31 | 31 | # self.dataOut.nChannels = self.dataIn.nChannels |
|
32 | 32 | self.dataOut.nBaud = self.dataIn.nBaud |
|
33 | 33 | self.dataOut.nCode = self.dataIn.nCode |
|
34 | 34 | self.dataOut.code = self.dataIn.code |
|
35 | 35 | # self.dataOut.nProfiles = 1 |
|
36 | 36 | # self.dataOut.nProfiles = self.dataOut.nFFTPoints |
|
37 | 37 | self.dataOut.nFFTPoints = self.dataIn.nHeights |
|
38 | 38 | # self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
39 | 39 | # self.dataOut.flagNoData = self.dataIn.flagNoData |
|
40 |
self.dataOut.flag |
|
|
40 | self.dataOut.flagDiscontinuousBlock = self.dataIn.flagDiscontinuousBlock | |
|
41 | 41 | self.dataOut.utctime = self.dataIn.utctime |
|
42 | 42 | # self.dataOut.utctime = self.firstdatatime |
|
43 | 43 | self.dataOut.flagDecodeData = self.dataIn.flagDecodeData #asumo q la data esta decodificada |
|
44 | 44 | self.dataOut.flagDeflipData = self.dataIn.flagDeflipData #asumo q la data esta sin flip |
|
45 | 45 | # self.dataOut.flagShiftFFT = self.dataIn.flagShiftFFT |
|
46 | 46 | self.dataOut.nCohInt = self.dataIn.nCohInt |
|
47 | 47 | self.dataOut.nIncohInt = 1 |
|
48 | 48 | # self.dataOut.ippSeconds= self.dataIn.ippSeconds |
|
49 | 49 | self.dataOut.windowOfFilter = self.dataIn.windowOfFilter |
|
50 | 50 | |
|
51 | 51 | self.dataOut.timeInterval = self.dataIn.timeInterval*self.dataOut.nIncohInt |
|
52 | 52 | # self.dataOut.set=self.dataIn.set |
|
53 | 53 | # self.dataOut.deltaHeight=self.dataIn.deltaHeight |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | def __updateObjFromFits(self): |
|
57 | 57 | self.dataOut.utctime = self.dataIn.utctime |
|
58 | 58 | self.dataOut.channelIndexList = self.dataIn.channelIndexList |
|
59 | 59 | |
|
60 | 60 | self.dataOut.channelList = self.dataIn.channelList |
|
61 | 61 | self.dataOut.heightList = self.dataIn.heightList |
|
62 | 62 | self.dataOut.data_spc = self.dataIn.data |
|
63 | 63 | self.dataOut.timeInterval = self.dataIn.timeInterval |
|
64 | 64 | self.dataOut.timeZone = self.dataIn.timeZone |
|
65 | 65 | self.dataOut.useLocalTime = True |
|
66 | 66 | # self.dataOut. |
|
67 | 67 | # self.dataOut. |
|
68 | 68 | |
|
69 | 69 | def __getFft(self): |
|
70 | 70 | |
|
71 | 71 | fft_volt = numpy.fft.fft(self.dataIn.data, axis=1) |
|
72 | 72 | fft_volt = numpy.fft.fftshift(fft_volt,axes=(1,)) |
|
73 | 73 | spc = numpy.abs(fft_volt * numpy.conjugate(fft_volt))/(self.dataOut.nFFTPoints) |
|
74 | 74 | self.dataOut.data_spc = spc |
|
75 | 75 | |
|
76 | 76 | def run(self): |
|
77 | 77 | |
|
78 | 78 | self.dataOut.flagNoData = True |
|
79 | 79 | |
|
80 | 80 | if self.dataIn.type == "Fits": |
|
81 | 81 | self.__updateObjFromFits() |
|
82 | 82 | self.dataOut.flagNoData = False |
|
83 | 83 | return |
|
84 | 84 | |
|
85 | 85 | if self.dataIn.type == "SpectraHeis": |
|
86 | 86 | self.dataOut.copy(self.dataIn) |
|
87 | 87 | return |
|
88 | 88 | |
|
89 | 89 | if self.dataIn.type == "Voltage": |
|
90 | 90 | self.__updateObjFromInput() |
|
91 | 91 | self.__getFft() |
|
92 | 92 | self.dataOut.flagNoData = False |
|
93 | 93 | |
|
94 | 94 | return |
|
95 | 95 | |
|
96 | 96 | raise ValueError, "The type object %s is not valid"%(self.dataIn.type) |
|
97 | 97 | |
|
98 | 98 | |
|
99 | 99 | def selectChannels(self, channelList): |
|
100 | 100 | |
|
101 | 101 | channelIndexList = [] |
|
102 | 102 | |
|
103 | 103 | for channel in channelList: |
|
104 | 104 | index = self.dataOut.channelList.index(channel) |
|
105 | 105 | channelIndexList.append(index) |
|
106 | 106 | |
|
107 | 107 | self.selectChannelsByIndex(channelIndexList) |
|
108 | 108 | |
|
109 | 109 | def selectChannelsByIndex(self, channelIndexList): |
|
110 | 110 | """ |
|
111 | 111 | Selecciona un bloque de datos en base a canales segun el channelIndexList |
|
112 | 112 | |
|
113 | 113 | Input: |
|
114 | 114 | channelIndexList : lista sencilla de canales a seleccionar por ej. [2,3,7] |
|
115 | 115 | |
|
116 | 116 | Affected: |
|
117 | 117 | self.dataOut.data |
|
118 | 118 | self.dataOut.channelIndexList |
|
119 | 119 | self.dataOut.nChannels |
|
120 | 120 | self.dataOut.m_ProcessingHeader.totalSpectra |
|
121 | 121 | self.dataOut.systemHeaderObj.numChannels |
|
122 | 122 | self.dataOut.m_ProcessingHeader.blockSize |
|
123 | 123 | |
|
124 | 124 | Return: |
|
125 | 125 | None |
|
126 | 126 | """ |
|
127 | 127 | |
|
128 | 128 | for channelIndex in channelIndexList: |
|
129 | 129 | if channelIndex not in self.dataOut.channelIndexList: |
|
130 | 130 | print channelIndexList |
|
131 | 131 | raise ValueError, "The value %d in channelIndexList is not valid" %channelIndex |
|
132 | 132 | |
|
133 | 133 | # nChannels = len(channelIndexList) |
|
134 | 134 | |
|
135 | 135 | data_spc = self.dataOut.data_spc[channelIndexList,:] |
|
136 | 136 | |
|
137 | 137 | self.dataOut.data_spc = data_spc |
|
138 | 138 | self.dataOut.channelList = [self.dataOut.channelList[i] for i in channelIndexList] |
|
139 | 139 | |
|
140 | 140 | return 1 |
|
141 | 141 | |
|
142 | 142 | class IncohInt4SpectraHeis(Operation): |
|
143 | 143 | |
|
144 | 144 | isConfig = False |
|
145 | 145 | |
|
146 | 146 | __profIndex = 0 |
|
147 | 147 | __withOverapping = False |
|
148 | 148 | |
|
149 | 149 | __byTime = False |
|
150 | 150 | __initime = None |
|
151 | 151 | __lastdatatime = None |
|
152 | 152 | __integrationtime = None |
|
153 | 153 | |
|
154 | 154 | __buffer = None |
|
155 | 155 | |
|
156 | 156 | __dataReady = False |
|
157 | 157 | |
|
158 | 158 | n = None |
|
159 | 159 | |
|
160 | 160 | |
|
161 | 161 | def __init__(self): |
|
162 | 162 | |
|
163 | 163 | Operation.__init__(self) |
|
164 | 164 | # self.isConfig = False |
|
165 | 165 | |
|
166 | 166 | def setup(self, n=None, timeInterval=None, overlapping=False): |
|
167 | 167 | """ |
|
168 | 168 | Set the parameters of the integration class. |
|
169 | 169 | |
|
170 | 170 | Inputs: |
|
171 | 171 | |
|
172 | 172 | n : Number of coherent integrations |
|
173 | 173 | timeInterval : Time of integration. If the parameter "n" is selected this one does not work |
|
174 | 174 | overlapping : |
|
175 | 175 | |
|
176 | 176 | """ |
|
177 | 177 | |
|
178 | 178 | self.__initime = None |
|
179 | 179 | self.__lastdatatime = 0 |
|
180 | 180 | self.__buffer = None |
|
181 | 181 | self.__dataReady = False |
|
182 | 182 | |
|
183 | 183 | |
|
184 | 184 | if n == None and timeInterval == None: |
|
185 | 185 | raise ValueError, "n or timeInterval should be specified ..." |
|
186 | 186 | |
|
187 | 187 | if n != None: |
|
188 | 188 | self.n = n |
|
189 | 189 | self.__byTime = False |
|
190 | 190 | else: |
|
191 | 191 | self.__integrationtime = timeInterval #* 60. #if (type(timeInterval)!=integer) -> change this line |
|
192 | 192 | self.n = 9999 |
|
193 | 193 | self.__byTime = True |
|
194 | 194 | |
|
195 | 195 | if overlapping: |
|
196 | 196 | self.__withOverapping = True |
|
197 | 197 | self.__buffer = None |
|
198 | 198 | else: |
|
199 | 199 | self.__withOverapping = False |
|
200 | 200 | self.__buffer = 0 |
|
201 | 201 | |
|
202 | 202 | self.__profIndex = 0 |
|
203 | 203 | |
|
204 | 204 | def putData(self, data): |
|
205 | 205 | |
|
206 | 206 | """ |
|
207 | 207 | Add a profile to the __buffer and increase in one the __profileIndex |
|
208 | 208 | |
|
209 | 209 | """ |
|
210 | 210 | |
|
211 | 211 | if not self.__withOverapping: |
|
212 | 212 | self.__buffer += data.copy() |
|
213 | 213 | self.__profIndex += 1 |
|
214 | 214 | return |
|
215 | 215 | |
|
216 | 216 | #Overlapping data |
|
217 | 217 | nChannels, nHeis = data.shape |
|
218 | 218 | data = numpy.reshape(data, (1, nChannels, nHeis)) |
|
219 | 219 | |
|
220 | 220 | #If the buffer is empty then it takes the data value |
|
221 | 221 | if self.__buffer == None: |
|
222 | 222 | self.__buffer = data |
|
223 | 223 | self.__profIndex += 1 |
|
224 | 224 | return |
|
225 | 225 | |
|
226 | 226 | #If the buffer length is lower than n then stakcing the data value |
|
227 | 227 | if self.__profIndex < self.n: |
|
228 | 228 | self.__buffer = numpy.vstack((self.__buffer, data)) |
|
229 | 229 | self.__profIndex += 1 |
|
230 | 230 | return |
|
231 | 231 | |
|
232 | 232 | #If the buffer length is equal to n then replacing the last buffer value with the data value |
|
233 | 233 | self.__buffer = numpy.roll(self.__buffer, -1, axis=0) |
|
234 | 234 | self.__buffer[self.n-1] = data |
|
235 | 235 | self.__profIndex = self.n |
|
236 | 236 | return |
|
237 | 237 | |
|
238 | 238 | |
|
239 | 239 | def pushData(self): |
|
240 | 240 | """ |
|
241 | 241 | Return the sum of the last profiles and the profiles used in the sum. |
|
242 | 242 | |
|
243 | 243 | Affected: |
|
244 | 244 | |
|
245 | 245 | self.__profileIndex |
|
246 | 246 | |
|
247 | 247 | """ |
|
248 | 248 | |
|
249 | 249 | if not self.__withOverapping: |
|
250 | 250 | data = self.__buffer |
|
251 | 251 | n = self.__profIndex |
|
252 | 252 | |
|
253 | 253 | self.__buffer = 0 |
|
254 | 254 | self.__profIndex = 0 |
|
255 | 255 | |
|
256 | 256 | return data, n |
|
257 | 257 | |
|
258 | 258 | #Integration with Overlapping |
|
259 | 259 | data = numpy.sum(self.__buffer, axis=0) |
|
260 | 260 | n = self.__profIndex |
|
261 | 261 | |
|
262 | 262 | return data, n |
|
263 | 263 | |
|
264 | 264 | def byProfiles(self, data): |
|
265 | 265 | |
|
266 | 266 | self.__dataReady = False |
|
267 | 267 | avgdata = None |
|
268 | 268 | # n = None |
|
269 | 269 | |
|
270 | 270 | self.putData(data) |
|
271 | 271 | |
|
272 | 272 | if self.__profIndex == self.n: |
|
273 | 273 | |
|
274 | 274 | avgdata, n = self.pushData() |
|
275 | 275 | self.__dataReady = True |
|
276 | 276 | |
|
277 | 277 | return avgdata |
|
278 | 278 | |
|
279 | 279 | def byTime(self, data, datatime): |
|
280 | 280 | |
|
281 | 281 | self.__dataReady = False |
|
282 | 282 | avgdata = None |
|
283 | 283 | n = None |
|
284 | 284 | |
|
285 | 285 | self.putData(data) |
|
286 | 286 | |
|
287 | 287 | if (datatime - self.__initime) >= self.__integrationtime: |
|
288 | 288 | avgdata, n = self.pushData() |
|
289 | 289 | self.n = n |
|
290 | 290 | self.__dataReady = True |
|
291 | 291 | |
|
292 | 292 | return avgdata |
|
293 | 293 | |
|
294 | 294 | def integrate(self, data, datatime=None): |
|
295 | 295 | |
|
296 | 296 | if self.__initime == None: |
|
297 | 297 | self.__initime = datatime |
|
298 | 298 | |
|
299 | 299 | if self.__byTime: |
|
300 | 300 | avgdata = self.byTime(data, datatime) |
|
301 | 301 | else: |
|
302 | 302 | avgdata = self.byProfiles(data) |
|
303 | 303 | |
|
304 | 304 | |
|
305 | 305 | self.__lastdatatime = datatime |
|
306 | 306 | |
|
307 | 307 | if avgdata == None: |
|
308 | 308 | return None, None |
|
309 | 309 | |
|
310 | 310 | avgdatatime = self.__initime |
|
311 | 311 | |
|
312 | 312 | deltatime = datatime -self.__lastdatatime |
|
313 | 313 | |
|
314 | 314 | if not self.__withOverapping: |
|
315 | 315 | self.__initime = datatime |
|
316 | 316 | else: |
|
317 | 317 | self.__initime += deltatime |
|
318 | 318 | |
|
319 | 319 | return avgdata, avgdatatime |
|
320 | 320 | |
|
321 | 321 | def run(self, dataOut, **kwargs): |
|
322 | 322 | |
|
323 | 323 | if not self.isConfig: |
|
324 | 324 | self.setup(**kwargs) |
|
325 | 325 | self.isConfig = True |
|
326 | 326 | |
|
327 | 327 | avgdata, avgdatatime = self.integrate(dataOut.data_spc, dataOut.utctime) |
|
328 | 328 | |
|
329 | 329 | # dataOut.timeInterval *= n |
|
330 | 330 | dataOut.flagNoData = True |
|
331 | 331 | |
|
332 | 332 | if self.__dataReady: |
|
333 | 333 | dataOut.data_spc = avgdata |
|
334 | 334 | dataOut.nIncohInt *= self.n |
|
335 | 335 | # dataOut.nCohInt *= self.n |
|
336 | 336 | dataOut.utctime = avgdatatime |
|
337 | 337 | # dataOut.timeInterval = dataOut.ippSeconds * dataOut.nIncohInt |
|
338 | 338 | # dataOut.timeInterval = self.__timeInterval*self.n |
|
339 | 339 | dataOut.flagNoData = False No newline at end of file |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: modified file | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
|
1 | NO CONTENT: file was removed | |
The requested commit or file is too big and content was truncated. Show full diff |
General Comments 0
You need to be logged in to leave comments.
Login now