@@ -1,863 +1,863 | |||||
1 | ''' |
|
1 | ''' | |
2 | Created on Jul 3, 2014 |
|
2 | Created on Jul 3, 2014 | |
3 |
|
3 | |||
4 | @author: roj-idl71 |
|
4 | @author: roj-idl71 | |
5 | ''' |
|
5 | ''' | |
6 | # SUBCHANNELS EN VEZ DE CHANNELS |
|
6 | # SUBCHANNELS EN VEZ DE CHANNELS | |
7 | # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO |
|
7 | # BENCHMARKS -> PROBLEMAS CON ARCHIVOS GRANDES -> INCONSTANTE EN EL TIEMPO | |
8 | # ACTUALIZACION DE VERSION |
|
8 | # ACTUALIZACION DE VERSION | |
9 | # HEADERS |
|
9 | # HEADERS | |
10 | # MODULO DE ESCRITURA |
|
10 | # MODULO DE ESCRITURA | |
11 | # METADATA |
|
11 | # METADATA | |
12 |
|
12 | |||
13 | import os |
|
13 | import os | |
14 | import time |
|
14 | import time | |
15 | import datetime |
|
15 | import datetime | |
16 | import numpy |
|
16 | import numpy | |
17 | import timeit |
|
17 | import timeit | |
18 | from fractions import Fraction |
|
18 | from fractions import Fraction | |
19 | from time import time |
|
19 | from time import time | |
20 | from time import sleep |
|
20 | from time import sleep | |
21 |
|
21 | |||
22 | import schainpy.admin |
|
22 | import schainpy.admin | |
23 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader |
|
23 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
24 | from schainpy.model.data.jrodata import Voltage |
|
24 | from schainpy.model.data.jrodata import Voltage | |
25 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator |
|
25 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation, MPDecorator | |
26 |
|
26 | |||
27 | import pickle |
|
27 | import pickle | |
28 | try: |
|
28 | try: | |
29 | os.environ["HDF5_USE_FILE_LOCKING"] = "FALSE" |
|
29 | os.environ["HDF5_USE_FILE_LOCKING"] = "FALSE" | |
30 | import digital_rf |
|
30 | import digital_rf | |
31 | except: |
|
31 | except: | |
32 | pass |
|
32 | pass | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | class DigitalRFReader(ProcessingUnit): |
|
35 | class DigitalRFReader(ProcessingUnit): | |
36 | ''' |
|
36 | ''' | |
37 | classdocs |
|
37 | classdocs | |
38 | ''' |
|
38 | ''' | |
39 |
|
39 | |||
40 | def __init__(self): |
|
40 | def __init__(self): | |
41 | ''' |
|
41 | ''' | |
42 | Constructor |
|
42 | Constructor | |
43 | ''' |
|
43 | ''' | |
44 |
|
44 | |||
45 | ProcessingUnit.__init__(self) |
|
45 | ProcessingUnit.__init__(self) | |
46 |
|
46 | |||
47 | self.dataOut = Voltage() |
|
47 | self.dataOut = Voltage() | |
48 | self.__printInfo = True |
|
48 | self.__printInfo = True | |
49 | self.__flagDiscontinuousBlock = False |
|
49 | self.__flagDiscontinuousBlock = False | |
50 | self.__bufferIndex = 9999999 |
|
50 | self.__bufferIndex = 9999999 | |
51 | self.__codeType = 0 |
|
51 | self.__codeType = 0 | |
52 | self.__ippKm = None |
|
52 | self.__ippKm = None | |
53 | self.__nCode = None |
|
53 | self.__nCode = None | |
54 | self.__nBaud = None |
|
54 | self.__nBaud = None | |
55 | self.__code = None |
|
55 | self.__code = None | |
56 | self.dtype = None |
|
56 | self.dtype = None | |
57 | self.oldAverage = None |
|
57 | self.oldAverage = None | |
58 | self.path = None |
|
58 | self.path = None | |
59 |
|
59 | |||
60 | def close(self): |
|
60 | def close(self): | |
61 | print('Average of writing to digital rf format is ', self.oldAverage * 1000) |
|
61 | print('Average of writing to digital rf format is ', self.oldAverage * 1000) | |
62 | return |
|
62 | return | |
63 |
|
63 | |||
64 | def __getCurrentSecond(self): |
|
64 | def __getCurrentSecond(self): | |
65 |
|
65 | |||
66 | return self.__thisUnixSample / self.__sample_rate |
|
66 | return self.__thisUnixSample / self.__sample_rate | |
67 |
|
67 | |||
68 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") |
|
68 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") | |
69 |
|
69 | |||
70 | def __setFileHeader(self): |
|
70 | def __setFileHeader(self): | |
71 | ''' |
|
71 | ''' | |
72 | In this method will be initialized every parameter of dataOut object (header, no data) |
|
72 | In this method will be initialized every parameter of dataOut object (header, no data) | |
73 | ''' |
|
73 | ''' | |
74 | ippSeconds = 1.0 * self.__nSamples / self.__sample_rate |
|
74 | ippSeconds = 1.0 * self.__nSamples / self.__sample_rate | |
75 | if not self.getByBlock: |
|
75 | if not self.getByBlock: | |
76 | nProfiles = 1.0 / ippSeconds # Number of profiles in one second |
|
76 | nProfiles = 1.0 / ippSeconds # Number of profiles in one second | |
77 | else: |
|
77 | else: | |
78 | nProfiles = self.nProfileBlocks # Number of profiles in one block |
|
78 | nProfiles = self.nProfileBlocks # Number of profiles in one block | |
79 |
|
79 | |||
80 | try: |
|
80 | try: | |
81 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( |
|
81 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( | |
82 | self.__radarControllerHeader) |
|
82 | self.__radarControllerHeader) | |
83 | except: |
|
83 | except: | |
84 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( |
|
84 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader( | |
85 | txA=0, |
|
85 | txA=0, | |
86 | txB=0, |
|
86 | txB=0, | |
87 | nWindows=1, |
|
87 | nWindows=1, | |
88 | nHeights=self.__nSamples, |
|
88 | nHeights=self.__nSamples, | |
89 | firstHeight=self.__firstHeigth, |
|
89 | firstHeight=self.__firstHeigth, | |
90 | deltaHeight=self.__deltaHeigth, |
|
90 | deltaHeight=self.__deltaHeigth, | |
91 | codeType=self.__codeType, |
|
91 | codeType=self.__codeType, | |
92 | nCode=self.__nCode, nBaud=self.__nBaud, |
|
92 | nCode=self.__nCode, nBaud=self.__nBaud, | |
93 | code=self.__code) |
|
93 | code=self.__code) | |
94 |
|
94 | |||
95 | try: |
|
95 | try: | |
96 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) |
|
96 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) | |
97 | except: |
|
97 | except: | |
98 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, |
|
98 | self.dataOut.systemHeaderObj = SystemHeader(nSamples=self.__nSamples, | |
99 | nProfiles=nProfiles, |
|
99 | nProfiles=nProfiles, | |
100 | nChannels=len( |
|
100 | nChannels=len( | |
101 | self.__channelList), |
|
101 | self.__channelList), | |
102 | adcResolution=14) |
|
102 | adcResolution=14) | |
103 | self.dataOut.type = "Voltage" |
|
103 | self.dataOut.type = "Voltage" | |
104 |
|
104 | |||
105 | self.dataOut.data = None |
|
105 | self.dataOut.data = None | |
106 |
|
106 | |||
107 | self.dataOut.dtype = self.dtype |
|
107 | self.dataOut.dtype = self.dtype | |
108 |
|
108 | |||
109 | # self.dataOut.nChannels = 0 |
|
109 | # self.dataOut.nChannels = 0 | |
110 |
|
110 | |||
111 | # self.dataOut.nHeights = 0 |
|
111 | # self.dataOut.nHeights = 0 | |
112 |
|
112 | |||
113 | self.dataOut.nProfiles = int(nProfiles) |
|
113 | self.dataOut.nProfiles = int(nProfiles) | |
114 |
|
114 | |||
115 | self.dataOut.heightList = self.__firstHeigth + \ |
|
115 | self.dataOut.heightList = self.__firstHeigth + \ | |
116 | numpy.arange(self.__nSamples, dtype=numpy.float) * \ |
|
116 | numpy.arange(self.__nSamples, dtype=numpy.float_) * \ | |
117 | self.__deltaHeigth |
|
117 | self.__deltaHeigth | |
118 |
|
118 | |||
119 | #self.dataOut.channelList = list(range(self.__num_subchannels)) |
|
119 | #self.dataOut.channelList = list(range(self.__num_subchannels)) | |
120 | self.dataOut.channelList = list(range(len(self.__channelList))) |
|
120 | self.dataOut.channelList = list(range(len(self.__channelList))) | |
121 | if not self.getByBlock: |
|
121 | if not self.getByBlock: | |
122 |
|
122 | |||
123 | self.dataOut.blocksize = self.dataOut.nChannels * self.dataOut.nHeights |
|
123 | self.dataOut.blocksize = self.dataOut.nChannels * self.dataOut.nHeights | |
124 | else: |
|
124 | else: | |
125 | self.dataOut.blocksize = self.dataOut.nChannels * self.dataOut.nHeights*self.nProfileBlocks |
|
125 | self.dataOut.blocksize = self.dataOut.nChannels * self.dataOut.nHeights*self.nProfileBlocks | |
126 |
|
126 | |||
127 | # self.dataOut.channelIndexList = None |
|
127 | # self.dataOut.channelIndexList = None | |
128 |
|
128 | |||
129 | self.dataOut.flagNoData = True |
|
129 | self.dataOut.flagNoData = True | |
130 | if not self.getByBlock: |
|
130 | if not self.getByBlock: | |
131 | self.dataOut.flagDataAsBlock = False |
|
131 | self.dataOut.flagDataAsBlock = False | |
132 | else: |
|
132 | else: | |
133 | self.dataOut.flagDataAsBlock = True |
|
133 | self.dataOut.flagDataAsBlock = True | |
134 | # Set to TRUE if the data is discontinuous |
|
134 | # Set to TRUE if the data is discontinuous | |
135 | self.dataOut.flagDiscontinuousBlock = False |
|
135 | self.dataOut.flagDiscontinuousBlock = False | |
136 |
|
136 | |||
137 | self.dataOut.utctime = None |
|
137 | self.dataOut.utctime = None | |
138 |
|
138 | |||
139 | # timezone like jroheader, difference in minutes between UTC and localtime |
|
139 | # timezone like jroheader, difference in minutes between UTC and localtime | |
140 | self.dataOut.timeZone = self.__timezone / 60 |
|
140 | self.dataOut.timeZone = self.__timezone / 60 | |
141 |
|
141 | |||
142 | self.dataOut.dstFlag = 0 |
|
142 | self.dataOut.dstFlag = 0 | |
143 |
|
143 | |||
144 | self.dataOut.errorCount = 0 |
|
144 | self.dataOut.errorCount = 0 | |
145 |
|
145 | |||
146 | try: |
|
146 | try: | |
147 | self.dataOut.nCohInt = self.fixed_metadata_dict.get( |
|
147 | self.dataOut.nCohInt = self.fixed_metadata_dict.get( | |
148 | 'nCohInt', self.nCohInt) |
|
148 | 'nCohInt', self.nCohInt) | |
149 |
|
149 | |||
150 | # asumo que la data esta decodificada |
|
150 | # asumo que la data esta decodificada | |
151 | self.dataOut.flagDecodeData = self.fixed_metadata_dict.get( |
|
151 | self.dataOut.flagDecodeData = self.fixed_metadata_dict.get( | |
152 | 'flagDecodeData', self.flagDecodeData) |
|
152 | 'flagDecodeData', self.flagDecodeData) | |
153 |
|
153 | |||
154 | # asumo que la data esta sin flip |
|
154 | # asumo que la data esta sin flip | |
155 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] |
|
155 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] | |
156 |
|
156 | |||
157 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] |
|
157 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] | |
158 |
|
158 | |||
159 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] |
|
159 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] | |
160 | except: |
|
160 | except: | |
161 | pass |
|
161 | pass | |
162 |
|
162 | |||
163 | self.dataOut.ippSeconds = ippSeconds |
|
163 | self.dataOut.ippSeconds = ippSeconds | |
164 |
|
164 | |||
165 | # Time interval between profiles |
|
165 | # Time interval between profiles | |
166 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
166 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
167 |
|
167 | |||
168 | self.dataOut.frequency = self.__frequency |
|
168 | self.dataOut.frequency = self.__frequency | |
169 |
|
169 | |||
170 | self.dataOut.realtime = self.__online |
|
170 | self.dataOut.realtime = self.__online | |
171 |
|
171 | |||
172 | def findDatafiles(self, path, startDate=None, endDate=None): |
|
172 | def findDatafiles(self, path, startDate=None, endDate=None): | |
173 |
|
173 | |||
174 | if not os.path.isdir(path): |
|
174 | if not os.path.isdir(path): | |
175 | return [] |
|
175 | return [] | |
176 |
|
176 | |||
177 | try: |
|
177 | try: | |
178 | digitalReadObj = digital_rf.DigitalRFReader( |
|
178 | digitalReadObj = digital_rf.DigitalRFReader( | |
179 | path, load_all_metadata=True) |
|
179 | path, load_all_metadata=True) | |
180 | except: |
|
180 | except: | |
181 | digitalReadObj = digital_rf.DigitalRFReader(path) |
|
181 | digitalReadObj = digital_rf.DigitalRFReader(path) | |
182 |
|
182 | |||
183 | channelNameList = digitalReadObj.get_channels() |
|
183 | channelNameList = digitalReadObj.get_channels() | |
184 |
|
184 | |||
185 | if not channelNameList: |
|
185 | if not channelNameList: | |
186 | return [] |
|
186 | return [] | |
187 |
|
187 | |||
188 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) |
|
188 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) | |
189 |
|
189 | |||
190 | sample_rate = metadata_dict['sample_rate'][0] |
|
190 | sample_rate = metadata_dict['sample_rate'][0] | |
191 |
|
191 | |||
192 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) |
|
192 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) | |
193 |
|
193 | |||
194 | try: |
|
194 | try: | |
195 | timezone = this_metadata_file['timezone'].value |
|
195 | timezone = this_metadata_file['timezone'].value | |
196 | except: |
|
196 | except: | |
197 | timezone = 0 |
|
197 | timezone = 0 | |
198 |
|
198 | |||
199 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( |
|
199 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds( | |
200 | channelNameList[0]) / sample_rate - timezone |
|
200 | channelNameList[0]) / sample_rate - timezone | |
201 |
|
201 | |||
202 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) |
|
202 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) | |
203 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) |
|
203 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) | |
204 |
|
204 | |||
205 | if not startDate: |
|
205 | if not startDate: | |
206 | startDate = startDatetime.date() |
|
206 | startDate = startDatetime.date() | |
207 |
|
207 | |||
208 | if not endDate: |
|
208 | if not endDate: | |
209 | endDate = endDatatime.date() |
|
209 | endDate = endDatatime.date() | |
210 |
|
210 | |||
211 | dateList = [] |
|
211 | dateList = [] | |
212 |
|
212 | |||
213 | thisDatetime = startDatetime |
|
213 | thisDatetime = startDatetime | |
214 |
|
214 | |||
215 | while(thisDatetime <= endDatatime): |
|
215 | while(thisDatetime <= endDatatime): | |
216 |
|
216 | |||
217 | thisDate = thisDatetime.date() |
|
217 | thisDate = thisDatetime.date() | |
218 |
|
218 | |||
219 | if thisDate < startDate: |
|
219 | if thisDate < startDate: | |
220 | continue |
|
220 | continue | |
221 |
|
221 | |||
222 | if thisDate > endDate: |
|
222 | if thisDate > endDate: | |
223 | break |
|
223 | break | |
224 |
|
224 | |||
225 | dateList.append(thisDate) |
|
225 | dateList.append(thisDate) | |
226 | thisDatetime += datetime.timedelta(1) |
|
226 | thisDatetime += datetime.timedelta(1) | |
227 |
|
227 | |||
228 | return dateList |
|
228 | return dateList | |
229 |
|
229 | |||
230 | def setup(self, path=None, |
|
230 | def setup(self, path=None, | |
231 | startDate=None, |
|
231 | startDate=None, | |
232 | endDate=None, |
|
232 | endDate=None, | |
233 | startTime=datetime.time(0, 0, 0), |
|
233 | startTime=datetime.time(0, 0, 0), | |
234 | endTime=datetime.time(23, 59, 59), |
|
234 | endTime=datetime.time(23, 59, 59), | |
235 | channelList=None, |
|
235 | channelList=None, | |
236 | nSamples=None, |
|
236 | nSamples=None, | |
237 | online=False, |
|
237 | online=False, | |
238 | delay=60, |
|
238 | delay=60, | |
239 | buffer_size=1024, |
|
239 | buffer_size=1024, | |
240 | ippKm=None, |
|
240 | ippKm=None, | |
241 | nCohInt=1, |
|
241 | nCohInt=1, | |
242 | nCode=1, |
|
242 | nCode=1, | |
243 | nBaud=1, |
|
243 | nBaud=1, | |
244 | flagDecodeData=False, |
|
244 | flagDecodeData=False, | |
245 |
code=numpy.ones((1, 1), dtype= |
|
245 | code=numpy.ones((1, 1), dtype=int), | |
246 | getByBlock=0, |
|
246 | getByBlock=0, | |
247 | nProfileBlocks=1, |
|
247 | nProfileBlocks=1, | |
248 | **kwargs): |
|
248 | **kwargs): | |
249 | ''' |
|
249 | ''' | |
250 | In this method we should set all initial parameters. |
|
250 | In this method we should set all initial parameters. | |
251 |
|
251 | |||
252 | Inputs: |
|
252 | Inputs: | |
253 | path |
|
253 | path | |
254 | startDate |
|
254 | startDate | |
255 | endDate |
|
255 | endDate | |
256 | startTime |
|
256 | startTime | |
257 | endTime |
|
257 | endTime | |
258 | set |
|
258 | set | |
259 | expLabel |
|
259 | expLabel | |
260 | ext |
|
260 | ext | |
261 | online |
|
261 | online | |
262 | delay |
|
262 | delay | |
263 | ''' |
|
263 | ''' | |
264 | self.path = path |
|
264 | self.path = path | |
265 | self.nCohInt = nCohInt |
|
265 | self.nCohInt = nCohInt | |
266 | self.flagDecodeData = flagDecodeData |
|
266 | self.flagDecodeData = flagDecodeData | |
267 | self.i = 0 |
|
267 | self.i = 0 | |
268 |
|
268 | |||
269 | self.getByBlock = getByBlock |
|
269 | self.getByBlock = getByBlock | |
270 | self.nProfileBlocks = nProfileBlocks |
|
270 | self.nProfileBlocks = nProfileBlocks | |
271 | if online: |
|
271 | if online: | |
272 | print('Waiting for RF data..') |
|
272 | print('Waiting for RF data..') | |
273 | sleep(40) |
|
273 | sleep(40) | |
274 |
|
274 | |||
275 | if not os.path.isdir(path): |
|
275 | if not os.path.isdir(path): | |
276 | raise ValueError("[Reading] Directory %s does not exist" % path) |
|
276 | raise ValueError("[Reading] Directory %s does not exist" % path) | |
277 |
|
277 | |||
278 | #print("path",path) |
|
278 | #print("path",path) | |
279 | try: |
|
279 | try: | |
280 | self.digitalReadObj = digital_rf.DigitalRFReader( |
|
280 | self.digitalReadObj = digital_rf.DigitalRFReader( | |
281 | path, load_all_metadata=True) |
|
281 | path, load_all_metadata=True) | |
282 | except: |
|
282 | except: | |
283 | self.digitalReadObj = digital_rf.DigitalRFReader(path) |
|
283 | self.digitalReadObj = digital_rf.DigitalRFReader(path) | |
284 |
|
284 | |||
285 | channelNameList = self.digitalReadObj.get_channels() |
|
285 | channelNameList = self.digitalReadObj.get_channels() | |
286 |
|
286 | |||
287 | if not channelNameList: |
|
287 | if not channelNameList: | |
288 | raise ValueError("[Reading] Directory %s does not have any files" % path) |
|
288 | raise ValueError("[Reading] Directory %s does not have any files" % path) | |
289 |
|
289 | |||
290 | if not channelList: |
|
290 | if not channelList: | |
291 | channelList = list(range(len(channelNameList))) |
|
291 | channelList = list(range(len(channelNameList))) | |
292 |
|
292 | |||
293 | ########## Reading metadata ###################### |
|
293 | ########## Reading metadata ###################### | |
294 |
|
294 | |||
295 | top_properties = self.digitalReadObj.get_properties( |
|
295 | top_properties = self.digitalReadObj.get_properties( | |
296 | channelNameList[channelList[0]]) |
|
296 | channelNameList[channelList[0]]) | |
297 |
|
297 | |||
298 | self.__num_subchannels = top_properties['num_subchannels'] |
|
298 | self.__num_subchannels = top_properties['num_subchannels'] | |
299 | self.__sample_rate = 1.0 * \ |
|
299 | self.__sample_rate = 1.0 * \ | |
300 | top_properties['sample_rate_numerator'] / \ |
|
300 | top_properties['sample_rate_numerator'] / \ | |
301 | top_properties['sample_rate_denominator'] |
|
301 | top_properties['sample_rate_denominator'] | |
302 | # self.__samples_per_file = top_properties['samples_per_file'][0] |
|
302 | # self.__samples_per_file = top_properties['samples_per_file'][0] | |
303 | self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15? |
|
303 | self.__deltaHeigth = 1e6 * 0.15 / self.__sample_rate # why 0.15? | |
304 |
|
304 | |||
305 | this_metadata_file = self.digitalReadObj.get_digital_metadata( |
|
305 | this_metadata_file = self.digitalReadObj.get_digital_metadata( | |
306 | channelNameList[channelList[0]]) |
|
306 | channelNameList[channelList[0]]) | |
307 | metadata_bounds = this_metadata_file.get_bounds() |
|
307 | metadata_bounds = this_metadata_file.get_bounds() | |
308 | self.fixed_metadata_dict = this_metadata_file.read( |
|
308 | self.fixed_metadata_dict = this_metadata_file.read( | |
309 | metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER |
|
309 | metadata_bounds[0])[metadata_bounds[0]] # GET FIRST HEADER | |
310 |
|
310 | |||
311 | try: |
|
311 | try: | |
312 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] |
|
312 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] | |
313 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] |
|
313 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] | |
314 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] |
|
314 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] | |
315 | self.dtype = pickle.loads(self.fixed_metadata_dict['dtype']) |
|
315 | self.dtype = pickle.loads(self.fixed_metadata_dict['dtype']) | |
316 | except: |
|
316 | except: | |
317 | pass |
|
317 | pass | |
318 |
|
318 | |||
319 | self.__frequency = None |
|
319 | self.__frequency = None | |
320 |
|
320 | |||
321 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) |
|
321 | self.__frequency = self.fixed_metadata_dict.get('frequency', 1) | |
322 |
|
322 | |||
323 | self.__timezone = self.fixed_metadata_dict.get('timezone', 18000) |
|
323 | self.__timezone = self.fixed_metadata_dict.get('timezone', 18000) | |
324 |
|
324 | |||
325 | try: |
|
325 | try: | |
326 | nSamples = self.fixed_metadata_dict['nSamples'] |
|
326 | nSamples = self.fixed_metadata_dict['nSamples'] | |
327 | except: |
|
327 | except: | |
328 | nSamples = None |
|
328 | nSamples = None | |
329 |
|
329 | |||
330 | self.__firstHeigth = 0 |
|
330 | self.__firstHeigth = 0 | |
331 |
|
331 | |||
332 | try: |
|
332 | try: | |
333 | codeType = self.__radarControllerHeader['codeType'] |
|
333 | codeType = self.__radarControllerHeader['codeType'] | |
334 | except: |
|
334 | except: | |
335 | codeType = 0 |
|
335 | codeType = 0 | |
336 |
|
336 | |||
337 | try: |
|
337 | try: | |
338 | if codeType: |
|
338 | if codeType: | |
339 | nCode = self.__radarControllerHeader['nCode'] |
|
339 | nCode = self.__radarControllerHeader['nCode'] | |
340 | nBaud = self.__radarControllerHeader['nBaud'] |
|
340 | nBaud = self.__radarControllerHeader['nBaud'] | |
341 | code = self.__radarControllerHeader['code'] |
|
341 | code = self.__radarControllerHeader['code'] | |
342 | except: |
|
342 | except: | |
343 | pass |
|
343 | pass | |
344 |
|
344 | |||
345 | if not ippKm: |
|
345 | if not ippKm: | |
346 | try: |
|
346 | try: | |
347 | # seconds to km |
|
347 | # seconds to km | |
348 | ippKm = self.__radarControllerHeader['ipp'] |
|
348 | ippKm = self.__radarControllerHeader['ipp'] | |
349 | except: |
|
349 | except: | |
350 | ippKm = None |
|
350 | ippKm = None | |
351 | #################################################### |
|
351 | #################################################### | |
352 | self.__ippKm = ippKm |
|
352 | self.__ippKm = ippKm | |
353 | startUTCSecond = None |
|
353 | startUTCSecond = None | |
354 | endUTCSecond = None |
|
354 | endUTCSecond = None | |
355 |
|
355 | |||
356 | if startDate: |
|
356 | if startDate: | |
357 | startDatetime = datetime.datetime.combine(startDate, startTime) |
|
357 | startDatetime = datetime.datetime.combine(startDate, startTime) | |
358 | startUTCSecond = ( |
|
358 | startUTCSecond = ( | |
359 | startDatetime - datetime.datetime(1970, 1, 1)).total_seconds()# + self.__timezone |
|
359 | startDatetime - datetime.datetime(1970, 1, 1)).total_seconds()# + self.__timezone | |
360 |
|
360 | |||
361 | if endDate: |
|
361 | if endDate: | |
362 | endDatetime = datetime.datetime.combine(endDate, endTime) |
|
362 | endDatetime = datetime.datetime.combine(endDate, endTime) | |
363 | endUTCSecond = (endDatetime - datetime.datetime(1970, |
|
363 | endUTCSecond = (endDatetime - datetime.datetime(1970, | |
364 | 1, 1)).total_seconds()# + self.__timezone |
|
364 | 1, 1)).total_seconds()# + self.__timezone | |
365 | start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]]) |
|
365 | start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]]) | |
366 | if start_index==None or end_index==None: |
|
366 | if start_index==None or end_index==None: | |
367 | print("Check error No data, start_index: ",start_index,",end_index: ",end_index) |
|
367 | print("Check error No data, start_index: ",start_index,",end_index: ",end_index) | |
368 | #return 0 |
|
368 | #return 0 | |
369 | if not startUTCSecond: |
|
369 | if not startUTCSecond: | |
370 | startUTCSecond = start_index / self.__sample_rate |
|
370 | startUTCSecond = start_index / self.__sample_rate | |
371 | if start_index > startUTCSecond * self.__sample_rate: |
|
371 | if start_index > startUTCSecond * self.__sample_rate: | |
372 | startUTCSecond = start_index / self.__sample_rate |
|
372 | startUTCSecond = start_index / self.__sample_rate | |
373 |
|
373 | |||
374 | if not endUTCSecond: |
|
374 | if not endUTCSecond: | |
375 | endUTCSecond = end_index / self.__sample_rate |
|
375 | endUTCSecond = end_index / self.__sample_rate | |
376 |
|
376 | |||
377 | if end_index < endUTCSecond * self.__sample_rate: |
|
377 | if end_index < endUTCSecond * self.__sample_rate: | |
378 | endUTCSecond = end_index / self.__sample_rate #Check UTC and LT time |
|
378 | endUTCSecond = end_index / self.__sample_rate #Check UTC and LT time | |
379 |
|
379 | |||
380 | if not nSamples: |
|
380 | if not nSamples: | |
381 | if not ippKm: |
|
381 | if not ippKm: | |
382 | raise ValueError("[Reading] nSamples or ippKm should be defined") |
|
382 | raise ValueError("[Reading] nSamples or ippKm should be defined") | |
383 | nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate)) |
|
383 | nSamples = int(ippKm / (1e6 * 0.15 / self.__sample_rate)) | |
384 |
|
384 | |||
385 | channelBoundList = [] |
|
385 | channelBoundList = [] | |
386 | channelNameListFiltered = [] |
|
386 | channelNameListFiltered = [] | |
387 |
|
387 | |||
388 | for thisIndexChannel in channelList: |
|
388 | for thisIndexChannel in channelList: | |
389 | thisChannelName = channelNameList[thisIndexChannel] |
|
389 | thisChannelName = channelNameList[thisIndexChannel] | |
390 | start_index, end_index = self.digitalReadObj.get_bounds( |
|
390 | start_index, end_index = self.digitalReadObj.get_bounds( | |
391 | thisChannelName) |
|
391 | thisChannelName) | |
392 | channelBoundList.append((start_index, end_index)) |
|
392 | channelBoundList.append((start_index, end_index)) | |
393 | channelNameListFiltered.append(thisChannelName) |
|
393 | channelNameListFiltered.append(thisChannelName) | |
394 |
|
394 | |||
395 | self.profileIndex = 0 |
|
395 | self.profileIndex = 0 | |
396 | self.i = 0 |
|
396 | self.i = 0 | |
397 | self.__delay = delay |
|
397 | self.__delay = delay | |
398 |
|
398 | |||
399 | self.__codeType = codeType |
|
399 | self.__codeType = codeType | |
400 | self.__nCode = nCode |
|
400 | self.__nCode = nCode | |
401 | self.__nBaud = nBaud |
|
401 | self.__nBaud = nBaud | |
402 | self.__code = code |
|
402 | self.__code = code | |
403 |
|
403 | |||
404 | self.__datapath = path |
|
404 | self.__datapath = path | |
405 | self.__online = online |
|
405 | self.__online = online | |
406 | self.__channelList = channelList |
|
406 | self.__channelList = channelList | |
407 | self.__channelNameList = channelNameListFiltered |
|
407 | self.__channelNameList = channelNameListFiltered | |
408 | self.__channelBoundList = channelBoundList |
|
408 | self.__channelBoundList = channelBoundList | |
409 | self.__nSamples = nSamples |
|
409 | self.__nSamples = nSamples | |
410 | if self.getByBlock: |
|
410 | if self.getByBlock: | |
411 | nSamples = nSamples*nProfileBlocks |
|
411 | nSamples = nSamples*nProfileBlocks | |
412 |
|
412 | |||
413 |
|
413 | |||
414 | self.__samples_to_read = int(nSamples) # FIJO: AHORA 40 |
|
414 | self.__samples_to_read = int(nSamples) # FIJO: AHORA 40 | |
415 | self.__nChannels = len(self.__channelList) |
|
415 | self.__nChannels = len(self.__channelList) | |
416 | #print("------------------------------------------") |
|
416 | #print("------------------------------------------") | |
417 | #print("self.__samples_to_read",self.__samples_to_read) |
|
417 | #print("self.__samples_to_read",self.__samples_to_read) | |
418 | #print("self.__nSamples",self.__nSamples) |
|
418 | #print("self.__nSamples",self.__nSamples) | |
419 | # son iguales y el buffer_index da 0 |
|
419 | # son iguales y el buffer_index da 0 | |
420 | self.__startUTCSecond = startUTCSecond |
|
420 | self.__startUTCSecond = startUTCSecond | |
421 | self.__endUTCSecond = endUTCSecond |
|
421 | self.__endUTCSecond = endUTCSecond | |
422 |
|
422 | |||
423 | self.__timeInterval = 1.0 * self.__samples_to_read / \ |
|
423 | self.__timeInterval = 1.0 * self.__samples_to_read / \ | |
424 | self.__sample_rate # Time interval |
|
424 | self.__sample_rate # Time interval | |
425 |
|
425 | |||
426 | if online: |
|
426 | if online: | |
427 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) |
|
427 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) | |
428 | startUTCSecond = numpy.floor(endUTCSecond) |
|
428 | startUTCSecond = numpy.floor(endUTCSecond) | |
429 |
|
429 | |||
430 | # por que en el otro metodo lo primero q se hace es sumar samplestoread |
|
430 | # por que en el otro metodo lo primero q se hace es sumar samplestoread | |
431 | self.__thisUnixSample = int(startUTCSecond * self.__sample_rate) - self.__samples_to_read |
|
431 | self.__thisUnixSample = int(startUTCSecond * self.__sample_rate) - self.__samples_to_read | |
432 |
|
432 | |||
433 | #self.__data_buffer = numpy.zeros( |
|
433 | #self.__data_buffer = numpy.zeros( | |
434 | # (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex) |
|
434 | # (self.__num_subchannels, self.__samples_to_read), dtype=numpy.complex) | |
435 | print("samplestoread",self.__samples_to_read) |
|
435 | print("samplestoread",self.__samples_to_read) | |
436 | self.__data_buffer = numpy.zeros((int(len(channelList)), self.__samples_to_read), dtype=numpy.complex) |
|
436 | self.__data_buffer = numpy.zeros((int(len(channelList)), self.__samples_to_read), dtype=numpy.complex_) | |
437 |
|
437 | |||
438 |
|
438 | |||
439 | self.__setFileHeader() |
|
439 | self.__setFileHeader() | |
440 | self.isConfig = True |
|
440 | self.isConfig = True | |
441 |
|
441 | |||
442 | print("[Reading] Digital RF Data was found from %s to %s " % ( |
|
442 | print("[Reading] Digital RF Data was found from %s to %s " % ( | |
443 | datetime.datetime.utcfromtimestamp( |
|
443 | datetime.datetime.utcfromtimestamp( | |
444 | self.__startUTCSecond - self.__timezone), |
|
444 | self.__startUTCSecond - self.__timezone), | |
445 | datetime.datetime.utcfromtimestamp( |
|
445 | datetime.datetime.utcfromtimestamp( | |
446 | self.__endUTCSecond - self.__timezone) |
|
446 | self.__endUTCSecond - self.__timezone) | |
447 | )) |
|
447 | )) | |
448 |
|
448 | |||
449 | print("[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), |
|
449 | print("[Reading] Starting process from %s to %s" % (datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), | |
450 | datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone))) |
|
450 | datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone))) | |
451 | self.oldAverage = None |
|
451 | self.oldAverage = None | |
452 | self.count = 0 |
|
452 | self.count = 0 | |
453 | self.executionTime = 0 |
|
453 | self.executionTime = 0 | |
454 |
|
454 | |||
455 | def __reload(self): |
|
455 | def __reload(self): | |
456 |
|
456 | |||
457 | # print "%s not in range [%s, %s]" %( |
|
457 | # print "%s not in range [%s, %s]" %( | |
458 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
458 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
459 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), |
|
459 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
460 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) |
|
460 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
461 | # ) |
|
461 | # ) | |
462 | print("[Reading] reloading metadata ...") |
|
462 | print("[Reading] reloading metadata ...") | |
463 |
|
463 | |||
464 | try: |
|
464 | try: | |
465 | self.digitalReadObj.reload(complete_update=True) |
|
465 | self.digitalReadObj.reload(complete_update=True) | |
466 | except: |
|
466 | except: | |
467 | self.digitalReadObj = digital_rf.DigitalRFReader(self.path) |
|
467 | self.digitalReadObj = digital_rf.DigitalRFReader(self.path) | |
468 |
|
468 | |||
469 | start_index, end_index = self.digitalReadObj.get_bounds( |
|
469 | start_index, end_index = self.digitalReadObj.get_bounds( | |
470 | self.__channelNameList[self.__channelList[0]]) |
|
470 | self.__channelNameList[self.__channelList[0]]) | |
471 |
|
471 | |||
472 | if start_index > self.__startUTCSecond * self.__sample_rate: |
|
472 | if start_index > self.__startUTCSecond * self.__sample_rate: | |
473 | self.__startUTCSecond = 1.0 * start_index / self.__sample_rate |
|
473 | self.__startUTCSecond = 1.0 * start_index / self.__sample_rate | |
474 |
|
474 | |||
475 | if end_index > self.__endUTCSecond * self.__sample_rate: |
|
475 | if end_index > self.__endUTCSecond * self.__sample_rate: | |
476 | self.__endUTCSecond = 1.0 * end_index / self.__sample_rate |
|
476 | self.__endUTCSecond = 1.0 * end_index / self.__sample_rate | |
477 | print() |
|
477 | print() | |
478 | print("[Reading] New timerange found [%s, %s] " % ( |
|
478 | print("[Reading] New timerange found [%s, %s] " % ( | |
479 | datetime.datetime.utcfromtimestamp( |
|
479 | datetime.datetime.utcfromtimestamp( | |
480 | self.__startUTCSecond - self.__timezone), |
|
480 | self.__startUTCSecond - self.__timezone), | |
481 | datetime.datetime.utcfromtimestamp( |
|
481 | datetime.datetime.utcfromtimestamp( | |
482 | self.__endUTCSecond - self.__timezone) |
|
482 | self.__endUTCSecond - self.__timezone) | |
483 | )) |
|
483 | )) | |
484 |
|
484 | |||
485 | return True |
|
485 | return True | |
486 |
|
486 | |||
487 | return False |
|
487 | return False | |
488 |
|
488 | |||
489 | def timeit(self, toExecute): |
|
489 | def timeit(self, toExecute): | |
490 | t0 = time.time() |
|
490 | t0 = time.time() | |
491 | toExecute() |
|
491 | toExecute() | |
492 | self.executionTime = time.time() - t0 |
|
492 | self.executionTime = time.time() - t0 | |
493 | if self.oldAverage is None: |
|
493 | if self.oldAverage is None: | |
494 | self.oldAverage = self.executionTime |
|
494 | self.oldAverage = self.executionTime | |
495 | self.oldAverage = (self.executionTime + self.count * |
|
495 | self.oldAverage = (self.executionTime + self.count * | |
496 | self.oldAverage) / (self.count + 1.0) |
|
496 | self.oldAverage) / (self.count + 1.0) | |
497 | self.count = self.count + 1.0 |
|
497 | self.count = self.count + 1.0 | |
498 | return |
|
498 | return | |
499 |
|
499 | |||
500 | def __readNextBlock(self, seconds=30, volt_scale=1/20000.0): |
|
500 | def __readNextBlock(self, seconds=30, volt_scale=1/20000.0): | |
501 | ''' |
|
501 | ''' | |
502 | NOTA: APLICACION RADAR METEOROLOGICO |
|
502 | NOTA: APLICACION RADAR METEOROLOGICO | |
503 | VALORES OBTENIDOS CON LA USRP, volt_scale = 1,conexion directa al Ch Rx. |
|
503 | VALORES OBTENIDOS CON LA USRP, volt_scale = 1,conexion directa al Ch Rx. | |
504 |
|
504 | |||
505 | MAXIMO |
|
505 | MAXIMO | |
506 | 9886 -> 0.980 Voltiospp |
|
506 | 9886 -> 0.980 Voltiospp | |
507 | 4939 -> 0.480 Voltiospp |
|
507 | 4939 -> 0.480 Voltiospp | |
508 | 14825 -> 1.440 Voltiospp |
|
508 | 14825 -> 1.440 Voltiospp | |
509 | 18129 -> 1.940 Voltiospp |
|
509 | 18129 -> 1.940 Voltiospp | |
510 | Para llevar al valor correspondiente de Voltaje, debemos dividir por 20000 |
|
510 | Para llevar al valor correspondiente de Voltaje, debemos dividir por 20000 | |
511 | y obtenemos la Amplitud correspondiente de entrada IQ. |
|
511 | y obtenemos la Amplitud correspondiente de entrada IQ. | |
512 | volt_scale = (1/20000.0) |
|
512 | volt_scale = (1/20000.0) | |
513 | ''' |
|
513 | ''' | |
514 | # Set the next data |
|
514 | # Set the next data | |
515 | self.__flagDiscontinuousBlock = False |
|
515 | self.__flagDiscontinuousBlock = False | |
516 | self.__thisUnixSample += self.__samples_to_read |
|
516 | self.__thisUnixSample += self.__samples_to_read | |
517 |
|
517 | |||
518 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: |
|
518 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: | |
519 | print ("[Reading] There are no more data into selected time-range") |
|
519 | print ("[Reading] There are no more data into selected time-range") | |
520 | if self.__online: |
|
520 | if self.__online: | |
521 | sleep(3) |
|
521 | sleep(3) | |
522 | self.__reload() |
|
522 | self.__reload() | |
523 | else: |
|
523 | else: | |
524 | return False |
|
524 | return False | |
525 |
|
525 | |||
526 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: |
|
526 | if self.__thisUnixSample + 2 * self.__samples_to_read > self.__endUTCSecond * self.__sample_rate: | |
527 | return False |
|
527 | return False | |
528 | self.__thisUnixSample -= self.__samples_to_read |
|
528 | self.__thisUnixSample -= self.__samples_to_read | |
529 |
|
529 | |||
530 | indexChannel = 0 |
|
530 | indexChannel = 0 | |
531 |
|
531 | |||
532 | dataOk = False |
|
532 | dataOk = False | |
533 |
|
533 | |||
534 | for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS? |
|
534 | for thisChannelName in self.__channelNameList: # TODO VARIOS CHANNELS? | |
535 | for indexSubchannel in range(self.__num_subchannels): |
|
535 | for indexSubchannel in range(self.__num_subchannels): | |
536 | try: |
|
536 | try: | |
537 | t0 = time() |
|
537 | t0 = time() | |
538 | #print("thisUNixSample",self.__thisUnixSample) |
|
538 | #print("thisUNixSample",self.__thisUnixSample) | |
539 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, |
|
539 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, | |
540 | self.__samples_to_read, |
|
540 | self.__samples_to_read, | |
541 | thisChannelName, sub_channel=indexSubchannel) |
|
541 | thisChannelName, sub_channel=indexSubchannel) | |
542 | #print("result--------------",result) |
|
542 | #print("result--------------",result) | |
543 | self.executionTime = time() - t0 |
|
543 | self.executionTime = time() - t0 | |
544 | if self.oldAverage is None: |
|
544 | if self.oldAverage is None: | |
545 | self.oldAverage = self.executionTime |
|
545 | self.oldAverage = self.executionTime | |
546 | self.oldAverage = ( |
|
546 | self.oldAverage = ( | |
547 | self.executionTime + self.count * self.oldAverage) / (self.count + 1.0) |
|
547 | self.executionTime + self.count * self.oldAverage) / (self.count + 1.0) | |
548 | self.count = self.count + 1.0 |
|
548 | self.count = self.count + 1.0 | |
549 |
|
549 | |||
550 | except IOError as e: |
|
550 | except IOError as e: | |
551 | # read next profile |
|
551 | # read next profile | |
552 | self.__flagDiscontinuousBlock = True |
|
552 | self.__flagDiscontinuousBlock = True | |
553 | print("[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e) |
|
553 | print("[Reading] %s" % datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e) | |
554 | bot = 0 |
|
554 | bot = 0 | |
555 | while(self.__flagDiscontinuousBlock): |
|
555 | while(self.__flagDiscontinuousBlock): | |
556 | bot +=1 |
|
556 | bot +=1 | |
557 |
self.__thisUnixSample += self.__sample_ |
|
557 | self.__thisUnixSample += self.__samples_to_read | |
558 | try: |
|
558 | try: | |
559 | result = result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,self.__samples_to_read,thisChannelName, sub_channel=indexSubchannel) |
|
559 | result = result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample,self.__samples_to_read,thisChannelName, sub_channel=indexSubchannel) | |
560 | self.__flagDiscontinuousBlock=False |
|
560 | self.__flagDiscontinuousBlock=False | |
561 | print("Searching.. NΒ°: ",bot,"Success",self.__thisUnixSample) |
|
561 | print("Searching.. NΒ°: ",bot,"Success",self.__thisUnixSample) | |
562 | except: |
|
562 | except: | |
563 | print("Searching...NΒ°: ",bot,"Fail", self.__thisUnixSample) |
|
563 | print("Searching...NΒ°: ",bot,"Fail", self.__thisUnixSample) | |
564 | if self.__flagDiscontinuousBlock==True: |
|
564 | if self.__flagDiscontinuousBlock==True: | |
565 | break |
|
565 | break | |
566 | else: |
|
566 | else: | |
567 | print("New data index found...",self.__thisUnixSample) |
|
567 | print("New data index found...",self.__thisUnixSample) | |
568 | #break |
|
568 | #break | |
569 |
|
569 | |||
570 | if result.shape[0] != self.__samples_to_read: |
|
570 | if result.shape[0] != self.__samples_to_read: | |
571 | self.__flagDiscontinuousBlock = True |
|
571 | self.__flagDiscontinuousBlock = True | |
572 | print("[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
572 | print("[Reading] %s: Too few samples were found, just %d/%d samples" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
573 | result.shape[0], |
|
573 | result.shape[0], | |
574 | self.__samples_to_read)) |
|
574 | self.__samples_to_read)) | |
575 | break |
|
575 | break | |
576 |
|
576 | |||
577 | self.__data_buffer[indexChannel, :] = result * volt_scale |
|
577 | self.__data_buffer[indexChannel, :] = result * volt_scale | |
578 | indexChannel+=1 |
|
578 | indexChannel+=1 | |
579 |
|
579 | |||
580 | dataOk = True |
|
580 | dataOk = True | |
581 |
|
581 | |||
582 | self.__utctime = self.__thisUnixSample / self.__sample_rate |
|
582 | self.__utctime = self.__thisUnixSample / self.__sample_rate | |
583 |
|
583 | |||
584 | if not dataOk: |
|
584 | if not dataOk: | |
585 | return False |
|
585 | return False | |
586 |
|
586 | |||
587 | print("[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
587 | print("[Reading] %s: %d samples <> %f sec" % (datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
588 | self.__samples_to_read, |
|
588 | self.__samples_to_read, | |
589 | self.__timeInterval)) |
|
589 | self.__timeInterval)) | |
590 |
|
590 | |||
591 | self.__bufferIndex = 0 |
|
591 | self.__bufferIndex = 0 | |
592 |
|
592 | |||
593 | return True |
|
593 | return True | |
594 |
|
594 | |||
595 | def __isBufferEmpty(self): |
|
595 | def __isBufferEmpty(self): | |
596 |
|
596 | |||
597 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40 |
|
597 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples # 40960 - 40 | |
598 |
|
598 | |||
599 | def getData(self, seconds=30, nTries=5): |
|
599 | def getData(self, seconds=30, nTries=5): | |
600 | ''' |
|
600 | ''' | |
601 | This method gets the data from files and put the data into the dataOut object |
|
601 | This method gets the data from files and put the data into the dataOut object | |
602 |
|
602 | |||
603 | In addition, increase el the buffer counter in one. |
|
603 | In addition, increase el the buffer counter in one. | |
604 |
|
604 | |||
605 | Return: |
|
605 | Return: | |
606 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
606 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
607 | buffer. Si no hay mas archivos a leer retorna None. |
|
607 | buffer. Si no hay mas archivos a leer retorna None. | |
608 |
|
608 | |||
609 | Affected: |
|
609 | Affected: | |
610 | self.dataOut |
|
610 | self.dataOut | |
611 | self.profileIndex |
|
611 | self.profileIndex | |
612 | self.flagDiscontinuousBlock |
|
612 | self.flagDiscontinuousBlock | |
613 | self.flagIsNewBlock |
|
613 | self.flagIsNewBlock | |
614 | ''' |
|
614 | ''' | |
615 | #print("getdata") |
|
615 | #print("getdata") | |
616 | err_counter = 0 |
|
616 | err_counter = 0 | |
617 | self.dataOut.flagNoData = True |
|
617 | self.dataOut.flagNoData = True | |
618 |
|
618 | |||
619 |
|
619 | |||
620 | if self.__isBufferEmpty(): |
|
620 | if self.__isBufferEmpty(): | |
621 | #print("hi") |
|
621 | #print("hi") | |
622 | self.__flagDiscontinuousBlock = False |
|
622 | self.__flagDiscontinuousBlock = False | |
623 |
|
623 | |||
624 | while True: |
|
624 | while True: | |
625 | if self.__readNextBlock(): |
|
625 | if self.__readNextBlock(): | |
626 | break |
|
626 | break | |
627 | if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate: |
|
627 | if self.__thisUnixSample > self.__endUTCSecond * self.__sample_rate: | |
628 | raise schainpy.admin.SchainError('Error') |
|
628 | raise schainpy.admin.SchainError('Error') | |
629 | return |
|
629 | return | |
630 |
|
630 | |||
631 | if self.__flagDiscontinuousBlock: |
|
631 | if self.__flagDiscontinuousBlock: | |
632 | raise schainpy.admin.SchainError('discontinuous block found') |
|
632 | raise schainpy.admin.SchainError('discontinuous block found') | |
633 | return |
|
633 | return | |
634 |
|
634 | |||
635 | if not self.__online: |
|
635 | if not self.__online: | |
636 | raise schainpy.admin.SchainError('Online?') |
|
636 | raise schainpy.admin.SchainError('Online?') | |
637 | return |
|
637 | return | |
638 |
|
638 | |||
639 | err_counter += 1 |
|
639 | err_counter += 1 | |
640 | if err_counter > nTries: |
|
640 | if err_counter > nTries: | |
641 | raise schainpy.admin.SchainError('Max retrys reach') |
|
641 | raise schainpy.admin.SchainError('Max retrys reach') | |
642 | return |
|
642 | return | |
643 |
|
643 | |||
644 | print('[Reading] waiting %d seconds to read a new block' % seconds) |
|
644 | print('[Reading] waiting %d seconds to read a new block' % seconds) | |
645 | sleep(seconds) |
|
645 | sleep(seconds) | |
646 |
|
646 | |||
647 |
|
647 | |||
648 | if not self.getByBlock: |
|
648 | if not self.getByBlock: | |
649 |
|
649 | |||
650 | #print("self.__bufferIndex",self.__bufferIndex)# este valor siempre es cero aparentemente |
|
650 | #print("self.__bufferIndex",self.__bufferIndex)# este valor siempre es cero aparentemente | |
651 | self.dataOut.data = self.__data_buffer[:, self.__bufferIndex:self.__bufferIndex + self.__nSamples] |
|
651 | self.dataOut.data = self.__data_buffer[:, self.__bufferIndex:self.__bufferIndex + self.__nSamples] | |
652 | self.dataOut.utctime = ( self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate |
|
652 | self.dataOut.utctime = ( self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate | |
653 | self.dataOut.flagNoData = False |
|
653 | self.dataOut.flagNoData = False | |
654 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock |
|
654 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
655 | self.dataOut.profileIndex = self.profileIndex |
|
655 | self.dataOut.profileIndex = self.profileIndex | |
656 |
|
656 | |||
657 | self.__bufferIndex += self.__nSamples |
|
657 | self.__bufferIndex += self.__nSamples | |
658 | self.profileIndex += 1 |
|
658 | self.profileIndex += 1 | |
659 |
|
659 | |||
660 | if self.profileIndex == self.dataOut.nProfiles: |
|
660 | if self.profileIndex == self.dataOut.nProfiles: | |
661 | self.profileIndex = 0 |
|
661 | self.profileIndex = 0 | |
662 | else: |
|
662 | else: | |
663 | # ojo debo anadir el readNextBLock y el __isBufferEmpty( |
|
663 | # ojo debo anadir el readNextBLock y el __isBufferEmpty( | |
664 | self.dataOut.flagNoData = False |
|
664 | self.dataOut.flagNoData = False | |
665 | buffer = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex + self.__samples_to_read] |
|
665 | buffer = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex + self.__samples_to_read] | |
666 | buffer = buffer.reshape((self.__nChannels, self.nProfileBlocks, int(self.__samples_to_read/self.nProfileBlocks))) |
|
666 | buffer = buffer.reshape((self.__nChannels, self.nProfileBlocks, int(self.__samples_to_read/self.nProfileBlocks))) | |
667 | self.dataOut.nProfileBlocks = self.nProfileBlocks |
|
667 | self.dataOut.nProfileBlocks = self.nProfileBlocks | |
668 | self.dataOut.data = buffer |
|
668 | self.dataOut.data = buffer | |
669 | self.dataOut.utctime = ( self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate |
|
669 | self.dataOut.utctime = ( self.__thisUnixSample + self.__bufferIndex) / self.__sample_rate | |
670 | self.profileIndex += self.__samples_to_read |
|
670 | self.profileIndex += self.__samples_to_read | |
671 | self.__bufferIndex += self.__samples_to_read |
|
671 | self.__bufferIndex += self.__samples_to_read | |
672 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock |
|
672 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
673 | return True |
|
673 | return True | |
674 |
|
674 | |||
675 |
|
675 | |||
676 | def printInfo(self): |
|
676 | def printInfo(self): | |
677 | ''' |
|
677 | ''' | |
678 | ''' |
|
678 | ''' | |
679 | if self.__printInfo == False: |
|
679 | if self.__printInfo == False: | |
680 | return |
|
680 | return | |
681 |
|
681 | |||
682 | # self.systemHeaderObj.printInfo() |
|
682 | # self.systemHeaderObj.printInfo() | |
683 | # self.radarControllerHeaderObj.printInfo() |
|
683 | # self.radarControllerHeaderObj.printInfo() | |
684 |
|
684 | |||
685 | self.__printInfo = False |
|
685 | self.__printInfo = False | |
686 |
|
686 | |||
687 | def printNumberOfBlock(self): |
|
687 | def printNumberOfBlock(self): | |
688 | ''' |
|
688 | ''' | |
689 | ''' |
|
689 | ''' | |
690 | return |
|
690 | return | |
691 | # print self.profileIndex |
|
691 | # print self.profileIndex | |
692 |
|
692 | |||
693 | def run(self, **kwargs): |
|
693 | def run(self, **kwargs): | |
694 | ''' |
|
694 | ''' | |
695 | This method will be called many times so here you should put all your code |
|
695 | This method will be called many times so here you should put all your code | |
696 | ''' |
|
696 | ''' | |
697 |
|
697 | |||
698 | if not self.isConfig: |
|
698 | if not self.isConfig: | |
699 | self.setup(**kwargs) |
|
699 | self.setup(**kwargs) | |
700 |
|
700 | |||
701 | self.getData(seconds=self.__delay) |
|
701 | self.getData(seconds=self.__delay) | |
702 |
|
702 | |||
703 | return |
|
703 | return | |
704 |
|
704 | |||
705 | @MPDecorator |
|
705 | @MPDecorator | |
706 | class DigitalRFWriter(Operation): |
|
706 | class DigitalRFWriter(Operation): | |
707 | ''' |
|
707 | ''' | |
708 | classdocs |
|
708 | classdocs | |
709 | ''' |
|
709 | ''' | |
710 |
|
710 | |||
711 | def __init__(self, **kwargs): |
|
711 | def __init__(self, **kwargs): | |
712 | ''' |
|
712 | ''' | |
713 | Constructor |
|
713 | Constructor | |
714 | ''' |
|
714 | ''' | |
715 | Operation.__init__(self, **kwargs) |
|
715 | Operation.__init__(self, **kwargs) | |
716 | self.metadata_dict = {} |
|
716 | self.metadata_dict = {} | |
717 | self.dataOut = None |
|
717 | self.dataOut = None | |
718 | self.dtype = None |
|
718 | self.dtype = None | |
719 | self.oldAverage = 0 |
|
719 | self.oldAverage = 0 | |
720 |
|
720 | |||
721 | def setHeader(self): |
|
721 | def setHeader(self): | |
722 |
|
722 | |||
723 | self.metadata_dict['frequency'] = self.dataOut.frequency |
|
723 | self.metadata_dict['frequency'] = self.dataOut.frequency | |
724 | self.metadata_dict['timezone'] = self.dataOut.timeZone |
|
724 | self.metadata_dict['timezone'] = self.dataOut.timeZone | |
725 | self.metadata_dict['dtype'] = pickle.dumps(self.dataOut.dtype) |
|
725 | self.metadata_dict['dtype'] = pickle.dumps(self.dataOut.dtype) | |
726 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles |
|
726 | self.metadata_dict['nProfiles'] = self.dataOut.nProfiles | |
727 | self.metadata_dict['heightList'] = self.dataOut.heightList |
|
727 | self.metadata_dict['heightList'] = self.dataOut.heightList | |
728 | self.metadata_dict['channelList'] = self.dataOut.channelList |
|
728 | self.metadata_dict['channelList'] = self.dataOut.channelList | |
729 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData |
|
729 | self.metadata_dict['flagDecodeData'] = self.dataOut.flagDecodeData | |
730 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData |
|
730 | self.metadata_dict['flagDeflipData'] = self.dataOut.flagDeflipData | |
731 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT |
|
731 | self.metadata_dict['flagShiftFFT'] = self.dataOut.flagShiftFFT | |
732 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime |
|
732 | self.metadata_dict['useLocalTime'] = self.dataOut.useLocalTime | |
733 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt |
|
733 | self.metadata_dict['nCohInt'] = self.dataOut.nCohInt | |
734 | self.metadata_dict['type'] = self.dataOut.type |
|
734 | self.metadata_dict['type'] = self.dataOut.type | |
735 | self.metadata_dict['flagDataAsBlock']= getattr( |
|
735 | self.metadata_dict['flagDataAsBlock']= getattr( | |
736 | self.dataOut, 'flagDataAsBlock', None) # chequear |
|
736 | self.dataOut, 'flagDataAsBlock', None) # chequear | |
737 |
|
737 | |||
738 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): |
|
738 | def setup(self, dataOut, path, frequency, fileCadence, dirCadence, metadataCadence, set=0, metadataFile='metadata', ext='.h5'): | |
739 | ''' |
|
739 | ''' | |
740 | In this method we should set all initial parameters. |
|
740 | In this method we should set all initial parameters. | |
741 | Input: |
|
741 | Input: | |
742 | dataOut: Input data will also be outputa data |
|
742 | dataOut: Input data will also be outputa data | |
743 | ''' |
|
743 | ''' | |
744 | self.setHeader() |
|
744 | self.setHeader() | |
745 | self.__ippSeconds = dataOut.ippSeconds |
|
745 | self.__ippSeconds = dataOut.ippSeconds | |
746 | self.__deltaH = dataOut.getDeltaH() |
|
746 | self.__deltaH = dataOut.getDeltaH() | |
747 | self.__sample_rate = 1e6 * 0.15 / self.__deltaH |
|
747 | self.__sample_rate = 1e6 * 0.15 / self.__deltaH | |
748 | self.__dtype = dataOut.dtype |
|
748 | self.__dtype = dataOut.dtype | |
749 | if len(dataOut.dtype) == 2: |
|
749 | if len(dataOut.dtype) == 2: | |
750 | self.__dtype = dataOut.dtype[0] |
|
750 | self.__dtype = dataOut.dtype[0] | |
751 | self.__nSamples = dataOut.systemHeaderObj.nSamples |
|
751 | self.__nSamples = dataOut.systemHeaderObj.nSamples | |
752 | self.__nProfiles = dataOut.nProfiles |
|
752 | self.__nProfiles = dataOut.nProfiles | |
753 |
|
753 | |||
754 | if self.dataOut.type != 'Voltage': |
|
754 | if self.dataOut.type != 'Voltage': | |
755 | raise 'Digital RF cannot be used with this data type' |
|
755 | raise 'Digital RF cannot be used with this data type' | |
756 | self.arr_data = numpy.ones((1, dataOut.nFFTPoints * len( |
|
756 | self.arr_data = numpy.ones((1, dataOut.nFFTPoints * len( | |
757 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) |
|
757 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |
758 | else: |
|
758 | else: | |
759 | self.arr_data = numpy.ones((self.__nSamples, len( |
|
759 | self.arr_data = numpy.ones((self.__nSamples, len( | |
760 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) |
|
760 | self.dataOut.channelList)), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |
761 |
|
761 | |||
762 | file_cadence_millisecs = 1000 |
|
762 | file_cadence_millisecs = 1000 | |
763 |
|
763 | |||
764 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() |
|
764 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() | |
765 | sample_rate_numerator = int(sample_rate_fraction.numerator) |
|
765 | sample_rate_numerator = int(sample_rate_fraction.numerator) | |
766 | sample_rate_denominator = int(sample_rate_fraction.denominator) |
|
766 | sample_rate_denominator = int(sample_rate_fraction.denominator) | |
767 | start_global_index = dataOut.utctime * self.__sample_rate |
|
767 | start_global_index = dataOut.utctime * self.__sample_rate | |
768 |
|
768 | |||
769 | uuid = 'prueba' |
|
769 | uuid = 'prueba' | |
770 | compression_level = 0 |
|
770 | compression_level = 0 | |
771 | checksum = False |
|
771 | checksum = False | |
772 | is_complex = True |
|
772 | is_complex = True | |
773 | num_subchannels = len(dataOut.channelList) |
|
773 | num_subchannels = len(dataOut.channelList) | |
774 | is_continuous = True |
|
774 | is_continuous = True | |
775 | marching_periods = False |
|
775 | marching_periods = False | |
776 |
|
776 | |||
777 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, |
|
777 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, dirCadence, | |
778 | fileCadence, start_global_index, |
|
778 | fileCadence, start_global_index, | |
779 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, |
|
779 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, | |
780 | is_complex, num_subchannels, is_continuous, marching_periods) |
|
780 | is_complex, num_subchannels, is_continuous, marching_periods) | |
781 | metadata_dir = os.path.join(path, 'metadata') |
|
781 | metadata_dir = os.path.join(path, 'metadata') | |
782 | os.system('mkdir %s' % (metadata_dir)) |
|
782 | os.system('mkdir %s' % (metadata_dir)) | |
783 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 |
|
783 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, dirCadence, 1, # 236, file_cadence_millisecs / 1000 | |
784 | sample_rate_numerator, sample_rate_denominator, |
|
784 | sample_rate_numerator, sample_rate_denominator, | |
785 | metadataFile) |
|
785 | metadataFile) | |
786 | self.isConfig = True |
|
786 | self.isConfig = True | |
787 | self.currentSample = 0 |
|
787 | self.currentSample = 0 | |
788 | self.oldAverage = 0 |
|
788 | self.oldAverage = 0 | |
789 | self.count = 0 |
|
789 | self.count = 0 | |
790 | return |
|
790 | return | |
791 |
|
791 | |||
792 | def writeMetadata(self): |
|
792 | def writeMetadata(self): | |
793 | start_idx = self.__sample_rate * self.dataOut.utctime |
|
793 | start_idx = self.__sample_rate * self.dataOut.utctime | |
794 |
|
794 | |||
795 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( |
|
795 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict( | |
796 | ) |
|
796 | ) | |
797 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict( |
|
797 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict( | |
798 | ) |
|
798 | ) | |
799 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict( |
|
799 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict( | |
800 | ) |
|
800 | ) | |
801 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) |
|
801 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) | |
802 | return |
|
802 | return | |
803 |
|
803 | |||
804 | def timeit(self, toExecute): |
|
804 | def timeit(self, toExecute): | |
805 | t0 = time() |
|
805 | t0 = time() | |
806 | toExecute() |
|
806 | toExecute() | |
807 | self.executionTime = time() - t0 |
|
807 | self.executionTime = time() - t0 | |
808 | if self.oldAverage is None: |
|
808 | if self.oldAverage is None: | |
809 | self.oldAverage = self.executionTime |
|
809 | self.oldAverage = self.executionTime | |
810 | self.oldAverage = (self.executionTime + self.count * |
|
810 | self.oldAverage = (self.executionTime + self.count * | |
811 | self.oldAverage) / (self.count + 1.0) |
|
811 | self.oldAverage) / (self.count + 1.0) | |
812 | self.count = self.count + 1.0 |
|
812 | self.count = self.count + 1.0 | |
813 | return |
|
813 | return | |
814 |
|
814 | |||
815 | def writeData(self): |
|
815 | def writeData(self): | |
816 | if self.dataOut.type != 'Voltage': |
|
816 | if self.dataOut.type != 'Voltage': | |
817 | raise 'Digital RF cannot be used with this data type' |
|
817 | raise 'Digital RF cannot be used with this data type' | |
818 | for channel in self.dataOut.channelList: |
|
818 | for channel in self.dataOut.channelList: | |
819 | for i in range(self.dataOut.nFFTPoints): |
|
819 | for i in range(self.dataOut.nFFTPoints): | |
820 | self.arr_data[1][channel * self.dataOut.nFFTPoints + |
|
820 | self.arr_data[1][channel * self.dataOut.nFFTPoints + | |
821 | i]['r'] = self.dataOut.data[channel][i].real |
|
821 | i]['r'] = self.dataOut.data[channel][i].real | |
822 | self.arr_data[1][channel * self.dataOut.nFFTPoints + |
|
822 | self.arr_data[1][channel * self.dataOut.nFFTPoints + | |
823 | i]['i'] = self.dataOut.data[channel][i].imag |
|
823 | i]['i'] = self.dataOut.data[channel][i].imag | |
824 | else: |
|
824 | else: | |
825 | for i in range(self.dataOut.systemHeaderObj.nSamples): |
|
825 | for i in range(self.dataOut.systemHeaderObj.nSamples): | |
826 | for channel in self.dataOut.channelList: |
|
826 | for channel in self.dataOut.channelList: | |
827 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real |
|
827 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real | |
828 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag |
|
828 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag | |
829 |
|
829 | |||
830 | def f(): return self.digitalWriteObj.rf_write(self.arr_data) |
|
830 | def f(): return self.digitalWriteObj.rf_write(self.arr_data) | |
831 | self.timeit(f) |
|
831 | self.timeit(f) | |
832 |
|
832 | |||
833 | return |
|
833 | return | |
834 |
|
834 | |||
835 | def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=1000, dirCadence=36000, metadataCadence=1, **kwargs): |
|
835 | def run(self, dataOut, frequency=49.92e6, path=None, fileCadence=1000, dirCadence=36000, metadataCadence=1, **kwargs): | |
836 | ''' |
|
836 | ''' | |
837 | This method will be called many times so here you should put all your code |
|
837 | This method will be called many times so here you should put all your code | |
838 | Inputs: |
|
838 | Inputs: | |
839 | dataOut: object with the data |
|
839 | dataOut: object with the data | |
840 | ''' |
|
840 | ''' | |
841 | # print dataOut.__dict__ |
|
841 | # print dataOut.__dict__ | |
842 | self.dataOut = dataOut |
|
842 | self.dataOut = dataOut | |
843 | if not self.isConfig: |
|
843 | if not self.isConfig: | |
844 | self.setup(dataOut, path, frequency, fileCadence, |
|
844 | self.setup(dataOut, path, frequency, fileCadence, | |
845 | dirCadence, metadataCadence, **kwargs) |
|
845 | dirCadence, metadataCadence, **kwargs) | |
846 | self.writeMetadata() |
|
846 | self.writeMetadata() | |
847 |
|
847 | |||
848 | self.writeData() |
|
848 | self.writeData() | |
849 |
|
849 | |||
850 | ## self.currentSample += 1 |
|
850 | ## self.currentSample += 1 | |
851 | # if self.dataOut.flagDataAsBlock or self.currentSample == 1: |
|
851 | # if self.dataOut.flagDataAsBlock or self.currentSample == 1: | |
852 | # self.writeMetadata() |
|
852 | # self.writeMetadata() | |
853 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 |
|
853 | ## if self.currentSample == self.__nProfiles: self.currentSample = 0 | |
854 |
|
854 | |||
855 | return dataOut# en la version 2.7 no aparece este return |
|
855 | return dataOut# en la version 2.7 no aparece este return | |
856 |
|
856 | |||
857 | def close(self): |
|
857 | def close(self): | |
858 | print('[Writing] - Closing files ') |
|
858 | print('[Writing] - Closing files ') | |
859 | print('Average of writing to digital rf format is ', self.oldAverage * 1000) |
|
859 | print('Average of writing to digital rf format is ', self.oldAverage * 1000) | |
860 | try: |
|
860 | try: | |
861 | self.digitalWriteObj.close() |
|
861 | self.digitalWriteObj.close() | |
862 | except: |
|
862 | except: | |
863 | pass |
|
863 | pass |
General Comments 0
You need to be logged in to leave comments.
Login now