@@ -17,6 +17,7 import datetime | |||||
17 | import numpy |
|
17 | import numpy | |
18 | import timeit |
|
18 | import timeit | |
19 | from fractions import Fraction |
|
19 | from fractions import Fraction | |
|
20 | from time import time | |||
20 |
|
21 | |||
21 | import schainpy.admin |
|
22 | import schainpy.admin | |
22 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader |
|
23 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
@@ -42,17 +43,18 class DigitalRFReader(ProcessingUnit): | |||||
42 |
|
43 | |||
43 | ProcessingUnit.__init__(self) |
|
44 | ProcessingUnit.__init__(self) | |
44 |
|
45 | |||
45 | self.dataOut = Voltage() |
|
46 | self.dataOut = Voltage() | |
46 | self.__printInfo = True |
|
47 | self.__printInfo = True | |
47 | self.__flagDiscontinuousBlock = False |
|
48 | self.__flagDiscontinuousBlock = False | |
48 | self.__bufferIndex = 9999999 |
|
49 | self.__bufferIndex = 9999999 | |
49 |
self.__ |
|
50 | self.__codeType = 0 | |
50 |
self.__ |
|
51 | self.__ippKm = None | |
51 | self.__nCode = None |
|
52 | self.__nCode = None | |
52 | self.__nBaud = None |
|
53 | self.__nBaud = None | |
53 | self.__code = None |
|
54 | self.__code = None | |
54 | self.dtype = None |
|
55 | self.dtype = None | |
55 | self.oldAverage = None |
|
56 | self.oldAverage = None | |
|
57 | self.path = None | |||
56 |
|
58 | |||
57 | def close(self): |
|
59 | def close(self): | |
58 | print('Average of writing to digital rf format is ', self.oldAverage * 1000) |
|
60 | print('Average of writing to digital rf format is ', self.oldAverage * 1000) | |
@@ -95,9 +97,9 class DigitalRFReader(ProcessingUnit): | |||||
95 | nChannels=len( |
|
97 | nChannels=len( | |
96 | self.__channelList), |
|
98 | self.__channelList), | |
97 | adcResolution=14) |
|
99 | adcResolution=14) | |
98 | self.dataOut.type = "Voltage" |
|
100 | self.dataOut.type = "Voltage" | |
99 |
|
101 | |||
100 | self.dataOut.data = None |
|
102 | self.dataOut.data = None | |
101 |
|
103 | |||
102 | self.dataOut.dtype = self.dtype |
|
104 | self.dataOut.dtype = self.dtype | |
103 |
|
105 | |||
@@ -105,32 +107,32 class DigitalRFReader(ProcessingUnit): | |||||
105 |
|
107 | |||
106 | # self.dataOut.nHeights = 0 |
|
108 | # self.dataOut.nHeights = 0 | |
107 |
|
109 | |||
108 | self.dataOut.nProfiles = int(nProfiles) |
|
110 | self.dataOut.nProfiles = int(nProfiles) | |
109 |
|
111 | |||
110 | self.dataOut.heightList = self.__firstHeigth + \ |
|
112 | self.dataOut.heightList = self.__firstHeigth + \ | |
111 | numpy.arange(self.__nSamples, dtype=numpy.float) * \ |
|
113 | numpy.arange(self.__nSamples, dtype=numpy.float) * \ | |
112 | self.__deltaHeigth |
|
114 | self.__deltaHeigth | |
113 |
|
115 | |||
114 | self.dataOut.channelList = list(range(self.__num_subchannels)) |
|
116 | self.dataOut.channelList = list(range(self.__num_subchannels)) | |
115 |
|
117 | |||
116 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() |
|
118 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
117 |
|
119 | |||
118 | # self.dataOut.channelIndexList = None |
|
120 | # self.dataOut.channelIndexList = None | |
119 |
|
121 | |||
120 | self.dataOut.flagNoData = True |
|
122 | self.dataOut.flagNoData = True | |
121 |
|
123 | |||
122 | self.dataOut.flagDataAsBlock = False |
|
124 | self.dataOut.flagDataAsBlock = False | |
123 | # Set to TRUE if the data is discontinuous |
|
125 | # Set to TRUE if the data is discontinuous | |
124 | self.dataOut.flagDiscontinuousBlock = False |
|
126 | self.dataOut.flagDiscontinuousBlock = False | |
125 |
|
127 | |||
126 | self.dataOut.utctime = None |
|
128 | self.dataOut.utctime = None | |
127 |
|
129 | |||
128 | # timezone like jroheader, difference in minutes between UTC and localtime |
|
130 | # timezone like jroheader, difference in minutes between UTC and localtime | |
129 | self.dataOut.timeZone = self.__timezone / 60 |
|
131 | self.dataOut.timeZone = self.__timezone / 60 | |
130 |
|
132 | |||
131 | self.dataOut.dstFlag = 0 |
|
133 | self.dataOut.dstFlag = 0 | |
132 |
|
134 | |||
133 | self.dataOut.errorCount = 0 |
|
135 | self.dataOut.errorCount = 0 | |
134 |
|
136 | |||
135 | try: |
|
137 | try: | |
136 | self.dataOut.nCohInt = self.fixed_metadata_dict.get( |
|
138 | self.dataOut.nCohInt = self.fixed_metadata_dict.get( | |
@@ -143,9 +145,9 class DigitalRFReader(ProcessingUnit): | |||||
143 | # asumo que la data esta sin flip |
|
145 | # asumo que la data esta sin flip | |
144 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] |
|
146 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] | |
145 |
|
147 | |||
146 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] |
|
148 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] | |
147 |
|
149 | |||
148 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] |
|
150 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] | |
149 | except: |
|
151 | except: | |
150 | pass |
|
152 | pass | |
151 |
|
153 | |||
@@ -154,9 +156,9 class DigitalRFReader(ProcessingUnit): | |||||
154 | # Time interval between profiles |
|
156 | # Time interval between profiles | |
155 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
157 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
156 |
|
158 | |||
157 | self.dataOut.frequency = self.__frequency |
|
159 | self.dataOut.frequency = self.__frequency | |
158 |
|
160 | |||
159 | self.dataOut.realtime = self.__online |
|
161 | self.dataOut.realtime = self.__online | |
160 |
|
162 | |||
161 | def findDatafiles(self, path, startDate=None, endDate=None): |
|
163 | def findDatafiles(self, path, startDate=None, endDate=None): | |
162 |
|
164 | |||
@@ -169,46 +171,46 class DigitalRFReader(ProcessingUnit): | |||||
169 | except: |
|
171 | except: | |
170 | digitalReadObj = digital_rf.DigitalRFReader(path) |
|
172 | digitalReadObj = digital_rf.DigitalRFReader(path) | |
171 |
|
173 | |||
172 | channelNameList = digitalReadObj.get_channels() |
|
174 | channelNameList = digitalReadObj.get_channels() | |
173 |
|
175 | |||
174 | if not channelNameList: |
|
176 | if not channelNameList: | |
175 | return [] |
|
177 | return [] | |
176 |
|
178 | |||
177 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) |
|
179 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) | |
178 |
|
180 | |||
179 | sample_rate = metadata_dict['sample_rate'][0] |
|
181 | sample_rate = metadata_dict['sample_rate'][0] | |
180 |
|
182 | |||
181 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) |
|
183 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) | |
182 |
|
184 | |||
183 | try: |
|
185 | try: | |
184 | timezone = this_metadata_file['timezone'].value |
|
186 | timezone = this_metadata_file['timezone'].value | |
185 | except: |
|
187 | except: | |
186 | timezone = 0 |
|
188 | timezone = 0 | |
187 |
|
189 | |||
188 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( |
|
190 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( | |
189 | channelNameList[0]) / sample_rate - timezone |
|
191 | channelNameList[0]) / sample_rate - timezone | |
190 |
|
192 | |||
191 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) |
|
193 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) | |
192 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) |
|
194 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) | |
193 |
|
195 | |||
194 | if not startDate: |
|
196 | if not startDate: | |
195 | startDate = startDatetime.date() |
|
197 | startDate = startDatetime.date() | |
196 |
|
198 | |||
197 | if not endDate: |
|
199 | if not endDate: | |
198 | endDate = endDatatime.date() |
|
200 | endDate = endDatatime.date() | |
199 |
|
201 | |||
200 | dateList = [] |
|
202 | dateList = [] | |
201 |
|
203 | |||
202 | thisDatetime = startDatetime |
|
204 | thisDatetime = startDatetime | |
203 |
|
205 | |||
204 | while(thisDatetime <= endDatatime): |
|
206 | while(thisDatetime <= endDatatime): | |
205 |
|
207 | |||
206 | thisDate = thisDatetime.date() |
|
208 | thisDate = thisDatetime.date() | |
207 |
|
209 | |||
208 | if thisDate < startDate: |
|
210 | if thisDate < startDate: | |
209 | continue |
|
211 | continue | |
210 |
|
212 | |||
211 | if thisDate > endDate: |
|
213 | if thisDate > endDate: | |
212 | break |
|
214 | break | |
213 |
|
215 | |||
214 | dateList.append(thisDate) |
|
216 | dateList.append(thisDate) | |
@@ -241,16 +243,17 class DigitalRFReader(ProcessingUnit): | |||||
241 | startDate |
|
243 | startDate | |
242 | endDate |
|
244 | endDate | |
243 | startTime |
|
245 | startTime | |
244 |
endTime |
|
246 | endTime | |
245 | set |
|
247 | set | |
246 | expLabel |
|
248 | expLabel | |
247 | ext |
|
249 | ext | |
248 | online |
|
250 | online | |
249 | delay |
|
251 | delay | |
250 | ''' |
|
252 | ''' | |
251 | self.nCohInt = nCohInt |
|
253 | self.path = path | |
|
254 | self.nCohInt = nCohInt | |||
252 | self.flagDecodeData = flagDecodeData |
|
255 | self.flagDecodeData = flagDecodeData | |
253 | self.i = 0 |
|
256 | self.i = 0 | |
254 | if not os.path.isdir(path): |
|
257 | if not os.path.isdir(path): | |
255 | raise ValueError("[Reading] Directory %s does not exist" % path) |
|
258 | raise ValueError("[Reading] Directory %s does not exist" % path) | |
256 |
|
259 | |||
@@ -260,7 +263,7 class DigitalRFReader(ProcessingUnit): | |||||
260 | except: |
|
263 | except: | |
261 | self.digitalReadObj = digital_rf.DigitalRFReader(path) |
|
264 | self.digitalReadObj = digital_rf.DigitalRFReader(path) | |
262 |
|
265 | |||
263 | channelNameList = self.digitalReadObj.get_channels() |
|
266 | channelNameList = self.digitalReadObj.get_channels() | |
264 |
|
267 | |||
265 | if not channelNameList: |
|
268 | if not channelNameList: | |
266 | raise ValueError("[Reading] Directory %s does not have any files" % path) |
|
269 | raise ValueError("[Reading] Directory %s does not have any files" % path) | |
@@ -270,27 +273,27 class DigitalRFReader(ProcessingUnit): | |||||
270 |
|
273 | |||
271 | ########## Reading metadata ###################### |
|
274 | ########## Reading metadata ###################### | |
272 |
|
275 | |||
273 | top_properties = self.digitalReadObj.get_properties( |
|
276 | top_properties = self.digitalReadObj.get_properties( | |
274 | channelNameList[channelList[0]]) |
|
277 | channelNameList[channelList[0]]) | |
275 |
|
278 | |||
276 | self.__num_subchannels = top_properties['num_subchannels'] |
|
279 | self.__num_subchannels = top_properties['num_subchannels'] | |
277 | self.__sample_rate = 1.0 * \ |
|
280 | self.__sample_rate = 1.0 * \ | |
278 | top_properties['sample_rate_numerator'] / \ |
|
281 | top_properties['sample_rate_numerator'] / \ | |
279 | top_properties['sample_rate_denominator'] |
|
282 | top_properties['sample_rate_denominator'] | |
280 | # self.__samples_per_file = top_properties['samples_per_file'][0] |
|
283 | # self.__samples_per_file = top_properties['samples_per_file'][0] | |
281 | self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15? |
|
284 | self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15? | |
282 |
|
285 | |||
283 | this_metadata_file = self.digitalReadObj.get_digital_metadata( |
|
286 | this_metadata_file = self.digitalReadObj.get_digital_metadata( | |
284 | channelNameList[channelList[0]]) |
|
287 | channelNameList[channelList[0]]) | |
285 | metadata_bounds = this_metadata_file.get_bounds() |
|
288 | metadata_bounds = this_metadata_file.get_bounds() | |
286 | self.fixed_metadata_dict = this_metadata_file.read( |
|
289 | self.fixed_metadata_dict = this_metadata_file.read( | |
287 | metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER |
|
290 | metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER | |
288 |
|
291 | |||
289 | try: |
|
292 | try: | |
290 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] |
|
293 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] | |
291 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] |
|
294 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] | |
292 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] |
|
295 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] | |
293 | self.dtype = pickle.loads(self.fixed_metadata_dict['dtype']) |
|
296 | self.dtype = pickle.loads(self.fixed_metadata_dict['dtype']) | |
294 | except: |
|
297 | except: | |
295 | pass |
|
298 | pass | |
296 |
|
299 | |||
@@ -298,7 +301,7 class DigitalRFReader(ProcessingUnit): | |||||
298 |
|
301 | |||
299 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) |
|
302 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) | |
300 |
|
303 | |||
301 |
self.__timezone = self.fixed_metadata_dict.get('timezone', |
|
304 | self.__timezone = self.fixed_metadata_dict.get('timezone', 18000) | |
302 |
|
305 | |||
303 | try: |
|
306 | try: | |
304 | nSamples = self.fixed_metadata_dict['nSamples'] |
|
307 | nSamples = self.fixed_metadata_dict['nSamples'] | |
@@ -308,15 +311,15 class DigitalRFReader(ProcessingUnit): | |||||
308 | self.__firstHeigth = 0 |
|
311 | self.__firstHeigth = 0 | |
309 |
|
312 | |||
310 | try: |
|
313 | try: | |
311 | codeType = self.__radarControllerHeader['codeType'] |
|
314 | codeType = self.__radarControllerHeader['codeType'] | |
312 | except: |
|
315 | except: | |
313 | codeType = 0 |
|
316 | codeType = 0 | |
314 |
|
317 | |||
315 | try: |
|
318 | try: | |
316 | if codeType: |
|
319 | if codeType: | |
317 | nCode = self.__radarControllerHeader['nCode'] |
|
320 | nCode = self.__radarControllerHeader['nCode'] | |
318 | nBaud = self.__radarControllerHeader['nBaud'] |
|
321 | nBaud = self.__radarControllerHeader['nBaud'] | |
319 | code = self.__radarControllerHeader['code'] |
|
322 | code = self.__radarControllerHeader['code'] | |
320 | except: |
|
323 | except: | |
321 | pass |
|
324 | pass | |
322 |
|
325 | |||
@@ -327,18 +330,18 class DigitalRFReader(ProcessingUnit): | |||||
327 | except: |
|
330 | except: | |
328 | ippKm = None |
|
331 | ippKm = None | |
329 | #################################################### |
|
332 | #################################################### | |
330 | self.__ippKm = ippKm |
|
333 | self.__ippKm = ippKm | |
331 | startUTCSecond = None |
|
334 | startUTCSecond = None | |
332 | endUTCSecond = None |
|
335 | endUTCSecond = None | |
333 |
|
336 | |||
334 | if startDate: |
|
337 | if startDate: | |
335 | startDatetime = datetime.datetime.combine(startDate, startTime) |
|
338 | startDatetime = datetime.datetime.combine(startDate, startTime) | |
336 | startUTCSecond = ( |
|
339 | startUTCSecond = ( | |
337 | startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone |
|
340 | startDatetime - datetime.datetime(1970, 1, 1)).total_seconds() + self.__timezone | |
338 |
|
341 | |||
339 | if endDate: |
|
342 | if endDate: | |
340 | endDatetime = datetime.datetime.combine(endDate, endTime) |
|
343 | endDatetime = datetime.datetime.combine(endDate, endTime) | |
341 | endUTCSecond = (endDatetime - datetime.datetime(1970, |
|
344 | endUTCSecond = (endDatetime - datetime.datetime(1970, | |
342 | 1, 1)).total_seconds() + self.__timezone |
|
345 | 1, 1)).total_seconds() + self.__timezone | |
343 |
|
346 | |||
344 | start_index, end_index = self.digitalReadObj.get_bounds( |
|
347 | start_index, end_index = self.digitalReadObj.get_bounds( | |
@@ -347,50 +350,50 class DigitalRFReader(ProcessingUnit): | |||||
347 | if not startUTCSecond: |
|
350 | if not startUTCSecond: | |
348 | startUTCSecond = start_index / self.__sample_rate |
|
351 | startUTCSecond = start_index / self.__sample_rate | |
349 |
|
352 | |||
350 | if start_index > startUTCSecond * self.__sample_rate: |
|
353 | if start_index > startUTCSecond * self.__sample_rate: | |
351 | startUTCSecond = start_index / self.__sample_rate |
|
354 | startUTCSecond = start_index / self.__sample_rate | |
352 |
|
355 | |||
353 | if not endUTCSecond: |
|
356 | if not endUTCSecond: | |
354 | endUTCSecond = end_index / self.__sample_rate |
|
357 | endUTCSecond = end_index / self.__sample_rate | |
355 |
|
358 | |||
356 | if end_index < endUTCSecond * self.__sample_rate: |
|
359 | if end_index < endUTCSecond * self.__sample_rate: | |
357 | endUTCSecond = end_index / self.__sample_rate |
|
360 | endUTCSecond = end_index / self.__sample_rate | |
358 | if not nSamples: |
|
361 | if not nSamples: | |
359 | if not ippKm: |
|
362 | if not ippKm: | |
360 | raise ValueError("[Reading] nSamples or ippKm should be defined") |
|
363 | raise ValueError("[Reading] nSamples or ippKm should be defined") | |
361 | nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate)) |
|
364 | nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate)) | |
362 | channelBoundList = [] |
|
365 | channelBoundList = [] | |
363 | channelNameListFiltered = [] |
|
366 | channelNameListFiltered = [] | |
364 |
|
367 | |||
365 | for thisIndexChannel in channelList: |
|
368 | for thisIndexChannel in channelList: | |
366 | thisChannelName = channelNameList[thisIndexChannel] |
|
369 | thisChannelName = channelNameList[thisIndexChannel] | |
367 | start_index, end_index = self.digitalReadObj.get_bounds( |
|
370 | start_index, end_index = self.digitalReadObj.get_bounds( | |
368 | thisChannelName) |
|
371 | thisChannelName) | |
369 | channelBoundList.append((start_index, end_index)) |
|
372 | channelBoundList.append((start_index, end_index)) | |
370 | channelNameListFiltered.append(thisChannelName) |
|
373 | channelNameListFiltered.append(thisChannelName) | |
371 |
|
374 | |||
372 | self.profileIndex = 0 |
|
375 | self.profileIndex = 0 | |
373 | self.i = 0 |
|
376 | self.i = 0 | |
374 | self.__delay = delay |
|
377 | self.__delay = delay | |
375 |
|
378 | |||
376 | self.__codeType = codeType |
|
379 | self.__codeType = codeType | |
377 | self.__nCode = nCode |
|
380 | self.__nCode = nCode | |
378 | self.__nBaud = nBaud |
|
381 | self.__nBaud = nBaud | |
379 | self.__code = code |
|
382 | self.__code = code | |
380 |
|
383 | |||
381 | self.__datapath = path |
|
384 | self.__datapath = path | |
382 | self.__online = online |
|
385 | self.__online = online | |
383 | self.__channelList = channelList |
|
386 | self.__channelList = channelList | |
384 | self.__channelNameList = channelNameListFiltered |
|
387 | self.__channelNameList = channelNameListFiltered | |
385 | self.__channelBoundList = channelBoundList |
|
388 | self.__channelBoundList = channelBoundList | |
386 | self.__nSamples = nSamples |
|
389 | self.__nSamples = nSamples | |
387 | self.__samples_to_read = int(nSamples) # FIJO: AHORA 40 |
|
390 | self.__samples_to_read = int(nSamples) # FIJO: AHORA 40 | |
388 | self.__nChannels = len(self.__channelList) |
|
391 | self.__nChannels = len(self.__channelList) | |
389 |
|
392 | |||
390 | self.__startUTCSecond = startUTCSecond |
|
393 | self.__startUTCSecond = startUTCSecond | |
391 | self.__endUTCSecond = endUTCSecond |
|
394 | self.__endUTCSecond = endUTCSecond | |
392 |
|
395 | |||
393 | self.__timeInterval = 1.0 * self.__samples_to_read / \ |
|
396 | self.__timeInterval = 1.0 * self.__samples_to_read / \ | |
394 | self.__sample_rate # Time interval |
|
397 | self.__sample_rate # Time interval | |
395 |
|
398 | |||
396 | if online: |
|
399 | if online: | |
@@ -398,10 +401,9 class DigitalRFReader(ProcessingUnit): | |||||
398 | startUTCSecond = numpy.floor(endUTCSecond) |
|
401 | startUTCSecond = numpy.floor(endUTCSecond) | |
399 |
|
402 | |||
400 | # por que en el otro metodo lo primero q se hace es sumar samplestoread |
|
403 | # por que en el otro metodo lo primero q se hace es sumar samplestoread | |
401 | self.__thisUnixSample = int( |
|
404 | self.__thisUnixSample = int(startUTCSecond * self.__sample_rate) - self.__samples_to_read | |
402 | startUTCSecond * self.__sample_rate) - self.__samples_to_read |
|
|||
403 |
|
405 | |||
404 | self.__data_buffer = numpy.zeros( |
|
406 | self.__data_buffer = numpy.zeros( | |
405 | (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex) |
|
407 | (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex) | |
406 |
|
408 | |||
407 | self.__setFileHeader() |
|
409 | self.__setFileHeader() | |
@@ -418,8 +420,8 class DigitalRFReader(ProcessingUnit): | |||||
418 | datetime.datetime.utcfromtimestamp( |
|
420 | datetime.datetime.utcfromtimestamp( | |
419 | endUTCSecond - self.__timezone) |
|
421 | endUTCSecond - self.__timezone) | |
420 | )) |
|
422 | )) | |
421 | self.oldAverage = None |
|
423 | self.oldAverage = None | |
422 | self.count = 0 |
|
424 | self.count = 0 | |
423 | self.executionTime = 0 |
|
425 | self.executionTime = 0 | |
424 |
|
426 | |||
425 | def __reload(self): |
|
427 | def __reload(self): | |
@@ -434,15 +436,15 class DigitalRFReader(ProcessingUnit): | |||||
434 | try: |
|
436 | try: | |
435 | self.digitalReadObj.reload(complete_update=True) |
|
437 | self.digitalReadObj.reload(complete_update=True) | |
436 | except: |
|
438 | except: | |
437 |
self.digitalReadObj. |
|
439 | self.digitalReadObj = digital_rf.DigitalRFReader(self.path) | |
438 |
|
440 | |||
439 | start_index, end_index = self.digitalReadObj.get_bounds( |
|
441 | start_index, end_index = self.digitalReadObj.get_bounds( | |
440 | self.__channelNameList[self.__channelList[0]]) |
|
442 | self.__channelNameList[self.__channelList[0]]) | |
441 |
|
443 | |||
442 | if start_index > self.__startUTCSecond * self.__sample_rate: |
|
444 | if start_index > self.__startUTCSecond * self.__sample_rate: | |
443 | self.__startUTCSecond = 1.0 * start_index / self.__sample_rate |
|
445 | self.__startUTCSecond = 1.0 * start_index / self.__sample_rate | |
444 |
|
446 | |||
445 | if end_index > self.__endUTCSecond * self.__sample_rate: |
|
447 | if end_index > self.__endUTCSecond * self.__sample_rate: | |
446 | self.__endUTCSecond = 1.0 * end_index / self.__sample_rate |
|
448 | self.__endUTCSecond = 1.0 * end_index / self.__sample_rate | |
447 | print() |
|
449 | print() | |
448 | print("[Reading] New timerange found [%s, %s] " % ( |
|
450 | print("[Reading] New timerange found [%s, %s] " % ( | |
@@ -457,14 +459,14 class DigitalRFReader(ProcessingUnit): | |||||
457 | return False |
|
459 | return False | |
458 |
|
460 | |||
459 | def timeit(self, toExecute): |
|
461 | def timeit(self, toExecute): | |
460 | t0 = time.time() |
|
462 | t0 = time.time() | |
461 | toExecute() |
|
463 | toExecute() | |
462 | self.executionTime = time.time() - t0 |
|
464 | self.executionTime = time.time() - t0 | |
463 | if self.oldAverage is None: |
|
465 | if self.oldAverage is None: | |
464 | self.oldAverage = self.executionTime |
|
466 | self.oldAverage = self.executionTime | |
465 | self.oldAverage = (self.executionTime + self.count * |
|
467 | self.oldAverage = (self.executionTime + self.count * | |
466 | self.oldAverage) / (self.count + 1.0) |
|
468 | self.oldAverage) / (self.count + 1.0) | |
467 | self.count = self.count + 1.0 |
|
469 | self.count = self.count + 1.0 | |
468 | return |
|
470 | return | |
469 |
|
471 | |||
470 | def __readNextBlock(self, seconds=30, volt_scale=1): |
|
472 | def __readNextBlock(self, seconds=30, volt_scale=1): | |
@@ -473,10 +475,10 class DigitalRFReader(ProcessingUnit): | |||||
473 |
|
475 | |||
474 | # Set the next data |
|
476 | # Set the next data | |
475 | self.__flagDiscontinuousBlock = False |
|
477 | self.__flagDiscontinuousBlock = False | |
476 | self.__thisUnixSample += self.__samples_to_read |
|
478 | self.__thisUnixSample += self.__samples_to_read | |
477 |
|
479 | |||
478 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: |
|
480 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: | |
479 | print("[Reading] There are no more data into selected time-range") |
|
481 | print ("[Reading] There are no more data into selected time-range") | |
480 | if self.__online: |
|
482 | if self.__online: | |
481 | self.__reload() |
|
483 | self.__reload() | |
482 | else: |
|
484 | else: | |
@@ -489,17 +491,18 class DigitalRFReader(ProcessingUnit): | |||||
489 | indexChannel = 0 |
|
491 | indexChannel = 0 | |
490 |
|
492 | |||
491 | dataOk = False |
|
493 | dataOk = False | |
|
494 | ||||
492 | for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS? |
|
495 | for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS? | |
493 | for indexSubchannel in range(self.__num_subchannels): |
|
496 | for indexSubchannel in range(self.__num_subchannels): | |
494 | try: |
|
497 | try: | |
495 | t0 = time() |
|
498 | t0 = time() | |
496 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, |
|
499 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, | |
497 | self.__samples_to_read, |
|
500 | self.__samples_to_read, | |
498 | thisChannelName, sub_channel=indexSubchannel) |
|
501 | thisChannelName, sub_channel=indexSubchannel) | |
499 | self.executionTime = time() - t0 |
|
502 | self.executionTime = time() - t0 | |
500 | if self.oldAverage is None: |
|
503 | if self.oldAverage is None: | |
501 | self.oldAverage = self.executionTime |
|
504 | self.oldAverage = self.executionTime | |
502 | self.oldAverage = ( |
|
505 | self.oldAverage = ( | |
503 | self.executionTime + self.count * self.oldAverage) / (self.count + 1.0) |
|
506 | self.executionTime + self.count * self.oldAverage) / (self.count + 1.0) | |
504 | self.count = self.count + 1.0 |
|
507 | self.count = self.count + 1.0 | |
505 |
|
508 | |||
@@ -515,14 +518,13 class DigitalRFReader(ProcessingUnit): | |||||
515 | result.shape[0], |
|
518 | result.shape[0], | |
516 | self.__samples_to_read)) |
|
519 | self.__samples_to_read)) | |
517 | break |
|
520 | break | |
518 |
|
521 | |||
519 | self.__data_buffer[indexSubchannel, :] = result * volt_scale |
|
522 | self.__data_buffer[indexSubchannel, :] = result * volt_scale | |
|
523 | indexChannel+=1 | |||
520 |
|
524 | |||
521 |
|
|
525 | dataOk = True | |
522 |
|
526 | |||
523 | dataOk = True |
|
527 | self.__utctime = self.__thisUnixSample / self.__sample_rate | |
524 |
|
||||
525 | self.__utctime = self.__thisUnixSample / self.__sample_rate |
|
|||
526 |
|
528 | |||
527 | if not dataOk: |
|
529 | if not dataOk: | |
528 | return False |
|
530 | return False | |
@@ -531,7 +533,7 class DigitalRFReader(ProcessingUnit): | |||||
531 | self.__samples_to_read, |
|
533 | self.__samples_to_read, | |
532 | self.__timeInterval)) |
|
534 | self.__timeInterval)) | |
533 |
|
535 | |||
534 | self.__bufferIndex = 0 |
|
536 | self.__bufferIndex = 0 | |
535 |
|
537 | |||
536 | return True |
|
538 | return True | |
537 |
|
539 | |||
@@ -554,27 +556,29 class DigitalRFReader(ProcessingUnit): | |||||
554 | self.flagDiscontinuousBlock |
|
556 | self.flagDiscontinuousBlock | |
555 | self.flagIsNewBlock |
|
557 | self.flagIsNewBlock | |
556 | ''' |
|
558 | ''' | |
557 |
|
559 | #print("getdata") | ||
558 | err_counter = 0 |
|
560 | err_counter = 0 | |
559 | self.dataOut.flagNoData = True |
|
561 | self.dataOut.flagNoData = True | |
560 |
|
562 | |||
561 | if self.__isBufferEmpty(): |
|
563 | if self.__isBufferEmpty(): | |
|
564 | #print("hi") | |||
562 | self.__flagDiscontinuousBlock = False |
|
565 | self.__flagDiscontinuousBlock = False | |
563 |
|
566 | |||
564 | while True: |
|
567 | while True: | |
|
568 | #print ("q ha pasado") | |||
565 | if self.__readNextBlock(): |
|
569 | if self.__readNextBlock(): | |
566 | break |
|
570 | break | |
567 | if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate: |
|
571 | if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate: | |
568 | raise schainpy.admin.SchainError('Error') |
|
572 | raise schainpy.admin.SchainError('Error') | |
569 |
return |
|
573 | return | |
570 |
|
574 | |||
571 | if self.__flagDiscontinuousBlock: |
|
575 | if self.__flagDiscontinuousBlock: | |
572 | raise schainpy.admin.SchainError('discontinuous block found') |
|
576 | raise schainpy.admin.SchainError('discontinuous block found') | |
573 | return |
|
577 | return | |
574 |
|
578 | |||
575 | if not self.__online: |
|
579 | if not self.__online: | |
576 | raise schainpy.admin.SchainError('Online?') |
|
580 | raise schainpy.admin.SchainError('Online?') | |
577 |
return |
|
581 | return | |
578 |
|
582 | |||
579 | err_counter += 1 |
|
583 | err_counter += 1 | |
580 | if err_counter > nTries: |
|
584 | if err_counter > nTries: | |
@@ -584,21 +588,19 class DigitalRFReader(ProcessingUnit): | |||||
584 | print('[Reading] waiting %d seconds to read a new block' % seconds) |
|
588 | print('[Reading] waiting %d seconds to read a new block' % seconds) | |
585 | time.sleep(seconds) |
|
589 | time.sleep(seconds) | |
586 |
|
590 | |||
587 | self.dataOut.data = self.__data_buffer[:, |
|
591 | self.dataOut.data = self.__data_buffer[:, self.__bufferIndex:self.__bufferIndex + self.__nSamples] | |
588 | self.__bufferIndex:self.__bufferIndex + self.__nSamples] |
|
592 | self.dataOut.utctime = ( self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate | |
589 |
self.dataOut. |
|
593 | self.dataOut.flagNoData = False | |
590 | self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate |
|
|||
591 | self.dataOut.flagNoData = False |
|
|||
592 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock |
|
594 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
593 | self.dataOut.profileIndex = self.profileIndex |
|
595 | self.dataOut.profileIndex = self.profileIndex | |
594 |
|
596 | |||
595 | self.__bufferIndex += self.__nSamples |
|
597 | self.__bufferIndex += self.__nSamples | |
596 | self.profileIndex += 1 |
|
598 | self.profileIndex += 1 | |
597 |
|
599 | |||
598 | if self.profileIndex == self.dataOut.nProfiles: |
|
600 | if self.profileIndex == self.dataOut.nProfiles: | |
599 | self.profileIndex = 0 |
|
601 | self.profileIndex = 0 | |
600 |
|
602 | |||
601 | return |
|
603 | return True | |
602 |
|
604 | |||
603 | def printInfo(self): |
|
605 | def printInfo(self): | |
604 | ''' |
|
606 | ''' | |
@@ -621,12 +623,12 class DigitalRFReader(ProcessingUnit): | |||||
621 | ''' |
|
623 | ''' | |
622 | This method will be called many times so here you should put all your code |
|
624 | This method will be called many times so here you should put all your code | |
623 | ''' |
|
625 | ''' | |
624 |
|
626 | |||
625 | if not self.isConfig: |
|
627 | if not self.isConfig: | |
626 | self.setup(**kwargs) |
|
628 | self.setup(**kwargs) | |
627 | #self.i = self.i+1 |
|
629 | #self.i = self.i+1 | |
628 | self.getData(seconds=self.__delay) |
|
630 | self.getData(seconds=self.__delay) | |
629 |
|
631 | |||
630 | return |
|
632 | return | |
631 |
|
633 | |||
632 |
|
634 | |||
@@ -641,25 +643,25 class DigitalRFWriter(Operation): | |||||
641 | ''' |
|
643 | ''' | |
642 | Operation.__init__(self, **kwargs) |
|
644 | Operation.__init__(self, **kwargs) | |
643 | self.metadata_dict = {} |
|
645 | self.metadata_dict = {} | |
644 | self.dataOut = None |
|
646 | self.dataOut = None | |
645 | self.dtype = None |
|
647 | self.dtype = None | |
646 | self.oldAverage = 0 |
|
648 | self.oldAverage = 0 | |
647 |
|
649 | |||
648 | def setHeader(self): |
|
650 | def setHeader(self): | |
649 |
|
651 | |||
650 | self.metadata_dict['frequency'] = self.dataOut.frequency |
|
652 | self.metadata_dict['frequency'] = self.dataOut.frequency | |
651 | self.metadata_dict['timezone'] = self.dataOut.timeZone |
|
653 | self.metadata_dict['timezone'] = self.dataOut.timeZone | |
652 | self.metadata_dict['dtype'] = pickle.dumps(self.dataOut.dtype) |
|
654 | self.metadata_dict['dtype'] = pickle.dumps(self.dataOut.dtype) | |
653 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles |
|
655 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles | |
654 | self.metadata_dict['heightList'] = self.dataOut.heightList |
|
656 | self.metadata_dict['heightList'] = self.dataOut.heightList | |
655 | self.metadata_dict['channelList'] = self.dataOut.channelList |
|
657 | self.metadata_dict['channelList'] = self.dataOut.channelList | |
656 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData |
|
658 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData | |
657 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData |
|
659 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData | |
658 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT |
|
660 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT | |
659 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime |
|
661 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime | |
660 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt |
|
662 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt | |
661 | self.metadata_dict['type'] = self.dataOut.type |
|
663 | self.metadata_dict['type'] = self.dataOut.type | |
662 |
self.metadata_dict['flagDataAsBlock'] |
|
664 | self.metadata_dict['flagDataAsBlock']= getattr( | |
663 | self.dataOut, 'flagDataAsBlock', None) # chequear |
|
665 | self.dataOut, 'flagDataAsBlock', None) # chequear | |
664 |
|
666 | |||
665 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): |
|
667 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): | |
@@ -669,13 +671,13 class DigitalRFWriter(Operation): | |||||
669 | dataOut: Input data will also be outputa data |
|
671 | dataOut: Input data will also be outputa data | |
670 | ''' |
|
672 | ''' | |
671 | self.setHeader() |
|
673 | self.setHeader() | |
672 | self.__ippSeconds = dataOut.ippSeconds |
|
674 | self.__ippSeconds = dataOut.ippSeconds | |
673 | self.__deltaH = dataOut.getDeltaH() |
|
675 | self.__deltaH = dataOut.getDeltaH() | |
674 | self.__sample_rate = 1e6 * 0.15 / self.__deltaH |
|
676 | self.__sample_rate = 1e6 * 0.15 / self.__deltaH | |
675 | self.__dtype = dataOut.dtype |
|
677 | self.__dtype = dataOut.dtype | |
676 | if len(dataOut.dtype) == 2: |
|
678 | if len(dataOut.dtype) == 2: | |
677 | self.__dtype = dataOut.dtype[0] |
|
679 | self.__dtype = dataOut.dtype[0] | |
678 | self.__nSamples = dataOut.systemHeaderObj.nSamples |
|
680 | self.__nSamples = dataOut.systemHeaderObj.nSamples | |
679 | self.__nProfiles = dataOut.nProfiles |
|
681 | self.__nProfiles = dataOut.nProfiles | |
680 |
|
682 | |||
681 | if self.dataOut.type != 'Voltage': |
|
683 | if self.dataOut.type != 'Voltage': | |
@@ -686,44 +688,44 class DigitalRFWriter(Operation): | |||||
686 | self.arr_data = numpy.ones((self.__nSamples, len( |
|
688 | self.arr_data = numpy.ones((self.__nSamples, len( | |
687 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) |
|
689 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |
688 |
|
690 | |||
689 | file_cadence_millisecs = 1000 |
|
691 | file_cadence_millisecs = 1000 | |
690 |
|
692 | |||
691 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() |
|
693 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() | |
692 | sample_rate_numerator = int(sample_rate_fraction.numerator) |
|
694 | sample_rate_numerator = int(sample_rate_fraction.numerator) | |
693 | sample_rate_denominator = int(sample_rate_fraction.denominator) |
|
695 | sample_rate_denominator = int(sample_rate_fraction.denominator) | |
694 | start_global_index = dataOut.utctime * self.__sample_rate |
|
696 | start_global_index = dataOut.utctime * self.__sample_rate | |
695 |
|
697 | |||
696 | uuid = 'prueba' |
|
698 | uuid = 'prueba' | |
697 | compression_level = 0 |
|
699 | compression_level = 0 | |
698 | checksum = False |
|
700 | checksum = False | |
699 | is_complex = True |
|
701 | is_complex = True | |
700 | num_subchannels = len(dataOut.channelList) |
|
702 | num_subchannels = len(dataOut.channelList) | |
701 | is_continuous = True |
|
703 | is_continuous = True | |
702 | marching_periods = False |
|
704 | marching_periods = False | |
703 |
|
705 | |||
704 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, |
|
706 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, | |
705 | fileCadence, start_global_index, |
|
707 | fileCadence, start_global_index, | |
706 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, |
|
708 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, | |
707 | is_complex, num_subchannels, is_continuous, marching_periods) |
|
709 | is_complex, num_subchannels, is_continuous, marching_periods) | |
708 | metadata_dir = os.path.join(path, 'metadata') |
|
710 | metadata_dir = os.path.join(path, 'metadata') | |
709 | os.system('mkdir %s' % (metadata_dir)) |
|
711 | os.system('mkdir %s' % (metadata_dir)) | |
710 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 |
|
712 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 | |
711 | sample_rate_numerator, sample_rate_denominator, |
|
713 | sample_rate_numerator, sample_rate_denominator, | |
712 | metadataFile) |
|
714 | metadataFile) | |
713 | self.isConfig = True |
|
715 | self.isConfig = True | |
714 | self.currentSample = 0 |
|
716 | self.currentSample = 0 | |
715 | self.oldAverage = 0 |
|
717 | self.oldAverage = 0 | |
716 | self.count = 0 |
|
718 | self.count = 0 | |
717 | return |
|
719 | return | |
718 |
|
720 | |||
719 | def writeMetadata(self): |
|
721 | def writeMetadata(self): | |
720 | start_idx = self.__sample_rate * self.dataOut.utctime |
|
722 | start_idx = self.__sample_rate * self.dataOut.utctime | |
721 |
|
723 | |||
722 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( |
|
724 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( | |
723 | ) |
|
725 | ) | |
724 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict( |
|
726 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict( | |
725 | ) |
|
727 | ) | |
726 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict( |
|
728 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict( | |
727 | ) |
|
729 | ) | |
728 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) |
|
730 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) | |
729 | return |
|
731 | return | |
@@ -731,12 +733,12 class DigitalRFWriter(Operation): | |||||
731 | def timeit(self, toExecute): |
|
733 | def timeit(self, toExecute): | |
732 | t0 = time() |
|
734 | t0 = time() | |
733 | toExecute() |
|
735 | toExecute() | |
734 | self.executionTime = time() - t0 |
|
736 | self.executionTime = time() - t0 | |
735 | if self.oldAverage is None: |
|
737 | if self.oldAverage is None: | |
736 | self.oldAverage = self.executionTime |
|
738 | self.oldAverage = self.executionTime | |
737 | self.oldAverage = (self.executionTime + self.count * |
|
739 | self.oldAverage = (self.executionTime + self.count * | |
738 | self.oldAverage) / (self.count + 1.0) |
|
740 | self.oldAverage) / (self.count + 1.0) | |
739 | self.count = self.count + 1.0 |
|
741 | self.count = self.count + 1.0 | |
740 | return |
|
742 | return | |
741 |
|
743 | |||
742 | def writeData(self): |
|
744 | def writeData(self): | |
@@ -779,7 +781,7 class DigitalRFWriter(Operation): | |||||
779 | # self.writeMetadata() |
|
781 | # self.writeMetadata() | |
780 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 |
|
782 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 | |
781 |
|
783 | |||
782 | return dataOut |
|
784 | return dataOut# en la version 2.7 no aparece este return | |
783 |
|
785 | |||
784 | def close(self): |
|
786 | def close(self): | |
785 | print('[Writing] - Closing files ') |
|
787 | print('[Writing] - Closing files ') | |
@@ -788,5 +790,3 class DigitalRFWriter(Operation): | |||||
788 | self.digitalWriteObj.close() |
|
790 | self.digitalWriteObj.close() | |
789 | except: |
|
791 | except: | |
790 | pass |
|
792 | pass | |
791 |
|
||||
792 |
|
General Comments 0
You need to be logged in to leave comments.
Login now