This diff has been collapsed as it changes many lines, (751 lines changed) Show them Hide them | |||
@@ -0,0 +1,751 | |||
|
1 | ||
|
2 | ''' | |
|
3 | Created on Jul 3, 2014 | |
|
4 | ||
|
5 | @author: roj-idl71 | |
|
6 | ''' | |
|
7 | # SUBCHANNELS EN VEZ DE CHANNELS | |
|
8 | # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO | |
|
9 | # ACTUALIZACION DE VERSION | |
|
10 | # HEADERS | |
|
11 | # MODULO DE ESCRITURA | |
|
12 | # METADATA | |
|
13 | ||
|
14 | import os | |
|
15 | import datetime | |
|
16 | import numpy | |
|
17 | import timeit | |
|
18 | from profilehooks import coverage, profile | |
|
19 | from fractions import Fraction | |
|
20 | ||
|
21 | try: | |
|
22 | from gevent import sleep | |
|
23 | except: | |
|
24 | from time import sleep | |
|
25 | ||
|
26 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
|
27 | from schainpy.model.data.jrodata import Voltage | |
|
28 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
|
29 | from time import time | |
|
30 | ||
|
31 | import cPickle | |
|
32 | try: | |
|
33 | import digital_rf | |
|
34 | except: | |
|
35 | print 'You should install "digital_rf" module if you want to read Digital RF data' | |
|
36 | ||
|
37 | class DigitalRFReader(ProcessingUnit): | |
|
38 | ''' | |
|
39 | classdocs | |
|
40 | ''' | |
|
41 | ||
|
42 | def __init__(self, **kwargs): | |
|
43 | ''' | |
|
44 | Constructor | |
|
45 | ''' | |
|
46 | ||
|
47 | ProcessingUnit.__init__(self, **kwargs) | |
|
48 | ||
|
49 | self.dataOut = Voltage() | |
|
50 | self.__printInfo = True | |
|
51 | self.__flagDiscontinuousBlock = False | |
|
52 | self.__bufferIndex = 9999999 | |
|
53 | self.__ippKm = None | |
|
54 | self.__codeType = 0 | |
|
55 | self.__nCode = None | |
|
56 | self.__nBaud = None | |
|
57 | self.__code = None | |
|
58 | self.dtype = None | |
|
59 | ||
|
60 | def close(self): | |
|
61 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 | |
|
62 | return | |
|
63 | ||
|
64 | def __getCurrentSecond(self): | |
|
65 | ||
|
66 | return self.__thisUnixSample/self.__sample_rate | |
|
67 | ||
|
68 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") | |
|
69 | ||
|
70 | def __setFileHeader(self): | |
|
71 | ''' | |
|
72 | In this method will be initialized every parameter of dataOut object (header, no data) | |
|
73 | ''' | |
|
74 | ippSeconds = 1.0*self.__nSamples/self.__sample_rate | |
|
75 | ||
|
76 | nProfiles = 1.0/ippSeconds # Number of profiles in one second | |
|
77 | ||
|
78 | try: | |
|
79 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader(self.__radarControllerHeader) | |
|
80 | except: | |
|
81 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( | |
|
82 | txA=0, | |
|
83 | txB=0, | |
|
84 | nWindows=1, | |
|
85 | nHeights=self.__nSamples, | |
|
86 | firstHeight=self.__firstHeigth, | |
|
87 | deltaHeight=self.__deltaHeigth, | |
|
88 | codeType=self.__codeType, | |
|
89 | nCode=self.__nCode, nBaud=self.__nBaud, | |
|
90 | code = self.__code) | |
|
91 | ||
|
92 | try: | |
|
93 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) | |
|
94 | except: | |
|
95 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, | |
|
96 | nProfiles=nProfiles, | |
|
97 | nChannels=len(self.__channelList), | |
|
98 | adcResolution=14) | |
|
99 | self.dataOut.type = "Voltage" | |
|
100 | ||
|
101 | self.dataOut.data = None | |
|
102 | ||
|
103 | self.dataOut.dtype = self.dtype | |
|
104 | ||
|
105 | # self.dataOut.nChannels = 0 | |
|
106 | ||
|
107 | # self.dataOut.nHeights = 0 | |
|
108 | ||
|
109 | self.dataOut.nProfiles = int(nProfiles) | |
|
110 | ||
|
111 | self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth | |
|
112 | ||
|
113 | self.dataOut.channelList = range(self.__num_subchannels) | |
|
114 | ||
|
115 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
|
116 | ||
|
117 | # self.dataOut.channelIndexList = None | |
|
118 | ||
|
119 | self.dataOut.flagNoData = True | |
|
120 | ||
|
121 | self.dataOut.flagDataAsBlock = False | |
|
122 | # Set to TRUE if the data is discontinuous | |
|
123 | self.dataOut.flagDiscontinuousBlock = False | |
|
124 | ||
|
125 | self.dataOut.utctime = None | |
|
126 | ||
|
127 | self.dataOut.timeZone = self.__timezone/60 # timezone like jroheader, difference in minutes between UTC and localtime | |
|
128 | ||
|
129 | self.dataOut.dstFlag = 0 | |
|
130 | ||
|
131 | self.dataOut.errorCount = 0 | |
|
132 | ||
|
133 | try: | |
|
134 | self.dataOut.nCohInt = self.fixed_metadata_dict.get('nCohInt', 1) | |
|
135 | ||
|
136 | self.dataOut.flagDecodeData = self.fixed_metadata_dict['flagDecodeData'] # asumo que la data esta decodificada | |
|
137 | ||
|
138 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] # asumo que la data esta sin flip | |
|
139 | ||
|
140 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] | |
|
141 | ||
|
142 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] | |
|
143 | except: | |
|
144 | pass | |
|
145 | ||
|
146 | ||
|
147 | self.dataOut.ippSeconds = ippSeconds | |
|
148 | ||
|
149 | # Time interval between profiles | |
|
150 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
|
151 | ||
|
152 | self.dataOut.frequency = self.__frequency | |
|
153 | ||
|
154 | self.dataOut.realtime = self.__online | |
|
155 | ||
|
156 | def findDatafiles(self, path, startDate=None, endDate=None): | |
|
157 | ||
|
158 | if not os.path.isdir(path): | |
|
159 | return [] | |
|
160 | ||
|
161 | try: | |
|
162 | digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True) | |
|
163 | except: | |
|
164 | digitalReadObj = digital_rf.DigitalRFReader(path) | |
|
165 | ||
|
166 | channelNameList = digitalReadObj.get_channels() | |
|
167 | ||
|
168 | if not channelNameList: | |
|
169 | return [] | |
|
170 | ||
|
171 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) | |
|
172 | ||
|
173 | sample_rate = metadata_dict['sample_rate'][0] | |
|
174 | ||
|
175 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) | |
|
176 | ||
|
177 | try: | |
|
178 | timezone = this_metadata_file['timezone'].value | |
|
179 | except: | |
|
180 | timezone = 0 | |
|
181 | ||
|
182 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone | |
|
183 | ||
|
184 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) | |
|
185 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) | |
|
186 | ||
|
187 | if not startDate: | |
|
188 | startDate = startDatetime.date() | |
|
189 | ||
|
190 | if not endDate: | |
|
191 | endDate = endDatatime.date() | |
|
192 | ||
|
193 | dateList = [] | |
|
194 | ||
|
195 | thisDatetime = startDatetime | |
|
196 | ||
|
197 | while(thisDatetime<=endDatatime): | |
|
198 | ||
|
199 | thisDate = thisDatetime.date() | |
|
200 | ||
|
201 | if thisDate < startDate: | |
|
202 | continue | |
|
203 | ||
|
204 | if thisDate > endDate: | |
|
205 | break | |
|
206 | ||
|
207 | dateList.append(thisDate) | |
|
208 | thisDatetime += datetime.timedelta(1) | |
|
209 | ||
|
210 | return dateList | |
|
211 | ||
|
212 | def setup(self, path = None, | |
|
213 | startDate = None, | |
|
214 | endDate = None, | |
|
215 | startTime = datetime.time(0,0,0), | |
|
216 | endTime = datetime.time(23,59,59), | |
|
217 | channelList = None, | |
|
218 | nSamples = None, | |
|
219 | online = False, | |
|
220 | delay = 60, | |
|
221 | buffer_size = 1024, | |
|
222 | ippKm=None, | |
|
223 | **kwargs): | |
|
224 | ''' | |
|
225 | In this method we should set all initial parameters. | |
|
226 | ||
|
227 | Inputs: | |
|
228 | path | |
|
229 | startDate | |
|
230 | endDate | |
|
231 | startTime | |
|
232 | endTime | |
|
233 | set | |
|
234 | expLabel | |
|
235 | ext | |
|
236 | online | |
|
237 | delay | |
|
238 | ''' | |
|
239 | self.i = 0 | |
|
240 | if not os.path.isdir(path): | |
|
241 | raise ValueError, "[Reading] Directory %s does not exist" %path | |
|
242 | ||
|
243 | try: | |
|
244 | self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True) | |
|
245 | except: | |
|
246 | self.digitalReadObj = digital_rf.DigitalRFReader(path) | |
|
247 | ||
|
248 | channelNameList = self.digitalReadObj.get_channels() | |
|
249 | ||
|
250 | if not channelNameList: | |
|
251 | raise ValueError, "[Reading] Directory %s does not have any files" %path | |
|
252 | ||
|
253 | if not channelList: | |
|
254 | channelList = range(len(channelNameList)) | |
|
255 | ||
|
256 | ||
|
257 | ########## Reading metadata ###################### | |
|
258 | ||
|
259 | top_properties = self.digitalReadObj.get_properties(channelNameList[channelList[0]]) | |
|
260 | ||
|
261 | ||
|
262 | self.__num_subchannels = top_properties['num_subchannels'] | |
|
263 | self.__sample_rate = 1.0 * top_properties['sample_rate_numerator'] / top_properties['sample_rate_denominator'] | |
|
264 | # self.__samples_per_file = top_properties['samples_per_file'][0] | |
|
265 | self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15? | |
|
266 | ||
|
267 | this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]]) | |
|
268 | metadata_bounds = this_metadata_file.get_bounds() | |
|
269 | self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ## GET FIRST HEADER | |
|
270 | ||
|
271 | try: | |
|
272 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] | |
|
273 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] | |
|
274 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] | |
|
275 | self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype']) | |
|
276 | except: | |
|
277 | pass | |
|
278 | ||
|
279 | ||
|
280 | self.__frequency = None | |
|
281 | ||
|
282 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) | |
|
283 | ||
|
284 | self.__timezone = self.fixed_metadata_dict.get('timezone', 300) | |
|
285 | ||
|
286 | ||
|
287 | try: | |
|
288 | nSamples = self.fixed_metadata_dict['nSamples'] | |
|
289 | except: | |
|
290 | nSamples = None | |
|
291 | ||
|
292 | self.__firstHeigth = 0 | |
|
293 | ||
|
294 | try: | |
|
295 | codeType = self.__radarControllerHeader['codeType'] | |
|
296 | except: | |
|
297 | codeType = 0 | |
|
298 | ||
|
299 | nCode = 1 | |
|
300 | nBaud = 1 | |
|
301 | code = numpy.ones((nCode, nBaud), dtype=numpy.int) | |
|
302 | ||
|
303 | try: | |
|
304 | if codeType: | |
|
305 | nCode = self.__radarControllerHeader['nCode'] | |
|
306 | nBaud = self.__radarControllerHeader['nBaud'] | |
|
307 | code = self.__radarControllerHeader['code'] | |
|
308 | except: | |
|
309 | pass | |
|
310 | ||
|
311 | ||
|
312 | if not ippKm: | |
|
313 | try: | |
|
314 | # seconds to km | |
|
315 | ippKm = self.__radarControllerHeader['ipp'] | |
|
316 | except: | |
|
317 | ippKm = None | |
|
318 | #################################################### | |
|
319 | self.__ippKm = ippKm | |
|
320 | startUTCSecond = None | |
|
321 | endUTCSecond = None | |
|
322 | ||
|
323 | if startDate: | |
|
324 | startDatetime = datetime.datetime.combine(startDate, startTime) | |
|
325 | startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone | |
|
326 | ||
|
327 | if endDate: | |
|
328 | endDatetime = datetime.datetime.combine(endDate, endTime) | |
|
329 | endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone | |
|
330 | ||
|
331 | start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]]) | |
|
332 | ||
|
333 | if not startUTCSecond: | |
|
334 | startUTCSecond = start_index/self.__sample_rate | |
|
335 | ||
|
336 | if start_index > startUTCSecond*self.__sample_rate: | |
|
337 | startUTCSecond = start_index/self.__sample_rate | |
|
338 | ||
|
339 | if not endUTCSecond: | |
|
340 | endUTCSecond = end_index/self.__sample_rate | |
|
341 | ||
|
342 | if end_index < endUTCSecond*self.__sample_rate: | |
|
343 | endUTCSecond = end_index/self.__sample_rate | |
|
344 | if not nSamples: | |
|
345 | if not ippKm: | |
|
346 | raise ValueError, "[Reading] nSamples or ippKm should be defined" | |
|
347 | nSamples = int(ippKm / (1e6*0.15/self.__sample_rate)) | |
|
348 | channelBoundList = [] | |
|
349 | channelNameListFiltered = [] | |
|
350 | ||
|
351 | for thisIndexChannel in channelList: | |
|
352 | thisChannelName = channelNameList[thisIndexChannel] | |
|
353 | start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName) | |
|
354 | channelBoundList.append((start_index, end_index)) | |
|
355 | channelNameListFiltered.append(thisChannelName) | |
|
356 | ||
|
357 | self.profileIndex = 0 | |
|
358 | self.i= 0 | |
|
359 | self.__delay = delay | |
|
360 | ||
|
361 | self.__codeType = codeType | |
|
362 | self.__nCode = nCode | |
|
363 | self.__nBaud = nBaud | |
|
364 | self.__code = code | |
|
365 | ||
|
366 | self.__datapath = path | |
|
367 | self.__online = online | |
|
368 | self.__channelList = channelList | |
|
369 | self.__channelNameList = channelNameListFiltered | |
|
370 | self.__channelBoundList = channelBoundList | |
|
371 | self.__nSamples = nSamples | |
|
372 | self.__samples_to_read = long(nSamples) # FIJO: AHORA 40 | |
|
373 | self.__nChannels = len(self.__channelList) | |
|
374 | ||
|
375 | self.__startUTCSecond = startUTCSecond | |
|
376 | self.__endUTCSecond = endUTCSecond | |
|
377 | ||
|
378 | self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate # Time interval | |
|
379 | ||
|
380 | if online: | |
|
381 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) | |
|
382 | startUTCSecond = numpy.floor(endUTCSecond) | |
|
383 | ||
|
384 | self.__thisUnixSample = long(startUTCSecond*self.__sample_rate) - self.__samples_to_read ## por que en el otro metodo lo primero q se hace es sumar samplestoread | |
|
385 | ||
|
386 | self.__data_buffer = numpy.zeros((self.__num_subchannels, self.__samples_to_read), dtype = numpy.complex) | |
|
387 | ||
|
388 | self.__setFileHeader() | |
|
389 | self.isConfig = True | |
|
390 | ||
|
391 | print "[Reading] Digital RF Data was found from %s to %s " %( | |
|
392 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
393 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
394 | ) | |
|
395 | ||
|
396 | print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), | |
|
397 | datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone) | |
|
398 | ) | |
|
399 | self.oldAverage = None | |
|
400 | self.count = 0 | |
|
401 | self.executionTime = 0 | |
|
402 | def __reload(self): | |
|
403 | ||
|
404 | # print "%s not in range [%s, %s]" %( | |
|
405 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
406 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
407 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
408 | # ) | |
|
409 | print "[Reading] reloading metadata ..." | |
|
410 | ||
|
411 | try: | |
|
412 | self.digitalReadObj.reload(complete_update=True) | |
|
413 | except: | |
|
414 | self.digitalReadObj.reload() | |
|
415 | ||
|
416 | start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]]) | |
|
417 | ||
|
418 | if start_index > self.__startUTCSecond*self.__sample_rate: | |
|
419 | self.__startUTCSecond = 1.0*start_index/self.__sample_rate | |
|
420 | ||
|
421 | if end_index > self.__endUTCSecond*self.__sample_rate: | |
|
422 | self.__endUTCSecond = 1.0*end_index/self.__sample_rate | |
|
423 | ||
|
424 | print "[Reading] New timerange found [%s, %s] " %( | |
|
425 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
|
426 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
|
427 | ) | |
|
428 | ||
|
429 | return True | |
|
430 | ||
|
431 | return False | |
|
432 | ||
|
433 | def timeit(self, toExecute): | |
|
434 | t0 = time() | |
|
435 | toExecute() | |
|
436 | self.executionTime = time() - t0 | |
|
437 | if self.oldAverage is None: self.oldAverage = self.executionTime | |
|
438 | self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0) | |
|
439 | self.count = self.count + 1.0 | |
|
440 | return | |
|
441 | ||
|
442 | def __readNextBlock(self, seconds=30, volt_scale = 1): | |
|
443 | ''' | |
|
444 | ''' | |
|
445 | ||
|
446 | # Set the next data | |
|
447 | self.__flagDiscontinuousBlock = False | |
|
448 | self.__thisUnixSample += self.__samples_to_read | |
|
449 | ||
|
450 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: | |
|
451 | print "[Reading] There are no more data into selected time-range" | |
|
452 | if self.__online: | |
|
453 | self.__reload() | |
|
454 | else: | |
|
455 | return False | |
|
456 | ||
|
457 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: | |
|
458 | return False | |
|
459 | self.__thisUnixSample -= self.__samples_to_read | |
|
460 | ||
|
461 | indexChannel = 0 | |
|
462 | ||
|
463 | dataOk = False | |
|
464 | for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS? | |
|
465 | for indexSubchannel in range(self.__num_subchannels): | |
|
466 | try: | |
|
467 | t0 = time() | |
|
468 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, | |
|
469 | self.__samples_to_read, | |
|
470 | thisChannelName, sub_channel=indexSubchannel) | |
|
471 | self.executionTime = time() - t0 | |
|
472 | if self.oldAverage is None: self.oldAverage = self.executionTime | |
|
473 | self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0) | |
|
474 | self.count = self.count + 1.0 | |
|
475 | ||
|
476 | except IOError, e: | |
|
477 | #read next profile | |
|
478 | self.__flagDiscontinuousBlock = True | |
|
479 | print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e | |
|
480 | break | |
|
481 | ||
|
482 | if result.shape[0] != self.__samples_to_read: | |
|
483 | self.__flagDiscontinuousBlock = True | |
|
484 | print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
485 | result.shape[0], | |
|
486 | self.__samples_to_read) | |
|
487 | break | |
|
488 | ||
|
489 | self.__data_buffer[indexSubchannel,:] = result*volt_scale | |
|
490 | ||
|
491 | indexChannel += 1 | |
|
492 | ||
|
493 | dataOk = True | |
|
494 | ||
|
495 | self.__utctime = self.__thisUnixSample/self.__sample_rate | |
|
496 | ||
|
497 | if not dataOk: | |
|
498 | return False | |
|
499 | ||
|
500 | print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
|
501 | self.__samples_to_read, | |
|
502 | self.__timeInterval) | |
|
503 | ||
|
504 | self.__bufferIndex = 0 | |
|
505 | ||
|
506 | return True | |
|
507 | ||
|
508 | def __isBufferEmpty(self): | |
|
509 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40 | |
|
510 | ||
|
511 | def getData(self, seconds=30, nTries=5): | |
|
512 | ||
|
513 | ''' | |
|
514 | This method gets the data from files and put the data into the dataOut object | |
|
515 | ||
|
516 | In addition, increase el the buffer counter in one. | |
|
517 | ||
|
518 | Return: | |
|
519 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
|
520 | buffer. Si no hay mas archivos a leer retorna None. | |
|
521 | ||
|
522 | Affected: | |
|
523 | self.dataOut | |
|
524 | self.profileIndex | |
|
525 | self.flagDiscontinuousBlock | |
|
526 | self.flagIsNewBlock | |
|
527 | ''' | |
|
528 | ||
|
529 | err_counter = 0 | |
|
530 | self.dataOut.flagNoData = True | |
|
531 | ||
|
532 | if self.__isBufferEmpty(): | |
|
533 | self.__flagDiscontinuousBlock = False | |
|
534 | ||
|
535 | while True: | |
|
536 | if self.__readNextBlock(): | |
|
537 | break | |
|
538 | if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate: | |
|
539 | return False | |
|
540 | ||
|
541 | if self.__flagDiscontinuousBlock: | |
|
542 | print '[Reading] discontinuous block found ... continue with the next block' | |
|
543 | continue | |
|
544 | ||
|
545 | if not self.__online: | |
|
546 | return False | |
|
547 | ||
|
548 | err_counter += 1 | |
|
549 | if err_counter > nTries: | |
|
550 | return False | |
|
551 | ||
|
552 | print '[Reading] waiting %d seconds to read a new block' %seconds | |
|
553 | sleep(seconds) | |
|
554 | ||
|
555 | self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples] | |
|
556 | self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate | |
|
557 | self.dataOut.flagNoData = False | |
|
558 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
|
559 | self.dataOut.profileIndex = self.profileIndex | |
|
560 | ||
|
561 | self.__bufferIndex += self.__nSamples | |
|
562 | self.profileIndex += 1 | |
|
563 | ||
|
564 | if self.profileIndex == self.dataOut.nProfiles: | |
|
565 | self.profileIndex = 0 | |
|
566 | ||
|
567 | return True | |
|
568 | ||
|
569 | def printInfo(self): | |
|
570 | ''' | |
|
571 | ''' | |
|
572 | if self.__printInfo == False: | |
|
573 | return | |
|
574 | ||
|
575 | # self.systemHeaderObj.printInfo() | |
|
576 | # self.radarControllerHeaderObj.printInfo() | |
|
577 | ||
|
578 | self.__printInfo = False | |
|
579 | ||
|
580 | def printNumberOfBlock(self): | |
|
581 | ''' | |
|
582 | ''' | |
|
583 | return | |
|
584 | # print self.profileIndex | |
|
585 | ||
|
586 | ||
|
587 | def run(self, **kwargs): | |
|
588 | ''' | |
|
589 | This method will be called many times so here you should put all your code | |
|
590 | ''' | |
|
591 | ||
|
592 | if not self.isConfig: | |
|
593 | self.setup(**kwargs) | |
|
594 | #self.i = self.i+1 | |
|
595 | self.getData(seconds=self.__delay) | |
|
596 | ||
|
597 | return | |
|
598 | ||
|
599 | class DigitalRFWriter(Operation): | |
|
600 | ''' | |
|
601 | classdocs | |
|
602 | ''' | |
|
603 | ||
|
604 | def __init__(self, **kwargs): | |
|
605 | ''' | |
|
606 | Constructor | |
|
607 | ''' | |
|
608 | Operation.__init__(self, **kwargs) | |
|
609 | self.metadata_dict = {} | |
|
610 | self.dataOut = None | |
|
611 | self.dtype = None | |
|
612 | ||
|
613 | def setHeader(self): | |
|
614 | ||
|
615 | self.metadata_dict['frequency'] = self.dataOut.frequency | |
|
616 | self.metadata_dict['timezone'] = self.dataOut.timeZone | |
|
617 | self.metadata_dict['dtype'] = cPickle.dumps(self.dataOut.dtype) | |
|
618 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles | |
|
619 | self.metadata_dict['heightList'] = self.dataOut.heightList | |
|
620 | self.metadata_dict['channelList'] = self.dataOut.channelList | |
|
621 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData | |
|
622 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData | |
|
623 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT | |
|
624 | self.metadata_dict['flagDataAsBlock'] = self.dataOut.flagDataAsBlock | |
|
625 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime | |
|
626 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt | |
|
627 | ||
|
628 | return | |
|
629 | ||
|
630 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): | |
|
631 | ''' | |
|
632 | In this method we should set all initial parameters. | |
|
633 | Input: | |
|
634 | dataOut: Input data will also be outputa data | |
|
635 | ''' | |
|
636 | self.setHeader() | |
|
637 | self.__ippSeconds = dataOut.ippSeconds | |
|
638 | self.__deltaH = dataOut.getDeltaH() | |
|
639 | self.__sample_rate = 1e6*0.15/self.__deltaH | |
|
640 | self.__dtype = dataOut.dtype | |
|
641 | if len(dataOut.dtype) == 2: | |
|
642 | self.__dtype = dataOut.dtype[0] | |
|
643 | self.__nSamples = dataOut.systemHeaderObj.nSamples | |
|
644 | self.__nProfiles = dataOut.nProfiles | |
|
645 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile | |
|
646 | ||
|
647 | self.arr_data = arr_data = numpy.ones((self.__nSamples, len(self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |
|
648 | ||
|
649 | file_cadence_millisecs = long(1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000 | |
|
650 | sub_cadence_secs = file_cadence_millisecs / 500 | |
|
651 | ||
|
652 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() | |
|
653 | sample_rate_numerator = long(sample_rate_fraction.numerator) | |
|
654 | sample_rate_denominator = long(sample_rate_fraction.denominator) | |
|
655 | start_global_index = dataOut.utctime * self.__sample_rate | |
|
656 | ||
|
657 | uuid = 'prueba' | |
|
658 | compression_level = 1 | |
|
659 | checksum = False | |
|
660 | is_complex = True | |
|
661 | num_subchannels = len(dataOut.channelList) | |
|
662 | is_continuous = True | |
|
663 | marching_periods = False | |
|
664 | ||
|
665 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, | |
|
666 | fileCadence, start_global_index, | |
|
667 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, | |
|
668 | is_complex, num_subchannels, is_continuous, marching_periods) | |
|
669 | ||
|
670 | metadata_dir = os.path.join(path, 'metadata') | |
|
671 | os.system('mkdir %s' % (metadata_dir)) | |
|
672 | ||
|
673 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, ##236, file_cadence_millisecs / 1000 | |
|
674 | sample_rate_numerator, sample_rate_denominator, | |
|
675 | metadataFile) | |
|
676 | ||
|
677 | ||
|
678 | self.isConfig = True | |
|
679 | self.currentSample = 0 | |
|
680 | self.oldAverage = 0 | |
|
681 | self.count = 0 | |
|
682 | return | |
|
683 | ||
|
684 | def writeMetadata(self): | |
|
685 | print '[Writing] - Writing metadata' | |
|
686 | start_idx = self.__sample_rate * self.dataOut.utctime | |
|
687 | ||
|
688 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict() | |
|
689 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict() | |
|
690 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict() | |
|
691 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) | |
|
692 | return | |
|
693 | ||
|
694 | ||
|
695 | def timeit(self, toExecute): | |
|
696 | t0 = time() | |
|
697 | toExecute() | |
|
698 | self.executionTime = time() - t0 | |
|
699 | if self.oldAverage is None: self.oldAverage = self.executionTime | |
|
700 | self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0) | |
|
701 | self.count = self.count + 1.0 | |
|
702 | return | |
|
703 | ||
|
704 | ||
|
705 | def writeData(self): | |
|
706 | for i in range(self.dataOut.systemHeaderObj.nSamples): | |
|
707 | for channel in self.dataOut.channelList: | |
|
708 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real | |
|
709 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag | |
|
710 | ||
|
711 | def f(): return self.digitalWriteObj.rf_write(self.arr_data) | |
|
712 | self.timeit(f) | |
|
713 | ||
|
714 | return | |
|
715 | ||
|
716 | def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=100, dirCadence=25, metadataCadence=1, **kwargs): | |
|
717 | ''' | |
|
718 | This method will be called many times so here you should put all your code | |
|
719 | Inputs: | |
|
720 | dataOut: object with the data | |
|
721 | ''' | |
|
722 | # print dataOut.__dict__ | |
|
723 | self.dataOut = dataOut | |
|
724 | if not self.isConfig: | |
|
725 | self.setup(dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, **kwargs) | |
|
726 | self.writeMetadata() | |
|
727 | ||
|
728 | self.writeData() | |
|
729 | ||
|
730 | ## self.currentSample += 1 | |
|
731 | ## if self.dataOut.flagDataAsBlock or self.currentSample == 1: | |
|
732 | ## self.writeMetadata() | |
|
733 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 | |
|
734 | ||
|
735 | def close(self): | |
|
736 | print '[Writing] - Closing files ' | |
|
737 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 | |
|
738 | try: | |
|
739 | self.digitalWriteObj.close() | |
|
740 | except: | |
|
741 | pass | |
|
742 | ||
|
743 | # raise | |
|
744 | if __name__ == '__main__': | |
|
745 | ||
|
746 | readObj = DigitalRFReader() | |
|
747 | ||
|
748 | while True: | |
|
749 | readObj.run(path='/home/jchavez/jicamarca/mocked_data/') | |
|
750 | # readObj.printInfo() | |
|
751 | # readObj.printNumberOfBlock() |
@@ -0,0 +1,15 | |||
|
1 | Lectura | |
|
2 | 200samples -> 0.47m HDD 1000'' | |
|
3 | 200samples -> 6 HDD 100ms file 100s folder | |
|
4 | 200samples -> 0.48ms HDD 100ms file 1000s folder | |
|
5 | 200samples -> 116ms HDD 5000ms file 100s folder | |
|
6 | 200samples -> 182 HDD 10000ms file 100s folder | |
|
7 | 200samples -> 143 HDD 10000ms file 100s folder SSD | |
|
8 | ||
|
9 | Escritura | |
|
10 | 200samples -> 0.78m HDD 100ms file 1000s folder | |
|
11 | 200samples -> 0.066m HDD 100ms file 1000s folder | |
|
12 | 200samples -> 0.30 HDD 100ms file 100s folder | |
|
13 | 200samples -> 0.23 HDD 5000ms file 100s folder | |
|
14 | 200samples -> 0.176 HDD 10000ms file 100s folder | |
|
15 |
@@ -0,0 +1,117 | |||
|
1 | #!/usr/bin/env python | |
|
2 | ''' | |
|
3 | Created on Jul 7, 2014 | |
|
4 | ||
|
5 | @author: roj-idl71 | |
|
6 | ''' | |
|
7 | import os, sys | |
|
8 | ||
|
9 | from schainpy.controller import Project | |
|
10 | ||
|
11 | def main(): | |
|
12 | ||
|
13 | desc = "Testing USRP data reader" | |
|
14 | filename = "schain.xml" | |
|
15 | figpath = "./" | |
|
16 | remotefolder = "/home/wmaster/graficos" | |
|
17 | ||
|
18 | #this controller object save all user configuration and then execute each module | |
|
19 | #with their parameters. | |
|
20 | controllerObj = Project() | |
|
21 | ||
|
22 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
23 | ||
|
24 | #Creating a reader object with its parameters | |
|
25 | #schainpy.model.io.jroIO_usrp.USRPReader.setup() | |
|
26 | readUnitConfObj = controllerObj.addReadUnit(datatype='DigitalRF', | |
|
27 | path='/home/nanosat/data/', | |
|
28 | startDate='2000/07/03', | |
|
29 | endDate='2017/07/03', | |
|
30 | startTime='00:00:00', | |
|
31 | endTime='23:59:59', | |
|
32 | online=0) | |
|
33 | ||
|
34 | # procUnitConfObj0 = controllerObj.addProcUnit(datatype='Voltage', | |
|
35 | # inputId=readUnitConfObj.getId()) | |
|
36 | ||
|
37 | # opObj10 = procUnitConfObj0.addOperation(name='selectHeights') | |
|
38 | # opObj10.addParameter(name='minHei', value='0', format='float') | |
|
39 | # opObj10.addParameter(name='maxHei', value='8', format='float') | |
|
40 | ||
|
41 | # opObj10 = procUnitConfObj0.addOperation(name='setH0') | |
|
42 | # opObj10.addParameter(name='h0', value='5.4', format='float') | |
|
43 | ||
|
44 | # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external') | |
|
45 | # opObj10.addParameter(name='code', value='1,-1', format='intlist') | |
|
46 | # opObj10.addParameter(name='nCode', value='2', format='float') | |
|
47 | # opObj10.addParameter(name='nBaud', value='1', format='float') | |
|
48 | ||
|
49 | # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
|
50 | # opObj10.addParameter(name='n', value='128', format='float') | |
|
51 | ||
|
52 | # opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='external') | |
|
53 | # opObj11.addParameter(name='id', value='121', format='int') | |
|
54 | # opObj11.addParameter(name='wintitle', value='Scope', format='str') | |
|
55 | ||
|
56 | # procUnitConfObj1 = controllerObj.addProcUnit(datatype='Spectra', | |
|
57 | # inputId=procUnitConfObj0.getId()) | |
|
58 | ||
|
59 | # #Creating a processing object with its parameters | |
|
60 | # #schainpy.model.proc.jroproc_spectra.SpectraProc.run() | |
|
61 | # #If you need to add more parameters can use the "addParameter method" | |
|
62 | # procUnitConfObj1.addParameter(name='nFFTPoints', value='8', format='int') | |
|
63 | # procUnitConfObj1.addParameter(name='pairsList', value='(0,1)', format='pairslist') | |
|
64 | ||
|
65 | # opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') | |
|
66 | # opObj10.addParameter(name='n', value='2', format='float') | |
|
67 | # | |
|
68 | #Using internal methods | |
|
69 | #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels() | |
|
70 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
|
71 | # opObj10.addParameter(name='channelList', value='0,1', format='intlist') | |
|
72 | ||
|
73 | #Using internal methods | |
|
74 | #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights() | |
|
75 | # opObj10 = procUnitConfObj1.addOperation(name='selectHeights') | |
|
76 | # opObj10.addParameter(name='minHei', value='90', format='float') | |
|
77 | # opObj10.addParameter(name='maxHei', value='180', format='float') | |
|
78 | ||
|
79 | #Using external methods (new modules) | |
|
80 | # #schainpy.model.proc.jroproc_spectra.IncohInt.setup() | |
|
81 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
82 | # opObj12.addParameter(name='n', value='1', format='int') | |
|
83 | ||
|
84 | #Using external methods (new modules) | |
|
85 | #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup() | |
|
86 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
|
87 | # opObj11.addParameter(name='id', value='11', format='int') | |
|
88 | # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
|
89 | # opObj11.addParameter(name='zmin', value='0', format='int') | |
|
90 | # opObj11.addParameter(name='zmax', value='90', format='int') | |
|
91 | # opObj11.addParameter(name='save', value='1', format='int') | |
|
92 | # opObj11.addParameter(name='xmin', value='-20', format='float') | |
|
93 | # opObj11.addParameter(name='xmax', value='20', format='float') | |
|
94 | ||
|
95 | #Using external methods (new modules) | |
|
96 | #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup() | |
|
97 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
|
98 | # opObj11.addParameter(name='id', value='30', format='int') | |
|
99 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') | |
|
100 | # # opObj11.addParameter(name='zmin', value='0', format='int') | |
|
101 | # # opObj11.addParameter(name='zmax', value='90', format='int') | |
|
102 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
103 | # opObj11.addParameter(name='timerange', value=str(2*60*60), format='int') | |
|
104 | # opObj11.addParameter(name='xmin', value='19.5', format='float') | |
|
105 | # opObj11.addParameter(name='xmax', value='20', format='float') | |
|
106 | ||
|
107 | # opObj11 = procUnitConfObj1.addOperation(name='CrossSpectraPlot', optype='other') | |
|
108 | # opObj11.addParameter(name='id', value='3', format='int') | |
|
109 | # opObj11.addParameter(name='wintitle', value='CrossSpectraPlot', format='str') | |
|
110 | # opObj11.addParameter(name='zmin', value='30', format='int') | |
|
111 | # opObj11.addParameter(name='zmax', value='120', format='int') | |
|
112 | # opObj11.addParameter(name='pairsList', value='(0,1)', format='pairslist') | |
|
113 | ||
|
114 | controllerObj.start() | |
|
115 | ||
|
116 | if __name__ == '__main__': | |
|
117 | main() |
@@ -0,0 +1,98 | |||
|
1 | import os, sys | |
|
2 | ||
|
3 | from schainpy.controller import Project | |
|
4 | ||
|
5 | if __name__ == '__main__': | |
|
6 | ||
|
7 | desc = "Segundo Test" | |
|
8 | filename = "schain.xml" | |
|
9 | ||
|
10 | controllerObj = Project() | |
|
11 | ||
|
12 | controllerObj.setup(id = '191', name='test01', description=desc) | |
|
13 | ||
|
14 | readUnitConfObj = controllerObj.addReadUnit(datatype='VoltageReader', | |
|
15 | path='/home/nanosat/data/John', | |
|
16 | startDate='2010/10/28', | |
|
17 | endDate='2017/10/28', | |
|
18 | startTime='00:00:00', | |
|
19 | endTime='23:59:59', | |
|
20 | online=0, | |
|
21 | walk=0) | |
|
22 | ||
|
23 | opObj00 = readUnitConfObj.addOperation(name='printNumberOfBlock') | |
|
24 | ||
|
25 | procUnitConfObj0 = controllerObj.addProcUnit(datatype='VoltageProc', | |
|
26 | inputId=readUnitConfObj.getId()) | |
|
27 | ||
|
28 | # opObj11 = procUnitConfObj0.addOperation(name='Scope', optype='external') | |
|
29 | # opObj11.addParameter(name='id', value='121', format='int') | |
|
30 | # opObj11.addParameter(name='wintitle', value='Scope', format='str') | |
|
31 | ||
|
32 | opObj10 = procUnitConfObj0.addOperation(name='DigitalRFWriter', optype='other') | |
|
33 | opObj10.addParameter(name='path', value='/home/nanosat/data/digitalrf', format='str') | |
|
34 | # opObj10.addParameter(name='minHei', value='0', format='float') | |
|
35 | # opObj10.addParameter(name='maxHei', value='8', format='float') | |
|
36 | ||
|
37 | # opObj10 = procUnitConfObj0.addOperation(name='filterByHeights') | |
|
38 | # opObj10.addParameter(name='window', value='2', format='float') | |
|
39 | ||
|
40 | # opObj10 = procUnitConfObj0.addOperation(name='Decoder', optype='external') | |
|
41 | # opObj10.addParameter(name='code', value='1,-1', format='intlist') | |
|
42 | # opObj10.addParameter(name='nCode', value='2', format='float') | |
|
43 | # opObj10.addParameter(name='nBaud', value='1', format='float') | |
|
44 | ||
|
45 | ||
|
46 | # opObj10 = procUnitConfObj0.addOperation(name='CohInt', optype='external') | |
|
47 | # opObj10.addParameter(name='n', value='1296', format='float') | |
|
48 | ||
|
49 | # procUnitConfObj1 = controllerObj.addProcUnit(datatype='SpectraProc', | |
|
50 | # inputId=procUnitConfObj0.getId()) | |
|
51 | ||
|
52 | #Creating a processing object with its parameters | |
|
53 | #schainpy.model.proc.jroproc_spectra.SpectraProc.run() | |
|
54 | #If you need to add more parameters can use the "addParameter method" | |
|
55 | # procUnitConfObj1.addParameter(name='nFFTPoints', value='128', format='int') | |
|
56 | ||
|
57 | # opObj10 = procUnitConfObj1.addOperation(name='IncohInt', optype='external') | |
|
58 | # opObj10.addParameter(name='n', value='2', format='float') | |
|
59 | ||
|
60 | #Using internal methods | |
|
61 | #schainpy.model.proc.jroproc_spectra.SpectraProc.selectChannels() | |
|
62 | # opObj10 = procUnitConfObj1.addOperation(name='selectChannels') | |
|
63 | # opObj10.addParameter(name='channelList', value='0,1', format='intlist') | |
|
64 | ||
|
65 | #Using internal methods | |
|
66 | #schainpy.model.proc.jroproc_spectra.SpectraProc.selectHeights() | |
|
67 | # opObj10 = procUnitConfObj1.addOperation(name='selectHeights') | |
|
68 | # opObj10.addParameter(name='minHei', value='90', format='float') | |
|
69 | # opObj10.addParameter(name='maxHei', value='180', format='float') | |
|
70 | ||
|
71 | #Using external methods (new modules) | |
|
72 | # #schainpy.model.proc.jroproc_spectra.IncohInt.setup() | |
|
73 | # opObj12 = procUnitConfObj1.addOperation(name='IncohInt', optype='other') | |
|
74 | # opObj12.addParameter(name='n', value='1', format='int') | |
|
75 | ||
|
76 | #Using external methods (new modules) | |
|
77 | #schainpy.model.graphics.jroplot_spectra.SpectraPlot.setup() | |
|
78 | # opObj11 = procUnitConfObj1.addOperation(name='SpectraPlot', optype='external') | |
|
79 | # opObj11.addParameter(name='id', value='11', format='int') | |
|
80 | # opObj11.addParameter(name='wintitle', value='SpectraPlot', format='str') | |
|
81 | # opObj11.addParameter(name='zmin', value='-60', format='int') | |
|
82 | # opObj11.addParameter(name='zmax', value='10', format='int') | |
|
83 | # opObj11.addParameter(name='save', value='1', format='int') | |
|
84 | ||
|
85 | # #Using external methods (new modules) | |
|
86 | # #schainpy.model.graphics.jroplot_spectra.RTIPlot.setup() | |
|
87 | # opObj11 = procUnitConfObj1.addOperation(name='RTIPlot', optype='other') | |
|
88 | # opObj11.addParameter(name='id', value='30', format='int') | |
|
89 | # opObj11.addParameter(name='wintitle', value='RTI', format='str') | |
|
90 | # opObj11.addParameter(name='zmin', value='-60', format='int') | |
|
91 | # opObj11.addParameter(name='zmax', value='-10', format='int') | |
|
92 | # opObj11.addParameter(name='showprofile', value='1', format='int') | |
|
93 | # # opObj11.addParameter(name='timerange', value=str(5*60*60*60), format='int') | |
|
94 | # opObj11.addParameter(name='xmin', value='14', format='float') | |
|
95 | # opObj11.addParameter(name='xmax', value='23.9', format='float') | |
|
96 | # opObj11.addParameter(name='save', value='1', format='int') | |
|
97 | ||
|
98 | controllerObj.start() |
@@ -0,0 +1,1 | |||
|
1 | You should install "digital_rf_hdf5" module if you want to read USRP data |
@@ -100,16 +100,16 ENV/ | |||
|
100 | 100 | # eclipse |
|
101 | 101 | .project |
|
102 | 102 | .pydevproject |
|
103 | ||
|
104 | 103 | # vscode |
|
105 | 104 | |
|
106 | 105 | .vscode |
|
107 | 106 | |
|
108 | schainpy/scripts/ | |
|
109 | 107 | schaingui/node_modules/ |
|
108 | schainpy/scripts/ | |
|
110 | 109 | .svn/ |
|
111 | 110 | *.png |
|
112 | 111 | *.pyc |
|
113 | *.xml | |
|
112 | schainpy/scripts | |
|
113 | .vscode | |
|
114 | trash | |
|
114 | 115 | *.log |
|
115 | trash No newline at end of file |
@@ -31,18 +31,17 PREFIX = 'experiment' | |||
|
31 | 31 | |
|
32 | 32 | @click.command() |
|
33 | 33 | @click.option('--version', '-v', is_flag=True, callback=print_version, help='SChain version', type=str) |
|
34 | @click.option('--xml', '-x', default=None, help='run an XML file', type=click.Path(exists=True, resolve_path=True)) | |
|
35 | 34 | @click.argument('command', default='run', required=True) |
|
36 | 35 | @click.argument('nextcommand', default=None, required=False, type=str) |
|
37 |
def main(command, nextcommand, version |
|
|
36 | def main(command, nextcommand, version): | |
|
38 | 37 | """COMMAND LINE INTERFACE FOR SIGNAL CHAIN - JICAMARCA RADIO OBSERVATORY \n |
|
39 | 38 | Available commands.\n |
|
40 | 39 | --xml: runs a schain XML generated file\n |
|
41 | 40 | run: runs any python script starting 'experiment_'\n |
|
42 | 41 | generate: generates a template schain script\n |
|
43 | 42 | search: return avilable operations, procs or arguments of the give operation/proc\n""" |
|
44 | if xml is not None: | |
|
45 |
runFromXML( |
|
|
43 | if command == 'xml': | |
|
44 | runFromXML(nextcommand) | |
|
46 | 45 | elif command == 'generate': |
|
47 | 46 | generate() |
|
48 | 47 | elif command == 'test': |
@@ -54,6 +53,7 def main(command, nextcommand, version, xml): | |||
|
54 | 53 | else: |
|
55 | 54 | log.error('Command {} is not defined'.format(command)) |
|
56 | 55 | |
|
56 | ||
|
57 | 57 | def check_module(possible, instance): |
|
58 | 58 | def check(x): |
|
59 | 59 | try: |
@@ -77,19 +77,23 def search(nextcommand): | |||
|
77 | 77 | log.error('There is no Operation/ProcessingUnit to search') |
|
78 | 78 | elif nextcommand == 'procs': |
|
79 | 79 | procs = paramsFinder.getProcs() |
|
80 | log.success('Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs))) | |
|
80 | log.success( | |
|
81 | 'Current ProcessingUnits are:\n\033[1m{}\033[0m'.format('\n'.join(procs))) | |
|
81 | 82 | |
|
82 | 83 | elif nextcommand == 'operations': |
|
83 | 84 | operations = paramsFinder.getOperations() |
|
84 |
log.success('Current Operations are:\n\033[1m{}\033[0m'.format( |
|
|
85 | log.success('Current Operations are:\n\033[1m{}\033[0m'.format( | |
|
86 | '\n'.join(operations))) | |
|
85 | 87 | else: |
|
86 | 88 | try: |
|
87 | 89 | args = paramsFinder.getArgs(nextcommand) |
|
88 | log.warning('Use this feature with caution. It may not return all the allowed arguments') | |
|
90 | log.warning( | |
|
91 | 'Use this feature with caution. It may not return all the allowed arguments') | |
|
89 | 92 | if len(args) == 0: |
|
90 | 93 | log.success('{} has no arguments'.format(nextcommand)) |
|
91 | 94 | else: |
|
92 |
log.success('Showing arguments |
|
|
95 | log.success('Showing {} arguments:\n\033[1m{}\033[0m'.format( | |
|
96 | nextcommand, '\n'.join(args))) | |
|
93 | 97 | except Exception as e: |
|
94 | 98 | log.error('Module {} does not exists'.format(nextcommand)) |
|
95 | 99 | allModules = paramsFinder.getAll() |
@@ -117,12 +121,18 def runschain(nextcommand): | |||
|
117 | 121 | |
|
118 | 122 | def basicInputs(): |
|
119 | 123 | inputs = {} |
|
120 | inputs['desc'] = click.prompt('Enter a description', default="A schain project", type=str) | |
|
121 | inputs['name'] = click.prompt('Name of the project', default="project", type=str) | |
|
122 | inputs['path'] = click.prompt('Data path', default=os.getcwd(), type=click.Path(exists=True, resolve_path=True)) | |
|
123 | inputs['startDate'] = click.prompt('Start date', default='1970/01/01', type=str) | |
|
124 |
inputs[' |
|
|
125 | inputs['startHour'] = click.prompt('Start hour', default='00:00:00', type=str) | |
|
124 | inputs['desc'] = click.prompt( | |
|
125 | 'Enter a description', default="A schain project", type=str) | |
|
126 | inputs['name'] = click.prompt( | |
|
127 | 'Name of the project', default="project", type=str) | |
|
128 | inputs['path'] = click.prompt('Data path', default=os.getcwd( | |
|
129 | ), type=click.Path(exists=True, resolve_path=True)) | |
|
130 | inputs['startDate'] = click.prompt( | |
|
131 | 'Start date', default='1970/01/01', type=str) | |
|
132 | inputs['endDate'] = click.prompt( | |
|
133 | 'End date', default='2017/12/31', type=str) | |
|
134 | inputs['startHour'] = click.prompt( | |
|
135 | 'Start hour', default='00:00:00', type=str) | |
|
126 | 136 | inputs['endHour'] = click.prompt('End hour', default='23:59:59', type=str) |
|
127 | 137 | inputs['figpath'] = inputs['path'] + '/figs' |
|
128 | 138 | return inputs |
@@ -132,7 +142,8 def generate(): | |||
|
132 | 142 | inputs = basicInputs() |
|
133 | 143 | inputs['multiprocess'] = click.confirm('Is this a multiprocess script?') |
|
134 | 144 | if inputs['multiprocess']: |
|
135 |
inputs['nProcess'] = click.prompt( |
|
|
145 | inputs['nProcess'] = click.prompt( | |
|
146 | 'How many process?', default=cpu_count(), type=int) | |
|
136 | 147 | current = templates.multiprocess.format(**inputs) |
|
137 | 148 | else: |
|
138 | 149 | current = templates.basic.format(**inputs) |
@@ -1,11 +1,10 | |||
|
1 | 1 | basic = '''from schainpy.controller import Project |
|
2 | 2 | |
|
3 | 3 | desc = "{desc}" |
|
4 | project = Project() | |
|
5 | project.setup(id='200', name="{name}", description=desc) | |
|
4 | 6 | |
|
5 | controller = Project() | |
|
6 | controller.setup(id='191', name="{name}", description=desc) | |
|
7 | ||
|
8 | readUnitConf = controller.addReadUnit(datatype='VoltageReader', | |
|
7 | voltage_reader = project.addReadUnit(datatype='VoltageReader', | |
|
9 | 8 | path="{path}", |
|
10 | 9 | startDate="{startDate}", |
|
11 | 10 | endDate="{endDate}", |
@@ -16,60 +15,76 readUnitConf = controller.addReadUnit(datatype='VoltageReader', | |||
|
16 | 15 | walk=1, |
|
17 | 16 | ) |
|
18 | 17 | |
|
19 |
|
|
|
18 | voltage_proc = project.addProcUnit(datatype='VoltageProc', inputId=voltage_reader.getId()) | |
|
20 | 19 | |
|
21 |
|
|
|
22 |
|
|
|
20 | profile = voltage_proc.addOperation(name='ProfileSelector', optype='other') | |
|
21 | profile.addParameter(name='profileRangeList', value='120,183', format='intlist') | |
|
23 | 22 | |
|
24 |
|
|
|
25 |
|
|
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
|
|
|
23 | rti = voltage_proc.addOperation(name='RTIPlot', optype='other') | |
|
24 | rti.addParameter(name='wintitle', value='Jicamarca Radio Observatory', format='str') | |
|
25 | rti.addParameter(name='showprofile', value='0', format='int') | |
|
26 | rti.addParameter(name='xmin', value='0', format='int') | |
|
27 | rti.addParameter(name='xmax', value='24', format='int') | |
|
28 | rti.addParameter(name='figpath', value="{figpath}", format='str') | |
|
29 | rti.addParameter(name='wr_period', value='5', format='int') | |
|
30 | rti.addParameter(name='exp_code', value='22', format='int') | |
|
32 | 31 | |
|
33 | 32 | |
|
34 | 33 | controller.start() |
|
35 | 34 | ''' |
|
36 | 35 | |
|
37 |
multiprocess = '''from schainpy.controller import Project, |
|
|
38 | ||
|
36 | multiprocess = '''from schainpy.controller import Project, MPProject | |
|
37 | from time import sleep | |
|
39 | 38 | desc = "{desc}" |
|
40 | 39 | |
|
41 | def fiber(cursor, skip, q, day): | |
|
42 | controller = Project() | |
|
43 | controller.setup(id='191', name="{name}", description=desc) | |
|
44 | ||
|
45 | readUnitConf = controller.addReadUnit(datatype='SpectraReader', | |
|
46 | path="{path}", | |
|
47 | startDate=day, | |
|
48 | endDate=day, | |
|
49 | startTime="{startHour}", | |
|
50 | endTime="{endHour}", | |
|
51 | online=0, | |
|
52 | queue=q, | |
|
53 | cursor=cursor, | |
|
54 | skip=skip, | |
|
55 | verbose=1, | |
|
56 | walk=1, | |
|
57 | ) | |
|
58 | ||
|
59 | procUnitConf1 = controller.addProcUnit(datatype='Spectra', inputId=readUnitConf.getId()) | |
|
60 | ||
|
61 | procUnitConf2 = controller.addProcUnit(datatype='ParametersProc', inputId=readUnitConf.getId()) | |
|
62 | opObj11 = procUnitConf2.addOperation(name='SpectralMoments', optype='other') | |
|
63 | ||
|
64 | opObj12 = procUnitConf2.addOperation(name='PublishData', optype='other') | |
|
65 | opObj12.addParameter(name='zeromq', value=1, format='int') | |
|
66 | opObj12.addParameter(name='verbose', value=0, format='bool') | |
|
67 | ||
|
68 | controller.start() | |
|
69 | ||
|
70 | ||
|
71 | if __name__ == '__main__': | |
|
72 | multiSchain(fiber, nProcess={nProcess}, startDate="{startDate}", endDate="{endDate}") | |
|
40 | #################### | |
|
41 | # PLOTTER RECEIVER # | |
|
42 | #################### | |
|
43 | plotter = Project() | |
|
44 | plotter.setup(id='100', name='receiver', description=desc) | |
|
45 | ||
|
46 | receiver_plot = plotter.addProcUnit(name='PlotterReceiver') | |
|
47 | receiver_plot.addParameter(name='throttle', value=20, format='int') | |
|
48 | receiver_plot.addParameter(name='plottypes', value='rti', format='str') | |
|
49 | ||
|
50 | rti = receiver_plot.addOperation(name='PlotRTIData', optype='other') | |
|
51 | rti.addParameter(name='zmin', value='-40.0', format='float') | |
|
52 | rti.addParameter(name='zmax', value='100.0', format='float') | |
|
53 | rti.addParameter(name='decimation', value='200', format='int') | |
|
54 | rti.addParameter(name='xmin', value='0.0', format='int') | |
|
55 | rti.addParameter(name='colormap', value='jet', format='str') | |
|
56 | ||
|
57 | plotter.start() | |
|
58 | ||
|
59 | sleep(2) | |
|
60 | ||
|
61 | ################ | |
|
62 | # DATA EMITTER # | |
|
63 | ################ | |
|
64 | project = Project() | |
|
65 | project.setup(id='200', name="{name}", description=desc) | |
|
66 | ||
|
67 | spectra_reader = project.addReadUnit(datatype='SpectraReader', | |
|
68 | path="{path}", | |
|
69 | startDate={startDate}, | |
|
70 | endDate={endDate}, | |
|
71 | startTime="{startHour}", | |
|
72 | endTime="{endHour}", | |
|
73 | online=0, | |
|
74 | verbose=1, | |
|
75 | walk=1, | |
|
76 | ) | |
|
77 | ||
|
78 | spectra_proc = project.addProcUnit(datatype='Spectra', inputId=spectra_reader.getId()) | |
|
79 | ||
|
80 | parameters_proc = project.addProcUnit(datatype='ParametersProc', inputId=spectra_proc.getId()) | |
|
81 | moments = parameters_proc.addOperation(name='SpectralMoments', optype='other') | |
|
82 | ||
|
83 | publish = parameters_proc.addOperation(name='PublishData', optype='other') | |
|
84 | publish.addParameter(name='zeromq', value=1, format='int') | |
|
85 | publish.addParameter(name='verbose', value=0, format='bool') | |
|
86 | ||
|
87 | MPProject(project, 16) | |
|
73 | 88 | |
|
74 | 89 | |
|
75 | 90 | ''' |
@@ -1,11 +1,11 | |||
|
1 | 1 | ## CHANGELOG: |
|
2 | 2 | |
|
3 | 3 | ### 2.3 |
|
4 |
* Added high order function ` |
|
|
4 | * Added high order function `MPProject` for multiprocessing scripts. | |
|
5 | 5 | * Added two new Processing Units `PublishData` and `ReceiverData` for receiving and sending dataOut through multiple ways (tcp, ipc, inproc). |
|
6 | 6 | * Added a new graphics Processing Unit `PlotterReceiver`. It is decoupled from normal processing sequence with support for data generated by multiprocessing scripts. |
|
7 | 7 | * Added support for sending realtime graphic to web server. |
|
8 |
* GUI command `schain` |
|
|
8 | * GUI command `schain` is now `schainGUI`. | |
|
9 | 9 | * Added a CLI tool named `schain`. |
|
10 | 10 | * Scripts templates can be now generated with `schain generate`. |
|
11 | 11 | * Now it is possible to search Processing Units and Operations with `schain search [module]` to get the right name and its allowed parameters. |
@@ -21,7 +21,7 | |||
|
21 | 21 | ### 2.2.6 |
|
22 | 22 | * Graphics generated by the GUI are now the same as generated by scripts. Issue #1074. |
|
23 | 23 | * Added support for C extensions. |
|
24 |
* |
|
|
24 | * Function `hildebrand_sehkon` optimized with a C wrapper. | |
|
25 | 25 | * Numpy version updated. |
|
26 | 26 | * Migration to GIT. |
|
27 | 27 |
@@ -24,6 +24,7 DTYPES = { | |||
|
24 | 24 | 'Spectra': '.pdata' |
|
25 | 25 | } |
|
26 | 26 | |
|
27 | ||
|
27 | 28 | def MPProject(project, n=cpu_count()): |
|
28 | 29 | ''' |
|
29 | 30 | Project wrapper to run schain in n processes |
@@ -34,8 +35,8 def MPProject(project, n=cpu_count()): | |||
|
34 | 35 | dt1 = op.getParameterValue('startDate') |
|
35 | 36 | dt2 = op.getParameterValue('endDate') |
|
36 | 37 | days = (dt2 - dt1).days |
|
37 | ||
|
38 | for day in range(days+1): | |
|
38 | ||
|
39 | for day in range(days + 1): | |
|
39 | 40 | skip = 0 |
|
40 | 41 | cursor = 0 |
|
41 | 42 | processes = [] |
@@ -43,17 +44,17 def MPProject(project, n=cpu_count()): | |||
|
43 | 44 | dt_str = dt.strftime('%Y/%m/%d') |
|
44 | 45 | reader = JRODataReader() |
|
45 | 46 | paths, files = reader.searchFilesOffLine(path=rconf.path, |
|
46 | startDate=dt, | |
|
47 | endDate=dt, | |
|
48 | ext=DTYPES[rconf.datatype]) | |
|
47 | startDate=dt, | |
|
48 | endDate=dt, | |
|
49 | ext=DTYPES[rconf.datatype]) | |
|
49 | 50 | nFiles = len(files) |
|
50 | 51 | if nFiles == 0: |
|
51 | 52 | continue |
|
52 |
skip = int(math.ceil(nFiles/n)) |
|
|
53 | while nFiles > cursor*skip: | |
|
54 |
rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor, |
|
|
55 | skip=skip) | |
|
56 |
p = project.clone() |
|
|
53 | skip = int(math.ceil(nFiles / n)) | |
|
54 | while nFiles > cursor * skip: | |
|
55 | rconf.update(startDate=dt_str, endDate=dt_str, cursor=cursor, | |
|
56 | skip=skip) | |
|
57 | p = project.clone() | |
|
57 | 58 | p.start() |
|
58 | 59 | processes.append(p) |
|
59 | 60 | cursor += 1 |
@@ -72,6 +73,7 def MPProject(project, n=cpu_count()): | |||
|
72 | 73 | |
|
73 | 74 | time.sleep(3) |
|
74 | 75 | |
|
76 | ||
|
75 | 77 | class ParameterConf(): |
|
76 | 78 | |
|
77 | 79 | id = None |
@@ -108,7 +110,7 class ParameterConf(): | |||
|
108 | 110 | return self.__formated_value |
|
109 | 111 | |
|
110 | 112 | if value == '': |
|
111 | raise ValueError, '%s: This parameter value is empty' %self.name | |
|
113 | raise ValueError, '%s: This parameter value is empty' % self.name | |
|
112 | 114 | |
|
113 | 115 | if format == 'list': |
|
114 | 116 | strList = value.split(',') |
@@ -174,16 +176,16 class ParameterConf(): | |||
|
174 | 176 | new_value = ast.literal_eval(value) |
|
175 | 177 | |
|
176 | 178 | if type(new_value) not in (tuple, list): |
|
177 | raise ValueError, '%s has to be a tuple or list of pairs' %value | |
|
179 | raise ValueError, '%s has to be a tuple or list of pairs' % value | |
|
178 | 180 | |
|
179 | 181 | if type(new_value[0]) not in (tuple, list): |
|
180 | 182 | if len(new_value) != 2: |
|
181 | raise ValueError, '%s has to be a tuple or list of pairs' %value | |
|
183 | raise ValueError, '%s has to be a tuple or list of pairs' % value | |
|
182 | 184 | new_value = [new_value] |
|
183 | 185 | |
|
184 | 186 | for thisPair in new_value: |
|
185 | 187 | if len(thisPair) != 2: |
|
186 | raise ValueError, '%s has to be a tuple or list of pairs' %value | |
|
188 | raise ValueError, '%s has to be a tuple or list of pairs' % value | |
|
187 | 189 | |
|
188 | 190 | self.__formated_value = new_value |
|
189 | 191 | |
@@ -253,13 +255,14 class ParameterConf(): | |||
|
253 | 255 | self.value = parmElement.get('value') |
|
254 | 256 | self.format = str.lower(parmElement.get('format')) |
|
255 | 257 | |
|
256 | #Compatible with old signal chain version | |
|
258 | # Compatible with old signal chain version | |
|
257 | 259 | if self.format == 'int' and self.name == 'idfigure': |
|
258 | 260 | self.name = 'id' |
|
259 | 261 | |
|
260 | 262 | def printattr(self): |
|
261 | 263 | |
|
262 | print 'Parameter[%s]: name = %s, value = %s, format = %s' %(self.id, self.name, self.value, self.format) | |
|
264 | print 'Parameter[%s]: name = %s, value = %s, format = %s' % (self.id, self.name, self.value, self.format) | |
|
265 | ||
|
263 | 266 | |
|
264 | 267 | class OperationConf(): |
|
265 | 268 | |
@@ -279,10 +282,9 class OperationConf(): | |||
|
279 | 282 | self.priority = None |
|
280 | 283 | self.type = 'self' |
|
281 | 284 | |
|
282 | ||
|
283 | 285 | def __getNewId(self): |
|
284 | 286 | |
|
285 | return int(self.id)*10 + len(self.parmConfObjList) + 1 | |
|
287 | return int(self.id) * 10 + len(self.parmConfObjList) + 1 | |
|
286 | 288 | |
|
287 | 289 | def updateId(self, new_id): |
|
288 | 290 | |
@@ -291,7 +293,7 class OperationConf(): | |||
|
291 | 293 | n = 1 |
|
292 | 294 | for parmObj in self.parmConfObjList: |
|
293 | 295 | |
|
294 | idParm = str(int(new_id)*10 + n) | |
|
296 | idParm = str(int(new_id) * 10 + n) | |
|
295 | 297 | parmObj.updateId(idParm) |
|
296 | 298 | |
|
297 | 299 | n += 1 |
@@ -329,15 +331,14 class OperationConf(): | |||
|
329 | 331 | def getParameterValue(self, parameterName): |
|
330 | 332 | |
|
331 | 333 | parameterObj = self.getParameterObj(parameterName) |
|
332 | ||
|
334 | ||
|
333 | 335 | # if not parameterObj: |
|
334 | 336 | # return None |
|
335 | ||
|
337 | ||
|
336 | 338 | value = parameterObj.getValue() |
|
337 | 339 | |
|
338 | 340 | return value |
|
339 | 341 | |
|
340 | ||
|
341 | 342 | def getKwargs(self): |
|
342 | 343 | |
|
343 | 344 | kwargs = {} |
@@ -367,7 +368,7 class OperationConf(): | |||
|
367 | 368 | self.parmConfObjList = [] |
|
368 | 369 | |
|
369 | 370 | def addParameter(self, name, value, format='str'): |
|
370 | ||
|
371 | ||
|
371 | 372 | if value is None: |
|
372 | 373 | return None |
|
373 | 374 | id = self.__getNewId() |
@@ -405,8 +406,8 class OperationConf(): | |||
|
405 | 406 | self.type = opElement.get('type') |
|
406 | 407 | self.priority = opElement.get('priority') |
|
407 | 408 | |
|
408 | #Compatible with old signal chain version | |
|
409 | #Use of 'run' method instead 'init' | |
|
409 | # Compatible with old signal chain version | |
|
410 | # Use of 'run' method instead 'init' | |
|
410 | 411 | if self.type == 'self' and self.name == 'init': |
|
411 | 412 | self.name = 'run' |
|
412 | 413 | |
@@ -418,8 +419,8 class OperationConf(): | |||
|
418 | 419 | parmConfObj = ParameterConf() |
|
419 | 420 | parmConfObj.readXml(parmElement) |
|
420 | 421 | |
|
421 | #Compatible with old signal chain version | |
|
422 | #If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
|
422 | # Compatible with old signal chain version | |
|
423 | # If an 'plot' OPERATION is found, changes name operation by the value of its type PARAMETER | |
|
423 | 424 | if self.type != 'self' and self.name == 'Plot': |
|
424 | 425 | if parmConfObj.format == 'str' and parmConfObj.name == 'type': |
|
425 | 426 | self.name = parmConfObj.value |
@@ -429,22 +430,21 class OperationConf(): | |||
|
429 | 430 | |
|
430 | 431 | def printattr(self): |
|
431 | 432 | |
|
432 | print '%s[%s]: name = %s, type = %s, priority = %s' %(self.ELEMENTNAME, | |
|
433 | self.id, | |
|
434 | self.name, | |
|
435 | self.type, | |
|
436 | self.priority) | |
|
433 | print '%s[%s]: name = %s, type = %s, priority = %s' % (self.ELEMENTNAME, | |
|
434 | self.id, | |
|
435 | self.name, | |
|
436 | self.type, | |
|
437 | self.priority) | |
|
437 | 438 | |
|
438 | 439 | for parmConfObj in self.parmConfObjList: |
|
439 | 440 | parmConfObj.printattr() |
|
440 | 441 | |
|
441 | 442 | def createObject(self, plotter_queue=None): |
|
442 | 443 | |
|
443 | ||
|
444 | 444 | if self.type == 'self': |
|
445 | 445 | raise ValueError, 'This operation type cannot be created' |
|
446 | 446 | |
|
447 |
if self.type == 'plotter': |
|
|
447 | if self.type == 'plotter': | |
|
448 | 448 | if not plotter_queue: |
|
449 | 449 | raise ValueError, 'plotter_queue is not defined. Use:\nmyProject = Project()\nmyProject.setPlotterQueue(plotter_queue)' |
|
450 | 450 | |
@@ -489,11 +489,11 class ProcUnitConf(): | |||
|
489 | 489 | |
|
490 | 490 | def __getPriority(self): |
|
491 | 491 | |
|
492 | return len(self.opConfObjList)+1 | |
|
492 | return len(self.opConfObjList) + 1 | |
|
493 | 493 | |
|
494 | 494 | def __getNewId(self): |
|
495 | 495 | |
|
496 | return int(self.id)*10 + len(self.opConfObjList) + 1 | |
|
496 | return int(self.id) * 10 + len(self.opConfObjList) + 1 | |
|
497 | 497 | |
|
498 | 498 | def getElementName(self): |
|
499 | 499 | |
@@ -505,18 +505,17 class ProcUnitConf(): | |||
|
505 | 505 | |
|
506 | 506 | def updateId(self, new_id, parentId=parentId): |
|
507 | 507 | |
|
508 | new_id = int(parentId) * 10 + (int(self.id) % 10) | |
|
509 | new_inputId = int(parentId) * 10 + (int(self.inputId) % 10) | |
|
508 | 510 | |
|
509 | new_id = int(parentId)*10 + (int(self.id) % 10) | |
|
510 | new_inputId = int(parentId)*10 + (int(self.inputId) % 10) | |
|
511 | ||
|
512 | #If this proc unit has not inputs | |
|
511 | # If this proc unit has not inputs | |
|
513 | 512 | if self.inputId == '0': |
|
514 | 513 | new_inputId = 0 |
|
515 | 514 | |
|
516 | 515 | n = 1 |
|
517 | 516 | for opConfObj in self.opConfObjList: |
|
518 | 517 | |
|
519 | idOp = str(int(new_id)*10 + n) | |
|
518 | idOp = str(int(new_id) * 10 + n) | |
|
520 | 519 | opConfObj.updateId(idOp) |
|
521 | 520 | |
|
522 | 521 | n += 1 |
@@ -525,7 +524,6 class ProcUnitConf(): | |||
|
525 | 524 | self.id = str(new_id) |
|
526 | 525 | self.inputId = str(new_inputId) |
|
527 | 526 | |
|
528 | ||
|
529 | 527 | def getInputId(self): |
|
530 | 528 | |
|
531 | 529 | return self.inputId |
@@ -559,18 +557,18 class ProcUnitConf(): | |||
|
559 | 557 | |
|
560 | 558 | def setup(self, id, name, datatype, inputId, parentId=None): |
|
561 | 559 | |
|
562 | #Compatible with old signal chain version | |
|
563 | if datatype==None and name==None: | |
|
560 | # Compatible with old signal chain version | |
|
561 | if datatype == None and name == None: | |
|
564 | 562 | raise ValueError, 'datatype or name should be defined' |
|
565 | 563 | |
|
566 | if name==None: | |
|
564 | if name == None: | |
|
567 | 565 | if 'Proc' in datatype: |
|
568 | 566 | name = datatype |
|
569 | 567 | else: |
|
570 | name = '%sProc' %(datatype) | |
|
568 | name = '%sProc' % (datatype) | |
|
571 | 569 | |
|
572 | if datatype==None: | |
|
573 | datatype = name.replace('Proc','') | |
|
570 | if datatype == None: | |
|
571 | datatype = name.replace('Proc', '') | |
|
574 | 572 | |
|
575 | 573 | self.id = str(id) |
|
576 | 574 | self.name = name |
@@ -650,16 +648,15 class ProcUnitConf(): | |||
|
650 | 648 | |
|
651 | 649 | def printattr(self): |
|
652 | 650 | |
|
653 | print '%s[%s]: name = %s, datatype = %s, inputId = %s' %(self.ELEMENTNAME, | |
|
654 | self.id, | |
|
655 | self.name, | |
|
656 | self.datatype, | |
|
657 | self.inputId) | |
|
658 | ||
|
651 | print '%s[%s]: name = %s, datatype = %s, inputId = %s' % (self.ELEMENTNAME, | |
|
652 | self.id, | |
|
653 | self.name, | |
|
654 | self.datatype, | |
|
655 | self.inputId) | |
|
656 | ||
|
659 | 657 | for opConfObj in self.opConfObjList: |
|
660 | 658 | opConfObj.printattr() |
|
661 | 659 | |
|
662 | ||
|
663 | 660 | def getKwargs(self): |
|
664 | 661 | |
|
665 | 662 | opObj = self.opConfObjList[0] |
@@ -675,10 +672,11 class ProcUnitConf(): | |||
|
675 | 672 | |
|
676 | 673 | for opConfObj in self.opConfObjList: |
|
677 | 674 | |
|
678 | if opConfObj.type=='self' and self.name=='run': | |
|
675 | if opConfObj.type == 'self' and self.name == 'run': | |
|
679 | 676 | continue |
|
680 | elif opConfObj.type=='self': | |
|
681 |
procUnitObj.addOperationKwargs( |
|
|
677 | elif opConfObj.type == 'self': | |
|
678 | procUnitObj.addOperationKwargs( | |
|
679 | opConfObj.id, **opConfObj.getKwargs()) | |
|
682 | 680 | continue |
|
683 | 681 | |
|
684 | 682 | opObj = opConfObj.createObject(plotter_queue) |
@@ -704,10 +702,10 class ProcUnitConf(): | |||
|
704 | 702 | |
|
705 | 703 | kwargs[parmConfObj.name] = parmConfObj.getValue() |
|
706 | 704 | |
|
707 |
sts = self.procUnitObj.call(opType |
|
|
708 |
opName |
|
|
709 |
opId |
|
|
710 | ||
|
705 | sts = self.procUnitObj.call(opType=opConfObj.type, | |
|
706 | opName=opConfObj.name, | |
|
707 | opId=opConfObj.id) | |
|
708 | ||
|
711 | 709 | is_ok = is_ok or sts |
|
712 | 710 | |
|
713 | 711 | return is_ok |
@@ -725,6 +723,7 class ProcUnitConf(): | |||
|
725 | 723 | |
|
726 | 724 | return |
|
727 | 725 | |
|
726 | ||
|
728 | 727 | class ReadUnitConf(ProcUnitConf): |
|
729 | 728 | |
|
730 | 729 | path = None |
@@ -754,10 +753,9 class ReadUnitConf(ProcUnitConf): | |||
|
754 | 753 | def setup(self, id, name, datatype, path='', startDate='', endDate='', |
|
755 | 754 | startTime='', endTime='', parentId=None, server=None, **kwargs): |
|
756 | 755 | |
|
757 | #Compatible with old signal chain version | |
|
758 | if datatype==None and name==None: | |
|
756 | # Compatible with old signal chain version | |
|
757 | if datatype == None and name == None: | |
|
759 | 758 | raise ValueError, 'datatype or name should be defined' |
|
760 | ||
|
761 | 759 | if name == None: |
|
762 | 760 | if 'Reader' in datatype: |
|
763 | 761 | name = datatype |
@@ -792,15 +790,16 class ReadUnitConf(ProcUnitConf): | |||
|
792 | 790 | if 'Reader' in datatype: |
|
793 | 791 | self.name = datatype |
|
794 | 792 | else: |
|
795 | self.name = '%sReader' %(datatype) | |
|
793 | self.name = '%sReader' % (datatype) | |
|
796 | 794 | self.datatype = self.name.replace('Reader', '') |
|
797 | 795 | |
|
798 |
attrs = ('path', 'startDate', 'endDate', |
|
|
799 | ||
|
796 | attrs = ('path', 'startDate', 'endDate', | |
|
797 | 'startTime', 'endTime', 'parentId') | |
|
798 | ||
|
800 | 799 | for attr in attrs: |
|
801 | 800 | if attr in kwargs: |
|
802 | 801 | setattr(self, attr, kwargs.pop(attr)) |
|
803 | ||
|
802 | ||
|
804 | 803 | self.inputId = '0' |
|
805 | 804 | self.updateRunOperation(**kwargs) |
|
806 | 805 | |
@@ -813,21 +812,26 class ReadUnitConf(ProcUnitConf): | |||
|
813 | 812 | |
|
814 | 813 | def addRunOperation(self, **kwargs): |
|
815 | 814 | |
|
816 |
opObj = self.addOperation(name |
|
|
815 | opObj = self.addOperation(name='run', optype='self') | |
|
817 | 816 | |
|
818 | 817 | if self.server is None: |
|
819 | opObj.addParameter(name='datatype', value=self.datatype, format='str') | |
|
818 | opObj.addParameter( | |
|
819 | name='datatype', value=self.datatype, format='str') | |
|
820 | 820 | opObj.addParameter(name='path', value=self.path, format='str') |
|
821 | opObj.addParameter(name='startDate', value=self.startDate, format='date') | |
|
822 |
|
|
|
823 | opObj.addParameter(name='startTime', value=self.startTime, format='time') | |
|
824 |
|
|
|
825 | ||
|
821 | opObj.addParameter( | |
|
822 | name='startDate', value=self.startDate, format='date') | |
|
823 | opObj.addParameter( | |
|
824 | name='endDate', value=self.endDate, format='date') | |
|
825 | opObj.addParameter( | |
|
826 | name='startTime', value=self.startTime, format='time') | |
|
827 | opObj.addParameter( | |
|
828 | name='endTime', value=self.endTime, format='time') | |
|
829 | ||
|
826 | 830 | for key, value in kwargs.items(): |
|
827 |
opObj.addParameter(name=key, value=value, |
|
|
831 | opObj.addParameter(name=key, value=value, | |
|
832 | format=type(value).__name__) | |
|
828 | 833 | else: |
|
829 |
opObj.addParameter(name='server' |
|
|
830 | ||
|
834 | opObj.addParameter(name='server', value=self.server, format='str') | |
|
831 | 835 | |
|
832 | 836 | return opObj |
|
833 | 837 | |
@@ -838,16 +842,19 class ReadUnitConf(ProcUnitConf): | |||
|
838 | 842 | |
|
839 | 843 | opObj.addParameter(name='datatype', value=self.datatype, format='str') |
|
840 | 844 | opObj.addParameter(name='path', value=self.path, format='str') |
|
841 | opObj.addParameter(name='startDate', value=self.startDate, format='date') | |
|
845 | opObj.addParameter( | |
|
846 | name='startDate', value=self.startDate, format='date') | |
|
842 | 847 | opObj.addParameter(name='endDate', value=self.endDate, format='date') |
|
843 | opObj.addParameter(name='startTime', value=self.startTime, format='time') | |
|
848 | opObj.addParameter( | |
|
849 | name='startTime', value=self.startTime, format='time') | |
|
844 | 850 | opObj.addParameter(name='endTime', value=self.endTime, format='time') |
|
845 | ||
|
851 | ||
|
846 | 852 | for key, value in kwargs.items(): |
|
847 |
opObj.addParameter(name=key, value=value, |
|
|
853 | opObj.addParameter(name=key, value=value, | |
|
854 | format=type(value).__name__) | |
|
848 | 855 | |
|
849 | 856 | return opObj |
|
850 | ||
|
857 | ||
|
851 | 858 | def readXml(self, upElement): |
|
852 | 859 | |
|
853 | 860 | self.id = upElement.get('id') |
@@ -877,6 +884,7 class ReadUnitConf(ProcUnitConf): | |||
|
877 | 884 | self.startTime = opConfObj.getParameterValue('startTime') |
|
878 | 885 | self.endTime = opConfObj.getParameterValue('endTime') |
|
879 | 886 | |
|
887 | ||
|
880 | 888 | class Project(Process): |
|
881 | 889 | |
|
882 | 890 | id = None |
@@ -905,7 +913,7 class Project(Process): | |||
|
905 | 913 | |
|
906 | 914 | idList = self.procUnitConfObjDict.keys() |
|
907 | 915 | |
|
908 | id = int(self.id)*10 | |
|
916 | id = int(self.id) * 10 | |
|
909 | 917 | |
|
910 | 918 | while True: |
|
911 | 919 | id += 1 |
@@ -938,8 +946,8 class Project(Process): | |||
|
938 | 946 | for procKey in keyList: |
|
939 | 947 | |
|
940 | 948 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
941 | idProcUnit = str(int(self.id)*10 + n) | |
|
942 |
procUnitConfObj.updateId(idProcUnit, parentId |
|
|
949 | idProcUnit = str(int(self.id) * 10 + n) | |
|
950 | procUnitConfObj.updateId(idProcUnit, parentId=self.id) | |
|
943 | 951 | |
|
944 | 952 | newProcUnitConfObjDict[idProcUnit] = procUnitConfObj |
|
945 | 953 | n += 1 |
@@ -949,9 +957,9 class Project(Process): | |||
|
949 | 957 | def setup(self, id, name='', description=''): |
|
950 | 958 | |
|
951 | 959 | |
|
952 | print '*'*60 | |
|
960 | print '*' * 60 | |
|
953 | 961 | print ' Starting SIGNAL CHAIN PROCESSING v%s ' % schainpy.__version__ |
|
954 | print '*'*60 | |
|
962 | print '*' * 60 | |
|
955 | 963 | |
|
956 | 964 | self.id = str(id) |
|
957 | 965 | self.description = description |
@@ -974,7 +982,8 class Project(Process): | |||
|
974 | 982 | idReadUnit = str(id) |
|
975 | 983 | |
|
976 | 984 | readUnitConfObj = ReadUnitConf() |
|
977 |
readUnitConfObj.setup(idReadUnit, name, datatype, |
|
|
985 | readUnitConfObj.setup(idReadUnit, name, datatype, | |
|
986 | parentId=self.id, **kwargs) | |
|
978 | 987 | |
|
979 | 988 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
980 | 989 | |
@@ -985,7 +994,8 class Project(Process): | |||
|
985 | 994 | idProcUnit = self.__getNewId() |
|
986 | 995 | |
|
987 | 996 | procUnitConfObj = ProcUnitConf() |
|
988 |
procUnitConfObj.setup(idProcUnit, name, datatype, |
|
|
997 | procUnitConfObj.setup(idProcUnit, name, datatype, | |
|
998 | inputId, parentId=self.id) | |
|
989 | 999 | |
|
990 | 1000 | self.procUnitConfObjDict[procUnitConfObj.getId()] = procUnitConfObj |
|
991 | 1001 | |
@@ -1059,11 +1069,11 class Project(Process): | |||
|
1059 | 1069 | abs_file = os.path.abspath(filename) |
|
1060 | 1070 | |
|
1061 | 1071 | if not os.access(os.path.dirname(abs_file), os.W_OK): |
|
1062 | print 'No write permission on %s' %os.path.dirname(abs_file) | |
|
1072 | print 'No write permission on %s' % os.path.dirname(abs_file) | |
|
1063 | 1073 | return 0 |
|
1064 | 1074 | |
|
1065 | 1075 | if os.path.isfile(abs_file) and not(os.access(abs_file, os.W_OK)): |
|
1066 | print 'File %s already exists and it could not be overwriten' %abs_file | |
|
1076 | print 'File %s already exists and it could not be overwriten' % abs_file | |
|
1067 | 1077 | return 0 |
|
1068 | 1078 | |
|
1069 | 1079 | self.makeXml() |
@@ -1074,7 +1084,7 class Project(Process): | |||
|
1074 | 1084 | |
|
1075 | 1085 | return 1 |
|
1076 | 1086 | |
|
1077 |
def readXml(self, filename |
|
|
1087 | def readXml(self, filename=None): | |
|
1078 | 1088 | |
|
1079 | 1089 | if not filename: |
|
1080 | 1090 | print 'filename is not defined' |
@@ -1083,7 +1093,7 class Project(Process): | |||
|
1083 | 1093 | abs_file = os.path.abspath(filename) |
|
1084 | 1094 | |
|
1085 | 1095 | if not os.path.isfile(abs_file): |
|
1086 | print '%s file does not exist' %abs_file | |
|
1096 | print '%s file does not exist' % abs_file | |
|
1087 | 1097 | return 0 |
|
1088 | 1098 | |
|
1089 | 1099 | self.projectElement = None |
@@ -1092,16 +1102,17 class Project(Process): | |||
|
1092 | 1102 | try: |
|
1093 | 1103 | self.projectElement = ElementTree().parse(abs_file) |
|
1094 | 1104 | except: |
|
1095 | print 'Error reading %s, verify file format' %filename | |
|
1105 | print 'Error reading %s, verify file format' % filename | |
|
1096 | 1106 | return 0 |
|
1097 | 1107 | |
|
1098 | 1108 | self.project = self.projectElement.tag |
|
1099 | 1109 | |
|
1100 | 1110 | self.id = self.projectElement.get('id') |
|
1101 | 1111 | self.name = self.projectElement.get('name') |
|
1102 |
self.description = self.projectElement.get('description') |
|
|
1103 | ||
|
1104 |
readUnitElementList = self.projectElement.iter( |
|
|
1112 | self.description = self.projectElement.get('description') | |
|
1113 | ||
|
1114 | readUnitElementList = self.projectElement.iter( | |
|
1115 | ReadUnitConf().getElementName()) | |
|
1105 | 1116 | |
|
1106 | 1117 | for readUnitElement in readUnitElementList: |
|
1107 | 1118 | readUnitConfObj = ReadUnitConf() |
@@ -1112,7 +1123,8 class Project(Process): | |||
|
1112 | 1123 | |
|
1113 | 1124 | self.procUnitConfObjDict[readUnitConfObj.getId()] = readUnitConfObj |
|
1114 | 1125 | |
|
1115 |
procUnitElementList = self.projectElement.iter( |
|
|
1126 | procUnitElementList = self.projectElement.iter( | |
|
1127 | ProcUnitConf().getElementName()) | |
|
1116 | 1128 | |
|
1117 | 1129 | for procUnitElement in procUnitElementList: |
|
1118 | 1130 | procUnitConfObj = ProcUnitConf() |
@@ -1129,10 +1141,10 class Project(Process): | |||
|
1129 | 1141 | |
|
1130 | 1142 | def printattr(self): |
|
1131 | 1143 | |
|
1132 | print 'Project[%s]: name = %s, description = %s' %(self.id, | |
|
1133 | self.name, | |
|
1134 | self.description) | |
|
1135 | ||
|
1144 | print 'Project[%s]: name = %s, description = %s' % (self.id, | |
|
1145 | self.name, | |
|
1146 | self.description) | |
|
1147 | ||
|
1136 | 1148 | for procUnitConfObj in self.procUnitConfObjDict.values(): |
|
1137 | 1149 | procUnitConfObj.printattr() |
|
1138 | 1150 | |
@@ -1154,11 +1166,11 class Project(Process): | |||
|
1154 | 1166 | if int(inputId) == 0: |
|
1155 | 1167 | continue |
|
1156 | 1168 | |
|
1157 | #Get input object | |
|
1169 | # Get input object | |
|
1158 | 1170 | puConfINObj = self.procUnitConfObjDict[inputId] |
|
1159 | 1171 | puObjIN = puConfINObj.getProcUnitObj() |
|
1160 | 1172 | |
|
1161 | #Get current object | |
|
1173 | # Get current object | |
|
1162 | 1174 | thisPUObj = thisPUConfObj.getProcUnitObj() |
|
1163 | 1175 | |
|
1164 | 1176 | self.__connect(puObjIN, thisPUObj) |
@@ -1168,11 +1180,11 class Project(Process): | |||
|
1168 | 1180 | import socket |
|
1169 | 1181 | |
|
1170 | 1182 | err = traceback.format_exception(sys.exc_info()[0], |
|
1171 | sys.exc_info()[1], | |
|
1172 | sys.exc_info()[2]) | |
|
1173 | ||
|
1174 | print '***** Error occurred in %s *****' %(procUnitConfObj.name) | |
|
1175 | print '***** %s' %err[-1] | |
|
1183 | sys.exc_info()[1], | |
|
1184 | sys.exc_info()[2]) | |
|
1185 | ||
|
1186 | print '***** Error occurred in %s *****' % (procUnitConfObj.name) | |
|
1187 | print '***** %s' % err[-1] | |
|
1176 | 1188 | |
|
1177 | 1189 | message = ''.join(err) |
|
1178 | 1190 | |
@@ -1181,30 +1193,33 class Project(Process): | |||
|
1181 | 1193 | if not send_email: |
|
1182 | 1194 | return |
|
1183 | 1195 | |
|
1184 |
subject = |
|
|
1196 | subject = 'SChain v%s: Error running %s\n' % ( | |
|
1197 | schainpy.__version__, procUnitConfObj.name) | |
|
1185 | 1198 | |
|
1186 | subtitle = '%s: %s\n' %(procUnitConfObj.getElementName() ,procUnitConfObj.name) | |
|
1187 | subtitle += 'Hostname: %s\n' %socket.gethostbyname(socket.gethostname()) | |
|
1188 | subtitle += 'Working directory: %s\n' %os.path.abspath('./') | |
|
1189 | subtitle += 'Configuration file: %s\n' %self.filename | |
|
1190 |
subtitle += ' |
|
|
1199 | subtitle = '%s: %s\n' % ( | |
|
1200 | procUnitConfObj.getElementName(), procUnitConfObj.name) | |
|
1201 | subtitle += 'Hostname: %s\n' % socket.gethostbyname( | |
|
1202 | socket.gethostname()) | |
|
1203 | subtitle += 'Working directory: %s\n' % os.path.abspath('./') | |
|
1204 | subtitle += 'Configuration file: %s\n' % self.filename | |
|
1205 | subtitle += 'Time: %s\n' % str(datetime.datetime.now()) | |
|
1191 | 1206 | |
|
1192 | 1207 | readUnitConfObj = self.getReadUnitObj() |
|
1193 | 1208 | if readUnitConfObj: |
|
1194 | 1209 | subtitle += '\nInput parameters:\n' |
|
1195 | subtitle += '[Data path = %s]\n' %readUnitConfObj.path | |
|
1196 | subtitle += '[Data type = %s]\n' %readUnitConfObj.datatype | |
|
1197 | subtitle += '[Start date = %s]\n' %readUnitConfObj.startDate | |
|
1198 | subtitle += '[End date = %s]\n' %readUnitConfObj.endDate | |
|
1199 | subtitle += '[Start time = %s]\n' %readUnitConfObj.startTime | |
|
1200 | subtitle += '[End time = %s]\n' %readUnitConfObj.endTime | |
|
1210 | subtitle += '[Data path = %s]\n' % readUnitConfObj.path | |
|
1211 | subtitle += '[Data type = %s]\n' % readUnitConfObj.datatype | |
|
1212 | subtitle += '[Start date = %s]\n' % readUnitConfObj.startDate | |
|
1213 | subtitle += '[End date = %s]\n' % readUnitConfObj.endDate | |
|
1214 | subtitle += '[Start time = %s]\n' % readUnitConfObj.startTime | |
|
1215 | subtitle += '[End time = %s]\n' % readUnitConfObj.endTime | |
|
1201 | 1216 | |
|
1202 | 1217 | adminObj = schainpy.admin.SchainNotify() |
|
1203 | 1218 | adminObj.sendAlert(message=message, |
|
1204 | subject=subject, | |
|
1205 | subtitle=subtitle, | |
|
1206 | filename=self.filename) | |
|
1207 | ||
|
1219 | subject=subject, | |
|
1220 | subtitle=subtitle, | |
|
1221 | filename=self.filename) | |
|
1222 | ||
|
1208 | 1223 | def isPaused(self): |
|
1209 | 1224 | return 0 |
|
1210 | 1225 | |
@@ -1255,7 +1270,7 class Project(Process): | |||
|
1255 | 1270 | def run(self): |
|
1256 | 1271 | |
|
1257 | 1272 | log.success('Starting {}'.format(self.name)) |
|
1258 | ||
|
1273 | ||
|
1259 | 1274 | self.createObjects() |
|
1260 | 1275 | self.connectObjects() |
|
1261 | 1276 | |
@@ -1287,14 +1302,14 class Project(Process): | |||
|
1287 | 1302 | is_ok = False |
|
1288 | 1303 | break |
|
1289 | 1304 | |
|
1290 | #If every process unit finished so end process | |
|
1305 | # If every process unit finished so end process | |
|
1291 | 1306 | if not(is_ok): |
|
1292 | 1307 | break |
|
1293 | 1308 | |
|
1294 | 1309 | if not self.runController(): |
|
1295 | 1310 | break |
|
1296 | 1311 | |
|
1297 | #Closing every process | |
|
1312 | # Closing every process | |
|
1298 | 1313 | for procKey in keyList: |
|
1299 | 1314 | procUnitConfObj = self.procUnitConfObjDict[procKey] |
|
1300 | 1315 | procUnitConfObj.close() |
@@ -50,7 +50,6 class ProjectParms(): | |||
|
50 | 50 | indexDatatype = 2 |
|
51 | 51 | if 'usrp' in self.datatype.lower(): |
|
52 | 52 | indexDatatype = 3 |
|
53 | ||
|
54 | 53 | return indexDatatype |
|
55 | 54 | |
|
56 | 55 | def getExt(self): |
@@ -65,7 +64,6 class ProjectParms(): | |||
|
65 | 64 | ext = '.fits' |
|
66 | 65 | if self.datatype.lower() == 'usrp': |
|
67 | 66 | ext = '.hdf5' |
|
68 | ||
|
69 | 67 | return ext |
|
70 | 68 | |
|
71 | 69 | def set(self, project_name, datatype, ext, dpath, online, |
@@ -5,8 +5,8 | |||
|
5 | 5 | # from schainpy.model.utils.jroutils import * |
|
6 | 6 | # from schainpy.serializer import * |
|
7 | 7 | |
|
8 | from graphics import * | |
|
8 | 9 | from data import * |
|
9 | 10 | from io import * |
|
10 | 11 | from proc import * |
|
11 |
from |
|
|
12 | from utils import * No newline at end of file | |
|
12 | from utils import * |
@@ -292,11 +292,9 class JROData(GenericData): | |||
|
292 | 292 | return fmax |
|
293 | 293 | |
|
294 | 294 | def getFmax(self): |
|
295 | ||
|
296 | 295 | PRF = 1./(self.ippSeconds * self.nCohInt) |
|
297 | 296 | |
|
298 | 297 | fmax = PRF |
|
299 | ||
|
300 | 298 | return fmax |
|
301 | 299 | |
|
302 | 300 | def getVmax(self): |
@@ -7,6 +7,7 import sys | |||
|
7 | 7 | import numpy |
|
8 | 8 | import copy |
|
9 | 9 | import datetime |
|
10 | import inspect | |
|
10 | 11 | |
|
11 | 12 | SPEED_OF_LIGHT = 299792458 |
|
12 | 13 | SPEED_OF_LIGHT = 3e8 |
@@ -82,7 +83,25 class Header(object): | |||
|
82 | 83 | def write(self): |
|
83 | 84 | |
|
84 | 85 | raise NotImplementedError |
|
86 | ||
|
87 | def getAllowedArgs(self): | |
|
88 | args = inspect.getargspec(self.__init__).args | |
|
89 | try: | |
|
90 | args.remove('self') | |
|
91 | except: | |
|
92 | pass | |
|
93 | return args | |
|
94 | ||
|
95 | def getAsDict(self): | |
|
96 | args = self.getAllowedArgs() | |
|
97 | asDict = {} | |
|
98 | for x in args: | |
|
99 | asDict[x] = self[x] | |
|
100 | return asDict | |
|
85 | 101 | |
|
102 | def __getitem__(self, name): | |
|
103 | return getattr(self, name) | |
|
104 | ||
|
86 | 105 | def printInfo(self): |
|
87 | 106 | |
|
88 | 107 | message = "#"*50 + "\n" |
@@ -115,6 +134,7 class BasicHeader(Header): | |||
|
115 | 134 | dstFlag = None |
|
116 | 135 | errorCount = None |
|
117 | 136 | datatime = None |
|
137 | structure = BASIC_STRUCTURE | |
|
118 | 138 | __LOCALTIME = None |
|
119 | 139 | |
|
120 | 140 | def __init__(self, useLocalTime=True): |
@@ -189,16 +209,17 class SystemHeader(Header): | |||
|
189 | 209 | nChannels = None |
|
190 | 210 | adcResolution = None |
|
191 | 211 | pciDioBusWidth = None |
|
192 | ||
|
193 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWith=0): | |
|
212 | structure = SYSTEM_STRUCTURE | |
|
213 | ||
|
214 | def __init__(self, nSamples=0, nProfiles=0, nChannels=0, adcResolution=14, pciDioBusWidth=0): | |
|
194 | 215 | |
|
195 | 216 | self.size = 24 |
|
196 | 217 | self.nSamples = nSamples |
|
197 | 218 | self.nProfiles = nProfiles |
|
198 | 219 | self.nChannels = nChannels |
|
199 | 220 | self.adcResolution = adcResolution |
|
200 | self.pciDioBusWidth = pciDioBusWith | |
|
201 | ||
|
221 | self.pciDioBusWidth = pciDioBusWidth | |
|
222 | ||
|
202 | 223 | def read(self, fp): |
|
203 | 224 | self.length = 0 |
|
204 | 225 | try: |
@@ -260,15 +281,15 class RadarControllerHeader(Header): | |||
|
260 | 281 | line5Function = None |
|
261 | 282 | fClock = None |
|
262 | 283 | prePulseBefore = None |
|
263 |
prePulse |
|
|
284 | prePulseAfter = None | |
|
264 | 285 | rangeIpp = None |
|
265 | 286 | rangeTxA = None |
|
266 | 287 | rangeTxB = None |
|
267 | ||
|
288 | structure = RADAR_STRUCTURE | |
|
268 | 289 | __size = None |
|
269 | 290 | |
|
270 | 291 | def __init__(self, expType=2, nTx=1, |
|
271 |
ipp |
|
|
292 | ipp=None, txA=0, txB=0, | |
|
272 | 293 | nWindows=None, nHeights=None, firstHeight=None, deltaHeight=None, |
|
273 | 294 | numTaus=0, line6Function=0, line5Function=0, fClock=None, |
|
274 | 295 | prePulseBefore=0, prePulseAfter=0, |
@@ -278,10 +299,10 class RadarControllerHeader(Header): | |||
|
278 | 299 | # self.size = 116 |
|
279 | 300 | self.expType = expType |
|
280 | 301 | self.nTx = nTx |
|
281 |
self.ipp = ipp |
|
|
302 | self.ipp = ipp | |
|
282 | 303 | self.txA = txA |
|
283 | 304 | self.txB = txB |
|
284 |
self.rangeIpp = ipp |
|
|
305 | self.rangeIpp = ipp | |
|
285 | 306 | self.rangeTxA = txA |
|
286 | 307 | self.rangeTxB = txB |
|
287 | 308 | |
@@ -292,7 +313,7 class RadarControllerHeader(Header): | |||
|
292 | 313 | self.line5Function = line5Function |
|
293 | 314 | self.fClock = fClock |
|
294 | 315 | self.prePulseBefore = prePulseBefore |
|
295 |
self.prePulse |
|
|
316 | self.prePulseAfter = prePulseAfter | |
|
296 | 317 | |
|
297 | 318 | self.nHeights = nHeights |
|
298 | 319 | self.firstHeight = firstHeight |
@@ -342,7 +363,7 class RadarControllerHeader(Header): | |||
|
342 | 363 | self.line5Function = int(header['nLine5Function'][0]) |
|
343 | 364 | self.fClock = float(header['fClock'][0]) |
|
344 | 365 | self.prePulseBefore = int(header['nPrePulseBefore'][0]) |
|
345 |
self.prePulse |
|
|
366 | self.prePulseAfter = int(header['nPrePulseAfter'][0]) | |
|
346 | 367 | self.rangeIpp = header['sRangeIPP'][0] |
|
347 | 368 | self.rangeTxA = header['sRangeTxA'][0] |
|
348 | 369 | self.rangeTxB = header['sRangeTxB'][0] |
@@ -450,7 +471,7 class RadarControllerHeader(Header): | |||
|
450 | 471 | self.line5Function, |
|
451 | 472 | self.fClock, |
|
452 | 473 | self.prePulseBefore, |
|
453 |
self.prePulse |
|
|
474 | self.prePulseAfter, | |
|
454 | 475 | self.rangeIpp, |
|
455 | 476 | self.rangeTxA, |
|
456 | 477 | self.rangeTxB) |
@@ -540,15 +561,18 class ProcessingHeader(Header): | |||
|
540 | 561 | nCohInt = None |
|
541 | 562 | nIncohInt = None |
|
542 | 563 | totalSpectra = None |
|
543 | ||
|
564 | structure = PROCESSING_STRUCTURE | |
|
544 | 565 | flag_dc = None |
|
545 | 566 | flag_cspc = None |
|
546 | 567 | |
|
547 | def __init__(self): | |
|
568 | def __init__(self, dtype=0, blockSize=0, profilesPerBlock=0, dataBlocksPerFile=0, nWindows=0,processFlags=0, nCohInt=0, | |
|
569 | nIncohInt=0, totalSpectra=0, nHeights=0, firstHeight=0, deltaHeight=0, samplesWin=0, spectraComb=0, nCode=0, | |
|
570 | code=0, nBaud=None, shif_fft=False, flag_dc=False, flag_cspc=False, flag_decode=False, flag_deflip=False | |
|
571 | ): | |
|
548 | 572 | |
|
549 | 573 | # self.size = 0 |
|
550 |
self.dtype = |
|
|
551 |
self.blockSize = |
|
|
574 | self.dtype = dtype | |
|
575 | self.blockSize = blockSize | |
|
552 | 576 | self.profilesPerBlock = 0 |
|
553 | 577 | self.dataBlocksPerFile = 0 |
|
554 | 578 | self.nWindows = 0 |
@@ -572,6 +596,7 class ProcessingHeader(Header): | |||
|
572 | 596 | self.flag_decode = False |
|
573 | 597 | self.flag_deflip = False |
|
574 | 598 | self.length = 0 |
|
599 | ||
|
575 | 600 | def read(self, fp): |
|
576 | 601 | self.length = 0 |
|
577 | 602 | try: |
@@ -8,78 +8,78 from figure import Figure, isRealtime | |||
|
8 | 8 | class CorrelationPlot(Figure): |
|
9 | 9 | isConfig = None |
|
10 | 10 | __nsubplots = None |
|
11 | ||
|
11 | ||
|
12 | 12 | WIDTHPROF = None |
|
13 | 13 | HEIGHTPROF = None |
|
14 | 14 | PREFIX = 'corr' |
|
15 | ||
|
16 | def __init__(self): | |
|
17 | ||
|
15 | ||
|
16 | def __init__(self, **kwargs): | |
|
17 | Figure.__init__(self, **kwargs) | |
|
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=False, show=True): |
|
41 | ||
|
42 |
showprofile = False |
|
|
41 | ||
|
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 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile=False, |
|
76 | 76 | xmin=None, xmax=None, ymin=None, ymax=None, zmin=None, zmax=None, |
|
77 | 77 | save=False, figpath='./', figfile=None, show=True, ftp=False, wr_period=1, |
|
78 | 78 | server=None, folder=None, username=None, password=None, |
|
79 | 79 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0, realtime=False): |
|
80 | ||
|
80 | ||
|
81 | 81 | """ |
|
82 | ||
|
82 | ||
|
83 | 83 | Input: |
|
84 | 84 | dataOut : |
|
85 | 85 | id : |
@@ -93,15 +93,15 class CorrelationPlot(Figure): | |||
|
93 | 93 | zmin : None, |
|
94 | 94 | zmax : None |
|
95 | 95 | """ |
|
96 | ||
|
96 | ||
|
97 | 97 | if dataOut.flagNoData: |
|
98 | 98 | return None |
|
99 | ||
|
99 | ||
|
100 | 100 | if realtime: |
|
101 | 101 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
102 | 102 | print 'Skipping this plot function' |
|
103 | 103 | return |
|
104 | ||
|
104 | ||
|
105 | 105 | if channelList == None: |
|
106 | 106 | channelIndexList = dataOut.channelIndexList |
|
107 | 107 | else: |
@@ -110,53 +110,53 class CorrelationPlot(Figure): | |||
|
110 | 110 | if channel not in dataOut.channelList: |
|
111 | 111 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
112 | 112 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
113 | ||
|
113 | ||
|
114 | 114 | factor = dataOut.normFactor |
|
115 | 115 | lenfactor = factor.shape[1] |
|
116 | 116 | x = dataOut.getLagTRange(1) |
|
117 | 117 | y = dataOut.getHeiRange() |
|
118 | ||
|
118 | ||
|
119 | 119 | z = copy.copy(dataOut.data_corr[:,:,0,:]) |
|
120 | 120 | for i in range(dataOut.data_corr.shape[0]): |
|
121 |
z[i,:,:] = z[i,:,:]/factor[i,:] |
|
|
121 | z[i,:,:] = z[i,:,:]/factor[i,:] | |
|
122 | 122 | zdB = numpy.abs(z) |
|
123 | ||
|
123 | ||
|
124 | 124 | avg = numpy.average(z, axis=1) |
|
125 | 125 | # avg = numpy.nanmean(z, axis=1) |
|
126 | 126 | # noise = dataOut.noise/factor |
|
127 | ||
|
127 | ||
|
128 | 128 | #thisDatetime = dataOut.datatime |
|
129 | 129 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
130 |
title = wintitle + " Correlation" |
|
|
130 | title = wintitle + " Correlation" | |
|
131 | 131 | xlabel = "Lag T (s)" |
|
132 | 132 | ylabel = "Range (Km)" |
|
133 | ||
|
133 | ||
|
134 | 134 | if not self.isConfig: |
|
135 | ||
|
136 |
nplots = dataOut.data_corr.shape[0] |
|
|
137 | ||
|
135 | ||
|
136 | nplots = dataOut.data_corr.shape[0] | |
|
137 | ||
|
138 | 138 | self.setup(id=id, |
|
139 | 139 | nplots=nplots, |
|
140 | 140 | wintitle=wintitle, |
|
141 | 141 | showprofile=showprofile, |
|
142 | 142 | show=show) |
|
143 | ||
|
143 | ||
|
144 | 144 | if xmin == None: xmin = numpy.nanmin(x) |
|
145 | 145 | if xmax == None: xmax = numpy.nanmax(x) |
|
146 | 146 | if ymin == None: ymin = numpy.nanmin(y) |
|
147 | 147 | if ymax == None: ymax = numpy.nanmax(y) |
|
148 | 148 | if zmin == None: zmin = 0 |
|
149 | 149 | if zmax == None: zmax = 1 |
|
150 | ||
|
150 | ||
|
151 | 151 | self.FTP_WEI = ftp_wei |
|
152 | 152 | self.EXP_CODE = exp_code |
|
153 | 153 | self.SUB_EXP_CODE = sub_exp_code |
|
154 | 154 | self.PLOT_POS = plot_pos |
|
155 | ||
|
155 | ||
|
156 | 156 | self.isConfig = True |
|
157 | ||
|
157 | ||
|
158 | 158 | self.setWinTitle(title) |
|
159 | ||
|
159 | ||
|
160 | 160 | for i in range(self.nplots): |
|
161 | 161 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
|
162 | 162 | title = "Channel %d and %d: : %s" %(dataOut.pairsList[i][0],dataOut.pairsList[i][1] , str_datetime) |
@@ -165,7 +165,7 class CorrelationPlot(Figure): | |||
|
165 | 165 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, zmin=zmin, zmax=zmax, |
|
166 | 166 | xlabel=xlabel, ylabel=ylabel, title=title, |
|
167 | 167 | ticksize=9, cblabel='') |
|
168 | ||
|
168 | ||
|
169 | 169 | # if self.__showprofile: |
|
170 | 170 | # axes = self.axesList[i*self.__nsubplots +1] |
|
171 | 171 | # axes.pline(avgdB[i], y, |
@@ -173,15 +173,15 class CorrelationPlot(Figure): | |||
|
173 | 173 | # xlabel='dB', ylabel='', title='', |
|
174 | 174 | # ytick_visible=False, |
|
175 | 175 | # grid='x') |
|
176 | # | |
|
176 | # | |
|
177 | 177 | # noiseline = numpy.repeat(noisedB[i], len(y)) |
|
178 | 178 | # axes.addpline(noiseline, y, idline=1, color="black", linestyle="dashed", lw=2) |
|
179 | ||
|
179 | ||
|
180 | 180 | self.draw() |
|
181 | ||
|
181 | ||
|
182 | 182 | self.save(figpath=figpath, |
|
183 | 183 | figfile=figfile, |
|
184 | 184 | save=save, |
|
185 | 185 | ftp=ftp, |
|
186 | 186 | wr_period=wr_period, |
|
187 |
thisDatetime=thisDatetime) |
|
|
187 | thisDatetime=thisDatetime) |
@@ -16,8 +16,10 from schainpy.model.proc.jroproc_base import Operation | |||
|
16 | 16 | from schainpy.utils import log |
|
17 | 17 | |
|
18 | 18 | jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90] |
|
19 |
blu_values = matplotlib.pyplot.get_cmap( |
|
|
20 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values))) | |
|
19 | blu_values = matplotlib.pyplot.get_cmap( | |
|
20 | "seismic_r", 20)(numpy.arange(20))[10:15] | |
|
21 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
|
22 | "jro", numpy.vstack((blu_values, jet_values))) | |
|
21 | 23 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
22 | 24 | |
|
23 | 25 | CMAPS = [plt.get_cmap(s) for s in ('jro', 'jet', 'RdBu_r', 'seismic')] |
@@ -52,7 +54,7 class PlotData(Operation, Process): | |||
|
52 | 54 | self.kwargs['code'] = self.CODE |
|
53 | 55 | self.mp = False |
|
54 | 56 | self.data = None |
|
55 |
self.isConfig = False |
|
|
57 | self.isConfig = False | |
|
56 | 58 | self.figures = [] |
|
57 | 59 | self.axes = [] |
|
58 | 60 | self.cb_axes = [] |
@@ -72,13 +74,13 class PlotData(Operation, Process): | |||
|
72 | 74 | self.zmin = kwargs.get('zmin', None) |
|
73 | 75 | self.zmax = kwargs.get('zmax', None) |
|
74 | 76 | self.zlimits = kwargs.get('zlimits', None) |
|
75 |
self.xmin = kwargs.get('xmin', None) |
|
|
77 | self.xmin = kwargs.get('xmin', None) | |
|
76 | 78 | self.xmax = kwargs.get('xmax', None) |
|
77 | 79 | self.xrange = kwargs.get('xrange', 24) |
|
78 | 80 | self.ymin = kwargs.get('ymin', None) |
|
79 | 81 | self.ymax = kwargs.get('ymax', None) |
|
80 | 82 | self.xlabel = kwargs.get('xlabel', None) |
|
81 |
self.__MAXNUMY = kwargs.get('decimation', 100) |
|
|
83 | self.__MAXNUMY = kwargs.get('decimation', 100) | |
|
82 | 84 | self.showSNR = kwargs.get('showSNR', False) |
|
83 | 85 | self.oneFigure = kwargs.get('oneFigure', True) |
|
84 | 86 | self.width = kwargs.get('width', None) |
@@ -115,18 +117,18 class PlotData(Operation, Process): | |||
|
115 | 117 | self.pf_axes = [] |
|
116 | 118 | self.cmaps = [] |
|
117 | 119 | |
|
118 | size = '15%' if self.ncols==1 else '30%' | |
|
119 | pad = '4%' if self.ncols==1 else '8%' | |
|
120 | size = '15%' if self.ncols == 1 else '30%' | |
|
121 | pad = '4%' if self.ncols == 1 else '8%' | |
|
120 | 122 | |
|
121 | 123 | if self.oneFigure: |
|
122 | 124 | if self.height is None: |
|
123 | self.height = 1.4*self.nrows + 1 | |
|
125 | self.height = 1.4 * self.nrows + 1 | |
|
124 | 126 | fig = plt.figure(figsize=(self.width, self.height), |
|
125 | 127 | edgecolor='k', |
|
126 | 128 | facecolor='w') |
|
127 | 129 | self.figures.append(fig) |
|
128 |
for n in range(self.nplots): |
|
|
129 | ax = fig.add_subplot(self.nrows, self.ncols, n+1) | |
|
130 | for n in range(self.nplots): | |
|
131 | ax = fig.add_subplot(self.nrows, self.ncols, n + 1) | |
|
130 | 132 | ax.tick_params(labelsize=8) |
|
131 | 133 | ax.firsttime = True |
|
132 | 134 | ax.index = 0 |
@@ -134,15 +136,15 class PlotData(Operation, Process): | |||
|
134 | 136 | self.axes.append(ax) |
|
135 | 137 | if self.showprofile: |
|
136 | 138 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
137 |
cax.tick_params(labelsize=8) |
|
|
139 | cax.tick_params(labelsize=8) | |
|
138 | 140 | self.pf_axes.append(cax) |
|
139 | 141 | else: |
|
140 | 142 | if self.height is None: |
|
141 | 143 | self.height = 3 |
|
142 | 144 | for n in range(self.nplots): |
|
143 | 145 | fig = plt.figure(figsize=(self.width, self.height), |
|
144 |
|
|
|
145 |
|
|
|
146 | edgecolor='k', | |
|
147 | facecolor='w') | |
|
146 | 148 | ax = fig.add_subplot(1, 1, 1) |
|
147 | 149 | ax.tick_params(labelsize=8) |
|
148 | 150 | ax.firsttime = True |
@@ -152,12 +154,12 class PlotData(Operation, Process): | |||
|
152 | 154 | self.axes.append(ax) |
|
153 | 155 | if self.showprofile: |
|
154 | 156 | cax = self.__add_axes(ax, size=size, pad=pad) |
|
155 |
cax.tick_params(labelsize=8) |
|
|
157 | cax.tick_params(labelsize=8) | |
|
156 | 158 | self.pf_axes.append(cax) |
|
157 | ||
|
159 | ||
|
158 | 160 | for n in range(self.nrows): |
|
159 | 161 | if self.colormaps is not None: |
|
160 |
cmap = plt.get_cmap(self.colormaps[n]) |
|
|
162 | cmap = plt.get_cmap(self.colormaps[n]) | |
|
161 | 163 | else: |
|
162 | 164 | cmap = plt.get_cmap(self.colormap) |
|
163 | 165 | cmap.set_bad(self.bgcolor, 1.) |
@@ -269,7 +271,7 class PlotData(Operation, Process): | |||
|
269 | 271 | ''' |
|
270 | 272 | divider = make_axes_locatable(ax) |
|
271 | 273 | nax = divider.new_horizontal(size=size, pad=pad) |
|
272 |
ax.figure.add_axes(nax) |
|
|
274 | ax.figure.add_axes(nax) | |
|
273 | 275 | return nax |
|
274 | 276 | |
|
275 | 277 | self.setup() |
@@ -278,7 +280,7 class PlotData(Operation, Process): | |||
|
278 | 280 | ''' |
|
279 | 281 | This method should be implemented in the child class, the following |
|
280 | 282 | attributes should be set: |
|
281 | ||
|
283 | ||
|
282 | 284 | self.nrows: number of rows |
|
283 | 285 | self.ncols: number of cols |
|
284 | 286 | self.nplots: number of plots (channels or pairs) |
@@ -298,26 +300,26 class PlotData(Operation, Process): | |||
|
298 | 300 | deltas = x_buffer[1:] - x_buffer[0:-1] |
|
299 | 301 | x_median = numpy.median(deltas) |
|
300 | 302 | |
|
301 | index = numpy.where(deltas > 5*x_median) | |
|
303 | index = numpy.where(deltas > 5 * x_median) | |
|
302 | 304 | |
|
303 | 305 | if len(index[0]) != 0: |
|
304 | 306 | z_buffer[::, index[0], ::] = self.__missing |
|
305 | 307 | z_buffer = numpy.ma.masked_inside(z_buffer, |
|
306 | 0.99*self.__missing, | |
|
307 | 1.01*self.__missing) | |
|
308 | 0.99 * self.__missing, | |
|
309 | 1.01 * self.__missing) | |
|
308 | 310 | |
|
309 | 311 | return x_buffer, y_buffer, z_buffer |
|
310 | 312 | |
|
311 | 313 | def decimate(self): |
|
312 | 314 | |
|
313 | 315 | # dx = int(len(self.x)/self.__MAXNUMX) + 1 |
|
314 | dy = int(len(self.y)/self.__MAXNUMY) + 1 | |
|
316 | dy = int(len(self.y) / self.__MAXNUMY) + 1 | |
|
315 | 317 | |
|
316 | 318 | # x = self.x[::dx] |
|
317 | 319 | x = self.x |
|
318 | 320 | y = self.y[::dy] |
|
319 | 321 | z = self.z[::, ::, ::dy] |
|
320 | ||
|
322 | ||
|
321 | 323 | return x, y, z |
|
322 | 324 | |
|
323 | 325 | def format(self): |
@@ -337,7 +339,7 class PlotData(Operation, Process): | |||
|
337 | 339 | xmin = self.xmin |
|
338 | 340 | |
|
339 | 341 | if self.xmax is None: |
|
340 | xmax = xmin+self.xrange*60*60 | |
|
342 | xmax = xmin + self.xrange * 60 * 60 | |
|
341 | 343 | else: |
|
342 | 344 | if self.xaxis is 'time': |
|
343 | 345 | dt = self.getDateTime(self.max_time) |
@@ -354,7 +356,9 class PlotData(Operation, Process): | |||
|
354 | 356 | i = 1 if numpy.where(ymax < Y)[0][0] < 0 else numpy.where(ymax < Y)[0][0] |
|
355 | 357 | ystep = Y[i-1]/5 |
|
356 | 358 | |
|
357 | for n, ax in enumerate(self.axes): | |
|
359 | ystep = 200 if ymax >= 800 else 100 if ymax >= 400 else 50 if ymax >= 200 else 20 | |
|
360 | ||
|
361 | for n, ax in enumerate(self.axes): | |
|
358 | 362 | if ax.firsttime: |
|
359 | 363 | ax.set_facecolor(self.bgcolor) |
|
360 | 364 | ax.yaxis.set_major_locator(MultipleLocator(ystep)) |
@@ -363,14 +367,15 class PlotData(Operation, Process): | |||
|
363 | 367 | ax.xaxis.set_major_locator(LinearLocator(9)) |
|
364 | 368 | if self.xlabel is not None: |
|
365 | 369 | ax.set_xlabel(self.xlabel) |
|
366 |
ax.set_ylabel(self.ylabel) |
|
|
370 | ax.set_ylabel(self.ylabel) | |
|
367 | 371 | ax.firsttime = False |
|
368 | 372 | if self.showprofile: |
|
369 | 373 | self.pf_axes[n].set_ylim(ymin, ymax) |
|
370 |
self.pf_axes[n].set_xlim(self.zmin, self.zmax) |
|
|
374 | self.pf_axes[n].set_xlim(self.zmin, self.zmax) | |
|
371 | 375 | self.pf_axes[n].set_xlabel('dB') |
|
372 | 376 | self.pf_axes[n].grid(b=True, axis='x') |
|
373 |
[tick.set_visible(False) |
|
|
377 | [tick.set_visible(False) | |
|
378 | for tick in self.pf_axes[n].get_yticklabels()] | |
|
374 | 379 | if self.colorbar: |
|
375 | 380 | ax.cbar = plt.colorbar(ax.plt, ax=ax, pad=0.02, aspect=10) |
|
376 | 381 | ax.cbar.ax.tick_params(labelsize=8) |
@@ -379,7 +384,7 class PlotData(Operation, Process): | |||
|
379 | 384 | ax.cbar.set_label(self.cb_label, size=8) |
|
380 | 385 | elif self.cb_labels: |
|
381 | 386 | ax.cbar.set_label(self.cb_labels[n], size=8) |
|
382 | ||
|
387 | ||
|
383 | 388 | ax.set_title('{} - {} {}'.format( |
|
384 | 389 | self.titles[n], |
|
385 | 390 | self.getDateTime(self.max_time).strftime('%H:%M:%S'), |
@@ -392,10 +397,10 class PlotData(Operation, Process): | |||
|
392 | 397 | ''' |
|
393 | 398 | ''' |
|
394 | 399 | log.success('Plotting', self.name) |
|
395 | ||
|
400 | ||
|
396 | 401 | self.plot() |
|
397 | 402 | self.format() |
|
398 | ||
|
403 | ||
|
399 | 404 | for n, fig in enumerate(self.figures): |
|
400 | 405 | if self.nrows == 0 or self.nplots == 0: |
|
401 | 406 | log.warning('No data', self.name) |
@@ -405,7 +410,7 class PlotData(Operation, Process): | |||
|
405 | 410 | fig.canvas.manager.set_window_title('{} - {}'.format(self.title, |
|
406 | 411 | self.getDateTime(self.max_time).strftime('%Y/%m/%d'))) |
|
407 | 412 | # fig.canvas.draw() |
|
408 | ||
|
413 | ||
|
409 | 414 | if self.save and self.data.ended: |
|
410 | 415 | channels = range(self.nrows) |
|
411 | 416 | if self.oneFigure: |
@@ -438,9 +443,10 class PlotData(Operation, Process): | |||
|
438 | 443 | receiver.setsockopt(zmq.CONFLATE, self.CONFLATE) |
|
439 | 444 | |
|
440 | 445 | if 'server' in self.kwargs['parent']: |
|
441 | receiver.connect('ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |
|
446 | receiver.connect( | |
|
447 | 'ipc:///tmp/{}.plots'.format(self.kwargs['parent']['server'])) | |
|
442 | 448 | else: |
|
443 |
receiver.connect("ipc:///tmp/zmq.plots") |
|
|
449 | receiver.connect("ipc:///tmp/zmq.plots") | |
|
444 | 450 | |
|
445 | 451 | while True: |
|
446 | 452 | try: |
@@ -460,7 +466,7 class PlotData(Operation, Process): | |||
|
460 | 466 | if self.isConfig is False: |
|
461 | 467 | self.__setup() |
|
462 | 468 | self.isConfig = True |
|
463 | ||
|
469 | ||
|
464 | 470 | self.__plot() |
|
465 | 471 | |
|
466 | 472 | except zmq.Again as e: |
@@ -474,23 +480,24 class PlotData(Operation, Process): | |||
|
474 | 480 | if self.data: |
|
475 | 481 | self.__plot() |
|
476 | 482 | |
|
483 | ||
|
477 | 484 | class PlotSpectraData(PlotData): |
|
478 | 485 | ''' |
|
479 | 486 | Plot for Spectra data |
|
480 | 487 | ''' |
|
481 | 488 | |
|
482 | 489 | CODE = 'spc' |
|
483 |
colormap = 'jro' |
|
|
490 | colormap = 'jro' | |
|
484 | 491 | |
|
485 | 492 | def setup(self): |
|
486 | 493 | self.nplots = len(self.data.channels) |
|
487 | self.ncols = int(numpy.sqrt(self.nplots)+ 0.9) | |
|
488 | self.nrows = int((1.0*self.nplots/self.ncols) + 0.9) | |
|
489 | self.width = 3.4*self.ncols | |
|
490 | self.height = 3*self.nrows | |
|
494 | self.ncols = int(numpy.sqrt(self.nplots) + 0.9) | |
|
495 | self.nrows = int((1.0 * self.nplots / self.ncols) + 0.9) | |
|
496 | self.width = 3.4 * self.ncols | |
|
497 | self.height = 3 * self.nrows | |
|
491 | 498 | self.cb_label = 'dB' |
|
492 |
if self.showprofile: |
|
|
493 | self.width += 0.8*self.ncols | |
|
499 | if self.showprofile: | |
|
500 | self.width += 0.8 * self.ncols | |
|
494 | 501 | |
|
495 | 502 | self.ylabel = 'Range [Km]' |
|
496 | 503 | |
@@ -514,7 +521,7 class PlotSpectraData(PlotData): | |||
|
514 | 521 | y = self.data.heights |
|
515 | 522 | self.y = y |
|
516 | 523 | z = self.data['spc'] |
|
517 | ||
|
524 | ||
|
518 | 525 | for n, ax in enumerate(self.axes): |
|
519 | 526 | noise = self.data['noise'][n][-1] |
|
520 | 527 | if self.CODE == 'spc_mean': |
@@ -525,15 +532,16 class PlotSpectraData(PlotData): | |||
|
525 | 532 | self.zmin = self.zmin if self.zmin else numpy.nanmin(z) |
|
526 | 533 | self.zmax = self.zmax if self.zmax else numpy.nanmax(z) |
|
527 | 534 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
528 | vmin=self.zmin, | |
|
529 | vmax=self.zmax, | |
|
530 | cmap=plt.get_cmap(self.colormap) | |
|
531 |
) |
|
|
535 | vmin=self.zmin, | |
|
536 | vmax=self.zmax, | |
|
537 | cmap=plt.get_cmap(self.colormap) | |
|
538 | ) | |
|
532 | 539 | |
|
533 | 540 | if self.showprofile: |
|
534 |
ax.plt_profile= self.pf_axes[n].plot( |
|
|
541 | ax.plt_profile = self.pf_axes[n].plot( | |
|
542 | self.data['rti'][n][-1], y)[0] | |
|
535 | 543 | ax.plt_noise = self.pf_axes[n].plot(numpy.repeat(noise, len(y)), y, |
|
536 |
|
|
|
544 | color="k", linestyle="dashed", lw=1)[0] | |
|
537 | 545 | if self.CODE == 'spc_mean': |
|
538 | 546 | ax.plt_mean = ax.plot(mean, y, color='k')[0] |
|
539 | 547 | else: |
@@ -554,17 +562,17 class PlotCrossSpectraData(PlotData): | |||
|
554 | 562 | zmin_coh = None |
|
555 | 563 | zmax_coh = None |
|
556 | 564 | zmin_phase = None |
|
557 |
zmax_phase = None |
|
|
565 | zmax_phase = None | |
|
558 | 566 | |
|
559 | 567 | def setup(self): |
|
560 | 568 | |
|
561 | 569 | self.ncols = 4 |
|
562 | 570 | self.nrows = len(self.data.pairs) |
|
563 | self.nplots = self.nrows*4 | |
|
564 | self.width = 3.4*self.ncols | |
|
565 | self.height = 3*self.nrows | |
|
571 | self.nplots = self.nrows * 4 | |
|
572 | self.width = 3.4 * self.ncols | |
|
573 | self.height = 3 * self.nrows | |
|
566 | 574 | self.ylabel = 'Range [Km]' |
|
567 |
self.showprofile = False |
|
|
575 | self.showprofile = False | |
|
568 | 576 | |
|
569 | 577 | def plot(self): |
|
570 | 578 | |
@@ -588,24 +596,24 class PlotCrossSpectraData(PlotData): | |||
|
588 | 596 | for n in range(self.nrows): |
|
589 | 597 | noise = self.data['noise'][n][-1] |
|
590 | 598 | pair = self.data.pairs[n] |
|
591 | ax = self.axes[4*n] | |
|
592 | ax3 = self.axes[4*n+3] | |
|
599 | ax = self.axes[4 * n] | |
|
600 | ax3 = self.axes[4 * n + 3] | |
|
593 | 601 | if ax.firsttime: |
|
594 | 602 | self.xmax = self.xmax if self.xmax else numpy.nanmax(x) |
|
595 | 603 | self.xmin = self.xmin if self.xmin else -self.xmax |
|
596 | 604 | self.zmin = self.zmin if self.zmin else numpy.nanmin(spc) |
|
597 |
self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) |
|
|
605 | self.zmax = self.zmax if self.zmax else numpy.nanmax(spc) | |
|
598 | 606 | ax.plt = ax.pcolormesh(x, y, spc[pair[0]].T, |
|
599 | 607 | vmin=self.zmin, |
|
600 | 608 | vmax=self.zmax, |
|
601 | 609 | cmap=plt.get_cmap(self.colormap) |
|
602 |
) |
|
|
610 | ) | |
|
603 | 611 | else: |
|
604 | 612 | ax.plt.set_array(spc[pair[0]].T.ravel()) |
|
605 | 613 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
606 | 614 | |
|
607 | ax = self.axes[4*n+1] | |
|
608 |
if ax.firsttime: |
|
|
615 | ax = self.axes[4 * n + 1] | |
|
616 | if ax.firsttime: | |
|
609 | 617 | ax.plt = ax.pcolormesh(x, y, spc[pair[1]].T, |
|
610 | 618 | vmin=self.zmin, |
|
611 | 619 | vmax=self.zmax, |
@@ -615,12 +623,12 class PlotCrossSpectraData(PlotData): | |||
|
615 | 623 | ax.plt.set_array(spc[pair[1]].T.ravel()) |
|
616 | 624 | self.titles.append('CH {}: {:3.2f}dB'.format(n, noise)) |
|
617 | 625 | |
|
618 | out = cspc[n]/numpy.sqrt(spc[pair[0]]*spc[pair[1]]) | |
|
626 | out = cspc[n] / numpy.sqrt(spc[pair[0]] * spc[pair[1]]) | |
|
619 | 627 | coh = numpy.abs(out) |
|
620 | phase = numpy.arctan2(out.imag, out.real)*180/numpy.pi | |
|
621 | ||
|
622 | ax = self.axes[4*n+2] | |
|
623 |
if ax.firsttime: |
|
|
628 | phase = numpy.arctan2(out.imag, out.real) * 180 / numpy.pi | |
|
629 | ||
|
630 | ax = self.axes[4 * n + 2] | |
|
631 | if ax.firsttime: | |
|
624 | 632 | ax.plt = ax.pcolormesh(x, y, coh.T, |
|
625 | 633 | vmin=0, |
|
626 | 634 | vmax=1, |
@@ -628,9 +636,10 class PlotCrossSpectraData(PlotData): | |||
|
628 | 636 | ) |
|
629 | 637 | else: |
|
630 | 638 | ax.plt.set_array(coh.T.ravel()) |
|
631 | self.titles.append('Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |
|
639 | self.titles.append( | |
|
640 | 'Coherence Ch{} * Ch{}'.format(pair[0], pair[1])) | |
|
632 | 641 | |
|
633 | ax = self.axes[4*n+3] | |
|
642 | ax = self.axes[4 * n + 3] | |
|
634 | 643 | if ax.firsttime: |
|
635 | 644 | ax.plt = ax.pcolormesh(x, y, phase.T, |
|
636 | 645 | vmin=-180, |
@@ -640,7 +649,7 class PlotCrossSpectraData(PlotData): | |||
|
640 | 649 | else: |
|
641 | 650 | ax.plt.set_array(phase.T.ravel()) |
|
642 | 651 | self.titles.append('Phase CH{} * CH{}'.format(pair[0], pair[1])) |
|
643 | ||
|
652 | ||
|
644 | 653 | self.saveTime = self.max_time |
|
645 | 654 | |
|
646 | 655 | |
@@ -662,12 +671,13 class PlotRTIData(PlotData): | |||
|
662 | 671 | |
|
663 | 672 | def setup(self): |
|
664 | 673 | self.xaxis = 'time' |
|
665 |
self.ncols = 1 |
|
|
674 | self.ncols = 1 | |
|
666 | 675 | self.nrows = len(self.data.channels) |
|
667 | 676 | self.nplots = len(self.data.channels) |
|
668 | 677 | self.ylabel = 'Range [Km]' |
|
669 | 678 | self.cb_label = 'dB' |
|
670 |
self.titles = ['{} Channel {}'.format( |
|
|
679 | self.titles = ['{} Channel {}'.format( | |
|
680 | self.CODE.upper(), x) for x in range(self.nrows)] | |
|
671 | 681 | |
|
672 | 682 | def plot(self): |
|
673 | 683 | self.x = self.times |
@@ -676,17 +686,18 class PlotRTIData(PlotData): | |||
|
676 | 686 | self.z = numpy.ma.masked_invalid(self.z) |
|
677 | 687 | |
|
678 | 688 | for n, ax in enumerate(self.axes): |
|
679 |
x, y, z = self.fill_gaps(*self.decimate()) |
|
|
689 | x, y, z = self.fill_gaps(*self.decimate()) | |
|
680 | 690 | self.zmin = self.zmin if self.zmin else numpy.min(self.z) |
|
681 | 691 | self.zmax = self.zmax if self.zmax else numpy.max(self.z) |
|
682 |
if ax.firsttime: |
|
|
692 | if ax.firsttime: | |
|
683 | 693 | ax.plt = ax.pcolormesh(x, y, z[n].T, |
|
684 | vmin=self.zmin, | |
|
685 | vmax=self.zmax, | |
|
686 | cmap=plt.get_cmap(self.colormap) | |
|
687 | ) | |
|
694 | vmin=self.zmin, | |
|
695 | vmax=self.zmax, | |
|
696 | cmap=plt.get_cmap(self.colormap) | |
|
697 | ) | |
|
688 | 698 | if self.showprofile: |
|
689 |
ax.plot_profile= self.pf_axes[n].plot( |
|
|
699 | ax.plot_profile = self.pf_axes[n].plot( | |
|
700 | self.data['rti'][n][-1], self.y)[0] | |
|
690 | 701 | ax.plot_noise = self.pf_axes[n].plot(numpy.repeat(self.data['noise'][n][-1], len(self.y)), self.y, |
|
691 | 702 | color="k", linestyle="dashed", lw=1)[0] |
|
692 | 703 | else: |
@@ -695,12 +706,13 class PlotRTIData(PlotData): | |||
|
695 | 706 | vmin=self.zmin, |
|
696 | 707 | vmax=self.zmax, |
|
697 | 708 | cmap=plt.get_cmap(self.colormap) |
|
698 | ) | |
|
709 | ) | |
|
699 | 710 | if self.showprofile: |
|
700 | 711 | ax.plot_profile.set_data(self.data['rti'][n][-1], self.y) |
|
701 |
ax.plot_noise.set_data(numpy.repeat( |
|
|
712 | ax.plot_noise.set_data(numpy.repeat( | |
|
713 | self.data['noise'][n][-1], len(self.y)), self.y) | |
|
702 | 714 | |
|
703 |
self.saveTime = self.min_time |
|
|
715 | self.saveTime = self.min_time | |
|
704 | 716 | |
|
705 | 717 | |
|
706 | 718 | class PlotCOHData(PlotRTIData): |
@@ -715,13 +727,15 class PlotCOHData(PlotRTIData): | |||
|
715 | 727 | self.ncols = 1 |
|
716 | 728 | self.nrows = len(self.data.pairs) |
|
717 | 729 | self.nplots = len(self.data.pairs) |
|
718 |
self.ylabel = 'Range [Km]' |
|
|
730 | self.ylabel = 'Range [Km]' | |
|
719 | 731 | if self.CODE == 'coh': |
|
720 | 732 | self.cb_label = '' |
|
721 | self.titles = ['Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
|
733 | self.titles = [ | |
|
734 | 'Coherence Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
|
722 | 735 | else: |
|
723 | 736 | self.cb_label = 'Degrees' |
|
724 | self.titles = ['Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
|
737 | self.titles = [ | |
|
738 | 'Phase Map Ch{} * Ch{}'.format(x[0], x[1]) for x in self.data.pairs] | |
|
725 | 739 | |
|
726 | 740 | |
|
727 | 741 | class PlotPHASEData(PlotCOHData): |
@@ -753,9 +767,9 class PlotNoiseData(PlotData): | |||
|
753 | 767 | |
|
754 | 768 | x = self.times |
|
755 | 769 | xmin = self.min_time |
|
756 | xmax = xmin+self.xrange*60*60 | |
|
770 | xmax = xmin + self.xrange * 60 * 60 | |
|
757 | 771 | Y = self.data[self.CODE] |
|
758 | ||
|
772 | ||
|
759 | 773 | if self.axes[0].firsttime: |
|
760 | 774 | for ch in self.data.channels: |
|
761 | 775 | y = Y[ch] |
@@ -765,7 +779,7 class PlotNoiseData(PlotData): | |||
|
765 | 779 | for ch in self.data.channels: |
|
766 | 780 | y = Y[ch] |
|
767 | 781 | self.axes[0].lines[ch].set_data(x, y) |
|
768 | ||
|
782 | ||
|
769 | 783 | self.ymin = numpy.nanmin(Y) - 5 |
|
770 | 784 | self.ymax = numpy.nanmax(Y) + 5 |
|
771 | 785 | self.saveTime = self.min_time |
@@ -813,26 +827,27 class PlotSkyMapData(PlotData): | |||
|
813 | 827 | else: |
|
814 | 828 | self.figure.clf() |
|
815 | 829 | |
|
816 | self.ax = plt.subplot2grid((self.nrows, self.ncols), (0, 0), 1, 1, polar=True) | |
|
830 | self.ax = plt.subplot2grid( | |
|
831 | (self.nrows, self.ncols), (0, 0), 1, 1, polar=True) | |
|
817 | 832 | self.ax.firsttime = True |
|
818 | 833 | |
|
819 | ||
|
820 | 834 | def plot(self): |
|
821 | 835 | |
|
822 |
arrayParameters = numpy.concatenate( |
|
|
823 | error = arrayParameters[:,-1] | |
|
836 | arrayParameters = numpy.concatenate( | |
|
837 | [self.data['param'][t] for t in self.times]) | |
|
838 | error = arrayParameters[:, -1] | |
|
824 | 839 | indValid = numpy.where(error == 0)[0] |
|
825 | finalMeteor = arrayParameters[indValid,:] | |
|
826 | finalAzimuth = finalMeteor[:,3] | |
|
827 | finalZenith = finalMeteor[:,4] | |
|
840 | finalMeteor = arrayParameters[indValid, :] | |
|
841 | finalAzimuth = finalMeteor[:, 3] | |
|
842 | finalZenith = finalMeteor[:, 4] | |
|
828 | 843 | |
|
829 | x = finalAzimuth*numpy.pi/180 | |
|
844 | x = finalAzimuth * numpy.pi / 180 | |
|
830 | 845 | y = finalZenith |
|
831 | 846 | |
|
832 | 847 | if self.ax.firsttime: |
|
833 | 848 | self.ax.plot = self.ax.plot(x, y, 'bo', markersize=5)[0] |
|
834 | self.ax.set_ylim(0,90) | |
|
835 | self.ax.set_yticks(numpy.arange(0,90,20)) | |
|
849 | self.ax.set_ylim(0, 90) | |
|
850 | self.ax.set_yticks(numpy.arange(0, 90, 20)) | |
|
836 | 851 | self.ax.set_xlabel(self.xlabel) |
|
837 | 852 | self.ax.set_ylabel(self.ylabel) |
|
838 | 853 | self.ax.yaxis.labelpad = 40 |
@@ -847,9 +862,9 class PlotSkyMapData(PlotData): | |||
|
847 | 862 | dt2, |
|
848 | 863 | len(x)) |
|
849 | 864 | self.ax.set_title(title, size=8) |
|
850 | ||
|
851 | 865 | self.saveTime = self.max_time |
|
852 | 866 | |
|
867 | ||
|
853 | 868 | class PlotParamData(PlotRTIData): |
|
854 | 869 | ''' |
|
855 | 870 | Plot for data_param object |
@@ -866,7 +881,7 class PlotParamData(PlotRTIData): | |||
|
866 | 881 | if self.showSNR: |
|
867 | 882 | self.nrows += 1 |
|
868 | 883 | self.nplots += 1 |
|
869 | ||
|
884 | ||
|
870 | 885 | self.ylabel = 'Height [Km]' |
|
871 | 886 | self.titles = self.data.parameters \ |
|
872 | 887 | if self.data.parameters else ['Param {}'.format(x) for x in xrange(self.nrows)] |
@@ -874,10 +889,10 class PlotParamData(PlotRTIData): | |||
|
874 | 889 | self.titles.append('SNR') |
|
875 | 890 | |
|
876 | 891 | def plot(self): |
|
877 |
self.data.normalize_heights() |
|
|
892 | self.data.normalize_heights() | |
|
878 | 893 | self.x = self.times |
|
879 | 894 | self.y = self.data.heights |
|
880 |
if self.showSNR: |
|
|
895 | if self.showSNR: | |
|
881 | 896 | self.z = numpy.concatenate( |
|
882 | 897 | (self.data[self.CODE], self.data['snr']) |
|
883 | 898 | ) |
@@ -900,7 +915,7 class PlotParamData(PlotRTIData): | |||
|
900 | 915 | vmin=self.zmin, |
|
901 | 916 | vmax=self.zmax, |
|
902 | 917 | cmap=self.cmaps[n] |
|
903 |
) |
|
|
918 | ) | |
|
904 | 919 | else: |
|
905 | 920 | if self.zlimits is not None: |
|
906 | 921 | self.zmin, self.zmax = self.zlimits[n] |
@@ -909,7 +924,7 class PlotParamData(PlotRTIData): | |||
|
909 | 924 | vmin=self.zmin, |
|
910 | 925 | vmax=self.zmax, |
|
911 | 926 | cmap=self.cmaps[n] |
|
912 | ) | |
|
927 | ) | |
|
913 | 928 | |
|
914 | 929 | self.saveTime = self.min_time |
|
915 | 930 |
@@ -11,79 +11,80 from figure import Figure, isRealtime | |||
|
11 | 11 | from plotting_codes import * |
|
12 | 12 | |
|
13 | 13 | class SpectraHeisScope(Figure): |
|
14 | ||
|
15 | ||
|
14 | ||
|
15 | ||
|
16 | 16 | isConfig = None |
|
17 | 17 | __nsubplots = None |
|
18 | ||
|
18 | ||
|
19 | 19 | WIDTHPROF = None |
|
20 | 20 | HEIGHTPROF = None |
|
21 | 21 | PREFIX = 'spc' |
|
22 | ||
|
23 | def __init__(self): | |
|
24 | ||
|
22 | ||
|
23 | def __init__(self, **kwargs): | |
|
24 | ||
|
25 | Figure.__init__(self, **kwargs) | |
|
25 | 26 | self.isConfig = False |
|
26 | 27 | self.__nsubplots = 1 |
|
27 | ||
|
28 | ||
|
28 | 29 | self.WIDTH = 230 |
|
29 | 30 | self.HEIGHT = 250 |
|
30 | 31 | self.WIDTHPROF = 120 |
|
31 | 32 | self.HEIGHTPROF = 0 |
|
32 | 33 | self.counter_imagwr = 0 |
|
33 | ||
|
34 | ||
|
34 | 35 | self.PLOT_CODE = SPEC_CODE |
|
35 | ||
|
36 | ||
|
36 | 37 | def getSubplots(self): |
|
37 | ||
|
38 | ||
|
38 | 39 | ncol = int(numpy.sqrt(self.nplots)+0.9) |
|
39 | 40 | nrow = int(self.nplots*1./ncol + 0.9) |
|
40 | ||
|
41 | ||
|
41 | 42 | return nrow, ncol |
|
42 | ||
|
43 | ||
|
43 | 44 | def setup(self, id, nplots, wintitle, show): |
|
44 | ||
|
45 | ||
|
45 | 46 | showprofile = False |
|
46 | 47 | self.__showprofile = showprofile |
|
47 | 48 | self.nplots = nplots |
|
48 | ||
|
49 | ||
|
49 | 50 | ncolspan = 1 |
|
50 | 51 | colspan = 1 |
|
51 | 52 | if showprofile: |
|
52 | 53 | ncolspan = 3 |
|
53 | 54 | colspan = 2 |
|
54 | 55 | self.__nsubplots = 2 |
|
55 | ||
|
56 | ||
|
56 | 57 | self.createFigure(id = id, |
|
57 | 58 | wintitle = wintitle, |
|
58 | 59 | widthplot = self.WIDTH + self.WIDTHPROF, |
|
59 | 60 | heightplot = self.HEIGHT + self.HEIGHTPROF, |
|
60 | 61 | show = show) |
|
61 | ||
|
62 | ||
|
62 | 63 | nrow, ncol = self.getSubplots() |
|
63 | ||
|
64 | ||
|
64 | 65 | counter = 0 |
|
65 | 66 | for y in range(nrow): |
|
66 | 67 | for x in range(ncol): |
|
67 | ||
|
68 | ||
|
68 | 69 | if counter >= self.nplots: |
|
69 | 70 | break |
|
70 | ||
|
71 | ||
|
71 | 72 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan, colspan, 1) |
|
72 | ||
|
73 | ||
|
73 | 74 | if showprofile: |
|
74 | 75 | self.addAxes(nrow, ncol*ncolspan, y, x*ncolspan+colspan, 1, 1) |
|
75 | ||
|
76 | ||
|
76 | 77 | counter += 1 |
|
77 | 78 | |
|
78 | ||
|
79 | ||
|
79 | 80 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
80 | 81 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
81 | 82 | figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
82 | 83 | server=None, folder=None, username=None, password=None, |
|
83 | 84 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
84 | ||
|
85 | ||
|
85 | 86 | """ |
|
86 | ||
|
87 | ||
|
87 | 88 | Input: |
|
88 | 89 | dataOut : |
|
89 | 90 | id : |
@@ -94,12 +95,12 class SpectraHeisScope(Figure): | |||
|
94 | 95 | ymin : None, |
|
95 | 96 | ymax : None, |
|
96 | 97 | """ |
|
97 | ||
|
98 | ||
|
98 | 99 | if dataOut.realtime: |
|
99 | 100 | if not(isRealtime(utcdatatime = dataOut.utctime)): |
|
100 | 101 | print 'Skipping this plot function' |
|
101 | 102 | return |
|
102 | ||
|
103 | ||
|
103 | 104 | if channelList == None: |
|
104 | 105 | channelIndexList = dataOut.channelIndexList |
|
105 | 106 | else: |
@@ -108,9 +109,9 class SpectraHeisScope(Figure): | |||
|
108 | 109 | if channel not in dataOut.channelList: |
|
109 | 110 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
110 | 111 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
111 | ||
|
112 | ||
|
112 | 113 | # x = dataOut.heightList |
|
113 |
c = 3E8 |
|
|
114 | c = 3E8 | |
|
114 | 115 | deltaHeight = dataOut.heightList[1] - dataOut.heightList[0] |
|
115 | 116 | #deberia cambiar para el caso de 1Mhz y 100KHz |
|
116 | 117 | x = numpy.arange(-1*dataOut.nHeights/2.,dataOut.nHeights/2.)*(c/(2*deltaHeight*dataOut.nHeights*1000)) |
@@ -122,7 +123,7 class SpectraHeisScope(Figure): | |||
|
122 | 123 | data = dataOut.data_spc / factor |
|
123 | 124 | datadB = 10.*numpy.log10(data) |
|
124 | 125 | y = datadB |
|
125 | ||
|
126 | ||
|
126 | 127 | #thisDatetime = dataOut.datatime |
|
127 | 128 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
128 | 129 | title = wintitle + " Scope: %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
@@ -130,29 +131,29 class SpectraHeisScope(Figure): | |||
|
130 | 131 | #para 1Mhz descomentar la siguiente linea |
|
131 | 132 | #xlabel = "Frequency x 10000" |
|
132 | 133 | ylabel = "Intensity (dB)" |
|
133 | ||
|
134 | ||
|
134 | 135 | if not self.isConfig: |
|
135 | 136 | nplots = len(channelIndexList) |
|
136 | ||
|
137 | ||
|
137 | 138 | self.setup(id=id, |
|
138 | 139 | nplots=nplots, |
|
139 | 140 | wintitle=wintitle, |
|
140 | 141 | show=show) |
|
141 | ||
|
142 | ||
|
142 | 143 | if xmin == None: xmin = numpy.nanmin(x) |
|
143 | 144 | if xmax == None: xmax = numpy.nanmax(x) |
|
144 | 145 | if ymin == None: ymin = numpy.nanmin(y) |
|
145 | 146 | if ymax == None: ymax = numpy.nanmax(y) |
|
146 | ||
|
147 | ||
|
147 | 148 | self.FTP_WEI = ftp_wei |
|
148 | 149 | self.EXP_CODE = exp_code |
|
149 | 150 | self.SUB_EXP_CODE = sub_exp_code |
|
150 | 151 | self.PLOT_POS = plot_pos |
|
151 | ||
|
152 | ||
|
152 | 153 | self.isConfig = True |
|
153 | ||
|
154 | ||
|
154 | 155 | self.setWinTitle(title) |
|
155 | ||
|
156 | ||
|
156 | 157 | for i in range(len(self.axesList)): |
|
157 | 158 | ychannel = y[i,:] |
|
158 | 159 | str_datetime = '%s %s'%(thisDatetime.strftime("%Y/%m/%d"),thisDatetime.strftime("%H:%M:%S")) |
@@ -161,10 +162,10 class SpectraHeisScope(Figure): | |||
|
161 | 162 | axes.pline(x, ychannel, |
|
162 | 163 | xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, |
|
163 | 164 | xlabel=xlabel, ylabel=ylabel, title=title, grid='both') |
|
164 | ||
|
165 | ||
|
165 | ||
|
166 | ||
|
166 | 167 | self.draw() |
|
167 | ||
|
168 | ||
|
168 | 169 | self.save(figpath=figpath, |
|
169 | 170 | figfile=figfile, |
|
170 | 171 | save=save, |
@@ -173,18 +174,18 class SpectraHeisScope(Figure): | |||
|
173 | 174 | thisDatetime=thisDatetime) |
|
174 | 175 | |
|
175 | 176 | class RTIfromSpectraHeis(Figure): |
|
176 | ||
|
177 | ||
|
177 | 178 | isConfig = None |
|
178 | 179 | __nsubplots = None |
|
179 | 180 | |
|
180 | 181 | PREFIX = 'rtinoise' |
|
181 | ||
|
182 | def __init__(self): | |
|
183 | ||
|
182 | ||
|
183 | def __init__(self, **kwargs): | |
|
184 | Figure.__init__(self, **kwargs) | |
|
184 | 185 | self.timerange = 24*60*60 |
|
185 | 186 | self.isConfig = False |
|
186 | 187 | self.__nsubplots = 1 |
|
187 | ||
|
188 | ||
|
188 | 189 | self.WIDTH = 820 |
|
189 | 190 | self.HEIGHT = 200 |
|
190 | 191 | self.WIDTHPROF = 120 |
@@ -193,43 +194,43 class RTIfromSpectraHeis(Figure): | |||
|
193 | 194 | self.xdata = None |
|
194 | 195 | self.ydata = None |
|
195 | 196 | self.figfile = None |
|
196 | ||
|
197 | ||
|
197 | 198 | self.PLOT_CODE = RTI_CODE |
|
198 | ||
|
199 | ||
|
199 | 200 | def getSubplots(self): |
|
200 | ||
|
201 | ||
|
201 | 202 | ncol = 1 |
|
202 | 203 | nrow = 1 |
|
203 | ||
|
204 | ||
|
204 | 205 | return nrow, ncol |
|
205 | ||
|
206 | ||
|
206 | 207 | def setup(self, id, nplots, wintitle, showprofile=True, show=True): |
|
207 | ||
|
208 | ||
|
208 | 209 | self.__showprofile = showprofile |
|
209 | 210 | self.nplots = nplots |
|
210 | ||
|
211 | ||
|
211 | 212 | ncolspan = 7 |
|
212 | 213 | colspan = 6 |
|
213 | 214 | self.__nsubplots = 2 |
|
214 | ||
|
215 | ||
|
215 | 216 | self.createFigure(id = id, |
|
216 | 217 | wintitle = wintitle, |
|
217 | 218 | widthplot = self.WIDTH+self.WIDTHPROF, |
|
218 | 219 | heightplot = self.HEIGHT+self.HEIGHTPROF, |
|
219 | 220 | show = show) |
|
220 | ||
|
221 | ||
|
221 | 222 | nrow, ncol = self.getSubplots() |
|
222 | ||
|
223 | ||
|
223 | 224 | self.addAxes(nrow, ncol*ncolspan, 0, 0, colspan, 1) |
|
224 | ||
|
225 | ||
|
225 | ||
|
226 | ||
|
226 | 227 | def run(self, dataOut, id, wintitle="", channelList=None, showprofile='True', |
|
227 | 228 | xmin=None, xmax=None, ymin=None, ymax=None, |
|
228 | 229 | timerange=None, |
|
229 | 230 | save=False, figpath='./', figfile=None, ftp=False, wr_period=1, show=True, |
|
230 | 231 | server=None, folder=None, username=None, password=None, |
|
231 | 232 | ftp_wei=0, exp_code=0, sub_exp_code=0, plot_pos=0): |
|
232 | ||
|
233 | ||
|
233 | 234 | if channelList == None: |
|
234 | 235 | channelIndexList = dataOut.channelIndexList |
|
235 | 236 | channelList = dataOut.channelList |
@@ -239,86 +240,86 class RTIfromSpectraHeis(Figure): | |||
|
239 | 240 | if channel not in dataOut.channelList: |
|
240 | 241 | raise ValueError, "Channel %d is not in dataOut.channelList" |
|
241 | 242 | channelIndexList.append(dataOut.channelList.index(channel)) |
|
242 | ||
|
243 | ||
|
243 | 244 | if timerange != None: |
|
244 | 245 | self.timerange = timerange |
|
245 | ||
|
246 | ||
|
246 | 247 | x = dataOut.getTimeRange() |
|
247 | 248 | y = dataOut.getHeiRange() |
|
248 | ||
|
249 | ||
|
249 | 250 | factor = dataOut.normFactor |
|
250 | 251 | data = dataOut.data_spc / factor |
|
251 | 252 | data = numpy.average(data,axis=1) |
|
252 | 253 | datadB = 10*numpy.log10(data) |
|
253 | ||
|
254 | ||
|
254 | 255 | # factor = dataOut.normFactor |
|
255 | 256 | # noise = dataOut.getNoise()/factor |
|
256 | 257 | # noisedB = 10*numpy.log10(noise) |
|
257 | ||
|
258 | ||
|
258 | 259 | #thisDatetime = dataOut.datatime |
|
259 | 260 | thisDatetime = datetime.datetime.utcfromtimestamp(dataOut.getTimeRange()[0]) |
|
260 | 261 | title = wintitle + " RTI: %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
261 | 262 | xlabel = "Local Time" |
|
262 | 263 | ylabel = "Intensity (dB)" |
|
263 | ||
|
264 | ||
|
264 | 265 | if not self.isConfig: |
|
265 | ||
|
266 | ||
|
266 | 267 | nplots = 1 |
|
267 | ||
|
268 | ||
|
268 | 269 | self.setup(id=id, |
|
269 | 270 | nplots=nplots, |
|
270 | 271 | wintitle=wintitle, |
|
271 | 272 | showprofile=showprofile, |
|
272 | 273 | show=show) |
|
273 | ||
|
274 | ||
|
274 | 275 | self.tmin, self.tmax = self.getTimeLim(x, xmin, xmax) |
|
275 | ||
|
276 | ||
|
276 | 277 | if ymin == None: ymin = numpy.nanmin(datadB) |
|
277 | 278 | if ymax == None: ymax = numpy.nanmax(datadB) |
|
278 | ||
|
279 | ||
|
279 | 280 | self.name = thisDatetime.strftime("%Y%m%d_%H%M%S") |
|
280 | 281 | self.isConfig = True |
|
281 | 282 | self.figfile = figfile |
|
282 | 283 | self.xdata = numpy.array([]) |
|
283 | 284 | self.ydata = numpy.array([]) |
|
284 | ||
|
285 | ||
|
285 | 286 | self.FTP_WEI = ftp_wei |
|
286 | 287 | self.EXP_CODE = exp_code |
|
287 | 288 | self.SUB_EXP_CODE = sub_exp_code |
|
288 | 289 | self.PLOT_POS = plot_pos |
|
289 | ||
|
290 | ||
|
290 | 291 | self.setWinTitle(title) |
|
291 | ||
|
292 | ||
|
292 | ||
|
293 | ||
|
293 | 294 | # title = "RTI %s" %(thisDatetime.strftime("%d-%b-%Y")) |
|
294 | 295 | title = "RTI - %s" %(thisDatetime.strftime("%d-%b-%Y %H:%M:%S")) |
|
295 | ||
|
296 | ||
|
296 | 297 | legendlabels = ["channel %d"%idchannel for idchannel in channelList] |
|
297 | 298 | axes = self.axesList[0] |
|
298 | ||
|
299 | ||
|
299 | 300 | self.xdata = numpy.hstack((self.xdata, x[0:1])) |
|
300 | ||
|
301 | ||
|
301 | 302 | if len(self.ydata)==0: |
|
302 | 303 | self.ydata = datadB[channelIndexList].reshape(-1,1) |
|
303 | 304 | else: |
|
304 | 305 | self.ydata = numpy.hstack((self.ydata, datadB[channelIndexList].reshape(-1,1))) |
|
305 | ||
|
306 | ||
|
306 | ||
|
307 | ||
|
307 | 308 | axes.pmultilineyaxis(x=self.xdata, y=self.ydata, |
|
308 | 309 | xmin=self.tmin, xmax=self.tmax, ymin=ymin, ymax=ymax, |
|
309 | 310 | xlabel=xlabel, ylabel=ylabel, title=title, legendlabels=legendlabels, marker='.', markersize=8, linestyle="solid", grid='both', |
|
310 | 311 | XAxisAsTime=True |
|
311 | 312 | ) |
|
312 | ||
|
313 | ||
|
313 | 314 | self.draw() |
|
314 | ||
|
315 | ||
|
315 | 316 | update_figfile = False |
|
316 | ||
|
317 | ||
|
317 | 318 | if dataOut.ltctime >= self.tmax: |
|
318 | 319 | self.counter_imagwr = wr_period |
|
319 | 320 | self.isConfig = False |
|
320 | 321 | update_figfile = True |
|
321 | ||
|
322 | ||
|
322 | 323 | self.save(figpath=figpath, |
|
323 | 324 | figfile=figfile, |
|
324 | 325 | save=save, |
@@ -25,8 +25,8 class SpectraPlot(Figure): | |||
|
25 | 25 | self.isConfig = False |
|
26 | 26 | self.__nsubplots = 1 |
|
27 | 27 | |
|
28 |
self.WIDTH = |
|
|
29 |
self.HEIGHT = |
|
|
28 | self.WIDTH = 300 | |
|
29 | self.HEIGHT = 300 | |
|
30 | 30 | self.WIDTHPROF = 120 |
|
31 | 31 | self.HEIGHTPROF = 0 |
|
32 | 32 | self.counter_imagwr = 0 |
@@ -113,7 +113,7 class Scope(Figure): | |||
|
113 | 113 | def run(self, dataOut, id, wintitle="", channelList=None, |
|
114 | 114 | xmin=None, xmax=None, ymin=None, ymax=None, save=False, |
|
115 | 115 | figpath='./', figfile=None, show=True, wr_period=1, |
|
116 | ftp=False, server=None, folder=None, username=None, password=None, type='power'): | |
|
116 | ftp=False, server=None, folder=None, username=None, password=None, type='power', **kwargs): | |
|
117 | 117 | |
|
118 | 118 | """ |
|
119 | 119 |
@@ -4,32 +4,36 import sys | |||
|
4 | 4 | import matplotlib |
|
5 | 5 | |
|
6 | 6 | if 'linux' in sys.platform: |
|
7 |
matplotlib.use(" |
|
|
7 | matplotlib.use("TkAgg") | |
|
8 | 8 | |
|
9 | 9 | if 'darwin' in sys.platform: |
|
10 | 10 | matplotlib.use('TKAgg') |
|
11 | #Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' | |
|
11 | # Qt4Agg', 'GTK', 'GTKAgg', 'ps', 'agg', 'cairo', 'MacOSX', 'GTKCairo', 'WXAgg', 'template', 'TkAgg', 'GTK3Cairo', 'GTK3Agg', 'svg', 'WebAgg', 'CocoaAgg', 'emf', 'gdk', 'WX' | |
|
12 | 12 | import matplotlib.pyplot |
|
13 | 13 | |
|
14 | 14 | from mpl_toolkits.axes_grid1 import make_axes_locatable |
|
15 | 15 | from matplotlib.ticker import FuncFormatter, LinearLocator |
|
16 | 16 | |
|
17 | 17 | ########################################### |
|
18 | #Actualizacion de las funciones del driver | |
|
18 | # Actualizacion de las funciones del driver | |
|
19 | 19 | ########################################### |
|
20 | 20 | |
|
21 | 21 | # create jro colormap |
|
22 | 22 | |
|
23 | 23 | jet_values = matplotlib.pyplot.get_cmap("jet", 100)(numpy.arange(100))[10:90] |
|
24 |
blu_values = matplotlib.pyplot.get_cmap( |
|
|
25 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list("jro", numpy.vstack((blu_values, jet_values))) | |
|
24 | blu_values = matplotlib.pyplot.get_cmap( | |
|
25 | "seismic_r", 20)(numpy.arange(20))[10:15] | |
|
26 | ncmap = matplotlib.colors.LinearSegmentedColormap.from_list( | |
|
27 | "jro", numpy.vstack((blu_values, jet_values))) | |
|
26 | 28 | matplotlib.pyplot.register_cmap(cmap=ncmap) |
|
27 | 29 | |
|
28 | def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80): | |
|
30 | ||
|
31 | def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi=80): | |
|
29 | 32 | |
|
30 | 33 | matplotlib.pyplot.ioff() |
|
31 | 34 | |
|
32 |
fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=( |
|
|
35 | fig = matplotlib.pyplot.figure(num=id, facecolor=facecolor, figsize=( | |
|
36 | 1.0 * width / dpi, 1.0 * height / dpi)) | |
|
33 | 37 | fig.canvas.manager.set_window_title(wintitle) |
|
34 | 38 | # fig.canvas.manager.resize(width, height) |
|
35 | 39 | matplotlib.pyplot.ion() |
@@ -39,10 +43,11 def createFigure(id, wintitle, width, height, facecolor="w", show=True, dpi = 80 | |||
|
39 | 43 | |
|
40 | 44 | return fig |
|
41 | 45 | |
|
46 | ||
|
42 | 47 | def closeFigure(show=False, fig=None): |
|
43 | 48 | |
|
44 | # matplotlib.pyplot.ioff() | |
|
45 | # matplotlib.pyplot.pause(0) | |
|
49 | # matplotlib.pyplot.ioff() | |
|
50 | # matplotlib.pyplot.pause(0) | |
|
46 | 51 | |
|
47 | 52 | if show: |
|
48 | 53 | matplotlib.pyplot.show() |
@@ -60,47 +65,52 def closeFigure(show=False, fig=None): | |||
|
60 | 65 | |
|
61 | 66 | return |
|
62 | 67 | |
|
68 | ||
|
63 | 69 | def saveFigure(fig, filename): |
|
64 | 70 | |
|
65 | # matplotlib.pyplot.ioff() | |
|
71 | # matplotlib.pyplot.ioff() | |
|
66 | 72 | fig.savefig(filename, dpi=matplotlib.pyplot.gcf().dpi) |
|
67 | 73 | # matplotlib.pyplot.ion() |
|
68 | 74 | |
|
75 | ||
|
69 | 76 | def clearFigure(fig): |
|
70 | 77 | |
|
71 | 78 | fig.clf() |
|
72 | 79 | |
|
80 | ||
|
73 | 81 | def setWinTitle(fig, title): |
|
74 | 82 | |
|
75 | 83 | fig.canvas.manager.set_window_title(title) |
|
76 | 84 | |
|
85 | ||
|
77 | 86 | def setTitle(fig, title): |
|
78 | 87 | |
|
79 | 88 | fig.suptitle(title) |
|
80 | 89 | |
|
90 | ||
|
81 | 91 | def createAxes(fig, nrow, ncol, xpos, ypos, colspan, rowspan, polar=False): |
|
82 | 92 | |
|
83 | 93 | matplotlib.pyplot.ioff() |
|
84 | 94 | matplotlib.pyplot.figure(fig.number) |
|
85 | 95 | axes = matplotlib.pyplot.subplot2grid((nrow, ncol), |
|
86 | (xpos, ypos), | |
|
87 | colspan=colspan, | |
|
88 | rowspan=rowspan, | |
|
89 | polar=polar) | |
|
90 | ||
|
91 | axes.grid(True) | |
|
96 | (xpos, ypos), | |
|
97 | colspan=colspan, | |
|
98 | rowspan=rowspan, | |
|
99 | polar=polar) | |
|
92 | 100 | |
|
93 | 101 | matplotlib.pyplot.ion() |
|
94 | 102 | return axes |
|
95 | 103 | |
|
104 | ||
|
96 | 105 | def setAxesText(ax, text): |
|
97 | 106 | |
|
98 | 107 | ax.annotate(text, |
|
99 |
xy |
|
|
100 |
xycoords |
|
|
101 |
horizontalalignment |
|
|
102 |
verticalalignment |
|
|
103 |
fontsize |
|
|
108 | xy=(.1, .99), | |
|
109 | xycoords='figure fraction', | |
|
110 | horizontalalignment='left', | |
|
111 | verticalalignment='top', | |
|
112 | fontsize=10) | |
|
113 | ||
|
104 | 114 | |
|
105 | 115 | def printLabels(ax, xlabel, ylabel, title): |
|
106 | 116 | |
@@ -108,11 +118,11 def printLabels(ax, xlabel, ylabel, title): | |||
|
108 | 118 | ax.set_ylabel(ylabel, size=11) |
|
109 | 119 | ax.set_title(title, size=8) |
|
110 | 120 | |
|
121 | ||
|
111 | 122 | def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', |
|
112 | 123 | ticksize=9, xtick_visible=True, ytick_visible=True, |
|
113 | 124 | nxticks=4, nyticks=10, |
|
114 | grid=None,color='blue'): | |
|
115 | ||
|
125 | grid=None, color='blue'): | |
|
116 | 126 | """ |
|
117 | 127 | |
|
118 | 128 | Input: |
@@ -121,18 +131,19 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='' | |||
|
121 | 131 | |
|
122 | 132 | matplotlib.pyplot.ioff() |
|
123 | 133 | |
|
124 | ax.set_xlim([xmin,xmax]) | |
|
125 | ax.set_ylim([ymin,ymax]) | |
|
134 | ax.set_xlim([xmin, xmax]) | |
|
135 | ax.set_ylim([ymin, ymax]) | |
|
126 | 136 | |
|
127 | 137 | printLabels(ax, xlabel, ylabel, title) |
|
128 | 138 | |
|
129 | 139 | ###################################################### |
|
130 | if (xmax-xmin)<=1: | |
|
131 | xtickspos = numpy.linspace(xmin,xmax,nxticks) | |
|
132 | xtickspos = numpy.array([float("%.1f"%i) for i in xtickspos]) | |
|
140 | if (xmax - xmin) <= 1: | |
|
141 | xtickspos = numpy.linspace(xmin, xmax, nxticks) | |
|
142 | xtickspos = numpy.array([float("%.1f" % i) for i in xtickspos]) | |
|
133 | 143 | ax.set_xticks(xtickspos) |
|
134 | 144 | else: |
|
135 |
xtickspos = numpy.arange(nxticks)* |
|
|
145 | xtickspos = numpy.arange(nxticks) * \ | |
|
146 | int((xmax - xmin) / (nxticks)) + int(xmin) | |
|
136 | 147 | # xtickspos = numpy.arange(nxticks)*float(xmax-xmin)/float(nxticks) + int(xmin) |
|
137 | 148 | ax.set_xticks(xtickspos) |
|
138 | 149 | |
@@ -170,26 +181,29 def createPline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='' | |||
|
170 | 181 | |
|
171 | 182 | return iplot |
|
172 | 183 | |
|
184 | ||
|
173 | 185 | def set_linedata(ax, x, y, idline): |
|
174 | 186 | |
|
175 | ax.lines[idline].set_data(x,y) | |
|
187 | ax.lines[idline].set_data(x, y) | |
|
188 | ||
|
176 | 189 | |
|
177 | 190 | def pline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
178 | 191 | |
|
179 |
ax = iplot. |
|
|
192 | ax = iplot.axes | |
|
180 | 193 | |
|
181 | 194 | printLabels(ax, xlabel, ylabel, title) |
|
182 | 195 | |
|
183 | 196 | set_linedata(ax, x, y, idline=0) |
|
184 | 197 | |
|
198 | ||
|
185 | 199 | def addpline(ax, x, y, color, linestyle, lw): |
|
186 | 200 | |
|
187 | ax.plot(x,y,color=color,linestyle=linestyle,lw=lw) | |
|
201 | ax.plot(x, y, color=color, linestyle=linestyle, lw=lw) | |
|
188 | 202 | |
|
189 | 203 | |
|
190 | 204 | def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, |
|
191 |
xlabel='', ylabel='', title='', ticksize |
|
|
192 | colormap='jet',cblabel='', cbsize="5%", | |
|
205 | xlabel='', ylabel='', title='', ticksize=9, | |
|
206 | colormap='jet', cblabel='', cbsize="5%", | |
|
193 | 207 | XAxisAsTime=False): |
|
194 | 208 | |
|
195 | 209 | matplotlib.pyplot.ioff() |
@@ -199,16 +213,16 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |||
|
199 | 213 | fig = ax.get_figure() |
|
200 | 214 | fig.add_axes(ax_cb) |
|
201 | 215 | |
|
202 | ax.set_xlim([xmin,xmax]) | |
|
203 | ax.set_ylim([ymin,ymax]) | |
|
216 | ax.set_xlim([xmin, xmax]) | |
|
217 | ax.set_ylim([ymin, ymax]) | |
|
204 | 218 | |
|
205 | 219 | printLabels(ax, xlabel, ylabel, title) |
|
206 | 220 | |
|
207 | 221 | z = numpy.ma.masked_invalid(z) |
|
208 | cmap=matplotlib.pyplot.get_cmap(colormap) | |
|
209 |
cmap.set_bad(' |
|
|
210 | imesh = ax.pcolormesh(x,y,z.T, vmin=zmin, vmax=zmax, cmap=cmap) | |
|
211 |
cb = |
|
|
222 | cmap = matplotlib.pyplot.get_cmap(colormap) | |
|
223 | cmap.set_bad('black', 1.) | |
|
224 | imesh = ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap) | |
|
225 | cb = matplotlib.pyplot.colorbar(imesh, cax=ax_cb) | |
|
212 | 226 | cb.set_label(cblabel) |
|
213 | 227 | |
|
214 | 228 | # for tl in ax_cb.get_yticklabels(): |
@@ -237,36 +251,30 def createPcolor(ax, x, y, z, xmin, xmax, ymin, ymax, zmin, zmax, | |||
|
237 | 251 | |
|
238 | 252 | if XAxisAsTime: |
|
239 | 253 | |
|
240 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
|
254 | def func(x, pos): return ('%s') % ( | |
|
255 | datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
|
241 | 256 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
242 | 257 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
243 | 258 | |
|
244 | ax.grid(True) | |
|
245 | 259 | matplotlib.pyplot.ion() |
|
246 | 260 | return imesh |
|
247 | 261 | |
|
248 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
|
249 | 262 | |
|
250 | z = numpy.ma.masked_invalid(z) | |
|
251 | ||
|
252 | cmap=matplotlib.pyplot.get_cmap('jet') | |
|
253 | cmap.set_bad('white',1.) | |
|
263 | def pcolor(imesh, z, xlabel='', ylabel='', title=''): | |
|
254 | 264 | |
|
255 | 265 | z = z.T |
|
256 |
ax = imesh. |
|
|
266 | ax = imesh.axes | |
|
257 | 267 | printLabels(ax, xlabel, ylabel, title) |
|
258 | 268 | imesh.set_array(z.ravel()) |
|
259 | ax.grid(True) | |
|
260 | 269 | |
|
261 | 270 | |
|
262 | 271 | def addpcolor(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
263 | 272 | |
|
264 | 273 | printLabels(ax, xlabel, ylabel, title) |
|
265 | z = numpy.ma.masked_invalid(z) | |
|
266 | cmap=matplotlib.pyplot.get_cmap(colormap) | |
|
267 | cmap.set_bad('white',1.) | |
|
268 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=matplotlib.pyplot.get_cmap(colormap)) | |
|
269 | ax.grid(True) | |
|
274 | ||
|
275 | ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, | |
|
276 | cmap=matplotlib.pyplot.get_cmap(colormap)) | |
|
277 | ||
|
270 | 278 | |
|
271 | 279 | def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', colormap='jet'): |
|
272 | 280 | |
@@ -275,19 +283,17 def addpcolorbuffer(ax, x, y, z, zmin, zmax, xlabel='', ylabel='', title='', col | |||
|
275 | 283 | ax.collections.remove(ax.collections[0]) |
|
276 | 284 | |
|
277 | 285 | z = numpy.ma.masked_invalid(z) |
|
278 | ||
|
279 | cmap=matplotlib.pyplot.get_cmap(colormap) | |
|
280 | cmap.set_bad('white',1.) | |
|
281 | 286 | |
|
282 | ax.pcolormesh(x,y,z.T,vmin=zmin,vmax=zmax, cmap=cmap) | |
|
283 | ax.grid(True) | |
|
287 | cmap = matplotlib.pyplot.get_cmap(colormap) | |
|
288 | cmap.set_bad('black', 1.) | |
|
284 | 289 | |
|
290 | ax.pcolormesh(x, y, z.T, vmin=zmin, vmax=zmax, cmap=cmap) | |
|
285 | 291 | |
|
286 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
|
287 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
|
288 | nxticks=4, nyticks=10, | |
|
289 | grid=None): | |
|
290 | 292 | |
|
293 | def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
|
294 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
|
295 | nxticks=4, nyticks=10, | |
|
296 | grid=None): | |
|
291 | 297 | """ |
|
292 | 298 | |
|
293 | 299 | Input: |
@@ -299,11 +305,12 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', tit | |||
|
299 | 305 | lines = ax.plot(x.T, y) |
|
300 | 306 | leg = ax.legend(lines, legendlabels, loc='upper right') |
|
301 | 307 | leg.get_frame().set_alpha(0.5) |
|
302 | ax.set_xlim([xmin,xmax]) | |
|
303 | ax.set_ylim([ymin,ymax]) | |
|
308 | ax.set_xlim([xmin, xmax]) | |
|
309 | ax.set_ylim([ymin, ymax]) | |
|
304 | 310 | printLabels(ax, xlabel, ylabel, title) |
|
305 | 311 | |
|
306 |
xtickspos = numpy.arange(nxticks)* |
|
|
312 | xtickspos = numpy.arange(nxticks) * \ | |
|
313 | int((xmax - xmin) / (nxticks)) + int(xmin) | |
|
307 | 314 | ax.set_xticks(xtickspos) |
|
308 | 315 | |
|
309 | 316 | for tick in ax.get_xticklabels(): |
@@ -340,19 +347,19 def createPmultiline(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', tit | |||
|
340 | 347 | |
|
341 | 348 | def pmultiline(iplot, x, y, xlabel='', ylabel='', title=''): |
|
342 | 349 | |
|
343 |
ax = iplot. |
|
|
350 | ax = iplot.axes | |
|
344 | 351 | |
|
345 | 352 | printLabels(ax, xlabel, ylabel, title) |
|
346 | 353 | |
|
347 | 354 | for i in range(len(ax.lines)): |
|
348 | 355 | line = ax.lines[i] |
|
349 | line.set_data(x[i,:],y) | |
|
356 | line.set_data(x[i, :], y) | |
|
350 | 357 | |
|
351 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
|
352 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
|
353 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", | |
|
354 | grid=None, XAxisAsTime=False): | |
|
355 | 358 | |
|
359 | def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='', title='', legendlabels=None, | |
|
360 | ticksize=9, xtick_visible=True, ytick_visible=True, | |
|
361 | nxticks=4, nyticks=10, marker='.', markersize=10, linestyle="None", | |
|
362 | grid=None, XAxisAsTime=False): | |
|
356 | 363 | """ |
|
357 | 364 | |
|
358 | 365 | Input: |
@@ -369,10 +376,11 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='' | |||
|
369 | 376 | leg = ax.legend(lines, legendlabels, |
|
370 | 377 | loc='upper right', bbox_to_anchor=(1.16, 1), borderaxespad=0) |
|
371 | 378 | |
|
372 |
for label in leg.get_texts(): |
|
|
379 | for label in leg.get_texts(): | |
|
380 | label.set_fontsize(9) | |
|
373 | 381 | |
|
374 | ax.set_xlim([xmin,xmax]) | |
|
375 | ax.set_ylim([ymin,ymax]) | |
|
382 | ax.set_xlim([xmin, xmax]) | |
|
383 | ax.set_ylim([ymin, ymax]) | |
|
376 | 384 | printLabels(ax, xlabel, ylabel, title) |
|
377 | 385 | |
|
378 | 386 | # xtickspos = numpy.arange(nxticks)*int((xmax-xmin)/(nxticks)) + int(xmin) |
@@ -407,7 +415,8 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='' | |||
|
407 | 415 | |
|
408 | 416 | if XAxisAsTime: |
|
409 | 417 | |
|
410 | func = lambda x, pos: ('%s') %(datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
|
418 | def func(x, pos): return ('%s') % ( | |
|
419 | datetime.datetime.utcfromtimestamp(x).strftime("%H:%M:%S")) | |
|
411 | 420 | ax.xaxis.set_major_formatter(FuncFormatter(func)) |
|
412 | 421 | ax.xaxis.set_major_locator(LinearLocator(7)) |
|
413 | 422 | |
@@ -415,30 +424,33 def createPmultilineYAxis(ax, x, y, xmin, xmax, ymin, ymax, xlabel='', ylabel='' | |||
|
415 | 424 | |
|
416 | 425 | return iplot |
|
417 | 426 | |
|
427 | ||
|
418 | 428 | def pmultilineyaxis(iplot, x, y, xlabel='', ylabel='', title=''): |
|
419 | 429 | |
|
420 |
ax = iplot. |
|
|
430 | ax = iplot.axes | |
|
431 | ||
|
421 | 432 | printLabels(ax, xlabel, ylabel, title) |
|
422 | 433 | |
|
423 | 434 | for i in range(len(ax.lines)): |
|
424 | 435 | line = ax.lines[i] |
|
425 | line.set_data(x,y[i,:]) | |
|
436 | line.set_data(x, y[i, :]) | |
|
437 | ||
|
426 | 438 | |
|
427 | 439 | def createPolar(ax, x, y, |
|
428 |
xlabel='', ylabel='', title='', ticksize |
|
|
429 |
|
|
|
430 |
|
|
|
440 | xlabel='', ylabel='', title='', ticksize=9, | |
|
441 | colormap='jet', cblabel='', cbsize="5%", | |
|
442 | XAxisAsTime=False): | |
|
431 | 443 | |
|
432 | 444 | matplotlib.pyplot.ioff() |
|
433 | 445 | |
|
434 | ax.plot(x,y,'bo', markersize=5) | |
|
446 | ax.plot(x, y, 'bo', markersize=5) | |
|
435 | 447 | # ax.set_rmax(90) |
|
436 | ax.set_ylim(0,90) | |
|
437 | ax.set_yticks(numpy.arange(0,90,20)) | |
|
448 | ax.set_ylim(0, 90) | |
|
449 | ax.set_yticks(numpy.arange(0, 90, 20)) | |
|
438 | 450 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center' ,size='11') |
|
439 | 451 | # ax.text(0, 50, ylabel, rotation='vertical', va ='center', ha = 'left' ,size='11') |
|
440 | 452 | # ax.text(100, 100, 'example', ha='left', va='center', rotation='vertical') |
|
441 |
ax.yaxis.labelpad = |
|
|
453 | ax.yaxis.labelpad = 40 | |
|
442 | 454 | printLabels(ax, xlabel, ylabel, title) |
|
443 | 455 | iplot = ax.lines[-1] |
|
444 | 456 | |
@@ -457,18 +469,19 def createPolar(ax, x, y, | |||
|
457 | 469 | |
|
458 | 470 | matplotlib.pyplot.ion() |
|
459 | 471 | |
|
460 | ||
|
461 | 472 | return iplot |
|
462 | 473 | |
|
474 | ||
|
463 | 475 | def polar(iplot, x, y, xlabel='', ylabel='', title=''): |
|
464 | 476 | |
|
465 |
ax = iplot. |
|
|
477 | ax = iplot.axes | |
|
466 | 478 | |
|
467 | 479 | # ax.text(0, -110, ylabel, rotation='vertical', va ='center', ha = 'center',size='11') |
|
468 | 480 | printLabels(ax, xlabel, ylabel, title) |
|
469 | 481 | |
|
470 | 482 | set_linedata(ax, x, y, idline=0) |
|
471 | 483 | |
|
484 | ||
|
472 | 485 | def draw(fig): |
|
473 | 486 | |
|
474 | 487 | if type(fig) == 'int': |
@@ -476,6 +489,7 def draw(fig): | |||
|
476 | 489 | |
|
477 | 490 | fig.canvas.draw() |
|
478 | 491 | |
|
492 | ||
|
479 | 493 | def pause(interval=0.000001): |
|
480 | 494 | |
|
481 | 495 | matplotlib.pyplot.pause(interval) |
@@ -1,4 +1,5 | |||
|
1 |
import os |
|
|
1 | import os | |
|
2 | import sys | |
|
2 | 3 | import glob |
|
3 | 4 | import fnmatch |
|
4 | 5 | import datetime |
@@ -6,11 +7,9 import time | |||
|
6 | 7 | import re |
|
7 | 8 | import h5py |
|
8 | 9 | import numpy |
|
9 | import matplotlib.pyplot as plt | |
|
10 | 10 | |
|
11 | import pylab as plb | |
|
12 | 11 | from scipy.optimize import curve_fit |
|
13 | from scipy import asarray as ar,exp | |
|
12 | from scipy import asarray as ar, exp | |
|
14 | 13 | from scipy import stats |
|
15 | 14 | |
|
16 | 15 | from duplicity.path import Path |
@@ -31,113 +30,130 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |||
|
31 | 30 | from numpy import imag, shape, NaN |
|
32 | 31 | |
|
33 | 32 | |
|
34 | startFp = open('/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc',"rb") | |
|
35 | ||
|
36 | ||
|
37 | FILE_HEADER = numpy.dtype([ #HEADER 1024bytes | |
|
38 | ('Hname',numpy.str_,32), #Original file name | |
|
39 |
('H |
|
|
40 | ('Hoper',numpy.str_,64), #Name of operator who created the file | |
|
41 |
('H |
|
|
42 | ('Hdescr',numpy.str_,256), #Description of measurements | |
|
43 |
('H |
|
|
44 | #Main chunk | |
|
45 | ('Msign','<i4'), #Main chunk signature FZKF or NUIG | |
|
46 | ('MsizeData','<i4'), #Size of data block main chunk | |
|
47 | #Processing DSP parameters | |
|
48 | ('PPARsign','<i4'), #PPAR signature | |
|
49 | ('PPARsize','<i4'), #PPAR size of block | |
|
50 | ('PPARprf','<i4'), #Pulse repetition frequency | |
|
51 |
(' |
|
|
52 | ('PPARsft','<i4'), #FFT length | |
|
53 |
('PPAR |
|
|
54 |
('PPAR |
|
|
55 |
('PPAR |
|
|
56 | ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1. | |
|
57 | #Service DSP parameters | |
|
58 | ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off | |
|
59 |
(' |
|
|
60 | ('SPARaddGain0','<f4'), #OBSOLETE | |
|
61 |
(' |
|
|
62 | ('SPARwnd','<i4'), #Debug only. It normal mode it is 0. | |
|
63 | ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns | |
|
64 | ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal. | |
|
65 | ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE | |
|
66 | ('SPARcal','<i4'), #OBSOLETE | |
|
67 | ('SPARnos','<i4'), #OBSOLETE | |
|
68 |
('SPAR |
|
|
69 |
('SPAR |
|
|
70 |
('SPAR |
|
|
71 |
('SPAR |
|
|
72 | ('SPARosc','<i4'), #flag Oscillosgram mode | |
|
73 |
('SPAR |
|
|
74 | ('SPARcor','<i4'), #OBSOLETE | |
|
75 |
('SPARo |
|
|
76 | ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate | |
|
77 | ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates | |
|
78 | ('SPARcalibPow_M','<f4'), #OBSOLETE | |
|
79 |
('SPAR |
|
|
80 |
('SPARcal |
|
|
81 |
('SPAR |
|
|
82 | ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5 | |
|
83 | ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal | |
|
84 |
('SPAR |
|
|
85 | ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off | |
|
86 | ||
|
87 | ||
|
88 | ||
|
89 | self.Hname= None | |
|
90 | self.Htime= None | |
|
91 | self.Hoper= None | |
|
92 | self.Hplace= None | |
|
93 | self.Hdescr= None | |
|
94 | self.Hdummy= None | |
|
95 | ||
|
96 | self.Msign=None | |
|
97 | self.MsizeData=None | |
|
98 | ||
|
99 | self.PPARsign=None | |
|
100 | self.PPARsize=None | |
|
101 | self.PPARprf=None | |
|
102 | self.PPARpdr=None | |
|
103 | self.PPARsft=None | |
|
104 | self.PPARavc=None | |
|
105 | self.PPARihp=None | |
|
106 | self.PPARchg=None | |
|
107 | self.PPARpol=None | |
|
108 | #Service DSP parameters | |
|
109 | self.SPARatt=None | |
|
110 | self.SPARtx=None | |
|
111 | self.SPARaddGain0=None | |
|
112 | self.SPARaddGain1=None | |
|
113 | self.SPARwnd=None | |
|
114 |
self. |
|
|
115 | self.SPARadd=None | |
|
116 | self.SPARlen=None | |
|
117 |
self. |
|
|
118 |
self. |
|
|
119 |
self. |
|
|
120 |
self. |
|
|
121 |
self. |
|
|
122 |
self. |
|
|
123 |
self. |
|
|
124 |
self. |
|
|
125 |
self. |
|
|
126 | self.SPARofs=None | |
|
127 |
self.SPAR |
|
|
128 |
self.SPAR |
|
|
129 |
self.SPAR |
|
|
130 |
self.SPAR |
|
|
131 |
self.SPAR |
|
|
132 |
self.SPAR |
|
|
133 |
self.SPAR |
|
|
134 |
self.SPAR |
|
|
135 |
self.SPAR |
|
|
136 |
self.SPAR |
|
|
137 | ||
|
138 | ||
|
139 | ||
|
140 | header = numpy.fromfile(fp, FILE_HEADER,1) | |
|
33 | startFp = open( | |
|
34 | '/home/erick/Documents/MIRA35C/20160117/20160117_0000.zspc', "rb") | |
|
35 | ||
|
36 | ||
|
37 | FILE_HEADER = numpy.dtype([ # HEADER 1024bytes | |
|
38 | ('Hname', numpy.str_, 32), # Original file name | |
|
39 | # Date and time when the file was created | |
|
40 | ('Htime', numpy.str_, 32), | |
|
41 | # Name of operator who created the file | |
|
42 | ('Hoper', numpy.str_, 64), | |
|
43 | # Place where the measurements was carried out | |
|
44 | ('Hplace', numpy.str_, 128), | |
|
45 | # Description of measurements | |
|
46 | ('Hdescr', numpy.str_, 256), | |
|
47 | ('Hdummy', numpy.str_, 512), # Reserved space | |
|
48 | # Main chunk | |
|
49 | ('Msign', '<i4'), # Main chunk signature FZKF or NUIG | |
|
50 | ('MsizeData', '<i4'), # Size of data block main chunk | |
|
51 | # Processing DSP parameters | |
|
52 | ('PPARsign', '<i4'), # PPAR signature | |
|
53 | ('PPARsize', '<i4'), # PPAR size of block | |
|
54 | ('PPARprf', '<i4'), # Pulse repetition frequency | |
|
55 | ('PPARpdr', '<i4'), # Pulse duration | |
|
56 | ('PPARsft', '<i4'), # FFT length | |
|
57 | # Number of spectral (in-coherent) averages | |
|
58 | ('PPARavc', '<i4'), | |
|
59 | # Number of lowest range gate for moment estimation | |
|
60 | ('PPARihp', '<i4'), | |
|
61 | # Count for gates for moment estimation | |
|
62 | ('PPARchg', '<i4'), | |
|
63 | # switch on/off polarimetric measurements. Should be 1. | |
|
64 | ('PPARpol', '<i4'), | |
|
65 | # Service DSP parameters | |
|
66 | # STC attenuation on the lowest ranges on/off | |
|
67 | ('SPARatt', '<i4'), | |
|
68 | ('SPARtx', '<i4'), # OBSOLETE | |
|
69 | ('SPARaddGain0', '<f4'), # OBSOLETE | |
|
70 | ('SPARaddGain1', '<f4'), # OBSOLETE | |
|
71 | # Debug only. It normal mode it is 0. | |
|
72 | ('SPARwnd', '<i4'), | |
|
73 | # Delay between sync pulse and tx pulse for phase corr, ns | |
|
74 | ('SPARpos', '<i4'), | |
|
75 | # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal. | |
|
76 | ('SPARadd', '<i4'), | |
|
77 | # Time for measuring txn pulse phase. OBSOLETE | |
|
78 | ('SPARlen', '<i4'), | |
|
79 | ('SPARcal', '<i4'), # OBSOLETE | |
|
80 | ('SPARnos', '<i4'), # OBSOLETE | |
|
81 | ('SPARof0', '<i4'), # detection threshold | |
|
82 | ('SPARof1', '<i4'), # OBSOLETE | |
|
83 | ('SPARswt', '<i4'), # 2nd moment estimation threshold | |
|
84 | ('SPARsum', '<i4'), # OBSOLETE | |
|
85 | ('SPARosc', '<i4'), # flag Oscillosgram mode | |
|
86 | ('SPARtst', '<i4'), # OBSOLETE | |
|
87 | ('SPARcor', '<i4'), # OBSOLETE | |
|
88 | ('SPARofs', '<i4'), # OBSOLETE | |
|
89 | # Hildebrand div noise detection on noise gate | |
|
90 | ('SPARhsn', '<i4'), | |
|
91 | # Hildebrand div noise detection on all gates | |
|
92 | ('SPARhsa', '<f4'), | |
|
93 | ('SPARcalibPow_M', '<f4'), # OBSOLETE | |
|
94 | ('SPARcalibSNR_M', '<f4'), # OBSOLETE | |
|
95 | ('SPARcalibPow_S', '<f4'), # OBSOLETE | |
|
96 | ('SPARcalibSNR_S', '<f4'), # OBSOLETE | |
|
97 | # Lowest range gate for spectra saving Raw_Gate1 >=5 | |
|
98 | ('SPARrawGate1', '<i4'), | |
|
99 | # Number of range gates with atmospheric signal | |
|
100 | ('SPARrawGate2', '<i4'), | |
|
101 | # flag - IQ or spectra saving on/off | |
|
102 | ('SPARraw', '<i4'), | |
|
103 | ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off | |
|
104 | ||
|
105 | ||
|
106 | self.Hname = None | |
|
107 | self.Htime = None | |
|
108 | self.Hoper = None | |
|
109 | self.Hplace = None | |
|
110 | self.Hdescr = None | |
|
111 | self.Hdummy = None | |
|
112 | ||
|
113 | self.Msign = None | |
|
114 | self.MsizeData = None | |
|
115 | ||
|
116 | self.PPARsign = None | |
|
117 | self.PPARsize = None | |
|
118 | self.PPARprf = None | |
|
119 | self.PPARpdr = None | |
|
120 | self.PPARsft = None | |
|
121 | self.PPARavc = None | |
|
122 | self.PPARihp = None | |
|
123 | self.PPARchg = None | |
|
124 | self.PPARpol = None | |
|
125 | # Service DSP parameters | |
|
126 | self.SPARatt = None | |
|
127 | self.SPARtx = None | |
|
128 | self.SPARaddGain0 = None | |
|
129 | self.SPARaddGain1 = None | |
|
130 | self.SPARwnd = None | |
|
131 | self.SPARpos = None | |
|
132 | self.SPARadd = None | |
|
133 | self.SPARlen = None | |
|
134 | self.SPARcal = None | |
|
135 | self.SPARnos = None | |
|
136 | self.SPARof0 = None | |
|
137 | self.SPARof1 = None | |
|
138 | self.SPARswt = None | |
|
139 | self.SPARsum = None | |
|
140 | self.SPARosc = None | |
|
141 | self.SPARtst = None | |
|
142 | self.SPARcor = None | |
|
143 | self.SPARofs = None | |
|
144 | self.SPARhsn = None | |
|
145 | self.SPARhsa = None | |
|
146 | self.SPARcalibPow_M = None | |
|
147 | self.SPARcalibSNR_M = None | |
|
148 | self.SPARcalibPow_S = None | |
|
149 | self.SPARcalibSNR_S = None | |
|
150 | self.SPARrawGate1 = None | |
|
151 | self.SPARrawGate2 = None | |
|
152 | self.SPARraw = None | |
|
153 | self.SPARprc = None | |
|
154 | ||
|
155 | ||
|
156 | header = numpy.fromfile(fp, FILE_HEADER, 1) | |
|
141 | 157 | ''' numpy.fromfile(file, dtype, count, sep='') |
|
142 | 158 | file : file or str |
|
143 | 159 | Open file object or filename. |
@@ -157,95 +173,93 header = numpy.fromfile(fp, FILE_HEADER,1) | |||
|
157 | 173 | |
|
158 | 174 | ''' |
|
159 | 175 | |
|
160 |
Hname= str(header['Hname'][0]) |
|
|
161 | Htime= str(header['Htime'][0]) | |
|
162 | Hoper= str(header['Hoper'][0]) | |
|
163 | Hplace= str(header['Hplace'][0]) | |
|
164 | Hdescr= str(header['Hdescr'][0]) | |
|
165 | Hdummy= str(header['Hdummy'][0]) | |
|
166 | ||
|
167 |
Msign=header['Msign'][0] |
|
|
168 | MsizeData=header['MsizeData'][0] | |
|
169 | ||
|
170 | PPARsign=header['PPARsign'][0] | |
|
171 | PPARsize=header['PPARsize'][0] | |
|
172 | PPARprf=header['PPARprf'][0] | |
|
173 | PPARpdr=header['PPARpdr'][0] | |
|
174 | PPARsft=header['PPARsft'][0] | |
|
175 | PPARavc=header['PPARavc'][0] | |
|
176 | PPARihp=header['PPARihp'][0] | |
|
177 | PPARchg=header['PPARchg'][0] | |
|
178 | PPARpol=header['PPARpol'][0] | |
|
179 | #Service DSP parameters | |
|
180 | SPARatt=header['SPARatt'][0] | |
|
181 | SPARtx=header['SPARtx'][0] | |
|
182 | SPARaddGain0=header['SPARaddGain0'][0] | |
|
183 | SPARaddGain1=header['SPARaddGain1'][0] | |
|
184 | SPARwnd=header['SPARwnd'][0] | |
|
185 | SPARpos=header['SPARpos'][0] | |
|
186 | SPARadd=header['SPARadd'][0] | |
|
187 | SPARlen=header['SPARlen'][0] | |
|
188 | SPARcal=header['SPARcal'][0] | |
|
189 | SPARnos=header['SPARnos'][0] | |
|
190 | SPARof0=header['SPARof0'][0] | |
|
191 | SPARof1=header['SPARof1'][0] | |
|
192 | SPARswt=header['SPARswt'][0] | |
|
193 | SPARsum=header['SPARsum'][0] | |
|
194 | SPARosc=header['SPARosc'][0] | |
|
195 | SPARtst=header['SPARtst'][0] | |
|
196 | SPARcor=header['SPARcor'][0] | |
|
197 | SPARofs=header['SPARofs'][0] | |
|
198 | SPARhsn=header['SPARhsn'][0] | |
|
199 | SPARhsa=header['SPARhsa'][0] | |
|
200 | SPARcalibPow_M=header['SPARcalibPow_M'][0] | |
|
201 | SPARcalibSNR_M=header['SPARcalibSNR_M'][0] | |
|
202 | SPARcalibPow_S=header['SPARcalibPow_S'][0] | |
|
203 | SPARcalibSNR_S=header['SPARcalibSNR_S'][0] | |
|
204 | SPARrawGate1=header['SPARrawGate1'][0] | |
|
205 | SPARrawGate2=header['SPARrawGate2'][0] | |
|
206 | SPARraw=header['SPARraw'][0] | |
|
207 | SPARprc=header['SPARprc'][0] | |
|
208 | ||
|
209 | ||
|
210 | ||
|
211 | SRVI_STRUCTURE = numpy.dtype([ | |
|
212 |
(' |
|
|
213 |
('t |
|
|
214 |
(' |
|
|
215 |
('npw |
|
|
216 |
(' |
|
|
217 |
(' |
|
|
218 |
('p |
|
|
219 |
(' |
|
|
220 |
(' |
|
|
221 |
(' |
|
|
222 |
('grs |
|
|
223 |
(' |
|
|
224 |
('azi |
|
|
225 |
(' |
|
|
226 |
('elv |
|
|
227 |
(' |
|
|
228 |
(' |
|
|
229 |
(' |
|
|
230 |
(' |
|
|
231 |
(' |
|
|
232 | ('RadarConst','<f4'),]) # | |
|
233 | ||
|
234 | JUMP_STRUCTURE = numpy.dtype([ | |
|
235 |
(' |
|
|
236 |
(' |
|
|
237 |
(' |
|
|
238 |
(' |
|
|
239 | ('SizeOfSRVI1','<i4'),])# | |
|
240 | ||
|
241 | ||
|
242 | ||
|
243 | #frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0, | |
|
244 | #cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0, | |
|
245 | #grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0, | |
|
246 | #microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0 | |
|
247 | ||
|
248 | ||
|
176 | Hname = str(header['Hname'][0]) | |
|
177 | Htime = str(header['Htime'][0]) | |
|
178 | Hoper = str(header['Hoper'][0]) | |
|
179 | Hplace = str(header['Hplace'][0]) | |
|
180 | Hdescr = str(header['Hdescr'][0]) | |
|
181 | Hdummy = str(header['Hdummy'][0]) | |
|
182 | ||
|
183 | Msign = header['Msign'][0] | |
|
184 | MsizeData = header['MsizeData'][0] | |
|
185 | ||
|
186 | PPARsign = header['PPARsign'][0] | |
|
187 | PPARsize = header['PPARsize'][0] | |
|
188 | PPARprf = header['PPARprf'][0] | |
|
189 | PPARpdr = header['PPARpdr'][0] | |
|
190 | PPARsft = header['PPARsft'][0] | |
|
191 | PPARavc = header['PPARavc'][0] | |
|
192 | PPARihp = header['PPARihp'][0] | |
|
193 | PPARchg = header['PPARchg'][0] | |
|
194 | PPARpol = header['PPARpol'][0] | |
|
195 | # Service DSP parameters | |
|
196 | SPARatt = header['SPARatt'][0] | |
|
197 | SPARtx = header['SPARtx'][0] | |
|
198 | SPARaddGain0 = header['SPARaddGain0'][0] | |
|
199 | SPARaddGain1 = header['SPARaddGain1'][0] | |
|
200 | SPARwnd = header['SPARwnd'][0] | |
|
201 | SPARpos = header['SPARpos'][0] | |
|
202 | SPARadd = header['SPARadd'][0] | |
|
203 | SPARlen = header['SPARlen'][0] | |
|
204 | SPARcal = header['SPARcal'][0] | |
|
205 | SPARnos = header['SPARnos'][0] | |
|
206 | SPARof0 = header['SPARof0'][0] | |
|
207 | SPARof1 = header['SPARof1'][0] | |
|
208 | SPARswt = header['SPARswt'][0] | |
|
209 | SPARsum = header['SPARsum'][0] | |
|
210 | SPARosc = header['SPARosc'][0] | |
|
211 | SPARtst = header['SPARtst'][0] | |
|
212 | SPARcor = header['SPARcor'][0] | |
|
213 | SPARofs = header['SPARofs'][0] | |
|
214 | SPARhsn = header['SPARhsn'][0] | |
|
215 | SPARhsa = header['SPARhsa'][0] | |
|
216 | SPARcalibPow_M = header['SPARcalibPow_M'][0] | |
|
217 | SPARcalibSNR_M = header['SPARcalibSNR_M'][0] | |
|
218 | SPARcalibPow_S = header['SPARcalibPow_S'][0] | |
|
219 | SPARcalibSNR_S = header['SPARcalibSNR_S'][0] | |
|
220 | SPARrawGate1 = header['SPARrawGate1'][0] | |
|
221 | SPARrawGate2 = header['SPARrawGate2'][0] | |
|
222 | SPARraw = header['SPARraw'][0] | |
|
223 | SPARprc = header['SPARprc'][0] | |
|
224 | ||
|
225 | ||
|
226 | SRVI_STRUCTURE = numpy.dtype([ | |
|
227 | ('frame_cnt', '<u4'), | |
|
228 | ('time_t', '<u4'), # | |
|
229 | ('tpow', '<f4'), # | |
|
230 | ('npw1', '<f4'), # | |
|
231 | ('npw2', '<f4'), # | |
|
232 | ('cpw1', '<f4'), # | |
|
233 | ('pcw2', '<f4'), # | |
|
234 | ('ps_err', '<u4'), # | |
|
235 | ('te_err', '<u4'), # | |
|
236 | ('rc_err', '<u4'), # | |
|
237 | ('grs1', '<u4'), # | |
|
238 | ('grs2', '<u4'), # | |
|
239 | ('azipos', '<f4'), # | |
|
240 | ('azivel', '<f4'), # | |
|
241 | ('elvpos', '<f4'), # | |
|
242 | ('elvvel', '<f4'), # | |
|
243 | ('northAngle', '<f4'), | |
|
244 | ('microsec', '<u4'), # | |
|
245 | ('azisetvel', '<f4'), # | |
|
246 | ('elvsetpos', '<f4'), # | |
|
247 | ('RadarConst', '<f4'), ]) # | |
|
248 | ||
|
249 | JUMP_STRUCTURE = numpy.dtype([ | |
|
250 | ('jump', '<u140'), | |
|
251 | ('SizeOfDataBlock1', numpy.str_, 32), | |
|
252 | ('jump', '<i4'), | |
|
253 | ('DataBlockTitleSRVI1', numpy.str_, 32), | |
|
254 | ('SizeOfSRVI1', '<i4'), ]) | |
|
255 | ||
|
256 | ||
|
257 | # frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0, | |
|
258 | # cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0, | |
|
259 | # grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0, | |
|
260 | # microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0 | |
|
261 | ||
|
262 | ||
|
249 | 263 | frame_cnt = frame_cnt |
|
250 | 264 | dwell = time_t |
|
251 | 265 | tpow = tpow |
@@ -267,23 +281,22 microsec = microsec | |||
|
267 | 281 | azisetvel = azisetvel |
|
268 | 282 | elvsetpos = elvsetpos |
|
269 | 283 | RadarConst5 = RadarConst |
|
270 | ||
|
271 | 284 | |
|
272 | 285 | |
|
273 | #print fp | |
|
274 | #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
275 | #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
276 | #RecCounter=0 | |
|
277 | #Off2StartNxtRec=811248 | |
|
278 | #print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec | |
|
286 | # print fp | |
|
287 | # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
288 | # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
289 | # RecCounter=0 | |
|
290 | # Off2StartNxtRec=811248 | |
|
291 | # print 'OffsetStartHeader ',self.OffsetStartHeader,'RecCounter ', self.RecCounter, 'Off2StartNxtRec ' , self.Off2StartNxtRec | |
|
279 | 292 | #OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec |
|
280 | 293 | #startFp.seek(OffRHeader, os.SEEK_SET) |
|
281 | print 'debe ser 48, RecCounter*811248', self.OffsetStartHeader,self.RecCounter,self.Off2StartNxtRec | |
|
282 | print 'Posicion del bloque: ',OffRHeader | |
|
294 | print 'debe ser 48, RecCounter*811248', self.OffsetStartHeader, self.RecCounter, self.Off2StartNxtRec | |
|
295 | print 'Posicion del bloque: ', OffRHeader | |
|
283 | 296 | |
|
284 | header = numpy.fromfile(startFp,SRVI_STRUCTURE,1) | |
|
297 | header = numpy.fromfile(startFp, SRVI_STRUCTURE, 1) | |
|
285 | 298 | |
|
286 |
self.frame_cnt = header['frame_cnt'][0] |
|
|
299 | self.frame_cnt = header['frame_cnt'][0] | |
|
287 | 300 | self.time_t = header['frame_cnt'][0] # |
|
288 | 301 | self.tpow = header['frame_cnt'][0] # |
|
289 | 302 | self.npw1 = header['frame_cnt'][0] # |
@@ -303,19 +316,16 self.northAngle = header['frame_cnt'][0] # | |||
|
303 | 316 | self.microsec = header['frame_cnt'][0] # |
|
304 | 317 | self.azisetvel = header['frame_cnt'][0] # |
|
305 | 318 | self.elvsetpos = header['frame_cnt'][0] # |
|
306 |
self.RadarConst = header['frame_cnt'][0] # |
|
|
319 | self.RadarConst = header['frame_cnt'][0] # | |
|
307 | 320 | |
|
308 | 321 | |
|
309 | self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz) | |
|
322 | self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz) | |
|
310 | 323 | |
|
311 | self.RHsize = 180+20*self.nChannels | |
|
312 | self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4 | |
|
313 | #print 'Datasize',self.Datasize | |
|
314 | endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec | |
|
324 | self.RHsize = 180 + 20 * self.nChannels | |
|
325 | self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4 | |
|
326 | # print 'Datasize',self.Datasize | |
|
327 | endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec | |
|
315 | 328 | |
|
316 | 329 | print '==============================================' |
|
317 | 330 | |
|
318 | 331 | print '==============================================' |
|
319 | ||
|
320 | ||
|
321 | No newline at end of file |
@@ -8,7 +8,7 from jroIO_voltage import * | |||
|
8 | 8 | from jroIO_spectra import * |
|
9 | 9 | from jroIO_heispectra import * |
|
10 | 10 | from jroIO_usrp import * |
|
11 | ||
|
11 | from jroIO_digitalRF import * | |
|
12 | 12 | from jroIO_kamisr import * |
|
13 | 13 | from jroIO_param import * |
|
14 | 14 | from jroIO_hf import * |
@@ -83,6 +83,7 DATA_STRUCTURE = numpy.dtype([ | |||
|
83 | 83 | ('sea_algorithm', '<u4') |
|
84 | 84 | ]) |
|
85 | 85 | |
|
86 | ||
|
86 | 87 | class BLTRParamReader(JRODataReader, ProcessingUnit): |
|
87 | 88 | ''' |
|
88 | 89 | Boundary Layer and Tropospheric Radar (BLTR) reader, Wind velocities and SNR from *.sswma files |
@@ -92,14 +93,14 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
92 | 93 | |
|
93 | 94 | def __init__(self, **kwargs): |
|
94 | 95 | |
|
95 |
ProcessingUnit.__init__(self |
|
|
96 | ProcessingUnit.__init__(self, **kwargs) | |
|
96 | 97 | |
|
97 |
self.dataOut = Parameters() |
|
|
98 | self.dataOut = Parameters() | |
|
98 | 99 | self.counter_records = 0 |
|
99 | 100 | self.flagNoMoreFiles = 0 |
|
100 |
self.isConfig = False |
|
|
101 | self.isConfig = False | |
|
101 | 102 | self.filename = None |
|
102 | ||
|
103 | ||
|
103 | 104 | def setup(self, |
|
104 | 105 | path=None, |
|
105 | 106 | startDate=None, |
@@ -122,7 +123,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
122 | 123 | if self.path is None: |
|
123 | 124 | raise ValueError, "The path is not valid" |
|
124 | 125 | |
|
125 |
if ext is None: |
|
|
126 | if ext is None: | |
|
126 | 127 | ext = self.ext |
|
127 | 128 | |
|
128 | 129 | self.search_files(self.path, startDate, endDate, ext) |
@@ -130,50 +131,50 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
130 | 131 | self.fileIndex = 0 |
|
131 | 132 | |
|
132 | 133 | if not self.fileList: |
|
133 |
raise |
|
|
134 | raise Warning, "There is no files matching these date in the folder: %s. \n Check 'startDate' and 'endDate' " % ( | |
|
135 | path) | |
|
134 | 136 | |
|
135 | 137 | self.setNextFile() |
|
136 | ||
|
138 | ||
|
137 | 139 | def search_files(self, path, startDate, endDate, ext): |
|
138 | 140 | ''' |
|
139 | 141 | Searching for BLTR rawdata file in path |
|
140 | 142 | Creating a list of file to proces included in [startDate,endDate] |
|
141 | ||
|
143 | ||
|
142 | 144 | Input: |
|
143 | 145 | path - Path to find BLTR rawdata files |
|
144 | 146 | startDate - Select file from this date |
|
145 | 147 | enDate - Select file until this date |
|
146 | 148 | ext - Extension of the file to read |
|
147 |
|
|
|
148 |
|
|
|
149 | ||
|
149 | ''' | |
|
150 | ||
|
150 | 151 | log.success('Searching files in {} '.format(path), 'BLTRParamReader') |
|
151 | 152 | foldercounter = 0 |
|
152 | 153 | fileList0 = glob.glob1(path, "*%s" % ext) |
|
153 | 154 | fileList0.sort() |
|
154 | ||
|
155 | ||
|
155 | 156 | self.fileList = [] |
|
156 | 157 | self.dateFileList = [] |
|
157 | ||
|
158 |
for thisFile in fileList0: |
|
|
158 | ||
|
159 | for thisFile in fileList0: | |
|
159 | 160 | year = thisFile[-14:-10] |
|
160 | 161 | if not isNumber(year): |
|
161 | 162 | continue |
|
162 | ||
|
163 | ||
|
163 | 164 | month = thisFile[-10:-8] |
|
164 | 165 | if not isNumber(month): |
|
165 | 166 | continue |
|
166 | ||
|
167 | ||
|
167 | 168 | day = thisFile[-8:-6] |
|
168 | 169 | if not isNumber(day): |
|
169 |
continue |
|
|
170 | ||
|
170 | continue | |
|
171 | ||
|
171 | 172 | year, month, day = int(year), int(month), int(day) |
|
172 | 173 | dateFile = datetime.date(year, month, day) |
|
173 | ||
|
174 | ||
|
174 | 175 | if (startDate > dateFile) or (endDate < dateFile): |
|
175 | 176 | continue |
|
176 | ||
|
177 | ||
|
177 | 178 | self.fileList.append(thisFile) |
|
178 | 179 | self.dateFileList.append(dateFile) |
|
179 | 180 | |
@@ -192,14 +193,15 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
192 | 193 | filename = os.path.join(self.path, self.fileList[file_id]) |
|
193 | 194 | |
|
194 | 195 | dirname, name = os.path.split(filename) |
|
195 |
|
|
|
196 | # 'peru2' ---> Piura - 'peru1' ---> Huancayo or Porcuya | |
|
197 | self.siteFile = name.split('.')[0] | |
|
196 | 198 | if self.filename is not None: |
|
197 | 199 | self.fp.close() |
|
198 | 200 | self.filename = filename |
|
199 | 201 | self.fp = open(self.filename, 'rb') |
|
200 | 202 | self.header_file = numpy.fromfile(self.fp, FILE_HEADER_STRUCTURE, 1) |
|
201 | 203 | self.nrecords = self.header_file['nrec'][0] |
|
202 |
self.sizeOfFile = os.path.getsize(self.filename) |
|
|
204 | self.sizeOfFile = os.path.getsize(self.filename) | |
|
203 | 205 | self.counter_records = 0 |
|
204 | 206 | self.flagIsNewFile = 0 |
|
205 | 207 | self.fileIndex += 1 |
@@ -238,7 +240,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
238 | 240 | |
|
239 | 241 | pointer = self.fp.tell() |
|
240 | 242 | header_rec = numpy.fromfile(self.fp, REC_HEADER_STRUCTURE, 1) |
|
241 | self.nchannels = header_rec['nchan'][0]/2 | |
|
243 | self.nchannels = header_rec['nchan'][0] / 2 | |
|
242 | 244 | self.kchan = header_rec['nrxs'][0] |
|
243 | 245 | self.nmodes = header_rec['nmodes'][0] |
|
244 | 246 | self.nranges = header_rec['nranges'][0] |
@@ -249,7 +251,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
249 | 251 | self.flagDiscontinuousBlock = 0 |
|
250 | 252 | |
|
251 | 253 | for mode in range(self.nmodes): |
|
252 |
self.readHeader() |
|
|
254 | self.readHeader() | |
|
253 | 255 | data = self.readData() |
|
254 | 256 | self.height[mode] = (data[0] - self.correction) / 1000. |
|
255 | 257 | self.buffer[mode] = data[1] |
@@ -263,7 +265,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
263 | 265 | ''' |
|
264 | 266 | RecordHeader of BLTR rawdata file |
|
265 | 267 | ''' |
|
266 | ||
|
268 | ||
|
267 | 269 | header_structure = numpy.dtype( |
|
268 | 270 | REC_HEADER_STRUCTURE.descr + [ |
|
269 | 271 | ('antenna_coord', 'f4', (2, self.nchannels)), |
@@ -277,7 +279,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
277 | 279 | self.lon = self.header_rec['lon'][0] |
|
278 | 280 | self.delta = self.header_rec['delta_r'][0] |
|
279 | 281 | self.correction = self.header_rec['dmode_rngcorr'][0] |
|
280 |
self.imode = self.header_rec['dmode_index'][0] |
|
|
282 | self.imode = self.header_rec['dmode_index'][0] | |
|
281 | 283 | self.antenna = self.header_rec['antenna_coord'] |
|
282 | 284 | self.rx_gains = self.header_rec['rx_gains'] |
|
283 | 285 | self.time = self.header_rec['time'][0] |
@@ -308,22 +310,23 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
308 | 310 | data = numpy.fromfile(self.fp, data_structure, self.nranges) |
|
309 | 311 | |
|
310 | 312 | height = data['range'] |
|
311 | winds = numpy.array((data['zonal'], data['meridional'], data['vertical'])) | |
|
313 | winds = numpy.array( | |
|
314 | (data['zonal'], data['meridional'], data['vertical'])) | |
|
312 | 315 | snr = data['rx_snr'].T |
|
313 | 316 | |
|
314 |
winds[numpy.where(winds == -9999.)] = numpy.nan |
|
|
317 | winds[numpy.where(winds == -9999.)] = numpy.nan | |
|
315 | 318 | winds[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
316 | 319 | snr[numpy.where(snr == -9999.)] = numpy.nan |
|
317 | 320 | snr[:, numpy.where(data['status'] != self.status_value)] = numpy.nan |
|
318 |
snr = numpy.power(10, snr / 10) |
|
|
319 | ||
|
321 | snr = numpy.power(10, snr / 10) | |
|
322 | ||
|
320 | 323 | return height, winds, snr |
|
321 | 324 | |
|
322 | 325 | def set_output(self): |
|
323 | 326 | ''' |
|
324 | 327 | Storing data from databuffer to dataOut object |
|
325 | 328 | ''' |
|
326 | ||
|
329 | ||
|
327 | 330 | self.dataOut.data_SNR = self.snr |
|
328 | 331 | self.dataOut.height = self.height |
|
329 | 332 | self.dataOut.data = self.buffer |
@@ -333,7 +336,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
333 | 336 | self.dataOut.paramInterval = 157 |
|
334 | 337 | self.dataOut.timezone = self.timezone |
|
335 | 338 | self.dataOut.site = self.siteFile |
|
336 | self.dataOut.nrecords = self.nrecords/self.nmodes | |
|
339 | self.dataOut.nrecords = self.nrecords / self.nmodes | |
|
337 | 340 | self.dataOut.sizeOfFile = self.sizeOfFile |
|
338 | 341 | self.dataOut.lat = self.lat |
|
339 | 342 | self.dataOut.lon = self.lon |
@@ -357,7 +360,7 class BLTRParamReader(JRODataReader, ProcessingUnit): | |||
|
357 | 360 | log.success('No file left to process', 'BLTRParamReader') |
|
358 | 361 | return 0 |
|
359 | 362 | |
|
360 |
if not |
|
|
363 | if not self.readNextBlock(): | |
|
361 | 364 | self.dataOut.flagNoData = True |
|
362 | 365 | return 0 |
|
363 | 366 |
This diff has been collapsed as it changes many lines, (535 lines changed) Show them Hide them | |||
@@ -10,7 +10,8 import time | |||
|
10 | 10 | import numpy |
|
11 | 11 | import fnmatch |
|
12 | 12 | import inspect |
|
13 |
import time |
|
|
13 | import time | |
|
14 | import datetime | |
|
14 | 15 | import traceback |
|
15 | 16 | import zmq |
|
16 | 17 | |
@@ -24,6 +25,7 from schainpy.model.data.jroheaderIO import get_dtype_index, get_numpy_dtype, ge | |||
|
24 | 25 | |
|
25 | 26 | LOCALTIME = True |
|
26 | 27 | |
|
28 | ||
|
27 | 29 | def isNumber(cad): |
|
28 | 30 | """ |
|
29 | 31 | Chequea si el conjunto de caracteres que componen un string puede ser convertidos a un numero. |
@@ -38,11 +40,12 def isNumber(cad): | |||
|
38 | 40 | False : no es un string numerico |
|
39 | 41 | """ |
|
40 | 42 | try: |
|
41 |
float( |
|
|
43 | float(cad) | |
|
42 | 44 | return True |
|
43 | 45 | except: |
|
44 | 46 | return False |
|
45 | 47 | |
|
48 | ||
|
46 | 49 | def isFileInEpoch(filename, startUTSeconds, endUTSeconds): |
|
47 | 50 | """ |
|
48 | 51 | Esta funcion determina si un archivo de datos se encuentra o no dentro del rango de fecha especificado. |
@@ -67,16 +70,16 def isFileInEpoch(filename, startUTSeconds, endUTSeconds): | |||
|
67 | 70 | basicHeaderObj = BasicHeader(LOCALTIME) |
|
68 | 71 | |
|
69 | 72 | try: |
|
70 | fp = open(filename,'rb') | |
|
73 | fp = open(filename, 'rb') | |
|
71 | 74 | except IOError: |
|
72 | print "The file %s can't be opened" %(filename) | |
|
75 | print "The file %s can't be opened" % (filename) | |
|
73 | 76 | return 0 |
|
74 | 77 | |
|
75 | 78 | sts = basicHeaderObj.read(fp) |
|
76 | 79 | fp.close() |
|
77 | 80 | |
|
78 | 81 | if not(sts): |
|
79 | print "Skipping the file %s because it has not a valid header" %(filename) | |
|
82 | print "Skipping the file %s because it has not a valid header" % (filename) | |
|
80 | 83 | return 0 |
|
81 | 84 | |
|
82 | 85 | if not ((startUTSeconds <= basicHeaderObj.utc) and (endUTSeconds > basicHeaderObj.utc)): |
@@ -84,19 +87,18 def isFileInEpoch(filename, startUTSeconds, endUTSeconds): | |||
|
84 | 87 | |
|
85 | 88 | return 1 |
|
86 | 89 | |
|
87 | def isTimeInRange(thisTime, startTime, endTime): | |
|
88 | 90 | |
|
91 | def isTimeInRange(thisTime, startTime, endTime): | |
|
89 | 92 | if endTime >= startTime: |
|
90 | 93 | if (thisTime < startTime) or (thisTime > endTime): |
|
91 | 94 | return 0 |
|
92 | ||
|
93 | 95 | return 1 |
|
94 | 96 | else: |
|
95 | 97 | if (thisTime < startTime) and (thisTime > endTime): |
|
96 | 98 | return 0 |
|
97 | ||
|
98 | 99 | return 1 |
|
99 | 100 | |
|
101 | ||
|
100 | 102 | def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): |
|
101 | 103 | """ |
|
102 | 104 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
@@ -122,11 +124,10 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |||
|
122 | 124 | |
|
123 | 125 | """ |
|
124 | 126 | |
|
125 | ||
|
126 | 127 | try: |
|
127 | fp = open(filename,'rb') | |
|
128 | fp = open(filename, 'rb') | |
|
128 | 129 | except IOError: |
|
129 | print "The file %s can't be opened" %(filename) | |
|
130 | print "The file %s can't be opened" % (filename) | |
|
130 | 131 | return None |
|
131 | 132 | |
|
132 | 133 | firstBasicHeaderObj = BasicHeader(LOCALTIME) |
@@ -139,7 +140,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |||
|
139 | 140 | sts = firstBasicHeaderObj.read(fp) |
|
140 | 141 | |
|
141 | 142 | if not(sts): |
|
142 | print "[Reading] Skipping the file %s because it has not a valid header" %(filename) | |
|
143 | print "[Reading] Skipping the file %s because it has not a valid header" % (filename) | |
|
143 | 144 | return None |
|
144 | 145 | |
|
145 | 146 | if not systemHeaderObj.read(fp): |
@@ -153,10 +154,10 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |||
|
153 | 154 | |
|
154 | 155 | filesize = os.path.getsize(filename) |
|
155 | 156 | |
|
156 | offset = processingHeaderObj.blockSize + 24 #header size | |
|
157 | offset = processingHeaderObj.blockSize + 24 # header size | |
|
157 | 158 | |
|
158 | 159 | if filesize <= offset: |
|
159 | print "[Reading] %s: This file has not enough data" %filename | |
|
160 | print "[Reading] %s: This file has not enough data" % filename | |
|
160 | 161 | return None |
|
161 | 162 | |
|
162 | 163 | fp.seek(-offset, 2) |
@@ -172,7 +173,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |||
|
172 | 173 | thisDate = thisDatetime.date() |
|
173 | 174 | thisTime_first_block = thisDatetime.time() |
|
174 | 175 | |
|
175 | #General case | |
|
176 | # General case | |
|
176 | 177 | # o>>>>>>>>>>>>>><<<<<<<<<<<<<<o |
|
177 | 178 | #-----------o----------------------------o----------- |
|
178 | 179 | # startTime endTime |
@@ -183,8 +184,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |||
|
183 | 184 | |
|
184 | 185 | return thisDatetime |
|
185 | 186 | |
|
186 | #If endTime < startTime then endTime belongs to the next day | |
|
187 | ||
|
187 | # If endTime < startTime then endTime belongs to the next day | |
|
188 | 188 | |
|
189 | 189 | #<<<<<<<<<<<o o>>>>>>>>>>> |
|
190 | 190 | #-----------o----------------------------o----------- |
@@ -201,6 +201,7 def isFileInTimeRange(filename, startDate, endDate, startTime, endTime): | |||
|
201 | 201 | |
|
202 | 202 | return thisDatetime |
|
203 | 203 | |
|
204 | ||
|
204 | 205 | def isFolderInDateRange(folder, startDate=None, endDate=None): |
|
205 | 206 | """ |
|
206 | 207 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
@@ -227,7 +228,7 def isFolderInDateRange(folder, startDate=None, endDate=None): | |||
|
227 | 228 | basename = os.path.basename(folder) |
|
228 | 229 | |
|
229 | 230 | if not isRadarFolder(basename): |
|
230 | print "The folder %s has not the rigth format" %folder | |
|
231 | print "The folder %s has not the rigth format" % folder | |
|
231 | 232 | return 0 |
|
232 | 233 | |
|
233 | 234 | if startDate and endDate: |
@@ -241,6 +242,7 def isFolderInDateRange(folder, startDate=None, endDate=None): | |||
|
241 | 242 | |
|
242 | 243 | return 1 |
|
243 | 244 | |
|
245 | ||
|
244 | 246 | def isFileInDateRange(filename, startDate=None, endDate=None): |
|
245 | 247 | """ |
|
246 | 248 | Retorna 1 si el archivo de datos se encuentra dentro del rango de horas especificado. |
@@ -269,7 +271,7 def isFileInDateRange(filename, startDate=None, endDate=None): | |||
|
269 | 271 | basename = os.path.basename(filename) |
|
270 | 272 | |
|
271 | 273 | if not isRadarFile(basename): |
|
272 | print "The filename %s has not the rigth format" %filename | |
|
274 | print "The filename %s has not the rigth format" % filename | |
|
273 | 275 | return 0 |
|
274 | 276 | |
|
275 | 277 | if startDate and endDate: |
@@ -283,6 +285,7 def isFileInDateRange(filename, startDate=None, endDate=None): | |||
|
283 | 285 | |
|
284 | 286 | return 1 |
|
285 | 287 | |
|
288 | ||
|
286 | 289 | def getFileFromSet(path, ext, set): |
|
287 | 290 | validFilelist = [] |
|
288 | 291 | fileList = os.listdir(path) |
@@ -293,7 +296,7 def getFileFromSet(path, ext, set): | |||
|
293 | 296 | for thisFile in fileList: |
|
294 | 297 | try: |
|
295 | 298 | year = int(thisFile[1:5]) |
|
296 |
doy |
|
|
299 | doy = int(thisFile[5:8]) | |
|
297 | 300 | except: |
|
298 | 301 | continue |
|
299 | 302 | |
@@ -302,21 +305,23 def getFileFromSet(path, ext, set): | |||
|
302 | 305 | |
|
303 | 306 | validFilelist.append(thisFile) |
|
304 | 307 | |
|
305 | myfile = fnmatch.filter(validFilelist,'*%4.4d%3.3d%3.3d*'%(year,doy,set)) | |
|
308 | myfile = fnmatch.filter( | |
|
309 | validFilelist, '*%4.4d%3.3d%3.3d*' % (year, doy, set)) | |
|
306 | 310 | |
|
307 | if len(myfile)!= 0: | |
|
311 | if len(myfile) != 0: | |
|
308 | 312 | return myfile[0] |
|
309 | 313 | else: |
|
310 | filename = '*%4.4d%3.3d%3.3d%s'%(year,doy,set,ext.lower()) | |
|
311 | print 'the filename %s does not exist'%filename | |
|
314 | filename = '*%4.4d%3.3d%3.3d%s' % (year, doy, set, ext.lower()) | |
|
315 | print 'the filename %s does not exist' % filename | |
|
312 | 316 | print '...going to the last file: ' |
|
313 | 317 | |
|
314 | 318 | if validFilelist: |
|
315 |
validFilelist = sorted( |
|
|
319 | validFilelist = sorted(validFilelist, key=str.lower) | |
|
316 | 320 | return validFilelist[-1] |
|
317 | 321 | |
|
318 | 322 | return None |
|
319 | 323 | |
|
324 | ||
|
320 | 325 | def getlastFileFromPath(path, ext): |
|
321 | 326 | """ |
|
322 | 327 | Depura el fileList dejando solo los que cumplan el formato de "PYYYYDDDSSS.ext" |
@@ -354,11 +359,12 def getlastFileFromPath(path, ext): | |||
|
354 | 359 | validFilelist.append(thisFile) |
|
355 | 360 | |
|
356 | 361 | if validFilelist: |
|
357 |
validFilelist = sorted( |
|
|
362 | validFilelist = sorted(validFilelist, key=str.lower) | |
|
358 | 363 | return validFilelist[-1] |
|
359 | 364 | |
|
360 | 365 | return None |
|
361 | 366 | |
|
367 | ||
|
362 | 368 | def checkForRealPath(path, foldercounter, year, doy, set, ext): |
|
363 | 369 | """ |
|
364 | 370 | Por ser Linux Case Sensitive entonces checkForRealPath encuentra el nombre correcto de un path, |
@@ -386,28 +392,32 def checkForRealPath(path, foldercounter, year, doy, set, ext): | |||
|
386 | 392 | find_flag = False |
|
387 | 393 | filename = None |
|
388 | 394 | |
|
389 | prefixDirList = [None,'d','D'] | |
|
390 | if ext.lower() == ".r": #voltage | |
|
391 | prefixFileList = ['d','D'] | |
|
392 | elif ext.lower() == ".pdata": #spectra | |
|
393 | prefixFileList = ['p','P'] | |
|
395 | prefixDirList = [None, 'd', 'D'] | |
|
396 | if ext.lower() == ".r": # voltage | |
|
397 | prefixFileList = ['d', 'D'] | |
|
398 | elif ext.lower() == ".pdata": # spectra | |
|
399 | prefixFileList = ['p', 'P'] | |
|
394 | 400 | else: |
|
395 | 401 | return None, filename |
|
396 | 402 | |
|
397 | #barrido por las combinaciones posibles | |
|
403 | # barrido por las combinaciones posibles | |
|
398 | 404 | for prefixDir in prefixDirList: |
|
399 | 405 | thispath = path |
|
400 | 406 | if prefixDir != None: |
|
401 | #formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
|
407 | # formo el nombre del directorio xYYYYDDD (x=d o x=D) | |
|
402 | 408 | if foldercounter == 0: |
|
403 |
thispath = os.path.join(path, "%s%04d%03d" % |
|
|
409 | thispath = os.path.join(path, "%s%04d%03d" % | |
|
410 | (prefixDir, year, doy)) | |
|
404 | 411 | else: |
|
405 |
thispath = os.path.join(path, "%s%04d%03d_%02d" % ( |
|
|
406 | for prefixFile in prefixFileList: #barrido por las dos combinaciones posibles de "D" | |
|
407 | filename = "%s%04d%03d%03d%s" % ( prefixFile, year, doy, set, ext ) #formo el nombre del file xYYYYDDDSSS.ext | |
|
408 | fullfilename = os.path.join( thispath, filename ) #formo el path completo | |
|
409 | ||
|
410 | if os.path.exists( fullfilename ): #verifico que exista | |
|
412 | thispath = os.path.join(path, "%s%04d%03d_%02d" % ( | |
|
413 | prefixDir, year, doy, foldercounter)) | |
|
414 | for prefixFile in prefixFileList: # barrido por las dos combinaciones posibles de "D" | |
|
415 | # formo el nombre del file xYYYYDDDSSS.ext | |
|
416 | filename = "%s%04d%03d%03d%s" % (prefixFile, year, doy, set, ext) | |
|
417 | fullfilename = os.path.join( | |
|
418 | thispath, filename) # formo el path completo | |
|
419 | ||
|
420 | if os.path.exists(fullfilename): # verifico que exista | |
|
411 | 421 | find_flag = True |
|
412 | 422 | break |
|
413 | 423 | if find_flag: |
@@ -418,6 +428,7 def checkForRealPath(path, foldercounter, year, doy, set, ext): | |||
|
418 | 428 | |
|
419 | 429 | return fullfilename, filename |
|
420 | 430 | |
|
431 | ||
|
421 | 432 | def isRadarFolder(folder): |
|
422 | 433 | try: |
|
423 | 434 | year = int(folder[1:5]) |
@@ -427,15 +438,17 def isRadarFolder(folder): | |||
|
427 | 438 | |
|
428 | 439 | return 1 |
|
429 | 440 | |
|
441 | ||
|
430 | 442 | def isRadarFile(file): |
|
431 |
|
|
|
432 |
|
|
|
433 |
|
|
|
434 |
|
|
|
435 |
|
|
|
436 |
|
|
|
443 | try: | |
|
444 | year = int(file[1:5]) | |
|
445 | doy = int(file[5:8]) | |
|
446 | set = int(file[8:11]) | |
|
447 | except: | |
|
448 | return 0 | |
|
449 | ||
|
450 | return 1 | |
|
437 | 451 | |
|
438 | return 1 | |
|
439 | 452 | |
|
440 | 453 | def getDateFromRadarFile(file): |
|
441 | 454 | try: |
@@ -445,9 +458,10 def getDateFromRadarFile(file): | |||
|
445 | 458 | except: |
|
446 | 459 | return None |
|
447 | 460 | |
|
448 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1) | |
|
461 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1) | |
|
449 | 462 | return thisDate |
|
450 | 463 | |
|
464 | ||
|
451 | 465 | def getDateFromRadarFolder(folder): |
|
452 | 466 | try: |
|
453 | 467 | year = int(folder[1:5]) |
@@ -455,9 +469,10 def getDateFromRadarFolder(folder): | |||
|
455 | 469 | except: |
|
456 | 470 | return None |
|
457 | 471 | |
|
458 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy-1) | |
|
472 | thisDate = datetime.date(year, 1, 1) + datetime.timedelta(doy - 1) | |
|
459 | 473 | return thisDate |
|
460 | 474 | |
|
475 | ||
|
461 | 476 | class JRODataIO: |
|
462 | 477 | |
|
463 | 478 | c = 3E8 |
@@ -540,6 +555,7 class JRODataIO: | |||
|
540 | 555 | def getAllowedArgs(self): |
|
541 | 556 | return inspect.getargspec(self.run).args |
|
542 | 557 | |
|
558 | ||
|
543 | 559 | class JRODataReader(JRODataIO): |
|
544 | 560 | |
|
545 | 561 | online = 0 |
@@ -548,11 +564,11 class JRODataReader(JRODataIO): | |||
|
548 | 564 | |
|
549 | 565 | nReadBlocks = 0 |
|
550 | 566 | |
|
551 |
delay |
|
|
567 | delay = 10 # number of seconds waiting a new file | |
|
552 | 568 | |
|
553 |
nTries |
|
|
569 | nTries = 3 # quantity tries | |
|
554 | 570 | |
|
555 |
nFiles = 3 |
|
|
571 | nFiles = 3 # number of files for searching | |
|
556 | 572 | |
|
557 | 573 | path = None |
|
558 | 574 | |
@@ -572,14 +588,13 class JRODataReader(JRODataIO): | |||
|
572 | 588 | |
|
573 | 589 | txIndex = None |
|
574 | 590 | |
|
575 | #Added-------------------- | |
|
591 | # Added-------------------- | |
|
576 | 592 | |
|
577 | 593 | selBlocksize = None |
|
578 | 594 | |
|
579 | 595 | selBlocktime = None |
|
580 | 596 | |
|
581 | 597 | def __init__(self): |
|
582 | ||
|
583 | 598 | """ |
|
584 | 599 | This class is used to find data files |
|
585 | 600 | |
@@ -590,7 +605,6 class JRODataReader(JRODataIO): | |||
|
590 | 605 | """ |
|
591 | 606 | pass |
|
592 | 607 | |
|
593 | ||
|
594 | 608 | def createObjByDefault(self): |
|
595 | 609 | """ |
|
596 | 610 | |
@@ -605,8 +619,8 class JRODataReader(JRODataIO): | |||
|
605 | 619 | path, |
|
606 | 620 | startDate=None, |
|
607 | 621 | endDate=None, |
|
608 | startTime=datetime.time(0,0,0), | |
|
609 | endTime=datetime.time(23,59,59), | |
|
622 | startTime=datetime.time(0, 0, 0), | |
|
623 | endTime=datetime.time(23, 59, 59), | |
|
610 | 624 | set=None, |
|
611 | 625 | expLabel='', |
|
612 | 626 | ext='.r', |
@@ -619,22 +633,23 class JRODataReader(JRODataIO): | |||
|
619 | 633 | |
|
620 | 634 | pathList = [] |
|
621 | 635 | |
|
622 | dateList, pathList = self.findDatafiles(path, startDate, endDate, expLabel, ext, walk, include_path=True) | |
|
636 | dateList, pathList = self.findDatafiles( | |
|
637 | path, startDate, endDate, expLabel, ext, walk, include_path=True) | |
|
623 | 638 | |
|
624 | 639 | if dateList == []: |
|
625 | 640 | return [], [] |
|
626 | 641 | |
|
627 | 642 | if len(dateList) > 1: |
|
628 | print "[Reading] Data found for date range [%s - %s]: total days = %d" %(startDate, endDate, len(dateList)) | |
|
643 | print "[Reading] Data found for date range [%s - %s]: total days = %d" % (startDate, endDate, len(dateList)) | |
|
629 | 644 | else: |
|
630 | print "[Reading] Data found for date range [%s - %s]: date = %s" %(startDate, endDate, dateList[0]) | |
|
645 | print "[Reading] Data found for date range [%s - %s]: date = %s" % (startDate, endDate, dateList[0]) | |
|
631 | 646 | |
|
632 | 647 | filenameList = [] |
|
633 | 648 | datetimeList = [] |
|
634 | 649 | |
|
635 | 650 | for thisPath in pathList: |
|
636 | 651 | |
|
637 | fileList = glob.glob1(thisPath, "*%s" %ext) | |
|
652 | fileList = glob.glob1(thisPath, "*%s" % ext) | |
|
638 | 653 | fileList.sort() |
|
639 | 654 | |
|
640 | 655 | skippedFileList = [] |
@@ -644,19 +659,21 class JRODataReader(JRODataIO): | |||
|
644 | 659 | if skip == 0: |
|
645 | 660 | skippedFileList = [] |
|
646 | 661 | else: |
|
647 |
skippedFileList = fileList[cursor* |
|
|
662 | skippedFileList = fileList[cursor * | |
|
663 | skip: cursor * skip + skip] | |
|
648 | 664 | |
|
649 | 665 | else: |
|
650 | 666 | skippedFileList = fileList |
|
651 | 667 | |
|
652 | 668 | for file in skippedFileList: |
|
653 | 669 | |
|
654 | filename = os.path.join(thisPath,file) | |
|
670 | filename = os.path.join(thisPath, file) | |
|
655 | 671 | |
|
656 | 672 | if not isFileInDateRange(filename, startDate, endDate): |
|
657 | 673 | continue |
|
658 | 674 | |
|
659 |
thisDatetime = isFileInTimeRange( |
|
|
675 | thisDatetime = isFileInTimeRange( | |
|
676 | filename, startDate, endDate, startTime, endTime) | |
|
660 | 677 | |
|
661 | 678 | if not(thisDatetime): |
|
662 | 679 | continue |
@@ -665,10 +682,10 class JRODataReader(JRODataIO): | |||
|
665 | 682 | datetimeList.append(thisDatetime) |
|
666 | 683 | |
|
667 | 684 | if not(filenameList): |
|
668 | print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" %(startTime, endTime, ext, path) | |
|
685 | print "[Reading] Time range selected invalid [%s - %s]: No *%s files in %s)" % (startTime, endTime, ext, path) | |
|
669 | 686 | return [], [] |
|
670 | 687 | |
|
671 | print "[Reading] %d file(s) was(were) found in time range: %s - %s" %(len(filenameList), startTime, endTime) | |
|
688 | print "[Reading] %d file(s) was(were) found in time range: %s - %s" % (len(filenameList), startTime, endTime) | |
|
672 | 689 | |
|
673 | 690 | |
|
674 | 691 | # for i in range(len(filenameList)): |
@@ -679,8 +696,7 class JRODataReader(JRODataIO): | |||
|
679 | 696 | |
|
680 | 697 | return pathList, filenameList |
|
681 | 698 | |
|
682 |
def __searchFilesOnLine(self, path, expLabel |
|
|
683 | ||
|
699 | def __searchFilesOnLine(self, path, expLabel="", ext=None, walk=True, set=None): | |
|
684 | 700 | """ |
|
685 | 701 | Busca el ultimo archivo de la ultima carpeta (determinada o no por startDateTime) y |
|
686 | 702 | devuelve el archivo encontrado ademas de otros datos. |
@@ -712,9 +728,9 class JRODataReader(JRODataIO): | |||
|
712 | 728 | fullpath = path |
|
713 | 729 | foldercounter = 0 |
|
714 | 730 | else: |
|
715 | #Filtra solo los directorios | |
|
731 | # Filtra solo los directorios | |
|
716 | 732 | for thisPath in os.listdir(path): |
|
717 | if not os.path.isdir(os.path.join(path,thisPath)): | |
|
733 | if not os.path.isdir(os.path.join(path, thisPath)): | |
|
718 | 734 | continue |
|
719 | 735 | if not isRadarFolder(thisPath): |
|
720 | 736 | continue |
@@ -724,14 +740,14 class JRODataReader(JRODataIO): | |||
|
724 | 740 | if not(dirList): |
|
725 | 741 | return None, None, None, None, None, None |
|
726 | 742 | |
|
727 |
dirList = sorted( |
|
|
743 | dirList = sorted(dirList, key=str.lower) | |
|
728 | 744 | |
|
729 | 745 | doypath = dirList[-1] |
|
730 |
foldercounter = int(doypath.split('_')[1]) if len( |
|
|
746 | foldercounter = int(doypath.split('_')[1]) if len( | |
|
747 | doypath.split('_')) > 1 else 0 | |
|
731 | 748 | fullpath = os.path.join(path, doypath, expLabel) |
|
732 | 749 | |
|
733 | ||
|
734 | print "[Reading] %s folder was found: " %(fullpath ) | |
|
750 | print "[Reading] %s folder was found: " % (fullpath) | |
|
735 | 751 | |
|
736 | 752 | if set == None: |
|
737 | 753 | filename = getlastFileFromPath(fullpath, ext) |
@@ -741,14 +757,14 class JRODataReader(JRODataIO): | |||
|
741 | 757 | if not(filename): |
|
742 | 758 | return None, None, None, None, None, None |
|
743 | 759 | |
|
744 | print "[Reading] %s file was found" %(filename) | |
|
760 | print "[Reading] %s file was found" % (filename) | |
|
745 | 761 | |
|
746 | 762 | if not(self.__verifyFile(os.path.join(fullpath, filename))): |
|
747 | 763 | return None, None, None, None, None, None |
|
748 | 764 | |
|
749 |
year = int( |
|
|
750 |
doy |
|
|
751 |
set |
|
|
765 | year = int(filename[1:5]) | |
|
766 | doy = int(filename[5:8]) | |
|
767 | set = int(filename[8:11]) | |
|
752 | 768 | |
|
753 | 769 | return fullpath, foldercounter, filename, year, doy, set |
|
754 | 770 | |
@@ -769,7 +785,7 class JRODataReader(JRODataIO): | |||
|
769 | 785 | continue |
|
770 | 786 | |
|
771 | 787 | fileSize = os.path.getsize(filename) |
|
772 | fp = open(filename,'rb') | |
|
788 | fp = open(filename, 'rb') | |
|
773 | 789 | break |
|
774 | 790 | |
|
775 | 791 | self.flagIsNewFile = 1 |
@@ -813,29 +829,32 class JRODataReader(JRODataIO): | |||
|
813 | 829 | self.set = 0 |
|
814 | 830 | self.foldercounter += 1 |
|
815 | 831 | |
|
816 | #busca el 1er file disponible | |
|
817 | fullfilename, filename = checkForRealPath( self.path, self.foldercounter, self.year, self.doy, self.set, self.ext ) | |
|
832 | # busca el 1er file disponible | |
|
833 | fullfilename, filename = checkForRealPath( | |
|
834 | self.path, self.foldercounter, self.year, self.doy, self.set, self.ext) | |
|
818 | 835 | if fullfilename: |
|
819 | 836 | if self.__verifyFile(fullfilename, False): |
|
820 | 837 | fileOk_flag = True |
|
821 | 838 | |
|
822 | #si no encuentra un file entonces espera y vuelve a buscar | |
|
839 | # si no encuentra un file entonces espera y vuelve a buscar | |
|
823 | 840 | if not(fileOk_flag): |
|
824 |
|
|
|
841 | # busco en los siguientes self.nFiles+1 files posibles | |
|
842 | for nFiles in range(self.nFiles + 1): | |
|
825 | 843 | |
|
826 | if firstTime_flag: #si es la 1era vez entonces hace el for self.nTries veces | |
|
844 | if firstTime_flag: # si es la 1era vez entonces hace el for self.nTries veces | |
|
827 | 845 | tries = self.nTries |
|
828 | 846 | else: |
|
829 | tries = 1 #si no es la 1era vez entonces solo lo hace una vez | |
|
847 | tries = 1 # si no es la 1era vez entonces solo lo hace una vez | |
|
830 | 848 | |
|
831 |
for nTries in range( |
|
|
849 | for nTries in range(tries): | |
|
832 | 850 | if firstTime_flag: |
|
833 |
print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % ( |
|
|
834 |
sleep( |
|
|
851 | print "\t[Reading] Waiting %0.2f sec for the next file: \"%s\" , try %03d ..." % (self.delay, filename, nTries + 1) | |
|
852 | sleep(self.delay) | |
|
835 | 853 | else: |
|
836 | 854 | print "\t[Reading] Searching the next \"%s%04d%03d%03d%s\" file ..." % (self.optchar, self.year, self.doy, self.set, self.ext) |
|
837 | 855 | |
|
838 |
fullfilename, filename = checkForRealPath( |
|
|
856 | fullfilename, filename = checkForRealPath( | |
|
857 | self.path, self.foldercounter, self.year, self.doy, self.set, self.ext) | |
|
839 | 858 | if fullfilename: |
|
840 | 859 | if self.__verifyFile(fullfilename): |
|
841 | 860 | fileOk_flag = True |
@@ -849,16 +868,18 class JRODataReader(JRODataIO): | |||
|
849 | 868 | print "\t[Reading] Skipping the file \"%s\" due to this file doesn't exist" % filename |
|
850 | 869 | self.set += 1 |
|
851 | 870 | |
|
852 |
|
|
|
871 | # si no encuentro el file buscado cambio de carpeta y busco en la siguiente carpeta | |
|
872 | if nFiles == (self.nFiles - 1): | |
|
853 | 873 | self.set = 0 |
|
854 | 874 | self.doy += 1 |
|
855 | 875 | self.foldercounter = 0 |
|
856 | 876 | |
|
857 | 877 | if fileOk_flag: |
|
858 |
self.fileSize = os.path.getsize( |
|
|
878 | self.fileSize = os.path.getsize(fullfilename) | |
|
859 | 879 | self.filename = fullfilename |
|
860 | 880 | self.flagIsNewFile = 1 |
|
861 |
if self.fp != None: |
|
|
881 | if self.fp != None: | |
|
882 | self.fp.close() | |
|
862 | 883 | self.fp = open(fullfilename, 'rb') |
|
863 | 884 | self.flagNoMoreFiles = 0 |
|
864 | 885 | # print '[Reading] Setting the file: %s' % fullfilename |
@@ -908,48 +929,47 class JRODataReader(JRODataIO): | |||
|
908 | 929 | |
|
909 | 930 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
910 | 931 | |
|
911 |
for nTries in range( |
|
|
932 | for nTries in range(self.nTries): | |
|
912 | 933 | |
|
913 | 934 | self.fp.close() |
|
914 |
self.fp = open( |
|
|
915 |
self.fp.seek( |
|
|
935 | self.fp = open(self.filename, 'rb') | |
|
936 | self.fp.seek(currentPointer) | |
|
916 | 937 | |
|
917 |
self.fileSize = os.path.getsize( |
|
|
938 | self.fileSize = os.path.getsize(self.filename) | |
|
918 | 939 | currentSize = self.fileSize - currentPointer |
|
919 | 940 | |
|
920 |
if ( |
|
|
941 | if (currentSize >= neededSize): | |
|
921 | 942 | self.basicHeaderObj.read(self.fp) |
|
922 | 943 | return 1 |
|
923 | 944 | |
|
924 | 945 | if self.fileSize == self.fileSizeByHeader: |
|
925 | # self.flagEoF = True | |
|
946 | # self.flagEoF = True | |
|
926 | 947 | return 0 |
|
927 | 948 | |
|
928 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
|
929 |
sleep( |
|
|
930 | ||
|
949 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1) | |
|
950 | sleep(self.delay) | |
|
931 | 951 | |
|
932 | 952 | return 0 |
|
933 | 953 | |
|
934 | def waitDataBlock(self,pointer_location): | |
|
954 | def waitDataBlock(self, pointer_location): | |
|
935 | 955 | |
|
936 | 956 | currentPointer = pointer_location |
|
937 | 957 | |
|
938 | neededSize = self.processingHeaderObj.blockSize #+ self.basicHeaderSize | |
|
958 | neededSize = self.processingHeaderObj.blockSize # + self.basicHeaderSize | |
|
939 | 959 | |
|
940 |
for nTries in range( |
|
|
960 | for nTries in range(self.nTries): | |
|
941 | 961 | self.fp.close() |
|
942 |
self.fp = open( |
|
|
943 |
self.fp.seek( |
|
|
962 | self.fp = open(self.filename, 'rb') | |
|
963 | self.fp.seek(currentPointer) | |
|
944 | 964 | |
|
945 |
self.fileSize = os.path.getsize( |
|
|
965 | self.fileSize = os.path.getsize(self.filename) | |
|
946 | 966 | currentSize = self.fileSize - currentPointer |
|
947 | 967 | |
|
948 |
if ( |
|
|
968 | if (currentSize >= neededSize): | |
|
949 | 969 | return 1 |
|
950 | 970 | |
|
951 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries+1) | |
|
952 |
sleep( |
|
|
971 | print "[Reading] Waiting %0.2f seconds for the next block, try %03d ..." % (self.delay, nTries + 1) | |
|
972 | sleep(self.delay) | |
|
953 | 973 | |
|
954 | 974 | return 0 |
|
955 | 975 | |
@@ -961,7 +981,7 class JRODataReader(JRODataIO): | |||
|
961 | 981 | csize = self.fileSize - self.fp.tell() |
|
962 | 982 | blocksize = self.processingHeaderObj.blockSize |
|
963 | 983 | |
|
964 | #salta el primer bloque de datos | |
|
984 | # salta el primer bloque de datos | |
|
965 | 985 | if csize > self.processingHeaderObj.blockSize: |
|
966 | 986 | self.fp.seek(self.fp.tell() + blocksize) |
|
967 | 987 | else: |
@@ -971,7 +991,7 class JRODataReader(JRODataIO): | |||
|
971 | 991 | neededsize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
972 | 992 | while True: |
|
973 | 993 | |
|
974 | if self.fp.tell()<self.fileSize: | |
|
994 | if self.fp.tell() < self.fileSize: | |
|
975 | 995 | self.fp.seek(self.fp.tell() + neededsize) |
|
976 | 996 | else: |
|
977 | 997 | self.fp.seek(self.fp.tell() - neededsize) |
@@ -987,12 +1007,12 class JRODataReader(JRODataIO): | |||
|
987 | 1007 | self.__isFirstTimeOnline = 0 |
|
988 | 1008 | |
|
989 | 1009 | def __setNewBlock(self): |
|
990 | #if self.server is None: | |
|
1010 | # if self.server is None: | |
|
991 | 1011 | if self.fp == None: |
|
992 | 1012 | return 0 |
|
993 | 1013 | |
|
994 | 1014 | # if self.online: |
|
995 |
# self.__jumpToLastBlock() |
|
|
1015 | # self.__jumpToLastBlock() | |
|
996 | 1016 | |
|
997 | 1017 | if self.flagIsNewFile: |
|
998 | 1018 | self.lastUTTime = self.basicHeaderObj.utc |
@@ -1003,8 +1023,8 class JRODataReader(JRODataIO): | |||
|
1003 | 1023 | if not(self.setNextFile()): |
|
1004 | 1024 | return 0 |
|
1005 | 1025 | else: |
|
1006 |
return 1 |
|
|
1007 | #if self.server is None: | |
|
1026 | return 1 | |
|
1027 | # if self.server is None: | |
|
1008 | 1028 | currentSize = self.fileSize - self.fp.tell() |
|
1009 | 1029 | neededSize = self.processingHeaderObj.blockSize + self.basicHeaderSize |
|
1010 | 1030 | if (currentSize >= neededSize): |
@@ -1018,11 +1038,11 class JRODataReader(JRODataIO): | |||
|
1018 | 1038 | if self.__waitNewBlock(): |
|
1019 | 1039 | self.lastUTTime = self.basicHeaderObj.utc |
|
1020 | 1040 | return 1 |
|
1021 | #if self.server is None: | |
|
1041 | # if self.server is None: | |
|
1022 | 1042 | if not(self.setNextFile()): |
|
1023 | 1043 | return 0 |
|
1024 | 1044 | |
|
1025 |
deltaTime = self.basicHeaderObj.utc - self.lastUTTime |
|
|
1045 | deltaTime = self.basicHeaderObj.utc - self.lastUTTime | |
|
1026 | 1046 | self.lastUTTime = self.basicHeaderObj.utc |
|
1027 | 1047 | |
|
1028 | 1048 | self.flagDiscontinuousBlock = 0 |
@@ -1034,29 +1054,27 class JRODataReader(JRODataIO): | |||
|
1034 | 1054 | |
|
1035 | 1055 | def readNextBlock(self): |
|
1036 | 1056 | |
|
1037 | #Skip block out of startTime and endTime | |
|
1038 |
while True: |
|
|
1039 |
if not(self.__setNewBlock()): |
|
|
1057 | # Skip block out of startTime and endTime | |
|
1058 | while True: | |
|
1059 | if not(self.__setNewBlock()): | |
|
1040 | 1060 | return 0 |
|
1041 | ||
|
1061 | ||
|
1042 | 1062 | if not(self.readBlock()): |
|
1043 | 1063 | return 0 |
|
1044 | 1064 | |
|
1045 | 1065 | self.getBasicHeader() |
|
1046 | ||
|
1047 | if not isTimeInRange(self.dataOut.datatime.time(), self.startTime, self.endTime): | |
|
1048 | ||
|
1049 | print "[Reading] Block No. %d/%d -> %s [Skipping]" %(self.nReadBlocks, | |
|
1050 | self.processingHeaderObj.dataBlocksPerFile, | |
|
1051 | self.dataOut.datatime.ctime()) | |
|
1066 | if (self.dataOut.datatime < datetime.datetime.combine(self.startDate, self.startTime)) or (self.dataOut.datatime > datetime.datetime.combine(self.endDate, self.endTime)): | |
|
1067 | print "[Reading] Block No. %d/%d -> %s [Skipping]" % (self.nReadBlocks, | |
|
1068 | self.processingHeaderObj.dataBlocksPerFile, | |
|
1069 | self.dataOut.datatime.ctime()) | |
|
1052 | 1070 | continue |
|
1053 | 1071 | |
|
1054 | 1072 | break |
|
1055 | 1073 | |
|
1056 | 1074 | if self.verbose: |
|
1057 | print "[Reading] Block No. %d/%d -> %s" %(self.nReadBlocks, | |
|
1058 | self.processingHeaderObj.dataBlocksPerFile, | |
|
1059 | self.dataOut.datatime.ctime()) | |
|
1075 | print "[Reading] Block No. %d/%d -> %s" % (self.nReadBlocks, | |
|
1076 | self.processingHeaderObj.dataBlocksPerFile, | |
|
1077 | self.dataOut.datatime.ctime()) | |
|
1060 | 1078 | return 1 |
|
1061 | 1079 | |
|
1062 | 1080 | def __readFirstHeader(self): |
@@ -1068,27 +1086,30 class JRODataReader(JRODataIO): | |||
|
1068 | 1086 | |
|
1069 | 1087 | self.firstHeaderSize = self.basicHeaderObj.size |
|
1070 | 1088 | |
|
1071 |
datatype = int(numpy.log2((self.processingHeaderObj.processFlags & |
|
|
1089 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & | |
|
1090 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
|
1072 | 1091 | if datatype == 0: |
|
1073 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
|
1092 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
|
1074 | 1093 | elif datatype == 1: |
|
1075 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
|
1094 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
|
1076 | 1095 | elif datatype == 2: |
|
1077 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
|
1096 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
|
1078 | 1097 | elif datatype == 3: |
|
1079 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
|
1098 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
|
1080 | 1099 | elif datatype == 4: |
|
1081 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
|
1100 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
|
1082 | 1101 | elif datatype == 5: |
|
1083 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
|
1102 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
|
1084 | 1103 | else: |
|
1085 | 1104 | raise ValueError, 'Data type was not defined' |
|
1086 | 1105 | |
|
1087 | 1106 | self.dtype = datatype_str |
|
1088 | 1107 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
1089 |
self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + |
|
|
1090 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
|
1091 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
|
1108 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \ | |
|
1109 | self.firstHeaderSize + self.basicHeaderSize * \ | |
|
1110 | (self.processingHeaderObj.dataBlocksPerFile - 1) | |
|
1111 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) | |
|
1112 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) | |
|
1092 | 1113 | self.getBlockDimension() |
|
1093 | 1114 | |
|
1094 | 1115 | def __verifyFile(self, filename, msgFlag=True): |
@@ -1113,25 +1134,25 class JRODataReader(JRODataIO): | |||
|
1113 | 1134 | radarControllerHeaderObj = RadarControllerHeader() |
|
1114 | 1135 | processingHeaderObj = ProcessingHeader() |
|
1115 | 1136 | |
|
1116 |
if not( |
|
|
1137 | if not(basicHeaderObj.read(fp)): | |
|
1117 | 1138 | fp.close() |
|
1118 | 1139 | return False |
|
1119 | 1140 | |
|
1120 |
if not( |
|
|
1141 | if not(systemHeaderObj.read(fp)): | |
|
1121 | 1142 | fp.close() |
|
1122 | 1143 | return False |
|
1123 | 1144 | |
|
1124 |
if not( |
|
|
1145 | if not(radarControllerHeaderObj.read(fp)): | |
|
1125 | 1146 | fp.close() |
|
1126 | 1147 | return False |
|
1127 | 1148 | |
|
1128 |
if not( |
|
|
1149 | if not(processingHeaderObj.read(fp)): | |
|
1129 | 1150 | fp.close() |
|
1130 | 1151 | return False |
|
1131 | 1152 | |
|
1132 | 1153 | neededSize = processingHeaderObj.blockSize + basicHeaderObj.size |
|
1133 | 1154 | else: |
|
1134 | msg = "[Reading] Skipping the file %s due to it hasn't enough data" %filename | |
|
1155 | msg = "[Reading] Skipping the file %s due to it hasn't enough data" % filename | |
|
1135 | 1156 | |
|
1136 | 1157 | fp.close() |
|
1137 | 1158 | |
@@ -1161,7 +1182,7 class JRODataReader(JRODataIO): | |||
|
1161 | 1182 | if not os.path.isdir(single_path): |
|
1162 | 1183 | continue |
|
1163 | 1184 | |
|
1164 | fileList = glob.glob1(single_path, "*"+ext) | |
|
1185 | fileList = glob.glob1(single_path, "*" + ext) | |
|
1165 | 1186 | |
|
1166 | 1187 | if not fileList: |
|
1167 | 1188 | continue |
@@ -1199,7 +1220,7 class JRODataReader(JRODataIO): | |||
|
1199 | 1220 | |
|
1200 | 1221 | for thisPath in os.listdir(single_path): |
|
1201 | 1222 | |
|
1202 | if not os.path.isdir(os.path.join(single_path,thisPath)): | |
|
1223 | if not os.path.isdir(os.path.join(single_path, thisPath)): | |
|
1203 | 1224 | continue |
|
1204 | 1225 | |
|
1205 | 1226 | if not isRadarFolder(thisPath): |
@@ -1218,7 +1239,7 class JRODataReader(JRODataIO): | |||
|
1218 | 1239 | for thisDir in dirList: |
|
1219 | 1240 | |
|
1220 | 1241 | datapath = os.path.join(single_path, thisDir, expLabel) |
|
1221 | fileList = glob.glob1(datapath, "*"+ext) | |
|
1242 | fileList = glob.glob1(datapath, "*" + ext) | |
|
1222 | 1243 | |
|
1223 | 1244 | if not fileList: |
|
1224 | 1245 | continue |
@@ -1238,10 +1259,10 class JRODataReader(JRODataIO): | |||
|
1238 | 1259 | pattern_path = multi_path[0] |
|
1239 | 1260 | |
|
1240 | 1261 | if path_empty: |
|
1241 | print "[Reading] No *%s files in %s for %s to %s" %(ext, pattern_path, startDate, endDate) | |
|
1262 | print "[Reading] No *%s files in %s for %s to %s" % (ext, pattern_path, startDate, endDate) | |
|
1242 | 1263 | else: |
|
1243 | 1264 | if not dateList: |
|
1244 | print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" %(startDate, endDate, ext, path) | |
|
1265 | print "[Reading] Date range selected invalid [%s - %s]: No *%s files in %s)" % (startDate, endDate, ext, path) | |
|
1245 | 1266 | |
|
1246 | 1267 | if include_path: |
|
1247 | 1268 | return dateList, pathList |
@@ -1249,31 +1270,31 class JRODataReader(JRODataIO): | |||
|
1249 | 1270 | return dateList |
|
1250 | 1271 | |
|
1251 | 1272 | def setup(self, |
|
1252 |
|
|
|
1253 |
|
|
|
1254 |
|
|
|
1255 |
|
|
|
1256 |
|
|
|
1257 |
|
|
|
1258 |
|
|
|
1259 |
|
|
|
1260 |
|
|
|
1261 |
|
|
|
1262 |
|
|
|
1263 |
|
|
|
1264 |
|
|
|
1265 |
|
|
|
1266 |
|
|
|
1267 |
|
|
|
1268 |
|
|
|
1269 |
|
|
|
1270 |
|
|
|
1271 |
|
|
|
1272 |
|
|
|
1273 |
|
|
|
1274 |
|
|
|
1275 |
|
|
|
1276 |
|
|
|
1273 | path=None, | |
|
1274 | startDate=None, | |
|
1275 | endDate=None, | |
|
1276 | startTime=datetime.time(0, 0, 0), | |
|
1277 | endTime=datetime.time(23, 59, 59), | |
|
1278 | set=None, | |
|
1279 | expLabel="", | |
|
1280 | ext=None, | |
|
1281 | online=False, | |
|
1282 | delay=60, | |
|
1283 | walk=True, | |
|
1284 | getblock=False, | |
|
1285 | nTxs=1, | |
|
1286 | realtime=False, | |
|
1287 | blocksize=None, | |
|
1288 | blocktime=None, | |
|
1289 | skip=None, | |
|
1290 | cursor=None, | |
|
1291 | warnings=True, | |
|
1292 | verbose=True, | |
|
1293 | server=None, | |
|
1294 | format=None, | |
|
1295 | oneDDict=None, | |
|
1296 | twoDDict=None, | |
|
1297 | ind2DList=None): | |
|
1277 | 1298 | if server is not None: |
|
1278 | 1299 | if 'tcp://' in server: |
|
1279 | 1300 | address = server |
@@ -1285,7 +1306,7 class JRODataReader(JRODataIO): | |||
|
1285 | 1306 | self.receiver.connect(self.server) |
|
1286 | 1307 | time.sleep(0.5) |
|
1287 | 1308 | print '[Starting] ReceiverData from {}'.format(self.server) |
|
1288 |
else: |
|
|
1309 | else: | |
|
1289 | 1310 | self.server = None |
|
1290 | 1311 | if path == None: |
|
1291 | 1312 | raise ValueError, "[Reading] The path is not valid" |
@@ -1296,32 +1317,33 class JRODataReader(JRODataIO): | |||
|
1296 | 1317 | if online: |
|
1297 | 1318 | print "[Reading] Searching files in online mode..." |
|
1298 | 1319 | |
|
1299 |
for nTries in range( |
|
|
1300 |
fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine( |
|
|
1320 | for nTries in range(self.nTries): | |
|
1321 | fullpath, foldercounter, file, year, doy, set = self.__searchFilesOnLine( | |
|
1322 | path=path, expLabel=expLabel, ext=ext, walk=walk, set=set) | |
|
1301 | 1323 | |
|
1302 | 1324 | if fullpath: |
|
1303 | 1325 | break |
|
1304 | 1326 | |
|
1305 | print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries+1) | |
|
1306 |
sleep( |
|
|
1327 | print '[Reading] Waiting %0.2f sec for an valid file in %s: try %02d ...' % (self.delay, path, nTries + 1) | |
|
1328 | sleep(self.delay) | |
|
1307 | 1329 | |
|
1308 | 1330 | if not(fullpath): |
|
1309 | 1331 | print "[Reading] There 'isn't any valid file in %s" % path |
|
1310 | 1332 | return |
|
1311 | 1333 | |
|
1312 | 1334 | self.year = year |
|
1313 |
self.doy |
|
|
1314 |
self.set |
|
|
1335 | self.doy = doy | |
|
1336 | self.set = set - 1 | |
|
1315 | 1337 | self.path = path |
|
1316 | 1338 | self.foldercounter = foldercounter |
|
1317 | 1339 | last_set = None |
|
1318 | 1340 | else: |
|
1319 | 1341 | print "[Reading] Searching files in offline mode ..." |
|
1320 | 1342 | pathList, filenameList = self.searchFilesOffLine(path, startDate=startDate, endDate=endDate, |
|
1321 | startTime=startTime, endTime=endTime, | |
|
1322 | set=set, expLabel=expLabel, ext=ext, | |
|
1323 | walk=walk, cursor=cursor, | |
|
1324 | skip=skip) | |
|
1343 | startTime=startTime, endTime=endTime, | |
|
1344 | set=set, expLabel=expLabel, ext=ext, | |
|
1345 | walk=walk, cursor=cursor, | |
|
1346 | skip=skip) | |
|
1325 | 1347 | |
|
1326 | 1348 | if not(pathList): |
|
1327 | 1349 | self.fileIndex = -1 |
@@ -1345,8 +1367,9 class JRODataReader(JRODataIO): | |||
|
1345 | 1367 | self.nTxs = nTxs |
|
1346 | 1368 | self.startTime = startTime |
|
1347 | 1369 | self.endTime = endTime |
|
1348 | ||
|
1349 | #Added----------------- | |
|
1370 | self.endDate = endDate | |
|
1371 | self.startDate = startDate | |
|
1372 | # Added----------------- | |
|
1350 | 1373 | self.selBlocksize = blocksize |
|
1351 | 1374 | self.selBlocktime = blocktime |
|
1352 | 1375 | |
@@ -1355,10 +1378,10 class JRODataReader(JRODataIO): | |||
|
1355 | 1378 | self.warnings = warnings |
|
1356 | 1379 | |
|
1357 | 1380 | if not(self.setNextFile()): |
|
1358 | if (startDate!=None) and (endDate!=None): | |
|
1359 | print "[Reading] No files in range: %s - %s" %(datetime.datetime.combine(startDate,startTime).ctime(), datetime.datetime.combine(endDate,endTime).ctime()) | |
|
1381 | if (startDate != None) and (endDate != None): | |
|
1382 | print "[Reading] No files in range: %s - %s" % (datetime.datetime.combine(startDate, startTime).ctime(), datetime.datetime.combine(endDate, endTime).ctime()) | |
|
1360 | 1383 | elif startDate != None: |
|
1361 | print "[Reading] No files in range: %s" %(datetime.datetime.combine(startDate,startTime).ctime()) | |
|
1384 | print "[Reading] No files in range: %s" % (datetime.datetime.combine(startDate, startTime).ctime()) | |
|
1362 | 1385 | else: |
|
1363 | 1386 | print "[Reading] No files" |
|
1364 | 1387 | |
@@ -1370,12 +1393,14 class JRODataReader(JRODataIO): | |||
|
1370 | 1393 | # self.getBasicHeader() |
|
1371 | 1394 | |
|
1372 | 1395 | if last_set != None: |
|
1373 | self.dataOut.last_block = last_set * self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock | |
|
1396 | self.dataOut.last_block = last_set * \ | |
|
1397 | self.processingHeaderObj.dataBlocksPerFile + self.basicHeaderObj.dataBlock | |
|
1374 | 1398 | return |
|
1375 | 1399 | |
|
1376 | 1400 | def getBasicHeader(self): |
|
1377 | 1401 | |
|
1378 |
self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond/ |
|
|
1402 | self.dataOut.utctime = self.basicHeaderObj.utc + self.basicHeaderObj.miliSecond / \ | |
|
1403 | 1000. + self.profileIndex * self.radarControllerHeaderObj.ippSeconds | |
|
1379 | 1404 | |
|
1380 | 1405 | self.dataOut.flagDiscontinuousBlock = self.flagDiscontinuousBlock |
|
1381 | 1406 | |
@@ -1387,11 +1412,10 class JRODataReader(JRODataIO): | |||
|
1387 | 1412 | |
|
1388 | 1413 | self.dataOut.useLocalTime = self.basicHeaderObj.useLocalTime |
|
1389 | 1414 | |
|
1390 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
|
1415 | self.dataOut.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |
|
1391 | 1416 | |
|
1392 | 1417 | # self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs |
|
1393 | 1418 | |
|
1394 | ||
|
1395 | 1419 | def getFirstHeader(self): |
|
1396 | 1420 | |
|
1397 | 1421 | raise NotImplementedError |
@@ -1414,11 +1438,11 class JRODataReader(JRODataIO): | |||
|
1414 | 1438 | |
|
1415 | 1439 | def printReadBlocks(self): |
|
1416 | 1440 | |
|
1417 | print "[Reading] Number of read blocks per file %04d" %self.nReadBlocks | |
|
1441 | print "[Reading] Number of read blocks per file %04d" % self.nReadBlocks | |
|
1418 | 1442 | |
|
1419 | 1443 | def printTotalBlocks(self): |
|
1420 | 1444 | |
|
1421 | print "[Reading] Number of read blocks %04d" %self.nTotalBlocks | |
|
1445 | print "[Reading] Number of read blocks %04d" % self.nTotalBlocks | |
|
1422 | 1446 | |
|
1423 | 1447 | def printNumberOfBlock(self): |
|
1424 | 1448 | 'SPAM!' |
@@ -1441,31 +1465,31 class JRODataReader(JRODataIO): | |||
|
1441 | 1465 | self.__printInfo = False |
|
1442 | 1466 | |
|
1443 | 1467 | def run(self, |
|
1444 |
|
|
|
1445 |
|
|
|
1446 |
|
|
|
1447 |
|
|
|
1448 |
|
|
|
1449 |
|
|
|
1450 |
|
|
|
1451 |
|
|
|
1452 |
|
|
|
1453 |
|
|
|
1454 |
|
|
|
1455 |
|
|
|
1456 |
|
|
|
1457 |
|
|
|
1458 |
|
|
|
1459 |
|
|
|
1460 |
|
|
|
1461 |
|
|
|
1462 |
|
|
|
1463 |
|
|
|
1464 |
|
|
|
1465 |
|
|
|
1466 |
|
|
|
1467 |
|
|
|
1468 |
|
|
|
1468 | path=None, | |
|
1469 | startDate=None, | |
|
1470 | endDate=None, | |
|
1471 | startTime=datetime.time(0, 0, 0), | |
|
1472 | endTime=datetime.time(23, 59, 59), | |
|
1473 | set=None, | |
|
1474 | expLabel="", | |
|
1475 | ext=None, | |
|
1476 | online=False, | |
|
1477 | delay=60, | |
|
1478 | walk=True, | |
|
1479 | getblock=False, | |
|
1480 | nTxs=1, | |
|
1481 | realtime=False, | |
|
1482 | blocksize=None, | |
|
1483 | blocktime=None, | |
|
1484 | skip=None, | |
|
1485 | cursor=None, | |
|
1486 | warnings=True, | |
|
1487 | server=None, | |
|
1488 | verbose=True, | |
|
1489 | format=None, | |
|
1490 | oneDDict=None, | |
|
1491 | twoDDict=None, | |
|
1492 | ind2DList=None, **kwargs): | |
|
1469 | 1493 | |
|
1470 | 1494 | if not(self.isConfig): |
|
1471 | 1495 | self.setup(path=path, |
@@ -1496,9 +1520,10 class JRODataReader(JRODataIO): | |||
|
1496 | 1520 | self.isConfig = True |
|
1497 | 1521 | if server is None: |
|
1498 | 1522 | self.getData() |
|
1499 |
else: |
|
|
1523 | else: | |
|
1500 | 1524 | self.getFromServer() |
|
1501 | 1525 | |
|
1526 | ||
|
1502 | 1527 | class JRODataWriter(JRODataIO): |
|
1503 | 1528 | |
|
1504 | 1529 | """ |
@@ -1523,23 +1548,18 class JRODataWriter(JRODataIO): | |||
|
1523 | 1548 | def __init__(self, dataOut=None): |
|
1524 | 1549 | raise NotImplementedError |
|
1525 | 1550 | |
|
1526 | ||
|
1527 | 1551 | def hasAllDataInBuffer(self): |
|
1528 | 1552 | raise NotImplementedError |
|
1529 | 1553 | |
|
1530 | ||
|
1531 | 1554 | def setBlockDimension(self): |
|
1532 | 1555 | raise NotImplementedError |
|
1533 | 1556 | |
|
1534 | ||
|
1535 | 1557 | def writeBlock(self): |
|
1536 | 1558 | raise NotImplementedError |
|
1537 | 1559 | |
|
1538 | ||
|
1539 | 1560 | def putData(self): |
|
1540 | 1561 | raise NotImplementedError |
|
1541 | 1562 | |
|
1542 | ||
|
1543 | 1563 | def getProcessFlags(self): |
|
1544 | 1564 | |
|
1545 | 1565 | processFlags = 0 |
@@ -1575,12 +1595,12 class JRODataWriter(JRODataIO): | |||
|
1575 | 1595 | |
|
1576 | 1596 | def setBasicHeader(self): |
|
1577 | 1597 | |
|
1578 | self.basicHeaderObj.size = self.basicHeaderSize #bytes | |
|
1598 | self.basicHeaderObj.size = self.basicHeaderSize # bytes | |
|
1579 | 1599 | self.basicHeaderObj.version = self.versionFile |
|
1580 | 1600 | self.basicHeaderObj.dataBlock = self.nTotalBlocks |
|
1581 | 1601 | |
|
1582 | 1602 | utc = numpy.floor(self.dataOut.utctime) |
|
1583 |
milisecond |
|
|
1603 | milisecond = (self.dataOut.utctime - utc) * 1000.0 | |
|
1584 | 1604 | |
|
1585 | 1605 | self.basicHeaderObj.utc = utc |
|
1586 | 1606 | self.basicHeaderObj.miliSecond = milisecond |
@@ -1618,7 +1638,8 class JRODataWriter(JRODataIO): | |||
|
1618 | 1638 | |
|
1619 | 1639 | # CALCULAR PARAMETROS |
|
1620 | 1640 | |
|
1621 |
sizeLongHeader = self.systemHeaderObj.size + |
|
|
1641 | sizeLongHeader = self.systemHeaderObj.size + \ | |
|
1642 | self.radarControllerHeaderObj.size + self.processingHeaderObj.size | |
|
1622 | 1643 | self.basicHeaderObj.size = self.basicHeaderSize + sizeLongHeader |
|
1623 | 1644 | |
|
1624 | 1645 | self.basicHeaderObj.write(self.fp) |
@@ -1644,12 +1665,11 class JRODataWriter(JRODataIO): | |||
|
1644 | 1665 | self.basicHeaderObj.write(self.fp) |
|
1645 | 1666 | return 1 |
|
1646 | 1667 | |
|
1647 |
if not( |
|
|
1668 | if not(self.setNextFile()): | |
|
1648 | 1669 | return 0 |
|
1649 | 1670 | |
|
1650 | 1671 | return 1 |
|
1651 | 1672 | |
|
1652 | ||
|
1653 | 1673 | def writeNextBlock(self): |
|
1654 | 1674 | """ |
|
1655 | 1675 | Selecciona el bloque siguiente de datos y los escribe en un file |
@@ -1658,13 +1678,13 class JRODataWriter(JRODataIO): | |||
|
1658 | 1678 | 0 : Si no hizo pudo escribir el bloque de datos |
|
1659 | 1679 | 1 : Si no pudo escribir el bloque de datos |
|
1660 | 1680 | """ |
|
1661 |
if not( |
|
|
1681 | if not(self.__setNewBlock()): | |
|
1662 | 1682 | return 0 |
|
1663 | 1683 | |
|
1664 | 1684 | self.writeBlock() |
|
1665 | 1685 | |
|
1666 | print "[Writing] Block No. %d/%d" %(self.blockIndex, | |
|
1667 | self.processingHeaderObj.dataBlocksPerFile) | |
|
1686 | print "[Writing] Block No. %d/%d" % (self.blockIndex, | |
|
1687 | self.processingHeaderObj.dataBlocksPerFile) | |
|
1668 | 1688 | |
|
1669 | 1689 | return 1 |
|
1670 | 1690 | |
@@ -1689,46 +1709,48 class JRODataWriter(JRODataIO): | |||
|
1689 | 1709 | if self.fp != None: |
|
1690 | 1710 | self.fp.close() |
|
1691 | 1711 | |
|
1692 |
timeTuple = time.localtime( |
|
|
1693 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year,timeTuple.tm_yday) | |
|
1712 | timeTuple = time.localtime(self.dataOut.utctime) | |
|
1713 | subfolder = 'd%4.4d%3.3d' % (timeTuple.tm_year, timeTuple.tm_yday) | |
|
1694 | 1714 | |
|
1695 |
fullpath = os.path.join( |
|
|
1715 | fullpath = os.path.join(path, subfolder) | |
|
1696 | 1716 | setFile = self.setFile |
|
1697 | 1717 | |
|
1698 |
if not( |
|
|
1718 | if not(os.path.exists(fullpath)): | |
|
1699 | 1719 | os.mkdir(fullpath) |
|
1700 | setFile = -1 #inicializo mi contador de seteo | |
|
1720 | setFile = -1 # inicializo mi contador de seteo | |
|
1701 | 1721 | else: |
|
1702 |
filesList = os.listdir( |
|
|
1703 |
if len( |
|
|
1704 |
filesList = sorted( |
|
|
1722 | filesList = os.listdir(fullpath) | |
|
1723 | if len(filesList) > 0: | |
|
1724 | filesList = sorted(filesList, key=str.lower) | |
|
1705 | 1725 | filen = filesList[-1] |
|
1706 | 1726 | # el filename debera tener el siguiente formato |
|
1707 | 1727 | # 0 1234 567 89A BCDE (hex) |
|
1708 | 1728 | # x YYYY DDD SSS .ext |
|
1709 |
if isNumber( |
|
|
1710 |
|
|
|
1729 | if isNumber(filen[8:11]): | |
|
1730 | # inicializo mi contador de seteo al seteo del ultimo file | |
|
1731 | setFile = int(filen[8:11]) | |
|
1711 | 1732 | else: |
|
1712 | 1733 | setFile = -1 |
|
1713 | 1734 | else: |
|
1714 | setFile = -1 #inicializo mi contador de seteo | |
|
1735 | setFile = -1 # inicializo mi contador de seteo | |
|
1715 | 1736 | |
|
1716 | 1737 | setFile += 1 |
|
1717 | 1738 | |
|
1718 | #If this is a new day it resets some values | |
|
1739 | # If this is a new day it resets some values | |
|
1719 | 1740 | if self.dataOut.datatime.date() > self.fileDate: |
|
1720 | 1741 | setFile = 0 |
|
1721 | 1742 | self.nTotalBlocks = 0 |
|
1722 | 1743 | |
|
1723 | filen = '%s%4.4d%3.3d%3.3d%s' % (self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext ) | |
|
1744 | filen = '%s%4.4d%3.3d%3.3d%s' % ( | |
|
1745 | self.optchar, timeTuple.tm_year, timeTuple.tm_yday, setFile, ext) | |
|
1724 | 1746 | |
|
1725 |
filename = os.path.join( |
|
|
1747 | filename = os.path.join(path, subfolder, filen) | |
|
1726 | 1748 | |
|
1727 |
fp = open( |
|
|
1749 | fp = open(filename, 'wb') | |
|
1728 | 1750 | |
|
1729 | 1751 | self.blockIndex = 0 |
|
1730 | 1752 | |
|
1731 | #guardando atributos | |
|
1753 | # guardando atributos | |
|
1732 | 1754 | self.filename = filename |
|
1733 | 1755 | self.subfolder = subfolder |
|
1734 | 1756 | self.fp = fp |
@@ -1738,7 +1760,7 class JRODataWriter(JRODataIO): | |||
|
1738 | 1760 | |
|
1739 | 1761 | self.setFirstHeader() |
|
1740 | 1762 | |
|
1741 | print '[Writing] Opening file: %s'%self.filename | |
|
1763 | print '[Writing] Opening file: %s' % self.filename | |
|
1742 | 1764 | |
|
1743 | 1765 | self.__writeFirstHeader() |
|
1744 | 1766 | |
@@ -1783,7 +1805,7 class JRODataWriter(JRODataIO): | |||
|
1783 | 1805 | |
|
1784 | 1806 | self.dataOut = dataOut |
|
1785 | 1807 | self.fileDate = self.dataOut.datatime.date() |
|
1786 | #By default | |
|
1808 | # By default | |
|
1787 | 1809 | self.dtype = self.dataOut.dtype |
|
1788 | 1810 | |
|
1789 | 1811 | if datatype is not None: |
@@ -1801,7 +1823,8 class JRODataWriter(JRODataIO): | |||
|
1801 | 1823 | |
|
1802 | 1824 | if not(self.isConfig): |
|
1803 | 1825 | |
|
1804 |
self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, |
|
|
1826 | self.setup(dataOut, path, blocksPerFile, profilesPerBlock=profilesPerBlock, | |
|
1827 | set=set, ext=ext, datatype=datatype, **kwargs) | |
|
1805 | 1828 | self.isConfig = True |
|
1806 | 1829 | |
|
1807 | 1830 | self.putData() |
This diff has been collapsed as it changes many lines, (1270 lines changed) Show them Hide them | |||
@@ -1,4 +1,5 | |||
|
1 |
import os |
|
|
1 | import os | |
|
2 | import sys | |
|
2 | 3 | import glob |
|
3 | 4 | import fnmatch |
|
4 | 5 | import datetime |
@@ -6,7 +7,6 import time | |||
|
6 | 7 | import re |
|
7 | 8 | import h5py |
|
8 | 9 | import numpy |
|
9 | import matplotlib.pyplot as plt | |
|
10 | 10 | |
|
11 | 11 | import pylab as plb |
|
12 | 12 | from scipy.optimize import curve_fit |
@@ -33,73 +33,71 from jroIO_base import JRODataReader | |||
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | class Header(object): |
|
36 | ||
|
36 | ||
|
37 | 37 | def __init__(self): |
|
38 | 38 | raise NotImplementedError |
|
39 | ||
|
40 | ||
|
39 | ||
|
41 | 40 | def read(self): |
|
42 | ||
|
41 | ||
|
43 | 42 | raise NotImplementedError |
|
44 | ||
|
43 | ||
|
45 | 44 | def write(self): |
|
46 | ||
|
45 | ||
|
47 | 46 | raise NotImplementedError |
|
48 | ||
|
47 | ||
|
49 | 48 | def printInfo(self): |
|
50 | ||
|
51 | message = "#"*50 + "\n" | |
|
49 | ||
|
50 | message = "#" * 50 + "\n" | |
|
52 | 51 | message += self.__class__.__name__.upper() + "\n" |
|
53 | message += "#"*50 + "\n" | |
|
54 | ||
|
52 | message += "#" * 50 + "\n" | |
|
53 | ||
|
55 | 54 | keyList = self.__dict__.keys() |
|
56 | 55 | keyList.sort() |
|
57 | ||
|
56 | ||
|
58 | 57 | for key in keyList: |
|
59 | message += "%s = %s" %(key, self.__dict__[key]) + "\n" | |
|
60 | ||
|
58 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" | |
|
59 | ||
|
61 | 60 | if "size" not in keyList: |
|
62 | 61 | attr = getattr(self, "size") |
|
63 | ||
|
64 | if attr: | |
|
65 | message += "%s = %s" %("size", attr) + "\n" | |
|
66 | ||
|
67 | #print message | |
|
68 | 62 | |
|
63 | if attr: | |
|
64 | message += "%s = %s" % ("size", attr) + "\n" | |
|
69 | 65 | |
|
66 | # print message | |
|
70 | 67 | |
|
71 | 68 | |
|
69 | FILE_STRUCTURE = numpy.dtype([ # HEADER 48bytes | |
|
70 | ('FileMgcNumber', '<u4'), # 0x23020100 | |
|
71 | # No Of FDT data records in this file (0 or more) | |
|
72 | ('nFDTdataRecors', '<u4'), | |
|
73 | ('OffsetStartHeader', '<u4'), | |
|
74 | ('RadarUnitId', '<u4'), | |
|
75 | ('SiteName', numpy.str_, 32), # Null terminated | |
|
76 | ]) | |
|
72 | 77 | |
|
73 | FILE_STRUCTURE = numpy.dtype([ #HEADER 48bytes | |
|
74 | ('FileMgcNumber','<u4'), #0x23020100 | |
|
75 | ('nFDTdataRecors','<u4'), #No Of FDT data records in this file (0 or more) | |
|
76 | ('OffsetStartHeader','<u4'), | |
|
77 | ('RadarUnitId','<u4'), | |
|
78 | ('SiteName',numpy.str_,32), #Null terminated | |
|
79 | ]) | |
|
80 | 78 | |
|
81 | 79 | class FileHeaderBLTR(Header): |
|
82 | ||
|
80 | ||
|
83 | 81 | def __init__(self): |
|
84 | ||
|
85 |
self.FileMgcNumber= 0 |
|
|
86 |
|
|
|
87 |
self. |
|
|
88 |
self. |
|
|
89 |
self. |
|
|
82 | ||
|
83 | self.FileMgcNumber = 0 # 0x23020100 | |
|
84 | # No Of FDT data records in this file (0 or more) | |
|
85 | self.nFDTdataRecors = 0 | |
|
86 | self.RadarUnitId = 0 | |
|
87 | self.OffsetStartHeader = 0 | |
|
88 | self.SiteName = "" | |
|
90 | 89 | self.size = 48 |
|
91 | ||
|
90 | ||
|
92 | 91 | def FHread(self, fp): |
|
93 | #try: | |
|
94 | startFp = open(fp,"rb") | |
|
95 | ||
|
96 | header = numpy.fromfile(startFp, FILE_STRUCTURE,1) | |
|
97 | ||
|
92 | # try: | |
|
93 | startFp = open(fp, "rb") | |
|
94 | ||
|
95 | header = numpy.fromfile(startFp, FILE_STRUCTURE, 1) | |
|
96 | ||
|
98 | 97 | print ' ' |
|
99 | 98 | print 'puntero file header', startFp.tell() |
|
100 | 99 | print ' ' |
|
101 | ||
|
102 | ||
|
100 | ||
|
103 | 101 | ''' numpy.fromfile(file, dtype, count, sep='') |
|
104 | 102 | file : file or str |
|
105 | 103 | Open file object or filename. |
@@ -119,32 +117,28 class FileHeaderBLTR(Header): | |||
|
119 | 117 | |
|
120 | 118 | ''' |
|
121 | 119 | |
|
120 | self.FileMgcNumber = hex(header['FileMgcNumber'][0]) | |
|
121 | # No Of FDT data records in this file (0 or more) | |
|
122 | self.nFDTdataRecors = int(header['nFDTdataRecors'][0]) | |
|
123 | self.RadarUnitId = int(header['RadarUnitId'][0]) | |
|
124 | self.OffsetStartHeader = int(header['OffsetStartHeader'][0]) | |
|
125 | self.SiteName = str(header['SiteName'][0]) | |
|
126 | ||
|
127 | # print 'Numero de bloques', self.nFDTdataRecors | |
|
122 | 128 | |
|
123 | ||
|
124 | self.FileMgcNumber= hex(header['FileMgcNumber'][0]) | |
|
125 | self.nFDTdataRecors=int(header['nFDTdataRecors'][0]) #No Of FDT data records in this file (0 or more) | |
|
126 | self.RadarUnitId= int(header['RadarUnitId'][0]) | |
|
127 | self.OffsetStartHeader= int(header['OffsetStartHeader'][0]) | |
|
128 | self.SiteName= str(header['SiteName'][0]) | |
|
129 | ||
|
130 | #print 'Numero de bloques', self.nFDTdataRecors | |
|
131 | ||
|
132 | ||
|
133 | if self.size <48: | |
|
129 | if self.size < 48: | |
|
134 | 130 | return 0 |
|
135 | ||
|
131 | ||
|
136 | 132 | return 1 |
|
137 | ||
|
138 | ||
|
133 | ||
|
139 | 134 | def write(self, fp): |
|
140 | ||
|
135 | ||
|
141 | 136 | headerTuple = (self.FileMgcNumber, |
|
142 | 137 | self.nFDTdataRecors, |
|
143 | 138 | self.RadarUnitId, |
|
144 | 139 | self.SiteName, |
|
145 | 140 | self.size) |
|
146 | ||
|
147 | ||
|
141 | ||
|
148 | 142 | header = numpy.array(headerTuple, FILE_STRUCTURE) |
|
149 | 143 | # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) |
|
150 | 144 | header.tofile(fp) |
@@ -162,272 +156,308 class FileHeaderBLTR(Header): | |||
|
162 | 156 | first converting it to the closest Python type, and then using "format" % item. |
|
163 | 157 | |
|
164 | 158 | ''' |
|
165 | ||
|
166 | return 1 | |
|
167 | 159 | |
|
160 | return 1 | |
|
168 | 161 | |
|
169 | 162 | |
|
163 | RECORD_STRUCTURE = numpy.dtype([ # RECORD HEADER 180+20N bytes | |
|
164 | ('RecMgcNumber', '<u4'), # 0x23030001 | |
|
165 | ('RecCounter', '<u4'), # Record counter(0,1, ...) | |
|
166 | # Offset to start of next record form start of this record | |
|
167 | ('Off2StartNxtRec', '<u4'), | |
|
168 | # Offset to start of data from start of this record | |
|
169 | ('Off2StartData', '<u4'), | |
|
170 | # Epoch time stamp of start of acquisition (seconds) | |
|
171 | ('nUtime', '<i4'), | |
|
172 | # Millisecond component of time stamp (0,...,999) | |
|
173 | ('nMilisec', '<u4'), | |
|
174 | # Experiment tag name (null terminated) | |
|
175 | ('ExpTagName', numpy.str_, 32), | |
|
176 | # Experiment comment (null terminated) | |
|
177 | ('ExpComment', numpy.str_, 32), | |
|
178 | # Site latitude (from GPS) in degrees (positive implies North) | |
|
179 | ('SiteLatDegrees', '<f4'), | |
|
180 | # Site longitude (from GPS) in degrees (positive implies East) | |
|
181 | ('SiteLongDegrees', '<f4'), | |
|
182 | # RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE) | |
|
183 | ('RTCgpsStatus', '<u4'), | |
|
184 | ('TransmitFrec', '<u4'), # Transmit frequency (Hz) | |
|
185 | ('ReceiveFrec', '<u4'), # Receive frequency | |
|
186 | # First local oscillator frequency (Hz) | |
|
187 | ('FirstOsciFrec', '<u4'), | |
|
188 | # (0="O", 1="E", 2="linear 1", 3="linear2") | |
|
189 | ('Polarisation', '<u4'), | |
|
190 | # Receiver filter settings (0,1,2,3) | |
|
191 | ('ReceiverFiltSett', '<u4'), | |
|
192 | # Number of modes in use (1 or 2) | |
|
193 | ('nModesInUse', '<u4'), | |
|
194 | # Dual Mode index number for these data (0 or 1) | |
|
195 | ('DualModeIndex', '<u4'), | |
|
196 | # Dual Mode range correction for these data (m) | |
|
197 | ('DualModeRange', '<u4'), | |
|
198 | # Number of digital channels acquired (2*N) | |
|
199 | ('nDigChannels', '<u4'), | |
|
200 | # Sampling resolution (meters) | |
|
201 | ('SampResolution', '<u4'), | |
|
202 | # Number of range gates sampled | |
|
203 | ('nHeights', '<u4'), | |
|
204 | # Start range of sampling (meters) | |
|
205 | ('StartRangeSamp', '<u4'), | |
|
206 | ('PRFhz', '<u4'), # PRF (Hz) | |
|
207 | ('nCohInt', '<u4'), # Integrations | |
|
208 | # Number of data points transformed | |
|
209 | ('nProfiles', '<u4'), | |
|
210 | # Number of receive beams stored in file (1 or N) | |
|
211 | ('nChannels', '<u4'), | |
|
212 | ('nIncohInt', '<u4'), # Number of spectral averages | |
|
213 | # FFT windowing index (0 = no window) | |
|
214 | ('FFTwindowingInd', '<u4'), | |
|
215 | # Beam steer angle (azimuth) in degrees (clockwise from true North) | |
|
216 | ('BeamAngleAzim', '<f4'), | |
|
217 | # Beam steer angle (zenith) in degrees (0=> vertical) | |
|
218 | ('BeamAngleZen', '<f4'), | |
|
219 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
220 | ('AntennaCoord0', '<f4'), | |
|
221 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
222 | ('AntennaAngl0', '<f4'), | |
|
223 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
224 | ('AntennaCoord1', '<f4'), | |
|
225 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
226 | ('AntennaAngl1', '<f4'), | |
|
227 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
228 | ('AntennaCoord2', '<f4'), | |
|
229 | # Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
230 | ('AntennaAngl2', '<f4'), | |
|
231 | # Receiver phase calibration (degrees) - N values | |
|
232 | ('RecPhaseCalibr0', '<f4'), | |
|
233 | # Receiver phase calibration (degrees) - N values | |
|
234 | ('RecPhaseCalibr1', '<f4'), | |
|
235 | # Receiver phase calibration (degrees) - N values | |
|
236 | ('RecPhaseCalibr2', '<f4'), | |
|
237 | # Receiver amplitude calibration (ratio relative to receiver one) - N values | |
|
238 | ('RecAmpCalibr0', '<f4'), | |
|
239 | # Receiver amplitude calibration (ratio relative to receiver one) - N values | |
|
240 | ('RecAmpCalibr1', '<f4'), | |
|
241 | # Receiver amplitude calibration (ratio relative to receiver one) - N values | |
|
242 | ('RecAmpCalibr2', '<f4'), | |
|
243 | # Receiver gains in dB - N values | |
|
244 | ('ReceiverGaindB0', '<i4'), | |
|
245 | # Receiver gains in dB - N values | |
|
246 | ('ReceiverGaindB1', '<i4'), | |
|
247 | # Receiver gains in dB - N values | |
|
248 | ('ReceiverGaindB2', '<i4'), | |
|
249 | ]) | |
|
170 | 250 | |
|
171 | 251 | |
|
172 | RECORD_STRUCTURE = numpy.dtype([ #RECORD HEADER 180+20N bytes | |
|
173 | ('RecMgcNumber','<u4'), #0x23030001 | |
|
174 | ('RecCounter','<u4'), #Record counter(0,1, ...) | |
|
175 | ('Off2StartNxtRec','<u4'), #Offset to start of next record form start of this record | |
|
176 | ('Off2StartData','<u4'), #Offset to start of data from start of this record | |
|
177 | ('nUtime','<i4'), #Epoch time stamp of start of acquisition (seconds) | |
|
178 | ('nMilisec','<u4'), #Millisecond component of time stamp (0,...,999) | |
|
179 | ('ExpTagName',numpy.str_,32), #Experiment tag name (null terminated) | |
|
180 | ('ExpComment',numpy.str_,32), #Experiment comment (null terminated) | |
|
181 | ('SiteLatDegrees','<f4'), #Site latitude (from GPS) in degrees (positive implies North) | |
|
182 | ('SiteLongDegrees','<f4'), #Site longitude (from GPS) in degrees (positive implies East) | |
|
183 | ('RTCgpsStatus','<u4'), #RTC GPS engine status (0=SEEK, 1=LOCK, 2=NOT FITTED, 3=UNAVAILABLE) | |
|
184 | ('TransmitFrec','<u4'), #Transmit frequency (Hz) | |
|
185 | ('ReceiveFrec','<u4'), #Receive frequency | |
|
186 | ('FirstOsciFrec','<u4'), #First local oscillator frequency (Hz) | |
|
187 | ('Polarisation','<u4'), #(0="O", 1="E", 2="linear 1", 3="linear2") | |
|
188 | ('ReceiverFiltSett','<u4'), #Receiver filter settings (0,1,2,3) | |
|
189 | ('nModesInUse','<u4'), #Number of modes in use (1 or 2) | |
|
190 | ('DualModeIndex','<u4'), #Dual Mode index number for these data (0 or 1) | |
|
191 | ('DualModeRange','<u4'), #Dual Mode range correction for these data (m) | |
|
192 | ('nDigChannels','<u4'), #Number of digital channels acquired (2*N) | |
|
193 | ('SampResolution','<u4'), #Sampling resolution (meters) | |
|
194 | ('nHeights','<u4'), #Number of range gates sampled | |
|
195 | ('StartRangeSamp','<u4'), #Start range of sampling (meters) | |
|
196 | ('PRFhz','<u4'), #PRF (Hz) | |
|
197 | ('nCohInt','<u4'), #Integrations | |
|
198 | ('nProfiles','<u4'), #Number of data points transformed | |
|
199 | ('nChannels','<u4'), #Number of receive beams stored in file (1 or N) | |
|
200 | ('nIncohInt','<u4'), #Number of spectral averages | |
|
201 | ('FFTwindowingInd','<u4'), #FFT windowing index (0 = no window) | |
|
202 | ('BeamAngleAzim','<f4'), #Beam steer angle (azimuth) in degrees (clockwise from true North) | |
|
203 | ('BeamAngleZen','<f4'), #Beam steer angle (zenith) in degrees (0=> vertical) | |
|
204 | ('AntennaCoord0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
205 | ('AntennaAngl0','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
206 | ('AntennaCoord1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
207 | ('AntennaAngl1','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
208 | ('AntennaCoord2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
209 | ('AntennaAngl2','<f4'), #Antenna coordinates (Range(meters), Bearing(degrees)) - N pairs | |
|
210 | ('RecPhaseCalibr0','<f4'), #Receiver phase calibration (degrees) - N values | |
|
211 | ('RecPhaseCalibr1','<f4'), #Receiver phase calibration (degrees) - N values | |
|
212 | ('RecPhaseCalibr2','<f4'), #Receiver phase calibration (degrees) - N values | |
|
213 | ('RecAmpCalibr0','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values | |
|
214 | ('RecAmpCalibr1','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values | |
|
215 | ('RecAmpCalibr2','<f4'), #Receiver amplitude calibration (ratio relative to receiver one) - N values | |
|
216 | ('ReceiverGaindB0','<i4'), #Receiver gains in dB - N values | |
|
217 | ('ReceiverGaindB1','<i4'), #Receiver gains in dB - N values | |
|
218 | ('ReceiverGaindB2','<i4'), #Receiver gains in dB - N values | |
|
219 | ]) | |
|
252 | class RecordHeaderBLTR(Header): | |
|
220 | 253 | |
|
254 | def __init__(self, RecMgcNumber=None, RecCounter=0, Off2StartNxtRec=811248, | |
|
255 | nUtime=0, nMilisec=0, ExpTagName=None, | |
|
256 | ExpComment=None, SiteLatDegrees=0, SiteLongDegrees=0, | |
|
257 | RTCgpsStatus=0, TransmitFrec=0, ReceiveFrec=0, | |
|
258 | FirstOsciFrec=0, Polarisation=0, ReceiverFiltSett=0, | |
|
259 | nModesInUse=0, DualModeIndex=0, DualModeRange=0, | |
|
260 | nDigChannels=0, SampResolution=0, nHeights=0, | |
|
261 | StartRangeSamp=0, PRFhz=0, nCohInt=0, | |
|
262 | nProfiles=0, nChannels=0, nIncohInt=0, | |
|
263 | FFTwindowingInd=0, BeamAngleAzim=0, BeamAngleZen=0, | |
|
264 | AntennaCoord0=0, AntennaCoord1=0, AntennaCoord2=0, | |
|
265 | RecPhaseCalibr0=0, RecPhaseCalibr1=0, RecPhaseCalibr2=0, | |
|
266 | RecAmpCalibr0=0, RecAmpCalibr1=0, RecAmpCalibr2=0, | |
|
267 | AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0, | |
|
268 | ReceiverGaindB0=0, ReceiverGaindB1=0, ReceiverGaindB2=0, Off2StartData=0, OffsetStartHeader=0): | |
|
221 | 269 | |
|
222 | class RecordHeaderBLTR(Header): | |
|
223 | ||
|
224 | def __init__(self, RecMgcNumber=None, RecCounter= 0, Off2StartNxtRec= 811248, | |
|
225 | nUtime= 0, nMilisec= 0, ExpTagName= None, | |
|
226 | ExpComment=None, SiteLatDegrees=0, SiteLongDegrees= 0, | |
|
227 | RTCgpsStatus= 0, TransmitFrec= 0, ReceiveFrec= 0, | |
|
228 | FirstOsciFrec= 0, Polarisation= 0, ReceiverFiltSett= 0, | |
|
229 | nModesInUse= 0, DualModeIndex= 0, DualModeRange= 0, | |
|
230 | nDigChannels= 0, SampResolution= 0, nHeights= 0, | |
|
231 | StartRangeSamp= 0, PRFhz= 0, nCohInt= 0, | |
|
232 | nProfiles= 0, nChannels= 0, nIncohInt= 0, | |
|
233 | FFTwindowingInd= 0, BeamAngleAzim= 0, BeamAngleZen= 0, | |
|
234 | AntennaCoord0= 0, AntennaCoord1= 0, AntennaCoord2= 0, | |
|
235 | RecPhaseCalibr0= 0, RecPhaseCalibr1= 0, RecPhaseCalibr2= 0, | |
|
236 | RecAmpCalibr0= 0, RecAmpCalibr1= 0, RecAmpCalibr2= 0, | |
|
237 | AntennaAngl0=0, AntennaAngl1=0, AntennaAngl2=0, | |
|
238 | ReceiverGaindB0= 0, ReceiverGaindB1= 0, ReceiverGaindB2= 0, Off2StartData=0, OffsetStartHeader=0): | |
|
239 | ||
|
240 | self.RecMgcNumber = RecMgcNumber #0x23030001 | |
|
241 | self.RecCounter = RecCounter | |
|
242 | self.Off2StartNxtRec = Off2StartNxtRec | |
|
270 | self.RecMgcNumber = RecMgcNumber # 0x23030001 | |
|
271 | self.RecCounter = RecCounter | |
|
272 | self.Off2StartNxtRec = Off2StartNxtRec | |
|
243 | 273 | self.Off2StartData = Off2StartData |
|
244 |
self.nUtime = nUtime |
|
|
245 |
self.nMilisec = nMilisec |
|
|
246 |
self.ExpTagName = ExpTagName |
|
|
247 |
self.ExpComment = ExpComment |
|
|
248 |
self.SiteLatDegrees = SiteLatDegrees |
|
|
249 |
self.SiteLongDegrees = SiteLongDegrees |
|
|
250 |
self.RTCgpsStatus = RTCgpsStatus |
|
|
251 |
self.TransmitFrec = TransmitFrec |
|
|
252 |
self.ReceiveFrec = ReceiveFrec |
|
|
253 |
self.FirstOsciFrec = FirstOsciFrec |
|
|
254 |
self.Polarisation = Polarisation |
|
|
255 |
self.ReceiverFiltSett = ReceiverFiltSett |
|
|
256 |
self.nModesInUse = nModesInUse |
|
|
257 |
self.DualModeIndex = DualModeIndex |
|
|
258 |
self.DualModeRange = DualModeRange |
|
|
274 | self.nUtime = nUtime | |
|
275 | self.nMilisec = nMilisec | |
|
276 | self.ExpTagName = ExpTagName | |
|
277 | self.ExpComment = ExpComment | |
|
278 | self.SiteLatDegrees = SiteLatDegrees | |
|
279 | self.SiteLongDegrees = SiteLongDegrees | |
|
280 | self.RTCgpsStatus = RTCgpsStatus | |
|
281 | self.TransmitFrec = TransmitFrec | |
|
282 | self.ReceiveFrec = ReceiveFrec | |
|
283 | self.FirstOsciFrec = FirstOsciFrec | |
|
284 | self.Polarisation = Polarisation | |
|
285 | self.ReceiverFiltSett = ReceiverFiltSett | |
|
286 | self.nModesInUse = nModesInUse | |
|
287 | self.DualModeIndex = DualModeIndex | |
|
288 | self.DualModeRange = DualModeRange | |
|
259 | 289 | self.nDigChannels = nDigChannels |
|
260 |
self.SampResolution = SampResolution |
|
|
261 |
self.nHeights = nHeights |
|
|
262 |
self.StartRangeSamp = StartRangeSamp |
|
|
263 |
self.PRFhz = PRFhz |
|
|
264 |
self.nCohInt = nCohInt |
|
|
265 |
self.nProfiles = nProfiles |
|
|
266 |
self.nChannels = nChannels |
|
|
267 |
self.nIncohInt = nIncohInt |
|
|
268 |
self.FFTwindowingInd = FFTwindowingInd |
|
|
269 |
self.BeamAngleAzim = BeamAngleAzim |
|
|
270 |
self.BeamAngleZen = BeamAngleZen |
|
|
290 | self.SampResolution = SampResolution | |
|
291 | self.nHeights = nHeights | |
|
292 | self.StartRangeSamp = StartRangeSamp | |
|
293 | self.PRFhz = PRFhz | |
|
294 | self.nCohInt = nCohInt | |
|
295 | self.nProfiles = nProfiles | |
|
296 | self.nChannels = nChannels | |
|
297 | self.nIncohInt = nIncohInt | |
|
298 | self.FFTwindowingInd = FFTwindowingInd | |
|
299 | self.BeamAngleAzim = BeamAngleAzim | |
|
300 | self.BeamAngleZen = BeamAngleZen | |
|
271 | 301 | self.AntennaCoord0 = AntennaCoord0 |
|
272 | 302 | self.AntennaAngl0 = AntennaAngl0 |
|
273 | 303 | self.AntennaAngl1 = AntennaAngl1 |
|
274 | 304 | self.AntennaAngl2 = AntennaAngl2 |
|
275 | 305 | self.AntennaCoord1 = AntennaCoord1 |
|
276 |
self.AntennaCoord2 = AntennaCoord2 |
|
|
306 | self.AntennaCoord2 = AntennaCoord2 | |
|
277 | 307 | self.RecPhaseCalibr0 = RecPhaseCalibr0 |
|
278 | 308 | self.RecPhaseCalibr1 = RecPhaseCalibr1 |
|
279 |
self.RecPhaseCalibr2 = RecPhaseCalibr2 |
|
|
309 | self.RecPhaseCalibr2 = RecPhaseCalibr2 | |
|
280 | 310 | self.RecAmpCalibr0 = RecAmpCalibr0 |
|
281 | 311 | self.RecAmpCalibr1 = RecAmpCalibr1 |
|
282 |
self.RecAmpCalibr2 = RecAmpCalibr2 |
|
|
312 | self.RecAmpCalibr2 = RecAmpCalibr2 | |
|
283 | 313 | self.ReceiverGaindB0 = ReceiverGaindB0 |
|
284 | 314 | self.ReceiverGaindB1 = ReceiverGaindB1 |
|
285 |
self.ReceiverGaindB2 = ReceiverGaindB2 |
|
|
286 |
self.OffsetStartHeader = |
|
|
287 | ||
|
288 | ||
|
289 | ||
|
315 | self.ReceiverGaindB2 = ReceiverGaindB2 | |
|
316 | self.OffsetStartHeader = 48 | |
|
317 | ||
|
290 | 318 | def RHread(self, fp): |
|
291 | #print fp | |
|
292 | #startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
293 |
|
|
|
294 | #RecCounter=0 | |
|
295 | #Off2StartNxtRec=811248 | |
|
296 | OffRHeader= self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec | |
|
319 | # print fp | |
|
320 | # startFp = open('/home/erick/Documents/Data/huancayo.20161019.22.fdt',"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
321 | # The method tell() returns the current position of the file read/write pointer within the file. | |
|
322 | startFp = open(fp, "rb") | |
|
323 | # RecCounter=0 | |
|
324 | # Off2StartNxtRec=811248 | |
|
325 | OffRHeader = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec | |
|
297 | 326 | print ' ' |
|
298 | 327 | print 'puntero Record Header', startFp.tell() |
|
299 | 328 | print ' ' |
|
300 | ||
|
301 | ||
|
329 | ||
|
302 | 330 | startFp.seek(OffRHeader, os.SEEK_SET) |
|
303 | ||
|
331 | ||
|
304 | 332 | print ' ' |
|
305 | 333 | print 'puntero Record Header con seek', startFp.tell() |
|
306 | 334 | print ' ' |
|
307 | ||
|
308 | #print 'Posicion del bloque: ',OffRHeader | |
|
309 | ||
|
310 | header = numpy.fromfile(startFp,RECORD_STRUCTURE,1) | |
|
311 | ||
|
335 | ||
|
336 | # print 'Posicion del bloque: ',OffRHeader | |
|
337 | ||
|
338 | header = numpy.fromfile(startFp, RECORD_STRUCTURE, 1) | |
|
339 | ||
|
312 | 340 | print ' ' |
|
313 | 341 | print 'puntero Record Header con seek', startFp.tell() |
|
314 | 342 | print ' ' |
|
315 | ||
|
343 | ||
|
316 | 344 | print ' ' |
|
317 | 345 | # |
|
318 | #print 'puntero Record Header despues de seek', header.tell() | |
|
346 | # print 'puntero Record Header despues de seek', header.tell() | |
|
319 | 347 | print ' ' |
|
320 | ||
|
321 |
self.RecMgcNumber = hex(header['RecMgcNumber'][0]) |
|
|
322 |
self.RecCounter = int(header['RecCounter'][0]) |
|
|
323 |
self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0]) |
|
|
324 |
self.Off2StartData = int(header['Off2StartData'][0]) |
|
|
325 |
self.nUtime = header['nUtime'][0] |
|
|
326 |
self.nMilisec = header['nMilisec'][0] |
|
|
327 |
self.ExpTagName = str(header['ExpTagName'][0]) |
|
|
328 |
self.ExpComment = str(header['ExpComment'][0]) |
|
|
329 |
self.SiteLatDegrees = header['SiteLatDegrees'][0] |
|
|
330 |
self.SiteLongDegrees = header['SiteLongDegrees'][0] |
|
|
331 |
self.RTCgpsStatus = header['RTCgpsStatus'][0] |
|
|
332 |
self.TransmitFrec = header['TransmitFrec'][0] |
|
|
333 |
self.ReceiveFrec = header['ReceiveFrec'][0] |
|
|
334 |
self.FirstOsciFrec = header['FirstOsciFrec'][0] |
|
|
335 |
self.Polarisation = header['Polarisation'][0] |
|
|
336 |
self.ReceiverFiltSett = header['ReceiverFiltSett'][0] |
|
|
337 |
self.nModesInUse = header['nModesInUse'][0] |
|
|
338 |
self.DualModeIndex = header['DualModeIndex'][0] |
|
|
339 |
self.DualModeRange = header['DualModeRange'][0] |
|
|
348 | ||
|
349 | self.RecMgcNumber = hex(header['RecMgcNumber'][0]) # 0x23030001 | |
|
350 | self.RecCounter = int(header['RecCounter'][0]) | |
|
351 | self.Off2StartNxtRec = int(header['Off2StartNxtRec'][0]) | |
|
352 | self.Off2StartData = int(header['Off2StartData'][0]) | |
|
353 | self.nUtime = header['nUtime'][0] | |
|
354 | self.nMilisec = header['nMilisec'][0] | |
|
355 | self.ExpTagName = str(header['ExpTagName'][0]) | |
|
356 | self.ExpComment = str(header['ExpComment'][0]) | |
|
357 | self.SiteLatDegrees = header['SiteLatDegrees'][0] | |
|
358 | self.SiteLongDegrees = header['SiteLongDegrees'][0] | |
|
359 | self.RTCgpsStatus = header['RTCgpsStatus'][0] | |
|
360 | self.TransmitFrec = header['TransmitFrec'][0] | |
|
361 | self.ReceiveFrec = header['ReceiveFrec'][0] | |
|
362 | self.FirstOsciFrec = header['FirstOsciFrec'][0] | |
|
363 | self.Polarisation = header['Polarisation'][0] | |
|
364 | self.ReceiverFiltSett = header['ReceiverFiltSett'][0] | |
|
365 | self.nModesInUse = header['nModesInUse'][0] | |
|
366 | self.DualModeIndex = header['DualModeIndex'][0] | |
|
367 | self.DualModeRange = header['DualModeRange'][0] | |
|
340 | 368 | self.nDigChannels = header['nDigChannels'][0] |
|
341 |
self.SampResolution = header['SampResolution'][0] |
|
|
342 |
self.nHeights = header['nHeights'][0] |
|
|
343 |
self.StartRangeSamp = header['StartRangeSamp'][0] |
|
|
344 |
self.PRFhz = header['PRFhz'][0] |
|
|
345 |
self.nCohInt = header['nCohInt'][0] |
|
|
346 |
self.nProfiles = header['nProfiles'][0] |
|
|
347 |
self.nChannels = header['nChannels'][0] |
|
|
348 |
self.nIncohInt = header['nIncohInt'][0] |
|
|
349 |
self.FFTwindowingInd = header['FFTwindowingInd'][0] |
|
|
350 |
self.BeamAngleAzim = header['BeamAngleAzim'][0] |
|
|
351 |
self.BeamAngleZen = header['BeamAngleZen'][0] |
|
|
369 | self.SampResolution = header['SampResolution'][0] | |
|
370 | self.nHeights = header['nHeights'][0] | |
|
371 | self.StartRangeSamp = header['StartRangeSamp'][0] | |
|
372 | self.PRFhz = header['PRFhz'][0] | |
|
373 | self.nCohInt = header['nCohInt'][0] | |
|
374 | self.nProfiles = header['nProfiles'][0] | |
|
375 | self.nChannels = header['nChannels'][0] | |
|
376 | self.nIncohInt = header['nIncohInt'][0] | |
|
377 | self.FFTwindowingInd = header['FFTwindowingInd'][0] | |
|
378 | self.BeamAngleAzim = header['BeamAngleAzim'][0] | |
|
379 | self.BeamAngleZen = header['BeamAngleZen'][0] | |
|
352 | 380 | self.AntennaCoord0 = header['AntennaCoord0'][0] |
|
353 | 381 | self.AntennaAngl0 = header['AntennaAngl0'][0] |
|
354 | 382 | self.AntennaCoord1 = header['AntennaCoord1'][0] |
|
355 |
self.AntennaAngl1 = header['AntennaAngl1'][0] |
|
|
383 | self.AntennaAngl1 = header['AntennaAngl1'][0] | |
|
356 | 384 | self.AntennaCoord2 = header['AntennaCoord2'][0] |
|
357 |
self.AntennaAngl2 = header['AntennaAngl2'][0] |
|
|
385 | self.AntennaAngl2 = header['AntennaAngl2'][0] | |
|
358 | 386 | self.RecPhaseCalibr0 = header['RecPhaseCalibr0'][0] |
|
359 | 387 | self.RecPhaseCalibr1 = header['RecPhaseCalibr1'][0] |
|
360 |
self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0] |
|
|
388 | self.RecPhaseCalibr2 = header['RecPhaseCalibr2'][0] | |
|
361 | 389 | self.RecAmpCalibr0 = header['RecAmpCalibr0'][0] |
|
362 | 390 | self.RecAmpCalibr1 = header['RecAmpCalibr1'][0] |
|
363 |
self.RecAmpCalibr2 = header['RecAmpCalibr2'][0] |
|
|
391 | self.RecAmpCalibr2 = header['RecAmpCalibr2'][0] | |
|
364 | 392 | self.ReceiverGaindB0 = header['ReceiverGaindB0'][0] |
|
365 | 393 | self.ReceiverGaindB1 = header['ReceiverGaindB1'][0] |
|
366 | 394 | self.ReceiverGaindB2 = header['ReceiverGaindB2'][0] |
|
367 | 395 | |
|
368 | self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz) | |
|
369 | ||
|
370 | self.RHsize = 180+20*self.nChannels | |
|
371 | self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4 | |
|
372 | #print 'Datasize',self.Datasize | |
|
373 | endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec | |
|
374 | ||
|
396 | self.ipp = 0.5 * (SPEED_OF_LIGHT / self.PRFhz) | |
|
397 | ||
|
398 | self.RHsize = 180 + 20 * self.nChannels | |
|
399 | self.Datasize = self.nProfiles * self.nChannels * self.nHeights * 2 * 4 | |
|
400 | # print 'Datasize',self.Datasize | |
|
401 | endFp = self.OffsetStartHeader + self.RecCounter * self.Off2StartNxtRec | |
|
402 | ||
|
375 | 403 | print '==============================================' |
|
376 | print 'RecMgcNumber ',self.RecMgcNumber | |
|
377 | print 'RecCounter ',self.RecCounter | |
|
378 |
print 'Off2StartNxtRec ',self.Off2StartNxtRec |
|
|
379 | print 'Off2StartData ',self.Off2StartData | |
|
380 | print 'Range Resolution ',self.SampResolution | |
|
381 | print 'First Height ',self.StartRangeSamp | |
|
382 | print 'PRF (Hz) ',self.PRFhz | |
|
383 | print 'Heights (K) ',self.nHeights | |
|
384 | print 'Channels (N) ',self.nChannels | |
|
385 | print 'Profiles (J) ',self.nProfiles | |
|
386 | print 'iCoh ',self.nCohInt | |
|
387 | print 'iInCoh ',self.nIncohInt | |
|
388 | print 'BeamAngleAzim ',self.BeamAngleAzim | |
|
389 | print 'BeamAngleZen ',self.BeamAngleZen | |
|
390 | ||
|
391 | #print 'ModoEnUso ',self.DualModeIndex | |
|
392 | #print 'UtcTime ',self.nUtime | |
|
393 | #print 'MiliSec ',self.nMilisec | |
|
394 | #print 'Exp TagName ',self.ExpTagName | |
|
395 | #print 'Exp Comment ',self.ExpComment | |
|
396 | #print 'FFT Window Index ',self.FFTwindowingInd | |
|
397 | #print 'N Dig. Channels ',self.nDigChannels | |
|
398 | print 'Size de bloque ',self.RHsize | |
|
399 | print 'DataSize ',self.Datasize | |
|
400 | print 'BeamAngleAzim ',self.BeamAngleAzim | |
|
401 | #print 'AntennaCoord0 ',self.AntennaCoord0 | |
|
402 | #print 'AntennaAngl0 ',self.AntennaAngl0 | |
|
403 | #print 'AntennaCoord1 ',self.AntennaCoord1 | |
|
404 | #print 'AntennaAngl1 ',self.AntennaAngl1 | |
|
405 | #print 'AntennaCoord2 ',self.AntennaCoord2 | |
|
406 | #print 'AntennaAngl2 ',self.AntennaAngl2 | |
|
407 | print 'RecPhaseCalibr0 ',self.RecPhaseCalibr0 | |
|
408 | print 'RecPhaseCalibr1 ',self.RecPhaseCalibr1 | |
|
409 | print 'RecPhaseCalibr2 ',self.RecPhaseCalibr2 | |
|
410 | print 'RecAmpCalibr0 ',self.RecAmpCalibr0 | |
|
411 | print 'RecAmpCalibr1 ',self.RecAmpCalibr1 | |
|
412 | print 'RecAmpCalibr2 ',self.RecAmpCalibr2 | |
|
413 | print 'ReceiverGaindB0 ',self.ReceiverGaindB0 | |
|
414 | print 'ReceiverGaindB1 ',self.ReceiverGaindB1 | |
|
415 | print 'ReceiverGaindB2 ',self.ReceiverGaindB2 | |
|
404 | print 'RecMgcNumber ', self.RecMgcNumber | |
|
405 | print 'RecCounter ', self.RecCounter | |
|
406 | print 'Off2StartNxtRec ', self.Off2StartNxtRec | |
|
407 | print 'Off2StartData ', self.Off2StartData | |
|
408 | print 'Range Resolution ', self.SampResolution | |
|
409 | print 'First Height ', self.StartRangeSamp | |
|
410 | print 'PRF (Hz) ', self.PRFhz | |
|
411 | print 'Heights (K) ', self.nHeights | |
|
412 | print 'Channels (N) ', self.nChannels | |
|
413 | print 'Profiles (J) ', self.nProfiles | |
|
414 | print 'iCoh ', self.nCohInt | |
|
415 | print 'iInCoh ', self.nIncohInt | |
|
416 | print 'BeamAngleAzim ', self.BeamAngleAzim | |
|
417 | print 'BeamAngleZen ', self.BeamAngleZen | |
|
418 | ||
|
419 | # print 'ModoEnUso ',self.DualModeIndex | |
|
420 | # print 'UtcTime ',self.nUtime | |
|
421 | # print 'MiliSec ',self.nMilisec | |
|
422 | # print 'Exp TagName ',self.ExpTagName | |
|
423 | # print 'Exp Comment ',self.ExpComment | |
|
424 | # print 'FFT Window Index ',self.FFTwindowingInd | |
|
425 | # print 'N Dig. Channels ',self.nDigChannels | |
|
426 | print 'Size de bloque ', self.RHsize | |
|
427 | print 'DataSize ', self.Datasize | |
|
428 | print 'BeamAngleAzim ', self.BeamAngleAzim | |
|
429 | # print 'AntennaCoord0 ',self.AntennaCoord0 | |
|
430 | # print 'AntennaAngl0 ',self.AntennaAngl0 | |
|
431 | # print 'AntennaCoord1 ',self.AntennaCoord1 | |
|
432 | # print 'AntennaAngl1 ',self.AntennaAngl1 | |
|
433 | # print 'AntennaCoord2 ',self.AntennaCoord2 | |
|
434 | # print 'AntennaAngl2 ',self.AntennaAngl2 | |
|
435 | print 'RecPhaseCalibr0 ', self.RecPhaseCalibr0 | |
|
436 | print 'RecPhaseCalibr1 ', self.RecPhaseCalibr1 | |
|
437 | print 'RecPhaseCalibr2 ', self.RecPhaseCalibr2 | |
|
438 | print 'RecAmpCalibr0 ', self.RecAmpCalibr0 | |
|
439 | print 'RecAmpCalibr1 ', self.RecAmpCalibr1 | |
|
440 | print 'RecAmpCalibr2 ', self.RecAmpCalibr2 | |
|
441 | print 'ReceiverGaindB0 ', self.ReceiverGaindB0 | |
|
442 | print 'ReceiverGaindB1 ', self.ReceiverGaindB1 | |
|
443 | print 'ReceiverGaindB2 ', self.ReceiverGaindB2 | |
|
416 | 444 | print '==============================================' |
|
417 | ||
|
445 | ||
|
418 | 446 | if OffRHeader > endFp: |
|
419 | sys.stderr.write("Warning %s: Size value read from System Header is lower than it has to be\n" %fp) | |
|
447 | sys.stderr.write( | |
|
448 | "Warning %s: Size value read from System Header is lower than it has to be\n" % fp) | |
|
420 | 449 | return 0 |
|
421 | ||
|
450 | ||
|
422 | 451 | if OffRHeader < endFp: |
|
423 | sys.stderr.write("Warning %s: Size value read from System Header size is greater than it has to be\n" %fp) | |
|
452 | sys.stderr.write( | |
|
453 | "Warning %s: Size value read from System Header size is greater than it has to be\n" % fp) | |
|
424 | 454 | return 0 |
|
425 | ||
|
455 | ||
|
426 | 456 | return 1 |
|
427 | 457 | |
|
428 | ||
|
458 | ||
|
429 | 459 | class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODataReader): |
|
430 | ||
|
460 | ||
|
431 | 461 | path = None |
|
432 | 462 | startDate = None |
|
433 | 463 | endDate = None |
@@ -435,28 +465,25 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
435 | 465 | endTime = None |
|
436 | 466 | walk = None |
|
437 | 467 | isConfig = False |
|
438 | ||
|
439 | ||
|
440 | fileList= None | |
|
441 | ||
|
442 | #metadata | |
|
443 | TimeZone= None | |
|
444 | Interval= None | |
|
445 | heightList= None | |
|
446 | ||
|
447 |
|
|
|
448 |
|
|
|
449 | utctime= None | |
|
450 | ||
|
451 | ||
|
452 | ||
|
468 | ||
|
469 | fileList = None | |
|
470 | ||
|
471 | # metadata | |
|
472 | TimeZone = None | |
|
473 | Interval = None | |
|
474 | heightList = None | |
|
475 | ||
|
476 | # data | |
|
477 | data = None | |
|
478 | utctime = None | |
|
479 | ||
|
453 | 480 | def __init__(self, **kwargs): |
|
454 | ||
|
455 | #Eliminar de la base la herencia | |
|
481 | ||
|
482 | # Eliminar de la base la herencia | |
|
456 | 483 | ProcessingUnit.__init__(self, **kwargs) |
|
457 | ||
|
484 | ||
|
458 | 485 | #self.isConfig = False |
|
459 | ||
|
486 | ||
|
460 | 487 | #self.pts2read_SelfSpectra = 0 |
|
461 | 488 | #self.pts2read_CrossSpectra = 0 |
|
462 | 489 | #self.pts2read_DCchannels = 0 |
@@ -464,60 +491,59 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
464 | 491 | self.utc = None |
|
465 | 492 | self.ext = ".fdt" |
|
466 | 493 | self.optchar = "P" |
|
467 | self.fpFile=None | |
|
494 | self.fpFile = None | |
|
468 | 495 | self.fp = None |
|
469 | self.BlockCounter=0 | |
|
496 | self.BlockCounter = 0 | |
|
470 | 497 | self.dtype = None |
|
471 | 498 | self.fileSizeByHeader = None |
|
472 | 499 | self.filenameList = [] |
|
473 | 500 | self.fileSelector = 0 |
|
474 | self.Off2StartNxtRec=0 | |
|
475 | self.RecCounter=0 | |
|
501 | self.Off2StartNxtRec = 0 | |
|
502 | self.RecCounter = 0 | |
|
476 | 503 | self.flagNoMoreFiles = 0 |
|
477 | self.data_spc=None | |
|
478 | self.data_cspc=None | |
|
479 | self.data_output=None | |
|
504 | self.data_spc = None | |
|
505 | self.data_cspc = None | |
|
506 | self.data_output = None | |
|
480 | 507 | self.path = None |
|
481 | self.OffsetStartHeader=0 | |
|
482 | self.Off2StartData=0 | |
|
508 | self.OffsetStartHeader = 0 | |
|
509 | self.Off2StartData = 0 | |
|
483 | 510 | self.ipp = 0 |
|
484 | self.nFDTdataRecors=0 | |
|
511 | self.nFDTdataRecors = 0 | |
|
485 | 512 | self.blocksize = 0 |
|
486 | 513 | self.dataOut = Spectra() |
|
487 | self.profileIndex = 1 #Always | |
|
488 | self.dataOut.flagNoData=False | |
|
514 | self.profileIndex = 1 # Always | |
|
515 | self.dataOut.flagNoData = False | |
|
489 | 516 | self.dataOut.nRdPairs = 0 |
|
490 | 517 | self.dataOut.pairsList = [] |
|
491 | self.dataOut.data_spc=None | |
|
492 | self.dataOut.noise=[] | |
|
493 | self.dataOut.velocityX=[] | |
|
494 | self.dataOut.velocityY=[] | |
|
495 | self.dataOut.velocityV=[] | |
|
496 | ||
|
497 | ||
|
518 | self.dataOut.data_spc = None | |
|
519 | self.dataOut.noise = [] | |
|
520 | self.dataOut.velocityX = [] | |
|
521 | self.dataOut.velocityY = [] | |
|
522 | self.dataOut.velocityV = [] | |
|
498 | 523 | |
|
499 | 524 | def Files2Read(self, fp): |
|
500 | 525 | ''' |
|
501 | 526 | Function that indicates the number of .fdt files that exist in the folder to be read. |
|
502 | 527 | It also creates an organized list with the names of the files to read. |
|
503 | 528 | ''' |
|
504 | #self.__checkPath() | |
|
505 | ||
|
506 |
|
|
|
507 | ListaData=sorted(ListaData) #Sort the list of files from least to largest by names | |
|
508 | nFiles=0 #File Counter | |
|
509 | FileList=[] #A list is created that will contain the .fdt files | |
|
510 | for IndexFile in ListaData : | |
|
511 | if '.fdt' in IndexFile: | |
|
529 | # self.__checkPath() | |
|
530 | ||
|
531 | # Gets the list of files within the fp address | |
|
532 | ListaData = os.listdir(fp) | |
|
533 | # Sort the list of files from least to largest by names | |
|
534 | ListaData = sorted(ListaData) | |
|
535 | nFiles = 0 # File Counter | |
|
536 | FileList = [] # A list is created that will contain the .fdt files | |
|
537 | for IndexFile in ListaData: | |
|
538 | if '.fdt' in IndexFile: | |
|
512 | 539 | FileList.append(IndexFile) |
|
513 | nFiles+=1 | |
|
514 | ||
|
515 | #print 'Files2Read' | |
|
516 |
#print 'Existen '+str(nFiles)+' archivos .fdt' |
|
|
517 | ||
|
518 | self.filenameList=FileList #List of files from least to largest by names | |
|
519 | ||
|
520 | ||
|
540 | nFiles += 1 | |
|
541 | ||
|
542 | # print 'Files2Read' | |
|
543 | # print 'Existen '+str(nFiles)+' archivos .fdt' | |
|
544 | ||
|
545 | self.filenameList = FileList # List of files from least to largest by names | |
|
546 | ||
|
521 | 547 | def run(self, **kwargs): |
|
522 | 548 | ''' |
|
523 | 549 | This method will be the one that will initiate the data entry, will be called constantly. |
@@ -527,341 +553,350 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
527 | 553 | if not self.isConfig: |
|
528 | 554 | self.setup(**kwargs) |
|
529 | 555 | self.isConfig = True |
|
530 | ||
|
556 | ||
|
531 | 557 | self.getData() |
|
532 | #print 'running' | |
|
533 | ||
|
534 | ||
|
558 | # print 'running' | |
|
559 | ||
|
535 | 560 | def setup(self, path=None, |
|
536 |
|
|
|
537 |
|
|
|
538 |
|
|
|
539 |
|
|
|
540 |
|
|
|
541 |
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
|
|
|
545 |
|
|
|
546 | ||
|
561 | startDate=None, | |
|
562 | endDate=None, | |
|
563 | startTime=None, | |
|
564 | endTime=None, | |
|
565 | walk=True, | |
|
566 | timezone='utc', | |
|
567 | code=None, | |
|
568 | online=False, | |
|
569 | ReadMode=None, | |
|
570 | **kwargs): | |
|
571 | ||
|
547 | 572 | self.isConfig = True |
|
548 | ||
|
549 |
self.path=path |
|
|
550 | self.startDate=startDate | |
|
551 | self.endDate=endDate | |
|
552 |
self.startTime=startTime |
|
|
553 | self.endTime=endTime | |
|
554 |
self.walk=walk |
|
|
555 | self.ReadMode=int(ReadMode) | |
|
556 | ||
|
573 | ||
|
574 | self.path = path | |
|
575 | self.startDate = startDate | |
|
576 | self.endDate = endDate | |
|
577 | self.startTime = startTime | |
|
578 | self.endTime = endTime | |
|
579 | self.walk = walk | |
|
580 | self.ReadMode = int(ReadMode) | |
|
581 | ||
|
557 | 582 | pass |
|
558 | ||
|
559 | ||
|
583 | ||
|
560 | 584 | def getData(self): |
|
561 | 585 | ''' |
|
562 | 586 | Before starting this function, you should check that there is still an unread file, |
|
563 | 587 | If there are still blocks to read or if the data block is empty. |
|
564 | ||
|
588 | ||
|
565 | 589 | You should call the file "read". |
|
566 | ||
|
590 | ||
|
567 | 591 | ''' |
|
568 | ||
|
592 | ||
|
569 | 593 | if self.flagNoMoreFiles: |
|
570 | 594 | self.dataOut.flagNoData = True |
|
571 | 595 | print 'NoData se vuelve true' |
|
572 | 596 | return 0 |
|
573 | 597 | |
|
574 | self.fp=self.path | |
|
598 | self.fp = self.path | |
|
575 | 599 | self.Files2Read(self.fp) |
|
576 | 600 | self.readFile(self.fp) |
|
577 | 601 | self.dataOut.data_spc = self.data_spc |
|
578 | self.dataOut.data_cspc =self.data_cspc | |
|
579 | self.dataOut.data_output=self.data_output | |
|
580 | ||
|
602 | self.dataOut.data_cspc = self.data_cspc | |
|
603 | self.dataOut.data_output = self.data_output | |
|
604 | ||
|
581 | 605 | print 'self.dataOut.data_output', shape(self.dataOut.data_output) |
|
582 | ||
|
583 | #self.removeDC() | |
|
584 |
return self.dataOut.data_spc |
|
|
585 | ||
|
586 | ||
|
587 | def readFile(self,fp): | |
|
606 | ||
|
607 | # self.removeDC() | |
|
608 | return self.dataOut.data_spc | |
|
609 | ||
|
610 | def readFile(self, fp): | |
|
588 | 611 | ''' |
|
589 | 612 | You must indicate if you are reading in Online or Offline mode and load the |
|
590 | 613 | The parameters for this file reading mode. |
|
591 | ||
|
614 | ||
|
592 | 615 | Then you must do 2 actions: |
|
593 | ||
|
616 | ||
|
594 | 617 | 1. Get the BLTR FileHeader. |
|
595 | 618 | 2. Start reading the first block. |
|
596 | 619 | ''' |
|
597 | ||
|
598 | #The address of the folder is generated the name of the .fdt file that will be read | |
|
599 | print "File: ",self.fileSelector+1 | |
|
600 | ||
|
620 | ||
|
621 | # The address of the folder is generated the name of the .fdt file that will be read | |
|
622 | print "File: ", self.fileSelector + 1 | |
|
623 | ||
|
601 | 624 | if self.fileSelector < len(self.filenameList): |
|
602 | ||
|
603 |
self.fpFile=str(fp)+'/'+ |
|
|
604 | #print self.fpFile | |
|
625 | ||
|
626 | self.fpFile = str(fp) + '/' + \ | |
|
627 | str(self.filenameList[self.fileSelector]) | |
|
628 | # print self.fpFile | |
|
605 | 629 | fheader = FileHeaderBLTR() |
|
606 |
fheader.FHread(self.fpFile) |
|
|
607 | self.nFDTdataRecors=fheader.nFDTdataRecors | |
|
608 | ||
|
609 |
self.readBlock() |
|
|
630 | fheader.FHread(self.fpFile) # Bltr FileHeader Reading | |
|
631 | self.nFDTdataRecors = fheader.nFDTdataRecors | |
|
632 | ||
|
633 | self.readBlock() # Block reading | |
|
610 | 634 | else: |
|
611 | 635 | print 'readFile FlagNoData becomes true' |
|
612 | self.flagNoMoreFiles=True | |
|
636 | self.flagNoMoreFiles = True | |
|
613 | 637 | self.dataOut.flagNoData = True |
|
614 |
return 0 |
|
|
615 | ||
|
638 | return 0 | |
|
639 | ||
|
616 | 640 | def getVelRange(self, extrapoints=0): |
|
617 |
|
|
|
618 |
|
|
|
619 | Vmax=-Lambda/(4.*(1./PRF)*self.dataOut.nCohInt*2.) | |
|
620 | deltafreq = PRF / (self.nProfiles) | |
|
621 |
|
|
|
622 | freqrange = deltafreq*(numpy.arange(self.nProfiles)-self.nProfiles/2.) - deltafreq/2 | |
|
623 | velrange = deltavel*(numpy.arange(self.nProfiles)-self.nProfiles/2.) | |
|
624 | return velrange | |
|
625 | ||
|
626 | def readBlock(self): | |
|
641 | Lambda = SPEED_OF_LIGHT / 50000000 | |
|
642 | # 1./(self.dataOut.ippSeconds * self.dataOut.nCohInt) | |
|
643 | PRF = self.dataOut.PRF | |
|
644 | Vmax = -Lambda / (4. * (1. / PRF) * self.dataOut.nCohInt * 2.) | |
|
645 | deltafreq = PRF / (self.nProfiles) | |
|
646 | deltavel = (Vmax * 2) / (self.nProfiles) | |
|
647 | freqrange = deltafreq * \ | |
|
648 | (numpy.arange(self.nProfiles) - self.nProfiles / 2.) - deltafreq / 2 | |
|
649 | velrange = deltavel * \ | |
|
650 | (numpy.arange(self.nProfiles) - self.nProfiles / 2.) | |
|
651 | return velrange | |
|
652 | ||
|
653 | def readBlock(self): | |
|
627 | 654 | ''' |
|
628 | 655 | It should be checked if the block has data, if it is not passed to the next file. |
|
629 | ||
|
656 | ||
|
630 | 657 | Then the following is done: |
|
631 | ||
|
658 | ||
|
632 | 659 | 1. Read the RecordHeader |
|
633 | 660 | 2. Fill the buffer with the current block number. |
|
634 | ||
|
661 | ||
|
635 | 662 | ''' |
|
636 | ||
|
637 | if self.BlockCounter < self.nFDTdataRecors-2: | |
|
663 | ||
|
664 | if self.BlockCounter < self.nFDTdataRecors - 2: | |
|
638 | 665 | print self.nFDTdataRecors, 'CONDICION!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!' |
|
639 | if self.ReadMode==1: | |
|
640 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter+1) | |
|
641 | elif self.ReadMode==0: | |
|
666 | if self.ReadMode == 1: | |
|
667 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter + 1) | |
|
668 | elif self.ReadMode == 0: | |
|
642 | 669 | rheader = RecordHeaderBLTR(RecCounter=self.BlockCounter) |
|
643 | ||
|
644 |
rheader.RHread(self.fpFile) |
|
|
645 | ||
|
646 | self.OffsetStartHeader=rheader.OffsetStartHeader | |
|
647 | self.RecCounter=rheader.RecCounter | |
|
648 | self.Off2StartNxtRec=rheader.Off2StartNxtRec | |
|
649 | self.Off2StartData=rheader.Off2StartData | |
|
650 | self.nProfiles=rheader.nProfiles | |
|
651 | self.nChannels=rheader.nChannels | |
|
652 | self.nHeights=rheader.nHeights | |
|
653 | self.frequency=rheader.TransmitFrec | |
|
654 | self.DualModeIndex=rheader.DualModeIndex | |
|
655 | ||
|
656 | self.pairsList =[(0,1),(0,2),(1,2)] | |
|
670 | ||
|
671 | rheader.RHread(self.fpFile) # Bltr FileHeader Reading | |
|
672 | ||
|
673 | self.OffsetStartHeader = rheader.OffsetStartHeader | |
|
674 | self.RecCounter = rheader.RecCounter | |
|
675 | self.Off2StartNxtRec = rheader.Off2StartNxtRec | |
|
676 | self.Off2StartData = rheader.Off2StartData | |
|
677 | self.nProfiles = rheader.nProfiles | |
|
678 | self.nChannels = rheader.nChannels | |
|
679 | self.nHeights = rheader.nHeights | |
|
680 | self.frequency = rheader.TransmitFrec | |
|
681 | self.DualModeIndex = rheader.DualModeIndex | |
|
682 | ||
|
683 | self.pairsList = [(0, 1), (0, 2), (1, 2)] | |
|
657 | 684 | self.dataOut.pairsList = self.pairsList |
|
658 | ||
|
659 | self.nRdPairs=len(self.dataOut.pairsList) | |
|
685 | ||
|
686 | self.nRdPairs = len(self.dataOut.pairsList) | |
|
660 | 687 | self.dataOut.nRdPairs = self.nRdPairs |
|
661 | ||
|
662 | self.__firstHeigth=rheader.StartRangeSamp | |
|
663 | self.__deltaHeigth=rheader.SampResolution | |
|
664 |
self.dataOut.heightList= self.__firstHeigth + |
|
|
688 | ||
|
689 | self.__firstHeigth = rheader.StartRangeSamp | |
|
690 | self.__deltaHeigth = rheader.SampResolution | |
|
691 | self.dataOut.heightList = self.__firstHeigth + \ | |
|
692 | numpy.array(range(self.nHeights)) * self.__deltaHeigth | |
|
665 | 693 | self.dataOut.channelList = range(self.nChannels) |
|
666 | self.dataOut.nProfiles=rheader.nProfiles | |
|
667 | self.dataOut.nIncohInt=rheader.nIncohInt | |
|
668 | self.dataOut.nCohInt=rheader.nCohInt | |
|
669 | self.dataOut.ippSeconds= 1/float(rheader.PRFhz) | |
|
670 | self.dataOut.PRF=rheader.PRFhz | |
|
671 | self.dataOut.nFFTPoints=rheader.nProfiles | |
|
672 | self.dataOut.utctime=rheader.nUtime | |
|
673 | self.dataOut.timeZone=0 | |
|
674 |
self.dataOut.normFactor= self.dataOut.nProfiles* |
|
|
675 | self.dataOut.outputInterval= self.dataOut.ippSeconds * self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles | |
|
676 | ||
|
677 | self.data_output=numpy.ones([3,rheader.nHeights])*numpy.NaN | |
|
694 | self.dataOut.nProfiles = rheader.nProfiles | |
|
695 | self.dataOut.nIncohInt = rheader.nIncohInt | |
|
696 | self.dataOut.nCohInt = rheader.nCohInt | |
|
697 | self.dataOut.ippSeconds = 1 / float(rheader.PRFhz) | |
|
698 | self.dataOut.PRF = rheader.PRFhz | |
|
699 | self.dataOut.nFFTPoints = rheader.nProfiles | |
|
700 | self.dataOut.utctime = rheader.nUtime | |
|
701 | self.dataOut.timeZone = 0 | |
|
702 | self.dataOut.normFactor = self.dataOut.nProfiles * \ | |
|
703 | self.dataOut.nIncohInt * self.dataOut.nCohInt | |
|
704 | self.dataOut.outputInterval = self.dataOut.ippSeconds * \ | |
|
705 | self.dataOut.nCohInt * self.dataOut.nIncohInt * self.nProfiles | |
|
706 | ||
|
707 | self.data_output = numpy.ones([3, rheader.nHeights]) * numpy.NaN | |
|
678 | 708 | print 'self.data_output', shape(self.data_output) |
|
679 | self.dataOut.velocityX=[] | |
|
680 | self.dataOut.velocityY=[] | |
|
681 | self.dataOut.velocityV=[] | |
|
682 | ||
|
709 | self.dataOut.velocityX = [] | |
|
710 | self.dataOut.velocityY = [] | |
|
711 | self.dataOut.velocityV = [] | |
|
712 | ||
|
683 | 713 | '''Block Reading, the Block Data is received and Reshape is used to give it |
|
684 | 714 | shape. |
|
685 |
''' |
|
|
686 | ||
|
687 | #Procedure to take the pointer to where the date block starts | |
|
688 | startDATA = open(self.fpFile,"rb") | |
|
689 |
OffDATA= self.OffsetStartHeader + self.RecCounter* |
|
|
715 | ''' | |
|
716 | ||
|
717 | # Procedure to take the pointer to where the date block starts | |
|
718 | startDATA = open(self.fpFile, "rb") | |
|
719 | OffDATA = self.OffsetStartHeader + self.RecCounter * \ | |
|
720 | self.Off2StartNxtRec + self.Off2StartData | |
|
690 | 721 | startDATA.seek(OffDATA, os.SEEK_SET) |
|
691 | ||
|
722 | ||
|
692 | 723 | def moving_average(x, N=2): |
|
693 | return numpy.convolve(x, numpy.ones((N,))/N)[(N-1):] | |
|
694 | ||
|
695 | def gaus(xSamples,a,x0,sigma): | |
|
696 | return a*exp(-(xSamples-x0)**2/(2*sigma**2)) | |
|
697 | ||
|
698 | def Find(x,value): | |
|
724 | return numpy.convolve(x, numpy.ones((N,)) / N)[(N - 1):] | |
|
725 | ||
|
726 | def gaus(xSamples, a, x0, sigma): | |
|
727 | return a * exp(-(xSamples - x0)**2 / (2 * sigma**2)) | |
|
728 | ||
|
729 | def Find(x, value): | |
|
699 | 730 | for index in range(len(x)): |
|
700 | if x[index]==value: | |
|
701 |
return index |
|
|
702 | ||
|
731 | if x[index] == value: | |
|
732 | return index | |
|
733 | ||
|
703 | 734 | def pol2cart(rho, phi): |
|
704 | 735 | x = rho * numpy.cos(phi) |
|
705 | 736 | y = rho * numpy.sin(phi) |
|
706 | 737 | return(x, y) |
|
707 | ||
|
708 | ||
|
709 | ||
|
710 | ||
|
711 | if self.DualModeIndex==self.ReadMode: | |
|
712 | ||
|
713 | self.data_fft = numpy.fromfile( startDATA, [('complex','<c8')],self.nProfiles*self.nChannels*self.nHeights ) | |
|
714 | ||
|
715 | self.data_fft=self.data_fft.astype(numpy.dtype('complex')) | |
|
716 | ||
|
717 | self.data_block=numpy.reshape(self.data_fft,(self.nHeights, self.nChannels, self.nProfiles )) | |
|
718 | ||
|
719 | self.data_block = numpy.transpose(self.data_block, (1,2,0)) | |
|
720 | ||
|
738 | ||
|
739 | if self.DualModeIndex == self.ReadMode: | |
|
740 | ||
|
741 | self.data_fft = numpy.fromfile( | |
|
742 | startDATA, [('complex', '<c8')], self.nProfiles * self.nChannels * self.nHeights) | |
|
743 | ||
|
744 | self.data_fft = self.data_fft.astype(numpy.dtype('complex')) | |
|
745 | ||
|
746 | self.data_block = numpy.reshape( | |
|
747 | self.data_fft, (self.nHeights, self.nChannels, self.nProfiles)) | |
|
748 | ||
|
749 | self.data_block = numpy.transpose(self.data_block, (1, 2, 0)) | |
|
750 | ||
|
721 | 751 | copy = self.data_block.copy() |
|
722 |
spc = copy * numpy.conjugate(copy) |
|
|
723 | ||
|
724 |
self.data_spc = numpy.absolute( |
|
|
725 | ||
|
752 | spc = copy * numpy.conjugate(copy) | |
|
753 | ||
|
754 | self.data_spc = numpy.absolute( | |
|
755 | spc) # valor absoluto o magnitud | |
|
756 | ||
|
726 | 757 | factor = self.dataOut.normFactor |
|
727 | ||
|
728 | ||
|
729 | z = self.data_spc.copy()#/factor | |
|
758 | ||
|
759 | z = self.data_spc.copy() # /factor | |
|
730 | 760 | z = numpy.where(numpy.isfinite(z), z, numpy.NAN) |
|
731 | 761 | #zdB = 10*numpy.log10(z) |
|
732 | 762 | print ' ' |
|
733 | 763 | print 'Z: ' |
|
734 |
print shape(z) |
|
|
764 | print shape(z) | |
|
735 | 765 | print ' ' |
|
736 | 766 | print ' ' |
|
737 | ||
|
738 | self.dataOut.data_spc=self.data_spc | |
|
739 | ||
|
740 |
self.noise = self.dataOut.getNoise( |
|
|
767 | ||
|
768 | self.dataOut.data_spc = self.data_spc | |
|
769 | ||
|
770 | self.noise = self.dataOut.getNoise( | |
|
771 | ymin_index=80, ymax_index=132) # /factor | |
|
741 | 772 | #noisedB = 10*numpy.log10(self.noise) |
|
742 | ||
|
743 | ||
|
744 |
|
|
|
745 |
|
|
|
746 |
|
|
|
747 | coherence=numpy.ones([3,self.nProfiles]) | |
|
748 | PhaseSlope=numpy.ones(3) | |
|
749 | PhaseInter=numpy.ones(3) | |
|
750 | ||
|
773 | ||
|
774 | ySamples = numpy.ones([3, self.nProfiles]) | |
|
775 | phase = numpy.ones([3, self.nProfiles]) | |
|
776 | CSPCSamples = numpy.ones( | |
|
777 | [3, self.nProfiles], dtype=numpy.complex_) | |
|
778 | coherence = numpy.ones([3, self.nProfiles]) | |
|
779 | PhaseSlope = numpy.ones(3) | |
|
780 | PhaseInter = numpy.ones(3) | |
|
781 | ||
|
751 | 782 | '''****** Getting CrossSpectra ******''' |
|
752 | cspc=self.data_block.copy() | |
|
753 | self.data_cspc=self.data_block.copy() | |
|
754 | ||
|
755 | xFrec=self.getVelRange(1) | |
|
756 | VelRange=self.getVelRange(1) | |
|
757 | self.dataOut.VelRange=VelRange | |
|
758 | #print ' ' | |
|
759 | #print ' ' | |
|
760 | #print 'xFrec',xFrec | |
|
761 | #print ' ' | |
|
762 | #print ' ' | |
|
763 | #Height=35 | |
|
764 |
for i in range(self.nRdPairs): |
|
|
765 | ||
|
783 | cspc = self.data_block.copy() | |
|
784 | self.data_cspc = self.data_block.copy() | |
|
785 | ||
|
786 | xFrec = self.getVelRange(1) | |
|
787 | VelRange = self.getVelRange(1) | |
|
788 | self.dataOut.VelRange = VelRange | |
|
789 | # print ' ' | |
|
790 | # print ' ' | |
|
791 | # print 'xFrec',xFrec | |
|
792 | # print ' ' | |
|
793 | # print ' ' | |
|
794 | # Height=35 | |
|
795 | for i in range(self.nRdPairs): | |
|
796 | ||
|
766 | 797 | chan_index0 = self.dataOut.pairsList[i][0] |
|
767 | 798 | chan_index1 = self.dataOut.pairsList[i][1] |
|
768 | ||
|
769 |
self.data_cspc[i,:,:]=cspc[chan_index0,:, |
|
|
770 | ||
|
771 | ||
|
799 | ||
|
800 | self.data_cspc[i, :, :] = cspc[chan_index0, :, | |
|
801 | :] * numpy.conjugate(cspc[chan_index1, :, :]) | |
|
802 | ||
|
772 | 803 | '''Getting Eij and Nij''' |
|
773 |
(AntennaX0,AntennaY0)=pol2cart( |
|
|
774 |
|
|
|
775 |
(AntennaX |
|
|
776 | ||
|
777 |
|
|
|
778 | N01=AntennaY0-AntennaY1 | |
|
779 | ||
|
780 |
E0 |
|
|
781 |
N0 |
|
|
782 | ||
|
783 |
E |
|
|
784 |
N |
|
|
785 | ||
|
786 | self.ChanDist= numpy.array([[E01, N01],[E02,N02],[E12,N12]]) | |
|
787 | ||
|
804 | (AntennaX0, AntennaY0) = pol2cart( | |
|
805 | rheader.AntennaCoord0, rheader.AntennaAngl0 * numpy.pi / 180) | |
|
806 | (AntennaX1, AntennaY1) = pol2cart( | |
|
807 | rheader.AntennaCoord1, rheader.AntennaAngl1 * numpy.pi / 180) | |
|
808 | (AntennaX2, AntennaY2) = pol2cart( | |
|
809 | rheader.AntennaCoord2, rheader.AntennaAngl2 * numpy.pi / 180) | |
|
810 | ||
|
811 | E01 = AntennaX0 - AntennaX1 | |
|
812 | N01 = AntennaY0 - AntennaY1 | |
|
813 | ||
|
814 | E02 = AntennaX0 - AntennaX2 | |
|
815 | N02 = AntennaY0 - AntennaY2 | |
|
816 | ||
|
817 | E12 = AntennaX1 - AntennaX2 | |
|
818 | N12 = AntennaY1 - AntennaY2 | |
|
819 | ||
|
820 | self.ChanDist = numpy.array( | |
|
821 | [[E01, N01], [E02, N02], [E12, N12]]) | |
|
822 | ||
|
788 | 823 | self.dataOut.ChanDist = self.ChanDist |
|
789 | ||
|
790 | ||
|
824 | ||
|
825 | ||
|
791 | 826 | # for Height in range(self.nHeights): |
|
792 | # | |
|
827 | # | |
|
793 | 828 | # for i in range(self.nRdPairs): |
|
794 | # | |
|
829 | # | |
|
795 | 830 | # '''****** Line of Data SPC ******''' |
|
796 | 831 | # zline=z[i,:,Height] |
|
797 | # | |
|
832 | # | |
|
798 | 833 | # '''****** DC is removed ******''' |
|
799 | 834 | # DC=Find(zline,numpy.amax(zline)) |
|
800 | 835 | # zline[DC]=(zline[DC-1]+zline[DC+1])/2 |
|
801 | # | |
|
802 | # | |
|
836 | # | |
|
837 | # | |
|
803 | 838 | # '''****** SPC is normalized ******''' |
|
804 | 839 | # FactNorm= zline.copy() / numpy.sum(zline.copy()) |
|
805 | 840 | # FactNorm= FactNorm/numpy.sum(FactNorm) |
|
806 | # | |
|
841 | # | |
|
807 | 842 | # SmoothSPC=moving_average(FactNorm,N=3) |
|
808 | # | |
|
843 | # | |
|
809 | 844 | # xSamples = ar(range(len(SmoothSPC))) |
|
810 | 845 | # ySamples[i] = SmoothSPC-self.noise[i] |
|
811 | # | |
|
846 | # | |
|
812 | 847 | # for i in range(self.nRdPairs): |
|
813 | # | |
|
848 | # | |
|
814 | 849 | # '''****** Line of Data CSPC ******''' |
|
815 | 850 | # cspcLine=self.data_cspc[i,:,Height].copy() |
|
816 | # | |
|
817 | # | |
|
818 | # | |
|
851 | # | |
|
852 | # | |
|
853 | # | |
|
819 | 854 | # '''****** CSPC is normalized ******''' |
|
820 | 855 | # chan_index0 = self.dataOut.pairsList[i][0] |
|
821 |
# chan_index1 = self.dataOut.pairsList[i][1] |
|
|
856 | # chan_index1 = self.dataOut.pairsList[i][1] | |
|
822 | 857 | # CSPCFactor= numpy.sum(ySamples[chan_index0]) * numpy.sum(ySamples[chan_index1]) |
|
823 | # | |
|
824 | # | |
|
858 | # | |
|
859 | # | |
|
825 | 860 | # CSPCNorm= cspcLine.copy() / numpy.sqrt(CSPCFactor) |
|
826 | # | |
|
827 | # | |
|
861 | # | |
|
862 | # | |
|
828 | 863 | # CSPCSamples[i] = CSPCNorm-self.noise[i] |
|
829 | 864 | # coherence[i] = numpy.abs(CSPCSamples[i]) / numpy.sqrt(CSPCFactor) |
|
830 | # | |
|
865 | # | |
|
831 | 866 | # '''****** DC is removed ******''' |
|
832 | 867 | # DC=Find(coherence[i],numpy.amax(coherence[i])) |
|
833 | 868 | # coherence[i][DC]=(coherence[i][DC-1]+coherence[i][DC+1])/2 |
|
834 | 869 | # coherence[i]= moving_average(coherence[i],N=2) |
|
835 | # | |
|
870 | # | |
|
836 | 871 | # phase[i] = moving_average( numpy.arctan2(CSPCSamples[i].imag, CSPCSamples[i].real),N=1)#*180/numpy.pi |
|
837 | # | |
|
838 | # | |
|
872 | # | |
|
873 | # | |
|
839 | 874 | # '''****** Getting fij width ******''' |
|
840 | # | |
|
875 | # | |
|
841 | 876 | # yMean=[] |
|
842 |
# yMean2=[] |
|
|
843 | # | |
|
877 | # yMean2=[] | |
|
878 | # | |
|
844 | 879 | # for j in range(len(ySamples[1])): |
|
845 | 880 | # yMean=numpy.append(yMean,numpy.average([ySamples[0,j],ySamples[1,j],ySamples[2,j]])) |
|
846 | # | |
|
881 | # | |
|
847 | 882 | # '''******* Getting fitting Gaussian ******''' |
|
848 | 883 | # meanGauss=sum(xSamples*yMean) / len(xSamples) |
|
849 | 884 | # sigma=sum(yMean*(xSamples-meanGauss)**2) / len(xSamples) |
|
850 | 885 | # #print 'Height',Height,'SNR', meanGauss/sigma**2 |
|
851 | # | |
|
886 | # | |
|
852 | 887 | # if (abs(meanGauss/sigma**2) > 0.0001) : |
|
853 | # | |
|
854 |
# try: |
|
|
888 | # | |
|
889 | # try: | |
|
855 | 890 | # popt,pcov = curve_fit(gaus,xSamples,yMean,p0=[1,meanGauss,sigma]) |
|
856 | # | |
|
891 | # | |
|
857 | 892 | # if numpy.amax(popt)>numpy.amax(yMean)*0.3: |
|
858 | 893 | # FitGauss=gaus(xSamples,*popt) |
|
859 | # | |
|
860 |
# else: |
|
|
894 | # | |
|
895 | # else: | |
|
861 | 896 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) |
|
862 | 897 | # print 'Verificador: Dentro', Height |
|
863 | 898 | # except RuntimeError: |
|
864 | # | |
|
899 | # | |
|
865 | 900 | # try: |
|
866 | 901 | # for j in range(len(ySamples[1])): |
|
867 | 902 | # yMean2=numpy.append(yMean2,numpy.average([ySamples[1,j],ySamples[2,j]])) |
@@ -869,7 +904,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
869 | 904 | # FitGauss=gaus(xSamples,*popt) |
|
870 | 905 | # print 'Verificador: Exepcion1', Height |
|
871 | 906 | # except RuntimeError: |
|
872 | # | |
|
907 | # | |
|
873 | 908 | # try: |
|
874 | 909 | # popt,pcov = curve_fit(gaus,xSamples,ySamples[1],p0=[1,meanGauss,sigma]) |
|
875 | 910 | # FitGauss=gaus(xSamples,*popt) |
@@ -880,12 +915,12 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
880 | 915 | # else: |
|
881 | 916 | # FitGauss=numpy.ones(len(xSamples))*numpy.mean(yMean) |
|
882 | 917 | # #print 'Verificador: Fuera', Height |
|
883 | # | |
|
884 | # | |
|
885 | # | |
|
918 | # | |
|
919 | # | |
|
920 | # | |
|
886 | 921 | # Maximun=numpy.amax(yMean) |
|
887 | 922 | # eMinus1=Maximun*numpy.exp(-1) |
|
888 | # | |
|
923 | # | |
|
889 | 924 | # HWpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-eMinus1))) |
|
890 | 925 | # HalfWidth= xFrec[HWpos] |
|
891 | 926 | # GCpos=Find(FitGauss, numpy.amax(FitGauss)) |
@@ -894,39 +929,39 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
894 | 929 | # #Vpos=Find(FactNorm, min(FactNorm, key=lambda value:abs(value- numpy.mean(FactNorm) ))) |
|
895 | 930 | # #print 'GCpos',GCpos, numpy.amax(FitGauss), 'HWpos',HWpos |
|
896 | 931 | # '''****** Getting Fij ******''' |
|
897 | # | |
|
932 | # | |
|
898 | 933 | # GaussCenter=xFrec[GCpos] |
|
899 | 934 | # if (GaussCenter<0 and HalfWidth>0) or (GaussCenter>0 and HalfWidth<0): |
|
900 | 935 | # Fij=abs(GaussCenter)+abs(HalfWidth)+0.0000001 |
|
901 | 936 | # else: |
|
902 | 937 | # Fij=abs(GaussCenter-HalfWidth)+0.0000001 |
|
903 | # | |
|
938 | # | |
|
904 | 939 | # '''****** Getting Frecuency range of significant data ******''' |
|
905 | # | |
|
940 | # | |
|
906 | 941 | # Rangpos=Find(FitGauss,min(FitGauss, key=lambda value:abs(value-Maximun*0.10))) |
|
907 | # | |
|
942 | # | |
|
908 | 943 | # if Rangpos<GCpos: |
|
909 | 944 | # Range=numpy.array([Rangpos,2*GCpos-Rangpos]) |
|
910 | 945 | # else: |
|
911 | 946 | # Range=numpy.array([2*GCpos-Rangpos,Rangpos]) |
|
912 | # | |
|
947 | # | |
|
913 | 948 | # FrecRange=xFrec[Range[0]:Range[1]] |
|
914 | # | |
|
949 | # | |
|
915 | 950 | # #print 'FrecRange', FrecRange |
|
916 | 951 | # '''****** Getting SCPC Slope ******''' |
|
917 | # | |
|
952 | # | |
|
918 | 953 | # for i in range(self.nRdPairs): |
|
919 | # | |
|
954 | # | |
|
920 | 955 | # if len(FrecRange)>5 and len(FrecRange)<self.nProfiles*0.5: |
|
921 |
# PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3) |
|
|
922 | # | |
|
956 | # PhaseRange=moving_average(phase[i,Range[0]:Range[1]],N=3) | |
|
957 | # | |
|
923 | 958 | # slope, intercept, r_value, p_value, std_err = stats.linregress(FrecRange,PhaseRange) |
|
924 | 959 | # PhaseSlope[i]=slope |
|
925 | 960 | # PhaseInter[i]=intercept |
|
926 | 961 | # else: |
|
927 | 962 | # PhaseSlope[i]=0 |
|
928 | 963 | # PhaseInter[i]=0 |
|
929 | # | |
|
964 | # | |
|
930 | 965 | # # plt.figure(i+15) |
|
931 | 966 | # # plt.title('FASE ( CH%s*CH%s )' %(self.dataOut.pairsList[i][0],self.dataOut.pairsList[i][1])) |
|
932 | 967 | # # plt.xlabel('Frecuencia (KHz)') |
@@ -934,76 +969,76 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
934 | 969 | # # #plt.subplot(311+i) |
|
935 | 970 | # # plt.plot(FrecRange,PhaseRange,'b') |
|
936 | 971 | # # plt.plot(FrecRange,FrecRange*PhaseSlope[i]+PhaseInter[i],'r') |
|
937 | # | |
|
972 | # | |
|
938 | 973 | # #plt.axis([-0.6, 0.2, -3.2, 3.2]) |
|
939 | # | |
|
940 | # | |
|
974 | # | |
|
975 | # | |
|
941 | 976 | # '''Getting constant C''' |
|
942 | 977 | # cC=(Fij*numpy.pi)**2 |
|
943 | # | |
|
978 | # | |
|
944 | 979 | # # '''Getting Eij and Nij''' |
|
945 | 980 | # # (AntennaX0,AntennaY0)=pol2cart(rheader.AntennaCoord0, rheader.AntennaAngl0*numpy.pi/180) |
|
946 | 981 | # # (AntennaX1,AntennaY1)=pol2cart(rheader.AntennaCoord1, rheader.AntennaAngl1*numpy.pi/180) |
|
947 | 982 | # # (AntennaX2,AntennaY2)=pol2cart(rheader.AntennaCoord2, rheader.AntennaAngl2*numpy.pi/180) |
|
948 | # # | |
|
983 | # # | |
|
949 | 984 | # # E01=AntennaX0-AntennaX1 |
|
950 | 985 | # # N01=AntennaY0-AntennaY1 |
|
951 | # # | |
|
986 | # # | |
|
952 | 987 | # # E02=AntennaX0-AntennaX2 |
|
953 | 988 | # # N02=AntennaY0-AntennaY2 |
|
954 | # # | |
|
989 | # # | |
|
955 | 990 | # # E12=AntennaX1-AntennaX2 |
|
956 | 991 | # # N12=AntennaY1-AntennaY2 |
|
957 | # | |
|
992 | # | |
|
958 | 993 | # '''****** Getting constants F and G ******''' |
|
959 | 994 | # MijEijNij=numpy.array([[E02,N02], [E12,N12]]) |
|
960 | 995 | # MijResult0=(-PhaseSlope[1]*cC) / (2*numpy.pi) |
|
961 |
# MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi) |
|
|
996 | # MijResult1=(-PhaseSlope[2]*cC) / (2*numpy.pi) | |
|
962 | 997 | # MijResults=numpy.array([MijResult0,MijResult1]) |
|
963 | 998 | # (cF,cG) = numpy.linalg.solve(MijEijNij, MijResults) |
|
964 | # | |
|
999 | # | |
|
965 | 1000 | # '''****** Getting constants A, B and H ******''' |
|
966 | 1001 | # W01=numpy.amax(coherence[0]) |
|
967 | 1002 | # W02=numpy.amax(coherence[1]) |
|
968 | 1003 | # W12=numpy.amax(coherence[2]) |
|
969 | # | |
|
1004 | # | |
|
970 | 1005 | # WijResult0=((cF*E01+cG*N01)**2)/cC - numpy.log(W01 / numpy.sqrt(numpy.pi/cC)) |
|
971 | 1006 | # WijResult1=((cF*E02+cG*N02)**2)/cC - numpy.log(W02 / numpy.sqrt(numpy.pi/cC)) |
|
972 | 1007 | # WijResult2=((cF*E12+cG*N12)**2)/cC - numpy.log(W12 / numpy.sqrt(numpy.pi/cC)) |
|
973 | # | |
|
1008 | # | |
|
974 | 1009 | # WijResults=numpy.array([WijResult0, WijResult1, WijResult2]) |
|
975 | # | |
|
976 |
# WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ]) |
|
|
1010 | # | |
|
1011 | # WijEijNij=numpy.array([ [E01**2, N01**2, 2*E01*N01] , [E02**2, N02**2, 2*E02*N02] , [E12**2, N12**2, 2*E12*N12] ]) | |
|
977 | 1012 | # (cA,cB,cH) = numpy.linalg.solve(WijEijNij, WijResults) |
|
978 | # | |
|
1013 | # | |
|
979 | 1014 | # VxVy=numpy.array([[cA,cH],[cH,cB]]) |
|
980 | # | |
|
1015 | # | |
|
981 | 1016 | # VxVyResults=numpy.array([-cF,-cG]) |
|
982 | 1017 | # (Vx,Vy) = numpy.linalg.solve(VxVy, VxVyResults) |
|
983 | 1018 | # Vzon = Vy |
|
984 | 1019 | # Vmer = Vx |
|
985 | 1020 | # Vmag=numpy.sqrt(Vzon**2+Vmer**2) |
|
986 | 1021 | # Vang=numpy.arctan2(Vmer,Vzon) |
|
987 | # | |
|
1022 | # | |
|
988 | 1023 | # if abs(Vy)<100 and abs(Vy)> 0.: |
|
989 | 1024 | # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, Vzon) #Vmag |
|
990 | 1025 | # #print 'Vmag',Vmag |
|
991 | 1026 | # else: |
|
992 | 1027 | # self.dataOut.velocityX=numpy.append(self.dataOut.velocityX, NaN) |
|
993 | # | |
|
1028 | # | |
|
994 | 1029 | # if abs(Vx)<100 and abs(Vx) > 0.: |
|
995 | 1030 | # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, Vmer) #Vang |
|
996 |
# #print 'Vang',Vang |
|
|
1031 | # #print 'Vang',Vang | |
|
997 | 1032 | # else: |
|
998 | 1033 | # self.dataOut.velocityY=numpy.append(self.dataOut.velocityY, NaN) |
|
999 | # | |
|
1034 | # | |
|
1000 | 1035 | # if abs(GaussCenter)<2: |
|
1001 | 1036 | # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, xFrec[Vpos]) |
|
1002 | # | |
|
1037 | # | |
|
1003 | 1038 | # else: |
|
1004 | 1039 | # self.dataOut.velocityV=numpy.append(self.dataOut.velocityV, NaN) |
|
1005 | # | |
|
1006 | # | |
|
1040 | # | |
|
1041 | # | |
|
1007 | 1042 | # # print '********************************************' |
|
1008 | 1043 | # # print 'HalfWidth ', HalfWidth |
|
1009 | 1044 | # # print 'Maximun ', Maximun |
@@ -1033,25 +1068,25 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
1033 | 1068 | # # print 'PhaseSlope ',PhaseSlope[2] |
|
1034 | 1069 | # # print '********************************************' |
|
1035 | 1070 | # #print 'data_output',shape(self.dataOut.velocityX), shape(self.dataOut.velocityY) |
|
1036 | # | |
|
1071 | # | |
|
1037 | 1072 | # #print 'self.dataOut.velocityX', len(self.dataOut.velocityX) |
|
1038 | 1073 | # #print 'self.dataOut.velocityY', len(self.dataOut.velocityY) |
|
1039 | 1074 | # #print 'self.dataOut.velocityV', self.dataOut.velocityV |
|
1040 | # | |
|
1075 | # | |
|
1041 | 1076 | # self.data_output[0]=numpy.array(self.dataOut.velocityX) |
|
1042 | 1077 | # self.data_output[1]=numpy.array(self.dataOut.velocityY) |
|
1043 | 1078 | # self.data_output[2]=numpy.array(self.dataOut.velocityV) |
|
1044 | # | |
|
1079 | # | |
|
1045 | 1080 | # prin= self.data_output[0][~numpy.isnan(self.data_output[0])] |
|
1046 | 1081 | # print ' ' |
|
1047 |
# print 'VmagAverage',numpy.mean(prin) |
|
|
1082 | # print 'VmagAverage',numpy.mean(prin) | |
|
1048 | 1083 | # print ' ' |
|
1049 | 1084 | # # plt.figure(5) |
|
1050 | 1085 | # # plt.subplot(211) |
|
1051 | 1086 | # # plt.plot(self.dataOut.velocityX,'yo:') |
|
1052 | 1087 | # # plt.subplot(212) |
|
1053 | 1088 | # # plt.plot(self.dataOut.velocityY,'yo:') |
|
1054 | # | |
|
1089 | # | |
|
1055 | 1090 | # # plt.figure(1) |
|
1056 | 1091 | # # # plt.subplot(121) |
|
1057 | 1092 | # # # plt.plot(xFrec,ySamples[0],'k',label='Ch0') |
@@ -1060,7 +1095,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
1060 | 1095 | # # # plt.plot(xFrec,FitGauss,'yo:',label='fit') |
|
1061 | 1096 | # # # plt.legend() |
|
1062 | 1097 | # # plt.title('DATOS A ALTURA DE 2850 METROS') |
|
1063 | # # | |
|
1098 | # # | |
|
1064 | 1099 | # # plt.xlabel('Frecuencia (KHz)') |
|
1065 | 1100 | # # plt.ylabel('Magnitud') |
|
1066 | 1101 | # # # plt.subplot(122) |
@@ -1070,7 +1105,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
1070 | 1105 | # # plt.plot(xFrec,FactNorm) |
|
1071 | 1106 | # # plt.axis([-4, 4, 0, 0.15]) |
|
1072 | 1107 | # # # plt.xlabel('SelfSpectra KHz') |
|
1073 |
# # |
|
|
1108 | # # | |
|
1074 | 1109 | # # plt.figure(10) |
|
1075 | 1110 | # # # plt.subplot(121) |
|
1076 | 1111 | # # plt.plot(xFrec,ySamples[0],'b',label='Ch0') |
@@ -1079,7 +1114,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
1079 | 1114 | # # # plt.plot(xFrec,FitGauss,'yo:',label='fit') |
|
1080 | 1115 | # # plt.legend() |
|
1081 | 1116 | # # plt.title('SELFSPECTRA EN CANALES') |
|
1082 | # # | |
|
1117 | # # | |
|
1083 | 1118 | # # plt.xlabel('Frecuencia (KHz)') |
|
1084 | 1119 | # # plt.ylabel('Magnitud') |
|
1085 | 1120 | # # # plt.subplot(122) |
@@ -1089,19 +1124,19 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
1089 | 1124 | # # # plt.plot(xFrec,FactNorm) |
|
1090 | 1125 | # # # plt.axis([-4, 4, 0, 0.15]) |
|
1091 | 1126 | # # # plt.xlabel('SelfSpectra KHz') |
|
1092 |
# # |
|
|
1127 | # # | |
|
1093 | 1128 | # # plt.figure(9) |
|
1094 | # # | |
|
1095 | # # | |
|
1129 | # # | |
|
1130 | # # | |
|
1096 | 1131 | # # plt.title('DATOS SUAVIZADOS') |
|
1097 | 1132 | # # plt.xlabel('Frecuencia (KHz)') |
|
1098 | 1133 | # # plt.ylabel('Magnitud') |
|
1099 | 1134 | # # plt.plot(xFrec,SmoothSPC,'g') |
|
1100 | # # | |
|
1135 | # # | |
|
1101 | 1136 | # # #plt.plot(xFrec,FactNorm) |
|
1102 | 1137 | # # plt.axis([-4, 4, 0, 0.15]) |
|
1103 | 1138 | # # # plt.xlabel('SelfSpectra KHz') |
|
1104 | # # # | |
|
1139 | # # # | |
|
1105 | 1140 | # # plt.figure(2) |
|
1106 | 1141 | # # # #plt.subplot(121) |
|
1107 | 1142 | # # plt.plot(xFrec,yMean,'r',label='Mean SelfSpectra') |
@@ -1115,7 +1150,7 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
1115 | 1150 | # # plt.xlabel('Frecuencia (KHz)') |
|
1116 | 1151 | # # plt.ylabel('Magnitud') |
|
1117 | 1152 | # # plt.legend() |
|
1118 | # # # | |
|
1153 | # # # | |
|
1119 | 1154 | # # # plt.figure(3) |
|
1120 | 1155 | # # # plt.subplot(311) |
|
1121 | 1156 | # # # #plt.plot(xFrec,phase[0]) |
@@ -1125,30 +1160,23 class BLTRSpectraReader (ProcessingUnit, FileHeaderBLTR, RecordHeaderBLTR, JRODa | |||
|
1125 | 1160 | # # # plt.subplot(313) |
|
1126 | 1161 | # # # plt.plot(xFrec,phase[2],'g') |
|
1127 | 1162 | # # # #plt.plot(xFrec,phase[2]) |
|
1128 | # # # | |
|
1163 | # # # | |
|
1129 | 1164 | # # # plt.figure(4) |
|
1130 | # # # | |
|
1165 | # # # | |
|
1131 | 1166 | # # # plt.plot(xSamples,coherence[0],'b') |
|
1132 | 1167 | # # # plt.plot(xSamples,coherence[1],'r') |
|
1133 | 1168 | # # # plt.plot(xSamples,coherence[2],'g') |
|
1134 | 1169 | # # plt.show() |
|
1135 | # # # | |
|
1170 | # # # | |
|
1136 | 1171 | # # # plt.clf() |
|
1137 | 1172 | # # # plt.cla() |
|
1138 |
# # # plt.close() |
|
|
1139 | # | |
|
1140 |
# print ' ' |
|
|
1141 | ||
|
1142 | ||
|
1143 | ||
|
1144 | self.BlockCounter+=2 | |
|
1145 | ||
|
1173 | # # # plt.close() | |
|
1174 | # | |
|
1175 | # print ' ' | |
|
1176 | ||
|
1177 | self.BlockCounter += 2 | |
|
1178 | ||
|
1146 | 1179 | else: |
|
1147 |
self.fileSelector+=1 |
|
|
1148 | self.BlockCounter=0 | |
|
1180 | self.fileSelector += 1 | |
|
1181 | self.BlockCounter = 0 | |
|
1149 | 1182 | print "Next File" |
|
1150 | ||
|
1151 | ||
|
1152 | ||
|
1153 | ||
|
1154 |
This diff has been collapsed as it changes many lines, (1027 lines changed) Show them Hide them | |||
@@ -1,4 +1,5 | |||
|
1 |
import os |
|
|
1 | import os | |
|
2 | import sys | |
|
2 | 3 | import glob |
|
3 | 4 | import fnmatch |
|
4 | 5 | import datetime |
@@ -6,11 +7,9 import time | |||
|
6 | 7 | import re |
|
7 | 8 | import h5py |
|
8 | 9 | import numpy |
|
9 | import matplotlib.pyplot as plt | |
|
10 | 10 | |
|
11 | import pylab as plb | |
|
12 | 11 | from scipy.optimize import curve_fit |
|
13 | from scipy import asarray as ar,exp | |
|
12 | from scipy import asarray as ar, exp | |
|
14 | 13 | from scipy import stats |
|
15 | 14 | |
|
16 | 15 | from numpy.ma.core import getdata |
@@ -30,152 +29,168 from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |||
|
30 | 29 | from numpy import imag, shape, NaN, empty |
|
31 | 30 | |
|
32 | 31 | |
|
33 | ||
|
34 | 32 | class Header(object): |
|
35 | ||
|
33 | ||
|
36 | 34 | def __init__(self): |
|
37 | 35 | raise NotImplementedError |
|
38 | ||
|
39 | ||
|
36 | ||
|
40 | 37 | def read(self): |
|
41 | ||
|
38 | ||
|
42 | 39 | raise NotImplementedError |
|
43 | ||
|
40 | ||
|
44 | 41 | def write(self): |
|
45 | ||
|
42 | ||
|
46 | 43 | raise NotImplementedError |
|
47 | ||
|
44 | ||
|
48 | 45 | def printInfo(self): |
|
49 | ||
|
50 | message = "#"*50 + "\n" | |
|
46 | ||
|
47 | message = "#" * 50 + "\n" | |
|
51 | 48 | message += self.__class__.__name__.upper() + "\n" |
|
52 | message += "#"*50 + "\n" | |
|
53 | ||
|
49 | message += "#" * 50 + "\n" | |
|
50 | ||
|
54 | 51 | keyList = self.__dict__.keys() |
|
55 | 52 | keyList.sort() |
|
56 | ||
|
53 | ||
|
57 | 54 | for key in keyList: |
|
58 | message += "%s = %s" %(key, self.__dict__[key]) + "\n" | |
|
59 | ||
|
55 | message += "%s = %s" % (key, self.__dict__[key]) + "\n" | |
|
56 | ||
|
60 | 57 | if "size" not in keyList: |
|
61 | 58 | attr = getattr(self, "size") |
|
62 | ||
|
59 | ||
|
63 | 60 | if attr: |
|
64 | message += "%s = %s" %("size", attr) + "\n" | |
|
65 | ||
|
66 | #print message | |
|
67 | ||
|
68 | ||
|
69 |
FILE_HEADER = numpy.dtype([ |
|
|
70 |
('Hname','a32'), |
|
|
71 |
|
|
|
72 |
('H |
|
|
73 | ('Hplace',numpy.str_,128), #Place where the measurements was carried out | |
|
74 |
('H |
|
|
75 | ('Hdummy',numpy.str_,512), #Reserved space | |
|
76 |
|
|
|
77 | ('Msign',numpy.str_,4), #Main chunk signature FZKF or NUIG | |
|
78 | ('MsizeData','<i4'), #Size of data block main chunk | |
|
79 | #Processing DSP parameters 36bytes | |
|
80 | ('PPARsign',numpy.str_,4), #PPAR signature | |
|
81 | ('PPARsize','<i4'), #PPAR size of block | |
|
82 | ('PPARprf','<i4'), #Pulse repetition frequency | |
|
83 |
(' |
|
|
84 | ('PPARsft','<i4'), #FFT length | |
|
85 | ('PPARavc','<i4'), #Number of spectral (in-coherent) averages | |
|
86 |
('PPAR |
|
|
87 |
('PPAR |
|
|
88 | ('PPARpol','<i4'), #switch on/off polarimetric measurements. Should be 1. | |
|
89 | #Service DSP parameters 112bytes | |
|
90 | ('SPARatt','<i4'), #STC attenuation on the lowest ranges on/off | |
|
91 |
(' |
|
|
92 | ('SPARaddGain0','<f4'), #OBSOLETE | |
|
93 |
(' |
|
|
94 | ('SPARwnd','<i4'), #Debug only. It normal mode it is 0. | |
|
95 | ('SPARpos','<i4'), #Delay between sync pulse and tx pulse for phase corr, ns | |
|
96 | ('SPARadd','<i4'), #"add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal. | |
|
97 | ('SPARlen','<i4'), #Time for measuring txn pulse phase. OBSOLETE | |
|
98 | ('SPARcal','<i4'), #OBSOLETE | |
|
99 | ('SPARnos','<i4'), #OBSOLETE | |
|
100 |
('SPAR |
|
|
101 |
('SPAR |
|
|
102 |
('SPAR |
|
|
103 |
('SPAR |
|
|
104 | ('SPARosc','<i4'), #flag Oscillosgram mode | |
|
105 |
('SPAR |
|
|
106 | ('SPARcor','<i4'), #OBSOLETE | |
|
107 |
('SPARo |
|
|
108 | ('SPARhsn','<i4'), #Hildebrand div noise detection on noise gate | |
|
109 | ('SPARhsa','<f4'), #Hildebrand div noise detection on all gates | |
|
110 | ('SPARcalibPow_M','<f4'), #OBSOLETE | |
|
111 |
('SPAR |
|
|
112 |
('SPARcal |
|
|
113 |
('SPAR |
|
|
114 | ('SPARrawGate1','<i4'), #Lowest range gate for spectra saving Raw_Gate1 >=5 | |
|
115 | ('SPARrawGate2','<i4'), #Number of range gates with atmospheric signal | |
|
116 |
('SPAR |
|
|
117 | ('SPARprc','<i4'),]) #flag - Moment estimation switched on/off | |
|
118 | ||
|
119 | ||
|
120 | ||
|
61 | message += "%s = %s" % ("size", attr) + "\n" | |
|
62 | ||
|
63 | # print message | |
|
64 | ||
|
65 | ||
|
66 | FILE_HEADER = numpy.dtype([ # HEADER 1024bytes | |
|
67 | ('Hname', 'a32'), # Original file name | |
|
68 | # Date and time when the file was created | |
|
69 | ('Htime', numpy.str_, 32), | |
|
70 | # Name of operator who created the file | |
|
71 | ('Hoper', numpy.str_, 64), | |
|
72 | # Place where the measurements was carried out | |
|
73 | ('Hplace', numpy.str_, 128), | |
|
74 | # Description of measurements | |
|
75 | ('Hdescr', numpy.str_, 256), | |
|
76 | ('Hdummy', numpy.str_, 512), # Reserved space | |
|
77 | # Main chunk 8bytes | |
|
78 | # Main chunk signature FZKF or NUIG | |
|
79 | ('Msign', numpy.str_, 4), | |
|
80 | ('MsizeData', '<i4'), # Size of data block main chunk | |
|
81 | # Processing DSP parameters 36bytes | |
|
82 | ('PPARsign', numpy.str_, 4), # PPAR signature | |
|
83 | ('PPARsize', '<i4'), # PPAR size of block | |
|
84 | ('PPARprf', '<i4'), # Pulse repetition frequency | |
|
85 | ('PPARpdr', '<i4'), # Pulse duration | |
|
86 | ('PPARsft', '<i4'), # FFT length | |
|
87 | # Number of spectral (in-coherent) averages | |
|
88 | ('PPARavc', '<i4'), | |
|
89 | # Number of lowest range gate for moment estimation | |
|
90 | ('PPARihp', '<i4'), | |
|
91 | # Count for gates for moment estimation | |
|
92 | ('PPARchg', '<i4'), | |
|
93 | # switch on/off polarimetric measurements. Should be 1. | |
|
94 | ('PPARpol', '<i4'), | |
|
95 | # Service DSP parameters 112bytes | |
|
96 | # STC attenuation on the lowest ranges on/off | |
|
97 | ('SPARatt', '<i4'), | |
|
98 | ('SPARtx', '<i4'), # OBSOLETE | |
|
99 | ('SPARaddGain0', '<f4'), # OBSOLETE | |
|
100 | ('SPARaddGain1', '<f4'), # OBSOLETE | |
|
101 | # Debug only. It normal mode it is 0. | |
|
102 | ('SPARwnd', '<i4'), | |
|
103 | # Delay between sync pulse and tx pulse for phase corr, ns | |
|
104 | ('SPARpos', '<i4'), | |
|
105 | # "add to pulse" to compensate for delay between the leading edge of driver pulse and envelope of the RF signal. | |
|
106 | ('SPARadd', '<i4'), | |
|
107 | # Time for measuring txn pulse phase. OBSOLETE | |
|
108 | ('SPARlen', '<i4'), | |
|
109 | ('SPARcal', '<i4'), # OBSOLETE | |
|
110 | ('SPARnos', '<i4'), # OBSOLETE | |
|
111 | ('SPARof0', '<i4'), # detection threshold | |
|
112 | ('SPARof1', '<i4'), # OBSOLETE | |
|
113 | ('SPARswt', '<i4'), # 2nd moment estimation threshold | |
|
114 | ('SPARsum', '<i4'), # OBSOLETE | |
|
115 | ('SPARosc', '<i4'), # flag Oscillosgram mode | |
|
116 | ('SPARtst', '<i4'), # OBSOLETE | |
|
117 | ('SPARcor', '<i4'), # OBSOLETE | |
|
118 | ('SPARofs', '<i4'), # OBSOLETE | |
|
119 | # Hildebrand div noise detection on noise gate | |
|
120 | ('SPARhsn', '<i4'), | |
|
121 | # Hildebrand div noise detection on all gates | |
|
122 | ('SPARhsa', '<f4'), | |
|
123 | ('SPARcalibPow_M', '<f4'), # OBSOLETE | |
|
124 | ('SPARcalibSNR_M', '<f4'), # OBSOLETE | |
|
125 | ('SPARcalibPow_S', '<f4'), # OBSOLETE | |
|
126 | ('SPARcalibSNR_S', '<f4'), # OBSOLETE | |
|
127 | # Lowest range gate for spectra saving Raw_Gate1 >=5 | |
|
128 | ('SPARrawGate1', '<i4'), | |
|
129 | # Number of range gates with atmospheric signal | |
|
130 | ('SPARrawGate2', '<i4'), | |
|
131 | # flag - IQ or spectra saving on/off | |
|
132 | ('SPARraw', '<i4'), | |
|
133 | ('SPARprc', '<i4'), ]) # flag - Moment estimation switched on/off | |
|
134 | ||
|
135 | ||
|
121 | 136 | class FileHeaderMIRA35c(Header): |
|
122 | ||
|
137 | ||
|
123 | 138 | def __init__(self): |
|
124 | ||
|
125 |
self.Hname= None |
|
|
126 | self.Htime= None | |
|
127 | self.Hoper= None | |
|
128 | self.Hplace= None | |
|
129 | self.Hdescr= None | |
|
130 | self.Hdummy= None | |
|
131 | ||
|
132 | self.Msign=None | |
|
133 | self.MsizeData=None | |
|
134 | ||
|
135 | self.PPARsign=None | |
|
136 | self.PPARsize=None | |
|
137 | self.PPARprf=None | |
|
138 | self.PPARpdr=None | |
|
139 | self.PPARsft=None | |
|
140 | self.PPARavc=None | |
|
141 | self.PPARihp=None | |
|
142 | self.PPARchg=None | |
|
143 | self.PPARpol=None | |
|
144 | #Service DSP parameters | |
|
145 | self.SPARatt=None | |
|
146 | self.SPARtx=None | |
|
147 | self.SPARaddGain0=None | |
|
148 | self.SPARaddGain1=None | |
|
149 | self.SPARwnd=None | |
|
150 | self.SPARpos=None | |
|
151 | self.SPARadd=None | |
|
152 | self.SPARlen=None | |
|
153 | self.SPARcal=None | |
|
154 | self.SPARnos=None | |
|
155 | self.SPARof0=None | |
|
156 | self.SPARof1=None | |
|
157 | self.SPARswt=None | |
|
158 | self.SPARsum=None | |
|
159 | self.SPARosc=None | |
|
160 | self.SPARtst=None | |
|
161 | self.SPARcor=None | |
|
162 | self.SPARofs=None | |
|
163 | self.SPARhsn=None | |
|
164 | self.SPARhsa=None | |
|
165 | self.SPARcalibPow_M=None | |
|
166 | self.SPARcalibSNR_M=None | |
|
167 | self.SPARcalibPow_S=None | |
|
168 | self.SPARcalibSNR_S=None | |
|
169 | self.SPARrawGate1=None | |
|
170 | self.SPARrawGate2=None | |
|
171 | self.SPARraw=None | |
|
172 |
self.SPARprc=None |
|
|
173 | ||
|
174 | self.FHsize=1180 | |
|
175 | ||
|
139 | ||
|
140 | self.Hname = None | |
|
141 | self.Htime = None | |
|
142 | self.Hoper = None | |
|
143 | self.Hplace = None | |
|
144 | self.Hdescr = None | |
|
145 | self.Hdummy = None | |
|
146 | ||
|
147 | self.Msign = None | |
|
148 | self.MsizeData = None | |
|
149 | ||
|
150 | self.PPARsign = None | |
|
151 | self.PPARsize = None | |
|
152 | self.PPARprf = None | |
|
153 | self.PPARpdr = None | |
|
154 | self.PPARsft = None | |
|
155 | self.PPARavc = None | |
|
156 | self.PPARihp = None | |
|
157 | self.PPARchg = None | |
|
158 | self.PPARpol = None | |
|
159 | # Service DSP parameters | |
|
160 | self.SPARatt = None | |
|
161 | self.SPARtx = None | |
|
162 | self.SPARaddGain0 = None | |
|
163 | self.SPARaddGain1 = None | |
|
164 | self.SPARwnd = None | |
|
165 | self.SPARpos = None | |
|
166 | self.SPARadd = None | |
|
167 | self.SPARlen = None | |
|
168 | self.SPARcal = None | |
|
169 | self.SPARnos = None | |
|
170 | self.SPARof0 = None | |
|
171 | self.SPARof1 = None | |
|
172 | self.SPARswt = None | |
|
173 | self.SPARsum = None | |
|
174 | self.SPARosc = None | |
|
175 | self.SPARtst = None | |
|
176 | self.SPARcor = None | |
|
177 | self.SPARofs = None | |
|
178 | self.SPARhsn = None | |
|
179 | self.SPARhsa = None | |
|
180 | self.SPARcalibPow_M = None | |
|
181 | self.SPARcalibSNR_M = None | |
|
182 | self.SPARcalibPow_S = None | |
|
183 | self.SPARcalibSNR_S = None | |
|
184 | self.SPARrawGate1 = None | |
|
185 | self.SPARrawGate2 = None | |
|
186 | self.SPARraw = None | |
|
187 | self.SPARprc = None | |
|
188 | ||
|
189 | self.FHsize = 1180 | |
|
190 | ||
|
176 | 191 | def FHread(self, fp): |
|
177 | ||
|
178 | header = numpy.fromfile(fp, FILE_HEADER,1) | |
|
192 | ||
|
193 | header = numpy.fromfile(fp, FILE_HEADER, 1) | |
|
179 | 194 | ''' numpy.fromfile(file, dtype, count, sep='') |
|
180 | 195 | file : file or str |
|
181 | 196 | Open file object or filename. |
@@ -194,85 +209,83 class FileHeaderMIRA35c(Header): | |||
|
194 | 209 | at least one whitespace. |
|
195 | 210 | |
|
196 | 211 | ''' |
|
197 | ||
|
198 | ||
|
199 |
self.H |
|
|
200 |
self.H |
|
|
201 |
self.H |
|
|
202 |
self.H |
|
|
203 |
self.Hd |
|
|
204 | self.Hdummy= str(header['Hdummy'][0]) | |
|
205 | #1024 | |
|
206 | ||
|
207 |
self.Msi |
|
|
208 | self.MsizeData=header['MsizeData'][0] | |
|
209 | #8 | |
|
210 | ||
|
211 |
self.PPARsi |
|
|
212 |
self.PPAR |
|
|
213 |
self.PPARp |
|
|
214 |
self.PPAR |
|
|
215 |
self.PPAR |
|
|
216 |
self.PPAR |
|
|
217 |
self.PPAR |
|
|
218 |
self.PPAR |
|
|
219 | self.PPARpol=header['PPARpol'][0] | |
|
220 | #Service DSP parameters | |
|
221 | #36 | |
|
222 | ||
|
223 |
self.SPAR |
|
|
224 |
self.SPAR |
|
|
225 |
self.SPARaddGain |
|
|
226 |
self.SPAR |
|
|
227 |
self.SPAR |
|
|
228 |
self.SPAR |
|
|
229 |
self.SPAR |
|
|
230 |
self.SPAR |
|
|
231 |
self.SPAR |
|
|
232 |
self.SPAR |
|
|
233 |
self.SPARof |
|
|
234 |
self.SPAR |
|
|
235 |
self.SPARs |
|
|
236 |
self.SPAR |
|
|
237 |
self.SPAR |
|
|
238 |
self.SPAR |
|
|
239 |
self.SPAR |
|
|
240 |
self.SPAR |
|
|
241 |
self.SPARhs |
|
|
242 |
self.SPAR |
|
|
243 |
self.SPARcalib |
|
|
244 |
self.SPARcalib |
|
|
245 |
self.SPARcalib |
|
|
246 |
self.SPAR |
|
|
247 |
self.SPARrawGate |
|
|
248 |
self.SPARraw |
|
|
249 |
self.SPAR |
|
|
250 | self.SPARprc=header['SPARprc'][0] | |
|
251 |
# |
|
|
252 | #1180 | |
|
253 | #print 'Pointer fp header', fp.tell() | |
|
254 |
#print ' |
|
|
255 |
#print |
|
|
256 | #print self.SPARrawGate2 - self.SPARrawGate1 | |
|
257 | ||
|
258 |
#print ' |
|
|
259 |
#print |
|
|
260 | #print self.Hname | |
|
261 | ||
|
262 |
#print ' |
|
|
263 |
#print |
|
|
264 | #print self.Msign | |
|
265 | ||
|
212 | ||
|
213 | self.Hname = str(header['Hname'][0]) | |
|
214 | self.Htime = str(header['Htime'][0]) | |
|
215 | self.Hoper = str(header['Hoper'][0]) | |
|
216 | self.Hplace = str(header['Hplace'][0]) | |
|
217 | self.Hdescr = str(header['Hdescr'][0]) | |
|
218 | self.Hdummy = str(header['Hdummy'][0]) | |
|
219 | # 1024 | |
|
220 | ||
|
221 | self.Msign = str(header['Msign'][0]) | |
|
222 | self.MsizeData = header['MsizeData'][0] | |
|
223 | # 8 | |
|
224 | ||
|
225 | self.PPARsign = str(header['PPARsign'][0]) | |
|
226 | self.PPARsize = header['PPARsize'][0] | |
|
227 | self.PPARprf = header['PPARprf'][0] | |
|
228 | self.PPARpdr = header['PPARpdr'][0] | |
|
229 | self.PPARsft = header['PPARsft'][0] | |
|
230 | self.PPARavc = header['PPARavc'][0] | |
|
231 | self.PPARihp = header['PPARihp'][0] | |
|
232 | self.PPARchg = header['PPARchg'][0] | |
|
233 | self.PPARpol = header['PPARpol'][0] | |
|
234 | # Service DSP parameters | |
|
235 | # 36 | |
|
236 | ||
|
237 | self.SPARatt = header['SPARatt'][0] | |
|
238 | self.SPARtx = header['SPARtx'][0] | |
|
239 | self.SPARaddGain0 = header['SPARaddGain0'][0] | |
|
240 | self.SPARaddGain1 = header['SPARaddGain1'][0] | |
|
241 | self.SPARwnd = header['SPARwnd'][0] | |
|
242 | self.SPARpos = header['SPARpos'][0] | |
|
243 | self.SPARadd = header['SPARadd'][0] | |
|
244 | self.SPARlen = header['SPARlen'][0] | |
|
245 | self.SPARcal = header['SPARcal'][0] | |
|
246 | self.SPARnos = header['SPARnos'][0] | |
|
247 | self.SPARof0 = header['SPARof0'][0] | |
|
248 | self.SPARof1 = header['SPARof1'][0] | |
|
249 | self.SPARswt = header['SPARswt'][0] | |
|
250 | self.SPARsum = header['SPARsum'][0] | |
|
251 | self.SPARosc = header['SPARosc'][0] | |
|
252 | self.SPARtst = header['SPARtst'][0] | |
|
253 | self.SPARcor = header['SPARcor'][0] | |
|
254 | self.SPARofs = header['SPARofs'][0] | |
|
255 | self.SPARhsn = header['SPARhsn'][0] | |
|
256 | self.SPARhsa = header['SPARhsa'][0] | |
|
257 | self.SPARcalibPow_M = header['SPARcalibPow_M'][0] | |
|
258 | self.SPARcalibSNR_M = header['SPARcalibSNR_M'][0] | |
|
259 | self.SPARcalibPow_S = header['SPARcalibPow_S'][0] | |
|
260 | self.SPARcalibSNR_S = header['SPARcalibSNR_S'][0] | |
|
261 | self.SPARrawGate1 = header['SPARrawGate1'][0] | |
|
262 | self.SPARrawGate2 = header['SPARrawGate2'][0] | |
|
263 | self.SPARraw = header['SPARraw'][0] | |
|
264 | self.SPARprc = header['SPARprc'][0] | |
|
265 | # 112 | |
|
266 | # 1180 | |
|
267 | # print 'Pointer fp header', fp.tell() | |
|
268 | # print ' ' | |
|
269 | # print 'SPARrawGate' | |
|
270 | # print self.SPARrawGate2 - self.SPARrawGate1 | |
|
271 | ||
|
272 | # print ' ' | |
|
273 | # print 'Hname' | |
|
274 | # print self.Hname | |
|
275 | ||
|
276 | # print ' ' | |
|
277 | # print 'Msign' | |
|
278 | # print self.Msign | |
|
279 | ||
|
266 | 280 | def write(self, fp): |
|
267 | ||
|
281 | ||
|
268 | 282 | headerTuple = (self.Hname, |
|
269 | 283 | self.Htime, |
|
270 | 284 | self.Hoper, |
|
271 | 285 | self.Hplace, |
|
272 | 286 | self.Hdescr, |
|
273 | 287 | self.Hdummy) |
|
274 | ||
|
275 | ||
|
288 | ||
|
276 | 289 | header = numpy.array(headerTuple, FILE_HEADER) |
|
277 | 290 | # numpy.array(object, dtype=None, copy=True, order=None, subok=False, ndmin=0) |
|
278 | 291 | header.tofile(fp) |
@@ -290,72 +303,70 class FileHeaderMIRA35c(Header): | |||
|
290 | 303 | first converting it to the closest Python type, and then using "format" % item. |
|
291 | 304 | |
|
292 | 305 | ''' |
|
293 | ||
|
306 | ||
|
294 | 307 | return 1 |
|
295 | 308 | |
|
296 | SRVI_HEADER = numpy.dtype([ | |
|
297 | ('SignatureSRVI1',numpy.str_,4),# | |
|
298 |
('Si |
|
|
299 |
('DataBlock |
|
|
300 |
(' |
|
|
301 | ||
|
302 | class SRVIHeader(Header): | |
|
309 | ||
|
310 | SRVI_HEADER = numpy.dtype([ | |
|
311 | ('SignatureSRVI1', numpy.str_, 4), | |
|
312 | ('SizeOfDataBlock1', '<i4'), | |
|
313 | ('DataBlockTitleSRVI1', numpy.str_, 4), | |
|
314 | ('SizeOfSRVI1', '<i4'), ]) | |
|
315 | ||
|
316 | ||
|
317 | class SRVIHeader(Header): | |
|
303 | 318 | def __init__(self, SignatureSRVI1=0, SizeOfDataBlock1=0, DataBlockTitleSRVI1=0, SizeOfSRVI1=0): |
|
304 | ||
|
319 | ||
|
305 | 320 | self.SignatureSRVI1 = SignatureSRVI1 |
|
306 | 321 | self.SizeOfDataBlock1 = SizeOfDataBlock1 |
|
307 | 322 | self.DataBlockTitleSRVI1 = DataBlockTitleSRVI1 |
|
308 |
self.SizeOfSRVI1 = SizeOfSRVI1 |
|
|
309 | ||
|
310 | self.SRVIHsize=16 | |
|
311 | ||
|
312 |
def SRVIread(self, fp): |
|
|
313 | ||
|
314 | header = numpy.fromfile(fp, SRVI_HEADER,1) | |
|
323 | self.SizeOfSRVI1 = SizeOfSRVI1 | |
|
324 | ||
|
325 | self.SRVIHsize = 16 | |
|
326 | ||
|
327 | def SRVIread(self, fp): | |
|
328 | ||
|
329 | header = numpy.fromfile(fp, SRVI_HEADER, 1) | |
|
315 | 330 | |
|
316 | 331 | self.SignatureSRVI1 = str(header['SignatureSRVI1'][0]) |
|
317 | 332 | self.SizeOfDataBlock1 = header['SizeOfDataBlock1'][0] |
|
318 | 333 | self.DataBlockTitleSRVI1 = str(header['DataBlockTitleSRVI1'][0]) |
|
319 | 334 | self.SizeOfSRVI1 = header['SizeOfSRVI1'][0] |
|
320 | #16 | |
|
335 | # 16 | |
|
321 | 336 | print 'Pointer fp SRVIheader', fp.tell() |
|
322 | ||
|
323 | ||
|
324 | SRVI_STRUCTURE = numpy.dtype([ | |
|
325 | ('frame_cnt','<u4'),# | |
|
326 | ('time_t','<u4'), # | |
|
327 | ('tpow','<f4'), # | |
|
328 | ('npw1','<f4'), # | |
|
329 | ('npw2','<f4'), # | |
|
330 | ('cpw1','<f4'), # | |
|
331 | ('pcw2','<f4'), # | |
|
332 | ('ps_err','<u4'), # | |
|
333 | ('te_err','<u4'), # | |
|
334 | ('rc_err','<u4'), # | |
|
335 | ('grs1','<u4'), # | |
|
336 | ('grs2','<u4'), # | |
|
337 | ('azipos','<f4'), # | |
|
338 | ('azivel','<f4'), # | |
|
339 | ('elvpos','<f4'), # | |
|
340 | ('elvvel','<f4'), # | |
|
341 | ('northAngle','<f4'), # | |
|
342 | ('microsec','<u4'), # | |
|
343 | ('azisetvel','<f4'), # | |
|
344 | ('elvsetpos','<f4'), # | |
|
345 | ('RadarConst','<f4'),]) # | |
|
346 | 337 | |
|
347 | 338 | |
|
339 | SRVI_STRUCTURE = numpy.dtype([ | |
|
340 | ('frame_cnt', '<u4'), | |
|
341 | ('time_t', '<u4'), # | |
|
342 | ('tpow', '<f4'), # | |
|
343 | ('npw1', '<f4'), # | |
|
344 | ('npw2', '<f4'), # | |
|
345 | ('cpw1', '<f4'), # | |
|
346 | ('pcw2', '<f4'), # | |
|
347 | ('ps_err', '<u4'), # | |
|
348 | ('te_err', '<u4'), # | |
|
349 | ('rc_err', '<u4'), # | |
|
350 | ('grs1', '<u4'), # | |
|
351 | ('grs2', '<u4'), # | |
|
352 | ('azipos', '<f4'), # | |
|
353 | ('azivel', '<f4'), # | |
|
354 | ('elvpos', '<f4'), # | |
|
355 | ('elvvel', '<f4'), # | |
|
356 | ('northAngle', '<f4'), | |
|
357 | ('microsec', '<u4'), # | |
|
358 | ('azisetvel', '<f4'), # | |
|
359 | ('elvsetpos', '<f4'), # | |
|
360 | ('RadarConst', '<f4'), ]) # | |
|
348 | 361 | |
|
349 | 362 | |
|
350 | 363 | class RecordHeader(Header): |
|
351 | ||
|
352 | ||
|
353 | def __init__(self, frame_cnt=0, time_t= 0, tpow=0, npw1=0, npw2=0, | |
|
354 | cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0, | |
|
355 |
|
|
|
356 | microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0 , RecCounter=0, Off2StartNxtRec=0): | |
|
357 | ||
|
358 | ||
|
364 | ||
|
365 | def __init__(self, frame_cnt=0, time_t=0, tpow=0, npw1=0, npw2=0, | |
|
366 | cpw1=0, pcw2=0, ps_err=0, te_err=0, rc_err=0, grs1=0, | |
|
367 | grs2=0, azipos=0, azivel=0, elvpos=0, elvvel=0, northangle=0, | |
|
368 | microsec=0, azisetvel=0, elvsetpos=0, RadarConst=0, RecCounter=0, Off2StartNxtRec=0): | |
|
369 | ||
|
359 | 370 | self.frame_cnt = frame_cnt |
|
360 | 371 | self.dwell = time_t |
|
361 | 372 | self.tpow = tpow |
@@ -377,22 +388,22 class RecordHeader(Header): | |||
|
377 | 388 | self.azisetvel = azisetvel |
|
378 | 389 | self.elvsetpos = elvsetpos |
|
379 | 390 | self.RadarConst = RadarConst |
|
380 | self.RHsize=84 | |
|
391 | self.RHsize = 84 | |
|
381 | 392 | self.RecCounter = RecCounter |
|
382 | self.Off2StartNxtRec=Off2StartNxtRec | |
|
383 | ||
|
393 | self.Off2StartNxtRec = Off2StartNxtRec | |
|
394 | ||
|
384 | 395 | def RHread(self, fp): |
|
385 | ||
|
386 | #startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
387 | ||
|
396 | ||
|
397 | # startFp = open(fp,"rb") #The method tell() returns the current position of the file read/write pointer within the file. | |
|
398 | ||
|
388 | 399 | #OffRHeader= 1180 + self.RecCounter*(self.Off2StartNxtRec) |
|
389 | 400 | #startFp.seek(OffRHeader, os.SEEK_SET) |
|
390 | ||
|
391 | #print 'Posicion del bloque: ',OffRHeader | |
|
392 | ||
|
393 | header = numpy.fromfile(fp,SRVI_STRUCTURE,1) | |
|
394 | ||
|
395 |
self.frame_cnt = header['frame_cnt'][0] |
|
|
401 | ||
|
402 | # print 'Posicion del bloque: ',OffRHeader | |
|
403 | ||
|
404 | header = numpy.fromfile(fp, SRVI_STRUCTURE, 1) | |
|
405 | ||
|
406 | self.frame_cnt = header['frame_cnt'][0] | |
|
396 | 407 | self.time_t = header['time_t'][0] # |
|
397 | 408 | self.tpow = header['tpow'][0] # |
|
398 | 409 | self.npw1 = header['npw1'][0] # |
@@ -413,26 +424,26 class RecordHeader(Header): | |||
|
413 | 424 | self.azisetvel = header['azisetvel'][0] # |
|
414 | 425 | self.elvsetpos = header['elvsetpos'][0] # |
|
415 | 426 | self.RadarConst = header['RadarConst'][0] # |
|
416 | #84 | |
|
417 | ||
|
418 | #print 'Pointer fp RECheader', fp.tell() | |
|
419 | ||
|
427 | # 84 | |
|
428 | ||
|
429 | # print 'Pointer fp RECheader', fp.tell() | |
|
430 | ||
|
420 | 431 | #self.ipp= 0.5*(SPEED_OF_LIGHT/self.PRFhz) |
|
421 | ||
|
432 | ||
|
422 | 433 | #self.RHsize = 180+20*self.nChannels |
|
423 | 434 | #self.Datasize= self.nProfiles*self.nChannels*self.nHeights*2*4 |
|
424 | #print 'Datasize',self.Datasize | |
|
435 | # print 'Datasize',self.Datasize | |
|
425 | 436 | #endFp = self.OffsetStartHeader + self.RecCounter*self.Off2StartNxtRec |
|
426 | ||
|
437 | ||
|
427 | 438 | print '==============================================' |
|
428 | ||
|
439 | ||
|
429 | 440 | print '==============================================' |
|
430 | 441 | |
|
431 | ||
|
432 | 442 | return 1 |
|
433 | ||
|
434 | class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader): | |
|
435 | ||
|
443 | ||
|
444 | ||
|
445 | class MIRA35CReader (ProcessingUnit, FileHeaderMIRA35c, SRVIHeader, RecordHeader): | |
|
446 | ||
|
436 | 447 | path = None |
|
437 | 448 | startDate = None |
|
438 | 449 | endDate = None |
@@ -440,87 +451,84 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader): | |||
|
440 | 451 | endTime = None |
|
441 | 452 | walk = None |
|
442 | 453 | isConfig = False |
|
443 | ||
|
444 | ||
|
445 | fileList= None | |
|
446 | ||
|
447 | #metadata | |
|
448 | TimeZone= None | |
|
449 | Interval= None | |
|
450 | heightList= None | |
|
451 | ||
|
452 |
|
|
|
453 |
|
|
|
454 | utctime= None | |
|
455 | ||
|
456 | ||
|
457 | ||
|
458 | def __init__(self, **kwargs): | |
|
459 | ||
|
460 | #Eliminar de la base la herencia | |
|
454 | ||
|
455 | fileList = None | |
|
456 | ||
|
457 | # metadata | |
|
458 | TimeZone = None | |
|
459 | Interval = None | |
|
460 | heightList = None | |
|
461 | ||
|
462 | # data | |
|
463 | data = None | |
|
464 | utctime = None | |
|
465 | ||
|
466 | def __init__(self, **kwargs): | |
|
467 | ||
|
468 | # Eliminar de la base la herencia | |
|
461 | 469 | ProcessingUnit.__init__(self, **kwargs) |
|
462 | 470 | self.PointerReader = 0 |
|
463 | 471 | self.FileHeaderFlag = False |
|
464 | 472 | self.utc = None |
|
465 | 473 | self.ext = ".zspca" |
|
466 | 474 | self.optchar = "P" |
|
467 | self.fpFile=None | |
|
475 | self.fpFile = None | |
|
468 | 476 | self.fp = None |
|
469 | self.BlockCounter=0 | |
|
477 | self.BlockCounter = 0 | |
|
470 | 478 | self.dtype = None |
|
471 | 479 | self.fileSizeByHeader = None |
|
472 | 480 | self.filenameList = [] |
|
473 | 481 | self.fileSelector = 0 |
|
474 | self.Off2StartNxtRec=0 | |
|
475 | self.RecCounter=0 | |
|
482 | self.Off2StartNxtRec = 0 | |
|
483 | self.RecCounter = 0 | |
|
476 | 484 | self.flagNoMoreFiles = 0 |
|
477 | self.data_spc=None | |
|
478 | #self.data_cspc=None | |
|
479 | self.data_output=None | |
|
485 | self.data_spc = None | |
|
486 | # self.data_cspc=None | |
|
487 | self.data_output = None | |
|
480 | 488 | self.path = None |
|
481 | self.OffsetStartHeader=0 | |
|
482 | self.Off2StartData=0 | |
|
489 | self.OffsetStartHeader = 0 | |
|
490 | self.Off2StartData = 0 | |
|
483 | 491 | self.ipp = 0 |
|
484 | self.nFDTdataRecors=0 | |
|
492 | self.nFDTdataRecors = 0 | |
|
485 | 493 | self.blocksize = 0 |
|
486 | 494 | self.dataOut = Spectra() |
|
487 | self.profileIndex = 1 #Always | |
|
488 | self.dataOut.flagNoData=False | |
|
495 | self.profileIndex = 1 # Always | |
|
496 | self.dataOut.flagNoData = False | |
|
489 | 497 | self.dataOut.nRdPairs = 0 |
|
490 | 498 | self.dataOut.pairsList = [] |
|
491 | self.dataOut.data_spc=None | |
|
492 | ||
|
493 | self.dataOut.normFactor=1 | |
|
499 | self.dataOut.data_spc = None | |
|
500 | ||
|
501 | self.dataOut.normFactor = 1 | |
|
494 | 502 | self.nextfileflag = True |
|
495 | 503 | self.dataOut.RadarConst = 0 |
|
496 | 504 | self.dataOut.HSDV = [] |
|
497 | 505 | self.dataOut.NPW = [] |
|
498 | 506 | self.dataOut.COFA = [] |
|
499 | 507 | self.dataOut.noise = 0 |
|
500 | ||
|
501 | ||
|
508 | ||
|
502 | 509 | def Files2Read(self, fp): |
|
503 | 510 | ''' |
|
504 | 511 | Function that indicates the number of .fdt files that exist in the folder to be read. |
|
505 | 512 | It also creates an organized list with the names of the files to read. |
|
506 | 513 | ''' |
|
507 | #self.__checkPath() | |
|
508 | ||
|
509 |
|
|
|
510 | ListaData=sorted(ListaData) #Sort the list of files from least to largest by names | |
|
511 | nFiles=0 #File Counter | |
|
512 | FileList=[] #A list is created that will contain the .fdt files | |
|
513 | for IndexFile in ListaData : | |
|
514 | if '.zspca' in IndexFile and '.gz' not in IndexFile: | |
|
514 | # self.__checkPath() | |
|
515 | ||
|
516 | # Gets the list of files within the fp address | |
|
517 | ListaData = os.listdir(fp) | |
|
518 | # Sort the list of files from least to largest by names | |
|
519 | ListaData = sorted(ListaData) | |
|
520 | nFiles = 0 # File Counter | |
|
521 | FileList = [] # A list is created that will contain the .fdt files | |
|
522 | for IndexFile in ListaData: | |
|
523 | if '.zspca' in IndexFile and '.gz' not in IndexFile: | |
|
515 | 524 | FileList.append(IndexFile) |
|
516 | nFiles+=1 | |
|
517 | ||
|
518 | #print 'Files2Read' | |
|
519 |
#print 'Existen '+str(nFiles)+' archivos .fdt' |
|
|
520 | ||
|
521 | self.filenameList=FileList #List of files from least to largest by names | |
|
522 | ||
|
523 | ||
|
525 | nFiles += 1 | |
|
526 | ||
|
527 | # print 'Files2Read' | |
|
528 | # print 'Existen '+str(nFiles)+' archivos .fdt' | |
|
529 | ||
|
530 | self.filenameList = FileList # List of files from least to largest by names | |
|
531 | ||
|
524 | 532 | def run(self, **kwargs): |
|
525 | 533 | ''' |
|
526 | 534 | This method will be the one that will initiate the data entry, will be called constantly. |
@@ -530,274 +538,265 class MIRA35CReader (ProcessingUnit,FileHeaderMIRA35c,SRVIHeader,RecordHeader): | |||
|
530 | 538 | if not self.isConfig: |
|
531 | 539 | self.setup(**kwargs) |
|
532 | 540 | self.isConfig = True |
|
533 | ||
|
541 | ||
|
534 | 542 | self.getData() |
|
535 | ||
|
536 | ||
|
543 | ||
|
537 | 544 | def setup(self, path=None, |
|
538 |
|
|
|
539 |
|
|
|
540 |
|
|
|
541 |
|
|
|
542 |
|
|
|
543 |
|
|
|
544 |
|
|
|
545 |
|
|
|
546 |
|
|
|
547 | ||
|
545 | startDate=None, | |
|
546 | endDate=None, | |
|
547 | startTime=None, | |
|
548 | endTime=None, | |
|
549 | walk=True, | |
|
550 | timezone='utc', | |
|
551 | code=None, | |
|
552 | online=False, | |
|
553 | ReadMode=None, **kwargs): | |
|
554 | ||
|
548 | 555 | self.isConfig = True |
|
549 | ||
|
550 |
self.path=path |
|
|
551 | self.startDate=startDate | |
|
552 | self.endDate=endDate | |
|
553 |
self.startTime=startTime |
|
|
554 | self.endTime=endTime | |
|
555 |
self.walk=walk |
|
|
556 | #self.ReadMode=int(ReadMode) | |
|
557 | ||
|
556 | ||
|
557 | self.path = path | |
|
558 | self.startDate = startDate | |
|
559 | self.endDate = endDate | |
|
560 | self.startTime = startTime | |
|
561 | self.endTime = endTime | |
|
562 | self.walk = walk | |
|
563 | # self.ReadMode=int(ReadMode) | |
|
564 | ||
|
558 | 565 | pass |
|
559 | ||
|
560 | ||
|
566 | ||
|
561 | 567 | def getData(self): |
|
562 | 568 | ''' |
|
563 | 569 | Before starting this function, you should check that there is still an unread file, |
|
564 | 570 | If there are still blocks to read or if the data block is empty. |
|
565 | ||
|
571 | ||
|
566 | 572 | You should call the file "read". |
|
567 | ||
|
573 | ||
|
568 | 574 | ''' |
|
569 | ||
|
575 | ||
|
570 | 576 | if self.flagNoMoreFiles: |
|
571 | 577 | self.dataOut.flagNoData = True |
|
572 | 578 | print 'NoData se vuelve true' |
|
573 | 579 | return 0 |
|
574 | ||
|
575 | self.fp=self.path | |
|
580 | ||
|
581 | self.fp = self.path | |
|
576 | 582 | self.Files2Read(self.fp) |
|
577 | 583 | self.readFile(self.fp) |
|
578 | ||
|
579 | self.dataOut.data_spc = self.dataOut_spc#self.data_spc.copy() | |
|
584 | ||
|
585 | self.dataOut.data_spc = self.dataOut_spc # self.data_spc.copy() | |
|
580 | 586 | self.dataOut.RadarConst = self.RadarConst |
|
581 | self.dataOut.data_output=self.data_output | |
|
587 | self.dataOut.data_output = self.data_output | |
|
582 | 588 | self.dataOut.noise = self.dataOut.getNoise() |
|
583 | #print 'ACAAAAAA', self.dataOut.noise | |
|
584 | self.dataOut.data_spc = self.dataOut.data_spc+self.dataOut.noise | |
|
585 |
#print 'self.dataOut.noise',self.dataOut.noise |
|
|
586 | ||
|
587 | ||
|
589 | # print 'ACAAAAAA', self.dataOut.noise | |
|
590 | self.dataOut.data_spc = self.dataOut.data_spc + self.dataOut.noise | |
|
591 | # print 'self.dataOut.noise',self.dataOut.noise | |
|
592 | ||
|
588 | 593 | return self.dataOut.data_spc |
|
589 | ||
|
590 | ||
|
591 | def readFile(self,fp): | |
|
594 | ||
|
595 | def readFile(self, fp): | |
|
592 | 596 | ''' |
|
593 | 597 | You must indicate if you are reading in Online or Offline mode and load the |
|
594 | 598 | The parameters for this file reading mode. |
|
595 | ||
|
599 | ||
|
596 | 600 | Then you must do 2 actions: |
|
597 | ||
|
601 | ||
|
598 | 602 | 1. Get the BLTR FileHeader. |
|
599 | 603 | 2. Start reading the first block. |
|
600 | 604 | ''' |
|
601 | ||
|
602 | #The address of the folder is generated the name of the .fdt file that will be read | |
|
603 | print "File: ",self.fileSelector+1 | |
|
604 | ||
|
605 | ||
|
606 | # The address of the folder is generated the name of the .fdt file that will be read | |
|
607 | print "File: ", self.fileSelector + 1 | |
|
608 | ||
|
605 | 609 | if self.fileSelector < len(self.filenameList): |
|
606 | ||
|
607 |
self.fpFile=str(fp)+'/'+ |
|
|
608 | ||
|
609 | if self.nextfileflag==True: | |
|
610 | self.fp = open(self.fpFile,"rb") | |
|
611 |
self. |
|
|
612 | ||
|
610 | ||
|
611 | self.fpFile = str(fp) + '/' + \ | |
|
612 | str(self.filenameList[self.fileSelector]) | |
|
613 | ||
|
614 | if self.nextfileflag == True: | |
|
615 | self.fp = open(self.fpFile, "rb") | |
|
616 | self.nextfileflag == False | |
|
617 | ||
|
613 | 618 | '''HERE STARTING THE FILE READING''' |
|
614 | ||
|
615 | ||
|
619 | ||
|
616 | 620 | self.fheader = FileHeaderMIRA35c() |
|
617 |
self.fheader.FHread(self.fp) |
|
|
618 | ||
|
621 | self.fheader.FHread(self.fp) # Bltr FileHeader Reading | |
|
619 | 622 | |
|
620 | 623 | self.SPARrawGate1 = self.fheader.SPARrawGate1 |
|
621 | 624 | self.SPARrawGate2 = self.fheader.SPARrawGate2 |
|
622 | 625 | self.Num_Hei = self.SPARrawGate2 - self.SPARrawGate1 |
|
623 | 626 | self.Num_Bins = self.fheader.PPARsft |
|
624 | 627 | self.dataOut.nFFTPoints = self.fheader.PPARsft |
|
625 | ||
|
626 | ||
|
628 | ||
|
627 | 629 | self.Num_inCoh = self.fheader.PPARavc |
|
628 | 630 | self.dataOut.PRF = self.fheader.PPARprf |
|
629 | self.dataOut.frequency = 34.85*10**9 | |
|
630 | self.Lambda = SPEED_OF_LIGHT/self.dataOut.frequency | |
|
631 | self.dataOut.ippSeconds= 1./float(self.dataOut.PRF) | |
|
632 | ||
|
633 |
pulse_width = self.fheader.PPARpdr * 10**-9 |
|
|
631 | self.dataOut.frequency = 34.85 * 10**9 | |
|
632 | self.Lambda = SPEED_OF_LIGHT / self.dataOut.frequency | |
|
633 | self.dataOut.ippSeconds = 1. / float(self.dataOut.PRF) | |
|
634 | ||
|
635 | pulse_width = self.fheader.PPARpdr * 10**-9 | |
|
634 | 636 | self.__deltaHeigth = 0.5 * SPEED_OF_LIGHT * pulse_width |
|
635 | ||
|
636 |
self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins,2)) |
|
|
637 | ||
|
638 | self.data_spc = numpy.zeros((self.Num_Hei, self.Num_Bins, 2)) | |
|
637 | 639 | self.dataOut.HSDV = numpy.zeros((self.Num_Hei, 2)) |
|
638 | ||
|
640 | ||
|
639 | 641 | self.Ze = numpy.zeros(self.Num_Hei) |
|
640 | self.ETA = numpy.zeros(([2,self.Num_Hei])) | |
|
641 | ||
|
642 | ||
|
643 | ||
|
644 | self.readBlock() #Block reading | |
|
645 | ||
|
642 | self.ETA = numpy.zeros(([2, self.Num_Hei])) | |
|
643 | ||
|
644 | self.readBlock() # Block reading | |
|
645 | ||
|
646 | 646 | else: |
|
647 | 647 | print 'readFile FlagNoData becomes true' |
|
648 | self.flagNoMoreFiles=True | |
|
648 | self.flagNoMoreFiles = True | |
|
649 | 649 | self.dataOut.flagNoData = True |
|
650 | 650 | self.FileHeaderFlag == True |
|
651 |
return 0 |
|
|
652 | ||
|
653 | ||
|
654 | ||
|
655 | def readBlock(self): | |
|
651 | return 0 | |
|
652 | ||
|
653 | def readBlock(self): | |
|
656 | 654 | ''' |
|
657 | 655 | It should be checked if the block has data, if it is not passed to the next file. |
|
658 | ||
|
656 | ||
|
659 | 657 | Then the following is done: |
|
660 | ||
|
658 | ||
|
661 | 659 | 1. Read the RecordHeader |
|
662 | 660 | 2. Fill the buffer with the current block number. |
|
663 | ||
|
661 | ||
|
664 | 662 | ''' |
|
665 | ||
|
663 | ||
|
666 | 664 | if self.PointerReader > 1180: |
|
667 |
self.fp.seek(self.PointerReader |
|
|
665 | self.fp.seek(self.PointerReader, os.SEEK_SET) | |
|
668 | 666 | self.FirstPoint = self.PointerReader |
|
669 | ||
|
670 |
else |
|
|
667 | ||
|
668 | else: | |
|
671 | 669 | self.FirstPoint = 1180 |
|
672 | ||
|
673 | ||
|
674 | ||
|
670 | ||
|
675 | 671 | self.srviHeader = SRVIHeader() |
|
676 | ||
|
677 | self.srviHeader.SRVIread(self.fp) #Se obtiene la cabecera del SRVI | |
|
678 | ||
|
679 | self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque | |
|
680 | ||
|
672 | ||
|
673 | self.srviHeader.SRVIread(self.fp) # Se obtiene la cabecera del SRVI | |
|
674 | ||
|
675 | self.blocksize = self.srviHeader.SizeOfDataBlock1 # Se obtiene el tamao del bloque | |
|
676 | ||
|
681 | 677 | if self.blocksize == 148: |
|
682 | 678 | print 'blocksize == 148 bug' |
|
683 |
jump = numpy.fromfile(self.fp,[('jump',numpy.str_,140)] |
|
|
684 | ||
|
685 |
|
|
|
686 | ||
|
679 | jump = numpy.fromfile(self.fp, [('jump', numpy.str_, 140)], 1) | |
|
680 | ||
|
681 | # Se obtiene la cabecera del SRVI | |
|
682 | self.srviHeader.SRVIread(self.fp) | |
|
683 | ||
|
687 | 684 | if not self.srviHeader.SizeOfSRVI1: |
|
688 |
self.fileSelector+=1 |
|
|
689 | self.nextfileflag==True | |
|
685 | self.fileSelector += 1 | |
|
686 | self.nextfileflag == True | |
|
690 | 687 | self.FileHeaderFlag == True |
|
691 | ||
|
688 | ||
|
692 | 689 | self.recordheader = RecordHeader() |
|
693 | 690 | self.recordheader.RHread(self.fp) |
|
694 | 691 | self.RadarConst = self.recordheader.RadarConst |
|
695 | 692 | dwell = self.recordheader.time_t |
|
696 | 693 | npw1 = self.recordheader.npw1 |
|
697 | 694 | npw2 = self.recordheader.npw2 |
|
698 | ||
|
699 | ||
|
695 | ||
|
700 | 696 | self.dataOut.channelList = range(1) |
|
701 |
self.dataOut.nIncohInt = self.Num_inCoh |
|
|
697 | self.dataOut.nIncohInt = self.Num_inCoh | |
|
702 | 698 | self.dataOut.nProfiles = self.Num_Bins |
|
703 | 699 | self.dataOut.nCohInt = 1 |
|
704 | 700 | self.dataOut.windowOfFilter = 1 |
|
705 | 701 | self.dataOut.utctime = dwell |
|
706 | self.dataOut.timeZone=0 | |
|
707 | ||
|
702 | self.dataOut.timeZone = 0 | |
|
703 | ||
|
708 | 704 | self.dataOut.outputInterval = self.dataOut.getTimeInterval() |
|
709 |
self.dataOut.heightList = self.SPARrawGate1*self.__deltaHeigth + |
|
|
710 | ||
|
711 | ||
|
712 | ||
|
713 |
self.HSDV |
|
|
714 |
self. |
|
|
715 |
|
|
|
716 |
self.HSDV_Cx = numpy.fromfile( |
|
|
717 | ||
|
718 | self.COFAsign = numpy.fromfile( self.fp, [('COFA',numpy.str_,4)],1) | |
|
719 |
self. |
|
|
720 |
self.COFA |
|
|
721 |
self.COFA_C |
|
|
722 | ||
|
723 | self.ZSPCsign = numpy.fromfile(self.fp, [('ZSPCsign',numpy.str_,4)],1) | |
|
724 | self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC','<i4')],1) | |
|
725 | ||
|
726 | self.dataOut.HSDV[0]=self.HSDV_Co[:][0] | |
|
727 | self.dataOut.HSDV[1]=self.HSDV_Cx[:][0] | |
|
728 | ||
|
705 | self.dataOut.heightList = self.SPARrawGate1 * self.__deltaHeigth + \ | |
|
706 | numpy.array(range(self.Num_Hei)) * self.__deltaHeigth | |
|
707 | ||
|
708 | self.HSDVsign = numpy.fromfile(self.fp, [('HSDV', numpy.str_, 4)], 1) | |
|
709 | self.SizeHSDV = numpy.fromfile(self.fp, [('SizeHSDV', '<i4')], 1) | |
|
710 | self.HSDV_Co = numpy.fromfile( | |
|
711 | self.fp, [('HSDV_Co', '<f4')], self.Num_Hei) | |
|
712 | self.HSDV_Cx = numpy.fromfile( | |
|
713 | self.fp, [('HSDV_Cx', '<f4')], self.Num_Hei) | |
|
714 | ||
|
715 | self.COFAsign = numpy.fromfile(self.fp, [('COFA', numpy.str_, 4)], 1) | |
|
716 | self.SizeCOFA = numpy.fromfile(self.fp, [('SizeCOFA', '<i4')], 1) | |
|
717 | self.COFA_Co = numpy.fromfile( | |
|
718 | self.fp, [('COFA_Co', '<f4')], self.Num_Hei) | |
|
719 | self.COFA_Cx = numpy.fromfile( | |
|
720 | self.fp, [('COFA_Cx', '<f4')], self.Num_Hei) | |
|
721 | ||
|
722 | self.ZSPCsign = numpy.fromfile( | |
|
723 | self.fp, [('ZSPCsign', numpy.str_, 4)], 1) | |
|
724 | self.SizeZSPC = numpy.fromfile(self.fp, [('SizeZSPC', '<i4')], 1) | |
|
725 | ||
|
726 | self.dataOut.HSDV[0] = self.HSDV_Co[:][0] | |
|
727 | self.dataOut.HSDV[1] = self.HSDV_Cx[:][0] | |
|
728 | ||
|
729 | 729 | for irg in range(self.Num_Hei): |
|
730 |
|
|
|
731 | ||
|
730 | # Number of spectral sub pieces containing significant power | |
|
731 | nspc = numpy.fromfile(self.fp, [('nspc', 'int16')], 1)[0][0] | |
|
732 | ||
|
732 | 733 | for k in range(nspc): |
|
733 |
|
|
|
734 | nbins = numpy.fromfile(self.fp, [('nbins','int16')],1)[0][0] # Number of bins of the piece | |
|
735 | ||
|
736 | #Co_Channel | |
|
737 | jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0] # Spectrum piece to be normaliced | |
|
738 | jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0] # Maximun piece to be normaliced | |
|
739 | ||
|
740 | ||
|
741 | self.data_spc[irg,binIndex:binIndex+nbins,0] = self.data_spc[irg,binIndex:binIndex+nbins,0]+jbin/65530.*jmax | |
|
742 | ||
|
743 | #Cx_Channel | |
|
744 | jbin = numpy.fromfile(self.fp, [('jbin','uint16')],nbins)[0][0] | |
|
745 | jmax = numpy.fromfile(self.fp, [('jmax','float32')],1)[0][0] | |
|
746 | ||
|
747 | ||
|
748 | self.data_spc[irg,binIndex:binIndex+nbins,1] = self.data_spc[irg,binIndex:binIndex+nbins,1]+jbin/65530.*jmax | |
|
749 | ||
|
750 | for bin in range(self.Num_Bins): | |
|
751 | ||
|
752 | self.data_spc[:,bin,0] = self.data_spc[:,bin,0] - self.dataOut.HSDV[:,0] | |
|
753 | ||
|
754 | self.data_spc[:,bin,1] = self.data_spc[:,bin,1] - self.dataOut.HSDV[:,1] | |
|
755 | ||
|
756 | ||
|
734 | # Index of the spectral bin where the piece is beginning | |
|
735 | binIndex = numpy.fromfile( | |
|
736 | self.fp, [('binIndex', 'int16')], 1)[0][0] | |
|
737 | nbins = numpy.fromfile(self.fp, [('nbins', 'int16')], 1)[ | |
|
738 | 0][0] # Number of bins of the piece | |
|
739 | ||
|
740 | # Co_Channel | |
|
741 | jbin = numpy.fromfile(self.fp, [('jbin', 'uint16')], nbins)[ | |
|
742 | 0][0] # Spectrum piece to be normaliced | |
|
743 | jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[ | |
|
744 | 0][0] # Maximun piece to be normaliced | |
|
745 | ||
|
746 | self.data_spc[irg, binIndex:binIndex + nbins, 0] = self.data_spc[irg, | |
|
747 | binIndex:binIndex + nbins, 0] + jbin / 65530. * jmax | |
|
748 | ||
|
749 | # Cx_Channel | |
|
750 | jbin = numpy.fromfile( | |
|
751 | self.fp, [('jbin', 'uint16')], nbins)[0][0] | |
|
752 | jmax = numpy.fromfile(self.fp, [('jmax', 'float32')], 1)[0][0] | |
|
753 | ||
|
754 | self.data_spc[irg, binIndex:binIndex + nbins, 1] = self.data_spc[irg, | |
|
755 | binIndex:binIndex + nbins, 1] + jbin / 65530. * jmax | |
|
756 | ||
|
757 | for bin in range(self.Num_Bins): | |
|
758 | ||
|
759 | self.data_spc[:, bin, 0] = self.data_spc[:, | |
|
760 | bin, 0] - self.dataOut.HSDV[:, 0] | |
|
761 | ||
|
762 | self.data_spc[:, bin, 1] = self.data_spc[:, | |
|
763 | bin, 1] - self.dataOut.HSDV[:, 1] | |
|
764 | ||
|
757 | 765 | numpy.set_printoptions(threshold='nan') |
|
758 | ||
|
759 |
self.data_spc = numpy.where(self.data_spc > 0. |
|
|
760 | ||
|
761 |
self.dataOut.COFA = numpy.array([self.COFA_Co |
|
|
762 | ||
|
766 | ||
|
767 | self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0) | |
|
768 | ||
|
769 | self.dataOut.COFA = numpy.array([self.COFA_Co, self.COFA_Cx]) | |
|
770 | ||
|
763 | 771 | print ' ' |
|
764 | print 'SPC',numpy.shape(self.dataOut.data_spc) | |
|
765 | #print 'SPC',self.dataOut.data_spc | |
|
766 | ||
|
772 | print 'SPC', numpy.shape(self.dataOut.data_spc) | |
|
773 | # print 'SPC',self.dataOut.data_spc | |
|
774 | ||
|
767 | 775 | noinor1 = 713031680 |
|
768 | 776 | noinor2 = 30 |
|
769 | ||
|
770 | npw1 = 1#0**(npw1/10) * noinor1 * noinor2 | |
|
771 | npw2 = 1#0**(npw2/10) * noinor1 * noinor2 | |
|
777 | ||
|
778 | npw1 = 1 # 0**(npw1/10) * noinor1 * noinor2 | |
|
779 | npw2 = 1 # 0**(npw2/10) * noinor1 * noinor2 | |
|
772 | 780 | self.dataOut.NPW = numpy.array([npw1, npw2]) |
|
773 | ||
|
781 | ||
|
774 | 782 | print ' ' |
|
775 | ||
|
776 | self.data_spc = numpy.transpose(self.data_spc, (2,1,0)) | |
|
777 |
self.data_spc = numpy.fft.fftshift(self.data_spc, axes |
|
|
778 | ||
|
783 | ||
|
784 | self.data_spc = numpy.transpose(self.data_spc, (2, 1, 0)) | |
|
785 | self.data_spc = numpy.fft.fftshift(self.data_spc, axes=1) | |
|
786 | ||
|
779 | 787 | self.data_spc = numpy.fliplr(self.data_spc) |
|
780 | ||
|
781 |
self.data_spc = numpy.where(self.data_spc > 0. |
|
|
782 |
self.dataOut_spc= numpy.ones([1, self.Num_Bins |
|
|
783 | self.dataOut_spc[0,:,:] = self.data_spc[0,:,:] | |
|
784 | #print 'SHAPE', self.dataOut_spc.shape | |
|
785 | #For nyquist correction: | |
|
786 | #fix = 20 # ~3m/s | |
|
788 | ||
|
789 | self.data_spc = numpy.where(self.data_spc > 0., self.data_spc, 0) | |
|
790 | self.dataOut_spc = numpy.ones([1, self.Num_Bins, self.Num_Hei]) | |
|
791 | self.dataOut_spc[0, :, :] = self.data_spc[0, :, :] | |
|
792 | # print 'SHAPE', self.dataOut_spc.shape | |
|
793 | # For nyquist correction: | |
|
794 | # fix = 20 # ~3m/s | |
|
787 | 795 | #shift = self.Num_Bins/2 + fix |
|
788 | 796 | #self.data_spc = numpy.array([ self.data_spc[: , self.Num_Bins-shift+1: , :] , self.data_spc[: , 0:self.Num_Bins-shift , :]]) |
|
789 | ||
|
790 | ||
|
791 | ||
|
797 | ||
|
792 | 798 | '''Block Reading, the Block Data is received and Reshape is used to give it |
|
793 | 799 | shape. |
|
794 | 800 | ''' |
|
795 | ||
|
801 | ||
|
796 | 802 | self.PointerReader = self.fp.tell() |
|
797 | ||
|
798 | ||
|
799 | ||
|
800 | ||
|
801 | ||
|
802 | ||
|
803 | No newline at end of file |
@@ -11,7 +11,6 from schainpy.model.data.jroheaderIO import PROCFLAG, BasicHeader, SystemHeader, | |||
|
11 | 11 | from schainpy.model.data.jrodata import Spectra |
|
12 | 12 | |
|
13 | 13 | class SpectraReader(JRODataReader, ProcessingUnit): |
|
14 | ||
|
15 | 14 | """ |
|
16 | 15 | Esta clase permite leer datos de espectros desde archivos procesados (.pdata). La lectura |
|
17 | 16 | de los datos siempre se realiza por bloques. Los datos leidos (array de 3 dimensiones) |
@@ -21,7 +20,6 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
21 | 20 | paresCanalesDiferentes * alturas * perfiles (Cross Spectra) |
|
22 | 21 | canales * alturas (DC Channels) |
|
23 | 22 | |
|
24 | ||
|
25 | 23 | Esta clase contiene instancias (objetos) de las clases BasicHeader, SystemHeader, |
|
26 | 24 | RadarControllerHeader y Spectra. Los tres primeros se usan para almacenar informacion de la |
|
27 | 25 | cabecera de datos (metadata), y el cuarto (Spectra) para obtener y almacenar un bloque de |
@@ -76,7 +74,6 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
76 | 74 | Inicializador de la clase SpectraReader para la lectura de datos de espectros. |
|
77 | 75 | |
|
78 | 76 | Inputs: |
|
79 | ||
|
80 | 77 | dataOut : Objeto de la clase Spectra. Este objeto sera utilizado para |
|
81 | 78 | almacenar un perfil de datos cada vez que se haga un requerimiento |
|
82 | 79 | (getData). El perfil sera obtenido a partir del buffer de datos, |
@@ -84,107 +81,104 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
84 | 81 | bloque de datos. |
|
85 | 82 | Si este parametro no es pasado se creara uno internamente. |
|
86 | 83 | |
|
87 |
|
|
|
88 | Affected: | |
|
89 | ||
|
84 | Affected: | |
|
90 | 85 | self.dataOut |
|
91 | 86 | |
|
92 | 87 | Return : None |
|
93 | 88 | """ |
|
94 | 89 | |
|
95 | ||
|
96 | 90 | #Eliminar de la base la herencia |
|
97 | 91 | ProcessingUnit.__init__(self, **kwargs) |
|
98 | ||
|
92 | ||
|
99 | 93 | # self.isConfig = False |
|
100 | ||
|
94 | ||
|
101 | 95 | self.pts2read_SelfSpectra = 0 |
|
102 | ||
|
96 | ||
|
103 | 97 | self.pts2read_CrossSpectra = 0 |
|
104 | ||
|
98 | ||
|
105 | 99 | self.pts2read_DCchannels = 0 |
|
106 | ||
|
100 | ||
|
107 | 101 | self.datablock = None |
|
108 | ||
|
102 | ||
|
109 | 103 | self.utc = None |
|
110 | ||
|
104 | ||
|
111 | 105 | self.ext = ".pdata" |
|
112 | ||
|
106 | ||
|
113 | 107 | self.optchar = "P" |
|
114 | ||
|
108 | ||
|
115 | 109 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
116 | ||
|
110 | ||
|
117 | 111 | self.systemHeaderObj = SystemHeader() |
|
118 | ||
|
112 | ||
|
119 | 113 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
120 | ||
|
114 | ||
|
121 | 115 | self.processingHeaderObj = ProcessingHeader() |
|
122 | ||
|
116 | ||
|
123 | 117 | self.online = 0 |
|
124 | ||
|
118 | ||
|
125 | 119 | self.fp = None |
|
126 | ||
|
120 | ||
|
127 | 121 | self.idFile = None |
|
128 | ||
|
122 | ||
|
129 | 123 | self.dtype = None |
|
130 | ||
|
124 | ||
|
131 | 125 | self.fileSizeByHeader = None |
|
132 | ||
|
126 | ||
|
133 | 127 | self.filenameList = [] |
|
134 | ||
|
128 | ||
|
135 | 129 | self.filename = None |
|
136 | ||
|
130 | ||
|
137 | 131 | self.fileSize = None |
|
138 | ||
|
132 | ||
|
139 | 133 | self.firstHeaderSize = 0 |
|
140 | ||
|
134 | ||
|
141 | 135 | self.basicHeaderSize = 24 |
|
142 | ||
|
136 | ||
|
143 | 137 | self.pathList = [] |
|
144 | 138 | |
|
145 | 139 | self.lastUTTime = 0 |
|
146 | ||
|
140 | ||
|
147 | 141 | self.maxTimeStep = 30 |
|
148 | ||
|
142 | ||
|
149 | 143 | self.flagNoMoreFiles = 0 |
|
150 | ||
|
144 | ||
|
151 | 145 | self.set = 0 |
|
152 | ||
|
146 | ||
|
153 | 147 | self.path = None |
|
154 | 148 | |
|
155 | 149 | self.delay = 60 #seconds |
|
156 | ||
|
150 | ||
|
157 | 151 | self.nTries = 3 #quantity tries |
|
158 | ||
|
152 | ||
|
159 | 153 | self.nFiles = 3 #number of files for searching |
|
160 | ||
|
154 | ||
|
161 | 155 | self.nReadBlocks = 0 |
|
162 | ||
|
156 | ||
|
163 | 157 | self.flagIsNewFile = 1 |
|
164 | ||
|
158 | ||
|
165 | 159 | self.__isFirstTimeOnline = 1 |
|
166 | ||
|
160 | ||
|
167 | 161 | # self.ippSeconds = 0 |
|
168 | ||
|
169 |
self.flagDiscontinuousBlock = 0 |
|
|
170 | ||
|
162 | ||
|
163 | self.flagDiscontinuousBlock = 0 | |
|
164 | ||
|
171 | 165 | self.flagIsNewBlock = 0 |
|
172 | ||
|
166 | ||
|
173 | 167 | self.nTotalBlocks = 0 |
|
174 | ||
|
168 | ||
|
175 | 169 | self.blocksize = 0 |
|
176 | ||
|
170 | ||
|
177 | 171 | self.dataOut = self.createObjByDefault() |
|
178 | ||
|
172 | ||
|
179 | 173 | self.profileIndex = 1 #Always |
|
180 | 174 | |
|
181 | 175 | |
|
182 | 176 | def createObjByDefault(self): |
|
183 | ||
|
177 | ||
|
184 | 178 | dataObj = Spectra() |
|
185 | ||
|
179 | ||
|
186 | 180 | return dataObj |
|
187 | ||
|
181 | ||
|
188 | 182 | def __hasNotDataInBuffer(self): |
|
189 | 183 | return 1 |
|
190 | 184 | |
@@ -192,7 +186,7 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
192 | 186 | def getBlockDimension(self): |
|
193 | 187 | """ |
|
194 | 188 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
195 | ||
|
189 | ||
|
196 | 190 | Affected: |
|
197 | 191 | self.nRdChannels |
|
198 | 192 | self.nRdPairs |
@@ -212,39 +206,37 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
212 | 206 | |
|
213 | 207 | for i in range(0, self.processingHeaderObj.totalSpectra*2, 2): |
|
214 | 208 | if self.processingHeaderObj.spectraComb[i] == self.processingHeaderObj.spectraComb[i+1]: |
|
215 |
self.nRdChannels = self.nRdChannels + 1 #par de canales iguales |
|
|
216 | ||
|
209 | self.nRdChannels = self.nRdChannels + 1 #par de canales iguales | |
|
217 | 210 | else: |
|
218 | 211 | self.nRdPairs = self.nRdPairs + 1 #par de canales diferentes |
|
219 | 212 | self.rdPairList.append((self.processingHeaderObj.spectraComb[i], self.processingHeaderObj.spectraComb[i+1])) |
|
220 | 213 | |
|
221 | 214 | pts2read = self.processingHeaderObj.nHeights * self.processingHeaderObj.profilesPerBlock |
|
222 | ||
|
215 | ||
|
223 | 216 | self.pts2read_SelfSpectra = int(self.nRdChannels * pts2read) |
|
224 | 217 | self.blocksize = self.pts2read_SelfSpectra |
|
225 | ||
|
218 | ||
|
226 | 219 | if self.processingHeaderObj.flag_cspc: |
|
227 | 220 | self.pts2read_CrossSpectra = int(self.nRdPairs * pts2read) |
|
228 | 221 | self.blocksize += self.pts2read_CrossSpectra |
|
229 | ||
|
222 | ||
|
230 | 223 | if self.processingHeaderObj.flag_dc: |
|
231 | 224 | self.pts2read_DCchannels = int(self.systemHeaderObj.nChannels * self.processingHeaderObj.nHeights) |
|
232 | 225 | self.blocksize += self.pts2read_DCchannels |
|
233 | ||
|
226 | ||
|
234 | 227 | # self.blocksize = self.pts2read_SelfSpectra + self.pts2read_CrossSpectra + self.pts2read_DCchannels |
|
235 | 228 | |
|
236 | ||
|
229 | ||
|
237 | 230 | def readBlock(self): |
|
238 | 231 | """ |
|
239 | 232 | Lee el bloque de datos desde la posicion actual del puntero del archivo |
|
240 | 233 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
241 | 234 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
242 | 235 | es seteado a 0 |
|
243 | ||
|
236 | ||
|
244 | 237 | Return: None |
|
245 | ||
|
238 | ||
|
246 | 239 | Variables afectadas: |
|
247 | ||
|
248 | 240 | |
|
249 | 241 | self.flagIsNewFile |
|
250 | 242 | self.flagIsNewBlock |
@@ -253,10 +245,9 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
253 | 245 | self.data_cspc |
|
254 | 246 | self.data_dc |
|
255 | 247 | |
|
256 |
Exceptions: |
|
|
248 | Exceptions: | |
|
257 | 249 | Si un bloque leido no es un bloque valido |
|
258 | 250 | """ |
|
259 | ||
|
260 | 251 | blockOk_flag = False |
|
261 | 252 | fpointer = self.fp.tell() |
|
262 | 253 | |
@@ -266,32 +257,30 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
266 | 257 | if self.processingHeaderObj.flag_cspc: |
|
267 | 258 | cspc = numpy.fromfile( self.fp, self.dtype, self.pts2read_CrossSpectra ) |
|
268 | 259 | cspc = cspc.reshape( (self.nRdPairs, self.processingHeaderObj.nHeights, self.processingHeaderObj.profilesPerBlock) ) #transforma a un arreglo 3D |
|
269 | ||
|
260 | ||
|
270 | 261 | if self.processingHeaderObj.flag_dc: |
|
271 | 262 | dc = numpy.fromfile( self.fp, self.dtype, self.pts2read_DCchannels ) #int(self.processingHeaderObj.nHeights*self.systemHeaderObj.nChannels) ) |
|
272 | 263 | dc = dc.reshape( (self.systemHeaderObj.nChannels, self.processingHeaderObj.nHeights) ) #transforma a un arreglo 2D |
|
273 | ||
|
274 | ||
|
264 | ||
|
265 | ||
|
275 | 266 | if not(self.processingHeaderObj.shif_fft): |
|
276 | 267 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
277 | 268 | shift = int(self.processingHeaderObj.profilesPerBlock/2) |
|
278 | 269 | spc = numpy.roll( spc, shift , axis=2 ) |
|
279 | ||
|
270 | ||
|
280 | 271 | if self.processingHeaderObj.flag_cspc: |
|
281 | 272 | #desplaza a la derecha en el eje 2 determinadas posiciones |
|
282 | 273 | cspc = numpy.roll( cspc, shift, axis=2 ) |
|
283 | ||
|
274 | ||
|
284 | 275 | #Dimensions : nChannels, nProfiles, nSamples |
|
285 | 276 | spc = numpy.transpose( spc, (0,2,1) ) |
|
286 | 277 | self.data_spc = spc |
|
287 | ||
|
288 | if self.processingHeaderObj.flag_cspc: | |
|
289 | 278 | |
|
279 | if self.processingHeaderObj.flag_cspc: | |
|
290 | 280 | cspc = numpy.transpose( cspc, (0,2,1) ) |
|
291 | 281 | self.data_cspc = cspc['real'] + cspc['imag']*1j |
|
292 | 282 | else: |
|
293 | 283 | self.data_cspc = None |
|
294 | ||
|
295 | 284 | |
|
296 | 285 | if self.processingHeaderObj.flag_dc: |
|
297 | 286 | self.data_dc = dc['real'] + dc['imag']*1j |
@@ -305,60 +294,60 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
305 | 294 | self.nReadBlocks += 1 |
|
306 | 295 | |
|
307 | 296 | return 1 |
|
308 | ||
|
297 | ||
|
309 | 298 | def getFirstHeader(self): |
|
310 | ||
|
299 | ||
|
311 | 300 | self.getBasicHeader() |
|
312 | ||
|
301 | ||
|
313 | 302 | self.dataOut.systemHeaderObj = self.systemHeaderObj.copy() |
|
314 | ||
|
303 | ||
|
315 | 304 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
316 | ||
|
305 | ||
|
317 | 306 | # self.dataOut.ippSeconds = self.ippSeconds |
|
318 | ||
|
307 | ||
|
319 | 308 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt * self.processingHeaderObj.nIncohInt * self.processingHeaderObj.profilesPerBlock |
|
320 | 309 | |
|
321 | 310 | self.dataOut.dtype = self.dtype |
|
322 | ||
|
311 | ||
|
323 | 312 | # self.dataOut.nPairs = self.nPairs |
|
324 | ||
|
313 | ||
|
325 | 314 | self.dataOut.pairsList = self.rdPairList |
|
326 | ||
|
315 | ||
|
327 | 316 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
328 | ||
|
317 | ||
|
329 | 318 | self.dataOut.nFFTPoints = self.processingHeaderObj.profilesPerBlock |
|
330 | ||
|
319 | ||
|
331 | 320 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
332 | ||
|
321 | ||
|
333 | 322 | self.dataOut.nIncohInt = self.processingHeaderObj.nIncohInt |
|
334 | ||
|
323 | ||
|
335 | 324 | xf = self.processingHeaderObj.firstHeight + self.processingHeaderObj.nHeights*self.processingHeaderObj.deltaHeight |
|
336 | 325 | |
|
337 |
self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) |
|
|
338 | ||
|
326 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.firstHeight, xf, self.processingHeaderObj.deltaHeight) | |
|
327 | ||
|
339 | 328 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
340 | ||
|
329 | ||
|
341 | 330 | self.dataOut.flagShiftFFT = True #Data is always shifted |
|
342 | ||
|
331 | ||
|
343 | 332 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada |
|
344 | ||
|
345 |
self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip |
|
|
346 | ||
|
333 | ||
|
334 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data esta sin flip | |
|
335 | ||
|
347 | 336 | def getData(self): |
|
348 | 337 | """ |
|
349 | 338 | First method to execute before "RUN" is called. |
|
350 | ||
|
339 | ||
|
351 | 340 | Copia el buffer de lectura a la clase "Spectra", |
|
352 | 341 | con todos los parametros asociados a este (metadata). cuando no hay datos en el buffer de |
|
353 | 342 | lectura es necesario hacer una nueva lectura de los bloques de datos usando "readNextBlock" |
|
354 | ||
|
343 | ||
|
355 | 344 | Return: |
|
356 | 345 | 0 : Si no hay mas archivos disponibles |
|
357 | 346 | 1 : Si hizo una buena copia del buffer |
|
358 | ||
|
347 | ||
|
359 | 348 | Affected: |
|
360 | 349 | self.dataOut |
|
361 | ||
|
350 | ||
|
362 | 351 | self.flagDiscontinuousBlock |
|
363 | 352 | self.flagIsNewBlock |
|
364 | 353 | """ |
@@ -367,70 +356,68 class SpectraReader(JRODataReader, ProcessingUnit): | |||
|
367 | 356 | self.dataOut.flagNoData = True |
|
368 | 357 | print 'Process finished' |
|
369 | 358 | return 0 |
|
370 | ||
|
359 | ||
|
371 | 360 | self.flagDiscontinuousBlock = 0 |
|
372 | 361 | self.flagIsNewBlock = 0 |
|
373 | ||
|
374 |
if self.__hasNotDataInBuffer(): |
|
|
362 | ||
|
363 | if self.__hasNotDataInBuffer(): | |
|
375 | 364 | |
|
376 | 365 | if not( self.readNextBlock() ): |
|
377 | 366 | self.dataOut.flagNoData = True |
|
378 | 367 | return 0 |
|
379 | ||
|
380 | 368 | |
|
381 | 369 | #data es un numpy array de 3 dmensiones (perfiles, alturas y canales) |
|
382 | 370 | |
|
383 | 371 | if self.data_spc is None: |
|
384 | 372 | self.dataOut.flagNoData = True |
|
385 | 373 | return 0 |
|
386 | ||
|
374 | ||
|
387 | 375 | self.getBasicHeader() |
|
388 | ||
|
376 | ||
|
389 | 377 | self.getFirstHeader() |
|
390 | 378 | |
|
391 | 379 | self.dataOut.data_spc = self.data_spc |
|
392 | ||
|
380 | ||
|
393 | 381 | self.dataOut.data_cspc = self.data_cspc |
|
394 | ||
|
382 | ||
|
395 | 383 | self.dataOut.data_dc = self.data_dc |
|
396 | ||
|
384 | ||
|
397 | 385 | self.dataOut.flagNoData = False |
|
398 | ||
|
386 | ||
|
399 | 387 | self.dataOut.realtime = self.online |
|
400 | ||
|
388 | ||
|
401 | 389 | return self.dataOut.data_spc |
|
402 | 390 | |
|
403 | 391 | class SpectraWriter(JRODataWriter, Operation): |
|
404 | ||
|
405 |
""" |
|
|
392 | ||
|
393 | """ | |
|
406 | 394 | Esta clase permite escribir datos de espectros a archivos procesados (.pdata). La escritura |
|
407 |
de los datos siempre se realiza por bloques. |
|
|
395 | de los datos siempre se realiza por bloques. | |
|
408 | 396 | """ |
|
409 | ||
|
397 | ||
|
410 | 398 | ext = ".pdata" |
|
411 | ||
|
399 | ||
|
412 | 400 | optchar = "P" |
|
413 | ||
|
401 | ||
|
414 | 402 | shape_spc_Buffer = None |
|
415 | ||
|
403 | ||
|
416 | 404 | shape_cspc_Buffer = None |
|
417 | ||
|
405 | ||
|
418 | 406 | shape_dc_Buffer = None |
|
419 | ||
|
407 | ||
|
420 | 408 | data_spc = None |
|
421 | ||
|
409 | ||
|
422 | 410 | data_cspc = None |
|
423 | ||
|
411 | ||
|
424 | 412 | data_dc = None |
|
425 | ||
|
413 | ||
|
426 | 414 | # dataOut = None |
|
427 | ||
|
428 | def __init__(self): | |
|
429 |
""" |
|
|
415 | ||
|
416 | def __init__(self, **kwargs): | |
|
417 | """ | |
|
430 | 418 | Inicializador de la clase SpectraWriter para la escritura de datos de espectros. |
|
431 | ||
|
432 | Affected: | |
|
433 | 419 | |
|
420 | Affected: | |
|
434 | 421 | self.dataOut |
|
435 | 422 | self.basicHeaderObj |
|
436 | 423 | self.systemHeaderObj |
@@ -439,51 +426,49 class SpectraWriter(JRODataWriter, Operation): | |||
|
439 | 426 | |
|
440 | 427 | Return: None |
|
441 | 428 | """ |
|
442 | ||
|
443 | Operation.__init__(self) | |
|
444 | ||
|
429 | ||
|
430 | Operation.__init__(self, **kwargs) | |
|
431 | ||
|
445 | 432 | self.isConfig = False |
|
446 | ||
|
433 | ||
|
447 | 434 | self.nTotalBlocks = 0 |
|
448 | ||
|
435 | ||
|
449 | 436 | self.data_spc = None |
|
450 | ||
|
437 | ||
|
451 | 438 | self.data_cspc = None |
|
452 | ||
|
453 | 439 | |
|
454 | 440 | self.data_dc = None |
|
455 | 441 | |
|
456 | 442 | self.fp = None |
|
457 | 443 | |
|
458 | 444 | self.flagIsNewFile = 1 |
|
459 | ||
|
460 |
self.nTotalBlocks = 0 |
|
|
461 | ||
|
445 | ||
|
446 | self.nTotalBlocks = 0 | |
|
447 | ||
|
462 | 448 | self.flagIsNewBlock = 0 |
|
463 | 449 | |
|
464 | 450 | self.setFile = None |
|
465 | ||
|
451 | ||
|
466 | 452 | self.dtype = None |
|
467 | ||
|
453 | ||
|
468 | 454 | self.path = None |
|
469 | ||
|
455 | ||
|
470 | 456 | self.noMoreFiles = 0 |
|
471 | ||
|
457 | ||
|
472 | 458 | self.filename = None |
|
473 | ||
|
459 | ||
|
474 | 460 | self.basicHeaderObj = BasicHeader(LOCALTIME) |
|
475 | ||
|
461 | ||
|
476 | 462 | self.systemHeaderObj = SystemHeader() |
|
477 | ||
|
463 | ||
|
478 | 464 | self.radarControllerHeaderObj = RadarControllerHeader() |
|
479 | ||
|
465 | ||
|
480 | 466 | self.processingHeaderObj = ProcessingHeader() |
|
481 | 467 | |
|
482 | ||
|
468 | ||
|
483 | 469 | def hasAllDataInBuffer(self): |
|
484 | 470 | return 1 |
|
485 | 471 | |
|
486 | ||
|
487 | 472 | |
|
488 | 473 | def setBlockDimension(self): |
|
489 | 474 | """ |
@@ -503,15 +488,14 class SpectraWriter(JRODataWriter, Operation): | |||
|
503 | 488 | self.shape_cspc_Buffer = (self.dataOut.nPairs, |
|
504 | 489 | self.processingHeaderObj.nHeights, |
|
505 | 490 | self.processingHeaderObj.profilesPerBlock) |
|
506 | ||
|
491 | ||
|
507 | 492 | self.shape_dc_Buffer = (self.dataOut.nChannels, |
|
508 | 493 | self.processingHeaderObj.nHeights) |
|
509 | 494 | |
|
510 | ||
|
495 | ||
|
511 | 496 | def writeBlock(self): |
|
512 | 497 | """ |
|
513 | 498 | Escribe el buffer en el file designado |
|
514 | ||
|
515 | 499 | |
|
516 | 500 | Affected: |
|
517 | 501 | self.data_spc |
@@ -520,11 +504,11 class SpectraWriter(JRODataWriter, Operation): | |||
|
520 | 504 | self.flagIsNewFile |
|
521 | 505 | self.flagIsNewBlock |
|
522 | 506 | self.nTotalBlocks |
|
523 |
self.nWriteBlocks |
|
|
524 | ||
|
507 | self.nWriteBlocks | |
|
508 | ||
|
525 | 509 | Return: None |
|
526 | 510 | """ |
|
527 | ||
|
511 | ||
|
528 | 512 | spc = numpy.transpose( self.data_spc, (0,2,1) ) |
|
529 | 513 | if not( self.processingHeaderObj.shif_fft ): |
|
530 | 514 | spc = numpy.roll( spc, self.processingHeaderObj.profilesPerBlock/2, axis=2 ) #desplaza a la derecha en el eje 2 determinadas posiciones |
@@ -541,7 +525,6 class SpectraWriter(JRODataWriter, Operation): | |||
|
541 | 525 | data['imag'] = cspc.imag |
|
542 | 526 | data = data.reshape((-1)) |
|
543 | 527 | data.tofile(self.fp) |
|
544 | ||
|
545 | 528 | |
|
546 | 529 | if self.data_dc is not None: |
|
547 | 530 | data = numpy.zeros( self.shape_dc_Buffer, self.dtype ) |
@@ -552,147 +535,145 class SpectraWriter(JRODataWriter, Operation): | |||
|
552 | 535 | data.tofile(self.fp) |
|
553 | 536 | |
|
554 | 537 | # self.data_spc.fill(0) |
|
555 | # | |
|
538 | # | |
|
556 | 539 | # if self.data_dc is not None: |
|
557 | 540 | # self.data_dc.fill(0) |
|
558 | # | |
|
541 | # | |
|
559 | 542 | # if self.data_cspc is not None: |
|
560 | 543 | # self.data_cspc.fill(0) |
|
561 | ||
|
562 | 544 | |
|
563 | 545 | self.flagIsNewFile = 0 |
|
564 | 546 | self.flagIsNewBlock = 1 |
|
565 | 547 | self.nTotalBlocks += 1 |
|
566 | 548 | self.nWriteBlocks += 1 |
|
567 | 549 | self.blockIndex += 1 |
|
568 | ||
|
550 | ||
|
569 | 551 | # print "[Writing] Block = %d04" %self.blockIndex |
|
570 | ||
|
552 | ||
|
571 | 553 | def putData(self): |
|
572 | 554 | """ |
|
573 |
Setea un bloque de datos y luego los escribe en un file |
|
|
574 | ||
|
555 | Setea un bloque de datos y luego los escribe en un file | |
|
575 | 556 | |
|
576 | 557 | Affected: |
|
577 | 558 | self.data_spc |
|
578 | 559 | self.data_cspc |
|
579 | 560 | self.data_dc |
|
580 | 561 | |
|
581 |
Return: |
|
|
582 |
0 : Si no hay data o no hay mas files que puedan escribirse |
|
|
562 | Return: | |
|
563 | 0 : Si no hay data o no hay mas files que puedan escribirse | |
|
583 | 564 | 1 : Si se escribio la data de un bloque en un file |
|
584 | 565 | """ |
|
585 | ||
|
566 | ||
|
586 | 567 | if self.dataOut.flagNoData: |
|
587 | 568 | return 0 |
|
588 | ||
|
569 | ||
|
589 | 570 | self.flagIsNewBlock = 0 |
|
590 | ||
|
571 | ||
|
591 | 572 | if self.dataOut.flagDiscontinuousBlock: |
|
592 | 573 | self.data_spc.fill(0) |
|
593 |
self.data_cspc |
|
|
594 |
self.data_ |
|
|
574 | if self.dataOut.data_cspc is not None: | |
|
575 | self.data_cspc.fill(0) | |
|
576 | if self.dataOut.data_dc is not None: | |
|
577 | self.data_dc.fill(0) | |
|
595 | 578 | self.setNextFile() |
|
596 | ||
|
579 | ||
|
597 | 580 | if self.flagIsNewFile == 0: |
|
598 | 581 | self.setBasicHeader() |
|
599 | ||
|
582 | ||
|
600 | 583 | self.data_spc = self.dataOut.data_spc.copy() |
|
601 | ||
|
584 | ||
|
602 | 585 | if self.dataOut.data_cspc is not None: |
|
603 | 586 | self.data_cspc = self.dataOut.data_cspc.copy() |
|
604 | ||
|
587 | ||
|
605 | 588 | if self.dataOut.data_dc is not None: |
|
606 | 589 | self.data_dc = self.dataOut.data_dc.copy() |
|
607 | ||
|
590 | ||
|
608 | 591 | # #self.processingHeaderObj.dataBlocksPerFile) |
|
609 | 592 | if self.hasAllDataInBuffer(): |
|
610 | 593 | # self.setFirstHeader() |
|
611 | 594 | self.writeNextBlock() |
|
612 | ||
|
595 | ||
|
613 | 596 | return 1 |
|
614 | ||
|
615 | 597 | |
|
616 | 598 | def __getBlockSize(self): |
|
617 | 599 | ''' |
|
618 | 600 | Este metodos determina el cantidad de bytes para un bloque de datos de tipo Spectra |
|
619 | 601 | ''' |
|
620 | ||
|
602 | ||
|
621 | 603 | dtype_width = self.getDtypeWidth() |
|
622 | ||
|
604 | ||
|
623 | 605 | pts2write = self.dataOut.nHeights * self.dataOut.nFFTPoints |
|
624 | ||
|
606 | ||
|
625 | 607 | pts2write_SelfSpectra = int(self.dataOut.nChannels * pts2write) |
|
626 | 608 | blocksize = (pts2write_SelfSpectra*dtype_width) |
|
627 | ||
|
609 | ||
|
628 | 610 | if self.dataOut.data_cspc is not None: |
|
629 | 611 | pts2write_CrossSpectra = int(self.dataOut.nPairs * pts2write) |
|
630 | 612 | blocksize += (pts2write_CrossSpectra*dtype_width*2) |
|
631 | ||
|
613 | ||
|
632 | 614 | if self.dataOut.data_dc is not None: |
|
633 | 615 | pts2write_DCchannels = int(self.dataOut.nChannels * self.dataOut.nHeights) |
|
634 | 616 | blocksize += (pts2write_DCchannels*dtype_width*2) |
|
635 | ||
|
617 | ||
|
636 | 618 | # blocksize = blocksize #* datatypeValue * 2 #CORREGIR ESTO |
|
637 | 619 | |
|
638 | 620 | return blocksize |
|
639 | ||
|
621 | ||
|
640 | 622 | def setFirstHeader(self): |
|
641 | ||
|
623 | ||
|
642 | 624 | """ |
|
643 | 625 | Obtiene una copia del First Header |
|
644 | ||
|
626 | ||
|
645 | 627 | Affected: |
|
646 | 628 | self.systemHeaderObj |
|
647 | 629 | self.radarControllerHeaderObj |
|
648 | 630 | self.dtype |
|
649 | 631 | |
|
650 |
Return: |
|
|
632 | Return: | |
|
651 | 633 | None |
|
652 | 634 | """ |
|
653 | ||
|
635 | ||
|
654 | 636 | self.systemHeaderObj = self.dataOut.systemHeaderObj.copy() |
|
655 | 637 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
656 | 638 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
657 | ||
|
639 | ||
|
658 | 640 | self.processingHeaderObj.dtype = 1 # Spectra |
|
659 | 641 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
660 | 642 | self.processingHeaderObj.profilesPerBlock = self.dataOut.nFFTPoints |
|
661 | 643 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
662 | 644 | self.processingHeaderObj.nWindows = 1 #podria ser 1 o self.dataOut.processingHeaderObj.nWindows |
|
663 | 645 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt# Se requiere para determinar el valor de timeInterval |
|
664 |
self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt |
|
|
646 | self.processingHeaderObj.nIncohInt = self.dataOut.nIncohInt | |
|
665 | 647 | self.processingHeaderObj.totalSpectra = self.dataOut.nPairs + self.dataOut.nChannels |
|
666 | 648 | self.processingHeaderObj.shif_fft = self.dataOut.flagShiftFFT |
|
667 | ||
|
668 | 649 | |
|
669 | 650 | if self.processingHeaderObj.totalSpectra > 0: |
|
670 | 651 | channelList = [] |
|
671 | 652 | for channel in range(self.dataOut.nChannels): |
|
672 | 653 | channelList.append(channel) |
|
673 | 654 | channelList.append(channel) |
|
674 | ||
|
655 | ||
|
675 | 656 | pairsList = [] |
|
676 | 657 | if self.dataOut.nPairs > 0: |
|
677 | 658 | for pair in self.dataOut.pairsList: |
|
678 | 659 | pairsList.append(pair[0]) |
|
679 | 660 | pairsList.append(pair[1]) |
|
680 | ||
|
661 | ||
|
681 | 662 | spectraComb = channelList + pairsList |
|
682 | 663 | spectraComb = numpy.array(spectraComb, dtype="u1") |
|
683 | 664 | self.processingHeaderObj.spectraComb = spectraComb |
|
684 | ||
|
665 | ||
|
685 | 666 | if self.dataOut.code is not None: |
|
686 | 667 | self.processingHeaderObj.code = self.dataOut.code |
|
687 | 668 | self.processingHeaderObj.nCode = self.dataOut.nCode |
|
688 | 669 | self.processingHeaderObj.nBaud = self.dataOut.nBaud |
|
689 | ||
|
670 | ||
|
690 | 671 | if self.processingHeaderObj.nWindows != 0: |
|
691 | 672 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
692 | 673 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - self.dataOut.heightList[0] |
|
693 | 674 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
694 | 675 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
695 | ||
|
676 | ||
|
696 | 677 | self.processingHeaderObj.processFlags = self.getProcessFlags() |
|
697 | ||
|
678 | ||
|
698 | 679 | self.setBasicHeader() |
@@ -15,6 +15,7 import tempfile | |||
|
15 | 15 | from StringIO import StringIO |
|
16 | 16 | # from _sha import blocksize |
|
17 | 17 | |
|
18 | ||
|
18 | 19 | class VoltageReader(JRODataReader, ProcessingUnit): |
|
19 | 20 | """ |
|
20 | 21 | Esta clase permite leer datos de voltage desde archivos en formato rawdata (.r). La lectura |
@@ -134,13 +135,13 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
134 | 135 | |
|
135 | 136 | self.path = None |
|
136 | 137 | |
|
137 | self.profileIndex = 2**32-1 | |
|
138 | self.profileIndex = 2**32 - 1 | |
|
138 | 139 | |
|
139 |
self.delay |
|
|
140 | self.delay = 3 # seconds | |
|
140 | 141 | |
|
141 |
self.nTries |
|
|
142 | self.nTries = 3 # quantity tries | |
|
142 | 143 | |
|
143 |
self.nFiles = 3 |
|
|
144 | self.nFiles = 3 # number of files for searching | |
|
144 | 145 | |
|
145 | 146 | self.nReadBlocks = 0 |
|
146 | 147 | |
@@ -172,51 +173,49 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
172 | 173 | |
|
173 | 174 | def __hasNotDataInBuffer(self): |
|
174 | 175 | |
|
175 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock*self.nTxs: | |
|
176 | if self.profileIndex >= self.processingHeaderObj.profilesPerBlock * self.nTxs: | |
|
176 | 177 | return 1 |
|
177 | 178 | |
|
178 | 179 | return 0 |
|
179 | 180 | |
|
180 | ||
|
181 | 181 | def getBlockDimension(self): |
|
182 | 182 | """ |
|
183 | 183 | Obtiene la cantidad de puntos a leer por cada bloque de datos |
|
184 | ||
|
184 | ||
|
185 | 185 | Affected: |
|
186 | 186 | self.blocksize |
|
187 | 187 | |
|
188 | 188 | Return: |
|
189 | 189 | None |
|
190 | 190 | """ |
|
191 |
pts2read = self.processingHeaderObj.profilesPerBlock * |
|
|
191 | pts2read = self.processingHeaderObj.profilesPerBlock * \ | |
|
192 | self.processingHeaderObj.nHeights * self.systemHeaderObj.nChannels | |
|
192 | 193 | self.blocksize = pts2read |
|
193 | 194 | |
|
194 | ||
|
195 | ||
|
196 | 195 | def readBlock(self): |
|
197 | 196 | """ |
|
198 | 197 | readBlock lee el bloque de datos desde la posicion actual del puntero del archivo |
|
199 | 198 | (self.fp) y actualiza todos los parametros relacionados al bloque de datos |
|
200 | 199 | (metadata + data). La data leida es almacenada en el buffer y el contador del buffer |
|
201 | 200 | es seteado a 0 |
|
202 | ||
|
201 | ||
|
203 | 202 | Inputs: |
|
204 | 203 | None |
|
205 | ||
|
204 | ||
|
206 | 205 | Return: |
|
207 | 206 | None |
|
208 | ||
|
207 | ||
|
209 | 208 | Affected: |
|
210 | 209 | self.profileIndex |
|
211 | 210 | self.datablock |
|
212 | 211 | self.flagIsNewFile |
|
213 | 212 | self.flagIsNewBlock |
|
214 | 213 | self.nTotalBlocks |
|
215 | ||
|
214 | ||
|
216 | 215 | Exceptions: |
|
217 | 216 | Si un bloque leido no es un bloque valido |
|
218 | 217 | """ |
|
219 | ||
|
218 | ||
|
220 | 219 | # if self.server is not None: |
|
221 | 220 | # self.zBlock = self.receiver.recv() |
|
222 | 221 | # self.zHeader = self.zBlock[:24] |
@@ -227,22 +226,24 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
227 | 226 | # self.systemHeaderObj.nChannels |
|
228 | 227 | # else: |
|
229 | 228 | current_pointer_location = self.fp.tell() |
|
230 |
junk = numpy.fromfile( |
|
|
229 | junk = numpy.fromfile(self.fp, self.dtype, self.blocksize) | |
|
231 | 230 | |
|
232 | 231 | try: |
|
233 |
junk = junk.reshape( |
|
|
232 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
|
233 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
|
234 | 234 | except: |
|
235 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
|
235 | # print "The read block (%3d) has not enough data" %self.nReadBlocks | |
|
236 | 236 | |
|
237 | 237 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
238 |
junk = numpy.fromfile( |
|
|
239 |
junk = junk.reshape( |
|
|
238 | junk = numpy.fromfile(self.fp, self.dtype, self.blocksize) | |
|
239 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
|
240 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
|
240 | 241 | # return 0 |
|
241 | 242 | |
|
242 | #Dimensions : nChannels, nProfiles, nSamples | |
|
243 | # Dimensions : nChannels, nProfiles, nSamples | |
|
243 | 244 | |
|
244 | junk = numpy.transpose(junk, (2,0,1)) | |
|
245 | self.datablock = junk['real'] + junk['imag']*1j | |
|
245 | junk = numpy.transpose(junk, (2, 0, 1)) | |
|
246 | self.datablock = junk['real'] + junk['imag'] * 1j | |
|
246 | 247 | |
|
247 | 248 | self.profileIndex = 0 |
|
248 | 249 | |
@@ -263,9 +264,8 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
263 | 264 | self.dataOut.radarControllerHeaderObj = self.radarControllerHeaderObj.copy() |
|
264 | 265 | |
|
265 | 266 | if self.nTxs > 1: |
|
266 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
|
267 | ||
|
268 | #Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. | |
|
267 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |
|
268 | # Time interval and code are propierties of dataOut. Its value depends of radarControllerHeaderObj. | |
|
269 | 269 | |
|
270 | 270 | # self.dataOut.timeInterval = self.radarControllerHeaderObj.ippSeconds * self.processingHeaderObj.nCohInt |
|
271 | 271 | # |
@@ -281,15 +281,18 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
281 | 281 | |
|
282 | 282 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock |
|
283 | 283 | |
|
284 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights) *self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
|
284 | self.dataOut.heightList = numpy.arange( | |
|
285 | self.processingHeaderObj.nHeights) * self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
|
285 | 286 | |
|
286 | 287 | self.dataOut.channelList = range(self.systemHeaderObj.nChannels) |
|
287 | 288 | |
|
288 | 289 | self.dataOut.nCohInt = self.processingHeaderObj.nCohInt |
|
289 | 290 | |
|
290 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode #asumo q la data no esta decodificada | |
|
291 | # asumo q la data no esta decodificada | |
|
292 | self.dataOut.flagDecodeData = self.processingHeaderObj.flag_decode | |
|
291 | 293 | |
|
292 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip #asumo q la data no esta sin flip | |
|
294 | # asumo q la data no esta sin flip | |
|
295 | self.dataOut.flagDeflipData = self.processingHeaderObj.flag_deflip | |
|
293 | 296 | |
|
294 | 297 | self.dataOut.flagShiftFFT = self.processingHeaderObj.shif_fft |
|
295 | 298 | |
@@ -301,51 +304,57 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
301 | 304 | if self.nTxs == 1: |
|
302 | 305 | return |
|
303 | 306 | |
|
304 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1./self.nTxs) != 0: | |
|
305 |
raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" %( |
|
|
307 | if self.nTxs < 1 and self.processingHeaderObj.profilesPerBlock % (1. / self.nTxs) != 0: | |
|
308 | raise ValueError, "1./nTxs (=%f), should be a multiple of nProfiles (=%d)" % ( | |
|
309 | 1. / self.nTxs, self.processingHeaderObj.profilesPerBlock) | |
|
306 | 310 | |
|
307 | 311 | if self.nTxs > 1 and self.processingHeaderObj.nHeights % self.nTxs != 0: |
|
308 |
raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" %( |
|
|
312 | raise ValueError, "nTxs (=%d), should be a multiple of nHeights (=%d)" % ( | |
|
313 | self.nTxs, self.processingHeaderObj.nHeights) | |
|
309 | 314 | |
|
310 | self.datablock = self.datablock.reshape((self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock*self.nTxs, self.processingHeaderObj.nHeights/self.nTxs)) | |
|
315 | self.datablock = self.datablock.reshape( | |
|
316 | (self.systemHeaderObj.nChannels, self.processingHeaderObj.profilesPerBlock * self.nTxs, self.processingHeaderObj.nHeights / self.nTxs)) | |
|
311 | 317 | |
|
312 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock*self.nTxs | |
|
313 |
self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights/self.nTxs) * |
|
|
314 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds/self.nTxs | |
|
318 | self.dataOut.nProfiles = self.processingHeaderObj.profilesPerBlock * self.nTxs | |
|
319 | self.dataOut.heightList = numpy.arange(self.processingHeaderObj.nHeights / self.nTxs) * \ | |
|
320 | self.processingHeaderObj.deltaHeight + self.processingHeaderObj.firstHeight | |
|
321 | self.dataOut.radarControllerHeaderObj.ippSeconds = self.radarControllerHeaderObj.ippSeconds / self.nTxs | |
|
315 | 322 | |
|
316 | 323 | return |
|
317 | 324 | |
|
318 | 325 | def readFirstHeaderFromServer(self): |
|
319 | ||
|
326 | ||
|
320 | 327 | self.getFirstHeader() |
|
321 | 328 | |
|
322 | 329 | self.firstHeaderSize = self.basicHeaderObj.size |
|
323 | 330 | |
|
324 |
datatype = int(numpy.log2((self.processingHeaderObj.processFlags & |
|
|
331 | datatype = int(numpy.log2((self.processingHeaderObj.processFlags & | |
|
332 | PROCFLAG.DATATYPE_MASK)) - numpy.log2(PROCFLAG.DATATYPE_CHAR)) | |
|
325 | 333 | if datatype == 0: |
|
326 | datatype_str = numpy.dtype([('real','<i1'),('imag','<i1')]) | |
|
334 | datatype_str = numpy.dtype([('real', '<i1'), ('imag', '<i1')]) | |
|
327 | 335 | elif datatype == 1: |
|
328 | datatype_str = numpy.dtype([('real','<i2'),('imag','<i2')]) | |
|
336 | datatype_str = numpy.dtype([('real', '<i2'), ('imag', '<i2')]) | |
|
329 | 337 | elif datatype == 2: |
|
330 | datatype_str = numpy.dtype([('real','<i4'),('imag','<i4')]) | |
|
338 | datatype_str = numpy.dtype([('real', '<i4'), ('imag', '<i4')]) | |
|
331 | 339 | elif datatype == 3: |
|
332 | datatype_str = numpy.dtype([('real','<i8'),('imag','<i8')]) | |
|
340 | datatype_str = numpy.dtype([('real', '<i8'), ('imag', '<i8')]) | |
|
333 | 341 | elif datatype == 4: |
|
334 | datatype_str = numpy.dtype([('real','<f4'),('imag','<f4')]) | |
|
342 | datatype_str = numpy.dtype([('real', '<f4'), ('imag', '<f4')]) | |
|
335 | 343 | elif datatype == 5: |
|
336 | datatype_str = numpy.dtype([('real','<f8'),('imag','<f8')]) | |
|
344 | datatype_str = numpy.dtype([('real', '<f8'), ('imag', '<f8')]) | |
|
337 | 345 | else: |
|
338 | 346 | raise ValueError, 'Data type was not defined' |
|
339 | 347 | |
|
340 | 348 | self.dtype = datatype_str |
|
341 | 349 | #self.ippSeconds = 2 * 1000 * self.radarControllerHeaderObj.ipp / self.c |
|
342 |
self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + |
|
|
350 | self.fileSizeByHeader = self.processingHeaderObj.dataBlocksPerFile * self.processingHeaderObj.blockSize + \ | |
|
351 | self.firstHeaderSize + self.basicHeaderSize * \ | |
|
352 | (self.processingHeaderObj.dataBlocksPerFile - 1) | |
|
343 | 353 | # self.dataOut.channelList = numpy.arange(self.systemHeaderObj.numChannels) |
|
344 | 354 | # self.dataOut.channelIndexList = numpy.arange(self.systemHeaderObj.numChannels) |
|
345 | 355 | self.getBlockDimension() |
|
346 | 356 | |
|
347 | ||
|
348 | def getFromServer(self): | |
|
357 | def getFromServer(self): | |
|
349 | 358 | self.flagDiscontinuousBlock = 0 |
|
350 | 359 | self.profileIndex = 0 |
|
351 | 360 | self.flagIsNewBlock = 1 |
@@ -365,38 +374,46 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
365 | 374 | self.processingHeaderObj.read(block[self.blockPointer:]) |
|
366 | 375 | self.blockPointer += self.processingHeaderObj.length |
|
367 | 376 | self.readFirstHeaderFromServer() |
|
368 | ||
|
377 | ||
|
369 | 378 | timestamp = self.basicHeaderObj.get_datatime() |
|
370 | 379 | print '[Reading] - Block {} - {}'.format(self.nTotalBlocks, timestamp) |
|
371 | 380 | current_pointer_location = self.blockPointer |
|
372 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) | |
|
381 | junk = numpy.fromstring( | |
|
382 | block[self.blockPointer:], self.dtype, self.blocksize) | |
|
373 | 383 | |
|
374 | 384 | try: |
|
375 |
junk = junk.reshape( |
|
|
385 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
|
386 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
|
376 | 387 | except: |
|
377 | #print "The read block (%3d) has not enough data" %self.nReadBlocks | |
|
388 | # print "The read block (%3d) has not enough data" %self.nReadBlocks | |
|
378 | 389 | if self.waitDataBlock(pointer_location=current_pointer_location): |
|
379 | junk = numpy.fromstring( block[self.blockPointer:], self.dtype, self.blocksize ) | |
|
380 | junk = junk.reshape( (self.processingHeaderObj.profilesPerBlock, self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels) ) | |
|
390 | junk = numpy.fromstring( | |
|
391 | block[self.blockPointer:], self.dtype, self.blocksize) | |
|
392 | junk = junk.reshape((self.processingHeaderObj.profilesPerBlock, | |
|
393 | self.processingHeaderObj.nHeights, self.systemHeaderObj.nChannels)) | |
|
381 | 394 | # return 0 |
|
382 | 395 | |
|
383 | #Dimensions : nChannels, nProfiles, nSamples | |
|
396 | # Dimensions : nChannels, nProfiles, nSamples | |
|
384 | 397 | |
|
385 | junk = numpy.transpose(junk, (2,0,1)) | |
|
386 |
self.datablock = junk['real'] + junk['imag'] * 1j |
|
|
398 | junk = numpy.transpose(junk, (2, 0, 1)) | |
|
399 | self.datablock = junk['real'] + junk['imag'] * 1j | |
|
387 | 400 | self.profileIndex = 0 |
|
388 |
if self.selBlocksize == None: |
|
|
401 | if self.selBlocksize == None: | |
|
402 | self.selBlocksize = self.dataOut.nProfiles | |
|
389 | 403 | if self.selBlocktime != None: |
|
390 | 404 | if self.dataOut.nCohInt is not None: |
|
391 | 405 | nCohInt = self.dataOut.nCohInt |
|
392 | 406 | else: |
|
393 | 407 | nCohInt = 1 |
|
394 |
self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/( |
|
|
395 | self.dataOut.data = self.datablock[:,self.profileIndex:self.profileIndex+self.selBlocksize,:] | |
|
408 | self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / ( | |
|
409 | nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles))) | |
|
410 | self.dataOut.data = self.datablock[:, | |
|
411 | self.profileIndex:self.profileIndex + self.selBlocksize, :] | |
|
396 | 412 | datasize = self.dataOut.data.shape[1] |
|
397 | 413 | if datasize < self.selBlocksize: |
|
398 | buffer = numpy.zeros((self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype = 'complex') | |
|
399 | buffer[:,:datasize,:] = self.dataOut.data | |
|
414 | buffer = numpy.zeros( | |
|
415 | (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex') | |
|
416 | buffer[:, :datasize, :] = self.dataOut.data | |
|
400 | 417 | self.dataOut.data = buffer |
|
401 | 418 | self.profileIndex = blockIndex |
|
402 | 419 | |
@@ -412,30 +429,30 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
412 | 429 | del tipo "Voltage" con todos los parametros asociados a este (metadata). cuando no hay datos |
|
413 | 430 | en el buffer de lectura es necesario hacer una nueva lectura de los bloques de datos usando |
|
414 | 431 | "readNextBlock" |
|
415 | ||
|
432 | ||
|
416 | 433 | Ademas incrementa el contador del buffer "self.profileIndex" en 1. |
|
417 | ||
|
434 | ||
|
418 | 435 | Return: |
|
419 | ||
|
436 | ||
|
420 | 437 | Si el flag self.getByBlock ha sido seteado el bloque completo es copiado a self.dataOut y el self.profileIndex |
|
421 | 438 | es igual al total de perfiles leidos desde el archivo. |
|
422 | ||
|
439 | ||
|
423 | 440 | Si self.getByBlock == False: |
|
424 | ||
|
441 | ||
|
425 | 442 | self.dataOut.data = buffer[:, thisProfile, :] |
|
426 | ||
|
443 | ||
|
427 | 444 | shape = [nChannels, nHeis] |
|
428 | ||
|
445 | ||
|
429 | 446 | Si self.getByBlock == True: |
|
430 | ||
|
447 | ||
|
431 | 448 | self.dataOut.data = buffer[:, :, :] |
|
432 | ||
|
449 | ||
|
433 | 450 | shape = [nChannels, nProfiles, nHeis] |
|
434 | ||
|
451 | ||
|
435 | 452 | Variables afectadas: |
|
436 | 453 | self.dataOut |
|
437 | 454 | self.profileIndex |
|
438 | ||
|
455 | ||
|
439 | 456 | Affected: |
|
440 | 457 | self.dataOut |
|
441 | 458 | self.profileIndex |
@@ -449,7 +466,7 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
449 | 466 | self.flagDiscontinuousBlock = 0 |
|
450 | 467 | self.flagIsNewBlock = 0 |
|
451 | 468 | if self.__hasNotDataInBuffer(): |
|
452 |
if not( |
|
|
469 | if not(self.readNextBlock()): | |
|
453 | 470 | return 0 |
|
454 | 471 | |
|
455 | 472 | self.getFirstHeader() |
@@ -468,11 +485,11 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
468 | 485 | blocks is increased by nTxs (nProfiles *= nTxs) |
|
469 | 486 | """ |
|
470 | 487 | self.dataOut.flagDataAsBlock = False |
|
471 | self.dataOut.data = self.datablock[:,self.profileIndex,:] | |
|
488 | self.dataOut.data = self.datablock[:, self.profileIndex, :] | |
|
472 | 489 | self.dataOut.profileIndex = self.profileIndex |
|
473 | 490 | |
|
474 | 491 | self.profileIndex += 1 |
|
475 | ||
|
492 | ||
|
476 | 493 | # elif self.selBlocksize==None or self.selBlocksize==self.dataOut.nProfiles: |
|
477 | 494 | # """ |
|
478 | 495 | # Return all block |
@@ -480,42 +497,47 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
480 | 497 | # self.dataOut.flagDataAsBlock = True |
|
481 | 498 | # self.dataOut.data = self.datablock |
|
482 | 499 | # self.dataOut.profileIndex = self.dataOut.nProfiles - 1 |
|
483 |
# |
|
|
500 | # | |
|
484 | 501 | # self.profileIndex = self.dataOut.nProfiles |
|
485 | ||
|
502 | ||
|
486 | 503 | else: |
|
487 | 504 | """ |
|
488 | 505 | Return a block |
|
489 | 506 | """ |
|
490 |
if self.selBlocksize == None: |
|
|
507 | if self.selBlocksize == None: | |
|
508 | self.selBlocksize = self.dataOut.nProfiles | |
|
491 | 509 | if self.selBlocktime != None: |
|
492 | 510 | if self.dataOut.nCohInt is not None: |
|
493 | 511 | nCohInt = self.dataOut.nCohInt |
|
494 | 512 | else: |
|
495 | 513 | nCohInt = 1 |
|
496 |
self.selBlocksize = int(self.dataOut.nProfiles*round(self.selBlocktime/( |
|
|
514 | self.selBlocksize = int(self.dataOut.nProfiles * round(self.selBlocktime / ( | |
|
515 | nCohInt * self.dataOut.ippSeconds * self.dataOut.nProfiles))) | |
|
497 | 516 | |
|
498 |
self.dataOut.data = self.datablock[:, |
|
|
517 | self.dataOut.data = self.datablock[:, | |
|
518 | self.profileIndex:self.profileIndex + self.selBlocksize, :] | |
|
499 | 519 | self.profileIndex += self.selBlocksize |
|
500 | 520 | datasize = self.dataOut.data.shape[1] |
|
501 | 521 | |
|
502 | 522 | if datasize < self.selBlocksize: |
|
503 | buffer = numpy.zeros((self.dataOut.data.shape[0],self.selBlocksize,self.dataOut.data.shape[2]), dtype = 'complex') | |
|
504 | buffer[:,:datasize,:] = self.dataOut.data | |
|
523 | buffer = numpy.zeros( | |
|
524 | (self.dataOut.data.shape[0], self.selBlocksize, self.dataOut.data.shape[2]), dtype='complex') | |
|
525 | buffer[:, :datasize, :] = self.dataOut.data | |
|
505 | 526 | |
|
506 | while datasize < self.selBlocksize: #Not enough profiles to fill the block | |
|
507 |
if not( |
|
|
527 | while datasize < self.selBlocksize: # Not enough profiles to fill the block | |
|
528 | if not(self.readNextBlock()): | |
|
508 | 529 | return 0 |
|
509 | 530 | self.getFirstHeader() |
|
510 | 531 | self.reshapeData() |
|
511 | 532 | if self.datablock is None: |
|
512 | 533 | self.dataOut.flagNoData = True |
|
513 | 534 | return 0 |
|
514 | #stack data | |
|
535 | # stack data | |
|
515 | 536 | blockIndex = self.selBlocksize - datasize |
|
516 | datablock1 = self.datablock[:,:blockIndex,:] | |
|
537 | datablock1 = self.datablock[:, :blockIndex, :] | |
|
517 | 538 | |
|
518 |
buffer[:,datasize:datasize+ |
|
|
539 | buffer[:, datasize:datasize + | |
|
540 | datablock1.shape[1], :] = datablock1 | |
|
519 | 541 | datasize += datablock1.shape[1] |
|
520 | 542 | |
|
521 | 543 | self.dataOut.data = buffer |
@@ -527,16 +549,11 class VoltageReader(JRODataReader, ProcessingUnit): | |||
|
527 | 549 | self.dataOut.flagNoData = False |
|
528 | 550 | |
|
529 | 551 | self.getBasicHeader() |
|
530 | ||
|
531 | #print self.basicHeaderObj.printInfo() | |
|
532 | #print self.systemHeaderObj.printInfo() | |
|
533 | #print self.radarControllerHeaderObj.printInfo() | |
|
534 | #print self.processingHeaderObj.printInfo() | |
|
535 | ||
|
552 | ||
|
536 | 553 | self.dataOut.realtime = self.online |
|
537 | 554 | |
|
538 | 555 | return self.dataOut.data |
|
539 | ||
|
556 | ||
|
540 | 557 | |
|
541 | 558 | class VoltageWriter(JRODataWriter, Operation): |
|
542 | 559 | """ |
@@ -550,7 +567,6 class VoltageWriter(JRODataWriter, Operation): | |||
|
550 | 567 | |
|
551 | 568 | shapeBuffer = None |
|
552 | 569 | |
|
553 | ||
|
554 | 570 | def __init__(self, **kwargs): |
|
555 | 571 | """ |
|
556 | 572 | Inicializador de la clase VoltageWriter para la escritura de datos de espectros. |
@@ -597,7 +613,6 class VoltageWriter(JRODataWriter, Operation): | |||
|
597 | 613 | return 1 |
|
598 | 614 | return 0 |
|
599 | 615 | |
|
600 | ||
|
601 | 616 | def setBlockDimension(self): |
|
602 | 617 | """ |
|
603 | 618 | Obtiene las formas dimensionales del los subbloques de datos que componen un bloque |
@@ -614,8 +629,8 class VoltageWriter(JRODataWriter, Operation): | |||
|
614 | 629 | self.systemHeaderObj.nChannels) |
|
615 | 630 | |
|
616 | 631 | self.datablock = numpy.zeros((self.systemHeaderObj.nChannels, |
|
617 | self.processingHeaderObj.profilesPerBlock, | |
|
618 | self.processingHeaderObj.nHeights), | |
|
632 | self.processingHeaderObj.profilesPerBlock, | |
|
633 | self.processingHeaderObj.nHeights), | |
|
619 | 634 | dtype=numpy.dtype('complex64')) |
|
620 | 635 | |
|
621 | 636 | def writeBlock(self): |
@@ -631,16 +646,16 class VoltageWriter(JRODataWriter, Operation): | |||
|
631 | 646 | |
|
632 | 647 | Return: None |
|
633 | 648 | """ |
|
634 |
data = numpy.zeros( |
|
|
649 | data = numpy.zeros(self.shapeBuffer, self.dtype) | |
|
635 | 650 | |
|
636 | junk = numpy.transpose(self.datablock, (1,2,0)) | |
|
651 | junk = numpy.transpose(self.datablock, (1, 2, 0)) | |
|
637 | 652 | |
|
638 | 653 | data['real'] = junk.real |
|
639 | 654 | data['imag'] = junk.imag |
|
640 | 655 | |
|
641 |
data = data.reshape( |
|
|
656 | data = data.reshape((-1)) | |
|
642 | 657 | |
|
643 |
data.tofile( |
|
|
658 | data.tofile(self.fp) | |
|
644 | 659 | |
|
645 | 660 | self.datablock.fill(0) |
|
646 | 661 | |
@@ -678,12 +693,12 class VoltageWriter(JRODataWriter, Operation): | |||
|
678 | 693 | if self.profileIndex == 0: |
|
679 | 694 | self.setBasicHeader() |
|
680 | 695 | |
|
681 | self.datablock[:,self.profileIndex,:] = self.dataOut.data | |
|
696 | self.datablock[:, self.profileIndex, :] = self.dataOut.data | |
|
682 | 697 | |
|
683 | 698 | self.profileIndex += 1 |
|
684 | 699 | |
|
685 | 700 | if self.hasAllDataInBuffer(): |
|
686 | #if self.flagIsNewFile: | |
|
701 | # if self.flagIsNewFile: | |
|
687 | 702 | self.writeNextBlock() |
|
688 | 703 | # self.setFirstHeader() |
|
689 | 704 | |
@@ -696,12 +711,12 class VoltageWriter(JRODataWriter, Operation): | |||
|
696 | 711 | |
|
697 | 712 | dtype_width = self.getDtypeWidth() |
|
698 | 713 | |
|
699 |
blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * |
|
|
714 | blocksize = int(self.dataOut.nHeights * self.dataOut.nChannels * | |
|
715 | self.profilesPerBlock * dtype_width * 2) | |
|
700 | 716 | |
|
701 | 717 | return blocksize |
|
702 | 718 | |
|
703 | 719 | def setFirstHeader(self): |
|
704 | ||
|
705 | 720 | """ |
|
706 | 721 | Obtiene una copia del First Header |
|
707 | 722 | |
@@ -718,14 +733,17 class VoltageWriter(JRODataWriter, Operation): | |||
|
718 | 733 | self.systemHeaderObj.nChannels = self.dataOut.nChannels |
|
719 | 734 | self.radarControllerHeaderObj = self.dataOut.radarControllerHeaderObj.copy() |
|
720 | 735 | |
|
721 | self.processingHeaderObj.dtype = 0 # Voltage | |
|
736 | self.processingHeaderObj.dtype = 0 # Voltage | |
|
722 | 737 | self.processingHeaderObj.blockSize = self.__getBlockSize() |
|
723 | 738 | self.processingHeaderObj.profilesPerBlock = self.profilesPerBlock |
|
724 | 739 | self.processingHeaderObj.dataBlocksPerFile = self.blocksPerFile |
|
725 |
|
|
|
740 | # podria ser 1 o self.dataOut.processingHeaderObj.nWindows | |
|
741 | self.processingHeaderObj.nWindows = 1 | |
|
726 | 742 | self.processingHeaderObj.nCohInt = self.dataOut.nCohInt |
|
727 |
|
|
|
728 | self.processingHeaderObj.totalSpectra = 0 # Cuando la data de origen es de tipo Voltage | |
|
743 | # Cuando la data de origen es de tipo Voltage | |
|
744 | self.processingHeaderObj.nIncohInt = 1 | |
|
745 | # Cuando la data de origen es de tipo Voltage | |
|
746 | self.processingHeaderObj.totalSpectra = 0 | |
|
729 | 747 | |
|
730 | 748 | if self.dataOut.code is not None: |
|
731 | 749 | self.processingHeaderObj.code = self.dataOut.code |
@@ -734,7 +752,8 class VoltageWriter(JRODataWriter, Operation): | |||
|
734 | 752 | |
|
735 | 753 | if self.processingHeaderObj.nWindows != 0: |
|
736 | 754 | self.processingHeaderObj.firstHeight = self.dataOut.heightList[0] |
|
737 |
self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - |
|
|
755 | self.processingHeaderObj.deltaHeight = self.dataOut.heightList[1] - \ | |
|
756 | self.dataOut.heightList[0] | |
|
738 | 757 | self.processingHeaderObj.nHeights = self.dataOut.nHeights |
|
739 | 758 | self.processingHeaderObj.samplesWin = self.dataOut.nHeights |
|
740 | 759 |
@@ -6,8 +6,8 from jroproc_base import ProcessingUnit, Operation | |||
|
6 | 6 | from schainpy.model.data.jroamisr import AMISR |
|
7 | 7 | |
|
8 | 8 | class AMISRProc(ProcessingUnit): |
|
9 | def __init__(self): | |
|
10 | ProcessingUnit.__init__(self) | |
|
9 | def __init__(self, **kwargs): | |
|
10 | ProcessingUnit.__init__(self, **kwargs) | |
|
11 | 11 | self.objectDict = {} |
|
12 | 12 | self.dataOut = AMISR() |
|
13 | 13 | |
@@ -17,7 +17,8 class AMISRProc(ProcessingUnit): | |||
|
17 | 17 | |
|
18 | 18 | |
|
19 | 19 | class PrintInfo(Operation): |
|
20 | def __init__(self): | |
|
20 | def __init__(self, **kwargs): | |
|
21 | Operation.__init__(self, **kwargs) | |
|
21 | 22 | self.__isPrinted = False |
|
22 | 23 | |
|
23 | 24 | def run(self, dataOut): |
@@ -42,8 +43,8 class BeamSelector(Operation): | |||
|
42 | 43 | profileIndex = None |
|
43 | 44 | nProfiles = None |
|
44 | 45 | |
|
45 | def __init__(self): | |
|
46 | ||
|
46 | def __init__(self, **kwargs): | |
|
47 | Operation.__init__(self, **kwargs) | |
|
47 | 48 | self.profileIndex = 0 |
|
48 | 49 | self.__isConfig = False |
|
49 | 50 | |
@@ -98,7 +99,8 class BeamSelector(Operation): | |||
|
98 | 99 | |
|
99 | 100 | class ProfileToChannels(Operation): |
|
100 | 101 | |
|
101 | def __init__(self): | |
|
102 | def __init__(self, **kwargs): | |
|
103 | Operation.__init__(self, **kwargs) | |
|
102 | 104 | self.__isConfig = False |
|
103 | 105 | self.__counter_chan = 0 |
|
104 | 106 | self.buffer = None |
@@ -17,7 +17,6 from functools import partial | |||
|
17 | 17 | import time |
|
18 | 18 | #from sklearn.cluster import KMeans |
|
19 | 19 | |
|
20 | import matplotlib.pyplot as plt | |
|
21 | 20 | |
|
22 | 21 | from scipy.optimize import fmin_l_bfgs_b #optimize with bounds on state papameters |
|
23 | 22 | from jroproc_base import ProcessingUnit, Operation |
@@ -1766,8 +1765,8 class WindProfiler(Operation): | |||
|
1766 | 1765 | |
|
1767 | 1766 | n = None |
|
1768 | 1767 | |
|
1769 | def __init__(self): | |
|
1770 | Operation.__init__(self) | |
|
1768 | def __init__(self, **kwargs): | |
|
1769 | Operation.__init__(self, **kwargs) | |
|
1771 | 1770 | |
|
1772 | 1771 | def __calculateCosDir(self, elev, azim): |
|
1773 | 1772 | zen = (90 - elev)*numpy.pi/180 |
@@ -2473,8 +2472,8 class WindProfiler(Operation): | |||
|
2473 | 2472 | |
|
2474 | 2473 | class EWDriftsEstimation(Operation): |
|
2475 | 2474 | |
|
2476 | def __init__(self): | |
|
2477 | Operation.__init__(self) | |
|
2475 | def __init__(self, **kwargs): | |
|
2476 | Operation.__init__(self, **kwargs) | |
|
2478 | 2477 | |
|
2479 | 2478 | def __correctValues(self, heiRang, phi, velRadial, SNR): |
|
2480 | 2479 | listPhi = phi.tolist() |
@@ -142,7 +142,7 class SpectraProc(ProcessingUnit): | |||
|
142 | 142 | if self.dataIn.flagDataAsBlock: |
|
143 | 143 | #data dimension: [nChannels, nProfiles, nSamples] |
|
144 | 144 | nVoltProfiles = self.dataIn.data.shape[1] |
|
145 | # nVoltProfiles = self.dataIn.nProfiles | |
|
145 | # nVoltProfiles = self.dataIn.nProfiles | |
|
146 | 146 | |
|
147 | 147 | if nVoltProfiles == nProfiles: |
|
148 | 148 | self.buffer = self.dataIn.data.copy() |
@@ -197,7 +197,6 class SpectraProc(ProcessingUnit): | |||
|
197 | 197 | |
|
198 | 198 | self.dataOut.data_cspc = self.dataOut.data_cspc[pairsIndex] |
|
199 | 199 | self.dataOut.pairsList = pairs |
|
200 | self.dataOut.pairsIndexList = pairsIndex | |
|
201 | 200 | |
|
202 | 201 | return |
|
203 | 202 | |
@@ -877,7 +876,6 class IncohInt(Operation): | |||
|
877 | 876 | return self.__initime, avgdata_spc, avgdata_cspc, avgdata_dc |
|
878 | 877 | |
|
879 | 878 | def run(self, dataOut, n=None, timeInterval=None, overlapping=False): |
|
880 | ||
|
881 | 879 | if n==1: |
|
882 | 880 | return |
|
883 | 881 | |
@@ -901,4 +899,3 class IncohInt(Operation): | |||
|
901 | 899 | dataOut.nIncohInt *= self.n |
|
902 | 900 | dataOut.utctime = avgdatatime |
|
903 | 901 | dataOut.flagNoData = False |
|
904 |
@@ -1,1 +1,1 | |||
|
1 | <Project description="Claire" id="002" name="script02"><ReadUnit datatype="VoltageReader" id="21" inputId="0" name="VoltageReader"><Operation id="211" name="run" priority="1" type="self"><Parameter format="str" id="2111" name="datatype" value="VoltageReader" /><Parameter format="str" id="2112" name="path" value="/media/nanosat/0BDE10E00BDE10E0/CLAIRE" /><Parameter format="date" id="2113" name="startDate" value="2017/07/26" /><Parameter format="date" id="2114" name="endDate" value="2017/07/26" /><Parameter format="time" id="2115" name="startTime" value="15:00:00" /><Parameter format="time" id="2116" name="endTime" value="16:00:00" /><Parameter format="int" id="2118" name="delay" value="30" /><Parameter format="int" id="2119" name="walk" value="1" /><Parameter format="int" id="2120" name="online" value="0" /></Operation><Operation id="212" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="VoltageProc" id="22" inputId="21" name="VoltageProc"><Operation id="221" name="run" priority="1" type="self" /></ProcUnit><ProcUnit datatype="SpectraProc" id="23" inputId="22" name="SpectraProc"><Operation id="231" name="run" priority="1" type="self"><Parameter format="int" id="2311" name="nFFTPoints" value="128" /><Parameter format="int" id="2312" name="nProfiles" value="128" /><Parameter format="pairslist" id="2313" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="232" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="2321" name="frequency" value="445000000.0" /></Operation><Operation id="233" name="IncohInt" priority="3" type="other"><Parameter format="float" id="2331" name="timeInterval" value="128" /></Operation><Operation id="234" name="removeDC" priority="4" type="self"><Parameter format="int" id="2341" name="mode" value="2" /></Operation><Operation id="235" name="RTIPlot" priority="5" type="other"><Parameter format="int" id="2351" name="id" value="237" /><Parameter format="float" id="2352" name="xmin" value="9.0" /><Parameter format="float" id="2353" name="xmax" value="16.0" /><Parameter format="float" id="2354" name="zmin" value="15.0" /><Parameter format="float" id="2355" name="zmax" value="50.0" /></Operation></ProcUnit></Project> No newline at end of file | |
|
1 | <Project description="Claire" id="002" name="script02"><ReadUnit datatype="VoltageReader" id="21" inputId="0" name="VoltageReader"><Operation id="211" name="run" priority="1" type="self"><Parameter format="str" id="2111" name="datatype" value="VoltageReader" /><Parameter format="str" id="2112" name="path" value="/media/nanosat/0BDE10E00BDE10E0/CLAIRE" /><Parameter format="date" id="2113" name="startDate" value="2017/07/26" /><Parameter format="date" id="2114" name="endDate" value="2017/07/26" /><Parameter format="time" id="2115" name="startTime" value="15:00:00" /><Parameter format="time" id="2116" name="endTime" value="16:00:00" /><Parameter format="int" id="2118" name="delay" value="30" /><Parameter format="int" id="2119" name="walk" value="1" /><Parameter format="int" id="2120" name="online" value="0" /></Operation><Operation id="212" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="VoltageProc" id="22" inputId="21" name="VoltageProc"><Operation id="221" name="run" priority="1" type="self" /></ProcUnit><ProcUnit datatype="SpectraProc" id="23" inputId="22" name="SpectraProc"><Operation id="231" name="run" priority="1" type="self"><Parameter format="int" id="2311" name="nFFTPoints" value="128" /><Parameter format="int" id="2312" name="nProfiles" value="128" /><Parameter format="pairslist" id="2313" name="pairsList" value="(0,1),(0,2),(1,2)" /></Operation><Operation id="232" name="setRadarFrequency" priority="2" type="self"><Parameter format="float" id="2321" name="frequency" value="445000000.0" /></Operation><Operation id="233" name="IncohInt" priority="3" type="other"><Parameter format="float" id="2331" name="timeInterval" value="128" /></Operation><Operation id="234" name="removeDC" priority="4" type="self"><Parameter format="int" id="2341" name="mode" value="2" /></Operation><Operation id="235" name="RTIPlot" priority="5" type="other"><Parameter format="int" id="2351" name="id" value="237" /><Parameter format="float" id="2352" name="xmin" value="9.0" /><Parameter format="float" id="2353" name="xmax" value="16.0" /><Parameter format="float" id="2354" name="zmin" value="15.0" /><Parameter format="float" id="2355" name="zmax" value="50.0" /></Operation></ProcUnit></Project> |
@@ -17,6 +17,7 SCHAINPY - LOG | |||
|
17 | 17 | |
|
18 | 18 | import click |
|
19 | 19 | |
|
20 | ||
|
20 | 21 | def warning(message, tag='Warning'): |
|
21 | 22 | click.echo(click.style('[{}] {}'.format(tag, message), fg='yellow')) |
|
22 | 23 | pass |
@@ -39,6 +40,6 def log(message, tag='Info'): | |||
|
39 | 40 | |
|
40 | 41 | def makelogger(tag, bg='reset', fg='reset'): |
|
41 | 42 | def func(message): |
|
42 |
click.echo(click.style('[{}] {}'.format( |
|
|
43 |
|
|
|
43 | click.echo(click.style('[{}] {}'.format( | |
|
44 | tag.upper(), message), bg=bg, fg=fg)) | |
|
44 | 45 | return func |
@@ -8,6 +8,7 from setuptools import setup, Extension | |||
|
8 | 8 | from setuptools.command.build_ext import build_ext as _build_ext |
|
9 | 9 | from schainpy import __version__ |
|
10 | 10 | |
|
11 | ||
|
11 | 12 | class build_ext(_build_ext): |
|
12 | 13 | def finalize_options(self): |
|
13 | 14 | _build_ext.finalize_options(self) |
@@ -23,7 +24,7 setup(name="schainpy", | |||
|
23 | 24 | author="Miguel Urco", |
|
24 | 25 | author_email="miguel.urco@jro.igp.gob.pe", |
|
25 | 26 | url="http://jro.igp.gob.pe", |
|
26 |
packages |
|
|
27 | packages={'schainpy', | |
|
27 | 28 | 'schainpy.model', |
|
28 | 29 | 'schainpy.model.data', |
|
29 | 30 | 'schainpy.model.graphics', |
@@ -39,31 +40,30 setup(name="schainpy", | |||
|
39 | 40 | ext_package='schainpy', |
|
40 | 41 | py_modules=[''], |
|
41 | 42 | package_data={'': ['schain.conf.template'], |
|
42 | 'schainpy.gui.figures': ['*.png','*.jpg'], | |
|
43 | 'schainpy.gui.figures': ['*.png', '*.jpg'], | |
|
43 | 44 | }, |
|
44 | 45 | include_package_data=False, |
|
45 |
scripts |
|
|
46 | scripts=['schainpy/gui/schainGUI'], | |
|
46 | 47 | ext_modules=[ |
|
47 | Extension("cSchain", ["schainpy/model/proc/extensions.c"] | |
|
48 | )], | |
|
48 | Extension("cSchain", ["schainpy/model/proc/extensions.c"] | |
|
49 | )], | |
|
49 | 50 | entry_points={ |
|
50 | 'console_scripts': [ | |
|
51 | 'schain = schaincli.cli:main', | |
|
52 | ], | |
|
51 | 'console_scripts': [ | |
|
52 | 'schain = schaincli.cli:main', | |
|
53 | ], | |
|
53 | 54 | }, |
|
54 | cmdclass={'build_ext':build_ext}, | |
|
55 | cmdclass={'build_ext': build_ext}, | |
|
55 | 56 | setup_requires=["numpy >= 1.11.2"], |
|
56 | 57 | install_requires=[ |
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 | "pyfits >= 3.4", | |
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
|
|
|
66 | "colorama", | |
|
67 | "python-Levenshtein" | |
|
68 | ], | |
|
69 | ) | |
|
58 | "scipy >= 0.14.0", | |
|
59 | "h5py >= 2.2.1", | |
|
60 | "matplotlib >= 1.4.2", | |
|
61 | "pyfits >= 3.4", | |
|
62 | "paramiko >= 2.1.2", | |
|
63 | "paho-mqtt >= 1.2", | |
|
64 | "zmq", | |
|
65 | "fuzzywuzzy", | |
|
66 | "click", | |
|
67 | "python-Levenshtein" | |
|
68 | ], | |
|
69 | ) |
|
1 | NO CONTENT: file was removed |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now