@@ -1,677 +1,697 | |||||
1 |
|
1 | |||
2 | ''' |
|
2 | ''' | |
3 | Created on Jul 3, 2014 |
|
3 | Created on Jul 3, 2014 | |
4 |
|
4 | |||
5 | @author: roj-idl71 |
|
5 | @author: roj-idl71 | |
6 | ''' |
|
6 | ''' | |
7 | import os |
|
7 | import os | |
8 | import datetime |
|
8 | import datetime | |
9 | import numpy |
|
9 | import numpy | |
|
10 | import timeit | |||
10 | from profilehooks import coverage, profile |
|
11 | from profilehooks import coverage, profile | |
11 | from fractions import Fraction |
|
12 | from fractions import Fraction | |
12 |
|
13 | |||
13 | try: |
|
14 | try: | |
14 | from gevent import sleep |
|
15 | from gevent import sleep | |
15 | except: |
|
16 | except: | |
16 | from time import sleep |
|
17 | from time import sleep | |
17 |
|
18 | |||
18 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader |
|
19 | from schainpy.model.data.jroheaderIO import RadarControllerHeader, SystemHeader | |
19 | from schainpy.model.data.jrodata import Voltage |
|
20 | from schainpy.model.data.jrodata import Voltage | |
20 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation |
|
21 | from schainpy.model.proc.jroproc_base import ProcessingUnit, Operation | |
21 | from time import time |
|
22 | from time import time | |
|
23 | ||||
22 | import cPickle |
|
24 | import cPickle | |
23 | try: |
|
25 | try: | |
24 | import digital_rf |
|
26 | import digital_rf | |
25 | except: |
|
27 | except: | |
26 | print 'You should install "digital_rf" module if you want to read Digital RF data' |
|
28 | print 'You should install "digital_rf" module if you want to read Digital RF data' | |
27 |
|
29 | |||
28 | class DigitalRFReader(ProcessingUnit): |
|
30 | class DigitalRFReader(ProcessingUnit): | |
29 | ''' |
|
31 | ''' | |
30 | classdocs |
|
32 | classdocs | |
31 | ''' |
|
33 | ''' | |
32 |
|
34 | |||
33 | def __init__(self, **kwargs): |
|
35 | def __init__(self, **kwargs): | |
34 | ''' |
|
36 | ''' | |
35 | Constructor |
|
37 | Constructor | |
36 | ''' |
|
38 | ''' | |
37 |
|
39 | |||
38 | ProcessingUnit.__init__(self, **kwargs) |
|
40 | ProcessingUnit.__init__(self, **kwargs) | |
39 |
|
41 | |||
40 | self.dataOut = Voltage() |
|
42 | self.dataOut = Voltage() | |
41 | self.__printInfo = True |
|
43 | self.__printInfo = True | |
42 | self.__flagDiscontinuousBlock = False |
|
44 | self.__flagDiscontinuousBlock = False | |
43 | self.__bufferIndex = 9999999 |
|
45 | self.__bufferIndex = 9999999 | |
44 | self.__ippKm = None |
|
46 | self.__ippKm = None | |
45 | self.__codeType = 0 |
|
47 | self.__codeType = 0 | |
46 | self.__nCode = None |
|
48 | self.__nCode = None | |
47 | self.__nBaud = None |
|
49 | self.__nBaud = None | |
48 | self.__code = None |
|
50 | self.__code = None | |
49 |
|
51 | |||
50 | def __getCurrentSecond(self): |
|
52 | def __getCurrentSecond(self): | |
51 |
|
53 | |||
52 | return self.__thisUnixSample/self.__sample_rate |
|
54 | return self.__thisUnixSample/self.__sample_rate | |
53 |
|
55 | |||
54 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") |
|
56 | thisSecond = property(__getCurrentSecond, "I'm the 'thisSecond' property.") | |
55 |
|
57 | |||
56 | def __setFileHeader(self): |
|
58 | def __setFileHeader(self): | |
57 | ''' |
|
59 | ''' | |
58 | In this method will be initialized every parameter of dataOut object (header, no data) |
|
60 | In this method will be initialized every parameter of dataOut object (header, no data) | |
59 | ''' |
|
61 | ''' | |
60 | ippSeconds = 1.0*self.__nSamples/self.__sample_rate |
|
62 | ippSeconds = 1.0*self.__nSamples/self.__sample_rate | |
61 |
|
63 | |||
62 | nProfiles = 1.0/ippSeconds # Number of profiles in one second |
|
64 | nProfiles = 1.0/ippSeconds # Number of profiles in one second | |
63 |
|
65 | |||
64 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader(self.__radarControllerHeader) |
|
66 | self.dataOut.radarControllerHeaderObj = RadarControllerHeader(self.__radarControllerHeader) | |
65 |
|
67 | |||
66 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) |
|
68 | self.dataOut.systemHeaderObj = SystemHeader(self.__systemHeader) | |
67 |
|
69 | |||
68 | self.dataOut.type = "Voltage" |
|
70 | self.dataOut.type = "Voltage" | |
69 |
|
71 | |||
70 | self.dataOut.data = None |
|
72 | self.dataOut.data = None | |
71 |
|
73 | |||
72 | self.dataOut.dtype = self.dtype |
|
74 | self.dataOut.dtype = self.dtype | |
73 |
|
75 | |||
74 | # self.dataOut.nChannels = 0 |
|
76 | # self.dataOut.nChannels = 0 | |
75 |
|
77 | |||
76 | # self.dataOut.nHeights = 0 |
|
78 | # self.dataOut.nHeights = 0 | |
77 |
|
79 | |||
78 | self.dataOut.nProfiles = nProfiles |
|
80 | self.dataOut.nProfiles = nProfiles | |
79 |
|
81 | |||
80 | self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth |
|
82 | self.dataOut.heightList = self.__firstHeigth + numpy.arange(self.__nSamples, dtype = numpy.float)*self.__deltaHeigth | |
81 |
|
83 | |||
82 |
self.dataOut.channelList = self.__channel |
|
84 | self.dataOut.channelList = range(self.__num_subchannels) | |
83 |
|
85 | |||
84 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() |
|
86 | self.dataOut.blocksize = self.dataOut.getNChannels() * self.dataOut.getNHeights() | |
85 |
|
87 | |||
86 | # self.dataOut.channelIndexList = None |
|
88 | # self.dataOut.channelIndexList = None | |
87 |
|
89 | |||
88 | self.dataOut.flagNoData = True |
|
90 | self.dataOut.flagNoData = True | |
89 |
|
91 | |||
90 | self.dataOut.flagDataAsBlock = False |
|
92 | self.dataOut.flagDataAsBlock = False | |
91 | # Set to TRUE if the data is discontinuous |
|
93 | # Set to TRUE if the data is discontinuous | |
92 | self.dataOut.flagDiscontinuousBlock = False |
|
94 | self.dataOut.flagDiscontinuousBlock = False | |
93 |
|
95 | |||
94 | self.dataOut.utctime = None |
|
96 | self.dataOut.utctime = None | |
95 |
|
97 | |||
96 | self.dataOut.timeZone = self.__timezone/60 # timezone like jroheader, difference in minutes between UTC and localtime |
|
98 | self.dataOut.timeZone = self.__timezone/60 # timezone like jroheader, difference in minutes between UTC and localtime | |
97 |
|
99 | |||
98 | self.dataOut.dstFlag = 0 |
|
100 | self.dataOut.dstFlag = 0 | |
99 |
|
101 | |||
100 | self.dataOut.errorCount = 0 |
|
102 | self.dataOut.errorCount = 0 | |
101 |
|
103 | |||
102 | self.dataOut.nCohInt = self.fixed_metadata_dict['nCohInt'] |
|
104 | self.dataOut.nCohInt = self.fixed_metadata_dict['nCohInt'] | |
103 |
|
105 | |||
104 | self.dataOut.flagDecodeData = self.fixed_metadata_dict['flagDecodeData'] # asumo que la data esta decodificada |
|
106 | self.dataOut.flagDecodeData = self.fixed_metadata_dict['flagDecodeData'] # asumo que la data esta decodificada | |
105 |
|
107 | |||
106 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] # asumo que la data esta sin flip |
|
108 | self.dataOut.flagDeflipData = self.fixed_metadata_dict['flagDeflipData'] # asumo que la data esta sin flip | |
107 |
|
109 | |||
108 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] |
|
110 | self.dataOut.flagShiftFFT = self.fixed_metadata_dict['flagShiftFFT'] | |
109 |
|
111 | |||
110 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] |
|
112 | self.dataOut.useLocalTime = self.fixed_metadata_dict['useLocalTime'] | |
111 |
|
113 | |||
112 | self.dataOut.ippSeconds = ippSeconds |
|
114 | self.dataOut.ippSeconds = ippSeconds | |
113 |
|
115 | |||
114 | # Time interval between profiles |
|
116 | # Time interval between profiles | |
115 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt |
|
117 | # self.dataOut.timeInterval = self.dataOut.ippSeconds * self.dataOut.nCohInt | |
116 |
|
118 | |||
117 | self.dataOut.frequency = self.__frequency |
|
119 | self.dataOut.frequency = self.__frequency | |
118 |
|
120 | |||
119 | self.dataOut.realtime = self.__online |
|
121 | self.dataOut.realtime = self.__online | |
120 |
|
122 | |||
121 | def findDatafiles(self, path, startDate=None, endDate=None): |
|
123 | def findDatafiles(self, path, startDate=None, endDate=None): | |
122 |
|
124 | |||
123 | if not os.path.isdir(path): |
|
125 | if not os.path.isdir(path): | |
124 | return [] |
|
126 | return [] | |
125 |
|
127 | |||
126 | try: |
|
128 | try: | |
127 | digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True) |
|
129 | digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True) | |
128 | except: |
|
130 | except: | |
129 | digitalReadObj = digital_rf.DigitalRFReader(path) |
|
131 | digitalReadObj = digital_rf.DigitalRFReader(path) | |
130 |
|
132 | |||
131 | channelNameList = digitalReadObj.get_channels() |
|
133 | channelNameList = digitalReadObj.get_channels() | |
132 |
|
134 | |||
133 | if not channelNameList: |
|
135 | if not channelNameList: | |
134 | return [] |
|
136 | return [] | |
135 |
|
137 | |||
136 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) |
|
138 | metadata_dict = digitalReadObj.get_rf_file_metadata(channelNameList[0]) | |
137 |
|
139 | |||
138 | sample_rate = metadata_dict['sample_rate'][0] |
|
140 | sample_rate = metadata_dict['sample_rate'][0] | |
139 |
|
141 | |||
140 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) |
|
142 | this_metadata_file = digitalReadObj.get_metadata(channelNameList[0]) | |
141 |
|
143 | |||
142 | try: |
|
144 | try: | |
143 | timezone = this_metadata_file['timezone'].value |
|
145 | timezone = this_metadata_file['timezone'].value | |
144 | except: |
|
146 | except: | |
145 | timezone = 0 |
|
147 | timezone = 0 | |
146 |
|
148 | |||
147 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone |
|
149 | startUTCSecond, endUTCSecond = digitalReadObj.get_bounds(channelNameList[0])/sample_rate - timezone | |
148 |
|
150 | |||
149 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) |
|
151 | startDatetime = datetime.datetime.utcfromtimestamp(startUTCSecond) | |
150 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) |
|
152 | endDatatime = datetime.datetime.utcfromtimestamp(endUTCSecond) | |
151 |
|
153 | |||
152 | if not startDate: |
|
154 | if not startDate: | |
153 | startDate = startDatetime.date() |
|
155 | startDate = startDatetime.date() | |
154 |
|
156 | |||
155 | if not endDate: |
|
157 | if not endDate: | |
156 | endDate = endDatatime.date() |
|
158 | endDate = endDatatime.date() | |
157 |
|
159 | |||
158 | dateList = [] |
|
160 | dateList = [] | |
159 |
|
161 | |||
160 | thisDatetime = startDatetime |
|
162 | thisDatetime = startDatetime | |
161 |
|
163 | |||
162 | while(thisDatetime<=endDatatime): |
|
164 | while(thisDatetime<=endDatatime): | |
163 |
|
165 | |||
164 | thisDate = thisDatetime.date() |
|
166 | thisDate = thisDatetime.date() | |
165 |
|
167 | |||
166 | if thisDate < startDate: |
|
168 | if thisDate < startDate: | |
167 | continue |
|
169 | continue | |
168 |
|
170 | |||
169 | if thisDate > endDate: |
|
171 | if thisDate > endDate: | |
170 | break |
|
172 | break | |
171 |
|
173 | |||
172 | dateList.append(thisDate) |
|
174 | dateList.append(thisDate) | |
173 | thisDatetime += datetime.timedelta(1) |
|
175 | thisDatetime += datetime.timedelta(1) | |
174 |
|
176 | |||
175 | return dateList |
|
177 | return dateList | |
176 |
|
178 | |||
177 | def setup(self, path = None, |
|
179 | def setup(self, path = None, | |
178 | startDate = None, |
|
180 | startDate = None, | |
179 | endDate = None, |
|
181 | endDate = None, | |
180 | startTime = datetime.time(0,0,0), |
|
182 | startTime = datetime.time(0,0,0), | |
181 | endTime = datetime.time(23,59,59), |
|
183 | endTime = datetime.time(23,59,59), | |
182 | channelList = None, |
|
184 | channelList = None, | |
183 | nSamples = None, |
|
185 | nSamples = None, | |
184 | online = False, |
|
186 | online = False, | |
185 | delay = 60, |
|
187 | delay = 60, | |
186 | buffer_size = 1024, |
|
188 | buffer_size = 1024, | |
187 | ippKm=None, |
|
189 | ippKm=None, | |
188 | **kwargs): |
|
190 | **kwargs): | |
189 | ''' |
|
191 | ''' | |
190 | In this method we should set all initial parameters. |
|
192 | In this method we should set all initial parameters. | |
191 |
|
193 | |||
192 | Inputs: |
|
194 | Inputs: | |
193 | path |
|
195 | path | |
194 | startDate |
|
196 | startDate | |
195 | endDate |
|
197 | endDate | |
196 | startTime |
|
198 | startTime | |
197 | endTime |
|
199 | endTime | |
198 | set |
|
200 | set | |
199 | expLabel |
|
201 | expLabel | |
200 | ext |
|
202 | ext | |
201 | online |
|
203 | online | |
202 | delay |
|
204 | delay | |
203 | ''' |
|
205 | ''' | |
204 |
|
206 | |||
205 | if not os.path.isdir(path): |
|
207 | if not os.path.isdir(path): | |
206 | raise ValueError, "[Reading] Directory %s does not exist" %path |
|
208 | raise ValueError, "[Reading] Directory %s does not exist" %path | |
207 |
|
209 | |||
208 | try: |
|
210 | try: | |
209 | self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True) |
|
211 | self.digitalReadObj = digital_rf.DigitalRFReader(path, load_all_metadata=True) | |
210 | except: |
|
212 | except: | |
211 | self.digitalReadObj = digital_rf.DigitalRFReader(path) |
|
213 | self.digitalReadObj = digital_rf.DigitalRFReader(path) | |
212 |
|
214 | |||
213 | channelNameList = self.digitalReadObj.get_channels() |
|
215 | channelNameList = self.digitalReadObj.get_channels() | |
214 |
|
216 | |||
215 | if not channelNameList: |
|
217 | if not channelNameList: | |
216 | raise ValueError, "[Reading] Directory %s does not have any files" %path |
|
218 | raise ValueError, "[Reading] Directory %s does not have any files" %path | |
217 |
|
219 | |||
218 | if not channelList: |
|
220 | if not channelList: | |
219 | channelList = range(len(channelNameList)) |
|
221 | channelList = range(len(channelNameList)) | |
220 |
|
222 | |||
221 |
|
223 | |||
222 | ########## Reading metadata ###################### |
|
224 | ########## Reading metadata ###################### | |
223 |
|
225 | |||
224 | top_properties = self.digitalReadObj.get_properties(channelNameList[channelList[0]]) |
|
226 | top_properties = self.digitalReadObj.get_properties(channelNameList[channelList[0]]) | |
225 |
|
227 | |||
|
228 | ||||
|
229 | ||||
|
230 | ||||
|
231 | ||||
|
232 | ||||
|
233 | self.__num_subchannels = top_properties['num_subchannels'] | |||
226 | self.__sample_rate = 1.0 * top_properties['sample_rate_numerator'] / top_properties['sample_rate_denominator'] |
|
234 | self.__sample_rate = 1.0 * top_properties['sample_rate_numerator'] / top_properties['sample_rate_denominator'] | |
227 |
|
235 | |||
228 | # self.__samples_per_file = top_properties['samples_per_file'][0] |
|
236 | # self.__samples_per_file = top_properties['samples_per_file'][0] | |
229 | self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15? |
|
237 | self.__deltaHeigth = 1e6*0.15/self.__sample_rate ## why 0.15? | |
230 |
|
238 | |||
231 | this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]]) |
|
239 | this_metadata_file = self.digitalReadObj.get_digital_metadata(channelNameList[channelList[0]]) | |
|
240 | print this_metadata_file | |||
232 | metadata_bounds = this_metadata_file.get_bounds() |
|
241 | metadata_bounds = this_metadata_file.get_bounds() | |
233 | self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ## GET FIRST HEADER |
|
242 | self.fixed_metadata_dict = this_metadata_file.read(metadata_bounds[0])[metadata_bounds[0]] ## GET FIRST HEADER | |
234 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] |
|
243 | self.__processingHeader = self.fixed_metadata_dict['processingHeader'] | |
235 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] |
|
244 | self.__radarControllerHeader = self.fixed_metadata_dict['radarControllerHeader'] | |
236 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] |
|
245 | self.__systemHeader = self.fixed_metadata_dict['systemHeader'] | |
237 | self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype']) |
|
246 | self.dtype = cPickle.loads(self.fixed_metadata_dict['dtype']) | |
238 |
|
247 | |||
239 | self.__frequency = None |
|
248 | self.__frequency = None | |
240 |
|
249 | |||
241 | try: |
|
250 | try: | |
242 | self.__frequency = self.fixed_metadata_dict['frequency'] |
|
251 | self.__frequency = self.fixed_metadata_dict['frequency'] | |
243 | except: |
|
252 | except: | |
244 | self.__frequency = None |
|
253 | self.__frequency = None | |
245 |
|
254 | |||
246 | try: |
|
255 | try: | |
247 | self.__timezone = self.fixed_metadata_dict['timezone'] * 60 |
|
256 | self.__timezone = self.fixed_metadata_dict['timezone'] * 60 | |
248 | except: |
|
257 | except: | |
249 | self.__timezone = 0 |
|
258 | self.__timezone = 0 | |
250 |
|
259 | |||
251 |
|
260 | |||
252 | try: |
|
261 | try: | |
253 | nSamples = self.fixed_metadata_dict['nSamples'] |
|
262 | nSamples = self.fixed_metadata_dict['nSamples'] | |
254 | except: |
|
263 | except: | |
255 | nSamples = None |
|
264 | nSamples = None | |
256 |
|
265 | |||
257 | self.__firstHeigth = 0 |
|
266 | self.__firstHeigth = 0 | |
258 |
|
267 | |||
259 | try: |
|
268 | try: | |
260 | codeType = self.__radarControllerHeader['codeType'] |
|
269 | codeType = self.__radarControllerHeader['codeType'] | |
261 | except: |
|
270 | except: | |
262 | codeType = 0 |
|
271 | codeType = 0 | |
263 |
|
272 | |||
264 | nCode = 1 |
|
273 | nCode = 1 | |
265 | nBaud = 1 |
|
274 | nBaud = 1 | |
266 | code = numpy.ones((nCode, nBaud), dtype=numpy.int) |
|
275 | code = numpy.ones((nCode, nBaud), dtype=numpy.int) | |
267 |
|
276 | |||
268 | if codeType: |
|
277 | if codeType: | |
269 | nCode = self.__radarControllerHeader['nCode'] |
|
278 | nCode = self.__radarControllerHeader['nCode'] | |
270 | nBaud = self.__radarControllerHeader['nBaud'] |
|
279 | nBaud = self.__radarControllerHeader['nBaud'] | |
271 | code = self.__radarControllerHeader['code'] |
|
280 | code = self.__radarControllerHeader['code'] | |
272 |
|
281 | |||
273 | if not ippKm: |
|
282 | if not ippKm: | |
274 | try: |
|
283 | try: | |
275 | # seconds to km |
|
284 | # seconds to km | |
276 | ippKm = self.__radarControllerHeader['ipp'] |
|
285 | ippKm = self.__radarControllerHeader['ipp'] | |
277 | except: |
|
286 | except: | |
278 | ippKm = None |
|
287 | ippKm = None | |
279 | #################################################### |
|
288 | #################################################### | |
280 | startUTCSecond = None |
|
289 | startUTCSecond = None | |
281 | endUTCSecond = None |
|
290 | endUTCSecond = None | |
282 |
|
291 | |||
283 | if startDate: |
|
292 | if startDate: | |
284 | startDatetime = datetime.datetime.combine(startDate, startTime) |
|
293 | startDatetime = datetime.datetime.combine(startDate, startTime) | |
285 | startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone |
|
294 | startUTCSecond = (startDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone | |
286 |
|
295 | |||
287 | if endDate: |
|
296 | if endDate: | |
288 | endDatetime = datetime.datetime.combine(endDate, endTime) |
|
297 | endDatetime = datetime.datetime.combine(endDate, endTime) | |
289 | endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone |
|
298 | endUTCSecond = (endDatetime-datetime.datetime(1970,1,1)).total_seconds() + self.__timezone | |
290 |
|
299 | |||
291 | start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]]) |
|
300 | start_index, end_index = self.digitalReadObj.get_bounds(channelNameList[channelList[0]]) | |
292 |
|
301 | |||
293 | if not startUTCSecond: |
|
302 | if not startUTCSecond: | |
294 | startUTCSecond = start_index/self.__sample_rate |
|
303 | startUTCSecond = start_index/self.__sample_rate | |
295 |
|
304 | |||
296 | if start_index > startUTCSecond*self.__sample_rate: |
|
305 | if start_index > startUTCSecond*self.__sample_rate: | |
297 | startUTCSecond = start_index/self.__sample_rate |
|
306 | startUTCSecond = start_index/self.__sample_rate | |
298 |
|
307 | |||
299 | if not endUTCSecond: |
|
308 | if not endUTCSecond: | |
300 | endUTCSecond = end_index/self.__sample_rate |
|
309 | endUTCSecond = end_index/self.__sample_rate | |
301 |
|
310 | |||
302 | if end_index < endUTCSecond*self.__sample_rate: |
|
311 | if end_index < endUTCSecond*self.__sample_rate: | |
303 | endUTCSecond = end_index/self.__sample_rate |
|
312 | endUTCSecond = end_index/self.__sample_rate | |
304 | print ippKm |
|
313 | print ippKm | |
305 | if not nSamples: |
|
314 | if not nSamples: | |
306 | if not ippKm: |
|
315 | if not ippKm: | |
307 | raise ValueError, "[Reading] nSamples or ippKm should be defined" |
|
316 | raise ValueError, "[Reading] nSamples or ippKm should be defined" | |
308 | nSamples = int(ippKm / (1e6*0.15/self.__sample_rate)) |
|
317 | nSamples = int(ippKm / (1e6*0.15/self.__sample_rate)) | |
309 | print nSamples |
|
318 | print nSamples | |
310 | channelBoundList = [] |
|
319 | channelBoundList = [] | |
311 | channelNameListFiltered = [] |
|
320 | channelNameListFiltered = [] | |
312 |
|
321 | |||
313 | for thisIndexChannel in channelList: |
|
322 | for thisIndexChannel in channelList: | |
314 | thisChannelName = channelNameList[thisIndexChannel] |
|
323 | thisChannelName = channelNameList[thisIndexChannel] | |
315 | start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName) |
|
324 | start_index, end_index = self.digitalReadObj.get_bounds(thisChannelName) | |
316 | channelBoundList.append((start_index, end_index)) |
|
325 | channelBoundList.append((start_index, end_index)) | |
317 | channelNameListFiltered.append(thisChannelName) |
|
326 | channelNameListFiltered.append(thisChannelName) | |
318 |
|
327 | |||
319 | self.profileIndex = 0 |
|
328 | self.profileIndex = 0 | |
320 | self.i= 0 |
|
329 | self.i= 0 | |
321 | self.__delay = delay |
|
330 | self.__delay = delay | |
322 | self.__ippKm = ippKm |
|
331 | self.__ippKm = ippKm | |
323 | self.__codeType = codeType |
|
332 | self.__codeType = codeType | |
324 | self.__nCode = nCode |
|
333 | self.__nCode = nCode | |
325 | self.__nBaud = nBaud |
|
334 | self.__nBaud = nBaud | |
326 | self.__code = code |
|
335 | self.__code = code | |
327 |
|
336 | |||
328 | self.__datapath = path |
|
337 | self.__datapath = path | |
329 | self.__online = online |
|
338 | self.__online = online | |
330 | self.__channelList = channelList |
|
339 | self.__channelList = channelList | |
331 | self.__channelNameList = channelNameListFiltered |
|
340 | self.__channelNameList = channelNameListFiltered | |
332 | self.__channelBoundList = channelBoundList |
|
341 | self.__channelBoundList = channelBoundList | |
333 | self.__nSamples = nSamples |
|
342 | self.__nSamples = nSamples | |
334 | self.__samples_to_read = long(nSamples) # FIJO: AHORA 40 |
|
343 | self.__samples_to_read = long(nSamples) # FIJO: AHORA 40 | |
335 | self.__nChannels = len(self.__channelList) |
|
344 | self.__nChannels = len(self.__channelList) | |
336 |
|
345 | |||
337 | self.__startUTCSecond = startUTCSecond |
|
346 | self.__startUTCSecond = startUTCSecond | |
338 | self.__endUTCSecond = endUTCSecond |
|
347 | self.__endUTCSecond = endUTCSecond | |
339 |
|
348 | |||
340 | self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate # Time interval |
|
349 | self.__timeInterval = 1.0 * self.__samples_to_read/self.__sample_rate # Time interval | |
341 |
|
350 | |||
342 | if online: |
|
351 | if online: | |
343 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) |
|
352 | # self.__thisUnixSample = int(endUTCSecond*self.__sample_rate - 4*self.__samples_to_read) | |
344 | startUTCSecond = numpy.floor(endUTCSecond) |
|
353 | startUTCSecond = numpy.floor(endUTCSecond) | |
345 |
|
354 | |||
346 | self.__thisUnixSample = long(startUTCSecond*self.__sample_rate) - self.__samples_to_read ## por que en el otro metodo lo primero q se hace es sumar samplestoread |
|
355 | self.__thisUnixSample = long(startUTCSecond*self.__sample_rate) - self.__samples_to_read ## por que en el otro metodo lo primero q se hace es sumar samplestoread | |
347 |
|
356 | |||
348 |
self.__data_buffer = numpy.zeros((self.__n |
|
357 | self.__data_buffer = numpy.zeros((self.__num_subchannels, self.__samples_to_read), dtype = numpy.complex) | |
349 |
|
358 | |||
350 | self.__setFileHeader() |
|
359 | self.__setFileHeader() | |
351 | self.isConfig = True |
|
360 | self.isConfig = True | |
352 |
|
361 | |||
353 | print "[Reading] Digital RF Data was found from %s to %s " %( |
|
362 | print "[Reading] Digital RF Data was found from %s to %s " %( | |
354 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), |
|
363 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
355 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) |
|
364 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
356 | ) |
|
365 | ) | |
357 |
|
366 | |||
358 | print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), |
|
367 | print "[Reading] Starting process from %s to %s" %(datetime.datetime.utcfromtimestamp(startUTCSecond - self.__timezone), | |
359 | datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone) |
|
368 | datetime.datetime.utcfromtimestamp(endUTCSecond - self.__timezone) | |
360 | ) |
|
369 | ) | |
361 |
|
370 | |||
362 | def __reload(self): |
|
371 | def __reload(self): | |
363 |
|
372 | |||
364 | # print "%s not in range [%s, %s]" %( |
|
373 | # print "%s not in range [%s, %s]" %( | |
365 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
374 | # datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
366 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), |
|
375 | # datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
367 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) |
|
376 | # datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
368 | # ) |
|
377 | # ) | |
369 | print "[Reading] reloading metadata ..." |
|
378 | print "[Reading] reloading metadata ..." | |
370 |
|
379 | |||
371 | try: |
|
380 | try: | |
372 | self.digitalReadObj.reload(complete_update=True) |
|
381 | self.digitalReadObj.reload(complete_update=True) | |
373 | except: |
|
382 | except: | |
374 | self.digitalReadObj.reload() |
|
383 | self.digitalReadObj.reload() | |
375 |
|
384 | |||
376 | start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]]) |
|
385 | start_index, end_index = self.digitalReadObj.get_bounds(self.__channelNameList[self.__channelList[0]]) | |
377 |
|
386 | |||
378 | if start_index > self.__startUTCSecond*self.__sample_rate: |
|
387 | if start_index > self.__startUTCSecond*self.__sample_rate: | |
379 | self.__startUTCSecond = 1.0*start_index/self.__sample_rate |
|
388 | self.__startUTCSecond = 1.0*start_index/self.__sample_rate | |
380 |
|
389 | |||
381 | if end_index > self.__endUTCSecond*self.__sample_rate: |
|
390 | if end_index > self.__endUTCSecond*self.__sample_rate: | |
382 | self.__endUTCSecond = 1.0*end_index/self.__sample_rate |
|
391 | self.__endUTCSecond = 1.0*end_index/self.__sample_rate | |
383 |
|
392 | |||
384 | print "[Reading] New timerange found [%s, %s] " %( |
|
393 | print "[Reading] New timerange found [%s, %s] " %( | |
385 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), |
|
394 | datetime.datetime.utcfromtimestamp(self.__startUTCSecond - self.__timezone), | |
386 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) |
|
395 | datetime.datetime.utcfromtimestamp(self.__endUTCSecond - self.__timezone) | |
387 | ) |
|
396 | ) | |
388 |
|
397 | |||
389 | return True |
|
398 | return True | |
390 |
|
399 | |||
391 | return False |
|
400 | return False | |
392 |
|
401 | |||
393 | def __readNextBlock(self, seconds=30, volt_scale = 1): |
|
402 | def __readNextBlock(self, seconds=30, volt_scale = 1): | |
394 | ''' |
|
403 | ''' | |
395 | ''' |
|
404 | ''' | |
396 |
|
405 | |||
397 | # Set the next data |
|
406 | # Set the next data | |
398 | self.__flagDiscontinuousBlock = False |
|
407 | self.__flagDiscontinuousBlock = False | |
399 | self.__thisUnixSample += self.__samples_to_read |
|
408 | self.__thisUnixSample += self.__samples_to_read | |
400 |
|
409 | |||
401 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: |
|
410 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: | |
402 | print "[Reading] There are no more data into selected time-range" |
|
411 | print "[Reading] There are no more data into selected time-range" | |
403 | if self.__online: |
|
412 | if self.__online: | |
404 | self.__reload() |
|
413 | self.__reload() | |
405 | else: |
|
414 | else: | |
406 | return False |
|
415 | return False | |
407 |
|
416 | |||
408 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: |
|
417 | if self.__thisUnixSample + 2*self.__samples_to_read > self.__endUTCSecond*self.__sample_rate: | |
409 | return False |
|
418 | return False | |
410 | self.__thisUnixSample -= self.__samples_to_read |
|
419 | self.__thisUnixSample -= self.__samples_to_read | |
411 |
|
420 | |||
412 | indexChannel = 0 |
|
421 | indexChannel = 0 | |
413 |
|
422 | |||
414 | dataOk = False |
|
423 | dataOk = False | |
415 | for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS? |
|
424 | for thisChannelName in self.__channelNameList: ##TODO VARIOS CHANNELS? | |
416 | try: |
|
425 | for indexSubchannel in range(self.__num_subchannels): | |
417 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, |
|
426 | try: | |
418 | self.__samples_to_read, |
|
427 | result = self.digitalReadObj.read_vector_c81d(self.__thisUnixSample, | |
419 |
|
|
428 | self.__samples_to_read, | |
420 | except IOError, e: |
|
429 | thisChannelName, sub_channel=indexSubchannel) | |
421 |
|
|
430 | except IOError, e: | |
422 | self.__flagDiscontinuousBlock = True |
|
431 | #read next profile | |
423 | print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e |
|
432 | self.__flagDiscontinuousBlock = True | |
424 | break |
|
433 | print "[Reading] %s" %datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), e | |
|
434 | break | |||
425 |
|
435 | |||
426 | if result.shape[0] != self.__samples_to_read: |
|
436 | if result.shape[0] != self.__samples_to_read: | |
427 | self.__flagDiscontinuousBlock = True |
|
437 | self.__flagDiscontinuousBlock = True | |
428 | print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
438 | print "[Reading] %s: Too few samples were found, just %d/%d samples" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
429 | result.shape[0], |
|
439 | result.shape[0], | |
430 | self.__samples_to_read) |
|
440 | self.__samples_to_read) | |
431 | break |
|
441 | break | |
432 |
|
442 | |||
433 |
self.__data_buffer[index |
|
443 | self.__data_buffer[indexSubchannel,:] = result*volt_scale | |
434 |
|
444 | |||
435 | indexChannel += 1 |
|
445 | indexChannel += 1 | |
436 |
|
446 | |||
437 | dataOk = True |
|
447 | dataOk = True | |
438 |
|
448 | |||
439 | self.__utctime = self.__thisUnixSample/self.__sample_rate |
|
449 | self.__utctime = self.__thisUnixSample/self.__sample_rate | |
440 |
|
450 | |||
441 | if not dataOk: |
|
451 | if not dataOk: | |
442 | return False |
|
452 | return False | |
443 |
|
453 | |||
444 | print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), |
|
454 | print "[Reading] %s: %d samples <> %f sec" %(datetime.datetime.utcfromtimestamp(self.thisSecond - self.__timezone), | |
445 | self.__samples_to_read, |
|
455 | self.__samples_to_read, | |
446 | self.__timeInterval) |
|
456 | self.__timeInterval) | |
447 |
|
457 | |||
448 | self.__bufferIndex = 0 |
|
458 | self.__bufferIndex = 0 | |
449 |
|
459 | |||
450 | return True |
|
460 | return True | |
451 |
|
461 | |||
452 | def __isBufferEmpty(self): |
|
462 | def __isBufferEmpty(self): | |
453 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40 |
|
463 | return self.__bufferIndex > self.__samples_to_read - self.__nSamples #40960 - 40 | |
454 |
|
464 | |||
455 | def getData(self, seconds=30, nTries=5): |
|
465 | def getData(self, seconds=30, nTries=5): | |
456 |
|
466 | |||
457 | ''' |
|
467 | ''' | |
458 | This method gets the data from files and put the data into the dataOut object |
|
468 | This method gets the data from files and put the data into the dataOut object | |
459 |
|
469 | |||
460 | In addition, increase el the buffer counter in one. |
|
470 | In addition, increase el the buffer counter in one. | |
461 |
|
471 | |||
462 | Return: |
|
472 | Return: | |
463 | data : retorna un perfil de voltages (alturas * canales) copiados desde el |
|
473 | data : retorna un perfil de voltages (alturas * canales) copiados desde el | |
464 | buffer. Si no hay mas archivos a leer retorna None. |
|
474 | buffer. Si no hay mas archivos a leer retorna None. | |
465 |
|
475 | |||
466 | Affected: |
|
476 | Affected: | |
467 | self.dataOut |
|
477 | self.dataOut | |
468 | self.profileIndex |
|
478 | self.profileIndex | |
469 | self.flagDiscontinuousBlock |
|
479 | self.flagDiscontinuousBlock | |
470 | self.flagIsNewBlock |
|
480 | self.flagIsNewBlock | |
471 | ''' |
|
481 | ''' | |
472 |
|
482 | |||
473 | err_counter = 0 |
|
483 | err_counter = 0 | |
474 | self.dataOut.flagNoData = True |
|
484 | self.dataOut.flagNoData = True | |
475 |
|
485 | |||
476 | if self.__isBufferEmpty(): |
|
486 | if self.__isBufferEmpty(): | |
477 | self.__flagDiscontinuousBlock = False |
|
487 | self.__flagDiscontinuousBlock = False | |
478 |
|
488 | |||
479 | while True: |
|
489 | while True: | |
480 | if self.__readNextBlock(): |
|
490 | if self.__readNextBlock(): | |
481 | break |
|
491 | break | |
482 | if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate: |
|
492 | if self.__thisUnixSample > self.__endUTCSecond*self.__sample_rate: | |
483 | return False |
|
493 | return False | |
484 |
|
494 | |||
485 | if self.__flagDiscontinuousBlock: |
|
495 | if self.__flagDiscontinuousBlock: | |
486 | print '[Reading] discontinuous block found ... continue with the next block' |
|
496 | print '[Reading] discontinuous block found ... continue with the next block' | |
487 | continue |
|
497 | continue | |
488 |
|
498 | |||
489 | if not self.__online: |
|
499 | if not self.__online: | |
490 | return False |
|
500 | return False | |
491 |
|
501 | |||
492 | err_counter += 1 |
|
502 | err_counter += 1 | |
493 | if err_counter > nTries: |
|
503 | if err_counter > nTries: | |
494 | return False |
|
504 | return False | |
495 |
|
505 | |||
496 | print '[Reading] waiting %d seconds to read a new block' %seconds |
|
506 | print '[Reading] waiting %d seconds to read a new block' %seconds | |
497 | sleep(seconds) |
|
507 | sleep(seconds) | |
498 |
|
508 | |||
499 | self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples] |
|
509 | self.dataOut.data = self.__data_buffer[:,self.__bufferIndex:self.__bufferIndex+self.__nSamples] | |
500 | self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate |
|
510 | self.dataOut.utctime = (self.__thisUnixSample + self.__bufferIndex)/self.__sample_rate | |
501 | self.dataOut.flagNoData = False |
|
511 | self.dataOut.flagNoData = False | |
502 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock |
|
512 | self.dataOut.flagDiscontinuousBlock = self.__flagDiscontinuousBlock | |
503 | self.dataOut.profileIndex = self.profileIndex |
|
513 | self.dataOut.profileIndex = self.profileIndex | |
504 |
|
514 | |||
505 | self.__bufferIndex += self.__nSamples |
|
515 | self.__bufferIndex += self.__nSamples | |
506 | self.profileIndex += 1 |
|
516 | self.profileIndex += 1 | |
507 |
|
517 | |||
508 | if self.profileIndex == self.dataOut.nProfiles: |
|
518 | if self.profileIndex == self.dataOut.nProfiles: | |
509 | self.profileIndex = 0 |
|
519 | self.profileIndex = 0 | |
510 |
|
520 | |||
511 | return True |
|
521 | return True | |
512 |
|
522 | |||
513 | def printInfo(self): |
|
523 | def printInfo(self): | |
514 | ''' |
|
524 | ''' | |
515 | ''' |
|
525 | ''' | |
516 | if self.__printInfo == False: |
|
526 | if self.__printInfo == False: | |
517 | return |
|
527 | return | |
518 |
|
528 | |||
519 | # self.systemHeaderObj.printInfo() |
|
529 | # self.systemHeaderObj.printInfo() | |
520 | # self.radarControllerHeaderObj.printInfo() |
|
530 | # self.radarControllerHeaderObj.printInfo() | |
521 |
|
531 | |||
522 | self.__printInfo = False |
|
532 | self.__printInfo = False | |
523 |
|
533 | |||
524 | def printNumberOfBlock(self): |
|
534 | def printNumberOfBlock(self): | |
525 | ''' |
|
535 | ''' | |
526 | ''' |
|
536 | ''' | |
527 | return |
|
537 | return | |
528 | # print self.profileIndex |
|
538 | # print self.profileIndex | |
529 |
|
539 | |||
530 | ##@profile |
|
540 | ##@profile | |
531 | def run(self, **kwargs): |
|
541 | def run(self, **kwargs): | |
532 | ''' |
|
542 | ''' | |
533 | This method will be called many times so here you should put all your code |
|
543 | This method will be called many times so here you should put all your code | |
534 | ''' |
|
544 | ''' | |
535 |
|
545 | |||
536 | if not self.isConfig: |
|
546 | if not self.isConfig: | |
537 | self.setup(**kwargs) |
|
547 | self.setup(**kwargs) | |
538 | self.i = self.i+1 |
|
548 | self.i = self.i+1 | |
539 | self.getData(seconds=self.__delay) |
|
549 | self.getData(seconds=self.__delay) | |
540 |
|
550 | |||
541 | return |
|
551 | return | |
542 |
|
552 | |||
543 | class DigitalRFWriter(Operation): |
|
553 | class DigitalRFWriter(Operation): | |
544 | ''' |
|
554 | ''' | |
545 | classdocs |
|
555 | classdocs | |
546 | ''' |
|
556 | ''' | |
547 |
|
557 | |||
548 | def __init__(self, **kwargs): |
|
558 | def __init__(self, **kwargs): | |
549 | ''' |
|
559 | ''' | |
550 | Constructor |
|
560 | Constructor | |
551 | ''' |
|
561 | ''' | |
552 | Operation.__init__(self, **kwargs) |
|
562 | Operation.__init__(self, **kwargs) | |
553 | self.metadata_dict = {} |
|
563 | self.metadata_dict = {} | |
554 | self.dataOut = None |
|
564 | self.dataOut = None | |
555 |
|
565 | |||
556 | def setHeader(self, dataOut): |
|
566 | def setHeader(self, dataOut): | |
557 | return |
|
567 | return | |
558 |
|
568 | |||
559 | def setup(self, dataOut, path, frequency, set=0, metadataFile='metadata', ext='.h5'): |
|
569 | def setup(self, dataOut, path, frequency, set=0, metadataFile='metadata', ext='.h5'): | |
560 | ''' |
|
570 | ''' | |
561 | In this method we should set all initial parameters. |
|
571 | In this method we should set all initial parameters. | |
562 | Input: |
|
572 | Input: | |
563 | dataOut: Input data will also be outputa data |
|
573 | dataOut: Input data will also be outputa data | |
564 | ''' |
|
574 | ''' | |
565 | self.metadata_dict['frequency'] = dataOut.frequency |
|
575 | self.metadata_dict['frequency'] = dataOut.frequency | |
566 | self.metadata_dict['timezone'] = dataOut.timeZone |
|
576 | self.metadata_dict['timezone'] = dataOut.timeZone | |
567 | self.metadata_dict['dtype'] = cPickle.dumps(dataOut.dtype) |
|
577 | self.metadata_dict['dtype'] = cPickle.dumps(dataOut.dtype) | |
568 | self.metadata_dict['nProfiles'] = dataOut.nProfiles |
|
578 | self.metadata_dict['nProfiles'] = dataOut.nProfiles | |
569 | self.metadata_dict['heightList'] = dataOut.heightList |
|
579 | self.metadata_dict['heightList'] = dataOut.heightList | |
570 | self.metadata_dict['channelList'] = dataOut.channelList |
|
580 | self.metadata_dict['channelList'] = dataOut.channelList | |
571 | self.metadata_dict['flagDecodeData'] = dataOut.flagDecodeData |
|
581 | self.metadata_dict['flagDecodeData'] = dataOut.flagDecodeData | |
572 | self.metadata_dict['flagDeflipData'] = dataOut.flagDeflipData |
|
582 | self.metadata_dict['flagDeflipData'] = dataOut.flagDeflipData | |
573 | self.metadata_dict['flagShiftFFT'] = dataOut.flagShiftFFT |
|
583 | self.metadata_dict['flagShiftFFT'] = dataOut.flagShiftFFT | |
574 | self.metadata_dict['flagDataAsBlock'] = dataOut.flagDataAsBlock |
|
584 | self.metadata_dict['flagDataAsBlock'] = dataOut.flagDataAsBlock | |
575 | self.metadata_dict['useLocalTime'] = dataOut.useLocalTime |
|
585 | self.metadata_dict['useLocalTime'] = dataOut.useLocalTime | |
576 | self.metadata_dict['nCohInt'] = dataOut.nCohInt |
|
586 | self.metadata_dict['nCohInt'] = dataOut.nCohInt | |
577 |
|
587 | |||
578 | self.__ippSeconds = dataOut.ippSeconds |
|
588 | self.__ippSeconds = dataOut.ippSeconds | |
579 | self.__deltaH = dataOut.getDeltaH() |
|
589 | self.__deltaH = dataOut.getDeltaH() | |
580 | self.__sample_rate = 1e6*0.15/self.__deltaH |
|
590 | self.__sample_rate = 1e6*0.15/self.__deltaH | |
581 | self.__dtype = dataOut.dtype |
|
591 | self.__dtype = dataOut.dtype | |
582 | if len(dataOut.dtype) == 2: |
|
592 | if len(dataOut.dtype) == 2: | |
583 | self.__dtype = dataOut.dtype[0] |
|
593 | self.__dtype = dataOut.dtype[0] | |
584 | self.__nSamples = dataOut.systemHeaderObj.nSamples |
|
594 | self.__nSamples = dataOut.systemHeaderObj.nSamples | |
585 | self.__nProfiles = dataOut.nProfiles |
|
595 | self.__nProfiles = dataOut.nProfiles | |
586 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile |
|
596 | self.__blocks_per_file = dataOut.processingHeaderObj.dataBlocksPerFile | |
587 | self.arr_data = arr_data = numpy.ones((self.__nSamples, 2), dtype=[('r', self.__dtype), ('i', self.__dtype)]) |
|
597 | self.arr_data = arr_data = numpy.ones((self.__nSamples, 2), dtype=[('r', self.__dtype), ('i', self.__dtype)]) | |
588 |
|
598 | |||
589 | file_cadence_millisecs = long(1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000 |
|
599 | file_cadence_millisecs = long(1.0 * self.__blocks_per_file * self.__nProfiles * self.__nSamples / self.__sample_rate) * 1000 | |
590 | sub_cadence_secs = file_cadence_millisecs / 500 |
|
600 | sub_cadence_secs = file_cadence_millisecs / 500 | |
591 |
|
601 | |||
592 | print file_cadence_millisecs |
|
602 | print file_cadence_millisecs | |
593 | print sub_cadence_secs |
|
603 | print sub_cadence_secs | |
594 |
|
604 | |||
595 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() |
|
605 | sample_rate_fraction = Fraction(self.__sample_rate).limit_denominator() | |
596 | sample_rate_numerator = long(sample_rate_fraction.numerator) |
|
606 | sample_rate_numerator = long(sample_rate_fraction.numerator) | |
597 | sample_rate_denominator = long(sample_rate_fraction.denominator) |
|
607 | sample_rate_denominator = long(sample_rate_fraction.denominator) | |
598 | start_global_index = dataOut.utctime * self.__sample_rate |
|
608 | start_global_index = dataOut.utctime * self.__sample_rate | |
599 |
|
609 | |||
600 | uuid = 'prueba' |
|
610 | uuid = 'prueba' | |
601 | compression_level = 1 |
|
611 | compression_level = 1 | |
602 | checksum = False |
|
612 | checksum = False | |
603 | is_complex = True |
|
613 | is_complex = True | |
604 |
num_subchannels = |
|
614 | num_subchannels = len(dataOut.channelList) | |
605 | is_continuous = True |
|
615 | is_continuous = True | |
606 | marching_periods = False |
|
616 | marching_periods = False | |
607 |
|
617 | |||
608 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, 100, |
|
618 | self.digitalWriteObj = digital_rf.DigitalRFWriter(path, self.__dtype, 100, | |
609 |
100 |
|
619 | 100, start_global_index, | |
610 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, |
|
620 | sample_rate_numerator, sample_rate_denominator, uuid, compression_level, checksum, | |
611 | is_complex, num_subchannels, is_continuous, marching_periods) |
|
621 | is_complex, num_subchannels, is_continuous, marching_periods) | |
612 |
|
622 | |||
613 | metadata_dir = os.path.join(path, 'metadata') |
|
623 | metadata_dir = os.path.join(path, 'metadata') | |
614 | os.system('mkdir %s' % (metadata_dir)) |
|
624 | os.system('mkdir %s' % (metadata_dir)) | |
615 |
|
625 | |||
616 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, 100, 1, ##236, file_cadence_millisecs / 1000 |
|
626 | self.digitalMetadataWriteObj = digital_rf.DigitalMetadataWriter(metadata_dir, 100, 1, ##236, file_cadence_millisecs / 1000 | |
617 | sample_rate_numerator, sample_rate_denominator, |
|
627 | sample_rate_numerator, sample_rate_denominator, | |
618 | metadataFile) |
|
628 | metadataFile) | |
619 |
|
629 | |||
620 |
|
630 | |||
621 | self.isConfig = True |
|
631 | self.isConfig = True | |
622 | self.currentSample = 0 |
|
632 | self.currentSample = 0 | |
|
633 | self.oldAverage = 0 | |||
|
634 | self.count = 0 | |||
623 | return |
|
635 | return | |
624 |
|
636 | |||
625 | def writeMetadata(self): |
|
637 | def writeMetadata(self): | |
626 | print '[Writing] - Writing metadata' |
|
638 | print '[Writing] - Writing metadata' | |
627 | start_idx = self.__sample_rate * self.dataOut.utctime |
|
639 | start_idx = self.__sample_rate * self.dataOut.utctime | |
628 |
|
640 | |||
629 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict() |
|
641 | self.metadata_dict['processingHeader'] = self.dataOut.processingHeaderObj.getAsDict() | |
630 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict() |
|
642 | self.metadata_dict['radarControllerHeader'] = self.dataOut.radarControllerHeaderObj.getAsDict() | |
631 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict() |
|
643 | self.metadata_dict['systemHeader'] = self.dataOut.systemHeaderObj.getAsDict() | |
632 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) |
|
644 | self.digitalMetadataWriteObj.write(start_idx, self.metadata_dict) | |
633 | return |
|
645 | return | |
634 |
|
646 | |||
635 |
|
647 | |||
636 | def writeData(self): |
|
648 | def writeData(self): | |
637 | for i in range(self.dataOut.systemHeaderObj.nSamples): |
|
649 | for i in range(self.dataOut.systemHeaderObj.nSamples): | |
638 | for channel in self.dataOut.channelList: |
|
650 | for channel in self.dataOut.channelList: | |
639 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real |
|
651 | self.arr_data[i][channel]['r'] = self.dataOut.data[channel][i].real | |
640 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag |
|
652 | self.arr_data[i][channel]['i'] = self.dataOut.data[channel][i].imag | |
|
653 | t0 = time() | |||
641 | self.digitalWriteObj.rf_write(self.arr_data) |
|
654 | self.digitalWriteObj.rf_write(self.arr_data) | |
|
655 | self.executionTime = time() - t0 | |||
|
656 | if self.oldAverage is None: self.oldAverage = self.executionTime | |||
|
657 | self.oldAverage = (self.executionTime + self.count*self.oldAverage) / (self.count + 1.0) | |||
|
658 | self.count = self.count + 1.0 | |||
|
659 | if self.oldAverage is None: self.oldAverage = self.executionTime | |||
|
660 | ||||
642 | return |
|
661 | return | |
643 |
|
662 | |||
644 | def run(self, dataOut, frequency=49.92e6, path=None, **kwargs): |
|
663 | def run(self, dataOut, frequency=49.92e6, path=None, **kwargs): | |
645 | ''' |
|
664 | ''' | |
646 | This method will be called many times so here you should put all your code |
|
665 | This method will be called many times so here you should put all your code | |
647 | Inputs: |
|
666 | Inputs: | |
648 | dataOut: object with the data |
|
667 | dataOut: object with the data | |
649 | ''' |
|
668 | ''' | |
650 | # print dataOut.__dict__ |
|
669 | # print dataOut.__dict__ | |
651 | self.dataOut = dataOut |
|
670 | self.dataOut = dataOut | |
652 | if not self.isConfig: |
|
671 | if not self.isConfig: | |
653 | self.setup(dataOut, path, frequency, **kwargs) |
|
672 | self.setup(dataOut, path, frequency, **kwargs) | |
654 |
|
673 | |||
655 | self.writeData() |
|
674 | self.writeData() | |
656 |
|
675 | |||
657 | self.currentSample += 1 |
|
676 | self.currentSample += 1 | |
658 | if self.dataOut.flagDataAsBlock or self.currentSample == 1: |
|
677 | if self.dataOut.flagDataAsBlock or self.currentSample == 1: | |
659 | self.writeMetadata() |
|
678 | self.writeMetadata() | |
660 | if self.currentSample == self.__nProfiles: self.currentSample = 0 |
|
679 | if self.currentSample == self.__nProfiles: self.currentSample = 0 | |
661 |
|
680 | |||
662 | def close(self): |
|
681 | def close(self): | |
663 | print '[Writing] - Closing files ' |
|
682 | print '[Writing] - Closing files ' | |
|
683 | print 'Average of writing to digital rf format is ', self.oldAverage * 1000 | |||
664 | try: |
|
684 | try: | |
665 | self.digitalWriteObj.close() |
|
685 | self.digitalWriteObj.close() | |
666 | except: |
|
686 | except: | |
667 | pass |
|
687 | pass | |
668 |
|
688 | |||
669 | # raise |
|
689 | # raise | |
670 | if __name__ == '__main__': |
|
690 | if __name__ == '__main__': | |
671 |
|
691 | |||
672 | readObj = DigitalRFReader() |
|
692 | readObj = DigitalRFReader() | |
673 |
|
693 | |||
674 | while True: |
|
694 | while True: | |
675 | readObj.run(path='/home/jchavez/jicamarca/mocked_data/') |
|
695 | readObj.run(path='/home/jchavez/jicamarca/mocked_data/') | |
676 | # readObj.printInfo() |
|
696 | # readObj.printInfo() | |
677 | # readObj.printNumberOfBlock() |
|
697 | # readObj.printNumberOfBlock() |
@@ -1,1 +1,1 | |||||
1 | <Project description="Segundo Test" id="191" name="test01"><ReadUnit datatype="VoltageReader" id="1911" inputId="0" name="VoltageReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="VoltageReader" /><Parameter format="str" id="191112" name="path" value="/home/jchavez/jicamarca/jro_data/rawdata" /><Parameter format="date" id="191113" name="startDate" value="2010/10/28" /><Parameter format="date" id="191114" name="endDate" value="2017/10/28" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="online" value="0" /><Parameter format="int" id="191119" name="walk" value="0" /></Operation><Operation id="19112" name="printNumberOfBlock" priority="2" type="self" /></ReadUnit><ProcUnit datatype="VoltageProc" id="1912" inputId="1911" name="VoltageProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="DigitalRFWriter" priority="2" type="other"><Parameter format="str" id="191221" name="path" value="/media/jchavez/DATA/mocked_data/voltage" /></Operation></ProcUnit></Project> No newline at end of file |
|
1 | <Project description="Testing USRP data reader" id="191" name="test01"><ReadUnit datatype="DigitalRF" id="1911" inputId="0" name="DigitalRFReader"><Operation id="19111" name="run" priority="1" type="self"><Parameter format="str" id="191111" name="datatype" value="DigitalRF" /><Parameter format="str" id="191112" name="path" value="/home/jchavez/jicamarca/mocked_data" /><Parameter format="date" id="191113" name="startDate" value="2000/07/03" /><Parameter format="date" id="191114" name="endDate" value="2017/07/03" /><Parameter format="time" id="191115" name="startTime" value="00:00:00" /><Parameter format="time" id="191116" name="endTime" value="23:59:59" /><Parameter format="int" id="191118" name="online" value="0" /></Operation></ReadUnit><ProcUnit datatype="Voltage" id="1912" inputId="1911" name="VoltageProc"><Operation id="19121" name="run" priority="1" type="self" /><Operation id="19122" name="Scope" priority="2" type="external"><Parameter format="int" id="191221" name="id" value="121" /><Parameter format="str" id="191222" name="wintitle" value="Scope" /></Operation></ProcUnit></Project> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now